Bug fixes and AJAX implementation for version plugin

This commit is contained in:
Diego Najar 2018-03-06 23:50:31 +01:00
parent 74a15685c9
commit a396ed137a
5 changed files with 68 additions and 49 deletions

View File

@ -66,16 +66,6 @@
<h4 class="panel-title"><?php $L->p('Notifications') ?></h4> <h4 class="panel-title"><?php $L->p('Notifications') ?></h4>
<ul class="uk-list uk-list-line"> <ul class="uk-list uk-list-line">
<?php <?php
// Print New version if the plugin Version is installed
if (pluginEnabled('pluginVersion')) {
if ($plugins['all']['pluginVersion']->newVersion()) {
echo '<li>';
echo '<b>'.$L->g('New version available').'</b>';
echo '<br><a href="https://www.bludit.com" target="_black">Bludit.com</a>';
echo '</li>';
}
}
// Print Notifications // Print Notifications
$logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT); $logs = array_slice($Syslog->db, 0, NOTIFICATIONS_AMOUNT);
foreach($logs as $log) { foreach($logs as $log) {

View File

@ -9,6 +9,9 @@ echo 'var HTML_PATH_UPLOADS = "'.HTML_PATH_UPLOADS.'";'.PHP_EOL;
echo 'var HTML_PATH_UPLOADS_THUMBNAILS = "'.HTML_PATH_UPLOADS_THUMBNAILS.'";'.PHP_EOL; echo 'var HTML_PATH_UPLOADS_THUMBNAILS = "'.HTML_PATH_UPLOADS_THUMBNAILS.'";'.PHP_EOL;
echo 'var PARENT = "'.PARENT.'";'.PHP_EOL; echo 'var PARENT = "'.PARENT.'";'.PHP_EOL;
echo 'var BLUDIT_VERSION = "'.BLUDIT_VERSION.'";'.PHP_EOL;
echo 'var BLUDIT_BUILD = "'.BLUDIT_BUILD.'";'.PHP_EOL;
echo 'var tokenCSRF = "'.$Security->getTokenCSRF().'";'.PHP_EOL; echo 'var tokenCSRF = "'.$Security->getTokenCSRF().'";'.PHP_EOL;
echo '</script>'; echo '</script>';

View File

@ -0,0 +1,23 @@
function getLatestVersion() {
$("#current-version").show();
$.ajax({
url: "https://version.bludit.com",
method: "GET",
dataType: 'json',
success: function(json) {
// Constant BLUDIT_BUILD is defined on functions.js
if (json.stable.build > BLUDIT_BUILD) {
$("#current-version").hide();
$("#new-version").show();
}
},
error: function(json) {
console.log("Error when try to get the version.");
}
});
}
getLatestVersion();

View File

@ -19,51 +19,38 @@ class pluginVersion extends Plugin {
color: #777; color: #777;
margin-left: 8px; margin-left: 8px;
} }
#new-version,
#current-version {
display: none;
}
</style>'; </style>';
return $html; return $html;
} }
public function adminBodyBegin()
{
global $Language;
$html = '<div id="plugin-version">';
$html .= '<div id="new-version"><a target="_blank" href="https://www.bludit.com"><i class="fa fa-download" aria-hidden="true"></i> '.$Language->get('New version available').'</a></div>';
if (defined('BLUDIT_PRO')) {
$html .= '<div id="current-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else {
$html .= '<div id="current-version">Bludit v'.BLUDIT_VERSION.'<a target="_blank" href="https://pro.bludit.com">'.$Language->get('Upgrade to Bludit PRO').'</a></div>';
}
$html .= '</div>';
$html .= '</div>';
return $html;
}
public function adminBodyEnd() public function adminBodyEnd()
{ {
global $ADMIN_CONTROLLER; $jsPath = $this->phpPath() . 'js' . DS;
global $Language; $scripts = '<script>' . file_get_contents($jsPath . 'version.js') . '</script>';
return $scripts;
$timeToCheck = Session::get('timeToCheck') + 10*60;
if( ($ADMIN_CONTROLLER=='dashboard') && ($timeToCheck<time()) ) {
$versions = $this->getVersion();
Session::set('timeToCheck', time());
Session::set('version', $versions['version']);
}
if ($this->newVersion()) {
$html = '<div id="plugin-version"><a target="_blank" href="https://www.bludit.com"><i class="fa fa-download" aria-hidden="true"></i> '.$Language->get('New version available').'</a></div>';
} else {
if(defined('BLUDIT_PRO')) {
$html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else {
$html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a target="_blank" href="https://pro.bludit.com">'.$Language->get('Upgrade to Bludit PRO').'</a></div>';
}
}
return $html;
}
public function newVersion()
{
return version_compare(Session::get('version'), BLUDIT_VERSION, '>');
}
private function getVersion()
{
$url = 'https://version.bludit.com';
$output = TCP::http($url);
$json = json_decode($output, true);
if (empty($json['stable'])) {
return false;
}
return $json['stable'];
} }
} }

View File

@ -306,6 +306,11 @@ function install($adminPassword, $email='', $timezone)
error_log($errorText, 0); error_log($errorText, 0);
} }
if (!mkdir(PATH_PLUGINS_DATABASES.'version', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'version';
error_log($errorText, 0);
}
// UPLOADS directories // UPLOADS directories
if (!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true)) { if (!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_PROFILES; $errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_PROFILES;
@ -545,6 +550,17 @@ function install($adminPassword, $email='', $timezone)
LOCK_EX LOCK_EX
); );
// File plugins/version/db.php
file_put_contents(
PATH_PLUGINS_DATABASES.'version'.DS.'db.php',
$dataHead.json_encode(
array(
'position'=>1
),
JSON_PRETTY_PRINT),
LOCK_EX
);
// Page create-your-own-content // Page create-your-own-content
$data = 'Title: '.$Language->get('example-page-1-title').PHP_EOL.'Content: '.PHP_EOL.$Language->get('example-page-1-content'); $data = 'Title: '.$Language->get('example-page-1-title').PHP_EOL.'Content: '.PHP_EOL.$Language->get('example-page-1-content');
file_put_contents(PATH_PAGES.$Language->get('example-page-1-slug').DS.FILENAME, $data, LOCK_EX); file_put_contents(PATH_PAGES.$Language->get('example-page-1-slug').DS.FILENAME, $data, LOCK_EX);