Exemplo n.º 1
0
/**
 * 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);
}
Exemplo n.º 2
0
 /**
  * The UI to translate code.
  *
  * @return tempcode		The UI
  */
 function interface_code()
 {
     $lang = filter_naughty_harsh(get_param('lang', ''));
     $lang_new = get_param('lang_new', $lang);
     if ($lang_new != '') {
         require_code('type_validation');
         if (!is_alphanumeric($lang_new, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         if (strlen($lang_new) > 5) {
             warn_exit(do_lang_tempcode('INVALID_LANG_CODE'));
         }
         $lang = $lang_new;
     }
     if ($lang == '') {
         $title = get_page_title('TRANSLATE_CODE');
         $GLOBALS['HELPER_PANEL_TEXT'] = comcode_lang_string('DOC_FIND_LANG_STRING_TIP');
         return $this->choose_lang($title, true, true, do_lang_tempcode('CHOOSE_EDIT_LIST_LANG_FILE'));
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE'))));
     breadcrumb_set_self(do_lang_tempcode('TRANSLATE_CODE'));
     $base_lang = fallback_lang();
     $map_a = get_file_base() . '/lang/langs.ini';
     $map_b = get_custom_file_base() . '/lang_custom/langs.ini';
     $search = get_param('search', '', true);
     if ($search != '') {
         $title = get_page_title('TRANSLATE_CODE');
         require_code('form_templates');
         $fields = new ocp_tempcode();
         global $LANGUAGE;
         foreach ($LANGUAGE[user_lang()] as $key => $value) {
             if (strpos(strtolower($value), strtolower($search)) !== false) {
                 $fields->attach(form_input_text($key, '', 'l_' . $key, str_replace('\\n', chr(10), $value), false));
             }
         }
         if ($fields->is_empty()) {
             inform_exit(do_lang_tempcode('NO_ENTRIES'));
         }
         $post_url = build_url(array('page' => '_SELF', 'type' => '_code2'), '_SELF');
         $hidden = new ocp_tempcode();
         $hidden->attach(form_input_hidden('redirect', get_self_url(true)));
         $hidden->attach(form_input_hidden('lang', $lang));
         return do_template('FORM_SCREEN', array('_GUID' => '2d7356fd2c4497ceb19450e65331c9c5', 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => '', 'SUBMIT_NAME' => do_lang('TRANSLATE_CODE')));
     }
     $lang_file = get_param('lang_file');
     if (!file_exists($map_b)) {
         $map_b = $map_a;
     }
     $map = better_parse_ini_file($map_b);
     $title = get_page_title('_TRANSLATE_CODE', true, array(escape_html($lang_file), escape_html(array_key_exists($lang, $map) ? $map[$lang] : $lang)));
     // Upgrade to custom if not there yet (or maybe we are creating a new lang - same difference)
     $custom_dir = get_custom_file_base() . '/lang_custom/' . $lang;
     if (!file_exists($custom_dir)) {
         require_code('abstract_file_manager');
         force_have_afm_details();
         afm_make_directory('lang_custom/' . $lang, true);
         $cached_dir = get_custom_file_base() . '/lang_cached/' . $lang;
         if (!file_exists($cached_dir)) {
             afm_make_directory('lang_cached/' . $lang, true);
         }
         // Make comcode page dirs
         $zones = find_all_zones();
         foreach ($zones as $zone) {
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/comcode_custom/' . $lang, true);
             }
             $_special_dir = get_custom_file_base() . '/' . $zone . '/pages/html_custom/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory($zone . ($zone == '' ? '' : '/') . 'pages/html_custom/' . $lang, true);
             }
         }
         // Make templates_cached dirs
         require_code('themes2');
         $themes = find_all_themes();
         foreach (array_keys($themes) as $theme) {
             $_special_dir = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang;
             if (!file_exists($_special_dir)) {
                 afm_make_directory('themes/' . $theme . '/templates_cached/' . $lang, true);
             }
         }
     }
     // Get some stuff
     $for_lang = get_lang_file_map($lang, $lang_file);
     $for_base_lang = get_lang_file_map($base_lang, $lang_file, true);
     $descriptions = get_lang_file_descriptions($base_lang, $lang_file);
     // Make our translation page
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = new ocp_tempcode();
     $next = 0;
     $trans_lot = '';
     $delimit = chr(10) . '=-=-=-=-=-=-=-=-' . chr(10);
     foreach ($for_base_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         if ($current == '' && strtolower($name) != $name) {
             $trans_lot .= str_replace('\\n', chr(10), str_replace(array('{', '}'), array('(((', ')))'), $old)) . $delimit;
         }
     }
     $translated_stuff = array();
     if ($trans_lot != '' && $intertrans != '') {
         $result = http_download_file('http://translate.google.com/translate_t', NULL, false, false, 'ocPortal', array('text' => $trans_lot, 'langpair' => 'en|' . $intertrans));
         if (!is_null($result)) {
             require_code('character_sets');
             $result = convert_to_internal_encoding($result);
             $matches = array();
             if (preg_match('#<div id=result_box dir="ltr">(.*)</div>#Us', convert_to_internal_encoding($result), $matches) != 0) {
                 $result2 = $matches[1];
                 $result2 = @html_entity_decode($result2, ENT_QUOTES, get_charset());
                 $result2 = preg_replace('#\\s?<br>\\s?#', chr(10), $result2);
                 $result2 = str_replace('> ', '>', str_replace(' <', ' <', str_replace('</ ', '</', str_replace(array('(((', ')))'), array('{', '}'), $result2))));
                 $translated_stuff = explode(trim($delimit), $result2 . chr(10));
             }
         }
     }
     foreach ($for_base_lang + $for_lang as $name => $old) {
         if (array_key_exists($name, $for_lang)) {
             $current = $for_lang[$name];
         } else {
             $current = '';
             //$this->find_lang_matches($old,$lang); Too slow / useless for code translation
         }
         $description = array_key_exists($name, $descriptions) ? $descriptions[$name] : '';
         if ($current == '' && strtolower($name) != $name && array_key_exists($next, $translated_stuff)) {
             $_current = '';
             $translate_auto = trim($translated_stuff[$next]);
             $next++;
         } else {
             $_current = str_replace('\\n', chr(10), $current);
             $translate_auto = NULL;
         }
         if ($_current == '') {
             $_current = str_replace('\\n', chr(10), $old);
         }
         if ($intertrans != '' && get_value('google_translate_api_key') !== NULL) {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => '9e9a68cb2c1a1e23a901b84c9af2280b', 'LANG_FROM' => get_site_default_lang(), 'LANG_TO' => $lang, 'NAME' => 'trans_' . $name, 'OLD' => $_current));
         }
         $temp = do_template('TRANSLATE_LINE', array('_GUID' => '9cb331f5852ee043e6ad30b45aedc43b', 'TRANSLATE_AUTO' => $translate_auto, 'DESCRIPTION' => $description, 'NAME' => $name, 'OLD' => str_replace('\\n', chr(10), $old), 'CURRENT' => $_current, 'ACTIONS' => $actions));
         $lines .= $temp->evaluate();
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_code', 'lang_file' => $lang_file, 'lang' => $lang), '_SELF');
     return do_template('TRANSLATE_SCREEN', array('_GUID' => 'b3429f8bd0b4eb79c33709ca43e3207c', 'PAGE' => $lang_file, 'INTERTRANS' => get_value('google_translate_api_key') !== NULL ? $intertrans : '', 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Exemplo n.º 3
0
 /**
  * The actualiser for super debranding.
  *
  * @return tempcode		The UI
  */
 function actual()
 {
     require_code('config2');
     if (get_file_base() == get_custom_file_base()) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     set_value('rebrand_name', post_param('rebrand_name'));
     set_value('rebrand_base_url', post_param('rebrand_base_url'));
     set_value('company_name', post_param('company_name'));
     set_option('show_docs', post_param('show_docs', '0'));
     require_code('database_action');
     //set_option('allow_member_integration','off');
     foreach (array(get_file_base() . '/pages/comcode_custom/' . get_site_default_lang(), get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang()) as $dir) {
         if (!file_exists($dir)) {
             require_code('files');
             if (@mkdir($dir, 0777) === false) {
                 warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR', escape_html($dir)));
             }
             fix_permissions($dir, 0777);
             sync_file($dir);
         }
     }
     $keyboard_map_path = get_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/keymap.txt';
     $myfile = @fopen($keyboard_map_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($keyboard_map_path);
     }
     $km = post_param('keyboard_map');
     if (fwrite($myfile, $km) < strlen($km)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($keyboard_map_path);
     sync_file($keyboard_map_path);
     $adminguide_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/website.txt';
     $adminguide = post_param('adminguide');
     $adminguide = str_replace('__company__', post_param('company_name'), $adminguide);
     $myfile = @fopen($adminguide_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($adminguide_path);
     }
     if (fwrite($myfile, $adminguide) < strlen($adminguide)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($adminguide_path);
     sync_file($adminguide_path);
     $start_path = get_file_base() . '/adminzone/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
     if (!file_exists($start_path)) {
         $start = post_param('start_page');
         $myfile = @fopen($start_path, 'wb');
         if ($myfile === false) {
             intelligent_write_error($start_path);
         }
         if (fwrite($myfile, $start) < strlen($start)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($start_path);
         sync_file($start_path);
     }
     if (get_file_base() == get_custom_file_base()) {
         $critical_errors = file_get_contents(get_file_base() . '/sources/critical_errors.php');
         $critical_errors = str_replace('ocPortal', post_param('rebrand_name'), $critical_errors);
         $critical_errors = str_replace('http://ocportal.com', post_param('rebrand_base_url'), $critical_errors);
         $critical_errors = str_replace('ocProducts', 'ocProducts/' . post_param('company_name'), $critical_errors);
         $critical_errors_path = 'sources_custom/critical_errors.php';
         afm_make_file($critical_errors_path, $critical_errors, false);
     }
     $save_header_path = get_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_custom/HEADER.tpl';
     $header_path = $save_header_path;
     if (!file_exists($header_path)) {
         $header_path = get_file_base() . '/themes/default/templates/HEADER.tpl';
     }
     $header_tpl = file_get_contents($header_path);
     $header_tpl = str_replace('Copyright ocProducts Limited', '', $header_tpl);
     $myfile = @fopen($save_header_path, 'wb');
     if ($myfile === false) {
         intelligent_write_error($save_header_path);
     }
     if (fwrite($myfile, $header_tpl) < strlen($header_tpl)) {
         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
     }
     fclose($myfile);
     fix_permissions($save_header_path);
     sync_file($save_header_path);
     if (post_param_integer('churchy', 0) == 1) {
         if (is_object($GLOBALS['FORUM_DB'])) {
             $GLOBALS['FORUM_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         } else {
             $GLOBALS['SITE_DB']->query_delete('f_emoticons', array('e_code' => ':devil:'), '', 1);
         }
     }
     // Make sure some stuff is disabled for non-admin staff
     $staff_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     $disallowed_pages = array('admin_setupwizard', 'admin_addons', 'admin_backup', 'admin_errorlog', 'admin_import', 'admin_occle', 'admin_phpinfo', 'admin_debrand');
     foreach (array_keys($staff_groups) as $id) {
         foreach ($disallowed_pages as $page) {
             $GLOBALS['SITE_DB']->query_delete('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id), '', 1);
             // in case already exists
             $GLOBALS['SITE_DB']->query_insert('group_page_access', array('page_name' => $page, 'zone_name' => 'adminzone', 'group_id' => $id));
         }
     }
     // Clean up the theme images
     //  background-image
     $theme = $GLOBALS['FORUM_DRIVER']->get_theme();
     find_theme_image('background_image');
     //$GLOBALS['SITE_DB']->query_update('theme_images',array('path'=>'themes/default/images/blank.gif'),array('id'=>'background-image','theme'=>$theme),'',1); No longer ocp-specific
     //  logo/*
     if (addon_installed('zone_logos')) {
         find_theme_image('logo/adminzone-logo');
         find_theme_image('logo/cms-logo');
         find_theme_image('logo/collaboration-logo');
         $main_logo_url = find_theme_image('logo/-logo', false, true);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/adminzone-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/cms-logo', 'theme' => $theme), '', 1);
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $main_logo_url), array('id' => 'logo/collaboration-logo', 'theme' => $theme), '', 1);
     }
     // Various other icons
     require_code('uploads');
     $path = get_url('', 'favicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'favicon'));
     }
     $path = get_url('', 'appleicon', 'themes/default/images_custom');
     if ($path[0] != '') {
         $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'appleicon'));
     }
     if (addon_installed('ocf_avatars')) {
         $path = get_url('', 'system_avatar', 'themes/default/images_custom');
         if ($path[0] != '') {
             $GLOBALS['SITE_DB']->query_update('theme_images', array('path' => $path[0]), array('id' => 'ocf_default_avatars/default_set/ocp_fanatic'));
         }
     }
     $title = get_page_title('SUPER_DEBRAND');
     // Redirect them back to editing screen
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Exemplo n.º 4
0
 /**
  * The actualiser to add a zone.
  *
  * @return tempcode		The UI
  */
 function _add_zone()
 {
     if (get_file_base() != get_custom_file_base()) {
         warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
     }
     $title = get_page_title('ADD_ZONE');
     require_code('abstract_file_manager');
     force_have_afm_details();
     $zone = post_param('zone');
     $_title = post_param('title');
     $default_page = post_param('default_page');
     $header_text = post_param('header_text');
     $theme = post_param('theme');
     $wide = post_param_integer('wide');
     if ($wide == -1) {
         $wide = NULL;
     }
     $require_session = post_param_integer('require_session', 0);
     $displayed_in_menu = post_param_integer('displayed_in_menu', 0);
     actual_add_zone($zone, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu);
     $this->set_permissions($zone);
     // Show it worked / Refresh
     $url = build_url(array('page' => $default_page), $zone);
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Exemplo n.º 5
0
/**
 * Make a theme. Note that this will trigger the AFM.
 *
 * @param  string		Name of the theme.
 * @param  ID_TEXT	The theme it's being generated from
 * @param  ID_TEXT	The algorithm to use
 * @set equations hsv
 * @param  string		Seed colour to use.
 * @param  boolean	Whether to use the theme immediately.
 * @param  ?boolean  Whether it will be a dark theme (NULL: autodetect).
 * @param  boolean	Whether to inherit the CSS, for easier theme upgrading.
 */
function make_theme($themename, $source_theme, $algorithm, $seed, $use, $dark = false, $inherit_css = false)
{
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    load_themewizard_params_from_theme($source_theme, $algorithm == 'hsv');
    if (file_exists(get_custom_file_base() . '/themes/' . $themename)) {
        require_code('abstract_file_manager');
        force_have_afm_details();
        $extending_existing = true;
    } else {
        if ($source_theme == 'default') {
            actual_add_theme($themename);
        } else {
            require_code('themes3');
            actual_copy_theme($source_theme, $themename);
        }
        $extending_existing = false;
    }
    if ($seed != find_theme_seed($source_theme) || $dark != find_theme_dark($source_theme)) {
        list($colours, $landscape) = calculate_theme($seed, $source_theme, $algorithm, 'colours', $dark);
        // Make images
        global $THEME_WIZARD_IMAGES, $THEME_WIZARD_IMAGES_NO_WILD, $IMG_CODES;
        if (function_exists('imagecolorallocatealpha')) {
            require_code('themes2');
            $full_img_set = array();
            foreach ($THEME_WIZARD_IMAGES as $expression) {
                if (substr($expression, -1) == '*') {
                    $expression = substr($expression, 0, strlen($expression) - 2);
                    // remove "/*"
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images', $expression)));
                    $full_img_set = array_merge($full_img_set, array_keys(get_all_image_codes(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/images/' . fallback_lang(), $expression)));
                } else {
                    $full_img_set[] = $expression;
                }
            }
            if ($extending_existing) {
                $temp_all_ids = collapse_2d_complexity('id', 'path', $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $themename)));
            } else {
                $temp_all_ids = array();
            }
            $_langs = find_all_langs(true);
            foreach ($full_img_set as $image_code) {
                if (!in_array($image_code, $THEME_WIZARD_IMAGES_NO_WILD)) {
                    if ($extending_existing && array_key_exists($image_code, $temp_all_ids) && strpos($temp_all_ids[$image_code], $themename . '/images_custom/') !== false && (!url_is_local($temp_all_ids[$image_code]) || file_exists(get_custom_file_base() . '/' . $temp_all_ids[$image_code]))) {
                        continue;
                    }
                    foreach (array_keys($_langs) as $lang) {
                        $orig_path = find_theme_image($image_code, true, true, $source_theme, $lang);
                        if ($orig_path == '') {
                            continue;
                        }
                        // Theme has specified non-existent image as themewizard-compatible
                        if (strpos($orig_path, '/' . $lang . '/') === false && $lang != fallback_lang()) {
                            continue;
                        }
                        if (strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/' . $lang . '/';
                        } else {
                            $composite = 'themes/' . filter_naughty($themename) . '/images/';
                        }
                        $saveat = get_custom_file_base() . '/' . $composite . $image_code . '.png';
                        $saveat_url = $composite . $image_code . '.png';
                        // Wipe out ones that might have been copied from source theme
                        if ($source_theme != 'default' && strpos($orig_path, 'images_custom') !== false) {
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.png');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpg');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.gif');
                            @unlink(str_replace('/images/', '/images_custom/', basename($saveat, '.png')) . '.jpeg');
                        }
                        if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                            $image = calculate_theme($seed, $source_theme, $algorithm, $image_code, $dark, $colours, $landscape, $lang);
                            if (!is_null($image)) {
                                $pos = strpos($image_code, '/');
                                if ($pos !== false || strpos($orig_path, '/' . fallback_lang() . '/') !== false) {
                                    afm_make_directory($composite . substr($image_code, 0, $pos), true, true);
                                }
                                @imagepng($image, $saveat) or intelligent_write_error($saveat);
                                imagedestroy($image);
                                fix_permissions($saveat);
                                sync_file($saveat);
                                actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                                //if ($lang==fallback_lang()) $IMG_CODES['site'][$image_code]=$saveat_url;
                            }
                        } else {
                            actual_edit_theme_image($image_code, $themename, $lang, $image_code, $saveat_url, true);
                        }
                    }
                }
            }
        }
        // Make sheets
        $dh = opendir(get_file_base() . '/themes/' . filter_naughty($source_theme) . ($source_theme == 'default' ? '/css/' : '/css_custom/'));
        while (($sheet = readdir($dh)) !== false) {
            if (substr($sheet, -4) == '.css') {
                $saveat = get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet;
                if (!file_exists($saveat) || $source_theme != 'default' || $algorithm == 'hsv') {
                    $fp = @fopen($saveat, 'wt') or intelligent_write_error(get_custom_file_base() . '/themes/' . filter_naughty($themename) . '/css_custom/' . $sheet);
                    if ($inherit_css) {
                        $output = '{+START,CSS_INHERIT,' . basename($sheet, '.css') . ',' . filter_naughty($source_theme) . ',' . $seed . ',' . ($dark ? '1' : '0') . ',' . $algorithm . '}{+END}';
                    } else {
                        $output = theme_wizard_colours_to_sheet($sheet, $landscape, $source_theme, $algorithm, $seed);
                    }
                    if (fwrite($fp, $output) < strlen($output)) {
                        warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                    }
                    fclose($fp);
                    fix_permissions($saveat);
                    sync_file($saveat);
                    if (!$inherit_css) {
                        $c_success = @copy(get_file_base() . '/themes/' . filter_naughty($source_theme) . '/css/' . $sheet, $saveat . '.editfrom');
                        if ($c_success !== false) {
                            fix_permissions($saveat . '.editfrom');
                            sync_file($saveat . '.editfrom');
                        }
                    } else {
                        @unlink($saveat . '.editfrom');
                    }
                }
            }
        }
    }
    // Use it, if requested
    if ($use) {
        $GLOBALS['SITE_DB']->query('UPDATE ' . get_table_prefix() . 'zones SET zone_theme=\'' . db_escape_string($themename) . '\' WHERE ' . db_string_not_equal_to('zone_name', 'cms') . ' AND ' . db_string_not_equal_to('zone_name', 'adminzone'));
        $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
        $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
        $GLOBALS['SITE_DB']->query_delete('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename));
        foreach (array_keys($groups) as $group_id) {
            if (in_array($group_id, $admin_groups)) {
                continue;
            }
            $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'theme', 'category_name' => $themename, 'group_id' => $group_id));
        }
        persistant_cache_empty();
    }
}
Exemplo n.º 6
0
 /**
  * The actualiser to move a page.
  *
  * @return tempcode		The UI
  */
 function _move()
 {
     $title = get_page_title('MOVE_PAGES');
     if (get_file_base() != get_custom_file_base()) {
         warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
     }
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/move';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_structure';
     $zone = post_param('zone', NULL);
     if (is_null($zone)) {
         $post_url = build_url(array('page' => '_SELF', 'type' => get_param('type')), '_SELF', NULL, true);
         $hidden = build_keep_form_fields('', true);
         return do_template('YESNO_SCREEN', array('_GUID' => 'c6e872cc62bdc7cf1c5157fbfdb2dfd6', 'TITLE' => $title, 'TEXT' => do_lang_tempcode('Q_SURE'), 'URL' => $post_url, 'HIDDEN' => $hidden));
     }
     $new_zone = post_param('destination_zone', '');
     if (substr($new_zone, -1) == ':') {
         $new_zone = substr($new_zone, 0, strlen($new_zone) - 1);
     }
     //$pages=find_all_pages_wrap($zone);
     $pages = array();
     require_code('site');
     foreach ($_POST as $key => $val) {
         if (substr($key, 0, 6) == 'page__' && $val === '1') {
             $page = substr($key, 6);
             $page_details = _request_page($page, $zone, NULL, NULL, true);
             if ($page_details === false) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             $pages[$page] = strtolower($page_details[0]);
             if (array_key_exists(3, $page_details)) {
                 $pages[$page] .= '/' . $page_details[3];
             }
         }
     }
     $afm_needed = false;
     foreach ($pages as $page => $type) {
         if (post_param_integer('page__' . $page, 0) == 1) {
             if ($type != 'comcode_custom') {
                 $afm_needed = true;
             }
         }
     }
     if ($afm_needed) {
         require_code('abstract_file_manager');
         force_have_afm_details();
     }
     $cannot_move = new ocp_tempcode();
     foreach ($pages as $page => $type) {
         if (!is_string($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             if (substr($type, 0, 7) == 'modules') {
                 $_page = $page . '.php';
             } elseif (substr($type, 0, 7) == 'comcode') {
                 $_page = $page . '.txt';
             } elseif (substr($type, 0, 4) == 'html') {
                 $_page = $page . '.htm';
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 if (!$cannot_move->is_empty()) {
                     $cannot_move->attach(do_lang_tempcode('LIST_SEP'));
                 }
                 $cannot_move->attach(do_lang_tempcode('PAGE_WRITE', escape_html($page)));
                 continue;
             }
         }
     }
     $moved_something = NULL;
     foreach ($pages as $page => $type) {
         if (!is_string($page)) {
             $page = strval($page);
         }
         if (post_param_integer('page__' . $page, 0) == 1) {
             $moved_something = $page;
             if (substr($type, 0, 7) == 'modules') {
                 $_page = $page . '.php';
             } elseif (substr($type, 0, 7) == 'comcode') {
                 $_page = $page . '.txt';
             } elseif (substr($type, 0, 4) == 'html') {
                 $_page = $page . '.htm';
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 continue;
             }
             if (file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page))) {
                 if ($afm_needed) {
                     afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page, true));
                 } else {
                     rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty($type) . '/' . $_page));
                 }
             }
             // If a non-overridden one is there too, need to move that too
             if (strpos($type, '_custom') !== false && file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page)) && !file_exists(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page))) {
                 if ($afm_needed) {
                     afm_move(zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true), zone_black_magic_filterer(filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page, true));
                 } else {
                     rename(zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page), zone_black_magic_filterer(get_custom_file_base() . '/' . filter_naughty($new_zone) . ($new_zone != '' ? '/' : '') . 'pages/' . filter_naughty(str_replace('_custom', '', $type)) . '/' . $_page));
                 }
             }
             log_it('MOVE_PAGES', $page);
         }
     }
     if (is_null($moved_something)) {
         warn_exit(do_lang_tempcode('NOTHING_SELECTED'));
     }
     persistant_cache_empty();
     require_lang('addons');
     if ($cannot_move->is_empty()) {
         $message = do_lang_tempcode('SUCCESS');
     } else {
         $message = do_lang_tempcode('WOULD_NOT_OVERWRITE_BUT_SUCCESS', $cannot_move);
     }
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PAGES')), array('_SELF:_SELF:move', do_lang_tempcode('MOVE_PAGES'))));
     decache('main_sitemap');
     if (has_js()) {
         return inform_screen($title, $message);
         // Came from site-tree editor, so want to just close this window when done
     }
     return $this->do_next_manager($title, $moved_something, $new_zone, new ocp_tempcode());
 }
Exemplo n.º 7
0
    /**
     * Standard import function.
     *
     * @param  object			The DB connection to import from
     * @param  string			The table prefix the target prefix is using
     * @param  PATH			The base directory we are importing from
     */
    function import_pages($db, $table_prefix, $file_base)
    {
        unset($db);
        unset($table_prefix);
        require_code('files2');
        $files = @get_directory_contents($file_base);
        $theme = either_param('theme');
        $convert_to_comcode = either_param_integer('convert_to_comcode', 0);
        $fix_html = either_param_integer('fix_html', 0);
        $base_url = either_param('base_url');
        if (substr($base_url, -1) == '/') {
            $base_url = substr($base_url, 0, strlen($base_url) - 1);
        }
        // Find all htm/html/php files
        $content_files = array();
        foreach ($files as $i => $file) {
            if (substr(strtolower($file), -4) == '.htm' || substr(strtolower($file), -5) == '.html' || substr(strtolower($file), -4) == '.php') {
                $content_files[] = $file;
                unset($files[$i]);
            }
        }
        if (count($content_files) == 0) {
            warn_exit(do_lang_tempcode('NO_PAGES_FOUND'));
        }
        // Discern new zones needed
        //  Note: files in directories in a deep path will be considered in a zone name changed so underscores replace slashes
        $new_zones = array();
        $current_zones = find_all_zones();
        foreach ($content_files as $file) {
            $zone = str_replace('/', '_', dirname($file));
            if ($zone == '.') {
                $zone = '';
            }
            if (!in_array($zone, $current_zones)) {
                $new_zones[] = $zone;
            }
        }
        $new_zones = array_unique($new_zones);
        // (Maybe AFM needed here - if zones have to be created, and possibly .htaccess changed to incorporate zone names in the redirects)
        if (count($new_zones) != 0) {
            require_code('abstract_file_manager');
            force_have_afm_details();
            $change_htaccess = get_option('htm_short_urls') == '1';
            $htaccess_path = get_file_base() . '/.htaccess';
            if ($change_htaccess && file_exists($htaccess_path) && is_writable_wrap($htaccess_path)) {
                $htaccess = file_get_contents($htaccess_path);
                $htaccess = preg_replace('#\\(site\\|forum\\|adminzone\\|cms\\|collaboration[^\\)]*#', '${0}|' . implode('|', $new_zones), $htaccess);
                $myfile = fopen($htaccess_path, 'wt');
                fwrite($myfile, $htaccess);
                fclose($myfile);
                fix_permissions($htaccess_path);
                sync_file($htaccess_path);
            }
            // Create new zones as needed (and set them to our chosen theme too)
            require_code('zones2');
            foreach ($new_zones as $zone) {
                actual_add_zone($zone, ucwords(str_replace('_', ' ', $zone)), 'start', '', $theme, 0, 0);
            }
        }
        // Discern cruft in htm/html via looking for best levenshtein to length ratio over a few pages; scan by tag, not by byte
        $compare_file_contents = array();
        shuffle($content_files);
        for ($i = 0; $i < min(2, count($content_files)); $i++) {
            $file_contents = file_get_contents($file_base . '/' . $content_files[$i]);
            $compare_file_contents[$content_files[$i]] = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base);
        }
        $cruft = array();
        if (count($compare_file_contents) > 1) {
            $to_find = array();
            if (file_exists($file_base . '/header.txt')) {
                $cruft['HEADER'] = $this->_html_filter(file_get_contents($file_base . '/header.txt'), $fix_html, $base_url, $files, $file_base);
            } else {
                $to_find[] = 'HEADER';
            }
            if (file_exists($file_base . '/footer.txt')) {
                $cruft['FOOTER'] = $this->_html_filter(file_get_contents($file_base . '/footer.txt'), $fix_html, $base_url, $files, $file_base);
            } else {
                $to_find[] = 'FOOTER';
            }
            foreach ($to_find as $template_wanted) {
                $best_ratios = array();
                foreach ($compare_file_contents as $i => $reference_file) {
                    if ($template_wanted == 'HEADER') {
                        $last_pos = strpos($reference_file, '<body');
                        if ($last_pos === false) {
                            $last_pos = 0;
                        } else {
                            $last_pos += 5;
                        }
                    } else {
                        $last_pos = strlen($reference_file) - 1;
                    }
                    $best_av_ratios = mixed();
                    $ratios = array();
                    while ($last_pos !== false) {
                        //@print('!'.(strlen($reference_file)-$last_pos).' '.$lv.' '.$ratio.'<br />'.chr(10));flush();if (@$dd++==180) @exit('fini'); // Useful for debugging
                        if ($template_wanted == 'HEADER') {
                            $next_pos = strpos($reference_file, '<', $last_pos);
                        } else {
                            $next_pos = strrpos(substr($reference_file, 0, $last_pos), '<');
                        }
                        if ($next_pos !== false) {
                            if ($template_wanted == 'HEADER') {
                                $up_to = substr($reference_file, 0, $next_pos);
                            } else {
                                $up_to = substr($reference_file, $next_pos);
                            }
                            $all_ratios_for_pos = array();
                            foreach ($compare_file_contents as $j => $other_file) {
                                if ($i != $j) {
                                    if ($template_wanted == 'HEADER') {
                                        $up_to_other_file = substr($other_file, 0, $next_pos);
                                    } else {
                                        $up_to_other_file = substr($other_file, $next_pos - (strlen($reference_file) - strlen($other_file)));
                                    }
                                    $lv = fake_levenshtein($up_to, $up_to_other_file);
                                    if ($template_wanted == 'HEADER') {
                                        $ratio = floatval($lv) * 3 - floatval($next_pos + 1);
                                        // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against.
                                    } else {
                                        $ratio = floatval($lv) * 3 - floatval(strlen($reference_file) - $next_pos);
                                        // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against.
                                    }
                                    $all_ratios_for_pos[] = $ratio;
                                }
                            }
                            $av_ratios = array_sum($all_ratios_for_pos) / floatval(count($all_ratios_for_pos));
                            if (is_null($best_av_ratios) || $av_ratios < $best_av_ratios) {
                                $best_av_ratios = $av_ratios;
                            } elseif ($av_ratios > $best_av_ratios + 300) {
                                break;
                            }
                            $ratios[$next_pos] = $av_ratios;
                            if ($template_wanted == 'HEADER') {
                                $next_pos++;
                            } else {
                                $next_pos--;
                            }
                        }
                        $last_pos = $next_pos;
                    }
                    asort($ratios);
                    $best_by_pos = array_keys($ratios);
                    $best_ratios[] = array($best_by_pos[0], $ratios[$best_by_pos[0]], $reference_file);
                }
                $best = mixed();
                $best_pos = NULL;
                $best_reference_file = NULL;
                foreach ($best_ratios as $bits) {
                    list($pos, $ratio, $reference_file) = $bits;
                    if (is_null($best) || $ratio < $best) {
                        $best = $ratio;
                        $best_pos = $pos;
                        $best_reference_file = $reference_file;
                    }
                }
                if ($template_wanted == 'HEADER') {
                    $cruft[$template_wanted] = substr($best_reference_file, 0, $best_pos);
                } else {
                    $cruft[$template_wanted] = substr($best_reference_file, $best_pos);
                }
            }
        } else {
            // We can't find any common consistency when we only have one, so we mark all cruft and then later we will actually assume GLOBAL.tpl does not change and the only header/footer bit is the logical one
            $cruft['HEADER'] = array_key_exists(0, $compare_file_contents) ? $compare_file_contents[0] : '';
            $cruft['FOOTER'] = array_key_exists(1, $compare_file_contents) ? $compare_file_contents[0] : '';
        }
        // Extract header from cruft (<body> and before); SAVE
        $header = $cruft['HEADER'];
        // special cases of something with ID or class of header/top going through too
        $header_cases = array('<div id="header"', '<div id="page_header"', '<div class="header"', '<div class="page_header"');
        foreach ($header_cases as $header_case) {
            $header_start_pos = strpos($header, $header_case);
            if ($header_start_pos !== false) {
                $header_start_pos = strpos($header, '>', $header_start_pos) + 1;
                break;
            }
        }
        if ($header_start_pos !== false) {
            $div_count = 1;
            do {
                $next_start = strpos($header, '<div ', $header_start_pos);
                $next_end = strpos($header, '</div>', $header_start_pos);
                $header_start_pos = $next_start !== false && $next_start < $next_end ? $next_start : $next_end;
                if ($header_start_pos !== false) {
                    $header_start_pos = strpos($header, '>', $header_start_pos) + 1;
                }
                $div_count += $next_start !== false && $next_start < $next_end ? 1 : -1;
            } while ($div_count > 0 && $header_start_pos !== false);
        }
        $body_start_pos = strpos($header, '<body');
        $head_end_pos = strpos($header, '<link');
        if ($head_end_pos === false) {
            $head_end_pos = strpos($header, '</head');
        }
        if ($header_start_pos === false) {
            $header_start_pos = strpos($header, '>', $body_start_pos) + 1;
        }
        if ($header_start_pos !== false) {
            $header = substr($header, 0, $header_start_pos);
        }
        $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/HEADER.tpl';
        $myfile = fopen($path, 'wt');
        $header_to_write = substr($header, 0, $head_end_pos) . '	<script type="text/javascript">// <![CDATA[
		{+START,IF,{$AND,{$EQ,,{$_GET,keep_has_js}},{$NOT,{$JS_ON}}}}
		if ((window.location.href.indexOf(\'upgrader.php\')==-1) && (window.location.search.indexOf(\'keep_has_js\')==-1)) {$,Redirect with JS on, and then hopefully we can remove keep_has_js after one click. This code only happens if JS is marked off, no infinite loops can happen.}
			window.location=window.location.href+((window.location.search==\'\')?(((window.location.href.indexOf(\'.htm\')==-1)&&(window.location.href.indexOf(\'.php\')==-1))?(((window.location.href.substr(window.location.href.length-1)!=\'/\')?\'/\':\'\')+\'index.php?\'):\'?\'):\'&\')+\'keep_has_js=1{+START,IF,{$DEV_MODE}}&keep_devtest=1{+END}\';
		{+END}
		{+START,IF,{$NOT,{$BROWSER_MATCHES,ie}}}{+START,IF,{$HAS_SPECIFIC_PERMISSION,sees_javascript_error_alerts}}window.take_errors=true;{+END}{+END}
		var {+START,IF,{$CONFIG_OPTION,is_on_timezone_detection}}server_timestamp={$FROM_TIMESTAMP%},{+END}ocp_lang=\'{$LANG;}\',ocp_theme=\'{$THEME;}\';
	//]]></script>

	<meta name="description" content="{+START,IF,{$NEQ,{DESCRIPTION},{!NA}}}{DESCRIPTION*}{+END}" />
	<meta name="keywords" content="{KEYWORDS*}" />

	{$CSS_TEMPCODE}

	{+START,IF_PASSED,EXTRA_HEAD}
		{EXTRA_HEAD}
	{+END}

	{$JS_TEMPCODE,header}

	{REFRESH}' . substr($header, $head_end_pos);
        $header_to_write = preg_replace('#<title>[^<>]*</title>#', '<title>{+START,IF_NON_EMPTY,{HEADER_TEXT}}{HEADER_TEXT*} - {+END}{$SITE_NAME*}</title>', $header_to_write);
        $header_to_write = preg_replace('#<meta name="keywords" content="([^"]*)"[^>]*>#', '', $header_to_write);
        $header_to_write = preg_replace('#<meta name="description" content="([^"]*)"[^>]*>#', '', $header_to_write);
        fwrite($myfile, $header_to_write);
        fclose($myfile);
        fix_permissions($path);
        sync_file($path);
        // Extract footer from cruft (</body> and below); SAVE
        $footer = $cruft['FOOTER'];
        // special cases of something with ID or class of footer/bottom going through too
        $footer_cases = array('<div id="footer"', '<div id="page_footer"', '<div class="footer"', '<div class="page_footer"');
        foreach ($footer_cases as $footer_case) {
            $footer_start_pos = strpos($footer, $footer_case);
            if ($footer_start_pos !== false) {
                break;
            }
        }
        if ($footer_start_pos === false) {
            $footer_start_pos = strpos($footer, '</body');
        }
        if ($footer_start_pos !== false) {
            $footer = substr($footer, $footer_start_pos);
        }
        $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/FOOTER.tpl';
        $myfile = fopen($path, 'wt');
        $footer_to_write = $footer;
        fwrite($myfile, $footer_to_write);
        fclose($myfile);
        fix_permissions($path);
        sync_file($path);
        // What remains is saved to GLOBAL (note that we don't try and be clever about panels - this is up to the user, and they don't really need them anyway)
        if (count($compare_file_contents) > 1) {
            $global_to_write = substr($cruft['HEADER'], strlen($header)) . "\n{MIDDLE}\n" . substr($cruft['FOOTER'], 0, strlen($cruft['FOOTER']) - strlen($footer));
        } else {
            $cruft['HEADER'] = $header_to_write;
            $cruft['FOOTER'] = $footer_to_write;
            $global_to_write = '{MIDDLE}';
        }
        $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/GLOBAL.tpl';
        $myfile = fopen($path, 'wt');
        fwrite($myfile, $global_to_write);
        fclose($myfile);
        fix_permissions($path);
        sync_file($path);
        // Extract site name from <title> tag, based on common consistency (largest common substring)
        $site_name = get_site_name();
        if (count($compare_file_contents) > 1) {
            $titles_in_reference_files = array();
            foreach ($compare_file_contents as $reference_file) {
                $matches = array();
                if (preg_match('#<title>(.*)</title>#', $reference_file, $matches) != 0) {
                    $titles_in_reference_files[] = $matches[1];
                }
            }
            // Find largest common substring
            $lcs = '';
            foreach ($titles_in_reference_files as $title_a) {
                for ($start = 0; $start < strlen($title_a); $start++) {
                    for ($end = $start + 1; $end < strlen($title_a); $end++) {
                        $current = substr($title_a, $start, $end - $start + 1);
                        foreach ($titles_in_reference_files as $title_b) {
                            if ($title_a != $title_b) {
                                if (strpos(strtolower($title_b), strtolower($current)) === false) {
                                    continue 2;
                                }
                            }
                        }
                        if (strpos(strtolower($title_b), strtolower($current)) !== false) {
                            if (strlen($current) > strlen($lcs)) {
                                $lcs = $current;
                            }
                        }
                    }
                }
            }
            // Strip bits
            $site_name = trim(preg_replace('#^[\\|\\-�,]#', '', preg_replace('#[\\|\\-�,]$#', '', trim($lcs))));
            // Save as site name
            set_option('site_name', $site_name);
        }
        // Go and save our pages
        disable_php_memory_limit();
        foreach ($content_files as $content_file) {
            $file_contents = file_get_contents($file_base . '/' . $content_file);
            // Find page-link for page
            $slash_count = substr_count($content_file, '/');
            if ($slash_count == 0) {
                $content_file = '/' . $content_file;
            } elseif ($slash_count > 1) {
                $last_slash_pos = strrpos($content_file, '/');
                $content_file = str_replace('/', '_', substr($content_file, 0, $last_slash_pos)) . substr($content_file, 0, $last_slash_pos);
            }
            list($zone, $page) = explode('/', preg_replace('#\\..*$#', '', $content_file), 2);
            if ($page == 'index') {
                $page = 'start';
            }
            if (substr($content_file, -4) == '.php') {
                $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/minimodules_custom/' . $page . '.php');
                $myfile = fopen($file_path, 'wt');
                fwrite($myfile, $file_contents);
                fclose($myfile);
                fix_permissions($file_path);
                sync_file($file_path);
            } else {
                $filtered = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base);
                // Try and work out page title from <title> tag
                $matches = array();
                $page_title = NULL;
                if (preg_match('#<title>(.*)</title>#', $filtered, $matches) != 0) {
                    $page_title = preg_replace('#( [\\|\\-�] )?' . preg_quote($site_name) . '( [\\|\\-�] )?#', '', $matches[1]);
                }
                $page_keywords = NULL;
                if (preg_match('#<meta name="keywords" content="([^"]*)"#', $filtered, $matches) != 0) {
                    $page_keywords = $matches[1];
                }
                $page_description = NULL;
                if (preg_match('#<meta name="description" content="([^"]*)"#', $filtered, $matches) != 0) {
                    $page_description = $matches[1];
                }
                require_code('seo2');
                seo_meta_set_for_explicit('comcode_page', $zone . ':' . $page, $page_keywords, $page_description);
                // Strip cruft off for htm/html files
                $i = strpos($filtered, '</head>');
                if ($i === false) {
                    $i = 0;
                } else {
                    $i += 7;
                }
                $filtered = $this->levenshtein_strip_search($cruft['HEADER'], $filtered, false, $i);
                $filtered = $this->levenshtein_strip_search($cruft['FOOTER'], $filtered, true, 0);
                // Copy htm/html/php files to correct zone page directories (html_custom/<lang>, or minimodules_custom)
                if ($convert_to_comcode == 0) {
                    // Insert an <h1> if the h1 is not there
                    if (strpos($filtered, '<h1') === false && !is_null($page_title)) {
                        $filtered = "<h1>" . $page_title . "</h1>\n\n" . $filtered;
                    }
                    $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt');
                    $myfile = fopen($file_path, 'wt');
                    fwrite($myfile, '[semihtml]' . $filtered . '[/semihtml]');
                    fclose($myfile);
                    fix_permissions($file_path);
                    sync_file($file_path);
                } else {
                    // Insert an <h1> if the h1 is not there
                    if (strpos($filtered, '[title') === false && !is_null($page_title)) {
                        $filtered = "[title]" . $page_title . "[/title]\n\n" . $filtered;
                    }
                    require_code('comcode_from_html');
                    $comcode = semihtml_to_comcode($filtered);
                    $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt');
                    $myfile = fopen($file_path, 'wt');
                    fwrite($myfile, $comcode);
                    fclose($myfile);
                    fix_permissions($file_path);
                    sync_file($file_path);
                }
            }
        }
        // Copy all remaining files to under uploads/website_specific
        foreach ($files as $file) {
            if (!file_exists($file_base . '/' . $file)) {
                continue;
            }
            $path = get_custom_file_base() . '/uploads/website_specific/' . $file;
            $create_path = $path;
            do {
                @mkdir(dirname($create_path), 0777);
                $create_path = dirname($create_path);
            } while (strlen($create_path) > 1);
            copy($file_base . '/' . $file, $path);
            fix_permissions($path);
            sync_file($path);
        }
        // Set the panels to be blank
        foreach (array('site/', '') as $zone) {
            $panels = array('panel_left', 'panel_right');
            foreach ($panels as $panel) {
                $path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . 'pages/comcode_custom/' . filter_naughty(fallback_lang()) . '/' . filter_naughty($panel) . '.txt');
                $myfile = fopen($path, 'wt');
                fclose($myfile);
                fix_permissions($path);
                sync_file($path);
            }
        }
    }
Exemplo n.º 8
0
/**
 * Delete a theme.
 *
 * @param  ID_TEXT		The theme name
 */
function actual_delete_theme($theme)
{
    if ($theme == 'default') {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    global $CACHED_THEME;
    if (!is_null($CACHED_THEME) && $CACHED_THEME == $theme) {
        $CACHED_THEME = 'default';
    }
    require_code('abstract_file_manager');
    force_have_afm_details();
    afm_delete_directory('themes/' . $theme, true);
    $GLOBALS['SITE_DB']->query_delete('theme_images', array('theme' => $theme));
    log_it('DELETE_THEME', $theme);
}
Exemplo n.º 9
0
 /**
  * The actualiser to edit a comcode page.
  *
  * @return tempcode		The UI
  */
 function __ed()
 {
     $simple_add = get_param_integer('simple_add', 0) == 1;
     $title = get_page_title($simple_add ? 'COMCODE_PAGE_ADD' : 'COMCODE_PAGE_EDIT');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/comcode_page_edit';
     $file = filter_naughty(post_param('file'));
     $lang = filter_naughty(post_param('lang'));
     $zone = filter_naughty(post_param('zone'));
     if (addon_installed('page_management')) {
         $new_file = filter_naughty(has_actual_page_access(get_member(), 'admin_sitetree') ? post_param('title', $file) : $file);
     } else {
         $new_file = filter_naughty($file);
     }
     if ($file == '') {
         $file = $new_file;
     }
     require_code('type_validation');
     if (!is_alphanumeric($file, true)) {
         warn_exit(do_lang_tempcode('BAD_CODENAME'));
     }
     $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt');
     $renaming_page = $new_file != $file;
     if ($renaming_page) {
         if (!is_alphanumeric($new_file, true)) {
             warn_exit(do_lang_tempcode('BAD_CODENAME'));
         }
         $langs = find_all_langs(true);
         $rename_map = array();
         $afm_needed = false;
         // Actually will stay false as we don't allow renaming original-pages at the moment
         foreach (array_keys($langs) as $lang) {
             $path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $file . '.txt', true);
             if (is_file(get_file_base() . '/' . $path)) {
                 $new_path = zone_black_magic_filterer(filter_naughty($zone) . ($zone != '' ? '/' : '') . 'pages/comcode_custom/' . $lang . '/' . $new_file . '.txt', true);
                 if (is_file($new_path)) {
                     warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone . ':' . $new_file)));
                 }
                 $rename_map[$path] = $new_path;
             }
             if (is_file(get_file_base() . '/' . str_replace('/comcode_custom/', '/comcode/', $path))) {
                 $completion_text = do_lang_tempcode('ORIGINAL_PAGE_NO_RENAME');
             }
         }
         if ($afm_needed) {
             require_code('abstract_file_manager');
             force_have_afm_details();
         }
     }
     $validated = post_param_integer('validated', 0);
     if (!has_specific_permission(get_member(), 'bypass_validation_highrange_content')) {
         $validated = 0;
     }
     $parent_page = post_param('parent_page', '');
     $show_as_edit = post_param_integer('show_as_edit', 0);
     $resource_owner = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file));
     check_edit_permission('high', $resource_owner);
     if ($GLOBALS['FORUM_DRIVER']->is_super_admin(get_member())) {
         $_owner = post_param('owner', $GLOBALS['FORUM_DRIVER']->get_username(get_member()));
         $owner = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_owner);
         if (is_null($owner)) {
             $owner = get_member();
         }
     } else {
         $owner = get_member();
     }
     if (is_null($resource_owner)) {
         check_submit_permission('high');
         require_code('submit');
         give_submit_points('COMCODE_PAGE_ADD');
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => 0));
     } else {
         if (!has_actual_page_access(get_member(), $file, $zone)) {
             access_denied('PAGE_ACCESS');
         }
         require_code('submit');
         $just_validated = !content_validated('comcode_page', $zone . ':' . $file) && $validated == 1;
         if ($just_validated) {
             send_content_validated_notification('comcode_page', $zone . ':' . $file);
         }
         if (!addon_installed('unvalidated')) {
             $validated = 1;
         }
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $parent_page, 'p_validated' => $validated, 'p_edit_date' => time(), 'p_submitter' => $owner, 'p_show_as_edit' => $show_as_edit), array('the_zone' => $zone, 'the_page' => $file), '', 1);
     }
     if ($validated == 0) {
         require_code('submit');
         $edit_url = build_url(array('page' => '_SELF', 'type' => '_ed', 'page_link' => $zone . ':' . $new_file), '_SELF', NULL, false, false, true);
         if (addon_installed('unvalidated')) {
             send_validation_request('COMCODE_PAGE_EDIT', 'comcode_pages', true, $zone . ':' . $new_file, $edit_url);
         }
     }
     $new = post_param('post');
     require_code('attachments2');
     $_new = do_comcode_attachments($new, 'comcode_page', $zone . ':' . $file);
     $new = $_new['comcode'];
     if (!file_exists($fullpath) || $new != file_get_contents($fullpath, FILE_TEXT)) {
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile === false) {
             intelligent_write_error($fullpath);
         }
         final_attachments_from_preview($zone . ':' . $file);
         if (fwrite($myfile, $new) < strlen($new)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file($fullpath);
         $file_changed = true;
     } else {
         $file_changed = false;
     }
     require_code('seo2');
     $new_keywords = post_param('meta_keywords', '');
     $new_description = post_param('meta_description', '');
     if ($new_keywords == '' && $new_description == '') {
         seo_meta_set_for_implicit('comcode_page', $zone . ':' . $file, array($new), $new);
     } else {
         seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, $new_keywords, $new_description);
     }
     $completion_text = $validated == 0 ? do_lang_tempcode('SUBMIT_UNVALIDATED') : do_lang_tempcode('SUCCESS');
     // Update cache  NO WE CAN'T - THEY'RE MULTI-THEME NOW
     /*	$string_index=$GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages','string_index',array('the_zone'=>$zone,'the_page'=>$file));
     		if (!is_null($string_index))
     		{
     			lang_remap_comcode($string_index,$new);
     		} else
     		{
     			$string_index=insert_lang_comcode($new,1,NULL,false,NULL,NULL,false,NULL,NULL,60,true,true);
     			$GLOBALS['SITE_DB']->query_insert('cached_comcode_pages',array('the_zone'=>$zone,'the_page'=>$file,'string_index'=>$string_index));
     		}*/
     require_code('permissions2');
     set_page_permissions_from_environment($zone, $file);
     $caches = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => $zone, 'the_page' => $file));
     $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $file));
     foreach ($caches as $cache) {
         delete_lang($cache['string_index']);
     }
     persistant_cache_empty();
     persistant_cache_delete(array('PAGE_INFO'));
     decache('main_comcode_page_children');
     fix_permissions($fullpath);
     if (is_file($fullpath) && get_option('store_revisions') == '1' && $file_changed) {
         $time = time();
         @copy($fullpath, $fullpath . '.' . strval($time)) or intelligent_write_error($fullpath . '.' . strval($time));
         fix_permissions($fullpath . '.' . strval($time));
         sync_file($fullpath . '.' . strval($time));
     }
     log_it('COMCODE_PAGE_EDIT', $file, $zone);
     require_code('autosave');
     clear_ocp_autosave();
     if ($renaming_page) {
         $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone, 'the_page' => $new_file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_page' => $new_file), array('the_zone' => $zone, 'the_page' => $file), '', 1);
         $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_parent_page' => $new_file), array('the_zone' => $zone, 'p_parent_page' => $file));
         foreach ($rename_map as $path => $new_path) {
             if ($afm_needed) {
                 afm_move($path, $new_path);
             } else {
                 rename(get_custom_file_base() . '/' . $path, get_custom_file_base() . '/' . $new_path);
             }
         }
         if (addon_installed('awards')) {
             $types = $GLOBALS['SITE_DB']->query_select('award_types', array('id'), array('a_content_type' => 'comcode_page'));
             foreach ($types as $type) {
                 $GLOBALS['SITE_DB']->query_update('award_archive', array('content_id' => $new_file), array('content_id' => $file, 'a_type_id' => $type['id']));
             }
         }
         $file = $new_file;
     }
     if (post_param_integer('delete', 0) == 1) {
         unlink(get_custom_file_base() . '/' . $path);
     }
     if (addon_installed('awards')) {
         require_code('awards');
         handle_award_setting('comcode_page', $zone . ':' . $file);
     }
     decache('main_sitemap');
     breadcrumb_set_self(do_lang_tempcode('DONE'));
     // Look for bad title semantics
     $_new['html'] = $_new['tempcode']->evaluate();
     if (substr($file, 0, 1) != '_' && substr($file, 0, 6) != 'panel_' && trim($_new['html']) != '') {
         if (strpos($_new['html'], '<h1') === false && strpos($_new['comcode'], '[title]') === false && strpos($_new['comcode'], '[title="1"]') === false) {
             attach_message(do_lang_tempcode('NO_LEVEL_1_HEADERS'), 'notice');
         }
         $matches = array();
         if (strpos($_new['html'], '<h2') === false && preg_match_all('#\\n\\[(b|font|size)\\][^\\.]+\\[/(b|font|size)\\]\\n#', $_new['comcode'], $matches) >= 2) {
             attach_message(do_lang_tempcode('NO_LEVEL_2_HEADERS'), 'inform');
         }
     }
     // Show it worked / Refresh
     $url = post_param('redirect', '');
     if ($url != '') {
         return redirect_screen($title, $url, $completion_text);
     }
     return $this->do_next_manager($title, $file, $zone, $completion_text);
 }
