Example #1
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (!array_key_exists('param', $map)) {
         $map['param'] = '';
     }
     if (!array_key_exists('extra', $map)) {
         $map['extra'] = '';
     }
     $max = array_key_exists('max', $map) ? intval($map['max']) : 100;
     require_code('banners');
     $b_type = $map['param'];
     $myquery = 'SELECT * FROM ' . get_table_prefix() . 'banners WHERE ((((the_type<>1) OR ((campaign_remaining>0) AND ((expiry_date IS NULL) or (expiry_date>' . strval(time()) . ')))) AND ' . db_string_not_equal_to('name', '') . ')) AND validated=1 AND ' . db_string_equal_to('b_type', $b_type) . ' ORDER BY name';
     $banners = $GLOBALS['SITE_DB']->query($myquery, 200);
     $assemble = new ocp_tempcode();
     if (count($banners) > $max) {
         shuffle($banners);
         $banners = array_slice($banners, 0, $max);
     }
     foreach ($banners as $i => $banner) {
         $bd = show_banner($banner['name'], $banner['b_title_text'], get_translated_tempcode($banner['caption']), $banner['img_url'], '', $banner['site_url'], $banner['b_type']);
         $more_coming = $i < count($banners) - 1;
         $assemble->attach(do_template('BLOCK_MAIN_BANNER_WAVE_BWRAP', array('EXTRA' => $map['extra'], 'TYPE' => $map['param'], 'BANNER' => $bd, 'MORE_COMING' => $more_coming)));
     }
     return do_template('BLOCK_MAIN_BANNER_WAVE', array('EXTRA' => $map['extra'], 'TYPE' => $map['param'], 'ASSEMBLE' => $assemble));
 }
Example #2
0
/**
 * A page is not validated, so show a warning.
 *
 * @param  ID_TEXT		The zone the page is being loaded from
 * @param  ID_TEXT		The codename of the page
 * @param  tempcode		The edit URL (blank if no edit access)
 * @return tempcode		The warning
 */
function get_page_warning_details($zone, $codename, $edit_url)
{
    $warning_details = new ocp_tempcode();
    if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
        access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
    }
    $uv_warning = do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT');
    // Wear sun cream
    if (!$edit_url->is_empty()) {
        $menu_links = $GLOBALS['SITE_DB']->query('SELECT DISTINCT i_menu FROM ' . get_table_prefix() . 'menu_items WHERE ' . db_string_equal_to('i_url', $zone . ':' . $codename) . ' OR ' . db_string_equal_to('i_url', '_SEARCH:' . $codename));
        if (count($menu_links) != 0) {
            $menu_items_linking = new ocp_tempcode();
            foreach ($menu_links as $menu_link) {
                if (!$menu_items_linking->is_empty()) {
                    $menu_items_linking->attach(do_lang_tempcode('LIST_SEP'));
                }
                $menu_edit_url = build_url(array('page' => 'admin_menus', 'type' => 'edit', 'id' => $menu_link['i_menu']), get_module_zone('admin_menus'));
                $menu_items_linking->attach(hyperlink($menu_edit_url, $menu_link['i_menu'], false, true));
            }
            $uv_warning = do_lang_tempcode('UNVALIDATED_TEXT_STAFF', $menu_items_linking);
        }
    }
    $warning_details->attach(do_template('WARNING_TABLE', array('WARNING' => $uv_warning)));
    return $warning_details;
}
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_lang('galleries');
     require_code('galleries');
     require_css('galleries');
     require_css('side_blocks');
     $parent_id = array_key_exists('param', $map) ? $map['param'] : 'root';
     $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('galleries');
     $show_empty = array_key_exists('show_empty', $map) ? $map['show_empty'] == '1' : false;
     $depth = array_key_exists('depth', $map) ? intval($map['depth']) : 0;
     // If depth is 1 then we go down 1 level. Only 0 or 1 is supported.
     // For all galleries off the root gallery
     $query = 'SELECT name,fullname FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'galleries WHERE ' . db_string_equal_to('parent_id', $parent_id) . ' AND name NOT LIKE \'' . db_encode_like('download\\_%') . '\' ORDER BY add_date';
     $galleries = $GLOBALS['SITE_DB']->query($query, 300);
     if ($depth == 0) {
         $content = $this->inside($zone, $galleries, 'BLOCK_SIDE_ROOT_GALLERIES_LINE', $show_empty);
     } else {
         $content = new ocp_tempcode();
         foreach ($galleries as $gallery) {
             if ($show_empty || gallery_has_content($gallery['name'])) {
                 $subgalleries = $GLOBALS['SITE_DB']->query_select('galleries', array('name', 'fullname'), array('parent_id' => $gallery['name']), 'ORDER BY add_date', 300);
                 $nest = $this->inside($zone, $subgalleries, 'BLOCK_SIDE_ROOT_GALLERIES_LINE_DEPTH', $show_empty);
                 $caption = get_translated_text($gallery['fullname']);
                 $content->attach(do_template('BLOCK_SIDE_ROOT_GALLERIES_LINE_CONTAINER', array('_GUID' => 'e50b84369b5e2146c4fab4fddc84bf0a', 'ID' => $gallery['name'], 'CAPTION' => $caption, 'CONTENTS' => $nest)));
             }
         }
     }
     $_title = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'fullname', array('name' => $parent_id));
     if (!is_null($_title)) {
         $title = get_translated_text($_title);
     } else {
         $title = '';
     }
     return do_template('BLOCK_SIDE_ROOT_GALLERIES', array('_GUID' => 'ed420ce9d1b1dde95eb3fd8473090228', 'TITLE' => $title, 'ID' => $parent_id, 'DEPTH' => $depth != 0, 'CONTENT' => $content));
 }
Example #4
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     $val = get_param('name');
     $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON g.g_name=t.id WHERE ' . db_string_equal_to('text_original', $val), 'g.id');
     if (is_null($test)) {
         return new ocp_tempcode();
     }
     return make_string_tempcode(str_replace(array('&lsquo;', '&rsquo;', '&ldquo;', '&rdquo;'), array('"', '"', '"', '"'), html_entity_decode(do_lang('ALREADY_EXISTS', escape_html($val)), ENT_QUOTES)));
 }
Example #5
0
/**
 * Get an SQL 'WHERE' clause for the posts in a topic.
 *
 * @param  AUTO_LINK		The ID of the topic we are getting details of.
 * @param  ?MEMBER		The member doing the lookup (NULL: current member).
 * @return string			The WHERE clause.
 */
function ocf_get_topic_where($topic_id, $member_id = NULL)
{
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    $where = 'p_topic_id=' . strval((int) $topic_id);
    if (is_guest()) {
        $where .= ' AND p_intended_solely_for IS NULL';
    } elseif (!has_specific_permission($member_id, 'view_other_pt')) {
        $where .= ' AND (p_intended_solely_for=' . strval((int) $member_id) . ' OR p_poster=' . strval((int) $member_id) . ' OR p_intended_solely_for IS NULL)';
    }
    if (!has_specific_permission($member_id, 'see_unvalidated')) {
        $where .= ' AND (p_validated=1 OR ((p_poster<>' . strval($GLOBALS['FORUM_DRIVER']->get_guest_id()) . ' OR ' . db_string_equal_to('p_ip_address', get_ip_address()) . ') AND p_poster=' . strval((int) $member_id) . '))';
    }
    return $where;
}
Example #6
0
 /**
  * Standard modular run function for RSS hooks.
  *
  * @param  string			A list of categories we accept from
  * @param  TIME			Cutoff time, before which we do not show results from
  * @param  string			Prefix that represents the template set we use
  * @set    RSS_ ATOM_
  * @param  string			The standard format of date to use for the syndication type represented in the prefix
  * @param  integer		The maximum number of entries to return, ordering by date
  * @return ?array			A pair: The main syndication section, and a title (NULL: error)
  */
 function run($_filters, $cutoff, $prefix, $date_string, $max)
 {
     if (get_forum_type() != 'ocf') {
         return NULL;
     }
     if (!has_actual_page_access(get_member(), 'forumview')) {
         return NULL;
     }
     if (is_guest()) {
         return NULL;
     }
     $condition = 'l_time<t_cache_last_time OR (l_time IS NULL AND t_cache_last_time>' . strval(time() - 60 * 60 * 24 * intval(get_option('post_history_days'))) . ')';
     $query = ' FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics top LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_read_logs l ON (top.id=l.l_topic_id AND l.l_member_id=' . strval((int) get_member()) . ') LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND top.t_cache_first_post=t.id WHERE (' . $condition . ') AND t_forum_id IS NOT NULL ' . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND t_validated=1 ' : '') . ' ORDER BY t_cache_last_time DESC';
     $rows = $GLOBALS['FORUM_DB']->query('SELECT *,top.id AS t_id ' . $query, $max);
     $categories = 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'));
     $content = new ocp_tempcode();
     foreach ($rows as $row) {
         if ((!is_null($row['t_forum_id']) || $row['t_pt_to'] == get_member()) && has_category_access(get_member(), 'forums', strval($row['t_forum_id']))) {
             $id = strval($row['id']);
             $author = $row['t_cache_first_username'];
             $news_date = date($date_string, $row['t_cache_first_time']);
             $edit_date = date($date_string, $row['t_cache_last_time']);
             if ($edit_date == $news_date) {
                 $edit_date = '';
             }
             $news_title = xmlentities($row['t_cache_first_title']);
             $_summary = get_translated_tempcode($row['t_cache_first_post'], $GLOBALS['FORUM_DB']);
             $summary = xmlentities($_summary->evaluate());
             $news = '';
             $category = array_key_exists($row['t_forum_id'], $categories) ? $categories[$row['t_forum_id']] : do_lang('NA');
             $category_raw = strval($row['t_forum_id']);
             $view_url = build_url(array('page' => 'topicview', 'id' => $row['t_id']), get_module_zone('topicview'));
             if ($prefix == 'RSS_') {
                 $if_comments = do_template('RSS_ENTRY_COMMENTS', array('COMMENT_URL' => $view_url, 'ID' => strval($row['t_id'])));
             } else {
                 $if_comments = new ocp_tempcode();
             }
             $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date)));
         }
     }
     require_lang('ocf');
     return array($content, do_lang('TOPICS_UNREAD'));
 }
