Example #1
0
/**
 * Get hidden fields for a form representing 'keep_x'. If we are having a GET form instead of a POST form, we need to do this. This function also encodes the page name, as we'll always want that.
 *
 * @param  ID_TEXT		The page for the form to go to (blank: don't attach)
 * @param  boolean		Whether to keep all elements of the current URL represented in this form (rather than just the keep_ fields, and page)
 * @param  ?array			A list of parameters to exclude (NULL: don't exclude any)
 * @return tempcode		The builtup hidden form fields
 */
function _build_keep_form_fields($page = '', $keep_all = false, $exclude = NULL)
{
    if (is_null($exclude)) {
        $exclude = array();
    }
    if ($page == '_SELF') {
        $page = get_page_name();
    }
    $out = new ocp_tempcode();
    if (count($_GET) > 0) {
        foreach ($_GET as $key => $val) {
            if (!is_string($val)) {
                continue;
            }
            if (get_magic_quotes_gpc()) {
                $val = stripslashes($val);
            }
            if ((substr($key, 0, 5) == 'keep_' || $keep_all) && !in_array($key, $exclude) && $key != 'page' && !skippable_keep($key, $val)) {
                $out->attach(form_input_hidden($key, $val));
            }
        }
    }
    if ($page != '') {
        $out->attach(form_input_hidden('page', $page));
    }
    return $out;
}
Example #2
0
 /**
  * Standard modular run function for snippet hooks. Generates XHTML to insert into a page using AJAX.
  *
  * @return tempcode  The snippet
  */
 function run()
 {
     if (get_option('is_on_rating') == '0') {
         return do_lang_tempcode('INTERNAL_ERROR');
     }
     // Has there actually been any rating?
     if (strtoupper(ocp_srv('REQUEST_METHOD')) == 'POST' || ocp_srv('HTTP_REFERER') == '') {
         $rating = either_param_integer('rating', NULL);
     } else {
         $rating = post_param_integer('rating');
         // Will fail
     }
     $content_type = get_param('content_type');
     $type = get_param('type', '');
     $content_id = get_param('id');
     $content_url = get_param('content_url', '', true);
     $content_title = get_param('content_title', '', true);
     require_code('feedback');
     actualise_specific_rating($rating, get_page_name(), get_member(), $content_type, $type, $content_id, $content_url, $content_title);
     actualise_give_rating_points();
     $template = get_param('template', NULL);
     if ($template !== '') {
         if (is_null($template)) {
             $template = 'RATING_BOX';
         }
         return display_rating($content_url, $content_title, $content_type, $content_id, $template);
     }
     return do_lang_tempcode('THANKYOU_FOR_RATING_SHORT');
 }
Example #3
0
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     // The counter we're using
     $name = array_key_exists('param', $map) ? $map['param'] : '';
     if ($name == '-') {
         $name = get_page_name() . ':' . get_param('type', 'misc') . ':' . get_param('id', '');
     }
     if ($name == '') {
         $name = 'hits';
     }
     $start = array_key_exists('start', $map) ? intval($map['start']) : 0;
     // Set it if it's not already
     $_current_value = get_value($name);
     if (is_null($_current_value)) {
         set_value($name, strval($start));
         $current_value = $start;
     } else {
         $current_value = intval($_current_value);
         if ($start > $current_value) {
             $current_value = $start;
             set_value($name, strval($current_value));
         }
     }
     // Hit counter?
     $hit_count = array_key_exists('hit_count', $map) ? intval($map['hit_count']) : 1;
     if ($hit_count == 1) {
         update_stat($name, 1);
     }
     return do_template('MAIN_COUNT', array('NAME' => $name, 'VALUE' => strval($current_value)));
 }
Example #4
0
/**
 * Extend breadcrumbs for the Admin Zone (called by breadcrumbs_get_default_stub).
 *
 * @param  tempcode		Reference to the breadcrumbs stub we're assembling
 */
function adminzone_extend_breadcrumbs(&$stub)
{
    global $BREADCRUMB_SET_PARENTS;
    if (count($BREADCRUMB_SET_PARENTS) > 0 && !is_object($BREADCRUMB_SET_PARENTS[0][0])) {
        // Works by finding where our oldest ancestor connects on to the do-next menus, and carries from there
        list($zone, $attributes, ) = page_link_decode($BREADCRUMB_SET_PARENTS[0][0]);
        $type = array_key_exists('type', $attributes) ? $attributes['type'] : 'misc';
        $page = $attributes['page'];
        if ($page == '_SELF') {
            $page = get_page_name();
        }
        if ($zone == '_SEARCH') {
            $zone = get_module_zone($page);
        }
        if ($zone == '_SELF') {
            $zone = get_zone_name();
        }
    } else {
        // Works by finding where we connect on to the do-next menus, and carries from there
        $type = get_param('type', 'misc');
        $page = get_page_name();
        $zone = get_zone_name();
    }
    if ($page != 'admin' && $page != 'cms') {
        // Loop over menus, hunting for connection
        $hooks = find_all_hooks('systems', 'do_next_menus');
        $_hooks = array();
        $page_looking = $page;
        $page_looking = preg_replace('#^(cms|admin)\\_#', '', $page_looking);
        if (array_key_exists($page_looking, $hooks)) {
            $_hooks[$page_looking] = $hooks[$page_looking];
            unset($hooks[$page_looking]);
            $hooks = array_merge($_hooks, $hooks);
        }
        foreach ($hooks as $hook => $sources_dir) {
            $run_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/do_next_menus/' . $hook . '.php', array('run'));
            if ($run_function[0] !== NULL) {
                $info = is_array($run_function[0]) ? call_user_func_array($run_function[0][0], $run_function[0][1]) : eval($run_function[0]);
                foreach ($info as $i) {
                    if ($i === NULL) {
                        continue;
                    }
                    if ($page == $i[2][0] && (!array_key_exists('type', $i[2][1]) && $type == 'misc' || array_key_exists('type', $i[2][1]) && ($type == $i[2][1]['type'] || $i[2][1]['type'] == 'misc')) && $zone == $i[2][2]) {
                        if ($i[0] == 'cms') {
                            $url = build_url(array('page' => 'cms', 'type' => $i[0] == 'cms' ? NULL : $i[0]), 'cms');
                        } else {
                            $url = build_url(array('page' => 'admin', 'type' => $i[0]), 'adminzone');
                        }
                        require_lang('menus');
                        require_lang('security');
                        $stub->attach(hyperlink($url, do_lang_tempcode(strtoupper($i[0])), false, false, do_lang_tempcode('GO_BACKWARDS_TO', @html_entity_decode(strip_tags(do_lang(strtoupper($i[0]))), ENT_QUOTES, get_charset()))));
                        //if ((!array_key_exists('type',$i[2][1])) || ($type==$i[2][1]['type'])) break;
                        return;
                    }
                }
            }
        }
    }
}
Example #5
0
/**
 * Parse the text to transform variable.
 *
 * @param string $sContent The text.
 * @return string The text parsed.
 */
function parse_var($sContent)
{
    $sContent = str_replace('{site_url}', RELATIVE, $sContent);
    $sContent = str_replace('{static_url}', STATIC_URL, $sContent);
    $sContent = str_replace('{lang}', LANG, $sContent);
    $sContent = str_replace('{tpl_name}', TPL, $sContent);
    $sContent = str_replace('{site_name}', SITE_NAME, $sContent);
    $sContent = str_replace('{page_name}', get_page_name(), $sContent);
    $sContent = str_replace('{menu_links}', get_links_html(), $sContent);
    $sContent = str_replace('{menu_langs}', get_langs_html(), $sContent);
    $sContent = str_replace('{year}', date('Y'), $sContent);
    return $sContent;
}
Example #6
0
 function auth_set($member_id, $oauth_url)
 {
     require_lang('facebook');
     require_code('facebook_connect');
     global $FACEBOOK_CONNECT;
     $code = get_param('code', '', true);
     if ($code == '') {
         $oauth_redir_url = $FACEBOOK_CONNECT->getLoginUrl(array('redirect_uri' => $oauth_url->evaluate(), 'scope' => array('publish_stream')));
         header('Location: ' . $oauth_redir_url);
         exit;
     }
     if (!is_null(get_param('error_reason', NULL))) {
         attach_message(do_lang_tempcode('FACEBOOK_OAUTH_FAIL', escape_html(get_param('error_reason'))), 'warn');
         return false;
     }
     // oauth apparently worked
     $access_token = $FACEBOOK_CONNECT->getAccessToken();
     if (is_null($access_token)) {
         attach_message(do_lang_tempcode('FACEBOOK_OAUTH_FAIL', escape_html(do_lang('UNKNOWN'))), 'warn');
         return false;
     }
     if (is_null($member_id)) {
         /*$FACEBOOK_CONNECT->setExtendedAccessToken();		Facebook API no longer has this
         		$FACEBOOK_CONNECT->api('/oauth/access_token', 'POST',
         			array(
         				'grant_type'=>'fb_exchange_token',
         				'client_id'=>get_option('facebook_appid'),
         				'client_secret'=>get_option('facebook_secret_code'),
         				'fb_exchange_token'=>$access_token
         		    )
         		);*/
         if (get_option('facebook_uid') == '') {
             require_code('config2');
             $facebook_uid = $FACEBOOK_CONNECT->getUser();
             set_option('facebook_uid', strval($facebook_uid));
         }
     }
     if (strpos($access_token, '|') === false || is_null($member_id)) {
         $save_to = 'facebook_oauth_token';
         if (!is_null($member_id)) {
             $save_to .= '__' . strval($member_id);
         }
         set_long_value($save_to, $access_token);
     }
     if (get_page_name() != 'facebook_oauth') {
         header('Location: ' . str_replace('&syndicate_start__facebook=1', '', str_replace('oauth_in_progress=1&', 'oauth_in_progress=0&', $oauth_url->evaluate())));
         exit;
     }
     return true;
 }
Example #7
0
 function init__chat()
 {
     global $MEMBERS_BEFRIENDED;
     $MEMBERS_BEFRIENDED = NULL;
     global $EFFECT_SETTINGS_ROWS;
     $EFFECT_SETTINGS_ROWS = NULL;
     if (!defined('CHAT_ACTIVITY_PRUNE')) {
         define('CHAT_ACTIVITY_PRUNE', 25);
         define('CHAT_BACKLOG_TIME', 60 * 5);
         // 5 minutes of messages if you enter an existing room
         define('CHAT_EVENT_PRUNE', 60 * 24);
     }
     if (get_page_name() == 'chat') {
         require_code('developer_tools');
         destrictify(false);
     }
 }
Example #8
0
/**
 * Make a forum.
 *
 * @param  SHORT_TEXT 	The name of the forum.
 * @param  SHORT_TEXT 	The description for the forum.
 * @param  ?AUTO_LINK	What forum category the forum will be filed with (NULL: this is the root forum).
 * @param  ?array			Permission map (NULL: do it the standard way, outside of this function). This parameter is for import/compatibility only and works upon an emulation of 'access levels' (ala ocPortal 2.5/2.6), and it is recommended to use the normal aed_module functionality for permissions setting.
 * @param  ?AUTO_LINK 	The ID of the parent forum (NULL: this is the root forum).
 * @param  integer		The position of this forum relative to other forums viewable on the same screen (if parent forum hasn't specified automatic ordering).
 * @param  BINARY			Whether post counts will be incremented if members post in the forum.
 * @param  BINARY			Whether the ordering of subforums is done automatically, alphabetically).
 * @param  LONG_TEXT		The question that is shown for newbies to the forum (blank: none).
 * @param  SHORT_TEXT	The answer to the question (blank: no specific answer.. if there's a 'question', it just requires a click-through).
 * @param  SHORT_TEXT	Either blank for no redirection, the ID of another forum we are mirroring, or a URL to redirect to.
 * @param  ID_TEXT		The order the topics are shown in, by default.
 * @param  BINARY			Whether the forum is threaded.
 * @return AUTO_LINK		The ID of the newly created forum.
 */
