/** * load a module * @author Jim McDonald <*****@*****.**> * @link http://www.mcdee.net * @param 'name' the name of the module * @param 'type' the type of functions to load * @param 'force' determines to load Module even if module isn't active * @return string name of module loaded, or false on failure */ function pnModLoad($modname, $type = 'user', $force = false) { // define input, all numbers and booleans to strings $modname = isset($modname) ? (string) $modname : ''; // validate if (!pnVarValidate($modname, 'mod')) { return false; } if (strtolower(substr($type, -3)) == 'api') { return false; } static $loaded = array(); if (!empty($loaded[strtolower("{$modname}{$type}")])) { // Already loaded from somewhere else return $modname; } // get the module info $modinfo = pnModGetInfo(pnModGetIDFromName($modname)); // check the modules state if (!$force && !pnModAvailable($modname) && pnModGetName() != 'Modules') { return false; } // Load the module and module language files list($osdirectory, $ostype) = pnVarPrepForOS($modinfo['directory'], $type); $mosfile = "modules/{$osdirectory}/pn{$ostype}.php"; $mosdir = "modules/{$osdirectory}/pn{$ostype}"; if (file_exists($mosfile)) { // Load the file from modules include $mosfile; } elseif (is_dir($mosdir)) { } else { // File does not exist return false; } $loaded[strtolower("{$modname}{$type}")] = 1; // load the module language file pnModLangLoad($modname, $type); // Load datbase info pnModDBInfoLoad($modname, $modinfo['directory']); // Return the module name return $modname; }
/** * "Blank", sample plugin * * @param array $args['item'] menu node to be replaced * @param string $args['lang'] current menu language * @param string $args['extrainfo'] additional params - if 'flat' then return links ungrouped * @return mixed array of links if successful, false otherwise */ public function blank($args) { /** * args may look like this: * Array * ( * [item] => Array * ( * [id] => 999 * [name] => Name given in menutree form * [href] => {ext:blank:foo=1&bar=2} * [title] => Some title * [className] => important * [state] => 1 * [lang] => eng * [lineno] => 99 * [parent] => 0 * ) * [lang] => pol * [bid] => 999 * [extrainfo] => foo=1&bar=2 * ) * */ $dom = ZLanguage::getModuleDomain('menutree'); $item = isset($args['item']) && !empty($args['item']) ? $args['item'] : null; $lang = isset($args['lang']) && !empty($args['lang']) ? $args['lang'] : null; $bid = isset($args['bid']) && !empty($args['bid']) ? $args['bid'] : null; $extrainfo = isset($args['extrainfo']) && !empty($args['extrainfo']) ? $args['extrainfo'] : null; // $item ang lang params are required if (!$item || !$lang) { return false; } // is there is extrainfo - convert it into array, parse_str is quite handy if ($extrainfo) { parse_str($extrainfo, $extrainfo); } // get id for first element, use api func to aviod id conflicts inside menu $idoffset = Blocks_MenutreeUtil::getIdOffset($item['id']); // load plugin language file pnModLangLoad('menutree', 'externalapi_blank'); $links = array(); // build some link // you may use associative array keys $links['first'] = array($lang => array('id' => $idoffset++, 'name' => $item['name'], 'href' => ModUtil::url('News'), 'title' => $item['title'], 'className' => $item['className'], 'state' => $item['state'], 'lang' => $lang, 'lineno' => $item['lineno'], 'parent' => $item['parent'])); // build second link - this one will be child of the first element $secondLink = isset($extrainfo['foo']) ? ModUtil::url('News', 'user', 'display', array('sid' => $extrainfo['foo'])) : ModUtil::url('News'); $links['second'] = array($lang => array('id' => $idoffset++, 'name' => 'Second blank link', 'href' => $secondLink, 'title' => __('Title', $dom), 'className' => '', 'state' => 1, 'lang' => $lang, 'lineno' => 0, 'parent' => $links['first'][$lang]['id'])); // build third link - this one will be on the same level as first link $thirdLink = isset($extrainfo['bar']) ? ModUtil::url('News', 'user', 'display', array('sid' => $extrainfo['bar'])) : ModUtil::url('News'); $links['third'] = array($lang => array('id' => $idoffset++, 'name' => 'Third blank link', 'href' => $thirdLink, 'title' => '', 'className' => '', 'state' => $item['state'], 'lang' => $lang, 'lineno' => $item['lineno'] + 1, 'parent' => $item['parent'])); return $links; }