Strict type check prevents old config files from breaking everything (per new changes...
[squirrelmail.git] / functions / identity.php
index ade32603c17f8ae4db6a34d4b9885034e7da1375..9fd5b2619d94710f1a0af13af7bde34b1a8232ff 100644 (file)
@@ -3,27 +3,22 @@
 /**
  * identity.php
  *
- * Copyright (c) 1999-2005 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * This contains utility functions for dealing with multiple identities
  *
+ * @copyright © 1999-2006 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
+ * @since 1.4.2
  */
 
-/** Used to simplify includes */
-if (!defined('SM_PATH')) {
-    define('SM_PATH','../');
-}
-
-include_once(SM_PATH . 'include/load_prefs.php');
 
 /**
-* Returns an array of all the identities.
-* Array is keyed: full_name, reply_to, email_address, index, signature
-* @return array full_name,reply_to,email_address,index,signature
-*/
+ * Returns an array of all the identities.
+ * Array is keyed: full_name, reply_to, email_address, index, signature
+ * @return array full_name,reply_to,email_address,index,signature
+ * @since 1.4.2
+ */
 function get_identities() {
 
     global $username, $data_dir, $domain;
@@ -63,6 +58,7 @@ function get_identities() {
  * Function to save the identities array
  *
  * @param  array     $identities     Array of identities
+ * @since 1.5.1 and 1.4.5
  */
 function save_identities($identities) {
 
@@ -74,7 +70,7 @@ function save_identities($identities) {
 
 
     $num_cur = getPref($data_dir, $username, 'identities');
-    
+
     $cnt = count($identities);
 
     // Remove any additional identities in prefs //
@@ -112,6 +108,7 @@ function save_identities($identities) {
  * @param   int         $id             Identity to modify
  * @param   string      $action         Action to perform
  * @return  array
+ * @since 1.5.1 and 1.4.5
  */
 function sqfixidentities( $identities, $id, $action ) {
 
@@ -135,6 +132,10 @@ function sqfixidentities( $identities, $id, $action ) {
 
                 if ($key == $id) {
                     $fixed[0] = $ident;
+
+                    // inform plugins about renumbering of ids
+                    do_hook('options_identities_renumber', $id, 'default');
+
                     continue 2;
                 } else {
                     $fixed[$i+1] = $ident;
@@ -145,6 +146,10 @@ function sqfixidentities( $identities, $id, $action ) {
 
                 if ($key == ($id - 1)) {
                     $tmp_hold = $ident;
+
+                    // inform plugins about renumbering of ids
+                    do_hook('options_identities_renumber', $id , $id - 1);
+
                     continue 2;
                 } else {
                     $fixed[$i] = $ident;
@@ -159,14 +164,25 @@ function sqfixidentities( $identities, $id, $action ) {
             case 'delete':
 
                 if ($key == $id) {
+                    // inform plugins about deleted id
+                    do_hook('options_identities_process', $action, $id);
+
                     continue 2;
                 } else {
                     $fixed[$i] = $ident;
                 }
                 break;
 
-            // we should never hit this but just in case //
+            // Process actions from plugins and save/update action //
             default:
+                /**
+                 * send action and id information. number of hook arguments
+                 * differs from 1.4.4 or older and 1.5.0. count($args) can
+                 * be used to detect modified hook. Older hook does not
+                 * provide information that can be useful for plugins.
+                 */
+                do_hook('options_identities_process', $action, $id);
+
                 $fixed[$i] = $ident;
 
         }
@@ -185,6 +201,7 @@ function sqfixidentities( $identities, $id, $action ) {
  *
  * @param   array   $identity   Identitiy Array
  * @return  boolean
+ * @since 1.5.1 and 1.4.5
  */
 function empty_identity($ident) {
     if (empty($ident['full_name']) && empty($ident['email_address']) && empty($ident['signature']) && empty($ident['reply_to'])) {
@@ -193,5 +210,3 @@ function empty_identity($ident) {
         return false;
     }
 }
-
-?>