Example #1
0
 function get_prerendered_content($format = 'htmlbody')
 {
     global $CommentList, $Plugins, $DB;
     $use_cache = $this->ID && in_array($format, array('htmlbody', 'entityencoded', 'xml', 'text'));
     if ($use_cache) {
         // the format/comment can be cached:
         if (empty($CommentList)) {
             // set comments Blog from comment Item
             $this->get_Item();
             $comments_Blog =& $this->Item->get_Blog();
         } else {
             // set comments Blog from CommentList
             $comments_Blog =& $CommentList->Blog;
         }
         $comment_renderers = $this->get_renderers_validated();
         if (empty($comment_renderers)) {
             return format_to_output($this->content, $format);
         }
         $comment_renderers = implode('.', $comment_renderers);
         $cache_key = $format . '/' . $comment_renderers;
         $CommentPrerenderingCache =& get_CommentPrerenderingCache();
         if (isset($CommentPrerenderingCache[$format][$this->ID][$cache_key])) {
             // already in PHP cache.
             $r = $CommentPrerenderingCache[$format][$this->ID][$cache_key];
             // Save memory, typically only accessed once.
             unset($CommentPrerenderingCache[$format][$this->ID][$cache_key]);
         } else {
             // try loading into Cache
             if (!isset($CommentPrerenderingCache[$format])) {
                 // only do the prefetch loading once.
                 $CommentPrerenderingCache[$format] = array();
                 $SQL = new SQL();
                 $SQL->SELECT('cmpr_cmt_ID, cmpr_format, cmpr_renderers, cmpr_content_prerendered');
                 $SQL->FROM('T_comments__prerendering');
                 if (empty($CommentList)) {
                     // load prerendered cache for each comment which belongs to this comments Item
                     $SQL->FROM_add('INNER JOIN T_comments ON cmpr_cmt_ID = comment_ID');
                     $SQL->WHERE('comment_post_ID = ' . $this->Item->ID);
                 } else {
                     // load prerendered cache for each comment from the CommentList
                     $SQL->WHERE('cmpr_cmt_ID IN ( ' . implode(',', $CommentList->get_page_ID_array()) . ' )');
                 }
                 $SQL->WHERE_and('cmpr_format = ' . $DB->quote($format));
                 $rows = $DB->get_results($SQL->get(), OBJECT, 'Preload prerendered comments content (' . $format . ')');
                 foreach ($rows as $row) {
                     $row_cache_key = $row->cmpr_format . '/' . $row->cmpr_renderers;
                     if (!isset($CommentPrerenderingCache[$format][$row->cmpr_cmt_ID])) {
                         // init list
                         $CommentPrerenderingCache[$format][$row->cmpr_cmt_ID] = array();
                     }
                     $CommentPrerenderingCache[$format][$row->cmpr_cmt_ID][$row_cache_key] = $row->cmpr_content_prerendered;
                 }
                 // Get the value for current Comment.
                 if (isset($CommentPrerenderingCache[$format][$this->ID][$cache_key])) {
                     $r = $CommentPrerenderingCache[$format][$this->ID][$cache_key];
                     // Save memory, typically only accessed once.
                     unset($CommentPrerenderingCache[$format][$this->ID][$cache_key]);
                 }
             }
         }
     }
     if (!isset($r)) {
         $data = $this->content;
         $Plugins->trigger_event('FilterCommentContent', array('data' => &$data, 'Comment' => $this));
         $r = format_to_output($data, $format);
         if ($use_cache) {
             // save into DB (using REPLACE INTO because it may have been pre-rendered by another thread since the SELECT above)
             $DB->query("\n\t\t\t\t\tREPLACE INTO T_comments__prerendering (cmpr_cmt_ID, cmpr_format, cmpr_renderers, cmpr_content_prerendered)\n\t\t\t\t\t VALUES ( " . $this->ID . ", '" . $format . "', " . $DB->quote($comment_renderers) . ', ' . $DB->quote($r) . ' )', 'Cache prerendered comment content');
         }
     }
     return $r;
 }
Example #2
0
 /**
  * Set Blog
  */
 function load_Blog()
 {
     if (is_null($this->Blog)) {
         $this->Blog =& $this->Item->get_Blog();
     }
 }