Exemple #1
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('iotds')) {
         return array();
     }
     if (get_option('iotd_update_time') == '') {
         return array();
     }
     require_lang('iotds');
     $date = $GLOBALS['SITE_DB']->query_value_null_ok('iotd', 'date_and_time', array('is_current' => 1));
     $limit_hours = intval(get_option('iotd_update_time'));
     $seconds_ago = mixed();
     if (!is_null($date)) {
         $seconds_ago = time() - $date;
         $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1;
     } else {
         $status = 0;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $config_row = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'section'), array('the_name' => 'iotd_update_time'), '', 1);
     if (array_key_exists(0, $config_row)) {
         $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $config_row[0]['the_page']), get_module_zone('admin_config'));
         $config_url = $_config_url->evaluate();
         $config_url .= '#group_' . $config_row[0]['section'];
     } else {
         $config_url = NULL;
     }
     $url = build_url(array('page' => 'cms_iotds', 'type' => 'ed'), get_module_zone('cms_iotds'));
     $num_queue = $this->get_num_iotd_queue();
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
     $info->attach(do_lang_tempcode('NUM_QUEUE', integer_format($num_queue)));
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => '5c55aed7bedca565c8aa553548b88e64', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('PT_choose_iotd'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, 'iotd_update_time'));
 }
Exemple #2
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('news')) {
         return array();
     }
     if (get_option('news_update_time') == '') {
         return array();
     }
     require_lang('news');
     $date = $GLOBALS['SITE_DB']->query_value_null_ok('news n JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON n.news_category=c.id', 'MAX(date_and_time)', array('validated' => 1, 'nc_owner' => NULL));
     $limit_hours = intval(get_option('news_update_time'));
     $seconds_ago = mixed();
     if (!is_null($date)) {
         $seconds_ago = time() - $date;
         $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1;
     } else {
         $status = 0;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $config_row = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'section'), array('the_name' => 'news_update_time'), '', 1);
     if (array_key_exists(0, $config_row)) {
         $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $config_row[0]['the_page']), get_module_zone('admin_config'));
         $config_url = $_config_url->evaluate();
         $config_url .= '#group_' . $config_row[0]['section'];
     } else {
         $config_url = NULL;
     }
     $url = build_url(array('page' => 'cms_news', 'type' => 'ad'), get_module_zone('cms_news'));
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => 'dd14f34eafa4f24c4c173c195cd84fe3', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('ADD_NEWS'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, 'news_update_time'));
 }
Exemple #3
0
 /**
  * Get a URL to a forum member's member profile.
  *
  * @param  MEMBER			The forum member
  * @param  boolean		Whether to be insistent that we go to the profile, rather than possibly starting an IM which can link to the profile
  * @param  boolean		Whether it is okay to return the result using Tempcode (more efficient, and allows keep_* parameters to propagate which you almost certainly want!)
  * @return mixed			The URL
  */
 function member_profile_url($id, $definitely_profile = false, $tempcode_okay = false)
 {
     $url = mixed();
     if (!$definitely_profile && $id != $this->get_guest_id() && addon_installed('chat') && has_specific_permission(get_member(), 'start_im')) {
         $username_click_im = get_option('username_click_im', true);
         if ($username_click_im == '1') {
             $url = build_url(array('page' => 'chat', 'type' => 'misc', 'enter_im' => $id), get_module_zone('chat'));
             if (!$tempcode_okay) {
                 $url = $url->evaluate();
             }
             return $url;
         }
     }
     $url = $this->_member_profile_url($id, $tempcode_okay);
     if ($tempcode_okay && !is_object($url)) {
         $url = make_string_tempcode($url);
     }
     if (get_forum_type() != 'none' && get_forum_type() != 'ocf' && get_option('forum_in_portal', true) == '1') {
         $url = build_url(array('page' => 'forums', 'url' => $url), get_module_zone('forums'));
         if (!$tempcode_okay) {
             $url = $url->evaluate();
         }
     }
     return $url;
 }
Exemple #4
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('newsletter')) {
         return array();
     }
     if (get_option('news_update_time', true) == '') {
         return array();
     }
     $limit_hours = intval(get_option('news_update_time', true));
     $limit_hours = intval($limit_hours / 3);
     // 3 news pieces (+ other stuff) per newsletter seems reasonable
     require_lang('newsletter');
     $date = get_value('newsletter_send_time');
     $seconds_ago = mixed();
     if (!is_null($date)) {
         $seconds_ago = time() - intval($date);
         $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1;
     } else {
         $status = 0;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $config_row = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'section'), array('the_name' => 'news_update_time'), '', 1);
     if (array_key_exists(0, $config_row)) {
         $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $config_row[0]['the_page']), get_module_zone('admin_config'));
         $config_url = $_config_url->evaluate();
         $config_url .= '#group_' . $config_row[0]['section'];
     } else {
         $config_url = NULL;
     }
     $url = build_url(array('page' => 'admin_newsletter', 'type' => 'whatsnew'), 'adminzone');
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => 'fb9483bb05ad90b9f2b7eba0c53996f4', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('NEWSLETTER_SEND'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, 'news_update_time'));
 }
Exemple #5
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('flagrant')) {
         return array();
     }
     require_lang('flagrant');
     $rows = $GLOBALS['SITE_DB']->query_select('text', array('activation_time', 'days'), array('active_now' => 1), '', NULL, NULL, true);
     if (is_null($rows)) {
         return array();
     }
     $seconds_due_in = mixed();
     if (array_key_exists(0, $rows)) {
         $activation_time = $rows[0]['activation_time'];
         $days = $rows[0]['days'];
         $date = $activation_time + $days * 24 * 60 * 60;
         $seconds_due_in = $date - time();
         $status = $seconds_due_in <= 0 ? 0 : 1;
     } else {
         $status = 1;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $url = build_url(array('page' => 'admin_flagrant', 'type' => 'misc'), 'adminzone');
     $num_queue = $this->get_num_flagrant_queue();
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_due_in);
     $info->attach(do_lang_tempcode('NUM_QUEUE', escape_html(integer_format($num_queue))));
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => '820e0e3cd80754dc7dfd9a0d05a43ec0', 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('CHOOSE_FLAGRANT'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, NULL));
 }
Exemple #6
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('backup')) {
         return array();
     }
     if (get_option('backup_time', true) == '') {
         return array();
     }
     $limit_hours = intval(get_option('backup_time', true));
     require_lang('backups');
     $date = intval(get_value('last_backup'));
     $seconds_ago = mixed();
     if ($date != 0) {
         $seconds_ago = time() - $date;
         $status = intval($seconds_ago) > $limit_hours * 60 * 60 ? 0 : 1;
     } else {
         $status = 0;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $config_row = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'section'), array('the_name' => 'backup_time'), '', 1);
     if (array_key_exists(0, $config_row)) {
         $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $config_row[0]['the_page']), get_module_zone('admin_config'));
         $config_url = $_config_url->evaluate();
         $config_url .= '#group_' . $config_row[0]['section'];
     } else {
         $config_url = NULL;
     }
     $url = build_url(array('page' => 'admin_backup', 'type' => 'misc'), 'adminzone');
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => '432685ec6c9f7548ce8b488b6ce00030', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('BACKUP'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, 'backup_time'));
 }
/**
 * Set up a new session / Restore an existing one that was lost.
 *
 * @param  MEMBER			Logged in member
 * @param  BINARY			Whether the session should be considered confirmed
 * @param  boolean		Whether the session should be invisible
 * @return AUTO_LINK		New session ID
 */
function create_session($member, $session_confirmed = 0, $invisible = false)
{
    global $SESSION_CACHE;
    global $MEMBER_CACHED;
    $MEMBER_CACHED = $member;
    if ($invisible && get_option('is_on_invisibility') == '0') {
        $invisible = false;
    }
    $new_session = mixed();
    $restored_session = delete_expired_sessions_or_recover($member);
    if (is_null($restored_session)) {
        // Generate random session
        $new_session = mt_rand(0, mt_getrandmax() - 1);
        // Store session
        $username = $GLOBALS['FORUM_DRIVER']->get_username($member);
        $new_session_row = array('the_session' => $new_session, 'last_activity' => time(), 'the_user' => $member, 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed, 'session_invisible' => $invisible ? 1 : 0, 'cache_username' => $username, 'the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => substr(get_page_name(), 0, 80), 'the_type' => substr(get_param('type', '', true), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80));
        $GLOBALS['SITE_DB']->query_insert('sessions', $new_session_row, false, true);
        $SESSION_CACHE[$new_session] = $new_session_row;
        $big_change = true;
    } else {
        $new_session = $restored_session;
        $prior_session_row = $SESSION_CACHE[$new_session];
        $new_session_row = array('the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => get_page_name(), 'the_type' => substr(either_param('type', ''), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80), 'last_activity' => time(), 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed);
        $big_change = $prior_session_row['last_activity'] < time() - 10 || $prior_session_row['session_confirmed'] != $session_confirmed || $prior_session_row['ip'] != $new_session_row['ip'];
        if ($big_change) {
            $GLOBALS['SITE_DB']->query_update('sessions', $new_session_row, array('the_session' => $new_session), '', 1, NULL, false, true);
        }
        $SESSION_CACHE[$new_session] = array_merge($SESSION_CACHE[$new_session], $new_session_row);
    }
    if ($big_change) {
        if (get_value('session_prudence') !== '1') {
            // With session prudence we don't store all these in persistant cache due to the size of it all. So only re-save if that's not on.
            persistant_cache_set('SESSION_CACHE', $SESSION_CACHE);
        }
    }
    set_session_id($new_session);
    // We won't set it true here, but something that really needs it to persist might come back and re-set it
    // New sessions = Login points
    if (!is_null($member) && addon_installed('points') && addon_installed('stats') && !is_guest($member)) {
        $points_per_daily_visit = intval(get_option('points_per_daily_visit', true));
        if ($points_per_daily_visit != 0) {
            // See if this is the first visit today
            $test = $GLOBALS['SITE_DB']->query_value('stats', 'MAX(date_and_time)', array('the_user' => $member));
            if (!is_null($test)) {
                require_code('temporal');
                require_code('tempcode');
                if (date('d/m/Y', tz_time($test, get_site_timezone())) != date('d/m/Y', tz_time(time(), get_site_timezone()))) {
                    require_code('points');
                    $_before = point_info($member);
                    if (array_key_exists('points_gained_given', $_before)) {
                        $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_given', strval(intval($_before['points_gained_given']) + $points_per_daily_visit));
                    }
                }
            }
        }
    }
    $GLOBALS['SESSION_CONFIRMED'] = $session_confirmed;
    return $new_session;
}
Exemple #8
0
/**
 * Send (by e-mail) a validation request for a submitted item to the admin.
 *
 * @param  ID_TEXT		The validation request will say one of this type has been submitted. By convention it is the language code of what was done, e.g. ADD_DOWNLOAD
 * @param  ?ID_TEXT		The table saved into (NULL: unknown)
 * @param  boolean		Whether the ID field is not an integer
 * @param  ID_TEXT		The validation request will say this ID has been submitted
 * @param  tempcode		The validation request will link to this URL
 * @param  ?MEMBER		Member doing the submitting (NULL: current member)
 */
function send_validation_request($type, $table, $non_integer_id, $id, $url, $member_id = NULL)
{
    $good = NULL;
    if (!is_null($table)) {
        $_hooks = find_all_hooks('modules', 'admin_unvalidated');
        foreach (array_keys($_hooks) as $hook) {
            require_code('hooks/modules/admin_unvalidated/' . filter_naughty_harsh($hook));
            $object = object_factory('Hook_unvalidated_' . filter_naughty_harsh($hook), true);
            if (is_null($object)) {
                continue;
            }
            $info = $object->info();
            if (is_null($info)) {
                continue;
            }
            if ($info['db_table'] == $table) {
                $good = $info;
                break;
            }
        }
    }
    $title = mixed();
    $title = '';
    if (!is_null($good) && !is_array($good['db_identifier'])) {
        $db = array_key_exists('db', $good) ? $good['db'] : $GLOBALS['SITE_DB'];
        $where = $good['db_identifier'] . '=' . $id;
        if ($non_integer_id) {
            $where = db_string_equal_to($good['db_identifier'], $id);
        }
        $rows = $db->query('SELECT ' . $good['db_identifier'] . (array_key_exists('db_title', $good) ? ',' . $good['db_title'] : '') . ' FROM ' . $db->get_table_prefix() . $good['db_table'] . ' WHERE ' . $where, 100);
        if (array_key_exists('db_title', $good)) {
            $title = $rows[0][$good['db_title']];
            if ($good['db_title_dereference']) {
                $title = get_translated_text($title, $db);
            }
            // May actually be comcode (can't be certain), but in which case it will be shown as source
        } else {
            $title = '#' . (is_integer($id) ? strval($id) : $id);
        }
    }
    if ($title == '') {
        $title = '#' . (is_integer($id) ? strval($id) : $id);
    }
    if (is_null($member_id)) {
        $member_id = get_member();
    }
    require_lang('unvalidated');
    $_type = do_lang($type, NULL, NULL, NULL, NULL, false);
    if (!is_null($_type)) {
        $type = $_type;
    }
    $comcode = do_template('VALIDATION_REQUEST', array('_GUID' => '1885be371b2ff7810287715ef2f7b948', 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($member_id), 'TYPE' => $type, 'ID' => $id, 'URL' => $url), get_site_default_lang());
    require_code('notifications');
    $subject = do_lang('UNVALIDATED_TITLE', $title, '', '', get_site_default_lang());
    $message = $comcode->evaluate(get_site_default_lang(), false);
    dispatch_notification('needs_validation', NULL, $subject, $message);
}
Exemple #9
0
/**
 * Give an award.
 *
 * @param  AUTO_LINK			The award ID
 * @param  ID_TEXT			The content ID
 * @param  ?TIME				Time the award was given (NULL: now)
 */
function give_award($award_id, $content_id, $time = NULL)
{
    require_lang('awards');
    if (is_null($time)) {
        $time = time();
    }
    $awards = $GLOBALS['SITE_DB']->query_select('award_types', array('*'), array('id' => $award_id), '', 1);
    if (!array_key_exists(0, $awards)) {
        warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
    }
    $award_title = get_translated_text($awards[0]['a_title']);
    log_it('GIVE_AWARD', strval($award_id), $award_title);
    require_code('hooks/systems/awards/' . filter_naughty_harsh($awards[0]['a_content_type']));
    $object = object_factory('Hook_awards_' . $awards[0]['a_content_type']);
    $info = $object->info();
    if (is_null($info)) {
        fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
    }
    if (array_key_exists('submitter_field', $info) && $awards[0]['a_content_type'] != 'author' && !is_null($info['submitter_field'])) {
        require_code('content');
        list($content_title, $member_id, , $content) = content_get_details($awards[0]['a_content_type'], $content_id);
        if (is_null($content)) {
            warn_exit(do_lang_tempcode('_MISSING_RESOURCE', escape_html($awards[0]['a_content_type'] . ':' . $content_id)));
        }
        // Lots of fiddling around to work out how to check permissions for this
        $permission_type_code = convert_ocportal_type_codes('award_hook', $awards[0]['a_content_type'], 'permissions_type_code');
        $module = convert_ocportal_type_codes('module', $awards[0]['a_content_type'], 'permissions_type_code');
        if ($module == '') {
            $module = $content_id;
        }
        $category_id = mixed();
        if (isset($info['category_field'])) {
            if (is_array($info['category_field'])) {
                $category_id = $content[$info['category_field'][1]];
            } else {
                $category_id = $content[$info['category_field']];
            }
        }
        if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'awards') && has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $module) && ($permission_type_code == '' || is_null($category_id) || has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), $permission_type_code, is_integer($category_id) ? strval($category_id) : $category_id))) {
            syndicate_described_activity(is_null($member_id) || is_guest($member_id) ? 'awards:_ACTIVITY_GIVE_AWARD' : 'awards:ACTIVITY_GIVE_AWARD', $award_title, $content_title, '', '_SEARCH:awards:award:' . strval($award_id), '', '', 'awards', 1, NULL, false, $member_id);
        }
    } else {
        $member_id = NULL;
    }
    if (is_null($member_id)) {
        $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    if (!is_guest($member_id) && addon_installed('points')) {
        require_code('points2');
        system_gift_transfer(do_lang('_AWARD', get_translated_text($awards[0]['a_title'])), $awards[0]['a_points'], $member_id);
    }
    $GLOBALS['SITE_DB']->query_insert('award_archive', array('a_type_id' => $award_id, 'member_id' => $member_id, 'content_id' => $content_id, 'date_and_time' => $time));
    decache('main_awards');
    decache('main_multi_content');
}
Exemple #10
0
/**
 * Standard code module initialisation function.
 */
function init__ocf_forums()
{
    global $USER_ACCESS_CACHE;
    $USER_ACCESS_CACHE = array();
    global $CATEGORY_TITLES;
    $CATEGORY_TITLES = NULL;
    global $FORUM_TREE_SECURE_CACHE;
    $FORUM_TREE_SECURE_CACHE = mixed();
    global $ALL_FORUMS_STRUCT;
    $ALL_FORUMS_STRUCT = NULL;
}
Exemple #11
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     $award_types = $GLOBALS['SITE_DB']->query_select('award_types', array('*'));
     $out = array();
     foreach ($award_types as $award) {
         // Find out how many submissions we've had since the last award was given
         if (!file_exists(get_file_base() . '/sources/hooks/systems/awards/' . filter_naughty_harsh($award['a_content_type']) . '.php') && !file_exists(get_file_base() . '/sources_custom/hooks/systems/awards/' . filter_naughty_harsh($award['a_content_type']) . '.php')) {
             continue;
         }
         require_code('hooks/systems/awards/' . $award['a_content_type']);
         $hook_object = object_factory('Hook_awards_' . $award['a_content_type'], true);
         if (is_null($hook_object)) {
             continue;
         }
         $details = $hook_object->info();
         if (!is_null($details)) {
             $date = $GLOBALS['SITE_DB']->query_value_null_ok('award_archive', 'date_and_time', array('a_type_id' => $award['id']), 'ORDER BY date_and_time DESC');
             $seconds_ago = mixed();
             $limit_hours = $award['a_update_time_hours'];
             if (!is_null($date)) {
                 $seconds_ago = time() - $date;
                 $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1;
             } else {
                 $status = 0;
             }
             $config_url = build_url(array('page' => 'admin_awards', 'type' => '_ed', 'id' => $award['id']), get_module_zone('admin_awards'));
             $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
             $url = $details['add_url'];
             if (is_object($url)) {
                 $url = $url->evaluate();
             }
             $url = str_replace('=!', '_ignore=1', $url);
             $task = escape_html(get_translated_text($award['a_title']));
             if (!is_null($date) && !is_null($details['date_field'])) {
                 $where = filter_naughty_harsh($details['date_field']) . '>' . strval(intval($date));
                 $num_queue = $details['connection']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $details['connection']->get_table_prefix() . str_replace('1=1', $where, $details['table']) . ' r WHERE ' . $where);
                 $_num_queue = integer_format($num_queue);
                 $num_new_since = do_lang_tempcode('NUM_NEW_SINCE', $_num_queue);
             } else {
                 $num_new_since = new ocp_tempcode();
             }
             list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
             $info->attach($num_new_since);
             $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => '4049affae5a6f38712ee3e0237a2e18e', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => $task, 'INFO' => $info));
             $out[] = array($tpl, $seconds_due_in, NULL, NULL);
         }
     }
     return $out;
 }
/**
 * @license		http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright	ocProducts Ltd
 * @package		activity_feed
 */