Example #7
0
/**
 * Declare that an action succeeded - delete safety autosave cookies.
 */
function clear_ocp_autosave()
{
    $or_list = '';
    foreach (array_keys($_COOKIE) as $key) {
        if (substr($key, 0, 13) == 'ocp_autosave_') {
            require_code('users_active_actions');
            // Has to do both, due to inconsistencies with how PHP reads and sets cookies -- reading de-urlencodes (although not strictly needed), whilst setting does not urlencode; may differ between versions
            ocp_setcookie(urlencode($key), '0', true);
            ocp_setcookie($key, '0', true);
            if ($or_list != '') {
                $or_list .= ' OR ';
            }
            $or_list .= db_string_equal_to('a_key', $key);
        }
    }
    if ($or_list != '') {
        $GLOBALS['SITE_DB']->query('DELETE FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'autosave WHERE a_time<' . strval(time() - 60 * 60 * 24) . ' OR (a_member_id=' . strval(intval(get_member())) . ' AND (' . $or_list . '))');
    }
}
 /**
  * Standard modular run function for symbol hooks. Searches for tasks to perform.
  *
  * @param  array		Symbol parameters
  * @return string		Result
  */
 function run($param)
 {
     $value = '';
     if (array_key_exists(0, $param)) {
         $limit = array_key_exists(1, $param) ? intval($param[1]) : NULL;
         $resolve = array_key_exists(2, $param) ? $param[2] : '';
         // Content-type to associate back to, and fetch the ID for
         $rating_type = array_key_exists(3, $param) ? $param[3] : '';
         // If non empty, it will get the highest rated first
         $done = 0;
         $table = 'catalogue_fields f JOIN ' . get_table_prefix() . 'catalogue_efv_short s ON f.id=s.cf_id AND ' . db_string_equal_to('cf_type', 'reference') . ' OR cf_type LIKE \'' . db_encode_like('ck_%') . '\'';
         $select = array('ce_id');
         $order_by = '';
         if ($resolve != '') {
             $table .= ' JOIN ' . get_table_prefix() . 'catalogue_entry_linkage ON ' . db_string_equal_to('content_type', $param[2]) . ' AND catalogue_entry_id=ce_id';
             $select[] = 'content_id';
             if ($rating_type != '') {
                 $select[] = '(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', $rating_type) . ' AND rating_for_id=content_id) AS compound_rating';
                 $order_by = 'ORDER BY compound_rating DESC';
             }
         }
         $results = $GLOBALS['SITE_DB']->query_select($table, $select, array('cv_value' => $param[0]), $order_by);
         foreach ($results as $result) {
             if ($value != '') {
                 $value .= ',';
             }
             if ($resolve != '') {
                 $value .= $result['content_id'];
             } else {
                 $value .= strval($result['ce_id']);
             }
             $done++;
             if (!is_null($limit) && $done == $limit) {
                 break;
             }
         }
     }
     return $value;
 }
Example #9
0
 /**
  * Get the products handled by this eCommerce hook.
  *
  * IMPORTANT NOTE TO PROGRAMMERS: This function may depend only on the database, and not on get_member() or any GET/POST values.
  *  Such dependencies will break IPN, which works via a Guest and no dependable environment variables. It would also break manual transactions from the Admin Zone.
  *
  * @param  boolean	Whether to make sure the language for item_name is the site default language (crucial for when we read/go to third-party sales systems and use the item_name as a key).
  * @param  ?ID_TEXT	Product being searched for (NULL: none).
  * @param  boolean 	Whether $search refers to the product name rather than the product_id.
  * @return array		A map of product name to list of product details.
  */
 function get_products($site_lang = false, $search = NULL, $search_titles_not_ids = false)
 {
     $products = array();
     require_lang('shopping');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     if (!is_null($search)) {
         $where = '1=1';
         if (!$search_titles_not_ids) {
             $l = do_lang('CART_ORDER', '', NULL, NULL, $site_lang ? get_site_default_lang() : user_lang());
             if (substr($search, 0, strlen($l)) != $l) {
                 return array();
             }
             $where .= ' AND id=' . strval(intval(substr($search, strlen($l))));
         }
     } else {
         $where = '(' . db_string_equal_to('order_status', 'ORDER_STATUS_awaiting_payment') . ' OR ' . db_string_equal_to('order_status', 'ORDER_STATUS_payment_received') . ')';
     }
     if (is_null($search)) {
         $count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'shopping_order WHERE ' . $where);
         if ($count > 50) {
             return array();
         }
         // Too many to list
     }
     $start = 0;
     do {
         $orders = $GLOBALS['SITE_DB']->query('SELECT id,tot_price FROM ' . get_table_prefix() . 'shopping_order WHERE ' . $where, 500);
         foreach ($orders as $order) {
             $products[do_lang('CART_ORDER', strval($order['id']), NULL, NULL, $site_lang ? get_site_default_lang() : user_lang())] = array(PRODUCT_ORDERS, $order['tot_price'], 'handle_product_orders', array(), do_lang('CART_ORDER', strval($order['id']), NULL, NULL, $site_lang ? get_site_default_lang() : user_lang()));
         }
         $start += 500;
     } while (count($orders) == 500);
     return $products;
 }
Example #10
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (!array_key_exists('param', $map)) {
         $map['param'] = '';
     }
     require_code('banners');
     require_lang('banners');
     $b_type = $map['param'];
     $myquery = 'SELECT * FROM ' . get_table_prefix() . 'banners WHERE validated=1 AND ' . db_string_equal_to('b_type', $b_type) . ' AND (expiry_date IS NULL OR expiry_date>' . strval(time()) . ') ORDER BY hits_from+hits_to DESC';
     $_banners = $GLOBALS['SITE_DB']->query($myquery, 200);
     $assemble = new ocp_tempcode();
     $banners = array();
     foreach ($_banners as $banner) {
         $description = get_translated_tempcode($banner['caption']);
         $bd = show_banner($banner['name'], $banner['b_title_text'], $description, $banner['img_url'], '', $banner['site_url'], $banner['b_type']);
         $banners[] = array('BANNER' => $bd, 'NAME' => $banner['name'], 'URL' => $banner['site_url'], 'DESCRIPTION' => $description, 'HITSFROM' => strval($banner['hits_from']), 'HITSTO' => strval($banner['hits_to']), 'VIEWSFROM' => strval($banner['views_from']), 'VIEWSTO' => strval($banner['views_to']), 'ADDDATE' => strval($banner['add_date']), 'SUBMITTER' => strval($banner['submitter']));
     }
     if (has_actual_page_access(NULL, 'cms_banners', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_banners')) {
         $submit_url = build_url(array('page' => 'cms_banners', 'type' => 'ad', 'redirect' => SELF_REDIRECT), get_module_zone('cms_banners'));
     } else {
         $submit_url = new ocp_tempcode();
     }
     return do_template('BLOCK_MAIN_TOPSITES', array('TYPE' => $map['param'], 'BANNERS' => $banners, 'SUBMIT_URL' => $submit_url));
 }
Example #11
0
/**
 * List all the multi moderations that may be used in a certain forum.
 *
 * @param  ?AUTO_LINK	The forum we are listing for (NULL: private topics).
 * @return array 			List of multi moderations.
 */
function ocf_list_multi_moderations($forum_id)
{
    if (!addon_installed('ocf_multi_moderations')) {
        return array();
    }
    if (is_null($forum_id)) {
        return array();
    }
    $rows = $GLOBALS['FORUM_DB']->query_select('f_multi_moderations m LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND m.mm_name=t.id', array('mm_forum_multi_code', 'm.id', 'm.mm_name', 'text_original AS _mm_name'), NULL, 'ORDER BY text_original');
    $out = array();
    if (count($rows) == 0) {
        return $out;
    }
    $lots_of_forums = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)') > 200;
    if (!$lots_of_forums) {
        $all_forums = collapse_2d_complexity('id', 'f_parent_forum', $GLOBALS['FORUM_DB']->query_select('f_forums', array('id', 'f_parent_forum')));
    }
    foreach ($rows as $row) {
        if ($GLOBALS['RECORD_LANG_STRINGS_CONTENT'] || is_null($row['_mm_name'])) {
            $row['_mm_name'] = get_translated_text($row['mm_name'], $GLOBALS['FORUM_DB']);
        }
        require_code('ocfiltering');
        if ($lots_of_forums) {
            $sql = ocfilter_to_sqlfragment($row['mm_forum_multi_code'], 'id', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
            if (!is_null($GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval($forum_id) . ' AND (' . $sql . ')'))) {
                $out[$row['id']] = $row['_mm_name'];
            }
        } else {
            $idlist = ocfilter_to_idlist_using_memory($row['mm_forum_multi_code'], $all_forums, 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
            if (in_array($forum_id, $idlist)) {
                $out[$row['id']] = $row['_mm_name'];
            }
        }
    }
    return $out;
}
Example #12
0
 /**
  * UI to show all orders
  *
  * @return tempcode	The interface.
  */
 function show_orders()
 {
     require_code('shopping');
     $title = get_page_title('ORDER_LIST');
     $filter = get_param('filter', NULL);
     $search = get_param('search', '', true);
     $cond = "WHERE 1=1";
     if ($filter == 'undispatched') {
         $cond .= " AND t1.order_status='ORDER_STATUS_payment_received'";
         $title = get_page_title('UNDISPATCHED_ORDER_LIST');
     }
     $extra_join = '';
     if (!is_null($search) && $search != '') {
         $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
         $cond .= " AND (t1.id LIKE '" . db_encode_like(str_replace('#', '', $search) . '%') . "' OR t2.m_username LIKE '" . db_encode_like(str_replace('#', '', $search) . '%') . "')";
         $extra_join = ' JOIN ' . get_table_prefix() . 'f_members t2 ON t2.id=t1.c_member';
     }
     breadcrumb_set_parents(array(array('_SEARCH:admin_ecommerce:ecom_usage', do_lang_tempcode('ECOMMERCE')), array('_SELF:_SELF:misc', do_lang_tempcode('ORDERS'))));
     $orders = array();
     //pagination
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 10);
     require_code('templates_results_browser');
     require_code('templates_results_table');
     $sortables = array('t1.id' => do_lang_tempcode('ECOM_ORDER'), 't1.add_date' => do_lang_tempcode('ORDERED_DATE'), 't1.c_member' => do_lang_tempcode('ORDERED_BY'), 't1.tot_price' => do_lang_tempcode('ORDER_PRICE_AMT'), 't3.included_tax' => do_lang_tempcode('TAX_PAID'), 't1.order_status' => do_lang_tempcode('STATUS'), 't1.transaction_id' => do_lang_tempcode('TRANSACTION_ID'));
     $query_sort = explode(' ', get_param('sort', 't1.add_date ASC'), 2);
     if (count($query_sort) == 1) {
         $query_sort[] = 'ASC';
     }
     list($sortable, $sort_order) = $query_sort;
     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_title = results_field_title(array(do_lang_tempcode('ECOM_ORDER'), do_lang_tempcode('THE_PRICE'), do_lang_tempcode('TAX_PAID'), do_lang_tempcode('ORDERED_DATE'), do_lang_tempcode('ORDERED_BY'), do_lang_tempcode('TRANSACTION_ID'), do_lang_tempcode('STATUS'), do_lang_tempcode('ACTIONS')), $sortables, 'sort', $sortable . ' ' . $sort_order);
     global $NO_DB_SCOPE_CHECK;
     $NO_DB_SCOPE_CHECK = true;
     $max_rows = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . get_table_prefix() . 'shopping_order t1' . $extra_join . ' LEFT JOIN ' . get_table_prefix() . 'shopping_order_details t3 ON t1.id=t3.order_id ' . $cond);
     $results_browser = results_browser(do_lang_tempcode('ORDERS'), NULL, $start, 'start', $max, 'max', $max_rows, NULL, 'show_orders', true, true);
     $rows = $GLOBALS['SITE_DB']->query('SELECT t1.*,(t3.p_quantity*t3.included_tax) as tax FROM ' . get_table_prefix() . 'shopping_order t1' . $extra_join . ' LEFT JOIN ' . get_table_prefix() . 'shopping_order_details t3 ON t1.id=t3.order_id ' . $cond . ' GROUP BY t1.id ORDER BY ' . db_string_equal_to('t1.order_status', 'ORDER_STATUS_cancelled') . ',' . $sortable . ' ' . $sort_order, $max, $start);
     $order_entries = new ocp_tempcode();
     foreach ($rows as $row) {
         if ($row['purchase_through'] == 'cart') {
             $order_det_url = build_url(array('page' => '_SELF', 'type' => 'order_det', 'id' => $row['id']), '_SELF');
             $order_title = do_lang('CART_ORDER', strval($row['id']));
         } else {
             $res = $GLOBALS['SITE_DB']->query_select('shopping_order_details', array('p_id', 'p_name'), array('order_id' => $row['id']));
             if (!array_key_exists(0, $res)) {
                 continue;
             }
             // DB corruption
             $product_det = $res[0];
             $order_title = do_lang('PURCHASE_ORDER', strval($row['id']));
             $order_det_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $product_det['p_id']), get_module_zone('catalogues'));
         }
         $submitted_by = $GLOBALS['FORUM_DRIVER']->get_username($row['c_member']);
         $order_status = do_lang($row['order_status']);
         $ordr_act_submit = build_url(array('page' => '_SELF', 'type' => 'order_act', 'id' => $row['id']), '_SELF');
         $actions = do_template('ADMIN_ORDER_ACTIONS', array('ORDER_TITLE' => $order_title, 'ORDR_ACT_URL' => $ordr_act_submit, 'ORDER_STATUS' => $order_status));
         $url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $row['c_member']), get_module_zone('members'));
         $member = hyperlink($url, $submitted_by, false, true, do_lang('CUSTOMER'));
         $view_url = build_url(array('page' => '_SELF', 'type' => 'order_det', 'id' => $row['id']), '_SELF');
         $order_date = hyperlink($view_url, get_timezoned_date($row['add_date'], true, false, true, true));
         $transaction_details_link = build_url(array('page' => '_SELF', 'type' => 'order_det', 'id' => $row['id']), '_SELF');
         if ($row['transaction_id'] != '') {
             $transaction_details_link = build_url(array('page' => 'admin_ecommerce', 'type' => 'logs', 'product' => $order_title, 'id' => $row['id']), get_module_zone('admin_ecommerce'));
             $transaction_id = hyperlink($transaction_details_link, strval($row['transaction_id']));
         } else {
             $transaction_id = do_lang_tempcode('INCOMPLETED_TRANCACTION');
         }
         $order_entries->attach(results_entry(array(escape_html($order_title), ecommerce_get_currency_symbol() . escape_html(float_format($row['tot_price'], 2)), escape_html(float_format($row['tax'], 2)), $order_date, $member, $transaction_id, $order_status, $actions), false, NULL));
     }
     $width = array('110', '70', '80', '200', '120', '180', '180', '200');
     $results_table = results_table(do_lang_tempcode('ORDERS'), 0, 'start', $max_rows, 'max', $max_rows, $fields_title, $order_entries, $sortables, $sortable, $sort_order, 'sort', NULL, $width, 'cart');
     if (is_null($order_entries)) {
         inform_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $hidden = build_keep_form_fields('_SELF', true, array('filter'));
     $search_url = get_self_url(true);
     return do_template('ECOM_ADMIN_ORDERS_SCREEN', array('TITLE' => $title, 'CURRENCY' => get_option('currency'), 'ORDERS' => $orders, 'RESULTS_BROWSER' => $results_browser, 'RESULT_TABLE' => $results_table, 'SEARCH_URL' => $search_url, 'HIDDEN' => $hidden, 'SEARCH_VAL' => $search));
 }
