/4.8/mambots/content/moscomment.php
PHP | 185 lines | 166 code | 6 blank | 13 comment | 20 complexity | 0d1e946b9239d29ea9432d9b5eb784ce MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-2.0
- <?php
- /**
- * @package MiaCMS
- * @author MiaCMS see README.php
- * @copyright see README.php
- * See COPYRIGHT.php for copyright notices and details.
- * @license GNU/GPL Version 2, see LICENSE.php
- * MiaCMS 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; version 2 of the License.
- */
-
- /** ensure this file is being included by a parent file */
- defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
-
- require_once mosCorePathAppend('/components/com_comment/comment.class.php');
- require_once mosCorePathAppend('/mambots/content/moscomment.html.php');
-
- $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosComment' );
-
- function botMosComment( $published, &$row, &$cparams, $page=0, $params ) {
- $config = new mosCommentConfig();
- $show_comments_in_print_popup = $config->get('show_comments_in_print_popup');
- if (!$show_comments_in_print_popup ){
- $pop = intval( mosGetParam( $_REQUEST, 'pop', 0 ) );
- if ($pop == 1)
- return true;
- }
- $bot = new botMosComment();
- $bot->perform( $published, $row, $cparams, $page, $params );
- return true;
- }
-
- class botMosComment {
- var $vars = array();
- var $clean_vars = array();
- var $config = array();
- var $option = '';
- var $task = '';
- var $Itemid = '';
- var $user = '';
- var $usecaptcha = '';
- var $absolute_path = '';
- var $live_site = '';
-
- function botMosComment() {
- $this->init();
- }
- function register() {
- return 'onPrepareContent';
- }
- function perform( $published, &$row, &$cparams, $page=0, $params ) {
- if (in_array ($row->sectionid, $this->config['allow_comments_in_sections'])) {
- ob_start();
- $total = $this->totalComments($row->id);
- $output = new mosComment_HTML();
- $output->start();
- if ($this->option=='com_content' AND $this->task=='view' AND !$params->get( 'intro_only' )) {
- if ( $total > 0 ) {
- $output->commentSectionStart(array('comment'=>T_('User Comments')));
- $this->loadComments($row->id);
- for ($i=0, $n=count( $this->clean_vars['comments'] ); $i < $n; $i++) {
- $output->commentStart();
- $output->commentTitle($this->clean_vars['comments'][$i]);
- $output->comment($this->clean_vars['comments'][$i]);
- if(($i+1)%$this->config['comments_per_page'] == 0 && ($i+1) < $n) {
- $output->commentEnd();
- $output->end();
- $output->commentPageBreak();
- $output->start();
- $output->commentSectionStart(array('comment'=>T_('Comments')));
- } else {
- $output->commentEnd();
- }
- }
- $output->commentSectionEnd();
- }
- $output->formStart();
- if (!$this->config['allow_anonymous_entries'] AND !$this->user->id) {
- $output->message(array('comment'=>T_('Please login or register to add comments')));
- } else {
- $mcreadonly = $mcname = $mcemail = $website = $curr_com = '';
- // retrieve data from session var if captcha failed
- mos_session_start();
- if (isset($_SESSION['comment_content'])) {
- $post = unserialize($_SESSION['comment_content']);
- $mcname = isset($post['name']) ? $post['name'] : '';
- $mcemail = isset($post['email']) ? $post['email'] : '';
- $website = isset($post['website']) ? $post['website'] : '';
- $curr_com = isset($post['comments']) ? $post['comments'] : '';
- unset($_SESSION['comment_content']);
- }
- if ($this->user->id) {
- $this->user->load($this->user->id);
- $mcname = $this->user->username;
- $mcemail = $this->user->email;
- $mcreadonly = " readonly='readonly'";
- }
- $cflink = $this->live_site.'/index.php?option=com_comment&task=captcha-audio&id='.$row->id;
- $cflink .= $this->Itemid ? "&Itemid=".$this->Itemid : '';
- $cflink = sefRelToAbs($cflink);
- $vars = array(
- 'total'=>$total,
- 'mcitemid'=>$this->Itemid,
- 'articleid'=>$row->id,
- 'limit'=>mosGetParam( $_POST, 'limit', '' ),
- 'limitstart'=>mosGetParam( $_POST, 'limitstart', '' ),
- 'mcname'=>$mcname,
- 'mcemail'=>$mcemail,
- 'website'=>$website,
- 'curr_com'=>$curr_com,
- 'mcreadonly'=>$mcreadonly,
- 'cflink'=>$cflink
- );
- $this->vars['form'] = $vars;
- $this->cleanVars();
- $output->formHeader($this->clean_vars['form']);
- $output->formInputFields($this->clean_vars['form']);
- if ($this->usecaptcha == '1') {
- $output->formCaptcha($this->clean_vars['form']);
- }
- $output->formFooter();
- }
- $output->formEnd();
- } else {
- $pages = $this->totalPages($row->text);
- $link = $this->live_site."/index.php?option=com_content&task=view&id=$row->id";
- $link .= $this->Itemid ? "&Itemid=".$this->Itemid : '';
- $link .= $pages > 0 ? ('&limit=1&limitstart='.$pages) : '';
- $link = sefRelToAbs($link);
- $vars = array('total'=>$total, 'link'=>$link);
- $output->summary($vars);
- }
- $output->end();
- $row->text .= ob_get_contents();
- ob_end_clean();
- }
- return true;
- }
- function init() {
- $this->option = mosGetParam($_REQUEST, 'option', '');
- $this->task = mosGetParam($_REQUEST, 'task', '');
- $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0);
- $this->Itemid = $this->Itemid ? $this->Itemid : '';
- $this->user = mamboCore::get('currentUser');
- $this->usecaptcha = mamboCore::get('mosConfig_usecaptcha');
- $this->absolute_path = mamboCore::get('mosConfig_absolute_path');
- $this->live_site = mamboCore::get('mosConfig_live_site');
- $config = mosCommentConfig::getInstance();
- $this->config = $config->cleanVars();
- }
- function cleanVars() {
- require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php');
- static $process;
- if (!isset($process)) $process =& new InputFilter( null, null, 1, 1 );
- $this->clean_vars = $process->process($this->vars);
- return $this->clean_vars;
- }
- function totalComments($id) {
- $database =& mamboDatabase::getInstance();
- $database->setQuery( "SELECT count(*) FROM #__comment WHERE articleid='".(int)$id."' AND published='1'" );
- return $database->loadResult();
- }
- function totalPages($content) {
- $regex = '/{(mospagebreak)\s*(.*?)}/i';
- $matches = array();
- preg_match_all( $regex, $content, $matches, PREG_SET_ORDER );
- return count($matches);
- }
- function loadComments($id) {
- $database =& mamboDatabase::getInstance();
- $database->setQuery( "SELECT * FROM #__comment WHERE articleid='".(int)$id."' AND published='1'" );
- $results = $database->loadAssocList();
- // format date
- for ($i=0; $i<count($results); $i++) {
- $results[$i]['startdate'] = $this->dateFormat($results[$i]['startdate']);
- }
- $this->vars['comments'] = $results;
- $this->cleanVars();
- }
- function dateFormat($date) {
- return mosFormatDate($date, $this->config['date_format']);
- }
- }
- ?>