/** * Makes a copy of a template file in a new location * * @uses ManageThemes template, copy_template sub-template. */ public function action_copy() { global $context, $settings; loadTemplate('ManageThemes'); require_once SUBSDIR . '/Themes.subs.php'; $context[$context['admin_menu_name']]['current_subsection'] = 'edit'; $context['theme_id'] = isset($_GET['th']) ? (int) $_GET['th'] : (int) $_GET['id']; $theme_dirs = array(); $theme_dirs = loadThemeOptionsInto($context['theme_id'], null, $theme_dirs, array('base_theme_dir', 'theme_dir')); if (isset($_REQUEST['template']) && preg_match('~[\\./\\\\:\\0]~', $_REQUEST['template']) == 0) { if (!empty($theme_dirs['base_theme_dir']) && file_exists($theme_dirs['base_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) { $filename = $theme_dirs['base_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; } elseif (file_exists($settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php')) { $filename = $settings['default_theme_dir'] . '/' . $_REQUEST['template'] . '.template.php'; } else { fatal_lang_error('no_access', false); } $fp = fopen($theme_dirs['theme_dir'] . '/' . $_REQUEST['template'] . '.template.php', 'w'); fwrite($fp, file_get_contents($filename)); fclose($fp); redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy'); } elseif (isset($_REQUEST['lang_file']) && preg_match('~^[^\\./\\\\:\\0]\\.[^\\./\\\\:\\0]$~', $_REQUEST['lang_file']) != 0) { if (!empty($theme_dirs['base_theme_dir']) && file_exists($theme_dirs['base_theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php')) { $filename = $theme_dirs['base_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; } elseif (file_exists($settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php')) { $filename = $settings['default_theme_dir'] . '/languages/' . $_REQUEST['template'] . '.php'; } else { fatal_lang_error('no_access', false); } $fp = fopen($theme_dirs['theme_dir'] . '/languages/' . $_REQUEST['lang_file'] . '.php', 'w'); fwrite($fp, file_get_contents($filename)); fclose($fp); redirectexit('action=admin;area=theme;th=' . $context['theme_id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . ';sa=copy'); } $templates = array(); $lang_files = array(); $dir = dir($settings['default_theme_dir']); while ($entry = $dir->read()) { if (substr($entry, -13) == '.template.php') { $templates[] = substr($entry, 0, -13); } } $dir->close(); $dir = dir($settings['default_theme_dir'] . '/languages'); while ($entry = $dir->read()) { if (preg_match('~^([^\\.]+\\.[^\\.]+)\\.php$~', $entry, $matches)) { $lang_files[] = $matches[1]; } } $dir->close(); if (!empty($theme_dirs['base_theme_dir'])) { $dir = dir($theme_dirs['base_theme_dir']); while ($entry = $dir->read()) { if (substr($entry, -13) == '.template.php' && !in_array(substr($entry, 0, -13), $templates)) { $templates[] = substr($entry, 0, -13); } } $dir->close(); if (file_exists($theme_dirs['base_theme_dir'] . '/languages')) { $dir = dir($theme_dirs['base_theme_dir'] . '/languages'); while ($entry = $dir->read()) { if (preg_match('~^([^\\.]+\\.[^\\.]+)\\.php$~', $entry, $matches) && !in_array($matches[1], $lang_files)) { $lang_files[] = $matches[1]; } } $dir->close(); } } natcasesort($templates); natcasesort($lang_files); $context['available_templates'] = array(); foreach ($templates as $template) { $context['available_templates'][$template] = array('filename' => $template . '.template.php', 'value' => $template, 'already_exists' => false, 'can_copy' => is_writable($theme_dirs['theme_dir'])); } $context['available_language_files'] = array(); foreach ($lang_files as $file) { $context['available_language_files'][$file] = array('filename' => $file . '.php', 'value' => $file, 'already_exists' => false, 'can_copy' => file_exists($theme_dirs['theme_dir'] . '/languages') ? is_writable($theme_dirs['theme_dir'] . '/languages') : is_writable($theme_dirs['theme_dir'])); } $dir = dir($theme_dirs['theme_dir']); while ($entry = $dir->read()) { if (substr($entry, -13) == '.template.php' && isset($context['available_templates'][substr($entry, 0, -13)])) { $context['available_templates'][substr($entry, 0, -13)]['already_exists'] = true; $context['available_templates'][substr($entry, 0, -13)]['can_copy'] = is_writable($theme_dirs['theme_dir'] . '/' . $entry); } } $dir->close(); if (file_exists($theme_dirs['theme_dir'] . '/languages')) { $dir = dir($theme_dirs['theme_dir'] . '/languages'); while ($entry = $dir->read()) { if (preg_match('~^([^\\.]+\\.[^\\.]+)\\.php$~', $entry, $matches) && isset($context['available_language_files'][$matches[1]])) { $context['available_language_files'][$matches[1]]['already_exists'] = true; $context['available_language_files'][$matches[1]]['can_copy'] = is_writable($theme_dirs['theme_dir'] . '/languages/' . $entry); } } $dir->close(); } $context['sub_template'] = 'copy_template'; }
/** * Load the options for an user. * * @param int $memID id_member */ function loadThemeOptions($memID) { global $context, $options, $cur_profile; if (isset($_POST['default_options'])) { $_POST['options'] = isset($_POST['options']) ? $_POST['options'] + $_POST['default_options'] : $_POST['default_options']; } if ($context['user']['is_owner']) { $context['member']['options'] = $options; if (isset($_POST['options']) && is_array($_POST['options'])) { foreach ($_POST['options'] as $k => $v) { $context['member']['options'][$k] = $v; } } } else { require_once SUBSDIR . '/Themes.subs.php'; $context['member']['options'] = loadThemeOptionsInto(array(1, (int) $cur_profile['id_theme']), array(-1, $memID), $context['member']['options']); if (isset($_POST['options'])) { foreach ($_POST['options'] as $var => $val) { $context['member']['options'][$var] = $val; } } } }