/** * Standard pointstore item configuration save function. */ function save_config() { $i = 0; $rows = list_to_map('id', $GLOBALS['SITE_DB']->query_select('pstore_customs', array('*'))); while (array_key_exists('custom_' . strval($i), $_POST)) { $id = post_param_integer('custom_' . strval($i)); $title = post_param('custom_title_' . strval($i)); $description = post_param('custom_description_' . strval($i)); $enabled = post_param_integer('custom_enabled_' . strval($i), 0); $cost = post_param_integer('custom_cost_' . strval($i)); $one_per_member = post_param_integer('custom_one_per_member_' . strval($i), 0); $delete = post_param_integer('delete_custom_' . strval($i), 0); $_title = $rows[$id]['c_title']; $_description = $rows[$id]['c_description']; if ($delete == 1) { delete_lang($_title); delete_lang($_description); $GLOBALS['SITE_DB']->query_delete('pstore_customs', array('id' => $id), '', 1); } else { $GLOBALS['SITE_DB']->query_update('pstore_customs', array('c_title' => lang_remap($_title, $title), 'c_description' => lang_remap($_description, $description), 'c_enabled' => $enabled, 'c_cost' => $cost, 'c_one_per_member' => $one_per_member), array('id' => $id), '', 1); } $i++; } $title = post_param('custom_title', NULL); if (!is_null($title)) { $description = post_param('custom_description'); $enabled = post_param_integer('custom_enabled', 0); $cost = post_param_integer('custom_cost'); $one_per_member = post_param_integer('custom_one_per_member', 0); $GLOBALS['SITE_DB']->query_insert('pstore_customs', array('c_title' => insert_lang($title, 2), 'c_description' => insert_lang($description, 2), 'c_enabled' => $enabled, 'c_cost' => $cost, 'c_one_per_member' => $one_per_member)); } }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { $url = array_key_exists('param', $map) ? $map['param'] : 'http://ocportal.com/backend.php?type=rss&mode=news&filter=16,17,18,19,20'; // http://channel9.msdn.com/Feeds/RSS/ require_code('rss'); $rss = new rss($url); if (!is_null($rss->error)) { return paragraph($rss->error, 'gfgrtyhyyfhd'); } global $NEWS_CATS; $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); $_postdetailss = array(); // Now for the actual stream contents $max = array_key_exists('max_entries', $map) ? intval($map['max_entries']) : 10; $content = new ocp_tempcode(); foreach ($rss->gleamed_items as $i => $item) { if ($i >= $max) { break; } if (array_key_exists('full_url', $item)) { $full_url = $item['full_url']; } elseif (array_key_exists('guid', $item)) { $full_url = $item['guid']; } elseif (array_key_exists('comment_url', $item)) { $full_url = $item['comment_url']; } else { $full_url = ''; } $_title = $item['title']; $date = array_key_exists('clean_add_date', $item) ? get_timezoned_date($item['clean_add_date']) : array_key_exists('add_date', $item) ? $item['add_date'] : ''; $_postdetailss[] = array('DATE' => $date, 'FULL_URL' => $full_url, 'NEWS_TITLE' => $_title); } return do_template('BLOCK_BOTTOM_NEWS', array('_GUID' => '0fc123199c4d4b7af5a26706271b1f4f', 'POSTS' => $_postdetailss)); }
function get_group_points() { $_group_points = $GLOBALS['SITE_DB']->query_select('group_points', array('*'), NULL, '', NULL, NULL, true); if (is_null($_group_points)) { $group_points = array(); install_group_points_stuff(); } else { $group_points = list_to_map('p_group_id', $_group_points); } return $group_points; }
/** * For a list of booking IDs (assumed to be from same member), reconstitute/simplify as much as possible, and return the booking details structure. * * @param array List of booking IDs. * @return array Reconstituted booking details structure to check. */ function get_booking_request_from_db($booking_ids) { $request = array(); foreach ($booking_ids as $booking_id) { $booking = $GLOBALS['SITE_DB']->query_select('booking', array('*'), array('id' => $booking_id), '', 1); if (!array_key_exists(0, $booking)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $supplements = $GLOBALS['SITE_DB']->query_select('booking_supplement', array('supplement_id', 'quantity', 'notes'), array('booking_id' => $booking_id)); $request[] = array('bookable_id' => $booking[0]['bookable_id'], 'start_day' => $booking[0]['b_day'], 'start_month' => $booking[0]['b_month'], 'start_year' => $booking[0]['b_year'], 'end_day' => $booking[0]['b_day'], 'end_month' => $booking[0]['b_month'], 'end_year' => $booking[0]['b_year'], 'notes' => $booking[0]['notes'], 'supplements' => list_to_map('supplement_id', $supplements), 'quantity' => 1, '_rows' => array($booking[0])); } reconstitute_booking_requests($request); return $request; }
/** * Standard modular run function for RSS hooks. * * @param string A list of categories we accept from * @param TIME Cutoff time, before which we do not show results from * @param string Prefix that represents the template set we use * @set RSS_ ATOM_ * @param string The standard format of date to use for the syndication type represented in the prefix * @param integer The maximum number of entries to return, ordering by date * @return ?array A pair: The main syndication section, and a title (NULL: error) */ function run($_filters, $cutoff, $prefix, $date_string, $max) { if (!addon_installed('ocf_forum')) { return NULL; } if (get_forum_type() != 'ocf') { return NULL; } if (!has_actual_page_access(get_member(), 'forumview')) { return NULL; } $filters = ocfilter_to_sqlfragment($_filters, 'p_topic_id', 'f_forums', 'f_parent_forum', 'p_cache_forum_id', 'id', true, true, $GLOBALS['FORUM_DB']); $cutoff = max($cutoff, time() - 60 * 60 * 24 * 60); if (!is_guest()) { $filters .= ' AND (p_poster<>' . strval(get_member()) . ')'; } $rows = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_time>' . strval($cutoff) . (!has_specific_permission(get_member(), 'see_unvalidated') ? ' AND p_validated=1 ' : '') . ' AND ' . $filters . ' ORDER BY p_time DESC,id DESC', $max); $categories = list_to_map('id', $GLOBALS['FORUM_DB']->query('SELECT id,t_cache_first_title,t_pt_from,t_pt_to FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE t_cache_last_time>' . strval((int) $cutoff))); $content = new ocp_tempcode(); foreach ($rows as $row) { if (!array_key_exists($row['p_topic_id'], $categories)) { continue; } $category = $categories[$row['p_topic_id']]['t_cache_first_title']; if ((!is_null($row['p_cache_forum_id']) || $categories[$row['p_topic_id']]['t_pt_from'] == get_member() || $categories[$row['p_topic_id']]['t_pt_to'] == get_member()) && (is_null($row['p_intended_solely_for']) || $row['p_intended_solely_for'] == get_member()) && has_category_access(get_member(), 'forums', strval($row['p_cache_forum_id']))) { $id = strval($row['id']); $author = $row['p_poster_name_if_guest']; $news_date = date($date_string, $row['p_time']); $edit_date = is_null($row['p_last_edit_time']) ? '' : date($date_string, $row['p_last_edit_time']); if ($edit_date == $news_date) { $edit_date = ''; } $news_title = xmlentities($row['p_title']); $_summary = get_translated_tempcode($row['p_post'], $GLOBALS['FORUM_DB']); $summary = xmlentities($_summary->evaluate()); $news = ''; $category_raw = strval($row['p_topic_id']); $view_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $row['id']), get_module_zone('forumview'), NULL, false, false, true); if ($prefix == 'RSS_') { $if_comments = do_template('RSS_ENTRY_COMMENTS', array('_GUID' => 'ed06bc8f174a5427e1789820666fdd81', 'COMMENT_URL' => $view_url, 'ID' => strval($row['p_topic_id']))); } else { $if_comments = new ocp_tempcode(); } $content->attach(do_template($prefix . 'ENTRY', array('VIEW_URL' => $view_url, 'SUMMARY' => $summary, 'EDIT_DATE' => $edit_date, 'IF_COMMENTS' => $if_comments, 'TITLE' => $news_title, 'CATEGORY_RAW' => $category_raw, 'CATEGORY' => $category, 'AUTHOR' => $author, 'ID' => $id, 'NEWS' => $news, 'DATE' => $news_date))); } } require_lang('ocf'); return array($content, do_lang('FORUM_TOPICS')); }
/** * The actualiser to import wordpress blog * * @return tempcode The UI */ function _import_wordpress() { check_specific_permission('mass_import', NULL, NULL, 'cms_news'); $title = get_page_title('IMPORT_WP_DB'); require_code('rss'); require_code('news'); require_code('news2'); $GLOBALS['LAX_COMCODE'] = true; require_code('uploads'); is_swf_upload(true); $is_validated = post_param_integer('wp_auto_validate', 0); $to_own_account = post_param_integer('wp_add_to_own', 0); //Wordpress post xml file importing method if (get_param('method') == 'xml') { $rss_url = post_param('xml_url', NULL); if (array_key_exists('file_novalidate', $_FILES)) { if (is_swf_upload(true) && array_key_exists('file_novalidate', $_FILES) || array_key_exists('file_novalidate', $_FILES) && is_uploaded_file($_FILES['file_novalidate']['tmp_name'])) { $rss_url = $_FILES['file_novalidate']['tmp_name']; } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } $rss = new rss($rss_url, true); if (!is_null($rss->error)) { warn_exit($rss->error); } $cat_id = NULL; $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); $extra_post_data = array(); foreach ($rss->gleamed_items as $item) { if (!array_key_exists('category', $item)) { $item['category'] = do_lang('NC_general'); } $extra_post_data[] = $item; foreach ($NEWS_CATS as $_cat => $news_cat) { if (get_translated_text($news_cat['nc_title']) == $item['category']) { $cat_id = $_cat; } } //Check for existing owner categories, if not create blog category for creator if ($to_own_account == 0) { $creator = $item['author']; $submitter_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($creator); } else { $submitter_id = get_member(); } //if(is_null($submitter_id)) continue; //Skip importing posts of nonexisting users $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $submitter_id)); if (is_null($cat_id)) { $cat_id = add_news_category($item['category'], 'newscats/general', '', NULL); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } // Add news add_news($item['title'], html_to_comcode($item['news']), NULL, $is_validated, 1, 1, 1, '', array_key_exists('news_article', $item) ? html_to_comcode($item['news_article']) : '', $owner_category_id, array($cat_id), NULL, $submitter_id, 0, time(), NULL, ''); } if (url_is_local($rss_url)) { // Means it is a temp file @unlink($rss_url); } } elseif (get_param('method') == 'db') { import_wordpress_db(); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_BLOGS')), array('_SELF:_SELF:import_wordpress', do_lang_tempcode('IMPORT_WORDPRESS')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return inform_screen($title, do_lang_tempcode('IMPORT_WORDPRESS_DONE')); }
/** * Import wordpress db */ function import_wordpress_db() { disable_php_memory_limit(); $data = get_wordpress_data(); $is_validated = post_param_integer('wp_auto_validate', 0); $to_own_account = post_param_integer('wp_add_to_own', 0); // Create members require_code('ocf_members_action'); require_code('ocf_groups'); $def_grp_id = get_first_default_group(); $cat_id = array(); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); foreach ($data as $values) { if (get_forum_type() == 'ocf') { $member_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $values['user_login'])); if (is_null($member_id)) { if (post_param_integer('wp_import_wordpress_users', 0) == 1) { $member_id = ocf_make_member($values['user_login'], $values['user_pass'], '', NULL, NULL, NULL, NULL, array(), NULL, $def_grp_id, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false, 'wordpress'); } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username('admin'); // Set admin as owner if (is_null($member_id)) { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id() + 1; } } } } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // Guest user // If post should go to own account if ($to_own_account == 1) { $member_id = get_member(); } if (array_key_exists('POSTS', $values)) { // Create posts in blog foreach ($values['POSTS'] as $post_id => $post) { if (array_key_exists('category', $post)) { $cat_id = array(); foreach ($post['category'] as $cat_code => $category) { $cat_code = NULL; if ($category == 'Uncategorized') { continue; } // Skip blank category creation foreach ($NEWS_CATS as $id => $existing_cat) { if (get_translated_text($existing_cat['nc_title']) == $category) { $cat_code = $id; } } if (is_null($cat_code)) { $cat_code = add_news_category($category, 'newscats/community', $category); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*')); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $cat_id = array_merge($cat_id, array($cat_code)); } } $owner_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $member_id)); if ($post['post_type'] == 'post') { $id = add_news($post['post_title'], html_to_comcode($post['post_content']), NULL, $is_validated, 1, $post['comment_status'] == 'closed' ? 0 : 1, 1, '', html_to_comcode($post['post_content']), $owner_category_id, $cat_id, NULL, $member_id, 0, time(), NULL, ''); } elseif ($post['post_type'] == 'page') { // If dont have permission to write comcode page, skip the post if (!has_submit_permission('high', get_member(), get_ip_address(), NULL, NULL)) { continue; } require_code('comcode'); // Save articles as new comcode pages $zone = filter_naughty(post_param('zone', 'site')); $lang = filter_naughty(post_param('lang', 'EN')); $file = preg_replace('/[^A-Za-z0-9]/', '_', $post['post_title']); // Filter non alphanumeric charactors $parent_page = post_param('parent_page', ''); $fullpath = zone_black_magic_filterer(get_custom_file_base() . '/' . $zone . '/pages/comcode_custom/' . $lang . '/' . $file . '.txt'); // Check existancy of new page $submiter = $GLOBALS['SITE_DB']->query_value_null_ok('comcode_pages', 'p_submitter', array('the_zone' => $zone, 'the_page' => $file)); if (!is_null($submiter)) { continue; } // Skip existing titled articles - may need change require_code('submit'); give_submit_points('COMCODE_PAGE_ADD'); if (!addon_installed('unvalidated')) { $is_validated = 1; } $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => $zone, 'the_page' => $file, 'p_parent_page' => $parent_page, 'p_validated' => $is_validated, 'p_edit_date' => NULL, 'p_add_date' => strtotime($post['post_date']), 'p_submitter' => $member_id, 'p_show_as_edit' => 0)); if (!file_exists($fullpath)) { $_content = html_to_comcode($post['post_content']); $myfile = @fopen($fullpath, 'wt'); if ($myfile === false) { intelligent_write_error($fullpath); } if (fwrite($myfile, $_content) < strlen($_content)) { warn_exit(do_lang_tempcode('COULD_NOT_SAVE_FILE')); } fclose($myfile); sync_file($fullpath); } require_code('seo2'); seo_meta_set_for_explicit('comcode_page', $zone . ':' . $file, post_param('meta_keywords', ''), post_param('meta_description', '')); require_code('permissions2'); set_page_permissions_from_environment($zone, $file); } $content_url = build_url(array('page' => 'news', 'type' => 'view', 'id' => $id), get_module_zone('news'), NULL, false, false, true); $content_title = $post['post_title']; // Add comments if (post_param_integer('wp_import_blog_comments', 0) == 1) { if (array_key_exists('COMMENTS', $post)) { $submitter = NULL; foreach ($post['COMMENTS'] as $comment) { $submitter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_members', 'id', array('m_username' => $comment['comment_author'])); if (is_null($submitter)) { $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } // If comment is made by a non-member, assign comment to guest account $forum = is_null(get_value('comment_forum__news')) ? get_option('comments_forum_name') : get_value('comment_forum__news'); $result = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, 'news_' . strval($id), $submitter, $post['post_title'], $comment['comment_content'], $content_title, do_lang('COMMENT'), $content_url, NULL, NULL, 1, 1, false); } } } } } } }
/** * Read in a great big map of details relating to a topic. * * @param ?AUTO_LINK The ID of the topic we are getting details of (NULL: whispers). * @param integer The start row for getting details of posts in the topic (i.e. 0 is start of topic, higher is further through). * @param integer The maximum number of posts to get detail of. * @param boolean Whether we are viewing poll results for the topic (if there is no poll for the topic, this is irrelevant). * @param boolean Whether to check permissions. * @return array The map of details. */ function ocf_read_in_topic($topic_id, $start, $max, $view_poll_results = false, $check_perms = true) { if (!is_null($topic_id)) { $_topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics t LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums f ON f.id=t.t_forum_id', array('t.*', 'f.f_is_threaded'), array('t.id' => $topic_id), '', 1); if (!array_key_exists(0, $_topic_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $topic_info = $_topic_info[0]; // Are we allowed into here? // Check forum $forum_id = $topic_info['t_forum_id']; if (!is_null($forum_id)) { if ($check_perms) { if (!has_category_access(get_member(), 'forums', strval($forum_id))) { access_denied('CATEGORY_ACCESS_LEVEL'); } } } else { // It must be a personal topic. Do we have access? $from = $topic_info['t_pt_from']; $to = $topic_info['t_pt_to']; if ($from != get_member() && $to != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt')) { access_denied('SPECIFIC_PERMISSION', 'view_other_pt'); } decache('_new_pp', array(get_member())); decache('side_ocf_personal_topics', array(get_member())); } // Check validated if ($topic_info['t_validated'] == 0) { if (!has_specific_permission(get_member(), 'jump_to_unvalidated')) { access_denied('SPECIFIC_PERMISSION', 'jump_to_unvalidated'); } } if (is_null(get_param_integer('threaded', NULL))) { if ($start > 0) { if ($topic_info['f_is_threaded'] == 1) { $_GET['threaded'] = '0'; } } } $is_threaded = get_param_integer('threaded', is_null($topic_info['f_is_threaded']) ? 0 : $topic_info['f_is_threaded']); if ($is_threaded != 1) { $is_threaded = 0; } // In case of invalid URLs causing inconsistent handling // Some general info $out = array('num_views' => $topic_info['t_num_views'], 'num_posts' => $topic_info['t_cache_num_posts'], 'validated' => $topic_info['t_validated'], 'title' => $topic_info['t_cache_first_title'], 'description' => $topic_info['t_description'], 'description_link' => $topic_info['t_description_link'], 'emoticon' => $topic_info['t_emoticon'], 'forum_id' => $topic_info['t_forum_id'], 'first_post' => $topic_info['t_cache_first_post'], 'first_poster' => $topic_info['t_cache_first_member_id'], 'first_post_id' => $topic_info['t_cache_first_post_id'], 'pt_from' => $topic_info['t_pt_from'], 'pt_to' => $topic_info['t_pt_to'], 'is_open' => $topic_info['t_is_open'], 'is_threaded' => $is_threaded, 'is_really_threaded' => is_null($topic_info['f_is_threaded']) ? 0 : $topic_info['f_is_threaded'], 'last_time' => $topic_info['t_cache_last_time'], 'meta_data' => array('created' => date('Y-m-d', $topic_info['t_cache_first_time']), 'creator' => $topic_info['t_cache_first_username'], 'publisher' => '', 'modified' => date('Y-m-d', $topic_info['t_cache_last_time']), 'type' => 'Forum topic', 'title' => $topic_info['t_cache_first_title'], 'identifier' => '_SEARCH:topicview:misc:' . strval($topic_id), 'numcomments' => strval($topic_info['t_cache_num_posts']), 'image' => find_theme_image('bigicons/forums'))); // Poll? if (!is_null($topic_info['t_poll_id'])) { require_code('ocf_polls'); $voted_already = $GLOBALS['FORUM_DB']->query_value_null_ok('f_poll_votes', 'pv_member_id', array('pv_poll_id' => $topic_info['t_poll_id'], 'pv_member_id' => get_member())); $out['poll'] = ocf_poll_get_results($topic_info['t_poll_id'], $view_poll_results || !is_null($voted_already)); $out['poll']['voted_already'] = $voted_already; $out['poll_id'] = $topic_info['t_poll_id']; } // Post query $where = ocf_get_topic_where($topic_id); $query = 'SELECT p.*,t.text_parsed AS text_parsed,t.text_original AS message_comcode,h.h_post_id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_post_history h ON (h.h_post_id=p.id AND h.h_action_date_and_time=p.p_last_edit_time) LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND p.p_post=t.id WHERE ' . $where . ' ORDER BY p_time,p.id'; } else { $out = array('num_views' => 0, 'num_posts' => 0, 'validated' => 1, 'title' => do_lang('INLINE_PERSONAL_POSTS'), 'description' => '', 'description_link' => '', 'emoticon' => '', 'forum_id' => NULL, 'first_post' => NULL, 'first_poster' => NULL, 'first_post_id' => NULL, 'pt_from' => NULL, 'pt_to' => NULL, 'is_open' => 1, 'is_threaded' => 0, 'last_time' => time(), 'meta_data' => array()); // Post query $where = 'p_intended_solely_for=' . strval(get_member()); $query = 'SELECT p.*,t.text_parsed AS text_parsed,t.text_original AS message_comcode,h.h_post_id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts p LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_post_history h ON (h.h_post_id=p.id AND h.h_action_date_and_time=p.p_last_edit_time) LEFT JOIN ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'translate t ON ' . db_string_equal_to('language', user_lang()) . ' AND p.p_post=t.id WHERE ' . $where . ' ORDER BY p_time,p.id'; } // Posts if ($out['is_threaded'] == 0) { $_postdetailss = list_to_map('id', $GLOBALS['FORUM_DB']->query($query, $max, $start)); if ($start == 0 && count($_postdetailss) < $max) { $out['max_rows'] = $max; } else { $out['max_rows'] = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT COUNT(*) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE ' . $where); } $posts = array(); // Precache member/group details in one fell swoop $members = array(); foreach ($_postdetailss as $_postdetails) { $members[$_postdetails['p_poster']] = 1; if ($out['title'] == '') { $out['title'] = $_postdetails['p_title']; } } ocf_cache_member_details(array_keys($members)); $i = 0; foreach ($_postdetailss as $_postdetails) { if (is_null($_postdetails['message_comcode'])) { $_postdetails['message_comcode'] = get_translated_text($_postdetails['p_post'], $GLOBALS['FORUM_DB']); } $linked_type = ''; $linked_id = ''; $linked_url = ''; // If it's a spacer post, see if we can detect it better $is_spacer_post = $i == 0 && substr($_postdetails['message_comcode'], 0, strlen('[semihtml]' . do_lang('SPACER_POST_MATCHER'))) == '[semihtml]' . do_lang('SPACER_POST_MATCHER'); if ($is_spacer_post) { $c_prefix = do_lang('COMMENT') . ': #'; if (substr($out['description'], 0, strlen($c_prefix)) == $c_prefix && $out['description_link'] != '') { list($linked_type, $linked_id) = explode('_', substr($out['description'], strlen($c_prefix)), 2); $linked_url = $out['description_link']; $out['description'] = ''; } } // Load post if (get_page_name() == 'search' || is_null($_postdetails['text_parsed']) || $_postdetails['text_parsed'] == '' || $_postdetails['p_post'] == 0) { $_postdetails['message'] = get_translated_tempcode($_postdetails['p_post'], $GLOBALS['FORUM_DB']); } else { $_postdetails['message'] = new ocp_tempcode(); if (!$_postdetails['message']->from_assembly($_postdetails['text_parsed'], true)) { $_postdetails['message'] = get_translated_tempcode($_postdetails['p_post'], $GLOBALS['FORUM_DB']); } } // Fake a quoted post? (kind of a nice 'tidy up' feature if a forum's threading has been turned off, leaving things for flat display) if (!is_null($_postdetails['p_parent_id']) && strpos($_postdetails['message_comcode'], '[quote') === false) { $p = mixed(); // NULL if (array_key_exists($_postdetails['p_parent_id'], $_postdetailss)) { $p = $_postdetailss[$_postdetails['p_parent_id']]; // Load post if (get_page_name() == 'search' || is_null($p['text_parsed']) || $p['text_parsed'] == '' || $p['p_post'] == 0) { $p['message'] = get_translated_tempcode($p['p_post'], $GLOBALS['FORUM_DB']); } else { $p['message'] = new ocp_tempcode(); if (!$p['message']->from_assembly($p['text_parsed'], true)) { $p['message'] = get_translated_tempcode($p['p_post'], $GLOBALS['FORUM_DB']); } } } else { $_p = $GLOBALS['FORUM_DB']->query_select('f_posts', array('*'), array('id' => $_postdetails['p_parent_id']), '', 1); if (array_key_exists(0, $_p)) { $p = $_p[0]; $p['message'] = get_translated_tempcode($p['p_post'], $GLOBALS['FORUM_DB']); } } $temp = $_postdetails['message']; $_postdetails['message'] = new ocp_tempcode(); $_postdetails['message'] = do_template('COMCODE_QUOTE_BY', array('SAIDLESS' => false, 'BY' => $p['p_poster_name_if_guest'], 'CONTENT' => $p['message'])); $_postdetails['message']->attach($temp); } // Spacer posts may have a better first post put in place if ($is_spacer_post) { require_code('ocf_posts'); list($new_description, $new_post) = ocf_display_spacer_post($linked_type, $linked_id); //if (!is_null($new_description)) $out['description']=$new_description; Actually, it's a bit redundant if (!is_null($new_post)) { $_postdetails['message'] = $new_post; } $out['title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $out['title']); $_postdetails['p_title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $_postdetails['p_title']); } // Put together $collated_post_details = ocf_get_details_to_show_post($_postdetails, $start == 0 && count($_postdetailss) == 1); $collated_post_details['is_spacer_post'] = $is_spacer_post; $posts[] = $collated_post_details; $i++; } $out['posts'] = $posts; } // Any special topic/for-any-post-in-topic controls? if (!is_null($topic_id)) { $out['last_poster'] = $topic_info['t_cache_last_member_id']; $out['last_post_id'] = $topic_info['t_cache_last_post_id']; if (is_null($forum_id) || ocf_may_post_in_topic($forum_id, $topic_id, $topic_info['t_cache_last_member_id'])) { $out['may_reply'] = true; } if (ocf_may_report_post()) { $out['may_report_posts'] = true; } if (ocf_may_make_personal_topic()) { $out['may_pt_members'] = true; } if (ocf_may_edit_topics_by($forum_id, get_member(), $topic_info['t_cache_first_member_id'])) { $out['may_edit_topic'] = true; } require_code('ocf_moderation'); require_code('ocf_forums'); if (ocf_may_warn_members()) { $out['may_warn_members'] = true; } if (ocf_may_delete_topics_by($forum_id, get_member(), $topic_info['t_cache_first_member_id'])) { $out['may_delete_topic'] = true; } if (ocf_may_perform_multi_moderation($forum_id)) { $out['may_multi_moderate'] = true; } if (has_specific_permission(get_member(), 'use_quick_reply')) { $out['may_use_quick_reply'] = true; } $may_moderate_forum = ocf_may_moderate_forum($forum_id); if ($may_moderate_forum) { if ($topic_info['t_is_open'] == 0) { $out['may_open_topic'] = 1; } else { $out['may_close_topic'] = 1; } if ($topic_info['t_pinned'] == 0) { $out['may_pin_topic'] = 1; } else { $out['may_unpin_topic'] = 1; } if ($topic_info['t_sunk'] == 0) { $out['may_sink_topic'] = 1; } else { $out['may_unsink_topic'] = 1; } if ($topic_info['t_cascading'] == 0) { $out['may_cascade_topic'] = 1; } else { $out['may_uncascade_topic'] = 1; } $out['may_move_topic'] = 1; $out['may_post_closed'] = 1; $out['may_move_posts'] = 1; $out['may_delete_posts'] = 1; $out['may_validate_posts'] = 1; $out['may_make_personal'] = 1; $out['may_change_max'] = 1; } else { if ($topic_info['t_cache_first_member_id'] == get_member() && has_specific_permission(get_member(), 'close_own_topics') && $topic_info['t_is_open'] == 1) { $out['may_close_topic'] = 1; } } if (!is_null($topic_info['t_poll_id'])) { require_code('ocf_polls'); if (ocf_may_edit_poll_by($forum_id, $topic_info['t_cache_first_member_id'])) { $out['may_edit_poll'] = 1; } if (ocf_may_delete_poll_by($forum_id, $topic_info['t_cache_first_member_id'])) { $out['may_delete_poll'] = 1; } } else { require_code('ocf_polls'); if (ocf_may_attach_poll($topic_id, $topic_info['t_cache_first_member_id'], !is_null($topic_info['t_poll_id']), $forum_id)) { $out['may_attach_poll'] = 1; } } } else { $out['last_poster'] = NULL; $out['last_post_id'] = NULL; $out['may_reply'] = false; } return $out; }
/** * The actualiser to edit a menu. * * @return tempcode The UI */ function _edit_menu() { $title = get_page_title('_EDIT_MENU', true, array(escape_html(get_param('id')))); post_param_integer('confirm'); // Just to make sure hackers don't try and get people to erase this form via a URL $menu_id = get_param('id'); // Find what we have on the menu first $ids = array(); foreach ($_POST as $key => $val) { if (is_string($val)) { if (substr($key, 0, 7) == 'parent_') { $ids[intval(substr($key, 7))] = $val; } } } /*// Order $orderings=array(); $ids_copy=$ids; while (count($ids_copy)!=0) { $best_value=0; // to initialise to integer type $best_value=NULL; $best_id=NULL; foreach ($ids_copy as $id=>$parent) { $value=post_param_integer('order_'.strval($id)); if ((is_null($best_id)) || ($value<$best_value)) { $best_id=$id; $best_value=$value; } } $orderings[]=$best_id; unset($ids_copy[$best_id]); }*/ $orderings = array_keys($ids); // Get language codes currently used $old_menu_bits = list_to_map('id', $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'i_caption', 'i_caption_long'), array('i_menu' => $menu_id))); // Now, process everything on the root $order = 0; foreach ($orderings as $id) { $parent = $ids[$id]; if ($parent == '') { $this->add_menu_item($menu_id, $id, $ids, NULL, $old_menu_bits, $order); $order++; } } // Erase old stuff foreach ($old_menu_bits as $menu_item_id => $lang_code) { $GLOBALS['SITE_DB']->query_delete('menu_items', array('id' => $menu_item_id)); delete_lang($lang_code['i_caption']); delete_lang($lang_code['i_caption_long']); } decache('side_stored_menu'); persistant_cache_delete(array('MENU', $menu_id)); log_it(count($_POST) == 1 ? 'DELETE_MENU' : 'EDIT_MENU', $menu_id); // Go back to editing the menu $url = get_param('redirect', '!'); if ($url == '!') { if (count($_POST) == 1) { $_url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); } else { $_url = build_url(array('page' => '_SELF', 'type' => 'edit', 'wide' => 1, 'id' => $menu_id), '_SELF'); } $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Standard modular run function for implicit usergroup hooks. Finds all members in the group. * * @return ?array The list of members as a map between member ID and member row (NULL: unsupported by hook). */ function get_member_list() { return list_to_map('id', $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . $this->_where())); }
/** * Add a member. * * @param SHORT_TEXT The username. * @param SHORT_TEXT The password. * @param SHORT_TEXT The e-mail address. * @param ?array A list of usergroups (NULL: default/current usergroups). * @param ?integer Day of date of birth (NULL: unknown). * @param ?integer Month of date of birth (NULL: unknown). * @param ?integer Year of date of birth (NULL: unknown). * @param array A map of custom field values (field-id=>value). * @param ?ID_TEXT The member timezone (NULL: auto-detect). * @param ?GROUP The member's primary (NULL: default). * @param BINARY Whether the profile has been validated. * @param ?TIME When the member joined (NULL: now). * @param ?TIME When the member last visited (NULL: now). * @param ID_TEXT The member's default theme. * @param ?URLPATH The URL to the member's avatar (blank: none) (NULL: choose one automatically). * @param LONG_TEXT The member's signature (blank: none). * @param BINARY Whether the member is permanently banned. * @param BINARY Whether posts are previewed before they are made. * @param BINARY Whether the member's age may be shown. * @param SHORT_TEXT The member's title (blank: get from primary). * @param URLPATH The URL to the member's photo (blank: none). * @param URLPATH The URL to the member's photo thumbnail (blank: none). * @param BINARY Whether the member sees signatures in posts. * @param ?BINARY Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config). * @param ?LANGUAGE_NAME The member's language (NULL: auto detect). * @param BINARY Whether the member allows e-mails via the site. * @param BINARY Whether the member allows e-mails from staff via the site. * @param LONG_TEXT Personal notes of the member. * @param ?IP The member's IP address (NULL: IP address of current user). * @param SHORT_TEXT The code required before the account becomes active (blank: already entered). * @param boolean Whether to check details for correctness. * @param ?ID_TEXT The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted). * @param SHORT_TEXT The password salt (blank: password compatibility scheme does not use a salt / auto-generate). * @param BINARY Whether the member likes to view zones without menus, when a choice is available. * @param ?TIME The time the member last made a submission (NULL: set to now). * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param BINARY Whether the member username will be highlighted. * @param SHORT_TEXT Usergroups that may PT the member. * @param LONG_TEXT Rules that other members must agree to before they may start a PT with the member. * @return AUTO_LINK The ID of the new member. */ function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '') { if (is_null($auto_monitor_contrib_content)) { $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1; } if (is_null($password_compatibility_scheme)) { if (get_value('no_password_hashing') === '1') { $password_compatibility_scheme = 'plain'; } else { $password_compatibility_scheme = ''; } } if (is_null($language)) { $language = ''; } if (is_null($signature)) { $signature = ''; } if (is_null($title)) { $title = ''; } if (is_null($timezone)) { $timezone = get_site_timezone(); } if (is_null($allow_emails)) { $allow_emails = 1; } if (is_null($allow_emails_from_staff)) { $allow_emails_from_staff = 1; } if (is_null($personal_notes)) { $personal_notes = ''; } if (is_null($avatar_url)) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) { $avatar_url = ''; } else { if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) { require_code('themes2'); $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']); shuffle($codes); $results = array(); foreach ($codes as $code) { if (strpos($code, 'ocp_fanatic') !== false) { continue; } $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true))); if (is_null($count)) { $count = 0; } $results[$code] = $count; } @asort($results); // @'d as type checker fails for some odd reason $found_avatars = array_keys($results); $avatar_url = find_theme_image(array_shift($found_avatars), true, true); } if (is_null($avatar_url)) { $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => '')); // In case failure cached, gets very confusing $avatar_url = find_theme_image('ocf_default_avatars/default', true, true); if (is_null($avatar_url)) { $avatar_url = ''; } } } } if ($check_correctness) { if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) { ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL); } if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) { require_code('type_validation'); if (!is_valid_email_address($email_address) && $email_address != '') { warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address))); } } } require_code('ocf_members'); require_code('ocf_groups'); if (is_null($last_submit_time)) { $last_submit_time = time(); } if (is_null($join_time)) { $join_time = time(); } if (is_null($last_visit_time)) { $last_visit_time = time(); } if (is_null($primary_group)) { $primary_group = get_first_default_group(); // This is members } if (is_null($secondary_groups)) { $secondary_groups = ocf_get_all_default_groups(false); } foreach ($secondary_groups as $_g_id => $g_id) { if ($g_id == $primary_group) { unset($secondary_groups[$_g_id]); } } if (is_null($ip_address)) { $ip_address = get_ip_address(); } if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') { $password_compatibility_scheme = 'plain'; $salt = ''; } if ($salt == '' && $password_compatibility_scheme == '') { $salt = produce_salt(); $password_salted = md5($salt . md5($password)); } else { $password_salted = $password; } // Supplement custom field values given with defaults, and check constraints $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups)); require_code('fields'); foreach ($all_fields as $field) { $field_id = $field['id']; if (array_key_exists($field_id, $custom_fields)) { if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) { access_denied('I_ERROR'); } } else { $custom_fields[$field_id] = ''; } } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL); if (!is_null($id)) { $map['id'] = $id; } $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true); if ($check_correctness) { // If it was an invite/recommendation, award the referrer if (addon_installed('recommend')) { $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time'); if (!is_null($inviter)) { if (addon_installed('points')) { require_code('points2'); require_lang('recommend'); system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter); } if (addon_installed('chat')) { require_code('chat2'); buddy_add($inviter, $member_id); buddy_add($member_id, $inviter); } } } } $value = mixed(); // Store custom fields $row = array('mf_member_id' => $member_id); $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields); foreach ($custom_fields as $field_num => $value) { if (!array_key_exists($field_num, $all_fields_types)) { continue; } // Trying to set a field we're not allowed to (doesn't apply to our group) $ob = get_fields_hook($all_fields_types[$field_num]); list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]); if (strpos($storage_type, '_trans') !== false) { $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']); } $row['field_' . strval($field_num)] = $value; } // Set custom field row $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type')); foreach ($all_fields_regardless as $field) { if (!array_key_exists('field_' . strval($field['id']), $row)) { $ob = get_fields_hook($field['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($field); $value = ''; if (strpos($storage_type, '_trans') !== false) { $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']); } $row['field_' . strval($field['id'])] = $value; } } $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row); // Any secondary work foreach ($secondary_groups as $g) { if ($g != $primary_group) { $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1); $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1)); } } if ($check_correctness) { if (function_exists('decache')) { decache('side_stats'); } } return $member_id; }
/** * The UI to choose filter parameters. * * @return tempcode The UI */ function search() { $title = get_page_title('VIEW_ACTION_LOGS'); $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/actionlog'; $GLOBALS['HELPER_PANEL_TUTORIAL'] = 'tut_trace'; require_code('form_templates'); $fields = new ocp_tempcode(); // Possible selections for member filter $_member_choice_list = array(); if (get_forum_type() == 'ocf') { if ($GLOBALS['FORUM_DB']->query_value('f_moderator_logs', 'COUNT(DISTINCT l_by)') < 5000) { $members = list_to_map('l_by', $GLOBALS['FORUM_DB']->query_select('f_moderator_logs', array('l_by', 'COUNT(*) AS cnt'), NULL, 'GROUP BY l_by ORDER BY cnt DESC')); foreach ($members as $member) { $username = $GLOBALS['FORUM_DRIVER']->get_username($member['l_by']); if (is_null($username)) { $username = strval($member['l_by']); } $_member_choice_list[$member['l_by']] = array($username, $member['cnt']); } } } if ($GLOBALS['SITE_DB']->query_value('adminlogs', 'COUNT(DISTINCT the_user)') < 5000) { $_staff = list_to_map('the_user', $GLOBALS['SITE_DB']->query_select('adminlogs', array('the_user', 'COUNT(*) AS cnt'), NULL, 'GROUP BY the_user ORDER BY cnt DESC')); foreach ($_staff as $staff) { $username = $GLOBALS['FORUM_DRIVER']->get_username($staff['the_user']); if (is_null($username)) { $username = strval($staff['the_user']); } if (!array_key_exists($staff['the_user'], $_member_choice_list)) { $_member_choice_list[$staff['the_user']] = array($username, $staff['cnt']); } else { $_member_choice_list[$staff['the_user']][1] += $staff['cnt']; } } } $member_choice_list = new ocp_tempcode(); $member_choice_list->attach(form_input_list_entry('-1', true, do_lang_tempcode('_ALL'))); foreach ($_member_choice_list as $id => $user_actions) { list($username, $action_count) = $user_actions; $member_choice_list->attach(form_input_list_entry(strval($id), false, do_lang($action_count == 1 ? 'ACTIONLOG_USERCOUNT_UNI' : 'ACTIONLOG_USERCOUNT', $username, integer_format($action_count)))); } $fields->attach(form_input_list(do_lang_tempcode('USERNAME'), '', 'id', $member_choice_list, NULL, true)); // Possible selections for action type filter $_action_type_list = array(); $rows1 = get_forum_type() == 'ocf' ? $GLOBALS['FORUM_DB']->query_select('f_moderator_logs', array('DISTINCT l_the_type')) : array(); $rows2 = $GLOBALS['SITE_DB']->query_select('adminlogs', array('DISTINCT the_type')); foreach ($rows1 as $row) { $lang = do_lang($row['l_the_type'], NULL, NULL, NULL, NULL, false); if (!is_null($lang)) { $_action_type_list[$row['l_the_type']] = $lang; } } foreach ($rows2 as $row) { $lang = do_lang($row['the_type'], NULL, NULL, NULL, NULL, false); if (!is_null($lang)) { $_action_type_list[$row['the_type']] = $lang; } } asort($_action_type_list); $action_type_list = new ocp_tempcode(); $action_type_list->attach(form_input_list_entry('', true, do_lang_tempcode('_ALL'))); foreach ($_action_type_list as $lang_id => $lang) { $action_type_list->attach(form_input_list_entry($lang_id, false, $lang)); } $fields->attach(form_input_list(do_lang_tempcode('ACTION'), '', 'to_type', $action_type_list, NULL, false, false)); // Filters $fields->attach(form_input_line(do_lang_tempcode('PARAMETER_A'), '', 'param_a', '', false)); $fields->attach(form_input_line(do_lang_tempcode('PARAMETER_B'), '', 'param_b', '', false)); $post_url = build_url(array('page' => '_SELF', 'type' => 'list'), '_SELF', NULL, false, true); $submit_name = do_lang_tempcode('VIEW_ACTION_LOGS'); breadcrumb_set_self(do_lang_tempcode('VIEW_ACTION_LOGS')); return do_template('FORM_SCREEN', array('_GUID' => 'f2c6eda24e0e973aa7e253054f6683a5', 'GET' => true, 'SKIP_VALIDATION' => true, 'HIDDEN' => '', 'TITLE' => $title, 'TEXT' => '', 'URL' => $post_url, 'FIELDS' => $fields, 'SUBMIT_NAME' => $submit_name)); }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('news'); require_css('news'); require_css('side_blocks'); $max = array_key_exists('param', $map) ? intval($map['param']) : 5; $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news'); require_lang('news'); $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1; $historic = array_key_exists('historic', $map) ? $map['historic'] : ''; $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : ''; global $NEWS_CATS; if (!isset($NEWS_CATS)) { $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $content = new ocp_tempcode(); // News Query require_code('ocfiltering'); $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*'); $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')'; if ($blogs === 0) { if ($q_filter != '') { $q_filter .= ' AND '; } $q_filter .= 'nc_owner IS NULL'; } elseif ($blogs === 1) { if ($q_filter != '') { $q_filter .= ' AND '; } $q_filter .= '(nc_owner IS NOT NULL)'; } if ($blogs != -1) { $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category'; } else { $join = ''; } if ($filter_and != '') { $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $filters_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')'; } if ($historic == '') { $news = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY date_and_time DESC', $max); } else { if (function_exists('set_time_limit')) { @set_time_limit(0); } $start = 0; do { $_rows = $GLOBALS['SITE_DB']->query('SELECT p.* FROM ' . get_table_prefix() . 'news p LEFT JOIN ' . get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start); $news = array(); foreach ($_rows as $row) { $ok = false; switch ($historic) { case 'month': if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; case 'week': if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; case 'day': if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; } if ($ok) { if (count($news) < $max) { $news[] = $row; } else { break; } } } $start += 200; } while (count($_rows) == 200 && count($news) < $max); unset($_rows); } $news = remove_duplicate_rows($news, 'id'); $_title = do_lang_tempcode($blogs === 1 ? 'BLOGS_POSTS' : 'NEWS'); if (array_key_exists('title', $map) && $map['title'] != '') { $_title = protect_from_escaping(escape_html($map['title'])); } foreach ($news as $myrow) { if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) { $url_map = array('page' => 'news', 'type' => 'view', 'id' => $myrow['id']); if ($filter != '*') { $url_map['filter'] = $filter; } if ($filter_and != '*' && $filter_and != '') { $url_map['filter_and'] = $filter_and; } if ($blogs === 1) { $url_map['blog'] = 1; } $full_url = build_url($url_map, $zone); $news_title = get_translated_tempcode($myrow['title']); $date = locale_filter(date('d M', utctime_to_usertime($myrow['date_and_time']))); $summary = get_translated_tempcode($myrow['news']); if ($summary->is_empty()) { $summary = get_translated_tempcode($myrow['news_article']); } if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) { $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1); if (array_key_exists(0, $_news_cats)) { $NEWS_CATS[$myrow['news_category']] = $_news_cats[0]; } } $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']); $content->attach(do_template('BLOCK_SIDE_NEWS_SUMMARY', array('_GUID' => 'f7bc5288680e68641ca94ca4a3111d4a', 'IMG_URL' => find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']), 'AUTHOR' => $myrow['author'], 'ID' => strval($myrow['id']), 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'BLOG' => $blogs === 1, 'FULL_URL' => $full_url, 'NEWS' => $summary, 'NEWS_TITLE' => $news_title, '_DATE' => strval($myrow['date_and_time']), 'DATE' => $date))); } } $tmp = array('page' => 'news', 'type' => 'misc'); if ($filter != '*') { $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter; } if ($filter_and != '*' && $filter_and != '') { $tmp['filter_and'] = $filter_and; } if ($blogs != -1) { $tmp['blog'] = $blogs; } $archive_url = build_url($tmp, $zone); $_is_on_rss = get_option('is_rss_advertised', true); $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss); // Set to zero if we don't want to show RSS links $submit_url = new ocp_tempcode(); if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) { $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT); if (is_numeric($filter)) { $map2['cat'] = $filter; // select news cat by default, if we are only showing one news cat in this block } elseif ($filter != '*') { $pos_a = strpos($filter, ','); $pos_b = strpos($filter, '-'); if ($pos_a !== false) { $first_cat = substr($filter, 0, $pos_a); } elseif ($pos_b !== false) { $first_cat = substr($filter, 0, $pos_b); } else { $first_cat = ''; } if (is_numeric($first_cat)) { $map2['cat'] = $first_cat; } } $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news')); } return do_template('BLOCK_SIDE_NEWS', array('_GUID' => '611b83965c4b6e42fb4a709d94c332f7', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $content, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url)); }
/** * Gets all a member's custom fields that match certain parameters. * * @param MEMBER The member. * @param ?BINARY That are publicly viewable (NULL: don't care). * @param ?BINARY That are owner viewable (NULL: don't care). * @param ?BINARY That are owner settable (NULL: don't care). * @param ?BINARY That are encrypted (NULL: don't care). * @param ?BINARY That are required (NULL: don't care). * @param ?BINARY That are to be shown in posts (NULL: don't care). * @param ?BINARY That are to be shown in post previews (NULL: don't care). * @param BINARY That start 'ocp_' * @param ?boolean That are to go on the join form (NULL: don't care). * @return array A mapping of field title to a map of details: 'RAW' as the raw field value, 'RENDERED' as the rendered field value. */ function ocf_get_all_custom_fields_match_member($member_id, $public_view = NULL, $owner_view = NULL, $owner_set = NULL, $encrypted = NULL, $required = NULL, $show_in_posts = NULL, $show_in_post_previews = NULL, $special_start = 0, $show_on_join_form = NULL) { $fields_to_show = ocf_get_all_custom_fields_match($GLOBALS['FORUM_DRIVER']->get_members_groups($member_id), $public_view, $owner_view, $owner_set, $required, $show_in_posts, $show_in_post_previews, $special_start, $show_on_join_form); $custom_fields = array(); $member_mappings = ocf_get_custom_field_mappings($member_id); $member_value = mixed(); // Initialise type to mixed $all_cpf_permissions = get_member() == $member_id || $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) ? array() : list_to_map('field_id', $GLOBALS['FORUM_DB']->query_select('f_member_cpf_perms', array('*'), array('member_id' => $member_id))); require_code('fields'); foreach ($fields_to_show as $i => $field_to_show) { $member_value = $member_mappings['field_' . strval($field_to_show['id'])]; // Decrypt the value if appropriate if (array_key_exists('cf_encrypted', $field_to_show) && $field_to_show['cf_encrypted'] == 1) { require_code('encryption'); if (is_encryption_enabled() && !is_null(post_param('decrypt', NULL))) { $member_value = decrypt_data($member_value, post_param('decrypt')); } } $ob = get_fields_hook($field_to_show['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($field_to_show); if (strpos($storage_type, '_trans') !== false) { if (is_null($member_value) || $member_value == 0) { $member_value = ''; } else { $member_value = get_translated_tempcode($member_value, $GLOBALS['FORUM_DB']); } // This is meant to be '' for blank, not new ocp_tempcode() if (is_object($member_value) && $member_value->is_empty()) { $member_value = ''; } } // get custom permissions for the current CPF $cpf_permissions = array_key_exists($field_to_show['id'], $all_cpf_permissions) ? $all_cpf_permissions[$field_to_show['id']] : array(); $display_cpf = true; // if there are custom permissions set and we are not showing to all if (array_key_exists(0, $cpf_permissions) && !is_null($public_view)) { $display_cpf = false; // Negative ones if ($cpf_permissions[0]['guest_view'] == 1) { $display_cpf = true; } if (!is_guest()) { if ($cpf_permissions[0]['member_view'] == 1) { $display_cpf = true; } } if (!$display_cpf) { if ($cpf_permissions[0]['friend_view'] == 1) { if (!is_null($GLOBALS['SITE_DB']->query_value_null_ok('chat_buddies', 'member_liked', array('member_likes' => $member_id, 'member_liked' => get_member())))) { $display_cpf = true; } } if (!is_guest()) { if ($cpf_permissions[0]['group_view'] == 'all') { $display_cpf = true; } else { if (strlen($cpf_permissions[0]['group_view']) > 0) { require_code('ocfiltering'); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, false, false, NULL, $member_id); $groups_to_search = array(); foreach (array_keys($groups) as $group_id) { $groups_to_search[$group_id] = NULL; } $matched_groups = ocfilter_to_idlist_using_memory($cpf_permissions[0]['group_view'], $groups_to_search); if (count($matched_groups) > 0) { $display_cpf = true; } } } } } } if ($display_cpf) { $rendered_value = $ob->render_field_value($field_to_show, $member_value, $i, NULL); $custom_fields[$field_to_show['trans_name']] = array('RAW' => $member_value, 'RENDERED' => $rendered_value); } } return $custom_fields; }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('news'); require_lang('ocf'); require_css('news'); $days = array_key_exists('param', $map) ? intval($map['param']) : 14; $multiplier = array_key_exists('multiplier', $map) ? floatval($map['multiplier']) : 0.5; $fallback_full = array_key_exists('fallback_full', $map) ? intval($map['fallback_full']) : 3; $fallback_archive = array_key_exists('fallback_archive', $map) ? intval($map['fallback_archive']) : 6; $zone = array_key_exists('zone', $map) ? $map['zone'] : get_module_zone('news'); $historic = array_key_exists('historic', $map) ? $map['historic'] : ''; $filter_and = array_key_exists('filter_and', $map) ? $map['filter_and'] : ''; $blogs = array_key_exists('blogs', $map) ? intval($map['blogs']) : -1; $member_based = array_key_exists('member_based', $map) && $map['member_based'] == '1'; global $NEWS_CATS; if (!isset($NEWS_CATS)) { $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $days_full = floatval($days) * $multiplier; $days_outline = floatval($days) - $days_full; // News Query require_code('ocfiltering'); $filter = array_key_exists('filter', $map) ? $map['filter'] : get_param('news_filter', '*'); $filters_1 = ocfilter_to_sqlfragment($filter, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $filters_2 = ocfilter_to_sqlfragment($filter, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $q_filter = '(' . $filters_1 . ' OR ' . $filters_2 . ')'; if ($blogs === 0) { if ($q_filter != '') { $q_filter .= ' AND '; } $q_filter .= 'nc_owner IS NULL'; } elseif ($blogs === 1) { if ($q_filter != '') { $q_filter .= ' AND '; } $q_filter .= '(nc_owner IS NOT NULL)'; } if ($blogs != -1) { $join = ' LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_categories c ON c.id=p.news_category'; } else { $join = ''; } if ($filter_and != '') { $filters_and_1 = ocfilter_to_sqlfragment($filter_and, 'p.news_category', 'news_categories', NULL, 'p.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $filters_and_2 = ocfilter_to_sqlfragment($filter_and, 'd.news_entry_category', 'news_categories', NULL, 'd.news_category', 'id'); // Note that the parameters are fiddled here so that category-set and record-set are the same, yet SQL is returned to deal in an entirely different record-set (entries' record-set) $q_filter .= ' AND (' . $filters_and_1 . ' OR ' . $filters_and_2 . ')'; } if ($historic == '') { $rows = $days_full == 0.0 ? array() : $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON d.news_entry=p.id' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300); if (!array_key_exists(0, $rows)) { $rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_full); $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', $fallback_archive, $fallback_full); } else { $rows2 = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1 AND date_and_time>=' . strval(time() - 60 * 60 * 24 * intval($days_full + $days_outline)) . ' AND date_and_time<' . strval(time() - 60 * 60 * 24 * intval($days_full)) . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 300); } } else { if (function_exists('set_time_limit')) { @set_time_limit(0); } $start = 0; do { $_rows = $GLOBALS['SITE_DB']->query('SELECT *,p.id AS p_id FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'news_category_entries d ON p.id=d.news_entry' . $join . ' WHERE ' . $q_filter . ' AND validated=1' . (can_arbitrary_groupby() ? ' GROUP BY p.id' : '') . ' ORDER BY p.date_and_time DESC', 200, $start); $rows = array(); $rows2 = array(); foreach ($_rows as $row) { $ok = false; switch ($historic) { case 'month': if (date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; case 'week': if (date('W', utctime_to_usertime($row['date_and_time'])) == date('W', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; case 'day': if (date('d', utctime_to_usertime($row['date_and_time'])) == date('d', utctime_to_usertime()) && date('m', utctime_to_usertime($row['date_and_time'])) == date('m', utctime_to_usertime()) && date('Y', utctime_to_usertime($row['date_and_time'])) != date('Y', utctime_to_usertime())) { $ok = true; } break; } if ($ok) { if (count($rows) < $fallback_full) { $rows[] = $row; } elseif (count($rows2) < $fallback_archive) { $rows2[] = $row; } else { break 2; } } } $start += 200; } while (count($_rows) == 200); unset($_rows); } $rows = remove_duplicate_rows($rows, 'p_id'); $i = 0; $news_text = new ocp_tempcode(); while (array_key_exists($i, $rows)) { $myrow = $rows[$i]; // $categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['p_id'])); if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) { $id = $myrow['p_id']; $date = get_timezoned_date($myrow['date_and_time']); $author_url = addon_installed('authors') && !$member_based ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $myrow['author']), get_module_zone('authors')) : new ocp_tempcode(); $author = $myrow['author']; $news_title = get_translated_tempcode($myrow['title']); if (array_key_exists('show_in_full', $map) && $map['show_in_full'] == '1') { $news = get_translated_tempcode($myrow['news_article']); $truncate = false; if ($news->is_empty()) { $news = get_translated_tempcode($myrow['news']); } } else { $news = get_translated_tempcode($myrow['news']); if ($news->is_empty()) { $news = get_translated_tempcode($myrow['news_article']); $truncate = true; } else { $truncate = false; } } $tmp = array('page' => 'news', 'type' => 'view', 'id' => $id); if ($filter != '*') { $tmp['filter'] = $filter; } if ($filter_and != '*' && $filter_and != '') { $tmp['filter_and'] = $filter_and; } if ($blogs != -1) { $tmp['blog'] = $blogs; } $full_url = build_url($tmp, $zone); if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) { $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1); if (array_key_exists(0, $_news_cats)) { $NEWS_CATS[$myrow['news_category']] = $_news_cats[0]; } } if (!array_key_exists($myrow['news_category'], $NEWS_CATS) || !array_key_exists('nc_title', $NEWS_CATS[$myrow['news_category']])) { $myrow['news_category'] = db_get_first_id(); } $img = find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']); if (is_null($img)) { $img = ''; } if ($myrow['news_image'] != '') { $img = $myrow['news_image']; if (url_is_local($img)) { $img = get_custom_base_url() . '/' . $img; } } $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']); $seo_bits = seo_meta_get_for('news', strval($id)); $map2 = array('TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'ID' => strval($id), 'TRUNCATE' => $truncate, 'BLOG' => $blogs === 1, 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'IMG' => $img, 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'NEWS_TITLE' => $news_title, 'AUTHOR' => $author, 'AUTHOR_URL' => $author_url, 'NEWS' => $news, 'FULL_URL' => $full_url); if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) { $map2['COMMENT_COUNT'] = '1'; } $news_text->attach(do_template('NEWS_PIECE_SUMMARY', $map2)); } $i++; } $j = 0; $news_text2 = new ocp_tempcode(); while (array_key_exists($j, $rows2)) { $myrow = $rows2[$j]; // $categories=$GLOBALS['SITE_DB']->query_select('news_category_entries',array('news_entry_category'),array('news_entry'=>$myrow['id'])); if (has_category_access(get_member(), 'news', strval($myrow['news_category']))) { $date = get_timezoned_date($myrow['date_and_time']); $tmp = array('page' => 'news', 'type' => 'view', 'id' => $myrow['p_id']); if ($filter != '*') { $tmp['filter'] = $filter; } if ($filter_and != '*' && $filter_and != '') { $tmp['filter_and'] = $filter_and; } if ($blogs != -1) { $tmp['blog'] = $blogs; } $url = build_url($tmp, $zone); $title = get_translated_tempcode($myrow['title']); $title_plain = get_translated_text($myrow['title']); $seo_bits = seo_meta_get_for('news', strval($myrow['p_id'])); $map2 = array('_GUID' => 'd81bda3a0912a1e708af6bb1f503b296', 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'BLOG' => $blogs === 1, 'ID' => strval($myrow['p_id']), 'SUBMITTER' => strval($myrow['submitter']), 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'URL' => $url, 'TITLE_PLAIN' => $title_plain, 'TITLE' => $title); if (get_option('is_on_comments') == '1' && !has_no_forum() && $myrow['allow_comments'] >= 1) { $map2['COMMENT_COUNT'] = '1'; } $news_text2->attach(do_template('NEWS_BRIEF', $map2)); } $j++; } $tmp = array('page' => 'news', 'type' => 'misc'); if ($filter != '*') { $tmp[is_numeric($filter) ? 'id' : 'filter'] = $filter; } if ($filter_and != '*' && $filter_and != '') { $tmp['filter_and'] = $filter_and; } if ($blogs != -1) { $tmp['blog'] = $blogs; } $archive_url = build_url($tmp, $zone); $_is_on_rss = get_option('is_rss_advertised', true); $is_on_rss = is_null($_is_on_rss) ? 0 : intval($_is_on_rss); // Set to zero if we don't want to show RSS links $submit_url = new ocp_tempcode(); if (($blogs !== 1 || has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) && has_actual_page_access(NULL, $blogs === 1 ? 'cms_blogs' : 'cms_news', NULL, NULL) && has_submit_permission('high', get_member(), get_ip_address(), $blogs === 1 ? 'cms_blogs' : 'cms_news')) { $map2 = array('page' => $blogs === 1 ? 'cms_blogs' : 'cms_news', 'type' => 'ad', 'redirect' => SELF_REDIRECT); if (is_numeric($filter)) { $map2['cat'] = $filter; // select news cat by default, if we are only showing one news cat in this block } elseif ($filter != '*') { $pos_a = strpos($filter, ','); $pos_b = strpos($filter, '-'); if ($pos_a !== false) { $first_cat = substr($filter, 0, $pos_a); } elseif ($pos_b !== false) { $first_cat = substr($filter, 0, $pos_b); } else { $first_cat = ''; } if (is_numeric($first_cat)) { $map2['cat'] = $first_cat; } } $submit_url = build_url($map2, get_module_zone($blogs === 1 ? 'cms_blogs' : 'cms_news')); } $_title = do_lang_tempcode($blogs == 1 ? 'BLOGS_POSTS' : 'NEWS'); if (array_key_exists('title', $map) && $map['title'] != '') { $_title = protect_from_escaping(escape_html($map['title'])); } if ($i == 0 && $j == 0) { return do_template('BLOCK_NO_ENTRIES', array('_GUID' => '9d7065af4dd4026ffb34243fd931f99d', 'HIGH' => false, 'TITLE' => $_title, 'MESSAGE' => do_lang_tempcode($blogs == 1 ? 'BLOG_NO_NEWS' : 'NO_NEWS'), 'ADD_NAME' => do_lang_tempcode($blogs == 1 ? 'ADD_NEWS_BLOG' : 'ADD_NEWS'), 'SUBMIT_URL' => $submit_url)); } $atom_url = new ocp_tempcode(); $rss_url = new ocp_tempcode(); if ($is_on_rss == 1) { $atom_url = make_string_tempcode(find_script('backend') . '?type=atom&mode=news&filter=' . $filter); $atom_url->attach(symbol_tempcode('KEEP')); $rss_url = make_string_tempcode(find_script('backend') . '?type=rss2&mode=news&filter=' . $filter); $rss_url->attach(symbol_tempcode('KEEP')); } return do_template('BLOCK_MAIN_NEWS', array('_GUID' => '01f5fbd2b0c7c8f249023ecb4254366e', 'BLOG' => $blogs === 1, 'TITLE' => $_title, 'CONTENT' => $news_text, 'BRIEF' => $news_text2, 'FILTER' => $filter, 'ARCHIVE_URL' => $archive_url, 'SUBMIT_URL' => $submit_url, 'RSS_URL' => $rss_url, 'ATOM_URL' => $atom_url)); }
/** * Search the database to find human-readable names for language IDs. * * @param array The language IDs (array of AUTO_LINK) * @return array Human readable names (List of string against same IDs in input array or null for orphan strings) */ function find_lang_content_names($ids) { static $langidfields = NULL; if (is_null($langidfields)) { $query = 'SELECT m_name,m_table,m_type FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'db_meta'; $all_fields = $GLOBALS['SITE_DB']->query($query); $langidfields = array(); foreach ($all_fields as $f) { if (substr($f['m_type'], -6) == '_TRANS') { $langidfields[] = array('m_name' => $f['m_name'], 'm_table' => $f['m_table'], 'key' => ''); } } foreach ($langidfields as $i => $l) { foreach ($all_fields as $f) { if ($l['m_table'] == $f['m_table'] && substr($f['m_type'], 0, 1) == '*' && $l['key'] == '') { $langidfields[$i]['key'] = $f['m_name']; } } } $langidfields[] = array('m_name' => 'config_value', 'm_table' => 'config', 'key' => 'the_name'); } $ret = array(); foreach ($langidfields as $field) { $db = $GLOBALS[substr($field['m_table'], 0, 2) == 'f_' ? 'FORUM_DB' : 'SITE_DB']; if (is_null($db)) { continue; } // None forum driver $or_list = ''; foreach ($ids as $id) { if (!isset($ret[$id])) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= $field['m_table'] == 'config' ? db_string_equal_to($field['m_name'], strval($id)) : $field['m_name'] . '=' . strval($id); } } if ($or_list != '') { $test = list_to_map($field['m_name'], $db->query('SELECT * FROM ' . $db->get_table_prefix() . $field['m_table'] . ' WHERE ' . $or_list)); foreach ($ids as $id) { if (array_key_exists($id, $test)) { $cma_hooks = find_all_hooks('systems', 'content_meta_aware'); foreach (array_keys($cma_hooks) as $hook) { require_code('hooks/systems/content_meta_aware/' . $hook); $ob = object_factory('Hook_content_meta_aware_' . $hook); $info = $ob->info(); if ($info['table'] == $field['m_table']) { if ($info['title_field_dereference']) { $ret[$id] = $field['m_table'] . ' \\ ' . get_translated_text($test[$id][$info['title_field']]) . ' \\ ' . $field['m_name']; } else { $ret[$id] = $field['m_table'] . ' \\ ' . (is_integer($test[$id][$info['title_field']]) ? strval($test[$id][$info['title_field']]) : $test[$id][$info['title_field']]) . ' \\ ' . $field['m_name']; } continue 2; } } $ret[$id] = $field['m_table'] . ' \\ ' . (is_integer($test[$id][$field['key']]) ? strval($test[$id][$field['key']]) : $test[$id][$field['key']]) . ' \\ ' . $field['m_name']; } else { if (!array_key_exists($id, $ret)) { $ret[$id] = NULL; } } } } } return $ret; }
/** * 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; }
/** * The actualiser to import news * * @return tempcode The UI */ function _import_news() { check_specific_permission('mass_import'); $title = get_page_title('IMPORT_NEWS'); require_code('rss'); require_code('news'); require_code('files'); $GLOBALS['LAX_COMCODE'] = true; disable_php_memory_limit(); $rss_url = post_param('rss_feed_url', NULL); require_code('uploads'); if (is_swf_upload(true) && array_key_exists('file_novalidate', $_FILES) || array_key_exists('file_novalidate', $_FILES) && is_uploaded_file($_FILES['file_novalidate']['tmp_name'])) { $rss_url = $_FILES['file_novalidate']['tmp_name']; } if (is_null($rss_url)) { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN')); } $is_validated = post_param_integer('auto_validate', 0); $download_images = post_param_integer('download_images', 0); $rss = new rss($rss_url, true); if (!is_null($rss->error)) { warn_exit($rss->error); } $submitter = get_member(); $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); $extra_post_data = array(); foreach ($rss->gleamed_items as $i => $item) { if (!array_key_exists('category', $item)) { $item['category'] = do_lang('NC_general'); } $extra_post_data[] = $item; $cats_to_process = array($item['category']); if (array_key_exists('extra_categories', $item)) { $cats_to_process = array_merge($cats_to_process, $item['extra_categories']); } $cat_id = mixed(); $extra_categories = array(); foreach ($cats_to_process as $j => $cat) { $_cat_id = mixed(); foreach ($NEWS_CATS as $_cat => $news_cat) { if (get_translated_text($news_cat['nc_title']) == $cat) { $_cat_id = $_cat; } } if (is_null($_cat_id)) { $_cat_id = add_news_category($cat, 'newscats/general', '', NULL); // Need to reload now $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } if ($j == 0) { $cat_id = $_cat_id; } else { $extra_categories[] = $_cat_id; } } $rep_image = ''; if (array_key_exists('rep_image', $item)) { $rep_image = $item['rep_image']; if ($download_images == 1) { $stem = 'uploads/grepimages/' . basename(urldecode($rep_image)); $target_path = get_custom_file_base() . '/' . $stem; $rep_image = 'uploads/grepimages/' . basename($rep_image); while (file_exists($target_path)) { $uniqid = uniqid(''); $stem = 'uploads/grepimages/' . $uniqid . '_' . basename(urldecode($rep_image)); $target_path = get_custom_file_base() . '/' . $stem; $rep_image = 'uploads/grepimages/' . $uniqid . '_' . basename($rep_image); } $target_handle = fopen($target_path, 'wb') or intelligent_write_error($target_path); $result = http_download_file($item['rep_image'], NULL, false, false, 'ocPortal', NULL, NULL, NULL, NULL, NULL, $target_handle); fclose($target_handle); } } // Add news $ts = array_key_exists('clean_add_date', $item) ? $item['clean_add_date'] : (array_key_exists('add_date', $item) ? strtotime($item['add_date']) : time()); if ($ts === false) { $ts = time(); } // Seen in error email, it's if the add date won't parse by PHP $edit_date = array_key_exists('clean_edit_date', $item) ? $item['clean_edit_date'] : (array_key_exists('edit_date', $item) ? strtotime($item['edit_date']) : NULL); if ($edit_date === false) { $edit_date = NULL; } $news = array_key_exists('news', $item) ? html_to_comcode($item['news']) : ''; $news_article = array_key_exists('news_article', $item) ? html_to_comcode($item['news_article']) : ''; $news_id = add_news($item['title'], $news, array_key_exists('author', $item) ? $item['author'] : $GLOBALS['FORUM_DRIVER']->get_username(get_member()), $is_validated, 1, 1, 1, '', $news_article, $cat_id, $extra_categories, $ts, $submitter, 0, $edit_date, NULL, $rep_image); $rss->gleamed_items[$i]['import_id'] = $news_id; $rss->gleamed_items[$i]['import__news'] = $news; $rss->gleamed_items[$i]['import__news_article'] = $news_article; } foreach ($rss->gleamed_items as $i => $item) { $news = $item['import__news']; $news_article = $item['import__news_article']; $this->_grab_images_and_fix_links($download_images == 1, $news, $rss->gleamed_items); $this->_grab_images_and_fix_links($download_images == 1, $news_article, $rss->gleamed_items); lang_remap_comcode($GLOBALS['SITE_DB']->query_value('news', 'news', array('id' => $item['import_id'])), $news); lang_remap_comcode($GLOBALS['SITE_DB']->query_value('news', 'news_article', array('id' => $item['import_id'])), $news_article); } breadcrumb_set_parents(array(array('_SELF:_SELF:misc', do_lang_tempcode('MANAGE_NEWS')), array('_SELF:_SELF:import', do_lang_tempcode('IMPORT_NEWS')))); breadcrumb_set_self(do_lang_tempcode('DONE')); if (url_is_local($rss_url)) { // Means it is a temp file @unlink($rss_url); } return inform_screen($title, do_lang_tempcode('IMPORT_NEWS_DONE')); }
/** * Standard modular run function for CRON hooks. Searches for tasks to perform. */ function run() { if (get_param('keep_lang', NULL) === NULL || get_param('keep_theme', NULL) === NULL) { // We need to run this for each language and for each theme $langs = find_all_langs(); require_code('themes2'); $themes = find_all_themes(); foreach (array_keys($langs) as $lang) { foreach (array_keys($themes) as $theme) { if ($theme == 'default' || has_category_access(get_member(), 'theme', $theme)) { $where = array('c_theme' => $theme, 'c_lang' => $lang); $count = $GLOBALS['SITE_DB']->query_value('cron_caching_requests', 'COUNT(*)', $where); if ($count > 0) { $url = get_base_url() . '/data/cron_bridge.php?limit_hook=block_caching&keep_lang=' . urlencode($lang) . '&keep_theme=' . urlencode($theme); http_download_file($url, NULL, false); } } } } // Force re-loading of values that we use to mark progress (as above calls probably resulted in changes happening) global $VALUES; $VALUES = $GLOBALS['SITE_DB']->query_select('values', array('*')); $VALUES = list_to_map('the_name', $VALUES); return; } $where = array('c_theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'c_lang' => user_lang()); $requests = $GLOBALS['SITE_DB']->query_select('cron_caching_requests', array('id', 'c_codename', 'c_map', 'c_timezone', 'c_is_bot', 'c_in_panel', 'c_interlock', 'c_store_as_tempcode'), $where); foreach ($requests as $request) { $GLOBALS['NO_QUERY_LIMIT'] = true; $codename = $request['c_codename']; $map = unserialize($request['c_map']); $object = do_block_hunt_file($codename, $map); if (is_object($object)) { global $LANGS_REQUESTED, $JAVASCRIPTS, $CSSS, $LANGS_REQUESTED, $DO_NOT_CACHE_THIS, $TIMEZONE_MEMBER_CACHE; $backup_langs_requested = $LANGS_REQUESTED; $backup_javascripts = $JAVASCRIPTS; $backup_csss = $CSSS; get_users_timezone(); $backup_timezone = $TIMEZONE_MEMBER_CACHE[get_member()]; $LANGS_REQUESTED = array(); $JAVASCRIPTS = array('javascript' => 1, 'javascript_thumbnails' => 1); $CSSS = array('no_cache' => 1, 'global' => 1); $cache = $object->run($map); $TIMEZONE_MEMBER_CACHE[get_member()] = $backup_timezone; $cache->handle_symbol_preprocessing(); if (!$DO_NOT_CACHE_THIS) { if (method_exists($object, 'cacheing_environment')) { $info = $object->cacheing_environment(); } else { $info = array(); $info['cache_on'] = 'array($map,$GLOBALS[\'FORUM_DRIVER\']->get_members_groups(get_member()))'; $info['ttl'] = 60 * 24; } $ttl = $info['ttl']; $_cache_identifier = array(); $cache_on = $info['cache_on']; if (is_array($cache_on)) { $_cache_identifier = call_user_func($cache_on[0], $map); } else { if ($cache_on != '' && !defined('HIPHOP_PHP')) { $_cache_on = eval('return ' . $cache_on . ';'); // NB: This uses $map, as $map is referenced inside $cache_on if (is_null($_cache_on)) { return NULL; } foreach ($_cache_on as $on) { $_cache_identifier[] = $on; } } elseif (defined('HIPHOP_PHP')) { return NULL; } } $_cache_identifier[] = $request['c_timezone']; $_cache_identifier[] = $request['c_is_bot'] == 0; $_cache_identifier[] = strval($request['c_in_panel']); $_cache_identifier[] = strval($request['c_interlock']); $cache_identifier = serialize($_cache_identifier); require_code('caches2'); if ($request['c_store_as_tempcode'] == 1) { $cache = make_string_tempcode($cache->evaluate()); } put_into_cache($codename, $ttl, $cache_identifier, $cache, array_keys($LANGS_REQUESTED), array_keys($JAVASCRIPTS), array_keys($CSSS), true); } $LANGS_REQUESTED += $backup_langs_requested; $JAVASCRIPTS += $backup_javascripts; $CSSS += $backup_csss; } $GLOBALS['SITE_DB']->query_delete('cron_caching_requests', $request); } }
/** * Get the list of sections that we can work through, in logical order. * * @return array The section list */ function _get_ordered_sections() { $_sections = list_to_map('p_section', $GLOBALS['SITE_DB']->query_select('sp_list', array('DISTINCT p_section'))); foreach ($_sections as $i => $s) { if ($s['p_section'] == 'SECTION_FORUMS') { $_sections[$i]['trans'] = do_lang('FORUMS_AND_MEMBERS'); } else { $_sections[$i]['trans'] = do_lang($s['p_section']); } } global $M_SORT_KEY; $M_SORT_KEY = 'trans'; @uasort($_sections, 'multi_sort'); /* @ is to stop PHP bug warning about altered array contents when Tempcode copies are evaluated internally */ $orderings = array('SUBMISSION', 'GENERAL_SETTINGS', 'SECTION_FORUMS', 'STAFF_ACTIONS', '_COMCODE', '_FEEDBACK', 'POINTS'); $_sections_prior = array(); foreach ($orderings as $ordering) { if (array_key_exists($ordering, $_sections)) { $x = $_sections[$ordering]; unset($_sections[$ordering]); $_sections_prior[$ordering] = $x; } } if (count($_sections_prior) != 0) { $_sections_prior[''] = NULL; } $_sections = array_merge($_sections_prior, $_sections); return $_sections; }
/** * Standard code module initialisation function. */ function init__users() { global $MEMBERS_BLOCKED, $MEMBERS_BLOCKING_US; $MEMBERS_BLOCKED = NULL; $MEMBERS_BLOCKING_US = NULL; global $SESSION_CACHE, $MEMBER_CACHED, $ADMIN_GROUP_CACHE, $MODERATOR_GROUP_CACHE, $USERGROUP_LIST_CACHE; global $USER_NAME_CACHE, $MEMBER_EMAIL_CACHE, $USERS_GROUPS_CACHE; global $SESSION_CONFIRMED, $GETTING_MEMBER, $EMOTICON_CACHE, $CACHED_THEME, $EMOTICON_LEVELS, $EMOTICON_SET_DIR; $EMOTICON_LEVELS = NULL; $USER_NAME_CACHE = array(); $MEMBER_EMAIL_CACHE = array(); $USERGROUP_LIST_CACHE = NULL; $USERS_GROUPS_CACHE = array(); $ADMIN_GROUP_CACHE = NULL; $MODERATOR_GROUP_CACHE = NULL; $MEMBER_CACHED = NULL; $SESSION_CONFIRMED = 0; $GETTING_MEMBER = false; $EMOTICON_CACHE = NULL; $CACHED_THEME = NULL; $EMOTICON_SET_DIR = NULL; global $IS_ACTUALLY_ADMIN; $IS_ACTUALLY_ADMIN = false; global $IS_A_COOKIE_LOGIN; $IS_A_COOKIE_LOGIN = false; // Load all sessions into memory, if possible if (get_value('session_prudence') !== '1') { $SESSION_CACHE = persistant_cache_get('SESSION_CACHE'); } else { $SESSION_CACHE = NULL; } global $IN_MINIKERNEL_VERSION; if (!is_array($SESSION_CACHE) && $IN_MINIKERNEL_VERSION == 0) { if (get_value('session_prudence') !== '1') { $where = ''; } else { $where = ' WHERE the_session=' . strval(get_session_id()) . ' OR ' . db_string_equal_to('ip', get_ip_address()); } $SESSION_CACHE = array(); if (get_forum_type() == 'ocf' && get_db_site() == get_db_forums() && get_db_site_host() == get_db_forums_host()) { $GLOBALS['NO_DB_SCOPE_CHECK'] = true; $_s = $GLOBALS['SITE_DB']->query('SELECT s.*,m.m_primary_group FROM ' . get_table_prefix() . 'sessions s LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'f_members m ON m.id=s.the_user' . $where); $SESSION_CACHE = list_to_map('the_session', $_s); $GLOBALS['NO_DB_SCOPE_CHECK'] = false; } else { $SESSION_CACHE = list_to_map('the_session', $GLOBALS['SITE_DB']->query('SELECT * FROM ' . get_table_prefix() . 'sessions' . $where)); } if (get_value('session_prudence') !== '1') { persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } // Canonicalise various disparities in how HTTP auth environment variables are set if (array_key_exists('REDIRECT_REMOTE_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['REDIRECT_REMOTE_USER']); } if (array_key_exists('PHP_AUTH_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['PHP_AUTH_USER']); } if (array_key_exists('REMOTE_USER', $_SERVER)) { $_SERVER['PHP_AUTH_USER'] = preg_replace('#@.*$#', '', $_SERVER['REMOTE_USER']); } }
/** * Read booking request from POST environment. * * @return array Booking details structure. */ function get_booking_request_from_form() { $request = array(); $bookables = list_to_map('id', $GLOBALS['SITE_DB']->query_select('bookable', array('*'))); foreach ($bookables as $bookable_id => $bookable) { $all_supplements = $GLOBALS['SITE_DB']->query_select('bookable_supplement', array('*')); $quantity = post_param_integer('bookable_' . strval($bookable_id) . '_quantity', 0); if ($quantity > 0) { $start = get_input_date('bookable_' . strval($bookable_id) . '_date_from'); if (is_null($start)) { $start = get_input_date('bookable_date_from'); } $start_day = intval(date('d', $start)); $start_month = intval(date('m', $start)); $start_year = intval(date('Y', $start)); if ($bookable['dates_are_ranges'] == 1) { $end = get_input_date('bookable_' . strval($bookable_id) . '_date_to'); if (is_null($end)) { $end = get_input_date('bookable_date_to'); } $end_day = intval(date('d', $end)); $end_month = intval(date('m', $end)); $end_year = intval(date('Y', $end)); } else { $end_day = $start_day; $end_month = $start_month; $end_year = $start_year; } $notes = read_booking_notes_from_form('bookable_' . strval($bookable_id) . '_notes'); $supplements = array(); foreach ($all_supplements as $supplement) { $s_quantity = post_param_integer('bookable_' . strval($bookable_id) . '_supplement_' . strval($supplement['id']) . '_quantity', 0); if ($s_quantity > 0) { $s_notes = read_booking_notes_from_form('bookable_' . strval($bookable_id) . '_supplement_' . strval($supplement['id']) . '_notes'); $supplements[$supplement['id']] = array('quantity' => $s_quantity, 'notes' => $s_notes); } } $request[] = array('bookable_id' => $bookable_id, 'start_day' => $start_day, 'start_month' => $start_month, 'start_year' => $start_year, 'end_day' => $end_day, 'end_month' => $end_month, 'end_year' => $end_year, 'quantity' => $quantity, 'notes' => $notes, 'supplements' => $supplements); } } return $request; }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('news'); require_css('news'); require_css('side_blocks'); require_code('obfuscate'); $url = array_key_exists('param', $map) ? $map['param'] : 'http://ocportal.com/backend.php?type=rss&mode=news&filter=16,17,18,19,20'; // http://channel9.msdn.com/Feeds/RSS/ if (strpos($url, '{') !== false) { require_code('tempcode_compiler'); $url = static_evaluate_tempcode(template_to_tempcode($url)); } $ticker = array_key_exists('ticker', $map) && $map['ticker'] == '1'; require_code('rss'); $rss = new rss($url); if (!is_null($rss->error)) { $GLOBALS['DO_NOT_CACHE_THIS'] = true; require_code('failure'); if (strpos($url, 'twitter') === false) { // Twitter is always failing ;). relay_error_notification(do_lang('ERROR_HANDLING_RSS_FEED', $url, $rss->error), false, 'error_occurred_rss'); } if (cron_installed()) { if (!$GLOBALS['FORUM_DRIVER']->is_staff(get_member())) { return new ocp_tempcode(); } } return do_template('INLINE_WIP_MESSAGE', array('MESSAGE' => htmlentities($rss->error))); } // Sorting $items = array(); foreach ($rss->gleamed_items as $item) { if (!array_key_exists('clean_add_date', $item)) { $item['clean_add_date'] = time(); } $items[] = $item; } global $M_SORT_KEY; $M_SORT_KEY = 'clean_add_date'; usort($items, 'multi_sort'); $items = array_reverse($items); global $NEWS_CATS; $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); if (!array_key_exists('title', $rss->gleamed_feed)) { $rss->gleamed_feed['title'] = do_lang_tempcode('RSS_STREAM'); } if (array_key_exists('title', $map)) { $rss->gleamed_feed['title'] = $map['title']; } // Reduce what we collected about the feed to a minimum. This is very awkward, as we don't know what's here. if (array_key_exists('author', $rss->gleamed_feed)) { $__author = NULL; $_author_string = $rss->gleamed_feed['author']; if (array_key_exists('url', $rss->gleamed_feed)) { $__author = hyperlink($rss->gleamed_feed['url'], escape_html($_author_string), true); } elseif (array_key_exists('author_url', $rss->gleamed_feed)) { $__author = hyperlink($rss->gleamed_feed['author_url'], escape_html($_author_string), true); } elseif (array_key_exists('author_email', $rss->gleamed_feed)) { $__author = hyperlink(mailto_obfuscated() . obfuscate_email_address($rss->gleamed_feed['author_email']), escape_html($_author_string), true); } if (!is_null($__author)) { $_author_string = $__author->evaluate(); } $_author = do_lang_tempcode('RSS_SOURCE_FROM', $_author_string); } else { $_author = new ocp_tempcode(); } if (!array_key_exists('copyright', $rss->gleamed_feed)) { $rss->gleamed_feed['copyright'] = ''; } if (array_key_exists('copyright', $map)) { $rss->gleamed_feed['copyright'] = $map['copyright']; } // Now for the actual stream contents $max = array_key_exists('max_entries', $map) ? intval($map['max_entries']) : 5; $content = new ocp_tempcode(); foreach ($items as $i => $item) { if ($i >= $max) { break; } if (array_key_exists('full_url', $item)) { $full_url = $item['full_url']; } elseif (array_key_exists('guid', $item)) { $full_url = $item['guid']; } elseif (array_key_exists('comment_url', $item)) { $full_url = $item['comment_url']; } else { $full_url = ''; } $_title = $item['title']; $_title = array_key_exists('title', $item) ? $item['title'] : ''; $date = array_key_exists('clean_add_date', $item) ? get_timezoned_date($item['clean_add_date']) : (array_key_exists('add_date', $item) ? $item['add_date'] : ''); $content->attach(do_template('BLOCK_SIDE_RSS_SUMMARY', array('_GUID' => '18f6d1ccfe980cc01bbdd2ee178c2410', 'TICKER' => $ticker, 'FEED_URL' => $url, 'FULL_URL' => $full_url, 'NEWS_TITLE' => $_title, 'DATE' => $date, 'DATE_RAW' => array_key_exists('clean_add_date', $item) ? strval($item['clean_add_date']) : '', 'SUMMARY' => array_key_exists('news', $item) ? $item['news'] : (array_key_exists('news_article', $item) ? $item['news_article'] : '')))); } return do_template('BLOCK_SIDE_RSS', array('_GUID' => 'fe3319e942d75fedb83e4cf80f80e19f', 'TICKER' => $ticker, 'FEED_URL' => $url, 'TITLE' => $rss->gleamed_feed['title'], 'CONTENT' => $content)); }
/** * Standard modular run function for rendering a search result. * * @param array The data row stored when we retrieved the result * @return tempcode The output */ function render($myrow) { global $NEWS_CATS; if (!isset($NEWS_CATS)) { $NEWS_CATS = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('nc_owner' => NULL)); $NEWS_CATS = list_to_map('id', $NEWS_CATS); } $id = $myrow['id']; $date = get_timezoned_date($myrow['date_and_time']); $author_url = addon_installed('authors') ? build_url(array('page' => 'authors', 'type' => 'misc', 'id' => $myrow['author']), get_module_zone('authors')) : new ocp_tempcode(); $author = $myrow['author']; $news_title = get_translated_tempcode($myrow['title']); $news = get_translated_tempcode($myrow['news']); if ($news->is_empty()) { $news = get_translated_tempcode($myrow['news_article']); $truncate = true; } else { $truncate = false; } $tmp = array('page' => 'news', 'type' => 'view', 'id' => $id); $full_url = build_url($tmp, get_module_zone('news')); if (!array_key_exists($myrow['news_category'], $NEWS_CATS)) { $_news_cats = $GLOBALS['SITE_DB']->query_select('news_categories', array('*'), array('id' => $myrow['news_category']), '', 1); if (array_key_exists(0, $_news_cats)) { $NEWS_CATS[$myrow['news_category']] = $_news_cats[0]; } } if (!array_key_exists($myrow['news_category'], $NEWS_CATS) || !array_key_exists('nc_title', $NEWS_CATS[$myrow['news_category']])) { $myrow['news_category'] = db_get_first_id(); } $img = find_theme_image($NEWS_CATS[$myrow['news_category']]['nc_img']); if (is_null($img)) { $img = ''; } if ($myrow['news_image'] != '') { $img = $myrow['news_image']; if (url_is_local($img)) { $img = get_base_url() . '/' . $img; } } $category = get_translated_text($NEWS_CATS[$myrow['news_category']]['nc_title']); $seo_bits = seo_meta_get_for('news', strval($id)); $map = array('ID' => strval($id), 'TAGS' => get_loaded_tags('news', explode(',', $seo_bits[0])), 'TRUNCATE' => $truncate, 'BLOG' => false, 'SUBMITTER' => strval($myrow['submitter']), 'CATEGORY' => $category, 'IMG' => $img, 'DATE' => $date, 'DATE_RAW' => strval($myrow['date_and_time']), 'NEWS_TITLE' => $news_title, 'AUTHOR' => $author, 'AUTHOR_URL' => $author_url, 'NEWS' => $news, 'FULL_URL' => $full_url); $tpl = do_template('NEWS_PIECE_SUMMARY', $map); return put_in_standard_box($tpl, do_lang_tempcode('NEWS_ARTICLE')); }
/** * Standard modular render function for profile tabs edit 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 tuple: The tab title, the tab body text (may be blank), the tab fields, extra Javascript (may be blank) the suggested tab order, hidden fields (optional) (NULL: if $leave_to_ajax_if_possible was set) */ function render_tab($member_id_of, $member_id_viewing, $leave_to_ajax_if_possible = false) { $order = 0; // Actualiser if (post_param('submitting_settings_tab', NULL) !== NULL) { require_code('ocf_members_action2'); $is_ldap = ocf_is_ldap_member($member_id_of); $is_httpauth = ocf_is_httpauth_member($member_id_of); $is_remote = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_password_compat_scheme') == 'remote'; if ($is_ldap || $is_httpauth || $is_remote || $member_id_of != $member_id_viewing && !has_specific_permission($member_id_viewing, 'assume_any_member')) { $password = NULL; } else { $password = post_param('edit_password'); if ($password == '') { $password = NULL; } else { $password_confirm = trim(post_param('password_confirm')); if ($password != $password_confirm) { warn_exit(make_string_tempcode(escape_html(do_lang('PASSWORD_MISMATCH')))); } } } $custom_fields = ocf_get_all_custom_fields_match($GLOBALS['FORUM_DRIVER']->get_members_groups($member_id_of), $member_id_of != $member_id_viewing && !has_specific_permission($member_id_viewing, 'view_any_profile_field') ? 1 : NULL, $member_id_of != $member_id_viewing ? NULL : 1, $member_id_of != $member_id_viewing ? NULL : 1); $actual_custom_fields = ocf_read_in_custom_fields($custom_fields, $member_id_of); $pt_allow = array_key_exists('pt_allow', $_POST) ? implode(',', $_POST['pt_allow']) : ''; $tmp_groups = $GLOBALS['OCF_DRIVER']->get_usergroup_list(true, true); $all_pt_allow = ''; foreach (array_keys($tmp_groups) as $key) { if ($key != db_get_first_id()) { if ($all_pt_allow != '') { $all_pt_allow .= ','; } $all_pt_allow .= strval($key); } } if ($pt_allow == $all_pt_allow) { $pt_allow = '*'; } $pt_rules_text = post_param('pt_rules_text', NULL); if (has_specific_permission($member_id_viewing, 'member_maintenance')) { $validated = post_param_integer('validated', 0); $primary_group = $is_ldap || !has_specific_permission($member_id_viewing, 'assume_any_member') ? NULL : post_param_integer('primary_group', NULL); $is_perm_banned = post_param_integer('is_perm_banned', 0); $old_is_perm_banned = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_is_perm_banned'); if ($old_is_perm_banned != $is_perm_banned) { if ($is_perm_banned == 1) { ocf_ban_member($member_id_of); } else { ocf_unban_member($member_id_of); } } $highlighted_name = post_param_integer('highlighted_name', 0); if (has_specific_permission($member_id_viewing, 'probate_members')) { $on_probation_until = get_input_date('on_probation_until'); $current__on_probation_until = $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id_of, 'm_on_probation_until'); if ((is_null($on_probation_until) || $on_probation_until <= time()) && $current__on_probation_until > time()) { log_it('STOP_PROBATION', strval($member_id_of), $GLOBALS['FORUM_DRIVER']->get_username($member_id_of)); } elseif (!is_null($on_probation_until) && $on_probation_until > time() && $current__on_probation_until <= time()) { log_it('START_PROBATION', strval($member_id_of), $GLOBALS['FORUM_DRIVER']->get_username($member_id_of)); } elseif (!is_null($on_probation_until) && $current__on_probation_until > $on_probation_until && $on_probation_until > time() && $current__on_probation_until > time()) { log_it('REDUCE_PROBATION', strval($member_id_of), $GLOBALS['FORUM_DRIVER']->get_username($member_id_of)); } elseif (!is_null($on_probation_until) && $current__on_probation_until < $on_probation_until && $on_probation_until > time() && $current__on_probation_until > time()) { log_it('EXTEND_PROBATION', strval($member_id_of), $GLOBALS['FORUM_DRIVER']->get_username($member_id_of)); } } else { $on_probation_until = NULL; } } else { $validated = NULL; $primary_group = NULL; $highlighted_name = NULL; $on_probation_until = NULL; } if (has_actual_page_access($member_id_viewing, 'admin_ocf_join') || has_specific_permission($member_id_of, 'rename_self')) { $username = $is_ldap || $is_remote ? NULL : post_param('edit_username', NULL); } else { $username = NULL; } $email = post_param('email_address', NULL); if (!is_null($email)) { $email = trim($email); } $theme = post_param('theme', NULL); if ($is_remote) { $preview_posts = NULL; $zone_wide = NULL; $auto_monitor_contrib_content = NULL; $views_signatures = NULL; $timezone = NULL; } else { $preview_posts = post_param_integer('preview_posts', 0); $zone_wide = post_param_integer('zone_wide', 0); $auto_monitor_contrib_content = NULL; //post_param_integer('auto_monitor_contrib_content',0); Moved to notifications tab $views_signatures = post_param_integer('views_signatures', 0); $timezone = post_param('timezone', get_site_timezone()); } ocf_edit_member($member_id_of, $email, $preview_posts, post_param_integer('dob_day', -1), post_param_integer('dob_month', -1), post_param_integer('dob_year', -1), $timezone, $primary_group, $actual_custom_fields, $theme, post_param_integer('reveal_age', 0), $views_signatures, $auto_monitor_contrib_content, post_param('language', NULL), post_param_integer('allow_emails', 0), post_param_integer('allow_emails_from_staff', 0), $validated, $username, $password, $zone_wide, $highlighted_name, $pt_allow, $pt_rules_text, $on_probation_until); if (!array_key_exists('secondary_groups', $_POST)) { $_POST['secondary_groups'] = array(); } require_code('ocf_groups_action2'); $members_groups = $GLOBALS['OCF_DRIVER']->get_members_groups($member_id_of); $group_count = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)'); $groups = list_to_map('id', $GLOBALS['FORUM_DB']->query_select('f_groups', array('*'), $group_count > 200 ? array('g_is_private_club' => 0) : NULL)); foreach ($_POST['secondary_groups'] as $group_id) { $group = $groups[intval($group_id)]; if ($group['g_hidden'] == 1 && !in_array($group['id'], $members_groups) && !has_specific_permission($member_id_viewing, 'see_hidden_groups')) { continue; } if (!in_array($group['id'], $members_groups) && (has_specific_permission($member_id_viewing, 'assume_any_member') || $group['g_open_membership'] == 1)) { ocf_add_member_to_group($member_id_of, $group['id']); } } foreach ($members_groups as $group_id) { if (!in_array(strval($group_id), $_POST['secondary_groups'])) { ocf_member_leave_group($group_id, $member_id_of); } } $GLOBALS['FORUM_DB']->query('DELETE FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_member_known_login_ips WHERE i_member_id=' . strval($member_id_of) . ' AND ' . db_string_not_equal_to('i_val_code', '')); // So any re-confirms can happen if (addon_installed('awards')) { require_code('awards'); handle_award_setting('member', strval($member_id_of)); } attach_message(do_lang_tempcode('SUCCESS_SAVE'), 'inform'); } if ($leave_to_ajax_if_possible) { return NULL; } // UI $title = do_lang_tempcode('SETTINGS'); $myrow = $GLOBALS['FORUM_DRIVER']->get_member_row($member_id_of); if (is_null($myrow)) { warn_exit(do_lang_tempcode('USER_NO_EXIST')); } require_code('ocf_members_action2'); list($fields, $hidden) = ocf_get_member_fields_settings(false, $member_id_of, NULL, $myrow['m_email_address'], $myrow['m_preview_posts'], $myrow['m_dob_day'], $myrow['m_dob_month'], $myrow['m_dob_year'], get_users_timezone($member_id_of), $myrow['m_theme'], $myrow['m_reveal_age'], $myrow['m_views_signatures'], $myrow['m_auto_monitor_contrib_content'], $myrow['m_language'], $myrow['m_allow_emails'], $myrow['m_allow_emails_from_staff'], $myrow['m_validated'], $myrow['m_primary_group'], $myrow['m_username'], $myrow['m_is_perm_banned'], '', $myrow['m_zone_wide'], $myrow['m_highlighted_name'], $myrow['m_pt_allow'], get_translated_text($myrow['m_pt_rules_text'], $GLOBALS['FORUM_DB']), $myrow['m_on_probation_until']); // Awards? if (addon_installed('awards')) { require_code('awards'); $fields->attach(get_award_fields('member', strval($member_id_of))); } $redirect = get_param('redirect', NULL); if (!is_null($redirect)) { $hidden->attach(form_input_hidden('redirect', $redirect)); } $hidden->attach(form_input_hidden('submitting_settings_tab', '1')); $javascript = "\n\t\t\tvar form=document.getElementById('email_address').form;\n\t\t\tform.prior_profile_edit_submit=form.onsubmit;\n\t\t\tform.onsubmit=function()\n\t\t\t\t{\n\t\t\t\t\tif (typeof form.elements['edit_password']!='undefined')\n\t\t\t\t\t{\n\t\t\t\t\t\tif ((form.elements['password_confirm']) && (form.elements['password_confirm'].value!=form.elements['edit_password'].value))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\twindow.fauxmodal_alert('" . php_addslashes(do_lang('PASSWORD_MISMATCH')) . "');\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (typeof form.prior_profile_edit_submit!='undefined' && form.prior_profile_edit_submit) return form.prior_profile_edit_submit();\n\t\t\t\t\treturn true;\n\t\t\t\t};\n\t\t"; $text = ''; return array($title, $fields, $text, $javascript, $order, $hidden); }
/** * Script to handle XML DB/MySQL chain synching. */ function xml_dump_script() { // Run checks and set up chain DB if (get_db_type() != 'xml') { warn_exit('It makes no sense to run this script if you are not running the XML database driver.'); } global $SITE_INFO; if (array_key_exists('db_chain_type', $SITE_INFO)) { require_code('database/' . $SITE_INFO['db_chain_type']); $chain_db = new database_driver($SITE_INFO['db_chain'], $SITE_INFO['db_chain_host'], $SITE_INFO['db_chain_user'], $SITE_INFO['db_chain_password'], get_table_prefix(), false, object_factory('Database_Static_' . $SITE_INFO['db_chain_type'])); } else { warn_exit('It makes no sense to run this script if you have not set up the following config options in info.php: db_chain_type, db_chain_host, db_chain_user, db_chain_password, db_chain'); } $chain_connection =& $chain_db->connection_write; if (count($chain_connection) > 4) { $chain_connection = call_user_func_array(array($chain_db->static_ob, 'db_get_connection'), $chain_connection); _general_db_init(); } if (function_exists('set_time_limit')) { @set_time_limit(0); } $GLOBALS['DEBUG_MODE'] = false; $GLOBALS['SEMI_DEBUG_MODE'] = false; @ini_set('ocproducts.xss_detect', '0'); if (strtolower(ocp_srv('REQUEST_METHOD')) == 'get') { $from = get_param('from', NULL); $skip = get_param('skip', NULL); $only = get_param('only', NULL); echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>XML/MySQL DB syncher</title> </head> <body> '; echo '<p>Select the tables to sync below. Tables have been auto-ticked based on what seems to need re-synching.</p>'; $keep = symbol_tempcode('KEEP', array('1')); echo '<form title="Choose tables" method="post" action="' . escape_html(find_script('xml_db_import') . $keep->evaluate()) . '">'; $tables = array_keys(find_all_tables($GLOBALS['SITE_DB'])); $mysql_status = list_to_map('Name', $chain_db->query('SHOW TABLE STATUS')); $mysql_tables = array_keys($mysql_status); foreach ($tables as $table_name) { $default_selected = (!is_null($from) && $table_name >= $from || !is_null($only) && in_array($table_name, explode(',', $only))) && (!is_null($skip) || !in_array($table_name, explode(',', $skip))); $missing = !in_array(get_table_prefix() . $table_name, $mysql_tables); $count_mismatch = !$missing && $chain_db->query_value($table_name, 'COUNT(*)') != $GLOBALS['SITE_DB']->query_value($table_name, 'COUNT(*)'); $date_mismatch = false; if (!$missing && !$count_mismatch) { $last_m_time = NULL; $path = get_custom_file_base() . '/uploads/website_specific/' . get_db_site() . '/' . get_table_prefix() . $table_name; $dh = @opendir($path); if ($dh !== false) { while (($f = readdir($dh)) !== false) { if (substr($f, -4) == '.dat' || substr($f, -4) == '.xml') { $last_m_time = @max($last_m_time, filemtime($path . '/' . $f)); } // @ because of the 255 read filepath limit on Windows } closedir($dh); } if (!is_null($last_m_time)) { $mysql_time = strtotime($mysql_status[get_table_prefix() . $table_name]['Update_time']); $date_mismatch = $mysql_time < $last_m_time; // We can't do "!=" as last m-time for MySQL could well by the last sync time } } $needs_doing = $count_mismatch || $date_mismatch || $missing || $default_selected; echo ' <div style="width: 500px"> <span style="float: right; font-style: italic"> ' . ($missing ? '[table is missing]' : '') . ' ' . ($count_mismatch ? '[different record-counts]' : '') . ' ' . ($date_mismatch ? '[different last-modified-time]' : '') . ' </span> <input ' . ($needs_doing ? 'checked="checked" ' : '') . 'type="checkbox" name="table_' . htmlentities($table_name) . '" id="table_' . htmlentities($table_name) . '" value="1" /> <label for="table_' . htmlentities($table_name) . '">' . htmlentities($table_name) . '</label> </div> '; } echo '<p><input type="submit" value="Sync" /> [<a href="#" onclick="var form=document.getElementsByTagName(\'form\')[0]; for (var i=0;i<form.elements.length;i++) if (form.elements[i].checked) form.elements[i].checked=false; return false;">un-tick all</a>]</p>'; echo '</form>'; echo ' </body> </html> '; exit; } // Actualiser $from = NULL; $skip = NULL; $only = ''; foreach (array_keys($_POST) as $key) { if (substr($key, 0, 6) == 'table_') { if ($only != '') { $only .= ','; } $only .= substr($key, 6); } } if ($only == '') { $only = NULL; } @header('Content-type: text/plain'); @ob_end_clean(); $sql = get_sql_dump(true, true, $from, is_null($skip) ? array() : explode(',', $skip), is_null($only) ? NULL : explode(',', $only)); $cnt = count($sql); foreach ($sql as $i => $s) { print 'Executing query ' . strval($i + 1) . '/' . strval($cnt) . ' ... ' . $s . "\n\n"; flush(); $fail_ok = substr($s, 0, 5) == 'ALTER'; $chain_db->static_ob->db_query($s, $chain_connection, NULL, NULL, $fail_ok, false); } print '!!Done!!'; }
/** * Load full details for posts (we had not done so far to preserve memory). * * @param array Posts to load * @return array Upgraded posts */ function _grab_full_post_details($posts) { $id_list = array(); foreach ($posts as $p) { if (!isset($p['post'])) { $id_list[] = $p['id']; } } $posts_extended = list_to_map('id', $GLOBALS['FORUM_DRIVER']->get_post_remaining_details($this->topic_id, $id_list)); foreach ($posts as $i => $p) { if (isset($posts_extended[$p['id']])) { $posts[$i] += $posts_extended[$p['id']]; } } return $posts; }
/** * Standard modular run function. * * @param array A map of parameters. * @return tempcode The result of execution. */ function run($map) { require_lang('awards'); require_code('awards'); if (array_key_exists('param', $map)) { $type_id = $map['param']; } else { if (addon_installed('downloads')) { $type_id = 'download'; } else { $hooks = find_all_hooks('systems', 'awards'); $type_id = key($hooks); } } $mode = array_key_exists('mode', $map) ? $map['mode'] : 'recent'; // recent|top|random|all $filter = array_key_exists('filter', $map) ? $map['filter'] : ''; $filter_b = array_key_exists('filter_b', $map) ? $map['filter_b'] : ''; $zone = array_key_exists('zone', $map) ? $map['zone'] : '_SEARCH'; $efficient = (array_key_exists('efficient', $map) ? $map['efficient'] : '1') == '1'; $title = array_key_exists('title', $map) ? $map['title'] : ''; $max = array_key_exists('max', $map) ? intval($map['max']) : 10; $days = array_key_exists('days', $map) && $map['days'] != '' ? intval($map['days']) : NULL; $lifetime = array_key_exists('lifetime', $map) && $map['lifetime'] != '' ? intval($map['lifetime']) : NULL; $pinned = array_key_exists('pinned', $map) && $map['pinned'] != '' ? explode(',', $map['pinned']) : array(); if (!file_exists(get_file_base() . '/sources/hooks/systems/awards/' . filter_naughty_harsh($type_id) . '.php') && !file_exists(get_file_base() . '/sources_custom/hooks/systems/awards/' . filter_naughty_harsh($type_id) . '.php')) { return paragraph(do_lang_tempcode('NO_SUCH_CONTENT_TYPE', $type_id)); } require_code('hooks/systems/awards/' . filter_naughty_harsh($type_id), true); $object = object_factory('Hook_awards_' . $type_id); $info = $object->info($filter_b == '' ? NULL : $filter_b); if (is_null($info)) { warn_exit(do_lang_tempcode('IMPOSSIBLE_TYPE_USED')); } $submit_url = $info['add_url']; if (is_object($submit_url)) { $submit_url = $submit_url->evaluate(); } if (!has_actual_page_access(NULL, $info['cms_page'], NULL, NULL)) { $submit_url = ''; } // Get entries if (is_array($info['category_field'])) { $category_field_access = $info['category_field'][0]; $category_field_filter = $info['category_field'][1]; } else { $category_field_access = $info['category_field']; $category_field_filter = $info['category_field']; } if (array_key_exists('category_type', $info)) { if (is_array($info['category_type'])) { $category_type_access = $info['category_type'][0]; $category_type_filter = $info['category_type'][1]; } else { $category_type_access = $info['category_type']; $category_type_filter = $info['category_type']; } } else { $category_type_access = mixed(); $category_type_filter = mixed(); } $where = ''; $query = 'FROM ' . get_table_prefix() . $info['table'] . ' r'; if (!$GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) && !$efficient) { $_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(get_member(), false, true); $groups = ''; foreach ($_groups as $group) { if ($groups != '') { $groups .= ' OR '; } $groups .= 'a.group_id=' . strval((int) $group); } if (!is_null($category_field_access)) { if ($category_type_access === '!') { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_page_access a ON (r.' . $category_field_filter . '=a.page_name AND r.' . $category_field_access . '=a.zone_name AND (' . $groups . '))'; $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_zone_access a2 ON (r.' . $category_field_access . '=a2.zone_name)'; } else { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_category_access a ON (' . db_string_equal_to('a.module_the_name', $category_type_access) . ' AND r.' . $category_field_access . '=a.category_name)'; } } if (!is_null($category_field_filter) && $category_field_filter != $category_field_access && $info['category_type'] !== '!') { $query .= ' LEFT JOIN ' . get_table_prefix() . 'group_category_access a2 ON (' . db_string_equal_to('a.module_the_name', $category_type_filter) . ' AND r.' . $category_field_filter . '=a2.category_name)'; } if (!is_null($category_field_access)) { if ($where != '') { $where .= ' AND '; } if ($info['category_type'] === '!') { $where .= '(a.group_id IS NULL) AND (' . str_replace('a.', 'a2.', $groups) . ') AND (a2.group_id IS NOT NULL)'; } else { $where .= '(' . $groups . ') AND (a.group_id IS NOT NULL)'; } } if (!is_null($category_field_filter) && $category_field_filter != $category_field_access && $info['category_type'] !== '!') { if ($where != '') { $where .= ' AND '; } $where .= '(' . str_replace('a.group_id', 'a2.group_id', $groups) . ') AND (a2.group_id IS NOT NULL)'; } if (array_key_exists('where', $info)) { if ($where != '') { $where .= ' AND '; } $where .= $info['where']; } } if (array_key_exists('validated_field', $info) && $info['validated_field'] != '') { if ($where != '') { $where .= ' AND '; } $where .= 'r.' . $info['validated_field'] . '=1'; } $x1 = ''; $x2 = ''; if ($filter != '' && !is_null($category_field_filter)) { $x1 = $this->build_filter($filter, $info, 'r.' . $category_field_filter); } if ($filter_b != '' && !is_null($category_field_access)) { $x2 = $this->build_filter($filter_b, $info, 'r.' . $category_field_access); } if (!is_null($days)) { if ($where != '') { $where .= ' AND '; } $where .= $info['date_field'] . '>=' . strval(time() - 60 * 60 * 24 * $days); } if (is_array($info['id_field'])) { $lifetime = NULL; } // Cannot join on this if (!is_null($lifetime)) { $block_cache_id = md5(serialize($map)); $query .= ' LEFT JOIN ' . $info['connection']->get_table_prefix() . 'feature_lifetime_monitor m ON m.content_id=r.' . $info['id_field'] . ' AND ' . db_string_equal_to('m.block_cache_id', $block_cache_id); if ($where != '') { $where .= ' AND '; } $where .= '(m.run_period IS NULL OR m.run_period<' . strval($lifetime * 60 * 60 * 24) . ')'; } if (array_key_exists('extra_select_sql', $info)) { $extra_select_sql = $info['extra_select_sql']; } else { $extra_select_sql = ''; } if (array_key_exists('extra_table_sql', $info)) { $query .= $info['extra_table_sql']; } if (array_key_exists('extra_where_sql', $info)) { if ($where != '') { $where .= ' AND '; } $where .= $info['extra_where_sql']; } if ($mode == 'all') { if (array_key_exists('title_field', $info) && strpos($info['title_field'], ':') === false) { $query .= ' LEFT JOIN ' . get_table_prefix() . 'translate t ON t.id=r.' . $info['title_field'] . ' AND ' . db_string_equal_to('t.language', user_lang()); } } if ($where . $x1 . $x2 != '') { if ($where == '') { $where = '1=1'; } $query .= ' WHERE ' . $where; if ($x1 != '') { $query .= ' AND (' . $x1 . ')'; } if ($x2 != '') { $query .= ' AND (' . $x2 . ')'; } } if ($mode == 'top' && array_key_exists('feedback_type', $info) && is_null($info['feedback_type'])) { $mode = 'all'; } switch ($mode) { case 'random': $cnt = $info['connection']->query_value_null_ok_full('SELECT COUNT(*) as cnt ' . $query); $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query, $max, mt_rand(0, max(0, $cnt - $max))); break; case 'recent': if (array_key_exists('date_field', $info) && !is_null($info['date_field'])) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['date_field'] . ' DESC', $max, NULL); break; } case 'views': if (array_key_exists('views_field', $info) && !is_null($info['views_field'])) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['views_field'] . ' DESC', $max, NULL); break; } case 'top': if (array_key_exists('feedback_type', $info) && !is_null($info['feedback_type'])) { $select_rating = ',(SELECT AVG(rating) FROM ' . get_table_prefix() . 'rating WHERE ' . db_string_equal_to('rating_for_type', $info['feedback_type']) . ' AND rating_for_id=' . $info['id_field'] . ') AS compound_rating'; $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . $select_rating . ' ' . $query, $max, NULL, 'ORDER BY compound_rating DESC'); break; } case 'all': if (array_key_exists('title_field', $info) && strpos($info['title_field'], ':') === false) { if ($info['title_field_dereference']) { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY t.text_original ASC', $max, NULL); } else { $rows = $info['connection']->query('SELECT r.*' . $extra_select_sql . ' ' . $query . ' ORDER BY r.' . $info['title_field'] . ' ASC', $max, NULL); } } else { $sql = 'SELECT r.*' . $extra_select_sql . ' ' . $query; if (is_string($info['id_field'])) { $sql .= ' ORDER BY r.' . $info['id_field'] . ' ASC'; } else { $sql .= ' ORDER BY '; foreach ($info['id_field'] as $i => $id_field) { if ($i != 0) { $sql .= ','; } $sql .= 'r.' . $id_field . ' ASC'; } } $rows = $info['connection']->query($sql, $max, NULL); } break; default: $rows = array(); } $pinned_order = array(); require_code('content'); // Add in requested pinned awards foreach ($pinned as $i => $p) { $awarded_rows = $GLOBALS['SITE_DB']->query_select('award_archive', array('*'), array('a_type_id' => intval($p)), 'ORDER BY date_and_time DESC', 1); if (!array_key_exists(0, $awarded_rows)) { continue; } $awarded_row = $awarded_rows[0]; $award_content_row = content_get_row($awarded_row['content_id'], $info); if (!is_null($award_content_row) && (!isset($info['validated_field']) || $award_content_row[$info['validated_field']] != 0)) { $pinned_order[$i] = $award_content_row; } } if (count($pinned_order) > 0) { if (count($rows) > 0) { //Bit inefficient I know, but it'll mean less rewriting of the later code -- Paul $old_rows = $rows; $rows = array(); $total_count = count($old_rows) + count($pinned_order); $used_ids = array(); /* * NOTE: If anything is pinned as the first element, it can't just be passed on directly because * next() will miss the first element of the $old rows array. It is necessary to assess the first * element of the array so if a pinned element must be first, tacking it on to the start of the * array then using the array's first element under either circumstance is the simplest answer. */ if (array_key_exists(0, $pinned_order)) { array_unshift($old_rows, $pinned_order[0]); } reset($old_rows); //Why is there no 'get number _then_ goto next element' function? $temp_row = current($old_rows); $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count = 1; //If duplicates exist, position in the new array needs to be maintained. //Carry on as it should be for ($t_count = 1; $t_count < $total_count; $t_count++) { if (array_key_exists($n_count, $pinned_order)) { if (!in_array($pinned_order[$n_count][$info['id_field']], $used_ids)) { $rows[] = $pinned_order[$n_count]; $used_ids[] = $pinned_order[$n_count][$info['id_field']]; $n_count++; } else { $temp_row = next($old_rows); if (!in_array($temp_row[$info['id_field']], $used_ids)) { $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count++; } } } else { $temp_row = next($old_rows); if (!in_array($temp_row[$info['id_field']], $used_ids)) { $rows[] = $temp_row; $used_ids[] = $temp_row[$info['id_field']]; $n_count++; } } } } else { switch ($mode) { case 'recent': if (array_key_exists('date_field', $info)) { global $M_SORT_KEY; $M_SORT_KEY = $info['date_field']; usort($pinned_order, 'multi_sort'); $rows = array_reverse($pinned_order); } break; case 'views': if (array_key_exists('views_field', $info)) { global $M_SORT_KEY; $M_SORT_KEY = $info['views_field']; usort($pinned_order, 'multi_sort'); $rows = array_reverse($pinned_order); } break; } } } // Sort out run periods if (!is_null($lifetime)) { $lifetime_monitor = list_to_map('content_id', $GLOBALS['SITE_DB']->query_select('feature_lifetime_monitor', array('content_id', 'run_period', 'last_update'), array('block_cache_id' => $block_cache_id, 'running_now' => 1))); } // Render $archive_url = $info['archive_url']; $view_url = array_key_exists('view_url', $info) ? $info['view_url'] : new ocp_tempcode(); $done_already = array(); // We need to keep track, in case those pulled up via awards would also come up naturally $rendered_content = array(); $content_data = array(); foreach ($rows as $row) { if (count($done_already) == $max) { break; } // Get content ID if (is_array($info['id_field'])) { $content_id = ''; foreach ($info['id_field'] as $f) { if ($content_id != '') { $content_id .= ':'; } $x = $row[$f]; if (!is_string($x)) { $x = strval($x); } $content_id .= $x; } } else { $content_id = $row[$info['id_field']]; if (!is_string($content_id)) { $content_id = strval($content_id); } } if (array_key_exists($content_id, $done_already)) { continue; } $done_already[$content_id] = 1; // Lifetime managing if (!is_null($lifetime)) { if (!array_key_exists($content_id, $lifetime_monitor)) { // Test to see if it is actually there in the past - we only loaded the "running now" ones for performance reasons. Any new ones coming will trigger extra queries to see if they've been used before, as a tradeoff to loading potentially 10's of thousands of rows. $lifetime_monitor += list_to_map('content_id', $GLOBALS['SITE_DB']->query_select('feature_lifetime_monitor', array('content_id', 'run_period', 'last_update'), array('block_cache_id' => $block_cache_id, 'content_id' => $content_id))); } if (array_key_exists($content_id, $lifetime_monitor)) { $GLOBALS['SITE_DB']->query_update('feature_lifetime_monitor', array('run_period' => $lifetime_monitor[$content_id]['run_period'] + (time() - $lifetime_monitor[$content_id]['last_update']), 'running_now' => 1, 'last_update' => time()), array('content_id' => $content_id, 'block_cache_id' => $block_cache_id)); unset($lifetime_monitor[$content_id]); } else { $GLOBALS['SITE_DB']->query_insert('feature_lifetime_monitor', array('content_id' => $content_id, 'block_cache_id' => $block_cache_id, 'run_period' => 0, 'running_now' => 1, 'last_update' => time())); } } // Render $rendered_content[] = $object->run($row, $zone); // Try and get a better submit url $submit_url = str_replace('%21', $content_id, $submit_url); $content_data[] = array('URL' => str_replace('%21', $content_id, $view_url->evaluate())); } // Sort out run periods of stuff gone if (!is_null($lifetime)) { foreach (array_keys($lifetime_monitor) as $content_id) { if (is_integer($content_id)) { $content_id = strval($content_id); } $GLOBALS['SITE_DB']->query_update('feature_lifetime_monitor', array('run_period' => $lifetime_monitor[$content_id]['run_period'] + (time() - $lifetime_monitor[$content_id]['last_update']), 'running_now' => 0, 'last_update' => time()), array('content_id' => $content_id, 'block_cache_id' => $block_cache_id)); } } if (array_key_exists('no_links', $map) && $map['no_links'] == '1') { $submit_url = ''; $archive_url = ''; } return do_template('BLOCK_MAIN_MULTI_CONTENT', array('TYPE' => $info['title'], 'TITLE' => $title, 'CONTENT' => $rendered_content, 'CONTENT_DATA' => $content_data, 'SUBMIT_URL' => $submit_url, 'ARCHIVE_URL' => $archive_url)); }
/** * 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); }
/** * The actualiser for importing a CSV file. * * @return tempcode The UI */ function _import_csv() { $title = get_page_title('IMPORT_MEMBER_CSV'); disable_php_memory_limit(); // Even though we split into chunks, PHP does leak memory :( $GLOBALS['HELPER_PANEL_PIC'] = 'pagepics/import_csv'; if (function_exists('set_time_limit')) { @set_time_limit(0); } require_lang('ocf'); require_code('ocf_members_action'); $default_password = post_param('default_password'); $num_added = 0; $num_edited = 0; $done = 0; $headings = $this->_get_csv_headings(); $all_cpfs = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_default', 'cf_type', 'cf_name'), NULL, 'ORDER BY cf_order'); foreach ($all_cpfs as $i => $c) { $c['text_original'] = get_translated_text($c['cf_name'], $GLOBALS['FORUM_DB']); $all_cpfs[$i] = $c; $headings[$c['text_original']] = NULL; } $_all_groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, false, true); $all_groups = array_flip($_all_groups); $all_members = collapse_2d_complexity('id', 'm_username', $GLOBALS['FORUM_DB']->query_select('f_members', array('id', 'm_username'))); $all_members_flipped = array_flip($all_members); // Import require_code('uploads'); if (is_swf_upload(true) || array_key_exists('file', $_FILES) && is_uploaded_file($_FILES['file']['tmp_name'])) { $_csv_data = array(); $fixed_contents = unixify_line_format(file_get_contents($_FILES['file']['tmp_name'])); $myfile = @fopen($_FILES['file']['tmp_name'], 'wb'); if ($myfile !== false) { fwrite($myfile, $fixed_contents); fclose($myfile); } $myfile = fopen($_FILES['file']['tmp_name'], 'rb'); $del = ','; $csv_header = fgetcsv($myfile, 102400, $del); if ($csv_header === false) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } if (count($csv_header) == 1 && strpos($csv_header[0], ';') !== false) { $del = ';'; rewind($myfile); $csv_header = fgetcsv($myfile, 102400, $del); } while (($csv_line = fgetcsv($myfile, 102400, $del)) !== false) { $line = array(); foreach ($csv_header as $i => $h) { $extracted_value = trim(unixify_line_format(array_key_exists($i, $csv_line) ? $csv_line[$i] : '')); if (strpos($h, ':') !== false) { $parts = explode(':', $h, 2); $h = trim($parts[0]); if ($extracted_value != '') { $extracted_value = $parts[1] . ': ' . $extracted_value; } } if (array_key_exists($h, $line)) { if ($extracted_value != '') { $line[$h] .= ($line[$h] != '' ? chr(10) : '') . $extracted_value; } } else { $line[$h] = $extracted_value; } } if (!array_key_exists('Username', $line) || $line['Username'] == '') { // Can we auto-generate it $forename = NULL; if (array_key_exists('Forenames', $line)) { $forename = $line['Forenames']; } if (array_key_exists('Forename', $line)) { $forename = $line['Forename']; } if (array_key_exists('First name', $line)) { $forename = $line['First name']; } if (array_key_exists('First Name', $line)) { $forename = $line['First Name']; } $surname = NULL; if (array_key_exists('Surname', $line)) { $surname = $line['Surname']; } if (array_key_exists('Last name', $line)) { $surname = $line['Last name']; } if (array_key_exists('Last Name', $line)) { $surname = $line['Last Name']; } if (!is_null($forename) || !is_null($surname)) { // Can we get a year too? $year = ''; foreach ($line as $tl_key => $tl_val) { if (substr($tl_key, 0, 4) == 'Year') { $year = $tl_val; break; } } if (strlen($year) == 4 && (substr($year, 0, 2) == '19' || substr($year, 0, 2) == '20')) { $year = substr($year, 2); } // Tidy up forename $_forename = preg_replace('#[^\\w]#', '', preg_replace('#[\\s\\.].*#', '', $forename)); // Tidy up surname (last bit strips like 'OBE') $_surname = preg_replace('#[^\\w]#', '', trim(preg_replace('#\\s*[A-Z\\d][A-Z\\d]+#', '', $surname))); // Put it together $line['Username'] = ucfirst($_forename) . ucfirst($_surname) . $year; } else { continue; // This field is needed } } $username = $line['Username']; $linked_id = NULL; if (array_key_exists('ID', $line)) { $linked_id = $line['ID'] != '' && array_key_exists(intval($line['ID']), $all_members) ? intval($line['ID']) : NULL; } if (is_null($linked_id)) { $linked_id = array_key_exists($username, $all_members_flipped) ? $all_members_flipped[$username] : NULL; } $new_member = is_null($linked_id); $email_address_key = 'E-mail address'; if (array_key_exists('Email address', $line)) { $email_address_key = 'Email address'; } if (array_key_exists('E-mail Address', $line)) { $email_address_key = 'E-mail Address'; } if (array_key_exists('Email Address', $line)) { $email_address_key = 'Email Address'; } if (array_key_exists('E-mail', $line)) { $email_address_key = 'E-mail'; } if (array_key_exists('Email', $line)) { $email_address_key = 'Email'; } $dob_key = 'Date of birth'; if (array_key_exists('Date Of Birth', $line)) { $dob_key = 'Date Of Birth'; } if (array_key_exists('DOB', $line)) { $dob_key = 'DOB'; } // If it's an edited member, add in their existing CSV details, so that if it's a partial merge it'll still work without deleting anything! if (!$new_member) { $member_groups = $GLOBALS['FORUM_DB']->query_select('f_group_members', array('gm_member_id', 'gm_group_id'), array('gm_validated' => 1, 'gm_member_id' => $linked_id)); $member_cpfs = list_to_map('mf_member_id', $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), array('mf_member_id' => $linked_id), '', 1)); $this_record = $this->_get_csv_member_record($member_cpfs, $GLOBALS['FORUM_DRIVER']->get_member_row($linked_id), $_all_groups, $headings, $all_cpfs, $member_groups); // Remember "+" in PHP won't overwrite existing keys if (!array_key_exists($email_address_key, $line)) { unset($this_record['E-mail address']); } if (!array_key_exists($dob_key, $line)) { unset($this_record['Date of birth']); } $line += $this_record; } // Set up member row if (array_key_exists('Password', $line) && $line['Password'] != '') { $parts = explode('/', $line['Password']); $password = $parts[0]; $salt = array_key_exists(1, $parts) ? $parts[1] : NULL; $password_compatibility_scheme = array_key_exists(2, $parts) ? $parts[2] : NULL; } else { $password = NULL; $salt = NULL; $password_compatibility_scheme = NULL; } $matches = array(); if (array_key_exists($email_address_key, $line)) { $email_address = $line[$email_address_key]; } else { $email_address = NULL; } if (preg_match('#^([^\\s]*)\\s+\\(.*\\)$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (preg_match('#^.*\\s+<(.*)>$#', $email_address, $matches) != 0) { $email_address = $matches[1]; } if (array_key_exists($dob_key, $line)) { $parts = explode('/', $line[$dob_key]); $dob_day = array_key_exists(2, $parts) ? intval($parts[2]) : NULL; $dob_month = array_key_exists(1, $parts) ? intval($parts[1]) : NULL; $dob_year = array_key_exists(0, $parts) ? intval($parts[0]) : NULL; } else { $dob_day = NULL; $dob_month = NULL; $dob_year = NULL; } $validated = array_key_exists('Validated', $line) ? strtoupper($line['Validated']) == 'YES' || $line['Validated'] == '1' || strtoupper($line['Validated']) == 'Y' || strtoupper($line['Validated']) == 'ON' ? 1 : 0 : 1; if (array_key_exists('Join time', $line)) { if (strpos($line['Join time'], '-') !== false) { $parts = explode('-', $line['Join time']); } else { $parts = explode('/', $line['Join time']); } if (!array_key_exists(1, $parts)) { $parts[1] = '1'; } if (!array_key_exists(2, $parts)) { $parts[2] = '1'; } if (strlen($parts[2]) != 4) { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[2]), intval($parts[0])); // yy(yy)-mm-dd } else { $join_time = mktime(0, 0, 0, intval($parts[1]), intval($parts[0]), intval($parts[2])); // dd-mm-yyyy } if ($join_time > time()) { $join_time = time(); } // Fixes MySQL out of range error that could happen } else { $join_time = NULL; } $avatar_url = array_key_exists('Avatar', $line) ? $line['Avatar'] : ''; if (!is_null($avatar_url)) { if (substr($avatar_url, 0, strlen(get_base_url() . '/')) == get_base_url() . '/') { $avatar_url = substr($avatar_url, strlen(get_base_url() . '/')); } } $signature = array_key_exists('Signature', $line) ? $line['Signature'] : ''; $is_perm_banned = array_key_exists('Banned', $line) ? strtoupper($line['Banned']) == 'YES' || $line['Banned'] == '1' || strtoupper($line['Banned']) == 'Y' || strtoupper($line['Banned']) == 'ON' ? 1 : 0 : 0; $reveal_age = array_key_exists('Reveal age', $line) ? strtoupper($line['Reveal age']) == 'YES' || $line['Reveal age'] == '1' || strtoupper($line['Reveal age']) == 'Y' || strtoupper($line['Reveal age']) == 'ON' ? 1 : 0 : 0; $language = array_key_exists('Language', $line) ? $line['Language'] : ''; $allow_emails = array_key_exists('Accept member e-mails', $line) ? strtoupper($line['Accept member e-mails']) == 'YES' || $line['Accept member e-mails'] == '1' || strtoupper($line['Accept member e-mails']) == 'Y' || strtoupper($line['Accept member e-mails']) == 'ON' ? 1 : 0 : 0; $allow_emails_from_staff = array_key_exists('Opt-in', $line) ? strtoupper($line['Opt-in']) == 'YES' || $line['Opt-in'] == '1' || strtoupper($line['Opt-in']) == 'Y' || strtoupper($line['Opt-in']) == 'ON' ? 1 : 0 : 0; $primary_group = NULL; $groups = NULL; if (array_key_exists('Usergroup', $line)) { $parts = explode('/', $line['Usergroup']); foreach ($parts as $p) { if (!array_key_exists($p, $all_groups)) { require_code('ocf_groups_action'); $g_id = ocf_make_group($p, 0, 0, 0, ''); $all_groups[$p] = $g_id; $_group_edit_url = build_url(array('page' => 'admin_ocf_groups', 'type' => '_ed', 'id' => $g_id), get_module_zone('admin_ocf_groups')); $group_edit_url = $_group_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_GROUP_ADDED', escape_html($p), escape_html($group_edit_url)), 'inform'); } } $primary_group = $all_groups[$parts[0]]; unset($parts[0]); $groups = array(); foreach ($parts as $p) { $groups[] = $all_groups[$p]; } } $photo_url = array_key_exists('Photo', $line) ? $line['Photo'] : ''; if ($photo_url != '') { require_code('images'); $photo_thumb_url = 'uploads/ocf_photos_thumbs/' . uniqid('', true) . '.png'; convert_image($photo_url, $photo_thumb_url, -1, -1, intval(get_option('thumb_width')), false); } else { $photo_thumb_url = ''; } $custom_fields = array(); foreach ($all_cpfs as $cpf) { $custom_fields[$cpf['id']] = array_key_exists($cpf['text_original'], $line) ? $line[$cpf['text_original']] : $cpf['cf_default']; if (!array_key_exists($cpf['text_original'], $line) && $cpf['cf_type'] == 'list') { $parts = explode($custom_fields[$cpf['id']], '|'); $custom_fields[$cpf['id']] = $parts[0]; } if ($cpf['cf_type'] == 'integer') { $custom_fields[$cpf['id']] = intval($custom_fields[$cpf['id']]); } elseif ($cpf['cf_type'] == 'tick') { $custom_fields[$cpf['id']] = strtoupper($custom_fields[$cpf['id']]) == 'YES' || strtoupper($custom_fields[$cpf['id']]) == 'Y' || strtoupper($custom_fields[$cpf['id']]) == 'ON' || $custom_fields[$cpf['id']] == '1' ? 1 : 0; } elseif ($cpf['cf_type'] == 'short_text' || $cpf['cf_type'] == 'short_trans') { $custom_fields[$cpf['id']] = substr(str_replace(chr(10), ', ', str_replace(',' . chr(10), chr(10), $custom_fields[$cpf['id']])), 0, 255); } elseif ($cpf['cf_type'] == 'long_text' || $cpf['cf_type'] == 'long_trans') { //$custom_fields[$cpf['id']]=$custom_fields[$cpf['id']]; } elseif ($cpf['cf_type'] == 'float') { if (preg_match('#^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\n(\\d\\d\\d\\d)$#', $custom_fields[$cpf['id']]) != 0) { $parts = explode(chr(10), $custom_fields[$cpf['id']], 2); $month_lookup = array('Jan' => 0.1, 'Feb' => 0.2, 'Mar' => 0.3, 'Apr' => 0.4, 'May' => 0.5, 'Jun' => 0.6, 'Jul' => 0.7, 'Aug' => 0.8, 'Sep' => 0.9, 'Oct' => 0.1, 'Nov' => 0.11, 'Dec' => 0.12); $custom_fields[$cpf['id']] = floatval($parts[1]) + $month_lookup[$parts[0]]; } else { $custom_fields[$cpf['id']] = floatval($custom_fields[$cpf['id']]); } } unset($line[$cpf['text_original']]); } foreach (array_keys($headings) as $h) { unset($line[$h]); } unset($line[$email_address_key]); unset($line[$dob_key]); foreach ($line as $h => $f) { $cf_id = ocf_make_custom_field($h, 0, '', '', 0, 0, 0, 0, 'long_text'); $_cpf_edit_url = build_url(array('page' => 'admin_ocf_customprofilefields', 'type' => '_ed', 'id' => $cf_id), get_module_zone('admin_ocf_customprofilefields')); $cpf_edit_url = $_cpf_edit_url->evaluate(); attach_message(do_lang_tempcode('MEMBER_IMPORT_CPF_ADDED', escape_html($h), escape_html($cpf_edit_url)), 'inform'); $custom_fields[$cf_id] = $f; $all_cpfs[] = array('id' => $cf_id, 'cf_default' => '', 'text_original' => $h, 'cf_type' => 'short_line'); } if ($new_member) { if (is_null($password)) { $password = $default_password; } if (is_null($salt)) { $salt = ''; } if (is_null($password_compatibility_scheme)) { $password_compatibility_scheme = ''; } $linked_id = ocf_make_member($username, $password, is_null($email_address) ? '' : $email_address, $groups, $dob_day, $dob_month, $dob_year, $custom_fields, NULL, $primary_group, $validated, $join_time, NULL, '', $avatar_url, $signature, $is_perm_banned, get_option('default_preview_guests') == '1' ? 1 : 0, $reveal_age, '', $photo_url, $photo_thumb_url, 1, 1, $language, $allow_emails, $allow_emails_from_staff, '', NULL, '', false, $password_compatibility_scheme, $salt, 1, NULL, NULL, 0, '*', ''); $all_members[$linked_id] = $username; $all_members_flipped[$username] = $linked_id; $num_added++; } else { $old_username = $GLOBALS['OCF_DRIVER']->get_member_row_field($linked_id, 'm_username'); if ($old_username == $username) { $username = NULL; } ocf_edit_member($linked_id, $email_address, NULL, $dob_day, $dob_month, $dob_year, NULL, $primary_group, $custom_fields, NULL, $reveal_age, NULL, NULL, $language, $allow_emails, $allow_emails_from_staff, $validated, $username, $password, NULL, NULL, NULL, NULL, NULL, $join_time, $avatar_url, $signature, $is_perm_banned, $photo_url, $photo_thumb_url, $salt, $password_compatibility_scheme, true); $num_edited++; } $done++; } fclose($myfile); } else { warn_exit(do_lang_tempcode('IMPROPERLY_FILLED_IN_UPLOAD')); } if ($done == 0) { warn_exit(do_lang_tempcode('NO_DATA_IMPORTED')); } breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS')), array('_SEARCH:admin_ocf_join:import_csv', do_lang_tempcode('IMPORT_MEMBER_CSV')))); breadcrumb_set_self(do_lang_tempcode('DONE')); return inform_screen($title, do_lang_tempcode('NUM_MEMBERS_IMPORTED', escape_html(integer_format($num_added)), escape_html(integer_format($num_edited)))); }