/** * Handle comment email notifications * * Should be called only when a new comment was posted or when a comment status was changed to published * * @param boolean set true if the comment was posted just now, false otherwise * @param integer the user ID who executed the action which will be notified, or NULL if it was executed by an anonymous user */ function handle_notifications($just_posted = false, $executed_by_userid = NULL) { global $Settings; if ($just_posted) { // send email notification to moderators $this->send_email_notifications(true, false, $executed_by_userid); } if ($this->status != 'published') { // don't send notificaitons about non published comments return; } $notifications_mode = $Settings->get('outbound_notifications_mode'); if ($notifications_mode == 'off') { // don't send notification return false; } if ($this->get('notif_status') != 'noreq') { // notification have been done before, or is in progress return false; } $edited_Item =& $this->get_Item(); if ($notifications_mode == 'immediate') { // Send email notifications now! $this->send_email_notifications(false, $just_posted, $executed_by_userid); // Record that processing has been done: $this->set('notif_status', 'finished'); } else { // Create scheduled job to send notifications // CREATE OBJECT: load_class('/cron/model/_cronjob.class.php', 'Cronjob'); $edited_Cronjob = new Cronjob(); // start datetime. We do not want to ping before the post is effectively published: $edited_Cronjob->set('start_datetime', $this->date); // name: $edited_Cronjob->set('name', sprintf(T_('Send notifications about new comment on «%s»'), strip_tags($edited_Item->get('title')))); // controller: $edited_Cronjob->set('controller', 'cron/jobs/_comment_notifications.job.php'); // params: specify which post this job is supposed to send notifications for: $edited_Cronjob->set('params', array('comment_ID' => $this->ID, 'except_moderators' => $just_posted, 'executed_by_userid' => $executed_by_userid)); // Save cronjob to DB: $edited_Cronjob->dbinsert(); // Memorize the cron job ID which is going to handle this post: $this->set('notif_ctsk_ID', $edited_Cronjob->ID); // Record that processing has been scheduled: $this->set('notif_status', 'todo'); } // update comment notification params $this->dbupdate(); }
} // CREATE OBJECT: load_class('/cron/model/_cronjob.class.php', 'Cronjob'); $edited_Cronjob = new Cronjob(); if ($edited_Cronjob->load_from_Request($cron_job_names, $cron_job_params)) { // We could load data from form without errors: if (!empty($ctsk_controller)) { // Save controller field from copied object $edited_Cronjob->set('controller', $ctsk_controller); } if (!empty($ctsk_params)) { // Save params field from copied object $edited_Cronjob->set('params', $ctsk_params); } // Save to DB: $edited_Cronjob->dbinsert(); $Messages->add(T_('New job has been scheduled.'), 'success'); // Redirect so that a reload doesn't write to the DB twice: header_redirect('?ctrl=crontab', 303); // Will EXIT // We have EXITed already at this point!! } break; case 'update': // Check that this action request is not a CSRF hacked request: $Session->assert_received_crumb('crontask'); // Check that we have permission to edit options: $current_User->check_perm('options', 'edit', true, NULL); if ($edited_Cronjob->load_from_Request($cron_job_names, $cron_job_params)) { // We could load data from form without errors: if ($edited_Cronjob->dbupdate()) {
/** * Execute or schedule post(=after) processing tasks * * Includes notifications & pings * * @param boolean a new post was just created or it was called after an update * @param boolean give more info messages (we want to avoid that when we save & continue editing) */ function handle_post_processing($just_created, $verbose = true) { global $Settings, $Messages, $localtimenow, $posttypes_nopermanentURL; if ($just_created) { // we must try to send moderation notifications for the newly created posts $already_notified = $this->send_moderation_emails(); } else { // Moderation notifications were not sent, so there are no already notified users $already_notified = NULL; } $notifications_mode = $Settings->get('outbound_notifications_mode'); if ($notifications_mode == 'off') { // Exit silently return false; } if ($this->notifications_status == 'finished') { // pings have been done before if ($verbose) { $Messages->add(T_('Post had already pinged: skipping notifications...'), 'note'); } return false; } if ($this->notifications_status != 'noreq') { // pings have been done before // TODO: Check if issue_date has changed and reschedule if ($verbose) { $Messages->add(T_('Post processing already pending...'), 'note'); } return false; } if ($this->status != 'published') { // TODO: discard any notification that may be pending! if ($verbose) { $Messages->add(T_('Post not publicly published: skipping notifications...'), 'note'); } return false; } if (in_array($this->ityp_ID, $posttypes_nopermanentURL)) { // TODO: discard any notification that may be pending! if ($verbose) { $Messages->add(T_('This post type doesn\'t need notifications...'), 'note'); } return false; } if ($notifications_mode == 'immediate' && strtotime($this->issue_date) <= $localtimenow) { // We want to do the post processing immediately: // send outbound pings: $this->send_outbound_pings($verbose); // Send email notifications now! $this->send_email_notifications(false, $already_notified); // Record that processing has been done: $this->set('notifications_status', 'finished'); } else { // We want asynchronous post processing. This applies to posts with date in future too. $Messages->add(sprintf(T_('You just published a post in the future. You must set your notifications to <a %s>Asynchronous</a> so that b2evolution can send out notification when this post goes live.'), 'href="http://b2evolution.net/man/after-each-post-settings"'), 'warning'); // CREATE OBJECT: load_class('/cron/model/_cronjob.class.php', 'Cronjob'); $edited_Cronjob = new Cronjob(); // start datetime. We do not want to ping before the post is effectively published: $edited_Cronjob->set('start_datetime', $this->issue_date); // no repeat. // key: $edited_Cronjob->set('key', 'send-post-notifications'); // params: specify which post this job is supposed to send notifications for: $edited_Cronjob->set('params', array('item_ID' => $this->ID)); // Save cronjob to DB: $edited_Cronjob->dbinsert(); // Memorize the cron job ID which is going to handle this post: $this->set('notifications_ctsk_ID', $edited_Cronjob->ID); // Record that processing has been scheduled: $this->set('notifications_status', 'todo'); } // Save the new processing status to DB, but do not update last edited by user, slug or post excerpt $this->dbupdate(false, false, false); return true; }
/** * Handle comment email notifications * * Should be called only when a new comment was posted or when a comment status was changed to published * * @param boolean set true if the comment was posted just now, false otherwise * @param integer the user ID who executed the action which will be notified, or NULL if it was executed by an anonymous user */ function handle_notifications($just_posted = false, $executed_by_userid = NULL) { global $Settings; if ($just_posted) { // send email notification to moderators or to users with "meta comments" notification $this->send_email_notifications(true, false, $executed_by_userid); if ($this->is_meta()) { // Record that processing has been done in case of this meta comment $this->set('notif_status', 'finished'); $this->dbupdate(); } } if ($this->is_meta()) { // Meta comments were already notified when they were posted. return; } if ($this->status != 'published') { // don't send notificaitons about non published comments return; } $notifications_mode = $Settings->get('outbound_notifications_mode'); if ($notifications_mode == 'off') { // don't send notification return false; } if ($this->get('notif_status') != 'noreq') { // notification have been done before, or is in progress return false; } $edited_Item =& $this->get_Item(); if ($notifications_mode == 'immediate') { // Send email notifications now! $this->send_email_notifications(false, $just_posted, $executed_by_userid); // Record that processing has been done: $this->set('notif_status', 'finished'); } else { // Create scheduled job to send notifications // CREATE OBJECT: load_class('/cron/model/_cronjob.class.php', 'Cronjob'); $edited_Cronjob = new Cronjob(); // start datetime. We do not want to ping before the post is effectively published: $edited_Cronjob->set('start_datetime', $this->date); // key: $edited_Cronjob->set('key', 'send-comment-notifications'); // params: specify which post this job is supposed to send notifications for: $edited_Cronjob->set('params', array('comment_ID' => $this->ID, 'except_moderators' => $just_posted, 'executed_by_userid' => $executed_by_userid)); // Save cronjob to DB: $edited_Cronjob->dbinsert(); // Memorize the cron job ID which is going to handle this post: $this->set('notif_ctsk_ID', $edited_Cronjob->ID); // Record that processing has been scheduled: $this->set('notif_status', 'todo'); } // update comment notification params $this->dbupdate(); }
/** * Execute or schedule post(=after) processing tasks * * Includes notifications & pings * * @param boolean a new post was just created or it was called after an update * @param boolean give more info messages (we want to avoid that when we save & continue editing) */ function handle_post_processing($just_created, $verbose = true) { global $Settings, $Messages, $localtimenow, $posttypes_nopermanentURL; if ($just_created) { // we must try to send moderation notifications for the newly created posts $already_notified = $this->send_moderation_emails(); } else { // Moderation notifications were not sent, so there are no already notified users $already_notified = NULL; } $notifications_mode = $Settings->get('outbound_notifications_mode'); if ($notifications_mode == 'off') { // Exit silently return false; } if ($this->notifications_status == 'finished') { // pings have been done before if ($verbose) { $Messages->add(T_('Post had already pinged: skipping notifications...'), 'note'); } return false; } if ($this->notifications_status != 'noreq') { // pings have been done before // TODO: Check if issue_date has changed and reschedule if ($verbose) { $Messages->add(T_('Post processing already pending...'), 'note'); } return false; } if ($this->status != 'published') { // TODO: discard any notification that may be pending! if ($verbose) { $Messages->add(T_('Post not publicly published: skipping notifications...'), 'note'); } return false; } if (in_array($this->ptyp_ID, $posttypes_nopermanentURL)) { // TODO: discard any notification that may be pending! if ($verbose) { $Messages->add(T_('This post type doesn\'t need notifications...'), 'note'); } return false; } if ($notifications_mode == 'immediate' && strtotime($this->issue_date) <= $localtimenow) { // We want to do the post processing immediately: // send outbound pings: $this->send_outbound_pings($verbose); // Send email notifications now! $this->send_email_notifications(false, $already_notified); // Record that processing has been done: $this->set('notifications_status', 'finished'); } else { // We want asynchronous post processing. This applies to posts with date in future too. $Messages->add(T_('Scheduling asynchronous notifications...'), 'note'); // CREATE OBJECT: load_class('/cron/model/_cronjob.class.php', 'Cronjob'); $edited_Cronjob = new Cronjob(); // start datetime. We do not want to ping before the post is effectively published: $edited_Cronjob->set('start_datetime', $this->issue_date); // no repeat. // name: $edited_Cronjob->set('name', sprintf(T_('Send notifications for «%s»'), strip_tags($this->title))); // controller: $edited_Cronjob->set('controller', 'cron/jobs/_post_notifications.job.php'); // params: specify which post this job is supposed to send notifications for: $edited_Cronjob->set('params', array('item_ID' => $this->ID)); // Save cronjob to DB: $edited_Cronjob->dbinsert(); // Memorize the cron job ID which is going to handle this post: $this->set('notifications_ctsk_ID', $edited_Cronjob->ID); // Record that processing has been scheduled: $this->set('notifications_status', 'todo'); } // Save the new processing status to DB $this->dbupdate(); return true; }