Example #13
0
 /**
  * Read in the sort order currently active, and a suffix to the select statement to allow it to work. Apply security.
  *
  * @return array			A quarter: The sort order, The sort order (for backwards sorting), SQL suffix for select statement for images, SQL suffix for select statement for videos
  */
 function get_sort_order()
 {
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'sort';
     $NON_CANONICAL_PARAMS[] = 'select';
     $NON_CANONICAL_PARAMS[] = 'video_select';
     $sort = get_param('sort', 'add_date DESC');
     if ($sort == 'random ASC') {
         $sort = 'add_date ASC';
     }
     if ($sort != 'fixed_random ASC' && $sort != 'compound_rating DESC' && $sort != 'compound_rating ASC' && $sort != 'add_date DESC' && $sort != 'add_date ASC' && $sort != 'url DESC' && $sort != 'url ASC' && $sort != 'title DESC' && $sort != 'title ASC') {
         log_hack_attack_and_exit('ORDERBY_HACK');
     }
     list($_sort, $_dir) = explode(' ', $sort, 2);
     $sort_backwards = $_sort . ' ' . ($_dir == 'ASC' ? 'DESC' : 'ASC');
     if ($sort == 'compound_rating ASC' || $sort == 'compound_rating DESC') {
         $suffix_images = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'images') . ' AND rating_for_id=e.id) AS compound_rating';
         $suffix_videos = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', 'videos') . ' AND rating_for_id=e.id) AS compound_rating';
     } elseif ($sort == 'fixed_random ASC') {
         $suffix_images = ',(MOD(id,3.142)) AS fixed_random';
         $suffix_videos = ',(MOD(id,3.142)) AS fixed_random';
     } else {
         $suffix_images = '';
         $suffix_videos = '';
     }
     return array($sort, $sort_backwards, $suffix_images, $suffix_videos);
 }
Example #14
0
 /**
  * Get the topic ID from a topic identifier in the specified forum. It is used by comment topics, which means that the unique-topic-name assumption holds valid.
  *
  * @param  string			The forum name / ID
  * @param  SHORT_TEXT	The topic identifier
  * @return ?integer		The topic ID (NULL: not found)
  */
 function find_topic_id_for_topic_identifier($forum, $topic_identifier)
 {
     if (is_integer($forum)) {
         $forum_id = $forum;
     } else {
         $forum_id = $this->forum_id_from_name($forum);
     }
     $query = 'SELECT tid FROM ' . $this->connection->get_table_prefix() . 'topics WHERE t_bid=' . strval((int) $forum_id);
     $query .= ' AND (' . db_string_equal_to('t_description', $topic_identifier) . ' OR t_description LIKE \'%: #' . db_encode_like($topic_identifier) . '\')';
     return $this->connection->query_value_null_ok_full($query);
 }
Example #15
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     require_code('catalogues');
     require_lang('main_google_map');
     // Set up config/defaults
     if (!array_key_exists('title', $map)) {
         $map['title'] = '';
     }
     if (!array_key_exists('region', $map)) {
         $map['region'] = '';
     }
     if (!array_key_exists('latitude', $map)) {
         $map['latitude'] = '0';
     }
     if (!array_key_exists('longitude', $map)) {
         $map['longitude'] = '0';
     }
     $mapwidth = array_key_exists('width', $map) ? $map['width'] : '100%';
     $mapheight = array_key_exists('height', $map) ? $map['height'] : '300px';
     $api_key = array_key_exists('api_key', $map) ? $map['api_key'] : '';
     $set_zoom = array_key_exists('zoom', $map) ? $map['zoom'] : '3';
     $set_center = array_key_exists('center', $map) ? $map['center'] : '0';
     $set_show_links = array_key_exists('show_links', $map) ? $map['show_links'] : '1';
     $cluster = array_key_exists('cluster', $map) ? $map['cluster'] : '0';
     if (!array_key_exists('catalogue', $map)) {
         $map['catalogue'] = '';
     }
     if (!array_key_exists('longfield', $map)) {
         $map['longfield'] = 'Longitude';
     }
     if (!array_key_exists('latfield', $map)) {
         $map['latfield'] = 'Latitude';
     }
     $min_latitude = array_key_exists('min_latitude', $map) ? $map['min_latitude'] : '';
     $max_latitude = array_key_exists('max_latitude', $map) ? $map['max_latitude'] : '';
     $min_longitude = array_key_exists('min_longitude', $map) ? $map['min_longitude'] : '';
     $max_longitude = array_key_exists('max_longitude', $map) ? $map['max_longitude'] : '';
     $longitude_key = $map['longfield'];
     $latitude_key = $map['latfield'];
     $catalogue_name = $map['catalogue'];
     $star_entry = array_key_exists('star_entry', $map) ? $map['star_entry'] : '';
     $max_results = array_key_exists('max_results', $map) && $map['max_results'] != '' ? intval($map['max_results']) : 1000;
     $icon = array_key_exists('icon', $map) ? $map['icon'] : '';
     if (!array_key_exists('filter_category', $map)) {
         $map['filter_category'] = '';
     }
     if (!array_key_exists('filter_rating', $map)) {
         $map['filter_rating'] = '';
     }
     if (!array_key_exists('filter_term', $map)) {
         $map['filter_term'] = '';
     }
     if (!array_key_exists('filter_hours', $map)) {
         $map['filter_hours'] = '';
     }
     $data = array();
     if ($catalogue_name != '') {
         // Data query
         $query = 'SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'catalogue_entries WHERE ce_validated=1 AND ' . db_string_equal_to('c_name', $catalogue_name);
         // Filtering
         if ($map['filter_category'] != '') {
             require_code('ocfiltering');
             $query .= ' AND (' . ocfilter_to_sqlfragment($map['filter_category'], 'id', 'catalogue_categories', 'cc_parent_id', 'cc_id', 'id') . ')';
         }
         if ($map['filter_hours'] != '') {
             $query .= ' AND ce_add_date>' . strval(time() - 60 * 60 * intval($map['filter_hours']));
         }
         if ($map['filter_rating'] != '') {
             $query .= ' AND (SELECT AVG(rating) FROM rating WHERE ' . db_string_equal_to('rating_for_type', 'catalogue_entry') . ' AND rating_for_id=id)>' . strval(intval($map['filter_rating']));
         }
         // Info about our catalogue
         $catalogue_rows = $GLOBALS['SITE_DB']->query_select('catalogues', array('*'), array('c_name' => $catalogue_name), '', 1);
         if (!array_key_exists(0, $catalogue_rows)) {
             return paragraph('Could not find the catalogue named "' . escape_html($catalogue_name) . '".', '', 'nothing_here');
         }
         $catalogue_row = $catalogue_rows[0];
         // Get results
         $entries_to_show = array();
         if ($star_entry != '') {
             $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' AND id=' . strval(intval($star_entry))));
             $query .= ' AND id<>' . strval(intval($star_entry));
         }
         $entries_to_show = array_merge($entries_to_show, $GLOBALS['SITE_DB']->query($query . ' ORDER BY ce_add_date DESC', $max_results));
         if (count($entries_to_show) == 0 && ($min_latitude == '' || $max_latitude == '' || $min_longitude == '' || $max_longitude == '')) {
             //return paragraph(do_lang_tempcode('NO_ENTRIES'),'','nothing_here');
         }
         // Make marker data Javascript-friendly
         foreach ($entries_to_show as $i => $entry_row) {
             $entry_row['allow_rating'] = 0;
             // Performance: So rating is not loaded
             $details = get_catalogue_entry_map($entry_row, $catalogue_row, 'CATEGORY', $catalogue_name, NULL);
             $two_d_list = $details['FIELDS_2D'];
             $longitude = NULL;
             $latitude = NULL;
             $entry_title = '';
             $all_output = '';
             foreach ($two_d_list as $index => $l) {
                 if ($l['NAME'] == $longitude_key) {
                     $longitude = $l['VALUE'];
                 }
                 if ($l['NAME'] == $latitude_key) {
                     $latitude = $l['VALUE'];
                 }
                 if ($index == 0) {
                     $entry_title = $l['VALUE'];
                 }
                 $all_output .= (is_object($l['VALUE']) ? $l['VALUE']->evaluate() : $l['VALUE']) . ' ';
             }
             if (is_object($longitude)) {
                 $longitude = $longitude->evaluate();
             }
             if (is_object($latitude)) {
                 $latitude = $latitude->evaluate();
             }
             if (is_object($entry_title)) {
                 $entry_title = $entry_title->evaluate();
             }
             if (is_numeric($longitude) && is_numeric($latitude)) {
                 if ($map['filter_term'] == '' || strpos(strtolower($all_output), strtolower($map['filter_term'])) !== false) {
                     $details['LONGITUDE'] = float_to_raw_string(floatval($longitude));
                     $details['LATITUDE'] = float_to_raw_string(floatval($latitude));
                     $details['ENTRY_TITLE'] = $entry_title;
                     $entry_content = do_template('CATALOGUE_googlemap_ENTRY_EMBED', $details, NULL, false, 'CATALOGUE_DEFAULT_ENTRY_EMBED');
                     //put_in_standard_box(hyperlink($url,do_lang_tempcode('VIEW')),do_lang_tempcode('CATALOGUE_ENTRY').' ('.do_lang_tempcode('IN',get_translated_text($catalogue['c_title'])).')');
                     $details['ENTRY_CONTENT'] = $entry_content;
                     $details['STAR'] = '0';
                     if ($star_entry != '') {
                         if ($entry_row['id'] == intval($star_entry)) {
                             $details['STAR'] = '1';
                         }
                     }
                     $details['CC_ID'] = strval($entry_row['cc_id']);
                     $details['ICON'] = '';
                     $data[] = $details;
                 }
             }
         }
     }
     $hooks_to_use = explode('|', array_key_exists('extra_sources', $map) ? $map['extra_sources'] : '');
     $hooks = find_all_hooks('blocks', 'main_google_map');
     foreach (array_keys($hooks) as $hook) {
         if (in_array($hook, $hooks_to_use)) {
             require_code('hooks/blocks/main_google_map/' . $hook);
             $ob = object_factory('Hook_Map_' . $hook);
             $data = array_merge($data, $ob->get_data($map, $max_results, $min_latitude, $max_latitude, $min_longitude, $max_longitude, $latitude_key, $longitude_key, $catalogue_row, $catalogue_name));
         }
     }
     $uniqid = uniqid('', true);
     $div_id = 'div_' . $catalogue_name . '_' . $uniqid;
     return do_template('BLOCK_MAIN_GOOGLE_MAP', array('TITLE' => $map['title'], 'ICON' => $icon, 'MIN_LATITUDE' => $min_latitude, 'MAX_LATITUDE' => $max_latitude, 'MIN_LONGITUDE' => $min_longitude, 'MAX_LONGITUDE' => $max_longitude, 'DATA' => $data, 'SHOW_LINKS' => $set_show_links, 'DIV_ID' => $div_id, 'CLUSTER' => $cluster, 'REGION' => $map['region'], 'WIDTH' => $mapwidth, 'HEIGHT' => $mapheight, 'LATITUDE' => $map['latitude'], 'LONGITUDE' => $map['longitude'], 'ZOOM' => $set_zoom, 'CENTER' => $set_center));
 }
