These variables should be pretty self explanatory. However the name should only contain letters, numbers, dashes, or hyphens. Do not enter any spaces here. The version is your internal version number separate from 68 Classifieds. The admin_capable and user_capable determine if the module should be accessed from either location. Since the admin_capable has a value of 1 that means it can be accessed through the administration. Where as the user_capable has a 0 which means this module only includes an admin file.
==== Create an init.php file ====
The init.php file is responsible for installing items into the database and uninstalling if the user decides to remove the module.
The init.php file can have three functions and they are:
install()
upgrade()
uninstall()
These functions are not required if you do not need to insert any items into the database.
For our module this file will include the following code:
query($sSQL);
$class_tpl->assign('msg', 'Everything installed successfully.');
}
?>
==== Creating a hooks.php file ====
The hooks.php file is responsible for integrating functionality in the core of the script. Here is an example file:
register('admin_tpl_layout_category', $this, 'admin_links');
}
function admin_links()
{
echo 'Custom Cats';
}
}
?>
This code basically does two things. First in the constructor it registers the event you want and then when that hook is called it runs your method. In the example above we register admin_links to the admin_tpl_layout_category hook. Once this hook is called the admin_links method is ran. In this case it adds a new link to the admin navigation.
==== Creating an admin.php file ====
The admin.php file is not always needed but if you have $data['module']['admin_capable'] set in the config file then it would be required. Our admin.php file will be responsible for showing the user a list of their categories and a way to add the custom template for each one. Here is the completed file:
query($sSQL);
$rs=$result->fetch();
$class_tpl->bulkAssign($rs);
$result->freeResult();
$location = FILESYSTEM_PATH .'modules/customcats/templates/cattemplates/';
if ($handle = opendir($location))
{
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != ".." && $file!="CVS" && $file!="index.htm")
{
$filelist[]=$file;
}
}
closedir($handle);
}
$class_tpl->assign('files', $filelist);
$class_tpl->assign('body','customcats_edit.tpl.php');
}
elseif (isset($_POST['action']) && $_POST['action']=="save")
{
$sSQL = 'UPDATE '.PREFIX.'categories SET ccTemplate="'.$_POST['ccTemplate'].'" WHERE id='.(int)$_POST['id'];
$result=$db->query($sSQL);
//sucessfull
$location="modules.php?mod=customcats";
$class_tpl->assign('title',LANG_FORWARD_SUCESS);
$class_tpl->assign('forward',TRUE);
$class_tpl->assign('location',$location);
$class_tpl->assign('body','forward.tpl.php');
}
else
{
$tree=$Categories->getAdminCatTree("", 0, TRUE);
$class_tpl->assign("results", $tree);
$class_tpl->assign('body','customcats_browse.tpl.php');
}
$class_tpl->displayTemplate();
?>
As you can see this file has three steps. Viewing the category list, editing a category, and updating the database.
==== Creating a language file ====
The next step is to create our language file. For this tutorial we will only create an english language file but it should give you the idea on how it is setup.
Inside your module folder you should create another folder named language and then an english.php file. For this example it will be located here: modules/customcats/language/english.php
Here is what this language file looks like:
One thing to keep in mind is that you do not want to use the same defined variable as another. So please prefix your define statements like done here.
==== Creating the templates ====
The templates for your modules will all be located in the modules/customcats/templates folder. Because 68 Classifieds uses a layered approach they will be automatically loaded when the admin or index file is ran.
For our module we will create two templates. customcats_browse.tpl.php and customcats_edit.tpl.php
Here is what I have included in each:
customcats_browse.tpl.php
{$smarty.const.LANG_CC_TITLE}
{$smarty.const.LANG_ID}
{$smarty.const.LANG_FULLNAME}
{$smarty.const.LANG_ACTIONS}
{foreach from=$results item="entry" name=status}
{$entry.id}
{$entry.name}
{$smarty.const.LANG_MODIFY}
{foreachelse}
{$smarty.const.LANG_NO_RESULTS}
{/foreach}
customcats_edit.tpl.php
{$name}
{if $success}
{$smarty.const.LANG_SETTINGS_SAVED}
{/if}
For this module I also created a new folder named cattemplates located inside the templates folder. Here is the path:
modules/customcats/templates/cattemplates
This will be the place for the administrator to save their custom templates. This way it will keep it separate.