Custom Source Page

Started by Matthew K., December 10, 2009, 12:43:54 AM

Previous topic - Next topic

Matthew K.

Hello,

I am trying to write up a custom source page for the Admin section, as a mod I am developing definitely needs it's own space. I have taken a look at how other mods do it and done my best to replicate it as best as I could. - I have just very recently started working heavily with Source files so I'm still "new" to Sources.

In Snow.php (my Source file) I have the following:

<?php

if (!defined('SMF'))
die('Hacking attempt...');

function 
project_snow()
{

// Lets start with one text field for now.
array ('text''let_it_snow'),

}

?>


In Admin.php I found this:
'current_theme' => array(
and added this before: 'snow' => array(
'label' => $txt['Snow'],
'file' => 'Snow.php',
'function' => 'project_snow',
'icon' => 'snowflake.png',
'custom_url' => $scripturl . '?action=admin;area=snow;sa=admin',
'icon' => '',
'subsections' => array(
'admin' => array($txt['Snow']),

),
),


I know something definitely needs to be changed with "custom_url".

Help would be appreciated.
Labradoodle-360

Arantor

How many options are we talking and where were you planning on putting this in the menu?

Matthew K.

More than I thought at first, but a total of 20 inputs, text or checkboxes.
I don't really care where the menu goes, so whatever is fine for position.

Labradoodle-360

Arantor

See, you really don't need to create a whole new page in the sources (and associated template) for that. Also requires you do all your own input validation and sanitisation.

You can create new admin pages with far less work; several of my mods do just that.

Matthew K.

Okay, what is a mod that does it? I'll take a look at how it's built :)

Arantor

Auto Lock Old Topics creates its own admin page inside the Modifications area.

Share This Topic, which I gave away, creates a page elsewhere in the admin panel (and covers how to do it in both 1.1 and 2.0)

Matthew K.

Thanks Arantor! I'll take a look.

Matthew K.

Okay, I looked inside Share this topic, a lot simpler than adding my own Source.

ManageSettings.php Code added for page:function ModifyShareTopicSettings($return_config = false)
{
global $txt, $scripturl, $context, $settings, $sc;

$sites = array('facebook', 'myspace', 'delicious', 'digg', 'reddit', 'stumbleupon', 'twitter', 'technorati', 'magnolia', 'google', 'yahoo');
$config_vars = array();

foreach($sites as $site) {
$config_vars[] = array('check', 'share_' . $site);
}

if ($return_config)
return $config_vars;

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

saveDBSettings($config_vars);
writeLog();

redirectexit('action=admin;area=featuresettings;sa=sharetopic');
}

$context['post_url'] = $scripturl . '?action=admin;area=featuresettings;save;sa=sharetopic';
$context['settings_title'] = $txt['share_default_menu'];

prepareDBSettingContext($config_vars);
}


I obviously change "Share Topic" and other Share Topic text to my text. But where $sites = array('facebook', 'myspace', 'delicious', 'digg', 'reddit', 'stumbleupon', 'twitter', 'technorati', 'magnolia', 'google', 'yahoo');
$config_vars = array();

foreach($sites as $site) {
$config_vars[] = array('check', 'share_' . $site);
that code is, I put my fields, correct?

Matthew K.

Basically, I customize the file to suit my mod name and then remove: $sites = array('facebook', 'myspace', 'delicious', 'digg', 'reddit', 'stumbleupon', 'twitter', 'technorati', 'magnolia', 'google', 'yahoo');
$config_vars = array();

foreach($sites as $site) {
$config_vars[] = array('check', 'share_' . $site);
putting my fields in.

Arantor

Yes, you populate $config_vars, just as you have in other edits to ManageSettings.php.

Advertisement: