Файловый менеджер - Редактировать - /home/harasnat/www/mf/plugins.tar
Назад
sampledata/blog/src/Extension/Blog.php 0000644 00000250516 15062070550 0013752 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Sampledata.blog * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\SampleData\Blog\Extension; use Joomla\CMS\Application\ApplicationHelper; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Extension\ExtensionHelper; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Multilanguage; use Joomla\CMS\Language\Text; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Session\Session; use Joomla\Database\DatabaseAwareTrait; use Joomla\Database\ParameterType; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Sampledata - Blog Plugin * * @since 3.8.0 */ final class Blog extends CMSPlugin { use DatabaseAwareTrait; /** * Affects constructor behavior. If true, language files will be loaded automatically. * * @var boolean * * @since 3.8.0 */ protected $autoloadLanguage = true; /** * Holds the menuitem model * * @var \Joomla\Component\Menus\Administrator\Model\ItemModel * * @since 3.8.0 */ private $menuItemModel; /** * Get an overview of the proposed sampledata. * * @return \stdClass|void Will be converted into the JSON response to the module. * * @since 3.8.0 */ public function onSampledataGetOverview() { if (!$this->getApplication()->getIdentity()->authorise('core.create', 'com_content')) { return; } $data = new \stdClass(); $data->name = $this->_name; $data->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_OVERVIEW_TITLE'); $data->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_OVERVIEW_DESC'); $data->icon = 'wifi'; $data->steps = 4; return $data; } /** * First step to enter the sampledata. Content. * * @return array|void Will be converted into the JSON response to the module. * * @since 3.8.0 */ public function onAjaxSampledataApplyStep1() { if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_tags')) { $response = []; $response['success'] = true; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_tags'); return $response; } // Get some metadata. $access = (int) $this->getApplication()->get('access', 1); $user = $this->getApplication()->getIdentity(); // Detect language to be used. $language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*'; $langSuffix = ($language !== '*') ? ' (' . $language . ')' : ''; /** @var \Joomla\Component\Tags\Administrator\Model\TagModel $model */ $modelTag = $this->getApplication()->bootComponent('com_tags')->getMVCFactory() ->createModel('Tag', 'Administrator', ['ignore_request' => true]); $tagIds = []; // Create first three tags. for ($i = 0; $i <= 3; $i++) { $title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_TAG_' . $i . '_TITLE') . $langSuffix; $tag = [ 'id' => 0, 'title' => $title, 'alias' => ApplicationHelper::stringURLSafe($title), // Parent is root, except for the 4th tag. The 4th is child of the 3rd 'parent_id' => $i === 3 ? $tagIds[2] : 1, 'published' => 1, 'access' => $access, 'created_user_id' => $user->id, 'language' => $language, 'description' => '', ]; try { if (!$modelTag->save($tag)) { $this->getApplication()->getLanguage()->load('com_tags'); throw new \Exception($this->getApplication()->getLanguage()->_($modelTag->getError())); } } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage()); return $response; } $tagIds[] = $modelTag->getItem()->id; } if (!ComponentHelper::isEnabled('com_content') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_content')) { $response = []; $response['success'] = true; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_content'); return $response; } if (ComponentHelper::isEnabled('com_fields') && $user->authorise('core.create', 'com_fields')) { $this->getApplication()->getLanguage()->load('com_fields'); $mvcFactory = $this->getApplication()->bootComponent('com_fields')->getMVCFactory(); $groupModel = $mvcFactory->createModel('Group', 'Administrator', ['ignore_request' => true]); $group = [ 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_GROUP_TITLE') . $langSuffix, 'id' => 0, 'published' => 1, 'ordering' => 0, 'note' => '', 'state' => 1, 'access' => $access, 'created_user_id' => $user->id, 'context' => 'com_content.article', 'description' => '', 'language' => $language, 'params' => '{"display_readonly":"1"}', ]; try { if (!$groupModel->save($group)) { throw new \Exception($groupModel->getError()); } } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage()); return $response; } $groupId = $groupModel->getItem()->id; // Add fields $fieldIds = []; $articleFields = [ [ 'type' => 'textarea', 'fieldparams' => [ 'rows' => 3, 'cols' => 80, 'maxlength' => 400, 'filter' => '', ], ], ]; $fieldModel = $mvcFactory->createModel('Field', 'Administrator', ['ignore_request' => true]); foreach ($articleFields as $i => $cf) { // Set values from language strings. $cfTitle = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_FIELD_' . $i . '_TITLE') . $langSuffix; $cf['id'] = 0; $cf['name'] = $cfTitle; $cf['label'] = $cfTitle; $cf['title'] = $cfTitle; $cf['description'] = ''; $cf['note'] = ''; $cf['default_value'] = ''; $cf['group_id'] = $groupId; $cf['ordering'] = 0; $cf['state'] = 1; $cf['language'] = $language; $cf['access'] = $access; $cf['context'] = 'com_content.article'; $cf['params'] = [ 'hint' => '', 'class' => '', 'label_class' => '', 'show_on' => '', 'render_class' => '', 'showlabel' => '1', 'label_render_class' => '', 'display' => '3', 'prefix' => '', 'suffix' => '', 'layout' => '', 'display_readonly' => '2', ]; try { if (!$fieldModel->save($cf)) { throw new \Exception($fieldModel->getError()); } } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage()); return $response; } // Get ID from the field we just added $fieldIds[] = $fieldModel->getItem()->id; } } if (ComponentHelper::isEnabled('com_workflow') && $this->getApplication()->getIdentity()->authorise('core.create', 'com_workflow')) { $this->getApplication()->bootComponent('com_workflow'); // Create workflow $workflowTable = new \Joomla\Component\Workflow\Administrator\Table\WorkflowTable($this->getDatabase()); $workflowTable->default = 0; $workflowTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_TITLE') . $langSuffix; $workflowTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_DESCRIPTION'); $workflowTable->published = 1; $workflowTable->access = $access; $workflowTable->created_user_id = $user->id; $workflowTable->extension = 'com_content.article'; if (!$workflowTable->store()) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($workflowTable->getError())); return $response; } // Get ID from workflow we just added $workflowId = $workflowTable->id; // Create Stages. for ($i = 1; $i <= 9; $i++) { $stageTable = new \Joomla\Component\Workflow\Administrator\Table\StageTable($this->getDatabase()); // Set values from language strings. $stageTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_TITLE'); $stageTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_DESCRIPTION'); // Set values which are always the same. $stageTable->id = 0; $stageTable->published = 1; $stageTable->ordering = 0; $stageTable->default = $i == 6 ? 1 : 0; $stageTable->workflow_id = $workflowId; if (!$stageTable->store()) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($stageTable->getError())); return $response; } } // Get the stage Ids of the new stages $query = $this->getDatabase()->getQuery(true); $query->select([$this->getDatabase()->quoteName('title'), $this->getDatabase()->quoteName('id')]) ->from($this->getDatabase()->quoteName('#__workflow_stages')) ->where($this->getDatabase()->quoteName('workflow_id') . ' = :workflow_id') ->bind(':workflow_id', $workflowId, ParameterType::INTEGER); $stages = $this->getDatabase()->setQuery($query)->loadAssocList('title', 'id'); // Prepare Transitions $defaultOptions = json_encode( [ 'publishing' => 0, 'featuring' => 0, 'notification_send_mail' => false, ] ); $fromTo = [ [ // Idea to Copywriting 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')], 'options' => $defaultOptions, ], [ // Copywriting to Graphic Design 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')], 'options' => $defaultOptions, ], [ // Graphic Design to Fact Check 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')], 'options' => $defaultOptions, ], [ // Fact Check to Review 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')], 'options' => $defaultOptions, ], [ // Edit article - revision to copy writer 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')], 'options' => $defaultOptions, ], [ // Revision to published and featured 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')], 'options' => json_encode( [ 'publishing' => 1, 'featuring' => 1, 'notification_send_mail' => true, 'notification_text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'), 'notification_groups' => ["7"], ] ), ], [ // All to on Hold 'from_stage_id' => -1, 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')], 'options' => json_encode( [ 'publishing' => 2, 'featuring' => 0, 'notification_send_mail' => false, ] ), ], [ // Idea to trash 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')], 'options' => json_encode( [ 'publishing' => -2, 'featuring' => 0, 'notification_send_mail' => false, ] ), ], [ // On Hold to Idea (Re-activate an idea) 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')], 'options' => $defaultOptions, ], [ // Unpublish a published article 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')], 'options' => $defaultOptions, ], [ // Trash a published article 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')], 'options' => $defaultOptions, ], [ // From unpublished back to published 'from_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')], 'to_stage_id' => $stages[$this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')], 'options' => json_encode( [ 'publishing' => 1, 'featuring' => 0, 'notification_send_mail' => true, 'notification_text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'), 'notification_groups' => ["7"], ] ), ], ]; // Create Transitions. for ($i = 0; $i < count($fromTo); $i++) { $trTable = new \Joomla\Component\Workflow\Administrator\Table\TransitionTable($this->getDatabase()); $trTable->from_stage_id = $fromTo[$i]['from_stage_id']; $trTable->to_stage_id = $fromTo[$i]['to_stage_id']; $trTable->options = $fromTo[$i]['options']; // Set values from language strings. $trTable->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_TITLE'); $trTable->description = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_DESCRIPTION'); // Set values which are always the same. $trTable->id = 0; $trTable->published = 1; $trTable->ordering = 0; $trTable->workflow_id = $workflowId; if (!$trTable->store()) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($trTable->getError())); return $response; } } } // Store the categories $catIds = []; for ($i = 0; $i <= 3; $i++) { $categoryModel = $this->getApplication()->bootComponent('com_categories') ->getMVCFactory()->createModel('Category', 'Administrator'); $categoryTitle = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_' . $i . '_TITLE'); $categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle); // Set unicodeslugs if alias is empty if (trim(str_replace('-', '', $categoryAlias) == '')) { $unicode = $this->getApplication()->set('unicodeslugs', 1); $categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle); $this->getApplication()->set('unicodeslugs', $unicode); } // Category 0 gets the workflow from above $params = $i == 0 ? '{"workflow_id":"' . $workflowId . '"}' : '{}'; $category = [ 'title' => $categoryTitle . $langSuffix, 'parent_id' => 1, 'id' => 0, 'published' => 1, 'access' => $access, 'created_user_id' => $user->id, 'extension' => 'com_content', 'level' => 1, 'alias' => $categoryAlias . $langSuffix, 'associations' => [], 'description' => '', 'language' => $language, 'params' => $params, ]; try { if (!$categoryModel->save($category)) { $this->getApplication()->getLanguage()->load('com_categories'); throw new \Exception($categoryModel->getError()); } } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage()); return $response; } // Get ID from category we just added $catIds[] = $categoryModel->getItem()->id; } // Create Articles. $articles = [ // Category 1 = Help [ // Article 0 - About 'catid' => $catIds[1], ], [ // Article 1 - Working on Your Site 'catid' => $catIds[1], 'access' => 3, ], // Category 0 = Blog [ // Article 2 - Welcome to your blog 'catid' => $catIds[0], 'featured' => 1, 'tags' => array_map('strval', $tagIds), 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa1-1200.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-1200.jpg?width=1200&height=400', 'float_intro' => '', 'image_intro_alt' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_2_INTROIMAGE_ALT'), 'image_intro_alt_empty' => '', 'image_intro_caption' => '', 'image_fulltext' => 'images/sampledata/cassiopeia/nasa1-400.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-400.jpg?width=400&height=400', 'float_fulltext' => 'float-start', 'image_fulltext_alt' => '', 'image_fulltext_alt_empty' => 1, 'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery', ], ], [ // Article 3 - About your home page 'catid' => $catIds[0], 'featured' => 1, 'tags' => array_map('strval', $tagIds), 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa2-1200.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-1200.jpg?width=1200&height=400', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', 'image_fulltext' => 'images/sampledata/cassiopeia/nasa2-400.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-400.jpg?width=400&height=400', 'float_fulltext' => 'float-start', 'image_fulltext_alt' => '', 'image_fulltext_alt_empty' => 1, 'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery', ], 'authorValue' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_FIELD_0'), ], [ // Article 4 - Your Modules 'catid' => $catIds[0], 'featured' => 1, 'tags' => array_map('strval', $tagIds), 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa3-1200.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-1200.jpg?width=1200&height=400', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', 'image_fulltext' => 'images/sampledata/cassiopeia/nasa3-400.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-400.jpg?width=400&height=400', 'float_fulltext' => 'float-start', 'image_fulltext_alt' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_4_FULLTEXTIMAGE_ALT'), 'image_fulltext_alt_empty' => '', 'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery', ], ], [ // Article 5 - Your Template 'catid' => $catIds[0], 'featured' => 1, 'tags' => array_map('strval', $tagIds), 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa4-1200.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-1200.jpg?width=1200&height=400', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', 'image_fulltext' => 'images/sampledata/cassiopeia/nasa4-400.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400', 'float_fulltext' => 'float-start', 'image_fulltext_alt' => '', 'image_fulltext_alt_empty' => 1, 'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery', ], ], // Category 2 = Joomla - marketing texts [ // Article 6 - Millions 'catid' => $catIds[2], 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa1-640.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-640.jpg?width=640&height=320', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', ], ], [ // Article 7 - Love 'catid' => $catIds[2], 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa2-640.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-640.jpg?width=640&height=320', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', ], ], [ // Article 8 - Joomla 'catid' => $catIds[2], 'images' => [ 'image_intro' => 'images/sampledata/cassiopeia/nasa3-640.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-640.jpg?width=640&height=320', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => 1, 'image_intro_caption' => '', ], ], [ // Article 9 - Workflows 'catid' => $catIds[1], 'images' => [ 'image_intro' => '', 'float_intro' => '', 'image_intro_alt' => '', 'image_intro_alt_empty' => '', 'image_intro_caption' => '', 'image_fulltext' => 'images/sampledata/cassiopeia/nasa4-400.jpg#' . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400', 'float_fulltext' => 'float-end', 'image_fulltext_alt' => '', 'image_fulltext_alt_empty' => 1, 'image_fulltext_caption' => 'www.nasa.gov/multimedia/imagegallery', ], 'authorValue' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_FIELD_0'), ], // Category 3 - Typography [ // Article 10 - Typography 'catid' => $catIds[3], ], ]; $mvcFactory = $this->getApplication()->bootComponent('com_content')->getMVCFactory(); // Store the articles foreach ($articles as $i => $article) { $articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]); // Set values from language strings. $title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_TITLE'); $alias = ApplicationHelper::stringURLSafe($title); $article['title'] = $title . $langSuffix; $article['introtext'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_INTROTEXT'); $article['fulltext'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_FULLTEXT'); // Set values which are always the same. $article['id'] = 0; $article['ordering'] = 0; $article['created_user_id'] = $user->id; $article['created_by_alias'] = 'Joomla'; $article['alias'] = ApplicationHelper::stringURLSafe($article['title']); // Set unicodeslugs if alias is empty if (trim(str_replace('-', '', $alias) == '')) { $unicode = $this->getApplication()->set('unicodeslugs', 1); $article['alias'] = ApplicationHelper::stringURLSafe($article['title']); $this->getApplication()->set('unicodeslugs', $unicode); } $article['language'] = $language; $article['associations'] = []; $article['metakey'] = ''; $article['metadesc'] = ''; if (!isset($article['featured'])) { $article['featured'] = 0; } if (!isset($article['state'])) { $article['state'] = 1; } if (!isset($article['images'])) { $article['images'] = ''; } if (!isset($article['access'])) { $article['access'] = $access; } if (!$articleModel->save($article)) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $this->getApplication()->getLanguage()->_($articleModel->getError())); return $response; } // Get ID from article we just added $ids[] = $articleModel->getItem()->id; if ( $article['featured'] && ComponentHelper::isEnabled('com_workflow') && PluginHelper::isEnabled('workflow', 'featuring') && ComponentHelper::getParams('com_content')->get('workflow_enabled') ) { // Set the article featured in #__content_frontpage $this->getDatabase()->getQuery(true); $featuredItem = (object) [ 'content_id' => $articleModel->getItem()->id, 'ordering' => 0, 'featured_up' => null, 'featured_down' => null, ]; $this->getDatabase()->insertObject('#__content_frontpage', $featuredItem); } // Add a value to the custom field if a value is given if (ComponentHelper::isEnabled('com_fields') && $this->getApplication()->getIdentity()->authorise('core.create', 'com_fields')) { if (!empty($article['authorValue'])) { // Store a field value $valueAuthor = (object) [ 'item_id' => $articleModel->getItem()->id, 'field_id' => $fieldIds[0], 'value' => $article['authorValue'], ]; $this->getDatabase()->insertObject('#__fields_values', $valueAuthor); } } } $this->getApplication()->setUserState('sampledata.blog.articles', $ids); $this->getApplication()->setUserState('sampledata.blog.articles.catIds', $catIds); $response = []; $response['success'] = true; $response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP1_SUCCESS'); return $response; } /** * Second step to enter the sampledata. Menus. * * @return array|void Will be converted into the JSON response to the module. * * @since 3.8.0 */ public function onAjaxSampledataApplyStep2() { if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_menus') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_menus')) { $response = []; $response['success'] = true; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 2, 'com_menus'); return $response; } // Detect language to be used. $language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*'; $langSuffix = ($language !== '*') ? ' (' . $language . ')' : ''; // Create the menu types. $menuTable = new \Joomla\Component\Menus\Administrator\Table\MenuTypeTable($this->getDatabase()); $menuTypes = []; for ($i = 0; $i <= 2; $i++) { $title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_TITLE'); $menu = [ 'id' => 0, 'title' => $title . ' ' . $langSuffix, 'description' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_DESCRIPTION'), ]; // Calculate menutype. The maximum number of characters allowed is 24. $menu['menutype'] = $i . HTMLHelper::_('string.truncate', $title, 16, true, false) . $langSuffix; try { $menuTable->load(); $menuTable->bind($menu); if (!$menuTable->check()) { $this->getApplication()->getLanguage()->load('com_menu'); throw new \Exception($menuTable->getError()); } $menuTable->store(); } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage()); return $response; } $menuTypes[] = $menuTable->menutype; } // Storing IDs in UserState for later usage. $this->getApplication()->setUserState('sampledata.blog.menutypes', $menuTypes); // Get previously entered Data from UserStates. $articleIds = $this->getApplication()->getUserState('sampledata.blog.articles'); // Get MenuItemModel. $this->menuItemModel = $this->getApplication()->bootComponent('com_menus')->getMVCFactory() ->createModel('Item', 'Administrator', ['ignore_request' => true]); // Get previously entered categories ids $catIds = $this->getApplication()->getUserState('sampledata.blog.articles.catIds'); // Link to the homepage from logout $home = $this->getApplication()->getMenu('site')->getDefault()->id; if (Multilanguage::isEnabled()) { $homes = Multilanguage::getSiteHomePages(); if (isset($homes[$language])) { $home = $homes[$language]->id; } } // Insert menuitems level 1. $menuItems = [ [ // Blog 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'), 'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'layout_type' => 'blog', 'show_category_title' => 0, 'num_leading_articles' => 4, 'num_intro_articles' => 4, 'num_links' => 0, 'orderby_sec' => 'rdate', 'order_date' => 'published', 'blog_class_leading' => 'boxed columns-2', 'show_pagination' => 2, 'secure' => 0, 'show_page_heading' => 1, ], ], [ // Help 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE'), 'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[1], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'blog_class_leading' => '', 'blog_class' => 'boxed', 'num_leading_articles' => 0, 'num_intro_articles' => 4, 'num_links' => 0, 'orderby_sec' => 'rdate', 'order_date' => 'published', 'show_pagination' => 4, 'show_pagination_results' => 1, 'article_layout' => '_:default', 'link_titles' => 0, 'info_block_show_title' => '', 'show_category' => 0, 'link_category' => '', 'show_parent_category' => '', 'link_parent_category' => '', 'show_author' => 0, 'link_author' => '', 'show_create_date' => 0, 'show_modify_date' => '', 'show_publish_date' => 0, 'show_hits' => 0, 'menu_text' => 1, 'menu_show' => 1, 'show_page_heading' => 1, 'secure' => 0, ], ], [ // Login 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_2_TITLE'), 'link' => 'index.php?option=com_users&view=login', 'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id, 'access' => 5, 'params' => [ 'loginredirectchoice' => '1', 'login_redirect_url' => '', 'login_redirect_menuitem' => $home, 'logoutredirectchoice' => '1', 'logout_redirect_url' => '', 'logout_redirect_menuitem' => $home, 'secure' => 0, ], ], [ // Logout 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'), 'link' => 'index.php?option=com_users&view=login&layout=logout&task=user.menulogout', 'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id, 'access' => 2, 'params' => [ 'logout' => $home, 'secure' => 0, ], ], [ // Sample metismenu (heading) 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_11_TITLE'), 'type' => 'heading', 'link' => '', 'component_id' => 0, 'params' => [ 'layout_type' => 'heading', 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ // Typography 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_14_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'show_title' => 0, 'link_titles' => 0, 'show_intro' => 1, 'info_block_position' => '', 'info_block_show_title' => 0, 'show_category' => 0, 'show_author' => 0, 'show_create_date' => 0, 'show_modify_date' => 0, 'show_publish_date' => 0, 'show_item_navigation' => 0, 'show_hits' => 0, 'show_tags' => 0, 'menu_text' => 1, 'menu_show' => 1, 'page_title' => '', 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_3_TITLE'), 'link' => 'index.php?option=com_content&view=form&layout=edit', 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'access' => 3, 'params' => [ 'enable_category' => 1, 'catid' => $catIds[0], 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_4_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . $articleIds[1], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_5_TITLE'), 'link' => 'administrator', 'type' => 'url', 'component_id' => 0, 'browserNav' => 1, 'access' => 3, 'params' => [ 'menu_text' => 1, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_6_TITLE'), 'link' => 'index.php?option=com_users&view=profile&layout=edit', 'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id, 'access' => 2, 'params' => [ 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_7_TITLE'), 'link' => 'index.php?option=com_users&view=login', 'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id, 'params' => [ 'logindescription_show' => 1, 'logoutdescription_show' => 1, 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], ]; try { $menuIdsLevel1 = $this->addMenuItems($menuItems, 1); } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage()); return $response; } // Insert level 1 (Link in the footer as alias) $menuItems = [ [ 'menutype' => $menuTypes[2], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_8_TITLE'), 'link' => 'index.php?Itemid=', 'type' => 'alias', 'access' => 5, 'params' => [ 'aliasoptions' => $menuIdsLevel1[2], 'alias_redirect' => 0, 'menu-anchor_title' => '', 'menu-anchor_css' => '', 'menu_image' => '', 'menu_image_css' => '', 'menu_text' => 1, 'menu_show' => 1, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[2], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'), 'link' => 'index.php?Itemid=', 'type' => 'alias', 'access' => 2, 'params' => [ 'aliasoptions' => $menuIdsLevel1[3], 'alias_redirect' => 0, 'menu-anchor_title' => '', 'menu-anchor_css' => '', 'menu_image' => '', 'menu_image_css' => '', 'menu_text' => 1, 'menu_show' => 1, 'secure' => 0, ], ], [ // Hidden menuItem search 'menutype' => $menuTypes[2], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_15_TITLE'), 'link' => 'index.php?option=com_finder&view=search', 'type' => 'component', 'component_id' => ExtensionHelper::getExtensionRecord('com_finder', 'component')->extension_id, 'params' => [ 'show_date_filters' => '1', 'show_advanced' => '', 'expand_advanced' => '1', 'show_taxonomy' => '1', 'show_date' => '1', 'show_url' => '1', 'menu_text' => 0, 'menu_show' => 0, 'secure' => 0, ], ], ]; try { $menuIdsLevel1 = array_merge($menuIdsLevel1, $this->addMenuItems($menuItems, 1)); } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage()); return $response; } $this->getApplication()->setUserState('sampledata.blog.menuIdsLevel1', $menuIdsLevel1); // Insert menuitems level 2. $menuItems = [ [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_9_TITLE'), 'link' => 'index.php?option=com_config&view=config', 'parent_id' => $menuIdsLevel1[6], 'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id, 'access' => 6, 'params' => [ 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[1], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_10_TITLE'), 'link' => 'index.php?option=com_config&view=templates', 'parent_id' => $menuIdsLevel1[6], 'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id, 'access' => 6, 'params' => [ 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ // Blog 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'), 'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0], 'parent_id' => $menuIdsLevel1[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'layout_type' => 'blog', 'show_category_title' => 0, 'num_leading_articles' => 1, 'num_intro_articles' => 2, 'num_links' => 2, 'orderby_sec' => 'front', 'order_date' => 'published', 'blog_class_leading' => 'boxed columns-1', 'blog_class' => 'columns-2', 'show_pagination' => 2, 'show_pagination_results' => 1, 'show_category' => 0, 'info_bloc_position' => 0, 'show_publish_date' => 0, 'show_hits' => 0, 'show_feed_link' => 0, 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ // Category List 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_12_TITLE'), 'link' => 'index.php?option=com_content&view=category&id=' . $catIds[0], 'parent_id' => $menuIdsLevel1[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_text' => 1, 'show_page_heading' => 1, 'secure' => 0, ], ], [ // Articles (menu header) 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_13_TITLE'), 'link' => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[2], 'parent_id' => $menuIdsLevel1[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'layout_type' => 'blog', 'show_category_title' => 0, 'num_leading_articles' => 3, 'num_intro_articles' => 0, 'num_links' => 2, 'orderby_sec' => 'front', 'order_date' => 'published', 'blog_class_leading' => 'boxed columns-3', 'blog_class' => '', 'show_pagination' => 2, 'show_pagination_results' => 1, 'show_category' => 0, 'info_bloc_position' => 0, 'show_publish_date' => 0, 'show_hits' => 0, 'show_feed_link' => 0, 'menu_text' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[3], 'parent_id' => $menuIdsLevel1[1], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_show' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[9], 'parent_id' => $menuIdsLevel1[1], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_show' => 1, 'show_page_heading' => 0, 'secure' => 0, ], ], ]; try { $menuIdsLevel2 = $this->addMenuItems($menuItems, 2); } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage()); return $response; } // Add a third level of menuItems - use article title also for menuItem title $menuItems = [ [ 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_6_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[6], 'parent_id' => $menuIdsLevel2[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_show' => 1, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_7_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[7], 'parent_id' => $menuIdsLevel2[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_show' => 1, 'secure' => 0, ], ], [ 'menutype' => $menuTypes[0], 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_8_TITLE'), 'link' => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[8], 'parent_id' => $menuIdsLevel2[4], 'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id, 'params' => [ 'menu_show' => 1, 'secure' => 0, ], ], ]; try { $this->addMenuItems($menuItems, 3); } catch (\Exception $e) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage()); return $response; } $response = []; $response['success'] = true; $response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP2_SUCCESS'); return $response; } /** * Third step to enter the sampledata. Modules. * * @return array|void Will be converted into the JSON response to the module. * * @since 3.8.0 */ public function onAjaxSampledataApplyStep3() { if (!Session::checkToken('get') || $this->getApplication()->getInput()->get('type') != $this->_name) { return; } $this->getApplication()->getLanguage()->load('com_modules'); if (!ComponentHelper::isEnabled('com_modules') || !$this->getApplication()->getIdentity()->authorise('core.create', 'com_modules')) { $response = []; $response['success'] = true; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 3, 'com_modules'); return $response; } // Detect language to be used. $language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*'; $langSuffix = ($language !== '*') ? ' (' . $language . ')' : ''; // Add Include Paths. /** @var \Joomla\Component\Modules\Administrator\Model\ModuleModel $model */ $model = $this->getApplication()->bootComponent('com_modules')->getMVCFactory() ->createModel('Module', 'Administrator', ['ignore_request' => true]); $access = (int) $this->getApplication()->get('access', 1); // Get previously entered Data from UserStates. $articleIds = $this->getApplication()->getUserState('sampledata.blog.articles'); // Get previously entered Data from UserStates $menuTypes = $this->getApplication()->getUserState('sampledata.blog.menutypes'); // Get previously entered categories ids $catIds = $this->getApplication()->getUserState('sampledata.blog.articles.catIds'); // Link to article "typography" in banner module $headerLink = 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3]; $modules = [ [ // The main menu Blog 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_0_TITLE'), 'ordering' => 1, 'position' => 'menu', 'module' => 'mod_menu', 'showtitle' => 0, 'params' => [ 'menutype' => $menuTypes[0], 'layout' => 'cassiopeia:collapse-metismenu', 'startLevel' => 1, 'endLevel' => 0, 'showAllChildren' => 1, 'class_sfx' => '', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'itemid', 'module_tag' => 'nav', 'bootstrap_size' => 0, 'header_tag' => 'h3', 'style' => 0, ], ], [ // The author Menu, for registered users 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_1_TITLE'), 'ordering' => 1, 'position' => 'sidebar-right', 'module' => 'mod_menu', 'access' => 3, 'showtitle' => 0, 'params' => [ 'menutype' => $menuTypes[1], 'startLevel' => 1, 'endLevel' => 0, 'showAllChildren' => 1, 'class_sfx' => '', 'layout' => '_:default', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'itemid', 'module_tag' => 'aside', 'bootstrap_size' => 0, 'header_tag' => 'h3', 'style' => 0, ], ], [ // Syndication 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_2_TITLE'), 'ordering' => 6, 'position' => 'sidebar-right', 'module' => 'mod_syndicate', 'showtitle' => 0, 'params' => [ 'display_text' => 1, 'text' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_NEWSFEEDS_TITLE'), 'format' => 'rss', 'layout' => '_:default', 'cache' => 0, 'module_tag' => 'section', ], ], [ // Archived Articles 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_3_TITLE'), 'ordering' => 4, 'position' => 'sidebar-right', 'module' => 'mod_articles_archive', 'params' => [ 'count' => 10, 'layout' => '_:default', 'cache' => 1, 'cache_time' => 900, 'module_tag' => 'div', 'cachemode' => 'static', ], ], [ // Latest Posts 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_4_TITLE'), 'ordering' => 6, 'position' => 'top-a', 'module' => 'mod_articles_news', // Assignment 1 means here - only on the homepage 'assignment' => 1, 'showtitle' => 0, 'params' => [ 'catid' => $catIds[2], 'image' => 1, 'img_intro_full' => 'intro', 'item_title' => 0, 'link_titles' => '', 'item_heading' => 'h4', 'triggerevents' => 1, 'showLastSeparator' => 1, 'show_introtext' => 1, 'readmore' => 1, 'count' => 3, 'show_featured' => '', 'exclude_current' => 0, 'ordering' => 'a.publish_up', 'direction' => 1, 'layout' => '_:horizontal', 'moduleclass_sfx' => '', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'itemid', 'style' => 'Cassiopeia-noCard', 'module_tag' => 'div', 'bootstrap_size' => '0', 'header_tag' => 'h3', 'header_class' => '', ], ], [ // Older Posts (from category 0 = blog) 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_5_TITLE'), 'ordering' => 2, 'position' => 'bottom-b', 'module' => 'mod_articles_category', 'params' => [ 'mode' => 'normal', 'show_on_article_page' => 0, 'show_front' => 'show', 'count' => 6, 'category_filtering_type' => 1, 'catid' => $catIds[0], 'show_child_category_articles' => 0, 'levels' => 1, 'author_filtering_type' => 1, 'author_alias_filtering_type' => 1, 'date_filtering' => 'off', 'date_field' => 'a.created', 'relative_date' => 30, 'article_ordering' => 'a.created', 'article_ordering_direction' => 'DESC', 'article_grouping' => 'none', 'article_grouping_direction' => 'krsort', 'month_year_format' => 'F Y', 'item_heading' => 5, 'link_titles' => 1, 'show_date' => 0, 'show_date_field' => 'created', 'show_date_format' => $this->getApplication()->getLanguage()->_('DATE_FORMAT_LC5'), 'show_category' => 0, 'show_hits' => 0, 'show_author' => 0, 'show_introtext' => 0, 'introtext_limit' => 100, 'show_readmore' => 0, 'show_readmore_title' => 1, 'readmore_limit' => 15, 'layout' => '_:default', 'owncache' => 1, 'cache_time' => 900, 'module_tag' => 'div', 'bootstrap_size' => 4, 'header_tag' => 'h3', 'style' => 0, ], ], [ // Bottom Menu 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_6_TITLE'), 'ordering' => 1, 'position' => 'footer', 'module' => 'mod_menu', 'showtitle' => 0, 'params' => [ 'menutype' => $menuTypes[2], 'class_sfx' => 'menu-horizontal', 'startLevel' => 1, 'endLevel' => 0, 'showAllChildren' => 0, 'layout' => 'cassiopeia:dropdown-metismenu', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'itemid', 'module_tag' => 'div', 'bootstrap_size' => 0, 'header_tag' => 'h3', 'style' => 0, ], ], [ // Search 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'), 'ordering' => 1, 'position' => 'search', 'module' => 'mod_finder', 'params' => [ 'searchfilter' => '', 'show_autosuggest' => 1, 'show_advanced' => 0, 'show_label' => 0, 'alt_label' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'), 'show_button' => 1, 'opensearch' => 1, 'opensearch_name' => '', 'set_itemid' => 0, 'layout' => '_:default', 'module_tag' => 'search', ], ], [ // Header image 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_TITLE'), 'content' => '<p>' . Text::sprintf('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_CONTENT', $headerLink) . '</p>', 'ordering' => 1, 'position' => 'banner', 'module' => 'mod_custom', // Assignment 1 means here - only on the homepage 'assignment' => 1, 'showtitle' => 0, 'params' => [ 'prepare_content' => 0, 'backgroundimage' => 'images/banners/banner.jpg#joomlaImage://local-images/banners/banner.jpg?width=1140&height=600', 'layout' => 'cassiopeia:banner', 'moduleclass_sfx' => '', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'static', 'style' => '0', 'module_tag' => 'div', 'bootstrap_size' => '0', 'header_tag' => 'h3', 'header_class' => '', ], ], [ // Popular Tags 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_9_TITLE'), 'ordering' => 1, 'position' => 'bottom-b', 'module' => 'mod_tags_popular', 'params' => [ 'maximum' => 8, 'timeframe' => 'alltime', 'order_value' => 'count', 'order_direction' => 1, 'display_count' => 1, 'no_results_text' => 0, 'minsize' => 1, 'maxsize' => 2, 'layout' => '_:cloud', 'owncache' => 1, 'module_tag' => 'aside', 'bootstrap_size' => 4, 'header_tag' => 'h3', 'style' => 0, ], ], [ // Similar Items 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_10_TITLE'), 'ordering' => 0, 'module' => 'mod_tags_similar', 'position' => 'bottom-b', 'params' => [ 'maximum' => 5, 'matchtype' => 'any', 'layout' => '_:default', 'owncache' => 1, 'module_tag' => 'div', 'bootstrap_size' => 4, 'header_tag' => 'h3', 'style' => 0, ], ], [ // Backend - Site Information 'title' => $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_11_TITLE'), 'ordering' => 4, 'position' => 'cpanel', 'module' => 'mod_stats_admin', 'access' => 6, 'client_id' => 1, 'params' => [ 'serverinfo' => 1, 'siteinfo' => 1, 'counter' => 0, 'increase' => 0, 'layout' => '_:default', 'cache' => 1, 'cache_time' => 900, 'cachemode' => 'static', 'module_tag' => 'div', 'bootstrap_size' => 0, 'header_tag' => 'h3', 'style' => 0, ], ], ]; // Assignment means always "only on the homepage". if (Multilanguage::isEnabled()) { $homes = Multilanguage::getSiteHomePages(); if (isset($homes[$language])) { $home = $homes[$language]->id; } } if (!isset($home)) { $home = $this->getApplication()->getMenu('site')->getDefault()->id; } foreach ($modules as $module) { // Append language suffix to title. $module['title'] .= $langSuffix; // Set values which are always the same. $module['id'] = 0; $module['asset_id'] = 0; $module['language'] = $language; $module['note'] = ''; $module['published'] = 1; if (!isset($module['assignment'])) { $module['assignment'] = 0; } else { $module['assigned'] = [$home]; } if (!isset($module['content'])) { $module['content'] = ''; } if (!isset($module['access'])) { $module['access'] = $access; } if (!isset($module['showtitle'])) { $module['showtitle'] = 1; } if (!isset($module['client_id'])) { $module['client_id'] = 0; } if (!$model->save($module)) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, $this->getApplication()->getLanguage()->_($model->getError())); return $response; } } // Get previously entered categories ids $menuIdsLevel1 = $this->getApplication()->getUserState('sampledata.blog.menuIdsLevel1'); // Get the login modules there could be more than one $MVCFactory = $this->getApplication()->bootComponent('com_modules')->getMVCFactory(); $modelModules = $MVCFactory->createModel('Modules', 'Administrator', ['ignore_request' => true]); $modelModules->setState('filter.module', 'mod_login'); $modelModules->setState('filter.client_id', 1); $loginModules = $modelModules->getItems(); if (!empty($loginModules)) { $modelModule = $MVCFactory->createModel('Module', 'Administrator', ['ignore_request' => true]); foreach ($loginModules as $loginModule) { $lm = (array) $loginModule; // Un-assign the module from login view, to avoid 403 error $lm['assignment'] = 1; $loginId = - (int) $menuIdsLevel1[2]; $lm['assigned'] = [$loginId]; if (!$modelModule->save($lm)) { $response = []; $response['success'] = false; $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, $this->getApplication()->getLanguage()->_($model->getError())); return $response; } } } $response = []; $response['success'] = true; $response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP3_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 onAjaxSampledataApplyStep4() { if ($this->getApplication()->getInput()->get('type') != $this->_name) { return; } $response['success'] = true; $response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_BLOG_STEP4_SUCCESS'); return $response; } /** * Adds menuitems. * * @param array $menuItems Array holding the menuitems arrays. * @param integer $level Level in the category tree. * * @return array IDs of the inserted menuitems. * * @since 3.8.0 * * @throws \Exception */ private function addMenuItems(array $menuItems, $level) { $itemIds = []; $access = (int) $this->getApplication()->get('access', 1); $user = $this->getApplication()->getIdentity(); // Detect language to be used. $language = Multilanguage::isEnabled() ? $this->getApplication()->getLanguage()->getTag() : '*'; $langSuffix = ($language !== '*') ? ' (' . $language . ')' : ''; foreach ($menuItems as $menuItem) { // Reset item.id in model state. $this->menuItemModel->setState('item.id', 0); // Set values which are always the same. $menuItem['id'] = 0; $menuItem['created_user_id'] = $user->id; $menuItem['alias'] = ApplicationHelper::stringURLSafe($menuItem['title']); // Set unicodeslugs if alias is empty if (trim(str_replace('-', '', $menuItem['alias']) == '')) { $unicode = $this->getApplication()->set('unicodeslugs', 1); $menuItem['alias'] = ApplicationHelper::stringURLSafe($menuItem['title']); $this->getApplication()->set('unicodeslugs', $unicode); } // Append language suffix to title. $menuItem['title'] .= $langSuffix; $menuItem['published'] = 1; $menuItem['language'] = $language; $menuItem['note'] = ''; $menuItem['img'] = ''; $menuItem['associations'] = []; $menuItem['client_id'] = 0; $menuItem['level'] = $level; $menuItem['home'] = 0; // Set browserNav to default if not set if (!isset($menuItem['browserNav'])) { $menuItem['browserNav'] = 0; } // Set access to default if not set if (!isset($menuItem['access'])) { $menuItem['access'] = $access; } // Set type to 'component' if not set if (!isset($menuItem['type'])) { $menuItem['type'] = 'component'; } // Set template_style_id to global if not set if (!isset($menuItem['template_style_id'])) { $menuItem['template_style_id'] = 0; } // Set parent_id to root (1) if not set if (!isset($menuItem['parent_id'])) { $menuItem['parent_id'] = 1; } if (!$this->menuItemModel->save($menuItem)) { // Try two times with another alias (-1 and -2). $menuItem['alias'] .= '-1'; if (!$this->menuItemModel->save($menuItem)) { $menuItem['alias'] = substr_replace($menuItem['alias'], '2', -1); if (!$this->menuItemModel->save($menuItem)) { throw new \Exception($menuItem['title'] . ' => ' . $menuItem['alias'] . ' : ' . $this->menuItemModel->getError()); } } } // Get ID from menuitem we just added $itemIds[] = $this->menuItemModel->getState('item.id'); } return $itemIds; } } sampledata/blog/blog.xml 0000644 00000001632 15062070550 0011251 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="sampledata" method="upgrade"> <name>plg_sampledata_blog</name> <author>Joomla! Project</author> <creationDate>2017-07</creationDate> <copyright>(C) 2017 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.8.0</version> <description>PLG_SAMPLEDATA_BLOG_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\SampleData\Blog</namespace> <files> <folder plugin="blog">services</folder> <folder>src</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_sampledata_blog.ini</language> <language tag="en-GB">language/en-GB/plg_sampledata_blog.sys.ini</language> </languages> <config> <fields name="params"> </fields> </config> </extension> sampledata/blog/services/provider.php 0000644 00000002637 15062070550 0014000 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Sampledata.blog * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\Database\DatabaseInterface; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\SampleData\Blog\Extension\Blog; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.4.0 */ public function register(Container $container): void { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Blog( $dispatcher, (array) PluginHelper::getPlugin('sampledata', 'blog') ); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class)); return $plugin; } ); } }; sampledata/multilang/multilang.xml 0000644 00000001674 15062070550 0013401 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="sampledata" method="upgrade"> <name>plg_sampledata_multilang</name> <author>Joomla! Project</author> <creationDate>2018-07</creationDate> <copyright>(C) 2018 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>4.0.0</version> <description>PLG_SAMPLEDATA_MULTILANG_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\SampleData\MultiLanguage</namespace> <files> <folder plugin="multilang">services</folder> <folder>src</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_sampledata_multilang.ini</language> <language tag="en-GB">language/en-GB/plg_sampledata_multilang.sys.ini</language> </languages> <config> <fields name="params"> </fields> </config> </extension> sampledata/multilang/src/Extension/MultiLanguage.php 0000644 00000126131 15062070550 0016671 0 ustar 00 <?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 */ namespace Joomla\Plugin\SampleData\MultiLanguage\Extension; 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\DatabaseAwareTrait; 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 */ final class MultiLanguage extends CMSPlugin { use DatabaseAwareTrait; /** * 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->getApplication()->getIdentity()->authorise('core.create', 'com_content')) { return; } $data = new \stdClass(); $data->name = $this->_name; $data->title = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_MULTILANG_OVERVIEW_TITLE'); $data->description = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') != $this->_name) { return; } $languages = LanguageHelper::getContentLanguages([0, 1]); if (count($languages) < 2) { $response = []; $response['success'] = false; $response['message'] = $this->getApplication()->getLanguage()->_('PLG_SAMPLEDATA_MULTILANG_MISSING_LANGUAGE'); return $response; } if (!$this->enablePlugin('plg_system_languagefilter')) { $response = []; $response['success'] = false; $lang = $this->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_modules') || !$this->getApplication()->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->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_menus') || !$this->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_modules') || !$this->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') != $this->_name) { return; } if (!ComponentHelper::isEnabled('com_content') || !$this->getApplication()->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->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->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'] = $this->getApplication()->getLanguage()->_('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->getApplication()->getInput()->get('type') !== $this->_name) { return; } $response['success'] = true; $response['message'] = $this->getApplication()->getLanguage()->_('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->getDatabase(); $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->getDatabase(); $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->getApplication()->bootComponent('com_menus')->getMVCFactory()->createTable('MenuType', 'Administrator', ['dbo' => $this->getDatabase()]); $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->getApplication()->bootComponent('com_menus')->getMVCFactory()->createTable('Menu', 'Administrator', ['dbo' => $this->getDatabase()]); $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->getApplication()->bootComponent('com_menus')->getMVCFactory()->createTable('Menu', 'Administrator', ['dbo' => $this->getDatabase()]); $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->getDatabase(); 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->getDatabase(); $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->getApplication()->bootComponent('com_categories')->getMVCFactory()->createTable('Category', 'Administrator', ['dbo' => $this->getDatabase()]); $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->getDatabase(); $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->getApplication()->set('unicodeslugs', 1); $alias = ApplicationHelper::stringURLSafe($title); $this->getApplication()->set('unicodeslugs', $unicode); } // Initialize a new article. $article = $this->getApplication()->bootComponent('com_content')->getMVCFactory()->createTable('Article', 'Administrator', ['dbo' => $this->getDatabase()]); $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->getApplication(), $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->getApplication()->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->getDatabase(); $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->getDatabase(); $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; } } sampledata/multilang/services/provider.php 0000644 00000002704 15062070550 0015044 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Sampledata.multilang * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\Database\DatabaseInterface; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\SampleData\MultiLanguage\Extension\MultiLanguage; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.4.0 */ public function register(Container $container): void { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new MultiLanguage( $dispatcher, (array) PluginHelper::getPlugin('sampledata', 'multilang') ); $plugin->setApplication(Factory::getApplication()); $plugin->setDatabase($container->get(DatabaseInterface::class)); return $plugin; } ); } }; fields/imagelist/src/Extension/Imagelist.php 0000644 00000002522 15062070550 0015163 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.imagelist * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Imagelist\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Imagelist Plugin * * @since 3.7.0 */ final class Imagelist extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('hide_default', 'true'); $fieldNode->setAttribute('directory', '/images/' . $fieldNode->getAttribute('directory')); return $fieldNode; } } fields/imagelist/params/imagelist.xml 0000644 00000001713 15062070550 0013755 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="directory" type="folderlist" label="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_LABEL" description="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_DESC" directory="images" hide_none="true" hide_default="true" recursive="true" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="/">/</option> </field> <field name="multiple" type="list" label="PLG_FIELDS_IMAGELIST_PARAMS_MULTIPLE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> <field name="image_class" type="textarea" label="PLG_FIELDS_IMAGELIST_PARAMS_IMAGE_CLASS_LABEL" validate="CssIdentifier" /> </fieldset> </fields> </form> fields/imagelist/imagelist.xml 0000644 00000003436 15062070550 0012476 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_imagelist</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_IMAGELIST_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Imagelist</namespace> <files> <folder>params</folder> <folder plugin="imagelist">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_imagelist.ini</language> <language tag="en-GB">language/en-GB/plg_fields_imagelist.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="directory" type="folderlist" label="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_LABEL" description="PLG_FIELDS_IMAGELIST_PARAMS_DIRECTORY_DESC" directory="images" hide_none="true" hide_default="true" recursive="true" default="/" validate="options" > <option value="/">/</option> </field> <field name="multiple" type="radio" label="PLG_FIELDS_IMAGELIST_PARAMS_MULTIPLE_LABEL" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> <field name="image_class" type="textarea" label="PLG_FIELDS_IMAGELIST_PARAMS_IMAGE_CLASS_LABEL" validate="CssIdentifier" /> </fieldset> </fields> </config> </extension> fields/imagelist/services/provider.php 0000644 00000002456 15062070550 0014165 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.imagelist * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Imagelist\Extension\Imagelist; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Imagelist( $dispatcher, (array) PluginHelper::getPlugin('fields', 'imagelist') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/imagelist/tmpl/imagelist.php 0000644 00000003035 15062070550 0013434 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Imagelist * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Image\Image; if ($field->value == '') { return; } $class = $fieldParams->get('image_class'); if ($class) { // space before, so if no class sprintf below works $class = ' class="' . htmlentities($class, ENT_COMPAT, 'UTF-8', true) . '"'; } $value = (array) $field->value; $buffer = ''; foreach ($value as $path) { if (!$path || $path == '-1') { continue; } $imageFilePath = htmlentities($path, ENT_COMPAT, 'UTF-8', true); if ($fieldParams->get('directory', '/') !== '/') { $imageInfo = Image::getImageFileProperties(JPATH_ROOT . '/images/' . $fieldParams->get('directory') . '/' . $imageFilePath); $buffer .= sprintf( '<img loading="lazy" width="%s" height="%s" src="images/%s/%s"%s alt="">', $imageInfo->width, $imageInfo->height, $fieldParams->get('directory'), $imageFilePath, $class ); } else { $imageInfo = Image::getImageFileProperties(JPATH_ROOT . '/images/' . $imageFilePath); $buffer .= sprintf( '<img loading="lazy" width="%s" height="%s" src="images/%s"%s>', $imageInfo->width, $imageInfo->height, $imageFilePath, $class ); } } echo $buffer; fields/subform/services/provider.php 0000644 00000002444 15062070550 0013661 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.subform * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Subform\Extension\Subform; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Subform( $dispatcher, (array) PluginHelper::getPlugin('fields', 'subform') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/subform/params/subform.xml 0000644 00000003717 15062070550 0013161 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <field name="default_value" type="hidden" default="" /> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="repeat" type="radio" label="PLG_FIELDS_SUBFORM_PARAMS_REPEAT_LABEL" layout="joomla.form.field.radio.switcher" default="1" > <option value="0">JNO</option> <option value="1">JYES</option> </field> <field name="max_rows" type="number" label="PLG_FIELDS_SUBFORM_PARAMS_MAX_ROWS_LABEL" default="" filter="integer" showon="repeat:1" /> <field name="options" type="subform" label="PLG_FIELDS_SUBFORM_PARAMS_OPTIONS_LABEL" icon="list" layout="joomla.form.field.subform.repeatable-table" min="1" multiple="true" > <form hidden="true" name="options_modal" repeat="true"> <field context="" name="customfield" type="subfields" label="PLG_FIELDS_SUBFORM_PARAMS_CUSTOMFIELD_LABEL" default="" required="true" /> <field name="render_values" type="radio" label="PLG_FIELDS_SUBFORM_PARAMS_RENDER_VALUES_LABEL" layout="joomla.form.field.radio.switcher" default="1" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </form> </field> </fieldset> </fields> <fields name="params"> <fieldset name="basic"> <fieldset name="formoptions"> <field name="form_layout" type="list" label="COM_FIELDS_FIELD_FORM_LAYOUT_LABEL" default="" class="form-select" showon="repeat:1" > <option value="">JDEFAULT</option> <option value="joomla.form.field.subform.repeatable-table">PLG_FIELDS_SUBFORM_PARAMS_EDIT_LAYOUT_OPTION_REPEATABLE_TABLE_LABEL</option> <option value="joomla.form.field.subform.repeatable">PLG_FIELDS_SUBFORM_PARAMS_EDIT_LAYOUT_OPTION_REPEATABLE_FORM_LABEL</option> </field> </fieldset> </fieldset> </fields> </form> fields/subform/src/Extension/Subform.php 0000644 00000034437 15062070550 0014373 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.subform * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Subform\Extension; use DOMDocument; use DOMElement; use DOMXPath; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Subform Plugin * * @since 3.7.0 */ final class Subform extends FieldsPlugin { /** * Two-dimensional array to hold to do a fast in-memory caching of rendered * subfield values. * * @var array * * @since 4.0.0 */ protected $renderCache = []; /** * Array to do a fast in-memory caching of all custom field items. * * @var array * * @since 4.0.0 */ protected static $customFieldsCache = null; /** * Handles the onContentPrepareForm event. Adds form definitions to relevant forms. * * @param Form $form The form to manipulate * @param array|object $data The data of the form * * @return void * * @since 4.0.0 */ public function onContentPrepareForm(Form $form, $data) { // Get the path to our own form definition (basically ./params/subform.xml) $path = $this->getFormPath($form, $data); if ($path === null) { return; } // Ensure it is an object $formData = (object) $data; // Now load our own form definition into a DOMDocument, because we want to manipulate it $xml = new \DOMDocument(); $xml->load($path); // Prepare a DOMXPath object $xmlxpath = new \DOMXPath($xml); /** * Get all fields of type "subfields" in our own XML * * @var $valuefields \DOMNodeList */ $valuefields = $xmlxpath->evaluate('//field[@type="subfields"]'); // If we haven't found it, something is wrong if (!$valuefields || $valuefields->length != 1) { return; } // Now iterate over those fields and manipulate them, set its parameter `context` to our context foreach ($valuefields as $valuefield) { $valuefield->setAttribute('context', $formData->context); } // When this is not a new instance (editing an existing instance) if (isset($formData->id) && $formData->id > 0) { // Don't allow the 'repeat' attribute to be edited foreach ($xmlxpath->evaluate('//field[@name="repeat"]') as $field) { $field->setAttribute('readonly', '1'); } } // And now load our manipulated form definition into the JForm $form->load($xml->saveXML(), true, '/form/*'); } /** * Manipulates the $field->value before the field is being passed to * onCustomFieldsPrepareField. * * @param string $context The context * @param object $item The item * @param \stdClass $field The field * * @return void * * @since 4.0.0 */ public function onCustomFieldsBeforePrepareField($context, $item, $field) { if (!$this->isTypeSupported($field->type)) { return; } if (is_array($field->value)) { return; } $decoded_value = json_decode($field->value, true); if (!$decoded_value || !is_array($decoded_value)) { return; } $field->value = $decoded_value; } /** * Renders this fields value by rendering all sub fields and joining all those rendered sub fields together. * * @param string $context The context * @param object $item The item * @param \stdClass $field The field * * @return string * * @since 4.0.0 */ public function onCustomFieldsPrepareField($context, $item, $field) { // Check if the field should be processed by us if (!$this->isTypeSupported($field->type)) { return; } // If we don't have any subfields (or values for them), nothing to do. if (!is_array($field->value) || count($field->value) < 1) { return; } // Get the field params $field_params = $this->getParamsFromField($field); /** * Placeholder to hold all rows (if this field is repeatable). * Each array entry is another array representing a row, containing all of the sub fields that * are valid for this row and their raw and rendered values. */ $subform_rows = []; // Create an array with entries being subfields forms, and if not repeatable, containing only one element. $rows = $field->value; if ($field_params->get('repeat', '1') == '0') { $rows = [$field->value]; } // Iterate over each row of the data foreach ($rows as $row) { // Holds all sub fields of this row, incl. their raw and rendered value $row_subfields = []; // For each row, iterate over all the subfields foreach ($this->getSubfieldsFromField($field) as $subfield) { // Fill value (and rawvalue) if we have data for this subfield in the current row, otherwise set them to empty $subfield->rawvalue = $subfield->value = $row[$subfield->name] ?? ''; // Do we want to render the value of this field, and is the value non-empty? if ($subfield->value !== '' && $subfield->render_values == '1') { /** * Construct the cache-key for our renderCache. It is important that the cache key * is as unique as possible to avoid false duplicates (e.g. type and rawvalue is not * enough for the cache key, because type 'list' and value '1' can have different * rendered values, depending on the list items), but it also must be as general as possible * to not cause too many unneeded rendering processes (e.g. the type 'text' will always be * rendered the same when it has the same rawvalue). */ $renderCache_key = serialize( [ $subfield->type, $subfield->id, $subfield->rawvalue, ] ); // Let's see if we have a fast in-memory result for this if (isset($this->renderCache[$renderCache_key])) { $subfield->value = $this->renderCache[$renderCache_key]; } else { // Render this virtual subfield $subfield->value = $this->getApplication()->triggerEvent( 'onCustomFieldsPrepareField', [$context, $item, $subfield] ); $this->renderCache[$renderCache_key] = $subfield->value; } } // Flatten the value if it is an array (list, checkboxes, etc.) [independent of render_values] if (is_array($subfield->value)) { $subfield->value = implode(' ', $subfield->value); } // Store the subfield (incl. its raw and rendered value) into this rows sub fields $row_subfields[$subfield->fieldname] = $subfield; } // Store all the sub fields of this row $subform_rows[] = $row_subfields; } // Store all the rows and their corresponding sub fields in $field->subform_rows $field->subform_rows = $subform_rows; // Call our parent to combine all those together for the final $field->value return parent::onCustomFieldsPrepareField($context, $item, $field); } /** * Returns a DOMElement which is the child of $parent and represents * the form XML definition for this field. * * @param \stdClass $field The field * @param \DOMElement $parent The original parent element * @param Form $form The form * * @return \DOMElement * * @since 4.0.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { // Call the onCustomFieldsPrepareDom method on FieldsPlugin $parent_field = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$parent_field) { return $parent_field; } // Override the fieldname attribute of the subform - this is being used to index the rows $parent_field->setAttribute('fieldname', 'row'); // If the user configured this subform instance as required if ($field->required) { // Then we need to have at least one row $parent_field->setAttribute('min', '1'); } // Get the configured parameters for this field $field_params = $this->getParamsFromField($field); // If this fields should be repeatable, set some attributes on the subform element if ($field_params->get('repeat', '1') == '1') { $parent_field->setAttribute('multiple', 'true'); $parent_field->setAttribute('layout', 'joomla.form.field.subform.repeatable-table'); } // Create a child 'form' DOMElement under the field[type=subform] element. $parent_fieldset = $parent_field->appendChild(new \DOMElement('form')); $parent_fieldset->setAttribute('hidden', 'true'); $parent_fieldset->setAttribute('name', ($field->name . '_modal')); if ($field_params->get('max_rows')) { $parent_field->setAttribute('max', $field_params->get('max_rows')); } // If this field should be repeatable, set some attributes on the modal if ($field_params->get('repeat', '1') == '1') { $parent_fieldset->setAttribute('repeat', 'true'); } // Get the configured sub fields for this field $subfields = $this->getSubfieldsFromField($field); // If we have 5 or more of them, use the `repeatable` layout instead of the `repeatable-table` if (count($subfields) >= 5) { $parent_field->setAttribute('layout', 'joomla.form.field.subform.repeatable'); } // Iterate over the sub fields to call prepareDom on each of those sub-fields foreach ($subfields as $subfield) { // Let the relevant plugins do their work and insert the correct // DOMElement's into our $parent_fieldset. $this->getApplication()->triggerEvent( 'onCustomFieldsPrepareDom', [$subfield, $parent_fieldset, $form] ); } // If the edit layout is set we override any automation $editLayout = $field->params->get('form_layout'); if ($editLayout) { $parent_field->setAttribute('layout', $editLayout); } return $parent_field; } /** * Returns an array of all options configured for this field. * * @param \stdClass $field The field * * @return \stdClass[] * * @since 4.0.0 */ protected function getOptionsFromField(\stdClass $field) { $result = []; // Fetch the options from the plugin $params = $this->getParamsFromField($field); foreach ($params->get('options', []) as $option) { $result[] = (object) $option; } return $result; } /** * Returns the configured params for a given field. * * @param \stdClass $field The field * * @return \Joomla\Registry\Registry * * @since 4.0.0 */ protected function getParamsFromField(\stdClass $field) { $params = (clone $this->params); if (isset($field->fieldparams) && is_object($field->fieldparams)) { $params->merge($field->fieldparams); } return $params; } /** * Returns an array of all subfields for a given field. This will always return a bare clone * of a sub field, so manipulating it is safe. * * @param \stdClass $field The field * * @return \stdClass[] * * @since 4.0.0 */ protected function getSubfieldsFromField(\stdClass $field) { if (static::$customFieldsCache === null) { // Prepare our cache static::$customFieldsCache = []; // Get all custom field instances $customFields = FieldsHelper::getFields('', null, false, null, true); foreach ($customFields as $customField) { // Store each custom field instance in our cache with its id as key static::$customFieldsCache[$customField->id] = $customField; } } $result = []; // Iterate over all configured options for this field foreach ($this->getOptionsFromField($field) as $option) { // Check whether the wanted sub field really is an existing custom field if (!isset(static::$customFieldsCache[$option->customfield])) { continue; } // Get a clone of the sub field, so we and the caller can do some manipulation with it. $cur_field = (clone static::$customFieldsCache[$option->customfield]); // Manipulate it and add our custom configuration to it $cur_field->render_values = $option->render_values; /** * Set the name of the sub field to its id so that the values in the database are being saved * based on the id of the sub fields, not on their name. Actually we do not need the name of * the sub fields to render them, but just to make sure we have the name when we need it, we * store it as `fieldname`. */ $cur_field->fieldname = $cur_field->name; $cur_field->name = 'field' . $cur_field->id; // And add it to our result $result[] = $cur_field; } return $result; } } fields/subform/subform.xml 0000644 00000001614 15062070550 0011670 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_subform</name> <author>Joomla! Project</author> <creationDate>2017-06</creationDate> <copyright>(C) 2019 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>4.0.0</version> <description>PLG_FIELDS_SUBFORM_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Subform</namespace> <files> <folder>params</folder> <folder plugin="subform">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_subform.ini</language> <language tag="en-GB">language/en-GB/plg_fields_subform.sys.ini</language> </languages> </extension> fields/subform/tmpl/subform.php 0000644 00000003043 15062070550 0012631 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Subform * * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; defined('_JEXEC') or die; if (!$context || empty($field->subform_rows)) { return; } $result = ''; // Iterate over each row that we have foreach ($field->subform_rows as $subform_row) { // Placeholder array to generate this rows output $row_output = []; // Iterate over each sub field inside of that row foreach ($subform_row as $subfield) { $class = trim($subfield->params->get('render_class', '')); $layout = trim($subfield->params->get('layout', 'render')); $content = trim( FieldsHelper::render( $context, 'field.' . $layout, // normally just 'field.render' ['field' => $subfield] ) ); // Skip empty output if ($content === '') { continue; } // Generate the output for this sub field and row $row_output[] = '<span class="field-entry' . ($class ? (' ' . $class) : '') . '">' . $content . '</span>'; } // Skip empty rows if (count($row_output) == 0) { continue; } $result .= '<li>' . implode(', ', $row_output) . '</li>'; } ?> <?php if (trim($result) != '') : ?> <ul class="fields-container"> <?php echo $result; ?> </ul> <?php endif; ?> fields/list/list.xml 0000644 00000003422 15062070550 0010463 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_list</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_LIST_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\ListField</namespace> <files> <folder>params</folder> <folder plugin="list">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_list.ini</language> <language tag="en-GB">language/en-GB/plg_fields_list.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="multiple" type="radio" label="PLG_FIELDS_LIST_PARAMS_MULTIPLE_LABEL" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> <field name="options" type="subform" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_NAME_LABEL" /> <field name="value" type="text" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> </config> </extension> fields/list/tmpl/list.php 0000644 00000001200 15062070550 0011416 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.List * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; $fieldValue = $field->value; if ($fieldValue == '') { return; } $fieldValue = (array) $fieldValue; $texts = []; $options = $this->getOptionsFromField($field); foreach ($options as $value => $name) { if (in_array((string) $value, $fieldValue)) { $texts[] = Text::_($name); } } echo htmlentities(implode(', ', $texts)); fields/list/src/Extension/ListPlugin.php 0000644 00000004202 15062070550 0014331 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.list * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\ListField\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsListPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields List Plugin * * @since 3.7.0 */ final class ListPlugin extends FieldsListPlugin { /** * Before prepares the field value. * * @param string $context The context. * @param \stdclass $item The item. * @param \stdclass $field The field. * * @return void * * @since 3.7.0 */ public function onCustomFieldsBeforePrepareField($context, $item, $field) { if (!$this->getApplication()->isClient('api')) { return; } if (!$this->isTypeSupported($field->type)) { return; } $options = $this->getOptionsFromField($field); $field->apivalue = []; if (\is_array($field->value)) { foreach ($field->value as $value) { $field->apivalue[$value] = $options[$value]; } } elseif (!empty($field->value)) { $field->apivalue[$field->value] = $options[$field->value]; } } /** * Prepares the field * * @param string $context The context. * @param stdclass $item The item. * @param stdclass $field The field. * * @return object * * @since 3.9.2 */ public function onCustomFieldsPrepareField($context, $item, $field) { // Check if the field should be processed if (!$this->isTypeSupported($field->type)) { return; } // The field's rawvalue should be an array if (!is_array($field->rawvalue)) { $field->rawvalue = (array) $field->rawvalue; } return parent::onCustomFieldsPrepareField($context, $item, $field); } } fields/list/params/list.xml 0000644 00000002577 15062070550 0011760 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="multiple" type="list" label="PLG_FIELDS_LIST_PARAMS_MULTIPLE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> <field name="options" type="subform" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_NAME_LABEL" required="true" /> <field name="value" type="text" label="PLG_FIELDS_LIST_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> <fields name="params"> <fieldset name="basic"> <fieldset name="formoptions"> <field name="form_layout" type="list" label="COM_FIELDS_FIELD_FORM_LAYOUT_LABEL" class="form-select" > <option value="joomla.form.field.list">JDEFAULT</option> <option value="joomla.form.field.list-fancy-select">PLG_FIELDS_LIST_PARAMS_FORM_LAYOUT_FANCY_SELECT</option> </field> </fieldset> </fieldset> </fields> </form> fields/list/services/provider.php 0000644 00000002446 15062070550 0013161 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.list * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\ListField\Extension\ListPlugin; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new ListPlugin( $dispatcher, (array) PluginHelper::getPlugin('fields', 'list') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/media/tmpl/media.php 0000644 00000001303 15062070550 0011632 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Media * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Layout\LayoutHelper; if (empty($field->value) || empty($field->value['imagefile'])) { return; } $class = $fieldParams->get('image_class'); $options = [ 'src' => $field->value['imagefile'], 'alt' => empty($field->value['alt_text']) && empty($field->value['alt_empty']) ? false : $field->value['alt_text'], ]; if ($class) { $options['class'] = $class; } echo LayoutHelper::render('joomla.html.image', $options); fields/media/media.xml 0000644 00000003131 15062070550 0010670 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_media</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_MEDIA_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Media</namespace> <files> <folder>params</folder> <folder plugin="media">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_media.ini</language> <language tag="en-GB">language/en-GB/plg_fields_media.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="directory" type="folderlist" label="PLG_FIELDS_MEDIA_PARAMS_DIRECTORY_LABEL" directory="images" hide_none="true" recursive="true" /> <field name="preview" type="list" label="PLG_FIELDS_MEDIA_PARAMS_PREVIEW_LABEL" class="list" default="true" validate="options" > <option value="true">PLG_FIELDS_MEDIA_PARAMS_PREVIEW_INLINE</option> <option value="false">JNO</option> </field> <field name="image_class" type="textarea" label="PLG_FIELDS_MEDIA_PARAMS_IMAGE_CLASS_LABEL" validate="CssIdentifier" /> </fieldset> </fields> </config> </extension> fields/media/src/Extension/Media.php 0000644 00000004657 15062070550 0013400 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.media * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Media\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Media Plugin * * @since 3.7.0 */ final class Media extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 4.0.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('type', 'accessiblemedia'); if ($this->getApplication()->getIdentity()->authorise('core.create', 'com_media')) { $fieldNode->setAttribute('disabled', 'false'); } return $fieldNode; } /** * Before prepares the field value. * * @param string $context The context. * @param \stdclass $item The item. * @param \stdclass $field The field. * * @return void * * @since 4.0.0 */ public function onCustomFieldsBeforePrepareField($context, $item, $field) { // Check if the field should be processed by us if (!$this->isTypeSupported($field->type)) { return; } // Check if the field value is an old (string) value $field->value = $this->checkValue($field->value); } /** * Before prepares the field value. * * @param string $value The value to check. * * @return array The checked value * * @since 4.0.0 */ private function checkValue($value) { json_decode($value); if (json_last_error() === JSON_ERROR_NONE) { return (array) json_decode($value, true); } return ['imagefile' => $value, 'alt_text' => '']; } } fields/media/params/media.xml 0000644 00000001425 15062070550 0012157 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="directory" type="folderlist" label="PLG_FIELDS_MEDIA_PARAMS_DIRECTORY_LABEL" directory="images" hide_none="true" recursive="true" validate="options" /> <field name="preview" type="list" label="PLG_FIELDS_MEDIA_PARAMS_PREVIEW_LABEL" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="true">PLG_FIELDS_MEDIA_PARAMS_PREVIEW_INLINE</option> <option value="false">JNO</option> </field> <field name="image_class" type="textarea" label="PLG_FIELDS_MEDIA_PARAMS_IMAGE_CLASS_LABEL" validate="CssIdentifier" /> </fieldset> </fields> </form> fields/media/services/provider.php 0000644 00000002432 15062070550 0013260 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.media * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Media\Extension\Media; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Media( $dispatcher, (array) PluginHelper::getPlugin('fields', 'media') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/textarea/params/textarea.xml 0000644 00000002267 15062070550 0013460 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="rows" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_ROWS_LABEL" filter="integer" /> <field name="cols" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_COLS_LABEL" filter="integer" /> <field name="maxlength" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_MAXLENGTH_LABEL" filter="integer" /> <field name="filter" type="list" label="PLG_FIELDS_TEXTAREA_PARAMS_FILTER_LABEL" class="list" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="0">JNO</option> <option value="raw">JLIB_FILTER_PARAMS_RAW</option> <option value="safehtml">JLIB_FILTER_PARAMS_SAFEHTML</option> <option value="JComponentHelper::filterText">JLIB_FILTER_PARAMS_TEXT</option> <option value="alnum">JLIB_FILTER_PARAMS_ALNUM</option> <option value="integer">JLIB_FILTER_PARAMS_INTEGER</option> <option value="float">JLIB_FILTER_PARAMS_FLOAT</option> <option value="tel">JLIB_FILTER_PARAMS_TEL</option> </field> </fieldset> </fields> </form> fields/textarea/services/provider.php 0000644 00000002451 15062070550 0014017 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.textarea * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Textarea\Extension\Textarea; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Textarea( $dispatcher, (array) PluginHelper::getPlugin('fields', 'textarea') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/textarea/textarea.xml 0000644 00000004131 15062070550 0012165 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_textarea</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_TEXTAREA_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Textarea</namespace> <files> <folder>params</folder> <folder plugin="textarea">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_textarea.ini</language> <language tag="en-GB">language/en-GB/plg_fields_textarea.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="rows" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_ROWS_LABEL" default="10" filter="integer" /> <field name="cols" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_COLS_LABEL" default="10" filter="integer" /> <field name="maxlength" type="number" label="PLG_FIELDS_TEXTAREA_PARAMS_MAXLENGTH_LABEL" filter="integer" /> <field name="filter" type="list" label="PLG_FIELDS_TEXTAREA_PARAMS_FILTER_LABEL" class="list" default="JComponentHelper::filterText" validate="options" > <option value="0">JNO</option> <option value="raw">JLIB_FILTER_PARAMS_RAW</option> <option value="safehtml">JLIB_FILTER_PARAMS_SAFEHTML</option> <option value="JComponentHelper::filterText">JLIB_FILTER_PARAMS_TEXT</option> <option value="alnum">JLIB_FILTER_PARAMS_ALNUM</option> <option value="integer">JLIB_FILTER_PARAMS_INTEGER</option> <option value="float">JLIB_FILTER_PARAMS_FLOAT</option> <option value="tel">JLIB_FILTER_PARAMS_TEL</option> </field> </fieldset> </fields> </config> </extension> fields/textarea/tmpl/textarea.php 0000644 00000000623 15062070550 0013132 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Textarea * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper; $value = $field->value; if ($value == '') { return; } echo HTMLHelper::_('content.prepare', $value); fields/textarea/src/Extension/Textarea.php 0000644 00000001057 15062070550 0014663 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.textarea * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Textarea\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Textarea Plugin * * @since 3.7.0 */ final class Textarea extends FieldsPlugin { } fields/checkboxes/services/provider.php 0000644 00000002463 15062070550 0014323 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.checkboxes * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Checkboxes\Extension\Checkboxes; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Checkboxes( $dispatcher, (array) PluginHelper::getPlugin('fields', 'checkboxes') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/checkboxes/params/checkboxes.xml 0000644 00000001265 15062070550 0014257 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="options" type="subform" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_NAME_LABEL" required="true" /> <field name="value" type="text" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> </form> fields/checkboxes/checkboxes.xml 0000644 00000003052 15062070550 0012770 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_checkboxes</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_CHECKBOXES_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Checkboxes</namespace> <files> <folder>params</folder> <folder plugin="checkboxes">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_checkboxes.ini</language> <language tag="en-GB">language/en-GB/plg_fields_checkboxes.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="options" type="subform" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_NAME_LABEL" /> <field name="value" type="text" label="PLG_FIELDS_CHECKBOXES_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> </config> </extension> fields/checkboxes/src/Extension/Checkboxes.php 0000644 00000002765 15062070550 0015474 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.checkboxes * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Checkboxes\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsListPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Checkboxes Plugin * * @since 3.7.0 */ final class Checkboxes extends FieldsListPlugin { /** * Before prepares the field value. * * @param string $context The context. * @param \stdclass $item The item. * @param \stdclass $field The field. * * @return void * * @since 3.7.0 */ public function onCustomFieldsBeforePrepareField($context, $item, $field) { if (!$this->getApplication()->isClient('api')) { return; } if (!$this->isTypeSupported($field->type)) { return; } $field->apivalue = []; $options = $this->getOptionsFromField($field); if (empty($field->value)) { return; } if (is_array($field->value)) { foreach ($field->value as $key => $value) { $field->apivalue[$value] = $options[$value]; } } else { $field->apivalue[$field->value] = $options[$field->value]; } } } fields/checkboxes/tmpl/checkboxes.php 0000644 00000001237 15062070550 0013736 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Checkboxes * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; $fieldValue = $field->value; if ($fieldValue === '' || $fieldValue === null) { return; } $fieldValue = (array) $fieldValue; $texts = []; $options = $this->getOptionsFromField($field); foreach ($options as $value => $name) { if (in_array((string) $value, $fieldValue)) { $texts[] = Text::_($name); } } echo htmlentities(implode(', ', $texts)); fields/user/src/Extension/User.php 0000644 00000002317 15062070550 0013165 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.user * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\User\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields User Plugin * * @since 3.7.0 */ final class User extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { if ($this->getApplication()->isClient('site')) { // The user field is not working on the front end return; } return parent::onCustomFieldsPrepareDom($field, $parent, $form); } } fields/user/user.xml 0000644 00000001572 15062070550 0010475 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_user</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_USER_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\User</namespace> <files> <folder>params</folder> <folder plugin="user">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_user.ini</language> <language tag="en-GB">language/en-GB/plg_fields_user.sys.ini</language> </languages> </extension> fields/user/tmpl/user.php 0000644 00000001333 15062070550 0011433 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.User * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Factory; $value = $field->value; if ($value == '') { return; } $value = (array) $value; $texts = []; foreach ($value as $userId) { if (!$userId) { continue; } $user = Factory::getUser($userId); if ($user) { // Use the Username $texts[] = $user->name; continue; } // Fallback and add the User ID if we get no JUser Object $texts[] = $userId; } echo htmlentities(implode(', ', $texts)); fields/user/services/provider.php 0000644 00000002425 15062070550 0013161 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.user * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\User\Extension\User; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new User( $dispatcher, (array) PluginHelper::getPlugin('fields', 'user') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/user/params/user.xml 0000644 00000000541 15062070550 0011753 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <field name="default_value" type="user" label="PLG_FIELDS_USER_DEFAULT_VALUE_LABEL" validate="UserId" /> <fields name="params" label="COM_FIELDS_FIELD_BASIC_LABEL"> <fieldset name="basic"> <field name="show_on" type="hidden" filter="unset" /> </fieldset> </fields> </form> fields/editor/src/Extension/Editor.php 0000644 00000002616 15062070550 0014007 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.editor * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Editor\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Editor Plugin * * @since 3.7.0 */ final class Editor extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('buttons', $field->fieldparams->get('buttons', $this->params->get('buttons', 0)) ? 'true' : 'false'); $fieldNode->setAttribute('hide', implode(',', $field->fieldparams->get('hide', []))); return $fieldNode; } } fields/editor/params/editor.xml 0000644 00000002402 15062070550 0012571 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="buttons" type="list" label="PLG_FIELDS_EDITOR_PARAMS_SHOW_BUTTONS_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> <field name="hide" type="plugins" label="PLG_FIELDS_EDITOR_PARAMS_BUTTONS_HIDE_LABEL" folder="editors-xtd" multiple="true" layout="joomla.form.field.list-fancy-select" /> <field name="width" type="text" label="PLG_FIELDS_EDITOR_PARAMS_WIDTH_LABEL" /> <field name="height" type="text" label="PLG_FIELDS_EDITOR_PARAMS_HEIGHT_LABEL" /> <field name="filter" type="list" label="PLG_FIELDS_TEXT_PARAMS_FILTER_LABEL" class="list" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="0">JNO</option> <option value="raw">JLIB_FILTER_PARAMS_RAW</option> <option value="safehtml">JLIB_FILTER_PARAMS_SAFEHTML</option> <option value="JComponentHelper::filterText">JLIB_FILTER_PARAMS_TEXT</option> </field> </fieldset> </fields> </form> fields/editor/editor.xml 0000644 00000004227 15062070550 0011315 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_editor</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_EDITOR_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Editor</namespace> <files> <folder>params</folder> <folder plugin="editor">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_editor.ini</language> <language tag="en-GB">language/en-GB/plg_fields_editor.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="buttons" type="radio" label="PLG_FIELDS_EDITOR_PARAMS_SHOW_BUTTONS_LABEL" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JHIDE</option> <option value="1">JSHOW</option> </field> <field name="hide" type="plugins" label="PLG_FIELDS_EDITOR_PARAMS_BUTTONS_HIDE_LABEL" folder="editors-xtd" multiple="true" layout="joomla.form.field.list-fancy-select" /> <field name="width" type="text" label="PLG_FIELDS_EDITOR_PARAMS_WIDTH_LABEL" default="100%" /> <field name="height" type="text" label="PLG_FIELDS_EDITOR_PARAMS_HEIGHT_LABEL" default="250px" /> <field name="filter" type="list" label="PLG_FIELDS_EDITOR_PARAMS_FILTER_LABEL" class="list" default="JComponentHelper::filterText" validate="options" > <option value="0">JNO</option> <option value="raw">JLIB_FILTER_PARAMS_RAW</option> <option value="safehtml">JLIB_FILTER_PARAMS_SAFEHTML</option> <option value="JComponentHelper::filterText">JLIB_FILTER_PARAMS_TEXT</option> </field> </fieldset> </fields> </config> </extension> fields/editor/tmpl/editor.php 0000644 00000000621 15062070550 0012252 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Editor * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper; $value = $field->value; if ($value == '') { return; } echo HTMLHelper::_('content.prepare', $value); fields/editor/services/provider.php 0000644 00000002437 15062070550 0013474 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.editor * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Editor\Extension\Editor; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Editor( $dispatcher, (array) PluginHelper::getPlugin('fields', 'editor') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/url/params/url.xml 0000644 00000002153 15062070550 0011424 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="schemes" type="list" label="PLG_FIELDS_URL_PARAMS_SCHEMES_LABEL" multiple="true" layout="joomla.form.field.list-fancy-select" validate="options" > <option value="http">HTTP</option> <option value="https">HTTPS</option> <option value="ftp">FTP</option> <option value="ftps">FTPS</option> <option value="file">FILE</option> <option value="mailto">MAILTO</option> </field> <field name="relative" type="list" label="PLG_FIELDS_URL_PARAMS_RELATIVE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> <field name="show_url" type="radio" label="PLG_FIELDS_URL_PARAMS_SHOW_URL" layout="joomla.form.field.radio.switcher" default="1" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </fieldset> </fields> </form> fields/url/url.xml 0000644 00000003270 15062070550 0010142 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_url</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_URL_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Url</namespace> <files> <folder>params</folder> <folder plugin="url">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_url.ini</language> <language tag="en-GB">language/en-GB/plg_fields_url.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="schemes" type="list" label="PLG_FIELDS_URL_PARAMS_SCHEMES_LABEL" multiple="true" layout="joomla.form.field.list-fancy-select" validate="options" > <option value="http">HTTP</option> <option value="https">HTTPS</option> <option value="ftp">FTP</option> <option value="ftps">FTPS</option> <option value="file">FILE</option> <option value="mailto">MAILTO</option> </field> <field name="relative" type="radio" label="PLG_FIELDS_URL_PARAMS_RELATIVE_LABEL" layout="joomla.form.field.radio.switcher" default="1" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </fieldset> </fields> </config> </extension> fields/url/src/Extension/Url.php 0000644 00000002510 15062070550 0012630 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.url * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Url\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Url Plugin * * @since 3.7.0 */ final class Url extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('validate', 'url'); if (! $fieldNode->getAttribute('relative')) { $fieldNode->removeAttribute('relative'); } return $fieldNode; } } fields/url/services/provider.php 0000644 00000002420 15062070550 0013000 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.url * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Url\Extension\Url; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Url( $dispatcher, (array) PluginHelper::getPlugin('fields', 'url') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/url/tmpl/url.php 0000644 00000001414 15062070550 0011103 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.URL * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; use Joomla\CMS\Uri\Uri; $value = $field->value; if ($value == '') { return; } $attributes = ''; if (!Uri::isInternal($value)) { $attributes = ' rel="nofollow noopener noreferrer" target="_blank"'; $text = Text::_('JVISIT_WEBSITE'); } else { $text = Text::_('JVISIT_LINK'); } if ($fieldParams->get('show_url', 0)) { $text = htmlspecialchars($value); } echo sprintf( '<a href="%s"%s>%s</a>', htmlspecialchars($value), $attributes, $text ); fields/usergrouplist/params/usergrouplist.xml 0000644 00000000664 15062070550 0015703 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="multiple" type="list" label="PLG_FIELDS_USERGROUPLIST_PARAMS_MULTIPLE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> </fieldset> </fields> </form> fields/usergrouplist/tmpl/usergrouplist.php 0000644 00000001212 15062070550 0015351 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Usergrouplist * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\Component\Users\Administrator\Helper\UsersHelper; $value = $field->value; if ($value == '') { return; } $value = (array) $value; $texts = []; $groups = UsersHelper::getGroups(); foreach ($groups as $group) { if (in_array($group->value, $value)) { $texts[] = htmlentities(trim($group->text, '- ')); } } echo htmlentities(implode(', ', $texts)); fields/usergrouplist/usergrouplist.xml 0000644 00000002465 15062070550 0014421 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_usergrouplist</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_USERGROUPLIST_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\UsergroupList</namespace> <files> <folder>params</folder> <folder plugin="usergrouplist">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_usergrouplist.ini</language> <language tag="en-GB">language/en-GB/plg_fields_usergrouplist.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="multiple" type="radio" label="PLG_FIELDS_USERGROUPLIST_PARAMS_MULTIPLE_LABEL" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </fieldset> </fields> </config> </extension> fields/usergrouplist/services/provider.php 0000644 00000002502 15062070550 0015126 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.usergrouplist * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\UsergroupList\Extension\UsergroupList; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new UsergroupList( $dispatcher, (array) PluginHelper::getPlugin('fields', 'usergrouplist') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/usergrouplist/src/Extension/UsergroupList.php 0000644 00000001103 15062070550 0017037 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.usergrouplist * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\UsergroupList\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields UsergroupList Plugin * * @since 3.7.0 */ final class UsergroupList extends FieldsPlugin { } fields/integer/services/provider.php 0000644 00000002444 15062070550 0013641 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.integer * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Integer\Extension\Integer; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Integer( $dispatcher, (array) PluginHelper::getPlugin('fields', 'integer') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/integer/src/Extension/Integer.php 0000644 00000001053 15062070550 0014317 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.integer * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Integer\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Integer Plugin * * @since 3.7.0 */ final class Integer extends FieldsPlugin { } fields/integer/params/integer.xml 0000644 00000001433 15062070550 0013112 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="multiple" type="list" label="PLG_FIELDS_INTEGER_PARAMS_MULTIPLE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> <field name="first" type="number" label="PLG_FIELDS_INTEGER_PARAMS_FIRST_LABEL" filter="integer" /> <field name="last" type="number" label="PLG_FIELDS_INTEGER_PARAMS_LAST_LABEL" filter="integer" /> <field name="step" type="number" label="PLG_FIELDS_INTEGER_PARAMS_STEP_LABEL" filter="integer" /> </fieldset> </fields> </form> fields/integer/tmpl/integer.php 0000644 00000000707 15062070550 0012575 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Integer * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $value = $field->value; if ($value == '') { return; } if (is_array($value)) { $value = implode(', ', array_map('intval', $value)); } else { $value = (int) $value; } echo $value; fields/integer/integer.xml 0000644 00000003277 15062070550 0011637 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_integer</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_INTEGER_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Integer</namespace> <files> <folder>params</folder> <folder plugin="integer">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_integer.ini</language> <language tag="en-GB">language/en-GB/plg_fields_integer.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="multiple" type="radio" label="PLG_FIELDS_INTEGER_PARAMS_MULTIPLE_LABEL" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> <field name="first" type="number" label="PLG_FIELDS_INTEGER_PARAMS_FIRST_LABEL" default="1" filter="integer" /> <field name="last" type="number" label="PLG_FIELDS_INTEGER_PARAMS_LAST_LABEL" default="100" filter="integer" /> <field name="step" type="number" label="PLG_FIELDS_INTEGER_PARAMS_STEP_LABEL" default="1" filter="integer" /> </fieldset> </fields> </config> </extension> fields/calendar/calendar.xml 0000644 00000001622 15062070550 0012057 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_calendar</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_CALENDAR_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Calendar</namespace> <files> <folder>params</folder> <folder plugin="calendar">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_calendar.ini</language> <language tag="en-GB">language/en-GB/plg_fields_calendar.sys.ini</language> </languages> </extension> fields/calendar/tmpl/calendar.php 0000644 00000001156 15062070550 0013024 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Calendar * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; $value = $field->value; if ($value == '') { return; } if (is_array($value)) { $value = implode(', ', $value); } $formatString = $field->fieldparams->get('showtime', 0) ? 'DATE_FORMAT_LC5' : 'DATE_FORMAT_LC4'; echo htmlentities(HTMLHelper::_('date', $value, Text::_($formatString))); fields/calendar/services/provider.php 0000644 00000002451 15062070550 0013753 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.calendar * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Calendar\Extension\Calendar; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Calendar( $dispatcher, (array) PluginHelper::getPlugin('fields', 'calendar') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/calendar/params/calendar.xml 0000644 00000000730 15062070550 0013341 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="showtime" type="radio" label="PLG_FIELDS_CALENDAR_PARAMS_SHOWTIME_LABEL" description="PLG_FIELDS_CALENDAR_PARAMS_SHOWTIME_DESC" layout="joomla.form.field.radio.switcher" default="0" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </fieldset> </fields> </form> fields/calendar/src/Extension/Calendar.php 0000644 00000002737 15062070550 0014561 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.calendar * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Calendar\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Calendar Plugin * * @since 3.7.0 */ final class Calendar extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } // Set filter to user UTC $fieldNode->setAttribute('filter', 'USER_UTC'); // Set field to use translated formats $fieldNode->setAttribute('translateformat', '1'); $fieldNode->setAttribute('showtime', $field->fieldparams->get('showtime', 0) ? 'true' : 'false'); return $fieldNode; } } fields/color/src/Extension/Color.php 0000644 00000002334 15062070550 0013464 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.color * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Color\Extension; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Color Plugin * * @since 3.7.0 */ final class Color extends FieldsPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('validate', 'color'); return $fieldNode; } } fields/color/services/provider.php 0000644 00000002432 15062070550 0013317 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.color * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Color\Extension\Color; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Color( $dispatcher, (array) PluginHelper::getPlugin('fields', 'color') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/color/tmpl/color.php 0000644 00000000632 15062070550 0011734 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Color * * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $value = $field->value; if ($value == '') { return; } if (is_array($value)) { $value = implode(', ', $value); } echo htmlentities($value); fields/color/color.xml 0000644 00000001546 15062070550 0010776 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_color</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_COLOR_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Color</namespace> <files> <folder plugin="color">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_color.ini</language> <language tag="en-GB">language/en-GB/plg_fields_color.sys.ini</language> </languages> </extension> fields/radio/src/Extension/Radio.php 0000644 00000002423 15062070550 0013423 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.radio * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\Radio\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsListPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Radio Plugin * * @since 3.7.0 */ final class Radio extends FieldsListPlugin { /** * Before prepares the field value. * * @param string $context The context. * @param \stdclass $item The item. * @param \stdclass $field The field. * * @return void * * @since 3.7.0 */ public function onCustomFieldsBeforePrepareField($context, $item, $field) { if (!$this->getApplication()->isClient('api')) { return; } if (!$this->isTypeSupported($field->type)) { return; } $options = $this->getOptionsFromField($field); $field->apivalue = []; if (!empty($field->value)) { $field->apivalue = [$field->value => $options[$field->value]]; } } } fields/radio/radio.xml 0000644 00000002775 15062070550 0010743 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_radio</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_RADIO_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\Radio</namespace> <files> <folder>params</folder> <folder plugin="radio">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_radio.ini</language> <language tag="en-GB">language/en-GB/plg_fields_radio.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="options" type="subform" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_NAME_LABEL" /> <field name="value" type="text" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> </config> </extension> fields/radio/services/provider.php 0000644 00000002432 15062070550 0013277 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.radio * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\Radio\Extension\Radio; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new Radio( $dispatcher, (array) PluginHelper::getPlugin('fields', 'radio') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/radio/tmpl/radio.php 0000644 00000001174 15062070550 0011676 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Radio * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Language\Text; $value = $field->value; if ($value == '') { return; } $value = (array) $value; $texts = []; $options = $this->getOptionsFromField($field); foreach ($options as $optionValue => $optionText) { if (in_array((string) $optionValue, $value)) { $texts[] = Text::_($optionText); } } echo htmlentities(implode(', ', $texts)); fields/radio/params/radio.xml 0000644 00000002434 15062070550 0012216 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="options" type="subform" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_LABEL" layout="joomla.form.field.subform.repeatable-table" icon="list" multiple="true" > <form hidden="true" name="list_templates_modal" repeat="true"> <field name="name" type="text" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_NAME_LABEL" required="true" /> <field name="value" type="text" label="PLG_FIELDS_RADIO_PARAMS_OPTIONS_VALUE_LABEL" /> </form> </field> </fieldset> </fields> <fields name="params"> <fieldset name="basic"> <field name="class" type="textarea" label="COM_FIELDS_FIELD_CLASS_LABEL" default="btn-group" validate="CssIdentifier" /> <fieldset name="formoptions"> <field name="form_layout" type="list" label="COM_FIELDS_FIELD_FORM_LAYOUT_LABEL" class="form-select" > <option value="joomla.form.field.radio.buttons">PLG_FIELDS_RADIO_PARAMS_FORM_LAYOUT_BUTTONS</option> <option value="joomla.form.field.radio.switcher">PLG_FIELDS_RADIO_PARAMS_FORM_LAYOUT_SWITCHER</option> </field> </fieldset> </fieldset> </fields> </form> fields/sql/params/sql.xml 0000644 00000002057 15062070550 0011421 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <form> <fields name="fieldparams"> <fieldset name="fieldparams"> <field name="query" type="textarea" label="PLG_FIELDS_SQL_PARAMS_QUERY_LABEL" description="PLG_FIELDS_SQL_PARAMS_QUERY_DESC" filter="raw" rows="10" required="true" /> <field name="multiple" type="list" label="PLG_FIELDS_SQL_PARAMS_MULTIPLE_LABEL" filter="integer" validate="options" > <option value="">COM_FIELDS_FIELD_USE_GLOBAL</option> <option value="1">JYES</option> <option value="0">JNO</option> </field> </fieldset> </fields> <fields name="params"> <fieldset name="basic"> <fieldset name="formoptions"> <field name="form_layout" type="list" label="COM_FIELDS_FIELD_FORM_LAYOUT_LABEL" class="form-select" > <option value="joomla.form.field.list">JDEFAULT</option> <option value="joomla.form.field.list-fancy-select">PLG_FIELDS_SQL_PARAMS_FORM_LAYOUT_FANCY_SELECT</option> </field> </fieldset> </fieldset> </fields> </form> fields/sql/services/provider.php 0000644 00000002420 15062070550 0012775 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.sql * * @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Extension\PluginInterface; use Joomla\CMS\Factory; use Joomla\CMS\Plugin\PluginHelper; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use Joomla\Event\DispatcherInterface; use Joomla\Plugin\Fields\SQL\Extension\SQL; return new class () implements ServiceProviderInterface { /** * Registers the service provider with a DI container. * * @param Container $container The DI container. * * @return void * * @since 4.3.0 */ public function register(Container $container) { $container->set( PluginInterface::class, function (Container $container) { $dispatcher = $container->get(DispatcherInterface::class); $plugin = new SQL( $dispatcher, (array) PluginHelper::getPlugin('fields', 'sql') ); $plugin->setApplication(Factory::getApplication()); return $plugin; } ); } }; fields/sql/src/Extension/SQL.php 0000644 00000004437 15062070550 0012534 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.sql * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\SQL\Extension; use Joomla\CMS\Access\Access; use Joomla\CMS\Form\Form; use Joomla\Component\Fields\Administrator\Plugin\FieldsListPlugin; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields SQL Plugin * * @since 3.7.0 */ final class SQL extends FieldsListPlugin { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param \DOMElement $parent The field node parent. * @param Form $form The form. * * @return \DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { $fieldNode = parent::onCustomFieldsPrepareDom($field, $parent, $form); if (!$fieldNode) { return $fieldNode; } $fieldNode->setAttribute('value_field', 'text'); $fieldNode->setAttribute('key_field', 'value'); return $fieldNode; } /** * The save event. * * @param string $context The context * @param \Joomla\CMS\Table\Table $item The table * @param boolean $isNew Is new item * @param array $data The validated data * * @return boolean * * @since 3.7.0 */ public function onContentBeforeSave($context, $item, $isNew, $data = []) { // Only work on new SQL fields if ($context != 'com_fields.field' || !isset($item->type) || $item->type != 'sql') { return true; } // If we are not a super admin, don't let the user create or update a SQL field if (!Access::getAssetRules(1)->allow('core.admin', $this->getApplication()->getIdentity()->getAuthorisedGroups())) { $item->setError($this->getApplication()->getLanguage()->_('PLG_FIELDS_SQL_CREATE_NOT_POSSIBLE')); return false; } return true; } } fields/sql/sql.xml 0000644 00000002702 15062070550 0010133 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <extension type="plugin" group="fields" method="upgrade"> <name>plg_fields_sql</name> <author>Joomla! Project</author> <creationDate>2016-03</creationDate> <copyright>(C) 2016 Open Source Matters, Inc.</copyright> <license>GNU General Public License version 2 or later; see LICENSE.txt</license> <authorEmail>admin@joomla.org</authorEmail> <authorUrl>www.joomla.org</authorUrl> <version>3.7.0</version> <description>PLG_FIELDS_SQL_XML_DESCRIPTION</description> <namespace path="src">Joomla\Plugin\Fields\SQL</namespace> <files> <folder>params</folder> <folder plugin="sql">services</folder> <folder>src</folder> <folder>tmpl</folder> </files> <languages> <language tag="en-GB">language/en-GB/plg_fields_sql.ini</language> <language tag="en-GB">language/en-GB/plg_fields_sql.sys.ini</language> </languages> <config> <fields name="params"> <fieldset name="basic"> <field name="query" type="textarea" label="PLG_FIELDS_SQL_PARAMS_QUERY_LABEL" description="PLG_FIELDS_SQL_PARAMS_QUERY_DESC" rows="10" filter="raw" required="true" /> <field name="multiple" type="radio" layout="joomla.form.field.radio.switcher" default="0" label="PLG_FIELDS_SQL_PARAMS_MULTIPLE_LABEL" filter="integer" > <option value="0">JNO</option> <option value="1">JYES</option> </field> </fieldset> </fields> </config> </extension> fields/sql/tmpl/sql.php 0000644 00000002136 15062070550 0011077 0 ustar 00 <?php /** * @package Joomla.Plugin * @subpackage Fields.Sql * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\Database\ParameterType; $value = $field->value; if ($value == '') { return; } $db = Factory::getDbo(); $value = (array) $value; $query = $db->getQuery(true); $sql = $fieldParams->get('query', ''); $bindNames = $query->bindArray($value, ParameterType::STRING); // Run the query with a having condition because it supports aliases $query->setQuery($sql . ' HAVING ' . $db->quoteName('value') . ' IN (' . implode(',', $bindNames) . ')'); try { $db->setQuery($query); $items = $db->loadObjectList(); } catch (Exception $e) { // If the query failed, we fetch all elements $db->setQuery($sql); $items = $db->loadObjectList(); } $texts = []; foreach ($items as $item) { if (in_array($item->value, $value)) { $texts[] = $item->text; } } echo htmlentities(implode(', ', $texts)); fields/mediajce/layouts/plugins/fields/mediajce/iframe.php 0000644 00000000377 15062070550 0017726 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); }); echo '<iframe ' . ArrayHelper::toString($displayData) . '></iframe>'; fields/mediajce/layouts/plugins/fields/mediajce/audio.php 0000644 00000000375 15062070550 0017562 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); }); echo '<audio ' . ArrayHelper::toString($displayData) . '></audio>'; fields/mediajce/layouts/plugins/fields/mediajce/figure.php 0000644 00000000750 15062070550 0017737 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; $caption = $displayData['caption']; $html = $displayData['html']; unset($displayData['caption']); unset($displayData['html']); array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); }); echo '<figure' . ArrayHelper::toString($displayData) . '>' . $html . '<figcaption>' . htmlentities($caption, ENT_COMPAT, 'UTF-8', true) . '</figcaption></figure>'; fields/mediajce/layouts/plugins/fields/mediajce/link.php 0000644 00000000753 15062070550 0017416 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; $displayData['href'] = $displayData['src']; unset($displayData['src']); $attribs = array(); foreach ($displayData as $key => $value) { if ($value !== '') { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); $attribs[$key] = $value; } }; $text = isset($attribs['title']) ? $attribs['title'] : basename($attribs['href']); echo '<a ' . ArrayHelper::toString($attribs) . '>' . $text . '</a>'; fields/mediajce/layouts/plugins/fields/mediajce/video.php 0000644 00000000375 15062070550 0017567 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); }); echo '<video ' . ArrayHelper::toString($displayData) . '></video>'; fields/mediajce/layouts/plugins/fields/mediajce/image.php 0000644 00000000507 15062070550 0017540 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); if ($key !== 'alt' && $value == '') { unset($displayData[$key]); } }); echo '<img ' . ArrayHelper::toString($displayData) . '>'; fields/mediajce/layouts/plugins/fields/mediajce/object.php 0000644 00000000435 15062070550 0017724 0 ustar 00 <?php defined('_JEXEC') or die; use Joomla\Utilities\ArrayHelper; unset ($displayData['src']); array_walk($displayData, function (&$value, $key) { $value = htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); }); echo '<object ' . ArrayHelper::toString($displayData) . '></object>'; fields/mediajce/helper/mediahelper.php 0000644 00000006135 15062070550 0014027 0 ustar 00 <?php final class WfMediaHelper { /** * An array of supported embed types and their mime types */ private static $embedMimes = array( "doc"=> "application/msword", "xls"=> "application/vnd.ms-excel", "ppt"=> "application/vnd.ms-powerpoint", "dot"=> "application/msword", "pps"=> "application/vnd.ms-powerpoint", "docx"=> "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "dotx"=> "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "pptx"=> "application/vnd.openxmlformats-officedocument.presentationml.presentation", "xlsx"=> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsm"=> "application/vnd.ms-excel.sheet.macroEnabled.12", "ppsx"=> "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "sldx"=> "application/vnd.openxmlformats-officedocument.presentationml.slide", "potx"=> "application/vnd.openxmlformats-officedocument.presentationml.template", "xltx"=> "application/vnd.openxmlformats-officedocument.spreadsheetml.template", "odt"=> "application/vnd.oasis.opendocument.text", "odg"=> "application/vnd.oasis.opendocument.graphics", "odp"=> "application/vnd.oasis.opendocument.presentation", "ods"=> "application/vnd.oasis.opendocument.spreadsheet", "odf"=> "application/vnd.oasis.opendocument.formula", "txt"=> "text/plain", "rtf"=> "application/rtf", "md"=> "text/markdown", "pdf"=> "application/pdf" ); /** * An array of supported media layout types and their file extensions */ private static $allowable = array( 'image' => 'jpg,jpeg,png,gif', 'audio' => 'mp3,m4a,mp4a,ogg', 'video' => 'mp4,mp4v,mpeg,mov,webm', 'object' => 'doc,docx,odg,odp,ods,odt,pdf,ppt,pptx,txt,xcf,xls,xlsx,csv', 'iframe' => '', ); /** * Get the embed type from the file extension * * @param [string] $extension File extension * @return Mime type or false */ public static function getMimeType($extension) { if (array_key_exists($extension, self::$embedMimes)) { return self::$embedMimes[$extension]; } return false; } /** * Get the media layout from the file extension * * @param [type] $extension File extension * @return Layout type */ public static function getLayoutFromExtension($extension) { $layout = 'link'; array_walk(self::$allowable, function ($values, $key) use ($extension, &$layout) { if (in_array($extension, explode(',', $values))) { $layout = $key; } }); return $layout; } /** * Determine whether the value is an image * * @param [string] $value * @return boolean */ public static function isImage($value) { $extension = pathinfo($value, PATHINFO_EXTENSION); return in_array($extension, explode(',', self::$allowable['image'])); } } fields/mediajce/fields/mediajce.xml 0000644 00000000523 15062070550 0013304 0 ustar 00 <?xml version="1.0" encoding="utf-8"?> <form> <fieldset name="media"> <field name="media_src" type="mediajce" label="PLG_FIELDS_MEDIAJCE_MEDIA_FILE_LABEL" schemes="http,https,ftp,ftps,data,file" validate="url" relative="true" /> <field name="media_text" type="text" label="PLG_FIELDS_MEDIAJCE_MEDIA_TEXT_LABEL" /> </fieldset> </form>