Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
cache of news/version retrieval in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabeel Shahzad committed Apr 13, 2011
1 parent ce48396 commit 0fa6ee1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 29 deletions.
73 changes: 44 additions & 29 deletions admin/modules/Dashboard/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,42 @@ public function CheckInstallFolder() {
*/
public function CheckForUpdates() {
if (Config::Get('CHECK_RELEASE_VERSION') == true) {
$url = Config::Get('PHPVMS_API_SERVER') . '/version/get/xml/' . PHPVMS_VERSION;

# Default to fopen(), if that fails it'll use CURL
$file = new CodonWebService();
$contents = @$file->get($url);

# Something should have been returned
if ($contents == '') {
$msg = '<br /><b>Error:</b> The phpVMS update server could not be contacted.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';

$this->set('latestnews', $msg);
return;
}


$xml = @simplexml_load_string($contents);

if (!$xml) {
$msg = '<br /><b>Error:</b> There was an error retrieving news. It may be temporary.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';

$this->set('latestnews', $msg);
return;

$key = 'PHPVMS_LATEST_VERSION';
$feed = CodonCache::read($key);

if ($feed === false) {

$url = Config::Get('PHPVMS_API_SERVER') . '/version/get/xml/' . PHPVMS_VERSION;

# Default to fopen(), if that fails it'll use CURL
$file = new CodonWebService();
$contents = @$file->get($url);

# Something should have been returned
if ($contents == '') {
$msg = '<br /><b>Error:</b> The phpVMS update server could not be contacted.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';

$this->set('latestnews', $msg);
return;
}

$xml = @simplexml_load_string($contents);

if (!$xml) {
$msg = '<br /><b>Error:</b> There was an error retrieving news. It may be temporary.
Check to make sure allow_url_fopen is set to ON in your php.ini, or
that the cURL module is installed (contact your host).';

$this->set('latestnews', $msg);
return;
}

CodonCache::write($key, $xml, 'medium_well');
}

$version = $xml->version;

if (Config::Get('CHECK_BETA_VERSION') == true) {
Expand All @@ -124,8 +132,15 @@ public function CheckForUpdates() {

/* Retrieve latest news from Feedburner RSS, in case the phpVMS site is down
*/
$contents = $file->get(Config::Get('PHPVMS_NEWS_FEED'));
$feed = simplexml_load_string($contents);
$key = 'PHPVMS_NEWS_FEED';
$feed = CodonCache::read($key);

if ($feed === false) {
$contents = $file->get(Config::Get('PHPVMS_NEWS_FEED'));
$feed = simplexml_load_string($contents);
CodonCache::write($key, $feed, 'medium_well');
}

$contents = '';

$i = 1;
Expand Down
4 changes: 4 additions & 0 deletions core/app.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@
'medium' => array(
'duration' => '+1 hour',
),

'medium_well' => array(
'duration' => '+3 hour',
),

'long' => array(
'duration' => '+6 hours'
Expand Down

0 comments on commit 0fa6ee1

Please sign in to comment.