Skip to content

Commit

Permalink
Merge pull request #23 from FriendsOfREDAXO/skerbis-patch-github
Browse files Browse the repository at this point in the history
Github-Download
  • Loading branch information
skerbis authored Jan 1, 2024
2 parents d6d0b88 + b13e518 commit b7bf832
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 101 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Das AddOn registriert zwei neue Subpages im Installer (neben "Eigene hochladen")

* eine ZIP-Datei eines gültigen AddOns uploaden (wird geprüft).
* eine URL zu einer ZIP-Datei eines gültigen AddOns angeben.
* eine URL zu einem GitHub-Repo z.B.: `https://github.com/FriendsOfREDAXO/quick_navigation` (aktueller Haupt-Branch wird geladen)
* ZIP einer GitHub-Branch laden z.B: `https://github.com/FriendsOfREDAXO/quick_navigation/tree/dev`

Plugins lassen sich auch installieren. Diese werden automatisch in das richtige AddOn kopiert. (Benennung erfolgt ebenfalls automatisch)

Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lang/de_de.lang
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# URL
zip_install_url_title = Von URL installieren
zip_install_url = URL zu ZIP-Datei
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>
zip_install_url = URL zu ZIP-Datei oder GitHub-Repo
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> Bei Eingabe einer GitHub-Repo-Adresse wird automatisch das Main-Branch geladen.
zip_install_url_file_not_loaded = Fehler beim Herunterladen der Datei.
zip_install_url_no_zip = Die heruntergeladene Datei ist keine ZIP-Datei.
zip_install_url_tmp_not_written = Fehler beim Herunterladen der Datei. Temporäre Datei nicht vorhanden.
Expand Down
62 changes: 40 additions & 22 deletions lib/zip_url.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
<?php

/**
* zip_install Addon.
*
*
* @author Friends Of REDAXO
* @author stefan-beyer
*
* @var rex_addon
*/


class zip_url extends zip_install
{

protected static function downloadFile($url, $destination)
{
try {
Expand All @@ -26,14 +24,13 @@ protected static function downloadFile($url, $destination)
if (empty($location)) {
return false;
}


# add host if needed
if (strpos($location, '//') === false) {
$parsed = parse_url($url);
$host = $parsed['scheme'] . '://' . $parsed['host'];
if (isset($parsed['port'])) {
$host .= ':'. $parsed['port'];
$host .= ':' . $parsed['port'];
}
$location = $host . $location;
}
Expand All @@ -43,37 +40,58 @@ protected static function downloadFile($url, $destination)
$redircount++;
}

if(!$response->isOk()) {
if (!$response->isOk()) {
return false;
}

// write to file
if ($response->writeBodyTo($destination)) {
return true;
}
} catch(rex_socket_exception $e) {}
} catch (rex_socket_exception $e) {
}
return false;
}


public static function validateAndExtractUpload()
{
$url = rex_post('file_url');
if (!empty($url))
{
$fileUrl = rex_post('file_url');

if (!empty($fileUrl)) {
$tmp_file = rex_path::addon('zip_install', 'tmp/._tmp.zip');

if (!self::downloadFile($url, $tmp_file)) {
echo rex_view::error(rex_i18n::rawMsg('zip_install_url_file_not_loaded'));
}

if (!file_exists($tmp_file)) {
echo rex_view::error(rex_i18n::rawMsg('zip_install_url_tmp_not_written'));
return;
$isGithubRepo = preg_match("/^https:\/\/github\.com\/[\w-]+\/[\w-]+$/", $fileUrl);
$isGithubBranch = preg_match("/^https:\/\/github\.com\/[\w-]+\/[\w-]+\/tree\/[\w\.-]+$/", $fileUrl);
if ($isGithubRepo) {
$mainBranchUrl = $fileUrl . '/archive/main.zip';
$masterBranchUrl = $fileUrl . '/archive/master.zip';

// Versuche zuerst den 'main'-Branch
if (self::downloadFile($mainBranchUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
return;
}

// Versuche dann den 'master'-Branch
if (self::downloadFile($masterBranchUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
return;
}
} elseif ($isGithubBranch) {
// Entfernen Sie '/tree/' und ersetzen Sie es durch '/archive/' + '.zip'
$branchUrl = preg_replace("/\/tree\//", '/archive/', $fileUrl) . '.zip';
if (self::downloadFile($branchUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
return;
}
} else {
// Direkter Download der ZIP-Datei von der angegebenen URL
if (self::downloadFile($fileUrl, $tmp_file) && file_exists($tmp_file)) {
self::installZip($tmp_file);
return;
}
}
self::installZip($tmp_file);

echo rex_view::error(rex_i18n::rawMsg('zip_install_url_file_not_loaded'));
}
}

}
2 changes: 1 addition & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package: zip_install
version: '1.2'
version: '1.4.0'
author: Friends Of REDAXO
supportpage: github.com/FriendsOfREDAXO/zip_install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use function assert;
use function debug_backtrace;
use function sprintf;
use function str_replace;
use function strpos;
use function strrpos;
use function substr;
Expand Down Expand Up @@ -138,7 +139,7 @@ public static function triggerIfCalledFromOutside(string $package, string $link,

// first check that the caller is not from a tests folder, in which case we always let deprecations pass
if (isset($backtrace[1]['file'], $backtrace[0]['file']) && strpos($backtrace[1]['file'], DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR) === false) {
$path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package . DIRECTORY_SEPARATOR;
$path = DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $package) . DIRECTORY_SEPARATOR;

if (strpos($backtrace[0]['file'], $path) === false) {
return;
Expand Down
22 changes: 0 additions & 22 deletions vendor/doctrine/deprecations/phpcs.xml

This file was deleted.

9 changes: 0 additions & 9 deletions vendor/doctrine/deprecations/phpstan.neon

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/doctrine/deprecations/psalm.xml

This file was deleted.

2 changes: 1 addition & 1 deletion vendor/symfony/process/Pipes/WindowsPipes.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function readAndWrite(bool $blocking, bool $close = false): array
if ($w) {
@stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6);
} elseif ($this->fileHandles) {
usleep(Process::TIMEOUT_PRECISION * 1E6);
usleep((int) (Process::TIMEOUT_PRECISION * 1E6));
}
}
foreach ($this->fileHandles as $type => $fileHandle) {
Expand Down

0 comments on commit b7bf832

Please sign in to comment.