First, consider if your task can be accomplished by adding fields and editing templates. Most tasks can.
If simply adding fields and custom templates doesn't do the job for you, and you know a little PHP, perhaps you want to customize the code to create a new feature.
Any files placed in the /modifications/ directory will be included in every page. If possible, put your modifications here and just conditionalize when the code executes appropriately... by using the modifications directory you will make upgrades easy on yourself. See
this article for more detail.
Certain important functions can be overridden with
plugins... plugins can handle any manipulations you wish to do on an object before it gets added, for example.Plugins can be used to add new functionality or change existing functionality.
Suppose you want to add the ability to show the number of comments per day a member has posted. Once you know that all methods of a class are available as template variables, your first thought will be to open /classes/member.php to add a new method. In order to keep your changes upgradeable, though, you should use a
pseudomethod instead -- this will be effectively the same, but stored in a different file so that it's unaffected by upgrades.
The /classes/ directory is your friend. In the /classes/ directory you can find the files that control how links, categories, comments and members work. As of 5.0, most of the classes are children of classes/generic.php's class. Again though, adding methods is best done with pseudomethods.
If you ever need to get information from a particular link, category, comment or member in the code you're writing, you can get this easily by declaring an object, passing it 'id' and the id of the record you want. Assuming $id contains the id you want:
$alink = new onelink('id', $id);
$acategory = new category('id', $id);
$acomment = new comment('id', $id);
$amember = new member('id', $id);
Using $acategory->name thereafter in your code, for example, would give you the name of the category. All the database fields become attributes of the object.
If want to grab a large number of items at once using a mysql query, you can use the $db object (if in a function, be sure to use global $db; to get access to it). See classes/database.php for the available $db methods. This code will grab the links with more than 5 votes, in order of most votes first, limited to only the first 5, and will create objects for them in the loop which you could process in some way if you wished:
$one = 'modifications_guide - {LINKRATING}<br />'; // example content
$query = $db->select($settings->linkfields, 'linkstable', 'votes>5', 'ORDER BY votes DESC', 'LIMIT 0,5');
$num = $db->numrows($query);
for ($x=0; $x<$num; $x++)
{
$alink = new onelink('row', $db->row($query));
$all .= $alink->replacements($one);
}
At the end of the for loop, you'll have one line for each link that has more than 5 votes displayling the title and rating, contained in $all.
If you don't want to waste time learning the special methods of $db, you can just pass SQL directly to the $db->query($SQL) method (though when doing that you'll still need to use the appropriate variable for the table name, such as $linkstable for the links table).
Some generalizations about classes: the "add" function will control how the object is added to the database (see the beforeaddition and afteraddition pluggable functions to make upgradeable changes around additions of objects), and the "update" function will control how fields are updated. "deletethis" does deletions. All class values and functions are public, since it was originally designed for PHP 4. To create a new object you use $obj = new type('new', 'new'); and it will automatically inherit any field values which are among the $_POST values. If you want all attributes blank, not inheriting $_POST, use $obj = new type('blank', 'blank');. As the example above notes, $obj = new type('row', $db->row($query)); allows you to create an object based on a row of data, which can be quicker than processing by id number.
To register a new member, you can simply do this:
$mem = new member('new', 'new');
$mem->assigndefaults();
$mem->name = 'Some Username';
$mem->password = 'Some Password';
$mem->email = 'some@email.com';
$mem->register();
Experiment, be creative, and ask for help on the forum when needed.
If you want to add new sorts of data, you can
drop in new tables.
To change how redirection works after doing stuff, see
adding logic to redirects.
If you want, you can
use PHP in templates.
If you must make alterations to the native source code, please see
creating modification files for a way to maintain those changes effectively.
3.63/5 based on 8 votes. The median rating is 5.