1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 12:20:44 +02:00

Theme downlods in working state (work in progress, cleanup needed)

This commit is contained in:
SecretR
2013-05-19 12:16:10 +03:00
parent f5c6e866a2
commit 380e46cd56
4 changed files with 118 additions and 32 deletions

View File

@@ -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
{

View File

@@ -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 .= '<br />[#'.trim($contents[1]).'] '.trim($contents[0]);
}
@unlink(e_TEMP.$localfile);
return $status;
}
if(!file_exists(e_TEMP.$localfile))
{
$status = ADMIN_FALSE_ICON."<br /><a href='".$remotefile."'>Download Manually</a>";
//ADMIN_FALSE_ICON
$status = "<a href='".$remotefile."'>Download Manually</a>";
if(E107_DEBUG_LEVEL > 0)
{
$status .= 'local='.$localfile;
$status .= '<br />local='.$localfile;
}
echo $status;
exit;
return $status;
}
/*
else
{
$contents = file_get_contents(e_TEMP.$localfile);
if(strlen($contents) < 400)
{
echo "<script>alert('".$tp->toJS($contents)."')</script>";
return;
}
}
{
$contents = file_get_contents(e_TEMP.$localfile);
if(strlen($contents) < 400)
{
echo "<script>alert('".$tp->toJS($contents)."')</script>";
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 "<script>alert('".$alert."')</script>";
echo "Already Installed";
@unlink(e_TEMP.$localfile);
exit;
return;
}
if($dir == '')
{
echo "<script>alert('Couldn\'t detect the root folder in the zip.')</script>";
@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 "<script>alert('".$alert."')</script>";
@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."<br /><a href='".$remotefile."'>Download Manually</a>";
//ADMIN_FALSE_ICON.
$status = "<a href='".$remotefile."'>Download Manually</a>";
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;
}
}

View File

@@ -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)
{

View File

@@ -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 = "<a data-src='".$url."' href='#' 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> ";
$info_icon = "<a data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$url."&amp;info=1' data-cache='false' data-target='#uiModal' title='".TPVLAN_7."'>".trim(E_32_CAT_ABOUT)."</a>";
$downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&amp;' : '').'&action=download&amp;src='.base64_encode($d);//$url.'&amp;action=download';
$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> ";
$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'])
{