/**
 * Makes a post in the specified forum, in the specified topic according to the given specifications. If the topic doesn't exist, it is created along with a spacer-post.
 * Spacer posts exist in order to allow staff to delete the first true post in a topic. Without spacers, this would not be possible with most forum systems. They also serve to provide meta information on the topic that cannot be encoded in the title (such as a link to the content being commented upon).
 *
 * @param  object			Link to the real forum driver
 * @param  SHORT_TEXT	The forum name
 * @param  SHORT_TEXT	The topic identifier (usually <content-type>_<content-id>)
 * @param  MEMBER			The member ID
 * @param  LONG_TEXT		The post title
 * @param  LONG_TEXT		The post content in Comcode format
 * @param  string			The topic title; must be same as content title if this is for a comment topic
 * @param  string			This is put together with the topic identifier to make a more-human-readable topic title or topic description (hopefully the latter and a $content_title title, but only if the forum supports descriptions)
 * @param  ?URLPATH		URL to the content (NULL: do not make spacer post)
 * @param  ?TIME			The post time (NULL: use current time)
 * @param  ?IP				The post IP address (NULL: use current members IP address)
 * @param  ?BINARY		Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver.
 * @param  ?BINARY		Whether the topic is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). This only works with the OCF driver.
 * @param  boolean		Whether to skip post checks
 * @param  SHORT_TEXT	The name of the poster
 * @param  ?AUTO_LINK	ID of post being replied to (NULL: N/A)
 * @param  boolean		Whether the reply is only visible to staff
 * @param  ?ID_TEXT		DO NOT send notifications to: The notification code (NULL: no restriction)
 * @param  ?SHORT_TEXT	DO NOT send notifications to: The category within the notification code (NULL: none / no restriction)
 * @return array			Topic ID (may be NULL), and whether a hidden post has been made
 */
function _helper_make_post_forum_topic($this_ref, $forum_name, $topic_identifier, $member_id, $post_title, $post, $content_title, $topic_identifier_encapsulation_prefix, $content_url, $time, $ip, $validated, $topic_validated, $skip_post_checks, $poster_name_if_guest, $parent_id, $staff_only, $no_notify_for__notification_code, $no_notify_for__code_category)
{
    if (is_null($time)) {
        $time = time();
    }
    if (is_null($ip)) {
        $ip = get_ip_address();
    }
    require_code('comcode_check');
    check_comcode($post, NULL, false, NULL, true);
    require_code('ocf_topics');
    require_code('ocf_posts');
    //require_code('ocf_forums');
    require_lang('ocf');
    require_code('ocf_posts_action');
    require_code('ocf_posts_action2');
    if (!is_integer($forum_name)) {
        $forum_id = $this_ref->forum_id_from_name($forum_name);
        if (is_null($forum_id)) {
            warn_exit(do_lang_tempcode('MISSING_FORUM', escape_html($forum_name)));
        }
    } else {
        $forum_id = (int) $forum_name;
    }
    $topic_id = $this_ref->find_topic_id_for_topic_identifier($forum_name, $topic_identifier);
    $update_caching = false;
    $support_attachments = false;
    if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') {
        $update_caching = true;
        $support_attachments = true;
    }
    if (is_null($topic_id)) {
        $is_starter = true;
        require_code('ocf_topics_action');
        $topic_id = ocf_make_topic($forum_id, $topic_identifier_encapsulation_prefix . ': #' . $topic_identifier, '', $topic_validated, 1, 0, 0, 0, NULL, NULL, false, 0, NULL, $content_url);
        if (strpos($topic_identifier, ':') !== false) {
            // Sync comment_posted ones to also monitor the forum ones; no need for opposite way as comment ones already trigger forum ones
            $start = 0;
            $max = 300;
            require_code('notifications');
            $ob = _get_notification_ob_for_code('comment_posted');
            do {
                list($members, $possibly_has_more) = $ob->list_members_who_have_enabled('comment_posted', $topic_identifier, NULL, $start, $max);
                foreach ($members as $to_member_id => $setting) {
                    enable_notifications('ocf_topic', strval($topic_id), $to_member_id);
                }
                $start += $max;
            } while ($possibly_has_more);
        }
        // Make spacer post
        if (!is_null($content_url)) {
            $spacer_title = $content_title;
            $home_link = hyperlink($content_url, escape_html($content_title));
            $spacer_post = '[semihtml]' . do_lang('SPACER_POST', $home_link->evaluate(), '', '', get_site_default_lang()) . '[/semihtml]';
            ocf_make_post($topic_id, $spacer_title, $spacer_post, 0, true, 1, 0, do_lang('SYSTEM'), $ip, $time, db_get_first_id(), NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, false, false, false);
            $is_starter = false;
        }
        $is_new = true;
    } else {
        $is_starter = false;
        $is_new = false;
    }
    $GLOBALS['LAST_TOPIC_ID'] = $topic_id;
    $GLOBALS['LAST_TOPIC_IS_NEW'] = $is_new;
    if ($post == '') {
        return array(NULL, false);
    }
    ocf_check_post($post, $topic_id, $member_id);
    $poster_name = $poster_name_if_guest;
    if ($poster_name == '') {
        $poster_name = $this_ref->get_username($member_id);
    }
    $post_id = ocf_make_post($topic_id, $post_title, $post, 0, $is_starter, $validated, 0, $poster_name, $ip, $time, $member_id, $staff_only ? $GLOBALS['FORUM_DRIVER']->get_guest_id() : NULL, NULL, NULL, false, $update_caching, $forum_id, $support_attachments, $content_title, 0, NULL, false, $skip_post_checks, false, false, $parent_id);
    $GLOBALS['LAST_POST_ID'] = $post_id;
    if ($is_new) {
        // Broken cache now for the rest of this page view - fix by flushing
        global $TOPIC_IDENTIFIERS_TO_IDS;
        $TOPIC_IDENTIFIERS_TO_IDS = array();
    }
    // Send out notifications
    $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id));
    $url = $_url->evaluate();
    ocf_send_topic_notification($url, $topic_id, $forum_id, $member_id, $is_new, $post, $content_title, NULL, false, $no_notify_for__notification_code, $no_notify_for__code_category);
    $is_hidden = false;
    if (!running_script('stress_test_loader') && get_page_name() != 'admin_import') {
        $validated_actual = $this_ref->connection->query_value('f_posts', 'p_validated', array('id' => $post_id));
        if ($validated_actual == 0) {
            require_code('site');
            attach_message(do_lang_tempcode('SUBMIT_UNVALIDATED'), 'inform');
            $is_hidden = true;
        }
    }
    return array($topic_id, $is_hidden);
}
Example #2
0
 /**
  * Send out a notification to members enabled.
  */
 function dispatch()
 {
     if (running_script('stress_test_loader')) {
         return;
     }
     if (get_page_name() == 'admin_import') {
         return;
     }
     $subject = $this->subject;
     $message = $this->message;
     $no_cc = $this->no_cc;
     if ($GLOBALS['DEBUG_MODE']) {
         if (strpos($this->message, 'keep_devtest') !== false && $this->notification_code != 'hack_attack' && $this->notification_code != 'auto_ban' && strpos($this->message, running_script('index') ? static_evaluate_tempcode(build_url(array('page' => '_SELF'), '_SELF', NULL, true, false, true)) : get_self_url_easy()) === false && (strpos(ocp_srv('HTTP_REFERER'), 'keep_devtest') === false || strpos($this->message, ocp_srv('HTTP_REFERER')) === false)) {
             // Bad URL - it has to be general, not session-specific
             fatal_exit(do_lang_tempcode('INTERNAL_ERROR'));
         }
     }
     $ob = _get_notification_ob_for_code($this->notification_code);
     if (is_null($ob)) {
         if (get_page_name() != 'admin_setupwizard') {
             // Setupwizard may have removed after register_shutdown_function was called
             fatal_exit('Missing notification code: ' . $this->notification_code);
         }
         return;
     }
     require_lang('notifications');
     require_code('mail');
     if (function_exists('set_time_limit')) {
         @set_time_limit(0);
     }
     if ($this->store_in_staff_messaging_system && addon_installed('staff_messaging')) {
         require_lang('messaging');
         list($type, $id) = explode('_', $this->code_category, 2);
         $message_url = build_url(array('page' => 'admin_messaging', 'type' => 'view', 'id' => $id, 'message_type' => $type), get_module_zone('admin_messaging'), NULL, false, false, true);
         $message = do_lang('MESSAGING_NOTIFICATION_WRAPPER', $message, $message_url->evaluate());
         require_code('feedback');
         actualise_post_comment(true, $type, $id, $message_url, $subject, get_option('messaging_forum_name'), true, 1, true, true, true);
     }
     $testing = get_param_integer('keep_debug_notifications', 0) == 1;
     $start = 0;
     $max = 300;
     do {
         list($members, $possibly_has_more) = $ob->list_members_who_have_enabled($this->notification_code, $this->code_category, $this->to_member_ids, $start, $max);
         if (get_value('notification_safety_testing') === '1') {
             if (count($members) > 20) {
                 $members = array(6 => A_INSTANT_EMAIL);
                 // This is just for testing on ocportal.com, if lots of notifications going out it's probably a scary bug, so send just to Chris (#6) with a note
                 $message = 'OVER-ADDRESSED?' . "\n\n" . $message;
             }
         }
         foreach ($members as $to_member_id => $setting) {
             if (!is_null($this->no_notify_for__notification_code)) {
                 if (notifications_enabled($this->no_notify_for__notification_code, $this->no_notify_for__code_category, $to_member_id)) {
                     continue;
                 }
                 // Signal they are getting some other notification for this
             }
             if ($to_member_id !== $this->from_member_id || $testing) {
                 $no_cc = _dispatch_notification_to_member($to_member_id, $setting, $this->notification_code, $this->code_category, $subject, $message, $this->from_member_id, $this->priority, $no_cc);
             }
         }
         $start += $max;
     } while ($possibly_has_more);
 }
