PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  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' || $query->row['comment_system_enabled'] == 'n')
  1196. {
  1197. $LANG->fetch_language_file('comment');
  1198. return $LANG->line('cmt_commenting_has_expired');
  1199. }
  1200. /** ----------------------------------------
  1201. /** Return the "no cache" version of the form
  1202. /** ----------------------------------------*/
  1203. if ($return_form == FALSE)
  1204. {
  1205. if ($query->row['comment_use_captcha'] == 'n')
  1206. {
  1207. $TMPL->tagdata = str_replace(LD.'captcha'.RD, '', $TMPL->tagdata);
  1208. }
  1209. $nc = '';
  1210. if (is_array($TMPL->tagparams) AND count($TMPL->tagparams) > 0)
  1211. {
  1212. foreach ($TMPL->tagparams as $key => $val)
  1213. {
  1214. $nc .= ' '.$key.'="'.$val.'" ';
  1215. }
  1216. }
  1217. return '{NOCACHE_COMMENT_FORM="'.$nc.'"}'.$TMPL->tagdata.'{/NOCACHE_FORM}';
  1218. }
  1219. /** ----------------------------------------
  1220. /** Has commenting expired?
  1221. /** ----------------------------------------*/
  1222. $mode = ( ! isset($this->comment_expiration_mode)) ? 0 : $this->comment_expiration_mode;
  1223. if ($mode == 0)
  1224. {
  1225. if ($query->row['comment_expiration_date'] > 0)
  1226. {
  1227. if ($LOC->now > $query->row['comment_expiration_date'])
  1228. {
  1229. $LANG->fetch_language_file('comment');
  1230. return $LANG->line('cmt_commenting_has_expired');
  1231. }
  1232. }
  1233. }
  1234. else
  1235. {
  1236. if ($query->row['comment_expiration'] > 0)
  1237. {
  1238. $days = $query->row['entry_date'] + ($query->row['comment_expiration'] * 86400);
  1239. if ($LOC->now > $days)
  1240. {
  1241. $LANG->fetch_language_file('comment');
  1242. return $LANG->line('cmt_commenting_has_expired');
  1243. }
  1244. }
  1245. }
  1246. $tagdata = $TMPL->tagdata;
  1247. // -------------------------------------------
  1248. // 'comment_form_tagdata' hook.
  1249. // - Modify, add, etc. something to the comment form
  1250. //
  1251. if ($EXT->active_hook('comment_form_tagdata') === TRUE)
  1252. {
  1253. $tagdata = $EXT->call_extension('comment_form_tagdata', $tagdata);
  1254. if ($EXT->end_script === TRUE) return;
  1255. }
  1256. //
  1257. // -------------------------------------------
  1258. /** ----------------------------------------
  1259. /** Conditionals
  1260. /** ----------------------------------------*/
  1261. $cond = array();
  1262. $cond['logged_in'] = ($SESS->userdata('member_id') == 0) ? 'FALSE' : 'TRUE';
  1263. $cond['logged_out'] = ($SESS->userdata('member_id') != 0) ? 'FALSE' : 'TRUE';
  1264. if ($query->row['comment_use_captcha'] == 'n')
  1265. {
  1266. $cond['captcha'] = 'FALSE';
  1267. }
  1268. elseif ($query->row['comment_use_captcha'] == 'y')
  1269. {
  1270. $cond['captcha'] = ($PREFS->ini('captcha_require_members') == 'y' ||
  1271. ($PREFS->ini('captcha_require_members') == 'n' AND $SESS->userdata('member_id') == 0)) ? 'TRUE' : 'FALSE';
  1272. }
  1273. $tagdata = $FNS->prep_conditionals($tagdata, $cond);
  1274. /** ----------------------------------------
  1275. /** Single Variables
  1276. /** ----------------------------------------*/
  1277. foreach ($TMPL->var_single as $key => $val)
  1278. {
  1279. /** ----------------------------------------
  1280. /** parse {name}
  1281. /** ----------------------------------------*/
  1282. if ($key == 'name')
  1283. {
  1284. $name = ($SESS->userdata['screen_name'] != '') ? $SESS->userdata['screen_name'] : $SESS->userdata['username'];
  1285. $name = ( ! isset($_POST['name'])) ? $name : $_POST['name'];
  1286. $tagdata = $TMPL->swap_var_single($key, $REGX->form_prep($name), $tagdata);
  1287. }
  1288. /** ----------------------------------------
  1289. /** parse {email}
  1290. /** ----------------------------------------*/
  1291. if ($key == 'email')
  1292. {
  1293. $email = ( ! isset($_POST['email'])) ? $SESS->userdata['email'] : $_POST['email'];
  1294. $tagdata = $TMPL->swap_var_single($key, $REGX->form_prep($email), $tagdata);
  1295. }
  1296. /** ----------------------------------------
  1297. /** parse {url}
  1298. /** ----------------------------------------*/
  1299. if ($key == 'url')
  1300. {
  1301. $url = ( ! isset($_POST['url'])) ? $SESS->userdata['url'] : $_POST['url'];
  1302. if ($url == '')
  1303. $url = 'http://';
  1304. $tagdata = $TMPL->swap_var_single($key, $REGX->form_prep($url), $tagdata);
  1305. }
  1306. /** ----------------------------------------
  1307. /** parse {location}
  1308. /** ----------------------------------------*/
  1309. if ($key == 'location')
  1310. {
  1311. $location = ( ! isset($_POST['location'])) ? $SESS->userdata['location'] : $_POST['location'];
  1312. $tagdata = $TMPL->swap_var_single($key, $REGX->form_prep($location), $tagdata);
  1313. }
  1314. /** ----------------------------------------
  1315. /** parse {comment}
  1316. /** ----------------------------------------*/
  1317. if ($key == 'comment')
  1318. {
  1319. $comment = ( ! isset($_POST['comment'])) ? '' : $_POST['comment'];
  1320. $tagdata = $TMPL->swap_var_single($key, $comment, $tagdata);
  1321. }
  1322. /** ----------------------------------------
  1323. /** parse {captcha_word}
  1324. /** ----------------------------------------*/
  1325. if ($key == 'captcha_word')
  1326. {
  1327. $tagdata = $TMPL->swap_var_single($key, '', $tagdata);
  1328. }
  1329. /** ----------------------------------------
  1330. /** parse {save_info}
  1331. /** ----------------------------------------*/
  1332. if ($key == 'save_info')
  1333. {
  1334. $save_info = ( ! isset($_POST['save_info'])) ? '' : $_POST['save_info'];
  1335. $notify = ( ! isset($SESS->userdata['notify_by_default'])) ? $IN->GBL('save_info', 'COOKIE') : $SESS->userdata['notify_by_default'];
  1336. $checked = ( ! isset($_POST['PRV'])) ? $notify : $save_info;
  1337. $tagdata = $TMPL->swap_var_single($key, ($checked == 'yes') ? "checked=\"checked\"" : '', $tagdata);
  1338. }
  1339. /** ----------------------------------------
  1340. /** parse {notify_me}
  1341. /** ----------------------------------------*/
  1342. if ($key == 'notify_me')
  1343. {
  1344. $checked = '';
  1345. if ( ! isset($_POST['PRV']))
  1346. {
  1347. if ($IN->GBL('notify_me', 'COOKIE'))
  1348. {
  1349. $checked = $IN->GBL('notify_me', 'COOKIE');
  1350. }
  1351. if (isset($SESS->userdata['notify_by_default']))
  1352. {
  1353. $checked = ($SESS->userdata['notify_by_default'] == 'y') ? 'yes' : '';
  1354. }
  1355. }
  1356. if (isset($_POST['notify_me']))
  1357. {
  1358. $checked = $_POST['notify_me'];
  1359. }
  1360. $tagdata = $TMPL->swap_var_single($key, ($checked == 'yes') ? "checked=\"checked\"" : '', $tagdata);
  1361. }
  1362. }
  1363. /** ----------------------------------------
  1364. /** Create form
  1365. /** ----------------------------------------*/
  1366. $RET = (isset($_POST['RET'])) ? $_POST['RET'] : $FNS->fetch_current_uri();
  1367. $PRV = (isset($_POST['PRV'])) ? $_POST['PRV'] : $TMPL->fetch_param('preview');
  1368. $XID = (isset($_POST['XID'])) ? $_POST['XID'] : '';
  1369. $hidden_fields = array(
  1370. 'ACT' => $FNS->fetch_action_id('Comment', 'insert_new_comment'),
  1371. 'RET' => $RET,
  1372. 'URI' => ($IN->URI == '') ? 'index' : $IN->URI,
  1373. 'PRV' => $PRV,
  1374. 'XID' => $XID,
  1375. 'entry_id' => $query->row['entry_id']
  1376. );
  1377. if ($query->row['comment_use_captcha'] == 'y')
  1378. {
  1379. if (preg_match("/({captcha})/", $tagdata))
  1380. {
  1381. $tagdata = preg_replace("/{captcha}/", $FNS->create_captcha(), $tagdata);
  1382. }
  1383. }
  1384. // -------------------------------------------
  1385. // 'comment_form_hidden_fields' hook.
  1386. // - Add/Remove Hidden Fields for Comment Form
  1387. //
  1388. if ($EXT->active_hook('comment_form_hidden_fields') === TRUE)
  1389. {
  1390. $hidden_fields = $EXT->call_extension('comment_form_hidden_fields', $hidden_fields);
  1391. if ($EXT->end_script === TRUE) return;
  1392. }
  1393. //
  1394. // -------------------------------------------
  1395. // -------------------------------------------
  1396. // 'comment_form_action' hook.
  1397. // - Modify action="" attribute for comment form
  1398. // - Added 1.4.2
  1399. //
  1400. if ($EXT->active_hook('comment_form_action') === TRUE)
  1401. {
  1402. $RET = $EXT->call_extension('comment_form_action', $RET);
  1403. if ($EXT->end_script === TRUE) return;
  1404. }
  1405. //
  1406. // -------------------------------------------
  1407. $data = array(
  1408. 'hidden_fields' => $hidden_fields,
  1409. 'action' => $RET,
  1410. 'id' => 'comment_form'
  1411. );
  1412. if ($TMPL->fetch_param('name') !== FALSE &&
  1413. preg_match("#^[a-zA-Z0-9_\-]+$#i", $TMPL->fetch_param('name'), $match))
  1414. {
  1415. $data['name'] = $TMPL->fetch_param('name');
  1416. }
  1417. $res = $FNS->form_declaration($data);
  1418. $res .= stripslashes($tagdata);
  1419. $res .= "</form>";
  1420. // -------------------------------------------
  1421. // 'comment_form_end' hook.
  1422. // - Modify, add, etc. something to the comment form at end of processing
  1423. //
  1424. if ($EXT->active_hook('comment_form_end') === TRUE)
  1425. {
  1426. $res = $EXT->call_extension('comment_form_end', $res);
  1427. if ($EXT->end_script === TRUE) return $res;
  1428. }
  1429. //
  1430. // -------------------------------------------
  1431. return str_replace('&#47;', '/', $res);
  1432. }
  1433. /* END */
  1434. /** ----------------------------------------
  1435. /** Preview
  1436. /** ----------------------------------------*/
  1437. function preview()
  1438. {
  1439. global $IN, $TMPL, $FNS, $DB, $SESS, $LOC, $REGX, $EXT, $LANG, $OUT;
  1440. $entry_id = (isset($_POST['entry_id'])) ? $_POST['entry_id'] : $IN->QSTR;
  1441. if ( ! is_numeric($entry_id) OR empty($_POST['comment']))
  1442. {
  1443. return FALSE;
  1444. }
  1445. /** ----------------------------------------
  1446. /** Instantiate Typography class
  1447. /** ----------------------------------------*/
  1448. if ( ! class_exists('Typography'))
  1449. {
  1450. require PATH_CORE.'core.typography'.EXT;
  1451. }
  1452. $TYPE = new Typography(FALSE, FALSE);
  1453. $TYPE->encode_email = FALSE;
  1454. $sql = "SELECT exp_weblogs.comment_text_formatting, exp_weblogs.comment_html_formatting, exp_weblogs.comment_allow_img_urls, exp_weblogs.comment_auto_link_urls, exp_weblogs.comment_max_chars
  1455. FROM exp_weblogs, exp_weblog_titles
  1456. WHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  1457. AND exp_weblog_titles.entry_id = '".$DB->escape_str($entry_id)."'";
  1458. $query = $DB->query($sql);
  1459. if ($query->num_rows == 0)
  1460. {
  1461. return '';
  1462. }
  1463. /** -------------------------------------
  1464. /** Check size of comment
  1465. /** -------------------------------------*/
  1466. if ($query->row['comment_max_chars'] != '' AND $query->row['comment_max_chars'] != 0)
  1467. {
  1468. if (strlen($_POST['comment']) > $query->row['comment_max_chars'])
  1469. {
  1470. $str = str_replace("%n", strlen($_POST['comment']), $LANG->line('cmt_too_large'));
  1471. $str = str_replace("%x", $query->row['comment_max_chars'], $str);
  1472. return $OUT->show_user_error('submission', $str);
  1473. }
  1474. }
  1475. if ($query->num_rows == '')
  1476. {
  1477. $formatting = 'none';
  1478. }
  1479. else
  1480. {
  1481. $formatting = $query->row['comment_text_formatting'];
  1482. }
  1483. $tagdata = $TMPL->tagdata;
  1484. // -------------------------------------------
  1485. // 'comment_preview_tagdata' hook.
  1486. // - Play with the tagdata contents of the comment preview
  1487. //
  1488. if ($EXT->active_hook('comment_preview_tagdata') === TRUE)
  1489. {
  1490. $tagdata = $EXT->call_extension('comment_preview_tagdata', $tagdata);
  1491. if ($EXT->end_script === TRUE) return;
  1492. }
  1493. //
  1494. // -------------------------------------------
  1495. /** ----------------------------------------
  1496. /** Fetch all the date-related variables
  1497. /** ----------------------------------------*/
  1498. $comment_date = array();
  1499. if (preg_match_all("/".LD."comment_date\s+format=[\"'](.*?)[\"']".RD."/s", $tagdata, $matches))
  1500. {
  1501. for ($j = 0; $j < count($matches['0']); $j++)
  1502. {
  1503. $matches['0'][$j] = str_replace(LD, '', $matches['0'][$j]);
  1504. $matches['0'][$j] = str_replace(RD, '', $matches['0'][$j]);
  1505. $comment_date[$matches['0'][$j]] = $LOC->fetch_date_params($matches['1'][$j]);
  1506. }
  1507. }
  1508. /** ----------------------------------------
  1509. /** Set defaults based on member data as needed
  1510. /** ----------------------------------------*/
  1511. if (isset($_POST['name']) AND $_POST['name'] != '')
  1512. {
  1513. $name = stripslashes($IN->GBL('name', 'POST'));
  1514. }
  1515. elseif ($SESS->userdata['screen_name'] != '')
  1516. {
  1517. $name = $SESS->userdata['screen_name'];
  1518. }
  1519. else
  1520. {
  1521. $name = '';
  1522. }
  1523. foreach (array('email', 'url', 'location') as $v)
  1524. {
  1525. if (isset($_POST[$v]) AND $_POST[$v] != '')
  1526. {
  1527. ${$v} = stripslashes($IN->GBL($v, 'POST'));
  1528. }
  1529. elseif ($SESS->userdata[$v] != '')
  1530. {
  1531. ${$v} = $SESS->userdata[$v];
  1532. }
  1533. else
  1534. {
  1535. ${$v} = '';
  1536. }
  1537. }
  1538. /** ----------------------------------------
  1539. /** Conditionals
  1540. /** ----------------------------------------*/
  1541. $cond = $_POST; // Sanitized on input and also in prep_conditionals, so no real worries here
  1542. $cond['logged_in'] = ($SESS->userdata('member_id') == 0) ? 'FALSE' : 'TRUE';
  1543. $cond['logged_out'] = ($SESS->userdata('member_id') != 0) ? 'FALSE' : 'TRUE';
  1544. $cond['name'] = $name;
  1545. $cond['email'] = $email;
  1546. $cond['url'] = ($url == 'http://') ? '' : $url;
  1547. $cond['location'] = $location;
  1548. $tagdata = $FNS->prep_conditionals($tagdata, $cond);
  1549. /** ----------------------------------------
  1550. /** Single Variables
  1551. /** ----------------------------------------*/
  1552. foreach ($TMPL->var_single as $key => $val)
  1553. {
  1554. /** ----------------------------------------
  1555. /** {name}
  1556. /** ----------------------------------------*/
  1557. if ($key == 'name')
  1558. {
  1559. $tagdata = $TMPL->swap_var_single($key, $name, $tagdata);
  1560. }
  1561. /** ----------------------------------------
  1562. /** {email}
  1563. /** ----------------------------------------*/
  1564. if ($key == 'email')
  1565. {
  1566. $tagdata = $TMPL->swap_var_single($key, $email, $tagdata);
  1567. }
  1568. /** ----------------------------------------
  1569. /** {url}
  1570. /** ----------------------------------------*/
  1571. if ($key == 'url')
  1572. {
  1573. $tagdata = $TMPL->swap_var_single($key, $url, $tagdata);
  1574. }
  1575. /** ----------------------------------------
  1576. /** {location}
  1577. /** ----------------------------------------*/
  1578. if ($key == 'location')
  1579. {
  1580. $tagdata = $TMPL->swap_var_single($key, $location, $tagdata);
  1581. }
  1582. // Prep the URL
  1583. if ($url != '')
  1584. {
  1585. $url = $REGX->prep_url($url);
  1586. }
  1587. /** ----------------------------------------
  1588. /** {url_or_email}
  1589. /** ----------------------------------------*/
  1590. if ($key == "url_or_email")
  1591. {
  1592. $temp = $url;
  1593. if ($temp == '' AND $email != '')
  1594. {
  1595. $temp = $TYPE->encode_email($email, '', 0);
  1596. }
  1597. $tagdata = $TMPL->swap_var_single($val, $temp, $tagdata);
  1598. }
  1599. /** ----------------------------------------
  1600. /** {url_or_email_as_author}
  1601. /** ----------------------------------------*/
  1602. if ($key == "url_or_email_as_author")
  1603. {
  1604. if ($url != '')
  1605. {
  1606. $tagdata = $TMPL->swap_var_single($val, "<a href=\"".$url."\">".$name."</a>", $tagdata);
  1607. }
  1608. else
  1609. {
  1610. if ($email != '')
  1611. {
  1612. $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($email, $name), $tagdata);
  1613. }
  1614. else
  1615. {
  1616. $tagdata = $TMPL->swap_var_single($val, $name, $tagdata);
  1617. }
  1618. }
  1619. }
  1620. /** ----------------------------------------
  1621. /** {url_or_email_as_link}
  1622. /** ----------------------------------------*/
  1623. if ($key == "url_or_email_as_link")
  1624. {
  1625. if ($url != '')
  1626. {
  1627. $tagdata = $TMPL->swap_var_single($val, "<a href=\"".$url."\">".$url."</a>", $tagdata);
  1628. }
  1629. else
  1630. {
  1631. if ($email != '')
  1632. {
  1633. $tagdata = $TMPL->swap_var_single($val, $TYPE->encode_email($email), $tagdata);
  1634. }
  1635. else
  1636. {
  1637. $tagdata = $TMPL->swap_var_single($val, $name, $tagdata);
  1638. }
  1639. }
  1640. }
  1641. /** ----------------------------------------
  1642. /** parse comment field
  1643. /** ----------------------------------------*/
  1644. if ($key == 'comment')
  1645. {
  1646. // -------------------------------------------
  1647. // 'comment_preview_comment_format' hook.
  1648. // - Play with the tagdata contents of the comment preview
  1649. //
  1650. if ($EXT->active_hook('comment_preview_comment_format') === TRUE)
  1651. {
  1652. $data = $EXT->call_extension('comment_preview_comment_format', $query->row);
  1653. if ($EXT->end_script === TRUE) return;
  1654. }
  1655. else
  1656. {
  1657. $data = $TYPE->parse_type( stripslashes($IN->GBL('comment', 'POST')),
  1658. array(
  1659. 'text_format' => $query->row['comment_text_formatting'],
  1660. 'html_format' => $query->row['comment_html_formatting'],
  1661. 'auto_links' => $query->row['comment_auto_link_urls'],
  1662. 'allow_img_url' => $query->row['comment_allow_img_urls']
  1663. )
  1664. );
  1665. }
  1666. //
  1667. // -------------------------------------------
  1668. $tagdata = $TMPL->swap_var_single($key, $data, $tagdata);
  1669. }
  1670. /** ----------------------------------------
  1671. /** parse comment date
  1672. /** ----------------------------------------*/
  1673. if (isset($comment_date[$key]))
  1674. {
  1675. foreach ($comment_date[$key] as $dvar)
  1676. {
  1677. $val = str_replace($dvar, $LOC->convert_timestamp($dvar, $LOC->now, TRUE), $val);
  1678. }
  1679. $tagdata = $TMPL->swap_var_single($key, $val, $tagdata);
  1680. }
  1681. }
  1682. return $tagdata;
  1683. }
  1684. /* END */
  1685. /** ----------------------------------------
  1686. /** Preview handler
  1687. /** ----------------------------------------*/
  1688. function preview_handler()
  1689. {
  1690. global $IN, $OUT, $LANG, $FNS, $REGX;
  1691. if ($IN->GBL('PRV', 'POST') == '')
  1692. {
  1693. $error[] = $LANG->line('cmt_no_preview_template_specified');
  1694. return $OUT->show_user_error('general', $error);
  1695. }
  1696. if ( ! isset($_POST['PRV']) or $_POST['PRV'] == '')
  1697. {
  1698. exit('Preview template not specified in your comment form tag');
  1699. }
  1700. $_POST['PRV'] = $REGX->trim_slashes($REGX->xss_clean($_POST['PRV']));
  1701. $FNS->clear_caching('all', $_POST['PRV']);
  1702. $FNS->clear_caching('all', $_POST['RET']);
  1703. require PATH_CORE.'core.template'.EXT;
  1704. global $TMPL;
  1705. $TMPL = new Template();
  1706. $preview = ( ! $IN->GBL('PRV', 'POST')) ? '' : $IN->GBL('PRV');
  1707. if (strpos($preview, '/') === FALSE)
  1708. {
  1709. $preview = '';
  1710. }
  1711. else
  1712. {
  1713. $ex = explode("/", $preview);
  1714. if (count($ex) != 2)
  1715. {
  1716. $preview = '';
  1717. }
  1718. }
  1719. if ($preview == '')
  1720. {
  1721. $group = 'weblog';
  1722. $templ = 'preview';
  1723. }
  1724. else
  1725. {
  1726. $group = $ex['0'];
  1727. $templ = $ex['1'];
  1728. }
  1729. $TMPL->run_template_engine($group, $templ);
  1730. }
  1731. /* END */
  1732. /** ----------------------------------------
  1733. /** Insert new comment
  1734. /** ----------------------------------------*/
  1735. function insert_new_comment()
  1736. {
  1737. global $IN, $SESS, $PREFS, $DB, $FNS, $OUT, $LANG, $REGX, $LOC, $STAT, $EXT;
  1738. $default = array('name', 'email', 'url', 'comment', 'location', 'entry_id');
  1739. foreach ($default as $val)
  1740. {
  1741. if ( ! isset($_POST[$val]))
  1742. {
  1743. $_POST[$val] = '';
  1744. }
  1745. }
  1746. // No entry ID? What the heck are they doing?
  1747. if ( ! is_numeric($_POST['entry_id']))
  1748. {
  1749. return false;
  1750. }
  1751. // If the comment is empty, bounce them back
  1752. if ($_POST['comment'] == '')
  1753. {
  1754. if ( ! isset($_POST['RET']) OR $_POST['RET'] == '')
  1755. {
  1756. return false;
  1757. }
  1758. $FNS->redirect($_POST['RET']);
  1759. }
  1760. /** ----------------------------------------
  1761. /** Fetch the comment language pack
  1762. /** ----------------------------------------*/
  1763. $LANG->fetch_language_file('comment');
  1764. /** ----------------------------------------
  1765. /** Is the user banned?
  1766. /** ----------------------------------------*/
  1767. if ($SESS->userdata['is_banned'] == TRUE)
  1768. {
  1769. return $OUT->show_user_error('general', array($LANG->line('not_authorized')));
  1770. }
  1771. /** ----------------------------------------
  1772. /** Is the IP address and User Agent required?
  1773. /** ----------------------------------------*/
  1774. if ($PREFS->ini('require_ip_for_posting') == 'y')
  1775. {
  1776. if ($IN->IP == '0.0.0.0' || $SESS->userdata['user_agent'] == "")
  1777. {
  1778. return $OUT->show_user_error('general', array($LANG->line('not_authorized')));
  1779. }
  1780. }
  1781. /** ----------------------------------------
  1782. /** Is the nation of the user banend?
  1783. /** ----------------------------------------*/
  1784. $SESS->nation_ban_check();
  1785. /** ----------------------------------------
  1786. /** Can the user post comments?
  1787. /** ----------------------------------------*/
  1788. if ($SESS->userdata['can_post_comments'] == 'n')
  1789. {
  1790. $error[] = $LANG->line('cmt_no_authorized_for_comments');
  1791. return $OUT->show_user_error('general', $error);
  1792. }
  1793. /** ----------------------------------------
  1794. /** Blacklist/Whitelist Check
  1795. /** ----------------------------------------*/
  1796. if ($IN->blacklisted == 'y' && $IN->whitelisted == 'n')
  1797. {
  1798. return $OUT->show_user_error('general', array($LANG->line('not_authorized')));
  1799. }
  1800. /** ----------------------------------------
  1801. /** Is this a preview request?
  1802. /** ----------------------------------------*/
  1803. if (isset($_POST['preview']))
  1804. {
  1805. return $this->preview_handler();
  1806. }
  1807. // -------------------------------------------
  1808. // 'insert_comment_start' hook.
  1809. // - Allows complete rewrite of comment submission routine.
  1810. // - Or could be used to modify the POST data before processing
  1811. //
  1812. $edata = $EXT->call_extension('insert_comment_start');
  1813. if ($EXT->end_script === TRUE) return;
  1814. //
  1815. // -------------------------------------------
  1816. /** ----------------------------------------
  1817. /** Fetch weblog preferences
  1818. /** ----------------------------------------*/
  1819. $sql = "SELECT exp_weblog_titles.title,
  1820. exp_weblog_titles.url_title,
  1821. exp_weblog_titles.weblog_id,
  1822. exp_weblog_titles.author_id,
  1823. exp_weblog_titles.comment_total,
  1824. exp_weblog_titles.allow_comments,
  1825. exp_weblog_titles.entry_date,
  1826. exp_weblog_titles.comment_expiration_date,
  1827. exp_weblogs.blog_title,
  1828. exp_weblogs.comment_system_enabled,
  1829. exp_weblogs.comment_max_chars,
  1830. exp_weblogs.comment_use_captcha,
  1831. exp_weblogs.comment_timelock,
  1832. exp_weblogs.comment_require_membership,
  1833. exp_weblogs.comment_moderate,
  1834. exp_weblogs.comment_require_email,
  1835. exp_weblogs.comment_notify,
  1836. exp_weblogs.comment_notify_authors,
  1837. exp_weblogs.comment_notify_emails,
  1838. exp_weblogs.comment_expiration
  1839. FROM exp_weblog_titles, exp_weblogs
  1840. WHERE exp_weblog_titles.weblog_id = exp_weblogs.weblog_id
  1841. AND exp_weblog_titles.entry_id = '".$DB->escape_str($_POST['entry_id'])."'
  1842. AND exp_weblog_titles.status != 'closed' ";
  1843. // -------------------------------------------
  1844. // 'insert_comment_preferences_sql' hook.
  1845. // - Rewrite or add to the comment preference sql query
  1846. // - Could be handy for comment/weblog restrictions
  1847. //
  1848. if ($EXT->active_hook('insert_comment_preferences_sql') === TRUE)
  1849. {
  1850. $sql = $EXT->call_extension('insert_comment_preferences_sql', $sql);
  1851. if ($EXT->end_script === TRUE) return $edata;
  1852. }
  1853. //
  1854. // -------------------------------------------
  1855. $query = $DB->query($sql);
  1856. unset($sql);
  1857. if ($query->num_rows == 0)
  1858. {
  1859. return false;
  1860. }
  1861. /** ----------------------------------------
  1862. /** Are comments allowed?
  1863. /** ----------------------------------------*/
  1864. if ($query->row['allow_comments'] == 'n' || $query->row['comment_system_enabled'] == 'n')
  1865. {
  1866. return $OUT->show_user_error('submission', $LANG->line('cmt_comments_not_allowed'));
  1867. }
  1868. /** ----------------------------------------
  1869. /** Has commenting expired?
  1870. /** ----------------------------------------*/
  1871. if ($this->comment_expiration_mode == 0)
  1872. {
  1873. if ($query->row['comment_expiration_date'] > 0)
  1874. {
  1875. if ($LOC->now > $query->row['comment_expiration_date'])
  1876. {
  1877. return $OUT->show_user_error('submission', $LANG->line('cmt_commenting_has_expired'));
  1878. }
  1879. }
  1880. }
  1881. else
  1882. {
  1883. if ($query->row['comment_expiration'] > 0)
  1884. {
  1885. $days = $query->row['entry_date'] + ($query->row['comment_expiration'] * 86400);
  1886. if ($LOC->now > $days)
  1887. {
  1888. return $OUT->show_user_error('submission', $LANG->line('cmt_commenting_has_expired'));
  1889. }
  1890. }
  1891. }
  1892. /** ----------------------------------------
  1893. /** Is there a comment timelock?
  1894. /** ----------------------------------------*/
  1895. if ($query->row['comment_timelock'] != '' AND $query->row['comment_timelock'] > 0)
  1896. {
  1897. if ($SESS->userdata['group_id'] != 1)
  1898. {
  1899. $time = $LOC->now - $query->row['comment_timelock'];
  1900. $result = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE comment_date > '$time' AND ip_address = '$IN->IP' ");
  1901. if ($result->row['count'] > 0)
  1902. {
  1903. return $OUT->show_user_error('submission', str_replace("%s", $query->row['comment_timelock'], $LANG->line('cmt_comments_timelock')));
  1904. }
  1905. }
  1906. }
  1907. /** ----------------------------------------
  1908. /** Do we allow duplicate data?
  1909. /** ----------------------------------------*/
  1910. if ($PREFS->ini('deny_duplicate_data') == 'y')
  1911. {
  1912. if ($SESS->userdata['group_id'] != 1)
  1913. {
  1914. $result = $DB->query("SELECT COUNT(*) AS count FROM exp_comments WHERE comment = '".$DB->escape_str($_POST['comment'])."' ");
  1915. if ($result->row['count'] > 0)
  1916. {
  1917. return $OUT->show_user_error('submission', $LANG->line('cmt_duplicate_comment_warning'));
  1918. }
  1919. }
  1920. }
  1921. /** ----------------------------------------
  1922. /** Assign data
  1923. /** ----------------------------------------*/
  1924. $author_id = $query->row['author_id'];
  1925. $entry_title = $query->row['title'];
  1926. $url_title = $query->row['url_title'];
  1927. $blog_title = $query->row['blog_title'];
  1928. $weblog_id = $query->row['weblog_id'];
  1929. $comment_total = $query->row['comment_total'] + 1;
  1930. $require_membership = $query->row['comment_require_membership'];
  1931. $comment_moderate = ($SESS->userdata['group_id'] == 1 OR $SESS->userdata['exclude_from_moderation'] == 'y') ? 'n' : $query->row['comment_moderate'];
  1932. $author_notify = $query->row['comment_notify_authors'];
  1933. $notify_address = ($query->row['comment_notify'] == 'y' AND $query->row['comment_notify_emails'] != '') ? $query->row['comment_notify_emails'] : '';
  1934. /** ----------------------------------------
  1935. /** Start error trapping
  1936. /** ----------------------------------------*/
  1937. $error = array();
  1938. if ($SESS->userdata('member_id') != 0)
  1939. {
  1940. // If the user is logged in we'll reassign the POST variables with the user data
  1941. $_POST['name'] = ($SESS->userdata['screen_name'] != '') ? $SESS->userdata['screen_name'] : $SESS->userdata['username'];
  1942. $_POST['email'] = $SESS->userdata['email'];
  1943. $_POST['url'] = $SESS->userdata['url'];
  1944. $_POST['location'] = $SESS->userdata['location'];
  1945. }
  1946. /** ----------------------------------------
  1947. /** Is membership is required to post...
  1948. /** ----------------------------------------*/
  1949. if ($require_membership == 'y')
  1950. {
  1951. // Not logged in
  1952. if ($SESS->userdata('member_id') == 0)
  1953. {
  1954. return $OUT->show_user_error('submission', $LANG->line('cmt_must_be_member'));
  1955. }
  1956. // Membership is pending
  1957. if ($SESS->userdata['group_id'] == 4)
  1958. {
  1959. return $OUT->show_user_error('general', $LANG->line('cmt_account_not_active'));
  1960. }
  1961. }
  1962. else
  1963. {
  1964. /** ----------------------------------------
  1965. /** Missing name?
  1966. /** ----------------------------------------*/
  1967. if ($_POST['name'] == '')
  1968. {
  1969. $error[] = $LANG->line('cmt_missing_name');
  1970. }
  1971. /** -------------------------------------
  1972. /** Is name banned?
  1973. /** -------------------------------------*/
  1974. if ($SESS->ban_check('screen_name', $_POST['name']))
  1975. {
  1976. $error[] = $LANG->line('cmt_name_not_allowed');
  1977. }
  1978. /** ----------------------------------------
  1979. /** Missing or invalid email address
  1980. /** ----------------------------------------*/
  1981. if ($query->row['comment_require_email'] == 'y')
  1982. {
  1983. if ($_POST['email'] == '')
  1984. {
  1985. $error[] = $LANG->line('cmt_missing_email');
  1986. }
  1987. elseif ( ! $REGX->valid_email($_POST['email']))
  1988. {
  1989. $error[] = $LANG->line('cmt_invalid_email');
  1990. }
  1991. }
  1992. }
  1993. /** -------------------------------------
  1994. /** Is email banned?
  1995. /** -------------------------------------*/
  1996. if ($_POST['email'] != '')
  1997. {
  1998. if ($SESS->ban_check('email', $_POST['email']))
  1999. {
  2000. $error[] = $LANG->line('cmt_banned_email');
  2001. }
  2002. }
  2003. /** ----------------------------------------
  2004. /** Is comment too big?
  2005. /** ----------------------------------------*/
  2006. if ($query->row['comment_max_chars'] != '' AND $query->row['comment_max_chars'] != 0)
  2007. {
  2008. if (strlen($_POST['comment']) > $query->row['comment_max_chars'])
  2009. {
  2010. $str = str_replace("%n", strlen($_POST['comment']), $LANG->line('cmt_too_large'));
  2011. $str = str_replace("%x", $query->row['comment_max_chars'], $str);
  2012. $error[] = $str;
  2013. }
  2014. }
  2015. /** ----------------------------------------
  2016. /** Do we have errors to display?
  2017. /** ----------------------------------------*/
  2018. if (count($error) > 0)
  2019. {
  2020. return $OUT->show_user_error('submission', $error);
  2021. }
  2022. /** ----------------------------------------
  2023. /** Do we require captcha?
  2024. /** ----------------------------------------*/
  2025. if ($query->row['comment_use_captcha'] == 'y')
  2026. {
  2027. if ($PREFS->ini('captcha_require_members') == 'y' || ($PREFS->ini('captcha_require_members') == 'n' AND $SESS->userdata('member_id') == 0))
  2028. {
  2029. if ( ! isset($_POST['captcha']) || $_POST['captcha'] == '')
  2030. {
  2031. return $OUT->show_user_error('submission', $LANG->line('captcha_required'));
  2032. }
  2033. else
  2034. {
  2035. $res = $DB->query("SELECT COUNT(*) AS count FROM exp_captcha WHERE word='".$DB->escape_str($_POST['captcha'])."' AND ip_address = '".$IN->IP."' AND date > UNIX_TIMESTAMP()-7200");
  2036. if ($res->row['count'] == 0)
  2037. {
  2038. return $OUT->show_user_error('submission', $LANG->line('captcha_incorrect'));
  2039. }
  2040. $DB->query("DELETE FROM exp_captcha WHERE (word='".$DB->escape_str($_POST['captcha'])."' AND ip_address = '".$IN->IP."') OR date < UNIX_TIMESTAMP()-7200");
  2041. }
  2042. }
  2043. }
  2044. /** ----------------------------------------
  2045. /** Build the data array
  2046. /** ----------------------------------------*/
  2047. $notify = ($IN->GBL('notify_me', 'POST')) ? 'y' : 'n';
  2048. $cmtr_name = $REGX->xss_clean($_POST['name']);
  2049. $cmtr_email = $_POST['email'];
  2050. $cmtr_url = $REGX->xss_clean($REGX->prep_url($_POST['url']));
  2051. $cmtr_loc = $REGX->xss_clean($_POST['location']);
  2052. $data = array(
  2053. 'weblog_id' => $weblog_id,
  2054. 'entry_id' => $_POST['entry_id'],
  2055. 'author_id' => $SESS->userdata('member_id'),
  2056. 'name' => $cmtr_name,
  2057. 'email' => $cmtr_email,
  2058. 'url' => $cmtr_url,
  2059. 'location' => $cmtr_loc,
  2060. 'comment' => $REGX->xss_clean($_POST['comment']),
  2061. 'comment_date' => $LOC->now,
  2062. 'ip_address' => $IN->IP,
  2063. 'notify' => $notify,
  2064. 'status' => ($comment_moderate == 'y') ? 'c' : 'o',
  2065. 'site_id' => $PREFS->ini('site_id')
  2066. );
  2067. // -------------------------------------------
  2068. // 'insert_comment_insert_array' hook.
  2069. // - Modify any of the soon to be inserted values
  2070. //
  2071. if ($EXT->active_hook('insert_comment_insert_array') === TRUE)
  2072. {
  2073. $data = $EXT->call_extension('insert_comment_insert_array', $data);
  2074. if ($EXT->end_script === TRUE) return $edata;
  2075. }
  2076. //
  2077. // -------------------------------------------
  2078. /** ----------------------------------------
  2079. /** Insert data
  2080. /** ----------------------------------------*/
  2081. if ($PREFS->ini('secure_forms') == 'y')
  2082. {
  2083. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_security_hashes WHERE hash='".$DB->escape_str($_POST['XID'])."' AND ip_address = '".$IN->IP."' AND date > UNIX_TIMESTAMP()-7200");
  2084. if ($query->row['count'] > 0)
  2085. {
  2086. $sql = $DB->insert_string('exp_comments', $data);
  2087. $DB->query($sql);
  2088. $comment_id = $DB->insert_id;
  2089. $DB->query("DELETE FROM exp_security_hashes WHERE (hash='".$DB->escape_str($_POST['XID'])."' AND ip_address = '".$IN->IP."') OR date < UNIX_TIMESTAMP()-7200");
  2090. }
  2091. else
  2092. {
  2093. $FNS->redirect(stripslashes($_POST['RET']));
  2094. }
  2095. }
  2096. else
  2097. {
  2098. $sql = $DB->insert_string('exp_comments', $data);
  2099. $DB->query($sql);
  2100. $comment_id = $DB->insert_id;
  2101. }
  2102. if ($comment_moderate == 'n')
  2103. {
  2104. /** ------------------------------------------------
  2105. /** Update comment total and "recent comment" date
  2106. /** ------------------------------------------------*/
  2107. $DB->query("UPDATE exp_weblog_titles SET comment_total = '$comment_total', recent_comment_date = '".$LOC->now."' WHERE entry_id = '".$DB->escape_str($_POST['entry_id'])."'");
  2108. /** ----------------------------------------
  2109. /** Update member comment total and date
  2110. /** ----------------------------------------*/
  2111. if ($SESS->userdata('member_id') != 0)
  2112. {
  2113. $query = $DB->query("SELECT total_comments FROM exp_members WHERE member_id = '".$SESS->userdata('member_id')."'");
  2114. $DB->query("UPDATE exp_members SET total_comments = '".($query->row['total_comments'] + 1)."', last_comment_date = '".$LOC->now."' WHERE member_id = '".$SESS->userdata('member_id')."'");
  2115. }
  2116. /** ----------------------------------------
  2117. /** Update comment stats
  2118. /** ----------------------------------------*/
  2119. $STAT->update_comment_stats($weblog_id, $LOC->now);
  2120. /** ----------------------------------------
  2121. /** Fetch email notification addresses
  2122. /** ----------------------------------------*/
  2123. $query = $DB->query("SELECT DISTINCT(email), name, comment_id, author_id FROM exp_comments WHERE status = 'o' AND entry_id = '".$DB->escape_str($_POST['entry_id'])."' AND notify = 'y'");
  2124. $recipients = array();
  2125. if ($query->num_rows > 0)
  2126. {
  2127. foreach ($query->result as $row)
  2128. {
  2129. if ($row['email'] == "" AND $row['author_id'] != 0)
  2130. {
  2131. $result = $DB->query("SELECT email, screen_name FROM exp_members WHERE member_id = '".$DB->escape_str($row['author_id'])."'");
  2132. if ($result->num_rows == 1)
  2133. {
  2134. $recipients[] = array($result->row['email'], $row['comment_id'], $result->row['screen_name']);
  2135. }
  2136. }
  2137. elseif ($row['email'] != "")
  2138. {
  2139. $recipients[] = array($row['email'], $row['comment_id'], $row['name']);
  2140. }
  2141. }
  2142. }
  2143. }
  2144. /** ----------------------------------------
  2145. /** Fetch Author Notification
  2146. /** ----------------------------------------*/
  2147. if ($author_notify == 'y')
  2148. {
  2149. $result = $DB->query("SELECT email FROM exp_members WHERE member_id = '".$DB->escape_str($author_id)."'");
  2150. $notify_address .= ','.$result->row['email'];
  2151. }
  2152. /** ----------------------------------------
  2153. /** Instantiate Typography class
  2154. /** ----------------------------------------*/
  2155. if ( ! class_exists('Typography'))
  2156. {
  2157. require PATH_CORE.'core.typography'.EXT;
  2158. }
  2159. $TYPE = new Typography(FALSE, FALSE);
  2160. $TYPE->smileys = FALSE;
  2161. $comment = $REGX->xss_clean($_POST['comment']);
  2162. $comment = $TYPE->parse_type( $comment,
  2163. array(
  2164. 'text_format' => 'none',
  2165. 'html_format' => 'none',
  2166. 'auto_links' => 'n',
  2167. 'allow_img_url' => 'n'
  2168. )
  2169. );
  2170. /** ----------------------------
  2171. /** Send admin notification
  2172. /** ----------------------------*/
  2173. if ($notify_address != '')
  2174. {
  2175. $swap = array(
  2176. 'name' => $cmtr_name,
  2177. 'name_of_commenter' => $cmtr_name,
  2178. 'email' => $cmtr_email,
  2179. 'url' => $cmtr_url,
  2180. 'location' => $cmtr_loc,
  2181. 'weblog_name' => $blog_title,
  2182. 'entry_title' => $entry_title,
  2183. 'comment_id' => $comment_id,
  2184. 'comment' => $comment,
  2185. 'comment_url' => $FNS->remove_session_id($_POST['RET']),
  2186. 'delete_link' => $PREFS->ini('cp_url').'?S=0&C=edit'.'&M=del_comment_conf'.'&weblog_id='.$weblog_id.'&entry_id='.$_POST['entry_id'].'&comment_id='.$comment_id
  2187. );
  2188. $template = $FNS->fetch_email_template('admin_notify_comment');
  2189. $email_tit = $FNS->var_swap($template['title'], $swap);
  2190. $email_msg = $FNS->var_swap($template['data'], $swap);
  2191. // We don't want to send an admin notification if the person
  2192. // leaving the comment is an admin in the notification list
  2193. if ($_POST['email'] != '')
  2194. {
  2195. if (strpos($notify_address, $_POST['email']) !== FALSE)
  2196. {
  2197. $notify_address = str_replace($_POST['email'], "", $notify_address);
  2198. }
  2199. }
  2200. $notify_address = $REGX->remove_extra_commas($notify_address);
  2201. if ($notify_address != '')
  2202. {
  2203. /** ----------------------------
  2204. /** Send email
  2205. /** ----------------------------*/
  2206. if ( ! class_exists('EEmail'))
  2207. {
  2208. require PATH_CORE.'core.email'.EXT;
  2209. }
  2210. $replyto = ($data['email'] == '') ? $PREFS->ini('webmaster_email') : $data['email'];
  2211. $email = new EEmail;
  2212. $sent = array();
  2213. foreach (explode(',', $notify_address) as $addy)
  2214. {
  2215. if (in_array($addy, $sent)) continue;
  2216. $email->initialize();
  2217. $email->wordwrap = false;
  2218. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  2219. $email->to($addy);
  2220. $email->reply_to($replyto);
  2221. $email->subject($email_tit);
  2222. $email->message($REGX->entities_to_ascii($email_msg));
  2223. $email->Send();
  2224. $sent[] = $addy;
  2225. }
  2226. }
  2227. }
  2228. /** ----------------------------------------
  2229. /** Send user notifications
  2230. /** ----------------------------------------*/
  2231. if ($comment_moderate == 'n')
  2232. {
  2233. $email_msg = '';
  2234. if (count($recipients) > 0)
  2235. {
  2236. $qs = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  2237. $action_id = $FNS->fetch_action_id('Comment_CP', 'delete_comment_notification');
  2238. $swap = array(
  2239. 'name_of_commenter' => $cmtr_name,
  2240. 'weblog_name' => $blog_title,
  2241. 'entry_title' => $entry_title,
  2242. 'site_name' => stripslashes($PREFS->ini('site_name')),
  2243. 'site_url' => $PREFS->ini('site_url'),
  2244. 'comment_url' => $FNS->remove_session_id($_POST['RET']),
  2245. 'comment_id' => $comment_id,
  2246. 'comment' => $comment
  2247. );
  2248. $template = $FNS->fetch_email_template('comment_notification');
  2249. $email_tit = $FNS->var_swap($template['title'], $swap);
  2250. $email_msg = $FNS->var_swap($template['data'], $swap);
  2251. /** ----------------------------
  2252. /** Send email
  2253. /** ----------------------------*/
  2254. if ( ! class_exists('EEmail'))
  2255. {
  2256. require PATH_CORE.'core.email'.EXT;
  2257. }
  2258. $email = new EEmail;
  2259. $email->wordwrap = true;
  2260. $cur_email = ($_POST['email'] == '') ? FALSE : $_POST['email'];
  2261. if ( ! isset($sent)) $sent = array();
  2262. foreach ($recipients as $val)
  2263. {
  2264. // We don't notify the person currently commenting. That would be silly.
  2265. if ($val['0'] != $cur_email AND ! in_array($val['0'], $sent))
  2266. {
  2267. $title = $email_tit;
  2268. $message = $email_msg;
  2269. $title = str_replace('{name_of_recipient}', $val['2'], $title);
  2270. $message = str_replace('{name_of_recipient}', $val['2'], $message);
  2271. $title = str_replace('{notification_removal_url}', $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$val['1'], $title);
  2272. $message = str_replace('{notification_removal_url}', $FNS->fetch_site_index(0, 0).$qs.'ACT='.$action_id.'&id='.$val['1'], $message);
  2273. $email->initialize();
  2274. $email->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));
  2275. $email->to($val['0']);
  2276. $email->subject($title);
  2277. $email->message($REGX->entities_to_ascii($message));
  2278. $email->Send();
  2279. $sent[] = $val['0'];
  2280. }
  2281. }
  2282. }
  2283. /** ----------------------------------------
  2284. /** Clear cache files
  2285. /** ----------------------------------------*/
  2286. $FNS->clear_caching('all', $FNS->fetch_site_index().$_POST['URI']);
  2287. // clear out the entry_id version if the url_title is in the URI, and vice versa
  2288. if (preg_match("#\/".preg_quote($url_title)."\/#", $_POST['URI'], $matches))
  2289. {
  2290. $FNS->clear_caching('all', $FNS->fetch_site_index().preg_replace("#".preg_quote($matches['0'])."#", "/{$data['entry_id']}/", $_POST['URI']));
  2291. }
  2292. else
  2293. {
  2294. $FNS->clear_caching('all', $FNS->fetch_site_index().preg_replace("#{$data['entry_id']}#", $url_title, $_POST['URI']));
  2295. }
  2296. }
  2297. /** ----------------------------------------
  2298. /** Set cookies
  2299. /** ----------------------------------------*/
  2300. if ($notify == 'y')
  2301. {
  2302. $FNS->set_cookie('notify_me', 'yes', 60*60*24*365);
  2303. }
  2304. else
  2305. {
  2306. $FNS->set_cookie('notify_me', 'no', 60*60*24*365);
  2307. }
  2308. if ($IN->GBL('save_info', 'POST'))
  2309. {
  2310. $FNS->set_cookie('save_info', 'yes', 60*60*24*365);
  2311. $FNS->set_cookie('my_name', $_POST['name'], 60*60*24*365);
  2312. $FNS->set_cookie('my_email', $_POST['email'], 60*60*24*365);
  2313. $FNS->set_cookie('my_url', $_POST['url'], 60*60*24*365);
  2314. $FNS->set_cookie('my_location', $_POST['location'], 60*60*24*365);
  2315. }
  2316. else
  2317. {
  2318. $FNS->set_cookie('save_info', 'no', 60*60*24*365);
  2319. $FNS->set_cookie('my_name', '');
  2320. $FNS->set_cookie('my_email', '');
  2321. $FNS->set_cookie('my_url', '');
  2322. $FNS->set_cookie('my_location', '');
  2323. }
  2324. // -------------------------------------------
  2325. // 'insert_comment_end' hook.
  2326. // - More emails, more processing, different redirect
  2327. // - $comment_id added 1.6.1
  2328. //
  2329. $edata = $EXT->call_extension('insert_comment_end', $data, $comment_moderate, $comment_id);
  2330. if ($EXT->end_script === TRUE) return;
  2331. //
  2332. // -------------------------------------------
  2333. /** -------------------------------------------
  2334. /** Bounce user back to the comment page
  2335. /** -------------------------------------------*/
  2336. if ($comment_moderate == 'y')
  2337. {
  2338. $data = array( 'title' => $LANG->line('cmt_comment_accepted'),
  2339. 'heading' => $LANG->line('thank_you'),
  2340. 'content' => $LANG->line('cmt_will_be_reviewed'),
  2341. 'redirect' => $_POST['RET'],
  2342. 'link' => array($_POST['RET'], $LANG->line('cmt_return_to_comments')),
  2343. 'rate' => 3
  2344. );
  2345. $OUT->show_message($data);
  2346. }
  2347. else
  2348. {
  2349. $FNS->redirect($_POST['RET']);
  2350. }
  2351. }
  2352. /* END */
  2353. }
  2354. // END CLASS
  2355. ?>