Beispiel #1
0
 /**
  * Find if the given member id and password is valid. If username is NULL, then the member id is used instead.
  * All authorisation, cookies, and form-logins, are passed through this function.
  * Some forums do cookie logins differently, so a Boolean is passed in to indicate whether it is a cookie login.
  *
  * @param  ?SHORT_TEXT	The member username (NULL: don't use this in the authentication - but look it up using the ID if needed)
  * @param  MEMBER			The member id
  * @param  MD5				The md5-hashed password
  * @param  string			The raw password
  * @param  boolean		Whether this is a cookie login
  * @return array			A map of 'id' and 'error'. If 'id' is NULL, an error occurred and 'error' is set
  */
 function forum_authorise_login($username, $userid, $password_hashed, $password_raw, $cookie_login = false)
 {
     $out = array();
     $out['id'] = NULL;
     if (is_null($userid)) {
         $rows = $this->connection->query_select('members', array('*'), array('name' => $this->ipb_escape($username)), '', 1);
         if (array_key_exists(0, $rows)) {
             $this->MEMBER_ROWS_CACHED[$rows[0]['member_id']] = $rows[0];
         } else {
             $rows = $this->connection->query_select('members', array('*'), array('members_display_name' => $this->ipb_escape($username)), '', 1);
             if (array_key_exists(0, $rows)) {
                 $this->MEMBER_ROWS_CACHED[$rows[0]['member_id']] = $rows[0];
             }
         }
     } else {
         $rows[0] = $this->get_member_row($userid);
     }
     if (!array_key_exists(0, $rows)) {
         $out['error'] = do_lang_tempcode('_USER_NO_EXIST', $username);
         return $out;
     }
     $row = $rows[0];
     if ($row['member_banned'] == 1) {
         $out['error'] = do_lang_tempcode('USER_BANNED');
         return $out;
     }
     if ($cookie_login) {
         if ($password_hashed != $row['member_login_key']) {
             $out['error'] = do_lang_tempcode('USER_BAD_PASSWORD');
             return $out;
         }
         // Check stronghold
         global $SITE_INFO;
         if (array_key_exists('stronghold_cookies', $SITE_INFO) && $SITE_INFO['stronghold_cookies'] == 1) {
             $ip_octets = explode('.', ocp_srv('REMOTE_ADDR'));
             $crypt_salt = md5(get_db_forums_password() . get_db_forums_user());
             $a = get_member_cookie();
             $b = get_pass_cookie();
             for ($i = 0; $i < strlen($a) && $i < strlen($b); $i++) {
                 if ($a[$i] != $b[$i]) {
                     break;
                 }
             }
             $cookie_prefix = substr($a, 0, $i);
             $cookie = ocp_admirecookie($cookie_prefix . 'ipb_stronghold');
             $stronghold = md5(md5(strval($row['member_id']) . '-' . $ip_octets[0] . '-' . $ip_octets[1] . '-' . $row['member_login_key']) . $crypt_salt);
             if ($cookie != $stronghold) {
                 $out['error'] = do_lang_tempcode('USER_BAD_STRONGHOLD');
                 return $out;
             }
         }
     } else {
         if (!$this->_auth_hashed($row['member_id'], $password_hashed)) {
             $out['error'] = do_lang_tempcode('USER_BAD_PASSWORD');
             return $out;
         }
     }
     $pos = strpos(get_member_cookie(), 'member_id');
     ocp_eatcookie(substr(get_member_cookie(), 0, $pos) . 'session_id');
     $out['id'] = $row['member_id'];
     return $out;
 }
Beispiel #2
0
/**
 * Update a language code, in such a way that new attachments are created if they were specified.
 *
 * @param  integer		The language id
 * @param  LONG_TEXT		The new text
 * @param  ID_TEXT		The arbitrary type that the attached is for (e.g. download)
 * @param  ID_TEXT		The id in the set of the arbitrary types that the attached is for
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether to backup the language string before changing it
 * @param  ?MEMBER		The member to use for ownership permissions (NULL: current member)
 * @return integer		The language id
 */
