From 5d4cc191ad5794c12025e5923d4021fbb8498fb3 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 31 Jul 2011 21:57:15 +1000 Subject: [PATCH 01/66] Added some updating functions for later. --- lib/class.github.php | 7 ++++ update.php | 84 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/lib/class.github.php b/lib/class.github.php index 11790dc..e14196b 100755 --- a/lib/class.github.php +++ b/lib/class.github.php @@ -27,6 +27,13 @@ function getCommits(){ return $this->request($this->URL.'repos/'.$this->USER.'/'.$this->REPO.'/commits'); } + function getDownload($id = ''){ + if($id!==''){ + $id = '/'.$id; + } + return $this->request($this->URL.'repos/'.$this->USER.'/'.$this->REPO.'/downloads'.$id); + } + //creates a cURL request to the API. function request($url){ $ch = curl_init(); diff --git a/update.php b/update.php index afbc7be..79d2152 100644 --- a/update.php +++ b/update.php @@ -16,4 +16,88 @@ function updateVersion(){ } echo true; } + +function getNew(){ + require_once 'lib/class.github.php'; + $git = new GitHub('gugahoi'); + + echo '
';print_r($git->getDownload());echo '
'; +} + +function getGit(){ + ignore_user_abort(); +/* + if(!is_dir('.git') || !is_readable('.git')){ + echo 'Not a git installation. Creating one now.'; + $output = shell_exec('git clone git://github.com/gugahoi/mediafrontpage.git '.$_SERVER); + } else { + echo 'Pulling repo'; + $output = shell_exec('git pull'); + echo "
$output
"; + } +*/ +} + +function download($url){ + if (!extension_loaded('zip')) { + try{ + dl('zip.so'); + } catch(Exception $e){ + echo 'Could not load extension ZIP'; + exit; + } + } + + $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; + $file_zip = "update.zip"; + $file_txt = "update"; + + echo "Starting"; + + // make the cURL request to $url + $ch = curl_init(); + //Opening $file_zip to save the download + $fp = fopen("$file_zip", "w"); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_FAILONERROR, true); + //No headers + curl_setopt($ch, CURLOPT_HEADER,0); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, true); + curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_FILE, $fp); + + $page = curl_exec($ch); + + //In case the donwload failed + if (!$page) { + echo "
cURL error number:" .curl_errno($ch); + echo "
cURL error:" . curl_error($ch); + curl_close($ch); + exit; + } + curl_close($ch); + + echo "
Downloaded file: $url"; + echo "
Saved as file: $file_zip"; + echo "
About to unzip ..."; + + // Un zip the file + + $zip = new ZipArchive; + if (! $zip) { + echo "
Could not make ZipArchive object."; + exit; + } + if($zip->open("$file_zip") != "true") { + echo "
Could not open $file_zip"; + } + $zip->extractTo("$file_txt"); + $zip->close(); + + echo "
Unzipped file to: $file_txt

"; +} +download('https://nodeload.github.com/DejaVu77/mediafrontpage/zipball/561e9ea2e21dbb4c126877ccf1a9c95860bad79b'); ?> From 367df5e04c8844e0a701694662c324104a3fac58 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 31 Jul 2011 22:34:20 +1000 Subject: [PATCH 02/66] Able to get the name of the folder now. --- update.php | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/update.php b/update.php index 79d2152..043555b 100644 --- a/update.php +++ b/update.php @@ -47,7 +47,15 @@ function download($url){ exit; } } - + + if(file_exists('update')){ + unlink('update'); + echo 'Deleted leftover update from previous update
'; + } + if(file_exists('update.zip')){ + unlink('update.zip'); + echo 'Deleted leftover ZIP from previous update
'; + } $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; $file_txt = "update"; @@ -66,12 +74,12 @@ function download($url){ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FILE, $fp); $page = curl_exec($ch); - //In case the donwload failed + //In case the download failed if (!$page) { echo "
cURL error number:" .curl_errno($ch); echo "
cURL error:" . curl_error($ch); @@ -84,20 +92,32 @@ function download($url){ echo "
Saved as file: $file_zip"; echo "
About to unzip ..."; - // Un zip the file - + // Unzip the file $zip = new ZipArchive; - if (! $zip) { + if (!$zip) { echo "
Could not make ZipArchive object."; exit; } if($zip->open("$file_zip") != "true") { - echo "
Could not open $file_zip"; + echo "
Could not open $file_zip. Code: "; } $zip->extractTo("$file_txt"); $zip->close(); - echo "
Unzipped file to: $file_txt

"; + $name = ''; + if ($handle = opendir('update')) { + //echo "Directory handle: $handle\n"; + //echo "Files:\n"; + + /* This is the correct way to loop over the directory. */ + while (false !== ($file = readdir($handle))) { + if(strstr($file,'mediafrontpage')){ + $name = $file; + } + } + + closedir($handle); + } } download('https://nodeload.github.com/DejaVu77/mediafrontpage/zipball/561e9ea2e21dbb4c126877ccf1a9c95860bad79b'); ?> From ed52c1e676d7e23fe3da1e603fe64921bb093621 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 3 Aug 2011 20:22:34 +1000 Subject: [PATCH 03/66] Updated ignored files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5c3e76b..8d27ca1 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ layout.php config.ini m/mobileconfig.php sbpcache/* +update/* +update.zip \ No newline at end of file From 4795e3c9a68a9eb6970bb42d07e3de4e34673ede Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 3 Aug 2011 20:23:27 +1000 Subject: [PATCH 04/66] Further improvements of update function. --- update.php | 142 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 89 insertions(+), 53 deletions(-) diff --git a/update.php b/update.php index 043555b..77d4e77 100644 --- a/update.php +++ b/update.php @@ -1,4 +1,5 @@ ';print_r($git->getDownload());echo ''; } -function getGit(){ - ignore_user_abort(); -/* - if(!is_dir('.git') || !is_readable('.git')){ - echo 'Not a git installation. Creating one now.'; - $output = shell_exec('git clone git://github.com/gugahoi/mediafrontpage.git '.$_SERVER); - } else { - echo 'Pulling repo'; - $output = shell_exec('git pull'); - echo "
$output
"; - } -*/ -} - -function download($url){ - if (!extension_loaded('zip')) { - try{ - dl('zip.so'); - } catch(Exception $e){ - echo 'Could not load extension ZIP'; - exit; - } - } +function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ + cleanUp(); - if(file_exists('update')){ - unlink('update'); - echo 'Deleted leftover update from previous update
'; - } - if(file_exists('update.zip')){ - unlink('update.zip'); - echo 'Deleted leftover ZIP from previous update
'; - } $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; - $file_txt = "update"; echo "Starting"; - // make the cURL request to $url $ch = curl_init(); //Opening $file_zip to save the download $fp = fopen("$file_zip", "w"); curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + // set the cURL request to $url curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_FAILONERROR, true); //No headers curl_setopt($ch, CURLOPT_HEADER,0); + //Follow redirects curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_AUTOREFERER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); + //timeout set to 30 seconds. FIle must finish downloading in this time. curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FILE, $fp); - + //execute request $page = curl_exec($ch); //In case the download failed @@ -88,36 +61,99 @@ function download($url){ } curl_close($ch); - echo "
Downloaded file: $url"; + echo "
Downloaded file from: $url"; echo "
Saved as file: $file_zip"; - echo "
About to unzip ..."; + echo "
Starting unzip ..."; - // Unzip the file - $zip = new ZipArchive; - if (!$zip) { - echo "
Could not make ZipArchive object."; + if(!unzip($file_zip, 'update')){ + echo 'Unzip failed'; exit; } - if($zip->open("$file_zip") != "true") { - echo "
Could not open $file_zip. Code: "; - } - $zip->extractTo("$file_txt"); - $zip->close(); - echo "
Unzipped file to: $file_txt

