function listtree($path, $sub_path = '') { $data = array(); $dir = @dir($path . $sub_path); if (!$dir) { return array(); } while ($entry = $dir->read()) { if ($entry == '.' || $entry == '..') { continue; } if (is_dir($path . $sub_path . '/' . $entry)) { $data = array_merge($data, listtree($path, $sub_path . '/' . $entry)); } else { $data[] = array('filename' => $sub_path == '' ? $entry : $sub_path . '/' . $entry, 'size' => filesize($path . $sub_path . '/' . $entry), 'skipped' => false); } } $dir->close(); return $data; }
function ViewOperations() { global $context, $txt, $boarddir, $sourcedir, $modSettings; // Can't be in here buddy. isAllowedTo('admin_forum'); // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { fatal_lang_error('operation_invalid', 'general'); } // Load the required file. require_once $sourcedir . '/lib/Subs-Package.php'; // Uninstalling the mod? $reverse = isset($_REQUEST['reverse']) ? true : false; // Get the base name. $context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']); // We need to extract this again. if (is_file($boarddir . '/Packages/' . $context['filename'])) { $context['extracted_files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp'); if ($context['extracted_files'] && !file_exists($boarddir . '/Packages/temp/package-info.xml')) { foreach ($context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { $context['base_path'] = dirname($file['filename']) . '/'; break; } } } if (!isset($context['base_path'])) { $context['base_path'] = ''; } } elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) { copytree($boarddir . '/Packages/' . $context['filename'], $boarddir . '/Packages/temp'); $context['extracted_files'] = listtree($boarddir . '/Packages/temp'); $context['base_path'] = ''; } // Load up any custom themes we may want to install into... $request = smf_db_query(' SELECT id_theme, variable, value FROM {db_prefix}themes WHERE (id_theme = {int:default_theme} OR id_theme IN ({array_int:known_theme_list})) AND variable IN ({string:name}, {string:theme_dir})', array('known_theme_list' => explode(',', $modSettings['knownThemes']), 'default_theme' => 1, 'name' => 'name', 'theme_dir' => 'theme_dir')); $theme_paths = array(); while ($row = mysql_fetch_assoc($request)) { $theme_paths[$row['id_theme']][$row['variable']] = $row['value']; } mysql_free_result($request); // Boardmod? if (isset($_REQUEST['boardmod'])) { $mod_actions = parseBoardMod(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); } else { $mod_actions = parseModification(@file_get_contents($boarddir . '/Packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); } // Ok lets get the content of the file. $context['operations'] = array('search' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['search_original']), array('[' => '[', ']' => ']')), 'replace' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['replace_original']), array('[' => '[', ']' => ']')), 'position' => $mod_actions[$_REQUEST['operation_key']]['position']); // Let's do some formatting... $operation_text = $context['operations']['position'] == 'replace' ? 'operation_replace' : ($context['operations']['position'] == 'before' ? 'operation_after' : 'operation_before'); $context['operations']['search'] = parse_bbc('[code=' . $txt['operation_find'] . ']' . ($context['operations']['position'] == 'end' ? '?>' : $context['operations']['search']) . '[/code]'); $context['operations']['replace'] = parse_bbc('[code=' . $txt[$operation_text] . ']' . $context['operations']['replace'] . '[/code]'); // No layers $context['template_layers'] = array(); $context['sub_template'] = 'view_operations'; }
/** * List operations */ public function action_showoperations() { global $context, $txt; // Can't be in here buddy. isAllowedTo('admin_forum'); // We need to know the operation key for the search and replace, mod file looking at, is it a board mod? if (!isset($_REQUEST['operation_key'], $_REQUEST['filename']) && !is_numeric($_REQUEST['operation_key'])) { fatal_lang_error('operation_invalid', 'general'); } // Load the required file. require_once SUBSDIR . '/Package.subs.php'; require_once SUBSDIR . '/Themes.subs.php'; // Uninstalling the mod? $reverse = isset($_REQUEST['reverse']) ? true : false; // Get the base name. $context['filename'] = preg_replace('~[\\.]+~', '.', $_REQUEST['package']); // We need to extract this again. if (is_file(BOARDDIR . '/packages/' . $context['filename'])) { $context['extracted_files'] = read_tgz_file(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp'); if ($context['extracted_files'] && !file_exists(BOARDDIR . '/packages/temp/package-info.xml')) { foreach ($context['extracted_files'] as $file) { if (basename($file['filename']) == 'package-info.xml') { $context['base_path'] = dirname($file['filename']) . '/'; break; } } } if (!isset($context['base_path'])) { $context['base_path'] = ''; } } elseif (is_dir(BOARDDIR . '/packages/' . $context['filename'])) { copytree(BOARDDIR . '/packages/' . $context['filename'], BOARDDIR . '/packages/temp'); $context['extracted_files'] = listtree(BOARDDIR . '/packages/temp'); $context['base_path'] = ''; } // Load up any custom themes we may want to install into... $theme_paths = getThemesPathbyID(); // For uninstall operations we only consider the themes in which the package is installed. if (isset($_REQUEST['reverse']) && !empty($_REQUEST['install_id'])) { $install_id = (int) $_REQUEST['install_id']; if ($install_id > 0) { $old_themes = loadThemesAffected($install_id); foreach ($theme_paths as $id => $data) { if ($id != 1 && !in_array($id, $old_themes)) { unset($theme_paths[$id]); } } } } // Boardmod? if (isset($_REQUEST['boardmod'])) { $mod_actions = parseBoardMod(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); } else { $mod_actions = parseModification(@file_get_contents(BOARDDIR . '/packages/temp/' . $context['base_path'] . $_REQUEST['filename']), true, $reverse, $theme_paths); } // Ok lets get the content of the file. $context['operations'] = array('search' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['search_original'], ENT_COMPAT, 'UTF-8'), array('[' => '[', ']' => ']')), 'replace' => strtr(htmlspecialchars($mod_actions[$_REQUEST['operation_key']]['replace_original'], ENT_COMPAT, 'UTF-8'), array('[' => '[', ']' => ']')), 'position' => $mod_actions[$_REQUEST['operation_key']]['position']); // Let's do some formatting... $operation_text = $context['operations']['position'] == 'replace' ? 'operation_replace' : ($context['operations']['position'] == 'before' ? 'operation_after' : 'operation_before'); $context['operations']['search'] = parse_bbc('[code=' . $txt['operation_find'] . ']' . ($context['operations']['position'] == 'end' ? '?>' : $context['operations']['search']) . '[/code]'); $context['operations']['replace'] = parse_bbc('[code=' . $txt[$operation_text] . ']' . $context['operations']['replace'] . '[/code]'); // No layers Template_Layers::getInstance()->removeAll(); $context['sub_template'] = 'view_operations'; }
function PackageList() { global $txt, $scripturl, $boarddir, $context, $sourcedir; require_once $sourcedir . '/Subs-Package.php'; // No package? Show him or her the door. if (empty($_REQUEST['package']) || preg_match('~[^\\w0-9.\\-_]~', $_REQUEST['package']) === 1 || strpos($_REQUEST['package'], '..') !== false) { redirectexit('action=packages'); } $context['linktree'][] = array('url' => $scripturl . '?action=packages;sa=list;package=' . $_REQUEST['package'], 'name' => &$txt['smf180']); $context['page_title'] .= ' - ' . $txt['smf180']; $context['sub_template'] = 'list'; // The filename... $context['filename'] = $_REQUEST['package']; // Let the unpacker do the work. if (is_file($boarddir . '/Packages/' . $context['filename'])) { $context['files'] = read_tgz_file($boarddir . '/Packages/' . $context['filename'], null); } elseif (is_dir($boarddir . '/Packages/' . $context['filename'])) { $context['files'] = listtree($boarddir . '/Packages/' . $context['filename']); } }