[dev] Turba and IMSP patch

Michael Rubinsky mike at theupstairsroom.com
Sun Oct 24 17:43:12 PDT 2004


The following (finally) patches the Net_IMSP framework package and the 
Turba imsp driver for the following:

Advanced search in turba now works correctly for IMSP sources - the driver 
now supports searching on multiple fields.  Searching on composite fields 
is still not functioning properly.  I need to get the time to implement an 
"OR" search in the driver since the IMSP server itself does not support OR 
searches.

Contact ownership now functions more in-line with the rest of the turba 
drivers.  Added a driver parameter to allow turning off turba's contact 
ownership to better support IMSP addressbooks that may be used with 
multiple types of clients.

Thanks -
Mike
-------------- next part --------------
Index: IMSP/Book.php===================================================================RCS file: /repository/framework/Net_IMSP/IMSP/Book.php,vretrieving revision 1.14diff -r1.14 Book.php159,160c159,160<      * @param string $search Search criteria (may include * wild card).<      * @param optional string  $search_field Name of IMSP field to search on.--->      * @param string Array $search Search criteria in the form of>      *        'fieldName' => 'searchTerm' (may include * wild card).163,164c163,172<     function search($abook, $search, $search_field = 'name')<     {--->     function search($abook, $search)>     {   >         //If no field => value pairs, assume we are searching name.>         $criteria = array();>         if (!is_array($search)) {>             $criteria['name'] = $search;>         } else {>             $criteria = $search;>         }> 186c194,195<         $result = $this->_imsp->imspSend("$abook $search_field ",false,false);--->         //Start parsing the search array.>         $result = $this->_imsp->imspSend("$abook", false, false);190,195c199,203< <         // How about the search term as a {}.<         if (preg_match(IMSP_MUST_USE_LITERAL, $search)){<             $biSearch = sprintf("{%d}",strlen($search));< <             $result = $this->_imsp->imspSend($biSearch,false,true);--->         >         $count = count($criteria);>         $current = 1;>         foreach ($criteria as $search_field => $search){>             $result = $this->_imsp->imspSend(" $search_field ",false,false);200,214c208,235<             if (!preg_match(IMSP_COMMAND_CONTINUATION_RESPONSE<                             , $this->_imsp->imspReceive())) {< <                 return $this->_imsp->imspError(IMSP_NO_CONTINUATION_RESPONSE,<                                                __FILE__,__LINE__);<             }< <            $result = $this->_imsp->imspSend($search,false,true);<            if (is_a($result, 'PEAR_Error')) {<                return $result;<            }<         } else {<             $result = $this->_imsp->imspSend('"' . $search . '"',false,true);<             if (is_a($result, 'PEAR_Error')) {<                 return $result;--->             // How about the search term as a {}.>             if (preg_match(IMSP_MUST_USE_LITERAL, $search)){>                 $biSearch = sprintf("{%d}",strlen($search));>     >                 $result = $this->_imsp->imspSend($biSearch,false,true);>                 if (is_a($result, 'PEAR_Error')) {>                     return $result;>                 }>     >                 if (!preg_match(IMSP_COMMAND_CONTINUATION_RESPONSE>                                 , $this->_imsp->imspReceive())) {>     >                     return $this->_imsp->imspError(IMSP_NO_CONTINUATION_RESPONSE,>                                                    __FILE__,__LINE__);>                 }>     >                $result = $this->_imsp->imspSend($search,false,$current == $count);>                $current++;>                if (is_a($result, 'PEAR_Error')) {>                    return $result;>                }>             } else {>                 //Only send the CrLf if this is the last field/search atom..>                 $result = $this->_imsp->imspSend('"' . $search . '"', false, $current == $count);>                 $current++;>                 if (is_a($result, 'PEAR_Error')) {>                     return $result;>                 }217a239>         //Get the response
-------------- next part --------------
Index: config/sources.php.dist===================================================================RCS file: /repository/turba/config/sources.php.dist,vretrieving revision 1.91diff -r1.91 sources.php.dist424a425,430>  * >  * If you wish to keep track of ownership of individual contacts, set>  * 'contact_ownership' = true.  Note that entries created using other clients>  * will not be created this way and will therefore have no 'owner'.>  * Set 'contact_ownership' = false and the __owner field will be >  * automatically populated with the current username.426d431< 449c454,455<         'group_id_value' => 'group'--->         'group_id_value' => 'group',> 	    'contact_ownership' => false454a461>         '__owner' => '__owner',463c470,471<         'cellPhone' => 'cellphone'--->         'cellPhone' => 'cellphone',>         'freebusyUrl' => 'freebusyUrl'Index: lib/Driver/imsp.php===================================================================RCS file: /repository/turba/lib/Driver/imsp.php,vretrieving revision 1.18diff -r1.18 imsp.php98c98,102<     {--->     {   >         $query = array();>         $results = array();>         $hasName = false;>         104d107<         $results = array();108,114c111,119<         $temp = array_values($criteria);<         if (count($criteria)) {<             $searchField = $temp[0][0]['field'];<             $searchValue = $temp[0][0]['test'];<         } else {<             $searchField = 'name';<             $searchValue = '';--->         $imspSearch = array();>         if (count($criteria)){>             foreach($criteria as $key => $vals){>                 if (strval($key) == 'OR') {>                     //Don't support OR yet>                 } elseif (strval($key) == 'AND') {>                    $query = $this->_getSearch($vals);>                 }>             }117,132c122,136<         /* Make sure the searchvalue isn't FullName, since fullname is<          * created dynamically. */<         if ($searchField == 'fullname') {<             $searchField = 'name';<         }< <         /**<          * Are we searching for only Turba_Groups or Turba_Objects?<          * This is needed so the 'Show Lists' and 'Show Contacts' links<          * work correctly in Turba.<          */<         if ($searchField == '__type') {<             switch ($searchValue) {<             case 'Group':<                 $searchField = $this->_groupField;<                 $searchValue = $this->_groupValue;--->         for ($current = 0; $current < count($query); $current++) {>             $temp = $query[$current];>             $searchkey = $temp['field'];>             $searchval = $temp['test'];>             $searchop = $temp['op'];> >             //Now make sure we aren't searching on a dynamically created field>             switch ($searchkey){>             case 'fullname':>                 if (!$hasName){>                     $searchkey = 'name';>                     $hasName = true;>                 } else {>                     $searchkey = '';>                 }134,137c138,142<             case 'Object':<                 $searchField = 'name';<                 $searchValue = '';<                 $noGroups = true;--->                 >             case '__owner':>                 if (!$this->params['contact_ownership']){>                     continue 2;>                 }140d144<         }142,147c146,168<         /* If there is no searchValue than only use the wildcard. */<         if (strlen($searchValue) > 0 ) {<             $searchValue = '*' . $searchValue . '*';<         } else {<             $searchValue = '*';<         }--->             /**>              * Are we searching for only Turba_Groups or Turba_Objects?>              * This is needed so the 'Show Lists' and 'Show Contacts' links>              * work correctly in Turba.>              */>             if ($searchkey == '__type') {>                 switch ($searchval) {>                 case 'Group':>                     $searchkey = $this->_groupField;>                     $searchval = $this->_groupValue;>                     break;>                 case 'Object':>                     if (!$hasName){>                         $searchkey = 'name';>                         $searchval = '';>                         $hasName = true;>                     } else {>                         $searchkey = '';>                     }>                     $noGroups = true;>                     break;>                 }>             }149,150c170,187<         $names = $this->_imsp->search($this->_bookName, $searchValue,<                                       $searchField);--->             if (!$searchkey == ''){>                 //Check the searchval for content and for strict matches.>                 if (strlen($searchval) > 0 ) {>                     if ($searchop == 'LIKE'){ >                         $searchval = '*' . $searchval . '*';>                     }>                 } else {>                     $searchval = '*';>                 }>                 $imspSearch[$searchkey] = $searchval;>             }>         }>         if (!count($imspSearch)) {>             $imspSearch['name'] = '*';>         }>  >         //Finally get to the command.>         $names = $this->_imsp->search($this->_bookName, $imspSearch);158a196> 193a232>         $result = array();201c240,243< --->                 if (!isset($temp['__owner'])) {>                     $temp['__owner'] = Auth::getAuth();>                 }>                 244a287> 281d323< 284a327,329>         if (!$this->params['contact_ownership']){>             unset($attributes['__owner']);>         }301c346<      * @param string $object_id   (Ignored) the value of the key field.--->      * @param string $object_id   The value of the key field.347a393,430>     >     /**>      * Get the search criteria.>      * >      * @param $attributes array containing the turba search attribtes.>      * @return array containing arrays of search criteria.>      */>      function _getSearch($attributes){>          $search = array();>          foreach ($attributes as $key=>$values) {>              if (!empty($values['OR'])) {>                  //Not supported yet.>              } elseif (!empty($values['AND'])) {>                  $temp = $this->_getSearch($values);>                  for ($i=0; $i<count($temp); $i++) {>                      $search[] = $temp[$i];>                  }>              } else {>                  if (isset($values['field'])){>                      $search[] = $values;>                  } else {>                      foreach ($values as $test) {>                          if (!empty($test['OR'])) {>                              //not supported yet>                          } elseif (!empty($test['AND'])) {>                              $temp = $this->_getSearch($test);>                              for ($i=0; $i<count($temp); $i++){>                                  $search[] = $temp[$i];>                              }>                          } else {>                              $search[] = $test;>                          }>                      }>                  }>              }>          }>          return $search;>      }


More information about the dev mailing list