function ocf_make_forum($name, $description, $category_id, $access_mapping, $parent_forum, $position = 1, $post_count_increment = 1, $order_sub_alpha = 0, $intro_question = '', $intro_answer = '', $redirection = '', $order = 'last_post', $is_threaded = 0)
{
    if ($category_id == -1) {
        $category_id = NULL;
    }
    if ($parent_forum == -1) {
        $parent_forum = NULL;
    }
    if (get_page_name() != 'admin_import') {
        if (!is_null($category_id) && function_exists('ocf_ensure_category_exists')) {
            ocf_ensure_category_exists($category_id);
        }
        if (!is_null($parent_forum) && function_exists('ocf_ensure_forum_exists')) {
            ocf_ensure_forum_exists($parent_forum);
        }
    }
    $forum_id = $GLOBALS['FORUM_DB']->query_insert('f_forums', array('f_name' => $name, 'f_description' => insert_lang($description, 2, $GLOBALS['FORUM_DB']), 'f_category_id' => $category_id, 'f_parent_forum' => $parent_forum, 'f_position' => $position, 'f_order_sub_alpha' => $order_sub_alpha, 'f_post_count_increment' => $post_count_increment, 'f_intro_question' => insert_lang($intro_question, 3, $GLOBALS['FORUM_DB']), 'f_intro_answer' => $intro_answer, 'f_cache_num_topics' => 0, 'f_cache_num_posts' => 0, 'f_cache_last_topic_id' => NULL, 'f_cache_last_forum_id' => NULL, 'f_cache_last_title' => '', 'f_cache_last_time' => NULL, 'f_cache_last_username' => '', 'f_cache_last_member_id' => NULL, 'f_redirection' => $redirection, 'f_order' => $order, 'f_is_threaded' => $is_threaded), true);
    // Set permissions
    if (!is_null($access_mapping)) {
        $groups = $GLOBALS['OCF_DRIVER']->get_usergroup_list(false, true);
        foreach (array_keys($groups) as $group_id) {
            $level = 0;
            // No-access
            if (array_key_exists($group_id, $access_mapping)) {
                $level = $access_mapping[$group_id];
            }
            if ($level >= 1) {
                $GLOBALS['FORUM_DB']->query_insert('group_category_access', array('module_the_name' => 'forums', 'category_name' => strval($forum_id), 'group_id' => $group_id));
                if ($level == 1) {
                    $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'submit_lowrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 0));
                    $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'submit_midrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 0));
                }
                if ($level >= 3) {
                    $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'bypass_validation_lowrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 1));
                }
                if ($level >= 4) {
                    $GLOBALS['FORUM_DB']->query_insert('gsp', array('specific_permission' => 'bypass_validation_midrange_content', 'group_id' => $group_id, 'the_page' => '', 'module_the_name' => 'forums', 'category_name' => strval($forum_id), 'the_value' => 1));
                }
                // 2=May post, [3=May post instantly , 4=May start topics instantly , 5=Moderator  --  these ones will not be treated specially, so as to avoid overriding permissions unnecessary - let the admins configure it optimally manually]
            }
        }
    }
    log_it('ADD_FORUM', strval($forum_id), $name);
    return $forum_id;
}
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     $page = array_key_exists('param', $map) && $map['param'] != '' ? $map['param'] : get_page_name();
     $zone = array_key_exists('zone', $map) ? $map['zone'] : post_param('zone', get_comcode_zone($page, false));
     if ($zone == '_SEARCH') {
         $zone = NULL;
     }
     $qmap = array('p_parent_page' => $page);
     if (!is_null($zone)) {
         $qmap['the_zone'] = $zone;
     }
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $qmap['p_validated'] = 1;
     }
     $children = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('the_page', 'the_zone'), $qmap);
     foreach ($children as $i => $child) {
         $_title = $GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages', 'cc_page_title', array('the_page' => $child['the_page'], 'the_zone' => $child['the_zone']));
         if (!is_null($_title)) {
             $title = get_translated_text($_title, NULL, NULL, true);
             if (is_null($title)) {
                 $title = '';
             }
         } else {
             $title = '';
             if (get_option('is_on_comcode_page_cache') == '1') {
                 request_page($child['the_page'], false, $child['the_zone'], NULL, true);
                 $_title = $GLOBALS['SITE_DB']->query_value_null_ok('cached_comcode_pages', 'cc_page_title', array('the_page' => $child['the_page'], 'the_zone' => $child['the_zone']));
                 if (!is_null($_title)) {
                     $title = get_translated_text($_title);
                 }
             }
         }
         if ($title == '') {
             $title = escape_html(ucwords(str_replace('_', ' ', $child['the_page'])));
         }
         $child['TITLE'] = $title;
         $child['PAGE'] = $child['the_page'];
         $child['ZONE'] = $child['the_zone'];
         $children[$i] = $child;
     }
     $GLOBALS['M_SORT_KEY'] = 'TITLE';
     usort($children, 'multi_sort');
     return do_template('BLOCK_MAIN_COMCODE_PAGE_CHILDREN', array('_GUID' => '375aa1907fc6b2ca6b23ab5b5139aaef', 'CHILDREN' => $children, 'THE_PAGE' => $page, 'THE_ZONE' => $zone));
 }
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('page', $map)) {
         $map['page'] = get_page_name();
     }
     if (array_key_exists('id', $map)) {
         $id = $map['id'];
     } else {
         $id = get_param('id', '0');
     }
     require_code('feedback');
     //$self_url=get_self_url();
     //$self_title=$map['page'];
     /*$test_changed=post_param('title','');
     		if ($test_changed!='')
     		{
     			decache('main_trackbacks');
     		}*/
     //actualise_post_trackbacks(1,'block_main_trackbacks',$map['page'].'_'.$map['param'].$extra,$self_url,$self_title);
     actualise_post_trackback(get_option('is_on_trackbacks') == '1', $map['page'], $id);
     return get_trackbacks($map['page'], $id, get_option('is_on_trackbacks') == '1');
 }
Example #11
0
function check_login()
{
    // Detect pages where it should redirect to homepage or login page
    $page_name = get_page_name();
    if (isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == true) {
        if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])) {
            // Cast the user_id to int, and check if it is an int
            // Casting to int (multiplying by int)
            if (is_int((int) $_SESSION['user_id'])) {
                // The user is logged in
                $loggedin = true;
                if ($page_name == "login.php") {
                    redirect_to("index.php");
                }
            }
        }
    }
    if (!isset($loggedin) && $page_name != "login.php") {
        // User is not logged in
        redirect_to("login.php");
    }
}
Example #12
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'] = 'main';
     }
     if (!array_key_exists('page', $map)) {
         $map['page'] = get_page_name();
     }
     if (array_key_exists('extra_param_from', $map)) {
         $extra = '_' . $map['extra_param_from'];
     } else {
         $extra = '';
     }
     require_code('feedback');
     $self_url = get_self_url();
     $self_title = $map['page'];
     $id = $map['page'] . '_' . $map['param'] . $extra;
     $test_changed = post_param('rating_' . $id, '');
     if ($test_changed != '') {
         decache('main_rating');
     }
     actualise_rating(true, 'block_main_rating', $id, $self_url, $self_title);
     return get_rating_box($self_url, $self_title, 'block_main_rating', $id, true);
 }
Example #13
0
/**
 * Check to see if a member deserves promotion, and handle it.
 *
 * @param  ?MEMBER	The member (NULL: current member).
 */
function ocf_member_handle_promotion($member_id = NULL)
{
    if (!addon_installed('points')) {
        return;
    }
    if (get_page_name() == 'admin_import') {
        return;
    }
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    require_code('ocf_members');
    if (ocf_is_ldap_member($member_id)) {
        return;
    }
    require_code('points');
    $total_points = total_points($member_id);
    $groups = $GLOBALS['OCF_DRIVER']->get_members_groups($member_id, false, true);
    $or_list = '';
    foreach ($groups as $id) {
        if ($or_list != '') {
            $or_list .= ' OR ';
        }
        $or_list .= 'id=' . strval($id);
    }
    $promotions = $GLOBALS['FORUM_DB']->query('SELECT id,g_promotion_target FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_groups WHERE (' . $or_list . ') AND g_promotion_target IS NOT NULL AND g_promotion_threshold<=' . strval((int) $total_points) . ' ORDER BY g_promotion_threshold');
    $promotes_today = array();
    foreach ($promotions as $promotion) {
        $_p = $promotion['g_promotion_target'];
        if (!array_key_exists($_p, $groups) && !array_key_exists($_p, $promotes_today)) {
            // If it is our primary
            if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_primary_group') == $promotion['id']) {
                $GLOBALS['FORUM_DB']->query_update('f_members', array('m_primary_group' => $_p), array('id' => $member_id), '', 1);
            } else {
                $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $_p), '', 1);
                $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_validated' => 1, 'gm_member_id' => $member_id, 'gm_group_id' => $_p), false, true);
                $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $promotion['id']), '', 1);
                // It's a transition, so remove old membership
            }
            // Carefully update run-time cacheing
            global $USERS_GROUPS_CACHE;
            foreach (array(true, false) as $a) {
                foreach (array(true, false) as $b) {
                    if (isset($USERS_GROUPS_CACHE[$member_id][$a][$b])) {
                        $groups = $USERS_GROUPS_CACHE[$member_id][$a][$b];
                        $pos = array_search($_p, $groups);
                        if ($pos !== false) {
                            unset($groups[$pos]);
                        }
                        $groups[] = $promotion['id'];
                        $USERS_GROUPS_CACHE[$member_id][$a][$b] = $groups;
                    }
                }
            }
            $promotes_today[$_p] = 1;
        }
    }
    if (count($promotes_today) != 0) {
        $name = $GLOBALS['OCF_DRIVER']->get_member_row_field($member_id, 'm_username');
        log_it('MEMBER_PROMOTED_AUTOMATICALLY', strval($member_id), $name);
    }
}
Example #14
0
function handle_facebook_connection_login($current_logged_in_member)
{
    if (!class_exists('ocp_tempcode')) {
        return NULL;
    }
    if (is_guest($current_logged_in_member)) {
        $current_logged_in_member = NULL;
        // We are not a normal cookie login so ocPortal has loaded up a Guest session already in the expectation of keeping it. Unsetting it will force a rebind (existing session may be reused though)
        require_code('users_inactive_occasionals');
        set_session_id(-1);
    }
    // If already session-logged-in onto a Facebook account, don't bother doing anything
    if (!is_null($current_logged_in_member) && $GLOBALS['FORUM_DRIVER']->get_member_row_field($current_logged_in_member, 'm_password_compat_scheme') == 'facebook') {
        return $current_logged_in_member;
    }
    // Who is this user, from Facebook's point of view?
    global $FACEBOOK_CONNECT;
    $facebook_uid = $FACEBOOK_CONNECT->getUser();
    if (is_null($facebook_uid)) {
        return $current_logged_in_member;
    }
    try {
        $details = $FACEBOOK_CONNECT->api('/me');
    } catch (Exception $e) {
        return $current_logged_in_member;
    }
    $details2 = $FACEBOOK_CONNECT->api('/me', array('fields' => 'picture', 'type' => 'normal'));
    if (!is_array($details) || !is_array($details2)) {
        return $current_logged_in_member;
    }
    $details = array_merge($details, $details2);
    if (!isset($details['name'])) {
        return $current_logged_in_member;
    }
    $username = $details['name'];
    $photo_url = array_key_exists('picture', $details) ? $details['picture'] : '';
    if (is_array($photo_url)) {
        $photo_url = $photo_url['data']['url'];
    }
    if ($photo_url != '') {
        $photo_url = 'http://graph.facebook.com/' . strval($facebook_uid) . '/picture?type=large';
        // In case URL changes
    }
    $avatar_url = $photo_url == '' ? mixed() : $photo_url;
    $photo_thumb_url = '';
    if ($photo_url != '') {
        $photo_thumb_url = $photo_url;
    }
    $email_address = array_key_exists('email', $details) ? $details['email'] : '';
    $timezone = mixed();
    if (isset($details['timezone'])) {
        require_code('temporal');
        $timezone = convert_timezone_offset_to_formal_timezone($details['timezone']);
    }
    $language = mixed();
    if (isset($details['locale'])) {
        $language = strtoupper($details['locale']);
    }
    if ($language !== NULL) {
        if (!file_exists(get_custom_file_base() . '/lang_custom/' . $language)) {
            $language = preg_replace('#\\_.*$#', '', $language);
            if (!file_exists(get_custom_file_base() . '/lang_custom/' . $language)) {
                $language = '';
            }
        }
    }
    $dob = array_key_exists('birthday', $details) ? $details['birthday'] : '';
    $dob_day = mixed();
    $dob_month = mixed();
    $dob_year = mixed();
    if ($dob != '') {
        $_dob = explode('/', $dob);
        $dob_day = intval($_dob[1]);
        $dob_month = intval($_dob[0]);
        $dob_year = intval($_dob[2]);
    }
    // See if they have logged in before - i.e. have a synched account
    $member_row = $GLOBALS['FORUM_DB']->query_select('f_members', array('*'), array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => $facebook_uid), 'ORDER BY id DESC', 1);
    $member = array_key_exists(0, $member_row) ? $member_row[0]['id'] : NULL;
    if (is_guest($member)) {
        $member = NULL;
    }
    /*if (!is_null($member)) // Useful for debugging
    	{
    		require_code('ocf_members_action2');
    		ocf_delete_member($member);
    		$member=NULL;
    	}*/
    // If logged in before using Facebook, see if they've changed their name or email or timezone on Facebook -- if so, try and update locally to match
    if (!is_null($member)) {
        if (!is_null($current_logged_in_member) && $current_logged_in_member !== NULL && !is_guest($current_logged_in_member) && $current_logged_in_member != $member) {
            return $current_logged_in_member;
        }
        // User has an active login, and the Facebook account is bound to a DIFFERENT login. Take precedence to the other login that is active on top of this
        $last_visit_time = $member[0]['m_last_visit_time'];
        if ($timezone !== NULL) {
            if (tz_time(time(), $timezone) == tz_time(time(), $member[0]['m_timezone_offset'])) {
                $timezone = $member[0]['m_timezone_offset'];
            }
            // If equivalent, don't change
        }
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $username));
        if (!is_null($test)) {
            $update_map = array('m_username' => $username, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year);
            if ($email_address != '') {
                $update_map['m_email_address'] = $email_address;
            }
            if ($avatar_url !== NULL && ($test == '' || strpos($test, 'facebook') !== false || strpos($test, 'fbcdn') !== false)) {
                if ($timezone !== NULL) {
                    $update_map['m_timezone_offset'] = $timezone;
                }
                $update_map['m_avatar_url'] = $avatar_url;
                $update_map['m_photo_url'] = $photo_url;
                $update_map['m_photo_thumb_url'] = $photo_thumb_url;
            }
            $GLOBALS['FORUM_DB']->query_update('f_members', $update_map, array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => strval($facebook_uid)), '', 1);
            if ($username != $member[0]['m_username']) {
                // Fix cacheing for usernames
                $to_fix = array('f_forums/f_cache_last_username', 'f_posts/p_poster_name_if_guest', 'f_topics/t_cache_first_username', 'f_topics/t_cache_last_username');
                foreach ($to_fix as $fix) {
                    list($table, $field) = explode('/', $fix);
                    $GLOBALS['FORUM_DB']->query_update($table, array($field => $username), array($field => $member[0]['m_username']));
                }
            }
        }
    }
    // Not logged in before using Facebook, so we need to create an account, or bind to the active ocPortal login if there is one
    $in_a_sane_place = get_page_name() != 'login' && (running_script('index') || running_script('execute_temp'));
    // If we're in some weird script, or the login module UI, it's not a sane place, don't be doing account creation yet
    if (is_null($member) && $in_a_sane_place) {
        // Bind to existing ocPortal login?
        if (!is_null($current_logged_in_member)) {
            /*if (post_param_integer('associated_confirm',0)==0)		Won't work because Facebook is currently done in JS and cookies force this. If user wishes to cancel they must go to http://www.facebook.com/settings?tab=applications and remove the app, then run a lost password reset.
            		{
            			$title=get_page_title('LOGIN_FACEBOOK_HEADER');
            			$message=do_lang_tempcode('LOGGED_IN_SURE_FACEBOOK',escape_html($GLOBALS['FORUM_DRIVER']->get_username($current_logged_in_member)));
            			$middle=do_template('YESNO_SCREEN',array('TITLE'=>$title,'TEXT'=>$message,'HIDDEN'=>form_input_hidden('associated_confirm','1'),'URL'=>get_self_url_easy()));
            			$tpl=globalise($middle,NULL,'',true);
            			$tpl->evaluate_echo();
            			exit();
            		}*/
            $GLOBALS['FORUM_DB']->query_update('f_members', array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => $facebook_uid), array('id' => $current_logged_in_member), '', 1);
            require_code('site');
            require_lang('facebook');
            attach_message(do_lang_tempcode('FACEBOOK_ACCOUNT_CONNECTED', escape_html(get_site_name()), escape_html($GLOBALS['FORUM_DRIVER']->get_username($current_logged_in_member)), array(escape_html($username))), 'inform');
            return $current_logged_in_member;
        }
        // If we're still here, we have to create a new account...
        // -------------------------------------------------------
        $completion_form_submitted = post_param('email_address', '') != '';
        // If there's a conflicting username, we may need to change it (suffix a number)
        require_code('ocf_members_action2');
        $username = get_username_from_human_name($username);
        // Ask ocP to finish off the profile from the information presented in the POST environment (a standard mechanism in ocPortal, for third party logins of various kinds)
        require_lang('ocf');
        require_code('ocf_members');
        require_code('ocf_groups');
        require_code('ocf_members2');
        require_code('ocf_members_action');
        $_custom_fields = ocf_get_all_custom_fields_match(ocf_get_all_default_groups(true), NULL, NULL, NULL, 1);
        if (!$completion_form_submitted && count($_custom_fields) != 0 && get_value('no_finish_profile') !== '1') {
            $GLOBALS['FACEBOOK_FINISHING_PROFILE'] = true;
            $middle = ocf_member_external_linker_ask($username, 'facebook', $email_address, $dob_day, $dob_month, $dob_year);
            $tpl = globalise($middle, NULL, '', true);
            $tpl->evaluate_echo();
            exit;
        } else {
            $username = post_param('username', $username);
            if (count($_custom_fields) != 0 && get_value('no_finish_profile') !== '1') {
                // Was not auto-generated, so needs to be checked
                ocf_check_name_valid($username, NULL, NULL);
            }
            $member = ocf_member_external_linker($username, $facebook_uid, 'facebook', false, $email_address, $dob_day, $dob_month, $dob_year, $timezone, $language, $avatar_url, $photo_url, $photo_thumb_url);
        }
    }
    if (!is_null($member)) {
        require_code('users_inactive_occasionals');
        create_session($member, 1, isset($_COOKIE[get_member_cookie() . '_invisible']) && $_COOKIE[get_member_cookie() . '_invisible'] == '1');
        // This will mark it as confirmed
    }
    return $member;
}
Example #15
0
/**
 * Look at the user's browser, and decide if they are viewing on a mobile device or not.
 *
 * @param  ?string		The user agent (NULL: get from environment, current user's browser)
 * @param  boolean		Whether to always tell the truth (even if the current page does not have mobile support)
 * @return boolean		Whether the user is using a mobile device
 */
function is_mobile($user_agent = NULL, $truth = false)
{
    $user_agent_given = $user_agent !== NULL;
    if ($user_agent === NULL) {
        $user_agent = ocp_srv('HTTP_USER_AGENT');
    }
    global $IS_MOBILE, $IS_MOBILE_TRUTH;
    if (!$user_agent_given) {
        if (($truth ? $IS_MOBILE_TRUTH : $IS_MOBILE) !== NULL) {
            return $truth ? $IS_MOBILE_TRUTH : $IS_MOBILE;
        }
    }
    if (!function_exists('get_option') || get_option('mobile_support') == '0') {
        $IS_MOBILE = false;
        $IS_MOBILE_TRUTH = false;
        return false;
    }
    global $SITE_INFO;
    if ((!isset($SITE_INFO['assume_full_mobile_support']) || $SITE_INFO['assume_full_mobile_support'] == '0') && isset($GLOBALS['FORUM_DRIVER']) && !$truth && running_script('index') && ($theme = $GLOBALS['FORUM_DRIVER']->get_theme()) != 'default') {
        $ini_path = ($theme == 'default' ? get_file_base() : get_custom_file_base()) . '/themes/' . $theme . '/theme.ini';
        if (is_file($ini_path)) {
            require_code('files');
            $details = better_parse_ini_file($ini_path);
            if (isset($details['mobile_pages']) && $details['mobile_pages'] != '' && preg_match('#(^|,)\\s*' . str_replace('#', '\\#', preg_quote(get_page_name())) . '\\s*(,|$)#', $details['mobile_pages']) == 0) {
                $IS_MOBILE = false;
                return false;
            }
        }
    }
    if (!$user_agent_given) {
        $val = get_param_integer('keep_mobile', NULL);
        if ($val !== NULL) {
            if (isset($GLOBALS['FORUM_DRIVER'])) {
                $IS_MOBILE = $val == 1;
            }
            $IS_MOBILE_TRUTH = $IS_MOBILE;
            return $IS_MOBILE;
        }
    }
    // The set of browsers
    $browsers = array('WML', 'WAP', 'Wap', 'MIDP', 'Mobile', 'Smartphone', 'WebTV', 'Minimo', 'Fennec', 'Mobile Safari', 'Android', 'lynx', 'Links', 'iPhone', 'iPod', 'Opera Mobi', 'Opera Mini', 'BlackBerry', 'Windows Phone', 'Windows CE', 'Symbian', 'nook browser', 'Blazer', 'PalmOS', 'webOS', 'SonyEricsson', 'Nintendo', 'PlayStation Portable', 'UP.Browser', 'UP.Link', 'NetFront', 'Teleca', 'UCWEB', 'DDIPOCKET', 'SEMC-Browser', 'DoCoMo', 'Xda', 'ReqwirelessWeb', 'AvantGo');
    $exceptions = array('iPad');
    if ((!isset($SITE_INFO['no_extra_mobiles']) || $SITE_INFO['no_extra_mobiles'] == '0') && is_file(get_file_base() . '/text_custom/pdas.txt')) {
        require_code('files');
        $pdas = better_parse_ini_file(get_file_base() . '/text_custom/pdas.txt');
        foreach ($pdas as $key => $val) {
            if ($val == 1) {
                $browsers[] = $key;
            } else {
                $exceptions[] = $key;
            }
        }
    }
    // The test
    $result = preg_match('/(' . implode('|', $browsers) . ')/i', $user_agent) != 0 && preg_match('/(' . implode('|', $exceptions) . ')/i', $user_agent) == 0;
    if (!$user_agent_given) {
        if (isset($GLOBALS['FORUM_DRIVER'])) {
            $IS_MOBILE = $result;
            $IS_MOBILE_TRUTH = $IS_MOBILE;
        }
    }
    return $result;
}
Example #16
0
/**
 * Certain symbols need preprocessing, before the output stream is made.
 *
 * @param  array			Symbol details
 * @param  array			Where we store children stuff
 */
