1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 06:07:32 +02:00

Plugin and Theme manager fixes. Start on e-alert (requires more work)

This commit is contained in:
Cameron
2013-05-03 21:34:59 -07:00
parent 2db0b73da2
commit 086e8c3afc
5 changed files with 160 additions and 36 deletions

View File

@@ -436,6 +436,7 @@ echo "</head>
<body".$body_onload.">\n"; <body".$body_onload.">\n";
echo getModal(); echo getModal();
echo getAlert();
function getModal($caption = '', $type='') function getModal($caption = '', $type='')
{ {
@@ -467,6 +468,16 @@ echo getModal();
} }
function getAlert($caption)
{
return '<div id="uiAlert" class="alert alert-block alert-success hide fade in" style="box-shadow:0px 15px 8px #000;width:300px;position:absolute;left:40%;right:40%;top:15%;z-index:10000">
<!-- rest of alert code goes here --> some
Some text goes here and there and everywhere.
</div>';
}
// Header included notification, from this point header includes are not possible // Header included notification, from this point header includes are not possible

View File

@@ -27,13 +27,37 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax
$localfile = md5($remotefile.time()).".zip"; $localfile = md5($remotefile.time()).".zip";
$status = "Downloading..."; $status = "Downloading...";
e107::getFile()->getRemoteFile($remotefile,$localfile); // e107::getFile()->getRemoteFile($remotefile,$localfile);
e107::getFile()->download($remotefile,'plugin');
exit;
/*
if(!file_exists(e_TEMP.$localfile)) if(!file_exists(e_TEMP.$localfile))
{ {
echo 'There was a problem retrieving the file'; echo 'There was a problem retrieving the file';
exit; exit;
} }
else
{
$contents = file_get_contents(e_TEMP.$localfile);
if($contents == 'LOGIN')
{
echo "<div class='e-alert'>Please login to your e107.org account and try again</div>";
exit;
}
}
echo "Disabed";
exit;
// chmod(e_PLUGIN,0777); // chmod(e_PLUGIN,0777);
chmod(e_TEMP.$localfile,0755); chmod(e_TEMP.$localfile,0755);
@@ -45,7 +69,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax
// chmod(e_UPLOAD.$localfile,0666); // chmod(e_UPLOAD.$localfile,0666);
*/
/* Cannot use this yet until 'folder' is included in feed. /* Cannot use this yet until 'folder' is included in feed.
if($dir != $p['plugin_folder']) if($dir != $p['plugin_folder'])
{ {
@@ -56,7 +80,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax
exit; exit;
} }
*/ */
/*
if($unarc[0]['folder'] ==1 && is_dir($unarc[0]['filename'])) if($unarc[0]['folder'] ==1 && is_dir($unarc[0]['filename']))
{ {
$status = "Unzipping..."; $status = "Unzipping...";
@@ -84,6 +108,9 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax
// echo "file=".$file; // echo "file=".$file;
exit; exit;
*/
} }
e107::coreLan('plugin', true); e107::coreLan('plugin', true);
@@ -227,8 +254,9 @@ class pluginManager{
var $id; var $id;
var $frm; var $frm;
var $fieldpref; var $fieldpref;
var $titlearray = array(); var $titlearray = array();
var $pagetitle; var $pagetitle;
protected $pid = 'plugin_id'; protected $pid = 'plugin_id';
protected $fields = array( protected $fields = array(
@@ -256,7 +284,7 @@ class pluginManager{
function pluginManager() function __construct()
{ {
global $user_pref,$admin_log; global $user_pref,$admin_log;
@@ -292,13 +320,12 @@ class pluginManager{
// Complicated, as each uninstall system is different. // Complicated, as each uninstall system is different.
}*/ }*/
} }
function pluginObserver() function pluginObserver()
{ {
@@ -472,7 +499,8 @@ class pluginManager{
$text = " $text = "
<form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'> <form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='get'>
<div class='e-search'>".$frm->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online')."</div> <div class='e-search'>".$frm->search('srch', $srch, 'go', $filterName, $filterArray, $filterVal).$frm->hidden('mode','online')."
</div>
</form> </form>
<form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='post'> <form action='".e_SELF."?".e_QUERY."' id='core-plugin-list-form' method='post'>
@@ -536,9 +564,20 @@ class pluginManager{
function options($data) function options($data)
{ {
// print_a($data);
if(!e107::getFile()->hasAuthKey())
{
// return "<a href='".e_SELF."' class='btn btn-primary e-modal' >Download and Install</a>";
}
$d = http_build_query($data,false,'&'); $d = http_build_query($data,false,'&');
$url = e_SELF."?src=".base64_encode($d); $url = e_SELF."?src=".base64_encode($d);
$id = 'plug_'.$data['plugin_folder']; $id = 'plug_'.$data['plugin_id'];
return "<div id='{$id}' style='vertical-align:middle'> return "<div id='{$id}' style='vertical-align:middle'>
<button type='button' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='btn btn-primary e-ajax middle' value='Download and Install' data-src='".$url."' ><span>Download and Install</span></button> <button type='button' data-target='{$id}' data-loading='".e_IMAGE."/generic/loading_32.gif' class='btn btn-primary e-ajax middle' value='Download and Install' data-src='".$url."' ><span>Download and Install</span></button>
</div>"; </div>";
@@ -1483,7 +1522,7 @@ class pluginManager{
// $var['upload']['text'] = EPL_ADLAN_38; // $var['upload']['text'] = EPL_ADLAN_38;
// $var['upload']['link'] = e_SELF."?upload"; // $var['upload']['link'] = e_SELF."?upload";
$var['online']['text'] = "Search"; $var['online']['text'] = "Find Plugins";
$var['online']['link'] = e_SELF."?mode=online"; $var['online']['link'] = e_SELF."?mode=online";
$var['create']['text'] = "Plugin Builder"; $var['create']['text'] = "Plugin Builder";

View File

@@ -97,6 +97,10 @@ class e_file
*/ */
public $finfo = 'default'; public $finfo = 'default';
private $authKey = false; // Used when retrieving files from e107.org.
/** /**
* Constructor * Constructor
*/ */
@@ -320,6 +324,7 @@ class e_file
$cp = curl_init($remote_url); $cp = curl_init($remote_url);
curl_setopt($cp, CURLOPT_FILE, $fp); curl_setopt($cp, CURLOPT_FILE, $fp);
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)");
curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt'); curl_setopt($cp, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
@@ -680,6 +685,26 @@ class e_file
} }
// Use e107.org login.
private function setAuthKey($username,$password)
{
$now = gmdate('y-m-d H:i');
$this->authKey = sha1($username.md5($password).$now);
return $this;
}
private function getAuthKey()
{
return $this->authKey;
}
public function hasAuthKey()
{
return ($this->authKey != false) ? true : false;
}
/** /**
* 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.
@@ -690,9 +715,14 @@ class e_file
{ {
$tp = e107::getParser(); $tp = e107::getParser();
list($url,$qry) = explode("?",$remotefile);
$remotefile = $url."?auth=".$this->getAuthKey()."&".$qry;
$localfile = md5($remotefile.time()).".zip"; $localfile = md5($remotefile.time()).".zip";
$status = "Downloading..."; $status = "Downloading...";
// echo "<script>alert('".$remotefile."')</script>";
$result = $this->getRemoteFile($remotefile,$localfile); $result = $this->getRemoteFile($remotefile,$localfile);
if(!file_exists(e_TEMP.$localfile)) if(!file_exists(e_TEMP.$localfile))
@@ -708,7 +738,15 @@ class e_file
echo $status; echo $status;
exit; exit;
} }
else
{
$contents = file_get_contents(e_TEMP.$localfile);
if($contents == 'false')
{
echo "<div class='e-alert'>Authentication Error</div>";
exit;
}
}
// chmod(e_PLUGIN,0777); // chmod(e_PLUGIN,0777);
chmod(e_TEMP.$localfile,0755); chmod(e_TEMP.$localfile,0755);
@@ -719,13 +757,15 @@ class e_file
$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 = $this->getRootFolder($unarc);
$destpath = ($type == 'theme') ? e_THEME : e_PLUGIN; $destpath = ($type == 'theme') ? e_THEME : e_PLUGIN;
$typeDiz = ucfirst($type);
@copy(e_TEMP.$localfile,e_BACKUP.$dir.".zip"); // Make a Backup in the system folder. @copy(e_TEMP.$localfile,e_BACKUP.$dir.".zip"); // Make a Backup in the system folder.
if($dir && is_dir($destpath.$dir)) if($dir && is_dir($destpath.$dir))
{ {
$alert = $tp->toJS("Theme Already Installed".$destpath.$dir); $alert = $tp->toJS(ucfirst($type)." Already Installed".$destpath.$dir);
echo "<script>alert('".$alert."')</script>"; echo "<script>alert('".$alert."')</script>";
echo "Already Installed";
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
exit; exit;
} }
@@ -735,7 +775,7 @@ class e_file
$status = "Unzipping..."; $status = "Unzipping...";
if(!rename(e_TEMP.$dir,$destpath.$dir)) if(!rename(e_TEMP.$dir,$destpath.$dir))
{ {
$alert = $tp->toJS("Couldn't Move Theme to Theme Folder"); $alert = $tp->toJS("Couldn't Move ".$typeDiz." to ".$typeDiz." Folder");
echo "<script>alert('".$alert."')</script>"; echo "<script>alert('".$alert."')</script>";
@unlink(e_TEMP.$localfile); @unlink(e_TEMP.$localfile);
exit; exit;
@@ -746,7 +786,7 @@ class e_file
// $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 = ADMIN_TRUE_ICON; $status = "Done"; // ADMIN_TRUE_ICON;
} }
// elseif(already_a_directory // elseif(already_a_directory

View File

@@ -314,11 +314,12 @@ class xmlClass
* @param integer $timeout [optional] seconds * @param integer $timeout [optional] seconds
* @return string * @return string
*/ */
function getRemoteFile($address, $timeout = 10) function getRemoteFile($address, $timeout = 10, $postData=null)
{ {
// Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here // Could do something like: if ($timeout <= 0) $timeout = $pref['get_remote_timeout']; here
$timeout = min($timeout, 120); $timeout = min($timeout, 120);
$timeout = max($timeout, 3); $timeout = max($timeout, 3);
$this->xmlFileContents = '';
$mes = e107::getMessage(); $mes = e107::getMessage();
@@ -339,6 +340,39 @@ class xmlClass
// ... and there shouldn't be unprintable characters in the URL anyway // ... and there shouldn't be unprintable characters in the URL anyway
// Keep this in first position.
if (function_exists("curl_init")) // Preferred.
{
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $address);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, true);
curl_setopt($cu, CURLOPT_HEADER, 0);
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
curl_setopt($cu, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cu, CURLOPT_REFERER, e_REQUEST_HTTP);
curl_setopt($cu, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($cu, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($cu, CURLOPT_COOKIEFILE, e_SYSTEM.'cookies.txt');
curl_setopt($cu, CURLOPT_COOKIEJAR, e_SYSTEM.'cookies.txt');
if(!file_exists(e_SYSTEM.'cookies.txt'))
{
file_put_contents(e_SYSTEM.'cookies.txt','');
}
$this->xmlFileContents = curl_exec($cu);
if (curl_error($cu))
{
$this->error = "Curl error: ".curl_errno($cu).", ".curl_error($cu);
return FALSE;
}
curl_close($cu);
return $this->xmlFileContents;
}
if (function_exists('file_get_contents') && ini_get('allow_url_fopen')) if (function_exists('file_get_contents') && ini_get('allow_url_fopen'))
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);
@@ -359,22 +393,7 @@ class xmlClass
$this->error = "File_get_contents(XML) error"; // Fill in more info later $this->error = "File_get_contents(XML) error"; // Fill in more info later
return FALSE; return FALSE;
} }
if (function_exists("curl_init"))
{
$cu = curl_init();
curl_setopt($cu, CURLOPT_URL, $address);
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cu, CURLOPT_HEADER, 0);
curl_setopt($cu, CURLOPT_TIMEOUT, $timeout);
$this->xmlFileContents = curl_exec($cu);
if (curl_error($cu))
{
$this->error = "Curl error: ".curl_errno($cu).", ".curl_error($cu);
return FALSE;
}
curl_close($cu);
return $this->xmlFileContents;
}
if (ini_get("allow_url_fopen")) if (ini_get("allow_url_fopen"))
{ {
$old_timeout = e107_ini_set('default_socket_timeout', $timeout); $old_timeout = e107_ini_set('default_socket_timeout', $timeout);

View File

@@ -301,6 +301,21 @@ $(document).ready(function()
// $(".e-spinner").spinner(); //FIXME breaks tooltips etc. // $(".e-spinner").spinner(); //FIXME breaks tooltips etc.
$(".e-alert").live("click", function(){
var message = $(this).html();
alert(message);
$("#uiAlert").val(message);
$("#uiAlert").alert();
$("#uiAlert").fadeIn('slow');
window.setTimeout(function() { $("#uiAlert").alert('close'); }, 4000);
});
$(".e-radio-multi").each(function() { $(".e-radio-multi").each(function() {
// $(this).nextAll(".field-help").hide(); // $(this).nextAll(".field-help").hide();
// $(this).nextAll(":input").tipsy({title: 'hello'}); // $(this).nextAll(":input").tipsy({title: 'hello'});