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

/components/com_jomcomment/main.jomcomment.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1401 lines | 960 code | 250 blank | 191 comment | 167 complexity | 8d7850bb026e686a5842f91e39bc0444 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * Jom Comment
  4. * @package JomComment
  5. * @copyright (C) 2006 by Azrul Rahim - All rights reserved!
  6. * @license Copyrighted Commercial Software
  7. **/
  8. (defined('_VALID_MOS') OR defined('_JEXEC')) or die('Direct Access to this location is not allowed.');
  9. if (defined('_JC_MAINFRAME_CLASS')) {
  10. return;
  11. } else {
  12. define('_JC_MAINFRAME_CLASS', 1);
  13. }
  14. global $_JOMCOMMENT, $_JC_CONFIG, $_JC_UTF8;
  15. // Include our custom cmslib
  16. if(!defined('CMSLIB_DEFINED'))
  17. include_once ((dirname(dirname(dirname(__FILE__)))). '/components/libraries/cmslib/spframework.php');
  18. $cms = & cmsInstance('CMSCore');
  19. // Include all core files
  20. include_once ($cms->get_path('root') . '/components/com_jomcomment/defines.jomcomment.php');
  21. // Include helper files
  22. include_once(JC_HELPER_PATH . '/comments.helper.php');
  23. include_once(JC_HELPER_PATH . '/minimal.helper.php');
  24. include_once (JC_CONFIG);
  25. include_once (JC_COM_PATH . '/class.templates.php');
  26. include_once (JC_COM_PATH . '/class.encoding.php');
  27. include_once (JC_COM_PATH . '/functions.jomcomment.php');
  28. /**
  29. * Main controller class
  30. */
  31. class JCMainFrame
  32. {
  33. var $_language = null;
  34. var $_utf8 = null;
  35. var $_viewMgr = null;
  36. var $_dataMgr = null;
  37. var $db = null;
  38. var $cms = null;
  39. var $cfg = null;
  40. /**
  41. * Constructor
  42. */
  43. function JCMainFrame() {
  44. global $_JC_CONFIG;
  45. include_once (JC_COM_PATH . '/datamanager.jomcomment.php');
  46. include_once (JC_COM_PATH . '/views.jomcomment.php');
  47. include_once (JC_ADMIN_COM_PATH . '/config.jomcomment.php');
  48. # load the config
  49. $this->_config = new StdClass();
  50. # set up utf8 object
  51. $this->_utf8 = new Utf8Helper();
  52. # set up data manager
  53. $this->_dataMgr = new JCDataManager();
  54. # set up view manager
  55. $this->_viewMgr = new JCView();
  56. $this->db = &cmsInstance('CMSDb');
  57. $this->cms = &cmsInstance('CMSCore');
  58. $this->cfg = $_JC_CONFIG;
  59. }
  60. function getCommentContainer() {
  61. }
  62. # Return the formatted comments list
  63. function getHTML($cid, $option, & $contentObj) {
  64. $this->cms->load('libraries', 'input');
  65. $page = $this->cms->input->get('cpage', 0);
  66. $count = jcCountComment($cid, $option);
  67. $data = $this->_dataMgr->getAll($cid, $option,$count,$page);
  68. $html = $this->_viewMgr->prepAll($data, $cid, $option, $contentObj);
  69. unset($data);
  70. return $html;
  71. }
  72. function tbGetHTML($cid, $option) {
  73. $data = $this->_dataMgr->tbGetAll($cid, $option);
  74. $html = $this->_viewMgr->tbPrepAll($data, $cid, $option);
  75. return $html;
  76. }
  77. /**
  78. * Return the name of current template.
  79. * Just a special version of config.
  80. */
  81. function getTemplate() {
  82. global $_JC_CONFIG;
  83. return $_JC_CONFIG->get('template');
  84. }
  85. function getSecurityImg($sid) {
  86. }
  87. /**
  88. * Return a unique 32 character unique id
  89. */
  90. function getSid($len = 12) {
  91. $token = md5(uniqid('a'));
  92. $sid = md5(uniqid(rand(), true));
  93. $ret = "";
  94. for($i = 0; $i < $len; $i++){
  95. $ret .= substr($sid, rand(1, ($len-1)), 1 );
  96. }
  97. return $ret;
  98. }
  99. /**
  100. * Need to notify admin and give link to publish/unpublish the comment
  101. */
  102. function notifyAdmin($data) {
  103. global $mainframe, $_JC_CONFIG;
  104. $this->cms->load('helper','url');
  105. # Must make sure that the emai is valid, otherwise, do not send the
  106. # email
  107. $email = $_JC_CONFIG->get('notifyEmail');
  108. //$regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
  109. //if(!empty($email) && eregi($regexp, $email)){
  110. $sid = $this->getSid();
  111. $date = strftime("%Y-%m-%d %H:%M:%S", time() + ($mainframe->getCfg('offset') * 60 * 60));
  112. $this->db->query("DELETE FROM #__jomcomment_admin WHERE sid='$sid'");
  113. $this->db->query("INSERT INTO #__jomcomment_admin "
  114. . "\n SET sid='$sid', action='moderate', commentid='{$data->id}', date='$date'");
  115. // ON DUPLICATE KEY UPDATE date='$date' : removed since it only works on mysql > 4.1
  116. $subject = "New comment added. ";
  117. if (!$data->published)
  118. $subject .= "Moderator approval required.";
  119. $publishLink = cmsSefAmpReplace("index.php?option=com_jomcomment&task=jomadmin&sid=$sid&do=publish", false);
  120. $unpublishLink = cmsSefAmpReplace("index.php?option=com_jomcomment&task=jomadmin&sid=$sid&do=unpublish", false);
  121. $deleteLink = cmsSefAmpReplace("index.php?option=com_jomcomment&task=jomadmin&sid=$sid&do=delete", false);
  122. if(isset($_SERVER['HTTP_REFERER'])){
  123. $link = $_SERVER['HTTP_REFERER'];
  124. }
  125. // Check if the option is com_comprofiler as we do not want to send the wrong titles.
  126. if( $data->option == 'com_comprofiler' ){
  127. $contentTitle = JCView::_translateTemplate('_JC_TPL_CBMAILTITLE') . ' ' . jcGetAuthorName($data->contentid);
  128. } else {
  129. $contentTitle = jcContentTitle($data->contentid);
  130. }
  131. $comment = jcTextwrap($data->comment);
  132. #Check if mambots/system/pc_includes/template.php was included.
  133. if(!defined('AzrulJXTemplate')){
  134. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  135. }
  136. $tpl = new AzrulJXTemplate();
  137. if(!$data->published){
  138. // Comment is not published.
  139. $emailMsg = $tpl->fetch(JC_COM_PATH . '/templates/admin/mail.approve.html');
  140. } else {
  141. // Comment is published.
  142. $emailMsg = $tpl->fetch(JC_COM_PATH . '/templates/admin/mail.notice.html');
  143. }
  144. $emailMsg = str_replace('%PUBLISH%', $publishLink, $emailMsg);
  145. $emailMsg = str_replace('%UNPUBLISH%', $unpublishLink, $emailMsg);
  146. $emailMsg = str_replace('%DELETE%', $deleteLink, $emailMsg);
  147. $emailMsg = str_replace('%CONTENTTITLE%', $contentTitle, $emailMsg);
  148. $emailMsg = str_replace('%COMMENTTITLE%', $data->title, $emailMsg);
  149. $emailMsg = str_replace('%NAME%', $data->name, $emailMsg);
  150. $emailMsg = str_replace('%EMAIL%', $data->email, $emailMsg);
  151. $emailMsg = str_replace('%LINK%', $link, $emailMsg);
  152. $emailMsg = str_replace('%COMMENT%', $data->comment, $emailMsg);
  153. // Set mail properties.
  154. $mode = 0;
  155. $cc = NULL;
  156. $bcc = NULL;
  157. $attachment = NULL;
  158. $replyto = NULL;
  159. $replytoname = NULL;
  160. if($data->email)
  161. $replyto = $data->email;
  162. if($data->name)
  163. $replytoname = $data->name;
  164. // Check if there is a comma in the email so we can split it and send the mails.
  165. $emails = explode(',', $email);
  166. jomMail($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'), $emails, $subject, $emailMsg, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
  167. //}
  168. }
  169. # Test if the given section id is part of our valid sections
  170. # This is now, more appropriately, should be called valid category
  171. function validCategory($sectionid) {
  172. global $_JC_CONFIG;
  173. $valid = true;
  174. # 1. section 1024 is all valid
  175. if ($sectionid == 1024)
  176. return true;
  177. # 2. if we don't limit on section, it's valid
  178. #if(!$_JC_CONFIG->get('limitSection'))
  179. # return true;
  180. # 3. Check if static content needs comment as well.
  181. if ($_JC_CONFIG->get('staticContent') && $sectionid == 0)
  182. return true;
  183. # 4. If we limit on section, make sure it is there.
  184. $categories = explode(",", $_JC_CONFIG->get('categories'));
  185. return in_array($sectionid, $categories);
  186. }
  187. /**
  188. * Process click from admin's email
  189. */
  190. function processAdminTask() {
  191. }
  192. /**
  193. * Given the name, email and website, we simply return all of it back, with
  194. * updates name and email if user is currently logged in
  195. */
  196. function ajaxLoadUserInfo($name, $email, $website) {
  197. global $_JC_CONFIG, $mainframe;
  198. $this->cms->load('libraries','user');
  199. while (@ ob_end_clean());
  200. ob_start();
  201. if (!isset ($name))
  202. $name = "";
  203. if (!isset ($email))
  204. $email = "";
  205. if (!isset ($website))
  206. $website = "";
  207. if (is_array($name))
  208. $name = "";
  209. if (is_array($email))
  210. $email = "";
  211. if (is_array($website))
  212. $website = "";
  213. if ($this->cms->user->name) {
  214. $name = $this->cms->user->name;
  215. $email = $this->cms->user->email;
  216. # name is all but in utf-8 encoding. We need to convert this to utf8
  217. if (function_exists('mb_convert_encoding') && @ (_ISO)) {
  218. $iso = explode('=', _ISO);
  219. $name = mb_convert_encoding($name, "UTF-8", $iso[1]);
  220. }
  221. }
  222. $objResponse = new JAXResponse();
  223. $objResponse->addAssign('jc_name', 'value', strval($name));
  224. $objResponse->addAssign('jc_email', 'value', strval($email));
  225. $objResponse->addAssign('jc_website', 'value', strval($website));
  226. // Need to load new security code picture as well
  227. if ($_JC_CONFIG->get('useCaptcha') AND $mainframe->getCfg('caching')) {
  228. $sidNew = $this->getSid();
  229. // Use absolute path instead
  230. $resultCaptchaImg = $this->cms->get_path('live') . "/index2.php?option=com_jomcomment&no_html=1&task=img&jc_sid=$sidNew";
  231. $resultCaptchaSid = $sidNew;
  232. $objResponse->addAssign('jc_captchaImg', 'src', $resultCaptchaImg);
  233. $objResponse->addAssign('jc_sid', 'value', $resultCaptchaSid);
  234. }
  235. return $objResponse->sendResponse();
  236. }
  237. /**
  238. * Some code that need to be attached to the page <head> section.
  239. * There is no need to add this code if the user opt to.
  240. */
  241. function addCustomHeader() {
  242. global $mainframe, $option, $_JC_CONFIG;
  243. if (!$this->requireHeaderScript())
  244. return;
  245. $jsscript = "";
  246. $style = $_JC_CONFIG->get('template') . "/comment_style.css";
  247. if (@ strpos($style, ".html")) {
  248. $style = substr($_JC_CONFIG->get('template'), 0, -5) . "/comment_style.css";
  249. }
  250. $jsscript .= '<link rel="stylesheet" type="text/css" href="'.JC_COM_LIVEPATH.'/style.css"/>' . "\n";
  251. $jsscript .= '<link rel="stylesheet" type="text/css" href="'.JC_COM_LIVEPATH.'/templates/' . $style . '"/>' . "\n";
  252. //$jsscript .= $this->addCustomScript();
  253. $jsscript = jcFixLiveSiteUrl($jsscript);
  254. $mainframe->addCustomHeadTag($jsscript);
  255. return;
  256. }
  257. /**
  258. * Add a new comment
  259. */
  260. function ajaxAddComment($xajaxArgs) {
  261. ini_set('display_errors',1);
  262. error_reporting(E_ALL);
  263. global $_JC_CONFIG, $mainframe;
  264. $this->cms->load('libraries','user');
  265. $this->cms->load('libraries', 'input');
  266. include_once (JC_COM_PATH.'/spamfilter.jomcomment.php');
  267. $language = jcGetLanguage();
  268. include_once(JC_LANGUAGE_PATH . '/' . $language);
  269. //$ob_active = ob_get_length() !== FALSE;
  270. if (ob_get_length() !== FALSE || ob_get_length() > 0) {
  271. while (@ ob_end_clean());
  272. if (function_exists('ob_clean')) {
  273. @ ob_clean();
  274. }
  275. }
  276. $view = new JCView();
  277. $this->cms->load('libraries', 'user');
  278. ob_start();
  279. $emailAdmin = $_JC_CONFIG->get('notifyAdmin');
  280. $objResponse = new JAXResponse();
  281. $responseMsg = "";
  282. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_MESSAGE_ADDED);
  283. $status = JC_STATUS_OK;
  284. # create a new comment object
  285. $data = $this->_dataMgr->create($xajaxArgs);
  286. if ($data == null) {
  287. # If 'create' fail, there could be some missing info or data not validated
  288. $resultMsg = $this->_dataMgr->getCreateError();
  289. $status = JC_STATUS_WARNING;
  290. }
  291. # apply filters
  292. if ($status == JC_STATUS_OK) {
  293. $filter = new JCSpamFilter($data, $objResponse);
  294. if ($filter->isSpam()) {
  295. $resultMsg = $filter->getErrorMsg();
  296. $status = JC_STATUS_WARNING;
  297. }
  298. }
  299. if (!class_exists('HTML_BBCodeParser') AND !function_exists('BBCode')) {
  300. include_once (JC_COM_PATH . "/bbcode.php");
  301. }
  302. # @rule: For com_content, do not add the comment if the content are unpublished
  303. if($data->option == 'com_content'){
  304. if(jcContentPublished($data->contentid) != 1){
  305. $resultMsg = "Cannot add comment to unpublished content";
  306. $status = JC_STATUS_WARNING;
  307. }
  308. }
  309. # @rule: hard limit on the number of comment per 30 minutes by the same IP
  310. # we block it's IP automatically. and inform admin
  311. $numcommentByIp = $this->_dataMgr->getNumCommentByIP($data->ip, $data->date);
  312. if (($status == JC_STATUS_OK) AND ($numcommentByIp > 20)) {
  313. $_JC_CONFIG->addBlockedIP($data->ip);
  314. $status = JC_STATUS_WARNING;
  315. $resultMsg = preg_replace("/{INTERVAL}/i",$_JC_CONFIG->get('postInterval'), $this->_utf8->utf8ToHtmlEntities(_JC_TPL_REPOST_WARNING));
  316. }
  317. # @rule: block SPAM flood
  318. if ($_JC_CONFIG->get('postInterval') AND ($status == JC_STATUS_OK)) {
  319. if ($this->_dataMgr->getFlood($data->name, $data->ip, $data->date, $_JC_CONFIG->get('postInterval'))) {
  320. $status = JC_STATUS_WARNING;
  321. $resultMsg = preg_replace("/{INTERVAL}/i",$_JC_CONFIG->get('postInterval'), $this->_utf8->utf8ToHtmlEntities(_JC_TPL_REPOST_WARNING));
  322. }
  323. }
  324. # @rule : minimum comment length
  325. if ($_JC_CONFIG->get('commentMinLen') AND ($status == JC_STATUS_OK)) {
  326. $tmp = BBCode($data->comment);
  327. $tmp = strip_tags($tmp);
  328. if ($this->_utf8->strlen($tmp) < intval(trim($_JC_CONFIG->get('commentMinLen')))) {
  329. $status = JC_STATUS_WARNING;
  330. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_TPL_TOO_SHORT);
  331. }
  332. }
  333. # @rule : maximum comment length
  334. if (($status == JC_STATUS_OK) AND $_JC_CONFIG->get('commentMaxLen')) {
  335. // Strip HTML tags before checking length.
  336. if ($this->_utf8->strlen($data->comment) > intval($_JC_CONFIG->get('commentMaxLen'))) {
  337. $status = JC_STATUS_WARNING;
  338. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_TPL_TOO_LONG);
  339. }
  340. }
  341. # Check if user agreed to the terms.
  342. if(($status == JC_STATUS_OK) AND $_JC_CONFIG->get('showTerms')){
  343. if(!isset($data->jc_agree) || empty($data->jc_agree)){
  344. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_TPL_TERMS_WARNING);
  345. $status = JC_STATUS_WARNING;
  346. $objResponse->addAssign('err_jc_agree', 'innerHTML', '*');
  347. } else {
  348. $objResponse->addAssign('err_jc_agree', 'innerHTML', '');
  349. }
  350. }
  351. # @rule: duplicate entry
  352. if (($status == JC_STATUS_OK) AND $this->_dataMgr->searchSimilarComments($data->contentid, $data->comment, $data->date)) {
  353. $status = JC_STATUS_WARNING;
  354. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_TPL_DUPLICATE);
  355. }
  356. # @rule: match re-captcha image
  357. if($_JC_CONFIG->get('useRecaptcha') && ($status == JC_STATUS_OK)){
  358. include_once($this->cms->get_path('root') . '/components/com_jomcomment/includes/recaptcha.php');
  359. $response = recaptcha_check_answer($_JC_CONFIG->get('recaptchaPrivateKey'),
  360. $_SERVER["REMOTE_ADDR"], $data->_recaptchaChallange,
  361. $data->_recaptchaResponse);
  362. if(!$response->is_valid){
  363. $status = JC_STATUS_WARNING;
  364. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_RECAPTCHA_MISMATCH);
  365. }
  366. }
  367. # @rule: password must be correct,
  368. if ($_JC_CONFIG->get('useCaptcha') AND ($status == JC_STATUS_OK)) {
  369. $isOk = false;
  370. if (!$_JC_CONFIG->get('useCaptchaRegistered') AND $this->cms->user->username) {
  371. $isOk = true;
  372. } else {
  373. $secCode = $this->_dataMgr->getPassword($data->_sid);
  374. $isOk = (isset ($secCode) AND (strval($secCode) == strval($data->_password)));
  375. $this->_dataMgr->deletePassword($data->_sid);
  376. }
  377. if (!$isOk) {
  378. $status = JC_STATUS_WARNING;
  379. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_CAPTCHA_MISMATCH);
  380. }
  381. }
  382. # xss filter
  383. $data->comment = $this->cms->input->xss_clean($data->comment);
  384. // Set current page. Since this is an ajax call, we can use
  385. // HTTP_REFERER as this would be called from the current page.
  386. $data->referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
  387. # store the new comment into database
  388. if ($status == JC_STATUS_OK) {
  389. $data->store();
  390. }
  391. #Get the list of subscribers and insert a row in the mailq table.
  392. if($status == JC_STATUS_OK){
  393. # Get all the subscriber for this particular content
  394. $strSQL = "SELECT * FROM #__jomcomment_subs WHERE `contentid`='{$data->contentid}'";
  395. $this->cms->db->query($strSQL);
  396. $rows = $this->cms->db->get_object_list();
  397. $articleName = '';
  398. # For content/myblog we can get the article title
  399. if($data->option == 'com_content' || $data->option == 'com_myblog'){
  400. $strSQL = "SELECT `title` FROM #__content WHERE `id`='{$data->contentid}'";
  401. $this->cms->db->query($strSQL);
  402. $articleName = $this->cms->db->get_value();
  403. }
  404. else{
  405. #Unknown component
  406. }
  407. #Get the referer url
  408. $urlreferer = isset ($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : "";
  409. $urlreferer .= '#comment-' . $data->id;
  410. #Check if mambots/system/pc_includes/template.php was included.
  411. if(!defined('AzrulJXTemplate')){
  412. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  413. }
  414. $tpl = new AzrulJXTemplate();
  415. // Comment is not published.
  416. $emailMsg = $tpl->fetch(JC_COM_PATH . '/templates/admin/subscribe.mail.html');
  417. $emailMsg = str_replace('%LINK%', $urlreferer, $emailMsg);
  418. $emailMsg = str_replace('%COMMENT%', $data->comment, $emailMsg);
  419. if($rows){
  420. #There is already subscribers
  421. foreach($rows as $row){
  422. $insertData = array(
  423. 'email' => $row->email,
  424. 'commentid' => $data->id,
  425. 'status' => 0, #not yet send?
  426. 'title' => 'Comment replied for article: ' . $articleName,
  427. 'name' => $row->name,
  428. 'content' => $emailMsg,
  429. 'posted_on' => $data->date
  430. );
  431. $this->cms->db->insert('#__jomcomment_mailq',$insertData);
  432. }
  433. }else{
  434. #No subscribers
  435. }
  436. }
  437. $subscribed = false;
  438. # Save in subscription table?
  439. if ($status == JC_STATUS_OK && ($data->_subscribe) && $this->cms->user->id){
  440. #Check if user has already subscribed previously with this contentid
  441. $strSQL = "SELECT COUNT(*) FROM #__jomcomment_subs "
  442. . "WHERE userid='". $this->cms->user->id . "' "
  443. . "AND contentid='$data->contentid'";
  444. $this->cms->db->query($strSQL);
  445. if($this->cms->db->get_value() <= 0){
  446. #User has not subscribed before for this content
  447. $insertData = array('userid' => $this->cms->user->id,
  448. 'contentid' => $data->contentid,
  449. 'option' => $data->option,
  450. 'status' => '1',
  451. 'email' => $data->email,
  452. 'name' => $data->name
  453. );
  454. #Insert into subscription table
  455. $this->cms->db->insert('#__jomcomment_subs', $insertData);
  456. $subscribed = true;
  457. }
  458. }
  459. # check if we need to unpublish it
  460. if ($status == JC_STATUS_OK) {
  461. # @unpublish rule: unpublish if necesary
  462. if (!$_JC_CONFIG->get('autoPublish')) {
  463. $this->_dataMgr->unpublish($data->id);
  464. $data->published = 0;
  465. $status = JC_STATUS_BLOCKED;
  466. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_MESSAGE_NEED_MOD);
  467. }
  468. # @unpublish rule: moderate guest post
  469. if (($status == JC_STATUS_OK) AND $_JC_CONFIG->get('modGuest') AND !$this->cms->user->username) {
  470. $this->_dataMgr->unpublish($data->id);
  471. $data->published = 0;
  472. $status = JC_STATUS_BLOCKED;
  473. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_MESSAGE_NEED_MOD);
  474. $emailAdmin = true;
  475. }
  476. //@todo: Need to optimize this block the for loop seems to take some time to be processed.
  477. # @unpublish rule: contain blocked words
  478. if (($status == JC_STATUS_OK) AND $_JC_CONFIG->get('blockWords')) {
  479. $words = explode(",", $_JC_CONFIG->get('blockWords'));
  480. array_walk($words, "jcTrim");
  481. foreach ($words as $word)
  482. {
  483. if (!empty ($word))
  484. {
  485. if( jcStrIpos( $data->comment , $word) !== false )
  486. {
  487. $this->_dataMgr->unpublish($data->id);
  488. $data->published = 0;
  489. $status = JC_STATUS_BLOCKED;
  490. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_MESSAGE_NEED_MOD);
  491. $emailAdmin = true;
  492. }
  493. }
  494. }
  495. }
  496. # @unpublish rule: maximum number of link.
  497. # unfortunately, we need to process the comment first to be able to reliably count
  498. # the number of links
  499. $comment = $data->comment;
  500. $comment = BBCode($comment);
  501. # @rule : maximum comment length
  502. $urlCount = preg_match_all("/(a href=)/ie", $comment, $matches);
  503. if (intval($urlCount) > $_JC_CONFIG->get('spamMaxLink')) {
  504. $this->_dataMgr->unpublish($data->id);
  505. $data->published = 0;
  506. $status = JC_STATUS_BLOCKED;
  507. $resultMsg = $this->_utf8->utf8ToHtmlEntities(_JC_MESSAGE_NEED_MOD);
  508. }
  509. # send notification to admins if required
  510. # $_JCPROFILER->mark('Sending Email');
  511. if ($emailAdmin) {
  512. $this->notifyAdmin($data);
  513. }
  514. #$_JCPROFILER->mark('Notify Admin');
  515. # send notification to content author
  516. if ($_JC_CONFIG->get('notifyAuthor') && (($data->option == "com_content") || ($data->option == "com_myblog"))) {
  517. $auid = jcGetContentAuthor($data->contentid);
  518. $contentTitle = jcContentTitle($data->contentid);
  519. $this->db->query("SELECT email FROM #__users WHERE id=$auid");
  520. $authorEmail = $this->db->get_value();
  521. if(isset($_SERVER['HTTP_REFERER'])){
  522. $link = $_SERVER['HTTP_REFERER'];
  523. }
  524. $emailSubject = "Author notification: New comment posted";
  525. #Check if mambots/system/pc_includes/template.php was included.
  526. if(!defined('AzrulJXTemplate')){
  527. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  528. }
  529. $tpl = new AzrulJXTemplate();
  530. $emailMsg = $tpl->fetch(JC_COM_PATH . '/templates/admin/mail.author.html');
  531. $emailMsg = str_replace('%CONTENTTITLE%', $contentTitle, $emailMsg);
  532. $emailMsg = str_replace('%COMMENTTITLE%', $data->title, $emailMsg);
  533. $emailMsg = str_replace('%COMMENT%', $data->comment, $emailMsg);
  534. $mode = 0;
  535. $cc = NULL;
  536. $bcc = NULL;
  537. $attachment = NULL;
  538. $replyto = NULL;
  539. $replytoname = NULL;
  540. if ($data->email)
  541. $replyto = $data->email;
  542. if ($data->name)
  543. $replytoname = $data->name;
  544. jomMail($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'), $authorEmail, $emailSubject, $emailMsg, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
  545. }
  546. #$_JCPROFILER->mark('Notify Author');
  547. # for joomla 1.0.9 and above, we need to clear content cache
  548. # also needs to clear up caching for modules
  549. jcClearCache();
  550. }
  551. $sidNew = $this->getSid();
  552. $resultCaptchaImg = $this->cms->get_path('live') . "/index2.php?option=com_jomcomment&no_html=1&task=img&jc_sid=$sidNew";
  553. $resultCaptchaSid = $sidNew;
  554. $responseMsg = '<div class="infolevel1"></div><div class="infolevel2"></div>';
  555. $responseMsg .= '<div class="infolevel3" id="infolevel3" style="text-align: center;">' . $resultMsg . '</div>';
  556. $responseMsg .= '<div class="infolevel2"></div><div class="infolevel1"></div>';
  557. switch ($status) {
  558. case JC_STATUS_OK :
  559. // Need to make sure that hidden value is set to false to make sure this comment gets shown
  560. // Otherwise, it will be marked as 'lowly rated comment'
  561. $data->hidden = false;
  562. $newComment = $this->_viewMgr->getCommentsHTML($data);
  563. $newComment = $this->_viewMgr->_cleanUpOutput($newComment);
  564. $objResponse->addAssign('jc_busyDiv', 'innerHTML', $responseMsg);
  565. $objResponse->addScriptCall("jc_insertNewEntry", $newComment, "pc_" . $data->id);
  566. $objResponse->addClear('jc_comment', 'value');
  567. $objResponse->addClear('jc_title', 'value');
  568. $objResponse->addAssign('jc_numComment', 'innerHTML', $this->_dataMgr->getNumComment($data->contentid, $data->option));
  569. break;
  570. case JC_STATUS_BLOCKED :
  571. $objResponse->addClear('jc_title', 'value');
  572. $objResponse->addClear('jc_comment', 'value');
  573. break;
  574. case JC_STATUS_WARNING :
  575. break;
  576. }
  577. # $objResponse->addAssign('mos_profiler', 'innerHTML', $_JCPROFILER->getHTML());
  578. $objResponse->addAssign('jc_captchaImg', 'src', $resultCaptchaImg);
  579. $objResponse->addAssign('jc_sid', 'value', $resultCaptchaSid);
  580. $objResponse->addAssign('jc_busyDiv', 'innerHTML', $responseMsg);
  581. $objResponse->addClear('jc_password', 'value');
  582. $objResponse->addScriptCall("jc_enableForm");
  583. $objResponse->addScriptCall("jcOpacity", "jc_busyDiv", 0, 100);
  584. $objResponse->addScriptCall("jc_fadeMessage");
  585. if($_JC_CONFIG->get('useRecaptcha')){
  586. $objResponse->addScriptCall('Recaptcha.reload();');
  587. }
  588. # technically, the output buffering should be empty. If it is not, send a bug report
  589. $ob_content = ob_get_contents();
  590. if (!empty ($ob_content)) {
  591. }
  592. # clear the caching
  593. $this->cms->load('libraries', 'cache');
  594. //$this->cms->cache->clear();
  595. return $objResponse->sendResponse();
  596. }
  597. function notifySubscribers($contentid, $option, $newcomment) {
  598. }
  599. function jcxUpdateComment($cid, $com, $num) {
  600. $contentid = intval($cid);
  601. $com = strval($com);
  602. $currentNum = $this->_dataMgr->getNumComment($cid, $com);
  603. while (@ ob_end_clean());
  604. ob_start();
  605. $objResponse = new JAXResponse();
  606. if ($num != $currentNum) {
  607. $comments = $this->getHTML($cid, $com, 0);
  608. $objResponse->addAssign('jc_commentsDiv', 'innerHTML', $comments);
  609. $objResponse->addAssign('jc_numComment', 'innerHTML', $currentNum);
  610. }
  611. $objResponse->addScriptCall("setTimeout", "jc_update()", strval($_JC_CONFIG->get('updatePeriod')));
  612. return $objResponse->sendResponse();
  613. }
  614. function jcxUnpublish($postid, $com) {
  615. $this->cms->load('libraries','user');
  616. $allowedUser = array (
  617. 'Editor',
  618. 'Publisher',
  619. 'Manager',
  620. 'Administrator',
  621. 'Super Administrator'
  622. );
  623. $isAdmin = in_array($this->cms->user->usertype, $allowedUser);
  624. $objResponse = new JAXResponse();
  625. if ($isAdmin) {
  626. $id = substr($postid, 3);
  627. $this->db->query("UPDATE #__jomcomment SET published=0 WHERE id=$id AND `option`='$com'");
  628. $this->db->query("SELECT contentid FROM #__jomcomment WHERE id=$id");
  629. $contentid = $this->db->get_value();
  630. $objResponse->addAssign('jc_numComment', 'innerHTML', jcCountComment($contentid, $com));
  631. } else {
  632. $objResponse->addAlert("Permission Error. You might have been logged-out.");
  633. }
  634. return $objResponse->sendResponse();
  635. }
  636. function jcxReport($id, $com, $referrer){
  637. $objResponse = new JAXResponse();
  638. if(!$this->cfg->get('allowvote')){
  639. $objResponse->addAlert("Permission Denied");
  640. return $objResponse->sendResponse();
  641. }
  642. $this->cms->load('libraries', 'user');
  643. global $mainframe, $_JC_CONFIG;
  644. // include_once (JC_LANGUAGE_PATH.'/'.$this->cfg->get('language'));
  645. // If similar report has been dismissed, we ignore it
  646. $this->db->query("SELECT COUNT(*) FROM #__jomcomment_reported WHERE `commentid`='$id'");
  647. if($this->db->get_value()){
  648. $html = $this->_getCustomAlertHtml('', JCView::_translateTemplate('_JC_NOTIFY_ADMIN'));
  649. $objResponse->addScriptCall('azrulShowWindow', 'pc_'.$id, $html);
  650. // $objResponse->addAlert(_JC_NOTIFY_ADMIN);
  651. return $objResponse->sendResponse();
  652. }
  653. // same IP cannot report on the same commentid/option combo
  654. $numreports = $this->db->get_count("#__jomcomment_reports", array(
  655. "ip" =>$_SERVER['REMOTE_ADDR'],
  656. "commentid" => $id,
  657. "option" => $com
  658. ));
  659. if($numreports > 0){
  660. //$objResponse->addAssign('voteReport_' . $id,'innerHTML',_JC_TPL_REPORTS_DUP);
  661. //$objResponse->addScriptCall("jax.$('voteReport_$id').style.display = 'block';");
  662. //$objResponse->addAlert(_JC_TPL_REPORTS_DUP);
  663. $html = $this->_getCustomAlertHtml('', JCView::_translateTemplate('_JC_TPL_REPORTS_DUP'));
  664. $objResponse->addScriptCall('azrulShowWindow', 'pc_'.$id, $html);
  665. return $objResponse->sendResponse();
  666. }
  667. $data = array(
  668. "ip" =>$_SERVER['REMOTE_ADDR'],
  669. "commentid" => $id,
  670. "option" => $com,
  671. 'user_id' => $this->cms->user->id
  672. );
  673. $this->db->insert("#__jomcomment_reports", $data);
  674. // Count how many report, if too many, unpublish the comment
  675. $numreports = $this->db->get_count("#__jomcomment_reports", array(
  676. "commentid" => $id,
  677. "option" => $com));
  678. // Need to check if auto unpublish reported is disabled.
  679. if($numreports > $this->cfg->get('unpublishReported') && intval($this->cfg->get('unpublishReported')) != 0){
  680. $this->db->update('#__jomcomment', "published='0'", array('id' => $id));
  681. // Alert admin that a comment has been unpublished
  682. $result = $this->db->query("SELECT * FROM #__jomcomment WHERE id='$id'");
  683. $data = $this->db->first_row();
  684. $subject = "A comment has been automatically unpublished as maximum reports has been reached.";
  685. $contentTitle = jcContentTitle($data->contentid);
  686. $comment = jcTextwrap($data->comment);
  687. $email_msg = "";
  688. $email_msg = "The following comment has been reported by site visitors and has reached the limit of " . $this->cfg->get('unpublishReported') . " reports";
  689. $email_msg .= "\n
  690. ===========================================================================
  691. Content Title: $contentTitle
  692. ===========================================================================\n
  693. Comment Title: $data->title
  694. Author: $data->name
  695. Email: $data->email
  696. Comment:
  697. $data->comment\n
  698. \n
  699. ===========================================================================\n
  700. \n
  701. \n
  702. [Powered by Jom Comment]\n
  703. ";
  704. $mode = 0;
  705. $cc = NULL;
  706. $bcc = NULL;
  707. $attachment = NULL;
  708. $replyto = NULL;
  709. $replytoname = NULL;
  710. if ($data->email)
  711. $replyto = $data->email;
  712. if ($data->name)
  713. $replytoname = $data->name;
  714. jomMail($mainframe->getCfg('mailfrom'), $mainframe->getCfg('fromname'), $_JC_CONFIG->get('notifyEmail'), $subject, $email_msg, $mode, $cc, $bcc, $attachment, $replyto, $replytoname);
  715. }
  716. // Set response
  717. //$objResponse->addAssign('voteReport_' . $id,'innerHTML',_JC_NOTIFY_ADMIN);
  718. //$objResponse->addScriptCall("jax.$('voteReport_$id').style.display = 'block';");
  719. //$objResponse->addAlert(_JC_NOTIFY_ADMIN);
  720. $html = $this->_getCustomAlertHtml('', JCView::_translateTemplate('_JC_NOTIFY_ADMIN'));
  721. $objResponse->addScriptCall('azrulShowWindow', 'pc_'.$id, $html);
  722. return $objResponse->sendResponse();
  723. }
  724. function jcxShowEmailThis($cid, $option){
  725. $objResponse = new JAXResponse();
  726. $uri = $_SERVER['HTTP_REFERER'];
  727. //Check if mambots/system/pc_includes/template.php was included.
  728. if(!class_exists('AzrulJXTemplate')){
  729. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  730. }
  731. $this->cms->load('libraries','user');
  732. $tpl = new AzrulJXTemplate();
  733. $path = jcGetTemplatePath('share.tpl.html');
  734. $tpl->set('uri', $uri);
  735. $tpl->set('name', $this->cms->user->name);
  736. $tpl->set('email', $this->cms->user->email);
  737. $data = $tpl->fetch($path);
  738. $data = $this->_getCustomAlertHtml('<div class="show-linkmore jcemail" style="float:left">_JC_TITLE_SHARE</div>', $data);
  739. $data = JCView::_translateTemplate($data);
  740. $objResponse->addScriptCall('azrulShowWindow', 'commentTools', $data);
  741. return $objResponse->sendResponse();
  742. }
  743. function jcxShowBookmarkThis($id, $option){
  744. global $mainframe;
  745. $objResponse = new JAXResponse();
  746. // Use HTTP_REFERER since the current content is the content that the user
  747. // would like to bookmark.
  748. $uri = urlencode($_SERVER['HTTP_REFERER']);
  749. $title = ('com_myblog' == $option || 'com_content' == $option ) ? jcContentTitle($id) : 'n/a';
  750. $title = urlencode($title);
  751. $busyimg = $this->cms->get_path('live') .'/components/com_jomcomment/busy.gif';
  752. //Check if mambots/system/pc_includes/template.php was included.
  753. if(!class_exists('AzrulJXTemplate')){
  754. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  755. }
  756. $tpl = new AzrulJXTemplate();
  757. $path = jcGetTemplatePath('bookmarks.tpl.html');
  758. $tpl->set('uri', $uri);
  759. $tpl->set('title', $title);
  760. $data = $tpl->fetch($path);
  761. $data = $this->_getCustomAlertHtml('<div class="show-linkmore jcshare" style="float:left">_JC_TITLE_BOOKMARKS</div>', $data);
  762. $data = JCView::_translateTemplate($data);
  763. $objResponse->addScriptCall('azrulShowWindow', 'commentTools', $data);
  764. return $objResponse->sendResponse();
  765. }
  766. /**
  767. * Ajax call to show terms and conditions
  768. **/
  769. function jcxShowTerms(){
  770. global $_JC_CONFIG;
  771. $objResponse = new JAXResponse();
  772. $html = $this->_getCustomAlertHtml('<div class="show-linkmore" style="float:left">_JC_TPL_TERMS_TITLE</div>',
  773. stripslashes($_JC_CONFIG->get('termsText'))
  774. . '<div class="clear" style="clear:both;z-order:100"></div>');
  775. $html = JCView::_translateTemplate($html);
  776. $objResponse->addScriptCall('azrulShowWindow', 'err_jc_agree', $html);
  777. return $objResponse->sendResponse();
  778. }
  779. function jcxShowFavorites($cid, $option){
  780. $objResponse = new JAXResponse();
  781. $html = $this->_getCustomAlertHtml('<div class="show-linkmore jcfav" style="float:left">Set as favorite</div>',
  782. '<form name="emailForm" id="emailForm" action="#" onsubmit="return false;" method="post">
  783. <table width="100%" cellpadding="3">
  784. <tr>
  785. <td><span class="smalltext">Friends email:</span></td><td align="left"><input type="text" name="recipientEmail" id="recipientEmail" class="inputbox" size="30"><span id="emailRecipientError" class="jcerr"></span></td></tr><tr><td><span class="smalltext">Your Name:</span></td>
  786. <td align="left"><input type="text" name="senderName" id="senderName" class="inputbox" size="30"><span id="emailNameError" class="jcerr"></span></td>
  787. </tr>
  788. <tr>
  789. <td><span class="smalltext">Your E-Mail:</span></td>
  790. <td align="left"><input type="text" name="senderEmail" id="senderEmail" class="inputbox" size="30"><span id="emailSenderError" class="jcerr"></span></td>
  791. </tr>
  792. <tr>
  793. <td width="35%"><span class="smalltext">Message Subject:</span></td>
  794. <td width="65%" align="left"><input type="text" id="senderSubject" name="senderSubject" size="35" class="inputbox"><span id="emailSubjectError" class="jcerr"></span></td>
  795. </tr>
  796. <tr>
  797. <td colspan="2" align="center">
  798. <input type="reset" class="button" value="Reset">&nbsp;
  799. <input class="button" type="button" value="Send" onclick="javascript:jax.call(\'jomcomment\', \'jcxSendEmail\', jax.$(\'recipientEmail\').value, jax.$(\'senderName\').value, jax.$(\'senderEmail\').value, jax.$(\'senderSubject\').value, \'$uri\');"></td>
  800. </tr>
  801. </table>
  802. <div class="clear" style="clear:both;z-order:100"></div>
  803. </form>');
  804. $objResponse->addScriptCall('azrulShowWindow', 'commentTools', $html);
  805. return $objResponse->sendResponse();
  806. }
  807. function jcxVote($status, $id, $com){
  808. global $mainframe;
  809. if(!$this->cfg->get('allowvote'))
  810. return;
  811. // Make sure someone didn't inject some funny vote values
  812. if($status > 0) $status = 1;
  813. if($status < 0) $status = -1;
  814. // include_once (JC_LANGUAGE_PATH.'/'.$this->cfg->get('language'));
  815. $objResponse = new JAXResponse();
  816. // same IP cannot report on the same commentid/option combo
  817. $numreports = $this->db->get_count("#__jomcomment_votes", array(
  818. "ip" =>$_SERVER['REMOTE_ADDR'],
  819. "value"=>$status,
  820. "commentid" => $id,
  821. "option" => $com
  822. ));
  823. if($numreports > 0){
  824. $html = $this->_getCustomAlertHtml('', JCView::_translateTemplate('_JC_TPL_VOTINGS_DUP'));
  825. $objResponse->addScriptCall('azrulShowWindow', 'pc_'.$id, $html);
  826. return $objResponse->sendResponse();
  827. }
  828. $voted_on = strftime("%Y-%m-%d %H:%M:%S", time() + ($mainframe->getCfg('offset') * 60 * 60));
  829. $data = array(
  830. "ip" =>$_SERVER['REMOTE_ADDR'],
  831. "value"=>$status,
  832. "commentid" => $id,
  833. "option" => $com,
  834. 'voted_on' => $voted_on
  835. );
  836. // Make sure the same IP hasn't vote on the same comment before
  837. $this->db->insert("#__jomcomment_votes", $data);
  838. // Now update the overall rating value for the comment
  839. $this->db->update("#__jomcomment", "`voted`=`voted` + ($status)", "`id`='$id'");
  840. // If The vote cause the total vote to be too small or too big, clear the cache
  841. $this->db->query("SELECT voted FROM #__jomcomment WHERE `id`='$id'");
  842. $voted = $this->db->get_value();
  843. // Check if auto minimize vote is disabled
  844. if($voted == (-1*$this->cfg->get('minVoteCount')) && (intval($this->cfg->get('minVoteCount')) != 0)){
  845. $this->cms->load('libraries', 'cache');
  846. $this->cms->cache->clear();
  847. // Clear cache so that the value of votes will be updated immediately.
  848. jcClearCache();
  849. }
  850. // Set response
  851. $html = $this->_getCustomAlertHtml('', JCView::_translateTemplate('_JC_VOTE_VOTED'));
  852. $objResponse->addScriptCall('azrulShowWindow', 'pc_'.$id, $html);
  853. // Update the vote count instantly
  854. $this->db->query("SELECT `voted` FROM #__jomcomment WHERE `id`='{$id}'");
  855. $objResponse->addAssign('cvote-'.$id, 'innerHTML', $this->db->get_value());
  856. // Clear the cache so that the votes will be displayed correctly when the next page reload.
  857. jcClearCache();
  858. return $objResponse->sendResponse();
  859. }
  860. // When a report is dismissed, we should ignore all future report on the
  861. // same comment
  862. function jcxDismissReport($id){
  863. $objResponse = new JAXResponse();
  864. $this->db->query("SELECT COUNT(*) FROM #__jomcomment_reported WHERE `commentid`='$id'");
  865. if(!$this->db->get_value()){
  866. $this->db->query("INSERT INTO #__jomcomment_reported SET `commentid`='$id'");
  867. // Now delete all related reports
  868. $this->db->query("DELETE FROM `#__jomcomment_reports` WHERE `commentid`='$id'");
  869. }
  870. #Reload the page
  871. $objResponse->addScriptCall('window.location.reload();');
  872. return $objResponse->sendResponse();
  873. }
  874. function jcxEdit($postid) {
  875. $this->cms->load('libraries','user');
  876. $allowedUser = array (
  877. 'Editor',
  878. 'Publisher',
  879. 'Manager',
  880. 'Administrator',
  881. 'Super Administrator'
  882. );
  883. $isAdmin = in_array($this->cms->user->usertype, $allowedUser);
  884. $objResponse = new JAXResponse();
  885. if ($isAdmin) {
  886. $id = substr($postid, 3);
  887. $this->db->query("SELECT comment FROM #__jomcomment WHERE id=$postid");
  888. $comment = $this->db->get_value();
  889. $text = '<div id="pc_{id}" name="pc_{id}">
  890. <form id="form-edit-{id}" name="form-edit-{id}" method="post" action="">
  891. <label>
  892. <textarea name="comment" rows="8" id="comment" style="width:98%">{comment}</textarea>
  893. </label>
  894. <input name="id" type="hidden" id="id" value="{id}" />
  895. <label>
  896. <input name="Save" type="button" value="Save" onclick="jax.call(\'jomcomment\', \'jcxSave\', jax.getFormValues(\'form-edit-{id}\'), true);" />
  897. </label>
  898. <label>
  899. <input name="Discard" type="button" value="Discard" onclick="jax.call(\'jomcomment\',\'jcxSave\', jax.getFormValues(\'form-edit-{id}\'), false);"/>
  900. </label>
  901. </form>
  902. </div>';
  903. $text = str_replace('{id}', $postid, $text);
  904. $text = str_replace('{comment}', $comment, $text);
  905. $objResponse->addAssign('pc_edit_' . $postid, 'innerHTML', $text);
  906. } else {
  907. $objResponse->addAlert("Permission Error. You might have been logged-out.");
  908. }
  909. return $objResponse->sendResponse();
  910. }
  911. // Return true if we need to add custom header to this particular page
  912. function requireHeaderScript() {
  913. global $option, $_JC_CONFIG;
  914. if($_JC_CONFIG->get('extComSupport')){
  915. return true;
  916. }
  917. return ($option == 'com_content' OR $option == 'com_myblog' OR $option=='com_frontpage');
  918. }
  919. /**
  920. * Saving the data from front-end editing
  921. */
  922. function jcxSave($xajaxArgs, $saveit) {
  923. global $_JC_CONFIG, $_JOMCOMMENT;
  924. $this->cms->load('libraries','user');
  925. $allowedUser = array (
  926. 'Editor',
  927. 'Publisher',
  928. 'Manager',
  929. 'Administrator',
  930. 'Super Administrator'
  931. );
  932. $isAdmin = in_array($this->cms->user->usertype, $allowedUser);
  933. $objResponse = new JAXResponse();
  934. if ($isAdmin) {
  935. require (JC_CONFIG);
  936. $comment = isset ($xajaxArgs['comment']) ? $xajaxArgs['comment'] : "";
  937. $id = isset ($xajaxArgs['id']) ? $xajaxArgs['id'] : 0;
  938. $comment = strip_tags( $comment , $_JC_CONFIG->get('allowedTags') );
  939. if (isset($saveit) && ($saveit == 'true')) {
  940. $this->db->query("UPDATE #__jomcomment SET comment='$comment' WHERE id=$id");
  941. // Format comment
  942. include_once(JC_COM_PATH . '/views.jomcomment.php');
  943. $view = new JCView();
  944. $formattedComment = addslashes($view->_formatComment($comment, '', false));
  945. $formattedComment = $this->cms->db->_escape( $formattedComment );
  946. $this->db->query("UPDATE #__jomcomment SET preview='$formattedComment' WHERE id=$id");
  947. }
  948. $query = "SELECT * FROM #__jomcomment WHERE id=$id";
  949. $dbResult = $this->db->query($query);
  950. $item = $this->db->first_row();
  951. $this->_viewMgr->prepData($item, 0, "none", false);
  952. $objResponse->addAssign('comment-text-container-' . $id, 'innerHTML', $item->comment);
  953. $objResponse->addAssign('pc_edit_' . $id, 'innerHTML', "");
  954. } else {
  955. $objResponse->addAlert("Permission Error. You might have been logged-out.");
  956. return $objResponse->sendResponse();
  957. }
  958. # Clear the cache, otherwise it won't show after refresh
  959. jcClearCache();
  960. return $objResponse->sendResponse();
  961. }
  962. function jcxMyFav($cid, $option){
  963. $this->cms->load('libraries','user');
  964. $objResponse = new JAXResponse();
  965. if($this->cms->user->id != 0){
  966. $this->cms->load('libraries', 'user');
  967. $this->cms->db->query("SELECT COUNT(*) FROM #__jomcomment_fav WHERE `contentid`='$cid' AND `option`='$option' AND `userid`='{$this->cms->user->id}'");
  968. $ref = $_SERVER['HTTP_REFERER'];
  969. if($this->cms->db->get_value()){
  970. $html = $this->_getCustomAlertHtml( '<div class="show-linkmore jcfav" style="float:left">' . JCView::_translateTemplate('_JC_TITLE_FAVORITES') . '</div>',
  971. JCView::_translateTemplate('_JC_TPL_WARNING_FAVORITE'));
  972. $objResponse->addScriptCall('azrulShowWindow','commentTools',$html);
  973. }else {
  974. $data = array( 'userid' => $this->cms->user->id,
  975. 'url' => $ref,
  976. 'contentid' =>$cid,
  977. 'option' => $option );
  978. $this->cms->db->insert('#__jomcomment_fav', $data);
  979. $busyimg = $this->cms->get_path('live') .'/components/com_jomcomment/busy.gif';
  980. $html = $this->_getCustomAlertHtml(
  981. '<div class="show-linkmore jcfav" style="float:left">' . JCView::_translateTemplate('_JC_TITLE_FAVORITES') . '</div>',
  982. '<span id="favnotice">' . JCView::_translateTemplate('_JC_TPL_ADDED_FAVORITE') . '</span>'
  983. );
  984. $objResponse->addScriptCall('azrulShowWindow','commentTools',$html);
  985. }
  986. }else{
  987. // Show message to user that they will need to register first.
  988. $html = $this->_getCustomAlertHtml( '<div class="show-linkmore jcfav" style="float:left">' . JCView::_translateTemplate('_JC_TITLE_FAVORITES') . '</div>',
  989. JCView::_translateTemplate('_JC_TPL_MEMBERS_FAV'));
  990. $objResponse->addScriptCall('azrulShowWindow','commentTools',$html);
  991. }
  992. return $objResponse->sendResponse();
  993. }
  994. function jcxRemoveFav($id){
  995. $objResponse = new JAXResponse();
  996. $strSQL = "DELETE FROM #__jomcomment_fav WHERE `id`='{$id}'";
  997. $this->cms->db->query($strSQL);
  998. $objResponse->addScriptCall('window.location.reload();');
  999. return $objResponse->sendResponse();
  1000. }
  1001. function jcxShowSendEmail(){
  1002. $objResponse = new JAXResponse();
  1003. return $objResponse->sendResponse();
  1004. }
  1005. /**
  1006. * Ajax function call (jcxSendEmail)
  1007. * params: $recipient - Receiver's email address
  1008. * $name - Sender's Name
  1009. * $email - Sender's Email
  1010. * $subject - Subject of the Email
  1011. * $articleLink- Link for the current article.
  1012. **/
  1013. function jcxSendEmail($recipient, $name, $email, $subject, $articleLink){
  1014. global $_JC_CONFIG;
  1015. $objResponse = new JAXResponse();
  1016. $processForm = true;
  1017. # Rule: Check if recipient email is valid.
  1018. if(!jcValidEmail($recipient)){
  1019. $processForm = false;
  1020. $objResponse->addAssign('emailRecipientError','innerHTML','*');
  1021. }else{
  1022. //Previously may contain error, so we just reset it.
  1023. $objResponse->addAssign('emailRecipientError','innerHTML','');
  1024. }
  1025. # Rule: Check if sender's email is valid.
  1026. if(!jcValidEmail($email)){
  1027. $processForm = false;
  1028. $objResponse->addAssign('emailSenderError','innerHTML','*');
  1029. }else{
  1030. $objResponse->addAssign('emailSenderError','innerHTML','');
  1031. }
  1032. # Rule: Check if name is entered.
  1033. if(strlen($name) <= 0){
  1034. $objResponse->addAssign('emailNameError','innerHTML','*');
  1035. }else{
  1036. $objResponse->addAssign('emailNameError','innerHTML','');
  1037. }
  1038. # Rule: Check if subject is entered.
  1039. if(strlen($subject) <= 0){
  1040. $objResponse->addAssign('emailSubjectError','innerHTML','*');
  1041. }else{
  1042. $objResponse->addAssign('emailSubjectError','innerHTML','');
  1043. }
  1044. # Rule: Check for spams?
  1045. # Check if to process the form
  1046. if($processForm){
  1047. $html = "<div id=\"emailFormResult\">" . JCView::_translateTemplate('_JC_TPL_SENT_MAIL') . " <span id=\"email\">{$recipient}</span>.</div><br />";
  1048. $articleLlink = urldecode($articleLink);
  1049. #Check if mambots/system/pc_includes/template.php was included.
  1050. if(!class_exists('AzrulJXTemplate')){
  1051. include_once($this->cms->get_path('plugins') . '/system/pc_includes/template.php');
  1052. }
  1053. $tpl = new AzrulJXTemplate();
  1054. $emailMsg = $tpl->fetch(JC_COM_PATH . '/templates/admin/share.mail.html');
  1055. $emailMsg = str_replace('%NAME%', $name, $emailMsg);
  1056. $emailMsg = str_replace('%SITE%', $articleLink, $emailMsg);
  1057. // Send email
  1058. global $mainframe;
  1059. if(jomMail($email, $name, $recipient, $subject, $emailMsg , 0 , NULL , NULL , NULL , $email)){
  1060. // Sendmail success
  1061. // Hide email form,
  1062. $objResponse->addAssign('dialog_body','innerHTML',$html);
  1063. } else {
  1064. // Sendmail failed.
  1065. $html = "<div id=\"emailFormResult\">Error while sending an email to <span id=\"email\">{$email}</span>.</div><br />";
  1066. $objResponse->addAssign('dialog_body','innerHTML',$html);
  1067. }
  1068. }
  1069. return $objResponse->sendResponse();
  1070. }
  1071. function jcxUnsubscribe($id){
  1072. $objResponse = new JAXResponse();
  1073. $strSQL = "DELETE FROM #__jomcomment_subs WHERE `id`='{$id}'";
  1074. $this->cms->db->query($strSQL);
  1075. $objResponse->addScriptCall('window.location.reload();');
  1076. return $objResponse->sendResponse();
  1077. }
  1078. function jcxEnableSubscription($id){
  1079. $objResponse = new JAXResponse();
  1080. $strSQL = "UPDATE #__jomcomment_subs SET `status`='1' WHERE `id`='{$id}'";
  1081. $this->cms->db->query($strSQL);
  1082. $objResponse->addScriptCall('window.location.reload();');
  1083. return $objResponse->sendResponse();
  1084. }
  1085. function jcxPreviewComment($comment){
  1086. global $_JC_CONFIG;
  1087. $response = new JAXResponse();
  1088. if($_JC_CONFIG->get('commentPreview')){
  1089. $view = new JCView();
  1090. if($comment == ''){
  1091. $response->addScriptCall('alert("' . JCView::_translateTemplate('_JC_TPL_ERROR_PREVIEW') . '");');
  1092. } else {
  1093. // Just format the comment to be displayed
  1094. $comment = '<br />' . $view->_formatComment($comment);
  1095. $comment .= '<br /><br />
  1096. <div style="text-align: right;"><button id="addcommentbutton" class="button" onclick="javascript:addComments();azrulHideWindow();">'
  1097. . JCView::_translateTemplate('_JC_TPL_ADDCOMMENT') . '</button></div>';
  1098. $html = $this->_getCustomAlertHtml('<div class="show-linkmore jcpreview" style="float:left">' . JCView::_translateTemplate('_JC_TPL_HEAD_PREVIEW') . '</div>',
  1099. $comment);
  1100. $response->addScriptCall('azrulShowWindow', 'jc_commentForm', $html);
  1101. }
  1102. } else {
  1103. $response->addScriptCall('alert("Not available.");');
  1104. }
  1105. return $response->sendResponse();
  1106. }
  1107. function jcxDisableSubscription($id){
  1108. $objResponse = new JAXResponse();
  1109. $strSQL = "UPDATE #__jomcomment_subs SET `status`='0' WHERE `id`='{$id}'";
  1110. $this->cms->db->query($strSQL);
  1111. $objResponse->addScriptCall('window.location.reload();');
  1112. return $objResponse->sendResponse();
  1113. }
  1114. function jcxShowComment($id){
  1115. $objResponse = new JAXResponse();
  1116. $query = "SELECT * FROM #__jomcomment WHERE id=$id";
  1117. $dbResult = $this->db->query($query);
  1118. $item = $this->db->first_row();
  1119. // Need to rif the voted count so that it gets displayed
  1120. $item->voted = 0;
  1121. $newComment = $this->_viewMgr->getCommentsHTML($item);
  1122. $newComment = $this->_viewMgr->_cleanUpOutput($newComment);
  1123. //$objResponse->addAssign('pc_'.$id, 'innerHTML', $newComment);
  1124. //$objResponse->addAlert("Permission Error. You might have been logged-out.");
  1125. $objResponse->addScriptCall("jc_showComment", $newComment, "pc_" . $id);
  1126. return $objResponse->sendResponse();
  1127. }
  1128. function _getCustomAlertHtml($title, $content, $style ='', $actions=''){
  1129. $html = '<div class="dialog_header">'. $title .'<div onclick="azrulHideWindow();" class="dialog_close">[ ' . JCView::_translateTemplate('_JC_TPL_CLOSEWIN') . ' ]</div></div>
  1130. <div class="dialog_content">
  1131. <div id="dialog_body" class="dialog_body">
  1132. '. $content .'
  1133. </div>';
  1134. if($actions){
  1135. $html .='
  1136. <div id="dialog_buttons" class="dialog_buttons">
  1137. <hr size="1" noshade="noshade"/>
  1138. '.$actions.'
  1139. </div>';
  1140. }
  1141. $html .='</div>';
  1142. return $html;
  1143. }
  1144. }
  1145. // Initiate some global objects
  1146. $_JC_CONFIG = new JCConfig();
  1147. $_JOMCOMMENT = new JCMainFrame();
  1148. $_JC_UTF8 = new Utf8Helper();