[ 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_languages 6 * 7 * @copyright (C) 2011 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\Languages\Administrator\Helper; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\LanguageHelper; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Log\Log; 17 use Joomla\Registry\Registry; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Multilang status helper. 25 * 26 * @since 1.7.1 27 */ 28 abstract class MultilangstatusHelper 29 { 30 /** 31 * Method to get the number of published home pages. 32 * 33 * @return integer 34 */ 35 public static function getHomes() 36 { 37 // Check for multiple Home pages. 38 $db = Factory::getDbo(); 39 $query = $db->getQuery(true) 40 ->select('COUNT(*)') 41 ->from($db->quoteName('#__menu')) 42 ->where( 43 [ 44 $db->quoteName('home') . ' = 1', 45 $db->quoteName('published') . ' = 1', 46 $db->quoteName('client_id') . ' = 0', 47 ] 48 ); 49 50 $db->setQuery($query); 51 52 return $db->loadResult(); 53 } 54 55 /** 56 * Method to get the number of published language switcher modules. 57 * 58 * @return integer 59 */ 60 public static function getLangswitchers() 61 { 62 // Check if switcher is published. 63 $db = Factory::getDbo(); 64 $query = $db->getQuery(true) 65 ->select('COUNT(*)') 66 ->from($db->quoteName('#__modules')) 67 ->where( 68 [ 69 $db->quoteName('module') . ' = ' . $db->quote('mod_languages'), 70 $db->quoteName('published') . ' = 1', 71 $db->quoteName('client_id') . ' = 0', 72 ] 73 ); 74 75 $db->setQuery($query); 76 77 return $db->loadResult(); 78 } 79 80 /** 81 * Method to return a list of published content languages. 82 * 83 * @return array of language objects. 84 */ 85 public static function getContentlangs() 86 { 87 // Check for published Content Languages. 88 $db = Factory::getDbo(); 89 $query = $db->getQuery(true) 90 ->select( 91 [ 92 $db->quoteName('lang_code'), 93 $db->quoteName('published'), 94 $db->quoteName('sef'), 95 ] 96 ) 97 ->from($db->quoteName('#__languages')); 98 99 $db->setQuery($query); 100 101 return $db->loadObjectList(); 102 } 103 104 /** 105 * Method to return combined language status. 106 * 107 * @return array of language objects. 108 */ 109 public static function getStatus() 110 { 111 // Check for combined status. 112 $db = Factory::getDbo(); 113 $query = $db->getQuery(true); 114 115 // Select all fields from the languages table. 116 $query->select( 117 [ 118 $db->quoteName('a') . '.*', 119 $db->quoteName('a.published'), 120 $db->quoteName('a.lang_code'), 121 $db->quoteName('e.enabled'), 122 $db->quoteName('e.element'), 123 $db->quoteName('l.home'), 124 $db->quoteName('l.published', 'home_published'), 125 ] 126 ) 127 ->from($db->quoteName('#__languages', 'a')) 128 ->join( 129 'LEFT', 130 $db->quoteName('#__menu', 'l'), 131 $db->quoteName('l.language') . ' = ' . $db->quoteName('a.lang_code') 132 . ' AND ' . $db->quoteName('l.home') . ' = 1 AND ' . $db->quoteName('l.language') . ' <> ' . $db->quote('*') 133 ) 134 ->join('LEFT', $db->quoteName('#__extensions', 'e'), $db->quoteName('e.element') . ' = ' . $db->quoteName('a.lang_code')) 135 ->where( 136 [ 137 $db->quoteName('e.client_id') . ' = 0', 138 $db->quoteName('e.enabled') . ' = 1', 139 $db->quoteName('e.state') . ' = 0', 140 ] 141 ); 142 143 $db->setQuery($query); 144 145 return $db->loadObjectList(); 146 } 147 148 /** 149 * Method to return a list of contact objects. 150 * 151 * @return array of contact objects. 152 */ 153 public static function getContacts() 154 { 155 $db = Factory::getDbo(); 156 $languages = count(LanguageHelper::getLanguages()); 157 158 // Get the number of contact with all as language 159 $alang = $db->getQuery(true) 160 ->select('COUNT(*)') 161 ->from($db->quoteName('#__contact_details', 'cd')) 162 ->where( 163 [ 164 $db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'), 165 $db->quoteName('cd.published') . ' = 1', 166 $db->quoteName('cd.language') . ' = ' . $db->quote('*'), 167 ] 168 ); 169 170 // Get the number of languages for the contact 171 $slang = $db->getQuery(true) 172 ->select('COUNT(DISTINCT ' . $db->quoteName('l.lang_code') . ')') 173 ->from($db->quoteName('#__languages', 'l')) 174 ->join('LEFT', $db->quoteName('#__contact_details', 'cd'), $db->quoteName('cd.language') . ' = ' . $db->quoteName('l.lang_code')) 175 ->where( 176 [ 177 $db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'), 178 $db->quoteName('cd.published') . ' = 1', 179 $db->quoteName('l.published') . ' = 1', 180 ] 181 ); 182 183 // Get the number of multiple contact/language 184 $mlang = $db->getQuery(true) 185 ->select('COUNT(*)') 186 ->from($db->quoteName('#__languages', 'l')) 187 ->join('LEFT', $db->quoteName('#__contact_details', 'cd'), $db->quoteName('cd.language') . ' = ' . $db->quoteName('l.lang_code')) 188 ->where( 189 [ 190 $db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id'), 191 $db->quoteName('cd.published') . ' = 1', 192 $db->quoteName('l.published') . ' = 1', 193 ] 194 ) 195 ->group($db->quoteName('l.lang_code')) 196 ->having('COUNT(*) > 1'); 197 198 // Get the contacts 199 $subQuery = $db->getQuery(true) 200 ->select('1') 201 ->from($db->quoteName('#__content', 'c')) 202 ->where($db->quoteName('c.created_by') . ' = ' . $db->quoteName('u.id')); 203 204 $query = $db->getQuery(true) 205 ->select( 206 [ 207 $db->quoteName('u.name'), 208 '(' . $alang . ') AS ' . $db->quoteName('alang'), 209 '(' . $slang . ') AS ' . $db->quoteName('slang'), 210 '(' . $mlang . ') AS ' . $db->quoteName('mlang'), 211 ] 212 ) 213 ->from($db->quoteName('#__users', 'u')) 214 ->join('LEFT', $db->quoteName('#__contact_details', 'cd'), $db->quoteName('cd.user_id') . ' = ' . $db->quoteName('u.id')) 215 ->where('EXISTS (' . $subQuery . ')') 216 ->group( 217 [ 218 $db->quoteName('u.id'), 219 $db->quoteName('u.name'), 220 ] 221 ); 222 223 $db->setQuery($query); 224 $warnings = $db->loadObjectList(); 225 226 foreach ($warnings as $index => $warn) { 227 if ($warn->alang == 1 && $warn->slang == 0) { 228 unset($warnings[$index]); 229 } 230 231 if ($warn->alang == 0 && $warn->slang == 0 && empty($warn->mlang)) { 232 unset($warnings[$index]); 233 } 234 235 if ($warn->alang == 0 && $warn->slang == $languages && empty($warn->mlang)) { 236 unset($warnings[$index]); 237 } 238 } 239 240 return $warnings; 241 } 242 243 /** 244 * Method to get the status of the module displaying the menutype of the default Home page set to All languages. 245 * 246 * @return boolean True if the module is published, false otherwise. 247 * 248 * @since 3.7.0 249 */ 250 public static function getDefaultHomeModule() 251 { 252 // Find Default Home menutype. 253 $db = Factory::getDbo(); 254 $query = $db->getQuery(true) 255 ->select($db->quoteName('menutype')) 256 ->from($db->quoteName('#__menu')) 257 ->where( 258 [ 259 $db->quoteName('home') . ' = 1', 260 $db->quoteName('published') . ' = 1', 261 $db->quoteName('client_id') . ' = 0', 262 $db->quoteName('language') . ' = ' . $db->quote('*'), 263 ] 264 ); 265 266 $db->setQuery($query); 267 268 $menutype = $db->loadResult(); 269 270 // Get published site menu modules titles. 271 $query->clear() 272 ->select($db->quoteName('title')) 273 ->from($db->quoteName('#__modules')) 274 ->where( 275 [ 276 $db->quoteName('module') . ' = ' . $db->quote('mod_menu'), 277 $db->quoteName('published') . ' = 1', 278 $db->quoteName('client_id') . ' = 0', 279 ] 280 ); 281 282 $db->setQuery($query); 283 284 $menutitles = $db->loadColumn(); 285 286 // Do we have a published menu module displaying the default Home menu item set to all languages? 287 foreach ($menutitles as $menutitle) { 288 $module = self::getModule('mod_menu', $menutitle); 289 $moduleParams = new Registry($module->params); 290 $param = $moduleParams->get('menutype', ''); 291 292 if ($param && $param != $menutype) { 293 continue; 294 } 295 296 return true; 297 } 298 } 299 300 /** 301 * Get module by name 302 * 303 * @param string $moduleName The name of the module 304 * @param string $instanceTitle The title of the module, optional 305 * 306 * @return \stdClass The Module object 307 * 308 * @since 3.7.0 309 */ 310 public static function getModule($moduleName, $instanceTitle = null) 311 { 312 $db = Factory::getDbo(); 313 314 $query = $db->getQuery(true) 315 ->select( 316 [ 317 $db->quoteName('id'), 318 $db->quoteName('title'), 319 $db->quoteName('module'), 320 $db->quoteName('position'), 321 $db->quoteName('content'), 322 $db->quoteName('showtitle'), 323 $db->quoteName('params'), 324 ] 325 ) 326 ->from($db->quoteName('#__modules')) 327 ->where( 328 [ 329 $db->quoteName('module') . ' = :module', 330 $db->quoteName('published') . ' = 1', 331 $db->quoteName('client_id') . ' = 0', 332 ] 333 ) 334 ->bind(':module', $moduleName); 335 336 if ($instanceTitle) { 337 $query->where($db->quoteName('title') . ' = :title') 338 ->bind(':title', $instanceTitle); 339 } 340 341 $db->setQuery($query); 342 343 try { 344 $modules = $db->loadObject(); 345 } catch (\RuntimeException $e) { 346 Log::add(Text::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $e->getMessage()), Log::WARNING, 'jerror'); 347 } 348 349 return $modules; 350 } 351 }
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 |