/packages/vbcms/search/result/content.php

https://github.com/ProjectBenelux/Website · PHP · 234 lines · 129 code · 26 blank · 79 comment · 10 complexity · 8a72d4694698965194794e92382972b6 MD5 · raw file

  1. <?php if (!defined('VB_ENTRY')) die('Access denied.');
  2. /*======================================================================*\
  3. || #################################################################### ||
  4. || # vBulletin 4.1.5
  5. || # ---------------------------------------------------------------- # ||
  6. || # Copyright ©2000-2011 vBulletin Solutions Inc. All Rights Reserved. ||
  7. || # This file may not be redistributed in whole or significant part. # ||
  8. || # ---------------- VBULLETIN IS NOT FREE SOFTWARE ---------------- # ||
  9. || # http://www.vbulletin.com | http://www.vbulletin.com/license.html # ||
  10. || #################################################################### ||
  11. \*======================================================================*/
  12. /**
  13. * @package vBulletin
  14. * @subpackage Search
  15. * @author Ed Brown, vBulletin Development Team
  16. * @version $Id: content.php 38280 2010-08-11 20:20:21Z ksours $
  17. * @since $Date: 2010-08-11 13:20:21 -0700 (Wed, 11 Aug 2010) $
  18. * @copyright vBulletin Solutions Inc.
  19. */
  20. require_once (DIR . '/vb/search/result.php');
  21. include_once DIR . '/packages/vbcms/item/content/article.php';
  22. require_once (DIR . '/vb/search/indexcontroller/null.php');
  23. /**
  24. * Result Implementation for CMS Article
  25. *
  26. * @see vB_Search_Result
  27. * @package vBulletin
  28. * @subpackage Search
  29. */
  30. class vBCms_Search_Result_Article extends vB_Search_Result
  31. {
  32. /** record node id **/
  33. private $itemid;
  34. /** database record **/
  35. private $record;
  36. /**
  37. * factory method to create a result object
  38. *
  39. * @param integer $id
  40. * @return result object
  41. */
  42. public static function create($id)
  43. {
  44. $contenttypeid = vb_Types::instance()->getContentTypeId('vBCms_Article');
  45. if ($rst = vB::$vbulletin->db->query_read("SELECT a.contentid as itemid,
  46. u.username, a.contentid, n.nodeid, u.userid, i.html_title,
  47. a.pagetext, i.title, i.description, n.publishdate, u.avatarrevision
  48. " . (vB::$vbulletin->options['avatarenabled'] ? ", avatar.avatarpath,
  49. customavatar.userid AS hascustomavatar, customavatar.dateline AS avatardateline,
  50. customavatar.width AS avwidth,customavatar.height AS avheight" : "") .
  51. " FROM " . TABLE_PREFIX . "cms_article a
  52. LEFT JOIN " . TABLE_PREFIX . "cms_node n ON n.contentid = a.contentid
  53. LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo i ON i.nodeid = n.nodeid
  54. LEFT JOIN " . TABLE_PREFIX . "user u ON u.userid = n.userid
  55. " . (vB::$vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX .
  56. "avatar AS avatar ON(avatar.avatarid = u.avatarid) LEFT JOIN " . TABLE_PREFIX .
  57. "customavatar AS customavatar ON(customavatar.userid = u.userid)" : "") . "
  58. WHERE a.contentid = $id AND n.contenttypeid = " . $contenttypeid))
  59. {
  60. if ($search_result = vB::$vbulletin->db->fetch_array($rst))
  61. {
  62. //If unpublished we hide this.
  63. if (!($search_result['publishdate'] < TIMENOW))
  64. {
  65. continue;
  66. }
  67. $item = new vBCms_Search_Result_Article();
  68. $item->itemid = $search_result['itemid'];
  69. $item->contenttypeid = $contenttypeid;
  70. $item->record = $search_result;
  71. return $item;
  72. }
  73. return false;
  74. }
  75. }
  76. /**
  77. * this will create an array of result objects from an array of ids()
  78. *
  79. * @param array of integer $ids
  80. * @return array of objects
  81. */
  82. public static function create_array($ids)
  83. {
  84. $contenttypeid = vb_Types::instance()->getContentTypeId('vBCms_Article');
  85. if ($rst = vB::$vbulletin->db->query_read("SELECT a.contentid as itemid,
  86. u.username, a.contentid, n.nodeid, u.userid, i.html_title,
  87. a.pagetext, i.title, i.description, n.publishdate
  88. FROM " . TABLE_PREFIX . "cms_article a
  89. LEFT JOIN " . TABLE_PREFIX . "cms_node n ON n.contentid = a.contentid
  90. LEFT JOIN " . TABLE_PREFIX . "cms_nodeinfo i ON i.nodeid = n.nodeid
  91. LEFT JOIN " . TABLE_PREFIX . "user u ON u.userid = n.userid
  92. WHERE a.contentid IN (" . implode(', ', $ids) .
  93. ") AND n.contenttypeid = " . $contenttypeid))
  94. {
  95. while ($search_result = vB::$vbulletin->db->fetch_array($rst))
  96. {
  97. //If unpublished we hide this.
  98. if (!($search_result['publishdate'] < TIMENOW))
  99. {
  100. continue;
  101. }
  102. $item = new vBCms_Search_Result_Article();
  103. $item->itemid = $search_result['itemid'];
  104. $item->contenttypeid = $contenttypeid;
  105. $item->record = $search_result;
  106. $items[$search_result['itemid']] = $item;
  107. }
  108. return $items;
  109. }
  110. return false;
  111. }
  112. /**
  113. * protected constructor, to ensure use of create()
  114. *
  115. */
  116. protected function __construct()
  117. {}
  118. /**
  119. * all result objects must tell their contenttypeid
  120. *
  121. * @return integer contenttypeid
  122. */
  123. public function get_contenttype()
  124. {
  125. return isset($this->contenttypeid) ?
  126. $this->contenttypeid :
  127. vB_Types::instance()->getContentTypeID("vBCms_Article");
  128. }
  129. /**
  130. * all result objects must tell whether they are searchable
  131. *
  132. * @param mixed $user: the id of the user requesting access
  133. * @return bool true
  134. */
  135. public function can_search($user)
  136. {
  137. //By definition, an article is always searchable, even
  138. // for a guest.
  139. return true;
  140. }
  141. /**
  142. * function to return the rendered html for this result
  143. *
  144. * @param string $current_user
  145. * @param object $criteria
  146. * @return
  147. */
  148. public function render($current_user, $criteria, $template_name = '')
  149. {
  150. global $vbulletin;
  151. global $show;
  152. include_once DIR . '/vb/search/searchtools.php';
  153. if (!strlen($template_name))
  154. {
  155. $template_name = 'vbcms_content_article_preview';
  156. }
  157. $template = vB_Template::create($template_name);
  158. $template->register('title', $this->record['title'] );
  159. $template->register('html_title', $this->record['html_title'] );
  160. $page_url = vB_Route::create('vBCms_Route_Content', $this->record['nodeid'])->getCurrentURL();
  161. $template->register('page_url', $page_url);
  162. $join_char = strpos($page_url,'?') ? '&amp;' : '?';
  163. $template->register('newcomment_url', $page_url . $join_char . "goto=newcomment");
  164. $template->register('username', $this->record['username']);
  165. $template->register('description', $this->record['description']);
  166. $template->register('pagetext',
  167. vB_Search_Searchtools::getSummary($this->record['pagetext'], 100));
  168. $template->register('dateline', date($vbulletin->options['dateformat']. ' '
  169. . $vbulletin->options['default_timeformat'], $this->record['dateline']));
  170. if (vB::$vbulletin->options['avatarenabled'])
  171. {
  172. $avatar = fetch_avatar_from_record($post);
  173. }
  174. else
  175. {
  176. $avatar = false;
  177. }
  178. $template->register('avatar', $avatar);
  179. $result = $template->render();
  180. return $result;
  181. }
  182. /**** returns the database record
  183. *
  184. * @return array
  185. ****/
  186. public function get_record()
  187. {
  188. return $this->record;
  189. }
  190. /*** Returns the primary id. Allows us to cache a result item.
  191. *
  192. * @result integer
  193. ***/
  194. public function get_id()
  195. {
  196. if (isset($this->record) AND isset($this->record['nodeid']) )
  197. {
  198. return $this->record['nodeid'];
  199. }
  200. return false;
  201. }
  202. }
  203. /*======================================================================*\
  204. || ####################################################################
  205. || #
  206. || # SVN: $Revision: 38280 $
  207. || ####################################################################
  208. \*======================================================================*/