-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.php
More file actions
216 lines (171 loc) · 7.95 KB
/
install.php
File metadata and controls
216 lines (171 loc) · 7.95 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php defined('_JEXEC') or die('Restricted access');
/*
This file is part of "Content Map Joomla Extension".
Author: Open Source solutions http://www.opensourcesolutions.es
You can redistribute and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation,
either version 2 of the License, or (at your option) any later version.
GNU/GPL license gives you the freedom:
* to use this software for both commercial and non-commercial purposes
* to share, copy, distribute and install this software and charge for it if you wish.
Under the following conditions:
* You must attribute the work to the original author
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this software. If not, see http://www.gnu.org/licenses/gpl-2.0.html.
@copyright Copyright (C) 2012 Open Source Solutions S.L.U. All rights reserved.
*/
class com_contentmapInstallerScript
{
protected $component_name;
protected $extension_name;
protected $event;
function install($parent)
{
$this->event = "install";
$this->chain_install($parent);
$this->logo($parent);
}
function uninstall($parent)
{
$this->event = "uninstall";
$this->results = array();
//$this->logo($parent);
}
function update($parent)
{
$this->event = "update";
$this->chain_install($parent);
$this->logo($parent);
$db = JFactory::getDBO();
// Fixes a Joomla bug, wich adds a second repository rather than overwrite the first one if they are different
$query = "DELETE FROM `#__update_sites` WHERE `name` = '" . $this->extension_name . " update site';";
$db->setQuery($query);
$db->query();
// Clear updates cache related to this extension
$query = "DELETE FROM `#__updates` WHERE `name` = '" . $this->extension_name . "';";
$db->setQuery($query);
$db->query();
}
function preflight($type, $parent)
{
$this->component_name = $parent->get("element");
$this->extension_name = substr($this->component_name, 4);
}
function postflight($type, $parent) {
if ($type == 'uninstall') return true;
$installed = true;
foreach ($this->results as $res){
if ($res['result']!="INSTALLED"){
$installed = false;
break;
}
}
if (!$installed){
return true;
}
if (version_compare(JVERSION, '3.0', 'ge')){
//style="width:34%;margin-left:-20%;top:25%;"
$app = JFactory::getApplication();
$html=array();
$html[] ='<div id="contentmap-modal" class="modal hide fade" >';
$html[] ='';
$html[] =' <div class="modal-header">';
$html[] =' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
$html[] =' <h3>ContentMap</h3>';
$html[] =' </div>';
$html[] =' <div class="modal-body">';
$html[] =' <div class="progress progress-success progress-striped">';
$html[] =' <div class="bar" style="width: 0;"></div>';
$html[] =' </div>';
require_once(JPATH_ROOT . '/' . "libraries" . '/' . "contentmap" . '/' . "language" . '/' . "contentmap.inc");
$language = JFactory::getLanguage();
$language->load("com_contentmap.sys", realpath(dirname(__FILE__)));
$langcode = preg_replace("/-.*/", "", $language->get("tag"));
if (isset($GLOBALS["contentmap"]) && isset($GLOBALS["contentmap"]["ha"]) && $GLOBALS["contentmap"]["ha"]) {
}else{
$html[] =' <div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button> ';
$html[] =' <div style="float:left;margin-right:16px;margin-left:10px;">';
$html[] =' <a href="http://www.opensourcesolutions.es/ext/contentmap.html" target="_blank">';
$html[] =' <img src="'.JURI::root().'media/contentmap/images/buy_now.jpg" border="0" alt="Buy now">';
$html[] =' </a>';
$html[] =' </div>';
$html[] =' <p><strong>'.$language->_("COM_CONTENTMAP_PURCHASE").'</strong></p></div> ';
}
$html[] =' </div>';
$html[] =' <div class="modal-footer">';
$html[] =' <button class="btn" data-dismiss="modal" aria-hidden="true">OK</button>';
$html[] =' </div>';
$html[] ='</div>';
$html[] ="<script>jQuery('#contentmap-modal').remove().prependTo('body').modal({keyboard: false});jQuery('#contentmap-modal .bar').animate({ width: '100%' },1000);</script>";
$app->enqueueMessage('Installing ContentMap... '.implode("\n",$html));
}
return true;
}
private function chain_install(&$parent)
{
$manifest = $parent->get("manifest");
if (!isset($manifest->chain->extension)) return;
$result = array();
foreach($manifest->chain->extension as $extension)
{
// We absolutely need to create a new installer instance each cycle,
// otherwise the first failing extension would roll-back previuosly installed extensions.
// Note that the library is the first in install chain and it contains the language files.
$installer = new JInstaller();
$attributes = $extension->attributes();
$item = $parent->getParent()->getPath("source") . '/' . $attributes["directory"] . '/' . $attributes["name"];
$result["type"] = (string)$attributes["type"];
$result["result"] = $installer->install($item) ? "INSTALLED" : "NOT_INSTALLED";
$this->results[(string)$attributes["name"]] = $result;
}
// If Installscript is running, the component is already installed
$result["type"] = "COMPONENT";
$result["result"] = "INSTALLED";
$this->results[$this->component_name] = $result;
// Language files are installed within the library
$result["type"] = "LANGUAGES";
$result["result"] = $this->results["lib_" . $this->extension_name]["result"];
$this->results["lan_" . $this->extension_name] = $result;
//ho commentato <media destination="contentmap" folder="media"> in extras\lib_contentmap\contentmap.xml e lo copio manualmente
//perché se lo lascio fare a joomla, lui cancella la directory di destinazione prima di copiarvi sopra quella nuova e
//questo causa la cancellazione di marker aggiunti dagli utenti.
$src_marker_folder=$parent->getParent()->getPath("source").'/extras/lib_contentmap/media';
$dst_marker_folder=JPATH_ROOT.'/media/contentmap';
JFolder::create($dst_marker_folder);
JFolder::copy($src_marker_folder, $dst_marker_folder,'',true);
}
private function logo(&$parent)
{
JFactory::getLanguage()->load($this->extension_name . ".admin", JPATH_ROOT . "/libraries/" . $this->extension_name);
$manifest = $parent->get("manifest");
//JFactory::getDocument()->addStyleSheet(JURI::base(true) . "/components/" . $this->component_name . "/css/install.css");
// http://davidwalsh.name/create-html-elements-php-htmlelement-class
echo(
'<style type="text/css">' .
'@import url("' . JURI::base(true) . "/components/" . $this->component_name . "/css/install.css" . '");' .
'</style>' .
'<img ' .
'class="install_logo" width="128" height="128" ' .
'src="' . (string)$manifest->authorUrl . 'logo/' . $this->extension_name . "-" . $this->event . '-logo.jpg" ' .
'alt="' . JText::_((string)$manifest->name) . ' Logo" ' .
'/>' .
'<div class="install_container">' .
'<div class="install_row">' .
'<h2 class="install_title">' . JText::_((string)$manifest->name) . '</h2>' .
'</div>');
foreach ($this->results as $name => $extension)
{
echo(
'<div class="install_row">' .
'<div class="install_' . strtolower($extension["type"]) . ' install_icon">' . JText::_(strtoupper($this->extension_name) . "_" . $extension["type"]) . '</div>' .
'<div class="install_' . strtolower($extension["result"]) . ' install_icon">' . JText::_(strtoupper($this->extension_name) . "_" . $extension["result"]) . '</div>' .
'</div>'
);
}
echo('</div>');
}
}