PageRenderTime 66ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 1ms

/src/site/components/com_comment/joscomment/comment.class.php

https://bitbucket.org/manchas/jrobotz
PHP | 3209 lines | 2332 code | 387 blank | 490 comment | 353 complexity | 03b2846b7f05618caa20b605669e8cac MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0

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

  1. <?php defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
  2. /*
  3. * Copyright Copyright (C) 2007 Alain Georgette. All rights reserved.
  4. * Copyright Copyright (C) 2006 Frantisek Hliva. All rights reserved.
  5. * License http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  6. *
  7. * !JoomlaComment is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * !JoomlaComment is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301, USA.
  21. */
  22. global $mosConfig_absolute_path;
  23. require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/utils.php');
  24. require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/strutils.php');
  25. require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/jscript.php');
  26. require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/security.php');
  27. class JOSC_template {
  28. var $_live_site;
  29. var $_absolute_path;
  30. var $_template_path = '';
  31. var $_template_absolute_path = '';
  32. var $_name = '';
  33. var $_css = '';
  34. var $_title = '';
  35. /*
  36. * parsed blocks
  37. */
  38. var $_body = '';
  39. var $_library = '';
  40. var $_readon = '';
  41. var $_previewline = '';
  42. var $_menu = ''; /* ? */
  43. var $_post = '';
  44. var $_search = '';
  45. var $_searchResults = '';
  46. var $_form = '';
  47. var $_poweredby = '';
  48. function JOSC_template($name,$css='template_css.css')
  49. {
  50. $this->_name = $name;
  51. $this->_css = $css;
  52. }
  53. function loadFromFile()
  54. {
  55. $fileName = $this->_template_absolute_path .'/'. $this->_name . '/index.html';
  56. if (file_exists($fileName)) {
  57. $file = fopen ($fileName, 'r');
  58. $template = fread ($file, filesize($fileName));
  59. fclose($file);
  60. return $template;
  61. } else die ('!JoomlaComment template not found: ' . $this->_name);
  62. }
  63. function CSS()
  64. {
  65. //return JOSC_utils::insertToHead('<link rel="stylesheet" href="' . $this->_template_path . '/' . $this->_name . '/css/'.$this->_css.'" type="text/css" />');
  66. global $mosConfig_caching;
  67. /*
  68. * cache does not calculate again head for bots... :(
  69. * and link rel outside head is not good accepted by IE7
  70. * for example after a embed object...
  71. * not a complete solution but less blocking
  72. */
  73. if ($mosConfig_caching) {
  74. $html = "\n<script type = \"text/javascript\">"
  75. . "<!--"
  76. . "\n if (!JOSC_cssStyleSheet)" /* TODO: search in StyleSheets elements if exist */
  77. . "\n { var JOSC_csslink = document.createElement('link');"
  78. . "\n var JOSC_cssStyleSheet = '". $this->_template_path . '/' . $this->_name . '/css/'.$this->_css ."';"
  79. . "\n JOSC_csslink.setAttribute('href', JOSC_cssStyleSheet );"
  80. . "\n JOSC_csslink.setAttribute('rel', 'stylesheet');"
  81. . "\n JOSC_csslink.setAttribute('type', 'text/css');"
  82. . "\n var JOSC_csshead = document.getElementsByTagName('head').item(0);"
  83. . "\n JOSC_csshead.appendChild(JOSC_csslink);"
  84. . "\n }//-->"
  85. . "\n</script>";
  86. return $html;
  87. } else {
  88. return JOSC_utils::insertToHead('<link rel="stylesheet" href="' . $this->_template_path . '/' . $this->_name . '/css/'.$this->_css.'" type="text/css" />');
  89. }
  90. }
  91. function parse($readon=false)
  92. {
  93. $template = $this->loadFromFile();
  94. $this->_body = JOSC_utils::block($template, 'body');
  95. $this->_library = JOSC_utils::block($template, 'library');
  96. if ($readon) {
  97. $this->_readon = JOSC_utils::block($template, 'readon');
  98. $this->_previewline = JOSC_utils::block($template, 'previewline');
  99. } else {
  100. $this->_menu = JOSC_utils::block($template, 'menu');
  101. $this->_search = JOSC_utils::block($template, 'search');
  102. $this->_searchResults = JOSC_utils::block($template, 'searchresults');
  103. $this->_post = JOSC_utils::block($template, 'post');
  104. $this->_form = JOSC_utils::block($template, 'form');
  105. $this->_poweredby = JOSC_utils::block($template, 'poweredby');
  106. }
  107. }
  108. }
  109. class JOSC_properties extends JOSC_template {
  110. /* special parameters */
  111. var $_contentrow;
  112. var $_params;
  113. var $_component;
  114. var $_sectionid;
  115. var $_comObject;
  116. var $_limitstart;
  117. var $_total;
  118. var $_request_uri;
  119. /* config params */
  120. var $_ajax;
  121. var $_local_charset;
  122. var $_only_registered;
  123. var $_language;
  124. var $_moderator = array();
  125. var $_include_sc;
  126. var $_exclude_sections = array();
  127. var $_exclude_categories = array();
  128. var $_exclude_contentitems = array();
  129. var $_exclude_contentids = array();
  130. var $_template;
  131. var $_template_css;
  132. var $_form_area_cols;
  133. var $_emoticon_pack;
  134. var $_emoticon_wcount;
  135. var $_tree;
  136. var $_mlink_post;
  137. var $_tree_indent;
  138. var $_sort_downward;
  139. var $_display_num;
  140. var $_support_emoticons;
  141. var $_support_UBBcode;
  142. var $_support_pictures;
  143. var $_censorship_enable;
  144. var $_censorship_case_sensitive;
  145. var $_censorship_words;
  146. var $_censorship_usertypes;
  147. var $_IP_visible;
  148. var $_IP_partial;
  149. var $_IP_caption;
  150. var $_IP_usertypes;
  151. var $_preview_visible;
  152. var $_preview_length;
  153. var $_preview_lines;
  154. var $_voting_visible;
  155. var $_use_name;
  156. var $_notify_admin;
  157. var $_notify_email;
  158. var $_notify_moderator;
  159. var $_notify_users;
  160. var $_rss;
  161. var $_date_format;
  162. var $_no_search;
  163. var $_captcha;
  164. var $_autopublish;
  165. var $_ban;
  166. var $_avatar;
  167. var $_profile;
  168. var $_profiles;
  169. var $_maxlength_text;
  170. var $_maxlength_word;
  171. var $_maxlength_line;
  172. var $_show_readon;
  173. var $_debug_username;
  174. var $_xmlerroralert;
  175. var $_ajaxdebug;
  176. function JOSC_properties($absolutePath, $liveSite, &$comObject, &$exclude, &$row, &$params)
  177. {
  178. global $my, $mosConfig_absolute_path;
  179. //require("$absolutePath/../config.comment.php");
  180. /* abolutepath = .../administrator/components/com_comment/joscomment absolute path */
  181. require_once("$mosConfig_absolute_path/administrator/components/com_comment/class.config.comment.php");
  182. $config = new JOSC_config(0, $comObject);
  183. if (!$config->load()) {
  184. $exclude = true;
  185. return;
  186. }
  187. /*
  188. * setting
  189. */
  190. $this->_comObject = $config->_comObject;
  191. $this->_component = $this->_comObject->_component;
  192. $this->_sectionid = $this->_comObject->_sectionid;
  193. $this->_content_id = $this->_comObject->_id;
  194. $this->_ajax = $config->_ajax;
  195. $this->_local_charset = $config->_local_charset;
  196. $this->_only_registered = $config->_only_registered;
  197. $this->_language = $config->_language;
  198. $this->_moderator = explode(',', $config->_moderator);
  199. /*
  200. * content item
  201. */
  202. if ($exclude && isset($row)) {
  203. $this->_show_readon = $this->_comObject->setShowReadon( $row, $params, $config );
  204. $this->_exclude_contentids = $config->_exclude_contentids ? explode(',', $config->_exclude_contentids) : array();
  205. $this->_exclude_contentitems = $config->_exclude_contentitems ? explode(',', $config->_exclude_contentitems) : array();
  206. $this->_exclude_sections = $config->_exclude_sections ? explode(',', $config->_exclude_sections) : array();
  207. $this->_exclude_categories = $config->_exclude_categories ? explode(',', $config->_exclude_categories) : array();
  208. $this->_include_sc = $config->_include_sc;
  209. if ($this->_comObject->_official) {
  210. $obj = $this;
  211. if (!$this->_comObject->checkSectionCategory($row, $obj ))
  212. return false;
  213. } else {
  214. if (!$this->_comObject->checkSectionCategory($row, $this->_include_sc, $this->_exclude_sections, $this->_exclude_categories, $this->_exclude_contentids ))
  215. return false;
  216. }
  217. }
  218. /*
  219. * others
  220. */
  221. $this->_tree = $config->_tree;
  222. $this->_mlink_post = $config->_mlink_post;
  223. $this->_tree_indent = $config->_tree_indent;
  224. $this->_sort_downward = $config->_sort_downward; //($this->_tree ? 0 : $config->_sort_downward);
  225. $this->_display_num = $config->_display_num;
  226. $this->_support_emoticons = $config->_support_emoticons;
  227. $this->_enter_website = $config->_enter_website;
  228. $this->_support_UBBcode = $config->_support_UBBcode;
  229. $this->_support_pictures = $config->_support_pictures;
  230. $this->_pictures_maxwidth = $config->_pictures_maxwidth;
  231. $this->_censorship_enable = $config->_censorship_enable && in_array(JOSC_utils::getJOSCUserType($my->usertype), explode(',', $config->_censorship_usertypes));
  232. $this->_censorship_case_sensitive = $config->_censorship_case_sensitive;
  233. // $this->_censorship_words = explode(',', $config->_censorship_words);
  234. $this->Set_censorship_words($config->_censorship_words);
  235. $this->_IP_usertypes = explode(',', $config->_IP_usertypes);
  236. $this->_IP_visible = $config->_IP_visible;
  237. $this->_IP_partial = $config->_IP_partial;
  238. $this->_IP_caption = $config->_IP_caption;
  239. $this->_preview_visible = $config->_preview_visible;
  240. $this->_preview_length = $config->_preview_length;
  241. $this->_preview_lines = $config->_preview_lines;
  242. $this->_voting_visible = $config->_voting_visible;
  243. $this->_use_name = $config->_use_name;
  244. $this->_notify_admin = $config->_notify_admin;
  245. $this->_notify_email = $config->_notify_email;
  246. $this->_notify_moderator = $config->_notify_moderator;
  247. $this->_autopublish = $config->_autopublish;
  248. $this->_notify_users = $config->_notify_users;
  249. $this->_rss = $config->_rss;
  250. $this->_date_format = $config->_date_format;
  251. $this->_no_search = $config->_no_search;
  252. $this->_captcha = $config->_captcha && in_array(JOSC_utils::getJOSCUserType($my->usertype), explode(',', $config->_captcha_usertypes));
  253. $this->_website_registered = $config->_website_registered;
  254. $this->_ban = $config->_ban;
  255. $cb = JOSC_TableUtils::existsTable('#__comprofiler');
  256. $this->_profile = $config->_support_profiles && $cb;
  257. $this->_avatar = $config->_support_avatars && $cb;
  258. $this->_maxlength_text = $config->_maxlength_text;
  259. $this->_maxlength_word = $config->_maxlength_word;
  260. $this->_maxlength_line = $config->_maxlength_line;
  261. $this->_absolute_path = $absolutePath;
  262. $this->_live_site = $liveSite;
  263. $this->_template = $config->_template_custom ? $config->_template_custom : $config->_template;
  264. $this->_template_path = $config->_template_custom ? $config->_template_custom_livepath : "$liveSite/templates";
  265. $this->_template_absolute_path = $config->_template_custom ? $config->_template_custom_path : "$absolutePath/templates";
  266. $this->_template_css = $config->_template_custom ? $config->_template_custom_css : $config->_template_css;
  267. $this->JOSC_template($this->_template, $this->_template_css);
  268. $this->_template_library = $config->_template_library;
  269. $this->_form_area_cols = $config->_form_area_cols;
  270. $this->_emoticon_pack = $config->_emoticon_pack;
  271. $this->_emoticon_wcount = $config->_emoticon_wcount;
  272. $this->_emoticons_path = $liveSite . "/emoticons/$this->_emoticon_pack/images";
  273. JOSC_utils::set_charsetConstant($this->_local_charset);
  274. $this->loadLanguage($GLOBALS['josComment_absolute_path'], $this->_language);
  275. $this->loadEmoticons("$absolutePath/emoticons/$this->_emoticon_pack/index.php");
  276. $this->_debug_username = $config->_debug_username;
  277. $this->_xmlerroralert = $config->_xmlerroralert ? '1' : '0';
  278. $this->_ajaxdebug = $config->_ajaxdebug ? '1' : '0';
  279. if ($this->_profile)
  280. $this->loadProfiles();
  281. $exclude = false;
  282. }
  283. function Set_censorship_words($censorship_words)
  284. {
  285. $this->_censorship_words = array();
  286. if ($this->_censorship_enable && $censorship_words) {
  287. $censorship_words = explode(',', $censorship_words);
  288. if (is_array($censorship_words)) {
  289. foreach($censorship_words as $word) {
  290. $word = trim($word);
  291. if (strpos($word, '=')) {
  292. $word = explode('=', $word);
  293. $from = trim($word[0]);
  294. $to = trim($word[1]);
  295. } else {
  296. $from = $word;
  297. $to = JOSC_strutils::str_fill(strlen($word), '*');
  298. }
  299. $this->_censorship_words[$from] = $to;
  300. }
  301. }
  302. }
  303. return;
  304. }
  305. function jscriptInit()
  306. {
  307. global $mosConfig_live_site, $my;
  308. $html = "\n<script type='text/javascript'>\n";
  309. $html .= "var JOSC_ajaxEnabled=$this->_ajax;";
  310. $html .= "if (!JOSC_http) JOSC_ajaxEnabled=false;";
  311. $html .= "var JOSC_sortDownward='$this->_sort_downward';";
  312. $captchaEnabled = $this->_captcha ? 'true' : 'false';
  313. $html .= "var JOSC_captchaEnabled=$captchaEnabled;";
  314. $html .= "var JOSC_template='$this->_template_path/$this->_name';";
  315. $html .= "var JOSC_liveSite='$this->_live_site';"; /* joscomment */
  316. $html .= "var JOSC_ConfigLiveSite='$mosConfig_live_site';";
  317. $html .= "var JOSC_linkToContent='".$this->_comObject->linkToContent( $this->_content_id )."';";
  318. $html .= "var JOSC_autopublish='$this->_autopublish';"; /* not used ?*/
  319. if ($this->_debug_username && ($my->username==$this->_debug_username || $this->_debug_username=="JOSCdebugactive")) {
  320. $html .= "var JOSC_XmlErrorAlert=$this->_xmlerroralert;";
  321. $html .= "var JOSC_AjaxDebug=$this->_ajaxdebug;";
  322. }
  323. $html .= "\n</script>\n";
  324. return $html;
  325. }
  326. function loadLanguage($path, $language)
  327. {
  328. // $path .= '/language/';
  329. // if ($language == 'auto') $language = $path . $GLOBALS['mosConfig_lang'] . '.php';
  330. // else $language = $path . $language;
  331. // if (file_exists($language))
  332. // require_once($language);
  333. // require_once($path . 'english.php'); // default is EN. non existant constants will be taken from default from this
  334. JOSC_utils::loadFrontendLoadLanguage($language);
  335. }
  336. function loadEmoticons($fileName)
  337. {
  338. require_once($fileName);
  339. $this->_emoticons = $GLOBALS["JOSC_emoticon"];
  340. }
  341. function loadProfiles()
  342. {
  343. if (defined('_JOSC_J15'))
  344. $database =& JFactory::getDBO();
  345. else
  346. global $database;
  347. $database->setQuery('SELECT u.username, c.user_id, c.avatar
  348. FROM #__users AS u, #__comprofiler AS c
  349. WHERE u.id = c.user_id');
  350. $userList = $database->loadAssocList();
  351. $this->_profiles = array();
  352. foreach ($userList as $item) {
  353. /*
  354. * set _profiles[userid][avatar]
  355. */
  356. if ($this->_avatar)
  357. $this->_profiles[$item['user_id']]['avatar'] = $item['avatar'];
  358. else
  359. $this->_profiles[$item['user_id']]['avatar'] = false;
  360. /*
  361. * set _profiles[userid][id of cb]
  362. */
  363. if ($this->_profile)
  364. $this->_profiles[$item['user_id']]['id'] = $item['user_id'];
  365. else
  366. $this->_profiles[$item['user_id']]['id'] = false;
  367. }
  368. unset($userList);
  369. }
  370. }
  371. class JOSC_visual extends JOSC_properties {
  372. var $_parent_id = -1;
  373. function insertMenu()
  374. {
  375. $menu = new JOSC_menu($this->_menu);
  376. $menu->setContentId($this->_content_id);
  377. $menu->setTemplate_path($this->_template_path);
  378. $menu->setTemplate_name($this->_name);
  379. $menu->setRSS($this->_rss);
  380. $menu->setModerator($this->_moderator);
  381. $menu->setOnly_registered($this->_only_registered);
  382. $menu->setNoSearch($this->_no_search);
  383. return $menu->menu_htmlCode();
  384. }
  385. function insertPoweredby()
  386. {
  387. return '<div id="poweredby" align="center" class="small">Powered by <a target="_blank" href="http://compojoom.com/">!JoomlaComment '."3.26".'</a></div>';
  388. }
  389. function insertHiddenCopyright()
  390. {
  391. return '<h4 style="display:none;">3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."</h4>';
  392. }
  393. function insertSearch()
  394. {
  395. $html = $this->_search;
  396. $hidden = JOSC_support::formHiddenValues($this->_content_id, $this->_component, $this->_sectionid);
  397. $html = str_replace('{_HIDDEN_VALUES}', $hidden, $html);
  398. $html = str_replace('{_JOOMLACOMMENT_SEARCH}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH)), $html);
  399. $html = str_replace('{_JOOMLACOMMENT_PROMPT_KEYWORD}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_PROMPT_KEYWORD)), $html);
  400. $html = str_replace('{_JOOMLACOMMENT_SEARCH_ANYWORDS}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_ANYWORDS)), $html);
  401. $html = str_replace('{_JOOMLACOMMENT_SEARCH_ALLWORDS}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_ALLWORDS)), $html);
  402. $html = str_replace('{_JOOMLACOMMENT_SEARCH_PHRASE}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_PHRASE)), $html);
  403. return $html;
  404. }
  405. function initializePost($item, $postCSS)
  406. { /* post is used in module latest... ! */
  407. $post = new JOSC_post($this->_post); /* template block */
  408. $post->setUseName($this->_use_name); /* needed for setItem */
  409. $post->setItem($item);
  410. $post->setTemplate_path($this->_template_path);
  411. $post->setTemplate_name($this->_name);
  412. $post->setCSS($postCSS);
  413. $post->setAjax($this->_ajax);
  414. $post->setTree($this->_tree);
  415. $post->setMLinkPost($this->_mlink_post);
  416. $post->setTree_indent($this->_tree_indent);
  417. $post->setDate_format($this->_date_format);
  418. $post->setIP_visible($this->_IP_visible);
  419. $post->setIP_partial($this->_IP_partial);
  420. $post->setIP_caption($this->_IP_caption);
  421. $post->setIP_usertypes($this->_IP_usertypes);
  422. $post->setCensorShip( $this->_censorship_enable,
  423. $this->_censorship_case_sensitive,
  424. $this->_censorship_words,
  425. $this->_censorship_usertypes
  426. );
  427. $post->setContentId($this->_content_id);
  428. $post->setComponent($this->_component);
  429. $post->setVoting_visible($this->_voting_visible);
  430. $post->setSupport_emoticons($this->_support_emoticons);
  431. $post->setSupport_UBBcode($this->_support_UBBcode);
  432. $post->setSupport_quotecode($this->_support_UBBcode); /* only module use */
  433. $post->setSupport_link($this->_support_UBBcode); /* only module use */
  434. $post->setSupport_pictures($this->_support_pictures, $this->_pictures_maxwidth);
  435. $post->setEmoticons($this->_emoticons);
  436. $post->setEmoticons_path($this->_emoticons_path);
  437. $post->setOnly_registered($this->_only_registered);
  438. $post->setWebsiteRegistered($this->_website_registered);
  439. $post->setModerator($this->_moderator);
  440. if ($post->_item['userid']) {
  441. $post->setUser_id( ($this->_profile && isset($this->_profiles[$post->_item['userid']])) ? $this->_profiles[$post->_item['userid']]['id'] : false );
  442. $post->setAvatar( ($this->_avatar && isset($this->_profiles[$post->_item['userid']])) ? $this->_profiles[$post->_item['userid']]['avatar'] : false );
  443. }
  444. $post->setNotify_users($this->_notify_users, $this->_notify_moderator);
  445. $post->setMaxLength_text($this->_maxlength_text);
  446. $post->setMaxLength_word($this->_maxlength_word);
  447. $post->setMaxLength_line($this->_maxlength_line);
  448. return $post;
  449. }
  450. function insertPost($item, $postCSS)
  451. { /* post is used in module latest... ! */
  452. $post = $this->initializePost($item, $postCSS);
  453. return( $post->post_htmlCode() );
  454. }
  455. function getPageNav()
  456. {
  457. if ($this->_total <= $this->_display_num) return '';
  458. $pageNav = new JOSC_PageNav( $this->_ajax, $this->_total, $this->_limitstart, $this->_display_num );
  459. $link = $this->_request_uri;
  460. /* delete limit and limitstart parameters before add new */
  461. $link = preg_replace("/(.*)(&josclimit=.*)(&.*|)/", '\\1\\3', $link);
  462. $link = preg_replace("/(.*)(&josclimitstart=.*)(&.*|)/", '\\1\\3', $link);
  463. $html = "<div id='joscPageNavLink'>".$pageNav->writePagesLinks( $link, "#joscpagenav" )."</div>";
  464. if ($this->_ajax)
  465. $html.= "<div id='joscPageNavNoLink' style='display:none;visibility:hidden;'>".$pageNav->writePagesLinks('')."</div>";
  466. $addjs = "\n<script type='text/javascript'>";
  467. if ($this->_sort_downward) {
  468. /* DESC addeed to begin -> if not begin needs refresh*/
  469. if ($this->_limitstart <= $this->_display_num)
  470. $addjs .= "var JOSC_postREFRESH=false;";
  471. else
  472. $addjs .= "var JOSC_postREFRESH=true;";
  473. } else {
  474. /* ASC addeed to end -> if not end needs refresh */
  475. if (($this->_limitstart+$this->_display_num)>=$this->_total)
  476. $addjs .= "var JOSC_postREFRESH=false;";
  477. else
  478. $addjs .= "var JOSC_postREFRESH=true;";
  479. }
  480. $addjs .= "</script>\n";
  481. return "<a name='joscpagenav'>".$addjs.$html;
  482. }
  483. function insertPageNav()
  484. {
  485. return "<div id='joscPageNav'>".$this->getPageNav()."</div>";
  486. }
  487. function getComments($onlydata=false)
  488. {
  489. if (defined('_JOSC_J15'))
  490. $database =& JFactory::getDBO();
  491. else
  492. global $database;
  493. if ($this->_sort_downward) {
  494. $sort = 'DESC'; /* new first */
  495. } else {
  496. $sort = 'ASC'; /* last first */
  497. }
  498. $html = '';
  499. $com = $this->_component;
  500. /*
  501. * ORDER must be done only on high level
  502. * because children must be ordered ascending for tree construction
  503. */
  504. $queryselect = "SELECT * ";
  505. $querycount = "SELECT COUNT(*) ";
  506. $queryfrom = "\nFROM #__comment"
  507. . "\n WHERE contentid='$this->_content_id' AND component='$com' "
  508. . "\n AND published='1' ";
  509. $queryparent = $this->_tree ? "\n AND parentid<=0 " : "";
  510. $querychildren = $this->_tree ? "\n AND parentid>0 " : "";
  511. $queryorder = "\n ORDER BY id $sort";
  512. if ($this->_display_num>0) {
  513. /*
  514. * pages -> use limitstart on root id (childs are not counted - always attached to root id)
  515. */
  516. if ($this->_comment_id) {
  517. /*
  518. * - get the limitstart(page) of the comment_id
  519. * - comment id can be a root id but also a child !
  520. * in this case, we must search for its root id.
  521. */
  522. $parentid = $id = $this->_comment_id;
  523. for ($i=1; $i<=20 && $parentid>0; $i++)
  524. { /* LEFT JOIN is for loop optimization : 1 loop = 2 levels */
  525. /* 20 times is for infinity loop limit = maximum 40 levels. it should be enough....? :) */
  526. $query = "SELECT c.id, c.parentid, p.id AS p_id, p.parentid AS p_parentid "
  527. . "\n FROM #__comment AS c LEFT JOIN #__comment AS p ON c.parentid=p.id "
  528. . "\n WHERE c.id=$parentid LIMIT 1";
  529. $database->SetQuery($query);
  530. $row = $database->loadAssocList();
  531. if ($row=$row[0]) {
  532. $id = $row['id'];
  533. $parentid = $row['parentid'];
  534. if ($row['parentid']>0) {
  535. $id = $row['p_id'];
  536. $parentid=$row['p_parentid'];
  537. }
  538. } else {
  539. $id = $parentid = -1;
  540. }
  541. }
  542. if ($id) {
  543. /* get the limitstart from the root id */
  544. $database->SetQuery("SELECT id ".$queryfrom.$queryparent.$queryorder);
  545. $data = $database->loadResultArray();
  546. $i = array_search($id, $data);
  547. if ($i) $this->_limitstart = $i;
  548. }
  549. }
  550. $database->SetQuery($querycount.$queryfrom.$queryparent.$queryorder);
  551. $this->_total = $database->loadResult();
  552. $checklimit = new JOSC_PageNav($this->_ajax, $this->_total, $this->_limitstart, $this->_display_num);
  553. $this->_limitstart = $checklimit->limitstart;
  554. $database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder, $this->_limitstart, $this->_display_num);
  555. $dataparent = $database->loadAssocList();
  556. } else {
  557. $database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder);
  558. $dataparent = $database->loadAssocList();
  559. }
  560. if ($this->_tree) {
  561. $database->SetQuery($queryselect.$queryfrom.$querychildren."\n ORDER BY id ASC");
  562. $datachildren = $database->loadAssocList();
  563. $data = ($dataparent && count($datachildren)>0) ? array_merge($dataparent,$datachildren) : $dataparent;
  564. } else {
  565. $data = $dataparent;
  566. }
  567. //return "displ=".$this->_display_num;
  568. //return JOSC_utils::debug_array($data);
  569. /*
  570. * $data is composed of ALL or ROOT array + CHILDREN array
  571. * this means that position of a ROOT gives the page position.
  572. */
  573. $postCSS = 1;
  574. if (!$data && $onlydata) return $data;
  575. if ($data != null) {
  576. if ($this->_tree) $data = JOSC_utils::buildTree($data);
  577. //return $data;
  578. if ($onlydata) return $data; /* after the foreach */
  579. if ($data != null) {
  580. foreach($data as $item) {
  581. $html .= $this->insertPost($item, $postCSS);
  582. $postCSS++;
  583. if ($postCSS == 3) $postCSS = 1;
  584. }
  585. }
  586. }
  587. $addjs = "\n<script type='text/javascript'>"
  588. . " var JOSC_postCSS=$postCSS;"
  589. . "</script>";
  590. /* Daniel add-on for Allvideo Reloaded */
  591. if (defined('_JOSC_J15')) {
  592. if (JPluginHelper::importPlugin('content', 'avreloaded')) {
  593. $app = &JFactory::getApplication();
  594. $res = $app->triggerEvent('onAvReloadedGetVideo', array($html));
  595. if (is_array($res) && (count($res) == 1)) {
  596. $html = $res[0];
  597. }
  598. }
  599. }
  600. /* *** */
  601. return $html.$addjs;
  602. }
  603. function insertComments()
  604. {
  605. return "<div id='Comments'>".$this->getComments()."</div>";
  606. }
  607. function insertForm()
  608. {
  609. $form = new JOSC_form($this->_form); /* template block */
  610. $form->setAbsolute_path($this->_absolute_path);
  611. $form->setLive_site($this->_live_site);
  612. $form->setOnly_registered($this->_only_registered);
  613. $form->setSupport_emoticons($this->_support_emoticons);
  614. $form->setSupport_UBBcode($this->_support_UBBcode);
  615. $form->setEmoticons($this->_emoticons);
  616. $form->setEmoticons_path($this->_emoticons_path);
  617. $form->setTemplate_path($this->_template_path);
  618. $form->setTemplateAbsolutePath($this->_template_absolute_path);
  619. $form->setTemplate_name($this->_name);
  620. $form->setContentId($this->_content_id);
  621. $form->setComponent($this->_component);
  622. $form->setSectionid($this->_sectionid);
  623. $form->setCaptcha($this->_captcha);
  624. $form->setNotifyUsers($this->_notify_users);
  625. $form->setEnterWebsite($this->_enter_website);
  626. $form->setEmoticonWCount($this->_emoticon_wcount);
  627. $form->setFormAreaCols($this->_form_area_cols);
  628. $form->set_tname($this->_tname);
  629. $form->set_temail($this->_temail);
  630. $form->set_twebsite($this->_twebsite);
  631. $form->set_tnotify($this->_tnotify);
  632. return $form->form_htmlCode();
  633. }
  634. function comments($number)
  635. {
  636. if ($number < 1) $comments = _JOOMLACOMMENT_COMMENTS_0;
  637. elseif ($number == 1) $comments = _JOOMLACOMMENT_COMMENTS_1;
  638. elseif ($number >= 2 && $number <= 4) $comments = _JOOMLACOMMENT_COMMENTS_2_4;
  639. else $comments = _JOOMLACOMMENT_COMMENTS_MORE;
  640. return $comments;
  641. }
  642. function insertCountButton()
  643. {
  644. if (defined('_JOSC_J15'))
  645. $database =& JFactory::getDBO();
  646. else
  647. global $database;
  648. $address = $this->_comObject->linkToContent( $this->_content_id );
  649. $com = $this->_component;
  650. /*
  651. * READON BLOCK
  652. */
  653. $query = "SELECT COUNT(*) FROM #__comment WHERE contentid='$this->_content_id' AND component='$com' AND published='1'";
  654. $database->SetQuery($query);
  655. $number = $database->loadResult();
  656. if (!$number) $number = 0;
  657. $html = $this->_readon;
  658. /*
  659. * no blocks
  660. */
  661. /* {READON_xxx} */
  662. $html = str_replace('{READON_LINK}', $address , $html);
  663. $html = str_replace('{READON_WRITE_COMMENT}', _JOOMLACOMMENT_WRITECOMMENT, $html);
  664. $html = str_replace('{READON_COUNT}', $number, $html);
  665. $html = str_replace('{READON_COMMENTS}', $this->comments($number), $html);
  666. /*
  667. * PREVIEW BLOCK
  668. */
  669. /* {BLOCK-preview} */
  670. if ($this->_preview_visible) {
  671. $database->SetQuery("SELECT * FROM #__comment WHERE contentid='$this->_content_id' AND component='$com' AND published='1' ORDER BY date DESC");
  672. $data = $database->loadAssocList();
  673. }
  674. $display = $this->_preview_visible && ($data!=null);
  675. $html = JOSC_utils::checkBlock('BLOCK-preview', $display, $html);
  676. if ($display) {
  677. $index = 0;
  678. $previewlines = '';
  679. foreach($data as $item) {
  680. if ($index >= $this->_preview_lines)
  681. break;
  682. if ($item['title'] != '') {
  683. $title = $item['title'];
  684. } else {
  685. $title = $item['comment'];
  686. }
  687. if (strlen($title) > $this->_preview_length)
  688. $title = substr($title, 0, $this->_preview_length) . '...';
  689. $previewline = $this->_previewline;
  690. /* {PREVIEW_LINK} */
  691. $previewline = str_replace('{PREVIEW_LINK}', $address, $previewline);
  692. /* {PREVIEW_DATE} */
  693. $previewline = str_replace('{PREVIEW_DATE}', JOSC_utils::getLocalDate($item['date'],$this->_date_format) , $previewline);//date($this->_date_format,strtotime($item['date'])) , $previewline);
  694. /* {PREVIEW_TITLE} */
  695. $previewline = str_replace('{PREVIEW_TITLE}', $title, $previewline);
  696. /* {PREVIEW_TITLE} */
  697. $previewline = str_replace('{id}', $item['id'], $previewline);
  698. $index++;
  699. $previewlines .= $previewline;
  700. }
  701. /* {preview-lines} */
  702. $html = str_replace('{preview-lines}', $previewlines, $html);
  703. }
  704. return $html;
  705. }
  706. function visual_htmlCode()
  707. {
  708. // global $option, $task;
  709. $html = "";
  710. $css = $this->CSS(); /* empty if no cache */
  711. // $contentId = intval($this->decodeData_Charset('id'));
  712. /*
  713. * if check htmlCode -> html code
  714. * else if check readon -> readon
  715. * else nothing
  716. *
  717. */
  718. $checkVisual = $this->_comObject->checkVisual( $this->_content_id );
  719. if ($checkVisual)
  720. {
  721. $html .= JOSC_jscript::insertJavaScript($this->_live_site);
  722. /*
  723. * get template blocks
  724. * _body (container)
  725. * _menu
  726. * _search
  727. * _searchResults
  728. * _post
  729. * _form
  730. * _poweredby
  731. */
  732. $this->parse(false);
  733. /*
  734. * construct HTML (by replacement...)
  735. */
  736. $html .= "<div id='comment'>";
  737. if ($this->_body) {
  738. $html .= $this->_body;
  739. $html = JOSC_utils::checkBlock('library', $this->_template_library, $html); /* js scripts ... */
  740. $html = JOSC_utils::checkBlock('menu', false, $html, $this->insertMenu());
  741. $html = JOSC_utils::checkBlock('post', false, $html, $this->insertComments());
  742. $html = JOSC_utils::checkBlock('form', false, $html, $this->insertForm());
  743. $html = JOSC_utils::checkBlock('pagenav', false, $html, $this->insertPageNav());
  744. $html = JOSC_utils::checkBlock('poweredby', false, $html, $this->insertPoweredby());
  745. } else {
  746. $html .= $this->insertMenu();
  747. if ($this->_sort_downward) {
  748. $html .= $this->insertForm();
  749. $html .= $this->insertComments();
  750. } else {
  751. $html .= $this->insertComments();
  752. $html .= $this->insertForm();
  753. }
  754. $html .= $this->insertPoweredby();
  755. }
  756. $html .= $this->insertHiddenCopyright();
  757. $html .= "</div>";
  758. $html .= $this->jscriptInit();
  759. $html .= $css;
  760. } elseif ($this->_show_readon) {
  761. /*
  762. * get template blocks
  763. * _readon
  764. * _previewlines
  765. */
  766. $this->parse(true);
  767. $html .= $this->insertCountButton();
  768. $html .= $css;
  769. } else
  770. return "";
  771. return $html;
  772. }
  773. }
  774. class JOSC_board extends JOSC_visual {
  775. // var $_contentId; /* row->id */
  776. var $_josctask;
  777. var $_userid;
  778. var $_usertype;
  779. var $_tname;
  780. var $_ttitle;
  781. var $_tcomment;
  782. var $_twebsite;
  783. var $_temail;
  784. var $_comment_id;
  785. var $_content_id = 0; /* row-<id OR
  786. * decode content_id from url (comes from the add new comment form)
  787. * -> deleteall, editpost, getComments, gotoPost
  788. */
  789. var $_search_keyword;
  790. var $_search_phrase;
  791. var $_charset;
  792. function JOSC_board($absolutePath, $liveSite, &$comObject, &$exclude, &$row, &$params)
  793. { /* be carefull, board is used in component but also in module !! */
  794. $this->JOSC_properties($absolutePath, $liveSite, $comObject, $exclude, $row, $params);
  795. }
  796. function setContentId($value)
  797. {
  798. $this->_content_id = $value;
  799. }
  800. function setUser()
  801. {
  802. if (defined('_JOSC_J15'))
  803. $database =& JFactory::getDBO();
  804. else
  805. global $database;
  806. /* also in post ! and notification */
  807. $query = "SELECT * FROM #__users WHERE id='".$this->_userid."' LIMIT 1";
  808. $database->SetQuery($query);
  809. $result = $database->loadAssocList();
  810. if ($result) {
  811. $user = $result[0];
  812. $this->_usertype = $user['usertype'];
  813. $this->_tname = $this->_use_name ? $user['name'] : $user['username'];
  814. $this->_temail = $user['email'];
  815. }
  816. }
  817. function voting($item, $mode)
  818. {
  819. if (defined('_JOSC_J15'))
  820. $database =& JFactory::getDBO();
  821. else
  822. global $database;
  823. $t = time()-3 * 86400;
  824. $database->SetQuery("DELETE FROM #__comment_voting WHERE time<'$t'");
  825. $database->Query();
  826. $database->SetQuery("SELECT COUNT(*) FROM #__comment_voting WHERE id='" . $item['id'] . "' AND ip='" . $_SERVER['REMOTE_ADDR'] . "'");
  827. $exists = $database->loadResult();
  828. if (!$exists) {
  829. $item["voting_$mode"]++;
  830. $database->SetQuery("
  831. UPDATE #__comment SET
  832. voting_$mode='" . $item["voting_$mode"] . "'
  833. WHERE id=$this->_comment_id");
  834. $database->Query() or die('Database error: voting(1)!');
  835. $database->SetQuery("INSERT INTO #__comment_voting(id,ip,time)
  836. VALUES(
  837. '" . $item['id'] . "',
  838. '" . $_SERVER['REMOTE_ADDR'] . "',
  839. '" . time() . "')");
  840. $database->Query() or die("Database error: voting(2)!");
  841. }
  842. $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
  843. header($header);
  844. $xml = '<?xml version="1.0" standalone="yes"?><voting><id>' . $item['id'] . '</id><yes>' . $item["voting_yes"] . '</yes><no>' . $item["voting_no"] . '</no></voting>';
  845. $this->_comObject->cleanComponentCache();
  846. exit($xml);
  847. }
  848. // function getNewPost($sort, &$data)
  849. // {
  850. // global $database;
  851. // $database->SetQuery("SELECT * FROM #__comment WHERE contentid='$this->_content_id' AND published='1' ORDER BY id $sort");
  852. // $data = $database->loadAssocList(); // or die('Database error: getNewPost!');
  853. // }
  854. function isBlocked($ip)
  855. {
  856. if ($this->_ban != '') {
  857. $ipList = split(',', $this->_ban);
  858. foreach($ipList as $item) {
  859. if (trim($item) == $ip) return true;
  860. }
  861. }
  862. return false;
  863. }
  864. // function censorTextOLD($text)
  865. // {
  866. // if ($this->_censorship_enable && is_array($this->_censorship_words)) {
  867. // if ($this->_censorship_case_sensitive) $replace = str_replace;
  868. // else $replace = str_ireplace;
  869. // foreach($this->_censorship_words as $word) {
  870. // $word = trim($word);
  871. // if (strpos($word, '=')) {
  872. // $word = explode('=', $word);
  873. // $text = $replace(trim($word[0]), trim($word[1]), $text);
  874. // } else $text = $replace($word, JOSC_strutils::str_fill(strlen($word), '*'), $text);
  875. // }
  876. // }
  877. // return $text;
  878. // }
  879. function censorText($text)
  880. {
  881. return JOSC_utils::censorText($text,$this->_censorship_enable,$this->_censorship_words,$this->_censorship_case_sensitive);
  882. }
  883. function insertNewPost($ajax = false)
  884. {
  885. $ip = $_SERVER['REMOTE_ADDR'];
  886. if ($this->isBlocked($ip)) return false;
  887. global $my;
  888. if (defined('_JOSC_J15'))
  889. $database =& JFactory::getDBO();
  890. else
  891. global $database;
  892. $debug = '';
  893. $com = $this->_component;
  894. $userid = $this->_userid;
  895. $name = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tname)));
  896. $email = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_temail)));
  897. $website = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_twebsite)));
  898. if ( $website && strncmp( "http://", $website, 7 )!=0 ) $website = "http://" . $website;
  899. $website = htmlentities($website);//ampReplace($website);
  900. $notify = JOSC_utils::mysql_escape_string(strip_tags($this->_tnotify)) ? true : false ;
  901. $title = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_ttitle)));
  902. $comment = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tcomment)));
  903. if (!$comment) $comment = _JOOMLACOMMENT_EMPTYCOMMENT;
  904. $published = $this->_autopublish || JOSC_utils::isModerator($this->_moderator);
  905. $parent_id = $this->_parent_id;
  906. $database->SetQuery("
  907. INSERT INTO #__comment
  908. (contentid,component,ip,userid,usertype,date,name,email,website,notify,title,comment,published,voting_yes,voting_no,parentid)
  909. VALUES(
  910. '$this->_content_id',
  911. '$com',
  912. '$ip',
  913. '$userid',
  914. '',
  915. now(),
  916. '$name',
  917. '$email',
  918. '$website',
  919. '$notify',
  920. '$title',
  921. '$comment',
  922. '$published',
  923. '0',
  924. '0',
  925. '$parent_id'
  926. )");
  927. $result=$database->Query() or die(_JOOMLACOMMENT_SAVINGFAILED); //.$database->getQuery());
  928. $this->_comment_id = $database->insertid();
  929. $notification = new JOSC_notification($this, $this->_comment_id, $this->_content_id);
  930. $notification->setNotifyAllPostOfUser($userid, $email, $notify);
  931. $notification->lists['name'] = $name;
  932. $notification->lists['title'] = $title;
  933. $notification->lists['notify'] = $notify;
  934. $notification->lists['comment'] = $comment;
  935. if ($published) {
  936. $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_NEW_SUBJECT;
  937. $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_NEW_MESSAGE;
  938. $templist = $notification->getMailList($this->_content_id,$email);
  939. $notification->notifyMailList( $templist );
  940. } else {
  941. $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_TOBEAPPROVED_SUBJECT;
  942. $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_TOBEAPPROVED_MESSAGE;
  943. if (!JOSC_utils::isModerator($this->_moderator)) {
  944. $templist = $notification->getMailList_moderator();
  945. $notification->notifyMailList($templist);
  946. }
  947. }
  948. if ($ajax) {
  949. $data = $this->getComments(true);
  950. // if ($this->_tree) {
  951. // $this->getNewPost('ASC', $data); /* get all post of the content_id */
  952. // if ($data) {
  953. // $id = $data[sizeOf($data)-1]['id'];
  954. // $data = JOSC_utils::buildTree($data);
  955. // $after = -1;
  956. // /* look for the right place */
  957. // foreach($data as $item) {
  958. // if ($item['id'] == $id) {
  959. // $item['after'] = $after;
  960. // $item['view'] = $published;
  961. // $item['debug'] = $debug;
  962. // $item['noerror'] = 1;
  963. // return $item;
  964. // }
  965. // $after = $item['id'];
  966. // }
  967. // }
  968. // } else {
  969. // $this->getNewPost('DESC LIMIT 1', $data);
  970. // }
  971. /* $data[0]['view'] = $published;
  972. $data[0]['debug'] = $debug;
  973. $data[0]['noerror'] = 1;
  974. return $data[0];
  975. */
  976. $after = -1;
  977. /* look for the right place */
  978. foreach($data as $item) {
  979. if ($item['id'] == $this->_comment_id) {
  980. $item['after'] = $after;
  981. $item['view'] = $published;
  982. $item['debug'] = $debug;
  983. $item['noerror'] = 1;
  984. return $item;
  985. }
  986. $after = $item['id'];
  987. }
  988. $data[0]['view'] = $published;
  989. $data[0]['debug'] = $debug;
  990. $data[0]['noerror'] = 1;
  991. return $data[0];
  992. } else return $published;
  993. }
  994. function editPost()
  995. {
  996. $ip = $_SERVER['REMOTE_ADDR'];
  997. if ($this->isBlocked($ip)) return false;
  998. if (defined('_JOSC_J15'))
  999. $database =& JFactory::getDBO();
  1000. else
  1001. global $database;
  1002. $debug = '';
  1003. $database->SetQuery("SELECT * FROM #__comment WHERE id='$this->_comment_id'");
  1004. $item = $database->loadAssocList();
  1005. if ($this->checkEditPost($item[0])) {
  1006. $title = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_ttitle)));
  1007. $comment = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tcomment)));
  1008. $website = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_twebsite)));
  1009. if ( $website && strncmp( "http://", $website, 7 )!=0 ) $website = "http://" . $website;
  1010. $website = htmlentities($website);//ampReplace($website);
  1011. $notify = JOSC_utils::mysql_escape_string(strip_tags($this->_tnotify)) ? '1' : '0' ;
  1012. $query = "
  1013. UPDATE #__comment SET
  1014. date=now()
  1015. ,title='$title'
  1016. ,comment='$comment'
  1017. ,website='$website'
  1018. ,notify='$notify'
  1019. WHERE id=$this->_comment_id";
  1020. $database->SetQuery($query);
  1021. $database->Query() or die(_JOOMLACOMMENT_EDITINGFAILED . "\n $query");
  1022. $database->SetQuery("SELECT * FROM #__comment WHERE id='$this->_comment_id' AND published='1' LIMIT 1");
  1023. $data = $database->loadAssocList() or die('Database error: editPost!');
  1024. $notification = new JOSC_notification($this, $this->_comment_id, $this->_content_id);
  1025. $notification->setNotifyAllPostOfUser($item[0]['userid'], $item[0]['email'], $notify);
  1026. /* send email to Moderator */
  1027. if (!JOSC_utils::isModerator($this->_moderator)) {
  1028. $notification->lists['name'] = $item[0]['name'];
  1029. $notification->lists['title'] = $title;
  1030. $notification->lists['notify'] = $item[0]['notify'];
  1031. $notification->lists['comment'] = $comment;
  1032. $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_EDIT_SUBJECT;
  1033. $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_EDIT_MESSAGE;
  1034. $templist = $notification->getMailList_moderator();
  1035. $notification->notifyMailList( $templist );
  1036. }
  1037. $data[0]['view'] = 1;
  1038. $data[0]['debug'] = $debug;
  1039. $data[0]['noerror'] = 1;
  1040. return $data[0];
  1041. }
  1042. }
  1043. /*
  1044. * same as isCommentModerator
  1045. */
  1046. function checkEditPost($item)
  1047. {
  1048. //global $my;
  1049. if (!$item) return false;
  1050. /* edit if registered or comment is own or is moderator */
  1051. if ( JOSC_utils::isCommentModerator($this->_moderator, $item['userid'])) // $item['name'], $item['usertype']))
  1052. return true;
  1053. else
  1054. return false;
  1055. }
  1056. function modify($event = false)
  1057. {
  1058. /* example of call : $this->modify(editPost)
  1059. * event is a method which will be called below as $this->$event(true)
  1060. * where true means ajax call.
  1061. */
  1062. global $my;
  1063. if (!$event) {
  1064. if (!$my->username && $this->_only_registered) {
  1065. /* only registered */
  1066. JOSC_utils::showMessage(_JOOMLACOMMENT_ONLYREGISTERED);
  1067. } else {
  1068. if (!($this->_captcha && !JOSC_security::captchaResult(true))) {
  1069. /* captcha ok */
  1070. $published = $this->insertNewPost();
  1071. unset($this->_tcomment);
  1072. $this->_comObject->cleanComponentCache();
  1073. if ($published) {
  1074. mosRedirect($this->_comObject->linkToContent($this->_content_id, $this->_comment_id));
  1075. } else {
  1076. mosRedirect($this->_comObject->linkToContent($this->_content_id), _JOOMLACOMMENT_BEFORE_APPROVAL);
  1077. }
  1078. }
  1079. }
  1080. mosRedirect($this->_comObject->linkToContent($this->_content_id, $this->_comment_id));
  1081. }
  1082. $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
  1083. header($header);
  1084. if (!($this->_captcha && !JOSC_security::captchaResult(true))) {
  1085. $item = $this->$event(true);
  1086. if (!$item) exit();
  1087. $this->parse();
  1088. $xml = '<?xml version="1.0" standalone="yes"?>';
  1089. $xml .= '<post>';
  1090. $xml .= '<id>' . $item['id'] . '</id>';
  1091. if ($this->_tree && isset($item['after'])) $xml .= '<after>' . $item['after'] . '</after>';
  1092. $xml .= '<published>' . $item['view'] . '</published>';
  1093. $xml .= '<noerror>' . $item['noerror'] . '</noerror>';
  1094. $xml .= '<debug>' . $item['debug'] . '</debug>';
  1095. if ($item['view']) {
  1096. $html = JOSC_utils::cdata(JOSC_utils::filter($this->encodeData_Charset($this->insertPost($item, ''))));
  1097. $xml .= "<body>$html</body>";
  1098. }
  1099. if ($this->_captcha) {
  1100. $captcha = JOSC_utils::cdata(JOSC_security::insertCaptcha('security_refid'));
  1101. $xml .= "<captcha>$captcha</captcha>";
  1102. }
  1103. $xml .= '</post>';
  1104. $this->_comObject->clean

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