diff --git a/e107_admin/theme.php b/e107_admin/theme.php
index 829656ac9..62092f4fe 100644
--- a/e107_admin/theme.php
+++ b/e107_admin/theme.php
@@ -68,10 +68,46 @@ 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 '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'];
+ $data = $themec->getThemeInfo($tm);
+ echo $themec->renderThemeInfo($data);
+ exit;
+ break;
+
+ }
+/*
if(vartrue($_GET['src'])) // Process Theme Download.
{
$string = base64_decode($_GET['src']);
@@ -90,13 +126,15 @@ if(e_AJAX_REQUEST)
exit;
}
-
+*/
// Theme Info Ajax
+ // FIXME addd action=preview to the url, remove this block
$tm = (string) $_GET['id'];
$data = $themec->getThemeInfo($tm);
echo $themec->renderThemeInfo($data);
exit;
+
}
else
{
diff --git a/e107_handlers/e_marketplace.php b/e107_handlers/e_marketplace.php
index 742b0f58c..1b7799141 100644
--- a/e107_handlers/e_marketplace.php
+++ b/e107_handlers/e_marketplace.php
@@ -84,6 +84,14 @@ class e_marketplace
return $this->adapter()->call($method, $data, $apply);
}
+ /**
+ * Adapter proxy
+ */
+ public function download($id, $mode, $type)
+ {
+ return $this->adapter()->download($id, $mode, $type);
+ }
+
/**
* Direct adapter()->call() execution - experimental stage
*/
@@ -145,49 +153,69 @@ abstract class e_marketplace_adapter_abstract
/**
* Download a Plugin or Theme to Temp, then test and move to plugin/theme folder and backup to system backup folder.
+ * 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)
+ *
* @param string $remotefile URL
* @param string $type plugin or theme
*/
- public function download($id, $type='theme')
+ public function download($id, $mode, $type)
{
$tp = e107::getParser();
$id = intval($id);
- $qry = 'id='.$id;
+ $qry = 'id='.$id.'&type='.$type.'&mode='.$mode;
$remotefile = $this->downloadUrl."?auth=".$this->getAuthKey()."&".$qry;
-
+
$localfile = md5($remotefile.time()).".zip";
$status = "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)
+ {
+ $status = "Download Error.";
+ if(filesize(e_TEMP.$localfile))
+ {
+ $contents = file_get_contents(e_TEMP.$localfile);
+ $contents = explode('REQ_', $contents);
+ $status .= '
[#'.trim($contents[1]).'] '.trim($contents[0]);
+ }
+ @unlink(e_TEMP.$localfile);
+ return $status;
+ }
if(!file_exists(e_TEMP.$localfile))
{
- $status = ADMIN_FALSE_ICON."
Download Manually";
+ //ADMIN_FALSE_ICON
+ $status = "Download Manually";
if(E107_DEBUG_LEVEL > 0)
{
- $status .= 'local='.$localfile;
+ $status .= '
local='.$localfile;
}
- echo $status;
- exit;
+ return $status;
}
+ /*
else
- {
- $contents = file_get_contents(e_TEMP.$localfile);
- if(strlen($contents) < 400)
- {
- echo "";
- return;
- }
- }
+ {
+ $contents = file_get_contents(e_TEMP.$localfile);
+ if(strlen($contents) < 400)
+ {
+ echo "";
+ return;
+ }
+ }*/
+
chmod(e_TEMP.$localfile, 0755);
require_once(e_HANDLER."pclzip.lib.php");
$archive = new PclZip(e_TEMP.$localfile);
$unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_TEMP, PCLZIP_OPT_SET_CHMOD, 0755)); // Store in TEMP first.
- $dir = $this->getRootFolder($unarc);
+ $dir = e107::getFile(true)->getRootFolder($unarc);
$destpath = ($type == 'theme') ? e_THEME : e_PLUGIN;
$typeDiz = ucfirst($type);
@@ -199,14 +227,14 @@ abstract class e_marketplace_adapter_abstract
echo "";
echo "Already Installed";
@unlink(e_TEMP.$localfile);
- exit;
+ return;
}
if($dir == '')
{
echo "";
@unlink(e_TEMP.$localfile);
- exit;
+ return;
}
if(is_dir(e_TEMP.$dir))
@@ -217,7 +245,7 @@ abstract class e_marketplace_adapter_abstract
$alert = $tp->toJS("Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder");
echo "";
@unlink(e_TEMP.$localfile);
- exit;
+ return;
}
$alert = $tp->toJS("Download Complete!");
@@ -226,46 +254,58 @@ abstract class e_marketplace_adapter_abstract
// $dir = basename($unarc[0]['filename']);
// $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir));
$status = "Done"; // ADMIN_TRUE_ICON;
-
+ return $status;
}
else
{
- $status = ADMIN_FALSE_ICON."
Download Manually";
+ //ADMIN_FALSE_ICON.
+ $status = "Download Manually";
if(E107_DEBUG_LEVEL > 0)
{
$status .= print_a($unarc, true);
}
}
- echo $status;
+ return $status;
@unlink(e_TEMP.$localfile);
- exit;
}
// Grab a remote file and save it in the /temp directory. requires CURL
function getRemoteFile($remote_url, $local_file, $type='temp')
{
// FIXME - different methods (see xml handler getRemoteFile()), error handling, appropriate error messages,
- if (function_exists("curl_init"))
+ if (!function_exists("curl_init"))
{
return false;
}
$path = ($type == 'media') ? e_MEDIA : e_TEMP;
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
+ //$fp1 = fopen(e_TEMP.'/curllog.txt', 'w');
$cp = curl_init($remote_url);
curl_setopt($cp, CURLOPT_FILE, $fp);
+
+ //curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ //curl_setopt($ch, CURLOPT_STDERR, $fp1);
+
curl_setopt($cp, CURLOPT_REFERER, e_REQUEST_HTTP);
curl_setopt($cp, CURLOPT_HEADER, 0);
curl_setopt($cp, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
$buffer = curl_exec($cp);
-
+
curl_close($cp);
fclose($fp);
-
+ //fclose($fp1);
+
+ if($buffer)
+ {
+ $size = filesize($path.$local_file);
+ if($size < 400) $buffer = false;
+ }
+
return ($buffer) ? true : false;
}
}
diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php
index 671078dcb..19cbf03aa 100644
--- a/e107_handlers/file_class.php
+++ b/e107_handlers/file_class.php
@@ -723,9 +723,11 @@ class e_file
/**
* Download a Plugin or Theme to Temp, then test and move to plugin/theme folder and backup to system backup folder.
+ * DEPRECATED - moved to e_marketplace
* @param $remotefile URL
* @param $type plugin or theme
*/
+/*
public function download($remotefile, $type='theme')
{
$tp = e107::getParser();
@@ -835,13 +837,14 @@ class e_file
// echo "file=".$file;
exit;
- }
+ } */
+
/**
* Runs through the zip archive array and finds the root directory.
*/
- private function getRootFolder($unarc)
+ public function getRootFolder($unarc)
{
foreach($unarc as $d)
{
diff --git a/e107_handlers/theme_handler.php b/e107_handlers/theme_handler.php
index 74ce89061..267d53c8b 100644
--- a/e107_handlers/theme_handler.php
+++ b/e107_handlers/theme_handler.php
@@ -546,6 +546,9 @@ class themeHandler
}
$theme = array(
+ 'id' => $r['params']['id'],
+ 'type' => 'theme',
+ 'mode' => $r['params']['mode'],
'name' => stripslashes($r['name']),
'category' => $r['category'],
'preview' => varset($r['screenshots']['image']),
@@ -561,7 +564,6 @@ class themeHandler
'livedemo' => $r['livedemo'],
);
-
$text .= $this->renderTheme(FALSE, $theme);
$c++;
@@ -1032,8 +1034,11 @@ class themeHandler
$id = $frm->name2id($theme['name']);
$LAN_DOWNLOAD = ($theme['price'] > 0) ? "Buy/Download" : "Download";
- $main_icon = "
";
- $info_icon = "".trim(E_32_CAT_ABOUT)."";
+ $downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&' : '').'&action=download&src='.base64_encode($d);//$url.'&action=download';
+ $infoUrl = $url.'&action=info';
+
+ $main_icon = "
";
+ $info_icon = "".trim(E_32_CAT_ABOUT)."";
if($theme['livedemo'])
{