Example #1
0
/**
 * URL'ise specially encoded text-acceptance language strings.
 *
 * @param  string			The language string
 * @param  mixed			The URL (either tempcode or string)
 * @param  string			The title of the hyperlink
 * @param  boolean		Whether to use a new window
 * @return tempcode		The encoded version
 */
function _urlise_lang($string, $url, $title, $new_window)
{
    $a = strpos($string, '<{');
    $b = strpos($string, '}>');
    if ($a === false || $b === false || $b < $a) {
        return make_string_tempcode($string);
    }
    $section = substr($string, $a + 2, $b - $a - 2);
    $prior = substr($string, 0, $a);
    $after = substr($string, $b + 2);
    if ($GLOBALS['XSS_DETECT']) {
        ocp_mark_as_escaped($section);
        ocp_mark_as_escaped($prior);
        ocp_mark_as_escaped($after);
    }
    if (is_string($url)) {
        if ($url == '') {
            return protect_from_escaping($section);
        }
    } else {
        if ($url->is_empty()) {
            return protect_from_escaping($section);
        }
    }
    $out = new ocp_tempcode();
    $out->attach(protect_from_escaping($prior));
    $out->attach(hyperlink($url, protect_from_escaping($section), $new_window, false, $title));
    $out->attach(protect_from_escaping($after));
    return $out;
}
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('downloads');
     require_css('downloads');
     require_lang('downloads');
     require_code('ocfiltering');
     $number = array_key_exists('param', $map) ? intval($map['param']) : 10;
     $filter = array_key_exists('filter', $map) ? $map['filter'] : '*';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('downloads');
     $sql_filter = ocfilter_to_sqlfragment($filter, 'p.category_id', 'download_categories', 'parent_id', 'p.category_id', 'id');
     // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set)
     $rows = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'download_downloads p WHERE validated=1 AND (' . $sql_filter . ') ORDER BY add_date DESC', $number);
     $title = do_lang_tempcode('RECENT', make_string_tempcode(integer_format($number)), do_lang_tempcode('SECTION_DOWNLOADS'));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $title = protect_from_escaping(escape_html($map['title']));
     }
     $out = new ocp_tempcode();
     foreach ($rows as $i => $row) {
         if ($i != 0) {
             $out->attach(do_template('BLOCK_SEPARATOR'));
         }
         $out->attach(get_download_html($row, true, true, $zone));
     }
     if ($out->is_empty()) {
         if (has_actual_page_access(NULL, 'cms_downloads', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_downloads')) {
             $submit_url = build_url(array('page' => 'cms_downloads', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_downloads'));
         } else {
             $submit_url = new ocp_tempcode();
         }
         return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '74399763a51102bdd6e6d92c2c11354f', 'HIGH' => false, 'TITLE' => $title, 'MESSAGE' => do_lang_tempcode('NO_DOWNLOADS_YET'), 'ADD_NAME' => do_lang_tempcode('ADD_DOWNLOAD'), 'SUBMIT_URL' => $submit_url));
     }
     return do_template('BLOCK_MAIN_RECENT_DOWNLOADS', array('_GUID' => '257fa1b83d1b6fe3acbceb2b618e6d7f', 'TITLE' => $title, 'CONTENT' => $out, 'NUMBER' => integer_format($number)));
 }
Example #3
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     $bits = new ocp_tempcode();
     $map = array();
     $url = get_base_url();
     list($rank, $links, $speed) = getAlexaRank($url);
     $map['Google PageRank'] = getPageRank($url);
     $map['Alexa rank'] = $rank;
     $map['Back links'] = protect_from_escaping('<a title="Show back links" href="http://www.google.co.uk/search?as_lq=' . urlencode($url) . '">' . $links . '</a>');
     $map['Speed'] = $speed;
     foreach ($map as $key => $val) {
         $bits->attach(do_template('BLOCK_SIDE_STATS_SUBLINE', array('KEY' => $key, 'VALUE' => is_null($val) ? '' : $val)));
     }
     $section = do_template('BLOCK_SIDE_STATS_SECTION', array('SECTION' => 'Meta stats', 'CONTENT' => $bits));
     return $section;
 }
Example #4
0
/**
 * Get template fields to insert into a form page, for manipulation of seo fields.
 *
 * @param  ID_TEXT		The type of resource (e.g. download)
 * @param  ?ID_TEXT		The ID of the resource (NULL: adding)
 * @return tempcode		Form page tempcode fragment
 */
function seo_get_fields($type, $id = NULL)
{
    require_code('form_templates');
    if (is_null($id)) {
        list($keywords, $description) = array('', '');
    } else {
        list($keywords, $description) = seo_meta_get_for($type, $id);
    }
    $fields = new ocp_tempcode();
    if (get_value('disable_seo') !== '1' && (get_value('disable_seo') !== '2' || !is_null($id))) {
        $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('SECTION_HIDDEN' => $keywords == '' && $description == '', 'TITLE' => do_lang_tempcode('SEO'), 'HELP' => get_option('show_docs') === '0' ? NULL : protect_from_escaping(symbol_tempcode('URLISE_LANG', array(do_lang('TUTORIAL_ON_THIS'), brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/tut_seo', 'tut_seo', '1'))))));
        $fields->attach(form_input_line_multi(do_lang_tempcode('KEYWORDS'), do_lang_tempcode('DESCRIPTION_META_KEYWORDS'), 'meta_keywords[]', array_map('trim', explode(',', preg_replace('#,+#', ',', $keywords))), 0));
        $fields->attach(form_input_line(do_lang_tempcode('META_DESCRIPTION'), do_lang_tempcode('DESCRIPTION_META_DESCRIPTION'), 'meta_description', $description, false));
    }
    return $fields;
}
Example #5
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     $base_url = get_forum_base_url();
     $forums = get_param('url', $base_url . '/');
     if (substr($forums, 0, strlen($base_url)) != $base_url) {
         $base_url = rtrim($forums, '/');
         if (strpos($base_url, '.php') !== false || strpos($base_url, '?') !== false) {
             $base_url = dirname($base_url);
         }
         //log_hack_attack_and_exit('REFERRER_IFRAME_HACK'); No longer a hack attack becase people webmasters changed their forum base URL at some point, creating problems with old bookmarks!
         header('Location: ' . get_self_url(true, false, array('url' => get_forum_base_url())));
         exit;
     }
     $old_method = false;
     if ($old_method) {
         return do_template('FORUMS_EMBED', array('_GUID' => '159575f6b83c5366d29e184a8dd5fc49', 'FORUMS' => $forums));
     }
     $GLOBALS['SCREEN_TEMPLATE_CALLED'] = '';
     require_code('integrator');
     return do_template('COMCODE_SURROUND', array('CLASS' => 'float_surrounder', 'CONTENT' => protect_from_escaping(reprocess_url($forums, $base_url))));
 }
Example #6
0
/**
 * Get an ordered array of all the entries in the specified catalogue.
 *
 * @param  ?AUTO_LINK		The ID of the category for which the entries are being collected (NULL: entries are [and must be] passed instead)
 * @param  ID_TEXT			The name of the catalogue
 * @param  ?array				A database row of the catalogue we are working with (NULL: read it in)
 * @param  ID_TEXT			The view type we're doing
 * @set    PAGE SEARCH CATEGORY
 * @param  ID_TEXT			The template set we are rendering this category using
 * @param  ?integer			The maximum number of entries to show on a single page of this this category (NULL: all)
 * @param  ?integer			The entry number to start at (NULL: all)
 * @param  ?mixed				The entries to show, may be from other categories. Can either be SQL fragment, or array (NULL: use $start and $max)
 * @param  ?AUTO_LINK		The virtual root for display of this category (NULL: default)
 * @param  ?SHORT_INTEGER	The display type to use (NULL: lookup from $catalogue)
 * @param  boolean			Whether to perform sorting
 * @param  ?array				A list of entry rows (NULL: select them normally)
 * @param  string				Search filter (blank: no filter)
 * @param  ?ID_TEXT			Orderer (NULL: read from environment)
 * @return array				An array containing our built up entries (renderable tempcode), our sorting interface, and our entries (entry records from database, with an additional 'map' field), and the max rows
 */
function get_catalogue_category_entry_buildup($category_id, $catalogue_name, $catalogue, $view_type, $tpl_set, $max, $start, $select, $root, $display_type = NULL, $do_sorting = true, $entries = NULL, $search = '', $_order_by = NULL)
{
    if (addon_installed('ecommerce')) {
        require_code('ecommerce');
    }
    $is_ecomm = is_ecommerce_catalogue($catalogue_name);
    if (is_null($catalogue)) {
        $_catalogues = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
        $catalogue = $_catalogues[0];
    }
    $or_list = mixed();
    if (is_null($entries) && !is_null($select)) {
        if (is_array($select) && count($select) == 0 || is_string($select) && $select == '') {
            $entries = array();
        } else {
            if (!is_array($select)) {
                $or_list = $select;
            } else {
                $or_list = '';
                foreach ($select as $s) {
                    if ($or_list != '') {
                        $or_list .= ' OR ';
                    }
                    $or_list .= 'e.id=' . strval($s);
                }
            }
        }
    }
    if (is_null($display_type)) {
        $display_type = get_param_integer('keep_cat_display_type', $catalogue['c_display_type']);
    }
    // Find order field
    global $CAT_FIELDS_CACHE;
    if (isset($CAT_FIELDS_CACHE[$catalogue_name])) {
        $fields = $CAT_FIELDS_CACHE[$catalogue_name];
    } else {
        $fields = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $catalogue_name), 'ORDER BY cf_order');
    }
    $CAT_FIELDS_CACHE[$catalogue_name] = $fields;
    if ($do_sorting) {
        global $NON_CANONICAL_PARAMS;
        $NON_CANONICAL_PARAMS[] = 'order';
        if (is_null($_order_by)) {
            $_order_by = get_param('order', '');
        }
        if ($_order_by == '' || strpos($_order_by, ' ') === false) {
            $order_by = '0';
            $direction = 'ASC';
            foreach ($fields as $i => $field) {
                if ($field['cf_defines_order'] != 0) {
                    $order_by = strval($i);
                    $direction = $field['cf_defines_order'] == 1 ? 'ASC' : 'DESC';
                    $_order_by = strval($field['id']) . ' ' . $direction;
                    break;
                }
            }
        } else {
            list($order_by, $direction) = explode(' ', $_order_by);
            if ($direction != 'ASC' && $direction != 'DESC') {
                log_hack_attack_and_exit('ORDERBY_HACK');
            }
            if ($order_by != 'rating' && $order_by != 'add_date') {
                $found = false;
                foreach ($fields as $i => $field) {
                    if ($order_by == strval($field['id'])) {
                        $order_by = strval($i);
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    $order_by = '0';
                }
                // Could not find
            }
        }
    } else {
        $order_by = mixed();
        $direction = 'ASC';
    }
    // Get entries in this category
    $map = '1=1';
    if (!is_null($category_id)) {
        $map .= ' AND cc_id=' . strval($category_id);
    }
    if (!has_specific_permission(get_member(), 'see_unvalidated')) {
        $map .= ' AND ce_validated=1';
    }
    if (!is_null($or_list)) {
        $map .= ' AND (' . $or_list . ')';
    }
    $in_db_sorting = !is_null($order_by) && $do_sorting;
    require_code('fields');
    if (is_null($entries)) {
        if ($in_db_sorting) {
            $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
            if ($order_by == 'add_date') {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map . ' ORDER BY ce_add_date ' . $direction, $max, $start);
            } elseif ($order_by == 'rating') {
                $select_rating = '(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogues') . ' AND rating_for_id=e.id) AS compound_rating';
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.*,' . $select_rating . ' FROM ' . get_table_prefix() . 'catalogue_entries e  WHERE ' . $map . ' ORDER BY compound_rating ' . $direction, $max, $start);
            } else {
                $ob = get_fields_hook($fields[intval($order_by)]['cf_type']);
                list(, , $table) = $ob->get_field_value_row_bits($fields[$order_by]);
                if (strpos($table, '_trans') !== false) {
                    $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']) . ' LEFT JOIN ' . get_table_prefix() . 'translate t ON f.cv_value=t.id';
                    $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ' . ($num_entries > 300 ? '' : 'ORDER BY t.text_original ' . $direction), $max, $start);
                } else {
                    $join = get_table_prefix() . 'catalogue_entries e LEFT JOIN ' . get_table_prefix() . 'catalogue_efv_' . $table . ' f ON f.ce_id=e.id AND f.cf_id=' . strval($fields[$order_by]['id']);
                    $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . $join . ' WHERE ' . $map . ' ORDER BY f.cv_value ' . $direction, $max, $start);
                }
            }
            $start = 0;
            // To stop it skipping itself
        } else {
            if ((is_null($order_by) || !$do_sorting) && !is_null($max)) {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map, $max, $start);
                $num_entries = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
                $start = 0;
                // To stop it skipping itself
            } else {
                $entries = $max == 0 ? array() : $GLOBALS['SITE_DB']->query('SELECT e.* FROM ' . get_table_prefix() . 'catalogue_entries e WHERE ' . $map);
                $num_entries = count($entries);
            }
        }
    } else {
        $num_entries = count($entries);
    }
    if ($num_entries > 300 && !$in_db_sorting) {
        $in_db_sorting = true;
    }
    // Needed to stop huge slow down
    foreach ($entries as $i => $entry) {
        $entries[$i]['map'] = get_catalogue_entry_map($entry, $catalogue, $view_type, $tpl_set, $root, $fields, $display_type == 1 && !$is_ecomm && !is_null($order_by) ? array(0, intval($order_by)) : NULL, false, false, intval($order_by));
    }
    // Implement search filter
    if ($search != '') {
        $new_entries = array();
        for ($i = 0; $i < $num_entries; $i++) {
            $two_d_list = $entries[$i]['map']['FIELDS_2D'];
            $all_output = '';
            foreach ($two_d_list as $index => $l) {
                $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' ';
            }
            if (strpos(strtolower($all_output), strtolower($search)) !== false) {
                $new_entries[] = $entries[$i];
            }
        }
        $entries = $new_entries;
    }
    disable_php_memory_limit();
    if ($do_sorting) {
        // Sort entries
        $selectors = new ocp_tempcode();
        foreach ($fields as $i => $field) {
            if ($field['cf_searchable'] == 1) {
                $potential_sorter_name = get_translated_text($field['cf_name']);
                foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) {
                    $sort_sel = $order_by == strval($i) && $direction == $dir_code;
                    $_potential_sorter_name = new ocp_tempcode();
                    $_potential_sorter_name->attach(escape_html($potential_sorter_name));
                    $_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
                    $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'dfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => strval($field['id']) . ' ' . $dir_code)));
                }
            }
        }
        $extra_sorts = array();
        $extra_sorts['add_date'] = '_ADDED';
        if (get_option('is_on_rating') == '0') {
            $has_ratings = false;
        } else {
            if (is_null($entries)) {
                $has_ratings = false;
                foreach ($entries as $entry) {
                    if ($entry['allow_rating'] == 1) {
                        $has_ratings = true;
                    }
                }
                if ($has_ratings) {
                    $extra_sorts['rating'] = 'RATING';
                }
            } else {
                $has_ratings = true;
            }
        }
        foreach ($extra_sorts as $extra_sort_code => $extra_sort_lang) {
            foreach (array('ASC' => '_ASCENDING', 'DESC' => '_DESCENDING') as $dir_code => $dir_lang) {
                $sort_sel = $order_by == $extra_sort_code && $direction == $dir_code;
                $_potential_sorter_name = new ocp_tempcode();
                $_potential_sorter_name->attach(do_lang_tempcode($extra_sort_lang));
                $_potential_sorter_name->attach(do_lang_tempcode($dir_lang));
                $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('_GUID' => 'xfdsfdsusd0fsd0dsf', 'SELECTED' => $sort_sel, 'NAME' => protect_from_escaping($_potential_sorter_name), 'VALUE' => $extra_sort_code . ' ' . $dir_code)));
            }
        }
        $sort_url = get_self_url(false, false, array('order' => NULL), false, true);
        $sorting = do_template('RESULTS_BROWSER_SORT', array('_GUID' => '9fgjfdklgjdfgkjlfdjgd90', 'SORT' => 'order', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors));
        if (!$in_db_sorting) {
            for ($i = 0; $i < $num_entries; $i++) {
                if (!array_key_exists($i, $entries)) {
                    continue;
                }
                for ($j = $i + 1; $j < $num_entries; $j++) {
                    if (!array_key_exists($j, $entries)) {
                        continue;
                    }
                    $a = @$entries[$j]['map']['FIELD_' . $order_by];
                    if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$j]['map'])) {
                        $a = @$entries[$j]['map']['FIELD_' . $order_by . '_PLAIN'];
                    }
                    $b = @$entries[$i]['map']['FIELD_' . $order_by];
                    if (array_key_exists('FIELD_' . $order_by . '_PLAIN', @$entries[$i]['map'])) {
                        $b = @$entries[$i]['map']['FIELD_' . $order_by . '_PLAIN'];
                    }
                    if (is_object($a)) {
                        $a = $a->evaluate();
                    }
                    if (is_object($b)) {
                        $b = $b->evaluate();
                    }
                    if ($fields[$order_by]['cf_type'] == 'date') {
                        $bits = explode(' ', $a, 2);
                        $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3);
                        if (!array_key_exists(1, $date_bits)) {
                            $date_bits[1] = date('m');
                        }
                        if (!array_key_exists(2, $date_bits)) {
                            $date_bits[2] = date('Y');
                        }
                        $time_bits = explode(':', $bits[1], 3);
                        if (!array_key_exists(1, $time_bits)) {
                            $time_bits[1] = '00';
                        }
                        if (!array_key_exists(2, $time_bits)) {
                            $time_bits[2] = '00';
                        }
                        $time_a = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0]));
                        $bits = explode(' ', $b, 2);
                        $date_bits = explode(strpos($bits[0], '-') !== false ? '-' : '/', $bits[0], 3);
                        if (!array_key_exists(1, $date_bits)) {
                            $date_bits[1] = date('m');
                        }
                        if (!array_key_exists(2, $date_bits)) {
                            $date_bits[2] = date('Y');
                        }
                        $time_bits = explode(':', $bits[1], 3);
                        if (!array_key_exists(1, $time_bits)) {
                            $time_bits[1] = '00';
                        }
                        if (!array_key_exists(2, $time_bits)) {
                            $time_bits[2] = '00';
                        }
                        $time_b = mktime(intval($time_bits[0]), intval($time_bits[1]), intval($time_bits[2]), intval($date_bits[1]), intval($date_bits[2]), intval($date_bits[0]));
                        $r = $time_a < $time_b ? -1 : ($time_a == $time_b ? 0 : 1);
                    } else {
                        $r = strnatcmp(strtolower($a), strtolower($b));
                    }
                    if ($r < 0 && $direction == 'ASC' || $r > 0 && $direction == 'DESC') {
                        $temp = $entries[$i];
                        $entries[$i] = $entries[$j];
                        $entries[$j] = $temp;
                    }
                }
            }
        }
    } else {
        $sorting = new ocp_tempcode();
    }
    // Build up entries
    $entry_buildup = new ocp_tempcode();
    $extra_map = array();
    if ($is_ecomm) {
        require_lang('shopping');
        $i = 0;
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            $extra_map[$i]['ADD_TO_CART'] = build_url(array('page' => 'shopping', 'type' => 'add_item', 'product_id' => $entry['id'], 'hook' => 'catalogue_items'), get_module_zone('shopping'));
        }
    }
    if ($display_type == 2) {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) {
                $tab_entry_map = $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array());
                if (get_option('is_on_comments') == '1' && $entry['allow_comments'] >= 1 || get_option('is_on_rating') == '1' && $entry['allow_rating'] == 1 || get_option('is_on_trackbacks') == '1' && $entry['allow_trackbacks'] == 1) {
                    $tab_entry_map['VIEW_URL'] = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $entry['id'], 'root' => $root == -1 ? NULL : $root), get_module_zone('catalogues'));
                } else {
                    $tab_entry_map['VIEW_URL'] = '';
                }
                $entry_buildup->attach(static_evaluate_tempcode(do_template('CATALOGUE_' . $tpl_set . '_TAB_ENTRY', $tab_entry_map, NULL, false, 'CATALOGUE_DEFAULT_TAB_ENTRY')));
            }
            if (!is_null($start) && $i >= $start + $max) {
                break;
            }
        }
        if (!$entry_buildup->is_empty()) {
            $head = new ocp_tempcode();
            $field_count = 0;
            foreach ($fields as $i => $field) {
                if (($field['cf_put_in_category'] == 1 && $view_type == 'CATEGORY' || $field['cf_put_in_search'] == 1 && $view_type == 'SEARCH') && $field['cf_visible'] == 1) {
                    if ($field['cf_searchable'] == 1) {
                        $sort_url_asc = get_self_url(false, false, array('order' => strval($field['id']) . ' ASC'), true);
                        $sort_url_desc = get_self_url(false, false, array('order' => strval($field['id']) . ' DESC'), true);
                        $sort_asc_selected = $order_by == strval($field['id']) && $direction == 'ASC';
                        $sort_desc_selected = $order_by == strval($field['id']) && $direction == 'DESC';
                    } else {
                        $sort_url_asc = '';
                        $sort_url_desc = '';
                        $sort_asc_selected = false;
                        $sort_desc_selected = false;
                    }
                    $head->attach(do_template('CATALOGUE_' . $tpl_set . '_TAB_FIELD_HEAD', array('SORT_ASC_SELECTED' => $sort_asc_selected, 'SORT_DESC_SELECTED' => $sort_desc_selected, 'SORT_URL_ASC' => $sort_url_asc, 'SORT_URL_DESC' => $sort_url_desc, 'CATALOGUE' => $catalogue_name, 'FIELDID' => strval($i), '_FIELDID' => strval($field['id']), 'FIELD' => get_translated_text($field['cf_name']), 'FIELDTYPE' => $field['cf_type']), NULL, false, 'CATALOGUE_DEFAULT_TAB_FIELD_HEAD'));
                    $field_count++;
                }
            }
            $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_TAB_WRAP', array('CATALOGUE' => $catalogue_name, 'HEAD' => $head, 'CONTENT' => $entry_buildup, 'FIELD_COUNT' => strval($field_count)), NULL, false, 'CATALOGUE_DEFAULT_TAB_WRAP');
        }
    } elseif ($display_type == 0) {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($max) || $in_db_sorting || (is_null($start) || $i >= $start && $i < $start + $max)) {
                $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_ENTRY_EMBED', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED'));
            }
        }
    } else {
        for ($i = 0; $i < $num_entries; $i++) {
            if (!array_key_exists($i, $entries)) {
                break;
            }
            $entry = $entries[$i];
            if (is_null($start) || $in_db_sorting || $i >= $start && $i < $start + $max) {
                $entry_buildup->attach(do_template('CATALOGUE_' . $tpl_set . '_LINE', $entry['map'] + (array_key_exists($i, $extra_map) ? $extra_map[$i] : array()), NULL, false, 'CATALOGUE_DEFAULT_LINE'));
            }
        }
        if (!$entry_buildup->is_empty()) {
            $entry_buildup = do_template('CATALOGUE_' . $tpl_set . '_LINE_WRAP', $entry['map'] + array('CATALOGUE' => $catalogue_name, 'CONTENT' => $entry_buildup), NULL, false, 'CATALOGUE_DEFAULT_LINE_WRAP');
        }
    }
    return array($entry_buildup, $sorting, $entries, $num_entries);
}
Example #7
0
 /**
  * Get tempcode for adding/editing form.
  *
  * @param  ?AUTO_LINK	The ID of the award (NULL: not added yet)
  * @param  SHORT_TEXT	The title
  * @param  LONG_TEXT		The description
  * @param  integer		How many points are given to the awardee
  * @param  ID_TEXT		The content type the award type is for
  * @param  BINARY			Whether to not show the awardee when displaying this award
  * @param  integer		The approximate time in hours between awards (e.g. 168 for a week)
  * @return tempcode		The input fields
  */
 function get_form_fields($id = NULL, $title = '', $description = '', $points = 0, $content_type = 'download', $hide_awardee = 0, $update_time_hours = 168)
 {
     $fields = new ocp_tempcode();
     $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_TITLE'), 'title', $title, true));
     $fields->attach(form_input_text_comcode(do_lang_tempcode('DESCRIPTION'), do_lang_tempcode('DESCRIPTION_DESCRIPTION'), 'description', $description, true));
     if (addon_installed('points')) {
         $fields->attach(form_input_integer(do_lang_tempcode('POINTS'), do_lang_tempcode('DESCRIPTION_AWARD_POINTS'), 'points', $points, true));
     }
     $list = new ocp_tempcode();
     $_hooks = array();
     $hooks = find_all_hooks('systems', 'awards');
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/systems/awards/' . $hook);
         $hook_object = object_factory('Hook_awards_' . $hook, true);
         if (is_null($hook_object)) {
             continue;
         }
         $hook_info = $hook_object->info();
         if (!is_null($hook_info)) {
             $_hooks[$hook] = $hook_info['title']->evaluate();
         }
     }
     asort($_hooks);
     foreach ($_hooks as $hook => $hook_title) {
         $list->attach(form_input_list_entry($hook, $hook == $content_type, protect_from_escaping($hook_title)));
     }
     if ($list->is_empty()) {
         inform_exit(do_lang_tempcode('NO_CATEGORIES'));
     }
     $fields->attach(form_input_list(do_lang_tempcode('CONTENT_TYPE'), do_lang_tempcode('DESCRIPTION_CONTENT_TYPE'), 'content_type', $list));
     $fields->attach(form_input_tick(do_lang_tempcode('HIDE_AWARDEE'), do_lang_tempcode('DESCRIPTION_HIDE_AWARDEE'), 'hide_awardee', $hide_awardee == 1));
     $fields->attach(form_input_integer(do_lang_tempcode('AWARD_UPDATE_TIME_HOURS'), do_lang_tempcode('DESCRIPTION_AWARD_UPDATE_TIME_HOURS'), 'update_time_hours', $update_time_hours, true));
     // Permissions
     $fields->attach($this->get_permission_fields(is_null($id) ? NULL : strval($id), do_lang_tempcode('AWARD_PERMISSION_HELP'), false, do_lang_tempcode('GIVE_AWARD')));
     return $fields;
 }