"; + $name = ''; + //Getting the name of the file. It should be the only file in the UPDATE directory for now. + //In the future I'd like to rename the update according to the PUSHED TIME or DOWNLOADED TIME. if ($handle = opendir('update')) { - //echo "Directory handle: $handle\n"; - //echo "Files:\n"; - - /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { if(strstr($file,'mediafrontpage')){ $name = $file; } } - closedir($handle); } + + $updateContents = scandir('update/'.$name); + foreach($updateContents as $number=>$fileName){ + try{ + rename('update/'.$name.'/'.$fileName, $fileName); + } catch(Exception $e) { + echo 'Could not move file '.$fileName; + } + } +} + +function unzip($file, $extractDir = 'update'){ + //check if ZIP extension is loaded + if (!extension_loaded('zip')) { + try{ + dl('zip.so'); + } catch(Exception $e){ + echo 'Could not load extension ZIP'; + exit; + } + } + // Unzip the file + $zip = new ZipArchive; + if (!$zip) { + echo "
Could not make ZipArchive object."; + return false; + } + if($zip->open("$file") != "true") { + echo "
Could not open $file."; + return false; + } + $zip->extractTo($extractDir); + $zip->close(); + echo "
Unzipped file to: ".$extractDir.''; + return true; +} +/* +/Function to clean up some leftover files. If files other than 'update' folder and 'update.zip' +/are to be deleted, than the $extra variable and be used. If multiple files are to be deleted use +/$extra as an array. +/ +/return: false if nothing is deleted, a string with the deleted files otherwise. +*/ +function cleanUp($extra = ''){ + $return_value = ''; + if(file_exists('update')){ + if(@unlink('update')){ + $return_value .= '
update folder deleted'; + } + } + if(file_exists('update.zip')){ + if(@unlink('update.zip')){ + $return_value .= '
update.zip deleted'; + } + } + if($extra !== ''){ + if(is_array($extra)){ + foreach($extra as $x){ + if(@unlink($x)){ + $return_value = '
'.$x.' deleted'; + } + } + } else { + if(@unlink($extra)){ + $return_value = '
'.$extra.' deleted'; + } + } + } + if($return_value === ''){ + return false; + } else { + return $return_value; + } } -download('https://nodeload.github.com/DejaVu77/mediafrontpage/zipball/561e9ea2e21dbb4c126877ccf1a9c95860bad79b'); +download(); ?> From e915a8792017bb5e971de09cf3763e2be8ba4841 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 3 Aug 2011 22:33:10 +1000 Subject: [PATCH 05/66] More functions --- update.php | 204 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 141 insertions(+), 63 deletions(-) diff --git a/update.php b/update.php index 77d4e77..073ce2f 100644 --- a/update.php +++ b/update.php @@ -1,17 +1,15 @@ getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); - try{ - $config->set('version', $commitNo, 'ADVANCED'); + try{ + $config->set('version', $commitNo, 'ADVANCED'); } catch (Exception $e){ echo false; exit; } @@ -26,54 +24,54 @@ function getNew(){ } function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ - cleanUp(); + echo cleanUp(); $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; echo "Starting"; - $ch = curl_init(); - //Opening $file_zip to save the download - $fp = fopen("$file_zip", "w"); - curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + $ch = curl_init(); + //Opening $file_zip to save the download + $fp = fopen("$file_zip", "w"); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); // set the cURL request to $url - curl_setopt($ch, CURLOPT_URL,$url); - curl_setopt($ch, CURLOPT_FAILONERROR, true); + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_FAILONERROR, true); //No headers - curl_setopt($ch, CURLOPT_HEADER,0); - //Follow redirects - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_AUTOREFERER, true); - curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); - //timeout set to 30 seconds. FIle must finish downloading in this time. - curl_setopt($ch, CURLOPT_TIMEOUT, 30); - curl_setopt($ch, CURLOPT_FILE, $fp); - //execute request - $page = curl_exec($ch); - - //In case the download failed - if (!$page) { - echo "
cURL error number:" .curl_errno($ch); - echo "
cURL error:" . curl_error($ch); - curl_close($ch); - exit; - } - curl_close($ch); - - echo "
Downloaded file from: $url"; - echo "
Saved as file: $file_zip"; - echo "
Starting unzip ..."; - - if(!unzip($file_zip, 'update')){ - echo 'Unzip failed'; - exit; - } - - $name = ''; + curl_setopt($ch, CURLOPT_HEADER,0); + //Follow redirects + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, true); + curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); + //timeout set to 30 seconds. File must finish downloading in this time. + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_FILE, $fp); + //execute request + $page = curl_exec($ch); + + //In case the download failed + if (!$page) { + echo "
cURL error number:" .curl_errno($ch); + echo "
cURL error:" . curl_error($ch); + curl_close($ch); + exit; + } + curl_close($ch); + + echo "
Downloaded file from: $url"; + echo "
Saved as file: $file_zip"; + echo "
Starting unzip ..."; + + if(!unzip($file_zip, 'update')){ + echo 'Unzip failed'; + exit; + } + + $name = ''; //Getting the name of the file. It should be the only file in the UPDATE directory for now. //In the future I'd like to rename the update according to the PUSHED TIME or DOWNLOADED TIME. - if ($handle = opendir('update')) { + if ($handle = opendir('update')) { while (false !== ($file = readdir($handle))) { if(strstr($file,'mediafrontpage')){ $name = $file; @@ -82,12 +80,18 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } + deleteOld(); + $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ - try{ - rename('update/'.$name.'/'.$fileName, $fileName); - } catch(Exception $e) { - echo 'Could not move file '.$fileName; + if(is_dir($fileName)){ + moveDownload('update/'.$name.'/'.$fileName,''); + } else { + if(rename('update/'.$name.'/'.$fileName, $fileName)){ + echo $filename.' moved successfully'; + } else { + echo 'Could not move file '.$fileName; + } } } } @@ -102,21 +106,22 @@ function unzip($file, $extractDir = 'update'){ exit; } } - // Unzip the file - $zip = new ZipArchive; - if (!$zip) { - echo "
Could not make ZipArchive object."; - return false; - } - if($zip->open("$file") != "true") { - echo "
Could not open $file."; - return false; - } - $zip->extractTo($extractDir); - $zip->close(); - echo "
Unzipped file to: ".$extractDir.''; + // Unzip the file + $zip = new ZipArchive; + if (!$zip) { + echo "
Could not make ZipArchive object."; + return false; + } + if($zip->open("$file") != "true") { + echo "
Could not open $file."; + return false; + } + $zip->extractTo($extractDir); + $zip->close(); + echo "
Unzipped file to: ".$extractDir.''; return true; } + /* /Function to clean up some leftover files. If files other than 'update' folder and 'update.zip' /are to be deleted, than the $extra variable and be used. If multiple files are to be deleted use @@ -155,5 +160,78 @@ function cleanUp($extra = ''){ return $return_value; } } -download(); + +/* +/Recursively move items from src to dst. Will overwrite if needed. +*/ +function moveDownload($src,$dst){ + $dir = opendir($src); + while(false !== ($file = readdir($dir))){ + if (($file != '.') && ($file != '..') && ($file != 'config.ini') && ($file != 'layout.php') && ($file != 'sbpcache') && ($file !='update')){ + if (is_dir($src.'/'.$file)){ + if(file_exists($dst.'/'.$file)){ + rrmdir($dst.'/'.$file); + } + } + if(@rename($src . '/' . $file, $dst . '/' . $file)){ + echo '
Moved successfully: '.$file.''; + } else { + if(@chmod($src.'/'.$file, 0777)){ + if(@rename($src . '/' . $file, $dst . '/' . $file)){ + echo '
Moved successfully: '.$file.''; + } else { + echo '
Failed to move: '.$file.'. RENAME did not work.'; + } + } else { + echo '
Failed to move: '.$file.'. CHMOD did not work.'; + } + } + } + } + closedir($dir); +} + +//Deletes directories and it's contents. +function rrmdir($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir"){ + echo 'Going into '.$dir."/".$object; + rrmdir($dir."/".$object); + } else { + if(unlink($dir."/".$object)){ + echo 'Deleted: '.$dir."/".$object; + } else { + echo 'Failed to delete: '.$dir."/".$object; + } + } + } + } + reset($objects); + rmdir($dir); + } +} + +function deleteOld(){ + $contents = scandir('/'); + foreach($contents as $number => $name){ + if($name != 'update' && $name != 'config.ini' && $name != 'layout.php'){ + if(is_dir($name)){ + echo '
Deleting DIR: '.$name.''; + rrmdir($name); + } else { + if(unlink($name)){ + echo '
Deleting file: '.$name.' OK'; + } else { + echo '
Deleting file: '.$name.' FAILED'; + } + } + } + } + + +} +//download(); ?> From b7339c5c3adac2ac718a715b7024acbb502aaedb Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 11:52:55 +1000 Subject: [PATCH 06/66] Update functions updated --- update.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/update.php b/update.php index 073ce2f..5c58d1d 100644 --- a/update.php +++ b/update.php @@ -1,7 +1,6 @@ $fileName){ if(is_dir($fileName)){ moveDownload('update/'.$name.'/'.$fileName,''); @@ -94,6 +94,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } } } +*/ } function unzip($file, $extractDir = 'update'){ @@ -198,13 +199,13 @@ function rrmdir($dir) { foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir"){ - echo 'Going into '.$dir."/".$object; + echo '
Going into '.$dir."/".$object; rrmdir($dir."/".$object); } else { if(unlink($dir."/".$object)){ - echo 'Deleted: '.$dir."/".$object; + echo '
Deleting file: '.$dir."/".$object.' OK'; } else { - echo 'Failed to delete: '.$dir."/".$object; + echo '
Deleting file: '.$dir."/".$object.' FAILED'; } } } @@ -215,9 +216,9 @@ function rrmdir($dir) { } function deleteOld(){ - $contents = scandir('/'); + $contents = scandir('./'); foreach($contents as $number => $name){ - if($name != 'update' && $name != 'config.ini' && $name != 'layout.php'){ + if($name != 'update' && $name != 'config.ini' && $name != 'layout.php' && $name != '..' && $name != '.' && $name != '.git' && $name != '.gitignore'){ if(is_dir($name)){ echo '
Deleting DIR: '.$name.''; rrmdir($name); @@ -230,8 +231,6 @@ function deleteOld(){ } } } - - } -//download(); +download(); ?> From 2e2575e790ccd337ed29ada519a5f85580a5a5fe Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 11:56:10 +1000 Subject: [PATCH 07/66] More updates --- update.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/update.php b/update.php index 5c58d1d..8140d92 100644 --- a/update.php +++ b/update.php @@ -81,20 +81,20 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip deleteOld(); - /* -$updateContents = scandir('update/'.$name); + + $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ if(is_dir($fileName)){ - moveDownload('update/'.$name.'/'.$fileName,''); + moveDownload('update/'.$name.'/'.$fileName, $fileName); } else { if(rename('update/'.$name.'/'.$fileName, $fileName)){ - echo $filename.' moved successfully'; + echo '
'.$filename.' moved successfully OK'; } else { - echo 'Could not move file '.$fileName; + echo '
Could not move file '.$fileName.'ERROR'; } } } -*/ + } function unzip($file, $extractDir = 'update'){ From f273b381885bb29f5bba11801c78f7f817381ce4 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 12:04:17 +1000 Subject: [PATCH 08/66] Moving to tmp directory --- update.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) mode change 100644 => 100755 update.php diff --git a/update.php b/update.php old mode 100644 new mode 100755 index 8140d92..803cb81 --- a/update.php +++ b/update.php @@ -84,14 +84,16 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ - if(is_dir($fileName)){ - moveDownload('update/'.$name.'/'.$fileName, $fileName); - } else { - if(rename('update/'.$name.'/'.$fileName, $fileName)){ - echo '
'.$filename.' moved successfully OK'; - } else { - echo '
Could not move file '.$fileName.'ERROR'; - } + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ + if(is_dir($fileName)){ + moveDownload('update/'.$name.'/'.$fileName, 'tmp/'.$fileName); + } else { + if(rename('update/'.$name.'/'.$fileName, 'tmp/'.$fileName)){ + echo '
'.$filename.' moved successfully OK'; + } else { + echo '
Could not move file '.$fileName.'ERROR'; + } + } } } From 98ace2ec1a28a881ddec2bee578674e72a7fde78 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 12:10:50 +1000 Subject: [PATCH 09/66] Moving to tmp dir. --- EXTRAS/Core.js | 0 EXTRAS/MediaLibrary.js | 0 EXTRAS/index.html | 0 firstrun.php | 0 js/parse_uri.js | 0 update.php | 2 +- 6 files changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 EXTRAS/Core.js mode change 100644 => 100755 EXTRAS/MediaLibrary.js mode change 100644 => 100755 EXTRAS/index.html mode change 100644 => 100755 firstrun.php mode change 100644 => 100755 js/parse_uri.js diff --git a/EXTRAS/Core.js b/EXTRAS/Core.js old mode 100644 new mode 100755 diff --git a/EXTRAS/MediaLibrary.js b/EXTRAS/MediaLibrary.js old mode 100644 new mode 100755 diff --git a/EXTRAS/index.html b/EXTRAS/index.html old mode 100644 new mode 100755 diff --git a/firstrun.php b/firstrun.php old mode 100644 new mode 100755 diff --git a/js/parse_uri.js b/js/parse_uri.js old mode 100644 new mode 100755 diff --git a/update.php b/update.php index 803cb81..b717c29 100755 --- a/update.php +++ b/update.php @@ -220,7 +220,7 @@ function rrmdir($dir) { function deleteOld(){ $contents = scandir('./'); foreach($contents as $number => $name){ - if($name != 'update' && $name != 'config.ini' && $name != 'layout.php' && $name != '..' && $name != '.' && $name != '.git' && $name != '.gitignore'){ + if($name != 'update' && $name != 'config.ini' && $name != 'layout.php' && $name != '..' && $name != '.' && $name != '.git' && $name != '.gitignore' && $name != 'tmp'){ if(is_dir($name)){ echo '
Deleting DIR: '.$name.''; rrmdir($name); From 3b0ec935cc7f4337dad68acb6d35395723b73384 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 12:20:14 +1000 Subject: [PATCH 10/66] Rearranging --- update.php | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/update.php b/update.php index b717c29..2b3c30e 100755 --- a/update.php +++ b/update.php @@ -79,9 +79,28 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - deleteOld(); + //deleteOld(); + echo 'OLD STUFF'; + echo ''; + $updateContents = scandir('./'); + foreach($updateContents as $number=>$fileName){ + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ + if(is_dir($fileName)){ + moveDownload($fileName, 'old/'.$fileName); + } else { + if(rename($fileName, 'old/'.$fileName)){ + echo ''; + } else { + echo ''; + } + } + } + } + echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; + echo 'New stuff'; + echo ''; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ @@ -89,14 +108,14 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip moveDownload('update/'.$name.'/'.$fileName, 'tmp/'.$fileName); } else { if(rename('update/'.$name.'/'.$fileName, 'tmp/'.$fileName)){ - echo '
'.$filename.' moved successfully OK'; + echo ''; } else { - echo '
Could not move file '.$fileName.'ERROR'; + echo ''; } } } } - + echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; } function unzip($file, $extractDir = 'update'){ From e1df6e19168cdc8bf0d77ea5a6ec81d7fa709c43 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 7 Aug 2011 12:25:06 +1000 Subject: [PATCH 11/66] More updates --- update.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/update.php b/update.php index 2b3c30e..cb028dd 100755 --- a/update.php +++ b/update.php @@ -81,7 +81,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip //deleteOld(); - echo 'OLD STUFF'; + echo '

OLD STUFF

'; echo ''; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ @@ -99,7 +99,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } echo '
'; - echo 'New stuff'; + echo '

New stuff

'; echo ''; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ @@ -196,16 +196,16 @@ function moveDownload($src,$dst){ } } if(@rename($src . '/' . $file, $dst . '/' . $file)){ - echo '
Moved successfully: '.$file.''; + echo ''; } else { if(@chmod($src.'/'.$file, 0777)){ if(@rename($src . '/' . $file, $dst . '/' . $file)){ - echo '
Moved successfully: '.$file.''; + echo ''; } else { - echo '
Failed to move: '.$file.'. RENAME did not work.'; + echo ''; } } else { - echo '
Failed to move: '.$file.'. CHMOD did not work.'; + echo ''; } } } From 2e06fa1685433bdefc455cac3e2a3f683ccad21f Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 20:45:10 +1000 Subject: [PATCH 12/66] Updated Trakt widget to Ajax to speed up loading of page. --- widgets/wTrakt.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/widgets/wTrakt.php b/widgets/wTrakt.php index 191df73..0e69b7a 100755 --- a/widgets/wTrakt.php +++ b/widgets/wTrakt.php @@ -1,5 +1,5 @@ "trakt.tv", "type" => "inline", "function" => "wTrakt();", "headerfunction" => "wTraktHeader();"); +$wIndex["wTrakt"] = array("name" => "trakt.tv", "type" => "ajax", "block" => "traktwrapper", "call" => "widgets/wTrakt.php?style=w", "headerfunction" => "wTraktHeader();", "interval" => "100000"); function wTraktHeader() { @@ -10,9 +10,9 @@ function wTraktHeader() $("a[rel^='prettyPhoto']").prettyPhoto( { social_tools: false - }); + }); }); - + clearInterval(traktwrapper_interval); --> TRAKTHEADER; @@ -32,11 +32,12 @@ function wTrakt() wTraktMovieRecommendations(); echo '

TV Recommendation

'; wTraktTVRecommendations(); + echo ''; } function traktMethods($traktApiMethods, $post = false, $format = "json", $debug = false) //set debug to true to see the actual returned values { - require "config.php"; + require "../config.php"; global $trakt_api, $trakt_username, $trakt_password; $response; echo (empty($trakt_api))?"

API not set in config.php

":""; @@ -308,4 +309,24 @@ function printItem($type, $url, $title, $year, $poster, $overview, $runtime, $im echo '
'.$file.' moved successfully OK
'.$file.' moved successfully OK
Could not move file '.$file.'ERROR RENAME
Could not move file '.$file.'ERROR CHMOD
'; } +if(!empty($_GET['style']) && ($_GET['style'] == "w")) { + require_once "../config.php"; + if($_GET['style'] == "w") { ?> + + + Media Front Page - Trakt + + + + + + + \ No newline at end of file From fbd6e6e5f5b184f7cd547ed7da2c10c01786c0bd Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 20:55:12 +1000 Subject: [PATCH 13/66] Added some jquery toggling. --- update.php | 65 ++++++------------------------------------------------ 1 file changed, 7 insertions(+), 58 deletions(-) diff --git a/update.php b/update.php index cb028dd..42553a0 100755 --- a/update.php +++ b/update.php @@ -79,15 +79,13 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - //deleteOld(); - - echo '

OLD STUFF

'; - echo ''; + echo '

OLD STUFF

'; + echo '
'; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ if(is_dir($fileName)){ - moveDownload($fileName, 'old/'.$fileName); + rename($fileName, 'old/'.$fileName); } else { if(rename($fileName, 'old/'.$fileName)){ echo ''; @@ -99,15 +97,15 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } echo '
'.$fileName.' moved successfully OK
'; - echo '

New stuff

'; - echo ''; + echo '

New stuff

'; + echo '
'; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ if(is_dir($fileName)){ - moveDownload('update/'.$name.'/'.$fileName, 'tmp/'.$fileName); + rename('update/'.$name.'/'.$fileName, './'.$fileName); } else { - if(rename('update/'.$name.'/'.$fileName, 'tmp/'.$fileName)){ + if(rename('update/'.$name.'/'.$fileName, './'.$fileName)){ echo ''; } else { echo ''; @@ -183,36 +181,6 @@ function cleanUp($extra = ''){ } } -/* -/Recursively move items from src to dst. Will overwrite if needed. -*/ -function moveDownload($src,$dst){ - $dir = opendir($src); - while(false !== ($file = readdir($dir))){ - if (($file != '.') && ($file != '..') && ($file != 'config.ini') && ($file != 'layout.php') && ($file != 'sbpcache') && ($file !='update')){ - if (is_dir($src.'/'.$file)){ - if(file_exists($dst.'/'.$file)){ - rrmdir($dst.'/'.$file); - } - } - if(@rename($src . '/' . $file, $dst . '/' . $file)){ - echo ''; - } else { - if(@chmod($src.'/'.$file, 0777)){ - if(@rename($src . '/' . $file, $dst . '/' . $file)){ - echo ''; - } else { - echo ''; - } - } else { - echo ''; - } - } - } - } - closedir($dir); -} - //Deletes directories and it's contents. function rrmdir($dir) { if (is_dir($dir)) { @@ -235,23 +203,4 @@ function rrmdir($dir) { rmdir($dir); } } - -function deleteOld(){ - $contents = scandir('./'); - foreach($contents as $number => $name){ - if($name != 'update' && $name != 'config.ini' && $name != 'layout.php' && $name != '..' && $name != '.' && $name != '.git' && $name != '.gitignore' && $name != 'tmp'){ - if(is_dir($name)){ - echo '
Deleting DIR: '.$name.''; - rrmdir($name); - } else { - if(unlink($name)){ - echo '
Deleting file: '.$name.'OK'; - } else { - echo '
Deleting file: '.$name.'FAILED'; - } - } - } - } -} -download(); ?> From eb4aaec6888b837b3919377802c0956cea48f9b1 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:09:47 +1000 Subject: [PATCH 14/66] ignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8d27ca1..7290720 100755 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ config.ini m/mobileconfig.php sbpcache/* update/* -update.zip \ No newline at end of file +update.zip +tmp/* \ No newline at end of file From 3ea1294f1b621de575ea2fd48320540897ea7e25 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:10:35 +1000 Subject: [PATCH 15/66] not ignoring. --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 7290720..4a6c06b 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,4 @@ layout.php config.ini m/mobileconfig.php sbpcache/* -update/* -update.zip -tmp/* \ No newline at end of file +update.zip \ No newline at end of file From 7b1b71f31ee03ce85ce6d8ff24724be8be71a9c2 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:11:13 +1000 Subject: [PATCH 16/66] Added tmp, update folder. --- tmp/placeholder | 0 update/placeholder | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tmp/placeholder create mode 100644 update/placeholder diff --git a/tmp/placeholder b/tmp/placeholder new file mode 100644 index 0000000..e69de29 diff --git a/update/placeholder b/update/placeholder new file mode 100644 index 0000000..e69de29 From 7e9f26aada27e203080ab59c2b77fe3f507ba746 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:40:53 +1000 Subject: [PATCH 17/66] Added some logic to updating. --- update.php | 123 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 48 deletions(-) diff --git a/update.php b/update.php index 42553a0..e633d82 100755 --- a/update.php +++ b/update.php @@ -23,7 +23,6 @@ function getNew(){ } function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ - echo cleanUp(); $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; @@ -79,41 +78,70 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - echo '

OLD STUFF

'; - echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'.$file.' moved successfully OK
'.$file.' moved successfully OK
Could not move file '.$file.'ERROR RENAME
Could not move file '.$file.'ERROR CHMOD
'; - $updateContents = scandir('./'); + $succesful = true; + echo '

OLD STUFF

'; + echo '
'; + $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ - if(is_dir($fileName)){ - rename($fileName, 'old/'.$fileName); - } else { - if(rename($fileName, 'old/'.$fileName)){ - echo ''; - } else { - echo ''; - } - } + if(is_dir($fileName)){ + rename($fileName, 'tmp/'.$fileName); + } else { + if(rename($fileName, 'tmp/'.$fileName)){ + echo ''; + } else { + echo ''; + $successful = false; + } + } } } - echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; + echo ''; - echo '

New stuff

'; - echo ''; - $updateContents = scandir('update/'.$name); - foreach($updateContents as $number=>$fileName){ - if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ - if(is_dir($fileName)){ - rename('update/'.$name.'/'.$fileName, './'.$fileName); - } else { - if(rename('update/'.$name.'/'.$fileName, './'.$fileName)){ - echo ''; - } else { - echo ''; - } - } + if($successful){ + echo '

New stuff

'; + echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; + $updateContents = scandir('update/'.$name); + foreach($updateContents as $number=>$fileName){ + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ + if(is_dir($fileName)){ + rename('update/'.$name.'/'.$fileName, './'.$fileName); + } else { + if(rename('update/'.$name.'/'.$fileName, './'.$fileName)){ + echo ''; + } else { + echo ''; + $successful = false; + } + } + } } } - echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; + echo ''; + + //If the renaming went through smoothly, need to clean up the downloaded and backed up files. Otherwise, + //move the files back and tell user to update manually. + if($successful){ + echo "

UPDATE SUCCESSFULL

"; + $dir = scandir('update/'); + echo "

Cleaning up

"; + foreach($dir as $number=>$fileName){ + if($fileName != '..' && $fileName != '.'){ + if(is_dir($fileName)){ + rrmdir('update/'.$fileName); + } else { + if(unlink('update/'.$fileName)){ + echo ''; + } else { + echo ''; + $successful = false; + } + } + } + } + } else { + echo "

FAILED

"; + } } function unzip($file, $extractDir = 'update'){ @@ -183,24 +211,23 @@ function cleanUp($extra = ''){ //Deletes directories and it's contents. function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (filetype($dir."/".$object) == "dir"){ - echo '
Going into '.$dir."/".$object; - rrmdir($dir."/".$object); - } else { - if(unlink($dir."/".$object)){ - echo '
Deleting file: '.$dir."/".$object.'OK'; - } else { - echo '
Deleting file: '.$dir."/".$object.'FAILED'; - } - } - } - } - reset($objects); - rmdir($dir); - } + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (filetype($dir."/".$object) == "dir"){ + rrmdir($dir."/".$object); + } else { + if(unlink($dir."/".$object)){ + echo ''; + } else { + echo ''; + } + } + } + } + reset($objects); + rmdir($dir); + } } ?> From 0bfd370dbca08dd3552be9bd638a30cd9bffbe5f Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:42:48 +1000 Subject: [PATCH 18/66] Typo --- update.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index e633d82..9718802 100755 --- a/update.php +++ b/update.php @@ -78,7 +78,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - $succesful = true; + $successful = true; echo '

OLD STUFF

'; echo '
'.$fileName.' deleted successfully OK
Could not delete file '.$fileName.'ERROR
'.$dir."/".$object.' deleted successfully OK
Could not delete file '.$dir."/".$object.'ERROR
'; $updateContents = scandir('./'); @@ -230,4 +230,5 @@ function rrmdir($dir) { rmdir($dir); } } +download(); ?> From c81046cce4c0f69d35fb10ba2c829a8266bf06ec Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:45:43 +1000 Subject: [PATCH 19/66] Ignoring again. --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4a6c06b..15855f7 100755 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ layout.php config.ini m/mobileconfig.php sbpcache/* -update.zip \ No newline at end of file +update.zip +update/* +tmp/* \ No newline at end of file From dc9e3d8d497647bae320c886df7b125d6cb7f65c Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:46:02 +1000 Subject: [PATCH 20/66] Added jquery. --- update.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) mode change 100755 => 100644 update.php diff --git a/update.php b/update.php old mode 100755 new mode 100644 index 9718802..6b71dd6 --- a/update.php +++ b/update.php @@ -23,7 +23,7 @@ function getNew(){ } function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ - + echo ''; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; @@ -78,7 +78,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - $successful = true; + $succesful = true; echo '

OLD STUFF

'; echo '
'; $updateContents = scandir('./'); @@ -230,5 +230,4 @@ function rrmdir($dir) { rmdir($dir); } } -download(); ?> From 46f68f30fc7a89ad041dd56f22dc461adb224dcc Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:54:43 +1000 Subject: [PATCH 21/66] More checks. --- update.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index 6b71dd6..10bdb65 100644 --- a/update.php +++ b/update.php @@ -134,13 +134,24 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip echo ''; } else { echo ''; - $successful = false; } } } } + echo '
'.$fileName.' deleted successfully OK
Could not delete file '.$fileName.'ERROR
'; } else { echo "

FAILED

"; + $dir = scandir('tmp/'); + echo "

Moving things back

"; + foreach($dir as $number=>$fileName){ + if($fileName != '..' && $fileName != '.'){ + if(rename('tmp/'.$fileName, './'.$fileName)){ + echo ''; + } else { + echo ''; + } + } + } } } @@ -230,4 +241,5 @@ function rrmdir($dir) { rmdir($dir); } } +download(); ?> From 432cdc7e6cd7b7bb1984859bbc3e17e71fdb7259 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:59:16 +1000 Subject: [PATCH 22/66] More stuff. --- update.php | 1 + 1 file changed, 1 insertion(+) diff --git a/update.php b/update.php index 10bdb65..7705125 100644 --- a/update.php +++ b/update.php @@ -152,6 +152,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } } } + echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; } } From d4447f13892fb13d9dedf65984e55236ba29d4e7 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 21:59:58 +1000 Subject: [PATCH 23/66] The typo is back?!?! --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index 7705125..2f57f78 100644 --- a/update.php +++ b/update.php @@ -78,7 +78,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip closedir($handle); } - $succesful = true; + $successful = true; echo '

OLD STUFF

'; echo ''; $updateContents = scandir('./'); From 7adbcd0e09a8c4af799c501825b4be1c28536c99 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:22:43 +1000 Subject: [PATCH 24/66] More clean ups. --- update.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/update.php b/update.php index 2f57f78..f7941d5 100644 --- a/update.php +++ b/update.php @@ -83,7 +83,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip echo '
'; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ - if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ if(is_dir($fileName)){ rename($fileName, 'tmp/'.$fileName); } else { @@ -103,7 +103,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip echo '
'; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ - if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore'){ + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ if(is_dir($fileName)){ rename('update/'.$name.'/'.$fileName, './'.$fileName); } else { @@ -124,14 +124,30 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip if($successful){ echo "

UPDATE SUCCESSFULL

"; $dir = scandir('update/'); - echo "

Cleaning up

"; + echo "

Cleaning up UPDATE

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ rrmdir('update/'.$fileName); + //} else { + //if(unlink('update/'.$fileName)){ + // echo ''; + // } else { + // echo ''; + // } + } + } + } + echo '
'.$fileName.' deleted successfully OK
Could not delete file '.$fileName.'ERROR
'; + $dir = scandir('tmp/'); + echo "

Cleaning up TMP

"; + foreach($dir as $number=>$fileName){ + if($fileName != '..' && $fileName != '.'){ + if(is_dir($fileName)){ + rrmdir('tmp/'.$fileName); } else { - if(unlink('update/'.$fileName)){ - echo ''; + if(unlink('tmp/'.$fileName)){ + echo ''; } else { echo ''; } From 8e52e640e3698fff3b4a9fb38636848f6d6b4b23 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:29:14 +1000 Subject: [PATCH 25/66] Updating commit numbers. --- update.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/update.php b/update.php index f7941d5..27c5742 100644 --- a/update.php +++ b/update.php @@ -7,13 +7,13 @@ function updateVersion(){ $commit = $github->getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); + echo "

Updating commit number from: ".$config->get('version', 'ADVANCED');." -> ".$commitNo."

" try{ $config->set('version', $commitNo, 'ADVANCED'); + echo "OK"; } catch (Exception $e){ - echo false; exit; + echo "ERROR"; } - echo true; - exit; } function getNew(){ @@ -155,6 +155,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } } echo '
'.$fileName.' deleted successfully OK
'.$fileName.' deleted successfully OK
Could not delete file '.$fileName.'ERROR
'; + updateVersion(); } else { echo "

FAILED

"; $dir = scandir('tmp/'); From c38544531c82752d6eaa0b02d96c457c67cfeefb Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:31:40 +1000 Subject: [PATCH 26/66] Display none tables. --- update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update.php b/update.php index 27c5742..8766fb9 100644 --- a/update.php +++ b/update.php @@ -80,7 +80,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip $successful = true; echo '

OLD STUFF

'; - echo ''; + echo '
'; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ @@ -100,7 +100,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip if($successful){ echo '

New stuff

'; - echo ''; + echo '
'; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ @@ -124,7 +124,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip if($successful){ echo "

UPDATE SUCCESSFULL

"; $dir = scandir('update/'); - echo "

Cleaning up UPDATE

"; + echo "

Cleaning up UPDATE

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ From 46a2cbc5c409432093e123d426ead22dba13241f Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:32:42 +1000 Subject: [PATCH 27/66] forgot ; on line 10 --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index 8766fb9..66556af 100644 --- a/update.php +++ b/update.php @@ -7,7 +7,7 @@ function updateVersion(){ $commit = $github->getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); - echo "

Updating commit number from: ".$config->get('version', 'ADVANCED');." -> ".$commitNo."

" + echo "

Updating commit number from: ".$config->get('version', 'ADVANCED');." -> ".$commitNo."

"; try{ $config->set('version', $commitNo, 'ADVANCED'); echo "OK"; From 2a1f7cb773d28f94b99dd3d07d1b06bae2a9550e Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:37:49 +1000 Subject: [PATCH 28/66] Added html tags --- update.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index 66556af..9785db2 100644 --- a/update.php +++ b/update.php @@ -7,7 +7,7 @@ function updateVersion(){ $commit = $github->getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); - echo "

Updating commit number from: ".$config->get('version', 'ADVANCED');." -> ".$commitNo."

"; + echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo."

"; try{ $config->set('version', $commitNo, 'ADVANCED'); echo "OK"; @@ -23,7 +23,9 @@ function getNew(){ } function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ + echo ''; echo ''; + echo ''; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; @@ -171,6 +173,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } echo '
'; } + echo ''; } function unzip($file, $extractDir = 'update'){ From a23eaa490ce09f496474621583b7a2b8610dabfa Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 22:44:58 +1000 Subject: [PATCH 29/66] Almost there!!! --- update.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/update.php b/update.php index 9785db2..daf8a23 100644 --- a/update.php +++ b/update.php @@ -7,12 +7,12 @@ function updateVersion(){ $commit = $github->getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); - echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo."

"; + echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo; try{ $config->set('version', $commitNo, 'ADVANCED'); - echo "OK"; + echo " OK

"; } catch (Exception $e){ - echo "ERROR"; + echo " ERROR

"; } } @@ -24,7 +24,7 @@ function getNew(){ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ echo ''; - echo ''; + echo ''; echo ''; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; @@ -81,7 +81,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } $successful = true; - echo '

OLD STUFF

'; + echo '

OLD STUFF

'; echo ''; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ @@ -101,7 +101,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip echo ''; if($successful){ - echo '

New stuff

'; + echo '

New stuff

'; echo ''; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ @@ -126,7 +126,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip if($successful){ echo "

UPDATE SUCCESSFULL

"; $dir = scandir('update/'); - echo "

Cleaning up UPDATE

"; + echo "

Cleaning up UPDATE

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ From b31bd58f4b6507d10d0ba51dde7a053f544f66ee Mon Sep 17 00:00:00 2001 From: gugahoi Date: Wed, 10 Aug 2011 23:03:15 +1000 Subject: [PATCH 30/66] Hidding tables. --- update.php | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/update.php b/update.php index daf8a23..2591902 100644 --- a/update.php +++ b/update.php @@ -25,6 +25,15 @@ function getNew(){ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ echo ''; echo ''; + echo ''; echo ''; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; @@ -81,8 +90,8 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } $successful = true; - echo '

OLD STUFF

'; - echo '
'; + echo '

Old stuff

'; + echo ''; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ @@ -98,11 +107,11 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } } } - echo '
'; + echo ''; if($successful){ - echo '

New stuff

'; - echo ''; + echo '

New stuff

'; + echo ''; $updateContents = scandir('update/'.$name); foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp'){ @@ -119,14 +128,14 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } } } - echo '
'; + echo ''; //If the renaming went through smoothly, need to clean up the downloaded and backed up files. Otherwise, //move the files back and tell user to update manually. if($successful){ echo "

UPDATE SUCCESSFULL

"; $dir = scandir('update/'); - echo "

Cleaning up UPDATE

"; + echo "

Cleaning up UPDATE

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ @@ -142,7 +151,7 @@ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zip } echo ''; $dir = scandir('tmp/'); - echo "

Cleaning up TMP

"; + echo "

Cleaning up TMP

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ From 320c51e3264d32eb09e59a8f362d93b4c183cbcf Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 10:32:51 +1000 Subject: [PATCH 31/66] Added css --- update.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/update.php b/update.php index 2591902..379e46a 100644 --- a/update.php +++ b/update.php @@ -25,6 +25,9 @@ function getNew(){ function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ echo ''; echo ''; + echo ''; + echo ''; + echo ''; echo ''; - echo ''; + echo '
'; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $file_zip = "update.zip"; - + echo '
+
+

MediaFrontPage Update

+
'; + echo "Starting"; $ch = curl_init(); @@ -93,7 +97,7 @@ function toggle(id){ } $successful = true; - echo '

Old stuff

'; + echo '
'; $updateContents = scandir('./'); foreach($updateContents as $number=>$fileName){ @@ -113,13 +117,17 @@ function toggle(id){ echo '
'; if($successful){ - echo '

New stuff

'; + echo ''; echo ''; + echo '

'; if($successful){ - echo ''; + echo '

'; echo '

'; + echo '

'; //If the renaming went through smoothly, need to clean up the downloaded and backed up files. Otherwise, //move the files back and tell user to update manually. if($successful){ echo "

UPDATE SUCCESSFULL

"; $dir = scandir('update/'); - echo "

Cleaning up UPDATE

"; + echo "

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ @@ -160,9 +160,9 @@ function toggle(id){ } } } - echo '
'; + echo '

'; $dir = scandir('tmp/'); - echo "

Cleaning up TMP

"; + echo "

"; foreach($dir as $number=>$fileName){ if($fileName != '..' && $fileName != '.'){ if(is_dir($fileName)){ @@ -177,9 +177,10 @@ function toggle(id){ } } echo '
'; + echo '

'; updateVersion(); } else { - echo "

FAILED

"; + echo "

UPDATE FAILED

"; $dir = scandir('tmp/'); echo "

Moving things back

"; foreach($dir as $number=>$fileName){ From 9a7dc8fef1487b68deb99a2d79775d1858be98a1 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 12:10:01 +1000 Subject: [PATCH 36/66] Started converting individual actions to functions. --- update.php | 153 ++++++++++++++++++++++++----------------------------- 1 file changed, 70 insertions(+), 83 deletions(-) diff --git a/update.php b/update.php index 01e11c0..a5ecc9f 100644 --- a/update.php +++ b/update.php @@ -1,28 +1,16 @@ getCommits(); - $commitNo = $commit['0']['sha']; - $config = new ConfigMagik('config.ini', true, true); - echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo; - try{ - $config->set('version', $commitNo, 'ADVANCED'); - echo " OK

"; - } catch (Exception $e){ - echo " ERROR

"; +if(!empty($_GET)){ + if(isset($_GET['download'] && $_GET['download']){ + download(); + } + if(isset($_GET['unzip'] && $_GET['unzip']){ + unzip($file_zip, 'update'); } } -function getNew(){ - require_once 'lib/class.github.php'; - $git = new GitHub('gugahoi'); - echo '
';print_r($git->getDownload());echo '
'; -} - -function download($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ +function main($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ echo ''; echo ''; echo ''; @@ -38,8 +26,6 @@ function toggle(id){ } '; echo '
'; - $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; - $file_zip = "update.zip"; echo '

MediaFrontPage Auto-Update

@@ -47,33 +33,6 @@ function toggle(id){ echo "Starting"; - $ch = curl_init(); - //Opening $file_zip to save the download - $fp = fopen("$file_zip", "w"); - curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); - // set the cURL request to $url - curl_setopt($ch, CURLOPT_URL,$url); - curl_setopt($ch, CURLOPT_FAILONERROR, true); - //No headers - curl_setopt($ch, CURLOPT_HEADER,0); - //Follow redirects - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_AUTOREFERER, true); - curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); - //timeout set to 30 seconds. File must finish downloading in this time. - curl_setopt($ch, CURLOPT_TIMEOUT, 30); - curl_setopt($ch, CURLOPT_FILE, $fp); - //execute request - $page = curl_exec($ch); - - //In case the download failed - if (!$page) { - echo "
cURL error number:" .curl_errno($ch); - echo "
cURL error:" . curl_error($ch); - curl_close($ch); - exit; - } - curl_close($ch); echo "
Downloaded file from: $url"; echo "
Saved as file: $file_zip"; @@ -144,38 +103,12 @@ function toggle(id){ //If the renaming went through smoothly, need to clean up the downloaded and backed up files. Otherwise, //move the files back and tell user to update manually. if($successful){ - echo "

UPDATE SUCCESSFULL

"; - $dir = scandir('update/'); + echo "

UPDATE SUCCESSFULL


"; echo "

"; - foreach($dir as $number=>$fileName){ - if($fileName != '..' && $fileName != '.'){ - if(is_dir($fileName)){ - rrmdir('update/'.$fileName); - //} else { - //if(unlink('update/'.$fileName)){ - // echo ''; - // } else { - // echo ''; - // } - } - } - } + rrmdir('update', false); echo '
'.$fileName.' deleted successfully OK
Could not delete file '.$fileName.'ERROR

'; - $dir = scandir('tmp/'); echo "

'; updateVersion(); @@ -262,8 +195,8 @@ function cleanUp($extra = ''){ } } -//Deletes directories and it's contents. -function rrmdir($dir) { +//Deletes directories and it's contents. If $remove is true, it will delete the directory otherwise, only it's contents. +function rrmdir($dir, $remove = true) { if (is_dir($dir)) { $objects = scandir($dir); foreach ($objects as $object) { @@ -278,10 +211,64 @@ function rrmdir($dir) { } } } - } - reset($objects); - rmdir($dir); + } + reset($objects); + if($remove){ + if(rmdir($dir)){ + echo 'DIR: '.$dir.' deleted successfully OK'; + } else { + echo 'Could not delete dir '.$dir.'ERROR'; + } + } } } -download(); + +function download($file_name = "update.zip"){ + $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; + $ch = curl_init(); + //Opening $file_zip to save the download + $fp = fopen("$file_name", "w"); + curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); + // set the cURL request to $url + curl_setopt($ch, CURLOPT_URL,$url); + curl_setopt($ch, CURLOPT_FAILONERROR, true); + //No headers + curl_setopt($ch, CURLOPT_HEADER,0); + //Follow redirects + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_AUTOREFERER, true); + curl_setopt($ch, CURLOPT_BINARYTRANSFER,true); + //timeout set to 30 seconds. File must finish downloading in this time. + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_FILE, $fp); + //execute request + $page = curl_exec($ch); + + //In case the download failed + if (!$page) { + //echo "
cURL error number:" .curl_errno($ch); + //echo "
cURL error:" . curl_error($ch); + curl_close($ch); + return false; + } + curl_close($ch); + return true; +} + +function updateVersion(){ + require_once 'lib/class.settings.php';require_once 'lib/class.github.php'; + $github = new GitHub('gugahoi','mediafrontpage'); + $commit = $github->getCommits(); + $commitNo = $commit['0']['sha']; + $config = new ConfigMagik('config.ini', true, true); + echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo; + try{ + $config->set('version', $commitNo, 'ADVANCED'); + echo " OK

"; + } catch (Exception $e){ + echo " ERROR

"; + } +} + +//download(); ?> From 0cbc5a9aa1f6688b5336f1e0599f54822b1072d3 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 12:20:54 +1000 Subject: [PATCH 37/66] Converted rrmdir return values. --- update.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) mode change 100644 => 100755 update.php diff --git a/update.php b/update.php old mode 100644 new mode 100755 index a5ecc9f..ffbbce8 --- a/update.php +++ b/update.php @@ -8,6 +8,12 @@ if(isset($_GET['unzip'] && $_GET['unzip']){ unzip($file_zip, 'update'); } + if(isset($_GET['update'] && $_GET['update']){ + updateVersion(); + } + if(isset($_GET['remove'] && $_GET['remove'] != false){ + rrmdir($_GET['remove']); + } } function main($url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'){ @@ -202,24 +208,29 @@ function rrmdir($dir, $remove = true) { foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir"){ - rrmdir($dir."/".$object); + if(rrmdir($dir."/".$object)){ + return true; + } else { + return false; + } } else { if(unlink($dir."/".$object)){ - echo ''.$dir."/".$object.' deleted successfully OK'; + //echo ''.$dir."/".$object.' deleted successfully OK'; + return true; } else { echo 'Could not delete file '.$dir."/".$object.'ERROR'; + return false; } } } } reset($objects); if($remove){ - if(rmdir($dir)){ - echo 'DIR: '.$dir.' deleted successfully OK'; - } else { - echo 'Could not delete dir '.$dir.'ERROR'; + if(!rmdir($dir)){ + return false; } } + return true; } } From a33295ae54d03c8ba9d4d76386cbed390a658f59 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 12:33:52 +1000 Subject: [PATCH 38/66] Added main table --- update.php | 204 ++++++++++++++++------------------------------------- 1 file changed, 61 insertions(+), 143 deletions(-) diff --git a/update.php b/update.php index ffbbce8..eced648 100755 --- a/update.php +++ b/update.php @@ -1,141 +1,5 @@ '; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; - echo '
-
-

MediaFrontPage Auto-Update

-
'; - - echo "Starting"; - - - echo "
Downloaded file from: $url"; - echo "
Saved as file: $file_zip"; - echo "
Starting unzip ..."; - - if(!unzip($file_zip, 'update')){ - echo 'Unzip failed'; - exit; - } - - $name = ''; - //Getting the name of the file. It should be the only file in the UPDATE directory for now. - //In the future I'd like to rename the update according to the PUSHED TIME or DOWNLOADED TIME. - if ($handle = opendir('update')) { - while (false !== ($file = readdir($handle))) { - if(strstr($file,'mediafrontpage')){ - $name = $file; - } - } - closedir($handle); - } - - $successful = true; - echo '

'; - echo '

'; - - if($successful){ - echo '

'; - echo '

'; - - //If the renaming went through smoothly, need to clean up the downloaded and backed up files. Otherwise, - //move the files back and tell user to update manually. - if($successful){ - echo "

UPDATE SUCCESSFULL


"; - echo "

'; - echo "

'; - updateVersion(); - } else { - echo "

UPDATE FAILED

"; - $dir = scandir('tmp/'); - echo "

Moving things back

"; - foreach($dir as $number=>$fileName){ - if($fileName != '..' && $fileName != '.'){ - if(rename('tmp/'.$fileName, './'.$fileName)){ - echo ''; - } else { - echo ''; - } - } - } - echo '
'.$fileName.' moved successfully OK
Could not move file '.$fileName.'ERROR
'; - } - echo '
'; -} - function unzip($file, $extractDir = 'update'){ //check if ZIP extension is loaded if (!extension_loaded('zip')) { @@ -260,10 +124,10 @@ function download($file_name = "update.zip"){ //echo "
cURL error number:" .curl_errno($ch); //echo "
cURL error:" . curl_error($ch); curl_close($ch); - return false; + echo false; } curl_close($ch); - return true; + echo true; } function updateVersion(){ @@ -272,14 +136,68 @@ function updateVersion(){ $commit = $github->getCommits(); $commitNo = $commit['0']['sha']; $config = new ConfigMagik('config.ini', true, true); - echo "

Updating commit number from: ".$config->get('version', 'ADVANCED')." -> ".$commitNo; try{ $config->set('version', $commitNo, 'ADVANCED'); - echo " OK

"; + echo true; } catch (Exception $e){ - echo " ERROR

"; + echo false; } } -//download(); -?> +if(!empty($_GET)){ + if(isset($_GET['download']) && $_GET['download']){ + download(); + } + if(isset($_GET['unzip']) && $_GET['unzip']){ + unzip($file_zip, 'update'); + } + if(isset($_GET['update']) && $_GET['update']){ + updateVersion(); + } + if(isset($_GET['remove']) && $_GET['remove'] != false){ + rrmdir($_GET['remove']); + } +} else { + $url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'; + ?> + + + UPDATING + + + + + + + +
+
+
+

MediaFrontPage Auto-Update

+
+ + + + + + + + + + +
Downloading latest version
Unziping archive
+
+
+ + + \ No newline at end of file From 78738b8eb59737c354ecc93e754c09d7b7692b6a Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 13:25:46 +1000 Subject: [PATCH 39/66] Added some javascript --- js/update.js | 21 +++++++++++++++++++++ update.php | 19 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 js/update.js diff --git a/js/update.js b/js/update.js new file mode 100755 index 0000000..268e3ee --- /dev/null +++ b/js/update.js @@ -0,0 +1,21 @@ +$(document).ready(function() { + ajaxRequest('download=true'); +}); + +function ajaxRequest(params){ + //alert(params); + $.ajax({ + type: 'GET', + url: "update.php?" + params, + success: function(data) { // successful request; do something with the data + if(data == 1){ + $("img#dl").attr('src','media/green-tick.png'); + } else { + $("img#dl").attr('src','media/red-cross.png'); + } + }, + error: function() { // failed request; give feedback to user + alert("Ajax error."); + } + }); +} \ No newline at end of file diff --git a/update.php b/update.php index eced648..53edbf4 100755 --- a/update.php +++ b/update.php @@ -164,6 +164,7 @@ function updateVersion(){ UPDATING + @@ -191,7 +192,23 @@ function toggle(id){ Unziping archive - + + + + Backing up old files + + + + Updating + + + + Cleaning up backup + + + + Cleaning up leftovers + From 62eee4282d70eb44056db0918a6f2d7bd7101189 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 14:03:08 +1000 Subject: [PATCH 40/66] more javascript. Downloading works. --- js/update.js | 19 ++++++++++++++----- update.php | 20 +++++++++++--------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/js/update.js b/js/update.js index 268e3ee..2a2f0ca 100755 --- a/js/update.js +++ b/js/update.js @@ -1,21 +1,30 @@ +var success = ''; $(document).ready(function() { - ajaxRequest('download=true'); + ajaxRequest('download=true', 'dl'); + if(success){ + alert('yes!'); + } }); -function ajaxRequest(params){ +function ajaxRequest(params, id){ //alert(params); $.ajax({ type: 'GET', url: "update.php?" + params, success: function(data) { // successful request; do something with the data if(data == 1){ - $("img#dl").attr('src','media/green-tick.png'); + $("img#"+id).attr('src','media/green-tick.png'); + success = true; } else { - $("img#dl").attr('src','media/red-cross.png'); + $("img#"+id).attr('src','media/red-cross.png'); + success = false; } }, error: function() { // failed request; give feedback to user alert("Ajax error."); - } + }, }); + + return $.ajax().responseText; + //document.getElementById('result').innerHTML = JSON.stringify(result);; } \ No newline at end of file diff --git a/update.php b/update.php index 53edbf4..4cf3606 100755 --- a/update.php +++ b/update.php @@ -6,24 +6,24 @@ function unzip($file, $extractDir = 'update'){ try{ dl('zip.so'); } catch(Exception $e){ - echo 'Could not load extension ZIP'; - exit; + //echo 'Could not load extension ZIP'; + echo false; return false; } } // Unzip the file $zip = new ZipArchive; if (!$zip) { - echo "
Could not make ZipArchive object."; - return false; + //echo "
Could not make ZipArchive object."; + echo false; return false; } if($zip->open("$file") != "true") { - echo "
Could not open $file."; - return false; + //echo "
Could not open $file."; + echo false;return false; } $zip->extractTo($extractDir); $zip->close(); - echo "

Unzipped file to: ".$extractDir.'

'; - return true; + //echo "

Unzipped file to: ".$extractDir.'

'; + echo true;return true; } /* @@ -99,6 +99,7 @@ function rrmdir($dir, $remove = true) { } function download($file_name = "update.zip"){ + $url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'; $userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; $ch = curl_init(); //Opening $file_zip to save the download @@ -180,7 +181,7 @@ function toggle(id){
-
+

MediaFrontPage Auto-Update

@@ -211,6 +212,7 @@ function toggle(id){ +
From 419a1f2ea9d4290e2e14c45b2e4ced5fb0220fc5 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:08:49 +1000 Subject: [PATCH 41/66] More javascript! --- js/update.js | 24 ++++++++++++++++-------- update.php | 30 ++++++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/js/update.js b/js/update.js index 2a2f0ca..b7029a3 100755 --- a/js/update.js +++ b/js/update.js @@ -1,9 +1,6 @@ -var success = ''; +var count = 0; $(document).ready(function() { ajaxRequest('download=true', 'dl'); - if(success){ - alert('yes!'); - } }); function ajaxRequest(params, id){ @@ -14,7 +11,8 @@ function ajaxRequest(params, id){ success: function(data) { // successful request; do something with the data if(data == 1){ $("img#"+id).attr('src','media/green-tick.png'); - success = true; + callNext(count); + count++; } else { $("img#"+id).attr('src','media/red-cross.png'); success = false; @@ -24,7 +22,17 @@ function ajaxRequest(params, id){ alert("Ajax error."); }, }); - - return $.ajax().responseText; - //document.getElementById('result').innerHTML = JSON.stringify(result);; + //document.getElementById('result').innerHTML = JSON.stringify(result); +} + +function callNext(i){ + if(i == 0){ + $("#zip").html(''); + ajaxRequest('unzip=true','unzip'); + } else if(i == 1){ + $("#backup").html(''); + ajaxRequest('move=true&src=.&dst=tmp','bp'); + } else { + alert('Finished'); + } } \ No newline at end of file diff --git a/update.php b/update.php index 4cf3606..047ecd0 100755 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ $fileName){ + if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp' && $fileName != 'update'){ + if(!rename($src.$fileName, $dst.$fileName)){ + echo false;return false; + } + } + } + echo true; return true; +} + /* /Function to clean up some leftover files. If files other than 'update' folder and 'update.zip' /are to be deleted, than the $extra variable and be used. If multiple files are to be deleted use @@ -150,7 +164,7 @@ function updateVersion(){ download(); } if(isset($_GET['unzip']) && $_GET['unzip']){ - unzip($file_zip, 'update'); + unzip(); } if(isset($_GET['update']) && $_GET['update']){ updateVersion(); @@ -158,6 +172,14 @@ function updateVersion(){ if(isset($_GET['remove']) && $_GET['remove'] != false){ rrmdir($_GET['remove']); } + if(isset($_GET['move']) && $_GET['move']){ + if(isset($_GET['src']) && isset($_GET['dst'])){ + moveDir($_GET['src'], $_GET['dst']); + } else { + echo false; return false; + } + } + } else { $url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'; ?> @@ -193,11 +215,11 @@ function toggle(id){ Unziping archive - +
Backing up old files - +
Updating From cc8ccb7083e1a161574386f4df20fd19f839ac8a Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:16:02 +1000 Subject: [PATCH 42/66] update section. --- js/update.js | 3 +++ update.php | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/js/update.js b/js/update.js index b7029a3..d7d2e0a 100755 --- a/js/update.js +++ b/js/update.js @@ -32,6 +32,9 @@ function callNext(i){ } else if(i == 1){ $("#backup").html(''); ajaxRequest('move=true&src=.&dst=tmp','bp'); + } else if(i == 2){ + $("#update").html(''); + ajaxRequest('moveupdate=true', 'up'); } else { alert('Finished'); } diff --git a/update.php b/update.php index 047ecd0..215cd49 100755 --- a/update.php +++ b/update.php @@ -40,6 +40,24 @@ function moveDir($src, $dst){ echo true; return true; } +function moveUpdate(){ + $name = ''; + if ($handle = opendir('update')) { + while (false !== ($file = readdir($handle))) { + if(strstr($file,'mediafrontpage')){ + $name = $file; + } + } + closedir($handle); + } + if($name != ''){ + if(moveDir($name, '.')){ + echo true; return true; + } + } + echo false; return false; +} + /* /Function to clean up some leftover files. If files other than 'update' folder and 'update.zip' /are to be deleted, than the $extra variable and be used. If multiple files are to be deleted use @@ -178,7 +196,11 @@ function updateVersion(){ } else { echo false; return false; } - } + } + if(isset($_GET['movenew']) && $_GET['movenew']){ + moveUpdate(); + } + } else { $url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'; @@ -223,7 +245,7 @@ function toggle(id){ Updating - +
Cleaning up backup From b00451d477c6d39d59bacae4e615ea99adf93e84 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:25:25 +1000 Subject: [PATCH 43/66] FInished js? --- js/update.js | 9 +++++++-- update.php | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/js/update.js b/js/update.js index d7d2e0a..0bb711f 100755 --- a/js/update.js +++ b/js/update.js @@ -31,10 +31,15 @@ function callNext(i){ ajaxRequest('unzip=true','unzip'); } else if(i == 1){ $("#backup").html(''); + $("#update").html(''); ajaxRequest('move=true&src=.&dst=tmp','bp'); } else if(i == 2){ - $("#update").html(''); - ajaxRequest('moveupdate=true', 'up'); + $("#update").html(''); + $("#clean-back").html(''); + ajaxRequest('cleanup=true&dir=tmp','cb'); + } else if(i == 3){ + $("#clean-left").html(''); + ajaxRequest('cleanup=true&dir=update','cu'); } else { alert('Finished'); } diff --git a/update.php b/update.php index 215cd49..acd6d0d 100755 --- a/update.php +++ b/update.php @@ -37,7 +37,10 @@ function moveDir($src, $dst){ } } } - echo true; return true; + if(moveUpdate()){ + echo true; return true; + } + echo false; return false; } function moveUpdate(){ @@ -52,10 +55,10 @@ function moveUpdate(){ } if($name != ''){ if(moveDir($name, '.')){ - echo true; return true; + return true; } } - echo false; return false; + return false; } /* @@ -197,8 +200,12 @@ function updateVersion(){ echo false; return false; } } - if(isset($_GET['movenew']) && $_GET['movenew']){ - moveUpdate(); + if(isset($_GET['cleanup']) && $_GET['cleanup']){ + if(isset($_GET['dir']) && $_GET['dir'] != ''){ + rrmdir($_GET['dir']); + } else { + echo false; return false; + } } @@ -249,11 +256,11 @@ function toggle(id){ Cleaning up backup - +
Cleaning up leftovers - +
From 4eb48ebc207b0f1db006e33e45614220c9028862 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:30:44 +1000 Subject: [PATCH 44/66] Found an error.... --- js/update.js | 1 - update.php | 57 +++++++++++----------------------------------------- 2 files changed, 12 insertions(+), 46 deletions(-) diff --git a/js/update.js b/js/update.js index 0bb711f..5d63c30 100755 --- a/js/update.js +++ b/js/update.js @@ -15,7 +15,6 @@ function ajaxRequest(params, id){ count++; } else { $("img#"+id).attr('src','media/red-cross.png'); - success = false; } }, error: function() { // failed request; give feedback to user diff --git a/update.php b/update.php index acd6d0d..922578f 100755 --- a/update.php +++ b/update.php @@ -26,7 +26,7 @@ function unzip($file = 'update.zip', $extractDir = 'update'){ echo true;return true; } -function moveDir($src, $dst){ +function moveDir($src, $dst, $update = true){ $src = $src.'/'; $dst = $dst.'/'; $updateContents = scandir($src); @@ -37,10 +37,15 @@ function moveDir($src, $dst){ } } } - if(moveUpdate()){ - echo true; return true; + if($update){ + if(moveUpdate()){ + echo true; return true; + } + else { + echo false; return false; + } } - echo false; return false; + echo true; return true; } function moveUpdate(){ @@ -54,51 +59,13 @@ function moveUpdate(){ closedir($handle); } if($name != ''){ - if(moveDir($name, '.')){ - return true; + if(moveDir($name, '.', false)){ + echo true; return true; } } - return false; + echo true; return false; } -/* -/Function to clean up some leftover files. If files other than 'update' folder and 'update.zip' -/are to be deleted, than the $extra variable and be used. If multiple files are to be deleted use -/$extra as an array. -/ -/return: false if nothing is deleted, a string with the deleted files otherwise. -*/ -function cleanUp($extra = ''){ - $return_value = ''; - if(file_exists('update')){ - if(@unlink('update')){ - $return_value .= '
update folder deleted'; - } - } - if(file_exists('update.zip')){ - if(@unlink('update.zip')){ - $return_value .= '
update.zip deleted'; - } - } - if($extra !== ''){ - if(is_array($extra)){ - foreach($extra as $x){ - if(@unlink($x)){ - $return_value = '
'.$x.' deleted'; - } - } - } else { - if(@unlink($extra)){ - $return_value = '
'.$extra.' deleted'; - } - } - } - if($return_value === ''){ - return false; - } else { - return $return_value; - } -} //Deletes directories and it's contents. If $remove is true, it will delete the directory otherwise, only it's contents. function rrmdir($dir, $remove = true) { From eae399ef873f40a17cd3e259772d10f7349bd3a4 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:34:14 +1000 Subject: [PATCH 45/66] Added some error feedback --- js/update.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/update.js b/js/update.js index 5d63c30..da2d168 100755 --- a/js/update.js +++ b/js/update.js @@ -15,6 +15,7 @@ function ajaxRequest(params, id){ count++; } else { $("img#"+id).attr('src','media/red-cross.png'); + document.getElementById('result').innerHTML = ' An ERROR occurred '+data; } }, error: function() { // failed request; give feedback to user From 9c6671820621176fc4752113df701dedcbee7644 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:42:42 +1000 Subject: [PATCH 46/66] Found the directory problem. --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/update.php b/update.php index 922578f..dd409e0 100755 --- a/update.php +++ b/update.php @@ -59,7 +59,7 @@ function moveUpdate(){ closedir($handle); } if($name != ''){ - if(moveDir($name, '.', false)){ + if(moveDir('update/'.$name, '.', false)){ echo true; return true; } } From 938cd212352396512a941fcaa00da117cf046666 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:48:22 +1000 Subject: [PATCH 47/66] Less echoing. --- update.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/update.php b/update.php index dd409e0..27bd815 100755 --- a/update.php +++ b/update.php @@ -33,7 +33,7 @@ function moveDir($src, $dst, $update = true){ foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp' && $fileName != 'update'){ if(!rename($src.$fileName, $dst.$fileName)){ - echo false;return false; + echo false; return false; } } } @@ -60,10 +60,10 @@ function moveUpdate(){ } if($name != ''){ if(moveDir('update/'.$name, '.', false)){ - echo true; return true; + return true; } } - echo true; return false; + return false; } From e62e8da5f72bf25d8fbb1ed5233335357b215810 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 15:50:29 +1000 Subject: [PATCH 48/66] Still a lot of 1's? --- update.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/update.php b/update.php index 27bd815..c1f1274 100755 --- a/update.php +++ b/update.php @@ -38,11 +38,8 @@ function moveDir($src, $dst, $update = true){ } } if($update){ - if(moveUpdate()){ - echo true; return true; - } - else { - echo false; return false; + if(!moveUpdate()){ + echo false; return false; exit; } } echo true; return true; From b7afeac31748fc51df6262cacab559dee11eed35 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 16:03:42 +1000 Subject: [PATCH 49/66] Moving new items --- js/update.js | 7 ++++--- update.php | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/js/update.js b/js/update.js index da2d168..cd2341b 100755 --- a/js/update.js +++ b/js/update.js @@ -31,13 +31,14 @@ function callNext(i){ ajaxRequest('unzip=true','unzip'); } else if(i == 1){ $("#backup").html(''); - $("#update").html(''); ajaxRequest('move=true&src=.&dst=tmp','bp'); } else if(i == 2){ - $("#update").html(''); + $("#update").html(''); + ajaxRequest('moveupdate=true','up'); + } else if(i == 3){ $("#clean-back").html(''); ajaxRequest('cleanup=true&dir=tmp','cb'); - } else if(i == 3){ + } else if(i == 4){ $("#clean-left").html(''); ajaxRequest('cleanup=true&dir=update','cu'); } else { diff --git a/update.php b/update.php index c1f1274..0e45da4 100755 --- a/update.php +++ b/update.php @@ -26,7 +26,7 @@ function unzip($file = 'update.zip', $extractDir = 'update'){ echo true;return true; } -function moveDir($src, $dst, $update = true){ +function moveDir($src, $dst){ $src = $src.'/'; $dst = $dst.'/'; $updateContents = scandir($src); @@ -37,11 +37,6 @@ function moveDir($src, $dst, $update = true){ } } } - if($update){ - if(!moveUpdate()){ - echo false; return false; exit; - } - } echo true; return true; } @@ -56,7 +51,7 @@ function moveUpdate(){ closedir($handle); } if($name != ''){ - if(moveDir('update/'.$name, '.', false)){ + if(moveDir('update/'.$name, '.')){ return true; } } @@ -164,6 +159,9 @@ function updateVersion(){ echo false; return false; } } + if(isset($_GET['moveupdate']) && $_GET['moveupdate']){ + moveUpdate(); + } if(isset($_GET['cleanup']) && $_GET['cleanup']){ if(isset($_GET['dir']) && $_GET['dir'] != ''){ rrmdir($_GET['dir']); From 199fc4b15ff073c78fec5bcbf8128c78c97577c5 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 16:16:18 +1000 Subject: [PATCH 50/66] Move update section. --- js/update.js | 26 ++++++++++++++++++++++++-- update.php | 4 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/js/update.js b/js/update.js index cd2341b..0561cac 100755 --- a/js/update.js +++ b/js/update.js @@ -34,7 +34,7 @@ function callNext(i){ ajaxRequest('move=true&src=.&dst=tmp','bp'); } else if(i == 2){ $("#update").html(''); - ajaxRequest('moveupdate=true','up'); + moveUpdate('moveupdate=true','up'); } else if(i == 3){ $("#clean-back").html(''); ajaxRequest('cleanup=true&dir=tmp','cb'); @@ -44,4 +44,26 @@ function callNext(i){ } else { alert('Finished'); } -} \ No newline at end of file +} + +function moveUpdate(params, id){ + //alert(params); + $.ajax({ + type: 'GET', + url: "tmp/update.php?" + params, + success: function(data) { // successful request; do something with the data + if(data == 1){ + $("img#"+id).attr('src','media/green-tick.png'); + callNext(count); + count++; + } else { + $("img#"+id).attr('src','media/red-cross.png'); + document.getElementById('result').innerHTML = ' An ERROR occurred '+data; + } + }, + error: function() { // failed request; give feedback to user + alert("Ajax error."); + }, + }); + //document.getElementById('result').innerHTML = JSON.stringify(result); +} diff --git a/update.php b/update.php index 0e45da4..66343d9 100755 --- a/update.php +++ b/update.php @@ -42,7 +42,7 @@ function moveDir($src, $dst){ function moveUpdate(){ $name = ''; - if ($handle = opendir('update')) { + if ($handle = opendir('../update')) { while (false !== ($file = readdir($handle))) { if(strstr($file,'mediafrontpage')){ $name = $file; @@ -51,7 +51,7 @@ function moveUpdate(){ closedir($handle); } if($name != ''){ - if(moveDir('update/'.$name, '.')){ + if(moveDir('../update/'.$name, '../')){ return true; } } From 76b8c32cfae04bff729d16b69b83e9e1850f853f Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 16:20:23 +1000 Subject: [PATCH 51/66] Clean up fix. --- update.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index 66343d9..a506cfa 100755 --- a/update.php +++ b/update.php @@ -164,7 +164,12 @@ function updateVersion(){ } if(isset($_GET['cleanup']) && $_GET['cleanup']){ if(isset($_GET['dir']) && $_GET['dir'] != ''){ - rrmdir($_GET['dir']); + if(rrmdir($_GET['dir'], false)){ + echo true; return true; + } else { + echo false; return false; + } + } else { echo false; return false; } From 915b3a70e30d742251f3334679f459a75dfa2bb8 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 22:53:56 +1000 Subject: [PATCH 52/66] Single returns. --- js/update.js | 2 +- update.php | 88 ++++++++++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 48 deletions(-) diff --git a/js/update.js b/js/update.js index 0561cac..e14059f 100755 --- a/js/update.js +++ b/js/update.js @@ -66,4 +66,4 @@ function moveUpdate(params, id){ }, }); //document.getElementById('result').innerHTML = JSON.stringify(result); -} +} \ No newline at end of file diff --git a/update.php b/update.php index a506cfa..04dd571 100755 --- a/update.php +++ b/update.php @@ -7,23 +7,23 @@ function unzip($file = 'update.zip', $extractDir = 'update'){ dl('zip.so'); } catch(Exception $e){ //echo 'Could not load extension ZIP'; - echo false; return false; + return false; } } // Unzip the file $zip = new ZipArchive; if (!$zip) { //echo "
Could not make ZipArchive object."; - echo false; return false; + return false; } if($zip->open("$file") != "true") { //echo "
Could not open $file."; - echo false;return false; + return false; } $zip->extractTo($extractDir); $zip->close(); //echo "

Unzipped file to: ".$extractDir.'

'; - echo true;return true; + return true; } function moveDir($src, $dst){ @@ -33,11 +33,11 @@ function moveDir($src, $dst){ foreach($updateContents as $number=>$fileName){ if($fileName != 'update' && $fileName != 'config.ini' && $fileName != 'layout.php' && $fileName != '..' && $fileName != '.' && $fileName != '.git' && $fileName != '.gitignore' && $fileName != 'tmp' && $fileName != 'update'){ if(!rename($src.$fileName, $dst.$fileName)){ - echo false; return false; + return false; } } } - echo true; return true; + return true; } function moveUpdate(){ @@ -76,7 +76,7 @@ function rrmdir($dir, $remove = true) { //echo ''.$dir."/".$object.' deleted successfully OK'; return true; } else { - echo 'Could not delete file '.$dir."/".$object.'ERROR'; + //echo 'Could not delete file '.$dir."/".$object.'ERROR'; return false; } } @@ -119,10 +119,10 @@ function download($file_name = "update.zip"){ //echo "
cURL error number:" .curl_errno($ch); //echo "
cURL error:" . curl_error($ch); curl_close($ch); - echo false; + return false; } curl_close($ch); - echo true; + return true; } function updateVersion(){ @@ -133,51 +133,52 @@ function updateVersion(){ $config = new ConfigMagik('config.ini', true, true); try{ $config->set('version', $commitNo, 'ADVANCED'); - echo true; + return true; } catch (Exception $e){ - echo false; + return false; } } if(!empty($_GET)){ if(isset($_GET['download']) && $_GET['download']){ - download(); + if(download()){ + echo true; return true; + } } - if(isset($_GET['unzip']) && $_GET['unzip']){ - unzip(); + elseif(isset($_GET['unzip']) && $_GET['unzip']){ + if(unzip()){ + echo true; return true; + } } - if(isset($_GET['update']) && $_GET['update']){ - updateVersion(); + elseif(isset($_GET['update']) && $_GET['update']){ + if(updateVersion()){ + echo true; return true; + } } - if(isset($_GET['remove']) && $_GET['remove'] != false){ - rrmdir($_GET['remove']); + elseif(isset($_GET['remove']) && $_GET['remove'] != false){ + if(rrmdir($_GET['remove'])){ + echo true; return true; + } } - if(isset($_GET['move']) && $_GET['move']){ + elseif(isset($_GET['move']) && $_GET['move']){ if(isset($_GET['src']) && isset($_GET['dst'])){ - moveDir($_GET['src'], $_GET['dst']); - } else { - echo false; return false; + if(moveDir($_GET['src'], $_GET['dst'])){ + echo true; return true; + } } } - if(isset($_GET['moveupdate']) && $_GET['moveupdate']){ + elseif(isset($_GET['moveupdate']) && $_GET['moveupdate']){ moveUpdate(); } - if(isset($_GET['cleanup']) && $_GET['cleanup']){ + elseif(isset($_GET['cleanup']) && $_GET['cleanup']){ if(isset($_GET['dir']) && $_GET['dir'] != ''){ if(rrmdir($_GET['dir'], false)){ echo true; return true; - } else { - echo false; return false; } - - } else { - echo false; return false; - } } - - + echo false; return false; exit; } else { - $url = 'https://nodeload.github.com/gugahoi/mediafrontpage/zipball/master'; + rrmdir('tmp', false); ?> @@ -188,13 +189,6 @@ function updateVersion(){ @@ -204,29 +198,29 @@ function toggle(id){

MediaFrontPage Auto-Update

- +
- + - + - + - + - + - +
Downloading latest versionDownloading latest version
Unziping archiveUnziping archive
Backing up old filesBacking up old files
UpdatingUpdating
Cleaning up backupCleaning up backup
Cleaning up leftoversCleaning up leftovers
From 462e8cba4e9e9799d4687549f724005092368198 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:00:09 +1000 Subject: [PATCH 53/66] Forgot one condition. --- update.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index 04dd571..a46a259 100755 --- a/update.php +++ b/update.php @@ -168,13 +168,16 @@ function updateVersion(){ } } elseif(isset($_GET['moveupdate']) && $_GET['moveupdate']){ - moveUpdate(); + if(moveUpdate()){ + echo true; return true; + } } elseif(isset($_GET['cleanup']) && $_GET['cleanup']){ if(isset($_GET['dir']) && $_GET['dir'] != ''){ if(rrmdir($_GET['dir'], false)){ echo true; return true; } + } } echo false; return false; exit; } else { From e0d7ab9d5858e75c3af96314ea2514ed4e0e64ba Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:12:21 +1000 Subject: [PATCH 54/66] Ceaning tmp and update folder before the start of the updating process to be safe. --- update.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/update.php b/update.php index a46a259..cc4d981 100755 --- a/update.php +++ b/update.php @@ -62,7 +62,8 @@ function moveUpdate(){ //Deletes directories and it's contents. If $remove is true, it will delete the directory otherwise, only it's contents. function rrmdir($dir, $remove = true) { if (is_dir($dir)) { - $objects = scandir($dir); + $objects = scandir($dir); + //echo '
';print_r($objects);echo '
'; foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir"){ @@ -182,6 +183,7 @@ function updateVersion(){ echo false; return false; exit; } else { rrmdir('tmp', false); + rrmdir('update',false); ?> From d86f244c1429507a4fe3426172ad275f82dfc9d1 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:21:44 +1000 Subject: [PATCH 55/66] Finally cleaning up... --- update.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/update.php b/update.php index cc4d981..fbe0869 100755 --- a/update.php +++ b/update.php @@ -63,21 +63,17 @@ function moveUpdate(){ function rrmdir($dir, $remove = true) { if (is_dir($dir)) { $objects = scandir($dir); - //echo '
';print_r($objects);echo '
'; + echo '
';print_r($objects);echo '
'; foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir"){ - if(rrmdir($dir."/".$object)){ - return true; - } else { + if(!rrmdir($dir."/".$object, true)){ + echo 'Could not delete directory '.$dir."/".$object.'ERROR
'; return false; } } else { - if(unlink($dir."/".$object)){ - //echo ''.$dir."/".$object.' deleted successfully OK'; - return true; - } else { - //echo 'Could not delete file '.$dir."/".$object.'ERROR'; + if(!unlink($dir."/".$object)){ + echo 'Could not delete file '.$dir."/".$object.'ERROR
'; return false; } } @@ -85,12 +81,14 @@ function rrmdir($dir, $remove = true) { } reset($objects); if($remove){ - if(!rmdir($dir)){ + if(rmdir($dir)){ + return true; + } else { return false; } } - return true; - } + } + return true; } function download($file_name = "update.zip"){ From acb23fb067404ba85ea68cb119a929107ece5dc8 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:22:50 +1000 Subject: [PATCH 56/66] Forgot to comment out something silly. --- update.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100755 => 100644 update.php diff --git a/update.php b/update.php old mode 100755 new mode 100644 index fbe0869..a296e75 --- a/update.php +++ b/update.php @@ -63,7 +63,7 @@ function moveUpdate(){ function rrmdir($dir, $remove = true) { if (is_dir($dir)) { $objects = scandir($dir); - echo '
';print_r($objects);echo '
'; + //echo '
';print_r($objects);echo '
'; foreach ($objects as $object) { if ($object != "." && $object != "..") { if (filetype($dir."/".$object) == "dir"){ From c2ce031f3ed75e137197c5d67086ca1181014e37 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:41:20 +1000 Subject: [PATCH 57/66] Updating commit number. --- js/update.js | 3 +++ update.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/js/update.js b/js/update.js index e14059f..9c0b3c5 100755 --- a/js/update.js +++ b/js/update.js @@ -41,6 +41,9 @@ function callNext(i){ } else if(i == 4){ $("#clean-left").html(''); ajaxRequest('cleanup=true&dir=update','cu'); + } else if(i == 5){ + $("#commit").html(''); + ajaxRequest('update=true','com'); } else { alert('Finished'); } diff --git a/update.php b/update.php index a296e75..aeafb56 100644 --- a/update.php +++ b/update.php @@ -226,6 +226,10 @@ function updateVersion(){ Cleaning up leftovers
+ + Updating commit number +
+
From 4f478916cec9d36bbcd33b52cdec73e3a31efb3d Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:54:31 +1000 Subject: [PATCH 58/66] Updated settings page. --- settings.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) mode change 100755 => 100644 settings.php diff --git a/settings.php b/settings.php old mode 100755 new mode 100644 index 07c4337..917c57f --- a/settings.php +++ b/settings.php @@ -147,8 +147,9 @@ getInfo(); - echo $date['pushed_at']; - ?> + $currentVersion = $config->get('version','ADVANCED'); + $updateddate = str_replace(array("T","Z"), " ", $date['pushed_at']); + echo "Time: ".substr($updateddate,11,20)." Date: ".substr($updateddate,0,10).""; ?> @@ -156,14 +157,17 @@ getCommits(); $commitNo = $commit['0']['sha']; - $currentVersion = $config->get('version','ADVANCED'); - echo "Version ".$currentVersion.''; - if($commitNo != $currentVersion){ - echo "\t***UPDATE Available***"; - } + echo "Version ".$currentVersion.""; ?> + + "; + } + ?> +


From 328ead87fb5cf16229fde70b1a7c0fff864ca06a Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:56:53 +1000 Subject: [PATCH 59/66] Forgot 's --- settings.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/settings.php b/settings.php index 917c57f..cee390f 100644 --- a/settings.php +++ b/settings.php @@ -153,21 +153,23 @@ - + Version getCommits(); $commitNo = $commit['0']['sha']; - echo "Version ".$currentVersion.""; + echo "".$currentVersion.""; ?> - + + "; } ?> - + +


From 551fbdad1600e9649f1beccd20cde2905fa3d2bb Mon Sep 17 00:00:00 2001 From: gugahoi Date: Thu, 11 Aug 2011 23:59:15 +1000 Subject: [PATCH 60/66] Oh man, another silly one. update.html -> update.php --- settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.php b/settings.php index cee390f..b90fa56 100644 --- a/settings.php +++ b/settings.php @@ -165,7 +165,7 @@ "; + echo ""; } ?> From 891ef77fd3616ffa7927e8a7798bb309e9031cc2 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 14 Aug 2011 19:05:09 +1000 Subject: [PATCH 61/66] Redirecting after successfull update. --- js/update.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/update.js b/js/update.js index 9c0b3c5..78d5c0d 100755 --- a/js/update.js +++ b/js/update.js @@ -45,7 +45,8 @@ function callNext(i){ $("#commit").html(''); ajaxRequest('update=true','com'); } else { - alert('Finished'); + $("#result").html('

Update successfull

You will be redirected in a few seconds.'); + window.location.href = window.top.location.reload(); } } From ca41d15c257052982ef215edc0640830e9ebf3a2 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 14 Aug 2011 19:08:11 +1000 Subject: [PATCH 62/66] Skipping first run when config.ini already exists. --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index 9e07513..1f75caa 100755 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ Date: Sun, 14 Aug 2011 19:38:08 +1000 Subject: [PATCH 63/66] Added first version of jDownloader widget. --- widgets/wjDownloader.php | 197 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 widgets/wjDownloader.php diff --git a/widgets/wjDownloader.php b/widgets/wjDownloader.php new file mode 100644 index 0000000..cd0d2b3 --- /dev/null +++ b/widgets/wjDownloader.php @@ -0,0 +1,197 @@ + "jDownloader", "type" => "ajax", "block" => "jdownloaderwrapper", "headerfunction" => "widgetjDHeader();", "call" => "widgets/wjDownloader.php?style=w", "interval" => 10000); + +function widgetjDHeader() { + echo <<< JDHEADER + +JDHEADER; +} + +function widgetjDownloader(){ + + try{ + $speed = getInfoDownloader("get/speed"); + $status = getInfoDownloader("get/downloadstatus"); + $speedLimit = getInfoDownloader("get/speedlimit"); + //echo $speed.'
'.$status.'
'.$speedLimit; + $action=""; + + switch($status){ + case 'RUNNING': + $status="Downloading @".$speed." kB/s"; + $action = "stop"; + break; + case 'STOPPING': + $status="Stopping"; + break; + case 'NOT_RUNNING': + $status="Stopped"; + $action = "start"; + break; + } + + echo "".$status.""; + + $dlList = getInfoDownloader("get/downloads/alllist"); + if($dlList){ + $doc = new DOMDocument(); + $doc->loadXML($dlList); + } + else{ + echo "ERROR! $dlList"; + return false; + } + + if(is_object($doc->getElementsByTagName('jdownloader'))) + { + if(is_object($doc->getElementsByTagName('package'))) + { + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + $package = $doc->getElementsByTagName('package'); + foreach($package as $item){ + $progress = $item->getAttribute('package_linksinprogress'); + $eta = $item->getAttribute('package_ETA'); + $total = $item->getAttribute('package_linkstotal'); + $loaded = $item->getAttribute('package_loaded'); + $name = $item->getAttribute('package_name'); + $percent = $item->getAttribute('package_percent'); + $size = $item->getAttribute('package_size'); + $speed = $item->getAttribute('package_speed'); + $todo = $item->getAttribute('package_todo'); + + //echo "$name | $eta | $progress | $total | $loaded | $percent | $size | $speed | $todo"; + + $colour = "green"; + if(intval($progress) == 0){ + $colour = "red"; + } + $popup = "

Name: $name

"; + $popup .= "

ETA: $eta

"; + $popup .= "

Links: $progress of $total

"; + $popup .= "

Size: $size

"; + $popup .= "

Name: $name

"; + + $pack = $name; + + echo ""; + echo ""; + echo ""; + echo ""; + + $file = $item->getElementsByTagName('file'); + foreach($file as $sub){ + $hoster = $sub->getAttribute('file_hoster'); + $subname = $sub->getAttribute('file_name'); + $package = $sub->getAttribute('file_package'); + $peercent = $sub->getAttribute('file_percent'); + $speed = $sub->getAttribute('file_speed'); + $status = $sub->getAttribute('file_status'); + + $colour = "green"; + if(intval($speed) == 0){ + $colour = "red"; + } + + + echo ""; + echo ""; + echo ""; + echo ""; + + } + echo ""; + } + echo "
"; + echo "\t\t\t\t
"; + echo "\t\t\t\t\t
"; + echo "\t\t\t\t\t
$name $loaded of $size @ $speed
"; + echo "\t\t\t\t
"; + echo "\t\t\t
"; + echo "
"; + echo "\t\t\t\t
"; + echo "\t\t\t\t\t
"; + echo "\t\t\t\t\t
".$subname." $loaded of $size @ $speed
"; + echo "\t\t\t\t
"; + echo "\t\t\t
"; + echo "
"; + } + } + } + catch(Exception $e){ + echo $e; + } +} +function getInfoDownloader($param = ""){ + global $jd_url; + + if(!empty($param)){ + $url = $jd_url.$param; + } + else{ + echo false; + return false; + } + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPGET, 1); + curl_setopt($ch, CURLOPT_URL, $url); + + $response = curl_exec($ch); + curl_close($ch); + + return $response; +} + +if(!empty($_GET['action'])){ + if($_GET['action'] == "start"){ + $x = getInfoDownloader("action/start"); + echo "$x"; + } + elseif($_GET['action'] == "stop"){ + $x = getInfoDownloader("action/stop"); + echo "$x"; + } +} + +if(!empty($_GET['style']) && ($_GET['style'] == "w")) { + require_once "../config.php"; + if($_GET['style'] == "w") { +?> + + + Media Front Page - jDownloader + + + + + + + From 62112027e39dacd26315c59053fd607a27e9aacc Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 14 Aug 2011 19:49:59 +1000 Subject: [PATCH 64/66] Fixed stop/start entire queue. --- widgets/wjDownloader.php | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/wjDownloader.php b/widgets/wjDownloader.php index cd0d2b3..33809ed 100644 --- a/widgets/wjDownloader.php +++ b/widgets/wjDownloader.php @@ -164,6 +164,7 @@ function getInfoDownloader($param = ""){ } if(!empty($_GET['action'])){ + require_once "../config.php"; if($_GET['action'] == "start"){ $x = getInfoDownloader("action/start"); echo "$x"; From 944817d06b8964c33e48657fc352f9ea9d0f264c Mon Sep 17 00:00:00 2001 From: gugahoi Date: Sun, 14 Aug 2011 19:56:48 +1000 Subject: [PATCH 65/66] Updated default-layout to add jDownloader and start with system and trakt widgets collapsed. --- default-layout.php | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/default-layout.php b/default-layout.php index 607b782..f2b514e 100755 --- a/default-layout.php +++ b/default-layout.php @@ -11,10 +11,6 @@ "title" => "XBMC Library", "display" => "" ), - "wControl" => array( - "title" => "Control", - "display" => "" - ), "wRecentTV" => array( "title" => "Recent TV", "display" => "" @@ -22,7 +18,7 @@ "wRecentMovies" => array( "title" => "Recent Movies", "display" => "" - ) + ), ), "section3" => array( "wSearch" => array( @@ -36,13 +32,13 @@ "wHardDrives" => array( "title" => "Hard Drives", "display" => "" + ), + "wControl" => array( + "title" => "Control", + "display" => "" ) ), "section4" => array( - "wNowPlaying" => array( - "title" => "Now Playing", - "display" => "" - ), "wTransmission" => array( "title" => "Transmission", "display" => "" @@ -51,18 +47,26 @@ "title" => "Sabnzbd", "display" => "" ), + "wjDownloader" => array( + "title" => "jDownloader", + "display" => "" + ), "wMessage" => array( "title" => "XBMC Message", "display" => "" ), + "wNowPlaying" => array( + "title" => "Now Playing", + "display" => "" + ), "wTrakt" => array( "title" => "trakt.tv", - "display" => "" + "display" => "collapsed" ), "wSystem" => array( "title" => "System info", - "display" => "" - ) + "display" => "collapsed" + ), ) ); From b489383de8b28f0c391271ca8a3420492beca823 Mon Sep 17 00:00:00 2001 From: gugahoi Date: Fri, 19 Aug 2011 17:17:36 +1000 Subject: [PATCH 66/66] ComingEpisodes Lunias' Fix --- widgets/wComingEpisodes.php | 41 ++++--------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/widgets/wComingEpisodes.php b/widgets/wComingEpisodes.php index 7acc80d..2dce53a 100755 --- a/widgets/wComingEpisodes.php +++ b/widgets/wComingEpisodes.php @@ -151,7 +151,9 @@ function adjustHeight() { if(!empty($_GET["display"])) { include_once "../config.php"; - $body = getComingSoon($sickbeardcomingepisodes); + $html = getComingSoon($sickbeardcomingepisodes); + $body = stripBody($html); + $body = stripInnerWrapper($body); $urldata = @parse_url($sickbeardcomingepisodes); if(empty($urldata)){echo 'Sickbeard could not be reached. Please check if the URL is correct.';} @@ -197,7 +199,7 @@ function stripBody($body) { return $body; } function stripInnerWrapper($body) { - $pos = strpos($body, "

Coming Episodes

"); + $pos = strpos($body, "

"); if ($pos > 0) { $body = substr($body, $pos); $pos = strpos($body, "