From c4121e5fd770d4804f8f46db9d1203c2c3ac3a0a Mon Sep 17 00:00:00 2001 From: SecretR Date: Sun, 19 May 2013 17:28:43 +0300 Subject: [PATCH] Ajax theme downloads --- e107_admin/theme.php | 33 +++++++++++--------------- e107_handlers/e_marketplace.php | 42 +++++++++++++++------------------ e107_handlers/theme_handler.php | 3 ++- 3 files changed, 35 insertions(+), 43 deletions(-) diff --git a/e107_admin/theme.php b/e107_admin/theme.php index 62092f4fe..348155a51 100644 --- a/e107_admin/theme.php +++ b/e107_admin/theme.php @@ -69,35 +69,30 @@ if(e_AJAX_REQUEST) 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) { 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 "
Connecting...
"; flush(); // FIXME change the modal default label, default is Loading... + // download and flush + $mp->download($p['id'], $p['mode'], $p['type']); + echo "
"; flush(); + exit; + break; + case 'info': $string = base64_decode($_GET['src']); parse_str($string,$p); echo $themec->renderThemeInfo($p); exit; break; + case 'preview': // Theme Info Ajax $tm = (string) $_GET['id']; diff --git a/e107_handlers/e_marketplace.php b/e107_handlers/e_marketplace.php index 1b7799141..54fe2f2e2 100644 --- a/e107_handlers/e_marketplace.php +++ b/e107_handlers/e_marketplace.php @@ -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 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) - * + * This method is direct outputting the status. If not needed - use buffer * @param string $remotefile URL * @param string $type plugin or theme */ @@ -168,35 +168,35 @@ abstract class e_marketplace_adapter_abstract $remotefile = $this->downloadUrl."?auth=".$this->getAuthKey()."&".$qry; $localfile = md5($remotefile.time()).".zip"; - $status = "Downloading..."; - + echo "Downloading...
"; + flush(); // 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) { - $status = "Download Error."; + echo "Download Error.
"; flush(); if(filesize(e_TEMP.$localfile)) { $contents = file_get_contents(e_TEMP.$localfile); $contents = explode('REQ_', $contents); - $status .= '
[#'.trim($contents[1]).'] '.trim($contents[0]); + echo '[#'.trim($contents[1]).'] '.trim($contents[0]); flush(); } @unlink(e_TEMP.$localfile); - return $status; + return; } if(!file_exists(e_TEMP.$localfile)) { //ADMIN_FALSE_ICON - $status = "Download Manually"; + echo "Automated download not possible. Please Download Manually"; flush(); if(E107_DEBUG_LEVEL > 0) { - $status .= '
local='.$localfile; + echo '
local='.$localfile; flush(); } - return $status; + return; } /* else @@ -223,50 +223,46 @@ abstract class e_marketplace_adapter_abstract if($dir && is_dir($destpath.$dir)) { - $alert = $tp->toJS(ucfirst($type)." Already Installed".$destpath.$dir); - echo ""; - echo "Already Installed"; + echo "(".ucfirst($type).") Already Installed".$destpath.$dir; flush(); @unlink(e_TEMP.$localfile); return; } if($dir == '') { - echo ""; + echo "Couldn't detect the root folder in the zip."; flush(); @unlink(e_TEMP.$localfile); return; } if(is_dir(e_TEMP.$dir)) { - $status = "Unzipping..."; + echo "Unzipping...
"; if(!rename(e_TEMP.$dir,$destpath.$dir)) { - $alert = $tp->toJS("Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"); - echo ""; + echo "Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder"; flush(); usleep(50000); @unlink(e_TEMP.$localfile); return; } - $alert = $tp->toJS("Download Complete!"); - echo ""; + echo "Download Complete!
"; flush(); // $dir = basename($unarc[0]['filename']); // $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir)); - $status = "Done"; // ADMIN_TRUE_ICON; - return $status; + //$status = "Done"; // ADMIN_TRUE_ICON; + @unlink(e_TEMP.$localfile); + return; } else { //ADMIN_FALSE_ICON. - $status = "Download Manually"; + echo "Download Manually"; flush(); usleep(50000); if(E107_DEBUG_LEVEL > 0) { - $status .= print_a($unarc, true); + echo print_a($unarc, true); flush(); } } - return $status; @unlink(e_TEMP.$localfile); } diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php index 267d53c8b..cffc8c889 100644 --- a/e107_handlers/theme_handler.php +++ b/e107_handlers/theme_handler.php @@ -1037,7 +1037,8 @@ class themeHandler $downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&' : '').'&action=download&src='.base64_encode($d);//$url.'&action=download'; $infoUrl = $url.'&action=info'; - $main_icon = " "; + //$main_icon = " "; + $main_icon = " "; $info_icon = "".trim(E_32_CAT_ABOUT).""; if($theme['livedemo'])