<?php

// Below snipped from Kure, great little system.
// http://findthekure.net
// Licensed under the GPL

/* * *** FIND PLUGINS **** */
$rac[] = true; // mockup array so all our foreach()s don't fail if we don't find plugins
if (file_exists($root . "modules/")) { // plugins dir is optional
    $findmods = glob($root . "modules/*.php");
    if (count($findmods) != 0) {
        // intialize our arrays so array_merge_recursive won't fail if they are not arrays by that time
        $rac = array();
        $rack = array();
        foreach ($findmods as $weight => $pluginfile) {
            include($pluginfile); // read the plugin ($rack will get set by the plugin during this time)
            $rack = add_dimension($rack, $pluginfile); // turns $rack['posts']['post-body_after'] into $rack['posts']['post-body_after']['pluginfilename.php']
            $rac = array_merge_recursive($rac, $rack); // merge with all other plugins
            unset($rack); // remove all entries from $rack so that they don't overflow into the next plugin's array
        }
    }
}

function plug($page, $hook) {
    global $rac, $root;
// processes and prints plugins in page $page at position $hook
    $plugging = true;
    if (!is_array($rac[$page][$hook]))
        return;
    foreach ($rac[$page][$hook] as $file => $html) {
        include($file);
        if ($page == "admplugins" && $hook == "listing")
            echo("<br />\n");
        echo($rack[$page][$hook]);
    }
    $plugging = false;
}

function add_dimension($array, $dimension) {
// adds dimension $dimension to each element in array $array, e.g. $x['a']['b'] = y; becomes $x['a']['b']['c'] = y;
    if (!is_array($array))
        return array($dimension => $array); // base case
    foreach ($array as $key => $val)
        $array[$key] = add_dimension($val, $dimension);
    return $array;
}

function array_isearch($str, $array) {
    foreach ($array as $k => $v) {
        if (strcasecmp($str, $v) == 0)
            return $k;
    }
    return false;
}

/* * ******************** */
// ------------------------------------------------------------ 
?>