Last active
December 17, 2015 21:58
-
-
Save joomdonation/5678158 to your computer and use it in GitHub Desktop.
SEF router plugin for EDocman extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @version 1.5.2 | |
| * @package Joomla | |
| * @subpackage Edocman | |
| * @author Tuan Pham Ngoc | |
| * @copyright Copyright (C) 2011 Ossolution Team | |
| * @license GNU/GPL, see LICENSE.php | |
| */ | |
| defined('_JEXEC') or die(); | |
| /** | |
| * Build the route for the com_edocman component | |
| * | |
| * @param array An array of URL arguments | |
| * @return array The URL arguments to use to assemble the subsequent URL. | |
| * @since 1.5 | |
| */ | |
| function EdocmanBuildRoute(&$query) | |
| { | |
| $db = JFactory::getDbo(); | |
| $queryArr = $query; | |
| if (isset($queryArr['option'])) | |
| unset($queryArr['option']); | |
| if (isset($queryArr['Itemid'])) | |
| unset($queryArr['Itemid']); | |
| //Store the query string to use in the parseRouter method | |
| $queryString = http_build_query($queryArr); | |
| $segments = array(); | |
| $view = isset($query['view']) ? $query['view'] : ''; | |
| $task = isset($query['task']) ? $query['task'] : ''; | |
| $id = isset($query['id']) ? (int) $query['id'] : 0; | |
| switch ($view) | |
| { | |
| case 'categories': | |
| case 'category' : | |
| if ($id) | |
| $segments = array_merge( $segments, EdocmanHelper::getCategoryArray($id)); | |
| $segments[] = JText::_('EDOCMAN_SEF_VIEW_CAT'); | |
| break; | |
| case 'document' : | |
| if ($id) { | |
| $segments[] = EdocmanHelper::getDocumentTitle($id); | |
| } | |
| break ; | |
| } | |
| switch ($task) | |
| { | |
| case 'document.download' : | |
| case 'document.viewdoc' : | |
| case 'document.edit': | |
| if ($id) { | |
| $segments[] = EdocmanHelper::getDocumentTitle($id); | |
| } | |
| $languageItem = 'EDOCMAN_SEF_'.strtoupper(implode('_', explode('.', $task))) ; | |
| $segments[] = JText::_($languageItem); | |
| break ; | |
| } | |
| if (isset($query['task'])) | |
| { | |
| unset($query['task']); | |
| } | |
| if (isset($query['view'])) | |
| { | |
| unset($query['view']); | |
| } | |
| if (isset($query['id'])) | |
| { | |
| unset($query['id']); | |
| } | |
| if (count($segments)) | |
| { | |
| $segments = array_map('JApplication::stringURLSafe', $segments); | |
| $key = md5(implode('/', $segments)); | |
| $q = $db->getQuery(true); | |
| $q->select('COUNT(*)') | |
| ->from('#__edocman_urls') | |
| ->where('md5_key="'.$key.'"') | |
| ; | |
| $db->setQuery($q); | |
| $total = $db->loadResult(); | |
| if (!$total) | |
| { | |
| $q->clear(); | |
| $q->insert('#__edocman_urls') | |
| ->columns('md5_key, `query`') | |
| ->values("'$key', '$queryString'"); | |
| $db->setQuery($q); | |
| $db->query(); | |
| } | |
| } | |
| return $segments; | |
| } | |
| /** | |
| * Parse the segments of a URL. | |
| * | |
| * @param array The segments of the URL to parse. | |
| * | |
| * @return array The URL attributes to be used by the application. | |
| * @since 1.5 | |
| */ | |
| function EdocmanParseRoute($segments) | |
| { | |
| $vars = array(); | |
| if (count($segments)) | |
| { | |
| $db = JFactory::getDbo(); | |
| $key = md5(str_replace(':', '-', implode('/', $segments))); | |
| $query = $db->getQuery(true); | |
| $query->select('`query`') | |
| ->from('#__edocman_urls') | |
| ->where('md5_key="'.$key.'"'); | |
| $db->setQuery($query); | |
| $queryString = $db->loadResult(); | |
| if ($queryString) | |
| parse_str($queryString, $vars); | |
| } | |
| return $vars; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment