bludit/bl-plugins/version/plugin.php

63 lines
1.3 KiB
PHP
Raw Normal View History

<?php
class pluginVersion extends Plugin {
2017-06-28 22:27:17 +02:00
public function adminHead()
{
$html = '<style>
#plugin-version {
display: block;
position: fixed;
bottom: 0;
right: 0;
background: #eee;
padding: 2px 10px;
font-size: 0.9em;
color: #555;
}
#plugin-version a {
color: #777;
margin-left: 8px;
}
</style>';
return $html;
}
public function adminBodyEnd()
{
global $ADMIN_CONTROLLER;
2017-06-29 22:13:25 +02:00
$timeToCheck = Session::get('timeToCheck') + 10*60;
if( ($ADMIN_CONTROLLER=='dashboard') && ($timeToCheck<time()) ) {
$versions = $this->getVersion();
Session::set('timeToCheck', time());
2017-08-08 00:55:14 +02:00
Session::set('version', $versions['version']);
2017-06-28 22:27:17 +02:00
}
2017-08-08 00:55:14 +02:00
if( version_compare(Session::get('version'), BLUDIT_VERSION, '>') ) {
2017-06-28 22:27:17 +02:00
$html = '<div id="plugin-version"><a href="https://www.bludit.com">New version available</a></div>';
} else {
2017-07-02 22:46:05 +02:00
if(defined('BLUDIT_PRO')) {
2017-06-29 22:13:25 +02:00
$html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else {
$html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="">Upgrade to Bludit PRO</a></div>';
}
2017-06-28 22:27:17 +02:00
}
return $html;
}
private function getVersion()
{
$url = 'https://version.bludit.com';
$output = TCP::http($url);
$json = json_decode($output, true);
2017-08-08 00:55:14 +02:00
if (empty($json['stable'])) {
2017-08-03 23:28:32 +02:00
return false;
}
2017-08-08 00:55:14 +02:00
return $json['stable'];
}
}