Example #16
0
/**
 * Update the member tracker for the currently viewing user.
 */
function member_tracking_update()
{
    global $ZONE;
    $page = get_param('page', $ZONE['zone_default_page']);
    $type = get_param('type', '/');
    $id = get_param('id', '/', true);
    if ($type == '/') {
        $type = '';
    }
    if ($id == '/') {
        $id = '';
    }
    $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'member_tracking WHERE mt_time<' . strval(time() - 60 * intval(get_option('users_online_time'))) . ' OR (mt_member_id=' . strval((int) get_member()) . ' AND ' . db_string_equal_to('mt_type', $type) . ' AND ' . db_string_equal_to('mt_id', $id) . ' AND ' . db_string_equal_to('mt_page', $page) . ')');
    $GLOBALS['SITE_DB']->query_insert('member_tracking', array('mt_member_id' => get_member(), 'mt_cache_username' => $GLOBALS['FORUM_DRIVER']->get_username(get_member()), 'mt_time' => time(), 'mt_page' => $page, 'mt_type' => $type, 'mt_id' => $id), false, true);
    // Ignore errors for race conditions
}
Example #17
0
 /**
  * UI: find quiz winner.
  *
  * @return tempcode	The result of execution.
  */
 function find_winner()
 {
     $title = get_page_title('FIND_WINNERS');
     require_code('form_templates');
     $_m = $GLOBALS['SITE_DB']->query('SELECT * FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'quizzes WHERE ' . db_string_equal_to('q_type', 'COMPETITION') . ' ORDER BY q_validated DESC,q_add_date DESC', 300);
     $entries = new ocp_tempcode();
     foreach ($_m as $m) {
         $entries->attach(form_input_list_entry(strval($m['id']), false, get_translated_text($m['q_name'])));
     }
     if ($entries->is_empty()) {
         inform_exit(do_lang_tempcode('NO_ENTRIES'));
     }
     $fields = new ocp_tempcode();
     $fields->attach(form_input_list(do_lang_tempcode('QUIZ'), '', 'id', $entries, NULL, true));
     $post_url = build_url(array('page' => '_SELF', 'type' => '_find_winner'), '_SELF');
     $submit_name = do_lang_tempcode('PROCEED');
     $text = do_lang_tempcode('CHOOSE_WINNERS');
     breadcrumb_set_self(do_lang_tempcode('CHOOSE'));
     breadcrumb_set_parents(array(array('_SELF:_SELF', do_lang_tempcode('MANAGE_QUIZZES'))));
     return do_template('FORM_SCREEN', array('HIDDEN' => '', 'SKIP_VALIDATION' => true, 'TITLE' => $title, 'TEXT' => $text, 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name));
 }
Example #18
0
/**
 * Find whether you have rated the specified resource before.
 *
 * @param  array			List of types (download, etc) that this rating is for. All need to be rated for it to return true.
 * @param  ID_TEXT		The ID of the type that this rating is for
 * @return boolean		Whether the resource has already been rated
 */
function already_rated($rating_for_types, $content_id)
{
    $more = !is_guest() ? ' OR rating_member=' . strval((int) get_member()) : '';
    $for_types = '';
    foreach ($rating_for_types as $rating_for_type) {
        if ($for_types != '') {
            $for_types .= ' OR ';
        }
        $for_types .= db_string_equal_to('rating_for_type', $rating_for_type);
    }
    $query = 'SELECT COUNT(*) FROM ' . get_table_prefix() . 'rating WHERE (' . $for_types . ') AND ' . db_string_equal_to('rating_for_id', $content_id);
    $query .= ' AND (';
    if (!$GLOBALS['IS_ACTUALLY_ADMIN']) {
        $query .= 'rating_ip=\'' . get_ip_address() . '\'';
    } else {
        $query .= '1=0';
    }
    $query .= $more . ')';
    $has_rated = $GLOBALS['SITE_DB']->query_value_null_ok_full($query);
    return $has_rated >= count($rating_for_types);
}
Example #19
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_ocf_groups($db, $table_prefix, $file_base)
 {
     require $file_base . '/config.php';
     $rows = $db->query('SELECT * FROM ' . $table_prefix . 'user_groups ORDER BY user_group_id');
     foreach ($rows as $row) {
         if (import_check_if_imported('group', strval($row['user_group_id']))) {
             continue;
         }
         $is_super_admin = $row['admin_rights'];
         $is_super_moderator = $row['super_moderator_rights'];
         $group_name_remap = array('Unregistered' => 'Guests', 'Moderators' => 'Super-members', 'Super Moderators' => 'Super-moderators');
         if (array_key_exists($row['user_group_name'], $group_name_remap)) {
             $row['user_group_name'] = $group_name_remap[$row['user_group_name']];
         }
         $id_new = $GLOBALS['FORUM_DB']->query_value_null_ok('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON g.g_name=t.id WHERE ' . db_string_equal_to('text_original', $row['user_group_name']), 'g.id');
         if (is_null($id_new)) {
             $id_new = ocf_make_group($row['user_group_name'], 0, $is_super_admin, $is_super_moderator, $row['user_group_title'], '', NULL, NULL, NULL, constant('FLOOD_INTERVAL'), 0, $row['post_attachments'] == 0 ? 0 : 5, 5, constant('AVATAR_DIMENSIONS_MAX'), constant('AVATAR_DIMENSIONS_MAX'), 30000, 700, 25, $row['add_mana']);
         }
         // privileges
         set_specific_permission($id_new, 'vote_in_polls', $row['vote_on_polls']);
         set_specific_permission($id_new, 'use_pt', $row['pm']);
         set_specific_permission($id_new, 'submit_lowrange_content', $row['post_new_topics']);
         set_specific_permission($id_new, 'view_member_photos', $row['view_member_info']);
         set_specific_permission($id_new, 'edit_lowrange_content', $row['edit_own_posts']);
         set_specific_permission($id_new, 'add_public_events', $row['post_public_events']);
         set_specific_permission($id_new, 'view_calendar', $row['view_public_events']);
         $denies = array();
         if ($row['view_board'] == 0) {
             $denies[] = array('forumview', get_module_zone('forumview'));
         }
         if ($row['search'] == 0) {
             $denies[] = array('search', get_module_zone('search'));
         }
         foreach ($denies as $deny) {
             list($page, $zone) = $deny;
             $test = $GLOBALS['SITE_DB']->query_value_null_ok('group_page_access', 'group_id', array('group_id' => $id_new, 'zone_name' => $zone, 'page_name' => $page));
             if (is_null($test)) {
                 $GLOBALS['SITE_DB']->query_insert('group_page_access', array('group_id' => $id_new, 'zone_name' => $zone, 'page_name' => $page));
             }
         }
         import_id_remap_put('group', strval($row['user_group_id']), $id_new);
     }
 }
Example #20
0
/**
 * Delete a privilege, and every usergroup is then relaxed from the restrictions of this permission.
 *
 * @param  ID_TEXT		The codename of the permission
 */
function delete_specific_permission($name)
{
    $GLOBALS['SITE_DB']->query_delete('sp_list', array('the_name' => $name), '', 1);
    $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'gsp WHERE ' . db_string_not_equal_to('module_the_name', 'forums') . ' AND ' . db_string_equal_to('specific_permission', $name));
}
Example #21
0
 /**
  * Standard import function.
  *
  * @param  object			The DB connection to import from
  * @param  string			The table prefix the target prefix is using
  * @param  PATH			The base directory we are importing from
  */
 function import_wordfilter($db, $table_prefix, $file_base)
 {
     $rows = $db->query('SELECT value FROM ' . $table_prefix . 'setting WHERE ' . db_string_equal_to('varname', 'censorwords'));
     $censorwords = $rows[0]['value'];
     foreach (explode(' ', $censorwords) as $word) {
         if ($word != '') {
             add_wordfilter_word($word);
         }
     }
 }
Example #22
0
 /**
  * Standard modular new-style deep page-link finder function (does not return the main entry-points).
  *
  * @param  string  	Callback function to send discovered page-links to.
  * @param  MEMBER		The member we are finding stuff for (we only find what the member can view).
  * @param  integer	Code for how deep we are tunnelling down, in terms of whether we are getting entries as well as categories.
  * @param  string		Stub used to create page-links. This is passed in because we don't want to assume a zone or page name within this function.
  */
 function get_sitemap_pagelinks($callback, $member_id, $depth, $pagelink_stub)
 {
     // Entries
     if ($depth >= DEPTH__ENTRIES) {
         $rows = $GLOBALS['SITE_DB']->query_select('iotd c LEFT JOIN ' . get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND t.id=c.i_title', array('c.i_title', 'c.id', 't.text_original AS title', 'add_date', 'edit_date'), array('used' => 1));
         foreach ($rows as $row) {
             if (is_null($row['title'])) {
                 $row['title'] = get_translated_text($row['i_title']);
             }
             $pagelink = $pagelink_stub . 'view:' . strval($row['id']);
             call_user_func_array($callback, array($pagelink, $pagelink_stub . 'misc', $row['add_date'], $row['edit_date'], 0.2, $row['title']));
             // Callback
         }
     }
 }
Example #23
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 #24
0
 /**
  * The actualiser to prune subscribers.
  *
  * @return tempcode		The UI
  */
 function bounce_filter_d()
 {
     $title = get_page_title('BOUNCE_FILTER');
     $sup = '';
     foreach (array_keys($_POST) as $key) {
         if (substr($key, 0, 6) == 'email_') {
             if ($sup != '') {
                 $sup .= ' OR ';
             }
             $sup .= db_string_equal_to('email', post_param($key));
         }
     }
     if ($sup == '') {
         warn_exit(do_lang_tempcode('NOTHING_SELECTED'));
     }
     $query = 'DELETE FROM ' . get_table_prefix() . 'newsletter WHERE ' . $sup;
     $GLOBALS['SITE_DB']->query($query);
     return inform_screen($title, do_lang_tempcode('SUCCESS'));
 }
Example #25
0
/**
 * Show the point transactions a member has had.
 *
 * @param  ID_TEXT		The type of transactions we are looking for
 * @set    from to
 * @param  MEMBER			Who we are looking at transactions for
 * @param  MEMBER			Who we are looking at transactions using the account of
 * @return tempcode		The UI
 */
function points_get_transactions($type, $member_id_of, $member_id_viewing)
{
    $where = array('gift_' . $type => $member_id_of);
    if ($type == 'from') {
        $where['anonymous'] = 0;
    }
    $start = get_param_integer('gift_start_' . $type, 0);
    $max = get_param_integer('gift_max_' . $type, 10);
    $sortables = array('date_and_time' => do_lang_tempcode('DATE'), 'amount' => do_lang_tempcode('AMOUNT'));
    $test = explode(' ', get_param('gift_sort_' . $type, 'date_and_time DESC'));
    if (count($test) == 1) {
        $test[1] = 'DESC';
    }
    list($sortable, $sort_order) = $test;
    if (strtoupper($sort_order) != 'ASC' && strtoupper($sort_order) != 'DESC' || !array_key_exists($sortable, $sortables)) {
        log_hack_attack_and_exit('ORDERBY_HACK');
    }
    global $NON_CANONICAL_PARAMS;
    $NON_CANONICAL_PARAMS[] = 'gift_sort_' . $type;
    $NON_CANONICAL_PARAMS[] = 'gift_start_' . $type;
    $max_rows = $GLOBALS['SITE_DB']->query_value('gifts', 'COUNT(*)', $where);
    $rows = $GLOBALS['SITE_DB']->query_select('gifts g LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND t.id=g.reason', array('*'), $where, 'ORDER BY ' . $sortable . ' ' . $sort_order, $max, $start);
    $out = new ocp_tempcode();
    $viewing_name = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
    if (is_null($viewing_name)) {
        $viewing_name = do_lang('UNKNOWN');
    }
    require_code('templates_results_table');
    $fields_title = results_field_title(array(do_lang_tempcode('DATE'), do_lang_tempcode('AMOUNT'), do_lang_tempcode('FROM'), do_lang_tempcode('TO'), do_lang_tempcode('REASON')), $sortables, 'gift_sort_' . $type, $sortable . ' ' . $sort_order);
    foreach ($rows as $myrow) {
        if ($myrow['anonymous'] == 1 && $type == 'from') {
            continue;
        }
        // Their name
        $fromname = is_guest($myrow['gift_from']) ? get_site_name() : $GLOBALS['FORUM_DRIVER']->get_username($myrow['gift_from']);
        $toname = $GLOBALS['FORUM_DRIVER']->get_username($myrow['gift_to']);
        if (is_null($fromname)) {
            $fromname = do_lang('UNKNOWN');
        }
        if ($myrow['anonymous'] == 1 && !is_guest($myrow['gift_from'])) {
            if (!has_specific_permission($member_id_viewing, 'trace_anonymous_gifts')) {
                $_fromname = do_lang_tempcode('ANON');
            } else {
                $_fromname = hyperlink(build_url(array('page' => 'points', 'type' => 'member', 'id' => $myrow['gift_from']), get_module_zone('points')), do_lang_tempcode('ANON'), false, false, escape_html($fromname));
            }
        } else {
            $_fromname = is_guest($myrow['gift_from']) ? make_string_tempcode(escape_html($fromname)) : hyperlink(build_url(array('page' => 'points', 'type' => 'member', 'id' => $myrow['gift_from']), get_module_zone('points')), escape_html($fromname), false, false, do_lang_tempcode('VIEW_POINTS'));
        }
        $_toname = hyperlink(build_url(array('page' => 'points', 'type' => 'member', 'id' => $myrow['gift_to']), get_module_zone('points')), escape_html($toname), false, false, do_lang_tempcode('VIEW_POINTS'));
        $date = get_timezoned_date($myrow['date_and_time']);
        $amount = $myrow['amount'];
        if (get_page_name() != 'search' && array_key_exists('text_parsed', $myrow) && !is_null($myrow['text_parsed']) && $myrow['text_parsed'] != '' && $myrow['reason'] != 0) {
            $reason = new ocp_tempcode();
            if (!$reason->from_assembly($myrow['text_parsed'], true)) {
                $reason = get_translated_tempcode($myrow['reason']);
            }
        } else {
            $reason = get_translated_tempcode($myrow['reason']);
        }
        $out->attach(results_entry(array(escape_html($date), escape_html(integer_format($amount)), $_fromname, $_toname, $reason)));
    }
    $out = results_table(do_lang_tempcode('_POINTS', escape_html($viewing_name)), $start, 'gift_start_' . $type, $max, 'gift_max_' . $type, $max_rows, $fields_title, $out, $sortables, $sortable, $sort_order, 'gift_sort_' . $type, NULL, NULL, NULL, 8, 'gfhfghtrhhjghgfhfgf', false, 'tab__points');
    if ($type == 'to') {
        $title = do_lang_tempcode('POINTS_TO');
    } else {
        $title = do_lang_tempcode('POINTS_FROM');
    }
    return do_template('POINTS_TRANSACTIONS_WRAP', array('_GUID' => 'f19e3eedeb0b8bf398251b24e8389723', 'CONTENT' => $out, 'TITLE' => $title));
}
Example #26
0
 /**
  * The UI to translate content.
  *
  * @return tempcode		The UI
  */
 function interface_content()
 {
     $title = get_page_title('TRANSLATE_CONTENT');
     if (!multi_lang()) {
         warn_exit(do_lang_tempcode('MULTILANG_OFF'));
     }
     $max = get_param_integer('max', 100);
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     // Fiddle around in order to find what we haven't translated. Subqueries and self joins don't work well enough across different db's
     if (!db_has_subqueries($GLOBALS['SITE_DB']->connection_read)) {
         $_done_id_list = collapse_2d_complexity('id', 'text_original', $GLOBALS['SITE_DB']->query_select('translate', array('id', 'text_original'), array('language' => $lang, 'broken' => 0)));
         $done_id_list = '';
         foreach (array_keys($_done_id_list) as $done_id) {
             if ($done_id_list != '') {
                 $done_id_list .= ',';
             }
             $done_id_list .= strval($done_id);
         }
         $and_clause = $done_id_list == '' ? '' : 'AND id NOT IN (' . $done_id_list . ')';
         $query = 'FROM ' . get_table_prefix() . 'translate WHERE ' . db_string_not_equal_to('language', $lang) . ' ' . $and_clause . ' AND ' . db_string_not_equal_to('text_original', '') . ' ORDER BY importance_level';
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT * ' . $query, $max);
     } else {
         $query = 'FROM ' . get_table_prefix() . 'translate a LEFT JOIN ' . get_table_prefix() . 'translate b ON a.id=b.id AND b.broken=0 AND ' . db_string_equal_to('b.language', $lang) . ' WHERE b.id IS NULL AND ' . db_string_not_equal_to('a.language', $lang) . ' AND ' . db_string_not_equal_to('a.text_original', '');
         $to_translate = $GLOBALS['SITE_DB']->query('SELECT a.* ' . $query . (can_arbitrary_groupby() ? ' GROUP BY a.id' : '') . ' ORDER BY a.importance_level', $max);
     }
     $total = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) ' . $query);
     if (count($to_translate) == 0) {
         inform_exit(do_lang_tempcode('NOTHING_TO_TRANSLATE'));
     }
     require_all_lang($lang, true);
     require_all_open_lang_files($lang);
     // Make our translation page
     require_code('lang2');
     $lines = '';
     $intertrans = $this->get_intertran_conv($lang);
     $actions = make_string_tempcode('&nbsp;');
     $last_level = NULL;
     $too_many = count($to_translate) == $max;
     $ids_to_lookup = array();
     foreach ($to_translate as $it) {
         $ids_to_lookup[] = $it['id'];
     }
     $names = find_lang_content_names($ids_to_lookup);
     foreach ($to_translate as $i => $it) {
         if ($it['importance_level'] == 0) {
             continue;
         }
         // Corrupt data
         $id = $it['id'];
         $old = $it['text_original'];
         $current = $this->find_lang_matches($old, $lang);
         $priority = $last_level === $it['importance_level'] ? NULL : do_lang('PRIORITY_' . strval($it['importance_level']));
         $name = $names[$id];
         if (is_null($name)) {
             continue;
         }
         // Orphaned string
         if ($intertrans != '') {
             $actions = do_template('TRANSLATE_ACTION', array('_GUID' => 'f625cf15c9db5e5af30fc772a7f0d5ff', 'LANG_FROM' => $it['language'], 'LANG_TO' => $lang, 'NAME' => 'trans_' . strval($id), 'OLD' => $old));
         }
         $line = do_template('TRANSLATE_LINE_CONTENT', array('_GUID' => '87a0f5298ce9532839f3206cd0e06051', 'NAME' => $name, 'ID' => strval($id), 'OLD' => $old, 'CURRENT' => $current, 'ACTIONS' => $actions, 'PRIORITY' => $priority));
         $lines .= $line->evaluate();
         /*XHTMLXHTML*/
         $last_level = $it['importance_level'];
     }
     $url = build_url(array('page' => '_SELF', 'type' => '_content', 'lang' => $lang), '_SELF');
     require_code('lang2');
     return do_template('TRANSLATE_SCREEN_CONTENT_SCREEN', array('_GUID' => 'af732c5e595816db1c6f025c4b8fa6a2', 'MAX' => integer_format($max), 'TOTAL' => integer_format($total - $max), 'LANG_ORIGINAL_NAME' => get_site_default_lang(), 'LANG_NICE_ORIGINAL_NAME' => lookup_language_full_name(get_site_default_lang()), 'LANG_NICE_NAME' => lookup_language_full_name($lang), 'TOO_MANY' => $too_many, 'INTERTRANS' => $intertrans, 'LANG' => $lang, 'LINES' => $lines, 'TITLE' => $title, 'URL' => $url));
 }
