/** * Copy a theme. * * @param ID_TEXT The original theme name * @param ID_TEXT The copy's theme name */ function actual_copy_theme($theme, $to) { if ($theme == 'default') { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } if (file_exists(get_custom_file_base() . '/themes/' . $to) || $to == 'default') { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($to))); } require_code('abstract_file_manager'); require_code('files2'); force_have_afm_details(); $contents = get_directory_contents(get_custom_file_base() . '/themes/' . $theme, '', true); foreach ($contents as $c) { afm_make_directory(dirname('themes/' . $to . '/' . $c), true, true); afm_copy('themes/' . $theme . '/' . $c, 'themes/' . $to . '/' . $c, true); } $needed = array('css', 'css_custom', 'images', 'images_custom', 'templates', 'templates_cached/' . get_site_default_lang(), 'templates_custom'); foreach ($needed as $n) { afm_make_directory(dirname('themes/' . $to . '/' . $n), true, true); } $images = $GLOBALS['SITE_DB']->query_select('theme_images', array('*'), array('theme' => $theme)); foreach ($images as $i) { $i['theme'] = $to; $i['path'] = str_replace('themes/' . $theme . '/', 'themes/' . $to . '/', $i['path']); $GLOBALS['SITE_DB']->query_insert('theme_images', $i); } log_it('COPY_THEME', $theme, $to); }
/** * Add a theme. * * @param ID_TEXT The theme name */ function actual_add_theme($name) { $GLOBALS['NO_QUERY_LIMIT'] = true; if (file_exists(get_custom_file_base() . '/themes/' . $name) || $name == 'default') { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name))); } require_code('abstract_file_manager'); force_have_afm_details(); // Create directories $dir_list = array('', 'images', 'images/logo', 'images_custom', 'templates', 'templates_custom', 'templates_cached', 'css', 'css_custom'); $langs = find_all_langs(true); foreach (array_keys($langs) as $lang) { $dir_list[] = 'templates_cached/' . $lang; } $dir_list_access = array('', 'images', 'images_custom', 'css'); foreach ($dir_list as $dir) { $path = 'themes/' . $name . '/' . $dir; afm_make_directory($path, true); if (!in_array($dir, $dir_list_access)) { // $path='themes/'.$name.'/'.$dir.'/.htaccess'; // afm_copy('themes/default/templates_cached/.htaccess',$path,false); } $path = 'themes/' . $name . '/' . ($dir == '' ? '' : $dir . '/') . 'index.html'; if (file_exists(get_file_base() . '/themes/default/templates_cached/index.html')) { afm_copy('themes/default/templates_cached/index.html', $path, false); } } afm_copy('themes/default/theme.ini', 'themes/' . $name . '/theme.ini', true); /*$_dir=opendir(get_custom_file_base().'/themes/default/css'); while (false!==($file=readdir($_dir))) { if (strtolower(substr($file,-4,4))=='.css') { $path='themes/'.$name.'/css_custom/'.$file; $new_css_file="@import url(../../../default/css/$file);\n\n".file_get_contents(get_custom_file_base().'/themes/default/css/'.$file,FILE_TEXT); afm_make_file($path,$new_css_file,false); } } closedir($_dir);*/ // Copy image references from default $start = 0; do { $theme_images = $GLOBALS['SITE_DB']->query_select('theme_images', array('*'), array('theme' => 'default'), '', 100, $start); foreach ($theme_images as $theme_image) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('theme_images', 'id', array('theme' => $name, 'id' => $theme_image['id'], 'lang' => $theme_image['lang'])); if (is_null($test)) { $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => $theme_image['id'], 'theme' => $name, 'path' => $theme_image['path'], 'lang' => $theme_image['lang'])); } } $start += 100; } while (count($theme_images) == 100); log_it('ADD_THEME', $name); }
/** * Extract all the files in the specified TAR file to the specified path. * * @param array The TAR file handle * @param PATH The full path to the folder to extract to * @param boolean Whether to extract via the AFM (assumes AFM has been set up prior to this function call) * @param ?array The files to extract (NULL: all) * @param boolean Whether to take backups of Comcode pages */ function tar_extract_to_folder(&$resource, $path, $use_afm = false, $files = NULL, $comcode_backups = false) { if (!array_key_exists('directory', $resource)) { tar_get_directory($resource); } if (substr($path, -1) != '/') { $path .= '/'; } $directory = $resource['directory']; foreach ($directory as $file) { if ($file['path'] != 'mod.inf' && $file['path'] != 'mod.php' && (is_null($files) || in_array($file['path'], $files))) { // Special case for directories. ocPortal doesn't add directory records, but at least 7-zip does if (substr($file['path'], -1) == '/') { if (!$use_afm) { @mkdir($path . $file['path'], 0777); fix_permissions($path . $file['path'], 0777); sync_file($path . $file['path']); } else { afm_make_directory($path . $file['path'], true); } continue; } $data = tar_get_file($resource, $file['path']); $path_components = explode('/', $file['path']); $buildup = ''; foreach ($path_components as $i => $component) { if ($component != '') { if (array_key_exists($i + 1, $path_components)) { $buildup .= $component . '/'; if (!$use_afm) { if (!file_exists($path . $buildup)) { @mkdir($path . $buildup, 0777); fix_permissions($path . $buildup, 0777); sync_file($path . $buildup); } } else { afm_make_directory($path . $buildup, true); } } } } // Take backup of Comcode page, if requested if ($comcode_backups) { if (substr($file['path'], -4) == '.txt') { if (!$use_afm) { if (file_exists(get_custom_file_base() . '/' . $path . $file['path'])) { copy(get_custom_file_base() . '/' . $path . $file['path'], $path . $file['path'] . '.' . strval(time())); } } else { if (file_exists(get_custom_file_base() . '/' . $path . $file['path'])) { afm_copy($path . $file['path'], $path . $file['path'] . '.' . strval(time()), true); } } } } // Actually make file if ($path == '/' && $comcode_backups && get_param_integer('keep_theme_test', 0) == 1 && preg_match('#^[\\w\\_]+\\.txt$#', basename($file['path'])) != 0) { $theme = NULL; foreach ($directory as $file2) { $matches = array(); if (preg_match('#^themes/([\\w\\_\\-]+)/#', $file2['path'], $matches) != 0) { $theme = $matches[1]; break; } } if (!is_null($theme)) { $file['path'] = dirname($file['path']) . '/' . $theme . '__' . basename($file['path']); } } if (!$use_afm) { $myfile = @fopen(get_custom_file_base() . '/' . $path . $file['path'], 'wb'); if ($myfile === false) { intelligent_write_error($path . $file['path']); } if (fwrite($myfile, $data['data']) < strlen($data['data'])) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } $fullpath = get_custom_file_base() . '/' . $path . $file['path']; @chmod($fullpath, $data['mode']); fclose($myfile); fix_permissions($fullpath); sync_file($fullpath); } else { afm_make_file($path . $file['path'], $data['data'], ($data['mode'] & 02) != 0); } } } }