diff options
author | Stefan Parviainen <saparvia@caterva.eu> | 2015-01-04 14:23:23 +0100 |
---|---|---|
committer | Stefan Parviainen <saparvia@caterva.eu> | 2015-01-04 14:23:23 +0100 |
commit | 57809f20a4a3624bfb50bd5bc881fe81db26c02c (patch) | |
tree | ac7af255b8a85b244dd1d10bf5b2e8c26836babd /mod | |
parent | 386f361855663b445d1497bbbabcf87891ce94d9 (diff) | |
parent | 9433a0ddc8926cc483521e97ae911d2eb82c91f6 (diff) | |
download | volse-hubzilla-57809f20a4a3624bfb50bd5bc881fe81db26c02c.tar.gz volse-hubzilla-57809f20a4a3624bfb50bd5bc881fe81db26c02c.tar.bz2 volse-hubzilla-57809f20a4a3624bfb50bd5bc881fe81db26c02c.zip |
Sorting of autocomplete
Diffstat (limited to 'mod')
-rw-r--r-- | mod/acl.php | 31 | ||||
-rw-r--r-- | mod/connedit.php | 20 | ||||
-rw-r--r-- | mod/filestorage.php | 4 | ||||
-rw-r--r-- | mod/profiles.php | 22 |
4 files changed, 56 insertions, 21 deletions
diff --git a/mod/acl.php b/mod/acl.php index 7973ece4e..22821da52 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -32,6 +32,9 @@ function acl_init(&$a){ $sql_extra = " AND `name` LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " "; $sql_extra2 = "AND ( xchan_name LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " OR xchan_addr LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . ") "; + // This horrible mess is needed because position also returns 0 if nothing is found. W/ould be MUCH easier if it instead returned a very large value + // Otherwise we could just order by LEAST(POSTION($search IN xchan_name),POSITION($search IN xchan_addr)). + $order_extra2 = "CASE WHEN xchan_name LIKE " . protect_sprintf( "'%" . dbesc($search) . "%'" ) ." then POSITION('".dbesc($search)."' IN xchan_name) else position('".dbesc($search)."' IN xchan_addr) end, "; $col = ((strpos($search,'@') !== false) ? 'xchan_addr' : 'xchan_name' ); $sql_extra3 = "AND $col like " . protect_sprintf( "'%" . dbesc($search) . "%'" ) . " "; @@ -91,7 +94,7 @@ function acl_init(&$a){ $r = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags FROM abook left join xchan on abook_xchan = xchan_hash - WHERE (abook_channel = %d $extra_channels_sql) AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by xchan_name asc" , + WHERE (abook_channel = %d $extra_channels_sql) AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra xchan_name asc" , intval(local_user()), intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED), intval(XCHAN_FLAGS_DELETED) @@ -100,7 +103,7 @@ function acl_init(&$a){ else { // Visitors $r = q("SELECT xchan_hash as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags FROM xchan left join xlink on xlink_link = xchan_hash - WHERE xlink_xchan = '%s' AND NOT (xchan_flags & %d) > 0 $sql_extra2 order by xchan_name asc" , + WHERE xlink_xchan = '%s' AND NOT (xchan_flags & %d) > 0 $sql_extra2 order by $order_extra xchan_name asc" , dbesc(get_observer_hash()), intval(XCHAN_FLAGS_DELETED)); @@ -116,19 +119,39 @@ function acl_init(&$a){ $r2 = q("SELECT abook_id as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, abook_their_perms, abook_flags FROM abook left join xchan on abook_xchan = xchan_hash - WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by xchan_name asc" , + WHERE abook_channel IN ($extra_channels_sql) $known_hashes_sql AND not ( abook_flags & %d )>0 and not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra xchan_name asc" , intval(ABOOK_FLAG_BLOCKED|ABOOK_FLAG_PENDING|ABOOK_FLAG_ARCHIVED|ABOOK_FLAG_HIDDEN), intval(XCHAN_FLAGS_DELETED) ); if($r2) $r = array_merge($r,$r2); + + // Sort accoring to match position, then alphabetically. This could be avoided if the above two SQL queries could be combined into one, and the sorting could be done on the SQl server (like in the case of a local user) + $matchpos = function($x) use($search) { + $namepos = strpos($x['name'],$search); + $nickpos = strpos($x['nick'],$search); + // Use a large position if not found + return min($namepos === false ? 9999 : $namepos, $nickpos === false ? 9999 : $nickpos); + }; + // This could be made simpler if PHP supported stable sorting + usort($r,function($a,$b) use($matchpos) { + $pos1 = $matchpos($a); + $pos2 = $matchpos($b); + if($pos1 == $pos2) { // Order alphabetically if match position is the same + if($a['name'] == $b['name']) + return 0; + else + return ($a['name'] < $b['name']) ? -1 : 1; + } + return ($pos1 < $pos2) ? -1 : 1; + }); } } if(intval(get_config('system','taganyone')) || intval(get_pconfig(local_user(),'system','taganyone'))) { if((! $r) && $type == 'c') { $r = q("SELECT substr(xchan_hash,1,18) as id, xchan_hash as hash, xchan_name as name, xchan_photo_s as micro, xchan_url as url, xchan_addr as nick, 0 as abook_their_perms, 0 as abook_flags FROM xchan - WHERE not (xchan_flags & %d )>0 $sql_extra2 order by xchan_name asc" , + WHERE not (xchan_flags & %d )>0 $sql_extra2 order by $order_extra2 xchan_name asc" , intval(XCHAN_FLAGS_DELETED) ); } diff --git a/mod/connedit.php b/mod/connedit.php index 5bf9c130b..6729029ac 100644 --- a/mod/connedit.php +++ b/mod/connedit.php @@ -444,32 +444,34 @@ function connedit_content(&$a) { 'url' => $a->get_baseurl(true) . '/network/?f=&cid=' . $contact['abook_id'], 'sel' => '', 'title' => t('View recent posts and comments'), - ), + ) + ); + $buttons = array( array( 'label' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? t('Unblock') : t('Block')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/block', 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_BLOCKED) ? 'active' : ''), - 'title' => t('Block or Unblock this connection'), + 'title' => t('Block (or Unblock) all communications with this connection'), ), array( 'label' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? t('Unignore') : t('Ignore')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/ignore', 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_IGNORED) ? 'active' : ''), - 'title' => t('Ignore or Unignore this connection'), + 'title' => t('Ignore (or Unignore) all inbound communications from this connection'), ), array( 'label' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? t('Unarchive') : t('Archive')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/archive', 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_ARCHIVED) ? 'active' : ''), - 'title' => t('Archive or Unarchive this connection'), + 'title' => t('Archive (or Unarchive) this connection - mark channel dead but keep content'), ), array( 'label' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? t('Unhide') : t('Hide')), 'url' => $a->get_baseurl(true) . '/connedit/' . $contact['abook_id'] . '/hide', 'sel' => (($contact['abook_flags'] & ABOOK_FLAG_HIDDEN) ? 'active' : ''), - 'title' => t('Hide or Unhide this connection'), + 'title' => t('Hide or Unhide this connection from your other connections'), ), array( @@ -542,11 +544,15 @@ function connedit_content(&$a) { '$notself' => (($self) ? '' : '1'), '$self' => (($self) ? '1' : ''), '$autolbl' => t('Apply the permissions indicated on this page to all new connections.'), + '$buttons' => (($self) ? '' : $buttons), '$viewprof' => t('View Profile'), '$lbl_slider' => t('Slide to adjust your degree of friendship'), '$slide' => $slide, '$tabs' => $t, '$tab_str' => $tab_str, + '$perms_step1' => t('<p>Step #1. (Completed).</p><p>Create connection with minimal or no permissions.</p>'), + '$perms_step2' => t('<p>Step #2. (Incomplete).</p><p>Review and/or edit the default individual permissions on this page, if desired.</p>'), + '$perms_step3' => t('<p>Step #3. (Incomplete).</p><p>Submit this page to apply the selected permissions.</p><p>Until this is complete, this connection may have insufficient permission to communicate with you.</p>'), '$is_pending' => (($contact['abook_flags'] & ABOOK_FLAG_PENDING) ? 1 : ''), '$unapproved' => $unapproved, '$inherited' => t('inherited'), @@ -598,12 +604,8 @@ function connedit_content(&$a) { '$ignored' => (($contact['readonly']) ? t('Currently ignored') : ''), '$archived' => (($contact['archive']) ? t('Currently archived') : ''), '$pending' => (($contact['archive']) ? t('Currently pending') : ''), - '$hidden' => array('hidden', t('Hide this contact from others'), ($contact['hidden'] == 1), t('Replies/likes to your public posts <strong>may</strong> still be visible')), - '$photo' => $contact['photo'], '$name' => $contact['name'], - '$dir_icon' => $dir_icon, '$alt_text' => $alt_text, - '$sparkle' => $sparkle, '$url' => $url )); diff --git a/mod/filestorage.php b/mod/filestorage.php index 6b731e440..0a25617f0 100644 --- a/mod/filestorage.php +++ b/mod/filestorage.php @@ -147,7 +147,9 @@ function filestorage_content(&$a) { '$isadir' => $is_a_dir, '$cpdesc' => t('Copy/paste this code to attach file to a post'), '$cpldesc' => t('Copy/paste this URL to link file from a web page'), - '$submit' => t('Submit') + '$submit' => t('Submit'), + '$attach_btn_title' => t('Attach this file to a new post'), + '$link_btn_title' => t('Show URL to this file'), )); echo $o; diff --git a/mod/profiles.php b/mod/profiles.php index 6bdc7f11a..fa6a6e35c 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -11,7 +11,7 @@ function profiles_init(&$a) { if((argc() > 2) && (argv(1) === "drop") && intval(argv(2))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", - intval($a->argv[2]), + intval(argv(2)), intval(local_user()) ); if(! count($r)) { @@ -159,9 +159,13 @@ function profiles_init(&$a) { if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { if(feature_enabled(local_user(),'multi_profiles')) $id = $a->argv[1]; - else - $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; - + else { + $x = q("select id from profile where uid = %d and is_default = 1", + intval(local_user()) + ); + if($x) + $id = $x[0]['id']; + } $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($id), intval(local_user()) @@ -564,9 +568,13 @@ function profiles_content(&$a) { if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { if(feature_enabled(local_user(),'multi_profiles')) $id = $a->argv[1]; - else - $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; - + else { + $x = q("select id from profile where uid = %d and is_default = 1", + intval(local_user()) + ); + if($x) + $id = $x[0]['id']; + } $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($id), intval(local_user()) |