From: Michael J. Rubinsky Date: Thu, 27 Jan 2011 01:00:12 +0000 (-0500) Subject: PHP5 / Horde4 standards for Turba X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=c1e7344905b762cb816cce4ba441bd9be422dab5;p=horde.git PHP5 / Horde4 standards for Turba --- diff --git a/turba/lib/Application.php b/turba/lib/Application.php index 6934c12e8..a42b0182e 100644 --- a/turba/lib/Application.php +++ b/turba/lib/Application.php @@ -165,7 +165,7 @@ class Turba_Application extends Horde_Registry_Application * * @param Horde_Menu $menu The menu object. */ - public function menu($menu) + public function menu(Horde_Menu $menu) { if ($GLOBALS['session']->get('turba', 'has_share')) { $menu->add(Horde::url('addressbooks/index.php'), _("_My Address Books"), 'turba.png'); @@ -192,7 +192,7 @@ class Turba_Application extends Horde_Registry_Application * * @param Horde_Core_Prefs_Ui $ui The UI object. */ - public function prefsGroup($ui) + public function prefsGroup(Horde_Core_Prefs_Ui $ui) { global $prefs; @@ -250,7 +250,7 @@ class Turba_Application extends Horde_Registry_Application * * @return string The HTML code to display on the prefs page. */ - public function prefsSpecial($ui, $item) + public function prefsSpecial(Horde_Core_Prefs_Ui $ui, $item) { switch ($item) { case 'addressbookselect': @@ -360,7 +360,7 @@ class Turba_Application extends Horde_Registry_Application * * @return boolean True if preference was updated. */ - public function prefsSpecialUpdate($ui, $item) + public function prefsSpecialUpdate(Horde_Core_Prefs_Ui $ui, $item) { global $prefs; diff --git a/turba/lib/Data/Ldif.php b/turba/lib/Data/Ldif.php index c3d903dfc..a78a7c78a 100644 --- a/turba/lib/Data/Ldif.php +++ b/turba/lib/Data/Ldif.php @@ -12,17 +12,16 @@ */ class Turba_Data_Ldif extends Horde_Data { - var $_extension = 'ldif'; + protected $_extension = 'ldif'; - var $_contentType = 'text/ldif'; + protected $_contentType = 'text/ldif'; /** * Useful Mozilla address book attribute names. * - * @private * @var array */ - var $_mozillaAttr = array('cn', 'givenName', 'sn', 'mail', 'mozillaNickname', + private $_mozillaAttr = array('cn', 'givenName', 'sn', 'mail', 'mozillaNickname', 'homeStreet', 'mozillaHomeStreet2', 'mozillaHomeLocalityName', 'mozillaHomeState', 'mozillaHomePostalCode', 'mozillaHomeCountryName', 'street', @@ -34,10 +33,9 @@ class Turba_Data_Ldif extends Horde_Data /** * Useful Turba address book attribute names. * - * @private * @var array */ - var $_turbaAttr = array('name', 'firstname', 'lastname', 'email', 'alias', + private $_turbaAttr = array('name', 'firstname', 'lastname', 'email', 'alias', 'homeAddress', 'homeStreet', 'homeCity', 'homeProvince', 'homePostalCode', 'homeCountry', 'workAddress', 'workStreet', 'workCity', 'workProvince', @@ -48,10 +46,9 @@ class Turba_Data_Ldif extends Horde_Data /** * Turba address book attribute names and the corresponding Mozilla name. * - * @private * @var array */ - var $_turbaMozillaMap = array('name' => 'cn', + private $_turbaMozillaMap = array('name' => 'cn', 'firstname' => 'givenName', 'lastname' => 'sn', 'email' => 'mail', @@ -89,7 +86,7 @@ class Turba_Data_Ldif extends Horde_Data * * @return boolean True if the string is safe, false otherwise. */ - function _is_safe_string($str) + private function _is_safe_string($str) { /* SAFE-CHAR = %x01-09 / %x0B-0C / %x0E-7F * ; any value <= 127 decimal except NUL, LF, @@ -116,7 +113,7 @@ class Turba_Data_Ldif extends Horde_Data return true; } - function importData($contents, $header = false) + public function importData($contents, $header = false) { $data = array(); $records = preg_split('/(\r?\n){2}/', $contents); @@ -151,7 +148,7 @@ class Turba_Data_Ldif extends Horde_Data * @param boolean $header If true, the rows of $data are associative * arrays with field names as their keys. */ - function exportFile($filename, $data, $header = false) + public function exportFile($filename, $data, $header = false) { $export = $this->exportData($data, $header); $GLOBALS['browser']->downloadHeaders($filename, 'text/ldif', false, strlen($export)); @@ -168,7 +165,7 @@ class Turba_Data_Ldif extends Horde_Data * * @return string The LDIF data. */ - function exportData($data, $header = false) + public function exportData($data, $header = false) { if (!is_array($data) || !count($data)) { return ''; @@ -219,7 +216,7 @@ class Turba_Data_Ldif extends Horde_Data * data set after the final step. * @throws Horde_Data_Exception */ - function nextStep($action, $param = array()) + public function nextStep($action, $param = array()) { switch ($action) { case Horde_Data::IMPORT_FILE: diff --git a/turba/lib/Driver.php b/turba/lib/Driver.php index 9051de1fb..a5c1eae78 100644 --- a/turba/lib/Driver.php +++ b/turba/lib/Driver.php @@ -115,10 +115,11 @@ class Turba_Driver implements Countable /** * Constructs a new Turba_Driver object. * + * @param string $name Source name * @param array $params Hash containing additional configuration * parameters. */ - public function __construct($name = '', $params = array()) + public function __construct($name = '', array $params = array()) { $this->_name = $name; $this->_params = $params; @@ -175,7 +176,7 @@ class Turba_Driver implements Countable * * @return array Translated version of $hash. */ - public function toDriverKeys($hash) + public function toDriverKeys(array $hash) { /* Handle category. */ if (!empty($hash['category'])) { @@ -268,7 +269,7 @@ class Turba_Driver implements Countable * search by the driver. The translation is based on the contents of * $this->map, and includes nested OR searches for composite fields. * - * @param array $hash Hash of criteria using Turba keys. + * @param array $criteria Hash of criteria using Turba keys. * @param string $search_type OR search or AND search? * @param array $strict Fields that must be matched exactly. * @param boolean $match_begin Whether to match only at beginning of @@ -276,7 +277,7 @@ class Turba_Driver implements Countable * * @return array An array of search criteria. */ - public function makeSearch($criteria, $search_type, $strict, + public function makeSearch($criteria, $search_type, array $strict, $match_begin = false) { $search = $search_terms = $subsearch = $strict_search = array(); @@ -448,7 +449,7 @@ class Turba_Driver implements Countable * * @return array Translated version of $entry. */ - public function toTurbaKeys($entry) + public function toTurbaKeys(array $entry) { $new_entry = array(); foreach ($this->map as $key => $val) { @@ -482,9 +483,9 @@ class Turba_Driver implements Countable * @return Turba_List The sorted, filtered list of search results. * @throws Turba_Exception */ - public function search($search_criteria, $sort_order = null, - $search_type = 'AND', $return_fields = array(), - $custom_strict = array(), $match_begin = false) + public function search(array $search_criteria, $sort_order = null, + $search_type = 'AND', array $return_fields = array(), + array $custom_strict = array(), $match_begin = false) { /* If we are not using Horde_Share, enforce the requirement that the * current user must be the owner of the addressbook. */ @@ -555,9 +556,9 @@ class Turba_Driver implements Countable * Takes an array of object hashes and returns a Turba_List * containing the correct Turba_Objects * - * @param array $objects An array of object hashes (keyed to backend). - * @param array $order Array of hashes describing sort fields. Each - * hash has the following fields: + * @param array $objects An array of object hashes (keyed to backend). + * @param array $sort_order Array of hashes describing sort fields. Each + * hash has the following fields: *
      * ascending - (boolean) Indicating sort direction.
      * field - (string) Sort field.
@@ -565,7 +566,7 @@ class Turba_Driver implements Countable
      *
      * @return Turba_List  A list object.
      */
-    protected function _toTurbaObjects($objects, $sort_order = null)
+    protected function _toTurbaObjects(array $objects, array $sort_order = null)
     {
         $list = new Turba_List();
 
@@ -600,12 +601,12 @@ class Turba_Driver implements Countable
      *
      * @param Horde_Date $start  The start date of the valid period.
      * @param Horde_Date $end    The end date of the valid period.
-     * @param $category          The timeObjects category to return.
+     * @param string $category   The timeObjects category to return.
      *
-     * @return mixed  A list of timeObject hashes.
+     * @return array  A list of timeObject hashes.
      * @throws Turba Exception
      */
-    public function listTimeObjects($start, $end, $category)
+    public function listTimeObjects(Horde_Date $start, Horde_Date $end, $category)
     {
         try {
             $res = $this->getTimeObjectTurbaList($start, $end, $category);
@@ -686,7 +687,7 @@ class Turba_Driver implements Countable
      * @return Turba_List  A list of objects.
      * @throws Turba_Exception
      */
-    public function getTimeObjectTurbaList($start, $end, $field)
+    public function getTimeObjectTurbaList(Horde_Date $start, Horde_Date $end, $field)
     {
         return $this->_getTimeObjectTurbaListFallback($start, $end, $field);
     }
@@ -704,7 +705,7 @@ class Turba_Driver implements Countable
      * @return Turba_List  A list of objects.
      * @throws Turba_Exception
      */
-    protected function _getTimeObjectTurbaListFallback($start, $end, $field)
+    protected function _getTimeObjectTurbaListFallback(Horde_Date $start, Horde_Date $end, $field)
     {
         return $this->search(array(), null, 'AND', array('name', $field, 'category'));
     }
@@ -717,7 +718,7 @@ class Turba_Driver implements Countable
      * @return array  The array of retrieved objects (Turba_Objects).
      * @throws Turba_Exception
      */
-    public function getObjects($objectIds)
+    public function getObjects(array $objectIds)
     {
         $objects = $this->_read($this->map['__key'], $objectIds,
                                 $this->getContactOwner(),
@@ -779,7 +780,7 @@ class Turba_Driver implements Countable
      * @return string  The new __key value on success.
      * @throws Turba_Exception
      */
-    public function add($attributes)
+    public function add(array $attributes)
     {
         /* Only set __type and __owner if they are not already set. */
         if (!isset($attributes['__type'])) {
@@ -905,7 +906,7 @@ class Turba_Driver implements Countable
      * @return string  The object id, possibly updated.
      * @throws Turba_Exception
      */
-    public function save($object)
+    public function save(Turba_Object $object)
     {
         $object_id = $this->_save($object);
 
@@ -958,8 +959,8 @@ class Turba_Driver implements Countable
      *
      * @return Horde_Icalendar_Vcard  A vcard object.
      */
-    public function tovCard($object, $version = '2.1', $fields = null,
-                            $skipEmpty = false)
+    public function tovCard(Turba_Object $object, $version = '2.1',
+                            array $fields = null, $skipEmpty = false)
     {
         $hash = $object->getAttributes();
         $vcard = new Horde_Icalendar_Vcard($version);
@@ -2423,7 +2424,7 @@ class Turba_Driver implements Countable
      *
      * @return array  A contact hash.
      */
-    public function fromASContact($message)
+    public function fromASContact(Horde_ActiveSync_Message_Contact $message)
     {
         $hash = array();
         $formattedname = false;
@@ -2583,18 +2584,19 @@ class Turba_Driver implements Countable
     /**
      * Creates a new Horde_Share for this source type.
      *
-     * @param array $params  The params for the share.
+     * @param string $share_name  The share name
+     * @param array  $params      The params for the share.
      *
      * @return Horde_Share  The share object.
      */
-    public function createShare($share_id, $params)
+    public function createShare($share_name, array $params)
     {
         // If the raw address book name is not set, use the share name
         if (empty($params['params']['name'])) {
-            $params['params']['name'] = $share_id;
+            $params['params']['name'] = $share_name;
         }
 
-        return Turba::createShare($share_id, $params);
+        return Turba::createShare($share_name, $params);
     }
 
     /**
@@ -2605,7 +2607,7 @@ class Turba_Driver implements Countable
      *
      * @return string  A unique ID for the new object.
      */
-    protected function _makeKey($attributes)
+    protected function _makeKey(array $attributes)
     {
         return hash('md5', mt_rand());
     }
@@ -2621,7 +2623,7 @@ class Turba_Driver implements Countable
      * @return Turba_Driver  The concrete driver object.
      * @throws Turba_Exception
      */
-    static public function factory($name, $config)
+    static public function factory($name, array $config)
     {
         $class = __CLASS__ . '_' . ucfirst(basename($config['type']));
 
@@ -2682,13 +2684,14 @@ class Turba_Driver implements Countable
      * filtered list of results. If the criteria parameter is an empty array,
      * all records will be returned.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  Array of fields containing binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         throw new Turba_Exception(_("Searching is not available."));
     }
@@ -2700,11 +2703,12 @@ class Turba_Driver implements Countable
      * @param mixed $ids     The ids of the contacts to load.
      * @param string $owner  Only return contacts owned by this user.
      * @param array $fields  List of fields to return.
+     * @param array $blobFields  Array of fields containing binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _read($key, $ids, $owner, $fields, $blobFields = array())
+    protected function _read($key, $ids, $owner, array $fields, array $blobFields = array())
     {
         throw new Turba_Exception(_("Reading contacts is not available."));
     }
@@ -2716,7 +2720,7 @@ class Turba_Driver implements Countable
      *
      * @throws Turba_Exception
      */
-    protected function _add($attributes)
+    protected function _add(array $attributes)
     {
         throw new Turba_Exception(_("Adding contacts is not available."));
     }
@@ -2724,8 +2728,8 @@ class Turba_Driver implements Countable
     /**
      * Deletes the specified contact from the SQL database.
      *
-     * @param $object_key TODO
-     * @param $object_id TODO
+     * @param string $object_key TODO
+     * @param string $object_id  TODO
      *
      * @throws Turba_Exception
      */
@@ -2737,10 +2741,12 @@ class Turba_Driver implements Countable
     /**
      * Saves the specified object in the SQL database.
      *
+     * @param Turba_Object $object  The object to save
+     *
      * @return string  The object id, possibly updated.
      * @throws Turba_Exception
      */
-    protected function _save($object)
+    protected function _save(Turba_Object $object)
     {
         throw new Turba_Exception(_("Saving contacts is not available."));
     }
@@ -2760,12 +2766,12 @@ class Turba_Driver implements Countable
     /**
      * Check if the passed in share is the default share for this source.
      *
-     * @param Horde_Share $share  The share object.
-     * @param array $srcconfig    The cfgSource entry for the share.
+     * @param Horde_Share_Object $share  The share object.
+     * @param array $srcconfig           The cfgSource entry for the share.
      *
      * @return boolean TODO
      */
-    public function checkDefaultShare($share, $srcconfig)
+    public function checkDefaultShare(Horde_Share_Object $share, array $srcconfig)
     {
         $params = @unserialize($share->get('params'));
         if (!isset($params['default'])) {
@@ -2788,7 +2794,13 @@ class Turba_Driver implements Countable
     public function count()
     {
         if (is_null($this->_count)) {
-            $this->_count = count($this->_search(array('AND' => array(array('field' => $this->toDriver('__owner'), 'op' => '=', 'test' => $this->getContactOwner()))), array($this->toDriver('__key'))));
+            $this->_count = count(
+                $this->_search(array('AND' => array(
+                                   array('field' => $this->toDriver('__owner'),
+                                         'op' => '=',
+                                         'test' => $this->getContactOwner()))),
+                               array($this->toDriver('__key')))
+            );
         }
 
         return $this->_count;
diff --git a/turba/lib/Driver/Facebook.php b/turba/lib/Driver/Facebook.php
index 6e2af8202..1ff44b3e1 100644
--- a/turba/lib/Driver/Facebook.php
+++ b/turba/lib/Driver/Facebook.php
@@ -2,7 +2,6 @@
 /**
  * Read-only Turba directory driver for Facebook friends. Requires a Horde
  * application to be setup on Facebook and configured in horde/config/conf.php.
- * This driver based on the favourites driver.
  *
  * Of limited utility since email addresses are not retrievable via the
  * Facebook API, unless the user allows the Horde application to access it -
@@ -23,6 +22,8 @@ class Turba_Driver_Facebook extends Turba_Driver
 {
     /**
      * TODO
+     *
+     * @var Horde_Service_Facebook
      */
     private $_facebook;
 
@@ -51,13 +52,14 @@ class Turba_Driver_Facebook extends Turba_Driver
      * filtered list of results. If the criteria parameter is an empty array,
      * all records will be returned.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  A list of fields that contain binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         $results = $this->_getAddressBook($fields);
 
@@ -105,12 +107,13 @@ class Turba_Driver_Facebook extends Turba_Driver
      * fields.
      *
      * @param array $criteria  Search criteria.
-     * @param string $id       Data identifier.
+     * @param mixed $ids       Data identifier.
+     * @param string $owner    Restrict contacts to those owned by this user.
      * @param array $fields    List of fields to return.
      *
      * @return array  Hash containing the search results.
      */
-    protected function _read($criteria, $ids, $owner, $fields)
+    protected function _read(array $criteria, $ids, $owner, array $fields)
     {
         return $this->_getEntry($ids, $fields);
     }
@@ -118,7 +121,7 @@ class Turba_Driver_Facebook extends Turba_Driver
     /**
      * TODO
      */
-    protected function _getEntry($keys, $fields)
+    protected function _getEntry(array $keys, array $fields)
     {
         $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
         $fields = implode(', ', $fields);
@@ -135,7 +138,7 @@ class Turba_Driver_Facebook extends Turba_Driver
     /**
      * TODO
      */
-    protected function _getAddressBook($fields = array())
+    protected function _getAddressBook(array $fields = array())
     {
         $facebook = $GLOBALS['injector']->getInstance('Horde_Service_Facebook');
         $fields = implode(', ', $fields);
@@ -164,40 +167,4 @@ class Turba_Driver_Facebook extends Turba_Driver
         return $addressbook;
     }
 
-    /**
-     * TODO
-     *
-     * @throws Turba_Exception
-     */
-    function _getFacebook()
-    {
-        global $conf, $prefs;
-
-        if (!$conf['facebook']['enabled']) {
-            throw new Turba_Exception(_("No Facebook integration exists."));
-        }
-
-        if (empty($this->_facebook)) {
-            $context = array(
-                'http_client' => new Horde_Http_Client(),
-                'http_request' => $GLOBALS['injector']->getInstance('Horde_Controller_Request')
-            );
-            $this->_facebook = new Horde_Service_Facebook(
-                $conf['facebook']['key'],
-                $conf['facebook']['secret'],
-                $context
-            );
-
-            $session = unserialize($prefs->getValue('facebook'));
-            if (!$session ||
-                !isset($session['uid']) ||
-                !isset($session['sid'])) {
-                throw new Turba_Exception(_("You have to connect to Facebook in your address book preferences."));
-            }
-            $this->_facebook->auth->setUser($session['uid'], $session['sid'], 0);
-        }
-
-        return $this->_facebook;
-    }
-
 }
diff --git a/turba/lib/Driver/Favourites.php b/turba/lib/Driver/Favourites.php
index 63e1fe691..58402cf2e 100644
--- a/turba/lib/Driver/Favourites.php
+++ b/turba/lib/Driver/Favourites.php
@@ -42,11 +42,12 @@ class Turba_Driver_Favourites extends Turba_Driver
      *
      * @param array $criteria  Array containing the search criteria.
      * @param array $fields    List of fields to return.
+     * @param array $blobFields  A list of fields that contain binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         $results = array();
 
@@ -94,13 +95,14 @@ class Turba_Driver_Favourites extends Turba_Driver
      * fields.
      *
      * @param array $criteria  Search criteria.
-     * @param string $id       Data identifier.
+     * @param mixed $id        Data identifier.
+     * @param string $owner    Filter on contacts owned by this owner.
      * @param array $fields    List of fields to return.
      *
      * @return arry  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _read($criteria, $ids, $owner, $fields)
+    protected function _read(array $criteria, $ids, $owner, array $fields)
     {
         $book = $this->_getAddressBook();
 
diff --git a/turba/lib/Driver/Group.php b/turba/lib/Driver/Group.php
index fb8021b8a..1d788109c 100644
--- a/turba/lib/Driver/Group.php
+++ b/turba/lib/Driver/Group.php
@@ -54,13 +54,14 @@ class Turba_Driver_Group extends Turba_Driver
      *
      * This method 'borrowed' from the favorites driver.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  A list of fields that contain binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         $results = array();
 
@@ -108,12 +109,12 @@ class Turba_Driver_Group extends Turba_Driver
      * Again, this method taken from the favorites driver.
      *
      * @param array $criteria  Search criteria.
-     * @param string $id       Data identifier.
+     * @param mixed $id        Data identifier.
      * @param array $fields    List of fields to return.
      *
      * @return array  Hash containing the search results.
      */
-    protected function _read($criteria, $ids, $fields)
+    protected function _read(array $criteria, $ids, array $fields)
     {
         $book = $this->_getAddressBook();
         $results = array();
diff --git a/turba/lib/Driver/Ldap.php b/turba/lib/Driver/Ldap.php
index b2a6e5cba..436f9c63d 100644
--- a/turba/lib/Driver/Ldap.php
+++ b/turba/lib/Driver/Ldap.php
@@ -39,9 +39,12 @@ class Turba_Driver_Ldap extends Turba_Driver
     /**
      * Constructs a new Turba LDAP driver object.
      *
-     * @param $params  Hash containing additional configuration parameters.
+     * @param string $name   The source name
+     * @param array $params  Hash containing additional configuration parameters.
+     *
+     * @return Turba_Driver_Ldap
      */
-    public function __construct($name = '', $params = array())
+    public function __construct($name = '', array $params = array())
     {
         if (!Horde_Util::extensionExists('ldap')) {
             throw new Turba_Exception(_("LDAP support is required but the LDAP module is not available or not loaded."));
@@ -105,7 +108,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @return array  Translated version of $hash.
      */
-    public function toDriverKeys($hash)
+    public function toDriverKeys(array $hash)
     {
         // First check for combined fields in the dn-fields and add them.
         if (is_array($this->_params['dn'])) {
@@ -135,13 +138,14 @@ class Turba_Driver_Ldap extends Turba_Driver
      * a filtered list of results. If no criteria are specified, all
      * records are returned.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  Fields that contain binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         /* Build the LDAP filter. */
         $filter = '';
@@ -207,7 +211,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _read($key, $ids, $owner, $fields)
+    protected function _read($key, $ids, $owner, array $fields)
     {
         /* Only DN. */
         if ($key != 'dn') {
@@ -257,7 +261,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @throws Turba_Exception
      */
-    protected function _add($attributes)
+    protected function _add(array $attributes)
     {
         if (empty($attributes['dn'])) {
             throw new Turba_Exception('Tried to add an object with no dn: [' . serialize($attributes) . '].');
@@ -314,7 +318,8 @@ class Turba_Driver_Ldap extends Turba_Driver
     /**
      * Deletes the specified entry from the LDAP directory.
      *
-     * TODO
+     * @param string $object_key
+     * @param string $object_id
      *
      * @throws Turba_Exception
      */
@@ -332,6 +337,8 @@ class Turba_Driver_Ldap extends Turba_Driver
     /**
      * Modifies the specified entry in the LDAP directory.
      *
+     * @param Turba_Object $object  The object we wish to save.
+     *
      * @return string  The object id, possibly updated.
      * @throw Turba_Exception
      */
@@ -416,7 +423,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @return string  The RDN for the new object.
      */
-    protected function _makeRDN($attributes)
+    protected function _makeRDN(array $attributes)
     {
         if (!is_array($this->_params['dn'])) {
             return '';
@@ -441,7 +448,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @return string  The DN for the new object.
      */
-    protected function _makeKey($attributes)
+    protected function _makeKey(array $attributes)
     {
         return $this->_makeRDN($attributes) . ',' . $this->_params['root'];
     }
@@ -453,7 +460,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *
      * @return string  An LDAP query fragment.
      */
-    protected function _buildSearchQuery($criteria)
+    protected function _buildSearchQuery(array $criteria)
     {
         $clause = '';
 
@@ -493,7 +500,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      * @return array  Hash containing the results.
      * @throws Turba_Exception
      */
-    protected function _getResults($fields, $res)
+    protected function _getResults(array $fields, $res)
     {
         $entries = @ldap_get_entries($this->_ds, $res);
         if ($entries === false) {
@@ -573,6 +580,8 @@ class Turba_Driver_Ldap extends Turba_Driver
     /**
      * Format and encode attributes including postal addresses,
      * character set encoding, etc.
+     *
+     * @param array $attributes  The attributes array.
      */
     protected function _encodeAttributes(&$attributes)
     {
@@ -608,7 +617,7 @@ class Turba_Driver_Ldap extends Turba_Driver
      *                that have been configured as being required.
      * @throws Turba_Exception
      */
-    protected function _checkRequiredAttributes($objectclasses)
+    protected function _checkRequiredAttributes(array $objectclasses)
     {
        $retval = array();
        $schema = $this->_ldap->schema();
@@ -697,4 +706,5 @@ class Turba_Driver_Ldap extends Turba_Driver
 
         return $this->_syntaxCache[$att];
     }
+
 }
diff --git a/turba/lib/Driver/Prefs.php b/turba/lib/Driver/Prefs.php
index 670999aa3..b2919e635 100644
--- a/turba/lib/Driver/Prefs.php
+++ b/turba/lib/Driver/Prefs.php
@@ -19,12 +19,13 @@ class Turba_Driver_Prefs extends Turba_Driver
      * Returns all entries - searching isn't implemented here for now. The
      * parameters are simply ignored.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  Array of fields containing binary data.
      *
      * @return array  Hash containing the search results.
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         return array_values($this->_getAddressBook());
     }
@@ -34,12 +35,12 @@ class Turba_Driver_Prefs extends Turba_Driver
      * fields.
      *
      * @param array $criteria  Search criteria.
-     * @param string $id       Data identifier.
+     * @param mixed $ids       Data identifier(s).
      * @param array $fields    List of fields to return.
      *
      * @return  Hash containing the search results.
      */
-    protected function _read($criteria, $ids, $fields)
+    protected function _read(array $criteria, $ids, array $fields)
     {
         $book = $this->_getAddressBook();
         $results = array();
@@ -60,7 +61,7 @@ class Turba_Driver_Prefs extends Turba_Driver
      *
      * @param array $attributes  TODO
      */
-    protected function _add($attributes)
+    protected function _add(array $attributes)
     {
         $book = $this->_getAddressBook();
         $book[$attributes['id']] = $attributes;
@@ -78,8 +79,8 @@ class Turba_Driver_Prefs extends Turba_Driver
     /**
      * Deletes the specified object from the preferences.
      *
-     * @param $object_key TODO
-     * @param $object_id  TODO
+     * @param string $object_key TODO
+     * @param string $object_id  TODO
      */
     protected function _delete($object_key, $object_id)
     {
@@ -91,7 +92,7 @@ class Turba_Driver_Prefs extends Turba_Driver
     /**
      * Saves the specified object in the preferences.
      *
-     * @param $object TODO
+     * @param Turba_Object $object TODO
      */
     function _save($object)
     {
diff --git a/turba/lib/Driver/Share.php b/turba/lib/Driver/Share.php
index 8860e2afe..57023a598 100644
--- a/turba/lib/Driver/Share.php
+++ b/turba/lib/Driver/Share.php
@@ -11,6 +11,7 @@
  *
  * @author   Chuck Hagenbuch 
  * @author   Jon Parise 
+ * @author   Michael J. Rubinsky 
  * @category Horde
  * @license  http://www.horde.org/licenses/asl.php ASL
  * @package  Turba
@@ -39,7 +40,7 @@ class Turba_Driver_Share extends Turba_Driver
      *
      * @return Turba_Driver
      */
-    public function __construct($name = '', $params = array())
+    public function __construct($name = '', array $params = array())
     {
         parent::__construct($name, $params);
         $this->_share = $this->_params['config']['params']['share'];
@@ -104,13 +105,14 @@ class Turba_Driver_Share extends Turba_Driver
      * filtered list of results. If the criteria parameter is an empty array,
      * all records will be returned.
      *
-     * @param array $criteria  Array containing the search criteria.
-     * @param array $fields    List of fields to return.
+     * @param array $criteria    Array containing the search criteria.
+     * @param array $fields      List of fields to return.
+     * @param array $blobFields  Array of fields containing binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _search($criteria, $fields, $blobFields = array())
+    protected function _search(array $criteria, array $fields, array $blobFields = array())
     {
         return $this->_driver->_search($criteria, $fields, $blobFields);
     }
@@ -140,12 +142,13 @@ class Turba_Driver_Share extends Turba_Driver
      * @param mixed $ids     The ids of the contacts to load.
      * @param string $owner  Only return contacts owned by this user.
      * @param array $fields  List of fields to return.
+     * @param array $blobFields  Array of fields containing binary data.
      *
      * @return array  Hash containing the search results.
      * @throws Turba_Exception
      */
-    protected function _read($key, $ids, $owner, $fields,
-                             $blob_fields = array())
+    protected function _read($key, $ids, $owner, array $fields,
+                             array $blob_fields = array())
     {
         return $this->_driver->_read($key, $ids, $owner, $fields, $blob_fields);
     }
@@ -153,9 +156,10 @@ class Turba_Driver_Share extends Turba_Driver
     /**
      * Adds the specified object to the SQL database.
      *
-     * TODO
+     * @param array $attributes
+     * @param array $blob_fields
      */
-    protected function _add($attributes, $blob_fields = array())
+    protected function _add(array $attributes, array $blob_fields = array())
     {
         $this->_driver->_add($attributes, $blob_fields);
     }
@@ -181,6 +185,8 @@ class Turba_Driver_Share extends Turba_Driver
     /**
      * Deletes all contacts from a specific address book.
      *
+     * @param string $sourceName  The source to delete all contacts from.
+     *
      * @throws Turba_Exception
      */
     protected function _deleteAll($sourceName = null)
@@ -194,16 +200,20 @@ class Turba_Driver_Share extends Turba_Driver
     /**
      * Saves the specified object in the SQL database.
      *
+     * @param Turba_Object $object The object to save
+     *
      * @return string  The object id, possibly updated.
      * @throws Turba_Exception
      */
-    protected function _save($object)
+    protected function _save(Turba_Object $object)
     {
         return $this->_driver->_save($object);
     }
 
     /**
-     * Stub for removing all data for a specific user.
+     * Remove all data for a specific user.
+     *
+     * @param string $user  The user to remove all data for.
      */
     public function removeUserData($user)
     {
@@ -213,15 +223,21 @@ class Turba_Driver_Share extends Turba_Driver
     }
 
     /**
-     * TODO
+     * @param array $attributes
      */
-    protected function _makeKey($attributes)
+    protected function _makeKey(array $attributes)
     {
         return $this->_driver->_makeKey($attributes);
     }
 
     /**
-     * TODO
+     * @param Horde_Date $start  The starting date.
+     * @param Horde_Date $end    The ending date.
+     * @param string $field      The address book field containing the
+     *                           timeObject information (birthday,
+     *                           anniversary).
+     *
+     * @return array  The list of timeobjects
      */
     public function getTimeObjectTurbaList($start, $end, $field)
     {
diff --git a/turba/lib/Driver/Sql.php b/turba/lib/Driver/Sql.php
index dc18075e0..380308210 100644
--- a/turba/lib/Driver/Sql.php
+++ b/turba/lib/Driver/Sql.php
@@ -1,6 +1,6 @@
 
+ * @author   Michael J. Rubinsky 
  * @category Horde
  * @license  http://www.horde.org/licenses/asl.php ASL
  * @package  Turba
@@ -42,13 +43,17 @@ class Turba_Driver_Sql extends Turba_Driver
     /**
      * Constructor.
      *
+     * @param string $name   The source name
      * @param array $params  Additional parameters needed:
      * 
      * 'db' - (Horde_Db_Adapter) A DB Adapter object.
      * 
*/ - public function __construct($name = '', $params = array()) + public function __construct($name = '', array $params = array()) { + if (empty($params['db'])) { + throw new InvalidArgumentException(_("Missing required Horde_Db_Adapter obejct")); + } $this->_db = $params['db']; unset($params['db']); @@ -317,16 +322,17 @@ class Turba_Driver_Sql extends Turba_Driver * Reads the given data from the SQL database and returns the * results. * - * @param string $key The primary key field to use. - * @param mixed $ids The ids of the contacts to load. - * @param string $owner Only return contacts owned by this user. - * @param array $fields List of fields to return. + * @param string $key The primary key field to use. + * @param mixed $ids The ids of the contacts to load. + * @param string $owner Only return contacts owned by this user. + * @param array $fields List of fields to return. + * @param array $blob_fields List of fields that contain binary data. * * @return array Hash containing the search results. * @throws Turba_Exception */ - protected function _read($key, $ids, $owner, $fields, - $blob_fields = array()) + protected function _read($key, $ids, $owner, array $fields, + array $blob_fields = array()) { $values = array(); @@ -488,10 +494,12 @@ class Turba_Driver_Sql extends Turba_Driver /** * Saves the specified object in the SQL database. * + * @param Turba_Object $object The object to save. + * * @return string The object id, possibly updated. * @throws Turba_Exception */ - function _save($object) + function _save(Turba_Object $object) { list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key')))); $attributes = $this->toDriverKeys($object->getAttributes()); @@ -523,7 +531,7 @@ class Turba_Driver_Sql extends Turba_Driver * * @return string A unique ID for the new object. */ - protected function _makeKey($attributes) + protected function _makeKey(array $attributes) { return strval(new Horde_Support_Randomid()); } @@ -537,7 +545,7 @@ class Turba_Driver_Sql extends Turba_Driver * @return array An SQL fragment and a list of values suitable for binding * as an array. */ - protected function _buildSearchQuery($glue, $criteria) + protected function _buildSearchQuery($glue, array $criteria) { $clause = ''; $values = array(); @@ -626,13 +634,13 @@ class Turba_Driver_Sql extends Turba_Driver * * @param string $user The user's data to remove. * - * @throws Turba_Exception + * @throws Horde_Exception_PermissionDenied */ public function removeUserData($user) { // Make sure we are being called by an admin. if (!$GLOBALS['registry']->isAdmin()) { - throw new Turba_Exception(_("Permission denied")); + throw new Horde_Exception_PermissionDenied(_("Permission denied")); } $this->_deleteAll($user); diff --git a/turba/lib/Driver/Vbook.php b/turba/lib/Driver/Vbook.php index 8c600b266..0aea11519 100644 --- a/turba/lib/Driver/Vbook.php +++ b/turba/lib/Driver/Vbook.php @@ -29,9 +29,11 @@ class Turba_Driver_Vbook extends Turba_Driver public $searchCriteria; /** + * + * @see Turba_Driver::__construct * @throws Turba_Exception */ - public function __construct($name = '', $params = array()) + public function __construct($name = '', array $params = array()) { parent::__construct($name, $params); @@ -66,11 +68,12 @@ class Turba_Driver_Vbook extends Turba_Driver * * @param array $criteria Array containing the search criteria. * @param array $fields List of fields to return + * @param array $blobFileds Array of fields that contain * * @return array Hash containing the search results. * @throws Turba_Exception */ - protected function _search($criteria, $fields, $blobFields = array()) + protected function _search(array $criteria, array $fields, array $blobFields = array()) { /* Add the passed in search criteria to the vbook criteria * (which need to be mapped from turba fields to @@ -90,7 +93,7 @@ class Turba_Driver_Vbook extends Turba_Driver * * @return array Hash containing the search results. */ - protected function _read($key, $ids, $owner, $fields) + protected function _read($key, $ids, $owner, array $fields) { return $this->_driver->_read($key, $ids, $owner, $fields); } @@ -98,9 +101,10 @@ class Turba_Driver_Vbook extends Turba_Driver /** * Not supported for virtual address books. * + * @see Turba_Driver::_add * @throws Turba_Exception */ - protected function _add($attributes) + protected function _add(array $attributes) { throw new Turba_Exception(_("You cannot add new contacts to a virtual address book")); } @@ -108,6 +112,7 @@ class Turba_Driver_Vbook extends Turba_Driver /** * Not supported for virtual address books. * + * @see Turba_Driver::_delete * @throws Turba_Exception */ protected function _delete($object_key, $object_id) @@ -116,9 +121,9 @@ class Turba_Driver_Vbook extends Turba_Driver } /** - * TODO + * @see Turba_Driver::_save */ - protected function _save($object) + protected function _save(Turba_Object $object) { return $this->_driver->save($object); } diff --git a/turba/lib/Form/AddContact.php b/turba/lib/Form/AddContact.php index f0e088e2d..a388a89aa 100644 --- a/turba/lib/Form/AddContact.php +++ b/turba/lib/Form/AddContact.php @@ -4,14 +4,15 @@ */ class Turba_Form_AddContact extends Turba_Form_Contact { - var $_contact = null; + protected $_contact = null; - public function __construct(&$vars, &$contact) + public function __construct($vars, Turba_Object $contact) { + // @TODO: $addSources should be injected global $addSources, $notification; parent::Horde_Form($vars, _("Add Contact")); - $this->_contact = &$contact; + $this->_contact = $contact; $this->setButtons(_("Add")); $this->addHidden('', 'url', 'text', false); @@ -43,7 +44,7 @@ class Turba_Form_AddContact extends Turba_Form_Contact } } - function validate() + public function validate() { if (!$this->_vars->get('source')) { return false; @@ -51,8 +52,10 @@ class Turba_Form_AddContact extends Turba_Form_Contact return parent::validate($this->_vars); } - function execute() + public function execute() { + // @TODO $driver should be injected, or at the very least, obtained + // via the injector global $driver, $notification; /* Form valid, save data. */ diff --git a/turba/lib/Form/Contact.php b/turba/lib/Form/Contact.php index 86418eca0..4956e650a 100644 --- a/turba/lib/Form/Contact.php +++ b/turba/lib/Form/Contact.php @@ -4,7 +4,11 @@ */ class Turba_Form_Contact extends Horde_Form { - public function __construct(&$vars, &$contact, $tabs = true) + /** + * @param array $vars Array of form variables + * @param Turba_Object $contact + */ + public function __construct($vars, Turba_Object $contact, $tabs = true) { global $conf, $notification; @@ -34,9 +38,12 @@ class Turba_Form_Contact extends Horde_Form /** * Set up the Horde_Form fields for $contact's attributes. + * + * @param Turba_Object $contact The contact */ - function _addFields($contact, $useTabs = true) + public function _addFields(Turba_Object $contact, $useTabs = true) { + // @TODO: inject this global $attributes; // Run through once to see what form actions, if any, we need @@ -81,11 +88,11 @@ class Turba_Form_Contact extends Horde_Form $desc = isset($attribute['desc']) ? $attribute['desc'] : null; if (is_array($map[$field])) { - $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params); + $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], false, false, $desc, $params); $v->disable(); } else { $readonly = isset($attribute['readonly']) ? $attribute['readonly'] : null; - $v = &$this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params); + $v = $this->addVariable($attribute['label'], 'object[' . $field . ']', $attribute['type'], $attribute['required'], $readonly, $desc, $params); if (!empty($actions[$field])) { $actionfields = array(); diff --git a/turba/lib/Form/CreateAddressBook.php b/turba/lib/Form/CreateAddressBook.php index 6c39f22af..c0a6befae 100644 --- a/turba/lib/Form/CreateAddressBook.php +++ b/turba/lib/Form/CreateAddressBook.php @@ -17,7 +17,7 @@ */ class Turba_Form_CreateAddressBook extends Horde_Form { - public function __construct(&$vars) + public function __construct($vars) { parent::__construct($vars, _("Create Address Book")); @@ -30,7 +30,7 @@ class Turba_Form_CreateAddressBook extends Horde_Form /** * @throws Turba_Exception */ - function execute() + public function execute() { // Need a clean cfgSources array include TURBA_BASE . '/config/backends.php'; diff --git a/turba/lib/Form/DeleteAddressBook.php b/turba/lib/Form/DeleteAddressBook.php index 0b09708b7..3bae3e77e 100644 --- a/turba/lib/Form/DeleteAddressBook.php +++ b/turba/lib/Form/DeleteAddressBook.php @@ -20,11 +20,11 @@ class Turba_Form_DeleteAddressBook extends Horde_Form /** * Address book being deleted */ - var $_addressbook; + protected $_addressbook; - public function __construct(&$vars, &$addressbook) + public function __construct($vars, $addressbook) { - $this->_addressbook = &$addressbook; + $this->_addressbook = $addressbook; parent::__construct($vars, sprintf(_("Delete %s"), $addressbook->get('name'))); $this->addHidden('', 'a', 'text', true); @@ -38,7 +38,7 @@ class Turba_Form_DeleteAddressBook extends Horde_Form * * @throws Turba_Exception */ - function execute() + public function execute() { // If cancel was clicked, return false. if ($this->_vars->get('submitbutton') == _("Cancel")) { @@ -55,8 +55,7 @@ class Turba_Form_DeleteAddressBook extends Horde_Form // We have a Turba_Driver, try to delete the address book. $driver->deleteAll(); - // Address book successfully deleted from backend, remove the - // share. + // Address book successfully deleted from backend, remove the share. try { $GLOBALS['turba_shares']->removeShare($this->_addressbook); } catch (Horde_Share_Exception $e) { diff --git a/turba/lib/Form/EditAddressBook.php b/turba/lib/Form/EditAddressBook.php index df213526c..72a910958 100644 --- a/turba/lib/Form/EditAddressBook.php +++ b/turba/lib/Form/EditAddressBook.php @@ -19,12 +19,14 @@ class Turba_Form_EditAddressBook extends Horde_Form { /** * Address book being edited + * + * @var Horde_Share_Object */ - var $_addressbook; + protected $_addressbook; - public function __construct(&$vars, &$addressbook) + public function __construct($vars, Horde_Share_Object $addressbook) { - $this->_addressbook = &$addressbook; + $this->_addressbook = $addressbook; parent::__construct($vars, sprintf(_("Edit %s"), $addressbook->get('name'))); $this->addHidden('', 'a', 'text', true); @@ -34,16 +36,15 @@ class Turba_Form_EditAddressBook extends Horde_Form $this->setButtons(array(_("Save"))); } - function execute() + public function execute() { $this->_addressbook->set('name', $this->_vars->get('name')); $this->_addressbook->set('desc', $this->_vars->get('description')); - try { $this->_addressbook->save(); return true; - } catch (Turba_Exception $e) { - return PEAR::raiseError(sprintf(_("Unable to save address book \"%s\": %s"), $id, $e->getMessage())); + } catch (Horde_Share_Exception $e) { + throw new Turba_Exception(sprintf(_("Unable to save address book \"%s\": %s"), $id, $e->getMessage())); } } diff --git a/turba/lib/Form/EditContact.php b/turba/lib/Form/EditContact.php index c4c836866..be06989b2 100644 --- a/turba/lib/Form/EditContact.php +++ b/turba/lib/Form/EditContact.php @@ -4,15 +4,19 @@ */ class Turba_Form_EditContact extends Turba_Form_Contact { - var $_source; - var $_contact; + protected $_source; + protected $_contact; - public function __construct(&$vars, &$contact) + /** + * @param Turba_Object $contact + * @param array $vars + */ + public function __construct($vars, Turba_Object $contact) { global $conf; parent::Horde_Form($vars, '', 'Turba_View_EditContact'); - $this->_contact = &$contact; + $this->_contact = $contact; $this->setButtons(_("Save")); $this->addHidden('', 'url', 'text', false); @@ -36,17 +40,17 @@ class Turba_Form_EditContact extends Turba_Form_Contact $vars->set('source', $contact->getSource()); } - function getSource() + public function getSource() { return $this->_source; } - function execute() + public function execute() { global $conf, $notification; if (!$this->validate($this->_vars)) { - return PEAR::raiseError('Invalid'); + throw new Turba_Exception('Invalid'); } /* Form valid, save data. */ @@ -71,7 +75,7 @@ class Turba_Form_EditContact extends Turba_Form_Contact } catch (Turba_Exception $e) { Horde::logMessage($e, 'ERR'); $notification->push(_("There was an error saving the contact. Contact your system administrator for further help."), 'horde.error'); - return PEAR::raiseError($e->getMessage()); + throw $e; } if ($conf['documents']['type'] != 'none' && isset($info['vfs'])) { diff --git a/turba/lib/Form/EditContactGroup.php b/turba/lib/Form/EditContactGroup.php index dcb99ac09..64bfe9367 100644 --- a/turba/lib/Form/EditContactGroup.php +++ b/turba/lib/Form/EditContactGroup.php @@ -4,7 +4,7 @@ */ class Turba_Form_EditContactGroup extends Turba_Form_EditContact { - public function __construct(&$vars, &$contact) + public function __construct($vars, $contact) { $this->addHidden('', 'objectkeys', 'text', false); $this->addHidden('', 'original_source', 'text', false); @@ -30,7 +30,7 @@ class Turba_Form_EditContactGroup extends Turba_Form_EditContact $this->appendButtons(_("Finish")); } - function renderActive($renderer, &$vars, $action, $method) + public function renderActive($renderer, $vars, $action, $method) { parent::renderActive($renderer, $vars, $action, $method); @@ -44,7 +44,7 @@ class Turba_Form_EditContactGroup extends Turba_Form_EditContact echo '
' . $listView->getPage($numDisplayed); } - function execute() + public function execute() { $result = parent::execute(); diff --git a/turba/lib/List.php b/turba/lib/List.php index a8c231cae..978152617 100644 --- a/turba/lib/List.php +++ b/turba/lib/List.php @@ -33,7 +33,7 @@ class Turba_List implements Countable /** * Constructor. */ - public function __construct($ids = array()) + public function __construct(array $ids = array()) { foreach ($ids as $value) { list($source, $key) = explode(':', $value); @@ -49,7 +49,7 @@ class Turba_List implements Countable * * @param Turba_Object $object The object to insert. */ - public function insert($object) + public function insert(Turba_Object $object) { if ($object instanceof Turba_Object) { $key = $object->getSource() . ':' . $object->getValue('__key'); @@ -179,7 +179,7 @@ class Turba_List implements Countable * * @return integer Comparison of the two field values. */ - protected function _cmp($a, $b) + protected function _cmp(Turba_Object $a, Turba_Object $b) { foreach ($this->_usortCriteria as $field) { // Set the comparison type based on the type of attribute we're diff --git a/turba/lib/Object.php b/turba/lib/Object.php index 1023475b6..5cecdca1c 100644 --- a/turba/lib/Object.php +++ b/turba/lib/Object.php @@ -7,35 +7,35 @@ * @author Jon Parise * @package Turba */ -class Turba_Object { - +class Turba_Object +{ /** * Underlying driver. * * @var Turba_Driver */ - var $driver; + public $driver; /** * Hash of attributes for this contact. * * @var array */ - var $attributes; + public $attributes; /** * Reference to this object's VFS instance. * * @var VFS */ - var $_vfs; + protected $_vfs; /** * Keeps the normalized values of sort columns. * * @var array */ - var $sortValue = array(); + public $sortValue = array(); /** * Constructs a new Turba_Object object. @@ -43,9 +43,9 @@ class Turba_Object { * @param Turba_Driver $driver The source that this object came from. * @param array $attributes Hash of attributes for this object. */ - function Turba_Object(&$driver, $attributes = array()) + public function __construct(Turba_Driver $driver, array $attributes = array()) { - $this->driver = &$driver; + $this->driver = $driver; $this->attributes = $attributes; $this->attributes['__type'] = 'Object'; } @@ -55,7 +55,7 @@ class Turba_Object { * * @return array All properties of this object. */ - function getAttributes() + public function getAttributes() { return $this->attributes; } @@ -63,7 +63,7 @@ class Turba_Object { /** * Returns the name of the address book that this object is from. */ - function getSource() + public function getSource() { return $this->driver->getName(); } @@ -75,7 +75,7 @@ class Turba_Object { * * @return string Fully qualified contact id. */ - function getGuid($delimiter = ':') + public function getGuid($delimiter = ':') { return 'turba' . $delimiter . $this->getSource() . $delimiter . $this->getValue('__uid'); } @@ -96,7 +96,6 @@ class Turba_Object { return Horde::callHook('decode_attribute', array($attribute, $this->attributes[$attribute]), 'turba'); } catch (Turba_Exception $e) {} } - if (isset($this->driver->map[$attribute]) && is_array($this->driver->map[$attribute])) { $args = array(); @@ -127,14 +126,13 @@ class Turba_Object { * @param string $attribute The attribute to set. * @param string $value The value of $attribute. */ - function setValue($attribute, $value) + public function setValue($attribute, $value) { if (Horde::hookExists('encode_attribute', 'turba')) { try { $value = Horde::callHook('encode_attribute', array($attribute, $value, isset($this->attributes[$attribute]) ? $this->attributes[$attribute] : null, $this), 'turba'); } catch (Turba_Exception $e) {} } - if (isset($this->driver->map[$attribute]) && is_array($this->driver->map[$attribute]) && !isset($this->driver->map[$attribute]['attribute'])) { @@ -153,7 +151,7 @@ class Turba_Object { * * @return boolean Whether or not there is a value for $attribute. */ - function hasValue($attribute) + public function hasValue($attribute) { if (isset($this->driver->map[$attribute]) && is_array($this->driver->map[$attribute])) { @@ -175,18 +173,16 @@ class Turba_Object { * * @return integer The timestamp of the last modification or zero. */ - function lastModification() + public function lastModification() { $time = $this->getValue('__modified'); if (!is_null($time)) { return $time; } - if (!$this->getValue('__uid')) { $this->setValue('__modified', 0); return 0; } - $time = 0; try { $log = $GLOBALS['injector'] @@ -210,7 +206,7 @@ class Turba_Object { * * @param Turba_Object $contact Another contact. */ - function merge(Turba_Object $contact) + public function merge(Turba_Object $contact) { foreach (array_keys($contact->attributes) as $attribute) { if (!$this->hasValue($attribute) && $contact->hasValue($attribute)) { @@ -225,12 +221,11 @@ class Turba_Object { * @return array A hash with the optional entries 'created' and 'modified' * and human readable history information as the values. */ - function getHistory() + public function getHistory() { if (!$this->getValue('__uid')) { return array(); } - $history = array(); try { $log = $GLOBALS['injector'] @@ -263,7 +258,7 @@ class Turba_Object { * * @return boolean True if this object is a group of multiple contacts. */ - function isGroup() + public function isGroup() { return false; } @@ -273,7 +268,7 @@ class Turba_Object { * * @return boolean Whether or not the current user can edit this object */ - function isEditable() + public function isEditable() { return $this->driver->hasPermission(Horde_Perms::EDIT); } @@ -285,15 +280,20 @@ class Turba_Object { * * @return boolean True if user has the permission. */ - function hasPermission($perm) + public function hasPermission($perm) { return $this->driver->hasPermission($perm); } /** * Contact url. + * + * @param string $view The view for the url + * @param boolean $full Generate a full url? + * + * @return string */ - function url($view = null, $full = false) + public function url($view = null, $full = false) { $url = Horde::url('contact.php', $full)->add(array( 'source' => $this->driver->getName(), @@ -314,10 +314,9 @@ class Turba_Object { * Horde_Form_Type_file. * @throws Turba_Exception */ - function addFile($info) + public function addFile(array $info) { $this->_vfsInit(); - $dir = TURBA_VFS_PATH . '/' . $this->getValue('__uid'); $file = $info['name']; while ($this->_vfs->exists($dir, $file)) { @@ -332,7 +331,6 @@ class Turba_Object { } } } - try { $this->_vfs->write($dir, $file, $info['tmp_name'], true); } catch (VFS_Exception $e) { @@ -346,7 +344,7 @@ class Turba_Object { * @param string $file The file name. * @throws Turba_Exception */ - function deleteFile($file) + public function deleteFile($file) { $this->_vfsInit(); try { @@ -361,7 +359,7 @@ class Turba_Object { * * @throws Turba_Exception */ - function deleteFiles() + public function deleteFiles() { $this->_vfsInit(); if ($this->_vfs->exists(TURBA_VFS_PATH, $this->getValue('__uid'))) { @@ -378,7 +376,7 @@ class Turba_Object { * * @return array A list of hashes with file informations. */ - function listFiles() + public function listFiles() { try { $this->_vfsInit(); @@ -398,7 +396,7 @@ class Turba_Object { * * @return string The HTML code of the generated link. */ - function vfsDisplayUrl($file) + public function vfsDisplayUrl($file) { global $registry, $mime_drivers_map, $mime_drivers; @@ -433,7 +431,7 @@ class Turba_Object { * * @return string The HTML code of the generated link. */ - function vfsEditUrl($file) + public function vfsEditUrl($file) { $delform = '
getValue('name'); - $lastname = Turba::guessLastname($name); + $lastname = self::guessLastname($name); if ($name_format == 'last_first' && !is_int(strpos($name, ',')) && Horde_String::length($name) > Horde_String::length($lastname)) { @@ -283,14 +290,19 @@ class Turba { $name = preg_replace('/' . preg_quote($lastname, '/') . ',\s*/', '', $name); $name = $name . ' ' . $lastname; } + return $name; } } /** * Returns the real name, if available, of a user. + * + * @param string $uid The uid of the name to return. + * + * @return string The user's full, real name. */ - function getUserName($uid) + static public function getUserName($uid) { static $names = array(); @@ -309,12 +321,14 @@ class Turba { /** * Gets extended permissions on an address book. * - * @param Turba_Driver $addressBook The address book to get extended permissions for. - * @param string $permission What extended permission to get. + * @param Turba_Driver $addressBook The address book to get extended + * permissions for. + * @param string $permission What extended permission to get. * - * @return mixed The requested extended permissions value, or true if it doesn't exist. + * @return mixed The requested extended permissions value, or true if it + * doesn't exist. */ - function getExtendedPermission($addressBook, $permission) + static public function getExtendedPermission(Turba_Driver $addressBook, $permission) { // We want to check the base source as extended permissions // are enforced per backend, not per share. @@ -347,7 +361,7 @@ class Turba { * * @return array The filtered data. */ - function permissionsFilter($in, $permission = Horde_Perms::READ, $options = array()) + static public function permissionsFilter(array $in, $permission = Horde_Perms::READ, array $options = array()) { $out = array(); @@ -374,19 +388,19 @@ class Turba { * Replaces all share-enabled sources in a source list with all shares * from this source that the current user has access to. * - * This will only sync shares that are unique to Horde (basically, a SQL - * driver source for now). Any backend that supports ACLs or similar - * mechanism should be configured from within backends.php or + * This will only sync shares that are unique to Horde (such as a SQL + * source). Any backend that supports ACLs or similar mechanism should be + * configured from within backends.php or * _horde_hook_share_* calls. * * @param array $sources The default $cfgSources array. * * @return array The $cfgSources array. */ - function getConfigFromShares($sources) + static public function getConfigFromShares(array $sources) { try { - $shares = Turba::listShares(); + $shares = self::listShares(); } catch (Horde_Share_Exception $e) { // Notify the user if we failed, but still return the $cfgSource // array. @@ -495,8 +509,10 @@ class Turba { * Retrieve a new source config entry based on a Turba share. * * @param Horde_Share object The share to base config on. + * + * @return array The $cfgSource entry for this share source. */ - function getSourceFromShare($share) + static public function getSourceFromShare(Horde_Share $share) { // Require a fresh config file. require TURBA_BASE . '/config/backends.php'; @@ -522,7 +538,7 @@ class Turba { * * @return array Shares the user has the requested permissions to. */ - function listShares($owneronly = false, $permission = Horde_Perms::READ) + static public function listShares($owneronly = false, $permission = Horde_Perms::READ) { if (!$GLOBALS['session']->get('turba', 'has_share')) { // No backends are configured to provide shares @@ -548,13 +564,13 @@ class Turba { /** * Create a new Turba share. * - * @param string $share_id The id for the new share. - * @param array $params Parameters for the new share. + * @param string $share_name The id for the new share. + * @param array $params Parameters for the new share. * * @return Horde_Share The new share object. * @throws Turba_Exception */ - static public function createShare($share_id, $params) + static public function createShare($share_name, $params) { if (!isset($params['name'])) { /* Sensible default for empty display names */ @@ -567,7 +583,7 @@ class Turba { /* Generate the new share. */ try { - $share = $GLOBALS['turba_shares']->newShare($GLOBALS['registry']->getAuth(), $share_id); + $share = $GLOBALS['turba_shares']->newShare($GLOBALS['registry']->getAuth(), $share_name); /* Set the display name for this share. */ $share->set('name', $name); @@ -588,13 +604,13 @@ class Turba { /* Update share_id as backends like Kolab change it to the IMAP folder * name. */ - $share_id = $share->getName(); + $share_name = $share->getName(); /* Add the new addressbook to the user's list of visible address * books. */ $prefs = json_decode($GLOBALS['prefs']->getValue('addressbooks'), true); - if (!is_array($prefs) || array_search($share_id, $prefs) === false) { - $prefs[] = $share_id; + if (!is_array($prefs) || array_search($share_name, $prefs) === false) { + $prefs[] = $share_name; $GLOBALS['prefs']->setValue('addressbooks', json_encode($prefs)); } @@ -604,7 +620,7 @@ class Turba { /** * Add browse.js javascript to page. */ - public function addBrowseJs() + static public function addBrowseJs() { Horde::addScriptFile('browse.js', 'turba'); Horde::addInlineJsVars(array( diff --git a/turba/lib/View/Browse.php b/turba/lib/View/Browse.php index 7aaea161a..9c69e7b79 100644 --- a/turba/lib/View/Browse.php +++ b/turba/lib/View/Browse.php @@ -11,24 +11,24 @@ * @author Chuck Hagenbuch * @package Turba */ -class Turba_View_Browse { - +class Turba_View_Browse +{ /** * @var array */ - var $_params; + protected $_params; /** * Constructor; * * @param array $params Stuff to import into the view's scope. */ - public function __construct($params) + public function __construct(array $params) { $this->_params = $params; } - function updateSortOrderFromVars() + public function updateSortOrderFromVars() { extract($this->_params, EXTR_REFS); @@ -36,7 +36,6 @@ class Turba_View_Browse { $sources = Turba::getColumns(); $columns = isset($sources[$source]) ? $sources[$source] : array(); $column_name = Turba::getColumnName($sortby, $columns); - $append = true; $ascending = ($vars->get('sortdir') == 0); if ($vars->get('sortadd')) { @@ -58,18 +57,19 @@ class Turba_View_Browse { } } - function run() + public function run() { extract($this->_params, EXTR_REFS); $this->updateSortOrderFromVars(); - $title = _("Address Book Listing"); if (!$browse_source_count && $vars->get('key') != '**search') { $notification->push(_("There are no browseable address books."), 'horde.warning'); } else { try { - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($source); + $driver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($source); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); unset($driver); @@ -78,8 +78,6 @@ class Turba_View_Browse { if (isset($driver)) { $actionID = $vars->get('actionID'); - - // Run through the action handlers. switch ($actionID) { case 'delete': $keys = $vars->get('objectkeys'); @@ -94,7 +92,7 @@ class Turba_View_Browse { if ($key && $key != '**search') { // We are removing a contact from a list. $errorCount = 0; - $list = &$driver->getObject($key); + $list = $driver->getObject($key); foreach ($keys as $sourceKey) { list($objectSource, $objectKey) = explode(':', $sourceKey, 2); if (!$list->removeMember($objectKey, $objectSource)) { @@ -102,11 +100,21 @@ class Turba_View_Browse { } } if (!$errorCount) { - $notification->push(sprintf(_("Successfully removed %d contact(s) from list."), count($keys)), 'horde.success'); + $notification->push( + sprintf(_("Successfully removed %d contact(s) from list."), + count($keys)), + 'horde.success'); } elseif (count($keys) == $errorCount) { - $notification->push(sprintf(_("Error removing %d contact(s) from list."), count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error removing %d contact(s) from list."), + count($keys)), + 'horde.error'); } else { - $notification->push(sprintf(_("Error removing %d of %d requested contact(s) from list."), $errorCount, count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error removing %d of %d requested contact(s) from list."), + $errorCount, + count($keys)), + 'horde.error'); } $list->store(); } else { @@ -121,11 +129,21 @@ class Turba_View_Browse { } } if (!$errorCount) { - $notification->push(sprintf(_("Successfully deleted %d contact(s)."), count($keys)), 'horde.success'); + $notification->push( + sprintf(_("Successfully deleted %d contact(s)."), + count($keys)), + 'horde.success'); } elseif (count($keys) == $errorCount) { - $notification->push(sprintf(_("Error deleting %d contact(s)."), count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error deleting %d contact(s)."), + count($keys)), + 'horde.error'); } else { - $notification->push(sprintf(_("Error deleting %d of %d requested contacts(s)."), $errorCount, count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error deleting %d of %d requested contacts(s)."), + $errorCount, + count($keys)), + 'horde.error'); } } break; @@ -141,7 +159,9 @@ class Turba_View_Browse { $targetSource = $vars->get('targetAddressbook'); try { - $targetDriver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($targetSource); + $targetDriver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); break; @@ -170,7 +190,9 @@ class Turba_View_Browse { // Try and load the driver for the source. try { - $sourceDriver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($objectSource); + $sourceDriver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($objectSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); continue; @@ -179,15 +201,24 @@ class Turba_View_Browse { try { $object = $sourceDriver->getObject($objectKey); } catch (Turba_Exception $e) { - $notification->push(sprintf(_("Failed to find object to be added: %s"), $e->getMessage()), 'horde.error'); + $notification->push( + sprintf(_("Failed to find object to be added: %s"), + $e->getMessage()), + 'horde.error'); continue; } if ($object->isGroup()) { if ($actionID == 'move') { - $notification->push(sprintf(_("\"%s\" was not moved because it is a list."), $object->getValue('name')), 'horde.warning'); + $notification->push( + sprintf(_("\"%s\" was not moved because it is a list."), + $object->getValue('name')), + 'horde.warning'); } else { - $notification->push(sprintf(_("\"%s\" was not copied because it is a list."), $object->getValue('name')), 'horde.warning'); + $notification->push( + sprintf(_("\"%s\" was not copied because it is a list."), + $object->getValue('name')), + 'horde.warning'); } continue; } @@ -203,7 +234,10 @@ class Turba_View_Browse { // Get 'data' value if object type is image, the // direct value in other case. - $objAttributes[$info_key] = isset($GLOBALS['attributes'][$info_key]) && $GLOBALS['attributes'][$info_key]['type'] == 'image' ? $objectValue['load']['data'] : $objectValue; + $objAttributes[$info_key] = + isset($GLOBALS['attributes'][$info_key]) && + $GLOBALS['attributes'][$info_key]['type'] == 'image' ? + $objectValue['load']['data'] : $objectValue; } } unset($objAttributes['__owner']); @@ -211,11 +245,20 @@ class Turba_View_Browse { try { $targetDriver->add($objAttributes); } catch (Turba_Exception $e) { - $notification->push(sprintf(_("Failed to add %s to %s: %s"), $object->getValue('name'), $targetDriver->title, $e), 'horde.error'); + $notification->push( + sprintf(_("Failed to add %s to %s: %s"), + $object->getValue('name'), + $targetDriver->title, + $e), + 'horde.error'); break; } - $notification->push(sprintf(_("Successfully added %s to %s"), $object->getValue('name'), $targetDriver->title), 'horde.success'); + $notification->push( + sprintf(_("Successfully added %s to %s"), + $object->getValue('name'), + $targetDriver->title), + 'horde.success'); // If we're moving objects, and we succeeded, // delete them from the original source now. @@ -223,7 +266,10 @@ class Turba_View_Browse { try { $sourceDriver->delete($objectKey); } catch (Turba_Exception $e) { - $notification->push(sprintf(_("There was an error deleting \"%s\" from the source address book."), $object->getValue('name')), 'horde.error'); + $notification->push( + sprintf(_("There was an error deleting \"%s\" from the source address book."), + $object->getValue('name')), + 'horde.error'); } /* Log the adding of this item in the history again, @@ -256,7 +302,9 @@ class Turba_View_Browse { } try { - $targetDriver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($targetSource); + $targetDriver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); break; @@ -271,7 +319,9 @@ class Turba_View_Browse { } else { $targetSource = $vars->get('targetAddressbook'); try { - $targetDriver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($targetSource); + $targetDriver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($targetSource); } catch (Turba_Exception $e) { $notification->push($e, 'horde.error'); break; @@ -288,11 +338,21 @@ class Turba_View_Browse { } } if (!$errorCount) { - $notification->push(sprintf(_("Successfully added %d contact(s) to list."), count($keys)), 'horde.success'); + $notification->push( + sprintf(_("Successfully added %d contact(s) to list."), + count($keys)), + 'horde.success'); } elseif ($errorCount == count($keys)) { - $notification->push(sprintf(_("Error adding %d contact(s) to list."), count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error adding %d contact(s) to list."), + count($keys)), + 'horde.error'); } else { - $notification->push(sprintf(_("Error adding %d of %d requested contact(s) to list."), $errorCount, count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error adding %d of %d requested contact(s) to list."), + $errorCount, + count($keys)), + 'horde.error'); } $target->store(); } @@ -304,7 +364,9 @@ class Turba_View_Browse { Horde::permissionDeniedError( 'turba', 'max_contacts', - sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), $max_contacts, $cfgSources[$source]['title']) + sprintf(_("You are not allowed to create more than %d contacts in \"%s\"."), + $max_contacts, + $cfgSources[$source]['title']) ); break; } @@ -327,7 +389,10 @@ class Turba_View_Browse { try { $target = $targetDriver->getObject($targetKey); if ($target->isGroup()) { - $notification->push(sprintf(_("Successfully created the contact list \"%s\"."), $newList['name']), 'horde.success'); + $notification->push( + sprintf(_("Successfully created the contact list \"%s\"."), + $newList['name']), + 'horde.success'); if (is_array($keys)) { $errorCount = 0; foreach ($keys as $sourceKey) { @@ -337,11 +402,21 @@ class Turba_View_Browse { } } if (!$errorCount) { - $notification->push(sprintf(_("Successfully added %d contact(s) to list."), count($keys)), 'horde.success'); + $notification->push( + sprintf(_("Successfully added %d contact(s) to list."), + count($keys)), + 'horde.success'); } elseif ($errorCount == count($keys)) { - $notification->push(sprintf(_("Error adding %d contact(s) to list."), count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error adding %d contact(s) to list."), + count($keys)), + 'horde.error'); } else { - $notification->push(sprintf(_("Error adding %d of %d requested contact(s) to list."), $errorCount, count($keys)), 'horde.error'); + $notification->push( + sprintf(_("Error adding %d of %d requested contact(s) to list."), + $errorCount, + count($keys)), + 'horde.error'); } $target->store(); } @@ -388,7 +463,11 @@ class Turba_View_Browse { $results = $list->listMembers($sortorder); if (count($results) != count($list)) { $count = count($list) - count($results); - $notification->push(sprintf(ngettext("There is %d contact in this list that is not viewable to you", "There are %d contacts in this list that are not viewable to you", $count), $count), 'horde.message'); + $notification->push( + sprintf(ngettext("There is %d contact in this list that is not viewable to you", + "There are %d contacts in this list that are not viewable to you", $count), + $count), + 'horde.message'); } $view = new Turba_View_List($results, null, $columns); $view->setType('list'); diff --git a/turba/lib/View/Contact.php b/turba/lib/View/Contact.php index 436a87a30..67213e7df 100644 --- a/turba/lib/View/Contact.php +++ b/turba/lib/View/Contact.php @@ -5,22 +5,22 @@ * @author Chuck Hagenbuch * @package Turba */ -class Turba_View_Contact { - +class Turba_View_Contact +{ /** * @var Turba_Object */ - var $contact; + public $contact; /** * @param Turba_Object &$contact */ - public function __construct(&$contact) + public function __construct(Turba_Object $contact) { - $this->contact = &$contact; + $this->contact = $contact; } - function getTitle() + public function getTitle() { if (!$this->contact) { return _("Not Found"); @@ -28,7 +28,7 @@ class Turba_View_Contact { return $this->contact->getValue('name'); } - function html($active = true) + public function html($active = true) { global $conf, $prefs, $registry; @@ -44,9 +44,12 @@ class Turba_View_Contact { /* Get the contact's history. */ $history = $this->contact->getHistory(); foreach ($history as $what => $when) { - $v = &$form->addVariable( + $v = $form->addVariable( $what == 'created' ? _("Created") : _("Last Modified"), - 'object[__' . $what . ']', 'text', false, false); + 'object[__' . $what . ']', + 'text', + false, + false); $v->disable(); $vars->set('object[__' . $what . ']', $when); } diff --git a/turba/lib/View/DeleteContact.php b/turba/lib/View/DeleteContact.php index 6e2029f5c..b7f07dd7c 100644 --- a/turba/lib/View/DeleteContact.php +++ b/turba/lib/View/DeleteContact.php @@ -1,23 +1,28 @@ * @package Turba */ -class Turba_View_DeleteContact { - - var $contact; +class Turba_View_DeleteContact +{ + /** + * @var Turba_Object + * + */ + public $contact; /** - * @param Turba_Object &$contact + * @param Turba_Object $contact */ - public function __construct($contact) + public function __construct(Turba_Object $contact) { $this->contact = $contact; } - function getTitle() + public function getTitle() { if (!$this->contact) { return _("Not Found"); @@ -25,7 +30,7 @@ class Turba_View_DeleteContact { return sprintf(_("Delete %s"), $this->contact->getValue('name')); } - function html($active = true) + public function html($active = true) { global $conf, $prefs; @@ -45,19 +50,19 @@ class Turba_View_DeleteContact { } echo ' - +
+ + + + +
+

+ " /> +
+
+ + hasFeature('dom')) { if ($this->contact->hasPermission(Horde_Perms::READ)) { $view = new Turba_View_Contact($this->contact); diff --git a/turba/lib/View/EditContact.php b/turba/lib/View/EditContact.php index 622cdb26b..976709642 100644 --- a/turba/lib/View/EditContact.php +++ b/turba/lib/View/EditContact.php @@ -5,19 +5,23 @@ * @author Chuck Hagenbuch * @package Turba */ -class Turba_View_EditContact { - - var $contact; +class Turba_View_EditContact +{ + /** + * + * @var Turba_Object + */ + public $contact; /** * @param Turba_Object $contact */ - public function __construct($contact) + public function __construct(Turba_Object $contact) { $this->contact = $contact; } - function getTitle() + public function getTitle() { if (!$this->contact) { return _("Not Found"); @@ -25,7 +29,7 @@ class Turba_View_EditContact { return sprintf(_("Edit %s"), $this->contact->getValue('name')); } - function html($active = true) + public function html($active = true) { global $conf, $prefs, $vars; @@ -45,7 +49,7 @@ class Turba_View_EditContact { } echo ''; diff --git a/turba/lib/View/List.php b/turba/lib/View/List.php index 5e141d77b..02020ebcb 100644 --- a/turba/lib/View/List.php +++ b/turba/lib/View/List.php @@ -14,84 +14,84 @@ class Turba_View_List implements Countable * * @var Turba_List */ - var $list; + public $list; /** * Show/hide "mark" column in the display. * * @var boolean */ - var $showMark = false; + public $showMark = false; /** * Show/hide "edit" column in the display. * * @var boolean */ - var $showEdit = false; + public $showEdit = false; /** * Show/hide "vcard" column in the display. * * @var boolean */ - var $showVcard = false; + public $showVcard = false; /** * Show/hide "group" column in the display. * * @var boolean */ - var $showGroup = false; + public $showGroup = false; /** * Show/hide "sort" column in the display. * * @var boolean */ - var $showSort = false; + public $showSort = false; /** * Type of list. * * @var string */ - var $type; + public $type; /** * The HTML renderer. * * @var Horde_Core_Ui_VarRenderer_Html */ - var $renderer; + public $renderer; /** * A Horde_Variables object. * * @var Horde_Variables */ - var $vars; + public $vars; /** * A list of Horde_Form_Variable objects. * * @var array */ - var $variables = array(); + public $variables = array(); /** * A dummy form object. * * @var Horde_Form */ - var $form = null; + public $form = null; /** * Which columns to render * * @var array */ - var $columns; + public $columns; /** * Constructs a new Turba_View_List object. @@ -99,8 +99,10 @@ class Turba_View_List implements Countable * @param Turba_List $list List of contacts to display. * @param array $controls Which icons to display * @param array $columns The list of columns to display + * + * @return Turba_View_List */ - function Turba_View_List(&$list, $controls = null, $columns = null) + public function __construct($list, array $controls = null, array $columns = null) { if ($controls === null) { $controls = array('Mark' => true, @@ -110,10 +112,8 @@ class Turba_View_List implements Countable 'Sort' => true); } $this->columns = $columns; - - $this->list = &$list; + $this->list = $list; $this->setControls($controls); - $this->renderer = Horde_Core_Ui_VarRenderer::factory('Html'); $this->vars = new Horde_Variables(); } @@ -123,7 +123,7 @@ class Turba_View_List implements Countable * * @param array $controls */ - function setControls($controls) + public function setControls(array $controls) { foreach ($controls as $control => $show) { $key = 'show' . $control; @@ -131,51 +131,61 @@ class Turba_View_List implements Countable } } - function setType($type) + /** + * + * @param string $type + */ + public function setType($type) { $this->type = $type; } - function getType() + /** + * + * @return string + */ + public function getType() { return $this->type; } - function display() + /** + * @TODO: these should be injected when we refactor to Horde_View + * @global $prefs + * @global $session + * @global $default_source + * @global $copymove_source_options + */ + public function display() { global $prefs, $session, $default_source, $copymove_source_options; - $driver = $GLOBALS['injector']->getInstance('Turba_Injector_Factory_Driver')->create($default_source); - + $driver = $GLOBALS['injector'] + ->getInstance('Turba_Injector_Factory_Driver') + ->create($default_source); $hasDelete = $driver->hasPermission(Horde_Perms::DELETE); $hasEdit = $driver->hasPermission(Horde_Perms::EDIT); $hasExport = ($GLOBALS['conf']['menu']['import_export'] && !empty($GLOBALS['cfgSources'][$default_source]['export'])); list($addToList, $addToListSources) = $this->getAddSources(); - $viewurl = Horde::url('browse.php')->add(array( 'key' => Horde_Util::getFormData('key'), 'url' => Horde::selfUrl(true, false, true) )); - if ($this->type == 'search') { $page = Horde_Util::getFormData('page', 0); $numitem = count($this); $maxpage = $prefs->getValue('maxpage'); $perpage = $prefs->getValue('perpage'); - $min = $page * $perpage; while ($min > $numitem) { $page--; $min = $page * $perpage; } - $max = $min + $perpage; $start = ($page * $perpage) + 1; $end = min($numitem, $start + $perpage - 1); - $listHtml = $this->getPage($numDisplayed, $min, $max); - $crit = array(); if ($session->get('turba', 'search_mode') == 'advanced') { $map = $driver->getCriteria(); @@ -194,14 +204,12 @@ class Turba_View_List implements Countable 'source' => Horde_Util::getFormData('source', $default_source) )); $viewurl = Horde::url('search.php')->add($params); - $vars = Horde_Variables::getDefaultVariables(); $pager = new Horde_Core_Ui_Pager('page', $vars, array('num' => $numitem, 'url' => $viewurl, 'page_limit' => $maxpage, 'perpage' => $perpage)); - $pagerHeader = 'numPager.inc'; } else { $page = Horde_Util::getFormData('page', '*'); @@ -214,7 +222,6 @@ class Turba_View_List implements Countable $page = 'A'; } } - $listHtml = $this->getAlpha($numDisplayed, $page); $pagerHeader = 'alphaPager.inc'; } @@ -236,9 +243,10 @@ class Turba_View_List implements Countable * rendered. * @param integer $min Minimum number of rows to display. * @param integer $max Maximum number of rows to display. + * * @return string HTML to echo. */ - function getPage(&$numDisplayed, $min = 0, $max = null) + public function getPage(&$numDisplayed, $min = 0, $max = null) { if (is_null($max)) { $max = count($this); @@ -256,7 +264,7 @@ class Turba_View_List implements Countable * * @return string HTML of the list. */ - function getAlpha(&$numDisplayed, $alpha) + public function getAlpha(&$numDisplayed, $alpha) { return $this->_get($numDisplayed, new Turba_View_List_AlphaFilter($alpha)); @@ -266,9 +274,10 @@ class Turba_View_List implements Countable * Retrieves a column's name * * @param integer $i The zero-basd index of the column + * * @return string */ - function getColumnName($i) + public function getColumnName($i) { return Turba::getColumnName($i, $this->columns); } @@ -276,7 +285,7 @@ class Turba_View_List implements Countable /** * @param integer $i The zero-based index of the column */ - function getSortInfoForColumn($i) + public function getSortInfoForColumn($i) { $sortorder = Turba::getPreferredSortOrder(); $column_name = $this->getColumnName($i); @@ -290,7 +299,14 @@ class Turba_View_List implements Countable return null; } - function getColumnSortImage($i, $title = null) + /** + * + * @param integer $i + * @param string $title + * + * @return string + */ + public function getColumnSortImage($i, $title = null) { if (is_null($title)) { $title = _("Sort Direction"); @@ -305,9 +321,10 @@ class Turba_View_List implements Countable /** * Retrieves a natural language description of the sort order + * * @return string */ - function getSortOrderDescription() + public function getSortOrderDescription() { $description = array(); $sortorder = Turba::getPreferredSortOrder(); @@ -318,18 +335,20 @@ class Turba_View_List implements Countable } $description[] = $GLOBALS['attributes'][$field]['label']; } + return join(', ', $description); } /** * @param integer $i The zero-based index of the column */ - function getColumnSortDirection($i) + public function getColumnSortDirection($i) { $result = $this->getSortInfoForColumn($i); if (is_null($result)) { return null; } + return $result['ascending'] ? 0 : 1; } @@ -337,28 +356,39 @@ class Turba_View_List implements Countable * Determines whether we are sorting on the specified column * * @param integer $i The zero-based column index + * * @return boolean */ - function isSortColumn($i) + public function isSortColumn($i) { return !is_null($this->getSortInfoForColumn($i)); } /** * Determines whether this is the first column to sort by + * * @param integer $i The zero-based column index + * * @return boolean */ - function isPrimarySortColumn($i) + public function isPrimarySortColumn($i) { $result = $this->getSortInfoForColumn($i); if (is_null($result)) { return false; } + return ($result['rank'] == 0); } - function _get(&$numDisplayed, $filter) + /** + * + * @param integer $numDisplayed + * @param object $filter A Turba_View_List filter object + * + * @return string + */ + protected function _get(&$numDisplayed, $filter) { ob_start(); $width = floor(90 / (count($this->columns) + 1)); @@ -381,7 +411,7 @@ class Turba_View_List implements Countable return ob_get_clean(); } - function getAddSources() + public function getAddSources() { global $addSources; @@ -450,53 +480,4 @@ class Turba_View_List implements Countable } -/** - * Skips objects whose name does not start with the specified letter - */ -class Turba_View_List_AlphaFilter { - - var $_alpha; - var $_format; - - function Turba_View_List_AlphaFilter($alpha) - { - $this->_alpha = Horde_String::lower($alpha); - $this->_format = $GLOBALS['prefs']->getValue('name_sort'); - } - - function skip(&$ob) - { - $name = Turba::formatName($ob, $this->_format); - if ($this->_alpha != '*' && - Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) { - return true; - } - return false; - } - -} - -/** - * Skips objects which are not on the current page - */ -class Turba_View_List_PageFilter { - - var $_min; - var $_max; - var $_count = 0; - function Turba_View_List_PageFilter($min, $max) - { - $this->_min = $min; - $this->_max = $max; - } - - function skip(&$ob) - { - if ($this->_count++ < $this->_min) { - return true; - } - return ($this->_count > $this->_max); - } - -} diff --git a/turba/lib/View/List/AlphaFilter.php b/turba/lib/View/List/AlphaFilter.php new file mode 100644 index 000000000..da02bd904 --- /dev/null +++ b/turba/lib/View/List/AlphaFilter.php @@ -0,0 +1,35 @@ + + * @author Jon Parise + * @package Turba + */ +/** + * Skips objects whose name does not start with the specified letter + */ +class Turba_View_List_AlphaFilter +{ + protected $_alpha; + protected $_format; + + public function __construct($alpha) + { + $this->_alpha = Horde_String::lower($alpha); + $this->_format = $GLOBALS['prefs']->getValue('name_sort'); + } + + public function skip($ob) + { + $name = Turba::formatName($ob, $this->_format); + if ($this->_alpha != '*' && + Horde_String::lower(substr($name, 0, 1)) != $this->_alpha) { + return true; + } + + return false; + } + +} \ No newline at end of file diff --git a/turba/lib/View/List/PageFilter.php b/turba/lib/View/List/PageFilter.php new file mode 100644 index 000000000..959439580 --- /dev/null +++ b/turba/lib/View/List/PageFilter.php @@ -0,0 +1,34 @@ + + * @author Jon Parise + * @package Turba + */ + /** + * Skips objects which are not on the current page + */ +class Turba_View_List_PageFilter +{ + protected $_min; + protected $_max; + protected $_count = 0; + + public function __construct($min, $max) + { + $this->_min = $min; + $this->_max = $max; + } + + public function skip($ob) + { + if ($this->_count++ < $this->_min) { + return true; + } + + return ($this->_count > $this->_max); + } + +} \ No newline at end of file