Navigation

Views

Search
 

Toolbox

Module Tutorial

From Documentation

Revision as of 21:12, 22 May 2006; view current revision
←Older revision | Newer revision→

What do I need?

This tutorial assumes you have a basic understanding of 68 Classifieds and php. Also you will need 68 Classifieds installed and some type of php editor. Your first module

Your first module

To start building our module we have to create a new directory and few php files. The first step is to name your module, and in this case it will be named “Module Test”. So we create a directory inside the modules folder named module_test. Next create a new php file named config.php that will reside in that folder.

The config.php file should look like this:

<?php 
$data['module']['name'] = "module_test";
$data['module']['displayname'] = "Test Module ";
$data['module']['description'] = "This is my test module ";
$data['module']['version'] = "v0.1";
$data['module']['admin_capable'] = "0";
$data['module']['user_capable'] = "0";
?>

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 seperate from 68 Classifieds. The admin_capable and user_capable determine if the module should be accessed from either location. Since both of these have a 0 they do not have an option for the user or administrator to enter information.

After you have created the config.php file we will next create a mod_user.php file. The mod_user file includes hooks that are called throughout 68 Classifieds. For our example module we want to email your buddy whenever a listing is added. That way you can brag about how many new listings you get. ;)

So create the file and include this:

function module_test_listing_added($id)
{
global $db;
$url='<a href="'.URL.'/viewlisting.php?view='.$id.'">';
$url.=URL.'/viewlisting.php?view='.$id.'</a>';
$message = "Hey my friend,\n";
$message .= "I have a new listing added to my site:\n";
$message .= $url
$mail = new Mailer();
$mail->AddAddress('[email protected]);
$mail->Subject = 'My Subject';
$mail->IsHTML(true);
$mail->Body = $message;
$mail->Send();
$mail->ClearAddresses();
}

The function is named module_test_listing_added which comes from two locations. First the module_test is the name of the module we entered in the config.php file. The listing_added comes from the file includes/classes/kernel/Listings.php:

$modules->call_hook('listing_added', $result->insertID());

These hooks are throughout the script and run through the active modules to find a function like listed above.