Example #8
0
 /**
  * The UI to choose a zone to edit.
  *
  * @param  string			The follow-on type
  * @param  ?tempcode		The title to use (NULL: the EDIT_ZONE title)
  * @return tempcode		The UI
  */
 function edit_zone($type = '_edit', $title = NULL)
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/zones';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_structure';
     if (is_null($title)) {
         $title = get_page_title('EDIT_ZONE');
     }
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 50);
     $_zones = find_all_zones(false, true, false, $start, $max);
     $url_map = array('page' => '_SELF', 'type' => $type);
     if ($type == '_editor') {
         $url_map['wide'] = 1;
     }
     require_code('templates_results_table');
     $current_ordering = 'name ASC';
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array();
     $header_row = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('TITLE'), do_lang_tempcode('DEFAULT_PAGE'), do_lang_tempcode('THEME'), do_lang_tempcode('DISPLAYED_IN_MENU'), do_lang_tempcode('WIDE'), do_lang_tempcode('REQUIRE_SESSION'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $max_rows = $GLOBALS['SITE_DB']->query_value('zones', 'COUNT(*)');
     foreach ($_zones as $_zone_details) {
         list($zone_name, $zone_title, $zone_show_in_menu, $zone_default_page, $remaining_row) = $_zone_details;
         $edit_link = build_url($url_map + array('id' => $zone_name), '_SELF');
         $fields->attach(results_entry(array(hyperlink(build_url(array('page' => ''), $zone_name), $zone_name == '' ? do_lang_tempcode('NA_EM') : make_string_tempcode(escape_html($zone_name))), $zone_title, $zone_default_page, $remaining_row['zone_theme'] == '-1' ? do_lang_tempcode('NA_EM') : hyperlink(build_url(array('page' => 'admin_themes'), 'adminzone'), escape_html($remaining_row['zone_theme'])), $zone_show_in_menu == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $remaining_row['zone_wide'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $remaining_row['zone_require_session'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, $zone_name))), true));
     }
     $table = results_table(do_lang('ZONES'), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order);
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('ZONES'))));
     breadcrumb_set_self(do_lang_tempcode('CHOOSE'));
     $text = do_lang_tempcode('CHOOSE_EDIT_LIST');
     return do_template('TABLE_TABLE_SCREEN', array('TITLE' => $title, 'TEXT' => $text, 'TABLE' => $table, 'SUBMIT_NAME' => NULL, 'POST_URL' => get_self_url()));
 }
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'tag_tag ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('tag_tag' => do_lang_tempcode('COMCODE_TAG'), 'tag_title' => do_lang_tempcode('TITLE'), 'tag_dangerous_tag' => do_lang_tempcode('DANGEROUS_TAG'), 'tag_block_tag' => do_lang_tempcode('BLOCK_TAG'), 'tag_textual_tag' => do_lang_tempcode('TEXTUAL_TAG'), 'tag_enabled' => do_lang_tempcode('ENABLED'));
     $header_row = results_field_title(array(do_lang_tempcode('COMCODE_TAG'), do_lang_tempcode('TITLE'), do_lang_tempcode('DANGEROUS_TAG'), do_lang_tempcode('BLOCK_TAG'), do_lang_tempcode('TEXTUAL_TAG'), do_lang_tempcode('ENABLED'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['tag_tag']), '_SELF');
         $fields->attach(results_entry(array($row['tag_tag'], get_translated_text($row['tag_title']), $row['tag_dangerous_tag'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $row['tag_block_tag'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $row['tag_textual_tag'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $row['tag_enabled'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . $row['tag_tag']))), true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false);
 }
Example #10
0
 /**
  * Standard modular render function for profile tab hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return array			A triple: The tab title, the tab contents, the suggested tab order
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     $title = do_lang_tempcode('PROFILE');
     $order = 10;
     $photo_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_url');
     if ($photo_url != '' && addon_installed('ocf_member_photos') && has_specific_permission($member_id_viewing, 'view_member_photos')) {
         require_code('images');
         $photo_thumb_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_thumb_url');
         $photo_thumb_url = ensure_thumbnail($photo_url, $photo_thumb_url, strpos($photo_url, 'uploads/photos') !== false ? 'photos' : 'ocf_photos', 'f_members', $member_id_of, 'm_photo_thumb_url');
         if (url_is_local($photo_url)) {
             $photo_url = get_complex_base_url($photo_url) . '/' . $photo_url;
         }
         if (url_is_local($photo_thumb_url)) {
             $photo_thumb_url = get_complex_base_url($photo_thumb_url) . '/' . $photo_thumb_url;
         }
     } else {
         $photo_url = '';
         $photo_thumb_url = '';
     }
     $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id_of);
     $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
     // Things staff can do with this user
     $modules = array();
     if (has_specific_permission($member_id_viewing, 'warn_members') && has_actual_page_access($member_id_viewing, 'warnings') && addon_installed('ocf_warnings')) {
         $redir_url = get_self_url(true);
         $modules[] = array('usage', do_lang_tempcode('WARN_MEMBER'), build_url(array('page' => 'warnings', 'type' => 'ad', 'id' => $member_id_of, 'redirect' => $redir_url), get_module_zone('warnings')));
         $modules[] = array('usage', do_lang_tempcode('PUNITIVE_HISTORY'), build_url(array('page' => 'warnings', 'type' => 'history', 'id' => $member_id_of), get_module_zone('warnings')));
     }
     if (has_specific_permission($member_id_viewing, 'view_content_history') && has_actual_page_access($member_id_viewing, 'admin_ocf_history')) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('usage', do_lang_tempcode('POST_HISTORY'), build_url(array('page' => 'admin_ocf_history', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_lookup')) {
         require_lang('submitban');
         $modules[] = array('usage', do_lang_tempcode('INVESTIGATE_USER'), build_url(array('page' => 'admin_lookup', 'param' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_security')) {
         require_lang('security');
         $modules[] = array('usage', do_lang_tempcode('SECURITY_LOGGING'), build_url(array('page' => 'admin_security', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (addon_installed('actionlog')) {
         if (has_actual_page_access($member_id_viewing, 'admin_actionlog')) {
             require_lang('submitban');
             $modules[] = array('usage', do_lang_tempcode('VIEW_ACTION_LOGS'), build_url(array('page' => 'admin_actionlog', 'type' => 'list', 'id' => $member_id_of), 'adminzone'));
         }
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('ocf_forum') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH_POSTS'), build_url(array('page' => 'search', 'type' => 'results', 'id' => 'ocf_posts', 'author' => $username, 'sort' => 'add_date', 'direction' => 'DESC', 'content' => ''), get_module_zone('search')), 'search');
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH'), build_url(array('page' => 'search', 'type' => 'misc', 'author' => $username), get_module_zone('search')), 'search');
     }
     if (addon_installed('authors')) {
         $author = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT author FROM ' . get_table_prefix() . 'authors WHERE (forum_handle=' . strval($member_id_viewing) . ') OR (forum_handle IS NULL AND ' . db_string_equal_to('author', $username) . ')');
         if (has_actual_page_access($member_id_viewing, 'authors') && !is_null($author)) {
             $modules[] = array('content', do_lang_tempcode('AUTHOR'), build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $author), get_module_zone('authors')), 'me');
         }
     }
     require_code('ocf_members2');
     if (!is_guest() && ocf_may_whisper($member_id_of) && has_actual_page_access($member_id_viewing, 'topics') && ocf_may_make_personal_topic() && $member_id_viewing != $member_id_of) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('contact', do_lang_tempcode('ADD_PERSONAL_TOPIC'), build_url(array('page' => 'topics', 'type' => 'new_pt', 'id' => $member_id_of), get_module_zone('topics')), 'reply');
     }
     $extra_sections = array();
     $info_details = array();
     $hooks = find_all_hooks('modules', 'members');
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/modules/members/' . filter_naughty_harsh($hook));
         $object = object_factory('Hook_members_' . filter_naughty_harsh($hook), true);
         if (is_null($object)) {
             continue;
         }
         if (method_exists($object, 'run')) {
             $hook_result = $object->run($member_id_of);
             $modules = array_merge($modules, $hook_result);
         }
         if (method_exists($object, 'get_info_details')) {
             $hook_result = $object->get_info_details($member_id_of);
             $info_details = array_merge($info_details, $hook_result);
         }
         if (method_exists($object, 'get_sections')) {
             $hook_result = $object->get_sections($member_id_of);
             $extra_sections = array_merge($extra_sections, $hook_result);
         }
     }
     if (addon_installed('ocf_contactmember')) {
         if (($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_allow_emails') == 1 || get_option('allow_email_disable') == '0') && $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address') != '' && !is_guest($member_id_of) && has_actual_page_access($member_id_viewing, 'contactmember') && $member_id_viewing != $member_id_of) {
             $redirect = get_self_url(true);
             $modules[] = array('contact', do_lang_tempcode('_EMAIL_MEMBER'), build_url(array('page' => 'contactmember', 'redirect' => $redirect, 'id' => $member_id_of), get_module_zone('contactmember')), 'reply');
         }
     }
     require_lang('menus');
     $sections = array('contact' => do_lang_tempcode('CONTACT'), 'profile' => do_lang_tempcode('EDIT_PROFILE'), 'views' => do_lang_tempcode('ACCOUNT'), 'usage' => do_lang_tempcode('USAGE'), 'content' => do_lang_tempcode('CONTENT'));
     $actions = array();
     global $M_SORT_KEY;
     $M_SORT_KEY = mixed();
     $M_SORT_KEY = 1;
     @uasort($modules, 'multi_sort');
     /* @ is to stop PHP bug warning about altered array contents when Tempcode copies are evaluated internally */
     foreach ($sections as $section_code => $section_title) {
         $links = new ocp_tempcode();
         foreach ($modules as $module) {
             if (count($module) == 3) {
                 list($_section_code, $lang, $url) = $module;
                 $rel = NULL;
             } else {
                 list($_section_code, $lang, $url, $rel) = $module;
             }
             if ($section_code == $_section_code) {
                 $links->attach(do_template('OCF_MEMBER_ACTION', array('_GUID' => '67b2a640a368c6f53f1b1fa10f922fd0', 'ID' => strval($member_id_of), 'URL' => $url, 'LANG' => $lang, 'REL' => $rel)));
             }
         }
         $actions[$section_code] = $links;
     }
     // Custom fields
     $_custom_fields = ocf_get_all_custom_fields_match_member($member_id_of, $member_id_viewing != $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL, $member_id_viewing == $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL);
     $custom_fields = array();
     require_code('encryption');
     $value = mixed();
     foreach ($_custom_fields as $name => $_value) {
         $value = $_value['RAW'];
         $rendered_value = $_value['RENDERED'];
         $encrypted_value = '';
         if (is_data_encrypted($value)) {
             $encrypted_value = remove_magic_encryption_marker($value);
         } elseif (is_integer($value)) {
             $value = strval($value);
         } elseif (is_float($value)) {
             $value = float_to_raw_string($value);
         }
         if (!is_object($value) && $value != '' || is_object($value) && !$value->is_empty()) {
             $custom_fields[] = array('NAME' => $name, 'RAW_VALUE' => $value, 'VALUE' => $rendered_value, 'ENCRYPTED_VALUE' => $encrypted_value);
             if ($name == do_lang('KEYWORDS')) {
                 $GLOBALS['SEO_KEYWORDS'] = is_object($value) ? $value->evaluate() : $value;
             }
             if ($name == do_lang('DESCRIPTION')) {
                 $GLOBALS['SEO_DESCRIPTION'] = is_object($value) ? $value->evaluate() : $value;
             }
         }
     }
     // Birthday
     $dob = '';
     if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_reveal_age') == 1) {
         $day = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_day');
         $month = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_month');
         $year = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_year');
         if (!is_null($day)) {
             if (@strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) != '1963') {
                 $dob = strval($year) . '-' . str_pad(strval($month), 2, '0', STR_PAD_LEFT) . '-' . str_pad(strval($day), 2, '0', STR_PAD_LEFT);
             } else {
                 $dob = get_timezoned_date(mktime(12, 0, 0, $month, $day, $year), false, true, true);
             }
         }
     }
     // Find forum with most posts
     $forums = $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0');
     $best_yet_forum = 0;
     // Initialise to integer type
     $best_yet_forum = NULL;
     $most_active_forum = NULL;
     $_best_yet_forum = $GLOBALS['FORUM_DB']->query_select('f_posts', array('COUNT(*) as cnt', 'p_cache_forum_id'), array('p_poster' => $member_id_of), 'GROUP BY p_cache_forum_id');
     $_best_yet_forum = collapse_2d_complexity('p_cache_forum_id', 'cnt', $_best_yet_forum);
     foreach ($forums as $forum) {
         if (array_key_exists($forum['id'], $_best_yet_forum) && (is_null($best_yet_forum) || $_best_yet_forum[$forum['id']] > $best_yet_forum)) {
             $most_active_forum = has_category_access($member_id_viewing, 'forums', strval($forum['id'])) ? protect_from_escaping(escape_html($forum['f_name'])) : do_lang_tempcode('PROTECTED_FORUM');
             $best_yet_forum = $_best_yet_forum[$forum['id']];
         }
     }
     $post_count = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_cache_num_posts');
     $best_post_fraction = $post_count == 0 ? do_lang_tempcode('NA_EM') : make_string_tempcode(integer_format(100 * $best_yet_forum / $post_count));
     $most_active_forum = is_null($best_yet_forum) ? new ocp_tempcode() : do_lang_tempcode('_MOST_ACTIVE_FORUM', $most_active_forum, make_string_tempcode(integer_format($best_yet_forum)), array($best_post_fraction));
     $time_for_them_raw = tz_time(time(), get_users_timezone($member_id_of));
     $time_for_them = get_timezoned_time(time(), true, $member_id_of);
     $banned = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_is_perm_banned') == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
     $last_submit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_submit_time');
     $submit_days_ago = intval(floor(floatval(time() - $last_submit_time) / 60.0 / 60.0 / 24.0));
     require_code('ocf_groups');
     $primary_group_id = ocf_get_member_primary_group($member_id_of);
     $primary_group = ocf_get_group_link($primary_group_id);
     $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_signature'), $GLOBALS['FORUM_DB']);
     $last_visit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_visit_time');
     if (member_is_online($member_id_of)) {
         $online_now = do_lang_tempcode('YES');
         $_online_now = true;
     } else {
         $_online_now = false;
         $minutes_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0));
         $hours_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0));
         $days_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0));
         $months_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0 / 31.0));
         if ($minutes_ago < 180) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MINUTES', integer_format($minutes_ago));
         } elseif ($hours_ago < 72) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_HOURS', integer_format($hours_ago));
         } elseif ($days_ago < 93) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_DAYS', integer_format($days_ago));
         } else {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MONTHS', integer_format($months_ago));
         }
     }
     $join_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_join_time');
     $days_joined = intval(round((time() - $join_time) / 60 / 60 / 24));
     $total_posts = $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)');
     $join_date = $join_time == 0 ? '' : get_timezoned_date($join_time, false);
     $count_posts = do_lang_tempcode('_COUNT_POSTS', integer_format($post_count), float_format(floatval($post_count) / floatval($days_joined == 0 ? 1 : $days_joined)), array(float_format(floatval(100 * $post_count) / floatval($total_posts == 0 ? 1 : $total_posts))));
     $a = $avatar_url == '' ? 0 : ocf_get_member_best_group_property($member_id_of, 'max_avatar_width');
     $b = $photo_thumb_url == '' ? 0 : intval(get_option('thumb_width'));
     $right_margin = max($a, $b) == 0 ? 'auto' : strval(max($a, $b) + 6) . 'px';
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MEMBERS'))));
     if (has_specific_permission($member_id_viewing, 'see_ip')) {
         $ip_address = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_ip_address');
     } else {
         $ip_address = '';
     }
     $secondary_groups = ocf_get_members_groups($member_id_of, true);
     unset($secondary_groups[$primary_group_id]);
     if (count($secondary_groups) > 0) {
         $_secondary_groups = array();
         $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, array_keys($secondary_groups), $member_id_of);
         foreach (array_keys($secondary_groups) as $key) {
             $_secondary_groups[$key] = $all_groups[$key];
         }
         $secondary_groups = $_secondary_groups;
     }
     if (addon_installed('points')) {
         require_code('points');
         $count_points = integer_format(total_points($member_id_of));
     } else {
         $count_points = '';
     }
     $user_agent = NULL;
     $operating_system = NULL;
     if (has_specific_permission($member_id_viewing, 'show_user_browsing') && addon_installed('stats')) {
         $last_stats = $GLOBALS['SITE_DB']->query_select('stats', array('browser', 'operating_system'), array('the_user' => $member_id_of), 'ORDER BY date_and_time DESC', 1);
         if (array_key_exists(0, $last_stats)) {
             $user_agent = $last_stats[0]['browser'];
             $operating_system = $last_stats[0]['operating_system'];
         }
     }
     /*if ((get_option('allow_member_integration')!='off') && (get_option('allow_member_integration')!='hidden'))
     		{
     			$remote=$GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of,'m_password_compat_scheme')=='remote';
     		} else */
     $remote = NULL;
     $_on_probation = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_on_probation_until');
     if (is_null($_on_probation) || $_on_probation <= time()) {
         $on_probation = NULL;
     } else {
         $on_probation = strval($_on_probation);
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $join_time), 'creator' => $username, 'publisher' => '', 'modified' => '', 'type' => 'Member', 'title' => '', 'identifier' => '_SEARCH:members:view:' . strval($member_id_of), 'description' => '', 'image' => $avatar_url == '' && has_specific_permission($member_id_viewing, 'view_member_photos') ? $photo_url : $avatar_url);
     // Look up member's clubs
     $clubs = array();
     if (addon_installed('ocf_clubs')) {
         $club_ids = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id_of, true);
         $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1), '', 200));
         if (count($club_rows) == 200) {
             $club_rows = NULL;
         }
         foreach ($club_ids as $club_id) {
             if (is_null($club_rows)) {
                 $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1, 'id' => $club_id), '', 200));
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
                 $club_rows = NULL;
             } else {
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
             }
             $club_name = get_translated_text($club_row['g_name'], $GLOBALS['FORUM_DB']);
             $club_forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.f_description', 'f.id', array('text_original' => do_lang('FORUM_FOR_CLUB', $club_name)));
             $clubs[] = array('CLUB_NAME' => $club_name, 'CLUB_ID' => strval($club_row['id']), 'CLUB_FORUM' => is_null($club_forum) ? '' : strval($club_forum));
         }
     }
     $content = do_template('OCF_MEMBER_PROFILE_ABOUT', array('_GUID' => 'fodfjdsfjsdljfdls', 'CLUBS' => $clubs, 'REMOTE' => $remote, 'RIGHT_MARGIN' => $right_margin, 'AVATAR_WIDTH' => strval($a) . 'px', 'PHOTO_WIDTH' => strval($b) . 'px', 'MOST_ACTIVE_FORUM' => $most_active_forum, 'TIME_FOR_THEM' => $time_for_them, 'TIME_FOR_THEM_RAW' => strval($time_for_them_raw), 'SUBMIT_DAYS_AGO' => integer_format($submit_days_ago), 'SUBMIT_TIME_RAW' => strval($last_submit_time), 'LAST_VISIT_TIME_RAW' => strval($last_visit_time), 'ONLINE_NOW' => $online_now, '_ONLINE_NOW' => $_online_now, 'BANNED' => $banned, 'USER_AGENT' => $user_agent, 'OPERATING_SYSTEM' => $operating_system, 'DOB' => $dob, 'IP_ADDRESS' => $ip_address, 'COUNT_POSTS' => $count_posts, 'COUNT_POINTS' => $count_points, 'PRIMARY_GROUP' => $primary_group, 'PRIMARY_GROUP_ID' => strval($primary_group_id), 'PHOTO_URL' => $photo_url, 'PHOTO_THUMB_URL' => $photo_thumb_url, 'EMAIL_ADDRESS' => $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address'), 'AVATAR_URL' => $avatar_url, 'SIGNATURE' => $signature, 'JOIN_DATE' => $join_date, 'JOIN_DATE_RAW' => strval($join_time), 'CUSTOM_FIELDS' => $custom_fields, 'ACTIONS_contact' => $actions['contact'], 'ACTIONS_profile' => $actions['profile'], 'ACTIONS_views' => $actions['views'], 'ACTIONS_usage' => $actions['usage'], 'ACTIONS_content' => $actions['content'], 'USERNAME' => $username, 'MEMBER_ID' => strval($member_id_of), 'SECONDARY_GROUPS' => $secondary_groups, 'VIEW_PROFILES' => $member_id_viewing == $member_id_of || has_specific_permission($member_id_viewing, 'view_profiles'), 'ON_PROBATION' => $on_probation, 'EXTRA_INFO_DETAILS' => $info_details, 'EXTRA_SECTIONS' => $extra_sections));
     return array($title, $content, $order);
 }
Example #11
0
 /**
  * Convert an array to tempcode for display.
  *
  * @param  array				Array to display
  * @return tempcode			Tempcode for array
  */
 function _array_to_html($array)
 {
     //Convert an array to an HTML format
     $output = new ocp_tempcode();
     $key = mixed();
     foreach ($array as $key => $value) {
         if (is_array($value)) {
             $value = protect_from_escaping($this->_array_to_html($value));
         }
         $output->attach(do_template('OCCLE_ARRAY_ELEMENT', array('_GUID' => '18c9700c05fbe9c8b45f454376deda05', 'KEY' => is_string($key) ? $key : strval($key), 'VALUE' => is_string($value) ? $value : (is_null($value) ? 'NULL' : (is_object($value) ? $value : strval($value))))));
     }
     return do_template('OCCLE_ARRAY', array('_GUID' => 'ab75cdb77fa797d2e42185b51e34d857', 'ELEMENTS' => $output));
 }
Example #12
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (has_no_forum()) {
         return new ocp_tempcode();
     }
     require_css('news');
     // Read in variables
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     $limit = array_key_exists('limit', $map) ? intval($map['limit']) : 6;
     $hot = array_key_exists('hot', $map) ? intval($map['hot']) : 0;
     $date_key = array_key_exists('date_key', $map) ? $map['date_key'] : 'lasttime';
     if ($date_key != 'lasttime' && $date_key != 'firsttime') {
         $date_key = 'firsttime';
     }
     $username_key = array_key_exists('username_key', $map) ? $map['username_key'] : 'firstusername';
     if ($username_key != 'lastusername' && $username_key != 'firstusername') {
         $username_key = 'firstusername';
     }
     $memberid_key = $username_key == 'firstusername' ? 'firstmemberid' : 'lastmemberid';
     // Work out exactly what forums we're reading
     $forum_ids = array();
     if (get_forum_type() == 'ocf' && (strpos($forum_name, ',') !== false || strpos($forum_name, '*') !== false || preg_match('#\\d[-\\*\\+]#', $forum_name) != 0 || is_numeric($forum_name))) {
         require_code('ocfiltering');
         $forum_names = ocfilter_to_idlist_using_db($forum_name, 'id', 'f_forums', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
     } else {
         $forum_names = explode(',', $forum_name);
     }
     foreach ($forum_names as $forum_name) {
         if (!is_string($forum_name)) {
             $forum_name = strval($forum_name);
         }
         $forum_name = trim($forum_name);
         if ($forum_name == '<announce>') {
             $forum_id = NULL;
         } else {
             $forum_id = is_numeric($forum_name) ? intval($forum_name) : $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
         }
         if (get_forum_type() == 'ocf' && array_key_exists('check', $map) && $map['check'] == '1') {
             if (!has_category_access(get_member(), 'forums', strval($forum_id))) {
                 continue;
             }
         }
         if (!is_null($forum_id)) {
             $forum_ids[$forum_id] = $forum_name;
         }
     }
     // Block title
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     if (is_numeric($forum_name) && get_forum_type() == 'ocf') {
         $forum_name = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_name', array('id' => intval($forum_name)));
         if (is_null($forum_name)) {
             return paragraph(do_lang_tempcode('MISSING_RESOURCE'));
         }
     }
     $_title = do_lang_tempcode('ACTIVE_TOPICS_IN', escape_html($forum_name));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     // Add topic link
     if (count($forum_names) == 1 && get_forum_type() == 'ocf' && !is_null($forum_id)) {
         $submit_url = build_url(array('page' => 'topics', 'type' => 'new_topic', 'id' => $forum_id), get_module_zone('topics'));
         $add_name = do_lang_tempcode('ADD_TOPIC');
     } else {
         $submit_url = new ocp_tempcode();
         $add_name = new ocp_tempcode();
     }
     // Show all topics
     if (get_forum_type() == 'ocf') {
         $forum_names_map = collapse_2d_complexity('id', 'f_name', $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0'));
     } else {
         $forum_names_map = NULL;
     }
     if (!has_no_forum()) {
         $max_rows = 0;
         $topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key, $hot == 1);
         $out = new ocp_tempcode();
         if (!is_null($topics)) {
             global $M_SORT_KEY;
             $M_SORT_KEY = $date_key;
             usort($topics, 'multi_sort');
             $topics = array_reverse($topics, false);
             if (count($topics) < $limit && $hot == 1) {
                 $more_topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key);
                 if (is_null($more_topics)) {
                     $more_topics = array();
                 }
                 $topics = array_merge($topics, $more_topics);
             }
             $done = 0;
             $seen = array();
             foreach ($topics as $topic) {
                 if (array_key_exists($topic['id'], $seen)) {
                     continue;
                 }
                 $seen[$topic['id']] = 1;
                 $topic_url = $GLOBALS['FORUM_DRIVER']->topic_url($topic['id'], $forum_name);
                 $topic_url_unread = mixed();
                 if (get_forum_type() == 'ocf') {
                     $topic_url_unread = build_url(array('page' => 'topicview', 'id' => $topic['id'], 'type' => 'first_unread'), get_module_zone('topicview'), NULL, false, false, false, 'first_unread');
                 }
                 $title = escape_html($topic['title']);
                 $date = get_timezoned_date($topic[$date_key]);
                 $username = $topic[$username_key];
                 $member_id = array_key_exists($memberid_key, $topic) ? $topic[$memberid_key] : NULL;
                 if (!is_null($forum_names_map) && !array_key_exists($topic['forum_id'], $forum_names_map)) {
                     continue;
                 }
                 // Maybe Private Topic, slipped in via reference to a missing forum
                 $forum_name = is_null($forum_names_map) ? NULL : $forum_names_map[$topic['forum_id']];
                 $out->attach(do_template('BLOCK_MAIN_FORUM_TOPICS_TOPIC', array('_GUID' => 'ae4e351b3fa5422bf8ecdfb7e49076d1', 'POST' => $topic['firstpost'], 'FORUM_ID' => is_null($forum_names_map) ? NULL : strval($topic['forum_id']), 'FORUM_NAME' => $forum_name, 'TOPIC_LINK' => $topic_url, 'TOPIC_LINK_UNREAD' => $topic_url_unread, 'TITLE' => $title, 'DATE' => $date, 'DATE_RAW' => strval($topic[$date_key]), 'USERNAME' => $username, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'NUM_POSTS' => integer_format($topic['num']))));
                 $done++;
                 if ($done == $limit) {
                     break;
                 }
             }
         }
         if ($out->is_empty()) {
             return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'c76ab018a0746c2875c6cf69c92a01fb', 'HIGH' => false, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($hot == 1 ? 'NO_TOPICS_HOT' : 'NO_TOPICS'), 'ADD_NAME' => $add_name, 'SUBMIT_URL' => $submit_url));
         }
         return do_template('BLOCK_MAIN_FORUM_TOPICS', array('_GUID' => '368b80c49a335ad035b00510681d5008', 'TITLE' => $_title, 'CONTENT' => $out, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'SUBMIT_URL' => $submit_url));
     } else {
         return new ocp_tempcode();
     }
 }
Example #13
0
 /**
  * The UI to view a staff member.
  *
  * @return tempcode		The UI
  */
 function do_staff_member()
 {
     require_code('obfuscate');
     $username = get_param('id');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('STAFF_TITLE', escape_html(get_site_name())))));
     $row_staff = $GLOBALS['FORUM_DRIVER']->pget_row($username);
     if (is_null($row_staff)) {
         warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
     }
     $id = $GLOBALS['FORUM_DRIVER']->pname_id($row_staff);
     $title = get_page_title('_STAFF', true, array(escape_html($username)));
     $_real_name = get_ocp_cpf('fullname', $id);
     if ($_real_name == '') {
         $real_name = do_lang_tempcode('_UNKNOWN');
         // Null should not happen, but sometimes things corrupt
     } else {
         $real_name = protect_from_escaping(escape_html($_real_name));
     }
     $_role = get_ocp_cpf('role', $id);
     if ($_role == '') {
         $role = do_lang_tempcode('_UNKNOWN');
         // Null should not happen, but sometimes things corrupt
     } else {
         require_code('comcode_text');
         $role = make_string_tempcode(apply_emoticons($_role));
     }
     $email_address = obfuscate_email_address($GLOBALS['FORUM_DRIVER']->pname_email($row_staff));
     $name = $GLOBALS['FORUM_DRIVER']->pname_name($row_staff);
     $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($id, false, true);
     $all_link = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF');
     return do_template('STAFF_SCREEN', array('_GUID' => 'fd149466f16722fcbcef0fba5685a895', 'TITLE' => $title, 'REAL_NAME' => $real_name, 'ROLE' => $role, 'ADDRESS' => $email_address, 'NAME' => $name, 'MEMBER_ID' => strval($id), 'PROFILE_URL' => $profile_url, 'ALL_LINK' => $all_link));
 }
