Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] Tours alias language #41161

Merged
merged 163 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
7190150
New Radio/Checkbox option for interactive target type
Geraint2 Jun 16, 2023
aa99cc3
Put advanced options on second tab in step editing
Geraint2 Jun 16, 2023
c35540a
handle required value for tests on text type input fields
hans2103 Jun 19, 2023
fa9672f
handle required value for tests on text type input fields - store dat…
Geraint2 Jun 19, 2023
fad0c9f
Add support for select list interactive type
Geraint2 Jun 21, 2023
0ddc801
Remove redundant use statement
Geraint2 Jun 21, 2023
8b0b6a5
allow text field to support textarea too
Geraint2 Jun 21, 2023
041589f
make the required value field a text area
Geraint2 Jun 21, 2023
e96cb4e
remove Factory::getLanguage
Geraint2 Jun 21, 2023
c5868ce
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jun 21, 2023
8a6acb7
PHP code style
Geraint2 Jun 21, 2023
dec5adf
PHP code style
Geraint2 Jun 21, 2023
2ef9adf
PHP code style
Geraint2 Jun 21, 2023
7f7314f
PHP code style
Geraint2 Jun 21, 2023
cb7200f
PHP code style
Geraint2 Jun 21, 2023
949de72
PHP code style
Geraint2 Jun 21, 2023
72cea45
bad cut and paste of SQL :(
Geraint2 Jun 21, 2023
94481f9
reoder use statements
Geraint2 Jun 21, 2023
4bc1f4e
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jun 29, 2023
8a64b6e
add alias field to tour
Geraint2 Jun 30, 2023
d92b11e
Remove unecessary use Rules
Geraint2 Jun 30, 2023
d6427fd
Add strict extensions filter to list of tours so we can see which tou…
Geraint2 Jun 30, 2023
34a4115
Change required field to radiobox/selector
Jul 2, 2023
589973b
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jul 2, 2023
7b10c7e
Language file typo
Geraint2 Jul 3, 2023
685fac2
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jul 3, 2023
1fe8041
change fieldset name for required values
Geraint2 Jul 3, 2023
cff1124
Merge remote-tracking branch 'origin/tour-4' into tour-4
Geraint2 Jul 3, 2023
4f73668
Merge remote-tracking branch 'origin/tour-4' into tours-identifier
Geraint2 Jul 4, 2023
0cd24e3
handle risk of orphan blur event listeners by making sure tourId is set
Geraint2 Jul 6, 2023
6f54f75
shorten timeout for event handlers
Geraint2 Jul 6, 2023
bea86b4
rename event fired when step is displayed and positioned.
Geraint2 Jul 6, 2023
0f03214
Get Tour by alias
Geraint2 Jul 7, 2023
c3319dd
New language file naming convention with fallback to old files to all…
Geraint2 Jul 10, 2023
f4d369a
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jul 10, 2023
ac72ba5
include tour step element in event detail
Geraint2 Jul 11, 2023
70e258c
Merge branch '5.0-dev' into tour-4
GeraintEdwards Jul 12, 2023
896090e
No need to include reference to es5 javascript 5 at all.
Geraint2 Jul 12, 2023
20c8ac4
Merge remote-tracking branch 'origin/tour-4' into tour-4
Geraint2 Jul 12, 2023
f540a45
Merge remote-tracking branch 'upstream/5.0-dev' into tours-identifier
Geraint2 Jul 12, 2023
3e1e016
editor button for selecting tours
Geraint2 Jul 12, 2023
caf28d1
Merge branch 'tour-4' into tours-identifier
Geraint2 Jul 12, 2023
f002a7e
editor button for selecting tours
Geraint2 Jul 12, 2023
2e1f050
editor button for selecting tours
Geraint2 Jul 12, 2023
14846ff
Implement user tour tracking
Geraint2 Jul 13, 2023
3e897e4
Revert accidental commit
Geraint2 Jul 13, 2023
80d3af1
Remove tagged tours experiment
Geraint2 Jul 13, 2023
3756fd4
SQL correction
Geraint2 Jul 13, 2023
25dc0cd
Extracting language and alias code from wider changes to create PR
Geraint2 Jul 14, 2023
461b690
Make sure the tour alias is unique
Geraint2 Jul 14, 2023
fa63176
remove extended editor button from PR
Geraint2 Jul 14, 2023
11d1fd8
a bit more of a clean up
Geraint2 Jul 14, 2023
0d1d1be
a bit more of a clean up
Geraint2 Jul 14, 2023
7480e41
language file rename
Geraint2 Jul 14, 2023
0a48933
language file rename
Geraint2 Jul 14, 2023
34cad86
phpcs fixes
Geraint2 Jul 14, 2023
332acef
phpcs fixes
Geraint2 Jul 14, 2023
bf61a88
Reverse unnecessary file commit
Geraint2 Jul 15, 2023
8265a11
missing empty line
Geraint2 Jul 15, 2023
ff74e41
phpcs
Geraint2 Jul 15, 2023
dbfcdd3
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Jul 15, 2023
d20253c
Update administrator/components/com_guidedtours/src/Model/TourModel.php
obuisard Jul 15, 2023
ddb763a
Update administrator/modules/mod_guidedtours/tmpl/default.php
GeraintEdwards Jul 17, 2023
e0f9b11
Update administrator/modules/mod_guidedtours/tmpl/default.php
GeraintEdwards Jul 17, 2023
e39b205
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Jul 17, 2023
d707160
Split steps language strings from tour strings
Geraint2 Jul 17, 2023
873de92
Merge remote-tracking branch 'origin/tours-alias-language' into tours…
Geraint2 Jul 17, 2023
46179f7
Split steps language strings from tour strings
Geraint2 Jul 17, 2023
66f6486
Replace double quotes with single quotes
Geraint2 Jul 18, 2023
17ae57e
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Jul 18, 2023
a7fe6dd
Merge remote-tracking branch 'upstream/5.0-dev' into tours-alias-lang…
Geraint2 Aug 8, 2023
3d7e248
Remove "_title" suffix from pre-built joomla tour aliases
Geraint2 Aug 14, 2023
406b7c4
Add missing can fail installer hint (#41184)
richard67 Jul 18, 2023
8d307df
[4.4] Unification of the spelling in plg_quickicon_eos.sys.ini (#41099)
tecpromotion Jul 3, 2023
13e9c78
[5.0] New onAfterInitialiseDocument event (#40512)
Fedik Jul 21, 2023
0dcbd72
[5.0] Application event classes (#40522)
Fedik Jul 21, 2023
690be98
[5.0] b/c plugin - Load class aliases earlier and move es5 assets (#4…
HLeithner Jul 22, 2023
66dd7e1
Fix excluded files from PR #41065 (#41207)
richard67 Jul 22, 2023
514e573
[5.0] Rename Login with Web Authentication to Login with Passkeys (#4…
brianteeman Jul 23, 2023
0d663dd
[5.x] SQL field plugin (#41122)
brianteeman Jul 23, 2023
bacdd8f
[5.x] Redirect filter (#41166)
brianteeman Jul 23, 2023
a143291
[5.0] Replace JPATH_PLATFORM with _JEXEC (#41212)
heelc29 Jul 23, 2023
b69548f
Translation Update (#40731)
joomla-translation-bot Jun 30, 2023
65f6121
Remove "_title" suffix from pre-built joomla tour aliases from instal…
Geraint2 Aug 14, 2023
0834614
Merge remote-tracking branch 'upstream/5.0-dev' into HEAD
Geraint2 Aug 14, 2023
f853a13
[5.0] [GSoC22] Rich Snippets - schema.org implementation (#41151)
shazmasiddiqui Jul 25, 2023
0d8c694
Joomla! 5.0.0 Alpha 3
HLeithner Jul 25, 2023
9759452
[5.0] schemaorg missing namespace (#41237)
brianteeman Jul 25, 2023
2b6a917
[5.0] Move the compatibility plugin from system to behaviour folder (…
HLeithner Aug 1, 2023
989912e
[5.0] schema.org cleanup (#41260)
bembelimen Aug 5, 2023
e870187
Remove "_title" suffix from pre-built joomla tour aliases
Geraint2 Aug 14, 2023
5531bc6
Merge remote-tracking branch 'origin/tours-alias-language' into tours…
Geraint2 Aug 14, 2023
3fda3b3
fussy phpcs
Geraint2 Aug 14, 2023
ec09ab6
fussy phpcs
Geraint2 Aug 14, 2023
48b6454
Default to {alias}.ini and {alias}_steps.ini for tour language file n…
Geraint2 Aug 14, 2023
df25424
Remove duplicate comment
Geraint2 Aug 15, 2023
e528cb9
alpha ordering of language file keys
Geraint2 Aug 15, 2023
8e63e39
Fix update SQL files to populate the alias column correctly and remov…
Geraint2 Aug 15, 2023
044b3f5
Remove accidental comment
Geraint2 Aug 15, 2023
18fa0c1
Remove accidental change and commit
Geraint2 Aug 15, 2023
b9a340c
replicate model change from Joomla 4.3
Geraint2 Aug 15, 2023
0ffa758
Update administrator/language/en-GB/com_guidedtours.ini
GeraintEdwards Aug 15, 2023
d4ca277
Update plugins/system/guidedtours/src/Extension/GuidedTours.php
GeraintEdwards Aug 15, 2023
2dc17e7
Update administrator/language/en-GB/com_guidedtours.ini
GeraintEdwards Aug 15, 2023
b1efd0a
Update administrator/language/en-GB/com_guidedtours_joomla_guidedtour…
GeraintEdwards Aug 15, 2023
bea9a34
Update administrator/language/en-GB/com_guidedtours_joomla_guidedtour…
GeraintEdwards Aug 15, 2023
ad3ee1f
Replace " with '
Geraint2 Aug 16, 2023
e2dba35
Remove unecessary use statement
Geraint2 Aug 16, 2023
83a796d
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 17, 2023
3128502
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 22, 2023
b2d4246
Correct the alias for the "guided tour steps" tour
Aug 22, 2023
738c782
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 22, 2023
a155d4e
Update administrator/components/com_guidedtours/src/Model/StepModel.php
GeraintEdwards Aug 23, 2023
0db42e1
SQL to set initial alias values need to use hyphen not underscore.
Aug 24, 2023
bd9269c
Removed language load for when a step is in creation
obuisard Aug 24, 2023
bb2580e
Update 5.0.0-2023-06-22.sql
obuisard Aug 24, 2023
83d2655
Update StepModel.php
obuisard Aug 24, 2023
722298a
Update administrator/language/en-GB/com_guidedtours.ini
GeraintEdwards Aug 25, 2023
9f9bc8b
Update administrator/language/en-GB/com_guidedtours.ini
GeraintEdwards Aug 25, 2023
f113706
Update administrator/language/en-GB/com_guidedtours.ini
GeraintEdwards Aug 25, 2023
445bbc7
Skip setting of redundant variable - tourLanguage
Aug 25, 2023
cf9afdd
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 25, 2023
3a8ea34
Update com_guidedtours.ini
obuisard Aug 25, 2023
c83fa9f
Update com_guidedtours.ini
obuisard Aug 26, 2023
0828e58
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 26, 2023
912611a
Ensure unique alias is created when duplicating a tour
Aug 26, 2023
55584fb
Merge remote-tracking branch 'origin/tours-alias-language' into tours…
Aug 26, 2023
9cddb59
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 26, 2023
403e729
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 30, 2023
c1f88ef
Rename language files to follow pattern com_guidedtours.unique_identi…
Geraint2 Aug 30, 2023
0b18938
Rename update file
Geraint2 Aug 30, 2023
dd89369
Missing renamed language files
Geraint2 Aug 30, 2023
e549185
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Aug 31, 2023
8250d40
Merge branch '5.0-dev' into tours-alias-language
richard67 Sep 1, 2023
92a1309
Renamed alias column in tours table to uid
Geraint2 Sep 2, 2023
b71b28a
Merge remote-tracking branch 'origin/tours-alias-language' into tours…
Geraint2 Sep 2, 2023
d5e29fa
Merge remote-tracking branch 'upstream/5.0-dev' into tours-alias-lang…
Geraint2 Sep 2, 2023
343496d
Missed a reference to tourAlias => tourUid
Geraint2 Sep 2, 2023
d6a9907
no need for @ operator when calling urldecode as it won't throw an ex…
Geraint2 Sep 2, 2023
6b25133
Fix closure call in array_walk for setting initial values for blank u…
Geraint2 Sep 2, 2023
ee96de6
Fix closure call in array_walk for setting initial values for blank u…
Geraint2 Sep 2, 2023
29981d3
Merge branch '5.0-dev' into tours-alias-language
obuisard Sep 2, 2023
567b8a3
Update StepModel.php
obuisard Sep 2, 2023
2d69f54
Update GuidedTours.php
obuisard Sep 2, 2023
bc22210
Merge branch '5.0-dev' into tours-alias-language
obuisard Sep 2, 2023
8ae7387
Update extensions.sql
obuisard Sep 2, 2023
5f66dbf
Update extensions.sql
obuisard Sep 2, 2023
b88b816
Update TourTable.php
obuisard Sep 2, 2023
edbcea9
Update GuidedtoursHelper.php
obuisard Sep 2, 2023
82a3e2c
Update edit.php
obuisard Sep 2, 2023
d4d425b
Update administrator/components/com_admin/script.php
obuisard Sep 2, 2023
f58ecbd
Update script.php
obuisard Sep 2, 2023
f75e5bb
Update administrator/components/com_admin/script.php
obuisard Sep 2, 2023
015854c
Merge branch '5.0-dev' into tours-alias-language
GeraintEdwards Sep 2, 2023
263d0ef
Merge branch '5.0-dev' into tours-alias-language
obuisard Sep 2, 2023
9e9000b
Merge branch '5.0-dev' into tours-alias-language
obuisard Sep 2, 2023
5ba7f45
Update GuidedTours.php
obuisard Sep 3, 2023
5964f64
Update GuidedtoursHelper.php
obuisard Sep 3, 2023
e24c947
Update TourTable.php
obuisard Sep 3, 2023
e1b689e
Update script.php
obuisard Sep 3, 2023
94a912c
Update script.php
obuisard Sep 3, 2023
2ae15a6
Update script.php
obuisard Sep 3, 2023
2b7a414
Merge branch '5.0-dev' into tours-alias-language
obuisard Sep 3, 2023
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
66 changes: 66 additions & 0 deletions administrator/components/com_admin/script.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Extension\ExtensionHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\File;
Expand All @@ -18,6 +19,7 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Uri\Uri;
use Joomla\Database\ParameterType;

// phpcs:disable PSR1.Files.SideEffects
Expand Down Expand Up @@ -2252,6 +2254,8 @@ public function postflight($action, $installer)
return false;
}

$this->setGuidedToursUid();

return true;
}

Expand Down Expand Up @@ -2359,6 +2363,68 @@ private function migrateTinymceConfiguration(): bool
return true;
}

/**
* setup Guided Tours Unique Identifiers
*
* @return boolean True on success
*
* @since __DEPLOY_VERSION__
*/
private function setGuidedToursUid()
{
/** @var \Joomla\Component\Cache\Administrator\Model\CacheModel $model */
$model = Factory::getApplication()->bootComponent('com_guidedtours')->getMVCFactory()
->createModel('Tours', 'Administrator', ['ignore_request' => true]);

$items = $model->getItems();

foreach ($items as $item) {
// Set uid for tours where it is empty
if (empty($item->uid)) {
$tourItem = $model->getTable('Tour');
$tourItem->load($item->id);

// Tour follows Joomla naming convention
if (str_starts_with($tourItem->title, 'COM_GUIDEDTOURS_TOUR_') && str_ends_with($tourItem->title, '_TITLE')) {
$uidTitle = 'joomla_' . str_replace('COM_GUIDEDTOURS_TOUR_', '', $tourItem->title);

// Remove the last _TITLE part
$pos = strrpos($uidTitle, '_TITLE');
if ($pos !== false) {
$uidTitle = substr($uidTitle, 0, $pos);
}
} elseif (preg_match('#COM_(\w+)_TOUR_#', $tourItem->title) && str_ends_with($tourItem->title, '_TITLE')) {
// Tour follows component naming pattern
$uidTitle = preg_replace('#COM_(\w+)_TOUR_#', '$1.', $tourItem->title);

// Remove the last _TITLE part
$pos = strrpos($uidTitle, "_TITLE");
if ($pos !== false) {
$uidTitle = substr($uidTitle, 0, $pos);
}
} else {
$uri = Uri::getInstance();
$host = $uri->toString(['host']);
$host = ApplicationHelper::stringURLSafe($host, $tourItem->language);
$uidTitle = $host . ' ' . str_replace('COM_GUIDEDTOURS_TOUR_', '', $tourItem->title);
// Remove the last _TITLE part
if (str_ends_with($uidTitle, '_TITLE')) {
$pos = strrpos($uidTitle, '_TITLE');
$uidTitle = substr($uidTitle, 0, $pos);
}
}
// ApplicationHelper::stringURLSafe will replace a period (.) separator so we split the construction into multiple parts
$uidTitleParts = explode('.', $uidTitle);
array_walk($uidTitleParts, function (&$value, $key, $tourLanguage) {
$value = ApplicationHelper::stringURLSafe($value, $tourLanguage);
}, $tourItem->language);
$tourItem->uid = implode('.', $uidTitleParts);

$tourItem->store();
}
}
}

/**
* Renames or removes incorrectly cased files.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE `#__guidedtours` ADD COLUMN `uid` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL AFTER `title`/** CAN FAIL **/;
ALTER TABLE `#__guidedtours` ADD INDEX `idx_uid` (`uid`(191)) /** CAN FAIL **/;

UPDATE `#__guidedtours` SET `uid` = 'joomla-guidedtours' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_GUIDEDTOURS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-guidedtoursteps' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_GUIDEDTOURSTEPS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-articles' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_ARTICLES_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-categories' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_CATEGORIES_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-menus' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_MENUS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-tags' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_TAGS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-banners' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_BANNERS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-contacts' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_CONTACTS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-newsfeeds' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_NEWSFEEDS_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-smartsearch' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_SMARTSEARCH_TITLE';
UPDATE `#__guidedtours` SET `uid` = 'joomla-users' WHERE `title` = 'COM_GUIDEDTOURS_TOUR_USERS_TITLE';
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE "#__guidedtours" ADD COLUMN "uid" varchar(255) DEFAULT '' NOT NULL /** CAN FAIL **/;
CREATE INDEX "#__guidedtours_idx_uid" ON "#__guidedtours" ("uid") /** CAN FAIL **/;

UPDATE "#__guidedtours" SET "uid" = 'joomla-guidedtours' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_GUIDEDTOURS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-guidedtoursteps' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_GUIDEDTOURSTEPS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-articles' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_ARTICLES_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-categories' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_CATEGORIES_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-menus' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_MENUS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-tags' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_TAGS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-banners' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_BANNERS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-contacts' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_CONTACTS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-newsfeeds' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_NEWSFEEDS_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-smartsearch' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_SMARTSEARCH_TITLE';
UPDATE "#__guidedtours" SET "uid" = 'joomla-users' WHERE "title" = 'COM_GUIDEDTOURS_TOUR_USERS_TITLE';
9 changes: 9 additions & 0 deletions administrator/components/com_guidedtours/forms/tour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
readonly="true"
/>

<field
name="uid"
type="text"
label="COM_GUIDEDTOURS_TOUR_UID_LABEL"
description="COM_GUIDEDTOURS_TOUR_UID_DESC"
hint="COM_GUIDEDTOURS_TOUR_UID_HINT"
required="false"
/>

<field
name="description"
type="editor"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

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

namespace Joomla\Component\Guidedtours\Administrator\Helper;

use Joomla\CMS\Factory;

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

/**
* Guidedtours component helper.
*
* @since __DEPLOY_VERSION__
*/
class GuidedtoursHelper
{
/**
* Load the translation files for an Guided Tour
*
* @param string $uid Guided Tour Unique Identifier
* @param boolean $steps Should tour steps language file be loaded
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public static function loadTranslationFiles($uid, bool $steps = false)
{
static $cache = [];
$uid = strtolower($uid);

if (isset($cache[$uid])) {
return;
}

$lang = Factory::getLanguage();

// The uid has an extension separator so we need to check the extension language files
if (strpos($uid, '.') > 0) {
list($extension, $tourid) = explode('.', $uid, 2);

$source = '';

switch (substr($extension, 0, 3)) {
case 'com':
$source = JPATH_ADMINISTRATOR . '/components/' . $extension;
break;

case 'lib':
$source = JPATH_LIBRARIES . '/' . substr($extension, 4);
break;

case 'mod':
$source = JPATH_SITE . '/modules/' . $extension;
break;

case 'plg':
$parts = explode('_', $extension, 3);

if (\count($parts) > 2) {
$source = JPATH_PLUGINS . '/' . $parts[1] . '/' . $parts[2];
}
break;

case 'pkg':
$source = JPATH_SITE;
break;

case 'tpl':
$source = JPATH_BASE . '/templates/' . substr($extension, 4);
break;

default:
$source = JPATH_ADMINISTRATOR . '/components/com_' . $extension;
break;
}

$lang->load($extension . '.' . str_replace('-', '_', $tourid), JPATH_ADMINISTRATOR)
|| $lang->load($extension . '.' . str_replace('-', '_', $tourid), $source);
if ($steps) {
$lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', JPATH_ADMINISTRATOR)
|| $lang->load($extension . '.' . str_replace('-', '_', $tourid) . '_steps', JPATH_ADMINISTRATOR);
}
} else {
$lang->load('guidedtours.' . str_replace('-', '_', $uid), JPATH_ADMINISTRATOR);
if ($steps) {
$lang->load('guidedtours.' . str_replace('-', '_', $uid) . '_steps', JPATH_ADMINISTRATOR);
}
}

$cache[$uid] = true;

return;
}
}
26 changes: 15 additions & 11 deletions administrator/components/com_guidedtours/src/Model/StepModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Object\CMSObject;
use Joomla\CMS\Table\Table;
use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -237,25 +238,28 @@ protected function loadFormData()
*/
public function getItem($pk = null)
{
Factory::getLanguage()->load('com_guidedtours.sys', JPATH_ADMINISTRATOR);

if ($result = parent::getItem($pk)) {
$app = Factory::getApplication();

/** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */
$tourModel = $app->bootComponent('com_guidedtours')
->getMVCFactory()->createModel('Tour', 'Administrator', ['ignore_request' => true]);

if (!empty($result->id)) {
// Editing an existing step
$tour = $tourModel->getItem($result->tour_id);

GuidedtoursHelper::loadTranslationFiles($tour->uid, true);

$result->title_translation = Text::_($result->title);
$result->description_translation = Text::_($result->description);
} else {
$app = Factory::getApplication();
// Creating a new step so we get the tour id from the session data
$tourId = $app->getUserState('com_guidedtours.tour_id');

/** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */
$tourModel = $app->bootComponent('com_guidedtours')
->getMVCFactory()->createModel('Tour', 'Administrator', ['ignore_request' => true]);

$tour = $tourModel->getItem($tourId);
$tourLanguage = !empty($tour->language) ? $tour->language : '*';
$tour = $tourModel->getItem($tourId);

// Sets step language to parent tour language
$result->language = $tourLanguage;
$result->language = !empty($tour->language) ? $tour->language : '*';

// Set the step's tour id
$result->tour_id = $tourId;
Expand Down
19 changes: 17 additions & 2 deletions administrator/components/com_guidedtours/src/Model/StepsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Component\Guidedtours\Administrator\Helper\GuidedtoursHelper;
use Joomla\Database\DatabaseQuery;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;
Expand Down Expand Up @@ -228,9 +229,23 @@ public function getItems()
{
$items = parent::getItems();

Factory::getLanguage()->load('com_guidedtours.sys', JPATH_ADMINISTRATOR);

$tourLanguageLoaded = false;
foreach ($items as $item) {
if (!$tourLanguageLoaded) {
$app = Factory::getApplication();
$tourId = $item->tour_id;

/** @var \Joomla\Component\Guidedtours\Administrator\Model\TourModel $tourModel */
$tourModel = $app->bootComponent('com_guidedtours')
->getMVCFactory()->createModel('Tour', 'Administrator', [ 'ignore_request' => true ]);

$tour = $tourModel->getItem($tourId);

GuidedtoursHelper::loadTranslationFiles($tour->uid, true);

$tourLanguageLoaded = true;
}

$item->title = Text::_($item->title);
$item->description = Text::_($item->description);
}
Expand Down
Loading