Repository navigation
Expand file tree
/
Copy pathscript.php
More file actions
137 lines (119 loc) · 4.38 KB
/
Copy pathscript.php
File metadata and controls
137 lines (119 loc) · 4.38 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
135
136
137
<?php
/**
* @package TLWeb.Plugin
* @subpackage Fields.Prettyprotecteddownloads
*
* @copyright Copyright (C) 2026 TLWebdesign. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
\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;
/**
* Script file of the Pretty Protected Downloads fields plugin.
*/
return new class () implements InstallerScriptInterface {
/**
* Joomla 5.3 is the first whose plugins are constructed from their configuration
* alone, without the event dispatcher, which Joomla 7 no longer accepts.
*
* @var string
*/
private string $minimumJoomla = '5.3';
/**
* @var string
*/
private string $minimumPhp = '8.1';
/**
* @param InstallerAdapter $adapter The adapter calling this method.
*
* @return bool
*/
public function install(InstallerAdapter $adapter): bool
{
return true;
}
/**
* @param InstallerAdapter $adapter The adapter calling this method.
*
* @return bool
*/
public function update(InstallerAdapter $adapter): bool
{
return true;
}
/**
* The stored files are left where they are: they are the site's documents, not the
* plugin's, and a folder outside the web root may not even be the plugin's to empty.
*
* @param InstallerAdapter $adapter The adapter calling this method.
*
* @return bool
*/
public function uninstall(InstallerAdapter $adapter): bool
{
echo Text::_('PLG_FIELDS_PRETTYPROTECTEDDOWNLOADS_INSTALLERSCRIPT_UNINSTALL');
return true;
}
/**
* Refuse to install on a PHP or Joomla version the plugin does not run on.
*
* @param string $type install, update, discover_install or uninstall.
* @param InstallerAdapter $adapter The adapter calling this method.
*
* @return bool
*/
public function preflight(string $type, InstallerAdapter $adapter): bool
{
if ($type === 'uninstall') {
return true;
}
if (version_compare(PHP_VERSION, $this->minimumPhp, '<')) {
Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_PHP', $this->minimumPhp), Log::WARNING, 'jerror');
return false;
}
if (version_compare(JVERSION, $this->minimumJoomla, '<')) {
Log::add(Text::sprintf('JLIB_INSTALLER_MINIMUM_JOOMLA', $this->minimumJoomla), Log::WARNING, 'jerror');
return false;
}
return true;
}
/**
* Switch the plugin on after a first install, and say what happened. A discovered
* install never calls install(), so this is done here rather than there.
*
* @param string $type install, update, discover_install or uninstall.
* @param InstallerAdapter $adapter The adapter calling this method.
*
* @return bool
*/
public function postflight(string $type, InstallerAdapter $adapter): bool
{
if ($type === 'install' || $type === 'discover_install') {
// A field type that is installed but switched off simply is not offered, so
// switch it on: the storage settings are the step that needs a decision.
$db = Factory::getContainer()->get(DatabaseInterface::class);
$extension = 'plugin';
$folder = 'fields';
$element = 'prettyprotecteddownloads';
$query = $db->createQuery()
->update($db->quoteName('#__extensions'))
->set($db->quoteName('enabled') . ' = 1')
->where($db->quoteName('type') . ' = :type')
->where($db->quoteName('folder') . ' = :folder')
->where($db->quoteName('element') . ' = :element')
->bind(':type', $extension)
->bind(':folder', $folder)
->bind(':element', $element);
$db->setQuery($query)->execute();
echo Text::_('PLG_FIELDS_PRETTYPROTECTEDDOWNLOADS_INSTALLERSCRIPT_INSTALL');
} elseif ($type === 'update') {
echo Text::_('PLG_FIELDS_PRETTYPROTECTEDDOWNLOADS_INSTALLERSCRIPT_UPDATE');
}
return true;
}
};