Repository navigation
Expand file tree
/
Copy pathscript.php
More file actions
134 lines (107 loc) · 4.13 KB
/
Copy pathscript.php
File metadata and controls
134 lines (107 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* @package Joomla.Site
* @subpackage mod_prettylinks
*
* @copyright Copyright (C) 2022 TLWebdesign. All rights reserved.
* @license GNU General Public License version 3 or later; see LICENSE
*/
\defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Installer\InstallerAdapter;
use Joomla\CMS\Installer\InstallerScriptInterface;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Log\Log;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\File;
use Joomla\Registry\Registry;
return new class () implements InstallerScriptInterface {
private const MINIMUM_JOOMLA = '5.4.0';
private const MINIMUM_PHP = '8.1.0';
public function install(InstallerAdapter $adapter): bool
{
echo Text::_('MOD_PRETTYLINKS_INSTALLERSCRIPT_INSTALL');
return true;
}
public function update(InstallerAdapter $adapter): bool
{
echo Text::_('MOD_PRETTYLINKS_INSTALLERSCRIPT_UPDATE');
return true;
}
public function uninstall(InstallerAdapter $adapter): bool
{
echo Text::_('MOD_PRETTYLINKS_INSTALLERSCRIPT_UNINSTALL');
return true;
}
public function preflight(string $type, InstallerAdapter $adapter): bool
{
if ($type === 'uninstall') {
return true;
}
if (version_compare(PHP_VERSION, self::MINIMUM_PHP, '<')) {
Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_PHP', self::MINIMUM_PHP), Log::WARNING, 'jerror');
return false;
}
if (version_compare(JVERSION, self::MINIMUM_JOOMLA, '<')) {
Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_JOOMLA', self::MINIMUM_JOOMLA), Log::WARNING, 'jerror');
return false;
}
return true;
}
public function postflight(string $type, InstallerAdapter $adapter): bool
{
if ($type === 'update') {
$this->removeLegacyEntryFile();
$this->warnAboutIconOnlyLinks();
}
return true;
}
/**
* 1.0.x used a mod_prettylinks.php entry file; since 1.1.0 the module boots from services/provider.php.
*/
private function removeLegacyEntryFile(): void
{
$file = JPATH_SITE . '/modules/mod_prettylinks/mod_prettylinks.php';
if (is_file($file)) {
File::delete($file);
}
}
/**
* Warn about modules with icon-only links: since 1.1.0 a link needs text for its accessible name,
* so these rows are rendered as an icon without a link until text is added.
*/
private function warnAboutIconOnlyLinks(): void
{
try {
$db = Factory::getContainer()->get(DatabaseInterface::class);
$module = 'mod_prettylinks';
$query = $db->getQuery(true)
->select($db->quoteName(['id', 'title', 'params']))
->from($db->quoteName('#__modules'))
->where($db->quoteName('module') . ' = :module')
->where($db->quoteName('published') . ' != -2')
->bind(':module', $module);
$affected = [];
foreach ($db->setQuery($query)->loadObjectList() as $item) {
$links = (new Registry($item->params))->get('prettylinks');
foreach ((array) $links as $link) {
$link = (object) $link;
if (trim((string) ($link->text ?? '')) === '' && trim((string) ($link->iconclass ?? '')) !== ''
&& trim((string) ($link->url ?? '')) !== '') {
$affected[] = htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . ' (ID ' . (int) $item->id . ')';
break;
}
}
}
if ($affected) {
Factory::getApplication()->enqueueMessage(
Text::sprintf('MOD_PRETTYLINKS_INSTALLERSCRIPT_ICON_ONLY_WARNING', implode(', ', $affected)),
'warning'
);
}
} catch (\Throwable $e) {
// The warning is informational only; never block the update because of it.
Log::add($e->getMessage(), Log::WARNING, 'jerror');
}
}
};