Skip to main content
Topic: ManageSettings.... (Read 8168 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

ManageSettings....

I'm trying to work on a very small mod.
Since I liked the mod Global Headers anf Footers for SMF, but SMFHacks made it so many edits and files, I have decided to make a very simple one like it, for ElkArte.

However, since I can't do hooks, I need to do edits. I managed to find all that needed to do, except what would go into SMF's ManageSettings.php file.

Code: [Select]
	<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="replace"><![CDATA[// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!]]></search>
<add><![CDATA[// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
                array('text', 'global_head', '30'),
array('text', 'global_mid', '30'),
array('text', 'global_foot', '30'),
'',
]]></add>
</operation>
</file>

Where, and how would I do that?  ;D

Re: ManageSettings....

Reply #1

If you can't do something with a hook, please post what it is that you are trying to do. Obviously, templates aren't pluggable (yet).

You probably want to use the hooks in https://github.com/elkarte/Elkarte/blob/development/sources/admin/AddonSettings.controller.php

Re: ManageSettings....

Reply #2

I can't do anything with hooks.
I have learning disabilities, and am lucky I can do what I can... LOL

Hooks, look like nothing but gibberish to me.

Here is the file edits I have for my mod:

Code: [Select]
	<file name="$themedir/index.template.php">
<operation>
<search position="after"><![CDATA[</head>]]></search>
<add><![CDATA[if(!empty($modSettings['global_head']))
echo '
<div>', $modSettings['global_head'], '</div>
]]></add>
</operation>

<operation>
<search position="after"><![CDATA[ // Show the navigation tree.
theme_linktree();]]></search>
<add><![CDATA[if(!empty($modSettings['global_head']))
echo '
<div>', $modSettings['global_head'], '</div>
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[</body>]]></search>
<add><![CDATA[if(!empty($modSettings['global_foot']))
echo '
<div>', $modSettings['global_foot'], '</div>
]]></add>
</operation>
</file>

<file name="$languagedir/Addons.english.php">
<operation>
<search position="end" />
<add><![CDATA[
$txt['global_head'] = 'Add content to the <head></head> tags:';
$txt['global_mid'] = 'Add content below linktree:';
$txt['global_foot'] = 'Add content to the footer:';
]]></add>
</operation>
</file>

<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="replace"><![CDATA[// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!]]></search>
<add><![CDATA[// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!
                array('text', 'global_head', '30'),
array('text', 'global_mid', '30'),
array('text', 'global_foot', '30'),
'',
]]></add>
</operation>
</file>

Re: ManageSettings....

Reply #3

I think you can insert that as top and bottom layers but I cant exactly understand the guide given by @emanuele last time. Basically (I think), create your two templates and insert them as layers. The settings and language parts should be easy. I'll try to give them a look when I sit before my pc.

Re: ManageSettings....

Reply #4

Well, the template and language edits, are okay. I found the files needed to do them.
I just can't figure out how to get the settings in the addons misc section... LOL


Re: ManageSettings....

Reply #6

1 problem with that, @emanuele
I still can't do hooks, and I see no way to do the edits there.
So, someone is going to have to help Hook this addon.... LOL

Re: ManageSettings....

Reply #7

Quote from: Burke Knight – I still can't do hooks, and I see no way to do the edits there.
Why you don't see any way?
Isn't that a piece of code like any other? ;)

ETA: just to be a little more clear, what I would do is search for:
Code: [Select]
);

// Add new settings with a nice hook.
(tabs lost in the copy&paste from github)
Bugs creator.
Features destroyer.
Template killer.

Re: ManageSettings....

Reply #8

What I meant, is how do I do the edits, in non-hook form?
I have no idea how to write out a file for hooks.
It's one reason, why I never got my mods updated.... LOL

I need to add these lines:

Code: [Select]
		array('text', 'global_head', '30'),
array('text', 'global_mid', '30'),
array('text', 'global_foot', '30'),

Unless you mean to replace what you posted with:
Code: [Select]
		array('text', 'global_head', '30'),
array('text', 'global_mid', '30'),
array('text', 'global_foot', '30'),
);

// Add new settings with a nice hook.

EDIT: That worked on test forum!

Now, in the modification xml file, I take it, I need to adjust: $sourcedir/AddonSettings.controller.php
to this, maybe: $sourcedir/admin/AddonSettings.controller.php

Re: ManageSettings....

Reply #9

One thing I missed: in Elk there is not $sourcedir and alike, but constants like "SOURCEDIR", "THEMEDIR", "SUBSDIR", "ADMINDIR", "LANGUAGEDIR", etc.
The full list should be the one in index.php at:
https://github.com/elkarte/Elkarte/blob/9bfcf0a52afa37e193a29d2771558abaecfd7696/index.php#L66

The difference is that, instead of:
Code: [Select]
<file name="$themedir/index.template.php">
you'll have to write:
Code: [Select]
<file name="THEMEDIR/index.template.php">

And of course, if one day you'll be curious about hooks, let me know your questions and doubts (side note: I think that starting from 1.1 they will become easier to grasp (I hope), because it will be possible to use the approach "put the file in that place and everything will automagically work", anyway it's still a bit early for that :P).
Bugs creator.
Features destroyer.
Template killer.

Re: ManageSettings....

Reply #10

Yeah, I inadvertently found that one out! LOL :)

Okay, I'm getting TPE on the index.template edit, and can't find out why:

Code: [Select]
syntax error, unexpected 'id' (T_STRING), expecting ',' or ';'

Code: [Select]
<file name="THEMEDIR/index.template.php">
<operation>
<search position="replace"><![CDATA[ echo '
</head>]]></search>
<add><![CDATA[
if(!empty($modSettings['global_head']))
echo '
<div>', $modSettings['global_head'], '</div>

</head>]]></add>
</operation>

<operation>
<search position="before"><![CDATA[ // Show the navigation tree.
theme_linktree();]]></search>
<add><![CDATA[if(!empty($modSettings['global_mid']))
echo '
<div>', $modSettings['global_mid'], '</div>';
]]></add>
</operation>

<operation>
<search position="before"><![CDATA[</body>]]></search>
<add><![CDATA[if(!empty($modSettings['global_foot']))
echo '
<div>', $modSettings['global_foot'], '</div>
]]></add>
</operation>
</file>

Any help on finding what I did wrong, would be appreciated.

Re: ManageSettings....

Reply #11

Shouldn't the last edit operation be after?

Re: ManageSettings....

Reply #12

EDITED:


Well, got it fixed, and running on a test site nicely![1]

Here's what it's all about now, since I added a few changes:



QuoteGlobal Header and Footer

Version: 1.0.0 Date: 6/28/15
Compatibility: 1.0.4

Made by: BurkeKnight - BurkeKnight Enterprises

This modification allows you to add HTML global content to three different parts of your forum.

Head <head></head> Content
Header Content (below linktree)
Footer Content (base of wrapper)


This addon aslo allows the Admin to add their own custom copyright right above the ElkArte Copyright.



This work is licensed under an open source BSD-3 clause license.

I'll be getting it onto GitHub soon, and will do the addon site pull request when can. :)

On GitHub now, waiting for the post to be merged.  ;D
Finally! LOL

Re: ManageSettings....

Reply #13

Nice work @Burke Knight . Now let's see if we can make this Global Header And Footer (GHF) mod into a hook mod.[1] We shall create files for it like GHF.subs.php, GHF.hooks.php etc.[2]

First part is the header part. I think we can call that in $context['html_headers']. In GHF.subs.php (whatever you want to name it), create a function for that so it the file will look something like this:
Code: [Select]
<?php
/**
 *
 * @author  Your name, email etc
 * @license Your license
 * @mod     Your mod name
 *
 */

if (!defined('ELK'))
die('No access...');

function GHF_Main()
{
// Globalize what you need
global $context, $modSettings;

// Load what you need
// eg. loadLanguage('GHF');

// Add things in header
if(!empty($modSettings['global_head'])) {
$context['html_headers'] .= ' . $modSettings['global_head'] . ';
}
}

?>

For footer, I think you can use $context['insert_after_template'] using the same principle as above.[3] Just modify the above function like this:

Code: [Select]
	// Add things in header
if(!empty($modSettings['global_head'])) {
$context['html_headers'] .= ' . $modSettings['global_head'] . ';
}
// Add things in footer
if(!empty($modSettings['global_foot'])) {
$context['insert_after_template'] .= ' . $modSettings['global_foot'] . ';
}

I am not so sure about the middle one after the linktree though I supposed you can use either addAfter or buffer. To use buffer, you can add another function like this:

Code: [Select]
function GHF_Mid(&$buffer)
{
// Globalize what you need
global $modSettings, $context;

if (isset($_REQUEST['xml']) || $context['current_action'] == 'printpage') return $buffer;

$ghf = array();

// Description
if(!empty($modSettings['global_mid'])) {
// Define the old and the new title
$title_old = '<div id="main_content_section"><a id="skipnav"></a>';
$title_new = '<br /><div>' . $modSettings['global_mid'] . '</div>
<div id="main_content_section"><a id="skipnav"></a>';
$gfh[$title_old] = $title_new;
}
// Now let's change the title, if we're allowed to
return str_replace(array_keys($gfh), array_values($gfh), $buffer);
}

Or if you wish to use layer addAfter you can create another function[4] something like this:

Code: [Select]
function GHF_middle()
{
// Globalize what you need

// Load what you need
// Add things in middle
if(!empty($modSettings['global_mid'])) {
loadTemplate('GHF);
$template_layers->addAfter('template_body_above', 'GHF_middle');
}
}

That cover your changes in the template file. Your language file should be a simple GHF.english.php and put all the contents inside it.

Code: [Select]
<?php
/**
 *
 * @author  Your name, email etc
 * @license Your license
 * @mod     Your mod name
 *
 */

$txt['global_head'] = 'Add content to the <head></head> tags:';
$txt['global_mid'] = 'Add content below linktree:';
$txt['global_foot'] = 'Add content to the footer:';
$txt['global_copy'] = 'Add custom copyright to the footer:';

?>

Your addon settings can be made inside the GHF.subs.php by adding another function:

Code: [Select]
function GHF_Settings(&$config_vars)
{
// Load the language
loadLanguage('GHF');

// Add the settings
$ghf = array(
array('large_text', 'global_head', '4'),
array('large_text', 'global_mid', '4'),
array('large_text', 'global_foot', '4'),
array('text', 'global_copy', '30'),
'',
);

// Insert after all available slice.
$first = array_slice($config_vars, 0);
$config_vars = array_merge($first, $ghf);
}

Then you hook file, GHF.hooks.php.

Code: [Select]
<?php
/**
 *
 * @author  Your name, email etc
 * @license Your license
 * @mod     Your mod name
 *
 */

// If we have found SSI.php and we are outside of ELK, then we are running standalone.
if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('ELK'))
require_once(dirname(__FILE__) . '/SSI.php');

// If we are outside ELK and can't find SSI.php, then throw an error
elseif (!defined('ELK'))
die('<b>Error:</b> Cannot install - please verify you put this file in the same place as Elkarte\'s SSI.php.');

if (ELK == 'SSI')
db_extend('packages');

// Define the hooks
$hook_functions = array(
'integrate_buffer' => 'GHF_Mid|SOURCEDIR/addons/GHF.subs.php',
'integrate_load_theme' => 'GHF_Main|SOURCEDIR/addons/GHF.subs.php',
'integrate_general_mod_settings' => 'GHF_Settings|SOURCEDIR/addons/GHF.subs.php',
);

// Adding or removing them?
if (!empty($context['uninstalling']))
$call = 'remove_integration_function';
else
$call = 'add_integration_function';

// Do the deed
foreach ($hook_functions as $hook => $function)
$call($hook, $function);

if (ELK == 'SSI')
   echo 'Congratulations! You have successfully installed this mod!';
?>

Lastly, you should have something like this in your package-info.xml
Code: [Select]
	<install for="1.0 - 1.0.99">
<readme type="file" parsebbc="true">GHF.readme.txt</readme>
<require-file name="GHF.english.php" destination="LANGUAGEDIR/english" />
<require-file name="GHF.subs.php" destination="SOURCEDIR/addons" />
<code>GHF.hooks.php</code>
<redirect url="?action=admin;area=addonsettings" timeout="499">Redirecting to Addons Settings...</redirect>
</install>
<uninstall for="1.0 - 1.0.99">
<readme parsebbc="true">GHF.readme.txt</readme>
<remove-file name="LANGUAGEDIR/english/GHF.english.php" />
<remove-file name="SOURCEDIR/addons/GHF.subs.php" />
<code>GHF.hooks.php</code>
<redirect url="?action=admin;area=packages" timeout="499">Redirecting to Package Manager...</redirect>
</uninstall>

That are the rough ideas on making it a hook mod. However, I haven't tested it yet.
Up to the extend of what I know ony. Do correct me if I am wrong.
This is an old style until I understand the other integration methods. Lol.
Is this correct @emanuele as I haven't used this before?
Not quite practical to me since you must create own template file for this.