Exemplo n.º 10
0
/**
 * Upgrade a theme automatically, using hand-coded migration arrays.
 *
 * @param   ID_TEXT	Theme to be upgraded
 * @param   float		From version
 * @param   float		Target version
 * @param   boolean	Whether executing a test run (i.e. not do anything)
 * @return  array		A pair: List of errors, List of successes
 */
function upgrade_theme($theme, $from_version, $to_version, $test_run = true)
{
    $errors = array();
    $successes = array();
    if (!$test_run) {
        require_code('abstract_file_manager');
        force_have_afm_details();
    }
    $css_replace__single_match = array();
    $css_prepend__single_match = array();
    $css_append__single_match = array();
    $css_replace__multi_match = array();
    $css_prepend__multi_match = array();
    $css_append__multi_match = array();
    $css_file_append = array();
    $theme_images_new = array();
    $theme_images_renames = array();
    $templates_replace = array();
    $templates_rename = array();
    $templates_borked = array();
    if ($from_version < 8.0 && $to_version >= 8.0 && $to_version < 9.0) {
        $css_recognition_string = '2004-2011';
        // Must be defined. Ensures theme is right version.
        $css_replace__multi_match = array('*' => array("2004-2011" => "2004-2012", "gradiant" => "gradient", "\$IMG," => "\$IMG;,", "url(\"" => "url('", "\")" => "')"), 'global.css' => array("comments_outer" => "comments_posting_form_outer", "comments_inner" => "comments_posting_form_inner", "comments_end" => "comments_posting_form_end", "comments_emoticons" => "comments_posting_form_emoticons", "comments_links" => "comments_posting_form_links"));
        $css_replace__single_match = array('adminzone.css' => array("template_edit_guid__true" => "template_edit_guid_1", "template_edit_guid__false" => "template_edit_guid_0"), 'calendar.css' => array(".calendar_week_hour {\n\twidth: 90px;\n}" => ".calendar_week_hour {\n\twidth: 90px;\n\theight: 30px;\n\tborder: 1px solid #6b81a1; /* {\$,dottedborder.border, 95% (seed sat_to 33) + 5% !W/B}*/\n}"), 'chat.css' => array(".chat_lobby_convos_area {\n}" => ".chat_lobby_convos_area {\n\toverflow: hidden;\n\twidth: 100%;\n}"), 'global.css' => array("tt, kbd, samp {\n\tfont-size: 1.25em;\n\tfont-weight: bold;\n}" => "tt, kbd, samp {\n\tfont-weight: bold;\n}", "input[type=\"text\"],input[type=\"password\"],textarea,select { /* Normally a browser default, but gets inherited on some phones */" => "input[type=\"text\"],input[type=\"password\"],input[type=\"color\"],input[type=\"email\"],input[type=\"number\"],input[type=\"range\"],input[type=\"search\"],input[type=\"tel\"],input[type=\"url\"],textarea,select { /* Normally a browser default, but gets inherited on some phones */", ".breadcrumbs {\n\tpadding: 5px 0 0 0;\n\tfloat: {!en_right};\n\tmargin-left: 5px;\n\tzoom: 1;\n}" => ".breadcrumbs {\n\tpadding: 5px 0 0 0;\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\tfloat: {!en_right};\n\t\tmargin-left: 5px;\n\t{+END}\n\tzoom: 1;\n}\n\n.breadcrumbs abbr {\n\twhite-space: nowrap;\n}", ".standardbox_wrap_panel img {\n\tmax-width: 100%;\n}" => ".standardbox_wrap_panel img {\n\tmax-width: 98%;\n}", ".standardbox_classic, .standardbox_links_classic {" => ".standardbox_classic, .standardbox_wrap_classic .standardbox_links_classic {", ".scale_down { /* {\$,Membership of this class is used as a tag to turn on image scaling} */\n\tmax-width: 100%;\n}" => ".scale_down { /* {\$,Membership of this class is used as a tag to turn on image scaling} */\n\tmax-width: 100%;\n\tbox-sizing: border-box;\n}", "ul.compact_list {" => "ul.compact_list, ol.compact_list {", "ul.compact_list li {" => "ul.compact_list li, ol.compact_list li {", "ul.spaced_list, .spaced_list ul {" => "ul.spaced_list, .spaced_list ul, ol.spaced_list, .spaced_list ol {", ".trinav_right {\n\tfloat: right;\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\tmargin-left: 10px;\n\t{+END}\n\t{+START,IF,{\$MOBILE}}\n\t\twidth: 33%;\n\t{+END}\n\ttext-align: right;\n}\n" => ".trinav_right {\n\tfloat: right;\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\tmargin-left: 10px;\n\t\tmargin-right: 26px;\n\t{+END}\n\t{+START,IF,{\$MOBILE}}\n\t\twidth: 33%;\n\t{+END}\n\ttext-align: right;\n}\n", ".category_entry {\n\tpadding: 6px 0;\n\tmargin: 6px 0;\n\tclear: both;\n}" => ".category_entry {\n\tpadding: 6px 0;\n\tmargin: 6px 0;\n\tclear: both;\n\toverflow: hidden;\n\twidth: 100%;\n}", "ul.actions_list li, ul.actions_list_compact li, ul.actions_list_super_compact li {\n\tpadding: 0;\n\tmargin: 0;\n\tlist-style-type: none;\n}" => "ul.actions_list li, ul.actions_list_compact li, ul.actions_list_super_compact li {\n\tpadding: 0;\n\tmargin: 0;\n\tlist-style-type: none;\n\tlist-style-image: none;\n}", ".non_link:link,\n.non_link:visited,\n.non_link:hover,\n.non_link:active {\n\tcolor: #0d1522; /* {\$,wizard, 20% seed + 80% !W/B} */\n\ttext-decoration: none;\n\tcursor: default;\n}" => ".non_link,\n.non_link:link,\n.non_link:visited,\n.non_link:hover,\n.non_link:active {\n\tcolor: #0d1522 !important; /* {\$,wizard, 20% seed + 80% !W/B} */\n\ttext-decoration: none;\n\tcursor: default;\n}", "text-shadow: 1px 1px 1px #000000; /* {\$,wizard, 100% !W/B} */\n\tmargin: 0 2px;\n}" => "text-shadow: 1px 1px 1px #000000; /* {\$,wizard, 100% !W/B} */\n\tmargin: 0 2px;\n\toverflow: visible; /* stops button padding on IE7 */\n}", ".inline_image {\n\tvertical-align: top;\n}\n\n.inline_image_2 {\n\tvertical-align: middle;\n}\n\n.inline_image_3 {\n\tvertical-align: baseline;\n}\n\n.inline_image_4 {\n\tmargin-top: -4px;\n}" => ".inline_image {\n\tvertical-align: top !important;\n}\n\n.inline_image_2 {\n\tvertical-align: middle !important;\n}\n\n.inline_image_3 {\n\tvertical-align: baseline !important;\n}\n\n.inline_image_4 {\n\tmargin-top: -4px !important;\n}", ".gallery_media_full_expose {\n\toverflow: hidden;\n\twidth: 100%;\n\toutline: 0;\n\tmargin: {\$?,{\$MOBILE},1,3}em 0;\n}\n\n.gallery_media_full_expose {\n\ttext-align: center;\n}" => ".gallery_media_full_expose {\n\toverflow: hidden;\n\twidth: 100%;\n\toutline: 0;\n\tmargin: {\$?,{\$MOBILE},1,3}em 0;\n\ttext-align: center;\n\tposition: relative;\n}", ".gallery_media_full_expose img, .img_thumb {\n\tborder: 1px solid #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\t-webkit-box-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\t-moz-box-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\tbox-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\tmax-width: 100%;\n}" => ".gallery_media_full_expose img, .img_thumb {\n\tborder: 1px solid #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\t-webkit-box-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\t-moz-box-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\tbox-shadow: 3px 3px 10px #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\tmax-width: 100%;\n\tbox-sizing: border-box;\n}", ".form_field_name {\n\tmargin: 4px 0;\n}" => ".form_field_name {\n\tmargin: 4px;\n\tdisplay: inline-block;\n}", ".input_author, .input_username, .input_colour, .input_email,\n" => ".input_author, .input_username, .input_colour, .input_email, .input_codename,\n", ".input_author_required, .input_username_required, .input_colour_required, .input_email_required,\n" => ".input_author_required, .input_username_required, .input_colour_required, .input_email_required, .input_codename_required,\n", ".members_viewing {\n\tborder-top: 0;\n\tpadding: 4px;\n\ttext-indent: 25px;\n\tpadding-{!en_left}: 0;\n}" => ".members_viewing {\n\tpadding: 4px;\n\ttext-indent: 25px;\n\tpadding-{!en_left}: 0;\n}\n\n.ocf_topic_0 .members_viewing {\n\tborder-top: 0;\n}", ".post .post_edit_link {\n}" => ".post .post_action_link {\n}\n\n.post .post_thread_children {\n\tmargin-top: 1em;\n\t{+START,IF,{\$MOBILE}}\n\t\tmargin-left: 7px;\n\t{+END}\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\tmargin-left: 20px;\n\t{+END}\n}\n\n.post .ocf_post_buttons {\n\tmargin-top: 1.3em;\n}\n\n.ocf_post_buttons a {\n\topacity: 0.0;\n\t-webkit-transition-property : opacity;\n\t-webkit-transition-duration : 0.5s;\n\t-moz-transition-property : opacity;\n\t-moz-transition-duration : 0.5s;\n\t-o-transition-property : opacity;\n\t-o-transition-duration : 0.5s;\n\ttransition-property : opacity;\n\ttransition-duration : 0.5s;\n}\n\n.ocf_post_buttons a[rel=\"add reply\"] {\n\topacity: 1.0;\n}\n\n.ocf_post_buttons:hover a {\n\topacity: 1.0;\n}\n\n.post_show_more {\n\ttext-align: center;\n\tborder: 1px dashed #c1cee3; /* {\$,wizard, 100% lightborder} */\n\tborder-bottom-left-radius: 40px;\n\tborder-bottom-right-radius: 40px;\n\tpadding: 15px;\n\tfont-weight: bold;\n\tfont-size: 0.85em;\n}\n\n.post .post_show_more {\n\tmargin-left: 20px;\n}", "ul.sitemap {\n\tlist-style-type: none;\n\tmargin-left: 0;\n\tpadding-left: 0;\n}" => "ul.sitemap {\n\tlist-style-type: none;\n\tlist-style-image: none;\n\tmargin-left: 0;\n\tpadding-left: 0;\n}", ".rating_inner {\n\ttext-align: center;\n\twhite-space: nowrap;\n}" => ".RATING_BOX .rating_inner {\n\ttext-align: center;\n}\n\n.RATING_INLINE_DYNAMIC .rating_inner, .RATING_INLINE_DYNAMIC form {\n\tdisplay: inline;\n}\n\n.post_action_link .RATING_INLINE_DYNAMIC {\n\tpadding-left: 20px;\n}\n\n.rating_inner {\n\twhite-space: nowrap;\n}\n\n.rating_inner img {\n\tcursor: pointer;\n}", ".tab {\n\tfloat: left;\n\tbackground: url('{\$IMG,tab}');\n\tpadding: 3px 5px 0 5px;\n\theight: 20px;\n\ttext-align: center;\n\tcursor: pointer;\n}" => ".tab {\n\tfloat: left;\n\tbackground: url('{\$IMG;,tab}') !important;\n\tpadding: 3px 7px 0 7px !important;\n\theight: 20px;\n\ttext-align: center;\n\tcursor: pointer;\n}", ".tab_active, .tab:hover {\n\tfont-weight: bold;\n}" => ".tab_active {\n\tfont-weight: bold;\n}\n\n.tab:hover {\n\ttext-decoration: underline !important;\n}", ".nl li {\n\tdisplay: block;\n\tmargin-{!en_left}: 0;\n\tpadding-{!en_left}: 0;\n\tlist-style-type: none;\n}" => ".nl li {\n\tdisplay: block;\n\tmargin-{!en_left}: 0;\n\tpadding-{!en_left}: 0;\n\tlist-style-type: none;\n\tlist-style-image: none;\n}", ".menu_type__popup li a:link a:hover {\n\tcolor: #9C202F; /* {\$,wizard, 100% a.hover}*/\n}" => ".menu_type__popup li a:hover {\n\tcolor: #9C202F !important; /* {\$,wizard, 100% a.hover}*/\n}", ".menu_type__top li, .menu_type__dropdown li.toplevel {\n\tfloat: {!en_left};\n\tborder-{!en_left}: 1px solid #0d1522; /* {\$,wizard, 20% seed + 80% !W/B} */\n\tmargin-{!en_right}: -1px;" => ".menu_type__top li, .menu_type__dropdown li.toplevel {\n\tfloat: {!en_left};\n\tborder-{!en_left}: 1px solid #0d1522; /* {\$,wizard, 20% seed + 80% !W/B} */\n\tmargin-{!en_right}: -1px;\n\tmargin-bottom: 0;", ".menu_type__top img, .menu_type__dropdown li.toplevel img {\n\tfloat: {!en_left};\n\tpadding: 0 8px 0 3px;\n\tmargin-top: -2px;\n}" => ".menu_type__top img, .menu_type__dropdown .toplevel_link img {\n\tmargin-top: -2px;\n}\n\n.menu_type__top img, .menu_type__dropdown img {\n\tfloat: {!en_left};\n\tpadding: 0 8px 0 3px;\n}", ".menu_type__top .menu_spacer, .menu_type__dropdown li.toplevel.menu_spacer {\n\theight: 1.15em;\n\twidth: 4em;\n\tpadding: 4px;\n}" => ".menu_type__top .menu_spacer, .menu_type__dropdown li.toplevel.menu_spacer {\n\theight: 1.15em;\n\twidth: 4em;\n\tpadding: 4px;\n\tfloat: {!en_left};\n}", ".menu_type__zone {\n\tfont-size: 0.9em;\n}" => ".menu_type__zone {\n\tfont-size: 0.9em;\n\tmax-height: 15px;\n}", ".menu_type__zone li {\n\tdisplay: inline;\n\tpadding: 0;\n\tlist-style-type: none;\n}" => ".menu_type__zone li {\n\tdisplay: inline;\n\tpadding: 0;\n\tlist-style-type: none;\n\tlist-style-image: none;\n}\n\n.menu_type__zone li * {\n\tvertical-align: middle;\n}", ".edit_menu_link_inline {\n\tposition: absolute;\n\tright: 1px;\n}" => "*>.edit_menu_link_inline {\n\tdisplay: none;\n}\n\n*:hover>.edit_menu_link_inline {\n\tdisplay: block;\n}\n\n.edit_menu_link_inline {\n\tposition: absolute;\n\tright: 1px;\n\tz-index: 10000;\n}", ".radio_list_picture {\n\tfloat: {!en_left};\n\twhite-space: nowrap;\n\tpadding: 3px;\n\tmin-width: 35px;\n\tmin-height: 35px;\n}" => ".radio_list_picture {\n\tfloat: {!en_left};\n\twhite-space: nowrap;\n\tpadding: 3px;\n\tmin-width: 40px;\n\tmin-height: 40px;\n\tfont-size: 0.8em;\n\tmin-height: 65px;\n\tmin-width: 85px;\n}"), 'news.css' => array(".standardbox_wrap_classic .news_piece_summary h3, .rss_summary h3 {\n\tmargin-{!en_right}: 130px;\n\tborder-bottom: 1px solid #6b81a1; /* {\$,wizard, 100% medborder.border} */\n}" => ".news_piece_summary h3, .rss_summary h3 {\n\tmargin-{!en_right}: 130px !important;\n\tborder-bottom: 1px solid #6b81a1 !important; /* {\$,wizard, 100% medborder.border} */\n}\n\n.rss_summary nobr { /* Stops naughty Google news from breaking layout */\n\twhite-space: normal;\n}"), 'ocf.css' => array(".ocf_post_details_date {\n\tfloat: {!en_left};\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\twidth: 25em;\n\t{+END}\n\tpadding-{!en_left}: 4px;\n}" => ".ocf_post_details_date {\n\tfloat: {!en_left};\n\tpadding-{!en_left}: 4px;\n}\n\n.ocf_post_details_rating {\n\tfloat: {!en_left};\n\tpadding-{!en_left}: 20px;\n\twhite-space: nowrap;\n}", ".ocf_information_bar { /* {\$,either OCF_GUEST_BAR.tpl or OCF_MEMBER_BAR.tpl} */\n\tbackground-color: #eef2f7; /* {\$,wizard, 60% bgcol + 40% W/B} */\n\tfont-size: 0.85em;\n\tborder-collapse: collapse;\n\twhite-space: nowrap;\n\twidth: 100%;\n}" => ".ocf_information_bar { /* {\$,either OCF_GUEST_BAR.tpl or OCF_MEMBER_BAR.tpl} */\n\tbackground-color: #eef2f7; /* {\$,wizard, 60% bgcol + 40% W/B} */\n\tfont-size: 0.85em;\n\tborder-collapse: collapse;\n\twhite-space: nowrap;\n\twidth: 100%;\n\tpadding: 0;\n}", ".ocf_member_column_d {\n\t{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\twidth: 11.3em;\n\t{+END}\n\t{+START,IF,{\$MOBILE}}\n\t\tfloat: left;\n\t{+END}\n\twhite-space: nowrap;\n}" => ".ocf_member_column_d {\n\twhite-space: nowrap;\n}", ".ocf_member_column_e {\n\twhite-space: nowrap;\n}\n\n" => "", ".ocf_post_details_unvalidated {\n\tfloat: {!en_left};\n\t}" => ".ocf_post_details_unvalidated {\n\tfloat: {!en_left};\n\tpadding-{!en_left}: 7px;\n\t}"), 'points.css' => array(".points_give_choices .sub_option {\n\tfont-size: 0.9em;\n}" => ".points_give_choices .sub_option {\n\tfont-size: 0.9em;\n\twhite-space: nowrap;\n}"), 'swfupload.css' => array("width: 365px;" => "{+START,IF,{\$NOT,{\$MOBILE}}}\n\t\twidth: 365px;\n\t{+END}"), 'tickets.css' => array(".closed_ticket {\n\tfont-weight: bold;\n\tpadding-{!en_left}: 30px;\n}" => ".closed_ticket {\n\tfont-style: italic;\n\tfloat: right;\n\tpadding-{!en_left}: 30px;\n}"));
        $css_prepend__single_match = array('adminzone.css' => array(".css_colour_strip" => ".dottedborder .css_colour_chooser_name {\n\twidth: 190px;\n}\n\n.dottedborder .css_colour_chooser {\n\twidth: 680px;\n\tmargin: 0;\n}\n\n", ".menu_editor_rh_side" => ".menu_editor_page.docked .menu_editor_rh_side {\n\toverflow-y: scroll;\n\tmax-height: 380px;\n\tmargin-right: 10px;\n}\n\n", ".menu_editor_lh_side" => ".menu_editor_page.docked #mini_form_hider {\n\tmargin-top: 1em;\n\tborder-top: 3px dotted #8b96df !important; /* {\$,wizard, 61% seed + 39% W/B} */\n\tposition: fixed;\n\tleft: 0;\n\tbottom: 0;\n\tbackground: #ffffff; /* {\$,wizard, 100% W/B} */\n\tfont-size: 0.9em;\n}\n\n.docked .menu_edit_main {\n\tpadding-bottom: 30em;\n}\n\n.dock_button {\n\tfloat: right;\n\tpadding: 5px;\n\tcursor: pointer;\n}\n\n"), 'calendar.css' => array(".top_navigation" => "abbr.dtstart, abbr.dtend {\n\tborder-bottom: 0;\n}\n\n"), 'galleries.css' => array(".nav_mid" => "#gallery_entry_screen {\n\twidth: 100%;\n\tmin-height: 100%;\n}\n\n", "/* side_root galleries block */" => ".slideshow_speed {\n\tposition: absolute;\n\tright: 0;\n\ttop: 0;\n}\n\n.slideshow_speed input {\n\twidth: 3em;\n}\n\n#changer {\n\tfont-weight: bold;\n\tfont-family: Courier;\n\tfont-size: 1.2em;\n}\n\n"), 'global.css' => array(".standardbox_title_classic a" => "h3.standardbox_title_classic {\n\tborder-bottom: 0;\n}\n\n", ".no_stbox_padding .dottedborder {" => ".overlay .dottedborder_huge_a, .overlay .dottedborder_barrier_a_nonrequired, .overlay .dottedborder_barrier_b_nonrequired, .overlay .dottedborder_divider, .overlay .dottedborder_divider_continue, .overlay .no_stbox_padding .forcedottedborder, .overlay .dottedborder {\n\tborder: 0;\n}\n\n", ".edited {" => ".bookmarks_menu_box {\n\twidth: 320px;\n}\n\n", "\na.poster_member:hover" => ".post_poster a.poster_member:link, .post_poster a.poster_member:active, .post_poster a.poster_member:visited, .post_poster a.poster_member:hover {\n\tdisplay: inline-block;\n}\n", ".menu_type__dropdown ul.nlevel, .menu_type__popup ul" => ".menu_type__popup {\n\tmin-width: 150px;\n}\n\n", ".comments_posting_form_inner table" => ".comments_posting_form_inner textarea {\n\tcolor: #94979d; /* {\$,wizard, 65% bgcol + 35% !W/B} */\n}\n\n"));
        $css_append__single_match = array('global.css' => array(".medborder_detailhead a:hover {\n\tcolor: #9C202F; /* {\$,wizard, 100% a.hover}*/\n}\n\n" => ".global_side .medborder_detailhead_wrap {\n\tpadding: 0;\n}\n\n.global_side .medborder_detailhead {\n\tborder-bottom: 0;\n\tpadding-left: 0;\n\tpadding-top: 5px;\n}\n\n", "\ttop: -256000px;\n\tleft: 0;\n" => "\tdisplay: block; /* stops browser bugs where it interacts with the layout flow incorrectly */\n", ".page_icon {\n\tvertical-align: middle;\n\t{+START,IF,{\$MOBILE}}\n\t\tmargin-bottom: 5px;\n\t{+END}\n}\n\n" => ".standardbox_title_classic .page_icon {\n\tmargin: -1px 3px 0 0;\n}\n\n", ".input_huge_field {\n}\n\n" => ".password_strength {\n\tfloat: right;\n\twidth: 100px;\n\tborder: 1px solid #6b81a1; /* {\$,wizard, 100% medborder.border} */\n\tdisplay: none;\n}\n\n.password_strength_inner {\n\theight: 1em;\n\twidth: 0px;\n}\n\n", ".radio_list_picture {\n\tfloat: {!en_left};\n\twhite-space: nowrap;\n\tpadding: 3px;\n\tmin-width: 40px;\n\tmin-height: 40px;\n}\n\n" => "#page_running_admin_themes .radio_list_picture {\n\tfloat: none;\n\tmargin: 15px;\n\tborder: 1px solid #c1cee3; /* {\$,wizard, 100% lightborder} */\n}\n\n.radio_list_picture img {\n\tmax-width: 100px;\n}\n\n", ".tab_last {\n\tborder-right: 1px solid;\n\tborder-color: #b5b5b5; /* {\$,wizard, 100% b5b5b5} */\n}\n\n" => ".tab_surround .tab { /* subtabs */\n\tpadding-top: 5px !important;\n\theight: 18px;\n\tfont-size: 0.88em;\n}\n\n", "#screen_actions .digg {\n\tbackground-image: url('{\$IMG,recommend/digg}');\n}" => "\n#screen_actions .google_plusone {\n\tmargin-top: 1px;\n}\n"));
        $css_file_append = array('galleries.css' => array("\n/* Miscellaneous media handling */\n\n.gallery_pdf {\n\twidth: 100%;\n\theight: 600px;\n}"), 'no_cache.css' => array("\n{\$BROWSER,opera,,tt\\, kbd\\, samp \\{ font-size: 1.25em; \\}}\n"));
        // NB: This UNIX command can work out what theme images are added...
        // OLD=/Library/WebServer/Documents/test/themes/default/images ; NEW=/Library/WebServer/Documents/git/themes/default/images ; diff -r $OLD $NEW | grep "Only in $NEW" | grep -v .DS_Store | sed "s#Only in "$NEW"##g" | sed "s#: #/#g" | sed "s#^/##g" | sed "s#^EN/##g" | sed "s#\.*$##"
        // Obviously only theme-wizable images should go here
        $theme_images_new = array('page/add_ticket', 'page/disable_notifications', 'page/enable_notifications', 'page/forum', 'page/send_message', 'pageitem/disable_notifications', 'pageitem/enable_notifications', 'pageitem/reply', 'pageitem/send_message');
        $theme_images_renames = array('standardboxes/title_gradiant' => 'standardboxes/title_gradient', 'quote_gradiant' => 'quote_gradient', 'zone_gradiant' => 'zone_gradient');
        $templates_replace = array('*' => array('_true' => '1', '_false' => '0', 'TOPIC_NAME' => 'TOPIC_TITLE', 'load_XML_doc' => 'do_ajax_request', 'DESPATCH' => 'DISPATCH'));
        /*Find deleted/renamed templates:
        		OLD=/Library/WebServer/Documents/test/themes/default/templates ; NEW=/Library/WebServer/Documents/git/themes/default/templates ; diff -r $OLD $NEW | grep .tpl$ | grep "Only in "$OLD | sed "s#Only in "$OLD": ##"*/
        $templates_rename = array('COMMENTS.tpl' => 'COMMENTS_POSTING_FORM.tpl', 'CEDI_RATING_INSIDE.tpl' => 'CEDI_RATING_FORM.tpl', 'RATING_INSIDE.tpl' => 'RATING_FORM.tpl', 'RATING.tpl' => 'RATING_BOX.tpl', 'RATING_INLINE.tpl' => 'RATING_INLINE_STATIC.tpl');
        /*Find diff of changes templates
        		OLD=/Library/WebServer/Documents/test/themes/default/templates ; NEW=/Library/WebServer/Documents/git/themes/default/templates ; diff -u $OLD $NEW > ~/Desktop/diff.txt*/
        $templates_borked = array('COMMENTS_POSTING_FORM.tpl', 'CEDI_RATING_FORM.tpl', 'RATING_FORM.tpl', 'RATING_BOX.tpl', 'RATING_INLINE_STATIC.tpl', 'COMMENTS_WRAPPER.tpl', 'CEDI_RATING.tpl', 'OCF_MEMBER_PROFILE_SCREEN.tpl', 'ATTACHMENT.tpl', 'POSTING_FORM.tpl', 'POSTING_FIELD.tpl', 'ATTACHMENTS.tpl', 'BLOCK_HELPER_DONE.tpl', 'ATTACHMENT_IMG.tpl', 'ATTACHMENT_IMG_MINI.tpl', 'CATALOGUE_DEFAULT_CATEGORY_SCREEN.tpl', 'JAVASCRIPT.tpl', 'JAVASCRIPT_AJAX.tpl', 'JAVASCRIPT_AJAX_PEOPLE_LISTS.tpl', 'JAVASCRIPT_CHAT.tpl', 'JAVASCRIPT_DATE_CHOOSER.tpl', 'JAVASCRIPT_EDITING.tpl', 'JAVASCRIPT_JWPLAYER.tpl', 'JAVASCRIPT_MENU_EDITOR.tpl', 'JAVASCRIPT_PERMISSIONS.tpl', 'JAVASCRIPT_POSTING.tpl', 'JAVASCRIPT_SOUND.tpl', 'JAVASCRIPT_STAFF.tpl', 'JAVASCRIPT_SWFUPLOAD.tpl', 'JAVASCRIPT_THUMBNAILS.tpl', 'JAVASCRIPT_TREE_LIST.tpl', 'JAVASCRIPT_VALIDATION.tpl', 'JAVASCRIPT_YAHOO_EVENTS.tpl', 'JAVASCRIPT_ZONE_EDITOR.tpl', 'FORM_SCREEN_INPUT_CAPTCHA.tpl', 'FORM_SCREEN_INPUT_DATE.tpl', 'FORM_SCREEN_INPUT_PASSWORD.tpl', 'FORM_SCREEN_INPUT_RADIO_LIST.tpl', 'FORM_SCREEN_INPUT_RADIO_LIST_ENTRY_PICTURE_2.tpl', 'FORM_SCREEN_INPUT_TICK.tpl', 'FORM_SCREEN_INPUT_TREE_LIST.tpl', 'FORM_SCREEN_INPUT_UPLOAD.tpl', 'FORM_SCREEN_INPUT_UPLOAD_MULTI.tpl', 'GALLERY_NAV.tpl', 'MENU_EDITOR_BRANCH_WRAP.tpl', 'MENU_EDITOR_SCREEN.tpl', 'OCF_FORUM.tpl', 'OCF_MEMBER_BAR.tpl', 'OCF_TOPIC_WRAP.tpl', 'PAGE_LINK_CHOOSER.tpl', 'POINTS_SCREEN.tpl', 'SUPPORT_TICKETS_SCREEN.tpl', 'SUPPORT_TICKET_SCREEN.tpl');
    } else {
        $errors[] = do_lang_tempcode('NO_DEFINED_THEME_UPGRADER');
        return array($errors, array());
    }
    if (addon_installed('themewizard')) {
        require_code('themewizard');
        $seed = find_theme_seed($theme);
        $dark = find_theme_dark($theme);
        list($colours, $landscape) = calculate_theme($seed, 'default', 'equations', 'colours', $dark);
    }
    // CSS
    $css_dir = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/css_custom/';
    $dh = @opendir($css_dir);
    if ($dh !== false) {
        while (($css_file = readdir($dh)) !== false) {
            if (substr($css_file, -4) != '.css') {
                continue;
            }
            if (substr($css_file, 0, 1) == '.') {
                continue;
            }
            $css_file_contents = file_get_contents($css_dir . $css_file);
            $orig_css_file_contents = $css_file_contents;
            if (strpos($css_file_contents, $css_recognition_string) === false) {
                $errors[] = do_lang_tempcode('NON_RECOGNISED_CSS_FILE', escape_html($css_file), escape_html(float_to_raw_string($from_version)));
                //continue;		Actually we'll let it pass
            }
            // Apply single match rules. First check single match rules apply exactly once (means rule is bogus if it matches more than once, or unusable if not at all)
            foreach (array('css_replace' => $css_replace__single_match, 'css_prepend' => $css_prepend__single_match, 'css_append' => $css_append__single_match) as $rule_set_type => $rule_set) {
                foreach ($rule_set as $target_file => $_rule_set) {
                    // If people have moved CSS into global.css, to optimise page load times
                    if ($target_file != '*' && $target_file != 'global.css' && $css_file == 'global.css') {
                        if (file_exists($css_dir . $target_file) && strlen(trim(file_get_contents($css_dir . $target_file))) == 0) {
                            $target_file = 'global.css';
                        }
                    }
                    if ($target_file == '*' || $target_file == $css_file) {
                        foreach ($_rule_set as $from => $to) {
                            // Apply theme wizard to $to
                            if (addon_installed('themewizard')) {
                                $to = theme_wizard_colours_to_css($to, $landscape, 'default', 'equations', $seed);
                            }
                            $occurrences = substr_count($css_file_contents, $from);
                            if ($occurrences == 0) {
                                if (addon_installed('themewizard')) {
                                    $from = theme_wizard_colours_to_css($from, $landscape, 'default', 'equations', $seed);
                                    $occurrences = substr_count($css_file_contents, $from);
                                }
                            }
                            if ($occurrences == 0) {
                                $errors[] = do_lang_tempcode('CSS_RULE_UNMATCHED_' . $rule_set_type, escape_html($from), escape_html($to), escape_html($target_file));
                            } elseif ($occurrences > 1) {
                                $errors[] = do_lang_tempcode('CSS_RULE_OVERMATCHED_' . $rule_set_type, escape_html($from), escape_html($to), escape_html($target_file));
                            } else {
                                switch ($rule_set_type) {
                                    case 'css_replace':
                                        $css_file_contents = str_replace($from, $to, $css_file_contents);
                                        break;
                                    case 'css_prepend':
                                        $pos = strpos($css_file_contents, $from);
                                        if (substr($css_file_contents, $pos - strlen($to), strlen($to)) != $to) {
                                            $css_file_contents = substr($css_file_contents, 0, $pos) . $to . substr($css_file_contents, $pos);
                                        }
                                        break;
                                    case 'css_append':
                                        $pos = strpos($css_file_contents, $from) + strlen($from);
                                        if (substr($css_file_contents, $pos, strlen($to)) != $to) {
                                            $css_file_contents = substr($css_file_contents, 0, $pos) . $to . substr($css_file_contents, $pos);
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            // Apply multi-match rules
            foreach (array('css_replace' => $css_replace__multi_match, 'css_prepend' => $css_prepend__multi_match, 'css_append' => $css_append__multi_match) as $rule_set_type => $rule_set) {
                foreach ($rule_set as $target_file => $_rule_set) {
                    if ($target_file == '*' || $target_file == $css_file) {
                        foreach ($_rule_set as $from_a => $to) {
                            // Apply theme wizard to $to
                            if (addon_installed('themewizard')) {
                                $to = theme_wizard_colours_to_css($to, $landscape, 'default', 'equations', $seed);
                            }
                            $froms = array($from_a);
                            if (addon_installed('themewizard')) {
                                $froms[] = theme_wizard_colours_to_css($from_a, $landscape, 'default', 'equations', $seed);
                            }
                            foreach ($froms as $from) {
                                switch ($rule_set_type) {
                                    case 'css_replace':
                                        $css_file_contents = str_replace($from, $to, $css_file_contents);
                                        break;
                                    case 'css_prepend':
                                        $pos = 0;
                                        do {
                                            $pos = strpos($css_file_contents, $from, $pos);
                                            if ($pos !== false) {
                                                if (substr($css_file_contents, $pos, -strlen($to)) != $to) {
                                                    $css_file_contents = substr($css_file_contents, 0, $pos) . $to . substr($css_file_contents, $pos);
                                                    $pos += strlen($to) + strlen($from);
                                                } else {
                                                    $pos += strlen($from);
                                                }
                                            }
                                        } while ($pos !== false);
                                        break;
                                    case 'css_append':
                                        $pos = 0;
                                        do {
                                            $pos = strpos($css_file_contents, $from, $pos);
                                            if ($pos !== false) {
                                                if (substr($css_file_contents, $pos, strlen($to)) != $to) {
                                                    $pos += strlen($from);
                                                    $css_file_contents = substr($css_file_contents, 0, $pos) . $to . substr($css_file_contents, $pos);
                                                    $pos += strlen($to);
                                                } else {
                                                    $pos += strlen($from);
                                                }
                                            }
                                        } while ($pos !== false);
                                        break;
                                }
                            }
                        }
                    }
                }
            }
            // Apply unmatched rules
            foreach ($css_file_append as $target_file => $rule_set) {
                if ($target_file == '*' || $target_file == $css_file) {
                    foreach ($rule_set as $to) {
                        $css_file_contents .= $to;
                    }
                }
            }
            if (!$test_run) {
                // Take revision
                $revision_file = $css_dir . $css_file . '.' . strval(time());
                if (@copy($css_dir . $css_file, $revision_file) !== false) {
                    fix_permissions($revision_file);
                    sync_file($revision_file);
                }
                // Save
                if ($orig_css_file_contents != $css_file_contents) {
                    $outfile = @fopen($css_dir . $css_file, 'wb') or intelligent_write_error($css_dir . $css_file);
                    fwrite($outfile, $css_file_contents);
                    fclose($outfile);
                }
                $successes[] = do_lang_tempcode('CSS_FILE_UPGRADED', escape_html($css_file));
            }
        }
        closedir($dh);
    }
    // Theme images
    require_code('themes2');
    $langs = array('EN' => 'lang');
    //find_all_langs();
    foreach ($theme_images_renames as $old => $new) {
        foreach (array_keys($langs) as $lang) {
            $path = urldecode(find_theme_image($old, true, true, $theme, $lang));
            if ($path != '') {
                $new_path = str_replace('/' . $old, '/' . $new, $path);
                if (!$test_run) {
                    if (!file_exists(get_custom_file_base() . '/' . $new_path)) {
                        if (file_exists($path)) {
                            afm_move($path, $new_path);
                        }
                        $where_map = array('theme' => $theme, 'id' => $new);
                        if ($lang != '' && !is_null($lang)) {
                            $where_map['lang'] = $lang;
                        }
                        $GLOBALS['SITE_DB']->query_delete('theme_images', $where_map);
                        actual_edit_theme_image($old, $theme, $lang, $new, $new_path);
                        $successes[] = do_lang_tempcode('THEME_IMAGE_RENAMED', escape_html($old), escape_html($new));
                    }
                }
            }
        }
    }
    if (addon_installed('themewizard')) {
        if ($theme != 'default') {
            foreach ($theme_images_new as $new) {
                foreach (array_keys($langs) as $lang) {
                    $path = urldecode(find_theme_image($new, true, true, 'default', $lang));
                    if ($path != '') {
                        $new_path = str_replace('themes/default/images/', 'themes/' . $theme . '/images/', $path);
                        if (!file_exists(get_custom_file_base() . '/' . $new_path)) {
                            if (!$test_run) {
                                afm_make_directory(dirname($new_path), true, true);
                            }
                            $image = calculate_theme($seed, 'default', 'equations', $new, $dark, $colours, $landscape, $lang);
                            if (!is_null($image)) {
                                if (!$test_run) {
                                    @imagepng($image, get_custom_file_base() . '/' . $new_path) or intelligent_write_error(get_custom_file_base() . '/' . $new_path);
                                    imagedestroy($image);
                                    fix_permissions(get_custom_file_base() . '/' . $new_path);
                                    sync_file(get_custom_file_base() . '/' . $new_path);
                                    $successes[] = do_lang_tempcode('THEME_IMAGE_NEW', escape_html($new));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Templates
    $templates_dir = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/';
    $dh = @opendir($templates_dir);
    if ($dh !== false) {
        while (($templates_file = readdir($dh)) !== false) {
            if (substr($templates_file, -4) != '.tpl') {
                continue;
            }
            $templates_file_contents = file_get_contents($templates_dir . $templates_file);
            $orig_templates_file_contents = $templates_file_contents;
            foreach ($templates_replace as $target_file => $rule_set) {
                if ($target_file == '*' || $target_file == $templates_file) {
                    foreach ($rule_set as $from => $to) {
                        $templates_file_contents = str_replace($from, $to, $templates_file_contents);
                    }
                }
            }
            if (array_key_exists($templates_file, $templates_rename)) {
                if (!$test_run) {
                    @rename($templates_dir . $templates_file, $templates_dir . $templates_rename[$templates_file]) or intelligent_write_error($templates_dir . $templates_rename[$templates_file]);
                    $successes[] = do_lang_tempcode('TEMPLATE_RENAMED', escape_html($templates_file), escape_html($templates_rename[$templates_file]));
                }
                $templates_file = $templates_rename[$templates_file];
            }
            if ($templates_file_contents != $orig_templates_file_contents) {
                if (!$test_run) {
                    $successes[] = do_lang_tempcode('TEMPLATE_ALTERED', escape_html($templates_file));
                    // Save
                    $outfile = @fopen($templates_dir . $templates_file, 'wb') or intelligent_write_error($templates_dir . $templates_file);
                    fwrite($outfile, $templates_file_contents);
                    fclose($outfile);
                }
            }
            if (in_array($templates_file, $templates_borked)) {
                $errors[] = do_lang_tempcode('TEMPLATE_WILL_NEED_RESTORING', escape_html($templates_file));
            }
        }
        closedir($dh);
    }
    return array($errors, $successes);
}
Exemplo n.º 11
0
 /**
  * UI for a setup wizard step (done).
  *
  * @return tempcode		The UI
  */
 function step10()
 {
     $title = get_page_title('SETUP_WIZARD_STEP', true, array(integer_format(10), integer_format(10)));
     $GLOBALS['NO_QUERY_LIMIT'] = true;
     require_code('abstract_file_manager');
     force_have_afm_details();
     if (function_exists('set_time_limit')) {
         @set_time_limit(600);
     }
     require_code('config2');
     require_code('menus2');
     require_code('themes2');
     require_lang('zones');
     $header_text = post_param('header_text');
     $name = post_param('site_name');
     $theme = substr(preg_replace('#[^A-Za-z\\d]#', '_', $name), 0, 40);
     $installprofile = post_param('installprofile', '');
     if ($installprofile != '') {
         // Simplify down to a single menu
         foreach (array('main_community', 'main_content', 'main_features', 'main_website', 'root_website') as $merge_item) {
             $GLOBALS['SITE_DB']->query_update('menu_items', array('i_menu' => 'site'), array('i_menu' => $merge_item));
         }
         $duplicates = $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'COUNT(*) AS cnt'), array('i_menu' => 'site'), 'GROUP BY i_url');
         foreach ($duplicates as $duplicate) {
             if ($duplicate['cnt'] > 1) {
                 delete_menu_item($duplicate['id']);
             }
         }
         delete_menu_item_simple('site:');
         // Remove panel_top
         if (addon_installed('redirects_editor')) {
             $GLOBALS['SITE_DB']->query_delete('redirects', array('r_to_page' => 'panel_top'));
         }
         $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_top.txt';
         if (file_exists($fullpath)) {
             @copy($fullpath, $fullpath . '.' . strval(time()));
         }
         $myfile = @fopen($fullpath, 'wt');
         if ($myfile !== false) {
             fwrite($myfile, '');
             fclose($myfile);
             fix_permissions($fullpath);
             sync_file($fullpath);
         }
         // Run any specific code for the profile
         $object = mixed();
         if (is_file(get_file_base() . '/sources/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php') || is_file(get_file_base() . '/sources_custom/hooks/modules/admin_setupwizard_installprofiles/' . $installprofile . '.php')) {
             require_code('hooks/modules/admin_setupwizard_installprofiles/' . $installprofile);
             $object = object_factory('Hook_admin_setupwizard_installprofiles_' . $installprofile, true);
         }
         if (!is_null($object)) {
             $object->install_code();
             $installprofileblocks = $object->default_blocks();
         } else {
             $installprofileblocks = array();
         }
     } else {
         $installprofileblocks = array();
     }
     if (post_param_integer('skip_8', 0) == 0 && function_exists('imagecreatefromstring') && addon_installed('themewizard')) {
         require_code('themewizard');
         // Make theme
         global $IMG_CODES;
         $old_img_codes_site = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'lang' => user_lang()));
         if (!file_exists(get_custom_file_base() . '/themes/' . $theme)) {
             make_theme($theme, 'default', 'equations', post_param('seed_hex'), true, post_param_integer('dark', 0) == 1);
         }
         foreach (array($theme, 'default') as $logo_save_theme) {
             $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'logo-template');
             $path = 'themes/' . $logo_save_theme . '/images_custom/-logo.png';
             @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
             actual_edit_theme_image('logo/-logo', $logo_save_theme, get_site_default_lang(), 'logo/-logo', $path, true);
             if (addon_installed('collaboration_zone')) {
                 actual_edit_theme_image('logo/collaboration-logo', $logo_save_theme, get_site_default_lang(), 'logo/collaboration-logo', $path, true);
             }
             imagedestroy($logo);
             $logo = generate_logo($name, $header_text, false, $logo_save_theme, 'trimmed-logo-template');
             $path = 'themes/' . $logo_save_theme . '/images_custom/trimmed-logo.png';
             @imagepng($logo, get_custom_file_base() . '/' . $path) or intelligent_write_error($path);
             actual_edit_theme_image('logo/trimmed-logo', $logo_save_theme, get_site_default_lang(), 'logo/trimmed-logo', $path, true);
             imagedestroy($logo);
         }
         $myfile = fopen(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini', 'wt');
         fwrite($myfile, 'title=' . $name . chr(10));
         fwrite($myfile, 'description=' . do_lang('NA') . chr(10));
         if (fwrite($myfile, 'author=ocPortal' . chr(10)) == 0) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         sync_file(get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/theme.ini');
         $IMG_CODES['site'] = $old_img_codes_site;
         // Just so it renders with the old theme
     }
     // Set options
     if (post_param_integer('skip_3', 0) == 0) {
         set_option('site_name', $name);
         set_option('copyright', 'Copyright &copy; ' . $name . ' ' . date('Y'));
         set_option('description', post_param('description'));
         set_option('site_scope', post_param('site_scope'));
         set_option('copyright', post_param('copyright'));
         set_option('staff_address', post_param('staff_address'));
         set_option('keywords', post_param('keywords'));
         set_option('google_analytics', post_param('google_analytics'));
         set_option('fixed_width', post_param('fixed_width', '0'));
         $a = $GLOBALS['SITE_DB']->query_value('zones', 'zone_header_text', array('zone_name' => ''));
         lang_remap($a, $header_text);
         $b = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => 'site'));
         if (!is_null($b)) {
             lang_remap($b, $header_text);
         }
     }
     if (post_param_integer('skip_9', 0) == 0) {
         set_option('site_closed', strval(post_param_integer('site_closed', 0)));
         set_option('closed', post_param('closed', ''));
     }
     // Set addons
     if (post_param_integer('skip_4', 0) == 0 && get_file_base() == get_custom_file_base()) {
         require_lang('addons');
         require_code('addons');
         $addons_installed = find_installed_addons();
         $uninstalling = array();
         foreach ($addons_installed as $addon_row) {
             if (post_param_integer('addon_' . $addon_row['addon_name'], 0) == 0) {
                 $uninstalling[$addon_row['addon_name']] = $addon_row;
             }
         }
         if (!file_exists(get_file_base() . '/.svn')) {
             do {
                 $cnt = count($uninstalling);
                 foreach ($addons_installed as $addon_row) {
                     if (array_key_exists($addon_row['addon_name'], $uninstalling)) {
                         $addon_row += read_addon_info($addon_row['addon_name']);
                         $addon_row['addon_author'] = '';
                         // Fudge, to stop it dying on warnings for official addons
                         // Check dependencies
                         $dependencies = $addon_row['addon_dependencies_on_this'];
                         foreach (array_keys($uninstalling) as $d) {
                             if (in_array($d, $dependencies)) {
                                 // Can mark this dependency as irrelevant, as we are uninstalling the addon for it anyway
                                 unset($dependencies[array_search($d, $dependencies)]);
                             }
                         }
                         if (count($dependencies) != 0) {
                             unset($uninstalling[$addon_row['addon_name']]);
                         }
                     }
                 }
             } while ($cnt != count($uninstalling));
             // Dependency chains can be complex, so loop until we're stopped finding anything changing
             foreach ($uninstalling as $addon_row) {
                 // Archive it off to exports/addons
                 if ($addon_row['addon_files'] != '') {
                     $file = preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $addon_row['addon_name'])) . '.tar';
                     create_addon($file, explode(chr(10), $addon_row['addon_files']), $addon_row['addon_name'], implode(',', $addon_row['addon_incompatibilities']), implode(',', $addon_row['addon_dependencies']), $addon_row['addon_author'], $addon_row['addon_organisation'], $addon_row['addon_version'], $addon_row['addon_description'], 'imports/addons');
                 }
                 uninstall_addon($addon_row['addon_name']);
             }
         }
     }
     // Set features
     if (post_param_integer('skip_5', 0) == 0) {
         $hooks = find_all_hooks('modules', 'admin_setupwizard');
         foreach (array_keys($hooks) as $hook) {
             if (post_param_integer('addon_' . $hook, 0) == 1) {
                 $path = get_file_base() . '/sources_custom/modules/systems/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php';
                 if (!file_exists($path)) {
                     $path = get_file_base() . '/sources/hooks/modules/admin_setupwizard/' . filter_naughty_harsh($hook) . '.php';
                 }
                 $_hook_bits = extract_module_functions($path, array('set_fields'));
                 if (is_array($_hook_bits[0])) {
                     call_user_func_array($_hook_bits[0][0], $_hook_bits[0][1]);
                 } else {
                     @eval($_hook_bits[0]);
                 }
             }
         }
         set_option('show_content_tagging', post_param('show_content_tagging', '0'));
         set_option('show_content_tagging_inline', post_param('show_content_tagging_inline', '0'));
         set_option('show_screen_actions', post_param('show_screen_actions', '0'));
     }
     // Zone structure
     $collapse_zones = post_param_integer('collapse_user_zones', 0) == 1;
     if (post_param_integer('skip_5', 0) == 0) {
         require_code('config2');
         set_option('collapse_user_zones', strval($collapse_zones));
         /*if (addon_installed('redirects_editor')) Old method
         		{
         			if ($collapse_zones)
         			{
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_left','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>'','r_is_transparent'=>1));
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'panel_right','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>'','r_is_transparent'=>1));
         				$test=$GLOBALS['SITE_DB']->query_value_null_ok('redirects','r_from_page',array('r_from_page'=>'start','r_from_zone'=>'site'));
         				if (is_null($test)) $GLOBALS['SITE_DB']->query_insert('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>'','r_is_transparent'=>1));
         			} else
         			{
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_left','r_from_zone'=>'site','r_to_page'=>'panel_left','r_to_zone'=>''),'',1);
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'panel_right','r_from_zone'=>'site','r_to_page'=>'panel_right','r_to_zone'=>''),'',1);
         				$GLOBALS['SITE_DB']->query_delete('redirects',array('r_from_page'=>'start','r_from_zone'=>'site','r_to_page'=>'start','r_to_zone'=>''),'',1);
         			}
         		}*/
         if (post_param_integer('guest_zone_access', 0) == 1) {
             $guest_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($GLOBALS['FORUM_DRIVER']->get_guest_id());
             $test = $GLOBALS['SITE_DB']->query_value_null_ok('group_zone_access', 'zone_name', array('zone_name' => 'site', 'group_id' => $guest_groups[0]));
             if (is_null($test)) {
                 $GLOBALS['SITE_DB']->query_insert('group_zone_access', array('zone_name' => 'site', 'group_id' => $guest_groups[0]));
             }
         }
     }
     // Rules
     if (post_param_integer('skip_7', 0) == 0) {
         $fullpath = get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt';
         if (file_exists($fullpath)) {
             @copy($fullpath, $fullpath . '.' . strval(time()));
             fix_permissions($fullpath . '.' . strval(time()));
             sync_file($fullpath . '.' . strval(time()));
         }
         $myfile = @fopen($fullpath, 'wt') or intelligent_write_error(get_custom_file_base() . '/pages/comcode_custom/' . get_site_default_lang() . '/rules.txt');
         $rf = $this->get_rules_file(post_param('rules'));
         if (fwrite($myfile, $rf) < strlen($rf)) {
             warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
         }
         fclose($myfile);
         fix_permissions($fullpath);
         sync_file($fullpath);
     }
     $block_options = mixed();
     if ($installprofile != '' && !is_null($object)) {
         $block_options = $object->block_options();
     }
     // Blocks
     if (post_param_integer('skip_6', 0) == 0) {
         require_code('setupwizard');
         $page_structure = _get_zone_pages($installprofileblocks, $block_options, $collapse_zones, $installprofile);
         foreach ($page_structure as $zone => $zone_pages) {
             // Start
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/start.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = @fopen($fullpath, 'wt') or intelligent_write_error($fullpath);
             if ($myfile !== false) {
                 if ($zone_pages['start'] != '') {
                     if (fwrite($myfile, $zone_pages['start']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
             // Left
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_left.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = @fopen($fullpath, 'wt');
             if ($myfile !== false) {
                 if ($zone_pages['left'] != '') {
                     if (fwrite($myfile, $zone_pages['left']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
             // Right
             $fullpath = get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/panel_right.txt';
             if (file_exists($fullpath)) {
                 @copy($fullpath, $fullpath . '.' . strval(time()));
             }
             $myfile = fopen($fullpath, 'wt');
             if ($myfile !== false) {
                 if ($zone_pages['right'] != '') {
                     if (fwrite($myfile, $zone_pages['right']) == 0) {
                         warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE'));
                     }
                 }
                 fclose($myfile);
                 fix_permissions($fullpath);
                 sync_file($fullpath);
             }
         }
     }
     // We're done
     set_value('setup_wizard_completed', '1');
     // Clear some cacheing
     require_code('view_modes');
     require_code('zones3');
     erase_comcode_page_cache();
     erase_tempcode_cache();
     //persistant_cache_delete('OPTIONS');  Done by set_option
     persistant_cache_empty();
     erase_cached_templates();
     //breadcrumb_set_parents(array(array('_SELF:_SELF:misc',do_lang_tempcode('START'))));
     //breadcrumb_set_self(do_lang_tempcode('SETUP_WIZARD_STEP',integer_format(10),integer_format(10)));
     $url = build_url(array('page' => '_SELF', 'type' => 'step11'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }
Exemplo n.º 12
0
/**
 * Delete a zone.
 *
 * @param  ID_TEXT		The name of the zone
 */
function actual_delete_zone($zone)
{
    if (get_file_base() != get_custom_file_base()) {
        warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT'));
    }
    require_code('abstract_file_manager');
    force_have_afm_details();
    if (function_exists('set_time_limit')) {
        @set_time_limit(0);
    }
    disable_php_memory_limit();
    $pages = find_all_pages_wrap($zone, false, false, FIND_ALL_PAGES__ALL);
    $bad = array();
    foreach (array_keys($pages) as $page) {
        if (substr($page, 0, 6) != 'panel_' && $page != 'start') {
            $bad[] = $page;
        }
    }
    if ($bad != array()) {
        require_lang('zones');
        warn_exit(do_lang_tempcode('DELETE_ZONE_ERROR', '<kbd>' . implode('</kbd>, <kbd>', $bad) . '</kbd>'));
    }
    actual_delete_zone_lite($zone);
    if (file_exists(get_custom_file_base() . '/' . filter_naughty($zone))) {
        afm_delete_directory(filter_naughty($zone), true);
    }
}
Exemplo n.º 13
0
 /**
  * The UI to uninstall an addon.
  *
  * @return tempcode		The UI
  */
 function _addon_uninstall()
 {
     $title = get_page_title('UNINSTALL_ADDON');
     require_code('abstract_file_manager');
     force_have_afm_details();
     $name = post_param('name');
     $addon_row = read_addon_info($name);
     // Archive it off to exports/mods
     if (file_exists(get_file_base() . '/sources/hooks/systems/addon_registry/' . $name . '.php')) {
         $file = preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $name)) . '.tar';
     } else {
         $file = preg_replace('#^[\\_\\.\\-]#', 'x', preg_replace('#[^\\w\\.\\-]#', '_', $name)) . date('-dmY-Hm', time()) . '.tar';
     }
     $new_addon_files = array();
     foreach ($addon_row['addon_files'] as $_file) {
         if (substr($_file, -9) != '.editfrom') {
             // This would have been added back in automatically
             $new_addon_files[] = $_file;
         }
     }
     create_addon($file, $new_addon_files, $addon_row['addon_name'], implode(',', $addon_row['addon_incompatibilities']), implode(',', $addon_row['addon_dependencies']), $addon_row['addon_author'], $addon_row['addon_organisation'], $addon_row['addon_version'], $addon_row['addon_description'], 'imports/mods');
     uninstall_addon($name);
     // Clear some cacheing
     require_code('view_modes');
     require_code('zones2');
     require_code('zones3');
     erase_comcode_page_cache();
     erase_tempcode_cache();
     //persistant_cache_delete('OPTIONS');  Done by set_option
     persistant_cache_empty();
     erase_cached_templates();
     // Show it worked / Refresh
     $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
 }