function testNoMissingParams() { global $ATTACHED_MESSAGES, $ATTACHED_MESSAGES_RAW; $lists = find_all_previews__by_screen(); foreach ($lists as $function => $tpls) { $template = $tpls[0]; $hook = NULL; if (is_file(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function)) { continue; } // To make easier to debug through if (function_exists('set_time_limit')) { @set_time_limit(0); } $ATTACHED_MESSAGES = new ocp_tempcode(); $ATTACHED_MESSAGES_RAW = array(); $out1 = render_screen_preview($template, $hook, $function); $put_out = !$ATTACHED_MESSAGES->is_empty() || count($ATTACHED_MESSAGES_RAW) > 0; $this->assertFalse($put_out, 'Messages put out by ' . $function . ' (' . strip_tags($ATTACHED_MESSAGES->evaluate()) . ')'); if (!$put_out) { fclose(fopen(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function, 'wb')); sync_file(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function); fix_permissions(get_file_base() . '/_tests/screens_tested/nonemissing__' . $function); } unset($out1); } }
/** * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format. * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declaritive. * Assumptions: You can assume all Lang/CSS/Javascript files in this addon have been pre-required. * * @return array Array of previews, each is Tempcode. Normally we have just one preview, but occasionally it is good to test templates are flexible (e.g. if they use IF_EMPTY, we can test with and without blank data). */ function tpl_preview__administrative__form_screen_input_permission() { require_lang('permissions'); $permission_rows = new ocp_tempcode(); foreach (placeholder_array() as $k => $v) { $overrides = new ocp_tempcode(); $all_global = true; foreach (placeholder_array() as $k => $v) { $overrides->attach(do_lorem_template('FORM_SCREEN_INPUT_PERMISSION_OVERRIDE', array('FORCE_PRESETS' => false, 'GROUP_NAME' => lorem_phrase(), 'VIEW_ACCESS' => '', 'TABINDEX' => placeholder_number(), 'GROUP_ID' => placeholder_random_id(), 'SP' => strval($k), 'ALL_GLOBAL' => true, 'TITLE' => lorem_phrase(), 'DEFAULT_ACCESS' => '', 'CODE' => '-1'))); } $permission_rows->attach(do_lorem_template('FORM_SCREEN_INPUT_PERMISSION', array('FORCE_PRESETS' => false, 'GROUP_NAME' => lorem_phrase(), 'OVERRIDES' => $overrides->evaluate(), 'ALL_GLOBAL' => true, 'VIEW_ACCESS' => '', 'TABINDEX' => placeholder_number(), 'GROUP_ID' => placeholder_random_id(), 'PINTERFACE_VIEW' => ''))); } $permission_rows->attach(do_lorem_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX_OUTER', array('INNER' => lorem_word()))); $permission_rows->attach(do_lorem_template('FORM_SCREEN_INPUT_PERMISSION_ADMIN', array('PINTERFACE_VIEW' => lorem_word(), 'GROUP_ID' => placeholder_random_id(), 'GROUP_NAME' => lorem_phrase(), 'FORCE_PRESETS' => false, 'OVERRIDES' => placeholder_array()))); $field = do_lorem_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX', array('TITLE' => lorem_phrase(), 'SERVER_ID' => placeholder_id(), 'COLOR' => lorem_word(), 'OVERRIDES' => placeholder_array(), 'PERMISSION_ROWS' => $permission_rows)); return array(lorem_globalise(do_lorem_template('FORM_GROUPED', array('URL' => '#', 'FIELD_GROUPS' => $field, 'TEXT' => '', 'SUBMIT_NAME' => lorem_word_2())), NULL, '', true)); }
/** * The UI to send a newsletter. * * @param LONG_TEXT Default newsletter to put in * @return tempcode The UI */ function send_gui($_existing = '') { // If this is a periodic newsletter, we make some changes to the regular // language strings. $periodic_action_raw = post_param('periodic_choice', ''); $periodic_subject = ''; $defaults = mixed(); switch (preg_replace('#\\_\\d+$#', '', $periodic_action_raw)) { case 'remove_existing': // Remove whatever is already set. We don't need any changes for // this, but we do need a hidden form field. $periodic_action = 'remove'; break; case 'replace_existing': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'replace'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); $periodic_id = intval(preg_replace('#^[^\\d]+#', '', $periodic_action_raw)); $_defaults = $GLOBALS['SITE_DB']->query_select('newsletter_periodic', array('*'), array('id' => $periodic_id), '', 1); if (!array_key_exists(0, $_defaults)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $defaults = $_defaults[0]; break; case 'make_periodic': // Make the current newsletter periodic. This requires language // fiddling. $periodic_action = 'make'; $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP'); break; case 'no_change': default: // The default action is to leave the current settings as-is. $periodic_action = 'none'; break; } $title = get_page_title('NEWSLETTER_SEND'); $lang = choose_language($title); if (is_object($lang)) { return $lang; } $comcode_given = $_existing != '' && strpos($_existing, '<html') !== false; $_existing = post_param('message', $_existing); if ($_existing == '') { $from_news = get_param_integer('from_news', -1); if ($from_news != -1 && addon_installed('news')) { $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('id' => $from_news), 'ORDER BY id DESC', 1); if (!array_key_exists(0, $rows)) { require_lang('news'); return warn_screen(get_page_title('NEWS'), do_lang_tempcode('MISSING_RESOURCE')); } $myrow = $rows[0]; $_existing = get_translated_text($myrow['news_article'], NULL, $lang); if ($_existing == '') { $_existing = get_translated_text($myrow['news'], NULL, $lang); } } $existing = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f42', 'CONTENT' => $_existing, 'LANG' => $lang)); } else { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f44', 'CONTENT' => $_existing, 'LANG' => $lang)); if (strpos($default->evaluate(), '<html') !== false) { if ($comcode_given) { $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f46', 'CONTENT' => comcode_to_tempcode($_existing), 'LANG' => $lang)); } $existing = $default; } else { $existing = make_string_tempcode($_existing); } } $post_url = build_url(array('page' => '_SELF', 'type' => 'confirm', 'old_type' => get_param('type', '')), '_SELF'); $submit_name = do_lang_tempcode('PREVIEW'); $hidden = new ocp_tempcode(); $hidden->attach(form_input_hidden('lang', $lang)); // Build up form $fields = new ocp_tempcode(); require_code('form_templates'); $default_subject = get_option('newsletter_title'); if (!is_null($defaults)) { $default_subject = $defaults['np_subject']; } if ($periodic_action != 'make' && $periodic_action != 'replace') { $default_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true); } $default_subject = post_param('subject', $default_subject); $fields->attach(form_input_line_comcode(do_lang_tempcode('SUBJECT'), do_lang_tempcode('NEWSLETTER_DESCRIPTION_TITLE', $periodic_subject), 'subject', $default_subject, true)); $in_full = post_param_integer('in_full', 0); $chosen_categories = post_param('chosen_categories', ''); if ($periodic_action == 'make' || $periodic_action == 'replace') { // We are making a periodic newsletter. This means we need to pass // through the chosen categories if (!is_null($defaults)) { $chosen_categories = $defaults['np_message']; $in_full = $defaults['np_in_full']; $fields->attach(form_input_tick(do_lang_tempcode('EMBED_FULL_ARTICLES'), do_lang_tempcode('DESCRIPTION_EMBED_FULL_ARTICLES'), 'in_full', $in_full == 1)); $fields->attach(form_input_huge(do_lang_tempcode('NEWSLETTER_CONTENT'), do_lang('NEWSLETTER_CONTENT_SELECT'), 'chosen_categories', $chosen_categories, true)); } else { $hidden->attach(form_input_hidden('chosen_categories', $chosen_categories)); $hidden->attach(form_input_hidden('in_full', strval($in_full))); } $hidden->attach(form_input_hidden('cutoff_day', post_param('cutoff_day'))); $hidden->attach(form_input_hidden('cutoff_month', post_param('cutoff_month'))); $hidden->attach(form_input_hidden('cutoff_year', post_param('cutoff_year'))); $hidden->attach(form_input_hidden('cutoff_hour', post_param('cutoff_hour'))); $hidden->attach(form_input_hidden('cutoff_minute', post_param('cutoff_minute'))); $hidden->attach(form_input_hidden('message', $existing->evaluate())); } else { $hidden->attach(form_input_hidden('in_full', strval($in_full))); if (strpos($existing->evaluate(), '<html') === false) { $fields->attach(form_input_huge_comcode(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } else { $fields->attach(form_input_huge(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true)); } } if (addon_installed('calendar') && $periodic_action == 'none' && cron_installed()) { $fields->attach(form_input_date__scheduler(do_lang_tempcode('DEFER_TIME'), do_lang_tempcode('DESCRIPTION_DEFER_TIME'), 'schedule', true, true, true)); } $from_email = post_param('from_email', get_option('staff_address')); if (!is_null($defaults)) { $from_email = post_param('from_email', $defaults['np_from_email']); } $fields->attach(form_input_email(do_lang_tempcode('FROM_EMAIL'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_EMAIL'), 'from_email', $from_email, true)); $from_name = post_param('from_name', get_site_name()); if (!is_null($defaults)) { $from_name = post_param('from_name', $defaults['np_from_name']); } $fields->attach(form_input_line(do_lang_tempcode('FROM_NAME'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_NAME'), 'from_name', $from_name, true)); $_html_only = post_param_integer('html_only', NULL); if (is_null($_html_only)) { $html_only = strpos($existing->evaluate(), '<html') !== false; if (!is_null($defaults)) { $html_only = $defaults['np_html_only']; } } else { $html_only = $_html_only == 1; } if (get_value('force_html_only') === '1') { $hidden->attach(form_input_hidden('html_only', '1')); } else { $fields->attach(form_input_tick(do_lang_tempcode('HTML_ONLY'), do_lang_tempcode('DESCRIPTION_HTML_ONLY'), 'html_only', $html_only)); } $l = new ocp_tempcode(); $priority = post_param_integer('priority', 3); if (!is_null($defaults)) { $priority = post_param_integer('priority', $defaults['np_priority']); } for ($i = 1; $i <= 5; $i++) { $l->attach(form_input_list_entry(strval($i), $i == $priority, do_lang_tempcode('PRIORITY_' . strval($i)))); } $fields->attach(form_input_list(do_lang_tempcode('PRIORITY'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_PRIORITY'), 'priority', $l)); // Where to send to $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('CHOOSE_SEND_TO')))); $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*')); foreach ($newsletters as $newsletter) { $level = post_param_integer(strval($newsletter['id']), post_param_integer('level', -1)); $c4 = $this->count_level($newsletter['id'], 4, $lang); $c3 = $this->count_level($newsletter['id'], 3, $lang); $c2 = $this->count_level($newsletter['id'], 2, $lang); $c1 = $this->count_level($newsletter['id'], 1, $lang); if ($c1 != 0) { $newsletter_title = get_translated_text($newsletter['title']); $newsletter_description = get_translated_text($newsletter['description']); if ($c1 == $c2 && $c1 == $c3 && $c1 == $c4) { $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_PREFIX', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_NOSUBSCRIPTION_LEVEL', escape_html(integer_format($c4)), escape_html($newsletter_description)), strval($newsletter['id']), $level >= 1, NULL, '4')); } else { $l = new ocp_tempcode(); $l->attach(form_input_list_entry('0', $level == 0, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_0_ALT'), do_lang_tempcode('NUM_READERS', integer_format(0))))); $l->attach(form_input_list_entry('1', $level == 1, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_1'), do_lang_tempcode('NUM_READERS', integer_format($c1))))); $l->attach(form_input_list_entry('2', $level == 2, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_2'), do_lang_tempcode('NUM_READERS', integer_format($c2))))); $l->attach(form_input_list_entry('3', $level == 3, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_3'), do_lang_tempcode('NUM_READERS', integer_format($c3))))); $l->attach(form_input_list_entry('4', $level == 4, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_4'), do_lang_tempcode('NUM_READERS', integer_format($c4))))); $fields->attach(form_input_list(do_lang_tempcode('SUBSCRIPTION_LEVEL_FOR', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_SUBSCRIPTION_LEVEL', escape_html($newsletter_description)), strval($newsletter['id']), $l)); } } } if (get_forum_type() == 'ocf') { $c5 = $this->count_level(-1, 5, $lang); $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_OCF'), do_lang_tempcode('NUM_READERS', integer_format($c5)), '-1', false)); $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) { $fields->attach(form_input_tick(do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))), do_lang_tempcode('NUM_READERS', integer_format($c6)), 'g' . strval($group_id), post_param_integer('g' . strval($group_id), 0) == 1)); } } } } $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD_CSV'), 'file', false, NULL, NULL, true, 'csv,txt')); //if ($fields->is_empty()) inform_exit(do_lang_tempcode('NOBODY_TO_SEND_TO')); handle_max_file_size($hidden); $template_choices = new ocp_tempcode(); $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom'); while (($f = readdir($dh)) !== false) { if (preg_match('#^MAIL.*\\.tpl$#', $f) != 0) { $tpl = basename($f, '.tpl'); $template_choices->attach(form_input_list_entry($tpl, post_param('template', 'MAIL') == $tpl, $tpl)); } } if (!file_exists(get_custom_file_base() . '/themes/default/templates_custom/MAIL.tpl')) { $template_choices->attach(form_input_list_entry('MAIL', true, 'MAIL')); } closedir($dh); $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER_TEMPLATE'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_TEMPLATE'), 'template', $template_choices, NULL, false, true)); // If we're making a periodic newsletter then we need to know when it // should be sent if ($periodic_action == 'make' || $periodic_action == 'replace') { $hidden->attach(form_input_hidden('make_periodic', '1')); $hidden->attach(form_input_hidden('periodic_choice', post_param('periodic_choice'))); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('PERIODIC_WHEN'), 'HELP' => do_lang('PERIODIC_WHEN_HELP')))); // The choices are given as radio buttons: weekly or bi-weekly or monthly? // In the labels for these radio buttons, we put a dropdown for day of // the week and day of the month. $frequency = post_param('periodic_when', 'weekly'); if (!is_null($defaults)) { $frequency = post_param('periodic_when', $defaults['np_frequency']); } $current_day_weekly = post_param_integer('periodic_weekly', 5); if (!is_null($defaults)) { $current_day_weekly = post_param_integer('periodic_weekly', $defaults['np_day']); } $current_day_biweekly = post_param_integer('periodic_biweekly', 5); if (!is_null($defaults)) { $current_day_biweekly = post_param_integer('periodic_biweekly', $defaults['np_day']); } $current_day_of_month = post_param_integer('periodic_monthly', 1); if (!is_null($defaults)) { $current_day_of_month = post_param_integer('periodic_monthly', $defaults['np_day']); } $radios = new ocp_tempcode(); $week_days_weekly = new ocp_tempcode(); $week_days_biweekly = new ocp_tempcode(); require_lang('dates'); $week_days = array(1 => do_lang('MONDAY'), 2 => do_lang('TUESDAY'), 3 => do_lang('WEDNESDAY'), 4 => do_lang('THURSDAY'), 5 => do_lang('FRIDAY'), 6 => do_lang('SATURDAY'), 7 => do_lang('SUNDAY')); foreach ($week_days as $i => $this_day) { $week_days_weekly->attach(form_input_list_entry(strval($i), $i == $current_day_weekly, $this_day, false, false)); $week_days_biweekly->attach(form_input_list_entry(strval($i), $i == $current_day_biweekly, $this_day, false, false)); } $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_WEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_weekly', 'CONTENT' => $week_days_weekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'weekly', $frequency == 'weekly', $weekly_desc, NULL, '')); $weekly_desc = new ocp_tempcode(); $weekly_desc->attach(do_lang('PERIODIC_BIWEEKLY_ON')); $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_biweekly', 'CONTENT' => $week_days_biweekly, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'biweekly', $frequency == 'biweekly', $weekly_desc, NULL, '')); $month_days = new ocp_tempcode(); foreach (range(1, 28) as $this_day) { $suffix = gmdate('S', gmmktime(0, 0, 0, 1, $this_day, 1990)); $month_days->attach(form_input_list_entry(strval($this_day), $this_day == 1, strval($this_day) . $suffix, $current_day_of_month == $this_day)); } $monthly_desc = new ocp_tempcode(); $monthly_desc->attach(do_lang('PERIODIC_MONTHLY_ON')); $monthly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_monthly', 'CONTENT' => $month_days, 'INLINE_LIST' => '0'))); $radios->attach(form_input_radio_entry('periodic_when', 'monthly', $frequency == 'monthly', $monthly_desc, NULL, '')); $fields->attach(form_input_radio(do_lang('PERIODIC_WHEN_CHOICE'), '', 'periodic_when', $radios, true)); $radios = new ocp_tempcode(); $radios->attach(form_input_radio_entry('periodic_for', 'all', false, do_lang_tempcode('CREATE_PERIODIC_FOR_ALL'), NULL, '')); $radios->attach(form_input_radio_entry('periodic_for', 'future', true, do_lang_tempcode('CREATE_PERIODIC_FOR_FUTURE'), NULL, '')); $fields->attach(form_input_radio(do_lang('CREATE_PERIODIC_FOR'), '', 'periodic_for', $radios, true)); } return do_template('FORM_SCREEN', array('_GUID' => '0b2a4825ec586d9ff557026d9a1e0cca', 'TITLE' => $title, 'TEXT' => $periodic_action == 'make' || $periodic_action == 'replace' ? do_lang_tempcode('PERIODIC_NO_EDIT') : do_lang_tempcode('NEWSLETTER_SEND_TEXT'), 'HIDDEN' => $hidden, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url)); }
/** * Standard modular UI to edit an entry. * * @return tempcode The UI */ function _ed() { $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); //$submit_name=(strpos($doing,' ')!==false)?protect_from_escaping($doing):do_lang($doing); //if (!is_null($this->edit_submit_name)) $submit_name=$this->edit_submit_name; $submit_name = do_lang_tempcode('SAVE'); //$test=$this->choose_catalogue($title); //if (!is_null($test)) return $test; $id = mixed(); // Define type as mixed $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id')); $map = array('page' => '_SELF', 'type' => '__e' . $this->type_code, 'id' => $id); if (get_param('catalogue_name', '') != '') { $map['catalogue_name'] = get_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'); } if (!is_null($this->upload) || $this->possibly_some_kind_of_upload) { $map['uploading'] = 1; } $post_url = build_url($map, '_SELF'); if (multi_lang() && has_actual_page_access(get_member(), 'admin_lang') && user_lang() != get_site_default_lang()) { require_code('lang2'); $switch_url = get_self_url(false, false, array('keep_lang' => get_site_default_lang())); attach_message(do_lang_tempcode('lang:EDITING_CONTENT_IN_LANGUAGE_STAFF', escape_html(lookup_language_full_name(user_lang())), escape_html(lookup_language_full_name(get_site_default_lang())), escape_html($switch_url->evaluate())), 'warn'); } if (method_exists($this, 'get_submitter')) { list($submitter, $date_and_time) = $this->get_submitter($id); } else { $submitter = NULL; $date_and_time = NULL; } if (!is_null($this->permissions_require)) { check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name); } if (!is_null($this->permissions_cat_require) && !has_category_access(get_member(), $this->permissions_cat_require, $this->get_cat($id))) { access_denied('CATEGORY_ACCESS'); } if (!is_null($this->permissions_cat_require_b) && !has_category_access(get_member(), $this->permissions_cat_require_b, $this->get_cat_b($id))) { access_denied('CATEGORY_ACCESS'); } $bits = $this->fill_in_edit_form($id); $delete_fields = new ocp_tempcode(); $all_delete_fields_given = false; $fields2 = new ocp_tempcode(); if (is_array($bits)) { $fields = $bits[0]; $hidden = $bits[1]; if (array_key_exists(2, $bits) && !is_null($bits[2])) { $delete_fields = $bits[2]; } if (array_key_exists(3, $bits) && !is_null($bits[3])) { $this->edit_text = $bits[3]; } if (array_key_exists(4, $bits) && $bits[4]) { $all_delete_fields_given = true; } if (array_key_exists(5, $bits) && !is_null($bits[5])) { $this->posting_form_text = $bits[5]; } if (array_key_exists(6, $bits) && !is_null($bits[6])) { $fields2 = $bits[6]; } if (array_key_exists(7, $bits)) { $this->posting_form_text_parsed = $bits[7]; } } else { $fields = $bits; $hidden = new ocp_tempcode(); } // Add in custom fields if ($this->has_tied_catalogue()) { require_code('fields'); $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('MORE')))); append_form_custom_fields($this->award_type, $id, $fields, $hidden); } // SEO? if (!is_null($this->seo_type)) { require_code('seo2'); $fields2->attach(seo_get_fields($this->seo_type, $id)); } // Awards? if (addon_installed('awards')) { if (!is_null($this->award_type)) { require_code('awards'); $fields2->attach(get_award_fields($this->award_type, $id)); } } // Action fields / deletion options $delete_permission = true; if (!is_null($this->permissions_require)) { $delete_permission = has_delete_permission($this->permissions_require, get_member(), $submitter, is_null($this->permission_page_name) ? get_page_name() : $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id))); } $may_delete = (!method_exists($this, 'may_delete_this') || $this->may_delete_this($id)) && (!is_numeric($id) || intval($id) >= db_get_first_id() + $this->protect_first) && $delete_permission; // Deletion options $action_fields = new ocp_tempcode(); if ($may_delete) { if (!$all_delete_fields_given) { $action_fields->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false)); } if (addon_installed('points') && !is_null($submitter) && !is_null($date_and_time)) { $points_test = $GLOBALS['SITE_DB']->query_value_null_ok('gifts', 'id', array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id())); if (!is_null($points_test)) { require_lang('points'); $action_fields->attach(form_input_tick(do_lang_tempcode('REVERSE_TITLE'), do_lang_tempcode('REVERSE_TITLE_DESCRIPTION'), 'reverse_point_transaction', false)); } } $action_fields->attach($delete_fields); } if (!$this->appended_actions_already && !$action_fields->is_empty()) { $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS')))); } $fields2->attach($action_fields); if (!is_object($this->edit_text)) { $this->edit_text = make_string_tempcode(is_null($this->edit_text) ? '' : $this->edit_text); } if (!is_null($this->upload)) { if ($this->upload == 'image') { require_code('images'); $max = floatval(get_max_image_size()) / floatval(1024 * 1024); if ($max < 3.0) { require_code('files2'); $config_url = get_upload_limit_config_url(); $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url)))); } } else { require_code('files2'); $max = floatval(get_max_file_size()) / floatval(1024 * 1024); if ($max < 30.0) { $config_url = get_upload_limit_config_url(); $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url)))); } } } if (get_param('type', '_ed') == '_edit_catalogue') { require_javascript('javascript_catalogues'); // Existing fields $field_count = 0; $c_name = get_param('id', false, true); $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $c_name), 'ORDER BY cf_order'); $fields_existing = new ocp_tempcode(); foreach ($rows as $i => $myrow) { $name = get_translated_text($myrow['cf_name']); $description = get_translated_text($myrow['cf_description']); $prefix = 'existing_field_' . strval($myrow['id']) . '_'; list($_fields_existing, $_fields_hidden) = $this->get_field_fields($i == 0 && substr($c_name, 0, 1) != '_', count($rows) + 10, $prefix, $field_count, $name, $description, $myrow['cf_type'], $myrow['cf_defines_order'], $myrow['cf_visible'], $myrow['cf_searchable'], $myrow['cf_default'], $myrow['cf_required'], $myrow['cf_put_in_category'], $myrow['cf_put_in_search']); if (!is_ecommerce_catalogue($c_name) || $i > 9) { $_fields_existing->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS')))); $_fields_existing->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), $prefix . 'delete', false)); } $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '1492d973db45cbecff892ad4ac1af28f' . get_class($this), 'NAME' => $name, 'ID' => 'FIELD_' . strval($i + 1), 'FIELDS' => $_fields_existing->evaluate())); $fields_existing->attach($temp); $hidden->attach($_fields_hidden); $field_count++; } // New field $fields_new = new ocp_tempcode(); for ($i = 0; $i < 5; $i++) { list($_fields_new, $_fields_hidden) = $this->get_field_fields(false, count($rows) + 10, 'new_field_' . strval($i) . '_', $field_count); $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '8b9a632eafae003ccc6b007eefb0ce3d' . get_class($this), 'NAME' => do_lang_tempcode('NEW_FIELD', strval($i + 1)), 'ID' => 'NEW_FIELD_' . strval($i + 1), 'FIELDS' => $_fields_new->evaluate())); $fields_new->attach($temp); $hidden->attach($_fields_hidden); $field_count++; } $fields->attach($fields2); return do_template('CATALOGUE_EDITING_SCREEN', array('_GUID' => '584d7dc7c2c13939626102374f13f508' . get_class($this), 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $this->add_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'FIELDS_EXISTING' => $fields_existing->evaluate(), 'FIELDS_NEW' => $fields_new->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript)); } list($warning_details, $ping_url) = handle_conflict_resolution(); if (!is_null($this->posting_form_title)) { $posting_form = get_posting_form($submit_name, $this->posting_form_text, $post_url, $hidden, $fields, $this->posting_form_title, '', $fields2, $this->posting_form_text_parsed, $this->javascript, NULL, $this->posting_field_required); return do_template('POSTING_SCREEN', array('_GUID' => '841b9af3aa80bcab86b907e4b942786a' . get_class($this), 'PREVIEW' => $this->do_preview, 'TITLE' => $title, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TEXT' => $this->add_text, 'POSTING_FORM' => $posting_form->evaluate(), 'JAVASCRIPT' => $this->javascript)); } else { $fields->attach($fields2); return do_template('FORM_SCREEN', array('_GUID' => '2d70be34595a16c6f170d966b894bfe2' . get_class($this), 'PREVIEW' => $this->do_preview, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'TITLE' => $title, 'SKIP_VALIDATION' => $this->skip_validation, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'HIDDEN' => $hidden, 'TEXT' => $this->edit_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript)); } }
/** * Create a form field input matrix for permission setting. * * @param ID_TEXT Permission ID (pagelink style) for the resource being set * @param array An inverted list showing what view permissions are set for what we're setting permissions for * @param array List of overridable privilege codes for what we're setting permissions for * @param array List of privilege settings relating to what we're setting permissions for, from the database * @param array Multi-dimensional array showing what the inherited defaults for this permission would be * @param boolean Whether to not include the stuff to make it fit alongside other form fields in a normal form table * @param ?tempcode Label for view permissions (NULL: default) * @return tempcode The form field matrix */ function get_permissions_matrix($server_id, $access, $overridables, $specific_permissions, $default_access, $no_outer = false, $pinterface_view = NULL) { require_lang('permissions'); require_javascript('javascript_permissions'); $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups(); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, true); if (is_null($pinterface_view)) { $pinterface_view = do_lang_tempcode('PINTERFACE_VIEW'); } // Permission rows for matrix $permission_rows = new ocp_tempcode(); $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true); foreach (array_keys($access) as $id) { if (!array_key_exists($id, $groups) && array_key_exists($id, $all_groups)) { $groups[$id] = $all_groups[$id]; } } foreach ($groups as $id => $group_name) { if (!in_array($id, $admin_groups)) { $perhaps = count($access) == 0 ? 1 : $access[$id]; $view_access = $perhaps == 1; $tabindex = get_form_field_tabindex(NULL); $overrides = new ocp_tempcode(); $all_global = true; foreach (array_keys($overridables) as $override) { if (isset($specific_permissions[$override][$id])) { $all_global = false; } } foreach ($overridables as $override => $cat_support) { $lang_string = do_lang_tempcode('PT_' . $override); if (is_array($cat_support)) { $lang_string = do_lang_tempcode($cat_support[1]); } if (is_array($cat_support)) { $cat_support = $cat_support[0]; } if ($cat_support == 0) { continue; } $overrides->attach(do_template('FORM_SCREEN_INPUT_PERMISSION_OVERRIDE', array('FORCE_PRESETS' => $no_outer, 'GROUP_NAME' => $group_name, 'VIEW_ACCESS' => $view_access, 'TABINDEX' => strval($tabindex), 'GROUP_ID' => strval($id), 'SP' => $override, 'ALL_GLOBAL' => $all_global, 'TITLE' => $lang_string, 'DEFAULT_ACCESS' => $default_access[$id][$override], 'CODE' => isset($specific_permissions[$override][$id]) ? $specific_permissions[$override][$id] : '-1'))); } $permission_rows->attach(do_template('FORM_SCREEN_INPUT_PERMISSION', array('_GUID' => 'e2c4459ae995d33376c07e498f1d973a', 'FORCE_PRESETS' => $no_outer, 'GROUP_NAME' => $group_name, 'OVERRIDES' => $overrides->evaluate(), 'ALL_GLOBAL' => $all_global, 'VIEW_ACCESS' => $view_access, 'TABINDEX' => strval($tabindex), 'GROUP_ID' => strval($id), 'PINTERFACE_VIEW' => $pinterface_view))); } else { $overridables_filtered = array(); foreach ($overridables as $override => $cat_support) { if (is_array($cat_support)) { $cat_support = $cat_support[0]; } if ($cat_support == 1) { $overridables_filtered[$override] = 1; } } $permission_rows->attach(do_template('FORM_SCREEN_INPUT_PERMISSION_ADMIN', array('FORCE_PRESETS' => $no_outer, 'OVERRIDES' => $overridables_filtered, 'GROUP_NAME' => $group_name, 'GROUP_ID' => strval($id), 'PINTERFACE_VIEW' => $pinterface_view))); } } if (count($overridables) == 0 && !$no_outer) { return $permission_rows; } // Find out colour for our vertical text image headings (CSS can't rotate text), using the CSS as a basis $tmp_file = @file_get_contents(get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css'); $color = 'FF00FF'; $matches = array(); if ($tmp_file !== false) { if (preg_match('#\\nth.*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);.*\\}#sU', $tmp_file, $matches) != 0) { $color = $matches[1]; } } // For heading up the table matrix $overrides_array = array(); foreach ($overridables as $override => $cat_support) { $lang_string = do_lang_tempcode('PT_' . $override); if (is_array($cat_support)) { $lang_string = do_lang_tempcode($cat_support[1]); } if (is_array($cat_support)) { $cat_support = $cat_support[0]; } if ($cat_support == 0) { continue; } $overrides_array[$override] = array('TITLE' => $lang_string); } // Finish off the matrix and return $inner = do_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX', array('_GUID' => '0f019c7e60366fa04058097ee6f3829a', 'SERVER_ID' => $server_id, 'COLOR' => $color, 'OVERRIDES' => $overrides_array, 'PERMISSION_ROWS' => $permission_rows)); if ($no_outer) { return make_string_tempcode(static_evaluate_tempcode($inner)); } return make_string_tempcode(static_evaluate_tempcode(do_template('FORM_SCREEN_INPUT_PERMISSION_MATRIX_OUTER', array('_GUID' => '2a2f9f78f3639185300c92cab50767c5', 'INNER' => $inner)))); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_all_lang(); require_code('zones2'); $skip_pages = array_key_exists('skip', $map) ? explode(',', $map['skip']) : array(); $comcode_page_rows = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*')); $_zones = array(); $zones = find_all_zones(false, true); $GLOBALS['MEMORY_OVER_SPEED'] = true; $low_memory = ini_get('memory_limit') != '-1' && ini_get('memory_limit') != '0' && ini_get('memory_limit') != '' && intval(preg_replace('#M$#', '', ini_get('memory_limit'))) < 26 || get_option('has_low_memory_limit') === '1'; // Reorder a bit $zones2 = array(); foreach (array('', 'site') as $zone_match) { foreach ($zones as $i => $zone) { if ($zone[0] == $zone_match) { $zones2[] = $zone; unset($zones[$i]); } } } $zones2 = array_merge($zones2, $zones); foreach ($zones2 as $z) { list($zone, $zone_title, , $zone_default_page) = $z; if (has_zone_access(get_member(), $zone)) { $_pages = array(); $pages = find_all_pages_wrap($zone); if (isset($pages[$zone_default_page])) { $default = $pages[$zone_default_page]; $pages = array($zone_default_page => $default) + $pages; } foreach ($pages as $page => $page_type) { if (is_integer($page)) { $page = strval($page); } if (substr($page, 0, 6) == 'panel_') { continue; } if (substr($page, 0, 1) == '_') { continue; } if (in_array($page, $skip_pages)) { continue; } if (in_array($zone . ':' . $page, $skip_pages)) { continue; } if ($page == '404') { continue; } if (strpos($page, '_tree_made') !== false) { continue; } if ($page == 'sitemap') { continue; } if ($page == 'forums' && substr($page_type, 0, 7) == 'modules' && (get_forum_type() == 'ocf' || get_forum_type() == 'none')) { continue; } if ($page == 'join' && substr($page_type, 0, 7) == 'modules' && !is_guest()) { continue; } if (has_page_access(get_member(), $page, $zone)) { $_entrypoints = array(); $__entrypoints = $low_memory ? array(NULL) : extract_module_functions_page($zone, $page, array('get_entry_points')); if (!is_null($__entrypoints[0])) { $entrypoints = is_array($__entrypoints[0]) ? call_user_func_array($__entrypoints[0][0], $__entrypoints[0][1]) : (strpos($__entrypoints[0], '::') !== false ? NULL : eval($__entrypoints[0])); // The strpos thing is a little hack that allows it to work for base-class derived modules if (is_null($entrypoints)) { $path = zone_black_magic_filterer($zone . ($zone == '' ? '' : '/') . 'pages/' . $page_type . '/' . $page . '.php', true); if ($low_memory && !defined('HIPHOP_PHP') && strpos(file_get_contents(get_file_base() . '/' . $path), ' extends standard_aed_module') !== false) { $new_code = str_replace(',parent::get_entry_points()', '', str_replace('parent::get_entry_points(),', '', $__entrypoints[0])); if (strpos($new_code, 'parent::') !== false) { continue; } $entrypoints = eval($new_code); } else { require_code($path); if (class_exists('Mx_' . filter_naughty_harsh($page))) { $object = object_factory('Mx_' . filter_naughty_harsh($page)); } else { $object = object_factory('Module_' . filter_naughty_harsh($page)); } $entrypoints = $object->get_entry_points(); } } } else { $entrypoints = array('!'); } if (!is_array($entrypoints)) { $entrypoints = array('!'); } if ($entrypoints == array('!')) { $url = build_url(array('page' => $page), $zone, NULL, false, false, true); $title = ucwords(str_replace('_', ' ', $page)); if (substr($page_type, 0, 7) == 'comcode') { foreach ($comcode_page_rows as $page_row) { if ($page_row['p_validated'] == 0 && $page_row['the_page'] == $page && $page_row['the_zone'] == $zone) { continue 2; } } $path = zone_black_magic_filterer((strpos($page_type, '_custom') !== false ? get_custom_file_base() : get_file_base()) . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.txt'); if (!is_file($path)) { $path = zone_black_magic_filterer(get_file_base() . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.txt'); } $page_contents = file_get_contents($path); $matches = array(); if (preg_match('#\\[title[^\\]]*\\]#', $page_contents, $matches) != 0) { $start = strpos($page_contents, $matches[0]) + strlen($matches[0]); $end = strpos($page_contents, '[/title]', $start); $matches = array(); $title_portion = str_replace('{$SITE_NAME}', get_site_name(), substr($page_contents, $start, $end - $start)); if (preg_match('#\\{\\!([\\w:]+)\\}#', $title_portion, $matches) != 0) { $title_portion = str_replace($matches[0], do_lang($matches[1]), $title_portion); } if (preg_match('#^[^<>\\[\\{\\&]*$#', $title_portion, $matches) != 0) { $title = $matches[0]; } elseif (!$low_memory) { $_title = comcode_to_tempcode($title_portion); $title = strip_tags(@html_entity_decode($_title->evaluate(), ENT_QUOTES, get_charset())); } } } elseif (substr($page_type, 0, 4) == 'html') { $path = zone_black_magic_filterer((strpos($page_type, '_custom') !== false ? get_custom_file_base() : get_file_base()) . '/' . filter_naughty($zone) . '/pages/' . filter_naughty($page_type) . '/' . $page . '.htm'); $page_contents = file_get_contents($path); $matches = array(); if (preg_match('#\\<title[^\\>]*\\>#', $page_contents, $matches) != 0) { $start = strpos($page_contents, $matches[0]) + strlen($matches[0]); $end = strpos($page_contents, '</title>', $start); $title = strip_tags(@html_entity_decode(substr($page_contents, $start, $end - $start), ENT_QUOTES, get_charset())); } } $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => '92e657f8b9a3642df053f54e724e66f6', 'URL' => $url, 'NAME' => $title, 'CHILDREN' => array())); $_pages[$title] = $temp->evaluate(); // FUDGEFUDGE } elseif (count($entrypoints) != 0) { foreach ($entrypoints as $entrypoint => $title) { if (($entrypoint == 'concede' || $entrypoint == 'invisible' || $entrypoint == 'logout') && is_guest()) { continue; } if ($entrypoint == '!') { $url = build_url(array('page' => $page), $zone, NULL, false, false, true); } else { $url = build_url(array('page' => $page, 'type' => $entrypoint), $zone, NULL, false, false, true); } $_entrypoints[$title] = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => 'ae2ed2549644a8e699e0938b3ab98ddb', 'URL' => $url, 'NAME' => do_lang_tempcode($title), 'CHILDREN' => array())); } //ksort($_entrypoints); $title = do_lang('MODULE_TRANS_NAME_' . $page, NULL, NULL, NULL, NULL, false); if (is_null($title)) { $title = ucwords(str_replace('_', ' ', preg_replace('#^ocf\\_#', '', preg_replace('#^' . str_replace('#', '\\#', preg_quote($zone)) . '_#', '', preg_replace('#^' . str_replace('#', '\\#', preg_quote(str_replace('zone', '', $zone))) . '_#', '', $page))))); } if (count($_entrypoints) == 1) { $temp_keys = array_keys($_entrypoints); $temp = $_entrypoints[$temp_keys[0]]; } else { $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => 'dfc5cc7db0301acd938d3b2e3fceaab8', 'URL' => new ocp_tempcode(), 'NAME' => $title, 'CHILDREN' => $_entrypoints)); } $_pages[$title] = $temp->evaluate(); // FUDGEFUDGE } } } $url = new ocp_tempcode(); if ($_pages != array()) { $keys = array_keys($_pages); $first = $_pages[$keys[0]]; ksort($_pages); $_pages = array($keys[0] => $first) + $_pages; } $temp = do_template('BLOCK_MAIN_SITEMAP_NEST', array('_GUID' => '38abb0a0e5bec968b28b4791320dd0dc', 'URL' => $url, 'NAME' => $zone_title, 'CHILDREN' => $_pages)); $_zones[] = $temp->evaluate(); // FUDGEFUDGE } } // To avoid running out of memory $out = do_template('BLOCK_MAIN_SITEMAP', array('_GUID' => 'd0807b30925e47d10cdb2c36231436ab', 'CHILDREN' => $_zones)); $e = $out->evaluate(); $explode = explode('__keep__', $e); // the URLs are build without keep and the templates tack it on the end if (strpos($e, '__keep__') !== false) { $out = new ocp_tempcode(); foreach ($explode as $i => $bit) { if ($i != 0) { $out->attach(symbol_tempcode('KEEP', NULL, array(ENTITY_ESCAPED))); } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($bit); } $out->attach($bit); } } $e = $out->evaluate(); if (strpos($e, '__keep1__') !== false) { $explode = explode('__keep1__', $e); $out = new ocp_tempcode(); foreach ($explode as $i => $bit) { if ($i != 0) { $out->attach(symbol_tempcode('KEEP', array('1'), array(ENTITY_ESCAPED))); } if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($bit); } $out->attach($bit); } } return $out; }
/** * Actualiser: process quiz results. * * @return tempcode The result of execution. */ function _do_quiz() { $id = get_param_integer('id'); $quizzes = $GLOBALS['SITE_DB']->query_select('quizzes', array('*'), array('id' => $id), '', 1); if (!array_key_exists(0, $quizzes)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $quiz = $quizzes[0]; $this->enforcement_checks($quiz); $last_visit_time = $GLOBALS['SITE_DB']->query_value_null_ok('quiz_member_last_visit', 'v_time', array('v_quiz_id' => $id, 'v_member_id' => get_member()), 'ORDER BY v_time DESC'); if (is_null($last_visit_time)) { warn_exit(do_lang_tempcode('QUIZ_TWICE')); } if (!is_null($quiz['q_timeout'])) { if (time() - $last_visit_time > $quiz['q_timeout'] * 60 + 10) { warn_exit(do_lang_tempcode('TOO_LONG_ON_SCREEN')); } // +10 is for page load time, worst case scenario to be fair } // Our entry $entry_id = $GLOBALS['SITE_DB']->query_insert('quiz_entries', array('q_time' => time(), 'q_member' => get_member(), 'q_quiz' => $id, 'q_results' => 0), true); $GLOBALS['SITE_DB']->query_update('quiz_member_last_visit', array('v_time' => time() - (is_null($quiz['q_timeout']) ? 0 : $quiz['q_timeout']) * 60), array('v_member_id' => get_member(), 'v_quiz_id' => $id), '', 1); // Calculate results and store $questions = $GLOBALS['SITE_DB']->query_select('quiz_questions', array('*'), array('q_quiz' => $id)); foreach ($questions as $i => $question) { $answers = $GLOBALS['SITE_DB']->query_select('quiz_question_answers', array('*'), array('q_question' => $question['id'])); $questions[$i]['answers'] = $answers; } $marks = 0.0; $potential_extra_marks = 0; $out_of = count($questions); if ($out_of == 0) { $out_of = 1; } $results = array(); $corrections = array(); $unknowns = array(); foreach ($questions as $i => $question) { $name = 'q_' . strval($question['id']); if ($question['q_num_choosable_answers'] == 0) { if (count($question['answers']) == 0) { $potential_extra_marks++; $unknowns[] = array(get_translated_text($question['q_question_text']), post_param($name)); } else { $was_right = false; $correct_answer = new ocp_tempcode(); $correct_explanation = NULL; foreach ($question['answers'] as $a) { if ($a['q_is_correct'] == 1) { $correct_answer = make_string_tempcode(escape_html(get_translated_text($a['q_answer_text']))); } if ($a['q_is_correct'] == 1 && get_translated_text($a['q_answer_text']) == post_param($name)) { $marks++; $was_right = true; break; } if (get_translated_text($a['q_answer_text']) == post_param($name)) { $correct_explanation = $a['q_explanation']; } } if (!$was_right) { $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, post_param($name)); if (!is_null($correct_explanation)) { $explanation = get_translated_text($correct_explanation); if ($explanation != '') { $correction[] = $explanation; } } $corrections[] = $correction; } } $results[$i] = post_param($name); $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => $results[$i])); } elseif ($question['q_num_choosable_answers'] > 1) { // Vector distance $wrongness = 0.0; $accum = new ocp_tempcode(); $correct_answer = new ocp_tempcode(); $correct_explanation = NULL; foreach ($question['answers'] as $a) { $for_this = post_param_integer($name . '_' . strval($a['id']), 0); $should_be_this = $a['q_is_correct']; $dist = $for_this - $should_be_this; $wrongness += $dist * $dist; if ($should_be_this == 1) { if (!$correct_answer->is_empty()) { $correct_answer->attach(do_lang_tempcode('LIST_SEP')); } $correct_answer->attach(escape_html(get_translated_text($a['q_answer_text']))); $correct_explanation = $a['q_explanation']; } if ($for_this == 1) { if (!$accum->is_empty()) { $accum->attach(do_lang_tempcode('LIST_SEP')); } $accum->attach(escape_html(get_translated_text($a['q_answer_text']))); $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => strval($a['id']))); } } $wrongness = sqrt($wrongness); // Normalise it $wrongness /= count($question['answers']); // And get our complement $correctness = 1.0 - $wrongness; $marks += $correctness; if ($correctness != 1.0) { $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, $accum); if (!is_null($correct_explanation)) { $explanation = get_translated_text($correct_explanation); if ($explanation != '') { $correction[] = $explanation; } } $corrections[] = $correction; } $results[$i] = $accum->evaluate(); } else { $was_right = false; $correct_answer = new ocp_tempcode(); $correct_explanation = NULL; foreach ($question['answers'] as $a) { if ($a['q_is_correct'] == 1) { $correct_answer = make_string_tempcode(escape_html(get_translated_text($a['q_answer_text']))); } if (post_param_integer($name, -1) == $a['id']) { $results[$i] = get_translated_text($a['q_answer_text']); if ($a['q_is_correct'] == 1) { $was_right = true; $marks++; break; } $correct_explanation = $a['q_explanation']; } } $GLOBALS['SITE_DB']->query_insert('quiz_entry_answer', array('q_entry' => $entry_id, 'q_question' => $question['id'], 'q_answer' => post_param($name, ''))); if (!array_key_exists($i, $results)) { $results[$i] = '/'; } if (!$was_right) { $correction = array($question['id'], get_translated_text($question['q_question_text']), $correct_answer, $results[$i]); if (!is_null($correct_explanation)) { $explanation = get_translated_text($correct_explanation); if ($explanation != '') { $correction[] = $explanation; } } $corrections[] = $correction; } } } $mail_title = do_lang('EMAIL_TITLE', do_lang($quiz['q_type']), $GLOBALS['FORUM_DRIVER']->get_username(get_member()), strval($entry_id), get_site_default_lang()); $_corrections = new ocp_tempcode(); $_corrections_to_show = new ocp_tempcode(); foreach ($corrections as $correction) { $this_correction = new ocp_tempcode(); $this_correction->attach(do_lang('QUIZ_MISTAKE', is_object($correction[1]) ? $correction[1]->evaluate() : $correction[1], is_object($correction[3]) ? $correction[3]->evaluate() : $correction[3], array(is_object($correction[2]) ? $correction[2]->evaluate() : $correction[2], array_key_exists(4, $correction) ? $correction[4] : ''))); if (array_key_exists(4, $correction)) { $_corrections_to_show->attach($this_correction); } $_corrections->attach($this_correction); } $_answers = new ocp_tempcode(); foreach ($results as $i => $result) { $_answers->attach(do_lang('QUIZ_RESULT', get_translated_text($questions[$i]['q_question_text']), is_null($result) ? '' : $result)); } $_unknowns = new ocp_tempcode(); foreach ($unknowns as $unknown) { $_unknowns->attach(do_lang('QUIZ_UNKNOWN', $unknown[0], $unknown[1])); } require_code('notifications'); // Award points? if ($out_of == 0) { $out_of = 1; } $minimum_percentage = intval(round(100.0 * $marks / $out_of)); $maximum_percentage = intval(round(100.0 * ($marks + $potential_extra_marks) / $out_of)); if (addon_installed('points') && $quiz['q_points_for_passing'] != 0 && ($quiz['q_type'] != 'TEST' || $minimum_percentage >= $quiz['q_percentage'])) { require_code('points2'); $points_difference = $quiz['q_points_for_passing']; system_gift_transfer(do_lang('POINTS_COMPLETED_QUIZ', get_translated_text($quiz['q_name'])), $points_difference, get_member()); } else { $points_difference = 0; } // Give them their result if it is a test. if ($quiz['q_type'] == 'TEST') { $result = new ocp_tempcode(); $result->attach(paragraph(do_lang_tempcode('MARKS_OUT_OF', float_format($marks) . ($potential_extra_marks == 0 ? '' : '-' . float_format($marks + $potential_extra_marks)), integer_format($out_of), strval($minimum_percentage) . ($potential_extra_marks == 0 ? '' : '-' . strval($maximum_percentage))), 'trete9r0itre')); $result2 = do_lang_tempcode('MAIL_MARKS_OUT_OF', float_format($marks) . ($potential_extra_marks == 0 ? '' : '-' . float_format($marks + $potential_extra_marks)), integer_format($out_of), strval($minimum_percentage) . ($potential_extra_marks == 0 ? '' : '-' . strval($maximum_percentage))); if ($minimum_percentage >= $quiz['q_percentage']) { $result->attach(paragraph(do_lang_tempcode('TEST_PASS'), '4tfdhdhghh')); $result2->attach(do_lang_tempcode('MAIL_TEST_PASS')); syndicate_described_activity('quiz:ACTIVITY_PASSED_TEST', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes'); } elseif ($maximum_percentage < $quiz['q_percentage']) { $result->attach(paragraph(do_lang_tempcode('TEST_FAIL'), '5yrgdgsdg')); $result2->attach(do_lang_tempcode('MAIL_TEST_FAIL')); } else { $result->attach(paragraph(do_lang_tempcode('TEST_UNKNOWN'), 'yteyrthrt')); $result2->attach(do_lang_tempcode('MAIL_TEST_UNKNOWN')); } // Send mail about the result to the staff: include result and corrections, and unknowns $mail = do_template('QUIZ_TEST_ANSWERS_MAIL', array('_GUID' => 'a0f8f47cdc1ef83b59c93135ebb5c114', 'UNKNOWNS' => $_unknowns, 'CORRECTIONS' => $_corrections, 'RESULT' => $result2, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()))); dispatch_notification('quiz_results', strval($id), $mail_title, $mail->evaluate(get_site_default_lang())); } elseif ($quiz['q_type'] == 'COMPETITION') { $result = comcode_to_tempcode($_corrections->evaluate()); syndicate_described_activity('quiz:ACTIVITY_ENTERED_COMPETITION', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes'); } else { $result = paragraph(do_lang_tempcode('SURVEY_THANKYOU'), '4rtyrthgf'); $_answers = do_template('QUIZ_ANSWERS_MAIL', array('_GUID' => '381f392c8e491b6e078bcae34adc45e8', 'ANSWERS' => $_answers, 'MEMBER_PROFILE_URL' => is_guest() ? '' : $GLOBALS['FORUM_DRIVER']->member_profile_url(get_member(), false, true), 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()))); // Send mail of answers to the staff dispatch_notification('quiz_results', strval($id), $mail_title, $_answers->evaluate(get_site_default_lang())); syndicate_described_activity('quiz:ACTIVITY_FILLED_SURVEY', get_translated_text($quiz['q_name']), '', '', '_SEARCH:quiz:do:' . strval($id), '', '', 'quizzes'); } // Store results for entry $GLOBALS['SITE_DB']->query_update('quiz_entries', array('q_results' => intval(round($marks))), array('id' => $entry_id), '', 1); breadcrumb_set_self(do_lang_tempcode('DONE')); breadcrumb_set_parents(array(array('_SELF:_SELF:misc', make_string_tempcode(escape_html(get_translated_text($quiz['q_name'])))))); // Show end text $title = get_page_title(do_lang_tempcode('THIS_WITH', do_lang_tempcode($quiz['q_type']), make_string_tempcode(escape_html(get_translated_text($quiz['q_name'])))), false); $fail_text = get_translated_tempcode($quiz['q_end_text_fail']); $message = $quiz['q_type'] != 'TEST' || $minimum_percentage >= $quiz['q_percentage'] || $fail_text->is_empty() ? get_translated_tempcode($quiz['q_end_text']) : get_translated_tempcode($quiz['q_end_text_fail']); return do_template('QUIZ_DONE_SCREEN', array('_GUID' => 'fa783f087eca7f8f577b134ec0bdc4ce', 'CORRECTIONS_TO_SHOW' => comcode_to_tempcode($_corrections_to_show->evaluate()), 'POINTS_DIFFERENCE' => strval($points_difference), 'RESULT' => $result, 'TITLE' => $title, 'TYPE' => $quiz['q_type'], 'MESSAGE' => $message)); }
/** * Actualise ticket creation/reply, then show the ticket again. * * @return tempcode The UI */ function do_update_ticket() { $title = get_page_title('SUPPORT_TICKETS'); $id = get_param('id'); $_title = post_param('title'); $post = post_param('post'); if ($post == '') { warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post')); } $ticket_type = post_param_integer('ticket_type', -1); $this->check_id($id); $staff_only = post_param_integer('staff_only', 0) == 1; // Update $_home_url = build_url(array('page' => '_SELF', 'type' => 'ticket', 'id' => $id, 'redirect' => NULL), '_SELF', NULL, false, true, true); $home_url = $_home_url->evaluate(); $email = ''; if ($ticket_type != -1) { $type_string = get_translated_text($ticket_type); $ticket_type_details = get_ticket_type($ticket_type); //$_title=$type_string.' ('.$_title.')'; if (!has_category_access(get_member(), 'tickets', $type_string)) { access_denied('I_ERROR'); } // Check FAQ search results first if ($ticket_type_details['search_faq'] && post_param_integer('faq_searched', 0) == 0) { $results = $this->do_search($title, $id, $post); if (!is_null($results)) { return $results; } } $new_post = new ocp_tempcode(); $new_post->attach(do_lang('THIS_WITH_COMCODE', do_lang('TICKET_TYPE'), $type_string) . "\n\n"); $email = trim(post_param('email', '')); if ($email != '') { $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post); if (substr($body, -2) == '> ') { $body = substr($body, 0, strlen($body) - 2); } $new_post->attach('[email subject="Re: ' . comcode_escape(post_param('title')) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n"); } elseif (is_guest() && $ticket_type_details['guest_emails_mandatory']) { // Error if the e-mail address is required for this ticket type warn_exit(do_lang_tempcode('ERROR_GUEST_EMAILS_MANDATORY')); } $new_post->attach($post); $post = $new_post->evaluate(); } if (addon_installed('captcha')) { if (get_option('captcha_on_feedback') == '1') { require_code('captcha'); enforce_captcha(); } } ticket_add_post(get_member(), $id, $ticket_type, $_title, $post, $home_url, $staff_only); // Find true ticket title $_forum = 1; $_topic_id = 1; $_ticket_type = 1; // These will be returned by reference $posts = get_ticket_posts($id, $_forum, $_topic_id, $_ticket_type); if (!is_array($posts)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $__title = $_title; foreach ($posts as $ticket_post) { $__title = $ticket_post['title']; if ($__title != '') { break; } } // Send email if (!$staff_only) { if ($email == '') { $email = $GLOBALS['FORUM_DRIVER']->get_member_email_address(get_member()); } send_ticket_email($id, $__title, $post, $home_url, $email, $ticket_type); } $url = build_url(array('page' => '_SELF', 'type' => 'ticket', 'id' => $id), '_SELF'); if (is_guest()) { $url = build_url(array('page' => '_SELF'), '_SELF'); } if (get_param('redirect', '') != '') { $url = make_string_tempcode(get_param('redirect')); } return redirect_screen($title, $url, do_lang_tempcode('TICKET_STARTED')); }
/** * Get the tempcode for the breadcrumbs. * * @return tempcode The breadcrumbs */ function breadcrumbs() { global $BREADCRUMB_SET_PARENTS, $BREADCRUMBS, $BREADCRUMB_EXTRA_SEGMENTS; $show_top = get_param_integer('wide_high', get_param_integer('keep_wide_high', 0)) != 1; if (!$show_top) { return new ocp_tempcode(); } if ($BREADCRUMBS === NULL) { $BREADCRUMBS = breadcrumbs_get_default_stub($BREADCRUMB_EXTRA_SEGMENTS->is_empty()); } $out = new ocp_tempcode(); $out->attach($BREADCRUMBS); if (!$BREADCRUMB_EXTRA_SEGMENTS->is_empty()) { if (!$out->is_empty()) { $out->attach(do_template('BREADCRUMB_ESCAPED')); } $out->attach($BREADCRUMB_EXTRA_SEGMENTS); } // Substitutions (deprecated hardcoding example) $segment_substitutions = array(); $root = get_param('keep_catalogue_root_page', NULL); if ($root !== NULL) { $page_name = get_param('keep_catalogue_root_page_name'); $target_url = build_url(array('page' => $root), '_SEARCH'); $breadcrumb_tpl = do_template('BREADCRUMB_ESCAPED'); $from = '\\<a title="[^"]*" href="[^"]*/site/index.php\\?page=catalogues&type=misc[^"]*"\\>Catalogues\\</a\\>' . $breadcrumb_tpl->evaluate(); $to = '<a title="' . do_lang('GO_BACKWARDS_TO', escape_html(strip_tags($page_name))) . '" href="' . escape_html($target_url->evaluate()) . '">' . escape_html($page_name) . '</a>' . $breadcrumb_tpl->evaluate(); $segment_substitutions[$from] = $to; } // Substitutions (XML) if (addon_installed('breadcrumbs') && function_exists('xml_parser_create')) { $data = @file_get_contents(get_custom_file_base() . '/data_custom/breadcrumbs.xml', FILE_TEXT); if ($data === false && get_custom_file_base() != get_file_base()) { $data = @file_get_contents(get_file_base() . '/data_custom/breadcrumbs.xml', FILE_TEXT); } if (trim($data) != '') { require_code('breadcrumbs'); $segment_substitutions = array_merge($segment_substitutions, load_breadcrumb_substitutions($out->evaluate(), $data)); } } if (count($segment_substitutions) != 0) { $_out = $out->evaluate(); foreach ($segment_substitutions as $from => $to) { $_out = preg_replace('~' . str_replace('~', '\\~', $from) . '~Us', $to, $_out, 1); } return make_string_tempcode($_out); } return $out; }
/** * Get tempcode for a news adding/editing form. * * @param ?AUTO_LINK The primary category for the news (NULL: personal) * @param ?array A list of categories the news is in (NULL: not known) * @param SHORT_TEXT The news title * @param LONG_TEXT The news summary * @param SHORT_TEXT The name of the author * @param BINARY Whether the news is validated * @param ?BINARY Whether rating is allowed (NULL: decide statistically, based on existing choices) * @param ?SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) (NULL: decide statistically, based on existing choices) * @param ?BINARY Whether trackbacks are allowed (NULL: decide statistically, based on existing choices) * @param BINARY Whether to show the "send trackback" field * @param LONG_TEXT Notes for the video * @param URLPATH URL to the image for the news entry (blank: use cat image) * @param ?array Scheduled go-live time (NULL: N/A) * @return array A tuple of lots of info (fields, hidden fields, trailing fields) */ function get_form_fields($main_news_category = NULL, $news_category = NULL, $title = '', $news = '', $author = '', $validated = 1, $allow_rating = NULL, $allow_comments = NULL, $allow_trackbacks = NULL, $send_trackbacks = 1, $notes = '', $image = '', $scheduled = NULL) { list($allow_rating, $allow_comments, $allow_trackbacks) = $this->choose_feedback_fields_statistically($allow_rating, $allow_comments, $allow_trackbacks); global $NON_CANONICAL_PARAMS; $NON_CANONICAL_PARAMS[] = 'validated'; if (is_null($main_news_category)) { $NON_CANONICAL_PARAMS[] = 'cat'; $param_cat = get_param('cat', ''); if ($param_cat == '') { $news_category = array(); $main_news_category = NULL; } elseif (strpos($param_cat, ',') === false) { $news_category = array(); $main_news_category = intval($param_cat); } else { require_code('ocfiltering'); $news_category = ocfilter_to_idlist_using_db($param_cat, 'id', 'news_categories', 'news_categories', NULL, 'id', 'id'); $main_news_category = NULL; } $author = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); } $cats1 = nice_get_news_categories($main_news_category, false, true, false, true); $cats2 = nice_get_news_categories(is_null($news_category) || count($news_category) == 0 ? array(get_param_integer('cat', NULL)) : $news_category, false, true, true, false); $fields = new ocp_tempcode(); $fields2 = new ocp_tempcode(); $hidden = new ocp_tempcode(); require_code('form_templates'); $fields->attach(form_input_line_comcode(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true)); if ($validated == 0) { $validated = get_param_integer('validated', 0); if ($validated == 1) { attach_message(do_lang_tempcode('WILL_BE_VALIDATED_WHEN_SAVING')); } } if (has_some_cat_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', 'cms_news', $this->permissions_cat_require)) { if (addon_installed('unvalidated')) { $fields2->attach(form_input_tick(do_lang_tempcode('VALIDATED'), do_lang_tempcode('DESCRIPTION_VALIDATED'), 'validated', $validated == 1)); } } if ($cats1->is_empty()) { warn_exit(do_lang_tempcode('NO_CATEGORIES')); } if (addon_installed('authors')) { $hidden->attach(form_input_hidden('author', $author)); } $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => (is_null($news_category) || count($news_category) == 0) && $image == '' && (is_null($news_category) || $news_category == array()), 'TITLE' => do_lang_tempcode('ADVANCED')))); $fields2->attach(form_input_text_comcode(do_lang_tempcode('BLOG_NEWS_SUMMARY'), do_lang_tempcode('DESCRIPTION_NEWS_SUMMARY'), 'news', $news, false)); if (get_value('disable_secondary_news') !== '1') { $fields2->attach(form_input_list(do_lang_tempcode('MAIN_CATEGORY'), do_lang_tempcode('DESCRIPTION_MAIN_CATEGORY'), 'main_news_category', $cats1)); } else { $fields2->attach(form_input_hidden('main_news_category', is_null($main_news_category) ? 'personal' : strval($main_news_category))); } if (get_value('disable_secondary_news') !== '1') { $fields2->attach(form_input_multi_list(do_lang_tempcode('SECONDARY_CATEGORIES'), do_lang_tempcode('DESCRIPTION_SECONDARY_CATEGORIES'), 'news_category', $cats2)); } $fields2->attach(form_input_upload(do_lang_tempcode('IMAGE'), do_lang_tempcode('DESCRIPTION_NEWS_IMAGE_OVERRIDE'), 'file', false, $image, NULL, true, str_replace(' ', '', get_option('valid_images')))); //handle_max_file_size($hidden,'image'); Attachments will add this if (addon_installed('calendar') && has_specific_permission(get_member(), 'scheduled_publication_times')) { $fields2->attach(form_input_date__scheduler(do_lang_tempcode('PUBLICATION_TIME'), do_lang_tempcode('DESCRIPTION_PUBLICATION_TIME'), 'schedule', true, true, true, $scheduled, intval(date('Y')) - 1970 + 2, 1970)); } require_code('feedback2'); $fields2->attach(feedback_fields($allow_rating == 1, $allow_comments == 1, $allow_trackbacks == 1, $send_trackbacks == 1, $notes, $allow_comments == 2)); $fields2->attach(get_syndication_option_fields()); return array($fields, $hidden, NULL, NULL, NULL, NULL, make_string_tempcode($fields2->evaluate())); }
/** * Bind the parameter bits, or recursively bind children (doesn't change self, returns a bound tempcode object) * * @param array Map of parameters to bind parameter bits to * @param ID_TEXT The codename of the template this tempcode is from * @return tempcode The new bound tempcode object */ function bind(&$parameters, $codename) { if (!isset($parameters['_GUID'])) { $parameters['_GUID'] = ''; static $dbt = NULL; if ($dbt === NULL) { $dbt = function_exists('debug_backtrace'); } if ($dbt) { $trace = debug_backtrace(); $parameters['_GUID'] = isset($trace[3]) ? $trace[3]['function'] . '/' . $trace[2]['function'] : (isset($trace[2]) ? $trace[2]['function'] : $trace[1]['function']); } } $out = new ocp_tempcode(); $out->codename = $codename; $out->code_to_preexecute = $this->code_to_preexecute; $out->preprocessable_bits = array(); foreach ($this->preprocessable_bits as $preprocessable_bit) { foreach ($preprocessable_bit[3] as $i => $param) { if (($preprocessable_bit[2] != 'SET' || $i == 1) && is_object($param)) { $preprocessable_bit[3][$i] = $param->bind($parameters, ''); } } $out->preprocessable_bits[] = $preprocessable_bit; } if ($GLOBALS['RECORD_TEMPLATES_TREE']) { $out->children = isset($this->children) ? $this->children : array(); foreach ($parameters as $key => $parameter) { if (is_object($parameter)) { if (count($parameter->preprocessable_bits) != 0) { $parameter->handle_symbol_preprocessing(); } // Needed to force children to be populated. Otherwise it is possible but not definite that evaluation will result in children being pushed down (SHIFT_ENCODING in a template can cause them to be misappropriated, as it causes a runtime cache string in the Tempcode tree). $out->children[] = array($parameter->codename, isset($parameter->children) ? $parameter->children : array(), isset($parameter->fresh) ? $parameter->fresh : false); } elseif (is_string($parameter) && $key == '_GUID') { $out->children[] = array(':guid', array(array(':' . $parameter, array(), true)), true); } } } foreach ($parameters as $key => $parameter) { $p_type = gettype($parameter); if ($p_type == 'string') { // Performance, this is most likely } elseif ($p_type == 'object') { if (isset($parameter->preprocessable_bits[0])) { $out->preprocessable_bits = array_merge($out->preprocessable_bits, $parameter->preprocessable_bits); } elseif (!isset($parameter->seq_parts[0])) { $parameters[$key] = ''; } // Little optimisation to save memory } elseif ($p_type == 'boolean') { $parameters[$key] = $parameter ? '1' : '0'; } elseif ($p_type != 'array' && $p_type != 'NULL') { warn_exit(do_lang_tempcode('NO_INTEGERS_TEMPLATE', escape_html($key))); } } foreach ($this->seq_parts as $bit) { if (($bit[0][0] != 's' || substr($bit[0], 0, 14) != 'string_attach_') && $bit[2] != TC_LANGUAGE_REFERENCE) { $bit[1] =& $parameters; } // & is to preserve memory $out->seq_parts[] = $bit; } // Force pre-execution, so shift encoding handled. This is prior to pre-processing (it needs to be for validity in interaction with what is in itself preprocessed), so you could consider it pre-pre-processing if (strpos($out->code_to_preexecute, 'SHIFT_ENCODE') !== false) { $out->evaluate(); } return $out; }
/** * Get information for the user relating to an addon that they are intending to uninstall. * * @param string Name of the addon * @param ?array List of addons that we're currently uninstalling (so dependencies from these are irrelevant). (NULL: none) * @param ?array Addon details. (NULL: load in function) * @return array Pair: warnings, files */ function inform_about_addon_uninstall($name, $also_uninstalling = NULL, $addon_row = NULL) { if (is_null($also_uninstalling)) { $also_uninstalling = array(); } // Read/show info if (is_null($addon_row)) { $addon_row = read_addon_info($name); } $files = new ocp_tempcode(); // The files can come in as either a newline-separated string or an array. // If its an array then we use it as-is, if it's a string then we explode it first. if (is_array($addon_row['addon_files'])) { $loopable = $addon_row['addon_files']; } else { $loopable = explode(chr(10), $addon_row['addon_files']); } foreach ($loopable as $i => $filename) { $files->attach(do_template('ADDON_INSTALL_FILES', array('I' => strval($i), 'DISABLED' => true, 'PATH' => $filename))); } // Check dependencies $dependencies = $addon_row['addon_dependencies_on_this']; foreach ($also_uninstalling as $d) { if (in_array($d, $dependencies)) { unset($dependencies[array_search($d, $dependencies)]); } } $warnings = new ocp_tempcode(); $_dependencies_str = new ocp_tempcode(); foreach ($dependencies as $in) { if (!$_dependencies_str->is_empty()) { $_dependencies_str->attach(do_lang_tempcode('LIST_SEP')); } $_dependencies_str->attach(escape_html($in)); } if (count($dependencies) != 0) { if ($addon_row['addon_author'] == 'Core Team') { $post_fields = build_keep_post_fields(); foreach ($dependencies as $in) { $post_fields->attach(form_input_hidden('uninstall_' . $in, $in)); } if (get_param('type', 'misc') == 'addon_uninstall') { $post_fields->attach(form_input_hidden('uninstall_' . $name, $name)); $url = static_evaluate_tempcode(build_url(array('page' => '_SELF', 'type' => 'multi_action'), '_SELF')); } else { $url = get_self_url(true); } warn_exit(do_lang_tempcode('_ADDON_WARNING_PRESENT_DEPENDENCIES', $_dependencies_str->evaluate(), escape_html($name), array(escape_html($url), $post_fields))); } else { $warnings->attach(do_template('ADDON_INSTALL_WARNING', array('WARNING' => do_lang_tempcode('ADDON_WARNING_PRESENT_DEPENDENCIES', $_dependencies_str, escape_html($name))))); } } return array($warnings, $files); }
/** * Evaluate a conventional tempcode variable, handling escaping * * @param LANGUAGE_NAME The language to evaluate this symbol in (some symbols refer to language elements) * @param array Array of escaping operations * @param integer The type of symbol this is (TC_SYMBOL, TC_LANGUAGE_REFERENCE) * @set 0 2 * @param ID_TEXT The name of the symbol * @param array Parameters to the symbol. For all but directive it is an array of strings. For directives it is an array of Tempcode objects. Actually there may be template-style parameters in here, as an influence of singular_bind and these may be Tempcode, but we ignore them. * @return mixed The result. Either tempcode, or a string. */ function ecv($lang, $escaped, $type, $name, $param) { global $TEMPCODE_SETGET, $CYCLES, $PREPROCESSABLE_SYMBOLS, $DISPLAYED_TITLE; //echo '<!--'.$name.'-->'."\n"; if ($type == TC_SYMBOL) { $escaped_codes = $name . ($escaped == array() ? '' : serialize($escaped)); $cacheable = $param == array() && !isset($GLOBALS['NON_CACHEABLE_SYMBOLS'][$name]); if ($cacheable) { global $SYMBOL_CACHE; if (isset($SYMBOL_CACHE[$escaped_codes])) { return $SYMBOL_CACHE[$escaped_codes]; } } $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } $temp_array = array(); if (isset($PREPROCESSABLE_SYMBOLS[$name]) && $name != 'PAGE_LINK') { handle_symbol_preprocessing(array($escaped, $type, $name, $param), $temp_array); } // Late preprocessing. Should not be needed in case of full screen output (as this was properly preprocessed), but is in other cases switch ($name) { case 'PAGE_LINK': if (isset($param[0])) { list($zone, $map, $hash) = page_link_decode(is_object($param[0]) ? $param[0]->evaluate() : $param[0]); $skip = NULL; if (isset($param[4])) { $skip = array_flip(explode('|', $param[4])); } $avoid_remap = isset($param[1]) && $param[1] == '1'; $skip_keep = isset($param[2]) && $param[2] == '1'; $keep_all = isset($param[3]) && $param[3] == '1'; foreach ($map as $key => $val) { if (is_object($val)) { $map[$key] = $val->evaluate(); } } $value = _build_url($map, $zone, $skip, $keep_all, $avoid_remap, $skip_keep, $hash); } else { $value = get_zone_name() . ':' . get_page_name(); foreach ($_GET as $key => $val) { if ($key == 'page') { continue; } if (is_array($val)) { continue; } if (substr($key, 0, 5) == 'keep_' && !skippable_keep($key, $val)) { continue; } $value .= ':' . $key . '=' . $val; } } break; case 'SET': if (isset($param[1])) { if (isset($param[1]) && is_object($param[1])) { $TEMPCODE_SETGET[$param[0]] = $param[1]; } else { $param_copy = $param; unset($param_copy[0]); $TEMPCODE_SETGET[$param[0]] = implode(',', $param_copy); } } break; case 'GET': if (isset($param[0])) { if (isset($TEMPCODE_SETGET[$param[0]])) { if (is_object($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = $TEMPCODE_SETGET[$param[0]]->evaluate(); } $value = $TEMPCODE_SETGET[$param[0]]; } } break; case 'EQ': if (isset($param[1])) { $first = array_shift($param); $count = 0; foreach ($param as $test) { if ($first == $test) { $count++; break; } } $value = $count != 0 ? '1' : '0'; } break; case 'NEQ': if (isset($param[1])) { $first = array_shift($param); $count = 0; foreach ($param as $test) { if ($first == $test) { $count++; } } $value = $count == 0 ? '1' : '0'; } break; case 'NOT': if (isset($param[0])) { $value = $param[0] == '1' || $param[0] == '1' ? '0' : '1'; } break; case 'OR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count > 0 ? '1' : '0'; break; case 'AND': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == count($param) ? '1' : '0'; break; case 'HAS_ACTUAL_PAGE_ACCESS': if (isset($param[0])) { $value = has_actual_page_access($param !== NULL && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], isset($param[1]) ? $param[1] : NULL) ? '1' : '0'; } break; case '?': if (isset($param[1])) { $value = $param[0] == '1' || $param[0] == '1' ? $param[1] : (isset($param[2]) ? $param[2] : $value); } break; case 'IMG': if (isset($param[0]) && isset($GLOBALS['SITE_DB']) && function_exists('find_theme_image') && $GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { $value = find_theme_image($param[0], isset($param[3]) && $param[3] == '1', false, array_key_exists(2, $param) && $param[2] != '' ? $param[2] : NULL, NULL, isset($param[1]) && $param[1] == '1' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']); } break; case '': break; case 'META_DATA': if (isset($param[0])) { global $META_DATA; if (isset($param[1])) { $matches = array(); if ($param[0] == 'image' && preg_match('#^' . preg_quote(find_script('attachment'), '#') . '\\?id=(\\d+)#', $param[1], $matches) != 0) { require_code('attachments'); if (!has_attachment_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), intval($matches[1]))) { break; } } $META_DATA[$param[0]] = $param[1]; } else { $value = isset($META_DATA[$param[0]]) ? strip_comcode($META_DATA[$param[0]]) : ''; if ($value === NULL) { $value = ''; } } } break; case 'SPECIAL_CLICK_TO_EDIT': $_value = do_lang_tempcode('SPECIAL_CLICK_TO_EDIT'); $value = $_value->evaluate(); break; case 'KEEP': // What needs preserving in the URL $value = keep_symbol($param); break; case 'BROWSER': if (isset($param[1])) { $q = false; foreach (explode('|', $param[0]) as $browser) { $q = browser_matches($browser); if ($q) { break; } } $value = $q ? $param[1] : (isset($param[2]) ? $param[2] : ''); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } } break; case 'JAVASCRIPT_INCLUDE': if (isset($param[0])) { require_javascript($param[0]); /*// Has to do this inline, as you're not allowed to reference scripts outside head if (!array_key_exists($param[0],$GLOBALS['JAVASCRIPTS'])) { $GLOBALS['JAVASCRIPTS'][$param[0]]=1; $file=javascript_enforce($param[0]); $_value=do_template('JAVASCRIPT_NEED_INLINE',array('_GUID'=>'d6c907e26c5a8dd8c65f1d36a1a674a9','CODE'=>file_get_contents($file,FILE_TEXT))); $value=$_value->evaluate(); }*/ } break; case 'FACILITATE_AJAX_BLOCK_CALL': if (isset($param[0])) { require_javascript('javascript_ajax'); require_code('blocks'); $_block_constraints = block_params_to_block_signature(block_params_str_to_arr($param[0])); if (array_key_exists(1, $param)) { $_block_constraints = array_merge($_block_constraints, block_params_str_to_arr($param[1])); ksort($_block_constraints); } $block_constraints = block_params_arr_to_str($_block_constraints); // Store permissions $_auth_key = $GLOBALS['SITE_DB']->query_select('temp_block_permissions', array('id', 'p_time'), array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints), '', 1); if (!array_key_exists(0, $_auth_key)) { $auth_key = $GLOBALS['SITE_DB']->query_insert('temp_block_permissions', array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints, 'p_time' => time()), true); } else { $auth_key = $_auth_key[0]['id']; if (time() - $_auth_key[0]['p_time'] > 100) { $GLOBALS['SITE_DB']->query_update('temp_block_permissions', array('p_time' => time()), array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints), '', 1); } } $keep = symbol_tempcode('KEEP'); $value = find_script('snippet') . '?snippet=block&auth_key=' . urlencode(strval($auth_key)) . '&block_map=' . urlencode($param[0]) . $keep->evaluate(); } break; case 'LANG': $value = user_lang(); break; case '_GET': if (isset($param[0])) { $value = get_param($param[0], isset($param[1]) ? $param[1] : '', true); } break; case 'QUERY_STRING': $value = ocp_srv('QUERY_STRING'); break; case 'USER_AGENT': $value = ocp_srv('HTTP_USER_AGENT'); break; case 'STRIP_TAGS': if (isset($param[0])) { if (isset($param[1]) && $param[1] == '1') { $value = strip_tags(str_replace('))', ')', str_replace('((', '(', str_replace('<em>', '(', str_replace('</em>', ')', $param[0]))))); } else { $value = strip_tags($param[0], array_key_exists(2, $param) ? $param[2] : ''); } if (isset($param[1]) && $param[1] == '1') { $value = @html_entity_decode($value, ENT_QUOTES, get_charset()); } } break; case 'CONFIG_OPTION': if (isset($param[0])) { if (!isset($GLOBALS['OPTIONS'])) { $value = '0'; } else { $value = get_option($param[0], true); if ($value === NULL) { $value = ''; } } } break; case 'TRUNCATE_LEFT': // Truncate the left length of a string. 0: text to truncate, 1: the truncate length, 2: whether to use a tooltip mouse-over if it is truncated, 3: whether it is encoded as HTML (0=no [default, plain-text], 1=yes) $value = symbol_truncator($param, 'left'); break; case 'TRUNCATE_RIGHT': $value = symbol_truncator($param, 'right'); break; case 'TRUNCATE_SPREAD': $value = symbol_truncator($param, 'spread'); break; case 'TRUNCATE_EXPAND': $value = symbol_truncator($param, 'expand'); break; case 'THEME': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->get_theme(); } else { $value = 'default'; } break; case 'REVERSE': if (isset($param[0])) { $value = implode(',', array_reverse(explode(',', $param[0]))); } break; case 'COMMA_LIST_GET': if (isset($param[1])) { require_code('blocks'); $values = block_params_str_to_arr($param[0]); $value = isset($values[$param[1]]) ? $values[$param[1]] : ''; } break; case 'COMMA_LIST_SET': if (isset($param[2])) { require_code('blocks'); $values = block_params_str_to_arr($param[0]); $values[$param[1]] = $param[2]; $value = block_params_arr_to_str($values); } break; case 'IS_EMPTY': if (isset($param[0])) { $value = $param[0] == '' ? '1' : '0'; } break; case 'IS_NON_EMPTY': if (isset($param[0])) { $value = $param[0] != '' ? '1' : '0'; } break; case 'CUSTOM_BASE_URL': $value = get_custom_base_url(isset($param[0]) && $param[0] != '' ? $param[0] == '1' : NULL); if (isset($param[1]) && $param[1] == '1') { $value = cdn_filter($value); } break; case 'LOAD_PANEL': foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } global $LOADED_PANELS; if (strpos($param[0], ':') !== false) { $param = array_reverse(explode(':', $param[0], 2)); } if (substr($param[0], 0, 6) == 'panel_') { $param[0] = substr($param[0], 6); } $sr = serialize($param); $value = array_key_exists($sr, $LOADED_PANELS) ? $LOADED_PANELS[$sr] : ''; break; case 'HAS_JS': case 'JS_ON': if (isset($param[1])) { $value = has_js() ? $param[0] : $param[1]; } else { $value = has_js() ? '1' : '0'; } break; case 'BASE_URL_NOHTTP': $value = preg_replace('#^https?://[^/]+#', '', get_base_url()); if (substr($value, 0, 2) == '//') { $value = substr($value, 1); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'CUSTOM_BASE_URL_NOHTTP': $value = preg_replace('#^https?://[^/]+/#', '/', get_custom_base_url()); if (substr($value, 0, 2) == '//') { $value = substr($value, 1); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'BASE_URL': $value = get_base_url(isset($param[0]) ? $param[0] == '1' : NULL); break; case 'ZONE': $value = get_zone_name(); break; case 'PAGE': $value = get_page_name(); break; case 'SITE_NAME': $value = get_site_name(); break; case 'HEADER_TEXT': global $ZONE; $value = $ZONE['zone_header_text_trans']; break; case 'PANEL_WIDTH': if (isset($TEMPCODE_SETGET['PANEL_WIDTH']) && $TEMPCODE_SETGET['PANEL_WIDTH'] != '') { $value = $TEMPCODE_SETGET['PANEL_WIDTH']; } else { $value = get_option('panel_width', true); if ($value === NULL) { $value = '13.3em'; } } break; case 'PANEL_WIDTH_SPACED': if (isset($TEMPCODE_SETGET['PANEL_WIDTH_SPACED']) && $TEMPCODE_SETGET['PANEL_WIDTH_SPACED'] != '') { $value = $TEMPCODE_SETGET['PANEL_WIDTH_SPACED']; } else { $value = get_option('panel_width_spaced', true); if (is_null($value)) { $value = '14.3em'; } } break; case 'TRIM': if (isset($param[0])) { $value = preg_replace(array('#^\\s+#', '#^(<br\\s*/?' . '>\\s*)+#', '#^( )+#', '#\\s+$#', '#(<br\\s*/?' . '>\\s*)+$#', '#( )+$#'), array('', '', '', '', '', ''), $param[0]); } break; case 'CPF_VALUE': if (isset($param[0])) { if (is_numeric($param[0])) { require_code('ocf_members'); $fields = ocf_get_custom_fields_member(isset($param[1]) ? intval($param[1]) : get_member()); if (array_key_exists(intval($param[0]), $fields)) { $_value = $fields[intval($param[0])]; } } elseif (substr($param[0], 0, 2) == 'm_' && strpos(strtolower($param[0]), 'hash') === false && strpos(strtolower($param[0]), 'salt') === false) { $_value = $GLOBALS['FORUM_DRIVER']->get_member_row_field(isset($param[1]) ? intval($param[1]) : get_member(), $param[0]); } else { $_value = get_ocp_cpf($param[0], isset($param[1]) ? intval($param[1]) : NULL); } if (!is_string($_value)) { $value = is_null($_value) ? '' : strval($_value); } else { $value = $_value; } } break; case 'BANNER': if (addon_installed('banners')) { global $SITE_INFO; $is_on_banners = get_option('is_on_banners') == '1' && (!has_specific_permission(get_member(), 'banner_free') || $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) && get_option('admin_banners') == '1' || !is_null($GLOBALS['CURRENT_SHARE_USER'])); if (array_key_exists('throttle_bandwidth_registered', $SITE_INFO)) { $views_till_now = intval(get_value('page_views')); $bandwidth_allowed = $SITE_INFO['throttle_bandwidth_registered']; $total_bandwidth = intval(get_value('download_bandwidth')); if ($bandwidth_allowed * 1024 * 1024 >= $total_bandwidth) { $is_on_banners = false; } } if ($is_on_banners && !is_page_https(get_zone_name(), get_page_name())) { require_code('banners'); $b_type = isset($param[0]) ? $param[0] : ''; $internal_only = isset($param[1]) ? intval($param[1]) : ($b_type == '' ? 0 : 1); if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { $_value = banners_script(true, '', '', $b_type, $internal_only, ''); $value = $_value->evaluate(); } else { $value = 'Banner goes here'; } } } break; case 'AVATAR': $value = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url(isset($param[0]) ? intval($param[0]) : get_member()); if (url_is_local($value) && $value != '') { $value = get_custom_base_url() . '/' . $value; } break; case 'IS_GUEST': if (isset($param[0])) { $value = is_guest(intval($param[0])) ? '1' : '0'; } else { $value = is_guest() ? '1' : '0'; } break; case 'MEMBER': $value = strval(get_member()); break; case 'USER': if (!isset($param[0])) { $value = strval(get_member()); } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($param[0]); $value = is_null($member_id) ? '' : strval($member_id); } break; case 'CSS_INCLUDE': if (isset($param[0])) { require_css($param[0]); /*// Has to do this inline, as you're not allowed to reference sheets outside head if (!array_key_exists($param[0],$GLOBALS['CSSS'])) { $GLOBALS['CSSS'][$param[0]]=1; $file=css_enforce($param[0]); $_value=do_template('CSS_NEED_INLINE',array('_GUID'=>'9de994d2f6d47a622d49347feb7ebe96','CSS'=>str_replace('../../../../',get_base_url().'/',file_get_contents($file,FILE_TEXT)))); $value=$_value->evaluate(); }*/ } break; case 'USER_OVERIDE': $value = get_param('id', ''); if (!is_numeric($value) || $value == '') { $value = strval(get_member()); } break; case 'IS_HTTPAUTH_LOGIN': $value = is_httpauth_login() ? '1' : '0'; break; case 'MEMBER_PROFILE_LINK': $value = $GLOBALS['FORUM_DRIVER']->member_profile_url(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member(), false, true); if (is_null($value)) { $value = ''; } break; case 'USERNAME': $value = $GLOBALS['FORUM_DRIVER']->get_username(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()); if (is_null($value)) { $value = do_lang('UNKNOWN'); } break; case 'CYCLE': if (isset($param[0])) { if (!isset($CYCLES[$param[0]])) { $CYCLES[$param[0]] = 0; } if (!isset($param[1])) { $value = strval($CYCLES[$param[0]]); } else { if (count($param) == 2) { $param = array_merge(array($param[0]), explode(',', $param[1])); } ++$CYCLES[$param[0]]; if (!array_key_exists($CYCLES[$param[0]], $param)) { $CYCLES[$param[0]] = 1; } $value = $param[$CYCLES[$param[0]]]; } } break; case 'THUMBNAIL': require_code('images'); $value = _symbol_thumbnail($param); break; case 'IMAGE_WIDTH': require_code('images'); list($value, ) = _symbol_image_dims($param); break; case 'IMAGE_HEIGHT': require_code('images'); list(, $value) = _symbol_image_dims($param); break; case 'IS_IN_GROUP': if (isset($param[0])) { if (in_array($param[count($param) - 1], array('', 'primary', 'secondary'))) { $last_param = $param[count($param) - 1]; unset($param[count($param) - 1]); } else { $last_param = ''; } $member_id = get_member(); $new_param = ''; $param_2 = array(); foreach ($param as $group) { if (substr($group, 0, 1) == '!' && is_numeric(substr($group, 1))) { $member_id = intval(substr($group, 1)); } else { $param_2 = array_merge($param_2, explode(',', $group)); } } foreach ($param_2 as $group) { if ($new_param != '') { $new_param .= ','; } $new_param .= $group; } if ($last_param == 'primary') { $member_row = $GLOBALS['FORUM_DRIVER']->get_member_row($member_id); $real_group_list = array($GLOBALS['FORUM_DRIVER']->pname_group($member_row)); } elseif ($last_param == 'secondary') { $real_group_list = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id); $member_row = $GLOBALS['FORUM_DRIVER']->get_member_row($member_id); $real_group_list = array_diff($real_group_list, array($GLOBALS['FORUM_DRIVER']->pname_group($member_row))); } else { $real_group_list = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id); } require_code('ocfiltering'); $value = count(array_intersect(ocfilter_to_idlist_using_memory($new_param, $GLOBALS['FORUM_DRIVER']->get_usergroup_list()), $real_group_list)) != 0 ? '1' : '0'; } break; case 'IS_STAFF': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->is_staff(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()) ? '1' : '0'; } else { $value = '0'; } break; case 'IS_SUPER_ADMIN': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->is_super_admin(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()) ? '1' : '0'; } else { $value = '0'; } break; case 'PHOTO': if (isset($param[0])) { $value = $GLOBALS['FORUM_DRIVER']->get_member_photo_url(intval($param[0])); if (url_is_local($value) && $value != '') { $value = get_custom_base_url() . '/' . $value; } } break; case 'OCF_RANK_IMAGE': if (addon_installed('ocf_forum')) { require_code('ocf_groups'); $rank_images = new ocp_tempcode(); $member_id = isset($param[0]) ? intval($param[0]) : get_member(); $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id, true); foreach ($posters_groups as $group) { $rank_image = ocf_get_group_property($group, 'rank_image'); $group_leader = ocf_get_group_property($group, 'group_leader'); $group_name = ocf_get_group_name($group); $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only'); if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_primary_group'))) { $rank_images->attach(do_template('OCF_RANK_IMAGE', array('USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($member_id), 'GROUP_NAME' => $group_name, 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $member_id))); } } $value = $rank_images->evaluate(); } break; case 'TOTAL_POINTS': if (addon_installed('points')) { require_code('points'); $value = strval(total_points(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'POINTS_USED': if (addon_installed('points')) { require_code('points'); $value = strval(points_used(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'AVAILABLE_POINTS': if (addon_installed('points')) { require_code('points'); $value = strval(available_points(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'URL_FOR_GET_FORM': if (isset($param[0])) { $url_bits = parse_url($param[0]); if (array_key_exists('scheme', $url_bits)) { $value = $url_bits['scheme'] . '://' . (array_key_exists('host', $url_bits) ? $url_bits['host'] : 'localhost'); if (array_key_exists('port', $url_bits) && $url_bits['port'] != 80) { $value .= ':' . strval($url_bits['port']); } } if (array_key_exists('path', $url_bits)) { $value .= $url_bits['path']; } } break; case 'HIDDENS_FOR_GET_FORM': $_value = new ocp_tempcode(); $url_bits = parse_url($param[0]); if (array_key_exists('query', $url_bits) && $url_bits['query'] != '') { foreach (explode('&', $url_bits['query']) as $exp) { $parts = explode('=', $exp, 2); if (count($parts) == 2) { if (!in_array($parts[0], $param)) { $_value->attach(form_input_hidden($parts[0], urldecode($parts[1]))); } } } } $value = $_value->evaluate(); break; case 'NOTIFICATIONS_ENABLED': $value = ''; if (array_key_exists(0, $param)) { require_code('notifications'); $value = notifications_enabled(array_key_exists(1, $param) ? $param[1] : get_page_name(), $param[0]) ? '1' : '0'; } break; case 'DOCUMENT_HELP': global $DOCUMENT_HELP, $HELPER_PANEL_TUTORIAL; $value = $DOCUMENT_HELP; if ($value == '' && $HELPER_PANEL_TUTORIAL != '') { $value = brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/' . $HELPER_PANEL_TUTORIAL; } break; case 'HTTP_STATUS_CODE': global $HTTP_STATUS_CODE; $value = $HTTP_STATUS_CODE; break; case 'TEMPCODE': if (isset($param[0])) { require_code('tempcode_compiler'); $_value = template_to_tempcode($param[0]); $value = $_value->evaluate(); } break; case 'COMCODE': if (isset($param[0])) { $_value = comcode_to_tempcode($param[0], NULL, true); $value = $_value->evaluate(); } break; case 'FLAGRANT': $_value = get_flagrant(); $value = $_value->evaluate(); break; case 'IMG_WIDTH': case 'IMG_HEIGHT': if (isset($param[0]) && isset($GLOBALS['SITE_DB']) && function_exists('find_theme_image') && $GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $THEME_IMG_DIMS_CACHE; if (!isset($THEME_IMG_DIMS_CACHE)) { $THEME_IMG_DIMS_CACHE = function_exists('persistant_cache_get') ? persistant_cache_get('THEME_IMG_DIMS') : array(); } if (isset($THEME_IMG_DIMS_CACHE[$param[0]])) { list($width, $height) = $THEME_IMG_DIMS_CACHE[$param[0]]; $value = $name == 'IMG_WIDTH' ? $width : $height; } else { if (strpos($param[0], '://') === false) { $img_url = find_theme_image($param[0], false, false, array_key_exists(2, $param) ? $param[2] : NULL, NULL, isset($param[1]) && $param[1] == '1' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']); } else { $img_url = $param[0]; } require_code('images'); list($width, $height) = _symbol_image_dims(array($img_url)); $value = $name == 'IMG_WIDTH' ? $width : $height; $THEME_IMG_DIMS_CACHE[$param[0]] = array($width, $height); if (function_exists('persistant_cache_set')) { persistant_cache_set('THEME_IMG_DIMS', $THEME_IMG_DIMS_CACHE); } } } break; case 'CLEAN_FILE_SIZE': if (isset($param[0])) { $bytes = is_numeric($param[0]) ? intval($param[0]) : NULL; require_code('files'); $value = clean_file_size($bytes); } break; case 'TIME_PERIOD': if (isset($param[0])) { $value = display_time_period(intval($param[0])); } break; case 'MAKE_RELATIVE_DATE': if (isset($param[0])) { if (get_option('use_contextual_dates') == '0' && (!array_key_exists(1, $param) || $param[1] != '1')) { $value = get_timezoned_date(intval($param[0])); } else { $value = display_time_period(time() - intval($param[0])); } } break; case 'TIMEZONE': $value = make_nice_timezone_name(get_site_timezone()); break; case 'LOAD_PAGE': foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } global $LOADED_PAGES; if (strpos($param[0], ':') !== false) { $param = array_reverse(explode(':', $param[0], 2)); } $_value = $LOADED_PAGES[serialize($param)]; $value = $_value->evaluate(); break; case 'RUNNING_SCRIPT': if (isset($param[0])) { $value = running_script($param[0]) ? '1' : '0'; } break; case 'MATCH_KEY_MATCH': $value = '0'; foreach ($param as $match_key) { if ($match_key == '1' || $match_key == '0' || $match_key == '') { continue; } if (match_key_match($match_key, isset($param[1]) && $match_key == '1')) { $value = '1'; } } break; case 'VERSION': $value = strval(ocp_version()); break; case 'PREVIEW_VALIDATION': $value = get_option('is_on_preview_validation') == '1' ? '1' : '0'; break; case 'BLOCK': if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } if (count($param) == 1 && strpos($param[0], ',') !== false) { $param = preg_split('#((?<!\\\\)|(?<=\\\\\\\\)|(?<=^)),#', $param[0]); foreach ($param as $key => $val) { $param[$key] = str_replace('\\,', ',', $val); } } global $LOADED_BLOCKS; if (isset($LOADED_BLOCKS[serialize($param)])) { // Will always be set $value = $LOADED_BLOCKS[serialize($param)]->evaluate(); } } break; case 'CURRENCY': if (addon_installed('ecommerce')) { if (isset($param[0])) { require_code('currency'); $value = currency_convert(floatval(str_replace(',', '', $param[0])), isset($param[1]) && $param[1] != '' ? $param[1] : get_option('currency'), isset($param[2]) && $param[2] != '' ? $param[2] : NULL, isset($param[3]) && $param[3] == '1'); if (is_null($value)) { $value = do_lang('INTERNAL_ERROR'); } } else { $value = get_option('currency'); } } break; case 'CURRENCY_SYMBOL': if (addon_installed('ecommerce')) { require_code('ecommerce'); $value = ecommerce_get_currency_symbol(); } break; case 'GEOLOCATE': $value = geolocate_ip(isset($param[0]) ? $param[0] : NULL); break; case 'NO_SAFE_MODE': $value = str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1' ? '0' : '1'; break; case 'FORCE_PREVIEWS': if (get_option('forced_preview_option') == '1') { if (get_forum_type() == 'ocf') { if (is_guest() && get_option('default_preview_guests') == '0') { $value = '0'; } else { $value = $GLOBALS['FORUM_DRIVER']->get_member_row_field(get_member(), 'm_preview_posts') == 1 ? '1' : '0'; } } else { $value = get_option('default_preview_guests') == '0' ? '0' : '1'; } } else { $value = '0'; } break; case 'PREVIEW_URL': $value = find_script('preview'); $value .= '?page=' . get_page_name(); $value .= '&type=' . get_param('type', '', true); break; case 'ADDON_INSTALLED': if (isset($param[0]) && !running_script('install')) { $value = addon_installed($param[0]) ? '1' : '0'; } break; case 'VALUE_OPTION': if (isset($param[0])) { $value = function_exists('get_value') ? get_value($param[0]) : ''; if (is_null($value)) { $value = function_exists('get_long_value') ? get_long_value($param[0]) : ''; if (is_null($value)) { $value = isset($param[1]) ? $param[1] : ''; if ($param[0] == 'textmate' && (ocp_srv('HTTP_HOST') == 'localhost' && strpos(ocp_srv('HTTP_USER_AGENT'), 'Macintosh') !== false)) { $value = '1'; } } } } break; case 'KEEP_INDEX': // What needs preserving in the URL $value = 'index.php'; if (count($_GET) > 0) { foreach ($_GET as $key => $val) { if (is_array($val)) { continue; } if (get_magic_quotes_gpc()) { $val = stripslashes($val); } if (substr($key, 0, 5) == 'keep_' && !skippable_keep($key, $val) && strpos($key, '_expand_') === false) { $value .= ($value == 'index.php' ? '?' : '&') . urlencode($key) . '=' . ocp_url_encode($val); } } } break; case 'HIDE_HELP_PANEL': $value = array_key_exists('hide_help_panel', $_COOKIE) && $_COOKIE['hide_help_panel'] == '1' ? '1' : '0'; break; case 'URLISE_LANG': if (isset($param[1])) { $_value = urlise_lang($param[0], $param[1], isset($param[2]) ? $param[2] : '', isset($param[3]) ? $param[3] == '1' : false); $value = $_value->evaluate(); } break; case 'FIND_SCRIPT_NOHTTP': if (isset($param[0]) && function_exists('find_script')) { $value = preg_replace('#^https?://[^/]+#', '', find_script($param[0], false, isset($param[1]) ? intval($param[1]) : 0)); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'FIND_SCRIPT': if (isset($param[0]) && function_exists('find_script')) { $value = find_script($param[0], false, isset($param[1]) ? intval($param[1]) : 0); } break; case 'MOBILE': $value = is_mobile(NULL, array_key_exists(0, $param) ? $param[0] == '1' : false) ? '1' : '0'; break; case 'VALID_FILE_TYPES': $value = get_option('valid_types'); $types = array_flip(explode(',', $value)); $value = ''; ksort($types); foreach (array_flip($types) as $val) { $value .= $val . ','; } $value = substr($value, 0, strlen($value) - 1); break; case 'BROWSER_UA': $browser = get_browser_string(); $value = $browser; break; case 'OS': $os = get_os_string(); if (is_null($os)) { $os = ''; } $value = $os; break; case 'ANCHOR': if (isset($param[0])) { $_value = do_template('ANCHOR', array('_GUID' => '8795c70c9dd7c6217bb765264ac24092', 'NAME' => $param[0])); $value = $_value->evaluate(); } break; case 'CSS_TEMPCODE': $_value = css_tempcode(); $value = $_value->evaluate(); break; case 'JS_TEMPCODE': $_value = javascript_tempcode(isset($param[0]) ? $param[0] : NULL); $value = $_value->evaluate(); break; case 'PAD_LEFT': if (array_key_exists(1, $param)) { $value = str_pad($param[0], intval($param[1]), array_key_exists(2, $param) ? $param[2] : '', STR_PAD_LEFT); } break; case 'PAD_RIGHT': if (array_key_exists(1, $param)) { $value = str_pad($param[0], intval($param[1]), array_key_exists(2, $param) ? $param[2] : '', STR_PAD_RIGHT); } break; case 'PAGE_TITLE': $value = is_null($DISPLAYED_TITLE) ? '' : $DISPLAYED_TITLE->evaluate(); break; case 'SET_TITLE': if (array_key_exists(0, $param)) { get_page_title($param[0], false); } break; case 'EXTRA_HEAD': $_value = $GLOBALS['EXTRA_HEAD']; if ($_value === NULL) { $_value = new ocp_tempcode(); } $value = $_value->evaluate(); break; case 'EXTRA_FOOT': if ($GLOBALS['EXTRA_FOOT'] === NULL) { $GLOBALS['EXTRA_FOOT'] = new ocp_tempcode(); } $_value = $GLOBALS['EXTRA_FOOT']; if (array_key_exists(0, $param)) { $GLOBALS['EXTRA_FOOT']->attach($param[0]); } else { $value = $_value->evaluate(); } break; case 'RAND': if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['RAND'])) { $GLOBALS['NO_EVAL_CACHE'] = true; $value = strval(mt_rand(0, 32000)); } else { $value = '4'; } break; case 'SET_RAND': if (isset($param[0])) { if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { $GLOBALS['NO_EVAL_CACHE'] = true; $value = $param[mt_rand(0, count($param) - 1)]; } else { $value = $param[0]; } } break; case 'COPYRIGHT': $value = str_replace('$CURRENT_YEAR', date('Y'), get_option('copyright')); break; case 'KEYWORDS_SPACED': $value = str_replace(',', ' ', get_option('keywords')); break; case 'STAFF_ADDRESS_PURE': $value = get_option('staff_address'); break; case 'STAFF_ADDRESS': require_code('obfuscate'); $value = obfuscate_email_address(get_option('staff_address')); break; case 'DOMAIN': $value = get_domain(); break; case 'BRAND_NAME': $value = function_exists('get_value') ? get_value('rebrand_name') : NULL; if (is_null($value)) { $value = 'ocPortal'; } break; case 'BRAND_BASE_URL': $value = brand_base_url(); break; case 'SHOW_DOCS': $value = get_option('show_docs') === '0' ? '0' : '1'; break; case 'MEMBER_EMAIL': $value = $GLOBALS['FORUM_DRIVER']->get_member_email_address(isset($param[0]) ? intval($param[0]) : get_member()); break; case 'OCF_MEMBER_HTML': if (get_forum_type() == 'ocf') { require_code('ocf_members'); require_code('ocf_members2'); $_value = ocf_show_member_box(isset($param[0]) ? intval($param[0]) : get_member()); $value = $_value->evaluate(); } break; case 'HAS_SPECIFIC_PERMISSION': if (isset($param[0])) { $value = has_specific_permission(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_ZONE_ACCESS': if (isset($param[0])) { $value = has_zone_access(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_PAGE_ACCESS': if (isset($param[0]) && isset($param[1])) { $value = has_page_access(!is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], $param[1], !is_null($param) && isset($param[3]) ? $param[3] == '1' : false) ? '1' : '0'; } break; case 'HAS_CATEGORY_ACCESS': if (isset($param[0])) { $value = has_category_access(!is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], $param[1]) ? '1' : '0'; } break; case 'HAS_ATTACHMENT_ACCESS': if (isset($param[0])) { require_code('attachments'); $value = has_attachment_access(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_SUBMIT_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high')) { $value = has_submit_permission(strtolower($param[0]), !is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), !is_null($param) && isset($param[2]) ? $param[2] : get_ip_address(), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'HAS_DELETE_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high') && isset($param[1])) { $value = has_delete_permission(strtolower($param[0]), !is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), intval($param[1]), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'HAS_EDIT_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high') && isset($param[1])) { $value = has_edit_permission(strtolower($param[0]), !is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), intval($param[1]), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'ENTITY_DECODE': if (isset($param[0])) { $value = @html_entity_decode($param[0], ENT_QUOTES, get_charset()); } break; case 'RESET_CYCLE': if (isset($param[0])) { $CYCLES[$param[0]] = 0; } break; case 'SITE_SCOPE': $value = get_option('site_scope'); break; case 'LAST_VISIT_TIME': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $value = strval($member_info['last_visit_time']); } break; case 'NUM_NEW_TOPICS': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $_new_topics = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE NOT t_forum_id IS NULL AND t_cache_first_time>' . strval((int) $member_info['last_visit_time'])); $new_topics = $_new_topics[0]['mycnt']; $value = strval($new_topics); } break; case 'NUM_NEW_POSTS': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $_new_posts = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE NOT p_cache_forum_id IS NULL AND p_time>' . strval((int) $member_info['last_visit_time'])); $new_posts = $_new_posts[0]['mycnt']; $value = strval($new_posts); } break; case 'HAS_FORUM': $value = has_no_forum() ? '0' : '1'; break; case 'OCF': $value = get_forum_type() == 'ocf' ? '1' : '0'; break; case 'BOARD_PREFIX': $value = get_forum_base_url(); break; case 'DATE_AND_TIME': $use_contextual_dates = isset($param[0]) && $param[0] == '1'; $verbose = isset($param[1]) && $param[1] == '1'; $server_time = isset($param[2]) && $param[2] == '1'; $time = isset($param[3]) ? intval($param[3]) : time(); $value = get_timezoned_date($time, true, $verbose, $server_time, !$use_contextual_dates); break; case 'DATE': $use_contextual_dates = isset($param[0]) && $param[0] == '1'; $verbose = isset($param[1]) && $param[1] == '1'; $server_time = isset($param[2]) && $param[2] == '1'; $time = isset($param[3]) ? intval($param[3]) : time(); $value = get_timezoned_date($time, false, $verbose, $server_time, !$use_contextual_dates); break; case 'TIME': $time = isset($param[0]) ? intval($param[0]) : time(); $value = get_timezoned_time($time); break; case 'SECONDS_PERIOD': if (array_key_exists(0, $param)) { $value = display_seconds_period(intval($param[0])); } break; case 'FROM_TIMESTAMP': if (isset($param[0])) { $timestamp = isset($param[1]) ? intval($param[1]) : time(); if (!array_key_exists(2, $param) || $param[2] == '1') { $timestamp = utctime_to_usertime($timestamp); } $value = locale_filter(my_strftime($param[0], $timestamp)); if ($value == $param[0]) { // If no conversion happened then the syntax must have been for 'date' not 'strftime' $value = date($param[0], $timestamp); } } else { $timestamp = time(); $value = strval($timestamp); } break; case 'TO_TIMESTAMP': if (isset($param[0])) { $value = strval(strtotime($param[0])); if (array_key_exists(1, $param) && $param[1] == '1') { $value = strval(usertime_to_utctime(intval($value))); } // '1' means date was in user-time so needs converting to a UTC timestamp } else { $value = strval(time()); } break; case 'SESSION_HASHED': $value = md5(strval(get_session_id())); break; case 'SESSION': $value = strval(get_session_id()); break; case 'IN_ARRAY': if (isset($param[1])) { $array = array_slice($param, 1); $value = in_array($param[0], $array) ? '1' : '0'; } break; case 'MULT': if (isset($param[1])) { $value = float_to_raw_string(floatval($param[0]) * floatval($param[1]), 2, true); } break; case 'ROUND': if (isset($param[0])) { $amount = isset($param[1]) ? intval($param[1]) : 0; if ($amount > 0) { $value = float_format(floatval($param[0]), $amount); } else { $value = strval(intval(round(floatval($param[0]), $amount))); } } break; case 'DEV_MODE': $value = $GLOBALS['DEBUG_MODE'] ? '1' : '0'; break; case 'BROWSER_MATCHES': if (isset($param[0])) { $q = false; foreach (explode('|', $param[0]) as $browser) { $q = browser_matches($browser); if ($q) { break; } } $value = $q ? '1' : '0'; } break; case 'ISSET': if (isset($param[0])) { $value = isset($TEMPCODE_SETGET[$param[0]]) ? '1' : '0'; } break; case 'INIT': if (isset($param[1])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = $param[1]; } } break; case 'INC': if (isset($param[0])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = '0'; } $TEMPCODE_SETGET[$param[0]] = strval(intval($TEMPCODE_SETGET[$param[0]]) + 1); } break; case 'DEC': if (isset($param[0])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = '0'; } $TEMPCODE_SETGET[$param[0]] = strval(intval($TEMPCODE_SETGET[$param[0]]) - 1); } break; case 'PREG_MATCH': if (isset($param[1])) { $value = preg_match('#' . str_replace('#', '\\#', $param[0]) . '#' . (isset($param[2]) ? str_replace('e', '', $param[2]) : ''), $param[1]) != 0 ? '1' : '0'; } break; case 'PREG_REPLACE': if (isset($param[2])) { $value = preg_replace('#' . str_replace('#', '\\#', $param[0]) . '#' . (isset($param[3]) ? str_replace('e', '', $param[3]) : ''), $param[1], $param[2]); } break; case 'MAX': if (isset($param[0])) { $value = strval(max(intval($param[0]), intval($param[1]))); } break; case 'MIN': if (isset($param[0])) { $value = strval(min(intval($param[0]), intval($param[1]))); } break; case 'MOD': if (isset($param[0])) { $value = strval(max(intval($param[0]), -intval($param[0]))); } break; case 'REM': if (isset($param[1])) { $value = strval(intval($param[0]) % intval($param[1])); } break; case 'DIV_FLOAT': if (isset($param[1])) { $value = float_to_raw_string(floatval($param[0]) / floatval($param[1]), 2, true); } break; case 'DIV': if (isset($param[1])) { $value = strval(intval(floor(floatval($param[0]) / floatval($param[1])))); } break; case 'SUBTRACT': if (isset($param[1])) { $value = float_to_raw_string(floatval(str_replace(',', '', $param[0])) - floatval(str_replace(',', '', $param[1])), 2, true); } break; case 'ADD': if (isset($param[1])) { $value = float_to_raw_string(floatval(str_replace(',', '', $param[0])) + floatval(str_replace(',', '', $param[1])), 2, true); } break; case 'WCASE': if (isset($param[0])) { $value = ucwords($param[0]); } break; case 'LCASE': if (isset($param[0])) { $value = ocp_mb_strtolower($param[0]); } break; case 'UCASE': if (isset($param[0])) { $value = ocp_mb_strtoupper($param[0]); } break; case '_POST': if (isset($param[0])) { $value = post_param($param[0], isset($param[1]) ? $param[1] : ''); } break; case 'REPLACE': if (isset($param[2])) { $value = str_replace($param[0], $param[1], $param[2]); if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'AT': if (isset($param[1])) { $value = ocp_mb_substr($param[0], intval($param[1]), 1); } break; case 'STRPOS': if (isset($param[1])) { $t_value = strpos($param[0], $param[1]); $value = $t_value === false ? '0' : strval($t_value); } break; case 'IN_STR': if (isset($param[1])) { if ($param[1] == '') { $value = '0'; } else { $value = '0'; foreach ($param as $i => $check) { if (is_integer($i) && $i != 0 && $check != '') { if (strpos($param[0], $check) !== false) { $value = '1'; break; } } } } } break; case 'SUBSTR_COUNT': if (isset($param[1])) { $value = strval(substr_count($param[0], $param[1])); } break; case 'SUBSTR': if (isset($param[1])) { $value = ocp_mb_substr($param[0], intval($param[1]), isset($param[2]) ? intval($param[2]) : strlen($param[0])); } break; case 'LENGTH': if (isset($param[0])) { $value = strval(ocp_mb_strlen($param[0])); } break; case 'WORDWRAP': if (isset($param[1])) { $cut = isset($param[3]) && $param[3] == '1'; $value = wordwrap($param[0], intval($param[1]), isset($param[2]) ? $param[2] : '<br />', $cut); if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'ALTERNATOR_TRUNCATED': // Alternate values according to whether some given text WOULD have been truncated. 0: text to check against, 1: the truncate length, 2:IF would not be do this, 3: if it would be do this, 4: whether given text is encoded as HTML (0=no [default, plain-text], 1=yes) if (isset($param[3])) { $amount = intval($param[1]); $is_html = isset($param[4]) && $param[4] == '1'; if (strlen($is_html ? strip_tags($param[0]) : $param[0]) > $amount) { $value = $param[3]; } else { $value = $param[2]; } } break; case 'ESCAPE': if (isset($param[0])) { $d_escaping = array(isset($param[1]) ? constant($param[1]) : ENTITY_ESCAPED); if (is_string($param[0])) { apply_tempcode_escaping($d_escaping, $param[0]); } $value = $param[0]; } break; case 'COOKIE_PATH': $value = function_exists('get_cookie_path') ? get_cookie_path() : '/'; break; case 'COOKIE_DOMAIN': $s_value = function_exists('get_cookie_domain') ? get_cookie_domain() : ''; $value = is_null($s_value) ? '' : $s_value; break; case 'IS_A_COOKIE_LOGIN': global $IS_A_COOKIE_LOGIN; $value = $IS_A_COOKIE_LOGIN && ini_get('suhosin.cookie.max_name_length') !== '64' ? '1' : '0'; break; case 'GROUP_ID': if (isset($param[0])) { $groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(isset($param[1]) ? intval($param[1]) : get_member()); $value = array_key_exists(intval($param[0]), $groups) ? strval($groups[intval($param[0])]) : ''; } break; case 'GROUP_NAME': if (isset($param[0])) { $groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(isset($param[1]) ? intval($param[1]) : get_member()); if (array_key_exists(intval($param[0]), $groups)) { $all_usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); $value = $all_usergroups[$groups[intval($param[0])]]; } if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'NEGATE': if (isset($param[0])) { $value = strval(-intval($param[0])); } break; case 'XOR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == 1 ? '1' : '0'; break; case 'NOR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count > 0 ? '0' : '1'; break; case 'NAND': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == count($param) ? '0' : '1'; break; case 'LT': if (isset($param[1])) { $value = intval($param[0]) < intval($param[1]) ? '1' : '0'; } break; case 'GT': if (isset($param[1])) { $value = intval($param[0]) > intval($param[1]) ? '1' : '0'; } break; case 'COPPA_ON': $value = get_option('is_on_coppa') == '1' ? '1' : '0'; break; case 'OBFUSCATE': if (isset($param[0])) { require_code('obfuscate'); $value = obfuscate_entities($param[0]); } break; case 'FIX_ID': if (isset($param[0])) { $value = fix_id($param[0]); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } } break; case 'MAILTO': require_code('obfuscate'); $value = mailto_obfuscated(); break; case 'INLINE_STATS': $value = get_option('show_inline_stats') == '1' ? '1' : '0'; break; case 'ATTACHMENT_DOWNLOADS': if (isset($param[0])) { $db = $GLOBALS['SITE_DB']; if (isset($param[1]) && $param[1] == '1') { $db = $GLOBALS['FORUM_DB']; } $_value = $db->query_value_null_ok('attachments', 'a_num_downloads', array('id' => intval($param[0]))); $value = is_null($_value) ? '?' : strval($_value); } break; case 'CSS_DIMENSION_REDUCE': if (isset($param[1])) { $value = $param[0]; if (substr($value, -2) == 'px') { $b = $param[1]; $value = strval(intval(substr($value, 0, -2)) - intval($b)) . 'px'; } if ($value == '') { $value = '0px'; } } break; case 'COMMENT_COUNT': if (isset($param[1])) { if (get_option('is_on_comments') == '1') { $count = 0; $_comments = $GLOBALS['FORUM_DRIVER']->get_forum_topic_posts($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier(get_option('comments_forum_name'), $param[0] . '_' . $param[1]), $count, 0, 0, false); $_value = do_lang_tempcode('_COMMENTS', integer_format(0)); if (is_array($_comments)) { $_value = do_lang_tempcode('_COMMENTS', escape_html(integer_format($count))); } $value = $_value->evaluate(); } else { $value = do_lang('VIEW'); } } break; case 'CAN_SPELLCHECK': $value = function_exists('pspell_check') ? '1' : '0'; break; case 'AWARD_ID': if (array_key_exists(0, $param)) { $value = $GLOBALS['SITE_DB']->query_value_null_ok('award_archive', 'content_id', array('a_type_id' => intval($param[0])), 'ORDER BY date_and_time DESC'); if (is_null($value)) { $value = ''; } } break; case 'SELF_PAGE_LINK': $value = ''; if (running_script('index') || running_script('iframe')) { $value = get_zone_name() . ':' . get_page_name(); foreach ($_GET as $key => $val) { if ($key == 'page') { continue; } if (is_array($val)) { continue; } if (substr($key, 0, 5) == 'keep_') { continue; } $value .= ':' . $key . '=' . $val; } } break; case 'SET_TUTORIAL_LINK': $value = ''; if (array_key_exists(1, $param) && $param[1] != '' && $param[1][0] != '#') { set_tutorial_link($param[0], $param[1]); } break; case 'DISPLAY_CONCEPT': $value = ''; if (array_key_exists(0, $param)) { $key = $param[0]; $page_link = get_tutorial_link('concept___' . preg_replace('#[^\\w_]#', '_', $key)); if (is_null($page_link)) { $temp_tpl = make_string_tempcode($key); } else { list($zone, $attributes, $hash) = page_link_decode($page_link); $_url = build_url($attributes, $zone, NULL, false, false, false, $hash); $temp_tpl = do_template('COMCODE_CONCEPT', array('_GUID' => 'ee0cd05f87329923f05145180004d8a8', 'TEXT' => $key, 'URL' => $_url)); } $value = $temp_tpl->evaluate(); } break; case 'SELF_URL': $extra_params = NULL; if (isset($param[3])) { $extra_params = array(); $i = 3; while (isset($param[$i])) { $bits = explode('=', $param[$i], 2); if ($bits[1] == '<null>') { $bits[1] = NULL; } $extra_params[$bits[0]] = $bits[1]; $i++; } } $value = get_self_url(true, isset($param[0]) && $param[0] == '1', $extra_params, isset($param[1]) && $param[1] == '1', isset($param[2]) && $param[2] == '1'); break; case 'SHIFT_DECODE': if (isset($param[0])) { global $SHIFT_VARIABLES; $key = $param[0]; $value = isset($SHIFT_VARIABLES[$key]) ? $SHIFT_VARIABLES[$key]->evaluate() : ''; } break; case 'NUMBER_FORMAT': if (isset($param[0])) { $value = integer_format(intval($param[0])); } break; case 'FLOAT_FORMAT': if (isset($param[0])) { $value = float_format(floatval($param[0])); } break; case 'CURRENTLY_INVISIBLE': $value = is_invisible() ? '1' : '0'; break; case 'IS_FRIEND': if (isset($param[0])) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('chat_buddies', 'member_likes', array('member_likes' => isset($param[1]) ? intval($param[1]) : get_member(), 'member_liked' => intval($param[0]))); $value = is_null($test) ? '0' : '1'; } break; case 'SSW': $value = get_option('ssw') == '1' ? '1' : '0'; break; case 'RATING': if (isset($param[1])) { require_code('feedback'); $rating = get_rating_simple_array(array_key_exists(3, $param) ? $param[3] : get_self_url(true), array_key_exists(4, $param) ? $param[4] : (is_null($DISPLAYED_TITLE) ? '' : $DISPLAYED_TITLE->evaluate()), $param[0], $param[1], array_key_exists(5, $param) ? $param[5] : 'RATING_FORM', array_key_exists(2, $param) ? $param[2] : NULL); if ($rating !== NULL) { if (!array_key_exists(2, $param) || $param[2] == '0') { $value = isset($rating['ALL_RATING_CRITERIA'][0]['RATING']) ? $rating['ALL_RATING_CRITERIA'][0]['RATING'] : ''; } else { $value = do_template('RATING_INLINE_STATIC', $rating); } if (is_object($value)) { $value = $value->evaluate(); } } } break; case 'VIEWS': if (isset($param[2])) { $id_field = 'id'; // Not allowed for security reasons if (preg_match('#^\\w*views\\w*$#', $param[1]) != 0) { $test = $GLOBALS['SITE_DB']->query_value_null_ok($param[0], $param[1], array($id_field => $param[2])); if (!is_null($test)) { $value = integer_format($test); } } } break; default: global $EXTRA_SYMBOLS; if (is_null($EXTRA_SYMBOLS)) { $EXTRA_SYMBOLS = array(); $hooks = find_all_hooks('systems', 'symbols'); foreach (array_keys($hooks) as $hook) { $EXTRA_SYMBOLS[$hook] = array(); } } if (array_key_exists($name, $EXTRA_SYMBOLS)) { if (!array_key_exists('ob', $EXTRA_SYMBOLS[$name])) { require_code('hooks/systems/symbols/' . filter_naughty_harsh($name)); $EXTRA_SYMBOLS[$name]['ob'] = object_factory('Hook_symbol_' . filter_naughty_harsh($name)); } $value = $EXTRA_SYMBOLS[$name]['ob']->run($param); break; } if (defined($name)) { $value = @strval(constant($name)); break; } $value = ''; require_code('site'); attach_message(do_lang_tempcode('MISSING_SYMBOL', escape_html($name)), 'warn'); } if ($escaped != array()) { if (is_object($value)) { $value = $value->evaluate(); } apply_tempcode_escaping($escaped, $value); } if ($cacheable) { $SYMBOL_CACHE[$escaped_codes] = $value; } return $value; } // Is it a directive? if ($type == TC_DIRECTIVE) { $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } // In our param we should have a map of bubbled template parameters (under 'vars') and our numbered directive parameters if ($param === NULL) { $param = array(); } // Closure-based Tempcode parser may send in strings, so we need to adapt... foreach ($param as $key => $val) { if (is_string($val)) { $param[$key] = make_string_tempcode($val); } } if (!isset($param['vars'])) { $param['vars'] = array(); } switch ($name) { case 'SHIFT_ENCODE': break; case 'PARAM_INFO': $_value = do_template('PARAM_INFO', array('MAP' => $param['vars'])); $value = $_value->evaluate(); break; case 'CSS_INHERIT': // e.g. {+START,CSS_INHERIT,global,default,#886aa9}{+END} if (isset($param[0])) { require_code('css_and_js'); $css_file = $param[0]->evaluate(); $theme = isset($param[1]) ? $param[1]->evaluate() : 'default'; $seed = isset($param[2]) ? $param[2]->evaluate() : NULL; if ($seed == '') { $seed = NULL; } $dark = isset($param[3]) ? $param[3]->evaluate() == '1' : false; $algorithm = isset($param[4]) ? $param[4]->evaluate() : 'equations'; $value = css_inherit($css_file, $theme, $GLOBALS['FORUM_DRIVER']->get_theme(), $seed, $dark, $algorithm); } break; case 'FRACTIONAL_EDITABLE': foreach (array_keys($param) as $key) { if (!is_numeric($key)) { unset($param[$key]); } } if (isset($param[3])) { $edit_text = $param[0]->evaluate(); $edit_param_name = $param[1]->evaluate(); $edit_pagelink = $param[2]->evaluate(); $supports_comcode = (isset($param[4]) ? $param[3]->evaluate() : '0') == '1'; list($zone, $attributes, ) = page_link_decode($edit_pagelink); if ($zone == '_SEARCH') { $zone = get_module_zone($attributes['page']); } if (has_actual_page_access(get_member(), $attributes['page'], $zone) && has_zone_access(get_member(), 'adminzone')) { $keep = symbol_tempcode('KEEP'); $url = find_script('fractional_edit') . '?edit_param_name=' . urlencode($edit_param_name) . '&supports_comcode=' . ($supports_comcode ? '1' : '0') . '&zone=' . urlencode($zone) . $keep->evaluate(); foreach ($attributes as $key => $val) { $url .= '&' . $key . '=' . urlencode($val); } $_value = $param[count($param) - 1]; $_value = do_template('FRACTIONAL_EDIT', array('_GUID' => '075ac126c427d28b309004bc67b32b08', 'VALUE' => $_value, 'URL' => $url, 'EDIT_TEXT' => $edit_text, 'EDIT_PARAM_NAME' => $edit_param_name)); $value = $_value->evaluate(); } else { $value = $param[count($param) - 1]->evaluate(); } } break; case 'SET': if (isset($param[1])) { $var = $param[0]->evaluate(); $set_val = ''; $i = 1; while (isset($param[$i])) { if ($i != 1) { $set_val .= ','; } $set_val .= $param[1]->evaluate(); $i++; } $TEMPCODE_SETGET[$var] = $set_val; } break; case 'IN_ARRAY': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '1' : '0'; } break; case 'NOT_IN_ARRAY': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '0' : '1'; } break; case 'IF_IN_ARRAY': if (isset($param[2])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? $param[2]->evaluate() : ''; } break; case 'IF_NOT_IN_ARRAY': if (isset($param[2])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '' : $param[2]->evaluate(); } break; case 'IMPLODE': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); if (isset($param[2]) && $param[2]->evaluate() == '1') { $delim = $param[0]->evaluate(); foreach ($array as $key => $val) { if ($value != '') { $value .= $delim; } $value .= (is_integer($key) ? integer_format($key) : $key) . ' = ' . $val; } } else { $value = implode($param[0]->evaluate(), $array); } } break; case 'COUNT': if (isset($param[0])) { $key = $param[0]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = strval(count($array)); } break; case 'BOX': unset($param['vars']); $title = isset($param[1]) ? $param[0]->evaluate() : ''; $dimensions = isset($param[2]) ? $param[1]->evaluate() : '100%'; if ($dimensions == '') { $dimensions = '100%'; } $box_type = isset($param[3]) ? $param[2]->evaluate() : 'classic'; $options = isset($param[4]) ? $param[3]->evaluate() : ''; $meta = isset($param[5]) ? $param[4]->evaluate() : ''; $links = isset($param[6]) ? $param[5]->evaluate() : ''; $expand = isset($param[7]) ? $param[6]->evaluate() == '1' : false; $toplink = isset($param[8]) ? $param[7]->evaluate() : ''; $tmp = put_in_standard_box(array_pop($param), $title, $dimensions, $box_type, $options, $meta, $links, $expand, $toplink); $value = $tmp->evaluate(); break; case 'IF_NON_EMPTY': if (isset($param[1])) { if (!$param[0]->is_really_empty()) { $value = $param[1]->evaluate(); } } break; case 'IF_PASSED': if (isset($param[1])) { $t = $param[0]->evaluate(); if (isset($param['vars'][$t])) { $value = $param[1]->evaluate(); } } break; case 'IF_NON_PASSED': if (isset($param[1])) { $t = $param[0]->evaluate(); if (!isset($param['vars'][$t])) { $value = $param[1]->evaluate(); } } break; case 'IF_EMPTY': if (isset($param[1])) { if ($param[0]->is_really_empty()) { $value = $param[1]->evaluate(); } } break; case 'IF_ARRAY_EMPTY': if (isset($param[0])) { $looking_at = $param[0]->evaluate(); if (array_key_exists($looking_at, $param['vars'])) { if (count($param['vars'][$looking_at]) == 0) { $value = $param[1]->evaluate(); } } } break; case 'IF_ARRAY_NON_EMPTY': if (isset($param[0])) { $looking_at = $param[0]->evaluate(); if (array_key_exists($looking_at, $param['vars'])) { if (count($param['vars'][$looking_at]) != 0) { $value = $param[1]->evaluate(); } } } break; case 'OF': if (isset($param[1])) { $key = $param[0]->evaluate(); $x = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $x2 = is_numeric($x) ? intval($x) : $x; if (is_integer($x2)) { if ($x2 < 0) { $x2 = count($array) - 1; } elseif ($x2 >= count($array)) { $x2 -= count($array); } } $value = array_key_exists($x2, $array) ? $array[$x2] : ''; if (is_object($value)) { $value = $value->evaluate(); } } break; case 'INCLUDE': if (isset($param[1])) { $tpl_params = $param['vars']; $explode = explode(chr(10), $param[1]->evaluate()); foreach ($explode as $val) { $bits = explode('=', $val, 2); if (count($bits) == 2) { $tpl_params[ltrim($bits[0])] = $bits[1]; } } $td = isset($param[3]) ? $param[2]->evaluate() : ''; if ($td == '') { $td = 'templates'; } $ex = isset($param[2]) ? $param[1]->evaluate() : ''; if ($ex == '') { $ex = '.tpl'; } $_value = do_template($param[0]->evaluate(), $tpl_params, NULL, false, NULL, $ex, $td); $value = $_value->evaluate(); } break; case 'WHILE': if (isset($param[1])) { $_p = $param[0]->evaluate(); if ($_p == '1' || $_p == '1') { $value = ''; $value .= $param[1]->evaluate(); $value .= ecv($lang, $escaped, $type, $name, $param); } } break; case 'IF': if (isset($param[1])) { $_p = $param[0]->evaluate(); if ($_p == '1' || $_p == '1') { $value = $param[1]->evaluate(); } } break; case 'LOOP': if (isset($param[0])) { if (!array_key_exists($param[0]->evaluate(), $param['vars'])) { require_code('site'); attach_message(do_lang_tempcode('MISSING_TEMPLATE_PARAMETER', $param[0]->evaluate(), '???'), 'warn'); return ''; } $array_key = $param[0]->evaluate(); if (is_numeric($array_key) || strpos($array_key, ',') !== false) { $array = explode(',', $array_key); } else { $array = array_key_exists($array_key, $param['vars']) ? $param['vars'][$array_key] : array(); if (!is_array($array)) { $array = array(); } } $value = ''; if (array_key_exists(1 + 1, $param)) { $columns = $param[1]->evaluate(); $row_starter = array_key_exists(2 + 1, $param) ? $param[2]->evaluate() : '<tr>'; $row_terminator = array_key_exists(3 + 1, $param) ? $param[3]->evaluate() : '</tr>'; $value .= $row_starter; // Sorting if (array_key_exists(4 + 1, $param)) { $sort_key = $param[4]->evaluate(); $rev = array_key_exists(5 + 1, $param) && $param[5]->evaluate() == 'DESC'; if ($sort_key != '') { global $M_SORT_KEY; $M_SORT_KEY = $sort_key; uasort($array, 'multi_sort'); } if ($rev) { $array = array_reverse($array); } } } $last = count($param) - 2; $col = 0; $first = true; foreach ($array as $go_key => $go) { if (!is_array($go)) { $go = array('_loop_key' => make_string_tempcode(is_integer($go_key) ? strval($go_key) : $go_key), '_loop_var' => make_string_tempcode($go)); } // In case it's not a list of maps, but just a list if (isset($param[2]) && $col % $columns == 0 && $col != 0) { $value .= $row_starter; } $ps = $go + $param['vars'] + array('_loop_key' => make_string_tempcode(is_integer($go_key) ? strval($go_key) : $go_key), '_i' => strval($col), '_first' => $first, '_last' => $col == count($array) - 1); $bound = $param[$last]->bind($ps, ''); $value .= $bound->evaluate(); ++$col; if (isset($param[3]) && $col % $columns == 0) { $value .= $row_terminator; } $first = false; } if (isset($param[2]) && $col % $columns != 0) { $value .= $row_terminator; } } break; default: require_code('site'); attach_message(do_lang_tempcode('UNKNOWN_DIRECTIVE', escape_html($name)), 'warn'); } if ($escaped != array()) { apply_tempcode_escaping($escaped, $value); } return $value; } // By elimination, it's language $a = isset($param[0]) ? is_object($param[0]) ? $param[0]->evaluate() : $param[0] : NULL; $b = isset($param[1]) ? is_object($param[1]) ? $param[1]->evaluate() : $param[1] : NULL; $c = isset($param[2]) ? array_splice($param, 2) : NULL; if ($c !== NULL) { foreach ($c as $i => $cc) { if (is_object($cc)) { $c[$i] = $cc->evaluate(); } } } static $dle = false; if (!$dle) { $dle = function_exists('do_lang'); } $ret = $dle ? do_lang($name, $a, $b, $c, $lang, false) : escape_html($name . ':' . (!is_null($a) ? $a : '') . ',' . (!is_null($b) ? $b : '')); if ($ret === NULL) { if ($type != TC_PARAMETER) { require_code('site'); attach_message(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($name)), 'warn'); } $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } return $value; } if ($escaped != array() && $escaped != array(ENTITY_ESCAPED)) { apply_tempcode_escaping(array_diff($escaped, array(ENTITY_ESCAPED)), $ret); } // Escape but without ENTITY_ESCAPED because we don't do that on lang strings return $ret; }
/** * Show results of running a validation function. * * @param string The data validated * @param array Error information * @param boolean Whether we are opening up an XHTML-fragment in a preview box * @param boolean Whether to return Tempcode * @return string Returned result (won't return it $ret is false) */ function display_validation_results($out, $error, $preview_mode = false, $ret = false) { global $KEEP_MARKERS, $SHOW_EDIT_LINKS; $KEEP_MARKERS = false; $SHOW_EDIT_LINKS = false; global $XHTML_SPIT_OUT; $XHTML_SPIT_OUT = 1; if (function_exists('set_time_limit')) { @set_time_limit(280); } require_css('adminzone'); if (!$ret) { $echo = do_header($preview_mode); $echo->evaluate_echo(); } else { ob_start(); } $title = get_page_title('VALIDATION_ERROR'); // Escape and colourfy $i = 0; // Output header if (count($_POST) == 0) { $messy_url = get_param_integer('keep_markers', 0) == 1 ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'special_page_type' => 'code', 'keep_markers' => 1), '_SELF', NULL, true); $ignore_url = build_url(array('page' => '_SELF', 'keep_novalidate' => 1), '_SELF', NULL, true); $ignore_url_2 = build_url(array('page' => '_SELF', 'novalidate' => 1), '_SELF', NULL, true); } else { $messy_url = new ocp_tempcode(); $ignore_url = new ocp_tempcode(); $ignore_url_2 = new ocp_tempcode(); } $error_lines = array(); $return_url = new ocp_tempcode(); if (count($error['errors']) != 0) { $errorst = new ocp_tempcode(); foreach ($error['errors'] as $j => $_error) { $errorst->attach(do_template('VALIDATE_ERROR', array('_GUID' => '2239470f4b9bd38fcb570689cecaedd2', 'I' => strval($j), 'LINE' => integer_format($_error['line']), 'POS' => integer_format($_error['pos']), 'ERROR' => $_error['error']))); $error_lines[$_error['line']] = 1; } $errors = $errorst->evaluate(); $echo = do_template('VALIDATE_ERROR_SCREEN', array('_GUID' => 'db6c362632471e7c856380d32da91054', 'MSG' => do_lang_tempcode('_NEXT_ITEM_BACK'), 'RETURN_URL' => $return_url, 'TITLE' => $title, 'IGNORE_URL_2' => $ignore_url_2, 'IGNORE_URL' => $ignore_url, 'MESSY_URL' => $messy_url, 'ERRORS' => $errorst, 'RET' => $ret)); unset($errorst); $echo->evaluate_echo(); } else { $echo = do_template('VALIDATE_SCREEN', array('_GUID' => 'd8de848803287e4c592418d57450b7db', 'MSG' => do_lang_tempcode('_NEXT_ITEM_BACK'), 'RETURN_URL' => $return_url, 'TITLE' => get_page_title('VIEWING_SOURCE'), 'MESSY_URL' => $messy_url, 'RET' => $ret)); $echo->evaluate_echo(); } $level_ranges = $error['level_ranges']; $tag_ranges = $error['tag_ranges']; $value_ranges = $error['value_ranges']; $current_range = 0; $current_tag = 0; $current_value = 0; $number = 1; $in_at = false; for ($i = 0; $i < strlen($out); ++$i) { if (isset($level_ranges[$current_range])) { $level = $level_ranges[$current_range][0]; $start = $level_ranges[$current_range][1]; if ($start == 0) { $start = 1; } // Hack for when error starts before a line, messing up our output if ($i == $start) { $x = 8; if ($level % $x == 0) { $colour = 'teal'; } if ($level % $x == 1) { $colour = 'blue'; } if ($level % $x == 2) { $colour = 'purple'; } if ($level % $x == 3) { $colour = 'gray'; } if ($level % $x == 4) { $colour = 'red'; } if ($level % $x == 5) { $colour = 'maroon'; } if ($level % $x == 6) { $colour = 'navy'; } if ($level % $x == 7) { $colour = 'olive'; } $previous = $i == 0 ? '' : $out[$i - 1]; $string = new ocp_tempcode(); if ($previous == ' ' || $previous == chr(10) || $previous == chr(13)) { $string->attach(str_pad('', $level * 3 * 6, ' ')); } $string->attach(do_template('VALIDATE_TAG_START', array('_GUID' => '3a4c99283d32006143fc688ce8f2cadc', 'COLOUR' => $colour))); $string->evaluate_echo(); } } if (isset($tag_ranges[$current_tag])) { $start = $tag_ranges[$current_tag][0]; if ($i == $start) { $string = do_template('VALIDATE_TAG_NAME_START'); $string->evaluate_echo(); } } if (isset($value_ranges[$current_value])) { $start = $value_ranges[$current_value][0]; if ($i == $start) { $in_at = true; $string = do_template('VALIDATE_ATTRIBUTE_START'); $string->evaluate_echo(); } } $char = $out[$i]; if ($char == chr(10) || $i == 0) { if ($number > 1) { $escaped_code = do_template('VALIDATE_LINE_END'); $escaped_code->evaluate_echo(); } if (isset($error_lines[$number])) { $markers = new ocp_tempcode(); foreach ($error['errors'] as $j => $_error) { if ($number == $_error['line']) { $markers->attach(do_template('VALIDATE_MARKER', array('_GUID' => '4b1898d5f1e0f56d18a47561659da3bb', 'I' => strval($j), 'ERROR' => $_error['error']))); } } $escaped_code = do_template('VALIDATE_LINE_ERROR', array('_GUID' => '2ffa5c26090d3d814206e3a9e46c7b4e', 'MARKERS' => $markers, 'NUMBER' => integer_format($number))); $escaped_code->evaluate_echo(); } else { $escaped_code = do_template('VALIDATE_LINE', array('_GUID' => '4994f4748c3cd0cbf4e9278ca0e9b1fc', 'NUMBER' => integer_format($number))); $escaped_code->evaluate_echo(); } ++$number; } // Marker $end_markers = new ocp_tempcode(); if (isset($error_lines[$number])) { foreach ($error['errors'] as $_error) { if ($i == $_error['global_pos']) { $_text = do_template('VALIDATE_MARKER_START'); $_text->evaluate_echo(); if ($char == chr(13) || $char == chr(10)) { $__text = '!' . do_lang('HERE') . '!'; if (function_exists('ocp_mark_as_escaped')) { ocp_mark_as_escaped($__text); } echo $__text; } $end_markers->attach(do_template('VALIDATE_MARKER_END')); } } } // Escaping if ($char == '&') { $char = '&'; } if ($char == '<') { $char = '<'; } if ($char == '>') { $char = '>'; } if ($char == '"') { $char = '"'; } if ($char == '\'') { $char = '''; } if (is_null($level_ranges) && $char == ' ') { $char = ' '; } if (is_null($level_ranges) && $char == "\t") { $char = ' '; } // if ($char==' ') $char=' '; if (function_exists('ocp_mark_as_escaped')) { ocp_mark_as_escaped($char); } echo $char; // Marker $end_markers->evaluate_echo(); if (isset($value_ranges[$current_value])) { $end = $value_ranges[$current_value][1]; if ($i == $end - 1) { if ($in_at) { $text = do_template('VALIDATE_ATTRIBUTE_END'); $text->evaluate_echo(); } $in_at = false; ++$current_value; } } if (isset($level_ranges[$current_range])) { $end = $level_ranges[$current_range][2]; if ($i == $end - 1) { $string = do_template('VALIDATE_TAG_END'); $string->evaluate_echo(); ++$current_range; while (isset($level_ranges[$current_range]) && $level_ranges[$current_range][1] <= $i) { ++$current_range; } } } if (isset($tag_ranges[$current_tag])) { $end = $tag_ranges[$current_tag][1]; if ($i == $end - 1) { $string = do_template('VALIDATE_TAG_NAME_END'); $string->evaluate_echo(); ++$current_tag; } } } if ($number > 1) { $escaped_code = do_template('VALIDATE_LINE_END'); $escaped_code->evaluate_echo(); } $echo = do_template('VALIDATE_SCREEN_END', array('_GUID' => '739514a06ae65252293fc62b1c7cec40', 'RET' => $ret)); $echo->evaluate_echo(); if (!$ret) { $echo = do_footer(); $echo->evaluate_echo(); exit; } $out = ob_get_contents(); ob_end_clean(); return $out; }
/** * Get a list of all field types to choose from. * * @param ID_TEXT Field type to select * @param boolean Whether to only show options in the same storage set as $type * @return tempcode List of field types */ function nice_get_field_type($type = '', $limit_to_storage_set = false) { require_lang('fields'); $all_types = find_all_hooks('systems', 'fields'); if ($limit_to_storage_set) { $ob = get_fields_hook($type); $types = array(); list(, , $db_type) = $ob->get_field_value_row_bits(NULL); foreach ($all_types as $this_type => $hook_type) { $ob = get_fields_hook($this_type); list(, , $this_db_type) = $ob->get_field_value_row_bits(NULL); if ($this_db_type == $db_type) { $types[$this_type] = $hook_type; } } } else { $types = $all_types; } $orderings = array(do_lang_tempcode('FIELD_TYPES__TEXT'), 'short_trans', 'short_trans_multi', 'short_text', 'short_text_multi', 'long_trans', 'long_text', 'posting_field', 'codename', 'password', 'email', do_lang_tempcode('FIELD_TYPES__NUMBERS'), 'integer', 'float', do_lang_tempcode('FIELD_TYPES__CHOICES'), 'list', 'radiolist', 'tick', 'multilist', 'tick_multi', do_lang_tempcode('FIELD_TYPES__UPLOADSANDURLS'), 'upload', 'picture', 'video', 'url', 'page_link', 'theme_image', 'theme_image_multi', do_lang_tempcode('FIELD_TYPES__MAGIC'), 'auto_increment', 'random', 'guid', do_lang_tempcode('FIELD_TYPES__REFERENCES'), 'isbn', 'reference', 'content_link', 'content_link_multi', 'user', 'user_multi', 'author'); $_types = array(); $done_one_in_section = true; foreach ($orderings as $o) { if (is_object($o)) { if (!$done_one_in_section) { array_pop($_types); } $_types[] = $o; $done_one_in_section = false; } else { if (array_key_exists($o, $types)) { $_types[] = $o; unset($types[$o]); $done_one_in_section = true; } } } if (!$done_one_in_section) { array_pop($_types); } if (count($types) != 0) { $types = array_merge($_types, array(do_lang_tempcode('FIELD_TYPES__OTHER')), array_keys($types)); } else { $types = $_types; } $type_list = new ocp_tempcode(); foreach ($types as $_type) { if (is_object($_type)) { if (!$type_list->is_empty()) { $type_list->attach(form_input_list_entry('', false, escape_html(''), false, true)); } $type_list->attach(form_input_list_entry('', false, $_type, false, true)); } else { $ob = get_fields_hook($_type); if (method_exists($ob, 'get_field_types')) { $sub_types = $ob->get_field_types(); } else { $sub_types = array($_type => do_lang_tempcode('FIELD_TYPE_' . $_type)); } foreach ($sub_types as $__type => $_title) { $type_list->attach(form_input_list_entry($__type, $__type == $type, $_title)); } } } return make_string_tempcode($type_list->evaluate()); // XHTMLXHTML }