/** * Standard interface stage of pointstore item purchase. * * @return tempcode The UI */ function action() { require_code('database_action'); $class = str_replace('hook_pointstore_', '', strtolower(get_class($this))); $title = get_page_title('OCGIFTS_TITLE'); require_code('form_templates'); $map = NULL; $category = either_param('category', ''); if ($category != '') { $map = array('category' => $category); } $max_rows = $GLOBALS['SITE_DB']->query_value('ocgifts', 'COUNT(*)', $map); $max = get_param_integer('max', 20); $start = get_param_integer('start', 0); require_code('templates_results_browser'); $results_browser = results_browser(do_lang_tempcode('OCGIFTS_TITLE'), get_param('id'), $start, 'start', $max, 'max', $max_rows, NULL, NULL, true, true); $rows = $GLOBALS['SITE_DB']->query_select('ocgifts g', array('*', '(SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'members_gifts m WHERE m.gift_id=g.id) AS popularity'), $map, 'ORDER BY popularity DESC', $max, $start); $username = get_param('username', ''); $gifts = array(); foreach ($rows as $gift) { $gift_url = build_url(array('page' => 'pointstore', 'type' => 'action_done', 'id' => 'ocgifts', 'gift' => $gift['id'], 'username' => $username), '_SEARCH'); $image_url = ''; if (is_file(get_custom_file_base() . '/' . rawurldecode($gift['image']))) { $image_url = get_custom_base_url() . '/' . $gift['image']; } $gifts[] = array('NAME' => $gift['name'], 'PRICE' => integer_format($gift['price']), 'POPULARITY' => integer_format($gift['popularity']), 'GIFT_URL' => $gift_url, 'IMAGE_URL' => $image_url); } $categories = collapse_1d_complexity('category', $GLOBALS['SITE_DB']->query_select('ocgifts', array('DISTINCT category'), NULL, 'ORDER BY category')); return do_template('POINTSTORE_OCGIFTS_GIFTS', array('TITLE' => $title, 'GIFTS' => $gifts, 'RESULTS_BROWSER' => $results_browser, 'CATEGORY' => $category, 'CATEGORIES' => $categories)); }
/** * Validate an IP address, indirectly by passing through a confirmation code. */ function validate_ip_script() { @ob_end_clean(); global $EXTRA_HEAD; $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML $keep = keep_symbol(array('1')); $code = either_param('code', ''); if ($code == '') { $title = get_page_title('CONFIRM'); require_code('form_templates'); $fields = new ocp_tempcode(); $fields->attach(form_input_codename(do_lang_tempcode('CODE'), '', 'code', '', true)); $submit_name = do_lang_tempcode('PROCEED'); $url = find_script('validateip') . $keep; $middle = do_template('FORM_SCREEN', array('_GUID' => 'd92ce4ec82dc709f920a4ce6760778de', 'TITLE' => $title, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'URL' => $url, 'FIELDS' => $fields, 'TEXT' => do_lang_tempcode('MISSING_CONFIRM_CODE'), 'SUBMIT_NAME' => $submit_name)); $echo = globalise($middle, NULL, '', true); $echo->evaluate_echo(); exit; } // If we're still here, we're ok to go require_lang('ocf'); $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_member_known_login_ips', 'i_val_code', array('i_val_code' => $code)); if (is_null($test)) { warn_exit(do_lang_tempcode('ALREADY_VALIDATED')); } $GLOBALS['FORUM_DB']->query_update('f_member_known_login_ips', array('i_val_code' => ''), array('i_val_code' => $code), '', 1); $title = get_page_title('CONFIRM'); $middle = redirect_screen($title, get_base_url() . $keep, do_lang_tempcode('SUCCESS')); $echo = globalise($middle, NULL, '', true); $echo->evaluate_echo(); exit; }
/** * Helper function. From a given GET/POST parameter name, tries to identify a member ID. Parameter may be given as a direct member ID or via a username. * * @param string The given parameter name. * @return ?MEMBER Member ID (NULL: blank requested) */ function grab_new_owner($param_name) { $new_owner_raw = either_param($param_name); if ($new_owner_raw == '') { return NULL; } if (is_numeric($new_owner_raw)) { return intval($new_owner_raw); } return $GLOBALS['FORUM_DRIVER']->get_member_from_username($param_name); }
/** * Standard modular run function. * * @return tempcode The result of execution. */ function run() { require_lang('ecommerce'); require_code('ecommerce'); require_lang('shopping'); require_javascript('javascript_shopping'); require_css('shopping'); require_code('users_active_actions'); $type = get_param('type', 'misc'); if ($type == 'misc') { return $this->misc(); } if ($type == 'show_orders') { return $this->show_orders(); } if ($type == 'order_det') { return $this->order_details(); } if ($type == 'order_act') { $action = either_param('action'); if ($action == 'add_note') { return $this->add_note(); } if ($action == 'dispatch') { return $this->dispatch(); } if ($action == 'del_order') { return $this->delete_order(); } if ($action == 'return') { return $this->return_order(); } if ($action == 'hold') { return $this->hold_order(); } } if ($type == '_add_note') { return $this->_add_note(); } if ($type == 'order_export') { return $this->order_export(); } if ($type == '_order_export') { return $this->_order_export(); } return new ocp_tempcode(); }
/** * Standard modular render function for profile tab hooks. * * @param MEMBER The ID of the member who is being viewed * @param MEMBER The ID of the member who is doing the viewing * @param boolean Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later * @return array A triple: The tab title, the tab contents, the suggested tab order */ function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false) { $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=activities&filter=' . strval($member_id_of); require_lang('activities'); $title = do_lang_tempcode('ACTIVITIES_TITLE'); $order = 70; // Need to declare these here as the Tempcode engine can't look as deep, into a loop (I think), as it would need to, to find the block declaring the dependency require_css('activities'); require_javascript('javascript_activities_state'); require_javascript('javascript_activities'); require_javascript('javascript_jquery'); require_javascript('javascript_base64'); // Allow user to link up things for syndication $syndications = array(); if ($member_id_of == $member_id_viewing) { $dests = find_all_hooks('systems', 'syndication'); foreach (array_keys($dests) as $hook) { require_code('hooks/systems/syndication/' . $hook); $ob = object_factory('Hook_Syndication_' . $hook); if ($ob->is_available()) { if (either_param('syndicate_stop__' . $hook, NULL) !== NULL) { $ob->auth_unset($member_id_of); } elseif (either_param('syndicate_start__' . $hook, NULL) !== NULL) { $url_map = array('page' => '_SELF', 'type' => 'view', 'id' => $member_id_of, 'oauth_in_progress' => 1); $url_map['syndicate_start__' . $hook] = 1; $oauth_url = build_url($url_map, '_SELF', NULL, false, false, false, 'tab__activities'); $ob->auth_set($member_id_of, $oauth_url); } elseif (running_script('index') && !$leave_to_ajax_if_possible && $ob->auth_is_set($member_id_of) && either_param('oauth_in_progress', NULL) === NULL && !$GLOBALS['IS_ACTUALLY_ADMIN']) { /* running_script('index') won't work currently due to execution contexts, and it is never non-AJAX, and it's probably not needed anyway // Do a refresh to make sure the token is updated $url_map=array('page'=>'_SELF','type'=>'view','id'=>$member_id_of,'oauth_in_progress'=>1); $url_map['syndicate_start__'.$hook]=1; $oauth_url=build_url($url_map,'_SELF',NULL,false,false,false,'tab__activities'); $ob->auth_set($member_id_of,$oauth_url); */ } $syndications[$hook] = array('SYNDICATION_IS_SET' => $ob->auth_is_set($member_id_of), 'SYNDICATION_SERVICE_NAME' => $ob->get_service_name()); } } } if ($leave_to_ajax_if_possible) { return array($title, NULL, $order); } $content = do_template('OCF_MEMBER_PROFILE_ACTIVITIES', array('MEMBER_ID' => strval($member_id_of), 'SYNDICATIONS' => $syndications)); return array($title, $content, $order); }
/** * Function to process the file upload process */ function incoming_uploads_script() { $image_url_sub_for = get_param('image_url_sub_for', NULL); if ($image_url_sub_for !== NULL) { require_code('files'); if (!url_is_local($image_url_sub_for) || strpos($image_url_sub_for, '/incoming/') !== false) { $url_to = 'uploads/website_specific/' . md5(uniqid('', true)) . '.png'; } else { $url_to = dirname($image_url_sub_for) . '/' . md5(uniqid('', true)) . '.png'; } $write_to_file = fopen($url_to, 'wb'); http_download_file(either_param('imageurl'), NULL, true, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $write_to_file); fclose($write_to_file); $GLOBALS['SITE_DB']->query_insert('image_url_sub_for', array('url_from' => $image_url_sub_for, 'url_to' => $url_to, 'member_id' => get_member(), 'expire' => time() + 60 * 60 * 24)); exit; } non_overrided__incoming_uploads_script(); }
/** * Output the trackback script and handle trackbacks. */ function trackback_script() { if (get_option('is_on_trackbacks') == '0') { return; } require_lang('trackbacks'); header('Content-type: text/xml'); $page = get_param('page'); $id = get_param_integer('id'); $mode = either_param('__mode', 'none'); $allow_trackbacks = true; $hooks = find_all_hooks('systems', 'trackback'); foreach (array_keys($hooks) as $hook) { if ($hook == $page) { require_code('hooks/systems/trackback/' . filter_naughty_harsh($hook)); $object = object_factory('Hook_trackback_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $allow_trackbacks = $object->run($id); break; } } if ($mode == 'rss') { //List all the trackbacks to the specified page $xml = get_trackbacks($page, strval($id), $allow_trackbacks, 'xml'); } else { $time = get_param_integer('time'); if ($time > time() - 60 * 5) { exit; } // Trackback link intentionally goes stale after 5 minutes, so it can't be statically stored and spam hammered //Add a trackback for the specified page $output = actualise_post_trackback($allow_trackbacks, $page, strval($id)); if ($output) { $xml = do_template('TRACKBACK_XML_NO_ERROR', array()); } else { $xml = do_template('TRACKBACK_XML_ERROR', array('_GUID' => 'ac5e34aeabf92712607e62e062407861', 'TRACKBACK_ERROR' => do_lang_tempcode('TRACKBACK_ERROR'))); } } $echo = do_template('TRACKBACK_XML_WRAPPER', array('_GUID' => 'cd8d057328569803a6cca9f8d37a0ac8', 'XML' => $xml)); $echo->evaluate_echo(); }
function activities_ajax_submit_handler() { header('Content-Type: text/xml'); // header('HTTP/1.0 200 Ok'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past $response = '<' . '?xml version="1.0" encoding="' . get_charset() . '" ?' . '>'; $response .= '<response><content>'; $map = array(); $guest_id = intval($GLOBALS['FORUM_DRIVER']->get_guest_id()); if (!is_guest(get_member())) { $map['STATUS'] = trim(either_param('status', '')); if (post_param('zone', '') != '' && $map['STATUS'] != '' && $map['STATUS'] != do_lang('activities:TYPE_HERE')) { comcode_to_tempcode($map['STATUS'], $guest_id, false, NULL); $map['PRIVACY'] = either_param('privacy', 'private'); if (strlen(strip_tags($map['STATUS'])) < strlen($map['STATUS'])) { $cc_guide = build_url(array('page' => 'userguide_comcode'), 'site'); $response .= '<success>0</success><feedback><![CDATA[No HTML allowed. See <a href="' . $cc_guide->evaluate() . '">Comcode Help</a> for info on the alternative.]]></feedback>'; } else { if (strlen($map['STATUS']) > 255) { $response .= '<success>0</success><feedback>Message is ' . strval(strlen($map['STATUS']) - 255) . ' characters too long</feedback>'; } else { $stored_id = activities_addon_syndicate_described_activity('RAW_DUMP', $map['STATUS'], '', '', '', '', '', '', $map['PRIVACY'] == 'public' ? 1 : 0); if ($stored_id > 0) { $response .= '<success>1</success><feedback>Message received.</feedback>'; } elseif ($stored_id == -1) { $response .= '<success>0</success><feedback>Message already received.</feedback>'; } } } } } else { $response .= '<success>0</success><feedback>' . do_lang('LOGIN_EXPIRED_POST') . '</feedback>'; } $response .= '</content></response>'; echo $response; }
/** * The actualiser for logging in. * * @return tempcode The UI. */ function login_after() { breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('_LOGIN')))); $username = trim(post_param('login_username')); $feedback = $GLOBALS['FORUM_DRIVER']->forum_authorise_login($username, NULL, apply_forum_driver_md5_variant(trim(post_param('password')), $username), trim(post_param('password'))); $id = $feedback['id']; if (!is_null($id)) { $title = get_page_title('LOGGED_IN'); $url = enforce_sessioned_url(either_param('redirect')); //set_session_id(get_session_id()); // Just in case something earlier set it to a pre-logged-in one Not needed if (count($_POST) <= 4) { require_code('site2'); assign_refresh($url, 0.0); $post = new ocp_tempcode(); $refresh = new ocp_tempcode(); } else { $post = build_keep_post_fields(array('redirect', 'redirect_passon')); $redirect_passon = post_param('redirect_passon', NULL); if (!is_null($redirect_passon)) { $post->attach(form_input_hidden('redirect', $redirect_passon)); } $refresh = do_template('JS_REFRESH', array('_GUID' => 'c7d2f9e7a2cc637f3cf9ac4d1cf97eca', 'FORM_NAME' => 'redir_form')); } decache('side_users_online'); return do_template('LOGIN_REDIRECT_SCREEN', array('_GUID' => '82e056de9150bbed185120eac3571f40', 'REFRESH' => $refresh, 'TITLE' => $title, 'TEXT' => do_lang_tempcode('_LOGIN_TEXT'), 'URL' => $url, 'POST' => $post)); } else { get_page_title('USER_LOGIN_ERROR'); $text = $feedback['error']; attach_message($text, 'warn'); if (get_forum_type() == 'ocf') { require_lang('ocf'); $forgotten_link = build_url(array('page' => 'lostpassword'), get_module_zone('lostpassword')); $extra = do_lang_tempcode('IF_FORGOTTEN_PASSWORD', escape_html($forgotten_link->evaluate())); attach_message($extra, 'inform'); } return $this->login_before(); } }
/** * Add trackbacks to the specified resource. * * @param boolean Whether this resource allows trackback (if not, this function does nothing - but it's nice to move out this common logic into the shared function) * @param ID_TEXT The type (download, etc) that this trackback is for * @param ID_TEXT The ID of the type that this trackback is for * @return boolean Whether trackbacks are on */ function actualise_post_trackback($allow_trackbacks, $content_type, $content_id) { if (get_option('is_on_trackbacks') == '0' || !$allow_trackbacks) { return false; } $url = either_param('url', NULL); if (is_null($url)) { return false; } $title = either_param('title', $url); $excerpt = either_param('excerpt', ''); $name = either_param('blog_name', $url); $GLOBALS['SITE_DB']->query_insert('trackbacks', array('trackback_for_type' => $content_type, 'trackback_for_id' => $content_id, 'trackback_ip' => get_ip_address(), 'trackback_time' => time(), 'trackback_url' => $url, 'trackback_title' => $title, 'trackback_excerpt' => $excerpt, 'trackback_name' => $name)); return true; }
/** * Get Javascript to restrict post lengths. * * @return string The post Javascript */ function _post_javascript() { $size = ocf_get_member_best_group_property(get_member(), 'max_post_length_comcode'); $javascript = ''; $javascript .= "\n\t\t\tvar form=document.getElementById('post').form;\n\t\t\tform.old_submit=form.onsubmit;\n\t\t\tform.onsubmit=function() {\n\t\t\t\tvar post=form.elements['post'];\n\t\t\t\tvar text_value;\n\t\t\t\tif (is_wysiwyg_field(post))\n\t\t\t\t{\n\t\t\t\t\ttry\n\t\t\t\t\t{\n\t\t\t\t\t\ttext_value=window.CKEDITOR.instances['post'].getData();\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {};\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\tif ((!post.value) && (post[1])) post=post[1];\n\t\t\t\t\ttext_value=post.value;\n\t\t\t\t}\n\t\t\t\tif (text_value.length>" . strval($size) . ")\n\t\t\t\t{\n\t\t\t\t\twindow.fauxmodal_alert('" . php_addslashes(do_lang('_POST_TOO_LONG')) . "');\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t"; $stub = unixify_line_format(either_param('stub', '')); if ($stub != '') { $javascript .= "\n\t\t\t\tvar df='" . str_replace(chr(10), '\\n', addslashes($stub)) . "';\n\n\t\t\t\tvar pv=post.value;\n\t\t\t\tif ((post) && (pv.substring(0,df.length)==df))\n\t\t\t\t{\n\t\t\t\t\tpv=pv.substring(df.length,pv.length);\n\t\t\t\t}\n\t\t\t\tpost.value=pv;\n\t\t"; } $javascript .= "\n\t\t\t\tif (typeof form.old_submit!='undefined' && form.old_submit) return form.old_submit();\n\n\t\t\t\treturn true;\n\t\t\t};\n\t\t"; return $javascript; }
/** * The main user interface for choosing a chat room to moderate. * * @return tempcode The UI. */ function chat_choose_room() { if (has_actual_page_access(get_member(), 'admin_chat')) { require_lang('menus'); $also_url = build_url(array('page' => 'admin_chat'), get_module_zone('admin_chat')); attach_message(do_lang_tempcode('ALSO_SEE_CMS', escape_html($also_url->evaluate())), 'inform'); } $title = get_page_title('CHAT_MOD_PANEL'); $introtext = do_lang_tempcode('CHAT_PANEL_INTRO'); breadcrumb_set_self(do_lang_tempcode('CHOOSE')); $start = get_param_integer('start', 0); $max = get_param_integer('max', 50); $sortables = array('room_name' => do_lang_tempcode('ROOM_NAME'), 'messages' => do_lang_tempcode('MESSAGES')); $test = explode(' ', either_param('sort', 'room_name DESC')); if (count($test) == 1) { $test[1] = 'DESC'; } list($sortable, $sort_order) = $test; if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) { log_hack_attack_and_exit('ORDERBY_HACK'); } global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'sort'; require_code('templates_results_table'); $fields_title = results_field_title(array(do_lang_tempcode('ROOM_NAME'), do_lang_tempcode('ROOM_OWNER'), do_lang_tempcode('ROOM_LANG'), do_lang_tempcode('MESSAGES')), $sortables, 'sort', $sortable . ' ' . $sort_order); $max_rows = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'COUNT(*)', array('is_im' => 0)); $sort_clause = $sortable == 'room_name' ? 'ORDER BY room_name ' . $sort_order : ''; $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('is_im' => 0), $sort_clause, $max, $start); if ($sortable == 'messages') { usort($rows, array('Module_cms_chat', '_sort_chat_browse_rows')); if ($sort_order == 'DESC') { $rows = array_reverse($rows); } } $fields = new ocp_tempcode(); foreach ($rows as $row) { $has_mod_access = has_specific_permission(get_member(), 'edit_lowrange_content', 'cms_chat', array('chat', $row['id'])) || $row['room_owner'] == get_member() && has_specific_permission(get_member(), 'moderate_my_private_rooms'); if (!handle_chatroom_pruning($row) && $has_mod_access) { $url = build_url(array('page' => '_SELF', 'type' => 'room', 'id' => $row['id']), '_SELF'); $messages = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)', array('room_id' => $row['id'])); $username = $GLOBALS['FORUM_DRIVER']->get_username($row['room_owner']); if (is_null($username)) { $username = ''; } //do_lang('UNKNOWN'); $fields->attach(results_entry(array(hyperlink($url, escape_html($row['room_name'])), escape_html($username), escape_html($row['room_language']), escape_html(integer_format($messages))))); } } if ($fields->is_empty()) { inform_exit(do_lang_tempcode('NO_CATEGORIES')); } $results_table = results_table(do_lang_tempcode('ROOMS'), $start, 'start', $max, 'max', $max_rows, $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort'); return do_template('CHAT_MODERATE_SCREEN', array('_GUID' => 'c59cb6c8409d0e678b05628d92e423db', 'TITLE' => $title, 'INTRODUCTION' => $introtext, 'CONTENT' => $results_table, 'LINKS' => array())); }
/** * Standard modular run function. * * @return tempcode The result of execution. */ function run() { require_code('ocworld'); require_code('ocworld_screens'); // Decide what functions to execute for this command $command = either_param('type', 'room'); $param = either_param('param', ''); $dest_member_id = either_param_integer('user', -1); $member_id = get_member(); if (is_guest($member_id)) { ocw_refresh_with_message(do_lang_tempcode('W_NOT_LOGGED_IN'), 'warn'); return new ocp_tempcode(); } $item = either_param('item', ''); // Create the member if they aren't already in the system $member_rows = $GLOBALS['SITE_DB']->query_select('w_members', array('*'), array('id' => $member_id), '', 1); if (!array_key_exists(0, $member_rows)) { $member_rows[0] = array('id' => $member_id, 'location_realm' => 0, 'location_x' => 0, 'location_y' => 0, 'banned' => 0, 'health' => 10, 'trolled' => 0, 'lastactive' => time()); $GLOBALS['SITE_DB']->query_insert('w_members', $member_rows[0]); } $member_row = $member_rows[0]; // Check for banning if ($member_row['banned'] == 1) { ocw_refresh_with_message(do_lang_tempcode('W_YOU_BANNED'), 'warn'); } // Check for death if ($member_row['health'] < 1) { take_items($member_id); $GLOBALS['SITE_DB']->query_update('w_members', array('location_realm' => 0, 'location_x' => 0, 'location_y' => 0, 'banned' => 0, 'health' => 10), array('id' => $member_id), '', 1); ocw_refresh_with_message(do_lang_tempcode('W_YOU_DIED'), 'warn'); } // Mark as active $GLOBALS['SITE_DB']->query_update('w_members', array('lastactive' => time()), array('id' => $member_id), '', 1); destick($member_id); // Check to see if the user is locked into answering a trolls questions if ($member_row['trolled'] != 0) { $realm = $member_row['location_realm']; // Get the questions that were asked $i = 0; $trolled = $member_row['trolled']; $q = array(); $a = array(); while (($trolled & 255 << $i * 8) != 0) { $q_num = $trolled >> $i * 8 & 255; $q[$i + 1] = $GLOBALS['SITE_DB']->query_value('w_realms', 'q' . strval($q_num), array('id' => $realm)); $a[$i + 1] = $GLOBALS['SITE_DB']->query_value('w_realms', 'a' . strval($q_num), array('id' => $realm)); $i++; } $num_questions = $i; // Are we marking or answering? if (post_param('a1', '!!') != '!!') { // Mark them $pass = 0; for ($i = 1; $i <= $num_questions; $i++) { $given = strtolower(post_param('a' . strval($i))); $stored = strtolower($a[$i]); if ($given == $stored) { $pass++; } elseif (strstr(':' . $stored . ':', ':' . $given . ':') !== false) { $pass++; } } // Regardless they have had their chance: no more questions $GLOBALS['SITE_DB']->query_update('w_members', array('trolled' => 0), array('id' => $member_id), '', 1); if ($pass == 0) { $pen_id = mt_rand(0, 2); if ($pen_id == 0) { $joke = mt_rand(1, 10); $penalty = do_lang_tempcode('W_JOKE_' . strval($joke)); hurt($member_id); } if ($pen_id == 1) { $penalty = do_lang('W_PENALTY_STOLEN'); steal($member_id, -$realm - 1); } if ($pen_id == 2) { $penalty = do_lang('W_PENALTY_SENT_LOBBY'); basic_enter_room($member_id, $realm, 0, 0); } ocw_refresh_with_message(do_lang_tempcode('W_TROLL_YOU', escape_html($penalty)), 'warn'); } else { ocw_refresh_with_message(do_lang_tempcode('W_TROLL_THANKYOU', integer_format($pass))); } } else { $troll_name = $GLOBALS['SITE_DB']->query_value('w_realms', 'troll_name', array('id' => $realm)); $title = get_page_title('W_TROLL_Q', true, array(escape_html($troll_name))); $questions = new ocp_tempcode(); for ($i = 1; $i <= $num_questions; $i++) { $questions->attach(do_template('W_TROLL_QUESTION', array('_GUID' => 'b09eb44e4264a9dca5bdf651ca9a48d4', 'Q' => $q[$i], 'I' => strval($i)))); } return do_template('W_TROLL', array('_GUID' => 'e108ccaebc5b1adfa9db6b5b23e93602', 'TITLE' => $title, 'TROLL' => $troll_name, 'QUESTIONS' => $questions)); } } // There is a chance the troll on this realm will pick this 'turn' to move if (mt_rand(0, 6) == 1) { $realm = $member_row['location_realm']; $troll_id = -$realm - 1; $troll_loc = get_loc_details($troll_id, true); if (!is_null($troll_loc)) { list(, $troll_x, $troll_y) = $troll_loc; $dx = -1; $dy = -1; do { $dx = mt_rand(-1, 1); $dy = mt_rand(-1, 1); } while (!room_exists($troll_x + $dx, $troll_y + $dy, $realm)); $GLOBALS['SITE_DB']->query_update('w_members', array('location_x' => $troll_x + $dx, 'location_y' => $troll_y + $dy), array('id' => $troll_id), '', 1); } } require_code('uploads'); // What command are we being asked to do? if ($command == 'confirm') { $url = build_url(array('page' => 'ocworld'), '_SELF'); $command2 = either_param('btype', ''); $item = either_param('item', ''); $user = either_param_integer('user', -1); $param = either_param('param', ''); return do_template('W_CONFIRM_SCREEN', array('_GUID' => '365870cb4c6cb4282ff6c7a11f4f8a5b', 'TITLE' => get_page_title('W_CONFIRM_TITLE'), 'URL' => $url, 'COMMAND' => $command2, 'ITEM' => $item, 'USER' => strval($user), 'PARAM' => $param)); } if ($command == 'reallocate') { if (!has_specific_permission(get_member(), 'administer_ocworld')) { ocw_refresh_with_message(do_lang_tempcode('W_ONLY_STAFF_REALLOC'), 'warn'); } $out = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('items', array('*'), array('copy_owner' => NULL)); foreach ($rows as $myrow) { $owner = $GLOBALS['SITE_DB']->query_value('w_itemdef', 'owner', array('name' => $myrow['name'])); if (!is_null($owner)) { $GLOBALS['SITE_DB']->query_update('w_items', array('copy_owner' => $owner), array('name' => $myrow['name'], 'copy_owner' => NULL)); $out->attach(paragraph(do_lang_tempcode('W_REALLOCATING', escape_html($myrow['name']), 'tfgdfgd4rf'))); } } return do_template('W_REALLOCATE', array('_GUID' => '8fa4b9205310d6bc2fc28348a52898d5', 'TITLE' => get_page_title('W_REALLOCATE'), 'OUT' => $out)); } if ($command == 'portal') { portal($member_id, intval($param)); } if ($command == 'realms') { realms(); return new ocp_tempcode(); } if ($command == 'up') { $tpl = try_to_enter_room($member_id, 0, -1, ''); if (!is_null($tpl)) { return $tpl; } ocw_refresh_with_message(new ocp_tempcode()); } if ($command == 'down') { $tpl = try_to_enter_room($member_id, 0, 1, ''); if (!is_null($tpl)) { return $tpl; } ocw_refresh_with_message(new ocp_tempcode()); } if ($command == 'right') { $tpl = try_to_enter_room($member_id, 1, 0, ''); if (!is_null($tpl)) { return $tpl; } ocw_refresh_with_message(new ocp_tempcode()); } if ($command == 'left') { $tpl = try_to_enter_room($member_id, -1, 0, ''); if (!is_null($tpl)) { return $tpl; } ocw_refresh_with_message(new ocp_tempcode()); } if ($command == 'answered') { $tpl = try_to_enter_room($member_id, post_param_integer('dx'), post_param_integer('dy'), $param); if (!is_null($tpl)) { return $tpl; } } if ($command == 'drop') { drop_wrap($member_id, $item); } if ($command == 'give') { give($member_id, $dest_member_id, $item); } if ($command == 'pickpocket') { pickpocket($member_id, $dest_member_id); } if ($command == 'use') { useitem($member_id, $item); } if ($command == 'take') { take($member_id, $item, $dest_member_id); } if ($command == 'buy') { buy($member_id, $item, $dest_member_id); } if ($command == 'inventory') { $tpl = output_inventory_screen($dest_member_id); return $tpl; } if ($command == 'findperson') { findperson($param == '' ? strval($dest_member_id) : $param); } if ($command == 'message') { message($member_id, post_param('post'), post_param_integer('tuser')); } if ($command == 'emergency') { basic_enter_room($member_id, 0, 0, 0); } if ($command == 'delete-message-by-person') { if (!has_specific_permission($member_id, 'administer_ocworld') && $member_id != $dest_member_id) { ocw_refresh_with_message(do_lang_tempcode('ACCESS_DENIED__I_ERROR', $GLOBALS['FORUM_DRIVER']->get_username(get_member())), 'warn'); } delete_message($member_id, $dest_member_id, addslashes($param)); } // Management if ($command == 'additem') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { $tpl = do_template('W_ITEM_SCREEN', array('_GUID' => '0246f7037a360996bdfb4f1dcf96bcfc', 'PRICE' => integer_format(get_price('mud_item')), 'TEXT' => paragraph(do_lang_tempcode('W_ADD_ITEM_TEXT')), 'TITLE' => get_page_title('W_ADD_ITEM_TITLE'), 'PAGE_TYPE' => 'additem', 'ITEM' => '', 'DESCRIPTION' => '', 'BRIBABLE' => '0', 'HEALTHY' => '0', 'PICTURE_URL' => '', 'MAX_PER_PLAYER' => '10', 'REPLICATEABLE' => '1')); return $tpl; } $urls = get_url('url', 'pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); add_item_wrap($member_id, $name, post_param_integer('cost', 0), post_param_integer('not_infinite', 0), post_param_integer('bribable', 0), post_param_integer('healthy', 0), $urls[0], post_param_integer('max_per_player', -1), post_param_integer('replicateable', 0), post_param('description')); } if ($command == 'additemcopy') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'w_itemdef WHERE replicateable=1 OR owner=' . strval((int) get_member()) . ' ORDER BY name'); $items = ''; foreach ($rows as $myrow) { $items .= "<option value=\"" . escape_html($myrow['name']) . "\">" . escape_html($myrow['name']) . "</option>"; } if ($items == '') { ocw_refresh_with_message(do_lang_tempcode('W_NO_ITEMS_YET'), 'warn'); } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($items); } $tpl = do_template('W_ITEMCOPY_SCREEN', array('_GUID' => '15799930bca51eafdee3c0a8e197866a', 'PRICE' => integer_format(get_price('mud_item_copy')), 'TEXT' => paragraph(do_lang_tempcode('W_ADD_ITEM_COPY_TEXT')), 'TITLE' => get_page_title('W_ADD_ITEM_COPY_TITLE'), 'PAGE_TYPE' => 'additemcopy', 'NOT_INFINITE' => '1', 'ITEMS' => $items, 'COST' => '')); return $tpl; } add_item_wrap_copy($member_id, $name, post_param_integer('cost'), post_param_integer('not_infinite', 0)); } if ($command == 'addroom') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { list($realm, $x, $y) = get_loc_details($member_id); $tpl = do_template('W_ROOM_SCREEN', array('_GUID' => '5357a6cf8648c952cf29c2b7234cfa6c', 'PRICE' => integer_format(get_price('mud_room')), 'TEXT' => paragraph(do_lang_tempcode('W_ADD_ROOM_TEXT')), 'ROOM_TEXT' => '', 'TITLE' => get_page_title('W_ADD_ROOM_TITLE'), 'PAGE_TYPE' => 'addroom', 'NAME' => '', 'PASSWORD_QUESTION' => '', 'PASSWORD_ANSWER' => '', 'PASSWORD_FAIL_MESSAGE' => '', 'REQUIRED_ITEM' => '', 'LOCKED_UP' => '0', 'LOCKED_DOWN' => '0', 'LOCKED_LEFT' => '0', 'LOCKED_RIGHT' => '0', 'ALLOW_PORTAL' => '1', 'PICTURE_URL' => '')); return $tpl; } $urls = get_url('url', 'pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); add_room_wrap($member_id, post_param_integer('position'), $name, post_param('text'), post_param('password_question'), post_param('password_answer'), post_param('password_fail_message'), post_param('required_item'), post_param_integer('locked_up', 0), post_param_integer('locked_down', 0), post_param_integer('locked_right', 0), post_param_integer('locked_left', 0), $urls[0], post_param_integer('allow_portal', 0)); } if ($command == 'addrealm') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { $fortnights = (time() - $GLOBALS['FORUM_DRIVER']->get_member_join_timestamp(get_member())) / (60 * 60 * 24 * 7 * 2); $made = $GLOBALS['SITE_DB']->query_value('w_realms', 'COUNT(*)', array('owner' => get_member())); $left = round($fortnights - $made); $_qa = new ocp_tempcode(); for ($i = 1; $i <= 30; $i++) { $_qa->attach(do_template('W_REALM_SCREEN_QUESTION', array('_GUID' => '5fa7725f11b0df7e58ff83f2f1751515', 'I' => strval($i), 'Q' => '', 'A' => ''))); } $tpl = do_template('W_REALM_SCREEN', array('_GUID' => '7ae26fe1766aed02233e1be84772759b', 'PRICE' => integer_format(get_price('mud_realm')), 'TEXT' => paragraph(do_lang_tempcode('W_ADD_REALM_TEXT', integer_format($left))), 'TITLE' => get_page_title('W_ADD_REALM_TITLE'), 'PAGE_TYPE' => 'addrealm', 'QA' => $_qa, 'NAME' => '', 'TROLL_NAME' => '', 'PRIVATE' => '0')); return $tpl; } $i = 1; $qa = array(); while (strlen(post_param('question' . strval($i), '')) > 0) { $qa[$i] = array(); $qa[$i]['q'] = post_param('question' . strval($i)); $qa[$i]['a'] = post_param('answer' . strval($i)); $i++; } $urls1 = get_url('jail_pic_url', 'jail_pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); $urls2 = get_url('jail_house_pic_url', 'jail_house_pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); $urls3 = get_url('lobby_pic_url', 'lobby_pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); add_realm_wrap($member_id, $name, post_param('troll_name'), post_param('jail_name'), post_param('jail_text'), $urls1[0], post_param('jail_house_name'), post_param('jail_house_text'), $urls2[0], post_param('lobby_name'), post_param('lobby_text'), $urls3[0], $qa, post_param_integer('private', 0)); } if ($command == 'addportal') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { $tpl = do_template('W_PORTAL_SCREEN', array('_GUID' => '69e74a964f69721d0381a920c4a25ce5', 'PRICE' => integer_format(get_price('mud_portal')), 'TEXT' => paragraph(do_lang_tempcode('W_ADD_PORTAL_TEXT')), 'TITLE' => get_page_title('W_ADD_PORTAL_TITLE'), 'PORTAL_TEXT' => '', 'PAGE_TYPE' => 'addportal', 'NAME' => '', 'END_LOCATION_REALM' => '', 'END_LOCATION_X' => '', 'END_LOCATION_Y' => '')); return $tpl; } add_portal_wrap($member_id, $name, post_param('text'), post_param_integer('end_location_realm', -1), post_param_integer('end_location_x', -1), post_param_integer('end_location_y', -1)); } if ($command == 'deleteitem') { require_code('ocworld_action'); delete_item_wrap($item); } if ($command == 'deleteroom') { require_code('ocworld_action'); delete_room_wrap($member_id); } if ($command == 'deleterealm') { require_code('ocworld_action'); delete_realm_wrap($member_id); } if ($command == 'deleteportal') { require_code('ocworld_action'); delete_portal_wrap($member_id, intval($param)); } // Admin commands if (has_specific_permission($member_id, 'administer_ocworld')) { if ($command == 'mergeitems') { merge_items($item, either_param('item2')); } if ($command == 'teleport-person') { $ast = strpos($param, ':'); $b = strpos($param, ':', $ast + 1); $realm = substr($param, 0, $ast); $x = intval(substr($param, $ast + 1, $b - $ast - 1)); $y = intval(substr($param, $b + 1)); basic_enter_room($dest_member_id, $realm, $x, $y); } if ($command == 'imprison-person') { imprison($dest_member_id); } if ($command == 'hurt-person') { hurt($dest_member_id); } if ($command == 'dehurt-person') { dehurt($dest_member_id); } if ($command == 'ban-person') { ban_member($dest_member_id); } if ($command == 'unban-person') { unban_member($dest_member_id); } if ($command == 'take-from-person') { steal($member_id, $dest_member_id); } } if ($command == 'edititem') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { $rows = $GLOBALS['SITE_DB']->query_select('w_itemdef', array('*'), array('name' => either_param('item')), '', 1); if (!array_key_exists(0, $rows)) { ocw_refresh_with_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn'); } $row = $rows[0]; $tpl = do_template('W_ITEM_SCREEN', array('_GUID' => '1f581864bd2f0cbe05742e03ab6c2a53', 'TITLE' => get_page_title('W_EDIT_ITEM_TITLE'), 'PAGE_TYPE' => 'edititem', 'ITEM' => either_param('item'), 'DESCRIPTION' => $row['description'], 'BRIBABLE' => strval($row['bribable']), 'HEALTHY' => strval($row['healthy']), 'PICTURE_URL' => $row['picture_url'], 'OWNER' => is_null($row['owner']) ? '' : strval($row['owner']), 'MAX_PER_PLAYER' => strval($row['max_per_player']), 'REPLICATEABLE' => strval($row['replicateable']))); return $tpl; } $urls = get_url('url', 'pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); edit_item_wrap($member_id, $item, $name, post_param_integer('bribable', 0), post_param_integer('healthy', 0), $urls[0], grab_new_owner('new_owner'), post_param_integer('max_per_player', -1), post_param_integer('replicateable', 0), post_param('description')); } if ($command == 'edititemcopy') { require_code('ocworld_action'); $cost = post_param_integer('cost', -1); if ($cost == -1) { $user = get_param_integer('user'); list($realm, $x, $y) = get_loc_details($member_id); $cost = $GLOBALS['SITE_DB']->query_value('w_items', 'cost', array('copy_owner' => $user, 'location_x' => $x, 'location_y' => $y, 'location_realm' => $realm, 'name' => get_param('item'))); $not_infinite = $GLOBALS['SITE_DB']->query_value('w_items', 'not_infinite', array('copy_owner' => $user, 'location_x' => $x, 'location_y' => $y, 'location_realm' => $realm, 'name' => get_param('item'))); $tpl = do_template('W_ITEMCOPY_SCREEN', array('_GUID' => 'a8d28f6516408dba96a8b57ddcd7cee6', 'TITLE' => get_page_title('W_EDIT_ITEM_COPY_TITLE'), 'PAGE_TYPE' => 'edititemcopy', 'NOT_INFINITE' => strval($not_infinite), 'X' => strval($x), 'Y' => strval($y), 'REALM' => strval($realm), 'ITEM' => get_param('item'), 'OWNER' => strval($user), 'COST' => strval($cost))); return $tpl; } edit_item_wrap_copy($member_id, $item, $cost, post_param_integer('not_infinite', 0), post_param_integer('new_x'), post_param_integer('new_y'), post_param_integer('new_realm'), grab_new_owner('new_owner')); } if ($command == 'editroom') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { list($location_realm, $x, $y) = get_loc_details($member_id); $rows = $GLOBALS['SITE_DB']->query_select('w_rooms', array('*'), array('location_x' => $x, 'location_y' => $y, 'location_realm' => $location_realm), '', 1); if (!array_key_exists(0, $rows)) { ocw_refresh_with_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn'); } $row = $rows[0]; $tpl = do_template('W_ROOM_SCREEN', array('_GUID' => 'a4c5f8ae962cdbaa304135cf07c583a0', 'TITLE' => get_page_title('W_EDIT_ROOM_TITLE'), 'PAGE_TYPE' => 'editroom', 'X' => strval($x), 'Y' => strval($y), 'REALM' => strval($location_realm), 'NAME' => $row['name'], 'ROOM_TEXT' => $row['r_text'], 'PASSWORD_QUESTION' => $row['password_question'], 'PASSWORD_ANSWER' => $row['password_answer'], 'PASSWORD_FAIL_MESSAGE' => $row['password_fail_message'], 'REQUIRED_ITEM' => $row['required_item'], 'LOCKED_UP' => strval($row['locked_up']), 'LOCKED_DOWN' => strval($row['locked_down']), 'LOCKED_LEFT' => strval($row['locked_left']), 'LOCKED_RIGHT' => strval($row['locked_right']), 'ALLOW_PORTAL' => strval($row['allow_portal']), 'PICTURE_URL' => $row['picture_url'], 'OWNER' => is_null($row['owner']) ? '' : strval($row['owner']))); return $tpl; } $urls = get_url('url', 'pic', 'uploads/ocworld', 0, OCP_UPLOAD_IMAGE); edit_room_wrap($member_id, $name, post_param('text'), post_param('password_question'), post_param('password_answer'), post_param('password_fail_message'), post_param('required_item'), post_param_integer('locked_up', 0), post_param_integer('locked_down', 0), post_param_integer('locked_right', 0), post_param_integer('locked_left', 0), $urls[0], post_param_integer('allow_portal', 0), grab_new_owner('new_owner'), post_param_integer('new_x'), post_param_integer('new_y'), post_param_integer('new_realm')); } if ($command == 'editrealm') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { list($realm, , ) = get_loc_details($member_id); $rows = $GLOBALS['SITE_DB']->query_select('w_realms', array('*'), array('id' => $realm), '', 1); if (!array_key_exists(0, $rows)) { ocw_refresh_with_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn'); } $row = $rows[0]; $qatc = new ocp_tempcode(); for ($i = 1; $i <= 30; $i++) { $qatc->attach(do_template('W_REALM_SCREEN_QUESTION', array('_GUID' => '0510427a3895969dede2bd13db7d46a6', 'I' => strval($i), 'Q' => $row['q' . strval($i)], 'A' => $row['a' . strval($i)]))); } $tpl = do_template('W_REALM_SCREEN', array('_GUID' => 'f2503e0be6e45a296baa8625cafb4d72', 'TITLE' => get_page_title('W_EDIT_REALM_TITLE'), 'PAGE_TYPE' => 'editrealm', 'OWNER' => is_null($row['owner']) ? '' : strval($row['owner']), 'QA' => $qatc, 'NAME' => $row['name'], 'TROLL_NAME' => $row['troll_name'], 'PRIVATE' => strval($row['r_private']))); return $tpl; } for ($i = 1; $i <= 30; $i++) { $qa[$i]['q'] = post_param('question' . strval($i)); $qa[$i]['a'] = post_param('answer' . strval($i)); } edit_realm_wrap($member_id, $name, post_param('troll_name'), $qa, post_param_integer('private', 0), grab_new_owner('new_owner')); } if ($command == 'editportal') { require_code('ocworld_action'); $name = post_param('name', ''); if ($name == '') { list($realm, $x, $y) = get_loc_details($member_id); $end_realm = get_param_integer('param'); $rows = $GLOBALS['SITE_DB']->query_select('w_portals', array('*'), array('start_location_x' => $x, 'start_location_y' => $y, 'start_location_realm' => $realm, 'end_location_realm' => $end_realm), '', 1); if (!array_key_exists(0, $rows)) { ocw_refresh_with_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn'); } $row = $rows[0]; $tpl = do_template('W_PORTAL_SCREEN', array('_GUID' => 'cad0e01c1c4c410e67b775c3ff6eeb3a', 'TITLE' => get_page_title('W_EDIT_PORTAL_TITLE'), 'PAGE_TYPE' => 'editportal', 'X' => strval($x), 'Y' => strval($y), 'REALM' => strval($realm), 'PARAM' => $param, 'NAME' => $row['name'], 'PORTAL_TEXT' => $row['p_text'], 'END_LOCATION_REALM' => strval($end_realm), 'END_LOCATION_X' => strval($row['end_location_x']), 'END_LOCATION_Y' => strval($row['end_location_y']), 'OWNER' => is_null($row['owner']) ? '' : strval($row['owner']))); return $tpl; } edit_portal_wrap($member_id, intval($param), $name, post_param('text'), post_param_integer('end_location_realm'), post_param_integer('end_location_x'), post_param_integer('end_location_y'), grab_new_owner('new_owner'), post_param_integer('new_x'), post_param_integer('new_y'), post_param_integer('new_realm')); } if ($command == 'room') { return output_room_screen($member_id); } ocw_refresh_with_message(do_lang('SUCCESS')); return new ocp_tempcode(); }
/** * AJAX script to tell if data has been changed. */ function change_detection_script() { header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past header('Content-type: text/plain; charset=' . get_charset()); $page = get_param('page'); require_code('hooks/systems/change_detection/' . filter_naughty($page), true); $refresh_if_changed = either_param('refresh_if_changed'); $object = object_factory('Hook_' . $page); $result = $object->run($refresh_if_changed); echo $result ? '1' : '0'; }
/** * The UI to confirm deletion of a page. * * @return tempcode The UI */ function _delete() { $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/deletepage'; $hidden = new ocp_tempcode(); $file = new ocp_tempcode(); $zone = either_param('zone'); $pages = array(); require_code('site'); foreach ($_REQUEST as $key => $val) { if (substr($key, 0, 6) == 'page__' && $val === '1') { $page = substr($key, 6); $page_details = _request_page($page, $zone, NULL, NULL, true); if ($page_details === false) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $pages[$page] = strtolower($page_details[0]); } } foreach ($pages as $page => $type) { if (is_integer($page)) { $page = strval($page); } if (either_param_integer('page__' . $page, 0) == 1) { $hidden->attach(form_input_hidden('page__' . $page, '1')); if (!$file->is_empty()) { $file->attach(do_lang_tempcode('LIST_SEP')); } $file->attach(do_lang_tempcode('ZONE_WRITE', escape_html($zone), escape_html($page))); if (get_file_base() != get_custom_file_base() && $type != 'comcode_custom') { warn_exit(do_lang_tempcode('SHARED_INSTALL_PROHIBIT')); } } } $title = get_page_title('DELETE_PAGES'); $url = build_url(array('page' => '_SELF', 'type' => '__delete'), '_SELF'); $text = do_lang_tempcode('CONFIRM_DELETE', escape_html($file)); breadcrumb_set_self(do_lang_tempcode('CONFIRM')); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('PAGES')), array('_SELF:_SELF:delete', do_lang_tempcode('DELETE_PAGES')))); $hidden->attach(form_input_hidden('zone', $zone)); return do_template('YESNO_SCREEN', array('_GUID' => 'f732bb10942759c6ca5771d2d446c333', 'TITLE' => $title, 'HIDDEN' => $hidden, 'TEXT' => $text, 'URL' => $url)); }
/** * Shows an HTML page for making block Comcode. */ function block_helper_script() { require_lang('comcode'); require_lang('blocks'); require_code('zones2'); require_code('zones3'); check_specific_permission('comcode_dangerous'); $title = get_page_title('BLOCK_HELPER'); require_code('form_templates'); require_all_lang(); $type_wanted = get_param('block_type', 'main'); $type = get_param('type', 'step1'); $content = new ocp_tempcode(); if ($type == 'step1') { // Find what addons all our block files are in, and icons if possible $hooks = find_all_hooks('systems', 'addon_registry'); $hook_keys = array_keys($hooks); $hook_files = array(); foreach ($hook_keys as $hook) { $path = get_file_base() . '/sources_custom/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; if (!file_exists($path)) { $path = get_file_base() . '/sources/hooks/systems/addon_registry/' . filter_naughty_harsh($hook) . '.php'; } $hook_files[$hook] = file_get_contents($path); } unset($hook_keys); $addon_icons = array(); $addons_blocks = array(); foreach ($hook_files as $addon_name => $hook_file) { $matches = array(); if (preg_match('#function get_file_list\\(\\)\\s*\\{([^\\}]*)\\}#', $hook_file, $matches) != 0) { if (!defined('HIPHOP_PHP')) { $addon_files = eval($matches[1]); } else { require_code('hooks/systems/addon_registry/' . $addon_name); $hook_ob = object_factory('Hook_addon_registry_' . $addon_name); $addon_files = $hook_ob->get_file_list(); } foreach ($addon_files as $file) { if (substr($file, 0, 31) == 'themes/default/images/bigicons/' && !array_key_exists($addon_name, $addon_icons)) { $addon_icons[$addon_name] = find_theme_image('bigicons/' . basename($file, '.png'), false, true); } if (substr($file, 0, 21) == 'sources_custom/blocks/' || substr($file, 0, 15) == 'sources/blocks/') { if ($addon_name == 'staff_messaging') { $addon_name = 'core_feedback_features'; } $addons_blocks[basename($file, '.php')] = $addon_name; } } } } // Find where blocks have been used $block_usage = array(); $zones = find_all_zones(false, true); foreach ($zones as $_zone) { $zone = $_zone[0]; $pages = find_all_pages_wrap($zone, true); foreach ($pages as $filename => $type) { if (substr(strtolower($filename), -4) == '.txt') { $matches = array(); $contents = file_get_contents(zone_black_magic_filterer((substr($type, 0, 15) == 'comcode_custom/' ? get_custom_file_base() : get_file_base()) . '/' . ($zone == '' ? '' : $zone . '/') . 'pages/' . $type . '/' . $filename)); //$fallback=get_file_base().'/'.(($zone=='')?'':($zone.'/')).'pages/comcode/'.fallback_lang().'/'.$filename; //if (file_exists($fallback)) $contents.=file_get_contents($fallback); $num_matches = preg_match_all('#\\[block[^\\]]*\\](.*)\\[/block\\]#U', $contents, $matches); for ($i = 0; $i < $num_matches; $i++) { $block_used = $matches[1][$i]; if (!array_key_exists($block_used, $block_usage)) { $block_usage[$block_used] = array(); } $block_usage[$block_used][] = $zone . ':' . basename($filename, '.txt'); } } } } // Show block list $links = new ocp_tempcode(); $blocks = find_all_blocks(); $dh = @opendir(get_file_base() . '/sources_custom/miniblocks'); if ($dh !== false) { while (($file = readdir($dh)) !== false) { if (substr($file, -4) == '.php' && preg_match('#^[\\w\\-]*$#', substr($file, 0, strlen($file) - 4)) != 0) { $blocks[substr($file, 0, strlen($file) - 4)] = 'sources_custom'; } } closedir($dh); } $block_types = array(); $block_types_icon = array(); $keep = symbol_tempcode('KEEP'); foreach (array_keys($blocks) as $block) { if (array_key_exists($block, $addons_blocks)) { $addon_name = $addons_blocks[$block]; $addon_icon = array_key_exists($addon_name, $addon_icons) ? $addon_icons[$addon_name] : NULL; $addon_name = preg_replace('#^core\\_#', '', $addon_name); } else { $addon_name = NULL; $addon_icon = NULL; } $this_block_type = is_null($addon_name) || strpos($addon_name, 'block') !== false || $addon_name == 'core' ? substr($block, 0, strpos($block, '_') === false ? strlen($block) : strpos($block, '_')) : $addon_name; if (!array_key_exists($this_block_type, $block_types)) { $block_types[$this_block_type] = new ocp_tempcode(); } if (!is_null($addon_icon)) { $block_types_icon[$this_block_type] = $addon_icon; } $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false); $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false); if (is_null($block_description)) { $block_description = ''; } if (is_null($block_use)) { $block_use = ''; } $descriptiont = $block_description == '' && $block_use == '' ? new ocp_tempcode() : do_lang_tempcode('BLOCK_HELPER_1X', $block_description, $block_use); $url = find_script('block_helper') . '?type=step2&block=' . urlencode($block) . '&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $url .= '&utheme=' . get_param('utheme'); } $url .= '&block_type=' . $type_wanted; $link_caption = do_lang_tempcode('NICE_BLOCK_NAME', escape_html(cleanup_block_name($block)), $block); $usage = array_key_exists($block, $block_usage) ? $block_usage[$block] : array(); $block_types[$this_block_type]->attach(do_template('BLOCK_HELPER_BLOCK_CHOICE', array('USAGE' => $usage, 'DESCRIPTION' => $descriptiont, 'URL' => $url, 'LINK_CAPTION' => $link_caption))); } /*if (array_key_exists($type_wanted,$block_types)) We don't do this now, as we structure by addon name { $x=$block_types[$type_wanted]; unset($block_types[$type_wanted]); $block_types=array_merge(array($type_wanted=>$x),$block_types); }*/ ksort($block_types); // We sort now instead $move_after = $block_types['adminzone_frontpage']; unset($block_types['adminzone_frontpage']); $block_types['adminzone_frontpage'] = $move_after; foreach ($block_types as $block_type => $_links) { switch ($block_type) { case 'side': case 'main': case 'bottom': $type_title = do_lang_tempcode('BLOCKS_TYPE_' . $block_type); $img = NULL; break; default: $type_title = do_lang_tempcode('BLOCKS_TYPE_ADDON', escape_html(cleanup_block_name($block_type))); $img = array_key_exists($block_type, $block_types_icon) ? $block_types_icon[$block_type] : NULL; break; } $links->attach(do_template('BLOCK_HELPER_BLOCK_GROUP', array('IMG' => $img, 'TITLE' => $type_title, 'LINKS' => $_links))); } $content = do_template('BLOCK_HELPER_START', array('_GUID' => 'd2d6837cdd8b19d80ea95ab9f5d09c9a', 'GET' => true, 'TITLE' => $title, 'LINKS' => $links)); } elseif ($type == 'step2') { require_code('comcode_text'); $defaults = parse_single_comcode_tag(get_param('parse_defaults', '', true), 'block'); $block = trim(get_param('block')); $title = get_page_title('_BLOCK_HELPER', true, array(escape_html($block))); $fields = new ocp_tempcode(); $parameters = get_block_parameters($block); $parameters[] = 'failsafe'; $parameters[] = 'cache'; $parameters[] = 'quick_cache'; if (!isset($defaults['cache'])) { $defaults['cache'] = block_cache_default($block); } if (is_null($parameters)) { $parameters = array(); } $advanced_ind = do_lang('BLOCK_IND_ADVANCED'); $param_classes = array('normal' => array(), 'advanced' => array()); foreach ($parameters as $parameter) { $param_class = 'normal'; if ($parameter == 'cache' || $parameter == 'quick_cache' || $parameter == 'failsafe' || strpos(do_lang('BLOCK_' . $block . '_PARAM_' . $parameter), $advanced_ind) !== false) { $param_class = 'advanced'; } $param_classes[$param_class][] = $parameter; } foreach ($param_classes as $param_class => $parameters) { if (count($parameters) == 0) { if ($param_class == 'normal') { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('PARAMETERS'), 'HELP' => protect_from_escaping(paragraph(do_lang_tempcode('BLOCK_HELPER_NO_PARAMETERS'), '', 'nothing_here'))))); } continue; } if ($param_class == 'advanced') { $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => true, 'TITLE' => do_lang_tempcode('ADVANCED')))); } foreach ($parameters as $parameter) { $matches = array(); switch ($parameter) { case 'quick_cache': case 'cache': case 'failsafe': $description = do_lang('BLOCK_PARAM_' . $parameter); break; default: $description = do_lang('BLOCK_' . $block . '_PARAM_' . $parameter); break; } $description = str_replace(do_lang('BLOCK_IND_STRIPPABLE_1'), '', $description); $description = trim(str_replace(do_lang('BLOCK_IND_ADVANCED'), '', $description)); // Work out default value for field $default = ''; if (preg_match('#' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\']#Ui', $description, $matches) != 0) { $default = $matches[1]; $has_default = true; $description = preg_replace('#\\s*' . do_lang('BLOCK_IND_DEFAULT') . ': ["\']([^"]*)["\'](?-U)\\.?(?U)#Ui', '', $description); } else { $has_default = false; } if (isset($defaults[$parameter])) { $default = $defaults[$parameter]; $has_default = true; } // Show field if ($block . ':' . $parameter == 'side_stored_menu:type') { $matches = array(); $dh = opendir(get_file_base() . '/themes/default/templates/'); $options = array(); while (($file = readdir($dh)) !== false) { if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0) { $options[] = $matches[1]; } } closedir($dh); $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom/'); while (($file = readdir($dh)) !== false) { if (preg_match('^MENU\\_([a-z]+)\\.tpl$^', $file, $matches) != 0 && !file_exists(get_file_base() . '/themes/default/templates/' . $file)) { $options[] = $matches[1]; } } closedir($dh); sort($options); $list = new ocp_tempcode(); foreach ($options as $option) { $list->attach(form_input_list_entry($option, $has_default && $option == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'side_stored_menu:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('menu_items', array('DISTINCT i_menu'), NULL, 'ORDER BY i_menu'); foreach ($rows as $row) { $list->attach(form_input_list_entry($row['i_menu'], $has_default && $row['i_menu'] == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'side_shoutbox:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'room_name'), array('is_im' => 0), '', 100); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, $row['room_name'])); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'main_poll:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('poll', array('id', 'question'), NULL, 'ORDER BY id DESC', 100); $list->attach(form_input_list_entry('', false, do_lang('NA'))); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['question']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($block . ':' . $parameter == 'main_awards:param') { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('award_types', array('id', 'a_title')); foreach ($rows as $row) { $list->attach(form_input_list_entry(strval($row['id']), $has_default && strval($row['id']) == $default, get_translated_text($row['a_title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'zone' || $parameter == 'param' && $block == 'main_as_zone_access') { $list = new ocp_tempcode(); $list->attach(form_input_list_entry('_SEARCH', $default == '')); $list->attach(nice_get_zones($default == '' ? NULL : $default)); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (($parameter == 'forum' || $parameter == 'param' && in_array($block, array('main_forum_topics'))) && get_forum_type() == 'ocf') { require_code('ocf_forums'); require_code('ocf_forums2'); if (!addon_installed('ocf_forum')) { warn_exit(do_lang_tempcode('NO_FORUM_INSTALLED')); } $list = ocf_get_forum_tree_secure(NULL, NULL, true, explode(',', $default)); $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list)); } elseif ($parameter == 'param' && in_array($block, array('side_root_galleries', 'main_gallery_tease', 'main_gallery_embed', 'main_image_fader'))) { require_code('galleries'); $list = nice_get_gallery_tree($default); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_download_category'))) { require_code('downloads'); $list = nice_get_download_category_tree($default == '' ? NULL : intval($default)); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_contact_catalogues')) || $parameter == 'catalogue' && in_array($block, array('main_recent_cc_entries'))) { require_code('catalogues'); $list = nice_get_catalogues($default, false); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_cc_embed')) && $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)') < 500) { $list = new ocp_tempcode(); $categories = $GLOBALS['SITE_DB']->query_select('catalogue_categories', array('id', 'cc_title', 'c_name'), NULL, 'ORDER BY c_name,id'); $last_cat = mixed(); foreach ($categories as $cat) { if (is_null($last_cat) || $cat['c_name'] != $last_cat) { $list->attach(form_input_list_entry($cat['c_name'], $has_default && $cat['c_name'] == $default, $cat['c_name'], false, true)); $last_cat = $cat['c_name']; } $list->attach(form_input_list_entry(strval($cat['id']), $has_default && strval($cat['id']) == $default, get_translated_text($cat['cc_title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_banner_wave', 'main_topsites'))) { require_code('banners'); $list = nice_get_banner_types($default); $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'param' && in_array($block, array('main_newsletter_signup'))) { $list = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('newsletters', array('id', 'title')); foreach ($rows as $newsletter) { $list->attach(form_input_list_entry(strval($newsletter['id']), $has_default && strval($newsletter['id']) == $default, get_translated_text($newsletter['title']))); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif ($parameter == 'filter' && in_array($block, array('bottom_news', 'main_news', 'side_news', 'side_news_archive'))) { require_code('news'); $list = nice_get_news_categories($default == '' ? -1 : intval($default)); $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list)); } elseif ($parameter == 'font') { $fonts = array(); $dh = opendir(get_file_base() . '/data/fonts'); while ($f = readdir($dh)) { if (substr($f, -4) == '.ttf') { $fonts[] = substr($f, 0, strlen($f) - 4); } } closedir($dh); $dh = opendir(get_custom_file_base() . '/data_custom/fonts'); while ($f = readdir($dh)) { if (substr($f, -4) == '.ttf') { $fonts[] = substr($f, 0, strlen($f) - 4); } } closedir($dh); $fonts = array_unique($fonts); sort($fonts); $list = new ocp_tempcode(); foreach ($fonts as $font) { $list->attach(form_input_list_entry($font, $font == $default)); } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (preg_match('#' . do_lang('BLOCK_IND_EITHER') . ' (.+)#i', $description, $matches) != 0) { $description = preg_replace('# \\(' . do_lang('BLOCK_IND_EITHER') . '.*\\)#U', '', $description); $list = new ocp_tempcode(); $matches2 = array(); $num_matches = preg_match_all('#\'([^\']*)\'="([^"]*)"#', $matches[1], $matches2); if ($num_matches != 0) { for ($i = 0; $i < $num_matches; $i++) { $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default, $matches2[2][$i])); } } else { $num_matches = preg_match_all('#\'([^\']*)\'#', $matches[1], $matches2); for ($i = 0; $i < $num_matches; $i++) { $list->attach(form_input_list_entry($matches2[1][$i], $matches2[1][$i] == $default)); } } $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } elseif (preg_match('#\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', $description, $matches) != 0) { $description = preg_replace('#\\s*\\(' . do_lang('BLOCK_IND_HOOKTYPE') . ': \'([^\'/]*)/([^\'/]*)\'\\)#i', '', $description); $list = new ocp_tempcode(); $hooks = find_all_hooks($matches[1], $matches[2]); ksort($hooks); if ($default == '' && $has_default) { $list->attach(form_input_list_entry('', true)); } foreach (array_keys($hooks) as $hook) { if ($block == 'side_tag_cloud') { if (substr($hook, -1) == 'y') { $hook .= ',' . substr($hook, 0, strlen($hook) - 1) . 'ies'; } elseif (substr($hook, -1) != 's' && $hook != 'quiz') { $hook .= ',' . $hook . 's'; } } $list->attach(form_input_list_entry($hook, $hook == $default)); } if ($block == 'main_search' && $parameter == 'limit_to' || $block == 'side_tag_cloud') { $fields->attach(form_input_multi_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, 0)); } else { $fields->attach(form_input_list(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $list, NULL, false, false)); } } elseif (($default == '0' || $default == '1' || strpos($description, '\'0\'') !== false || strpos($description, '\'1\'') !== false) && do_lang('BLOCK_IND_WHETHER') != '' && strpos(strtolower($description), do_lang('BLOCK_IND_WHETHER')) !== false) { $fields->attach(form_input_tick(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '1')); } elseif (do_lang('BLOCK_IND_NUMERIC') != '' && strpos($description, do_lang('BLOCK_IND_NUMERIC')) !== false) { $fields->attach(form_input_integer(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default == '' ? NULL : intval($default), false)); } else { $fields->attach(form_input_line(ucwords(str_replace('_', ' ', $parameter)), escape_html($description), $parameter, $default, false)); } } } $keep = symbol_tempcode('KEEP'); $post_url = find_script('block_helper') . '?type=step3&field_name=' . get_param('field_name') . $keep->evaluate(); if (get_param('utheme', '') != '') { $post_url .= '&utheme=' . get_param('utheme'); } $post_url .= '&block_type=' . $type_wanted; if (get_param('save_to_id', '') != '') { $post_url .= '&save_to_id=' . urlencode(get_param('save_to_id')); $submit_name = do_lang_tempcode('SAVE'); // Allow remove option $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => false, 'TITLE' => do_lang_tempcode('ACTIONS'), 'HELP' => ''))); $fields->attach(form_input_tick(do_lang_tempcode('REMOVE'), '', '_delete', false)); } else { $submit_name = do_lang_tempcode('USE'); } $block_description = do_lang('BLOCK_' . $block . '_DESCRIPTION', NULL, NULL, NULL, NULL, false); if (is_null($block_description)) { $block_description = ''; } $block_use = do_lang('BLOCK_' . $block . '_USE', NULL, NULL, NULL, NULL, false); if (is_null($block_use)) { $block_use = ''; } if ($block_description == '' && $block_use == '') { $text = new ocp_tempcode(); } else { $text = do_lang_tempcode('BLOCK_HELPER_2', escape_html(cleanup_block_name($block)), escape_html($block_description), escape_html($block_use)); } $hidden = form_input_hidden('block', $block); $content = do_template('FORM_SCREEN', array('_GUID' => '270058349d048a8be6570bba97c81fa2', 'TITLE' => $title, 'TARGET' => '_self', 'SKIP_VALIDATION' => true, 'FIELDS' => $fields, 'URL' => $post_url, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'HIDDEN' => $hidden, 'PREVIEW' => true, 'THEME' => $GLOBALS['FORUM_DRIVER']->get_theme())); if ($fields->is_empty()) { $type = 'step3'; } } if ($type == 'step3') { require_javascript('javascript_posting'); require_javascript('javascript_editing'); $field_name = get_param('field_name'); $bparameters = ''; $bparameters_xml = ''; $bparameters_tempcode = ''; $block = trim(either_param('block')); $parameters = get_block_parameters($block); $parameters[] = 'failsafe'; $parameters[] = 'cache'; $parameters[] = 'quick_cache'; if (in_array('param', $parameters)) { $_parameters = array('param'); unset($parameters[array_search('param', $parameters)]); $parameters = array_merge($_parameters, $parameters); } foreach ($parameters as $parameter) { $value = post_param($parameter, NULL); if (is_null($value)) { if (post_param_integer('tick_on_form__' . $parameter, NULL) === NULL) { continue; } // If not on form, continue, otherwise must be 0 $value = '0'; } if ($value != '' && ($parameter != 'failsafe' || $value == '1') && ($parameter != 'cache' || $value != block_cache_default($block)) && ($parameter != 'quick_cache' || $value == '1')) { if ($parameter == 'param') { $bparameters .= '="' . str_replace('"', '\\"', $value) . '"'; } else { $bparameters .= ' ' . $parameter . '="' . str_replace('"', '\\"', $value) . '"'; } $bparameters_xml = '<blockParam key="' . escape_html($parameter) . '" val="' . escape_html($value) . '" />'; $bparameters_tempcode .= ',' . $parameter . '=' . str_replace(',', '\\,', $value); } } $comcode = '[block' . $bparameters . ']' . $block . '[/block]'; $comcode_xml = '<block>' . $bparameters_xml . $block . '</block>'; $tempcode = '{$BLOCK,block=' . $block . $bparameters_tempcode . '}'; if ($type_wanted == 'template') { $comcode = $tempcode; } // This is what will be written in $comcode_semihtml = comcode_to_tempcode($comcode, NULL, false, 60, NULL, NULL, true, false, false); $content = do_template('BLOCK_HELPER_DONE', array('_GUID' => '575d6c8120d6001c8156560be518f296', 'TITLE' => $title, 'FIELD_NAME' => $field_name, 'BLOCK' => $block, 'COMCODE_XML' => $comcode_xml, 'COMCODE' => $comcode, 'COMCODE_SEMIHTML' => $comcode_semihtml)); } global $EXTRA_HEAD; if (!isset($EXTRA_HEAD)) { $EXTRA_HEAD = new ocp_tempcode(); } $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML $echo = do_template('POPUP_HTML_WRAP', array('TITLE' => do_lang_tempcode('BLOCK_HELPER'), 'CONTENT' => $content)); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); }
/** * High-level messages script handling */ function messages_script() { get_page_title('', false); // Force session time to be updated // Closed site $site_closed = get_option('site_closed'); if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) { header('Content-Type: text/plain'); @exit(get_option('closed')); } // Check we are allowed here //if (!has_actual_page_access(get_member(),'chat')) access_denied('PAGE_ACCESS'); Actually we'll use room permissions for that; don't want to block the shoutbox // Check the action $action = get_param('action', 'new'); if ($action == 'all') { // Getting all messages (i.e. up to five minutes ago) _chat_messages_script_ajax(either_param_integer('room_id'), true); } elseif ($action == 'post') { // Posting a message convert_data_encodings(true); $message = either_param('message'); _chat_post_message_ajax(either_param_integer('room_id'), $message, post_param('font', ''), post_param('colour', ''), post_param_integer('first_message', 0)); } elseif ($action == 'start_im') { require_lang('chat'); $people = get_param('people'); if ($people == '') { exit; } require_code('chat2'); if (strpos($people, ',') === false) { $room_name = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); } else { $room_name = do_lang('IM_MULTI', $GLOBALS['FORUM_DRIVER']->get_username(get_member())); } add_chatroom('', $room_name, get_member(), filter_invites_for_blocking(strval(get_member()) . ',' . $people), '', '', '', user_lang(), 1); // Send response of new messages, so we get instant result _chat_messages_script_ajax(-2, false, either_param_integer('message_id'), either_param_integer('event_id')); } elseif ($action == 'join_im') { $room_id = get_param_integer('room_id'); $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'is_im', 'c_welcome', 'allow_list_groups', 'disallow_list_groups', 'allow_list', 'disallow_list', 'room_owner'), array('id' => $room_id), '', 1); if (!array_key_exists(0, $room_check)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } if (!check_chatroom_access($room_check[0], true, NULL, true)) { return; } // Possibly the room was closed already $event_id = $GLOBALS['SITE_DB']->query_insert('chat_events', array('e_type_code' => 'JOIN_IM', 'e_member_id' => get_member(), 'e_room_id' => $room_id, 'e_date_and_time' => time()), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); fwrite($myfile, strval($event_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); // Catch up the current user so that they know who else is in the room just joined... $events_output = ''; $peoplea = explode(',', $room_check[0]['allow_list']); foreach ($peoplea as $person) { $person = trim($person); if ($person == '') { continue; } $member_id = intval($person); if ($member_id != get_member()) { $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id); $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id); if (!is_null($username)) { $events_output .= '<chat_event event_type="PREINVITED_TO_IM" away="' . (chatter_active($member_id) ? '0' : '1') . '" member_id="' . strval($member_id) . '" username="******" avatar_url="' . xmlentities($avatar_url) . '" room_id="' . strval($room_id) . '"></chat_event>'; } } } _chat_messages_script_ajax(-1, false, -1, either_param_integer('event_id'), $events_output); } elseif ($action == 'deinvolve_im') { $room_id = get_param_integer('room_id'); $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'is_im', 'c_welcome', 'allow_list_groups', 'disallow_list_groups', 'allow_list', 'disallow_list', 'room_owner'), array('id' => $room_id), '', 1); if (!array_key_exists(0, $room_check)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } if (!check_chatroom_access($room_check[0], true, NULL, true)) { return; } // Possibly the room was closed already $allow_list = str_replace(',' . strval(get_member()) . ',', ',', ',' . $room_check[0]['allow_list'] . ','); $allow_list = substr($allow_list, 1, strlen($allow_list) - 2); $event_id = $GLOBALS['SITE_DB']->query_insert('chat_events', array('e_type_code' => 'DEINVOLVE_IM', 'e_member_id' => get_member(), 'e_room_id' => $room_id, 'e_date_and_time' => time()), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); fwrite($myfile, strval($event_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); if ($allow_list == '') { require_code('chat2'); delete_chatroom($room_id); } else { $peoplea = explode(',', $allow_list); $room_owner = $room_check[0]['room_owner']; if ($room_owner == get_member()) { $room_owner = intval($peoplea[0]); } $GLOBALS['SITE_DB']->query_update('chat_rooms', array('room_owner' => $room_owner, 'allow_list' => $allow_list), array('id' => $room_id), '', 1); } } elseif ($action == 'invite_im') { $room_id = get_param_integer('room_id'); $people = get_param('people'); if ($people == '') { exit; } foreach (explode(',', $people) as $person) { $person = trim($person); if ($person == '') { continue; } $event_id = $GLOBALS['SITE_DB']->query_insert('chat_events', array('e_type_code' => 'PREINVITED_TO_IM', 'e_member_id' => intval($person), 'e_room_id' => $room_id, 'e_date_and_time' => time()), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); fwrite($myfile, strval($event_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_event.dat'); } $room_check = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('id', 'is_im', 'c_welcome', 'allow_list_groups', 'disallow_list_groups', 'allow_list', 'disallow_list', 'room_owner'), array('id' => $room_id), '', 1); if (!array_key_exists(0, $room_check)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } if (!check_chatroom_access($room_check[0], true, NULL, true)) { return; } // Possibly the room was closed already $allow_list = $room_check[0]['allow_list']; $_people = $allow_list . ',' . filter_invites_for_blocking($people); $GLOBALS['SITE_DB']->query_update('chat_rooms', array('allow_list' => $_people), array('id' => $room_id), '', 1); } else { // Getting all new messages (i.e. up to our last refresh time) _chat_messages_script_ajax(either_param_integer('room_id'), false, either_param_integer('message_id'), either_param_integer('event_id')); } }
/** * The UI to show submission rates. * * @return tempcode The UI */ function submission_rates() { //Like the users online above, we need to use a nice scatter graph $title = get_page_title('SUBMISSION_STATISTICS'); $start = get_param_integer('start', 0); $max = get_param_integer('max', 50); // Intentionally the browse is disabled, as the graph will show all - we fudge $max_rows to $i $csv = get_param_integer('csv', 0) == 1; if ($csv) { if (function_exists('set_time_limit')) { @set_time_limit(0); } $start = 0; $max = 10000; } $sortables = array('date_and_time' => do_lang_tempcode('DATE_TIME')); $test = explode(' ', either_param('sort', 'date_and_time DESC')); if (count($test) == 1) { $test[1] = 'DESC'; } list($sortable, $sort_order) = $test; if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) { log_hack_attack_and_exit('ORDERBY_HACK'); } global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'sort'; $rows = $GLOBALS['SITE_DB']->query_select('adminlogs', array('date_and_time', 'COUNT(*) AS cnt'), NULL, 'GROUP BY date_and_time ORDER BY ' . $sortable . ' ' . $sort_order, 3000); if (count($rows) < 1) { return warn_screen($title, do_lang_tempcode('NO_DATA')); } //$max_rows=$GLOBALS['SITE_DB']->query_value('adminlogs','COUNT(DISTINCT date_and_time)'); Cannot do this as the DB does not do all the processing $data = array(); $base = $rows[0]['date_and_time']; foreach ($rows as $value) { $date = get_timezoned_date($value['date_and_time'], false); $t = $value['date_and_time'] - $base; if ($t < 0) { $t = 0 - $t; } if (count($data) == 0 || $data[count($data) - 1]['key'] != $date) { $data[] = array('t' => $t, 'key' => $date, 'value' => $value['cnt']); } else { $data[count($data) - 1]['value'] += $value['cnt']; } } require_code('templates_results_table'); $fields_title = results_field_title(array(do_lang_tempcode('DATE_TIME'), do_lang_tempcode('PEAK')), $sortables, 'sort', $sortable . ' ' . $sort_order); $fields = new ocp_tempcode(); $real_data = array(); for ($i = 0; $i < $max; $i++) { if (!array_key_exists($i, $data)) { continue; } $real_data[] = array('Date/Time' => $data[$i]['key'], 'Tally' => $data[$i]['value']); $fields->attach(results_entry(array($data[$i]['key'], integer_format($data[$i]['value'])), true)); } $list = results_table(do_lang_tempcode('SUBMISSION_STATISTICS'), $start, 'start', $max, 'max', $i, $fields_title, $fields, $sortables, $sortable, $sort_order, 'sort', new ocp_tempcode()); if ($csv) { make_csv($real_data, 'submission_rates.csv'); } $output = create_scatter_graph($data, do_lang('DATE'), do_lang('SUBMISSION_STATISTICS'), '', ''); $this->save_graph('Global-Submissions', $output); $graph = do_template('STATS_GRAPH', array('_GUID' => 'f6d5a58eae148a555e0f868eda245304', 'GRAPH' => get_custom_base_url() . '/data_custom/modules/admin_stats/Global-Submissions.xml', 'TITLE' => do_lang_tempcode('SUBMISSION_STATISTICS'), 'TEXT' => do_lang_tempcode('DESCRIPTION_SUBMISSION_STATISTICS'))); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('SITE_STATISTICS')))); return do_template('STATS_SCREEN', array('_GUID' => '66e8534ef342c1d0197f4ddb8f767025', 'TITLE' => $title, 'GRAPH' => $graph, 'STATS' => $list)); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_pages($db, $table_prefix, $file_base) { unset($db); unset($table_prefix); require_code('files2'); $files = @get_directory_contents($file_base); $theme = either_param('theme'); $convert_to_comcode = either_param_integer('convert_to_comcode', 0); $fix_html = either_param_integer('fix_html', 0); $base_url = either_param('base_url'); if (substr($base_url, -1) == '/') { $base_url = substr($base_url, 0, strlen($base_url) - 1); } // Find all htm/html/php files $content_files = array(); foreach ($files as $i => $file) { if (substr(strtolower($file), -4) == '.htm' || substr(strtolower($file), -5) == '.html' || substr(strtolower($file), -4) == '.php') { $content_files[] = $file; unset($files[$i]); } } if (count($content_files) == 0) { warn_exit(do_lang_tempcode('NO_PAGES_FOUND')); } // Discern new zones needed // Note: files in directories in a deep path will be considered in a zone name changed so underscores replace slashes $new_zones = array(); $current_zones = find_all_zones(); foreach ($content_files as $file) { $zone = str_replace('/', '_', dirname($file)); if ($zone == '.') { $zone = ''; } if (!in_array($zone, $current_zones)) { $new_zones[] = $zone; } } $new_zones = array_unique($new_zones); // (Maybe AFM needed here - if zones have to be created, and possibly .htaccess changed to incorporate zone names in the redirects) if (count($new_zones) != 0) { require_code('abstract_file_manager'); force_have_afm_details(); $change_htaccess = get_option('htm_short_urls') == '1'; $htaccess_path = get_file_base() . '/.htaccess'; if ($change_htaccess && file_exists($htaccess_path) && is_writable_wrap($htaccess_path)) { $htaccess = file_get_contents($htaccess_path); $htaccess = preg_replace('#\\(site\\|forum\\|adminzone\\|cms\\|collaboration[^\\)]*#', '${0}|' . implode('|', $new_zones), $htaccess); $myfile = fopen($htaccess_path, 'wt'); fwrite($myfile, $htaccess); fclose($myfile); fix_permissions($htaccess_path); sync_file($htaccess_path); } // Create new zones as needed (and set them to our chosen theme too) require_code('zones2'); foreach ($new_zones as $zone) { actual_add_zone($zone, ucwords(str_replace('_', ' ', $zone)), 'start', '', $theme, 0, 0); } } // Discern cruft in htm/html via looking for best levenshtein to length ratio over a few pages; scan by tag, not by byte $compare_file_contents = array(); shuffle($content_files); for ($i = 0; $i < min(2, count($content_files)); $i++) { $file_contents = file_get_contents($file_base . '/' . $content_files[$i]); $compare_file_contents[$content_files[$i]] = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base); } $cruft = array(); if (count($compare_file_contents) > 1) { $to_find = array(); if (file_exists($file_base . '/header.txt')) { $cruft['HEADER'] = $this->_html_filter(file_get_contents($file_base . '/header.txt'), $fix_html, $base_url, $files, $file_base); } else { $to_find[] = 'HEADER'; } if (file_exists($file_base . '/footer.txt')) { $cruft['FOOTER'] = $this->_html_filter(file_get_contents($file_base . '/footer.txt'), $fix_html, $base_url, $files, $file_base); } else { $to_find[] = 'FOOTER'; } foreach ($to_find as $template_wanted) { $best_ratios = array(); foreach ($compare_file_contents as $i => $reference_file) { if ($template_wanted == 'HEADER') { $last_pos = strpos($reference_file, '<body'); if ($last_pos === false) { $last_pos = 0; } else { $last_pos += 5; } } else { $last_pos = strlen($reference_file) - 1; } $best_av_ratios = mixed(); $ratios = array(); while ($last_pos !== false) { //@print('!'.(strlen($reference_file)-$last_pos).' '.$lv.' '.$ratio.'<br />'.chr(10));flush();if (@$dd++==180) @exit('fini'); // Useful for debugging if ($template_wanted == 'HEADER') { $next_pos = strpos($reference_file, '<', $last_pos); } else { $next_pos = strrpos(substr($reference_file, 0, $last_pos), '<'); } if ($next_pos !== false) { if ($template_wanted == 'HEADER') { $up_to = substr($reference_file, 0, $next_pos); } else { $up_to = substr($reference_file, $next_pos); } $all_ratios_for_pos = array(); foreach ($compare_file_contents as $j => $other_file) { if ($i != $j) { if ($template_wanted == 'HEADER') { $up_to_other_file = substr($other_file, 0, $next_pos); } else { $up_to_other_file = substr($other_file, $next_pos - (strlen($reference_file) - strlen($other_file))); } $lv = fake_levenshtein($up_to, $up_to_other_file); if ($template_wanted == 'HEADER') { $ratio = floatval($lv) * 3 - floatval($next_pos + 1); // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against. } else { $ratio = floatval($lv) * 3 - floatval(strlen($reference_file) - $next_pos); // We want this number to be as small as possible. We have multiplied the levenshtein distance because we care about that more than length (this number reached by experimentation); HTML has a low entropy which this number is fighting against. } $all_ratios_for_pos[] = $ratio; } } $av_ratios = array_sum($all_ratios_for_pos) / floatval(count($all_ratios_for_pos)); if (is_null($best_av_ratios) || $av_ratios < $best_av_ratios) { $best_av_ratios = $av_ratios; } elseif ($av_ratios > $best_av_ratios + 300) { break; } $ratios[$next_pos] = $av_ratios; if ($template_wanted == 'HEADER') { $next_pos++; } else { $next_pos--; } } $last_pos = $next_pos; } asort($ratios); $best_by_pos = array_keys($ratios); $best_ratios[] = array($best_by_pos[0], $ratios[$best_by_pos[0]], $reference_file); } $best = mixed(); $best_pos = NULL; $best_reference_file = NULL; foreach ($best_ratios as $bits) { list($pos, $ratio, $reference_file) = $bits; if (is_null($best) || $ratio < $best) { $best = $ratio; $best_pos = $pos; $best_reference_file = $reference_file; } } if ($template_wanted == 'HEADER') { $cruft[$template_wanted] = substr($best_reference_file, 0, $best_pos); } else { $cruft[$template_wanted] = substr($best_reference_file, $best_pos); } } } else { // We can't find any common consistency when we only have one, so we mark all cruft and then later we will actually assume GLOBAL.tpl does not change and the only header/footer bit is the logical one $cruft['HEADER'] = array_key_exists(0, $compare_file_contents) ? $compare_file_contents[0] : ''; $cruft['FOOTER'] = array_key_exists(1, $compare_file_contents) ? $compare_file_contents[0] : ''; } // Extract header from cruft (<body> and before); SAVE $header = $cruft['HEADER']; // special cases of something with ID or class of header/top going through too $header_cases = array('<div id="header"', '<div id="page_header"', '<div class="header"', '<div class="page_header"'); foreach ($header_cases as $header_case) { $header_start_pos = strpos($header, $header_case); if ($header_start_pos !== false) { $header_start_pos = strpos($header, '>', $header_start_pos) + 1; break; } } if ($header_start_pos !== false) { $div_count = 1; do { $next_start = strpos($header, '<div ', $header_start_pos); $next_end = strpos($header, '</div>', $header_start_pos); $header_start_pos = $next_start !== false && $next_start < $next_end ? $next_start : $next_end; if ($header_start_pos !== false) { $header_start_pos = strpos($header, '>', $header_start_pos) + 1; } $div_count += $next_start !== false && $next_start < $next_end ? 1 : -1; } while ($div_count > 0 && $header_start_pos !== false); } $body_start_pos = strpos($header, '<body'); $head_end_pos = strpos($header, '<link'); if ($head_end_pos === false) { $head_end_pos = strpos($header, '</head'); } if ($header_start_pos === false) { $header_start_pos = strpos($header, '>', $body_start_pos) + 1; } if ($header_start_pos !== false) { $header = substr($header, 0, $header_start_pos); } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/HEADER.tpl'; $myfile = fopen($path, 'wt'); $header_to_write = substr($header, 0, $head_end_pos) . ' <script type="text/javascript">// <![CDATA[ {+START,IF,{$AND,{$EQ,,{$_GET,keep_has_js}},{$NOT,{$JS_ON}}}} if ((window.location.href.indexOf(\'upgrader.php\')==-1) && (window.location.search.indexOf(\'keep_has_js\')==-1)) {$,Redirect with JS on, and then hopefully we can remove keep_has_js after one click. This code only happens if JS is marked off, no infinite loops can happen.} window.location=window.location.href+((window.location.search==\'\')?(((window.location.href.indexOf(\'.htm\')==-1)&&(window.location.href.indexOf(\'.php\')==-1))?(((window.location.href.substr(window.location.href.length-1)!=\'/\')?\'/\':\'\')+\'index.php?\'):\'?\'):\'&\')+\'keep_has_js=1{+START,IF,{$DEV_MODE}}&keep_devtest=1{+END}\'; {+END} {+START,IF,{$NOT,{$BROWSER_MATCHES,ie}}}{+START,IF,{$HAS_SPECIFIC_PERMISSION,sees_javascript_error_alerts}}window.take_errors=true;{+END}{+END} var {+START,IF,{$CONFIG_OPTION,is_on_timezone_detection}}server_timestamp={$FROM_TIMESTAMP%},{+END}ocp_lang=\'{$LANG;}\',ocp_theme=\'{$THEME;}\'; //]]></script> <meta name="description" content="{+START,IF,{$NEQ,{DESCRIPTION},{!NA}}}{DESCRIPTION*}{+END}" /> <meta name="keywords" content="{KEYWORDS*}" /> {$CSS_TEMPCODE} {+START,IF_PASSED,EXTRA_HEAD} {EXTRA_HEAD} {+END} {$JS_TEMPCODE,header} {REFRESH}' . substr($header, $head_end_pos); $header_to_write = preg_replace('#<title>[^<>]*</title>#', '<title>{+START,IF_NON_EMPTY,{HEADER_TEXT}}{HEADER_TEXT*} - {+END}{$SITE_NAME*}</title>', $header_to_write); $header_to_write = preg_replace('#<meta name="keywords" content="([^"]*)"[^>]*>#', '', $header_to_write); $header_to_write = preg_replace('#<meta name="description" content="([^"]*)"[^>]*>#', '', $header_to_write); fwrite($myfile, $header_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // Extract footer from cruft (</body> and below); SAVE $footer = $cruft['FOOTER']; // special cases of something with ID or class of footer/bottom going through too $footer_cases = array('<div id="footer"', '<div id="page_footer"', '<div class="footer"', '<div class="page_footer"'); foreach ($footer_cases as $footer_case) { $footer_start_pos = strpos($footer, $footer_case); if ($footer_start_pos !== false) { break; } } if ($footer_start_pos === false) { $footer_start_pos = strpos($footer, '</body'); } if ($footer_start_pos !== false) { $footer = substr($footer, $footer_start_pos); } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/FOOTER.tpl'; $myfile = fopen($path, 'wt'); $footer_to_write = $footer; fwrite($myfile, $footer_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // What remains is saved to GLOBAL (note that we don't try and be clever about panels - this is up to the user, and they don't really need them anyway) if (count($compare_file_contents) > 1) { $global_to_write = substr($cruft['HEADER'], strlen($header)) . "\n{MIDDLE}\n" . substr($cruft['FOOTER'], 0, strlen($cruft['FOOTER']) - strlen($footer)); } else { $cruft['HEADER'] = $header_to_write; $cruft['FOOTER'] = $footer_to_write; $global_to_write = '{MIDDLE}'; } $path = get_custom_file_base() . '/themes/' . filter_naughty($theme) . '/templates_custom/GLOBAL.tpl'; $myfile = fopen($path, 'wt'); fwrite($myfile, $global_to_write); fclose($myfile); fix_permissions($path); sync_file($path); // Extract site name from <title> tag, based on common consistency (largest common substring) $site_name = get_site_name(); if (count($compare_file_contents) > 1) { $titles_in_reference_files = array(); foreach ($compare_file_contents as $reference_file) { $matches = array(); if (preg_match('#<title>(.*)</title>#', $reference_file, $matches) != 0) { $titles_in_reference_files[] = $matches[1]; } } // Find largest common substring $lcs = ''; foreach ($titles_in_reference_files as $title_a) { for ($start = 0; $start < strlen($title_a); $start++) { for ($end = $start + 1; $end < strlen($title_a); $end++) { $current = substr($title_a, $start, $end - $start + 1); foreach ($titles_in_reference_files as $title_b) { if ($title_a != $title_b) { if (strpos(strtolower($title_b), strtolower($current)) === false) { continue 2; } } } if (strpos(strtolower($title_b), strtolower($current)) !== false) { if (strlen($current) > strlen($lcs)) { $lcs = $current; } } } } } // Strip bits $site_name = trim(preg_replace('#^[\\|\\-�,]#', '', preg_replace('#[\\|\\-�,]$#', '', trim($lcs)))); // Save as site name set_option('site_name', $site_name); } // Go and save our pages disable_php_memory_limit(); foreach ($content_files as $content_file) { $file_contents = file_get_contents($file_base . '/' . $content_file); // Find page-link for page $slash_count = substr_count($content_file, '/'); if ($slash_count == 0) { $content_file = '/' . $content_file; } elseif ($slash_count > 1) { $last_slash_pos = strrpos($content_file, '/'); $content_file = str_replace('/', '_', substr($content_file, 0, $last_slash_pos)) . substr($content_file, 0, $last_slash_pos); } list($zone, $page) = explode('/', preg_replace('#\\..*$#', '', $content_file), 2); if ($page == 'index') { $page = 'start'; } if (substr($content_file, -4) == '.php') { $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/minimodules_custom/' . $page . '.php'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, $file_contents); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } else { $filtered = $this->_html_filter($file_contents, $fix_html, $base_url, $files, $file_base); // Try and work out page title from <title> tag $matches = array(); $page_title = NULL; if (preg_match('#<title>(.*)</title>#', $filtered, $matches) != 0) { $page_title = preg_replace('#( [\\|\\-�] )?' . preg_quote($site_name) . '( [\\|\\-�] )?#', '', $matches[1]); } $page_keywords = NULL; if (preg_match('#<meta name="keywords" content="([^"]*)"#', $filtered, $matches) != 0) { $page_keywords = $matches[1]; } $page_description = NULL; if (preg_match('#<meta name="description" content="([^"]*)"#', $filtered, $matches) != 0) { $page_description = $matches[1]; } require_code('seo2'); seo_meta_set_for_explicit('comcode_page', $zone . ':' . $page, $page_keywords, $page_description); // Strip cruft off for htm/html files $i = strpos($filtered, '</head>'); if ($i === false) { $i = 0; } else { $i += 7; } $filtered = $this->levenshtein_strip_search($cruft['HEADER'], $filtered, false, $i); $filtered = $this->levenshtein_strip_search($cruft['FOOTER'], $filtered, true, 0); // Copy htm/html/php files to correct zone page directories (html_custom/<lang>, or minimodules_custom) if ($convert_to_comcode == 0) { // Insert an <h1> if the h1 is not there if (strpos($filtered, '<h1') === false && !is_null($page_title)) { $filtered = "<h1>" . $page_title . "</h1>\n\n" . $filtered; } $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, '[semihtml]' . $filtered . '[/semihtml]'); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } else { // Insert an <h1> if the h1 is not there if (strpos($filtered, '[title') === false && !is_null($page_title)) { $filtered = "[title]" . $page_title . "[/title]\n\n" . $filtered; } require_code('comcode_from_html'); $comcode = semihtml_to_comcode($filtered); $file_path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . get_site_default_lang() . '/' . $page . '.txt'); $myfile = fopen($file_path, 'wt'); fwrite($myfile, $comcode); fclose($myfile); fix_permissions($file_path); sync_file($file_path); } } } // Copy all remaining files to under uploads/website_specific foreach ($files as $file) { if (!file_exists($file_base . '/' . $file)) { continue; } $path = get_custom_file_base() . '/uploads/website_specific/' . $file; $create_path = $path; do { @mkdir(dirname($create_path), 0777); $create_path = dirname($create_path); } while (strlen($create_path) > 1); copy($file_base . '/' . $file, $path); fix_permissions($path); sync_file($path); } // Set the panels to be blank foreach (array('site/', '') as $zone) { $panels = array('panel_left', 'panel_right'); foreach ($panels as $panel) { $path = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . 'pages/comcode_custom/' . filter_naughty(fallback_lang()) . '/' . filter_naughty($panel) . '.txt'); $myfile = fopen($path, 'wt'); fclose($myfile); fix_permissions($path); sync_file($path); } } }
/** * UI to choose a language. * * @param tempcode Title for the form * @param boolean Whether to give a tip about edit order * @param boolean Whether to add an 'all' entry to the list * @return mixed The UI (tempcode) or the language to use (string/LANGUAGE_NAME) */ function choose_language($title, $tip = false, $allow_all_selection = false) { if (!multi_lang()) { return user_lang(); } $lang = either_param('lang', NULL); if (!is_null($lang)) { return filter_naughty($lang); } if (!$tip) { $text = do_lang_tempcode('CHOOSE_LANG_DESCRIP'); } else { global $LANGS_MAP; if ($LANGS_MAP === NULL) { $map_a = get_file_base() . '/lang/langs.ini'; $map_b = get_custom_file_base() . '/lang_custom/langs.ini'; if (!is_file($map_b)) { $map_b = $map_a; } $LANGS_MAP = better_parse_ini_file($map_b); } $lang_name = get_site_default_lang(); if (array_key_exists($lang_name, $LANGS_MAP)) { $lang_name = $LANGS_MAP[$lang_name]; } $text = do_lang_tempcode('CHOOSE_LANG_DESCRIP_ADD_TO_MAIN_LANG_FIRST', escape_html($lang_name)); } $langs = new ocp_tempcode(); if ($allow_all_selection) { $langs->attach(form_input_list_entry('', false, do_lang_tempcode('_ALL'))); } $langs->attach(nice_get_langs()); require_code('form_templates'); $fields = form_input_list(do_lang_tempcode('LANGUAGE'), do_lang_tempcode('DESCRIPTION_LANGUAGE'), 'lang', $langs, NULL, true); $hidden = build_keep_post_fields(); $url = get_self_url(); return do_template('FORM_SCREEN', array('_GUID' => '1a2823d450237aa299c095bf9c689a2a', 'SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED'), 'TITLE' => $title, 'FIELDS' => $fields, 'URL' => $url, 'TEXT' => $text)); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_ocf_warnings($db, $table_prefix, $file_base) { $select = '*'; if (either_param('importer') == 'ipb2') { $select = 'wlog_id AS id,wlog_mid,wlog_notes,wlog_date,wlog_addedby,wlog_contact_content'; } $rows = $db->query('SELECT ' . $select . ' FROM ' . $table_prefix . 'warn_logs'); foreach ($rows as $row) { if (import_check_if_imported('warning', strval($row['id']))) { continue; } $member_id = import_id_remap_get('member', strval($row['wlog_mid']), true); if (is_null($member_id)) { continue; } $by = import_id_remap_get('member', strval($row['wlog_addedby'])); $id_new = ocf_make_warning($member_id, @html_entity_decode($row['wlog_contact_content'], ENT_QUOTES, get_charset()), $by, $row['wlog_date']); import_id_remap_put('warning', strval($row['id']), $id_new); } }
/** * The UI to view subscribers on the newsletter. * * @return tempcode The UI */ function view_subscribers() { $title = get_page_title('VIEW_NEWSLETTER_SUBSCRIBERS'); $lang = choose_language($title); if (is_object($lang)) { return $lang; } $id = either_param('id', NULL); $level = get_param_integer('level', NULL); require_lang('ocf'); // Select newsletter if (is_null($id)) { $fields = new ocp_tempcode(); require_code('form_templates'); // Selection $newsletters = new ocp_tempcode(); $rows = $GLOBALS['SITE_DB']->query_select('newsletters', array('id', 'title')); foreach ($rows as $newsletter) { $newsletters->attach(form_input_list_entry(strval($newsletter['id']), false, get_translated_text($newsletter['title']))); } if (get_forum_type() == 'ocf') { $newsletters->attach(form_input_list_entry('-1', false, do_lang_tempcode('NEWSLETTER_OCF'))); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); foreach ($groups as $group_id => $group) { if ($group_id != db_get_first_id()) { $map = array(); $map['g' . strval($group_id)] = 1; $_c = newsletter_who_send_to($map, $lang, 0, 0); $c6 = $_c[6]['g' . strval($group_id)]; if ($c6 != 0) { $newsletters->attach(form_input_list_entry('g' . strval($group_id), false, do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))))); } } } } if ($newsletters->is_empty()) { inform_exit(do_lang_tempcode('NO_CATEGORIES')); } $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER'), '', 'id', $newsletters)); // CSV option $fields->attach(form_input_tick(do_lang_tempcode('DOWNLOAD_AS_CSV'), do_lang_tempcode('DESCRIPTION_DOWNLOAD_AS_CSV'), 'csv', false)); $submit_name = do_lang_tempcode('VIEW_SUBSCRIBERS'); $post_url = get_self_url(); $prune_url = build_url(array('page' => '_SELF', 'type' => 'bounce_filter_a'), '_SELF'); return do_template('FORM_SCREEN', array('GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'TITLE' => $title, 'TEXT' => do_lang_tempcode('NEWSLETTER_SUBSCRIBERS_FORM', escape_html($prune_url->evaluate())), 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); } // Send to CSV file? $csv = either_param_integer('csv', 0); if ($csv == 1) { $filename = 'subscribers_' . $id . '.csv'; header('Content-type: text/csv'); if (strstr(ocp_srv('HTTP_USER_AGENT'), 'MSIE') !== false) { header('Content-Disposition: filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"'); } else { header('Content-Disposition: attachment; filename="' . str_replace(chr(13), '', str_replace(chr(10), '', addslashes($filename))) . '"'); } @ini_set('ocproducts.xss_detect', '0'); } // Show subscribers $levels = is_null($level) ? $id == '-1' || substr($id, 0, 1) == 'g' ? array(4) : array(1, 2, 3, 4) : array($level); $outs = array(); foreach ($levels as $level) { $max = get_param_integer('max_' . (is_null($level) ? '' : strval($level)), 100); $start = get_param_integer('start_' . (is_null($level) ? '' : strval($level)), 0); $max_rows = 0; if (is_null($level)) { $map[$id] = 1; // $id will be -1 $_c = newsletter_who_send_to($map, $lang, 0, 0, true); if (isset($_c[6][$id])) { $max_rows = $_c[6][$id]; } } else { $map[$id] = $level; // We're requesting that we probe subscribers of $id on $level $_c = newsletter_who_send_to($map, $lang, 0, 0, true); if (isset($_c[6][$id])) { $max_rows = $_c[6][$id]; } } $num = 0; $start2 = 0; do { $map = array(); if (is_null($level)) { $map[$id] = 1; // $id will be -1 $_c = newsletter_who_send_to($map, $lang, $start + $start2, $max, true); } else { $map[$id] = $level; // We're requesting that we probe subscribers of $id on $level $_c = newsletter_who_send_to($map, $lang, $start + $start2, $max, true); } $rows = $_c[7]; if ($csv == 1) { if ($start2 == 0) { if (!is_null($level)) { echo '"LEVEL ' . do_lang('NEWSLETTER_' . strval($level)) . '"' . chr(10); } echo '"' . str_replace('"', '""', do_lang('EMAIL_ADDRESS')) . '",' . '"' . str_replace('"', '""', do_lang('FORENAME')) . '",' . '"' . str_replace('"', '""', do_lang('SURNAME')) . '",' . '"' . str_replace('"', '""', do_lang('NAME')) . '",' . '"' . str_replace('"', '""', do_lang('NEWSLETTER_SEND_ID')) . '",' . '"' . str_replace('"', '""', do_lang('NEWSLETTER_HASH')) . '",' . '"' . str_replace('"', '""', do_lang('PASSWORD_HASH')) . '",' . '"' . str_replace('"', '""', do_lang('SALT')) . '",' . '"' . str_replace('"', '""', do_lang('LANGUAGE')) . '",' . '"' . str_replace('"', '""', do_lang('CONFIRM_CODE')) . '",' . '"' . str_replace('"', '""', do_lang('JOIN_DATE')) . '"' . chr(10); } } else { $out = ''; } foreach ($rows as $r) { $email = array_key_exists('email', $r) ? $r['email'] : $r['m_email_address']; $forename = array_key_exists('n_forename', $r) ? $r['n_forename'] : ''; $surname = array_key_exists('n_surname', $r) ? $r['n_surname'] : ''; $name = array_key_exists('m_username', $r) ? $r['m_username'] : ''; $salt = array_key_exists('pass_salt', $r) ? $r['pass_salt'] : ''; $_lang = array_key_exists('language', $r) ? $r['language'] : ''; $confirm_code = array_key_exists('confirm_code', $r) ? $r['confirm_code'] : 0; $join_time = array_key_exists('join_time', $r) ? $r['join_time'] : time(); $send_id = (array_key_exists('m_username', $r) ? 'm' : 'n') . (array_key_exists('id', $r) ? strval($r['id']) : $email); $hash = array_key_exists('the_password', $r) ? $r['the_password'] : ''; $unsub = array_key_exists('the_password', $r) ? best_hash($r['the_password'], 'xunsub') : ''; if ($csv == 1) { echo '"' . str_replace('"', '""', $email) . '",' . '"' . str_replace('"', '""', $forename) . '",' . '"' . str_replace('"', '""', $surname) . '",' . '"' . str_replace('"', '""', $name) . '",' . '"' . str_replace('"', '""', $send_id) . '",' . '"' . str_replace('"', '""', $unsub) . '",' . '"' . str_replace('"', '""', $hash) . '",' . '"' . str_replace('"', '""', $salt) . '",' . '"' . str_replace('"', '""', $_lang) . '",' . '"' . str_replace('"', '""', strval($confirm_code)) . '",' . '"' . str_replace('"', '""', date('Y-m-d h:i:s', $join_time)) . '"' . chr(10); } else { $tpl = do_template('NEWSLETTER_SUBSCRIBER', array('EMAIL' => $email, 'FORENAME' => $forename, 'SURNAME' => $surname, 'NAME' => $name, 'NEWSLETTER_SEND_ID' => $send_id, 'NEWSLETTER_HASH' => $hash)); $out .= $tpl->evaluate(); } } $start2 += $max; } while ($csv == 1 && array_key_exists(0, $rows)); if (count($rows) == 0 && $start2 == 0) { if ($csv == 1) { echo '"(' . do_lang('NONE') . ')"' . chr(10); } else { } } $text = do_lang_tempcode('NEWSLETTER_PEOPLE_ON_LEVEL', is_numeric($level) && intval($level) > 0 ? make_string_tempcode(escape_html(do_lang('NEWSLETTER_' . strval($level)))) : do_lang_tempcode('NA_EM')); if ($csv == 1) { } else { require_code('templates_results_browser'); $results_browser = results_browser(do_lang_tempcode('VIEW_NEWSLETTER_SUBSCRIBERS'), NULL, $start, 'start_' . (is_null($level) ? '' : strval($level)), $max, 'max_' . (is_null($level) ? '' : strval($level)), $max_rows, NULL, 'subscribers', true); $outs[] = array('RESULTS_BROWSER' => $results_browser, 'SUB' => $out, 'TEXT' => $text); } } if ($csv == 1) { $GLOBALS['SCREEN_TEMPLATE_CALLED'] = ''; exit; } // Work out stats of what domains are used $domains = array(); $start = 0; do { if (strpos(get_db_type(), 'mysql') !== false) { $rows = $GLOBALS['SITE_DB']->query_select('newsletter', array('email', 'COUNT(*) as cnt'), NULL, 'GROUP BY SUBSTRING_INDEX(email,\'@\',-1)'); // Far less PHP processing } else { $rows = $GLOBALS['SITE_DB']->query_select('newsletter', array('email'), NULL, 500, $start); } foreach ($rows as $row) { $email = $row['email']; if (strpos($email, '@') === false) { continue; } $domain = substr($email, strpos($email, '@') + 1); if (!is_string($domain)) { continue; } $cnt = array_key_exists('cnt', $row) ? $row['cnt'] : 1; if (!array_key_exists($domain, $domains)) { $domains[$domain] = 0; } $domains[$domain] += $cnt; } $start += 500; } while (array_key_exists(0, $rows) && strpos(get_db_type(), 'mysql') === false); arsort($domains); foreach ($domains as $key => $val) { $domains[$key] = strval($val); if (count($domains) > 100) { if ($val == 1) { unset($domains[$key]); } } } return do_template('NEWSLETTER_SUBSCRIBERS_SCREEN', array('_GUID' => '52e5d97d451b622d59f87f021a5b8f01', 'DOMAINS' => $domains, 'SUBSCRIBERS' => $outs, 'TITLE' => $title)); }
/** * The actualiser to do an import. * * @return tempcode The UI */ function do_import() { $refresh_url = get_self_url(true, false, array('type' => 'import'), true); $refresh_time = either_param_integer('refresh_time', 15); // Shouldn't default, but reported on some systems to do so if (function_exists('set_time_limit')) { @set_time_limit($refresh_time); } header('Content-type: text/html; charset=' . get_charset()); @ini_set('log_errors', '0'); global $I_REFRESH_URL; $I_REFRESH_URL = $refresh_url; require_code('database_action'); $title = get_page_title('IMPORT'); $importer = get_param('importer'); require_code('hooks/modules/admin_import/' . filter_naughty_harsh($importer)); $object = object_factory('Hook_' . filter_naughty_harsh($importer)); // Get data $old_base_dir = either_param('old_base_dir'); if (method_exists($object, 'verify_base_path') && !$object->verify_base_path($old_base_dir)) { warn_exit(do_lang_tempcode('BAD_IMPORT_PATH', escape_html($old_base_dir))); } if (method_exists($object, 'probe_db_access')) { list($db_name, $db_user, $db_password, $db_table_prefix) = $object->probe_db_access(either_param('old_base_dir')); } else { $db_name = either_param('db_name'); $db_user = either_param('db_user'); $db_password = either_param('db_password'); $db_table_prefix = either_param('db_table_prefix'); } if ($db_name == get_db_site() && $importer == 'ocp_merge' && $db_table_prefix == $GLOBALS['SITE_DB']->get_table_prefix()) { warn_exit(do_lang_tempcode('IMPORT_SELF_NO')); } $import_source = is_null($db_name) ? NULL : new database_driver($db_name, get_db_site_host(), $db_user, $db_password, $db_table_prefix); // Some preliminary tests $happy = get_param_integer('happy', 0); if (method_exists($object, 'pre_import_tests') && $happy == 0) { $ui = $object->pre_import_tests($import_source, $db_table_prefix, $old_base_dir); if (!is_null($ui)) { return $ui; } } // Save data $GLOBALS['SITE_DB']->query_delete('import_session', array('imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_session', array('imp_hook' => '', 'imp_old_base_dir' => $old_base_dir, 'imp_db_name' => is_null($db_name) ? '' : $db_name, 'imp_db_user' => is_null($db_user) ? '' : $db_user, 'imp_db_table_prefix' => is_null($db_table_prefix) ? '' : $db_table_prefix, 'imp_refresh_time' => $refresh_time, 'imp_session' => get_session_id())); $info = $object->info(); $_import_list = $info['import']; $out = new ocp_tempcode(); $parts_done = collapse_2d_complexity('imp_id', 'imp_session', $GLOBALS['SITE_DB']->query_select('import_parts_done', array('imp_id', 'imp_session'), array('imp_session' => get_session_id()))); $import_last = '-1'; if (get_forum_type() != 'ocf') { require_code('forum/ocf'); $GLOBALS['OCF_DRIVER'] = new forum_driver_ocf(); $GLOBALS['OCF_DRIVER']->connection = $GLOBALS['SITE_DB']; $GLOBALS['OCF_DRIVER']->MEMBER_ROWS_CACHED = array(); } $_import_list[] = 'ocf_switch'; $all_skipped = true; $lang_array = array(); $hooks = find_all_hooks('modules', 'admin_import_types'); foreach (array_keys($hooks) as $hook) { require_code('hooks/modules/admin_import_types/' . filter_naughty_harsh($hook)); $_hook = object_factory('Hook_admin_import_types_' . filter_naughty_harsh($hook)); $lang_array += $_hook->run(); } foreach ($_import_list as $import) { $import_this = either_param_integer('import_' . $import, 0); if ($import_this == 1) { $dependency = NULL; if (array_key_exists('dependencies', $info) && array_key_exists($import, $info['dependencies'])) { foreach ($info['dependencies'][$import] as $_dependency) { if (!array_key_exists($_dependency, $parts_done) && isset($lang_array[$_dependency])) { $dependency = $_dependency; } } } if (is_null($dependency)) { if ($import == 'ocf_switch') { $out->attach($this->ocf_switch()); } else { $function_name = 'import_' . $import; ocf_over_local(); $func_output = call_user_func_array(array($object, $function_name), array($import_source, $db_table_prefix, $old_base_dir)); if (!is_null($func_output)) { $out->attach($func_output); } ocf_over_msn(); } $parts_done[$import] = get_session_id(); $import_last = $import; $all_skipped = false; $GLOBALS['SITE_DB']->query_delete('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id()), '', 1); $GLOBALS['SITE_DB']->query_insert('import_parts_done', array('imp_id' => $import, 'imp_session' => get_session_id())); } else { $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => 'b2a853f5fb93beada51a3eb8fbd1575f', 'MESSAGE' => do_lang_tempcode('IMPORT_OF_SKIPPED', escape_html($import), escape_html($dependency))))); } } } if (!$all_skipped) { $lang_code = 'SUCCESS'; if (count($GLOBALS['ATTACHED_MESSAGES_RAW']) != 0) { $lang_code = 'SOME_ERRORS_OCCURRED'; } $out->attach(do_template('IMPORT_MESSAGE', array('_GUID' => '4c4860d021814ffd1df6e21e712c7b44', 'MESSAGE' => do_lang_tempcode($lang_code)))); } log_it('IMPORT'); // Quick and simple decacheing. No need to be smart about this. delete_value('ocf_member_count'); delete_value('ocf_topic_count'); delete_value('ocf_post_count'); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IMPORT')), array('_SELF:_SELF:session', do_lang_tempcode('IMPORT_SESSION')), array('_SELF:_SELF:hook:importer=' . $importer . ':session=' . get_param('session'), do_lang_tempcode('IMPORT')))); breadcrumb_set_self(do_lang_tempcode('START')); $back_url = build_url(array('page' => '_SELF', 'type' => 'hook', 'importer' => get_param('importer'), 'just' => $import_last), '_SELF'); $_GET['just'] = $import_last; return $this->choose_actions($out); }
/** * Standard modular UI to choose an entry to edit. * * @return tempcode The UI */ function ed() { if (!is_null($this->permissions_require) && is_null($this->permissions_cat_require)) { check_some_edit_permission($this->permissions_require, NULL, $this->permission_page_name); } $doing = 'EDIT_' . $this->lang_type; if ($this->catalogue && get_param('catalogue_name', '') != '') { $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name')))); if ($this->type_code == 'd') { $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title)); } elseif ($this->type_code == 'c') { $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title)); } } $title = get_page_title($doing); $test = $this->choose_catalogue($title); if (!is_null($test)) { return $test; } $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_LIST')); $next_type = '_e' . $this->type_code; if (get_param('type', 'ed') == 'edit_catalogue') { $next_type = '_edit_catalogue'; } $map = array('page' => '_SELF', 'type' => $next_type); if (either_param('catalogue_name', '') != '') { $map['catalogue_name'] = either_param('catalogue_name'); } if (!is_null(get_param('redirect', NULL))) { $map['redirect'] = get_param('redirect'); } if (!is_null(get_param('continue', NULL))) { $map['continue'] = get_param('continue'); } $description = $this->select_name_description != '' ? do_lang_tempcode($this->select_name_description) : new ocp_tempcode(); if (method_exists($this, 'nice_get_radio_entries')) { $entries = $this->nice_get_radio_entries(); if ($entries->is_empty()) { inform_exit(do_lang_tempcode($this->type_code == 'd' ? 'NO_ENTRIES' : 'NO_CATEGORIES')); } $fields = form_input_radio(do_lang_tempcode($this->select_name), $description, 'id', $entries, $this->no_blank_ids, true, ''); } elseif (method_exists($this, 'nice_get_ajax_tree') && ($_fields = $this->nice_get_ajax_tree()) !== NULL) { if (is_array($_fields)) { $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_LIST_EXTRA', escape_html($_fields[1]->evaluate()), escape_html($_fields[2]->evaluate()))); $fields = $_fields[0]; } else { $fields = $_fields; } } elseif (method_exists($this, 'nice_get_choose_table')) { list($test, ) = $this->get_entry_rows(); if (count($test) == 0) { inform_exit(do_lang_tempcode($this->type_code == 'd' ? 'NO_ENTRIES' : 'NO_CATEGORIES')); } $table_result = $this->nice_get_choose_table($map); if (is_null($table_result)) { inform_exit(do_lang_tempcode($this->type_code == 'd' ? 'NO_ENTRIES' : 'NO_CATEGORIES')); } $table = $table_result[0]; $has_ordering = $table_result[1]; if (array_key_exists(2, $table_result) && !is_null($table_result[2])) { $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_TABLE_EXTRA', escape_html($table_result[2]->evaluate()), escape_html($table_result[3]->evaluate()))); } else { $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_TABLE')); } return do_template('TABLE_TABLE_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'TABLE' => $table, 'SUBMIT_NAME' => $has_ordering ? do_lang_tempcode('ORDER') : NULL, 'POST_URL' => get_self_url())); } else { $_entries = $this->nice_get_entries(); if (is_array($_entries)) { $text = paragraph(do_lang_tempcode('CHOOSE_EDIT_LIST_EXTRA', escape_html($_entries[1]->evaluate()), escape_html($_entries[2]->evaluate()))); $entries = $_entries[0]; } else { $entries = $_entries; } if ($entries->is_empty()) { inform_exit(do_lang_tempcode($this->type_code == 'd' ? 'NO_ENTRIES' : 'NO_CATEGORIES')); } $fields = form_input_list(do_lang_tempcode($this->select_name), $description, 'id', $entries, NULL, true, $this->no_blank_ids); } $post_url = build_url($map, '_SELF', NULL, false, true); //$submit_name=(strpos($doing,' ')!==false)?protect_from_escaping($doing):do_lang($doing); $submit_name = do_lang_tempcode('PROCEED'); $keep = symbol_tempcode('KEEP'); $iframe_url = NULL; if (!$this->special_edit_frontend && has_js()) { $iframe_url = find_script('iframe') . '?zone=' . get_zone_name() . '&wide_high=1&opens_below=1'; foreach ($map as $key => $val) { $iframe_url .= '&' . $key . '=' . urlencode(str_replace('_SELF', get_page_name(), $val)); } $iframe_url .= $keep->evaluate(); } return do_template('FORM_SCREEN', array('_GUID' => '228a05e24253f324ea286ea8ac3d8b02' . get_class($this), 'GET' => true, 'IFRAME_URL' => $iframe_url, 'HIDDEN' => '', 'TITLE' => $title, 'TEXT' => $text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'SKIP_VALIDATION' => true)); }
/** * The actualiser to toggle a combined IP/member ban. * * @return tempcode The UI */ function multi_ban() { $title = get_page_title('BAN_USER'); $id = either_param('id', NULL); $_ip = explode(':', strrev($id), 2); $ip = strrev($_ip[0]); $member = array_key_exists(1, $_ip) ? strrev($_ip[1]) : NULL; if (post_param_integer('confirm', 0) == 0) { $preview = do_lang_tempcode('BAN_USER_DESCRIPTION', is_null($member) ? do_lang_tempcode('NA_EM') : make_string_tempcode(strval($member)), make_string_tempcode(escape_html($ip))); $url = get_self_url(false, false); return do_template('CONFIRM_SCREEN', array('_GUID' => '3840c52b23d9034cb6f9dd529b236c97', 'TITLE' => $title, 'PREVIEW' => $preview, 'FIELDS' => form_input_hidden('confirm', '1'), 'URL' => $url)); } if (!is_null($member)) { ocf_ban_member(intval($member)); } require_code('failure'); add_ip_ban($ip); return inform_screen($title, do_lang_tempcode('SUCCESS')); }
/** * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX. * * @return tempcode The snippet */ function run() { require_code('password_strength'); return make_string_tempcode(strval(test_password(either_param('password')))); }
/** * Set up a new session / Restore an existing one that was lost. * * @param MEMBER Logged in member * @param BINARY Whether the session should be considered confirmed * @param boolean Whether the session should be invisible * @return AUTO_LINK New session ID */ function create_session($member, $session_confirmed = 0, $invisible = false) { global $SESSION_CACHE; global $MEMBER_CACHED; $MEMBER_CACHED = $member; if ($invisible && get_option('is_on_invisibility') == '0') { $invisible = false; } $new_session = mixed(); $restored_session = delete_expired_sessions_or_recover($member); if (is_null($restored_session)) { // Generate random session $new_session = mt_rand(0, mt_getrandmax() - 1); // Store session $username = $GLOBALS['FORUM_DRIVER']->get_username($member); $new_session_row = array('the_session' => $new_session, 'last_activity' => time(), 'the_user' => $member, 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed, 'session_invisible' => $invisible ? 1 : 0, 'cache_username' => $username, 'the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => substr(get_page_name(), 0, 80), 'the_type' => substr(get_param('type', '', true), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80)); $GLOBALS['SITE_DB']->query_insert('sessions', $new_session_row, false, true); $SESSION_CACHE[$new_session] = $new_session_row; $big_change = true; } else { $new_session = $restored_session; $prior_session_row = $SESSION_CACHE[$new_session]; $new_session_row = array('the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => get_page_name(), 'the_type' => substr(either_param('type', ''), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80), 'last_activity' => time(), 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed); $big_change = $prior_session_row['last_activity'] < time() - 10 || $prior_session_row['session_confirmed'] != $session_confirmed || $prior_session_row['ip'] != $new_session_row['ip']; if ($big_change) { $GLOBALS['SITE_DB']->query_update('sessions', $new_session_row, array('the_session' => $new_session), '', 1, NULL, false, true); } $SESSION_CACHE[$new_session] = array_merge($SESSION_CACHE[$new_session], $new_session_row); } if ($big_change) { if (get_value('session_prudence') !== '1') { // With session prudence we don't store all these in persistant cache due to the size of it all. So only re-save if that's not on. persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } set_session_id($new_session); // We won't set it true here, but something that really needs it to persist might come back and re-set it // New sessions = Login points if (!is_null($member) && addon_installed('points') && addon_installed('stats') && !is_guest($member)) { $points_per_daily_visit = intval(get_option('points_per_daily_visit', true)); if ($points_per_daily_visit != 0) { // See if this is the first visit today $test = $GLOBALS['SITE_DB']->query_value('stats', 'MAX(date_and_time)', array('the_user' => $member)); if (!is_null($test)) { require_code('temporal'); require_code('tempcode'); if (date('d/m/Y', tz_time($test, get_site_timezone())) != date('d/m/Y', tz_time(time(), get_site_timezone()))) { require_code('points'); $_before = point_info($member); if (array_key_exists('points_gained_given', $_before)) { $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_given', strval(intval($_before['points_gained_given']) + $points_per_daily_visit)); } } } } } $GLOBALS['SESSION_CONFIRMED'] = $session_confirmed; return $new_session; }