Plugin version and updates

This commit is contained in:
Diego Najar 2017-06-29 22:13:25 +02:00
parent b1b0d6013d
commit a4e143151d
5 changed files with 26 additions and 10 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.DS_Store .DS_Store
bl-content/* bl-content/*
bl-plugins/timemachine bl-plugins/timemachine
bl-kernel/bludit.pro.php

View File

@ -187,6 +187,11 @@ include(PATH_HELPERS.'paginator.class.php');
include(PATH_HELPERS.'image.class.php'); include(PATH_HELPERS.'image.class.php');
include(PATH_HELPERS.'tcp.class.php'); include(PATH_HELPERS.'tcp.class.php');
// Include Bludit PRO
if( file_exists(PATH_KERNEL.'bludit.pro.php') ) {
include(PATH_KERNEL.'bludit.pro.php');
}
// Session // Session
Session::start(); Session::start();
if(Session::started()===false) { if(Session::started()===false) {

View File

@ -54,4 +54,8 @@ class Filesystem {
return unlink($filename); return unlink($filename);
} }
public static function fileExists($filename)
{
return file_exists($filename);
}
} }

View File

@ -2,7 +2,7 @@
class TCP { class TCP {
public static function http($url, $method='GET', $verifySSL=true) public static function http($url, $method='GET', $verifySSL=true, $timeOut=1)
{ {
if( function_exists('curl_version') ) { if( function_exists('curl_version') ) {
$ch = curl_init(); $ch = curl_init();
@ -10,6 +10,8 @@ class TCP {
// TRUE to include the header in the output // TRUE to include the header in the output
curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verifySSL);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeOut);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
if($method=='POST') { if($method=='POST') {
curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POST, true);
} }
@ -22,7 +24,8 @@ class TCP {
else { else {
$options = array( $options = array(
'http'=>array( 'http'=>array(
'method'=>$method 'method'=>$method,
'timeout'=>$timeOut
), ),
"ssl"=>array( "ssl"=>array(
"verify_peer"=>$verifySSL, "verify_peer"=>$verifySSL,

View File

@ -28,19 +28,23 @@ class pluginVersion extends Plugin {
{ {
global $ADMIN_CONTROLLER; global $ADMIN_CONTROLLER;
$timeToCheck = time() + 10; $timeToCheck = Session::get('timeToCheck') + 10*60;
if( ($ADMIN_CONTROLLER=='dashboard') && (Session::get('timeToCheck')>$timeToCheck) ) { if( ($ADMIN_CONTROLLER=='dashboard') && ($timeToCheck<time()) ) {
//$versions = $this->getVersion(); $versions = $this->getVersion();
$versions = array('latest'=>'2.1'); $versions = array('latest'=>'2.0');
Session::set('timeToCheck', $timeToCheck); Session::set('timeToCheck', time());
Session::set('latestVersion', $versions['latest']); Session::set('latestVersion', $versions['latest']);
} }
if( version_compare(Session::get('latestVersion'), BLUDIT_VERSION, '>') ) { if( version_compare(Session::get('latestVersion'), BLUDIT_VERSION, '>') ) {
$html = '<div id="plugin-version"><a href="https://www.bludit.com">New version available</a></div>'; $html = '<div id="plugin-version"><a href="https://www.bludit.com">New version available</a></div>';
} else {
if(BLUDIT_PRO) {
$html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else { } else {
$html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="">Upgrade to Bludit PRO</a></div>'; $html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="">Upgrade to Bludit PRO</a></div>';
} }
}
return $html; return $html;
} }
@ -48,12 +52,11 @@ class pluginVersion extends Plugin {
private function getVersion() private function getVersion()
{ {
$url = 'https://version.bludit.com'; $url = 'https://version.bludit.com';
$output = TCP::http($url); $output = TCP::http($url);
$json = json_decode($output, true); $json = json_decode($output, true);
if(empty($json)) { if(empty($json)) {
return array('version'=>''); return array('latest'=>'');
} }
return $json; return $json;