/** * Retrieve a list of all available modules. * * This function will scan the mods directory to find all available * modules. For each module, the module information (info.txt or * inline module info) is collected. * * @return array * An array, containing the following fields: * - modules: * An array of available modules. The keys are module names and the * values are arrays, containing detailed module information. * - priorities: * An array containing scheduling priority rules. * - deprecated: * An array of warnings about deprecated module hooks or an empty * array if there are no deprecation warnings. * - problems: * An array of (HTML formatted) errors and warnings regarding module * problems. */ function phorum_api_modules_list() { global $PHORUM; $modules = array(); $priorities = array(); $deprecated = array(); $problems = array(); include_once './include/version_functions.php'; $dh = opendir("./mods"); if (!$dh) { trigger_error("Unable to create a list of available modules: " . "opendir of directory \"./mods\" failed.", E_USER_ERROR); } while ($entry = readdir($dh)) { // Some entries which we skip by default. // ATTIC : a directory that I (maurice) sometimes use for storing // deprecated modules or for moving stuff temporarily out // of the way. // _vti_cnf : a directory that is created by Microsoft Frontpage for // storing settings (blame Azumandias for this one). if ($entry == '.' || $entry == '..' || $entry == '.svn' || $entry == '.htaccess' || $entry == 'ATTIC' || $entry == '_vti_cnf') { continue; } // Read in the module information. $lines = array(); if (file_exists("./mods/{$entry}/info.txt")) { $lines = file("./mods/{$entry}/info.txt"); } elseif (is_file("./mods/{$entry}") && substr($entry, -4) == ".php") { $entry = str_replace(".php", "", $entry); $data = file_get_contents("./mods/{$entry}.php"); if ($data = stristr($data, "/* phorum module info")) { $data = substr($data, 0, strpos($data, "*/")); $lines = preg_split('!(\\r|\\n|\\r\\n)!', $data); } } // Check if we found module information. if (!count($lines)) { $problems[] = "Warning: possible module " . "\"" . htmlspecialchars($entry) . "\" found, but no " . "module information is available for that module."; continue; } // Parse the module information. $info = array(); $info['version_disabled'] = false; foreach ($lines as $line) { if (strstr($line, ":")) { $parts = explode(":", trim($line), 2); if ($parts[0] == "hook") { list($hook, $function) = explode('|', trim($parts[1])); if (isset($PHORUM['API']['mods_deprecated_hooks'][$hook])) { $deprecated[] = "Mod " . htmlspecialchars($entry) . ": rename \"" . htmlspecialchars($hook) . "\"; to \"" . htmlspecialchars($PHORUM['API']['mods_deprecated_hooks'][$hook]) . "\""; $hook = $PHORUM['API']['mods_deprecated_hooks'][$hook]; $parts[1] = "{$hook}|{$function}"; } $info["hooks"][] = trim($parts[1]); } elseif ($parts[0] == "priority") { $prio = trim($parts[1]); if (preg_match('/^run\\s+hook\\s+(.+)\\s+(before|after)\\s(.+)$/i', $prio, $m)) { $priorities['hook'][$m[1]][$entry][] = $m; } elseif (preg_match('/^run\\s+module\\s+(before|after)\\s(.+)$/i', $prio, $m)) { $priorities['module'][$entry][] = $m; } else { $problems[] = "Priority configuration error for module " . htmlspecialchars($entry) . "<br/>" . "Cannot parse priority " . "\"" . htmlspecialchars($prio) . "\"<br/>"; } } elseif ($parts[0] == "required_version" || $parts[0] == "require_version") { $required_ver = trim($parts[1]); $phorum_ver = PHORUM; $info['required_version'] = $required_ver; list($currel, $cur) = phorum_parse_version($phorum_ver); list($reqrel, $req) = phorum_parse_version($required_ver); // If an admin is using a development or snapshot release, // the we asume that he knows what he's doing. if ($currel == 'snapshot' || $currel == 'development') { // noop } elseif (phorum_compare_version($cur, $req) == -1) { $info['version_disabled'] = true; } } else { $info[$parts[0]] = trim($parts[1]); } } } if (isset($PHORUM["mods"][$entry])) { $info['enabled'] = $PHORUM["mods"][$entry]; } else { $info['enabled'] = 0; } if (file_exists("./mods/{$entry}/settings.php")) { $info["settings"] = true; } else { $info["settings"] = false; } $modules[$entry] = $info; } closedir($dh); // Sort the modules by their title, so they show up in an easy // to use way for the user in the admin interface. uasort($modules, "module_sort"); // Store the data for other functions in this API. $PHORUM["API"]["mods_modules"] = $modules; $PHORUM["API"]["mods_priorities"] = $priorities; return array('modules' => $modules, 'priorities' => $priorities, 'deprecated' => $deprecated, 'problems' => $problems); }
/** * Finds out if there are any upgrades available for a version of Phorum. * * @param version - the version to check for (default is the running version) * @return releases - An array of available releases with the * "upgrade" field set in case the release would be an * upgrade for the currently running Phorum software. */ function phorum_find_upgrades($version = PHORUM) { // Parse the running version of phorum. $running_version = phorum_parse_version($version); // Retrieve the available releases. $releases = phorum_available_releases(); // Check if an upgrade is available for the running release. // If we're running a stable version, we only compare to the current // stable release. If we're running a development version, we compare both // stable and development. if (isset($releases["stable"])) { $avail_version = $releases["stable"]["pversion"]; if (phorum_compare_version($running_version, $avail_version) == -1) { $releases["stable"]["upgrade"] = true; } else { $releases["stable"]["upgrade"] = false; } } if (($running_version[0] == 'development' || $running_version[0] == 'snapshot') && isset($releases["development"])) { $avail_version = $releases["development"]["pversion"]; if (phorum_compare_version($running_version, $avail_version) == -1) { $releases["development"]["upgrade"] = true; } else { $releases["development"]["upgrade"] = false; } } return $releases; }
/** * Retrieve a list of all available modules. * * This function will scan the mods directory to find all available * modules. For each module, the module information (info.txt or * inline module info) is collected. * * @return array * An array, containing the following fields: * - modules: * An array of available modules. The keys are module names and the * values are arrays, containing detailed module information. * - priorities: * An array containing scheduling priority rules. * - deprecated: * An array of warnings about deprecated module hooks or an empty * array if there are no deprecation warnings. * - problems: * An array of (HTML formatted) errors and warnings regarding module * problems. */ function phorum_api_modules_list() { global $PHORUM; $modules = array(); $priorities = array(); $deprecated = array(); $problems = array(); require_once PHORUM_PATH . '/include/version_functions.php'; $dh = opendir(PHORUM_PATH . '/mods'); if (!$dh) { trigger_error("Unable to create a list of available modules: " . "opendir of directory \"{phorum dir}/mods\" failed.", E_USER_ERROR); } while ($entry = readdir($dh)) { // Some entries that we skip by default. // ATTIC : a directory that I (maurice) sometimes use for storing // deprecated modules or for moving stuff temporarily out // of the way. // _vti_cnf : a directory that is created by Microsoft Frontpage for // storing settings (blame Azumandias for this one). if ($entry == '.' || $entry == '..' || $entry == '.svn' || $entry == '.htaccess' || $entry == 'ATTIC' || $entry == '_vti_cnf') { continue; } // Read in the module information. $lines = array(); if (file_exists(PHORUM_PATH . "/mods/{$entry}/info.txt")) { $lines = file(PHORUM_PATH . "/mods/{$entry}/info.txt"); } elseif (is_file(PHORUM_PATH . "/mods/{$entry}") && substr($entry, -4) == ".php") { $entry = str_replace(".php", "", $entry); $data = file_get_contents(PHORUM_PATH . "/mods/{$entry}.php"); if ($data = stristr($data, "/* phorum module info")) { $data = substr($data, 0, strpos($data, "*/")); $lines = preg_split('!(\\r|\\n|\\r\\n)!', $data); } } // Check if we found module information. if (!count($lines)) { $problems[] = "Warning: possible module " . "\"" . htmlspecialchars($entry) . "\" found, but no " . "module information is available for that module."; continue; } // Parse the module information. $info = array(); $info['module'] = $entry; $info['version_disabled'] = false; foreach ($lines as $line) { if (strstr($line, ":")) { $parts = explode(":", trim($line), 2); if ($parts[0] == "hook") { list($hook, $function) = explode('|', trim($parts[1])); if (isset($PHORUM['API']['mods_deprecated_hooks'][$hook])) { $deprecated[] = "Mod " . htmlspecialchars($entry) . ": rename \"" . htmlspecialchars($hook) . "\"; to \"" . htmlspecialchars($PHORUM['API']['mods_deprecated_hooks'][$hook]) . "\""; $hook = $PHORUM['API']['mods_deprecated_hooks'][$hook]; $parts[1] = "{$hook}|{$function}"; } $info["hooks"][] = trim($parts[1]); } elseif ($parts[0] == "priority") { $prio = trim($parts[1]); if (preg_match('/^run\\s+hook\\s+(.+)\\s+(before|after)\\s(.+)$/i', $prio, $m)) { $priorities['hook'][$m[1]][$entry][] = $m; } elseif (preg_match('/^run\\s+module\\s+(before|after)\\s(.+)$/i', $prio, $m)) { $priorities['module'][$entry][] = $m; } else { $problems[] = "Priority configuration error for module " . htmlspecialchars($entry) . "<br/>" . "Cannot parse priority " . "\"" . htmlspecialchars($prio) . "\"<br/>"; } } elseif ($parts[0] == "required_version" || $parts[0] == "require_version") { $required_ver = trim($parts[1]); $phorum_ver = PHORUM; $info['required_version'] = $required_ver; $cur = phorum_parse_version($phorum_ver); $req = phorum_parse_version($required_ver); // If an admin is using a development or snapshot release, // the we asume that he knows what he's doing. if ($cur[0] == 'snapshot' || $cur[0] == 'development') { // noop } elseif (phorum_compare_version($cur, $req) == -1) { $info['version_disabled'] = true; } } elseif ($parts[0] == "compat") { list($extension, $function) = explode('|', trim($parts[1])); if (empty($info['compat'])) { $info['compat'] = array(); } $info['compat'][$function] = $extension; } else { $info[$parts[0]] = trim($parts[1]); } } } if (isset($PHORUM["mods"][$entry])) { $info['enabled'] = $PHORUM["mods"][$entry]; } else { $info['enabled'] = 0; } if (file_exists(PHORUM_PATH . "/mods/{$entry}/settings.php")) { $info["settings"] = true; } else { $info["settings"] = false; } $modules[$entry] = $info; } closedir($dh); // Check if there are modules available, which are no longer // included in the Phorum core distribution. If yes, then check // if the version of those modules indicates an old bundled version // of the module. In that case, the module is disabled and the admin // is told where to get an up-to-date version of the module. foreach ($PHORUM['API']['mods_no_longer_bundled'] as $module => $info) { if (isset($modules[$module]) && !empty($modules[$module]['enabled'])) { $modinfo = $modules[$module]; if (empty($modinfo['version']) || phorum_compare_version($modinfo['version'], $info['version']) == -1) { $modules[$module]['url'] = $info['url']; $problems[] = "The module \"{$modinfo['title']}\" is no longer included in the core Phorum distribution. A more recent version of this module (version {$info['version']} or higher) is available at the phorum.org website. Please download and install that version. For more information, visit <a href=\"{$info['url']}\" target=\"_new\">the module's page at phorum.org</a>."; } } } // Sort the modules by their title, so they show up in an easy // to use way for the user in the admin interface. uasort($modules, "module_sort"); // Store the data for other functions in this API. $PHORUM["API"]["mods_modules"] = $modules; $PHORUM["API"]["mods_priorities"] = $priorities; return array('modules' => $modules, 'priorities' => $priorities, 'deprecated' => $deprecated, 'problems' => $problems); }