[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_admin 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Admin\Administrator\Model; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Filesystem\Folder; 15 use Joomla\CMS\Help\Help; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\MVC\Model\BaseDatabaseModel; 18 use Joomla\String\StringHelper; 19 20 // phpcs:disable PSR1.Files.SideEffects 21 \defined('_JEXEC') or die; 22 // phpcs:enable PSR1.Files.SideEffects 23 24 /** 25 * Admin Component Help Model 26 * 27 * @since 1.6 28 */ 29 class HelpModel extends BaseDatabaseModel 30 { 31 /** 32 * The search string 33 * 34 * @var string 35 * @since 1.6 36 */ 37 protected $help_search = null; 38 39 /** 40 * The page to be viewed 41 * 42 * @var string 43 * @since 1.6 44 */ 45 protected $page = null; 46 47 /** 48 * The ISO language tag 49 * 50 * @var string 51 * @since 1.6 52 */ 53 protected $lang_tag = null; 54 55 /** 56 * Table of contents 57 * 58 * @var array 59 * @since 1.6 60 */ 61 protected $toc = null; 62 63 /** 64 * URL for the latest version check 65 * 66 * @var string 67 * @since 1.6 68 */ 69 protected $latest_version_check = null; 70 71 /** 72 * Method to get the help search string 73 * 74 * @return string Help search string 75 * 76 * @since 1.6 77 */ 78 public function &getHelpSearch() 79 { 80 if (\is_null($this->help_search)) { 81 $this->help_search = Factory::getApplication()->input->getString('helpsearch'); 82 } 83 84 return $this->help_search; 85 } 86 87 /** 88 * Method to get the page 89 * 90 * @return string The page 91 * 92 * @since 1.6 93 */ 94 public function &getPage() 95 { 96 if (\is_null($this->page)) { 97 $this->page = Help::createUrl(Factory::getApplication()->input->get('page', 'Start_Here')); 98 } 99 100 return $this->page; 101 } 102 103 /** 104 * Method to get the lang tag 105 * 106 * @return string lang iso tag 107 * 108 * @since 1.6 109 */ 110 public function getLangTag() 111 { 112 if (\is_null($this->lang_tag)) { 113 $this->lang_tag = Factory::getLanguage()->getTag(); 114 115 if (!is_dir(JPATH_BASE . '/help/' . $this->lang_tag)) { 116 // Use English as fallback 117 $this->lang_tag = 'en-GB'; 118 } 119 } 120 121 return $this->lang_tag; 122 } 123 124 /** 125 * Method to get the table of contents 126 * 127 * @return array Table of contents 128 */ 129 public function &getToc() 130 { 131 if (!\is_null($this->toc)) { 132 return $this->toc; 133 } 134 135 // Get vars 136 $lang_tag = $this->getLangTag(); 137 $help_search = $this->getHelpSearch(); 138 139 // New style - Check for a TOC \JSON file 140 if (file_exists(JPATH_BASE . '/help/' . $lang_tag . '/toc.json')) { 141 $data = json_decode(file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/toc.json')); 142 143 // Loop through the data array 144 foreach ($data as $key => $value) { 145 $this->toc[$key] = Text::_('COM_ADMIN_HELP_' . $value); 146 } 147 148 // Sort the Table of Contents 149 asort($this->toc); 150 151 return $this->toc; 152 } 153 154 // Get Help files 155 $files = Folder::files(JPATH_BASE . '/help/' . $lang_tag, '\.xml$|\.html$'); 156 $this->toc = array(); 157 158 foreach ($files as $file) { 159 $buffer = file_get_contents(JPATH_BASE . '/help/' . $lang_tag . '/' . $file); 160 161 if (!preg_match('#<title>(.*?)</title>#', $buffer, $m)) { 162 continue; 163 } 164 165 $title = trim($m[1]); 166 167 if (!$title) { 168 continue; 169 } 170 171 // Translate the page title 172 $title = Text::_($title); 173 174 // Strip the extension 175 $file = preg_replace('#\.xml$|\.html$#', '', $file); 176 177 if ($help_search && StringHelper::strpos(StringHelper::strtolower(strip_tags($buffer)), StringHelper::strtolower($help_search)) === false) { 178 continue; 179 } 180 181 // Add an item in the Table of Contents 182 $this->toc[$file] = $title; 183 } 184 185 // Sort the Table of Contents 186 asort($this->toc); 187 188 return $this->toc; 189 } 190 }
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 |