[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\Application; 11 12 use Joomla\CMS\Component\ComponentHelper; 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Filter\OutputFilter; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * Application helper functions 22 * 23 * @since 1.5 24 */ 25 class ApplicationHelper 26 { 27 /** 28 * Client information array 29 * 30 * @var array 31 * @since 1.6 32 */ 33 protected static $_clients = array(); 34 35 /** 36 * Return the name of the request component [main component] 37 * 38 * @param string $default The default option 39 * 40 * @return string Option (e.g. com_something) 41 * 42 * @since 1.6 43 */ 44 public static function getComponentName($default = null) 45 { 46 static $option; 47 48 if ($option) { 49 return $option; 50 } 51 52 $input = Factory::getApplication()->input; 53 $option = strtolower($input->get('option', '')); 54 55 if (empty($option)) { 56 $option = $default; 57 } 58 59 $input->set('option', $option); 60 61 return $option; 62 } 63 64 /** 65 * Provides a secure hash based on a seed 66 * 67 * @param string $seed Seed string. 68 * 69 * @return string A secure hash 70 * 71 * @since 3.2 72 */ 73 public static function getHash($seed) 74 { 75 return md5(Factory::getApplication()->get('secret') . $seed); 76 } 77 78 /** 79 * This method transliterates a string into a URL 80 * safe string or returns a URL safe UTF-8 string 81 * based on the global configuration 82 * 83 * @param string $string String to process 84 * @param string $language Language to transliterate to if unicode slugs are disabled 85 * 86 * @return string Processed string 87 * 88 * @since 3.2 89 */ 90 public static function stringURLSafe($string, $language = '') 91 { 92 if (Factory::getApplication()->get('unicodeslugs') == 1) { 93 $output = OutputFilter::stringUrlUnicodeSlug($string); 94 } else { 95 if ($language === '*' || $language === '') { 96 $languageParams = ComponentHelper::getParams('com_languages'); 97 $language = $languageParams->get('site'); 98 } 99 100 $output = OutputFilter::stringURLSafe($string, $language); 101 } 102 103 return $output; 104 } 105 106 /** 107 * Gets information on a specific client id. This method will be useful in 108 * future versions when we start mapping applications in the database. 109 * 110 * This method will return a client information array if called 111 * with no arguments which can be used to add custom application information. 112 * 113 * @param integer|string|null $id A client identifier 114 * @param boolean $byName If true, find the client by its name 115 * 116 * @return \stdClass|array|void Object describing the client, array containing all the clients or void if $id not known 117 * 118 * @since 1.5 119 */ 120 public static function getClientInfo($id = null, $byName = false) 121 { 122 // Only create the array if it is empty 123 if (empty(self::$_clients)) { 124 $obj = new \stdClass(); 125 126 // Site Client 127 $obj->id = 0; 128 $obj->name = 'site'; 129 $obj->path = JPATH_SITE; 130 self::$_clients[0] = clone $obj; 131 132 // Administrator Client 133 $obj->id = 1; 134 $obj->name = 'administrator'; 135 $obj->path = JPATH_ADMINISTRATOR; 136 self::$_clients[1] = clone $obj; 137 138 // Installation Client 139 $obj->id = 2; 140 $obj->name = 'installation'; 141 $obj->path = JPATH_INSTALLATION; 142 self::$_clients[2] = clone $obj; 143 144 // API Client 145 $obj->id = 3; 146 $obj->name = 'api'; 147 $obj->path = JPATH_API; 148 self::$_clients[3] = clone $obj; 149 150 // CLI Client 151 $obj->id = 4; 152 $obj->name = 'cli'; 153 $obj->path = JPATH_CLI; 154 self::$_clients[4] = clone $obj; 155 } 156 157 // If no client id has been passed return the whole array 158 if ($id === null) { 159 return self::$_clients; 160 } 161 162 // Are we looking for client information by id or by name? 163 if (!$byName) { 164 if (isset(self::$_clients[$id])) { 165 return self::$_clients[$id]; 166 } 167 } else { 168 foreach (self::$_clients as $client) { 169 if ($client->name == strtolower($id)) { 170 return $client; 171 } 172 } 173 } 174 } 175 176 /** 177 * Adds information for a client. 178 * 179 * @param mixed $client A client identifier either an array or object 180 * 181 * @return boolean True if the information is added. False on error 182 * 183 * @since 1.6 184 */ 185 public static function addClientInfo($client) 186 { 187 if (\is_array($client)) { 188 $client = (object) $client; 189 } 190 191 if (!\is_object($client)) { 192 return false; 193 } 194 195 $info = self::getClientInfo(); 196 197 if (!isset($client->id)) { 198 $client->id = \count($info); 199 } 200 201 self::$_clients[$client->id] = clone $client; 202 203 return true; 204 } 205 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |