Example #1
0
 /**
  * Notify the subscribers of new comments
  *
  * @param CommentsModel $objComment
  */
 public static function notifyCommentsSubscribers(CommentsModel $objComment)
 {
     // Notified already
     if ($objComment->notified) {
         return;
     }
     $objNotify = \CommentsNotifyModel::findActiveBySourceAndParent($objComment->source, $objComment->parent);
     // No subscriptions
     if ($objNotify === null) {
         return;
     }
     while ($objNotify->next()) {
         // Don't notify the commentor about his own comment
         if ($objNotify->email == $objComment->email) {
             continue;
         }
         // Prepare the URL
         $strUrl = \Idna::decode(\Environment::get('base')) . $objNotify->url;
         $objEmail = new \Email();
         $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
         $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME'];
         $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['com_notifySubject'], \Idna::decode(\Environment::get('host')));
         $objEmail->text = sprintf($GLOBALS['TL_LANG']['MSC']['com_notifyMessage'], $objNotify->name, $strUrl, $strUrl . '?token=' . $objNotify->tokenRemove);
         $objEmail->sendTo($objNotify->email);
     }
     $objComment->notified = 1;
     $objComment->save();
 }
 /**
  * Return the meta fields of a news article as array.
  *
  * @param NewsModel $objArticle The model.
  *
  * @return array
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.Superglobals)
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 protected function getMetaFields($objArticle)
 {
     $meta = deserialize($this->news_metaFields);
     if (!is_array($meta)) {
         return array();
     }
     $return = array();
     foreach ($meta as $field) {
         switch ($field) {
             case 'date':
                 $return['date'] = Date::parse($GLOBALS['objPage']->datimFormat, $objArticle->date);
                 break;
             case 'author':
                 if (($objAuthor = $objArticle->getRelated('author')) !== null) {
                     if ($objAuthor->google != '') {
                         $return['author'] = $GLOBALS['TL_LANG']['MSC']['by'] . ' <a href="https://plus.google.com/' . $objAuthor->google . '" rel="author" target="_blank">' . $objAuthor->name . '</a>';
                     } else {
                         $return['author'] = $GLOBALS['TL_LANG']['MSC']['by'] . ' ' . $objAuthor->name;
                     }
                 }
                 break;
             case 'comments':
                 if ($objArticle->noComments || $objArticle->source != 'default') {
                     break;
                 }
                 $intTotal = CommentsModel::countPublishedBySourceAndParent('tl_news', $objArticle->id);
                 $return['ccount'] = $intTotal;
                 $return['comments'] = sprintf($GLOBALS['TL_LANG']['MSC']['commentCount'], $intTotal);
                 break;
             default:
         }
     }
     return $return;
 }