CoreFiles by mySites.guru
multilang.php1,422 lines, 36,653 bytes, from Joomla_4.0.0-alpha6-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha5
md5
bd348a9bacf080d1cf27049f971ed2d4
sha1
35cd3e422ad570c5a102f6bc8ebf7991f091e7b0
sha256
e53b5475522ed4d4bedc9387c09835b0ebd9adf51e15f5b94012f22a69e679d6
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Sampledata.Multilang
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Component\ComponentHelper;
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\Table\Table;

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

	/**
	 * Application object
	 *
	 * @var    JApplicationCms
	 *
	 * @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;

	/**
	 * Holds the menuitem model
	 *
	 * @var     MenusModelItem
	 *
	 * @since   4.0.0
	 */
	private $menuItemModel;

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

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

	/**
	 * Get an overview of the proposed sampledata.
	 *
	 * @return  boolean  True on success.
	 *
	 * @since   4.0.0
	 */
	public function onSampledataGetOverview()
	{
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

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

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

			return $response;
		}

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

			$lang = Factory::getLanguage()->getTag();
			$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          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

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

			return $response;
		}

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

			$lang = Factory::getLanguage()->getTag();
			$lang->load('mod_languages', JPATH_SITE);
			$message = $lang->_('MOD_LANGUAGES');

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

			return $response;
		}

		$response          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

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

			return $response;
		}

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

			return $response;
		}

		$response          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

		if (!ComponentHelper::isEnabled('com_menus'))
		{
			$response            = array();
			$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            = array();
				$response['success'] = false;
				$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_MENUS', 4, $siteLang->language);

				return $response;
			}

			if (!$tableMenuItem = $this->addAllCategoriesMenuItem($siteLang))
			{
				$response            = array();
				$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            = array();
			$response['success'] = false;
			$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ASSOC_ALLCATEGORIES', 4);

			return $response;
		}

		$response          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

		if (!ComponentHelper::isEnabled('com_modules'))
		{
			$response            = array();
			$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            = array();
				$response['success'] = false;
				$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_MENUMODULES', 5, $siteLang->language);

				return $response;
			}
		}

		$response          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

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

			return $response;
		}

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

			return $response;
		}

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

			return $response;
		}

		$siteLanguages = $this->getInstalledlangsFrontend();

		if (!$tableWorkflow = $this->addWorkflow())
		{
			$response            = array();
			$response['success'] = false;
			$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_WORKFLOW', 6);

			return $response;
		}

		foreach ($siteLanguages as $siteLang)
		{
			if (!$tableCategory = $this->addCategory($siteLang, $tableWorkflow->id))
			{
				$response            = array();
				$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, $tableWorkflow->stageId))
			{
				$response            = array();
				$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            = array();
				$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            = array();
			$response['success'] = false;
			$response['message'] = Text::sprintf('PLG_SAMPLEDATA_MULTILANG_ERROR_ASSOC_VARIOUS', 6);

			return $response;
		}

		$response          = new stdClass;
		$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 ($this->app->input->get('type') != $this->_name)
		{
			return;
		}

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

			return $response;
		}

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

			return $response;
		}

		$response          = new stdClass;
		$response->success = true;
		$response->message = Text::_('PLG_SAMPLEDATA_MULTILANG_STEP7_SUCCESS');

		return $response;
	}

	/**
	 * Final step to show completion of sampledata.
	 *
	 * @return  array or void  Will be converted into the JSON response to the module.
	 *
	 * @since  4.0.0
	 */
	public function onAjaxSampledataApplyStep8()
	{
		$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    = Factory::getDbo();
		$query = $db->getQuery(true);

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

		$db->setQuery($query);

		try
		{
			$db->execute();
		}
		catch (JDatabaseExceptionExecuting $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') . ' = ' . $db->quote($params))
				->where($db->quoteName('name') . ' = ' . $db->quote('plg_system_languagefilter'))
				->where($db->quoteName('type') . ' = ' . $db->quote('plugin'));

			$db->setQuery($query);

			try
			{
				$db->execute();
			}
			catch (\JDatabaseExceptionExecuting $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    = Factory::getDbo();
		$query = $db->getQuery(true);

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

		try
		{
			$db->execute();
		}
		catch (\JDatabaseExceptionExecuting $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  = array(
			'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'     => array(),
		);

		// 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 = array(
			'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' => array(),
		);

		// 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)
	{
		Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/Table/');

		// Add Menu Group.
		$menuTable = new \Joomla\Component\Menus\Administrator\Table\MenuTypeTable($this->db);

		$menuData = array(
			'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  JTable|boolean  Menu Item Object. False otherwise.
	 *
	 * @since   4.0.0
	 */

	private function addAllCategoriesMenuItem($itemLanguage)
	{
		Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/Table/');

		// Add Menu Item.
		$tableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($this->db);

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

		$menuItem = array(
			'title'        => $title,
			'alias'        => $alias,
			'menutype'     => 'mainmenu-' . strtolower($itemLanguage->language),
			'type'         => 'component',
			'link'         => 'index.php?option=com_content&view=categories&id=0',
			'component_id' => 22,
			'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_columns":"","num_links":"",'
				. '"multi_column_order":"","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":"","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_icons":"","show_print_icon":"",'
				. '"show_email_icon":"","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":"","menu-meta_keywords":"","robots":"","secure":0}',
			'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  JTable|boolean  Menu Item Object. False otherwise.
	 *
	 * @since   4.0.0
	 */
	private function addBlogMenuItem($itemLanguage, $categoryId)
	{
		Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/Table/');

		// Add Menu Item.
		$tableItem = new \Joomla\Component\Menus\Administrator\Table\MenuTable($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 = array(
			'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' => 22,
			'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":"",'
				. '"page_subheading":"","num_leading_articles":"1","num_intro_articles":"3","num_columns":"3",'
				. '"num_links":"0","multi_column_order":"1","show_subcategory_content":"","orderby_pri":"",'
				. '"orderby_sec":"front","order_date":"","show_pagination":"2","show_pagination_results":"1",'
				. '"show_featured":"","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_icons":"","show_print_icon":"",'
				. '"show_email_icon":"","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":"","menu-meta_keywords":"","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 = Factory::getDbo();

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

			foreach ($associations as $language => $id)
			{
				$query->values(((int) $id) . ',' . $db->quote($context) . ',' . $db->quote($key));
			}

			$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    = Factory::getDbo();
		$query = $db->getQuery(true);

		// Add Module in Module menus.
		$query->clear()
			->insert($db->quoteName('#__modules_menu'))
			->columns(array($db->quoteName('moduleid'), $db->quoteName('menuid')))
			->values($moduleId . ', 0');
		$db->setQuery($query);

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

		return true;
	}

	/**
	 * Method to create a workflow for a specific language.
	 *
	 * @return  JTable|boolean  Workflow Object. False otherwise.
	 *
	 * @since   4.0.0
	 */
	public function addWorkflow()
	{
		$workflowModel =  $this->app->bootComponent('com_workflow')
			->getMVCFactory()->createModel('Workflow', 'Administrator');

		$workflow = [
			'title'       => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_TITLE'),
			'description' => Text::_('PLG_SAMPLEDATA_MULTILANG_CONTENT_WORKFLOW_DESCRIPTION'),
			'published'   => 1,
			'extension'   => 'com_content'
		];

		$workflowModel->save($workflow);

		$workflow = $workflowModel->getItem();

		$query = $this->db->getQuery(true)
				->select($this->db->quoteName('id'))
				->from($this->db->quoteName('#__workflow_stages'))
				->where($this->db->quoteName('workflow_id') . ' = ' . (int) $workflow->id)
				->where($this->db->quoteName('default') . ' = 1');

		$workflow->stageId = (int) $this->db->setQuery($query)->loadResult();

		return $workflow;
	}

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

		// Initialize a new category.
		$category = Table::getInstance('CategoryTable', '\\Joomla\\Component\\Categories\\Administrator\\Table\\');

		$data = array(
			'extension'       => 'com_content',
			'title'           => $title . ' (' . strtolower($itemLanguage->language) . ')',
			'description'     => '',
			'published'       => 1,
			'access'          => 1,
			'params'          => '{"target":"","image":"", "workflow_id":"' . (int) $workflowId . '"}',
			'metadesc'        => '',
			'metakey'         => '',
			'metadata'        => '{"page_title":"","author":"","robots":""}',
			'created_time'    => Factory::getDate()->toSql(),
			'created_user_id' => (int) $this->getAdminId(),
			'language'        => $itemLanguage->language,
			'rules'           => array(),
			'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.
	 * @param   integer   $stageId       The id of the initial stage.
	 *
	 * @return  JTable|boolean  Article Object. False otherwise.
	 *
	 * @since   4.0.0
	 */
	private function addArticle($itemLanguage, $categoryId, $stageId)
	{
		$db = Factory::getDbo();

		$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();

		// Initialize a new article.
		$article = Table::getInstance('ArticleTable', '\\Joomla\\Component\\Content\\Administrator\\Table\\');

		$data = array(
			'title'            => $title . ' (' . 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>',
			'images'           => json_encode(array()),
			'urls'             => json_encode(array()),
			'created'          => $currentDate,
			'created_by'       => (int) $this->getAdminId(),
			'created_by_alias' => 'Joomla',
			'publish_up'       => $currentDate,
			'publish_down'     => $db->getNullDate(),
			'version'          => 1,
			'catid'            => $categoryId,
			'metadata'         => '{"robots":"","author":"","rights":"","xreference":"","tags":null}',
			'metakey'          => '',
			'metadesc'         => '',
			'language'         => $itemLanguage->language,
			'featured'         => 1,
			'attribs'          => array(),
			'rules'            => array(),
		);

		// 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');

		$db->setQuery($query);

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

		$assoc = new stdClass;

		$assoc->item_id = $newId;
		$assoc->stage_id = $stageId;
		$assoc->extension = 'com_content';

		try
		{
			$db->insertObject('#__workflow_associations', $assoc);
		}
		catch (JDatabaseExceptionExecuting $e)
		{
			return false;
		}

		return $article;
	}

	/**
	 * Publish the Installed Content Languages.
	 *
	 * @return  boolean
	 *
	 * @since   4.0.0
	 */
	private function publishContentLanguages()
	{
		$app = Factory::getApplication();

		// Publish the Content Languages.
		$tableLanguage = Table::getInstance('Language');

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

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

				continue;
			}
		}

		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  $cms_client  Name of the cms client.
	 *
	 * @return  array
	 *
	 * @since   4.0.0
	 */
	protected function getInstalledlangs($cms_client = 'administrator')
	{
		// Get information.
		$path     = $this->getPath();
		$client   = $this->getClient($cms_client);
		$langlist = $this->getLanguageList($client->id);

		// Compute all the languages.
		$data = array();

		foreach ($langlist as $lang)
		{
			$file          = $path . '/' . $lang . '/' . $lang . '.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 = 0;
			$data[]           = $row;
		}

		usort($data, array($this, 'compareLanguages'));

		return $data;
	}

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

		// Select field element from the extensions table.
		$query->select($db->quoteName(array('element', 'name')))
			->from($db->quoteName('#__extensions'))
			->where($db->quoteName('type') . ' = ' . $db->quote('language'))
			->where($db->quoteName('state') . ' = 0')
			->where($db->quoteName('enabled') . ' = 1')
			->where($db->quoteName('client_id') . ' = ' . (int) $client_id);

		$db->setQuery($query);

		$this->langlist = $db->loadColumn();

		return $this->langlist;
	}

	/**
	 * 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')
	{
		$this->client = ApplicationHelper::getClientInfo($client, true);

		return $this->client;
	}

	/**
	 * 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    = Factory::getDbo();
		$query = $db->getQuery(true);

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

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

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

		return $id;
	}
}

No other release has this exact content. See every version of this file.