Skip to content

Commit eb35d86

Browse files
authored
Merge pull request #7 from cukabeka/master
URL install is here! :)
2 parents 482fe55 + c7d4e18 commit eb35d86

9 files changed

+291
-118
lines changed

README.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# REDAXO ZIP-Upload AddOn und Plugin Install!
2-
Mit diesem AddOn kannst du gezippte AddOns oder Plugins einfach im Backend hochladen und installieren.
2+
Mit diesem AddOn kannst du gezippte AddOns oder Plugins einfach im Backend oder über die URL zu einer ZIP-Datei hochladen.
33

44
![Screenshot](https://raw.githubusercontent.com/FriendsOfREDAXO/zip_install/assets/screen.png)
55

66
Benutzung
77
------------
8-
Das AddOn registriert eine neue Subpage im Installer (neben "Eigene hochladen"). Dort kannst du einfach eine ZIP-Datei eines gültigen AddOns uploaden (wird geprüft). Plugins lassen sich auch installieren. Diese werden automatisch in das richtige AddOn kopiert. (Benennung erfolgt ebenfalls automatisch)
8+
Das AddOn registriert zwei neue Subpages im Installer (neben "Eigene hochladen"). Dort kannst du
9+
10+
* eine ZIP-Datei eines gültigen AddOns uploaden (wird geprüft).
11+
* eine URL zu einer ZIP-Datei eines gültigen AddOns angeben.
12+
13+
Plugins lassen sich auch installieren. Diese werden automatisch in das richtige AddOn kopiert. (Benennung erfolgt ebenfalls automatisch)
914

1015
Installation
1116
------------
@@ -31,7 +36,8 @@ Voraussetzungen
3136

3237
Changelog
3338
------------
34-
Bug #1 gefixed
39+
* Bug #1 gefixed
40+
* Version 1.1 URL install
3541

3642
Known Issues
3743
------------

lang/de_de.lang

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
# URL
2+
zip_install_url_title = Von URL installieren
3+
zip_install_url = URL zu ZIP-Datei
4+
zip_install_url_choose_info = AddOns und Plugins möglich. Sollte der Ordner bereits existieren, wird dieser überschrieben.<br>Bitte ggf. vor dem Upload ein Backup anlegen.<br><br><strong>Hinweis: Der Ordner wird automatisch auf den Package-Name umbenannt, es muss nichts manuell gemacht werden.</strong>
5+
zip_install_url_file_not_loaded = Fehler beim Herunterladen der Datei.
6+
zip_install_url_no_zip = Die heruntergeladene Datei ist keine ZIP-Datei.
7+
zip_install_url_tmp_not_written = Fehler beim Herunterladen der Datei. Temporäre Datei nicht vorhanden.
8+
9+
# Upload
110
zip_install_title = ZIP Upload
211
zip_install_choose_file = Zip-Datei auswählen
312
zip_install_upload_file = Datei hochladen
413
zip_install_choose_info = AddOns und Plugins möglich. Sollte der Ordner bereits existieren, wird dieser überschrieben.<br>Bitte ggf. vor dem Upload ein Backup anlegen.<br><br><strong>Hinweis: Der Ordner wird automatisch auf den Package-Name umbenannt, es muss nichts manuell gemacht werden.</strong>
14+
zip_install_upload_failed = Upload fehlgeschlagen.
15+
16+
# General
517
zip_install_invalid_addon = Das Paket wurde nicht entpackt, da es ungültig war.
618
zip_install_plugin_parent_missing = Das Plugin konnte nicht installiert werden, da das zugehörige AddOn fehlt!
719
zip_install_install_succeed = Das AddOn %%addon%% wurde erfolgreich entpackt. <a href="index.php?page=packages">Zu den AddOns</a>
820
zip_install_plugin_install_succeed = Das Plugin %%plugin%% wurde erfolgreich entpackt. <a href="index.php?page=packages">Zu den AddOns</a>
9-
# Benennung für die Addonrechte, sichtbar innerhalb der REDAXO-Administration unter Benutzer > Rollen > Allgemein
1021

22+
# Benennung für die Addonrechte, sichtbar innerhalb der REDAXO-Administration unter Benutzer > Rollen > Allgemein
1123
perm_general_zip_install[] = Rechte für den Zip-Upload

lang/en_gb.lang

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1+
# URL
2+
zip_install_url_title = Install from URL
3+
zip_install_url = URL of ZIP file
4+
zip_install_url_choose_info = AddOns and PlugIns possible. If the folder already exists it will be overwritten.<br />Please create backups before uploading.<br /><br /><strong>Notice: the folder will automatically be renamed to the package name, no need to alter things manually</strong>
5+
zip_install_url_file_not_loaded = Download failed.
6+
zip_install_url_no_zip = Downloaded file is not a ZIP file.
7+
zip_install_url_tmp_not_written = Download failed. Temporary file not present.
8+
9+
# Upload
110
zip_install_title = ZIP Upload
211
zip_install_choose_file = Specify ZIP file
312
zip_install_upload_file = Upload file
413
zip_install_choose_info = AddOns and PlugIns possible. If the folder already exists it will be overwritten.<br />Please create backups before uploading.<br /><br /><strong>Notice: the folder will automatically be renamed to the package name, no need to alter things manually</strong>
14+
15+
# General
516
zip_install_invalid_addon = The package was not unpacked, because it was invalid.
617
zip_install_plugin_parent_missing = The PlugIn could not be installed, because the corresponding AddOn is missing!
718
zip_install_install_succeed = The AddOn %%addon%% has successfully been unpacked. <a href="index.php?page=packages">AddOns</a>
819
zip_install_plugin_install_succeed = The PlugIn %%plugin%% has successfully been unpacked. <a href="index.php?page=packages">AddOns</a>
9-
# Benennung für die Addonrechte, sichtbar innerhalb der REDAXO-Administration unter Benutzer > Rollen > Allgemein
20+
zip_install_upload_failed = Upload failed.
1021

22+
# Benennung für die Addonrechte, sichtbar innerhalb der REDAXO-Administration unter Benutzer > Rollen > Allgemein
1123
perm_general_zip_install[] = Permissions for ZIP Upload

lang/pt_br.lang

+6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
# URL
2+
3+
4+
# Upload
15
zip_install_title = ZIP Upload
26
zip_install_choose_file = Especificar arquivo ZIP
37
zip_install_upload_file = Fazer o upload do arquivo
48
zip_install_choose_info = AddOns e PlugIns possíveis. Se a pasta já existir, será sobregravada.<br /> Por favor, faça backups antes de realizar o Upload.<br /><br /><strong>Atenção: a pasta será automaticamente renomeada com o nome do package, não há necessidade para fazer uma alteração manual.</strong>
9+
10+
#
511
zip_install_invalid_addon = O package não foi aberto porque era inválido.
612
zip_install_plugin_parent_missing = O PlugIn não foi instalado porque o AddOn correspondente está faltando.
713
zip_install_install_succeed = O AddOn %%addon%% foi corretamente aberto. <a href="index.php?page=packages">AddOns</a>

lib/zip_install.php

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
/**
3+
* zip_install Addon.
4+
*
5+
* @author Friends Of REDAXO
6+
*
7+
* @var rex_addon
8+
*/
9+
10+
use Alchemy\Zippy\Zippy;
11+
12+
13+
class zip_install {
14+
protected static function installZip($tmp_file) {
15+
$error = false;
16+
$isPlugin = false;
17+
$foldername = '';
18+
$packageFile = false;
19+
$zippy = Zippy::load();
20+
21+
try {
22+
$archive = $zippy->open($tmp_file);
23+
24+
$i = 1;
25+
foreach ($archive as $member) {
26+
if(!$member->isDir() && $i == 1)
27+
{
28+
$error = true;
29+
break;
30+
}
31+
else if($member->isDir() && $i == 1)
32+
{
33+
$foldername = $member->getLocation();
34+
}
35+
36+
// search for first package.yml
37+
if(strpos($member->getLocation(), 'package.yml') && !$packageFile)
38+
{
39+
$packageFile = $member->getLocation();
40+
}
41+
42+
$i++;
43+
}
44+
45+
if($packageFile && !$error)
46+
{
47+
// extract into tmp folder
48+
$archive->extract(rex_path::addon('zip_install','tmp'));
49+
50+
// delete garbage
51+
rex_dir::delete(rex_path::addon('zip_install','tmp/__MACOSX'));
52+
rex_dir::delete(rex_path::addon('zip_install','tmp/.git'));
53+
rex_dir::delete(rex_path::addon('zip_install','tmp/.gitignore'));
54+
rex_dir::delete(rex_path::addon('zip_install','tmp/thumbs.db'));
55+
56+
57+
$config = rex_file::getConfig(rex_path::addon('zip_install','tmp/'.$foldername).'package.yml');
58+
if($config['package'])
59+
{
60+
$pluginCheck = explode('/', $config['package']);
61+
62+
if(count($pluginCheck) > 1) {
63+
$isPlugin = true;
64+
// check if parent exists
65+
if(rex_dir::isWritable(rex_path::addon($pluginCheck[0])))
66+
{
67+
// its a plugin, it should have a parent
68+
if(!rex_dir::copy(rex_path::addon('zip_install','tmp/'.$foldername), rex_path::addon($pluginCheck[0], 'plugins/'.$pluginCheck[1])))
69+
{
70+
$error = true;
71+
}
72+
}
73+
else
74+
{
75+
$parentIsMissing = true;
76+
$error = true;
77+
}
78+
79+
}
80+
else
81+
{
82+
// its an addon
83+
// copy over, no matter what!
84+
if(!rex_dir::copy(rex_path::addon('zip_install','tmp/'.$foldername), rex_path::addon($config['package'])))
85+
{
86+
$error = true;
87+
}
88+
}
89+
90+
91+
rex_dir::delete(rex_path::addon('zip_install','tmp/'.$foldername));
92+
}
93+
94+
}
95+
else
96+
{
97+
$error = true;
98+
}
99+
100+
} catch (Exception $e) {}
101+
102+
// delete tmp uploaded zip-file
103+
@unlink($tmp_file);
104+
105+
if (!$error)
106+
{
107+
if($isPlugin)
108+
{
109+
echo rex_view::info(str_replace('%%plugin%%', $config['package'], rex_i18n::rawMsg('zip_install_plugin_install_succeed')));
110+
}
111+
else
112+
{
113+
echo rex_view::info(str_replace('%%addon%%', $config['package'], rex_i18n::rawMsg('zip_install_install_succeed')));
114+
}
115+
}
116+
else
117+
{
118+
echo rex_view::warning(rex_i18n::rawMsg('zip_install_invalid_addon'));
119+
if($parentIsMissing)
120+
{
121+
echo rex_view::warning(rex_i18n::rawMsg('zip_install_plugin_parent_missing'));
122+
}
123+
124+
}
125+
}
126+
127+
}

lib/zip_upload.php

+5-112
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?php
22
/**
3-
* media_manager_autorewrite Addon.
3+
* zip_install Addon.
44
*
55
* @author Friends Of REDAXO
66
*
77
* @var rex_addon
88
*/
99

10-
use Alchemy\Zippy\Zippy;
1110

12-
class zip_upload
11+
class zip_upload extends zip_install
1312
{
1413
public static function validateAndExtractUpload()
1514
{
1615
if (!empty($_FILES['file']))
1716
{
18-
$error = true;
1917
$tmp_path = rex_path::addon('zip_install');
2018
$parentIsMissing = false;
2119

@@ -30,118 +28,13 @@ public static function validateAndExtractUpload()
3028
// check if upload status was successful
3129
if ($results['status'] === true)
3230
{
33-
$error = false;
34-
$isPlugin = false;
35-
$foldername = '';
36-
$packageFile = false;
37-
$zippy = Zippy::load();
38-
39-
try {
40-
$archive = $zippy->open($results['full_path']);
41-
42-
$i = 1;
43-
foreach ($archive as $member) {
44-
if(!$member->isDir() && $i == 1)
45-
{
46-
$error = true;
47-
break;
48-
}
49-
else if($member->isDir() && $i == 1)
50-
{
51-
$foldername = $member->getLocation();
52-
}
53-
54-
// search for first package.yml
55-
if(strpos($member->getLocation(), 'package.yml') && !$packageFile)
56-
{
57-
$packageFile = $member->getLocation();
58-
}
59-
60-
$i++;
61-
}
62-
63-
if($packageFile && !$error)
64-
{
65-
// extract into tmp folder
66-
$archive->extract(rex_path::addon('zip_install','tmp'));
67-
68-
// delete garbage
69-
rex_dir::delete(rex_path::addon('zip_install','tmp/__MACOSX'));
70-
rex_dir::delete(rex_path::addon('zip_install','tmp/.git'));
71-
rex_dir::delete(rex_path::addon('zip_install','tmp/.gitignore'));
72-
rex_dir::delete(rex_path::addon('zip_install','tmp/thumbs.db'));
73-
74-
75-
$config = rex_file::getConfig(rex_path::addon('zip_install','tmp/'.$foldername).'package.yml');
76-
if($config['package'])
77-
{
78-
$pluginCheck = explode('/', $config['package']);
79-
80-
if(count($pluginCheck) > 1) {
81-
$isPlugin = true;
82-
// check if parent exists
83-
if(rex_dir::isWritable(rex_path::addon($pluginCheck[0])))
84-
{
85-
// its a plugin, it should have a parent
86-
if(!rex_dir::copy(rex_path::addon('zip_install','tmp/'.$foldername), rex_path::addon($pluginCheck[0], 'plugins/'.$pluginCheck[1])))
87-
{
88-
$error = true;
89-
}
90-
}
91-
else
92-
{
93-
$parentIsMissing = true;
94-
$error = true;
95-
}
96-
97-
}
98-
else
99-
{
100-
// its an addon
101-
// copy over, no matter what!
102-
if(!rex_dir::copy(rex_path::addon('zip_install','tmp/'.$foldername), rex_path::addon($config['package'])))
103-
{
104-
$error = true;
105-
}
106-
}
107-
108-
109-
rex_dir::delete(rex_path::addon('zip_install','tmp/'.$foldername));
110-
}
111-
112-
}
113-
else
114-
{
115-
$error = true;
116-
}
117-
118-
} catch (Exception $e) {}
119-
120-
// delete tmp uploaded zip-file
121-
@unlink($results['full_path']);
31+
self::installZip($results['full_path']);
12232
}
123-
124-
125-
if (!$error)
33+
else
12634
{
127-
if($isPlugin)
128-
{
129-
echo rex_view::info(str_replace('%%plugin%%', $config['package'], rex_i18n::rawMsg('zip_install_plugin_install_succeed')));
130-
}
131-
else
132-
{
133-
echo rex_view::info(str_replace('%%addon%%', $config['package'], rex_i18n::rawMsg('zip_install_install_succeed')));
134-
}
35+
echo rex_view::warning(rex_i18n::rawMsg('zip_install_upload_failed'));
13536
}
136-
else
137-
{
138-
echo rex_view::warning(rex_i18n::rawMsg('zip_install_invalid_addon'));
139-
if($parentIsMissing)
140-
{
141-
echo rex_view::warning(rex_i18n::rawMsg('zip_install_plugin_parent_missing'));
142-
}
14337

144-
}
14538
}
14639
}
14740

0 commit comments

Comments
 (0)