Example #27
0
 /**
  * The UI to show the usergroup directory.
  *
  * @return tempcode		The UI
  */
 function directory()
 {
     $title = get_page_title('USERGROUPS');
     $map = has_specific_permission(get_member(), 'see_hidden_groups') ? array('g_is_private_club' => 0) : array('g_is_private_club' => 0, 'g_hidden' => 0);
     $groups = $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), $map, 'ORDER BY g_order,id');
     $staff_groups = array_merge($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), $GLOBALS['FORUM_DRIVER']->get_moderator_groups());
     foreach ($groups as $g_id => $row) {
         $groups[$g_id]['text_original'] = get_translated_text($row['g_name'], $GLOBALS['FORUM_DB']);
     }
     // Categorise
     $_staff = array();
     $_ranks = array();
     $_others = array();
     foreach ($groups as $group) {
         if ($group['id'] == 1) {
             continue;
         }
         // Don't show guest usergroup
         if (in_array($group['id'], $staff_groups)) {
             $_staff[$group['id']] = $group;
         } else {
             $_others[$group['id']] = $group;
             if (!is_null($group['g_promotion_target'])) {
                 // Are we at the start of a usergroup?
                 $found = false;
                 foreach ($groups as $group2) {
                     if ($group2['g_promotion_target'] == $group['id']) {
                         $found = true;
                         break;
                     }
                 }
                 if (!$found) {
                     $_ranks[$group['id']] = array($group['id'] => $group);
                     $next = $group['g_promotion_target'];
                     while (!is_null($next)) {
                         $found = false;
                         foreach ($groups as $group2) {
                             if ($group2['id'] == $next) {
                                 $next = $group2['g_promotion_target'];
                                 $_ranks[$group['id']][$group2['id']] = $group2;
                                 if (array_key_exists($next, $_ranks[$group['id']])) {
                                     break;
                                 }
                                 // uhoh- loop
                                 $found = true;
                                 break;
                             }
                         }
                         if (!$found) {
                             break;
                         }
                         // uhoh- either loop, or unfound usergroup
                     }
                 }
             }
         }
     }
     // Cleanup so no usergroups in rank lines are in $others
     foreach ($_ranks as $r) {
         foreach (array_keys($r) as $g_id) {
             unset($_others[$g_id]);
         }
     }
     // Generate usergroup result browsers
     require_code('templates_results_table');
     $sortables = array();
     list($sortable, $sort_order) = array('foo', 'ASC');
     //-Staff
     $start = get_param_integer('staff_start', 0);
     $max = get_param_integer('staff_max', 50);
     $max_rows = count($_staff);
     $fields_title = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('COUNT_MEMBERS')), $sortables);
     $staff = new ocp_tempcode();
     $i = 0;
     foreach ($_staff as $row) {
         if ($i < $start) {
             $i++;
             continue;
         }
         if ($i > $start + $max) {
             break;
         }
         $name = $row['text_original'];
         $url = build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $row['id']), '_SELF');
         $num_members = integer_format(ocf_get_group_members_raw_count($row['id'], true));
         $staff->attach(results_entry(array(hyperlink($url, escape_html($name)), escape_html($num_members))));
         $i++;
     }
     $staff = results_table(do_lang_tempcode('STAFF'), $start, 'staff_start', $max, 'staff_max', $max_rows, $fields_title, $staff, $sortables, $sortable, $sort_order, 'staff_sort', NULL, array('200'));
     //-Ranks
     $ranks = array();
     foreach ($_ranks as $g_id => $_rank) {
         $start = get_param_integer('rank_start_' . strval($g_id), 0);
         $max = get_param_integer('rank_max_' . strval($g_id), 50);
         $max_rows = count($_rank);
         $fields_title = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('COUNT_MEMBERS'), do_lang_tempcode('PROMOTION_THRESHOLD')), $sortables);
         $rank = new ocp_tempcode();
         $i = 0;
         foreach ($_rank as $row) {
             if ($i < $start) {
                 $i++;
                 continue;
             }
             if ($i > $start + $max) {
                 break;
             }
             $name = $row['text_original'];
             $url = build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $row['id']), '_SELF');
             $num_members = integer_format(ocf_get_group_members_raw_count($row['id'], true));
             $_p_t = $row['g_promotion_threshold'];
             $p_t = new ocp_tempcode();
             if (!is_null($_p_t) && array_key_exists($row['g_promotion_target'], $_rank)) {
                 $p_t = do_lang_tempcode('PROMOTION_TO', escape_html(integer_format($_p_t)), escape_html($_rank[$row['g_promotion_target']]['text_original']));
             }
             $rank->attach(results_entry(array(hyperlink($url, escape_html($name)), escape_html($num_members), $p_t)));
         }
         $rank = results_table(do_lang_tempcode('RANK_SETS'), $start, 'rank_start_' . strval($g_id), $max, 'rank_max_' . strval($g_id), $max_rows, $fields_title, $rank, $sortables, $sortable, $sort_order, 'rank_sort_' . strval($g_id), NULL, array('200'));
         $ranks[] = $rank;
     }
     //-Others
     $start = get_param_integer('others_start', 0);
     $max = get_param_integer('others_max', 20);
     $map = has_specific_permission(get_member(), 'see_hidden_groups') ? array('g_is_private_club' => 1) : array('g_is_private_club' => 1, 'g_hidden' => 0);
     $max_rows = count($_others);
     for ($i = 0; $i < $start; $i++) {
         array_shift($_others);
     }
     $query_max = $max - count($_others);
     $query_start = $start - $max_rows;
     if ($query_start < 0) {
         $query_max += $query_start;
         $query_start = 0;
     }
     if ($query_max < 0) {
         $query_max = 0;
     }
     $_others = array_merge($_others, $GLOBALS['FORUM_DB']->query_select('f_groups g LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND g.g_name=t.id', array('g.*', 'text_original'), $map, 'ORDER BY g_order,g.id', $query_max, $query_start));
     $max_rows += $GLOBALS['FORUM_DB']->query_value('f_groups g', 'COUNT(*)', $map);
     $fields_title = results_field_title(array(do_lang_tempcode('NAME'), do_lang_tempcode('COUNT_MEMBERS')), $sortables);
     $others = new ocp_tempcode();
     foreach ($_others as $row) {
         $row['text_original'] = get_translated_text($row['g_name'], $GLOBALS['FORUM_DB']);
         $name = $row['text_original'];
         $url = build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $row['id']), '_SELF');
         $num_members = integer_format(ocf_get_group_members_raw_count($row['id'], true));
         $others->attach(results_entry(array(hyperlink($url, escape_html($name)), escape_html($num_members))));
     }
     $others = results_table(do_lang_tempcode('OTHER_USERGROUPS'), $start, 'others_start', $max, 'others_max', $max_rows, $fields_title, $others, $sortables, $sortable, $sort_order, 'others_sort', NULL, array('200'));
     return do_template('OCF_GROUP_DIRECTORY_SCREEN', array('_GUID' => '39aebd8fcb618c2ae45e867d0c96a4cf', 'TITLE' => $title, 'STAFF' => $staff, 'OTHERS' => $others, 'RANKS' => $ranks));
 }
