/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_notifications($db, $table_prefix, $file_base) { require_code('notifications'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'subscribeforum'); foreach ($rows as $row) { if (import_check_if_imported('forum_notification', strval($row['subscribeforumid']))) { continue; } $member_id = import_id_remap_get('member', strval($row['userid']), true); if (is_null($member_id)) { continue; } $forum_id = import_id_remap_get('forum', strval($row['forumid']), true); if (is_null($forum_id)) { continue; } enable_notifications('ocf_topic', 'forum:' . strval($forum_id), $member_id); import_id_remap_put('forum_notification', strval($row['subscribeforumid']), 1); } $row_start = 0; do { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'subscribethread', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('topic_notification', strval($row['subscribethreadid']))) { continue; } $member_id = import_id_remap_get('member', strval($row['userid']), true); if (is_null($member_id)) { continue; } $topic_id = import_id_remap_get('topic', strval($row['threadid']), true); if (is_null($topic_id)) { continue; } enable_notifications('ocf_topic', strval($topic_id), $member_id); import_id_remap_put('topic_notification', strval($row['subscribethreadid']), 1); } $row_start += 200; } while (count($rows) > 0); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_notifications($db, $table_prefix, $file_base) { require_code('notifications'); $row_start = 0; $rows = array(); do { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'notifications', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('topic_notification', strval($row['topic_id']) . '-' . strval($row['user_id']))) { continue; } $member_id = import_id_remap_get('member', strval($row['user_id']), true); if (is_null($member_id)) { continue; } $topic_id = import_id_remap_get('topic', strval($row['topic_id']), true); if (is_null($topic_id)) { continue; } enable_notifications('ocf_topic', strval($topic_id), $member_id); import_id_remap_put('topic_notification', strval($row['topic_id']) . '-' . strval($row['user_id']), 1); } $row_start += 200; } while (count($rows) > 0); $row_start = 0; $rows = array(); do { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'watched_forums', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('forum_notification', strval($row['user_id']))) { continue; } $member_id = import_id_remap_get('member', strval($row['user_id']), true); if (is_null($member_id)) { continue; } $forums = explode(',', $row['forum_ids']); foreach ($forums as $forum) { $forum_id = import_id_remap_get('forum', strval($forum), true); if (is_null($forum_id)) { continue; } enable_notifications('ocf_topic', 'forum:' . strval($forum_id), $member_id); } import_id_remap_put('forum_notification', strval($row['user_id']), 1); } $row_start += 200; } while (count($rows) > 0); $row_start = 0; $rows = array(); do { $rows = $db->query('SELECT user_id,user_visited_topics FROM ' . $table_prefix . 'users', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('has_read', strval($row['user_id']))) { continue; } $member_id = import_id_remap_get('member', strval($row['user_id']), true); if (is_null($member_id)) { continue; } $details = unserialize($row['user_visited_topics']); if (is_array($details)) { foreach ($details as $topics) { if (is_array($topics)) { foreach ($topics as $topic_id => $time) { $topic_id = import_id_remap_get('topic', strval($topic_id), true); if (is_null($topic_id)) { continue; } $GLOBALS['FORUM_DB']->query_insert('f_read_logs', array('l_member_id' => $member_id, 'l_topic_id' => $topic_id, 'l_time' => $time), false, true); } } } } import_id_remap_put('has_read', strval($row['user_id']), 1); } $row_start += 200; } while (count($rows) > 0); }
/** * Enable notifications for a member on a notification type+category. * * @param ID_TEXT The notification code to use * @param ?SHORT_TEXT The category within the notification code (NULL: none) * @param ?MEMBER The member being signed up (NULL: current member) * @param ?integer Setting to use (NULL: default) */ function enable_notifications($notification_code, $notification_category, $member_id = NULL, $setting = NULL) { if (is_null($member_id)) { $member_id = get_member(); } if (is_guest($member_id)) { return; } if (is_null($setting)) { $ob = _get_notification_ob_for_code($notification_code); if (is_null($ob)) { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } $setting = $ob->get_default_auto_setting($notification_code, $notification_category); if (!_notification_setting_available($setting, $member_id)) { $setting = _find_member_statistical_notification_type($member_id); } } $db = substr($notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']; $db->query_delete('notifications_enabled', array('l_member_id' => $member_id, 'l_notification_code' => substr($notification_code, 0, 80), 'l_code_category' => is_null($notification_category) ? '' : $notification_category)); $db->query_insert('notifications_enabled', array('l_member_id' => $member_id, 'l_notification_code' => substr($notification_code, 0, 80), 'l_code_category' => is_null($notification_category) ? '' : $notification_category, 'l_setting' => $setting)); if ($notification_code == 'comment_posted' && get_forum_type() == 'ocf') { $topic_id = $GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier(get_option('comments_forum_name'), $notification_category); if (!is_null($topic_id)) { enable_notifications('ocf_topic', strval($topic_id), $member_id); } } global $NOTIFICATION_SETTING_CACHE; $NOTIFICATION_SETTING_CACHE = array(); }
/** * Add comments to the specified resource. * * @param boolean Whether this resource allows comments (if not, this function does nothing - but it's nice to move out this common logic into the shared function) * @param ID_TEXT The type (download, etc) that this commenting is for * @param ID_TEXT The ID of the type that this commenting is for * @param mixed The URL to where the commenting will pass back to (to put into the comment topic header) (URLPATH or Tempcode) * @param ?string The title to where the commenting will pass back to (to put into the comment topic header) (NULL: don't know, but not first post so not important) * @param ?string The name of the forum to use (NULL: default comment forum) * @param boolean Whether to not require a captcha * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver (hence is the last parameter). * @param boolean Whether to force allowance * @param boolean Whether to skip a success message * @param boolean Whether posts made should not be shared * @return boolean Whether a hidden post has been made */ function actualise_post_comment($allow_comments, $content_type, $content_id, $content_url, $content_title, $forum = NULL, $avoid_captcha = false, $validated = NULL, $explicit_allow = false, $no_success_message = false, $private = false) { if (!$explicit_allow) { if (get_option('is_on_comments') == '0' || !$allow_comments) { return false; } if (!has_specific_permission(get_member(), 'comment', get_page_name())) { return false; } } if (running_script('preview')) { return false; } $forum_tie = get_option('is_on_strong_forum_tie') == '1'; if (addon_installed('captcha')) { if (array_key_exists('post', $_POST) && $_POST['post'] != '' && !$avoid_captcha) { require_code('captcha'); enforce_captcha(); } } $post_title = post_param('title', NULL); if (is_null($post_title) && !$forum_tie) { return false; } $post = post_param('post', NULL); if ($post == do_lang('POST_WARNING')) { $post = ''; } if ($post == do_lang('THREADED_REPLY_NOTICE', do_lang('POST_WARNING'))) { $post = ''; } if ($post == '' && $post_title !== '') { $post = $post_title; $post_title = ''; } if ($post === '') { warn_exit(do_lang_tempcode('NO_PARAMETER_SENT', 'post')); } if (is_null($post)) { $post = ''; } $email = trim(post_param('email', '')); if ($email != '') { $body = '> ' . str_replace(chr(10), chr(10) . '> ', $post); if (substr($body, -2) == '> ') { $body = substr($body, 0, strlen($body) - 2); } if (get_page_name() != 'tickets') { $post .= '[staff_note]'; } $post .= "\n\n" . '[email subject="Re: ' . comcode_escape($post_title) . ' [' . get_site_name() . ']" body="' . comcode_escape($body) . '"]' . $email . '[/email]' . "\n\n"; if (get_page_name() != 'tickets') { $post .= '[/staff_note]'; } } $content_title = strip_comcode($content_title); if (is_null($forum)) { $forum = get_option('comments_forum_name'); } $content_url_flat = is_object($content_url) ? $content_url->evaluate() : $content_url; $_parent_id = post_param('parent_id', ''); $parent_id = $_parent_id == '' ? NULL : intval($_parent_id); $poster_name_if_guest = post_param('poster_name_if_guest', ''); list($topic_id, $is_hidden) = $GLOBALS['FORUM_DRIVER']->make_post_forum_topic($forum, $content_type . '_' . $content_id, get_member(), $post_title, $post, $content_title, do_lang('COMMENT'), $content_url_flat, NULL, NULL, $validated, $explicit_allow ? 1 : NULL, $explicit_allow, $poster_name_if_guest, $parent_id, false, !$private && $post != '' ? 'comment_posted' : NULL, !$private && $post != '' ? $content_type . '_' . $content_id : NULL); if (!is_null($topic_id)) { if (!is_integer($forum)) { $forum_id = $GLOBALS['FORUM_DRIVER']->forum_id_from_name($forum); } else { $forum_id = (int) $forum; } if (get_forum_type() == 'ocf' && !is_null($GLOBALS['LAST_POST_ID'])) { $extra_review_ratings = array(); global $REVIEWS_STRUCTURE; if (array_key_exists($content_type, $REVIEWS_STRUCTURE)) { $reviews_rating_criteria = $REVIEWS_STRUCTURE[$content_type]; } else { $reviews_rating_criteria[] = ''; } foreach ($reviews_rating_criteria as $rating_type) { // Has there actually been any rating? $rating = post_param_integer('review_rating__' . fix_id($rating_type), NULL); if (!is_null($rating)) { if ($rating > 10 || $rating < 1) { log_hack_attack_and_exit('VOTE_CHEAT'); } $GLOBALS['SITE_DB']->query_insert('review_supplement', array('r_topic_id' => $GLOBALS['LAST_TOPIC_ID'], 'r_post_id' => $GLOBALS['LAST_POST_ID'], 'r_rating_type' => $rating_type, 'r_rating_for_type' => $content_type, 'r_rating_for_id' => $content_id, 'r_rating' => $rating)); } } } } if (!$private && $post != '') { list(, $submitter, , $safe_content_url, $cma_info) = get_details_behind_feedback_code($content_type, $content_id); $content_type_title = $content_type; if (!is_null($cma_info) && isset($cma_info['content_type_label'])) { $content_type_title = do_lang($cma_info['content_type_label']); } // Notification require_code('notifications'); $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $subject = do_lang('NEW_COMMENT_SUBJECT', get_site_name(), $content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title, array($post_title, $username), get_site_default_lang()); $username = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); $message_raw = do_lang('NEW_COMMENT_BODY', comcode_escape(get_site_name()), comcode_escape($content_title == '' ? ocp_mb_strtolower($content_type_title) : $content_title), array($post_title == '' ? do_lang('NO_SUBJECT') : $post_title, post_param('post'), comcode_escape($content_url_flat), comcode_escape($username)), get_site_default_lang()); dispatch_notification('comment_posted', $content_type . '_' . $content_id, $subject, $message_raw); // Is the user gonna automatically enable notifications for this? if (get_forum_type() == 'ocf') { $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field(get_member(), 'm_auto_monitor_contrib_content'); if ($auto_monitor_contrib_content == 1) { enable_notifications('comment_posted', $content_type . '_' . $content_id); } } // Activity $real_content_type = convert_ocportal_type_codes('feedback_type_code', $content_type, 'cma_hook'); if (may_view_content_behind_feedback_code($GLOBALS['FORUM_DRIVER']->get_guest_id(), $real_content_type, $content_id)) { if (is_null($submitter)) { $submitter = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } $activity_type = is_null($submitter) || is_guest($submitter) ? '_ADDED_COMMENT_ON' : 'ADDED_COMMENT_ON'; if ($content_title == '') { syndicate_described_activity($activity_type . '_UNTITLED', ocp_mb_strtolower($content_type_title), $content_type_title, '', url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter); } else { syndicate_described_activity($activity_type, $content_title, ocp_mb_strtolower($content_type_title), $content_type_title, url_to_pagelink(is_object($safe_content_url) ? $safe_content_url->evaluate() : $safe_content_url), '', '', convert_ocportal_type_codes('feedback_type_code', $content_type, 'addon_name'), 1, NULL, false, $submitter); } } } if ($post != '' && $forum_tie && !$no_success_message) { require_code('site2'); assign_refresh($GLOBALS['FORUM_DRIVER']->topic_url($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier($forum, $content_type . '_' . $content_id), $forum), 0.0); } if ($post != '' && !$no_success_message) { attach_message(do_lang_tempcode('SUCCESS')); } return $is_hidden; }
/** * Makes a post in the specified forum, in the specified topic according to the given specifications. If the topic doesn't exist, it is created along with a spacer-post. * Spacer posts exist in order to allow staff to delete the first true post in a topic. Without spacers, this would not be possible with most forum systems. They also serve to provide meta information on the topic that cannot be encoded in the title (such as a link to the content being commented upon). * * @param object Link to the real forum driver * @param SHORT_TEXT The forum name * @param SHORT_TEXT The topic identifier (usually <content-type>_<content-id>) * @param MEMBER The member ID * @param LONG_TEXT The post title * @param LONG_TEXT The post content in Comcode format * @param string The topic title; must be same as content title if this is for a comment topic * @param string This is put together with the topic identifier to make a more-human-readable topic title or topic description (hopefully the latter and a $content_title title, but only if the forum supports descriptions) * @param ?URLPATH URL to the content (NULL: do not make spacer post) * @param ?TIME The post time (NULL: use current time) * @param ?IP The post IP address (NULL: use current members IP address) * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param ?BINARY Whether the topic is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver. * @param boolean Whether to skip post checks * @param SHORT_TEXT The name of the poster * @param ?AUTO_LINK ID of post being replied to (NULL: N/A) * @param boolean Whether the reply is only visible to staff * @param ?ID_TEXT DO NOT send notifications to: The notification code (NULL: no restriction) * @param ?SHORT_TEXT DO NOT send notifications to: The category within the notification code (NULL: none / no restriction) * @return array Topic ID (may be NULL), and whether a hidden post has been made */ function _helper_make_post_forum_topic($this_ref, $forum_name, $topic_identifier, $member_id, $post_title, $post, $content_title, $topic_identifier_encapsulation_prefix, $content_url, $time, $ip, $validated, $topic_validated, $skip_post_checks, $poster_name_if_guest, $parent_id, $staff_only, $no_notify_for__notification_code, $no_notify_for__code_category) { if (is_null($time)) { $time = time(); } if (is_null($ip)) { $ip = get_ip_address(); } require_code('comcode_check'); check_comcode($post, NULL, false, NULL, true); require_code('ocf_topics'); require_code('ocf_posts'); //require_code('ocf_forums'); require_lang('ocf'); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); if (!is_integer($forum_name)) { $forum_id = $this_ref->forum_id_from_name($forum_name); if (is_null($forum_id)) { warn_exit(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name))); } } else { $forum_id = (int) $forum_name; } $topic_id = $this_ref->find_topic_id_for_topic_identifier($forum_name, $topic_identifier); $update_caching = false; $support_attachments = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $update_caching = true; $support_attachments = true; } if (is_null($topic_id)) { $is_starter = true; require_code('ocf_topics_action'); $topic_id = ocf_make_topic($forum_id, $topic_identifier_encapsulation_prefix . ': #' . $topic_identifier, '', $topic_validated, 1, 0, 0, 0, NULL, NULL, false, 0, NULL, $content_url); if (strpos($topic_identifier, ':') !== false) { // Sync comment_posted ones to also monitor the forum ones; no need for opposite way as comment ones already trigger forum ones $start = 0; $max = 300; require_code('notifications'); $ob = _get_notification_ob_for_code('comment_posted'); do { list($members, $possibly_has_more) = $ob->list_members_who_have_enabled('comment_posted', $topic_identifier, NULL, $start, $max); foreach ($members as $to_member_id => $setting) { enable_notifications('ocf_topic', strval($topic_id), $to_member_id); } $start += $max; } while ($possibly_has_more); } // Make spacer post if (!is_null($content_url)) { $spacer_title = $content_title; $home_link = hyperlink($content_url, escape_html($content_title)); $spacer_post = '[semihtml]' . do_lang('SPACER_POST', $home_link->evaluate(), '', '', get_site_default_lang()) . '[/semihtml]'; ocf_make_post($topic_id, $spacer_title, $spacer_post, 0, true, 1, 0, do_lang('SYSTEM'), $ip, $time, db_get_first_id(), NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, false, false, false); $is_starter = false; } $is_new = true; } else { $is_starter = false; $is_new = false; } $GLOBALS['LAST_TOPIC_ID'] = $topic_id; $GLOBALS['LAST_TOPIC_IS_NEW'] = $is_new; if ($post == '') { return array(NULL, false); } ocf_check_post($post, $topic_id, $member_id); $poster_name = $poster_name_if_guest; if ($poster_name == '') { $poster_name = $this_ref->get_username($member_id); } $post_id = ocf_make_post($topic_id, $post_title, $post, 0, $is_starter, $validated, 0, $poster_name, $ip, $time, $member_id, $staff_only ? $GLOBALS['FORUM_DRIVER']->get_guest_id() : NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, $skip_post_checks, false, false, $parent_id); $GLOBALS['LAST_POST_ID'] = $post_id; if ($is_new) { // Broken cache now for the rest of this page view - fix by flushing global $TOPIC_IDENTIFIERS_TO_IDS; $TOPIC_IDENTIFIERS_TO_IDS = array(); } // Send out notifications $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); ocf_send_topic_notification($url, $topic_id, $forum_id, $member_id, $is_new, $post, $content_title, NULL, false, $no_notify_for__notification_code, $no_notify_for__code_category); $is_hidden = false; if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') { $validated_actual = $this_ref->connection->query_value('f_posts', 'p_validated', array('id' => $post_id)); if ($validated_actual == 0) { require_code('site'); attach_message(do_lang_tempcode('SUBMIT_UNVALIDATED'), 'inform'); $is_hidden = true; } } return array($topic_id, $is_hidden); }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_notifications($db, $table_prefix, $file_base) { require_code('notifications'); $row_start = 0; $rows = array(); do { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'log_notify WHERE id_topic<>0', 200, $row_start); foreach ($rows as $row) { if (import_check_if_imported('topic_notification', strval($row['id_topic']) . '-' . strval($row['id_member']))) { continue; } $member_id = import_id_remap_get('member', strval($row['id_member']), true); if (is_null($member_id)) { continue; } $topic_id = import_id_remap_get('topic', strval($row['id_topic']), true); if (is_null($topic_id)) { continue; } enable_notifications('ocf_topic', strval($topic_id), $member_id); import_id_remap_put('topic_notification', strval($row['id_topic']) . '-' . strval($row['id_member']), 1); } $row_start += 200; } while (count($rows) > 0); }
/** * The actualiser to invite a member to a PT. * * @return tempcode The UI */ function _invite_member() { $username = trim(post_param('username')); $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($username); if (is_null($member_id)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', escape_html($username))); } $topic_id = get_param_integer('topic_id'); require_code('ocf_topics_action'); require_code('ocf_topics_action2'); require_code('notifications'); enable_notifications('ocf_topic', strval($topic_id), $member_id); ocf_invite_to_pt($member_id, $topic_id); return $this->redirect_to('EDIT_TOPIC', $topic_id); }
/** * Add a post. * * @param AUTO_LINK The ID of the topic to add the post to. * @param SHORT_TEXT The title of the post (may be blank). * @param LONG_TEXT The post. * @param BINARY Whether to skip showing the posters signature in the post. * @param boolean Whether the post is the first in the topic. * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). * @param BINARY Whether the post is marked emphasised. * @param ?string The name of the person making the post (NULL: username of current member). * @param ?IP The IP address the post is to be made under (NULL: IP of current user). * @param ?TIME The time of the post (NULL: now). * @param ?MEMBER The poster (NULL: current member). * @param ?MEMBER The member that this post is intended solely for (NULL: public). * @param ?TIME The last edit time of the post (NULL: never edited). * @param ?MEMBER The member that was last to edit the post (NULL: never edited). * @param boolean Whether to check permissions for whether the post may be made as it is given. * @param boolean Whether to update the caches after making the post. * @param ?AUTO_LINK The forum the post will be in (NULL: find out from the DB). * @param boolean Whether to allow attachments in this post. * @param ?string The title of the topic (NULL: find from the DB). * @param BINARY Whether the topic is a sunk topic. * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param boolean Whether to make the post anonymous * @param boolean Whether to skip post checks * @param boolean Whether this is for a new Private Topic * @param boolean Whether to explicitly insert the Comcode with admin privileges * @param ?AUTO_LINK Parent post ID (NULL: none-threaded/root-of-thread) * @return AUTO_LINK The ID of the new post. */ function ocf_make_post($topic_id, $title, $post, $skip_sig = 0, $is_starter = false, $validated = NULL, $is_emphasised = 0, $poster_name_if_guest = NULL, $ip_address = NULL, $time = NULL, $poster = NULL, $intended_solely_for = NULL, $last_edit_time = NULL, $last_edit_by = NULL, $check_permissions = true, $update_cacheing = true, $forum_id = NULL, $support_attachments = true, $topic_title = '', $sunk = 0, $id = NULL, $anonymous = false, $skip_post_checks = false, $is_pt = false, $insert_comcode_as_admin = false, $parent_id = NULL) { if (is_null($poster)) { $poster = get_member(); } if ($check_permissions) { if (strlen($title) > 120) { warn_exit(do_lang_tempcode('TITLE_TOO_LONG')); } if (get_option('prevent_shouting') == '1') { if (strtoupper($title) == $title) { $title = ucwords($title); } } if (is_null($intended_solely_for) && !$skip_post_checks) { ocf_check_post($post, $topic_id, $poster); } } if (is_null($ip_address)) { $ip_address = get_ip_address(); } if (is_null($time)) { $time = time(); $send_notification = true; } else { $send_notification = false; } if (is_null($poster_name_if_guest)) { if ($poster == $GLOBALS['OCF_DRIVER']->get_guest_id() || $anonymous) { $poster_name_if_guest = do_lang('GUEST'); } else { $poster_name_if_guest = $GLOBALS['OCF_DRIVER']->get_username($poster); if (is_null($poster_name_if_guest)) { $poster_name_if_guest = do_lang('UNKNOWN'); } } } if (is_null($forum_id) || $topic_title == '' && !$is_starter) { $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_is_open', 't_pt_from', 't_pt_to', 't_forum_id', 't_cache_last_member_id', 't_cache_first_title'), array('id' => $topic_id), '', 1); if (!array_key_exists(0, $info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $forum_id = $info[0]['t_forum_id']; $topic_title = $info[0]['t_cache_first_title']; if ($topic_title == '') { $topic_title = $title; } if ($check_permissions) { if ($info[0]['t_pt_from'] != get_member() && $info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($forum_id)) { access_denied('I_ERROR'); } } } if (is_null($forum_id)) { if ($check_permissions && $poster == $GLOBALS['OCF_DRIVER']->get_guest_id()) { access_denied('I_ERROR'); } $validated = 1; // Personal posts always validated } else { if ($check_permissions) { if ($info[0]['t_is_open'] == 0 && !ocf_may_moderate_forum($forum_id)) { access_denied('I_ERROR'); } $last_member_id = $info[0]['t_cache_last_member_id']; if (!ocf_may_post_in_topic($forum_id, $topic_id, $last_member_id) && !$is_starter) { access_denied('I_ERROR'); } } } // Ensure parent post is from the same topic if (!is_null($parent_id)) { $test_topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_topic_id', array('id' => $parent_id), ' AND ' . ocf_get_topic_where($topic_id, $poster)); if (is_null($test_topic_id)) { $parent_id = NULL; } } if (is_null($validated) || $validated == 1 && $check_permissions) { if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_lowrange_content', 'topics', array('forums', $forum_id))) { $validated = 0; } else { $validated = 1; } } if (!$support_attachments) { $lang_id = insert_lang_comcode($post, 4, $GLOBALS['FORUM_DB'], $insert_comcode_as_admin); } else { $lang_id = 0; } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('p_title' => substr($title, 0, 255), 'p_post' => $lang_id, 'p_ip_address' => $ip_address, 'p_time' => $time, 'p_poster' => $anonymous ? db_get_first_id() : $poster, 'p_poster_name_if_guest' => substr($poster_name_if_guest, 0, 80), 'p_validated' => $validated, 'p_topic_id' => $topic_id, 'p_is_emphasised' => $is_emphasised, 'p_cache_forum_id' => $forum_id, 'p_last_edit_time' => $last_edit_time, 'p_last_edit_by' => $last_edit_by, 'p_intended_solely_for' => $intended_solely_for, 'p_skip_sig' => $skip_sig, 'p_parent_id' => $parent_id); if (!is_null($id)) { $map['id'] = $id; } $post_id = $GLOBALS['FORUM_DB']->query_insert('f_posts', $map, true); if ($support_attachments) { require_code('attachments2'); $lang_id = insert_lang_comcode_attachments(4, $post, 'ocf_post', strval($post_id), $GLOBALS['FORUM_DB']); $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_post' => $lang_id), array('id' => $post_id), '', 1); } $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); if ($validated == 0) { if ($check_permissions) { // send_validation_mail is used for other content - but forum is special $subject = do_lang('POST_REQUIRING_VALIDATION_MAIL_SUBJECT', $topic_title, NULL, NULL, get_site_default_lang()); $post_text = get_translated_text($lang_id, $GLOBALS['FORUM_DB'], get_site_default_lang()); $mail = do_lang('POST_REQUIRING_VALIDATION_MAIL', comcode_escape($url), comcode_escape($poster_name_if_guest), $post_text); require_code('notifications'); dispatch_notification('needs_validation', NULL, $subject, $mail); } } else { if ($check_permissions) { if ($send_notification) { $post_comcode = get_translated_text($lang_id, $GLOBALS['FORUM_DB']); require_code('ocf_posts_action2'); ocf_send_topic_notification($url, $topic_id, $forum_id, $anonymous ? db_get_first_id() : $poster, $is_starter, $post_comcode, $topic_title, $intended_solely_for, $is_pt); // Send a notification for the inline PP if (!is_null($intended_solely_for)) { require_code('notifications'); $msubject = do_lang('NEW_PERSONAL_POST_SUBJECT', $topic_title, NULL, NULL, get_lang($intended_solely_for)); $mmessage = do_lang('NEW_PERSONAL_POST_MESSAGE', comcode_escape($GLOBALS['FORUM_DRIVER']->get_username($anonymous ? db_get_first_id() : $poster)), comcode_escape($topic_title), array(comcode_escape($url), $post_comcode), get_lang($intended_solely_for)); dispatch_notification('ocf_new_pt', NULL, $msubject, $mmessage, array($intended_solely_for), $anonymous ? db_get_first_id() : $poster); } } } } if ($check_permissions) { // Is the user gonna automatically enable notifications for this? $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field($poster, 'm_auto_monitor_contrib_content'); if ($auto_monitor_contrib_content == 1) { require_code('notifications'); enable_notifications('ocf_topic', strval($topic_id), $poster); } } if ($update_cacheing) { if (function_exists('get_member')) { if (function_exists('ocf_ping_topic_read')) { ocf_ping_topic_read($topic_id); } if (is_null($forum_id)) { $with = $info[0]['t_pt_from']; if ($with == get_member()) { $with = $info[0]['t_pt_to']; } decache('side_ocf_personal_topics', array($with)); decache('_new_pp', array($with)); } if (get_option('show_post_validation') == '1') { decache('main_staff_checklist'); } } if (is_null($intended_solely_for)) { if ($validated == 1) { require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($topic_id, 1, true, $is_starter, $post_id, $time, $title, $lang_id, $poster_name_if_guest, $poster); } if ($validated == 1) { if (!is_null($forum_id)) { require_code('ocf_posts_action2'); // Find if the topic is validated. This can be approximate, if we don't get 1 then ocf_force_update_forum_cacheing will do a search, making the code very slightly slower if (!$check_permissions || is_null($forum_id)) { $topic_validated = 1; } else { if ($is_starter) { $topic_validated = has_specific_permission($poster, 'bypass_validation_midrange_content', 'topics', array('forums', $forum_id)) ? 1 : 0; } else { $topic_validated = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_validated', array('id' => $topic_id)); } } ocf_force_update_forum_cacheing($forum_id, $is_starter ? 1 : 0, 1, $topic_validated == 0 ? NULL : $topic_id, $topic_validated == 0 ? NULL : $topic_title, $topic_validated == 0 ? NULL : $time, $topic_validated == 0 ? NULL : $poster_name_if_guest, $topic_validated == 0 ? NULL : $poster, $topic_validated == 0 ? NULL : $forum_id); } } } // Update post count if (!is_null($forum_id)) { $post_counts = is_null($forum_id) ? 1 : $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_post_count_increment', array('id' => $forum_id)); if ($post_counts === 1 && !$anonymous && $validated == 1) { ocf_force_update_member_post_count($poster, 1); } if ($check_permissions) { ocf_decache_ocp_blocks($forum_id, NULL, $intended_solely_for); } // i.e. we don't run this if in installer } if ($poster != $GLOBALS['OCF_DRIVER']->get_guest_id()) { require_code('ocf_posts_action2'); ocf_member_handle_promotion($poster); } } return $post_id; }
/** * Install/upgrade OCF. * * @param ?float The version to upgrade from (NULL: fresh install). */ function install_ocf($upgrade_from = NULL) { require_code('ocf_members'); require_code('ocf_topics'); require_code('ocf_groups'); require_code('ocf_forums'); require_lang('ocf'); require_lang('ocf_config'); require_code('ocf_moderation_action'); require_code('ocf_posts_action'); require_code('ocf_members_action'); require_code('ocf_groups_action'); require_code('ocf_general_action'); require_code('ocf_forums_action'); require_code('ocf_topics_action'); require_code('database_action'); if (is_null($upgrade_from)) { uninstall_ocf_everytime(); uninstall_ocf(); } $test = $GLOBALS['FORUM_DB']->query('SELECT id FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums', NULL, NULL, true); $not_installed = is_null($test); if ($not_installed) { $upgrade_from = NULL; } if (is_null($upgrade_from) || $upgrade_from < 4.2) { add_config_option('ENCRYPTION_KEY', 'encryption_key', 'line', 'require_code(\'encryption\');return is_encryption_available()?\'\':NULL;', 'PRIVACY', 'ADVANCED'); add_config_option('DECRYPTION_KEY', 'decryption_key', 'line', 'require_code(\'encryption\');return is_encryption_available()?\'\':NULL;', 'PRIVACY', 'ADVANCED'); add_config_option('IS_ON_POST_TITLES', 'is_on_post_titles', 'tick', 'return is_null($old=get_value(\'no_post_titles\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('IS_ON_ANONYMOUS_POSTS', 'is_on_anonymous_posts', 'tick', 'return is_null($old=get_value(\'ocf_no_anonymous_post\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('IS_ON_TIMEZONE_DETECTION', 'is_on_timezone_detection', 'tick', 'return is_null($old=get_value(\'no_js_timezone_detect\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('IS_ON_TOPIC_DESCRIPTIONS', 'is_on_topic_descriptions', 'tick', 'return is_null($old=get_value(\'no_topic_descriptions\'))?\'1\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('IS_ON_TOPIC_EMOTICONS', 'is_on_topic_emoticons', 'tick', 'return is_null($old=get_value(\'ocf_no_topic_emoticons\'))?\'1\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('DEFAULT_PREVIEW_GUESTS', 'default_preview_guests', 'tick', 'return is_null($old=get_value(\'no_default_preview_guests\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('FORCED_PREVIEW_OPTION', 'forced_preview_option', 'tick', 'return is_null($old=get_value(\'no_forced_preview_option\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('OVERT_WHISPER_SUGGESTION', 'overt_whisper_suggestion', 'tick', 'return is_null($old=get_value(\'disable_overt_whispering\'))?\'1\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('IS_ON_INVISIBILITY', 'is_on_invisibility', 'tick', 'return is_null($old=get_value(\'no_invisible_option\'))?\'0\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('ALLOW_ALPHA_SEARCH', 'allow_alpha_search', 'tick', 'return is_null($old=get_value(\'allow_alpha_search\'))?\'0\':$old;', 'SECTION_FORUMS', 'GENERAL'); add_config_option('ALLOW_EMAIL_DISABLE', 'allow_email_disable', 'tick', 'return is_null($old=get_value(\'disable_allow_emails_field\'))?\'1\':invert_value($old);', 'SECTION_FORUMS', 'GENERAL'); add_config_option('MAX_MEMBER_TITLE_LENGTH', 'max_member_title_length', 'integer', 'return addon_installed(\'ocf_member_titles\')?\'20\':NULL;', 'SECTION_FORUMS', 'GENERAL'); $GLOBALS['FORUM_DB']->drop_if_exists('f_member_cpf_perms'); $GLOBALS['FORUM_DB']->create_table('f_member_cpf_perms', array('member_id' => '*USER', 'field_id' => '*AUTO_LINK', 'guest_view' => 'BINARY', 'member_view' => 'BINARY', 'friend_view' => 'BINARY', 'group_view' => 'SHORT_TEXT')); } if (is_null($upgrade_from) || $upgrade_from < 2.5) { add_config_option('HTTPAUTH_IS_ENABLED', 'httpauth_is_enabled', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'ADVANCED', 1); add_config_option('POST_HISTORY_DAYS', 'post_history_days', 'integer', 'return \'21\';', 'SECTION_FORUMS', 'GENERAL', 1); } if (is_null($upgrade_from)) { // Add config options add_config_option('FORUM_POSTS_PER_PAGE', 'forum_posts_per_page', 'integer', 'return has_no_forum()?NULL:\'20\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('FORUM_TOPICS_PER_PAGE', 'forum_topics_per_page', 'integer', 'return has_no_forum()?NULL:\'30\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('PREVENT_SHOUTING', 'prevent_shouting', 'tick', 'return has_no_forum()?NULL:\'1\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('RESTRICTED_USERNAMES', 'restricted_usernames', 'line', 'return do_lang(\'GUEST\').\', \'.do_lang(\'STAFF\').\', \'.do_lang(\'ADMIN\').\', \'.do_lang(\'MODERATOR\').\', googlebot\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('REQUIRE_NEW_MEMBER_VALIDATION', 'require_new_member_validation', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('REPORTED_POSTS_FORUM', 'reported_posts_forum', 'forum', 'return (has_no_forum()||(!addon_installed(\'ocf_reported_posts\')))?NULL:do_lang(\'ocf:REPORTED_POSTS_FORUM\');', 'SECTION_FORUMS', 'GENERAL'); add_config_option('ONE_PER_EMAIL_ADDRESS', 'one_per_email_address', 'tick', 'return \'1\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('HOT_TOPIC_DEFINITION', 'hot_topic_definition', 'integer', 'return has_no_forum()?NULL:\'20\';', 'SECTION_FORUMS', 'GENERAL'); } if (!is_null($upgrade_from) && $upgrade_from < 7.2) { $rows = $GLOBALS['FORUM_DB']->query('SELECT m_name FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'db_meta WHERE (' . db_string_equal_to('m_type', '?INTEGER') . ' OR ' . db_string_equal_to('m_type', 'BINARY') . ') AND ' . db_string_equal_to('m_table', 'f_member_custom_fields')); foreach ($rows as $row) { $GLOBALS['FORUM_DB']->alter_table_field('f_member_custom_fields', $row['m_name'], 'SHORT_TEXT'); } $i = 0; do { $rows = $GLOBALS['FORUM_DB']->query_select('f_member_custom_fields', array('*'), NULL, '', 100, $i); foreach ($rows as $j => $row) { foreach ($row as $key => $val) { if (substr($key, 0, 6) == 'field_') { $val = str_replace('|', chr(10), $val); $row[$key] = $val; } } if ($rows[$j] != $row) { $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', array('mf_member_id' => $row['mf_member_id']), $row, '', 1); } } $i += 100; } while (count($rows) != 0); $GLOBALS['FORUM_DB']->alter_table_field('f_members', 'm_track_contributed_topics', 'BINARY', 'm_auto_monitor_contrib_content'); } if (!is_null($upgrade_from) && $upgrade_from < 4.0) { $GLOBALS['FORUM_DB']->alter_table_field('f_members', 'm_password_compatibility_scheme', 'ID_TEXT', 'm_password_compat_scheme'); $GLOBALS['FORUM_DB']->delete_table_field('f_members', 'm_track_all_forums'); } if (!is_null($upgrade_from) && $upgrade_from < 3.1) { $GLOBALS['FORUM_DB']->add_table_field('f_emoticons', 'e_is_special', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_highlighted_name', 'BINARY', 0); } if (!is_null($upgrade_from) && $upgrade_from < 3.0) { $rows = $GLOBALS['FORUM_DB']->query_select('f_forum_group_access', array('*')); foreach ($rows as $row) { if ($row['a_level'] > 1) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'forums', 'category_name' => strval($row['a_forum_id']), 'group_id' => $row['a_group_id'])); } } $GLOBALS['FORUM_DB']->drop_if_exists('f_forum_group_access'); delete_specific_permission('allow_deletive_moderation'); $GLOBALS['FORUM_DB']->delete_table_field('f_post_templates', 't_minimum_access_level'); $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_is_presented_at_install', 'BINARY', 0); $GLOBALS['FORUM_DB']->alter_table_field('f_custom_fields', 'cf_name', 'SHORT_TRANS'); $GLOBALS['FORUM_DB']->alter_table_field('f_groups', 'g_rank_image', 'ID_TEXT'); } if (!is_null($upgrade_from) && $upgrade_from < 2.6) { $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_is_default', 'BINARY'); } if (is_null($upgrade_from) || $upgrade_from < 4.0) { add_config_option('MINIMUM_PASSWORD_LENGTH', 'minimum_password_length', 'integer', 'return \'4\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('MAXIMUM_PASSWORD_LENGTH', 'maximum_password_length', 'integer', 'return \'20\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('MINIMUM_USERNAME_LENGTH', 'minimum_username_length', 'integer', 'return \'1\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('MAXIMUM_USERNAME_LENGTH', 'maximum_username_length', 'integer', 'return \'20\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('PROHIBIT_PASSWORD_WHITESPACE', 'prohibit_password_whitespace', 'tick', 'return \'1\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); //add_config_option('PROHIBIT_PASSWORD_DICTIONARY','prohibit_password_dictionary','tick','return \'0\';','SECTION_FORUMS','USERNAMES_AND_PASSWORDS'); add_config_option('PROHIBIT_USERNAME_WHITESPACE', 'prohibit_username_whitespace', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('ASSIGN_RANDOM_AVATARS', 'random_avatars', 'tick', 'return addon_installed(\'ocf_member_avatars\')?\'1\':NULL;', 'SECTION_FORUMS', 'GENERAL'); add_config_option('CLUB_FORUM_PARENT_FORUM', 'club_forum_parent_forum', 'forum', 'return has_no_forum()?NULL:strval(db_get_first_id());', 'SECTION_FORUMS', 'GENERAL'); add_config_option('CLUB_FORUM_PARENT_CATEGORY', 'club_forum_parent_category', 'category', 'return has_no_forum()?NULL:strval(db_get_first_id());', 'SECTION_FORUMS', 'GENERAL'); add_config_option('DELETE_TRASHED_PTS', 'delete_trashed_pts', 'tick', 'return has_no_forum()?NULL:\'0\';', 'SECTION_FORUMS', 'GENERAL'); //add_config_option('ALLOW_MEMBER_INTEGRATION','allow_member_integration','list','return \'off\';','SECTION_FORUMS','USERNAMES_AND_PASSWORDS',0,'strict|on|hidden|off'); add_config_option('PROBATION_USERGROUP', 'probation_usergroup', 'usergroup', 'return do_lang(\'PROBATION\');', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('SHOW_FIRST_JOIN_PAGE', 'show_first_join_page', 'tick', 'return \'1\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('SKIP_EMAIL_CONFIRM_JOIN', 'skip_email_confirm_join', 'tick', 'return \'1\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('NO_DOB_ASK', 'no_dob_ask', 'list', 'return \'0\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS', 0, '0|1|2'); add_config_option('ALLOW_INTERNATIONAL', 'allow_international', 'tick', 'return \'1\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); } if (is_null($upgrade_from) || $upgrade_from < 8.0) { add_config_option('ALLOW_EMAIL_FROM_STAFF_DISABLE', 'allow_email_from_staff_disable', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('INTRO_FORUM_ID', 'intro_forum_id', '?forum', 'return \'\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); add_config_option('SIGNUP_FULLNAME', 'signup_fullname', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS'); } if (!is_null($upgrade_from) && $upgrade_from < 8.1) { delete_config_option('no_dob_ask'); add_config_option('NO_DOB_ASK', 'no_dob_ask', 'list', 'return \'0\';', 'SECTION_FORUMS', 'USERNAMES_AND_PASSWORDS', 0, '0|1|2'); // Recreate option } if (!is_null($upgrade_from) && $upgrade_from < 8.0) { $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_allow_emails_from_staff', 'BINARY'); $GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_show_on_join_form', 'BINARY'); $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_is_threaded', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_posts', 'p_parent_id', '?AUTO_LINK', NULL); $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_custom_fields SET cf_show_on_join_form=cf_required'); delete_config_option('send_staff_message_post_validation'); require_code('notifications'); $start = 0; do { $rows = $GLOBALS['FORUM_DB']->query_select('f_forum_tracking', array('r_forum_id', 'r_member_id'), NULL, '', 100, $start); foreach ($rows as $row) { enable_notifications('ocf_topic', 'forum:' . strval($row['r_forum_id']), $row['r_member_id']); } $start += 100; } while (count($rows) == 100); $start = 0; do { $rows = $GLOBALS['FORUM_DB']->query_select('f_topic_tracking', array('r_topic_id', 'r_member_id'), NULL, '', 100, $start); foreach ($rows as $row) { enable_notifications('ocf_topic', strval($row['r_topic_id']), $row['r_member_id']); } $start += 100; } while (count($rows) == 100); $GLOBALS['FORUM_DB']->drop_if_exists('f_forum_tracking'); $GLOBALS['FORUM_DB']->drop_if_exists('f_topic_tracking'); } if (!is_null($upgrade_from) && $upgrade_from < 4.2) { $GLOBALS['FORUM_DB']->add_table_field('f_topics', 't_description_link', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_encrypted', 'BINARY', 0); } if (!is_null($upgrade_from) && $upgrade_from < 4.0) { $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_on_probation_until', '?TIME', time()); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_pt_rules_text', 'LONG_TRANS', ''); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_pt_allow', 'SHORT_TEXT', '*'); $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_order', 'ID_TEXT', 'last_post'); // last_post,first_post,title $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_hidden', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_order', 'INTEGER'); $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_rank_image_pri_only', 'BINARY', 1); $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_open_membership', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_groups', 'g_is_private_club', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_posts', 'p_skip_sig', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_topics', 't_sunk', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_multi_moderations', 'mm_sink_state', '?BINARY', NULL); $GLOBALS['FORUM_DB']->add_table_field('f_multi_moderations', 'mm_title_suffix', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'w_is_warning', 'BINARY', 1); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_silence_from_topic', '?AUTO_LINK'); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_silence_from_forum', '?AUTO_LINK'); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_probation', 'INTEGER', 0); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_banned_ip', 'IP'); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_charged_points', 'INTEGER', 0); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_banned_member', 'BINARY', 0); $GLOBALS['FORUM_DB']->add_table_field('f_warnings', 'p_changed_usergroup_from', '?GROUP'); } if (is_null($upgrade_from) || $upgrade_from < 3.0) { add_config_option('COPPA_ENABLED', 'is_on_coppa', 'tick', 'return \'0\';', 'PRIVACY', 'GENERAL'); add_config_option('FAX_NUMBER', 'privacy_fax', 'line', 'return \'\';', 'PRIVACY', 'GENERAL'); add_config_option('ADDRESS', 'privacy_postal_address', 'text', 'return \'\';', 'PRIVACY', 'GENERAL'); } if (is_null($upgrade_from) || $upgrade_from < 2.6) { add_config_option('INVITES_ENABLED', 'is_on_invites', 'tick', 'return \'0\';', 'SECTION_FORUMS', 'GENERAL'); add_config_option('INVITES_PER_DAY', 'invites_per_day', 'float', 'return \'1\';', 'SECTION_FORUMS', 'GENERAL'); } if (!is_null($upgrade_from) && $upgrade_from < 2.5) { $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_redirection', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_order_sub_alpha', 'BINARY'); $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_intro_question', 'LONG_TRANS'); $GLOBALS['FORUM_DB']->add_table_field('f_forums', 'f_intro_answer', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_max_email_attach_size_mb', 'INTEGER', 3); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_zone_wide', 'BINARY', 1); $GLOBALS['FORUM_DB']->add_table_field('f_members', 'm_notes', 'LONG_TEXT'); // TODO: remove $GLOBALS['FORUM_DB']->add_table_field('f_emoticons', 'e_use_topics', 'BINARY', 1); $GLOBALS['FORUM_DB']->add_table_field('f_topics', 't_pt_from_category', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_topics', 't_pt_to_category', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_show_in_post_previews', 'BINARY', 1); $GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_order', 'INTEGER'); $GLOBALS['FORUM_DB']->add_table_field('f_custom_fields', 'cf_only_group', '?GROUP'); $GLOBALS['FORUM_DB']->add_table_field('f_multi_moderations', 'mm_forum_multi_code', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->alter_table_field('f_topics', 't_emoticon', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->alter_table_field('f_emoticons', 'e_theme_img_code', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->promote_text_field_to_comcode('f_forums', 'f_description'); $GLOBALS['FORUM_DB']->alter_table_field('f_members', 'm_pass_hash_salted', 'SHORT_TEXT'); $GLOBALS['FORUM_DB']->drop_if_exists('f_groups'); $GLOBALS['FORUM_DB']->query_delete('f_emoticons'); } if (!is_null($upgrade_from) && $upgrade_from < 3.1) { $GLOBALS['FORUM_DB']->alter_table_field('f_custom_fields', 'cf_only_group', 'LONG_TEXT'); } // If we have the forum installed to this db already, leave if (is_null($upgrade_from) && $not_installed) { uninstall_ocf(); $GLOBALS['FORUM_DB']->create_table('f_emoticons', array('e_code' => '*ID_TEXT', 'e_theme_img_code' => 'SHORT_TEXT', 'e_relevance_level' => 'INTEGER', 'e_use_topics' => 'BINARY', 'e_is_special' => 'BINARY')); $GLOBALS['FORUM_DB']->create_index('f_emoticons', 'relevantemoticons', array('e_relevance_level')); $GLOBALS['FORUM_DB']->create_index('f_emoticons', 'topicemos', array('e_use_topics')); $GLOBALS['FORUM_DB']->create_table('f_custom_fields', array('id' => '*AUTO', 'cf_locked' => 'BINARY', 'cf_name' => 'SHORT_TRANS', 'cf_description' => 'SHORT_TRANS', 'cf_default' => 'LONG_TEXT', 'cf_public_view' => 'BINARY', 'cf_owner_view' => 'BINARY', 'cf_owner_set' => 'BINARY', 'cf_type' => 'ID_TEXT', 'cf_required' => 'BINARY', 'cf_show_in_posts' => 'BINARY', 'cf_show_in_post_previews' => 'BINARY', 'cf_order' => 'INTEGER', 'cf_only_group' => 'LONG_TEXT', 'cf_encrypted' => 'BINARY', 'cf_show_on_join_form' => 'BINARY')); // These don't need to be filled in. We just use default from custom field if they aren't $GLOBALS['FORUM_DB']->create_table('f_member_custom_fields', array('mf_member_id' => '*USER')); //$GLOBALS['FORUM_DB']->create_index('f_member_custom_fields','fields_for_member',array('mf_member_id')); ocf_make_boiler_custom_field('SELF_DESCRIPTION'); //ocf_make_boiler_custom_field('im_aim'); //ocf_make_boiler_custom_field('im_msn'); //ocf_make_boiler_custom_field('im_yahoo'); //ocf_make_boiler_custom_field('im_icq'); //ocf_make_boiler_custom_field('im_jabber'); ocf_make_boiler_custom_field('im_skype'); ocf_make_boiler_custom_field('sn_facebook'); ocf_make_boiler_custom_field('sn_google'); ocf_make_boiler_custom_field('sn_twitter'); ocf_make_boiler_custom_field('interests'); ocf_make_boiler_custom_field('location'); ocf_make_boiler_custom_field('occupation'); ocf_make_boiler_custom_field('staff_notes'); } if (is_null($upgrade_from) || $upgrade_from < 2.6) { $GLOBALS['FORUM_DB']->create_table('f_invites', array('id' => '*AUTO', 'i_inviter' => 'USER', 'i_email_address' => 'SHORT_TEXT', 'i_time' => 'TIME', 'i_taken' => 'BINARY')); } if (is_null($upgrade_from) && $not_installed) { $GLOBALS['FORUM_DB']->create_table('f_group_members', array('gm_group_id' => '*GROUP', 'gm_member_id' => '*USER', 'gm_validated' => 'BINARY')); $GLOBALS['FORUM_DB']->create_index('f_group_members', 'gm_validated', array('gm_validated')); $GLOBALS['FORUM_DB']->create_index('f_group_members', 'gm_member_id', array('gm_member_id')); $GLOBALS['FORUM_DB']->create_index('f_group_members', 'gm_group_id', array('gm_group_id')); $GLOBALS['FORUM_DB']->create_table('f_members', array('id' => '*AUTO', 'm_username' => 'ID_TEXT', 'm_pass_hash_salted' => 'SHORT_TEXT', 'm_pass_salt' => 'SHORT_TEXT', 'm_theme' => 'ID_TEXT', 'm_avatar_url' => 'URLPATH', 'm_validated' => 'BINARY', 'm_validated_email_confirm_code' => 'SHORT_TEXT', 'm_cache_num_posts' => 'INTEGER', 'm_cache_warnings' => 'INTEGER', 'm_join_time' => 'TIME', 'm_timezone_offset' => 'SHORT_TEXT', 'm_primary_group' => 'GROUP', 'm_last_visit_time' => 'TIME', 'm_last_submit_time' => 'TIME', 'm_signature' => 'LONG_TRANS', 'm_is_perm_banned' => 'BINARY', 'm_preview_posts' => 'BINARY', 'm_dob_day' => '?INTEGER', 'm_dob_month' => '?INTEGER', 'm_dob_year' => '?INTEGER', 'm_reveal_age' => 'BINARY', 'm_email_address' => 'SHORT_TEXT', 'm_title' => 'SHORT_TEXT', 'm_photo_url' => 'URLPATH', 'm_photo_thumb_url' => 'URLPATH', 'm_views_signatures' => 'BINARY', 'm_auto_monitor_contrib_content' => 'BINARY', 'm_language' => 'ID_TEXT', 'm_ip_address' => 'IP', 'm_allow_emails' => 'BINARY', 'm_allow_emails_from_staff' => 'BINARY', 'm_notes' => 'LONG_TEXT', 'm_zone_wide' => 'BINARY', 'm_highlighted_name' => 'BINARY', 'm_pt_allow' => 'SHORT_TEXT', 'm_pt_rules_text' => 'LONG_TRANS', 'm_max_email_attach_size_mb' => 'INTEGER', 'm_password_change_code' => 'SHORT_TEXT', 'm_password_compat_scheme' => 'ID_TEXT', 'm_on_probation_until' => '?TIME')); $GLOBALS['FORUM_DB']->create_index('f_members', '#search_user', array('m_username')); $GLOBALS['FORUM_DB']->create_index('f_members', 'user_list', array('m_username')); $GLOBALS['FORUM_DB']->create_index('f_members', 'menail', array('m_email_address')); $GLOBALS['FORUM_DB']->create_index('f_members', 'external_auth_lookup', array('m_pass_hash_salted')); $GLOBALS['FORUM_DB']->create_index('f_members', 'sort_post_count', array('m_cache_num_posts')); $GLOBALS['FORUM_DB']->create_index('f_members', 'm_join_time', array('m_join_time')); $GLOBALS['FORUM_DB']->create_index('f_members', 'whos_validated', array('m_validated')); $GLOBALS['FORUM_DB']->create_index('f_members', 'birthdays', array('m_dob_day', 'm_dob_month')); $GLOBALS['FORUM_DB']->create_index('f_members', 'ftjoin_msig', array('m_signature')); $GLOBALS['FORUM_DB']->create_index('f_members', 'primary_group', array('m_primary_group')); $GLOBALS['FORUM_DB']->create_index('f_members', 'avatar_url', array('m_avatar_url')); // Used for uniform avatar randomisation } if (is_null($upgrade_from) || $upgrade_from < 2.5) { $no_use_topics = array('party' => 1, 'christmas' => 1, 'offtopic' => 1, 'rockon' => 1, 'guitar' => 1, 'sinner' => 1, 'wink' => 1, 'kiss' => 1, 'nod' => 1, 'smile' => 1, 'mellow' => 1, 'whistle' => 1, 'shutup' => 1, 'cyborg' => 1); $core_emoticons = array(':P' => 'cheeky', ":'(" => 'cry', ':dry:' => 'dry', ':$' => 'blush', ';)' => 'wink', 'O_o' => 'blink', ':wub:' => 'wub', ':cool:' => 'cool', ':lol:' => 'lol', ':(' => 'sad', ':)' => 'smile', ':thumbs:' => 'thumbs', ':offtopic:' => 'offtopic', ':|' => 'mellow', ':ninja:' => 'ph34r', ':o' => 'shocked'); $supported_emoticons = array(':rolleyes:' => 'rolleyes', ':D' => 'grin', '^_^' => 'glee', '(K)' => 'kiss', ':S' => 'confused', ':@' => 'angry', ':shake:' => 'shake', ':hand:' => 'hand', ':drool:' => 'drool', ':devil:' => 'devil', ':party:' => 'party', ':constipated:' => 'constipated', ':depressed:' => 'depressed', ':zzz:' => 'zzz', ':whistle:' => 'whistle', ':upsidedown:' => 'upsidedown', ':sick:' => 'sick', ':shutup:' => 'shutup', ':sarcy:' => 'sarcy', ':puppyeyes:' => 'puppyeyes', ':nod:' => 'nod', ':nerd:' => 'nerd', ':king:' => 'king', ':birthday:' => 'birthday', ':cyborg:' => 'cyborg', ':hippie:' => 'hippie', ':ninja2:' => 'ninja2', ':rockon:' => 'rockon', ':sinner:' => 'sinner', ':guitar:' => 'guitar'); $unused_emoticons = array(':christmas:' => 'christmas'); foreach ($core_emoticons as $a => $b) { ocf_make_emoticon($a, 'ocf_emoticons/' . $b, 0, array_key_exists($b, $no_use_topics) ? 0 : 1); } foreach ($supported_emoticons as $a => $b) { ocf_make_emoticon($a, 'ocf_emoticons/' . $b, 1, array_key_exists($b, $no_use_topics) ? 0 : 1); } foreach ($unused_emoticons as $a => $b) { ocf_make_emoticon($a, 'ocf_emoticons/' . $b, 1, array_key_exists($b, $no_use_topics) ? 0 : 1); } $GLOBALS['FORUM_DB']->create_table('f_groups', array('id' => '*AUTO', 'g_name' => 'SHORT_TRANS', 'g_is_default' => 'BINARY', 'g_is_presented_at_install' => 'BINARY', 'g_is_super_admin' => 'BINARY', 'g_is_super_moderator' => 'BINARY', 'g_group_leader' => '?USER', 'g_title' => 'SHORT_TRANS', 'g_promotion_target' => '?GROUP', 'g_promotion_threshold' => '?INTEGER', 'g_flood_control_submit_secs' => 'INTEGER', 'g_flood_control_access_secs' => 'INTEGER', 'g_gift_points_base' => 'INTEGER', 'g_gift_points_per_day' => 'INTEGER', 'g_max_daily_upload_mb' => 'INTEGER', 'g_max_attachments_per_post' => 'INTEGER', 'g_max_avatar_width' => 'INTEGER', 'g_max_avatar_height' => 'INTEGER', 'g_max_post_length_comcode' => 'INTEGER', 'g_max_sig_length_comcode' => 'INTEGER', 'g_enquire_on_new_ips' => 'BINARY', 'g_rank_image' => 'ID_TEXT', 'g_hidden' => 'BINARY', 'g_order' => 'INTEGER', 'g_rank_image_pri_only' => 'BINARY', 'g_open_membership' => 'BINARY', 'g_is_private_club' => 'BINARY')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'ftjoin_gname', array('g_name')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'ftjoin_gtitle', array('g_title')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'is_private_club', array('g_is_private_club')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'is_super_admin', array('g_is_super_admin')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'is_super_moderator', array('g_is_super_moderator')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'is_default', array('g_is_default')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'hidden', array('g_hidden')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'is_presented_at_install', array('g_is_presented_at_install')); $GLOBALS['FORUM_DB']->create_index('f_groups', 'gorder', array('g_order', 'id')); // For the_zone_access table require_code('zones2'); reinstall_module('adminzone', 'admin_permissions'); // Make guest $guest_group = ocf_make_group(do_lang('GUESTS'), 0, 0, 0, do_lang('DESCRIPTION_GUESTS')); // Make admin $administrator_group = ocf_make_group(do_lang('ADMINISTRATORS'), 0, 1, 0, do_lang('DESCRIPTION_ADMINISTRATORS'), 'ocf_rank_images/admin', NULL, NULL, NULL, 0); // Make mod $super_moderator_group = ocf_make_group(do_lang('SUPER_MODERATORS'), 0, 0, 1, do_lang('DESCRIPTION_SUPER_MODERATORS'), 'ocf_rank_images/mod', NULL, NULL, NULL, 0); // Make supermember $super_member_group = ocf_make_group(do_lang('SUPER_MEMBERS'), 0, 0, 0, do_lang('DESCRIPTION_SUPER_MEMBERS'), '', NULL, NULL, NULL, 0); // Make member $member_group_4 = ocf_make_group(do_lang('DEFAULT_RANK_4'), 0, 0, 0, do_lang('DESCRIPTION_MEMBERS'), 'ocf_rank_images/4'); $member_group_3 = ocf_make_group(do_lang('DEFAULT_RANK_3'), 0, 0, 0, do_lang('DESCRIPTION_MEMBERS'), 'ocf_rank_images/3', $member_group_4, 10000); $member_group_2 = ocf_make_group(do_lang('DEFAULT_RANK_2'), 0, 0, 0, do_lang('DESCRIPTION_MEMBERS'), 'ocf_rank_images/2', $member_group_3, 2500); $member_group_1 = ocf_make_group(do_lang('DEFAULT_RANK_1'), 0, 0, 0, do_lang('DESCRIPTION_MEMBERS'), 'ocf_rank_images/1', $member_group_2, 400); $member_group_0 = ocf_make_group(do_lang('DEFAULT_RANK_0'), 0, 0, 0, do_lang('DESCRIPTION_MEMBERS'), 'ocf_rank_images/0', $member_group_1, 100); // Not default because primary is always defaulted to this one // Make probation $probation_group = ocf_make_group(do_lang('PROBATION'), 0, 0, 0, do_lang('DESCRIPTION_PROBATION'), '', NULL, NULL, NULL, 0); } if (is_null($upgrade_from) && $not_installed) { $GLOBALS['FORUM_DB']->create_table('f_categories', array('id' => '*AUTO', 'c_title' => 'SHORT_TEXT', 'c_description' => 'LONG_TEXT', 'c_expanded_by_default' => 'BINARY')); $category_id = ocf_make_category(do_lang('DEFAULT_CATEGORY_TITLE'), ''); $category_id_staff = ocf_make_category(do_lang('STAFF'), ''); $GLOBALS['FORUM_DB']->create_table('f_forums', array('id' => '*AUTO', 'f_name' => 'SHORT_TEXT', 'f_description' => 'LONG_TRANS', 'f_category_id' => '?AUTO_LINK', 'f_parent_forum' => '?AUTO_LINK', 'f_position' => 'INTEGER', 'f_order_sub_alpha' => 'BINARY', 'f_post_count_increment' => 'BINARY', 'f_intro_question' => 'LONG_TRANS', 'f_intro_answer' => 'SHORT_TEXT', 'f_cache_num_topics' => 'INTEGER', 'f_cache_num_posts' => 'INTEGER', 'f_cache_last_topic_id' => '?AUTO_LINK', 'f_cache_last_title' => 'SHORT_TEXT', 'f_cache_last_time' => '?TIME', 'f_cache_last_username' => 'SHORT_TEXT', 'f_cache_last_member_id' => '?USER', 'f_cache_last_forum_id' => '?AUTO_LINK', 'f_redirection' => 'SHORT_TEXT', 'f_order' => 'ID_TEXT', 'f_is_threaded' => 'BINARY')); $GLOBALS['FORUM_DB']->create_index('f_forums', 'cache_num_posts', array('f_cache_num_posts')); // Used to find active forums $GLOBALS['FORUM_DB']->create_index('f_forums', 'subforum_parenting', array('f_parent_forum')); $GLOBALS['FORUM_DB']->create_index('f_forums', 'findnamedforum', array('f_name')); $GLOBALS['FORUM_DB']->create_index('f_forums', 'f_position', array('f_position')); $typical_access = array($guest_group => 4, $administrator_group => 5, $super_moderator_group => 5, $probation_group => 2, $super_member_group => 4, $member_group_0 => 4, $member_group_1 => 4, $member_group_2 => 4, $member_group_3 => 4, $member_group_4 => 4); $staff_post_access = array($guest_group => 1, $administrator_group => 5, $super_moderator_group => 5, $probation_group => 1, $super_member_group => 2, $member_group_0 => 1, $member_group_1 => 1, $member_group_2 => 1, $member_group_3 => 1, $member_group_4 => 1); $staff_access = array($administrator_group => 5, $super_moderator_group => 5); $root_forum = ocf_make_forum(do_lang('ROOT_FORUM'), '', NULL, $staff_post_access, NULL); //ocf_make_forum(do_lang('NEWS'),'',$category_id,$staff_post_access,$root_forum); ocf_make_forum(do_lang('DEFAULT_FORUM_TITLE'), '', $category_id, $typical_access, $root_forum); //ocf_make_forum(do_lang('_FEEDBACK'),'',$category_id,$typical_access,$root_forum); We already have a feedback page ocf_make_forum(do_lang('REPORTED_POSTS_FORUM'), '', $category_id_staff, $staff_access, $root_forum); $trash_forum_id = ocf_make_forum(do_lang('TRASH'), '', $category_id_staff, $staff_access, $root_forum); ocf_make_forum(do_lang('COMMENT_FORUM_NAME'), '', $category_id, $typical_access, $root_forum, 1, 1, 0, '', '', '', 'last_post', 1); if (addon_installed('tickets')) { require_lang('tickets'); ocf_make_forum(do_lang('TICKET_FORUM_NAME'), '', $category_id_staff, $staff_access, $root_forum); } $staff_forum_id = ocf_make_forum(do_lang('STAFF'), '', $category_id_staff, $staff_access, $root_forum); $GLOBALS['FORUM_DB']->create_table('f_topics', array('id' => '*AUTO', 't_pinned' => 'BINARY', 't_sunk' => 'BINARY', 't_cascading' => 'BINARY', 't_forum_id' => '?AUTO_LINK', 't_pt_from' => '?USER', 't_pt_to' => '?USER', 't_pt_from_category' => 'SHORT_TEXT', 't_pt_to_category' => 'SHORT_TEXT', 't_description' => 'SHORT_TEXT', 't_description_link' => 'SHORT_TEXT', 't_emoticon' => 'SHORT_TEXT', 't_num_views' => 'INTEGER', 't_validated' => 'BINARY', 't_is_open' => 'BINARY', 't_poll_id' => '?AUTO_LINK', 't_cache_first_post_id' => '?AUTO_LINK', 't_cache_first_time' => '?TIME', 't_cache_first_title' => 'SHORT_TEXT', 't_cache_first_post' => '?LONG_TRANS', 't_cache_first_username' => 'ID_TEXT', 't_cache_first_member_id' => '?USER', 't_cache_last_post_id' => '?AUTO_LINK', 't_cache_last_time' => '?TIME', 't_cache_last_title' => 'SHORT_TEXT', 't_cache_last_username' => 'ID_TEXT', 't_cache_last_member_id' => '?USER', 't_cache_num_posts' => 'INTEGER')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_num_views', array('t_num_views')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_pt_to', array('t_pt_to')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_pt_from', array('t_pt_from')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_validated', array('t_validated')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'in_forum', array('t_forum_id')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'topic_order_time', array('t_cache_last_time')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'topic_order_time_2', array('t_cache_first_time')); $GLOBALS['FORUM_DB']->create_index('f_topics', '#t_description', array('t_description')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'descriptionsearch', array('t_description')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'forumlayer', array('t_cache_first_title')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_cascading', array('t_cascading')); $GLOBALS['FORUM_DB']->create_index('f_topics', 't_cascading_or_forum', array('t_cascading', 't_forum_id')); $GLOBALS['FORUM_DB']->create_index('f_topics', 'topic_order', array('t_cascading', 't_pinned', 't_cache_last_time')); // Ordering for forumview, is picked up over topic_order_3 for just the ordering bit (it seems) $GLOBALS['FORUM_DB']->create_index('f_topics', 'topic_order_2', array('t_forum_id', 't_cascading', 't_pinned', 't_sunk', 't_cache_last_time')); // Total index for forumview, including ordering. Doesn't work on current MySQL. $GLOBALS['FORUM_DB']->create_index('f_topics', 'topic_order_3', array('t_forum_id', 't_cascading', 't_pinned', 't_cache_last_time')); // Total index for forumview, including ordering. Works if disable_sunk is turned on. $GLOBALS['FORUM_DB']->create_index('f_topics', 'ownedtopics', array('t_cache_first_member_id')); // Welcome topic $topic_id = ocf_make_topic($staff_forum_id, '', '', 1, 1, 0, 0, 0, NULL, NULL, false); $GLOBALS['FORUM_DB']->create_table('f_posts', array('id' => '*AUTO', 'p_title' => 'SHORT_TEXT', 'p_post' => 'LONG_TRANS', 'p_ip_address' => 'IP', 'p_time' => 'TIME', 'p_poster' => 'USER', 'p_intended_solely_for' => '?USER', 'p_poster_name_if_guest' => 'ID_TEXT', 'p_validated' => 'BINARY', 'p_topic_id' => 'AUTO_LINK', 'p_cache_forum_id' => '?AUTO_LINK', 'p_last_edit_time' => '?TIME', 'p_last_edit_by' => '?USER', 'p_is_emphasised' => 'BINARY', 'p_skip_sig' => 'BINARY', 'p_parent_id' => '?AUTO_LINK')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'p_validated', array('p_validated')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'in_topic', array('p_topic_id', 'p_time', 'id')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'post_order_time', array('p_time', 'id')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'p_last_edit_time', array('p_last_edit_time')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'posts_by', array('p_poster')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'find_pp', array('p_intended_solely_for')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'search_join', array('p_post')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'postsinforum', array('p_cache_forum_id')); $GLOBALS['FORUM_DB']->create_index('f_posts', 'deletebyip', array('p_ip_address')); } if (is_null($upgrade_from) && $not_installed || !is_null($upgrade_from) && $upgrade_from < 4.0) { $GLOBALS['FORUM_DB']->create_table('f_special_pt_access', array('s_member_id' => '*USER', 's_topic_id' => '*AUTO_LINK')); $GLOBALS['FORUM_DB']->create_table('f_saved_warnings', array('s_title' => '*SHORT_TEXT', 's_explanation' => 'LONG_TEXT', 's_message' => 'LONG_TEXT')); } if (is_null($upgrade_from) && $not_installed || $upgrade_from < 2.5) { $GLOBALS['FORUM_DB']->create_table('f_post_history', array('id' => '*AUTO', 'h_create_date_and_time' => 'TIME', 'h_action_date_and_time' => 'TIME', 'h_owner_member_id' => 'USER', 'h_alterer_member_id' => 'USER', 'h_post_id' => 'AUTO_LINK', 'h_topic_id' => 'AUTO_LINK', 'h_before' => 'LONG_TEXT', 'h_action' => 'ID_TEXT')); $GLOBALS['FORUM_DB']->create_index('f_post_history', 'phistorylookup', array('h_post_id')); $GLOBALS['FORUM_DB']->create_table('f_forum_intro_ip', array('i_forum_id' => '*AUTO_LINK', 'i_ip' => '*IP')); $GLOBALS['FORUM_DB']->create_table('f_forum_intro_member', array('i_forum_id' => '*AUTO_LINK', 'i_member_id' => '*USER')); $GLOBALS['FORUM_DB']->create_table('f_post_templates', array('id' => '*AUTO', 't_title' => 'SHORT_TEXT', 't_text' => 'LONG_TEXT', 't_forum_multi_code' => 'SHORT_TEXT', 't_use_default_forums' => 'BINARY')); ocf_make_post_template(do_lang('DEFAULT_POST_TEMPLATE_bug_title'), do_lang('DEFAULT_POST_TEMPLATE_bug_text'), '', 0); ocf_make_post_template(do_lang('DEFAULT_POST_TEMPLATE_task_title'), do_lang('DEFAULT_POST_TEMPLATE_task_text'), '', 0); ocf_make_post_template(do_lang('DEFAULT_POST_TEMPLATE_fault_title'), do_lang('DEFAULT_POST_TEMPLATE_fault_text'), '', 0); $GLOBALS['FORUM_DB']->create_index('f_posts', '#p_title', array('p_title')); } if (is_null($upgrade_from) && $not_installed) { $GLOBALS['FORUM_DB']->create_table('f_polls', array('id' => '*AUTO', 'po_question' => 'SHORT_TEXT', 'po_cache_total_votes' => 'INTEGER', 'po_is_private' => 'BINARY', 'po_is_open' => 'BINARY', 'po_minimum_selections' => 'INTEGER', 'po_maximum_selections' => 'INTEGER', 'po_requires_reply' => 'BINARY')); $GLOBALS['FORUM_DB']->create_table('f_poll_answers', array('id' => '*AUTO', 'pa_poll_id' => 'AUTO_LINK', 'pa_answer' => 'SHORT_TEXT', 'pa_cache_num_votes' => 'INTEGER')); $GLOBALS['FORUM_DB']->create_table('f_poll_votes', array('pv_poll_id' => '*AUTO_LINK', 'pv_member_id' => '*USER', 'pv_answer_id' => '*AUTO_LINK')); $GLOBALS['FORUM_DB']->create_table('f_multi_moderations', array('id' => '*AUTO', 'mm_name' => 'SHORT_TRANS', 'mm_post_text' => 'LONG_TEXT', 'mm_move_to' => '?INTEGER', 'mm_pin_state' => '?BINARY', 'mm_sink_state' => '?BINARY', 'mm_open_state' => '?BINARY', 'mm_forum_multi_code' => 'SHORT_TEXT', 'mm_title_suffix' => 'SHORT_TEXT')); ocf_make_multi_moderation(do_lang('TRASH'), '', $trash_forum_id, 0, 0, 0); $GLOBALS['FORUM_DB']->create_table('f_warnings', array('id' => '*AUTO', 'w_member_id' => 'USER', 'w_time' => 'TIME', 'w_explanation' => 'LONG_TEXT', 'w_by' => 'USER', 'w_is_warning' => 'BINARY', 'p_silence_from_topic' => '?AUTO_LINK', 'p_silence_from_forum' => '?AUTO_LINK', 'p_probation' => 'INTEGER', 'p_banned_ip' => 'IP', 'p_charged_points' => 'INTEGER', 'p_banned_member' => 'BINARY', 'p_changed_usergroup_from' => '?GROUP')); $GLOBALS['FORUM_DB']->create_index('f_warnings', 'warningsmemberid', array('w_member_id')); $GLOBALS['FORUM_DB']->create_table('f_moderator_logs', array('id' => '*AUTO', 'l_the_type' => 'ID_TEXT', 'l_param_a' => 'SHORT_TEXT', 'l_param_b' => 'SHORT_TEXT', 'l_date_and_time' => 'TIME', 'l_reason' => 'LONG_TEXT', 'l_by' => 'USER')); $GLOBALS['FORUM_DB']->create_table('f_member_known_login_ips', array('i_member_id' => '*USER', 'i_ip' => '*IP', 'i_val_code' => 'SHORT_TEXT')); if (strtoupper(ocp_srv('REQUEST_METHOD')) != 'POST') { exit; } // Needed as YSlow can load as GET's in background and cause horrible results // NB: post_param's will return default's if OCF is being installed but not used yet (e.g. IPB forum driver chosen at installation) // Make guest ocf_make_member(do_lang('GUEST'), '', '', NULL, NULL, NULL, NULL, array(), NULL, $guest_group, 1, time(), time(), '', NULL, '', 0, 1, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false); // Make admin user ocf_make_member(post_param('admin_username', 'admin'), post_param('ocf_admin_password', 'admin'), '', NULL, NULL, NULL, NULL, array(), NULL, $administrator_group, 1, time(), time(), '', 'themes/default/images/ocf_default_avatars/default_set/cool_flare.png', '', 0, 0, 1, '', '', '', 1, 1, '', 1, 1, '', NULL, '', false); // Make test user ocf_make_member('test', post_param('ocf_admin_password', 'admin'), '', NULL, NULL, NULL, NULL, array(), NULL, $member_group_0, 1, time(), time(), '', NULL, '', 0, 0, 1, '', '', '', 1, 0, '', 1, 1, '', NULL, '', false); $GLOBALS['FORUM_DB']->create_table('f_read_logs', array('l_member_id' => '*USER', 'l_topic_id' => '*AUTO_LINK', 'l_time' => 'TIME')); $GLOBALS['FORUM_DB']->create_index('f_read_logs', 'erase_old_read_logs', array('l_time')); ocf_make_post($topic_id, do_lang('DEFAULT_POST_TITLE'), do_lang('DEFAULT_POST_CONTENT'), 0, true, 1, 0, do_lang('SYSTEM'), '127.0.0.1', time(), $GLOBALS['OCF_DRIVER']->get_guest_id(), NULL, NULL, NULL, false, true); } // Permissions have to be done after usergroups if (is_null($upgrade_from)) { // Add privileges global $OCF_TRUE_PERMISSIONS, $OCF_FALSE_PERMISSIONS; foreach ($OCF_TRUE_PERMISSIONS as $permission) { add_specific_permission('SECTION_FORUMS', $permission, true); } foreach ($OCF_FALSE_PERMISSIONS as $permission) { add_specific_permission('SECTION_FORUMS', $permission, false, $permission == 'view_other_pt'); } } if (!is_null($upgrade_from) && $upgrade_from < 3.1) { add_specific_permission('SECTION_FORUMS', 'use_special_emoticons', false); } if (!is_null($upgrade_from) && $upgrade_from < 4.0) { add_specific_permission('SECTION_FORUMS', 'member_maintenance', false); add_specific_permission('SECTION_FORUMS', 'probate_members', false); add_specific_permission('SECTION_FORUMS', 'own_avatars', true); //add_specific_permission('SECTION_FORUMS','decide_comment_type',true); if we add threads add_specific_permission('SECTION_FORUMS', 'control_usergroups', false, true); add_specific_permission('SECTION_FORUMS', 'edit_personal_topic_posts', true); add_specific_permission('SECTION_FORUMS', 'multi_delete_topics', false); add_specific_permission('SECTION_FORUMS', 'show_user_browsing', false); add_specific_permission('SECTION_FORUMS', 'see_hidden_groups', false); add_specific_permission('SECTION_FORUMS', 'pt_anyone', false); } if (!is_null($upgrade_from) && $upgrade_from < 3.0) { add_specific_permission('SECTION_FORUMS', 'view_profiles', true); } if (!is_null($upgrade_from) && $upgrade_from < 2.5) { add_specific_permission('SECTION_FORUMS', 'moderate_personal_topic', false); add_specific_permission('SECTION_FORUMS', 'disable_lost_passwords', false); add_specific_permission('SECTION_FORUMS', 'view_any_profile_field', false); add_specific_permission('SECTION_FORUMS', 'rename_self', true); add_specific_permission('SECTION_FORUMS', 'double_post', false); add_specific_permission('SECTION_FORUMS', 'close_own_topics', false); add_specific_permission('SECTION_FORUMS', 'edit_own_polls', true); add_specific_permission('SECTION_FORUMS', 'warn_members', false); add_specific_permission('SECTION_FORUMS', 'see_warnings', false); add_specific_permission('SECTION_FORUMS', 'see_ip', false); add_specific_permission('SECTION_FORUMS', 'may_choose_custom_title', false); add_specific_permission('SECTION_FORUMS', 'delete_account', false); add_specific_permission('SECTION_FORUMS', 'view_other_pt', false); add_specific_permission('SECTION_FORUMS', 'view_poll_results_before_voting', false); add_specific_permission('SECTION_FORUMS', 'may_unblind_own_poll', true); delete_specific_permission('enquire_on_new_ips'); } }
function do_work() { $num_wanted = 100000; require_code('config2'); set_option('post_history_days', '0'); // Needed for a little sanity in recent post retrieval set_value('disable_sunk', '1'); // members (remember to test the username autocompleter, and birthdays) // authors (remember to check author autocompleter and popup author list) // lots of people getting notifications on a forum // lots of people getting notifications on a topic require_code('authors'); require_code('ocf_members_action'); require_code('notifications'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_members', 'COUNT(*)'); $i < $num_wanted; $i++) { $member_id = ocf_make_member(uniqid('', true), uniqid('', true), uniqid('', true) . '@example.com', array(), intval(date('d')), intval(date('m')), intval(date('Y')), array(), NULL, NULL, 1, NULL, NULL, '', NULL, '', 0, 0, 1, '', '', '', 1, 1, NULL, 1, 1, '', NULL, '', false); add_author(random_line(), '', $member_id, random_text(), random_text()); enable_notifications('ocf_topic', 'forum:' . strval(db_get_first_id()), $member_id); enable_notifications('ocf_topic', strval(db_get_first_id()), $member_id); // number of friends to a single member $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => db_get_first_id() + 1, 'date_and_time' => time()), false, true); } $member_id = db_get_first_id() + 2; // point earn list / gift points to a single member require_code('points2'); for ($j = $GLOBALS['SITE_DB']->query_value('gifts', 'COUNT(*)'); $j < $num_wanted; $j++) { give_points(10, $member_id, mt_rand(db_get_first_id(), min(100, $num_wanted - 1)), random_line(), false, false); } // number of friends of a single member for ($j = intval(floatval($GLOBALS['SITE_DB']->query_value('chat_buddies', 'COUNT(*)')) / 2.0); $j < $num_wanted; $j++) { $GLOBALS['SITE_DB']->query_insert('chat_buddies', array('member_likes' => $member_id, 'member_liked' => $j + db_get_first_id(), 'date_and_time' => time()), false, true); } echo 'done member/authors/points/notifications/friends stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // banners require_code('banners2'); for ($i = $GLOBALS['SITE_DB']->query_value('banners', 'COUNT(*)'); $i < $num_wanted; $i++) { add_banner(uniqid('', true), get_logo_url(), random_line(), random_text(), 100, get_base_url(), 3, '', db_get_first_id(), NULL, db_get_first_id() + 1, 1); } echo 'done banner stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // comcode pages require_code('files'); require_code('files2'); for ($i = $GLOBALS['SITE_DB']->query_value('comcode_pages', 'COUNT(*)'); $i < $num_wanted; $i++) { $file = uniqid('', true); /*$path=get_custom_file_base().'/site/pages/comcode_custom/'.fallback_lang().'/'.$file.'.txt'; $myfile=fopen($path,'wt'); fwrite($myfile,random_text()); fclose($myfile); sync_file($path); fix_permissions($path);*/ $GLOBALS['SITE_DB']->query_insert('comcode_pages', array('the_zone' => 'site', 'the_page' => $file, 'p_parent_page' => '', 'p_validated' => 1, 'p_edit_date' => NULL, 'p_add_date' => time(), 'p_submitter' => db_get_first_id(), 'p_show_as_edit' => 0)); } echo 'done comcode stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // zones require_code('zones2'); require_code('abstract_file_manager'); for ($i = $GLOBALS['SITE_DB']->query_value('zones', 'COUNT(*)'); $i < min($num_wanted, 1000); $i++) { actual_add_zone(uniqid('', true), random_line(), 'start', random_line(), 'default', 0, 0, 0); } echo 'done zone stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // calendar events require_code('calendar2'); for ($i = $GLOBALS['SITE_DB']->query_value('calendar_events', 'COUNT(*)'); $i < $num_wanted; $i++) { add_calendar_event(db_get_first_id(), '', NULL, 0, random_line(), random_text(), 1, 1, intval(date('Y')), intval(date('m')), intval(date('d')), 0, 0); } echo 'done event stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // chat rooms require_code('chat2'); require_code('chat'); for ($i = $GLOBALS['SITE_DB']->query_value('chat_rooms', 'COUNT(*)'); $i < $num_wanted; $i++) { $room_id = add_chatroom(random_text(), random_line(), mt_rand(db_get_first_id() + 1, $num_wanted - 1), strval(db_get_first_id() + 1), '', '', '', fallback_lang()); } $room_id = db_get_first_id() + 1; // messages in chat room for ($j = $GLOBALS['SITE_DB']->query_value('chat_messages', 'COUNT(*)'); $j < $num_wanted; $j++) { $_message_parsed = insert_lang_comcode(random_text(), 4); $GLOBALS['SITE_DB']->query_insert('chat_messages', array('system_message' => 0, 'ip_address' => '', 'room_id' => $room_id, 'user_id' => db_get_first_id(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font'))); } echo 'done chat stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // download categories under a subcategory require_code('downloads2'); $subcat_id = add_download_category(random_line(), db_get_first_id(), random_text(), ''); for ($i = $GLOBALS['SITE_DB']->query_value('download_categories', 'COUNT(*)'); $i < $num_wanted; $i++) { add_download_category(random_line(), $subcat_id, random_text(), ''); } // downloads (remember to test content by the single author) require_code('downloads2'); require_code('awards'); $time = time(); for ($i = $GLOBALS['SITE_DB']->query_value('download_downloads', 'COUNT(*)'); $i < $num_wanted; $i++) { $content_id = add_download(db_get_first_id(), random_line(), get_logo_url(), random_text(), 'admin', random_text(), NULL, 1, 1, 1, 1, '', uniqid('', true) . '.jpg', 100, 110, 1); give_award(db_get_first_id(), strval($content_id), $time - $i); } $content_id = db_get_first_id(); $content_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $content_id), 'site'); for ($j = $GLOBALS['SITE_DB']->query_value('trackbacks', 'COUNT(*)'); $j < $num_wanted; $j++) { // trackbacks $GLOBALS['SITE_DB']->query_insert('trackbacks', array('trackback_for_type' => 'downloads', 'trackback_for_id' => $content_id, 'trackback_ip' => '', 'trackback_time' => time(), 'trackback_url' => '', 'trackback_title' => random_line(), 'trackback_excerpt' => random_text(), 'trackback_name' => random_line())); // ratings $GLOBALS['SITE_DB']->query_insert('rating', array('rating_for_type' => 'downloads', 'rating_for_id' => $content_id, 'rating_member' => $j + 1, 'rating_ip' => '', 'rating_time' => time(), 'rating' => 3)); // posts in a comment topic $GLOBALS['FORUM_DRIVER']->make_post_forum_topic(get_option('comments_forum_name'), 'downloads_' . strval($content_id), get_member(), random_text(), random_line(), '', do_lang('COMMENT'), $content_url->evaluate(), NULL, NULL, 1, 1); } echo 'done download stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // forums under a forum (don't test it can display, just make sure the main index still works) require_code('ocf_forums_action'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_forums', 'COUNT(*)'); $i < $num_wanted; $i++) { ocf_make_forum(random_line(), random_text(), db_get_first_id(), array(), db_get_first_id() + 3); } // forum topics require_code('ocf_topics_action'); require_code('ocf_posts_action'); require_code('ocf_forums'); require_code('ocf_topics'); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) { $topic_id = ocf_make_topic(db_get_first_id(), '', '', NULL, 1, 0, 0, 0, NULL, NULL, false); ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, false, false); } // forum posts in a topic require_code('ocf_topics_action'); require_code('ocf_posts_action'); $topic_id = ocf_make_topic(db_get_first_id() + 1, '', '', NULL, 1, 0, 0, 0, NULL, NULL, false); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)')) / 3.0); $i < $num_wanted; $i++) { ocf_make_post($topic_id, random_line(), random_text(), 0, true, 0, 0, NULL, NULL, NULL, mt_rand(db_get_first_id(), $num_wanted - 1), NULL, NULL, NULL, false, false); } echo 'done forum stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // clubs require_code('ocf_groups_action'); require_code('ocf_groups'); for ($i = $GLOBALS['FORUM_DB']->query_value('f_groups', 'COUNT(*)'); $i < $num_wanted; $i++) { ocf_make_group(random_line(), 0, 0, 0, random_line(), '', NULL, NULL, NULL, 5, 0, 70, 50, 100, 100, 30000, 700, 25, 1, 0, 0, 0, $i, 1, 0, 1); } echo 'done club stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // galleries under a subcategory require_code('galleries2'); $xsubcat_id = uniqid('', true); add_gallery($xsubcat_id, random_line(), random_text(), '', '', 'root'); for ($i = $GLOBALS['SITE_DB']->query_value('galleries', 'COUNT(*)'); $i < $num_wanted; $i++) { add_gallery(uniqid('', true), random_line(), random_text(), '', '', $xsubcat_id); } // images require_code('galleries2'); for ($i = $GLOBALS['SITE_DB']->query_value('images', 'COUNT(*)'); $i < $num_wanted; $i++) { add_image('', 'root', random_text(), get_logo_url(), get_logo_url(), 1, 1, 1, 1, ''); } // videos / validation queue require_code('galleries2'); for ($i = $GLOBALS['SITE_DB']->query_value('videos', 'COUNT(*)'); $i < $num_wanted; $i++) { add_video('', 'root', random_text(), get_logo_url(), get_logo_url(), 0, 1, 1, 1, '', 0, 0, 0); } echo 'done galleries stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // newsletter subscribers require_code('newsletter'); for ($i = $GLOBALS['SITE_DB']->query_value('newsletter', 'COUNT(*)'); $i < $num_wanted; $i++) { basic_newsletter_join(uniqid('', true) . '@example.com'); } echo 'done newsletter stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // polls (remember to test poll archive) require_code('polls'); for ($i = $GLOBALS['SITE_DB']->query_value('poll', 'COUNT(*)'); $i < $num_wanted; $i++) { $poll_id = add_poll(random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), random_line(), 10, 0, 0, 0, 0, ''); } // votes on a poll $poll_id = db_get_first_id(); for ($j = $GLOBALS['SITE_DB']->query_value('poll_votes', 'COUNT(*)'); $j < $num_wanted; $j++) { $cast = mt_rand(1, 6); $ip = uniqid('', true); $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $poll_id, 'v_voter_id' => 2, 'v_voter_ip' => $ip, 'v_vote_for' => $cast)); } echo 'done polls stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // quizzes require_code('quiz'); for ($i = $GLOBALS['SITE_DB']->query_value('quizzes', 'COUNT(*)'); $i < $num_wanted; $i++) { add_quiz(random_line(), 0, random_text(), random_text(), random_text(), '', 0, time(), NULL, 3, 300, 'SURVEY', 1, '1) Some question'); } echo 'done quizzes stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // successful searches (to test the search recommender) // ACTUALLY: I have manually verified the code, it is an isolated portion // cedi pages (do a long descendant tree for some, and orphans for others) // cedi posts (remember to test cedi changes screen) require_code('cedi'); for ($i = $GLOBALS['SITE_DB']->query_value('seedy_pages', 'COUNT(*)'); $i < $num_wanted; $i++) { $page_id = cedi_add_page(random_line(), random_text(), '', 1); cedi_add_post($page_id, random_text(), 1, NULL, false); } echo 'done cedi stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // iotds require_code('iotds'); for ($i = $GLOBALS['SITE_DB']->query_value('iotd', 'COUNT(*)'); $i < $num_wanted; $i++) { add_iotd(get_logo_url(), random_line(), random_text(), get_logo_url(), 1, 0, 0, 0, ''); } echo 'done iotd stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // logged hack attempts for ($i = $GLOBALS['SITE_DB']->query_value('hackattack', 'COUNT(*)'); $i < $num_wanted; $i++) { $GLOBALS['SITE_DB']->query_insert('hackattack', array('url' => get_base_url(), 'data_post' => '', 'user_agent' => '', 'referer' => '', 'user_os' => '', 'the_user' => db_get_first_id(), 'date_and_time' => time(), 'ip' => uniqid('', true), 'reason' => 'ASCII_ENTITY_URL_HACK', 'reason_param_a' => '', 'reason_param_b' => '')); } // logged hits in one day require_code('site'); for ($i = $GLOBALS['SITE_DB']->query_value('stats', 'COUNT(*)'); $i < $num_wanted; $i++) { log_stats('/testing' . uniqid('', true), mt_rand(100, 2000)); } echo 'done logs stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // blogs and news entries (remember to test both blogs [categories] list, and a list of all news entries) require_code('news'); for ($i = $GLOBALS['SITE_DB']->query_value('news', 'COUNT(*)'); $i < $num_wanted; $i++) { add_news(random_line(), random_text(), 'admin', 1, 1, 1, 1, '', random_text(), NULL, NULL, NULL, db_get_first_id() + $i); } echo 'done news stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // support tickets require_code('tickets'); require_code('tickets2'); for ($i = intval(floatval($GLOBALS['FORUM_DB']->query_value('f_topics', 'COUNT(*)')) / 2.0); $i < $num_wanted; $i++) { ticket_add_post(mt_rand(db_get_first_id(), $num_wanted - 1), uniqid('', true), db_get_first_id(), random_line(), random_text(), '', ''); } echo 'done tickets stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // catalogues require_code('catalogues2'); $root_id = db_get_first_id(); for ($i = $GLOBALS['SITE_DB']->query_value('catalogues', 'COUNT(*)'); $i < $num_wanted; $i++) { $catalogue_name = uniqid('', true); $root_id = actual_add_catalogue($catalogue_name, random_line(), random_text(), mt_rand(0, 3), 1, '', 30); } // catalogue categories under a subcategory (remember to test all catalogue views: atoz, index, and root cat) $catalogue_name = 'products'; $subcat_id = actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $root_id); for ($j = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'COUNT(*)'); $j < $num_wanted; $j++) { actual_add_catalogue_category($catalogue_name, random_line(), random_text(), '', $subcat_id); } echo 'done catalogue stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } // items in ecommerce store require_code('catalogues2'); $cat_id = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'MIN(id)', array('c_name' => 'products')); $fields = collapse_1d_complexity('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id'), array('c_name' => 'products'))); for ($i = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'COUNT(*)'); $i < $num_wanted; $i++) { $map = array($fields[0] => random_line(), $fields[1] => uniqid('', true), $fields[2] => '1.0', $fields[3] => '1', $fields[4] => '0', $fields[5] => '1', $fields[6] => '0%', $fields[7] => get_logo_url(), $fields[8] => '2.0', $fields[9] => random_text()); $pid = actual_add_catalogue_entry($cat_id, 1, '', 1, 1, 1, $map); unset($map); } // outstanding ecommerce orders $pid = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'MIN(id)', array('c_name' => 'products')); require_code('shopping'); for ($j = $GLOBALS['SITE_DB']->query_value('shopping_cart', 'COUNT(*)'); $j < $num_wanted; $j++) { $product_det = array('product_id' => $pid, 'product_name' => $fields[0], 'product_code' => $fields[1], 'price' => $fields[2], 'tax' => preg_replace('#[^\\d\\.]#', '', $fields[6]), 'description' => $fields[9], 'quantity' => mt_rand(1, 20), 'product_type' => 'catalogue_items', 'product_weight' => $fields[8]); $GLOBALS['SITE_DB']->query_insert('shopping_cart', array('session_id' => mt_rand(0, 1000000), 'ordered_by' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'product_id' => $product_det['product_id'], 'product_name' => $product_det['product_name'], 'product_code' => $product_det['product_code'], 'quantity' => $product_det['quantity'], 'price' => round(floatval($product_det['price']), 2), 'price_pre_tax' => $product_det['tax'], 'product_description' => $product_det['description'], 'product_type' => $product_det['product_type'], 'product_weight' => $product_det['product_weight'], 'is_deleted' => 0)); } for ($j = $GLOBALS['SITE_DB']->query_value('shopping_order', 'COUNT(*)'); $j < $num_wanted; $j++) { $order_id = $GLOBALS['SITE_DB']->query_insert('shopping_order', array('c_member' => mt_rand(db_get_first_id() + 1, $num_wanted - 1), 'session_id' => mt_rand(0, 1000000), 'add_date' => time(), 'tot_price' => '123.00', 'order_status' => 'ORDER_STATUS_awaiting_payment', 'notes' => '', 'purchase_through' => 'purchase_module', 'transaction_id' => '', 'tax_opted_out' => 0), true); $GLOBALS['SITE_DB']->query_insert('shopping_order_details', array('p_id' => 123, 'p_name' => random_line(), 'p_code' => 123, 'p_type' => 'catalogue_items', 'p_quantity' => 1, 'p_price' => '12.00', 'order_id' => $order_id, 'dispatch_status' => '', 'included_tax' => '1.00')); } echo 'done store stuff' . chr(10); if (function_exists('gc_collect_cycles')) { gc_enable(); } echo '{{DONE}}' . chr(10); }
/** * Put out a user interface for managing notifications for a notification-category supporting content type. Also toggle notifications if an ID is passed. * * @param ID_TEXT The notification code to work with * @param ?tempcode Special message to output if we have toggled to enable (NULL: use standard) * @param ?tempcode Special message to output if we have toggled to disable (NULL: use standard) * @return tempcode UI */ function notifications_ui_advanced($notification_code, $enable_message = NULL, $disable_message = NULL) { require_css('notifications'); require_code('notifications'); require_lang('notifications'); require_javascript('javascript_notifications'); require_javascript('javascript_notifications'); require_all_lang(); $test = $GLOBALS['SITE_DB']->query_value_null_ok('notification_lockdown', 'l_setting', array('l_notification_code' => substr($notification_code, 0, 80))); if (!is_null($test)) { warn_exit(do_lang_tempcode('NOTIFICATION_CODE_LOCKED_DOWN')); } $ob = _get_notification_ob_for_code($notification_code); $info_details = $ob->list_handled_codes(); $title = get_page_title('NOTIFICATION_MANAGEMENT_FOR', true, array(escape_html($info_details[$notification_code][1]))); if (is_guest()) { access_denied('NOT_AS_GUEST'); } $db = substr($notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']; if (is_null($enable_message)) { $enable_message = do_lang_tempcode('NOW_ENABLED_NOTIFICATIONS'); } if (is_null($disable_message)) { $disable_message = do_lang_tempcode('NOW_DISABLED_NOTIFICATIONS'); } $_notification_types = _get_available_notification_types(get_member()); $notification_category = get_param('id', NULL); if (!is_null($notification_category)) { if (notifications_enabled($notification_code, $notification_category)) { enable_notifications($notification_code, $notification_category, NULL, A_NA); attach_message($disable_message, 'inform'); } else { enable_notifications($notification_code, $notification_category); attach_message($enable_message, 'inform'); } } else { if (count($_POST) != 0) { enable_notifications($notification_code, NULL, NULL, A_NA); // Make it clear we've overridden the general value by doing this foreach (array_keys($_POST) as $key) { $matches = array(); if (preg_match('#^notification\\_' . preg_quote($notification_code) . '\\_category\\_(.*)#', $key, $matches) != 0) { $notification_category = $matches[1]; $new_setting = A_NA; foreach ($_notification_types as $possible => $ntype) { if (post_param_integer('notification_' . $notification_category . '_' . $ntype, 0) == 1) { $new_setting = $new_setting | $possible; } } enable_notifications($notification_code, $notification_category, NULL, $new_setting); } } attach_message(do_lang_tempcode('SUCCESS'), 'inform'); // Redirect them back $redirect = get_param('redirect', NULL); if (!is_null($redirect)) { return redirect_screen($title, $redirect, do_lang_tempcode('SUCCESS')); } } } $tree = _notifications_build_category_tree($_notification_types, $notification_code, $ob, NULL); $notification_types_titles = array(); foreach ($_notification_types as $possible => $ntype) { $notification_types_titles[] = array('NTYPE' => $ntype, 'LABEL' => do_lang_tempcode('ENABLE_NOTIFICATIONS_' . $ntype), 'RAW' => strval($possible)); } $css_path = get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css'; $color = 'FF00FF'; if (file_exists($css_path)) { $tmp_file = file_get_contents($css_path); $matches = array(); if (preg_match('#\\nth[\\s,][^\\}]*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);#sU', $tmp_file, $matches) != 0) { $color = $matches[1]; } } return do_template('NOTIFICATIONS_MANAGE_ADVANCED_SCREEN', array('TITLE' => $title, 'COLOR' => $color, 'ACTION_URL' => get_self_url(false, false, array('id' => NULL)), 'NOTIFICATION_TYPES_TITLES' => $notification_types_titles, 'TREE' => $tree, 'NOTIFICATION_CODE' => $notification_code)); }