diff options
author | friendica <info@friendica.com> | 2015-01-26 18:27:03 -0800 |
---|---|---|
committer | friendica <info@friendica.com> | 2015-01-26 18:27:03 -0800 |
commit | ac594183c6fdc6cf4d5a2a29ade7478a17336397 (patch) | |
tree | d38f73727da4d8697b00d2102ae10b501d1909ce /include | |
parent | e6bfe3f2c10e851ed5ba49886ec8d0a9a9de2296 (diff) | |
parent | 9f5bfca28dde23893156ad36682e20ca2fc0dd45 (diff) | |
download | volse-hubzilla-ac594183c6fdc6cf4d5a2a29ade7478a17336397.tar.gz volse-hubzilla-ac594183c6fdc6cf4d5a2a29ade7478a17336397.tar.bz2 volse-hubzilla-ac594183c6fdc6cf4d5a2a29ade7478a17336397.zip |
Merge branch 'master' into tres and add some work on the item_deleted flag refactor
Conflicts:
include/attach.php
include/onedirsync.php
include/zot.php
mod/locs.php
Diffstat (limited to 'include')
-rw-r--r-- | include/RedDAV/RedBrowser.php | 7 | ||||
-rw-r--r-- | include/attach.php | 192 | ||||
-rw-r--r-- | include/bbcode.php | 2 | ||||
-rwxr-xr-x | include/diaspora.php | 2 | ||||
-rw-r--r-- | include/features.php | 1 | ||||
-rw-r--r-- | include/follow.php | 23 | ||||
-rwxr-xr-x | include/items.php | 2 | ||||
-rw-r--r-- | include/network.php | 35 | ||||
-rwxr-xr-x | include/oembed.php | 2 | ||||
-rw-r--r-- | include/onedirsync.php | 12 | ||||
-rw-r--r-- | include/photos.php | 20 | ||||
-rw-r--r-- | include/poller.php | 2 | ||||
-rw-r--r-- | include/socgraph.php | 211 | ||||
-rw-r--r-- | include/text.php | 3 | ||||
-rw-r--r-- | include/zot.php | 2 |
15 files changed, 422 insertions, 94 deletions
diff --git a/include/RedDAV/RedBrowser.php b/include/RedDAV/RedBrowser.php index 93a546086..5642c3f86 100644 --- a/include/RedDAV/RedBrowser.php +++ b/include/RedDAV/RedBrowser.php @@ -378,11 +378,14 @@ class RedBrowser extends DAV\Browser\Plugin { 'audio/mpeg' => 'icon-music', 'audio/wav' => 'icon-music', 'application/ogg' => 'icon-music', + 'audio/ogg' => 'icon-music', + 'audio/webm' => 'icon-music', + 'audio/mp4' => 'icon-music', //Video 'video/quicktime' => 'icon-film', - - + 'video/webm' => 'icon-film', + 'video/mp4' => 'icon-film' ); $iconFromType = 'icon-file-alt'; diff --git a/include/attach.php b/include/attach.php index 5a945dd66..1a12fc462 100644 --- a/include/attach.php +++ b/include/attach.php @@ -64,6 +64,11 @@ function z_mime_content_type($filename) { 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'ogg' => 'application/ogg', + 'opus' => 'audio/ogg', + 'webm' => 'audio/webm', + 'webm' => 'video/webm', + 'mp4' => 'audio/mp4', + 'mp4' => 'video/mp4', // adobe 'pdf' => 'application/pdf', @@ -81,6 +86,22 @@ function z_mime_content_type($filename) { // open office 'odt' => 'application/vnd.oasis.opendocument.text', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', + 'odp' => 'application/vnd.oasis.opendocument.presentation', + 'odg' => 'application/vnd.oasis.opendocument.graphics', + 'odc' => 'application/vnd.oasis.opendocument.chart', + 'odf' => 'application/vnd.oasis.opendocument.formula', + 'odi' => 'application/vnd.oasis.opendocument.image', + 'odm' => 'application/vnd.oasis.opendocument.text-master', + 'odb' => 'application/vnd.oasis.opendocument.base', + 'odb' => 'application/vnd.oasis.opendocument.database', + 'ott' => 'application/vnd.oasis.opendocument.text-template', + 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', + 'otp' => 'application/vnd.oasis.opendocument.presentation-template', + 'otg' => 'application/vnd.oasis.opendocument.graphics-template', + 'otc' => 'application/vnd.oasis.opendocument.chart-template', + 'otf' => 'application/vnd.oasis.opendocument.formula-template', + 'oti' => 'application/vnd.oasis.opendocument.image-template', + 'oth' => 'application/vnd.oasis.opendocument.text-web' ); $dot = strpos($filename, '.'); @@ -753,16 +774,16 @@ function attach_delete($channel_id, $resource) { $channel_address = (($c) ? $c[0]['channel_address'] : 'notfound'); - $r = q("SELECT hash, filename, flags, folder FROM attach WHERE hash = '%s' AND uid = %d limit 1", + $r = q("SELECT hash, flags, folder FROM attach WHERE hash = '%s' AND uid = %d limit 1", dbesc($resource), intval($channel_id) ); - if(! $r) return; - $url = get_parent_cloudpath($channel_id, $channel_address, $resource) . $r[0]['filename']; + $cloudpath = get_parent_cloudpath($channel_id, $channel_address, $resource); + $object = get_file_activity_object($channel_id, $resource, $cloudpath); // If resource is a directory delete everything in the directory recursive if($r[0]['flags'] & ATTACH_FLAG_DIR) { @@ -806,7 +827,8 @@ function attach_delete($channel_id, $resource) { intval($channel_id) ); - file_activity($channel_id, $resource, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', $url, 'drop', $no_activity=false); + file_activity($channel_id, $object, $allow_cid='', $allow_gid='', $deny_cid='', $deny_gid='', 'update', $no_activity=false); + } /** @@ -942,69 +964,87 @@ function pipe_streams($in, $out) { return $size; } -function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $url, $action, $no_activity) { +function file_activity($channel_id, $object, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $verb, $no_activity) { require_once('include/items.php'); - $url = rawurlencode($url); - $poster = get_app()->get_observer(); - $verb = ACTIVITY_FILE . '/' . $action . '/' . $hash; - $mid = item_message_id(); + $arr = array(); + $arr['item_wall'] = 1; $arr['item_origin'] = 1; $arr['item_unseen'] = 1; - if($action == 'post') { - //check if activity item exists - //if yes send drop activity and create a new one + $objtype = ACTIVITY_OBJ_FILE; - $r = q("SELECT * FROM item WHERE verb = '%s'", - dbesc($verb) - ); - if($r) { - - $dmid = item_message_id(); - $updateverb = ACTIVITY_FILE . '/drop/' . $hash . '#' . $mid; - - $arr = array(); - - $arr['aid'] = get_account_id(); - $arr['uid'] = $channel_id; - $arr['mid'] = $dmid; - $arr['parent_mid'] = $dmid; - $arr['author_xchan'] = $poster['xchan_hash']; - $arr['owner_xchan'] = $poster['xchan_hash']; - $arr['title'] = ''; - $arr['allow_cid'] = $allow_cid; - $arr['allow_gid'] = $allow_gid; - $arr['deny_cid'] = $deny_cid; - $arr['deny_gid'] = $deny_gid; - $arr['item_restrict'] = ITEM_HIDDEN; - $arr['item_private'] = 0; - $arr['verb'] = $updateverb; - $arr['body'] = $url; - - $post = item_store($arr); - $item_id = $post['item_id']; - - if($item_id) { - proc_run('php',"include/notifier.php","activity",$item_id); - } + $private = (($allow_cid || $allow_gid || $deny_cid || $deny_gid) ? 1 : 0); - //call_hooks('post_local_end', $arr); + $jsonobject = json_encode($object); - //notice( t('File activity updated') . EOL); + //check if item for this object exists + $y = q("SELECT * FROM item WHERE verb = '%s' AND obj_type = '%s' AND resource_id = '%s' AND uid = %d LIMIT 1", + dbesc(ACTIVITY_POST), + dbesc($objtype), + dbesc($object['hash']), + intval(local_user()) + ); - if($no_activity) { - return; - } + if($y) { + $update = true; + $object['d_mid'] = $y[0]['mid']; //attach mid of the old object + $u_jsonobject = json_encode($object); + + //we have got the relevant info - delete the old item before we create the new one + $z = q("DELETE FROM item WHERE obj_type = '%s' AND verb = '%s' AND mid = '%s'", + dbesc(ACTIVITY_OBJ_FILE), + dbesc(ACTIVITY_POST), + dbesc($y[0]['mid']) + ); + } + + if($update && $verb == 'post' ) { + //send update activity and create a new one + + $u_mid = item_message_id(); + + $arr['aid'] = get_account_id(); + $arr['uid'] = $channel_id; + $arr['mid'] = $u_mid; + $arr['parent_mid'] = $u_mid; + $arr['author_xchan'] = $poster['xchan_hash']; + $arr['owner_xchan'] = $poster['xchan_hash']; + $arr['title'] = ''; + //updates should be visible to everybody -> perms may have changed + $arr['allow_cid'] = ''; + $arr['allow_gid'] = ''; + $arr['deny_cid'] = ''; + $arr['deny_gid'] = ''; + $arr['item_hidden'] = 1; + $arr['item_private'] = 0; + $arr['verb'] = ACTIVITY_UPDATE; + $arr['obj_type'] = $objtype; + $arr['object'] = $u_jsonobject; + $arr['resource_id'] = $object['hash']; + $arr['resource_type'] = 'attach'; + $arr['body'] = ''; + + $post = item_store($arr); + $item_id = $post['item_id']; + if($item_id) { + proc_run('php',"include/notifier.php","activity",$item_id); } + + call_hooks('post_local_end', $arr); + + $update = false; + + //notice( t('File activity updated') . EOL); + } if($no_activity) { @@ -1027,10 +1067,14 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; - $arr['item_restrict'] = ITEM_HIDDEN; - $arr['item_private'] = 0; - $arr['verb'] = $verb; - $arr['body'] = $url; + $arr['item_hidden'] = 1; + $arr['item_private'] = $private; + $arr['verb'] = (($update) ? ACTIVITY_UPDATE : ACTIVITY_POST); + $arr['obj_type'] = $objtype; + $arr['resource_id'] = $object['hash']; + $arr['resource_type'] = 'attach'; + $arr['object'] = (($update) ? $u_jsonobject : $jsonobject); + $arr['body'] = ''; $post = item_store($arr); $item_id = $post['item_id']; @@ -1039,10 +1083,48 @@ function file_activity($channel_id, $hash, $allow_cid, $allow_gid, $deny_cid, $d proc_run('php',"include/notifier.php","activity",$item_id); } - //call_hooks('post_local_end', $arr); + call_hooks('post_local_end', $arr); - //(($action === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); + //(($verb === 'post') ? notice( t('File activity posted') . EOL) : notice( t('File activity dropped') . EOL)); return; } + +function get_file_activity_object($channel_id, $hash, $cloudpath) { + + $x = q("SELECT creator, filename, filetype, filesize, revision, folder, flags, created, edited FROM attach WHERE uid = %d AND hash = '%s' LIMIT 1", + intval($channel_id), + dbesc($hash) + ); + + $url = rawurlencode($cloudpath . $x[0]['filename']); + + $links = array(); + $links[] = array( + 'rel' => 'alternate', + 'type' => 'text/html', + 'href' => $url + ); + + $object = array( + 'type' => ACTIVITY_OBJ_FILE, + 'title' => $x[0]['filename'], + 'id' => $url, + 'link' => $links, + + 'hash' => $hash, + 'creator' => $x[0]['creator'], + 'filename' => $x[0]['filename'], + 'filetype' => $x[0]['filetype'], + 'filesize' => $x[0]['filesize'], + 'revision' => $x[0]['revision'], + 'folder' => $x[0]['folder'], + 'flags' => $x[0]['flags'], + 'created' => $x[0]['created'], + 'edited' => $x[0]['edited'] + ); + + return $object; + +} diff --git a/include/bbcode.php b/include/bbcode.php index 33017c011..5504dce7a 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -746,7 +746,7 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) { $Text = preg_replace_callback("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", 'tryzrlvideo', $Text); } if (strpos($Text,'[/audio]') !== false) { - $Text = preg_replace_callback("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", 'tryzrlaudio', $Text); + $Text = preg_replace_callback("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3|opus))\[\/audio\]/ism", 'tryzrlaudio', $Text); } // Try to Oembed diff --git a/include/diaspora.php b/include/diaspora.php index 317a4cbf9..4c7b58887 100755 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2549,7 +2549,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) { $relay_retract = false; $sql_sign_id = 'iid'; - if( intval($item['item_deleted']) { + if( intval($item['item_deleted'])) { $relay_retract = true; $target_type = ( ($item['verb'] === ACTIVITY_LIKE) ? 'Like' : 'Comment'); diff --git a/include/features.php b/include/features.php index 1a4b2654f..6b4bc34c6 100644 --- a/include/features.php +++ b/include/features.php @@ -57,6 +57,7 @@ function get_features() { t('Post Composition Features'), // array('richtext', t('Richtext Editor'), t('Enable richtext editor'),false), array('markdown', t('Use Markdown'), t('Allow use of "Markdown" to format posts'),false), + array('large_photos', t('Large Photos'), t('Include large (640px) photo thumbnails in posts. If not enabled, use small (320px) photo thumbnails'),false), array('channel_sources', t('Channel Sources'), t('Automatically import channel content from other channels or feeds'),false), array('content_encrypt', t('Even More Encryption'), t('Allow optional encryption of content end-to-end with a shared secret key'),false), array('adult_photo_flagging', t('Flag Adult Photos'), t('Provide photo edit option to hide adult photos from default album view'),false), diff --git a/include/follow.php b/include/follow.php index 1abd0e3b9..06c0c5c62 100644 --- a/include/follow.php +++ b/include/follow.php @@ -66,14 +66,15 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $my_perms = get_channel_default_perms($uid); - if($is_red && $j) { + $role = get_pconfig($uid,'system','permissions_role'); + if($role) { + $x = get_role_perms($role); + if($x['perms_follow']) + $my_perms = $x['perms_follow']; + } - $role = get_pconfig($uid,'system','permissions_role'); - if($role) { - $x = get_role_perms($role); - if($x['perms_follow']) - $my_perms = $x['perms_follow']; - } + + if($is_red && $j) { logger('follow: ' . $url . ' ' . print_r($j,true), LOGGER_DEBUG); @@ -105,7 +106,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) $xchan_hash = $x['hash']; - $their_perms = 0; $global_perms = get_perms(); @@ -163,12 +163,6 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) if($r) { $xchan_hash = $r[0]['xchan_hash']; $their_perms = 0; - $role = get_pconfig($uid,'system','permissions_role'); - if($role) { - $x = get_role_perms($role); - if($x['perms_follow']) - $my_perms = $x['perms_follow']; - } } } @@ -198,6 +192,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) } if($is_http) { + if(! intval(get_config('system','feed_contacts'))) { $result['message'] = t('Protocol disabled.'); return $result; diff --git a/include/items.php b/include/items.php index 180600495..21025f76f 100755 --- a/include/items.php +++ b/include/items.php @@ -3979,7 +3979,7 @@ function drop_item($id,$interactive = true,$stage = DROPITEM_NORMAL,$force = fal // set the deleted flag immediately on this item just in case the // hook calls a remote process which loops. We'll delete it properly in a second. - if($linked_item) && ! $force) { + if(($linked_item) && (! $force)) { $r = q("UPDATE item SET item_restrict = ( item_restrict | %d ) WHERE id = %d", intval(ITEM_HIDDEN), intval($item['id']) diff --git a/include/network.php b/include/network.php index 8082d0217..5f95cf0e0 100644 --- a/include/network.php +++ b/include/network.php @@ -464,24 +464,47 @@ function allowed_email($email) { return false; $str_allowed = get_config('system','allowed_email'); - if(! $str_allowed) + $str_not_allowed = get_config('system','not_allowed_email'); + + if(! $str_allowed && ! $str_not_allowed) return true; - $found = false; - + $return = false; + $found_allowed = false; + $found_not_allowed = false; + $fnmatch = function_exists('fnmatch'); + $allowed = explode(',',$str_allowed); if(count($allowed)) { foreach($allowed as $a) { $pat = strtolower(trim($a)); - if(($fnmatch && fnmatch($pat,$domain)) || ($pat == $domain)) { - $found = true; + if(($fnmatch && fnmatch($pat,$email)) || ($pat == $domain)) { + $found_allowed = true; break; } } } - return $found; + + $not_allowed = explode(',',$str_not_allowed); + + if(count($not_allowed)) { + foreach($not_allowed as $na) { + $pat = strtolower(trim($na)); + if(($fnmatch && fnmatch($pat,$email)) || ($pat == $domain)) { + $found_not_allowed = true; + break; + } + } + } + + if ($found_allowed) { + $return = true; + } elseif (!$str_allowed && !$found_not_allowed) { + $return = true; + } + return $return; } diff --git a/include/oembed.php b/include/oembed.php index e08b287d1..38c433e99 100755 --- a/include/oembed.php +++ b/include/oembed.php @@ -21,7 +21,7 @@ function oembed_fetch_url($embedurl){ // These media files should now be caught in bbcode.php // left here as a fallback in case this is called from another source - $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm"); + $noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm","opus"); $ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION); diff --git a/include/onedirsync.php b/include/onedirsync.php index 215c90008..ce516da9d 100644 --- a/include/onedirsync.php +++ b/include/onedirsync.php @@ -41,10 +41,11 @@ function onedirsync_run($argv, $argc){ intval(UPDATE_FLAGS_UPDATED) ); if($x) { - $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ", + $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date != '%s'", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), - intval(UPDATE_FLAGS_UPDATED) + intval(UPDATE_FLAGS_UPDATED), + dbesc($x[0]['ud_date']) ); return; } @@ -54,12 +55,11 @@ function onedirsync_run($argv, $argc){ $h = q("select * from hubloc where hubloc_addr = '%s' limit 1", dbesc($r[0]['ud_addr']) ); - if(($h) && (intval($h[0]['hubloc_error']))) { - $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 and ud_date < '%s' ", + if(($h) && ($h[0]['hubloc_status'] & HUBLOC_OFFLINE)) { + $y = q("update updates set ud_flags = ( ud_flags | %d ) where ud_addr = '%s' and ( ud_flags & %d ) = 0 ", intval(UPDATE_FLAGS_UPDATED), dbesc($r[0]['ud_addr']), - intval(UPDATE_FLAGS_UPDATED), - dbesc($x[0]['ud_date']) + intval(UPDATE_FLAGS_UPDATED) ); return; diff --git a/include/photos.php b/include/photos.php index 0ac47f7ba..f52b08473 100644 --- a/include/photos.php +++ b/include/photos.php @@ -252,10 +252,24 @@ function photo_upload($channel, $observer, $args) { $arr['item_thread_top'] = 1; $arr['plink'] = z_root() . '/channel/' . $channel['channel_address'] . '/?f=&mid=' . $arr['mid']; - if ($width_x_height) - $tag = '[zmg=' . $width_x_height. ']'; - else + // We should also put a width_x_height on large photos. Left as an exercise for + // devs looking fo simple stuff to fix. + + $larger = feature_enabled($channel['channel_id'],'large_photos'); + if($larger) { $tag = '[zmg]'; + if($r2) + $smallest = 1; + else + $smallest = 0; + } + else { + if ($width_x_height) + $tag = '[zmg=' . $width_x_height. ']'; + else + $tag = '[zmg]'; + } + $arr['body'] = '[zrl=' . z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash . ']' . $tag . z_root() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/zmg]' diff --git a/include/poller.php b/include/poller.php index a9647c725..b655259a4 100644 --- a/include/poller.php +++ b/include/poller.php @@ -388,7 +388,7 @@ function poller_run($argv, $argc){ } if($dirmode == DIRECTORY_MODE_SECONDARY || $dirmode == DIRECTORY_MODE_PRIMARY) { - $r = q("select distinct ud_addr, updates.* from updates where ( ud_flags & %d ) = 0 and ud_addr != '' and ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) group by ud_addr ", + $r = q("SELECT u.ud_addr, u.ud_id, u.ud_last FROM updates AS u INNER JOIN (SELECT ud_addr, max(ud_id) AS ud_id FROM updates WHERE ( ud_flags & %d ) = 0 AND ud_addr != '' AND ( ud_last = '%s' OR ud_last > %s - INTERVAL %s ) GROUP BY ud_addr) AS s ON s.ud_id = u.ud_id ", intval(UPDATE_FLAGS_UPDATED), dbesc(NULL_DATE), db_utcnow(), db_quoteinterval('7 DAY') diff --git a/include/socgraph.php b/include/socgraph.php index 466f4212d..ae135b2a8 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -119,7 +119,7 @@ function poco_load($xchan = '',$url = null) { $name = $entry['displayName']; $hash = $entry['hash']; - $rating = ((array_key_exists('rating',$entry)) ? intval($entry['rating']) : 0); + $rating = ((array_key_exists('rating',$entry) && (! is_array($entry['rating']))) ? intval($entry['rating']) : 0); $rating_text = ((array_key_exists('rating_text',$entry)) ? escape_tags($entry['rating_text']) :''); if(x($entry,'urls') && is_array($entry['urls'])) { @@ -414,3 +414,212 @@ function update_suggestions() { } } } + + +function poco($a,$extended = false) { + + $system_mode = false; + + if(intval(get_config('system','block_public')) && (! local_user()) && (! remote_user())) { + logger('mod_poco: block_public'); + http_status_exit(401); + } + + $observer = $a->get_observer(); + + if(argc() > 1) { + $user = notags(trim(argv(1))); + } + if(! x($user)) { + $c = q("select * from pconfig where cat = 'system' and k = 'suggestme' and v = '1'"); + if(! $c) { + logger('mod_poco: system mode. No candidates.', LOGGER_DEBUG); + http_status_exit(404); + } + $system_mode = true; + } + + + $format = (($_REQUEST['format']) ? $_REQUEST['format'] : 'json'); + + $justme = false; + + if(argc() > 2 && argv(2) === '@me') + $justme = true; + if(argc() > 3) { + if(argv(3) === '@all') + $justme = false; + elseif(argv(3) === '@self') + $justme = true; + } + if(argc() > 4 && intval(argv(4)) && $justme == false) + $cid = intval(argv(4)); + + if(! $system_mode) { + + $r = q("SELECT channel_id from channel where channel_address = '%s' limit 1", + dbesc($user) + ); + if(! $r) { + logger('mod_poco: user mode. Account not found. ' . $user); + http_status_exit(404); + } + + $channel_id = $r[0]['channel_id']; + $ohash = (($observer) ? $observer['xchan_hash'] : ''); + + if(! perm_is_allowed($channel_id,$ohash,'view_contacts')) { + logger('mod_poco: user mode. Permission denied for ' . $ohash . ' user: ' . $user); + http_status_exit(401); + } + + } + + if($justme) + $sql_extra = " and ( abook_flags & " . ABOOK_FLAG_SELF . " )>0 "; + else + $sql_extra = " and abook_flags = 0 "; + + if($cid) + $sql_extra = sprintf(" and abook_id = %d ",intval($cid)); + + if($system_mode) { + $r = q("SELECT count(*) as `total` from abook where ( abook_flags & " . ABOOK_FLAG_SELF . + " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = '1') "); + } + else { + $r = q("SELECT count(*) as `total` from abook where abook_channel = %d + $sql_extra ", + intval($channel_id) + ); + $rooms = q("select * from menu_item where ( mitem_flags & " . intval(MENU_ITEM_CHATROOM) . " )>0 and allow_cid = '' and allow_gid = '' and deny_cid = '' and deny_gid = '' and mitem_channel_id = %d", + intval($channel_id) + ); + } + if($r) + $totalResults = intval($r[0]['total']); + else + $totalResults = 0; + + $startIndex = intval($_GET['startIndex']); + if(! $startIndex) + $startIndex = 0; + $itemsPerPage = ((x($_GET,'count') && intval($_GET['count'])) ? intval($_GET['count']) : $totalResults); + + + if($system_mode) { + $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where ( abook_flags & " . ABOOK_FLAG_SELF . + " )>0 and abook_channel in (select uid from pconfig where cat = 'system' and k = 'suggestme' and v = '1') limit %d offset %d ", + intval($itemsPerPage), + intval($startIndex) + ); + } + else { + $r = q("SELECT abook.*, xchan.* from abook left join xchan on abook_xchan = xchan_hash where abook_channel = %d + $sql_extra LIMIT %d OFFSET %d", + intval($channel_id), + intval($itemsPerPage), + intval($startIndex) + ); + } + + $ret = array(); + if(x($_GET,'sorted')) + $ret['sorted'] = 'false'; + if(x($_GET,'filtered')) + $ret['filtered'] = 'false'; + if(x($_GET,'updatedSince')) + $ret['updateSince'] = 'false'; + + $ret['startIndex'] = (string) $startIndex; + $ret['itemsPerPage'] = (string) $itemsPerPage; + $ret['totalResults'] = (string) $totalResults; + + if($rooms) { + $ret['chatrooms'] = array(); + foreach($rooms as $room) { + $ret['chatrooms'][] = array('url' => $room['mitem_link'], 'desc' => $room['mitem_desc']); + } + } + + $ret['entry'] = array(); + + + $fields_ret = array( + 'id' => false, + 'guid' => false, + 'guid_sig' => false, + 'hash' => false, + 'displayName' => false, + 'urls' => false, + 'preferredUsername' => false, + 'photos' => false, + 'rating' => false + ); + + if((! x($_GET,'fields')) || ($_GET['fields'] === '@all')) + foreach($fields_ret as $k => $v) + $fields_ret[$k] = true; + else { + $fields_req = explode(',',$_GET['fields']); + foreach($fields_req as $f) + $fields_ret[trim($f)] = true; + } + + if(is_array($r)) { + if(count($r)) { + foreach($r as $rr) { + $entry = array(); + if($fields_ret['id']) + $entry['id'] = $rr['abook_id']; + if($fields_ret['guid']) + $entry['guid'] = $rr['xchan_guid']; + if($fields_ret['guid_sig']) + $entry['guid_sig'] = $rr['xchan_guid_sig']; + if($fields_ret['hash']) + $entry['hash'] = $rr['xchan_hash']; + + if($fields_ret['displayName']) + $entry['displayName'] = $rr['xchan_name']; + if($fields_ret['urls']) { + $entry['urls'] = array(array('value' => $rr['xchan_url'], 'type' => 'profile')); + $network = $rr['xchan_network']; + if(strpos($network,'friendica') !== false) + $network = 'friendica'; + if($rr['xchan_addr']) + $entry['urls'][] = array('value' => 'acct:' . $rr['xchan_addr'], 'type' => $network); + } + if($fields_ret['preferredUsername']) + $entry['preferredUsername'] = substr($rr['xchan_addr'],0,strpos($rr['xchan_addr'],'@')); + if($fields_ret['photos']) + $entry['photos'] = array(array('value' => $rr['xchan_photo_l'], 'mimetype' => $rr['xchan_photo_mimetype'], 'type' => 'profile')); + if($fields_ret['rating']) { + $entry['rating'] = ((array_key_exists('abook_rating',$rr)) ? intval($rr['abook_rating']) : 0); + $entry['rating_text'] = ((array_key_exists('abook_rating_text',$rr)) ? $rr['abook_rating_text'] : ''); + // maybe this should be a composite calculated rating in $system_mode + if($system_mode) + $entry['rating'] = 0; + } + $ret['entry'][] = $entry; + } + } + else + $ret['entry'][] = array(); + } + else + http_status_exit(500); + + if($format === 'xml') { + header('Content-type: text/xml'); + echo replace_macros(get_markup_template('poco_xml.tpl'),array_xmlify(array('$response' => $ret))); + http_status_exit(500); + } + if($format === 'json') { + header('Content-type: application/json'); + echo json_encode($ret); + killme(); + } + else + http_status_exit(500); + +} diff --git a/include/text.php b/include/text.php index 101d6ca2e..2aa270f3b 100644 --- a/include/text.php +++ b/include/text.php @@ -897,7 +897,8 @@ function sslify($s) { $cnt = preg_match_all("/\<(.*?)src=\"(http\:.*?)\"(.*?)\>/",$s,$matches,PREG_SET_ORDER); if($cnt) { foreach($matches as $match) { - $s = str_replace($match[2],z_root() . '/sslify?f=&url=' . urlencode($match[2]),$s); + $filename = basename( parse_url($match[2],PHP_URL_PATH) ); + $s = str_replace($match[2],z_root() . '/sslify/' . $filename . '?f=&url=' . urlencode($match[2]),$s); } } return $s; diff --git a/include/zot.php b/include/zot.php index 07d228ea5..18565a214 100644 --- a/include/zot.php +++ b/include/zot.php @@ -175,7 +175,7 @@ function zot_zot($url,$data) { */ -function zot_finger($webbie,$channel,$autofallback = true) { +function zot_finger($webbie,$channel = null,$autofallback = true) { if(strpos($webbie,'@') === false) { |