/** * Add a calendar event. * * @param AUTO_LINK The event type * @param SHORT_TEXT The recurrence code (set to 'none' for no recurrences: blank means infinite and will basically time-out ocPortal) * @param ?integer The number of recurrences (NULL: none/infinite) * @param BINARY Whether to segregate the comment-topics/rating/trackbacks per-recurrence * @param SHORT_TEXT The title of the event * @param LONG_TEXT The full text describing the event * @param integer The priority * @range 1 5 * @param BINARY Whether it is a public event * @param ?integer The year the event starts at (NULL: default) * @param ?integer The month the event starts at (NULL: default) * @param ?integer The day the event starts at (NULL: default) * @param ?integer The hour the event starts at (NULL: default) * @param ?integer The minute the event starts at (NULL: default) * @param ?integer The year the event ends at (NULL: not a multi day event) * @param ?integer The month the event ends at (NULL: not a multi day event) * @param ?integer The day the event ends at (NULL: not a multi day event) * @param ?integer The hour the event ends at (NULL: not a multi day event) * @param ?integer The minute the event ends at (NULL: not a multi day event) * @param ?ID_TEXT The timezone for the event (NULL: current user's timezone) * @param BINARY Whether the time should be presented in the viewer's own timezone * @param BINARY Whether the event has been validated * @param BINARY Whether the event may be rated * @param SHORT_INTEGER Whether comments are allowed (0=no, 1=yes, 2=review style) * @param BINARY Whether the event may be trackbacked * @param LONG_TEXT Hidden notes pertaining to the download * @param ?MEMBER The event submitter (NULL: current member) * @param integer The number of views so far * @param ?TIME The add time (NULL: now) * @param ?TIME The edit time (NULL: never) * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the event */ function add_calendar_event($type, $recurrence, $recurrences, $seg_recurrences, $title, $content, $priority, $is_public, $start_year, $start_month, $start_day, $start_hour, $start_minute, $end_year = NULL, $end_month = NULL, $end_day = NULL, $end_hour = NULL, $end_minute = NULL, $timezone = NULL, $do_timezone_conv = 1, $validated = 1, $allow_rating = 1, $allow_comments = 1, $allow_trackbacks = 1, $notes = '', $submitter = NULL, $views = 0, $add_date = NULL, $edit_date = NULL, $id = NULL) { if (is_null($submitter)) { $submitter = get_member(); } if (is_null($add_date)) { $add_date = time(); } if (is_null($timezone)) { $timezone = get_users_timezone(); } require_code('comcode_check'); check_comcode($content, NULL, false, NULL, true); if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('e_submitter' => $submitter, 'e_views' => $views, 'e_title' => insert_lang($title, 2), 'e_content' => 0, 'e_add_date' => $add_date, 'e_edit_date' => $edit_date, 'e_recurrence' => $recurrence, 'e_recurrences' => $recurrences, 'e_seg_recurrences' => $seg_recurrences, 'e_start_year' => $start_year, 'e_start_month' => $start_month, 'e_start_day' => $start_day, 'e_start_hour' => $start_hour, 'e_start_minute' => $start_minute, 'e_end_year' => $end_year, 'e_end_month' => $end_month, 'e_end_day' => $end_day, 'e_end_hour' => $end_hour, 'e_end_minute' => $end_minute, 'e_timezone' => $timezone, 'e_do_timezone_conv' => $do_timezone_conv, 'e_is_public' => $is_public, 'e_priority' => $priority, 'e_type' => $type, 'validated' => $validated, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks, 'notes' => $notes); if (!is_null($id)) { $map['id'] = $id; } $id = $GLOBALS['SITE_DB']->query_insert('calendar_events', $map, true); require_code('attachments2'); $GLOBALS['SITE_DB']->query_update('calendar_events', array('e_content' => insert_lang_comcode_attachments(3, $content, 'calendar', strval($id))), array('id' => $id), '', 1); require_code('seo2'); seo_meta_set_for_implicit('event', strval($id), array($title, $content), $content); decache('side_calendar'); if ($validated == 1) { require_lang('calendar'); require_code('notifications'); $subject = do_lang('CALENDAR_EVENT_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title)); $self_url = build_url(array('page' => 'calendar', 'type' => 'view', 'id' => $id), get_module_zone('calendar'), NULL, false, false, true); $mail = do_lang('CALENDAR_EVENT_NOTIFICATION_MAIL', comcode_escape(get_site_name()), comcode_escape($title), array($self_url->evaluate())); dispatch_notification('calendar_event', strval($type), $subject, $mail); } log_it('ADD_CALENDAR_EVENT', strval($id), $title); return $id; }
/** * Add a CEDI page * * @param SHORT_TEXT The page title * @param LONG_TEXT The page description * @param LONG_TEXT Hidden notes pertaining to the page * @param BINARY Whether to hide the posts on the page by default * @param ?MEMBER The member doing the action (NULL: current member) * @return AUTO_LINK The page ID */ function cedi_add_page($title, $description, $notes, $hide_posts, $member = NULL) { if (is_null($member)) { $member = get_member(); } require_code('comcode_check'); check_comcode($description, NULL, false, NULL, true); if ($description != '') { $id = $GLOBALS['SITE_DB']->query_insert('seedy_pages', array('submitter' => $member, 'hide_posts' => $hide_posts, 'seedy_views' => 0, 'notes' => $notes, 'description' => 0, 'title' => insert_lang($title, 2), 'add_date' => time()), true); require_code('attachments2'); $GLOBALS['SITE_DB']->query_update('seedy_pages', array('description' => insert_lang_comcode_attachments(2, $description, 'cedi_page', strval($id), NULL, false, $member)), array('id' => $id), '', 1); } else { $id = $GLOBALS['SITE_DB']->query_insert('seedy_pages', array('submitter' => $member, 'hide_posts' => $hide_posts, 'seedy_views' => 0, 'notes' => $notes, 'description' => insert_lang($description, 2), 'title' => insert_lang($title, 2), 'add_date' => time()), true); } update_stat('num_seedy_pages', 1); $GLOBALS['SITE_DB']->query_insert('seedy_changes', array('the_action' => 'CEDI_ADD_PAGE', 'the_page' => $id, 'date_and_time' => time(), 'ip' => get_ip_address(), 'the_user' => $member)); require_code('seo2'); seo_meta_set_for_implicit('seedy_page', strval($id), array($title, $description), $description); dispatch_cedi_page_notification($id, 'ADD'); return $id; }
/** * Update a language code, in such a way that new attachments are created if they were specified. * * @param integer The language id * @param LONG_TEXT The new text * @param ID_TEXT The arbitrary type that the attached is for (e.g. download) * @param ID_TEXT The id in the set of the arbitrary types that the attached is for * @param ?object The database connection to use (NULL: standard site connection) * @param boolean Whether to backup the language string before changing it * @param ?MEMBER The member to use for ownership permissions (NULL: current member) * @return integer The language id */ function update_lang_comcode_attachments($lang_id, $text, $type, $id, $connection = NULL, $backup_string = false, $for_member = NULL) { if ($lang_id == 0) { return insert_lang_comcode_attachments(3, $text, $type, $id, $connection, false, $for_member); } if ($text === STRING_MAGIC_NULL) { return $lang_id; } if (is_null($connection)) { $connection = $GLOBALS['SITE_DB']; } require_lang('comcode'); _check_attachment_count(); $test = $connection->query_value_null_ok('translate', 'text_original', array('id' => $id, 'language' => user_lang())); if ($backup_string) { $current = $connection->query_select('translate', array('*'), array('id' => $lang_id, 'language' => user_lang())); if (!array_key_exists(0, $current)) { $current = $connection->query_select('translate', array('*'), array('id' => $lang_id)); } $connection->query_insert('translate_history', array('lang_id' => $lang_id, 'language' => $current[0]['language'], 'text_original' => $current[0]['text_original'], 'broken' => $current[0]['broken'], 'action_member' => get_member(), 'action_time' => time())); } $member = function_exists('get_member') ? get_member() : $GLOBALS['FORUM_DRIVER']->get_guest_id(); $_info = do_comcode_attachments($text, $type, $id, false, $connection, NULL, $for_member); $text2 = ''; //Actually we'll let it regenerate with the correct permissions ($member, not $for_member) $_info['tempcode']->to_assembly(); $remap = array('text_original' => $_info['comcode'], 'text_parsed' => $text2); if (ocp_admirecookie('use_wysiwyg', '1') == '0' && get_value('edit_with_my_comcode_perms') === '1' || !has_specific_permission($member, 'allow_html') || !has_specific_permission($member, 'use_very_dangerous_comcode')) { $remap['source_user'] = $member; } if (!is_null($test)) { $connection->query_update('translate', $remap, array('id' => $lang_id, 'language' => user_lang())); } else { $connection->query_update('translate', $remap, array('id' => $lang_id)); } return $lang_id; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Adds an entry to the specified catalogue. * * @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 ?TIME The time the entry was added (NULL: now) * @param ?MEMBER The entries submitter (NULL: current user) * @param ?TIME The edit time (NULL: never) * @param integer The number of views * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @return AUTO_LINK The ID of the newly added entry */ function actual_add_catalogue_entry($category_id, $validated, $notes, $allow_rating, $allow_comments, $allow_trackbacks, $map, $time = NULL, $submitter = NULL, $edit_date = NULL, $views = 0, $id = NULL) { if (is_null($time)) { $time = time(); } if (is_null($submitter)) { $submitter = get_member(); } $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); require_code('comcode_check'); require_code('fields'); if (!addon_installed('unvalidated')) { $validated = 1; } $imap = array('c_name' => $catalogue_name, 'ce_edit_date' => $edit_date, 'cc_id' => $category_id, 'ce_last_moved' => time(), 'ce_submitter' => $submitter, 'ce_add_date' => $time, 'ce_views' => $views, 'ce_views_prior' => $views, 'ce_validated' => $validated, 'notes' => $notes, 'allow_rating' => $allow_rating, 'allow_comments' => $allow_comments, 'allow_trackbacks' => $allow_trackbacks); if (!is_null($id)) { $imap['id'] = $id; } $val = mixed(); foreach ($map as $field_id => $val) { $type = $fields[$field_id]; $ob = get_fields_hook($type); list($raw_type) = $ob->get_field_value_row_bits($_fields[$field_id]); if (strpos($raw_type, '_trans') !== false) { check_comcode($val); } } $id = $GLOBALS['SITE_DB']->query_insert('catalogue_entries', $imap, true); $title = NULL; foreach ($map as $field_id => $val) { if ($val == STRING_MAGIC_NULL) { $val = ''; } if (is_null($title)) { $title = $val; } $type = $fields[$field_id]; $ob = get_fields_hook($type); list($raw_type, , $sup_table_name) = $ob->get_field_value_row_bits($_fields[$field_id]); if (strpos($raw_type, '_trans') !== false) { if ($type == 'posting_field') { require_code('attachments2'); $val = insert_lang_comcode_attachments(3, $val, 'catalogue_entry', strval($id)); } else { $val = insert_lang_comcode($val, 3); } } if ($sup_table_name == 'short') { $val = substr($val, 0, 255); } if ($sup_table_name == 'float') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => is_null($val) || $val == '' ? NULL : floatval($val)); } elseif ($sup_table_name == 'integer') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => is_null($val) || $val == '' ? NULL : intval($val)); } elseif ($sup_table_name == 'short') { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => substr($val, 0, 255)); } else { $smap = array('cf_id' => $field_id, 'ce_id' => $id, 'cv_value' => $val); } $GLOBALS['SITE_DB']->query_insert('catalogue_efv_' . $sup_table_name, $smap); } require_code('seo2'); seo_meta_set_for_implicit('catalogue_entry', strval($id), $map, ''); calculate_category_child_count_cache($category_id); if ($catalogue_name[0] != '_') { if ($validated == 1) { require_lang('catalogues'); require_code('notifications'); $subject = do_lang('CATALOGUE_ENTRY_NOTIFICATION_MAIL_SUBJECT', get_site_name(), strip_comcode($title), array($catalogue_title)); $self_url = build_url(array('page' => 'catalogues', 'type' => 'entry', 'id' => $id), get_module_zone('catalogues'), NULL, false, false, true); $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); } log_it('ADD_CATALOGUE_ENTRY', strval($id), $title); } decache('main_cc_embed'); decache('main_recent_cc_entries'); return $id; }