function OnPreRender()
 {
     /* @var $o_top_level Category */
     $review_item = $this->o_topic->GetReviewItem();
     $s_suggested_title = urlencode(StringFormatter::PlainText(trim($review_item->GetTitle())));
     $s_page = urlencode($_SERVER['REQUEST_URI']);
     $s_subscribe_link = '/play/subscribe.php?type=' . $review_item->GetType() . '&item=' . $review_item->GetId() . '&title=' . $s_suggested_title . '&page=' . $s_page;
     $s_subscribe_title = 'Get an email alert every time there are new comments on this page';
     $this->AddControl('<div class="forumSubscribe"><a href="' . $s_subscribe_link . '" title="' . $s_subscribe_title . '">Subscribe to comments</a></div>');
     if (!$this->authentication_manager->GetUser()->Permissions()->HasPermission(PermissionType::ForumAddMessage())) {
         $add = $this->o_topic->GetCount() ? 'Add your comments' : 'Be the first to add your comments!';
         $this->AddControl('<div class="forumPost"><a href="' . Html::Encode($this->authentication_manager->GetPermissionUrl()) . urlencode('#forumMessageForm') . '">' . $add . '</a></div>');
     }
 }
 function SendCommentsSubscriptions(ReviewItem $review_item, ForumMessage $message)
 {
     # get all subscriptions for this item
     if (AuthenticationManager::GetUser()->IsSignedIn() and $review_item->GetId()) {
         $s_person = $this->GetSettings()->GetTable('User');
         $s_sub = $this->GetSettings()->GetTable('EmailSubscription');
         # join to item's table to get the title, regardless of message title
         $s_sql = '';
         switch ($review_item->GetType()) {
             case ContentType::STOOLBALL_MATCH:
                 $matches = $this->GetSettings()->GetTable('Match');
                 $s_sql = "SELECT {$matches}.match_title AS title, {$s_person}.email\n\t\t\t\t\tFROM ({$s_person} INNER JOIN {$s_sub} ON {$s_person}.user_id = {$s_sub}.user_id AND {$s_sub}.item_type = " . ContentType::STOOLBALL_MATCH . ")\n\t\t\t\t\tINNER JOIN {$matches} ON {$s_sub}.item_id = {$matches}.match_id AND {$s_sub}.item_type = " . ContentType::STOOLBALL_MATCH . "\n\t\t\t\t\tWHERE {$s_sub}.item_id = " . Sql::ProtectNumeric($review_item->GetId()) . " AND {$s_person}.user_id <> " . Sql::ProtectNumeric(AuthenticationManager::GetUser()->GetId());
                 break;
         }
         if ($s_sql) {
             # if there's at least one person, build email
             require_once 'Zend/Mail.php';
             $email = new Zend_Mail('UTF-8');
             if ($this->GetEmailAddresses($s_sql, $email)) {
                 $o_filter = new BadLanguageFilter();
                 $s_title = $o_filter->Filter($this->s_review_item_title);
                 unset($o_filter);
                 $s_title = StringFormatter::PlainText($s_title);
                 # send the email
                 $email->addTo($this->GetSettings()->GetSubscriptionEmailTo());
                 $email->setFrom($this->GetSettings()->GetSubscriptionEmailFrom(), $this->GetSettings()->GetSubscriptionEmailFrom());
                 $email->setSubject("Email alert: '" . $s_title . "'");
                 $email->setBodyText($this->GetHeader() . trim(AuthenticationManager::GetUser()->GetName()) . ' has just commented on a page at ' . $this->GetSettings()->GetSiteName() . ' for which you subscribed to an email alert.' . "\n\n" . "The page is called '" . $s_title . "' - here's an excerpt of the new comments:\n\n" . $message->GetExcerpt() . "\n\n" . 'View the new comments at' . "\n" . $review_item->GetNavigateUrl() . '#message' . $message->GetId() . $this->GetFooter());
                 try {
                     $email->send();
                 } catch (Zend_Mail_Transport_Exception $e) {
                     # Do nothing - email not that important so, if it fails, fail silently rather than raising a fatal error
                 }
             }
         }
     }
 }