Geeklog's way of doing things

From GeeklogWiki
Revision as of 21:09, 28 June 2004 by Tomw (talk | contribs)

Jump to: navigation, search

All of Geeklog's php files are pure php. PHP allows you to use php as a scripting language imbedded in html files but this is not how Geeklog does it. All of Geeklog's php files must have <?php as the first five characters and end with ?>. Failure to structure your Geeklog files this way will cause session and header errors. Geeklog attempts as much as possible to have only php code in the php files. Two of the conventions used in Geeklog to accomplish this are the use of templates and language files.

Time will be well spent by the Geeklog plugin or block developer to become familiar with several Geeklog libraries. The following section outlines the more important or frequently used libraries, functions and standards.



lib-common.php:

The Geeklog plugin or block developer should have a good understanding of lib-common.php which contains most of the display routines as well as some other general purpose routines. All of the Geeklog display routines return html. They do not contain echos or prints themselves. The way the Geeklog system is designed; you usually put your code between Geeklog display routines. For example: code to display a page would look like this:

$display = COM_siteHeader();
$display .= COM_startBlock("Title of Your Block");
$display .= "Some words";
$display .= somefunction();
$display .= COM_endBlock;
$display .= COM_siteFooter(true);
echo $display;

A summary of commonly used Geeklog functions are described below but reference the attached lib-common.php documentation for further examples.



lib-security.php:

The lib-security.php file contains the interface routines to the security system used in Geeklog. See the attached lib-security.php documentation. There are several SEC type functions that you may want to use in your projects. The table Commonly Used Geeklog Functions at the end of this section defines a couple of the more commonly used functions.



lib-database.php:

All database access should take place through the database abstraction in lib-database.php and table names should be accessed through the $_TABLES array. The table definitions in this array will then include whatever table prefix this site is using. You should ensure that your plugin or block uses the $_TABLES['mytable'] for all Database access related functions.

  • Block developers and site admins installing the block need to edit the lib-database.php program and add the new $_TABLES entries for your block tables. Ensure you follow the same standard by using the $_DB_table_prefix.
  • Plugin developers need to define their tables in the plugin config.php file. You have the ability to use the $_TABLES array or use your own plugin specific array to maintain the table definitions. It's recommend that your arrays use a name such as _XX_TABLES, where XX are two letters to describe your plugin. Once the plugin is installed and enabled, the tables defined in the config.php for the plugin are automatically known as globals.

lib-plugins.php:

This library contains all the code used to interface your plugin or block to Geeklog. You will not call any code from here directly. The functions in this file are called by the Geeklog main programs as they are used to call all plugins and are used to resolve the plugin name and check if your plugin has a particular function. You will usually only have to look at this file to understand some nuance of the implementation. See the documentation for functions.inc and the original plugin documentation for further help.



How your Plug-in or Block Interacts with Geeklog:

The program lib-common.php is the key to all interaction with Geeklog. It includes Geeklog's config.php and the rest of the Geeklog code libraries.

  • At the top of lib-common.php is an include of lib-custom.php. This is where you place all your block functions. They are then included when the site index.php is called.
  • At the very end of lib-common.php is a check for all enabled plugins. A plugin is registered with Geeklog when it has a record in the plugins table and the field pi_enabled is true. For all registered and enabled plugins, the code in lib-common.php will include the functions.inc file for each plugin. This is why the naming convention and location for each plugin file is strictly defined. All code libraries or configuration files your plugin needs should be included in your functions.inc. Since the plugins config.php is now also included this way - via the include in functions.inc - the variables in your plugin config.php become global and can be referenced in your plugin functions.

Common Global Variables

There are a few commonly used globals within Geeklog that you will want to use and reference. The following table outlines the more frequently used ones and its recommended that these be used instead of hard coding paths and table names in your links or project code.

 Variable   Description
$_CONF['path_html'] Fully qualified path to your sites public_htmk path
$_CONF['site_url'] Full URL to your sites public_html directory
$_CONF['site_admin_url'] Full URL to your sites admin directory
$_USER['uid'] Current user ID. A uid of 1 is an anonymous user
$_TABLES['tablename'] A array of geeklog tables with the site prefix defined.

Commonly used Geeklog functions

The following is a list of commonly used Geeklog functions that as developers we use and recommend you become more familiar with and use in your development projects. You will find example usage of these functions throughout the Geeklog code.

 Function Name</td>

      Description</td>
 </tr>
   <p align="left"> COM_siteHeader</td>
Display the main site header and
   optionally if 'none' is passed do not display the left blocks</td>
 </tr>
   <p align="left"> COM_siteFooter</td>
Display the main site footer and
   optionally if 'true' is passed display the right blocks</td>
 </tr>
   <p align="left"> COM_startBlock</td>
Formats the block title using the
   selected theme - pass the title, helpfile if any and optional block theme to 
   apply if you do not want to use default</td>
 </tr>
   <p align="left"> COM_endBlock</td>
Formats the block footer using
   the selected theme or the optional block theme if you do not want to use 
   default</td>
 </tr>
 COM_errorLOG</td> Use to format an error message or
   use for debugging - view output in <geeklog_dir>/logs/error.log</td>
 </tr>
   <p align="left"> DB_query</td>
Execute a formatted SQL query and
   return the record set to an array of records (which is also an array)</td>
 </tr>
   <p align="left"> DB_fetchArray</td>
Retrieve a record as an array
   from the returned record set - which DB_query returned.</td>
 </tr>
   <p align="left"> DB_numROWS</td>
Returns the number of records
   retrieved by the DB_query result</td>
 </tr>
 DB_getItem</td> Retrieve one record as an array.
   Pass a formatted SQL stmt with WHERE clause to retrieve one record</td>
 </tr>
 COM_checkHTML</td> Use to strip out $, <, > , [code]
   and replace with the HTML codes</td>
 </tr>
 COM_checkWords</td> Use to check passed text for any
   HTML tags that are not allowed as per the site config.php setting</td>
 </tr>
 SEC_inGroup</td> Used to check if user has passed
   group rights. Example: SEC_inGroup('Root') - returns true if user is</td>
 </tr>
 SEC_hasRights</td> Used to check if user has access
   right (feature). Example: SEC_hasRights('myplugin.edit')</td>
 </tr>
</table>