-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscript.php
127 lines (105 loc) · 3.62 KB
/
script.php
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
<?php
// No direct access
defined( '_JEXEC' ) or die;
/**
*
* @package Joomla.Plugin
* @subpackage System.Radicalform
* @since 3.5+
* @author Progreccor
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
class plgSystemRadicalformInstallerScript
{
function preflight ($type, $parent)
{
if (!(version_compare(PHP_VERSION, '5.6.0') >= 0)) {
JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WRONG_PHP'), 'error');
return false;
}
jimport('joomla.version');
// and now we check Joomla version
$jversion = new JVersion();
if (!$jversion->isCompatible('3.7'))
{
JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WRONG_JOOMLA'), 'error');
return false;
}
}
function uniqidReal($lenght = 23) {
if (function_exists("random_bytes")) {
$bytes = random_bytes(ceil($lenght / 2));
} elseif (function_exists("openssl_random_pseudo_bytes")) {
$bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
} else {
throw new Exception("no cryptographically secure random function available");
}
return substr(bin2hex($bytes), 0, $lenght);
}
function postflight( $type, $parent )
{
$db = JFactory::getDbo();
$query = $db->getQuery( true );
$query->update( '#__extensions' )->set( 'enabled=1' )->where( 'type=' . $db->q( 'plugin' ) )->where( 'element=' . $db->q( 'radicalform' ) );
$db->setQuery( $query )->execute();
try
{
// Get the params for the radicalform plugin
$params = $db->setQuery(
$db->getQuery(true)
->select($db->quoteName('params'))
->from($db->quoteName('#__extensions'))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'))
)->loadResult();
}
catch (Exception $e)
{
echo JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br />';
return false;
}
$params = json_decode($params, true);
// set the directory to safe place
if (!isset($params['uploadstorage']))
{
$params['uploadstorage'] = JPATH_ROOT.'/images/radicalform'.$this->uniqidReal();
mkdir($params['uploadstorage']);
}
// change bytes to megabytes from previous version of plugin
if (isset($params['maxfile']) && ($params['maxfile'] > 10000))
{
// here we think that this number is bytes
$params['maxfile'] = (int) ($params['maxfile'] / 1048576);
}
// if we update from previous versions -
if($type == "update")
{
if (!isset($params['attachfiles']))
{
$params['attachfiles'] = 1;
}
}
if (!isset($params['downloadpath']) || (trim($params['downloadpath']) == "") )
{
$params['downloadpath'] = "rfA".$this->uniqidReal(3);
}
$params = json_encode($params);
$query = $db->getQuery(true)
->update($db->quoteName('#__extensions'))
->set($db->quoteName('params') . ' = ' . $db->quote($params))
->where($db->quoteName('type') . ' = ' . $db->quote('plugin'))
->where($db->quoteName('folder') . ' = ' . $db->quote('system'))
->where($db->quoteName('element') . ' = ' . $db->quote('radicalform'));
try
{
$db->setQuery($query)->execute();
}
catch (Exception $e)
{
echo JText::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $e->getCode(), $e->getMessage()) . '<br />';
return false;
}
JFactory::getApplication()->enqueueMessage(JText::_('PLG_RADICALFORM_WELCOME_MESSAGE'), 'notice');
}
}