Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 55 additions & 15 deletions plugins/sampledata/blog/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,26 @@ public function onAjaxSampledataApplyStep1()
// Create "blog" category.
$categoryModel = JModelLegacy::getInstance('Category', 'CategoriesModel');
$catIds = array();
$categoryTitle = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_0_TITLE') . $langSuffix;
$categoryTitle = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_0_TITLE');
$alias = JApplicationHelper::stringURLSafe($categoryTitle);

// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $alias) == ''))
{
JFactory::getConfig()->set('unicodeslugs', 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably reset this to whatever value it was beforehand. Right now this causes a side effect of changing the setting for everything that happens after this call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be limited to the method concerned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean limited to the method

Adding
$unicode = JFactory::getConfig()->get('unicodeslugs', 1);

And at the end of the method
JFactory::getConfig()->set('unicodeslugs', $unicode);

And this for each method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be anything happening after that code which could produce any side effects. Only the AJAX response is left to be done by com_ajax.
But yeah, better safe than sorry 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anytime you're making a configuration change if it's supposed to be temporary to work around an issue it should be immediately reverted to the state it was before just to make sure nothing unexpected happens. As this one specifically is the first conditional hit in this step, if the configuration is changed then as is everything calling stringURLSafe afterwards (or anything relying on the unicodeslugs param) is arbitrarily left with unicodeslugs = 1. Granted, the chances of this particular thing causing side effects is low, it is best practice to always reset a temporary change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will modify asap. I had tested though that after this temporary change, the real value is not changed in configuration.php when the script has finished running.

$alias = JApplicationHelper::stringURLSafe($categoryTitle);
}

$category = array(
'title' => $categoryTitle,
'title' => $categoryTitle . $langSuffix,
'parent_id' => 1,
'id' => 0,
'published' => 1,
'access' => $access,
'created_user_id' => $user->id,
'extension' => 'com_content',
'level' => 1,
'alias' => JApplicationHelper::stringURLSafe($categoryTitle),
'alias' => $alias . $langSuffix,
'associations' => array(),
'description' => '',
'language' => $language,
Expand All @@ -150,17 +159,26 @@ public function onAjaxSampledataApplyStep1()
$catIds[] = $categoryModel->getItem()->id;

// Create "help" category.
$categoryTitle = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE') . $langSuffix;
$categoryTitle = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_CATEGORY_1_TITLE');
$alias = JApplicationHelper::stringURLSafe($categoryTitle);

// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $alias) == ''))
{
JFactory::getConfig()->set('unicodeslugs', 1);
$alias = JApplicationHelper::stringURLSafe($categoryTitle);
}

$category = array(
'title' => $categoryTitle,
'title' => $categoryTitle . $langSuffix,
'parent_id' => 1,
'id' => 0,
'published' => 1,
'access' => $access,
'created_user_id' => $user->id,
'extension' => 'com_content',
'level' => 1,
'alias' => JApplicationHelper::stringURLSafe($categoryTitle),
'alias' => $alias . $langSuffix,
'associations' => array(),
'description' => '',
'language' => $language,
Expand Down Expand Up @@ -219,14 +237,24 @@ public function onAjaxSampledataApplyStep1()
foreach ($articles as $i => $article)
{
// Set values from language strings.
$article['title'] = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_TITLE') . $langSuffix;
$title = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_TITLE');
$alias = JApplicationHelper::stringURLSafe($title);
$article['title'] = $title . $langSuffix;
$article['introtext'] = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_INTROTEXT');
$article['fulltext'] = JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_CONTENT_ARTICLE_' . $i . '_FULLTEXT');

// Set values which are always the same.
$article['id'] = 0;
$article['created_user_id'] = $user->id;
$article['alias'] = JApplicationHelper::stringURLSafe($article['title']);

// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $alias) == ''))
{
JFactory::getConfig()->set('unicodeslugs', 1);
$article['alias'] = JApplicationHelper::stringURLSafe($article['title']);
}

$article['language'] = $language;
$article['associations'] = array();
$article['state'] = 1;
Expand Down Expand Up @@ -304,8 +332,10 @@ public function onAjaxSampledataApplyStep2()
'description' => JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MENUS_MENU_' . $i . '_DESCRIPTION'),
);

// Calculate menutype.
$menu['menutype'] = JApplicationHelper::stringURLSafe($menu['title']);
// Calculate menutype. The number of characters allowed is 24.
$type = JHtml::_('string.truncate', $menu['title'], 23, true, false);

$menu['menutype'] = $i . $type;

$menuTable->load();
$menuTable->bind($menu);
Expand Down Expand Up @@ -410,7 +440,7 @@ public function onAjaxSampledataApplyStep2()
'access' => 3,
'params' => array(
'enable_category' => 1,
'catid' => 9,
'catid' => $catids[0],
'menu_text' => 1,
'show_page_heading' => 0,
'secure' => 0,
Expand Down Expand Up @@ -595,6 +625,8 @@ public function onAjaxSampledataApplyStep3()
// Get previously entered Data from UserStates
$menuTypes = $this->app->getUserState('sampledata.blog.menutypes');

$catids = $this->app->getUserState('sampledata.blog.articles.catids');

$modules = array(
array(
'title' => JText::_('PLG_SAMPLEDATA_BLOG_SAMPLEDATA_MODULES_MODULE_0_TITLE'),
Expand Down Expand Up @@ -674,7 +706,7 @@ public function onAjaxSampledataApplyStep3()
'position' => 'position-7',
'module' => 'mod_articles_popular',
'params' => array(
'catid' => ['9'],
'catid' => $catids[0],
'count' => 5,
'show_front' => 1,
'layout' => '_:default',
Expand All @@ -694,7 +726,7 @@ public function onAjaxSampledataApplyStep3()
'show_front' => 'show',
'count' => 6,
'category_filtering_type' => 1,
'catid' => ['9'],
'catid' => $catids[0],
'show_child_category_articles' => 0,
'levels' => 1,
'author_filtering_type' => 1,
Expand Down Expand Up @@ -948,13 +980,21 @@ private function addMenuItems(array $menuItems, $level)
// Reset item.id in model state.
$this->menuItemModel->setState('item.id', 0);

// Append language suffix to title.
$menuItem['title'] .= $langSuffix;

// Set values which are always the same.
$menuItem['id'] = 0;
$menuItem['created_user_id'] = $user->id;
$menuItem['alias'] = JApplicationHelper::stringURLSafe($menuItem['title']);

// Set unicodeslugs if alias is empty
if (trim(str_replace('-', '', $menuItem['alias']) == ''))
{
JFactory::getConfig()->set('unicodeslugs', 1);
$menuItem['alias'] = JApplicationHelper::stringURLSafe($menuItem['title']);
}

// Append language suffix to title.
$menuItem['title'] .= $langSuffix;

$menuItem['published'] = 1;
$menuItem['language'] = $language;
$menuItem['note'] = '';
Expand Down