PageRenderTime 57ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/html/AppCode/expressionengine/modules/comment/mod.comment.php

https://github.com/w3bg/www.hsifin.com
PHP | 3324 lines | 2126 code | 623 blank | 575 comment | 544 complexity | b5f2cc077858179941b24ddac8141f17 MD5 | raw file
Possible License(s): AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author ExpressionEngine Dev Team
  7. * @copyright Copyright (c) 2003 - 2010, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Comment Module
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Modules
  19. * @category Modules
  20. * @author ExpressionEngine Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Comment {
  24. // Maximum number of comments. This is a safety valve
  25. // in case the user doesn't specify a maximum
  26. var $limit = 100;
  27. // Show anchor?
  28. // TRUE/FALSE
  29. // Determines whether to show the <a name> anchor above each comment
  30. var $show_anchor = FALSE;
  31. // Comment Expiration Mode
  32. // 0 - Comments only expire if the comment expiration field in the PUBLISH page contains a value.
  33. // 1 - If the comment expiration field is blank, comments will still expire if the global preference
  34. // is set in the Channel Preferences page. Use this option only if you used EE prior to
  35. // version 1.1 and you want your old comments to expire.
  36. var $comment_expiration_mode = 0;
  37. /**
  38. * Constructor
  39. *
  40. * @access public
  41. */
  42. function Comment()
  43. {
  44. // Make a local reference to the ExpressionEngine super object
  45. $this->EE =& get_instance();
  46. $fields = array('name', 'email', 'url', 'location', 'comment');
  47. foreach ($fields as $val)
  48. {
  49. if (isset($_POST[$val] ))
  50. {
  51. $_POST[$val] = $this->EE->functions->encode_ee_tags($_POST[$val], TRUE);
  52. if ($val == 'comment')
  53. {
  54. $_POST[$val] = $this->EE->security->xss_clean($_POST[$val]);
  55. }
  56. }
  57. }
  58. }
  59. // --------------------------------------------------------------------
  60. /**
  61. * Comment Entries
  62. *
  63. * @access public
  64. * @return string
  65. */
  66. function entries()
  67. {
  68. $return = '';
  69. $current_page = '';
  70. $qstring = $this->EE->uri->query_string;
  71. $uristr = $this->EE->uri->uri_string;
  72. $switch = array();
  73. $search_link = '';
  74. // Pagination variables
  75. $paginate = FALSE;
  76. $paginate_data = '';
  77. $pagination_links = '';
  78. $page_next = '';
  79. $page_previous = '';
  80. $current_page = 0;
  81. $t_current_page = '';
  82. $total_pages = 1;
  83. if ($this->EE->TMPL->fetch_param('dynamic') == 'no')
  84. {
  85. $dynamic = FALSE;
  86. }
  87. else
  88. {
  89. $dynamic = TRUE;
  90. }
  91. $force_entry = FALSE;
  92. if ($this->EE->TMPL->fetch_param('entry_id') !== FALSE OR $this->EE->TMPL->fetch_param('url_title') !== FALSE OR $this->EE->TMPL->fetch_param('comment_id') !== FALSE)
  93. {
  94. $force_entry = TRUE;
  95. }
  96. /** ----------------------------------------------
  97. /** Do we allow dynamic POST variables to set parameters?
  98. /** ----------------------------------------------*/
  99. if ($this->EE->TMPL->fetch_param('dynamic_parameters') !== FALSE AND isset($_POST) AND count($_POST) > 0)
  100. {
  101. foreach (explode('|', $this->EE->TMPL->fetch_param('dynamic_parameters')) as $var)
  102. {
  103. if (isset($_POST[$var]) AND in_array($var, array('channel', 'limit', 'sort', 'orderby')))
  104. {
  105. $this->EE->TMPL->tagparams[$var] = $_POST[$var];
  106. }
  107. }
  108. }
  109. /** --------------------------------------
  110. /** Parse page number
  111. /** --------------------------------------*/
  112. // We need to strip the page number from the URL for two reasons:
  113. // 1. So we can create pagination links
  114. // 2. So it won't confuse the query with an improper proper ID
  115. if ( ! $dynamic)
  116. {
  117. if (preg_match("#(^|/)N(\d+)(/|$)#i", $qstring, $match))
  118. {
  119. $current_page = $match['2'];
  120. $uristr = trim($this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $uristr)), '/');
  121. }
  122. }
  123. else
  124. {
  125. if (preg_match("#(^|/)P(\d+)(/|$)#", $qstring, $match))
  126. {
  127. $current_page = $match['2'];
  128. $uristr = $this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $uristr));
  129. $qstring = trim($this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $qstring)), '/');
  130. }
  131. }
  132. if ($dynamic == TRUE OR $force_entry == TRUE)
  133. {
  134. // Fetch channel_ids if appropriate
  135. $channel_ids = array();
  136. if ($channel = $this->EE->TMPL->fetch_param('channel') OR $this->EE->TMPL->fetch_param('site'))
  137. {
  138. $this->EE->db->select('channel_id');
  139. $this->EE->db->where_in('site_id', $this->EE->TMPL->site_ids);
  140. if ($channel !== FALSE)
  141. {
  142. $this->EE->functions->ar_andor_string($channel, 'channel_name');
  143. }
  144. $channels = $this->EE->db->get('channels');
  145. if ($channels->num_rows() == 0)
  146. {
  147. return false;
  148. }
  149. else
  150. {
  151. foreach($channels->result_array() as $row)
  152. {
  153. $channel_ids[] = $row['channel_id'];
  154. }
  155. }
  156. }
  157. // Check if an entry_id or url_title was specified
  158. if ($entry_id = $this->EE->TMPL->fetch_param('entry_id'))
  159. {
  160. $sql = substr($this->EE->functions->sql_andor_string($entry_id, 'entry_id'), 4);
  161. $this->EE->db->where($sql, NULL, FALSE);
  162. }
  163. elseif ($url_title = $this->EE->TMPL->fetch_param('url_title'))
  164. {
  165. $sql = substr($this->EE->functions->sql_andor_string($url_title, 'url_title'), 4);
  166. $this->EE->db->where($sql, NULL, FALSE);
  167. }
  168. else
  169. {
  170. // If there is a slash in the entry ID we'll kill everything after it.
  171. $entry_id = trim($qstring);
  172. $entry_id = preg_replace("#/.+#", "", $entry_id);
  173. // Have to choose between id or url title
  174. if ( ! is_numeric($entry_id))
  175. {
  176. $this->EE->db->where('url_title', $entry_id);
  177. }
  178. else
  179. {
  180. $this->EE->db->where('entry_id', $entry_id);
  181. }
  182. }
  183. /** ----------------------------------------
  184. /** Do we have a valid entry ID number?
  185. /** ----------------------------------------*/
  186. $timestamp = ($this->EE->TMPL->cache_timestamp != '') ? $this->EE->localize->set_gmt($this->EE->TMPL->cache_timestamp) : $this->EE->localize->now;
  187. $this->EE->db->select('entry_id, channel_titles.channel_id');
  188. $this->EE->db->where('channel_titles.channel_id = '.$this->EE->db->dbprefix('channels').'.channel_id');
  189. $this->EE->db->where_in('channel_titles.site_id', $this->EE->TMPL->site_ids);
  190. if ($this->EE->TMPL->fetch_param('show_expired') !== 'yes')
  191. {
  192. $date_where = "(".$this->EE->db->protect_identifiers('expiration_date')." = 0 OR "
  193. .$this->EE->db->protect_identifiers('expiration_date')." > {$timestamp})";
  194. $this->EE->db->where($date_where);
  195. }
  196. if ($author_id = $this->EE->TMPL->fetch_param('author_id'))
  197. {
  198. $this->EE->db->where('author_id', $author_id);
  199. }
  200. if ($e_status = $this->EE->TMPL->fetch_param('entry_status'))
  201. {
  202. $e_status = str_replace('Open', 'open', $e_status);
  203. $e_status = str_replace('Closed', 'closed', $e_status);
  204. $sql = $this->EE->functions->sql_andor_string($e_status, 'status');
  205. if (stristr($sql, "'closed'") === FALSE)
  206. {
  207. $sql .= " AND status != 'closed' ";
  208. }
  209. // We need to drop the leading AND from the generated string
  210. $sql = substr($sql, 4);
  211. $this->EE->db->where($sql, NULL, FALSE);
  212. }
  213. else
  214. {
  215. $this->EE->db->where('status !=', 'closed');
  216. }
  217. /** ----------------------------------------------
  218. /** Limit to/exclude specific channels
  219. /** ----------------------------------------------*/
  220. if (count($channel_ids) == 1)
  221. {
  222. $this->EE->db->where('channel_titles.channel_id', $channel_ids['0']);
  223. }
  224. elseif (count($channel_ids) > 1)
  225. {
  226. $this->EE->db->where_in('channel_titles.channel_id', $channel_ids);
  227. }
  228. $this->EE->db->from('channel_titles');
  229. $this->EE->db->from('channels');
  230. $query = $this->EE->db->get();
  231. // Bad ID? See ya!
  232. if ($query->num_rows() == 0)
  233. {
  234. return FALSE;
  235. }
  236. // We'll reassign the entry IDs so they're the true numeric ID
  237. foreach($query->result_array() as $row)
  238. {
  239. $entry_ids[] = $row['entry_id'];
  240. }
  241. }
  242. // If the comment tag is being used in freeform mode
  243. // we need to fetch the channel ID numbers
  244. if ( ! $dynamic)
  245. {
  246. if ($channel = $this->EE->TMPL->fetch_param('channel') OR $this->EE->TMPL->fetch_param('site'))
  247. {
  248. $this->EE->db->select('channel_id');
  249. $this->EE->db->where_in('site_id', $this->EE->TMPL->site_ids);
  250. if ($channel !== FALSE)
  251. {
  252. $this->EE->functions->ar_andor_string($channel, 'channel_name');
  253. }
  254. $query = $this->EE->db->get('channels');
  255. if ($query->num_rows() == 0)
  256. {
  257. return $this->EE->TMPL->no_results();
  258. }
  259. else
  260. {
  261. // Store the query components in the AR cache so we don't need to
  262. // recompile them after we run count_all_results for pagination.
  263. $this->EE->db->start_cache();
  264. if ($query->num_rows() == 1)
  265. {
  266. $this->EE->db->where('channel_id', $query->row('channel_id'));
  267. }
  268. else
  269. {
  270. $ids = array();
  271. foreach ($query->result_array() as $row)
  272. {
  273. $ids[] = $row['channel_id'];
  274. }
  275. $this->EE->db->where_in('channel_id', $ids);
  276. }
  277. }
  278. }
  279. }
  280. /** ----------------------------------------
  281. /** Set sorting and limiting
  282. /** ----------------------------------------*/
  283. if ( ! $dynamic)
  284. {
  285. $limit = ( ! $this->EE->TMPL->fetch_param('limit')) ? 100 : $this->EE->TMPL->fetch_param('limit');
  286. $sort = ( ! $this->EE->TMPL->fetch_param('sort')) ? 'desc' : $this->EE->TMPL->fetch_param('sort');
  287. }
  288. else
  289. {
  290. $limit = ( ! $this->EE->TMPL->fetch_param('limit')) ? $this->limit : $this->EE->TMPL->fetch_param('limit');
  291. $sort = ( ! $this->EE->TMPL->fetch_param('sort')) ? 'asc' : $this->EE->TMPL->fetch_param('sort');
  292. }
  293. $allowed_sorts = array('date', 'email', 'location', 'name', 'url');
  294. /** ----------------------------------------
  295. /** Fetch comment ID numbers
  296. /** ----------------------------------------*/
  297. $temp = array();
  298. $i = 0;
  299. // Left this here for backward compatibility
  300. // We need to deprecate the "order_by" parameter
  301. if ($this->EE->TMPL->fetch_param('orderby') != '')
  302. {
  303. $order_by = $this->EE->TMPL->fetch_param('orderby');
  304. }
  305. else
  306. {
  307. $order_by = $this->EE->TMPL->fetch_param('order_by');
  308. }
  309. $random = ($order_by == 'random') ? TRUE : FALSE;
  310. $order_by = ($order_by == 'date' OR ! in_array($order_by, $allowed_sorts)) ? 'comment_date' : $order_by;
  311. $this->EE->db->select('comment_date, comment_id');
  312. $comment_sql = FALSE;
  313. if ($status = $this->EE->TMPL->fetch_param('status'))
  314. {
  315. $status = strtolower($status);
  316. $status = str_replace('open', 'o', $status);
  317. $status = str_replace('closed', 'c', $status);
  318. $status = str_replace('pending', 'p', $status);
  319. $comment_sql = $this->EE->functions->sql_andor_string($status, 'status');
  320. if (stristr($comment_sql, "'c'") === FALSE)
  321. {
  322. $comment_sql .= " AND status != 'c' ";
  323. }
  324. // We need to drop the leading AND from the generated string
  325. $comment_sql = substr($comment_sql, 4);
  326. $this->EE->db->where($comment_sql, NULL, FALSE);
  327. }
  328. else
  329. {
  330. $this->EE->db->where('status', 'o');
  331. }
  332. if ( ! $dynamic)
  333. {
  334. // When we are only showing comments and it is not based on an entry id or url title
  335. // in the URL, we can make the query much more efficient and save some work.
  336. if (isset($entry_ids) && count($entry_ids) > 0)
  337. {
  338. $this->EE->db->where_in('entry_id', $entry_ids);
  339. }
  340. $total_rows = $this->EE->db->count_all_results('comments');
  341. // We lose these in the counting process
  342. $this->EE->db->select('comment_date, comment_id');
  343. if ($comment_sql)
  344. {
  345. $this->EE->db->where($comment_sql, NULL, FALSE);
  346. }
  347. else
  348. {
  349. $this->EE->db->where('status', 'o');
  350. }
  351. if (isset($entry_ids) && count($entry_ids) > 0)
  352. {
  353. $this->EE->db->where_in('entry_id', $entry_ids);
  354. }
  355. $this_sort = ($random) ? 'random' : strtolower($sort);
  356. $this_page = ($current_page == '' OR ($limit > 1 AND $current_page == 1)) ? 0 : $current_page;
  357. $this->EE->db->order_by($order_by, $this_sort);
  358. $this->EE->db->limit($limit, $this_page);
  359. }
  360. else
  361. {
  362. // Force entry may result in multiple entry ids
  363. if (isset($entry_ids) && count($entry_ids) > 0)
  364. {
  365. $this->EE->db->where_in('entry_id', $entry_ids);
  366. }
  367. else
  368. {
  369. $this->EE->db->where('entry_id', $entry_id);
  370. }
  371. $this_sort = ($random) ? 'random' : strtolower($sort);
  372. $this->EE->db->order_by($order_by, $this_sort);
  373. }
  374. $query = $this->EE->db->get('comments');
  375. $result_ids = array();
  376. if ($query->num_rows() > 0)
  377. {
  378. foreach ($query->result_array() as $row)
  379. {
  380. $result_ids[] = $row['comment_id'];
  381. }
  382. }
  383. // We are done with this
  384. $this->EE->db->flush_cache();
  385. $this->EE->db->stop_cache();
  386. /** ------------------------------------
  387. /** No results? No reason to continue...
  388. /** ------------------------------------*/
  389. if (count($result_ids) == 0)
  390. {
  391. return $this->EE->TMPL->no_results();
  392. }
  393. /** ---------------------------------
  394. /** Do we need pagination?
  395. /** ---------------------------------*/
  396. // When showing only comments and no using the URL, then we already have this value
  397. if ($dynamic)
  398. {
  399. $total_rows = count($result_ids);
  400. }
  401. if (preg_match("/".LD."paginate(.*?)".RD."(.+?)".LD.'\/'."paginate".RD."/s", $this->EE->TMPL->tagdata, $match))
  402. {
  403. $paginate = TRUE;
  404. $paginate_data = $match['2'];
  405. $anchor = '';
  406. if ($match['1'] != '')
  407. {
  408. if (preg_match("/anchor.*?=[\"|\'](.+?)[\"|\']/", $match['1'], $amatch))
  409. {
  410. $anchor = '#'.$amatch['1'];
  411. }
  412. }
  413. $this->EE->TMPL->tagdata = preg_replace("/".LD."paginate.*?".RD.".+?".LD.'\/'."paginate".RD."/s", "", $this->EE->TMPL->tagdata);
  414. $current_page = ($current_page == '' OR ($limit > 1 AND $current_page == 1)) ? 0 : $current_page;
  415. if ($current_page > $total_rows)
  416. {
  417. $current_page = 0;
  418. }
  419. $t_current_page = floor(($current_page / $limit) + 1);
  420. $total_pages = intval(floor($total_rows / $limit));
  421. if ($total_rows % $limit)
  422. $total_pages++;
  423. if ($total_rows > $limit)
  424. {
  425. $this->EE->load->library('pagination');
  426. $deft_tmpl = '';
  427. if ($uristr == '')
  428. {
  429. if ($this->EE->config->item('template_group') == '')
  430. {
  431. $this->EE->db->select('group_name');
  432. $query = $this->EE->db->get_where('template_groups', array('is_site_default' => 'y'));
  433. $deft_tmpl = $query->row('group_name') .'/index';
  434. }
  435. else
  436. {
  437. $deft_tmpl = $this->EE->config->item('template_group').'/';
  438. $deft_tmpl .= ($this->EE->config->item('template') == '') ? 'index' : $this->EE->config->item('template');
  439. }
  440. }
  441. $basepath = $this->EE->functions->remove_double_slashes($this->EE->functions->create_url($uristr, FALSE).'/'.$deft_tmpl);
  442. if ($this->EE->TMPL->fetch_param('paginate_base'))
  443. {
  444. // Load the string helper
  445. $this->EE->load->helper('string');
  446. $pbase = trim_slashes($this->EE->TMPL->fetch_param('paginate_base'));
  447. $pbase = str_replace("/index", "/", $pbase);
  448. if ( ! strstr($basepath, $pbase))
  449. {
  450. $basepath = $this->EE->functions->remove_double_slashes($basepath.'/'.$pbase);
  451. }
  452. }
  453. $config['first_url'] = rtrim($basepath, '/').$anchor;
  454. $config['base_url'] = $basepath;
  455. $config['prefix'] = ( ! $dynamic) ? 'N' : 'P';
  456. $config['total_rows'] = $total_rows;
  457. $config['per_page'] = $limit;
  458. $config['cur_page'] = $current_page;
  459. $config['suffix'] = $anchor;
  460. $config['first_link'] = $this->EE->lang->line('pag_first_link');
  461. $config['last_link'] = $this->EE->lang->line('pag_last_link');
  462. // Allows $config['cur_page'] to override
  463. $config['uri_segment'] = 0;
  464. $this->EE->pagination->initialize($config);
  465. $pagination_links = $this->EE->pagination->create_links();
  466. if ((($total_pages * $limit) - $limit) > $current_page)
  467. {
  468. $page_next = $basepath.$config['prefix'].($current_page + $limit).'/';
  469. }
  470. if (($current_page - $limit ) >= 0)
  471. {
  472. $page_previous = $basepath.$config['prefix'].($current_page - $limit).'/';
  473. }
  474. }
  475. else
  476. {
  477. $current_page = '';
  478. }
  479. }
  480. // When only non-dynamic comments are shown, all results are valid as the
  481. // query is restricted with a LIMIT clause
  482. if ($dynamic)
  483. {
  484. if ($current_page == '')
  485. {
  486. $result_ids = array_slice($result_ids, 0, $limit);
  487. }
  488. else
  489. {
  490. $result_ids = array_slice($result_ids, $current_page, $limit);
  491. }
  492. }
  493. /** -----------------------------------
  494. /** Fetch Comments if necessary
  495. /** -----------------------------------*/
  496. $results = $result_ids;
  497. $mfields = array();
  498. /** ----------------------------------------
  499. /** "Search by Member" link
  500. /** ----------------------------------------*/
  501. // We use this with the {member_search_path} variable
  502. $result_path = (preg_match("/".LD."member_search_path\s*=(.*?)".RD."/s", $this->EE->TMPL->tagdata, $match)) ? $match['1'] : 'search/results';
  503. $result_path = str_replace("\"", "", $result_path);
  504. $result_path = str_replace("'", "", $result_path);
  505. $search_link = $this->EE->functions->fetch_site_index(0, 0).QUERY_MARKER.'ACT='.$this->EE->functions->fetch_action_id('Search', 'do_search').'&amp;result_path='.$result_path.'&amp;mbr=';
  506. $this->EE->db->select('comments.comment_id, comments.entry_id, comments.channel_id, comments.author_id, comments.name, comments.email, comments.url, comments.location AS c_location, comments.ip_address, comments.comment_date, comments.edit_date, comments.comment, comments.site_id AS comment_site_id,
  507. members.username, members.group_id, members.location, members.occupation, members.interests, members.aol_im, members.yahoo_im, members.msn_im, members.icq, members.group_id, members.member_id, members.signature, members.sig_img_filename, members.sig_img_width, members.sig_img_height, members.avatar_filename, members.avatar_width, members.avatar_height, members.photo_filename, members.photo_width, members.photo_height,
  508. member_data.*,
  509. channel_titles.title, channel_titles.url_title, channel_titles.author_id AS entry_author_id,
  510. channels.comment_text_formatting, channels.comment_html_formatting, channels.comment_allow_img_urls, channels.comment_auto_link_urls, channels.channel_url, channels.comment_url, channels.channel_title'
  511. );
  512. $this->EE->db->join('channels', 'comments.channel_id = channels.channel_id', 'left');
  513. $this->EE->db->join('channel_titles', 'comments.entry_id = channel_titles.entry_id', 'left');
  514. $this->EE->db->join('members', 'members.member_id = comments.author_id', 'left');
  515. $this->EE->db->join('member_data', 'member_data.member_id = members.member_id', 'left');
  516. $this->EE->db->where_in('comments.comment_id', $result_ids);
  517. $this->EE->db->order_by($order_by, $this_sort);
  518. $query = $this->EE->db->get('comments');
  519. $total_results = $query->num_rows();
  520. if ($query->num_rows() > 0)
  521. {
  522. $i = 0;
  523. foreach ($query->result_array() as $row)
  524. {
  525. $results[$row['comment_id']] = $query->result_array[$i];
  526. $i++;
  527. }
  528. // Potentially a lot of information
  529. $query->free_result();
  530. }
  531. /** ----------------------------------------
  532. /** Fetch custom member field IDs
  533. /** ----------------------------------------*/
  534. $this->EE->db->select('m_field_id, m_field_name');
  535. $query = $this->EE->db->get('member_fields');
  536. if ($query->num_rows() > 0)
  537. {
  538. foreach ($query->result_array() as $row)
  539. {
  540. $mfields[$row['m_field_name']] = $row['m_field_id'];
  541. }
  542. }
  543. /** ----------------------------------------
  544. /** Instantiate Typography class
  545. /** ----------------------------------------*/
  546. $config = ($this->EE->config->item('comment_word_censoring') == 'y') ? array('word_censor' => TRUE) : array();
  547. $this->EE->load->library('typography');
  548. $this->EE->typography->initialize($config);
  549. $this->EE->typography->parse_images = FALSE;
  550. $this->EE->typography->allow_headings = FALSE;
  551. /** ----------------------------------------
  552. /** Fetch all the date-related variables
  553. /** ----------------------------------------*/
  554. $gmt_comment_date = array();
  555. $comment_date = array();
  556. $edit_date = array();
  557. // We do this here to avoid processing cycles in the foreach loop
  558. $date_vars = array('gmt_comment_date', 'comment_date', 'edit_date');
  559. foreach ($date_vars as $val)
  560. {
  561. if (preg_match_all("/".LD.$val."\s+format=[\"'](.*?)[\"']".RD."/s", $this->EE->TMPL->tagdata, $matches))
  562. {
  563. for ($j = 0; $j < count($matches['0']); $j++)
  564. {
  565. $matches['0'][$j] = str_replace(LD, '', $matches['0'][$j]);
  566. $matches['0'][$j] = str_replace(RD, '', $matches['0'][$j]);
  567. switch ($val)
  568. {
  569. case 'comment_date' : $comment_date[$matches['0'][$j]] = $this->EE->localize->fetch_date_params($matches['1'][$j]);
  570. break;
  571. case 'gmt_comment_date' : $gmt_comment_date[$matches['0'][$j]] = $this->EE->localize->fetch_date_params($matches['1'][$j]);
  572. break;
  573. case 'edit_date' : $edit_date[$matches['0'][$j]] = $this->EE->localize->fetch_date_params($matches['1'][$j]);
  574. break;
  575. }
  576. }
  577. }
  578. }
  579. /** ----------------------------------------
  580. /** Protected Variables for Cleanup Routine
  581. /** ----------------------------------------*/
  582. // Since comments do not necessarily require registration, and since
  583. // you are allowed to put member variables in comments, we need to kill
  584. // left-over unparsed junk. The $member_vars array is all of those
  585. // member related variables that should be removed.
  586. $member_vars = array('location', 'occupation', 'interests', 'aol_im', 'yahoo_im', 'msn_im', 'icq',
  587. 'signature', 'sig_img_filename', 'sig_img_width', 'sig_img_height',
  588. 'avatar_filename', 'avatar_width', 'avatar_height',
  589. 'photo_filename', 'photo_width', 'photo_height');
  590. $member_cond_vars = array();
  591. foreach($member_vars as $var)
  592. {
  593. $member_cond_vars[$var] = '';
  594. }
  595. /** ----------------------------------------
  596. /** Start the processing loop
  597. /** ----------------------------------------*/
  598. $item_count = 0;
  599. $relative_count = 0;
  600. $absolute_count = ($current_page == '') ? 0 : $current_page;
  601. foreach ($results as $id => $row)
  602. {
  603. if ( ! is_array($row))
  604. continue;
  605. $relative_count++;
  606. $absolute_count++;
  607. $row['count'] = $relative_count;
  608. $row['absolute_count'] = $absolute_count;
  609. $row['total_comments'] = $total_rows;
  610. $row['total_results'] = $total_results;
  611. // This lets the {if location} variable work
  612. if (isset($row['author_id']))
  613. {
  614. if ($row['author_id'] == 0)
  615. $row['location'] = $row['c_location'];
  616. }
  617. $tagdata = $this->EE->TMPL->tagdata;
  618. // -------------------------------------------
  619. // 'comment_entries_tagdata' hook.
  620. // - Modify and play with the tagdata before everyone else
  621. //
  622. if ($this->EE->extensions->active_hook('comment_entries_tagdata') === TRUE)
  623. {
  624. $tagdata = $this->EE->extensions->call('comment_entries_tagdata', $tagdata, $row);
  625. if ($this->EE->extensions->end_script === TRUE) return $tagdata;
  626. }
  627. //
  628. // -------------------------------------------
  629. /** ----------------------------------------
  630. /** Conditionals
  631. /** ----------------------------------------*/
  632. $cond = array_merge($member_cond_vars, $row);
  633. $cond['comments'] = (substr($id, 0, 1) == 't') ? 'FALSE' : 'TRUE';
  634. $cond['logged_in'] = ($this->EE->session->userdata('member_id') == 0) ? 'FALSE' : 'TRUE';
  635. $cond['logged_out'] = ($this->EE->session->userdata('member_id') != 0) ? 'FALSE' : 'TRUE';
  636. $cond['allow_comments'] = (isset($row['allow_comments']) AND $row['allow_comments'] == 'n') ? 'FALSE' : 'TRUE';
  637. $cond['signature_image'] = ( ! isset($row['sig_img_filename']) OR $row['sig_img_filename'] == '' OR $this->EE->config->item('enable_signatures') == 'n' OR $this->EE->session->userdata('display_signatures') == 'n') ? 'FALSE' : 'TRUE';
  638. $cond['avatar'] = ( ! isset($row['avatar_filename']) OR $row['avatar_filename'] == '' OR $this->EE->config->item('enable_avatars') == 'n' OR $this->EE->session->userdata('display_avatars') == 'n') ? 'FALSE' : 'TRUE';
  639. $cond['photo'] = ( ! isset($row['photo_filename']) OR $row['photo_filename'] == '' OR $this->EE->config->item('enable_photos') == 'n' OR $this->EE->session->userdata('display_photos') == 'n') ? 'FALSE' : 'TRUE';
  640. $cond['is_ignored'] = ( ! isset($row['member_id']) OR ! in_array($row['member_id'], $this->EE->session->userdata['ignore_list'])) ? 'FALSE' : 'TRUE';
  641. $cond['editable'] = FALSE;
  642. $cond['can_moderate_comment'] = FALSE;
  643. if ($this->EE->session->userdata['group_id'] == 1 OR
  644. $this->EE->session->userdata['can_edit_all_comments'] == 'y' OR
  645. ($this->EE->session->userdata['can_edit_own_comments'] == 'y' && $row['entry_author_id'] == $this->EE->session->userdata['member_id']))
  646. {
  647. $cond['editable'] = TRUE;
  648. $cond['can_moderate_comment'] = TRUE;
  649. }
  650. elseif ($this->EE->session->userdata['member_id'] != '0' && $author_id == $this->EE->session->userdata['member_id'])
  651. {
  652. $cond['editable'] = TRUE;
  653. }
  654. if ( isset($mfields) && is_array($mfields) && count($mfields) > 0)
  655. {
  656. foreach($mfields as $key => $value)
  657. {
  658. if (isset($row['m_field_id_'.$value]))
  659. $cond[$key] = $row['m_field_id_'.$value];
  660. }
  661. }
  662. $tagdata = $this->EE->functions->prep_conditionals($tagdata, $cond);
  663. /** ----------------------------------------
  664. /** Parse "single" variables
  665. /** ----------------------------------------*/
  666. foreach ($this->EE->TMPL->var_single as $key => $val)
  667. {
  668. /** ----------------------------------------
  669. /** parse {switch} variable
  670. /** ----------------------------------------*/
  671. if (strncmp($key, 'switch', 6) == 0)
  672. {
  673. $sparam = $this->EE->functions->assign_parameters($key);
  674. $sw = '';
  675. if (isset($sparam['switch']))
  676. {
  677. $sopt = @explode("|", $sparam['switch']);
  678. $sw = $sopt[($relative_count + count($sopt) - 1) % count($sopt)];
  679. }
  680. $tagdata = $this->EE->TMPL->swap_var_single($key, $sw, $tagdata);
  681. }
  682. /** ----------------------------------------
  683. /** parse permalink
  684. /** ----------------------------------------*/
  685. if ($key == 'permalink' && isset($row['comment_id']))
  686. {
  687. $tagdata = $this->EE->TMPL->swap_var_single(
  688. $key,
  689. $this->EE->functions->create_url($uristr.'#'.$row['comment_id'], FALSE),
  690. $tagdata
  691. );
  692. }
  693. /** ----------------------------------------
  694. /** parse comment_path
  695. /** ----------------------------------------*/
  696. if (strncmp($key, 'comment_path', 12) == 0 OR strncmp($key, 'entry_id_path', 13) == 0)
  697. {
  698. $tagdata = $this->EE->TMPL->swap_var_single(
  699. $key,
  700. $this->EE->functions->create_url($this->EE->functions->extract_path($key).'/'.$row['entry_id']),
  701. $tagdata
  702. );
  703. }
  704. /** ----------------------------------------
  705. /** parse title permalink
  706. /** ----------------------------------------*/
  707. if (strncmp($key, 'title_permalink', 15) == 0 OR strncmp($key, 'url_title_path', 14) == 0)
  708. {
  709. $path = ($this->EE->functions->extract_path($key) != '' AND $this->EE->functions->extract_path($key) != 'SITE_INDEX') ? $this->EE->functions->extract_path($key).'/'.$row['url_title'] : $row['url_title'];
  710. $tagdata = $this->EE->TMPL->swap_var_single(
  711. $key,
  712. $this->EE->functions->create_url($path, FALSE),
  713. $tagdata
  714. );
  715. }
  716. /** ----------------------------------------
  717. /** parse comment date
  718. /** ----------------------------------------*/
  719. if (isset($comment_date[$key]) && isset($row['comment_date']))
  720. {
  721. foreach ($comment_date[$key] as $dvar)
  722. {
  723. $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $row['comment_date'], TRUE), $val);
  724. }
  725. $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata);
  726. }
  727. /** ----------------------------------------
  728. /** parse GMT comment date
  729. /** ----------------------------------------*/
  730. if (isset($gmt_comment_date[$key]) && isset($row['comment_date']))
  731. {
  732. foreach ($gmt_comment_date[$key] as $dvar)
  733. {
  734. $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $row['comment_date'], FALSE), $val);
  735. }
  736. $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata);
  737. }
  738. /** ----------------------------------------
  739. /** parse "last edit" date
  740. /** ----------------------------------------*/
  741. if (isset($edit_date[$key]))
  742. {
  743. if (isset($row['edit_date']))
  744. {
  745. foreach ($edit_date[$key] as $dvar)
  746. $val = str_replace($dvar, $this->EE->localize->convert_timestamp($dvar, $this->EE->localize->timestamp_to_gmt($row['edit_date']), TRUE), $val);
  747. $tagdata = $this->EE->TMPL->swap_var_single($key, $val, $tagdata);
  748. }
  749. }
  750. /** ----------------------------------------
  751. /** {member_search_path}
  752. /** ----------------------------------------*/
  753. if (strncmp($key, 'member_search_path', 18) == 0)
  754. {
  755. $tagdata = $this->EE->TMPL->swap_var_single($key, $search_link.$row['author_id'], $tagdata);
  756. }
  757. // Prep the URL
  758. if (isset($row['url']))
  759. {
  760. $this->EE->load->helper('url');
  761. $row['url'] = prep_url($row['url']);
  762. }
  763. /** ----------------------------------------
  764. /** {username}
  765. /** ----------------------------------------*/
  766. if ($key == "username")
  767. {
  768. $tagdata = $this->EE->TMPL->swap_var_single($val, (isset($row['username'])) ? $row['username'] : '', $tagdata);
  769. }
  770. /** ----------------------------------------
  771. /** {author}
  772. /** ----------------------------------------*/
  773. if ($key == "author")
  774. {
  775. $tagdata = $this->EE->TMPL->swap_var_single($val, (isset($row['name'])) ? $row['name'] : '', $tagdata);
  776. }
  777. /** ----------------------------------------
  778. /** {url_or_email} - Uses Raw Email Address, Like Channel Module
  779. /** ----------------------------------------*/
  780. if ($key == "url_or_email" AND isset($row['url']))
  781. {
  782. $tagdata = $this->EE->TMPL->swap_var_single($val, ($row['url'] != '') ? $row['url'] : $row['email'], $tagdata);
  783. }
  784. /** ----------------------------------------
  785. /** {url_as_author}
  786. /** ----------------------------------------*/
  787. if ($key == "url_as_author" AND isset($row['url']))
  788. {
  789. if ($row['url'] != '')
  790. {
  791. $tagdata = $this->EE->TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['name']."</a>", $tagdata);
  792. }
  793. else
  794. {
  795. $tagdata = $this->EE->TMPL->swap_var_single($val, $row['name'], $tagdata);
  796. }
  797. }
  798. /** ----------------------------------------
  799. /** {url_or_email_as_author}
  800. /** ----------------------------------------*/
  801. if ($key == "url_or_email_as_author" AND isset($row['url']))
  802. {
  803. if ($row['url'] != '')
  804. {
  805. $tagdata = $this->EE->TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['name']."</a>", $tagdata);
  806. }
  807. else
  808. {
  809. if ($row['email'] != '')
  810. {
  811. $tagdata = $this->EE->TMPL->swap_var_single($val, $this->EE->typography->encode_email($row['email'], $row['name']), $tagdata);
  812. }
  813. else
  814. {
  815. $tagdata = $this->EE->TMPL->swap_var_single($val, $row['name'], $tagdata);
  816. }
  817. }
  818. }
  819. /** ----------------------------------------
  820. /** {url_or_email_as_link}
  821. /** ----------------------------------------*/
  822. if ($key == "url_or_email_as_link" AND isset($row['url']))
  823. {
  824. if ($row['url'] != '')
  825. {
  826. $tagdata = $this->EE->TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['url']."</a>", $tagdata);
  827. }
  828. else
  829. {
  830. if ($row['email'] != '')
  831. {
  832. $tagdata = $this->EE->TMPL->swap_var_single($val, $this->EE->typography->encode_email($row['email']), $tagdata);
  833. }
  834. else
  835. {
  836. $tagdata = $this->EE->TMPL->swap_var_single($val, $row['name'], $tagdata);
  837. }
  838. }
  839. }
  840. /** ----------------------------------------
  841. /** {comment_auto_path}
  842. /** ----------------------------------------*/
  843. if ($key == "comment_auto_path")
  844. {
  845. $path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  846. $tagdata = $this->EE->TMPL->swap_var_single($key, $path, $tagdata);
  847. }
  848. /** ----------------------------------------
  849. /** {comment_url_title_auto_path}
  850. /** ----------------------------------------*/
  851. if ($key == "comment_url_title_auto_path")
  852. {
  853. $path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  854. $tagdata = $this->EE->TMPL->swap_var_single(
  855. $key,
  856. $path.'/'.$row['url_title'],
  857. $tagdata
  858. );
  859. }
  860. /** ----------------------------------------
  861. /** {comment_entry_id_auto_path}
  862. /** ----------------------------------------*/
  863. if ($key == "comment_entry_id_auto_path")
  864. {
  865. $path = ($row['comment_url'] == '') ? $row['channel_url'] : $row['comment_url'];
  866. $tagdata = $this->EE->TMPL->swap_var_single(
  867. $key,
  868. $path.'/'.$row['entry_id'],
  869. $tagdata
  870. );
  871. }
  872. /** ----------------------------------------
  873. /** parse comment_stripped field
  874. /** ----------------------------------------*/
  875. if ($key == "comment_stripped" AND isset($row['comment']))
  876. {
  877. $tagdata = $this->EE->TMPL->swap_var_single(
  878. $key,
  879. $this->EE->functions->encode_ee_tags($row['comment'], TRUE),
  880. $tagdata
  881. );
  882. }
  883. /** ----------------------------------------
  884. /** parse comment field
  885. /** ----------------------------------------*/
  886. if ($key == 'comment' AND isset($row['comment']))
  887. {
  888. // -------------------------------------------
  889. // 'comment_entries_comment_format' hook.
  890. // - Play with the tagdata contents of the comment entries
  891. //
  892. if ($this->EE->extensions->active_hook('comment_entries_comment_format') === TRUE)
  893. {
  894. $comment = $this->EE->extensions->call('comment_entries_comment_format', $row);
  895. if ($this->EE->extensions->end_script === TRUE) return;
  896. }
  897. else
  898. {
  899. $comment = $this->EE->typography->parse_type( $row['comment'],
  900. array(
  901. 'text_format' => $row['comment_text_formatting'],
  902. 'html_format' => $row['comment_html_formatting'],
  903. 'auto_links' => $row['comment_auto_link_urls'],
  904. 'allow_img_url' => $row['comment_allow_img_urls']
  905. )
  906. );
  907. }
  908. $tagdata = $this->EE->TMPL->swap_var_single($key, $comment, $tagdata);
  909. }
  910. // {location}
  911. if ($key == 'location' AND (isset($row['location']) OR isset($row['c_location'])))
  912. {
  913. $tagdata = $this->EE->TMPL->swap_var_single($key, (empty($row['location'])) ? $row['c_location'] : $row['location'], $tagdata);
  914. }
  915. /** ----------------------------------------
  916. /** {signature}
  917. /** ----------------------------------------*/
  918. if ($key == "signature")
  919. {
  920. if ($this->EE->session->userdata('display_signatures') == 'n' OR ! isset($row['signature']) OR $row['signature'] == '' OR $this->EE->session->userdata('display_signatures') == 'n')
  921. {
  922. $tagdata = $this->EE->TMPL->swap_var_single($key, '', $tagdata);
  923. }
  924. else
  925. {
  926. $tagdata = $this->EE->TMPL->swap_var_single($key,
  927. $this->EE->typography->parse_type($row['signature'], array(
  928. 'text_format' => 'xhtml',
  929. 'html_format' => 'safe',
  930. 'auto_links' => 'y',
  931. 'allow_img_url' => $this->EE->config->item('sig_allow_img_hotlink')
  932. )
  933. ), $tagdata);
  934. }
  935. }
  936. if ($key == "signature_image_url")
  937. {
  938. if ($this->EE->session->userdata('display_signatures') == 'n' OR $row['sig_img_filename'] == '' OR $this->EE->session->userdata('display_signatures') == 'n')
  939. {
  940. $tagdata = $this->EE->TMPL->swap_var_single($key, '', $tagdata);
  941. $tagdata = $this->EE->TMPL->swap_var_single('signature_image_width', '', $tagdata);
  942. $tagdata = $this->EE->TMPL->swap_var_single('signature_image_height', '', $tagdata);
  943. }
  944. else
  945. {
  946. $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->config->slash_item('sig_img_url').$row['sig_img_filename'], $tagdata);
  947. $tagdata = $this->EE->TMPL->swap_var_single('signature_image_width', $row['sig_img_width'], $tagdata);
  948. $tagdata = $this->EE->TMPL->swap_var_single('signature_image_height', $row['sig_img_height'], $tagdata);
  949. }
  950. }
  951. if ($key == "avatar_url")
  952. {
  953. if ( ! isset($row['avatar_filename']))
  954. $row['avatar_filename'] = '';
  955. if ($this->EE->session->userdata('display_avatars') == 'n' OR $row['avatar_filename'] == '' OR $this->EE->session->userdata('display_avatars') == 'n')
  956. {
  957. $tagdata = $this->EE->TMPL->swap_var_single($key, '', $tagdata);
  958. $tagdata = $this->EE->TMPL->swap_var_single('avatar_image_width', '', $tagdata);
  959. $tagdata = $this->EE->TMPL->swap_var_single('avatar_image_height', '', $tagdata);
  960. }
  961. else
  962. {
  963. $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->config->slash_item('avatar_url').$row['avatar_filename'], $tagdata);
  964. $tagdata = $this->EE->TMPL->swap_var_single('avatar_image_width', $row['avatar_width'], $tagdata);
  965. $tagdata = $this->EE->TMPL->swap_var_single('avatar_image_height', $row['avatar_height'], $tagdata);
  966. }
  967. }
  968. if ($key == "photo_url")
  969. {
  970. if ( ! isset($row['photo_filename']))
  971. $row['photo_filename'] = '';
  972. if ($this->EE->session->userdata('display_photos') == 'n' OR $row['photo_filename'] == '' OR $this->EE->session->userdata('display_photos') == 'n')
  973. {
  974. $tagdata = $this->EE->TMPL->swap_var_single($key, '', $tagdata);
  975. $tagdata = $this->EE->TMPL->swap_var_single('photo_image_width', '', $tagdata);
  976. $tagdata = $this->EE->TMPL->swap_var_single('photo_image_height', '', $tagdata);
  977. }
  978. else
  979. {
  980. $tagdata = $this->EE->TMPL->swap_var_single($key, $this->EE->config->slash_item('photo_url').$row['photo_filename'], $tagdata);
  981. $tagdata = $this->EE->TMPL->swap_var_single('photo_image_width', $row['photo_width'], $tagdata);
  982. $tagdata = $this->EE->TMPL->swap_var_single('photo_image_height', $row['photo_height'], $tagdata);
  983. }
  984. }
  985. /** ----------------------------------------
  986. /** parse basic fields
  987. /** ----------------------------------------*/
  988. if (isset($row[$val]) && $val != 'member_id')
  989. {
  990. $tagdata = $this->EE->TMPL->swap_var_single($val, $row[$val], $tagdata);
  991. }
  992. /** ----------------------------------------
  993. /** parse custom member fields
  994. /** ----------------------------------------*/
  995. if ( isset($mfields[$val]))
  996. {
  997. // Since comments do not necessarily require registration, and since
  998. // you are allowed to put custom member variables in comments,
  999. // we delete them if no such row exists
  1000. $return_val = (isset($row['m_field_id_'.$mfields[$val]])) ? $row['m_field_id_'.$mfields[$val]] : '';
  1001. $tagdata = $this->EE->TMPL->swap_var_single(
  1002. $val,
  1003. $return_val,
  1004. $tagdata
  1005. );
  1006. }
  1007. /** ----------------------------------------
  1008. /** Clean up left over member variables
  1009. /** ----------------------------------------*/
  1010. if (in_array($val, $member_vars))
  1011. {
  1012. $tagdata = str_replace(LD.$val.RD, '', $tagdata);
  1013. }
  1014. }
  1015. if ($this->show_anchor == TRUE)
  1016. {
  1017. $return .= "<a name=\"".$item_count."\"></a>\n";
  1018. }
  1019. $return .= $tagdata;
  1020. $item_count++;
  1021. }
  1022. /** ----------------------------------------
  1023. /** Parse path variable
  1024. /** ----------------------------------------*/
  1025. $return = preg_replace_callback("/".LD."\s*path=(.+?)".RD."/", array(&$this->EE->functions, 'create_url'), $return);
  1026. /** ----------------------------------------
  1027. /** Add pagination to result
  1028. /** ----------------------------------------*/
  1029. if ($paginate == TRUE)
  1030. {
  1031. $paginate_data = str_replace(LD.'current_page'.RD, $t_current_page, $paginate_data);
  1032. $paginate_data = str_replace(LD.'total_pages'.RD, $total_pages, $paginate_data);
  1033. $paginate_data = str_replace(LD.'pagination_links'.RD, $pagination_links, $paginate_data);
  1034. if (preg_match("/".LD."if previous_page".RD."(.+?)".LD.'\/'."if".RD."/s", $paginate_data, $match))
  1035. {
  1036. if ($page_previous == '')
  1037. {
  1038. $paginate_data = preg_replace("/".LD."if previous_page".RD.".+?".LD.'\/'."if".RD."/s", '', $paginate_data);
  1039. }
  1040. else
  1041. {
  1042. $match['1'] = str_replace(array(LD.'path'.RD, LD.'auto_path'.RD), $page_previous, $match['1']);
  1043. $paginate_data = str_replace($match['0'], $match['1'], $paginate_data);
  1044. }
  1045. }
  1046. if (preg_match("/".LD."if next_page".RD."(.+?)".LD.'\/'."if".RD."/s", $paginate_data, $match))
  1047. {
  1048. if ($page_next == '')
  1049. {
  1050. $paginate_data = preg_replace("/".LD."if next_page".RD.".+?".LD.'\/'."if".RD."/s", '', $paginate_data);
  1051. }
  1052. else
  1053. {
  1054. $match['1'] = str_replace(array(LD.'path'.RD, LD.'auto_path'.RD), $page_next, $match['1']);
  1055. $paginate_data = str_replace($match['0'], $match['1'], $paginate_data);
  1056. }
  1057. }
  1058. $position = ( ! $this->EE->TMPL->fetch_param('paginate')) ? '' : $this->EE->TMPL->fetch_param('paginate');
  1059. switch ($position)
  1060. {
  1061. case "top" : $return = $paginate_data.$return;
  1062. break;
  1063. case "both" : $return = $paginate_data.$return.$paginate_data;
  1064. break;
  1065. default : $return .= $paginate_data;
  1066. break;
  1067. }
  1068. }
  1069. return $return;
  1070. }
  1071. // --------------------------------------------------------------------
  1072. /**
  1073. * Comment Submission Form
  1074. *
  1075. * @access public
  1076. * @return string
  1077. */
  1078. function form($return_form = FALSE, $captcha = '')
  1079. {
  1080. $qstring = $this->EE->uri->query_string;
  1081. $entry_where = array();
  1082. $halt_processing = FALSE;
  1083. /** --------------------------------------
  1084. /** Remove page number
  1085. /** --------------------------------------*/
  1086. if (preg_match("#(^|/)P(\d+)(/|$)#", $qstring, $match))
  1087. {
  1088. $qstring = trim($this->EE->functions->remove_double_slashes(str_replace($match['0'], '/', $qstring)), '/');
  1089. }
  1090. // Figure out the right entry ID
  1091. // Order of precedence: POST, entry_id=, url_title=, $qstring
  1092. if (isset($_POST['entry_id']))
  1093. {
  1094. $entry_where = array('entry_id' => $_POST['entry_id']);
  1095. }
  1096. elseif ($entry_id = $this->EE->TMPL->fetch_param('entry_id'))
  1097. {
  1098. $entry_where = array('entry_id' => $entry_id);
  1099. }
  1100. elseif ($url_title = $this->EE->TMPL->fetch_param('url_title'))
  1101. {
  1102. $entry_where = array('url_title' => $url_title);
  1103. }
  1104. else
  1105. {
  1106. // If there is a slash in the entry ID we'll kill everything after it.
  1107. $entry_id = trim($qstring);
  1108. $entry_id = preg_replace("#/.+#", "", $entry_id);
  1109. if ( ! is_numeric($entry_id))
  1110. {
  1111. $entry_where = array('url_title' => $entry_id);
  1112. }
  1113. else
  1114. {
  1115. $entry_where = array('entry_id' => $entry_id);
  1116. }
  1117. }
  1118. /** ----------------------------------------
  1119. /** Are comments allowed?
  1120. /** ----------------------------------------*/
  1121. if ($channel = $this->EE->TMPL->fetch_param('channel'))
  1122. {
  1123. $this->EE->db->select('channel_id');
  1124. $this->EE->functions->ar_andor_string($channel, 'channel_name');
  1125. $this->EE->db->where_in('site_id', $this->EE->TMPL->site_ids);
  1126. $query = $this->EE->db->get('channels');
  1127. if ($query->num_rows() == 0)
  1128. {
  1129. return FALSE;
  1130. }
  1131. elseif ($query->num_rows() == 1)
  1132. {
  1133. $this->EE->db->where('channel_titles.channel_id', $query->row('channel_id'));
  1134. }
  1135. else
  1136. {
  1137. $ids = array();
  1138. foreach ($query->result_array() as $row)
  1139. {
  1140. $ids[] = $row['channel_id'];
  1141. }
  1142. $this->EE->db->where_in('channel_titles.channel_id', $ids);
  1143. }
  1144. }
  1145. // The where clauses above will affect this query - it's below the conditional
  1146. // because AR cannot keep track of two queries at once
  1147. $this->EE->db->select('channel_titles.entry_id, channel_titles.entry_date, channel_titles.comment_expiration_date, channel_titles.allow_comments, channels.comment_system_enabled, channels.comment_use_captcha, channels.comment_expiration');
  1148. $this->EE->db->from(array('channel_titles', 'channels'));
  1149. $this->EE->db->where_in('channel_titles.site_id', $this->EE->TMPL->site_ids);
  1150. $this->EE->db->where('channel_titles.channel_id = '.$this->EE->db->dbprefix('channels').'.channel_id');
  1151. if ($e_status = $this->EE->TMPL->fetch_param('entry_status'))
  1152. {
  1153. $e_status = str_replace('Open', 'open', $e_status);
  1154. $e_status = str_replace('Closed', 'closed', $e_status);
  1155. $sql = $this->EE->functions->sql_andor_string($e_status, 'status');
  1156. if (stristr($sql, "'closed'") === FALSE)
  1157. {
  1158. $sql .= " AND status != 'closed' ";
  1159. }
  1160. // We need to drop the leading AND from the generated string
  1161. $sql = substr($sql, 4);
  1162. $this->EE->db->where($sql, NULL, FALSE);
  1163. }
  1164. else
  1165. {
  1166. $this->EE->db->where('status !=', 'closed');
  1167. }
  1168. $this->EE->db->where($entry_where);
  1169. $query = $this->EE->db->get();
  1170. if ($query->num_rows() == 0)
  1171. {
  1172. return FALSE;
  1173. }
  1174. if ($query->row('allow_comments') == 'n' OR $query->row('comment_system_enabled') == 'n')
  1175. {
  1176. $halt_processing = 'disabled';
  1177. }
  1178. /** ----------------------------------------
  1179. /** Smart Notifications? Mark comments as read.
  1180. /** ----------------------------------------*/
  1181. if ($this->EE->session->userdata('smart_notifications') == 'y')
  1182. {
  1183. $this->EE->load->library('subscription');
  1184. $this->EE->subscription->init('comment', array('entry_id' => $query->row('entry_id')), TRUE);
  1185. $this->EE->subscription->mark_as_read();
  1186. }
  1187. /** ----------------------------------------
  1188. /** Return the "no cache" version of the form
  1189. /** ----------------------------------------*/
  1190. if ($return_form == FALSE)
  1191. {
  1192. if ($query->row('comment_use_captcha') == 'n')
  1193. {
  1194. $this->EE->TMPL->tagdata = str_replace(LD.'captcha'.RD, '', $this->EE->TMPL->tagdata);
  1195. }
  1196. $nc = '';
  1197. if (is_array($this->EE->TMPL->tagparams) AND count($this->EE->TMPL->tagparams) > 0)
  1198. {
  1199. foreach ($this->EE->TMPL->tagparams as $key => $val)
  1200. {
  1201. switch ($key)
  1202. {
  1203. case 'form_class':
  1204. $nc .= 'class="'.$val.'" ';
  1205. break;
  1206. case 'form_id':
  1207. $nc .= 'id="'.$val.'" ';
  1208. break;
  1209. default:
  1210. $nc .= ' '.$key.'="'.$val.'" ';
  1211. }
  1212. }
  1213. }
  1214. return '{NOCACHE_COMMENT_FORM="'.$nc.'"}'.$this->EE->TMPL->tagdata.'{/NOCACHE_FORM}';
  1215. }
  1216. /** ----------------------------------------
  1217. /** Has commenting expired?
  1218. /** ----------------------------------------*/
  1219. $mode = ( ! isset($this->comment_expiration_mode)) ? 0 : $this->comment_expiration_mode;
  1220. // First check whether expiration is overriden
  1221. if ($this->EE->config->item('comment_moderation_override') !== 'y')
  1222. {
  1223. if ($mode == 0)
  1224. {
  1225. if ($query->row('comment_expiration_date') > 0)
  1226. {
  1227. if ($this->EE->localize->now > $query->row('comment_expiration_date') )
  1228. {
  1229. $halt_processing = 'expired';
  1230. }
  1231. }
  1232. }
  1233. else
  1234. {
  1235. if ($query->row('comment_expiration') > 0)
  1236. {
  1237. $days = $query->row('entry_date') + ($query->row('comment_expiration') * 86400);
  1238. if ($this->EE->localize->now > $days)
  1239. {
  1240. $halt_processing = 'expired';
  1241. }
  1242. }
  1243. }
  1244. }
  1245. $tagdata = $this->EE->TMPL->tagdata;
  1246. if ($halt_processing != FALSE)
  1247. {
  1248. foreach ($this->EE->TMPL->var_cond as $key => $val)
  1249. {
  1250. if ($halt_processing == 'expired')
  1251. {
  1252. if (isset($val['3']) && $val['3'] == 'comments_expired')
  1253. {
  1254. return $val['2'];
  1255. }
  1256. }
  1257. elseif ($halt_processing == 'disabled')
  1258. {
  1259. if (isset($val['3']) && $val['3'] == 'comments_disabled')
  1260. {
  1261. return $val['2'];
  1262. }
  1263. }
  1264. }
  1265. // If there is no conditional- just return the message
  1266. $this->EE->lang->loadfile('comment');
  1267. return $this->EE->lang->line('cmt_commenting_has_expired');
  1268. }
  1269. // -------------------------------------------
  1270. // 'comment_form_tagdata' hook.
  1271. // - Modify, add, etc. something to the comment form
  1272. //
  1273. if ($this->EE->extensions->active_hook('comment_form_tagdata') === TRUE)
  1274. {
  1275. $tagdata = $this->EE->extensions->call('comment_form_tagdata', $tagdata);
  1276. if ($this->EE->extensions->end_script === TRUE) return;
  1277. }
  1278. //
  1279. // -------------------------------------------
  1280. /** ----------------------------------------
  1281. /** Conditionals
  1282. /** ----------------------------------------*/
  1283. $cond = array();
  1284. $cond['logged_in'] = ($this->EE->session->userdata('member_id') == 0) ? 'FALSE' : 'TRUE';
  1285. $cond['logged_out'] = ($this->EE->session->userdata('member_id') != 0) ? 'FALSE' : 'TRUE';
  1286. if ($query->row('comment_use_captcha') == 'n')
  1287. {
  1288. $cond['captcha'] = 'FALSE';
  1289. }
  1290. elseif ($query->row('comment_use_captcha') == 'y')
  1291. {
  1292. $cond['captcha'] = ($this->EE->config->item('captcha_require_members') == 'y' OR
  1293. ($this->EE->config->item('captcha_require_members') == 'n' AND $this->EE->session->userdata('member_id') == 0)) ? 'TRUE' : 'FALSE';
  1294. }
  1295. $tagdata = $this->EE->functions->prep_conditionals($tagdata, $cond);
  1296. /** ----------------------------------------
  1297. /** Single Variables
  1298. /** ----------------------------------------*/
  1299. // Load the form helper
  1300. $this->EE->load->helper('form');
  1301. foreach ($this->EE->TMPL->var_single as $key => $val)
  1302. {
  1303. /** ----------------------------------------
  1304. /** parse {nam…

Large files files are truncated, but you can click here to view the full file