Example #14
0
 /**
  * The UI to absorb usergroup permissions.
  *
  * @return tempcode		The UI
  */
 function absorb()
 {
     require_lang('security');
     $title = get_page_title('ABSORB_PERMISSIONS');
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/privileges';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_permissions';
     $groups_without = array();
     $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true);
     $list1 = new ocp_tempcode();
     $list2 = new ocp_tempcode();
     $admin_groups = $GLOBALS['FORUM_DRIVER']->get_super_admin_groups();
     $moderator_groups = $GLOBALS['FORUM_DRIVER']->get_moderator_groups();
     foreach ($all_groups as $id => $name) {
         if (in_array($id, $admin_groups)) {
             continue;
         }
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('gsp', 'group_id', array('group_id' => $id));
         if (is_null($test)) {
             $groups_without[$id] = $name;
         }
         $list1->attach(form_input_list_entry($id, is_null($test), $name));
         $list2->attach(form_input_list_entry($id, !is_null($test) && !in_array($id, $moderator_groups), $name));
     }
     $__groups_without = escape_html(implode(', ', $groups_without));
     if ($__groups_without == '') {
         $_groups_without = do_lang_tempcode('NONE_EM');
     } else {
         $_groups_without = protect_from_escaping($__groups_without);
     }
     $text = do_lang_tempcode('USERGROUPS_WITH_NO_PERMISSIONS', $_groups_without);
     $submit_name = do_lang_tempcode('ABSORB_PERMISSIONS');
     $post_url = build_url(array('page' => '_SELF', 'type' => '_absorb'), '_SELF');
     require_code('form_templates');
     $fields = new ocp_tempcode();
     $fields->attach(form_input_list(do_lang_tempcode('FROM'), do_lang_tempcode('PERMISSIONS_FROM'), 'from', $list1));
     $fields->attach(form_input_list(do_lang_tempcode('TO'), do_lang_tempcode('PERMISSIONS_TO'), 'to', $list2));
     return do_template('FORM_SCREEN', array('_GUID' => '9e20011006a26b240fc898279338875c', 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'HIDDEN' => '', 'FIELDS' => $fields, 'TEXT' => $text, 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
Example #15
0
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'title ASC', true);
     list($sortable, $sort_order) = array(substr($current_ordering, 0, strrpos($current_ordering, ' ')), substr($current_ordering, strrpos($current_ordering, ' ') + 1));
     $sortables = array('title' => do_lang_tempcode('TITLE'));
     if (db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $sortables['(SELECT COUNT(*) FROM ' . get_table_prefix() . 'newsletter n JOIN ' . get_table_prefix() . 'newsletter_subscribe s ON n.id=s.newsletter_id WHERE code_confirm=0)'] = do_lang_tempcode('COUNT_MEMBERS');
     }
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('TITLE'), do_lang_tempcode('COUNT_MEMBERS'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $num_readers = $GLOBALS['SITE_DB']->query_value('newsletter n JOIN ' . get_table_prefix() . 'newsletter_subscribe s ON n.id=s.newsletter_id', 'COUNT(*)', array('code_confirm' => 0));
         $fields->attach(results_entry(array(get_translated_text($row['title']), integer_format($num_readers), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id'])))), true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false);
 }
/**
 * Deletes a file (NOT a directory) on the open AFM connection.
 *
 * @param  PATH		The path to the file we are deleting.
 */
function afm_delete_file($basic_path)
{
    $path = _rescope_path($basic_path);
    $conn = _ftp_info();
    if ($conn !== false) {
        $success = @ftp_delete($conn, $path);
        if (!$success) {
            if (running_script('upgrader')) {
                echo @strval($php_errormsg);
                return;
            }
            warn_exit(protect_from_escaping(@strval($php_errormsg)));
        }
        clearstatcache();
        sync_file(get_custom_file_base() . '/' . $basic_path);
    } else {
        if (!file_exists($path)) {
            return;
        }
        @unlink($path) or intelligent_write_error($path);
        sync_file($path);
    }
}
Example #17
0
 /**
  * Choose product step.
  *
  * @param  tempcode	The page title.
  * @return tempcode	The result of execution.
  */
 function choose($title)
 {
     breadcrumb_set_self(do_lang_tempcode('PURCHASING'));
     /*if (is_guest())
     		{
     			$register=$GLOBALS['FORUM_DRIVER']->join_url();
     			if (is_object($register)) $register=$register->evaluate();
     			$_redirect=build_url(array('page'=>'_SELF','type'=>'misc'),'_SELF');
     			$redirect=$_redirect->evaluate();
     			$_login=build_url(array('page'=>'login','redirect'=>$redirect));
     			$login=$_login->evaluate();
     			return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_GUEST',array('_GUID'=>'accf475a1457f73d7280b14d774acc6e','TITLE'=>$title,'TEXT'=>do_lang_tempcode('PURCHASE_NOT_LOGGED_IN_2',escape_html($register),escape_html($login)))),$title,NULL);
     		}*/
     $url = build_url(array('page' => '_SELF', 'type' => 'message', 'id' => get_param_integer('id', -1)), '_SELF', NULL, true, true);
     require_code('form_templates');
     $list = new ocp_tempcode();
     $filter = get_param('filter', '');
     $products = find_all_products();
     foreach ($products as $product => $details) {
         if ($filter != '') {
             if (!is_string($product) || substr($product, 0, strlen($filter)) != $filter) {
                 continue;
             }
         }
         if (($details[0] == PRODUCT_PURCHASE_WIZARD || $details[0] == PRODUCT_SUBSCRIPTION || $details[0] == PRODUCT_CATALOGUE) && method_exists($details[count($details) - 1], 'is_available') && $details[count($details) - 1]->is_available($product, get_member())) {
             require_code('currency');
             $currency = get_option('currency');
             $price = currency_convert(floatval($details[1]), $currency, NULL, true);
             $description = $details[4];
             if (strpos($details[4], strpos($details[4], '.') === false ? preg_replace('#\\.00($|[^\\d])#', '', $price) : $price) === false) {
                 $description .= ' (' . $price . ')';
             }
             $list->attach(form_input_list_entry($product, false, protect_from_escaping($description)));
         }
     }
     if ($list->is_empty()) {
         inform_exit(do_lang_tempcode('NO_CATEGORIES'));
     }
     $fields = form_input_list(do_lang_tempcode('PRODUCT'), '', 'product', $list, NULL, true);
     return $this->wrap(do_template('PURCHASE_WIZARD_STAGE_CHOOSE', array('_GUID' => '47c22d48313ff50e6323f05a78342eae', 'FIELDS' => $fields, 'TITLE' => $title)), $title, $url, true);
 }
Example #18
0
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return ?array			A quartet: The choose table, Whether re-ordering is supported from this screen, Search URL, Archive URL (NULL: nothing to select).
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'date_and_time DESC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('title' => do_lang_tempcode('TITLE'), 'date_and_time' => do_lang_tempcode('_ADDED'), 'news_views' => do_lang_tempcode('_VIEWS'));
     if (addon_installed('unvalidated')) {
         $sortables['validated'] = do_lang_tempcode('VALIDATED');
     }
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $fh = array();
     $fh[] = do_lang_tempcode('TITLE');
     $fh[] = do_lang_tempcode('_ADDED');
     $fh[] = do_lang_tempcode('_VIEWS');
     if (addon_installed('unvalidated')) {
         $fh[] = do_lang_tempcode('VALIDATED');
     }
     $fh[] = do_lang_tempcode('ACTIONS');
     $header_row = results_field_title($fh, $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $only_owned = has_specific_permission(get_member(), 'edit_midrange_content', 'cms_news') ? NULL : get_member();
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering, is_null($only_owned) ? NULL : array('submitter' => $only_owned), false, ' JOIN ' . get_table_prefix() . 'news_categories c ON c.id=r.news_category AND nc_owner IS NOT NULL');
     if (count($rows) == 0) {
         return NULL;
     }
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $fr = array();
         $fr[] = protect_from_escaping(hyperlink(build_url(array('page' => 'news', 'type' => 'view', 'id' => $row['id']), get_module_zone('news')), get_translated_text($row['title']), false, true));
         $fr[] = get_timezoned_date($row['date_and_time']);
         $fr[] = integer_format($row['news_views']);
         if (addon_installed('unvalidated')) {
             $fr[] = $row['validated'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         }
         $fr[] = protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id'])));
         $fields->attach(results_entry($fr, true));
     }
     $search_url = build_url(array('page' => 'search', 'id' => 'news'), get_module_zone('search'));
     $archive_url = build_url(array('page' => 'news'), get_module_zone('news'));
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false, $search_url, $archive_url);
 }
Example #19
0
 /**
  * The UI to choose what configuration page to edit.
  *
  * @return tempcode		The UI
  */
 function config_choose()
 {
     $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/config';
     $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_adv_configuration';
     $title = get_page_title('CONFIGURATION');
     $rows = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'COUNT(*) AS cnt'), NULL, 'GROUP BY the_page ORDER BY the_page');
     $content = new ocp_tempcode();
     foreach ($rows as $myrow) {
         $url = build_url(array('page' => '_SELF', 'type' => 'category', 'id' => $myrow['the_page']), '_SELF');
         $_name = do_lang('CONFIG_CATEGORY_' . $myrow['the_page'], NULL, NULL, NULL, NULL, false);
         if (is_null($_name)) {
             continue;
         }
         $name = do_lang_tempcode('CONFIG_CATEGORY_' . $myrow['the_page']);
         //			if ($name->evaluate()=='') @exit($myrow['the_page']);
         $count = do_lang_tempcode('CATEGORY_SUBORDINATE_2', escape_html(integer_format($myrow['cnt'])));
         $content->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('_GUID' => '6ba2b09432d06e7502c71e7aac2d3527', 'COUNT' => $count, 'TITLE' => protect_from_escaping(do_lang('CONFIGURATION') . ': ' . $_name), 'URL' => $url, 'NAME' => $name, 'DESCRIPTION' => do_lang_tempcode('CONFIG_CATEGORY_DESCRIPTION__' . $myrow['the_page']))));
     }
     $content->attach(do_template('INDEX_SCREEN_FANCIER_ENTRY', array('COUNT' => NULL, 'TITLE' => protect_from_escaping(do_lang('CONFIGURATION') . ': ' . do_lang('BASE_CONFIGURATION')), 'URL' => get_base_url() . '/config_editor.php', 'NAME' => do_lang_tempcode('BASE_CONFIGURATION'), 'DESCRIPTION' => do_lang_tempcode('DOC_BASE_CONFIGURATION'))));
     return do_template('INDEX_SCREEN_FANCIER_SCREEN', array('_GUID' => 'c8fdb2b481625d58b0b228c897fda72f', 'PRE' => paragraph(do_lang_tempcode('CHOOSE_A_CONFIG_CATEGORY')), 'POST' => '', 'TITLE' => $title, 'CONTENT' => $content));
 }
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A quartet: The choose table, Whether re-ordering is supported from this screen, Search URL, Archive URL.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'c_title ASC', true);
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('c_title' => do_lang_tempcode('TITLE'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('TITLE'), do_lang_tempcode('EXPANDED_BY_DEFAULT'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $fields->attach(results_entry(array($row['c_title'], $row['c_expanded_by_default'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id'])))), true));
     }
     $search_url = NULL;
     $archive_url = NULL;
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false, $search_url, $archive_url);
 }
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'w_name ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('w_name' => do_lang_tempcode('NAME'), 'w_subject' => do_lang_tempcode('SUBJECT'), 'w_send_time' => do_lang_tempcode('SEND_TIME'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('SUBJECT'), do_lang_tempcode('SEND_TIME'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $fields->attach(results_entry(array($row['w_name'], get_translated_text($row['w_subject']), do_lang_tempcode('HOURS', escape_html(strval($row['w_send_time']))), protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id'])))), true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false);
 }
Example #22
0
/**
 * This is it - the start of rendering of a website page.
 * Take in all inputs, sends them to the correct functions to process, gathers up all the outputs, sticks them together and echoes them.
 */
function do_site()
{
    // More SEO redirection (monikers)
    // Does this URL arrangement support monikers?
    $url_id = get_param('id', NULL, true);
    if ($url_id !== NULL && url_monikers_enabled()) {
        $type = get_param('type', 'misc');
        $looking_for = '_SEARCH:' . get_page_name() . ':' . $type . ':_WILD';
        $hooks = find_all_hooks('systems', 'content_meta_aware');
        $ob_info = NULL;
        foreach (array_keys($hooks) as $hook) {
            require_code('hooks/systems/content_meta_aware/' . filter_naughty($hook));
            $ob = object_factory('Hook_content_meta_aware_' . $hook, true);
            if ($ob === NULL) {
                continue;
            }
            $ob_info = $ob->info();
            $ob_info['view_pagelink_pattern'] = preg_replace('#:[^:]*$#', ':_WILD', $ob_info['view_pagelink_pattern']);
            if ($ob_info['view_pagelink_pattern'] == $looking_for && $ob_info['support_url_monikers']) {
                if (is_numeric($url_id)) {
                    $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $url_id));
                    if ($correct_moniker !== NULL && $correct_moniker != $url_id && count($_POST) == 0) {
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    }
                } else {
                    // See if it is deprecated
                    if (strpos(get_db_type(), 'mysql') !== false) {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers USE INDEX (uim_moniker)', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    } else {
                        $monikers = $GLOBALS['SITE_DB']->query_select('url_id_monikers', array('m_resource_id', 'm_deprecated'), array('m_resource_page' => get_page_name(), 'm_resource_type' => get_param('type', 'misc'), 'm_moniker' => $url_id));
                    }
                    if (!array_key_exists(0, $monikers)) {
                        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
                    }
                    $deprecated = $monikers[0]['m_deprecated'] == 1;
                    if ($deprecated && count($_POST) == 0) {
                        $correct_moniker = find_id_moniker(array('page' => get_page_name(), 'type' => get_param('type', 'misc'), 'id' => $monikers[0]['m_resource_id']));
                        header('HTTP/1.0 301 Moved Permanently');
                        $_new_url = build_url(array('page' => '_SELF', 'id' => $correct_moniker), '_SELF', NULL, true);
                        $new_url = $_new_url->evaluate();
                        header('Location: ' . $new_url);
                        exit;
                    } else {
                        $_GET['id'] = $monikers[0]['m_resource_id'];
                        // We need to know the ID number rather than the moniker
                    }
                }
                break;
            }
        }
    }
    // Any messages to output?
    if (get_param_integer('redirected', 0) == 1) {
        $messages = $GLOBALS['SITE_DB']->query_select('messages_to_render', array('r_message', 'r_type'), array('r_session_id' => get_session_id()), 'ORDER BY r_time DESC');
        foreach ($messages as $message) {
            if ($GLOBALS['XSS_DETECT']) {
                ocp_mark_as_escaped($message['r_message']);
            }
            attach_message(protect_from_escaping($message['r_message']), $message['r_type']);
        }
        if (count($messages) != 0) {
            $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'messages_to_render WHERE r_session_id=' . strval((int) get_session_id()) . ' OR r_time<' . strval(time() - 60 * 60));
        }
    }
    if (in_safe_mode()) {
        $disable_safe_mode_url = get_self_url(true, true, array('keep_safe_mode' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_SAFE_MODE', escape_html($disable_safe_mode_url)), 'notice');
    }
    if (get_param_integer('keep_fatalistic', 0) == 1) {
        $disable_fatalistic_url = get_self_url(true, true, array('keep_fatalistic' => NULL));
        attach_message(do_lang_tempcode('CURRENTLY_HAS_KEEP_FATALISTIC', escape_html($disable_fatalistic_url)), 'notice');
    }
    $special_page_type = get_param('special_page_type', 'view');
    global $ZONE;
    $keep_markers = get_param_integer('keep_markers', 0);
    $show_edit_links = get_param_integer('show_edit_links', 0);
    global $KEEP_MARKERS, $SHOW_EDIT_LINKS;
    $KEEP_MARKERS = $keep_markers == 1 || $special_page_type == 'show_markers';
    if ($KEEP_MARKERS && !headers_sent()) {
        header('Content-type: text/html; charset=' . get_charset());
    }
    $SHOW_EDIT_LINKS = $show_edit_links == 1 || $special_page_type == 'show_edit_links';
    $out_evaluated = NULL;
    if ($special_page_type != 'view' && $special_page_type != 'show_markers') {
        require_code('view_modes');
        initialise_special_page_types($special_page_type);
    }
    // Set up Xdebug profiling
    if ($special_page_type == 'profile') {
        if (function_exists('xdebug_start_profiling')) {
            xdebug_start_profiling();
        }
        // xdebug 1 style
        if (ini_get('xdebug.profiler_enable') != '1') {
            attach_message(escape_html('Profiling must be enabled in php.ini'), 'warn');
        }
        // xdebug 2 style
        if (!is_writable_wrap(ini_get('xdebug.profiler_output_dir'))) {
            attach_message(escape_html('xdebug.profiler_output_dir needs setting to a writable directory'), 'warn');
        }
    }
    // Allow the site to be closed
    $site_closed = get_option('site_closed');
    if ($site_closed == '1' && !has_specific_permission(get_member(), 'access_closed_site') && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
        require_code('site2');
        closed_site();
    }
    // Work out which page we're viewing
    global $PAGE;
    $PAGE = get_page_name();
    $doing_special_page_type = $special_page_type != 'view' && $special_page_type != 'show_markers' && $special_page_type != 'show_edit_links' && $special_page_type != 'memory' && (has_specific_permission(get_member(), 'view_profiling_modes') || $GLOBALS['IS_ACTUALLY_ADMIN']);
    // Load up our frames into strings. Note that the header and the footer are fixed already.
    $middle = request_page($PAGE, true);
    global $CYCLES;
    $CYCLES = array();
    // Here we reset some Tempcode environmental stuff, because template compilation or preprocessing may have dirtied things
    if ($middle === NULL || $middle->is_definitely_empty()) {
        $GLOBALS['HTTP_STATUS_CODE'] = '404';
        if (!headers_sent()) {
            if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) {
                header('HTTP/1.0 404 Not Found');
            }
        }
        $title = get_page_title('ERROR_OCCURRED');
        $text = do_lang_tempcode('NO_PAGE_OUTPUT');
        $middle = warn_screen($title, $text, false);
    }
    // Extra stuff we can tag on (like messages)
    $additional = new ocp_tempcode();
    $site_closed = get_option('site_closed');
    // May have been JUST changed in page load - think Setup Wizard
    if ($site_closed == '1' && $PAGE != 'login' && $PAGE != 'join' && get_param_integer('wide_high', 0) == 0) {
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '03a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode(has_specific_permission(get_member(), 'access_closed_site') ? 'SITE_SPECIAL_ACCESS' : 'SITE_SPECIAL_ACCESS_SU'))));
    }
    if ($GLOBALS['IS_ACTUALLY_ADMIN']) {
        $unsu_link = get_self_url(true, true, array('keep_su' => NULL));
        $su_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => '13a41a91606b3ad05330e7d6f3e741c1', 'TYPE' => 'notice', 'MESSAGE' => do_lang_tempcode('USING_SU', escape_html($unsu_link), escape_html($su_username)))));
    }
    $out = new ocp_tempcode();
    // This is important - it makes sure the tempcode tree appears nicely
    $middle->handle_symbol_preprocessing();
    // Due to the '->evaluate()' below, plus so that some symbol preprocessing can be passed into header
    $out->attach(do_header());
    if (function_exists('memory_get_usage') && get_param('special_page_type', '') == 'memory') {
        if (function_exists('memory_get_peak_usage')) {
            $memory_usage = memory_get_peak_usage();
        } else {
            $memory_usage = memory_get_usage();
        }
        $additional->attach(do_template('ADDITIONAL', array('_GUID' => 'd605c0d111742a8cd2d4ef270a1e5fe1', 'TYPE' => 'inform', 'MESSAGE' => do_lang_tempcode('MEMORY_USAGE', float_format(round(floatval($memory_usage) / 1024.0 / 1024.0, 2))))));
    }
    // Whack it into our global template
    global $ATTACHED_MESSAGES;
    $global_template = 'GLOBAL';
    if (get_option('show_docs') == '0') {
        $GLOBALS['HELPER_PANEL_TUTORIAL'] = '';
    }
    $helper_panel_pic = $GLOBALS['HELPER_PANEL_PIC'];
    if ($helper_panel_pic != '') {
        if (find_theme_image($helper_panel_pic, true) == '') {
            $helper_panel_pic = '';
        }
    }
    $global = do_template($global_template, array('HELPER_PANEL_TUTORIAL' => $GLOBALS['HELPER_PANEL_TUTORIAL'], 'HELPER_PANEL_HTML' => $GLOBALS['HELPER_PANEL_HTML'], 'HELPER_PANEL_TEXT' => $GLOBALS['HELPER_PANEL_TEXT'], 'HELPER_PANEL_PIC' => $helper_panel_pic, 'MIDDLE' => $doing_special_page_type ? $middle : $middle->evaluate(), 'MESSAGE_TOP' => $ATTACHED_MESSAGES, 'MESSAGE' => $additional, 'BREADCRUMBS' => breadcrumbs()));
    unset($middle);
    $out->attach($global);
    $out->attach(do_footer());
    $out->handle_symbol_preprocessing();
    if (get_value('xhtml_strict') === '1') {
        $out = make_xhtml_strict($out);
    }
    // Validation
    $novalidate = get_param_integer('keep_novalidate', get_param_integer('novalidate', 0));
    $show_edit_links = get_param_integer('show_edit_links', 0);
    if ((in_array(ocp_srv('HTTP_HOST'), array('localhost', 'test.ocportal.com')) || $GLOBALS['FORUM_DRIVER']->is_staff(get_member())) && ($special_page_type == 'code' || $novalidate == 0 && get_option('validation') == '1') && $GLOBALS['REFRESH_URL'][0] == '' && $show_edit_links == 0) {
        require_code('view_modes');
        $out_evaluated = $out->evaluate(NULL, false);
        do_xhtml_validation($out_evaluated, $special_page_type == 'code' && get_param_integer('preview_mode', NULL) === NULL, get_param_integer('preview_mode', 0));
    }
    // Cacheing for spiders
    if (running_script('index') && count($_POST) == 0 && isset($GLOBALS['SITE_INFO']['fast_spider_cache']) && $GLOBALS['SITE_INFO']['fast_spider_cache'] == '1' && is_guest()) {
        $bot_type = get_bot_type();
        if (($bot_type !== NULL || isset($GLOBALS['SITE_INFO']['any_guest_cached_too']) && $GLOBALS['SITE_INFO']['any_guest_cached_too'] == '1') && can_fast_spider_cache()) {
            $fast_cache_path = get_custom_file_base() . '/persistant_cache/' . md5(serialize(get_self_url_easy()));
            if ($bot_type === NULL) {
                $fast_cache_path .= '__non-bot';
            }
            if (!array_key_exists('js_on', $_COOKIE)) {
                $fast_cache_path .= '__no-js';
            }
            if (is_mobile()) {
                $fast_cache_path .= '_mobile';
            }
            $fast_cache_path .= '.gcd';
            if (!is_dir(get_custom_file_base() . '/persistant_cache/')) {
                if (@mkdir(get_custom_file_base() . '/persistant_cache/', 0777)) {
                    fix_permissions(get_custom_file_base() . '/persistant_cache/', 0777);
                    sync_file(get_custom_file_base() . '/persistant_cache/');
                } else {
                    intelligent_write_error($fast_cache_path);
                }
            }
            $out_evaluated = $out->evaluate(NULL, false);
            $myfile = @fopen($fast_cache_path, 'wb') or intelligent_write_error($fast_cache_path);
            if (function_exists('gzencode')) {
                fwrite($myfile, gzencode($out_evaluated, 9));
            } else {
                fwrite($myfile, $out_evaluated);
            }
            fclose($myfile);
            fix_permissions($fast_cache_path);
            sync_file($fast_cache_path);
        }
    }
    if ($doing_special_page_type) {
        special_page_types($special_page_type, $out, $out_evaluated);
    }
    // We calculated the time before outputting so that latency and bandwidth do not adversely affect the result
    global $PAGE_START_TIME, $PAGE_STRING;
    $page_generation_time = microtime_diff($PAGE_START_TIME, microtime(false));
    if (!$GLOBALS['QUICK_REDIRECT']) {
        if ($out_evaluated !== NULL) {
            echo $out_evaluated;
        } else {
            $GLOBALS['FINISHING_OUTPUT'] = true;
            $out->evaluate_echo();
        }
    }
    // Finally, stats
    if ($PAGE_STRING !== NULL) {
        log_stats($PAGE_STRING, intval($page_generation_time));
    }
    // When someone hits the Admin Zone front page.
    if ($ZONE['zone_name'] == 'adminzone' && get_page_name() == 'start') {
        // Security feature admins can turn on
        require_code('notifications');
        $current_username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('AFA_NOTIFICATION_MAIL_SUBJECT', $current_username, get_site_name(), get_ip_address());
        $mail = do_lang('AFA_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($current_username), comcode_escape(get_ip_address()));
        dispatch_notification('adminzone_frontpage_accessed', NULL, $subject, $mail);
        // Track very basic details of what sites use ocPortal. You can remove if you like.
        if (preg_match('#^localhost[\\.\\:$]?#', ocp_srv('HTTP_HOST')) == 0) {
            global $EXPIRE, $KEY;
            $timeout_before = @ini_get('default_socket_timeout');
            @ini_set('default_socket_timeout', '3');
            http_download_file('http://ocportal.com/user.php?url=' . urlencode(get_base_url()) . '&name=' . urlencode(get_site_name()) . '&registered=2&key=' . ($KEY === NULL ? '' : strval($KEY)) . '&expire=' . ($EXPIRE === NULL ? '' : strval($EXPIRE)) . '&version=' . urlencode(ocp_version_full()), NULL, false);
            @ini_set('default_socket_timeout', $timeout_before);
        }
    }
    // Little disk space check
    $last_space_check = get_value('last_space_check');
    if ($last_space_check === NULL || intval($last_space_check) < time() - 60 * 60 * 3) {
        set_value('last_space_check', strval(time()));
        $low_space_check = intval(get_option('low_space_check')) * 1024 * 1024;
        $disk_space = @disk_free_space(get_file_base());
        if (is_integer($disk_space) && $disk_space < $low_space_check) {
            require_code('notifications');
            $subject = do_lang('LOW_DISK_SPACE_SUBJECT', NULL, NULL, NULL, get_site_default_lang());
            $message = do_lang('LOW_DISK_SPACE_MAIL', strval(intval(round($disk_space / 1024 / 1024))), NULL, NULL, get_site_default_lang());
            dispatch_notification('low_disk_space', NULL, $subject, $message, NULL, A_FROM_SYSTEM_PRIVILEGED);
        }
    }
    //exit();
}
Example #23
0
 /**
  * Standard modular UI/actualiser to edit an entry.
  *
  * @return tempcode	The UI
  */
 function __ed()
 {
     $id = mixed();
     // Define type as mixed
     $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id'));
     $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);
     if ($this->second_stage_preview && get_param_integer('preview', 0) == 1) {
         return $this->preview_intercept($title);
     }
     if (method_exists($this, 'get_submitter')) {
         list($submitter, $date_and_time) = $this->get_submitter($id);
         if (!is_null($date_and_time) && addon_installed('points')) {
             $reverse = post_param_integer('reverse_point_transaction', 0);
             if ($reverse == 1) {
                 $points_test = $GLOBALS['SITE_DB']->query_select('gifts', array('*'), array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id()));
                 if (array_key_exists(0, $points_test)) {
                     $amount = $points_test[0]['amount'];
                     $sender_id = $points_test[0]['gift_from'];
                     $recipient_id = $points_test[0]['gift_to'];
                     $GLOBALS['SITE_DB']->query_delete('gifts', array('id' => $points_test[0]['id']), '', 1);
                     if (!is_guest($sender_id)) {
                         $_sender_gift_points_used = point_info($sender_id);
                         $sender_gift_points_used = array_key_exists('gift_points_used', $_sender_gift_points_used) ? $_sender_gift_points_used['gift_points_used'] : 0;
                         $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used - $amount));
                     }
                     require_code('points');
                     $temp_points = point_info($recipient_id);
                     $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) - $amount));
                 }
             }
         }
     } else {
         $submitter = NULL;
     }
     breadcrumb_set_parents(array_merge($GLOBALS['BREADCRUMB_SET_PARENTS'], array(array('_SELF:_SELF:_e' . $this->type_code . ':' . $id, strpos($doing, ' ') !== false ? protect_from_escaping($doing) : do_lang_tempcode($doing)))));
     $delete = post_param_integer('delete', 0);
     if ($delete == 1 || $delete == 2) {
         if (!is_null($this->permissions_require)) {
             check_delete_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);
         }
         $doing = 'DELETE_' . $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_DELETE', escape_html($catalogue_title));
             } elseif ($this->type_code == 'c') {
                 $doing = do_lang('CATALOGUE_GENERIC_DELETE_CATEGORY', escape_html($catalogue_title));
             }
         }
         $title = get_page_title($doing);
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         $this->delete_actualisation($id);
         // Delete custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             delete_form_custom_fields($this->award_type, $id);
         }
         /*if ((!is_null($this->redirect_type)) || ((!is_null(get_param('redirect',NULL)))))		No - resource is gone now, and redirect would almost certainly try to take us back there
         		{
         			$url=(($this->redirect_type=='!') || (is_null($this->redirect_type)))?get_param('redirect'):build_url(array('page'=>'_SELF','type'=>$this->redirect_type),'_SELF');
         			return redirect_screen($title,$url,do_lang_tempcode('SUCCESS'));
         		}*/
         clear_ocp_autosave();
         $description = is_null($this->do_next_description) ? do_lang_tempcode('SUCCESS') : $this->do_next_description;
         return $this->do_next_manager($title, $description, NULL);
     } else {
         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);
         }
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         if ($this->user_facing && !is_null($this->permissions_require) && array_key_exists('validated', $_POST)) {
             if (!has_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? '' : post_param($this->permissions_cat_name), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? '' : post_param($this->permissions_cat_name_b)))) {
                 $_POST['validated'] = '0';
             }
         }
         if (!is_null($this->upload)) {
             require_code('uploads');
         }
         $description = $this->edit_actualisation($id);
         if (!is_null($this->new_id)) {
             $id = $this->new_id;
         }
         // Save custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             save_form_custom_fields($this->award_type, $id);
         }
         if ($this->output_of_action_is_confirmation && !is_null($description)) {
             return $description;
         }
         if (is_null($description)) {
             $description = do_lang_tempcode('SUCCESS');
         }
         if (addon_installed('awards')) {
             if (!is_null($this->award_type)) {
                 require_code('awards');
                 handle_award_setting($this->award_type, $id);
             }
         }
         if ($this->user_facing) {
             if ($this->check_validation && post_param_integer('validated', 0) == 0) {
                 require_code('submit');
                 if ($this->send_validation_request) {
                     $edit_url = build_url(array('page' => '_SELF', 'type' => '_e' . $this->type_code, 'id' => $id, 'validated' => 1), '_SELF', NULL, false, false, true);
                     if (addon_installed('unvalidated')) {
                         send_validation_request($doing, $this->table, $this->non_integer_id, $id, $edit_url);
                     }
                 }
                 $description->attach(paragraph(do_lang_tempcode('SUBMIT_UNVALIDATED')));
             }
         }
     }
     if (!is_null($this->redirect_type) || !is_null(get_param('redirect', NULL))) {
         $url = $this->redirect_type == '!' || is_null($this->redirect_type) ? make_string_tempcode(get_param('redirect')) : build_url(array('page' => '_SELF', 'type' => $this->redirect_type), '_SELF');
         return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
     }
     clear_ocp_autosave();
     decache('main_awards');
     return $this->do_next_manager($title, $description, $id);
 }
Example #24
0
/**
 * Render a topic row (i.e. a row in a forum or results view), from given details (from ocf_get_topic_array).
 *
 * @param  array		The details (array containing: last_post_id, id, modifiers, emoticon, first_member_id, first_username, first_post, num_posts, num_views).
 * @param  boolean	Whether the viewing member has the facility to mark off topics (send as false if there are no actions for them to perform).
 * @param  boolean	Whether the topic is a Private Topic.
 * @param  ?string	The forum name (NULL: do not show the forum name).
 * @return tempcode	The topic row.
 */
function ocf_render_topic($topic, $has_topic_marking, $pt = false, $show_forum = NULL)
{
    if (array_key_exists('last_post_id', $topic) && !is_null($topic['last_post_id'])) {
        $last_post_url = build_url(array('page' => 'topicview', 'id' => $topic['last_post_id'], 'type' => 'findpost'), get_module_zone('topicview'));
        $last_post_url->attach('#post_' . strval($topic['last_post_id']));
        if (!is_null($topic['last_member_id'])) {
            if ($topic['last_member_id'] != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
                //$colour=get_group_colour(ocf_get_member_primary_group($topic['last_member_id']));
                $poster = do_template('OCF_USER_MEMBER', array('USERNAME' => $topic['last_username'], 'PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($topic['last_member_id'], false, true)));
            } else {
                $poster = protect_from_escaping(escape_html($topic['last_username'] == '' ? do_lang('SYSTEM') : $topic['last_username']));
            }
        } else {
            $poster = do_lang_tempcode('NA');
        }
        $last_post = do_template('OCF_FORUM_TOPIC_ROW_LAST_POST', array('_GUID' => '6aa8d0f4024ae12bf94b68b74faae7cf', 'ID' => strval($topic['id']), 'DATE_RAW' => strval($topic['last_time']), 'DATE' => $topic['last_time_string'], 'POSTER' => $poster, 'LAST_URL' => $last_post_url));
    } else {
        $last_post = do_lang_tempcode('NA_EM');
    }
    $map = array('page' => 'topicview', 'id' => $topic['id']);
    if (array_key_exists('forum_id', $topic) && is_null(get_bot_type()) && get_param_integer('start', 0) != 0) {
        $map['kfs' . strval($topic['forum_id'])] = get_param_integer('start', 0);
    }
    $url = build_url($map, get_module_zone('topicview'));
    // Modifiers
    $topic_row_links = new ocp_tempcode();
    $modifiers = $topic['modifiers'];
    if (in_array('unread', $modifiers)) {
        $first_unread_url = build_url(array('page' => 'topicview', 'id' => $topic['id'], 'type' => 'first_unread'), get_module_zone('topicview'));
        $first_unread_url->attach('#first_unread');
        $topic_row_links->attach(do_template('OCF_TOPIC_ROW_LINK', array('_GUID' => '6f52881ed999f4c543c9d8573b37fa48', 'URL' => $first_unread_url, 'IMG' => 'unread', 'ALT' => do_lang_tempcode('JUMP_TO_FIRST_UNREAD'))));
    }
    $topic_row_modifiers = new ocp_tempcode();
    foreach ($modifiers as $modifier) {
        if ($modifier != 'unread') {
            $topic_row_modifiers->attach(do_template('OCF_TOPIC_ROW_MODIFIER', array('_GUID' => 'fbcb8791b571187fd699aa6796c3f401', 'IMG' => $modifier, 'ALT' => do_lang_tempcode('MODIFIER_' . $modifier))));
        }
    }
    // Emoticon
    if ($topic['emoticon'] != '') {
        $emoticon = do_template('OCF_TOPIC_EMOTICON', array('_GUID' => 'dfbe0e4a11b3caa4d2da298ff23ca221', 'EMOTICON' => $topic['emoticon']));
    } else {
        $emoticon = do_template('OCF_TOPIC_EMOTICON_NONE');
    }
    if ($topic['first_member_id'] != $GLOBALS['OCF_DRIVER']->get_guest_id()) {
        $poster_profile_url = $GLOBALS['OCF_DRIVER']->member_profile_url($topic['first_member_id'], false, true);
        //$colour=get_group_colour(ocf_get_member_primary_group($topic['first_member_id']));
        $poster = do_template('OCF_USER_MEMBER', array('PROFILE_URL' => $poster_profile_url, 'USERNAME' => $topic['first_username']));
    } else {
        $poster = make_string_tempcode(escape_html($topic['first_username']));
    }
    if ($pt) {
        $with = $topic['pt_from'] == $topic['first_member_id'] ? $topic['pt_to'] : $topic['pt_from'];
        $with_username = $GLOBALS['OCF_DRIVER']->get_username($with);
        if (is_null($with_username)) {
            $with_username = do_lang('UNKNOWN');
        }
        $colour = get_group_colour(ocf_get_member_primary_group($with));
        $b = do_template('OCF_USER_MEMBER', array('COLOUR' => $colour, 'PROFILE_URL' => $GLOBALS['OCF_DRIVER']->member_profile_url($with, false, true), 'USERNAME' => $with_username));
        $poster = do_template('OCF_PT_BETWEEN', array('_GUID' => '619cd7076c4baf7b26cb3149694af929', 'A' => $poster, 'B' => $b));
    }
    // Marker
    $marker = new ocp_tempcode();
    if ($has_topic_marking) {
        $marker = do_template('OCF_TOPIC_MARKER', array('_GUID' => '62ff977640d3d4270cf333edab42a18f', 'ID' => strval($topic['id'])));
    }
    // Title
    $title = $topic['first_title'];
    // Page jump
    $max = intval(get_option('forum_posts_per_page'));
    require_code('templates_result_launcher');
    $pages = results_launcher(do_lang_tempcode('NAMED_TOPIC', escape_html($title)), 'topicview', $topic['id'], $max, $topic['num_posts'], 'view', 5);
    // Tpl
    $post = $topic['first_post'];
    if (!is_null($show_forum)) {
        $hover = do_lang_tempcode('FORUM_AND_TIME_HOVER', escape_html($show_forum), escape_html(get_timezoned_date($topic['first_time'])));
        $breadcrumbs = ocf_forum_breadcrumbs($topic['forum_id'], NULL, NULL, false);
    } else {
        $hover = protect_from_escaping(is_null($topic['first_time']) ? '' : escape_html(get_timezoned_date($topic['first_time'])));
        $breadcrumbs = new ocp_tempcode();
    }
    return do_template('OCF_FORUM_TOPIC_ROW', array('_GUID' => '1aca672272132f390c9ec23eebe0d171', 'BREADCRUMBS' => $breadcrumbs, 'RAW_TIME' => is_null($topic['first_time']) ? '' : strval($topic['first_time']), 'UNREAD' => in_array('unread', $modifiers), 'ID' => strval($topic['id']), 'HOVER' => $hover, 'PAGES' => $pages, 'MARKER' => $marker, 'TOPIC_ROW_LINKS' => $topic_row_links, 'TOPIC_ROW_MODIFIERS' => $topic_row_modifiers, 'POST' => $post, 'EMOTICON' => $emoticon, 'DESCRIPTION' => $topic['description'], 'URL' => $url, 'TITLE' => $title, 'POSTER' => $poster, 'NUM_POSTS' => integer_format($topic['num_posts']), 'NUM_VIEWS' => integer_format($topic['num_views']), 'LAST_POST' => $last_post));
}
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'cf_order ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('cf_name' => do_lang_tempcode('NAME'), 'cf_owner_view' => do_lang_tempcode('OWNER_VIEW'), 'cf_owner_set' => do_lang_tempcode('OWNER_SET'), 'cf_public_view' => do_lang_tempcode('PUBLIC_VIEW'), 'cf_required' => do_lang_tempcode('REQUIRED'), 'cf_order' => do_lang_tempcode('ORDER'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $fh = array(do_lang_tempcode('NAME'), do_lang_tempcode('OWNER_VIEW'), do_lang_tempcode('OWNER_SET'), do_lang_tempcode('PUBLIC_VIEW'), do_lang_tempcode('REQUIRED'));
     $fh[] = do_lang_tempcode('SHOW_ON_JOIN_FORM');
     //$fh[]=do_lang_tempcode('SHOW_IN_POSTS');
     //$fh[]=do_lang_tempcode('SHOW_IN_POST_PREVIEWS');
     $fh[] = do_lang_tempcode('ORDER');
     $fh[] = do_lang_tempcode('ACTIONS');
     $header_row = results_field_title($fh, $sortables, 'sort', $sortable . ' ' . $sort_order);
     // Load up filters
     $hooks = find_all_hooks('systems', 'ocf_cpf_filter');
     $to_keep = array();
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/systems/ocf_cpf_filter/' . $hook);
         $_hook = object_factory('Hook_ocf_cpf_filter_' . $hook, true);
         if (is_null($_hook)) {
             continue;
         }
         $to_keep += $_hook->to_enable();
     }
     $fields = new ocp_tempcode();
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering, NULL);
     $changed = false;
     foreach ($rows as $row) {
         $order = post_param_integer('order_' . strval($row['id']), NULL);
         if (!is_null($order)) {
             $GLOBALS['FORUM_DB']->query_update('f_custom_fields', array('cf_order' => $order), array('id' => $row['id']), '', 1);
             $changed = true;
         }
     }
     if ($changed) {
         list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     }
     require_code('form_templates');
     foreach ($rows as $row) {
         $trans = get_translated_text($row['cf_name'], $GLOBALS['FORUM_DB']);
         $used = true;
         if (substr($trans, 0, 4) == 'ocp_') {
             // See if it gets filtered
             if (!array_key_exists(substr($trans, 4), $to_keep)) {
                 $used = false;
             }
             $test = do_lang('SPECIAL_CPF__' . $trans, NULL, NULL, NULL, NULL, false);
             if (!is_null($test)) {
                 $trans = $test;
             }
         }
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $orderlist = new ocp_tempcode();
         $num_cpfs = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'COUNT(*)');
         $selected_one = false;
         $order = $row['cf_order'];
         for ($i = 0; $i < max($num_cpfs, $order); $i++) {
             $selected = $i === $order;
             if ($selected) {
                 $selected_one = true;
             }
             $orderlist->attach(form_input_list_entry(strval($i), $selected, integer_format($i + 1)));
         }
         if (!$selected_one) {
             $orderlist->attach(form_input_list_entry(strval($order), true, integer_format($order + 1)));
         }
         $orderer = do_template('TABLE_TABLE_ROW_CELL_SELECT', array('LABEL' => do_lang_tempcode('ORDER'), 'NAME' => 'order_' . strval($row['id']), 'LIST' => $orderlist));
         $fr = array();
         $fr[] = $trans;
         $fr[] = $row['cf_owner_view'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         $fr[] = $row['cf_owner_set'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         $fr[] = $row['cf_public_view'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         $fr[] = $row['cf_required'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         $fr[] = $row['cf_show_on_join_form'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
         //$fr[]=($row['cf_show_in_posts']==1)?do_lang_tempcode('YES'):do_lang_tempcode('NO');
         //$fr[]=($row['cf_show_in_post_previews']==1)?do_lang_tempcode('YES'):do_lang_tempcode('NO');
         $fr[] = protect_from_escaping($orderer);
         if ($used) {
             $edit_link = hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id']));
         } else {
             $edit_link = do_lang_tempcode('UNUSED_CPF');
         }
         $fr[] = protect_from_escaping($edit_link);
         $fields->attach(results_entry($fr, true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order, 'sort', NULL, NULL, NULL, 8, 'gdfg43tfdgdfgdrfgd', true), true);
 }
Example #26
0
 /**
  * The UI to categorise some PTs.
  *
  * @return tempcode		The UI
  */
 function categorise_pts()
 {
     $topics = $this->get_markers();
     if (count($topics) == 0) {
         $topics[] = get_param('id', NULL);
         if (is_null($topics[0])) {
             warn_exit(do_lang_tempcode('NO_MARKERS_SELECTED'));
         }
         $_REQUEST['mark_' . $topics[0]] = 1;
     }
     $post_url = build_url(array('page' => '_SELF', 'type' => '_categorise_pts'), '_SELF');
     // Certain aspects relating to the posting system
     $fields = new ocp_tempcode();
     $filter_cats = ocf_get_filter_cats();
     $list = new ocp_tempcode();
     foreach ($filter_cats as $filter_cat) {
         $filter_cat_text = $filter_cat == '' ? do_lang_tempcode('NONE_EM') : make_string_tempcode($filter_cat);
         $list->attach(form_input_list_entry($filter_cat, $filter_cat == '', $filter_cat_text));
     }
     $fields->attach(form_input_list(do_lang_tempcode('CATEGORY'), do_lang_tempcode('DESCRIPTION_CATEGORY'), 'category_a', $list, NULL, true));
     $fields->attach(form_input_line(do_lang_tempcode('ALT_FIELD', do_lang_tempcode('NEW')), do_lang_tempcode('DESCRIPTION_ALTERNATE', protect_from_escaping(strtolower(do_lang('CATEGORY')))), 'category_b', '', false));
     $hidden = $this->keep_markers();
     breadcrumb_set_parents(array(array('_SEARCH:forumview:pt', do_lang_tempcode('PERSONAL_TOPICS'))));
     $title = get_page_title('CATEGORISE_PTS');
     $submit_name = do_lang_tempcode('CATEGORISE_PTS');
     return do_template('FORM_SCREEN', array('_GUID' => 'c6d0e273b5ce0e84d50a1c6294ece157', 'SKIP_VALIDATION' => true, 'HIDDEN' => $hidden, 'TITLE' => $title, 'FIELDS' => $fields, 'TEXT' => '', 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
Example #27
0
/**
 * Fourth installation step.
 *
 * @return tempcode		Progress report / UI
 */
function step_4()
{
    global $LANG;
    if (count($_POST) == 0) {
        exit(do_lang('INST_POST_ERROR'));
    }
    require_code('database/' . post_param('db_type'));
    $GLOBALS['DB_STATIC_OBJECT'] = object_factory('Database_Static_' . post_param('db_type'));
    $domain = ocp_srv('HTTP_HOST');
    if (substr($domain, 0, 4) == 'www.') {
        $domain = substr($domain, 4);
    }
    $colon_pos = strpos($domain, ':');
    if ($colon_pos !== false) {
        $domain = substr($domain, 0, $colon_pos);
    }
    $pos = strpos(ocp_srv('PHP_SELF'), 'install.php');
    if ($pos === false) {
        $pos = strlen(ocp_srv('PHP_SELF'));
    } else {
        $pos--;
    }
    $port = ocp_srv('SERVER_PORT');
    if ($port == '' || $port == '80' || $port == '443') {
        $port = '';
    } else {
        $port = ':' . $port;
    }
    $base_url = post_param('base_url', 'http://' . $domain . $port . substr(ocp_srv('PHP_SELF'), 0, $pos));
    if (substr($base_url, -1) == '/') {
        $base_url = substr($base_url, 0, strlen($base_url) - 1);
    }
    // Our forum is
    $forum_type = post_param('forum_type');
    require_code('forum/' . $forum_type);
    $GLOBALS['FORUM_DRIVER'] = object_factory('forum_driver_' . filter_naughty_harsh($forum_type));
    $GLOBALS['FORUM_DRIVER']->MEMBER_ROWS_CACHED = array();
    // Try and grab ourselves forum details
    global $INFO;
    $INFO['sql_database'] = '';
    $INFO['sql_user'] = '';
    $INFO['sql_pass'] = '';
    $board_path = post_param('board_path');
    find_forum_path($board_path);
    if (!array_key_exists('board_url', $INFO) || !(strlen($INFO['board_url']) > 0)) {
        $file_base = get_file_base();
        for ($i = 0; $i < strlen($board_path); $i++) {
            if ($i >= strlen($file_base)) {
                break;
            }
            if ($board_path[$i] != $file_base[$i]) {
                break;
            }
        }
        $append = str_replace('\\', '/', substr($board_path, $i));
        $INFO['board_url'] = strlen($append) < 15 ? substr($base_url, 0, strlen($base_url) - ($i - strlen($board_path))) . (strlen($append) > 0 && $append[0] == '/' ? '' : '/') . $append : $base_url . '/forums';
    }
    if (!array_key_exists('cookie_member_id', $INFO)) {
        $INFO['cookie_member_id'] = 'ocp_member_id';
    }
    if (!array_key_exists('cookie_member_hash', $INFO)) {
        $INFO['cookie_member_hash'] = 'ocp_member_hash';
    }
    $cookie_domain = '';
    //(($domain=='localhost') || (strpos($domain,'.')===false))?'':('.'.$domain);
    $cookie_path = '/';
    $cookie_days = '120';
    $use_persistent = false;
    require_code('version');
    $table_prefix = $domain == 'test.ocportal.com' ? $forum_type . '_ocp_' : 'ocp_';
    if (strpos(strtoupper(PHP_OS), 'WIN') !== false) {
        $db_site_host = '127.0.0.1';
    } else {
        $db_site_host = 'localhost';
    }
    $db_site_user = $INFO['sql_user'];
    $db_site_password = $INFO['sql_pass'];
    $db_site = $INFO['sql_database'];
    $db_forums_host = $db_site_host;
    $db_forums_user = $db_site_user;
    $db_forums_password = $db_site_password;
    $db_forums = $db_site;
    $board_prefix = $INFO['board_url'];
    $member_cookie = $INFO['cookie_member_id'];
    $pass_cookie = $INFO['cookie_member_hash'];
    if (function_exists('posix_getpwuid') && strpos(@ini_get('disable_functions'), 'posix_getpwuid') === false) {
        $u_info = posix_getpwuid(fileowner(get_file_base() . '/install.php'));
        if ($u_info !== false) {
            $ftp_username = $u_info['name'];
        } else {
            $ftp_username = '';
        }
    } else {
        $ftp_username = '';
    }
    if (is_null($ftp_username)) {
        $ftp_username = '';
    }
    $dr = array_key_exists('DOCUMENT_ROOT', $_SERVER) ? $_SERVER['DOCUMENT_ROOT'] : (array_key_exists('DOCUMENT_ROOT', $_ENV) ? $_ENV['DOCUMENT_ROOT'] : '');
    if (strpos($dr, '/') !== false) {
        $dr_parts = explode('/', $dr);
    } else {
        $dr_parts = explode('\\', $dr);
    }
    $webdir_stub = $dr_parts[count($dr_parts) - 1];
    // If we have a host where the FTP is two+ levels down (often when we have one FTP covering multiple virtual hosts), then this "last component" rule would be insufficient; do a search through for critical strings to try and make a better guess
    $special_root_dirs = array('public_html', 'www', 'webroot', 'httpdocs', 'wwwroot');
    $webdir_stub = $dr_parts[count($dr_parts) - 1];
    foreach ($dr_parts as $i => $part) {
        if (in_array($part, $special_root_dirs)) {
            $webdir_stub = implode('/', array_slice($dr_parts, $i));
        }
    }
    $ftp_folder = '/' . $webdir_stub . substr(ocp_srv('PHP_SELF'), 0, $pos);
    $ftp_domain = $domain;
    $specifics = $GLOBALS['FORUM_DRIVER']->install_specifics();
    // Now we've gone through all the work of detecting it, lets grab from info.php to see what we had last time we installed
    global $SITE_INFO;
    if (file_exists(get_file_base() . '/info.php') && filesize(get_file_base() . '/info.php') != 0) {
        require_once get_file_base() . '/info.php';
        if ($INFO['sql_database'] != '') {
            if (!array_key_exists('forum_type', $SITE_INFO) || $SITE_INFO['forum_type'] != $forum_type) {
                unset($SITE_INFO['user_cookie']);
                unset($SITE_INFO['pass_cookie']);
            }
            foreach ($specifics as $specific) {
                if (array_key_exists($specific['name'], $SITE_INFO)) {
                    unset($SITE_INFO[$specific['name']]);
                }
            }
            unset($SITE_INFO['db_forums_host']);
            unset($SITE_INFO['db_forums_user']);
            unset($SITE_INFO['db_forums_password']);
            unset($SITE_INFO['db_forums']);
            unset($SITE_INFO['db_site_host']);
            unset($SITE_INFO['db_site_user']);
            unset($SITE_INFO['db_site_password']);
            unset($SITE_INFO['db_site']);
        }
        unset($SITE_INFO['base_url']);
    }
    $sections = new ocp_tempcode();
    // Is this autoinstaller?
    global $FILE_ARRAY;
    if (@is_array($FILE_ARRAY) && !is_suexec_like()) {
        $title = protect_from_escaping(escape_html('FTP'));
        $text = do_lang_tempcode('AUTO_INSTALL');
        $hidden = new ocp_tempcode();
        $options = new ocp_tempcode();
        $options->attach(make_option(do_lang_tempcode('FTP_DOMAIN'), new ocp_tempcode(), 'ftp_domain', post_param('ftp_domain', $ftp_domain), false, true));
        $options->attach(make_option(do_lang_tempcode('FTP_USERNAME'), new ocp_tempcode(), 'ftp_username', post_param('ftp_username', $ftp_username), false, true));
        $options->attach(make_option(do_lang_tempcode('FTP_PASSWORD'), new ocp_tempcode(), 'ftp_password', post_param('ftp_password', ''), true));
        $options->attach(make_option(do_lang_tempcode('FTP_DIRECTORY'), do_lang_tempcode('FTP_FOLDER'), 'ftp_folder', post_param('ftp_folder', $ftp_folder)));
        $options->attach(make_option(do_lang_tempcode('FTP_FILES_PER_GO'), do_lang_tempcode('DESCRIPTION_FTP_FILES_PER_GO'), 'max', post_param('max', '1000')));
        $sections->attach(do_template('INSTALLER_STEP_4_SECTION', array('_GUID' => '50fcb00f4d1da1813e94d86529ea0862', 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $text, 'OPTIONS' => $options)));
    }
    $title = do_lang_tempcode('GENERAL_SETTINGS');
    $text = new ocp_tempcode();
    $options = new ocp_tempcode();
    $hidden = new ocp_tempcode();
    $options->attach(make_option(do_lang_tempcode('DOMAIN'), example('DOMAIN_EXAMPLE', 'DOMAIN_TEXT'), 'domain', $domain, false, true));
    $options->attach(make_option(do_lang_tempcode('BASE_URL'), example('BASE_URL_EXAMPLE', 'BASE_URL_TEXT'), 'base_url', $base_url, false, true));
    if (post_param('db_type') != 'xml') {
        $options->attach(make_option(do_lang_tempcode('TABLE_PREFIX'), example('TABLE_PREFIX_EXAMPLE', 'TABLE_PREFIX_TEXT'), 'table_prefix', $table_prefix));
    } else {
        $hidden->attach(form_input_hidden('table_prefix', $table_prefix));
    }
    $admin_password = '';
    $options->attach(make_option(do_lang_tempcode('MASTER_PASSWORD'), example('', 'CHOOSE_ADMIN_PASSWORD'), 'admin_password', $admin_password, true));
    $options->attach(make_tick(do_lang_tempcode('USE_PERSISTENT'), example('', 'USE_PERSISTENT_TEXT'), 'use_persistent', $use_persistent ? 1 : 0));
    //	$options->attach(make_tick(do_lang_tempcode('MULTI_LANG'),example('','MULTI_LANG_TEXT'),'multi_lang',true));
    require_lang('config');
    $options->attach(make_tick(do_lang_tempcode('SEND_ERROR_EMAILS_OCPRODUCTS'), example('', 'CONFIG_OPTION_send_error_emails_ocproducts'), 'allow_reports_default', 1));
    $sections->attach(do_template('INSTALLER_STEP_4_SECTION', array('_GUID' => 'f051465e86a7a53ec078e0d9de773993', 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $text, 'OPTIONS' => $options)));
    $hidden = new ocp_tempcode();
    $forum_text = new ocp_tempcode();
    if ($forum_type == 'ocf' || $forum_type == 'none') {
        $forum_title = do_lang_tempcode('FORUM_SETTINGS');
    } else {
        $_forum_type = do_lang('FORUM_CLASS_' . preg_replace('#\\d+$#', '', $forum_type), NULL, NULL, NULL, NULL, false);
        if (is_null($_forum_type)) {
            $_forum_type = ucwords($forum_type);
        }
        $forum_title = do_lang_tempcode('_FORUM_SETTINGS', escape_html($_forum_type));
    }
    $forum_options = new ocp_tempcode();
    $use_msn = post_param_integer('use_msn', 0);
    if ($use_msn == 0) {
        $use_msn = post_param_integer('use_multi_db', 0);
    }
    $forum_type = post_param('forum_type');
    if ($forum_type != 'none') {
        if ($use_msn == 1) {
            if ($forum_type != 'ocf') {
                $forum_text = do_lang_tempcode('AUTODETECT');
            }
            $forum_options->attach(make_option(do_lang_tempcode('DATABASE_NAME'), new ocp_tempcode(), 'db_forums', $db_forums, false, true));
            if (!$GLOBALS['DB_STATIC_OBJECT']->db_is_flat_file_simple()) {
                $forum_options->attach(make_option(do_lang_tempcode('DATABASE_HOST'), example('', 'DATABASE_HOST_TEXT'), 'db_forums_host', $db_forums_host, false, true));
                $forum_options->attach(make_option(do_lang_tempcode('DATABASE_USERNAME'), new ocp_tempcode(), 'db_forums_user', $db_forums_user, false, true));
                $forum_options->attach(make_option(do_lang_tempcode('DATABASE_PASSWORD'), new ocp_tempcode(), 'db_forums_password', $db_forums_password, true));
            } else {
                $hidden->attach(form_input_hidden('db_forums_host', 'localhost'));
                $hidden->attach(form_input_hidden('db_forums_user', ''));
                $hidden->attach(form_input_hidden('db_forums_password', ''));
            }
            $hidden->attach(form_input_hidden('use_msn', strval($use_msn)));
        }
        if ($forum_type != 'ocf' || $use_msn == 1) {
            $forum_options->attach(make_option(do_lang_tempcode('BASE_URL'), example('FORUM_BASE_URL_EXAMPLE', 'BASE_URL_TEXT_FORUM'), 'board_prefix', $board_prefix, false, true));
        }
    }
    foreach ($specifics as $specific) {
        if ($specific['name'] == 'clear_existing_forums_on_install') {
            $hidden->attach(form_input_hidden('clear_existing_forums_on_install', 'yes'));
        } elseif ($specific['name'] == 'ocf_table_prefix' && $use_msn == 0) {
            // Nothing
        } else {
            $forum_options->attach(make_option(is_object($specific['title']) ? $specific['title'] : make_string_tempcode($specific['title']), is_object($specific['description']) ? $specific['description'] : make_string_tempcode($specific['description']), $specific['name'], array_key_exists($specific['name'], $SITE_INFO) ? $SITE_INFO[$specific['name']] : $specific['default'], strpos($specific['name'], 'password') !== false));
        }
    }
    $text = $use_msn == 1 ? do_lang_tempcode($forum_type == 'ocf' ? 'DUPLICATE_OCF' : 'DUPLICATE') : new ocp_tempcode();
    $options = make_option(do_lang_tempcode('DATABASE_NAME'), new ocp_tempcode(), 'db_site', $db_site, false, true);
    if (!$GLOBALS['DB_STATIC_OBJECT']->db_is_flat_file_simple()) {
        $options->attach(make_option(do_lang_tempcode('DATABASE_HOST'), example('', 'DATABASE_HOST_TEXT'), 'db_site_host', $db_site_host, false, true));
        $options->attach(make_option(do_lang_tempcode('DATABASE_USERNAME'), new ocp_tempcode(), 'db_site_user', $db_site_user, false, true));
        $options->attach(make_option(do_lang_tempcode('DATABASE_PASSWORD'), new ocp_tempcode(), 'db_site_password', $db_site_password, true));
    } else {
        $hidden->attach(form_input_hidden('db_site_host', 'localhost'));
        $hidden->attach(form_input_hidden('db_site_user', ''));
        $hidden->attach(form_input_hidden('db_site_password', ''));
    }
    if ($use_msn == 0 && $forum_type != 'ocf') {
        $forum_options->attach($options);
        $sections->attach(do_template('INSTALLER_STEP_4_SECTION', array('HIDDEN' => $hidden, 'TITLE' => $forum_title, 'TEXT' => $forum_text, 'OPTIONS' => $forum_options)));
    } else {
        $title = do_lang_tempcode('OCPORTAL_SETTINGS');
        if (!$forum_options->is_empty()) {
            $sections->attach(do_template('INSTALLER_STEP_4_SECTION', array('_GUID' => '232b69a995f384275c1cd9269a42c3b8', 'HIDDEN' => '', 'TITLE' => $forum_title, 'TEXT' => $forum_text, 'OPTIONS' => $forum_options)));
        }
        $sections->attach(do_template('INSTALLER_STEP_4_SECTION', array('_GUID' => '15e0f275f78414b6c4fe7775a1cacb23', 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $text, 'OPTIONS' => $options)));
    }
    $title = do_lang_tempcode('COOKIE_SETTINGS');
    $text = new ocp_tempcode();
    $options = new ocp_tempcode();
    $hidden = new ocp_tempcode();
    $options->attach(make_option(do_lang_tempcode('COOKIE'), example('COOKIE_EXAMPLE', 'COOKIE_TEXT'), 'user_cookie', $member_cookie, false, true));
    $options->attach(make_option(do_lang_tempcode('COOKIE_PASSWORD'), example('COOKIE_PASSWORD_EXAMPLE', 'COOKIE_PASSWORD_TEXT'), 'pass_cookie', $pass_cookie, false, true));
    $options->attach(make_option(do_lang_tempcode('COOKIE_DOMAIN'), example('COOKIE_DOMAIN_EXAMPLE', 'COOKIE_DOMAIN_TEXT'), 'cookie_domain', $cookie_domain));
    $options->attach(make_option(do_lang_tempcode('COOKIE_PATH'), example('COOKIE_PATH_EXAMPLE', 'COOKIE_PATH_TEXT'), 'cookie_path', $cookie_path));
    $options->attach(make_option(do_lang_tempcode('COOKIE_DAYS'), example('COOKIE_DAYS_EXAMPLE', 'COOKIE_DAYS_TEXT'), 'cookie_days', $cookie_days, false, true));
    $temp = do_template('INSTALLER_STEP_4_SECTION', array('_GUID' => '3b9ea022164801f4b60780a4a966006f', 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $text, 'OPTIONS' => $options));
    $sections->attach(do_template('INSTALLER_STEP_4_SECTION_HIDE', array('_GUID' => '42eb3d44bcf8ef99987b6daa9e6530aa', 'TITLE' => $title, 'CONTENT' => $temp)));
    $js = do_template('JAVASCRIPT');
    $js->attach(chr(10));
    $js->attach(do_template('JAVASCRIPT_AJAX'));
    $message = paragraph(do_lang_tempcode('BASIC_CONFIG'));
    if ($forum_type != 'none' && $forum_type != 'ocf') {
        $message->attach(paragraph(do_lang_tempcode('FORUM_DRIVER_NATIVE_LOGIN')));
    }
    return do_template('INSTALLER_STEP_4', array('_GUID' => '73c3ac0a7108709b74b2e89cae30be12', 'JS' => $js, 'MESSAGE' => $message, 'LANG' => $LANG, 'DB_TYPE' => post_param('db_type'), 'FORUM_TYPE' => $forum_type, 'BOARD_PATH' => $board_path, 'SECTIONS' => $sections, 'MAX' => strval(post_param_integer('max', 1000))));
}
Example #28
0
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'the_message ASC');
     if (strpos($current_ordering, ' ') === false) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     list($sortable, $sort_order) = explode(' ', $current_ordering, 2);
     $sortables = array('the_message' => do_lang_tempcode('MESSAGE'), 'days' => do_lang_tempcode('NUMBER_DAYS'), 'order_time' => do_lang_tempcode('ORDER_DATE'), 'user_id' => do_lang_tempcode('OWNER'));
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('MESSAGE'), do_lang_tempcode('NUMBER_DAYS'), do_lang_tempcode('ORDER_DATE'), do_lang_tempcode('_UP_FOR'), do_lang_tempcode('OWNER'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $username = protect_from_escaping($GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($row['user_id']));
         $activation_time = $row['activation_time'];
         $days = is_null($activation_time) ? '' : float_format(round((time() - $activation_time) / 60 / 60 / 24, 3));
         $fields->attach(results_entry(array(protect_from_escaping(get_translated_tempcode($row['the_message'])), integer_format($row['days']), get_timezoned_date($row['order_time']), $row['active_now'] == 1 ? $days : do_lang_tempcode('NA_EM'), $username, protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . strval($row['id'])))), true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', either_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false);
 }
Example #29
0
/**
 * Convert a language string into another language string.
 *
 * @param  mixed			The string to convert
 * @param  LONG_TEXT		The language to convert to
 * @return LONG_TEXT		The converted string
 */
function google_translate($str_in, $lang)
{
    $tempcode = is_object($str_in);
    $GLOBALS['NO_QUERY_LIMIT'] = true;
    if (get_option('enable_google_translate', true) !== '1') {
        return $str_in;
    }
    if ($tempcode) {
        $str_in = $str_in->evaluate();
    }
    global $DOING_TRANSLATE;
    if (!isset($DOING_TRANSLATE)) {
        $DOING_TRANSLATE = false;
    }
    if ($DOING_TRANSLATE) {
        return $tempcode ? protect_from_escaping($str_in) : $str_in;
    }
    // Don't want loops
    if ($str_in == '') {
        return $tempcode ? protect_from_escaping(escape_html('')) : escape_html('');
    }
    if (strpos($str_in, 'gtranslate_cache') !== false) {
        return $tempcode ? protect_from_escaping($str_in) : $str_in;
    }
    // Stop loops about corrupt/missing database tables
    $language_list = array('ar' => 'Arabic', 'bg' => 'Bulgarian', 'zh-cn' => 'Simplified Chinese', 'zh-tw' => 'Traditional Chinese', 'hr' => 'Croatian', 'cs' => 'Czech', 'da' => 'Danish', 'nl' => 'Dutch', 'en' => 'English', 'fi' => 'Finnish', 'fr' => 'French', 'de' => 'German', 'el' => 'Greek', 'hi' => 'Hindi', 'it' => 'Italian', 'ja' => 'Japanese', 'ko' => 'Korean', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ro' => 'Romanian', 'ru' => 'Russian', 'es' => 'Spanish', 'sv' => 'Swedish');
    $lang = strtolower($lang);
    if (!array_key_exists($lang, $language_list)) {
        return $tempcode ? protect_from_escaping($str_in) : $str_in;
    }
    $DOING_TRANSLATE = true;
    require_lang('lang');
    $chache = check_google_cache($str_in, $lang);
    if (count($chache) == 0) {
        require_code('GTranslate');
        $translate = new GTranslate();
        $num_matches = array();
        $matches = array();
        $rep = array();
        $prepped = $str_in;
        $j = 0;
        foreach (array(array('[', ']'), array('{', '}')) as $symbol) {
            $_matches = array();
            $_num_matches = preg_match_all('#[' . preg_quote($symbol[0]) . '][^' . preg_quote($symbol[0]) . preg_quote($symbol[1]) . ']*[' . preg_quote($symbol[1]) . ']#', $str_in, $_matches);
            $matches[$symbol[0]] = $_matches;
            $num_matches[$symbol[0]] = $_num_matches;
            for ($i = 0; $i < $_num_matches; $i++) {
                $from = $_matches[0][$i];
                $to = '<span class="notranslate">' . strval($j) . '</span>';
                $rep['!' . strval($j)] = $from;
                // The '!' bit is because we can't trust indexing in PHP arrays if it is numeric
                $pos = 0;
                do {
                    $pos = strpos($prepped, $from, $pos);
                    if ($pos !== false) {
                        $pos_open = strrpos(substr($prepped, 0, $pos), '<');
                        $pos_close = strrpos(substr($prepped, 0, $pos), '>');
                        if ($pos_open === false || $pos_close !== false && $pos_close > $pos_open) {
                            $prepped = substr($prepped, 0, $pos) . $to . substr($prepped, $pos + strlen($from));
                            $pos += strlen($to);
                        } else {
                            $pos_title = strrpos(substr($prepped, 0, $pos), 'title="');
                            $pos_alt = strrpos(substr($prepped, 0, $pos), 'alt="');
                            $pos_quote = strrpos(substr($prepped, 0, $pos), '"');
                            if ($pos_alt !== false && $pos_alt > $pos_open && $pos_quote == $pos_alt + 4 || $pos_title !== false && $pos_title > $pos_open && $pos_quote == $pos_title + 6) {
                                $to2 = ' conv' . strval($j) . ' ';
                                $prepped = substr($prepped, 0, $pos) . $to2 . substr($prepped, $pos + strlen($from));
                                $pos += strlen($to2);
                            } else {
                                $pos += strlen($from);
                            }
                        }
                    }
                } while ($pos !== false);
                $j++;
            }
        }
        if (strpos(preg_replace('#<[^>]*>#', '', $prepped), '{') !== false) {
            $DOING_TRANSLATE = false;
            return $tempcode ? protect_from_escaping($str_in) : $str_in;
            // Cannot translate as it has very complex Tempcode in it
        }
        $to = $language_list[$lang];
        $from_lang = strtolower(get_site_default_lang());
        try {
            $convertedstring = $translate->Text($prepped)->From(array_key_exists($from_lang, $language_list) ? $language_list[$from_lang] : 'English')->To($to);
        } catch (Exception $e) {
        }
        if ($convertedstring === NULL) {
            $convertedstring = $str_in;
        }
        do {
            $before = $convertedstring;
            $convertedstring = preg_replace('#(<span class="notranslate">\\d+) (.*</span>)#', '${1}</span> <span class="notranslate">${2}', $convertedstring);
        } while ($before != $convertedstring);
        foreach (array_reverse($rep) as $_j => $from) {
            $j = intval(substr($_j, 1));
            $convertedstring = preg_replace('#\\s*<span class="notranslate">\\s*' . preg_quote(strval($j)) . '\\s*</span>\\s*#', $from, $convertedstring);
            $convertedstring = preg_replace('# conv' . preg_quote(strval($j)) . '\\s*#', $from, $convertedstring);
        }
        $convertedstring = str_replace('<html> ', '', $convertedstring);
        $convertedstring = str_replace('&#39;', '', $convertedstring);
        save_google_cache($str_in, $lang, $convertedstring);
        $str = $convertedstring;
    } else {
        $str = $chache['t_result'];
    }
    $DOING_TRANSLATE = false;
    if (function_exists('ocp_mark_as_escaped') && ocp_is_escaped($str_in)) {
        ocp_mark_as_escaped($str);
    }
    return $tempcode ? protect_from_escaping($str) : $str;
}
Example #30
0
 /**
  * Standard aed_module table function.
  *
  * @param  array			Details to go to build_url for link to the next screen.
  * @return array			A pair: The choose table, Whether re-ordering is supported from this screen.
  */
 function nice_get_choose_table($url_map)
 {
     require_code('templates_results_table');
     $current_ordering = get_param('sort', 'id ASC', true);
     list($sortable, $sort_order) = array(substr($current_ordering, 0, strrpos($current_ordering, ' ')), substr($current_ordering, strrpos($current_ordering, ' ') + 1));
     $sortables = array('id' => do_lang_tempcode('CODENAME'), 't_is_textual' => do_lang_tempcode('BANNER_IS_TEXTUAL'), 't_image_width' => do_lang_tempcode('WIDTH'), 't_image_height' => do_lang_tempcode('HEIGHT'), 't_max_file_size' => do_lang_tempcode('_FILE_SIZE'), 't_comcode_inline' => do_lang_tempcode('COMCODE_INLINE'));
     if (db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $sortables['(SELECT COUNT(*) FROM ' . get_table_prefix() . 'banners WHERE b_type=r.id)'] = do_lang_tempcode('COUNT_TOTAL');
     }
     if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $header_row = results_field_title(array(do_lang_tempcode('CODENAME'), do_lang_tempcode('BANNER_IS_TEXTUAL'), do_lang_tempcode('WIDTH'), do_lang_tempcode('HEIGHT'), do_lang_tempcode('_FILE_SIZE'), do_lang_tempcode('COMCODE_INLINE'), do_lang_tempcode('COUNT_TOTAL'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     $fields = new ocp_tempcode();
     require_code('form_templates');
     list($rows, $max_rows) = $this->get_entry_rows(false, $current_ordering);
     foreach ($rows as $row) {
         $edit_link = build_url($url_map + array('id' => $row['id']), '_SELF');
         $total = integer_format($GLOBALS['SITE_DB']->query_value('banners', 'COUNT(*)', array('b_type' => $row['id'])));
         $fields->attach(results_entry(array($row['id'] == '' ? do_lang('GENERAL') : $row['id'], $row['t_is_textual'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), integer_format($row['t_image_width']), integer_format($row['t_image_height']), clean_file_size($row['t_max_file_size'] * 1024), $row['t_comcode_inline'] == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO'), $total, protect_from_escaping(hyperlink($edit_link, do_lang_tempcode('EDIT'), false, true, '#' . $row['id']))), true));
     }
     return array(results_table(do_lang($this->menu_label), get_param_integer('start', 0), 'start', get_param_integer('max', 20), 'max', $max_rows, $header_row, $fields, $sortables, $sortable, $sort_order), false);
 }