Documentation update
authorAndreas Boehler <andreas@aboehler.at>
Fri, 01 Jul 2016 11:29:04 +0200
changeset 16 9f92b1b42241
parent 15 efa26dde82f2
child 17 8c73076d5dcb
Documentation update
action/ajax.php
action/cache.php
action/jsinfo.php
helper.php
plugin.info.txt
syntax/book.php
--- a/action/ajax.php	Wed Jun 22 18:11:51 2016 +0200
+++ b/action/ajax.php	Fri Jul 01 11:29:04 2016 +0200
@@ -2,6 +2,8 @@
 
 /**
  * DokuWiki DAVCard PlugIn - Ajax component
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author  Andreas Böhler <dev@aboehler.at>
  */
 
 if(!defined('DOKU_INC')) die();
--- a/action/cache.php	Wed Jun 22 18:11:51 2016 +0200
+++ b/action/cache.php	Fri Jul 01 11:29:04 2016 +0200
@@ -1,7 +1,9 @@
 <?php
 
 /**
- * DokuWiki DAVCal PlugIn - Ajax component
+ * DokuWiki DAVCal PlugIn - Cache component
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author  Andreas Böhler <dev@aboehler.at>
  */
 
 if(!defined('DOKU_INC')) die();
--- a/action/jsinfo.php	Wed Jun 22 18:11:51 2016 +0200
+++ b/action/jsinfo.php	Fri Jul 01 11:29:04 2016 +0200
@@ -2,6 +2,8 @@
 
 /**
  * DokuWiki DAVCard PlugIn - JSINFO component
+ * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+ * @author  Andreas Böhler <dev@aboehler.at>
  */
  
 if(!defined('DOKU_INC')) die();
--- a/helper.php	Wed Jun 22 18:11:51 2016 +0200
+++ b/helper.php	Fri Jul 01 11:29:04 2016 +0200
@@ -2,7 +2,8 @@
 /** 
   * Helper Class for the DAVCard plugin
   * This helper does the actual work.
-  * 
+  * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
+  * @author  Andreas Böhler <dev@aboehler.at>
   */
   
 // must be run within Dokuwiki
@@ -36,6 +37,15 @@
     }
   }
   
+  /**
+   * Retrieve a contact by specifying details like the name
+   * 
+   * @param int $id The address book ID
+   * @param string $type The type to look for
+   * @param array $params The parameter array
+   * 
+   * @return array An array containing the results
+   */
   private function getContactByDetails($id, $type, $params = array())
   {
     $write = false;
@@ -116,6 +126,14 @@
     return array('formattedname' => sprintf($this->getLang('contact_not_found'), $this->getLang('invalid_options')), 'result' => false);
   }
 
+
+  /**
+   * Retreive all address book entries
+   * 
+   * @param int $id The addressbook ID to retrieve
+   * 
+   * @return array All address book entries
+   */
   public function getAddressbookEntries($id)
   {
       $query = "SELECT contactdata, uri, formattedname, structuredname FROM addressbookobjects WHERE addressbookid = ? ORDER BY formattedname ASC";
@@ -123,23 +141,56 @@
       return $this->sqlite->res2arr($res);
   }
  
+  /**
+   * Retrieve a contact by the structured name
+   * 
+   * @param string $id The addressbook ID to work with
+   * @param string $firstname The contact's first name
+   * @param string $lastname The contact's last name
+   * 
+   * @return array The contact's details
+   */
   public function getContactByStructuredName($id, $firstname = '', $lastname = '')
   {
     return $this->getContactByDetails($id, 'structuredname', 
         array('firstname' => strtolower($firstname), 'lastname' => strtolower($lastname)));
   }
 
+  /**
+   * Retrieve a contact by e-mail address
+   * 
+   * @param string $id The address book ID
+   * @param string $email The E-Mail address
+   * 
+   * @return array The contact's details
+   */
   public function getContactByEmail($id, $email)
   {
       // FIXME: Maybe it's a good idea to save the e-mail in the database as well!
       return $this->getContactByDetails($id, 'email', array('email' => strtolower($email)));
   }
    
