CoreFiles by mySites.guru
multilang.php1,317 lines, 43,452 bytes, from Joomla_4.3.2-Stable-Full_Package.zip
Raw History Compare with 4.3.1
md5
557634e0c98a4bd6e117c74c870c2cd2
sha1
02ca95177e148af47e51e026dddcb5bc000b7d01
sha256
efc91ee7c444a165eae0564bc58d93b3b6d7efded48fcb5b99c239f71cf9e0ce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  Sampledata.Multilang
 *
 * @copyright   (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt

 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
 */

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Language\Language;
use Joomla\CMS\Language\LanguageHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Workflow\Workflow;
use Joomla\Database\Exception\ExecutionFailureException;
use Joomla\Database\ParameterType;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Sampledata - Multilang Plugin
 *
 * @since  4.0.0
 */
class PlgSampledataMultilang extends CMSPlugin
{
    /**
     * @var     \Joomla\Database\DatabaseDriver
     *
     * @since   4.0.0
     */
    protected $db;

    /**
     * @var     \Joomla\CMS\Application\CMSApplication
     *
     * @since   4.0.0
     */
    protected $app;

    /**
     * Affects constructor behavior. If true, language files will be loaded automatically.
     *
     * @var     boolean
     *
     * @since   4.0.0
     */
    protected $autoloadLanguage = true;

    /**
     * @var     string
     *
     * @since   4.0.0
     */
    protected $path = null;

    /**
     * @var    integer Id, author of all generated content.
     *
     * @since   4.0.0
     */
    protected $adminId;

    /**
     * Get an overview of the proposed sampledata.
     *
     * @return  stdClass|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onSampledataGetOverview()
    {
        if (!$this->app->getIdentity()->authorise('core.create', 'com_content')) {
            return;
        }

        $data              = new stdClass();
        $data->name        = $this->_name;
        $data->title       = Text::_('PLG_SAMPLEDATA_MULTILANG_OVERVIEW_TITLE');
        $data->description = Text::_('PLG_SAMPLEDATA_MULTILANG_OVERVIEW_DESC');
        $data->icon        = 'wifi';
        $data->steps       = 8;

        return $data;
    }

    /**
     * First step to enable the Language filter plugin.
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep1()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        $languages = LanguageHelper::getContentLanguages([0, 1]);

        if (count($languages) < 2) {
            $response            = [];
            $response['success'] = false;
            $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_MISSING_LANGUAGE');

            return $response;
        }

        if (!$this->enablePlugin('plg_system_languagefilter')) {
            $response            = [];
            $response['success'] = false;

            $lang = $this->app->getLanguage();
            $lang->load('plg_system_languagefilter', JPATH_ADMINISTRATOR);
            $message = $lang->_('PLG_SYSTEM_LANGUAGEFILTER');

            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_LANGFILTER', 2, $message);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP1_SUCCESS');

        return $response;
    }

    /**
     * Second step to add a language switcher module
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep2()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_modules') || !$this->app->getIdentity()->authorise('core.create', 'com_modules')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 2, 'com_modules');

            return $response;
        }

        if (!$this->addModuleLanguageSwitcher()) {
            $response            = [];
            $response['success'] = false;

            $lang = $this->app->getLanguage();
            $lang->load('mod_languages', JPATH_SITE);
            $message = $lang->_('MOD_LANGUAGES');

            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_SWITCHER', 2, $message);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP2_SUCCESS');

        return $response;
    }

    /**
     * Third step to make sure all content languages are published
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep3()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_languages')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 3, 'com_languages');

            return $response;
        }

        if (!$this->publishContentLanguages()) {
            $response            = [];
            $response['success'] = false;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_CONTENTLANGUAGES', 3);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP3_SUCCESS');

        return $response;
    }

    /**
     * Fourth step to create Menus and list all categories menu items
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep4()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_menus') || !$this->app->getIdentity()->authorise('core.create', 'com_menus')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 4, 'com_menus');

            return $response;
        }

        $siteLanguages = $this->getInstalledlangsFrontend();

        foreach ($siteLanguages as $siteLang) {
            if (!$this->addMenuGroup($siteLang)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_MENUS', 4, $siteLang->language);

                return $response;
            }

            if (!$tableMenuItem = $this->addAllCategoriesMenuItem($siteLang)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ALLCATEGORIES', 4, $siteLang->language);

                return $response;
            }

            $groupedAssociations['com_menus.item'][$siteLang->language] = $tableMenuItem->id;
        }

        if (!$this->addAssociations($groupedAssociations)) {
            $response            = [];
            $response['success'] = false;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ASSOC_ALLCATEGORIES', 4);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP4_SUCCESS');

        return $response;
    }

    /**
     * Fifth step to add menu modules
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep5()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_modules') || !$this->app->getIdentity()->authorise('core.create', 'com_modules')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 5, 'com_modules');

            return $response;
        }

        $siteLanguages = $this->getInstalledlangsFrontend();

        foreach ($siteLanguages as $siteLang) {
            if (!$this->addModuleMenu($siteLang)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_MENUMODULES', 5, $siteLang->language);

                return $response;
            }
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP5_SUCCESS');

        return $response;
    }

    /**
     * Sixth step to add workflow, categories, articles and blog menu items
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep6()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_content') || !$this->app->getIdentity()->authorise('core.create', 'com_content')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 6, 'com_content');

            return $response;
        }

        if (!ComponentHelper::isEnabled('com_categories') || !$this->app->getIdentity()->authorise('core.create', 'com_content.category')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 6, 'com_categories');

            return $response;
        }

        $siteLanguages = $this->getInstalledlangsFrontend();

        ComponentHelper::getParams('com_content')->set('workflow_enabled', 0);

        foreach ($siteLanguages as $siteLang) {
            if (!$tableCategory = $this->addCategory($siteLang)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_CATEGORY', 6, $siteLang->language);

                return $response;
            }

            $groupedAssociations['com_categories.item'][$siteLang->language] = $tableCategory->id;

            if (!$tableArticle = $this->addArticle($siteLang, $tableCategory->id)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ARTICLE', 6, $siteLang->language);

                return $response;
            }

            $groupedAssociations['com_content.item'][$siteLang->language] = $tableArticle->id;

            if (!$tableMenuItem = $this->addBlogMenuItem($siteLang, $tableCategory->id)) {
                $response            = [];
                $response['success'] = false;
                $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_BLOG', 6, $siteLang->language);

                return $response;
            }

            $groupedAssociations['com_menus.item'][$siteLang->language] = $tableMenuItem->id;
        }

        if (!$this->addAssociations($groupedAssociations)) {
            $response            = [];
            $response['success'] = false;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ASSOC_VARIOUS', 6);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP6_SUCCESS');

        return $response;
    }

    /**
     * Seventh step to disable the mainmenu module whose home page is set to All languages.
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since   4.0.0
     */
    public function onAjaxSampledataApplyStep7()
    {
        if (!Session::checkToken('get') || $this->app->getInput()->get('type') != $this->_name) {
            return;
        }

        if (!ComponentHelper::isEnabled('com_modules')) {
            $response            = [];
            $response['success'] = true;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_STEP_SKIPPED', 7, 'com_modules');

            return $response;
        }

        if (!$this->disableModuleMainMenu()) {
            $response            = [];
            $response['success'] = false;
            $response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_MAINMENU_MODULE', 7);

            return $response;
        }

        $response            = [];
        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP7_SUCCESS');

        return $response;
    }

    /**
     * Final step to show completion of sampledata.
     *
     * @return  array|void  Will be converted into the JSON response to the module.
     *
     * @since  4.0.0
     */
    public function onAjaxSampledataApplyStep8()
    {
        if ($this->app->getInput()->get('type') !== $this->_name) {
            return;
        }

        $response['success'] = true;
        $response['message'] = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP8_SUCCESS');

        return $response;
    }

    /**
     * Enable a Joomla plugin.
     *
     * @param   string  $pluginName  The name of plugin.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function enablePlugin($pluginName)
    {
        // Create a new db object.
        $db    = $this->db;
        $query = $db->getQuery(true);

        $query
            ->update($db->quoteName('#__extensions'))
            ->set($db->quoteName('enabled') . ' = 1')
            ->where($db->quoteName('name') . ' = :pluginname')
            ->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
            ->bind(':pluginname', $pluginName);

        $db->setQuery($query);

        try {
            $db->execute();
        } catch (ExecutionFailureException $e) {
            return false;
        }

        // Store language filter plugin parameters.
        if ($pluginName == 'plg_system_languagefilter') {
            $params = '{'
                . '"detect_browser":"0",'
                . '"automatic_change":"1",'
                . '"item_associations":"1",'
                . '"remove_default_prefix":"0",'
                . '"lang_cookie":"0",'
                . '"alternate_meta":"1"'
                . '}';
            $query
                ->clear()
                ->update($db->quoteName('#__extensions'))
                ->set($db->quoteName('params') . ' = :params')
                ->where($db->quoteName('name') . ' = ' . $db->quote('plg_system_languagefilter'))
                ->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
                ->bind(':params', $params);

            $db->setQuery($query);

            try {
                $db->execute();
            } catch (ExecutionFailureException $e) {
                return false;
            }
        }

        return true;
    }

    /**
     * Disable Default Main Menu Module.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function disableModuleMainMenu()
    {
        // Create a new db object.
        $db    = $this->db;
        $query = $db->getQuery(true);

        // Disable main menu module with Home set to ALL languages.
        $query
            ->update($db->quoteName('#__modules'))
            ->set($db->quoteName('published') . ' = 0')
            ->where(
                [
                    $db->quoteName('client_id') . ' = 0',
                    $db->quoteName('module') . ' = ' . $db->quote('mod_menu'),
                    $db->quoteName('language') . ' = ' . $db->quote('*'),
                    $db->quoteName('position') . ' = ' . $db->quote('sidebar-right'),
                ]
            );
        $db->setQuery($query);

        try {
            $db->execute();
        } catch (ExecutionFailureException $e) {
            return false;
        }

        return true;
    }

    /**
     * Enable the Language Switcher Module.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function addModuleLanguageSwitcher()
    {
        $tableModule = Table::getInstance('Module', 'Joomla\\CMS\\Table\\');

        $moduleData  = [
            'id'        => 0,
            'title'     => 'Language Switcher',
            'note'      => '',
            'content'   => '',
            'position'  => 'sidebar-right',
            'module'    => 'mod_languages',
            'access'    => 1,
            'showtitle' => 0,
            'params'    => '{"header_text":"","footer_text":"","dropdown":"0","image":"1","inline":"1","show_active":"1",'
                . '"full_name":"1","layout":"_:default","moduleclass_sfx":"","cache":"0","cache_time":"900","cachemode":"itemid",'
                . '"module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}',
            'client_id' => 0,
            'language'  => '*',
            'published' => 1,
            'rules'     => [],
        ];

        // Bind the data.
        if (!$tableModule->bind($moduleData)) {
            return false;
        }

        // Check the data.
        if (!$tableModule->check()) {
            return false;
        }

        // Store the data.
        if (!$tableModule->store()) {
            return false;
        }

        return $this->addModuleInModuleMenu((int) $tableModule->id);
    }

    /**
     * Add Module Menu.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function addModuleMenu($itemLanguage)
    {
        $tableModule = Table::getInstance('Module', 'Joomla\\CMS\\Table\\');
        $title       = 'Main menu ' . $itemLanguage->language;

        $moduleData = [
            'id'        => 0,
            'title'     => $title,
            'note'      => '',
            'content'   => '',
            'position'  => 'sidebar-right',
            'module'    => 'mod_menu',
            'access'    => 1,
            'showtitle' => 1,
            'params'    => '{"menutype":"mainmenu-' . strtolower($itemLanguage->language)
                . '","startLevel":"0","endLevel":"0","showAllChildren":"0","tag_id":"","class_sfx":"","window_open":"",'
                . '"layout":"","moduleclass_sfx":"","cache":"1","cache_time":"900","cachemode":"itemid"}',
            'client_id' => 0,
            'language'  => $itemLanguage->language,
            'published' => 1,
            'rules'     => [],
        ];

        // Bind the data.
        if (!$tableModule->bind($moduleData)) {
            return false;
        }

        // Check the data.
        if (!$tableModule->check()) {
            return false;
        }

        // Store the data.
        if (!$tableModule->store()) {
            return false;
        }

        return $this->addModuleInModuleMenu((int) $tableModule->id);
    }

    /**
     * Add Menu Group.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function addMenuGroup($itemLanguage)
    {
        // Add Menu Group.
        $menuTable = $this->app->bootComponent('com_menus')->getMVCFactory()->createTable('MenuType', 'Administrator', ['dbo' => $this->db]);

        $menuData = [
            'id'          => 0,
            'menutype'    => 'mainmenu-' . strtolower($itemLanguage->language),
            'title'       => 'Main Menu (' . $itemLanguage->language . ')',
            'description' => 'The main menu for the site in language ' . $itemLanguage->name,
        ];

        // Bind the data.
        if (!$menuTable->bind($menuData)) {
            return false;
        }

        // Check the data.
        if (!$menuTable->check()) {
            return false;
        }

        // Store the data.
        if (!$menuTable->store()) {
            return false;
        }

        return true;
    }

    /**
     * Add List All Categories Menu Item for new router.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     *
     * @return  Table|boolean Menu Item Object. False otherwise.
     *
     * @since   4.0.0
     */
    private function addAllCategoriesMenuItem($itemLanguage)
    {
        // Add Menu Item.
        $tableItem = $this->app->bootComponent('com_menus')->getMVCFactory()->createTable('Menu', 'Administrator', ['dbo' => $this->db]);

        $newlanguage = new Language($itemLanguage->language, false);
        $newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
        $title = $newlanguage->_('JCATEGORIES');
        $alias = 'allcategories_' . $itemLanguage->language;

        $menuItem = [
            'title'        => $title,
            'alias'        => $alias,
            'menutype'     => 'mainmenu-' . strtolower($itemLanguage->language),
            'type'         => 'component',
            'link'         => 'index.php?option=com_content&view=categories&id=0',
            'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
            'published'    => 1,
            'parent_id'    => 1,
            'level'        => 1,
            'home'         => 0,
            'params'       => '{"show_base_description":"","categories_description":"","maxLevelcat":"",'
                . '"show_empty_categories_cat":"","show_subcat_desc_cat":"","show_cat_num_articles_cat":"",'
                . '"show_category_title":"","show_description":"","show_description_image":"","maxLevel":"",'
                . '"show_empty_categories":"","show_no_articles":"","show_subcat_desc":"","show_cat_num_articles":"",'
                . '"num_leading_articles":"","num_intro_articles":"","num_links":"",'
                . '"show_subcategory_content":"","orderby_pri":"","orderby_sec":"",'
                . '"order_date":"","show_pagination_limit":"","filter_field":"","show_headings":"",'
                . '"list_show_date":"","date_format":"","list_show_hits":"","list_show_author":"","display_num":"10",'
                . '"show_pagination":"","show_pagination_results":"","article_layout":"_:default","show_title":"",'
                . '"link_titles":"","show_intro":"","show_category":"","link_category":"","show_parent_category":"",'
                . '"link_parent_category":"","show_author":"","link_author":"","show_create_date":"",'
                . '"show_modify_date":"","show_publish_date":"","show_item_navigation":"","show_vote":"",'
                . '"show_readmore":"","show_readmore_title":"","show_hits":"","show_noauth":"","show_feed_link":"",'
                . '"feed_summary":"","menu-anchor_title":"","menu-anchor_css":"","menu_image":"","menu_image_css":"",'
                . '"menu_text":1,"menu_show":0,"page_title":"","show_page_heading":"","page_heading":"",'
                . '"pageclass_sfx":"","menu-meta_description":"","robots":""}',
            'language' => $itemLanguage->language,
        ];

        // Bind the data.
        if (!$tableItem->bind($menuItem)) {
            return false;
        }

        $tableItem->setLocation($menuItem['parent_id'], 'last-child');

        // Check the data.
        if (!$tableItem->check()) {
            return false;
        }

        // Store the data.
        if (!$tableItem->store()) {
            return false;
        }

        // Rebuild the tree path.
        if (!$tableItem->rebuildPath($tableItem->id)) {
            return false;
        }

        return $tableItem;
    }

    /**
     * Add Blog Menu Item.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     * @param   integer   $categoryId    The id of the category displayed by the blog.
     *
     * @return  Table|boolean Menu Item Object. False otherwise.
     *
     * @since   4.0.0
     */
    private function addBlogMenuItem($itemLanguage, $categoryId)
    {
        // Add Menu Item.
        $tableItem = $this->app->bootComponent('com_menus')->getMVCFactory()->createTable('Menu', 'Administrator', ['dbo' => $this->db]);

        $newlanguage = new Language($itemLanguage->language, false);
        $newlanguage->load('com_languages', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
        $title = $newlanguage->_('COM_LANGUAGES_HOMEPAGE');
        $alias = 'home_' . $itemLanguage->language;

        $menuItem = [
            'title'        => $title,
            'alias'        => $alias,
            'menutype'     => 'mainmenu-' . strtolower($itemLanguage->language),
            'type'         => 'component',
            'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $categoryId,
            'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
            'published'    => 1,
            'parent_id'    => 1,
            'level'        => 1,
            'home'         => 1,
            'params'       => '{"layout_type":"blog","show_category_heading_title_text":"","show_category_title":"",'
                . '"show_description":"","show_description_image":"","maxLevel":"","show_empty_categories":"",'
                . '"show_no_articles":"","show_subcat_desc":"","show_cat_num_articles":"","show_cat_tags":"",'
                . '"blog_class_leading":"","blog_class":"","num_leading_articles":"1","num_intro_articles":"3",'
                . '"num_links":"0","show_subcategory_content":"","link_intro_image":"","orderby_pri":"",'
                . '"orderby_sec":"front","order_date":"","show_pagination":"2","show_pagination_results":"1",'
                . '"show_featured":"","article_layout":"_:default","show_title":"","link_titles":"","show_intro":"","info_block_position":"",'
                . '"info_block_show_title":"","show_category":"","link_category":"","show_parent_category":"",'
                . '"link_parent_category":"","show_associations":"","show_author":"","link_author":"",'
                . '"show_create_date":"","show_modify_date":"","show_publish_date":"","show_item_navigation":"",'
                . '"show_vote":"","show_readmore":"","show_readmore_title":"","show_hits":"","show_tags":"",'
                . '"show_noauth":"","show_feed_link":"1","feed_summary":"","menu-anchor_title":"","menu-anchor_css":"",'
                . '"menu_image":"","menu_image_css":"","menu_text":1,"menu_show":1,"page_title":"","show_page_heading":"1",'
                . '"page_heading":"","pageclass_sfx":"","menu-meta_description":"","robots":""}',
            'language' => $itemLanguage->language,
        ];

        // Bind the data.
        if (!$tableItem->bind($menuItem)) {
            return false;
        }

        $tableItem->setLocation($menuItem['parent_id'], 'last-child');

        // Check the data.
        if (!$tableItem->check()) {
            return false;
        }

        // Store the data.
        if (!$tableItem->store()) {
            return false;
        }

        // Rebuild the tree path.
        if (!$tableItem->rebuildPath($tableItem->id)) {
            return false;
        }

        return $tableItem;
    }

    /**
     * Create the language associations.
     *
     * @param   array  $groupedAssociations  Array of language associations for all items.
     *
     * @return  boolean  True on success.
     *
     * @since   4.0.0
     */
    private function addAssociations($groupedAssociations)
    {
        $db = $this->db;

        foreach ($groupedAssociations as $context => $associations) {
            $key   = md5(json_encode($associations));
            $query = $db->getQuery(true)
                ->insert($db->quoteName('#__associations'));

            foreach ($associations as $language => $id) {
                $query->values(
                    implode(
                        ',',
                        $query->bindArray(
                            [
                                $id,
                                $context,
                                $key,
                            ],
                            [
                                ParameterType::INTEGER,
                                ParameterType::STRING,
                                ParameterType::STRING,
                            ]
                        )
                    )
                );
            }

            $db->setQuery($query);

            try {
                $db->execute();
            } catch (\RuntimeException $e) {
                return false;
            }
        }

        return true;
    }

    /**
     * Add a Module in Module menus.
     *
     * @param   integer  $moduleId  The Id of module.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function addModuleInModuleMenu($moduleId)
    {
        // Create a new db object.
        $db       = $this->db;
        $query    = $db->getQuery(true);
        $moduleId = (int) $moduleId;

        // Add Module in Module menus.
        $query->insert($db->quoteName('#__modules_menu'))
            ->columns($db->quoteName(['moduleid', 'menuid']))
            ->values(':moduleId, 0')
            ->bind(':moduleId', $moduleId, ParameterType::INTEGER);

        $db->setQuery($query);

        try {
            $db->execute();
        } catch (RuntimeException $e) {
            return false;
        }

        return true;
    }

    /**
     * Method to create a category for a specific language.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     *
     * @return  Table|boolean Category Object. False otherwise.
     *
     * @since   4.0.0
     */
    public function addCategory($itemLanguage)
    {
        $newlanguage = new Language($itemLanguage->language, false);
        $newlanguage->load('joomla', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
        $title = $newlanguage->_('JCATEGORY');
        $alias = ApplicationHelper::stringURLSafe($title);

        $app = Factory::getApplication();

        // Set unicodeslugs if alias is empty
        if (trim(str_replace('-', '', $alias) == '')) {
            $unicode = $app->set('unicodeslugs', 1);
            $alias   = ApplicationHelper::stringURLSafe($title);
            $app->set('unicodeslugs', $unicode);
        }

        // Initialize a new category.
        $category = $this->app->bootComponent('com_categories')->getMVCFactory()->createTable('Category', 'Administrator', ['dbo' => $this->db]);

        $data = [
            'extension'       => 'com_content',
            'title'           => $title . ' (' . strtolower($itemLanguage->language) . ')',
            'alias'           => $alias . ' (' . strtolower($itemLanguage->language) . ')',
            'description'     => '',
            'published'       => 1,
            'access'          => 1,
            'params'          => '{"target":"","image":""}',
            'metadesc'        => '',
            'metakey'         => '',
            'metadata'        => '{"page_title":"","author":"","robots":""}',
            'created_time'    => Factory::getDate()->toSql(),
            'created_user_id' => (int) $this->getAdminId(),
            'language'        => $itemLanguage->language,
            'rules'           => [],
            'parent_id'       => 1,
        ];

        // Set the location in the tree.
        $category->setLocation(1, 'last-child');

        // Bind the data to the table
        if (!$category->bind($data)) {
            return false;
        }

        // Check to make sure our data is valid.
        if (!$category->check()) {
            return false;
        }

        // Store the category.
        if (!$category->store(true)) {
            return false;
        }

        // Build the path for our category.
        $category->rebuildPath($category->id);

        return $category;
    }

    /**
     * Create an article in a specific language.
     *
     * @param   stdClass  $itemLanguage  Language Object.
     * @param   integer   $categoryId    The id of the category where we want to add the article.
     *
     * @return  Table|boolean Article Object. False otherwise.
     *
     * @since   4.0.0
     */
    private function addArticle($itemLanguage, $categoryId)
    {
        $db = $this->db;

        $newlanguage = new Language($itemLanguage->language, false);
        $newlanguage->load('com_content.sys', JPATH_ADMINISTRATOR, $itemLanguage->language, true);
        $title       = $newlanguage->_('COM_CONTENT_CONTENT_TYPE_ARTICLE');
        $currentDate = Factory::getDate()->toSql();
        $alias       = ApplicationHelper::stringURLSafe($title);

        // Set unicodeslugs if alias is empty
        if (trim(str_replace('-', '', $alias) == '')) {
            $unicode = $this->app->set('unicodeslugs', 1);
            $alias   = ApplicationHelper::stringURLSafe($title);
            $this->app->set('unicodeslugs', $unicode);
        }

        // Initialize a new article.
        $article = $this->app->bootComponent('com_content')->getMVCFactory()->createTable('Article', 'Administrator', ['dbo' => $this->db]);

        $data = [
            'title'     => $title . ' (' . strtolower($itemLanguage->language) . ')',
            'alias'     => $alias . ' (' . strtolower($itemLanguage->language) . ')',
            'introtext' => '<p>Lorem ipsum ad his scripta blandit partiendo, eum fastidii accumsan euripidis'
                . ' in, eum liber hendrerit an. Qui ut wisi vocibus suscipiantur, quo dicit'
                . ' ridens inciderint id. Quo mundi lobortis reformidans eu, legimus senserit'
                . 'definiebas an eos. Eu sit tincidunt incorrupte definitionem, vis mutat'
                . ' affert percipit cu, eirmod consectetuer signiferumque eu per. In usu latine'
                . 'equidem dolores. Quo no falli viris intellegam, ut fugit veritus placerat'
                . 'per. Ius id vidit volumus mandamus, vide veritus democritum te nec, ei eos'
                . 'debet libris consulatu.</p>',
            'fulltext'         => '',
            'images'           => json_encode([]),
            'urls'             => json_encode([]),
            'created'          => $currentDate,
            'created_by'       => (int) $this->getAdminId(),
            'created_by_alias' => 'Joomla',
            'publish_up'       => $currentDate,
            'publish_down'     => null,
            'version'          => 1,
            'catid'            => $categoryId,
            'metadata'         => '{"robots":"","author":"","rights":"","tags":null}',
            'metakey'          => '',
            'metadesc'         => '',
            'language'         => $itemLanguage->language,
            'state'            => 1,
            'featured'         => 1,
            'attribs'          => [],
            'rules'            => [],
        ];

        // Bind the data to the table
        if (!$article->bind($data)) {
            return false;
        }

        // Check to make sure our data is valid.
        if (!$article->check()) {
            return false;
        }

        // Now store the category.
        if (!$article->store(true)) {
            return false;
        }

        // Get the new item ID.
        $newId = $article->get('id');

        $query = $db->getQuery(true)
            ->insert($db->quoteName('#__content_frontpage'))
            ->values($newId . ', 0, NULL, NULL');

        $db->setQuery($query);

        try {
            $db->execute();
        } catch (ExecutionFailureException $e) {
            return false;
        }

        $workflow = new Workflow('com_content.article', $this->app, $db);

        try {
            $stage_id = $workflow->getDefaultStageByCategory($categoryId);

            if ($stage_id) {
                $workflow->createAssociation($newId, $stage_id);
            }
        } catch (ExecutionFailureException $e) {
            return false;
        }

        return $article;
    }

    /**
     * Publish the Installed Content Languages.
     *
     * @return  boolean
     *
     * @since   4.0.0
     */
    private function publishContentLanguages()
    {
        // Publish the Content Languages.
        $tableLanguage = Table::getInstance('Language');

        $siteLanguages = $this->getInstalledlangs('site');

        // For each content language.
        foreach ($siteLanguages as $siteLang) {
            if ($tableLanguage->load(['lang_code' => $siteLang->language, 'published' => 0]) && !$tableLanguage->publish()) {
                $this->app->enqueueMessage(Text::sprintf('INSTL_DEFAULTLANGUAGE_COULD_NOT_CREATE_CONTENT_LANGUAGE', $siteLang->name), 'warning');
            }
        }

        return true;
    }

    /**
     * Get Languages item data for the Administrator.
     *
     * @return  array
     *
     * @since   4.0.0
     */
    public function getInstalledlangsAdministrator()
    {
        return $this->getInstalledlangs('administrator');
    }

    /**
     * Get Languages item data for the Frontend.
     *
     * @return  array  List of installed languages in the frontend application.
     *
     * @since   4.0.0
     */
    public function getInstalledlangsFrontend()
    {
        return $this->getInstalledlangs('site');
    }

    /**
     * Get Installed Languages.
     *
     * @param   string  $clientName  Name of the cms client.
     *
     * @return  array
     *
     * @since   4.0.0
     */
    protected function getInstalledlangs($clientName = 'administrator')
    {
        // Get information.
        $path     = $this->getPath();
        $client   = $this->getClient($clientName);
        $langlist = $this->getLanguageList($client->id);

        // Compute all the languages.
        $data = [];

        foreach ($langlist as $lang) {
            $file = $path . '/' . $lang . '/' . $lang . '.xml';

            if (!is_file($file)) {
                $file = $path . '/' . $lang . '/langmetadata.xml';
            }

            $info          = Installer::parseXMLInstallFile($file);
            $row           = new stdClass();
            $row->language = $lang;

            if (!is_array($info)) {
                continue;
            }

            foreach ($info as $key => $value) {
                $row->$key = $value;
            }

            // If current then set published.
            $params = ComponentHelper::getParams('com_languages');

            if ($params->get($client->name, 'en-GB') == $row->language) {
                $row->published = 1;
            } else {
                $row->published = 0;
            }

            $row->checked_out = null;
            $data[]           = $row;
        }

        usort($data, [$this, 'compareLanguages']);

        return $data;
    }

    /**
     * Get installed languages data.
     *
     * @param   integer  $clientId  The client ID to retrieve data for.
     *
     * @return  object  The language data.
     *
     * @since   4.0.0
     */
    protected function getLanguageList($clientId = 1)
    {
        // Create a new db object.
        $db    = $this->db;
        $query = $db->getQuery(true);

        // Select field element from the extensions table.
        $query->select($db->quoteName(['element', 'name']))
            ->from($db->quoteName('#__extensions'))
            ->where(
                [
                    $db->quoteName('type') . ' = ' . $db->quote('language'),
                    $db->quoteName('state') . ' = 0',
                    $db->quoteName('enabled') . ' = 1',
                    $db->quoteName('client_id') . ' = :clientid',
                ]
            )
            ->bind(':clientid', $clientId, ParameterType::INTEGER);

        $db->setQuery($query);

        return $db->loadColumn();
    }

    /**
     * Compare two languages in order to sort them.
     *
     * @param   object  $lang1  The first language.
     * @param   object  $lang2  The second language.
     *
     * @return  integer
     *
     * @since   4.0.0
     */
    protected function compareLanguages($lang1, $lang2)
    {
        return strcmp($lang1->name, $lang2->name);
    }

    /**
     * Get the languages folder path.
     *
     * @return  string  The path to the languages folders.
     *
     * @since   4.0.0
     */
    protected function getPath()
    {
        if ($this->path === null) {
            $client     = $this->getClient();
            $this->path = LanguageHelper::getLanguagePath($client->path);
        }

        return $this->path;
    }

    /**
     * Get the client object of Administrator or Frontend.
     *
     * @param   string  $client  Name of the client object.
     *
     * @return  object
     *
     * @since   4.0.0
     */
    protected function getClient($client = 'administrator')
    {
        return ApplicationHelper::getClientInfo($client, true);
    }

    /**
     * Retrieve the admin user id.
     *
     * @return  integer|boolean  One Administrator ID.
     *
     * @since   4.0.0
     */
    private function getAdminId()
    {
        if ($this->adminId) {
            // Return local cached admin ID.
            return $this->adminId;
        }

        $db    = $this->db;
        $query = $db->getQuery(true);

        // Select the admin user ID
        $query
            ->select($db->quoteName('u.id'))
            ->from($db->quoteName('#__users', 'u'))
            ->join(
                'LEFT',
                $db->quoteName('#__user_usergroup_map', 'map'),
                $db->quoteName('map.user_id') . ' = ' . $db->quoteName('u.id')
            )
            ->join(
                'LEFT',
                $db->quoteName('#__usergroups', 'g'),
                $db->quoteName('map.group_id') . ' = ' . $db->quoteName('g.id')
            )
            ->where(
                $db->quoteName('g.title') . ' = ' . $db->quote('Super Users')
            );

        $db->setQuery($query);
        $id = $db->loadResult();

        if (!$id || $id instanceof Exception) {
            return false;
        }

        return $id;
    }
}

The same content is in 6 releases, Joomla 4.3.2-rc1 to 4.3.4. See them all, or every version of this file.