1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-08 23:56:58 +02:00

One-click plugin download and install routine reinstated.

This commit is contained in:
Cameron
2015-02-03 21:58:26 -08:00
parent 486cd1d10f
commit 29c9b3b0b6
3 changed files with 125 additions and 26 deletions

View File

@@ -32,6 +32,15 @@ $plugin = new e107plugin;
$pman = new pluginManager;
define("e_PAGETITLE",ADLAN_98." - ".$pman->pagetitle);
if(e_AJAX_REQUEST) // Ajax
{
print_a($_POST);
print_a($_GET);
exit;
}
if(e_AJAX_REQUEST && isset($_GET['action'])) // Ajax
{
if($_GET['action'] == 'download')
@@ -39,7 +48,7 @@ if(e_AJAX_REQUEST && isset($_GET['action'])) // Ajax
$string = base64_decode($_GET['src']);
parse_str($string, $p);
print_a($p);
// print_a($p);
// $mp = $pman->getMarketplace();
// $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
@@ -49,7 +58,7 @@ if(e_AJAX_REQUEST && isset($_GET['action'])) // Ajax
// Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers)
echo "<pre>Connecting...\n"; flush(); // FIXME change the modal default label, default is Loading...
// download and flush
$mp->download($p['plugin_id'], $p['plugin_mode'], 'plugin');
// $mp->download($p['plugin_id'], $p['plugin_mode'], 'plugin');
echo "</pre>"; flush();
}
@@ -307,6 +316,13 @@ class pluginManager{
$this->fieldpref[] = $key;
}
}
if($this->action == 'download')
{
$this->pluginDownload();
return;
}
if($this->action == 'avail' || $this->action == 'installed') // Plugin Check is done during upgrade_routine.
@@ -579,12 +595,16 @@ class pluginManager{
$d = http_build_query($data,false,'&');
//$url = e_SELF."?src=".base64_encode($d);
$url = e_SELF.'?action=download&amp;src='.base64_encode($d);//$url.'&amp;action=download';
// $url = e_SELF.'?action=download&amp;src='.base64_encode($d);//$url.'&amp;action=download';
$id = 'plug_'.$data['plugin_id'];
//<button type='button' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='btn btn-primary e-ajax middle' value='Download and Install' data-src='".$url."' ><span>Download and Install</span></button>
$url = e_SELF.'?mode=download&amp;src='.base64_encode($d);
$dicon = '<a class="e-modal btn btn-default" href="'.$url.'" rel="external" data-loading="'.e_IMAGE.'/generic/loading_32.gif" data-cache="false" data-modal-caption="Downloading and Installing '.$data['plugin_name']." ".$data['plugin_version'].'" target="_blank" ><img class="top" src="'.e_IMAGE_ABS.'icons/download_32.png" alt="" /></a>';
// Temporary Pop-up version.
$dicon = '<a class="e-modal" href="'.$data['plugin_url'].'" rel="external" data-modal-caption="'.$data['plugin_name']." ".$data['plugin_version'].'" target="_blank" ><img class="top" src="'.e_IMAGE_ABS.'icons/download_32.png" alt="" /></a>';
// $dicon = '<a class="e-modal" href="'.$data['plugin_url'].'" rel="external" data-modal-caption="'.$data['plugin_name']." ".$data['plugin_version'].'" target="_blank" ><img class="top" src="'.e_IMAGE_ABS.'icons/download_32.png" alt="" /></a>';
// $dicon = "<a data-toggle='modal' data-modal-caption=\"Downloading ".$data['plugin_name']." ".$data['plugin_version']."\" href='{$url}' data-cache='false' data-target='#uiModal' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> ";
@@ -592,6 +612,60 @@ class pluginManager{
{$dicon}
</div>";
}
private function pluginDownload()
{
define('e_IFRAME', true);
$frm = e107::getForm();
$mes = e107::getMessage();
// print_a($_GET);
$string = base64_decode($_GET['src']);
parse_str($string, $data);
$mp = $this->getMarketplace();
// $mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
// print_a($data);
// Server flush useless. It's ajax ready state 4, we can't flush (sadly) before that (at least not for all browsers)
$mes->addSuccess("Connecting...");
if($mp->download($data['plugin_id'], $data['plugin_mode'], 'plugin'))
{
$text = e107::getPlugin()->install($data['plugin_folder']);
$mes->addInfo($text);
echo $mes->render('default', 'success');
}
else
{
echo $mes->addError('Unable to continue')->render('default', 'error');
}
echo $mes->render('default', 'debug');
return;
$text ="<iframe src='".$data['plugin_url']."' style='width:99%; height:500px; border:0px'>Loading...</iframe>";
// print_a($data);
$text .= $frm->open('upload-url-form','post');
$text .= "<div class='form-inline' style='padding:20px'>";
$text .= "<input type='text' name='upload_url' size='255' style='width:70%;height:50px;text-align:center' placeholder='eg. http://website.com/some-plugin.zip' />";
$text .= $frm->admin_button('upload_remote_url',1,'create','Install');
$text .= "</div>";
$text .= "</div>\n\n";
$text .= $frm->close();
echo $text;
}
// FIXME - move it to plugin handler, similar to install_plugin() routine

View File

@@ -226,7 +226,7 @@ abstract class e_marketplace_adapter_abstract
* e107.org download URL
* @var string
*/
protected $downloadUrl = 'http://e107.org/request';
protected $downloadUrl = 'http://e107.org/request/';
/**
* e107.org service URL [adapter implementation required]
@@ -240,6 +240,7 @@ abstract class e_marketplace_adapter_abstract
*/
public $requestMethod = null;
/**
* @var eAuth
*/
@@ -311,40 +312,47 @@ abstract class e_marketplace_adapter_abstract
public function download($id, $mode, $type)
{
$tp = e107::getParser();
$mes = e107::getMessage();
$id = intval($id);
$qry = 'id='.$id.'&type='.$type.'&mode='.$mode;
$remotefile = $this->downloadUrl."?auth=".$this->getAuthKey()."&".$qry;
$localfile = md5($remotefile.time()).".zip";
echo "Downloading...<br />";
flush();
$mes->addSuccess("Downloading...");
// FIXME call the service, check status first, then download (if status OK), else retireve the error break and show it
$result = $this->getRemoteFile($remotefile, $localfile);
if(!$result)
{
echo "Download Error.<br />"; flush();
$mes->addError("Download Error"); // flush();
if(filesize(e_TEMP.$localfile))
{
$contents = file_get_contents(e_TEMP.$localfile);
$contents = explode('REQ_', $contents);
echo '[#'.trim($contents[1]).'] '.trim($contents[0]); flush();
$mes->addError('[#'.trim($contents[1]).'] '.trim($contents[0])); flush();
}
@unlink(e_TEMP.$localfile);
return;
return false;
}
if(!file_exists(e_TEMP.$localfile))
{
//ADMIN_FALSE_ICON
echo "Automated download not possible. Please <a href='".$remotefile."'>Download Manually</a>"; flush();
$mes->addError( "Automated download not possible. Please <a href='".$remotefile."'>Download Manually</a>");
if(E107_DEBUG_LEVEL > 0)
{
echo '<br />local='.$localfile; flush();
$mes->addDebug('local='.$localfile); // ; flush();
}
return;
return false;
}
else
{
// $mes->addSuccess("Download Successful");
}
/*
else
@@ -371,49 +379,65 @@ abstract class e_marketplace_adapter_abstract
if($dir && is_dir($destpath.$dir))
{
echo "(".ucfirst($type).") Already Downloaded - ".basename($destpath).'/'.$dir; flush();
$mes->addError("(".ucfirst($type).") Already Downloaded - ".basename($destpath).'/'.$dir); flush();
@unlink(e_TEMP.$localfile);
return;
@unlink(e_TEMP.$dir );
return false;
}
if($dir == '')
{
echo "Couldn't detect the root folder in the zip."; flush();
$mes->addError("Couldn't detect the root folder in the zip."); // flush();
@unlink(e_TEMP.$localfile);
return;
return false;
}
if(is_dir(e_TEMP.$dir))
{
echo "Unzipping...<br />";
$this->success[] = "Unzipping...";
if(!rename(e_TEMP.$dir,$destpath.$dir))
{
echo "Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"; flush(); usleep(50000);
$mes->addError("Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"); // flush(); usleep(50000);
@unlink(e_TEMP.$localfile);
return;
return false;
}
echo "Download Complete!<br />"; flush();
$mes->addSuccess("Download Complete!"); flush();
// $dir = basename($unarc[0]['filename']);
// $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir));
//$status = "Done"; // ADMIN_TRUE_ICON;
@unlink(e_TEMP.$localfile);
return;
return true;
}
else
{
//ADMIN_FALSE_ICON.
echo "<a href='".$remotefile."'>Download Manually</a>"; flush(); usleep(50000);
$mes->addSuccess( "<a href='".$remotefile."'>Download Manually</a>"); // flush(); usleep(50000);
if(E107_DEBUG_LEVEL > 0)
{
echo print_a($unarc, true); flush();
$mes->addDebug(print_a($unarc, true)); flush();
}
}
@unlink(e_TEMP.$localfile);
return false;
}
public function getErrors()
{
return $this->errors;
}
public function getSuccess()
{
return $this->success;
}
// Grab a remote file and save it in the /temp directory. requires CURL
function getRemoteFile($remote_url, $local_file, $type='temp')
{

View File

@@ -946,7 +946,8 @@ class e_file
$text .= "\\n target=".$target;
if(E107_DEBUG_LEVEL > 0)
{
echo "<script>alert('".$text."')</script>";
e107::getMessage()->addDebug($text);
// echo "<script>alert('".$text."')</script>";
}
return $target;