Exemplo n.º 1
0
/**
 * Check a POST inputted date for validity, and get the Unix timestamp for the inputted date.
 *
 * @param  ID_TEXT		The stub of the parameter name (stub_year, stub_month, stub_day, stub_hour, stub_minute)
 * @param  boolean		Whether to allow over get parameters also
 * @return ?TIME			The timestamp of the date (NULL: no input date was chosen)
 */
function _get_input_date($stub, $get_also = false)
{
    $timezone = post_param('timezone', get_users_timezone());
    if ($get_also) {
        //		if (either_param_integer($stub,0)==0) return NULL; // NULL was chosen		Doesn't work like this now
        $year = either_param_integer($stub . '_year', NULL);
        if (is_null($year)) {
            return NULL;
        }
        $month = either_param_integer($stub . '_month', NULL);
        if (is_null($month)) {
            return NULL;
        }
        $day = either_param_integer($stub . '_day', NULL);
        if (is_null($day)) {
            return NULL;
        }
        $hour = either_param_integer($stub . '_hour', NULL);
        $minute = either_param_integer($stub . '_minute', NULL);
    } else {
        //		if (post_param_integer($stub,0)==0) return NULL; // NULL was chosen		Doesn't work like this now
        $year = post_param_integer($stub . '_year', NULL);
        if (is_null($year)) {
            return NULL;
        }
        $month = post_param_integer($stub . '_month', NULL);
        if (is_null($month)) {
            return NULL;
        }
        $day = post_param_integer($stub . '_day', NULL);
        if (is_null($day)) {
            return NULL;
        }
        $hour = post_param_integer($stub . '_hour', NULL);
        $minute = post_param_integer($stub . '_minute', NULL);
    }
    if (!checkdate($month, $day, $year)) {
        warn_exit(do_lang_tempcode('INVALID_DATE_GIVEN'));
    }
    if (is_null($hour)) {
        if (strpos($stub, 'end') !== false) {
            $hour = 23;
            $minute = 59;
        } else {
            $hour = 0;
            $minute = 0;
        }
    }
    $time = mktime($hour, $minute, 0, $month, $day, $year);
    if ($year >= 1970 || @strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) == '1963') {
        $amount_forward = tz_time($time, $timezone) - $time;
        $time = $time - $amount_forward;
    }
    return $time;
}
Exemplo n.º 2
0
/**
 * Get a list of timezones.
 *
 * @param  ?string		Current timezone to select (NULL: server default)
 * @return tempcode		List of timezones
 */
function nice_get_timezone_list($timezone = NULL)
{
    if (is_null($timezone)) {
        $timezone = get_site_timezone();
    }
    $timezone_list = new ocp_tempcode();
    foreach (get_timezone_list() as $_timezone => $timezone_nice) {
        $timezone_list->attach(do_template('OCF_AUTO_TIME_ZONE_ENTRY', array('HOUR' => date('H', tz_time(time(), $_timezone)), 'DW' => date('w', tz_time(time(), $_timezone)), 'NAME' => $_timezone, 'SELECTED' => $timezone == $_timezone, 'CLASS' => '', 'TEXT' => $timezone_nice)));
    }
    return $timezone_list;
}
Exemplo n.º 3
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);
 }
Exemplo n.º 4
0
function handle_facebook_connection_login($current_logged_in_member)
{
    if (!class_exists('ocp_tempcode')) {
        return NULL;
    }
    if (is_guest($current_logged_in_member)) {
        $current_logged_in_member = NULL;
        // We are not a normal cookie login so ocPortal has loaded up a Guest session already in the expectation of keeping it. Unsetting it will force a rebind (existing session may be reused though)
        require_code('users_inactive_occasionals');
        set_session_id(-1);
    }
    // If already session-logged-in onto a Facebook account, don't bother doing anything
    if (!is_null($current_logged_in_member) && $GLOBALS['FORUM_DRIVER']->get_member_row_field($current_logged_in_member, 'm_password_compat_scheme') == 'facebook') {
        return $current_logged_in_member;
    }
    // Who is this user, from Facebook's point of view?
    global $FACEBOOK_CONNECT;
    $facebook_uid = $FACEBOOK_CONNECT->getUser();
    if (is_null($facebook_uid)) {
        return $current_logged_in_member;
    }
    try {
        $details = $FACEBOOK_CONNECT->api('/me');
    } catch (Exception $e) {
        return $current_logged_in_member;
    }
    $details2 = $FACEBOOK_CONNECT->api('/me', array('fields' => 'picture', 'type' => 'normal'));
    if (!is_array($details) || !is_array($details2)) {
        return $current_logged_in_member;
    }
    $details = array_merge($details, $details2);
    if (!isset($details['name'])) {
        return $current_logged_in_member;
    }
    $username = $details['name'];
    $photo_url = array_key_exists('picture', $details) ? $details['picture'] : '';
    if (is_array($photo_url)) {
        $photo_url = $photo_url['data']['url'];
    }
    if ($photo_url != '') {
        $photo_url = 'http://graph.facebook.com/' . strval($facebook_uid) . '/picture?type=large';
        // In case URL changes
    }
    $avatar_url = $photo_url == '' ? mixed() : $photo_url;
    $photo_thumb_url = '';
    if ($photo_url != '') {
        $photo_thumb_url = $photo_url;
    }
    $email_address = array_key_exists('email', $details) ? $details['email'] : '';
    $timezone = mixed();
    if (isset($details['timezone'])) {
        require_code('temporal');
        $timezone = convert_timezone_offset_to_formal_timezone($details['timezone']);
    }
    $language = mixed();
    if (isset($details['locale'])) {
        $language = strtoupper($details['locale']);
    }
    if ($language !== NULL) {
        if (!file_exists(get_custom_file_base() . '/lang_custom/' . $language)) {
            $language = preg_replace('#\\_.*$#', '', $language);
            if (!file_exists(get_custom_file_base() . '/lang_custom/' . $language)) {
                $language = '';
            }
        }
    }
    $dob = array_key_exists('birthday', $details) ? $details['birthday'] : '';
    $dob_day = mixed();
    $dob_month = mixed();
    $dob_year = mixed();
    if ($dob != '') {
        $_dob = explode('/', $dob);
        $dob_day = intval($_dob[1]);
        $dob_month = intval($_dob[0]);
        $dob_year = intval($_dob[2]);
    }
    // See if they have logged in before - i.e. have a synched account
    $member_row = $GLOBALS['FORUM_DB']->query_select('f_members', array('*'), array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => $facebook_uid), 'ORDER BY id DESC', 1);
    $member = array_key_exists(0, $member_row) ? $member_row[0]['id'] : NULL;
    if (is_guest($member)) {
        $member = NULL;
    }
    /*if (!is_null($member)) // Useful for debugging
    	{
    		require_code('ocf_members_action2');
    		ocf_delete_member($member);
    		$member=NULL;
    	}*/
    // If logged in before using Facebook, see if they've changed their name or email or timezone on Facebook -- if so, try and update locally to match
    if (!is_null($member)) {
        if (!is_null($current_logged_in_member) && $current_logged_in_member !== NULL && !is_guest($current_logged_in_member) && $current_logged_in_member != $member) {
            return $current_logged_in_member;
        }
        // User has an active login, and the Facebook account is bound to a DIFFERENT login. Take precedence to the other login that is active on top of this
        $last_visit_time = $member[0]['m_last_visit_time'];
        if ($timezone !== NULL) {
            if (tz_time(time(), $timezone) == tz_time(time(), $member[0]['m_timezone_offset'])) {
                $timezone = $member[0]['m_timezone_offset'];
            }
            // If equivalent, don't change
        }
        $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $username));
        if (!is_null($test)) {
            $update_map = array('m_username' => $username, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year);
            if ($email_address != '') {
                $update_map['m_email_address'] = $email_address;
            }
            if ($avatar_url !== NULL && ($test == '' || strpos($test, 'facebook') !== false || strpos($test, 'fbcdn') !== false)) {
                if ($timezone !== NULL) {
                    $update_map['m_timezone_offset'] = $timezone;
                }
                $update_map['m_avatar_url'] = $avatar_url;
                $update_map['m_photo_url'] = $photo_url;
                $update_map['m_photo_thumb_url'] = $photo_thumb_url;
            }
            $GLOBALS['FORUM_DB']->query_update('f_members', $update_map, array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => strval($facebook_uid)), '', 1);
            if ($username != $member[0]['m_username']) {
                // Fix cacheing for usernames
                $to_fix = array('f_forums/f_cache_last_username', 'f_posts/p_poster_name_if_guest', 'f_topics/t_cache_first_username', 'f_topics/t_cache_last_username');
                foreach ($to_fix as $fix) {
                    list($table, $field) = explode('/', $fix);
                    $GLOBALS['FORUM_DB']->query_update($table, array($field => $username), array($field => $member[0]['m_username']));
                }
            }
        }
    }
    // Not logged in before using Facebook, so we need to create an account, or bind to the active ocPortal login if there is one
    $in_a_sane_place = get_page_name() != 'login' && (running_script('index') || running_script('execute_temp'));
    // If we're in some weird script, or the login module UI, it's not a sane place, don't be doing account creation yet
    if (is_null($member) && $in_a_sane_place) {
        // Bind to existing ocPortal login?
        if (!is_null($current_logged_in_member)) {
            /*if (post_param_integer('associated_confirm',0)==0)		Won't work because Facebook is currently done in JS and cookies force this. If user wishes to cancel they must go to http://www.facebook.com/settings?tab=applications and remove the app, then run a lost password reset.
            		{
            			$title=get_page_title('LOGIN_FACEBOOK_HEADER');
            			$message=do_lang_tempcode('LOGGED_IN_SURE_FACEBOOK',escape_html($GLOBALS['FORUM_DRIVER']->get_username($current_logged_in_member)));
            			$middle=do_template('YESNO_SCREEN',array('TITLE'=>$title,'TEXT'=>$message,'HIDDEN'=>form_input_hidden('associated_confirm','1'),'URL'=>get_self_url_easy()));
            			$tpl=globalise($middle,NULL,'',true);
            			$tpl->evaluate_echo();
            			exit();
            		}*/
            $GLOBALS['FORUM_DB']->query_update('f_members', array('m_password_compat_scheme' => 'facebook', 'm_pass_hash_salted' => $facebook_uid), array('id' => $current_logged_in_member), '', 1);
            require_code('site');
            require_lang('facebook');
            attach_message(do_lang_tempcode('FACEBOOK_ACCOUNT_CONNECTED', escape_html(get_site_name()), escape_html($GLOBALS['FORUM_DRIVER']->get_username($current_logged_in_member)), array(escape_html($username))), 'inform');
            return $current_logged_in_member;
        }
        // If we're still here, we have to create a new account...
        // -------------------------------------------------------
        $completion_form_submitted = post_param('email_address', '') != '';
        // If there's a conflicting username, we may need to change it (suffix a number)
        require_code('ocf_members_action2');
        $username = get_username_from_human_name($username);
        // Ask ocP to finish off the profile from the information presented in the POST environment (a standard mechanism in ocPortal, for third party logins of various kinds)
        require_lang('ocf');
        require_code('ocf_members');
        require_code('ocf_groups');
        require_code('ocf_members2');
        require_code('ocf_members_action');
        $_custom_fields = ocf_get_all_custom_fields_match(ocf_get_all_default_groups(true), NULL, NULL, NULL, 1);
        if (!$completion_form_submitted && count($_custom_fields) != 0 && get_value('no_finish_profile') !== '1') {
            $GLOBALS['FACEBOOK_FINISHING_PROFILE'] = true;
            $middle = ocf_member_external_linker_ask($username, 'facebook', $email_address, $dob_day, $dob_month, $dob_year);
            $tpl = globalise($middle, NULL, '', true);
            $tpl->evaluate_echo();
            exit;
        } else {
            $username = post_param('username', $username);
            if (count($_custom_fields) != 0 && get_value('no_finish_profile') !== '1') {
                // Was not auto-generated, so needs to be checked
                ocf_check_name_valid($username, NULL, NULL);
            }
            $member = ocf_member_external_linker($username, $facebook_uid, 'facebook', false, $email_address, $dob_day, $dob_month, $dob_year, $timezone, $language, $avatar_url, $photo_url, $photo_thumb_url);
        }
    }
    if (!is_null($member)) {
        require_code('users_inactive_occasionals');
        create_session($member, 1, isset($_COOKIE[get_member_cookie() . '_invisible']) && $_COOKIE[get_member_cookie() . '_invisible'] == '1');
        // This will mark it as confirmed
    }
    return $member;
}
Exemplo n.º 5
0
/**
 * Convert a user timestamp to a UTC timestamp. This is not a function to use much- you probably want utctime_to_usertime.
 * What complicate understanding of matters is that "user time" is not the timestamp that would exist on a user's PC, as all timestamps are meant to be stored in UTC. "user time" is offsetted to compensate, a virtual construct.
 *
 * @param  ?TIME			Input timestamp (NULL: now)
 * @param  ?MEMBER		Member for which the date is being rendered (NULL: current member)
 * @return TIME			Output timestamp
 */
function usertime_to_utctime($timestamp = NULL, $member = NULL)
{
    if (is_null($timestamp)) {
        $timestamp = time();
    }
    $timezone = get_users_timezone($member);
    $amount_forward = tz_time($timestamp, $timezone) - $timestamp;
    return $timestamp - $amount_forward;
}
/**
 * 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;
}
Exemplo n.º 7
0
/**
 * Put a timestamp into the correct timezone for being reported onto the calendar.
 *
 * @param  TIME			Timestamp (proper UTC timestamp, not in user time)
 * @param  ID_TEXT		The timezone associated with the event (the passed $utc_timestamp should NOT be relative to this timezone, that must be UTC)
 * @param  boolean		Whether the time should be converted to the viewer's own timezone instead
 * @return TIME			Altered timestamp
 */
function cal_utctime_to_usertime($utc_timestamp, $default_timezone, $show_in_users_timezone)
{
    if (!$show_in_users_timezone) {
        return $utc_timestamp;
    }
    return tz_time($utc_timestamp, get_users_timezone());
}
Exemplo n.º 8
0
/**
 * Get the tempcode for a date input.
 *
 * @param  mixed			A human intelligible name for this input field
 * @param  mixed			A description for this input field
 * @param  ID_TEXT		The parameter name stub for this input field (it's actually a composite field, read in by passing this stub to post_param_date)
 * @param  boolean		Whether this is a required field
 * @param  boolean		Whether this field is empty by default
 * @param  boolean		Whether to input time for this field also
 * @param  ?mixed			The default timestamp to use (either TIME or array of time components) (NULL: now)
 * @param  ?integer		The number of years to allow selection from (all into the future, as this field type is not meant for inputting past dates) (NULL: no limit)
 * @param  ?integer		The year to start from (NULL: this year)
 * @param  ?integer		The tab index of the field (NULL: not specified)
 * @param  ?boolean		Whether this is rendered in pink as a required field (NULL: depend on $null_ok)
 * @param  boolean		Whether to input date for this field (if false, will just do time)
 * @param  ?ID_TEXT		Timezone to input in (NULL: current user's timezone)
 * @param  boolean		Convert $default_time to $timezone
 * @return tempcode		The input field
 */
function form_input_date($pretty_name, $description, $stub, $null_ok, $null_default, $do_time, $default_time = NULL, $total_years_to_show = 10, $year_start = NULL, $tabindex = NULL, $required = NULL, $do_date = true, $timezone = NULL, $handle_timezone = true)
{
    if (is_null($required)) {
        $required = !$null_ok;
    }
    $tabindex = get_form_field_tabindex($tabindex);
    require_lang('dates');
    require_javascript('javascript_multi');
    require_javascript('javascript_yahoo');
    require_javascript('javascript_yahoo_events');
    require_javascript('javascript_date_chooser');
    require_css('date_chooser');
    if (is_null($year_start)) {
        $year_start = intval(date('Y'));
    }
    $untuned_year_start = $year_start;
    // The $year_start may go down if our default date requires it, but we need to know what our $total_years_to_show should really be relative to
    $default_minute = mixed();
    $default_hour = mixed();
    $default_month = mixed();
    $default_day = mixed();
    $default_year = mixed();
    if (is_array($default_time) && $default_time[4] < 1970 && @strftime('%Y', @mktime(0, 0, 0, 1, 1, 1963)) != '1963') {
        list($default_minute, $default_hour, $default_month, $default_day, $default_year) = $default_time;
        if (is_null($default_minute)) {
            $default_minute = 0;
        }
        if (is_null($default_hour)) {
            $default_hour = 0;
        }
    } else {
        if (is_array($default_time)) {
            if (is_null($default_time[4])) {
                $default_time = NULL;
            } else {
                list($default_minute, $default_hour, $default_month, $default_day, $default_year) = $default_time;
                $default_time = mktime($default_hour, $default_minute, 0, $default_month, $default_day, $default_year);
            }
        }
        $_default_time = filter_form_field_default($stub, is_null($default_time) ? '' : strval($default_time));
        $default_time = $_default_time == '' ? NULL : intval($_default_time);
        if (!is_null($default_time) && $handle_timezone) {
            if (is_null($timezone)) {
                $timezone = get_users_timezone();
            }
            $default_time = tz_time($default_time, $timezone);
        }
        $default_minute = is_null($default_time) ? NULL : intval(date('i', $default_time));
        $default_hour = is_null($default_time) ? NULL : intval(date('H', $default_time));
        $default_month = is_null($default_time) ? NULL : intval(date('n', $default_time));
        $default_day = is_null($default_time) ? NULL : intval(date('j', $default_time));
        $default_year = is_null($default_time) ? NULL : intval(date('Y', $default_time));
    }
    if (is_integer($default_year) && $default_year < $year_start) {
        $year_start = $default_year;
    }
    ob_start();
    for ($minute = 0; $minute < 60; $minute++) {
        $_minute = strval($minute);
        $temp = form_input_list_entry($_minute, $minute === $default_minute, $minute < 10 ? str_pad($_minute, 2, '0', STR_PAD_LEFT) : $_minute);
        $temp->evaluate_echo();
    }
    $minutes = ob_get_contents();
    ob_end_clean();
    ob_start();
    for ($hour = 0; $hour < 24; $hour++) {
        $text_hour = locale_filter(gmdate(do_lang('time_hour'), intval($hour * 60 * 60)));
        $temp = form_input_list_entry(strval($hour), $hour === $default_hour, $text_hour);
        $temp->evaluate_echo();
    }
    $hours = ob_get_contents();
    ob_end_clean();
    $time = $do_time ? do_template('FORM_SCREEN_INPUT_TIME', array('NULL_OK' => $null_ok, 'DISABLED' => $null_default && has_js(), 'TABINDEX' => strval($tabindex), 'MINUTES' => $minutes, 'HOURS' => $hours, 'STUB' => $stub)) : new ocp_tempcode();
    if (!$do_date) {
        return _form_input($stub, $pretty_name, $description, $time, $required, false, $tabindex, false, true);
    }
    $null = $null_ok ? do_template('FORM_SCREEN_INPUT_DATE_NULL', array('_GUID' => '22859d15f1b295b08036e1d0308d371a', 'TICKED' => !$null_default, 'TABINDEX' => strval($tabindex), 'STUB' => $stub)) : new ocp_tempcode();
    ob_start();
    for ($i = 1; $i <= 31; $i++) {
        $temp = form_input_list_entry(strval($i), $i === $default_day);
        $temp->evaluate_echo();
    }
    $days = ob_get_contents();
    ob_end_clean();
    ob_start();
    for ($i = 1; $i <= 12; $i++) {
        switch ($i) {
            case 1:
                $month_text = do_lang_tempcode('JANUARY');
                break;
            case 2:
                $month_text = do_lang_tempcode('FEBRUARY');
                break;
            case 3:
                $month_text = do_lang_tempcode('MARCH');
                break;
            case 4:
                $month_text = do_lang_tempcode('APRIL');
                break;
            case 5:
                $month_text = do_lang_tempcode('MAY');
                break;
            case 6:
                $month_text = do_lang_tempcode('JUNE');
                break;
            case 7:
                $month_text = do_lang_tempcode('JULY');
                break;
            case 8:
                $month_text = do_lang_tempcode('AUGUST');
                break;
            case 9:
                $month_text = do_lang_tempcode('SEPTEMBER');
                break;
            case 10:
                $month_text = do_lang_tempcode('OCTOBER');
                break;
            case 11:
                $month_text = do_lang_tempcode('NOVEMBER');
                break;
            case 12:
                $month_text = do_lang_tempcode('DECEMBER');
                break;
        }
        $temp = form_input_list_entry(strval($i), $i === $default_month, $month_text);
        $temp->evaluate_echo();
    }
    $months = ob_get_contents();
    ob_end_clean();
    ob_start();
    if (!is_null($total_years_to_show) && $total_years_to_show < 0) {
        $yt = $year_start + $total_years_to_show;
        for ($i = max($untuned_year_start, $year_start); $i >= $yt; $i--) {
            $temp = form_input_list_entry(strval($i), $i === $default_year);
            $temp->evaluate_echo();
        }
    } else {
        if (is_null($total_years_to_show)) {
            $yt = max($untuned_year_start, $year_start) + 5;
        } else {
            $yt = max($untuned_year_start, $year_start) + $total_years_to_show;
        }
        for ($i = $year_start; $i <= $yt; $i++) {
            $temp = form_input_list_entry(strval($i), $i === $default_year);
            $temp->evaluate_echo();
        }
    }
    $years = ob_get_contents();
    ob_end_clean();
    $input = do_template('FORM_SCREEN_INPUT_DATE', array('_GUID' => '5ace58dd0f540f70fb3bd440fb02a430', 'NULL_OK' => $null_ok, 'DISABLED' => $null_default, 'TABINDEX' => strval($tabindex), 'YEARS' => $years, 'MONTHS' => $months, 'DAYS' => $days, 'STUB' => $stub, 'NULL' => $null, 'TIME' => $time, 'UNLIMITED' => is_null($total_years_to_show)));
    return _form_input($stub, $pretty_name, $description, $input, $required, false, $tabindex, false, true);
}
Exemplo n.º 9
0
/**
 * Get array of an events from node of an imported ical file
 *
 * @param  array		Array of given event details
 * @return array		Returns array of event details for mapping
 */
function get_event_data_ical($calendar_nodes)
{
    $url = '';
    $type = NULL;
    //default value
    $e_recurrence = 'none';
    $recurrences = NULL;
    $seg_recurrences = 0;
    $title = '';
    $content = '';
    $priority = 2;
    $is_public = 1;
    $start_year = 2000;
    $start_month = 1;
    $start_day = 1;
    $start_hour = 0;
    $start_minute = 0;
    $end_year = NULL;
    $end_month = NULL;
    $end_day = NULL;
    $end_hour = NULL;
    $end_minute = NULL;
    $timezone = 'UTC';
    $validated = NULL;
    $allow_rating = NULL;
    $allow_comments = NULL;
    $allow_trackbacks = NULL;
    $notes = '';
    $validated = 1;
    $allow_rating = 1;
    $allow_comments = 1;
    $allow_trackbacks = 1;
    $matches = array();
    $rec_array = array('FREQ', 'BYDAY', 'INTERVAL', 'COUNT');
    $rec_by_day = array('MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU');
    //	if (array_key_exists('LOCATION',$calendar_nodes))
    //		$geo_position=$calendar_nodes['LOCATION'];
    if (array_key_exists('RRULE', $calendar_nodes)) {
        $byday = '';
        foreach ($rec_array as $value) {
            if (preg_match('/^((.)*(' . $value . '=))([^;]+)/i', $calendar_nodes['RRULE'], $matches) != 0) {
                switch ($value) {
                    case 'FREQ':
                        $e_recurrence = strtolower(end($matches));
                        break;
                    case 'INTERVAL':
                        $rec_patern = ' 1';
                        for ($i = 1; $i < intval(end($matches)); $i++) {
                            $rec_patern .= '0';
                        }
                        $e_recurrence .= $rec_patern;
                        break;
                    case 'COUNT':
                        $recurrences = end($matches);
                        break;
                }
            }
        }
    }
    if (array_key_exists('CATEGORIES', $calendar_nodes)) {
        $type = strtolower($calendar_nodes['CATEGORIES']);
    }
    // Check existency of category
    $type_id = NULL;
    if (is_null($type)) {
        $type = do_lang('GENERAL');
    }
    $rows = $GLOBALS['SITE_DB']->query_select('calendar_types', array('id', 't_title'));
    foreach ($rows as $row) {
        if (strtolower($type) == strtolower(get_translated_text($row['t_title']))) {
            $type_id = $row['id'];
        }
    }
    if (array_key_exists('SUMMARY', $calendar_nodes)) {
        $title = $calendar_nodes['SUMMARY'];
        $content = $calendar_nodes['SUMMARY'];
    }
    if (array_key_exists('DESCRIPTION', $calendar_nodes)) {
        $content = str_replace('\\n', "\n", $calendar_nodes['DESCRIPTION']);
    }
    if (array_key_exists('PRIORITY', $calendar_nodes)) {
        $priority = $calendar_nodes['PRIORITY'];
    }
    if (array_key_exists('TZID', $calendar_nodes)) {
        $timezone = $calendar_nodes['TZID'];
    }
    if (array_key_exists('URL', $calendar_nodes)) {
        $url = $calendar_nodes['URL'];
    }
    if (array_key_exists('DTSTART', $calendar_nodes)) {
        $all_day = false;
        if (strlen($calendar_nodes['DTSTART']) == 8) {
            $calendar_nodes['DTSTART'] .= ' 00:00';
            $all_day = true;
        }
        $start = strtotime($calendar_nodes['DTSTART']);
        $start_year = intval(date('Y', $start));
        $start_month = intval(date('m', $start));
        $start_day = intval(date('d', $start));
        $start_hour = $all_day ? NULL : intval(date('H', $start));
        $start_minute = $all_day ? NULL : intval(date('i', $start));
        if ($all_day) {
            $timestamp = mktime(0, 0, 0, $start_month, $start_day, $start_year);
            $amount_forward = tz_time($timestamp, $timezone) - $timestamp;
            $timestamp = $timestamp + $amount_forward;
            list($start_year, $start_month, $start_day) = array_map('intval', explode('-', date('Y-m-d', $timestamp)));
        } else {
            $timestamp = mktime($start_hour, $start_minute, 0, $start_month, $start_day, $start_year);
            $amount_forward = tz_time($timestamp, $timezone) - $timestamp;
            $timestamp = $timestamp + $amount_forward;
            list($start_year, $start_month, $start_day, $start_hour, $start_minute) = array_map('intval', explode('-', date('Y-m-d-H-i-s', $timestamp)));
        }
    }
    if (array_key_exists('DTEND', $calendar_nodes)) {
        if (strlen($calendar_nodes['DTEND']) == 8) {
            $calendar_nodes['DTEND'] .= ' 00:00';
        } else {
            $all_day = false;
        }
        $end = strtotime($calendar_nodes['DTEND']);
        $end_year = intval(date('Y', $end));
        $end_month = intval(date('m', $end));
        $end_day = intval(date('d', $end));
        $end_hour = mixed();
        $end_minute = mixed();
        $end_hour = $all_day ? NULL : intval(date('H', $end));
        $end_minute = $all_day ? NULL : intval(date('i', $end));
        if ($all_day) {
            $timestamp = mktime(0, 0, 0, $end_month, $end_day, $end_year);
            $amount_forward = tz_time($timestamp, $timezone) - $timestamp;
            $timestamp = $timestamp - $amount_forward;
            list($end_year, $end_month, $end_day) = array_map('intval', explode('-', date('Y-m-d', $timestamp - 1)));
        } else {
            $timestamp = mktime($end_hour, $end_minute, 0, $end_month, $end_day, $end_year);
            $amount_forward = tz_time($timestamp, $timezone) - $timestamp;
            $timestamp = $timestamp - $amount_forward;
            list($end_year, $end_month, $end_day, $end_hour, $end_minute) = array_map('intval', explode('-', date('Y-m-d-H-i-s', $timestamp - 1)));
        }
    }
    if ($all_day) {
        $start_hour = NULL;
        $start_minute = NULL;
        $end_hour = NULL;
        $end_minute = NULL;
    }
    $ret = array($url, $type_id, $type, $e_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);
    return $ret;
}