PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/4.8/mambots/content/moscomment.php

http://miacms.googlecode.com/
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
  1. <?php
  2. /**
  3. * @package MiaCMS
  4. * @author MiaCMS see README.php
  5. * @copyright see README.php
  6. * See COPYRIGHT.php for copyright notices and details.
  7. * @license GNU/GPL Version 2, see LICENSE.php
  8. * MiaCMS is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; version 2 of the License.
  11. */
  12. /** ensure this file is being included by a parent file */
  13. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  14. require_once mosCorePathAppend('/components/com_comment/comment.class.php');
  15. require_once mosCorePathAppend('/mambots/content/moscomment.html.php');
  16. $_MAMBOTS->registerFunction( 'onPrepareContent', 'botMosComment' );
  17. function botMosComment( $published, &$row, &$cparams, $page=0, $params ) {
  18. $config = new mosCommentConfig();
  19. $show_comments_in_print_popup = $config->get('show_comments_in_print_popup');
  20. if (!$show_comments_in_print_popup ){
  21. $pop = intval( mosGetParam( $_REQUEST, 'pop', 0 ) );
  22. if ($pop == 1)
  23. return true;
  24. }
  25. $bot = new botMosComment();
  26. $bot->perform( $published, $row, $cparams, $page, $params );
  27. return true;
  28. }
  29. class botMosComment {
  30. var $vars = array();
  31. var $clean_vars = array();
  32. var $config = array();
  33. var $option = '';
  34. var $task = '';
  35. var $Itemid = '';
  36. var $user = '';
  37. var $usecaptcha = '';
  38. var $absolute_path = '';
  39. var $live_site = '';
  40. function botMosComment() {
  41. $this->init();
  42. }
  43. function register() {
  44. return 'onPrepareContent';
  45. }
  46. function perform( $published, &$row, &$cparams, $page=0, $params ) {
  47. if (in_array ($row->sectionid, $this->config['allow_comments_in_sections'])) {
  48. ob_start();
  49. $total = $this->totalComments($row->id);
  50. $output = new mosComment_HTML();
  51. $output->start();
  52. if ($this->option=='com_content' AND $this->task=='view' AND !$params->get( 'intro_only' )) {
  53. if ( $total > 0 ) {
  54. $output->commentSectionStart(array('comment'=>T_('User Comments')));
  55. $this->loadComments($row->id);
  56. for ($i=0, $n=count( $this->clean_vars['comments'] ); $i < $n; $i++) {
  57. $output->commentStart();
  58. $output->commentTitle($this->clean_vars['comments'][$i]);
  59. $output->comment($this->clean_vars['comments'][$i]);
  60. if(($i+1)%$this->config['comments_per_page'] == 0 && ($i+1) < $n) {
  61. $output->commentEnd();
  62. $output->end();
  63. $output->commentPageBreak();
  64. $output->start();
  65. $output->commentSectionStart(array('comment'=>T_('Comments')));
  66. } else {
  67. $output->commentEnd();
  68. }
  69. }
  70. $output->commentSectionEnd();
  71. }
  72. $output->formStart();
  73. if (!$this->config['allow_anonymous_entries'] AND !$this->user->id) {
  74. $output->message(array('comment'=>T_('Please login or register to add comments')));
  75. } else {
  76. $mcreadonly = $mcname = $mcemail = $website = $curr_com = '';
  77. // retrieve data from session var if captcha failed
  78. mos_session_start();
  79. if (isset($_SESSION['comment_content'])) {
  80. $post = unserialize($_SESSION['comment_content']);
  81. $mcname = isset($post['name']) ? $post['name'] : '';
  82. $mcemail = isset($post['email']) ? $post['email'] : '';
  83. $website = isset($post['website']) ? $post['website'] : '';
  84. $curr_com = isset($post['comments']) ? $post['comments'] : '';
  85. unset($_SESSION['comment_content']);
  86. }
  87. if ($this->user->id) {
  88. $this->user->load($this->user->id);
  89. $mcname = $this->user->username;
  90. $mcemail = $this->user->email;
  91. $mcreadonly = " readonly='readonly'";
  92. }
  93. $cflink = $this->live_site.'/index.php?option=com_comment&amp;task=captcha-audio&amp;id='.$row->id;
  94. $cflink .= $this->Itemid ? "&amp;Itemid=".$this->Itemid : '';
  95. $cflink = sefRelToAbs($cflink);
  96. $vars = array(
  97. 'total'=>$total,
  98. 'mcitemid'=>$this->Itemid,
  99. 'articleid'=>$row->id,
  100. 'limit'=>mosGetParam( $_POST, 'limit', '' ),
  101. 'limitstart'=>mosGetParam( $_POST, 'limitstart', '' ),
  102. 'mcname'=>$mcname,
  103. 'mcemail'=>$mcemail,
  104. 'website'=>$website,
  105. 'curr_com'=>$curr_com,
  106. 'mcreadonly'=>$mcreadonly,
  107. 'cflink'=>$cflink
  108. );
  109. $this->vars['form'] = $vars;
  110. $this->cleanVars();
  111. $output->formHeader($this->clean_vars['form']);
  112. $output->formInputFields($this->clean_vars['form']);
  113. if ($this->usecaptcha == '1') {
  114. $output->formCaptcha($this->clean_vars['form']);
  115. }
  116. $output->formFooter();
  117. }
  118. $output->formEnd();
  119. } else {
  120. $pages = $this->totalPages($row->text);
  121. $link = $this->live_site."/index.php?option=com_content&amp;task=view&amp;id=$row->id";
  122. $link .= $this->Itemid ? "&amp;Itemid=".$this->Itemid : '';
  123. $link .= $pages > 0 ? ('&amp;limit=1&amp;limitstart='.$pages) : '';
  124. $link = sefRelToAbs($link);
  125. $vars = array('total'=>$total, 'link'=>$link);
  126. $output->summary($vars);
  127. }
  128. $output->end();
  129. $row->text .= ob_get_contents();
  130. ob_end_clean();
  131. }
  132. return true;
  133. }
  134. function init() {
  135. $this->option = mosGetParam($_REQUEST, 'option', '');
  136. $this->task = mosGetParam($_REQUEST, 'task', '');
  137. $this->Itemid = mosGetParam($_REQUEST, 'Itemid', 0);
  138. $this->Itemid = $this->Itemid ? $this->Itemid : '';
  139. $this->user = mamboCore::get('currentUser');
  140. $this->usecaptcha = mamboCore::get('mosConfig_usecaptcha');
  141. $this->absolute_path = mamboCore::get('mosConfig_absolute_path');
  142. $this->live_site = mamboCore::get('mosConfig_live_site');
  143. $config = mosCommentConfig::getInstance();
  144. $this->config = $config->cleanVars();
  145. }
  146. function cleanVars() {
  147. require_once(mamboCore::get('mosConfig_absolute_path').'/includes/phpInputFilter/class.inputfilter.php');
  148. static $process;
  149. if (!isset($process)) $process =& new InputFilter( null, null, 1, 1 );
  150. $this->clean_vars = $process->process($this->vars);
  151. return $this->clean_vars;
  152. }
  153. function totalComments($id) {
  154. $database =& mamboDatabase::getInstance();
  155. $database->setQuery( "SELECT count(*) FROM #__comment WHERE articleid='".(int)$id."' AND published='1'" );
  156. return $database->loadResult();
  157. }
  158. function totalPages($content) {
  159. $regex = '/{(mospagebreak)\s*(.*?)}/i';
  160. $matches = array();
  161. preg_match_all( $regex, $content, $matches, PREG_SET_ORDER );
  162. return count($matches);
  163. }
  164. function loadComments($id) {
  165. $database =& mamboDatabase::getInstance();
  166. $database->setQuery( "SELECT * FROM #__comment WHERE articleid='".(int)$id."' AND published='1'" );
  167. $results = $database->loadAssocList();
  168. // format date
  169. for ($i=0; $i<count($results); $i++) {
  170. $results[$i]['startdate'] = $this->dateFormat($results[$i]['startdate']);
  171. }
  172. $this->vars['comments'] = $results;
  173. $this->cleanVars();
  174. }
  175. function dateFormat($date) {
  176. return mosFormatDate($date, $this->config['date_format']);
  177. }
  178. }
  179. ?>