Beispiel #1
0
 function shKUCategoryName($catid, $option, $shLangIso, $shLangName)
 {
     global $sh_LANG;
     static $cats = null;
     $sefConfig =& Sh404sefFactory::getConfig();
     if (empty($catid) || !$sefConfig->shFbInsertCategoryName) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $category = KunenaForumCategory::getInstance($catid);
         $catname = $category->name;
     } elseif (class_exists('KunenaRouter')) {
         if (KunenaRouter::$catidcache === null) {
             KunenaRouter::loadCategories();
         }
         // Kunena 1.6 support
         $catname = empty(KunenaRouter::$catidcache[$catid]) ? '' : KunenaRouter::$catidcache[$catid]['name'];
     } else {
         // Kunena 1.0 / 1.5 support
         if (is_null($cats)) {
             try {
                 $cats = ShlDbHelper::selectObjectList('#__fb_categories', array('id', 'name'));
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
         }
         $catname = empty($cats[$catid]) ? null : $cats[$catid]->name;
     }
     $shCat = empty($catname) ? $sh_LANG[$shLangIso]['COM_SH404SEF_KU_CATEGORY'] . $sefConfig->replacement . $catid : ($sefConfig->shFbInsertCategoryId ? $catid . $sefConfig->replacement : '') . $catname;
     // if name, put ID only if requested
     return $shCat;
 }
Beispiel #2
0
 function shKUCategoryName($catid, $option, $shLangIso, $shLangName)
 {
     global $sh_LANG;
     static $cats = null;
     $sefConfig =& shRouter::shGetConfig();
     if (empty($catid) || !$sefConfig->shFbInsertCategoryName) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $category = KunenaForumCategory::getInstance($catid);
         $catname = $category->name;
     } elseif (class_exists('KunenaRouter')) {
         if (KunenaRouter::$catidcache === null) {
             KunenaRouter::loadCategories();
         }
         // Kunena 1.6 support
         $catname = empty(KunenaRouter::$catidcache[$catid]) ? '' : KunenaRouter::$catidcache[$catid]['name'];
     } else {
         // Kunena 1.0 / 1.5 support
         if (is_null($cats)) {
             $database =& JFactory::getDBO();
             $query = 'SELECT id, name FROM #__fb_categories';
             $database->setQuery($query);
             if (!shTranslateUrl($option, $shLangName)) {
                 $cats = $database->loadObjectList('id', false);
             } else {
                 $cats = $database->loadObjectList('id');
             }
         }
         $catname = empty($cats[$catid]) ? null : $cats[$catid]->name;
     }
     $shCat = empty($catname) ? $sh_LANG[$shLangIso]['COM_SH404SEF_KU_CATEGORY'] . $sefConfig->replacement . $catid : ($sefConfig->shFbInsertCategoryId ? $catid . $sefConfig->replacement : '') . $catname;
     // if name, put ID only if requested
     return $shCat;
 }
Beispiel #3
0
/**
 * Build SEF URL
 *
 * All SEF URLs are formatted like this:
 *
 * http://site.com/menuitem/1-category-name/10-subject/[view]/[layout]/[param1]-value1/[param2]-value2?param3=value3&param4=value4
 *
 * - If catid exists, category will always be in the first segment
 * - If there is no catid, second segment for message will not be used (param-value: id-10)
 * - [view] and [layout] are the only parameters without value
 * - all other segments (task, id, userid, page, sel) are using param-value format
 *
 * NOTE! Only major variables are using SEF segments
 *
 * @param $query
 * @return segments
 */
