Blame view

components/com_jmap/views/sitemap/tmpl/adapters/com_easyblog.php 7.12 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
<?php
/** 
 * @package JMAP::SITEMAP::components::com_jmap
 * @subpackage views
 * @subpackage sitemap
 * @subpackage tmpl
 * @subpackage adapters
 * @author Joomla! Extensions Store
 * @copyright (C) 2015 - Joomla! Extensions Store
 * @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
 */
defined('_JEXEC') or die('Restricted access');

// Adapter for Easydiscuss posts route helper
if(class_exists('EBR')) { // Easyblog 4+
	$helperRouteClass= 'EBR';
} else {
	$helperRouteClass= 'EasyBlogRouter'; // Easyblog < 4
}

// Use the component routing handler if it exists
$path = JPATH_SITE . '/components/com_easyblog/router.php';
// Use the custom routing handler if it exists
if (!isset($GLOBALS['jmapEBRouter']) && file_exists($path)) {
	require_once $path;
	$GLOBALS['jmapEBRouter'] = true;
}

// Get DB Object
$jDb = JFactory::getDbo();

switch ($targetViewName) {
	case 'entry':
		// Set empty in all cases
		$itemId = null;
		$directPostMenuItemid = null;
		$createdbyAuthorItemId = null;
		
		// Buffered itemid already resolved for this category
		if(isset($GLOBALS['jmapEBStaticCatsBuffer'][$elm->jsitemap_category_id])) {
			$itemId = $GLOBALS['jmapEBStaticCatsBuffer'][$elm->jsitemap_category_id];
		}
		
		// Get all Easyblog 'latest' menu items
		if(!isset($GLOBALS['jmapEBStaticMenusBuffer'])) {
			$query	= 'SELECT ' . $jDb->quoteName('id') . 
					  ' FROM ' . $jDb->quoteName( '#__menu' ) .
					  ' WHERE ' .  $jDb->quoteName( 'link' ) . ' = ' .  $jDb->quote( 'index.php?option=com_easyblog&view=latest' ) .
					  ' AND ' .  $jDb->quoteName( 'client_id' ) . ' = 0' .
					  ' AND ' .  $jDb->quoteName( 'published' ) . ' = 1';
			$jDb->setQuery( $query );
			$topLatestMenuItemids = $jDb->loadColumn();
			$GLOBALS['jmapEBStaticMenusBuffer'] = $topLatestMenuItemids;
		}
		
		// Check always if we have a direct post id to menu item and give highest priority
		$classMethod = 'getItemIdByEntry';
		$directPostMenuItemid = $helperRouteClass::$classMethod ( $elm->id );
		if( $directPostMenuItemid ){
			if(!in_array($directPostMenuItemid, $GLOBALS['jmapEBStaticMenusBuffer'])) {
				$itemId = $directPostMenuItemid;
			} else {
				$directPostMenuItemid = null;
			}
		}
		
		// Check always if we have a blogger author information and give priority to the author menu item
		if (! $itemId && isset($elm->created_by)) {
			$classMethod = 'getItemIdByBlogger';
			$createdbyAuthorItemId = $helperRouteClass::$classMethod ( $elm->created_by );
			if($createdbyAuthorItemId) {
				$itemId = $createdbyAuthorItemId;
			}
		}
		
		// Check if we have a direct category id to menu item
		if (! $itemId) {
			$classMethod = 'getItemIdByCategories';
			$itemId = $helperRouteClass::$classMethod ( $elm->jsitemap_category_id );
		}
		
		// Check if we have a parent category id to menu item
		if (! $itemId) {
			$parentCategories = array();
			$query	= 'SELECT parent.id' . 
					  ' FROM ' . $jDb->quoteName( '#__easyblog_category' ) . ' AS ' . $jDb->quoteName('node') . ', ' .
					  $jDb->quoteName( '#__easyblog_category' ) . ' AS ' . $jDb->quoteName('parent') . 
					  ' WHERE node.lft BETWEEN parent.lft AND parent.rgt' .
					  ' AND node.id = ' . $jDb->quote( $elm->jsitemap_category_id ) .
					  ' AND parent.id != ' . $jDb->quote( $elm->jsitemap_category_id ) .
					  ' ORDER BY parent.lft';
			$jDb->setQuery( $query );
			$parentCategories = $jDb->loadColumn();
			
			// Found parent categories?
			if(!empty($parentCategories)) {
				foreach ($parentCategories as $parentCat) {
					$itemId = $helperRouteClass::$classMethod ( $parentCat );
					if($itemId) {
						break;
					}
				}
			}
		}
		
		// Get all Easyblog 'categories' menu items if there is not the view=latest menu item
		if(!$itemId && !$GLOBALS['jmapEBStaticMenusBuffer']) {
			if(isset($GLOBALS['jmapEBStaticAllCategoriesItemMenusBuffer']) && $GLOBALS['jmapEBStaticAllCategoriesItemMenusBuffer']) {
				$itemId = $GLOBALS['jmapEBStaticAllCategoriesItemMenusBuffer'];
			}
			
			if(!isset($GLOBALS['jmapEBStaticAllCategoriesItemMenusBuffer'])) {
				$query	= 'SELECT ' . $jDb->quoteName('id') . 
						  ' FROM ' . $jDb->quoteName( '#__menu' ) .
						  ' WHERE ' .  $jDb->quoteName( 'link' ) . ' = ' .  $jDb->quote( 'index.php?option=com_easyblog&view=categories' ) .
						  ' AND ' .  $jDb->quoteName( 'client_id' ) . ' = 0' .
						  ' AND ' .  $jDb->quoteName( 'published' ) . ' = 1';
				$jDb->setQuery( $query );
				$itemId = $jDb->loadResult();
				$GLOBALS['jmapEBStaticAllCategoriesItemMenusBuffer'] = $itemId ? $itemId : false;
			}
		}
		
		if ($itemId) {
			// Assign only if a real category resolved Itemid
			if(!$directPostMenuItemid && !$createdbyAuthorItemId) {
				$GLOBALS['jmapEBStaticCatsBuffer'][$elm->jsitemap_category_id] = $itemId;
			}
			$itemId = '&Itemid=' . $itemId;
		}

		// Final SEF link routing
		if(!$directPostMenuItemid) {
			$seflink = JRoute::_ ('index.php?option=com_easyblog&view=entry&id=' . $elm->id . $itemId);
		} else {
			$seflink = JRoute::_ ('index.php?Itemid=' . $directPostMenuItemid);
		}

	break;

	case 'categories':
		if(strpos($additionalQueryStringParams, 'layout=listings')) {
			// Set empty in all cases
			$itemId = null;
			
			$classMethod = 'getItemIdByCategories';
			$itemId = $helperRouteClass::$classMethod ( $elm->id );
			
			// Check if we have a parent category id to menu item
			if (! $itemId) {
				$parentCategories = array();
				$query	= 'SELECT parent.id' .
						  ' FROM ' . $jDb->quoteName( '#__easyblog_category' ) . ' AS ' . $jDb->quoteName('node') . ', ' .
						  $jDb->quoteName( '#__easyblog_category' ) . ' AS ' . $jDb->quoteName('parent') .
						  ' WHERE node.lft BETWEEN parent.lft AND parent.rgt' .
						  ' AND node.id = ' . $jDb->quote( $elm->id ) .
						  ' AND parent.id != ' . $jDb->quote( $elm->id ) .
						  ' ORDER BY parent.lft';
			    $jDb->setQuery( $query );
			    $parentCategories = $jDb->loadColumn();
							
				// Found parent categories?
				if(!empty($parentCategories)) {
					foreach ($parentCategories as $parentCat) {
						$itemId = $helperRouteClass::$classMethod ( $parentCat );
						if($itemId) {
							break;
						}
					}
				}
			}
			
			// Get all Easyblog 'categories' menu items
			if(!$itemId) {
				if(isset($GLOBALS['jmapEBStaticAllCategoriesMenusBuffer']) && $GLOBALS['jmapEBStaticAllCategoriesMenusBuffer']) {
					$itemId = $GLOBALS['jmapEBStaticAllCategoriesMenusBuffer'];
				}
				
				if(!isset($GLOBALS['jmapEBStaticAllCategoriesMenusBuffer'])) {
					$query	= 'SELECT ' . $jDb->quoteName('id') . 
							  ' FROM ' . $jDb->quoteName( '#__menu' ) .
							  ' WHERE ' .  $jDb->quoteName( 'link' ) . ' = ' .  $jDb->quote( 'index.php?option=com_easyblog&view=categories' ) .
							  ' AND ' .  $jDb->quoteName( 'client_id' ) . ' = 0' .
							  ' AND ' .  $jDb->quoteName( 'published' ) . ' = 1';
					$jDb->setQuery( $query );
					$itemId = $jDb->loadResult();
					$GLOBALS['jmapEBStaticAllCategoriesMenusBuffer'] = $itemId ? $itemId : false;
				}
			}
			
			if ($itemId) {
				// Assign only if a real category resolved Itemid
				$itemId = '&Itemid=' . $itemId;
			}
			
			// Final SEF link routing
			$seflink = JRoute::_ ('index.php?option=com_easyblog&view=categories&layout=listings&id=' . $elm->id . $itemId);
		}
		
	break;
}