function update_lang_comcode_attachments($lang_id, $text, $type, $id, $connection = NULL, $backup_string = false, $for_member = NULL)
{
    if ($lang_id == 0) {
        return insert_lang_comcode_attachments(3, $text, $type, $id, $connection, false, $for_member);
    }
    if ($text === STRING_MAGIC_NULL) {
        return $lang_id;
    }
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    require_lang('comcode');
    _check_attachment_count();
    $test = $connection->query_value_null_ok('translate', 'text_original', array('id' => $id, 'language' => user_lang()));
    if ($backup_string) {
        $current = $connection->query_select('translate', array('*'), array('id' => $lang_id, 'language' => user_lang()));
        if (!array_key_exists(0, $current)) {
            $current = $connection->query_select('translate', array('*'), array('id' => $lang_id));
        }
        $connection->query_insert('translate_history', array('lang_id' => $lang_id, 'language' => $current[0]['language'], 'text_original' => $current[0]['text_original'], 'broken' => $current[0]['broken'], 'action_member' => get_member(), 'action_time' => time()));
    }
    $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    $_info = do_comcode_attachments($text, $type, $id, false, $connection, NULL, $for_member);
    $text2 = '';
    //Actually we'll let it regenerate with the correct permissions ($member, not $for_member) $_info['tempcode']->to_assembly();
    $remap = array('text_original' => $_info['comcode'], 'text_parsed' => $text2);
    if (ocp_admirecookie('use_wysiwyg', '1') == '0' && get_value('edit_with_my_comcode_perms') === '1' || !has_specific_permission($member, 'allow_html') || !has_specific_permission($member, 'use_very_dangerous_comcode')) {
        $remap['source_user'] = $member;
    }
    if (!is_null($test)) {
        $connection->query_update('translate', $remap, array('id' => $lang_id, 'language' => user_lang()));
    } else {
        $connection->query_update('translate', $remap, array('id' => $lang_id));
    }
    return $lang_id;
}
 /**
  * Standard modular run function.
  *
  * @param  array		A map of parameters.
  * @return tempcode	The result of execution.
  */
 function run($map)
 {
     unset($map);
     require_css('side_blocks');
     $member = get_member();
     $forum = get_forum_type();
     $content = new ocp_tempcode();
     $links = new ocp_tempcode();
     if (!is_guest()) {
         // Admins can jump user
         $has_su = get_option('ocp_show_su') == '1' && has_specific_permission(get_member(), 'assume_any_member');
         $staff_actions = new ocp_tempcode();
         $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member());
         if ($forum != 'none') {
             if (!has_no_forum() && get_option('forum_show_personal_stats_posts') == '1') {
                 // Post count
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '371dfee46e8c40b1b109e0350055f8cc', 'KEY' => do_lang_tempcode('COUNT_POSTSCOUNT'), 'VALUE' => integer_format($GLOBALS['FORUM_DRIVER']->get_post_count($member)))));
             }
             if (!has_no_forum() && get_option('forum_show_personal_stats_topics') == '1') {
                 // Topic count
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('KEY' => do_lang_tempcode('COUNT_TOPICSCOUNT'), 'VALUE' => integer_format($GLOBALS['FORUM_DRIVER']->get_topic_count($member)))));
             }
             // Member profile view link
             if (get_option('ocf_show_profile_link') == '1') {
                 $url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member, true, true);
                 $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINK', array('_GUID' => '2c8648c953c802a9de41c3adeef0e97f', 'NAME' => do_lang_tempcode('MY_PROFILE'), 'URL' => $url, 'REL' => 'me')));
             }
         }
         // Point count and point profile link
         if (addon_installed('points')) {
             require_lang('points');
             require_code('points');
             if (get_option('points_show_personal_stats_points_left') == '1') {
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '6241e58e30457576735f3a2618fd7fff', 'KEY' => do_lang_tempcode('COUNT_POINTS_LEFT'), 'VALUE' => integer_format(available_points($member)))));
             }
             if (get_option('points_show_personal_stats_points_used') == '1') {
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '6241e58edfdsf735f3a2618fd7fff', 'KEY' => do_lang_tempcode('COUNT_POINTS_USED'), 'VALUE' => integer_format(points_used($member)))));
             }
             if (get_option('points_show_personal_stats_total_points') == '1') {
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '3e6183abf9054574c0cd292d25a4fe5c', 'KEY' => do_lang_tempcode('COUNT_POINTS_EVER'), 'VALUE' => integer_format(total_points($member)))));
             }
             if (get_option('points_show_personal_stats_gift_points_left') == '1') {
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '6241e5ssd45ddsdsdsa2618fd7fff', 'KEY' => do_lang_tempcode('COUNT_GIFT_POINTS_LEFT'), 'VALUE' => integer_format(get_gift_points_to_give($member)))));
             }
             if (get_option('points_show_personal_stats_gift_points_used') == '1') {
                 $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '6241eddsd4sdddssdsa2618fd7fff', 'KEY' => do_lang_tempcode('COUNT_GIFT_POINTS_USED'), 'VALUE' => integer_format(get_gift_points_used($member)))));
             }
         }
         if (get_option('ocp_show_personal_usergroup') == '1') {
             $group_id = $GLOBALS['FORUM_DRIVER']->pname_group($GLOBALS['FORUM_DRIVER']->pget_row($username));
             $usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list();
             if (array_key_exists($group_id, $usergroups)) {
                 if (get_forum_type() == 'ocf') {
                     $group_url = build_url(array('page' => 'groups', 'type' => 'view', 'id' => $group_id), get_module_zone('groups'));
                     $hyperlink = hyperlink($group_url, $usergroups[$group_id], false, true);
                     $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE_COMPLEX', array('_GUID' => 'sas41eddsd4sdddssdsa2618fd7fff', 'KEY' => do_lang_tempcode('GROUP'), 'VALUE' => $hyperlink)));
                 } else {
                     $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => '65180134fbc4cf7e227011463d466677', 'KEY' => do_lang_tempcode('GROUP'), 'VALUE' => $usergroups[$group_id])));
                 }
             }
         }
         if (get_option('ocp_show_personal_last_visit') == '1') {
             $row = $GLOBALS['FORUM_DRIVER']->pget_row($username);
             if (get_forum_type() == 'ocf') {
                 $last_visit = intval(ocp_admirecookie('last_visit', strval($GLOBALS['FORUM_DRIVER']->pnamelast_visit($row))));
             } else {
                 $last_visit = $GLOBALS['FORUM_DRIVER']->pnamelast_visit($row);
             }
             $_last_visit = get_timezoned_date($last_visit, false);
             $content->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINE', array('_GUID' => 'sas41eddsdsdsdsdsa2618fd7fff', 'KEY' => do_lang_tempcode('LAST_HERE'), 'RAW_KEY' => strval($last_visit), 'VALUE' => $_last_visit)));
         }
         $avatar_url = '';
         if (!has_no_forum()) {
             if (get_option('ocp_show_avatar') === '1') {
                 $avatar_url = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url($member);
             }
         }
         // Subscription links
         if (get_forum_type() == 'ocf' && addon_installed('ecommerce') && get_option('ocp_show_personal_sub_links') == '1' && !has_zone_access(get_member(), 'adminzone') && has_actual_page_access(get_member(), 'purchase')) {
             $usergroup_subs = $GLOBALS['FORUM_DB']->query_select('f_usergroup_subs', array('id', 's_title', 's_group_id', 's_cost'), array('s_enabled' => 1));
             $in_one = false;
             $members_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($member);
             foreach ($usergroup_subs as $i => $sub) {
                 $usergroup_subs[$i]['s_cost'] = floatval($sub['s_cost']);
                 if (in_array($sub['s_group_id'], $members_groups)) {
                     $in_one = true;
                     break;
                 }
             }
             if (!$in_one) {
                 global $M_SORT_KEY;
                 $M_SORT_KEY = 's_cost';
                 usort($usergroup_subs, 'multi_sort');
                 foreach ($usergroup_subs as $sub) {
                     $url = build_url(array('page' => 'purchase', 'type' => 'message', 'product' => 'USERGROUP' . strval($sub['id'])), get_module_zone('purchase'));
                     $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINK', array('NAME' => do_lang_tempcode('UPGRADE_TO', escape_html(get_translated_text($sub['s_title']))), 'URL' => $url)));
                 }
             }
         }
         // Admin Zone link
         if (get_option('ocp_show_personal_adminzone_link') == '1' && has_zone_access(get_member(), 'adminzone')) {
             $url = build_url(array('page' => ''), 'adminzone');
             $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINK', array('_GUID' => 'ae243058f780f9528016f7854763a5fa', 'ACCESSKEY' => 'I', 'NAME' => do_lang_tempcode('ADMIN_ZONE'), 'URL' => $url)));
         }
         // Conceded mode link
         if ($GLOBALS['SESSION_CONFIRMED'] == 1 && get_option('ocp_show_conceded_mode_link') == '1') {
             $url = build_url(array('page' => 'login', 'type' => 'concede', 'redirect' => get_page_name() == 'login' ? NULL : SELF_REDIRECT), get_module_zone('login'));
             $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINK_2', array('_GUID' => '81fa81cfd3130e42996bf72b0e03d8aa', 'POST' => true, 'NAME' => do_lang_tempcode('CONCEDED_MODE'), 'DESCRIPTION' => do_lang_tempcode('DESCRIPTION_CONCEDED_MODE'), 'URL' => $url)));
         }
         // Becomes-invisible link
         if (get_option('is_on_invisibility') == '1') {
             $visible = array_key_exists(get_session_id(), $GLOBALS['SESSION_CACHE']) && $GLOBALS['SESSION_CACHE'][get_session_id()]['session_invisible'] == 0;
             $url = build_url(array('page' => 'login', 'type' => 'invisible', 'redirect' => get_page_name() == 'login' ? NULL : SELF_REDIRECT), get_module_zone('login'));
             $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LINK_2', array('NAME' => do_lang_tempcode($visible ? 'INVISIBLE' : 'BE_VISIBLE'), 'DESCRIPTION' => '', 'URL' => $url)));
         }
         // Logout link
         $url = build_url(array('page' => 'login', 'type' => 'logout'), get_module_zone('login'));
         if (!is_httpauth_login()) {
             $links->attach(do_template('BLOCK_SIDE_PERSONAL_STATS_LOGOUT', array('_GUID' => 'd1caacba272a7ee3bf5b2a758e4e54ee', 'NAME' => do_lang_tempcode('LOGOUT'), 'URL' => $url)));
         }
         return do_template('BLOCK_SIDE_PERSONAL_STATS', array('_GUID' => '99f9bc3387102daaeeedf99843b0502e', 'AVATAR_URL' => $avatar_url, 'LINKS' => $links, 'HAS_SU' => $has_su, 'CONTENT' => $content, 'USERNAME' => $username, 'STAFF_ACTIONS' => $staff_actions));
     } else {
         $title = do_lang_tempcode('NOT_LOGGED_IN');
         if (get_page_name() != 'join' && get_page_name() != 'login') {
             if (count($_POST) > 0) {
                 $_this_url = build_url(array('page' => ''), '', array('keep_session' => 1, 'redirect' => 1));
             } else {
                 $_this_url = build_url(array('page' => '_SELF'), '_SELF', array('keep_session' => 1, 'redirect' => 1), true);
             }
         } else {
             $_this_url = build_url(array('page' => ''), '', array('keep_session' => 1, 'redirect' => 1));
         }
         $this_url = $_this_url->evaluate();
         $login_url = build_url(array('page' => 'login', 'type' => 'login', 'redirect' => $this_url), get_module_zone('login'));
         $full_link = build_url(array('page' => 'login', 'type' => 'misc', 'redirect' => $this_url), get_module_zone('login'));
         $join_url = get_forum_type() != 'none' ? $GLOBALS['FORUM_DRIVER']->join_url() : '';
         return do_template('BLOCK_SIDE_PERSONAL_STATS_NO', array('_GUID' => '32aade68b98dfd191f0f84c6648f7dde', 'TITLE' => $title, 'FULL_LINK' => $full_link, 'JOIN_LINK' => $join_url, 'LOGIN_URL' => $login_url));
     }
 }
Beispiel #4
0
 /**
  * View the main calendar screen, with certain filter allowances.
  *
  * @return tempcode		The UI
  */
 function view_calendar()
 {
     check_specific_permission('view_calendar');
     $view = get_param('view', 'day');
     $member_id = get_param_integer('member_id', get_member());
     $filter = $this->get_filter();
     $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=calendar&filter=' . implode(',', $this->get_and_filter());
     if ($member_id != get_member()) {
         enforce_personal_access($member_id);
     }
     $back_url = NULL;
     switch ($view) {
         case 'day':
             // Like a diary
             $id = get_param('id', date('Y-m-d', utctime_to_usertime()));
             if (strpos($id, '-') === false) {
                 $id = date('Y-m-d', utctime_to_usertime());
             }
             // The id was actually a filter, will need to use default date/time
             $self_encompassing = $id == date('Y-m-d', utctime_to_usertime());
             $date = $id;
             $explode = explode('-', $id);
             if (count($explode) != 3) {
                 warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
             }
             $main = $this->view_calendar_view_day($id, $date, $explode, $member_id, $filter);
             $timestamp = mktime(0, 0, 0, intval($explode[1]), intval($explode[2]), intval($explode[0]));
             $back = get_week_number_for(utctime_to_usertime($timestamp));
             $back_view = 'week';
             $previous_timestamp = mktime(0, 0, 0, intval($explode[1]), intval($explode[2]), intval($explode[0])) - 60 * 60 * 24;
             $previous = date('Y-m-d', $previous_timestamp);
             $next_timestamp = mktime(0, 0, 0, intval($explode[1]), intval($explode[2]), intval($explode[0])) + 60 * 60 * 24;
             $next = date('Y-m-d', $next_timestamp);
             $title = get_page_title('CALENDAR_SPECIFIC', true, array(escape_html(locale_filter(date(do_lang('calendar_date_verbose'), $timestamp)))));
             break;
         case 'week':
             // Like a compressed diary
             $id = get_param('id', get_week_number_for(utctime_to_usertime()));
             $self_encompassing = $id == get_week_number_for(utctime_to_usertime());
             $explode = explode('-', $id);
             if (count($explode) != 2) {
                 warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
             }
             list($start_month, $start_day, $start_year) = date_from_week_of_year(intval($explode[0]), intval($explode[1]));
             $date = strval($start_year) . '-' . strval($start_month) . '-01';
             $main = $this->view_calendar_view_week($id, $date, $explode, $member_id, $filter);
             $timestamp = mktime(0, 0, 0, $start_month, $start_day, $start_year);
             $back = $explode[0] . '-' . strval($start_month);
             $back_view = 'month';
             $previous_timestamp = mktime(0, 0, 0, $start_month, $start_day, $start_year) - 60 * 60 * 24 * 7;
             $previous = get_week_number_for($previous_timestamp);
             $next_timestamp = mktime(0, 0, 0, $start_month, $start_day, $start_year) + 60 * 60 * 24 * 7;
             $next = get_week_number_for($next_timestamp);
             $title = get_page_title('CALENDAR_SPECIFIC_WEEK', true, array(escape_html($explode[0]), escape_html($explode[1]), escape_html(locale_filter(date('M', $timestamp)))));
             break;
         case 'month':
             // Like a main calendar page
             $id = get_param('id', date('Y-m', utctime_to_usertime()));
             $self_encompassing = $id == date('Y-m', utctime_to_usertime());
             $date = $id . '-01';
             $explode = explode('-', $id);
             if (count($explode) != 2) {
                 warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
             }
             $main = $this->view_calendar_view_month($id, $date, $explode, $member_id, $filter);
             $timestamp = mktime(0, 0, 0, intval($explode[1]), 1, intval($explode[0]));
             $back = $explode[0];
             $back_view = 'year';
             $previous_month = intval($explode[1]) - 1;
             $previous_year = intval($explode[0]);
             if ($previous_month == 0) {
                 $previous_month = 12;
                 $previous_year = $previous_year - 1;
             }
             $next_month = intval($explode[1]) + 1;
             $next_year = intval($explode[0]);
             if ($next_month == 13) {
                 $next_month = 1;
                 $next_year = $next_year + 1;
             }
             $previous_timestamp = mktime(0, 0, 0, $previous_month, 1, $previous_year);
             $previous = date('Y-m', $previous_timestamp);
             $next_timestamp = mktime(0, 0, 0, $next_month, 1, $next_year);
             $next = date('Y-m', $next_timestamp);
             $title = get_page_title('CALENDAR_SPECIFIC', true, array(escape_html(locale_filter(my_strftime(do_lang('calendar_month_in_year_verbose'), $timestamp)))));
             break;
         case 'year':
             // Like front of a calendar
             $id = get_param('id', date('Y'));
             $self_encompassing = $id == date('Y');
             $date = $id . '-01-01';
             $explode = explode('-', $id);
             if (count($explode) != 1) {
                 warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
             }
             $main = $this->view_calendar_view_year($id, $date, $explode, $member_id, $filter);
             $timestamp = mktime(0, 0, 0, 1, 1, intval($id));
             $back_url = $GLOBALS['FORUM_DRIVER']->member_profile_url($member_id);
             $previous_timestamp = mktime(0, 0, 0, 1, 1, intval($explode[0]) - 1);
             $previous = date('Y', $previous_timestamp);
             $next_timestamp = mktime(0, 0, 0, 1, 1, intval($explode[0]) + 1);
             $next = date('Y', $next_timestamp);
             $title = get_page_title('CALENDAR_SPECIFIC', true, array(escape_html($id)));
             break;
         default:
             warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
     }
     // Nofollow stuff
     $previous_no_follow = $previous_timestamp < filectime(get_file_base() . '/info.php');
     $next_no_follow = $next_timestamp > time();
     $map = array_merge($filter, array('page' => '_SELF', 'view' => $view, 'id' => $previous));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $previous_url = build_url($map, '_SELF');
     $map = array_merge($filter, array('page' => '_SELF', 'view' => $view, 'id' => $next));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $next_url = build_url($map, '_SELF');
     if (is_null($back_url)) {
         $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => $back_view, 'id' => $back));
         if (get_param_integer('member_id', get_member()) != get_member()) {
             $map['member_id'] = get_param_integer('member_id');
         }
         $back_url = build_url($map, '_SELF');
     }
     $interests_url = build_url(array('page' => '_SELF', 'type' => 'interests', 'view' => $view, 'id' => $id), '_SELF');
     $event_types_1 = new ocp_tempcode();
     $types = $GLOBALS['SITE_DB']->query_select('calendar_types', array('id', 't_title'));
     foreach ($types as $type) {
         if ($type['id'] == db_get_first_id()) {
             continue;
         }
         if (!has_category_access(get_member(), 'calendar', strval($type['id']))) {
             continue;
         }
         if (is_guest()) {
             $interested = '';
         } else {
             $test = $GLOBALS['SITE_DB']->query_value_null_ok('calendar_interests', 'i_member_id', array('i_member_id' => get_member(), 't_type' => $type['id']));
             $interested = !is_null($test) ? 'not_interested' : 'interested';
         }
         $event_types_1->attach(do_template('CALENDAR_EVENT_TYPE', array('_GUID' => '104b723d5211f400267345f616c4a677', 'S' => 'I', 'INTERESTED' => $interested, 'TYPE' => get_translated_text($type['t_title']), 'TYPE_ID' => strval($type['id']))));
     }
     $filter_url = build_url(array('page' => '_SELF', 'type' => 'misc', 'view' => $view, 'id' => $id), '_SELF', NULL, false, true);
     $event_types_2 = new ocp_tempcode();
     foreach ($types as $type) {
         if ($type['id'] == db_get_first_id()) {
             continue;
         }
         if (!has_category_access(get_member(), 'calendar', strval($type['id']))) {
             continue;
         }
         $interested = count($filter) == 0 || $filter['int_' . strval($type['id'])] == 1 ? 'not_interested' : 'interested';
         $event_types_2->attach(do_template('CALENDAR_EVENT_TYPE', array('_GUID' => '7511d60148835b7f4fea68a246af424e', 'S' => 'F', 'INTERESTED' => $interested, 'TYPE' => get_translated_text($type['t_title']), 'TYPE_ID' => strval($type['id']))));
     }
     if (has_actual_page_access(NULL, 'cms_calendar', NULL, NULL) && has_submit_permission('low', get_member(), get_ip_address(), 'cms_calendar')) {
         $and_filter = $this->get_and_filter();
         $add_url = build_url(array('page' => 'cms_calendar', 'type' => 'ad', 'date' => $self_encompassing ? NULL : $date, 'e_type' => count($and_filter) == 1 ? $and_filter[0] : NULL), get_module_zone('cms_calendar'));
     } else {
         $add_url = new ocp_tempcode();
     }
     // Allow jumping between views
     if ($self_encompassing) {
         $timestamp = time();
     }
     $day = date('Y-m-d', $timestamp);
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'day', 'id' => $day));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $day_url = $view == 'day' ? new ocp_tempcode() : build_url($map, '_SELF');
     $week = get_week_number_for($timestamp);
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'week', 'id' => $week));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $week_url = $view == 'week' ? new ocp_tempcode() : build_url($map, '_SELF');
     $month = date('Y-m', $timestamp);
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'month', 'id' => $month));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $month_url = $view == 'month' ? new ocp_tempcode() : build_url($map, '_SELF');
     $year = date('Y', $timestamp);
     $map = array_merge($filter, array('page' => '_SELF', 'type' => 'misc', 'view' => 'year', 'id' => $year));
     if (get_param_integer('member_id', get_member()) != get_member()) {
         $map['member_id'] = get_param_integer('member_id');
     }
     $year_url = $view == 'year' ? new ocp_tempcode() : build_url($map, '_SELF');
     // RSS
     $fields = new ocp_tempcode();
     require_code('form_templates');
     for ($i = 0; $i < 10; $i++) {
         $fields->attach(form_input_line(do_lang_tempcode('FEED', integer_format($i + 1)), '', 'feed_' . strval($i), ocp_admirecookie('feed_' . strval($i)), false));
     }
     $rss_form = do_template('FORM', array('HIDDEN' => '', 'TEXT' => do_lang_tempcode('DESCRIPTION_FEEDS_TO_OVERLAY'), 'URL' => get_self_url(), 'FIELDS' => $fields, 'SUBMIT_NAME' => do_lang_tempcode('PROCEED')));
     return do_template('CALENDAR_MAIN_SCREEN', array('_GUID' => '147a58dbe05366ac37698a8cdd501d12', 'RSS_FORM' => $rss_form, 'PREVIOUS_NO_FOLLOW' => $previous_no_follow, 'NEXT_NO_FOLLOW' => $next_no_follow, 'DAY_URL' => $day_url, 'WEEK_URL' => $week_url, 'MONTH_URL' => $month_url, 'YEAR_URL' => $year_url, 'PREVIOUS_URL' => $previous_url, 'NEXT_URL' => $next_url, 'ADD_URL' => $add_url, 'TITLE' => $title, 'BACK_URL' => $back_url, 'MAIN' => $main, 'FILTER_URL' => $filter_url, 'EVENT_TYPES_1' => $event_types_1, 'INTERESTS_URL' => $interests_url, 'EVENT_TYPES_2' => $event_types_2));
 }
Beispiel #5
0
/**
 * Get a user's timezone.
 *
 * @param  ?MEMBER		Member for which the date is being rendered (NULL: current user)
 * @return string			Users timezone in "boring" format.
 */
function get_users_timezone($member = NULL)
{
    if ($member === NULL) {
        $member = get_member();
    }
    global $TIMEZONE_MEMBER_CACHE;
    if (isset($TIMEZONE_MEMBER_CACHE[$member])) {
        return $TIMEZONE_MEMBER_CACHE[$member];
    }
    $timezone = get_param('keep_timezone', NULL);
    if (!is_null($timezone)) {
        $TIMEZONE_MEMBER_CACHE[$member] = $timezone;
        return $timezone;
    }
    // Get user timezone
    if (get_forum_type() == 'ocf' && !is_guest($member)) {
        $_timezone_member = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member, 'm_timezone_offset');
        if (is_integer($_timezone_member)) {
            // Database upgrade needed
            $GLOBALS['FORUM_DB']->alter_table_field('f_members', 'm_timezone_offset', 'SHORT_TEXT');
        }
        if (is_integer($_timezone_member) || is_numeric($_timezone_member)) {
            $_timezone_old_offset = get_value('timezone_old_offset');
            if (is_null($_timezone_old_offset)) {
                $_timezone_old_offset = '0';
            }
            @ini_restore('date.timezone');
            if (function_exists('date_default_timezone_set')) {
                @date_default_timezone_set(ini_get('date.timezone'));
            }
            $timezone_member = convert_timezone_offset_to_formal_timezone(floatval($_timezone_member) + floatval($_timezone_old_offset) + floatval(floatval(date('O')) / 100.0));
        } else {
            $timezone_member = $_timezone_member;
        }
    } elseif (function_exists('ocp_admirecookie') && get_option('is_on_timezone_detection') == '1' && get_option('allow_international') == '1') {
        $client_time = ocp_admirecookie('client_time');
        $client_time_ref = ocp_admirecookie('client_time_ref');
        if (!is_null($client_time) && !is_null($client_time_ref)) {
            $client_time = preg_replace('# ([A-Z]{3})([\\+\\-]\\d+)?( \\([\\w\\s]+\\))?( \\d{4})?$#', '${4}', $client_time);
            $timezone_dif = (floatval(strtotime($client_time)) - floatval($client_time_ref)) / 60.0 / 60.0;
            $timezone_numeric = round($timezone_dif, 1);
            if (abs($timezone_numeric) > 100.0) {
                $timezone_numeric = 0.0;
            }
            $timezone_member = convert_timezone_offset_to_formal_timezone($timezone_numeric);
        } else {
            $timezone_member = get_site_timezone();
        }
    } else {
        $timezone_member = get_site_timezone();
    }
    $TIMEZONE_MEMBER_CACHE[$member] = $timezone_member;
    return $timezone_member;
}
Beispiel #6
0
/**
 * Detect calendar matches in a time period, in user-time.
 *
 * @param  MEMBER			The member to detect conflicts for
 * @param  boolean		Whether to restrict only to viewable events for the current member
 * @param  ?TIME			The timestamp that found times must exceed. In user-time (NULL: use find_periods_recurrence default)
 * @param  ?TIME			The timestamp that found times must not exceed. In user-time (NULL: use find_periods_recurrence default)
 * @param  ?array			The type filter (NULL: none)
 * @param  boolean		Whether to include RSS events in the results
 * @return array			A list of events happening, with time details
 */
function calendar_matches($member_id, $restrict, $period_start, $period_end, $filter = NULL, $do_rss = true)
{
    if (is_null($period_start)) {
        $period_start = utctime_to_usertime(time());
    }
    if (is_null($period_end)) {
        $period_end = utctime_to_usertime(time() + 60 * 60 * 24 * 360 * 20);
    }
    $matches = array();
    $where = '';
    if ($restrict) {
        if ($where != '') {
            $where .= ' AND ';
        }
        $where .= '(e_submitter=' . strval((int) $member_id) . ' OR e_is_public=1)';
    }
    if (!is_null($filter)) {
        foreach ($filter as $a => $b) {
            if ($b == 0) {
                if ($where != '') {
                    $where .= ' AND ';
                }
                $where .= 'e_type<>' . strval((int) substr($a, 4));
            }
        }
    }
    if ($where != '') {
        $where .= ' AND ';
    }
    $where .= '(validated=1 OR e_is_public=0)';
    if (addon_installed('syndication_blocks')) {
        // Determine what feeds to overlay
        $feed_urls_todo = array();
        for ($i = 0; $i < 10; $i++) {
            $feed_url = post_param('feed_' . strval($i), ocp_admirecookie('feed_' . strval($i), ''));
            require_code('users_active_actions');
            ocp_setcookie('feed_' . strval($i), $feed_url);
            if ($feed_url != '' && preg_match('#^[\\w\\d\\-\\_]*$#', $feed_url) == 0) {
                $feed_urls_todo[$feed_url] = NULL;
            }
        }
        $_event_types = list_to_map('id', $GLOBALS['SITE_DB']->query_select('calendar_types', array('id', 't_title', 't_logo', 't_external_feed')));
        foreach ($_event_types as $j => $_event_type) {
            if ($_event_type['t_external_feed'] != '' && (is_null($filter) || !array_key_exists($_event_type['id'], $filter) || $filter[$_event_type['id']] == 1) && has_category_access(get_member(), 'calendar', strval($_event_type['id']))) {
                $feed_urls_todo[$_event_type['t_external_feed']] = $_event_type['id'];
            }
            $_event_types[$j]['text_original'] = get_translated_text($_event_type['t_title']);
        }
        $event_types = collapse_2d_complexity('text_original', 't_logo', $_event_types);
        // Overlay it
        foreach ($feed_urls_todo as $feed_url => $event_type) {
            $temp_file_path = ocp_tempnam('feed');
            require_code('files');
            $write_to_file = fopen($temp_file_path, 'wb');
            http_download_file($feed_url, 1024 * 512, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $write_to_file);
            if ($GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'] == 'text/calendar' || $GLOBALS['HTTP_DOWNLOAD_MIME_TYPE'] == 'application/octet-stream') {
                $data = file_get_contents($temp_file_path);
                require_code('calendar_ical');
                $whole = end(explode('BEGIN:VCALENDAR', $data));
                $events = explode('BEGIN:VEVENT', $whole);
                $calendar_nodes = array();
                foreach ($events as $key => $items) {
                    $items = preg_replace('#(.+)\\n +(.*)\\n#', '${1}${2}' . "\n", $items);
                    // Merge split lines
                    $nodes = explode("\n", $items);
                    foreach ($nodes as $_child) {
                        if (strpos($_child, ':') === false) {
                            continue;
                        }
                        $child = array('', '');
                        $in_quotes = false;
                        $j = 0;
                        for ($i = 0; $i < strlen($_child); $i++) {
                            $char = $_child[$i];
                            if ($char == '"') {
                                $in_quotes = !$in_quotes;
                            }
                            if ($j != 1 && !$in_quotes && $char == ':') {
                                $j++;
                            } else {
                                $child[$j] .= $char;
                            }
                        }
                        $matches2 = array();
                        if (preg_match('#;TZID=(.*)#', $child[0], $matches2)) {
                            $calendar_nodes[$key]['TZID'] = $matches2[1];
                        }
                        $child[0] = preg_replace('#;.*#', '', $child[0]);
                        if (array_key_exists("1", $child) && $child[0] !== 'PRODID' && $child[0] !== 'VERSION' && $child[0] !== 'END') {
                            $calendar_nodes[$key][$child[0]] = str_replace(array('\\n', '\\,'), array("\n", ','), trim($child[1]));
                        }
                    }
                    if ($key != 0) {
                        list($full_url, $type_id, $type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $timezone, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes) = get_event_data_ical($calendar_nodes[$key]);
                        $is_public = 1;
                        $event = array('e_recurrence' => $recurrence, 'e_content' => $content, 'e_title' => $title, 'e_id' => $feed_url, 'e_priority' => $priority, 't_logo' => 'calendar/rss', 'e_recurrences' => $recurrences, 'e_seg_recurrences' => $seg_recurrences, 'e_is_public' => $is_public, 'e_start_year' => $start_year, 'e_start_month' => $start_month, 'e_start_day' => $start_day, 'e_start_hour' => $start_hour, 'e_start_minute' => $start_minute, 'e_end_year' => $end_year, 'e_end_month' => $end_month, 'e_end_day' => $end_day, 'e_end_hour' => $end_hour, 'e_end_minute' => $end_minute, 'e_timezone' => $timezone);
                        if (!is_null($event_type)) {
                            $event['t_logo'] = $_event_types[$event_type]['t_logo'];
                        }
                        if (!is_null($type)) {
                            $event['t_title'] = $type;
                            if (array_key_exists($type, $event_types)) {
                                $event['t_logo'] = $event_types[$type];
                            }
                        }
                        $their_times = find_periods_recurrence($timezone, 0, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year, $end_month, $end_day, $end_hour, $end_minute, $recurrence, $recurrences, $period_start, $period_end);
                        // Now search every combination to see if we can get a hit
                        foreach ($their_times as $their) {
                            $matches[] = array($full_url, $event, $their[0], $their[1], $their[2], $their[3], $their[4], $their[5]);
                        }
                    }
                }
            } else {
                require_code('rss');
                $rss = new rss($temp_file_path, true);
                $content = new ocp_tempcode();
                foreach ($rss->gleamed_items as $item) {
                    if (array_key_exists('guid', $item)) {
                        $full_url = $item['guid'];
                    } elseif (array_key_exists('comment_url', $item)) {
                        $full_url = $item['comment_url'];
                    } elseif (array_key_exists('full_url', $item)) {
                        $full_url = $item['full_url'];
                    } else {
                        $full_url = '';
                    }
                    if (array_key_exists('title', $item) && array_key_exists('clean_add_date', $item) && $full_url != '') {
                        $event = array('e_recurrence' => 'none', 'e_content' => array_key_exists('news', $item) ? $item['news'] : '', 'e_title' => $item['title'], 'e_id' => $full_url, 'e_priority' => 'na', 't_logo' => 'calendar/rss', 'e_recurrences' => 1, 'e_seg_recurrences' => '', 'e_is_public' => 1, 'e_timezone' => get_users_timezone());
                        if (!is_null($event_type)) {
                            $event['t_logo'] = $_event_types[$event_type]['t_logo'];
                        }
                        if (array_key_exists('category', $item)) {
                            $event['t_title'] = $item['category'];
                            if (array_key_exists($item['category'], $event_types)) {
                                $event['t_logo'] = $event_types[$item['category']];
                            }
                        }
                        $from = utctime_to_usertime($item['clean_add_date']);
                        if ($from >= $period_start && $from < $period_end) {
                            $event += array('e_start_year' => date('Y', $from), 'e_start_month' => date('m', $from), 'e_start_day' => date('D', $from), 'e_start_hour' => date('H', $from), 'e_start_minute' => date('i', $from), 'e_end_year' => NULL, 'e_end_month' => NULL, 'e_end_day' => NULL, 'e_end_hour' => NULL, 'e_end_minute' => NULL);
                            $matches[] = array($full_url, $event, $from, NULL, $from, NULL, $from, NULL);
                        }
                    }
                }
            }
            @unlink($temp_file_path);
        }
    }
    if ($where != '') {
        $where .= ' AND ';
    }
    $where .= '(((e_start_month>=' . strval(intval(date('m', $period_start)) - 1) . ' AND e_start_year=' . date('Y', $period_start) . ' OR e_start_year>' . date('Y', $period_start) . ') AND (e_start_month<=' . strval(intval(date('m', $period_end)) + 1) . ' AND e_start_year=' . date('Y', $period_end) . ' OR e_start_year<' . date('Y', $period_end) . ')) OR ' . db_string_not_equal_to('e_recurrence', 'none') . ')';
    $where = ' WHERE ' . $where;
    $event_count = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_types t ON e.e_type=t.id' . $where);
    if ($event_count > 2000) {
        attach_message(do_lang_tempcode('TOO_MANY_TO_CHOOSE_FROM'), 'inform');
        return array();
    }
    $events = $GLOBALS['SITE_DB']->query('SELECT *,e.id AS e_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_events e LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'calendar_types t ON e.e_type=t.id' . $where);
    foreach ($events as $event) {
        if (!has_category_access(get_member(), 'calendar', strval($event['e_type']))) {
            continue;
        }
        $their_times = find_periods_recurrence($event['e_timezone'], $event['e_do_timezone_conv'], $event['e_start_year'], $event['e_start_month'], $event['e_start_day'], $event['e_start_hour'], $event['e_start_minute'], $event['e_end_year'], $event['e_end_month'], $event['e_end_day'], $event['e_end_hour'], $event['e_end_minute'], $event['e_recurrence'], $event['e_recurrences'], $period_start, $period_end);
        // Now search every combination to see if we can get a hit
        foreach ($their_times as $their) {
            $matches[] = array($event['e_id'], $event, $their[0], $their[1], $their[2], $their[3], $their[4], $their[5]);
        }
    }
    global $M_SORT_KEY;
    $M_SORT_KEY = 2;
    usort($matches, 'multi_sort');
    return $matches;
}
Beispiel #7
0
/**
 * Remap the specified language id, and return the id again - the id isn't changed.
 *
 * @param  integer		The language entries id
 * @param  string			The text to remap to
 * @param  ?object		The database connection to use (NULL: standard site connection)
 * @param  boolean		Whether it is to be parsed as comcode
 * @param  ?string		The special identifier for this lang code on the page it will be displayed on; this is used to provide an explicit binding between languaged elements and greater templated areas (NULL: none)
 * @param  ?MEMBER		The member performing the change (NULL: current member)
 * @param  boolean		Whether to generate Comcode as arbitrary admin
 * @param  boolean		Whether to backup the language string before changing it
 * @return integer		The language entries id
 */
function _lang_remap($id, $text, $connection = NULL, $comcode = false, $pass_id = NULL, $source_member = NULL, $as_admin = false, $backup_string = false)
{
    if ($id == 0) {
        return insert_lang($text, 3, $connection, $comcode, NULL, NULL, $as_admin, $pass_id);
    }
    if ($text === STRING_MAGIC_NULL) {
        return $id;
    }
    if (is_null($connection)) {
        $connection = $GLOBALS['SITE_DB'];
    }
    $lang = user_lang();
    $test = $connection->query_value_null_ok('translate', 'text_original', array('id' => $id, 'language' => $lang));
    // Mark old as out-of-date
    if ($test !== $text) {
        $GLOBALS['SITE_DB']->query_update('translate', array('broken' => 1), array('id' => $id));
    }
    if ($backup_string) {
        $current = $connection->query_select('translate', array('*'), array('id' => $id, 'language' => $lang), '', 1);
        if (!array_key_exists(0, $current)) {
            $current = $connection->query_select('translate', array('*'), array('id' => $id), '', 1);
        }
        $connection->query_insert('translate_history', array('lang_id' => $id, 'language' => $current[0]['language'], 'text_original' => $current[0]['text_original'], 'broken' => $current[0]['broken'], 'action_member' => get_member(), 'action_time' => time()));
    }
    if ($comcode) {
        $_text2 = comcode_to_tempcode($text, $source_member, $as_admin, 60, $pass_id, $connection);
        $connection->text_lookup_cache[$id] = $_text2;
        $text2 = $_text2->to_assembly();
    } else {
        $text2 = '';
    }
    if (is_null($source_member)) {
        $source_member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id();
    }
    // This updates the Comcode reference to match the current user, which may not be the owner of the content this is for. This is for a reason - we need to parse with the security token of the current user, not the original content submitter.
    $remap = array('broken' => 0, 'text_original' => $text, 'text_parsed' => $text2);
    if (function_exists('ocp_admirecookie') && (ocp_admirecookie('use_wysiwyg', '1') == '0' && get_value('edit_with_my_comcode_perms') === '1') || !has_specific_permission($source_member, 'allow_html') || !has_specific_permission($member, 'comcode_dangerous') || !has_specific_permission($source_member, 'use_very_dangerous_comcode')) {
        $remap['source_user'] = $source_member;
    }
    if (!is_null($test)) {
        $connection->query_update('translate', $remap, array('id' => $id, 'language' => $lang), '', 1);
    } else {
        $connection->query_update('translate', $remap, array('id' => $id), '', 1);
    }
    $connection->text_lookup_original_cache[$id] = $text;
    // $id doesn't change, but lets allow some functional embedding
    return $id;
}