summaryrefslogtreecommitdiff
path: root/lib/plugins/popularity
diff options
context:
space:
mode:
authorGuillaume Turri <guillaume.turri@gmail.com>2010-12-18 10:27:49 +0100
committerAndreas Gohr <andi@splitbrain.org>2010-12-18 10:38:32 +0100
commit5827ba0b8aa706e4201a3dc654b3c2cf141f6dd2 (patch)
treecc5046f96c40e495b4434401a117e80f995424b4 /lib/plugins/popularity
parent02700828f76adcfc63a9dafe75ffa941cdb9831b (diff)
downloadrpg-5827ba0b8aa706e4201a3dc654b3c2cf141f6dd2.tar.gz
rpg-5827ba0b8aa706e4201a3dc654b3c2cf141f6dd2.tar.bz2
Popularity plugin displays the last time the data was sent
Diffstat (limited to 'lib/plugins/popularity')
-rw-r--r--lib/plugins/popularity/action.php4
-rw-r--r--lib/plugins/popularity/admin.php10
-rw-r--r--lib/plugins/popularity/helper.php27
-rw-r--r--lib/plugins/popularity/lang/en/lang.php1
4 files changed, 39 insertions, 3 deletions
diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php
index ce10808b9..bf11efba6 100644
--- a/lib/plugins/popularity/action.php
+++ b/lib/plugins/popularity/action.php
@@ -48,10 +48,10 @@ class action_plugin_popularity extends Dokuwiki_Action_Plugin {
/**
* Check if it's time to send autosubmit data
- * (we should have check the autosubmit is enabled first)
+ * (we should have check if autosubmit is enabled first)
*/
function _isTooEarlyToSubmit(){
- $lastSubmit = @filemtime($this->helper->autosubmitFile);
+ $lastSubmit = $this->helper->lastSentTime();
return $lastSubmit + 24*60*60*30 > time();
}
}
diff --git a/lib/plugins/popularity/admin.php b/lib/plugins/popularity/admin.php
index 22ddb245b..40c3f5452 100644
--- a/lib/plugins/popularity/admin.php
+++ b/lib/plugins/popularity/admin.php
@@ -53,6 +53,10 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin {
//Send the data
if ( isset($_REQUEST['data']) ){
$this->sentStatus = $this->helper->sendData( $_REQUEST['data'] );
+ if ( $this->sentStatus === '' ){
+ //Update the last time we sent the data
+ touch ( $this->helper->popularityLastSubmitFile );
+ }
//Deal with the autosubmit option
$this->_enableAutosubmit( isset($_REQUEST['autosubmit']) );
}
@@ -87,6 +91,12 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin {
flush();
echo $this->buildForm('server');
+
+ //Print the last time the data was sent
+ $lastSent = $this->helper->lastSentTime();
+ if ( $lastSent !== 0 ){
+ echo $this->getLang('lastSent') . datetime_h($lastSent);
+ }
} else {
//If we just submitted the form
if ( $this->sentStatus === '' ){
diff --git a/lib/plugins/popularity/helper.php b/lib/plugins/popularity/helper.php
index 00a359cbd..629d0bd67 100644
--- a/lib/plugins/popularity/helper.php
+++ b/lib/plugins/popularity/helper.php
@@ -13,7 +13,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin {
/**
* Name of the file which determine if the the autosubmit is enabled,
- * and when it was submited for the las time
+ * and when it was submited for the last time
*/
var $autosubmitFile;
@@ -22,10 +22,19 @@ class helper_plugin_popularity extends Dokuwiki_Plugin {
*/
var $autosubmitErrorFile;
+ /**
+ * Name of the file which determine when the popularity data was manually
+ * submitted for the last time
+ * (If this file doesn't exist, the data has never been sent)
+ */
+ var $popularityLastSubmitFile;
+
+
function helper_plugin_popularity(){
global $conf;
$this->autosubmitFile = $conf['cachedir'].'/autosubmit.txt';
$this->autosubmitErrorFile = $conf['cachedir'].'/autosubmitError.txt';
+ $this->popularityLastSubmitFile = $conf['cachedir'].'/lastSubmitTime.txt';
}
function getMethods(){
@@ -48,6 +57,12 @@ class helper_plugin_popularity extends Dokuwiki_Plugin {
'params' => array(),
'return' => array('data' => 'string')
);
+ $result[] = array(
+ 'name' => 'lastSentTime',
+ 'desc' => 'Compute the last time popularity data was sent',
+ 'params' => 'array()',
+ 'return' => array('data' => 'int')
+ );
return $result;
}
@@ -76,6 +91,16 @@ class helper_plugin_popularity extends Dokuwiki_Plugin {
}
/**
+ * Compute the last time the data was sent. If it has never been sent, we return 0.
+ */
+ function lastSentTime(){
+ $manualSubmission = @filemtime($this->popularityLastSubmitFile);
+ $autoSubmission = @filemtime($this->autosubmitFile);
+
+ return max((int) $manualSubmission, (int) $autoSubmission);
+ }
+
+ /**
* Gather all information
* @return The popularity data as a string
*/
diff --git a/lib/plugins/popularity/lang/en/lang.php b/lib/plugins/popularity/lang/en/lang.php
index a94623718..78a5e862c 100644
--- a/lib/plugins/popularity/lang/en/lang.php
+++ b/lib/plugins/popularity/lang/en/lang.php
@@ -6,3 +6,4 @@ $lang['autosubmit'] = 'Automatically send data once a month';
$lang['submissionFailed'] = 'The data couldn\'t be sent due to the following error:';
$lang['submitDirectly'] = 'You can send the data manually by submitting the following form.';
$lang['autosubmitError'] = 'The last autosubmit failed, because of the following error: ';
+$lang['lastSent'] = 'The data has been sent ';