/src/site/components/com_comment/joscomment/comment.class.php
PHP | 3209 lines | 2332 code | 387 blank | 490 comment | 353 complexity | 03b2846b7f05618caa20b605669e8cac MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- <?php defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
-
- /*
- * Copyright Copyright (C) 2007 Alain Georgette. All rights reserved.
- * Copyright Copyright (C) 2006 Frantisek Hliva. All rights reserved.
- * License http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
- *
- * !JoomlaComment is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * !JoomlaComment is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- global $mosConfig_absolute_path;
-
- require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/utils.php');
- require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/strutils.php');
- require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/jscript.php');
- require_once($mosConfig_absolute_path.'/components/com_comment/joscomment/security.php');
-
-
- class JOSC_template {
- var $_live_site;
- var $_absolute_path;
- var $_template_path = '';
- var $_template_absolute_path = '';
- var $_name = '';
- var $_css = '';
- var $_title = '';
- /*
- * parsed blocks
- */
- var $_body = '';
- var $_library = '';
- var $_readon = '';
- var $_previewline = '';
- var $_menu = ''; /* ? */
- var $_post = '';
- var $_search = '';
- var $_searchResults = '';
- var $_form = '';
- var $_poweredby = '';
-
- function JOSC_template($name,$css='template_css.css')
- {
- $this->_name = $name;
- $this->_css = $css;
- }
-
- function loadFromFile()
- {
- $fileName = $this->_template_absolute_path .'/'. $this->_name . '/index.html';
- if (file_exists($fileName)) {
- $file = fopen ($fileName, 'r');
- $template = fread ($file, filesize($fileName));
- fclose($file);
- return $template;
- } else die ('!JoomlaComment template not found: ' . $this->_name);
- }
-
- function CSS()
- {
- //return JOSC_utils::insertToHead('<link rel="stylesheet" href="' . $this->_template_path . '/' . $this->_name . '/css/'.$this->_css.'" type="text/css" />');
-
- global $mosConfig_caching;
- /*
- * cache does not calculate again head for bots... :(
- * and link rel outside head is not good accepted by IE7
- * for example after a embed object...
- * not a complete solution but less blocking
- */
- if ($mosConfig_caching) {
- $html = "\n<script type = \"text/javascript\">"
- . "<!--"
- . "\n if (!JOSC_cssStyleSheet)" /* TODO: search in StyleSheets elements if exist */
- . "\n { var JOSC_csslink = document.createElement('link');"
- . "\n var JOSC_cssStyleSheet = '". $this->_template_path . '/' . $this->_name . '/css/'.$this->_css ."';"
- . "\n JOSC_csslink.setAttribute('href', JOSC_cssStyleSheet );"
- . "\n JOSC_csslink.setAttribute('rel', 'stylesheet');"
- . "\n JOSC_csslink.setAttribute('type', 'text/css');"
- . "\n var JOSC_csshead = document.getElementsByTagName('head').item(0);"
- . "\n JOSC_csshead.appendChild(JOSC_csslink);"
- . "\n }//-->"
- . "\n</script>";
- return $html;
- } else {
- return JOSC_utils::insertToHead('<link rel="stylesheet" href="' . $this->_template_path . '/' . $this->_name . '/css/'.$this->_css.'" type="text/css" />');
- }
- }
-
- function parse($readon=false)
- {
- $template = $this->loadFromFile();
- $this->_body = JOSC_utils::block($template, 'body');
- $this->_library = JOSC_utils::block($template, 'library');
- if ($readon) {
- $this->_readon = JOSC_utils::block($template, 'readon');
- $this->_previewline = JOSC_utils::block($template, 'previewline');
- } else {
- $this->_menu = JOSC_utils::block($template, 'menu');
- $this->_search = JOSC_utils::block($template, 'search');
- $this->_searchResults = JOSC_utils::block($template, 'searchresults');
- $this->_post = JOSC_utils::block($template, 'post');
- $this->_form = JOSC_utils::block($template, 'form');
- $this->_poweredby = JOSC_utils::block($template, 'poweredby');
- }
- }
- }
-
- class JOSC_properties extends JOSC_template {
- /* special parameters */
- var $_contentrow;
- var $_params;
- var $_component;
- var $_sectionid;
- var $_comObject;
- var $_limitstart;
- var $_total;
- var $_request_uri;
- /* config params */
- var $_ajax;
- var $_local_charset;
- var $_only_registered;
- var $_language;
- var $_moderator = array();
- var $_include_sc;
- var $_exclude_sections = array();
- var $_exclude_categories = array();
- var $_exclude_contentitems = array();
- var $_exclude_contentids = array();
- var $_template;
- var $_template_css;
- var $_form_area_cols;
- var $_emoticon_pack;
- var $_emoticon_wcount;
- var $_tree;
- var $_mlink_post;
- var $_tree_indent;
- var $_sort_downward;
- var $_display_num;
- var $_support_emoticons;
- var $_support_UBBcode;
- var $_support_pictures;
- var $_censorship_enable;
- var $_censorship_case_sensitive;
- var $_censorship_words;
- var $_censorship_usertypes;
- var $_IP_visible;
- var $_IP_partial;
- var $_IP_caption;
- var $_IP_usertypes;
- var $_preview_visible;
- var $_preview_length;
- var $_preview_lines;
- var $_voting_visible;
- var $_use_name;
- var $_notify_admin;
- var $_notify_email;
- var $_notify_moderator;
- var $_notify_users;
- var $_rss;
- var $_date_format;
- var $_no_search;
- var $_captcha;
- var $_autopublish;
- var $_ban;
- var $_avatar;
- var $_profile;
- var $_profiles;
- var $_maxlength_text;
- var $_maxlength_word;
- var $_maxlength_line;
- var $_show_readon;
- var $_debug_username;
- var $_xmlerroralert;
- var $_ajaxdebug;
-
- function JOSC_properties($absolutePath, $liveSite, &$comObject, &$exclude, &$row, &$params)
- {
- global $my, $mosConfig_absolute_path;
-
- //require("$absolutePath/../config.comment.php");
- /* abolutepath = .../administrator/components/com_comment/joscomment absolute path */
- require_once("$mosConfig_absolute_path/administrator/components/com_comment/class.config.comment.php");
- $config = new JOSC_config(0, $comObject);
- if (!$config->load()) {
- $exclude = true;
- return;
- }
- /*
- * setting
- */
- $this->_comObject = $config->_comObject;
- $this->_component = $this->_comObject->_component;
- $this->_sectionid = $this->_comObject->_sectionid;
-
- $this->_content_id = $this->_comObject->_id;
-
-
- $this->_ajax = $config->_ajax;
- $this->_local_charset = $config->_local_charset;
- $this->_only_registered = $config->_only_registered;
- $this->_language = $config->_language;
- $this->_moderator = explode(',', $config->_moderator);
-
- /*
- * content item
- */
-
- if ($exclude && isset($row)) {
- $this->_show_readon = $this->_comObject->setShowReadon( $row, $params, $config );
-
- $this->_exclude_contentids = $config->_exclude_contentids ? explode(',', $config->_exclude_contentids) : array();
- $this->_exclude_contentitems = $config->_exclude_contentitems ? explode(',', $config->_exclude_contentitems) : array();
- $this->_exclude_sections = $config->_exclude_sections ? explode(',', $config->_exclude_sections) : array();
- $this->_exclude_categories = $config->_exclude_categories ? explode(',', $config->_exclude_categories) : array();
- $this->_include_sc = $config->_include_sc;
- if ($this->_comObject->_official) {
- $obj = $this;
- if (!$this->_comObject->checkSectionCategory($row, $obj ))
- return false;
- } else {
- if (!$this->_comObject->checkSectionCategory($row, $this->_include_sc, $this->_exclude_sections, $this->_exclude_categories, $this->_exclude_contentids ))
- return false;
- }
- }
-
- /*
- * others
- */
- $this->_tree = $config->_tree;
- $this->_mlink_post = $config->_mlink_post;
- $this->_tree_indent = $config->_tree_indent;
- $this->_sort_downward = $config->_sort_downward; //($this->_tree ? 0 : $config->_sort_downward);
- $this->_display_num = $config->_display_num;
- $this->_support_emoticons = $config->_support_emoticons;
- $this->_enter_website = $config->_enter_website;
- $this->_support_UBBcode = $config->_support_UBBcode;
- $this->_support_pictures = $config->_support_pictures;
- $this->_pictures_maxwidth = $config->_pictures_maxwidth;
- $this->_censorship_enable = $config->_censorship_enable && in_array(JOSC_utils::getJOSCUserType($my->usertype), explode(',', $config->_censorship_usertypes));
- $this->_censorship_case_sensitive = $config->_censorship_case_sensitive;
- // $this->_censorship_words = explode(',', $config->_censorship_words);
- $this->Set_censorship_words($config->_censorship_words);
- $this->_IP_usertypes = explode(',', $config->_IP_usertypes);
- $this->_IP_visible = $config->_IP_visible;
- $this->_IP_partial = $config->_IP_partial;
- $this->_IP_caption = $config->_IP_caption;
- $this->_preview_visible = $config->_preview_visible;
- $this->_preview_length = $config->_preview_length;
- $this->_preview_lines = $config->_preview_lines;
- $this->_voting_visible = $config->_voting_visible;
- $this->_use_name = $config->_use_name;
- $this->_notify_admin = $config->_notify_admin;
- $this->_notify_email = $config->_notify_email;
- $this->_notify_moderator = $config->_notify_moderator;
- $this->_autopublish = $config->_autopublish;
- $this->_notify_users = $config->_notify_users;
- $this->_rss = $config->_rss;
- $this->_date_format = $config->_date_format;
- $this->_no_search = $config->_no_search;
- $this->_captcha = $config->_captcha && in_array(JOSC_utils::getJOSCUserType($my->usertype), explode(',', $config->_captcha_usertypes));
- $this->_website_registered = $config->_website_registered;
- $this->_ban = $config->_ban;
- $cb = JOSC_TableUtils::existsTable('#__comprofiler');
- $this->_profile = $config->_support_profiles && $cb;
- $this->_avatar = $config->_support_avatars && $cb;
- $this->_maxlength_text = $config->_maxlength_text;
- $this->_maxlength_word = $config->_maxlength_word;
- $this->_maxlength_line = $config->_maxlength_line;
-
- $this->_absolute_path = $absolutePath;
- $this->_live_site = $liveSite;
-
- $this->_template = $config->_template_custom ? $config->_template_custom : $config->_template;
- $this->_template_path = $config->_template_custom ? $config->_template_custom_livepath : "$liveSite/templates";
- $this->_template_absolute_path = $config->_template_custom ? $config->_template_custom_path : "$absolutePath/templates";
- $this->_template_css = $config->_template_custom ? $config->_template_custom_css : $config->_template_css;
- $this->JOSC_template($this->_template, $this->_template_css);
- $this->_template_library = $config->_template_library;
- $this->_form_area_cols = $config->_form_area_cols;
-
- $this->_emoticon_pack = $config->_emoticon_pack;
- $this->_emoticon_wcount = $config->_emoticon_wcount;
- $this->_emoticons_path = $liveSite . "/emoticons/$this->_emoticon_pack/images";
-
- JOSC_utils::set_charsetConstant($this->_local_charset);
- $this->loadLanguage($GLOBALS['josComment_absolute_path'], $this->_language);
-
- $this->loadEmoticons("$absolutePath/emoticons/$this->_emoticon_pack/index.php");
-
- $this->_debug_username = $config->_debug_username;
- $this->_xmlerroralert = $config->_xmlerroralert ? '1' : '0';
- $this->_ajaxdebug = $config->_ajaxdebug ? '1' : '0';
- if ($this->_profile)
- $this->loadProfiles();
- $exclude = false;
- }
-
- function Set_censorship_words($censorship_words)
- {
- $this->_censorship_words = array();
-
- if ($this->_censorship_enable && $censorship_words) {
-
- $censorship_words = explode(',', $censorship_words);
-
- if (is_array($censorship_words)) {
-
- foreach($censorship_words as $word) {
-
- $word = trim($word);
-
- if (strpos($word, '=')) {
- $word = explode('=', $word);
- $from = trim($word[0]);
- $to = trim($word[1]);
- } else {
- $from = $word;
- $to = JOSC_strutils::str_fill(strlen($word), '*');
- }
-
- $this->_censorship_words[$from] = $to;
- }
- }
- }
- return;
- }
-
- function jscriptInit()
- {
- global $mosConfig_live_site, $my;
-
- $html = "\n<script type='text/javascript'>\n";
- $html .= "var JOSC_ajaxEnabled=$this->_ajax;";
- $html .= "if (!JOSC_http) JOSC_ajaxEnabled=false;";
- $html .= "var JOSC_sortDownward='$this->_sort_downward';";
- $captchaEnabled = $this->_captcha ? 'true' : 'false';
- $html .= "var JOSC_captchaEnabled=$captchaEnabled;";
- $html .= "var JOSC_template='$this->_template_path/$this->_name';";
- $html .= "var JOSC_liveSite='$this->_live_site';"; /* joscomment */
- $html .= "var JOSC_ConfigLiveSite='$mosConfig_live_site';";
- $html .= "var JOSC_linkToContent='".$this->_comObject->linkToContent( $this->_content_id )."';";
- $html .= "var JOSC_autopublish='$this->_autopublish';"; /* not used ?*/
- if ($this->_debug_username && ($my->username==$this->_debug_username || $this->_debug_username=="JOSCdebugactive")) {
- $html .= "var JOSC_XmlErrorAlert=$this->_xmlerroralert;";
- $html .= "var JOSC_AjaxDebug=$this->_ajaxdebug;";
- }
-
- $html .= "\n</script>\n";
- return $html;
- }
- function loadLanguage($path, $language)
- {
- // $path .= '/language/';
- // if ($language == 'auto') $language = $path . $GLOBALS['mosConfig_lang'] . '.php';
- // else $language = $path . $language;
- // if (file_exists($language))
- // require_once($language);
- // require_once($path . 'english.php'); // default is EN. non existant constants will be taken from default from this
- JOSC_utils::loadFrontendLoadLanguage($language);
- }
-
- function loadEmoticons($fileName)
- {
- require_once($fileName);
- $this->_emoticons = $GLOBALS["JOSC_emoticon"];
- }
- function loadProfiles()
- {
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- $database->setQuery('SELECT u.username, c.user_id, c.avatar
- FROM #__users AS u, #__comprofiler AS c
- WHERE u.id = c.user_id');
- $userList = $database->loadAssocList();
- $this->_profiles = array();
- foreach ($userList as $item) {
- /*
- * set _profiles[userid][avatar]
- */
- if ($this->_avatar)
- $this->_profiles[$item['user_id']]['avatar'] = $item['avatar'];
- else
- $this->_profiles[$item['user_id']]['avatar'] = false;
-
- /*
- * set _profiles[userid][id of cb]
- */
- if ($this->_profile)
- $this->_profiles[$item['user_id']]['id'] = $item['user_id'];
- else
- $this->_profiles[$item['user_id']]['id'] = false;
-
- }
- unset($userList);
- }
-
- }
-
- class JOSC_visual extends JOSC_properties {
- var $_parent_id = -1;
-
- function insertMenu()
- {
- $menu = new JOSC_menu($this->_menu);
- $menu->setContentId($this->_content_id);
- $menu->setTemplate_path($this->_template_path);
- $menu->setTemplate_name($this->_name);
- $menu->setRSS($this->_rss);
- $menu->setModerator($this->_moderator);
- $menu->setOnly_registered($this->_only_registered);
- $menu->setNoSearch($this->_no_search);
- return $menu->menu_htmlCode();
- }
-
- function insertPoweredby()
- {
- return '<div id="poweredby" align="center" class="small">Powered by <a target="_blank" href="http://compojoom.com/">!JoomlaComment '."3.26".'</a></div>';
- }
-
- function insertHiddenCopyright()
- {
- 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>';
- }
-
- function insertSearch()
- {
- $html = $this->_search;
- $hidden = JOSC_support::formHiddenValues($this->_content_id, $this->_component, $this->_sectionid);
- $html = str_replace('{_HIDDEN_VALUES}', $hidden, $html);
- $html = str_replace('{_JOOMLACOMMENT_SEARCH}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH)), $html);
- $html = str_replace('{_JOOMLACOMMENT_PROMPT_KEYWORD}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_PROMPT_KEYWORD)), $html);
- $html = str_replace('{_JOOMLACOMMENT_SEARCH_ANYWORDS}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_ANYWORDS)), $html);
- $html = str_replace('{_JOOMLACOMMENT_SEARCH_ALLWORDS}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_ALLWORDS)), $html);
- $html = str_replace('{_JOOMLACOMMENT_SEARCH_PHRASE}', JOSC_utils::filter($this->encodeData_Charset(_JOOMLACOMMENT_SEARCH_PHRASE)), $html);
- return $html;
- }
-
- function initializePost($item, $postCSS)
- { /* post is used in module latest... ! */
- $post = new JOSC_post($this->_post); /* template block */
- $post->setUseName($this->_use_name); /* needed for setItem */
- $post->setItem($item);
- $post->setTemplate_path($this->_template_path);
- $post->setTemplate_name($this->_name);
- $post->setCSS($postCSS);
- $post->setAjax($this->_ajax);
- $post->setTree($this->_tree);
- $post->setMLinkPost($this->_mlink_post);
- $post->setTree_indent($this->_tree_indent);
- $post->setDate_format($this->_date_format);
- $post->setIP_visible($this->_IP_visible);
- $post->setIP_partial($this->_IP_partial);
- $post->setIP_caption($this->_IP_caption);
- $post->setIP_usertypes($this->_IP_usertypes);
- $post->setCensorShip( $this->_censorship_enable,
- $this->_censorship_case_sensitive,
- $this->_censorship_words,
- $this->_censorship_usertypes
- );
- $post->setContentId($this->_content_id);
- $post->setComponent($this->_component);
- $post->setVoting_visible($this->_voting_visible);
- $post->setSupport_emoticons($this->_support_emoticons);
- $post->setSupport_UBBcode($this->_support_UBBcode);
- $post->setSupport_quotecode($this->_support_UBBcode); /* only module use */
- $post->setSupport_link($this->_support_UBBcode); /* only module use */
- $post->setSupport_pictures($this->_support_pictures, $this->_pictures_maxwidth);
- $post->setEmoticons($this->_emoticons);
- $post->setEmoticons_path($this->_emoticons_path);
- $post->setOnly_registered($this->_only_registered);
- $post->setWebsiteRegistered($this->_website_registered);
- $post->setModerator($this->_moderator);
- if ($post->_item['userid']) {
- $post->setUser_id( ($this->_profile && isset($this->_profiles[$post->_item['userid']])) ? $this->_profiles[$post->_item['userid']]['id'] : false );
- $post->setAvatar( ($this->_avatar && isset($this->_profiles[$post->_item['userid']])) ? $this->_profiles[$post->_item['userid']]['avatar'] : false );
- }
- $post->setNotify_users($this->_notify_users, $this->_notify_moderator);
- $post->setMaxLength_text($this->_maxlength_text);
- $post->setMaxLength_word($this->_maxlength_word);
- $post->setMaxLength_line($this->_maxlength_line);
-
- return $post;
- }
-
- function insertPost($item, $postCSS)
- { /* post is used in module latest... ! */
- $post = $this->initializePost($item, $postCSS);
-
- return( $post->post_htmlCode() );
- }
-
- function getPageNav()
- {
- if ($this->_total <= $this->_display_num) return '';
-
- $pageNav = new JOSC_PageNav( $this->_ajax, $this->_total, $this->_limitstart, $this->_display_num );
-
- $link = $this->_request_uri;
- /* delete limit and limitstart parameters before add new */
- $link = preg_replace("/(.*)(&josclimit=.*)(&.*|)/", '\\1\\3', $link);
- $link = preg_replace("/(.*)(&josclimitstart=.*)(&.*|)/", '\\1\\3', $link);
-
- $html = "<div id='joscPageNavLink'>".$pageNav->writePagesLinks( $link, "#joscpagenav" )."</div>";
-
- if ($this->_ajax)
- $html.= "<div id='joscPageNavNoLink' style='display:none;visibility:hidden;'>".$pageNav->writePagesLinks('')."</div>";
-
- $addjs = "\n<script type='text/javascript'>";
- if ($this->_sort_downward) {
- /* DESC addeed to begin -> if not begin needs refresh*/
- if ($this->_limitstart <= $this->_display_num)
- $addjs .= "var JOSC_postREFRESH=false;";
- else
- $addjs .= "var JOSC_postREFRESH=true;";
- } else {
- /* ASC addeed to end -> if not end needs refresh */
- if (($this->_limitstart+$this->_display_num)>=$this->_total)
- $addjs .= "var JOSC_postREFRESH=false;";
- else
- $addjs .= "var JOSC_postREFRESH=true;";
- }
- $addjs .= "</script>\n";
-
- return "<a name='joscpagenav'>".$addjs.$html;
-
- }
-
- function insertPageNav()
- {
- return "<div id='joscPageNav'>".$this->getPageNav()."</div>";
- }
-
- function getComments($onlydata=false)
- {
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- if ($this->_sort_downward) {
- $sort = 'DESC'; /* new first */
- } else {
- $sort = 'ASC'; /* last first */
- }
- $html = '';
- $com = $this->_component;
- /*
- * ORDER must be done only on high level
- * because children must be ordered ascending for tree construction
- */
- $queryselect = "SELECT * ";
- $querycount = "SELECT COUNT(*) ";
- $queryfrom = "\nFROM #__comment"
- . "\n WHERE contentid='$this->_content_id' AND component='$com' "
- . "\n AND published='1' ";
- $queryparent = $this->_tree ? "\n AND parentid<=0 " : "";
- $querychildren = $this->_tree ? "\n AND parentid>0 " : "";
- $queryorder = "\n ORDER BY id $sort";
-
- if ($this->_display_num>0) {
-
- /*
- * pages -> use limitstart on root id (childs are not counted - always attached to root id)
- */
-
- if ($this->_comment_id) {
- /*
- * - get the limitstart(page) of the comment_id
- * - comment id can be a root id but also a child !
- * in this case, we must search for its root id.
- */
- $parentid = $id = $this->_comment_id;
- for ($i=1; $i<=20 && $parentid>0; $i++)
- { /* LEFT JOIN is for loop optimization : 1 loop = 2 levels */
- /* 20 times is for infinity loop limit = maximum 40 levels. it should be enough....? :) */
- $query = "SELECT c.id, c.parentid, p.id AS p_id, p.parentid AS p_parentid "
- . "\n FROM #__comment AS c LEFT JOIN #__comment AS p ON c.parentid=p.id "
- . "\n WHERE c.id=$parentid LIMIT 1";
- $database->SetQuery($query);
- $row = $database->loadAssocList();
- if ($row=$row[0]) {
- $id = $row['id'];
- $parentid = $row['parentid'];
- if ($row['parentid']>0) {
- $id = $row['p_id'];
- $parentid=$row['p_parentid'];
- }
- } else {
- $id = $parentid = -1;
- }
- }
- if ($id) {
- /* get the limitstart from the root id */
- $database->SetQuery("SELECT id ".$queryfrom.$queryparent.$queryorder);
- $data = $database->loadResultArray();
- $i = array_search($id, $data);
- if ($i) $this->_limitstart = $i;
- }
- }
-
- $database->SetQuery($querycount.$queryfrom.$queryparent.$queryorder);
- $this->_total = $database->loadResult();
-
- $checklimit = new JOSC_PageNav($this->_ajax, $this->_total, $this->_limitstart, $this->_display_num);
- $this->_limitstart = $checklimit->limitstart;
-
- $database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder, $this->_limitstart, $this->_display_num);
- $dataparent = $database->loadAssocList();
-
- } else {
- $database->SetQuery($queryselect.$queryfrom.$queryparent.$queryorder);
- $dataparent = $database->loadAssocList();
- }
- if ($this->_tree) {
- $database->SetQuery($queryselect.$queryfrom.$querychildren."\n ORDER BY id ASC");
- $datachildren = $database->loadAssocList();
-
- $data = ($dataparent && count($datachildren)>0) ? array_merge($dataparent,$datachildren) : $dataparent;
- } else {
- $data = $dataparent;
- }
- //return "displ=".$this->_display_num;
- //return JOSC_utils::debug_array($data);
-
- /*
- * $data is composed of ALL or ROOT array + CHILDREN array
- * this means that position of a ROOT gives the page position.
- */
- $postCSS = 1;
-
- if (!$data && $onlydata) return $data;
-
- if ($data != null) {
-
- if ($this->_tree) $data = JOSC_utils::buildTree($data);
-
- //return $data;
- if ($onlydata) return $data; /* after the foreach */
-
- if ($data != null) {
- foreach($data as $item) {
- $html .= $this->insertPost($item, $postCSS);
- $postCSS++;
- if ($postCSS == 3) $postCSS = 1;
- }
- }
- }
-
- $addjs = "\n<script type='text/javascript'>"
- . " var JOSC_postCSS=$postCSS;"
- . "</script>";
-
- /* Daniel add-on for Allvideo Reloaded */
- if (defined('_JOSC_J15')) {
- if (JPluginHelper::importPlugin('content', 'avreloaded')) {
- $app = &JFactory::getApplication();
- $res = $app->triggerEvent('onAvReloadedGetVideo', array($html));
- if (is_array($res) && (count($res) == 1)) {
- $html = $res[0];
- }
- }
- }
- /* *** */
- return $html.$addjs;
- }
-
- function insertComments()
- {
- return "<div id='Comments'>".$this->getComments()."</div>";
- }
-
- function insertForm()
- {
- $form = new JOSC_form($this->_form); /* template block */
- $form->setAbsolute_path($this->_absolute_path);
- $form->setLive_site($this->_live_site);
- $form->setOnly_registered($this->_only_registered);
- $form->setSupport_emoticons($this->_support_emoticons);
- $form->setSupport_UBBcode($this->_support_UBBcode);
- $form->setEmoticons($this->_emoticons);
- $form->setEmoticons_path($this->_emoticons_path);
- $form->setTemplate_path($this->_template_path);
- $form->setTemplateAbsolutePath($this->_template_absolute_path);
- $form->setTemplate_name($this->_name);
- $form->setContentId($this->_content_id);
- $form->setComponent($this->_component);
- $form->setSectionid($this->_sectionid);
- $form->setCaptcha($this->_captcha);
- $form->setNotifyUsers($this->_notify_users);
- $form->setEnterWebsite($this->_enter_website);
- $form->setEmoticonWCount($this->_emoticon_wcount);
- $form->setFormAreaCols($this->_form_area_cols);
- $form->set_tname($this->_tname);
- $form->set_temail($this->_temail);
- $form->set_twebsite($this->_twebsite);
- $form->set_tnotify($this->_tnotify);
-
- return $form->form_htmlCode();
- }
-
- function comments($number)
- {
- if ($number < 1) $comments = _JOOMLACOMMENT_COMMENTS_0;
- elseif ($number == 1) $comments = _JOOMLACOMMENT_COMMENTS_1;
- elseif ($number >= 2 && $number <= 4) $comments = _JOOMLACOMMENT_COMMENTS_2_4;
- else $comments = _JOOMLACOMMENT_COMMENTS_MORE;
-
- return $comments;
- }
-
- function insertCountButton()
- {
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- $address = $this->_comObject->linkToContent( $this->_content_id );
- $com = $this->_component;
-
- /*
- * READON BLOCK
- */
- $query = "SELECT COUNT(*) FROM #__comment WHERE contentid='$this->_content_id' AND component='$com' AND published='1'";
- $database->SetQuery($query);
- $number = $database->loadResult();
- if (!$number) $number = 0;
- $html = $this->_readon;
- /*
- * no blocks
- */
- /* {READON_xxx} */
- $html = str_replace('{READON_LINK}', $address , $html);
- $html = str_replace('{READON_WRITE_COMMENT}', _JOOMLACOMMENT_WRITECOMMENT, $html);
- $html = str_replace('{READON_COUNT}', $number, $html);
- $html = str_replace('{READON_COMMENTS}', $this->comments($number), $html);
-
- /*
- * PREVIEW BLOCK
- */
-
- /* {BLOCK-preview} */
-
- if ($this->_preview_visible) {
- $database->SetQuery("SELECT * FROM #__comment WHERE contentid='$this->_content_id' AND component='$com' AND published='1' ORDER BY date DESC");
- $data = $database->loadAssocList();
- }
- $display = $this->_preview_visible && ($data!=null);
- $html = JOSC_utils::checkBlock('BLOCK-preview', $display, $html);
- if ($display) {
- $index = 0;
- $previewlines = '';
- foreach($data as $item) {
- if ($index >= $this->_preview_lines)
- break;
- if ($item['title'] != '') {
- $title = $item['title'];
- } else {
- $title = $item['comment'];
- }
- if (strlen($title) > $this->_preview_length)
- $title = substr($title, 0, $this->_preview_length) . '...';
-
- $previewline = $this->_previewline;
- /* {PREVIEW_LINK} */
- $previewline = str_replace('{PREVIEW_LINK}', $address, $previewline);
- /* {PREVIEW_DATE} */
- $previewline = str_replace('{PREVIEW_DATE}', JOSC_utils::getLocalDate($item['date'],$this->_date_format) , $previewline);//date($this->_date_format,strtotime($item['date'])) , $previewline);
- /* {PREVIEW_TITLE} */
- $previewline = str_replace('{PREVIEW_TITLE}', $title, $previewline);
- /* {PREVIEW_TITLE} */
- $previewline = str_replace('{id}', $item['id'], $previewline);
-
- $index++;
- $previewlines .= $previewline;
- }
- /* {preview-lines} */
- $html = str_replace('{preview-lines}', $previewlines, $html);
-
- }
- return $html;
- }
-
- function visual_htmlCode()
- {
- // global $option, $task;
-
- $html = "";
- $css = $this->CSS(); /* empty if no cache */
-
- // $contentId = intval($this->decodeData_Charset('id'));
- /*
- * if check htmlCode -> html code
- * else if check readon -> readon
- * else nothing
- *
- */
- $checkVisual = $this->_comObject->checkVisual( $this->_content_id );
- if ($checkVisual)
- {
- $html .= JOSC_jscript::insertJavaScript($this->_live_site);
- /*
- * get template blocks
- * _body (container)
- * _menu
- * _search
- * _searchResults
- * _post
- * _form
- * _poweredby
- */
- $this->parse(false);
-
- /*
- * construct HTML (by replacement...)
- */
- $html .= "<div id='comment'>";
- if ($this->_body) {
- $html .= $this->_body;
- $html = JOSC_utils::checkBlock('library', $this->_template_library, $html); /* js scripts ... */
- $html = JOSC_utils::checkBlock('menu', false, $html, $this->insertMenu());
- $html = JOSC_utils::checkBlock('post', false, $html, $this->insertComments());
- $html = JOSC_utils::checkBlock('form', false, $html, $this->insertForm());
- $html = JOSC_utils::checkBlock('pagenav', false, $html, $this->insertPageNav());
- $html = JOSC_utils::checkBlock('poweredby', false, $html, $this->insertPoweredby());
- } else {
- $html .= $this->insertMenu();
- if ($this->_sort_downward) {
- $html .= $this->insertForm();
- $html .= $this->insertComments();
- } else {
- $html .= $this->insertComments();
- $html .= $this->insertForm();
- }
- $html .= $this->insertPoweredby();
- }
- $html .= $this->insertHiddenCopyright();
- $html .= "</div>";
- $html .= $this->jscriptInit();
- $html .= $css;
-
- } elseif ($this->_show_readon) {
- /*
- * get template blocks
- * _readon
- * _previewlines
- */
- $this->parse(true);
-
- $html .= $this->insertCountButton();
- $html .= $css;
- } else
- return "";
-
- return $html;
- }
- }
-
- class JOSC_board extends JOSC_visual {
- // var $_contentId; /* row->id */
- var $_josctask;
- var $_userid;
- var $_usertype;
- var $_tname;
- var $_ttitle;
- var $_tcomment;
- var $_twebsite;
- var $_temail;
- var $_comment_id;
- var $_content_id = 0; /* row-<id OR
- * decode content_id from url (comes from the add new comment form)
- * -> deleteall, editpost, getComments, gotoPost
- */
- var $_search_keyword;
- var $_search_phrase;
- var $_charset;
-
- function JOSC_board($absolutePath, $liveSite, &$comObject, &$exclude, &$row, &$params)
- { /* be carefull, board is used in component but also in module !! */
- $this->JOSC_properties($absolutePath, $liveSite, $comObject, $exclude, $row, $params);
- }
-
- function setContentId($value)
- {
- $this->_content_id = $value;
- }
-
- function setUser()
- {
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- /* also in post ! and notification */
- $query = "SELECT * FROM #__users WHERE id='".$this->_userid."' LIMIT 1";
- $database->SetQuery($query);
- $result = $database->loadAssocList();
- if ($result) {
- $user = $result[0];
- $this->_usertype = $user['usertype'];
- $this->_tname = $this->_use_name ? $user['name'] : $user['username'];
- $this->_temail = $user['email'];
- }
-
- }
-
- function voting($item, $mode)
- {
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- $t = time()-3 * 86400;
- $database->SetQuery("DELETE FROM #__comment_voting WHERE time<'$t'");
- $database->Query();
- $database->SetQuery("SELECT COUNT(*) FROM #__comment_voting WHERE id='" . $item['id'] . "' AND ip='" . $_SERVER['REMOTE_ADDR'] . "'");
- $exists = $database->loadResult();
- if (!$exists) {
- $item["voting_$mode"]++;
- $database->SetQuery("
- UPDATE #__comment SET
- voting_$mode='" . $item["voting_$mode"] . "'
- WHERE id=$this->_comment_id");
- $database->Query() or die('Database error: voting(1)!');
- $database->SetQuery("INSERT INTO #__comment_voting(id,ip,time)
- VALUES(
- '" . $item['id'] . "',
- '" . $_SERVER['REMOTE_ADDR'] . "',
- '" . time() . "')");
- $database->Query() or die("Database error: voting(2)!");
- }
- $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
- header($header);
- $xml = '<?xml version="1.0" standalone="yes"?><voting><id>' . $item['id'] . '</id><yes>' . $item["voting_yes"] . '</yes><no>' . $item["voting_no"] . '</no></voting>';
- $this->_comObject->cleanComponentCache();
- exit($xml);
- }
-
- // function getNewPost($sort, &$data)
- // {
- // global $database;
- // $database->SetQuery("SELECT * FROM #__comment WHERE contentid='$this->_content_id' AND published='1' ORDER BY id $sort");
- // $data = $database->loadAssocList(); // or die('Database error: getNewPost!');
- // }
-
- function isBlocked($ip)
- {
- if ($this->_ban != '') {
- $ipList = split(',', $this->_ban);
- foreach($ipList as $item) {
- if (trim($item) == $ip) return true;
- }
- }
- return false;
- }
-
- // function censorTextOLD($text)
- // {
- // if ($this->_censorship_enable && is_array($this->_censorship_words)) {
- // if ($this->_censorship_case_sensitive) $replace = str_replace;
- // else $replace = str_ireplace;
- // foreach($this->_censorship_words as $word) {
- // $word = trim($word);
- // if (strpos($word, '=')) {
- // $word = explode('=', $word);
- // $text = $replace(trim($word[0]), trim($word[1]), $text);
- // } else $text = $replace($word, JOSC_strutils::str_fill(strlen($word), '*'), $text);
- // }
- // }
- // return $text;
- // }
-
- function censorText($text)
- {
- return JOSC_utils::censorText($text,$this->_censorship_enable,$this->_censorship_words,$this->_censorship_case_sensitive);
- }
-
- function insertNewPost($ajax = false)
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- if ($this->isBlocked($ip)) return false;
-
- global $my;
-
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- $debug = '';
-
- $com = $this->_component;
- $userid = $this->_userid;
- $name = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tname)));
- $email = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_temail)));
- $website = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_twebsite)));
- if ( $website && strncmp( "http://", $website, 7 )!=0 ) $website = "http://" . $website;
- $website = htmlentities($website);//ampReplace($website);
- $notify = JOSC_utils::mysql_escape_string(strip_tags($this->_tnotify)) ? true : false ;
- $title = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_ttitle)));
- $comment = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tcomment)));
- if (!$comment) $comment = _JOOMLACOMMENT_EMPTYCOMMENT;
- $published = $this->_autopublish || JOSC_utils::isModerator($this->_moderator);
- $parent_id = $this->_parent_id;
- $database->SetQuery("
- INSERT INTO #__comment
- (contentid,component,ip,userid,usertype,date,name,email,website,notify,title,comment,published,voting_yes,voting_no,parentid)
- VALUES(
- '$this->_content_id',
- '$com',
- '$ip',
- '$userid',
- '',
- now(),
- '$name',
- '$email',
- '$website',
- '$notify',
- '$title',
- '$comment',
- '$published',
- '0',
- '0',
- '$parent_id'
- )");
- $result=$database->Query() or die(_JOOMLACOMMENT_SAVINGFAILED); //.$database->getQuery());
-
- $this->_comment_id = $database->insertid();
-
- $notification = new JOSC_notification($this, $this->_comment_id, $this->_content_id);
-
- $notification->setNotifyAllPostOfUser($userid, $email, $notify);
-
- $notification->lists['name'] = $name;
- $notification->lists['title'] = $title;
- $notification->lists['notify'] = $notify;
- $notification->lists['comment'] = $comment;
-
- if ($published) {
- $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_NEW_SUBJECT;
- $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_NEW_MESSAGE;
- $templist = $notification->getMailList($this->_content_id,$email);
- $notification->notifyMailList( $templist );
- } else {
- $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_TOBEAPPROVED_SUBJECT;
- $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_TOBEAPPROVED_MESSAGE;
- if (!JOSC_utils::isModerator($this->_moderator)) {
- $templist = $notification->getMailList_moderator();
- $notification->notifyMailList($templist);
- }
- }
-
- if ($ajax) {
- $data = $this->getComments(true);
-
- // if ($this->_tree) {
- // $this->getNewPost('ASC', $data); /* get all post of the content_id */
- // if ($data) {
- // $id = $data[sizeOf($data)-1]['id'];
- // $data = JOSC_utils::buildTree($data);
- // $after = -1;
- // /* look for the right place */
- // foreach($data as $item) {
- // if ($item['id'] == $id) {
- // $item['after'] = $after;
- // $item['view'] = $published;
- // $item['debug'] = $debug;
- // $item['noerror'] = 1;
- // return $item;
- // }
- // $after = $item['id'];
- // }
- // }
- // } else {
- // $this->getNewPost('DESC LIMIT 1', $data);
- // }
- /* $data[0]['view'] = $published;
- $data[0]['debug'] = $debug;
- $data[0]['noerror'] = 1;
- return $data[0];
- */
- $after = -1;
- /* look for the right place */
- foreach($data as $item) {
- if ($item['id'] == $this->_comment_id) {
- $item['after'] = $after;
- $item['view'] = $published;
- $item['debug'] = $debug;
- $item['noerror'] = 1;
- return $item;
- }
- $after = $item['id'];
- }
- $data[0]['view'] = $published;
- $data[0]['debug'] = $debug;
- $data[0]['noerror'] = 1;
- return $data[0];
- } else return $published;
- }
-
- function editPost()
- {
- $ip = $_SERVER['REMOTE_ADDR'];
- if ($this->isBlocked($ip)) return false;
-
- if (defined('_JOSC_J15'))
- $database =& JFactory::getDBO();
- else
- global $database;
-
- $debug = '';
-
- $database->SetQuery("SELECT * FROM #__comment WHERE id='$this->_comment_id'");
- $item = $database->loadAssocList();
-
- if ($this->checkEditPost($item[0])) {
- $title = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_ttitle)));
- $comment = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_tcomment)));
- $website = $this->censorText(JOSC_utils::mysql_escape_string(strip_tags($this->_twebsite)));
- if ( $website && strncmp( "http://", $website, 7 )!=0 ) $website = "http://" . $website;
- $website = htmlentities($website);//ampReplace($website);
- $notify = JOSC_utils::mysql_escape_string(strip_tags($this->_tnotify)) ? '1' : '0' ;
- $query = "
- UPDATE #__comment SET
- date=now()
- ,title='$title'
- ,comment='$comment'
- ,website='$website'
- ,notify='$notify'
- WHERE id=$this->_comment_id";
- $database->SetQuery($query);
- $database->Query() or die(_JOOMLACOMMENT_EDITINGFAILED . "\n $query");
- $database->SetQuery("SELECT * FROM #__comment WHERE id='$this->_comment_id' AND published='1' LIMIT 1");
- $data = $database->loadAssocList() or die('Database error: editPost!');
-
-
- $notification = new JOSC_notification($this, $this->_comment_id, $this->_content_id);
- $notification->setNotifyAllPostOfUser($item[0]['userid'], $item[0]['email'], $notify);
-
- /* send email to Moderator */
- if (!JOSC_utils::isModerator($this->_moderator)) {
- $notification->lists['name'] = $item[0]['name'];
- $notification->lists['title'] = $title;
- $notification->lists['notify'] = $item[0]['notify'];
- $notification->lists['comment'] = $comment;
- $notification->lists['subject'] = _JOOMLACOMMENT_NOTIFY_EDIT_SUBJECT;
- $notification->lists['message'] = _JOOMLACOMMENT_NOTIFY_EDIT_MESSAGE;
- $templist = $notification->getMailList_moderator();
- $notification->notifyMailList( $templist );
- }
-
- $data[0]['view'] = 1;
- $data[0]['debug'] = $debug;
- $data[0]['noerror'] = 1;
- return $data[0];
- }
- }
-
- /*
- * same as isCommentModerator
- */
- function checkEditPost($item)
- {
- //global $my;
-
- if (!$item) return false;
- /* edit if registered or comment is own or is moderator */
- if ( JOSC_utils::isCommentModerator($this->_moderator, $item['userid'])) // $item['name'], $item['usertype']))
- return true;
- else
- return false;
- }
-
- function modify($event = false)
- {
- /* example of call : $this->modify(editPost)
- * event is a method which will be called below as $this->$event(true)
- * where true means ajax call.
- */
- global $my;
-
- if (!$event) {
- if (!$my->username && $this->_only_registered) {
- /* only registered */
- JOSC_utils::showMessage(_JOOMLACOMMENT_ONLYREGISTERED);
- } else {
- if (!($this->_captcha && !JOSC_security::captchaResult(true))) {
- /* captcha ok */
- $published = $this->insertNewPost();
- unset($this->_tcomment);
- $this->_comObject->cleanComponentCache();
- if ($published) {
- mosRedirect($this->_comObject->linkToContent($this->_content_id, $this->_comment_id));
- } else {
- mosRedirect($this->_comObject->linkToContent($this->_content_id), _JOOMLACOMMENT_BEFORE_APPROVAL);
- }
- }
- }
- mosRedirect($this->_comObject->linkToContent($this->_content_id, $this->_comment_id));
- }
- $header = 'Content-Type: text/xml; charset=utf-8'; //.$this->_local_charset;
- header($header);
- if (!($this->_captcha && !JOSC_security::captchaResult(true))) {
- $item = $this->$event(true);
- if (!$item) exit();
- $this->parse();
- $xml = '<?xml version="1.0" standalone="yes"?>';
- $xml .= '<post>';
- $xml .= '<id>' . $item['id'] . '</id>';
- if ($this->_tree && isset($item['after'])) $xml .= '<after>' . $item['after'] . '</after>';
- $xml .= '<published>' . $item['view'] . '</published>';
- $xml .= '<noerror>' . $item['noerror'] . '</noerror>';
- $xml .= '<debug>' . $item['debug'] . '</debug>';
- if ($item['view']) {
- $html = JOSC_utils::cdata(JOSC_utils::filter($this->encodeData_Charset($this->insertPost($item, ''))));
- $xml .= "<body>$html</body>";
- }
- if ($this->_captcha) {
- $captcha = JOSC_utils::cdata(JOSC_security::insertCaptcha('security_refid'));
- $xml .= "<captcha>$captcha</captcha>";
- }
- $xml .= '</post>';
- $this->_comObject->clean…
Large files files are truncated, but you can click here to view the full file