Example #3
0
/**
 * Put out a user interface for managing notifications for a notification-category supporting content type. Also toggle notifications if an ID is passed.
 *
 * @param  ID_TEXT		The notification code to work with
 * @param  ?tempcode		Special message to output if we have toggled to enable (NULL: use standard)
 * @param  ?tempcode		Special message to output if we have toggled to disable (NULL: use standard)
 * @return tempcode		UI
 */
function notifications_ui_advanced($notification_code, $enable_message = NULL, $disable_message = NULL)
{
    require_css('notifications');
    require_code('notifications');
    require_lang('notifications');
    require_javascript('javascript_notifications');
    require_javascript('javascript_notifications');
    require_all_lang();
    $test = $GLOBALS['SITE_DB']->query_value_null_ok('notification_lockdown', 'l_setting', array('l_notification_code' => substr($notification_code, 0, 80)));
    if (!is_null($test)) {
        warn_exit(do_lang_tempcode('NOTIFICATION_CODE_LOCKED_DOWN'));
    }
    $ob = _get_notification_ob_for_code($notification_code);
    $info_details = $ob->list_handled_codes();
    $title = get_page_title('NOTIFICATION_MANAGEMENT_FOR', true, array(escape_html($info_details[$notification_code][1])));
    if (is_guest()) {
        access_denied('NOT_AS_GUEST');
    }
    $db = substr($notification_code, 0, 4) == 'ocf_' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB'];
    if (is_null($enable_message)) {
        $enable_message = do_lang_tempcode('NOW_ENABLED_NOTIFICATIONS');
    }
    if (is_null($disable_message)) {
        $disable_message = do_lang_tempcode('NOW_DISABLED_NOTIFICATIONS');
    }
    $_notification_types = _get_available_notification_types(get_member());
    $notification_category = get_param('id', NULL);
    if (!is_null($notification_category)) {
        if (notifications_enabled($notification_code, $notification_category)) {
            enable_notifications($notification_code, $notification_category, NULL, A_NA);
            attach_message($disable_message, 'inform');
        } else {
            enable_notifications($notification_code, $notification_category);
            attach_message($enable_message, 'inform');
        }
    } else {
        if (count($_POST) != 0) {
            enable_notifications($notification_code, NULL, NULL, A_NA);
            // Make it clear we've overridden the general value by doing this
            foreach (array_keys($_POST) as $key) {
                $matches = array();
                if (preg_match('#^notification\\_' . preg_quote($notification_code) . '\\_category\\_(.*)#', $key, $matches) != 0) {
                    $notification_category = $matches[1];
                    $new_setting = A_NA;
                    foreach ($_notification_types as $possible => $ntype) {
                        if (post_param_integer('notification_' . $notification_category . '_' . $ntype, 0) == 1) {
                            $new_setting = $new_setting | $possible;
                        }
                    }
                    enable_notifications($notification_code, $notification_category, NULL, $new_setting);
                }
            }
            attach_message(do_lang_tempcode('SUCCESS'), 'inform');
            // Redirect them back
            $redirect = get_param('redirect', NULL);
            if (!is_null($redirect)) {
                return redirect_screen($title, $redirect, do_lang_tempcode('SUCCESS'));
            }
        }
    }
    $tree = _notifications_build_category_tree($_notification_types, $notification_code, $ob, NULL);
    $notification_types_titles = array();
    foreach ($_notification_types as $possible => $ntype) {
        $notification_types_titles[] = array('NTYPE' => $ntype, 'LABEL' => do_lang_tempcode('ENABLE_NOTIFICATIONS_' . $ntype), 'RAW' => strval($possible));
    }
    $css_path = get_custom_file_base() . '/themes/' . $GLOBALS['FORUM_DRIVER']->get_theme() . '/templates_cached/' . user_lang() . '/global.css';
    $color = 'FF00FF';
    if (file_exists($css_path)) {
        $tmp_file = file_get_contents($css_path);
        $matches = array();
        if (preg_match('#\\nth[\\s,][^\\}]*\\sbackground-color:\\s*\\#([\\dA-Fa-f]*);#sU', $tmp_file, $matches) != 0) {
            $color = $matches[1];
        }
    }
    return do_template('NOTIFICATIONS_MANAGE_ADVANCED_SCREEN', array('TITLE' => $title, 'COLOR' => $color, 'ACTION_URL' => get_self_url(false, false, array('id' => NULL)), 'NOTIFICATION_TYPES_TITLES' => $notification_types_titles, 'TREE' => $tree, 'NOTIFICATION_CODE' => $notification_code));
}