Plugins Directory

page title: [Hack: Plugins Directory]


bugs: Probably
Compatible with: R6.1
Current version:
Credits: brianko, ported over from WikkaWiki

class/wacko.php <— add to end of file

<?php
/**
 * Build a (possibly valid) filepath from a delimited list of paths
 *
 * This function takes a list of paths delimited by ":"
 * and attempts to construct a fully-qualified pathname to a specific
 * file.  By default, this function checks to see if the file
 * pointed to by the fully-qualified pathname exists.  First valid
 * match wins.  Disabling this feature will return the first valid
 * constructed path (i.e, a path containing a valid directory, but
 * not necessarily pointing to an existant file).
 *
 * @param string $filename mandatory: filename to be used in
 *          construction of fully-qualified filepath
 * @param string $pathlist mandatory: list of
 *          paths (delimited by ":")
 * @param  boolean $checkIfFileExists optional: if TRUE, returns
 *          only a pathname that points to a file that exists
 *          (default)
 * @return string A fully-qualified pathname or NULL if none found
 */
function BuildFullpathFromMultipath($filename, $pathlist, $checkIfFileExists=TRUE): ?string
{
    $paths = preg_split('/:/', $pathlist);
    if(empty($paths[0])) return NULL;
    if(FALSE === $checkIfFileExists)
    {
        // Just return first directory that exists
        foreach($paths as $path)
        {
            $path = trim($path);
            if(file_exists($path))
            {
                return Ut::join_path($path, $filename);
            }
        }
        return NULL;
    }
    foreach($paths as $path)
    {
        $path = trim($path);
        $fqfn = Ut::join_path($path, $filename);
        if(file_exists($fqfn)) return $fqfn;
    }
    return NULL;
}
?>

1. Documentation

Introduces a preliminary plugin architecture that allows Wacko users to override core functionality with custom actions, handlers, formatters, and associated templates. The advantages of such a setup are numerous:

  • A component that “misbehaves” or does not perform to your expectations can simply be removed.
  • Future Wacko upgrades are guaranteed not to change or modify anything in the /plugins folders.
  • Testing of a new action, handler, formatter, or template is greatly enhanced: There is no need to modify core functionality, and it's easy to revert back to the core if necessary.

2. How to

To use the new plugin folders for your add-ons, you will have to create the /plugins tree and add the corresponding paths in your config/constants.php file. Components will be loaded following the path order specified in the config file (so for instance a custom action called /plugins/action/contact.php will override the default action/contact.php). The only supported path separator is the colon (:). For example:


const FORMATTER_DIR = 'plugins/formatter:formatter',
const HANDLER_DIR = 'plugins/handler:handler',
const ACTION_DIR = 'plugins/action:action',	

For some formatters with associated class files (pre_wacko.php, wackoformatter.php) manual changes are required in the config/autoload.conf file:


plugins/formatter/class/pre_wacko.php                       PreFormatter
plugins/formatter/class/wackoformatter.php                 WackoFormatter	

Other modifications are necessary to fully implement:


1. class/wacko.php
In the _format function, the two include_buffered calls that have Ut:join_path calls as the first argument need to be modified:

#$text      = $this->include_buffered(Ut::join_path(FORMATTER_DIR, $formatter . '.php'), $error, compact('text', 'options'));
$text       = $this->include_buffered($this->BuildFullpathFromMultipath($formatter . '.php', FORMATTER_DIR), $error, compact('text', 'options'));

#$text = $this->include_buffered(Ut::join_path(FORMATTER_DIR, 'typografica.php'), $error, compact('text'));
$text = $this->include_buffered($this->BuildFullpathFromMultipath('typografica.php', FORMATTER_DIR), $error, compact('text'));

2. formatter/wiki.php, formatter/highlight/notypo.php, formatter/highlight/wacko.php, formatter/highlight/info.php, formatter/highlight/noinclude.php, formatter/highlight/details.php, formatter/highlight/noautolinks.php, formatter/highlight/typografica.php
The Ut::join_path call(s) in each file need to be modified. For example:

#include Ut::join_path(FORMATTER_DIR, 'post_wacko.php');
include $this->BuildFullpathFromMultipath('post_wacko.php', FORMATTER_DIR);

2.1. Localization (optional)

put this at the end of your language file


lang/custom.<lang>.php
%%

3. Changelog

0.1 Intitial version

4. To Do


Referring pages:

  1. Dev/PatchesHacks

Read comments (5 comments)