PageRenderTime 75ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 1ms

/components/com_kunena/class.kunena.php

https://github.com/viollarr/alab
PHP | 1069 lines | 748 code | 193 blank | 128 comment | 151 complexity | c45fc4a456bdbfd28ee60a3d30ed185c MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, AGPL-3.0, Apache-2.0, BSD-3-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * Kunena Component
  5. * @package Kunena
  6. *
  7. * @Copyright (C) 2008 - 2011 Kunena Team. All rights reserved.
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. * @link http://www.kunena.org
  10. *
  11. * Based on FireBoard Component
  12. * @Copyright (C) 2006 - 2007 Best Of Joomla All rights reserved.
  13. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  14. * @link http://www.bestofjoomla.com
  15. */
  16. // Dont allow direct linking
  17. defined( '_JEXEC' ) or die();
  18. jimport('joomla.utilities.string');
  19. // Joomla absolute path
  20. define('KUNENA_JLIVEURL', JURI::root());
  21. require_once (KPATH_SITE . '/lib/kunena.defines.php');
  22. kimport('error');
  23. $kunena_app =& JFactory::getApplication();
  24. $document =& JFactory::getDocument();
  25. $kunena_config = KunenaFactory::getConfig ();
  26. $kunena_db = &JFactory::getDBO();
  27. $kunena_my = &JFactory::getUser();
  28. // Joomla template dir
  29. define('KUNENA_JTEMPLATEPATH', KUNENA_ROOT_PATH . "/templates/{$kunena_app->getTemplate()}");
  30. define('KUNENA_JTEMPLATEURL', KUNENA_JLIVEURL. "templates/{$kunena_app->getTemplate()}");
  31. /* _\|/_
  32. (o o)
  33. +----oOO-{_}-OOo--------------------------------+
  34. | Now we have the components Itemids everywhere |
  35. | Please use these constants where ever needed |
  36. +----------------------------------------------*/
  37. // Kunena live url
  38. define('KUNENA_LIVEURL', KUNENA_JLIVEURL . 'index.php?option=com_kunena');
  39. define('KUNENA_LIVEURLREL', 'index.php?option=com_kunena');
  40. // Kunena souces absolute path
  41. define('KUNENA_DIRECTURL', KUNENA_JLIVEURL . 'components/com_kunena/');
  42. if (!defined("KUNENA_JCSSURL")) {
  43. $current_stylesheet = $kunena_app->getTemplate();
  44. if (KunenaError::checkDatabaseError()) return;
  45. define('KUNENA_JCSSURL', KUNENA_JLIVEURL . 'templates/' . $current_stylesheet . '/css/template_css.css');
  46. }
  47. // Kunena uploaded files directory
  48. define('KUNENA_LIVEUPLOADEDPATH_LEGACY', KUNENA_JLIVEURL . 'images/fbfiles');
  49. define('KUNENA_LIVEUPLOADEDPATH', KUNENA_JLIVEURL . 'media/kunena');
  50. // now continue with other paths
  51. $fb_user_template = JRequest::getString('kunena_template', '', 'COOKIE');
  52. // don't allow directory travelling
  53. $fb_user_template = strtr($fb_user_template, '\\/', '');
  54. if (JString::strlen($fb_user_template) > 0 && file_exists(KUNENA_PATH_TEMPLATE .'/'. $fb_user_template . '/template.xml'))
  55. {
  56. $fb_cur_template = $fb_user_template;
  57. }
  58. else if (file_exists(KUNENA_PATH_TEMPLATE .'/'. $kunena_config->template . '/css'))
  59. {
  60. $fb_cur_template = $kunena_config->template;
  61. }
  62. else
  63. {
  64. $fb_cur_template = 'default';
  65. }
  66. // only for preview module - maybe used later by users to change template
  67. define('KUNENA_RELTMPLTPATH', $fb_cur_template);
  68. define('KUNENA_ABSTMPLTPATH', KUNENA_PATH_TEMPLATE .'/'. $fb_cur_template);
  69. define('KUNENA_ABSTMPLTMAINIMGPATH', KUNENA_PATH_TEMPLATE .'/'. $fb_cur_template);
  70. define('KUNENA_ABSIMAGESPATH', KUNENA_ABSTMPLTMAINIMGPATH . '/images/');
  71. // absolute icons path
  72. define('KUNENA_ABSICONSPATH', KUNENA_ABSIMAGESPATH . 'icons/');
  73. // absolute emoicons path
  74. define('KUNENA_ABSEMOTIONSPATH', KUNENA_ABSIMAGESPATH . 'emoticons/');
  75. // absolute ranks path
  76. define('KUNENA_ABSRANKSPATH', KUNENA_ABSIMAGESPATH . 'ranks/');
  77. // absolute catimages path
  78. define('KUNENA_ABSCATIMAGESPATH', KUNENA_ROOT_PATH.'/media/kunena/'.$kunena_config->catimagepath); // Kunena category images absolute path
  79. define('KUNENA_TMPLTURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/");
  80. define('KUNENA_TMPLTMAINIMGURL', KUNENA_DIRECTURL . "template/{$fb_cur_template}/");
  81. // IMAGES URL PATH
  82. define('KUNENA_TMPLTCSSURL', KUNENA_TMPLTURL . 'css/kunena.forum-min.css');
  83. define('KUNENA_URLIMAGESPATH', KUNENA_TMPLTMAINIMGURL . 'images/');
  84. // url icons path
  85. define('KUNENA_URLICONSPATH', KUNENA_URLIMAGESPATH . 'icons/');
  86. // url emoicons path
  87. define('KUNENA_URLEMOTIONSPATH', KUNENA_URLIMAGESPATH . 'emoticons/');
  88. // url ranks path
  89. define('KUNENA_URLRANKSPATH', KUNENA_URLIMAGESPATH . 'ranks/');
  90. // url catimages path
  91. define('KUNENA_URLCATIMAGES', KUNENA_LIVEUPLOADEDPATH ."/{$kunena_config->catimagepath}/"); // Kunena category images direct url
  92. function kunena_check_image_type($type) {
  93. switch (strtolower($type))
  94. {
  95. case 'jpeg':
  96. case 'pjpeg':
  97. case 'jpg':
  98. return '.jpg';
  99. break;
  100. case 'gif':
  101. return '.gif';
  102. break;
  103. case 'png':
  104. return '.png';
  105. break;
  106. }
  107. return false;
  108. }
  109. kimport('html.parser');
  110. class CKunenaTools {
  111. var $id = null;
  112. function checkDatabaseError() {
  113. kimport('error');
  114. return KunenaError::checkDatabaseError();
  115. }
  116. function showButton($name, $text) {
  117. return '<span class="'.$name.'"><span>'.$text.'</span></span>';
  118. }
  119. function showIcon($name, $title='') {
  120. return '<span class="kicon '.$name.'" title="'.$title.'"></span>';
  121. }
  122. function showModulePosition($position) {
  123. $html = '';
  124. if (JDocumentHTML::countModules ( $position )) {
  125. $document = &JFactory::getDocument ();
  126. $renderer = $document->loadRenderer ( 'modules' );
  127. $options = array ('style' => 'xhtml' );
  128. $html .= '<div class="'.$position.'">';
  129. $html .= $renderer->render ( $position, $options, null );
  130. $html .= '</div>';
  131. }
  132. echo $html;
  133. }
  134. // TODO: deprecated
  135. function parseText($txt) {
  136. user_error(__CLASS__.'::'.__FUNCTION__.'(): Deprecated', E_USER_NOTICE);
  137. kimport('html.parser');
  138. return KunenaParser::parseText($txt);
  139. }
  140. // TODO: deprecated
  141. function parseBBCode($txt) {
  142. user_error(__CLASS__.'::'.__FUNCTION__.'(): Deprecated', E_USER_NOTICE);
  143. kimport('html.parser');
  144. return KunenaParser::parseBBCode($txt);
  145. }
  146. // TODO: deprecated
  147. function stripBBCode($txt, $len=0) {
  148. user_error(__CLASS__.'::'.__FUNCTION__.'(): Deprecated', E_USER_NOTICE);
  149. kimport('html.parser');
  150. return KunenaParser::stripBBCode($txt, $len);
  151. }
  152. function reCountUserPosts() {
  153. $kunena_db = &JFactory::getDBO();
  154. // Reset category counts as next query ignores users which have written no messages
  155. $kunena_db->setQuery("UPDATE #__kunena_users SET posts=0");
  156. $kunena_db->query();
  157. if (KunenaError::checkDatabaseError()) return;
  158. // Update user post count (ignore unpublished categories and hidden messages)
  159. $kunena_db->setQuery("INSERT INTO #__kunena_users (userid, posts)"
  160. ." SELECT m.userid, COUNT(m.userid) "
  161. ." FROM #__kunena_messages AS m"
  162. ." INNER JOIN #__kunena_users AS u ON u.userid = m.userid"
  163. ." WHERE m.hold=0 and m.catid IN (SELECT id FROM #__kunena_categories WHERE published=1)"
  164. ." GROUP BY m.userid"
  165. ." ON DUPLICATE KEY UPDATE posts=VALUES(posts)");
  166. $kunena_db->query();
  167. KunenaError::checkDatabaseError();
  168. }
  169. function reCountBoardsRecursion(&$array, $current)
  170. {
  171. foreach ($array[$current]->children as $child)
  172. {
  173. if (!$array[$child]->published) continue;
  174. if (!empty($array[$child]->children)) CKunenaTools::reCountBoardsRecursion($array, $child);
  175. $array[$current]->numTopics += $array[$child]->numTopics;
  176. $array[$current]->numPosts += $array[$child]->numPosts;
  177. if (isset($array[$current]->id) && $array[$child]->id_last_msg > $array[$current]->id_last_msg)
  178. {
  179. $array[$current]->id_last_msg = $array[$child]->id_last_msg;
  180. $array[$current]->time_last_msg = $array[$child]->time_last_msg;
  181. }
  182. }
  183. }
  184. function reCountBoards()
  185. {
  186. $kunena_db = &JFactory::getDBO();
  187. // Reset category counts as next query ignores empty categories
  188. $kunena_db->setQuery("UPDATE #__kunena_categories SET numTopics=0, numPosts=0");
  189. $kunena_db->query();
  190. if (KunenaError::checkDatabaseError()) return;
  191. // Update category post count
  192. $kunena_db->setQuery("INSERT INTO #__kunena_categories (id, numTopics, numPosts, id_last_msg, time_last_msg)"
  193. ." SELECT c.id, SUM( m.parent=0 ), SUM( m.parent>0 ), MAX( m.id ), MAX( m.time )"
  194. ." FROM #__kunena_messages as m"
  195. ." INNER JOIN #__kunena_categories AS c ON c.id=m.catid"
  196. ." WHERE m.catid>0 AND m.hold=0"
  197. ." GROUP BY catid "
  198. ." ON DUPLICATE KEY UPDATE numTopics=VALUES(numTopics), numPosts=VALUES(numPosts), id_last_msg=VALUES(id_last_msg), time_last_msg=VALUES(time_last_msg)");
  199. $kunena_db->query();
  200. if (KunenaError::checkDatabaseError()) return;
  201. // Load categories to be counted
  202. $kunena_db->setQuery("SELECT id, parent, published, numTopics, numPosts, id_last_msg, time_last_msg FROM #__kunena_categories");
  203. $cats = $kunena_db->loadObjectList('id');
  204. if (KunenaError::checkDatabaseError()) return;
  205. foreach ($cats as $c)
  206. {
  207. if (isset($cats[$c->parent])) $cats[$c->parent]->children[] = $c->id;
  208. else $cats[0]->children[] = $c->id;
  209. }
  210. if (!empty($cats)) CKunenaTools::reCountBoardsRecursion($cats, 0);
  211. // now back to db
  212. foreach ($cats as $c)
  213. {
  214. if (!isset($c->id)) continue;
  215. $kunena_db->setQuery("UPDATE #__kunena_categories SET"
  216. ." numTopics=" . intval($c->numTopics)
  217. .", numPosts=" . intval($c->numPosts)
  218. .", id_last_msg=" . intval($c->id_last_msg)
  219. .", time_last_msg=" . intval($c->time_last_msg)
  220. ." WHERE id=" . intval($c->id));
  221. $kunena_db->query();
  222. if (KunenaError::checkDatabaseError()) return;
  223. }
  224. }
  225. function updateNameInfo()
  226. {
  227. $kunena_db = &JFactory::getDBO();
  228. $kunena_config = KunenaFactory::getConfig ();
  229. $fb_queryName = $kunena_config->username ? "username" : "name";
  230. $query = "UPDATE #__kunena_messages AS m, #__users AS u
  231. SET m.name = u.$fb_queryName
  232. WHERE m.userid = u.id";
  233. $kunena_db->setQuery($query);
  234. $kunena_db->query();
  235. KunenaError::checkDatabaseError();
  236. return $kunena_db->getAffectedRows();
  237. }
  238. function modifyCategoryStats($msg_id, $msg_parent, $msg_time, $msg_cat) {
  239. $kunena_db = &JFactory::getDBO();
  240. $kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__kunena_categories ORDER BY id ASC");
  241. $cats = $kunena_db->loadObjectList();
  242. if (KunenaError::checkDatabaseError()) return;
  243. foreach ($cats as $c) {
  244. $ctg[$c->id] = $c;
  245. }
  246. while ($msg_cat) {
  247. // traverse parental from orig msg_cat
  248. if ($msg_parent == 0) {
  249. $ctg[$msg_cat]->numTopics++;
  250. }
  251. else {
  252. $ctg[$msg_cat]->numPosts++;
  253. }
  254. $ctg[$msg_cat]->id_last_msg = $msg_id;
  255. $ctg[$msg_cat]->time_last_msg = $msg_time;
  256. // store to db (only changed)
  257. $kunena_db->setQuery(
  258. "UPDATE `#__kunena_categories`"
  259. ." SET `time_last_msg`='" . $ctg[$msg_cat]->time_last_msg . "'"
  260. .",`id_last_msg`='" . $ctg[$msg_cat]->id_last_msg . "'"
  261. .",`numTopics`='" . $ctg[$msg_cat]->numTopics . "'"
  262. .",`numPosts`='" . $ctg[$msg_cat]->numPosts . "'"
  263. ." WHERE (`id`='" . $ctg[$msg_cat]->id . "') ");
  264. $kunena_db->query();
  265. if (KunenaError::checkDatabaseError()) return;
  266. // parent
  267. $msg_cat = $ctg[$msg_cat]->parent;
  268. }
  269. }
  270. // FIXME: broken function, bad implementation
  271. function decreaseCategoryStats($msg_id, $msg_cat) {
  272. //topic : 1 , message = 0
  273. $kunena_db = &JFactory::getDBO();
  274. $kunena_db->setQuery("SELECT id, parent, numTopics, numPosts, id_last_msg, time_last_msg FROM #__kunena_categories ORDER BY id ASC");
  275. $cats = $kunena_db->loadObjectList();
  276. if (KunenaError::checkDatabaseError()) return;
  277. foreach ($cats as $c) {
  278. $ctg[$c->id] = $c;
  279. }
  280. $kunena_db->setQuery("SELECT id FROM #__kunena_messages WHERE id={$kunena_db->Quote($msg_id)} OR thread={$kunena_db->Quote($msg_id)}");
  281. $msg_ids = $kunena_db->loadResultArray();
  282. if (KunenaError::checkDatabaseError()) return;
  283. $cntTopics = 0;
  284. $cntPosts = 0;
  285. if (count($msg_ids) > 0) {
  286. foreach ($msg_ids as $msg) {
  287. if ($msg == $msg_id) {
  288. $cntTopics = 1;
  289. }
  290. else {
  291. $cntPosts++;
  292. }
  293. }
  294. }
  295. while ($msg_cat)
  296. {
  297. $kunena_db->setQuery("SELECT id, time FROM #__kunena_messages WHERE catid={$kunena_db->Quote($msg_cat)} AND (thread!={$kunena_db->Quote($msg_id)} AND id!={$kunena_db->Quote($msg_id)}) ORDER BY time DESC LIMIT 1;");
  298. $lastMsgInCat = $kunena_db->loadObject();
  299. if (KunenaError::checkDatabaseError()) return;
  300. $ctg[$msg_cat]->numTopics = (int) ($ctg[$msg_cat]->numTopics - $cntTopics);
  301. $ctg[$msg_cat]->numPosts = (int) ($ctg[$msg_cat]->numPosts - $cntPosts);
  302. $ctg[$msg_cat]->id_last_msg = $lastMsgInCat->id;
  303. $ctg[$msg_cat]->time_last_msg = $lastMsgInCat->time;
  304. $msg_cat = $ctg[$msg_cat]->parent;
  305. }
  306. // now back to db
  307. foreach ($ctg as $cc)
  308. {
  309. $kunena_db->setQuery("UPDATE `#__kunena_categories` SET `time_last_msg`='" . $cc->time_last_msg . "',`id_last_msg`='" . $cc->id_last_msg . "',`numTopics`='" . $cc->numTopics . "',`numPosts`='" . $cc->numPosts . "' WHERE `id`='" . $cc->id . "' ");
  310. $kunena_db->query();
  311. if (KunenaError::checkDatabaseError()) return;
  312. }
  313. return;
  314. }
  315. function markTopicRead($thread, $userid) {
  316. $thread = intval ( $thread );
  317. $userid = intval ( $userid );
  318. if (! $userid || ! $thread)
  319. return;
  320. $kunena_db = &JFactory::getDBO ();
  321. $kunena_session = KunenaFactory::getSession ();
  322. $readTopics = explode ( ',', $kunena_session->readtopics );
  323. if (! in_array ( $thread, $readTopics )) {
  324. $readTopics[] = $thread;
  325. $readTopics = implode ( ',', $readTopics );
  326. } else {
  327. $readTopics = false; // do not update session
  328. }
  329. if ($readTopics) {
  330. $kunena_db->setQuery ( "UPDATE #__kunena_sessions SET readtopics={$kunena_db->Quote($readTopics)} WHERE userid={$kunena_db->Quote($userid)}" );
  331. $kunena_db->query ();
  332. KunenaError::checkDatabaseError();
  333. }
  334. }
  335. function forumSelectList($name, $catid=0, $options=array(), $attr='', $sections=false) {
  336. $kunena_db = &JFactory::getDBO ();
  337. $list = JJ_categoryArray ();
  338. foreach ( $list as $item ) {
  339. $options [] = JHTML::_ ( 'select.option', $item->id, $item->treename, 'value', 'text', !$sections && $item->section);
  340. }
  341. if (is_array($catid)) $catids = 'catids[]';
  342. else $catids = 'catid';
  343. $parent = JHTML::_ ( 'select.genericlist', $options, $catids, $attr, 'value', 'text', $catid, $name );
  344. return $parent;
  345. }
  346. function KSelectList($name, $options=array(), $attr='', $sections=false, $id='', $selected=0) {
  347. $kunena_db = &JFactory::getDBO ();
  348. $list = JJ_categoryArray ();
  349. $preoptions = count($options);
  350. foreach ( $list as $item ) {
  351. if (!$preoptions && !$selected && ($sections || !$item->section)) {
  352. $selected = $item->id;
  353. }
  354. $options [] = JHTML::_ ( 'select.option', $item->id, $item->treename, 'value', 'text', !$sections && $item->section);
  355. }
  356. if (!$id) $id = $name;
  357. $catsList = JHTML::_ ( 'select.genericlist', $options, $name, $attr, 'value', 'text', $selected, $id );
  358. return $catsList;
  359. }
  360. function showBulkActionCats($disabled = 1) {
  361. $kunena_db = &JFactory::getDBO();
  362. $options = array ();
  363. $options[] = JHTML::_('select.option', '0', JText::_('COM_KUNENA_BULK_CHOOSE_DESTINATION'));
  364. $attr = 'class="inputbox fbs" size="1"' . ($disabled ? ' disabled="disabled" ' : "");
  365. $lists['parent'] = CKunenaTools::forumSelectList('bulkactions', 0, $options, $attr);
  366. echo $lists['parent'];
  367. }
  368. // TODO: deprecated
  369. function getTemplateImage($image) {
  370. $template = KunenaFactory::getTemplate ();
  371. return 'components/com_kunena/' . $template->getImagePath($image, false);
  372. }
  373. // TODO: deprecated
  374. function topicIcon($topic) {
  375. $template = KunenaFactory::getTemplate ();
  376. return $template->getTopicIcon($topic);
  377. }
  378. function isAdmin($uid = null) {
  379. $acl = KunenaFactory::getAccessControl();
  380. return $acl->isAdmin($uid);
  381. }
  382. function isModerator($uid=null, $catid=0) {
  383. $acl = KunenaFactory::getAccessControl();
  384. return $acl->isModerator($uid, $catid);
  385. }
  386. function getEMailToList($catid, $thread, $subscriptions = false, $moderators = false, $admins = false, $excludeList = null) {
  387. $acl = KunenaFactory::getAccessControl();
  388. return $acl->getSubscribers($catid, $thread, $subscriptions, $moderators, $admins, $excludeList);
  389. }
  390. function getAllowedForums($uid) {
  391. $acl = KunenaFactory::getAccessControl();
  392. return $acl->getAllowedCategories($uid);
  393. }
  394. function KDeletePosts() {
  395. $kunena_app = JFactory::getApplication ();
  396. $backUrl = $kunena_app->getUserState ( "com_kunena.ActionBulk" );
  397. if (!JRequest::checkToken()) {
  398. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  399. while (@ob_end_clean());
  400. $kunena_app->redirect ( $backUrl );
  401. }
  402. require_once (KUNENA_PATH_LIB . '/kunena.moderation.class.php');
  403. $kunena_mod = CKunenaModeration::getInstance ();
  404. $items = KGetArrayInts ( "cb" );
  405. // start iterating here
  406. $message = '';
  407. foreach ( $items as $id => $value ) {
  408. $delete = $kunena_mod->deleteThread ( $id, $DeleteAttachments = false );
  409. if (! $delete) {
  410. $kunena_app->enqueueMessage ( $kunena_mod->getErrorMessage (), 'notice' );
  411. } else {
  412. $message = JText::_ ( 'COM_KUNENA_BULKMSG_DELETED' );
  413. }
  414. } //end foreach
  415. while (@ob_end_clean());
  416. $kunena_app->redirect ( $backUrl, $message );
  417. }
  418. function KMovePosts($catid) {
  419. $catid = ( int ) $catid;
  420. $kunena_app = JFactory::getApplication ();
  421. $backUrl = $kunena_app->getUserState ( "com_kunena.ActionBulk" );
  422. if (!JRequest::checkToken()) {
  423. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  424. while (@ob_end_clean());
  425. $kunena_app->redirect ( $backUrl );
  426. }
  427. require_once (KUNENA_PATH_LIB . '/kunena.moderation.class.php');
  428. $kunena_mod = CKunenaModeration::getInstance ();
  429. $items = KGetArrayInts ( "cb" );
  430. $message = '';
  431. // start iterating here
  432. foreach ( $items as $id => $value ) {
  433. $move = $kunena_mod->moveThread ( $id, $catid, $DeleteAttachments = false );
  434. if (! $move) {
  435. $kunena_app->enqueueMessage ( $kunena_mod->getErrorMessage (), 'notice' );
  436. } else {
  437. $message = JText::_ ( 'COM_KUNENA_POST_SUCCESS_MOVE' );
  438. }
  439. } //end foreach
  440. while (@ob_end_clean());
  441. $kunena_app->redirect ( $backUrl, $message );
  442. }
  443. function KDeletePerm() {
  444. $kunena_app = JFactory::getApplication ();
  445. $kunena_db = JFactory::getDBO ();
  446. $backUrl = $kunena_app->getUserState ( "com_kunena.ActionBulk" );
  447. if (!JRequest::checkToken()) {
  448. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  449. while (@ob_end_clean());
  450. $kunena_app->redirect ( $backUrl );
  451. }
  452. require_once (KUNENA_PATH_LIB . '/kunena.moderation.class.php');
  453. $kunena_mod = CKunenaModeration::getInstance ();
  454. $items = KGetArrayInts ( "cb" );
  455. // start iterating here
  456. foreach ( $items as $id => $value ) {
  457. $query = "SELECT `hold` FROM #__kunena_messages WHERE `thread`={$kunena_db->quote($id)};";
  458. $kunena_db->setQuery ( $query );
  459. $messagesHold = $kunena_db->loadObjectList ();
  460. KunenaError::checkDatabaseError();
  461. foreach ( $messagesHold as $messageHold ) {
  462. $delete = $kunena_mod->deleteThreadPerminantly ( $id, true );
  463. if (! $delete) {
  464. $kunena_app->enqueueMessage ( $kunena_mod->getErrorMessage (), 'notice' );
  465. } else {
  466. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_BULKMSG_DELETED' ) );
  467. }
  468. }
  469. } //end foreach
  470. while (@ob_end_clean());
  471. $kunena_app->redirect ( $backUrl );
  472. }
  473. function KUndelete() {
  474. $kunena_app = JFactory::getApplication ();
  475. $kunena_db = JFactory::getDBO ();
  476. $backUrl = $kunena_app->getUserState ( "com_kunena.ActionBulk" );
  477. if (!JRequest::checkToken()) {
  478. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_ERROR_TOKEN' ), 'error' );
  479. while (@ob_end_clean());
  480. $kunena_app->redirect ( $backUrl );
  481. }
  482. require_once (KUNENA_PATH_LIB . '/kunena.moderation.class.php');
  483. $kunena_mod = CKunenaModeration::getInstance ();
  484. $items = KGetArrayInts ( "cb" );
  485. // start iterating here
  486. foreach ( $items as $id => $value ) {
  487. // Need to get hold value to check if the message is right deleted
  488. $query = "SELECT MAX(IF(`hold`=2 OR `hold`=3, 1, 0)) FROM #__kunena_messages WHERE `thread`={$kunena_db->quote($id)} GROUP BY `thread`;";
  489. $kunena_db->setQuery ( $query );
  490. $messageHold = $kunena_db->loadResult ();
  491. KunenaError::checkDatabaseError();
  492. if ($messageHold) {
  493. $delete = $kunena_mod->UndeleteThread ( $id, true );
  494. if (! $delete) {
  495. $kunena_app->enqueueMessage ( $kunena_mod->getErrorMessage (), 'notice' );
  496. } else {
  497. $kunena_app->enqueueMessage ( JText::_ ( 'COM_KUNENA_POST_SUCCESS_UNDELETE' ) );
  498. }
  499. // Last but not least update forum stats
  500. CKunenaTools::reCountBoards();
  501. // Activity integration
  502. $activity = KunenaFactory::getActivityIntegration();
  503. $activity->onAfterUndelete($this);
  504. }
  505. } //end foreach
  506. while (@ob_end_clean());
  507. $kunena_app->redirect ( $backUrl );
  508. }
  509. /**
  510. * This function formats a number to n significant digits when above
  511. * 10,000. Starting at 10,0000 the out put changes to 10k, starting
  512. * at 1,000,000 the output switches to 1m. Both k and m are defined
  513. * in the language file. The significant digits are used to limit the
  514. * number of digits displayed when in 10k or 1m mode.
  515. *
  516. * @param int $number Number to be formated
  517. * @param int $precision Significant digits for output
  518. */
  519. function formatLargeNumber($number, $precision = 4) {
  520. $output = '';
  521. // Do we need to reduce the number of significant digits?
  522. if ($number >= 10000){
  523. // Round the number to n significant digits
  524. $number = round ($number, -1*(log10($number)+1) + $precision);
  525. }
  526. if ($number < 10000) {
  527. $output = $number;
  528. } elseif ($number >= 1000000) {
  529. $output = $number / 1000000 . JText::_('COM_KUNENA_MILLION');
  530. } else {
  531. $output = $number / 1000 . JText::_('COM_KUNENA_THOUSAND');
  532. }
  533. return $output;
  534. }
  535. /**
  536. * This function shortens long filenames for display purposes.
  537. * The first 8 characters of the filename, followed by three dots
  538. * and the last 5 character of the filename.
  539. *
  540. * @param char $filename Filename to be shortened if too long
  541. */
  542. function shortenFileName($filename, $front=10, $back=8, $filler='...') {
  543. $len = strlen($filename);
  544. if ($len>($front+strlen($filler)+$back)){
  545. $output=substr($filename,0,$front).$filler.substr($filename,$len-$back,$back);
  546. }else{
  547. $output=$filename;
  548. }
  549. return $output;
  550. }
  551. function displayMenu() {
  552. jimport ( 'joomla.application.module.helper' );
  553. $position = "kunena_menu";
  554. $options = array ('style' => 'xhtml' );
  555. $modules = JModuleHelper::getModules ( $position );
  556. foreach ( $modules as $module ) {
  557. if ($module->module == 'mod_mainmenu' || $module->module == 'mod_menu') {
  558. $app = JFactory::getApplication();
  559. $menu = JSite::getMenu ();
  560. $active = $menu->getActive();
  561. $basemenu = KunenaRoute::getCurrentMenu ();
  562. if ($basemenu) {
  563. $module = clone $module;
  564. if (version_compare(JVERSION, '1.6','>')) {
  565. // Joomla 1.6+
  566. $search = array ('/"menutype":"([^"]*)"/i', '/"startLevel":"([^"]*)"/', '/"endLevel":"([^"]*)"/' );
  567. $replace = array ("\"menutype\":\"{$basemenu->menutype}\"", '"startLevel":"' . ($basemenu->level + 1) . '"', '"endLevel":"' . ($basemenu->level + 2) . '"' );
  568. } else {
  569. // Joomla 1.5
  570. $search = array ('/menutype=(.*)(\s)/', '/startLevel=(.*)(\s)/', '/endLevel=(.*)(\s)/' );
  571. $replace = array ("menutype={$basemenu->menutype}\\2", 'startLevel=' . ($basemenu->sublevel + 1) . '\2', 'endLevel=' . ($basemenu->sublevel + 2) . '\2' );
  572. }
  573. $module->params = preg_replace ( $search, $replace, $module->params );
  574. } else {
  575. if ($active)
  576. KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_NOMENU_ITEMID', $active->route, $active->id), 'nomenu');
  577. else
  578. KunenaError::warning(JText::sprintf('COM_KUNENA_WARNING_NOMENU_COMPONENT'), 'nomenu');
  579. }
  580. }
  581. echo JModuleHelper::renderModule ( $module, $options );
  582. }
  583. }
  584. function displayLoginBox() {
  585. require_once (KUNENA_PATH_LIB . '/kunena.login.php');
  586. $type = CKunenaLogin::getType ();
  587. if ($type == 'login') {
  588. CKunenaTools::loadTemplate('/loginbox/login.php');
  589. } else {
  590. CKunenaTools::loadTemplate('/loginbox/logout.php');
  591. }
  592. }
  593. /**
  594. * This function loads the appropriate template file
  595. * It checks if the selected template contains an override
  596. * and if so loads it. Fall back is the default template
  597. * implementation
  598. *
  599. * @param string $relpath Relative path to template file
  600. * @param bool $once limit to single include default false
  601. * @param string $template Custom path to template (relative to Joomla)
  602. */
  603. function loadTemplate($relpath, $once=false, $template=null) {
  604. if ($once){
  605. if ($template && file_exists ( JPATH_ROOT.$template.$relpath )) {
  606. require_once (JPATH_ROOT.$template.$relpath);
  607. } else if (file_exists ( KUNENA_ABSTMPLTPATH.$relpath )) {
  608. require_once (KUNENA_ABSTMPLTPATH.$relpath);
  609. } else {
  610. require_once (KUNENA_PATH_TEMPLATE_DEFAULT.$relpath);
  611. }
  612. } else {
  613. if ($template && file_exists ( JPATH_ROOT.$template.$relpath )) {
  614. require (JPATH_ROOT.$template.$relpath);
  615. } else if (file_exists ( KUNENA_ABSTMPLTPATH.$relpath )) {
  616. require (KUNENA_ABSTMPLTPATH.$relpath);
  617. } else {
  618. require (KUNENA_PATH_TEMPLATE_DEFAULT.$relpath);
  619. }
  620. }
  621. }
  622. /**
  623. * This function check the edit time for the author of the author
  624. * of the post and return if the user is allwoed or not to edit
  625. * her post
  626. *
  627. * @param timestamp $messagemodifiedtime Time when the message has been edited
  628. * @param timestamp $messagetime Actual message time
  629. */
  630. function editTimeCheck ($messagemodifiedtime, $messagetime) {
  631. $kunena_config = KunenaFactory::getConfig ();
  632. if (intval($kunena_config->useredit) != 1) return false;
  633. if (intval($kunena_config->useredittime) == 0) {
  634. return true;
  635. } else {
  636. //Check whether edit is in time
  637. $modtime = $messagemodifiedtime;
  638. if (! $modtime) {
  639. $modtime = $messagetime;
  640. }
  641. if ($modtime + intval($kunena_config->useredittime) >= CKunenaTimeformat::internalTime ()) {
  642. return true;
  643. }
  644. }
  645. }
  646. /**
  647. * This function load datas for rules or help page
  648. *
  649. */
  650. function getRulesHelpDatas($id) {
  651. $kunena_db = &JFactory::getDBO ();
  652. $kunena_db->setQuery ( "SELECT introtext, id FROM #__content WHERE id={$kunena_db->Quote($id)}" );
  653. $introtext = $kunena_db->loadResult ();
  654. KunenaError::checkDatabaseError();
  655. return $introtext;
  656. }
  657. /**
  658. * Wrapper to addStyleSheet
  659. *
  660. */
  661. function addStyleSheet($filename, $rtl=false) {
  662. $document = & JFactory::getDocument ();
  663. $kunena_config = KunenaFactory::getConfig ();
  664. if ($kunena_config->debug || Kunena::isSvn()) {
  665. // If we are in debug more, make sure we load the unpacked css
  666. $filename = preg_replace ( '/\-min\./u', '.', $filename );
  667. }
  668. $result = $document->addStyleSheet ( $filename );
  669. if ($rtl) {
  670. $filename = preg_replace ( '/((-min)?\.css)$/u', '.rtl\\1', $filename );
  671. $result = $document->addStyleSheet ( $filename );
  672. }
  673. return $result;
  674. }
  675. /**
  676. * Wrapper to addScript
  677. *
  678. */
  679. function addScript($filename) {
  680. $document = & JFactory::getDocument ();
  681. $kunena_config = KunenaFactory::getConfig ();
  682. if ($kunena_config->debug || Kunena::isSvn()) {
  683. // If we are in debug more, make sure we load the unpacked css
  684. $filename = preg_replace ( '/\-min\./u', '.', $filename );
  685. }
  686. return $document->addScript ( $filename );
  687. }
  688. } // end of class
  689. function JJ_categoryArray($admin=0) {
  690. $kunena_db = &JFactory::getDBO();
  691. $app = JFactory::getApplication();
  692. $kunena_my = JFactory::getUser();
  693. $func = JString::strtolower ( JRequest::getCmd ( 'func', JRequest::getCmd ( 'view', '' )) );
  694. // get a list of the menu items
  695. $query = "SELECT * FROM #__kunena_categories";
  696. if($app->isSite()) {
  697. $kunena_session =& KunenaFactory::getSession();
  698. if ($kunena_session && $kunena_session->allowed != 'na') {
  699. $query .= " WHERE id IN ($kunena_session->allowed) AND published='1' ";
  700. } else {
  701. $query .= " WHERE pub_access='0' AND published='1' ";
  702. }
  703. }
  704. $query .= " ORDER BY ordering, name";
  705. $kunena_db->setQuery($query);
  706. $items = $kunena_db->loadObjectList();
  707. KunenaError::checkDatabaseError();
  708. // establish the hierarchy of the menu
  709. $children = array ();
  710. // first pass - collect children
  711. foreach ($items as $v) {
  712. $pt = $v->parent;
  713. $list = isset($children[$pt]) ? $children[$pt] : array ();
  714. array_push($list, $v);
  715. $children[$pt] = $list;
  716. }
  717. // second pass - get an indent list of the items
  718. $array = fbTreeRecurse(0, '', array (), $children, 10, 0, 1);
  719. return $array;
  720. }
  721. function fbTreeRecurse( $id, $indent, $list, &$children, $maxlevel=9999, $level=0, $type=1 ) {
  722. if (isset($children[$id]) && $level <= $maxlevel) {
  723. foreach ($children[$id] as $v) {
  724. $id = $v->id;
  725. if (KUNENA_JOOMLA_COMPAT >= '1.6') {
  726. $pre = '- ';
  727. $spacer = '- ';
  728. } elseif ( $type ) {
  729. $pre = '&nbsp;';
  730. $spacer = '...';
  731. } else {
  732. $pre = '- ';
  733. $spacer = '&nbsp;&nbsp;';
  734. }
  735. if ( $v->parent == 0 ) {
  736. $txt = kunena_htmlspecialchars($v->name);
  737. } else {
  738. $txt = $pre . kunena_htmlspecialchars($v->name);
  739. }
  740. $pt = $v->parent;
  741. $list[$id] = $v;
  742. $list[$id]->treename = $indent . $txt;
  743. $list[$id]->children = !empty($children[$id]) ? count( $children[$id] ) : 0;
  744. $list[$id]->section = ($v->parent==0);
  745. $list = fbTreeRecurse( $id, $indent . $spacer, $list, $children, $maxlevel, $level+1, $type );
  746. }
  747. }
  748. return $list;
  749. }
  750. //
  751. //Begin Smilies mod
  752. //
  753. function generate_smilies() {
  754. $kunena_db = &JFactory::getDBO();
  755. $kunena_emoticons_rowset = array ();
  756. $inline_columns = 4;
  757. $inline_rows = 5;
  758. $kunena_db->setQuery("SELECT code, location, emoticonbar FROM #__kunena_smileys ORDER BY id");
  759. $set = $kunena_db->loadAssocList();
  760. KunenaError::checkDatabaseError();
  761. $num_smilies = 0;
  762. $num_iconbar = 0;
  763. foreach ($set as $smilies) {
  764. $key_exists = false;
  765. foreach ($kunena_emoticons_rowset as $check) //checks if the smiley (location) already exists with another code
  766. {
  767. if ($check['location'] == $smilies['location']) {
  768. $key_exists = true;
  769. }
  770. }
  771. if ($key_exists == false) {
  772. $kunena_emoticons_rowset[] = array
  773. (
  774. 'code' => $smilies['code'],
  775. 'location' => $smilies['location'],
  776. 'emoticonbar' => $smilies['emoticonbar']
  777. );
  778. }
  779. if ($smilies['emoticonbar'] == 1) {
  780. $num_iconbar++;
  781. }
  782. }
  783. $num_smilies = count($kunena_emoticons_rowset);
  784. if ($num_smilies) {
  785. $smilies_count = min(20, $num_smilies);
  786. $smilies_split_row = $inline_columns - 1;
  787. $s_colspan = 0;
  788. $row = 0;
  789. $col = 0;
  790. reset ($kunena_emoticons_rowset);
  791. $cur = 0;
  792. foreach ($kunena_emoticons_rowset as $data) {
  793. if ($data['emoticonbar'] == 1) {
  794. $cur++;
  795. if (!($cur > $inline_rows * $inline_columns)) {
  796. if (!$col) {
  797. echo '<tr align="center" valign="middle">' . "\n";
  798. }
  799. echo '<td onclick="bbfontstyle(\' '
  800. . $data['code'] . ' \',\'\')" style="cursor:pointer"><img class="btnImage" src="' . KUNENA_URLEMOTIONSPATH . $data['location'] . '" border="0" alt="' . $data['code'] . ' " title="' . $data['code'] . ' " /></td>' . "\n";
  801. $s_colspan = max($s_colspan, $col + 1);
  802. if ($col == $smilies_split_row) {
  803. $col = 0;
  804. $row++;
  805. echo "</tr>\n";
  806. }
  807. elseif ($cur == $num_iconbar && $s_colspan !== 0) {
  808. echo "<td colspan=\"" . $s_colspan . "\"></td></tr>";
  809. }
  810. else {
  811. $col++;
  812. }
  813. }
  814. }
  815. }
  816. if ($num_smilies > $inline_rows * $inline_columns) {
  817. echo "<tr><td class=\"moresmilies\" colspan=\"" . $inline_columns . "\" onclick=\"javascript:dE('smilie');\" style=\"cursor:pointer\"><b>" . JText::_('COM_KUNENA_EMOTICONS_MORE_SMILIES') . "</b></td></tr>";
  818. }
  819. }
  820. return $kunena_emoticons_rowset;
  821. }
  822. function KGetArrayInts($name) {
  823. $array = JRequest::getVar($name, array ( 0 ), 'post', 'array');
  824. $items = array();
  825. foreach ($array as $item=>$value) {
  826. if ((int)$item && (int)$item>0) $items[(int)$item] = 1;
  827. }
  828. $array = $items;
  829. if (!is_array($array)) {
  830. $array = array ( 0 );
  831. }
  832. return $array;
  833. }
  834. function KGetArrayReverseInts($name) {
  835. $array = JRequest::getVar($name, array ( 0 ), 'post', 'array');
  836. $items = array();
  837. foreach ($array as $item=>$value) {
  838. if ((int)$item && (int)$item>0) $items[(int)$item] = (int)$item;
  839. }
  840. $array = $items;
  841. if (!is_array($array)) {
  842. $array = array ( 0 );
  843. }
  844. return $array;
  845. }
  846. function kunena_htmlspecialchars($string, $quote_style=ENT_COMPAT, $charset='UTF-8') {
  847. return htmlspecialchars($string, $quote_style, $charset);
  848. }
  849. // TODO: deprecated
  850. function html_entity_decode_utf8($string)
  851. {
  852. static $trans_tbl = NULL;
  853. user_error(__FUNCTION__.'(): Deprecated', E_USER_NOTICE);
  854. // replace numeric entities
  855. $string = preg_replace('~&#x([0-9a-f]+);~ei', 'code2utf(hexdec("\\1"))', $string);
  856. $string = preg_replace('~&#([0-9]+);~e', 'code2utf(\\1)', $string);
  857. // replace literal entities
  858. if (!isset($trans_tbl))
  859. {
  860. $trans_tbl = array();
  861. foreach (get_html_translation_table(HTML_ENTITIES) as $val=>$key)
  862. $trans_tbl[$key] = utf8_encode($val);
  863. }
  864. return strtr($string, $trans_tbl);
  865. }
  866. // Returns the utf string corresponding to the unicode value (from php.net, courtesy - romans@void.lv)
  867. // TODO: deprecated
  868. function code2utf($num)
  869. {
  870. if ($num < 128) return chr($num);
  871. if ($num < 2048) return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
  872. if ($num < 65536) return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
  873. if ($num < 2097152) return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
  874. return '';
  875. }
  876. ?>