|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package Joomla.Site |
| 4 | + * @subpackage com_contact |
| 5 | + * |
| 6 | + * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved. |
| 7 | + * @license GNU General Public License version 2 or later; see LICENSE.txt |
| 8 | + */ |
| 9 | + |
| 10 | +defined('_JEXEC') or die; |
| 11 | + |
| 12 | +/** |
| 13 | + * Routing class from com_contact |
| 14 | + * |
| 15 | + * @since 3.3 |
| 16 | + */ |
| 17 | +class ContactRouter extends JComponentRouterView |
| 18 | +{ |
| 19 | + public $noIDs = false; |
| 20 | + |
| 21 | + /** |
| 22 | + * Search Component router constructor |
| 23 | + * |
| 24 | + * @param JApplicationCms $app The application object |
| 25 | + * @param JMenu $menu The menu object to work with |
| 26 | + */ |
| 27 | + public function __construct($app = null, $menu = null) |
| 28 | + { |
| 29 | + $categories = new JComponentRouterViewconfiguration('categories'); |
| 30 | + $categories->setKey('id'); |
| 31 | + $this->registerView($categories); |
| 32 | + $category = new JComponentRouterViewconfiguration('category'); |
| 33 | + $category->setKey('id')->setParent($categories, 'catid')->setNestable(); |
| 34 | + $this->registerView($category); |
| 35 | + $contact = new JComponentRouterViewconfiguration('contact'); |
| 36 | + $contact->setKey('id')->setParent($category, 'catid'); |
| 37 | + $this->registerView($contact); |
| 38 | + $this->registerView(new JComponentRouterViewconfiguration('featured')); |
| 39 | + |
| 40 | + parent::__construct($app, $menu); |
| 41 | + |
| 42 | + $this->attachRule(new JComponentRouterRulesMenu($this)); |
| 43 | + $this->attachRule(new JComponentRouterRulesStandard($this)); |
| 44 | + $this->attachRule(new JComponentRouterRulesNomenu($this)); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Method to get the segment(s) for a category |
| 49 | + * |
| 50 | + * @param string $id ID of the category to retrieve the segments for |
| 51 | + * @param array $query The request that is build right now |
| 52 | + * |
| 53 | + * @return array|string The segments of this item |
| 54 | + */ |
| 55 | + public function getCategorySegment($id, $query) |
| 56 | + { |
| 57 | + $category = JCategories::getInstance($this->getName())->get($id); |
| 58 | + |
| 59 | + if ($category) |
| 60 | + { |
| 61 | + $path = array_reverse($category->getPath(), true); |
| 62 | + $path[0] = '1:root'; |
| 63 | + |
| 64 | + if ($this->noIDs) |
| 65 | + { |
| 66 | + foreach ($path as &$segment) |
| 67 | + { |
| 68 | + list($id, $segment) = explode(':', $segment, 2); |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + return $path; |
| 73 | + } |
| 74 | + |
| 75 | + return array(); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Method to get the segment(s) for a category |
| 80 | + * |
| 81 | + * @param string $id ID of the category to retrieve the segments for |
| 82 | + * @param array $query The request that is build right now |
| 83 | + * |
| 84 | + * @return array|string The segments of this item |
| 85 | + */ |
| 86 | + public function getCategoriesSegment($id, $query) |
| 87 | + { |
| 88 | + return $this->getCategorySegment($id, $query); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Method to get the segment(s) for a contact |
| 93 | + * |
| 94 | + * @param string $id ID of the contact to retrieve the segments for |
| 95 | + * @param array $query The request that is build right now |
| 96 | + * |
| 97 | + * @return array|string The segments of this item |
| 98 | + */ |
| 99 | + public function getContactSegment($id, $query) |
| 100 | + { |
| 101 | + if (!strpos($id, ':')) |
| 102 | + { |
| 103 | + $db = JFactory::getDbo(); |
| 104 | + $dbquery = $db->getQuery(true); |
| 105 | + $dbquery->select($dbquery->qn('alias')) |
| 106 | + ->from($dbquery->qn('#__contact_details')) |
| 107 | + ->where('id = ' . $dbquery->q((int) $id)); |
| 108 | + $db->setQuery($dbquery); |
| 109 | + |
| 110 | + $id .= ':' . $db->loadResult(); |
| 111 | + } |
| 112 | + |
| 113 | + if ($this->noIDs) |
| 114 | + { |
| 115 | + list($void, $segment) = explode(':', $id, 2); |
| 116 | + |
| 117 | + return array($void => $segment); |
| 118 | + } |
| 119 | + |
| 120 | + return array((int) $id => $id); |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Method to get the id for a category |
| 125 | + * |
| 126 | + * @param string $segment Segment to retrieve the ID for |
| 127 | + * @param array $query The request that is parsed right now |
| 128 | + * |
| 129 | + * @return mixed The id of this item or false |
| 130 | + */ |
| 131 | + public function getCategoryId($segment, $query) |
| 132 | + { |
| 133 | + if (isset($query['id'])) |
| 134 | + { |
| 135 | + $category = JCategories::getInstance($this->getName())->get($query['id']); |
| 136 | + |
| 137 | + foreach ($category->getChildren() as $child) |
| 138 | + { |
| 139 | + if ($this->noIDs) |
| 140 | + { |
| 141 | + if ($child->alias == $segment) |
| 142 | + { |
| 143 | + return $child->id; |
| 144 | + } |
| 145 | + } |
| 146 | + else |
| 147 | + { |
| 148 | + if ($child->id == (int) $segment) |
| 149 | + { |
| 150 | + return $child->id; |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + |
| 156 | + return false; |
| 157 | + } |
| 158 | + |
| 159 | + /** |
| 160 | + * Method to get the segment(s) for a category |
| 161 | + * |
| 162 | + * @param string $segment Segment to retrieve the ID for |
| 163 | + * @param array $query The request that is parsed right now |
| 164 | + * |
| 165 | + * @return mixed The id of this item or false |
| 166 | + */ |
| 167 | + public function getCategoriesId($segment, $query) |
| 168 | + { |
| 169 | + return $this->getCategoryId($segment, $query); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * Method to get the segment(s) for a contact |
| 174 | + * |
| 175 | + * @param string $segment Segment of the contact to retrieve the ID for |
| 176 | + * @param array $query The request that is parsed right now |
| 177 | + * |
| 178 | + * @return mixed The id of this item or false |
| 179 | + */ |
| 180 | + public function getContactId($segment, $query) |
| 181 | + { |
| 182 | + if ($this->noIDs) |
| 183 | + { |
| 184 | + $db = JFactory::getDbo(); |
| 185 | + $dbquery = $db->getQuery(true); |
| 186 | + $dbquery->select($dbquery->qn('id')) |
| 187 | + ->from($dbquery->qn('#__contact_details')) |
| 188 | + ->where('alias = ' . $dbquery->q($segment)) |
| 189 | + ->where('catid = ' . $dbquery->q($query['id'])); |
| 190 | + $db->setQuery($dbquery); |
| 191 | + |
| 192 | + return (int) $db->loadResult(); |
| 193 | + } |
| 194 | + |
| 195 | + return (int) $segment; |
| 196 | + } |
| 197 | +} |
| 198 | + |
| 199 | +/** |
| 200 | + * Contact router functions |
| 201 | + * |
| 202 | + * These functions are proxys for the new router interface |
| 203 | + * for old SEF extensions. |
| 204 | + * |
| 205 | + * @param array &$query An array of URL arguments |
| 206 | + * |
| 207 | + * @return array The URL arguments to use to assemble the subsequent URL. |
| 208 | + * |
| 209 | + * @deprecated 4.0 Use Class based routers instead |
| 210 | + */ |
| 211 | +function ContactBuildRoute(&$query) |
| 212 | +{ |
| 213 | + $app = JFactory::getApplication(); |
| 214 | + $router = new ContactRouter($app, $app->getMenu()); |
| 215 | + |
| 216 | + return $router->build($query); |
| 217 | +} |
| 218 | + |
| 219 | +/** |
| 220 | + * Contact router functions |
| 221 | + * |
| 222 | + * These functions are proxys for the new router interface |
| 223 | + * for old SEF extensions. |
| 224 | + * |
| 225 | + * @param array $segments The segments of the URL to parse. |
| 226 | + * |
| 227 | + * @return array The URL attributes to be used by the application. |
| 228 | + * |
| 229 | + * @deprecated 4.0 Use Class based routers instead |
| 230 | + */ |
| 231 | +function ContactParseRoute($segments) |
| 232 | +{ |
| 233 | + $app = JFactory::getApplication(); |
| 234 | + $router = new ContactRouter($app, $app->getMenu()); |
| 235 | + |
| 236 | + return $router->parse($segments); |
| 237 | +} |
0 commit comments