PageRenderTime 50ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_easyblog/helpers/comment.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 695 lines | 510 code | 132 blank | 53 comment | 71 complexity | 6130daf696fe2c154095d8c8bc3e31a1 MD5 | raw file
  1. <?php
  2. /**
  3. * @package EasyBlog
  4. * @copyright Copyright (C) 2010 Stack Ideas Private Limited. All rights reserved.
  5. * @license GNU/GPL, see LICENSE.php
  6. *
  7. * EasyBlog is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. * See COPYRIGHT.php for copyright notices and details.
  12. */
  13. defined('_JEXEC') or die('Restricted access');
  14. /*
  15. * Comment utilities class.
  16. *
  17. */
  18. require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
  19. class EasyBlogCommentHelper
  20. {
  21. public $pagination = null;
  22. /**
  23. * Format comments data
  24. **/
  25. public static function format( $comments )
  26. {
  27. for($i = 0; $i < count($comments); $i++)
  28. {
  29. $row =& $comments[$i];
  30. $user = EasyBlogHelper::getTable( 'Profile', 'Table' );
  31. $row->poster = $user->load( $row->created_by );
  32. $row->comment = nl2br($row->comment);
  33. }
  34. return $comments;
  35. }
  36. /*
  37. * Determines whether the current comment system used is built in or an external tool
  38. *
  39. * @param null
  40. * @return boolean True if built in false otherwise.
  41. */
  42. public static function isBuiltin()
  43. {
  44. jimport( 'joomla.filesystem.file' );
  45. $config = EasyBlogHelper::getConfig();
  46. if( !$config->get( 'main_comment' ) )
  47. {
  48. return false;
  49. }
  50. // @rule: If the default comments and multiple comments are enabled, we assume that it is built in.
  51. if( $config->get( 'main_comment' ) && $config->get( 'main_comment_multiple' ) )
  52. {
  53. return true;
  54. }
  55. if( $config->get( 'intensedebate' ) )
  56. {
  57. return false;
  58. }
  59. if( $config->get( 'comment_disqus' ) )
  60. {
  61. return false;
  62. }
  63. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jomcomment' . DIRECTORY_SEPARATOR . 'jomcomment.php';
  64. if( $config->get( 'comment_jomcomment' ) && JFile::exists( $file ) )
  65. {
  66. return false;
  67. }
  68. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jcomments' . DIRECTORY_SEPARATOR . 'jcomments.php';
  69. if( $config->get( 'comment_jcomments' ) && JFile::exists( $file ) )
  70. {
  71. return false;
  72. }
  73. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_rscomments' . DIRECTORY_SEPARATOR . 'rscomments.php';
  74. if( $config->get( 'comment_rscomments' ) && JFile::exists( $file ) )
  75. {
  76. return false;
  77. }
  78. if( $config->get( 'comment_facebook' ) )
  79. {
  80. return false;
  81. }
  82. return true;
  83. }
  84. /**
  85. * Retrieves the comment count for the specific blog
  86. *
  87. * @param int $blogId The blog id.
  88. **/
  89. public static function getCommentCount( $blog )
  90. {
  91. $blogId = $blog->id;
  92. $config = EasyBlogHelper::getConfig();
  93. // If multiple comments, we output a common link
  94. if( $config->get( 'main_comment_multiple' ) )
  95. {
  96. return false;
  97. }
  98. if( $config->get( 'comment_komento' ) )
  99. {
  100. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'bootstrap.php';
  101. if( JFile::exists($file) )
  102. {
  103. require_once($file);
  104. $commentsModel = Komento::getModel( 'comments' );
  105. $commentCount = $commentsModel->getCount( 'com_easyblog', $blog->id );
  106. return $commentCount;
  107. }
  108. }
  109. if( $config->get( 'comment_compojoom' ) )
  110. {
  111. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_comment' . DIRECTORY_SEPARATOR . 'plugin' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'josc_com_easyblog.php';
  112. if( JFile::exists( $file ) )
  113. {
  114. require_once( $file );
  115. return CommentEasyBlog::output( $blog , array() , true );
  116. }
  117. }
  118. if( $config->get( 'intensedebate' ) )
  119. {
  120. return false;
  121. }
  122. if( $config->get( 'comment_disqus' ) )
  123. {
  124. static $disqus = false;
  125. if( !$disqus )
  126. {
  127. ob_start();
  128. ?>
  129. var disqus_shortname = '<?php echo $config->get( 'comment_disqus_code' );?>';
  130. (function () {
  131. var s = document.createElement('script'); s.async = true;
  132. s.type = 'text/javascript';
  133. s.src = 'http://' + disqus_shortname + '.disqus.com/count.js';
  134. (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
  135. }());
  136. <?php
  137. $contents = ob_get_contents();
  138. ob_end_clean();
  139. JFactory::getDocument()->addScriptDeclaration( $contents );
  140. $disqus = true;
  141. }
  142. $string = '<!-- Disqus -->';
  143. $string .= '<span class="discus-comment">';
  144. $string .= '<a href="' . EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id='.$blogId) . '#disqus_thread"><span>'.JText::_('COM_EASYBLOG_COMMENTS').'</span></a>';
  145. $string .= '</span>';
  146. return $string;
  147. // return false;
  148. }
  149. if( $config->get( 'comment_livefyre') )
  150. {
  151. return false;
  152. }
  153. if( $config->get( 'comment_jomcomment' ) )
  154. {
  155. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jomcomment' . DIRECTORY_SEPARATOR . 'helper' . DIRECTORY_SEPARATOR . 'minimal.helper.php';
  156. jimport( 'joomla.filesystem.file' );
  157. if( !JFile::exists( $file ) )
  158. {
  159. return false;
  160. }
  161. require_once( $file );
  162. return jcCountComment( $blogId , 'com_easyblog' );
  163. }
  164. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jcomments' . DIRECTORY_SEPARATOR . 'jcomments.php';
  165. if( $config->get( 'comment_jcomments' ) && JFile::exists( $file ) )
  166. {
  167. $db = EasyBlogHelper::db();
  168. $query = 'SELECT COUNT(1) FROM ' . $db->nameQuote( '#__jcomments' ) . ' '
  169. . 'WHERE ' . $db->nameQuote( 'object_id' ) . '=' . $db->Quote( $blogId ) . ' '
  170. . 'AND ' . $db->nameQuote( 'object_group' ) . '=' . $db->Quote( 'com_easyblog' ) . ' '
  171. . 'AND ' . $db->nameQuote( 'published' ) . '=' . $db->Quote( 1 );
  172. $db->setQuery( $query );
  173. $total = $db->loadResult();
  174. return $total;
  175. }
  176. if( $config->get( 'comment_rscomments' ) )
  177. {
  178. return false;
  179. }
  180. if( $config->get( 'comment_facebook' ) )
  181. {
  182. return false;
  183. }
  184. // @task: Let's allow the plugin to also trigger the comment count.
  185. $params = EasyBlogHelper::getRegistry();
  186. $result = EasyBlogHelper::triggerEvent( 'easyblog.commentCount' , $blog , $params , 0 );
  187. $count = trim( implode( " " , $result ) );
  188. if( !empty( $count ) )
  189. {
  190. return $count;
  191. }
  192. $db = EasyBlogHelper::db();
  193. $query = 'SELECT COUNT(1) FROM '
  194. . $db->nameQuote( '#__easyblog_comment' )
  195. . ' WHERE ' . $db->nameQuote( 'post_id' ) . '=' . $db->Quote( $blogId )
  196. . ' AND `published` = ' . $db->Quote('1');
  197. $db->setQuery( $query );
  198. $count = $db->loadResult();
  199. return $count;
  200. }
  201. public static function getBlogCommentLite( $blogId, $limistFrontEnd = 0, $sort = 'asc')
  202. {
  203. return EasyBlogCommentHelper::getBlogComment($blogId, $limistFrontEnd, $sort, true);
  204. }
  205. public function getBlogComment( $blogId, $limistFrontEnd = 0, $sort = 'asc', $isLite = false)
  206. {
  207. $config = EasyBlogHelper::getConfig();
  208. $comments = array();
  209. require_once( EBLOG_MODELS . DIRECTORY_SEPARATOR . 'blog.php' );
  210. $model = new EasyBlogModelBlog();
  211. $comments = $model->getBlogComment( $blogId , $limistFrontEnd , $sort, $isLite);
  212. $this->pagination = $model->getPagination();
  213. return $comments;
  214. }
  215. public static function getCommentHTML( $blog , $comments = array() , $pagination = '' )
  216. {
  217. $config = EasyBlogHelper::getConfig();
  218. $path = EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'comments';
  219. $registration = $config->get( 'comment_registeroncomment' );
  220. $commentSystems = array();
  221. // Double check this with Joomla's registration component
  222. if( $registration )
  223. {
  224. $params = JComponentHelper::getParams( 'com_users' );
  225. $registration = $params->get( 'allowUserRegistration' ) == '0' ? false : $registration;
  226. }
  227. if( $config->get( 'comment_facebook' ) )
  228. {
  229. require_once( $path . DIRECTORY_SEPARATOR . 'facebook.php' );
  230. $commentSystems[ 'FACEBOOK' ] = EasyBlogCommentFacebook::getHTML( $blog );
  231. if( !$config->get( 'main_comment_multiple' ) )
  232. {
  233. return $commentSystems[ 'FACEBOOK' ];
  234. }
  235. }
  236. if( $config->get( 'comment_compojoom' ) )
  237. {
  238. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_comment' . DIRECTORY_SEPARATOR . 'plugin' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'josc_com_easyblog.php';
  239. if( JFile::exists( $file ) )
  240. {
  241. require_once( $file );
  242. $commentSystems[ 'COMPOJOOM' ] = CommentEasyBlog::output( $blog , array() );
  243. if( !$config->get( 'main_comment_multiple' ) )
  244. {
  245. return $commentSystems[ 'COMPOJOOM' ];
  246. }
  247. }
  248. }
  249. if( $config->get('comment_intensedebate') )
  250. {
  251. require_once( $path . DIRECTORY_SEPARATOR . 'intensedebate.php' );
  252. $commentSystems[ 'INTENSEDEBATE' ] = EasyBlogCommentIntenseDebate::getHTML( $blog );
  253. if( !$config->get( 'main_comment_multiple' ) )
  254. {
  255. return $commentSystems[ 'INTENSEDEBATE' ];
  256. }
  257. }
  258. if( $config->get('comment_disqus') )
  259. {
  260. require_once( $path . DIRECTORY_SEPARATOR . 'disqus.php' );
  261. $commentSystems[ 'DISQUS' ] = EasyBlogCommentDisqus::getHTML( $blog );
  262. if( !$config->get( 'main_comment_multiple' ) )
  263. {
  264. return $commentSystems[ 'DISQUS' ];
  265. }
  266. }
  267. if( $config->get('comment_jomcomment') )
  268. {
  269. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jomcomment' . DIRECTORY_SEPARATOR . 'jomcomment.php';
  270. // Test if jomcomment exists.
  271. if( JFile::exists( $file ) )
  272. {
  273. require_once( $path . DIRECTORY_SEPARATOR . 'jomcomment.php' );
  274. $commentSystems[ 'JOMCOMMENT' ] = EasyBlogCommentJomComment::getHTML( $blog );
  275. if( !$config->get( 'main_comment_multiple' ) )
  276. {
  277. return $commentSystems[ 'JOMCOMMENT' ];
  278. }
  279. }
  280. }
  281. if( $config->get('comment_livefyre') )
  282. {
  283. require_once( $path . DIRECTORY_SEPARATOR . 'livefyre.php' );
  284. $commentSystems[ 'LIVEFYRE' ] = EasyBlogCommentLiveFyre::getHTML( $blog );
  285. if( !$config->get( 'main_comment_multiple' ) )
  286. {
  287. return $commentSystems[ 'LIVEFYRE' ];
  288. }
  289. }
  290. if( $config->get('comment_jcomments' ) )
  291. {
  292. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jcomments' . DIRECTORY_SEPARATOR . 'jcomments.php';
  293. if( JFile::exists( $file ) )
  294. {
  295. require_once( $path . DIRECTORY_SEPARATOR . 'jcomments.php' );
  296. $commentSystems[ 'JCOMMENTS' ] = EasyBlogCommentJComments::getHTML( $blog );
  297. if( !$config->get( 'main_comment_multiple' ) )
  298. {
  299. return $commentSystems[ 'JCOMMENTS' ];
  300. }
  301. }
  302. }
  303. if($config->get('comment_rscomments') )
  304. {
  305. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_rscomments' . DIRECTORY_SEPARATOR . 'rscomments.php';
  306. if( JFile::exists( $file ) )
  307. {
  308. include_once( $path . DIRECTORY_SEPARATOR . 'rscomments.php' );
  309. $commentSystems[ 'RSCOMMENTS' ] = EasyBlogCommentRSComments::getHTML( $blog );
  310. if( !$config->get( 'main_comment_multiple' ) )
  311. {
  312. return $commentSystems[ 'RSCOMMENTS' ];
  313. }
  314. }
  315. }
  316. if( $config->get( 'comment_easydiscuss' ) )
  317. {
  318. $enabled = JPluginHelper::isEnabled( 'content' , 'easydiscuss' );
  319. if( $enabled )
  320. {
  321. JPluginHelper::importPlugin( 'content' , 'easydiscuss' );
  322. $articleParams = new stdClass();
  323. $result = JFactory::getApplication()->triggerEvent( 'onDisplayComments' , array( &$blog , &$articleParams ) );
  324. if( isset( $result[ 0 ] ) )
  325. {
  326. $commentSystems['EASYDISCUSS'] = $result[ 0 ];
  327. if( !$config->get( 'main_comment_multiple') )
  328. {
  329. return $commentSystems[ 'EASYDISCUSS' ];
  330. }
  331. }
  332. }
  333. }
  334. if( $config->get( 'comment_komento' ) )
  335. {
  336. $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'bootstrap.php';
  337. if( JFile::exists( $file ) )
  338. {
  339. include_once( $file );
  340. $commentSystems[ 'KOMENTO' ] = Komento::commentify( 'com_easyblog', $blog, array('trigger'=>'onDisplayComments') );
  341. if( !$config->get( 'main_comment_multiple' ) )
  342. {
  343. return $commentSystems[ 'KOMENTO' ];
  344. }
  345. }
  346. }
  347. if( !$config->get( 'main_comment_multiple') || $config->get( 'comment_easyblog' ) )
  348. {
  349. //check if bbcode enabled or not.
  350. if($config->get('comment_bbcode'))
  351. {
  352. EasyBlogCommentHelper::loadBBCode();
  353. }
  354. // If all else fail, try to use the default comment system
  355. $theme = new CodeThemes();
  356. // setup my own info to show in comment form area
  357. $my = JFactory::getUser();
  358. $profile = EasyBlogHelper::getTable( 'Profile', 'Table' );
  359. $profile->load( $my->id );
  360. $my->avatar = $profile->getAvatar();
  361. $my->displayName = $profile->getName();
  362. $my->url = $profile->url;
  363. $blogURL = base64_encode( EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id , false ) );
  364. $loginURL = EasyBlogHelper::getLoginLink( $blogURL );
  365. $enableRecaptcha = $config->get('comment_recaptcha');
  366. $publicKey = $config->get('comment_recaptcha_public');
  367. // check if the user has subcribed to this thread
  368. $subscriptionId = false;
  369. if ($my->id > 0)
  370. {
  371. $blogModel = EasyblogHelper::getModel('Blog');
  372. $subscriptionId = $blogModel->isBlogSubscribedUser( $blog->id , $my->id , $my->email );
  373. $subscriptionId = is_null($subscriptionId) ? false : $subscriptionId;
  374. }
  375. $theme->set('loginURL' , $loginURL );
  376. $theme->set('blog' , $blog );
  377. $theme->set('my' , $my );
  378. $theme->set('config' , $config );
  379. $theme->set('blogComments' , $comments );
  380. $theme->set('pagination' , $pagination );
  381. $theme->set('allowComment' , true );
  382. $theme->set('canRegister' , $registration );
  383. $theme->set('acl' , EasyBlogACLHelper::getRuleSet() );
  384. $theme->set('subscriptionId' , $subscriptionId);
  385. $commentSystems[ 'EASYBLOGCOMMENTS' ] = $theme->fetch( 'blog.comment.box.php' );
  386. }
  387. if( !$config->get( 'main_comment_multiple' ) )
  388. {
  389. return $commentSystems[ 'EASYBLOGCOMMENTS' ];
  390. }
  391. // If there's 1 system only, there's no point loading the tabs.
  392. if( count( $commentSystems ) == 1 )
  393. {
  394. return $commentSystems[ key( $commentSystems ) ];
  395. }
  396. unset( $theme );
  397. // Reverse the comment systems array so that easyblog comments are always the first item.
  398. $commentSystems = array_reverse( $commentSystems );
  399. $theme = new CodeThemes();
  400. $theme->set( 'commentSystems' , $commentSystems );
  401. return $theme->fetch( 'blog.comment.multiple.php' );
  402. }
  403. public static function loadBBCode()
  404. {
  405. $document = JFactory::getDocument();
  406. $out = '<link rel="stylesheet" type="text/css" href="'.rtrim(JURI::root(), '/').'/components/com_easyblog/classes/markitup/skins/simple/style.css" />' . "\n";
  407. $out .= '<link rel="stylesheet" type="text/css" href="'.rtrim(JURI::root(), '/').'/components/com_easyblog/classes/markitup/sets/bbcode/style.css" />' . "\n";
  408. $out .= '<script type="text/javascript" src="'.rtrim(JURI::root(), '/').'/components/com_easyblog/classes/markitup/jquery.markitup.pack.js"></script>' . "\n";
  409. $bold = JText::_( 'COM_EASYBLOG_BBCODE_BOLD' , true );
  410. $italic = JText::_( 'COM_EASYBLOG_BBCODE_ITALIC' , true );
  411. $underline = JText::_( 'COM_EASYBLOG_BBCODE_UNDERLINE' , true );
  412. $picture = JText::_( 'COM_EASYBLOG_BBCODE_PICTURE' , true );
  413. $bullet = JText::_( 'COM_EASYBLOG_BBCODE_BULLETS' , true );
  414. $numeric = JText::_( 'COM_EASYBLOG_BBCODE_NUMERIC' , true );
  415. $list = JText::_( 'COM_EASYBLOG_BBCODE_LIST' , true );
  416. $quote = JText::_( 'COM_EASYBLOG_BBCODE_QUOTES' , true );
  417. $clean = JText::_( 'COM_EASYBLOG_BBCODE_CLEAN' , true );
  418. $happy = JText::_( 'COM_EASYBLOG_BBCODE_HAPPY' , true );
  419. $smile = JText::_( 'COM_EASYBLOG_BBCODE_SMILE' , true );
  420. $surprised = JText::_( 'COM_EASYBLOG_BBCODE_SURPRISED' , true );
  421. $tongue = JText::_( 'COM_EASYBLOG_BBCODE_TONGUE' , true );
  422. $unhappy = JText::_( 'COM_EASYBLOG_BBCODE_UNHAPPY' , true );
  423. $wink = JText::_( 'COM_EASYBLOG_BBCODE_WINK' , true );
  424. $bbcode =<<<EOF
  425. EasyBlogBBCodeSettings = {
  426. previewParserVar: 'data',
  427. markupSet: [
  428. {name:'$bold', key:'B', openWith:'[b]', closeWith:'[/b]'},
  429. {name:'$italic', key:'I', openWith:'[i]', closeWith:'[/i]'},
  430. {name:'$underline', key:'U', openWith:'[u]', closeWith:'[/u]'},
  431. {separator:'---------------' },
  432. {name:'$picture', key:'P', replaceWith:'[img][![Url]!][/img]'},
  433. {separator:'---------------' },
  434. {name:'$bullet', openWith:'[list]\\n', closeWith:'\\n[/list]'},
  435. {name:'$numeric', openWith:'[list=[![Starting number]!]]\\n', closeWith:'\\n[/list]'},
  436. {name:'$list', openWith:'[*] '},
  437. {separator:'---------------' },
  438. {name:'$quote', openWith:'[quote]', closeWith:'[/quote]'},
  439. {name:'$clean', className:"clean", replaceWith:function(markitup) { return markitup.selection.replace(/\[(.*?)\]/g, "") } },
  440. {separator:'---------------' },
  441. {name:'$happy', openWith:':D'},
  442. {name:'$smile', openWith:':)'},
  443. {name:'$surprised', openWith:':o'},
  444. {name:'$tongue', openWith:':p'},
  445. {name:'$unhappy', openWith:':('},
  446. {name:'$wink', openWith:';)'}
  447. ]
  448. };
  449. EOF;
  450. $out .= '<script type="text/javascript">' . "\n";
  451. $out .= $bbcode;
  452. $out .= 'EasyBlog.ready(function($) {' . "\n";
  453. $out .= ' $("#comment").markItUp(EasyBlogBBCodeSettings);' . "\n";
  454. $out .= '});' . "\n";
  455. $out .= '</script>' . "\n";
  456. $document->addCustomTag($out);
  457. }
  458. public static function parseBBCode($text)
  459. {
  460. //$text = htmlspecialchars($text , ENT_NOQUOTES );
  461. $text = trim($text);
  462. //$text = nl2br( $text );
  463. //$text = preg_replace_callback('/\[code\](.*?)\[\/code\]/ms', "escape", $text);
  464. $text = preg_replace_callback('/\[code( type="(.*?)")?\](.*?)\[\/code\]/ms', 'escape' , $text );
  465. // BBCode to find...
  466. $in = array( '/\[b\](.*?)\[\/b\]/ms',
  467. '/\[i\](.*?)\[\/i\]/ms',
  468. '/\[u\](.*?)\[\/u\]/ms',
  469. '/\[img\](.*?)\[\/img\]/ms',
  470. '/\[email\](.*?)\[\/email\]/ms',
  471. '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms',
  472. '/\[size\="?(.*?)"?\](.*?)\[\/size\]/ms',
  473. '/\[color\="?(.*?)"?\](.*?)\[\/color\]/ms',
  474. '/\[quote](.*?)\[\/quote\]/ms',
  475. '/\[list\=(.*?)\](.*?)\[\/list\]/ms',
  476. '/\[list\](.*?)\[\/list\]/ms',
  477. '/\[\*\]\s?(.*?)\n/ms'
  478. );
  479. // And replace them by...
  480. $out = array( '<strong>\1</strong>',
  481. '<em>\1</em>',
  482. '<u>\1</u>',
  483. '<img src="\1" alt="\1" />',
  484. '<a href="mailto:\1">\1</a>',
  485. '<a href="\1">\2</a>',
  486. '<span style="font-size:\1%">\2</span>',
  487. '<span style="color:\1">\2</span>',
  488. '<blockquote>\1</blockquote>',
  489. '<ol start="\1">\2</ol>',
  490. '<ul>\1</ul>',
  491. '<li>\1</li>'
  492. );
  493. $tmp = preg_replace( $in , '' , $text );
  494. $config = EasyBlogHelper::getConfig();
  495. if( $config->get( 'comment_autohyperlink' ) )
  496. {
  497. $text = EasyBlogCommentHelper::replaceURL( $tmp, $text );
  498. }
  499. $text = preg_replace($in, $out, $text);
  500. // Smileys to find...
  501. $in = array( ':D',
  502. ':)',
  503. ':o',
  504. ':p',
  505. ':(',
  506. ';)'
  507. );
  508. // And replace them by...
  509. $out = array(
  510. '<img alt=":D" src="'.EBLOG_EMOTICONS_DIR.'emoticon-happy.png" />',
  511. '<img alt=":)" src="'.EBLOG_EMOTICONS_DIR.'emoticon-smile.png" />',
  512. '<img alt=":o" src="'.EBLOG_EMOTICONS_DIR.'emoticon-surprised.png" />',
  513. '<img alt=":p" src="'.EBLOG_EMOTICONS_DIR.'emoticon-tongue.png" />',
  514. '<img alt=":(" src="'.EBLOG_EMOTICONS_DIR.'emoticon-unhappy.png" />',
  515. '<img alt=";)" src="'.EBLOG_EMOTICONS_DIR.'emoticon-wink.png" />'
  516. );
  517. $text = str_replace($in, $out, $text);
  518. // paragraphs
  519. $text = str_replace("\r", "", $text);
  520. $text = "<p>".preg_replace("/(\n){2,}/", "</p><p>", $text)."</p>";
  521. $text = preg_replace_callback('/<pre>(.*?)<\/pre>/ms', "removeBr", $text);
  522. $text = preg_replace('/<p><pre>(.*?)<\/pre><\/p>/ms', "<pre>\\1</pre>", $text);
  523. $text = preg_replace_callback('/<ul>(.*?)<\/ul>/ms', "removeBr", $text);
  524. $text = preg_replace('/<p><ul>(.*?)<\/ul><\/p>/ms', "<ul>\\1</ul>", $text);
  525. return $text;
  526. }
  527. public static function replaceURL( $tmp , $text )
  528. {
  529. $pattern = '@(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@';
  530. preg_match_all( $pattern , $tmp , $matches );
  531. if( isset( $matches[ 0 ] ) && is_array( $matches[ 0 ] ) )
  532. {
  533. // to avoid infinite loop, unique the matches
  534. $uniques = array_unique($matches[ 0 ]);
  535. foreach( $uniques as $match )
  536. {
  537. $match = str_ireplace( array( '<br' , '<br />' ) , '' , $match );
  538. $text = str_ireplace( $match , '<a href="' . $match . '">' . $match . '</a>' , $text );
  539. }
  540. }
  541. $text = str_ireplace( '&quot;' , '"', $text );
  542. return $text;
  543. }
  544. }
  545. // clean some tags to remain strict
  546. // not very elegant, but it works. No time to do better ;)
  547. if (!function_exists('removeBr')) {
  548. function removeBr($s) {
  549. return str_replace("<br />", "", $s[0]);
  550. }
  551. }
  552. // BBCode [code]
  553. if (!function_exists('escape')) {
  554. function escape($s) {
  555. global $text;
  556. $text = strip_tags($text);
  557. $code = $s[1];
  558. $code = htmlspecialchars($code);
  559. $code = str_replace("[", "&#91;", $code);
  560. $code = str_replace("]", "&#93;", $code);
  561. return '<pre><code>'.$code.'</code></pre>';
  562. }
  563. }