/** * Standard import function to get extra fields to ask for when starting the import. * * @return tempcode Extra fields */ function get_extra_fields() { // Give user options // - where to copy files from [actually this field is in admin_import.php] // - theme to save into (advise they should use Theme Wizard to create a theme with similar colour first) // - whether to Comcode-convert // - whether to fix invalid XHTML // - the base URL to use to turn absolute URLs into relative URLs $fields = new ocp_tempcode(); $themes = new ocp_tempcode(); require_code('themes2'); $_themes = find_all_themes(); require_code('form_templates'); foreach ($_themes as $theme => $theme_title) { $themes->attach(form_input_list_entry($theme, $theme == $GLOBALS['FORUM_DRIVER']->get_theme(), $theme_title)); } $fields = form_input_list(do_lang_tempcode('THEME'), do_lang_tempcode('THEME_TO_SAVE_INTO'), 'theme', $themes, NULL, true); $fields->attach(form_input_tick(do_lang_tempcode('WHETHER_CONVERT_COMCODE'), do_lang_tempcode('DESCRIPTION_WHETHER_CONVERT_COMCODE'), 'convert_to_comcode', false)); $fields->attach(form_input_tick(do_lang_tempcode('FIX_INVALID_HTML'), do_lang_tempcode('DESCRIPTION_FIX_INVALID_HTML'), 'fix_html', true)); $fields->attach(form_input_line(do_lang_tempcode('BASE_URL'), do_lang_tempcode('DESCRIPTION_IMPORT_BASE_URL'), 'base_url', get_base_url(), true)); return $fields; }
/** * 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)); }
/** * Get a UI list for choosing a theme. * * @param ?ID_TEXT The theme to select by default (NULL: no specific default) * @param boolean Whether to skip the 'rely on forums' entry * @param boolean Whether to forget about permissions for this list * @param ID_TEXT The language string to use for the default answer * @return tempcode The list */ function nice_get_themes($theme = NULL, $no_rely = false, $show_everything = false, $default_message_string = 'RELY_FORUMS') { if (!$no_rely) { $entries = form_input_list_entry('-1', false, do_lang_tempcode($default_message_string)); } else { $entries = new ocp_tempcode(); } $themes = find_all_themes(); foreach ($themes as $_theme => $title) { if ($show_everything || has_category_access(get_member(), 'theme', $_theme)) { $selected = $theme == $_theme; $entries->attach(form_input_list_entry($_theme, $selected, $title)); } } if ($entries->is_empty()) { $entries->attach(form_input_list_entry('default', false, $themes['default'])); } return $entries; }
require_code('images'); // Find default images $default_images = array(); foreach (array(get_custom_file_base() . '/themes/default/images', get_custom_file_base() . '/themes/default/images/EN') as $dir) { $dh = opendir($dir); while (($f = readdir($dh)) !== false) { if (is_image($f)) { $img_code = basename($f, '.' . get_file_extension($f)); $default_images[$img_code] = 1; } } closedir($dh); } // Go through each theme require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { if ($theme != 'default') { $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true); foreach (array_keys($groups) as $gid) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('group_id' => $gid, 'module_the_name' => 'theme', 'category_name' => $theme), false, true); } echo '<li>'; echo '<a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme), '')) . '">' . escape_html($theme) . '</a><br /> <span class="associated_details">(Other useful views: <a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme, 'keep_theme_seed' => '664422', 'keep_theme_algorithm' => 'hsv', 'keep_theme_source' => $theme), '')) . '">with brown seed</a> / <a href="' . static_evaluate_tempcode(build_url(array('page' => 'start', 'keep_theme_test' => '1', 'keep_theme' => $theme, 'keep_su' => 'Guest'), '')) . '">as Guest</a> / <a href="' . static_evaluate_tempcode(build_url(array('page' => 'cms_news', 'type' => 'ad', 'keep_theme_test' => '1', 'keep_theme' => $theme), 'cms')) . '">Add News Form</a> / <a href="' . static_evaluate_tempcode(build_url(array('page' => 'news', 'keep_theme_test' => '1', 'type' => 'view', 'id' => 1, 'keep_theme' => $theme), 'site')) . '">News screen</a> / <a href="' . static_evaluate_tempcode(build_url(array('page' => '', 'keep_theme_test' => '1', 'keep_theme' => $theme), 'forum')) . '">forumview</a>) </span>';
/** * The actualiser to edit a zone. * * @return tempcode The UI */ function __edit_zone() { $zone = post_param('zone'); $delete = post_param_integer('delete', 0); if ($delete == 1) { $title = get_page_title('DELETE_ZONE'); actual_delete_zone($zone); // Show it worked / Refresh $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF'); return redirect_screen($title, $_url, do_lang_tempcode('SUCCESS')); } else { $_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); $new_zone = post_param('new_zone'); actual_edit_zone($zone, $_title, $default_page, $header_text, $theme, $wide, $require_session, $displayed_in_menu, $new_zone); if ($new_zone != '') { $this->set_permissions($new_zone); } $title = get_page_title('EDIT_ZONE'); // Get title late, as we might be changing the theme this title is got from // Handle logos if (addon_installed('zone_logos')) { require_code('themes2'); require_code('uploads'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $iurl = ''; if (is_swf_upload() || array_key_exists('logo_upload_' . $theme, $_FILES) && is_uploaded_file($_FILES['logo_upload_' . $theme]['tmp_name'])) { $urls = get_url('', 'logo_upload_' . $theme, 'themes/' . $theme . '/images_custom', 0, OCP_UPLOAD_IMAGE); $iurl = $urls[0]; } if ($iurl == '') { $theme_img_code = post_param('logo_select_' . $theme, ''); if ($theme_img_code == '') { continue; // Probably a theme was added half-way //warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } $iurl = find_theme_image($theme_img_code, false, true, $theme); } $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'lang' => get_site_default_lang()), '', 1); $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'path' => $iurl, 'lang' => get_site_default_lang())); persistant_cache_delete('THEME_IMAGES'); } } // Show it worked / Refresh $url = get_param('redirect', NULL); if (is_null($url)) { $_url = build_url(array('page' => '_SELF', 'type' => 'edit'), '_SELF'); $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); } }
/** * Delete uploaded theme image if not tied into anything. * * @param URLPATH The URL to the theme image being deleted */ function cleanup_theme_images($old_url) { $files_referenced = collapse_1d_complexity('path', $GLOBALS['SITE_DB']->query_select('theme_images', array('DISTINCT path'))); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $files_existing = get_image_paths(get_custom_base_url() . '/themes/' . rawurlencode($theme) . '/images_custom/', get_custom_file_base() . '/themes/' . $theme . '/images_custom/'); foreach (array_keys($files_existing) as $path) { $path = str_replace(get_custom_file_base() . '/', '', filter_naughty($path)); $encoded_path = substr($path, 0, strrpos($path, '/') + 1) . rawurlencode(substr($path, strrpos($path, '/') + 1)); if (!in_array($path, $files_referenced) && !in_array($encoded_path, $files_referenced) && ($old_url == $path || $old_url == $encoded_path)) { @unlink(get_custom_file_base() . '/' . $path); sync_file($path); } } } }
/** * UI for a theme wizard step (choose colour). * * @return tempcode The UI */ function step1() { $title = get_page_title('_THEMEWIZARD', true, array(integer_format(1), integer_format(4))); $post_url = build_url(array('page' => '_SELF', 'type' => 'step2'), '_SELF', array('keep_theme_seed', 'keep_theme_dark', 'keep_theme_source', 'keep_theme_algorithm'), false, true); $text = do_lang_tempcode('THEMEWIZARD_1_DESCRIBE'); $submit_name = do_lang_tempcode('PROCEED'); require_code('form_templates'); $source_theme = get_param('source_theme', 'default'); $hidden = new ocp_tempcode(); if (count(find_all_themes()) == 1) { $hidden->attach(form_input_hidden('source_theme', $source_theme)); } else { $themes = nice_get_themes($source_theme, true); } $fields = new ocp_tempcode(); $fields->attach(form_input_codename(do_lang_tempcode('NEW_THEME'), do_lang_tempcode('DESCRIPTION_NAME'), 'themename', get_param('themename', ''), true)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('PARAMETERS')))); $fields->attach(form_input_colour(do_lang_tempcode('SEED_COLOUR'), do_lang_tempcode('DESCRIPTION_SEED_COLOUR'), 'seed', '#' . get_param('seed', find_theme_seed('default')), true)); if (count(find_all_themes()) != 1) { $fields->attach(form_input_list(do_lang_tempcode('SOURCE_THEME'), do_lang_tempcode('DESCRIPTION_SOURCE_THEME'), 'source_theme', $themes, NULL, true)); } $radios = new ocp_tempcode(); $radios->attach(form_input_radio_entry('algorithm', 'equations', $source_theme == 'default', do_lang_tempcode('THEMEGEN_ALGORITHM_EQUATIONS'))); $radios->attach(form_input_radio_entry('algorithm', 'hsv', $source_theme != 'default', do_lang_tempcode('THEMEGEN_ALGORITHM_HSV'))); $fields->attach(form_input_radio(do_lang_tempcode('THEMEGEN_ALGORITHM'), do_lang_tempcode('DESCRIPTION_THEMEGEN_ALGORITHM'), 'algorithm', $radios, true)); $fields->attach(form_input_tick(do_lang_tempcode('DARK_THEME'), do_lang_tempcode('DESCRIPTION_DARK_THEME'), 'dark', get_param_integer('dark', 0) == 1)); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED')))); $fields->attach(form_input_tick(do_lang_tempcode('INHERIT_CSS'), do_lang_tempcode('DESCRIPTION_INHERIT_CSS'), 'inherit_css', get_param_integer('inherit_css', 0) == 1)); breadcrumb_set_self(do_lang_tempcode('THEMEWIZARD')); require_javascript('javascript_ajax'); $script = find_script('snippet'); $javascript = "\n\t\t\tvar form=document.getElementById('main_form');\n\t\t\tform.elements['source_theme'].onchange=function() {\n\t\t\t\tvar default_theme=(form.elements['source_theme'].options[form.elements['source_theme'].selectedIndex].value=='default');\n\t\t\t\tform.elements['algorithm'][0].checked=default_theme;\n\t\t\t\tform.elements['algorithm'][1].checked=!default_theme;\n\t\t\t}\n\t\t\tform.old_submit=form.onsubmit;\n\t\t\tform.onsubmit=function()\n\t\t\t\t{\n\t\t\t\t\tdocument.getElementById('submit_button').disabled=true;\n\t\t\t\t\tvar url='" . addslashes($script) . "?snippet=exists_theme&name='+window.encodeURIComponent(form.elements['themename'].value);\n\t\t\t\t\tif (!do_ajax_field_test(url))\n\t\t\t\t\t{\n\t\t\t\t\t\tdocument.getElementById('submit_button').disabled=false;\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t\tdocument.getElementById('submit_button').disabled=false;\n\t\t\t\t\tif (typeof form.old_submit!='undefined' && form.old_submit) return form.old_submit();\n\t\t\t\t\treturn true;\n\t\t\t\t};\n\t\t"; return do_template('FORM_SCREEN', array('_GUID' => '98963f4d7ff60744382f937e6cc5acbf', 'GET' => true, 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'JAVASCRIPT' => $javascript, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'HIDDEN' => $hidden)); }
/** * The actualiser to add a theme image. * * @return tempcode The UI */ function _add_image() { require_code('uploads'); $title = get_page_title('ADD_THEME_IMAGE'); $theme = post_param('theme'); //if ((get_file_base()!=get_custom_file_base()) && ($theme=='default')) warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); $lang = post_param('lang'); $id = post_param('id'); $use_all_themes = post_param_integer('use_all_themes', 0); $use_all_langs = post_param_integer('use_all_langs', 0); $path = get_url('path', 'file', 'themes/' . ($use_all_themes == 1 ? 'default' : $theme) . '/images_custom'); if ($path[0] == '') { return warn_screen($title, do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } $theme_list = array_keys(find_all_themes()); $lang_list = find_all_langs(true); if ($use_all_themes == 1 && $use_all_langs == 1) { foreach ($theme_list as $theme) { foreach (array_keys($lang_list) as $lang) { actual_add_theme_image($theme, $lang, $id, $path[0], true); } } } elseif ($use_all_themes == 1) { foreach ($theme_list as $theme) { actual_add_theme_image($theme, $lang, $id, $path[0], true); } } elseif ($use_all_langs == 1) { foreach (array_keys($lang_list) as $lang) { actual_add_theme_image($theme, $lang, $id, $path[0], true); } } else { actual_add_theme_image($theme, $lang, $id, $path[0]); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_THEMES')), array('_SELF:_SELF:add_image:theme=' . post_param('theme'), do_lang_tempcode('CHOOSE')))); breadcrumb_set_self(do_lang_tempcode('DONE')); persistant_cache_delete('THEME_IMAGES'); erase_cached_templates(); return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), $theme, $lang, 'image', $id); }
/** * Automatically go through full upgrade for current site. */ function automate_upgrade() { // Database clear_caches_1(); clear_caches_2(); version_specific(); upgrade_modules(); // OCF ocf_upgrade(); // Themes require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $from = round(ocp_version_number()) - 1; $to = ocp_version_number(); upgrade_theme($theme, $from, $to, false); } }
/** * Standard modular run function for CRON hooks. Searches for tasks to perform. */ function run() { if (get_param('keep_lang', NULL) === NULL || get_param('keep_theme', NULL) === NULL) { // We need to run this for each language and for each theme $langs = find_all_langs(); require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($langs) as $lang) { foreach (array_keys($themes) as $theme) { if ($theme == 'default' || has_category_access(get_member(), 'theme', $theme)) { $where = array('c_theme' => $theme, 'c_lang' => $lang); $count = $GLOBALS['SITE_DB']->query_value('cron_caching_requests', 'COUNT(*)', $where); if ($count > 0) { $url = get_base_url() . '/data/cron_bridge.php?limit_hook=block_caching&keep_lang=' . urlencode($lang) . '&keep_theme=' . urlencode($theme); http_download_file($url, NULL, false); } } } } // Force re-loading of values that we use to mark progress (as above calls probably resulted in changes happening) global $VALUES; $VALUES = $GLOBALS['SITE_DB']->query_select('values', array('*')); $VALUES = list_to_map('the_name', $VALUES); return; } $where = array('c_theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'c_lang' => user_lang()); $requests = $GLOBALS['SITE_DB']->query_select('cron_caching_requests', array('id', 'c_codename', 'c_map', 'c_timezone', 'c_is_bot', 'c_in_panel', 'c_interlock', 'c_store_as_tempcode'), $where); foreach ($requests as $request) { $GLOBALS['NO_QUERY_LIMIT'] = true; $codename = $request['c_codename']; $map = unserialize($request['c_map']); $object = do_block_hunt_file($codename, $map); if (is_object($object)) { global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $LANGS_REQUESTED, $DO_NOT_CACHE_THIS, $TIMEZONE_MEMBER_CACHE; $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; get_users_timezone(); $backup_timezone = $TIMEZONE_MEMBER_CACHE[get_member()]; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); $cache = $object->run($map); $TIMEZONE_MEMBER_CACHE[get_member()] = $backup_timezone; $cache->handle_symbol_preprocessing(); if (!$DO_NOT_CACHE_THIS) { if (method_exists($object, 'cacheing_environment')) { $info = $object->cacheing_environment(); } else { $info = array(); $info['cache_on'] = 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))'; $info['ttl'] = 60 * 24; } $ttl = $info['ttl']; $_cache_identifier = array(); $cache_on = $info['cache_on']; if (is_array($cache_on)) { $_cache_identifier = call_user_func($cache_on[0], $map); } else { if ($cache_on != '' && !defined('HIPHOP_PHP')) { $_cache_on = eval('return ' . $cache_on . ';'); // NB: This uses $map, as $map is referenced inside $cache_on if (is_null($_cache_on)) { return NULL; } foreach ($_cache_on as $on) { $_cache_identifier[] = $on; } } elseif (defined('HIPHOP_PHP')) { return NULL; } } $_cache_identifier[] = $request['c_timezone']; $_cache_identifier[] = $request['c_is_bot'] == 0; $_cache_identifier[] = strval($request['c_in_panel']); $_cache_identifier[] = strval($request['c_interlock']); $cache_identifier = serialize($_cache_identifier); require_code('caches2'); if ($request['c_store_as_tempcode'] == 1) { $cache = make_string_tempcode($cache->evaluate()); } put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; } $GLOBALS['SITE_DB']->query_delete('cron_caching_requests', $request); } }
/** * Rename a zone in the database. * * @param ID_TEXT The old name of the zone * @param ID_TEXT The new name of the zone * @param boolean Whether to assume the main zone row has already been renamed as part of a wider editing operation */ function actual_rename_zone_lite($zone, $new_zone, $dont_bother_with_main_row = false) { if (!$dont_bother_with_main_row) { $GLOBALS['SITE_DB']->query_update('zones', array('zone_name' => $new_zone), array('zone_name' => $zone), '', 1); $GLOBALS['SITE_DB']->query_update('group_zone_access', array('zone_name' => $new_zone), array('zone_name' => $zone)); $GLOBALS['SITE_DB']->query_update('member_zone_access', array('zone_name' => $new_zone), array('zone_name' => $zone)); } else { $GLOBALS['SITE_DB']->query_delete('zones', array('zone_name' => $zone), '', 1); $GLOBALS['SITE_DB']->query_delete('group_zone_access', array('zone_name' => $zone)); $GLOBALS['SITE_DB']->query_delete('member_zone_access', array('zone_name' => $zone)); } $GLOBALS['SITE_DB']->query_update('group_page_access', array('zone_name' => $new_zone), array('zone_name' => $zone)); $GLOBALS['SITE_DB']->query_update('member_page_access', array('zone_name' => $new_zone), array('zone_name' => $zone)); $GLOBALS['SITE_DB']->query_update('comcode_pages', array('the_zone' => $new_zone), array('the_zone' => $zone), '', NULL, NULL, false, true); // May fail because the table might not exist when this is called if (addon_installed('redirects_editor')) { $GLOBALS['SITE_DB']->query_update('redirects', array('r_from_zone' => $new_zone), array('r_from_zone' => $zone)); $GLOBALS['SITE_DB']->query_update('redirects', array('r_to_zone' => $new_zone), array('r_to_zone' => $zone)); } // Copy logo theme images if needed require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($themes) as $theme) { $zone_logo_img = find_theme_image('logo/' . $zone . '-logo', true, true, $theme); $zone_logo_img_new = find_theme_image('logo/' . $new_zone . '-logo', true, true, $theme); if ($zone_logo_img != '' && $zone_logo_img_new == '') { $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'lang' => get_site_default_lang()), '', 1); $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => 'logo/' . $new_zone . '-logo', 'theme' => $theme, 'path' => $zone_logo_img, 'lang' => get_site_default_lang())); } } global $ALL_ZONES, $ALL_ZONES_TITLED; $ALL_ZONES = NULL; $ALL_ZONES_TITLED = NULL; }
/** * The UI to export an addon (1). * * @return tempcode The UI */ function addon_export() { $title = get_page_title('EXPORT_ADDON'); // Lang packs $url = build_url(array('page' => '_SELF', 'type' => '_addon_export', 'exp' => 'lang'), '_SELF'); $all_langs = find_all_langs(); ksort($all_langs); $i = 0; $tpl_languages = new ocp_tempcode(); $_lang_file_map = get_custom_file_base() . '/lang_custom/langs.ini'; if (!file_exists($_lang_file_map)) { $_lang_file_map = get_file_base() . '/lang/langs.ini'; } $lang_file_map = better_parse_ini_file($_lang_file_map); foreach ($all_langs as $lang => $dir) { if ($dir == 'lang_custom') { $files = $this->do_dir($dir . '/' . $lang); $frm_langs = new ocp_tempcode(); $frm_langs->attach(form_input_hidden('lang', $lang)); foreach (array_keys($files) as $file) { $frm_langs->attach(form_input_hidden('file_' . strval($i), $file)); $i++; } $nice_name = array_key_exists($lang, $lang_file_map) ? $lang_file_map[$lang] : $lang; $tpl_languages->attach(do_template('ADDON_EXPORT_LINE', array('_GUID' => '4e2f56799bdb3c4930396315236e2383', 'NAME' => $nice_name, 'URL' => $url, 'FILES' => $frm_langs))); } } // Theme packs $url = build_url(array('page' => '_SELF', 'type' => '_addon_export', 'exp' => 'theme'), '_SELF'); require_code('themes2'); $all_themes = find_all_themes(); ksort($all_themes); $i = 0; $tpl_themes = new ocp_tempcode(); foreach ($all_themes as $theme => $theme_title) { if ($theme != 'default') { $files = $this->do_dir('themes/' . $theme); $frm_themes = new ocp_tempcode(); foreach (array_keys($files) as $file) { $frm_themes->attach(form_input_hidden('file_' . strval($i), $file)); $i++; } $tpl_themes->attach(do_template('ADDON_EXPORT_LINE', array('_GUID' => '9c1dab6d6e6c13b5e01c86c83c3acde1', 'NAME' => $theme_title, 'URL' => $url, 'FILES' => $frm_themes))); } } // Files for choice export $url = build_url(array('page' => '_SELF', 'type' => '_addon_export', 'exp' => 'custom'), '_SELF'); $files = $this->do_dir(''); ksort($files); $frm_files = new ocp_tempcode(); $i = 0; foreach (array_keys($files) as $file) { $frm_files->attach(do_template('ADDON_EXPORT_FILE_CHOICE', array('_GUID' => '77a91b947259c5e0cc7b5240b24425ca', 'ID' => strval($i), 'PATH' => $file))); $i++; } $tpl_files = do_template('ADDON_EXPORT_LINE_CHOICE', array('_GUID' => '525b161afe5d84268360e960da5e759f', 'URL' => $url, 'FILES' => $frm_files)); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('ADDONS')))); return do_template('ADDON_EXPORT_SCREEN', array('_GUID' => 'd89367c0bbc3d6b8bd19f736d9474dfa', 'TITLE' => $title, 'LANGUAGES' => $tpl_languages, 'FILES' => $tpl_files, 'THEMES' => $tpl_themes)); }
/** * Erase all template caches (caches in all themes). * * @param boolean Whether to preserve CSS and JS files that might be linked to between requests */ function erase_cached_templates($preserve_some = false) { global $ERASED_TEMPLATES_ONCE; $ERASED_TEMPLATES_ONCE = true; require_code('themes2'); $themes = find_all_themes(); $langs = find_all_langs(true); foreach (array_keys($themes) as $theme) { foreach (array_keys($langs) as $lang) { $path = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang . '/'; $_dir = @opendir($path); if ($_dir === false) { @mkdir($path, 0777); // OR warn_exit(do_lang_tempcode('WRITE_ERROR_DIRECTORY_REPAIR',escape_html($path))); fix_permissions($path, 0777); } else { while (false !== ($file = readdir($_dir))) { if (substr($file, -4) == '.tcd' || substr($file, -4) == '.tcp' || !$preserve_some && (substr($file, -3) == '.js' || substr($file, -4) == '.css')) { $i = 0; while (@unlink($path . $file) === false && $i < 5) { if (!file_exists($path . $file)) { break; } // Race condition, gone already sleep(1); // May be race condition, lock $i++; } if ($i >= 5) { if (file_exists($path . $file)) { @unlink($path . $file) or intelligent_write_error($path . $file); } } } } closedir($_dir); } } } // Often the back button will be used to return to a form, so we need to ensure we have not broken the Javascript if (function_exists('get_member')) { javascript_enforce('javascript_validation'); javascript_enforce('javascript_editing'); } }