PageRenderTime 68ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
  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->cleanComponentCache();
  1105. exit($xml);
  1106. } else if ($this->_captcha) {
  1107. $xml = $this->xml_refreshCaptcha(true);
  1108. exit($xml);
  1109. } else exit;
  1110. }
  1111. function xml_refreshCaptcha($withalert=true)
  1112. {
  1113. $captcha = JOSC_utils::cdata(JOSC_security::insertCaptcha('security_refid'));
  1114. $xml = '<?xml version="1.0" standalone="yes"?>';
  1115. $xml .= '<post>';
  1116. $xml .= '<id>'. ($withalert ? 'captchaalert' : 'captcha' ).'</id>';
  1117. $xml .= "<captcha>$captcha</captcha>";
  1118. $xml .= '<noerror>1</noerror>';
  1119. $xml .= '</post>';
  1120. return $xml;
  1121. }
  1122. function deletePost($id = -1)
  1123. {
  1124. if (defined('_JOSC_J15'))
  1125. $database =& JFactory::getDBO();
  1126. else
  1127. global $database;
  1128. $com = $this->_component;
  1129. $contentid_where = "WHERE contentid='$this->_content_id' AND component='$com' ";
  1130. $where = ($id == -1) ? $contentid_where : "WHERE id='$id'";
  1131. $database->SetQuery("DELETE FROM #__comment $where");
  1132. $database->Query() or die(_JOOMLACOMMENT_DELETINGFAILED);
  1133. $this->_comObject->cleanComponentCache();
  1134. /* send mail to the moderators and to the notified writers */
  1135. if ($id == -1) {
  1136. $database->SetQuery("SELECT id FROM #__comment $where");
  1137. $cids = $database->loadResultArray();
  1138. } else {
  1139. $cids = $id; /* TODO : this has no sens :D */
  1140. }
  1141. $notification = new JOSC_notification($this);
  1142. $notification->notifyComments($cids, 'delete');
  1143. }
  1144. function search()
  1145. {
  1146. $this->parse();
  1147. $search = new JOSC_search($this->_searchResults, $this->_comObject);
  1148. $search->setKeyword($this->_search_keyword);
  1149. $search->setPhrase($this->_search_phrase);
  1150. $search->setDate_format($this->_date_format);
  1151. $search->setAjax($this->_ajax);
  1152. $search->setLocalCharset($this->_local_charset);
  1153. $search->setCensorShip( $this->_censorship_enable,
  1154. $this->_censorship_case_sensitive,
  1155. $this->_censorship_words,
  1156. $this->_censorship_usertypes
  1157. );
  1158. $search->setMaxLength_text($this->_maxlength_text);
  1159. $search->setMaxLength_word($this->_maxlength_word);
  1160. $search->setMaxLength_line($this->_maxlength_line);
  1161. $search->setContentId($this->_content_id);
  1162. $search->setComponent($this->_component);
  1163. $search->setSectionid($this->_sectionid);
  1164. return $search->search_htmlCode();
  1165. }
  1166. function filterAll($item)
  1167. { /* used also by search class */
  1168. $item['name'] = JOSC_utils::filter($this->encodeData_Charset($item['name']));
  1169. $item['title'] = JOSC_utils::filter($this->encodeData_Charset($item['title']));
  1170. $item['comment'] = JOSC_utils::filter($this->encodeData_Charset($item['comment']));
  1171. return $item;
  1172. }
  1173. function decodeURI()
  1174. {
  1175. global $my;
  1176. $this->_request_uri = mosGetParam( $_SERVER, 'REQUEST_URI', '' ); // _JOSC_MOS_ALLOWHTML
  1177. // $this->_request_uri = substr($this->_request_uri, strpos("index.php?"));
  1178. // $link = preg_replace("/(.*)(&josclimit=.*)(&.*|)/", '\\1\\3', $link);
  1179. $this->_josctask = $this->decodeData_Charset('josctask');
  1180. if ($my->username) {
  1181. $this->_userid = $my->id;
  1182. $this->_usertype = $my->usertype;
  1183. $this->_tname = $my->username;
  1184. $this->setUser();
  1185. } else {
  1186. $this->_userid = 0;
  1187. $this->_usertype = 'Unregistered';
  1188. $this->_tname = $this->decodeData_Charset('tname');
  1189. $this->_temail = $this->decodeData_Charset('temail');
  1190. }
  1191. $this->_tnotify = intval($this->decodeData_Charset('tnotify'));
  1192. $this->_twebsite = $this->decodeData_Charset('twebsite');
  1193. $this->_ttitle = $this->decodeData_Charset('ttitle');
  1194. $this->_tcomment = $this->decodeData_Charset('tcomment');
  1195. $this->_comment_id = intval($this->decodeData_Charset('comment_id'));
  1196. // if (!$this->_comment_id) $this->_comment_id = intval(preg_replace("/(.*#josc)(.*)(&.*|)/", '\\2', $this->_request_uri));
  1197. // #xxx is not sent by navigators as FF...
  1198. if (!$this->_content_id) $this->_content_id = intval($this->decodeData_Charset('content_id'));
  1199. if (!$this->_component) $this->_component = strval($this->decodeData_Charset('component'));
  1200. $this->_search_keyword = $this->decodeData_Charset('search_keyword');
  1201. $this->_search_phrase = $this->decodeData_Charset('search_phrase');
  1202. $this->_parent_id = $this->decodeData_Charset('parent_id');
  1203. if ($this->_parent_id == '') $this->_parent_id = '-1';
  1204. $this->_limitstart = intval($this->decodeData_Charset('josclimitstart'));
  1205. //no necessary? if ($this->_limitstart == '') $this->_limitstart = '0';
  1206. }
  1207. function decodeData_Charset($varName) {
  1208. /*
  1209. * javascript(ajax) encodeURI is only UTF-8. so we have to decode ajax send
  1210. * should be solved with joomla 1.5 ! (native utf-8)
  1211. */
  1212. if ($this->_ajax)
  1213. return JOSC_utils::myiconv_decode( JOSC_utils::decodeData($varName), $this->_local_charset );
  1214. else
  1215. return JOSC_utils::decodeData($varName);
  1216. }
  1217. function encodeData_Charset($var) {
  1218. /*
  1219. * javascript(ajax) encodeURI is only UTF-8. so we have to decode ajax send
  1220. * should be solved with joomla 1.5 ! (native utf-8)
  1221. */
  1222. if ($this->_ajax)
  1223. return JOSC_utils::myiconv_encode( $var , $this->_local_charset );
  1224. else
  1225. return $var;
  1226. }
  1227. /*
  1228. * decode URI
  1229. * and execute josctask if 'josctask'(ajax mode)
  1230. * OR insertnewPost if 'tcomment'(not ajax mode)
  1231. */
  1232. function execute()
  1233. {
  1234. if (defined('_JOSC_J15'))
  1235. $database =& JFactory::getDBO();
  1236. else
  1237. global $database;
  1238. /* don't forget if modify josctask
  1239. * that it is first checked in comment.php !
  1240. */
  1241. $this->decodeURI();
  1242. if ($this->_josctask == 'noajax') {
  1243. if ($this->_tcomment)
  1244. $this->modify(false); /* modify in not ajax mode */
  1245. } else {
  1246. $query = "SELECT * FROM #__comment WHERE id='$this->_comment_id' LIMIT 1";
  1247. $database->SetQuery($query);
  1248. $item = $database->loadAssocList();
  1249. $itemsave = $item ? $item[0] : "";
  1250. /* if ($this->_josctask == 'unsubscribe') {
  1251. $notification = new JOSC_notification($this, $this->_comment_id, $this->_content_id);
  1252. $notification->setNotifyAllPostOfUser($userid, $email, $notify);
  1253. }*/
  1254. if ($this->checkEditPost($itemsave)) {
  1255. if ($this->_josctask == 'ajax_delete') {
  1256. $this->deletePost($this->_comment_id);
  1257. exit;
  1258. }
  1259. if ($this->_josctask == 'ajax_edit') $this->modify('editPost');
  1260. }
  1261. if (JOSC_utils::isModerator($this->_moderator)) {
  1262. if ($this->_josctask == 'ajax_delete_all') {
  1263. $this->deletePost();
  1264. exit;
  1265. }
  1266. }
  1267. if ($this->_josctask == 'ajax_insert') {
  1268. /*
  1269. * if parent_id AND only moderator reply -> exit if not moderator
  1270. * because javascript reply deactivated, should not be possible except volontary spam...or delay change of setting
  1271. * else ok.
  1272. */
  1273. if ($this->_parent_id<1 || !$this->_mlink_post || JOSC_utils::isModerator($this->_moderator)) //$this->checkEditPost($itemsave))
  1274. $this->modify('insertNewPost');
  1275. else exit();
  1276. }
  1277. if ($this->_josctask == 'ajax_modify' || $this->_josctask == 'ajax_quote') {
  1278. /*
  1279. * return <post> content of current comment to the FORM
  1280. */
  1281. $item = $this->filterAll($item[0]);
  1282. $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset; not ok for IE ! only utf-8 is possible
  1283. header($header);
  1284. $item['email'] = ($item['userid'] ? JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_AUTOMATICEMAIL)) : $item['email']);
  1285. $xml = '<?xml version="1.0" standalone="yes"?><post>'
  1286. . '<name>' . JOSC_utils::cdata($item['name']) .'</name>'
  1287. . '<title>' . JOSC_utils::cdata($item['title']) . '</title>'
  1288. . '<comment>' . JOSC_utils::cdata($item['comment']) . '</comment>'
  1289. ;
  1290. if ($this->_josctask == 'ajax_modify' && $this->checkEditPost($itemsave)) {
  1291. $xml .= '<email>' . JOSC_utils::cdata($item['email']) . '</email>'
  1292. // . '<userid>' . JOSC_utils::cdata($item['userid']) . '</userid>'
  1293. . '<notify>' . JOSC_utils::cdata($item['notify']) . '</notify>'
  1294. . '<website>' . JOSC_utils::cdata($item['website']) . '</website>'
  1295. ;
  1296. }
  1297. $xml .= '</post>'
  1298. ;
  1299. exit($xml);
  1300. }
  1301. if ($this->_josctask == 'ajax_reload_captcha') {
  1302. $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
  1303. header($header);
  1304. $xml = $this->xml_refreshCaptcha(false);
  1305. exit($xml);
  1306. }
  1307. if ($this->_josctask == 'ajax_voting_yes') $this->voting($item[0], 'yes');
  1308. if ($this->_josctask == 'ajax_voting_no') $this->voting($item[0], 'no');
  1309. if ($this->_josctask == 'ajax_insert_search') {
  1310. $this->parse();
  1311. $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
  1312. header($header);
  1313. exit($this->insertSearch());
  1314. }
  1315. if ($this->_josctask == 'ajax_search') {
  1316. $header = 'Content-Type: text/xml; charset=utf-8'; //charset='.$this->_local_charset;
  1317. header($header);
  1318. exit($this->search());
  1319. }
  1320. if ($this->_josctask == 'ajax_getcomments') {
  1321. $header = 'Content-Type: text/xml; charset=utf-8'; //charset='.$this->_local_charset;
  1322. header($header);
  1323. $this->parse();
  1324. $html = $this->getComments();
  1325. if (!$html) exit();
  1326. $pagenav = $this->getPageNav();
  1327. $xml = '<?xml version="1.0" standalone="yes"?>';
  1328. $xml .= '<getpost>';
  1329. $xml .= '<limitstart>' . $this->_limitstart . '</limitstart>';
  1330. $xml .= '<body>'.JOSC_utils::cdata(JOSC_utils::filter($this->encodeData_Charset($html))).'</body>';
  1331. $xml .= '<pagenav>'.JOSC_utils::cdata(JOSC_utils::filter($this->encodeData_Charset($pagenav))).'</pagenav>';
  1332. // $xml .= '<debug>'.$this->_display_num.'</debug>';
  1333. $xml .= '</getpost>';
  1334. // $this->_comObject->cleanComponentCache();
  1335. exit($xml);
  1336. }
  1337. }
  1338. }
  1339. }
  1340. class JOSC_tree {
  1341. var $_id;
  1342. var $_counter;
  1343. function getSeed($data, $seed)
  1344. {
  1345. $this->_counter++;
  1346. if ($seed) {
  1347. foreach($seed as $item) {
  1348. $data[$item]['wrapnum'] = $this->_counter;
  1349. $this->_new[] = $data[$item];
  1350. if (isset($data[$item]['seed']) && $data[$item]['seed']) {
  1351. $this->getSeed($data, $data[$item]['seed']);
  1352. $data[$item] = null;
  1353. }
  1354. }
  1355. }
  1356. $this->_counter--;
  1357. }
  1358. function build($data)
  1359. {
  1360. $index = 0;
  1361. $this->_new = null;
  1362. $this->_counter = 0;
  1363. /*
  1364. * TREE :
  1365. * parents can have several direct children
  1366. * their children can have also their own children etc...
  1367. *
  1368. * parent
  1369. * |_ child1
  1370. * | |_ child1.1
  1371. * | | |_ child1.1.1
  1372. * | | |...
  1373. * | |_ child1.2
  1374. * | ...
  1375. * |_ child2
  1376. * ...
  1377. *
  1378. * SEED for one parent is the CHILDS ARRAY
  1379. */
  1380. /*
  1381. * FIRST LOOP : prepare datas
  1382. *
  1383. * $index is $data key (we call it: INDEX)
  1384. *
  1385. * $old[] : key = comment_id / value = INDEX
  1386. *
  1387. * - save INDEX in a new 'treeid' column
  1388. *
  1389. * - for all children: replace parentid value by PARENT INDEX value
  1390. * -> sort must be with parents first !! (means already set in old)
  1391. *
  1392. */
  1393. foreach($data as $item) {
  1394. $old[$item['id']] = $index;
  1395. $data[$index]['treeid'] = $index;
  1396. if ($data[$index]['parentid'] != -1)
  1397. $data[$index]['parentid'] = isset($old[$item['parentid']]) ? $old[$item['parentid']] : -2;
  1398. $index++;
  1399. }
  1400. //$debug .= JOSC_utils::debug_array($data);
  1401. /*
  1402. * 2ND LOOP : construct SEED
  1403. *
  1404. * - for all childrens : construct 1st level 'seed'[]
  1405. */
  1406. foreach($data as $item) {
  1407. /* IS CHILD -> PARENT[SEED][] = CHILD INDEX */
  1408. if ($item['parentid'] >= 0) {
  1409. $data[$item['parentid']]['seed'][] = $item['treeid'];
  1410. // $data[$item['treeid']]['treerootid'] = $this->getRootId($data, $item['parentid']);
  1411. }
  1412. }
  1413. //$debug .= JOSC_utils::debug_array($data);
  1414. foreach($data as $item) {
  1415. /* IS NOT A CHILD -> DATA[] */
  1416. if ($item['parentid'] == -1) {
  1417. $this->_new[] = $item;
  1418. if (isset($item['seed'])) $this->getSeed($data, $item['seed']);
  1419. }
  1420. }
  1421. //$debug .=JOSC_utils::debug_array($this->_new);
  1422. // return $debug;
  1423. return $this->_new;
  1424. }
  1425. function getRootId( &$data, $index )
  1426. {
  1427. if ($data[$index]['parentid']!=-1) {
  1428. /* is a child */
  1429. if (!$data[$index]['treerootid']) {
  1430. /* for every nodes, treerootid = root */
  1431. $data[$index]['treerootid'] = $this->getRootId($data, $data[$index]['parentid']);
  1432. }
  1433. return $data[$index]['treerootid'];
  1434. } else {
  1435. return $data[$index]['treeid'];
  1436. }
  1437. }
  1438. }
  1439. class JOSC_support {
  1440. var $_comObject;
  1441. var $_ajax;
  1442. var $_local_charset;
  1443. var $_absolute_path;
  1444. var $_live_site;
  1445. var $_template_absolute_path;
  1446. var $_template_path;
  1447. var $_template_name;
  1448. var $_only_registered;
  1449. var $_website_registered;
  1450. var $_support_emoticons;
  1451. var $_support_UBBcode;
  1452. var $_support_pictures;
  1453. var $_pictures_maxwidth;
  1454. var $_support_quotecode;
  1455. var $_support_link;
  1456. var $_hide;
  1457. var $_emoticons;
  1458. var $_emoticons_path;
  1459. var $_censorship_enable;
  1460. var $_censorship_case_sensitive;
  1461. var $_censorship_words;
  1462. var $_censorship_usertypes;
  1463. var $_content_id;
  1464. var $_component;
  1465. var $_sectionid;
  1466. var $_moderator;
  1467. var $_show_readon;
  1468. var $_date_format;
  1469. var $_maxlength_text;
  1470. var $_maxlength_word;
  1471. var $_maxlength_line;
  1472. function JOSC_support(&$comObject)
  1473. {
  1474. $this->_comObject = $comObject;
  1475. }
  1476. function setAjax($value)
  1477. {
  1478. $this->_ajax = $value;
  1479. }
  1480. function setLocalCharset($value)
  1481. {
  1482. $this->_local_charset = $value;
  1483. }
  1484. function setAbsolute_path($value)
  1485. {
  1486. $this->_absolute_path = $value;
  1487. }
  1488. function setLive_site($value)
  1489. {
  1490. $this->_live_site = $value;
  1491. }
  1492. function setTemplate_path($value)
  1493. {
  1494. $this->_template_path = $value;
  1495. }
  1496. function setTemplateAbsolutePath($value)
  1497. {
  1498. $this->_template_absolute_path = $value;
  1499. }
  1500. function setTemplate_name($value)
  1501. {
  1502. $this->_template_name = $value;
  1503. }
  1504. function setOnly_registered($value)
  1505. {
  1506. $this->_only_registered = $value;
  1507. }
  1508. function setWebsiteRegistered($value)
  1509. {
  1510. $this->_website_registered = $value;
  1511. }
  1512. function setSupport_emoticons($value)
  1513. {
  1514. $this->_support_emoticons = $value;
  1515. }
  1516. function setSupport_UBBcode($value)
  1517. {
  1518. $this->_support_UBBcode = $value;
  1519. }
  1520. function setSupport_pictures($value,$maxwidth='')
  1521. {
  1522. $this->_support_pictures = $value;
  1523. $this->_pictures_maxwidth = $maxwidth;
  1524. }
  1525. function getSupport_pictures()
  1526. { /* used in module */
  1527. return $this->_support_pictures;
  1528. }
  1529. function setSupport_quotecode($value)
  1530. {
  1531. $this->_support_quotecode = $value;
  1532. }
  1533. function getSupport_quotecode()
  1534. { /* used in module */
  1535. return $this->_support_quotecode;
  1536. }
  1537. function setSupport_link($value)
  1538. {
  1539. $this->_support_link = $value;
  1540. }
  1541. function getSupport_link()
  1542. { /* used in module */
  1543. return $this->_support_link;
  1544. }
  1545. function setHide($value)
  1546. {
  1547. $this->_hide = $value;
  1548. }
  1549. function setEmoticons($value)
  1550. {
  1551. $this->_emoticons = $value;
  1552. }
  1553. function setEmoticons_path($value)
  1554. {
  1555. $this->_emoticons_path = $value;
  1556. }
  1557. function setContentId($value)
  1558. {
  1559. $this->_content_id = $value;
  1560. }
  1561. function setComponent($value)
  1562. {
  1563. $this->_component = $value;
  1564. }
  1565. function setSectionid($value)
  1566. {
  1567. $this->_sectionid = $value;
  1568. }
  1569. function setModerator($value)
  1570. {
  1571. $this->_moderator = $value;
  1572. }
  1573. function setReadon($value)
  1574. {
  1575. $this->_show_readon= $value;
  1576. }
  1577. function setDate_format($value)
  1578. {
  1579. $this->_date_format = $value;
  1580. }
  1581. function setCensorShip($enable, $case_sensitive, $words, $usertypes ) {
  1582. $this->_censorship_enable = $enable;
  1583. $this->_censorship_case_sensitive = $case_sensitive;
  1584. $this->_censorship_words = $words;
  1585. $this->_censorship_usertypes = $usertypes;
  1586. }
  1587. function setMaxLength_text($value)
  1588. {
  1589. $this->_maxlength_text = $value;
  1590. }
  1591. function getMaxLength_text()
  1592. { /* used in module */
  1593. return $this->_maxlength_text;
  1594. }
  1595. function setMaxLength_word($value)
  1596. {
  1597. $this->_maxlength_word = $value;
  1598. }
  1599. function getMaxLength_word()
  1600. { /* used in module */
  1601. return $this->_maxlength_word;
  1602. }
  1603. function setMaxLength_line($value)
  1604. {
  1605. $this->_maxlength_line = $value;
  1606. }
  1607. function getMaxLength_line()
  1608. { /* used in module */
  1609. return $this->_maxlength_line;
  1610. }
  1611. function decodeData_Charset($varName) {
  1612. /*
  1613. * javascript(ajax) encodeURI is only UTF-8. so we have to decode ajax send
  1614. * should be solved with joomla 1.5 ! (native utf-8)
  1615. */
  1616. if ($this->_ajax)
  1617. return JOSC_utils::myiconv_decode( JOSC_utils::decodeData($varName), $this->_local_charset );
  1618. else
  1619. return JOSC_utils::decodeData($varName);
  1620. }
  1621. function encodeData_Charset($var) {
  1622. /*
  1623. * javascript(ajax) encodeURI is only UTF-8. so we have to decode ajax send
  1624. * should be solved with joomla 1.5 ! (native utf-8)
  1625. */
  1626. if ($this->_ajax)
  1627. return JOSC_utils::myiconv_encode( $var , $this->_local_charset );
  1628. else
  1629. return $var;
  1630. }
  1631. function censorText($text)
  1632. {
  1633. return JOSC_utils::censorText($text,$this->_censorship_enable,$this->_censorship_words,$this->_censorship_case_sensitive);
  1634. }
  1635. function formHiddenValues($contentid, $component, $sectionid )
  1636. { /* used also in BOARD ! */
  1637. $hidden = JOSC_utils::inputHidden('content_id', $contentid);
  1638. $hidden .= JOSC_utils::inputHidden('component', $component);
  1639. $hidden .= JOSC_utils::inputHidden('joscsectionid', $sectionid);
  1640. return $hidden;
  1641. }
  1642. }
  1643. class JOSC_menu extends JOSC_support {
  1644. var $_menu;
  1645. var $_rss;
  1646. var $_no_search;
  1647. function JOSC_menu($value)
  1648. {
  1649. $this->_menu = $value;
  1650. }
  1651. function setRSS($value)
  1652. {
  1653. $this->_rss = $value;
  1654. }
  1655. function setNoSearch($value)
  1656. {
  1657. $this->_no_search = $value;
  1658. }
  1659. function insertButton($text, $link, $icon = '')
  1660. {
  1661. if ($icon) $icon = "<img class='menuicon' src='$icon' alt='$icon' />";
  1662. return "<td class='button'><a id='$text' href='$link'>$icon$text</a></td>";
  1663. }
  1664. function menu_htmlCode()
  1665. {
  1666. global $my;
  1667. $html = $this->_menu;
  1668. $only_registered = !$my->username && $this->_only_registered;
  1669. /* {_JOOMLACOMMENT_COMMENTS_TITLE} */
  1670. $html = str_replace('{_JOOMLACOMMENT_COMMENTS_TITLE}', _JOOMLACOMMENT_COMMENTS_TITLE, $this->_menu);
  1671. /* {template_live_site} */
  1672. $html = str_replace('{template_live_site}', $this->_template_path.'/'.$this->_template_name, $html);
  1673. /* {BLOCK-add_new} _JOOMLACOMMENT_ADDNEW */
  1674. $display = !$only_registered;
  1675. $html = JOSC_utils::checkBlock('BLOCK-add_new', $display, $html);
  1676. if ($display) {
  1677. $html = str_replace('{_JOOMLACOMMENT_ADDNEW}', _JOOMLACOMMENT_ADDNEW, $html);
  1678. $html = str_replace('{BUTTON_ADDNEW_js}', 'JOSC_addNew()', $html);
  1679. }
  1680. /* {BLOCK-delete_all} _JOOMLACOMMENT_DELETEALL */
  1681. $display = JOSC_utils::isModerator($this->_moderator);
  1682. $html = JOSC_utils::checkBlock('BLOCK-delete_all', $display, $html);
  1683. if ($display) {
  1684. $html = str_replace('{_JOOMLACOMMENT_DELETEALL}', _JOOMLACOMMENT_DELETEALL, $html);
  1685. $html = str_replace('{BUTTON_DELETEALL_js}', 'JOSC_deleteAll()', $html);
  1686. }
  1687. /* {BLOCK-search} _JOOMLACOMMENT_SEARCH */
  1688. $display = !$this->_no_search;
  1689. $html = JOSC_utils::checkBlock('BLOCK-search', $display, $html);
  1690. if ($display) {
  1691. $html = str_replace('{_JOOMLACOMMENT_SEARCH}', _JOOMLACOMMENT_SEARCH, $html);
  1692. $html = str_replace('{BUTTON_SEARCH_js}', 'JOSC_searchForm()', $html);
  1693. }
  1694. /* {BLOCK-rss} _JOOMLACOMMENT_RSS */
  1695. $display = $this->_rss;
  1696. $html = JOSC_utils::checkBlock('BLOCK-rss', $display, $html);
  1697. if ($display) {
  1698. $html = str_replace('{_JOOMLACOMMENT_RSS}', _JOOMLACOMMENT_RSS, $html);
  1699. $html = str_replace('{BUTTON_RSS_URL}', "index2.php?option=com_comment&no_html=1&josctask=rss&contentid=$this->_content_id", $html);
  1700. }
  1701. return $html;
  1702. }
  1703. }
  1704. class JOSC_post extends JOSC_support {
  1705. var $_post;
  1706. var $_item;
  1707. var $_css;
  1708. var $_tree;
  1709. var $_mlink_post;
  1710. var $_tree_indent;
  1711. var $_IP_visible;
  1712. var $_IP_partial;
  1713. var $_IP_caption;
  1714. var $_IP_usertypes;
  1715. var $_voting_visible;
  1716. var $_avatar;
  1717. var $_user_id;
  1718. var $_use_name;
  1719. var $_notify_users;
  1720. var $_notify_moderator;
  1721. // var $_ubbcodeArray;
  1722. function JOSC_post($value)
  1723. {
  1724. $this->_post = $value;
  1725. }
  1726. /*
  1727. * AGE comment: the use of the following methods to just set the value seems heavy
  1728. * but this is a professional way to code from joomlacomment developpers
  1729. */
  1730. function setItem($value)
  1731. {
  1732. $this->_item = $value;
  1733. $this->setUser(); /* _use_name has to be set ! refresh comment user values according to */
  1734. }
  1735. function setUser()
  1736. {
  1737. if (defined('_JOSC_J15'))
  1738. $database =& JFactory::getDBO();
  1739. else
  1740. global $database;
  1741. if (!$this->_item || !$this->_item['userid'])
  1742. return;
  1743. $query = "SELECT * FROM #__users WHERE id='".$this->_item['userid']."' LIMIT 1";
  1744. $database->SetQuery($query);
  1745. $result = $database->loadAssocList();
  1746. if ($result) {
  1747. $user = $result[0];
  1748. $this->_item['name'] = $this->_use_name ? $user['name'] : $user['username'];
  1749. $this->_item['usertype'] = $user['usertype'];
  1750. $this->_item['email'] = $user['email'];
  1751. }
  1752. }
  1753. function setCSS($value)
  1754. {
  1755. $this->_css = $value;
  1756. }
  1757. function setTree($value)
  1758. {
  1759. $this->_tree = $value;
  1760. }
  1761. function setMLinkPost($value)
  1762. {
  1763. $this->_mlink_post = $value;
  1764. }
  1765. function setTree_indent($value)
  1766. {
  1767. $this->_tree_indent = $value;
  1768. }
  1769. function setIP_visible($value)
  1770. {
  1771. $this->_IP_visible = $value;
  1772. }
  1773. function setIP_partial($value)
  1774. {
  1775. $this->_IP_partial = $value;
  1776. }
  1777. function setIP_caption($value)
  1778. {
  1779. $this->_IP_caption = $value;
  1780. }
  1781. function setIP_usertypes($value)
  1782. {
  1783. $this->_IP_usertypes = $value;
  1784. }
  1785. function setVoting_visible($value)
  1786. {
  1787. $this->_voting_visible = $value;
  1788. }
  1789. function setAvatar($value)
  1790. {
  1791. $this->_avatar = $value;
  1792. }
  1793. function setUseName($value)
  1794. {
  1795. $this->_use_name = $value;
  1796. }
  1797. function setUser_id($value)
  1798. {
  1799. $this->_user_id = $value;
  1800. }
  1801. function setNotify_users($users, $moderators)
  1802. {
  1803. $this->_notify_users = $users;
  1804. $this->_notify_moderator = $moderators;
  1805. }
  1806. function highlightAdmin($usertype)
  1807. {
  1808. if ($usertype=='Super Administrator') $usertype = 'SAdministrator';
  1809. if (strpos($usertype, 'Administrator'))
  1810. $usertype = "<span class='administrator'>$usertype</span>";
  1811. return $usertype;
  1812. }
  1813. function anonymous($name)
  1814. {
  1815. if ($name == '') $name = _JOOMLACOMMENT_ANONYMOUS;
  1816. return $name;
  1817. }
  1818. function space($title)
  1819. {
  1820. if ($title == '') return '';
  1821. return ' - ';
  1822. }
  1823. function IP($ip, $usertype, $visible, $partial, $caption)
  1824. {
  1825. global $my;
  1826. $int_usertype = JOSC_utils::getJOSCUserType($usertype); /* -1 for unresgistered */
  1827. $int_myusertype = JOSC_utils::getJOSCUserType($my->usertype); /* -1 for unregistered */
  1828. $html = "";
  1829. if ($visible) {
  1830. /* only if comment writer usertype is in _IP_usertypes */
  1831. $visible = in_array($int_usertype, $this->_IP_usertypes);
  1832. } elseif ($int_myusertype>=0) {
  1833. /* not visible: only if my->usertype is in _IP_usertypes */
  1834. $visible = in_array($int_myusertype, $this->_IP_usertypes);
  1835. }
  1836. if ($visible) {
  1837. if ($int_usertype<0) {
  1838. /* IP address */
  1839. if ($partial) {
  1840. $ip = JOSC_utils::partialIP($ip);
  1841. }
  1842. $html = $caption . $ip;
  1843. } else {
  1844. /* usertype string */
  1845. $html = $this->highlightAdmin($usertype);
  1846. }
  1847. }
  1848. return $html;
  1849. }
  1850. function linkQuote($id)
  1851. {
  1852. return "<a href = 'javascript:JOSC_quote($id)'>" . _JOOMLACOMMENT_QUOTE . "</a>";
  1853. }
  1854. function linkPost($id)
  1855. {
  1856. return "<a href='javascript:JOSC_reply($id)'>" . _JOOMLACOMMENT_REPLY . '</a>';
  1857. }
  1858. function linkEdit($id)
  1859. {
  1860. return "<a href='javascript:JOSC_editComment($id)'>" . _JOOMLACOMMENT_EDIT . '</a>';
  1861. }
  1862. function linkDelete($id)
  1863. {
  1864. return "<a href='javascript:JOSC_deleteComment($id)'>" . _JOOMLACOMMENT_DELETE . '</a>';
  1865. }
  1866. function voting_cell($mode, $num, $id)
  1867. {
  1868. return "<td><a id='$mode$id' class='voting_$mode' href='javascript:JOSC_voting($id,\"$mode\")'>$num</a></td>";
  1869. }
  1870. function voting($voting_no, $voting_yes, $id, $contentId)
  1871. {
  1872. $html = '';
  1873. if ($this->_voting_visible) {
  1874. if ($voting_yes == '') {
  1875. $voting_yes = 0;
  1876. $voting_no = 0;
  1877. }
  1878. $html .= "<table cellspacing='0' cellpadding='0' border='0'>";
  1879. $html .= "<tr>" . $this->voting_cell('yes', $voting_yes, $id);
  1880. $html .= "<td>&nbsp;</td>";
  1881. $html .= $this->voting_cell('no', $voting_no, $id) . "</tr>";
  1882. $html .= "</table>";
  1883. }
  1884. /*
  1885. * If voting no are 2x greater than voting yes => mode hide
  1886. */
  1887. $this->_hide = (($voting_no + 1) > (($voting_yes + 1) * 2));
  1888. return $html;
  1889. }
  1890. function parseUBBCode($html)
  1891. {
  1892. $ubbcode = new JOSC_ubbcode($html);
  1893. $ubbcode->setMaxlength($this->_maxlength_word, $this->_maxlength_text, $this->_maxlength_line);
  1894. $ubbcode->setSupport_emoticons($this->_support_emoticons);
  1895. $ubbcode->setSupport_UBBcode($this->_support_UBBcode);
  1896. $ubbcode->setSupport_quotecode($this->_support_quotecode);
  1897. $ubbcode->setSupport_link($this->_support_link);
  1898. $ubbcode->setSupport_pictures($this->_support_pictures,$this->_pictures_maxwidth);
  1899. $ubbcode->setHide($this->_hide);
  1900. $ubbcode->setEmoticons($this->_emoticons);
  1901. $ubbcode->setEmoticons_path($this->_emoticons_path);
  1902. $html = $ubbcode->ubbcode_parse();
  1903. return($html);
  1904. }
  1905. function envelope($html, $id, $wrapnum)
  1906. {
  1907. $wrapnum = ($this->_tree) ? $wrapnum : 0;
  1908. /* $result = "<table class='postcontainer' id='post$id' width='100%' cellpadding='0' cellspacing='0' style='padding-left: $wrapnum;'>";
  1909. $result .= "<tr><td><a name='josc$id'></a>$html</td></tr>";
  1910. $result .= "</table>";*/
  1911. $result = str_replace('{wrapnum}',$wrapnum, $html);
  1912. return $result;
  1913. }
  1914. function setMaxLength($text)
  1915. {
  1916. return JOSC_utils::setMaxLength($text,$this->_maxlength_text);
  1917. }
  1918. // function wrapText($text)
  1919. // {
  1920. // return JOSC_utils::wrapText($text,$this->_maxlength_word);
  1921. // }
  1922. function profileLink($s, $id)
  1923. {
  1924. global $mosConfig_live_site;
  1925. return $id ? "<a href='$mosConfig_live_site/index.php?option=com_comprofiler&task=userProfile&user=$id'>$s</a>" : $s;
  1926. }
  1927. function notifyLink($notify, $notify_users )
  1928. {
  1929. $notifyactive = ($notify_users && $notify) ? '1' : '0';
  1930. return "<span class='postnotify$notifyactive' title='".( $notifyactive ? ( _JOOMLACOMMENT_NOTIFYTXT1 ) : _JOOMLACOMMENT_NOTIFYTXT0 )."'>&nbsp;</span>";
  1931. }
  1932. function post_htmlCode()
  1933. {
  1934. global $my, $gid, $mosConfig_live_site;
  1935. /*
  1936. * THIS LOGIC IS USED ALSO FOR MODULE
  1937. * so if changes are made, check also in module the result...
  1938. */
  1939. /*
  1940. * use ' character instead of \" in html code
  1941. */
  1942. /*
  1943. * prepare datas
  1944. */
  1945. $id = $this->_item['id'];
  1946. $name = $this->censorText(JOSC_utils::filter($this->anonymous($this->_item['name'])));
  1947. $website = $this->censorText(JOSC_utils::filter($this->_item['website']));
  1948. $title = $this->censorText(JOSC_utils::filter($this->_item['title']));
  1949. $comment = $this->censorText(JOSC_utils::filter($this->_item['comment']));
  1950. $usertype = $this->_item['usertype'];
  1951. $ip = $this->_item['ip'];
  1952. $date = JOSC_utils::getLocalDate($this->_item['date'],$this->_date_format);//date($this->_date_format, strtotime($this->_item['date']));
  1953. /* */
  1954. $isCommentModerator = JOSC_utils::isCommentModerator($this->_moderator, $this->_item['userid']); //, $name, $usertype);
  1955. $isModerator = JOSC_utils::isModerator($this->_moderator);
  1956. $notify = ($this->_notify_moderator && $usertype && $isModerator) ? '1' : $this->_item['notify'];
  1957. $edit = '';
  1958. /* reply : if not only moderator OR user is moderator */
  1959. if ($this->_tree) {
  1960. if ( !$this->_mlink_post || ($isModerator) )
  1961. $edit = $this->linkPost($id);
  1962. }
  1963. /* quote */
  1964. if ($this->_support_UBBcode) {
  1965. if ($edit) $edit .= ' | ';
  1966. $edit .= $this->linkQuote($id);
  1967. }
  1968. /* edit and delete */
  1969. if ($isCommentModerator) {
  1970. if ($edit) $edit .= ' | ';
  1971. $edit .= $this->linkEdit($id);
  1972. $edit .= ' | ' . $this->linkDelete($id);
  1973. }
  1974. $voting = $this->voting($this->_item['voting_no'], $this->_item['voting_yes'], $id, $this->_content_id);
  1975. $comment = $this->parseUBBCode($comment);
  1976. // $comment = $this->setMaxLength($comment); /* before long ubbcode tags ! */
  1977. // $comment = $this->parseUBBCode_2($comment);
  1978. /*
  1979. * parse template block
  1980. */
  1981. $html = $this->_post;
  1982. $NLsearch = array(); $NLsearch[] = "\n"; $NLsearch[] = "\r";
  1983. $BRreplace = array(); $BRreplace[] = "<br />"; $BRreplace[] = " ";
  1984. /*
  1985. * no blocks
  1986. */
  1987. /* {id} */
  1988. $html = str_replace('{id}', $id , $html);
  1989. /* {template_live_site} */
  1990. $html = str_replace('{template_live_site}', $this->_template_path.'/'.$this->_template_name, $html);
  1991. /* {postclass} */
  1992. $html = str_replace('{postclass}', 'sectiontableentry' . $this->_css, $html);
  1993. /* {username} */
  1994. $html = str_replace('{username}', $this->profileLink($name, $this->_user_id), $html);
  1995. /* {date} */
  1996. $html = str_replace('{date}', $date, $html);
  1997. /* {content} */
  1998. $html = str_replace('{content}', $comment, $html);
  1999. /* {content_js} */
  2000. $html = str_replace('{content_js}', addslashes(str_replace($NLsearch, $BRreplace,$comment)), $html);
  2001. /* {notify} */
  2002. $html = str_replace('{notify}', $this->notifyLink($notify, $this->_notify_users) , $html);
  2003. /*
  2004. * with blocks
  2005. */
  2006. /* {avatar_picture} */
  2007. $display = $this->_avatar;
  2008. $html = JOSC_utils::checkBlock('BLOCK-avatar_picture', $display, $html);
  2009. if ($display) {
  2010. if(strpos($this->_avatar,"gallery/")===false)
  2011. $path = "$mosConfig_live_site/images/comprofiler/tn$this->_avatar";
  2012. else
  2013. $path = "$mosConfig_live_site/images/comprofiler/$this->_avatar";
  2014. $html = str_replace('{avatar_picture}', $this->profileLink("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id), $html);
  2015. }
  2016. /* {website} */
  2017. $display = ($website && (!$this->_website_registered || $my->gid > 0)) ? true : false;
  2018. $html = JOSC_utils::checkBlock('BLOCK-website', $display, $html);
  2019. if ($display) {
  2020. $website = "<a class='postwebsite' rel='external nofollow' href='$website' title='$website' target='_blank'>&nbsp;</a>";
  2021. $html = str_replace('{website}', $website, $html);
  2022. }
  2023. /* {title} */
  2024. $display = $title ? true : false;
  2025. $html = JOSC_utils::checkBlock('BLOCK-title', $display, $html);
  2026. if ($display) {
  2027. $html = str_replace('{title}', $title, $html);
  2028. $html = str_replace('{title_js}', addslashes(str_replace($NLsearch, $BRreplace,$title)), $html);
  2029. }
  2030. /* {usertype} */
  2031. $display = $this->IP($ip, $usertype, $this->_IP_visible, $this->_IP_partial, $this->_IP_caption);
  2032. $html = JOSC_utils::checkBlock('BLOCK-usertype', $display, $html);
  2033. if ($display) {
  2034. $html = str_replace('{usertype}', $display, $html);
  2035. }
  2036. $display = ((!$my->username && $this->_only_registered) || !$this->_ajax || ($edit == '')) ? false : true;
  2037. $html = JOSC_utils::checkBlock('BLOCK-footer', $display, $html);
  2038. if ($display) {
  2039. /* {editbuttons} */
  2040. $html = str_replace('{editbuttons}', $edit, $html);
  2041. /* {voting} */
  2042. $html = str_replace('{voting}', $voting, $html);
  2043. }
  2044. $wrapnum = isset($this->_item['wrapnum']) ? $this->_item['wrapnum'] : 0;
  2045. return $this->envelope($html, $id, ($wrapnum * $this->_tree_indent) . 'px');
  2046. }
  2047. }
  2048. class JOSC_ubbcode extends JOSC_support {
  2049. var $_comment;
  2050. // var $_maxlength_word;
  2051. // var $_maxlength_line;
  2052. // var $_maxlength_text;
  2053. var $_ubbcodeCount=1;
  2054. var $_ubbcodeArray=array();
  2055. var $_splitTag;
  2056. var $_limittextTag;
  2057. var $_TO='<'; /* for debug change */
  2058. var $_TC='>'; /* for debug change */
  2059. function JOSC_ubbcode($value)
  2060. {
  2061. $this->_comment = $value;
  2062. }
  2063. function setMaxlength($word, $text, $line)
  2064. {
  2065. $this->_maxlength_word = $word;
  2066. $this->_maxlength_line = $line;
  2067. $this->_maxlength_text = $text;
  2068. }
  2069. function parseEmoticons($html)
  2070. {
  2071. foreach ($this->_emoticons as $ubb => $icon) {
  2072. /* do not set ubb as alt text ! else will be replace twice or more...! */
  2073. $html = str_replace($ubb, "<img src='" . $this->_emoticons_path . '/' . $icon . "' border='0' alt='' />", $html);
  2074. }
  2075. return $html;
  2076. }
  2077. // function parseImgElement($html)
  2078. // {
  2079. // //return preg_replace('/\[img\](.*?)\[\/img\]/i', '<img src=\'\\1\' alt=\'Posted image\' />', $html);
  2080. // $regexp = '/\[img\](.*?)\[\/img\]/i';
  2081. // return preg_replace_callback($regexp, array(&$this, 'callback_img'), $html);
  2082. // }
  2083. // function callback_img( &$matches )
  2084. // {
  2085. // $ubbcodeID = '['.$this->_ubbcodeCount++.']';
  2086. //
  2087. // $result = array();
  2088. // $result['type'] = 'img';
  2089. // $result['ID'] = $ubbcodeID;
  2090. // $result['value'] = $matches[1];
  2091. //
  2092. // $this->_ubbcodeArray[]=$result;
  2093. //
  2094. // return ($ubbcodeID); /* insert ID in string */
  2095. // }
  2096. //
  2097. // function parseQuoteElement($html)
  2098. // {
  2099. // $q1 = substr_count($html, "[/quote]");
  2100. // $q2 = substr_count($html, "[quote=");
  2101. // if ($q1 > $q2) $quotes = $q1;
  2102. // else $quotes = $q2;
  2103. // $patterns = array("/\[quote\](.+?)\[\/quote\]/is",
  2104. // "/\[quote=(.+?)\](.+?)\[\/quote\]/is");
  2105. // $replacements = array("<div class='quote'><div class='genmed'><b>" . _JOOMLACOMMENT_UBB_QUOTE . "</b></div><div class='quotebody'>\\1</div></div>",
  2106. // "<div class='quote'><div class='genmed'><b>\\1 " . _JOOMLACOMMENT_UBB_WROTE . "</b></div><div class='quotebody'>\\2</div></div>");
  2107. // while ($quotes > 0) {
  2108. // $html = preg_replace($patterns, $replacements, $html);
  2109. // $quotes--;
  2110. // }
  2111. // return $html;
  2112. // }
  2113. function code_unprotect($val)
  2114. {
  2115. $val = str_replace("{ : }", ":", $val);
  2116. $val = str_replace("{ ; }", ";", $val);
  2117. $val = str_replace("{ [ }", "[", $val);
  2118. $val = str_replace("{ ] }", "]", $val);
  2119. $val = str_replace(array("\n\r", "\r\n"), "\r", $val);
  2120. $val = str_replace("\r", '&#13;', $val);
  2121. return JOSC_utils::filter($val, true);
  2122. }
  2123. // function parseCodeElement($html)
  2124. // {
  2125. // if (preg_match_all('/\[code\](.+?)\[\/code\]/is', $html, $replacementI)) {
  2126. // foreach($replacementI[0] as $val) $html = str_replace($val, $this->code_unprotect($val), $html);
  2127. // }
  2128. // $pattern = array();
  2129. // $replacement = array();
  2130. // $pattern[] = "/\[code\](.+?)\[\/code\]/is";
  2131. // $replacement[] = "<div class='code'><div class='genmed'><b>" . _JOOMLACOMMENT_UBB_CODE . '</b></div><pre>\\1</pre></div>';
  2132. // return preg_replace($pattern, $replacement, $html);
  2133. // }
  2134. function parseUBB_withlimit($html)
  2135. {
  2136. /* this is COMPLEX !! but works for all.
  2137. * the reason is to a correct maximum length calculation
  2138. * and in case of cut: close all opened tags
  2139. *
  2140. * !! if someone can find one day a better way to do it working in all cases !! you're welcome man !
  2141. *
  2142. * logic :
  2143. * 1. preg_replace all with special addeed tags
  2144. * 2. use special addeed tags to split in an array and process wrap and max...
  2145. *
  2146. */
  2147. $this->_splitTag = $splitTag = 'joscplit';
  2148. $this->_limittextTag = $limittextTag = 'limittext';
  2149. $TO = $this->_TO;
  2150. $TC = $this->_TC;
  2151. $debug = false;
  2152. // $debug = true;
  2153. if ($debug) {
  2154. /* set true for debug */
  2155. $TO = $this->_TO = "(";
  2156. $TC = $this->_TC = ")";
  2157. }
  2158. // $maxlength_word = $this->_maxlength_word;
  2159. // $maxlength_line = $this->_maxlength_line;
  2160. // $maxlength_text = $this->_maxlength_text;
  2161. $maxlength_word = ($this->_maxlength_word!=-1) ? $this->_maxlength_word : 999999;
  2162. $maxlength_line = ($this->_maxlength_line!=-1) ? $this->_maxlength_line : 999999;
  2163. $maxlength_text = ($this->_maxlength_text!=-1) ? $this->_maxlength_text : 999999;
  2164. $parsedText = $this->parseUBB_recurse( $html );
  2165. /* get an array of tag and texts separated */
  2166. $TxtTags = explode($splitTag, $parsedText);
  2167. if (($nblines=count($TxtTags))<=1) {
  2168. $parsedText = JOSC_utils::wrapText($parsedText, $maxlength_word, ' ');
  2169. $parsedText = JOSC_utils::wrapText($parsedText, $maxlength_line, '<br />');
  2170. $parsedText = JOSC_utils::setMaxLength($parsedText, $maxlength_text);
  2171. return $parsedText;
  2172. }
  2173. //var_dump($TxtTags);
  2174. $text=""; $lentext=0;
  2175. $push=""; /* will contain end tags pushed and not poped [/x][/y] */
  2176. // if (substr($parsedText,0,strlen($splitTag))==$splitTag && $TxtTags[0]) $is_tag = true;
  2177. // else $is_tag = false;
  2178. for($i=0;$i<$nblines ;$i++)
  2179. {
  2180. $line = $TxtTags[$i];
  2181. // if ($is_tag && substr($line,0,1)!=$TO)
  2182. // $is_tag = false;
  2183. /* < is not accepted in comment -> we are sure it is from the preg_replace */
  2184. $is_tag = ($tagpos=strpos($line, $TO))===false ? false : true;
  2185. if ($is_tag) {
  2186. if ($debug) $text .= "<br />DEBUG_istag".$line."<br />";
  2187. /* push tags , pop end tags */
  2188. $tagkey = substr($line, 0, $tagpos); /* xxx<... */
  2189. if ($tagkey) {
  2190. $line = substr_replace($line, '', 0, $tagpos); /* xxx<... */
  2191. if (substr($line,1,1)=='/') {
  2192. if (!(($pos=strpos($push, $tagkey))===false))
  2193. /* pop */
  2194. $push = substr_replace($push,'',$pos-2,strlen($tagkey)+3);
  2195. } else {
  2196. /* push */
  2197. $push = "$TO/$tagkey$TC".$push;
  2198. }
  2199. }
  2200. $text .= $line;
  2201. $is_tag = false;
  2202. } else {
  2203. /* wrap and limit length */
  2204. if ($debug) $text .= "<br />DEBUG_isnot".$line."<br />";
  2205. if (!(strpos($line, $limittextTag)===false)) {
  2206. $line = str_replace($limittextTag, '', $line); /* could find several if users has included 2 links together... */
  2207. $line = JOSC_utils::setMaxLength($line, $maxlength_word);
  2208. }
  2209. $line = JOSC_utils::wrapText($line, $maxlength_word, '&nbsp;');
  2210. $line = JOSC_utils::wrapText($line, $maxlength_line, '<br />');
  2211. $diff = $maxlength_text - $lentext; /* remainder before (positive) */
  2212. $lentext += strlen($line);
  2213. // $diff2 = $maxlength_text - $lentext; /* remainder after (negative if over) */
  2214. if ($lentext<$maxlength_text)
  2215. $text.=$line;
  2216. else {
  2217. $text.= JOSC_utils::setMaxLength($line, $diff);
  2218. break;
  2219. }
  2220. $is_tag = true;
  2221. }
  2222. }
  2223. $text .= $push;
  2224. return $text;
  2225. }
  2226. function parseUBB_recurse( $matches )
  2227. {
  2228. $split = $this->_splitTag;
  2229. $limittext = $this->_limittextTag;
  2230. $TO = $this->_TO;
  2231. $TC = $this->_TC;
  2232. //Added following code to add http protocol to URL of no protocal exists
  2233. $reg_exp = "/\[url[\]|=]((ht|f)tp(s?):\/\/((www\.)?[^ \[\]\(\)\n\r\t]+)|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})\/)([^ \[\]\(\),;&quot;'&lt;&gt;\n\r\t]+)([^\. \[\]\(\),;&quot;'&lt;&gt;\n\r\t])|(([012]?[0-9]{1,2}\.){3}[012]?[0-9]{1,2})/";
  2234. if (is_array($matches)) {
  2235. if (! preg_match($reg_exp, $matches[0])) {
  2236. $matches[0] = preg_replace("/(\[url[\]|=])(.*)/", "\\1http://\\2", $matches[0]);
  2237. }
  2238. } else {
  2239. if (! preg_match($reg_exp, $matches)) {
  2240. $matches = preg_replace("/(\[url[\]|=])(.*)/", "\\1http://\\2", $matches);
  2241. }
  2242. }
  2243. //protocal check ends here
  2244. //protocal check ends here
  2245. /* other recurse : #\[img]((?:[^[]|\[(?!/?img])|(?R))+)\[/img]#i*/
  2246. /* ?: => group but do not capture
  2247. * change ...)*)\[/x... in )+)\[/x if empty inside not authorized
  2248. *
  2249. * always : $split+start+$split text $split.end.$split
  2250. */
  2251. $patterns = array(
  2252. '#\[b]((?:[^[]|\[(?!/?b])|(?R))*)\[/b]#i',
  2253. '#\[u]((?:[^[]|\[(?!/?u])|(?R))*)\[/u]#i',
  2254. '#\[i]((?:[^[]|\[(?!/?i])|(?R))*)\[/i]#i',
  2255. '#\[url=(.*?)]((?:[^[]|\[(?!/?url])|(?R))*)\[/url]#i',
  2256. '#\[url]((?:[^[]|\[(?!/?url])|(?R))*)\[/url]#i',
  2257. '#\[email]((?:[^[]|\[(?!/?email])|(?R))*)\[/email]#i',
  2258. '#\[email=(.*?)]((?:[^[]|\[(?!/?email])|(?R))*)\[/email]#i',
  2259. '#\[font=(.*?)]((?:[^[]|\[(?!/?font(?==)])|(?R))*)\[/font]#i',
  2260. '#\[size=(.*?)]((?:[^[]|\[(?!/?size(?==)])|(?R))*)\[/size]#i',
  2261. '#\[color=(.*?)]((?:[^[]|\[(?!/?color(?==)])|(?R))*)\[/color]#i',
  2262. '#\[quote]((?:[^[]|\[(?!/?quote])|(?R))*)\[/quote]#i',
  2263. '#\[quote=(.*?)]((?:[^[]|\[(?!/?quote(?==)])|(?R))*)\[/quote]#i',
  2264. '#\[code]((?:[^[]|\[(?!/?code])|(?R))*)\[/code]#i',
  2265. '#\[img]((?:[^[]|\[(?!/?img])|(?R))*)\[/img]#i',
  2266. '#\[img=(.*?)]((?:[^[]|\[(?!/?img])|(?R))*)\[/img]#i',
  2267. );
  2268. /*
  2269. * replacements
  2270. */
  2271. $replacements = array();
  2272. if ($this->_support_UBBcode) {
  2273. $replacements[] = $split.'b' .$TO.'b'.$TC.$split.'\\1'. $split.'b'.$TO.'/b'.$TC.$split;
  2274. $replacements[] = $split.'u' .$TO.'u'.$TC.$split.'\\1'. $split.'u'.$TO.'/u'.$TC.$split;
  2275. $replacements[] = $split.'i' .$TO.'i'.$TC.$split.'\\1'. $split.'i'.$TO.'/i'.$TC.$split;
  2276. if ($this->_support_link) {
  2277. $replacements[] = $split.'a' .$TO.'a target=\'_blank\' rel=\'external nofollow\' href=\'\\1\' title=\'Visit \\1\''.$TC.$split.$limittext.'\\2'. $split.'a'.$TO.'/a'.$TC.$split;
  2278. $replacements[] = $split.'a' .$TO.'a target=\'_blank\' rel=\'external nofollow\' href=\'\\1\' title=\'Visit \\1\''.$TC.$split.$limittext.'\\1'. $split.'a'.$TO.'/a'.$TC.$split;
  2279. $replacements[] = $split.'a' .$TO.'a href=\'mailto:\\1\''.$TC.$split.$limittext.'\\1'. $split.'a'.$TO.'/a'.$TC.$split;
  2280. $replacements[] = $split.'a' .$TO.'a href=\'mailto:\\1\''.$TC.$split.$limittext.'\\2'. $split.'a'.$TO.'/a'.$TC.$split;
  2281. } else {
  2282. $replacements[] = $split.' link:\\1';
  2283. $replacements[] = $split.' link:\\1';
  2284. $replacements[] = $split.' \\1';
  2285. $replacements[] = $split.' \\1';
  2286. }
  2287. $replacements[] = $split.'span' .$TO.'span style=\'font-family: \\1\''.$TC.$split.'\\2'. $split.'span'.$TO.'/span'.$TC.$split;
  2288. $replacements[] = $split.'span' .$TO.'span style=\'font-size: \\1\''.$TC.$split.'\\2'. $split.'span'.$TO.'/span'.$TC.$split;
  2289. if ($this->_hide) {
  2290. $replacements[] = $split.'\\2';
  2291. } else {
  2292. $replacements[] = $split.'span'.$TO.'span style=\'color: \\1\''.$TC.$split.'\\2'.$split.$TO.'/span'.$TC.$split;
  2293. }
  2294. } else {
  2295. $replacements[] = $split.' \\1';
  2296. $replacements[] = $split.' \\1';
  2297. $replacements[] = $split.' \\1';
  2298. $replacements[] = $split.' link:\\1';
  2299. $replacements[] = $split.' link:\\1';
  2300. $replacements[] = $split.' \\1';
  2301. $replacements[] = $split.' \\1';
  2302. $replacements[] = $split.' \\2';
  2303. $replacements[] = $split.' \\2';
  2304. $replacements[] = $split.' \\2';
  2305. }
  2306. /*
  2307. * quotes
  2308. */
  2309. // $patterns = array("/\[quote\](.+?)\[\/quote\]/is",
  2310. // "/\[quote=(.+?)\](.+?)\[\/quote\]/is");
  2311. // $replacements = array("<div class='quote'><div class='genmed'><b>" . _JOOMLACOMMENT_UBB_QUOTE . "</b></div><div class='quotebody'>\\1</div></div>",
  2312. // "<div class='quote'><div class='genmed'><b>\\1 " . _JOOMLACOMMENT_UBB_WROTE . "</b></div><div class='quotebody'>\\2</div></div>");
  2313. if ($this->_support_quotecode) {
  2314. $replacements[] = $split.'div' .$TO.'div class=\'quote\''.$TC. $split
  2315. .$split.'div' .$TO.'div class=\'genmed\''.$TC.$split
  2316. .$split.'b' .$TO.'b'.$TC.$split. _JOOMLACOMMENT_UBB_QUOTE
  2317. .$split.'b' .$TO.'/b'.$TC.$split
  2318. .$split.'div' .$TO.'/div'.$TC.$split
  2319. .$split.'div' .$TO.'div class=\'quotebody\''.$TC.$split.'\\1'
  2320. .$split.'div' .$TO.'/div'.$TC.$split
  2321. .$split.'div' .$TO.'/div'.$TC.$split;
  2322. $replacements[] = $split.'div' .$TO.'div class=\'quote\''.$TC. $split
  2323. .$split.'div' .$TO.'div class=\'genmed\''.$TC.$split
  2324. .$split.'b' .$TO.'b'.$TC.$split.'\\1 '._JOOMLACOMMENT_UBB_WROTE
  2325. .$split.'b' .$TO.'/b'.$TC.$split
  2326. .$split.'div' .$TO.'/div'.$TC.$split
  2327. .$split.'div' .$TO.'div class=\'quotebody\''.$TC.$split.'\\2'
  2328. .$split.'div' .$TO.'/div'.$TC.$split
  2329. .$split.'div' .$TO.'/div'.$TC.$split;
  2330. } else {
  2331. $replacements[] = $split.' \\1';
  2332. $replacements[] = $split.' \\2';
  2333. }
  2334. /*
  2335. * code
  2336. */
  2337. if ($this->_support_quotecode) {
  2338. $replacements[] = $split.'div' .$TO.'div class=\'code\''.$TC. $split
  2339. .$split.'div' .$TO.'div class=\'genmed\''.$TC.$split
  2340. .$split.'b' .$TO.'b'.$TC.$split. _JOOMLACOMMENT_UBB_CODE
  2341. .$split.'b' .$TO.'/b'.$TC.$split
  2342. .$split.'div' .$TO.'/div'.$TC.$split
  2343. .$split.'div' .$TO.'div class=\'quotebody\''.$TC.$split
  2344. .$split.'pre' .$TO.'pre'.$TC.$split.'\\1'
  2345. .$split.'pre' .$TO.'/pre'.$TC.$split
  2346. .$split.'div' .$TO.'/div'.$TC.$split
  2347. .$split.'div' .$TO.'/div'.$TC.$split;
  2348. } else {
  2349. $replacements[] = $split.' \\1';
  2350. }
  2351. /*
  2352. * images
  2353. */
  2354. if ($this->_support_pictures) {
  2355. $maxwidthpictures = (int) $this->_pictures_maxwidth;
  2356. if ($maxwidthpictures>0) {
  2357. $divO = $split.'div' .$TO.'div style=\'width:'.$maxwidthpictures.'px;overflow:hidden;\''.$TC. $split;
  2358. $divC = $split.'div' .$TO.'/div'.$TC.$split;
  2359. } else {
  2360. $divO = $divC = '';
  2361. }
  2362. $replacements[] = $divO. $split .$TO.'img src=\'\\1\' alt=\'Posted image\' /'.$TC.$split.$divC;
  2363. $replacements[] = $divO. $split .$TO.'img src=\'\\1\' alt=\'Posted image\' /'.$TC.$split.$divC;
  2364. } else {
  2365. /* no image = link */
  2366. if ($this->_support_link) {
  2367. $replacements[] = $split.'a' .$TO.'a target=\'_blank\' rel=\'external nofollow\' href=\'\\1\' title=\'Visit \\1\''.$TC.$split.$limittext.'\\1'. $split.'a'.$TO.'/a'.$TC.$split;
  2368. $replacements[] = $split.'a' .$TO.'a target=\'_blank\' rel=\'external nofollow\' href=\'\\1\' title=\'Visit \\1\''.$TC.$split.$limittext.'\\2'. $split.'a'.$TO.'/a'.$TC.$split;
  2369. } else {
  2370. $replacements[] = $split.' image:\\1';
  2371. $replacements[] = $split.' image:\\1';
  2372. }
  2373. }
  2374. if (is_array($matches)) {
  2375. $html = preg_replace($patterns, $replacements, $matches[0]);
  2376. $matches = $html;
  2377. }
  2378. return preg_replace_callback($patterns, array(&$this, 'parseUBB_recurse'), $matches );
  2379. }
  2380. function ubbcode_parse()
  2381. {
  2382. global $mosConfig_absolute_path;
  2383. $html = $this->_comment;
  2384. $html = $this->parseUBB_withlimit($html); //$this->parseUBB($html, $this->_hide);
  2385. if ($this->_support_emoticons) $html = $this->parseEmoticons($html);
  2386. //if ($this->_support_pictures) $html = $this->parseImgElement($html);
  2387. // if ($this->_support_UBBcode) {
  2388. //$html = $this->parseUBB($html, $this->_hide);
  2389. //$html = $this->parseCodeElement($html);
  2390. //$html = $this->parseQuoteElement($html);
  2391. // }
  2392. if ($this->_hide) $html = "<span class='hide'>$html</span>";
  2393. return str_replace('&#13;', "\r", nl2br($html));
  2394. }
  2395. }
  2396. class JOSC_form extends JOSC_support {
  2397. var $_form;
  2398. var $_captcha;
  2399. var $_notify_users;
  2400. var $_enter_website;
  2401. var $_emoticon_wcount;
  2402. var $_tname;
  2403. var $_temail;
  2404. var $_twebsite;
  2405. var $_tnotify;
  2406. var $_form_area_cols;
  2407. function JOSC_form($value)
  2408. {
  2409. $this->_form = $value;
  2410. }
  2411. function setCaptcha($value)
  2412. {
  2413. $this->_captcha = $value;
  2414. }
  2415. function setNotifyUsers($value)
  2416. {
  2417. $this->_notify_users = $value;
  2418. }
  2419. function setEnterWebsite($value)
  2420. {
  2421. $this->_enter_website = $value;
  2422. }
  2423. function setEmoticonWCount($value)
  2424. {
  2425. $this->_emoticon_wcount = $value;
  2426. }
  2427. function set_tname($value)
  2428. {
  2429. $this->_tname = $value;
  2430. }
  2431. function set_temail($value)
  2432. {
  2433. global $my;
  2434. $this->_temail = ($my->id ? _JOOMLACOMMENT_AUTOMATICEMAIL : $value); /* change also modify - ajax_quote ! */
  2435. }
  2436. function set_twebsite($value)
  2437. {
  2438. $this->_twebsite = $value;
  2439. }
  2440. function set_tnotify($value)
  2441. {
  2442. $this->_tnotify = $value;
  2443. }
  2444. function setFormAreaCols($value)
  2445. {
  2446. $this->_form_area_cols = $value;
  2447. }
  2448. function onlyRegistered()
  2449. {
  2450. return '<div class="onlyregistered">' . _JOOMLACOMMENT_ONLYREGISTERED . '</div>';
  2451. }
  2452. function readOnly($username)
  2453. {
  2454. if ($username) return 'DISABLED'; /* TODO: use readonly="readonly" for XHTML reason ? */
  2455. else return '';
  2456. }
  2457. function displayStyle($display)
  2458. {
  2459. return ($display) ? "" : "display:none;";
  2460. }
  2461. function emoticons($link=true)
  2462. {
  2463. if (!$this->_support_emoticons) return '';
  2464. $html = "<div class='emoticoncontainer'>";
  2465. $html .= "<div class='emoticonseparator'></div>";
  2466. $index = 0;
  2467. $icon_used = array();
  2468. foreach ($GLOBALS["JOSC_emoticon"] as $ubb => $icon) {
  2469. if (in_array($icon, $icon_used))
  2470. continue; /* ignore: avoid same icons twice ! */
  2471. $icon_used[] = $icon;
  2472. $html .= "<span class='emoticonseparator'>";
  2473. $html .= "<span class='emoticon'>";
  2474. $html .= $link ? "<a href='javascript:JOSC_emoticon(\"$ubb\")'>" : "";
  2475. $html .= "<img src='$this->_emoticons_path/$icon' border='0' alt='$ubb' />";
  2476. $html .= $link ? "</a>":"";
  2477. $html .= "</span></span>";
  2478. $index++;
  2479. if ($index == $this->_emoticon_wcount) {
  2480. $index = 0;
  2481. $html .= "<div class='emoticonseparator'></div>";
  2482. }
  2483. }
  2484. $html .= '</div>';
  2485. return "<div>$html</div>";
  2486. }
  2487. function loadUBBIcons(&$ubbIconList, $absolute_path, $live_site)
  2488. {
  2489. require_once("$absolute_path/ubb_icons.php");
  2490. foreach($ubbIcons as $name => $icon) {
  2491. $ubbIconList[$name] = "$live_site/$icon";
  2492. }
  2493. }
  2494. function UBBCodeButtons()
  2495. {
  2496. $absolute_path = "$this->_template_absolute_path/$this->_template_name/images";
  2497. $live_site = "$this->_template_path/$this->_template_name/images";
  2498. $ubbIconList = array();
  2499. $this->loadUBBIcons($ubbIconList, "$this->_absolute_path/images", "$this->_live_site/images");
  2500. if (file_exists("$absolute_path/ubb_icons.php")) $this->loadUBBIcons($ubbIconList, $absolute_path, $live_site);
  2501. $html = "<a href='javascript:JOSC_insertUBBTag(\"b\")'><img src='" . $ubbIconList['bold'] . "' class='buttonBB' name='bb' alt='[b]' /></a>&nbsp;";
  2502. $html .= "<a href='javascript:JOSC_insertUBBTag(\"i\")'><img src='" . $ubbIconList['italicize'] . "' class='buttonBB' name='bi' alt='[i]' /></a>&nbsp;";
  2503. $html .= "<a href='javascript:JOSC_insertUBBTag(\"u\")'><img src='" . $ubbIconList['underline'] . "' class='buttonBB' name='bu' alt='[u]' /></a>&nbsp;";
  2504. $html .= "<a href='javascript:JOSC_insertUBBTag(\"url\")'><img src='" . $ubbIconList['url'] . "' class='buttonBB' name='burl' alt='[url]' /></a>&nbsp;";
  2505. $html .= "<a href='javascript:JOSC_insertUBBTag(\"quote\")'><img src='" . $ubbIconList['quote'] . "' class='buttonBB' name='bquote' alt='[quote]' /></a>&nbsp;";
  2506. $html .= "<a href='javascript:JOSC_insertUBBTag(\"code\")'><img src='" . $ubbIconList['code'] . "' class='buttonBB' name='bcode' alt='[code]' /></a>&nbsp;";
  2507. $html .= "<a href='javascript:JOSC_insertUBBTag(\"img\")'><img src='" . $ubbIconList['image'] . "' class='buttonBB' name='bimg' alt='[img]' /></a>&nbsp;";
  2508. return $html;
  2509. }
  2510. function UBBCodeSelect()
  2511. {
  2512. $html = '';
  2513. $html .= "<select name='menuColor' class='select' onchange='JOSC_fontColor()'>";
  2514. $html .= "<option>-" . _JOOMLACOMMENT_COLOR . "-</option>";
  2515. $html .= "<option>" . _JOOMLACOMMENT_AQUA . "</option>";
  2516. $html .= "<option>" . _JOOMLACOMMENT_BLACK . "</option>";
  2517. $html .= "<option>" . _JOOMLACOMMENT_BLUE . "</option>";
  2518. $html .= "<option>" . _JOOMLACOMMENT_FUCHSIA . "</option>";
  2519. $html .= "<option>" . _JOOMLACOMMENT_GRAY . "</option>";
  2520. $html .= "<option>" . _JOOMLACOMMENT_GREEN . "</option>";
  2521. $html .= "<option>" . _JOOMLACOMMENT_LIME . "</option>";
  2522. $html .= "<option>" . _JOOMLACOMMENT_MAROON . "</option>";
  2523. $html .= "<option>" . _JOOMLACOMMENT_NAVY . "</option>";
  2524. $html .= "<option>" . _JOOMLACOMMENT_OLIVE . "</option>";
  2525. $html .= "<option>" . _JOOMLACOMMENT_PURPLE . "</option>";
  2526. $html .= "<option>" . _JOOMLACOMMENT_RED . "</option>";
  2527. $html .= "<option>" . _JOOMLACOMMENT_SILVER . "</option>";
  2528. $html .= "<option>" . _JOOMLACOMMENT_TEAL . "</option>";
  2529. $html .= "<option>" . _JOOMLACOMMENT_WHITE . "</option>";
  2530. $html .= "<option>" . _JOOMLACOMMENT_YELLOW . "</option>";
  2531. $html .= "</select>&nbsp;";
  2532. $html .= "<select name='menuSize' class='select' onchange='JOSC_fontSize()'>";
  2533. $html .= "<option>-" . _JOOMLACOMMENT_SIZE . "-</option>";
  2534. $html .= "<option>" . _JOOMLACOMMENT_TINY . "</option>";
  2535. $html .= "<option>" . _JOOMLACOMMENT_SMALL . "</option>";
  2536. $html .= "<option>" . _JOOMLACOMMENT_MEDIUM . "</option>";
  2537. $html .= "<option>" . _JOOMLACOMMENT_LARGE . "</option>";
  2538. $html .= "<option>" . _JOOMLACOMMENT_HUGE . "</option>";
  2539. $html .= "</select>";
  2540. return $html;
  2541. }
  2542. function notifySelect() {
  2543. $html = '';
  2544. $html .= "<select name='tnotify' class='inputbox'>";
  2545. // $html .= "<option value='0' ".($this->_tnotify ? "" : "checked") ." >" . _JOOMLACOMMENT_ENTERNOTIFY0 . "</option>";
  2546. // $html .= "<option value='1' ".($this->_tnotify ? "checked" : "") ." >" . _JOOMLACOMMENT_ENTERNOTIFY1 . "</option>";
  2547. $html .= "<option value='0' ".($this->_tnotify ? "" : "selected=\"selected\"") ." >" . _JOOMLACOMMENT_ENTERNOTIFY0 . "</option>";
  2548. $html .= "<option value='1' ".($this->_tnotify ? "selected=\"selected\"" : "") ." >" . _JOOMLACOMMENT_ENTERNOTIFY1 . "</option>";
  2549. $html .= "</select>";
  2550. return $html;
  2551. }
  2552. function form_htmlCode()
  2553. {
  2554. global $my, $gid;
  2555. $hidden = $this->formHiddenValues($this->_content_id, $this->_component, $this->_sectionid);
  2556. if (!$my->username && $this->_only_registered) {
  2557. $html = $this->onlyRegistered();
  2558. /* needed informations but hidden : */
  2559. $html .= "<form name='joomlacommentform' method='post' action='PHP_SELF'>";
  2560. $html .= $hidden;
  2561. $html .= "<table class='buttoncontainer' style='display:none;' cellpadding='0' cellspacing='0'>";
  2562. $html .= "<tr>";
  2563. $html .= "<td><input type='button' class='button' name='bsend' value='{_SENDFORM}' onclick='JOSC_editPost(-1,-1)' /></td>";
  2564. $html .= "<td id='JOSC_busy'></td>";
  2565. $html .= "</tr>";
  2566. $html .= "</table>";
  2567. $html .= "</form>";
  2568. return $html;
  2569. }
  2570. /*
  2571. * parse template block _form
  2572. */
  2573. $html = $this->_form;
  2574. /*
  2575. * No blocks
  2576. */
  2577. $html = str_replace('{_WRITECOMMENT}', _JOOMLACOMMENT_WRITECOMMENT, $html);
  2578. $html = str_replace('{self}', 'index.php', $html);
  2579. $html = str_replace('{id}', $this->_content_id, $html);
  2580. // $hidden = JOSC_utils::inputHidden('content_id',$this->_content_id);
  2581. // $hidden .= JOSC_utils::inputHidden('component',$this->_component);
  2582. // $hidden .= JOSC_utils::inputHidden('joscsectionid',$this->_sectionid);
  2583. // $hidden = $this->formHiddenValues($this->_content_id, $this->_component, $this->_sectionid);
  2584. $html = str_replace('{_HIDDEN_VALUES}', $hidden, $html);
  2585. $html = str_replace('{template_live_site}', $this->_template_path.'/'.$this->_template_name, $html);
  2586. $html = str_replace('{formareacols}', $this->_form_area_cols, $html);
  2587. $html = str_replace('{_ENTERNAME}', _JOOMLACOMMENT_ENTERNAME, $html);
  2588. $html = str_replace('{username}', $this->_tname, $html);
  2589. $html = str_replace('{registered_readonly}', $this->readOnly($this->_tname), $html);
  2590. $html = str_replace('{_ENTERTITLE}', _JOOMLACOMMENT_ENTERTITLE, $html);
  2591. $html = str_replace('{_SENDFORM}', _JOOMLACOMMENT_SENDFORM, $html);
  2592. /*
  2593. * With blocks
  2594. */
  2595. /* {_UBBCODE} {UBBCodeButtons} {UBBCodeSelect} */
  2596. $display = $this->_support_UBBcode;
  2597. $html = JOSC_utils::checkBlock('BLOCK-_UBBCODE', $display, $html);
  2598. if ($display) {
  2599. $UBBCodeButtons = $this->UBBCodeButtons();
  2600. $UBBCodeSelect = $this->UBBCodeSelect();
  2601. $html = str_replace('{_UBBCODE}', _JOOMLACOMMENT_UBBCODE, $html);
  2602. $html = str_replace('{UBBCodeButtons}', $UBBCodeButtons, $html);
  2603. $html = str_replace('{UBBCodeSelect}', $UBBCodeSelect, $html);
  2604. }
  2605. /* {_CAPTCHATXT} {security_image} */
  2606. $display = $this->_captcha;
  2607. $html = JOSC_utils::checkBlock('BLOCK-_CAPTCHATXT', $display, $html);
  2608. if ($display) {
  2609. $html = str_replace('{_CAPTCHATXT}', _JOOMLACOMMENT_FORMVALIDATE_CAPTCHATXT, $html);
  2610. $html = str_replace('{security_image}', "<div id='captcha'>" . JOSC_security::insertCaptcha('security_refid') . '</div>', $html);
  2611. }
  2612. /* {_ENTEREMAIL} {email} {notifyselect} */
  2613. $display = true;
  2614. $html = JOSC_utils::checkBlock('BLOCK-_ENTEREMAIL', $display, $html);
  2615. if ($display) {
  2616. $html = str_replace('{_ENTEREMAIL}', _JOOMLACOMMENT_ENTEREMAIL, $html);
  2617. $html = str_replace('{email}', $this->_temail, $html);
  2618. $html = str_replace('{notifyselect}', $this->_notify_users ? $this->notifySelect():"", $html);
  2619. }
  2620. /* {_ENTERWEBSITE} {website} */
  2621. $display = $this->_enter_website;
  2622. $html = JOSC_utils::checkBlock('BLOCK-_ENTERWEBSITE', $display, $html);
  2623. if ($display) {
  2624. $html = str_replace('{_ENTERWEBSITE}', _JOOMLACOMMENT_ENTERWEBSITE, $html);
  2625. $html = str_replace('{website}', $this->_twebsite, $html);
  2626. }
  2627. /* {emoticons} */
  2628. $display = $this->emoticons();
  2629. $html = JOSC_utils::checkBlock('BLOCK-emoticons', $display, $html);
  2630. if ($display) {
  2631. $html = str_replace('{emoticons}', $display, $html);
  2632. }
  2633. return $html;
  2634. }
  2635. }
  2636. class JOSC_search extends JOSC_support {
  2637. var $_search;
  2638. var $_keyword;
  2639. var $_phrase;
  2640. var $_counter;
  2641. var $_resultTemplate;
  2642. function JOSC_search($value,&$comObject)
  2643. {
  2644. $this->_search = $value;
  2645. $this->JOSC_support($comObject);
  2646. }
  2647. function setKeyword($value)
  2648. {
  2649. $this->_keyword = addslashes(trim($value));
  2650. }
  2651. function setPhrase($value)
  2652. {
  2653. $this->_phrase = $value;
  2654. }
  2655. function anonymous($name)
  2656. {
  2657. if ($name == '') $name = JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_ANONYMOUS));
  2658. return $name;
  2659. }
  2660. // function decodeData_Charset($varName) {
  2661. // /*
  2662. // * javascript(ajax) encodeURI is only UTF-8. so we have to decode ajax send
  2663. // * should be solved with joomla 1.5 ! (native utf-8)
  2664. // */
  2665. // if ($this->_ajax)
  2666. // return JOSC_utils::myiconv_decode( JOSC_utils::decodeData($varName), $this->_local_charset );
  2667. // else
  2668. // return JOSC_utils::decodeData($varName);
  2669. // }
  2670. function filterAll($item)
  2671. {
  2672. return JOSC_board::filterAll($item);
  2673. // $item['name'] = JOSC_utils::filter($this->encodeData_Charset($item['name']));
  2674. // $item['title'] = JOSC_utils::filter($this->encodeData_Charset($item['title']));
  2675. // $item['comment'] = JOSC_utils::filter($this->encodeData_Charset($item['comment']));
  2676. // return $item;
  2677. }
  2678. function searchMatch()
  2679. {
  2680. $result = ($this->_counter == 1) ? JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCHMATCH)) : JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCHMATCHES));
  2681. return sprintf($result, $this->_counter);
  2682. }
  2683. function trimResult($html, $word, $size)
  2684. {
  2685. $html = str_replace("\n", '', $html);
  2686. if ($word == '') return '';
  2687. $p = strpos($html, $word);
  2688. if ($p == 0) return substr($html, 0, $size);
  2689. $len = strlen($html);
  2690. $sublen = strlen($word);
  2691. $size = ($size - $sublen) / 2;
  2692. if ($size >= $len) $result = $html;
  2693. else {
  2694. if ($p < $size) $a = $p-1;
  2695. else $a = $size;
  2696. $c = $len - ($p + $sublen);
  2697. if ($c < $size) $b = $c;
  2698. else $b = $size;
  2699. $b = $a + $b + $sublen;
  2700. $result = substr($html, $p - $a, $b);
  2701. }
  2702. return $result;
  2703. }
  2704. function highlightWord($html, $maxSize = -1)
  2705. {
  2706. $html = stripslashes($html);
  2707. if (($this->_phrase == 'any') Or ($this->_phrase == 'all')) {
  2708. $words = split(' ', $this->_keyword);
  2709. if ($maxSize != -1) $html = $this->trimResult($html, $words[0], $maxSize);
  2710. foreach($words as $item) {
  2711. if ($item != '')
  2712. $html = str_ireplace($item, "<span>$item</span>", $html);
  2713. }
  2714. return $html;
  2715. } else {
  2716. if ($maxSize != -1) $html = $this->trimResult($html, $this->_keyword, $maxSize);
  2717. return str_ireplace($this->_keyword, "<span>$this->_keyword</span>", stripslashes($html));
  2718. }
  2719. }
  2720. function addItem($item, $itemCSS)
  2721. {
  2722. $comment = $this->censorText($item['comment']);
  2723. $title = $this->censorText($this->highlightWord($item['title']));
  2724. $name = $this->censorText($this->highlightWord($this->anonymous($item['name'])));
  2725. // $address = 'javascript:JOSC_goToPost(' . $item['contentid'] . ',' . $item['id'] . ')';
  2726. $address = $this->_comObject->linkToContent($item['contentid'], $item['id']);
  2727. $maxsize = min(200, $this->_maxlength_text);
  2728. $comment = JOSC_utils::wrapText($comment, $this->_maxlength_word, '&nbsp;');
  2729. $comment = JOSC_utils::wrapText($comment, $this->_maxlength_line, '<br />');
  2730. if ($maxsize != 0 && strlen($comment) > $maxsize)
  2731. $comment = '...' . $this->highlightWord($comment, $maxsize) . '...';
  2732. else $comment = $this->highlightWord($comment);
  2733. $html = $this->_resultTemplate;
  2734. $html = str_replace('{postclass}', 'sectiontableentry' . $itemCSS, $html);
  2735. $html = str_replace('{title}', "<b>$title</b>", $html);
  2736. $html = str_replace('{_JOOMLACOMMENT_BY}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_BY)), $html);
  2737. $html = str_replace('{name}', $name, $html);
  2738. $html = str_replace('{address}', $address, $html);
  2739. $html = str_replace('{preview}', $comment, $html);
  2740. $html = str_replace('{date}', JOSC_utils::getLocalDate($item['date'],$this->_date_format), $html);//date($this->_date_format, strToTime($item['date'])), $html);
  2741. return $html;
  2742. }
  2743. function find($terms)
  2744. {
  2745. if (defined('_JOSC_J15'))
  2746. $database =& JFactory::getDBO();
  2747. else
  2748. global $database;
  2749. /* TODO : search for all only if .... */
  2750. $database->setQuery("SELECT * FROM #__comment WHERE component='$this->_component' AND ( $terms ) ORDER BY date DESC");
  2751. $data = $database->loadAssocList();
  2752. $html = '';
  2753. $itemCSS = 1;
  2754. $this->_counter = 0;
  2755. if ($data == null) return '';
  2756. foreach($data as $item) {
  2757. $item = $this->filterAll($item);
  2758. $html .= $this->addItem($item, $itemCSS);
  2759. $this->_counter++;
  2760. $itemCSS++;
  2761. if ($itemCSS == 3) $itemCSS = 1;
  2762. }
  2763. return $html;
  2764. }
  2765. function terms($list, $term)
  2766. {
  2767. $result = '';
  2768. foreach($list as $item) {
  2769. if ($result != '') $result .= ' OR ';
  2770. $result .= $item . " $term ";
  2771. }
  2772. return $result;
  2773. }
  2774. function anyWords($list)
  2775. {
  2776. $result = '';
  2777. if (!strpos($this->_keyword, ' ')) return $this->terms($list, "LIKE '%$this->_keyword%'");
  2778. $words = split(' ', $this->_keyword);
  2779. foreach($words as $item) {
  2780. if ($item != '') {
  2781. if ($result != '') $result .= ' OR ';
  2782. $result .= $this->terms($list, "LIKE '%$item%'");
  2783. }
  2784. }
  2785. return $result;
  2786. }
  2787. function allWords($list)
  2788. {
  2789. $result = '';
  2790. if (!strpos($this->_keyword, ' ')) return $this->terms($list, "LIKE '%$this->_keyword%'");
  2791. $words = split(' ', $this->_keyword);
  2792. foreach($words as $item) {
  2793. if ($item != '') {
  2794. if ($result != '') $result .= ' AND ';
  2795. $result .= '(' . $this->terms($list, "LIKE '%$item%'") . ')';
  2796. }
  2797. }
  2798. return $result;
  2799. }
  2800. function exactPhrase($list)
  2801. {
  2802. return $this->terms($list, "LIKE '%$this->_keyword%'");
  2803. }
  2804. function search_htmlCode()
  2805. {
  2806. $html = $this->_search;
  2807. if ($this->_keyword) {
  2808. $list[] = 'name';
  2809. $list[] = 'title';
  2810. $list[] = 'comment';
  2811. if ($this->_phrase == 'any') $terms = $this->anyWords($list);
  2812. if ($this->_phrase == 'all') $terms = $this->allWords($list);
  2813. if ($this->_phrase == 'exact') $terms = $this->exactPhrase($list);
  2814. $this->_resultTemplate = JOSC_utils::block($html, 'searchresult');
  2815. $results = $this->find($terms);
  2816. } else $results = '';
  2817. $html = str_replace('{resulttitle}', ($results) ? $this->searchMatch() : JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_NOSEARCHMATCH)), $html);
  2818. $html = JOSC_utils::ignoreBlock($html, 'searchresult', true, $results);
  2819. return $html;
  2820. }
  2821. }
  2822. ?>