+  /**
+   * Retrieve a contact by formatted name
+   * 
+   * @param string $id The address book  ID
+   * @param string $name The contact's formatted name
+   * 
+   * @return array The contact's details
+   */
   public function getContactByFormattedName($id, $name)
   {
       return $this->getContactByDetails($id, 'formattedname', array('formattedname' => strtolower($name)));
   }
   
+  /**
+   * Retrieve a contact object by its URI
+   * 
+   * @param string $ID The address book ID
+   * @param string $uri The object URI
+   * 
+   * @return array An array containing the result
+   */
   public function getContactByUri($id, $uri)
   {
     $write = false;
@@ -185,6 +236,14 @@
     return $info;
   }
   
+  /**
+   * Retrieve an address book entry by URI (low-level version)
+   * 
+   * @param int $id The address book ID
+   * @param string $uri The object URI
+   * 
+   * @return array The contact's details
+   */
   private function getAddressbookEntryByUri($id, $uri)
   {
       $query = "SELECT contactdata, addressbookid, etag, uri, formattedname, structuredname FROM addressbookobjects WHERE addressbookid = ? AND uri = ?";
@@ -192,7 +251,16 @@
       return $this->sqlite->res2row($res);
   }
   
-  
+  /**
+   * Set the addressbook name for a given page
+   * 
+   * @param string $name The name to set
+   * @param string $description The address book description
+   * @param int $id (optional) The page ID
+   * @param string $userid (optional) The user's ID
+   * 
+   * @return boolean true on success, otherwise false 
+   */
   public function setAddressbookNameForPage($name, $description, $id = null, $userid = null)
   {
       if(is_null($id))
@@ -222,6 +290,13 @@
       return false;
   }
   
+  /**
+   * Get the address book ID associated with a given page
+   * 
+   * @param string $id (optional) The page ID
+   * 
+   * @return mixed The address book ID or false
+   */
   public function getAddressbookIdForPage($id = null)
   {
       if(is_null($id))
@@ -235,12 +310,22 @@
       $row = $this->sqlite->res2row($res);
       if(isset($row['addressbookid']))
       {
-        $calid = $row['addressbookid'];
-        return $calid;
+        $addrbkid = $row['addressbookid'];
+        return $addrbkid;
       }
       return false;
   }
   
+  /**
+   * Create a new address book for a given page
+   * 
+   * @param string $name The name of the new address book
+   * @param string $description The address book's description
+   * @param string $id (optional) The page ID
+   * @param string $userid (optional) The user's ID
+   * 
+   * @return boolean True on success, otherwise false
+   */
   public function createAddressbookForPage($name, $description, $id = null, $userid = null)
   {
       if(is_null($id))
@@ -287,6 +372,15 @@
       return false;
   }
 
+  /**
+   * Delete a contact entry from an address book by URI
+   * 
+   * @param string $id The address book ID
+   * @param string $user The user's ID
+   * @param string $uri The object URI to delete
+   * 
+   * @return boolean True on success, otherwise false
+   */
   public function deleteContactEntryToAddressbookForPage($id, $user, $uri)
   {
       if(strpos($id, 'webdav://') === 0)
@@ -306,10 +400,7 @@
       }
       
       $addressbookid = $this->getAddressbookIdForPage($id);
-      dbglog($addressbookid);
-      dbglog($uri);
       $query = "DELETE FROM addressbookobjects WHERE uri = ? AND addressbookid = ?";
-            dbglog($query);
       
       $res = $this->sqlite->query($query, $uri, $addressbookid);
       if($res !== false)
@@ -320,6 +411,16 @@
       return false;
   }
 
+  /**
+   * Edit a contact for a given address book
+   * 
+   * @param string $id The address book ID
+   * @param string $user The user name
+   * @param string $uri The object URI
+   * @param array $params The new address book parameters
+   * 
+   * @return boolean True on success, otherwise false
+   */
   public function editContactEntryToAddressbookForPage($id, $user, $uri, $params)
   {
       require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
@@ -410,6 +511,15 @@
       return false;
   }
   
