Ejemplo n.º 1
0
    /**
     * Notify the admin
     *
     * @param array $comment The comment that was submitted.
     */
    public static function notifyAdmin(array $comment)
    {
        // don't notify admin in case of spam
        if ($comment['status'] == 'spam') {
            return;
        }
        // build data for pushnotification
        if ($comment['status'] == 'moderation') {
            $alert = array('loc-key' => 'NEW_COMMENT_TO_MODERATE');
        } else {
            $alert = array('loc-key' => 'NEW_COMMENT');
        }
        // get count of unmoderated items
        $badge = (int) FrontendModel::getDB()->getVar('SELECT COUNT(i.id)
			 FROM blog_comments AS i
			 WHERE i.status = ? AND i.language = ?
			 GROUP BY i.status', array('moderation', FRONTEND_LANGUAGE));
        // reset if needed
        if ($badge == 0) {
            $badge = null;
        }
        // build data
        $data = array('data' => array('endpoint' => SITE_URL . '/api/1.0', 'comment_id' => $comment['id']));
        // push it
        FrontendModel::pushToAppleApp($alert, $badge, null, $data);
        FrontendModel::pushToMicrosoftApp('NEW_COMMENT', $badge, null, null, null, null, '/MainPage.xaml?website=' . SITE_URL, null);
        // @todo: clean this up
        // get settings
        $notifyByMailOnComment = FrontendModel::getModuleSetting('blog', 'notify_by_email_on_new_comment', false);
        $notifyByMailOnCommentToModerate = FrontendModel::getModuleSetting('blog', 'notify_by_email_on_new_comment_to_moderate', false);
        // create URLs
        $URL = SITE_URL . FrontendNavigation::getURLForBlock('blog', 'detail') . '/' . $comment['post_url'] . '#comment-' . $comment['id'];
        $backendURL = SITE_URL . FrontendNavigation::getBackendURLForBlock('comments', 'blog') . '#tabModeration';
        // notify on all comments
        if ($notifyByMailOnComment) {
            // comment to moderate
            if ($comment['status'] == 'moderation') {
                // set variables
                $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
            } elseif ($comment['status'] == 'published') {
                // set variables
                $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewComment'), array($comment['author'], $URL, $comment['post_title']));
            }
            // send the mail
            FrontendMailer::addEmail(FL::msg('NotificationSubject'), FRONTEND_CORE_PATH . '/layout/templates/mails/notification.tpl', $variables);
        } elseif ($notifyByMailOnCommentToModerate && $comment['status'] == 'moderation') {
            // set variables
            $variables['message'] = vsprintf(FL::msg('BlogEmailNotificationsNewCommentToModerate'), array($comment['author'], $URL, $comment['post_title'], $backendURL));
            // send the mail
            FrontendMailer::addEmail(FL::msg('NotificationSubject'), FRONTEND_CORE_PATH . '/layout/templates/mails/notification.tpl', $variables);
        }
    }