[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/sampledata/blog/ -> blog.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Sampledata.Blog
   6   *
   7   * @copyright   (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9  
  10   * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
  11   */
  12  
  13  use Joomla\CMS\Application\ApplicationHelper;
  14  use Joomla\CMS\Component\ComponentHelper;
  15  use Joomla\CMS\Extension\ExtensionHelper;
  16  use Joomla\CMS\HTML\HTMLHelper;
  17  use Joomla\CMS\Language\Multilanguage;
  18  use Joomla\CMS\Language\Text;
  19  use Joomla\CMS\Plugin\CMSPlugin;
  20  use Joomla\CMS\Plugin\PluginHelper;
  21  use Joomla\CMS\Session\Session;
  22  use Joomla\Database\ParameterType;
  23  
  24  // phpcs:disable PSR1.Files.SideEffects
  25  \defined('_JEXEC') or die;
  26  // phpcs:enable PSR1.Files.SideEffects
  27  
  28  /**
  29   * Sampledata - Blog Plugin
  30   *
  31   * @since  3.8.0
  32   */
  33  class PlgSampledataBlog extends CMSPlugin
  34  {
  35      /**
  36       * @var    \Joomla\Database\DatabaseDriver
  37       *
  38       * @since  3.8.0
  39       */
  40      protected $db;
  41  
  42      /**
  43       * @var    \Joomla\CMS\Application\CMSApplication
  44       *
  45       * @since  3.8.0
  46       */
  47      protected $app;
  48  
  49      /**
  50       * Affects constructor behavior. If true, language files will be loaded automatically.
  51       *
  52       * @var    boolean
  53       *
  54       * @since  3.8.0
  55       */
  56      protected $autoloadLanguage = true;
  57  
  58      /**
  59       * Holds the menuitem model
  60       *
  61       * @var    \Joomla\Component\Menus\Administrator\Model\ItemModel
  62       *
  63       * @since  3.8.0
  64       */
  65      private $menuItemModel;
  66  
  67      /**
  68       * Get an overview of the proposed sampledata.
  69       *
  70       * @return  stdClass|void  Will be converted into the JSON response to the module.
  71       *
  72       * @since  3.8.0
  73       */
  74      public function onSampledataGetOverview()
  75      {
  76          if (!$this->app->getIdentity()->authorise('core.create', 'com_content')) {
  77              return;
  78          }
  79  
  80          $data              = new stdClass();
  81          $data->name        = $this->_name;
  82          $data->title       = Text::_('PLG_SAMPLEDATA_BLOG_OVERVIEW_TITLE');
  83          $data->description = Text::_('PLG_SAMPLEDATA_BLOG_OVERVIEW_DESC');
  84          $data->icon        = 'wifi';
  85          $data->steps       = 4;
  86  
  87          return $data;
  88      }
  89  
  90      /**
  91       * First step to enter the sampledata. Content.
  92       *
  93       * @return  array|void  Will be converted into the JSON response to the module.
  94       *
  95       * @since  3.8.0
  96       */
  97      public function onAjaxSampledataApplyStep1()
  98      {
  99          if (!Session::checkToken('get') || $this->app->input->get('type') != $this->_name) {
 100              return;
 101          }
 102  
 103          if (!ComponentHelper::isEnabled('com_tags')) {
 104              $response            = [];
 105              $response['success'] = true;
 106              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_tags');
 107  
 108              return $response;
 109          }
 110  
 111          // Get some metadata.
 112          $access = (int) $this->app->get('access', 1);
 113          $user   = $this->app->getIdentity();
 114  
 115          // Detect language to be used.
 116          $language   = Multilanguage::isEnabled() ? $this->app->getLanguage()->getTag() : '*';
 117          $langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
 118  
 119          /** @var \Joomla\Component\Tags\Administrator\Model\TagModel $model */
 120          $modelTag = $this->app->bootComponent('com_tags')->getMVCFactory()
 121              ->createModel('Tag', 'Administrator', ['ignore_request' => true]);
 122  
 123          $tagIds = [];
 124  
 125          // Create first three tags.
 126          for ($i = 0; $i <= 3; $i++) {
 127              $title = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_TAG_' . $i . '_TITLE') . $langSuffix;
 128  
 129              $tag   = [
 130                  'id'              => 0,
 131                  'title'           => $title,
 132                  'alias'           => ApplicationHelper::stringURLSafe($title),
 133                  // Parent is root, except for the 4th tag. The 4th is child of the 3rd
 134                  'parent_id'       => $i === 3 ? $tagIds[2] : 1,
 135                  'published'       => 1,
 136                  'access'          => $access,
 137                  'created_user_id' => $user->id,
 138                  'language'        => $language,
 139                  'description'     => '',
 140              ];
 141  
 142              try {
 143                  if (!$modelTag->save($tag)) {
 144                      $this->app->getLanguage()->load('com_tags');
 145                      throw new Exception(Text::_($modelTag->getError()));
 146                  }
 147              } catch (Exception $e) {
 148                  $response            = [];
 149                  $response['success'] = false;
 150                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
 151  
 152                  return $response;
 153              }
 154  
 155              $tagIds[] = $modelTag->getItem()->id;
 156          }
 157  
 158          if (!ComponentHelper::isEnabled('com_content') || !$this->app->getIdentity()->authorise('core.create', 'com_content')) {
 159              $response            = [];
 160              $response['success'] = true;
 161              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 1, 'com_content');
 162  
 163              return $response;
 164          }
 165  
 166          if (ComponentHelper::isEnabled('com_fields') && $user->authorise('core.create', 'com_fields')) {
 167              $this->app->getLanguage()->load('com_fields');
 168  
 169              $mvcFactory = $this->app->bootComponent('com_fields')->getMVCFactory();
 170  
 171              $groupModel = $mvcFactory->createModel('Group', 'Administrator', ['ignore_request' => true]);
 172  
 173              $group = [
 174                  'title'           => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_GROUP_TITLE') . $langSuffix,
 175                  'id'              => 0,
 176                  'published'       => 1,
 177                  'ordering'        => 0,
 178                  'note'            => '',
 179                  'state'           => 1,
 180                  'access'          => $access,
 181                  'created_user_id' => $user->id,
 182                  'context'         => 'com_content.article',
 183                  'description'     => '',
 184                  'language'        => $language,
 185                  'params'          => '{"display_readonly":"1"}',
 186              ];
 187  
 188              try {
 189                  if (!$groupModel->save($group)) {
 190                      throw new Exception($groupModel->getError());
 191                  }
 192              } catch (Exception $e) {
 193                  $response            = array();
 194                  $response['success'] = false;
 195                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
 196  
 197                  return $response;
 198              }
 199  
 200              $groupId = $groupModel->getItem()->id;
 201  
 202              // Add fields
 203              $fieldIds = [];
 204  
 205              $articleFields = [
 206                  [
 207                      'type'   => 'textarea',
 208                      'fieldparams' => [
 209                          'rows'      => 3,
 210                          'cols'      => 80,
 211                          'maxlength' => 400,
 212                          'filter'    => '',
 213                      ],
 214                  ],
 215              ];
 216  
 217              $fieldModel = $mvcFactory->createModel('Field', 'Administrator', ['ignore_request' => true]);
 218  
 219              foreach ($articleFields as $i => $cf) {
 220                  // Set values from language strings.
 221                  $cfTitle                = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_FIELDS_FIELD_' . $i . '_TITLE') . $langSuffix;
 222  
 223                  $cf['id']               = 0;
 224                  $cf['name']             = $cfTitle;
 225                  $cf['label']            = $cfTitle;
 226                  $cf['title']            = $cfTitle;
 227                  $cf['description']      = '';
 228                  $cf['note']             = '';
 229                  $cf['default_value']    = '';
 230                  $cf['group_id']         = $groupId;
 231                  $cf['ordering']         = 0;
 232                  $cf['state']            = 1;
 233                  $cf['language']         = $language;
 234                  $cf['access']           = $access;
 235                  $cf['context']          = 'com_content.article';
 236                  $cf['params']       = [
 237                      'hint'               => '',
 238                      'class'              => '',
 239                      'label_class'        => '',
 240                      'show_on'            => '',
 241                      'render_class'       => '',
 242                      'showlabel'          => '1',
 243                      'label_render_class' => '',
 244                      'display'            => '3',
 245                      'prefix'             => '',
 246                      'suffix'             => '',
 247                      'layout'             => '',
 248                      'display_readonly'   => '2',
 249                  ];
 250  
 251                  try {
 252                      if (!$fieldModel->save($cf)) {
 253                          throw new Exception($fieldModel->getError());
 254                      }
 255                  } catch (Exception $e) {
 256                      $response            = array();
 257                      $response['success'] = false;
 258                      $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
 259  
 260                      return $response;
 261                  }
 262  
 263                  // Get ID from the field we just added
 264                  $fieldIds[] = $fieldModel->getItem()->id;
 265              }
 266          }
 267  
 268          if (ComponentHelper::isEnabled('com_workflow') && $this->app->getIdentity()->authorise('core.create', 'com_workflow')) {
 269              $this->app->bootComponent('com_workflow');
 270  
 271              // Create workflow
 272              $workflowTable = new \Joomla\Component\Workflow\Administrator\Table\WorkflowTable($this->db);
 273  
 274              $workflowTable->default = 0;
 275              $workflowTable->title = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_TITLE') . $langSuffix;
 276              $workflowTable->description = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_SAMPLE_DESCRIPTION');
 277              $workflowTable->published = 1;
 278              $workflowTable->access = $access;
 279              $workflowTable->created_user_id = $user->id;
 280              $workflowTable->extension = 'com_content.article';
 281  
 282              if (!$workflowTable->store()) {
 283                  $response            = array();
 284                  $response['success'] = false;
 285                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, Text::_($workflowTable->getError()));
 286  
 287                  return $response;
 288              }
 289  
 290              // Get ID from workflow we just added
 291              $workflowId = $workflowTable->id;
 292  
 293              // Create Stages.
 294              for ($i = 1; $i <= 9; $i++) {
 295                  $stageTable = new \Joomla\Component\Workflow\Administrator\Table\StageTable($this->db);
 296  
 297                  // Set values from language strings.
 298                  $stageTable->title  = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_TITLE');
 299                  $stageTable->description = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE' . $i . '_DESCRIPTION');
 300  
 301                  // Set values which are always the same.
 302                  $stageTable->id = 0;
 303                  $stageTable->published = 1;
 304                  $stageTable->ordering = 0;
 305                  $stageTable->default = $i == 6 ? 1 : 0;
 306                  $stageTable->workflow_id = $workflowId;
 307  
 308                  if (!$stageTable->store()) {
 309                      $response            = array();
 310                      $response['success'] = false;
 311                      $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, Text::_($stageTable->getError()));
 312  
 313                      return $response;
 314                  }
 315              }
 316  
 317              // Get the stage Ids of the new stages
 318              $query = $this->db->getQuery(true);
 319  
 320              $query->select([$this->db->quoteName('title'), $this->db->quoteName('id')])
 321                  ->from($this->db->quoteName('#__workflow_stages'))
 322                  ->where($this->db->quoteName('workflow_id') . ' = :workflow_id')
 323                  ->bind(':workflow_id', $workflowId, ParameterType::INTEGER);
 324  
 325              $stages = $this->db->setQuery($query)->loadAssocList('title', 'id');
 326  
 327              // Prepare Transitions
 328  
 329              $defaultOptions = json_encode(
 330                  [
 331                      'publishing' => 0,
 332                      'featuring' => 0,
 333                      'notification_send_mail' => false,
 334                  ]
 335              );
 336  
 337              $fromTo = array(
 338                  array(
 339                      // Idea to Copywriting
 340                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
 341                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
 342                      'options' => $defaultOptions,
 343                  ),
 344                  array(
 345                      // Copywriting to Graphic Design
 346                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
 347                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')],
 348                      'options' => $defaultOptions,
 349                  ),
 350                  array(
 351                      // Graphic Design to Fact Check
 352                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE3_TITLE')],
 353                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')],
 354                      'options' => $defaultOptions,
 355                  ),
 356                  array(
 357                      // Fact Check to Review
 358                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE4_TITLE')],
 359                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
 360                      'options' => $defaultOptions,
 361                  ),
 362                  array(
 363                      // Edit article - revision to copy writer
 364                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
 365                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE2_TITLE')],
 366                      'options' => $defaultOptions,
 367                  ),
 368                  array(
 369                      // Revision to published and featured
 370                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE5_TITLE')],
 371                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
 372                      'options' => json_encode(
 373                          array(
 374                              'publishing'  => 1,
 375                              'featuring' => 1,
 376                              'notification_send_mail' => true,
 377                              'notification_text' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'),
 378                              'notification_groups' => ["7"],
 379                          )
 380                      ),
 381                  ),
 382                  array(
 383                      // All to on Hold
 384                      'from_stage_id' => -1,
 385                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')],
 386                      'options' => json_encode(
 387                          array(
 388                              'publishing'  => 2,
 389                              'featuring' => 0,
 390                              'notification_send_mail' => false,
 391                          )
 392                      ),
 393                  ),
 394                  array(
 395                      // Idea to trash
 396                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
 397                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')],
 398                      'options' => json_encode(
 399                          array(
 400                              'publishing'  => -2,
 401                              'featuring' => 0,
 402                              'notification_send_mail' => false,
 403                          )
 404                      ),
 405                  ),
 406                  array(
 407                      // On Hold to Idea (Re-activate an idea)
 408                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE7_TITLE')],
 409                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE1_TITLE')],
 410                      'options' => $defaultOptions,
 411                  ),
 412                  array(
 413                      // Unpublish a published article
 414                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
 415                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')],
 416                      'options' => $defaultOptions,
 417                  ),
 418                  array(
 419                      // Trash a published article
 420                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
 421                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE8_TITLE')],
 422                      'options' => $defaultOptions,
 423                  ),
 424                  array(
 425                      // From unpublished back to published
 426                      'from_stage_id' => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE9_TITLE')],
 427                      'to_stage_id'   => $stages[Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TITLE')],
 428                      'options' => json_encode(
 429                          array(
 430                              'publishing'  => 1,
 431                              'featuring' => 0,
 432                              'notification_send_mail' => true,
 433                              'notification_text' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_STAGE6_TEXT'),
 434                              'notification_groups' => ["7"],
 435                          )
 436                      ),
 437                  ),
 438              );
 439  
 440              // Create Transitions.
 441              for ($i = 0; $i < count($fromTo); $i++) {
 442                  $trTable = new \Joomla\Component\Workflow\Administrator\Table\TransitionTable($this->db);
 443  
 444                  $trTable->from_stage_id = $fromTo[$i]['from_stage_id'];
 445                  $trTable->to_stage_id = $fromTo[$i]['to_stage_id'];
 446                  $trTable->options = $fromTo[$i]['options'];
 447  
 448                  // Set values from language strings.
 449                  $trTable->title = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_TITLE');
 450                  $trTable->description = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_WORKFLOW_TRANSITION' . ($i + 1) . '_DESCRIPTION');
 451  
 452                  // Set values which are always the same.
 453                  $trTable->id = 0;
 454                  $trTable->published = 1;
 455                  $trTable->ordering = 0;
 456                  $trTable->workflow_id = $workflowId;
 457  
 458                  if (!$trTable->store()) {
 459                      $response            = array();
 460                      $response['success'] = false;
 461                      $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, Text::_($trTable->getError()));
 462  
 463                      return $response;
 464                  }
 465              }
 466          }
 467  
 468          // Store the categories
 469          $catIds        = array();
 470  
 471          for ($i = 0; $i <= 3; $i++) {
 472              $categoryModel = $this->app->bootComponent('com_categories')
 473                  ->getMVCFactory()->createModel('Category', 'Administrator');
 474  
 475              $categoryTitle = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_' . $i . '_TITLE');
 476              $categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle);
 477  
 478              // Set unicodeslugs if alias is empty
 479              if (trim(str_replace('-', '', $categoryAlias) == '')) {
 480                  $unicode = $this->app->set('unicodeslugs', 1);
 481                  $categoryAlias = ApplicationHelper::stringURLSafe($categoryTitle);
 482                  $this->app->set('unicodeslugs', $unicode);
 483              }
 484  
 485              // Category 0 gets the workflow from above
 486              $params = $i == 0 ? '{"workflow_id":"' . $workflowId . '"}' : '{}';
 487  
 488              $category = [
 489                  'title'           => $categoryTitle . $langSuffix,
 490                  'parent_id'       => 1,
 491                  'id'              => 0,
 492                  'published'       => 1,
 493                  'access'          => $access,
 494                  'created_user_id' => $user->id,
 495                  'extension'       => 'com_content',
 496                  'level'           => 1,
 497                  'alias'           => $categoryAlias . $langSuffix,
 498                  'associations'    => array(),
 499                  'description'     => '',
 500                  'language'        => $language,
 501                  'params'          => $params,
 502              ];
 503  
 504              try {
 505                  if (!$categoryModel->save($category)) {
 506                      $this->app->getLanguage()->load('com_categories');
 507                      throw new Exception($categoryModel->getError());
 508                  }
 509              } catch (Exception $e) {
 510                  $response            = array();
 511                  $response['success'] = false;
 512                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, $e->getMessage());
 513  
 514                  return $response;
 515              }
 516  
 517              // Get ID from category we just added
 518              $catIds[] = $categoryModel->getItem()->id;
 519          }
 520  
 521          // Create Articles.
 522          $articles = array(
 523  
 524              // Category 1 = Help
 525              array(
 526                  // Article 0 - About
 527                  'catid'    => $catIds[1],
 528              ),
 529              array(
 530                  // Article 1 - Working on Your Site
 531                  'catid'    => $catIds[1],
 532                  'access'   => 3,
 533              ),
 534  
 535              // Category 0 = Blog
 536              array(
 537                  // Article 2 - Welcome to your blog
 538                  'catid'    => $catIds[0],
 539                  'featured' => 1,
 540                  'tags'     => array_map('strval', $tagIds),
 541                  'images'   => array(
 542                      'image_intro'               => 'images/sampledata/cassiopeia/nasa1-1200.jpg#'
 543                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-1200.jpg?width=1200&height=400',
 544                      'float_intro'               => '',
 545                      'image_intro_alt'           => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_2_INTROIMAGE_ALT'),
 546                      'image_intro_alt_empty'     => '',
 547                      'image_intro_caption'       => '',
 548                      'image_fulltext'            => 'images/sampledata/cassiopeia/nasa1-400.jpg#'
 549                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-400.jpg?width=400&height=400',
 550                      'float_fulltext'            => 'float-start',
 551                      'image_fulltext_alt'        => '',
 552                      'image_fulltext_alt_empty'  => 1,
 553                      'image_fulltext_caption'    => 'www.nasa.gov/multimedia/imagegallery',
 554                  ),
 555              ),
 556              array(
 557                  // Article 3 - About your home page
 558                  'catid'    => $catIds[0],
 559                  'featured' => 1,
 560                  'tags'     => array_map('strval', $tagIds),
 561                  'images'   => array(
 562                      'image_intro'               => 'images/sampledata/cassiopeia/nasa2-1200.jpg#'
 563                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-1200.jpg?width=1200&height=400',
 564                      'float_intro'               => '',
 565                      'image_intro_alt'           => '',
 566                      'image_intro_alt_empty'     => 1,
 567                      'image_intro_caption'       => '',
 568                      'image_fulltext'            => 'images/sampledata/cassiopeia/nasa2-400.jpg#'
 569                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-400.jpg?width=400&height=400',
 570                      'float_fulltext'            => 'float-start',
 571                      'image_fulltext_alt'        => '',
 572                      'image_fulltext_alt_empty'  => 1,
 573                      'image_fulltext_caption'    => 'www.nasa.gov/multimedia/imagegallery',
 574                  ),
 575                  'authorValue' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_FIELD_0'),
 576              ),
 577              array(
 578                  // Article 4 - Your Modules
 579                  'catid'    => $catIds[0],
 580                  'featured' => 1,
 581                  'tags'     => array_map('strval', $tagIds),
 582                  'images'   => array(
 583                      'image_intro'               => 'images/sampledata/cassiopeia/nasa3-1200.jpg#'
 584                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-1200.jpg?width=1200&height=400',
 585                      'float_intro'               => '',
 586                      'image_intro_alt'           => '',
 587                      'image_intro_alt_empty'     => 1,
 588                      'image_intro_caption'       => '',
 589                      'image_fulltext'            => 'images/sampledata/cassiopeia/nasa3-400.jpg#'
 590                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-400.jpg?width=400&height=400',
 591                      'float_fulltext'            => 'float-start',
 592                      'image_fulltext_alt'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_4_FULLTEXTIMAGE_ALT'),
 593                      'image_fulltext_alt_empty'  => '',
 594                      'image_fulltext_caption'    => 'www.nasa.gov/multimedia/imagegallery',
 595                  ),
 596              ),
 597              array(
 598                  // Article 5 - Your Template
 599                  'catid'    => $catIds[0],
 600                  'featured' => 1,
 601                  'tags'     => array_map('strval', $tagIds),
 602                  'images'   => array(
 603                      'image_intro'               => 'images/sampledata/cassiopeia/nasa4-1200.jpg#'
 604                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-1200.jpg?width=1200&height=400',
 605                      'float_intro'               => '',
 606                      'image_intro_alt'           => '',
 607                      'image_intro_alt_empty'     => 1,
 608                      'image_intro_caption'       => '',
 609                      'image_fulltext'            => 'images/sampledata/cassiopeia/nasa4-400.jpg#'
 610                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400',
 611                      'float_fulltext'            => 'float-start',
 612                      'image_fulltext_alt'        => '',
 613                      'image_fulltext_alt_empty'  => 1,
 614                      'image_fulltext_caption'    => 'www.nasa.gov/multimedia/imagegallery',
 615                  ),
 616              ),
 617              // Category 2 = Joomla - marketing texts
 618              array(
 619                  // Article 6 - Millions
 620                  'catid'    => $catIds[2],
 621                  'images'   => array(
 622                      'image_intro'            => 'images/sampledata/cassiopeia/nasa1-640.jpg#'
 623                                              . 'joomlaImage://local-images/sampledata/cassiopeia/nasa1-640.jpg?width=640&height=320',
 624                      'float_intro'            => '',
 625                      'image_intro_alt'        => '',
 626                      'image_intro_alt_empty'  => 1,
 627                      'image_intro_caption'    => '',
 628                  ),
 629              ),
 630              array(
 631                  // Article 7 - Love
 632                  'catid'    => $catIds[2],
 633                  'images'   => array(
 634                      'image_intro'            => 'images/sampledata/cassiopeia/nasa2-640.jpg#'
 635                                              . 'joomlaImage://local-images/sampledata/cassiopeia/nasa2-640.jpg?width=640&height=320',
 636                      'float_intro'            => '',
 637                      'image_intro_alt'        => '',
 638                      'image_intro_alt_empty'  => 1,
 639                      'image_intro_caption'    => '',
 640                  ),
 641              ),
 642              array(
 643                  // Article 8 - Joomla
 644                  'catid'    => $catIds[2],
 645                  'images'   => array(
 646                      'image_intro'            => 'images/sampledata/cassiopeia/nasa3-640.jpg#'
 647                                              . 'joomlaImage://local-images/sampledata/cassiopeia/nasa3-640.jpg?width=640&height=320',
 648                      'float_intro'            => '',
 649                      'image_intro_alt'        => '',
 650                      'image_intro_alt_empty'  => 1,
 651                      'image_intro_caption'    => '',
 652                  ),
 653              ),
 654              array(
 655                  // Article 9 - Workflows
 656                  'catid'       => $catIds[1],
 657                  'images'      => array(
 658                      'image_intro'               => '',
 659                      'float_intro'               => '',
 660                      'image_intro_alt'           => '',
 661                      'image_intro_alt_empty'     => '',
 662                      'image_intro_caption'       => '',
 663                      'image_fulltext'            => 'images/sampledata/cassiopeia/nasa4-400.jpg#'
 664                                                  . 'joomlaImage://local-images/sampledata/cassiopeia/nasa4-400.jpg?width=400&height=400',
 665                      'float_fulltext'            => 'float-end',
 666                      'image_fulltext_alt'        => '',
 667                      'image_fulltext_alt_empty'  => 1,
 668                      'image_fulltext_caption'    => 'www.nasa.gov/multimedia/imagegallery',
 669                  ),
 670                  'authorValue' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_FIELD_0'),
 671              ),
 672              // Category 3 - Typography
 673              array(
 674                  // Article 10 - Typography
 675                  'catid'    => $catIds[3],
 676              ),
 677          );
 678  
 679          $mvcFactory = $this->app->bootComponent('com_content')->getMVCFactory();
 680  
 681          // Store the articles
 682          foreach ($articles as $i => $article) {
 683              $articleModel = $mvcFactory->createModel('Article', 'Administrator', ['ignore_request' => true]);
 684  
 685              // Set values from language strings.
 686              $title                = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_TITLE');
 687              $alias                = ApplicationHelper::stringURLSafe($title);
 688              $article['title']     = $title . $langSuffix;
 689              $article['introtext'] = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_INTROTEXT');
 690              $article['fulltext']  = Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_FULLTEXT');
 691  
 692              // Set values which are always the same.
 693              $article['id']               = 0;
 694              $article['ordering']         = 0;
 695              $article['created_user_id']  = $user->id;
 696              $article['created_by_alias'] = 'Joomla';
 697              $article['alias']            = ApplicationHelper::stringURLSafe($article['title']);
 698  
 699              // Set unicodeslugs if alias is empty
 700              if (trim(str_replace('-', '', $alias) == '')) {
 701                  $unicode = $this->app->set('unicodeslugs', 1);
 702                  $article['alias'] = ApplicationHelper::stringURLSafe($article['title']);
 703                  $this->app->set('unicodeslugs', $unicode);
 704              }
 705  
 706              $article['language']        = $language;
 707              $article['associations']    = array();
 708              $article['metakey']         = '';
 709              $article['metadesc']        = '';
 710  
 711              if (!isset($article['featured'])) {
 712                  $article['featured']  = 0;
 713              }
 714  
 715              if (!isset($article['state'])) {
 716                  $article['state']  = 1;
 717              }
 718  
 719              if (!isset($article['images'])) {
 720                  $article['images']  = '';
 721              }
 722  
 723              if (!isset($article['access'])) {
 724                  $article['access'] = $access;
 725              }
 726  
 727              if (!$articleModel->save($article)) {
 728                  $response            = array();
 729                  $response['success'] = false;
 730                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 1, Text::_($articleModel->getError()));
 731  
 732                  return $response;
 733              }
 734  
 735              // Get ID from article we just added
 736              $ids[] = $articleModel->getItem()->id;
 737  
 738              if (
 739                  $article['featured']
 740                  && ComponentHelper::isEnabled('com_workflow')
 741                  && PluginHelper::isEnabled('workflow', 'featuring')
 742                  && ComponentHelper::getParams('com_content')->get('workflow_enabled')
 743              ) {
 744                  // Set the article featured in #__content_frontpage
 745                  $this->db->getQuery(true);
 746  
 747                  $featuredItem = (object) [
 748                      'content_id'      => $articleModel->getItem()->id,
 749                      'ordering'        => 0,
 750                      'featured_up'     => null,
 751                      'featured_down'   => null,
 752                  ];
 753  
 754                  $this->db->insertObject('#__content_frontpage', $featuredItem);
 755              }
 756  
 757              // Add a value to the custom field if a value is given
 758              if (ComponentHelper::isEnabled('com_fields') && $this->app->getIdentity()->authorise('core.create', 'com_fields')) {
 759                  if (!empty($article['authorValue'])) {
 760                      // Store a field value
 761  
 762                      $valueAuthor = (object) [
 763                          'item_id'  => $articleModel->getItem()->id,
 764                          'field_id' => $fieldIds[0],
 765                          'value'    => $article['authorValue'],
 766                      ];
 767  
 768                      $this->db->insertObject('#__fields_values', $valueAuthor);
 769                  }
 770              }
 771          }
 772  
 773          $this->app->setUserState('sampledata.blog.articles', $ids);
 774          $this->app->setUserState('sampledata.blog.articles.catIds', $catIds);
 775  
 776          $response            = [];
 777          $response['success'] = true;
 778          $response['message'] = Text::_('PLG_SAMPLEDATA_BLOG_STEP1_SUCCESS');
 779  
 780          return $response;
 781      }
 782  
 783      /**
 784       * Second step to enter the sampledata. Menus.
 785       *
 786       * @return  array|void  Will be converted into the JSON response to the module.
 787       *
 788       * @since  3.8.0
 789       */
 790      public function onAjaxSampledataApplyStep2()
 791      {
 792          if (!Session::checkToken('get') || $this->app->input->get('type') != $this->_name) {
 793              return;
 794          }
 795  
 796          if (!ComponentHelper::isEnabled('com_menus') || !$this->app->getIdentity()->authorise('core.create', 'com_menus')) {
 797              $response            = array();
 798              $response['success'] = true;
 799              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 2, 'com_menus');
 800  
 801              return $response;
 802          }
 803  
 804          // Detect language to be used.
 805          $language   = Multilanguage::isEnabled() ? $this->app->getLanguage()->getTag() : '*';
 806          $langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
 807  
 808          // Create the menu types.
 809          $menuTable = new \Joomla\Component\Menus\Administrator\Table\MenuTypeTable($this->db);
 810          $menuTypes = array();
 811  
 812          for ($i = 0; $i <= 2; $i++) {
 813              $menu = array(
 814                  'id'          => 0,
 815                  'title'       => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_TITLE') . $langSuffix,
 816                  'description' => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_DESCRIPTION'),
 817              );
 818  
 819              // Calculate menutype. The number of characters allowed is 24.
 820              $type = HTMLHelper::_('string.truncate', $menu['title'], 23, true, false);
 821  
 822              $menu['menutype'] = $i . $type;
 823  
 824              try {
 825                  $menuTable->load();
 826                  $menuTable->bind($menu);
 827  
 828                  if (!$menuTable->check()) {
 829                      $this->app->getLanguage()->load('com_menu');
 830                      throw new Exception($menuTable->getError());
 831                  }
 832  
 833                  $menuTable->store();
 834              } catch (Exception $e) {
 835                  $response            = array();
 836                  $response['success'] = false;
 837                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
 838  
 839                  return $response;
 840              }
 841  
 842              $menuTypes[] = $menuTable->menutype;
 843          }
 844  
 845          // Storing IDs in UserState for later usage.
 846          $this->app->setUserState('sampledata.blog.menutypes', $menuTypes);
 847  
 848          // Get previously entered Data from UserStates.
 849          $articleIds = $this->app->getUserState('sampledata.blog.articles');
 850  
 851          // Get MenuItemModel.
 852          $this->menuItemModel = $this->app->bootComponent('com_menus')->getMVCFactory()
 853              ->createModel('Item', 'Administrator', ['ignore_request' => true]);
 854  
 855          // Get previously entered categories ids
 856          $catIds = $this->app->getUserState('sampledata.blog.articles.catIds');
 857  
 858          // Link to the homepage from logout
 859          $home = $this->app->getMenu('site')->getDefault()->id;
 860  
 861          if (Multilanguage::isEnabled()) {
 862              $homes = Multilanguage::getSiteHomePages();
 863  
 864              if (isset($homes[$language])) {
 865                  $home = $homes[$language]->id;
 866              }
 867          }
 868  
 869          // Insert menuitems level 1.
 870          $menuItems = array(
 871              array(
 872                  // Blog
 873                  'menutype'     => $menuTypes[0],
 874                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'),
 875                  'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0],
 876                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
 877                  'params'       => array(
 878                      'layout_type'             => 'blog',
 879                      'show_category_title'     => 0,
 880                      'num_leading_articles'    => 4,
 881                      'num_intro_articles'      => 4,
 882                      'num_links'               => 0,
 883                      'orderby_sec'             => 'rdate',
 884                      'order_date'              => 'published',
 885                      'blog_class_leading'      => 'boxed columns-2',
 886                      'show_pagination'         => 2,
 887                      'secure'                  => 0,
 888                      'show_page_heading'       => 1,
 889                  ),
 890              ),
 891              array(
 892                  // Help
 893                  'menutype'     => $menuTypes[0],
 894                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE'),
 895                  'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[1],
 896                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
 897                  'params'       => array(
 898                      'blog_class_leading'      => '',
 899                      'blog_class'              => 'boxed',
 900                      'num_leading_articles'    => 0,
 901                      'num_intro_articles'      => 4,
 902                      'num_links'               => 0,
 903                      'orderby_sec'             => 'rdate',
 904                      'order_date'              => 'published',
 905                      'show_pagination'         => 4,
 906                      'show_pagination_results' => 1,
 907                      'article_layout'          => '_:default',
 908                      'link_titles'             => 0,
 909                      'info_block_show_title'   => '',
 910                      'show_category'           => 0,
 911                      'link_category'           => '',
 912                      'show_parent_category'    => '',
 913                      'link_parent_category'    => '',
 914                      'show_author'             => 0,
 915                      'link_author'             => '',
 916                      'show_create_date'        => 0,
 917                      'show_modify_date'        => '',
 918                      'show_publish_date'       => 0,
 919                      'show_hits'               => 0,
 920                      'menu_text'               => 1,
 921                      'menu_show'               => 1,
 922                      'show_page_heading'       => 1,
 923                      'secure'                  => 0,
 924                  ),
 925              ),
 926              array(
 927                  // Login
 928                  'menutype'     => $menuTypes[0],
 929                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_2_TITLE'),
 930                  'link'         => 'index.php?option=com_users&view=login',
 931                  'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
 932                  'access'       => 5,
 933                  'params'       => array(
 934                      'loginredirectchoice'      => '1',
 935                      'login_redirect_url'       => '',
 936                      'login_redirect_menuitem'  => $home,
 937                      'logoutredirectchoice'     => '1',
 938                      'logout_redirect_url'      => '',
 939                      'logout_redirect_menuitem' => $home,
 940                      'secure'                   => 0,
 941                  ),
 942              ),
 943              array(
 944                  // Logout
 945                  'menutype'     => $menuTypes[0],
 946                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'),
 947                  'link'         => 'index.php?option=com_users&view=login&layout=logout&task=user.menulogout',
 948                  'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
 949                  'access'       => 2,
 950                  'params'       => array(
 951                      'logout'   => $home,
 952                      'secure'   => 0,
 953                  ),
 954              ),
 955              array(
 956                  // Sample metismenu (heading)
 957                  'menutype'     => $menuTypes[0],
 958                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_11_TITLE'),
 959                  'type'         => 'heading',
 960                  'link'         => '',
 961                  'component_id' => 0,
 962                  'params'       => array(
 963                      'layout_type'             => 'heading',
 964                      'menu_text'               => 1,
 965                      'show_page_heading'       => 0,
 966                      'secure'                  => 0,
 967                  ),
 968              ),
 969              array(
 970                  // Typography
 971                  'menutype'     => $menuTypes[0],
 972                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_14_TITLE'),
 973                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3],
 974                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
 975                  'params'       => array(
 976                      'show_title'            => 0,
 977                      'link_titles'           => 0,
 978                      'show_intro'            => 1,
 979                      'info_block_position'   => '',
 980                      'info_block_show_title' => 0,
 981                      'show_category'         => 0,
 982                      'show_author'           => 0,
 983                      'show_create_date'      => 0,
 984                      'show_modify_date'      => 0,
 985                      'show_publish_date'     => 0,
 986                      'show_item_navigation'  => 0,
 987                      'show_hits'             => 0,
 988                      'show_tags'             => 0,
 989                      'menu_text'             => 1,
 990                      'menu_show'             => 1,
 991                      'page_title'            => '',
 992                      'secure'                => 0,
 993                  ),
 994              ),
 995              array(
 996                  'menutype'     => $menuTypes[1],
 997                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_3_TITLE'),
 998                  'link'         => 'index.php?option=com_content&view=form&layout=edit',
 999                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1000                  'access'       => 3,
1001                  'params'       => array(
1002                      'enable_category'   => 1,
1003                      'catid'             => $catIds[0],
1004                      'menu_text'         => 1,
1005                      'show_page_heading' => 0,
1006                      'secure'            => 0,
1007                  ),
1008              ),
1009              array(
1010                  'menutype'     => $menuTypes[1],
1011                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_4_TITLE'),
1012                  'link'         => 'index.php?option=com_content&view=article&id=' . $articleIds[1],
1013                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1014                  'params'       => array(
1015                      'menu_text'         => 1,
1016                      'show_page_heading' => 0,
1017                      'secure'            => 0,
1018                  ),
1019              ),
1020              array(
1021                  'menutype'     => $menuTypes[1],
1022                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_5_TITLE'),
1023                  'link'         => 'administrator',
1024                  'type'         => 'url',
1025                  'component_id' => 0,
1026                  'browserNav'   => 1,
1027                  'access'       => 3,
1028                  'params'       => array(
1029                      'menu_text' => 1,
1030                      'secure'    => 0,
1031                  ),
1032              ),
1033              array(
1034                  'menutype'     => $menuTypes[1],
1035                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_6_TITLE'),
1036                  'link'         => 'index.php?option=com_users&view=profile&layout=edit',
1037                  'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
1038                  'access'       => 2,
1039                  'params'       => array(
1040                      'menu_text'         => 1,
1041                      'show_page_heading' => 0,
1042                      'secure'            => 0,
1043                  ),
1044              ),
1045              array(
1046                  'menutype'     => $menuTypes[1],
1047                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_7_TITLE'),
1048                  'link'         => 'index.php?option=com_users&view=login',
1049                  'component_id' => ExtensionHelper::getExtensionRecord('com_users', 'component')->extension_id,
1050                  'params'       => array(
1051                      'logindescription_show'  => 1,
1052                      'logoutdescription_show' => 1,
1053                      'menu_text'              => 1,
1054                      'show_page_heading'      => 0,
1055                      'secure'                 => 0,
1056                  ),
1057              ),
1058          );
1059  
1060          try {
1061              $menuIdsLevel1 = $this->addMenuItems($menuItems, 1);
1062          } catch (Exception $e) {
1063              $response            = array();
1064              $response['success'] = false;
1065              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
1066  
1067              return $response;
1068          }
1069  
1070          // Insert level 1 (Link in the footer as alias)
1071          $menuItems = array(
1072              array(
1073                  'menutype'     => $menuTypes[2],
1074                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_8_TITLE'),
1075                  'link'         => 'index.php?Itemid=',
1076                  'type'         => 'alias',
1077                  'access'       => 5,
1078                  'params'       => array(
1079                      'aliasoptions'      => $menuIdsLevel1[2],
1080                      'alias_redirect'    => 0,
1081                      'menu-anchor_title' => '',
1082                      'menu-anchor_css'   => '',
1083                      'menu_image'        => '',
1084                      'menu_image_css'    => '',
1085                      'menu_text'         => 1,
1086                      'menu_show'         => 1,
1087                      'secure'            => 0,
1088                  ),
1089              ),
1090              array(
1091                  'menutype'     => $menuTypes[2],
1092                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_16_TITLE'),
1093                  'link'         => 'index.php?Itemid=',
1094                  'type'         => 'alias',
1095                  'access'       => 2,
1096                  'params'       => array(
1097                      'aliasoptions'      => $menuIdsLevel1[3],
1098                      'alias_redirect'    => 0,
1099                      'menu-anchor_title' => '',
1100                      'menu-anchor_css'   => '',
1101                      'menu_image'        => '',
1102                      'menu_image_css'    => '',
1103                      'menu_text'         => 1,
1104                      'menu_show'         => 1,
1105                      'secure'            => 0,
1106                      ),
1107                  ),
1108                  array(
1109                      // Hidden menuItem search
1110                  'menutype'     => $menuTypes[2],
1111                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_15_TITLE'),
1112                  'link'         => 'index.php?option=com_finder&view=search',
1113                  'type'         => 'component',
1114                  'component_id' => ExtensionHelper::getExtensionRecord('com_finder', 'component')->extension_id,
1115                  'params'       => array(
1116                      'show_date_filters' => '1',
1117                      'show_advanced'         => '',
1118                      'expand_advanced'       => '1',
1119                      'show_taxonomy'         => '1',
1120                      'show_date'             => '1',
1121                      'show_url'              => '1',
1122                      'menu_text'             => 0,
1123                      'menu_show'             => 0,
1124                      'secure'                => 0,
1125                  ),
1126              ),
1127          );
1128  
1129          try {
1130              $menuIdsLevel1 = array_merge($menuIdsLevel1, $this->addMenuItems($menuItems, 1));
1131          } catch (Exception $e) {
1132              $response            = array();
1133              $response['success'] = false;
1134              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
1135  
1136              return $response;
1137          }
1138  
1139          $this->app->setUserState('sampledata.blog.menuIdsLevel1', $menuIdsLevel1);
1140  
1141          // Insert menuitems level 2.
1142          $menuItems = array(
1143              array(
1144                  'menutype'     => $menuTypes[1],
1145                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_9_TITLE'),
1146                  'link'         => 'index.php?option=com_config&view=config',
1147                  'parent_id'    => $menuIdsLevel1[6],
1148                  'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id,
1149                  'access'       => 6,
1150                  'params'       => array(
1151                      'menu_text'         => 1,
1152                      'show_page_heading' => 0,
1153                      'secure'            => 0,
1154                  ),
1155              ),
1156              array(
1157                  'menutype'     => $menuTypes[1],
1158                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_10_TITLE'),
1159                  'link'         => 'index.php?option=com_config&view=templates',
1160                  'parent_id'    => $menuIdsLevel1[6],
1161                  'component_id' => ExtensionHelper::getExtensionRecord('com_config', 'component')->extension_id,
1162                  'access'       => 6,
1163                  'params'       => array(
1164                      'menu_text'         => 1,
1165                      'show_page_heading' => 0,
1166                      'secure'            => 0,
1167                  ),
1168              ),
1169              array(
1170                  // Blog
1171                  'menutype'     => $menuTypes[0],
1172                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_0_TITLE'),
1173                  'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[0],
1174                  'parent_id'    => $menuIdsLevel1[4],
1175                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1176                  'params'       => array(
1177                      'layout_type'             => 'blog',
1178                      'show_category_title'     => 0,
1179                      'num_leading_articles'    => 1,
1180                      'num_intro_articles'      => 2,
1181                      'num_links'               => 2,
1182                      'orderby_sec'             => 'front',
1183                      'order_date'              => 'published',
1184                      'blog_class_leading'      => 'boxed columns-1',
1185                      'blog_class'              => 'columns-2',
1186                      'show_pagination'         => 2,
1187                      'show_pagination_results' => 1,
1188                      'show_category'           => 0,
1189                      'info_bloc_position'      => 0,
1190                      'show_publish_date'       => 0,
1191                      'show_hits'               => 0,
1192                      'show_feed_link'          => 0,
1193                      'menu_text'               => 1,
1194                      'show_page_heading'       => 0,
1195                      'secure'                  => 0,
1196                  ),
1197              ),
1198              array(
1199                  // Category List
1200                  'menutype'     => $menuTypes[0],
1201                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_12_TITLE'),
1202                  'link'         => 'index.php?option=com_content&view=category&id=' . $catIds[0],
1203                  'parent_id'    => $menuIdsLevel1[4],
1204                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1205                  'params'       => array(
1206                      'menu_text'         => 1,
1207                      'show_page_heading' => 1,
1208                      'secure'            => 0,
1209                  ),
1210              ),
1211              array(
1212                  // Articles (menu header)
1213                  'menutype'     => $menuTypes[0],
1214                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_ITEM_13_TITLE'),
1215                  'link'         => 'index.php?option=com_content&view=category&layout=blog&id=' . $catIds[2],
1216                  'parent_id'    => $menuIdsLevel1[4],
1217                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1218                  'params'       => array(
1219                      'layout_type'             => 'blog',
1220                      'show_category_title'     => 0,
1221                      'num_leading_articles'    => 3,
1222                      'num_intro_articles'      => 0,
1223                      'num_links'               => 2,
1224                      'orderby_sec'             => 'front',
1225                      'order_date'              => 'published',
1226                      'blog_class_leading'      => 'boxed columns-3',
1227                      'blog_class'              => '',
1228                      'show_pagination'         => 2,
1229                      'show_pagination_results' => 1,
1230                      'show_category'           => 0,
1231                      'info_bloc_position'      => 0,
1232                      'show_publish_date'       => 0,
1233                      'show_hits'               => 0,
1234                      'show_feed_link'          => 0,
1235                      'menu_text'               => 1,
1236                      'show_page_heading'       => 0,
1237                      'secure'                  => 0,
1238                  ),
1239              ),
1240              array(
1241                  'menutype'     => $menuTypes[0],
1242                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_3_TITLE'),
1243                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[3],
1244                  'parent_id'    => $menuIdsLevel1[1],
1245                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1246                  'params'       => array(
1247                      'menu_show'         => 1,
1248                      'show_page_heading' => 0,
1249                      'secure'            => 0,
1250                  ),
1251              ),
1252              array(
1253                  'menutype'     => $menuTypes[0],
1254                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_9_TITLE'),
1255                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[9],
1256                  'parent_id'    => $menuIdsLevel1[1],
1257                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1258                  'params'       => array(
1259                      'menu_show'         => 1,
1260                      'show_page_heading' => 0,
1261                      'secure'            => 0,
1262                  ),
1263              ),
1264          );
1265  
1266          try {
1267              $menuIdsLevel2 = $this->addMenuItems($menuItems, 2);
1268          } catch (Exception $e) {
1269              $response            = array();
1270              $response['success'] = false;
1271              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
1272  
1273              return $response;
1274          }
1275  
1276          // Add a third level of menuItems - use article title also for menuItem title
1277          $menuItems = array(
1278              array(
1279                  'menutype'     => $menuTypes[0],
1280                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_6_TITLE'),
1281                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[6],
1282                  'parent_id'    => $menuIdsLevel2[4],
1283                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1284                  'params'       => array(
1285                      'menu_show' => 1,
1286                      'secure'    => 0,
1287                  ),
1288              ),
1289              array(
1290                  'menutype'     => $menuTypes[0],
1291                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_7_TITLE'),
1292                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[7],
1293                  'parent_id'    => $menuIdsLevel2[4],
1294                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1295                  'params'       => array(
1296                      'menu_show' => 1,
1297                      'secure'    => 0,
1298                  ),
1299              ),
1300              array(
1301                  'menutype'     => $menuTypes[0],
1302                  'title'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_8_TITLE'),
1303                  'link'         => 'index.php?option=com_content&view=article&id=' . (int) $articleIds[8],
1304                  'parent_id'    => $menuIdsLevel2[4],
1305                  'component_id' => ExtensionHelper::getExtensionRecord('com_content', 'component')->extension_id,
1306                  'params'       => array(
1307                      'menu_show' => 1,
1308                      'secure'    => 0,
1309                  ),
1310              ),
1311          );
1312  
1313          try {
1314              $this->addMenuItems($menuItems, 3);
1315          } catch (Exception $e) {
1316              $response            = array();
1317              $response['success'] = false;
1318              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 2, $e->getMessage());
1319  
1320              return $response;
1321          }
1322  
1323          $response            = array();
1324          $response['success'] = true;
1325          $response['message'] = Text::_('PLG_SAMPLEDATA_BLOG_STEP2_SUCCESS');
1326  
1327          return $response;
1328      }
1329  
1330      /**
1331       * Third step to enter the sampledata. Modules.
1332       *
1333       * @return  array|void  Will be converted into the JSON response to the module.
1334       *
1335       * @since  3.8.0
1336       */
1337      public function onAjaxSampledataApplyStep3()
1338      {
1339          if (!Session::checkToken('get') || $this->app->input->get('type') != $this->_name) {
1340              return;
1341          }
1342  
1343          $this->app->getLanguage()->load('com_modules');
1344  
1345          if (!ComponentHelper::isEnabled('com_modules') || !$this->app->getIdentity()->authorise('core.create', 'com_modules')) {
1346              $response            = array();
1347              $response['success'] = true;
1348              $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_SKIPPED', 3, 'com_modules');
1349  
1350              return $response;
1351          }
1352  
1353          // Detect language to be used.
1354          $language   = Multilanguage::isEnabled() ? $this->app->getLanguage()->getTag() : '*';
1355          $langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
1356  
1357          // Add Include Paths.
1358          /** @var \Joomla\Component\Modules\Administrator\Model\ModuleModel $model */
1359          $model = $this->app->bootComponent('com_modules')->getMVCFactory()
1360              ->createModel('Module', 'Administrator', ['ignore_request' => true]);
1361          $access = (int) $this->app->get('access', 1);
1362  
1363          // Get previously entered Data from UserStates.
1364          $articleIds = $this->app->getUserState('sampledata.blog.articles');
1365  
1366          // Get previously entered Data from UserStates
1367          $menuTypes = $this->app->getUserState('sampledata.blog.menutypes');
1368  
1369          // Get previously entered categories ids
1370          $catIds = $this->app->getUserState('sampledata.blog.articles.catIds');
1371  
1372          // Link to article "typography" in banner module
1373          $headerLink = 'index.php?option=com_content&view=article&id=' . (int) $articleIds[10] . '&catid=' . (int) $catIds[3];
1374  
1375          $modules = array(
1376              array(
1377                  // The main menu Blog
1378                  'title'     => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_0_TITLE'),
1379                  'ordering'  => 1,
1380                  'position'  => 'menu',
1381                  'module'    => 'mod_menu',
1382                  'showtitle' => 0,
1383                  'params'    => array(
1384                      'menutype'        => $menuTypes[0],
1385                      'layout'          => 'cassiopeia:collapse-metismenu',
1386                      'startLevel'      => 1,
1387                      'endLevel'        => 0,
1388                      'showAllChildren' => 1,
1389                      'class_sfx'       => '',
1390                      'cache'           => 1,
1391                      'cache_time'      => 900,
1392                      'cachemode'       => 'itemid',
1393                      'module_tag'      => 'nav',
1394                      'bootstrap_size'  => 0,
1395                      'header_tag'      => 'h3',
1396                      'style'           => 0,
1397                  ),
1398              ),
1399              array(
1400                  // The author Menu, for registered users
1401                  'title'     => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_1_TITLE'),
1402                  'ordering'  => 1,
1403                  'position'  => 'sidebar-right',
1404                  'module'    => 'mod_menu',
1405                  'access'    => 3,
1406                  'showtitle' => 0,
1407                  'params'    => array(
1408                      'menutype'        => $menuTypes[1],
1409                      'startLevel'      => 1,
1410                      'endLevel'        => 0,
1411                      'showAllChildren' => 1,
1412                      'class_sfx'       => '',
1413                      'layout'          => '_:default',
1414                      'cache'           => 1,
1415                      'cache_time'      => 900,
1416                      'cachemode'       => 'itemid',
1417                      'module_tag'      => 'aside',
1418                      'bootstrap_size'  => 0,
1419                      'header_tag'      => 'h3',
1420                      'style'           => 0,
1421                  ),
1422              ),
1423              array(
1424                  // Syndication
1425                  'title'     => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_2_TITLE'),
1426                  'ordering'  => 6,
1427                  'position'  => 'sidebar-right',
1428                  'module'    => 'mod_syndicate',
1429                  'showtitle' => 0,
1430                  'params'    => array(
1431                      'display_text' => 1,
1432                      'text'         => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_NEWSFEEDS_TITLE'),
1433                      'format'       => 'rss',
1434                      'layout'       => '_:default',
1435                      'cache'        => 0,
1436                      'module_tag'   => 'section',
1437                  ),
1438              ),
1439              array(
1440                  // Archived Articles
1441                  'title'    => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_3_TITLE'),
1442                  'ordering' => 4,
1443                  'position' => 'sidebar-right',
1444                  'module'   => 'mod_articles_archive',
1445                  'params'   => array(
1446                      'count'      => 10,
1447                      'layout'     => '_:default',
1448                      'cache'      => 1,
1449                      'cache_time' => 900,
1450                      'module_tag' => 'div',
1451                      'cachemode'  => 'static',
1452                  ),
1453              ),
1454              array(
1455                  // Latest Posts
1456                  'title'      => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_4_TITLE'),
1457                  'ordering'   => 6,
1458                  'position'   => 'top-a',
1459                  'module'     => 'mod_articles_news',
1460                  // Assignment 1 means here - only on the homepage
1461                  'assignment' => 1,
1462                  'showtitle'  => 0,
1463                  'params'   => array(
1464                      'catid'             => $catIds[2],
1465                      'image'             => 1,
1466                      'img_intro_full'    => 'intro',
1467                      'item_title'        => 0,
1468                      'link_titles'       => '',
1469                      'item_heading'      => 'h4',
1470                      'triggerevents'     => 1,
1471                      'showLastSeparator' => 1,
1472                      'show_introtext'    => 1,
1473                      'readmore'          => 1,
1474                      'count'             => 3,
1475                      'show_featured'     => '',
1476                      'exclude_current'   => 0,
1477                      'ordering'          => 'a.publish_up',
1478                      'direction'         => 1,
1479                      'layout'            => '_:horizontal',
1480                      'moduleclass_sfx'   => '',
1481                      'cache'             => 1,
1482                      'cache_time'        => 900,
1483                      'cachemode'         => 'itemid',
1484                      'style'             => 'Cassiopeia-noCard',
1485                      'module_tag'        => 'div',
1486                      'bootstrap_size'    => '0',
1487                      'header_tag'        => 'h3',
1488                      'header_class'      => '',
1489                  ),
1490              ),
1491              array(
1492                  // Older Posts (from category 0 = blog)
1493                  'title'    => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_5_TITLE'),
1494                  'ordering' => 2,
1495                  'position' => 'bottom-b',
1496                  'module'   => 'mod_articles_category',
1497                  'params'   => array(
1498                      'mode'                         => 'normal',
1499                      'show_on_article_page'         => 0,
1500                      'show_front'                   => 'show',
1501                      'count'                        => 6,
1502                      'category_filtering_type'      => 1,
1503                      'catid'                        => $catIds[0],
1504                      'show_child_category_articles' => 0,
1505                      'levels'                       => 1,
1506                      'author_filtering_type'        => 1,
1507                      'author_alias_filtering_type'  => 1,
1508                      'date_filtering'               => 'off',
1509                      'date_field'                   => 'a.created',
1510                      'relative_date'                => 30,
1511                      'article_ordering'             => 'a.created',
1512                      'article_ordering_direction'   => 'DESC',
1513                      'article_grouping'             => 'none',
1514                      'article_grouping_direction'   => 'krsort',
1515                      'month_year_format'            => 'F Y',
1516                      'item_heading'                 => 5,
1517                      'link_titles'                  => 1,
1518                      'show_date'                    => 0,
1519                      'show_date_field'              => 'created',
1520                      'show_date_format'             => Text::_('DATE_FORMAT_LC5'),
1521                      'show_category'                => 0,
1522                      'show_hits'                    => 0,
1523                      'show_author'                  => 0,
1524                      'show_introtext'               => 0,
1525                      'introtext_limit'              => 100,
1526                      'show_readmore'                => 0,
1527                      'show_readmore_title'          => 1,
1528                      'readmore_limit'               => 15,
1529                      'layout'                       => '_:default',
1530                      'owncache'                     => 1,
1531                      'cache_time'                   => 900,
1532                      'module_tag'                   => 'div',
1533                      'bootstrap_size'               => 4,
1534                      'header_tag'                   => 'h3',
1535                      'style'                        => 0,
1536                  ),
1537              ),
1538              array(
1539                  // Bottom Menu
1540                  'title'     => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_6_TITLE'),
1541                  'ordering'  => 1,
1542                  'position'  => 'footer',
1543                  'module'    => 'mod_menu',
1544                  'showtitle' => 0,
1545                  'params'    => array(
1546                      'menutype'        => $menuTypes[2],
1547                      'class_sfx'       => 'menu-horizontal',
1548                      'startLevel'      => 1,
1549                      'endLevel'        => 0,
1550                      'showAllChildren' => 0,
1551                      'layout'          => 'cassiopeia:dropdown-metismenu',
1552                      'cache'           => 1,
1553                      'cache_time'      => 900,
1554                      'cachemode'       => 'itemid',
1555                      'module_tag'      => 'div',
1556                      'bootstrap_size'  => 0,
1557                      'header_tag'      => 'h3',
1558                      'style'           => 0,
1559                  ),
1560              ),
1561              array(
1562                  // Search
1563                  'title'    => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'),
1564                  'ordering' => 1,
1565                  'position' => 'search',
1566                  'module'   => 'mod_finder',
1567                  'params'   => array(
1568                      'searchfilter'     => '',
1569                      'show_autosuggest' => 1,
1570                      'show_advanced'    => 0,
1571                      'show_label'       => 0,
1572                      'alt_label'        => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_7_TITLE'),
1573                      'show_button'      => 1,
1574                      'opensearch'       => 1,
1575                      'opensearch_name'  => '',
1576                      'set_itemid'       => 0,
1577                      'layout'           => '_:default',
1578                      'module_tag'       => 'search',
1579                  ),
1580              ),
1581              array(
1582                  // Header image
1583                  'title'      => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_TITLE'),
1584                  'content'    => '<p>' . Text::sprintf('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_8_CONTENT', $headerLink) . '</p>',
1585                  'ordering'   => 1,
1586                  'position'   => 'banner',
1587                  'module'     => 'mod_custom',
1588                  // Assignment 1 means here - only on the homepage
1589                  'assignment' => 1,
1590                  'showtitle'  => 0,
1591                  'params'     => array(
1592                      'prepare_content' => 0,
1593                      'backgroundimage' => 'images/banners/banner.jpg#joomlaImage://local-images/banners/banner.jpg?width=1140&height=600',
1594                      'layout'          => 'cassiopeia:banner',
1595                      'moduleclass_sfx' => '',
1596                      'cache'           => 1,
1597                      'cache_time'      => 900,
1598                      'cachemode'       => 'static',
1599                      'style'           => '0',
1600                      'module_tag'      => 'div',
1601                      'bootstrap_size'  => '0',
1602                      'header_tag'      => 'h3',
1603                      'header_class'    => '',
1604                  ),
1605              ),
1606              array(
1607                  // Popular Tags
1608                  'title'    => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_9_TITLE'),
1609                  'ordering' => 1,
1610                  'position' => 'bottom-b',
1611                  'module'   => 'mod_tags_popular',
1612                  'params'   => array(
1613                      'maximum'         => 8,
1614                      'timeframe'       => 'alltime',
1615                      'order_value'     => 'count',
1616                      'order_direction' => 1,
1617                      'display_count'   => 1,
1618                      'no_results_text' => 0,
1619                      'minsize'         => 1,
1620                      'maxsize'         => 2,
1621                      'layout'          => '_:cloud',
1622                      'owncache'        => 1,
1623                      'module_tag'      => 'aside',
1624                      'bootstrap_size'  => 4,
1625                      'header_tag'      => 'h3',
1626                      'style'           => 0,
1627                  ),
1628              ),
1629              array(
1630                  // Similar Items
1631                  'title'    => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_10_TITLE'),
1632                  'ordering' => 0,
1633                  'module'   => 'mod_tags_similar',
1634                  'position' => 'bottom-b',
1635                  'params'   => array(
1636                      'maximum'        => 5,
1637                      'matchtype'      => 'any',
1638                      'layout'         => '_:default',
1639                      'owncache'       => 1,
1640                      'module_tag'     => 'div',
1641                      'bootstrap_size' => 4,
1642                      'header_tag'     => 'h3',
1643                      'style'          => 0,
1644                  ),
1645              ),
1646              array(
1647                  // Backend - Site Information
1648                  'title'     => Text::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_11_TITLE'),
1649                  'ordering'  => 4,
1650                  'position'  => 'cpanel',
1651                  'module'    => 'mod_stats_admin',
1652                  'access'    => 6,
1653                  'client_id' => 1,
1654                  'params'    => array(
1655                      'serverinfo'     => 1,
1656                      'siteinfo'       => 1,
1657                      'counter'        => 0,
1658                      'increase'       => 0,
1659                      'layout'         => '_:default',
1660                      'cache'          => 1,
1661                      'cache_time'     => 900,
1662                      'cachemode'      => 'static',
1663                      'module_tag'     => 'div',
1664                      'bootstrap_size' => 0,
1665                      'header_tag'     => 'h3',
1666                      'style'          => 0,
1667                  ),
1668              ),
1669          );
1670  
1671          // Assignment means always "only on the homepage".
1672          if (Multilanguage::isEnabled()) {
1673              $homes = Multilanguage::getSiteHomePages();
1674  
1675              if (isset($homes[$language])) {
1676                  $home = $homes[$language]->id;
1677              }
1678          }
1679  
1680          if (!isset($home)) {
1681              $home = $this->app->getMenu('site')->getDefault()->id;
1682          }
1683  
1684          foreach ($modules as $module) {
1685              // Append language suffix to title.
1686              $module['title'] .= $langSuffix;
1687  
1688              // Set values which are always the same.
1689              $module['id']         = 0;
1690              $module['asset_id']   = 0;
1691              $module['language']   = $language;
1692              $module['note']       = '';
1693              $module['published']  = 1;
1694  
1695              if (!isset($module['assignment'])) {
1696                  $module['assignment'] = 0;
1697              } else {
1698                  $module['assigned'] = [$home];
1699              }
1700  
1701              if (!isset($module['content'])) {
1702                  $module['content'] = '';
1703              }
1704  
1705              if (!isset($module['access'])) {
1706                  $module['access'] = $access;
1707              }
1708  
1709              if (!isset($module['showtitle'])) {
1710                  $module['showtitle'] = 1;
1711              }
1712  
1713              if (!isset($module['client_id'])) {
1714                  $module['client_id'] = 0;
1715              }
1716  
1717              if (!$model->save($module)) {
1718                  $response            = array();
1719                  $response['success'] = false;
1720                  $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, Text::_($model->getError()));
1721  
1722                  return $response;
1723              }
1724          }
1725  
1726          // Get previously entered categories ids
1727          $menuIdsLevel1 = $this->app->getUserState('sampledata.blog.menuIdsLevel1');
1728  
1729          // Get the login modules there could be more than one
1730          $MVCFactory = $this->app->bootComponent('com_modules')->getMVCFactory();
1731          $modelModules = $MVCFactory->createModel('Modules', 'Administrator', ['ignore_request' => true]);
1732  
1733          $modelModules->setState('filter.module', 'mod_login');
1734          $modelModules->setState('filter.client_id', 1);
1735  
1736          $loginModules = $modelModules->getItems();
1737  
1738          if (!empty($loginModules)) {
1739              $modelModule = $MVCFactory->createModel('Module', 'Administrator', ['ignore_request' => true]);
1740  
1741              foreach ($loginModules as $loginModule) {
1742                  $lm = (array) $loginModule;
1743  
1744                  // Un-assign the module from login view, to avoid 403 error
1745                  $lm['assignment'] = 1;
1746                  $loginId = - (int) $menuIdsLevel1[2];
1747                  $lm['assigned']   = [$loginId];
1748  
1749                  if (!$modelModule->save($lm)) {
1750                      $response            = array();
1751                      $response['success'] = false;
1752                      $response['message'] = Text::sprintf('PLG_SAMPLEDATA_BLOG_STEP_FAILED', 3, Text::_($model->getError()));
1753  
1754                      return $response;
1755                  }
1756              }
1757          }
1758  
1759          $response            = array();
1760          $response['success'] = true;
1761          $response['message'] = Text::_('PLG_SAMPLEDATA_BLOG_STEP3_SUCCESS');
1762  
1763          return $response;
1764      }
1765  
1766      /**
1767       * Final step to show completion of sampledata.
1768       *
1769       * @return  array|void  Will be converted into the JSON response to the module.
1770       *
1771       * @since  4.0.0
1772       */
1773      public function onAjaxSampledataApplyStep4()
1774      {
1775          if ($this->app->input->get('type') != $this->_name) {
1776              return;
1777          }
1778  
1779          $response['success'] = true;
1780          $response['message'] = Text::_('PLG_SAMPLEDATA_BLOG_STEP4_SUCCESS');
1781  
1782          return $response;
1783      }
1784  
1785      /**
1786       * Adds menuitems.
1787       *
1788       * @param   array    $menuItems  Array holding the menuitems arrays.
1789       * @param   integer  $level      Level in the category tree.
1790       *
1791       * @return  array  IDs of the inserted menuitems.
1792       *
1793       * @since  3.8.0
1794       *
1795       * @throws  Exception
1796       */
1797      private function addMenuItems(array $menuItems, $level)
1798      {
1799          $itemIds = array();
1800          $access  = (int) $this->app->get('access', 1);
1801          $user    = $this->app->getIdentity();
1802  
1803          // Detect language to be used.
1804          $language   = Multilanguage::isEnabled() ? $this->app->getLanguage()->getTag() : '*';
1805          $langSuffix = ($language !== '*') ? ' (' . $language . ')' : '';
1806  
1807          foreach ($menuItems as $menuItem) {
1808              // Reset item.id in model state.
1809              $this->menuItemModel->setState('item.id', 0);
1810  
1811              // Set values which are always the same.
1812              $menuItem['id']              = 0;
1813              $menuItem['created_user_id'] = $user->id;
1814              $menuItem['alias']           = ApplicationHelper::stringURLSafe($menuItem['title']);
1815  
1816              // Set unicodeslugs if alias is empty
1817              if (trim(str_replace('-', '', $menuItem['alias']) == '')) {
1818                  $unicode = $this->app->set('unicodeslugs', 1);
1819                  $menuItem['alias'] = ApplicationHelper::stringURLSafe($menuItem['title']);
1820                  $this->app->set('unicodeslugs', $unicode);
1821              }
1822  
1823              // Append language suffix to title.
1824              $menuItem['title'] .= $langSuffix;
1825  
1826              $menuItem['published']       = 1;
1827              $menuItem['language']        = $language;
1828              $menuItem['note']            = '';
1829              $menuItem['img']             = '';
1830              $menuItem['associations']    = array();
1831              $menuItem['client_id']       = 0;
1832              $menuItem['level']           = $level;
1833              $menuItem['home']            = 0;
1834  
1835              // Set browserNav to default if not set
1836              if (!isset($menuItem['browserNav'])) {
1837                  $menuItem['browserNav'] = 0;
1838              }
1839  
1840              // Set access to default if not set
1841              if (!isset($menuItem['access'])) {
1842                  $menuItem['access'] = $access;
1843              }
1844  
1845              // Set type to 'component' if not set
1846              if (!isset($menuItem['type'])) {
1847                  $menuItem['type'] = 'component';
1848              }
1849  
1850              // Set template_style_id to global if not set
1851              if (!isset($menuItem['template_style_id'])) {
1852                  $menuItem['template_style_id'] = 0;
1853              }
1854  
1855              // Set parent_id to root (1) if not set
1856              if (!isset($menuItem['parent_id'])) {
1857                  $menuItem['parent_id'] = 1;
1858              }
1859  
1860              if (!$this->menuItemModel->save($menuItem)) {
1861                  // Try two times with another alias (-1 and -2).
1862                  $menuItem['alias'] .= '-1';
1863  
1864                  if (!$this->menuItemModel->save($menuItem)) {
1865                      $menuItem['alias'] = substr_replace($menuItem['alias'], '2', -1);
1866  
1867                      if (!$this->menuItemModel->save($menuItem)) {
1868                          throw new Exception($menuItem['title'] . ' => ' . $menuItem['alias'] . ' : ' . $this->menuItemModel->getError());
1869                      }
1870                  }
1871              }
1872  
1873              // Get ID from menuitem we just added
1874              $itemIds[] = $this->menuItemModel->getState('item.id');
1875          }
1876  
1877          return $itemIds;
1878      }
1879  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer