-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpkg_script.php
144 lines (121 loc) · 4.57 KB
/
pkg_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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
* @package CjBlog
* @subpackage plg_cjblog
*
* @copyright Copyright (C) 2009 - 2023 BulaSikku Technologies Pvt. Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
class pkg_cjblogInstallerScript
{
private $_minCjLibVersion = '3.2.9';
public function preflight( $type, $parent )
{
if(version_compare(PHP_VERSION, '5.5', '<'))
{
return false;
}
return true;
}
public function postflight($type, $parent)
{
$installCjLib = false;
if(!file_exists(JPATH_ROOT.'/components/com_cjlib/framework.php'))
{
$installCjLib = true;
}
if(!$installCjLib)
{
require_once JPATH_ROOT . '/components/com_cjblog/helpers/constants.php';
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('manifest_cache')
->from($db->quoteName('#__extensions'))
->where('element = ' . $db->q('pkg_cjlib'));
$db->setQuery($query);
$manifest = json_decode($db->loadResult(), true);
$installedCjLibVersion = $manifest['version'];
if(!$installedCjLibVersion || version_compare(CJBLOG_CJLIB_VER, $installedCjLibVersion, '>'))
{
$installCjLib = true;
}
}
if($installCjLib)
{
if(version_compare(PHP_VERSION, '5.6', '<')) {
$url = 'https://www.corejoomla.com/media/autoupdates/files/pkg_cjlib_v2.6.6.zip';
} else {
$url = 'https://github.com/shondalai/cjlib/releases/download/'.$this->_minCjLibVersion.'/cjlib_v'.$this->_minCjLibVersion.'.zip';
}
$package = $this->downloadPackage($url);
$return = $this->installPackage($package);
}
echo '<p>CjBlog Package:</p>
<table class="table table-hover table-striped">
<tr><td>CjBlog Component</td><td>Successfully installed</td></tr>
<tr><td>CjBlog CjBlog Bloggers Module</td><td>Successfully installed</td></tr>
<tr><td>CjBlog CjBlog Categories Module</td><td>Successfully installed</td></tr>
<tr><td>CjBlog CjBlog Archive Module</td><td>Successfully installed</td></tr>
<tr><td>CjBlog CjBlog Apps Plugin</td><td>Successfully installed</td></tr>
<tr><td>CjBlog Content Plugin</td><td>Successfully installed</td></tr>
<tr><td>CjBlog User Plugin</td><td>Successfully installed</td></tr>
</table>
<p><strong style="color: red;">Please install CjLib component if not yet installed. Please enable the plugins from plugin manager.</strong></p>
<p>Thank you for using corejoomla® software. Please add a rating and review at Joomla® Extension Directory.</p>';
}
private function installPackage($package)
{
// Get an installer instance.
$app = JFactory::getApplication();
$installer = JInstaller::getInstance();
if (is_array($package) && isset($package['dir']) && is_dir($package['dir']))
{
$installer->setPath('source', $package['dir']);
if (!$installer->findManifest())
{
// If a manifest isn't found at the source, this may be a Joomla package; check the package directory for the Joomla manifest
if (file_exists($package['dir'] . '/administrator/manifests/files/joomla.xml'))
{
// We have a Joomla package
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
$app->enqueueMessage(
JText::sprintf('COM_INSTALLER_UNABLE_TO_INSTALL_JOOMLA_PACKAGE', JRoute::_('index.php?option=com_joomlaupdate')),
'warning'
);
return false;
}
}
}
// Was the package unpacked?
if (!$package || !$package['type'])
{
JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
$app->enqueueMessage(JText::_('COM_INSTALLER_UNABLE_TO_FIND_INSTALL_PACKAGE'), 'error');
return false;
}
// Install the package.
if (!$installer->install($package['dir']))
{
// There was an error installing the package.
$app->enqueueMessage(JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_' . strtoupper($package['type']))));
return false;
}
return true;
}
private function downloadPackage($url)
{
// Download the package at the URL given.
$p_file = JInstallerHelper::downloadPackage($url);
// Was the package downloaded?
if (!$p_file)
{
throw new Exception(JText::_('COM_INSTALLER_MSG_INSTALL_INVALID_URL'), 403);
}
$config = JFactory::getConfig();
$tmp_dest = $config->get('tmp_path');
// Unpack the downloaded package file.
$package = JInstallerHelper::unpack($tmp_dest . '/' . $p_file, true);
return $package;
}
}