function handle_symbol_preprocessing($bit, &$children)
{
    switch ($bit[2]) {
        case 'PAGE_LINK':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            if (array_key_exists(0, $param)) {
                if (is_object($param[0])) {
                    $param[0] = $param[0]->evaluate();
                }
                list(, $url_parts, ) = page_link_decode(str_replace(chr(10), '', $param[0]));
                if (!array_key_exists('id', $url_parts)) {
                    return;
                }
                if (!array_key_exists('type', $url_parts)) {
                    $url_parts['type'] = 'misc';
                }
                if (is_null($url_parts['type'])) {
                    $url_parts['type'] = 'misc';
                }
                // NULL means "do not take from environment"; so we default it to 'misc' (even though it might actually be left out when SEO URLs are off, we know it cannot be for SEO URLs)
                if (!array_key_exists('page', $url_parts)) {
                    return;
                }
                if (!is_string($url_parts['id'])) {
                    if (is_null($url_parts['id'])) {
                        $url_parts['id'] = strval(db_get_first_id());
                    }
                }
                // Does this URL arrangement support monikers?
                global $CONTENT_OBS, $LOADED_MONIKERS;
                load_moniker_hooks();
                $found = false;
                $looking_for = '_SEARCH:' . $url_parts['page'] . ':' . $url_parts['type'] . ':_WILD';
                $ob_info = isset($CONTENT_OBS[$looking_for]) ? $CONTENT_OBS[$looking_for] : NULL;
                if (!is_null($ob_info)) {
                    if (!isset($LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']])) {
                        $LOADED_MONIKERS[$url_parts['page']][$url_parts['type']][$url_parts['id']] = true;
                    }
                    // Indicator to preload this
                }
            }
            return;
        case 'SET':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            if (array_key_exists(1, $param)) {
                global $TEMPCODE_SETGET;
                $param_copy = array();
                foreach ($param as $i => $x) {
                    if ($i != 0) {
                        $param_copy[] = is_object($x) ? $x->evaluate() : $x;
                    }
                }
                $TEMPCODE_SETGET[is_object($param[0]) ? $param[0]->evaluate() : $param[0]] = implode(',', $param_copy);
            }
            return;
        case 'BLOCK':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            if (count($param) == 1 && strpos($param[0], ',') !== false) {
                $param = preg_split('#((?<![^\\\\])|(?<!\\\\\\\\)|(?<!^)),#', $param[0]);
            }
            //if (strpos(serialize($param),'side_stored_menu')!==false) { @debug_print_backtrace();exit(); } // Useful for debugging
            global $REQUEST_BLOCK_NEST_LEVEL;
            global $LOADED_BLOCKS;
            if (array_key_exists(serialize($param), $LOADED_BLOCKS)) {
                $REQUEST_BLOCK_NEST_LEVEL--;
                return;
            }
            $REQUEST_BLOCK_NEST_LEVEL++;
            if ($REQUEST_BLOCK_NEST_LEVEL > 20) {
                $REQUEST_BLOCK_NEST_LEVEL = 0;
                $LOADED_BLOCKS[serialize($param)] = do_lang_tempcode('INTERNAL_ERROR');
                attach_message(do_lang_tempcode('STOPPED_RECURSIVE_RESOURCE_INCLUDE', is_string($param[0]) ? $param[0] : 'block'), 'warn');
                return;
            }
            $block_parms = array();
            foreach ($param as $_param) {
                $block_parts = explode('=', $_param, 2);
                if (count($block_parts) != 2) {
                    $LOADED_BLOCKS[serialize($param)] = new ocp_tempcode();
                    continue 2;
                }
                list($key, $val) = $block_parts;
                $block_parms[$key] = $val;
            }
            $b_value = do_block($block_parms['block'], $block_parms);
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                $children[] = array(':block: ' . $block_parms['block'], array(array($b_value->codename, $b_value->children, $b_value->fresh)), true);
            }
            $b_value->handle_symbol_preprocessing();
            $LOADED_BLOCKS[serialize($param)] = $b_value;
            $REQUEST_BLOCK_NEST_LEVEL--;
            return;
        case 'JAVASCRIPT_INCLUDE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            require_javascript($param[0]);
            return;
        case 'FACILITATE_AJAX_BLOCK_CALL':
            require_javascript('javascript_ajax');
            return;
        case 'CSS_INCLUDE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            require_css($param[0]);
            return;
        case 'LOAD_PANEL':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            global $LOADED_PANELS;
            if (array_key_exists(serialize($param), $LOADED_PANELS)) {
                return;
            }
            if (array_key_exists(0, $param)) {
                if (substr(get_page_name(), 0, 6) != 'panel_') {
                    if (strpos($param[0], ':') !== false) {
                        $param = array_reverse(explode(':', $param[0], 2));
                    }
                    if (substr($param[0], 0, 6) == 'panel_') {
                        $param[0] = substr($param[0], 6);
                    }
                    global $ZONE;
                    $wide_high = is_wide_high();
                    $wide = is_wide();
                    if (($wide == 0 || $wide_high == 0 && ($param[0] == 'bottom' || $param[0] == 'top')) && (get_option('site_closed') == '0' || $GLOBALS['IS_ACTUALLY_ADMIN'] || has_specific_permission(get_member(), 'access_closed_site'))) {
                        $tp_value = request_page('panel_' . $param[0], false, array_key_exists(1, $param) ? $param[1] : NULL, NULL);
                        $sub_children = array();
                        $tp_value->handle_symbol_preprocessing();
                        if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                            $children[] = array(':panel: ' . $param[0], $sub_children, isset($tp_value->fresh) ? $tp_value->fresh : false);
                        }
                        $value = $tp_value->evaluate();
                    } else {
                        $value = '';
                    }
                } else {
                    $value = '';
                }
            } else {
                $value = '';
            }
            $LOADED_PANELS[serialize($param)] = $value;
            return;
        case 'JS_TEMPCODE':
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                    return;
                }
                $param = $bit[3];
                foreach ($param as $i => $p) {
                    if (is_object($p)) {
                        $param[$i] = $p->evaluate();
                    }
                }
                $temp = javascript_tempcode(array_key_exists(0, $param) ? $param[0] : NULL);
                $children[] = array(':container', $temp->children, $temp->fresh);
            }
            return;
        case 'CSS_TEMPCODE':
            if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                    return;
                }
                $temp = css_tempcode();
                $children[] = array(':container', $temp->children, $temp->fresh);
            }
            return;
        case 'LOAD_PAGE':
            if (!array_key_exists(3, $bit) || is_null($bit[3])) {
                return;
            }
            $param = $bit[3];
            foreach ($param as $i => $p) {
                if (is_object($p)) {
                    $param[$i] = $p->evaluate();
                }
            }
            global $LOADED_PAGES;
            if (array_key_exists(serialize($param), $LOADED_PAGES)) {
                return;
            }
            if (array_key_exists(0, $param)) {
                if (strpos($param[0], ':') !== false) {
                    $param = array_reverse(explode(':', $param[0], 2));
                }
                $being_included = !array_key_exists(2, $param) || $param[2] == '1';
                $tp_value = request_page($param[0], false, array_key_exists(1, $param) ? $param[1] : NULL, NULL, $being_included);
                if ($GLOBALS['RECORD_TEMPLATES_TREE']) {
                    $children[] = array(':page: ' . $param[0], $tp_value->children, $tp_value->fresh);
                }
            } else {
                $tp_value = new ocp_tempcode();
            }
            $LOADED_PAGES[serialize($param)] = $tp_value;
            return;
        case 'FRACTIONAL_EDITABLE':
            require_javascript('javascript_fractional_edit');
            return;
    }
}
Example #17
0
/**
 * Find all restrictions that apply to our page/type.
 *
 * @param  ?string		The page name scoped for (NULL: current page)
 * @param  ?string		The page type scoped for (NULL: current type)
 * @return array			List of fields, each of which is a map (restriction => attributes)
 */
function load_field_restrictions($this_page = NULL, $this_type = NULL)
{
    global $FIELD_RESTRICTIONS;
    if ($FIELD_RESTRICTIONS === NULL) {
        $FIELD_RESTRICTIONS = array();
        if (function_exists('xml_parser_create')) {
            $temp = new field_restriction_loader();
            if (is_null($this_page)) {
                $this_page = get_page_name();
            }
            if (is_null($this_type)) {
                $this_type = get_param('type', array_key_exists('type', $_POST) ? $_POST['type'] : 'misc');
            }
            $temp->this_page = $this_page;
            $temp->this_type = $this_type;
            $temp->go();
        }
    }
    return $FIELD_RESTRICTIONS;
}
Example #18
0
 /**
  * Render a comment topic.
  *
  * @param  ID_TEXT		Content type to show topic for
  * @param  ID_TEXT		Content ID of content type to show topic for
  * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
  * @param  boolean		Whether the comment box will be invisible if there are not yet any comments (and you're not staff)
  * @param  ?string		The name of the forum to use (NULL: default comment forum)
  * @param  ?string		The default post to use (NULL: standard courtesy warning)
  * @param  ?mixed			The raw comment array (NULL: lookup). This is useful if we want to pass it through a filter
  * @param  boolean		Whether to skip permission checks
  * @param  boolean		Whether to reverse the posts
  * @param  ?MEMBER		User to highlight the posts of (NULL: none)
  * @param  boolean		Whether to allow ratings along with the comment (like reviews)
  * @return tempcode		The tempcode for the comment topic
  */
 function render_as_comment_topic($content_type, $content_id, $allow_comments, $invisible_if_no_comments, $forum_name, $post_warning, $preloaded_comments, $explicit_allow, $reverse, $highlight_by_user, $allow_reviews)
 {
     if (get_forum_type() == 'ocf' && !addon_installed('ocf_forum')) {
         return new ocp_tempcode();
     }
     $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum_name, $content_type . '_' . $content_id);
     // Settings we need
     $max_thread_depth = get_param_integer('max_thread_depth', intval(get_option('max_thread_depth')));
     $num_to_show_limit = get_param_integer('max_comments', intval(get_option('comments_to_show_in_thread')));
     $start = get_param_integer('start_comments', 0);
     // Load up posts from DB
     if (is_null($preloaded_comments)) {
         if (!$this->load_from_topic($topic_id, $num_to_show_limit, $start, $reverse)) {
             attach_message(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name)), 'warn');
         }
     } else {
         $this->_inject_posts_for_scoring_algorithm($preloaded_comments);
     }
     if (!$this->error) {
         if (count($this->all_posts_ordered) == 0 && $invisible_if_no_comments) {
             return new ocp_tempcode();
         }
         $may_reply = has_specific_permission(get_member(), 'comment', get_page_name());
         // Prepare review titles
         global $REVIEWS_STRUCTURE;
         if ($allow_reviews) {
             if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                 $this->set_reviews_rating_criteria($REVIEWS_STRUCTURE[$content_type]);
             } else {
                 $this->set_reviews_rating_criteria(array(''));
             }
         }
         // Load up reviews
         if (get_forum_type() == 'ocf' && $allow_reviews) {
             $all_individual_review_ratings = $GLOBALS['SITE_DB']->query_select('review_supplement', array('*'), array('r_topic_id' => $topic_id));
         } else {
             $all_individual_review_ratings = array();
         }
         $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
         // Posts
         list($posts, $serialized_options, $hash) = $this->render_posts($num_to_show_limit, $max_thread_depth, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id);
         // Pagination
         $results_browser = NULL;
         if (!$this->is_threaded && is_null($preloaded_comments)) {
             if ($this->total_posts > $num_to_show_limit) {
                 require_code('templates_results_browser');
                 $results_browser = results_browser(do_lang_tempcode('COMMENTS'), NULL, $start, 'start_comments', $num_to_show_limit, 'max_comments', $this->total_posts, NULL, NULL, true);
             }
         }
         // Environment meta data
         $this->inject_rss_url($forum_name, $content_type, $content_id);
         $this->inject_meta_data();
         // Make-a-comment form
         if ($may_reply) {
             $post_url = get_self_url();
             $form = $this->get_posting_form($content_type, $content_id, $allow_reviews, $post_url, $post_warning);
         } else {
             $form = new ocp_tempcode();
         }
         // Existing review ratings
         $reviews_rating_criteria = array();
         if (get_forum_type() == 'ocf' && $allow_reviews) {
             foreach ($this->reviews_rating_criteria as $review_title) {
                 $_rating = $GLOBALS['SITE_DB']->query_value('review_supplement', 'AVG(r_rating)', array('r_rating_type' => $review_title, 'r_topic_id' => $topic_id));
                 $rating = mixed();
                 $rating = is_null($_rating) ? NULL : $_rating;
                 $reviews_rating_criteria[] = array('REVIEW_TITLE' => $review_title, 'REVIEW_RATING' => make_string_tempcode(is_null($rating) ? '' : float_format($rating)));
                 if (!is_null($rating)) {
                     $GLOBALS['META_DATA'] += array('rating' => float_to_raw_string($rating));
                 }
             }
         }
         // Direct links to forum
         $forum_url = is_null($topic_id) ? '' : $GLOBALS['FORUM_DRIVER']->topic_url($topic_id, $forum_name, true);
         if ($GLOBALS['FORUM_DRIVER']->is_staff(get_member()) || $forum_name == get_option('comments_forum_name')) {
             $authorised_forum_url = $forum_url;
         } else {
             $authorised_forum_url = '';
         }
         // Show it all
         return do_template('COMMENTS_WRAPPER', array('_GUID' => 'a89cacb546157d34vv0994ef91b2e707', 'RESULTS_BROWSER' => $results_browser, 'TYPE' => $content_type, 'ID' => $content_id, 'REVIEW_RATING_CRITERIA' => $reviews_rating_criteria, 'FORUM_LINK' => $forum_url, 'AUTHORISED_FORUM_LINK' => $authorised_forum_url, 'FORM' => $form, 'COMMENTS' => $posts, 'HASH' => $hash, 'SERIALIZED_OPTIONS' => $serialized_options));
     }
     return new ocp_tempcode();
 }
