/** * Add a banner to the database, and return the new ID of that banner in the database. * * @param ID_TEXT The name of the banner * @param URLPATH The URL to the banner image * @param SHORT_TEXT The title text for the banner (only used for text banners, and functions as the 'trigger text' if the banner type is shown inline) * @param SHORT_TEXT The caption of the banner * @param ?integer The number of hits the banner may have (NULL: not applicable for this banner type) * @range 0 max * @param URLPATH The URL to the site the banner leads to * @param integer The banners "importance modulus" * @range 1 max * @param LONG_TEXT Any notes associated with the banner * @param SHORT_INTEGER The type of banner (0=permanent, 1=campaign, 2=default) * @set 0 1 2 * @param ?TIME The banner expiry date (NULL: never) * @param ?MEMBER The banners submitter (NULL: current member) * @param BINARY Whether the banner has been validated * @param ID_TEXT The banner type (can be anything, where blank means 'normal') * @param ?TIME The time the banner was added (NULL: now) * @param integer The number of return hits from this banners site * @param integer The number of banner hits to this banners site * @param integer The number of return views from this banners site * @param integer The number of banner views to this banners site * @param ?TIME The banner edit date (NULL: never) */ function add_banner_quiet($name, $imgurl, $title_text, $caption, $campaignremaining, $site_url, $importance_modulus, $notes, $the_type, $expiry_date, $submitter, $validated = 0, $b_type = '', $time = NULL, $hits_from = 0, $hits_to = 0, $views_from = 0, $views_to = 0, $edit_date = NULL) { if (!is_numeric($importance_modulus)) { $importance_modulus = 3; } if (!is_numeric($campaignremaining)) { $campaignremaining = NULL; } if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $test = $GLOBALS['SITE_DB']->query_value_null_ok('banners', 'name', array('name' => $name)); if (is_null($test)) { if (!addon_installed('unvalidated')) { $validated = 1; } $GLOBALS['SITE_DB']->query_insert('banners', array('b_title_text' => $title_text, 'b_type' => $b_type, 'edit_date' => $edit_date, 'add_date' => $time, 'expiry_date' => $expiry_date, 'the_type' => $the_type, 'submitter' => $submitter, 'name' => $name, 'img_url' => $imgurl, 'caption' => insert_lang_comcode($caption, 2), 'campaign_remaining' => $campaignremaining, 'site_url' => $site_url, 'importance_modulus' => $importance_modulus, 'notes' => '', 'validated' => $validated, 'hits_from' => $hits_from, 'hits_to' => $hits_to, 'views_from' => $views_from, 'views_to' => $views_to)); if (function_exists('decache')) { decache('main_banner_wave'); decache('main_topsites'); } log_it('ADD_BANNER', $name, $caption); } }
/** * Standard modular install function. * * @param ?integer What version we're upgrading from (NULL: new install) * @param ?integer What hack version we're upgrading from (NULL: new-install/not-upgrading-from-a-hacked-version) */ function install($upgrade_from = NULL, $upgrade_from_hack = NULL) { if (is_null($upgrade_from)) { require_lang('downloads'); $GLOBALS['SITE_DB']->create_table('download_categories', array('id' => '*AUTO', 'category' => 'SHORT_TRANS', 'parent_id' => '?AUTO_LINK', 'add_date' => 'TIME', 'notes' => 'LONG_TEXT', 'description' => 'LONG_TRANS', 'rep_image' => 'URLPATH')); $lang_key = lang_code_to_default_content('DOWNLOADS_HOME'); $id = $GLOBALS['SITE_DB']->query_insert('download_categories', array('rep_image' => '', 'parent_id' => NULL, 'add_date' => time(), 'notes' => '', 'description' => insert_lang_comcode('', 3), 'category' => $lang_key), true); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'downloads', 'category_name' => strval($id), 'group_id' => $group_id)); } $GLOBALS['SITE_DB']->create_index('download_categories', 'child_find', array('parent_id')); $GLOBALS['SITE_DB']->create_table('download_downloads', array('id' => '*AUTO', 'category_id' => 'AUTO_LINK', 'name' => 'SHORT_TRANS', 'url' => 'URLPATH', 'description' => 'LONG_TRANS', 'author' => 'ID_TEXT', 'comments' => 'LONG_TRANS', 'num_downloads' => 'INTEGER', 'out_mode_id' => '?AUTO_LINK', 'add_date' => 'TIME', 'edit_date' => '?TIME', 'validated' => 'BINARY', 'default_pic' => 'INTEGER', 'file_size' => '?INTEGER', 'allow_rating' => 'BINARY', 'allow_comments' => 'SHORT_INTEGER', 'allow_trackbacks' => 'BINARY', 'notes' => 'LONG_TEXT', 'download_views' => 'INTEGER', 'download_cost' => 'INTEGER', 'download_submitter_gets_points' => 'BINARY', 'submitter' => 'USER', 'original_filename' => 'SHORT_TEXT', 'rep_image' => 'URLPATH', 'download_licence' => '?AUTO_LINK', 'download_data_mash' => 'LONG_TEXT')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'download_views', array('download_views')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'category_list', array('category_id')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'recent_downloads', array('add_date')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'top_downloads', array('num_downloads')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'downloadauthor', array('author')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'dds', array('submitter')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'ddl', array('download_licence')); // For when deleting a download license $GLOBALS['SITE_DB']->create_index('download_downloads', 'dvalidated', array('validated')); $GLOBALS['SITE_DB']->create_table('download_logging', array('id' => '*AUTO_LINK', 'the_user' => '*USER', 'ip' => 'IP', 'date_and_time' => 'TIME')); $GLOBALS['SITE_DB']->create_index('download_logging', 'calculate_bandwidth', array('date_and_time')); add_config_option('MAXIMUM_DOWNLOAD', 'maximum_download', 'integer', 'return \'15\';', 'SITE', 'CLOSED_SITE'); add_config_option('SHOW_DLOAD_TREES', 'show_dload_trees', 'tick', 'return \'0\';', 'FEATURE', 'SECTION_DOWNLOADS', 1); add_config_option('ADD_DOWNLOAD', 'points_ADD_DOWNLOAD', 'integer', 'return addon_installed(\'points\')?\'150\':NULL;', 'POINTS', 'COUNT_POINTS_GIVEN'); require_lang('downloads'); add_menu_item_simple('main_content', NULL, 'SECTION_DOWNLOADS', '_SEARCH:downloads:type=misc'); $GLOBALS['SITE_DB']->create_index('download_downloads', 'ftjoin_dname', array('name')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'ftjoin_ddescrip', array('description')); $GLOBALS['SITE_DB']->create_index('download_downloads', 'ftjoin_dcomments', array('comments')); $GLOBALS['SITE_DB']->create_index('download_categories', 'ftjoin_dccat', array('category')); $GLOBALS['SITE_DB']->create_index('download_categories', 'ftjoin_dcdescrip', array('description')); } if (!is_null($upgrade_from) && $upgrade_from < 3) { $GLOBALS['SITE_DB']->add_table_field('download_downloads', 'allow_trackbacks', 'BINARY', 1); $GLOBALS['SITE_DB']->add_table_field('download_categories', 'rep_image', 'URLPATH'); } if (!is_null($upgrade_from) && $upgrade_from < 5) { $GLOBALS['SITE_DB']->add_table_field('download_downloads', 'download_licence', '?AUTO_LINK', NULL); $GLOBALS['SITE_DB']->add_table_field('download_downloads', 'download_data_mash', 'LONG_TEXT'); delete_config_option('is_on_downloads'); } if (is_null($upgrade_from) || $upgrade_from < 5) { $GLOBALS['SITE_DB']->create_index('download_downloads', '#download_data_mash', array('download_data_mash')); $GLOBALS['SITE_DB']->create_index('download_downloads', '#original_filename', array('original_filename')); $GLOBALS['SITE_DB']->create_table('download_licences', array('id' => '*AUTO', 'l_title' => 'SHORT_TEXT', 'l_text' => 'LONG_TEXT')); add_config_option('_SECTION_DOWNLOADS', 'downloads_show_stats_count_total', 'tick', 'return addon_installed(\'stats_block\')?\'0\':NULL;', 'BLOCKS', 'STATISTICS'); add_config_option('TOTAL_DOWNLOADS_IN_ARCHIVE', 'downloads_show_stats_count_archive', 'tick', 'return addon_installed(\'stats_block\')?\'0\':NULL;', 'BLOCKS', 'STATISTICS'); add_config_option('_COUNT_DOWNLOADS', 'downloads_show_stats_count_downloads', 'tick', 'return addon_installed(\'stats_block\')?\'0\':NULL;', 'BLOCKS', 'STATISTICS'); add_config_option('_COUNT_BANDWIDTH', 'downloads_show_stats_count_bandwidth', 'tick', 'return addon_installed(\'stats_block\')?\'0\':NULL;', 'BLOCKS', 'STATISTICS'); add_config_option('IMMEDIATE_DOWNLOADS', 'immediate_downloads', 'tick', 'return \'0\';', 'FEATURE', 'SECTION_DOWNLOADS'); } if (is_null($upgrade_from) || $upgrade_from < 6) { add_config_option('DOWNLOAD_GALLERY_ROOT', 'download_gallery_root', 'line', 'return is_null($old=get_value(\'download_gallery_root\'))?(addon_installed(\'galleries\')?\'root\':NULL):$old;', 'FEATURE', 'SECTION_DOWNLOADS'); } }
/** * Add a flagrant text message. * * @param SHORT_TEXT The message * @param integer The number of days to display for * @param LONG_TEXT Notes * @param BINARY Whether the message is for immediate use * @return AUTO_LINK The ID of the newly added message */ function add_flagrant($message, $days, $notes, $validated) { $order_time = time(); $id = $GLOBALS['SITE_DB']->query_insert('text', array('notes' => $notes, 'activation_time' => NULL, 'active_now' => 0, 'the_message' => insert_lang_comcode($message, 2), 'days' => $days, 'order_time' => $order_time, 'user_id' => get_member()), true); log_it('ADD_FLAGRANT', strval($id), $message); if ($validated == 1) { choose_flagrant($id); } return $id; }
/** * Get some info bits relating to our field type, that helps us look it up / set defaults. * * @param ?array The field details (NULL: new field) * @param ?boolean Whether a default value cannot be blank (NULL: don't "lock in" a new default value) * @param ?string The given default value as a string (NULL: don't "lock in" a new default value) * @param ?object Database connection (NULL: main site database) * @return array Tuple of details (row-type,default-value-to-use,db row-type) */ function get_field_value_row_bits($field, $required = NULL, $default = NULL, $db = NULL) { unset($field); if (!is_null($required)) { if ($required && $default == '') { $default = 'default'; } $default = strval(insert_lang_comcode($default, 3, $db)); } return array('long_trans', $default, 'long_trans'); }
/** * Add an IOTD to the database and return the ID of the new entry. * * @param URLPATH The URL to the IOTD image * @param SHORT_TEXT The IOTD title * @param LONG_TEXT The IOTD caption * @param URLPATH The URL to the IOTD thumbnail image * @param BINARY Whether the IOTD is currently in use (note: setting this to 1 will not actually set the IOTD, and if it is 1, then the IOTD must be explicitly set only to this) * @param BINARY Whether the IOTD may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the IOTD may be trackbacked * @param LONG_TEXT Notes for the IOTD * @param ?TIME The time of submission (NULL: now) * @param ?MEMBER The IOTD submitter (NULL: current member) * @param BINARY Whether the IOTD has been used before * @param ?TIME The time the IOTD was used (NULL: never) * @param integer The number of views had * @param ?TIME The edit date (NULL: never) * @return AUTO_LINK The ID of the IOTD just added */ function add_iotd($url, $title, $caption, $thumb_url, $current, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $time = NULL, $submitter = NULL, $used = 0, $use_time = NULL, $views = 0, $edit_date = NULL) { if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $id = $GLOBALS['SITE_DB']->query_insert('iotd', array('i_title' => insert_lang_comcode($title, 2), 'add_date' => time(), 'edit_date' => $edit_date, 'iotd_views' => $views, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'date_and_time' => $use_time, 'used' => $used, 'url' => $url, 'caption' => insert_lang_comcode($caption, 2), 'thumb_url' => $thumb_url, 'submitter' => $submitter, 'is_current' => $current), true); log_it('ADD_IOTD', strval($id), $caption); return $id; }
/** * Transfer gift-points into the specified member's account, courtesy of the system. * * @param SHORT_TEXT The reason for the transfer * @param integer The size of the transfer * @param MEMBER The member the transfer is to */ function system_gift_transfer($reason, $amount, $member_id) { require_lang('points'); require_code('points'); if (is_guest($member_id)) { return; } if ($amount == 0) { return; } $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'gift_to' => $member_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => 1)); $_before = point_info($member_id); $before = array_key_exists('points_gained_given', $_before) ? $_before['points_gained_given'] : 0; $new = strval($before + $amount); $GLOBALS['FORUM_DRIVER']->set_custom_field($member_id, 'points_gained_given', $new); global $TOTAL_POINTS_CACHE, $POINT_INFO_CACHE; if (array_key_exists($member_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$member_id] += $amount; } if (array_key_exists($member_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$member_id])) { $POINT_INFO_CACHE[$member_id]['points_gained_given'] += $amount; } //start add to mentor points if needed //$mentor_id=$GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id,'u_mentor'); $mentor_id = $GLOBALS['SITE_DB']->query_value_null_ok('members_mentors', 'mentor_id', array('member_id' => $member_id), '', true); if (isset($mentor_id) && !is_null($mentor_id) && intval($mentor_id) != 0) { //give points to mentor too $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => time(), 'amount' => $amount, 'gift_from' => $GLOBALS['FORUM_DRIVER']->get_guest_id(), 'gift_to' => $mentor_id, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => 1)); $_before = point_info($mentor_id); $before = array_key_exists('points_gained_given', $_before) ? $_before['points_gained_given'] : 0; $new = strval($before + $amount); $GLOBALS['FORUM_DRIVER']->set_custom_field($mentor_id, 'points_gained_given', $new); if (array_key_exists($mentor_id, $TOTAL_POINTS_CACHE)) { $TOTAL_POINTS_CACHE[$mentor_id] += $amount; } if (array_key_exists($mentor_id, $POINT_INFO_CACHE) && array_key_exists('points_gained_given', $POINT_INFO_CACHE[$mentor_id])) { $POINT_INFO_CACHE[$mentor_id]['points_gained_given'] += $amount; } } if (get_forum_type() == 'ocf') { require_code('ocf_posts_action'); require_code('ocf_posts_action2'); ocf_member_handle_promotion($member_id); } }
function setUp() { parent::setUp(); require_code('calendar2'); require_code('feedback'); require_code('ocf_posts_action'); require_code('ocf_forum_driver_helper'); require_lang('lang'); $this->event_id = add_calendar_event(8, '1', NULL, 0, 'test_event', '', 3, 1, 2010, 1, 10, 10, 15, 2010, NULL, 1, 1, 19, NULL, 1, 1, 1, 1, 1, '', NULL, 0, NULL, NULL, NULL); if ('test_event' == get_translated_text($GLOBALS['SITE_DB']->query_value('calendar_events', 'e_title ', array('id' => $this->event_id)))) { $lang_id = insert_lang_comcode('test_comment_desc_1', 4, $GLOBALS['FORUM_DB']); $map = array('p_title' => 'test_comment1', 'p_post' => $lang_id, 'p_ip_address' => '127.0.0.1', 'p_time' => time(), 'p_poster' => 0, 'p_poster_name_if_guest' => '', 'p_validated' => 1, 'p_topic_id' => 4, 'p_is_emphasised' => 0, 'p_cache_forum_id' => 4, 'p_last_edit_time' => NULL, 'p_last_edit_by' => NULL, 'p_intended_solely_for' => NULL, 'p_skip_sig' => 0, 'p_parent_id' => NULL); $this->post_id = $GLOBALS['FORUM_DB']->query_insert('f_posts', $map, true); } $rows = $GLOBALS['FORUM_DB']->query('SELECT p_title FROM ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'f_posts p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON t.id=p.p_post WHERE t.text_original NOT LIKE \'%' . db_encode_like(do_lang('SPACER_POST_MATCHER', '', '', '', get_site_default_lang()) . '%') . '\' AND ( p.id = ' . strval($this->post_id) . ') ORDER BY p.id'); $title = $rows[0]['p_title']; // Test the forum was actually created $this->assertTrue('test_comment1' == $title); }
/** * Add a download. * * @param AUTO_LINK The ID of the category the download is to be in * @param SHORT_TEXT The name of the download * @param URLPATH The URL to the download * @param LONG_TEXT The description of the download * @param ID_TEXT The author of the download (not necessarily same as the submitter) * @param LONG_TEXT The comments for the download * @param ?AUTO_LINK The out-mode-id (the ID of a download that this download is an old version of). Often people wonder why this is specified with the old version, and not the opposite with the new version - it is because statistically, we perceive more chance of downloads merging than splitting (NULL: none) * @param BINARY Whether the download has been validated * @param BINARY Whether the download may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the download may be trackbacked * @param LONG_TEXT Hidden notes pertaining to the download * @param SHORT_TEXT The downloads original filename (the URL may be obfuscated) * @param integer The file size of the download (we can't really detect this in real-time for remote URLs) * @param integer The cost of the download that members will have to pay to get it * @param BINARY Whether the submitter gets the points for the download (they are selling it) (otherwise they are just thrown out, which is an alternative model - one of enforcing community point building) * @param ?AUTO_LINK The licence to use (NULL: none) * @param ?TIME The add date for the download (NULL: now) * @param integer The number of downloads that this download has had * @param integer The number of views that this download has had * @param ?MEMBER The submitter (NULL: current user) * @param ?TIME The edit date (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the newly added download */ function add_download($category_id, $name, $url, $description, $author, $comments, $out_mode_id, $validated, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $original_filename, $file_size, $cost, $submitter_gets_points, $licence = NULL, $add_date = NULL, $num_downloads = 0, $views = 0, $submitter = NULL, $edit_date = NULL, $id = NULL) { if (is_null($add_date)) { $add_date = time(); } if (is_null($submitter)) { $submitter = get_member(); } if ($file_size == 0 || url_is_local($url)) { if (url_is_local($url)) { $file_size = @filesize(get_custom_file_base() . '/' . rawurldecode($url)) or $file_size = NULL; } else { $file_size = @filesize($url) or $file_size = NULL; } } $met = @ini_get('max_execution_time'); $data_mash = $url == '' ? '' : create_data_mash($url, NULL, get_file_extension($original_filename)); if (function_exists('set_time_limit')) { @set_time_limit($met); } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('download_data_mash' => $data_mash, 'download_licence' => $licence, 'rep_image' => '', 'edit_date' => $edit_date, 'download_submitter_gets_points' => $submitter_gets_points, 'download_cost' => $cost, 'original_filename' => $original_filename, 'download_views' => $views, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'submitter' => $submitter, 'default_pic' => 1, 'num_downloads' => $num_downloads, 'out_mode_id' => $out_mode_id, 'category_id' => $category_id, 'name' => insert_lang($name, 2), 'url' => $url, 'description' => insert_lang_comcode($description, 3), 'author' => $author, 'comments' => insert_lang_comcode($comments, 3), 'validated' => $validated, 'add_date' => $add_date, 'file_size' => $file_size); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('download_downloads', $map, true); require_code('seo2'); seo_meta_set_for_implicit('downloads_download', strval($id), array($name, $description, $comments), $description); // Make its gallery if (addon_installed('galleries') && !running_script('stress_test_loader')) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('name' => 'download_' . strval($id))); if (is_null($test)) { require_code('galleries2'); $download_gallery_root = get_option('download_gallery_root'); if (is_null($download_gallery_root)) { $download_gallery_root = 'root'; } add_gallery('download_' . strval($id), do_lang('GALLERY_FOR_DOWNLOAD', $name), '', '', '', $download_gallery_root); } } // Stat update_stat('num_archive_downloads', 1); if ($file_size > 0) { update_stat('archive_size', $file_size); } if ($validated == 1) { require_lang('downloads'); require_code('notifications'); $subject = do_lang('DOWNLOAD_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $name); $self_url = build_url(array('page' => 'downloads', 'type' => 'entry', 'id' => $id), get_module_zone('downloads'), NULL, false, false, true); $mail = do_lang('DOWNLOAD_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($name), array(comcode_escape($self_url->evaluate()))); dispatch_notification('download', strval($category_id), $subject, $mail); } log_it('ADD_DOWNLOAD', strval($id), $name); decache('main_recent_downloads'); decache('main_top_downloads'); decache('main_download_category'); decache('main_download_tease'); return $id; }
/** * The actualiser for editing a message. * * @return tempcode The UI. */ function _chat_edit_message() { breadcrumb_set_self(do_lang_tempcode('DONE')); $delete = post_param_integer('delete', 0); if ($delete == 1) { return $this->_chat_delete_message(); } else { $message_id = get_param_integer('id'); $room_id = $GLOBALS['SITE_DB']->query_value_null_ok('chat_messages', 'room_id', array('id' => $message_id)); if (is_null($room_id)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } check_chatroom_access($room_id); $room_details = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('id' => $room_id), '', 1); if (!array_key_exists(0, $room_details)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $row = $room_details[0]; $has_mod_access = has_specific_permission(get_member(), 'edit_lowrange_content', 'cms_chat', array('chat', $room_id)) || $row['room_owner'] == get_member() && has_specific_permission(get_member(), 'moderate_my_private_rooms'); if (!$has_mod_access) { access_denied('SPECIFIC_PERMISSION', 'edit_lowrange_content'); } $title = get_page_title('EDIT_MESSAGE'); $_message_parsed = insert_lang_comcode(wordfilter_text(post_param('message')), 4); $GLOBALS['SITE_DB']->query_update('chat_messages', array('the_message' => $_message_parsed, 'text_colour' => post_param('textcolour'), 'font_name' => post_param('fontname')), array('id' => $message_id), '', 1); log_it('EDIT_MESSAGE', strval($message_id), post_param('message')); decache('side_shoutbox'); require_code('templates_donext'); return do_next_manager($title, do_lang_tempcode('SUCCESS'), NULL, NULL, NULL, array('_SELF', array('type' => 'ed', 'id' => $message_id, 'room_id' => $room_id), '_SELF'), array('_SELF', array('type' => 'room', 'id' => $room_id), '_SELF'), NULL, array('_SELF', array(), '_SELF'), NULL, NULL, NULL, NULL, NULL, array(), array(), array(has_actual_page_access(get_member(), 'admin_chat') ? array('chatrooms', array('admin_chat', array('type' => 'misc'), get_module_zone('admin_chat')), do_lang('ROOMS')) : NULL), do_lang('SETUP')); } }
/** * Parse room creation chat code tag. * * @param string The room name * @param string Comma-separated list of members to allow in * @param SHORT_TEXT The username of who made this chatcode * @param string The text we are using * @param ?integer The maximum number of messages to be returned (NULL: no maximum) * @return array A pair: whether the message was deleted, and the new text of the message */ function _deal_with_chatcode_newroom($pm_user, $pm_message, $username, $text, $cutoff) { $pm_message_deleted = false; if (!has_specific_permission(get_member(), 'create_private_room')) { return array('pm_message_deleted' => $pm_message_deleted, 'text' => $text); } // This deals with the [newroom="roomname"]allowlist[/newroom] tag // We need to send invitations to all the people on the allow list // Create the room if it hasn't already been created $_row = $GLOBALS['SITE_DB']->query_select('chat_rooms', array('*'), array('room_name' => $pm_user), '', $cutoff); if (!array_key_exists(0, $_row)) { $new_room_id = $GLOBALS['SITE_DB']->query_insert('chat_rooms', array('is_im' => 0, 'room_name' => $pm_user, 'room_owner' => $GLOBALS['FORUM_DRIVER']->get_member_from_username($username), 'allow_list' => parse_allow_list_input($pm_message), 'disallow_list' => '', 'allow_list_groups' => '', 'disallow_list_groups' => '', 'c_welcome' => insert_lang('', 3), 'room_language' => user_lang()), true); $rooms = chat_get_all_rooms(); // For each person in the allow list, insert a private message into every room (except the new one) asking them to join the new room $_pm_message = explode(',', $pm_message); foreach ($_pm_message as $person) { if ($person != $GLOBALS['FORUM_DRIVER']->get_username(get_member()) && $person != do_lang('GUEST')) { foreach ($rooms as $room) { if ($room['id'] != $new_room_id) { $_message_parsed = insert_lang_comcode('[invite="' . $person . '"]' . get_chatroom_name($new_room_id) . '[/invite]', 4); $message_id = $GLOBALS['SITE_DB']->query_insert('chat_messages', array('ip_address' => get_ip_address(), 'room_id' => $room['id'], 'user_id' => get_member(), 'date_and_time' => time(), 'the_message' => $_message_parsed, 'text_colour' => get_option('chat_default_post_colour'), 'font_name' => get_option('chat_default_post_font')), true); $myfile = @fopen(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat', 'wb') or intelligent_write_error(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); fwrite($myfile, strval($message_id)); fclose($myfile); sync_file(get_custom_file_base() . '/data_custom/modules/chat/chat_last_msg.dat'); } } } } } $text = preg_replace('#\\[newroom="([^&]*)"\\]([^\\[]*)\\[/newroom\\]#', '', $text, 1); if (is_null($text) || $text == '') { $pm_message_deleted = true; } return array('pm_message_deleted' => $pm_message_deleted, 'text' => $text); }
/** * 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_cedi($db, $table_prefix, $file_base) { if (!import_check_if_imported('cedi_page', strval(db_get_first_id()))) { import_id_remap_put('cedi_page', strval(db_get_first_id()), db_get_first_id()); } $rows_pages = $db->query('SELECT * FROM ' . $table_prefix . 'seedy_pages', NULL, NULL, true); if (is_null($rows_pages)) { return; } $titlemap = array(); foreach ($rows_pages as $row) { $title = $this->get_lang_string($db, $row['title']); if (import_check_if_imported('cedi_page', strval($row['id']))) { $id = import_id_remap_get('cedi_page', strval($row['id'])); $titlemap[$id] = $title; continue; } $titlemap[$id] = $title; $id = $GLOBALS['SITE_DB']->query_insert('seedy_pages', array('submitter' => array_key_exists('submitter', $row) ? $row['submitter'] : get_member(), 'hide_posts' => array_key_exists('hide_posts', $row) ? $row['hide_posts'] : 0, 'seedy_views' => array_key_exists('seedy_views', $row) ? $row['seedy_views'] : 0, 'notes' => $row['notes'], 'description' => insert_lang_comcode($this->get_lang_string($db, $row['description']), 2), 'add_date' => $row['add_date'], 'title' => insert_lang($title, 2)), true); import_id_remap_put('cedi_page', strval($row['id']), $id); } $this->_import_catalogue_entry_linkage($db, $table_prefix, 'cedi_page', 'cedi_page'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'seedy_posts'); $on_same_msn = $this->on_same_msn($file_base); foreach ($rows as $row) { if (import_check_if_imported('cedi_post', strval($row['id']))) { continue; } $page_id = import_id_remap_get('cedi_page', $row['page_id'], true); if (is_null($page_id)) { $page_id = db_get_first_id(); } $user = $on_same_msn ? $row['the_user'] : import_id_remap_get('member', $row['the_user'], true); if (is_null($user)) { $user = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } $id_new = $GLOBALS['SITE_DB']->query_insert('seedy_posts', array('seedy_views' => array_key_exists('seedy_views', $row) ? $row['seedy_views'] : 0, 'validated' => array_key_exists('validated', $row) ? $row['validated'] : 1, 'the_message' => insert_lang_comcode($this->get_lang_string($db, $row['the_message']), 2), 'the_user' => $user, 'date_and_time' => $row['date_and_time'], 'page_id' => $page_id, 'edit_date' => $row['edit_date']), true); import_id_remap_put('cedi_post', strval($row['id']), $id_new); } $this->_import_catalogue_entry_linkage($db, $table_prefix, 'cedi_post', 'cedi_post'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'seedy_changes'); foreach ($rows as $row) { $page_id = import_id_remap_get('cedi_page', $row['the_page'], true); if (is_null($page_id)) { continue; } $user = $on_same_msn ? $row['the_user'] : import_id_remap_get('member', $row['the_user'], true); if (is_null($user)) { $user = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } $GLOBALS['SITE_DB']->query_insert('seedy_changes', array('the_action' => $row['the_action'], 'the_page' => $page_id, 'ip' => $row['ip'], 'the_user' => $user, 'date_and_time' => $row['date_and_time']), false, true); } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'seedy_children'); foreach ($rows as $row) { $child_id = import_id_remap_get('cedi_page', $row['child_id'], true); $parent_id = import_id_remap_get('cedi_page', $row['parent_id'], true); if (is_null($child_id)) { continue; } if (is_null($parent_id)) { continue; } if (array_key_exists($child_id, $titlemap)) { $title = $titlemap[$child_id]; } elseif (array_key_exists($child_id, $rows_pages)) { $title = $this->get_lang_string($db, $rows_pages[$child_id]['title']); } else { continue; } $GLOBALS['SITE_DB']->query_insert('seedy_children', array('parent_id' => $parent_id, 'child_id' => $child_id, 'the_order' => $row['the_order'], 'title' => $titlemap[$child_id]), false, true); } }
/** * Adds a news entry to the database, and send out the news to any RSS cloud listeners. * * @param SHORT_TEXT The news title * @param LONG_TEXT The news summary (or if not an article, the full news) * @param ?ID_TEXT The news author (possibly, a link to an existing author in the system, but does not need to be) (NULL: current username) * @param BINARY Whether the news has been validated * @param BINARY Whether the news may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the news may have trackbacks * @param LONG_TEXT Notes for the news * @param LONG_TEXT The news entry (blank means no entry) * @param ?AUTO_LINK The primary news category (NULL: personal) * @param ?array The IDs of the news categories that this is in (NULL: none) * @param ?TIME The time of submission (NULL: now) * @param ?MEMBER The news submitter (NULL: current member) * @param integer The number of views the article has had * @param ?TIME The edit date (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param URLPATH URL to the image for the news entry (blank: use cat image) * @return AUTO_LINK The ID of the news just added */ function add_news($title, $news, $author = NULL, $validated = 1, $allow_rating = 1, $allow_comments = 1, $allow_trackbacks = 1, $notes = '', $news_article = '', $main_news_category = NULL, $news_category = NULL, $time = NULL, $submitter = NULL, $views = 0, $edit_date = NULL, $id = NULL, $image = '') { if (is_null($author)) { $author = $GLOBALS['FORUM_DRIVER']->get_username(get_member()); } if (is_null($news_category)) { $news_category = array(); } if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $already_created_personal_category = false; require_code('comcode_check'); check_comcode($news_article, NULL, false, NULL, true); if (is_null($main_news_category)) { $main_news_category_id = $GLOBALS['SITE_DB']->query_value_null_ok('news_categories', 'id', array('nc_owner' => $submitter)); if (is_null($main_news_category_id)) { if (!has_specific_permission(get_member(), 'have_personal_category', 'cms_news')) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } $p_nc_title = insert_lang(do_lang('MEMBER_CATEGORY', $GLOBALS['FORUM_DRIVER']->get_username($submitter)), 2); $main_news_category_id = $GLOBALS['SITE_DB']->query_insert('news_categories', array('nc_title' => $p_nc_title, 'nc_img' => 'newscats/community', 'notes' => '', 'nc_owner' => $submitter), true); $already_created_personal_category = true; $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'news', 'category_name' => strval($main_news_category_id), 'group_id' => $group_id)); } } } else { $main_news_category_id = $main_news_category; } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('news_image' => $image, 'edit_date' => $edit_date, 'news_category' => $main_news_category_id, 'news_views' => $views, 'news_article' => 0, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes, 'submitter' => $submitter, 'validated' => $validated, 'date_and_time' => $time, 'title' => insert_lang_comcode($title, 1), 'news' => insert_lang_comcode($news, 1), 'author' => $author); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('news', $map, true); if (!is_null($news_category)) { $news_category = array_unique($news_category); foreach ($news_category as $value) { if (is_null($value) && !$already_created_personal_category) { $p_nc_title = insert_lang(do_lang('MEMBER_CATEGORY', $GLOBALS['FORUM_DRIVER']->get_username($submitter)), 2); $news_category_id = $GLOBALS['SITE_DB']->query_insert('news_categories', array('nc_title' => $p_nc_title, 'nc_img' => 'newscats/community', 'notes' => '', 'nc_owner' => $submitter), true); $groups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(false, true); foreach (array_keys($groups) as $group_id) { $GLOBALS['SITE_DB']->query_insert('group_category_access', array('module_the_name' => 'news', 'category_name' => strval($news_category_id), 'group_id' => $group_id)); } } else { $news_category_id = $value; } if (is_null($news_category_id)) { continue; } // Double selected $GLOBALS['SITE_DB']->query_insert('news_category_entries', array('news_entry' => $id, 'news_entry_category' => $news_category_id)); } } require_code('attachments2'); $map = array('news_article' => insert_lang_comcode_attachments(2, $news_article, 'news', strval($id))); $GLOBALS['SITE_DB']->query_update('news', $map, array('id' => $id), '', 1); log_it('ADD_NEWS', strval($id), $title); if (function_exists('xmlrpc_encode')) { if (function_exists('set_time_limit')) { @set_time_limit(0); } // Send out on RSS cloud $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'news_rss_cloud WHERE register_time<' . strval(time() - 25 * 60 * 60)); $start = 0; do { $listeners = $GLOBALS['SITE_DB']->query_select('news_rss_cloud', array('*'), NULL, '', 100, $start); foreach ($listeners as $listener) { $data = $listener['watching_channel']; if ($listener['rem_protocol'] == 'xml-rpc') { $request = xmlrpc_encode_request($listener['rem_procedure'], $data); $length = strlen($request); $_length = strval($length); $packet = <<<END POST /{$listener['rem_path']} HTTP/1.0 Host: {$listener['rem_ip']} Content-Type: text/xml Content-length: {$_length} {$request} END; } $errno = 0; $errstr = ''; $mysock = @fsockopen($listener['rem_ip'], $listener['rem_port'], $errno, $errstr, 6.0); if ($mysock !== false) { @fwrite($mysock, $packet); @fclose($mysock); } $start += 100; } } while (array_key_exists(0, $listeners)); } require_code('seo2'); seo_meta_set_for_implicit('news', strval($id), array($title, $news == '' ? $news_article : $news), $news == '' ? $news_article : $news); // News article could be used, but it's probably better to go for the summary only to avoid crap if ($validated == 1) { decache('main_news'); decache('side_news'); decache('side_news_archive'); decache('bottom_news'); dispatch_news_notification($id, $title, $main_news_category_id); } if ($validated == 1 && get_option('site_closed') == '0' && ocp_srv('HTTP_HOST') != '127.0.0.1' && ocp_srv('HTTP_HOST') != 'localhost' && has_category_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), 'news', strval($main_news_category_id))) { $_ping_url = str_replace('{url}', urlencode(get_base_url()), str_replace('{rss}', urlencode(find_script('backend') . '?type=rss&mode=news'), str_replace('{title}', urlencode(get_site_name()), get_option('ping_url')))); $ping_urls = explode(chr(10), $_ping_url); foreach ($ping_urls as $ping_url) { $ping_url = trim($ping_url); if ($ping_url != '') { http_download_file($ping_url, NULL, false); } } } return $id; }
/** * Convert a language string that is Comcode to tempcode, with potential cacheing in the db. * * @param ID_TEXT The language string ID * @return tempcode The parsed Comcode */ function _comcode_lang_string($lang_code) { global $COMCODE_LANG_STRING_CACHE; if (array_key_exists($lang_code, $COMCODE_LANG_STRING_CACHE)) { return $COMCODE_LANG_STRING_CACHE[$lang_code]; } $comcode_page = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages p LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON t.id=string_index AND ' . db_string_equal_to('t.language', user_lang()), array('string_index', 'text_parsed'), array('the_page' => $lang_code, 'the_zone' => '!'), '', 1); if (array_key_exists(0, $comcode_page) && !is_browser_decacheing()) { if (!is_null($comcode_page[0]['text_parsed']) && $comcode_page[0]['text_parsed'] != '') { $parsed = new ocp_tempcode(); if (!$parsed->from_assembly($comcode_page[0]['text_parsed'], true)) { $ret = get_translated_tempcode($comcode_page[0]['string_index']); unset($GLOBALS['RECORDED_LANG_STRINGS_CONTENT'][$comcode_page[0]['string_index']]); } } else { $ret = get_translated_tempcode($comcode_page[0]['string_index'], NULL, NULL, true); if (is_null($ret)) { $looked_up = do_lang($lang_code, NULL, NULL, NULL, NULL, false); $GLOBALS['SITE_DB']->query_insert('translate', array('id' => $comcode_page[0]['string_index'], 'source_user' => get_member(), 'broken' => 0, 'importance_level' => 1, 'text_original' => $looked_up, 'text_parsed' => '', 'language' => user_lang()), true, false, true); $ret = get_translated_tempcode($comcode_page[0]['string_index']); } unset($GLOBALS['RECORDED_LANG_STRINGS_CONTENT'][$comcode_page[0]['string_index']]); return $ret; } $COMCODE_LANG_STRING_CACHE[$lang_code] = $parsed; return $parsed; } elseif (array_key_exists(0, $comcode_page)) { $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_page' => $lang_code, 'the_zone' => '!')); delete_lang($comcode_page[0]['string_index']); } $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $looked_up = do_lang($lang_code, NULL, NULL, NULL, NULL, false); if (is_null($looked_up)) { return make_string_tempcode(escape_html('{!' . $lang_code . '}')); } $index = insert_lang_comcode($looked_up, 4, NULL, true, NULL, 60, false, true); $GLOBALS['SITE_DB']->query_insert('cached_comcode_pages', array('the_zone' => '!', 'the_page' => $lang_code, 'string_index' => $index, 'the_theme' => $GLOBALS['FORUM_DRIVER']->get_theme(), 'cc_page_title' => NULL), false, true); // Race conditions $parsed = get_translated_tempcode($index); $COMCODE_LANG_STRING_CACHE[$lang_code] = $parsed; $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; return $parsed; }
/** * Edit the specified catalogue entry * * @param AUTO_LINK The ID of the entry being edited * @param AUTO_LINK The ID of the category that the entry is in * @param BINARY Whether the entry has been validated * @param LONG_TEXT Hidden notes pertaining to the entry * @param BINARY Whether the entry may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the entry may be trackbacked * @param array A map of field IDs, to values, that defines the entries settings * @param ?SHORT_TEXT Meta keywords for this resource (NULL: do not edit) * @param ?LONG_TEXT Meta description for this resource (NULL: do not edit) */ function actual_edit_catalogue_entry($id, $category_id, $validated, $notes, $allow_rating, $allow_comments, $allow_trackbacks, $map, $meta_keywords = '', $meta_description = '') { $catalogue_name = $GLOBALS['SITE_DB']->query_value('catalogue_categories', 'c_name', array('id' => $category_id)); $catalogue_title = get_translated_text($GLOBALS['SITE_DB']->query_value('catalogues', 'c_title', array('c_name' => $catalogue_name))); $_fields = list_to_map('id', $GLOBALS['SITE_DB']->query_select('catalogue_fields', array('id', 'cf_type'), array('c_name' => $catalogue_name))); $fields = collapse_2d_complexity('id', 'cf_type', $_fields); $original_submitter = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'ce_submitter', array('id' => $id)); $old_category_id = $GLOBALS['SITE_DB']->query_value('catalogue_entries', 'cc_id', array('id' => $id)); if (!addon_installed('unvalidated')) { $validated = 1; } require_code('submit'); $was_validated = content_validated('catalogue_entry', strval($id)); $just_validated = !$was_validated && $validated == 1; if ($just_validated) { send_content_validated_notification('catalogue_entry', strval($id)); } $GLOBALS['SITE_DB']->query_update('catalogue_entries', array('ce_edit_date' => time(), 'cc_id' => $category_id, 'ce_validated' => $validated, 'notes' => $notes, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks), array('id' => $id), '', 1); require_code('fields'); $title = NULL; foreach ($map as $field_id => $val) { if (is_null($title)) { $title = $val; } $type = $fields[$field_id]; $ob = get_fields_hook($type); list(, , $sup_table_name) = $ob->get_field_value_row_bits($_fields[$field_id]); if (substr($sup_table_name, -6) == '_trans') { $_val = $GLOBALS['SITE_DB']->query_value_null_ok('catalogue_efv_' . $sup_table_name, 'cv_value', array('cf_id' => $field_id, 'ce_id' => $id)); if (is_null($_val)) { $_val = insert_lang_comcode($val, 3); } else { if ($type == 'posting_field') { require_code('attachments2'); require_code('attachments3'); $_val = update_lang_comcode_attachments($_val, $val, 'catalogue_entry', strval($id), NULL, false, $original_submitter); } else { $_val = lang_remap_comcode($_val, $val); } } $GLOBALS['SITE_DB']->query_update('catalogue_efv_' . $sup_table_name, array('cv_value' => $_val), array('cf_id' => $field_id, 'ce_id' => $id), '', 1); } else { if ($sup_table_name == 'float') { $smap = array('cv_value' => is_null($val) || $val == '' ? NULL : floatval($val)); } elseif ($sup_table_name == 'integer') { $smap = array('cv_value' => is_null($val) || $val == '' ? NULL : intval($val)); } else { $smap = array('cv_value' => $val); } $GLOBALS['SITE_DB']->query_update('catalogue_efv_' . $sup_table_name, $smap, array('cf_id' => $field_id, 'ce_id' => $id), '', 1); } } require_code('urls2'); suggest_new_idmoniker_for('catalogues', 'entry', strval($id), strip_comcode($title)); require_code('seo2'); seo_meta_set_for_explicit('catalogue_entry', strval($id), $meta_keywords, $meta_description); $self_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $id), get_module_zone('catalogues'), NULL, false, false, true); if ($category_id != $old_category_id || $was_validated != ($validated == 1)) { calculate_category_child_count_cache($category_id); if ($category_id != $old_category_id) { calculate_category_child_count_cache($old_category_id); } } decache('main_cc_embed'); decache('main_recent_cc_entries'); if ($catalogue_name[0] != '_') { log_it('EDIT_CATALOGUE_ENTRY', strval($id), $title); if ($just_validated) { require_lang('catalogues'); require_code('notifications'); $subject = do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title), array($catalogue_title)); $mail = do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape(strip_comcode($title)), array(comcode_escape($self_url->evaluate()), comcode_escape($catalogue_title))); dispatch_notification('catalogue_entry__' . $catalogue_name, strval($id), $subject, $mail); } } require_code('feedback'); update_spacer_post($allow_comments != 0, 'catalogues', strval($id), $self_url, $title, get_value('comment_forum__catalogues__' . $catalogue_name)); }
/** * 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_points_gifts_and_charges($db, $table_prefix, $file_base) { $rows = $db->query('SELECT * FROM ' . $table_prefix . 'reputation'); foreach ($rows as $row) { if (import_check_if_imported('points', strval($row['reputationid']))) { continue; } $time = $row['dateline']; $amount = $row['reputation']; $viewer_member = import_id_remap_get('member', strval($row['whoadded']), true); $member = import_id_remap_get('member', strval($row['userid']), true); $reason = $row['reason']; $anonymous = 0; $GLOBALS['SITE_DB']->query_insert('gifts', array('date_and_time' => $time, 'amount' => $amount, 'gift_from' => $viewer_member, 'gift_to' => $member, 'reason' => insert_lang_comcode($reason, 4), 'anonymous' => $anonymous)); import_id_remap_put('points', strval($row['reputationid']), -1); } }
/** * Add a member. * * @param SHORT_TEXT The username. * @param SHORT_TEXT The password. * @param SHORT_TEXT The e-mail address. * @param ?array A list of usergroups (NULL: default/current usergroups). * @param ?integer Day of date of birth (NULL: unknown). * @param ?integer Month of date of birth (NULL: unknown). * @param ?integer Year of date of birth (NULL: unknown). * @param array A map of custom field values (field-id=>value). * @param ?ID_TEXT The member timezone (NULL: auto-detect). * @param ?GROUP The member's primary (NULL: default). * @param BINARY Whether the profile has been validated. * @param ?TIME When the member joined (NULL: now). * @param ?TIME When the member last visited (NULL: now). * @param ID_TEXT The member's default theme. * @param ?URLPATH The URL to the member's avatar (blank: none) (NULL: choose one automatically). * @param LONG_TEXT The member's signature (blank: none). * @param BINARY Whether the member is permanently banned. * @param BINARY Whether posts are previewed before they are made. * @param BINARY Whether the member's age may be shown. * @param SHORT_TEXT The member's title (blank: get from primary). * @param URLPATH The URL to the member's photo (blank: none). * @param URLPATH The URL to the member's photo thumbnail (blank: none). * @param BINARY Whether the member sees signatures in posts. * @param ?BINARY Whether the member automatically is enabled for notifications for content they contribute to (NULL: get default from config). * @param ?LANGUAGE_NAME The member's language (NULL: auto detect). * @param BINARY Whether the member allows e-mails via the site. * @param BINARY Whether the member allows e-mails from staff via the site. * @param LONG_TEXT Personal notes of the member. * @param ?IP The member's IP address (NULL: IP address of current user). * @param SHORT_TEXT The code required before the account becomes active (blank: already entered). * @param boolean Whether to check details for correctness. * @param ?ID_TEXT The compatibility scheme that the password operates in (blank: none) (NULL: none [meaning normal ocPortal salted style] or plain, depending on whether passwords are encrypted). * @param SHORT_TEXT The password salt (blank: password compatibility scheme does not use a salt / auto-generate). * @param BINARY Whether the member likes to view zones without menus, when a choice is available. * @param ?TIME The time the member last made a submission (NULL: set to now). * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param BINARY Whether the member username will be highlighted. * @param SHORT_TEXT Usergroups that may PT the member. * @param LONG_TEXT Rules that other members must agree to before they may start a PT with the member. * @return AUTO_LINK The ID of the new member. */ function ocf_make_member($username, $password, $email_address, $secondary_groups, $dob_day, $dob_month, $dob_year, $custom_fields, $timezone = NULL, $primary_group = NULL, $validated = 1, $join_time = NULL, $last_visit_time = NULL, $theme = '', $avatar_url = NULL, $signature = '', $is_perm_banned = 0, $preview_posts = 0, $reveal_age = 1, $title = '', $photo_url = '', $photo_thumb_url = '', $views_signatures = 1, $auto_monitor_contrib_content = NULL, $language = NULL, $allow_emails = 1, $allow_emails_from_staff = 1, $personal_notes = '', $ip_address = NULL, $validated_email_confirm_code = '', $check_correctness = true, $password_compatibility_scheme = NULL, $salt = '', $zone_wide = 1, $last_submit_time = NULL, $id = NULL, $highlighted_name = 0, $pt_allow = '*', $pt_rules_text = '') { if (is_null($auto_monitor_contrib_content)) { $auto_monitor_contrib_content = get_value('no_auto_notifications') === '1' ? 0 : 1; } if (is_null($password_compatibility_scheme)) { if (get_value('no_password_hashing') === '1') { $password_compatibility_scheme = 'plain'; } else { $password_compatibility_scheme = ''; } } if (is_null($language)) { $language = ''; } if (is_null($signature)) { $signature = ''; } if (is_null($title)) { $title = ''; } if (is_null($timezone)) { $timezone = get_site_timezone(); } if (is_null($allow_emails)) { $allow_emails = 1; } if (is_null($allow_emails_from_staff)) { $allow_emails_from_staff = 1; } if (is_null($personal_notes)) { $personal_notes = ''; } if (is_null($avatar_url)) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 1 || !addon_installed('ocf_member_avatars')) { $avatar_url = ''; } else { if (get_option('random_avatars') == '1' && !running_script('stress_test_loader')) { require_code('themes2'); $codes = get_all_image_ids_type('ocf_default_avatars/default_set', false, $GLOBALS['FORUM_DB']); shuffle($codes); $results = array(); foreach ($codes as $code) { if (strpos($code, 'ocp_fanatic') !== false) { continue; } $count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(m_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_members WHERE ' . db_string_equal_to('m_avatar_url', find_theme_image($code, false, true))); if (is_null($count)) { $count = 0; } $results[$code] = $count; } @asort($results); // @'d as type checker fails for some odd reason $found_avatars = array_keys($results); $avatar_url = find_theme_image(array_shift($found_avatars), true, true); } if (is_null($avatar_url)) { $GLOBALS['SITE_DB']->query_delete('theme_images', array('id' => 'ocf_default_avatars/default', 'path' => '')); // In case failure cached, gets very confusing $avatar_url = find_theme_image('ocf_default_avatars/default', true, true); if (is_null($avatar_url)) { $avatar_url = ''; } } } } if ($check_correctness) { if (!in_array($password_compatibility_scheme, array('ldap', 'httpauth'))) { ocf_check_name_valid($username, NULL, $password_compatibility_scheme == '' ? $password : NULL); } if (!function_exists('has_actual_page_access') || !has_actual_page_access(get_member(), 'admin_ocf_join')) { require_code('type_validation'); if (!is_valid_email_address($email_address) && $email_address != '') { warn_exit(do_lang_tempcode('_INVALID_EMAIL_ADDRESS', escape_html($email_address))); } } } require_code('ocf_members'); require_code('ocf_groups'); if (is_null($last_submit_time)) { $last_submit_time = time(); } if (is_null($join_time)) { $join_time = time(); } if (is_null($last_visit_time)) { $last_visit_time = time(); } if (is_null($primary_group)) { $primary_group = get_first_default_group(); // This is members } if (is_null($secondary_groups)) { $secondary_groups = ocf_get_all_default_groups(false); } foreach ($secondary_groups as $_g_id => $g_id) { if ($g_id == $primary_group) { unset($secondary_groups[$_g_id]); } } if (is_null($ip_address)) { $ip_address = get_ip_address(); } if ($password_compatibility_scheme == '' && get_value('no_password_hashing') === '1') { $password_compatibility_scheme = 'plain'; $salt = ''; } if ($salt == '' && $password_compatibility_scheme == '') { $salt = produce_salt(); $password_salted = md5($salt . md5($password)); } else { $password_salted = $password; } // Supplement custom field values given with defaults, and check constraints $all_fields = list_to_map('id', ocf_get_all_custom_fields_match($secondary_groups)); require_code('fields'); foreach ($all_fields as $field) { $field_id = $field['id']; if (array_key_exists($field_id, $custom_fields)) { if ($check_correctness && $field[array_key_exists('cf_show_on_join_form', $field) ? 'cf_show_on_join_form' : 'cf_required'] == 0 && $field['cf_owner_set'] == 0 && !has_actual_page_access(get_member(), 'admin_ocf_join')) { access_denied('I_ERROR'); } } else { $custom_fields[$field_id] = ''; } } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('m_username' => $username, 'm_pass_hash_salted' => $password_salted, 'm_pass_salt' => $salt, 'm_theme' => $theme, 'm_avatar_url' => $avatar_url, 'm_validated' => $validated, 'm_validated_email_confirm_code' => $validated_email_confirm_code, 'm_cache_num_posts' => 0, 'm_cache_warnings' => 0, 'm_max_email_attach_size_mb' => 5, 'm_join_time' => $join_time, 'm_timezone_offset' => $timezone, 'm_primary_group' => $primary_group, 'm_last_visit_time' => $last_visit_time, 'm_last_submit_time' => $last_submit_time, 'm_signature' => insert_lang_comcode($signature, 4, $GLOBALS['FORUM_DB']), 'm_is_perm_banned' => $is_perm_banned, 'm_preview_posts' => $preview_posts, 'm_notes' => $personal_notes, 'm_dob_day' => $dob_day, 'm_dob_month' => $dob_month, 'm_dob_year' => $dob_year, 'm_reveal_age' => $reveal_age, 'm_email_address' => $email_address, 'm_title' => $title, 'm_photo_url' => $photo_url, 'm_photo_thumb_url' => $photo_thumb_url, 'm_views_signatures' => $views_signatures, 'm_auto_monitor_contrib_content' => $auto_monitor_contrib_content, 'm_highlighted_name' => $highlighted_name, 'm_pt_allow' => $pt_allow, 'm_pt_rules_text' => insert_lang_comcode($pt_rules_text, 4, $GLOBALS['FORUM_DB']), 'm_language' => $language, 'm_ip_address' => $ip_address, 'm_zone_wide' => $zone_wide, 'm_allow_emails' => $allow_emails, 'm_allow_emails_from_staff' => $allow_emails_from_staff, 'm_password_change_code' => '', 'm_password_compat_scheme' => $password_compatibility_scheme, 'm_on_probation_until' => NULL); if (!is_null($id)) { $map['id'] = $id; } $member_id = $GLOBALS['FORUM_DB']->query_insert('f_members', $map, true); if ($check_correctness) { // If it was an invite/recommendation, award the referrer if (addon_installed('recommend')) { $inviter = $GLOBALS['FORUM_DB']->query_value_null_ok('f_invites', 'i_inviter', array('i_email_address' => $email_address), 'ORDER BY i_time'); if (!is_null($inviter)) { if (addon_installed('points')) { require_code('points2'); require_lang('recommend'); system_gift_transfer(do_lang('RECOMMEND_SITE_TO', $username, get_site_name()), intval(get_option('points_RECOMMEND_SITE')), $inviter); } if (addon_installed('chat')) { require_code('chat2'); buddy_add($inviter, $member_id); buddy_add($member_id, $inviter); } } } } $value = mixed(); // Store custom fields $row = array('mf_member_id' => $member_id); $all_fields_types = collapse_2d_complexity('id', 'cf_type', $all_fields); foreach ($custom_fields as $field_num => $value) { if (!array_key_exists($field_num, $all_fields_types)) { continue; } // Trying to set a field we're not allowed to (doesn't apply to our group) $ob = get_fields_hook($all_fields_types[$field_num]); list(, , $storage_type) = $ob->get_field_value_row_bits($all_fields[$field_num]); if (strpos($storage_type, '_trans') !== false) { $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']); } $row['field_' . strval($field_num)] = $value; } // Set custom field row $all_fields_regardless = $GLOBALS['FORUM_DB']->query_select('f_custom_fields', array('id', 'cf_type')); foreach ($all_fields_regardless as $field) { if (!array_key_exists('field_' . strval($field['id']), $row)) { $ob = get_fields_hook($field['cf_type']); list(, , $storage_type) = $ob->get_field_value_row_bits($field); $value = ''; if (strpos($storage_type, '_trans') !== false) { $value = insert_lang($value, 3, $GLOBALS['FORUM_DB']); } $row['field_' . strval($field['id'])] = $value; } } $GLOBALS['FORUM_DB']->query_insert('f_member_custom_fields', $row); // Any secondary work foreach ($secondary_groups as $g) { if ($g != $primary_group) { $GLOBALS['FORUM_DB']->query_delete('f_group_members', array('gm_member_id' => $member_id, 'gm_group_id' => $g), '', 1); $GLOBALS['FORUM_DB']->query_insert('f_group_members', array('gm_group_id' => $g, 'gm_member_id' => $member_id, 'gm_validated' => 1)); } } if ($check_correctness) { if (function_exists('decache')) { decache('side_stats'); } } return $member_id; }
/** * 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_flagrant($db, $table_prefix, $old_base_dir) { require_code('flagrant'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'public_messages'); foreach ($rows as $row) { $member = $GLOBALS['FORUM_DRIVER']->get_member_from_username($row['who']); if (is_null($member)) { $member = $GLOBALS['FORUM_DRIVER']->get_guest_id(); } $GLOBALS['SITE_DB']->query_insert('text', array('user_id' => $member, 'the_message' => insert_lang_comcode($row['content'], 2), 'days' => 1, 'order_time' => strtotime($row['date']), 'activation_time' => NULL, 'active_now' => 0, 'notes' => '')); } }
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); }
/** * Adds an author (re-creating them if they already exist - thus it also serves to edit; the reason for this is the fluidity of authors - members are automatically authors even before an author profile is made) * * @param ID_TEXT The name of an author * @param URLPATH The URL to the authors home page * @param ?MEMBER The member ID of the author (NULL: no forum profile) * @param LONG_TEXT A description of the author * @param LONG_TEXT A terse string showing author skills * @param ?SHORT_TEXT Meta keywords for this resource (NULL: do not edit) (blank: implicit) * @param ?LONG_TEXT Meta description for this resource (NULL: do not edit) (blank: implicit) */ function add_author($author, $url, $forum_handle, $description, $skills, $meta_keywords = '', $meta_description = '') { log_it('DEFINE_AUTHOR', $author, is_null($forum_handle) ? '' : strval($forum_handle)); $rows = $GLOBALS['SITE_DB']->query_select('authors', array('description', 'skills'), array('author' => $author), '', 1); if (array_key_exists(0, $rows)) { delete_lang($rows[0]['description']); delete_lang($rows[0]['skills']); $GLOBALS['SITE_DB']->query_delete('authors', array('author' => $author), '', 1); } require_code('seo2'); if ($meta_keywords == '' && $meta_description == '') { seo_meta_set_for_implicit('authors', $author, array($author, $description, $skills), $description); } else { seo_meta_set_for_explicit('authors', $author, $meta_keywords, $meta_description); } $GLOBALS['SITE_DB']->query_insert('authors', array('author' => $author, 'url' => $url, 'forum_handle' => $forum_handle, 'description' => insert_lang_comcode($description, 3), 'skills' => insert_lang_comcode($skills, 3))); }
/** * Add a gallery with the specified parameters. * * @param ID_TEXT The gallery codename * @param SHORT_TEXT The full human-readeable name of the gallery * @param LONG_TEXT The description of the gallery * @param SHORT_TEXT Teaser text for the gallery * @param LONG_TEXT Hidden notes associated with the gallery * @param ID_TEXT The parent gallery (blank: no parent) * @param BINARY Whether images may be put in this gallery * @param BINARY Whether videos may be put in this gallery * @param BINARY Whether the gallery serves as a container for automatically created member galleries * @param BINARY Whether the gallery uses the flow mode interface * @param URLPATH The representative image of the gallery (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param URLPATH Watermark (blank: none) * @param BINARY Whether rating are allowed * @param BINARY Whether comments are allowed * @param boolean Whether to skip the check for whether the gallery exists (useful for importers) * @param ?TIME The add time (NULL: now) * @param ?MEMBER The gallery owner (NULL: nobody) */ function add_gallery($name, $fullname, $description, $teaser, $notes, $parent_id, $accept_images = 1, $accept_videos = 1, $is_member_synched = 0, $flow_mode_interface = 0, $rep_image = '', $watermark_top_left = '', $watermark_top_right = '', $watermark_bottom_left = '', $watermark_bottom_right = '', $allow_rating = 1, $allow_comments = 1, $skip_exists_check = false, $add_date = NULL, $g_owner = NULL) { if (is_null($add_date)) { $add_date = time(); } require_code('type_validation'); if (!is_alphanumeric($name, true)) { warn_exit(do_lang_tempcode('BAD_CODENAME')); } if (!$skip_exists_check) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('galleries', 'name', array('name' => $name)); if (!is_null($test)) { warn_exit(do_lang_tempcode('ALREADY_EXISTS', escape_html($name))); } } $GLOBALS['SITE_DB']->query_insert('galleries', array('name' => $name, 'add_date' => $add_date, 'description' => insert_lang_comcode($description, 2), 'teaser' => insert_lang_comcode($teaser, 2), 'notes' => $notes, 'fullname' => insert_lang($fullname, 1), 'watermark_top_left' => $watermark_top_left, 'watermark_top_right' => $watermark_top_right, 'watermark_bottom_left' => $watermark_bottom_left, 'watermark_bottom_right' => $watermark_bottom_right, 'parent_id' => $parent_id, 'accept_images' => $accept_images, 'rep_image' => $rep_image, 'accept_videos' => $accept_videos, 'is_member_synched' => $is_member_synched, 'flow_mode_interface' => $flow_mode_interface, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'g_owner' => $g_owner, 'gallery_views' => 0)); log_it('ADD_GALLERY', $name, $fullname); require_code('seo2'); seo_meta_set_for_implicit('gallery', $name, array($fullname, $description), $description); if (function_exists('decache')) { decache('main_top_galleries'); decache('main_recent_galleries'); decache('main_root_galleries'); decache('side_root_galleries'); } }
/** * Make an award type. * * @param SHORT_TEXT The title * @param LONG_TEXT The description * @param integer How many points are given to the awardee * @param ID_TEXT The content type the award type is for * @param BINARY Whether to not show the awardee when displaying this award * @param integer The approximate time in hours between awards (e.g. 168 for a week) * @return AUTO_LINK The ID */ function add_award_type($title, $description, $points, $content_type, $hide_awardee, $update_time_hours) { $id = $GLOBALS['SITE_DB']->query_insert('award_types', array('a_title' => insert_lang_comcode($title, 2), 'a_description' => insert_lang($description, 2), 'a_points' => $points, 'a_content_type' => filter_naughty_harsh($content_type), 'a_hide_awardee' => $hide_awardee, 'a_update_time_hours' => $update_time_hours), true); log_it('ADD_AWARD_TYPE', strval($id), $title); return $id; }
/** * The actualiser for uploading a file. * * @return tempcode The UI. */ function module_do_upload() { if (!has_specific_permission(get_member(), 'upload_filedump')) { access_denied('I_ERROR'); } $title = get_page_title('FILEDUMP_UPLOAD'); if (function_exists('set_time_limit')) { @set_time_limit(0); } // Slowly uploading a file can trigger time limit, on some servers $place = filter_naughty(post_param('place')); require_code('uploads'); if (!is_swf_upload(true) && (!array_key_exists('file', $_FILES) || !is_uploaded_file($_FILES['file']['tmp_name']))) { $attach_name = 'file'; $max_size = get_max_file_size(); if (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 1 || $_FILES[$attach_name]['error'] == 2)) { warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format($max_size))); } elseif (isset($_FILES[$attach_name]) && ($_FILES[$attach_name]['error'] == 3 || $_FILES[$attach_name]['error'] == 6 || $_FILES[$attach_name]['error'] == 7)) { warn_exit(do_lang_tempcode('ERROR_UPLOADING_' . strval($_FILES[$attach_name]['error']))); } else { warn_exit(do_lang_tempcode('ERROR_UPLOADING')); } } $file = $_FILES['file']['name']; if (get_magic_quotes_gpc()) { $file = stripslashes($file); } if (!has_specific_permission(get_member(), 'upload_anything_filedump') || get_file_base() != get_custom_file_base()) { check_extension($file); } $file = str_replace('.', '-', basename($file, '.' . get_file_extension($file))) . '.' . get_file_extension($file); if (!file_exists(get_custom_file_base() . '/uploads/filedump' . $place . $file)) { $max_size = get_max_file_size(); if ($_FILES['file']['size'] > $max_size) { warn_exit(do_lang_tempcode('FILE_TOO_BIG', integer_format(intval($max_size)))); } $full = get_custom_file_base() . '/uploads/filedump' . $place . $file; if (is_swf_upload(true)) { @rename($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place))); } else { @move_uploaded_file($_FILES['file']['tmp_name'], $full) or warn_exit(do_lang_tempcode('FILE_MOVE_ERROR', escape_html($file), escape_html('uploads/filedump' . $place))); } fix_permissions($full); sync_file($full); $return_url = build_url(array('page' => '_SELF', 'place' => $place), '_SELF'); $test = $GLOBALS['SITE_DB']->query_value_null_ok('filedump', 'description', array('name' => $file, 'path' => $place)); if (!is_null($test)) { delete_lang($test); } $GLOBALS['SITE_DB']->query_delete('filedump', array('name' => $file, 'path' => $place), '', 1); $description = post_param('description'); $GLOBALS['SITE_DB']->query_insert('filedump', array('name' => $file, 'path' => $place, 'the_member' => get_member(), 'description' => insert_lang_comcode($description, 3))); require_code('notifications'); $subject = do_lang('FILEDUMP_NOTIFICATION_MAIL_SUBJECT', get_site_name(), $file, $place); $mail = do_lang('FILEDUMP_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($file), array(comcode_escape($place), comcode_escape($description))); dispatch_notification('filedump', $place, $subject, $mail); log_it('FILEDUMP_UPLOAD', $file, $place); if (has_actual_page_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), get_page_name(), get_zone_name())) { syndicate_described_activity('filedump:ACTIVITY_FILEDUMP_UPLOAD', $place . '/' . $file, '', '', '', '', '', 'filedump'); } return redirect_screen($title, $return_url, do_lang_tempcode('SUCCESS')); } else { warn_exit(do_lang_tempcode('OVERWRITE_ERROR')); } return new ocp_tempcode(); }
/** * Set a custom profile field for a member. * * @param MEMBER The member. * @param AUTO_LINK The field being set. * @param mixed The value of the field. For a trans-type field, this can be either a lang-ID to be copied (from forum DB), or an actual string. * @param ?ID_TEXT The field type (NULL: look it up). * @param boolean Whether to defer the change, by returning a result change rather than doing it right away. * @return ?array Mapping change (NULL: none / can't defer). */ function ocf_set_custom_field($member_id, $field, $value, $type = NULL, $defer = false) { if (is_null($type)) { $type = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_type', array('id' => $field)); } ocf_get_custom_field_mappings($member_id); // This will do an auto-repair if CPF storage row is missing global $ANY_FIELD_ENCRYPTED; if ($ANY_FIELD_ENCRYPTED === NULL) { $ANY_FIELD_ENCRYPTED = !is_null($GLOBALS['FORUM_DB']->query_value_null_ok('f_custom_fields', 'cf_encrypted', array('cf_encrypted' => 1))); } if ($ANY_FIELD_ENCRYPTED) { $encrypted = $GLOBALS['FORUM_DB']->query_value('f_custom_fields', 'cf_encrypted', array('id' => $field)); if ($encrypted) { require_code('encryption'); $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id)); if (remove_magic_encryption_marker($value) == remove_magic_encryption_marker($current) && is_data_encrypted($current)) { return NULL; } $value = encrypt_data($value); } } else { $encrypted = false; } require_code('fields'); $ob = get_fields_hook($type); list(, , $storage_type) = $ob->get_field_value_row_bits(array('id' => $field, 'cf_default' => '', 'cf_type' => $type)); if (strpos($storage_type, '_trans') !== false) { if (is_integer($value)) { $value = get_translated_text($value, $GLOBALS['FORUM_DB']); } $current = $GLOBALS['FORUM_DB']->query_value('f_member_custom_fields', 'field_' . strval(intval($field)), array('mf_member_id' => $member_id)); if (is_null($current)) { if ($type == 'posting_field') { require_code('attachments2'); $current = insert_lang_comcode_attachments(3, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB']); } else { $current = insert_lang_comcode($value, 3, $GLOBALS['FORUM_DB']); } $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', array('field_' . strval(intval($field)) => $current), array('mf_member_id' => $member_id), '', 1); } else { if ($type == 'posting_field') { require_code('attachments2'); require_code('attachments3'); update_lang_comcode_attachments($current, $value, 'null', strval($member_id), $GLOBALS['FORUM_DB'], false, $member_id); } else { lang_remap_comcode($current, $value, $GLOBALS['FORUM_DB']); } } } else { $change = array('field_' . strval(intval($field)) => $value); if (!$defer) { $GLOBALS['FORUM_DB']->query_update('f_member_custom_fields', $change, array('mf_member_id' => $member_id), '', 1); } return $change; } return NULL; }
/** * Standard stage of pointstore item purchase. * * @return tempcode The UI */ function ___text() { if (get_option('is_on_flagrant_buy') == '0') { return new ocp_tempcode(); } $title = get_page_title('TITLE_NEWTEXT'); // Define variables $member_id = get_member(); $message = post_param('message'); $days = post_param_integer('days'); $points_left = available_points($member_id); // First we need to know the price of the number of days we ordered. After that, compare that price with our users current number of points. $dayprice = intval(get_option('text')); $total = $dayprice * $days; if ($points_left < $total && !has_specific_permission(get_member(), 'give_points_self')) { return warn_screen($title, do_lang_tempcode('FLAGRANT_LACK_POINTS', integer_format($days), integer_format($total), integer_format($points_left))); } // Add this to the database $GLOBALS['SITE_DB']->query_insert('text', array('notes' => '', 'activation_time' => NULL, 'active_now' => 0, 'user_id' => $member_id, 'the_message' => insert_lang_comcode($message, 2), 'days' => $days, 'order_time' => time())); // Mail off the notice require_code('notifications'); $_url = build_url(array('page' => 'admin_flagrant'), 'adminzone', NULL, false, false, true); $manage_url = $_url->evaluate(); dispatch_notification('pointstore_request_flagrant', NULL, do_lang('TITLE_NEWTEXT', NULL, NULL, NULL, get_site_default_lang()), do_lang('MAIL_FLAGRANT_TEXT', $message, comcode_escape($manage_url), NULL, get_site_default_lang())); // Now, deduct the points from our user's account require_code('points2'); charge_member($member_id, $total, do_lang('PURCHASED_FLAGRANT')); $url = build_url(array('page' => '_SELF', 'type' => 'misc'), '_SELF'); return redirect_screen($title, $url, do_lang_tempcode('ORDER_FLAGRANT_DONE')); }
/** * 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; }
/** * Add an entry to the change log. * * @param MEMBER The member that is being charged * @param integer The amount being charged * @param SHORT_TEXT The reason for the charging * @param ?TIME The time this is recorded to have happened (NULL: use current time) */ function add_to_charge_log($member_id, $amount, $reason, $time = NULL) { if (is_null($time)) { $time = time(); } $GLOBALS['SITE_DB']->query_insert('chargelog', array('user_id' => $member_id, 'amount' => $amount, 'reason' => insert_lang_comcode($reason, 4), 'date_and_time' => $time)); }
/** * Add a new poll to the database, then return the ID of the new entry. * * @param SHORT_TEXT The question * @param SHORT_TEXT The first choice * @range 1 max * @param SHORT_TEXT The second choice * @range 1 max * @param SHORT_TEXT The third choice (blank means not a choice) * @param SHORT_TEXT The fourth choice (blank means not a choice) * @param SHORT_TEXT The fifth choice (blank means not a choice) * @param SHORT_TEXT The sixth choice (blank means not a choice) * @param SHORT_TEXT The seventh choice (blank means not a choice) * @param SHORT_TEXT The eighth choice (blank means not a choice) * @param SHORT_TEXT The ninth choice (blank means not a choice) * @param SHORT_TEXT The tenth choice (blank means not a choice) * @param integer The number of choices * @range 2 5 * @param BINARY Whether the poll is the current poll * @param BINARY Whether to allow rating of this poll * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether to allow trackbacking on this poll * @param LONG_TEXT Notes about this poll * @param ?TIME The time the poll was submitted (NULL: now) * @param ?MEMBER The member who submitted (NULL: the current member) * @param ?TIME The time the poll was put to use (NULL: not put to use yet) * @param integer How many have voted for option 1 * @range 0 max * @param integer How many have voted for option 2 * @range 0 max * @param integer How many have voted for option 3 * @range 0 max * @param integer How many have voted for option 4 * @range 0 max * @param integer How many have voted for option 5 * @range 0 max * @param integer How many have voted for option 6 * @range 0 max * @param integer How many have voted for option 7 * @range 0 max * @param integer How many have voted for option 8 * @range 0 max * @param integer How many have voted for option 9 * @range 0 max * @param integer How many have voted for option 10 * @range 0 max * @param integer The number of views had * @param ?TIME The edit date (NULL: never) * @return AUTO_LINK The poll ID of our new poll */ function add_poll($question, $a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10, $num_options, $current, $allow_rating, $allow_comments, $allow_trackbacks, $notes, $time = NULL, $submitter = NULL, $use_time = NULL, $v1 = 0, $v2 = 0, $v3 = 0, $v4 = 0, $v5 = 0, $v6 = 0, $v7 = 0, $v8 = 0, $v9 = 0, $v10 = 0, $views = 0, $edit_date = NULL) { if ($current == 1) { persistant_cache_delete('POLL'); $GLOBALS['SITE_DB']->query_update('poll', array('is_current' => 0), array('is_current' => 1), '', 1); } if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $id = $GLOBALS['SITE_DB']->query_insert('poll', array('edit_date' => $edit_date, 'poll_views' => $views, 'add_time' => $time, 'allow_trackbacks' => $allow_trackbacks, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'notes' => $notes, 'submitter' => $submitter, 'date_and_time' => $use_time, 'votes1' => $v1, 'votes2' => $v2, 'votes3' => $v3, 'votes4' => $v4, 'votes5' => $v5, 'votes6' => $v6, 'votes7' => $v7, 'votes8' => $v8, 'votes9' => $v9, 'votes10' => $v10, 'question' => insert_lang_comcode($question, 1), 'option1' => insert_lang_comcode($a1, 1), 'option2' => insert_lang_comcode($a2, 1), 'option3' => insert_lang_comcode($a3, 1), 'option4' => insert_lang_comcode($a4, 1), 'option5' => insert_lang_comcode($a5, 1), 'option6' => insert_lang_comcode($a6, 1), 'option7' => insert_lang_comcode($a7, 1), 'option8' => insert_lang_comcode($a8, 1), 'option9' => insert_lang_comcode($a9, 1), 'option10' => insert_lang_comcode($a10, 1), 'num_options' => $num_options, 'is_current' => $current), true); log_it('ADD_POLL', strval($id), $question); return $id; }