+  /**
+   * Add a new contact entry to an address book page
+   * 
+   * @param string $id The page ID
+   * @param string $user The user ID
+   * @param array $params The entry's parameters
+   * 
+   * @return boolean True on success, otherwise false
+   */
   public function addContactEntryToAddressbookForPage($id, $user, $params)
   {
       require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
@@ -477,6 +587,15 @@
       return false;
   }
   
+  /**
+   * Parse a VCard and extract important contact information
+   * 
+   * @param string $card The VCard data
+   * @param string $uri The object URI
+   * @param boolean $write Writable
+   * 
+   * @return array An array with parsed data
+   */
   public function parseVcard($card, $uri, $write)
   {
     require_once(DOKU_PLUGIN.'davcard/vendor/autoload.php');
@@ -581,6 +700,13 @@
     );
   }
 
+  /**
+   * Retrieve the settings of a given address book
+   * 
+   * @param int $addressbookid The addressbook's ID
+   * 
+   * @return array The settings
+   */
   public function getAddressbookSettings($addressbookid)
   {
       $query = "SELECT id, principaluri, displayname, uri, description, synctoken FROM addressbooks WHERE id= ? ";
@@ -589,6 +715,13 @@
       return $row;
   }
 
+  /**
+   * Retrieve the current synctoken for an address book
+   * 
+   * @param int $addressbookid The addressbook's ID
+   * 
+   * @return string The current synctoken
+   */
   public function getSyncTokenForAddressbook($addressbookid)
   {
       $row = $this->getAddressbookSettings($addressbookid);
@@ -621,6 +754,16 @@
       }
       return false;
   }
+  
+  /**
+   * Update the synctoken log for a given address book
+   * 
+   * @param string $addressbookid The addressbook ID to work with
+   * @param string $uri The object URI that was modified
+   * @param string $operation The operation that was performed
+   * 
+   * @return boolean True on success, otherwise false
+   */
   private function updateSyncTokenLog($addressbookid, $uri, $operation)
   {
       $currentToken = $this->getSyncTokenForAddressbook($addressbookid);
--- a/plugin.info.txt	Wed Jun 22 18:11:51 2016 +0200
+++ b/plugin.info.txt	Fri Jul 01 11:29:04 2016 +0200
@@ -1,7 +1,7 @@
 base	davcard
 author  Andreas Boehler
 email   dev@aboehler.at
-date    2016-05-28
+date    2016-07-01
 name    Addressbook PlugIn with CardDAV client support
 desc    Show contact information from a CardDAV address book (needs webdavclient)
 url     http://www.dokuwiki.org/plugin:davcard
--- a/syntax/book.php	Wed Jun 22 18:11:51 2016 +0200
+++ b/syntax/book.php	Fri Jul 01 11:29:04 2016 +0200
@@ -183,7 +183,7 @@
             }
             foreach($entries as $entry)
             {
-                $contactdata = $this->hlp->parseVcard($entry['contactdata'], $entry['uri']);
+                $contactdata = $this->hlp->parseVcard($entry['contactdata'], $entry['uri'], $write);
                 if(!$this->contactFilterMatch($data['filter'], $contactdata))
                     continue;
                 $R->doc .= '<tr><td><a href="#" class="plugin_davcard_edit_vcard" data-davcardid="'.$id.'" data-davcarduri="'.$entry['uri'].'" data-write="'.($write ? 'true' : 'false').'">'.$entry['formattedname'].'</a></td><td>';
@@ -248,6 +248,14 @@
         
     }
 
+/**
+ * Check if a contact matches a given filter pattern
+ * 
+ * @param array $filter The filter array
+ * @param array $contactdata The contact's data to match
+ * 
+ * @return true on success, otherwise false
+ */
     private function contactFilterMatch($filter, $contactdata)
     {
         if(empty($filter))