From ac541a7d3246e1c5c60ae752326c1b9ba5ccd78f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 14 Aug 2013 20:09:02 -0700 Subject: most of expire is now ported from friendica, but the protocol bits to push out the delete notifications for the entire batch to all recipients of the original post are not complete and will take quite a bit more work. As a consequence, expire has been completely disabled until it is fully implmented since it could result in completely un-removable posts reminiscent of the infamous "Bonnie Nadri" incident at Diaspora which we do not wish to re-live. --- include/features.php | 3 ++- include/notifier.php | 19 +++++++++++++++---- include/poller.php | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/features.php b/include/features.php index da1322a14..757f719df 100644 --- a/include/features.php +++ b/include/features.php @@ -19,7 +19,8 @@ function get_features() { // General 'general' => array( t('General Features'), - array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')), +// uncomment when expire is fixed +// array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')), array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles')), array('webpages', t('Web Pages'), t('Provide managed web pages on your channel')), array('prettyphoto', t('Enhanced Photo Albums'), t('Enable photo album with enhanced features')), diff --git a/include/notifier.php b/include/notifier.php index a0c07200a..2a0301357 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -54,6 +54,7 @@ require_once('include/html2plain.php'); * ZOT * permission_update abook_id * refresh_all channel_id + * expire channel_id * relay item_id (item was relayed to owner, we will deliver it as owner) * */ @@ -166,14 +167,24 @@ function notifier_run($argv, $argc){ elseif($cmd === 'expire') { $normal_mode = false; $expire = true; - $items = q("SELECT * FROM `item` WHERE `uid` = %d AND `wall` = 1 - AND `deleted` = 1 AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE", - intval($item_id) + $items = q("SELECT * FROM item WHERE uid = %d AND ( item_flags & %d ) + AND ( item_restrict & %d ) AND `changed` > UTC_TIMESTAMP() - INTERVAL 10 MINUTE", + intval($item_id), + intval(ITEM_WALL), + intval(ITEM_DELETED) ); $uid = $item_id; $item_id = 0; - if(! count($items)) + if(! $items) return; + +// FIXME +// This will require a special zot packet containing a list of item message_id's to be expired. +// This packet will be public, since we cannot selectively deliver here. +// We need the handling on this end to create the array, and the handling on the remote end +// to verify permissions (for each item) and process it. Until this is complete, the expire feature will be disabled. + + return; } elseif($cmd === 'suggest') { $normal_mode = false; diff --git a/include/poller.php b/include/poller.php index 00914a712..7f76750b4 100644 --- a/include/poller.php +++ b/include/poller.php @@ -84,7 +84,8 @@ function poller_run($argv, $argc){ set_config('system','last_expire_day',$d2); - proc_run('php','include/expire.php'); +// Uncomment when expire protocol component is working +// proc_run('php','include/expire.php'); proc_run('php','include/cli_suggest.php'); -- cgit v1.2.3 From bdfd0aa917d75f68ff20d900e691f626df13da79 Mon Sep 17 00:00:00 2001 From: Christian Vogeley Date: Fri, 16 Aug 2013 02:30:55 +0200 Subject: Fix Load mobile theme --- include/security.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/security.php b/include/security.php index ef4d5a313..115539ae2 100644 --- a/include/security.php +++ b/include/security.php @@ -34,6 +34,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive else { $_SESSION['uid'] = $user_record['uid']; $_SESSION['theme'] = $user_record['theme']; + $_SESSION['mobile-theme'] = get_pconfig($user_record['uid'], 'system', 'mobile_theme'); $_SESSION['authenticated'] = 1; $_SESSION['page_flags'] = $user_record['page-flags']; $_SESSION['my_url'] = $a->get_baseurl() . '/channel/' . $user_record['nickname']; @@ -148,6 +149,7 @@ function change_channel($change_channel) { $_SESSION['uid'] = intval($r[0]['channel_id']); get_app()->set_channel($r[0]); $_SESSION['theme'] = $r[0]['channel_theme']; + $_SESSION['mobile-theme'] = get_pconfig(local_user(),'system', 'mobile_theme'); date_default_timezone_set($r[0]['channel_timezone']); $ret = $r[0]; } -- cgit v1.2.3 From d46436dc9c115d29a18a29203bd12d3246472365 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 15 Aug 2013 17:36:00 -0700 Subject: issues marking for death --- include/poller.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/poller.php b/include/poller.php index 7f76750b4..7a6aaeb22 100644 --- a/include/poller.php +++ b/include/poller.php @@ -118,18 +118,18 @@ function poller_run($argv, $argc){ $force = false; $restart = false; - if((argc() > 1) && (argv(1) == 'force')) + if(($argc > 1) && ($argv[1] == 'force')) $force = true; - if((argc() > 1) && (argv(1) == 'restart')) { + if(($argc > 1) && ($argv[1] == 'restart')) { $restart = true; - $generation = intval(argv(2)); + $generation = intval($argv[2]); if(! $generation) killme(); } - if((argc() > 1) && intval(argv(1))) { - $manual_id = intval(argv(1)); + if(($argc > 1) && intval($argv[1])) { + $manual_id = intval($argv[1]); $force = true; } @@ -157,7 +157,8 @@ function poller_run($argv, $argc){ : '' ); - $contacts = q("SELECT abook_id, abook_updated, abook_closeness, abook_channel + + $contacts = q("SELECT abook_id, abook_updated, abook_connected, abook_closeness, abook_channel FROM abook LEFT JOIN account on abook_account = account_id where 1 $sql_extra AND (( abook_flags = %d ) OR ( abook_flags = %d )) @@ -189,10 +190,10 @@ function poller_run($argv, $argc){ else { // if we've never connected with them, start the mark for death countdown from now - if($c === '0000-00-00 00:00:00') { + if($c == '0000-00-00 00:00:00') { $r = q("update abook set abook_connected = '%s' where abook_id = %d limit 1", dbesc(datetime_convert()), - intval($abook['abook_id']) + intval($contact['abook_id']) ); $c = datetime_convert(); $update = true; @@ -200,8 +201,8 @@ function poller_run($argv, $argc){ // He's dead, Jim - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $c . " + 30 day")) { - $r = q("update abook set abook_flags = (abook_flags & %d) where abook_id = %d limit 1", + if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 30 day")) > 0) { + $r = q("update abook set abook_flags = (abook_flags | %d) where abook_id = %d limit 1", intval(ABOOK_FLAG_ARCHIVED), intval($contact['abook_id']) ); @@ -213,17 +214,17 @@ function poller_run($argv, $argc){ // recently deceased, so keep up the regular schedule for 3 days - if((datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $c . " + 3 day")) - && (datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))) + if((strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $c . " + 3 day")) > 0) + && (strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 1 day")) > 0)) $update = true; // After that back off and put them on a morphine drip - if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 2 day")) { + if(strcmp(datetime_convert('UTC','UTC', 'now'),datetime_convert('UTC','UTC', $t . " + 2 day")) > 0) { $update = true; } } - +dbg(0); if((! $update) && (! $force)) continue; -- cgit v1.2.3 From 764e0201ce8259c84a3b6ce643a52effe9dc8a59 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 15 Aug 2013 17:43:19 -0700 Subject: don't include archived contacts in public posts, unless specifically requested --- include/Contact.php | 4 ++-- include/items.php | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index 992ed27e2..bf536ccd5 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -295,8 +295,8 @@ function contact_remove($channel_id, $abook_id) { $archive = get_pconfig($channel_id, 'system','archive_removed_contacts'); if($archive) { - q("update abook set abook_flags = abook_flags | %d where abook_id = %d and abook_channel = %d limit 1", - intval(ABOOK_FLAG_ARCHIVE), + q("update abook set abook_flags = ( abook_flags | %d ) where abook_id = %d and abook_channel = %d limit 1", + intval(ABOOK_FLAG_ARCHIVED), intval($abook_id), intval($channel_id) ); diff --git a/include/items.php b/include/items.php index 6d853323f..df49ba5c7 100755 --- a/include/items.php +++ b/include/items.php @@ -31,10 +31,11 @@ function collect_recipients($item,&$private) { } else { $recipients = array(); - $r = q("select * from abook where abook_channel = %d and not (abook_flags & %d) and not (abook_flags & %d)", + $r = q("select * from abook where abook_channel = %d and not (abook_flags & %d) and not (abook_flags & %d) and not (abook_flags & %d)", intval($item['uid']), intval(ABOOK_FLAG_SELF), - intval(ABOOK_FLAG_PENDING) + intval(ABOOK_FLAG_PENDING), + intval(ABOOK_FLAG_ARCHIVED) ); if($r) { foreach($r as $rr) { -- cgit v1.2.3 From a8dd7280b33008d5100b6d8020640673abf5a78a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 15 Aug 2013 22:52:19 -0700 Subject: get rid of more variables with dashes in the names - use underscore *except* in CSS. These were probably already here, but if you see any - please keep them out of PHP and MySQL where they sometimes get interpreted as a subtraction operation and are a bugger to find. --- include/auth.php | 2 +- include/oauth.php | 2 +- include/security.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/auth.php b/include/auth.php index c86a54fb1..143a16de8 100644 --- a/include/auth.php +++ b/include/auth.php @@ -14,7 +14,7 @@ function nuke_session() { unset($_SESSION['administrator']); unset($_SESSION['cid']); unset($_SESSION['theme']); - unset($_SESSION['mobile-theme']); + unset($_SESSION['mobile_theme']); unset($_SESSION['page_flags']); unset($_SESSION['submanage']); unset($_SESSION['my_url']); diff --git a/include/oauth.php b/include/oauth.php index 2f70f21fb..6ec5285e4 100644 --- a/include/oauth.php +++ b/include/oauth.php @@ -145,7 +145,7 @@ class FKOAuth1 extends OAuthServer { } $_SESSION['uid'] = $record['uid']; $_SESSION['theme'] = $record['theme']; - $_SESSION['mobile-theme'] = get_pconfig($record['uid'], 'system', 'mobile_theme'); + $_SESSION['mobile_theme'] = get_pconfig($record['uid'], 'system', 'mobile_theme'); $_SESSION['authenticated'] = 1; $_SESSION['page_flags'] = $record['page-flags']; $_SESSION['my_url'] = $a->get_baseurl() . '/channel/' . $record['nickname']; diff --git a/include/security.php b/include/security.php index 115539ae2..4738e473b 100644 --- a/include/security.php +++ b/include/security.php @@ -34,7 +34,7 @@ function authenticate_success($user_record, $login_initial = false, $interactive else { $_SESSION['uid'] = $user_record['uid']; $_SESSION['theme'] = $user_record['theme']; - $_SESSION['mobile-theme'] = get_pconfig($user_record['uid'], 'system', 'mobile_theme'); + $_SESSION['mobile_theme'] = get_pconfig($user_record['uid'], 'system', 'mobile_theme'); $_SESSION['authenticated'] = 1; $_SESSION['page_flags'] = $user_record['page-flags']; $_SESSION['my_url'] = $a->get_baseurl() . '/channel/' . $user_record['nickname']; @@ -149,7 +149,7 @@ function change_channel($change_channel) { $_SESSION['uid'] = intval($r[0]['channel_id']); get_app()->set_channel($r[0]); $_SESSION['theme'] = $r[0]['channel_theme']; - $_SESSION['mobile-theme'] = get_pconfig(local_user(),'system', 'mobile_theme'); + $_SESSION['mobile_theme'] = get_pconfig(local_user(),'system', 'mobile_theme'); date_default_timezone_set($r[0]['channel_timezone']); $ret = $r[0]; } -- cgit v1.2.3 From 353ccaac05fa73b7cdca4d5cc4ed7cc789a220b8 Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Sun, 18 Aug 2013 05:03:04 +0100 Subject: Issue #99 --- include/socgraph.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include') diff --git a/include/socgraph.php b/include/socgraph.php index 177ed0f3a..b34d5142c 100644 --- a/include/socgraph.php +++ b/include/socgraph.php @@ -1,5 +1,6 @@ Date: Sun, 18 Aug 2013 00:04:38 -0700 Subject: Another try at issue #61 and #62 - an earlier fix was partially working but the issue persisted - this extends it a bit. --- include/items.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index df49ba5c7..5137a8b31 100755 --- a/include/items.php +++ b/include/items.php @@ -773,14 +773,19 @@ function decode_tags($t) { function activity_sanitise($arr) { if($arr) { - $ret = array(); - foreach($arr as $k => $x) { - if(is_array($x)) - $ret[$k] = activity_sanitise($x); - else - $ret[$k] = htmlentities($x, ENT_COMPAT,'UTF-8',false); + if(is_array($arr)) { + $ret = array(); + foreach($arr as $k => $x) { + if(is_array($x)) + $ret[$k] = activity_sanitise($x); + else + $ret[$k] = htmlentities($x, ENT_COMPAT,'UTF-8',false); + } + return $ret; + } + else { + return htmlentities($arr, ENT_COMPAT,'UTF-8', false); } - return $ret; } return ''; } @@ -1572,10 +1577,10 @@ function item_store($arr,$allow_exec = false) { unset($arr['term']); } - dbesc_array($arr); - logger('item_store: ' . print_r($arr,true), LOGGER_DATA); + dbesc_array($arr); + $r = dbq("INSERT INTO `item` (`" . implode("`, `", array_keys($arr)) . "`) VALUES ('" -- cgit v1.2.3 From 8bac352b1cbbefd12fe04e1b269367472cba58ee Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 18 Aug 2013 05:04:37 -0700 Subject: item_store logging to discover where object is getting quote mangled. --- include/items.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 5137a8b31..ba0867562 100755 --- a/include/items.php +++ b/include/items.php @@ -1417,12 +1417,15 @@ function item_store($arr,$allow_exec = false) { } - + if($arr['object']) + logger('item_store: input object: ' . print_r($arr['object'],true), LOGGER_DATA); if((x($arr,'object')) && is_array($arr['object'])) { activity_sanitise($arr['object']); + logger('item_store: sanitised object: ' . print_r($arr['object'],true), LOGGER_DATA); $arr['object'] = json_encode($arr['object']); + logger('item_store: encoded object: ' . print_r($arr['object'],true), LOGGER_DATA); } if((x($arr,'target')) && is_array($arr['target'])) { -- cgit v1.2.3 From 20f3d097080fde4315b25523fe29b129cdd7034c Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 18 Aug 2013 20:20:03 -0700 Subject: some sane permission defaults. --- include/follow.php | 5 +++-- include/identity.php | 15 +++++++++++++-- include/permissions.php | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 6b192234c..ce550b07f 100644 --- a/include/follow.php +++ b/include/follow.php @@ -145,12 +145,13 @@ function new_contact($uid,$url,$channel,$interactive = false) { ); } else { - $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_created, abook_updated ) - values( %d, %d, '%s', %d, '%s', '%s' ) ", + $r = q("insert into abook ( abook_account, abook_channel, abook_xchan, abook_their_perms, abook_my_perms, abook_created, abook_updated ) + values( %d, %d, '%s', %d, %d, '%s', '%s' ) ", intval($aid), intval($uid), dbesc($xchan_hash), intval($their_perms), + intval(PERMS_W_STREAM|PERMS_W_MAIL), dbesc(datetime_convert()), dbesc(datetime_convert()) ); diff --git a/include/identity.php b/include/identity.php index 99b90cc8b..5f210c456 100644 --- a/include/identity.php +++ b/include/identity.php @@ -115,11 +115,19 @@ function create_identity($arr) { if(array_key_exists('primary', $arr)) $primary = intval($arr['primary']); + $perms_sql = ''; + + $defperms = site_default_perms(); + $global_perms = get_perms(); + foreach($defperms as $p => $v) { + $perms_keys .= ', ' . $global_perms[$p][0]; + $perms_vals .= ', ' . intval($v); + } $r = q("insert into channel ( channel_account_id, channel_primary, channel_name, channel_address, channel_guid, channel_guid_sig, - channel_hash, channel_prvkey, channel_pubkey, channel_pageflags ) - values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d ) ", + channel_hash, channel_prvkey, channel_pubkey, channel_pageflags $perms_keys ) + values ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d $perms_vals ) ", intval($arr['account_id']), intval($primary), @@ -133,6 +141,9 @@ function create_identity($arr) { intval($pageflags) ); + + + $r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", intval($arr['account_id']), diff --git a/include/permissions.php b/include/permissions.php index e7f50ceeb..bf50ebdd1 100644 --- a/include/permissions.php +++ b/include/permissions.php @@ -328,3 +328,38 @@ function check_list_permissions($uid,$arr,$perm) { return($result); } + + +function site_default_perms() { + + $typical = array( + 'view_stream' => PERMS_PUBLIC, + 'view_profile' => PERMS_PUBLIC, + 'view_photos' => PERMS_PUBLIC, + 'view_contacts' => PERMS_PUBLIC, + 'view_storage' => PERMS_PUBLIC, + 'view_pages' => PERMS_PUBLIC, + 'send_stream' => PERMS_SPECIFIC, + 'post_wall' => PERMS_SPECIFIC, + 'post_comments' => PERMS_SPECIFIC, + 'post_mail' => PERMS_SPECIFIC, + 'post_photos' => 0, + 'tag_deliver' => PERMS_SPECIFIC, + 'chat' => PERMS_SPECIFIC, + 'write_storage' => 0, + 'write_pages' => 0, + 'delegate' => 0, + ); + + + $global_perms = get_perms(); + $ret = array(); + + foreach($global_perms as $perm => $v) { + $x = get_config('default_perms',$perm); + if($x === false) + $x = $typical[$perm]; + $ret[$perm] = $x; + } + return $ret; +} -- cgit v1.2.3 From b9314935e6f85bb0098c651d021ce9bdc2753ecb Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 19 Aug 2013 19:05:11 -0700 Subject: localize_item() thinks all likes on posts are likes on comments because we didn't pass any info in the activity object to distinguish them from each other. --- include/conversation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 6d551a5c9..aade06b8a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -137,7 +137,7 @@ function localize_item(&$item){ case ACTIVITY_OBJ_NOTE: default: $post_type = t('status'); - if($obj['id'] != $item['mid']) + if($obj['mid'] != $obj['parent_mid']) $post_type = t('comment'); break; } -- cgit v1.2.3 From cd5fdbcb48a2e05198bb9daaf0753e8218ea4285 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 19 Aug 2013 21:19:39 -0700 Subject: email attachments (and fix email photos) --- include/items.php | 10 ++++++++++ include/message.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index ba0867562..10bdcb38f 100755 --- a/include/items.php +++ b/include/items.php @@ -840,6 +840,9 @@ function encode_mail($item) { $x['from'] = encode_item_xchan($item['from']); $x['to'] = encode_item_xchan($item['to']); + if($item['attach']) + $x['attach'] = json_decode_plus($item['attach']); + $x['flags'] = array(); if($item['mail_flags'] & MAIL_RECALLED) { @@ -885,6 +888,9 @@ function get_mail_elements($x) { $arr['mid'] = (($x['message_id']) ? htmlentities($x['message_id'], ENT_COMPAT,'UTF-8',false) : ''); $arr['parent_mid'] = (($x['message_parent']) ? htmlentities($x['message_parent'], ENT_COMPAT,'UTF-8',false) : ''); + if($x['attach']) + $arr['attach'] = activity_sanitise($x['attach']); + if(import_author_xchan($x['from'])) $arr['from_xchan'] = base64url_encode(hash('whirlpool',$x['from']['guid'] . $x['from']['guid_sig'], true)); @@ -2202,6 +2208,9 @@ function mail_store($arr) { if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false)) $arr['body'] = escape_tags($arr['body']); + if(array_key_exists('attach',$arr) && is_array($arr['attach'])) + $arr['attach'] = json_encode($arr['attach']); + $arr['account_id'] = ((x($arr,'account_id')) ? intval($arr['account_id']) : 0); $arr['mid'] = ((x($arr,'mid')) ? notags(trim($arr['mid'])) : random_string()); $arr['from_xchan'] = ((x($arr,'from_xchan')) ? notags(trim($arr['from_xchan'])) : ''); @@ -2210,6 +2219,7 @@ function mail_store($arr) { $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : ''); $arr['parent_mid'] = ((x($arr,'parent_mid')) ? notags(trim($arr['parent_mid'])) : ''); $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : ''); + $arr['mail_flags'] = ((x($arr,'mail_flags')) ? intval($arr['mail_flags']) : 0 ); diff --git a/include/message.php b/include/message.php index fc0d5f2b3..e54a6cd83 100644 --- a/include/message.php +++ b/include/message.php @@ -3,6 +3,7 @@ /* Private Message backend API */ require_once('include/crypto.php'); +require_once('include/attach.php'); // send a private message @@ -74,14 +75,44 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' if(preg_match_all("/\[img\](.*?)\[\/img\]/",$body,$match)) $images = $match[1]; + $match = false; + + if(preg_match_all("/\[attachment\](.*?)\[\/attachment\]/",$body,$match)) + $attaches = $match[1]; + + $attachments = ''; + + if(preg_match_all('/(\[attachment\](.*?)\[\/attachment\])/',$body,$match)) { + $attachments = array(); + foreach($match[2] as $mtch) { + $hash = substr($mtch,0,strpos($mtch,',')); + $rev = intval(substr($mtch,strpos($mtch,','))); + $r = attach_by_hash_nodata($hash,$rev); + if($r['success']) { + $attachments[] = array( + 'href' => $a->get_baseurl() . '/attach/' . $r['data']['hash'], + 'length' => $r['data']['filesize'], + 'type' => $r['data']['filetype'], + 'title' => urlencode($r['data']['filename']), + 'revision' => $r['data']['revision'] + ); + } + $body = str_replace($match[1],'',$body); + } + } + + $jattach = (($attachments) ? json_encode($attachments) : ''); + $key = get_config('system','pubkey'); if($subject) $subject = json_encode(aes_encapsulate($subject,$key)); if($body) $body = json_encode(aes_encapsulate($body,$key)); - $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, mid, parent_mid, created ) - VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", + + + $r = q("INSERT INTO mail ( account_id, mail_flags, channel_id, from_xchan, to_xchan, title, body, attach, mid, parent_mid, created ) + VALUES ( %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )", intval($channel['channel_account_id']), intval(MAIL_OBSCURED), intval($channel['channel_id']), @@ -89,6 +120,7 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' dbesc($recipient), dbesc($subject), dbesc($body), + dbesc($jattach), dbesc($mid), dbesc($replyto), dbesc(datetime_convert()) @@ -122,6 +154,19 @@ function send_message($uid = 0, $recipient='', $body='', $subject='', $replyto=' } } + if($attaches) { + foreach($attaches as $attach) { + $hash = substr($attach,0,strpos($attach,',')); + $rev = intval(substr($attach,strpos($attach,','))); + attach_store($channel,$observer_hash,$options = 'update', array( + 'hash' => $hash, + 'revision' => $rev, + 'allow_cid' => '<' . $recipient . '>', + + )); + } + } + proc_run('php','include/notifier.php','mail',$post_id); $ret['success'] = true; -- cgit v1.2.3 From 02a36948685737afdbbb9a292a338b304bb5cc04 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 20 Aug 2013 19:51:58 -0700 Subject: fix superblock for comments --- include/ItemObject.php | 4 ++-- include/conversation.php | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index 8c8c0ee2a..22b191e79 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -39,10 +39,10 @@ class Item extends BaseObject { foreach($data['children'] as $item) { /* - * Only add thos that will be displayed + * Only add those that will be displayed */ - if(! visible_activity($item)) { + if((! visible_activity($item)) || array_key_exists('author_blocked',$item)) { continue; } diff --git a/include/conversation.php b/include/conversation.php index aade06b8a..9dab5931b 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -712,6 +712,8 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { $threads = array(); foreach($items as $item) { + // Check for any blocked authors + if($arr_blocked) { $blocked = false; foreach($arr_blocked as $b) { @@ -724,6 +726,18 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional') { continue; } + // Check all the kids too + + if($arr_blocked && $item['children']) { + for($d = 0; $d < count($item['children']); $d ++) { + foreach($arr_blocked as $b) { + if(($b) && ($item['children'][$d]['author_xchan'] == $b)) + $item['children'][$d]['author_blocked'] = true; + } + } + } + + // Can we put this after the visibility check? like_puller($a,$item,$alike,'like'); -- cgit v1.2.3 From 5083aa3cbd9434b7ec63cf5bbbc2122e3da49696 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 21 Aug 2013 17:34:04 -0700 Subject: implement premium channel discovery --- include/zot.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index bddbc9bee..ff69a119e 100644 --- a/include/zot.php +++ b/include/zot.php @@ -441,6 +441,9 @@ function import_xchan($arr) { dbesc($xchan_hash) ); + if(! array_key_exists('connect_url', $arr)) + $arr['connect_url'] = ''; + if($r) { if($r[0]['xchan_photo_date'] != $arr['photo_updated']) @@ -462,18 +465,22 @@ function import_xchan($arr) { $new_flags = $r[0]['xchan_flags'] ^ XCHAN_FLAGS_HIDDEN; else $new_flags = $r[0]['xchan_flags']; - - + if(($r[0]['xchan_name_date'] != $arr['name_updated']) || ($r[0]['xchan_connurl'] != $arr['connections_url']) || ($r[0]['xchan_flags'] != $new_flags) || ($r[0]['xchan_addr'] != $arr['address']) + || ($r[0]['xchan_follow'] != $arr['follow_url']) + || ($r[0]['xchan_connpage'] != $arr['connect_url']) || ($r[0]['xchan_url'] != $arr['url'])) { - $r = q("update xchan set xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_flags = %d, + $r = q("update xchan set xchan_name = '%s', xchan_name_date = '%s', xchan_connurl = '%s', xchan_follow = '%s', + xchan_connpage = '%s', xchan_flags = %d, xchan_addr = '%s', xchan_url = '%s' where xchan_hash = '%s' limit 1", dbesc($arr['name']), dbesc($arr['name_updated']), dbesc($arr['connections_url']), + dbesc($arr['follow_url']), + dbesc($arr['connect_url']), intval($new_flags), dbesc($arr['address']), dbesc($arr['url']), @@ -503,8 +510,8 @@ function import_xchan($arr) { $new_flags = 0; $x = q("insert into xchan ( xchan_hash, xchan_guid, xchan_guid_sig, xchan_pubkey, xchan_photo_mimetype, - xchan_photo_l, xchan_addr, xchan_url, 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', %d) ", + xchan_photo_l, xchan_addr, xchan_url, xchan_connurl, xchan_follow, xchan_connpage, 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($xchan_hash), dbesc($arr['guid']), dbesc($arr['guid_sig']), @@ -514,6 +521,8 @@ function import_xchan($arr) { dbesc($arr['address']), dbesc($arr['url']), dbesc($arr['connections_url']), + dbesc($arr['follow_url']), + dbesc($arr['connect_url']), dbesc($arr['name']), dbesc('zot'), dbesc($arr['photo_updated']), -- cgit v1.2.3 From 6cea04eb440c2bb08bcb81ae13749c08d09b755c Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 21 Aug 2013 20:05:55 -0700 Subject: progress on generic sellpage - is not yet linked from existing connect buttons and editing has not been completed --- include/identity.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/identity.php b/include/identity.php index 5f210c456..1658669d6 100644 --- a/include/identity.php +++ b/include/identity.php @@ -182,7 +182,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_name, xchan_network, xchan_photo_date, xchan_name_date ) values ('%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_name, xchan_network, xchan_photo_date, xchan_name_date ) values ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')", dbesc($hash), dbesc($guid), dbesc($sig), @@ -192,6 +192,7 @@ function create_identity($arr) { dbesc($a->get_baseurl() . "/photo/profile/s/{$newuid}"), dbesc($ret['channel']['channel_address'] . '@' . get_app()->get_hostname()), dbesc(z_root() . '/channel/' . $ret['channel']['channel_address']), + dbesc(z_root() . '/follow?f=&url=%s'), dbesc($ret['channel']['channel_name']), dbesc('zot'), dbesc(datetime_convert()), -- cgit v1.2.3 From 925b046794b77345c1321a3c74e4561d5c10ec95 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 21 Aug 2013 22:10:08 -0700 Subject: premium/restricted channel connections implemented, configure at yoursite/channel/nickname - this basically redirects "follow" requests to a premium channel's sell page if it has one configured. You can still click through and create a connection request (introduction), but this provides a means for the channel owner to state their terms. If you don't abide by the terms, you will likely be blocked or the channel deleted. This facility is extensible in a number of ways. --- include/Contact.php | 9 ++++++++- include/follow.php | 7 ++++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/Contact.php b/include/Contact.php index bf536ccd5..46d356f3f 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -15,13 +15,20 @@ function rconnect_url($channel_id,$xchan) { if($r) return ''; + $r = q("select * from xchan where xchan_hash = '%s' limit 1", + dbesc($xchan) + ); + + if(($r) && ($r[0]['xchan_follow'])) + return $r[0]['xchan_follow']; + $r = q("select hubloc_url from hubloc where hubloc_hash = '%s' and ( hubloc_flags & %d ) limit 1", dbesc($xchan), intval(HUBLOC_FLAGS_PRIMARY) ); if($r) - return $r[0]['hubloc_url']; + return $r[0]['hubloc_url'] . '/follow?f=&url=%s'; return ''; } diff --git a/include/follow.php b/include/follow.php index ce550b07f..510c6cd7e 100644 --- a/include/follow.php +++ b/include/follow.php @@ -11,7 +11,7 @@ require_once('include/zot.php'); -function new_contact($uid,$url,$channel,$interactive = false) { +function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) { $result = array('success' => false,'message' => ''); @@ -60,6 +60,11 @@ function new_contact($uid,$url,$channel,$interactive = false) { return $result; } + // Premium channel, set confirm before callback to avoid recursion + + if(array_key_exists('connect_url',$j) && (! $confirm)) + goaway($j['connect_url']); + // check service class limits -- cgit v1.2.3 From 22b6ddef9457e5ed3d38cf03be4b4451ec9d150c Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Aug 2013 00:44:24 -0700 Subject: add zid to connect_url --- include/follow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/follow.php b/include/follow.php index 510c6cd7e..10bcddf2b 100644 --- a/include/follow.php +++ b/include/follow.php @@ -63,7 +63,7 @@ function new_contact($uid,$url,$channel,$interactive = false, $confirm = false) // Premium channel, set confirm before callback to avoid recursion if(array_key_exists('connect_url',$j) && (! $confirm)) - goaway($j['connect_url']); + goaway(zid($j['connect_url'])); // check service class limits -- cgit v1.2.3 From af72f40759418275abae575176f43d27388bfcd6 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Aug 2013 01:00:54 -0700 Subject: make premium channels a feature --- include/features.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include') diff --git a/include/features.php b/include/features.php index 757f719df..6272b33ea 100644 --- a/include/features.php +++ b/include/features.php @@ -27,8 +27,7 @@ function get_features() { //FIXME - needs a description, but how the hell do we explain this to normals? array('sendzid', t('Extended Identity Sharing'), t(' ')), array('expert', t('Expert Mode'), t('Enable Expert Mode to provide advanced configuration options')), - - + array('premium_channel', t('Premium Channel'), t('Allows you to set restrictions and terms on those that connect with your channel')), ), // Post composition -- cgit v1.2.3 From 32ff0932bf3b596e68ae7f4100bebbccdc1eae00 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Aug 2013 03:24:50 -0700 Subject: add detailed logging to public recips - find out why some public recipients are getting bypassed (David Benfells' problem with tagging groups, etc.) --- include/zot.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index ff69a119e..37d2a03bd 100644 --- a/include/zot.php +++ b/include/zot.php @@ -928,6 +928,8 @@ function public_recips($msg) { if(! $col) return NULL; + logger('__public_recips'); +dbg(1); if($msg['notify']['sender']['url'] === z_root()) $sql = " where (( " . $col . " & " . PERMS_NETWORK . " ) or ( " . $col . " & " . PERMS_SITE . " )) "; else @@ -945,6 +947,7 @@ function public_recips($msg) { if(! $x) $x = array(); +dbg(0); $r = array_merge($r,$x); logger('public_recips: ' . print_r($r,true), LOGGER_DATA); -- cgit v1.2.3 From 141c8ccb1f94b9ce80466aa6be178d97e3f290bf Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Aug 2013 05:50:15 -0700 Subject: possible fix for mention tags not posting to mentioned forum (when send stream permission is blocked) --- include/zot.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/zot.php b/include/zot.php index 37d2a03bd..c7049dee6 100644 --- a/include/zot.php +++ b/include/zot.php @@ -838,6 +838,7 @@ function zot_import($arr) { // and who are allowed to see them based on the sender's permissions $deliveries = allowed_public_recips($i); + } if(! $deliveries) { logger('zot_import: no deliveries on this site'); @@ -910,10 +911,12 @@ function zot_import($arr) { function public_recips($msg) { + $check_mentions = false; if($msg['message']['type'] === 'activity') { if(array_key_exists('flags',$msg['message']) && in_array('thread_parent', $msg['message']['flags'])) { $col = 'channel_w_stream'; $field = PERMS_W_STREAM; + $check_mentions = true; } else { $col = 'channel_w_comment'; @@ -928,8 +931,7 @@ function public_recips($msg) { if(! $col) return NULL; - logger('__public_recips'); -dbg(1); + if($msg['notify']['sender']['url'] === z_root()) $sql = " where (( " . $col . " & " . PERMS_NETWORK . " ) or ( " . $col . " & " . PERMS_SITE . " )) "; else @@ -947,9 +949,29 @@ dbg(1); if(! $x) $x = array(); -dbg(0); $r = array_merge($r,$x); + + // look for any public mentions on this site + // They will get filtered by tgroup_check() so we don't need to check permissions now + + if($check_mentions && $msg['message']['tags']) { + if(is_array($msg['message']['tags']) && $msg['message']['tags']) { + foreach($msg['message']['tags'] as $tag) { + if(($tag['type'] === 'mention') && (strpos($tag['url'],z_root()) !== false)) { + $address = basename($tag['url']); + if($address) { + $z = q("select channel_hash as hash from channel where channel_address = '%s' limit 1", + dbesc($address) + ); + if($z) + $r = array_merge($r,$z); + } + } + } + } + } + logger('public_recips: ' . print_r($r,true), LOGGER_DATA); return $r; } -- cgit v1.2.3 From 99a9aee03e55af84f6963bbdbe3e365a7721e93d Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 22 Aug 2013 06:15:00 -0700 Subject: extra logging for translating likes in notification emails - which is still failing on occasion. --- include/conversation.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 9dab5931b..6e6ffef94 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -162,6 +162,9 @@ function localize_item(&$item){ $item['body'] .= "\n\n\n" . '[zrl=' . chanlink_url($author_link) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]'; } + else { + logger('localize_item like failed: link ' . $author_link . ' name ' . $author_name . ' url ' . $item_url); + } } -- cgit v1.2.3