Skip to content

Commit

Permalink
Automatically download library.zip when missed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodim99 committed Oct 26, 2017
1 parent 13ee7ed commit 5e0c925
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cms/include/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ function curl_reset(&$ch){

if (!file_exists(DOCROOT.LIBRARY_PATH)) {

echo 'Download and unpack <a href="http://cetera.ru/cetera_cms/library.zip">http://cetera.ru/cetera_cms/library.zip</a> at your webserver home folder.';
echo 'Download and unpack <a href="http://cetera.ru/cetera_cms/library.zip">http://cetera.ru/cetera_cms/library.zip</a> at your webserver home folder. ';
echo '<a href="/cms/library_install.php">Click to automatic install</a>';
die();

}
Expand Down
58 changes: 58 additions & 0 deletions cms/library_install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?
require_once(__DIR__.'/include/constants.php');

if (file_exists(DOCROOT.LIBRARY_PATH)) {
header('Location: /cms/');
die();
}

try {
echo 'Trying to download '.LIBRARY_FILE.' ... ';
download_file(LIBRARY_FILE);
echo 'OK<br>';

echo 'Extracting archive ... ';
$zip = new \ZipArchive;
$zip->open(LIBRARY_FILE);
$zip->extractTo(DOCROOT);
unlink(LIBRARY_FILE);
echo 'OK<br>';

echo 'Redirect to backoffice ... ';
header('Location: /cms/');
die();

} catch (\Exception $e) {
print 'FAIL.<br>';
print $e->getMessage();
}

function download_file($file, $local = false) {
if (!$local) $local = $file;

$d = curl_get(DISTRIB_HOST.$file);
if (!$d) return false;
file_put_contents($local, $d);
return true;

}

function curl_get($url) {
$defaults = array(
CURLOPT_URL => $url,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
//CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
//CURLOPT_TIMEOUT => 4
);

$ch = curl_init();
curl_setopt_array($ch, $defaults);
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}

0 comments on commit 5e0c925

Please sign in to comment.