Skip to content

Instantly share code, notes, and snippets.

@yordanoff
Last active January 7, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yordanoff/ec0ef6e2357201711cb4369857a7de3e to your computer and use it in GitHub Desktop.
Save yordanoff/ec0ef6e2357201711cb4369857a7de3e to your computer and use it in GitHub Desktop.
Kirby CMS: Dashboard Widget Messages via JSON
<!--Print Information -->
<p>Current version: <strong><?= $localVersion ?></strong></p>
<?php if( $localVersion < $currentVersion ): ?>
<div class="upgrade">
<p>There is a newer version of Raport available<p>
<a href="<?= $upgradeURL ?>" target="_blank">
Update now to <strong>version <?= $currentVersion ?> &rarr;</strong></a>
</div>
<?php else: ?>
<div class="ok">You are using the latest version. Enjoy!</div>
<?php endif ?>
<?php
// Custom Message
// ------------------------------------
if( $customMessage != '' ): ?>
<div><?= $customMessage ?></div>
<?php endif ?>
<style>
.upgrade {
border: 1px solid #e57910;
color: #e57910;
padding: 10px;
border-radius: 3px;
text-align: center;
margin: 10px 0;
clear: both;
line-height: 1.5;
}
.ok {
border: 1px solid green;
padding: 10px;
border-radius: 3px;
text-align: center;
margin: 10px 0;
clear: both;
color: green;
line-height: 1.5;
}
</style>
<?php
return array(
'title' => 'Raport Version',
'html' => function() {
// Fetch Information
// ------------------------------------
$url = 'http://example.com/raport-version.json';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$arr = json_decode($data, true);
// load template and pass variables to it
return tpl::load(__DIR__ . DS . 'raport.html.php', [
'customMessage' => $arr['custom_message'],
'currentVersion' => $arr['current_version'],
'upgradeURL' => $arr['upgrade_url'],
'localVersion' => floatval(kirby()->site()->raportVersion()->value()),
'needUpdate' => false
]);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment