]> git.mxchange.org Git - friendica.git/commitdiff
user contacts: fix #797 , add searching in url and nickname, add batch actions
authorFabrixxm <fabrix.xm@gmail.com>
Tue, 17 Dec 2013 10:19:06 +0000 (05:19 -0500)
committerFabrixxm <fabrix.xm@gmail.com>
Tue, 17 Dec 2013 10:19:06 +0000 (05:19 -0500)
include/Contact.php
mod/contacts.php
view/templates/contact_template.tpl
view/templates/contacts-template.tpl
view/theme/duepuntozero/style.css
view/theme/quattro/dark/style.css
view/theme/quattro/green/style.css
view/theme/quattro/lilac/style.css
view/theme/quattro/quattro.less
view/theme/quattro/templates/contact_template.tpl

index ce1edbcc2164cc2336047fcfc9b08dcc1449037d..af77869989713c4fec3ae266b0d2859f411240e7 100644 (file)
@@ -215,13 +215,14 @@ function contact_photo_menu($contact) {
                $status_link = $profile_link . "?url=status";
                $photos_link = $profile_link . "?url=photos";
                $profile_link = $profile_link . "?url=profile";
-               $contact_drop_link = $a->get_baseurl() . '/contacts/' . $contact['id'] . '/drop';
                $pm_url = $a->get_baseurl() . '/message/new/' . $contact['id'];
        }
 
        $poke_link = $a->get_baseurl() . '/poke/?f=&c=' . $contact['id'];
        $contact_url = $a->get_baseurl() . '/contacts/' . $contact['id'];
        $posts_link = $a->get_baseurl() . '/network/0?nets=all&cid=' . $contact['id'];
+       $contact_drop_link = $a->get_baseurl() . "/contacts/" . $contact['id'] . '/drop?confirm=1';
+       
 
        $menu = Array(
                'poke' => array(t("Poke"), $poke_link),
index a405cedbc6329b6d80cf937a8788b0b67c39d9c7..d19c75ab9694dffe99ccdde4143c3399bf1d1f15 100644 (file)
@@ -67,11 +67,61 @@ function contacts_init(&$a) {
 
 }
 
+function contacts_batch_actions(&$a){
+       $contacts_id = $_POST['contact_batch'];
+       if (!is_array($contacts_id)) return;
+       
+       $orig_records = q("SELECT * FROM `contact` WHERE `id` IN (%s) AND `uid` = %d AND `self` = 0",
+               implode(",", $contacts_id),
+               intval(local_user())
+       );
+       
+       $count_actions=0;
+       foreach($orig_records as $orig_record) {
+               $contact_id = $orig_record['id'];
+               if (x($_POST, 'contacts_batch_update')) {
+                       _contact_update($contact_id);
+                       $count_actions++;
+               }
+               if (x($_POST, 'contacts_batch_block')) {
+                       $r  = _contact_block($contact_id, $orig_record);
+                       if ($r) $count_actions++;
+               }
+               if (x($_POST, 'contacts_batch_ignore')) {
+                       $r = _contact_ignore($contact_id, $orig_record);
+                       if ($r) $count_actions++;
+               }
+               if (x($_POST, 'contacts_batch_archive')) {
+                       $r = _contact_archive($contact_id, $orig_record);
+                       if ($r) $count_actions++;
+               }
+               if (x($_POST, 'contacts_batch_drop')) {
+                       _contact_drop($contact_id, $orig_record);
+                       $count_actions++;
+               }
+       }
+       if ($count_actions>0) {
+               info ( sprintf( tt("%d contact edited.", "%d contacts edited", $count_actions), $count_actions) );
+       }
+       
+       if(x($_SESSION,'return_url'))
+               goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
+       else
+               goaway($a->get_baseurl(true) . '/contacts');
+
+}
+
+
 function contacts_post(&$a) {
        
        if(! local_user())
                return;
 
+       if ($a->argv[1]==="batch") {
+               contacts_batch_actions($a);
+               return;
+       }
+
        $contact_id = intval($a->argv[1]);
        if(! $contact_id)
                return;
@@ -134,6 +184,49 @@ function contacts_post(&$a) {
 
 }
 
+/*contact actions*/
+function _contact_update($contact_id) {
+       // pull feed and consume it, which should subscribe to the hub.
+       proc_run('php',"include/poller.php","$contact_id"); 
+}
+function _contact_block($contact_id, $orig_record) {
+       $blocked = (($orig_record['blocked']) ? 0 : 1);
+       $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
+               intval($blocked),
+               intval($contact_id),
+               intval(local_user())
+       );
+       return $r;
+
+}
+function _contact_ignore($contact_id, $orig_record) {
+       $readonly = (($orig_record['readonly']) ? 0 : 1);
+       $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
+               intval($readonly),
+               intval($contact_id),
+               intval(local_user())
+       );
+       return $r;
+}
+function _contact_archive($contact_id, $orig_record) {
+       $archived = (($orig_record['archive']) ? 0 : 1);
+       $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
+               intval($archived),
+               intval($contact_id),
+               intval(local_user())
+       );
+       if ($archived) {
+               q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
+       }
+       return $r;
+}
+function _contact_drop($contact_id, $orig_record) {
+       require_once('include/Contact.php');
+       $a = get_app();
+
+       terminate_friendship($a->user,$a->contact,$orig_record);
+       contact_remove($orig_record['id']);
+}
 
 
 function contacts_content(&$a) {
@@ -168,57 +261,38 @@ function contacts_content(&$a) {
                }
                
                if($cmd === 'update') {
-
-                       // pull feed and consume it, which should subscribe to the hub.
-                       proc_run('php',"include/poller.php","$contact_id");
+                       _contact_update($contact_id);
                        goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
                        // NOTREACHED
                }
 
                if($cmd === 'block') {
-                       $blocked = (($orig_record[0]['blocked']) ? 0 : 1);
-                       $r = q("UPDATE `contact` SET `blocked` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval($blocked),
-                               intval($contact_id),
-                               intval(local_user())
-                       );
+                       $r = _contact_block($contact_id, $orig_record[0]);
                        if($r) {
-                               //notice( t('Contact has been ') . (($blocked) ? t('blocked') : t('unblocked')) . EOL );
                                info( (($blocked) ? t('Contact has been blocked') : t('Contact has been unblocked')) . EOL );
                        }
+                       
                        goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
                        return; // NOTREACHED
                }
 
                if($cmd === 'ignore') {
-                       $readonly = (($orig_record[0]['readonly']) ? 0 : 1);
-                       $r = q("UPDATE `contact` SET `readonly` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval($readonly),
-                               intval($contact_id),
-                               intval(local_user())
-                       );
+                       $r = _contact_ignore($contact_id, $orig_record[0]);
                        if($r) {
                                info( (($readonly) ? t('Contact has been ignored') : t('Contact has been unignored')) . EOL );
                        }
+                       
                        goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
                        return; // NOTREACHED
                }
 
 
                if($cmd === 'archive') {
-                       $archived = (($orig_record[0]['archive']) ? 0 : 1);
-                       $r = q("UPDATE `contact` SET `archive` = %d WHERE `id` = %d AND `uid` = %d LIMIT 1",
-                               intval($archived),
-                               intval($contact_id),
-                               intval(local_user())
-                       );
-                       if ($archived) {
-                               q("UPDATE `item` SET `private` = 2 WHERE `contact-id` = %d AND `uid` = %d", intval($contact_id), intval(local_user()));
-                       }
+                       $r = _contact_archive($contact_id, $orig_record[0]);
                        if($r) {
-                               //notice( t('Contact has been ') . (($archived) ? t('archived') : t('unarchived')) . EOL );
                                info( (($archived) ? t('Contact has been archived') : t('Contact has been unarchived')) . EOL );
-                       }
+                       }                       
+                       
                        goaway($a->get_baseurl(true) . '/contacts/' . $contact_id);
                        return; // NOTREACHED
                }
@@ -251,15 +325,13 @@ function contacts_content(&$a) {
                        }
                        // Now check how the user responded to the confirmation query
                        if($_REQUEST['canceled']) {
-                               goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
-
+                               if(x($_SESSION,'return_url'))
+                                       goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
+                               else
+                                       goaway($a->get_baseurl(true) . '/contacts');
                        }
 
-                       require_once('include/Contact.php');
-
-                       terminate_friendship($a->user,$a->contact,$orig_record[0]);
-
-                       contact_remove($orig_record[0]['id']);
+                       _contact_drop($contact_id, $orig_record[0]);
                        info( t('Contact has been removed.') . EOL );
                        if(x($_SESSION,'return_url'))
                                goaway($a->get_baseurl(true) . '/' . $_SESSION['return_url']);
@@ -526,7 +598,7 @@ function contacts_content(&$a) {
                $search_txt = dbesc(protect_sprintf(preg_quote($search)));
                $searching = true;
        }
-       $sql_extra .= (($searching) ? " AND `name` REGEXP '$search_txt' " : "");
+       $sql_extra .= (($searching) ? " AND (name REGEXP '$search_txt' OR url REGEXP '$search_txt'  OR nick REGEXP '$search_txt') " : "");
 
        if($nets)
                $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
@@ -604,6 +676,7 @@ function contacts_content(&$a) {
        
        $tpl = get_markup_template("contacts-template.tpl");
        $o .= replace_macros($tpl, array(
+               '$baseurl' => $a->get_baseurl(),
                '$header' => t('Contacts') . (($nets) ? ' - ' . network_to_name($nets) : ''),
                '$tabs' => $t,
                '$total' => $total,
@@ -613,6 +686,14 @@ function contacts_content(&$a) {
                '$submit' => t('Find'),
                '$cmd' => $a->cmd,
                '$contacts' => $contacts,
+               '$contact_drop_confirm' => t('Do you really want to delete this contact?'),
+               '$batch_actions' => array(
+                       'contacts_batch_update' => t('Update'),
+                       'contacts_batch_block' => t('Block')."/".t("Unblock"),
+                       "contacts_batch_ignore" => t('Ignore')."/".t("Unignore"),
+                       "contacts_batch_archive" => t('Archive')."/".t("Unarchive"),
+                       "contacts_batch_drop" => t('Delete'),
+               ),
                '$paginate' => paginate($a),
 
        )); 
index 8e0e1acc7fd3a1adc124419fb17e95ad0a46eea6..196254960bc6c2dc9eaaa53910cdd2f55bc65308 100644 (file)
@@ -1,8 +1,3 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 
 <div class="contact-entry-wrapper" id="contact-entry-wrapper-{{$contact.id}}" >
        <div class="contact-entry-photo-wrapper" >
 
                        <a href="{{$contact.url}}" title="{{$contact.img_hover}}" /><img src="{{$contact.thumb}}" {{$contact.sparkle}} alt="{{$contact.name}}" /></a>
 
+                       <input type="checkbox" class="contact-select" name="contact_batch[]" value="{{$contact.id}}">
                        {{if $contact.photo_menu}}
                        <span onclick="openClose('contact-photo-menu-{{$contact.id}}');" class="fakelink contact-photo-menu-button" id="contact-photo-menu-button-{{$contact.id}}">menu</span>
                 <div class="contact-photo-menu" id="contact-photo-menu-{{$contact.id}}">
                     <ul>
-                                               {{foreach $contact.photo_menu as $c}}
+                                               {{foreach $contact.photo_menu as $k=>$c}}
                                                {{if $c.2}}
-                                               <li><a target="redir" href="{{$c.1}}">{{$c.0}}</a></li>
+                                               <li><a class="{{$k}}" target="redir" href="{{$c.1}}">{{$c.0}}</a></li>
                                                {{else}}
-                                               <li><a href="{{$c.1}}">{{$c.0}}</a></li>
+                                               <li><a class="{{$k}}" href="{{$c.1}}">{{$c.0}}</a></li>
                                                {{/if}}
                                                {{/foreach}}
                     </ul>
index 66f3f5c87bcef5654d2a0df9ed2bf6175e52dfd0..7dc6e0cec30c4015a87c31fb645c6654e0907318 100644 (file)
@@ -1,8 +1,4 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
+
 <h1>{{$header}}{{if $total}} ({{$total}}){{/if}}</h1>
 
 {{if $finding}}<h4>{{$finding}}</h4>{{/if}}
 
 {{$tabs}}
 
-
+<form action="{{$baseurl}}/contacts/batch/" method="POST">
 {{foreach $contacts as $contact}}
        {{include file="contact_template.tpl"}}
 {{/foreach}}
 <div id="contact-edit-end"></div>
+<div class="submit">
+{{foreach $batch_actions as $n=>$l}}
+ <input class="batch-action" name="{{$n}}" value="{{$l}}" type="submit">
+ {{/foreach}}
+ </div>
+</form>
+<script>
+ $(document).ready(function() {
+  // javascript dialog to batch actions
+  $(".batch-action").click(function(e){
+    if (confirm($(this).attr('value')+" ?")) {
+     return true;
+    } else {
+     e.preventDefault();
+     return false;
+    }
+  });
+  // add javascript confirm dialog to "drop" links. Plain html url have "?confirm=1" to show confirmation form, we need to remove it
+  $(".drop").each(function() {
+   $(this).attr('href', $(this).attr('href').replace("confirm=1","") );
+   $(this).click(function(e){
+    if (confirm("{{$contact_drop_confirm}}")) {
+     return true;
+    } else {
+     e.preventDefault();
+     return false;
+    }
+   });
+   
+  });
+ });
+ </script>
 
 {{$paginate}}
 
index 3567062a4e127efd2b018d5a71cacb7372ec63eb..77362e552496ef7434fc80539645a656a65e8fbd 100644 (file)
@@ -1617,6 +1617,9 @@ input#dfrn-url {
        margin-top: 20px;
 }
 
+.contact-select {      position: absolute; top: 64px; left:64px; display:none; }
+.contact-select:checked,
+.contact-entry-photo:hover .contact-select {   display:block; }
 
 .contact-photo-menu-button {
        position: absolute;
index e72e557038b602618d6ffa6df8b106e8621037bc..f09b240b340cc75ab8e33f21a385a40983164e90 100644 (file)
@@ -1349,6 +1349,19 @@ span[id^="showmore-wrap"] {
 .contact-photo-wrapper {
   position: relative;
 }
+.contact-select {
+  position: absolute;
+  top: 64px;
+  left: 64px;
+  display: none;
+}
+.contact-select:checked,
+.contact-photo:hover .contact-select {
+  display: block;
+}
+.submit {
+  clear: both;
+}
 .contact-photo {
   width: 48px;
   height: 48px;
index 8e6a020b8ae9f02e5c91e1b86420ab23a9214d32..2c664b52dc6ff28cf84bb2011dcc291a018869f4 100644 (file)
@@ -1349,6 +1349,19 @@ span[id^="showmore-wrap"] {
 .contact-photo-wrapper {
   position: relative;
 }
+.contact-select {
+  position: absolute;
+  top: 64px;
+  left: 64px;
+  display: none;
+}
+.contact-select:checked,
+.contact-photo:hover .contact-select {
+  display: block;
+}
+.submit {
+  clear: both;
+}
 .contact-photo {
   width: 48px;
   height: 48px;
index d35ad52ed092920fce8ef4f8c41f97e3e22e8f48..c75178437c2765deab074e10690e22ea571b5991 100644 (file)
@@ -1349,6 +1349,19 @@ span[id^="showmore-wrap"] {
 .contact-photo-wrapper {
   position: relative;
 }
+.contact-select {
+  position: absolute;
+  top: 64px;
+  left: 64px;
+  display: none;
+}
+.contact-select:checked,
+.contact-photo:hover .contact-select {
+  display: block;
+}
+.submit {
+  clear: both;
+}
 .contact-photo {
   width: 48px;
   height: 48px;
index 6287a05ef8f6d204bc1b509983ce03be7c838f83..87492675012da389826210bb07d92db2a8e683b5 100644 (file)
@@ -527,7 +527,8 @@ section {
        .contact-photo-wrapper { margin-left: 16px; }
        .contact-photo { 
                width: 32px; height: 32px; 
-       }       
+       }
+       
        .contact-photo-menu-button {
                top: 15px !important;
                left: 0px !important;
@@ -738,6 +739,10 @@ span[id^="showmore-wrap"] {
 
 
 .contact-photo-wrapper { position: relative; }
+.contact-select {      position: absolute; top:64px; left:64px; display:none; }
+.contact-select:checked,
+.contact-photo:hover .contact-select { display:block; }
+.submit { clear: both; }
 .contact-photo { 
        width: 48px; height: 48px;
        img { width: 48px; height: 48px; }
index c74a513b8fc1e4a7a50900b7ed5e8b85931815a2..a63ffb3c9ad068f4c760cc16f397407ce4edd45e 100644 (file)
@@ -1,8 +1,3 @@
-{{*
- *     AUTOMATICALLY GENERATED TEMPLATE
- *     DO NOT EDIT THIS FILE, CHANGES WILL BE OVERWRITTEN
- *
- *}}
 
 <div class="contact-wrapper" id="contact-entry-wrapper-{{$id}}" >
        <div class="contact-photo-wrapper" >
@@ -12,6 +7,7 @@
 
                        <a href="{{$contact.url}}" title="{{$contact.img_hover}}" /><img src="{{$contact.thumb}}" {{$contact.sparkle}} alt="{{$contact.name}}" /></a>
 
+                       <input type="checkbox" class="contact-select" name="contact_batch[]" value="{{$contact.id}}">
                        {{if $contact.photo_menu}}
                        <a href="#" rel="#contact-photo-menu-{{$contact.id}}" class="contact-photo-menu-button icon s16 menu" id="contact-photo-menu-button-{{$contact.id}}">menu</a>
                        <ul class="contact-photo-menu menu-popup" id="contact-photo-menu-{{$contact.id}}">