basic friend suggestions (but not "new to the network and have no friends at all" suggestions)

This commit is contained in:
friendica 2013-03-05 21:00:25 -08:00
parent fbda9ababc
commit 4062be2869
7 changed files with 92 additions and 32 deletions

View File

@ -17,7 +17,7 @@ require_once('include/features.php');
define ( 'FRIENDICA_PLATFORM', 'Friendica Red'); define ( 'FRIENDICA_PLATFORM', 'Friendica Red');
define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R'); define ( 'FRIENDICA_VERSION', trim(file_get_contents('version.inc')) . 'R');
define ( 'ZOT_REVISION', 1 ); define ( 'ZOT_REVISION', 1 );
define ( 'DB_UPDATE_VERSION', 1032 ); define ( 'DB_UPDATE_VERSION', 1033 );
define ( 'EOL', '<br />' . "\r\n" ); define ( 'EOL', '<br />' . "\r\n" );
define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' );

View File

@ -254,12 +254,26 @@ function all_friends($uid,$cid,$start = 0, $limit = 80) {
function suggestion_query($uid, $start = 0, $limit = 80) { function suggestion_query($uid, $myxchan, $start = 0, $limit = 80) {
if(! $uid) if((! $uid) || (! $myxchan))
return array(); return array();
$r = q("SELECT count(glink.gcid) as `total`, gcontact.* from gcontact $r = q("SELECT count(xlink_xchan) as `total`, xchan.* from xchan
left join xlink on xlink_link = xchan_hash
where not xchan_hash in ( select abook_xchan from abook where abook_channel = %d )
and not xchan_hash in ( select xchan from xign where uid = %d )
and xchan_hash != '%s'
group by xchan_hash order by total desc limit %d, %d ",
intval($uid),
intval($uid),
dbesc($myxchan),
intval($start),
intval($limit)
);
/*
$r = q("SELECT count(xlink.xchan) as `total`, gcontact.* from gcontact
left join glink on glink.gcid = gcontact.id left join glink on glink.gcid = gcontact.id
where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d ) where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d )
and not gcontact.name in ( select name from contact where uid = %d ) and not gcontact.name in ( select name from contact where uid = %d )
@ -272,7 +286,12 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
intval($start), intval($start),
intval($limit) intval($limit)
); );
*/
if($r)
return $r;
/*
if(count($r) && count($r) >= ($limit -1)) if(count($r) && count($r) >= ($limit -1))
return $r; return $r;
@ -291,7 +310,7 @@ function suggestion_query($uid, $start = 0, $limit = 80) {
return array_merge($r,$r2); return array_merge($r,$r2);
*/
} }
function update_suggestions() { function update_suggestions() {

View File

@ -909,6 +909,15 @@ CREATE TABLE IF NOT EXISTS `xchan` (
KEY `xchan_connurl` (`xchan_connurl`) KEY `xchan_connurl` (`xchan_connurl`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `xign` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`uid` int(11) NOT NULL DEFAULT '0',
`xchan` char(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `uid` (`uid`),
KEY `xchan` (`xchan`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `xlink` ( CREATE TABLE IF NOT EXISTS `xlink` (
`xlink_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `xlink_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`xlink_xchan` char(255) NOT NULL DEFAULT '', `xlink_xchan` char(255) NOT NULL DEFAULT '',

View File

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1032 ); define( 'UPDATE_VERSION' , 1033 );
/** /**
* *
@ -52,7 +52,7 @@ function update_r1001() {
`meta` CHAR( 255 ) NOT NULL DEFAULT '', `meta` CHAR( 255 ) NOT NULL DEFAULT '',
`created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY ( `id` ) PRIMARY KEY ( `id` )
) ENGINE = MYISAM "); ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
$r2 = q("alter table `verify` add index (`channel`), add index (`type`), add index (`token`), $r2 = q("alter table `verify` add index (`channel`), add index (`type`), add index (`token`),
add index (`meta`), add index (`created`)"); add index (`meta`), add index (`created`)");
@ -91,7 +91,7 @@ function update_r1004() {
`site_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `site_update` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`site_directory` CHAR( 255 ) NOT NULL DEFAULT '', `site_directory` CHAR( 255 ) NOT NULL DEFAULT '',
PRIMARY KEY ( `site_url` ) PRIMARY KEY ( `site_url` )
) ENGINE = MYISAM "); ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
$r2 = q("alter table site add index (site_flags), add index (site_update), add index (site_directory) "); $r2 = q("alter table site add index (site_flags), add index (site_update), add index (site_directory) ");
@ -204,7 +204,7 @@ function update_r1013() {
`xlink_xchan` CHAR( 255 ) NOT NULL DEFAULT '', `xlink_xchan` CHAR( 255 ) NOT NULL DEFAULT '',
`xlink_link` CHAR( 255 ) NOT NULL DEFAULT '', `xlink_link` CHAR( 255 ) NOT NULL DEFAULT '',
`xlink_updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' `xlink_updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE = MYISAM "); ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
$r2 = q("alter table xlink add index ( xlink_xchan ), add index ( xlink_link ), add index ( xlink_updated ) "); $r2 = q("alter table xlink add index ( xlink_xchan ), add index ( xlink_link ), add index ( xlink_updated ) ");
if($r && $r2) if($r && $r2)
@ -367,7 +367,7 @@ ADD INDEX ( `channel_deleted` ) ");
} }
function update_r1030() { function update_r1030() {
$r = q("CREATE TABLE IF NOT EXISTS`issue` ( $r = q("CREATE TABLE IF NOT EXISTS `issue` (
`issue_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `issue_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`issue_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `issue_created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`issue_updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `issue_updated` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
@ -381,7 +381,7 @@ KEY `issue_assigned` (`issue_assigned`),
KEY `issue_priority` (`issue_priority`), KEY `issue_priority` (`issue_priority`),
KEY `issue_status` (`issue_status`), KEY `issue_status` (`issue_status`),
KEY `issue_component` (`issue_component`) KEY `issue_component` (`issue_component`)
) ENGINE = MYISAM "); ) ENGINE = MYISAM DEFAULT CHARSET=utf8");
if($r) if($r)
return UPDATE_SUCCESS; return UPDATE_SUCCESS;
@ -397,3 +397,16 @@ ADD INDEX ( `account_external` )");
} }
function update_r1032() {
$r = q("CREATE TABLE if not exists `xign` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`uid` INT NOT NULL DEFAULT '0',
`xchan` CHAR( 255 ) NOT NULL DEFAULT '',
KEY `uid` (`uid`),
KEY `xchan` (`xchan`)
) ENGINE = MYISAM DEFAULT CHARSET = utf8");
if($r)
return UPDATE_SUCCESS;
return UPDATE_FAILED;
}

View File

@ -8,10 +8,10 @@ function suggest_init(&$a) {
if(! local_user()) if(! local_user())
return; return;
if(x($_GET,'ignore') && intval($_GET['ignore'])) { if(x($_GET,'ignore')) {
q("insert into gcign ( uid, gcid ) values ( %d, %d ) ", q("insert into xign ( uid, xchan ) values ( %d, '%s' ) ",
intval(local_user()), intval(local_user()),
intval($_GET['ignore']) dbesc($_GET['ignore'])
); );
} }
@ -37,10 +37,9 @@ function suggest_content(&$a) {
$o .= '<h2>' . t('Friend Suggestions') . '</h2>'; $o .= '<h2>' . t('Friend Suggestions') . '</h2>';
$r = suggestion_query(local_user(),get_observer_hash());
$r = suggestion_query(local_user()); if(! $r) {
if(! count($r)) {
$o .= t('No suggestions available. If this is a new site, please try again in 24 hours.'); $o .= t('No suggestions available. If this is a new site, please try again in 24 hours.');
return $o; return $o;
} }
@ -49,13 +48,13 @@ function suggest_content(&$a) {
foreach($r as $rr) { foreach($r as $rr) {
$connlnk = $a->get_baseurl() . '/follow/?url=' . (($rr['connect']) ? $rr['connect'] : $rr['url']); $connlnk = $a->get_baseurl() . '/follow/?url=' . $rr['xchan_addr'];
$o .= replace_macros($tpl,array( $o .= replace_macros($tpl,array(
'$url' => zid($rr['url']), '$url' => zid($rr['xchan_url']),
'$name' => $rr['name'], '$name' => $rr['xchan_name'],
'$photo' => $rr['photo'], '$photo' => $rr['xchan_photo_m'],
'$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['id'], '$ignlnk' => $a->get_baseurl() . '/suggest?ignore=' . $rr['xchan_hash'],
'$conntxt' => t('Connect'), '$conntxt' => t('Connect'),
'$connlnk' => $connlnk, '$connlnk' => $connlnk,
'$ignore' => t('Ignore/Hide') '$ignore' => t('Ignore/Hide')

View File

@ -1,16 +1,26 @@
<div id="main-slider" class="slider" ><input id="main-range" type="text" name="cminmax" value="$val" /></div> <div id="main-slider" class="slider" ><input id="main-range" type="text" name="cminmax" value="$val" /></div>
<script> <script>
var old_cmin = 0;
var old_cmax = 99;
$("#main-range").slider({ from: 0, to: 99, step: 1, scale: ['$me', '|', '$intimate', '|', '$friends', '|', '$oldfriends', '|', '$acquaintances', '|', '$world' ], onstatechange: function(v) { $("#main-range").slider({ from: 0, to: 99, step: 1, scale: ['$me', '|', '$intimate', '|', '$friends', '|', '$oldfriends', '|', '$acquaintances', '|', '$world' ], onstatechange: function(v) {
var carr = v.split(";"); var carr = v.split(";");
bParam_cmin = carr[0]; if(carr[0] != bParam_cmin) {
bParam_cmax = carr[1]; old_cmin = bParam_cmin;
networkRefresh(); bParam_cmin = carr[0];
} }); }
if(carr[1] != bParam_cmax) {
old_cmax = bParam_cmax;
bParam_cmax = carr[1];
}
networkRefresh();
} });
var slideTimer = null; var slideTimer = null;
function networkRefresh() { function networkRefresh() {
if((document.readyState !== "complete") || (slideTimer !== null)) if((document.readyState !== "complete") || (slideTimer !== null))
return; return;
if((bParam_cmin == old_cmin) && (bParam_cmax == old_cmax))
return;
setTimeout(function() { $("#profile-jot-text-loading").show(); }, 1000 ); setTimeout(function() { $("#profile-jot-text-loading").show(); }, 1000 );
slideTimer = setTimeout(networkTimerRefresh,2000); slideTimer = setTimeout(networkTimerRefresh,2000);
} }

View File

@ -5,17 +5,27 @@
*}} *}}
<div id="main-slider" class="slider" ><input id="main-range" type="text" name="cminmax" value="{{$val}}" /></div> <div id="main-slider" class="slider" ><input id="main-range" type="text" name="cminmax" value="{{$val}}" /></div>
<script> <script>
var old_cmin = 0;
var old_cmax = 99;
$("#main-range").slider({ from: 0, to: 99, step: 1, scale: ['{{$me}}', '|', '{{$intimate}}', '|', '{{$friends}}', '|', '{{$oldfriends}}', '|', '{{$acquaintances}}', '|', '{{$world}}' ], onstatechange: function(v) { $("#main-range").slider({ from: 0, to: 99, step: 1, scale: ['{{$me}}', '|', '{{$intimate}}', '|', '{{$friends}}', '|', '{{$oldfriends}}', '|', '{{$acquaintances}}', '|', '{{$world}}' ], onstatechange: function(v) {
var carr = v.split(";"); var carr = v.split(";");
bParam_cmin = carr[0]; if(carr[0] != bParam_cmin) {
bParam_cmax = carr[1]; old_cmin = bParam_cmin;
networkRefresh(); bParam_cmin = carr[0];
} }); }
if(carr[1] != bParam_cmax) {
old_cmax = bParam_cmax;
bParam_cmax = carr[1];
}
networkRefresh();
} });
var slideTimer = null; var slideTimer = null;
function networkRefresh() { function networkRefresh() {
if((document.readyState !== "complete") || (slideTimer !== null)) if((document.readyState !== "complete") || (slideTimer !== null))
return; return;
if((bParam_cmin == old_cmin) && (bParam_cmax == old_cmax))
return;
setTimeout(function() { $("#profile-jot-text-loading").show(); }, 1000 ); setTimeout(function() { $("#profile-jot-text-loading").show(); }, 1000 );
slideTimer = setTimeout(networkTimerRefresh,2000); slideTimer = setTimeout(networkTimerRefresh,2000);
} }