mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
Theme downlods in working state (work in progress, cleanup needed)
This commit is contained in:
@@ -69,9 +69,45 @@ 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'])
|
||||||
|
{
|
||||||
|
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.
|
if(vartrue($_GET['src'])) // Process Theme Download.
|
||||||
{
|
{
|
||||||
$string = base64_decode($_GET['src']);
|
$string = base64_decode($_GET['src']);
|
||||||
@@ -90,13 +126,15 @@ if(e_AJAX_REQUEST)
|
|||||||
exit;
|
exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
// Theme Info Ajax
|
// Theme Info Ajax
|
||||||
|
// FIXME addd action=preview to the url, remove this block
|
||||||
$tm = (string) $_GET['id'];
|
$tm = (string) $_GET['id'];
|
||||||
$data = $themec->getThemeInfo($tm);
|
$data = $themec->getThemeInfo($tm);
|
||||||
echo $themec->renderThemeInfo($data);
|
echo $themec->renderThemeInfo($data);
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -84,6 +84,14 @@ class e_marketplace
|
|||||||
return $this->adapter()->call($method, $data, $apply);
|
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
|
* 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.
|
* 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 $remotefile URL
|
||||||
* @param string $type plugin or theme
|
* @param string $type plugin or theme
|
||||||
*/
|
*/
|
||||||
public function download($id, $type='theme')
|
public function download($id, $mode, $type)
|
||||||
{
|
{
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
$id = intval($id);
|
$id = intval($id);
|
||||||
$qry = 'id='.$id;
|
$qry = 'id='.$id.'&type='.$type.'&mode='.$mode;
|
||||||
$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...";
|
$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);
|
$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))
|
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)
|
if(E107_DEBUG_LEVEL > 0)
|
||||||
{
|
{
|
||||||
$status .= 'local='.$localfile;
|
$status .= '<br />local='.$localfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $status;
|
return $status;
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$contents = file_get_contents(e_TEMP.$localfile);
|
$contents = file_get_contents(e_TEMP.$localfile);
|
||||||
if(strlen($contents) < 400)
|
if(strlen($contents) < 400)
|
||||||
{
|
{
|
||||||
echo "<script>alert('".$tp->toJS($contents)."')</script>";
|
echo "<script>alert('".$tp->toJS($contents)."')</script>";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
chmod(e_TEMP.$localfile, 0755);
|
chmod(e_TEMP.$localfile, 0755);
|
||||||
require_once(e_HANDLER."pclzip.lib.php");
|
require_once(e_HANDLER."pclzip.lib.php");
|
||||||
|
|
||||||
$archive = new PclZip(e_TEMP.$localfile);
|
$archive = new PclZip(e_TEMP.$localfile);
|
||||||
$unarc = ($fileList = $archive -> extract(PCLZIP_OPT_PATH, e_TEMP, PCLZIP_OPT_SET_CHMOD, 0755)); // Store in TEMP first.
|
$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;
|
$destpath = ($type == 'theme') ? e_THEME : e_PLUGIN;
|
||||||
$typeDiz = ucfirst($type);
|
$typeDiz = ucfirst($type);
|
||||||
|
|
||||||
@@ -199,14 +227,14 @@ abstract class e_marketplace_adapter_abstract
|
|||||||
echo "<script>alert('".$alert."')</script>";
|
echo "<script>alert('".$alert."')</script>";
|
||||||
echo "Already Installed";
|
echo "Already Installed";
|
||||||
@unlink(e_TEMP.$localfile);
|
@unlink(e_TEMP.$localfile);
|
||||||
exit;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($dir == '')
|
if($dir == '')
|
||||||
{
|
{
|
||||||
echo "<script>alert('Couldn\'t detect the root folder in the zip.')</script>";
|
echo "<script>alert('Couldn\'t detect the root folder in the zip.')</script>";
|
||||||
@unlink(e_TEMP.$localfile);
|
@unlink(e_TEMP.$localfile);
|
||||||
exit;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_dir(e_TEMP.$dir))
|
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");
|
$alert = $tp->toJS("Couldn't Move ".e_TEMP.$dir." to ".$destpath.$dir." Folder");
|
||||||
echo "<script>alert('".$alert."')</script>";
|
echo "<script>alert('".$alert."')</script>";
|
||||||
@unlink(e_TEMP.$localfile);
|
@unlink(e_TEMP.$localfile);
|
||||||
exit;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$alert = $tp->toJS("Download Complete!");
|
$alert = $tp->toJS("Download Complete!");
|
||||||
@@ -226,36 +254,41 @@ abstract class e_marketplace_adapter_abstract
|
|||||||
// $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;
|
||||||
}
|
}
|
||||||
else
|
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)
|
if(E107_DEBUG_LEVEL > 0)
|
||||||
{
|
{
|
||||||
$status .= print_a($unarc, true);
|
$status .= print_a($unarc, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo $status;
|
return $status;
|
||||||
@unlink(e_TEMP.$localfile);
|
@unlink(e_TEMP.$localfile);
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab a remote file and save it in the /temp directory. requires CURL
|
// Grab a remote file and save it in the /temp directory. requires CURL
|
||||||
function getRemoteFile($remote_url, $local_file, $type='temp')
|
function getRemoteFile($remote_url, $local_file, $type='temp')
|
||||||
{
|
{
|
||||||
// FIXME - different methods (see xml handler getRemoteFile()), error handling, appropriate error messages,
|
// FIXME - different methods (see xml handler getRemoteFile()), error handling, appropriate error messages,
|
||||||
if (function_exists("curl_init"))
|
if (!function_exists("curl_init"))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$path = ($type == 'media') ? e_MEDIA : e_TEMP;
|
$path = ($type == 'media') ? e_MEDIA : e_TEMP;
|
||||||
|
|
||||||
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
$fp = fopen($path.$local_file, 'w'); // media-directory is the root.
|
||||||
|
//$fp1 = fopen(e_TEMP.'/curllog.txt', 'w');
|
||||||
|
|
||||||
$cp = curl_init($remote_url);
|
$cp = curl_init($remote_url);
|
||||||
curl_setopt($cp, CURLOPT_FILE, $fp);
|
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_REFERER, e_REQUEST_HTTP);
|
||||||
curl_setopt($cp, CURLOPT_HEADER, 0);
|
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_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
|
||||||
@@ -265,6 +298,13 @@ abstract class e_marketplace_adapter_abstract
|
|||||||
|
|
||||||
curl_close($cp);
|
curl_close($cp);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
//fclose($fp1);
|
||||||
|
|
||||||
|
if($buffer)
|
||||||
|
{
|
||||||
|
$size = filesize($path.$local_file);
|
||||||
|
if($size < 400) $buffer = false;
|
||||||
|
}
|
||||||
|
|
||||||
return ($buffer) ? true : false;
|
return ($buffer) ? true : false;
|
||||||
}
|
}
|
||||||
|
@@ -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.
|
* 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 $remotefile URL
|
||||||
* @param $type plugin or theme
|
* @param $type plugin or theme
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
public function download($remotefile, $type='theme')
|
public function download($remotefile, $type='theme')
|
||||||
{
|
{
|
||||||
$tp = e107::getParser();
|
$tp = e107::getParser();
|
||||||
@@ -835,13 +837,14 @@ class e_file
|
|||||||
|
|
||||||
// echo "file=".$file;
|
// echo "file=".$file;
|
||||||
exit;
|
exit;
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs through the zip archive array and finds the root directory.
|
* Runs through the zip archive array and finds the root directory.
|
||||||
*/
|
*/
|
||||||
private function getRootFolder($unarc)
|
public function getRootFolder($unarc)
|
||||||
{
|
{
|
||||||
foreach($unarc as $d)
|
foreach($unarc as $d)
|
||||||
{
|
{
|
||||||
|
@@ -546,6 +546,9 @@ class themeHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
$theme = array(
|
$theme = array(
|
||||||
|
'id' => $r['params']['id'],
|
||||||
|
'type' => 'theme',
|
||||||
|
'mode' => $r['params']['mode'],
|
||||||
'name' => stripslashes($r['name']),
|
'name' => stripslashes($r['name']),
|
||||||
'category' => $r['category'],
|
'category' => $r['category'],
|
||||||
'preview' => varset($r['screenshots']['image']),
|
'preview' => varset($r['screenshots']['image']),
|
||||||
@@ -561,7 +564,6 @@ class themeHandler
|
|||||||
'livedemo' => $r['livedemo'],
|
'livedemo' => $r['livedemo'],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$text .= $this->renderTheme(FALSE, $theme);
|
$text .= $this->renderTheme(FALSE, $theme);
|
||||||
|
|
||||||
$c++;
|
$c++;
|
||||||
@@ -1032,8 +1034,11 @@ class themeHandler
|
|||||||
$id = $frm->name2id($theme['name']);
|
$id = $frm->name2id($theme['name']);
|
||||||
$LAN_DOWNLOAD = ($theme['price'] > 0) ? "Buy/Download" : "Download";
|
$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> ";
|
$downloadUrl = e_SELF.'?'.(e_QUERY ? e_QUERY.'&' : '').'&action=download&src='.base64_encode($d);//$url.'&action=download';
|
||||||
$info_icon = "<a data-toggle='modal' data-modal-caption=\"".$theme['name']." ".$theme['version']."\" href='".$url."&info=1' data-cache='false' data-target='#uiModal' title='".TPVLAN_7."'>".trim(E_32_CAT_ABOUT)."</a>";
|
$infoUrl = $url.'&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'])
|
if($theme['livedemo'])
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user