/** * Sorts selected extensions by their setup order if present * * @global array $cfg * @param array $selected_extensions Unsorted list of extension names * @param bool $is_module TRUE if sorting modules, FALSE if sorting plugins * @return array Sorted list of extension names */ function cot_install_sort_extensions($selected_extensions, $is_module = FALSE) { global $cfg; $path = $is_module ? $cfg['modules_dir'] : $cfg['plugins_dir']; $ret = array(); // Split into groups by Order value $extensions = array(); foreach ($selected_extensions as $name) { $info = cot_infoget("{$path}/{$name}/{$name}.setup.php", 'COT_EXT'); $order = isset($info['Order']) ? (int) $info['Order'] : COT_PLUGIN_DEFAULT_ORDER; if ($info['Category'] == 'post-install' && $order < 999) { $order = 999; } $extensions[$order][] = $name; } // Merge back into a single array foreach ($extensions as $grp) { foreach ($grp as $name) { $ret[] = $name; } } return $ret; }
/** * Checks if requirements for installed/used package is satisfied * Returns boolean if checking is done or Error message otherwise * * @param string $target Target (case insensitive). Could be: * php - PHP version or PHP extensions * core - for checking Cotonti (core) version * system - Cotonti system modules (like Admin) * theme - for themes * plugin - for plugin check * module - for module check * extension - for checking among both types: plugins and modules * Can be in complex notation: * php_curl - for certain php module `curl` * pfs_module - for certain Cotonti module (`PFS`) * comments_plugin - for certain Cotonti plugin (`comments`) * * All other Target types treats as Cotonti Extension name, see examples below. * @param string $constraint Version string or version constraint * @param string $package_name (optional) Name of package for checking if not defined in type * @param string $ext_active (optional) Requirement to check is Extension installed, `true` by default * * @return bool | string Result of check or Error message * **Note:** result should be checked with strait comparison with === / !== operators, * * Examples of use: * cot_requirements_satisfied('core','0.9.19'); // Cotonti version check * cot_requirements_satisfied('PHP','5.4.1'); // Checking for PHP version * cot_requirements_satisfied('PHP','7.0','curl'); // Checking for PHP extension version * cot_requirements_satisfied('plugin','1.2','comments'); * cot_requirements_satisfied('module','1.1.3','page'); * cot_requirements_satisfied('theme','*','skeletonti'); // any version allowed * // installed theme treats as Default Cotonti theme * cot_requirements_satisfied('module','0.7.15','pfs', false); * // checking Extension is in the system but not is it installed * cot_requirements_satisfied('extension','0.9.18','somename'); // checking among plugins and modules * cot_requirements_satisfied('page_module','0.9.18'); * // shorthand for → 'module', 0.9.18, 'page' * cot_requirements_satisfied('test','0.9.18'); → 'extension', 0.9.18, 'test' * * @uses function cot_version_compare() */ function cot_requirements_satisfied($target, $constraint, $package_name = null, $ext_active = true) { global $cot_plugins_enabled, $cot_modules; $target_types = array('core', 'theme', 'admin_theme', 'module', 'plugin', 'system', 'extension'); $target = strtolower($target); if (!$package_name) { // tries to extract `package_name` from `target` foreach ($target_types as $ttype) { $last_part = substr($target, -strlen($ttype)); if ($last_part == $ttype) { $package_name = substr($target, 0, -(strlen($last_part) + 1)); $target = $last_part; break; } $last_part = ''; } if (!$last_part && substr($target, 0, 4) == 'php_') { $target = 'php'; $package_name = substr($target, 4); } } switch ($target) { case 'php': // PHP version $current_version = cot_phpversion($package_name); if (is_null($current_version)) { return false; } // ext not found break; case 'core': // Cotonti core $current_version = cot::$cfg['version']; break; case 'system': // Cotonti system modules, like admin $sql = $db->query("SELECT * FROM {$db_core} WHERE ct_lock = 1"); while ($row = $sql->fetch()) { if ($row['ct_code'] == $package_name) { $active = (bool) $row['ct_state']; $current_version = $row['ct_version']; } } $sql->closeCursor(); if (!$current_version || $ext_active && !$active) { return false; } break; case 'admin_theme': case 'theme': $themefile = cot::$cfg['themes_dir'] . ($target == 'admin-theme' ? '/admin/' : '') . "/{$package_name}/{$package_name}.php"; if (file_exists($themefile)) { $themeinfo = cot_infoget($themefile, 'COT_THEME'); $current_version = $themeinfo['Version']; if (!$current_version) { $themeinfo = cot_file_phpdoc($themefile); } $current_version = $themeinfo['version']; } else { return false; } if ($target != 'theme') { $active = cot::$cfg['admintheme'] == $package_name; } else { $active = cot::$cfg['forcedefaulttheme'] && cot::$cfg['defaulttheme'] == $package_name; } if ($ext_active && !$active) { return false; } break; case 'plugin': case 'module': case 'extension': // either plugin or module // either plugin or module default: if (!$target) { $target = 'extension'; } elseif (!$package_name) { $package_name = $target; $target = 'extension'; } if (!$package_name) { return cot_rc('req_no_target'); } if ($ext_active) { if ($target == 'extension' || $target == 'module') { $active = $current_version = $cot_modules[$package_name]['version']; } if ($target == 'extension' || $target == 'plugin') { $active || ($active = $current_version = $cot_plugins_enabled[$package_name]['version']); } if (!$active) { return false; } } else { // checking version from not installed Extension $setup_file = cot::$cfg['modules_dir'] . "/{$package_name}/{$package_name}.setup.php"; if ($target == 'extension' || $target == 'module') { is_file($setup_file) && ($info = cot_infoget($setup_file)); } if ($target == 'extension' || $target == 'plugin') { $info || is_file($setup_file) && ($info = cot_infoget($setup_file)); } if (!$info) { return cot_rc('req_ext_notfound', array('ext' => $package_name)); } $current_version = $info['Version']; } //end of default } $meet = cot_version_constraint($current_version, $constraint); // as we can get boolean (true | false) or integer (-1 | 0 | 1) respect // to operator presence in constraint, we need to change integer to boolean. if (is_int($meet)) { $meet = $meet == 1 ? true : false; } return $meet; }
/** * Returns Theme/Scheme selection dropdown * * @param string $selected_theme Seleced theme * @param string $selected_scheme Seleced color scheme * @param string $name Dropdown name * @return string */ function cot_selectbox_theme($selected_theme, $selected_scheme, $input_name) { global $cfg; require_once cot_incfile('extensions'); $handle = opendir($cfg['themes_dir']); while ($f = readdir($handle)) { if (mb_strpos($f, '.') === FALSE && is_dir("{$cfg['themes_dir']}/{$f}") && $f != "admin") { $themelist[] = $f; } } closedir($handle); sort($themelist); $values = array(); $titles = array(); foreach ($themelist as $x) { $themeinfo = "{$cfg['themes_dir']}/{$x}/{$x}.php"; if (file_exists($themeinfo)) { $info = cot_infoget($themeinfo, 'COT_THEME'); if ($info) { if (empty($info['Schemes'])) { $values[] = "{$x}:default"; $titles[] = $info['Name']; } else { $schemes = explode(',', $info['Schemes']); sort($schemes); foreach ($schemes as $sc) { $sc = explode(':', $sc); $values[] = $x . ':' . $sc[0]; $titles[] = count($schemes) > 1 ? $info['Name'] . ' (' . $sc[1] . ')' : $info['Name']; } } } else { $values[] = "{$x}:default"; $titles[] = $x; } } else { $values[] = "{$x}:default"; $titles[] = $x; } } return cot_selectbox("{$selected_theme}:{$selected_scheme}", $input_name, $values, $titles, false); }
/** * Returns themes info data for all available themes or a specified one * * @param string $theme_name Name of theme to get info. * Returns list for all themes if no name specified. * @return mixed Array of Theme info data or Theme info data or FALSE */ function cot_themes_info($theme_name = null) { require_once cot_incfile('extensions'); $themes_data = array(); $themelist = array(); $handle = opendir(cot::$cfg['themes_dir']); while ($f = readdir($handle)) { if (mb_strpos($f, '.') === FALSE && is_dir(cot::$cfg['themes_dir'] . "/{$f}") && $f != "admin") { $themelist[] = $f; } } closedir($handle); if (!is_null($theme_name)) { if (!in_array($theme_name, $themelist)) { return false; } else { $themelist = array($theme_name); } } else { sort($themelist); } foreach ($themelist as $name) { if ($theme_name && $theme_name != $name) { continue; } $themeinfo = array(); $themeinfo_file = cot::$cfg['themes_dir'] . "/{$name}/{$name}.php"; if (file_exists($themeinfo_file) && ($info = cot_infoget($themeinfo_file, 'COT_THEME'))) { $themeinfo = $info; if (!$themeinfo['Title']) { $themeinfo['Title'] = $info['Name'] ? $info['Name'] : $name; } $schemes_list = array(); if (!empty($info['Schemes'])) { $schemes = preg_split('/\\s*,\\s*/', $info['Schemes']); sort($schemes); foreach ($schemes as $scheme) { list($sc_name, $sc_title) = explode(':', $scheme); $schemes_list[$sc_name] = $sc_title; } } $themeinfo['Schemes'] = $schemes_list; } if (sizeof($themeinfo) > 0) { $themes_data[$name] = $themeinfo; } } if (is_null($theme_name)) { return $themes_data; } else { return $themes_data[$theme_name]; } }
function cot_get_extensionparams($code, $is_module = false) { global $cfg, $cot_modules, $cot_plugins_enabled; $dir = $is_module ? $cfg['modules_dir'] : $cfg['plugins_dir']; if ($is_module) { $name = $cot_modules[$code]['title']; } else { $name = $cot_plugins_enabled[$code]['title']; } if (empty($name)) { $ext_info = $dir . '/' . $code . '/' . $code . '.setup.php'; $exists = file_exists($ext_info); if ($exists) { $info = cot_infoget($ext_info, 'COT_EXT'); if (!$info && cot_plugin_active('genoa')) { // Try to load old format info $info = cot_infoget($ext_info, 'SED_EXTPLUGIN'); } $name = $info['Name']; $desc = $info['Desc']; } else { $info = array('Name' => $code); } $name = $info['Name']; } $icofile = $dir . '/' . $code . '/' . $code . '.png'; $icon = file_exists($icofile) ? $icofile : ''; $langfile = cot_langfile($code, $is_module ? 'module' : 'plug'); if (file_exists($langfile)) { include $langfile; if (!empty($L['info_name'])) { $name = $L['info_name']; } if (!empty($L['info_desc'])) { $desc = $L['info_desc']; } } return array('name' => htmlspecialchars($name), 'desc' => $desc, 'icon' => $icon); }
$db->delete($db_core, "ct_code IN ('comments', 'ratings', 'trash')"); // Set Module versions to Genoa version before upgrade $db->update($db_core, array('ct_version' => '0.8.99'), '1'); // Update modules foreach (array('forums', 'index', 'page', 'pfs', 'pm', 'polls', 'users') as $code) { $ret = cot_extension_install($code, true, true); if ($ret === false) { cot_error(cot_rc('ext_update_error', array('type' => $L['Module'], 'name' => $code))); } } // Update installed Siena plugins and uninstall Genoa plugins $res = $db->query("SELECT DISTINCT(pl_code) FROM {$db_plugins}\n\t\tWHERE pl_module = 0"); while ($row = $res->fetch(PDO::FETCH_NUM)) { $code = $row[0]; $setup_file = $cfg['plugins_dir'] . '/' . $code . '/' . $code . '.setup.php'; if (file_exists($setup_file) && ($info = cot_infoget($setup_file))) { // Update cot_extension_add($code, $info['Name'], '0.0.0', true); cot_extension_install($code, false, true); } else { // Uninstall $qcode = $db->quote($code); $db->delete($db_auth, "auth_option = {$qcode}"); $db->delete($db_config, "config_cat = {$qcode}"); $db->delete($db_plugins, "pl_code = {$qcode}"); } } $res->closeCursor(); // Install bbcode and html parsers cot_extension_install('bbcode'); cot_extension_install('html');
$dir = $dep_module ? $cfg['modules_dir'] : $cfg['plugins_dir']; foreach (explode(',', $info[$dep_type]) as $ext) { $ext = trim($ext); $dep_installed = cot_extension_installed($ext); if ($dep_obligatory) { $dep_class = $dep_installed ? 'highlight_green' : 'highlight_red'; $dependencies_satisfied &= $dep_installed; } else { $dep_class = ''; } $dep_ext_info = $dir . '/' . $ext . '/' . $ext . '.setup.php'; if (file_exists($dep_ext_info)) { $dep_info = cot_infoget($dep_ext_info, 'COT_EXT'); if (!$dep_info && cot_plugin_active('genoa')) { // Try to load old format info $dep_info = cot_infoget($dep_ext_info, 'SED_EXTPLUGIN'); } } else { $dep_info = array('Name' => $ext); } $t->assign(array('ADMIN_EXTENSIONS_DEPENDENCIES_ROW_CODE' => $ext, 'ADMIN_EXTENSIONS_DEPENDENCIES_ROW_NAME' => $dep_info['Name'], 'ADMIN_EXTENSIONS_DEPENDENCIES_ROW_URL' => $dep_module && file_exists($cfg['modules_dir'] . '/' . $ext) || !$dep_module && file_exists($cfg['plugins_dir'] . '/' . $ext) ? cot_url('admin', "m=extensions&a=details&{$arg}={$ext}") : '#', 'ADMIN_EXTENSIONS_DEPENDENCIES_ROW_TYPE' => $dep_module ? $L['Module'] : $L['Plugin'], 'ADMIN_EXTENSIONS_DEPENDENCIES_ROW_CLASS' => $dep_class)); $t->parse('MAIN.DETAILS.DEPENDENCIES.DEPENDENCIES_ROW'); } $t->assign(array('ADMIN_EXTENSIONS_DEPENDENCIES_TITLE' => $L['ext_' . strtolower($dep_type)])); $t->parse('MAIN.DETAILS.DEPENDENCIES'); } } } /* === Hook === */ foreach (cot_getextplugins('admin.extensions.details') as $pl) { include $pl;
/** * Returns an array containing meta information for all extensions in a directory * * @param string $dir Directory to search for extensions in * @return array Extension code => info array */ function cot_extension_list_info($dir) { $ext_list = array(); clearstatcache(); $dp = opendir($dir); while ($f = readdir($dp)) { $path = $dir . '/' . $f; if ($f[0] != '.' && is_dir($path) && file_exists("{$path}/{$f}.setup.php")) { $info = cot_infoget("{$path}/{$f}.setup.php", 'COT_EXT'); if (!$info && cot_plugin_active('genoa')) { // Try to load old format info $info = cot_infoget("{$path}/{$f}.setup.php", 'SED_EXTPLUGIN'); } if (empty($info['Category'])) { $info['Category'] = 'misc-ext'; } $ext_list[$f] = $info; } } closedir($dp); return $ext_list; }