/** * Regenerate all the theme image paths in the database. * * @param ID_TEXT The theme we're searching in. * @param ?array A map of languages (lang=>1) (NULL: find it in-function). * @param ?ID_TEXT The theme we're storing in (NULL: same as $theme). */ function regen_theme_images($theme, $langs = NULL, $target_theme = NULL) { if (is_null($langs)) { $langs = find_all_langs(true); } if (is_null($target_theme)) { $target_theme = $theme; } $images = array_merge(find_images_do_dir($theme, 'images/', $langs), find_images_do_dir($theme, 'images_custom/', $langs)); foreach (array_keys($langs) as $lang) { $existing = $GLOBALS['SITE_DB']->query_select('theme_images', array('id', 'path'), array('lang' => $lang, 'theme' => $target_theme)); foreach ($images as $id => $path) { $found = false; foreach ($existing as $e) { if ($e['path'] == $path || $e['id'] == $id) { $found = true; break; } } if (!$found) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $correct_path = find_theme_image($id, false, true, $theme, $lang); $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => $id, 'lang' => $lang, 'theme' => $target_theme, 'path' => $correct_path), false, true); // race conditions $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; } } } persistant_cache_delete('THEME_IMAGES'); }
/** * Choose a flagrant text message. * * @param AUTO_LINK The ID of the flagrant text message to choose */ function choose_flagrant($id) { $message = $GLOBALS['SITE_DB']->query_value('text', 'the_message', array('id' => $id)); $message = get_translated_text($message); log_it('CHOOSE_FLAGRANT', strval($id), $message); $GLOBALS['SITE_DB']->query_update('text', array('active_now' => 0)); $GLOBALS['SITE_DB']->query_update('text', array('activation_time' => time(), 'active_now' => 1), array('id' => $id), '', 1); persistant_cache_delete('FLAGRANT'); }
/** * Standard modular run function. * * @return tempcode Results */ function run() { if (!is_null($GLOBALS['CURRENT_SHARE_USER'])) { return new ocp_tempcode(); } $hooks = find_all_hooks('systems', 'disposable_values'); foreach (array_keys($hooks) as $hook) { $GLOBALS['SITE_DB']->query_delete('values', array('the_name' => $hook), '', 1); } persistant_cache_delete('VALUES'); return new ocp_tempcode(); }
/** * Standard modular run function. * * @return tempcode Results */ function run() { $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'theme_images WHERE path LIKE \'themes/%/images/%\''); persistant_cache_delete('THEME_IMAGES'); $paths = $GLOBALS['SITE_DB']->query_select('theme_images', array('path', 'id')); foreach ($paths as $path) { if ($path['path'] == '') { $GLOBALS['SITE_DB']->query_delete('theme_images', $path, '', 1); } elseif (preg_match('#^themes/[^/]+/images_custom/+' . str_replace('#', '\\#', preg_quote($path['id'])) . '\\.#', $path['path']) != 0) { if (!file_exists(get_custom_file_base() . '/' . $path['path']) && !file_exists(get_file_base() . '/' . $path['path'])) { $GLOBALS['SITE_DB']->query_delete('theme_images', $path, '', 1); } } } return new ocp_tempcode(); }
/** * Explictly sets the meta information for the specified resource. * * @param ID_TEXT The type of resource (e.g. download) * @param ID_TEXT The ID of the resource * @param SHORT_TEXT The keywords to use * @param SHORT_TEXT The description to use */ function seo_meta_set_for_explicit($type, $id, $keywords, $description) { if ($description == STRING_MAGIC_NULL) { return; } if ($keywords == STRING_MAGIC_NULL) { return; } $description = str_replace(chr(10), ' ', $description); $rows = $GLOBALS['SITE_DB']->query_select('seo_meta', array('meta_keywords', 'meta_description'), array('meta_for_type' => $type, 'meta_for_id' => $id), '', 1); if (array_key_exists(0, $rows)) { lang_remap($rows[0]['meta_keywords'], $keywords); lang_remap($rows[0]['meta_description'], $description); } else { $GLOBALS['SITE_DB']->query_insert('seo_meta', array('meta_for_type' => $type, 'meta_for_id' => $id, 'meta_keywords' => insert_lang($keywords, 2), 'meta_description' => insert_lang($description, 2))); } if (function_exists('decache')) { decache('side_tag_cloud'); } if (function_exists('persistant_cache_delete')) { persistant_cache_delete(array('seo', $type, $id)); } }
/** * 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); }
/** * Relay an error message, if appropriate, to e-mail listeners (sometimes ocProducts, and site staff). * * @param string A error message (in HTML) * @param boolean Also send to ocProducts * @param ID_TEXT The notification type */ function relay_error_notification($text, $ocproducts = true, $notification_type = 'error_occurred') { // Make sure we don't send too many error emails if (function_exists('get_value') && $GLOBALS['BOOTSTRAPPING'] == 0 && array_key_exists('SITE_DB', $GLOBALS) && !is_null($GLOBALS['SITE_DB'])) { $num = intval(get_value('num_error_mails_' . date('Y-m-d'))) + 1; if ($num == 51) { return; } // We've sent too many error mails today $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'values WHERE the_name LIKE \'' . db_encode_like('num\\_error\\_mails\\_%') . '\''); persistant_cache_delete('VALUES'); set_value('num_error_mails_' . date('Y-m-d'), strval($num)); } if (!function_exists('require_lang')) { return; } require_code('urls'); require_code('tempcode'); $error_url = running_script('index') ? static_evaluate_tempcode(build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true)) : get_self_url_easy(); require_code('notifications'); require_code('comcode'); $mail = do_lang('ERROR_MAIL', comcode_escape($error_url), str_replace(array('[html', '[/html'), array('[html', '[/html'), $text), NULL, get_site_default_lang()); dispatch_notification($notification_type, NULL, do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()), $mail, NULL, A_FROM_SYSTEM_PRIVILEGED); if ($ocproducts && get_option('send_error_emails_ocproducts', true) == '1' && !running_script('cron_bridge') && strpos($text, '_custom/') === false && strpos($text, 'data/occle.php') === false && strpos($text, '/mini') === false && strpos($text, 'A transaction for the wrong IPN e-mail went through') === false && strpos($text, 'has been disabled for security reasons') === false && strpos($text, 'max_questions') === false && strpos($text, 'Error at offset') === false && strpos($text, 'Unable to allocate memory for pool') === false && strpos($text, 'Out of memory') === false && strpos($text, 'Disk is full writing') === false && strpos($text, 'Disk quota exceeded') === false && strpos($text, 'from storage engine') === false && strpos($text, 'Lost connection to MySQL server') === false && strpos($text, 'Unable to save result set') === false && strpos($text, '.MYI') === false && strpos($text, 'MySQL server has gone away') === false && strpos($text, 'Incorrect key file') === false && strpos($text, 'Too many connections') === false && strpos($text, 'marked as crashed and should be repaired') === false && strpos($text, 'connect to') === false && strpos($text, 'Access denied for') === false && strpos($text, 'Unknown database') === false && strpos($text, 'headers already sent') === false && preg_match('#Maximum execution time of \\d+ seconds#', $text) == 0 && preg_match('#Out of memory \\(allocated (1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24)\\d{6}\\)#', $text) == 0 && strpos($text, 'is marked as crashed and last') === false && strpos($text, 'failed to open stream: Permission denied') === false && strpos($text, 'phpinfo() has been disabled') === false && (strpos($text, 'Maximum execution time') === false || strpos($text, '/js_') === false && strpos($text, '/caches_filesystem.php') === false && strpos($text, '/files2.php') === false) && (strpos($text, 'doesn\'t exist') === false || strpos($text, 'import') === false) && (strpos($text, 'No such file or directory') === false || strpos($text, 'admin_setupwizard') === false) && strpos($text, 'File(/tmp/) is not within the allowed path') === false) { require_code('mail'); mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array('errors_final' . strval(ocp_version()) . '@ocportal.com'), '', '', '', 3, NULL, true, NULL, true); } if ($ocproducts && !is_null(get_value('agency_email_address'))) { require_code('mail'); $agency_email_address = get_value('agency_email_address'); mail_wrap(do_lang('ERROR_OCCURRED_SUBJECT', get_page_name(), NULL, NULL, get_site_default_lang()) . ' ' . ocp_version_full(), $mail, array($agency_email_address), '', '', '', 3, NULL, true, NULL, true); } }
/** * The actualiser to edit a menu. * * @return tempcode The UI */ function _edit_menu() { $title = get_page_title('_EDIT_MENU', true, array(escape_html(get_param('id')))); post_param_integer('confirm'); // Just to make sure hackers don't try and get people to erase this form via a URL $menu_id = get_param('id'); // Find what we have on the menu first $ids = array(); foreach ($_POST as $key => $val) { if (is_string($val)) { if (substr($key, 0, 7) == 'parent_') { $ids[intval(substr($key, 7))] = $val; } } } /*// Order $orderings=array(); $ids_copy=$ids; while (count($ids_copy)!=0) { $best_value=0; // to initialise to integer type $best_value=NULL; $best_id=NULL; foreach ($ids_copy as $id=>$parent) { $value=post_param_integer('order_'.strval($id)); if ((is_null($best_id)) || ($value<$best_value)) { $best_id=$id; $best_value=$value; } } $orderings[]=$best_id; unset($ids_copy[$best_id]); }*/ $orderings = array_keys($ids); // Get language codes currently used $old_menu_bits = list_to_map('id', $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'i_caption', 'i_caption_long'), array('i_menu' => $menu_id))); // Now, process everything on the root $order = 0; foreach ($orderings as $id) { $parent = $ids[$id]; if ($parent == '') { $this->add_menu_item($menu_id, $id, $ids, NULL, $old_menu_bits, $order); $order++; } } // Erase old stuff foreach ($old_menu_bits as $menu_item_id => $lang_code) { $GLOBALS['SITE_DB']->query_delete('menu_items', array('id' => $menu_item_id)); delete_lang($lang_code['i_caption']); delete_lang($lang_code['i_caption_long']); } decache('side_stored_menu'); persistant_cache_delete(array('MENU', $menu_id)); log_it(count($_POST) == 1 ? 'DELETE_MENU' : 'EDIT_MENU', $menu_id); // Go back to editing the menu $url = get_param('redirect', '!'); if ($url == '!') { if (count($_POST) == 1) { $_url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); } else { $_url = build_url(array('page' => '_SELF', 'type' => 'edit', 'wide' => 1, 'id' => $menu_id), '_SELF'); } $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Delete the specified field from the specified table. * * @param object Link to the real database object * @param ID_TEXT The table name * @param ID_TEXT The field name */ function _helper_delete_table_field($this_ref, $table_name, $name) { $query = 'ALTER TABLE ' . $this_ref->table_prefix . $table_name . ' DROP COLUMN ' . $name; $this_ref->_query($query); $this_ref->query_delete('db_meta', array('m_table' => $table_name, 'm_name' => $name)); $this_ref->query_delete('db_meta_indices', array('i_table' => $table_name, 'i_fields' => $name)); if (isset($GLOBALS['XML_CHAIN_DB'])) { // DB chaining: It's a write query, so needs doing on chained DB too $GLOBALS['XML_CHAIN_DB']->_query($query); } if (function_exists('persistant_cache_set')) { persistant_cache_delete('TABLE_LANG_FIELDS'); } }
/** * Find the URL to the theme image of the specified ID. It searches various priorities, including language and theme overrides. * * @param ID_TEXT The theme image ID * @param boolean Whether to silently fail (i.e. not give out an error message when a theme image cannot be found) * @param boolean Whether to leave URLs as relative local URLs * @param ?ID_TEXT The theme to search in (NULL: users current theme) * @param ?LANGUAGE_NAME The language to search for (NULL: users current language) * @param ?object The database to use (NULL: site database) * @param boolean Whether to only search the default 'images' filesystem * @return URLPATH The URL found (blank: not found) */ function find_theme_image($id, $silent_fail = false, $leave_local = false, $theme = NULL, $lang = NULL, $db = NULL, $pure_only = false) { if (substr($id, 0, 4) == 'ocf_' && is_file(get_file_base() . '/themes/default/images/avatars/index.html')) { $id = substr($id, 4); } if (isset($_GET['keep_theme_seed']) && get_param('keep_theme_seed', NULL) !== NULL && function_exists('has_specific_permission') && has_specific_permission(get_member(), 'view_profiling_modes')) { require_code('themewizard'); $test = find_theme_image_themewizard_preview($id); if ($test !== NULL) { return $test; } } if ($db === NULL) { $db = $GLOBALS['SITE_DB']; } global $RECORD_IMG_CODES; if ($RECORD_IMG_CODES) { global $RECORDED_IMG_CODES; if (isset($GLOBALS['FORUM_DB']) && $db->connection_write !== $GLOBALS['FORUM_DB']->connection_write) { $RECORDED_IMG_CODES[serialize(array($id, $theme, $lang))] = 1; } } $true_theme = $GLOBALS['FORUM_DRIVER']->get_theme(); if ($theme === NULL) { $theme = $true_theme; } global $USER_LANG_CACHED; $true_lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED; if ($lang === NULL) { $lang = $true_lang; } $truism = $theme == $true_theme && $lang == $true_lang; $site = $GLOBALS['SITE_DB'] == $db ? 'site' : 'forums'; global $IMG_CODES; if (!isset($IMG_CODES[$site])) { static $cache = NULL; if ($site == 'site') { $cache = persistant_cache_get('THEME_IMAGES'); } if (!isset($cache[$true_theme][$true_lang])) { $IMG_CODES[$site] = $db->query_select('theme_images', array('id', 'path'), array('theme' => $true_theme, 'lang' => $true_lang)); $IMG_CODES[$site] = collapse_2d_complexity('id', 'path', $IMG_CODES[$site]); if ($site == 'site') { if ($cache === NULL) { $cache = array(); } $cache[$theme][$true_lang] = $IMG_CODES[$site]; persistant_cache_set('THEME_IMAGES', $cache); } } else { $IMG_CODES[$site] = $cache[$true_theme][$true_lang]; } } if (!$truism && !$pure_only) { $path = $db->query_value_null_ok('theme_images', 'path', array('theme' => $theme, 'lang' => $lang, 'id' => $id)); if ($path !== NULL) { if (url_is_local($path) && !$leave_local) { $path = ($db->connection_write != $GLOBALS['SITE_DB']->connection_write ? get_forum_base_url() : (substr($path, 0, 22) == 'themes/default/images/' ? get_base_url() : get_custom_base_url())) . '/' . $path; } return cdn_filter($path); } } if ($pure_only || !isset($IMG_CODES[$site][$id]) || !$truism) { $path = NULL; $priorities = array(); if (!$pure_only) { $priorities = array_merge($priorities, array(array($theme, $lang, 'images_custom'), array($theme, '', 'images_custom'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images_custom'))); } // This will not do a DB search, just a filesystem search. The Theme Wizard makes these though $priorities = array_merge($priorities, array(array($theme, $lang, 'images'), array($theme, '', 'images'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images'))); if ($theme != 'default') { if (!$pure_only) { $priorities = array_merge($priorities, array(array('default', $lang, 'images_custom'), array('default', '', 'images_custom'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images_custom'))); } $priorities = array_merge($priorities, array(array('default', $lang, 'images'), array('default', '', 'images'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images'))); } foreach ($priorities as $i => $priority) { if ($priority === NULL) { continue; } if ($priority[2] == 'images_custom' && $priority[1] != '') { $smap = array('id' => $id, 'theme' => $priority[0], 'lang' => $priority[1]); $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $truism_b = $priority[0] == $true_theme && (!multi_lang() || $priority[1] == '' || $priority[1] === $true_lang); $path = $truism_b ? NULL : $db->query_value_null_ok('theme_images', 'path', $smap); $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; if ($path !== NULL) { if (strpos($path, '/images/' . $id . '.') !== false) { continue; } if (array_key_exists('lang', $smap) && strpos($path, '/images/' . $smap['lang'] . '/' . $id . '.') !== false) { continue; } break; } } $test = _search_img_file($priority[0], $priority[1], $id, $priority[2]); if ($test !== NULL) { $path_bits = explode('/', $test); $path = ''; foreach ($path_bits as $bit) { if ($path != '') { $path .= '/'; } $path .= rawurlencode($bit); } break; } } if ($db->connection_write == $GLOBALS['SITE_DB']->connection_write) { if ($path !== NULL && $path != '' || $silent_fail && !$GLOBALS['SEMI_DEBUG_MODE']) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $db->query_delete('theme_images', array('id' => $id, 'theme' => $theme, 'lang' => $lang)); // Allow for race conditions $db->query_insert('theme_images', array('id' => $id, 'theme' => $theme, 'path' => $path === NULL ? '' : $path, 'lang' => $lang), false, true); // Allow for race conditions $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; persistant_cache_delete('THEME_IMAGES'); } } if ($path === NULL) { if (!$silent_fail) { require_code('site'); attach_message(do_lang_tempcode('NO_SUCH_IMAGE', escape_html($id)), 'warn'); } return ''; } if ($truism) { $IMG_CODES[$site][$id] = $path; } // only cache if we are looking up for our own theme/lang } else { $path = $IMG_CODES[$site][$id]; global $SITE_INFO; if ($path != '' && (!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && url_is_local($path) && !is_file(get_custom_file_base() . '/' . rawurldecode($path))) { unset($IMG_CODES[$site][$id]); return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, $pure_only); } } if (url_is_local($path) && !$leave_local && $path != '') { if ($db->connection_write != $GLOBALS['SITE_DB']->connection_write) { $base_url = get_forum_base_url(); } else { global $SITE_INFO; $missing = !$pure_only && ((!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && (!is_file(get_file_base() . '/' . rawurldecode($path)) && !is_file(get_custom_file_base() . '/' . rawurldecode($path)))); if (substr($path, 0, 22) == 'themes/default/images/' || $missing) { if ($missing) { return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, true); } $base_url = get_base_url(); } else { $base_url = get_custom_base_url(); } } $path = $base_url . '/' . $path; } return cdn_filter($path); }
} if (!is_file($FILE_BASE . '/sources/global.php')) { $a = strrpos($FILE_BASE, '/'); if ($a === false) { $a = 0; } $b = strrpos($FILE_BASE, '\\'); if ($b === false) { $b = 0; } $RELATIVE_PATH = substr($FILE_BASE, ($a > $b ? $a : $b) + 1); $FILE_BASE = substr($FILE_BASE, 0, $a > $b ? $a : $b); } else { $RELATIVE_PATH = ''; } @chdir($FILE_BASE); global $NON_PAGE_SCRIPT; $NON_PAGE_SCRIPT = 1; global $FORCE_INVISIBLE_GUEST; $FORCE_INVISIBLE_GUEST = 0; if (!is_file($FILE_BASE . '/sources/global.php')) { exit('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . chr(10) . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"><head><title>Critical startup error</title></head><body><h1>ocPortal startup error</h1><p>The second most basic ocPortal startup file, sources/global.php, could not be located. This is almost always due to an incomplete upload of the ocPortal system, so please check all files are uploaded correctly.</p><p>Once all ocPortal files are in place, ocPortal must actually be installed by running the installer. You must be seeing this message either because your system has become corrupt since installation, or because you have uploaded some but not all files from our manual installer package: the quick installer is easier, so you might consider using that instead.</p><p>ocProducts maintains full documentation for all procedures and tools, especially those for installation. These may be found on the <a href="http://ocportal.com">ocPortal website</a>. If you are unable to easily solve this problem, we may be contacted from our website and can help resolve it for you.</p><hr /><p style="font-size: 0.8em">ocPortal is a website engine created by ocProducts.</p></body></html>'); } require $FILE_BASE . '/sources/global.php'; require_code('database_action'); require_code('config2'); require_code('menus2'); $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'theme_images WHERE path LIKE \'themes/%/images/ocf_emoticons/%\''); $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'theme_images WHERE path LIKE \'themes/%/images//ocf_emoticons/%\''); persistant_cache_delete('THEME_IMAGES'); echo 'Installed';
/** * 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')); } }
/** * The actualiser to toggle an IP ban. * * @return tempcode The UI */ function toggle_ip_ban() { $ip = get_param('id'); $test = $GLOBALS['SITE_DB']->query_value_null_ok('usersubmitban_ip', 'ip', array('ip' => $ip)); if (is_null($test)) { $title = get_page_title('IP_BANNED'); if ($ip == get_ip_address()) { warn_exit(do_lang_tempcode('AVOIDING_BANNING_SELF')); } if (post_param_integer('confirm', 0) == 0) { $preview = do_lang_tempcode('BAN_IP_DESCRIPTION', escape_html($ip)); $url = get_self_url(false, false); return do_template('CONFIRM_SCREEN', array('TITLE' => $title, 'PREVIEW' => $preview, 'FIELDS' => form_input_hidden('confirm', '1'), 'URL' => $url)); } require_code('failure'); add_ip_ban($ip); log_it('IP_BANNED', $ip); } else { $title = get_page_title('IP_UNBANNED'); if (post_param_integer('confirm', 0) == 0) { $preview = do_lang_tempcode('UNBAN_IP_DESCRIPTION', escape_html($ip)); $url = get_self_url(false, false); return do_template('CONFIRM_SCREEN', array('TITLE' => $title, 'PREVIEW' => $preview, 'FIELDS' => form_input_hidden('confirm', '1'), 'URL' => $url)); } require_code('failure'); remove_ip_ban($ip); log_it('IP_UNBANNED', $ip); } persistant_cache_delete('IP_BANS'); // Show it worked / Refresh $_url = get_param('redirect', NULL); if (!is_null($_url)) { $url = make_string_tempcode($_url); } else { $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Add a zone. * * @param ID_TEXT Name of the zone * @param SHORT_TEXT The zone title * @param ID_TEXT The zones default page * @param SHORT_TEXT The header text * @param ID_TEXT The theme * @param BINARY Whether the zone is wide * @param BINARY Whether the zone requires a session for pages to be used * @param BINARY Whether the zone in displayed in the menu coded into some themes */ function actual_add_zone($zone, $title, $default_page = 'start', $header_text = '', $theme = 'default', $wide = 0, $require_session = 0, $displayed_in_menu = 1) { require_code('type_validation'); if (!is_alphanumeric($zone, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } if (get_file_base() != get_custom_file_base()) { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } // Check doesn't already exist $test = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $zone)); if (!is_null($test)) { if (file_exists(get_file_base() . '/' . $zone)) { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($zone))); } else { persistant_cache_delete(array('ZONE', $zone)); $GLOBALS['SITE_DB']->query_delete('zones', array('zone_name' => $zone), '', 1); } } if (!file_exists(get_file_base() . '/' . $zone)) { // Create structure afm_make_directory($zone . '/pages/minimodules_custom', true, true); afm_make_directory($zone . '/pages/minimodules', false, true); afm_make_directory($zone . '/pages/modules_custom', true, true); afm_make_directory($zone . '/pages/modules', false, true); $langs = array_keys(find_all_langs(true)); foreach ($langs as $lang) { afm_make_directory($zone . '/pages/comcode_custom/' . $lang, true, true); afm_make_directory($zone . '/pages/comcode/' . $lang, false, true); afm_make_directory($zone . '/pages/html_custom/' . $lang, true, true); afm_make_directory($zone . '/pages/html/' . $lang, false, true); } afm_make_file($zone . '/index.php', file_get_contents(get_file_base() . '/site/index.php'), false); if (file_exists(get_file_base() . '/pages/.htaccess')) { afm_make_file($zone . '/pages/.htaccess', file_get_contents(get_file_base() . '/pages/.htaccess'), false); } $index_php = array('pages/comcode', 'pages/comcode/EN', 'pages/comcode_custom', 'pages/comcode_custom/EN', 'pages/html', 'pages/html/EN', 'pages/html_custom', 'pages/html_custom/EN', 'pages/modules', 'pages/modules_custom', 'pages'); foreach ($index_php as $i) { afm_make_file($zone . '/' . $i . '/index.html', '', false); } $default_menu = <<<END [block="zone_{$zone}_menu" type="tree" caption="Menu"]side_stored_menu[/block] [block failsafe="1"]side_users_online[/block] [block failsafe="1"]side_stats[/block] [block]side_personal_stats[/block] END; afm_make_file($zone . '/pages/comcode_custom/EN/panel_left.txt', $default_menu, true); } afm_make_file($zone . '/pages/comcode_custom/EN/' . filter_naughty($default_page) . '.txt', '[title]' . do_lang('YOUR_NEW_ZONE') . '[/title]' . chr(10) . chr(10) . do_lang('YOUR_NEW_ZONE_PAGE', $zone . ':' . $default_page) . chr(10) . chr(10) . '[block]main_comcode_page_children[/block]', true); $GLOBALS['SITE_DB']->query_insert('zones', array('zone_name' => $zone, 'zone_title' => insert_lang($title, 1), 'zone_default_page' => $default_page, 'zone_header_text' => insert_lang($header_text, 1), 'zone_theme' => $theme, 'zone_wide' => $wide, 'zone_require_session' => $require_session, 'zone_displayed_in_menu' => $displayed_in_menu)); require_code('menus2'); $menu_item_count = $GLOBALS['SITE_DB']->query_value('menu_items', 'COUNT(*)', array('i_menu' => 'zone_menu')); if ($menu_item_count < 40) { add_menu_item_simple('zone_menu', NULL, $title, $zone . ':', 0, 1); } log_it('ADD_ZONE', $zone); persistant_cache_delete('ALL_ZONES'); decache('main_sitemap'); decache('side_stored_menu'); decache('side_zone_jump'); }
/** * Set a configuration option with the specified values. * * @param ID_TEXT The name of the value * @param LONG_TEXT The value * @param ?ID_TEXT The type of the option. This is normally ommited, but to save a DB lookup, may be passed through (NULL: work out the type) * @set float integer tick line text transline transtext list date forum category usergroup * @param ?LONG_TEXT The current value of the config option (NULL: unknown). This is just for efficiency for remapping language config options. */ function set_option($name, $value, $type = NULL, $current_value = NULL) { global $OPTIONS; if (is_null($type)) { global $GET_OPTION_LOOP; if ($GET_OPTION_LOOP != 1) { get_option($name); } // Ensure it's installed $type = $OPTIONS[$name]['the_type']; //$type=$GLOBALS['SITE_DB']->query_value('config','the_type',array('the_name'=>$name)); } if ($type == 'transline' || $type == 'transtext') { // $current_value=$GLOBALS['SITE_DB']->query_value('config','config_value',array('the_name'=>$name)); if (array_key_exists('c_set', $OPTIONS[$name]) && $OPTIONS[$name]['c_set'] == 0) { $GLOBALS['SITE_DB']->query_update('config', array('config_value' => strval(insert_lang($value, 1)), 'c_set' => 1), array('the_name' => $name), '', 1); } else { $current_value = $OPTIONS[$name]['config_value']; if (!is_null($current_value)) { // Should never happen, but might during upgrading lang_remap(intval($current_value), $value); } } } else { $map = array('config_value' => $value); if (array_key_exists('c_set', $OPTIONS[$name])) { $map['c_set'] = 1; } $GLOBALS['SITE_DB']->query_update('config', $map, array('the_name' => $name), '', 1); $OPTIONS[$name]['config_value'] = $value; } $OPTIONS[$name]['config_value_translated'] = $value; if (function_exists('log_it')) { require_lang('config'); log_it('CONFIGURATION', $name, $value); } if (function_exists('persistant_cache_delete')) { persistant_cache_delete('OPTIONS'); } }
/** * Get the processed tempcode for the specified block. Please note that you pass multiple parameters in as an array, but single parameters go in as a string or other flat variable. * * @param ID_TEXT The block name * @param ?array The block parameter map (NULL: no parameters) * @param ?integer The TTL to use in minutes (NULL: block default) * @return tempcode The generated tempcode */ function do_block($codename, $map = NULL, $ttl = NULL) { global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $DO_NOT_CACHE_THIS; if (is_null($map)) { $map = array(); } if (!array_key_exists('cache', $map)) { $map['cache'] = block_cache_default($codename); } $DO_NOT_CACHE_THIS = $map['cache'] == '0'; $object = NULL; if ((get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0) && strpos(get_param('special_page_type', ''), 't') === false) { // See if the block may be cached (else cannot, or is yet unknown) if ($map['cache'] == '0') { $row = NULL; } else { $row = find_cache_on($codename); if ($row === NULL) { $object = do_block_hunt_file($codename, $map); if (is_object($object) && method_exists($object, 'cacheing_environment')) { $info = $object->cacheing_environment($map); if ($info !== NULL) { $row = array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']); } } } if ($row === NULL && isset($map['quick_cache']) && $map['quick_cache'] == '1') { $row = array('cached_for' => $codename, 'cache_on' => 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))', 'cache_ttl' => 60); } } if ($row !== NULL) { $cache_identifier = do_block_get_cache_identifier($row['cache_on'], $map); // See if it actually is cached if ($cache_identifier !== NULL) { if ($ttl === NULL) { $ttl = $row['cache_ttl']; } $cache = get_cache_entry($codename, $cache_identifier, $ttl, true, array_key_exists('cache', $map) && $map['cache'] == '2', $map); if ($cache === NULL) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; if ($object !== NULL) { $object = do_block_hunt_file($codename, $map); } if (!is_object($object)) { // This probably happened as we uninstalled a block, and now we're getting a "missing block" message back. if (!defined('HIPHOP_PHP')) { // Removed outdated cache-on information $GLOBALS['SITE_DB']->query_delete('cache_on', array('cached_for' => $codename), '', 1); persistant_cache_delete('CACHE_ON'); } $out = new ocp_tempcode(); $out->attach($object); return $out; } $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); if (isset($map['quick_cache']) && $map['quick_cache'] == '1') { global $MEMORY_OVER_SPEED; $MEMORY_OVER_SPEED = true; // Let this eat up some CPU in order to let it save RAM, disable_php_memory_limit(); if (function_exists('set_time_limit')) { @set_time_limit(200); } } $cache = $object->run($map); $cache->handle_symbol_preprocessing(); if (!$DO_NOT_CACHE_THIS) { require_code('caches2'); if (isset($map['quick_cache']) && $map['quick_cache'] == '1' && has_cookies()) { $cache = make_string_tempcode(preg_replace('#((\\?)|(&(amp;)?))keep\\_[^="]*=[^&"]*#', '\\2', $cache->evaluate())); } put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); } elseif ($ttl != -1 && $cache->is_empty()) { $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; return do_block($codename, $map, -1); } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; } return $cache; } } } // NB: If we've got this far cache="2" is ignored. But later on (for normal expiries, different contexts, etc) cache_on will be known so not an issue. // We will need to load the actual file if (is_null($object)) { $object = do_block_hunt_file($codename, $map); } if (is_object($object)) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); $cache = $object->run($map); $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; } else { $out = new ocp_tempcode(); $out->attach($object); return $out; } // May it be added to cache_on? if (!$DO_NOT_CACHE_THIS && method_exists($object, 'cacheing_environment') && (get_option('is_on_block_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1 || get_param_integer('cache', 0) == 1) && (get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0)) { $info = $object->cacheing_environment($map); if ($info !== NULL) { $cache_identifier = do_block_get_cache_identifier($info['cache_on'], $map); if ($cache_identifier !== NULL) { require_code('caches2'); put_into_cache($codename, $info['ttl'], $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); if (!defined('HIPHOP_PHP') && !is_array($info['cache_on'])) { $GLOBALS['SITE_DB']->query_insert('cache_on', array('cached_for' => $codename, 'cache_on' => $info['cache_on'], 'cache_ttl' => $info['ttl']), false, true); // Allow errors in case of race conditions } } } } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; return $cache; }
/** * Delete a zones database stuff. * * @param ID_TEXT The name of the zone */ function actual_delete_zone_lite($zone) { $zone_header_text = $GLOBALS['SITE_DB']->query_value_null_ok('zones', 'zone_header_text', array('zone_name' => $zone)); if (is_null($zone_header_text)) { return; } $zone_title = $GLOBALS['SITE_DB']->query_value('zones', 'zone_title', array('zone_name' => $zone)); delete_lang($zone_header_text); delete_lang($zone_title); $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('group_page_access', array('zone_name' => $zone)); $GLOBALS['SITE_DB']->query_delete('comcode_pages', array('the_zone' => $zone), '', NULL, NULL, true); // May fail because the table might not exist when this is called if (addon_installed('redirects_editor')) { $GLOBALS['SITE_DB']->query_delete('redirects', array('r_from_zone' => $zone)); $GLOBALS['SITE_DB']->query_delete('redirects', array('r_to_zone' => $zone)); } $GLOBALS['SITE_DB']->query_delete('menu_items', array('i_url' => $zone . ':')); log_it('DELETE_ZONE', $zone); decache('side_zone_jump'); decache('side_stored_menu'); decache('main_sitemap'); persistant_cache_delete(array('ZONE', $zone)); persistant_cache_delete('ALL_ZONES'); global $ALL_ZONES, $ALL_ZONES_TITLED; $ALL_ZONES = NULL; $ALL_ZONES_TITLED = NULL; }
/** * Set the poll. * * @param AUTO_LINK The poll ID to set */ function set_poll($id) { persistant_cache_delete('POLL'); $rows = $GLOBALS['SITE_DB']->query_select('poll', array('question', 'submitter'), array('id' => $id)); $question = $rows[0]['question']; $submitter = $rows[0]['submitter']; log_it('CHOOSE_POLL', strval($id), get_translated_text($question)); if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'polls')) { syndicate_described_activity('polls:ACTIVITY_CHOOSE_POLL', get_translated_text($question), '', '', '_SEARCH:polls:view:' . strval($id), '', '', 'polls'); } if (!is_guest($submitter) && addon_installed('points')) { require_code('points2'); $_points_chosen = get_option('points_CHOOSE_POLL'); if (is_null($_points_chosen)) { $points_chosen = 35; } else { $points_chosen = intval($_points_chosen); } if ($points_chosen != 0) { system_gift_transfer(do_lang('POLL'), $points_chosen, $submitter); } } $GLOBALS['SITE_DB']->query_update('poll', array('is_current' => 0), array('is_current' => 1)); $GLOBALS['SITE_DB']->query_update('poll', array('is_current' => 1, 'date_and_time' => time()), array('id' => $id), '', 1); decache('main_poll'); require_lang('polls'); require_code('notifications'); $subject = do_lang('POLL_CHOSEN_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $question); $poll_url = build_url(array('page' => 'polls', 'type' => 'view', 'id' => $id), get_module_zone('polls'), NULL, false, false, true); $mail = do_lang('POLL_CHOSEN_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape(get_translated_text($question)), $poll_url->evaluate()); dispatch_notification('poll_chosen', NULL, $subject, $mail); }
/** * Remove an item from the general cache (most commonly used for blocks). * * @param ID_TEXT The type of what we are cacheing (e.g. block name) * @param ?array A map of identifiying characteristics (NULL: no identifying characteristics, decache all) */ function decache($cached_for, $identifier = NULL) { if (running_script('stress_test_loader')) { return; } if (get_page_name() == 'admin_import') { return; } // NB: If we use persistant cache we still need to decache from DB, in case we're switching between for whatever reason. Or maybe some users use persistant cache and others don't. Or maybe some nodes do and others don't. if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_delete(array('CACHE', $cached_for)); } $where = db_string_equal_to('cached_for', $cached_for); if ($identifier !== NULL) { $where .= ' AND ('; $done_first = false; // For combinations of implied parameters $bot_statuses = array(true, false); $timezones = array_keys(get_timezone_list()); foreach ($bot_statuses as $bot_status) { foreach ($timezones as $timezone) { $_cache_identifier = $identifier; $_cache_identifier[] = $timezone; $_cache_identifier[] = $bot_status; global $TEMPCODE_SETGET; $_cache_identifier[] = isset($TEMPCODE_SETGET['in_panel']) ? $TEMPCODE_SETGET['in_panel'] : '0'; $_cache_identifier[] = isset($TEMPCODE_SETGET['interlock']) ? $TEMPCODE_SETGET['interlock'] : '0'; if ($done_first) { $where .= ' OR '; } $where .= db_string_equal_to('identifier', md5(serialize($_cache_identifier))); $done_first = true; } } // And finally for no implied parameters (raw API usage) $_cache_identifier = $identifier; if ($done_first) { $where .= ' OR '; } $where .= db_string_equal_to('identifier', md5(serialize($_cache_identifier))); $done_first = true; $where .= ')'; } $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'cache WHERE ' . $where); }
/** * Import an emoticon. * * @param PATH Path to the emoticon file, on disk (must be in theme images folder). */ function _import_emoticon($path) { $emoticon_code = basename($path, '.' . get_file_extension($path)); if (file_exists(get_file_base() . '/themes/default/images/emoticons/index.html')) { $image_code = 'emoticons/' . $emoticon_code; } else { $image_code = 'ocf_emoticons/' . $emoticon_code; } $url_path = 'themes/default/images_custom/' . rawurlencode(basename($path)); $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => $image_code)); $GLOBALS['SITE_DB']->query_insert('theme_images', array('id' => $image_code, 'theme' => 'default', 'path' => $url_path, 'lang' => get_site_default_lang())); $GLOBALS['FORUM_DB']->query_delete('f_emoticons', array('e_code' => ':' . $emoticon_code . ':'), '', 1); $GLOBALS['FORUM_DB']->query_insert('f_emoticons', array('e_code' => ':' . $emoticon_code . ':', 'e_theme_img_code' => $image_code, 'e_relevance_level' => 2, 'e_use_topics' => 0, 'e_is_special' => 0)); persistant_cache_delete('THEME_IMAGES'); }
/** * UI for a logo wizard step (set). * * @return tempcode The UI */ function __make_logo() { $title = get_page_title('_LOGOWIZARD', true, array(integer_format(3), integer_format(3))); $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/logowizard'; $theme = post_param('theme'); // Do it require_code('themes2'); $rand = uniqid('', true); foreach (array($theme, 'default') as $logo_save_theme) { $path = 'themes/' . $logo_save_theme . '/images_custom/' . $rand . '.png'; $img = generate_logo(post_param('name'), post_param('title'), false, $logo_save_theme, 'logo-template'); @imagepng($img, get_custom_file_base() . '/' . $path) or intelligent_write_error($path); imagedestroy($img); actual_edit_theme_image('logo/-logo', $logo_save_theme, user_lang(), 'logo/-logo', $path); if (addon_installed('collaboration_zone')) { actual_edit_theme_image('logo/collaboration-logo', $logo_save_theme, user_lang(), 'logo/collaboration-logo', $path); } $rand = uniqid('', true); $path = 'themes/' . $logo_save_theme . '/images_custom/' . $rand . '.png'; $img = generate_logo(post_param('name'), post_param('title'), false, NULL, 'trimmed-logo-template'); @imagepng($img, get_custom_file_base() . '/' . $path) or intelligent_write_error($path); imagedestroy($img); actual_edit_theme_image('logo/trimmed-logo', $logo_save_theme, user_lang(), 'logo/trimmed-logo', $path); } persistant_cache_delete('THEME_IMAGES'); breadcrumb_set_parents(array(array('_SELF:_SELF:make_logo', do_lang_tempcode('START')))); $message = do_lang_tempcode('LOGOWIZARD_3_DESCRIBE', escape_html($theme)); return inform_screen($title, $message); }
/** * A theme image has been passed through by POST, either as a file (a new theme image), or as a reference to an existing one. Get the image code from the POST data. * * @param ID_TEXT The type of theme image * @param boolean Allow no code to be given * @param ID_TEXT Form field for uploading * @param ID_TEXT Form field for choosing * @param ?object Database connection (NULL: site database) * @return ID_TEXT The (possibly randomised) theme image code */ function get_theme_img_code($type, $allow_skip = false, $field_file = 'file', $field_choose = 'theme_img_code', $db = NULL) { if (is_null($db)) { $db = $GLOBALS['SITE_DB']; } // TODO: Image won't upload to central site. So perhaps we should not allow uploads if not editing on central site. if (substr($type, 0, 4) == 'ocf_' && file_exists(get_file_base() . '/themes/default/images/avatars/index.html')) { $type = substr($type, 4); } require_code('uploads'); if (is_swf_upload() || array_key_exists($field_file, $_FILES) && is_uploaded_file($_FILES[$field_file]['tmp_name'])) { $urls = get_url('', $field_file, 'themes/default/images_custom', 0, OCP_UPLOAD_IMAGE, false); $theme_img_code = $type . '/' . uniqid('', true); $db->query_insert('theme_images', array('id' => $theme_img_code, 'theme' => 'default', 'path' => $urls[0], 'lang' => get_site_default_lang())); persistant_cache_delete('THEME_IMAGES'); } else { $theme_img_code = post_param($field_choose, ''); if ($theme_img_code == '') { if ($allow_skip) { return ''; } warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } } return $theme_img_code; }
/** * The actualiser to edit a theme image. * * @return tempcode The UI */ function _edit_image() { require_code('uploads'); $title = get_page_title('EDIT_THEME_IMAGE'); $lang = choose_language($title, true, true); if (is_object($lang)) { return $lang; } $theme = post_param('theme'); //if ((get_file_base()!=get_custom_file_base()) && ($theme=='default')) warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); $id = post_param('id'); $old_id = post_param('old_id'); if (post_param_integer('delete', 0) == 1) { require_code('themes3'); actual_delete_theme_image($old_id, $theme, $lang); } else { $path = get_url('path', 'file', 'themes/' . $theme . '/images_custom'); if (url_is_local($path[0]) && !file_exists((substr($path[0], 0, 15) == 'themes/default/' ? get_file_base() : get_custom_file_base()) . '/' . rawurldecode($path[0]))) { warn_screen($title, do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } if ($path[0] == '') { return warn_screen($title, do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } actual_edit_theme_image($old_id, $theme, $lang, $id, $path[0]); } persistant_cache_delete('THEME_IMAGES'); erase_cached_templates(); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_THEMES')), array('_SELF:_SELF:manage_images:theme=' . $theme, do_lang_tempcode('CHOOSE')), array('_SELF:_SELF:edit_theme_image:id=' . $id, do_lang_tempcode('EDIT_THEME_IMAGE')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return $this->do_next_manager($title, do_lang_tempcode('SUCCESS'), $theme, $lang, 'image', $id); }
/** * Deletes a specified config option permanently from the database. * * @param ID_TEXT The codename of the config option */ function delete_config_option($name) { $rows = $GLOBALS['SITE_DB']->query_select('config', array('*'), array('the_name' => $name), '', 1); if (array_key_exists(0, $rows)) { $myrow = $rows[0]; if (($myrow['the_type'] == 'transline' || $myrow['the_type'] == 'transtext') && is_numeric($myrow['config_value'])) { delete_lang($myrow['config_value']); } $GLOBALS['SITE_DB']->query_delete('config', array('the_name' => $name), '', 1); /*global $OPTIONS; Don't do this, it will cause problems in some parts of the code unset($OPTIONS[$name]);*/ } if (function_exists('persistant_cache_delete')) { persistant_cache_delete('OPTIONS'); } }
/** * Delete a situational value. * * @param ID_TEXT The name of the value */ function delete_value($name) { $GLOBALS['SITE_DB']->query_delete('values', array('the_name' => $name), '', 1); if (function_exists('persistant_cache_delete')) { persistant_cache_delete('VALUES'); } }