Fix a few bugs and add possibility to display the search term when a contact was not found
authorAndreas Boehler <andreas@aboehler.at>
Tue, 31 May 2016 21:14:06 +0200
changeset 12 07dcd1321cd8
parent 11 c6719230ba09
child 13 2bbc76ec1944
Fix a few bugs and add possibility to display the search term when a contact was not found
action/ajax.php
helper.php
lang/en/lang.php
style.css
syntax/card.php
--- a/action/ajax.php	Sat May 28 16:30:26 2016 +0200
+++ b/action/ajax.php	Tue May 31 21:14:06 2016 +0200
@@ -80,7 +80,7 @@
               else
               {
                   $data['result'] = false;
-                  $data['html'] = $this->getLang('contact_not_found');
+                  $data['html'] = sprintf($this->getLang('contact_not_found'), 'ID='.$id.' URI='.$params['uri']);
               }
           break;
 
@@ -112,6 +112,10 @@
           case 'getContactAjax':
               $contactdata = $this->hlp->getContactByUri($id, $params['uri']);
               $cardpattern = $this->getConf('popup_content');
+              if($contactdata['result'] === false)
+              {
+                  echo hsc($contactdata['formattedname']);
+              }
               echo '<div class="plugin_davcard_popup_container">';
               foreach($contactdata['photo'] as $data)
               {
@@ -127,24 +131,24 @@
                   if($type == 'png')
                   {
                       $imgdata = 'data:image/png;base64,'.$imgdata;
-                      echo '<img src="'.$imgdata.'" alt="contact image" />';
+                      echo '<img src="'.hsc($imgdata).'" alt="contact image" />';
                   }
                   // JPEG images
                   elseif(($type == 'jpeg') || ($type == 'jpg'))
                   {
                       $imgdata = 'data:image/jpeg;base64,'.$imgdata;
-                      echo '<img src="'.$imgdata.'" alt="contact image" />';
+                      echo '<img src="'.hsc($imgdata).'" alt="contact image" />';
                   }
                   // GIF images
                   elseif($type == 'gif')
                   {
                       $imgdata = 'data:image/gif;base64,'.$imgdata;
-                      echo '<img src="'.$imgdata.'" alt="contact image" />';
+                      echo '<img src="'.hsc($imgdata).'" alt="contact image" />';
                   }
                   // URLs (no type given)
                   elseif(preg_match( $pattern, $string ) == 1)
                   {
-                      echo '<img src="'.$data['photo'].'" alt="contact image" />';
+                      echo '<img src="'.hsc($data['photo']).'" alt="contact image" />';
                   }
                   echo '</div>';
               }
--- a/helper.php	Sat May 28 16:30:26 2016 +0200
+++ b/helper.php	Tue May 31 21:14:06 2016 +0200
@@ -64,8 +64,8 @@
         {
             case 'structuredname':
                 $contactdata = explode(';', strtolower($entry['structuredname']));
-                if(count($contactdata) < 2) // We need at least first and lat name
-                    return array('formattedname' => $this->getLang('contact_not_found'));
+                if(count($contactdata) < 2) // We need at least first and last name
+                    return array('formattedname' => sprintf($this->getLang('contact_not_found'), $params['firstname']. ' '.$params['lastname']));
                 if(($params['lastname'] != '') && 
                     ($contactdata[0] === $params['lastname']) 
                     || $params['lastname'] === '')
@@ -98,7 +98,7 @@
             break;
         }
     }
-    return array('formattedname' => $this->getLang('contact_not_found'));
+    return array('formattedname' => sprintf($this->getLang('contact_not_found'), $this->getLang('invalid_options')), 'result' => false);
   }
 
   public function getAddressbookEntries($id)
@@ -149,7 +149,7 @@
     }
     
     if($row === false)
-        return array('formattedname' => $this->getLang('contact_not_found'), 'result' => false);
+        return array('formattedname' => sprintf($this->getLang('contact_not_found'), 'ID='.$id.' URI='.$uri), 'result' => false);
     $info = $this->parseVcard($row['contactdata'], $row['uri']);
     $info['result'] = true;
     return $info;
@@ -547,6 +547,7 @@
         'note' => $note,
         'title' => $title,
         'url' => $url,
+        'result' => true
     );
   }
 
--- a/lang/en/lang.php	Sat May 28 16:30:26 2016 +0200
+++ b/lang/en/lang.php	Tue May 31 21:14:06 2016 +0200
@@ -10,10 +10,11 @@
 $lang['no_wdc'] = 'Loading webdavclient PlugIn failed.';
 $lang['settings_not_found'] = 'The requested WebDAV connection was not found';
 $lang['wrong_type'] = 'The requested WebDAV connection is not of type contact';
-$lang['contact_not_found'] = 'The requested contact was not found';
+$lang['contact_not_found'] = 'The requested contact (%s) was not found';
 $lang['error_adding'] = 'Error adding contact';
 $lang['error_editing'] = 'Error editing contact';
 $lang['error_deleting'] = 'Error deleting contact';
+$lang['invalid_options'] = 'invalid options given';
 $lang['telvoice'] = 'Voice';
 $lang['telhome'] = 'Home';
 $lang['telmsg'] = 'Message';
--- a/style.css	Sat May 28 16:30:26 2016 +0200
+++ b/style.css	Tue May 31 21:14:06 2016 +0200
@@ -3,7 +3,6 @@
 div.dokuwiki a.plugin_davcard_url:hover,
 div.dokuwiki a.plugin_davcard_url:visited {
     position: relative;
-    padding-left: 18px;
     z-index: 10;
 }
 
--- a/syntax/card.php	Sat May 28 16:30:26 2016 +0200
+++ b/syntax/card.php	Tue May 31 21:14:06 2016 +0200
@@ -119,27 +119,31 @@
         
         
         $contactdata = array();
-
+        $srch = '';
         if($data['name'] !== '')
         {
             $contactdata = $this->hlp->getContactByFormattedName($data['id'], $data['name']);
+            $srch = $data['name'];
         }
         elseif(($data['firstname'] !== '') || ($data['lastname'] !== ''))
         {
             $contactdata = $this->hlp->getContactByStructuredName($data['id'], $data['firstname'], $data['lastname']);
+            $srch = $data['firstname'].' '.$data['lastname'];
         }
         elseif(($data['email'] !== ''))
         {
             $contactdata = $this->hlp->getContactByEmail($data['id'], $data['email']);
+            $srch = 'E-Mail = '.$data['email'];
         }
         elseif(($data['uri'] !== ''))
         {
             $contactdata = $this->hlp->getContactByUri($data['id'], $data['uri']);
+            $srch = 'URI = '.$data['uri'];
         }
-        if($contactdata === false)
+        if($contactdata['result'] === false)
         {
-            $contactdata['formattedname'] = $this->getLang('contact_not_found');
-            $contactdata['uri'] = '';
+            $R->doc .= sprintf($this->getLang('contact_not_found'), $srch);
+            return;
         }
         
         $R->doc .= '<a class="url fn plugin_davcard_url" href="#" data-davcarduri="'