[ 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) 2005 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\Installer\Adapter; 11 12 use Joomla\CMS\Application\ApplicationHelper; 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Filesystem\Folder; 16 use Joomla\CMS\Filter\InputFilter; 17 use Joomla\CMS\Installer\Installer; 18 use Joomla\CMS\Installer\InstallerAdapter; 19 use Joomla\CMS\Language\Language; 20 use Joomla\CMS\Language\LanguageHelper; 21 use Joomla\CMS\Language\Text; 22 use Joomla\CMS\Log\Log; 23 use Joomla\CMS\Table\Table; 24 use Joomla\CMS\Table\Update; 25 use Joomla\Database\ParameterType; 26 use Joomla\Registry\Registry; 27 28 // phpcs:disable PSR1.Files.SideEffects 29 \defined('JPATH_PLATFORM') or die; 30 // phpcs:enable PSR1.Files.SideEffects 31 32 /** 33 * Language installer 34 * 35 * @since 3.1 36 */ 37 class LanguageAdapter extends InstallerAdapter 38 { 39 /** 40 * Core language pack flag 41 * 42 * @var boolean 43 * @since 3.0.0 44 */ 45 protected $core = false; 46 47 /** 48 * The language tag for the package 49 * 50 * @var string 51 * @since 4.0.0 52 */ 53 protected $tag; 54 55 /** 56 * Flag indicating the uninstall process should not run SQL queries 57 * 58 * @var boolean 59 * @since 4.0.0 60 */ 61 protected $ignoreUninstallQueries = false; 62 63 /** 64 * Method to copy the extension's base files from the `<files>` tag(s) and the manifest file 65 * 66 * @return void 67 * 68 * @since 3.4 69 * @throws \RuntimeException 70 */ 71 protected function copyBaseFiles() 72 { 73 // @todo - Refactor adapter to use common code 74 } 75 76 /** 77 * Method to finalise the installation processing 78 * 79 * @return void 80 * 81 * @since 4.0.0 82 * @throws \RuntimeException 83 */ 84 protected function finaliseInstall() 85 { 86 // @todo - Refactor adapter to use common code 87 } 88 89 /** 90 * Method to finalise the uninstallation processing 91 * 92 * @return boolean 93 * 94 * @since 4.0.0 95 * @throws \RuntimeException 96 */ 97 protected function finaliseUninstall(): bool 98 { 99 if ($this->ignoreUninstallQueries) { 100 return false; 101 } 102 103 $this->resetUserLanguage(); 104 105 $extensionId = $this->extension->extension_id; 106 107 // Remove the schema version 108 $db = $this->getDatabase(); 109 $query = $db->getQuery(true) 110 ->delete($db->quoteName('#__schemas')) 111 ->where($db->quoteName('extension_id') . ' = :extension_id') 112 ->bind(':extension_id', $extensionId, ParameterType::INTEGER); 113 $db->setQuery($query); 114 $db->execute(); 115 116 // Clobber any possible pending updates 117 $update = Table::getInstance('update'); 118 $uid = $update->find( 119 [ 120 'element' => $this->extension->element, 121 'type' => $this->type, 122 ] 123 ); 124 125 if ($uid) { 126 $update->delete($uid); 127 } 128 129 // Clean installed languages cache. 130 Factory::getCache()->clean('com_languages'); 131 132 // Remove the extension table entry 133 $this->extension->delete(); 134 135 return true; 136 } 137 138 /** 139 * Removes this extension's files 140 * 141 * @return void 142 * 143 * @since 4.0.0 144 * @throws \RuntimeException 145 */ 146 protected function removeExtensionFiles() 147 { 148 $this->parent->removeFiles($this->getManifest()->media); 149 150 // Construct the path from the client, the language and the extension element name 151 $path = ApplicationHelper::getClientInfo($this->extension->client_id)->path . '/language/' . $this->extension->element; 152 153 if (!Folder::delete($path)) { 154 // If deleting failed we'll leave the extension entry in tact just in case 155 Log::add(Text::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DIRECTORY'), Log::WARNING, 'jerror'); 156 157 $this->ignoreUninstallQueries = true; 158 } 159 } 160 161 /** 162 * Method to do any prechecks and setup the install paths for the extension 163 * 164 * @return void 165 * 166 * @since 3.4 167 */ 168 protected function setupInstallPaths() 169 { 170 // @todo - Refactor adapter to use common code 171 } 172 173 /** 174 * Method to do any prechecks and setup the uninstall job 175 * 176 * @return void 177 * 178 * @since 4.0.0 179 */ 180 protected function setupUninstall() 181 { 182 // Grab a copy of the client details 183 $client = ApplicationHelper::getClientInfo($this->extension->client_id); 184 185 // Check the element isn't blank to prevent nuking the languages directory...just in case 186 if (empty($this->extension->element)) { 187 throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_ELEMENT_EMPTY')); 188 } 189 190 // Verify that it's not the default language for that client 191 $params = ComponentHelper::getParams('com_languages'); 192 193 if ($params->get($client->name) === $this->extension->element) { 194 throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_DEFAULT')); 195 } 196 197 // Construct the path from the client, the language and the extension element name 198 $path = $client->path . '/language/' . $this->extension->element; 199 200 // Get the package manifest object and remove media 201 $this->parent->setPath('source', $path); 202 203 // Check it exists 204 if (!Folder::exists($path)) { 205 // If the folder doesn't exist lets just nuke the row as well and presume the user killed it for us 206 $this->extension->delete(); 207 208 throw new \RuntimeException(Text::_('JLIB_INSTALLER_ERROR_LANG_UNINSTALL_PATH_EMPTY')); 209 } 210 211 // We do findManifest to avoid problem when uninstalling a list of extension: getManifest cache its manifest file 212 $this->parent->findManifest(); 213 $this->setManifest($this->parent->getManifest()); 214 } 215 216 /** 217 * Method to store the extension to the database 218 * 219 * @return void 220 * 221 * @since 3.4 222 * @throws \RuntimeException 223 */ 224 protected function storeExtension() 225 { 226 // @todo - Refactor adapter to use common code 227 } 228 229 /** 230 * Custom install method 231 * 232 * Note: This behaves badly due to hacks made in the middle of 1.5.x to add 233 * the ability to install multiple distinct packs in one install. The 234 * preferred method is to use a package to install multiple language packs. 235 * 236 * @return boolean|integer The extension ID on success, boolean false on failure 237 * 238 * @since 3.1 239 */ 240 public function install() 241 { 242 $source = $this->parent->getPath('source'); 243 244 if (!$source) { 245 $this->parent 246 ->setPath( 247 'source', 248 ApplicationHelper::getClientInfo($this->parent->extension->client_id)->path . '/language/' . $this->parent->extension->element 249 ); 250 } 251 252 $this->setManifest($this->parent->getManifest()); 253 254 // Get the client application target 255 if ($cname = (string) $this->getManifest()->attributes()->client) { 256 // Attempt to map the client to a base path 257 $client = ApplicationHelper::getClientInfo($cname, true); 258 259 if ($client === null) { 260 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_UNKNOWN_CLIENT_TYPE', $cname))); 261 262 return false; 263 } 264 265 $basePath = $client->path; 266 $clientId = $client->id; 267 $element = $this->getManifest()->files; 268 269 return $this->_install($cname, $basePath, $clientId, $element); 270 } else { 271 // No client attribute was found so we assume the site as the client 272 $cname = 'site'; 273 $basePath = JPATH_SITE; 274 $clientId = 0; 275 $element = $this->getManifest()->files; 276 277 return $this->_install($cname, $basePath, $clientId, $element); 278 } 279 } 280 281 /** 282 * Install function that is designed to handle individual clients 283 * 284 * @param string $cname Cname @todo: not used 285 * @param string $basePath The base name. 286 * @param integer $clientId The client id. 287 * @param object &$element The XML element. 288 * 289 * @return boolean|integer The extension ID on success, boolean false on failure 290 * 291 * @since 3.1 292 */ 293 protected function _install($cname, $basePath, $clientId, &$element) 294 { 295 $this->setManifest($this->parent->getManifest()); 296 297 // Get the language name 298 // Set the extensions name 299 $this->name = InputFilter::getInstance()->clean((string) $this->getManifest()->name, 'string'); 300 301 // Get the Language tag [ISO tag, eg. en-GB] 302 $tag = (string) $this->getManifest()->tag; 303 304 // Check if we found the tag - if we didn't, we may be trying to install from an older language package 305 if (!$tag) { 306 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::_('JLIB_INSTALLER_ERROR_NO_LANGUAGE_TAG'))); 307 308 return false; 309 } 310 311 $this->tag = $tag; 312 313 // Set the language installation path 314 $this->parent->setPath('extension_site', $basePath . '/language/' . $tag); 315 316 // Do we have a meta file in the file list? In other words... is this a core language pack? 317 if ($element && \count($element->children())) { 318 $files = $element->children(); 319 320 foreach ($files as $file) { 321 if ((string) $file->attributes()->file === 'meta') { 322 $this->core = true; 323 break; 324 } 325 } 326 } 327 328 // If the language directory does not exist, let's create it 329 $created = false; 330 331 if (!file_exists($this->parent->getPath('extension_site'))) { 332 if (!$created = Folder::create($this->parent->getPath('extension_site'))) { 333 $this->parent 334 ->abort( 335 Text::sprintf( 336 'JLIB_INSTALLER_ABORT', 337 Text::sprintf('JLIB_INSTALLER_ERROR_CREATE_FOLDER_FAILED', $this->parent->getPath('extension_site')) 338 ) 339 ); 340 341 return false; 342 } 343 } else { 344 // Look for an update function or update tag 345 $updateElement = $this->getManifest()->update; 346 347 // Upgrade manually set or update tag detected 348 if ($updateElement || $this->parent->isUpgrade()) { 349 // Transfer control to the update function 350 return $this->update(); 351 } elseif (!$this->parent->isOverwrite()) { 352 // Overwrite is set 353 // We didn't have overwrite set, find an update function or find an update tag so lets call it safe 354 if (file_exists($this->parent->getPath('extension_site'))) { 355 // If the site exists say so. 356 Log::add( 357 Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_site'))), 358 Log::WARNING, 359 'jerror' 360 ); 361 } elseif (file_exists($this->parent->getPath('extension_administrator'))) { 362 // If the admin exists say so. 363 Log::add( 364 Text::sprintf( 365 'JLIB_INSTALLER_ABORT', 366 Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_administrator')) 367 ), 368 Log::WARNING, 369 'jerror' 370 ); 371 } else { 372 // If the api exists say so. 373 Log::add( 374 Text::sprintf( 375 'JLIB_INSTALLER_ABORT', 376 Text::sprintf('JLIB_INSTALLER_ERROR_FOLDER_IN_USE', $this->parent->getPath('extension_api')) 377 ), 378 Log::WARNING, 379 'jerror' 380 ); 381 } 382 383 return false; 384 } 385 } 386 387 /* 388 * If we created the language directory we will want to remove it if we 389 * have to roll back the installation, so let's add it to the installation 390 * step stack 391 */ 392 if ($created) { 393 $this->parent->pushStep(array('type' => 'folder', 'path' => $this->parent->getPath('extension_site'))); 394 } 395 396 // Copy all the necessary files 397 if ($this->parent->parseFiles($element) === false) { 398 // Install failed, rollback changes 399 $this->parent->abort(); 400 401 return false; 402 } 403 404 // Parse optional tags 405 $this->parent->parseMedia($this->getManifest()->media); 406 407 // Get the language description 408 $description = (string) $this->getManifest()->description; 409 410 if ($description) { 411 $this->parent->set('message', Text::_($description)); 412 } else { 413 $this->parent->set('message', ''); 414 } 415 416 // Add an entry to the extension table with a whole heap of defaults 417 $row = Table::getInstance('extension'); 418 $row->set('name', $this->name); 419 $row->set('type', 'language'); 420 $row->set('element', $this->tag); 421 $row->set('changelogurl', (string) $this->getManifest()->changelogurl); 422 423 // There is no folder for languages 424 $row->set('folder', ''); 425 $row->set('enabled', 1); 426 $row->set('protected', 0); 427 $row->set('access', 0); 428 $row->set('client_id', $clientId); 429 $row->set('params', $this->parent->getParams()); 430 $row->set('manifest_cache', $this->parent->generateManifestCache()); 431 432 if (!$row->check() || !$row->store()) { 433 // Install failed, roll back changes 434 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', $row->getError())); 435 436 return false; 437 } 438 439 if ((int) $clientId === 0) { 440 $this->createContentLanguage($this->tag); 441 } 442 443 // Clobber any possible pending updates 444 /** @var Update $update */ 445 $update = Table::getInstance('update'); 446 $uid = $update->find(array('element' => $this->tag, 'type' => 'language', 'folder' => '')); 447 448 if ($uid) { 449 $update->delete($uid); 450 } 451 452 // Clean installed languages cache. 453 Factory::getCache()->clean('com_languages'); 454 455 return $row->get('extension_id'); 456 } 457 458 /** 459 * Gets a unique language SEF string. 460 * 461 * This function checks other existing language with the same code, if they exist provides a unique SEF name. 462 * For instance: en-GB, en-US and en-AU will share the same SEF code by default: www.mywebsite.com/en/ 463 * To avoid this conflict, this function creates an specific SEF in case of existing conflict: 464 * For example: www.mywebsite.com/en-au/ 465 * 466 * @param string $itemLanguageTag Language Tag. 467 * 468 * @return string 469 * 470 * @since 3.7.0 471 */ 472 protected function getSefString($itemLanguageTag) 473 { 474 $langs = explode('-', $itemLanguageTag); 475 $prefixToFind = $langs[0]; 476 $numberPrefixesFound = 0; 477 478 // Get the sef value of all current content languages. 479 $db = $this->getDatabase(); 480 $query = $db->getQuery(true) 481 ->select($db->quoteName('sef')) 482 ->from($db->quoteName('#__languages')); 483 $db->setQuery($query); 484 485 $siteLanguages = $db->loadObjectList(); 486 487 foreach ($siteLanguages as $siteLang) { 488 if ($siteLang->sef === $prefixToFind) { 489 $numberPrefixesFound++; 490 } 491 } 492 493 return $numberPrefixesFound === 0 ? $prefixToFind : strtolower($itemLanguageTag); 494 } 495 496 /** 497 * Custom update method 498 * 499 * @return boolean True on success, false on failure 500 * 501 * @since 3.1 502 */ 503 public function update() 504 { 505 $xml = $this->parent->getManifest(); 506 507 $this->setManifest($xml); 508 509 $cname = $xml->attributes()->client; 510 511 // Attempt to map the client to a base path 512 $client = ApplicationHelper::getClientInfo($cname, true); 513 514 if ($client === null || (empty($cname) && $cname !== 0)) { 515 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::sprintf('JLIB_INSTALLER_ERROR_UNKNOWN_CLIENT_TYPE', $cname))); 516 517 return false; 518 } 519 520 $basePath = $client->path; 521 $clientId = $client->id; 522 523 // Get the language name 524 // Set the extensions name 525 $name = (string) $this->getManifest()->name; 526 $name = InputFilter::getInstance()->clean($name, 'string'); 527 $this->name = $name; 528 529 // Get the Language tag [ISO tag, eg. en-GB] 530 $tag = (string) $xml->tag; 531 532 // Check if we found the tag - if we didn't, we may be trying to install from an older language package 533 if (!$tag) { 534 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', Text::_('JLIB_INSTALLER_ERROR_NO_LANGUAGE_TAG'))); 535 536 return false; 537 } 538 539 $this->tag = $tag; 540 541 // Set the language installation path 542 $this->parent->setPath('extension_site', $basePath . '/language/' . $tag); 543 544 // Do we have a meta file in the file list? In other words... is this a core language pack? 545 if (\count($xml->files->children())) { 546 foreach ($xml->files->children() as $file) { 547 if ((string) $file->attributes()->file === 'meta') { 548 $this->core = true; 549 break; 550 } 551 } 552 } 553 554 // Copy all the necessary files 555 if ($this->parent->parseFiles($xml->files) === false) { 556 // Install failed, rollback changes 557 $this->parent->abort(); 558 559 return false; 560 } 561 562 // Parse optional tags 563 $this->parent->parseMedia($xml->media); 564 565 // Get the language description and set it as message 566 $this->parent->set('message', (string) $xml->description); 567 568 /** 569 * --------------------------------------------------------------------------------------------- 570 * Finalization and Cleanup Section 571 * --------------------------------------------------------------------------------------------- 572 */ 573 574 // Clobber any possible pending updates 575 $update = Table::getInstance('update'); 576 $uid = $update->find(array('element' => $this->tag, 'type' => 'language', 'client_id' => $clientId)); 577 578 if ($uid) { 579 $update->delete($uid); 580 } 581 582 // Update an entry to the extension table 583 $row = Table::getInstance('extension'); 584 $eid = $row->find(array('element' => $this->tag, 'type' => 'language', 'client_id' => $clientId)); 585 586 if ($eid) { 587 $row->load($eid); 588 } else { 589 // Set the defaults 590 591 // There is no folder for language 592 $row->set('folder', ''); 593 $row->set('enabled', 1); 594 $row->set('protected', 0); 595 $row->set('access', 0); 596 $row->set('client_id', $clientId); 597 $row->set('params', $this->parent->getParams()); 598 } 599 600 $row->set('name', $this->name); 601 $row->set('type', 'language'); 602 $row->set('element', $this->tag); 603 $row->set('manifest_cache', $this->parent->generateManifestCache()); 604 $row->set('changelogurl', (string) $this->getManifest()->changelogurl); 605 606 // Clean installed languages cache. 607 Factory::getCache()->clean('com_languages'); 608 609 if (!$row->check() || !$row->store()) { 610 // Install failed, roll back changes 611 $this->parent->abort(Text::sprintf('JLIB_INSTALLER_ABORT', $row->getError())); 612 613 return false; 614 } 615 616 if ($clientId === 0) { 617 $this->createContentLanguage($this->tag); 618 } 619 620 return $row->get('extension_id'); 621 } 622 623 /** 624 * Custom discover method 625 * Finds language files 626 * 627 * @return \Joomla\CMS\Table\Extension[] Array of discovered extensions. 628 * 629 * @since 3.1 630 */ 631 public function discover() 632 { 633 $results = []; 634 $clients = [0 => JPATH_SITE, 1 => JPATH_ADMINISTRATOR, 3 => JPATH_API]; 635 636 foreach ($clients as $clientId => $basePath) { 637 $languages = Folder::folders($basePath . '/language'); 638 639 foreach ($languages as $language) { 640 $manifestfile = $basePath . '/language/' . $language . '/langmetadata.xml'; 641 642 if (!is_file($manifestfile)) { 643 $manifestfile = $basePath . '/language/' . $language . '/' . $language . '.xml'; 644 645 if (!is_file($manifestfile)) { 646 continue; 647 } 648 } 649 650 $manifest_details = Installer::parseXMLInstallFile($manifestfile); 651 $extension = Table::getInstance('extension'); 652 $extension->set('type', 'language'); 653 $extension->set('client_id', $clientId); 654 $extension->set('element', $language); 655 $extension->set('folder', ''); 656 $extension->set('name', $language); 657 $extension->set('state', -1); 658 $extension->set('manifest_cache', json_encode($manifest_details)); 659 $extension->set('params', '{}'); 660 $results[] = $extension; 661 } 662 } 663 664 return $results; 665 } 666 667 /** 668 * Custom discover install method 669 * Basically updates the manifest cache and leaves everything alone 670 * 671 * @return integer The extension id 672 * 673 * @since 3.1 674 */ 675 public function discover_install() 676 { 677 // Need to find to find where the XML file is since we don't store this normally 678 $client = ApplicationHelper::getClientInfo($this->parent->extension->client_id); 679 $short_element = $this->parent->extension->element; 680 $manifestPath = $client->path . '/language/' . $short_element . '/langmetadata.xml'; 681 682 if (!is_file($manifestPath)) { 683 $manifestPath = $client->path . '/language/' . $short_element . '/' . $short_element . '.xml'; 684 } 685 686 $this->parent->manifest = $this->parent->isManifest($manifestPath); 687 $this->parent->setPath('manifest', $manifestPath); 688 $this->parent->setPath('source', $client->path . '/language/' . $short_element); 689 $this->parent->setPath('extension_root', $this->parent->getPath('source')); 690 $manifest_details = Installer::parseXMLInstallFile($this->parent->getPath('manifest')); 691 $this->parent->extension->manifest_cache = json_encode($manifest_details); 692 $this->parent->extension->state = 0; 693 $this->parent->extension->name = $manifest_details['name']; 694 $this->parent->extension->enabled = 1; 695 696 // @todo remove code: $this->parent->extension->params = $this->parent->getParams(); 697 try { 698 $this->parent->extension->check(); 699 $this->parent->extension->store(); 700 } catch (\RuntimeException $e) { 701 Log::add(Text::_('JLIB_INSTALLER_ERROR_LANG_DISCOVER_STORE_DETAILS'), Log::WARNING, 'jerror'); 702 703 return false; 704 } 705 706 if ($client->id === 0) { 707 $this->createContentLanguage($short_element); 708 } 709 710 // Clean installed languages cache. 711 Factory::getCache()->clean('com_languages'); 712 713 return $this->parent->extension->get('extension_id'); 714 } 715 716 /** 717 * Refreshes the extension table cache 718 * 719 * @return boolean result of operation, true if updated, false on failure 720 * 721 * @since 3.1 722 */ 723 public function refreshManifestCache() 724 { 725 $client = ApplicationHelper::getClientInfo($this->parent->extension->client_id); 726 $manifestPath = $client->path . '/language/' . $this->parent->extension->element . '/langmetadata.xml'; 727 728 if (!is_file($manifestPath)) { 729 $manifestPath = $client->path . '/language/' . $this->parent->extension->element . '/' . $this->parent->extension->element . '.xml'; 730 } 731 732 $this->parent->manifest = $this->parent->isManifest($manifestPath); 733 $this->parent->setPath('manifest', $manifestPath); 734 $manifest_details = Installer::parseXMLInstallFile($this->parent->getPath('manifest')); 735 $this->parent->extension->manifest_cache = json_encode($manifest_details); 736 $this->parent->extension->name = $manifest_details['name']; 737 738 if ($this->parent->extension->store()) { 739 return true; 740 } 741 742 Log::add(Text::_('JLIB_INSTALLER_ERROR_MOD_REFRESH_MANIFEST_CACHE'), Log::WARNING, 'jerror'); 743 744 return false; 745 } 746 747 /** 748 * Resets user language to default language 749 * 750 * @return void 751 * 752 * @since 4.0.0 753 */ 754 private function resetUserLanguage(): void 755 { 756 $client = ApplicationHelper::getClientInfo($this->extension->client_id); 757 758 if ($client->name !== 'site' && $client->name !== 'administrator') { 759 return; 760 } 761 762 // Setting the language of users which have this language as the default language 763 $db = $this->getDatabase(); 764 $query = $db->getQuery(true) 765 ->select( 766 [ 767 $db->quoteName('id'), 768 $db->quoteName('params'), 769 ] 770 ) 771 ->from($db->quoteName('#__users')); 772 $db->setQuery($query); 773 $users = $db->loadObjectList(); 774 775 if ($client->name === 'administrator') { 776 $param_name = 'admin_language'; 777 } else { 778 $param_name = 'language'; 779 } 780 781 $count = 0; 782 783 // Prepare the query. 784 $query = $db->getQuery(true) 785 ->update($db->quoteName('#__users')) 786 ->set($db->quoteName('params') . ' = :registry') 787 ->where($db->quoteName('id') . ' = :userId') 788 ->bind(':registry', $registry) 789 ->bind(':userId', $userId, ParameterType::INTEGER); 790 $db->setQuery($query); 791 792 foreach ($users as $user) { 793 $registry = new Registry($user->params); 794 795 if ($registry->get($param_name) === $this->extension->element) { 796 // Update query parameters. 797 $registry->set($param_name, ''); 798 $userId = $user->id; 799 800 $db->execute(); 801 $count++; 802 } 803 } 804 805 if (!empty($count)) { 806 Log::add(Text::plural('JLIB_INSTALLER_NOTICE_LANG_RESET_USERS', $count), Log::NOTICE, 'jerror'); 807 } 808 } 809 810 /** 811 * Create an unpublished content language. 812 * 813 * @param $tag string The language tag 814 * 815 * @throws \Exception 816 * @since 4.0.0 817 */ 818 protected function createContentLanguage($tag) 819 { 820 $tableLanguage = Table::getInstance('language'); 821 822 // Check if content language already exists. 823 if ($tableLanguage->load(array('lang_code' => $tag))) { 824 return; 825 } 826 827 $manifestfile = JPATH_SITE . '/language/' . $tag . '/langmetadata.xml'; 828 829 if (!is_file($manifestfile)) { 830 $manifestfile = JPATH_SITE . '/language/' . $tag . '/' . $tag . '.xml'; 831 } 832 833 // Load the site language manifest. 834 $siteLanguageManifest = LanguageHelper::parseXMLLanguageFile($manifestfile); 835 836 // Set the content language title as the language metadata name. 837 $contentLanguageTitle = $siteLanguageManifest['name']; 838 839 // Set, as fallback, the content language native title to the language metadata name. 840 $contentLanguageNativeTitle = $contentLanguageTitle; 841 842 // If exist, load the native title from the language xml metadata. 843 if (isset($siteLanguageManifest['nativeName']) && $siteLanguageManifest['nativeName']) { 844 $contentLanguageNativeTitle = $siteLanguageManifest['nativeName']; 845 } 846 847 // Try to load a language string from the installation language var. Will be removed in 4.0. 848 if ($contentLanguageNativeTitle === $contentLanguageTitle) { 849 $manifestfile = JPATH_INSTALLATION . '/language/' . $tag . '/langmetadata.xml'; 850 851 if (!is_file($manifestfile)) { 852 $manifestfile = JPATH_INSTALLATION . '/language/' . $tag . '/' . $tag . '.xml'; 853 } 854 855 if (file_exists($manifestfile)) { 856 $installationLanguage = new Language($tag); 857 $installationLanguage->load('', JPATH_INSTALLATION); 858 859 if ($installationLanguage->hasKey('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME')) { 860 // Make sure it will not use the en-GB fallback. 861 $defaultLanguage = new Language('en-GB'); 862 $defaultLanguage->load('', JPATH_INSTALLATION); 863 864 $defaultLanguageNativeTitle = $defaultLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); 865 $installationLanguageNativeTitle = $installationLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); 866 867 if ($defaultLanguageNativeTitle !== $installationLanguageNativeTitle) { 868 $contentLanguageNativeTitle = $installationLanguage->_('INSTL_DEFAULTLANGUAGE_NATIVE_LANGUAGE_NAME'); 869 } 870 } 871 } 872 } 873 874 // Prepare language data for store. 875 $languageData = array( 876 'lang_id' => 0, 877 'lang_code' => $tag, 878 'title' => $contentLanguageTitle, 879 'title_native' => $contentLanguageNativeTitle, 880 'sef' => $this->getSefString($tag), 881 'image' => strtolower(str_replace('-', '_', $tag)), 882 'published' => 0, 883 'ordering' => 0, 884 'access' => (int) Factory::getApplication()->get('access', 1), 885 'description' => '', 886 'metadesc' => '', 887 'sitename' => '', 888 ); 889 890 if (!$tableLanguage->bind($languageData) || !$tableLanguage->check() || !$tableLanguage->store() || !$tableLanguage->reorder()) { 891 Log::add( 892 Text::sprintf('JLIB_INSTALLER_WARNING_UNABLE_TO_INSTALL_CONTENT_LANGUAGE', $siteLanguageManifest['name'], $tableLanguage->getError()), 893 Log::NOTICE, 894 'jerror' 895 ); 896 } 897 } 898 }
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 |