News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Help needed on re-coding a mod

Started by Burke ♞ Knight, September 02, 2014, 11:01:42 PM

Previous topic - Next topic

Burke ♞ Knight

Okay, I need to work on a mod I made, so it will get approved.
Here is the section that needs to be redone:

<file name="$sourcedir/BoardIndex.php">
<operation>
<search position="before"><![CDATA[$context['membergroups'] = cache_quick_get('membergroup_list', 'Subs-Membergroups.php', 'cache_getMembergroupList', array());]]></search>
<add><![CDATA[
elseif (!empty($modSettings['arrange_groupkeyorder']))
{
// Group Key Order
global $smcFunc, $scripturl;
$context['groupkeyorder'] = array();

$result = $smcFunc['db_query']('', '
SELECT online_color, group_name, id_group
FROM {db_prefix}membergroups',
array()
);
    while ($row = $smcFunc['db_fetch_assoc']($result))
    {
if (allowedTo('view_mlist'))
$link = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
else
$link = !empty($row['online_color']) ? '<span style="color: ' . $row['online_color'] . ';">'. $row['group_name'] . '</span>' : $row['group_name'];
$context['groupkeyorder'][] = array (
'id' => $row['id_group'],
'link' => $link,
);
}
    $smcFunc['db_free_result']($result);
$context['gko_group'] = explode(',', $modSettings['arrange_groupkeyorder'], 30);
foreach($context['gko_group'] AS $key => $dummy)
for ($i = 0; $i < count($context['groupkeyorder']); $i++)
if ($context['groupkeyorder'][$i]['id'] == $context['gko_group'][$key])
$context['membergroups'][] = $context['groupkeyorder'][$i]['link'];
}]]></add>
</operation>
</file>


I need to know how to get it to cache that query so that it doesn't run in every BoardIndex load.
Also, a different way to order the membergroups would be of help.

Right now, have to insert the membergroup ID's into the box in order want them, separated by commas except for the the last number. However, it is able to have added membergroups put into the box to be shown, and even ones removed from being displayed.

What I'd like, but would need help doing, would be to have the membergroups listed on a page, and checkboxes to select which to show. Then, maybe a drag and drop to arrange them, or something like that.

Now, if can rework this, would need to get the settings onto it's own page in admin section. That would be a must, if would have all that on it.

Hj Ahmad Rasyid Hj Ismail

Quote from: BurkeKnight on September 02, 2014, 11:01:42 PMNow, if can rework this, would need to get the settings onto it's own page in admin section. That would be a must, if would have all that on it.

I am not sure about others, but this last part would be easy. ;) Just create your own function for this and use hook to create your own mod settings page. Though this may not be perfect, here is what I did in Alternative Menu mod:


function AlternativeMenu_Admin(&$admin_areas)
{
global $txt;

// Load the AlternativeMenu language
loadLanguage('AlternativeMenu');

// Add our menu item
$admin_areas['config']['areas']['modsettings']['subsections']['alternativemenu'] = array($txt['AlternativeMenu'],);
}

function AlternativeMenu_Settings(&$subActions)
{
global $txt, $scripturl, $context, $modSettings, $settings;

// Load the AlternativeMenu language
loadLanguage('AlternativeMenu');

// Add AlternativeMenu Settings
$subActions['alternativemenu'] = 'AlternativeMenu';
}

function AlternativeMenu($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc, $modSettings;

$config_vars = array(
// Mod authors, feel free to modify this alternative menu but don't remove this statement and basic menu!!
array('check', 'alternativemenu'),
'',
array('check', 'altmenu_remove_help'),
array('check', 'altmenu_remove_search'),
array('check', 'altmenu_remove_profile'),
array('check', 'altmenu_remove_pm'),
array('check', 'altmenu_remove_calendar'),
array('check', 'altmenu_remove_mlist'),
array('check', 'altmenu_remove_register'),
'',
array('check', 'altmenu_replace_with_icon'),
);

// Make it even easier to add new settings.
call_integration_hook('integrate_alternative_menu_settings', array(&$config_vars));

if ($return_config)
return $config_vars;

$context['post_url'] = $scripturl . '?action=admin;area=modsettings;save;sa=alternativemenu';
$context['settings_title'] = $txt['altmenu_description'];

// Saving?
if (isset($_GET['save']))
{
checkSession();

$save_vars = $config_vars;

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
saveDBSettings($save_vars);

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: I LOVE TEA!
redirectexit('action=admin;area=modsettings;sa=alternativemenu');
}

// This line is to help mod authors do a search/add after if you want to add something here. Keyword: RED INK IS FOR TEACHERS AND THOSE WHO LIKE PAIN!
prepareDBSettingContext($config_vars);
}


Burke ♞ Knight

Load.php edit for my mod, since it does the info center, where would I edit the file?
I can not find the info center group key in Load.php whereas it was easy to find the edit area for your mod.....lol

margarett

That's just an example on how to use the cache ;)
In your case it would still go to BoardIndex.php ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Can I, um, add something interesting to this particular party?

If you're modifying the group key, the correct place to do this isn't BoardIndex.php. BoardIndex.php doesn't do the query itself, it calls cache_getMembergroupList() in Subs-Membergroups.php and for bonus points, one will notice the call from BoardIndex.php is already obtaining this via cache_quick_get... so you modify it there and you get it cached for free already.

So here's what I'd do. I'd take the bulk of that function which is:
global $scripturl, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groupCache = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
$smcFunc['db_free_result']($request);


And I'd replace it with this:
global $scripturl, $smcFunc, $modSettings;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groups = array();
$allowedTo = allowedTo('view_mlist'); // cheaper!
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($allowedTo)
$groups[$row['id_group']] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
else
$groups[$row['id_group']] = !empty($row['online_color']) ? '<span style="color: ' . $row['online_color'] . ';">'. $row['group_name'] . '</span>' : $row['group_name'];
}
$smcFunc['db_free_result']($request);

// Now rebuild it in the form expected for caching.
$groupCache = array();
if (!empty($modSettings['arrange_groupkeyorder']))
{
$group_order = explode(',', $modSettings['arrange_groupkeyorder']);
foreach ($group_order as $the_group)
{
$the_group = (int) trim($the_group);
if (isset($groups[$the_group]))
$groupCache[] = $groups[$the_group];
}
}
else
$groupCache = array_values($groups);


This way: if there's no setting defined, use standard behaviour of alpha-ordering, otherwise use the list specified, and in the process this gets to sanitise the information provided and won't be throwing errors if values aren't defined or are invalid, since we all know users do weird things sometimes like putting spaces after commas...

Burke ♞ Knight

Okay, so I replaced the BoardIndex.php edit code in the modifications file with this code to edit Subs-Membergroups.php.

<file name="$sourcedir/Subs-Membergroups.php">
<operation>
<search position="replace"><![CDATA[ global $scripturl, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groupCache = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
$smcFunc['db_free_result']($request);]]></search>
<add><![CDATA[ global $scripturl, $smcFunc, $modSettings;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groups = array();
$allowedTo = allowedTo('view_mlist'); // cheaper!
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($allowedTo)
$groups[$row['id_group']] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
else
$groups[$row['id_group']] = !empty($row['online_color']) ? '<span style="color: ' . $row['online_color'] . ';">'. $row['group_name'] . '</span>' : $row['group_name'];
}
$smcFunc['db_free_result']($request);

// Now rebuild it in the form expected for caching.
$groupCache = array();
if (!empty($modSettings['arrange_groupkeyorder']))
{
$group_order = explode(',', $modSettings['arrange_groupkeyorder']);
foreach ($group_order as $the_group)
{
$the_group = (int) trim($the_group);
if (isset($groups[$the_group]))
$groupCache[] = $groups[$the_group];
}
}
else
$groupCache = array_values($groups);]]></add>
</operation>
</file>

Burke ♞ Knight

Tried it out on a test site, and will not show the group key at all.
Nor will changes have effect if try to enable the default group key.

Arantor

I didn't test it :P

That would imply something weird with your $modSettings value though.

Burke ♞ Knight

They seem to look fine to me, but I could be missing something here.
Here is the modifications file:

<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<name>Group Key Order and Style</name>
<id>BurkeKnight:Group_Key_Order</id>
<version>1.0</version>
<file name="$languagedir/Modifications.english.php"">
<operation>
<search position="end" />
<add><![CDATA[
$txt['arrange_groupkeyorder'] = '<strong>Membergroup legend display arrangement.</strong><br />To enable the display, disable the "Show group key on board index" from Admin -> Current Theme, under Theme Settings tab.<br /><span class="smalltext">(Must be separated by comma. i.e. 1,2,8,7,6,5,4)</span>';
$txt['gkstyle_start'] = 'Opening HTML code to be used before group name:<br />You may use any HTML code to adjust the looks of the group key.';
$txt['gkstyle_end'] = 'Closing HTML code to be used after group name:<br />Be sure to close the HTML tags in reversed order.';
]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.english-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['arrange_groupkeyorder'] = '<strong>Membergroup legend display arrangement.</strong><br />To enable the display, disable the "Show group key on board index" from Admin -> Current Theme, under Theme Settings tab.<br /><span class="smalltext">(Must be separated by comma. i.e. 1,2,8,7,6,5,4)</span>';
$txt['gkstyle_start'] = 'Opening HTML code to be used before group name:<br />You may use any HTML code to adjust the looks of the group key.';
$txt['gkstyle_end'] = 'Closing HTML code to be used after group name:<br />Be sure to close the HTML tags in reversed order.';
]]></add>
</operation>
</file>

<file name="$languagedir/Help.english.php">
<operation>
<search position="end" />
<add><![CDATA[
$helptxt['arrange_groupkeyorder'] = 'Arrange the display of your membergroups legend. Enter the group id number and must be separated by comma. No comma after the last number. (i.e. 1,2,8,7,6,5,4).
To enable the display, disable the "Show group key on board index" from Admin -> Current Theme, under Theme Settings tab.';
$helptxt['gkstyle_start'] = '<strong>Enter the opening HTML code you want to use for the group key.<br />You may use any HTML code to adjust the looks of the group key.<br />Be sure to close the HTML tags in reversed order.</strong>';
$helptxt['gkstyle_end'] = '<strong>Enter the closing HTML code for the group key.<br />You may use any HTML code to adjust the looks of the group key.<br />Be sure to close the HTML tags in reversed order.</strong>';
]]></add>
</operation>
</file>

<file name="$languagedir/Help.english-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$helptxt['arrange_groupkeyorder'] = 'Arrange the display of your membergroups legend. Enter the group id number and must be separated by comma. No comma after the last number. (i.e. 1,2,8,7,6,5,4).
To enable the display, disable the "Show group key on board index" from Admin -> Current Theme, under Theme Settings tab.';
$helptxt['gkstyle_start'] = '<strong>Enter the opening HTML code you want to use for the group key.<br />You may use any HTML code to adjust the looks of the group key.<br />Be sure to close the HTML tags in reversed order.</strong>';
$helptxt['gkstyle_end'] = '<strong>Enter the closing HTML code for the group key.<br />You may use any HTML code to adjust the looks of the group key.<br />Be sure to close the HTML tags in reversed order.</strong>';
]]></add>
</operation>
</file>


<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="before"><![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[
array('text', 'arrange_groupkeyorder'),
      array('text', 'gkstyle_start', '30'),
  array('text', 'gkstyle_end', '30'),

'',
]]></add>
</operation>
</file>

<file name="$sourcedir/Subs-Membergroups.php">
<operation>
<search position="replace"><![CDATA[ global $scripturl, $smcFunc;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groupCache = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$groupCache[] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
$smcFunc['db_free_result']($request);]]></search>
<add><![CDATA[ global $scripturl, $smcFunc, $modSettings;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE min_posts = {int:min_posts}
AND hidden = {int:not_hidden}
AND id_group != {int:mod_group}
AND online_color != {string:blank_string}
ORDER BY group_name',
array(
'min_posts' => -1,
'not_hidden' => 0,
'mod_group' => 3,
'blank_string' => '',
)
);
$groups = array();
$allowedTo = allowedTo('view_mlist'); // cheaper!
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($allowedTo)
$groups[$row['id_group']] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
else
$groups[$row['id_group']] = !empty($row['online_color']) ? '<span style="color: ' . $row['online_color'] . ';">'. $row['group_name'] . '</span>' : $row['group_name'];
}
$smcFunc['db_free_result']($request);

// Now rebuild it in the form expected for caching.
$groupCache = array();
if (!empty($modSettings['arrange_groupkeyorder']))
{
$group_order = explode(',', $modSettings['arrange_groupkeyorder']);
foreach ($group_order as $the_group)
{
$the_group = (int) trim($the_group);
if (isset($groups[$the_group]))
$groupCache[] = $groups[$the_group];
}
}
else
$groupCache = array_values($groups);]]></add>
</operation>
</file>

<file name="$themedir/BoardIndex.template.php">
<operation>
<search position="replace"><![CDATA[if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
echo '
<br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';]]></search>
<add><![CDATA[if (!empty($context['membergroups']))
echo '</p><p class="last smalltext">
', $modSettings['gkstyle_start'], '' . implode(',&nbsp;', $context['membergroups']) . '', $modSettings['gkstyle_end'], '';]]></add>
</operation>
</file>

</modification>


And the database file:

groupkeyorderdb2.php

<?php

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!
defined('SMF'))
die('<b>Error:</b> Cannot update database.');

if(!
array_key_exists('db_insert'$smcFunc))
db_extend('packages');

$smcFunc['db_insert']('ignore''{db_prefix}settings',
array ('variable' => 'string''value' => 'string'),
array ('arrange_groupkeyorder''1,2,8,7,6,5,4'),
array()
);

?>

Arantor

Remember: it's *cached*, that means it doesn't apply it live!

Also, there's really no need to have half of what your installation file does. This is all you actually need in your case:

<?php

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!
defined('SMF'))
die('<b>Error:</b> Cannot update database.');

if (empty(
$modSettings['arrange_groupkeyorder']))
updateSettings(array('arrange_groupkeyorder' => '1,2,8,7,6,5,4'));
?>


Also, I didn't initially realise you wanted to allow post count groups on the list, which changes things slightly as these are ignored by default. Oh and since you wanted to show groups without a colour attached, needed to adjust that as well since again they're ignored. The only restrictions left are hidden groups and the board moderator group which are very special and cannot be linked to anyway.

Try this. This *has* been tested. ;)

global $scripturl, $smcFunc, $modSettings;

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name, online_color
FROM {db_prefix}membergroups
WHERE hidden = {int:not_hidden}
AND id_group != {int:mod_group}
ORDER BY group_name',
array(
'not_hidden' => 0,
'mod_group' => 3,
)
);
$groups = array();
$allowedTo = allowedTo('view_mlist'); // cheaper!
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if ($allowedTo)
$groups[$row['id_group']] = '<a href="' . $scripturl . '?action=groups;sa=members;group=' . $row['id_group'] . '" ' . ($row['online_color'] ? 'style="color: ' . $row['online_color'] . '"' : '') . '>' . $row['group_name'] . '</a>';
else
$groups[$row['id_group']] = !empty($row['online_color']) ? '<span style="color: ' . $row['online_color'] . ';">'. $row['group_name'] . '</span>' : $row['group_name'];
}
$smcFunc['db_free_result']($request);

// Now rebuild it in the form expected for caching.
$groupCache = array();
if (!empty($modSettings['arrange_groupkeyorder']))
{
$group_order = explode(',', $modSettings['arrange_groupkeyorder']);
foreach ($group_order as $the_group)
{
$the_group = (int) trim($the_group);
if (isset($groups[$the_group]))
$groupCache[] = $groups[$the_group];
}
}
else
$groupCache = array_values($groups);

Burke ♞ Knight

Okay, working now, with the default enabling of the key, which I really had wanted anyway, instead of disabling it. :)

Thank you, Arantor, my friend. :)

Now, one more thing the Cust team mentioned:

QuoteAbout the Group Style, you should process the user input in Modification Settings:
* Make sure they don't use wrong tags, which can break the page --> </html> or </body>
* Make sure the opened tags are closed and in the respective order. (this, being highly recommended, isn't required)

How would I do these?

Arantor

I have no idea what they are referring to. I have seen no such code referenced here.

Burke ♞ Knight

It's the style part, I had shortened the txt strings, as they seemed to have flooded the error log when they were longer.

', $modSettings['gkstyle_start'], '
and
', $modSettings['gkstyle_end'], '

Used to be: group_key_style_1 and group_key_style_2

<file name="$sourcedir/ManageSettings.php">
<operation>
<search position="before"><![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[
array('text', 'arrange_groupkeyorder'),
      array('text', 'gkstyle_start', '30'),
  array('text', 'gkstyle_end', '30'),

'',
]]></add>
</operation>
</file>

Arantor

I don't get what you're doing with these settings...

Burke ♞ Knight

The mod will also let you change the style for group key in board index.
Has 2 slots, one for HTML code placed before the key, and one for HTML code placed after the key.

You may use any HTML code to adjust the looks of the group key.

Be sure to close the HTML tags in reversed order.
Example: In Start Box: <strong><em>
In End Box: </em></strong>

I also would like to get the above example into the text string for the settings, but not sure how to get it to display the html code instead of use it.

Arantor

OK, so ultimately this is about ensuring what tags are used by the people who use that, and ensuring what tags they are allowed to use. Using </html> or similar in those boxes would be bad.

The only problem with that is that it's an extremely difficult thing to do properly, unless you strip it down to a truly tiny list of safe tags.

What I would suggest is that before saving the relevant things, you'd push them through strip_tags. Specifically, if $string contains the relevant option, strip_tags($string, '<div><span><strong><em>');

This will allow div, span, strong and em and remove all other tags.

The item about ensuring order, that's really hard to do well.

Burke ♞ Knight

Okay, where exactly would I place this?

strip_tags($string, '<style><span><strong><em>');

<div> tags make unexpected extra line break after, so that would be one I'd want not to be allowed, but style, span, strong, and em should all be okay.

EDIT:

Also, I would like to get the above example into the text string for the settings, but not sure how to get it to display the html code instead of use it. It is in the readme, but I'd like it also on the settings page, if can.

Arantor

You can't use <style> in line in a page. Not allowed.

As for where you would use it, you would use it during the save routine. $string is more a placeholder for descriptive purposes. In your case, I'd assume use of $_POST['gkstyle_start'] and $_POST['gkstyle_end'] instead before the saveDbSettings() call.

Displaying it on the mod's page is very complicated, lots of permutations, most of which depend on how much text you want to write.

Burke ♞ Knight

Okay, the part where the style is done, is just in BoardIndex.template.php

<file name="$themedir/BoardIndex.template.php">
<operation>
<search position="replace"><![CDATA[if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
echo '
<br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';]]></search>
<add><![CDATA[if (!empty($context['membergroups']))
echo '</p><p class="last smalltext">
', $modSettings['gkstyle_start'], '' . implode(',&nbsp;', $context['membergroups']) . '', $modSettings['gkstyle_end'], '';]]></add>
</operation>
</file>


However, we do have the php file for the db: groupkeyorderdb2.php

<?php

if (file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
elseif (!
defined('SMF'))
die('<b>Error:</b> Cannot update database.');

if (empty(
$modSettings['arrange_groupkeyorder']))
updateSettings(array('arrange_groupkeyorder' => '1,2,8,7,6,5,4'));
?>


As for the text string for settings page, if I could have it display the tags that are allowed, I can make it fit. Here is what is there now:

$txt['gkstyle_start'] = 'Opening HTML code to be used before group name:<br />You may use any HTML code to adjust the looks of the group key.';
$txt['gkstyle_end'] = 'Closing HTML code to be used after group name:<br />Be sure to close the HTML tags in reversed order.';


If can display the tags, then would not need this line after the line break in the start one:
You may use any HTML code to adjust the looks of the group key.

It could be replaced by the tags allowed.

Illori

an example from 2.1


$helptxt['enablePostHTML'] = 'This will allow the posting of some basic HTML tags:
<ul class="normallist">
<li>&lt;b&gt;, &lt;u&gt;, &lt;i&gt;, &lt;s&gt;, &lt;em&gt;, &lt;ins&gt;, &lt;del&gt;</li>
<li>&lt;a href=&quot;&quot;&gt;</li>
<li>&lt;img src=&quot;&quot; alt=&quot;&quot; /&gt;</li>
<li>&lt;br /&gt;, &lt;hr /&gt;</li>
<li>&lt;pre&gt;, &lt;blockquote&gt;</li>
</ul>';

Arantor

Yes but that requires you getting that content into the Help language file.

There are, broadly, 3 options for doing help text on a mod.
1. in the Help language file and tell it to use a (?) icon.
2. under the main item's text, only really suited to short messages.
3. under the main textbox'x text, suited to slightly longer messages, even if it is a bit complicated.

Lemme know which you'd be interested in doing. An example of the third option is attached as taken from LevGal.

Burke ♞ Knight

#2 should do it.

Line would be:

$txt['gkstyle_start'] = 'Opening HTML code to be used before group name:<br />Allowed HTML Tags: <strong></strong><em></em><span></span>';

I think those would be the only tags really needed for this, as can't use <u></u> as it underlines the whole line, and not just the text.

Illori

check the example i gave, it has the tags in it using html entities

Burke ♞ Knight

However, I need them on the settings page, not the help popup, as many people do not even click the ? to see it...LOL

Line would be:

$txt['gkstyle_start'] = 'Opening HTML code to be used before group name:<br />Allowed HTML Tags: &lt;strong&gt ;&lt;/strong&gt; &lt;em&gt; &lt;/em&gt; &lt;span&gt; &lt;/span&gt; ';

Arantor

What you're describing is not option 2, though it would work just fine if you replace the relevant < and > with &lt; and &gt;

By putting that as the main text item attached to the relevant option it should just work even if it will be ugly as sin in the admin panel search.

Burke ♞ Knight

Okay, mod updated on mod site.
Like stated in PM to Cust team, if people use tags that are not listed, then, basically, that is on them, as I have it clearly stated on mod settings page which tags can be used.

Allowed HTML Tags: <strong></strong> <em></em> <span></span>


Arantor

If you're using the strip-tags code, that's all they're able to use anyway ;D

Burke ♞ Knight

Quote from: Arantor on September 04, 2014, 04:44:50 PM
You can't use <style> in line in a page. Not allowed.

As for where you would use it, you would use it during the save routine. $string is more a placeholder for descriptive purposes. In your case, I'd assume use of $_POST['gkstyle_start'] and $_POST['gkstyle_end'] instead before the saveDbSettings() call.

Displaying it on the mod's page is very complicated, lots of permutations, most of which depend on how much text you want to write.

I still have no idea where to put it....LOL

Arantor

And I thought I'd told you already :P

The problem is, if I tell you how to do all of it, it's not really a learning experience for you, is it?

Burke ♞ Knight

ManageSettings.php

Wait, this is a bit of a trick question issue, isn't it?
I'd place it with the code I already have, since that is right above a save call anyway, right?

So would be:

$_POST['gkstyle_start'] = array('text', 'gkstyle_start', '30'),
                $_POST['gkstyle_end'] = array('text', 'gkstyle_end', '30'),


I hope I'm getting this, because I have never done this type of coding in a mod before....LOL

Arantor

No, that's not what I said at all. Nor is it a trick question.

You have the normal $config_vars definitions, which you had just fine.

Now, what I was telling you to do was put in $_POST['gkstyle_start'] = strip_tags($_POST['gkstyle_start'], '<span><strong><em>');

And put that before the call to saveDbSettings()...

Burke ♞ Knight

Like this:

Code (Find) Select
// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
                saveDBSettings($save_vars);


Code (Replace With) Select
// This line is to help mod authors do a search/add after if you want to add something here. Keyword: FOOT TAPPING SUCKS!
                $_POST['gkstyle_start'] = strip_tags($_POST['gkstyle_start'], '<span><strong><em>');
saveDBSettings($save_vars);

Arantor

Yup, to run the stripping of non-valid tags before it gets saved to the database.

Burke ♞ Knight

So now, this mod should be 100% approval ready. :)

Thank you my friend...
Sorry if did not understand you, but this is all new parts for me to coding.
Maybe, it'll help me make some more mods, too. :)

Arantor


Hj Ahmad Rasyid Hj Ismail

A really useful tip. A new knowledge for me today. ;)

Just a little add up that I learn from other mods, BurkeKnight, you can also give description to your mod using the following code:

// Mod authors, feel free to modify this alternative menu but don't remove this statement and basic menu!!
array('desc', 'gkstyle_mod_description'),


Add your language string for it and this will place a description for your mod settings page.

One extra idea that I have, but not tested, is to give some color / styling to this description box. Or may be there is some other way to do it better, yet I don't know :).

Arantor

There are more ways than even that. Consider the attached. This is using the very same template, almost, as the standard template for admin use.

Snippet of code:
// Define the generic master settings.
$config_vars = array(
array('title', 'levgal_quotas'),
array('desc', 'levgal_quotas_desc'),
array('text', 'lgal_max_space'),
array('message', 'lgal_max_space_note'),
);


First up, we have use of 'title' elements. That's how the big section dividers (Images, Audio, Video etc) are done.

Then there's a 'desc' element at the top (the one that says "This page allows you to configure...")

Then the textbox, which is the regular textbox with its setting text.

Then there's one of type 'message', which is a message that will float up on the right-hand side under the message there, whatever that happens to be. See, there's lots of options ;)

As for the magical fieldsets, they're another template, invoked by way of the 'callback' type that lets you call an arbitrary function to display a setting.

Burke ♞ Knight

Well, since this is going into the basic mod settings page, and not a page of it's own, I think it is okay as it is, as these pics will show. :)

Hj Ahmad Rasyid Hj Ismail

Awesome Arantor. Thank you very much for sharing small pieces of the "cake". This really made my day. ;)

Well, BurkeKnight, you can always create your own mod settings page in the future as the samples are already given. :)

Burke ♞ Knight

Indeed so. :)

