From 086e8c3afc5fe73952b04ec9267f09f70a561377 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 3 May 2013 21:34:59 -0700 Subject: [PATCH] Plugin and Theme manager fixes. Start on e-alert (requires more work) --- e107_admin/header.php | 11 +++++ e107_admin/plugin.php | 69 +++++++++++++++++++++++++------- e107_handlers/file_class.php | 48 ++++++++++++++++++++-- e107_handlers/xml_class.php | 53 ++++++++++++++++-------- e107_web/js/core/admin.jquery.js | 15 +++++++ 5 files changed, 160 insertions(+), 36 deletions(-) diff --git a/e107_admin/header.php b/e107_admin/header.php index 02f7e4893..b0e0ce303 100644 --- a/e107_admin/header.php +++ b/e107_admin/header.php @@ -436,6 +436,7 @@ echo " \n"; echo getModal(); +echo getAlert(); function getModal($caption = '', $type='') { @@ -467,6 +468,16 @@ echo getModal(); } +function getAlert($caption) +{ + + return '
+ some + Some text goes here and there and everywhere. +
'; + +} + // Header included notification, from this point header includes are not possible diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index bd6434514..9c6be3aed 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -27,13 +27,37 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax $localfile = md5($remotefile.time()).".zip"; $status = "Downloading..."; - e107::getFile()->getRemoteFile($remotefile,$localfile); +// e107::getFile()->getRemoteFile($remotefile,$localfile); + e107::getFile()->download($remotefile,'plugin'); + + + exit; + + /* + + + + + if(!file_exists(e_TEMP.$localfile)) { echo 'There was a problem retrieving the file'; exit; } + else + { + $contents = file_get_contents(e_TEMP.$localfile); + if($contents == 'LOGIN') + { + echo "
Please login to your e107.org account and try again
"; + exit; + } + } + + echo "Disabed"; + exit; + // chmod(e_PLUGIN,0777); chmod(e_TEMP.$localfile,0755); @@ -45,7 +69,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax // chmod(e_UPLOAD.$localfile,0666); - + */ /* Cannot use this yet until 'folder' is included in feed. if($dir != $p['plugin_folder']) { @@ -56,7 +80,7 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax exit; } */ - + /* if($unarc[0]['folder'] ==1 && is_dir($unarc[0]['filename'])) { $status = "Unzipping..."; @@ -84,6 +108,9 @@ if(e_AJAX_REQUEST && isset($_GET['src'])) // Ajax // echo "file=".$file; exit; + + */ + } e107::coreLan('plugin', true); @@ -227,8 +254,9 @@ class pluginManager{ var $id; var $frm; var $fieldpref; - var $titlearray = array(); + var $titlearray = array(); var $pagetitle; + protected $pid = 'plugin_id'; protected $fields = array( @@ -256,7 +284,7 @@ class pluginManager{ - function pluginManager() + function __construct() { global $user_pref,$admin_log; @@ -292,13 +320,12 @@ class pluginManager{ // Complicated, as each uninstall system is different. }*/ - - - - - } + + + + function pluginObserver() { @@ -472,9 +499,10 @@ class pluginManager{ $text = "
- +
- +
".$caption." @@ -535,10 +563,21 @@ class pluginManager{ function options($data) - { + { + + // print_a($data); + + + if(!e107::getFile()->hasAuthKey()) + { + // return "Download and Install"; + + } + + $d = http_build_query($data,false,'&'); $url = e_SELF."?src=".base64_encode($d); - $id = 'plug_'.$data['plugin_folder']; + $id = 'plug_'.$data['plugin_id']; return "
"; @@ -1483,7 +1522,7 @@ class pluginManager{ // $var['upload']['text'] = EPL_ADLAN_38; // $var['upload']['link'] = e_SELF."?upload"; - $var['online']['text'] = "Search"; + $var['online']['text'] = "Find Plugins"; $var['online']['link'] = e_SELF."?mode=online"; $var['create']['text'] = "Plugin Builder"; diff --git a/e107_handlers/file_class.php b/e107_handlers/file_class.php index 05a1b5b98..35d0e2ecd 100644 --- a/e107_handlers/file_class.php +++ b/e107_handlers/file_class.php @@ -96,6 +96,10 @@ class e_file * @var string default (BC) | image | file | all */ public $finfo = 'default'; + + + + private $authKey = false; // Used when retrieving files from e107.org. /** * Constructor @@ -320,6 +324,7 @@ class e_file $cp = curl_init($remote_url); curl_setopt($cp, CURLOPT_FILE, $fp); + 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'); @@ -679,8 +684,28 @@ 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. * @param $remotefile URL @@ -690,9 +715,14 @@ class e_file { $tp = e107::getParser(); + list($url,$qry) = explode("?",$remotefile); + + $remotefile = $url."?auth=".$this->getAuthKey()."&".$qry; + $localfile = md5($remotefile.time()).".zip"; $status = "Downloading..."; + // echo ""; $result = $this->getRemoteFile($remotefile,$localfile); if(!file_exists(e_TEMP.$localfile)) @@ -708,7 +738,15 @@ class e_file echo $status; exit; } - + else + { + $contents = file_get_contents(e_TEMP.$localfile); + if($contents == 'false') + { + echo "
Authentication Error
"; + exit; + } + } // chmod(e_PLUGIN,0777); 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. $dir = $this->getRootFolder($unarc); $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. if($dir && is_dir($destpath.$dir)) { - $alert = $tp->toJS("Theme Already Installed".$destpath.$dir); + $alert = $tp->toJS(ucfirst($type)." Already Installed".$destpath.$dir); echo ""; + echo "Already Installed"; @unlink(e_TEMP.$localfile); exit; } @@ -735,7 +775,7 @@ class e_file $status = "Unzipping..."; 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 ""; @unlink(e_TEMP.$localfile); exit; @@ -746,7 +786,7 @@ class e_file // $dir = basename($unarc[0]['filename']); // $plugPath = preg_replace("/[^a-z0-9-\._]/", "-", strtolower($dir)); - $status = ADMIN_TRUE_ICON; + $status = "Done"; // ADMIN_TRUE_ICON; } // elseif(already_a_directory diff --git a/e107_handlers/xml_class.php b/e107_handlers/xml_class.php index 4b25f78a6..a2b96ea0e 100644 --- a/e107_handlers/xml_class.php +++ b/e107_handlers/xml_class.php @@ -314,11 +314,12 @@ class xmlClass * @param integer $timeout [optional] seconds * @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 $timeout = min($timeout, 120); $timeout = max($timeout, 3); + $this->xmlFileContents = ''; $mes = e107::getMessage(); @@ -339,6 +340,39 @@ class xmlClass // ... 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')) { $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 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")) { $old_timeout = e107_ini_set('default_socket_timeout', $timeout); diff --git a/e107_web/js/core/admin.jquery.js b/e107_web/js/core/admin.jquery.js index 8751a2e48..d135dede3 100644 --- a/e107_web/js/core/admin.jquery.js +++ b/e107_web/js/core/admin.jquery.js @@ -301,6 +301,21 @@ $(document).ready(function() // $(".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() { // $(this).nextAll(".field-help").hide(); // $(this).nextAll(":input").tipsy({title: 'hello'});