function activities_addon_syndicate_described_activity($a_language_string_code = '', $a_label_1 = '', $a_label_2 = '', $a_label_3 = '', $a_pagelink_1 = '', $a_pagelink_2 = '', $a_pagelink_3 = '', $a_addon = '', $a_is_public = 1, $a_member_id = NULL, $sitewide_too = false, $a_also_involving = NULL)
{
    require_code('activities');
    require_lang('activities');
    if (get_db_type() == 'xml' && get_param_integer('keep_testing_logging', 0) != 1) {
        return NULL;
    }
    $stored_id = 0;
    if (is_null($a_member_id)) {
        $a_member_id = get_member();
    }
    if (is_guest($a_member_id)) {
        return NULL;
    }
    $go = array('a_language_string_code' => $a_language_string_code, 'a_label_1' => $a_label_1, 'a_label_2' => $a_label_2, 'a_label_3' => $a_label_3, 'a_is_public' => $a_is_public);
    $stored_id = mixed();
    // Check if this has been posted previously (within the last 10 minutes) to
    // stop spamming but allow generalised repeat status messages.
    $test = $GLOBALS['SITE_DB']->query_select('activities', array('a_language_string_code', 'a_label_1', 'a_label_2', 'a_label_3', 'a_is_public'), NULL, 'WHERE a_time>' . strval(time() - 600), 1);
    if (!array_key_exists(0, $test) || $test[0] != $go || running_script('execute_temp')) {
        // Log the activity
        $row = $go + array('a_member_id' => $a_member_id, 'a_also_involving' => $a_also_involving, 'a_pagelink_1' => $a_pagelink_1, 'a_pagelink_2' => $a_pagelink_2, 'a_pagelink_3' => $a_pagelink_3, 'a_time' => time(), 'a_addon' => $a_addon, 'a_is_public' => $a_is_public);
        $stored_id = $GLOBALS['SITE_DB']->query_insert('activities', $row, true);
        // Update the latest activity file
        log_newest_activity($stored_id, 1000);
        // External places
        if ($a_is_public == 1 && !$GLOBALS['IS_ACTUALLY_ADMIN']) {
            $dests = find_all_hooks('systems', 'syndication');
            foreach (array_keys($dests) as $hook) {
                require_code('hooks/systems/syndication/' . $hook);
                $ob = object_factory('Hook_Syndication_' . $hook);
                if ($ob->is_available()) {
                    $ob->syndicate_user_activity($a_member_id, $row);
                    if ($sitewide_too && has_specific_permission(get_member(), 'syndicate_site_activity') && post_param_integer('syndicate_this', 0) == 1) {
                        $ob->syndicate_site_activity($row);
                    }
                }
            }
        }
        list($message) = render_activity($row, false);
        require_code('notifications');
        $username = $GLOBALS['FORUM_DRIVER']->get_username($a_member_id);
        $subject = do_lang('ACTIVITY_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $username, html_entity_decode(strip_tags($message->evaluate()), ENT_QUOTES, get_charset()));
        $mail = do_lang('ACTIVITY_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($username), array('[semihtml]' . $message->evaluate() . '[/semihtml]'));
        dispatch_notification('activity', strval($a_member_id), $subject, $mail);
    }
    return $stored_id;
}
Exemple #13
0
 /**
  * Standard modular run function.
  *
  * @return array		An array of tuples: The task row to show, the number of seconds until it is due (or NULL if not on a timer), the number of things to sort out (or NULL if not on a queue), The name of the config option that controls the schedule (or NULL if no option).
  */
 function run()
 {
     if (!addon_installed('news')) {
         return array();
     }
     if (get_option('blog_update_time') == '') {
         return array();
     }
     require_lang('news');
     $admin_groups = array_merge($GLOBALS['FORUM_DRIVER']->get_super_admin_groups(), $GLOBALS['FORUM_DRIVER']->get_moderator_groups());
     $staff = $GLOBALS['FORUM_DRIVER']->member_group_query(array_keys($admin_groups), 100);
     if (count($staff) >= 100) {
         return array();
     }
     $or_list = '';
     foreach (array_keys($staff) as $staff_id) {
         if ($or_list != '') {
             $or_list .= ' OR ';
         }
         $or_list .= 'c.nc_owner=' . strval($staff_id);
     }
     if ($or_list == '') {
         return array();
     }
     $query = 'SELECT MAX(date_and_time) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news n JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON n.news_category=c.id WHERE validated=1 AND (' . $or_list . ')';
     $date = $GLOBALS['SITE_DB']->query_value_null_ok_full($query);
     $limit_hours = intval(get_option('blog_update_time'));
     $seconds_ago = mixed();
     if (!is_null($date)) {
         $status = $seconds_ago > $limit_hours * 60 * 60 ? 0 : 1;
     } else {
         $status = 0;
     }
     $_status = $status == 0 ? do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_0') : do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM_STATUS_1');
     $config_row = $GLOBALS['SITE_DB']->query_select('config', array('the_page', 'section'), array('the_name' => 'blog_update_time'), '', 1);
     if (array_key_exists(0, $config_row)) {
         $_config_url = build_url(array('page' => 'admin_config', 'type' => 'category', 'id' => $config_row[0]['the_page']), get_module_zone('admin_config'));
         $config_url = $_config_url->evaluate();
         $config_url .= '#group_' . $config_row[0]['section'];
     } else {
         $config_url = NULL;
     }
     $url = build_url(array('page' => 'cms_blogs', 'type' => 'ad'), get_module_zone('cms_blogs'));
     list($info, $seconds_due_in) = staff_checklist_time_ago_and_due($seconds_ago, $limit_hours);
     $tpl = do_template('BLOCK_MAIN_STAFF_CHECKLIST_ITEM', array('_GUID' => 'a75d4a165aa5e16ad3aa06d2e0bab5db', 'CONFIG_URL' => $config_url, 'URL' => $url, 'STATUS' => $_status, 'TASK' => do_lang_tempcode('BLOG'), 'INFO' => $info));
     return array(array($tpl, $seconds_due_in, NULL, 'blog_update_time'));
 }
Exemple #14
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_comments') == '0') {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     $serialized_options = get_param('serialized_options', false, true);
     $hash = get_param('hash');
     if (best_hash($serialized_options, get_site_salt()) != $hash) {
         warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     secure_serialized_data($serialized_options);
     list($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, $reverse, $may_reply, $highlight_by_user, $allow_reviews) = unserialize($serialized_options);
     $posts = array_map('intval', explode(',', get_param('ids', false, true)));
     $_parent_id = get_param('id', '');
     $parent_id = $_parent_id == '' ? mixed() : intval($_parent_id);
     require_code('topics');
     $renderer = new OCP_Topic();
     return $renderer->render_posts_from_topic($topic_id, $num_to_show_limit, $allow_comments, $invisible_if_no_comments, $forum, NULL, $reverse, $may_reply, $highlight_by_user, $allow_reviews, $posts, $parent_id);
 }
Exemple #15
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('clear_caches', array('h'), array(true)), '', '');
     } else {
         require_code('view_modes');
         $_caches = mixed();
         if (array_key_exists(0, $parameters)) {
             $_caches = array();
             $caches = explode(',', $parameters[0]);
             foreach ($caches as $cache) {
                 $_caches[] = trim($cache);
             }
         }
         $messages = static_evaluate_tempcode(ocportal_cleanup($_caches));
         if ($messages == '') {
             $messages = do_lang('SUCCESS');
         }
         return array('', $messages, '', '');
     }
 }
Exemple #16
0
 /**
  * Standard modular run function for OcCLE hooks.
  *
  * @param  array	The options with which the command was called
  * @param  array	The parameters with which the command was called
  * @param  array	A reference to the OcCLE filesystem object
  * @return array	Array of stdcommand, stdhtml, stdout, and stderr responses
  */
 function run($options, $parameters, &$occle_fs)
 {
     require_code('lookup');
     if (array_key_exists('h', $options) || array_key_exists('help', $options)) {
         return array('', do_command_help('whois', array('h', 's', 'm', 'f', 'o'), array(true)), '', '');
     } else {
         if (!array_key_exists(0, $parameters)) {
             return array('', '', '', do_lang('MISSING_PARAM', '1', 'whois'));
         }
         $start = array_key_exists('s', $options) ? intval($options['s']) : 0;
         $start = array_key_exists('start', $options) ? intval($options['start']) : 0;
         $max = array_key_exists('m', $options) ? intval($options['m']) : 50;
         $max = array_key_exists('max', $options) ? intval($options['max']) : 50;
         $sortable = array_key_exists('f', $options) ? $options['f'] : 'date_and_time';
         $sortable = array_key_exists('field', $options) ? $options['field'] : 'date_and_time';
         $sort_order = array_key_exists('o', $options) ? $options['o'] : 'DESC';
         $sort_order = array_key_exists('order', $options) ? $options['order'] : 'DESC';
         $name = mixed();
         $id = mixed();
         $ip = mixed();
         $rows = lookup_member_page($parameters[0], $name, $id, $ip);
         if (is_null($name)) {
             $name = do_lang('UNKNOWN');
         }
         if (is_null($id)) {
             $id = $GLOBALS['FORUM_DRIVER']->get_guest_id();
         }
         if (is_null($ip)) {
             $ip = '';
         }
         $ip_list = new ocp_tempcode();
         foreach ($rows as $row) {
             $ip_list->attach(do_template('LOOKUP_IP_LIST_ENTRY', array('IP' => $row['ip'])));
         }
         $stats = get_stats_track($id, $ip, $start, $max, $sortable, $sort_order);
         return array('', occle_make_normal_html_visible(do_template('OCCLE_WHOIS', array('_GUID' => 'f315a705e9a2a2fb50b78ae3a8fc6a05', 'STATS' => $stats, 'IP_LIST' => $ip_list, 'ID' => strval($id), 'IP' => $ip, 'NAME' => $name))), '', '');
     }
 }
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     if (has_no_forum()) {
         return new ocp_tempcode();
     }
     require_css('news');
     // Read in variables
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     $limit = array_key_exists('limit', $map) ? intval($map['limit']) : 6;
     $hot = array_key_exists('hot', $map) ? intval($map['hot']) : 0;
     $date_key = array_key_exists('date_key', $map) ? $map['date_key'] : 'lasttime';
     if ($date_key != 'lasttime' && $date_key != 'firsttime') {
         $date_key = 'firsttime';
     }
     $username_key = array_key_exists('username_key', $map) ? $map['username_key'] : 'firstusername';
     if ($username_key != 'lastusername' && $username_key != 'firstusername') {
         $username_key = 'firstusername';
     }
     $memberid_key = $username_key == 'firstusername' ? 'firstmemberid' : 'lastmemberid';
     // Work out exactly what forums we're reading
     $forum_ids = array();
     if (get_forum_type() == 'ocf' && (strpos($forum_name, ',') !== false || strpos($forum_name, '*') !== false || preg_match('#\\d[-\\*\\+]#', $forum_name) != 0 || is_numeric($forum_name))) {
         require_code('ocfiltering');
         $forum_names = ocfilter_to_idlist_using_db($forum_name, 'id', 'f_forums', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']);
     } else {
         $forum_names = explode(',', $forum_name);
     }
     foreach ($forum_names as $forum_name) {
         if (!is_string($forum_name)) {
             $forum_name = strval($forum_name);
         }
         $forum_name = trim($forum_name);
         if ($forum_name == '<announce>') {
             $forum_id = NULL;
         } else {
             $forum_id = is_numeric($forum_name) ? intval($forum_name) : $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum_name);
         }
         if (get_forum_type() == 'ocf' && array_key_exists('check', $map) && $map['check'] == '1') {
             if (!has_category_access(get_member(), 'forums', strval($forum_id))) {
                 continue;
             }
         }
         if (!is_null($forum_id)) {
             $forum_ids[$forum_id] = $forum_name;
         }
     }
     // Block title
     $forum_name = array_key_exists('param', $map) ? $map['param'] : 'General chat';
     if (is_numeric($forum_name) && get_forum_type() == 'ocf') {
         $forum_name = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_name', array('id' => intval($forum_name)));
         if (is_null($forum_name)) {
             return paragraph(do_lang_tempcode('MISSING_RESOURCE'));
         }
     }
     $_title = do_lang_tempcode('ACTIVE_TOPICS_IN', escape_html($forum_name));
     if (array_key_exists('title', $map) && $map['title'] != '') {
         $_title = protect_from_escaping(escape_html($map['title']));
     }
     // Add topic link
     if (count($forum_names) == 1 && get_forum_type() == 'ocf' && !is_null($forum_id)) {
         $submit_url = build_url(array('page' => 'topics', 'type' => 'new_topic', 'id' => $forum_id), get_module_zone('topics'));
         $add_name = do_lang_tempcode('ADD_TOPIC');
     } else {
         $submit_url = new ocp_tempcode();
         $add_name = new ocp_tempcode();
     }
     // Show all topics
     if (get_forum_type() == 'ocf') {
         $forum_names_map = collapse_2d_complexity('id', 'f_name', $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0'));
     } else {
         $forum_names_map = NULL;
     }
     if (!has_no_forum()) {
         $max_rows = 0;
         $topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key, $hot == 1);
         $out = new ocp_tempcode();
         if (!is_null($topics)) {
             global $M_SORT_KEY;
             $M_SORT_KEY = $date_key;
             usort($topics, 'multi_sort');
             $topics = array_reverse($topics, false);
             if (count($topics) < $limit && $hot == 1) {
                 $more_topics = $GLOBALS['FORUM_DRIVER']->show_forum_topics($forum_ids, $limit, 0, $max_rows, '', true, $date_key);
                 if (is_null($more_topics)) {
                     $more_topics = array();
                 }
                 $topics = array_merge($topics, $more_topics);
             }
             $done = 0;
             $seen = array();
             foreach ($topics as $topic) {
                 if (array_key_exists($topic['id'], $seen)) {
                     continue;
                 }
                 $seen[$topic['id']] = 1;
                 $topic_url = $GLOBALS['FORUM_DRIVER']->topic_url($topic['id'], $forum_name);
                 $topic_url_unread = mixed();
                 if (get_forum_type() == 'ocf') {
                     $topic_url_unread = build_url(array('page' => 'topicview', 'id' => $topic['id'], 'type' => 'first_unread'), get_module_zone('topicview'), NULL, false, false, false, 'first_unread');
                 }
                 $title = escape_html($topic['title']);
                 $date = get_timezoned_date($topic[$date_key]);
                 $username = $topic[$username_key];
                 $member_id = array_key_exists($memberid_key, $topic) ? $topic[$memberid_key] : NULL;
                 if (!is_null($forum_names_map) && !array_key_exists($topic['forum_id'], $forum_names_map)) {
                     continue;
                 }
                 // Maybe Private Topic, slipped in via reference to a missing forum
                 $forum_name = is_null($forum_names_map) ? NULL : $forum_names_map[$topic['forum_id']];
                 $out->attach(do_template('BLOCK_MAIN_FORUM_TOPICS_TOPIC', array('_GUID' => 'ae4e351b3fa5422bf8ecdfb7e49076d1', 'POST' => $topic['firstpost'], 'FORUM_ID' => is_null($forum_names_map) ? NULL : strval($topic['forum_id']), 'FORUM_NAME' => $forum_name, 'TOPIC_LINK' => $topic_url, 'TOPIC_LINK_UNREAD' => $topic_url_unread, 'TITLE' => $title, 'DATE' => $date, 'DATE_RAW' => strval($topic[$date_key]), 'USERNAME' => $username, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'NUM_POSTS' => integer_format($topic['num']))));
                 $done++;
                 if ($done == $limit) {
                     break;
                 }
             }
         }
         if ($out->is_empty()) {
             return do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'c76ab018a0746c2875c6cf69c92a01fb', 'HIGH' => false, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($hot == 1 ? 'NO_TOPICS_HOT' : 'NO_TOPICS'), 'ADD_NAME' => $add_name, 'SUBMIT_URL' => $submit_url));
         }
         return do_template('BLOCK_MAIN_FORUM_TOPICS', array('_GUID' => '368b80c49a335ad035b00510681d5008', 'TITLE' => $_title, 'CONTENT' => $out, 'FORUM_NAME' => array_key_exists('param', $map) ? $map['param'] : 'General chat', 'SUBMIT_URL' => $submit_url));
     } else {
         return new ocp_tempcode();
     }
 }
/**
 * Get a tempcoded version of a normal XHTML template. It is perhaps the most common ocPortal function to load up templates using do_template, and then attach them together either as parameters to each other, or via the tempcode attach method.
 *
 * @param  ID_TEXT			The codename of the template being loaded
 * @param  ?array				A map of parameters for the template (key to value) (NULL: no parameters)
 * @param  ?LANGUAGE_NAME 	The language to load the template in (templates can embed language references) (NULL: users own language)
 * @param  boolean			Whether to not produce a stack dump if the template is missing
 * @param  ?ID_TEXT			Alternate template to use if the primary one does not exist (NULL: none)
 * @param  string				File type suffix of template file (e.g. .tpl)
 * @param  string				Subdirectory type to look in
 * @set    templates css
 * @param  ID_TEXT			Theme to use
 * @return tempcode			The tempcode for this template
 */
function do_template($codename, $parameters = NULL, $lang = NULL, $light_error = false, $fallback = NULL, $suffix = '.tpl', $type = 'templates', $theme = NULL)
{
    if (is_null($lang) || $lang == '') {
        global $USER_LANG_CACHED;
        $lang = isset($USER_LANG_CACHED) ? $USER_LANG_CACHED : (function_exists('user_lang') ? user_lang() : 'EN');
    }
    if ($GLOBALS['SEMI_DEBUG_MODE']) {
        if ($codename != 'tempcode_test' && $codename != 'handle_conflict_resolution' && strtoupper($codename) != strtoupper($codename)) {
            fatal_exit('Template names should be in upper case, and the files should be stored in upper case.');
        }
        if (substr($codename, -7) == '_SCREEN' || $codename == 'POOR_XHTML_WRAPPER' || $codename == 'OCF_WRAPPER') {
            $GLOBALS['SCREEN_TEMPLATE_CALLED'] = $codename;
        }
    }
    if (is_null($parameters)) {
        $parameters = array();
    }
    global $RECORD_TEMPLATES_USED, $FILE_ARRAY, $MEM_CACHE, $CACHE_TEMPLATES, $KEEP_MARKERS, $SHOW_EDIT_LINKS, $XHTML_SPIT_OUT, $TEMPLATE_CACHE, $MOBILE, $FORUM_DRIVER;
    $special_treatment = ($KEEP_MARKERS || $SHOW_EDIT_LINKS) && is_null($XHTML_SPIT_OUT);
    // Is it already loaded?
    if ($RECORD_TEMPLATES_USED) {
        global $RECORDED_TEMPLATES_USED;
        $RECORDED_TEMPLATES_USED[] = $codename;
    }
    // Variables we'll need
    if (!isset($theme)) {
        $theme = isset($FORUM_DRIVER) && is_object($FORUM_DRIVER) && method_exists($FORUM_DRIVER, 'get_theme') ? filter_naughty($FORUM_DRIVER->get_theme()) : 'default';
    }
    $_codename = $MOBILE ? $codename . '_mobile' : $codename;
    if (isset($TEMPLATE_CACHE[$theme][$codename][$lang])) {
        $_data = $TEMPLATE_CACHE[$theme][$codename][$lang]->bind($parameters, $codename);
        // Copy and pasted to remove need for an function call
        if ($special_treatment) {
            if ($KEEP_MARKERS) {
                $__data = make_string_tempcode('<!-- START-TEMPLATE=' . $codename . ' -->');
                $__data->attach($_data);
                $__data->attach('<!-- END-TEMPLATE=' . $codename . ' -->');
                $_data = $__data;
            }
            if ($SHOW_EDIT_LINKS) {
                $edit_url = build_url(array('page' => 'admin_themes', 'theme' => $FORUM_DRIVER->get_theme(), 'template' => $codename), 'adminzone');
                $_data->attach('<br /><a href="' . escape_html($edit_url->evaluate()) . '">' . do_lang('EDIT') . ' ' . $codename . '</a>');
            }
        }
        return $_data;
    }
    // Is it structurally cached on disk yet?
    $data = mixed();
    if ($CACHE_TEMPLATES) {
        if (!is_null($MEM_CACHE)) {
            $data = persistant_cache_get(array('TEMPLATE', $theme, $lang, $_codename));
            if (!is_null($data)) {
                $_data = new ocp_tempcode();
                $_data->from_assembly($data);
                if ($_data->bits == array()) {
                    $data = false;
                }
                // Corrupt somehow
            } else {
                $data = false;
            }
        } elseif (is_null($data)) {
            $_data = new ocp_tempcode();
            $tcp_path = get_custom_file_base() . '/themes/' . $theme . '/templates_cached/' . $lang . '/' . $_codename . $suffix . '.tcd';
            $data = @file_get_contents($tcp_path, FILE_BINARY);
            if ($data === '') {
                $data = false;
            }
            // '' needed for PHP4 - weird
            if ($data !== false) {
                $_data->from_assembly($data);
                if ($_data->bits == array()) {
                    $data = false;
                }
                // Corrupt somehow
            }
        }
    } else {
        $data = false;
    }
    if ($data === false) {
        if (!isset($FILE_ARRAY)) {
            $_data = NULL;
            $prefix_default = get_file_base() . '/themes/';
            $prefix = $theme == 'default' ? $prefix_default : get_custom_file_base() . '/themes/';
            if (file_exists($prefix . $theme . '/' . $type . '_custom/' . $_codename . $suffix)) {
                $_data = _do_template($theme, '/' . $type . '_custom/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif (file_exists($prefix . $theme . '/' . $type . '/' . $_codename . $suffix)) {
                $_data = _do_template($theme, '/' . $type . '/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif (!is_null($GLOBALS['CURRENT_SHARE_USER']) && $theme != 'default' && file_exists($prefix_default . $theme . '/' . $type . '_custom/' . $_codename . $suffix)) {
                $_data = _do_template($theme, '/' . $type . '_custom/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif (!is_null($GLOBALS['CURRENT_SHARE_USER']) && $theme != 'default' && file_exists($prefix_default . $theme . '/' . $type . '/' . $_codename . $suffix)) {
                $_data = _do_template($theme, '/' . $type . '/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif (file_exists($prefix_default . 'default' . '/' . $type . '_custom/' . $_codename . $suffix)) {
                $_data = _do_template('default', '/' . $type . '_custom/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif (file_exists($prefix_default . 'default' . '/' . $type . '/' . $_codename . $suffix)) {
                $_data = _do_template('default', '/' . $type . '/', $_codename, $_codename, $lang, $suffix, $theme);
            } elseif ($codename != $_codename) {
                if (file_exists($prefix . $theme . '/' . $type . '_custom/' . $codename . $suffix)) {
                    $_data = _do_template($theme, '/' . $type . '_custom/', $codename, $_codename, $lang, $suffix, $theme);
                } elseif (file_exists($prefix . $theme . '/' . $type . '/' . $codename . $suffix)) {
                    $_data = _do_template($theme, '/' . $type . '/', $codename, $_codename, $lang, $suffix, $theme);
                } elseif (file_exists($prefix_default . 'default' . '/' . $type . '_custom/' . $codename . $suffix)) {
                    $_data = _do_template('default', '/' . $type . '_custom/', $codename, $_codename, $lang, $suffix, $theme);
                } elseif (file_exists($prefix_default . 'default' . '/' . $type . '/' . $codename . $suffix)) {
                    $_data = _do_template('default', '/' . $type . '/', $codename, $_codename, $lang, $suffix, $theme);
                }
            }
            if (is_null($_data)) {
                if (is_null($fallback)) {
                    if ($light_error) {
                        return paragraph(do_lang_tempcode('MISSING_TEMPLATE_FILE', escape_html($codename)));
                    }
                    fatal_exit(do_lang_tempcode('MISSING_TEMPLATE_FILE', escape_html($codename)));
                } else {
                    $result = do_template($fallback, $parameters, $lang);
                    $TEMPLATE_CACHE[$theme][$codename][$lang] = $TEMPLATE_CACHE[$fallback][$lang];
                    return $result;
                }
            }
        } else {
            $_data = _do_template('default', '/' . $type . '/', $codename, $codename, $lang, $suffix, $theme);
        }
    }
    $TEMPLATE_CACHE[$theme][$codename][$lang] = $_data;
    $ret = $_data->bind($parameters, $codename);
    if ($special_treatment) {
        if ($KEEP_MARKERS) {
            $__data = new ocp_tempcode();
            $__data->attach('<!-- START-TEMPLATE=' . $codename . ' -->');
            $__data->attach($ret);
            $__data->attach('<!-- END-TEMPLATE=' . $codename . ' -->');
            $ret = $__data;
        }
        if ($SHOW_EDIT_LINKS && $codename != 'PARAM_INFO') {
            $param_info = do_template('PARAM_INFO', array('MAP' => $parameters));
            $edit_url = build_url(array('page' => 'admin_themes', 'theme' => $FORUM_DRIVER->get_theme(), 'template' => $codename), 'adminzone');
            $SHOW_EDIT_LINKS = false;
            $ret = do_template('TEMPLATE_EDIT_LINK', array('_GUID' => '511ae911d31a5b237a4371ff22fc78fd', 'PARAM_INFO' => $param_info, 'CONTENTS' => $ret, 'CODENAME' => $codename, 'EDIT_URL' => $edit_url));
            $SHOW_EDIT_LINKS = true;
        }
    }
    return $ret;
}
/**
 * Initialise our aSpell calling environment.
 *
 * @return array			A tuple of environmental details (dictionary list,aspell call command,temporary file name,language being used)
 */
function aspell_init()
{
    // Find the language
    if (!isset($_REQUEST['dictionary']) || strlen(trim($_REQUEST['dictionary'])) < 1) {
        $lang = function_exists('do_lang') ? do_lang('dictionary') : 'en_GB';
        // Default to UK English (as per ocPortal)
    } else {
        $lang = $_REQUEST['dictionary'];
    }
    $aspellcommand = mixed();
    $force_shell = false;
    if (!function_exists('pspell_check') || $force_shell) {
        if (str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1') {
            exit('Spell Checker does not work with safe mode systems that do not have direct pspell support into PHP');
        }
        if (strpos(@ini_get('disable_functions'), 'shell_exec') !== false) {
            exit('Spell Checker does not work on systems with shell_exec disabled that do not have direct pspell support into PHP');
        }
        // Our temporary spell check file
        $temptext = tempnam(str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1' || @strval(ini_get('open_basedir')) != '' && preg_match('#(^|:|;)/tmp($|:|;|/)#', ini_get('open_basedir')) == 0 ? get_custom_file_base() . '/safe_mode_temp/' : '/tmp/', 'spell_');
        if ($temptext === false) {
            $temptext = tempnam(get_custom_file_base() . '/safe_mode_temp/', 'spell_');
        }
        // Find aspell
        $aspell = 'aspell';
        $aspell_args = '-a --lang=' . _filter_naughty_harsh($lang);
        if (DIRECTORY_SEPARATOR == '\\') {
            // See if there is a local install of aspell here
            if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell.exe')) {
                $aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell.exe';
                if (file_exists(dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe')) {
                    $aspell = dirname(__FILE__) . '\\aspell\\bin\\aspell_wrap.exe ' . dirname(__FILE__) . '\\aspell\\bin\\';
                }
                //$dic_dir=wrap_exec($aspell.' config dict-dir');
                //$dicfil=preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
                //$aspell_args.=' --dict-dir='.$dicfil;
            } else {
                $aspell = 'C:\\Progra~1\\Aspell\\bin\\aspell.exe';
            }
            if (!file_exists($aspell)) {
                exit('ASpell not installed in default locations.');
            }
            $aspell_version = wrap_exec($aspell . ' version');
        } else {
            // See if there is a local install of aspell here
            if (file_exists(dirname(__FILE__) . '/aspell/bin/aspell')) {
                putenv('PATH=' . dirname(__FILE__) . '/aspell/bin:' . getenv('PATH'));
                putenv('LD_LIBRARY_PATH=' . dirname(__FILE__) . '/aspell/lib:' . getenv('LD_LIBRARY_PATH'));
                //$dic_dir=wrap_exec($aspell.' config dict-dir');
                //$dicfil=dirname(__FILE__).'/aspell/lib/'.preg_replace('/^.*\/lib\/(aspell\S*)\n.*/s','$1',$dic_dir);
                //$aspell_args.=' --dict-dir='.$dicfil.' --add-filter-path='.$dicfil;
            }
            $aspell_version = wrap_exec($aspell . ' version');
        }
        if ($aspell_version === false) {
            exit('ASpell would not execute. It is most likely not installed, or a security measure is in place, or file permissions are not correctly set. If on Windows, you may need to give windows\\system32\\cmd.exe execute permissions to the web user.');
        }
        // Old aspell doesn't know about encoding, which means that unicode will be broke, but we should at least let it try.
        $a_ver = array();
        preg_match('/really [aA]spell ([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?/i', $aspell_version, $a_ver);
        if (!array_key_exists(1, $a_ver)) {
            $a_ver[1] = '1';
        }
        if (!array_key_exists(2, $a_ver)) {
            $a_ver[2] = '0';
        }
        if (!array_key_exists(3, $a_ver)) {
            $a_ver[3] = '0';
        }
        $a_ver = array('major' => (int) $a_ver[1], 'minor' => (int) $a_ver[2], 'release' => (int) $a_ver[3]);
        if ($a_ver['major'] >= 0 && $a_ver['minor'] >= 60) {
            $aspell_args .= ' -H --encoding=utf-8';
        } elseif (preg_match('/--encoding/', wrap_exec($aspell . ' 2>&1')) != 0) {
            $aspell_args .= ' --mode=none --add-filter=sgml --encoding=utf-8';
        } else {
            $aspell_args .= ' --mode=none --add-filter=sgml';
        }
        $aspelldictionaries = $aspell . ' dump dicts';
        $aspellcommand = $aspell . ' ' . $aspell_args . ' < ' . $temptext;
    } else {
        //list($lang,$spelling)=explode('_',$lang);
        $spelling = '';
        $temptext = NULL;
        $aspelldictionaries = NULL;
    }
    // Personal dictionaries
    global $SITE_INFO;
    if (!isset($SITE_INFO)) {
        require_once '../../../../info.php';
    }
    $cookie_member_id = $SITE_INFO['user_cookie'];
    $p_dicts_name = array_key_exists($cookie_member_id, $_COOKIE) ? _filter_naughty_harsh($_COOKIE[$cookie_member_id]) : 'guest';
    $p_dict_path = get_custom_file_base() . '/data_custom/spelling/personal_dicts' . DIRECTORY_SEPARATOR . $p_dicts_name;
    if (!file_exists($p_dict_path)) {
        mkdir($p_dict_path, 02770);
    }
    if (is_null($temptext)) {
        list($lang_stub, ) = explode('_', $lang);
        $charset = str_replace('ISO-', 'iso', str_replace('iso-', 'iso', do_lang('charset')));
        if (DIRECTORY_SEPARATOR == '\\') {
            $aspellcommand = @pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
            if ($aspellcommand === false) {
                $aspellcommand = pspell_new_personal($p_dict_path . '/' . $lang_stub . '.pws', $lang, $spelling, '', $charset);
            }
        } else {
            $aspellconfig = @pspell_config_create($lang, $spelling, '', $charset);
            if ($aspellconfig === false) {
                $aspellconfig = pspell_config_create('en', $spelling, '', $charset);
            }
            pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
            pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
            $aspellcommand = @pspell_new_config($aspellconfig);
            if ($aspellcommand === false && $lang != 'en') {
                $aspellconfig = pspell_config_create('en', $spelling, '', $charset);
                pspell_config_personal($aspellconfig, $p_dict_path . '/' . $lang_stub . '.pws');
                pspell_config_repl($aspellconfig, $p_dict_path . '/' . $lang_stub . '.prepl');
                $aspellcommand = pspell_new_config($aspellconfig);
            }
        }
        if (is_null($aspellcommand)) {
            exit;
        }
    }
    return array($aspelldictionaries, $aspellcommand, $temptext, $lang);
}
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;
}
Exemple #21
0
 /**
  * Standard modular UI/actualiser to edit an entry.
  *
  * @return tempcode	The UI
  */
 function __ed()
 {
     $id = mixed();
     // Define type as mixed
     $id = $this->non_integer_id ? get_param('id', false, true) : strval(get_param_integer('id'));
     $doing = 'EDIT_' . $this->lang_type;
     if ($this->catalogue && get_param('catalogue_name', '') != '') {
         $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name'))));
         if ($this->type_code == 'd') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT', escape_html($catalogue_title));
         } elseif ($this->type_code == 'c') {
             $doing = do_lang('CATALOGUE_GENERIC_EDIT_CATEGORY', escape_html($catalogue_title));
         }
     }
     $title = get_page_title($doing);
     if ($this->second_stage_preview && get_param_integer('preview', 0) == 1) {
         return $this->preview_intercept($title);
     }
     if (method_exists($this, 'get_submitter')) {
         list($submitter, $date_and_time) = $this->get_submitter($id);
         if (!is_null($date_and_time) && addon_installed('points')) {
             $reverse = post_param_integer('reverse_point_transaction', 0);
             if ($reverse == 1) {
                 $points_test = $GLOBALS['SITE_DB']->query_select('gifts', array('*'), array('date_and_time' => $date_and_time, 'gift_to' => $submitter, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id()));
                 if (array_key_exists(0, $points_test)) {
                     $amount = $points_test[0]['amount'];
                     $sender_id = $points_test[0]['gift_from'];
                     $recipient_id = $points_test[0]['gift_to'];
                     $GLOBALS['SITE_DB']->query_delete('gifts', array('id' => $points_test[0]['id']), '', 1);
                     if (!is_guest($sender_id)) {
                         $_sender_gift_points_used = point_info($sender_id);
                         $sender_gift_points_used = array_key_exists('gift_points_used', $_sender_gift_points_used) ? $_sender_gift_points_used['gift_points_used'] : 0;
                         $GLOBALS['FORUM_DRIVER']->set_custom_field($sender_id, 'gift_points_used', strval($sender_gift_points_used - $amount));
                     }
                     require_code('points');
                     $temp_points = point_info($recipient_id);
                     $GLOBALS['FORUM_DRIVER']->set_custom_field($recipient_id, 'points_gained_given', strval((array_key_exists('points_gained_given', $temp_points) ? $temp_points['points_gained_given'] : 0) - $amount));
                 }
             }
         }
     } else {
         $submitter = NULL;
     }
     breadcrumb_set_parents(array_merge($GLOBALS['BREADCRUMB_SET_PARENTS'], array(array('_SELF:_SELF:_e' . $this->type_code . ':' . $id, strpos($doing, ' ') !== false ? protect_from_escaping($doing) : do_lang_tempcode($doing)))));
     $delete = post_param_integer('delete', 0);
     if ($delete == 1 || $delete == 2) {
         if (!is_null($this->permissions_require)) {
             check_delete_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name);
         }
         $doing = 'DELETE_' . $this->lang_type;
         if ($this->catalogue && get_param('catalogue_name', '') != '') {
             $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => get_param('catalogue_name'))));
             if ($this->type_code == 'd') {
                 $doing = do_lang('CATALOGUE_GENERIC_DELETE', escape_html($catalogue_title));
             } elseif ($this->type_code == 'c') {
                 $doing = do_lang('CATALOGUE_GENERIC_DELETE_CATEGORY', escape_html($catalogue_title));
             }
         }
         $title = get_page_title($doing);
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         $this->delete_actualisation($id);
         // Delete custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             delete_form_custom_fields($this->award_type, $id);
         }
         /*if ((!is_null($this->redirect_type)) || ((!is_null(get_param('redirect',NULL)))))		No - resource is gone now, and redirect would almost certainly try to take us back there
         		{
         			$url=(($this->redirect_type=='!') || (is_null($this->redirect_type)))?get_param('redirect'):build_url(array('page'=>'_SELF','type'=>$this->redirect_type),'_SELF');
         			return redirect_screen($title,$url,do_lang_tempcode('SUCCESS'));
         		}*/
         clear_ocp_autosave();
         $description = is_null($this->do_next_description) ? do_lang_tempcode('SUCCESS') : $this->do_next_description;
         return $this->do_next_manager($title, $description, NULL);
     } else {
         if (!is_null($this->permissions_require)) {
             check_edit_permission($this->permissions_require, $submitter, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? NULL : $this->get_cat($id), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? NULL : $this->get_cat_b($id)), $this->permission_page_name);
         }
         $test = $this->handle_confirmations($title);
         if (!is_null($test)) {
             return $test;
         }
         if ($this->user_facing && !is_null($this->permissions_require) && array_key_exists('validated', $_POST)) {
             if (!has_specific_permission(get_member(), 'bypass_validation_' . $this->permissions_require . 'range_content', $this->permission_page_name, array($this->permissions_cat_require, is_null($this->permissions_cat_name) ? '' : post_param($this->permissions_cat_name), $this->permissions_cat_require_b, is_null($this->permissions_cat_name_b) ? '' : post_param($this->permissions_cat_name_b)))) {
                 $_POST['validated'] = '0';
             }
         }
         if (!is_null($this->upload)) {
             require_code('uploads');
         }
         $description = $this->edit_actualisation($id);
         if (!is_null($this->new_id)) {
             $id = $this->new_id;
         }
         // Save custom fields
         if ($this->has_tied_catalogue()) {
             require_code('fields');
             save_form_custom_fields($this->award_type, $id);
         }
         if ($this->output_of_action_is_confirmation && !is_null($description)) {
             return $description;
         }
         if (is_null($description)) {
             $description = do_lang_tempcode('SUCCESS');
         }
         if (addon_installed('awards')) {
             if (!is_null($this->award_type)) {
                 require_code('awards');
                 handle_award_setting($this->award_type, $id);
             }
         }
         if ($this->user_facing) {
             if ($this->check_validation && post_param_integer('validated', 0) == 0) {
                 require_code('submit');
                 if ($this->send_validation_request) {
                     $edit_url = build_url(array('page' => '_SELF', 'type' => '_e' . $this->type_code, 'id' => $id, 'validated' => 1), '_SELF', NULL, false, false, true);
                     if (addon_installed('unvalidated')) {
                         send_validation_request($doing, $this->table, $this->non_integer_id, $id, $edit_url);
                     }
                 }
                 $description->attach(paragraph(do_lang_tempcode('SUBMIT_UNVALIDATED')));
             }
         }
     }
     if (!is_null($this->redirect_type) || !is_null(get_param('redirect', NULL))) {
         $url = $this->redirect_type == '!' || is_null($this->redirect_type) ? make_string_tempcode(get_param('redirect')) : build_url(array('page' => '_SELF', 'type' => $this->redirect_type), '_SELF');
         return redirect_screen($title, $url, do_lang_tempcode('SUCCESS'));
     }
     clear_ocp_autosave();
     decache('main_awards');
     return $this->do_next_manager($title, $description, $id);
 }
 /**
  * The UI to send a newsletter.
  *
  * @param  LONG_TEXT		Default newsletter to put in
  * @return tempcode		The UI
  */
 function send_gui($_existing = '')
 {
     // If this is a periodic newsletter, we make some changes to the regular
     // language strings.
     $periodic_action_raw = post_param('periodic_choice', '');
     $periodic_subject = '';
     $defaults = mixed();
     switch (preg_replace('#\\_\\d+$#', '', $periodic_action_raw)) {
         case 'remove_existing':
             // Remove whatever is already set. We don't need any changes for
             // this, but we do need a hidden form field.
             $periodic_action = 'remove';
             break;
         case 'replace_existing':
             // Make the current newsletter periodic. This requires language
             // fiddling.
             $periodic_action = 'replace';
             $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP');
             $periodic_id = intval(preg_replace('#^[^\\d]+#', '', $periodic_action_raw));
             $_defaults = $GLOBALS['SITE_DB']->query_select('newsletter_periodic', array('*'), array('id' => $periodic_id), '', 1);
             if (!array_key_exists(0, $_defaults)) {
                 warn_exit(do_lang_tempcode('MISSING_RESOURCE'));
             }
             $defaults = $_defaults[0];
             break;
         case 'make_periodic':
             // Make the current newsletter periodic. This requires language
             // fiddling.
             $periodic_action = 'make';
             $periodic_subject = do_lang('PERIODIC_SUBJECT_HELP');
             break;
         case 'no_change':
         default:
             // The default action is to leave the current settings as-is.
             $periodic_action = 'none';
             break;
     }
     $title = get_page_title('NEWSLETTER_SEND');
     $lang = choose_language($title);
     if (is_object($lang)) {
         return $lang;
     }
     $comcode_given = $_existing != '' && strpos($_existing, '<html') !== false;
     $_existing = post_param('message', $_existing);
     if ($_existing == '') {
         $from_news = get_param_integer('from_news', -1);
         if ($from_news != -1 && addon_installed('news')) {
             $rows = $GLOBALS['SITE_DB']->query_select('news', array('*'), array('id' => $from_news), 'ORDER BY id DESC', 1);
             if (!array_key_exists(0, $rows)) {
                 require_lang('news');
                 return warn_screen(get_page_title('NEWS'), do_lang_tempcode('MISSING_RESOURCE'));
             }
             $myrow = $rows[0];
             $_existing = get_translated_text($myrow['news_article'], NULL, $lang);
             if ($_existing == '') {
                 $_existing = get_translated_text($myrow['news'], NULL, $lang);
             }
         }
         $existing = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f42', 'CONTENT' => $_existing, 'LANG' => $lang));
     } else {
         $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f44', 'CONTENT' => $_existing, 'LANG' => $lang));
         if (strpos($default->evaluate(), '<html') !== false) {
             if ($comcode_given) {
                 $default = do_template('NEWSLETTER_DEFAULT', array('_GUID' => '53c02947915806e519fe14c318813f46', 'CONTENT' => comcode_to_tempcode($_existing), 'LANG' => $lang));
             }
             $existing = $default;
         } else {
             $existing = make_string_tempcode($_existing);
         }
     }
     $post_url = build_url(array('page' => '_SELF', 'type' => 'confirm', 'old_type' => get_param('type', '')), '_SELF');
     $submit_name = do_lang_tempcode('PREVIEW');
     $hidden = new ocp_tempcode();
     $hidden->attach(form_input_hidden('lang', $lang));
     // Build up form
     $fields = new ocp_tempcode();
     require_code('form_templates');
     $default_subject = get_option('newsletter_title');
     if (!is_null($defaults)) {
         $default_subject = $defaults['np_subject'];
     }
     if ($periodic_action != 'make' && $periodic_action != 'replace') {
         $default_subject .= ' - ' . get_timezoned_date(time(), false, false, false, true);
     }
     $default_subject = post_param('subject', $default_subject);
     $fields->attach(form_input_line_comcode(do_lang_tempcode('SUBJECT'), do_lang_tempcode('NEWSLETTER_DESCRIPTION_TITLE', $periodic_subject), 'subject', $default_subject, true));
     $in_full = post_param_integer('in_full', 0);
     $chosen_categories = post_param('chosen_categories', '');
     if ($periodic_action == 'make' || $periodic_action == 'replace') {
         // We are making a periodic newsletter. This means we need to pass
         // through the chosen categories
         if (!is_null($defaults)) {
             $chosen_categories = $defaults['np_message'];
             $in_full = $defaults['np_in_full'];
             $fields->attach(form_input_tick(do_lang_tempcode('EMBED_FULL_ARTICLES'), do_lang_tempcode('DESCRIPTION_EMBED_FULL_ARTICLES'), 'in_full', $in_full == 1));
             $fields->attach(form_input_huge(do_lang_tempcode('NEWSLETTER_CONTENT'), do_lang('NEWSLETTER_CONTENT_SELECT'), 'chosen_categories', $chosen_categories, true));
         } else {
             $hidden->attach(form_input_hidden('chosen_categories', $chosen_categories));
             $hidden->attach(form_input_hidden('in_full', strval($in_full)));
         }
         $hidden->attach(form_input_hidden('cutoff_day', post_param('cutoff_day')));
         $hidden->attach(form_input_hidden('cutoff_month', post_param('cutoff_month')));
         $hidden->attach(form_input_hidden('cutoff_year', post_param('cutoff_year')));
         $hidden->attach(form_input_hidden('cutoff_hour', post_param('cutoff_hour')));
         $hidden->attach(form_input_hidden('cutoff_minute', post_param('cutoff_minute')));
         $hidden->attach(form_input_hidden('message', $existing->evaluate()));
     } else {
         $hidden->attach(form_input_hidden('in_full', strval($in_full)));
         if (strpos($existing->evaluate(), '<html') === false) {
             $fields->attach(form_input_huge_comcode(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true));
         } else {
             $fields->attach(form_input_huge(do_lang_tempcode('MESSAGE'), do_lang_tempcode('DESCRIPTION_MESSAGE_NEWSLETTER'), 'message', $existing->evaluate(), true));
         }
     }
     if (addon_installed('calendar') && $periodic_action == 'none' && cron_installed()) {
         $fields->attach(form_input_date__scheduler(do_lang_tempcode('DEFER_TIME'), do_lang_tempcode('DESCRIPTION_DEFER_TIME'), 'schedule', true, true, true));
     }
     $from_email = post_param('from_email', get_option('staff_address'));
     if (!is_null($defaults)) {
         $from_email = post_param('from_email', $defaults['np_from_email']);
     }
     $fields->attach(form_input_email(do_lang_tempcode('FROM_EMAIL'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_EMAIL'), 'from_email', $from_email, true));
     $from_name = post_param('from_name', get_site_name());
     if (!is_null($defaults)) {
         $from_name = post_param('from_name', $defaults['np_from_name']);
     }
     $fields->attach(form_input_line(do_lang_tempcode('FROM_NAME'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_FROM_NAME'), 'from_name', $from_name, true));
     $_html_only = post_param_integer('html_only', NULL);
     if (is_null($_html_only)) {
         $html_only = strpos($existing->evaluate(), '<html') !== false;
         if (!is_null($defaults)) {
             $html_only = $defaults['np_html_only'];
         }
     } else {
         $html_only = $_html_only == 1;
     }
     if (get_value('force_html_only') === '1') {
         $hidden->attach(form_input_hidden('html_only', '1'));
     } else {
         $fields->attach(form_input_tick(do_lang_tempcode('HTML_ONLY'), do_lang_tempcode('DESCRIPTION_HTML_ONLY'), 'html_only', $html_only));
     }
     $l = new ocp_tempcode();
     $priority = post_param_integer('priority', 3);
     if (!is_null($defaults)) {
         $priority = post_param_integer('priority', $defaults['np_priority']);
     }
     for ($i = 1; $i <= 5; $i++) {
         $l->attach(form_input_list_entry(strval($i), $i == $priority, do_lang_tempcode('PRIORITY_' . strval($i))));
     }
     $fields->attach(form_input_list(do_lang_tempcode('PRIORITY'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_PRIORITY'), 'priority', $l));
     // Where to send to
     $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang_tempcode('CHOOSE_SEND_TO'))));
     $newsletters = $GLOBALS['SITE_DB']->query_select('newsletters', array('*'));
     foreach ($newsletters as $newsletter) {
         $level = post_param_integer(strval($newsletter['id']), post_param_integer('level', -1));
         $c4 = $this->count_level($newsletter['id'], 4, $lang);
         $c3 = $this->count_level($newsletter['id'], 3, $lang);
         $c2 = $this->count_level($newsletter['id'], 2, $lang);
         $c1 = $this->count_level($newsletter['id'], 1, $lang);
         if ($c1 != 0) {
             $newsletter_title = get_translated_text($newsletter['title']);
             $newsletter_description = get_translated_text($newsletter['description']);
             if ($c1 == $c2 && $c1 == $c3 && $c1 == $c4) {
                 $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_PREFIX', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_NOSUBSCRIPTION_LEVEL', escape_html(integer_format($c4)), escape_html($newsletter_description)), strval($newsletter['id']), $level >= 1, NULL, '4'));
             } else {
                 $l = new ocp_tempcode();
                 $l->attach(form_input_list_entry('0', $level == 0, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_0_ALT'), do_lang_tempcode('NUM_READERS', integer_format(0)))));
                 $l->attach(form_input_list_entry('1', $level == 1, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_1'), do_lang_tempcode('NUM_READERS', integer_format($c1)))));
                 $l->attach(form_input_list_entry('2', $level == 2, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_2'), do_lang_tempcode('NUM_READERS', integer_format($c2)))));
                 $l->attach(form_input_list_entry('3', $level == 3, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_3'), do_lang_tempcode('NUM_READERS', integer_format($c3)))));
                 $l->attach(form_input_list_entry('4', $level == 4, do_lang_tempcode('NNR', do_lang_tempcode('NEWSLETTER_4'), do_lang_tempcode('NUM_READERS', integer_format($c4)))));
                 $fields->attach(form_input_list(do_lang_tempcode('SUBSCRIPTION_LEVEL_FOR', escape_html($newsletter_title)), do_lang_tempcode('DESCRIPTION_SUBSCRIPTION_LEVEL', escape_html($newsletter_description)), strval($newsletter['id']), $l));
             }
         }
     }
     if (get_forum_type() == 'ocf') {
         $c5 = $this->count_level(-1, 5, $lang);
         $fields->attach(form_input_tick(do_lang_tempcode('NEWSLETTER_OCF'), do_lang_tempcode('NUM_READERS', integer_format($c5)), '-1', false));
         $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
         foreach ($groups as $group_id => $group) {
             if ($group_id != db_get_first_id()) {
                 $map = array();
                 $map['g' . strval($group_id)] = 1;
                 $_c = newsletter_who_send_to($map, $lang, 0, 0);
                 $c6 = $_c[6]['g' . strval($group_id)];
                 if ($c6 != 0) {
                     $fields->attach(form_input_tick(do_lang_tempcode('THIS_WITH', do_lang_tempcode('GROUP'), make_string_tempcode(escape_html($group))), do_lang_tempcode('NUM_READERS', integer_format($c6)), 'g' . strval($group_id), post_param_integer('g' . strval($group_id), 0) == 1));
                 }
             }
         }
     }
     $fields->attach(form_input_upload(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_UPLOAD_CSV'), 'file', false, NULL, NULL, true, 'csv,txt'));
     //if ($fields->is_empty()) inform_exit(do_lang_tempcode('NOBODY_TO_SEND_TO'));
     handle_max_file_size($hidden);
     $template_choices = new ocp_tempcode();
     $dh = opendir(get_custom_file_base() . '/themes/default/templates_custom');
     while (($f = readdir($dh)) !== false) {
         if (preg_match('#^MAIL.*\\.tpl$#', $f) != 0) {
             $tpl = basename($f, '.tpl');
             $template_choices->attach(form_input_list_entry($tpl, post_param('template', 'MAIL') == $tpl, $tpl));
         }
     }
     if (!file_exists(get_custom_file_base() . '/themes/default/templates_custom/MAIL.tpl')) {
         $template_choices->attach(form_input_list_entry('MAIL', true, 'MAIL'));
     }
     closedir($dh);
     $fields->attach(form_input_list(do_lang_tempcode('NEWSLETTER_TEMPLATE'), do_lang_tempcode('DESCRIPTION_NEWSLETTER_TEMPLATE'), 'template', $template_choices, NULL, false, true));
     // If we're making a periodic newsletter then we need to know when it
     // should be sent
     if ($periodic_action == 'make' || $periodic_action == 'replace') {
         $hidden->attach(form_input_hidden('make_periodic', '1'));
         $hidden->attach(form_input_hidden('periodic_choice', post_param('periodic_choice')));
         $fields->attach(do_template('FORM_SCREEN_FIELD_SPACER', array('TITLE' => do_lang('PERIODIC_WHEN'), 'HELP' => do_lang('PERIODIC_WHEN_HELP'))));
         // The choices are given as radio buttons: weekly or bi-weekly or monthly?
         // In the labels for these radio buttons, we put a dropdown for day of
         // the week and day of the month.
         $frequency = post_param('periodic_when', 'weekly');
         if (!is_null($defaults)) {
             $frequency = post_param('periodic_when', $defaults['np_frequency']);
         }
         $current_day_weekly = post_param_integer('periodic_weekly', 5);
         if (!is_null($defaults)) {
             $current_day_weekly = post_param_integer('periodic_weekly', $defaults['np_day']);
         }
         $current_day_biweekly = post_param_integer('periodic_biweekly', 5);
         if (!is_null($defaults)) {
             $current_day_biweekly = post_param_integer('periodic_biweekly', $defaults['np_day']);
         }
         $current_day_of_month = post_param_integer('periodic_monthly', 1);
         if (!is_null($defaults)) {
             $current_day_of_month = post_param_integer('periodic_monthly', $defaults['np_day']);
         }
         $radios = new ocp_tempcode();
         $week_days_weekly = new ocp_tempcode();
         $week_days_biweekly = new ocp_tempcode();
         require_lang('dates');
         $week_days = array(1 => do_lang('MONDAY'), 2 => do_lang('TUESDAY'), 3 => do_lang('WEDNESDAY'), 4 => do_lang('THURSDAY'), 5 => do_lang('FRIDAY'), 6 => do_lang('SATURDAY'), 7 => do_lang('SUNDAY'));
         foreach ($week_days as $i => $this_day) {
             $week_days_weekly->attach(form_input_list_entry(strval($i), $i == $current_day_weekly, $this_day, false, false));
             $week_days_biweekly->attach(form_input_list_entry(strval($i), $i == $current_day_biweekly, $this_day, false, false));
         }
         $weekly_desc = new ocp_tempcode();
         $weekly_desc->attach(do_lang('PERIODIC_WEEKLY_ON'));
         $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_weekly', 'CONTENT' => $week_days_weekly, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'weekly', $frequency == 'weekly', $weekly_desc, NULL, ''));
         $weekly_desc = new ocp_tempcode();
         $weekly_desc->attach(do_lang('PERIODIC_BIWEEKLY_ON'));
         $weekly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_weekday_biweekly', 'CONTENT' => $week_days_biweekly, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'biweekly', $frequency == 'biweekly', $weekly_desc, NULL, ''));
         $month_days = new ocp_tempcode();
         foreach (range(1, 28) as $this_day) {
             $suffix = gmdate('S', gmmktime(0, 0, 0, 1, $this_day, 1990));
             $month_days->attach(form_input_list_entry(strval($this_day), $this_day == 1, strval($this_day) . $suffix, $current_day_of_month == $this_day));
         }
         $monthly_desc = new ocp_tempcode();
         $monthly_desc->attach(do_lang('PERIODIC_MONTHLY_ON'));
         $monthly_desc->attach(do_template('FORM_SCREEN_INPUT_LIST', array('TABINDEX' => strval(get_form_field_tabindex(NULL)), 'REQUIRED' => '0', 'NAME' => 'periodic_monthly', 'CONTENT' => $month_days, 'INLINE_LIST' => '0')));
         $radios->attach(form_input_radio_entry('periodic_when', 'monthly', $frequency == 'monthly', $monthly_desc, NULL, ''));
         $fields->attach(form_input_radio(do_lang('PERIODIC_WHEN_CHOICE'), '', 'periodic_when', $radios, true));
         $radios = new ocp_tempcode();
         $radios->attach(form_input_radio_entry('periodic_for', 'all', false, do_lang_tempcode('CREATE_PERIODIC_FOR_ALL'), NULL, ''));
         $radios->attach(form_input_radio_entry('periodic_for', 'future', true, do_lang_tempcode('CREATE_PERIODIC_FOR_FUTURE'), NULL, ''));
         $fields->attach(form_input_radio(do_lang('CREATE_PERIODIC_FOR'), '', 'periodic_for', $radios, true));
     }
     return do_template('FORM_SCREEN', array('_GUID' => '0b2a4825ec586d9ff557026d9a1e0cca', 'TITLE' => $title, 'TEXT' => $periodic_action == 'make' || $periodic_action == 'replace' ? do_lang_tempcode('PERIODIC_NO_EDIT') : do_lang_tempcode('NEWSLETTER_SEND_TEXT'), 'HIDDEN' => $hidden, 'FIELDS' => $fields->evaluate(), 'SUBMIT_NAME' => $submit_name, 'URL' => $post_url));
 }
Exemple #23
0
 /**
  * The UI for a "flow mode" gallery.
  *
  * @param  tempcode		Rating area
  * @param  tempcode		Commenting area
  * @param  ID_TEXT		Our gallery ID
  * @param  ID_TEXT		Virtual root gallery
  * @param  tempcode		The description of the gallery
  * @param  tempcode		The tempcode for our visible child galleries
  * @param  boolean		Whether may "download this gallery"
  * @param  tempcode		The URL to "edit this gallery"
  * @param  tempcode		The URL to "add a gallery"
  * @param  tempcode		The URL to "submit an image to this gallery"
  * @param  tempcode		The URL to "submit a video to this gallery"
  * @param  tempcode		The title of the page (our of get_page_title)
  * @param  URLPATH		The representative image for the gallery
  * @param  integer		The start position we are in browsing through child galleries
  * @param  integer		The maximum number of child galleries we can display per page
  * @param  integer		The number of child galleries we have
  * @param  string			The gallery title
  * @param  tempcode		Sorting UI
  * @return tempcode		The UI
  */
 function do_gallery_flow_mode($rating_details, $comment_details, $cat, $root, $description, $children, $may_download, $edit_url, $add_gallery_url, $submit_image_url, $submit_video_url, $title, $rep_image, $start, $max, $num_galleries, $fullname, $sorting)
 {
     list($sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos) = $this->get_sort_order();
     $page_num = intval(floor(floatval($start) / floatval($max))) + 1;
     $num_pages = intval(ceil(floatval($num_galleries) / floatval($max)));
     $image_select = get_param('select', '*');
     $video_select = get_param('video_select', '*');
     $previous = $page_num == 1 ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => max($start - $max, 0) == 0 ? NULL : max($start - $max, 0), 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF', NULL, true);
     $next = $page_num == $num_pages ? new ocp_tempcode() : build_url(array('page' => '_SELF', 'start' => $start + $max, 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF', NULL, true);
     if ($num_pages < 2) {
         $browse = new ocp_tempcode();
     } else {
         $browse = do_template('NEXT_BROWSER_BROWSE_NEXT', array('_GUID' => '5a01713ab670f1eb1dd17bde663e6e9f', 'PREVIOUS_LINK' => $previous, 'NEXT_LINK' => $next, 'PAGE_NUM' => integer_format($page_num), 'NUM_PAGES' => integer_format($num_pages)));
     }
     // View current entry
     $row = NULL;
     $current_entry = new ocp_tempcode();
     $view_url = new ocp_tempcode();
     $full_url = '';
     $entry_edit_url = new ocp_tempcode();
     $entry_rating_details = new ocp_tempcode();
     $entry_comment_details = new ocp_tempcode();
     $entry_trackback_details = new ocp_tempcode();
     $entry_add_date_raw = '';
     $entry_edit_date_raw = '';
     $entry_views = '';
     $entry_title = '';
     $entry_submitter = NULL;
     $entry_description = new ocp_tempcode();
     $probe_type = get_param('probe_type', 'first');
     $probe_id = get_param_integer('probe_id', 0);
     if ($probe_type == 'first') {
         $where = db_string_equal_to('cat', $cat);
         if (!has_specific_permission(get_member(), 'see_unvalidated')) {
             $where .= ' AND validated=1';
         }
         if (get_param('days', '') != '') {
             $where .= ' AND add_date>' . strval(time() - get_param_integer('days') * 60 * 60 * 24);
         }
         $first_video = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_videos . ' FROM ' . get_table_prefix() . 'videos r WHERE ' . $where . ' ORDER BY ' . $sort, 1);
         if (array_key_exists(0, $first_video)) {
             $row = $first_video[0];
             $probe_type = 'video';
             $probe_id = $row['id'];
         } else {
             $where = db_string_equal_to('cat', $cat);
             if (!has_specific_permission(get_member(), 'see_unvalidated')) {
                 $where .= ' AND validated=1';
             }
             if (get_param('days', '') != '') {
                 $where .= ' AND add_date>' . strval(time() - get_param_integer('days') * 60 * 60 * 24);
             }
             $first_image = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_images . ' FROM ' . get_table_prefix() . 'images r WHERE ' . $where . ' ORDER BY ' . $sort, 1);
             if (array_key_exists(0, $first_image)) {
                 $row = $first_image[0];
                 $probe_type = 'image';
                 $probe_id = $row['id'];
             }
             // If else, then we have no probe_type, and thus won't be able to show anything
         }
     }
     if (!is_null($row) && $row['validated'] == 0) {
         if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) {
             access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated');
         }
         $warning_details = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     switch ($probe_type) {
         case 'video':
             if (is_null($row)) {
                 $map = array('cat' => $cat, 'id' => $probe_id);
                 if (!has_specific_permission(get_member(), 'see_unvalidated')) {
                     $map['validated'] = 1;
                 }
                 $rows = $GLOBALS['SITE_DB']->query_select('videos', array('*'), $map, '', 1);
                 if (!array_key_exists(0, $rows)) {
                     attach_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn');
                     break;
                 }
                 $row = $rows[0];
             }
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $row['submitter'], 'cms_galleries', array('galleries', $cat))) {
                 $entry_edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ev', 'id' => $row['id']), get_module_zone('cms_galleries'));
             }
             /*$view_url=build_url(array('page'=>'_SELF','type'=>'video','root'=>($root=='root')?NULL:$root,'wide'=>1,'id'=>$row['id']),'_SELF');
             		$thumb_url=$row['thumb_url'];
             		if (($thumb_url!='') && (url_is_local($thumb_url))) $thumb_url=get_custom_base_url().'/'.$thumb_url;
             		if ($thumb_url=='') $thumb_url=find_theme_image('na');
             		$thumb=do_image_thumb($thumb_url,'');*/
             // Video HTML
             $thumb_url = $row['thumb_url'];
             $url = $row['url'];
             $video_player = show_gallery_media($url, $thumb_url, $row['video_width'], $row['video_height'], $row['video_length']);
             $view_url = build_url(array('page' => '_SELF', 'type' => 'video', 'id' => $row['id'], 'wide' => 1, 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
             // Some extra variables relating to the currently selected entry
             $entry_title = get_translated_text($row['title']);
             $entry_rating_details = get_rating_box(get_self_url(true), $entry_title, 'videos', strval($row['id']), $row['allow_rating'] == 1, $row['submitter']);
             $entry_comment_details = get_comments('videos', $row['allow_comments'] == 1, strval($row['id']), false, get_value('comment_forum__videos'), NULL, NULL, false, false, $row['submitter'], $row['allow_comments'] == 2);
             $entry_trackback_details = get_trackbacks('videos', strval($row['id']), $row['allow_trackbacks'] == 1);
             $entry_add_date_raw = is_null($row['add_date']) ? '' : strval($row['add_date']);
             $entry_edit_date_raw = is_null($row['edit_date']) ? '' : strval($row['edit_date']);
             $entry_views = integer_format($row['video_views']);
             $current_entry = do_template('GALLERY_FLOWMODE_VIDEO', array('_GUID' => 'b6a795dc3853789df2a2951293d0fb26', '_TITLE' => get_translated_text($row['title']), 'EDIT_URL' => $entry_edit_url, 'MAIN' => true, 'RATING_DETAILS' => $entry_rating_details, 'DESCRIPTION' => get_translated_tempcode($row['comments']), 'CAT' => $cat, 'THUMB_URL' => $url, 'FULL_URL' => $full_url, 'ID' => strval($row['id']), 'VIEWS' => strval($row['video_views']), 'ADD_DATE_RAW' => strval($row['add_date']), 'EDIT_DATE_RAW' => is_null($row['edit_date']) ? '' : strval($row['edit_date']), 'SUBMITTER' => strval($row['submitter']), 'VIDEO_PLAYER' => $video_player, 'VIEW_URL' => $view_url, 'VIDEO_DETAILS' => show_video_details($row)));
             $GLOBALS['SITE_DB']->query_update('videos', array('video_views' => $row['video_views'] + 1), array('id' => $row['id']), '', 1, NULL, false, true);
             break;
         case 'image':
             if (is_null($row)) {
                 $map = array('cat' => $cat, 'id' => $probe_id);
                 if (!has_specific_permission(get_member(), 'see_unvalidated')) {
                     $map['validated'] = 1;
                 }
                 $rows = $GLOBALS['SITE_DB']->query_select('images', array('*'), $map, '', 1);
                 if (!array_key_exists(0, $rows)) {
                     attach_message(do_lang_tempcode('MISSING_RESOURCE'), 'warn');
                     break;
                 }
                 $row = $rows[0];
             }
             if (has_actual_page_access(NULL, 'cms_galleries', NULL, NULL) && has_edit_permission('mid', get_member(), $row['submitter'], 'cms_galleries', array('galleries', $cat))) {
                 $entry_edit_url = build_url(array('page' => 'cms_galleries', 'type' => '_ed', 'id' => $row['id']), get_module_zone('cms_galleries'));
             }
             /*$view_url=build_url(array('page'=>'_SELF','type'=>'image','root'=>($root=='root')?NULL:$root,'wide'=>1,'id'=>$row['id']),'_SELF');
             		$thumb_url=ensure_thumbnail($row['url'],$row['thumb_url'],'galleries','images',$row['id']);
             		$thumb=do_image_thumb($thumb_url,'');*/
             $thumb_url = $row['url'];
             //do_image_thumb($row['url'],'');
             if (url_is_local($thumb_url)) {
                 $file_size = file_exists(get_custom_file_base() . '/' . rawurldecode($thumb_url)) ? strval(filesize(get_custom_file_base() . '/' . rawurldecode($thumb_url))) : '';
                 $thumb_url = get_custom_base_url() . '/' . $thumb_url;
             } else {
                 $file_size = '';
             }
             $full_url = $thumb_url;
             $view_url = build_url(array('page' => '_SELF', 'type' => 'image', 'id' => $row['id'], 'wide' => 1, 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
             // Some extra variables relatin to the currently selected entry
             $entry_title = get_translated_text($row['title']);
             $entry_rating_details = get_rating_box(get_self_url(true), $entry_title, 'images', strval($row['id']), $row['allow_rating'] == 1, $row['submitter']);
             $entry_comment_details = get_comments('images', $row['allow_comments'] == 1, strval($row['id']), false, get_value('comment_forum__images'), NULL, NULL, false, false, $row['submitter'], $row['allow_comments'] == 2);
             $entry_trackback_details = get_trackbacks('images', strval($row['id']), $row['allow_trackbacks'] == 1);
             $entry_add_date_raw = is_null($row['add_date']) ? '' : strval($row['add_date']);
             $entry_edit_date_raw = is_null($row['edit_date']) ? '' : strval($row['edit_date']);
             $entry_views = integer_format($row['image_views']);
             $current_entry = do_template('GALLERY_FLOWMODE_IMAGE', array('_GUID' => 'fd486cf9a3338bc277a7170a1961089b', '_TITLE' => get_translated_text($row['title']), 'EDIT_URL' => $entry_edit_url, 'MAIN' => true, 'RATING_DETAILS' => $entry_rating_details, 'DESCRIPTION' => get_translated_tempcode($row['comments']), 'FILE_SIZE' => $file_size, 'CAT' => $cat, 'THUMB_URL' => $thumb_url, 'FULL_URL' => $full_url, 'ID' => strval($row['id']), 'VIEWS' => strval($row['image_views']), 'ADD_DATE_RAW' => strval($row['add_date']), 'EDIT_DATE_RAW' => is_null($row['edit_date']) ? '' : strval($row['edit_date']), 'SUBMITTER' => strval($row['submitter']), 'THUMB' => $thumb_url, 'VIEW_URL' => $view_url));
             $GLOBALS['SITE_DB']->query_update('images', array('image_views' => $row['image_views'] + 1), array('id' => $row['id']), '', 1, NULL, false, true);
             break;
     }
     $entries = new ocp_tempcode();
     // Display entries
     $where = db_string_equal_to('cat', $cat);
     if (!has_specific_permission(get_member(), 'see_unvalidated')) {
         $where .= ' AND validated=1';
     }
     if (get_param('days', '') != '') {
         $where .= ' AND add_date>' . strval(time() - get_param_integer('days') * 60 * 60 * 24);
     }
     $_max_entries = get_value('flow_mode_max');
     if (is_null($_max_entries)) {
         $max_entries = 50;
     } else {
         $max_entries = intval($_max_entries);
     }
     $query_rows_videos = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_videos . ' FROM ' . get_table_prefix() . 'videos r WHERE ' . $where . ' ORDER BY ' . $sort, $max_entries);
     $query_rows_images = $GLOBALS['SITE_DB']->query('SELECT *' . $sql_suffix_images . ' FROM ' . get_table_prefix() . 'images r WHERE ' . $where . ' ORDER BY ' . $sort, $max_entries);
     // See if there is a numbering system to sort by
     $all_are = NULL;
     foreach ($query_rows_images as $q) {
         $this_are = strtolower(preg_replace('#\\d#', '', $q['url']));
         if (is_null($all_are)) {
             $all_are = $this_are;
         }
         if ($all_are != $this_are) {
             $all_are = NULL;
             break;
         }
     }
     if (!is_null($all_are)) {
         global $M_SORT_KEY;
         $M_SORT_KEY = mixed();
         $M_SORT_KEY = 'url';
         usort($query_rows_images, 'multi_sort');
     }
     $query_rows = array_merge($query_rows_images, $query_rows_videos);
     foreach ($query_rows as $row) {
         $type = array_key_exists('video_length', $row) ? 'video' : 'image';
         if ($type == $probe_type && $row['id'] == $probe_id) {
             continue;
         }
         $caption = get_translated_tempcode($row['comments']);
         $probe_url = build_url(array('page' => '_SELF', 'type' => 'misc', 'root' => $root == 'root' ? NULL : $root, 'id' => $cat, 'flow_mode_interface' => get_param_integer('flow_mode_interface', NULL), 'probe_type' => $type, 'probe_id' => $row['id'], 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
         $view_url_2 = build_url(array('page' => '_SELF', 'wide' => 1, 'type' => $type, 'root' => $root == 'root' ? NULL : $root, 'id' => $row['id'], 'days' => get_param('days', '') == '' ? NULL : get_param('days'), 'sort' => $sort == 'add_date DESC' ? NULL : $sort, 'select' => $image_select == '*' ? NULL : $image_select, 'video_select' => $video_select == '*' ? NULL : $video_select), '_SELF');
         if (array_key_exists('url', $row)) {
             $thumb_url = ensure_thumbnail($row['url'], $row['thumb_url'], 'galleries', 'images', $row['id']);
         } else {
             $thumb_url = $row['thumb_url'];
             if ($thumb_url == '') {
                 $thumb_url = find_theme_image('na');
             }
             if (url_is_local($thumb_url)) {
                 $thumb_url = get_custom_base_url() . '/' . $thumb_url;
             }
         }
         $class = $type == $probe_type && $row['id'] == $probe_id ? 'currentimage' : '';
         $thumb = do_image_thumb($thumb_url, $caption);
         $entries->attach(do_template('GALLERY_FLOW_ENTRY', array('_GUID' => 'ff75c904ba7fe857484874483ed65f5a', 'DESCRIPTION' => get_translated_tempcode($row['comments']), '_TITLE' => get_translated_text($row['title']), 'TYPE' => $type, 'ID' => strval($row['id']), 'VIEWS' => strval($row[$type . '_views']), 'ADD_DATE_RAW' => strval($row['add_date']), 'EDIT_DATE_RAW' => is_null($row['edit_date']) ? '' : strval($row['edit_date']), 'SUBMITTER' => strval($row['submitter']), 'CLASS' => $class, 'THUMB' => $thumb, 'VIEW_URL' => $probe_url, 'VIEW_URL_2' => $view_url_2)));
     }
     $member_id = get_member_id_from_gallery_name($cat, NULL, true);
     if (get_forum_type() == 'ocf') {
         require_code('ocf_members');
         require_code('ocf_members2');
     }
     $member_details = is_null($member_id) || get_forum_type() != 'ocf' ? new ocp_tempcode() : ocf_show_member_box($member_id);
     $rep_image_url = '';
     if ($rep_image != '' && url_is_local($rep_image)) {
         $rep_image_url = get_custom_base_url() . '/' . $rep_image;
     } elseif ($rep_image != '') {
         $rep_image_url = $rep_image;
     }
     list(, , , $first_entry_id, , , $first_type) = $this->build_set_navigation(db_string_equal_to('cat', $cat), '', '', $probe_id, $root, $probe_type, get_param_integer('slideshow', 0), get_param_integer('wide_high', 0), $start, $max, $cat, $sort, $sort_backwards, $sql_suffix_images, $sql_suffix_videos, get_param('select', '*'), get_param('video_select', '*'));
     return do_template('GALLERY_FLOW_MODE_SCREEN', array('_GUID' => '73728cb94579f06ab487627101011d43', 'FIRST_ENTRY_ID' => is_null($first_entry_id) ? '' : $first_type . ':' . strval($first_entry_id), 'SORTING' => $sorting, '_TITLE' => $fullname, 'MEMBER_ID' => is_null($member_id) ? '' : strval($member_id), 'VIEW_URL' => $view_url, 'FULL_URL' => $full_url, 'PROBE_TYPE' => $probe_type, 'PROBE_ID' => is_null($probe_id) ? '' : strval($probe_id), 'ENTRY_TITLE' => $entry_title, 'ENTRY_DESCRIPTION' => $entry_description, 'ENTRY_SUBMITTER' => is_null($entry_submitter) ? '' : strval($entry_submitter), 'ENTRY_VIEWS' => $entry_views, 'ENTRY_ADD_DATE_RAW' => $entry_add_date_raw, 'ENTRY_EDIT_DATE_RAW' => $entry_edit_date_raw, 'ENTRY_TRACKBACK_DETAILS' => $entry_trackback_details, 'ENTRY_RATING_DETAILS' => $entry_rating_details, 'ENTRY_COMMENT_DETAILS' => $entry_comment_details, 'ENTRY_EDIT_URL' => $entry_edit_url, 'WARNING_DETAILS' => $warning_details, 'TAGS' => get_loaded_tags('galleries'), 'RATING_DETAILS' => $rating_details, 'COMMENT_DETAILS' => $comment_details, 'BROWSE' => $browse, 'REP_IMAGE_URL' => $rep_image_url, 'TITLE' => $title, 'MEMBER_DETAILS' => $member_details, 'DESCRIPTION' => $description, 'CHILDREN' => $children, 'CURRENT_ENTRY' => $current_entry, 'ENTRIES' => $entries, 'ADD_GALLERY_URL' => $add_gallery_url, 'EDIT_URL' => $edit_url, 'IMAGE_URL' => $submit_image_url, 'VIDEO_URL' => $submit_video_url, 'MAY_DOWNLOAD' => $may_download, 'CAT' => $cat));
 }
Exemple #24
0
 /**
  * Standard modular run function.
  *
  * @return tempcode	The result of execution.
  */
 function run()
 {
     if (get_forum_type() != 'ocf') {
         warn_exit(do_lang_tempcode('NO_OCF'));
     } else {
         ocf_require_all_forum_stuff();
     }
     require_code('ocf_topicview');
     require_css('ocf');
     global $NON_CANONICAL_PARAMS;
     $NON_CANONICAL_PARAMS[] = 'max';
     $NON_CANONICAL_PARAMS[] = 'start';
     $NON_CANONICAL_PARAMS[] = 'threaded';
     $start = get_param_integer('start', 0);
     $default_max = intval(get_option('forum_posts_per_page'));
     $max = get_param_integer('max', $default_max);
     if ($max == 0) {
         $max = $default_max;
     }
     if ($max == 0) {
         $max = 1;
     }
     if ($max > 30 && !has_specific_permission(get_member(), 'remove_page_split')) {
         $max = $default_max;
     }
     $first_unread_id = -1;
     global $NON_CANONICAL_PARAMS;
     foreach (array_keys($_GET) as $key) {
         if (substr($key, 0, 3) == 'kfs') {
             $NON_CANONICAL_PARAMS[] = $key;
         }
     }
     $type = get_param('type', 'misc');
     $id = get_param_integer('id', NULL);
     if (is_guest() && is_null($id)) {
         access_denied('NOT_AS_GUEST');
     }
     if ($type == 'findpost') {
         $post_id = get_param_integer('id');
         $redirect = find_post_id_url($post_id);
         require_code('site2');
         assign_refresh($redirect, 0.0);
         return do_template('REDIRECT_SCREEN', array('_GUID' => '76e6d34c20a4f5284119827e41c7752f', 'URL' => $redirect, 'TITLE' => get_page_title('VIEW_TOPIC'), 'TEXT' => do_lang_tempcode('REDIRECTING')));
     } else {
         if ($type == 'first_unread') {
             $redirect = find_first_unread_url($id);
             require_code('site2');
             assign_refresh($redirect, 0.0);
             return do_template('REDIRECT_SCREEN', array('_GUID' => '12c5d16f60e8c4df03536d9a7a932528', 'URL' => $redirect, 'TITLE' => get_page_title('VIEW_TOPIC'), 'TEXT' => do_lang_tempcode('REDIRECTING')));
         }
     }
     if (!is_null($id)) {
         $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=ocf_topicview&filter=' . strval($id);
     }
     $view_poll_results = get_param_integer('view_poll_results', 0);
     // Mark as read
     if (!is_null($id)) {
         if (!is_guest()) {
             $GLOBALS['FORUM_DB']->query_delete('f_read_logs', array('l_member_id' => get_member(), 'l_topic_id' => $id), '', 1);
             $GLOBALS['FORUM_DB']->query_insert('f_read_logs', array('l_member_id' => get_member(), 'l_topic_id' => $id, 'l_time' => time()), false, true);
             // race condition
         }
         $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics SET t_num_views=(t_num_views+1) WHERE id=' . strval((int) $id), 1, NULL, true);
     }
     // Load up topic info
     $topic_info = ocf_read_in_topic($id, $start, $max, $view_poll_results == 1);
     $GLOBALS['META_DATA'] += $topic_info['meta_data'];
     global $SEO_TITLE;
     $SEO_TITLE = do_lang('_VIEW_TOPIC', $topic_info['title']);
     // Render posts according to whether threaded or not
     $threaded = $topic_info['is_threaded'] == 1;
     $may_reply = array_key_exists('may_reply', $topic_info) && ($topic_info['is_open'] || array_key_exists('may_post_closed', $topic_info));
     if (!$threaded) {
         $GLOBALS['META_DATA']['description'] = $topic_info['description'];
         // Poster detail hooks
         $hooks = find_all_hooks('modules', 'topicview');
         $hook_objects = array();
         foreach (array_keys($hooks) as $hook) {
             require_code('hooks/modules/topicview/' . filter_naughty_harsh($hook));
             $object = object_factory('Hook_' . filter_naughty_harsh($hook), true);
             if (is_null($object)) {
                 continue;
             }
             $hook_objects[$hook] = $object;
         }
         // Render non-threaded
         $posts = new ocp_tempcode();
         $replied = false;
         if (is_null($topic_info['forum_id'])) {
             decache('side_ocf_personal_topics', array(get_member()));
             decache('_new_pp', array(get_member()));
         }
         $second_poster = $topic_info['first_poster'];
         foreach ($topic_info['posts'] as $array_id => $_postdetails) {
             if ($array_id == 0) {
                 $description = $topic_info['description'];
             } else {
                 $description = NULL;
             }
             if ($_postdetails['poster'] == get_member()) {
                 $replied = true;
             }
             if ($array_id == 1 && $start == 0 || $array_id == 0 && $start != 0) {
                 $second_poster = $_postdetails['poster'];
             }
             if (array_key_exists('last_edit_time', $_postdetails)) {
                 $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('_GUID' => '77a28e8bc3cf2ec2211aafdb5ba192bf', 'LAST_EDIT_DATE_RAW' => is_null($_postdetails['last_edit_time']) ? '' : strval($_postdetails['last_edit_time']), 'LAST_EDIT_DATE' => $_postdetails['last_edit_time_string'], 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($_postdetails['last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => $_postdetails['last_edit_by_username']));
             } else {
                 $last_edited = new ocp_tempcode();
             }
             $last_edited_raw = array_key_exists('last_edit_time', $_postdetails) ? is_null($_postdetails['last_edit_time']) ? '' : strval($_postdetails['last_edit_time']) : '0';
             $is_spacer_post = $_postdetails['is_spacer_post'];
             // Post buttons
             $buttons = new ocp_tempcode();
             if (!$is_spacer_post) {
                 $buttons = ocf_render_post_buttons($topic_info, $_postdetails, $may_reply);
             }
             // Avatar
             if (array_key_exists('poster_avatar', $_postdetails) && $_postdetails['poster_avatar'] != '') {
                 $post_avatar = do_template('OCF_TOPIC_POST_AVATAR', array('_GUID' => 'd647ada9c11d56eedc0ff7894d33e83c', 'AVATAR' => $_postdetails['poster_avatar']));
             } else {
                 $post_avatar = new ocp_tempcode();
             }
             // Rank images
             $rank_images = new ocp_tempcode();
             if (!$is_spacer_post) {
                 $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($_postdetails['poster'], true);
                 foreach ($posters_groups as $group) {
                     $rank_image = ocf_get_group_property($group, 'rank_image');
                     $group_leader = ocf_get_group_property($group, 'group_leader');
                     $group_name = ocf_get_group_name($group);
                     $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only');
                     if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $GLOBALS['FORUM_DRIVER']->get_member_row_field($_postdetails['poster'], 'm_primary_group'))) {
                         $rank_images->attach(do_template('OCF_RANK_IMAGE', array('_GUID' => '0ff7855482b901be95591964d4212c44', 'GROUP_NAME' => $group_name, 'USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($_postdetails['poster']), 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $_postdetails['poster'])));
                     }
                 }
             }
             // Poster details
             if (!$is_spacer_post) {
                 if (!is_guest($_postdetails['poster'])) {
                     require_code('ocf_members2');
                     $poster_details = ocf_show_member_box($_postdetails, false, $hooks, $hook_objects, false);
                 } else {
                     $custom_fields = new ocp_tempcode();
                     if (array_key_exists('ip_address', $_postdetails)) {
                         $custom_fields->attach(do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('_GUID' => 'd85be094dff0d039a64120d6f8f381bb', 'NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => $_postdetails['ip_address'])));
                         $poster_details = do_template('OCF_GUEST_DETAILS', array('_GUID' => 'e43534acaf598008602e8da8f9725f38', 'CUSTOM_FIELDS' => $custom_fields));
                     } else {
                         $poster_details = new ocp_tempcode();
                     }
                 }
             } else {
                 $poster_details = new ocp_tempcode();
             }
             if (!is_guest($_postdetails['poster'])) {
                 $poster = do_template('OCF_POSTER_MEMBER', array('_GUID' => 'dbbed1850b6c01a6c9601d85c6aee43f', 'ONLINE' => member_is_online($_postdetails['poster']), 'ID' => strval($_postdetails['poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($_postdetails['poster'], false, true), 'POSTER_USERNAME' => $_postdetails['poster_username'], 'HIGHLIGHT_NAME' => array_key_exists('poster_highlighted_name', $_postdetails) ? strval($_postdetails['poster_highlighted_name']) : NULL));
             } else {
                 $ip_link = array_key_exists('ip_address', $_postdetails) && has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => $_postdetails['ip_address']), get_module_zone('admin_lookup')) : new ocp_tempcode();
                 $poster = do_template('OCF_POSTER_GUEST', array('_GUID' => '36a8e550222cdac5165ef8f722be3def', 'IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $_postdetails['poster_username']));
             }
             // Signature
             $signature = new ocp_tempcode();
             if (array_key_exists('signature', $_postdetails) && !$_postdetails['signature']->is_empty()) {
                 $signature = $_postdetails['signature'];
             }
             $post_title = $_postdetails['title'];
             $first_unread = $_postdetails['id'] == $first_unread_id || $first_unread_id < 0 && $array_id == count($topic_info['posts']) - 1 ? do_template('OCF_TOPIC_FIRST_UNREAD') : new ocp_tempcode();
             $unvalidated = $_postdetails['validated'] == 0 ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
             $post_url = $GLOBALS['FORUM_DRIVER']->post_url($_postdetails['id'], is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']), true);
             if (array_key_exists('intended_solely_for', $_postdetails) && $_postdetails['intended_solely_for'] == get_member()) {
                 decache('side_ocf_personal_topics', array(get_member()));
                 decache('_new_pp', array(get_member()));
             }
             $emphasis = ocf_get_post_emphasis($_postdetails);
             require_code('feedback');
             if (!array_key_exists('intended_solely_for', $_postdetails)) {
                 actualise_rating(true, 'post', strval($_postdetails['id']), get_self_url(), $_postdetails['title']);
                 $rating = display_rating(get_self_url(), $_postdetails['title'], 'post', strval($_postdetails['id']), 'RATING_INLINE_DYNAMIC', $_postdetails['poster']);
             } else {
                 $rating = new ocp_tempcode();
             }
             $rendered_post = do_template('OCF_TOPIC_POST', array('_GUID' => 'sacd09wekfofpw2f', 'ID' => $is_spacer_post ? '' : strval($_postdetails['id']), 'TOPIC_FIRST_POST_ID' => is_null($topic_info['first_post_id']) ? '' : strval($topic_info['first_post_id']), 'TOPIC_FIRST_POSTER' => is_null($topic_info['first_poster']) ? '' : strval($topic_info['first_poster']), 'POST_ID' => $is_spacer_post ? '' : (get_value('seq_post_ids') === '1' ? strval($start + $array_id + 1) : strval($_postdetails['id'])), 'URL' => $post_url, 'CLASS' => $_postdetails['is_emphasised'] ? 'ocf_post_emphasis' : (array_key_exists('intended_solely_for', $_postdetails) ? 'ocf_post_personal' : ''), 'EMPHASIS' => $emphasis, 'FIRST_UNREAD' => $first_unread, 'POSTER_TITLE' => $is_spacer_post ? '' : $_postdetails['poster_title'], 'POST_TITLE' => $post_title, 'POST_DATE_RAW' => strval($_postdetails['time']), 'POST_DATE' => $_postdetails['time_string'], 'POST' => $_postdetails['post'], 'TOPIC_ID' => is_null($id) ? '' : strval($id), 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'POSTER_ID' => strval($_postdetails['poster']), 'POSTER' => $is_spacer_post ? '' : $poster, 'POSTER_DETAILS' => $poster_details, 'POST_AVATAR' => $post_avatar, 'RANK_IMAGES' => $rank_images, 'BUTTONS' => $buttons, 'SIGNATURE' => $signature, 'UNVALIDATED' => $unvalidated, 'DESCRIPTION' => $description, 'RATING' => $rating));
             $posts->attach($rendered_post);
         }
         $serialized_options = mixed();
         $hash = mixed();
     } else {
         require_code('topics');
         $threaded_topic_ob = new OCP_Topic();
         // Load some settings into the renderer
         $threaded_topic_ob->first_post_id = $topic_info['first_post_id'];
         $threaded_topic_ob->topic_description = $topic_info['description'];
         $threaded_topic_ob->topic_description_link = $topic_info['description_link'];
         $threaded_topic_ob->topic_title = $topic_info['title'];
         $threaded_topic_ob->topic_info = $topic_info;
         // Other settings we need
         $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')));
         // Load posts
         $threaded_topic_ob->load_from_topic($id, $num_to_show_limit, $start, false, NULL, true);
         $threaded_topic_ob->is_threaded = true;
         // Render posts
         list($posts, $serialized_options, $hash) = $threaded_topic_ob->render_posts($num_to_show_limit, $max_thread_depth, $may_reply, $topic_info['first_poster'], array(), $topic_info['forum_id'], NULL, false);
         $GLOBALS['META_DATA']['description'] = $threaded_topic_ob->topic_description;
         // Get other gathered details
         $replied = $threaded_topic_ob->replied;
         if (!is_null($threaded_topic_ob->topic_title)) {
             // Updated topic title
             $topic_info['title'] = $threaded_topic_ob->topic_title;
         }
         $topic_info['max_rows'] = $threaded_topic_ob->total_posts;
         $second_poster = $GLOBALS['FORUM_DRIVER']->get_guest_id();
         // No definitive post orders
     }
     // Buttons for topic as whole
     $button_array = array();
     if (!is_null($id)) {
         if (get_value('no_threaded_buttons') !== '1') {
             if ($threaded) {
                 $view_as_linear_url = get_self_url(false, false, array('threaded' => 0));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('VIEW_AS_LINEAR'), 'url' => $view_as_linear_url, 'img' => 'linear');
             } else {
                 $view_as_threaded_url = get_self_url(false, false, array('threaded' => 1));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('VIEW_AS_THREADED'), 'url' => $view_as_threaded_url, 'img' => 'threaded');
             }
         }
         if (!is_guest()) {
             $too_old = $topic_info['last_time'] < time() - 60 * 60 * 24 * intval(get_option('post_history_days'));
             if (get_value('disable_mark_topic_unread') !== '1' && !$too_old) {
                 $map = array('page' => 'topics', 'type' => 'mark_unread_topic', 'id' => $id);
                 $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                 if ($test != -1 && $test != 0) {
                     $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                 }
                 $test = get_param_integer('threaded', -1);
                 if ($test != -1) {
                     $map['threaded'] = $test;
                 }
                 $mark_unread_url = build_url($map, get_module_zone('topics'));
                 $button_array[] = array('immediate' => true, 'title' => do_lang_tempcode('MARK_UNREAD'), 'url' => $mark_unread_url, 'img' => 'mark_unread');
             }
         }
         if ($may_reply && is_null(get_bot_type())) {
             $reply_prevented = false;
             // "Staff-only" reply for support tickets
             if ($GLOBALS['FORUM_DRIVER']->is_staff(get_member()) && addon_installed('tickets')) {
                 require_code('tickets');
                 if (is_ticket_forum($topic_info['forum_id'])) {
                     if (is_guest($second_poster)) {
                         $reply_prevented = true;
                     }
                     require_lang('tickets');
                     $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id, 'intended_solely_for' => $GLOBALS['FORUM_DRIVER']->get_guest_id());
                     $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                     if ($test != -1 && $test != 0) {
                         $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                     }
                     $test = get_param_integer('threaded', -1);
                     if ($test != -1) {
                         $map['threaded'] = $test;
                     }
                     $new_post_url = build_url($map, get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode('TICKET_STAFF_ONLY_REPLY'), 'url' => $new_post_url, 'img' => 'staff_only_reply');
                 }
             }
             if (!$reply_prevented) {
                 if ($topic_info['is_threaded'] == 0) {
                     $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id);
                     $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                     if ($test != -1 && $test != 0) {
                         $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                     }
                     $test = get_param_integer('threaded', -1);
                     if ($test != -1) {
                         $map['threaded'] = $test;
                     }
                     $new_post_url = build_url($map, get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode($topic_info['is_open'] ? 'REPLY' : 'CLOSED'), 'url' => $new_post_url, 'img' => $topic_info['is_open'] ? 'reply' : 'closed');
                 }
             } else {
                 unset($topic_info['may_use_quick_reply']);
             }
         } elseif ((is_null($topic_info['forum_id']) || has_specific_permission(get_member(), 'submit_lowrange_content', 'topics', array('forums', $topic_info['forum_id']))) && $topic_info['last_poster'] == get_member() && !is_guest() && ocf_may_edit_post_by(get_member(), $topic_info['forum_id'])) {
             $map = array('page' => 'topics', 'type' => 'edit_post', 'id' => $topic_info['last_post_id']);
             $test = get_param_integer('kfs' . strval($topic_info['forum_id']), -1);
             if ($test != -1 && $test != 0) {
                 $map['kfs' . strval($topic_info['forum_id'])] = $test;
             }
             $test = get_param_integer('threaded', -1);
             if ($test != -1) {
                 $map['threaded'] = $test;
             }
             $new_post_url = build_url($map, get_module_zone('topics'));
             $button_array[] = array('immediate' => false, 'rel' => 'edit', 'title' => do_lang_tempcode('LAST_POST'), 'url' => $new_post_url, 'img' => 'amend');
         }
         if (!is_null($topic_info['forum_id'])) {
             if (get_value('disable_add_topic_btn_in_topic') !== '1') {
                 if (ocf_may_post_topic($topic_info['forum_id'], get_member())) {
                     $new_topic_url = build_url(array('page' => 'topics', 'type' => 'new_topic', 'id' => $topic_info['forum_id']), get_module_zone('topics'));
                     $button_array[] = array('immediate' => false, 'rel' => 'add', 'title' => do_lang_tempcode('ADD_TOPIC'), 'url' => $new_topic_url, 'img' => 'new_topic');
                 }
             }
         } else {
             $invite_url = build_url(array('page' => 'topics', 'type' => 'invite_member', 'id' => $id), get_module_zone('topics'));
             $button_array[] = array('immediate' => false, 'title' => do_lang_tempcode('INVITE_MEMBER_TO_PT'), 'url' => $invite_url, 'img' => 'invite_member');
         }
     }
     $buttons = ocf_screen_button_wrap($button_array);
     // Poll
     if (array_key_exists('poll', $topic_info)) {
         $_poll = $topic_info['poll'];
         $voted_already = $_poll['voted_already'];
         $poll_results = array_key_exists(0, $_poll['answers']) && array_key_exists('num_votes', $_poll['answers'][0]);
         $answers = new ocp_tempcode();
         $real_button = false;
         if ($_poll['is_open']) {
             if ($poll_results) {
                 $button = new ocp_tempcode();
             } elseif ($_poll['requires_reply'] && !$replied) {
                 $button = do_lang_tempcode('POLL_REQUIRES_REPLY');
             } else {
                 if (!has_specific_permission(get_member(), 'vote_in_polls') || is_guest()) {
                     $button = do_lang_tempcode('VOTE_DENIED');
                 } else {
                     if (!is_null($voted_already)) {
                         $button = do_lang_tempcode('NOVOTE');
                     } else {
                         require_lang('polls');
                         $map = array('page' => 'topicview', 'id' => $id, 'view_poll_results' => 1, 'start' => $start == 0 ? NULL : $start, 'max' => $max == $default_max ? NULL : $max);
                         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
                         if ($test != -1 && $test != 0) {
                             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
                         }
                         $test = get_param_integer('threaded', -1);
                         if ($test != -1) {
                             $map['threaded'] = $test;
                         }
                         $results_url = build_url($map, get_module_zone('topics'));
                         $button = do_template('OCF_TOPIC_POLL_BUTTON', array('_GUID' => '94b932fd01028df8f67bb5864d9235f9', 'RESULTS_URL' => $results_url));
                         $real_button = true;
                     }
                 }
             }
         } else {
             $button = do_lang_tempcode('TOPIC_POLL_CLOSED');
         }
         foreach ($_poll['answers'] as $answer) {
             if ($poll_results && ($_poll['requires_reply'] == 0 || $replied)) {
                 $num_votes = $answer['num_votes'];
                 $total_votes = $_poll['total_votes'];
                 if ($total_votes != 0) {
                     $width = intval(round(70.0 * floatval($num_votes) / floatval($total_votes)));
                 } else {
                     $width = 0;
                 }
                 $answer_tpl = do_template('OCF_TOPIC_POLL_ANSWER_RESULTS', array('_GUID' => 'b32f4c526e147abf20ca0d668e40d515', 'ID' => strval($_poll['id']), 'NUM_VOTES' => integer_format($num_votes), 'WIDTH' => strval($width), 'ANSWER' => $answer['answer'], 'I' => strval($answer['id'])));
             } else {
                 $answer_tpl = do_template('OCF_TOPIC_POLL_ANSWER' . ($_poll['maximum_selections'] == 1 ? '_RADIO' : ''), array('REAL_BUTTON' => $real_button, 'ID' => strval($_poll['id']), 'ANSWER' => $answer['answer'], 'I' => strval($answer['id'])));
             }
             $answers->attach($answer_tpl);
         }
         $map = array('page' => 'topics', 'type' => 'vote_poll', 'id' => $id, 'start' => $start == 0 ? NULL : $start, 'max' => $max == $default_max ? NULL : $max);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $vote_url = build_url($map, get_module_zone('topics'));
         if ($_poll['is_private']) {
             $private = paragraph(do_lang_tempcode('TOPIC_POLL_IS_PRIVATE'), 'dfgsdgdsgs');
         } else {
             $private = new ocp_tempcode();
         }
         if ($_poll['maximum_selections'] > 1) {
             $num_choices = paragraph($_poll['minimum_selections'] == $_poll['maximum_selections'] ? do_lang_tempcode('POLL_NOT_ENOUGH_ERROR_2', integer_format($_poll['minimum_selections'])) : do_lang_tempcode('POLL_NOT_ENOUGH_ERROR', integer_format($_poll['minimum_selections']), integer_format($_poll['maximum_selections'])), 'dsfsdfsdfs');
         } else {
             $num_choices = new ocp_tempcode();
         }
         $poll = do_template('OCF_TOPIC_POLL' . ($poll_results ? '_VIEW_RESULTS' : ''), array('ID' => strval($_poll['id']), 'NUM_CHOICES' => $num_choices, 'PRIVATE' => $private, 'QUESTION' => $_poll['question'], 'ANSWERS' => $answers, 'REAL_BUTTON' => $real_button, 'BUTTON' => $button, 'VOTE_URL' => $vote_url, 'MINIMUM_SELECTIONS' => integer_format($_poll['minimum_selections']), 'MAXIMUM_SELECTIONS' => integer_format($_poll['maximum_selections'])));
     } else {
         $poll = new ocp_tempcode();
     }
     // Forum nav tree
     if (!is_null($topic_info['forum_id'])) {
         $tree = ocf_forum_breadcrumbs($topic_info['forum_id'], NULL, NULL, false);
     } else {
         $tree = new ocp_tempcode();
         $tree->attach(hyperlink(build_url(array('page' => 'members'), get_module_zone('members')), do_lang_tempcode('MEMBERS'), false, false, do_lang_tempcode('GO_BACKWARDS_TO', do_lang_tempcode('MEMBERS')), NULL, NULL, 'up'));
         $tree->attach(do_template('BREADCRUMB_ESCAPED'));
         if (has_specific_permission(get_member(), 'view_other_pt')) {
             $of_member = $topic_info['pt_from'] == get_member() ? $topic_info['pt_from'] : $topic_info['pt_to'];
         } else {
             $of_member = get_member();
         }
         $of_username = $GLOBALS['FORUM_DRIVER']->get_username($of_member);
         if (is_null($of_username)) {
             $of_username = do_lang('UNKNOWN');
         }
         $personal_topic_url = build_url(array('page' => 'members', 'type' => 'view', 'id' => $of_member), get_module_zone('members'), NULL, true, false, false, 'tab__pts');
         $tree->attach(hyperlink($personal_topic_url, do_lang_tempcode('MEMBER_PROFILE', escape_html($of_username)), false, false, do_lang_tempcode('GO_BACKWARDS_TO', do_lang_tempcode('MEMBERS')), NULL, NULL, 'up'));
     }
     // Quick reply
     if (array_key_exists('may_use_quick_reply', $topic_info) && $may_reply && !is_null($id)) {
         $map = array('page' => 'topics', 'type' => '_add_reply', 'topic_id' => $id);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $_post_url = build_url($map, get_module_zone('topics'));
         $post_url = $_post_url->evaluate();
         $map = array('page' => 'topics', 'type' => 'new_post', 'id' => $id);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $more_url = build_url($map, get_module_zone('topics'));
         $_postdetails = array_key_exists('first_post', $topic_info) ? get_translated_tempcode($topic_info['first_post'], $GLOBALS['FORUM_DB']) : new ocp_tempcode();
         $first_post = $_postdetails;
         $first_post_url = $GLOBALS['FORUM_DRIVER']->post_url($topic_info['first_post_id'], is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']), true);
         $display = 'block';
         $expand_type = 'contract';
         if ($topic_info['max_rows'] > $start + $max) {
             $display = 'none';
             $expand_type = 'expand';
         }
         $em = $GLOBALS['FORUM_DRIVER']->get_emoticon_chooser();
         require_javascript('javascript_editing');
         require_javascript('javascript_validation');
         if (addon_installed('captcha')) {
             require_code('captcha');
             $use_captcha = use_captcha();
             if ($use_captcha) {
                 generate_captcha();
             }
         } else {
             $use_captcha = false;
         }
         $post_warning = '';
         if ($topic_info['is_really_threaded'] == 1) {
             $post_warning = do_lang('THREADED_REPLY_NOTICE', $post_warning);
         }
         $quick_reply = do_template('COMMENTS_POSTING_FORM', array('_GUID' => '4c532620f3eb68d9cc820b18265792d7', 'JOIN_BITS' => '', 'USE_CAPTCHA' => $use_captcha, 'GET_EMAIL' => false, 'EMAIL_OPTIONAL' => true, 'GET_TITLE' => false, 'POST_WARNING' => $post_warning, 'COMMENT_TEXT' => '', 'EM' => $em, 'EXPAND_TYPE' => $expand_type, 'DISPLAY' => $display, 'FIRST_POST_URL' => $first_post_url, 'FIRST_POST' => $first_post, 'MORE_URL' => $more_url, 'COMMENT_URL' => $post_url, 'TITLE' => do_lang_tempcode('QUICK_REPLY'), 'SUBMIT_NAME' => do_lang_tempcode('MAKE_POST')));
     } else {
         $quick_reply = new ocp_tempcode();
     }
     $action_url = build_url(array('page' => 'topics', 'id' => $id), get_module_zone('topics'));
     if (!is_null($id)) {
         // Moderation options
         $moderator_actions = '';
         if (is_null($topic_info['forum_id'])) {
             $moderator_actions .= '<option value="categorise_pts">' . do_lang('_CATEGORISE_PTS') . '</option>';
         }
         if (array_key_exists('may_multi_moderate', $topic_info) && array_key_exists('forum_id', $topic_info)) {
             $multi_moderations = ocf_list_multi_moderations($topic_info['forum_id']);
             if (count($multi_moderations) != 0) {
                 $moderator_actions .= '<optgroup label="' . do_lang('MULTI_MODERATIONS') . '">';
                 foreach ($multi_moderations as $mm_id => $mm_name) {
                     $moderator_actions .= '<option value="mm_' . strval($mm_id) . '">' . $mm_name . '</option>';
                 }
                 $moderator_actions .= '</optgroup>';
             }
         }
         if (array_key_exists('may_move_topic', $topic_info)) {
             $moderator_actions .= '<option value="move_topic">' . do_lang('MOVE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_edit_topic', $topic_info)) {
             $moderator_actions .= '<option value="edit_topic">' . do_lang('EDIT_TOPIC') . '</option>';
         }
         if (array_key_exists('may_delete_topic', $topic_info)) {
             $moderator_actions .= '<option value="delete_topic">' . do_lang('DELETE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_pin_topic', $topic_info)) {
             $moderator_actions .= '<option value="pin_topic">' . do_lang('PIN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_unpin_topic', $topic_info)) {
             $moderator_actions .= '<option value="unpin_topic">' . do_lang('UNPIN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_sink_topic', $topic_info)) {
             $moderator_actions .= '<option value="sink_topic">' . do_lang('SINK_TOPIC') . '</option>';
         }
         if (array_key_exists('may_unsink_topic', $topic_info)) {
             $moderator_actions .= '<option value="unsink_topic">' . do_lang('UNSINK_TOPIC') . '</option>';
         }
         if (array_key_exists('may_cascade_topic', $topic_info)) {
             $moderator_actions .= '<option value="cascade_topic">' . do_lang('CASCADE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_uncascade_topic', $topic_info)) {
             $moderator_actions .= '<option value="uncascade_topic">' . do_lang('UNCASCADE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_open_topic', $topic_info)) {
             $moderator_actions .= '<option value="open_topic">' . do_lang('OPEN_TOPIC') . '</option>';
         }
         if (array_key_exists('may_close_topic', $topic_info)) {
             $moderator_actions .= '<option value="close_topic">' . do_lang('CLOSE_TOPIC') . '</option>';
         }
         if (array_key_exists('may_edit_poll', $topic_info)) {
             $moderator_actions .= '<option value="edit_poll">' . do_lang('EDIT_TOPIC_POLL') . '</option>';
         }
         if (array_key_exists('may_delete_poll', $topic_info)) {
             $moderator_actions .= '<option value="delete_poll">' . do_lang('DELETE_TOPIC_POLL') . '</option>';
         }
         if (array_key_exists('may_attach_poll', $topic_info)) {
             $moderator_actions .= '<option value="add_poll">' . do_lang('ADD_TOPIC_POLL') . '</option>';
         }
         if (has_specific_permission(get_member(), 'view_content_history') && $GLOBALS['FORUM_DB']->query_value('f_post_history', 'COUNT(*)', array('h_topic_id' => $id)) != 0) {
             $moderator_actions .= '<option value="topic_history">' . do_lang('POST_HISTORY') . '</option>';
         }
         if (array_key_exists('may_make_personal', $topic_info) && !is_null($topic_info['forum_id'])) {
             $moderator_actions .= '<option value="make_personal">' . do_lang('MAKE_PERSONAL') . '</option>';
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($moderator_actions);
         }
         // Marked post actions
         $map = array('page' => 'topics', 'id' => $id);
         $test = get_param_integer('kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id'])), -1);
         if ($test != -1 && $test != 0) {
             $map['kfs' . (is_null($topic_info['forum_id']) ? '' : strval($topic_info['forum_id']))] = $test;
         }
         $test = get_param_integer('threaded', -1);
         if ($test != -1) {
             $map['threaded'] = $test;
         }
         $action_url = build_url($map, get_module_zone('topics'), NULL, false, true);
         $marked_post_actions = '';
         if (array_key_exists('may_move_posts', $topic_info)) {
             $marked_post_actions .= '<option value="move_posts_a">' . do_lang('MERGE_POSTS') . '</option>';
             $marked_post_actions .= '<option value="move_posts_b">' . do_lang('SPLIT_POSTS') . '</option>';
         }
         if (array_key_exists('may_delete_posts', $topic_info)) {
             $marked_post_actions .= '<option value="delete_posts">' . do_lang('DELETE_POSTS') . '</option>';
         }
         if (array_key_exists('may_validate_posts', $topic_info)) {
             $marked_post_actions .= '<option value="validate_posts">' . do_lang('VALIDATE_POSTS') . '</option>';
         }
         if (get_value('disable_multi_quote') !== '1') {
             if ($may_reply) {
                 $marked_post_actions .= '<option value="new_post">' . do_lang('QUOTE_POSTS') . '</option>';
             }
         }
         if ($GLOBALS['XSS_DETECT']) {
             ocp_mark_as_escaped($marked_post_actions);
         }
     } else {
         $moderator_actions = '';
         $marked_post_actions = '';
     }
     $max_rows = $topic_info['max_rows'];
     if ($max_rows > $max && !$threaded) {
         require_code('templates_results_browser');
         $results_browser = results_browser(do_lang_tempcode('FORUM_POSTS'), $id, $start, 'start', $max, 'max', $max_rows, NULL, 'misc', true, false, 7, array(10, 20, 30));
     } else {
         $results_browser = new ocp_tempcode();
     }
     // Members viewing this topic
     $members = is_null($id) ? array() : get_members_viewing('topicview', '', strval($id), true);
     $num_guests = 0;
     $num_members = 0;
     if (is_null($members)) {
         $members_viewing = new ocp_tempcode();
     } else {
         $members_viewing = new ocp_tempcode();
         foreach ($members as $member_id => $at_details) {
             $username = $at_details['mt_cache_username'];
             if (is_guest($member_id)) {
                 $num_guests++;
             } else {
                 $num_members++;
                 $profile_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id, false, true);
                 $map = array('PROFILE_URL' => $profile_url, 'USERNAME' => $username);
                 if (has_specific_permission(get_member(), 'show_user_browsing') || in_array($at_details['the_page'], array('topics', 'topicview')) && $at_details['the_id'] == strval($id)) {
                     $map['AT'] = escape_html($at_details['the_title']);
                 }
                 $map['COLOUR'] = get_group_colour(ocf_get_member_primary_group($member_id));
                 $members_viewing->attach(do_template('OCF_USER_MEMBER', $map));
             }
         }
         if ($members_viewing->is_empty()) {
             $members_viewing = do_lang_tempcode('NONE_EM');
         }
     }
     if (!is_null($id)) {
         breadcrumb_add_segment($tree, do_lang_tempcode(is_null($topic_info['forum_id']) ? 'VIEW_PERSONAL_TOPIC' : 'VIEW_TOPIC'));
     }
     if (is_null($id)) {
         $root_forum_name = $GLOBALS['FORUM_DB']->query_value('f_forums', 'f_name', array('id' => db_get_first_id()));
         $tree = hyperlink(build_url(array('page' => 'forumview', 'id' => db_get_first_id()), get_module_zone('forumview')), escape_html($root_forum_name), false, false, do_lang('GO_BACKWARDS_TO'));
         breadcrumb_add_segment($tree, do_lang('INLINE_PERSONAL_POSTS'));
     }
     if ($topic_info['validated'] == 0) {
         $warning_details = do_template('WARNING_TABLE', array('WARNING' => do_lang_tempcode(get_param_integer('redirected', 0) == 1 ? 'UNVALIDATED_TEXT_NON_DIRECT' : 'UNVALIDATED_TEXT')));
     } else {
         $warning_details = new ocp_tempcode();
     }
     $topic_tpl = do_template('OCF_TOPIC_WRAP', array('_GUID' => 'bb201d5d59559e5e2bd60e7cf2e6f7e9', 'SERIALIZED_OPTIONS' => $serialized_options, 'HASH' => $hash, 'ID' => strval($id), 'TITLE' => $topic_info['title'], 'MAY_DOUBLE_POST' => has_specific_permission(get_member(), 'double_post'), 'LAST_POSTER' => array_key_exists('last_poster', $topic_info) ? is_null($topic_info['last_poster']) ? '' : strval($topic_info['last_poster']) : '', 'WARNING_DETAILS' => $warning_details, 'MAX' => strval($max), 'MAY_CHANGE_MAX' => array_key_exists('may_change_max', $topic_info), 'ACTION_URL' => $action_url, 'NUM_GUESTS' => integer_format($num_guests), 'NUM_MEMBERS' => integer_format($num_members), 'MEMBERS_VIEWING' => $members_viewing, 'RESULTS_BROWSER' => $results_browser, 'MODERATOR_ACTIONS' => $moderator_actions, 'MARKED_POST_ACTIONS' => $marked_post_actions, 'QUICK_REPLY' => $quick_reply, 'TREE' => $tree, 'POLL' => $poll, 'SCREEN_BUTTONS' => $buttons, 'POSTS' => $posts, 'THREADED' => $threaded));
     if (is_null($id)) {
         $title = get_page_title('INLINE_PERSONAL_POSTS');
     } else {
         if (is_null($topic_info['forum_id'])) {
             $title = get_page_title(do_lang_tempcode('NAMED_PERSONAL_TOPIC', escape_html($topic_info['title'])), false, NULL, do_lang_tempcode('READING_PERSONAL_TOPIC'));
         } else {
             if (addon_installed('awards')) {
                 require_code('awards');
                 $awards = find_awards_for('topic', strval($id));
             } else {
                 $awards = array();
             }
             $title = get_page_title(do_lang_tempcode('NAMED_TOPIC', escape_html($topic_info['title'])), false, NULL, NULL, $awards);
         }
     }
     return ocf_wrapper($title, $topic_tpl, true, false, $topic_info['forum_id']);
 }
Exemple #25
0
 /**
  * Standard modular render function for profile tab hooks.
  *
  * @param  MEMBER			The ID of the member who is being viewed
  * @param  MEMBER			The ID of the member who is doing the viewing
  * @param  boolean		Whether to leave the tab contents NULL, if tis hook supports it, so that AJAX can load it later
  * @return array			A triple: The tab title, the tab contents, the suggested tab order
  */
 function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false)
 {
     $title = do_lang_tempcode('PROFILE');
     $order = 10;
     $photo_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_url');
     if ($photo_url != '' && addon_installed('ocf_member_photos') && has_specific_permission($member_id_viewing, 'view_member_photos')) {
         require_code('images');
         $photo_thumb_url = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_photo_thumb_url');
         $photo_thumb_url = ensure_thumbnail($photo_url, $photo_thumb_url, strpos($photo_url, 'uploads/photos') !== false ? 'photos' : 'ocf_photos', 'f_members', $member_id_of, 'm_photo_thumb_url');
         if (url_is_local($photo_url)) {
             $photo_url = get_complex_base_url($photo_url) . '/' . $photo_url;
         }
         if (url_is_local($photo_thumb_url)) {
             $photo_thumb_url = get_complex_base_url($photo_thumb_url) . '/' . $photo_thumb_url;
         }
     } else {
         $photo_url = '';
         $photo_thumb_url = '';
     }
     $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member_id_of);
     $username = $GLOBALS['FORUM_DRIVER']->get_username($member_id_of);
     // Things staff can do with this user
     $modules = array();
     if (has_specific_permission($member_id_viewing, 'warn_members') && has_actual_page_access($member_id_viewing, 'warnings') && addon_installed('ocf_warnings')) {
         $redir_url = get_self_url(true);
         $modules[] = array('usage', do_lang_tempcode('WARN_MEMBER'), build_url(array('page' => 'warnings', 'type' => 'ad', 'id' => $member_id_of, 'redirect' => $redir_url), get_module_zone('warnings')));
         $modules[] = array('usage', do_lang_tempcode('PUNITIVE_HISTORY'), build_url(array('page' => 'warnings', 'type' => 'history', 'id' => $member_id_of), get_module_zone('warnings')));
     }
     if (has_specific_permission($member_id_viewing, 'view_content_history') && has_actual_page_access($member_id_viewing, 'admin_ocf_history')) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('usage', do_lang_tempcode('POST_HISTORY'), build_url(array('page' => 'admin_ocf_history', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_lookup')) {
         require_lang('submitban');
         $modules[] = array('usage', do_lang_tempcode('INVESTIGATE_USER'), build_url(array('page' => 'admin_lookup', 'param' => $member_id_of), 'adminzone'));
     }
     if (has_actual_page_access($member_id_viewing, 'admin_security')) {
         require_lang('security');
         $modules[] = array('usage', do_lang_tempcode('SECURITY_LOGGING'), build_url(array('page' => 'admin_security', 'member_id' => $member_id_of), 'adminzone'));
     }
     if (addon_installed('actionlog')) {
         if (has_actual_page_access($member_id_viewing, 'admin_actionlog')) {
             require_lang('submitban');
             $modules[] = array('usage', do_lang_tempcode('VIEW_ACTION_LOGS'), build_url(array('page' => 'admin_actionlog', 'type' => 'list', 'id' => $member_id_of), 'adminzone'));
         }
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('ocf_forum') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH_POSTS'), build_url(array('page' => 'search', 'type' => 'results', 'id' => 'ocf_posts', 'author' => $username, 'sort' => 'add_date', 'direction' => 'DESC', 'content' => ''), get_module_zone('search')), 'search');
     }
     if (has_actual_page_access($member_id_viewing, 'search') && addon_installed('search')) {
         $modules[] = array('content', do_lang_tempcode('SEARCH'), build_url(array('page' => 'search', 'type' => 'misc', 'author' => $username), get_module_zone('search')), 'search');
     }
     if (addon_installed('authors')) {
         $author = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT author FROM ' . get_table_prefix() . 'authors WHERE (forum_handle=' . strval($member_id_viewing) . ') OR (forum_handle IS NULL AND ' . db_string_equal_to('author', $username) . ')');
         if (has_actual_page_access($member_id_viewing, 'authors') && !is_null($author)) {
             $modules[] = array('content', do_lang_tempcode('AUTHOR'), build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $author), get_module_zone('authors')), 'me');
         }
     }
     require_code('ocf_members2');
     if (!is_guest() && ocf_may_whisper($member_id_of) && has_actual_page_access($member_id_viewing, 'topics') && ocf_may_make_personal_topic() && $member_id_viewing != $member_id_of) {
         $modules[] = !addon_installed('ocf_forum') ? NULL : array('contact', do_lang_tempcode('ADD_PERSONAL_TOPIC'), build_url(array('page' => 'topics', 'type' => 'new_pt', 'id' => $member_id_of), get_module_zone('topics')), 'reply');
     }
     $extra_sections = array();
     $info_details = array();
     $hooks = find_all_hooks('modules', 'members');
     foreach (array_keys($hooks) as $hook) {
         require_code('hooks/modules/members/' . filter_naughty_harsh($hook));
         $object = object_factory('Hook_members_' . filter_naughty_harsh($hook), true);
         if (is_null($object)) {
             continue;
         }
         if (method_exists($object, 'run')) {
             $hook_result = $object->run($member_id_of);
             $modules = array_merge($modules, $hook_result);
         }
         if (method_exists($object, 'get_info_details')) {
             $hook_result = $object->get_info_details($member_id_of);
             $info_details = array_merge($info_details, $hook_result);
         }
         if (method_exists($object, 'get_sections')) {
             $hook_result = $object->get_sections($member_id_of);
             $extra_sections = array_merge($extra_sections, $hook_result);
         }
     }
     if (addon_installed('ocf_contactmember')) {
         if (($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_allow_emails') == 1 || get_option('allow_email_disable') == '0') && $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address') != '' && !is_guest($member_id_of) && has_actual_page_access($member_id_viewing, 'contactmember') && $member_id_viewing != $member_id_of) {
             $redirect = get_self_url(true);
             $modules[] = array('contact', do_lang_tempcode('_EMAIL_MEMBER'), build_url(array('page' => 'contactmember', 'redirect' => $redirect, 'id' => $member_id_of), get_module_zone('contactmember')), 'reply');
         }
     }
     require_lang('menus');
     $sections = array('contact' => do_lang_tempcode('CONTACT'), 'profile' => do_lang_tempcode('EDIT_PROFILE'), 'views' => do_lang_tempcode('ACCOUNT'), 'usage' => do_lang_tempcode('USAGE'), 'content' => do_lang_tempcode('CONTENT'));
     $actions = array();
     global $M_SORT_KEY;
     $M_SORT_KEY = mixed();
     $M_SORT_KEY = 1;
     @uasort($modules, 'multi_sort');
     /* @ is to stop PHP bug warning about altered array contents when Tempcode copies are evaluated internally */
     foreach ($sections as $section_code => $section_title) {
         $links = new ocp_tempcode();
         foreach ($modules as $module) {
             if (count($module) == 3) {
                 list($_section_code, $lang, $url) = $module;
                 $rel = NULL;
             } else {
                 list($_section_code, $lang, $url, $rel) = $module;
             }
             if ($section_code == $_section_code) {
                 $links->attach(do_template('OCF_MEMBER_ACTION', array('_GUID' => '67b2a640a368c6f53f1b1fa10f922fd0', 'ID' => strval($member_id_of), 'URL' => $url, 'LANG' => $lang, 'REL' => $rel)));
             }
         }
         $actions[$section_code] = $links;
     }
     // Custom fields
     $_custom_fields = ocf_get_all_custom_fields_match_member($member_id_of, $member_id_viewing != $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL, $member_id_viewing == $member_id_of && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL);
     $custom_fields = array();
     require_code('encryption');
     $value = mixed();
     foreach ($_custom_fields as $name => $_value) {
         $value = $_value['RAW'];
         $rendered_value = $_value['RENDERED'];
         $encrypted_value = '';
         if (is_data_encrypted($value)) {
             $encrypted_value = remove_magic_encryption_marker($value);
         } elseif (is_integer($value)) {
             $value = strval($value);
         } elseif (is_float($value)) {
             $value = float_to_raw_string($value);
         }
         if (!is_object($value) && $value != '' || is_object($value) && !$value->is_empty()) {
             $custom_fields[] = array('NAME' => $name, 'RAW_VALUE' => $value, 'VALUE' => $rendered_value, 'ENCRYPTED_VALUE' => $encrypted_value);
             if ($name == do_lang('KEYWORDS')) {
                 $GLOBALS['SEO_KEYWORDS'] = is_object($value) ? $value->evaluate() : $value;
             }
             if ($name == do_lang('DESCRIPTION')) {
                 $GLOBALS['SEO_DESCRIPTION'] = is_object($value) ? $value->evaluate() : $value;
             }
         }
     }
     // Birthday
     $dob = '';
     if ($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_reveal_age') == 1) {
         $day = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_day');
         $month = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_month');
         $year = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_dob_year');
         if (!is_null($day)) {
             if (@strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) != '1963') {
                 $dob = strval($year) . '-' . str_pad(strval($month), 2, '0', STR_PAD_LEFT) . '-' . str_pad(strval($day), 2, '0', STR_PAD_LEFT);
             } else {
                 $dob = get_timezoned_date(mktime(12, 0, 0, $month, $day, $year), false, true, true);
             }
         }
     }
     // Find forum with most posts
     $forums = $GLOBALS['FORUM_DB']->query('SELECT id,f_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE f_cache_num_posts>0');
     $best_yet_forum = 0;
     // Initialise to integer type
     $best_yet_forum = NULL;
     $most_active_forum = NULL;
     $_best_yet_forum = $GLOBALS['FORUM_DB']->query_select('f_posts', array('COUNT(*) as cnt', 'p_cache_forum_id'), array('p_poster' => $member_id_of), 'GROUP BY p_cache_forum_id');
     $_best_yet_forum = collapse_2d_complexity('p_cache_forum_id', 'cnt', $_best_yet_forum);
     foreach ($forums as $forum) {
         if (array_key_exists($forum['id'], $_best_yet_forum) && (is_null($best_yet_forum) || $_best_yet_forum[$forum['id']] > $best_yet_forum)) {
             $most_active_forum = has_category_access($member_id_viewing, 'forums', strval($forum['id'])) ? protect_from_escaping(escape_html($forum['f_name'])) : do_lang_tempcode('PROTECTED_FORUM');
             $best_yet_forum = $_best_yet_forum[$forum['id']];
         }
     }
     $post_count = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_cache_num_posts');
     $best_post_fraction = $post_count == 0 ? do_lang_tempcode('NA_EM') : make_string_tempcode(integer_format(100 * $best_yet_forum / $post_count));
     $most_active_forum = is_null($best_yet_forum) ? new ocp_tempcode() : do_lang_tempcode('_MOST_ACTIVE_FORUM', $most_active_forum, make_string_tempcode(integer_format($best_yet_forum)), array($best_post_fraction));
     $time_for_them_raw = tz_time(time(), get_users_timezone($member_id_of));
     $time_for_them = get_timezoned_time(time(), true, $member_id_of);
     $banned = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_is_perm_banned') == 1 ? do_lang_tempcode('YES') : do_lang_tempcode('NO');
     $last_submit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_submit_time');
     $submit_days_ago = intval(floor(floatval(time() - $last_submit_time) / 60.0 / 60.0 / 24.0));
     require_code('ocf_groups');
     $primary_group_id = ocf_get_member_primary_group($member_id_of);
     $primary_group = ocf_get_group_link($primary_group_id);
     $signature = get_translated_tempcode($GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_signature'), $GLOBALS['FORUM_DB']);
     $last_visit_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_last_visit_time');
     if (member_is_online($member_id_of)) {
         $online_now = do_lang_tempcode('YES');
         $_online_now = true;
     } else {
         $_online_now = false;
         $minutes_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0));
         $hours_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0));
         $days_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0));
         $months_ago = intval(floor(floatval(time() - $last_visit_time) / 60.0 / 60.0 / 24.0 / 31.0));
         if ($minutes_ago < 180) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MINUTES', integer_format($minutes_ago));
         } elseif ($hours_ago < 72) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_HOURS', integer_format($hours_ago));
         } elseif ($days_ago < 93) {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_DAYS', integer_format($days_ago));
         } else {
             $online_now = do_lang_tempcode('_ONLINE_NOW_NO_MONTHS', integer_format($months_ago));
         }
     }
     $join_time = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_join_time');
     $days_joined = intval(round((time() - $join_time) / 60 / 60 / 24));
     $total_posts = $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)');
     $join_date = $join_time == 0 ? '' : get_timezoned_date($join_time, false);
     $count_posts = do_lang_tempcode('_COUNT_POSTS', integer_format($post_count), float_format(floatval($post_count) / floatval($days_joined == 0 ? 1 : $days_joined)), array(float_format(floatval(100 * $post_count) / floatval($total_posts == 0 ? 1 : $total_posts))));
     $a = $avatar_url == '' ? 0 : ocf_get_member_best_group_property($member_id_of, 'max_avatar_width');
     $b = $photo_thumb_url == '' ? 0 : intval(get_option('thumb_width'));
     $right_margin = max($a, $b) == 0 ? 'auto' : strval(max($a, $b) + 6) . 'px';
     breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MEMBERS'))));
     if (has_specific_permission($member_id_viewing, 'see_ip')) {
         $ip_address = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_ip_address');
     } else {
         $ip_address = '';
     }
     $secondary_groups = ocf_get_members_groups($member_id_of, true);
     unset($secondary_groups[$primary_group_id]);
     if (count($secondary_groups) > 0) {
         $_secondary_groups = array();
         $all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(true, false, false, array_keys($secondary_groups), $member_id_of);
         foreach (array_keys($secondary_groups) as $key) {
             $_secondary_groups[$key] = $all_groups[$key];
         }
         $secondary_groups = $_secondary_groups;
     }
     if (addon_installed('points')) {
         require_code('points');
         $count_points = integer_format(total_points($member_id_of));
     } else {
         $count_points = '';
     }
     $user_agent = NULL;
     $operating_system = NULL;
     if (has_specific_permission($member_id_viewing, 'show_user_browsing') && addon_installed('stats')) {
         $last_stats = $GLOBALS['SITE_DB']->query_select('stats', array('browser', 'operating_system'), array('the_user' => $member_id_of), 'ORDER BY date_and_time DESC', 1);
         if (array_key_exists(0, $last_stats)) {
             $user_agent = $last_stats[0]['browser'];
             $operating_system = $last_stats[0]['operating_system'];
         }
     }
     /*if ((get_option('allow_member_integration')!='off') && (get_option('allow_member_integration')!='hidden'))
     		{
     			$remote=$GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of,'m_password_compat_scheme')=='remote';
     		} else */
     $remote = NULL;
     $_on_probation = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_on_probation_until');
     if (is_null($_on_probation) || $_on_probation <= time()) {
         $on_probation = NULL;
     } else {
         $on_probation = strval($_on_probation);
     }
     $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $join_time), 'creator' => $username, 'publisher' => '', 'modified' => '', 'type' => 'Member', 'title' => '', 'identifier' => '_SEARCH:members:view:' . strval($member_id_of), 'description' => '', 'image' => $avatar_url == '' && has_specific_permission($member_id_viewing, 'view_member_photos') ? $photo_url : $avatar_url);
     // Look up member's clubs
     $clubs = array();
     if (addon_installed('ocf_clubs')) {
         $club_ids = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id_of, true);
         $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1), '', 200));
         if (count($club_rows) == 200) {
             $club_rows = NULL;
         }
         foreach ($club_ids as $club_id) {
             if (is_null($club_rows)) {
                 $club_rows = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), array('g_is_private_club' => 1, 'id' => $club_id), '', 200));
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
                 $club_rows = NULL;
             } else {
                 if (!array_key_exists($club_id, $club_rows)) {
                     continue;
                 }
                 $club_row = $club_rows[$club_id];
             }
             $club_name = get_translated_text($club_row['g_name'], $GLOBALS['FORUM_DB']);
             $club_forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums f LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON t.id=f.f_description', 'f.id', array('text_original' => do_lang('FORUM_FOR_CLUB', $club_name)));
             $clubs[] = array('CLUB_NAME' => $club_name, 'CLUB_ID' => strval($club_row['id']), 'CLUB_FORUM' => is_null($club_forum) ? '' : strval($club_forum));
         }
     }
     $content = do_template('OCF_MEMBER_PROFILE_ABOUT', array('_GUID' => 'fodfjdsfjsdljfdls', 'CLUBS' => $clubs, 'REMOTE' => $remote, 'RIGHT_MARGIN' => $right_margin, 'AVATAR_WIDTH' => strval($a) . 'px', 'PHOTO_WIDTH' => strval($b) . 'px', 'MOST_ACTIVE_FORUM' => $most_active_forum, 'TIME_FOR_THEM' => $time_for_them, 'TIME_FOR_THEM_RAW' => strval($time_for_them_raw), 'SUBMIT_DAYS_AGO' => integer_format($submit_days_ago), 'SUBMIT_TIME_RAW' => strval($last_submit_time), 'LAST_VISIT_TIME_RAW' => strval($last_visit_time), 'ONLINE_NOW' => $online_now, '_ONLINE_NOW' => $_online_now, 'BANNED' => $banned, 'USER_AGENT' => $user_agent, 'OPERATING_SYSTEM' => $operating_system, 'DOB' => $dob, 'IP_ADDRESS' => $ip_address, 'COUNT_POSTS' => $count_posts, 'COUNT_POINTS' => $count_points, 'PRIMARY_GROUP' => $primary_group, 'PRIMARY_GROUP_ID' => strval($primary_group_id), 'PHOTO_URL' => $photo_url, 'PHOTO_THUMB_URL' => $photo_thumb_url, 'EMAIL_ADDRESS' => $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_email_address'), 'AVATAR_URL' => $avatar_url, 'SIGNATURE' => $signature, 'JOIN_DATE' => $join_date, 'JOIN_DATE_RAW' => strval($join_time), 'CUSTOM_FIELDS' => $custom_fields, 'ACTIONS_contact' => $actions['contact'], 'ACTIONS_profile' => $actions['profile'], 'ACTIONS_views' => $actions['views'], 'ACTIONS_usage' => $actions['usage'], 'ACTIONS_content' => $actions['content'], 'USERNAME' => $username, 'MEMBER_ID' => strval($member_id_of), 'SECONDARY_GROUPS' => $secondary_groups, 'VIEW_PROFILES' => $member_id_viewing == $member_id_of || has_specific_permission($member_id_viewing, 'view_profiles'), 'ON_PROBATION' => $on_probation, 'EXTRA_INFO_DETAILS' => $info_details, 'EXTRA_SECTIONS' => $extra_sections));
     return array($title, $content, $order);
 }
Exemple #26
0
/**
 * Add a new booking to the database.
 *
 * @param  array		Booking details structure.
 * @param  MEMBER		Member ID being added against.
 * @return array		Booking details structure.
 */
function add_booking($request, $member_id)
{
    foreach ($request as $rid => $req) {
        $days = days_in_range($req['start_day'], $req['start_month'], $req['start_year'], $req['end_day'], $req['end_month'], $req['end_year']);
        // Now insert into DB. Technically each day gets its own booking
        for ($i = 0; $i < $req['quantity']; $i++) {
            $code = mixed();
            foreach ($days as $j => $_date) {
                list($day, $month, $year) = $_date;
                $code = find_free_bookable_code($req['bookable_id'], $day, $month, $year, $code);
                // Hopefully $code will stay the same, but it might not
                if (is_null($code)) {
                    fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
                }
                // Should not be possible, as we already checked availability
                $row = array('bookable_id' => $req['bookable_id'], 'member_id' => $member_id, 'b_day' => $day, 'b_month' => $month, 'b_year' => $year, 'code_allocation' => $code, 'notes' => $req['notes'], 'booked_at' => time(), 'paid_at' => NULL, 'paid_trans_id' => NULL);
                $booking_id = $GLOBALS['SITE_DB']->query_insert('booking', $row, true);
                if (!array_key_exists('_rows', $request[$rid])) {
                    $request[$rid]['_rows'] = array();
                }
                $request[$rid]['_rows'][] = $row;
                // Supplements
                foreach ($req['supplements'] as $supplement_id => $supplement) {
                    $GLOBALS['SITE_DB']->query_insert('booking_supplement', array('booking_id' => $booking_id, 'supplement_id' => $supplement_id, 'quantity' => $supplement['quantity'], 'notes' => $supplement['notes']));
                }
            }
        }
    }
    return $request;
}
Exemple #27
0
 /**
  * Render posts.
  *
  * @param  integer		Maximum to load if non-threaded
  * @param  array			Tree structure of posts
  * @param  boolean		Whether the current user may reply to the topic (influences what buttons show)
  * @param  ?AUTO_LINK	Only show posts under here (NULL: show posts from root)
  * @param  array			Review ratings rows
  * @param  AUTO_LINK		ID of forum this topic in in
  * @return tempcode		Rendered tree structure
  */
 function _render_post_tree($num_to_show_limit, $tree, $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id)
 {
     list($rendered, ) = $tree;
     $sequence = new ocp_tempcode();
     foreach ($rendered as $post) {
         if (get_forum_type() == 'ocf') {
             require_code('ocf_topicview');
             require_code('ocf_posts');
             $post += ocf_get_details_to_show_post($post);
         }
         // Misc details
         $datetime_raw = $post['date'];
         $datetime = get_timezoned_date($post['date']);
         $poster_url = is_guest($post['user']) ? new ocp_tempcode() : $GLOBALS['FORUM_DRIVER']->member_profile_url($post['user'], false, true);
         $poster_name = array_key_exists('username', $post) ? $post['username'] : $GLOBALS['FORUM_DRIVER']->get_username($post['user']);
         if (is_null($poster_name)) {
             $poster_name = do_lang('UNKNOWN');
         }
         $highlight = $highlight_by_user === $post['user'];
         // Find review, if there is one
         $individual_review_ratings = array();
         foreach ($all_individual_review_ratings as $potential_individual_review_rating) {
             if ($potential_individual_review_rating['r_post_id'] == $post['id']) {
                 $individual_review_ratings[$potential_individual_review_rating['r_rating_type']] = array('REVIEW_TITLE' => $potential_individual_review_rating['r_rating_type'], 'REVIEW_RATING' => float_to_raw_string($potential_individual_review_rating['r_rating']));
             }
         }
         // Edit URL
         $emphasis = new ocp_tempcode();
         $buttons = new ocp_tempcode();
         $last_edited = new ocp_tempcode();
         $last_edited_raw = '';
         $unvalidated = new ocp_tempcode();
         $poster = mixed();
         $poster_details = new ocp_tempcode();
         $is_spacer_post = false;
         if (get_forum_type() == 'ocf') {
             // Spacer post fiddling
             if (!is_null($this->first_post_id) && !is_null($this->topic_title) && !is_null($this->topic_description) && !is_null($this->topic_description_link)) {
                 $is_spacer_post = $post['id'] == $this->first_post_id && substr($post['message_comcode'], 0, strlen('[semihtml]' . do_lang('SPACER_POST_MATCHER'))) == '[semihtml]' . do_lang('SPACER_POST_MATCHER');
                 if ($is_spacer_post) {
                     $c_prefix = do_lang('COMMENT') . ': #';
                     if (substr($this->topic_description, 0, strlen($c_prefix)) == $c_prefix && $this->topic_description_link != '') {
                         list($linked_type, $linked_id) = explode('_', substr($this->topic_description, strlen($c_prefix)), 2);
                         $linked_url = $this->topic_description_link;
                         require_code('ocf_posts');
                         list($new_description, $new_post) = ocf_display_spacer_post($linked_type, $linked_id);
                         //if (!is_null($new_description)) $this->topic_description=$new_description;	Actually, it's a bit redundant
                         if (!is_null($new_post)) {
                             $post['message'] = $new_post;
                         }
                         $highlight = false;
                         $this->topic_title = do_lang('SPACER_TOPIC_TITLE_WRAP', $this->topic_title);
                         $post['title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $post['title']);
                         $this->topic_description = '';
                     }
                 }
             }
             // Misc meta details for post
             $emphasis = ocf_get_post_emphasis($post);
             $unvalidated = $post['validated'] == 0 ? do_lang_tempcode('UNVALIDATED') : new ocp_tempcode();
             if (array_key_exists('last_edit_time', $post)) {
                 $last_edited = do_template('OCF_TOPIC_POST_LAST_EDITED', array('LAST_EDIT_DATE_RAW' => is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']), 'LAST_EDIT_DATE' => $post['last_edit_time_string'], 'LAST_EDIT_PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['last_edit_by'], false, true), 'LAST_EDIT_USERNAME' => $post['last_edit_by_username']));
                 $last_edited_raw = is_null($post['last_edit_time']) ? '' : strval($post['last_edit_time']);
             }
             // Post buttons
             if (!$is_spacer_post) {
                 if (!is_null($this->topic_id)) {
                     if (is_null($this->topic_info)) {
                         $this->topic_info = ocf_read_in_topic($this->topic_id, 0, 0, false, false);
                     }
                     require_lang('ocf');
                     $buttons = ocf_render_post_buttons($this->topic_info, $post, $may_reply);
                 }
             }
             // OCF renderings of poster
             static $hooks = NULL;
             if (is_null($hooks)) {
                 $hooks = find_all_hooks('modules', 'topicview');
             }
             static $hook_objects = NULL;
             if (is_null($hook_objects)) {
                 $hook_objects = array();
                 foreach (array_keys($hooks) as $hook) {
                     require_code('hooks/modules/topicview/' . filter_naughty_harsh($hook));
                     $object = object_factory('Hook_' . filter_naughty_harsh($hook), true);
                     if (is_null($object)) {
                         continue;
                     }
                     $hook_objects[$hook] = $object;
                 }
             }
             if (!$is_spacer_post) {
                 if (!is_guest($post['poster'])) {
                     require_code('ocf_members2');
                     $poster_details = ocf_show_member_box($post, false, $hooks, $hook_objects, false);
                 } else {
                     $custom_fields = new ocp_tempcode();
                     if (array_key_exists('ip_address', $post) && addon_installed('ocf_forum')) {
                         $custom_fields->attach(do_template('OCF_TOPIC_POST_CUSTOM_FIELD', array('NAME' => do_lang_tempcode('IP_ADDRESS'), 'VALUE' => $post['ip_address'])));
                         $poster_details = do_template('OCF_GUEST_DETAILS', array('CUSTOM_FIELDS' => $custom_fields));
                     } else {
                         $poster_details = new ocp_tempcode();
                     }
                 }
             }
             if (addon_installed('ocf_forum')) {
                 if (!is_guest($post['poster'])) {
                     $poster = do_template('OCF_POSTER_MEMBER', array('ONLINE' => member_is_online($post['poster']), 'ID' => strval($post['poster']), 'POSTER_DETAILS' => $poster_details, 'PROFILE_URL' => $GLOBALS['FORUM_DRIVER']->member_profile_url($post['poster'], false, true), 'POSTER_USERNAME' => $post['poster_username']));
                 } else {
                     $ip_link = array_key_exists('ip_address', $post) && has_actual_page_access(get_member(), 'admin_lookup') ? build_url(array('page' => 'admin_lookup', 'param' => $post['ip_address']), get_module_zone('admin_lookup')) : new ocp_tempcode();
                     $poster = do_template('OCF_POSTER_GUEST', array('IP_LINK' => $ip_link, 'POSTER_DETAILS' => $poster_details, 'POSTER_USERNAME' => $post['poster_username']));
                 }
             } else {
                 $poster = make_string_tempcode(escape_html($post['poster_username']));
             }
         }
         // Child posts
         $children = mixed();
         // NULL
         $other_ids = array();
         if (array_key_exists('children', $post)) {
             foreach ($post['children'][1] as $u) {
                 $other_ids[] = strval($u['id']);
             }
             if ($this->is_threaded) {
                 $children = $this->_render_post_tree($num_to_show_limit, $post['children'], $may_reply, $highlight_by_user, $all_individual_review_ratings, $forum_id);
             }
         }
         if (get_forum_type() == 'ocf') {
             require_code('feedback');
             actualise_rating(true, 'post', strval($post['id']), get_self_url(), $post['title']);
             $rating = display_rating(get_self_url(), $post['title'], 'post', strval($post['id']), 'RATING_INLINE_DYNAMIC', $post['user']);
         } else {
             $rating = new ocp_tempcode();
         }
         if (array_key_exists('intended_solely_for', $post)) {
             decache('side_ocf_personal_topics', array(get_member()));
             decache('_new_pp', array(get_member()));
         }
         // Render
         $sequence->attach(static_evaluate_tempcode(do_template('POST', array('_GUID' => 'eb7df038959885414e32f58e9f0f9f39', 'INDIVIDUAL_REVIEW_RATINGS' => $individual_review_ratings, 'HIGHLIGHT' => $highlight, 'TITLE' => $post['title'], 'TIME_RAW' => strval($datetime_raw), 'TIME' => $datetime, 'POSTER_ID' => strval($post['user']), 'POSTER_URL' => $poster_url, 'POSTER_NAME' => $poster_name, 'POSTER' => $poster, 'POSTER_DETAILS' => $poster_details, 'ID' => strval($post['id']), 'POST' => $post['message'], 'POST_COMCODE' => isset($post['message_comcode']) ? $post['message_comcode'] : NULL, 'CHILDREN' => $children, 'OTHER_IDS' => count($other_ids) == 0 ? NULL : $other_ids, 'RATING' => $rating, 'EMPHASIS' => $emphasis, 'BUTTONS' => $buttons, 'LAST_EDITED_RAW' => $last_edited_raw, 'LAST_EDITED' => $last_edited, 'TOPIC_ID' => is_null($this->topic_id) ? '' : strval($this->topic_id), 'UNVALIDATED' => $unvalidated, 'IS_SPACER_POST' => $is_spacer_post, 'NUM_TO_SHOW_LIMIT' => strval($num_to_show_limit)))));
     }
     return $sequence;
 }
/**
 * Add a member.
 *
 * @param  SHORT_TEXT		The username.
 * @param  SHORT_TEXT		The password.
 * @param  SHORT_TEXT		The e-mail address.
 * @param  ?array				A list of usergroups (NULL: default/current usergroups).
 * @param  ?integer			Day of date of birth (NULL: unknown).
 * @param  ?integer			Month of date of birth (NULL: unknown).
 * @param  ?integer			Year of date of birth (NULL: unknown).
 * @param  array				A map of custom field values (field-id=>value).
 * @param  ?ID_TEXT			The member timezone (NULL: auto-detect).
 * @param  ?GROUP				The member's primary (NULL: default).
 * @param  BINARY				Whether the profile has been validated.
 * @param  ?TIME				When the member joined (NULL: now).
 * @param  ?TIME				When the member last visited (NULL: now).
 * @param  ID_TEXT			The member's default theme.
 * @param  ?URLPATH			The URL to the member's avatar (blank: none) (NULL: choose one automatically).
 * @param  LONG_TEXT			The member's signature (blank: none).
 * @param  BINARY				Whether the member is permanently banned.
 * @param  BINARY				Whether posts are previewed before they are made.
 * @param  BINARY				Whether the member's age may be shown.
 * @param  SHORT_TEXT		The member's title (blank: get from primary).
 * @param  URLPATH			The URL to the member's photo (blank: none).
 * @param  URLPATH			The URL to the member's photo thumbnail (blank: none).
 * @param  BINARY				Whether the member sees signatures in posts.
 * @param  ?BINARY			Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config).
 * @param  ?LANGUAGE_NAME	The member's language (NULL: auto detect).
 * @param  BINARY				Whether the member allows e-mails via the site.
 * @param  BINARY				Whether the member allows e-mails from staff via the site.
 * @param  LONG_TEXT			Personal notes of the member.
 * @param  ?IP					The member's IP address (NULL: IP address of current user).
 * @param  SHORT_TEXT		The code required before the account becomes active (blank: already entered).
 * @param  boolean			Whether to check details for correctness.
 * @param  ?ID_TEXT			The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted).
 * @param  SHORT_TEXT		The password salt (blank: password compatibility scheme does not use a salt / auto-generate).
 * @param  BINARY				Whether the member likes to view zones without menus, when a choice is available.
 * @param  ?TIME				The time the member last made a submission (NULL: set to now).
 * @param  ?AUTO_LINK		Force an ID (NULL: don't force an ID)
 * @param  BINARY				Whether the member username will be highlighted.
 * @param  SHORT_TEXT		Usergroups that may PT the member.
 * @param  LONG_TEXT			Rules that other members must agree to before they may start a PT with the member.
 * @return AUTO_LINK			The ID of the new member.
 */
function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '')
{
    if (is_null($auto_monitor_contrib_content)) {
        $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1;
    }
    if (is_null($password_compatibility_scheme)) {
        if (get_value('no_password_hashing') === '1') {
            $password_compatibility_scheme = 'plain';
        } else {
            $password_compatibility_scheme = '';
        }
    }
    if (is_null($language)) {
        $language = '';
    }
    if (is_null($signature)) {
        $signature = '';
    }
    if (is_null($title)) {
        $title = '';
    }
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    if (is_null($allow_emails)) {
        $allow_emails = 1;
    }
    if (is_null($allow_emails_from_staff)) {
        $allow_emails_from_staff = 1;
    }
    if (is_null($personal_notes)) {
        $personal_notes = '';
    }
    if (is_null($avatar_url)) {
        if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) {
            $avatar_url = '';
        } else {
            if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) {
                require_code('themes2');
                $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']);
                shuffle($codes);
                $results = array();
                foreach ($codes as $code) {
                    if (strpos($code, 'ocp_fanatic') !== false) {
                        continue;
                    }
                    $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true)));
                    if (is_null($count)) {
                        $count = 0;
                    }
                    $results[$code] = $count;
                }
                @asort($results);
                // @'d as type checker fails for some odd reason
                $found_avatars = array_keys($results);
                $avatar_url = find_theme_image(array_shift($found_avatars), true, true);
            }
            if (is_null($avatar_url)) {
                $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => ''));
                // In case failure cached, gets very confusing
                $avatar_url = find_theme_image('ocf_default_avatars/default', true, true);
                if (is_null($avatar_url)) {
                    $avatar_url = '';
                }
            }
        }
    }
    if ($check_correctness) {
        if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) {
            ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL);
        }
        if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) {
            require_code('type_validation');
            if (!is_valid_email_address($email_address) && $email_address != '') {
                warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address)));
            }
        }
    }
    require_code('ocf_members');
    require_code('ocf_groups');
    if (is_null($last_submit_time)) {
        $last_submit_time = time();
    }
    if (is_null($join_time)) {
        $join_time = time();
    }
    if (is_null($last_visit_time)) {
        $last_visit_time = time();
    }
    if (is_null($primary_group)) {
        $primary_group = get_first_default_group();
        // This is members
    }
    if (is_null($secondary_groups)) {
        $secondary_groups = ocf_get_all_default_groups(false);
    }
    foreach ($secondary_groups as $_g_id => $g_id) {
        if ($g_id == $primary_group) {
            unset($secondary_groups[$_g_id]);
        }
    }
    if (is_null($ip_address)) {
        $ip_address = get_ip_address();
    }
    if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') {
        $password_compatibility_scheme = 'plain';
        $salt = '';
    }
    if ($salt == '' && $password_compatibility_scheme == '') {
        $salt = produce_salt();
        $password_salted = md5($salt . md5($password));
    } else {
        $password_salted = $password;
    }
    // Supplement custom field values given with defaults, and check constraints
    $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups));
    require_code('fields');
    foreach ($all_fields as $field) {
        $field_id = $field['id'];
        if (array_key_exists($field_id, $custom_fields)) {
            if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) {
                access_denied('I_ERROR');
            }
        } else {
            $custom_fields[$field_id] = '';
        }
    }
    if (!addon_installed('unvalidated')) {
        $validated = 1;
    }
    $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL);
    if (!is_null($id)) {
        $map['id'] = $id;
    }
    $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true);
    if ($check_correctness) {
        // If it was an invite/recommendation, award the referrer
        if (addon_installed('recommend')) {
            $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time');
            if (!is_null($inviter)) {
                if (addon_installed('points')) {
                    require_code('points2');
                    require_lang('recommend');
                    system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter);
                }
                if (addon_installed('chat')) {
                    require_code('chat2');
                    buddy_add($inviter, $member_id);
                    buddy_add($member_id, $inviter);
                }
            }
        }
    }
    $value = mixed();
    // Store custom fields
    $row = array('mf_member_id' => $member_id);
    $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields);
    foreach ($custom_fields as $field_num => $value) {
        if (!array_key_exists($field_num, $all_fields_types)) {
            continue;
        }
        // Trying to set a field we're not allowed to (doesn't apply to our group)
        $ob = get_fields_hook($all_fields_types[$field_num]);
        list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]);
        if (strpos($storage_type, '_trans') !== false) {
            $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
        }
        $row['field_' . strval($field_num)] = $value;
    }
    // Set custom field row
    $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type'));
    foreach ($all_fields_regardless as $field) {
        if (!array_key_exists('field_' . strval($field['id']), $row)) {
            $ob = get_fields_hook($field['cf_type']);
            list(, , $storage_type) = $ob->get_field_value_row_bits($field);
            $value = '';
            if (strpos($storage_type, '_trans') !== false) {
                $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']);
            }
            $row['field_' . strval($field['id'])] = $value;
        }
    }
    $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row);
    // Any secondary work
    foreach ($secondary_groups as $g) {
        if ($g != $primary_group) {
            $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1);
            $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1));
        }
    }
    if ($check_correctness) {
        if (function_exists('decache')) {
            decache('side_stats');
        }
    }
    return $member_id;
}
Exemple #29
0
 /**
  * Standard modular directory creation function for OcCLE FS hooks.
  *
  * @param  array		The current meta-directory path
  * @param  string		The root node of the current meta-directory
  * @param  string		The new directory name
  * @param  array		A reference to the OcCLE filesystem object
  * @return boolean		Success?
  */
 function make_directory($meta_dir, $meta_root_node, $new_dir_name, &$occle_fs)
 {
     $GLOBALS['NO_DB_SCOPE_CHECK'] = true;
     if (count($meta_dir) < 1) {
         return false;
     } elseif (count($meta_dir) == 1) {
         //We're in a field, and adding a new row
         $where = $this->_do_where($meta_dir[0], $new_dir_name);
         $fields = $GLOBALS['SITE_DB']->query_select('db_meta', array('m_name', 'm_type'), array('m_table' => $meta_dir[0]));
         $value = mixed();
         foreach ($fields as $field) {
             $field['m_type'] = str_replace('?', '', str_replace('*', '', $field['m_type']));
             if (!array_key_exists($field['m_name'], $where)) {
                 if (in_array($field['m_type'], array('AUTO', 'USER', 'INTEGER', 'UINTEGER', 'MEMBER', 'SHORT_INTEGER', 'AUTO_LINK', 'BINARY', 'GROUP', 'TIME'))) {
                     $value = 0;
                 } elseif ($field['m_type'] == 'REAL') {
                     $value = 0.0;
                 } else {
                     $value = '';
                 }
                 $where[$field['m_name']] = $this->unescape_name($value);
             }
         }
         $GLOBALS['SITE_DB']->query_insert($meta_dir[0], $where);
     } else {
         return false;
     }
     //Directories aren't allowed to be added anywhere else
     return true;
 }
Exemple #30
0
/**
 * Get rating information for the specified resource.
 *
 * @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  ID_TEXT		The type (download, etc) that this rating is for
 * @param  ID_TEXT		The ID of the type that this rating is for
 * @param  ID_TEXT		The template to use to display the rating box
 * @param  ?MEMBER		Content owner (NULL: none)
 * @return ?array			Current rating information (ready to be passed into a template). RATING is the rating (out of 10), NUM_RATINGS s the number of ratings so far, RATING_FORM is the tempcode of the rating box (NULL: rating disabled)
 */
function get_rating_simple_array($content_url, $content_title, $content_type, $content_id, $form_tpl = 'RATING_FORM', $submitter = NULL)
{
    if (get_option('is_on_rating') == '1') {
        $liked_by = mixed();
        // Work out structure first
        global $RATINGS_STRUCTURE;
        $all_rating_criteria = array();
        if (array_key_exists($content_type, $RATINGS_STRUCTURE)) {
            $likes = $RATINGS_STRUCTURE[$content_type][0] == RATING_TYPE_like_dislike;
            foreach ($RATINGS_STRUCTURE[$content_type][1] as $r => $t) {
                $rating_for_type = $content_type;
                if ($r != '') {
                    $rating_for_type .= '_' . $r;
                }
                $all_rating_criteria[$rating_for_type] = array('TITLE' => $t, 'TYPE' => $r, 'RATING' => '0');
            }
        } else {
            $likes = get_option('likes') == '1';
            $all_rating_criteria[$content_type] = array('TITLE' => '', 'TYPE' => '', 'NUM_RATINGS' => '0', 'RATING' => '0');
        }
        // Fill in structure
        $has_ratings = false;
        $overall_num_ratings = 0;
        $overall_rating = 0.0;
        foreach ($all_rating_criteria as $i => $rating_criteria) {
            $rating_for_type = $content_type;
            if ($rating_criteria['TYPE'] != '') {
                $rating_for_type .= '_' . $rating_criteria['TYPE'];
            }
            $_num_ratings = $GLOBALS['SITE_DB']->query_select('rating', array('COUNT(*) AS cnt', 'SUM(rating) AS compound_rating'), array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id), '', 1);
            $num_ratings = $_num_ratings[0]['cnt'];
            if ($num_ratings > 0) {
                $rating = $_num_ratings[0]['compound_rating'];
                $overall_num_ratings = max($overall_num_ratings, $num_ratings);
                if ($num_ratings < MAX_LIKES_TO_SHOW && $likes) {
                    if (is_null($liked_by)) {
                        $liked_by = array();
                    }
                    if (count($liked_by) < MAX_LIKES_TO_SHOW) {
                        $_liked_by = $GLOBALS['SITE_DB']->query_select('rating', array('rating_member'), array('rating_for_type' => $rating_for_type, 'rating_for_id' => $content_id, 'rating' => 10));
                        foreach ($_liked_by as $l) {
                            $username = $GLOBALS['FORUM_DRIVER']->get_username($l['rating_member']);
                            if (!is_null($username)) {
                                $liked_by[] = array('MEMBER_ID' => strval($l['rating_member']), 'USERNAME' => $username);
                                if (count($liked_by) == MAX_LIKES_TO_SHOW) {
                                    break;
                                }
                            }
                        }
                    }
                }
                $calculated_rating = intval(round($rating / floatval($num_ratings)));
                $overall_rating += $calculated_rating;
                $all_rating_criteria[$i] = array('NUM_RATINGS' => integer_format($num_ratings), 'RATING' => make_string_tempcode(strval($calculated_rating))) + $all_rating_criteria[$i];
                $GLOBALS['META_DATA']['rating' . ($rating_criteria['TYPE'] == '' ? '' : '_' . $rating_criteria['TYPE'])] = strval($calculated_rating);
                $has_ratings = true;
            }
        }
        // Work out possible errors that mighr prevent rating being allowed
        $error = new ocp_tempcode();
        $rate_url = new ocp_tempcode();
        if ($submitter === get_member() && !is_guest()) {
            $error = do_lang_tempcode('RATE_DENIED_OWN');
        } elseif (!has_specific_permission(get_member(), 'rate', get_page_name())) {
            $error = do_lang_tempcode('RATE_DENIED');
        } elseif (already_rated(array_keys($all_rating_criteria), $content_id)) {
            $error = do_lang_tempcode('NORATE');
        } else {
            $rate_url = get_self_url();
        }
        // Templating
        $tpl_params = array('CONTENT_URL' => $content_url, 'CONTENT_TITLE' => $content_title, 'ERROR' => $error, 'CONTENT_TYPE' => $content_type, 'ID' => $content_id, 'URL' => $rate_url, 'ALL_RATING_CRITERIA' => $all_rating_criteria, 'OVERALL_NUM_RATINGS' => integer_format($overall_num_ratings), 'OVERALL_RATING' => make_string_tempcode(strval(intval($overall_rating / floatval(count($all_rating_criteria))))), 'HAS_RATINGS' => $has_ratings, 'SIMPLISTIC' => count($all_rating_criteria) == 1, 'LIKES' => $likes, 'LIKED_BY' => $liked_by);
        $rating_form = do_template($form_tpl, $tpl_params);
        return $tpl_params + array('RATING_FORM' => $rating_form);
    }
    return NULL;
}