Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Symphony 4.x #8

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 54 additions & 14 deletions assets/extension_downloader.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,86 @@
*/

#extension_downloader {
padding: 1em 0;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
order: 2;
position: relative;
padding: 0 3rem;
height: 100%;
}

@media (max-width: 766px){
#extension_downloader {
display: none;
}
}

#extension_downloader h3 {
padding: 0 20px 0 0;
margin: 0 1em 0 0;
display: block;
font-size: 1.4rem;
margin: 0 1.5rem 0 0;
white-space: nowrap;
}

#extension_downloader h3 a {
float: right;
font-size: 0.8em;
transition: color 0.2s;
color: #2f77eb;
font-size: 1.2rem;
padding-left: 1rem;
}

#extension_downloader h3 a:hover {
color: currentColor;
}

#extension_downloader.loading h3 {
background: transparent url(ajax-loader.gif) no-repeat 100% 50%;
padding-right: 3rem;
background: transparent url(ajax-loader.gif) no-repeat 100% 50%;
}

#extension_downloader_results {
padding: 1em 0;
overflow: auto;
position: absolute;
right: 0;
top: 100%;
padding: 0;
border: 1px solid #d3dce2;
border-top: none;
background: #fff;
min-width: 45rem;
max-width: 100vw;
max-height: 45rem;
}

#extension_downloader_results a {
display: block;
display: block;
color: #2f77eb;
font-size: 1.2rem;
line-height: 1.2rem;
padding: 1.5rem 3rem;
border-top: 1px solid #d3dce2;
white-space: nowrap;
}

#extension_downloader_results a:hover {
color: currentColor;
}

#extension_downloader_results a span {
display: inline-block;
display: inline-block;
}
#extension_downloader_results a span.ed_name {
min-width: 18em;
min-width: 18em;
}
#extension_downloader_results a span.ed_version {
min-width: 6em;
min-width: 6em;
}
#extension_downloader_results a span.ed_status,
#extension_downloader_results a span.ed_dev {
font-size: 0.9em;
margin-left:2em;
margin-left: 2em;
}
#extension_downloader_results a span.ed_status {
min-width: 10em;
}
}
66 changes: 33 additions & 33 deletions content/content.download.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class contentExtensionExtension_DownloaderDownload extends JSONPage {
private $alreadyExists;
private $downloadUrl;
private $extensionHandle;

private function getDestinationDirectory() {
return EXTENSIONS . '/' . $this->extensionHandle;
return EXTENSIONS . '/' . $this->extensionHandle;
}

/**
*
* Builds the content view
Expand All @@ -31,14 +31,14 @@ public function view() {
$this->download();
$this->_Result['success'] = true;
} catch (Exception $e) {
$this->_Result['success'] = false;
$this->_Result['success'] = false;
$this->_Result['error'] = $e->getMessage();
}
$this->_Result['handle'] = $this->extensionHandle;
$this->_Result['handle'] = $this->extensionHandle;
$this->_Result['exists'] = $this->alreadyExists;
$this->_Result['force'] = $this->forceOverwrite;
}

private static function handleFromPath($path) {
// github-user/repo-name
// complete github url
Expand All @@ -49,34 +49,34 @@ private static function handleFromPath($path) {
$parts = explode('.', $handle);
return $parts[count($parts)-1];
}

private function parseInput() {
$query = General::sanitize($_REQUEST['q']);

$this->forceOverwrite = (isset($_REQUEST['force']) && General::sanitize($_REQUEST['force']) == 'true');

if (empty($query)) {
throw new Exception(__('Query cannot be empty'));
} else if (strpos($query, 'zipball') !== FALSE || strpos($query, '.zip') !== FALSE) {
} else if (strpos($query, 'zipball') !== false || strpos($query, '.zip') !== false) {
// full url
$this->downloadUrl = $query;
$this->extensionHandle = self::handleFromPath($query);
} else if (strpos($query, '/') !== FALSE) {
} else if (strpos($query, '/') !== false) {
$this->extensionHandle = self::handleFromPath($query);
$this->downloadUrl = "https://github.com/$query/zipball/master";
} else {
// do a search for this handle
$this->searchExtension($query);
}

// check if directory exists
$this->alreadyExists = file_exists($this->getDestinationDirectory());

if (!$this->forceOverwrite && $this->alreadyExists) {
throw new Exception(__('Extension %s already exists', array($this->extensionHandle)));
}
}

private function download() {
// create the Gateway object
$gateway = new Gateway();
Expand All @@ -86,69 +86,69 @@ private function download() {

// get the raw response, ignore errors
$response = @$gateway->exec();

if (!$response) {
throw new Exception(__("Could not read from %s", array($this->downloadUrl)));
}

// write the output
$tmpFile = MANIFEST . '/tmp/' . Lang::createHandle($this->extensionHandle);

if (!General::writeFile($tmpFile, $response)) {
throw new Exception(__("Could not write file."));
}

// open the zip
$zip = new ZipArchive();
if (!$zip->open($tmpFile)) {
General::deleteFile($tmpFile, true);
General::deleteFile($tmpFile, true);
throw new Exception(__("Could not open downloaded file."));
}

// get the directory name
$dirname = $zip->getNameIndex(0);

// extract
$zip->extractTo(EXTENSIONS);
$zip->close();

// delete tarbal
General::deleteFile($tmpFile, false);
General::deleteFile($tmpFile, false);

// prepare
$curDir = EXTENSIONS . '/' . $dirname;
$toDir = $this->getDestinationDirectory();

// delete current version
if (!General::deleteDirectory($toDir)) {
throw new Exception(__('Could not delete %s', array($toDir)));
}

// rename extension folder
if (!@rename($curDir, $toDir)) {
throw new Exception(__('Could not rename %s to %s', array($curDir, $toDir)));
}
}

private function searchExtension($query) {

$xml = SymphonyExtensions::getExtensionAsXML($query);
$xml = current($xml);

$this->extensionHandle = $xml->xpath('/response/extension/@id');

if (empty($this->extensionHandle)) {
throw new Exception(__("Could not find extension handle"));
} else {
$this->extensionHandle = (string)$this->extensionHandle[0];
}

$this->downloadUrl = $xml->xpath("/response/extension/link[@rel='github:zip']/@href");

if (empty($this->downloadUrl)) {
throw new Exception(__("Could not find extension handle"));
} else {
$this->downloadUrl = (string)$this->downloadUrl[0];
}
}
}
}
9 changes: 6 additions & 3 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<extension id="extension_downloader" status="released" xmlns="http://getsymphony.com/schemas/extension/1.0">
<name>Extension Downloader</name>
<description>
An extension that makes it easy to download others extensions directly from the backend.
An extension that makes it easy to download others extensions directly from the backend.
Uses data from http://symphonyextensions.com
</description>
<repo type="github">https://github.com/DeuxHuitHuit/extension_downloader</repo>
Expand All @@ -23,8 +23,11 @@
<!-- None -->
</dependencies>
<releases>
<release version="2.0.0" date="TBA" min="4.0.0" max="4.x.x" php-min="5.6.x" php-max="7.x.x">
- Update for Symphony 4.x
</release>
<release version="1.1.2" date="2016-07-21" min="2.3" max="2.x.x">
- Updated fixed issues #5 and #6, compatibility with php 7
- Updated fixed issues #5 and #6, compatibility with php 7
</release>
<release version="1.1.1" date="2016-03-07" min="2.3" max="2.x.x">
- Updated compatibility info
Expand All @@ -36,4 +39,4 @@
- First release
</release>
</releases>
</extension>
</extension>