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

Ajax theme downloads

This commit is contained in:
SecretR
2013-05-19 17:28:43 +03:00
parent 380e46cd56
commit c4121e5fd7
3 changed files with 35 additions and 43 deletions

View File

@@ -69,35 +69,30 @@ if(e_AJAX_REQUEST)
define('e_IFRAME',true); define('e_IFRAME',true);
} }
// XXX message till we have better way to do the things
if(isset($_GET['action']) && $_GET['action'] == 'download') // Process Theme Download.
{
$string = base64_decode($_GET['src']);
parse_str($string,$p);
$mp = $themec->getMarketplace();
$mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
$status = $mp->download($p['id'], $p['mode'], $p['type']);
if($status)
{
e107::getMessage()->addInfo($status, 'default', true);
}
unset($_GET['src'], $_GET['action']);
$qry = '';
if($_GET) $qry = '?'.http_build_query($_GET, false, '&');
e107::getRedirect()->redirect(e_REQUEST_SELF.$qry);
}
if(e_AJAX_REQUEST) if(e_AJAX_REQUEST)
{ {
switch ($_GET['action']) switch ($_GET['action'])
{ {
case 'download':
$string = base64_decode($_GET['src']);
parse_str($string,$p);
$mp = $themec->getMarketplace();
$mp->generateAuthKey($e107SiteUsername, $e107SiteUserpass);
// 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...<br />"; flush(); // FIXME change the modal default label, default is Loading...
// download and flush
$mp->download($p['id'], $p['mode'], $p['type']);
echo "</pre>"; flush();
exit;
break;
case 'info': case 'info':
$string = base64_decode($_GET['src']); $string = base64_decode($_GET['src']);
parse_str($string,$p); parse_str($string,$p);
echo $themec->renderThemeInfo($p); echo $themec->renderThemeInfo($p);
exit; exit;
break; break;
case 'preview': case 'preview':
// Theme Info Ajax // Theme Info Ajax
$tm = (string) $_GET['id']; $tm = (string) $_GET['id'];

View File

@@ -156,7 +156,7 @@ abstract class e_marketplace_adapter_abstract
* XXX better way to return status (e.g. getError(), getStatus() service call before download) * XXX better way to return status (e.g. getError(), getStatus() service call before download)
* XXX temp is not well cleaned * XXX temp is not well cleaned
* XXX themes/plugins not well tested after unzip (example - Headline 1.0, non-default structure, same applies to most FS net free themes) * XXX themes/plugins not well tested after unzip (example - Headline 1.0, non-default structure, same applies to most FS net free themes)
* * This method is direct outputting the status. If not needed - use buffer
* @param string $remotefile URL * @param string $remotefile URL
* @param string $type plugin or theme * @param string $type plugin or theme
*/ */
@@ -168,35 +168,35 @@ abstract class e_marketplace_adapter_abstract
$remotefile = $this->downloadUrl."?auth=".$this->getAuthKey()."&".$qry; $remotefile = $this->downloadUrl."?auth=".$this->getAuthKey()."&".$qry;
$localfile = md5($remotefile.time()).".zip"; $localfile = md5($remotefile.time()).".zip";
$status = "Downloading..."; echo "Downloading...<br />";
flush();
// FIXME call the service, check status first, then download (if status OK), else retireve the error break and show it // 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); $result = $this->getRemoteFile($remotefile, $localfile);
if(!$result) if(!$result)
{ {
$status = "Download Error."; echo "Download Error.<br />"; flush();
if(filesize(e_TEMP.$localfile)) if(filesize(e_TEMP.$localfile))
{ {
$contents = file_get_contents(e_TEMP.$localfile); $contents = file_get_contents(e_TEMP.$localfile);
$contents = explode('REQ_', $contents); $contents = explode('REQ_', $contents);
$status .= '<br />[#'.trim($contents[1]).'] '.trim($contents[0]); echo '[#'.trim($contents[1]).'] '.trim($contents[0]); flush();
} }
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
return $status; return;
} }
if(!file_exists(e_TEMP.$localfile)) if(!file_exists(e_TEMP.$localfile))
{ {
//ADMIN_FALSE_ICON //ADMIN_FALSE_ICON
$status = "<a href='".$remotefile."'>Download Manually</a>"; echo "Automated download not possible. Please <a href='".$remotefile."'>Download Manually</a>"; flush();
if(E107_DEBUG_LEVEL > 0) if(E107_DEBUG_LEVEL > 0)
{ {
$status .= '<br />local='.$localfile; echo '<br />local='.$localfile; flush();
} }
return $status; return;
} }
/* /*
else else
@@ -223,50 +223,46 @@ abstract class e_marketplace_adapter_abstract
if($dir && is_dir($destpath.$dir)) if($dir && is_dir($destpath.$dir))
{ {
$alert = $tp->toJS(ucfirst($type)." Already Installed".$destpath.$dir); echo "(".ucfirst($type).") Already Installed".$destpath.$dir; flush();
echo "<script>alert('".$alert."')</script>";
echo "Already Installed";
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
return; return;
} }
if($dir == '') if($dir == '')
{ {
echo "<script>alert('Couldn\'t detect the root folder in the zip.')</script>"; echo "Couldn't detect the root folder in the zip."; flush();
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
return; return;
} }
if(is_dir(e_TEMP.$dir)) if(is_dir(e_TEMP.$dir))
{ {
$status = "Unzipping..."; echo "Unzipping...<br />";
if(!rename(e_TEMP.$dir,$destpath.$dir)) if(!rename(e_TEMP.$dir,$destpath.$dir))
{ {
$alert = $tp->toJS("Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"); echo "Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"; flush(); usleep(50000);
echo "<script>alert('".$alert."')</script>";
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
return; return;
} }
$alert = $tp->toJS("Download Complete!"); echo "Download Complete!<br />"; flush();
echo "<script>alert('".$alert."')</script>";
// $dir = basename($unarc[0]['filename']); // $dir = basename($unarc[0]['filename']);
// $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir)); // $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir));
$status = "Done"; // ADMIN_TRUE_ICON; //$status = "Done"; // ADMIN_TRUE_ICON;
return $status; @unlink(e_TEMP.$localfile);
return;
} }
else else
{ {
//ADMIN_FALSE_ICON. //ADMIN_FALSE_ICON.
$status = "<a href='".$remotefile."'>Download Manually</a>"; echo "<a href='".$remotefile."'>Download Manually</a>"; flush(); usleep(50000);
if(E107_DEBUG_LEVEL > 0) if(E107_DEBUG_LEVEL > 0)
{ {
$status .= print_a($unarc, true); echo print_a($unarc, true); flush();
} }
} }
return $status;
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
} }

View File

@@ -1037,7 +1037,8 @@ class themeHandler
$downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&amp;' : '').'&action=download&amp;src='.base64_encode($d);//$url.'&amp;action=download'; $downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&amp;' : '').'&action=download&amp;src='.base64_encode($d);//$url.'&amp;action=download';
$infoUrl = $url.'&amp;action=info'; $infoUrl = $url.'&amp;action=info';
$main_icon = "<a data-src='".$downloadUrl."' href='{$downloadUrl}' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='-e-ajax' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> "; //$main_icon = "<a data-src='".$downloadUrl."' href='{$downloadUrl}' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='-e-ajax' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> ";
$main_icon = "<a data-toggle='modal' data-modal-caption=\"Downloading ".$theme['name']." ".$theme['version']."\" href='{$downloadUrl}' data-cache='false' data-target='#uiModal' title='".$LAN_DOWNLOAD."' ><img class='top' src='".e_IMAGE_ABS."icons/download_32.png' alt='' /></a> ";
$info_icon = "<a data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoUrl."' data-cache='false' data-target='#uiModal' title='".TPVLAN_7."'>".trim(E_32_CAT_ABOUT)."</a>"; $info_icon = "<a data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$infoUrl."' data-cache='false' data-target='#uiModal' title='".TPVLAN_7."'>".trim(E_32_CAT_ABOUT)."</a>";
if($theme['livedemo']) if($theme['livedemo'])