Fixes for LoginTasks.
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 21:54:50 +0000 (15:54 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Thu, 25 Jun 2009 23:28:31 +0000 (17:28 -0600)
Use basename() to determine classname.
Prevent circumventing confirmation screens by refreshing browser.
Fix DISPLAY_NONE.

framework/LoginTasks/lib/Horde/LoginTasks.php
framework/LoginTasks/lib/Horde/LoginTasks/Tasklist.php

index 88865f3..46fb237 100644 (file)
@@ -139,15 +139,13 @@ class Horde_LoginTasks
             if (!is_null($fileroot) &&
                 is_dir($fileroot . '/lib/LoginTasks/Task')) {
                 foreach (scandir($fileroot . '/lib/LoginTasks/Task') as $file) {
-                    if (stripos($file, '.php') !== false) {
-                        $classname = $app . '_LoginTasks_Task_' . substr($file, 0, -4);
-                        if (class_exists($classname)) {
-                            $tasks[$classname] = $app;
-                            if (!isset($lasttasks[$app])) {
-                                $lasttasks[$app] = empty($last_logintasks[$app])
-                                    ? 0
-                                    : getdate($last_logintasks[$app]);
-                            }
+                    $classname = $app . '_LoginTasks_Task_' . basename($file, '.php');
+                    if (class_exists($classname)) {
+                        $tasks[$classname] = $app;
+                        if (!isset($lasttasks[$app])) {
+                            $lasttasks[$app] = empty($last_logintasks[$app])
+                                ? 0
+                                : getdate($last_logintasks[$app]);
                         }
                     }
                 }
@@ -212,17 +210,19 @@ class Horde_LoginTasks
      * This function will generate the list of tasks to perform during this
      * login and will redirect to the login tasks page if necessary.  This is
      * the function that should be called from the application upon login.
+     *
+     * @param boolean $confirmed  If true, indicates that any pending actions
+     *                            have been confirmed by the user.
      */
-    public function runTasks()
+    public function runTasks($confirmed = false)
     {
         if ($this->_tasklist === true) {
             return;
         }
 
         /* Perform ready tasks now. */
-        foreach ($this->_tasklist->ready() as $key => $val) {
-            if (($val->display == self::DISPLAY_AGREE) ||
-                ($val->display == self::DISPLAY_NOTICE) ||
+        foreach ($this->_tasklist->ready($this->_init || $confirmed) as $key => $val) {
+            if (in_array($val->display, array(self::DISPLAY_AGREE, self::DISPLAY_NOTICE, self::DISPLAY_NONE)) ||
                 Horde_Util::getFormData('logintasks_confirm_' . $key)) {
                 $val->execute();
             }
index af5dc05..c342613 100644 (file)
@@ -45,7 +45,7 @@ class Horde_LoginTasks_Tasklist
      *
      * @var integer
      */
-    protected $_ptr = null;
+    protected $_ptr = -1;
 
     /**
      * Constructor.
@@ -93,22 +93,23 @@ class Horde_LoginTasks_Tasklist
     /**
      * Returns the list of tasks to perform.
      *
+     * @param boolean $complete  Mark ready tasks as completed?
+     *
      * @return array  The list of tasks to perform.
      */
-    public function ready()
+    public function ready($advance = false)
     {
         $tmp = array();
 
         reset($this->_tasks);
         while (list($k, $v) = each($this->_tasks)) {
-            if ($v['display'] &&
-                (is_null($this->_ptr) || ($k > $this->_ptr))) {
+            if ($v['display'] && ($k > $this->_ptr)) {
                 break;
             }
             $tmp[] = $v['task'];
         }
 
-        if (!is_null($this->_ptr)) {
+        if ($advance) {
             $this->_tasks = array_slice($this->_tasks, $this->_ptr);
             $this->_ptr = 0;
         }