Example #28
0
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
Example #29
0
 /**
  * Get the topic ID from a topic identifier in the specified forum. It is used by comment topics, which means that the unique-topic-name assumption holds valid.
  *
  * @param  string			The forum name / ID
  * @param  SHORT_TEXT	The topic identifier
  * @return ?integer		The topic ID (NULL: not found)
  */
 function find_topic_id_for_topic_identifier($forum, $topic_identifier)
 {
     if (is_integer($forum)) {
         $forum_id = $forum;
     } else {
         $forum_id = $this->forum_id_from_name($forum);
     }
     return $this->connection->query_value_null_ok_full('SELECT threadid FROM ' . $this->connection->get_table_prefix() . 'threads WHERE boardid=' . strval((int) $forum_id) . ' AND (' . db_string_equal_to('topic', $topic_identifier) . ' OR topic LIKE \'%: #' . db_encode_like($topic_identifier) . '\')');
 }
Example #30
0
 /**
  * Standard modular entry function to get rows for selection from.
  *
  * @param  boolean		Whether to force a recache
  * @param  ?ID_TEXT		Order to use (NULL: automatic)
  * @param  ?array			Extra where clauses (NULL: none)
  * @param  boolean		Whether to always access using the site database
  * @param  string			Extra join clause for our query (blank: none)
  * @return array			A pair: Rows for selection from, Total results
  */
 function get_entry_rows($recache = false, $orderer = NULL, $where = NULL, $force_site_db = false, $join = '')
 {
     if (!$recache && !is_null($orderer) && !is_null($where)) {
         if (isset($this->cached_entry_rows)) {
             return array($this->cached_entry_rows, $this->cached_max_rows);
         }
     }
     $orderer_is_multi_lang = $this->orderer_is_multi_lang;
     if (is_null($orderer_is_multi_lang)) {
         $orderer_is_multi_lang = $this->title_is_multi_lang;
     }
     $select_field = !is_null($this->orderer) ? $this->orderer : $this->table_prefix . strtolower($this->select_name);
     if (is_null($orderer)) {
         $orderer = $select_field;
     }
     $table = (is_null($this->table) ? $this->module_type : $this->table) . ' r';
     $db = substr($table, 0, 2) == 'f_' && !$force_site_db && get_forum_type() != 'none' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
     if ($orderer_is_multi_lang && preg_replace('# (ASC|DESC)$#', '', $orderer) == $select_field) {
         $table .= ' LEFT JOIN ' . $db->get_table_prefix() . 'translate t ON t.id=r.' . preg_replace('# (ASC|DESC)$#', '', $orderer) . ' AND ' . db_string_equal_to('language', user_lang());
         $orderer = 't.text_original';
     }
     if ($force_site_db) {
         $dbs_bak = $GLOBALS['NO_DB_SCOPE_CHECK'];
         $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
     }
     $max_rows = $db->query_value($table . $join, 'COUNT(*)', $where, 'ORDER BY ' . $orderer);
     if ($max_rows == 0) {
         return array(array(), 0);
     }
     $start = get_param_integer('start', 0);
     $max = get_param_integer('max', 20);
     $rows = $db->query_select($table . $join, array('r.*'), $where, 'ORDER BY ' . $orderer, $max, $start);
     if ($force_site_db) {
         $GLOBALS['NO_DB_SCOPE_CHECK'] = $dbs_bak;
     }
     $_entries = array();
     foreach ($rows as $row) {
         $key = $row[$this->array_key];
         $readable = $orderer_is_multi_lang ? get_translated_text($row[$select_field], $db) : $row[$select_field];
         if (is_integer($readable)) {
             $readable = '#' . strval($readable);
         }
         if ($readable == '') {
             $readable = do_lang('_DEFAULT');
         }
         $row['_readable'] = $readable;
         $_entries[$key] = $row;
     }
     if (!is_null($orderer) && !is_null($where)) {
         $this->cached_entry_rows = $_entries;
         $this->cached_max_rows = $max_rows;
     }
     return array($_entries, $max_rows);
 }