PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/components/com_easyblog/helpers/router.php

https://bitbucket.org/pastor399/newcastleunifc
PHP | 1336 lines | 1019 code | 248 blank | 69 comment | 136 complexity | a97fdd7af8d2f9208d141ff30933cd86 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. jimport( 'joomla.filter.filteroutput');
  15. jimport( 'joomla.application.router');
  16. require_once( JPATH_ROOT. DIRECTORY_SEPARATOR .'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'constants.php' );
  17. require_once( EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'helper.php' );
  18. //include table path to make sure it gets the right table.
  19. JTable::addIncludePath( JPATH_ROOT . DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'tables' );
  20. class EasyBlogRouter extends JRouter
  21. {
  22. public static function generatePermalink( $string )
  23. {
  24. $config = EasyBlogHelper::getConfig();
  25. $permalink = '';
  26. if( $config->get( 'main_sef_unicode' ) )
  27. {
  28. //unicode support.
  29. $permalink = EasyBlogRouter::permalinkUnicodeSlug($string);
  30. }
  31. else
  32. {
  33. // Replace accents to get accurate string
  34. $string = EasyBlogRouter::replaceAccents( $string );
  35. // no unicode supported.
  36. $permalink = JFilterOutput::stringURLSafe( $string );
  37. // check if anything return or not. If not, then we give a date as the alias.
  38. if(trim(str_replace('-','',$permalink)) == '')
  39. {
  40. $datenow = EasyBlogHelper::getDate();
  41. $permalink = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
  42. }
  43. }
  44. return $permalink;
  45. }
  46. public static function getLanguageQuery()
  47. {
  48. if( EasyBlogHelper::getJoomlaVersion() < '1.6' )
  49. {
  50. return '';
  51. }
  52. $lang = JFactory::getLanguage()->getTag();
  53. $langQuery = '';
  54. if( !empty( $lang ) && $lang != '*' )
  55. {
  56. $db = EasyBlogHelper::db();
  57. $langQuery = ' AND (' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'language' ) . '=' . $db->Quote( $lang ) . ' OR `language` = '.$db->Quote('*').' )';
  58. }
  59. return $langQuery;
  60. }
  61. public static function permalinkUnicodeSlug( $string )
  62. {
  63. $str = '';
  64. if( EasyBlogHelper::getJoomlaVersion() >= '1.6')
  65. {
  66. $str = JFilterOutput::stringURLUnicodeSlug($string);
  67. }
  68. else
  69. {
  70. //replace double byte whitespaces by single byte (Far-East languages)
  71. $str = preg_replace('/\xE3\x80\x80/', ' ', $string);
  72. // remove any '-' from the string as they will be used as concatenator.
  73. // Would be great to let the spaces in but only Firefox is friendly with this
  74. $str = str_replace('-', ' ', $str);
  75. // replace forbidden characters by whitespaces
  76. $str = preg_replace( '#[:\#\*"@+=;!&\.%()\]\/\'\\\\|\[]#',"\x20", $str );
  77. //delete all '?'
  78. $str = str_replace('?', '', $str);
  79. //trim white spaces at beginning and end of alias, make lowercase
  80. $str = trim(JString::strtolower($str));
  81. // remove any duplicate whitespace and replace whitespaces by hyphens
  82. $str =preg_replace('#\x20+#','-', $str);
  83. }
  84. return $str;
  85. }
  86. public static function getDefaultRoutingOrder()
  87. {
  88. $config = EasyBlogHelper::getConfig();
  89. $routingType = array('bloggerstandalone','entry','category','blogger','teamblog');
  90. $routingTypeOrder = array();
  91. foreach($routingType as $key)
  92. {
  93. $config_key = 'main_routing_order_' . $key;
  94. $config_ignore = 'main_routing_order_' . $key . '_ignore';
  95. if( ! $config->get($config_ignore) )
  96. {
  97. $routingTypeOrder[$key] = $config->get( $config_key , '0');
  98. }
  99. }
  100. // real sorting perform here.
  101. asort($routingTypeOrder);
  102. return $routingTypeOrder;
  103. }
  104. public static function _($url, $xhtml = true, $ssl = null , $search = false, $isCanonical = false )
  105. {
  106. $mainframe = JFactory::getApplication();
  107. $config = EasyBlogHelper::getConfig();
  108. static $loaded = array();
  109. static $eUri = array();
  110. $useXHTML = (int) $xhtml . (int) $isCanonical;
  111. if( isset( $loaded[$url . $useXHTML ] ) )
  112. {
  113. return $loaded[$url . $useXHTML ];
  114. }
  115. $rawURL = $url;
  116. $blogger = JRequest::getVar( 'blogger' , '' );
  117. if( !empty($blogger) )
  118. {
  119. $url .= '&blogger=' . $blogger;
  120. }
  121. //$jURL = JRoute::_($url, false);
  122. $jURL = $url;
  123. // convert the string to variable so that we can access it.
  124. parse_str($jURL, $post);
  125. $view = isset( $post['view'] ) ? $post['view'] : 'latest';
  126. $Itemid = isset( $post['Itemid'] ) ? $post['Itemid'] : '';
  127. $routingBehavior = $config->get( 'main_routing', 'currentactive');
  128. $exItemid = '';
  129. $findItemId = false;
  130. $dropSegment = false;
  131. if( ($routingBehavior == 'currentactive' || $routingBehavior == 'menuitemid') && !$isCanonical )
  132. {
  133. $routingMenuItem = $config->get('main_routing_itemid','');
  134. if( ($routingBehavior == 'menuitemid') && ($routingMenuItem != '') )
  135. {
  136. $exItemid = $routingMenuItem;
  137. }
  138. // @rule: If there is already an item id, try to use the explicitly set one.
  139. if( empty( $exItemid ) )
  140. {
  141. if( $view == 'entry' )
  142. {
  143. $blogId = $post['id'];
  144. $blog = EasyBlogHelper::getTable( 'Blog', 'Table' );
  145. $blog->load( $blogId );
  146. $author = $blog->created_by;
  147. if( !empty( $author ) )
  148. {
  149. $tmpItemid = EasyBlogRouter::getItemIdByBlogger( $author );
  150. if( !empty( $tmpItemid ) )
  151. {
  152. $isBloggerMode = EasyBlogRouter::isMenuABloggerMode( $tmpItemid );
  153. if( $isBloggerMode )
  154. {
  155. $exItemid = $tmpItemid;
  156. }
  157. }
  158. }
  159. }
  160. // @rule: If it is not a blogger mode, we just use the current one.
  161. if ( !$mainframe->isAdmin() )
  162. {
  163. // Retrieve the active menu item.
  164. $menu = JFactory::getApplication()->getMenu();
  165. $item = $menu->getActive();
  166. if( isset( $item->id ) )
  167. {
  168. $isBloggerMode = EasyBlogRouter::isMenuABloggerMode( $item->id );
  169. if( !$isBloggerMode )
  170. {
  171. $exItemid = $item->id;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. else
  178. {
  179. switch( $view )
  180. {
  181. case 'entry':
  182. $routingOrder = EasyBlogRouter::getDefaultRoutingOrder();
  183. $exItemid = '';
  184. if( !empty($routingOrder) )
  185. {
  186. $blogId = $post['id'];
  187. $blog = EasyBlogHelper::getTable( 'Blog', 'Table' );
  188. $blog->load( $blogId );
  189. $authorId = $blog->created_by;
  190. $categoryId = $blog->category_id;
  191. foreach( $routingOrder as $key => $val )
  192. {
  193. switch( $key )
  194. {
  195. case 'bloggerstandalone':
  196. $bloggerId = EasyBlogRouter::isBloggerMode();
  197. if( $bloggerId !== false )
  198. {
  199. $exItemid = EasyBlogRouter::getItemIdByBlogger( $bloggerId );
  200. }
  201. break;
  202. case 'entry':
  203. $exItemid = EasyBlogRouter::getItemIdByEntry( $blogId );
  204. break;
  205. case 'category':
  206. $exItemid = EasyBlogRouter::getItemIdByCategories( $categoryId );
  207. break;
  208. case 'blogger':
  209. $exItemid = EasyBlogRouter::getItemIdByBlogger( $authorId );
  210. break;
  211. case 'teamblog':
  212. $teamId = $blog->getTeamContributed();
  213. if( ! empty( $teamId ) )
  214. $exItemid = EasyBlogRouter::getItemIdByTeamBlog( $teamId );
  215. break;
  216. }
  217. if( !empty( $exItemid ) )
  218. break;
  219. }
  220. }
  221. if( empty( $exItemid ) )
  222. {
  223. $view = 'latest';
  224. $findItemId = true;
  225. }
  226. break;
  227. case 'blogger':
  228. //if( isset( $post['layout'] ) && isset( $post['id'] ) )
  229. if( isset( $post['id'] ) )
  230. {
  231. $exItemid = EasyBlogRouter::getItemIdByBlogger( $post['id'] );
  232. if( !empty( $exItemid ) )
  233. {
  234. $dropSegment = true;
  235. }
  236. }
  237. if( empty( $exItemid ) )
  238. {
  239. $exItemid = EasyBlogRouter::getItemId( 'blogger', true );
  240. }
  241. if( empty( $exItemid ) )
  242. {
  243. $view = 'latest';
  244. $findItemId = true;
  245. }
  246. break;
  247. case 'categories':
  248. //if( isset( $post['layout'] ) && isset( $post['id'] ) )
  249. if( isset( $post['id'] ) )
  250. {
  251. $exItemid = EasyBlogRouter::getItemIdByCategories( $post['id'] );
  252. if( !empty( $exItemid ) )
  253. {
  254. $dropSegment = true;
  255. }
  256. }
  257. if( empty( $exItemid ) )
  258. {
  259. $bloggerId = EasyBlogRouter::isBloggerMode();
  260. if( $bloggerId !== false )
  261. {
  262. $exItemid = EasyBlogRouter::getItemIdByBlogger( $bloggerId );
  263. }
  264. if( empty( $exItemid ) )
  265. {
  266. $exItemid = EasyBlogRouter::getItemId( 'categories', true );
  267. }
  268. if( empty( $exItemid ) )
  269. {
  270. $view = 'latest';
  271. $findItemId = true;
  272. }
  273. }
  274. break;
  275. case 'teamblog':
  276. //if( isset( $post['layout'] ) && isset( $post['id'] ) )
  277. if( isset( $post['id'] ) )
  278. {
  279. $exItemid = EasyBlogRouter::getItemIdByTeamBlog( $post['id'] );
  280. if( !empty( $exItemid ) )
  281. {
  282. $dropSegment = true;
  283. }
  284. }
  285. if( empty( $exItemid ) )
  286. {
  287. $exItemid = EasyBlogRouter::getItemId( 'teamblog', true );
  288. }
  289. if( empty( $exItemid ) )
  290. {
  291. $view = 'latest';
  292. $findItemId = true;
  293. }
  294. break;
  295. case 'tags':
  296. if( isset( $post['layout'] ) && isset( $post['id'] ) )
  297. {
  298. //now check the active menu whether a blogger isolation mode or not.
  299. $bloggerId = EasyBlogRouter::isBloggerMode();
  300. if( $bloggerId !== false )
  301. {
  302. $exItemid = EasyBlogRouter::getItemIdByBlogger( $bloggerId );
  303. }
  304. if( empty( $exItemid ) )
  305. {
  306. $exItemid = EasyBlogRouter::getItemIdByTag( $post['id'] );
  307. if( !empty( $exItemid ) )
  308. {
  309. $dropSegment = true;
  310. }
  311. }
  312. }
  313. else
  314. {
  315. $exItemid = EasyBlogRouter::getItemId( 'tags' );
  316. }
  317. if( empty( $exItemid ) )
  318. {
  319. $view = 'latest';
  320. $findItemId = true;
  321. }
  322. break;
  323. case 'dashboard':
  324. if( isset( $post['layout'] ) )
  325. {
  326. $exItemid = EasyBlogRouter::getItemIdByDashboardLayout( $post['layout'] );
  327. }
  328. if( empty( $exItemid ) )
  329. {
  330. $exItemid = EasyBlogRouter::getItemId( 'dashboard', true );
  331. }
  332. if( empty( $exItemid ) )
  333. {
  334. $findItemId = true;
  335. }
  336. break;
  337. case 'latest':
  338. $bloggerId = EasyBlogRouter::isBloggerMode();
  339. if( $bloggerId !== false )
  340. {
  341. $exItemid = EasyBlogRouter::getItemIdByBlogger( $bloggerId );
  342. }
  343. if( empty( $exItemid ) )
  344. {
  345. $exItemid = EasyBlogRouter::getItemId( 'latest' );
  346. }
  347. if( empty( $exItemid ) )
  348. {
  349. $findItemId = true;
  350. }
  351. break;
  352. default:
  353. break;
  354. }
  355. }
  356. if( !empty($exItemid) )
  357. {
  358. if( self::isSefEnabled() && $dropSegment )
  359. {
  360. $url = 'index.php?Itemid=' . $exItemid;
  361. $loaded[ $rawURL . $useXHTML ] = JRoute::_($url, $xhtml, $ssl);
  362. return $loaded[$rawURL . $useXHTML];
  363. }
  364. //check if there is any anchor in the link or not.
  365. $pos = JString::strpos($url, '#');
  366. // If item id is provided in the query itself, we do not need to append any item id.
  367. // otherwise the result would be &Itemid=1&Itemid=2
  368. if( !$Itemid )
  369. {
  370. if ($pos === false)
  371. {
  372. $url .= '&Itemid='.$exItemid;
  373. }
  374. else
  375. {
  376. $url = JString::str_ireplace('#', '&Itemid='.$exItemid.'#', $url);
  377. }
  378. }
  379. $loaded[ $rawURL . $useXHTML ] = JRoute::_($url, $xhtml, $ssl);
  380. return $loaded[$rawURL . $useXHTML];
  381. }
  382. //fall back to previous style if getting the Itemid
  383. if( empty( $Itemid ) && $findItemId )
  384. {
  385. $tmpId = '';
  386. $useDefaultWay = false;
  387. if ( $mainframe->isAdmin())
  388. {
  389. //from backend.
  390. $useDefaultWay = true;
  391. }
  392. else
  393. {
  394. //from frontend.
  395. //lets try to get from the default itemId.
  396. $menu = JFactory::getApplication()->getMenu();
  397. $item = $menu->getActive();
  398. if( !$findItemId && isset($item->id) && ($item->component == 'com_easyblog' ) && !$search )
  399. {
  400. $tmpId = $item->id;
  401. }
  402. else
  403. {
  404. $useDefaultWay = true;
  405. }
  406. }
  407. if($useDefaultWay)
  408. {
  409. if(empty($eUri[$view]))
  410. {
  411. $tmpId = EasyBlogRouter::getItemId($view);
  412. $eUri[$view] = $tmpId;
  413. }
  414. else
  415. {
  416. $tmpId = $eUri[$view];
  417. }
  418. }
  419. //check if there is any anchor in the link or not.
  420. $pos = JString::strpos($url, '#');
  421. if ($pos === false)
  422. {
  423. $url .= '&Itemid='.$tmpId;
  424. }
  425. else
  426. {
  427. $url = JString::str_ireplace('#', '&Itemid='.$tmpId.'#', $url);
  428. }
  429. }
  430. $loaded[ $rawURL . $useXHTML ] = JRoute::_($url, $xhtml, $ssl);
  431. return $loaded[$rawURL . $useXHTML];
  432. }
  433. public static function isSefEnabled()
  434. {
  435. $jConfig = EasyBlogHelper::getJConfig();
  436. $isSef = false;
  437. $isSef = self::isSh404Enabled();
  438. // if sh404sef not enabled, we check on joomla
  439. if(! $isSef)
  440. {
  441. $isSef = $jConfig->get( 'sef' );
  442. }
  443. return $isSef;
  444. }
  445. public static function isSh404Enabled()
  446. {
  447. $isEnabled = false;
  448. //check if sh404sef enabled or not.
  449. if( defined('sh404SEF_AUTOLOADER_LOADED') && JFile::exists(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_sh404sef' . DIRECTORY_SEPARATOR . 'sh404sef.class.php'))
  450. {
  451. require_once(JPATH_ADMINISTRATOR.DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_sh404sef'.DIRECTORY_SEPARATOR.'sh404sef.class.php');
  452. if( class_exists( 'shRouter' ) )
  453. {
  454. $sefConfig = shRouter::shGetConfig();
  455. if ($sefConfig->Enabled)
  456. $isEnabled = true;
  457. }
  458. }
  459. return $isEnabled;
  460. }
  461. public static function getTagPermalink( $id )
  462. {
  463. $config = EasyBlogHelper::getConfig();
  464. JTable::addIncludePath( EBLOG_TABLES );
  465. $table = EasyBlogHelper::getTable( 'Tag' , 'Table' );
  466. $table->load( $id );
  467. if( $config->get( 'main_sef_unicode' ) )
  468. {
  469. return $table->id . '-' . $table->alias;
  470. }
  471. else
  472. {
  473. return $table->alias;
  474. }
  475. }
  476. public static function getTeamBlogPermalink( $id )
  477. {
  478. $config = EasyBlogHelper::getConfig();
  479. JTable::addIncludePath( EBLOG_TABLES );
  480. $team = EasyBlogHelper::getTable( 'TeamBlog' , 'Table' );
  481. $team->load( $id );
  482. if( $config->get( 'main_sef_unicode' ) )
  483. {
  484. return $team->id . '-' . $team->alias;
  485. }
  486. else
  487. {
  488. return $team->alias;
  489. }
  490. }
  491. public static function getBloggerPermalink( $id )
  492. {
  493. $config = EasyBlogHelper::getConfig();
  494. JTable::addIncludePath( EBLOG_TABLES );
  495. if( $id == 0 )
  496. {
  497. $id = null;
  498. }
  499. $user = JFactory::getUser($id);
  500. $profile = EasyBlogHelper::getTable( 'Profile' , 'Table' );
  501. $profile->load($id);
  502. $profile->setUser($user);
  503. if( empty($user->username) )
  504. {
  505. // blogger not exists
  506. return JText::_('COM_EASYBLOG_INVALID_PERMALINK_BLOGGER');
  507. }
  508. $bloggerPermalink = $profile->permalink;
  509. if( empty( $bloggerPermalink ) )
  510. {
  511. $bloggerPermalink = EasyBlogRouter::generatePermalink( $user->username );
  512. $db = EasyBlogHelper::db();
  513. $query = 'UPDATE `#__easyblog_users` SET `permalink` =' . $db->Quote( $bloggerPermalink ) . ' '
  514. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'id' ) . '=' . $db->Quote( $profile->id );
  515. $db->setQuery( $query );
  516. $db->query();
  517. }
  518. if( $config->get( 'main_sef_unicode' ) )
  519. {
  520. return $profile->id . '-' . $bloggerPermalink;
  521. }
  522. else
  523. {
  524. return $bloggerPermalink;
  525. }
  526. }
  527. public static function getCategoryPermalink( $id )
  528. {
  529. $config = EasyBlogHelper::getConfig();
  530. JTable::addIncludePath( EBLOG_TABLES );
  531. $table = EasyBlogHelper::getTable( 'Category' , 'Table' );
  532. $table->load( $id );
  533. if( $config->get( 'main_sef_unicode' ) )
  534. {
  535. return $table->id . '-' . $table->alias;
  536. }
  537. else
  538. {
  539. return $table->alias;
  540. }
  541. }
  542. public static function getBlogSefPermalink( $id , $external = false )
  543. {
  544. $config = EasyBlogHelper::getConfig();
  545. static $permalinks = null;
  546. if( !isset( $permalinks[ $id ] ) )
  547. {
  548. JTable::addIncludePath( EBLOG_TABLES );
  549. $db = EasyBlogHelper::db();
  550. $query = 'SELECT a.* FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__easyblog_post' ) . ' as a '
  551. . 'WHERE a.`id` ' . '=' . $db->Quote( $id );
  552. $db->setQuery( $query );
  553. $data = $db->loadObject();
  554. $config = EasyBlogHelper::getConfig();
  555. if( empty($data) )
  556. {
  557. // blog post not exists
  558. $permalinks[ $id ] = JText::_('COM_EASYBLOG_INVALID_PERMALINK_POST');
  559. return $permalinks[ $id ];
  560. }
  561. // Empty permalinks needs to be regenerated.
  562. if( empty($data->permalink) )
  563. {
  564. $data->permalink = EasyBlogHelper::getPermalink( $data->title );
  565. $query = 'UPDATE #__easyblog_post SET permalink=' . $db->Quote( $data->permalink ) . ' '
  566. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'id' ) . '=' . $db->Quote( $id );
  567. $db->setQuery( $query );
  568. $db->Query();
  569. }
  570. if( $config->get( 'main_sef_unicode' ) )
  571. {
  572. $data->permalink = $data->id . '-' . urlencode($data->permalink);
  573. }
  574. switch( $config->get( 'main_sef' ) )
  575. {
  576. // Date based SEF mode
  577. case 'date':
  578. $date = EasyBlogHelper::getDate( $data->created );
  579. $data->permalink = $date->toFormat('%Y') . '/' . $date->toFormat( '%m' ) . '/' . $date->toFormat('%d') . '/' . $data->permalink;
  580. break;
  581. case 'datecategory':
  582. $date = EasyBlogHelper::getDate( $data->created );
  583. $catPermalink = EasyBlogRouter::getCategoryPermalink( $data->category_id );
  584. $data->permalink = $catPermalink . '/' . $date->toFormat('%Y') . '/' . $date->toFormat( '%m' ) . '/' . $date->toFormat('%d') . '/' . $data->permalink;
  585. break;
  586. case 'category':
  587. $catPermalink = EasyBlogRouter::getCategoryPermalink( $data->category_id );
  588. $data->permalink = $catPermalink . '/' . $data->permalink;
  589. break;
  590. case 'custom':
  591. $data->permalink = self::getCustomPermalink( $data );
  592. break;
  593. // Default SEF mode leave it unchanged
  594. default:
  595. break;
  596. }
  597. if( $external )
  598. {
  599. $uri = JURI::getInstance();
  600. return $uri->toString( array('scheme', 'host', 'port')) . '/' . $data->permalink;
  601. }
  602. $permalinks[ $id ] = $data->permalink;
  603. }
  604. return $permalinks[ $id ];
  605. }
  606. public static function getCustomPermalink( &$data )
  607. {
  608. $cfg = EasyBlogHelper::getConfig();
  609. $custom = $cfg->get( 'main_sef_custom' );
  610. $date = EasyBlogHelper::getDate( $data->created );
  611. // @task: If the user didn't enter any values for the custom sef, we'll just load the default one which is the 'date' based
  612. if( empty( $custom ) )
  613. {
  614. return $date->toFormat('%Y') . '/' . $date->toFormat( '%m' ) . '/' . $date->toFormat('%d') . '/' . $data->permalink;
  615. }
  616. // @task: Break all parts separated by /
  617. $pieces = explode( '/' , $custom );
  618. if( !$pieces )
  619. {
  620. $date = EasyBlogHelper::getDate( $data->created );
  621. return $date->toFormat('%Y') . '/' . $date->toFormat( '%m' ) . '/' . $date->toFormat('%d') . '/' . $data->permalink;
  622. }
  623. $result = array();
  624. foreach( $pieces as $piece )
  625. {
  626. // @task: Replace %year_num%
  627. $piece = str_ireplace( '%year_num%' , $date->toFormat( '%Y' ) , $piece );
  628. // @task: Replace %month_num%
  629. $piece = str_ireplace( '%month_num%' , $date->toFormat( '%m' ) , $piece );
  630. // @task: Replace %day_num%
  631. $piece = str_ireplace( '%day_num%' , $date->toFormat( '%d' ) , $piece );
  632. // @task: Replace %day%
  633. $piece = str_ireplace( '%day%' , $date->toFormat( '%A' ) , $piece );
  634. // @task: Replace %month%
  635. $piece = str_ireplace( '%month%' , $date->toFormat( '%b' ) , $piece );
  636. // @task: Replace %blog_id%
  637. $piece = str_ireplace( '%blog_id%' , $data->id , $piece );
  638. // @task: Replace %category%
  639. $piece = str_ireplace( '%category%' , EasyBlogRouter::getCategoryPermalink( $data->category_id ) , $piece );
  640. // @task: Replace %category_id%
  641. $piece = str_ireplace( '%category_id%' , $data->category_id , $piece );
  642. $result[] = $piece;
  643. }
  644. $url = implode( '/' , $result );
  645. $url .= '/' . $data->permalink;
  646. return $url;
  647. }
  648. public static function getRoutedURL( $url , $xhtml = false , $external = false, $isCanonical = false )
  649. {
  650. if( !$external )
  651. {
  652. return EasyBlogRouter::_( $url , $xhtml, null, false, $isCanonical );
  653. }
  654. $mainframe = JFactory::getApplication();
  655. $uri = JURI::getInstance();
  656. $isDashboard = false;
  657. if ( !$mainframe->isAdmin() )
  658. {
  659. $menu = JFactory::getApplication()->getMenu();
  660. $item = $menu->getActive();
  661. if( isset($item->link) )
  662. {
  663. $pos = strpos($item->link, 'view=dashboard');
  664. if( $pos !== false)
  665. {
  666. $isDashboard = true;
  667. }
  668. }
  669. }
  670. //To fix 1.6 Jroute issue as it will include the administrator into the url path.
  671. $oriURL = $url;
  672. if( $mainframe->isAdmin() && EasyBlogRouter::isSefEnabled() )
  673. {
  674. if( EasyBlogHelper::getJoomlaVersion() >= '1.6')
  675. {
  676. JFactory::$application = JApplication::getInstance('site');
  677. }
  678. if( EasyBlogHelper::getJoomlaVersion() >= '3.0' )
  679. {
  680. jimport( 'joomla.libraries.cms.router' );
  681. }
  682. else
  683. {
  684. require_once( JPATH_ROOT . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'router.php' );
  685. require_once( JPATH_ROOT . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'application.php' );
  686. }
  687. $router = new JRouterSite(array('mode'=>JROUTER_MODE_SEF));
  688. $urls = str_replace('/administrator/', '/', EasyBlogRouter::_( $oriURL , $xhtml, null, $isDashboard, $isCanonical ));
  689. $urls = rtrim( JURI::root(), '/') . '/' . ltrim( str_replace('/administrator/', '/', $urls) , '/' );
  690. $container = explode('/', $urls);
  691. $container = array_unique($container);
  692. $urls = implode('/', $container);
  693. if( EasyBlogHelper::getJoomlaVersion() >= '1.6')
  694. {
  695. JFactory::$application = JApplication::getInstance('administrator');
  696. }
  697. return $urls;
  698. }
  699. else
  700. {
  701. $url = str_replace('/administrator/', '/', EasyBlogRouter::_( $url , $xhtml, null, $isDashboard, $isCanonical ));
  702. }
  703. // We need to use $uri->toString() because JURI::root() may contain a subfolder which will be duplicated
  704. // since $url already has the subfolder.
  705. if( $mainframe->isAdmin() )
  706. {
  707. return $uri->toString( array('scheme', 'host', 'port')) . '/' . ltrim( $url , '/' );
  708. }
  709. return $uri->toString( array('scheme', 'host', 'port')) . '/' . ltrim( $url , '/' );
  710. }
  711. public static function _isBlogPermalinkExists( $permalink )
  712. {
  713. $db = EasyBlogHelper::db();
  714. $query = 'SELECT COUNT(1) FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__easyblog_post' ) . ' '
  715. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'permalink' ) . '=' . $db->Quote( $permalink );
  716. $db->setQuery( $query );
  717. return $db->loadResult() > 0 ? true : false;
  718. }
  719. public static function replaceAccents( $string )
  720. {
  721. $a = array('Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß' , 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
  722. $b = array('AE', 'ae', 'OE', 'oe', 'UE', 'ue', 'ss', 'A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
  723. return str_replace($a, $b, $string);
  724. }
  725. public static function getEntryRoute( $id )
  726. {
  727. $url = 'index.php?option=com_easyblog&view=entry&id=' . $id;
  728. $url .= '&Itemid=' . EasyBlogRouter::getItemId('entry');
  729. return $url;
  730. }
  731. public static function getItemIdByEntry( $blogId )
  732. {
  733. static $entriesItems = null;
  734. if( !isset( $entriesItems[ $blogId ] ) )
  735. {
  736. $db = EasyBlogHelper::db();
  737. // We need to check against the correct latest entry to be used based on the category this article is in
  738. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'id' ) . ',' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'params') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' )
  739. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=latest' )
  740. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  741. . self::getLanguageQuery();
  742. $db->setQuery( $query );
  743. $menus = $db->loadObjectList();
  744. $blog = EasyBlogHelper::getTable( 'Blog' );
  745. $blog->load( $blogId );
  746. if( $menus )
  747. {
  748. foreach( $menus as $menu )
  749. {
  750. $params = EasyBlogHelper::getRegistry( $menu->params );
  751. $inclusion = EasyBlogHelper::getCategoryInclusion( $params->get( 'inclusion' ) );
  752. if( empty( $inclusion ) )
  753. {
  754. continue;
  755. }
  756. if( !is_array( $inclusion ) )
  757. {
  758. $inclusion = array( $inclusion );
  759. }
  760. if( in_array( $blog->category_id , $inclusion ) )
  761. {
  762. $entriesItems[ $blogId ] = $menu->id;
  763. }
  764. }
  765. }
  766. // Test if there is any entry specific view as this will always override the latest above.
  767. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  768. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=entry&id='.$blogId ) . ' '
  769. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  770. . self::getLanguageQuery()
  771. . ' LIMIT 1';
  772. $db->setQuery( $query );
  773. $itemid = $db->loadResult();
  774. if( $itemid )
  775. {
  776. $entriesItems[ $blogId ] = $itemid;
  777. }
  778. else
  779. {
  780. return '';
  781. }
  782. }
  783. return $entriesItems[ $blogId ];
  784. }
  785. public static function getItemIdByDashboardLayout( $layout )
  786. {
  787. static $dashboardLayout = null;
  788. if( !isset( $dashboardLayout[ $layout ] ) )
  789. {
  790. $db = EasyBlogHelper::db();
  791. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  792. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=dashboard&layout=' .$layout) . ' '
  793. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  794. . self::getLanguageQuery()
  795. . ' LIMIT 1';
  796. $db->setQuery( $query );
  797. $itemid = $db->loadResult();
  798. $dashboardLayout[ $layout ] = $itemid;
  799. return $itemid;
  800. }
  801. else
  802. {
  803. return $dashboardLayout[ $layout ];
  804. }
  805. }
  806. public static function getItemIdByTeamBlog( $teamId )
  807. {
  808. static $teamblogItems = null;
  809. if( !isset( $teamblogItems[ $teamId ] ) )
  810. {
  811. $db = EasyBlogHelper::db();
  812. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  813. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=teamblog&layout=listings&id='.$teamId ) . ' '
  814. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  815. . self::getLanguageQuery()
  816. . ' LIMIT 1';
  817. $db->setQuery( $query );
  818. $itemid = $db->loadResult();
  819. $teamblogItems[ $teamId ] = $itemid;
  820. return $itemid;
  821. }
  822. else
  823. {
  824. return $teamblogItems[ $teamId ];
  825. }
  826. }
  827. public static function getCategoryParentId( $categoryId , &$parents )
  828. {
  829. $category = EasyBlogHelper::getTable( 'Category' );
  830. $category->load( $categoryId );
  831. if( !empty( $category->parent_id) )
  832. {
  833. $parents[] = $category->parent_id;
  834. self::getCategoryParentId( $category->parent_id , $parents );
  835. }
  836. }
  837. public static function getItemIdByCategories( $categoryId )
  838. {
  839. static $categoryItems = null;
  840. if( !isset( $categoryItems[ $categoryId ] ) )
  841. {
  842. $categories = array( $categoryId );
  843. // self::getCategoryParentId( $categoryId , $categories );
  844. $itemid = false;
  845. $db = EasyBlogHelper::db();
  846. foreach( $categories as $categoryId )
  847. {
  848. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  849. . 'WHERE (' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=categories&layout=listings&id='.$categoryId) . ' '
  850. . 'OR ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . ' LIKE ' . $db->Quote( 'index.php?option=com_easyblog&view=categories&layout=listings&id='.$categoryId . '&limit%') . ') '
  851. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  852. . self::getLanguageQuery()
  853. . ' LIMIT 1';
  854. $db->setQuery( $query );
  855. $result = $db->loadResult();
  856. if( $result )
  857. {
  858. $itemid = $db->loadResult();
  859. break;
  860. }
  861. }
  862. $categoryItems[ $categoryId ] = $itemid;
  863. return $itemid;
  864. }
  865. else
  866. {
  867. return $categoryItems[ $categoryId ];
  868. }
  869. }
  870. public static function getItemIdByBlogger( $bloggerId )
  871. {
  872. static $bloggerItems = null;
  873. if( !isset( $bloggerItems[ $bloggerId ] ) )
  874. {
  875. $db = EasyBlogHelper::db();
  876. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  877. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=blogger&layout=listings&id='.$bloggerId ) . ' '
  878. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  879. . self::getLanguageQuery()
  880. . ' LIMIT 1';
  881. $db->setQuery( $query );
  882. $itemid = $db->loadResult();
  883. $bloggerItems[ $bloggerId ] = $itemid;
  884. return $itemid;
  885. }
  886. else
  887. {
  888. return $bloggerItems[ $bloggerId ];
  889. }
  890. }
  891. public static function getItemIdByTag( $tagId )
  892. {
  893. static $tagItems = null;
  894. if( !isset( $tagItems[ $tagId ] ) )
  895. {
  896. $db = EasyBlogHelper::db();
  897. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  898. . 'WHERE (' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=tags&layout=tag&id='.$tagId) . ' '
  899. . 'OR ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . ' LIKE ' . $db->Quote( 'index.php?option=com_easyblog&view=tags&layout=tag&id='.$tagId . '&limit%') . ') '
  900. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  901. . self::getLanguageQuery()
  902. . ' LIMIT 1';
  903. $db->setQuery( $query );
  904. $itemid = $db->loadResult();
  905. $tagItems[ $tagId ] = $itemid;
  906. return $itemid;
  907. }
  908. else
  909. {
  910. return $tagItems[ $tagId ];
  911. }
  912. }
  913. public static function getItemId( $view='' ,$exactMatch = false )
  914. {
  915. static $items = null;
  916. if( !isset( $items[ $view ] ) )
  917. {
  918. $db = EasyBlogHelper::db();
  919. switch($view)
  920. {
  921. case 'archive':
  922. $view='archive';
  923. break;
  924. case 'blogger':
  925. $view='blogger';
  926. break;
  927. case 'calendar':
  928. $view='calendar';
  929. break;
  930. case 'categories':
  931. $view='categories';
  932. break;
  933. case 'dashboard':
  934. $view='dashboard';
  935. break;
  936. case 'myblog':
  937. $view='myblog';
  938. break;
  939. case 'profile';
  940. $view='dashboard&layout=profile';
  941. break;
  942. case 'subscription':
  943. $view='subscription';
  944. break;
  945. case 'tags':
  946. $view='tags';
  947. break;
  948. case 'teamblog':
  949. $view='teamblog';
  950. break;
  951. case 'search':
  952. $view='search';
  953. break;
  954. case 'latest':
  955. default:
  956. $view='latest';
  957. break;
  958. }
  959. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  960. . 'WHERE (' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view='.$view ) . ' '
  961. . 'OR ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . ' LIKE ' . $db->Quote( 'index.php?option=com_easyblog&view='.$view.'&limit=%' ) . ') '
  962. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  963. . self::getLanguageQuery()
  964. . ' LIMIT 1';
  965. $db->setQuery( $query );
  966. $itemid = $db->loadResult();
  967. if( ! $exactMatch )
  968. {
  969. // @rule: Try to fetch based on the current view.
  970. if( empty( $itemid ) )
  971. {
  972. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  973. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . ' LIKE ' . $db->Quote( 'index.php?option=com_easyblog&view=' . $view . '%' ) . ' '
  974. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  975. . self::getLanguageQuery()
  976. . ' LIMIT 1';
  977. $db->setQuery( $query );
  978. $itemid = $db->loadResult();
  979. }
  980. }
  981. if(empty($itemid))
  982. {
  983. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  984. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . '=' . $db->Quote( 'index.php?option=com_easyblog&view=latest' ) . ' '
  985. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  986. . self::getLanguageQuery()
  987. . ' LIMIT 1';
  988. $db->setQuery( $query );
  989. $itemid = $db->loadResult();
  990. }
  991. //last try. get anything view that from easyblog.
  992. if(empty($itemid))
  993. {
  994. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  995. . 'WHERE ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'link' ) . ' LIKE ' . $db->Quote( 'index.php?option=com_easyblog&view=%' ) . ' '
  996. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  997. . self::getLanguageQuery()
  998. . ' ORDER BY `id` LIMIT 1';
  999. $db->setQuery( $query );
  1000. $itemid = $db->loadResult();
  1001. }
  1002. // if still failed the get any item id, then get the joomla default menu item id.
  1003. if( empty($itemid) )
  1004. {
  1005. $query = 'SELECT ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote('id') . ' FROM ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( '#__menu' ) . ' '
  1006. . 'WHERE `home` = ' . $db->Quote( '1' ) . ' '
  1007. . 'AND ' . EasyBlogHelper::getHelper( 'SQL' )->nameQuote( 'published' ) . '=' . $db->Quote( '1' )
  1008. . self::getLanguageQuery()
  1009. . ' ORDER BY `id` LIMIT 1';
  1010. $db->setQuery( $query );
  1011. $itemid = $db->loadResult();
  1012. }
  1013. $items[ $view ] = !empty($itemid)? $itemid : 1;
  1014. }
  1015. return $items[ $view ];
  1016. }
  1017. public function _encodeSegments($segments)
  1018. {
  1019. //return parent::_encodeSegments($segments);
  1020. return JFactory::getApplication()->getRouter()->_encodeSegments($segments);
  1021. }
  1022. function _getBloggerId($itemId)
  1023. {
  1024. $db = EasyBlogHelper::db();
  1025. $query = 'select `link` from `#__menu` where `id` = ' . $db->Quote($itemId);
  1026. $db->setQuery($query);
  1027. $link = $db->loadResult();
  1028. parse_str($link);
  1029. return $id;
  1030. }
  1031. public static function isBloggerMode()
  1032. {
  1033. static $itemIds = null;
  1034. $itemId = JRequest::getInt('Itemid', 0);
  1035. $blogger = JRequest::getVar( 'blogger' , '' );
  1036. if( !empty( $blogger ) )
  1037. {
  1038. return $blogger;
  1039. }
  1040. if(empty($itemId))
  1041. {
  1042. return false;
  1043. }
  1044. if( !isset( $itemIds[ $itemId ] ) )
  1045. {
  1046. $isBloggerMode = false;
  1047. $menu = JFactory::getApplication()->getMenu();
  1048. $menuparams = $menu->getParams( $itemId );
  1049. if($menuparams->get('standalone_blog', false))
  1050. {
  1051. $isBloggerMode = EasyBlogRouter::_getBloggerId($itemId);
  1052. }
  1053. $itemIds[$itemId] = $isBloggerMode;
  1054. }
  1055. return $itemIds[$itemId];
  1056. }
  1057. public static function isMenuABloggerMode( $itemId )
  1058. {
  1059. $mainframe = JFactory::getApplication();
  1060. if ( !$mainframe->isAdmin() )
  1061. {
  1062. $menu = JFactory::getApplication()->getMenu();
  1063. $menuparams = $menu->getParams( $itemId );
  1064. $isBloggerMode = $menuparams->get('standalone_blog', false);
  1065. return $isBloggerMode;
  1066. }
  1067. return false;
  1068. }
  1069. // return true or false
  1070. public static function isCurrentActiveMenu( $view, $id = 0 )
  1071. {
  1072. $activemenu = JFactory::getApplication()->getMenu();
  1073. $activeitem = $activemenu->getActive();
  1074. if( ! empty($activeitem) )
  1075. {
  1076. if( !empty( $id ) )
  1077. {
  1078. if( (strpos( $activeitem->link, 'view=' . $view ) !== false) && (strpos( $activeitem->link, 'id=' . $id ) !== false) )
  1079. return true;
  1080. }
  1081. else if( strpos( $activeitem->link, 'view=' . $view ) !== false)
  1082. {
  1083. return true;
  1084. }
  1085. }
  1086. return false;
  1087. }
  1088. }