Last active
January 7, 2018 21:42
-
-
Save yordanoff/ec0ef6e2357201711cb4369857a7de3e to your computer and use it in GitHub Desktop.
Kirby CMS: Dashboard Widget Messages via JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--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 ?> →</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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