/** * Get an array of all the INI description entries in the specified language. * * @param LANGUAGE_NAME The language * @param ?ID_TEXT The language file (NULL: all non-custom language files) * @return array The language descriptions */ function get_lang_file_descriptions($lang, $file = NULL) { if (is_null($file)) { $dh = opendir(get_file_base() . '/lang/' . $lang); $descriptions = array(); while (($f = readdir($dh)) !== false) { if (substr($f, -4) == '.ini') { $descriptions = array_merge($descriptions, get_lang_file_descriptions($lang, basename($f, '.ini'))); } } return $descriptions; } $a = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini'; if (get_custom_file_base() != get_file_base() && !is_file($a)) { $a = get_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini'; } $b = is_file($a) ? $a : get_file_base() . '/lang/' . $lang . '/' . $file . '.ini'; if (!is_file($b)) { $b = get_file_base() . '/lang/' . fallback_lang() . '/' . $file . '.ini'; } $target = array(); require_code('lang_compile'); _get_lang_file_map($b, $target, true); return $target; }
/** * The actualiser to translate code (called externally, and may operate on many lang files). * * @return tempcode The UI */ function set_lang_code_2() { $lang = post_param('lang'); $lang_files = get_lang_files(fallback_lang()); foreach (array_keys($lang_files) as $lang_file) { $for_base_lang = get_lang_file_map(fallback_lang(), $lang_file, true); $for_base_lang_2 = get_lang_file_map($lang, $lang_file, false); $descriptions = get_lang_file_descriptions(fallback_lang(), $lang_file); $out = ''; foreach ($for_base_lang_2 + $for_base_lang as $key => $now_val) { $val = post_param('l_' . $key, array_key_exists($key, $for_base_lang_2) ? $for_base_lang_2[$key] : $now_val); if (str_replace(chr(10), '\\n', $val) != $now_val || !array_key_exists($key, $for_base_lang) || $for_base_lang[$key] != $val || !file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $lang_file . '.ini')) { // if it's changed from default ocPortal, or not in default ocPortal, or was already changed in language file, or whole file is not in default ocPortal $out .= $key . '=' . str_replace(chr(10), '\\n', $val) . "\n"; } } if ($out != '') { $path = get_custom_file_base() . '/lang_custom/' . filter_naughty($lang) . '/' . filter_naughty($lang_file) . '.ini'; $path_backup = $path . '.' . strval(time()); if (file_exists($path)) { @copy($path, $path_backup) or intelligent_write_error($path_backup); sync_file($path_backup); } $myfile = @fopen($path, 'wt'); if ($myfile === false) { intelligent_write_error($path); } fwrite($myfile, "[descriptions]\n"); foreach ($descriptions as $key => $description) { if (fwrite($myfile, $key . '=' . $description . "\n") == 0) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } } fwrite($myfile, "\n[strings]\n"); fwrite($myfile, $out); fclose($myfile); fix_permissions($path); sync_file($path); $path_backup2 = $path . '.latest_in_ocp_edit'; @copy($path, $path_backup2) or intelligent_write_error($path_backup2); sync_file($path_backup2); } } $title = get_page_title('TRANSLATE_CODE'); log_it('TRANSLATE_CODE'); require_code('view_modes'); erase_cached_language(); erase_cached_templates(); // Show it worked / Refresh $url = post_param('redirect', ''); if ($url == '') { return inform_screen($title, do_lang_tempcode('SUCCESS')); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Handle special page type output. * * @param ID_TEXT The special page type. * @set query templates tree lang * @param tempcode The normal script tempcode output * @param string The normal script evaluated output */ function special_page_types($special_page_type, &$out, $out_evaluated) { global $RECORDED_TEMPLATES_USED; if (function_exists('set_time_limit')) { @set_time_limit(280); } $echo = do_header(); //$echo->evaluate_echo(); $echo2 = new ocp_tempcode(); if (is_null($out_evaluated)) { ob_start(); $out->evaluate_echo(); // False evaluation ob_end_clean(); } // HACKHACK: Yuck. we have to after-the-fact make it wide, and empty lots of internal caching to reset the state. $_GET['wide_high'] = '1'; $_GET['wide'] = '1'; $GLOBALS['LOADED_PANELS'] = array(); $GLOBALS['IS_WIDE_HIGH'] = 1; $GLOBALS['IS_WIDE'] = 1; $GLOBALS['TEMPCODE_SETGET'] = array(); $GLOBALS['LOADED_TPL_CACHE'] = array(); $GLOBALS['HELPER_PANEL_PIC'] = NULL; $GLOBALS['HELPER_PANEL_TEXT'] = NULL; $GLOBALS['HELPER_PANEL_TUTORIAL'] = NULL; $GLOBALS['HELPER_PANEL_HTML'] = NULL; // CSS if (substr($special_page_type, -4) == '.css') { $url = build_url(array('page' => 'admin_themes', 'type' => 'edit_css', 'theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'file' => $special_page_type, 'keep_wide_high' => 1), get_module_zone('admin_themes')); header('Location: ' . $url->evaluate()); exit; } // Site Tree Editor if ($special_page_type == 'site_tree') { $url = build_url(array('page' => 'admin_sitetree', 'type' => 'site_tree', 'id' => get_zone_name() . ':' . get_page_name()), get_module_zone('admin_sitetree')); header('Location: ' . $url->evaluate()); exit; } // IDE linkage if ($special_page_type == 'ide_linkage') { $title = get_page_title('IDE_LINKAGE'); $file_links = new ocp_tempcode(); global $JAVASCRIPTS, $CSSS, $_REQUIRED_CODE, $LANGS_REQUESTED; /*foreach (array_keys($JAVASCRIPTS) as $name) Already in list of templates { $txtmte_url='txmt://open?url=file://'.$name; $file_links->attach(do_template('INDEX_SCREEN_ENTRY',array('URL'=>$txtmte_url,'NAME'=>$name))); }*/ foreach (array_keys($CSSS) as $name) { $search = find_template_place($name, get_site_default_lang(), $GLOBALS['FORUM_DRIVER']->get_theme(), '.css', 'css'); if (!is_null($search)) { list($theme, $type) = $search; $txtmte_url = 'txmt://open?url=file://' . get_file_base() . '/themes/' . $theme . '/' . $type . '/' . $name . '.css'; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(CSS)', 'URL' => $txtmte_url, 'NAME' => $name . '.css'))); } } foreach (array_keys($_REQUIRED_CODE) as $name) { $path_a = get_file_base() . '/' . (strpos($name, '.php') === false ? '/sources_custom/' . $name . '.php' : $name); $path_b = get_file_base() . '/' . (strpos($name, '.php') === false ? '/sources/' . $name . '.php' : str_replace('_custom', '', $name)); if (file_exists($path_a)) { $txtmte_url = 'txmt://open?url=file://' . $path_a; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(PHP)', 'URL' => $txtmte_url, 'NAME' => $name . (strpos($name, '.php') === false ? '.php' : '')))); } if (file_exists($path_b)) { $txtmte_url = 'txmt://open?url=file://' . $path_b; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(PHP)', 'URL' => $txtmte_url, 'NAME' => $name . (strpos($name, '.php') === false ? '.php' : '')))); } } foreach (array_keys($LANGS_REQUESTED) as $name) { if (file_exists(get_file_base() . '/lang_custom/' . fallback_lang() . '/' . $name . '.ini')) { $txtmte_url = 'txmt://open?url=file://' . get_file_base() . '/lang_custom/' . fallback_lang() . '/' . $name . '.ini'; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(Language)', 'URL' => $txtmte_url, 'NAME' => $name . '.ini'))); } if (file_exists(get_file_base() . '/lang/' . fallback_lang() . '/' . $name . '.ini')) { $txtmte_url = 'txmt://open?url=file://' . get_file_base() . '/lang/' . fallback_lang() . '/' . $name . '.ini'; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(Language)', 'URL' => $txtmte_url, 'NAME' => $name . '.ini'))); } } foreach (array_unique($RECORDED_TEMPLATES_USED) as $name) { $search = find_template_place($name, get_site_default_lang(), $GLOBALS['FORUM_DRIVER']->get_theme(), '.tpl', 'templates'); if (!is_null($search)) { list($theme, $type) = $search; $txtmte_url = 'txmt://open?url=file://' . get_file_base() . '/themes/' . $theme . '/' . $type . '/' . $name . '.tpl'; $file_links->attach(do_template('INDEX_SCREEN_ENTRY', array('DISPLAY_STRING' => '(Templates)', 'URL' => $txtmte_url, 'NAME' => $name . '.tpl'))); } } $echo2 = do_template('INDEX_SCREEN', array('TITLE' => $title, 'CONTENT' => $file_links, 'PRE' => do_lang_tempcode('TXMT_PROTOCOL_EXPLAIN'), 'POST' => '')); } // Theme images mode if ($special_page_type == 'theme_images') { $title = get_page_title('THEME_IMAGE_EDITING'); $theme_images = new ocp_tempcode(); global $RECORDED_IMG_CODES; foreach (array_keys($RECORDED_IMG_CODES) as $theme_image_details) { list($id, $theme, $lang) = unserialize($theme_image_details); $url = build_url(array('page' => 'admin_themes', 'type' => 'edit_image', 'theme' => is_null($theme) ? $GLOBALS['FORUM_DRIVER']->get_theme() : $theme, 'lang' => $lang, 'id' => $id), 'adminzone'); $image = find_theme_image($id, false, false, $theme, $lang); if ($image == '') { continue; } $theme_images->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('IMG' => $image, 'DESCRIPTION' => '', 'URL' => $url, 'NAME' => $id))); } $echo2 = do_template('INDEX_SCREEN_FANCIER_SCREEN', array('TITLE' => $title, 'CONTENT' => $theme_images, 'PRE' => do_lang_tempcode('CONTEXTUAL_EDITING_SCREEN'), 'POST' => '')); } // Profile mode? if ($special_page_type == 'profile') { if (function_exists('xdebug_dump_function_profile')) { $type = XDEBUG_PROFILER_FS_SUM; xdebug_dump_function_profile($type); } else { $echo2 = make_string_tempcode('Check out the dump using KCacheGrind.'); } } elseif (substr($special_page_type, 0, 12) == 'lang_content') { $map_a = get_file_base() . '/lang/langs.ini'; $map_b = get_custom_file_base() . '/lang_custom/langs.ini'; if (!file_exists($map_b)) { $map_b = $map_a; } $map = better_parse_ini_file($map_b); $lang_name = user_lang(); if (array_key_exists($lang_name, $map)) { $lang_name = $map[$lang_name]; } global $RECORDED_LANG_STRINGS_CONTENT; require_lang('lang'); require_code('form_templates'); $fields = new ocp_tempcode(); require_code('lang2'); $names = find_lang_content_names(array_keys($RECORDED_LANG_STRINGS_CONTENT)); foreach ($RECORDED_LANG_STRINGS_CONTENT as $key => $forum_db) { $value_found = get_translated_text($key, $forum_db ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']); if ($value_found != '') { $description = make_string_tempcode(escape_html($value_found)); if (get_value('google_translate_api_key') === NULL || user_lang() == get_site_default_lang()) { $actions = new ocp_tempcode(); } else { require_javascript('javascript_translate'); $actions = do_template('TRANSLATE_ACTION', array('LANG_FROM' => get_site_default_lang(), 'LANG_TO' => user_lang(), 'NAME' => 'trans_' . strval($key), 'OLD' => $value_found)); } $description->attach($actions); $fields->attach(form_input_text(is_null($names[$key]) ? '#' . strval($key) : $names[$key], $description, 'trans_' . strval($key), $value_found, false)); } } if ($fields->is_empty()) { inform_exit(do_lang_tempcode('NOTHING_TO_TRANSLATE')); } $title = get_page_title('__TRANSLATE_CONTENT', true, array($lang_name)); $post_url = build_url(array('page' => 'admin_lang', 'type' => '_content', 'contextual' => 1), 'adminzone'); $hidden = form_input_hidden('redirect', get_self_url(true, true)); $hidden = form_input_hidden('lang', user_lang()); $echo2 = do_template('FORM_SCREEN', array('_GUID' => '0d4dd16b023d0a7960f3eac85f54ddc4', 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => do_lang_tempcode('CONTEXTUAL_EDITING_SCREEN'), 'SUBMIT_NAME' => do_lang_tempcode('SAVE'))); } elseif (substr($special_page_type, 0, 4) == 'lang') { $map_a = get_file_base() . '/lang/langs.ini'; $map_b = get_custom_file_base() . '/lang_custom/langs.ini'; if (!file_exists($map_b)) { $map_b = $map_a; } $map = better_parse_ini_file($map_b); $lang_name = user_lang(); if (array_key_exists($lang_name, $map)) { $lang_name = $map[$lang_name]; } global $RECORDED_LANG_STRINGS; require_lang('lang'); require_code('form_templates'); require_code('lang2'); $fields = new ocp_tempcode(); $descriptions = get_lang_file_descriptions(fallback_lang()); foreach (array_keys($RECORDED_LANG_STRINGS) as $key) { $value_found = do_lang($key, NULL, NULL, NULL, NULL, false); $description = array_key_exists($key, $descriptions) ? make_string_tempcode($descriptions[$key]) : new ocp_tempcode(); if (!is_null($value_found)) { if (get_value('google_translate_api_key') === NULL || user_lang() == get_site_default_lang()) { $actions = new ocp_tempcode(); } else { require_javascript('javascript_translate'); $actions = do_template('TRANSLATE_ACTION', array('LANG_FROM' => get_site_default_lang(), 'LANG_TO' => user_lang(), 'NAME' => 'l_' . $key, 'OLD' => str_replace('\\n', chr(10), $value_found))); } $description->attach($actions); $fields->attach(form_input_text($key, $description, 'l_' . $key, str_replace('\\n', chr(10), $value_found), false)); } } $title = get_page_title('__TRANSLATE_CODE', true, array($lang_name)); $post_url = build_url(array('page' => 'admin_lang', 'type' => '_code2'), 'adminzone'); $hidden = form_input_hidden('redirect', get_self_url(true, true)); $hidden = form_input_hidden('lang', user_lang()); $echo2 = do_template('FORM_SCREEN', array('_GUID' => '0d4dd16b023d0a7960f3eac85f54ddc4', 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => $hidden, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => do_lang_tempcode('CONTEXTUAL_EDITING_SCREEN'), 'SUBMIT_NAME' => do_lang_tempcode('SAVE'))); } // Template mode? if ($special_page_type == 'templates' || $special_page_type == 'tree') { require_lang('themes'); global $RECORD_TEMPLATES_USED; $RECORD_TEMPLATES_USED = false; $templates = new ocp_tempcode(); if ($special_page_type == 'templates') { $title = get_page_title('TEMPLATES'); $_RECORDED_TEMPLATES_USED = array_count_values($RECORDED_TEMPLATES_USED); ksort($_RECORDED_TEMPLATES_USED); foreach ($_RECORDED_TEMPLATES_USED as $name => $count) { //$restore_from=find_template_path($name); $file = $name . '.tpl'; $edit_url = build_url(array('page' => 'admin_themes', 'type' => '_edit_templates', 'theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'f0file' => $file), 'adminzone', NULL, false, true); $templates->attach(do_template('TEMPLATE_LIST_ENTRY', array('COUNT' => integer_format($count), 'NAME' => $name, 'EDIT_URL' => $edit_url))); } } else { $title = get_page_title('TEMPLATE_TREE'); $hidden = new ocp_tempcode(); global $CSSS, $JAVASCRIPTS; foreach (array_keys($CSSS) as $c) { $hidden->attach(form_input_hidden('f' . strval(mt_rand(0, 100000)) . 'file', $c . '.css')); } foreach (array_keys($JAVASCRIPTS) as $c) { $hidden->attach(form_input_hidden('f' . strval(mt_rand(0, 100000)) . 'file', strtoupper($c) . '.tpl')); } $edit_url = build_url(array('page' => 'admin_themes', 'type' => '_edit_templates', 'preview_url' => get_self_url(true, false, array('special_page_type' => NULL)), 'theme' => $GLOBALS['FORUM_DRIVER']->get_theme()), 'adminzone', NULL, false, true); $tree = find_template_tree_nice($out->codename, $out->children, $out->fresh); $templates = do_template('TEMPLATE_TREE', array('_GUID' => 'ff2a2233b8b4045ba4d8777595ef64c7', 'HIDDEN' => $hidden, 'EDIT_URL' => $edit_url, 'TREE' => $tree)); } $echo2 = do_template('TEMPLATE_LIST_SCREEN', array('_GUID' => 'ab859f67dcb635fcb4d1747d3c6a2c17', 'TITLE' => $title, 'TEMPLATES' => $templates)); } // Query mode? if ($special_page_type == 'query') { require_lang("profiling"); global $QUERY_LIST; $queries = new ocp_tempcode(); $total_time = 0.0; global $M_SORT_KEY; $M_SORT_KEY = 'time'; usort($QUERY_LIST, 'multi_sort'); $QUERY_LIST = array_reverse($QUERY_LIST); foreach ($QUERY_LIST as $query) { $queries->attach(do_template('QUERY_LOG', array('_GUID' => 'ab88e1e92609136229ad920c30647647', 'TIME' => float_format($query['time'], 3), 'TEXT' => $query['text']))); $total_time += $query['time']; } $title = get_page_title("VIEW_PAGE_QUERIES"); $total = count($QUERY_LIST); $echo2 = do_template('QUERY_SCREEN', array('_GUID' => '5f679c8f657b4e4ae94ae2d0ed4843fa', 'TITLE' => $title, 'TOTAL' => integer_format($total), 'TOTAL_TIME' => float_format($total_time, 3), 'QUERIES' => $queries)); } $echo->attach(globalise($echo2)); $echo->attach(do_footer()); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); exit; }