PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/system/modules/comment/mod.comment.php

https://github.com/danboy/Croissierd
PHP | 2948 lines | 1876 code | 562 blank | 510 comment | 484 complexity | 080b9d2eaf766c3e1cf59c21f039ada7 MD5 | raw file

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

  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: mod.comment.php
  15. -----------------------------------------------------
  16. Purpose: Commenting class
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  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 Weblog 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. function Comment()
  38. {
  39. global $REGX;
  40. $fields = array('name', 'email', 'url', 'location', 'comment');
  41. foreach ($fields as $val)
  42. {
  43. if (isset($_POST[$val] ))
  44. {
  45. $_POST[$val] = $REGX->encode_ee_tags($_POST[$val], TRUE);
  46. if ($val == 'comment')
  47. {
  48. $_POST[$val] = $REGX->xss_clean($_POST[$val]);
  49. }
  50. }
  51. }
  52. }
  53. /* END */
  54. /** ----------------------------------------
  55. /** Comment Entries
  56. /** ----------------------------------------*/
  57. function entries()
  58. {
  59. global $IN, $DB, $TMPL, $LOC, $PREFS, $REGX, $FNS, $SESS, $EXT;
  60. // Base variables
  61. $return = '';
  62. $current_page = '';
  63. $qstring = $IN->QSTR;
  64. $uristr = $IN->URI;
  65. $switch = array();
  66. $search_link = '';
  67. // Pagination variables
  68. $paginate = FALSE;
  69. $paginate_data = '';
  70. $pagination_links = '';
  71. $page_next = '';
  72. $page_previous = '';
  73. $current_page = 0;
  74. $t_current_page = '';
  75. $total_pages = 1;
  76. if ($TMPL->fetch_param('dynamic') == 'off')
  77. {
  78. $dynamic = FALSE;
  79. }
  80. else
  81. {
  82. $dynamic = TRUE;
  83. }
  84. $force_entry = FALSE;
  85. if ($TMPL->fetch_param('entry_id') !== FALSE OR $TMPL->fetch_param('url_title') !== FALSE)
  86. {
  87. $force_entry = TRUE;
  88. }
  89. /** ----------------------------------------------
  90. /** Do we allow dynamic POST variables to set parameters?
  91. /** ----------------------------------------------*/
  92. if ($TMPL->fetch_param('dynamic_parameters') !== FALSE AND isset($_POST) AND count($_POST) > 0)
  93. {
  94. foreach (explode('|', $TMPL->fetch_param('dynamic_parameters')) as $var)
  95. {
  96. if (isset($_POST[$var]) AND in_array($var, array('weblog', 'limit', 'sort', 'orderby')))
  97. {
  98. $TMPL->tagparams[$var] = $_POST[$var];
  99. }
  100. }
  101. }
  102. /** --------------------------------------
  103. /** Parse page number
  104. /** --------------------------------------*/
  105. // We need to strip the page number from the URL for two reasons:
  106. // 1. So we can create pagination links
  107. // 2. So it won't confuse the query with an improper proper ID
  108. if ( ! $dynamic)
  109. {
  110. if (preg_match("#N(\d+)#", $qstring, $match) OR preg_match("#/N(\d+)#", $qstring, $match))
  111. {
  112. $current_page = $match['1'];
  113. $uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $uristr));
  114. }
  115. }
  116. else
  117. {
  118. if (preg_match("#/P(\d+)#", $qstring, $match))
  119. {
  120. $current_page = $match['1'];
  121. $uristr = $FNS->remove_double_slashes(str_replace($match['0'], '', $uristr));
  122. $qstring = $FNS->remove_double_slashes(str_replace($match['0'], '', $qstring));
  123. }
  124. }
  125. if ($dynamic == TRUE OR $force_entry == TRUE)
  126. {
  127. // see if entry_id or url_title parameter is set
  128. if ($entry_id = $TMPL->fetch_param('entry_id'))
  129. {
  130. $entry_sql = " entry_id = '".$DB->escape_str($entry_id)."' ";
  131. }
  132. elseif ($url_title = $TMPL->fetch_param('url_title'))
  133. {
  134. $entry_sql = " url_title = '".$DB->escape_str($url_title)."' ";
  135. }
  136. else
  137. {
  138. // If there is a slash in the entry ID we'll kill everything after it.
  139. $entry_id = trim($qstring);
  140. $entry_id = preg_replace("#/.+#", "", $entry_id);
  141. $entry_sql = ( ! is_numeric($entry_id)) ? " url_title = '".$DB->escape_str($entry_id)."' " : " entry_id = '".$DB->escape_str($entry_id)."' ";
  142. }
  143. /** ----------------------------------------
  144. /** Do we have a vaild entry ID number?
  145. /** ----------------------------------------*/
  146. $timestamp = ($TMPL->cache_timestamp != '') ? $LOC->set_gmt($TMPL->cache_timestamp) : $LOC->now;
  147. $sql = "SELECT entry_id, exp_weblog_titles.weblog_id
  148. FROM exp_weblog_titles, exp_weblogs
  149. WHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  150. AND exp_weblog_titles.site_id IN ('".implode("','", $TMPL->site_ids)."') ";
  151. if ($TMPL->fetch_param('show_expired') !== 'yes')
  152. {
  153. $sql .= "AND (expiration_date = 0 || expiration_date > ".$timestamp.") ";
  154. }
  155. $sql .= "AND status != 'closed' AND ";
  156. $sql .= $entry_sql;
  157. /** ----------------------------------------------
  158. /** Limit to/exclude specific weblogs
  159. /** ----------------------------------------------*/
  160. if (USER_BLOG !== FALSE)
  161. {
  162. // If it's a "user blog" we limit to only their assigned blog
  163. $sql .= " AND exp_weblogs.weblog_id = '".$DB->escape_str(UB_BLOG_ID)."' ";
  164. }
  165. else
  166. {
  167. $sql .= "AND exp_weblogs.is_user_blog = 'n' ";
  168. if ($weblog = $TMPL->fetch_param('weblog') OR $TMPL->fetch_param('site'))
  169. {
  170. $xql = "SELECT weblog_id FROM exp_weblogs WHERE site_id IN ('".implode("','", $TMPL->site_ids)."') ";
  171. if ($weblog !== FALSE)
  172. {
  173. $xql .= $FNS->sql_andor_string($weblog, 'blog_name');
  174. }
  175. $query = $DB->query($xql);
  176. if ($query->num_rows == 1)
  177. {
  178. $sql .= "AND exp_weblog_titles.weblog_id = '".$query->row['weblog_id']."' ";
  179. }
  180. elseif ($query->num_rows > 1)
  181. {
  182. $sql .= "AND (";
  183. foreach ($query->result as $row)
  184. {
  185. $sql .= "exp_weblog_titles.weblog_id = '".$row['weblog_id']."' OR ";
  186. }
  187. $sql = substr($sql, 0, - 3);
  188. $sql .= ") ";
  189. }
  190. }
  191. }
  192. $query = $DB->query($sql);
  193. // Bad ID? See ya!
  194. if ($query->num_rows == 0)
  195. {
  196. return false;
  197. }
  198. unset($sql);
  199. // We'll reassign the entry ID so it's the true numeric ID
  200. $entry_id = $query->row['entry_id'];
  201. }
  202. // If the comment tag is being used in freeform mode
  203. // we need to fetch the weblog ID numbers
  204. $w_sql = '';
  205. if ( ! $dynamic)
  206. {
  207. if (USER_BLOG !== FALSE)
  208. {
  209. // If it's a "user blog" we limit to only their assigned blog
  210. $w_sql .= "AND weblog_id = '".UB_BLOG_ID."' ";
  211. }
  212. else
  213. {
  214. if ($weblog = $TMPL->fetch_param('weblog') OR $TMPL->fetch_param('site'))
  215. {
  216. $xql = "SELECT weblog_id FROM exp_weblogs WHERE site_id IN ('".implode("','", $TMPL->site_ids)."') ";
  217. if ($weblog !== FALSE)
  218. {
  219. $xql .= $FNS->sql_andor_string($weblog, 'blog_name');
  220. }
  221. $query = $DB->query($xql);
  222. if ($query->num_rows == 0)
  223. {
  224. return $TMPL->no_results();
  225. }
  226. else
  227. {
  228. if ($query->num_rows == 1)
  229. {
  230. $w_sql .= "AND weblog_id = '".$query->row['weblog_id']."' ";
  231. }
  232. else
  233. {
  234. $w_sql .= "AND (";
  235. foreach ($query->result as $row)
  236. {
  237. $w_sql .= "weblog_id = '".$row['weblog_id']."' OR ";
  238. }
  239. $w_sql = substr($w_sql, 0, - 3);
  240. $w_sql .= ") ";
  241. }
  242. }
  243. }
  244. }
  245. }
  246. /** ----------------------------------------
  247. /** Set trackback flag
  248. /** ----------------------------------------*/
  249. // Depending on whether the {if trackbacks} conditional
  250. // is present will determine whether we need to show trackbacks
  251. $show_trackbacks = (preg_match("/".LD."if\s+trackbacks".RD.".+?".LD.SLASH."if".RD."/s", $TMPL->tagdata)) ? TRUE : FALSE;
  252. /** ----------------------------------------
  253. /** Set sorting and limiting
  254. /** ----------------------------------------*/
  255. if ( ! $dynamic)
  256. {
  257. $limit = ( ! $TMPL->fetch_param('limit')) ? 100 : $TMPL->fetch_param('limit');
  258. $sort = ( ! $TMPL->fetch_param('sort')) ? 'desc' : $TMPL->fetch_param('sort');
  259. }
  260. else
  261. {
  262. $limit = ( ! $TMPL->fetch_param('limit')) ? $this->limit : $TMPL->fetch_param('limit');
  263. $sort = ( ! $TMPL->fetch_param('sort')) ? 'asc' : $TMPL->fetch_param('sort');
  264. }
  265. $allowed_sorts = array('date', 'email', 'location', 'name', 'url');
  266. /** ----------------------------------------
  267. /** Fetch comment ID numbers
  268. /** ----------------------------------------*/
  269. $temp = array();
  270. $i = 0;
  271. $comments_exist = FALSE;
  272. // Left this here for backward compatibility
  273. // We need to deprecate the "order_by" parameter
  274. if ($TMPL->fetch_param('orderby') != '')
  275. {
  276. $order_by = $TMPL->fetch_param('orderby');
  277. }
  278. else
  279. {
  280. $order_by = $TMPL->fetch_param('order_by');
  281. }
  282. $order_by = ($order_by == 'date' OR ! in_array($order_by, $allowed_sorts)) ? 'comment_date' : $order_by;
  283. if ( ! $dynamic)
  284. {
  285. // When we are only showing comments and it is not based on an entry id or url title
  286. // in the URL, we can make the query much more efficient and save some work.
  287. $e_sql = (isset($entry_id) && $entry_id != '') ? "AND entry_id = '".$DB->escape_str($entry_id)."' ": '';
  288. if ($show_trackbacks === FALSE)
  289. {
  290. $this_page = ($current_page == '' || ($limit > 1 AND $current_page == 1)) ? 0 : $current_page;
  291. $this_sort = (strtolower($sort) == 'desc') ? 'DESC' : 'ASC';
  292. $sql = "SELECT comment_date, comment_id FROM exp_comments
  293. WHERE status = 'o' ".$e_sql.$w_sql."
  294. ORDER BY ".$order_by." ".$this_sort."
  295. LIMIT {$this_page}, ".$limit;
  296. $query = $DB->query($sql);
  297. $count_query = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE status = 'o' ".$e_sql.$w_sql);
  298. $total_rows = $count_query->row['count'];
  299. }
  300. else
  301. {
  302. $sql = "SELECT comment_date, comment_id FROM exp_comments WHERE status = 'o' ".$e_sql.$w_sql." ORDER BY ".$order_by;
  303. }
  304. $query = $DB->query($sql);
  305. }
  306. else
  307. {
  308. $query = $DB->query("SELECT comment_date, comment_id FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o' ORDER BY ".$order_by);
  309. }
  310. if ($query->num_rows > 0)
  311. {
  312. $comments_exist = TRUE;
  313. foreach ($query->result as $row)
  314. {
  315. $key = $row['comment_date'];
  316. while(isset($temp[$key]))
  317. {
  318. $key++;
  319. }
  320. $temp[$key] = 'c'.$row['comment_id'];
  321. }
  322. }
  323. /** ----------------------------------------
  324. /** Fetch trackback ID numbers
  325. /** ----------------------------------------*/
  326. $trackbacks_exist = FALSE;
  327. if ($show_trackbacks)
  328. {
  329. if ( ! $dynamic)
  330. {
  331. $t_sql = '';
  332. if ($w_sql != '')
  333. {
  334. $t_sql = trim($w_sql);
  335. $t_sql = "WHERE ".substr($t_sql, 3);
  336. }
  337. $sql = "SELECT trackback_date, trackback_id FROM exp_trackbacks ".$t_sql." ORDER BY trackback_date";
  338. $query = $DB->query($sql);
  339. }
  340. else
  341. {
  342. $query = $DB->query("SELECT trackback_date, trackback_id FROM exp_trackbacks WHERE entry_id = '".$DB->escape_str($entry_id)."' ORDER BY trackback_date");
  343. }
  344. if ($query->num_rows > 0)
  345. {
  346. $trackbacks_exist = TRUE;
  347. foreach ($query->result as $row)
  348. {
  349. $key = $row['trackback_date'];
  350. while(isset($temp[$key]))
  351. {
  352. $key++;
  353. }
  354. $temp[$key] = 't'.$row['trackback_id'];
  355. }
  356. }
  357. }
  358. /** ------------------------------------
  359. /** No results? No reason to continue...
  360. /** ------------------------------------*/
  361. if (count($temp) == 0)
  362. {
  363. return $TMPL->no_results();
  364. }
  365. // Sort the array based on the keys (which contain the Unix timesamps
  366. // of the comments and trackbacks)
  367. if ($order_by == 'comment_date')
  368. {
  369. ksort($temp);
  370. }
  371. // Create a new, sequentially indexed array
  372. $result_ids = array();
  373. foreach ($temp as $val)
  374. {
  375. $result_ids[$val] = $val;
  376. }
  377. // Reverse the array if order is descending
  378. if ($sort == 'desc')
  379. {
  380. $result_ids = array_reverse($result_ids);
  381. }
  382. /** ---------------------------------
  383. /** Do we need pagination?
  384. /** ---------------------------------*/
  385. // When showing only comments and no using the URL, then we already have this value
  386. if ($dynamic OR $show_trackbacks === TRUE)
  387. {
  388. $total_rows = count($result_ids);
  389. }
  390. if (preg_match("/".LD."paginate(.*?)".RD."(.+?)".LD.SLASH."paginate".RD."/s", $TMPL->tagdata, $match))
  391. {
  392. $paginate = TRUE;
  393. $paginate_data = $match['2'];
  394. $anchor = '';
  395. if ($match['1'] != '')
  396. {
  397. if (preg_match("/anchor.*?=[\"|\'](.+?)[\"|\']/", $match['1'], $amatch))
  398. {
  399. $anchor = '#'.$amatch['1'];
  400. }
  401. }
  402. $TMPL->tagdata = preg_replace("/".LD."paginate.*?".RD.".+?".LD.SLASH."paginate".RD."/s", "", $TMPL->tagdata);
  403. $current_page = ($current_page == '' || ($limit > 1 AND $current_page == 1)) ? 0 : $current_page;
  404. if ($current_page > $total_rows)
  405. {
  406. $current_page = 0;
  407. }
  408. $t_current_page = floor(($current_page / $limit) + 1);
  409. $total_pages = intval(floor($total_rows / $limit));
  410. if ($total_rows % $limit)
  411. $total_pages++;
  412. if ($total_rows > $limit)
  413. {
  414. if ( ! class_exists('Paginate'))
  415. {
  416. require PATH_CORE.'core.paginate'.EXT;
  417. }
  418. $PGR = new Paginate();
  419. $deft_tmpl = '';
  420. if ($uristr == '')
  421. {
  422. if (USER_BLOG !== FALSE)
  423. {
  424. $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE group_id = '".$DB->escape_str(UB_TMP_GRP)."'");
  425. $deft_tmpl = $query->row['group_name'].'/index/';
  426. }
  427. else
  428. {
  429. if ($PREFS->ini('template_group') == '')
  430. {
  431. $query = $DB->query("SELECT group_name FROM exp_template_groups WHERE is_site_default = 'y' AND is_user_blog = 'n'");
  432. $deft_tmpl = $query->row['group_name'].'/index/';
  433. }
  434. else
  435. {
  436. $deft_tmpl = $PREFS->ini('template_group').'/';
  437. $deft_tmpl .= ($PREFS->ini('template') == '') ? 'index' : $PREFS->ini('template');
  438. $deft_tmpl .= '/';
  439. }
  440. }
  441. }
  442. $basepath = $FNS->remove_double_slashes($FNS->create_url($uristr, 1, 0).'/'.$deft_tmpl);
  443. $first_url = (substr($basepath, -5) == '.php/') ? substr($basepath, 0, -1) : $basepath;
  444. if ($TMPL->fetch_param('paginate_base'))
  445. {
  446. $pbase = $REGX->trim_slashes($TMPL->fetch_param('paginate_base'));
  447. $pbase = str_replace("&#47;index", "/", $pbase);
  448. if ( ! strstr($basepath, $pbase))
  449. {
  450. $basepath = $FNS->remove_double_slashes($basepath.'/'.$pbase.'/');
  451. }
  452. }
  453. $PGR->first_url = $first_url;
  454. $PGR->path = $basepath;
  455. $PGR->prefix = ( ! $dynamic) ? 'N' : 'P';
  456. $PGR->total_count = $total_rows;
  457. $PGR->per_page = $limit;
  458. $PGR->cur_page = $current_page;
  459. $PGR->suffix = $anchor;
  460. $pagination_links = $PGR->show_links();
  461. if ((($total_pages * $limit) - $limit) > $current_page)
  462. {
  463. $page_next = $basepath.'P'.($current_page + $limit).'/';
  464. }
  465. if (($current_page - $limit ) >= 0)
  466. {
  467. $page_previous = $basepath.'P'.($current_page - $limit).'/';
  468. }
  469. }
  470. else
  471. {
  472. $current_page = '';
  473. }
  474. }
  475. // When only non-dynamic comments are show, all results are valid as the
  476. // query is restricted with a LIMIT clause
  477. if ($dynamic OR $show_trackbacks === TRUE)
  478. {
  479. if ($current_page == '')
  480. {
  481. $result_ids = array_slice($result_ids, 0, $limit);
  482. }
  483. else
  484. {
  485. $result_ids = array_slice($result_ids, $current_page, $limit);
  486. }
  487. }
  488. /** -----------------------------------
  489. /** Fetch Comments if necessary
  490. /** -----------------------------------*/
  491. $results = $result_ids;
  492. $mfields = array();
  493. if ($comments_exist == TRUE)
  494. {
  495. $com = '';
  496. foreach ($result_ids as $val)
  497. {
  498. if (substr($val, 0, 1) == 'c')
  499. {
  500. $com .= substr($val, 1).",";
  501. }
  502. }
  503. if ($com != '')
  504. {
  505. /** ----------------------------------------
  506. /** "Search by Member" link
  507. /** ----------------------------------------*/
  508. // We use this with the {member_search_path} variable
  509. $result_path = (preg_match("/".LD."member_search_path\s*=(.*?)".RD."/s", $TMPL->tagdata, $match)) ? $match['1'] : 'search/results';
  510. $result_path = str_replace("\"", "", $result_path);
  511. $result_path = str_replace("'", "", $result_path);
  512. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  513. $search_link = $FNS->fetch_site_index(0, 0).$qs.'ACT='.$FNS->fetch_action_id('Search', 'do_search').'&amp;result_path='.$result_path.'&amp;mbr=';
  514. $sql = "SELECT
  515. exp_comments.comment_id, exp_comments.entry_id, exp_comments.weblog_id, exp_comments.author_id, exp_comments.name, exp_comments.email, exp_comments.url, exp_comments.location as c_location, exp_comments.ip_address, exp_comments.comment_date, exp_comments.edit_date, exp_comments.comment, exp_comments.notify, exp_comments.site_id AS comment_site_id,
  516. exp_members.location, exp_members.occupation, exp_members.interests, exp_members.aol_im, exp_members.yahoo_im, exp_members.msn_im, exp_members.icq, exp_members.group_id, exp_members.member_id, exp_members.signature, exp_members.sig_img_filename, exp_members.sig_img_width, exp_members.sig_img_height, exp_members.avatar_filename, exp_members.avatar_width, exp_members.avatar_height, exp_members.photo_filename, exp_members.photo_width, exp_members.photo_height,
  517. exp_member_data.*,
  518. exp_weblog_titles.title, exp_weblog_titles.url_title, exp_weblog_titles.author_id AS entry_author_id,
  519. exp_weblogs.comment_text_formatting, exp_weblogs.comment_html_formatting, exp_weblogs.comment_allow_img_urls, exp_weblogs.comment_auto_link_urls, exp_weblogs.blog_url, exp_weblogs.comment_url, exp_weblogs.blog_title
  520. FROM exp_comments
  521. LEFT JOIN exp_weblogs ON exp_comments.weblog_id = exp_weblogs.weblog_id
  522. LEFT JOIN exp_weblog_titles ON exp_comments.entry_id = exp_weblog_titles.entry_id
  523. LEFT JOIN exp_members ON exp_members.member_id = exp_comments.author_id
  524. LEFT JOIN exp_member_data ON exp_member_data.member_id = exp_members.member_id
  525. WHERE exp_comments.comment_id IN (".substr($com, 0, -1).")";
  526. $query = $DB->query($sql);
  527. if ($query->num_rows > 0)
  528. {
  529. $i = 0;
  530. foreach ($query->result as $row)
  531. {
  532. if (isset($results['c'.$row['comment_id']]))
  533. {
  534. $results['c'.$row['comment_id']] = $query->result[$i];
  535. $i++;
  536. }
  537. }
  538. }
  539. /** ----------------------------------------
  540. /** Fetch custom member field IDs
  541. /** ----------------------------------------*/
  542. $query = $DB->query("SELECT m_field_id, m_field_name FROM exp_member_fields");
  543. if ($query->num_rows > 0)
  544. {
  545. foreach ($query->result as $row)
  546. {
  547. $mfields[$row['m_field_name']] = $row['m_field_id'];
  548. }
  549. }
  550. }
  551. }
  552. /** -----------------------------------
  553. /** Fetch Trackbacks if necessary
  554. /** -----------------------------------*/
  555. if ($trackbacks_exist == TRUE)
  556. {
  557. $trb = '';
  558. foreach ($result_ids as $val)
  559. {
  560. if (substr($val, 0, 1) == 't')
  561. {
  562. $trb .= substr($val, 1).",";
  563. }
  564. }
  565. if ($trb != '')
  566. {
  567. $sql = "SELECT
  568. exp_trackbacks.trackback_id, exp_trackbacks.title, exp_trackbacks.content, exp_trackbacks.weblog_name, exp_trackbacks.trackback_url, exp_trackbacks.trackback_date, exp_trackbacks.trackback_ip,
  569. exp_weblog_titles.weblog_id, exp_weblog_titles.allow_trackbacks, exp_weblog_titles.url_title
  570. FROM exp_trackbacks
  571. LEFT JOIN exp_weblog_titles ON (exp_weblog_titles.entry_id = exp_trackbacks.entry_id)
  572. WHERE exp_trackbacks.trackback_id IN (".substr($trb, 0, -1).")";
  573. $query = $DB->query($sql);
  574. if ($query->num_rows > 0)
  575. {
  576. $i = 0;
  577. foreach ($query->result as $row)
  578. {
  579. if (isset($results['t'.$row['trackback_id']]))
  580. {
  581. $results['t'.$row['trackback_id']] = $query->result[$i];
  582. $i++;
  583. }
  584. }
  585. }
  586. }
  587. }
  588. /** ----------------------------------------
  589. /** Instantiate Typography class
  590. /** ----------------------------------------*/
  591. if ( ! class_exists('Typography'))
  592. {
  593. require PATH_CORE.'core.typography'.EXT;
  594. }
  595. $TYPE = new Typography(FALSE, FALSE);
  596. /** ----------------------------------------
  597. /** Fetch all the date-related variables
  598. /** ----------------------------------------*/
  599. $gmt_comment_date = array();
  600. $comment_date = array();
  601. $trackback_date = array();
  602. $edit_date = array();
  603. // We do this here to avoid processing cycles in the foreach loop
  604. $date_vars = array('gmt_comment_date', 'comment_date', 'trackback_date', 'edit_date');
  605. foreach ($date_vars as $val)
  606. {
  607. if (preg_match_all("/".LD.$val."\s+format=[\"'](.*?)[\"']".RD."/s", $TMPL->tagdata, $matches))
  608. {
  609. for ($j = 0; $j < count($matches['0']); $j++)
  610. {
  611. $matches['0'][$j] = str_replace(LD, '', $matches['0'][$j]);
  612. $matches['0'][$j] = str_replace(RD, '', $matches['0'][$j]);
  613. switch ($val)
  614. {
  615. case 'comment_date' : $comment_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]);
  616. break;
  617. case 'gmt_comment_date' : $gmt_comment_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]);
  618. break;
  619. case 'trackback_date' : $trackback_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]);
  620. break;
  621. case 'edit_date' : $edit_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]);
  622. break;
  623. }
  624. }
  625. }
  626. }
  627. /** ----------------------------------------
  628. /** Protected Variables for Cleanup Routine
  629. /** ----------------------------------------*/
  630. // Since comments do not necessarily require registration, and since
  631. // you are allowed to put member variables in comments, we need to kill
  632. // left-over unparsed junk. The $member_vars array is all of those
  633. // member related variables that should be removed.
  634. $member_vars = array('location', 'occupation', 'interests', 'aol_im', 'yahoo_im', 'msn_im', 'icq',
  635. 'signature', 'sig_img_filename', 'sig_img_width', 'sig_img_height',
  636. 'avatar_filename', 'avatar_width', 'avatar_height',
  637. 'photo_filename', 'photo_width', 'photo_height');
  638. $member_cond_vars = array();
  639. foreach($member_vars as $var)
  640. {
  641. $member_cond_vars[$var] = '';
  642. }
  643. /** ----------------------------------------
  644. /** Start the processing loop
  645. /** ----------------------------------------*/
  646. $item_count = 0;
  647. $relative_count = 0;
  648. $absolute_count = ($current_page == '') ? 0 : $current_page;
  649. $total_results = sizeof($results);
  650. foreach ($results as $id => $row)
  651. {
  652. if ( ! is_array($row))
  653. continue;
  654. $relative_count++;
  655. $absolute_count++;
  656. $row['count'] = $relative_count;
  657. $row['absolute_count'] = $absolute_count;
  658. $row['total_comments'] = $total_rows;
  659. $row['total_results'] = $total_results;
  660. // This lets the {if location} variable work
  661. if ($comments_exist == TRUE AND isset($row['author_id']))
  662. {
  663. if ($row['author_id'] == 0)
  664. $row['location'] = $row['c_location'];
  665. }
  666. $tagdata = $TMPL->tagdata;
  667. // -------------------------------------------
  668. // 'comment_entries_tagdata' hook.
  669. // - Modify and play with the tagdata before everyone else
  670. //
  671. if ($EXT->active_hook('comment_entries_tagdata') === TRUE)
  672. {
  673. $tagdata = $EXT->call_extension('comment_entries_tagdata', $tagdata, $row);
  674. if ($EXT->end_script === TRUE) return $tagdata;
  675. }
  676. //
  677. // -------------------------------------------
  678. /** ----------------------------------------
  679. /** Conditionals
  680. /** ----------------------------------------*/
  681. $cond = array_merge($member_cond_vars, $row);
  682. $cond['comments'] = (substr($id, 0, 1) == 't') ? 'FALSE' : 'TRUE';
  683. $cond['trackbacks'] = (substr($id, 0, 1) == 'c') ? 'FALSE' : 'TRUE';
  684. $cond['logged_in'] = ($SESS->userdata('member_id') == 0) ? 'FALSE' : 'TRUE';
  685. $cond['logged_out'] = ($SESS->userdata('member_id') != 0) ? 'FALSE' : 'TRUE';
  686. $cond['allow_comments'] = (isset($row['allow_comments']) AND $row['allow_comments'] == 'n') ? 'FALSE' : 'TRUE';
  687. $cond['allow_trackbacks'] = (isset($row['allow_trackbacks']) AND $row['allow_trackbacks'] == 'n') ? 'FALSE' : 'TRUE';
  688. $cond['signature_image'] = ( ! isset($row['sig_img_filename']) OR $row['sig_img_filename'] == '' OR $PREFS->ini('enable_signatures') == 'n' OR $SESS->userdata('display_signatures') == 'n') ? 'FALSE' : 'TRUE';
  689. $cond['avatar'] = ( ! isset($row['avatar_filename']) OR $row['avatar_filename'] == '' OR $PREFS->ini('enable_avatars') == 'n' OR $SESS->userdata('display_avatars') == 'n') ? 'FALSE' : 'TRUE';
  690. $cond['photo'] = ( ! isset($row['photo_filename']) OR $row['photo_filename'] == '' OR $PREFS->ini('enable_photos') == 'n' OR $SESS->userdata('display_photos') == 'n') ? 'FALSE' : 'TRUE';
  691. $cond['is_ignored'] = ( ! isset($row['member_id']) OR ! in_array($row['member_id'], $SESS->userdata['ignore_list'])) ? 'FALSE' : 'TRUE';
  692. if ( isset($mfields) && is_array($mfields) && sizeof($mfields) > 0)
  693. {
  694. foreach($mfields as $key => $value)
  695. {
  696. if (isset($row['m_field_id_'.$value]))
  697. $cond[$key] = $row['m_field_id_'.$value];
  698. }
  699. }
  700. $tagdata = $FNS->prep_conditionals($tagdata, $cond);
  701. /** ----------------------------------------
  702. /** Parse "single" variables
  703. /** ----------------------------------------*/
  704. foreach ($TMPL->var_single as $key => $val)
  705. {
  706. /** ----------------------------------------
  707. /** parse {switch} variable
  708. /** ----------------------------------------*/
  709. if (strncmp($key, 'switch', 6) == 0)
  710. {
  711. $sparam = $FNS->assign_parameters($key);
  712. $sw = '';
  713. if (isset($sparam['switch']))
  714. {
  715. $sopt = @explode("|", $sparam['switch']);
  716. $sw = $sopt[($relative_count + count($sopt) - 1) % count($sopt)];
  717. /* Old style switch parsing
  718. /*
  719. if (count($sopt) == 2)
  720. {
  721. if (isset($switch[$sparam['switch']]) AND $switch[$sparam['switch']] == $sopt['0'])
  722. {
  723. $switch[$sparam['switch']] = $sopt['1'];
  724. $sw = $sopt['1'];
  725. }
  726. else
  727. {
  728. $switch[$sparam['switch']] = $sopt['0'];
  729. $sw = $sopt['0'];
  730. }
  731. }
  732. */
  733. }
  734. $tagdata = $TMPL->swap_var_single($key, $sw, $tagdata);
  735. }
  736. /** ----------------------------------------
  737. /** parse permalink
  738. /** ----------------------------------------*/
  739. if (strncmp('permalink', $key, 9) == 0 && isset($row['comment_id']))
  740. {
  741. $tagdata = $TMPL->swap_var_single(
  742. $key,
  743. $FNS->create_url($uristr.'#'.$row['comment_id'], 0, 0),
  744. $tagdata
  745. );
  746. }
  747. /** ----------------------------------------
  748. /** parse comment_path or trackback_path
  749. /** ----------------------------------------*/
  750. if (preg_match("#^(comment_path|trackback_path|entry_id_path)#", $key))
  751. {
  752. $tagdata = $TMPL->swap_var_single(
  753. $key,
  754. $FNS->create_url($FNS->extract_path($key).'/'.$row['entry_id']),
  755. $tagdata
  756. );
  757. }
  758. /** ----------------------------------------
  759. /** parse title permalink
  760. /** ----------------------------------------*/
  761. if (preg_match("#^(title_permalink|url_title_path)#", $key))
  762. {
  763. $path = ($FNS->extract_path($key) != '' AND $FNS->extract_path($key) != 'SITE_INDEX') ? $FNS->extract_path($key).'/'.$row['url_title'] : $row['url_title'];
  764. $tagdata = $TMPL->swap_var_single(
  765. $key,
  766. $FNS->create_url($path, 1, 0),
  767. $tagdata
  768. );
  769. }
  770. /** ----------------------------------------
  771. /** parse comment date
  772. /** ----------------------------------------*/
  773. if (isset($comment_date[$key]) AND $comments_exist == TRUE AND isset($row['comment_date']))
  774. {
  775. foreach ($comment_date[$key] as $dvar)
  776. {
  777. $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['comment_date'], TRUE), $val);
  778. }
  779. $tagdata = $TMPL->swap_var_single($key, $val, $tagdata);
  780. }
  781. /** ----------------------------------------
  782. /** parse GMT comment date
  783. /** ----------------------------------------*/
  784. if (isset($gmt_comment_date[$key]) AND $comments_exist == TRUE AND isset($row['comment_date']))
  785. {
  786. foreach ($gmt_comment_date[$key] as $dvar)
  787. {
  788. $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['comment_date'], FALSE), $val);
  789. }
  790. $tagdata = $TMPL->swap_var_single($key, $val, $tagdata);
  791. }
  792. /** ----------------------------------------
  793. /** parse trackback date
  794. /** ----------------------------------------*/
  795. if (isset($trackback_date[$key]) AND $trackbacks_exist == TRUE AND isset($row['trackback_date']))
  796. {
  797. foreach ($trackback_date[$key] as $dvar)
  798. $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $row['trackback_date'], TRUE), $val);
  799. $tagdata = $TMPL->swap_var_single($key, $val, $tagdata);
  800. }
  801. /** ----------------------------------------
  802. /** parse "last edit" date
  803. /** ----------------------------------------*/
  804. if (isset($edit_date[$key]))
  805. {
  806. if (isset($row['edit_date']))
  807. {
  808. foreach ($edit_date[$key] as $dvar)
  809. $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $LOC->timestamp_to_gmt($row['edit_date']), TRUE), $val);
  810. $tagdata = $TMPL->swap_var_single($key, $val, $tagdata);
  811. }
  812. }
  813. /** ----------------------------------------
  814. /** {member_search_path}
  815. /** ----------------------------------------*/
  816. if (strncmp('member_search_path', $key, 18) == 0)
  817. {
  818. $tagdata = $TMPL->swap_var_single($key, $search_link.$row['author_id'], $tagdata);
  819. }
  820. // Prep the URL
  821. if (isset($row['url']))
  822. {
  823. $row['url'] = $REGX->prep_url($row['url']);
  824. }
  825. /** ----------------------------------------
  826. /** {author}
  827. /** ----------------------------------------*/
  828. if ($key == "author")
  829. {
  830. $tagdata = $TMPL->swap_var_single($val, (isset($row['name'])) ? $row['name'] : '', $tagdata);
  831. }
  832. /** ----------------------------------------
  833. /** {url_or_email} - Uses Raw Email Address, Like Weblog Module
  834. /** ----------------------------------------*/
  835. if ($key == "url_or_email" AND isset($row['url']))
  836. {
  837. $tagdata = $TMPL->swap_var_single($val, ($row['url'] != '') ? $row['url'] : $row['email'], $tagdata);
  838. }
  839. /** ----------------------------------------
  840. /** {url_as_author}
  841. /** ----------------------------------------*/
  842. if ($key == "url_as_author" AND isset($row['url']))
  843. {
  844. if ($row['url'] != '')
  845. {
  846. $tagdata = $TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['name']."</a>", $tagdata);
  847. }
  848. else
  849. {
  850. $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata);
  851. }
  852. }
  853. /** ----------------------------------------
  854. /** {url_or_email_as_author}
  855. /** ----------------------------------------*/
  856. if ($key == "url_or_email_as_author" AND isset($row['url']))
  857. {
  858. if ($row['url'] != '')
  859. {
  860. $tagdata = $TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['name']."</a>", $tagdata);
  861. }
  862. else
  863. {
  864. if ($row['email'] != '')
  865. {
  866. $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($row['email'], $row['name']), $tagdata);
  867. }
  868. else
  869. {
  870. $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata);
  871. }
  872. }
  873. }
  874. /** ----------------------------------------
  875. /** {url_or_email_as_link}
  876. /** ----------------------------------------*/
  877. if ($key == "url_or_email_as_link" AND isset($row['url']))
  878. {
  879. if ($row['url'] != '')
  880. {
  881. $tagdata = $TMPL->swap_var_single($val, "<a href=\"".$row['url']."\">".$row['url']."</a>", $tagdata);
  882. }
  883. else
  884. {
  885. if ($row['email'] != '')
  886. {
  887. $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($row['email']), $tagdata);
  888. }
  889. else
  890. {
  891. $tagdata = $TMPL->swap_var_single($val, $row['name'], $tagdata);
  892. }
  893. }
  894. }
  895. if (substr($id, 0, 1) == 'c')
  896. {
  897. /** ----------------------------------------
  898. /** {comment_auto_path}
  899. /** ----------------------------------------*/
  900. if ($key == "comment_auto_path")
  901. {
  902. $path = ($row['comment_url'] == '') ? $row['blog_url'] : $row['comment_url'];
  903. $tagdata = $TMPL->swap_var_single($key, $path, $tagdata);
  904. }
  905. /** ----------------------------------------
  906. /** {comment_url_title_auto_path}
  907. /** ----------------------------------------*/
  908. if ($key == "comment_url_title_auto_path" AND $comments_exist == TRUE)
  909. {
  910. $path = ($row['comment_url'] == '') ? $row['blog_url'] : $row['comment_url'];
  911. $tagdata = $TMPL->swap_var_single(
  912. $key,
  913. $path.$row['url_title'].'/',
  914. $tagdata
  915. );
  916. }
  917. /** ----------------------------------------
  918. /** {comment_entry_id_auto_path}
  919. /** ----------------------------------------*/
  920. if ($key == "comment_entry_id_auto_path" AND $comments_exist == TRUE)
  921. {
  922. $path = ($row['comment_url'] == '') ? $row['blog_url'] : $row['comment_url'];
  923. $tagdata = $TMPL->swap_var_single(
  924. $key,
  925. $path.$row['entry_id'].'/',
  926. $tagdata
  927. );
  928. }
  929. /** ----------------------------------------
  930. /** parse comment field
  931. /** ----------------------------------------*/
  932. if ($key == 'comment' AND isset($row['comment']))
  933. {
  934. // -------------------------------------------
  935. // 'comment_entries_comment_format' hook.
  936. // - Play with the tagdata contents of the comment entries
  937. //
  938. if ($EXT->active_hook('comment_entries_comment_format') === TRUE)
  939. {
  940. $comment = $EXT->call_extension('comment_entries_comment_format', $row);
  941. if ($EXT->end_script === TRUE) return;
  942. }
  943. else
  944. {
  945. $comment = $TYPE->parse_type( $row['comment'],
  946. array(
  947. 'text_format' => $row['comment_text_formatting'],
  948. 'html_format' => $row['comment_html_formatting'],
  949. 'auto_links' => $row['comment_auto_link_urls'],
  950. 'allow_img_url' => $row['comment_allow_img_urls']
  951. )
  952. );
  953. }
  954. //
  955. // -------------------------------------------
  956. $tagdata = $TMPL->swap_var_single($key, $comment, $tagdata);
  957. }
  958. }
  959. /** ----------------------------------------
  960. /** {location}
  961. /** ----------------------------------------*/
  962. if ($key == 'location' AND (isset($row['location']) || isset($row['c_location'])))
  963. {
  964. $tagdata = $TMPL->swap_var_single($key, (empty($row['location'])) ? $row['c_location'] : $row['location'], $tagdata);
  965. }
  966. /** ----------------------------------------
  967. /** {signature}
  968. /** ----------------------------------------*/
  969. if ($key == "signature")
  970. {
  971. if ($SESS->userdata('display_signatures') == 'n' OR ! isset($row['signature']) OR $row['signature'] == '' OR $SESS->userdata('display_signatures') == 'n')
  972. {
  973. $tagdata = $TMPL->swap_var_single($key, '', $tagdata);
  974. }
  975. else
  976. {
  977. $tagdata = $TMPL->swap_var_single($key,
  978. $TYPE->parse_type($row['signature'], array(
  979. 'text_format' => 'xhtml',
  980. 'html_format' => 'safe',
  981. 'auto_links' => 'y',
  982. 'allow_img_url' => $PREFS->ini('sig_allow_img_hotlink')
  983. )
  984. ), $tagdata);
  985. }
  986. }
  987. if ($key == "signature_image_url")
  988. {
  989. if ($SESS->userdata('display_signatures') == 'n' OR $row['sig_img_filename'] == '' OR $SESS->userdata('display_signatures') == 'n')
  990. {
  991. $tagdata = $TMPL->swap_var_single($key, '', $tagdata);
  992. $tagdata = $TMPL->swap_var_single('signature_image_width', '', $tagdata);
  993. $tagdata = $TMPL->swap_var_single('signature_image_height', '', $tagdata);
  994. }
  995. else
  996. {
  997. $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('sig_img_url', TRUE).$row['sig_img_filename'], $tagdata);
  998. $tagdata = $TMPL->swap_var_single('signature_image_width', $row['sig_img_width'], $tagdata);
  999. $tagdata = $TMPL->swap_var_single('signature_image_height', $row['sig_img_height'], $tagdata);
  1000. }
  1001. }
  1002. if ($key == "avatar_url")
  1003. {
  1004. if ( ! isset($row['avatar_filename']))
  1005. $row['avatar_filename'] = '';
  1006. if ($SESS->userdata('display_avatars') == 'n' OR $row['avatar_filename'] == '' OR $SESS->userdata('display_avatars') == 'n')
  1007. {
  1008. $tagdata = $TMPL->swap_var_single($key, '', $tagdata);
  1009. $tagdata = $TMPL->swap_var_single('avatar_image_width', '', $tagdata);
  1010. $tagdata = $TMPL->swap_var_single('avatar_image_height', '', $tagdata);
  1011. }
  1012. else
  1013. {
  1014. $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('avatar_url', 1).$row['avatar_filename'], $tagdata);
  1015. $tagdata = $TMPL->swap_var_single('avatar_image_width', $row['avatar_width'], $tagdata);
  1016. $tagdata = $TMPL->swap_var_single('avatar_image_height', $row['avatar_height'], $tagdata);
  1017. }
  1018. }
  1019. if ($key == "photo_url")
  1020. {
  1021. if ( ! isset($row['photo_filename']))
  1022. $row['photo_filename'] = '';
  1023. if ($SESS->userdata('display_photos') == 'n' OR $row['photo_filename'] == '' OR $SESS->userdata('display_photos') == 'n')
  1024. {
  1025. $tagdata = $TMPL->swap_var_single($key, '', $tagdata);
  1026. $tagdata = $TMPL->swap_var_single('photo_image_width', '', $tagdata);
  1027. $tagdata = $TMPL->swap_var_single('photo_image_height', '', $tagdata);
  1028. }
  1029. else
  1030. {
  1031. $tagdata = $TMPL->swap_var_single($key, $PREFS->ini('photo_url', 1).$row['photo_filename'], $tagdata);
  1032. $tagdata = $TMPL->swap_var_single('photo_image_width', $row['photo_width'], $tagdata);
  1033. $tagdata = $TMPL->swap_var_single('photo_image_height', $row['photo_height'], $tagdata);
  1034. }
  1035. }
  1036. /** ----------------------------------------
  1037. /** parse basic fields
  1038. /** ----------------------------------------*/
  1039. if (isset($row[$val]) && $val != 'member_id')
  1040. {
  1041. $tagdata = $TMPL->swap_var_single($val, $row[$val], $tagdata);
  1042. }
  1043. /** ----------------------------------------
  1044. /** parse custom member fields
  1045. /** ----------------------------------------*/
  1046. if ( isset($mfields[$val]))
  1047. {
  1048. // Since comments do not necessarily require registration, and since
  1049. // you are allowed to put custom member variables in comments,
  1050. // we delete them if no such row exists
  1051. $return_val = (isset($row['m_field_id_'.$mfields[$val]])) ? $row['m_field_id_'.$mfields[$val]] : '';
  1052. $tagdata = $TMPL->swap_var_single(
  1053. $val,
  1054. $return_val,
  1055. $tagdata
  1056. );
  1057. }
  1058. /** ----------------------------------------
  1059. /** Clean up left over member variables
  1060. /** ----------------------------------------*/
  1061. if (in_array($val, $member_vars))
  1062. {
  1063. $tagdata = str_replace(LD.$val.RD, '', $tagdata);
  1064. }
  1065. }
  1066. if ($this->show_anchor == TRUE)
  1067. {
  1068. $return .= "<a name=\"".$item_count."\"></a>\n";
  1069. }
  1070. $return .= $tagdata;
  1071. $item_count++;
  1072. }
  1073. /** ----------------------------------------
  1074. /** Parse path variable
  1075. /** ----------------------------------------*/
  1076. $return = preg_replace_callback("/".LD."\s*path=(.+?)".RD."/", array(&$FNS, 'create_url'), $return);
  1077. /** ----------------------------------------
  1078. /** Add pagination to result
  1079. /** ----------------------------------------*/
  1080. if ($paginate == TRUE)
  1081. {
  1082. $paginate_data = str_replace(LD.'current_page'.RD, $t_current_page, $paginate_data);
  1083. $paginate_data = str_replace(LD.'total_pages'.RD, $total_pages, $paginate_data);
  1084. $paginate_data = str_replace(LD.'pagination_links'.RD, $pagination_links, $paginate_data);
  1085. if (preg_match("/".LD."if previous_page".RD."(.+?)".LD.SLASH."if".RD."/s", $paginate_data, $match))
  1086. {
  1087. if ($page_previous == '')
  1088. {
  1089. $paginate_data = preg_replace("/".LD."if previous_page".RD.".+?".LD.SLASH."if".RD."/s", '', $paginate_data);
  1090. }
  1091. else
  1092. {
  1093. $match['1'] = str_replace(array(LD.'path'.RD, LD.'auto_path'.RD), $page_previous, $match['1']);
  1094. $paginate_data = str_replace($match['0'], $match['1'], $paginate_data);
  1095. }
  1096. }
  1097. if (preg_match("/".LD."if next_page".RD."(.+?)".LD.SLASH."if".RD."/s", $paginate_data, $match))
  1098. {
  1099. if ($page_next == '')
  1100. {
  1101. $paginate_data = preg_replace("/".LD."if next_page".RD.".+?".LD.SLASH."if".RD."/s", '', $paginate_data);
  1102. }
  1103. else
  1104. {
  1105. $match['1'] = str_replace(array(LD.'path'.RD, LD.'auto_path'.RD), $page_next, $match['1']);
  1106. $paginate_data = str_replace($match['0'], $match['1'], $paginate_data);
  1107. }
  1108. }
  1109. $position = ( ! $TMPL->fetch_param('paginate')) ? '' : $TMPL->fetch_param('paginate');
  1110. switch ($position)
  1111. {
  1112. case "top" : $return = $paginate_data.$return;
  1113. break;
  1114. case "both" : $return = $paginate_data.$return.$paginate_data;
  1115. break;
  1116. default : $return .= $paginate_data;
  1117. break;
  1118. }
  1119. }
  1120. return $return;
  1121. }
  1122. /* END */
  1123. /** ----------------------------------------
  1124. /** Comment Submission Form
  1125. /** ----------------------------------------*/
  1126. function form($return_form = FALSE, $captcha = '')
  1127. {
  1128. global $IN, $FNS, $PREFS, $SESS, $TMPL, $LOC, $DB, $REGX, $LANG, $EXT;
  1129. $qstring = $IN->QSTR;
  1130. /** --------------------------------------
  1131. /** Remove page number
  1132. /** --------------------------------------*/
  1133. if (preg_match("#/P\d+#", $qstring, $match))
  1134. {
  1135. $qstring = $FNS->remove_double_slashes(str_replace($match['0'], '', $qstring));
  1136. }
  1137. // Figure out the right entry ID
  1138. // Order of precedence: POST, entry_id=, url_title=, $qstring
  1139. if (isset($_POST['entry_id']))
  1140. {
  1141. $entry_sql = " entry_id = '".$DB->escape_str($_POST['entry_id'])."' ";
  1142. }
  1143. elseif ($entry_id = $TMPL->fetch_param('entry_id'))
  1144. {
  1145. $entry_sql = " entry_id = '".$DB->escape_str($entry_id)."' ";
  1146. }
  1147. elseif ($url_title = $TMPL->fetch_param('url_title'))
  1148. {
  1149. $entry_sql = " url_title = '".$DB->escape_str($url_title)."' ";
  1150. }
  1151. else
  1152. {
  1153. // If there is a slash in the entry ID we'll kill everything after it.
  1154. $entry_id = trim($qstring);
  1155. $entry_id = preg_replace("#/.+#", "", $entry_id);
  1156. $entry_sql = ( ! is_numeric($entry_id)) ? " url_title = '".$DB->escape_str($entry_id)."' " : " entry_id = '".$DB->escape_str($entry_id)."' ";
  1157. }
  1158. /** ----------------------------------------
  1159. /** Are comments allowed?
  1160. /** ----------------------------------------*/
  1161. $sql = "SELECT exp_weblog_titles.entry_id, exp_weblog_titles.entry_date, exp_weblog_titles.comment_expiration_date, exp_weblog_titles.allow_comments, exp_weblogs.comment_system_enabled, exp_weblogs.comment_use_captcha, exp_weblogs.comment_expiration FROM exp_weblog_titles, exp_weblogs ";
  1162. $sql .= " WHERE {$entry_sql}";
  1163. $sql .= " AND exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  1164. AND exp_weblog_titles.site_id IN ('".implode("','", $TMPL->site_ids)."')
  1165. AND status != 'closed' ";
  1166. if ($weblog = $TMPL->fetch_param('weblog'))
  1167. {
  1168. $xql = "SELECT weblog_id FROM exp_weblogs WHERE site_id IN ('".implode("','", $TMPL->site_ids)."') ";
  1169. $xql .= $FNS->sql_andor_string($weblog, 'blog_name');
  1170. $query = $DB->query($xql);
  1171. if ($query->num_rows == 0)
  1172. {
  1173. return false;
  1174. }
  1175. elseif ($query->num_rows == 1)
  1176. {
  1177. $sql .= "AND exp_weblog_titles.weblog_id = '".$query->row['weblog_id']."' ";
  1178. }
  1179. else
  1180. {
  1181. $sql .= "AND (";
  1182. foreach ($query->result as $row)
  1183. {
  1184. $sql .= "exp_weblog_titles.weblog_id = '".$row['weblog_id']."' OR ";
  1185. }
  1186. $sql = substr($sql, 0, - 3);
  1187. $sql .= ") ";
  1188. }
  1189. }
  1190. $query = $DB->query($sql);
  1191. if ($query->num_rows == 0)
  1192. {
  1193. return false;
  1194. }
  1195. if ($query->row['allow_comments'] == 'n…

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