function KunenaBuildRoute(&$query) {
	KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__FUNCTION__.'()') : null;

	$segments = array ();

	// If Kunena SEF is not enabled, do nothing
	if (! KunenaRoute::$config->sef) {
		KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__FUNCTION__.'()') : null;
		return $segments;
	}

	// Get menu item
	if (isset ( $query ['Itemid'] )) {
		static $menuitems = array();
		$Itemid = $query ['Itemid'] = (int) $query ['Itemid'];
		if (!isset($menuitems[$Itemid])) {
			$menuitems[$Itemid] = JFactory::getApplication()->getMenu ()->getItem ( $Itemid );
			if (!$menuitems[$Itemid]) {
				// Itemid doesn't exist or is invalid
				unset ($query ['Itemid']);
			}
		}
		$menuitem = $menuitems[$Itemid];
	}

	// Safety check: we need view in order to create SEF URLs
	if (!isset ( $menuitem->query ['view'] ) && empty ( $query ['view'] )) {
		KUNENA_PROFILER ? KunenaProfiler::instance()->start('function '.__FUNCTION__.'()') : null;
		return $segments;
	}

	// Get view for later use (query wins menu item)
	$view = isset ( $query ['view'] ) ? (string) preg_replace( '/[^a-z]/', '', $query ['view'] ) : $menuitem->query ['view'];

	// Get default values for URI variables
	if (isset(KunenaRouter::$views[$view])) {
		$defaults = KunenaRouter::$views[$view];
	}
	// Check all URI variables and remove those which aren't needed
	foreach ( $query as $var => $value ) {
		if (isset ( $defaults [$var] ) && !isset ( $menuitem->query [$var] ) && $value == $defaults [$var] ) {
			// Remove URI variable which has default value
			unset ( $query [$var] );
		} elseif ( isset ( $menuitem->query [$var] ) && $value == $menuitem->query [$var] && $var != 'Itemid' && $var != 'option' ) {
			// Remove URI variable which has the same value as menu item
			unset ( $query [$var] );
		}
	}

	// We may have catid also in the menu item (it will not be in URI)
	$numeric = !empty ( $menuitem->query ['catid'] );

	// Support URIs like: /forum/12-my_category
	if (!empty ( $query ['catid'] ) && ($view == 'category' || $view == 'topic' || $view == 'home')) {
		// TODO: ensure that we have view=categories/category/topic
		$catid = ( int ) $query ['catid'];
		if ($catid) {
			$numeric = true;

			if (KunenaRouter::$catidcache === null) {
				KunenaRouter::loadCategories ();
			}
			if (isset ( KunenaRouter::$catidcache [$catid] )) {
				$catname = KunenaRouter::$catidcache [$catid];
			}
			if (empty ( $catname )) {
				// If category name is empty (or doesn't exist), use numeric catid
				$segments [] = $catid;
			} elseif (KunenaRoute::$config->sefcats && isset(KunenaRouter::$sefviews[$view]) && !KunenaRouter::isCategoryConflict($menuitem, $catid, $catname)) {
				// If there's no naming conflict, we can use category name
				$segments [] = $catname;
			} else {
				// By default use 123-category_name
				$segments [] = "{$catid}-{$catname}";
			}
			// This segment fully defines category view so the variable is no longer needed
			if ($view == 'category') {
				unset ( $query ['view'] );
			}
		}
		unset ( $query ['catid'] );
	}

	// Support URIs like: /forum/12-category/123-topic
	if (!empty ( $query ['id'] ) && $numeric) {
		$id = (int) $query ['id'];
		if ($id) {
			$subject = KunenaRouter::stringURLSafe ( KunenaForumTopicHelper::get($id)->subject );
			if (empty ( $subject )) {
				$segments [] = $id;
			} else {
				$segments [] = "{$id}-{$subject}";
			}
			// This segment fully defines topic view so the variable is no longer needed
			if ($view == 'topic') {
				unset ( $query ['view'] );
			}
		}
		unset ( $query ['id'] );
	} else {
		// No id available, do not use numeric variable for mesid
		$numeric = false;
	}

	// View gets added only when we do not use short URI for category/topic
	if (!empty ( $query ['view'] )) {
		// Use filtered value
		$segments [] = $view;
	}

	// Support URIs like: /forum/12-category/123-topic/reply
	if (!empty ( $query ['layout'] )) {
		// Use filtered value
		$segments [] = (string) preg_replace( '/[^a-z]/', '', $query ['layout'] );
	}

	// Support URIs like: /forum/12-category/123-topic/reply/124
	if (isset ( $query ['mesid'] ) && $numeric) {
		$segments [] = (int) $query ['mesid'];
		unset ( $query ['mesid'] );
	}

	// Support URIs like: /forum/user/128-matias
	if (isset ( $query ['userid'] ) && $view == 'user') {
		$segments [] = (int) $query ['userid'] .'-'.KunenaRouter::stringURLSafe ( KunenaUserHelper::get((int)$query ['userid'])->getName() );
		unset ( $query ['userid'] );
	}

	unset ( $query ['view'], $query ['layout'] );

	// Rest of the known parameters are in var-value form
	foreach ( KunenaRouter::$parsevars as $var=>$dummy ) {
		if (isset ( $query [$var] )) {
			$segments [] = "{$var}-{$query[$var]}";
			unset ( $query [$var] );
		}
	}

	KUNENA_PROFILER ? KunenaProfiler::instance()->stop('function '.__FUNCTION__.'()') : null;
	return $segments;
}