Example #19
0
/**
 * Shows an HTML page of all attachments we can access with selection buttons.
 */
function attachment_popup_script()
{
    require_lang('comcode');
    require_javascript('javascript_editing');
    $connection = get_page_name() == 'topics' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    $members = array();
    if (!is_guest()) {
        $members[get_member()] = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
    }
    if (has_specific_permission(get_member(), 'reuse_others_attachments')) {
        $_members = $connection->query_select('attachments', array('DISTINCT a_member_id'));
        foreach ($_members as $_member) {
            $members[$_member['a_member_id']] = $GLOBALS['FORUM_DRIVER']->get_username($_member['a_member_id']);
        }
    }
    asort($members);
    $member_now = post_param_integer('member_id', get_member());
    if (!array_key_exists($member_now, $members)) {
        access_denied('REUSE_ATTACHMENT');
    }
    $list = new ocp_tempcode();
    foreach ($members as $member_id => $username) {
        $list->attach(form_input_list_entry(strval($member_id), $member_id == $member_now, $username));
    }
    $field_name = get_param('field_name', 'post');
    $keep = symbol_tempcode('KEEP', array(0, 1));
    $post_url = find_script('attachment_popup') . '?field_name=' . $field_name . $keep->evaluate();
    if (get_param('utheme', '') != '') {
        $post_url .= '&utheme=' . get_param('utheme');
    }
    $rows = $connection->query_select('attachments', array('*'), array('a_member_id' => $member_now));
    $content = new ocp_tempcode();
    foreach ($rows as $myrow) {
        $myrow['description'] = $myrow['a_description'];
        $tpl = render_attachment('attachment', array(), $myrow, uniqid('', true), get_member(), false, $connection, NULL, get_member());
        $content->attach(do_template('ATTACHMENTS_BROWSER_ATTACHMENT', array('_GUID' => '64356d30905c99325231d3bbee92128c', 'FIELD_NAME' => $field_name, 'TPL' => $tpl, 'DESCRIPTION' => $myrow['a_description'], 'DELETE_URL' => $post_url, 'ID' => strval($myrow['id']))));
    }
    $content = do_template('ATTACHMENTS_BROWSER', array('_GUID' => '7773aad46fb0bfe563a142030beb1a36', 'LIST' => $list, 'CONTENT' => $content, 'URL' => $post_url));
    global $EXTRA_HEAD;
    if (!isset($EXTRA_HEAD)) {
        $EXTRA_HEAD = new ocp_tempcode();
    }
    $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />');
    // XHTMLXHTML
    $echo = do_template('POPUP_HTML_WRAP', array('TITLE' => do_lang_tempcode('ATTACHMENT_POPUP'), 'CONTENT' => $content));
    $echo->evaluate_echo();
}
Example #20
0
 /**
  * This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available.
  *
  * @param  string			The complete SQL query
  * @param  array			A DB connection
  * @param  ?integer		The maximum number of rows to affect (NULL: no limit)
  * @param  ?integer		The start row to affect (NULL: no specification)
  * @param  boolean		Whether to output an error on failure
  * @param  boolean		Whether to get the autoincrement ID created for an insert query
  * @return ?mixed			The results (NULL: no results), or the insert ID
  */
 function db_query($query, $db, $max = NULL, $start = NULL, $fail_ok = false, $get_insert_id = false)
 {
     if (substr($query, 0, 7) == 'SELECT') {
         if (!is_null($max) && !is_null($start)) {
             $query .= ' LIMIT ' . strval(intval($start)) . ',' . strval(intval($max));
         } elseif (!is_null($max)) {
             $query .= ' LIMIT ' . strval(intval($max));
         } elseif (!is_null($start)) {
             $query .= ' LIMIT ' . strval(intval($start)) . ',30000000';
         }
     }
     $results = @sqlite_query($db, $query);
     if (($results === false || strtoupper(substr($query, 0, 7)) == 'SELECT ' && $results === true) && !$fail_ok) {
         $err = sqlite_last_error($db);
         if (function_exists('ocp_mark_as_escaped')) {
             ocp_mark_as_escaped($err);
         }
         if (!running_script('upgrader') && get_page_name() != 'admin_import') {
             if (!function_exists('do_lang') || is_null(do_lang('QUERY_FAILED', NULL, NULL, NULL, NULL, false))) {
                 fatal_exit(htmlentities('Query failed: ' . $query . ' : ' . $err));
             }
             fatal_exit(do_lang_tempcode('QUERY_FAILED', escape_html($query), $err));
         } else {
             echo htmlentities('Database query failed: ' . $query . ' [') . $err . htmlentities(']' . '<br />' . chr(10));
             return NULL;
         }
     }
     if (strtoupper(substr($query, 0, 7)) == 'SELECT ' && $results !== false && $results !== true) {
         return $this->db_get_query_rows($results);
     }
     if ($get_insert_id) {
         if (strtoupper(substr($query, 0, 7)) == 'UPDATE ') {
             return NULL;
         }
         return sqlite_last_insert_rowid($db);
     }
     return NULL;
 }
Example #21
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'] = 'main';
     }
     if (!array_key_exists('page', $map)) {
         $map['page'] = str_replace('-', '_', get_page_name());
     }
     if (array_key_exists('extra_param_from', $map)) {
         $extra = '_' . $map['extra_param_from'];
     } else {
         $extra = '';
     }
     require_code('feedback');
     $submitted = post_param_integer('_comment_form_post', 0) == 1;
     $self_url = build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true);
     $self_title = $map['page'];
     $test_changed = post_param('title', NULL);
     if (!is_null($test_changed)) {
         decache('main_comments');
     }
     $hidden = $submitted ? actualise_post_comment(true, 'block_main_comments', $map['page'] . '_' . $map['param'] . $extra, $self_url, $self_title, array_key_exists('forum', $map) ? $map['forum'] : NULL, false, NULL, get_page_name() == 'guestbook') : false;
     $out = new ocp_tempcode();
     if (array_key_exists('title', $_POST) && $hidden && $submitted) {
         $out->attach(paragraph(do_lang_tempcode('MESSAGE_POSTED'), 'dsgdgdfl;gkd09'));
         if (get_forum_type() == 'ocf') {
             if (addon_installed('unvalidated')) {
                 require_code('submit');
                 $validate_url = get_self_url(true, false, array('keep_session' => NULL));
                 $_validate_url = build_url(array('page' => 'topics', 'type' => 'validate_post', 'id' => $GLOBALS['LAST_POST_ID'], 'redirect' => $validate_url), get_module_zone('topics'), NULL, false, false, true);
                 $validate_url = $_validate_url->evaluate();
                 send_validation_request('MAKE_POST', 'f_posts', false, $GLOBALS['LAST_POST_ID'], $validate_url);
             }
         }
     }
     $invisible_if_no_comments = array_key_exists('invisible_if_no_comments', $map) && $map['invisible_if_no_comments'] == '1';
     $reverse = array_key_exists('reverse', $map) && $map['reverse'] == '1';
     $allow_reviews = !array_key_exists('reviews', $map) || $map['reviews'] == '1';
     $out->attach(get_comments('block_main_comments', true, $map['page'] . '_' . $map['param'] . $extra, $invisible_if_no_comments, array_key_exists('forum', $map) ? $map['forum'] : NULL, NULL, NULL, get_page_name() == 'guestbook', $reverse, NULL, $allow_reviews));
     return $out;
 }
Example #22
0
/**
 * Add comments to the specified resource.
 *
 * @param  boolean		Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function)
 * @param  ID_TEXT		The type (download, etc) that this commenting is for
 * @param  ID_TEXT		The ID of the type that this commenting is for
 * @param  mixed			The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode)
 * @param  ?string		The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important)
 * @param  ?string		The name of the forum to use (NULL: default comment forum)
 * @param  boolean		Whether to not require a captcha
 * @param  ?BINARY		Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver (hence is the last parameter).
 * @param  boolean		Whether to force allowance
 * @param  boolean		Whether to skip a success message
 * @param  boolean		Whether posts made should not be shared
 * @return boolean		Whether a hidden post has been made
 */
function actualise_post_comment($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $avoid_captcha = false, $validated = NULL, $explicit_allow = false, $no_success_message = false, $private = false)
{
    if (!$explicit_allow) {
        if (get_option('is_on_comments') == '0' || !$allow_comments) {
            return false;
        }
        if (!has_specific_permission(get_member(), 'comment', get_page_name())) {
            return false;
        }
    }
    if (running_script('preview')) {
        return false;
    }
    $forum_tie = get_option('is_on_strong_forum_tie') == '1';
    if (addon_installed('captcha')) {
        if (array_key_exists('post', $_POST) && $_POST['post'] != '' && !$avoid_captcha) {
            require_code('captcha');
            enforce_captcha();
        }
    }
    $post_title = post_param('title', NULL);
    if (is_null($post_title) && !$forum_tie) {
        return false;
    }
    $post = post_param('post', NULL);
    if ($post == do_lang('POST_WARNING')) {
        $post = '';
    }
    if ($post == do_lang('THREADED_REPLY_NOTICE', do_lang('POST_WARNING'))) {
        $post = '';
    }
    if ($post == '' && $post_title !== '') {
        $post = $post_title;
        $post_title = '';
    }
    if ($post === '') {
        warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post'));
    }
    if (is_null($post)) {
        $post = '';
    }
    $email = trim(post_param('email', ''));
    if ($email != '') {
        $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post);
        if (substr($body, -2) == '> ') {
            $body = substr($body, 0, strlen($body) - 2);
        }
        if (get_page_name() != 'tickets') {
            $post .= '[staff_note]';
        }
        $post .= "\n\n" . '[email subject="Re: ' . comcode_escape($post_title) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n";
        if (get_page_name() != 'tickets') {
            $post .= '[/staff_note]';
        }
    }
    $content_title = strip_comcode($content_title);
    if (is_null($forum)) {
        $forum = get_option('comments_forum_name');
    }
    $content_url_flat = is_object($content_url) ? $content_url->evaluate() : $content_url;
    $_parent_id = post_param('parent_id', '');
    $parent_id = $_parent_id == '' ? NULL : intval($_parent_id);
    $poster_name_if_guest = post_param('poster_name_if_guest', '');
    list($topic_id, $is_hidden) = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, $content_type . '_' . $content_id, get_member(), $post_title, $post, $content_title, do_lang('COMMENT'), $content_url_flat, NULL, NULL, $validated, $explicit_allow ? 1 : NULL, $explicit_allow, $poster_name_if_guest, $parent_id, false, !$private && $post != '' ? 'comment_posted' : NULL, !$private && $post != '' ? $content_type . '_' . $content_id : NULL);
    if (!is_null($topic_id)) {
        if (!is_integer($forum)) {
            $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum);
        } else {
            $forum_id = (int) $forum;
        }
        if (get_forum_type() == 'ocf' && !is_null($GLOBALS['LAST_POST_ID'])) {
            $extra_review_ratings = array();
            global $REVIEWS_STRUCTURE;
            if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) {
                $reviews_rating_criteria = $REVIEWS_STRUCTURE[$content_type];
            } else {
                $reviews_rating_criteria[] = '';
            }
            foreach ($reviews_rating_criteria as $rating_type) {
                // Has there actually been any rating?
                $rating = post_param_integer('review_rating__' . fix_id($rating_type), NULL);
                if (!is_null($rating)) {
                    if ($rating > 10 || $rating < 1) {
                        log_hack_attack_and_exit('VOTE_CHEAT');
                    }
                    $GLOBALS['SITE_DB']->query_insert('review_supplement', array('r_topic_id' => $GLOBALS['LAST_TOPIC_ID'], 'r_post_id' => $GLOBALS['LAST_POST_ID'], 'r_rating_type' => $rating_type, 'r_rating_for_type' => $content_type, 'r_rating_for_id' => $content_id, 'r_rating' => $rating));
                }
            }
        }
    }
    if (!$private && $post != '') {
        list(, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id);
        $content_type_title = $content_type;
        if (!is_null($cma_info) && isset($cma_info['content_type_label'])) {
            $content_type_title = do_lang($cma_info['content_type_label']);
        }
        // Notification
        require_code('notifications');
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $subject = do_lang('NEW_COMMENT_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title, array($post_title, $username), get_site_default_lang());
        $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
        $message_raw = do_lang('NEW_COMMENT_BODY', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array($post_title == '' ? do_lang('NO_SUBJECT') : $post_title, post_param('post'), comcode_escape($content_url_flat), comcode_escape($username)), get_site_default_lang());
        dispatch_notification('comment_posted', $content_type . '_' . $content_id, $subject, $message_raw);
        // Is the user gonna automatically enable notifications for this?
        if (get_forum_type() == 'ocf') {
            $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_auto_monitor_contrib_content');
            if ($auto_monitor_contrib_content == 1) {
                enable_notifications('comment_posted', $content_type . '_' . $content_id);
            }
        }
        // Activity
        $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook');
        if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) {
            if (is_null($submitter)) {
                $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id();
            }
            $activity_type = is_null($submitter) || is_guest($submitter) ? '_ADDED_COMMENT_ON' : 'ADDED_COMMENT_ON';
            if ($content_title == '') {
                syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            } else {
                syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter);
            }
        }
    }
    if ($post != '' && $forum_tie && !$no_success_message) {
        require_code('site2');
        assign_refresh($GLOBALS['FORUM_DRIVER']->topic_url($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $content_type . '_' . $content_id), $forum), 0.0);
    }
    if ($post != '' && !$no_success_message) {
        attach_message(do_lang_tempcode('SUCCESS'));
    }
    return $is_hidden;
}
Example #23
0
 /**
  * The UI to view an IOTD.
  *
  * @return tempcode		The UI
  */
 function view()
 {
     $title = get_page_title('IOTD');
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('IOTD_ARCHIVE'))));
     $id = get_param_integer('id');
     $rows = $GLOBALS['SITE_DB']->query_select('iotd', array('*'), array('id' => $id), '', 1);
     if (!array_key_exists(0, $rows)) {
         return warn_screen($title, do_lang_tempcode('MISSING_RESOURCE'));
     }
     $myrow = $rows[0];
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), strval($id), $myrow['allow_rating'], $myrow['allow_comments'], $myrow['allow_trackbacks'], is_null($myrow['date_and_time']) && $myrow['used'] == 0 ? 0 : 1, $myrow['submitter'], build_url(array('page' => '_SELF', 'type' => 'view', 'id' => $id), '_SELF', NULL, false, false, true), get_translated_text($myrow['i_title']), get_value('comment_forum__iotds'));
     $date_raw = strval($myrow['date_and_time']);
     $add_date_raw = strval($myrow['add_date']);
     $edit_date_raw = is_null($myrow['edit_date']) ? '' : strval($myrow['edit_date']);
     $date = get_timezoned_date($myrow['date_and_time']);
     $add_date = get_timezoned_date($myrow['add_date']);
     $edit_date = get_timezoned_date($myrow['edit_date']);
     // Views
     if (get_db_type() != 'xml') {
         $myrow['iotd_views']++;
         $GLOBALS['SITE_DB']->query_update('iotd', array('iotd_views' => $myrow['iotd_views']), array('id' => $id), '', 1, NULL, false, true);
     }
     if (has_actual_page_access(NULL, 'cms_iotds', NULL, NULL) && has_edit_permission('high', get_member(), $myrow['submitter'], 'cms_iotds')) {
         $edit_url = build_url(array('page' => 'cms_iotds', 'type' => '_ed', 'id' => $id), get_module_zone('cms_iotds'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     $url = $myrow['url'];
     if (url_is_local($url)) {
         $url = get_custom_base_url() . '/' . $url;
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => $GLOBALS['FORUM_DRIVER']->get_username($myrow['submitter']), 'publisher' => '', 'modified' => is_null($myrow['edit_date']) ? '' : date('Y-m-d', $myrow['edit_date']), 'type' => 'Poll', 'title' => get_translated_text($myrow['i_title']), 'identifier' => '_SEARCH:iotds:view:' . strval($id), 'description' => '', 'image' => $url);
     return do_template('IOTD_VIEW_SCREEN', array('_GUID' => 'f508d483459b88fab44cd8b9f4db780b', 'TITLE' => $title, 'SUBMITTER' => strval($myrow['submitter']), 'I_TITLE' => get_translated_tempcode($myrow['i_title']), 'CAPTION' => get_translated_tempcode($myrow['caption']), 'DATE_RAW' => $date_raw, 'ADD_DATE_RAW' => $add_date_raw, 'EDIT_DATE_RAW' => $edit_date_raw, 'DATE' => $date, 'ADD_DATE' => $add_date, 'EDIT_DATE' => $edit_date, 'VIEWS' => integer_format($myrow['iotd_views']), 'TRACKBACK_DETAILS' => $trackback_details, 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'EDIT_URL' => $edit_url, 'URL' => $url));
 }
Example #24
0
 /**
  * The actualiser for uploading a file.
  *
  * @return tempcode	The UI.
  */
 function module_do_upload()
 {
     if (!has_specific_permission(get_member(), 'upload_filedump')) {
         access_denied('I_ERROR');
     }
     $title = get_page_title('FILEDUMP_UPLOAD');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     // Slowly uploading a file can trigger time limit, on some servers
     $place = filter_naughty(post_param('place'));
     require_code('uploads');
     if (!is_swf_upload(true) && (!array_key_exists('file', $_FILES) || !is_uploaded_file($_FILES['file']['tmp_name']))) {
         $attach_name = 'file';
         $max_size = get_max_file_size();
         if (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 1 || $_FILES[$attach_name]['error'] == 2)) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size)));
         } elseif (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7)) {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error'])));
         } else {
             warn_exit(do_lang_tempcode('ERROR_UPLOADING'));
         }
     }
     $file = $_FILES['file']['name'];
     if (get_magic_quotes_gpc()) {
         $file = stripslashes($file);
     }
     if (!has_specific_permission(get_member(), 'upload_anything_filedump') || get_file_base() != get_custom_file_base()) {
         check_extension($file);
     }
     $file = str_replace('.', '-', basename($file, '.' . get_file_extension($file))) . '.' . get_file_extension($file);
     if (!file_exists(get_custom_file_base() . '/uploads/filedump' . $place . $file)) {
         $max_size = get_max_file_size();
         if ($_FILES['file']['size'] > $max_size) {
             warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(intval($max_size))));
         }
         $full = get_custom_file_base() . '/uploads/filedump' . $place . $file;
         if (is_swf_upload(true)) {
             @rename($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         } else {
             @move_uploaded_file($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place)));
         }
         fix_permissions($full);
         sync_file($full);
         $return_url = build_url(array('page' => '_SELF', 'place' => $place), '_SELF');
         $test = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => $file, 'path' => $place));
         if (!is_null($test)) {
             delete_lang($test);
         }
         $GLOBALS['SITE_DB']->query_delete('filedump', array('name' => $file, 'path' => $place), '', 1);
         $description = post_param('description');
         $GLOBALS['SITE_DB']->query_insert('filedump', array('name' => $file, 'path' => $place, 'the_member' => get_member(), 'description' => insert_lang_comcode($description, 3)));
         require_code('notifications');
         $subject = do_lang('FILEDUMP_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $file, $place);
         $mail = do_lang('FILEDUMP_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($file), array(comcode_escape($place), comcode_escape($description)));
         dispatch_notification('filedump', $place, $subject, $mail);
         log_it('FILEDUMP_UPLOAD', $file, $place);
         if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), get_page_name(), get_zone_name())) {
             syndicate_described_activity('filedump:ACTIVITY_FILEDUMP_UPLOAD', $place . '/' . $file, '', '', '', '', '', 'filedump');
         }
         return redirect_screen($title, $return_url, do_lang_tempcode('SUCCESS'));
     } else {
         warn_exit(do_lang_tempcode('OVERWRITE_ERROR'));
     }
     return new ocp_tempcode();
 }
Example #25
0
 /**
  * This function is a very basic query executor. It shouldn't usually be used by you, as there are abstracted versions available.
  *
  * @param  string			The complete SQL query
  * @param  array			A DB connection
  * @param  ?integer		The maximum number of rows to affect (NULL: no limit)
  * @param  ?integer		The start row to affect (NULL: no specification)
  * @param  boolean		Whether to output an error on failure
  * @param  boolean		Whether to get the autoincrement ID created for an insert query
  * @return ?mixed			The results (NULL: no results), or the insert ID
  */
 function db_query($query, $db, $max = NULL, $start = NULL, $fail_ok = false, $get_insert_id = false)
 {
     if (!is_null($max)) {
         if (is_null($start)) {
             $max += $start;
         }
         if (strtoupper(substr($query, 0, 7)) == 'SELECT ') {
             $query .= ' FETCH FIRST ' . strval($max + $start) . ' ROWS ONLY';
         }
     }
     $results = @odbc_exec($db, $query);
     if ($results === false && !$fail_ok) {
         $err = odbc_errormsg($db);
         if (function_exists('ocp_mark_as_escaped')) {
             ocp_mark_as_escaped($err);
         }
         if (!running_script('upgrader') && get_page_name() != 'admin_import') {
             if (!function_exists('do_lang') || is_null(do_lang('QUERY_FAILED', NULL, NULL, NULL, NULL, false))) {
                 fatal_exit(htmlentities('Query failed: ' . $query . ' : ' . $err));
             }
             fatal_exit(do_lang_tempcode('QUERY_FAILED', escape_html($query), $err));
         } else {
             echo htmlentities('Database query failed: ' . $query . ' [') . $err . htmlentities(']' . '<br />' . chr(10));
             return NULL;
         }
     }
     if (strtoupper(substr($query, 0, 7)) == 'SELECT ' && !$results !== false) {
         return $this->db_get_query_rows($results);
     }
     if ($get_insert_id) {
         if (strtoupper(substr($query, 0, 7)) == 'UPDATE ') {
             return NULL;
         }
         $pos = strpos($query, '(');
         $table_name = substr($query, 12, $pos - 13);
         $res2 = odbc_exec($db, 'SELECT MAX(id) FROM ' . $table_name);
         $ar2 = odbc_fetch_row($res2);
         return $ar2[0];
     }
     return NULL;
 }
Example #26
0
 /**
  * The UI to show a gallery.
  *
  * @return tempcode		The UI
  */
 function do_gallery()
 {
     require_code('images');
     $cat = get_param('id', 'root');
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=galleries&filter=' . $cat;
     $root = get_param('root', 'root');
     if (!has_category_access(get_member(), 'galleries', $cat)) {
         access_denied('CATEGORY_ACCESS');
     }
     // Info on our gallery
     $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $cat), '', 1);
     $implied_existence = false;
     if (!array_key_exists(0, $gallery_rows)) {
         // Possibly we will 'imply' it's existence if this is a member gallery; allows normal rendering to finish, with add links
         $matches = array();
         if (preg_match('#^member\\_(\\d+)\\_(.*)$#', $cat, $matches) != 0) {
             $username = $GLOBALS['FORUM_DRIVER']->get_username(intval($matches[1]));
             if (!is_null($username)) {
                 $gallery_rows = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('name' => $matches[2]), '', 1);
             }
         }
         if (!array_key_exists(0, $gallery_rows)) {
             return warn_screen(get_page_title('ERROR_OCCURRED'), do_lang_tempcode('MISSING_RESOURCE'));
         }
         $myrow = $gallery_rows[0];
         $myrow['is_member_synched'] = 0;
         $fullname = do_lang('PERSONAL_GALLERY_OF', $username, get_translated_text($myrow['fullname']));
         $myrow['parent_id'] = $matches[2];
         $implied_existence = true;
     } else {
         $myrow = $gallery_rows[0];
         $fullname = get_translated_text($myrow['fullname']);
     }
     if ($fullname == '') {
         $fullname = $cat;
     }
     $description = get_translated_tempcode($myrow['description']);
     if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_galleries', array('galleries', $cat))) {
         $submit_cat = $myrow['is_member_synched'] == 1 ? 'member_' . strval(get_member()) . '_' . $cat : $cat;
         $submit_image_url = $myrow['accept_images'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'ad', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
         $submit_video_url = $myrow['accept_videos'] == 0 ? new ocp_tempcode() : build_url(array('page' => 'cms_galleries', 'type' => 'av', 'cat' => $submit_cat), get_module_zone('cms_galleries'));
     } else {
         $submit_image_url = new ocp_tempcode();
         $submit_video_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('cat_mid', get_member(), get_member_id_from_gallery_name($cat), 'cms_galleries', array('galleries', $cat))) {
         $edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ec', 'id' => $cat), get_module_zone('cms_galleries'));
     } else {
         $edit_url = new ocp_tempcode();
     }
     if (!$implied_existence && has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_submit_permission('cat_mid', get_member(), get_ip_address(), 'cms_galleries')) {
         $add_gallery_url = build_url(array('page' => 'cms_galleries', 'type' => 'ac', 'cat' => $cat), get_module_zone('cms_galleries'));
     } else {
         $add_gallery_url = new ocp_tempcode();
     }
     $may_download_gallery = has_specific_permission(get_member(), 'may_download_gallery', 'galleries', array('galleries', $cat));
     $tree = gallery_breadcrumbs($cat, $root, true, get_module_zone('galleries'));
     if (!$tree->is_empty()) {
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
     }
     if (has_specific_permission(get_member(), 'open_virtual_roots')) {
         $url = get_self_url(false, false, array('root' => $cat));
         $tree->attach(hyperlink($url, escape_html($fullname), false, false, do_lang_tempcode('VIRTUAL_ROOT')));
     } else {
         $tree->attach('<span>' . escape_html($fullname) . '</span>');
     }
     $myrow['flow_mode_interface'] = get_param_integer('flow_mode_interface', $myrow['flow_mode_interface']);
     // Allow override via URL
     // Flow mode puts emphasis on subgalleries, rather than entries; it is subgalleries that there are a lot of, rather than entries
     if ($myrow['flow_mode_interface'] == 1) {
         $max = get_param_integer('max', get_default_gallery_max());
         if ($max < 1) {
             $max = 1;
         }
         $start = get_param_integer('start', 0);
     } else {
         $max = NULL;
         $start = NULL;
     }
     // Subgalleries
     $order = 'add_date DESC';
     if (get_option('gallery_name_order') == '1') {
         $order = 'name ASC';
     }
     $rows_children = $GLOBALS['SITE_DB']->query_select('galleries', array('*'), array('parent_id' => $cat), 'ORDER BY ' . $order, 200);
     $children = new ocp_tempcode();
     $num_galleries = 0;
     if (count($rows_children) == 200) {
         $rows_children = array();
     }
     // Lots of personal galleries. Will need to be reached via member profiles
     foreach ($rows_children as $child) {
         if (substr($child['name'], 0, 9) == 'download_') {
             continue;
         }
         if (!has_category_access(get_member(), 'galleries', $child['name'])) {
             continue;
         }
         if (get_option('show_empty_galleries') == '1' || gallery_has_content($child['name'])) {
             if (is_null($max) || $num_galleries >= $start && $num_galleries < $start + $max) {
                 $content = show_gallery_box($child, $root, true, get_zone_name(), get_option('show_empty_galleries') != '1');
                 if (!$content->is_empty()) {
                     $children->attach(do_template('GALLERY_SUBGALLERY_WRAP', array('CONTENT' => $content)));
                 }
             }
             $num_galleries++;
         }
     }
     // Views
     if (get_db_type() != 'xml') {
         $myrow['gallery_views']++;
         $GLOBALS['SITE_DB']->query_update('galleries', array('gallery_views' => $myrow['gallery_views']), array('name' => $cat), '', 1, NULL, false, true);
     }
     // Page title
     if (addon_installed('awards')) {
         require_code('awards');
         $awards = find_awards_for('gallery', $cat);
     } else {
         $awards = array();
     }
     $title_to_use = do_lang_tempcode('_GALLERY', escape_html($fullname));
     $title_to_use_2 = do_lang('_GALLERY', $fullname);
     $title = get_page_title($title_to_use, false, NULL, NULL, $awards);
     seo_meta_load_for('gallery', $cat, $title_to_use_2);
     $rep_image = $myrow['rep_image'];
     if (post_param_integer('rating_' . $cat, -1) != -1) {
         decache('main_top_galleries');
     }
     list($rating_details, $comment_details, $trackback_details) = embed_feedback_systems(get_page_name(), $cat, $myrow['allow_rating'], $myrow['allow_comments'], 0, 1, NULL, build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true), $title_to_use_2, get_value('comment_forum__galleries'));
     breadcrumb_add_segment($tree);
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $myrow['add_date']), 'creator' => is_null($myrow['g_owner']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($myrow['g_owner']), 'publisher' => '', 'modified' => '', 'type' => 'Gallery', 'title' => $fullname, 'identifier' => '_SEARCH:galleries:misc:' . $cat, 'description' => get_translated_text($myrow['description']));
     if ($rep_image != '') {
         $GLOBALS['META_DATA'] += array('image' => (url_is_local($rep_image) ? get_custom_base_url() . '/' : '') . $rep_image);
     }
     // Sorting
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     if (get_option('is_on_rating') == '1') {
         $_selectors['compound_rating DESC'] = 'POPULARITY';
     }
     $_selectors = array_merge($_selectors, array('url ASC' => 'FILENAME', 'add_date ASC' => 'OLDEST_FIRST', 'add_date DESC' => 'NEWEST_FIRST', 'title ASC' => 'TITLE'));
     $selectors = new ocp_tempcode();
     foreach ($_selectors as $selector_value => $selector_name) {
         $selected = $sort == $selector_value;
         $selectors->attach(do_template('RESULTS_BROWSER_SORTER', array('SELECTED' => $selected, 'NAME' => do_lang_tempcode($selector_name), 'VALUE' => $selector_value)));
     }
     $sort_url = get_self_url(false, false, array('sort' => NULL), false, true);
     $sorting = do_template('RESULTS_BROWSER_SORT', array('SORT' => 'sort', 'RAND' => uniqid(''), 'URL' => $sort_url, 'SELECTORS' => $selectors));
     if ($myrow['flow_mode_interface'] == 1) {
         return $this->do_gallery_flow_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $rep_image, $start, $max, $num_galleries, $fullname, $sorting);
     } else {
         return $this->do_gallery_regular_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download_gallery, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $fullname, $sorting);
     }
 }
Example #27
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 #28
0
 /**
  * Standard modular UI to edit an entry.
  *
  * @return tempcode	The UI
  */
 function _ed()
 {
     $doing = 'EDIT_' . $this->lang_type;
     if ($this->catalogue && get_param('catalogue_name', '') != '') {
         $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name'))));
         if ($this->type_code == 'd') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title));
         } elseif ($this->type_code == 'c') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title));
         }
     }
     $title = get_page_title($doing);
     //$submit_name=(strpos($doing,' ')!==false)?protect_from_escaping($doing):do_lang($doing);
     //if (!is_null($this->edit_submit_name)) $submit_name=$this->edit_submit_name;
     $submit_name = do_lang_tempcode('SAVE');
     //$test=$this->choose_catalogue($title);
     //if (!is_null($test)) return $test;
     $id = mixed();
     // Define type as mixed
     $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id'));
     $map = array('page' => '_SELF', 'type' => '__e' . $this->type_code, 'id' => $id);
     if (get_param('catalogue_name', '') != '') {
         $map['catalogue_name'] = get_param('catalogue_name');
     }
     if (!is_null(get_param('redirect', NULL))) {
         $map['redirect'] = get_param('redirect');
     }
     if (!is_null(get_param('continue', NULL))) {
         $map['continue'] = get_param('continue');
     }
     if (!is_null($this->upload) || $this->possibly_some_kind_of_upload) {
         $map['uploading'] = 1;
     }
     $post_url = build_url($map, '_SELF');
     if (multi_lang() && has_actual_page_access(get_member(), 'admin_lang') && user_lang() != get_site_default_lang()) {
         require_code('lang2');
         $switch_url = get_self_url(false, false, array('keep_lang' => get_site_default_lang()));
         attach_message(do_lang_tempcode('lang:EDITING_CONTENT_IN_LANGUAGE_STAFF', escape_html(lookup_language_full_name(user_lang())), escape_html(lookup_language_full_name(get_site_default_lang())), escape_html($switch_url->evaluate())), 'warn');
     }
     if (method_exists($this, 'get_submitter')) {
         list($submitter, $date_and_time) = $this->get_submitter($id);
     } else {
         $submitter = NULL;
         $date_and_time = NULL;
     }
     if (!is_null($this->permissions_require)) {
         check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name);
     }
     if (!is_null($this->permissions_cat_require) && !has_category_access(get_member(), $this->permissions_cat_require, $this->get_cat($id))) {
         access_denied('CATEGORY_ACCESS');
     }
     if (!is_null($this->permissions_cat_require_b) && !has_category_access(get_member(), $this->permissions_cat_require_b, $this->get_cat_b($id))) {
         access_denied('CATEGORY_ACCESS');
     }
     $bits = $this->fill_in_edit_form($id);
     $delete_fields = new ocp_tempcode();
     $all_delete_fields_given = false;
     $fields2 = new ocp_tempcode();
     if (is_array($bits)) {
         $fields = $bits[0];
         $hidden = $bits[1];
         if (array_key_exists(2, $bits) && !is_null($bits[2])) {
             $delete_fields = $bits[2];
         }
         if (array_key_exists(3, $bits) && !is_null($bits[3])) {
             $this->edit_text = $bits[3];
         }
         if (array_key_exists(4, $bits) && $bits[4]) {
             $all_delete_fields_given = true;
         }
         if (array_key_exists(5, $bits) && !is_null($bits[5])) {
             $this->posting_form_text = $bits[5];
         }
         if (array_key_exists(6, $bits) && !is_null($bits[6])) {
             $fields2 = $bits[6];
         }
         if (array_key_exists(7, $bits)) {
             $this->posting_form_text_parsed = $bits[7];
         }
     } else {
         $fields = $bits;
         $hidden = new ocp_tempcode();
     }
     // Add in custom fields
     if ($this->has_tied_catalogue()) {
         require_code('fields');
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('MORE'))));
         append_form_custom_fields($this->award_type, $id, $fields, $hidden);
     }
     // SEO?
     if (!is_null($this->seo_type)) {
         require_code('seo2');
         $fields2->attach(seo_get_fields($this->seo_type, $id));
     }
     // Awards?
     if (addon_installed('awards')) {
         if (!is_null($this->award_type)) {
             require_code('awards');
             $fields2->attach(get_award_fields($this->award_type, $id));
         }
     }
     // Action fields / deletion options
     $delete_permission = true;
     if (!is_null($this->permissions_require)) {
         $delete_permission = has_delete_permission($this->permissions_require, get_member(), $submitter, is_null($this->permission_page_name) ? get_page_name() : $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)));
     }
     $may_delete = (!method_exists($this, 'may_delete_this') || $this->may_delete_this($id)) && (!is_numeric($id) || intval($id) >= db_get_first_id() + $this->protect_first) && $delete_permission;
     // Deletion options
     $action_fields = new ocp_tempcode();
     if ($may_delete) {
         if (!$all_delete_fields_given) {
             $action_fields->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), 'delete', false));
         }
         if (addon_installed('points') && !is_null($submitter) && !is_null($date_and_time)) {
             $points_test = $GLOBALS['SITE_DB']->query_value_null_ok('gifts', 'id', array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id()));
             if (!is_null($points_test)) {
                 require_lang('points');
                 $action_fields->attach(form_input_tick(do_lang_tempcode('REVERSE_TITLE'), do_lang_tempcode('REVERSE_TITLE_DESCRIPTION'), 'reverse_point_transaction', false));
             }
         }
         $action_fields->attach($delete_fields);
     }
     if (!$this->appended_actions_already && !$action_fields->is_empty()) {
         $fields2->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS'))));
     }
     $fields2->attach($action_fields);
     if (!is_object($this->edit_text)) {
         $this->edit_text = make_string_tempcode(is_null($this->edit_text) ? '' : $this->edit_text);
     }
     if (!is_null($this->upload)) {
         if ($this->upload == 'image') {
             require_code('images');
             $max = floatval(get_max_image_size()) / floatval(1024 * 1024);
             if ($max < 3.0) {
                 require_code('files2');
                 $config_url = get_upload_limit_config_url();
                 $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url))));
             }
         } else {
             require_code('files2');
             $max = floatval(get_max_file_size()) / floatval(1024 * 1024);
             if ($max < 30.0) {
                 $config_url = get_upload_limit_config_url();
                 $this->edit_text->attach(paragraph(do_lang_tempcode(is_null($config_url) ? 'MAXIMUM_UPLOAD' : 'MAXIMUM_UPLOAD_STAFF', escape_html($max > 10.0 ? integer_format(intval($max)) : float_format($max)), escape_html(is_null($config_url) ? '' : $config_url))));
             }
         }
     }
     if (get_param('type', '_ed') == '_edit_catalogue') {
         require_javascript('javascript_catalogues');
         // Existing fields
         $field_count = 0;
         $c_name = get_param('id', false, true);
         $rows = $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('*'), array('c_name' => $c_name), 'ORDER BY cf_order');
         $fields_existing = new ocp_tempcode();
         foreach ($rows as $i => $myrow) {
             $name = get_translated_text($myrow['cf_name']);
             $description = get_translated_text($myrow['cf_description']);
             $prefix = 'existing_field_' . strval($myrow['id']) . '_';
             list($_fields_existing, $_fields_hidden) = $this->get_field_fields($i == 0 && substr($c_name, 0, 1) != '_', count($rows) + 10, $prefix, $field_count, $name, $description, $myrow['cf_type'], $myrow['cf_defines_order'], $myrow['cf_visible'], $myrow['cf_searchable'], $myrow['cf_default'], $myrow['cf_required'], $myrow['cf_put_in_category'], $myrow['cf_put_in_search']);
             if (!is_ecommerce_catalogue($c_name) || $i > 9) {
                 $_fields_existing->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('ACTIONS'))));
                 $_fields_existing->attach(form_input_tick(do_lang_tempcode('DELETE'), do_lang_tempcode('DESCRIPTION_DELETE'), $prefix . 'delete', false));
             }
             $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '1492d973db45cbecff892ad4ac1af28f' . get_class($this), 'NAME' => $name, 'ID' => 'FIELD_' . strval($i + 1), 'FIELDS' => $_fields_existing->evaluate()));
             $fields_existing->attach($temp);
             $hidden->attach($_fields_hidden);
             $field_count++;
         }
         // New field
         $fields_new = new ocp_tempcode();
         for ($i = 0; $i < 5; $i++) {
             list($_fields_new, $_fields_hidden) = $this->get_field_fields(false, count($rows) + 10, 'new_field_' . strval($i) . '_', $field_count);
             $temp = do_template('FORM_FIELD_SET_GROUPER', array('_GUID' => '8b9a632eafae003ccc6b007eefb0ce3d' . get_class($this), 'NAME' => do_lang_tempcode('NEW_FIELD', strval($i + 1)), 'ID' => 'NEW_FIELD_' . strval($i + 1), 'FIELDS' => $_fields_new->evaluate()));
             $fields_new->attach($temp);
             $hidden->attach($_fields_hidden);
             $field_count++;
         }
         $fields->attach($fields2);
         return do_template('CATALOGUE_EDITING_SCREEN', array('_GUID' => '584d7dc7c2c13939626102374f13f508' . get_class($this), 'HIDDEN' => $hidden, 'TITLE' => $title, 'TEXT' => $this->add_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'FIELDS_EXISTING' => $fields_existing->evaluate(), 'FIELDS_NEW' => $fields_new->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript));
     }
     list($warning_details, $ping_url) = handle_conflict_resolution();
     if (!is_null($this->posting_form_title)) {
         $posting_form = get_posting_form($submit_name, $this->posting_form_text, $post_url, $hidden, $fields, $this->posting_form_title, '', $fields2, $this->posting_form_text_parsed, $this->javascript, NULL, $this->posting_field_required);
         return do_template('POSTING_SCREEN', array('_GUID' => '841b9af3aa80bcab86b907e4b942786a' . get_class($this), 'PREVIEW' => $this->do_preview, 'TITLE' => $title, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'TEXT' => $this->add_text, 'POSTING_FORM' => $posting_form->evaluate(), 'JAVASCRIPT' => $this->javascript));
     } else {
         $fields->attach($fields2);
         return do_template('FORM_SCREEN', array('_GUID' => '2d70be34595a16c6f170d966b894bfe2' . get_class($this), 'PREVIEW' => $this->do_preview, 'SEPARATE_PREVIEW' => $this->second_stage_preview, 'TITLE' => $title, 'SKIP_VALIDATION' => $this->skip_validation, 'PING_URL' => $ping_url, 'WARNING_DETAILS' => $warning_details, 'HIDDEN' => $hidden, 'TEXT' => $this->edit_text, 'URL' => $post_url, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'JAVASCRIPT' => $this->javascript));
     }
 }
Example #29
0
/**
 * Find the cache signature for the block.
 *
 * @param  array	The block parameters.
 * @return array	The cache signature.
 */
function block_side_stored_menu__cache_on($map)
{
    $menu = array_key_exists('param', $map) ? $map['param'] : '';
    return array($GLOBALS['FORUM_DRIVER']->get_members_groups(get_member()), substr($menu, 0, 1) != '_' && substr($menu, 0, 3) != '!!!' && has_actual_page_access(get_member(), 'admin_menus'), get_zone_name(), get_page_name(), array_key_exists('type', $map) ? $map['type'] : 'tree', $menu, array_key_exists('caption', $map) ? $map['caption'] : '', array_key_exists('silent_failure', $map) ? $map['silent_failure'] : '0', array_key_exists('tray_status', $map) ? $map['tray_status'] : '');
}
Example #30
0
/**
 * Show a post, isolated of the other posts in it's topic.
 *
 * @param  array		The post row.
 * @param  boolean	Whether to use the post title, as opposed to the post's topic's title.
 * @return tempcode  The isolated post.
 */
function ocf_show_isolated_post($row, $use_post_title = false)
{
    require_code('ocf_groups');
    require_css('ocf');
    // Poster title
    $primary_group = $GLOBALS['FORUM_DRIVER']->get_member_row_field($row['p_poster'], 'm_primary_group');
    if (!is_null($primary_group)) {
        if (addon_installed('ocf_member_titles')) {
            $poster_title = $GLOBALS['OCF_DRIVER']->get_member_row_field($row['p_poster'], 'm_title');
            if ($poster_title == '') {
                $poster_title = get_translated_text(ocf_get_group_property($primary_group, 'title'), $GLOBALS['FORUM_DB']);
            }
        } else {
            $poster_title = '';
        }
        $avatar = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($row['p_poster']);
        $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($row['p_poster'], true);
    } else {
        $poster_title = '';
        $avatar = '';
        $posters_groups = array();
    }
    // Avatar
    if (is_guest($row['p_poster'])) {
        if ($row['p_poster_name_if_guest'] == do_lang('SYSTEM')) {
            $avatar = find_theme_image('ocf_default_avatars/default_set/ocp_fanatic', true);
        }
    }
    if ($avatar != '') {
        $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('AVATAR' => $avatar));
    } else {
        $post_avatar = new ocp_tempcode();
    }
    // Rank images
    $rank_images = new ocp_tempcode();
    foreach ($posters_groups as $group) {
        $rank_image = ocf_get_group_property($group, 'rank_image');
        $group_leader = ocf_get_group_property($group, 'group_leader');
        $group_name = ocf_get_group_name($group);
        $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only');
        if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $primary_group)) {
            $rank_images->attach(do_template('OCF_RANK_IMAGE', array('GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $row['p_poster'])));
        }
    }
    // Poster details
    if (!is_guest($row['p_poster']) && !is_null($primary_group)) {
        require_code('ocf_members2');
        $poster_details = ocf_show_member_box($row['p_poster'], false, NULL, NULL, false);
    } else {
        $custom_fields = new ocp_tempcode();
        $poster_details = new ocp_tempcode();
    }
    if (!is_guest($row['p_poster']) && !is_null($primary_group)) {
        $poster = do_template('OCF_POSTER_MEMBER', array('ONLINE' => member_is_online($row['p_poster']), 'ID' => strval($row['p_poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($row['p_poster'], false, true), 'POSTER_USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($row['p_poster']), 'HIGHLIGHT_NAME' => NULL));
    } else {
        $poster = do_template('OCF_POSTER_GUEST', array('IP_LINK' => '', 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $row['p_poster_name_if_guest'] != '' ? $row['p_poster_name_if_guest'] : do_lang('GUEST')));
    }
    // Last edited
    if (!is_null($row['p_last_edit_time'])) {
        $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => is_null($row['p_last_edit_time']) ? '' : strval($row['p_last_edit_time']), 'LAST_EDIT_DATE' => get_timezoned_date($row['p_last_edit_time']), 'LAST_EDIT_PROFILE_URL' => is_null($row['p_last_edit_by']) ? '' : $GLOBALS['FORUM_DRIVER']->member_profile_url($row['p_last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => is_null($row['p_last_edit_by']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($row['p_last_edit_by'])));
    } else {
        $last_edited = new ocp_tempcode();
    }
    $last_edited_raw = is_null($row['p_last_edit_time']) ? '' : strval($row['p_last_edit_time']);
    // Misc stuff
    $poster_id = $row['p_poster'];
    $tree = ocf_forum_breadcrumbs($row['p_cache_forum_id']);
    $post_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $row['id']), get_module_zone('topicview'));
    $post_url->attach('#post_' . strval($row['id']));
    if (get_page_name() != 'search' && array_key_exists('text_parsed', $row) && !is_null($row['text_parsed']) && $row['text_parsed'] != '' && $row['p_post'] != 0) {
        $post = new ocp_tempcode();
        if (!$post->from_assembly($row['text_parsed'], true)) {
            $post = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']);
        }
    } else {
        $post = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']);
    }
    $post_date = get_timezoned_date($row['p_time']);
    $post_date_raw = $row['p_time'];
    if ($use_post_title) {
        $post_title = $row['p_title'];
    } else {
        $post_title = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $row['p_topic_id']));
        if ($row['p_title'] != $post_title) {
            $post_title .= ': ' . $row['p_title'];
        }
    }
    //if ($post_title=='') $post_title=do_lang_tempcode('ISOLATED_POST_TITLE',strval($row['id']));
    $emphasis = new ocp_tempcode();
    if ($row['p_is_emphasised'] == 1) {
        $emphasis = do_lang_tempcode('IMPORTANT');
    } elseif (!is_null($row['p_intended_solely_for'])) {
        $pp_to_username = $GLOBALS['FORUM_DRIVER']->get_username($row['p_intended_solely_for']);
        if (is_null($pp_to_username)) {
            $pp_to_username = do_lang('UNKNOWN');
        }
        $emphasis = do_lang('PP_TO', $pp_to_username);
    }
    require_code('feedback');
    actualise_rating(true, 'post', strval($row['id']), get_self_url(), $row['p_title']);
    $rating = display_rating(get_self_url(), $row['p_title'], 'post', strval($row['id']), 'RATING_INLINE_DYNAMIC', $row['p_poster']);
    // Render
    return do_template('OCF_ISOLATED_POST', array('_GUID' => '9456f4fe4b8fb1bf34f606fcb2bcc9d7', 'URL' => $post_url, 'ID' => strval($row['id']), 'TREE' => $tree, 'POST' => do_template('OCF_TOPIC_POST', array('ID' => strval($row['id']), 'TOPIC_FIRST_POST_ID' => '', 'TOPIC_FIRST_POSTER' => '', 'POST_ID' => strval($row['id']), 'URL' => $post_url, 'CLASS' => $row['p_is_emphasised'] == 1 ? 'ocf_post_emphasis' : (!is_null($row['p_intended_solely_for']) ? 'ocf_post_personal' : ''), 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => '', 'POSTER_TITLE' => $poster_title, 'POST_TITLE' => $post_title, 'POST_DATE_RAW' => strval($post_date_raw), 'POST_DATE' => $post_date, 'POST' => $post, 'TOPIC_ID' => is_null($row['p_topic_id']) ? '' : strval($row['p_topic_id']), 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'POSTER_ID' => strval($poster_id), 'POSTER' => $poster, 'POSTER_DETAILS' => $poster_details, 'POST_AVATAR' => $post_avatar, 'RANK_IMAGES' => $rank_images, 'BUTTONS' => '', 'SIGNATURE' => '', 'UNVALIDATED' => '', 'DESCRIPTION' => '', 'PREVIEWING' => true, 'RATING' => $rating))));
}