new contact_selector function to provide more fine-tuned selection options.

This commit is contained in:
Friendika 2011-06-23 21:55:27 -07:00
parent 8ffcd4323b
commit 694c1c1af4
2 changed files with 119 additions and 17 deletions

View file

@ -43,6 +43,25 @@
define('FACEBOOK_MAXPOSTLEN', 420); define('FACEBOOK_MAXPOSTLEN', 420);
function facebook_install() {
register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
register_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
}
function facebook_uninstall() {
unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
unregister_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
}
/* declare the facebook_module function so that /facebook url requests will land here */ /* declare the facebook_module function so that /facebook url requests will land here */
function facebook_module() {} function facebook_module() {}
@ -339,22 +358,6 @@ function facebook_content(&$a) {
return $o; return $o;
} }
function facebook_install() {
register_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
register_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
register_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
register_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
register_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
}
function facebook_uninstall() {
unregister_hook('post_local_end', 'addon/facebook/facebook.php', 'facebook_post_hook');
unregister_hook('jot_networks', 'addon/facebook/facebook.php', 'facebook_jot_nets');
unregister_hook('plugin_settings', 'addon/facebook/facebook.php', 'facebook_plugin_settings');
unregister_hook('cron', 'addon/facebook/facebook.php', 'facebook_cron');
unregister_hook('queue_predeliver', 'addon/facebook/facebook.php', 'fb_queue_hook');
}
function facebook_cron($a,$b) { function facebook_cron($a,$b) {
@ -432,7 +435,7 @@ function facebook_post_hook(&$a,&$b) {
if((local_user()) && (local_user() == $b['uid'])) { if((local_user()) && (local_user() == $b['uid'])) {
// Facebook is not considered a private network // Facebook is not considered a private network
if($b['prvnets']) if($b['prvnets'] && $b['private'])
return; return;
if($b['parent']) { if($b['parent']) {

View file

@ -41,6 +41,104 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
} }
function contact_selector($selname, $selclass, $preselected = false, $options) {
$a = get_app();
$mutual = false;
$networks = null;
$single = false;
if($is_array($options)) {
if(x($options,'mutual_friends'))
$mutual = true;
if(x($options,'single'))
$single = true;
if(x($options,'multiple'))
$single = false;
if(x($options,'networks')) {
switch($options['networks']) {
case 'DFRN_ONLY':
$networks = array('dfrn');
break;
case 'PRIVATE':
if(is_array($a->user) && $a->user['prvnets'])
$networks = array('dfrn','mail','dspr');
else
$networks = array('dfrn','face','mail', 'dspr');
break;
case 'TWO_WAY':
if(is_array($a->user) && $a->user['prvnets'])
$networks = array('dfrn','mail','dspr');
else
$networks = array('dfrn','face','mail','dspr','stat');
break;
default:
break;
}
}
}
$x = array('options' => $options, 'single' => $single, 'mutual' => $mutual, 'networks' => $networks);
call_hooks('contact_select_options', $x);
$o = '';
$sql_extra = '';
if($x['mutual']) {
$sql_extra .= sprintf(" AND `rel` = %d ", intval(REL_BUD));
}
if(is_array($x['networks']) && count($x['networks'])) {
for($y = 0; $y < count($x['networks']) ; $y ++)
$x['networks'][$y] = "'" . dbesc($x['networks'][$y]) . "'";
$str_nets = implode(',',$x['networks']);
$sql_extra .= " AND `network` IN ( $str_nets ) ";
}
if($x['single'])
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
else
$o .= "<select name=\"{$selname}[]\" id=\"$selclass\" class=\"$selclass\" multiple=\"multiple\" size=\"$size\" >\r\n";
$r = q("SELECT `id`, `name`, `url`, `network` FROM `contact`
WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 AND `pending` = 0 AND `notify` != ''
$sql_extra
ORDER BY `name` ASC ",
intval(local_user())
);
$arr = array('contact' => $r, 'entry' => $o);
// e.g. 'network_pre_contact_deny', 'profile_pre_contact_allow'
call_hooks($a->module . '_pre_' . $selname, $arr);
if(count($r)) {
foreach($r as $rr) {
if((is_array($preselected)) && in_array($rr['id'], $preselected))
$selected = " selected=\"selected\" ";
else
$selected = '';
$trimmed = mb_substr($rr['name'],0,20);
$o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
}
}
$o .= "</select>\r\n";
call_hooks($a->module . '_post_' . $selname, $o);
return $o;
}
function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) { function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) {
@ -106,6 +204,7 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
return $o; return $o;
} }
function fixacl(&$item) { function fixacl(&$item) {
$item = intval(str_replace(array('<','>'),array('',''),$item)); $item = intval(str_replace(array('<','>'),array('',''),$item));
} }