I just did not think it was right to make own page for 3 settings, on this mod.
However, I do have plans on a mod that will need it's own settings page. :)

Arantor

If you want to see the callback in action, take a look at the anti spam page, where it uses one of those to make the anti-spam questions work ;) Note that using a callback will require you to do your own work in terms of validation and saving items.

Adding individual pages to the admin area via Modification Settings is fine. But the minute you start building entire areas, it gets real ugly, real fast :( I knew there was a reason I hadn't done it since SimpleDesk :P

Burke ♞ Knight

Okay, almost done here, but found an issue:

<file name="$themedir/BoardIndex.template.php">
<operation>
<search position="replace"><![CDATA[if (!empty($settings['show_group_key']) && !empty($context['membergroups']))
echo '
<br />[' . implode(']&nbsp;&nbsp;[', $context['membergroups']) . ']';]]></search>
<add><![CDATA[if (!empty($context['membergroups']))
echo '</p><p class="last smalltext">
', $modSettings['gkstyle_start'], '' . implode(',&nbsp;', $context['membergroups']) . '', $modSettings['gkstyle_end'], '';]]></add>
</operation>
</file>


As is, if the style boxes are left empty, we get errors:

Quote8: Undefined index: gkstyle_end
Themes/default/BoardIndex.template.php
Line: 442

I am guessing that SMF is balking at the fact the fields are empty, so I need to know what to do, to fix this.

Hj Ahmad Rasyid Hj Ismail

Have you defined this $modSettings['gkstyle_end']? If this is an empty field to be filled by the user, then you need to use condition that if it is not empty then display it, otherwise leave it empty. Something like !empty($modSettings['gkstyle_end']) ? $modSettings['gkstyle_end'] : ''

Advertisement: