/**
 * Get the tempcode for a view space page. (a view space shows a single entry, with the field name for each field to the left of the value)
 *
 * @param  tempcode		The title of the view space; should be out of get_page_title
 * @param  array			An array of mappings between title and value (each mapping being a field)
 * @return tempcode		The generated view space
 */
function view_space($title, $fields)
{
    $_fields = new ocp_tempcode();
    foreach ($fields as $key => $val) {
        if (!is_array($val)) {
            $raw = true;
        } else {
            list($val, $raw) = $val;
        }
        $_fields->attach(view_space_field(do_lang_tempcode($key), $val, $raw));
    }
    return do_template('VIEW_SPACE_SCREEN', array('_GUID' => 'c8c6cbc8e7b5a47a3078fd69feb057a0', 'TITLE' => $title, 'FIELDS' => $_fields));
}
Exemple #2
0
 /**
  * Standard modular run function for preview hooks.
  *
  * @return array			A pair: The preview, the updated post Comcode
  */
 function run()
 {
     $original_comcode = post_param('post');
     $posting_ref_id = post_param_integer('posting_ref_id', mt_rand(0, 100000));
     $post_bits = do_comcode_attachments($original_comcode, 'news', strval(-$posting_ref_id), true, $GLOBALS['SITE_DB']);
     $post_comcode = $post_bits['comcode'];
     $post_html = $post_bits['tempcode'];
     $view_space_map = array();
     $view_space_map[post_param('label_for__title')] = escape_html(post_param('title'));
     $view_space_map[post_param('label_for__post')] = $post_html;
     $view_space_map[post_param('label_for__news')] = comcode_to_tempcode(post_param('news', ''));
     require_code('templates_view_space');
     $view_space_fields = new ocp_tempcode();
     foreach ($view_space_map as $key => $val) {
         $view_space_fields->attach(view_space_field($key, $val, true));
     }
     $output = do_template('VIEW_SPACE', array('WIDTH' => '170', 'FIELDS' => $view_space_fields));
     return array($output, $post_comcode);
 }
Exemple #3
0
 /**
  * View a single filled-in survey.
  *
  * @return tempcode	The result of execution.
  */
 function __survey_results()
 {
     $title = get_page_title('SURVEY_RESULTS');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/survey_results';
     require_code('templates_view_space');
     $id = get_param_integer('id');
     // entry ID
     $fields = new ocp_tempcode();
     $rows = $GLOBALS['SITE_DB']->query_select('quiz_entries', array('q_time', 'q_member'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $member_id = $rows[0]['q_member'];
     $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id);
     if (is_null($username)) {
         $username = do_lang('UNKNOWN');
     }
     $date = get_timezoned_date($rows[0]['q_time']);
     $question_rows = $GLOBALS['SITE_DB']->query_select('quiz_questions q LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'quiz_entry_answer a ON q.id=a.q_question', array('q.id', 'q_question_text', 'q_answer', 'q_quiz'), array('q_entry' => $id), 'ORDER BY q.id');
     foreach ($question_rows as $q) {
         $quiz_id = $q['q_quiz'];
         $answer = $q['q_answer'];
         if (is_numeric($answer)) {
             $answer_rows = $GLOBALS['SITE_DB']->query_select('quiz_question_answers', array('q_answer_text'), array('q_question' => $q['id'], 'id' => intval($answer)), 'ORDER BY id');
             if (array_key_exists(0, $answer_rows)) {
                 $answer = get_translated_text($answer_rows[0]['q_answer_text']);
             }
         }
         $fields->attach(view_space_field(get_translated_text($q['q_question_text']), $answer));
     }
     breadcrumb_set_parents(array(array('_SELF:_SELF', do_lang_tempcode('MANAGE_QUIZZES')), array('_SELF:_SELF:_survey_results:id=' . strval($quiz_id), do_lang_tempcode('SURVEY_RESULTS'))));
     breadcrumb_set_self(do_lang_tempcode('RESULT'));
     $member_url = get_base_url();
     if (!is_guest($member_id)) {
         $member_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id, false, true);
         if (is_object($member_url)) {
             $member_url = $member_url->evaluate();
         }
     }
     return do_template('VIEW_SPACE_SCREEN', array('_GUID' => '02b4dd6d52feaf3844e631e56395c4da', 'TITLE' => $title, 'TEXT' => do_lang_tempcode('SURVEY_WAS_ENTERED_AS_FOLLOWS', escape_html($username), escape_html($member_url), escape_html($date)), 'FIELDS' => $fields));
 }
Exemple #4
0
/**
 * Build up a preview based on what was submitted.
 *
 * @param  boolean	Whether to return additional data
 * @return mixed		Either tempcode for the preview, or a tuple of details
 */
function build_preview($multi_return = false)
{
    // Check CAPTCHA if it is passed
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && array_key_exists('security_image', $_POST)) {
            require_code('captcha');
            enforce_captcha(false);
        }
    }
    require_code('attachments2');
    $hooks = find_all_hooks('systems', 'preview');
    $output = NULL;
    $new_post_value = NULL;
    $attachment_type = NULL;
    $forum_db = false;
    $limit_to = NULL;
    foreach (array_keys($hooks) as $hook) {
        require_code('hooks/systems/preview/' . $hook);
        $object = object_factory('Hook_Preview_' . $hook, true);
        if (is_null($object)) {
            continue;
        }
        $apply_bits = $object->applies();
        $applies = $apply_bits[0];
        if ($applies) {
            $attachment_type = $apply_bits[1];
            $forum_db = array_key_exists(2, $apply_bits) ? $apply_bits[2] : false;
            $limit_to = array_key_exists(3, $apply_bits) ? $apply_bits[3] : NULL;
            if (method_exists($object, 'run')) {
                list($output, $new_post_value) = $object->run();
            }
            break;
        }
    }
    $validation = new ocp_tempcode();
    $keyword_density = new ocp_tempcode();
    $spelling = new ocp_tempcode();
    $meta_keywords = post_param('meta_keywords', '');
    $spellcheck = post_param_integer('perform_spellcheck', 0) == 1;
    $keywordcheck = post_param_integer('perform_keywordcheck', 0) == 1 && $meta_keywords != '';
    if (post_param_integer('perform_validation', 0) != 0) {
        foreach ($_POST as $key => $val) {
            if (!is_string($val)) {
                continue;
            }
            $val = post_param($key, '');
            // stripslashes, and wysiwyg output handling
            $tempcodecss = post_param_integer('tempcodecss__' . $key, 0) == 1;
            $supports_comcode = post_param_integer('comcode__' . $key, 0) == 1;
            if ($supports_comcode) {
                $temp = $_FILES;
                $_FILES = array();
                $valt = comcode_to_tempcode($val);
                $_FILES = $temp;
                require_code('view_modes');
                require_code('obfuscate');
                require_code('validation');
                $validation->attach(do_xhtml_validation($valt->evaluate(), false, post_param_integer('perform_validation', 0), true));
            } elseif ($tempcodecss) {
                $i = 0;
                $color = post_param(strval($i), '');
                while ($color != '') {
                    $val = str_replace('<color-' . strval($i) . '>', '#' . $color, $val);
                    $i++;
                    $color = post_param(strval($i), '');
                }
                $_val_orig = $val;
                require_lang('validation');
                require_css('adminzone');
                require_code('view_modes');
                require_code('obfuscate');
                require_code('validation');
                require_code('validation2');
                $error = check_css($_val_orig);
                $show = count($error['errors']) != 0;
                if ($show) {
                    $validation->attach(display_validation_results($_val_orig, $error, true, true));
                }
            }
        }
    }
    if ($spellcheck) {
        if (addon_installed('wordfilter')) {
            $words_skip = collapse_1d_complexity('w_replacement', $GLOBALS['SITE_DB']->query_select('wordfilter', array('w_replacement')));
        } else {
            $words_skip = array();
        }
        require_once get_file_base() . '/data/areaedit/plugins/SpellChecker/spell-check-logic.php';
    }
    $db = $forum_db ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $view_space_map = array();
    require_code('templates_view_space');
    foreach ($_POST as $key => $val) {
        if (!is_string($val)) {
            continue;
        }
        if (!is_null($limit_to) && !in_array($key, $limit_to)) {
            continue;
        }
        $val = post_param($key, '');
        // stripslashes, and wysiwyg output handling
        if ($val == '0') {
            $val = do_lang('NO');
        }
        if ($val == '1') {
            $val = do_lang('YES');
        }
        if (substr($key, 0, 14) == 'review_rating' || substr($key, 0, 7) == 'rating') {
            $val .= '/10';
        }
        $is_hidden = in_array($key, array('from_url', 'password', 'confirm_password', 'edit_password', 'MAX_FILE_SIZE', 'perform_validation', '_validated', 'id', 'posting_ref_id', 'f_face', 'f_colour', 'f_size', 'http_referer')) || strpos($key, 'hour') !== false || strpos($key, 'access_') !== false || strpos($key, 'minute') !== false || strpos($key, 'confirm') !== false || strpos($key, 'pre_f_') !== false || strpos($key, 'label_for__') !== false || strpos($key, 'wysiwyg_version_of_') !== false || strpos($key, 'is_wysiwyg') !== false || strpos($key, 'require__') !== false || strpos($key, 'tempcodecss__') !== false || strpos($key, 'comcode__') !== false || strpos($key, '_parsed') !== false || preg_match('#^caption\\d+$#', $key) != 0 || preg_match('#^attachmenttype\\d+$#', $key) != 0 || substr($key, 0, 1) == '_' || substr($key, 0, 9) == 'hidFileID' || substr($key, 0, 11) == 'hidFileName';
        if (substr($key, 0, 14) == 'tick_on_form__') {
            if (post_param_integer(substr($key, 14), 0) == 1) {
                $is_hidden = true;
            } else {
                $key = substr($key, 14);
            }
        }
        if (substr($key, -4) == '_day') {
            $key = substr($key, 0, strlen($key) - 4);
            $timestamp = get_input_date($key);
            if (is_null($timestamp)) {
                $is_hidden = true;
            } else {
                $val = get_timezoned_date($timestamp, false, true, false, true);
            }
        } elseif (substr($key, -6) == '_month' || substr($key, -5) == '_year') {
            $is_hidden = true;
        }
        $key_nice = post_param('label_for__' . $key, ucwords(str_replace('_', ' ', $key)));
        if ($key_nice == '') {
            $is_hidden = true;
        }
        if (!$is_hidden) {
            if ($spellcheck) {
                require_code('comcode_from_html');
                $mispellings = spellchecklogic('check', strip_comcode(semihtml_to_comcode($val, true)), $words_skip, true);
                $_misspellings = array();
                foreach ($mispellings as $misspelling) {
                    list($word_bad, $words_good) = $misspelling;
                    $_misspellings[] = array('WORD' => $word_bad, 'CORRECTIONS' => implode(', ', $words_good));
                }
                if (count($_misspellings) != 0) {
                    $spelling->attach(do_template('PREVIEW_SCRIPT_SPELLING', array('_GUID' => '9649572982c01995a8f47c58d16fda39', 'FIELD' => $key_nice, 'MISSPELLINGS' => $_misspellings)));
                }
            }
            if ($keywordcheck && (strpos($val, ' ') !== false || $key == 'title')) {
                $keyword_explode = explode(',', $meta_keywords);
                $keywords = array();
                $word_count = str_word_count($val);
                if ($word_count != 0) {
                    foreach ($keyword_explode as $meta_keyword) {
                        $meta_keyword = trim($meta_keyword);
                        if ($meta_keyword != '') {
                            $density = substr_count($val, $meta_keyword) / $word_count;
                            $ideal_density = 1.0 / (9.0 * count($keyword_explode));
                            // Pretty rough -- common sense is needed
                            $keywords[] = array('sort' => $ideal_density, 'KEYWORD' => $meta_keyword, 'IDEAL_DENSITY' => strval(intval(round($ideal_density * 100))), 'DENSITY' => strval(intval(round($density * 100))));
                        }
                    }
                    global $M_SORT_KEY;
                    $M_SORT_KEY = 'sort';
                    usort($keywords, 'multi_sort');
                    foreach ($keywords as $ti => $meta_keyword) {
                        unset($keywords[$ti]['sort']);
                    }
                    if (count($keywords) != 0) {
                        $keyword_density->attach(do_template('PREVIEW_SCRIPT_KEYWORD_DENSITY', array('_GUID' => '4fa05e9f52023958a3594d1610b00747', 'FIELD' => $key_nice, 'KEYWORDS' => $keywords)));
                    }
                }
            }
        }
        if (is_null($output)) {
            if (is_null($attachment_type) || $key != 'post') {
                $tempcodecss = post_param_integer('tempcodecss__' . $key, 0) == 1;
                $supports_comcode = post_param_integer('comcode__' . $key, 0) == 1;
                $preformatted = post_param_integer('pre_f_' . $key, 0) == 1;
                if ($is_hidden) {
                    continue;
                }
                if ($preformatted) {
                    $valt = with_whitespace($val);
                } elseif ($supports_comcode) {
                    $valt = comcode_to_tempcode($val);
                } elseif ($tempcodecss) {
                    $i = 0;
                    $color = post_param(strval($i), '');
                    while ($color != '') {
                        $val = str_replace('<color-' . strval($i) . '>', '#' . $color, $val);
                        $i++;
                        $color = post_param(strval($i), '');
                    }
                    $_val_orig = $val;
                    $valt = comcode_to_tempcode("[code=\"CSS\"]" . $val . "[/code]");
                } else {
                    $valt = make_string_tempcode(escape_html($val));
                }
                $view_space_map[$key_nice] = $valt;
            } else {
                $tempcodecss = false;
                $posting_ref_id = post_param_integer('posting_ref_id');
                if ($posting_ref_id < 0) {
                    fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
                }
                $post_bits = do_comcode_attachments($val, $attachment_type, strval(-$posting_ref_id), true, $db);
                $new_post_value = $post_bits['comcode'];
                $view_space_map[$key_nice] = $post_bits['tempcode'];
                $val = $post_bits['tempcode'];
                $supports_comcode = true;
            }
        }
    }
    // Make attachments temporarily readable without any permission context
    global $COMCODE_ATTACHMENTS;
    $posting_ref_id = post_param_integer('posting_ref_id', NULL);
    if (!is_null($posting_ref_id)) {
        if (array_key_exists(strval(-$posting_ref_id), $COMCODE_ATTACHMENTS)) {
            foreach ($COMCODE_ATTACHMENTS[strval(-$posting_ref_id)] as $attachment) {
                $db->query_delete('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => strval(-$posting_ref_id), 'a_id' => $attachment['id']), '', 1);
                $db->query_insert('attachment_refs', array('r_referer_type' => 'null', 'r_referer_id' => strval(-$posting_ref_id), 'a_id' => $attachment['id']));
            }
        }
    }
    if (is_null($output)) {
        if (count($view_space_map) == 1) {
            $output = array_pop($view_space_map);
        } else {
            $view_space_fields = new ocp_tempcode();
            foreach ($view_space_map as $key => $val) {
                $view_space_fields->attach(view_space_field($key, $val, true));
            }
            $output = do_template('VIEW_SPACE', array('_GUID' => '3f548883b9eb37054c500d1088d9efa3', 'WIDTH' => '170', 'FIELDS' => $view_space_fields));
        }
    }
    // This is to get the Comcode attachments updated to the new IDs
    if (!is_null($new_post_value)) {
        $new_post_value_html = comcode_to_tempcode($new_post_value, NULL, false, 60, NULL, $db, true);
        if (strpos($new_post_value_html->evaluate(), '<!-- CC-error -->') === false) {
            $output->attach(do_template('PREVIEW_SCRIPT_CODE', array('_GUID' => 'bc7432af91e1eaf212dc210f3bf2f756', 'NEW_POST_VALUE_HTML' => $new_post_value_html, 'NEW_POST_VALUE' => $new_post_value)));
        }
    }
    $output->handle_symbol_preprocessing();
    if ($multi_return) {
        return array($output, $validation, $keyword_density, $spelling);
    }
    return $output;
}
Exemple #5
0
 /**
  * The UI to view a banner.
  *
  * @return tempcode		The UI
  */
 function view_banner()
 {
     $title = get_page_title('BANNER_INFORMATION');
     $source = get_param('source');
     $rows = $GLOBALS['SITE_DB']->query_select('banners', array('*'), array('name' => $source));
     if (!array_key_exists(0, $rows)) {
         warn_exit(do_lang_tempcode('BANNER_MISSING_SOURCE'));
     }
     $myrow = $rows[0];
     if (is_guest($myrow['submitter']) || $myrow['submitter'] != get_member()) {
         check_specific_permission('view_anyones_banner_stats');
     }
     switch ($myrow['the_type']) {
         case 0:
             $type = do_lang_tempcode('BANNER_PERMANENT');
             break;
         case 1:
             $type = do_lang_tempcode('_BANNER_HITS_LEFT', do_lang_tempcode('BANNER_CAMPAIGN'), make_string_tempcode(integer_format($myrow['campaign_remaining'])));
             break;
         case 2:
             $type = do_lang_tempcode('BANNER_DEFAULT');
             break;
     }
     if ($myrow['views_to'] != 0) {
         $click_through = protect_from_escaping(escape_html(float_format(100.0 * ($myrow['hits_to'] / $myrow['views_to']))));
     } else {
         $click_through = do_lang_tempcode('NA_EM');
     }
     $has_banner_network = $GLOBALS['SITE_DB']->query_value('banners', 'SUM(views_from)') != 0.0;
     $fields = new ocp_tempcode();
     require_code('templates_view_space');
     $fields->attach(view_space_field(do_lang_tempcode('TYPE'), $type));
     if ($myrow['b_type'] != '') {
         $fields->attach(view_space_field(do_lang_tempcode('_BANNER_TYPE'), $myrow['b_type']));
     }
     $expiry_date = is_null($myrow['expiry_date']) ? do_lang_tempcode('NA_EM') : make_string_tempcode(escape_html(get_timezoned_date($myrow['expiry_date'], true)));
     $fields->attach(view_space_field(do_lang_tempcode('EXPIRY_DATE'), $expiry_date));
     if ($has_banner_network) {
         $fields->attach(view_space_field(do_lang_tempcode('BANNER_HITSFROM'), integer_format($myrow['hits_from']), false, 'hits_from'));
         $fields->attach(view_space_field(do_lang_tempcode('BANNER_VIEWSFROM'), integer_format($myrow['views_from']), false, 'views_from'));
     }
     $fields->attach(view_space_field(do_lang_tempcode('BANNER_HITSTO'), $myrow['site_url'] == '' ? do_lang_tempcode('CANT_TRACK') : protect_from_escaping(escape_html(integer_format($myrow['hits_to']))), false, 'hits_to'));
     $fields->attach(view_space_field(do_lang_tempcode('BANNER_VIEWSTO'), $myrow['site_url'] == '' ? do_lang_tempcode('CANT_TRACK') : protect_from_escaping(escape_html(integer_format($myrow['views_to']))), false, 'views_to'));
     $fields->attach(view_space_field(do_lang_tempcode('BANNER_CLICKTHROUGH'), $click_through));
     $username = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($myrow['submitter']);
     $fields->attach(view_space_field(do_lang_tempcode('SUBMITTER'), $username, true));
     $view_space = do_template('VIEW_SPACE', array('_GUID' => 'eb97a46d8e9813da7081991d5beed270', 'WIDTH' => '300', 'FIELDS' => $fields));
     $banner = show_banner($myrow['name'], $myrow['b_title_text'], get_translated_tempcode($myrow['caption']), $myrow['img_url'], $source, $myrow['site_url'], $myrow['b_type']);
     $edit_url = new ocp_tempcode();
     if (has_actual_page_access(NULL, 'cms_banners', NULL, NULL) && has_edit_permission('mid', get_member(), $myrow['submitter'], 'cms_banners')) {
         $edit_url = build_url(array('page' => 'cms_banners', 'type' => '_ed', 'id' => $source), get_module_zone('cms_banners'));
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Banner', 'title' => get_translated_text($myrow['caption']), 'identifier' => '_SEARCH:banners:view:' . $source, 'description' => '', 'image' => $myrow['img_url']);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('CHOOSE'))));
     return do_template('BANNER_VIEW_SCREEN', array('_GUID' => 'ed923ae0682c6ed679c0efda688c49ea', 'TITLE' => $title, 'EDIT_URL' => $edit_url, 'VIEW_SPACE' => $view_space, 'BANNER' => $banner));
 }