aboutsummaryrefslogtreecommitdiffstats
path: root/include/identity.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/identity.php')
-rw-r--r--include/identity.php186
1 files changed, 137 insertions, 49 deletions
diff --git a/include/identity.php b/include/identity.php
index b25594c87..2db5d8ece 100644
--- a/include/identity.php
+++ b/include/identity.php
@@ -71,23 +71,34 @@ function validate_channelname($name) {
/**
- * @function create_dir_account()
+ * @function create_sys_channel()
* Create a system channel - which has no account attached
*
- * Currently unused.
- *
*/
-function create_dir_account() {
+function create_sys_channel() {
+ if(get_sys_channel())
+ return;
create_identity(array(
'account_id' => 'xxx', // This will create an identity with an (integer) account_id of 0, but account_id is required
- 'nickname' => 'dir',
- 'name' => 'Directory',
- 'pageflags' => PAGE_DIRECTORY_CHANNEL|PAGE_HIDDEN,
- 'publish' => 0
+ 'nickname' => 'sys',
+ 'name' => 'System',
+ 'pageflags' => PAGE_SYSTEM,
+ 'publish' => 0,
+ 'xchanflags' => XCHAN_FLAGS_SYSTEM
));
}
+function get_sys_channel() {
+ $r = q("select * from channel left join xchan on channel_hash = xchan_hash where (channel_pageflags & %d) limit 1",
+ intval(PAGE_SYSTEM)
+ );
+ if($r)
+ return $r[0];
+ return false;
+}
+
+
/**
* @channel_total()
* Return the total number of channels on this site. No filtering is performed.
@@ -145,7 +156,7 @@ function create_identity($arr) {
$name = escape_tags($arr['name']);
$pageflags = ((x($arr,'pageflags')) ? intval($arr['pageflags']) : PAGE_NORMAL);
-
+ $xchanflags = ((x($arr,'xchanflags')) ? intval($arr['xchanflags']) : XCHAN_FLAGS_NORMAL);
$name_error = validate_channelname($arr['name']);
if($name_error) {
$ret['message'] = $name_error;
@@ -243,7 +254,7 @@ function create_identity($arr) {
$newuid = $ret['channel']['channel_id'];
- $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
+ $r = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_l, xchan_photo_m, xchan_photo_s, xchan_addr, xchan_url, xchan_follow, xchan_connurl, xchan_name, xchan_network, xchan_photo_date, xchan_name_date, xchan_flags ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d)",
dbesc($hash),
dbesc($guid),
dbesc($sig),
@@ -258,7 +269,8 @@ function create_identity($arr) {
dbesc($ret['channel']['channel_name']),
dbesc('zot'),
dbesc(datetime_convert()),
- dbesc(datetime_convert())
+ dbesc(datetime_convert()),
+ intval($xchanflags)
);
// Not checking return value.
@@ -396,7 +408,7 @@ function identity_basic_export($channel_id) {
$ret['hubloc'] = $r;
}
- $r = q("select * from `group` where uid = %d ",
+ $r = q("select * from `groups` where uid = %d ",
intval($channel_id)
);
@@ -532,6 +544,9 @@ function profile_load(&$a, $nickname, $profile = '') {
}
$a->profile = $r[0];
+ $online = get_online_status($nickname);
+ $a->profile['online_status'] = $online['result'];
+
$a->profile_uid = $r[0]['profile_uid'];
$a->page['title'] = $a->profile['channel_name'] . " - " . $a->profile['channel_address'] . "@" . $a->get_hostname();
@@ -655,6 +670,7 @@ function profile_sidebar($profile, $block = 0, $show_connect = true) {
}
}
+
if((x($profile,'address') == 1)
|| (x($profile,'locality') == 1)
|| (x($profile,'region') == 1)
@@ -665,9 +681,15 @@ function profile_sidebar($profile, $block = 0, $show_connect = true) {
$gender = ((x($profile,'gender') == 1) ? t('Gender:') : False);
$marital = ((x($profile,'marital') == 1) ? t('Status:') : False);
$homepage = ((x($profile,'homepage') == 1) ? t('Homepage:') : False);
+ $profile['online'] = (($profile['online_status'] === 'online') ? t('Online Now') : False);
+logger('online: ' . $profile['online']);
+
+ if(! perm_is_allowed($profile['uid'],((is_array($observer)) ? $observer['xchan_hash'] : ''),'view_profile')) {
+ $block = true;
+ }
if(($profile['hidewall'] || $block) && (! local_user()) && (! remote_user())) {
- $location = $pdesc = $gender = $marital = $homepage = False;
+ $location = $pdesc = $gender = $marital = $homepage = $online = False;
}
$firstname = ((strpos($profile['name'],' '))
@@ -688,7 +710,7 @@ function profile_sidebar($profile, $block = 0, $show_connect = true) {
$channel_menu = menu_render($m);
}
$menublock = get_pconfig($profile['uid'],'system','channel_menublock');
- if ($menublock) {
+ if ($menublock && (! $block)) {
require_once('include/comanche.php');
$channel_menu .= comanche_block($menublock);
}
@@ -935,6 +957,8 @@ function advanced_profile(&$a) {
if($txt = prepare_text($a->profile['contact'])) $profile['contact'] = array( t('Contact information and Social Networks:'), $txt);
+ if($txt = prepare_text($a->profile['channels'])) $profile['channels'] = array( t('My other channels:'), $txt);
+
if($txt = prepare_text($a->profile['music'])) $profile['music'] = array( t('Musical interests:'), $txt);
if($txt = prepare_text($a->profile['book'])) $profile['book'] = array( t('Books, literature:'), $txt);
@@ -949,44 +973,15 @@ function advanced_profile(&$a) {
if($txt = prepare_text($a->profile['education'])) $profile['education'] = array( t('School/education:'), $txt );
- $r = q("select * from obj left join term on obj_obj = term_hash where term_hash != '' and obj_page = '%s' and uid = %d and obj_type = %d
- order by obj_verb, term",
- dbesc($a->profile['profile_guid']),
- intval($a->profile['profile_uid']),
- intval(TERM_OBJ_THING)
- );
- $things = null;
+ $things = get_things($a->profile['profile_guid'],$a->profile['profile_uid']);
- if($r) {
- $things = array();
-
- // Use the system obj_verbs array as a sort key, since we don't really
- // want an alphabetic sort. To change the order, use a plugin to
- // alter the obj_verbs() array or alter it in code. Unknown verbs come
- // after the known ones - in no particular order.
-
- $v = obj_verbs();
- foreach($v as $k => $foo)
- $things[$k] = null;
- foreach($r as $rr) {
- if(! $things[$rr['obj_verb']])
- $things[$rr['obj_verb']] = array();
- $things[$rr['obj_verb']][] = array('term' => $rr['term'],'url' => $rr['url'],'img' => $rr['imgurl']);
- }
- $sorted_things = array();
- if($things)
- foreach($things as $k => $v)
- if(is_array($things[$k]))
- $sorted_things[$k] = $v;
- }
-
- logger('mod_profile: things: ' . print_r($sorted_things,true), LOGGER_DATA);
+ logger('mod_profile: things: ' . print_r($things,true), LOGGER_DATA);
return replace_macros($tpl, array(
'$title' => t('Profile'),
'$profile' => $profile,
- '$things' => $sorted_things
+ '$things' => $things
));
}
@@ -1031,12 +1026,13 @@ function zid_init(&$a) {
call_hooks('zid_init',$arr);
if((! local_user()) && (! remote_user())) {
logger('zid_init: not authenticated. Invoking reverse magic-auth for ' . $tmp_str);
- $r = q("select * from hubloc where hubloc_addr = '%s' order by hubloc_id desc limit 1",
+ $r = q("select * from hubloc where hubloc_addr = '%s' order by hubloc_connected desc limit 1",
dbesc($tmp_str)
);
// try to avoid recursion - but send them home to do a proper magic auth
- $dest = '/' . $a->query_string;
- $dest = str_replace(array('?zid=','&zid='),array('?rzid=','&rzid='),$dest);
+ $query = $a->query_string;
+ $query = str_replace(array('?zid=','&zid='),array('?rzid=','&rzid='),$query);
+ $dest = '/' . urlencode($query);
if($r && ($r[0]['hubloc_url'] != z_root()) && (! strstr($dest,'/magic')) && (! strstr($dest,'/rmagic'))) {
goaway($r[0]['hubloc_url'] . '/magic' . '?f=&rev=1&dest=' . z_root() . $dest);
}
@@ -1104,3 +1100,95 @@ function get_theme_uid() {
}
return $uid;
}
+
+/**
+* @function get_default_profile_photo($size = 175)
+* Retrieves the path of the default_profile_photo for this system
+* with the specified size.
+* @param int $size
+* one of (175, 80, 48)
+* @returns string
+*
+*/
+
+function get_default_profile_photo($size = 175) {
+ $scheme = get_config('system','default_profile_photo');
+ if(! $scheme)
+ $scheme = 'rainbow_man';
+ return 'images/default_profile_photos/' . $scheme . '/' . $size . '.jpg';
+}
+
+
+/**
+ *
+ * @function is_foreigner($s)
+ * Test whether a given identity is NOT a member of the Red Matrix
+ * @param string $s;
+ * xchan_hash of the identity in question
+ *
+ * @returns boolean true or false
+ *
+ */
+
+function is_foreigner($s) {
+ return((strpbrk($s,':@')) ? true : false);
+}
+
+
+/**
+ *
+ * @function is_member($s)
+ * Test whether a given identity is a member of the Red Matrix
+ * @param string $s;
+ * xchan_hash of the identity in question
+ *
+ * @returns boolean true or false
+ *
+ */
+
+function is_member($s) {
+ return((is_foreigner($s)) ? false : true);
+}
+
+function get_online_status($nick) {
+
+ $ret = array('result' => false);
+
+ $r = q("select channel_id, channel_hash from channel where channel_address = '%s' limit 1",
+ dbesc(argv(1))
+ );
+ if($r) {
+ $hide = get_pconfig($r[0]['channel_id'],'system','hide_online_status');
+ if($hide)
+ return $ret;
+ $x = q("select cp_status from chatpresence where cp_xchan = '%s' and cp_room = 0 limit 1",
+ dbesc($r[0]['channel_hash'])
+ );
+ if($x)
+ $ret['result'] = $x[0]['cp_status'];
+ }
+
+ return $ret;
+}
+
+
+function remote_online_status($webbie) {
+
+ $result = false;
+ $r = q("select * from hubloc where hubloc_addr = '%s' limit 1",
+ dbesc($webbie)
+ );
+ if(! $r)
+ return $result;
+
+ $url = $r[0]['hubloc_url'] . '/online/' . substr($webbie,0,strpos($webbie,'@'));
+
+ $x = z_fetch_url($url);
+ if($x['success']) {
+ $j = json_decode($x['body'],true);
+ if($j)
+ $result = (($j['result']) ? $j['result'] : false);
+ }
+ return $result;
+
+}