From 764ee785f5505c2be804a850b8e4029598d81739 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 19:14:01 -0700 Subject: We will need a per item comment policy to be able to determine in advance if we have permission to comment on something , and we'll need to send it out with all communications. The current check is not only flawed but also a huge performance hit. Also provide the ability for an item to disable commenting completely - such as for a webpage or wherever you want to prevent comments on one item, without requiring a change to your entire permission scheme. All of this is only partially implemented at the moment but we need the structures in place on several sites in order to finish it without breaking everything. --- include/items.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 64eeae4b4..9d93accfe 100755 --- a/include/items.php +++ b/include/items.php @@ -549,13 +549,17 @@ function encode_item($item) { intval($item['uid']) ); - if($r) + if($r) { $public_scope = $r[0]['channel_r_stream']; - else + $comment_scope = $r[0]['channel_w_comment']; + } + else { $public_scope = 0; + $comment_scope = 0; + } $scope = map_scope($public_scope); - + $c_scope = map_scope($comment_scope); if($item['item_restrict'] & ITEM_DELETED) { $x['message_id'] = $item['mid']; @@ -597,6 +601,11 @@ function encode_item($item) { if(! in_array('private',$y)) $x['public_scope'] = $scope; + if($item['item_flags'] & ITEM_NOCOMMENT) + $x['comment_scope'] = 'none'; + else + $x['comment_scope'] = $c_scope; + if($item['term']) $x['tags'] = encode_item_terms($item['term']); -- cgit v1.2.3 From 28cd8594a7dcaf7d21b8b92c44ace34dc8aa6dd4 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 20:44:29 -0700 Subject: implement 'can_comment_on_post()' which doesn't require a separate DB lookup per item. --- include/ItemObject.php | 2 +- include/items.php | 42 +++++++++++++++++++++++++++++++++++++++++- include/text.php | 2 +- 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index ccd192ff5..351f446d4 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -44,7 +44,7 @@ class Item extends BaseObject { $this->commentable = $this->writable; if(($this->observer) && (! $this->writable)) { - $this->commentable = perm_is_allowed($this->data['uid'],$this->observer['xchan_hash'],'post_comments'); + $this->commentable = can_comment_on_post($this->observer['xchan_hash'],$data); } // logger('writable: ' . $this->writable); diff --git a/include/items.php b/include/items.php index 9d93accfe..93fc09ae9 100755 --- a/include/items.php +++ b/include/items.php @@ -53,6 +53,37 @@ function collect_recipients($item,&$private) { } + +function can_comment_on_post($observer_xchan,$item) { + if(! $observer_xchan) + return false; + if($item['comment_policy'] === 'none') + return false; + switch($item['comment_policy']) { + case 'self': + if($observer_xchan === $item['author_xchan'] || $observer_xchan === $item['owner_xchan']) + return true; + break; + case 'public': + return false; + break; + case 'contacts': + case '': + if(($item['owner']['abook_xchan']) && ($item['owner']['abook_their_perms'] & PERMS_W_COMMENT)) + return true; + break; + default: + break; + } + if(strstr('network:',$item['comment_policy']) && strstr('red',$item['comment_policy'])) + return true; + if(strstr('site:', $item['comment_policy']) && strstr(get_app()->get_hostname(),$item['comment_policy'])) + return true; + + return false; +} + + /** * @function red_zrl_callback * preg_match function when fixing 'naked' links in mod item.php @@ -142,6 +173,7 @@ function post_activity_item($arr) { $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); + $arr['comment_policy'] = map_policy($channel['channel_w_comment']); // for the benefit of plugins, we will behave as if this is an API call rather than a normal online post @@ -481,7 +513,8 @@ function get_item_elements($x) { $arr['mimetype'] = (($x['mimetype']) ? htmlentities($x['mimetype'], ENT_COMPAT,'UTF-8',false) : ''); $arr['obj_type'] = (($x['object_type']) ? htmlentities($x['object_type'], ENT_COMPAT,'UTF-8',false) : ''); $arr['tgt_type'] = (($x['target_type']) ? htmlentities($x['target_type'], ENT_COMPAT,'UTF-8',false) : ''); - + $arr['comment_policy'] = (($x['comment_scope']) ? htmlentities($x['comment_scope'], ENT_COMPAT,'UTF-8',false) : 'contacts'); + $arr['object'] = activity_sanitise($x['object']); $arr['target'] = activity_sanitise($x['target']); @@ -1332,10 +1365,17 @@ function item_store($arr,$force_parent = false) { $arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : ''); $arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : ''); $arr['item_restrict'] = ((x($arr,'item_restrict')) ? intval($arr['item_restrict']) : 0 ); + + $arr['comment_policy'] = ((x($arr,'comment_policy')) ? notags(trim($arr['comment_policy'])) : 'contacts' ); + $arr['item_flags'] = ((x($arr,'item_flags')) ? intval($arr['item_flags']) : 0 ); $arr['item_flags'] = $arr['item_flags'] | ITEM_UNSEEN; + if($arr['comment_policy'] == 'none') + $arr['item_flags'] = $arr['item_flags'] | ITEM_NOCOMMENT; + + // handle time travelers // Allow a bit of fudge in case somebody just has a slightly slow/fast clock diff --git a/include/text.php b/include/text.php index 71f2257ac..c51ee0bd2 100755 --- a/include/text.php +++ b/include/text.php @@ -1794,7 +1794,7 @@ function ids_to_querystr($arr,$idx = 'id') { // author_xchan and owner_xchan. If $abook is true also include the abook info. // This is needed in the API to save extra per item lookups there. -function xchan_query(&$items,$abook = false) { +function xchan_query(&$items,$abook = true) { $arr = array(); if($items && count($items)) { foreach($items as $item) { -- cgit v1.2.3 From 82539ba2bc93a6a84ce01492d37a725291ba32d9 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 22:56:56 -0700 Subject: override comment policy until it's working --- include/ItemObject.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index 351f446d4..e5185bef6 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -45,6 +45,10 @@ class Item extends BaseObject { if(($this->observer) && (! $this->writable)) { $this->commentable = can_comment_on_post($this->observer['xchan_hash'],$data); + if(! $this->commentable) { + logger('commentable: ' . $data['comment_policy']); + $this->commentable = true; + } } // logger('writable: ' . $this->writable); -- cgit v1.2.3 From 7ae340dd4031c69cd84b30e68c71c80cebdd7ef0 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 23:07:04 -0700 Subject: typos --- include/items.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 93fc09ae9..c3c594d59 100755 --- a/include/items.php +++ b/include/items.php @@ -75,9 +75,9 @@ function can_comment_on_post($observer_xchan,$item) { default: break; } - if(strstr('network:',$item['comment_policy']) && strstr('red',$item['comment_policy'])) + if(strstr($item['comment_policy'],'network:') && strstr($item['comment_policy'],'red')) return true; - if(strstr('site:', $item['comment_policy']) && strstr(get_app()->get_hostname(),$item['comment_policy'])) + if(strstr($item['comment_policy'],'site:') && strstr($item['comment_policy'],get_app()->get_hostname())) return true; return false; -- cgit v1.2.3 From 322c9d76fc099ac6a2b7efb7f0b3b7a25c83f87e Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 23:08:52 -0700 Subject: undefined function --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index c3c594d59..1490d66ce 100755 --- a/include/items.php +++ b/include/items.php @@ -173,7 +173,7 @@ function post_activity_item($arr) { $arr['deny_cid'] = ((x($arr,'deny_cid')) ? $arr['deny_cid'] : $channel['channel_deny_cid']); $arr['deny_gid'] = ((x($arr,'deny_gid')) ? $arr['deny_gid'] : $channel['channel_deny_gid']); - $arr['comment_policy'] = map_policy($channel['channel_w_comment']); + $arr['comment_policy'] = map_scope($channel['channel_w_comment']); // for the benefit of plugins, we will behave as if this is an API call rather than a normal online post -- cgit v1.2.3 From f4e8198335960465b4ac6106f59e0346d08ece1f Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 16 Jun 2013 23:20:36 -0700 Subject: found it - but I'll do some more testing before undoing the bypass --- include/items.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/items.php b/include/items.php index 1490d66ce..09e0f94fa 100755 --- a/include/items.php +++ b/include/items.php @@ -578,7 +578,7 @@ function encode_item($item) { logger('encode_item: ' . print_r($item,true)); - $r = q("select channel_r_stream from channel where channel_id = %d limit 1", + $r = q("select channel_r_stream, channel_w_comment from channel where channel_id = %d limit 1", intval($item['uid']) ); -- cgit v1.2.3 From 94c758080ff0b957d7d728428de5821c39a583e9 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 17 Jun 2013 16:21:03 -0700 Subject: zidify bodies of notification emails --- include/enotify.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/enotify.php b/include/enotify.php index 5728d054c..0a6befba1 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -354,8 +354,22 @@ function notification($params) { $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n", $body))),ENT_QUOTES,'UTF-8')); + $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), - "
\n",$body)))); + "
\n",$body))), ENT_QOUTES,'UTF-8'); + + + // use $_SESSION['zid_override'] to force zid() to use + // the recipient address instead of the current observer + + $_SESSION['zid_override'] = $recip['channel_address'] . '@' . $get_app()->get_hostname(); + + $textversion = zidify_links($textversion); + $htmlversion = zidify_links($htmlversion); + + // unset when done to revert to normal behaviour + + unset($_SESSION['zid_override']); $datarray = array(); -- cgit v1.2.3 From 49802d9a47d1f492715193092f61c60f43dd7723 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 17 Jun 2013 17:19:05 -0700 Subject: one of those days... --- include/enotify.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/enotify.php b/include/enotify.php index 0a6befba1..11f594d6c 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -356,13 +356,13 @@ function notification($params) { $body))),ENT_QUOTES,'UTF-8')); $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"), - "
\n",$body))), ENT_QOUTES,'UTF-8'); + "
\n",$body))), ENT_QUOTES,'UTF-8'); // use $_SESSION['zid_override'] to force zid() to use // the recipient address instead of the current observer - $_SESSION['zid_override'] = $recip['channel_address'] . '@' . $get_app()->get_hostname(); + $_SESSION['zid_override'] = $recip['channel_address'] . '@' . get_app()->get_hostname(); $textversion = zidify_links($textversion); $htmlversion = zidify_links($htmlversion); -- cgit v1.2.3 From c5e38598280209903fc60c9ce996e7f3c34a4533 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 17 Jun 2013 19:25:46 -0700 Subject: another try on zidified notifications - this time it actually seems to work --- include/enotify.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/enotify.php b/include/enotify.php index 11f594d6c..71629b9d9 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -363,13 +363,15 @@ function notification($params) { // the recipient address instead of the current observer $_SESSION['zid_override'] = $recip['channel_address'] . '@' . get_app()->get_hostname(); - + $_SESSION['zrl_override'] = z_root() . '/channel/' . $recip['channel_address']; + $textversion = zidify_links($textversion); $htmlversion = zidify_links($htmlversion); // unset when done to revert to normal behaviour unset($_SESSION['zid_override']); + unset($_SESSION['zrl_override']); $datarray = array(); -- cgit v1.2.3 From 5f84e3940d6a6ba8732104bf376921c061808f18 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 17 Jun 2013 20:16:50 -0700 Subject: much more efficient config functions. This will save potentially hundreds of DB lookups - still need to update the xconfig but want to give the others a good workout as it has been one of those days. --- include/config.php | 157 ++++++++++++++++++++--------------------------------- 1 file changed, 60 insertions(+), 97 deletions(-) (limited to 'include') diff --git a/include/config.php b/include/config.php index dc4470823..5b74f6292 100644 --- a/include/config.php +++ b/include/config.php @@ -17,20 +17,22 @@ function load_config($family) { global $a; - $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family)); - if($r) { - foreach($r as $rr) { - $k = $rr['k']; - if ($family === 'config') { - $a->config[$k] = $rr['v']; - } else { - $a->config[$family][$k] = $rr['v']; + + if(! array_key_exists($family,$a->config)) + $a->config[$family] = array(); + + if(! array_key_exists('config_loaded',$a->config[$family])) { + $r = q("SELECT * FROM config WHERE cat = '%s'", dbesc($family)); + if($r !== false) { + if($r) { + foreach($r as $rr) { + $k = $rr['k']; + $a->config[$family][$k] = $rr['v']; + } } + $a->config[$family]['config_loaded'] = true; } - } else if ($family != 'config') { - // Negative caching - $a->config[$family] = "!!"; - } + } } // get a particular config variable given the family name @@ -42,37 +44,21 @@ function load_config($family) { // to hit the DB again for this item. -function get_config($family, $key, $instore = false) { +function get_config($family, $key) { global $a; - if(! $instore) { - // Looking if the whole family isn't set - if(isset($a->config[$family])) { - if($a->config[$family] === '!!') { - return false; - } - } + if(! array_key_exists($family,$a->config)) + load_config($family); - if(isset($a->config[$family][$key])) { - if($a->config[$family][$key] === '!!') { - return false; - } - return $a->config[$family][$key]; + if(array_key_exists('config_loaded',$a->config[$family])) { + if(! array_key_exists($key,$a->config[$family])) { + return false; } - } - $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", - dbesc($family), - dbesc($key) - ); - if(count($ret)) { - // manage array value - $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); - $a->config[$family][$key] = $val; - return $val; - } - else { - $a->config[$family][$key] = '!!'; + return ((preg_match('|^a:[0-9]+:{.*}$|s', $a->config[$family][$key])) + ? unserialize($a->config[$family][$key]) + : $a->config[$family][$key] + ); } return false; } @@ -85,11 +71,12 @@ function get_config($family, $key, $instore = false) { function set_config($family,$key,$value) { global $a; // manage array value - $dbvalue = (is_array($value)?serialize($value):$value); - $dbvalue = (is_bool($dbvalue) ? intval($dbvalue) : $dbvalue); - if(get_config($family,$key,true) === false) { + $dbvalue = ((is_array($value)) ? serialize($value) : $value); + $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); + + if(get_config($family,$key) === false) { $a->config[$family][$key] = $value; - $ret = q("INSERT INTO `config` ( `cat`, `k`, `v` ) VALUES ( '%s', '%s', '%s' ) ", + $ret = q("INSERT INTO config ( cat, k, v ) VALUES ( '%s', '%s', '%s' ) ", dbesc($family), dbesc($key), dbesc($dbvalue) @@ -99,7 +86,7 @@ function set_config($family,$key,$value) { return $ret; } - $ret = q("UPDATE `config` SET `v` = '%s' WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("UPDATE config SET v = '%s' WHERE cat = '%s' AND k = '%s' LIMIT 1", dbesc($dbvalue), dbesc($family), dbesc($key) @@ -112,14 +99,11 @@ function set_config($family,$key,$value) { return $ret; } - - function del_config($family,$key) { - global $a; - if(x($a->config[$family],$key)) + if(array_key_exists($family,$a->config) && array_key_exists($key,$a->config[$family])) unset($a->config[$family][$key]); - $ret = q("DELETE FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("DELETE FROM config WHERE cat = '%s' AND k = '%s' LIMIT 1", dbesc($family), dbesc($key) ); @@ -127,11 +111,13 @@ function del_config($family,$key) { } -function load_pconfig($uid,$family) { +function load_pconfig($uid,$family = '') { global $a; - if(($uid) && (! array_key_exists($uid,$a->config))) + if(! array_key_exists($uid,$a->config)) $a->config[$uid] = array(); + if(($family) && (! array_key_exists($family,$a->config[$uid]))) + $a->config[$uid][$family] = array(); if($family) { $r = q("SELECT * FROM `pconfig` WHERE `cat` = '%s' AND `uid` = %d", @@ -149,15 +135,13 @@ function load_pconfig($uid,$family) { foreach($r as $rr) { $k = $rr['k']; $c = $rr['cat']; - if(! array_key_exists($c,$a->config[$uid])) + if(! array_key_exists($c,$a->config[$uid])) { $a->config[$uid][$c] = array(); + $a->config[$uid][$c]['config_loaded'] = true; + } $a->config[$uid][$c][$k] = $rr['v']; } } -// else if ($family != 'config') { - // Negative caching -// $a->config[$uid][$family] = "!!"; -// } } @@ -167,67 +151,46 @@ function get_pconfig($uid,$family, $key, $instore = false) { global $a; - if(! $instore) { - // Looking if the whole family isn't set - if(isset($a->config[$uid][$family])) { - if($a->config[$uid][$family] === '!!') { - return false; - } - } + if(! array_key_exists($uid,$a->config)) + load_pconfig($uid); - if(isset($a->config[$uid][$family][$key])) { - if($a->config[$uid][$family][$key] === '!!') { - return false; - } - return $a->config[$uid][$family][$key]; - } - } + if((! array_key_exists($family,$a->config[$uid])) || (! array_key_exists($key,$a->config[$uid][$family]))) + return false; - $ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", - intval($uid), - dbesc($family), - dbesc($key) + return ((preg_match('|^a:[0-9]+:{.*}$|s', $a->config[$uid][$family][$key])) + ? unserialize($a->config[$uid][$family][$key]) + : $a->config[$uid][$family][$key] ); - - if(count($ret)) { - $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']); - $a->config[$uid][$family][$key] = $val; - return $val; - } - else { - $a->config[$uid][$family][$key] = '!!'; - } - return false; } - - - - -// Same as above functions except these are for personal config storage and take an -// additional $uid argument. - - function set_pconfig($uid,$family,$key,$value) { global $a; + // manage array value - $dbvalue = (is_array($value)?serialize($value):$value); + $dbvalue = ((is_array($value)) ? serialize($value) : $value); + $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); + + if(get_pconfig($uid,$family,$key) === false) { + if(! array_key_exists($uid,$a->config)) + $a->config[$uid] = array(); + if(! array_key_exists($family,$a->config[$uid])) + $a->config[$uid][$family] = array(); - if(get_pconfig($uid,$family,$key,true) === false) { $a->config[$uid][$family][$key] = $value; - $ret = q("INSERT INTO `pconfig` ( `uid`, `cat`, `k`, `v` ) VALUES ( %d, '%s', '%s', '%s' ) ", + $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ", intval($uid), dbesc($family), dbesc($key), dbesc($dbvalue) ); - if($ret) + if($ret) return $value; return $ret; } - $ret = q("UPDATE `pconfig` SET `v` = '%s' WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", + + $ret = q("UPDATE pconfig SET v = '%s' WHERE uid = %d and cat = '%s' AND k = '%s' LIMIT 1", dbesc($dbvalue), intval($uid), dbesc($family), @@ -247,7 +210,7 @@ function del_pconfig($uid,$family,$key) { global $a; if(x($a->config[$uid][$family],$key)) unset($a->config[$uid][$family][$key]); - $ret = q("DELETE FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1", + $ret = q("DELETE FROM pconfig WHERE uid = %d AND cat = '%s' AND k = '%s' LIMIT 1", intval($uid), dbesc($family), dbesc($key) -- cgit v1.2.3 From c0cc494bf36a61885bc3391e6f05b48baafb312a Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 02:06:16 -0700 Subject: fix mod-display when not logged in. --- include/config.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/config.php b/include/config.php index 5b74f6292..7d2dbdcc7 100644 --- a/include/config.php +++ b/include/config.php @@ -114,6 +114,9 @@ function del_config($family,$key) { function load_pconfig($uid,$family = '') { global $a; + if($uid === false) + return false; + if(! array_key_exists($uid,$a->config)) $a->config[$uid] = array(); if(($family) && (! array_key_exists($family,$a->config[$uid]))) @@ -151,6 +154,9 @@ function get_pconfig($uid,$family, $key, $instore = false) { global $a; + if($uid === false) + return false; + if(! array_key_exists($uid,$a->config)) load_pconfig($uid); -- cgit v1.2.3 From 6220ab4b549e8a754b2d331d4e8b4fae36e8f98f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 02:51:43 -0700 Subject: fix profile update propagation --- include/directory.php | 16 ++++++++++------ include/notifier.php | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/include/directory.php b/include/directory.php index 5f3696a58..c286f5683 100644 --- a/include/directory.php +++ b/include/directory.php @@ -19,11 +19,6 @@ function directory_run($argv, $argc){ if($dirmode === false) $dirmode = DIRECTORY_MODE_NORMAL; - if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { - syncdirs($argv[1]); - return; - } - $x = q("select * from channel where channel_id = %d limit 1", intval($argv[1]) ); @@ -32,6 +27,15 @@ function directory_run($argv, $argc){ $channel = $x[0]; + + if(($dirmode == DIRECTORY_MODE_PRIMARY) || ($dirmode == DIRECTORY_MODE_STANDALONE)) { + syncdirs($argv[1]); + + // Now update all the connections + proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']); + return; + } + $directory = find_upstream_directory($dirmode); if($directory) { @@ -49,7 +53,7 @@ function directory_run($argv, $argc){ // Now update all the connections - proc_run('php','notifier','refresh_all',$channel['channel_id']); + proc_run('php','include/notifier.php','refresh_all',$channel['channel_id']); } diff --git a/include/notifier.php b/include/notifier.php index 7d107e4d4..96c0bf31f 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -189,6 +189,7 @@ function notifier_run($argv, $argc){ $item = $suggest[0]; } elseif($cmd === 'refresh_all') { + logger('notifier: refresh_all: ' . $item_id); $s = q("select * from channel where channel_id = %d limit 1", intval($item_id) ); @@ -196,10 +197,9 @@ function notifier_run($argv, $argc){ $channel = $s[0]; $uid = $item_id; $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)", intval($item_id), - intval(ABOOK_FLAG_SELF), - intval(ABOOK_FLAG_PENDING) + intval(ABOOK_FLAG_SELF) ); if($r) { foreach($r as $rr) { -- cgit v1.2.3 From 40c8e89d8476696a2e4a57a27970f6067b803e22 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 18:48:41 -0700 Subject: undo comment policy override - there are a handful of stored posts from the 17th-June with a broken policy (which won't have a comment box) but it seems to be working for both recent and older posts. --- include/ItemObject.php | 8 ++++---- include/conversation.php | 20 ++++++++++---------- include/enotify.php | 3 +++ 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/ItemObject.php b/include/ItemObject.php index e5185bef6..1205ae13e 100644 --- a/include/ItemObject.php +++ b/include/ItemObject.php @@ -45,10 +45,10 @@ class Item extends BaseObject { if(($this->observer) && (! $this->writable)) { $this->commentable = can_comment_on_post($this->observer['xchan_hash'],$data); - if(! $this->commentable) { - logger('commentable: ' . $data['comment_policy']); - $this->commentable = true; - } +// if(! $this->commentable) { +// logger('commentable: ' . $data['comment_policy']); +// $this->commentable = true; +// } } // logger('writable: ' . $this->writable); diff --git a/include/conversation.php b/include/conversation.php index 8e69e9ea3..b6823e3c5 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -6,7 +6,7 @@ require_once('include/items.php'); // is identical to the code in mod/message.php for 'item_extract_images' and // 'item_redir_and_replace_images' -if(! function_exists('item_extract_images')) { + function item_extract_images($body) { $saved_image = array(); @@ -46,9 +46,9 @@ function item_extract_images($body) { $new_body = $new_body . $orig_body; return array('body' => $new_body, 'images' => $saved_image); -}} +} + -if(! function_exists('item_redir_and_replace_images')) { function item_redir_and_replace_images($body, $images, $cid) { $origbody = $body; @@ -81,7 +81,7 @@ function item_redir_and_replace_images($body, $images, $cid) { } return $newbody; -}} +} @@ -826,7 +826,7 @@ function best_link_url($item) { } -if(! function_exists('item_photo_menu')){ + function item_photo_menu($item){ $a = get_app(); $contact = null; @@ -893,9 +893,9 @@ function item_photo_menu($item){ elseif ($v!="") $o .= "
  • $k
  • \n"; } return $o; -}} +} + -if(! function_exists('like_puller')) { function like_puller($a,$item,&$arr,$mode) { $url = ''; @@ -923,7 +923,7 @@ function like_puller($a,$item,&$arr,$mode) { $arr[$item['thr_parent'] . '-l'][] = '' . $item['author']['xchan_name'] . ''; } return; -}} +} // Format the like/dislike text for a profile item // $cnt = number of people who like/dislike the item @@ -932,7 +932,7 @@ function like_puller($a,$item,&$arr,$mode) { // $id = item id // returns formatted text -if(! function_exists('format_like')) { + function format_like($cnt,$arr,$type,$id) { $o = ''; if($cnt == 1) @@ -956,7 +956,7 @@ function format_like($cnt,$arr,$type,$id) { $o .= "\t" . ''; } return $o; -}} +} function status_editor($a,$x,$popup=false) { diff --git a/include/enotify.php b/include/enotify.php index 71629b9d9..3b7a643ed 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -50,6 +50,8 @@ function notification($params) { $additional_mail_header = ""; + // We really should pass this through localize_item - but only if we have a complete item. We may only have a couple of elements. + if(array_key_exists('item',$params)) { $title = $params['item']['title']; $body = $params['item']['body']; @@ -352,6 +354,7 @@ function notification($params) { logger('notification: sending notification email'); + $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n", $body))),ENT_QUOTES,'UTF-8')); -- cgit v1.2.3 From ba4f237be26608afdab9b00d6e58e38ac4238d1f Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 20:14:56 -0700 Subject: provide support for "bob likes Lisa's channel" activities --- include/conversation.php | 49 +++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index b6823e3c5..0b841aa77 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -108,6 +108,31 @@ function localize_item(&$item){ $item_url = get_rel_link($obj['link'],'alternate'); + $Bphoto = ''; + + switch($obj->type) { + case ACTIVITY_OBJ_PHOTO: + $post_type = t('photo'); + break; + case ACTIVITY_OBJ_EVENT: + $post_type = t('event'); + break; + case ACTIVITY_OBJ_PERSON: + $post_type = t('channel'); + $author_name = $obj['title']; + if($obj['link']) { + $author_link = get_rel_link($obj['link'],'alternate'); + $Bphoto = get_rel_link($obj['link'],'photo'); + } + break; + case ACTIVITY_OBJ_NOTE: + default: + $post_type = t('status'); + if($obj->id != $item['mid']) + $post_type = t('comment'); + break; + } + // If we couldn't parse something useful, don't bother translating. // We need something better than zid here, probably magic_link(), but it needs writing @@ -117,21 +142,6 @@ function localize_item(&$item){ $author = '[zrl=' . chanlink_url($item['author']['xchan_url']) . ']' . $item['author']['xchan_name'] . '[/zrl]'; $objauthor = '[zrl=' . chanlink_url($author_link) . ']' . $author_name . '[/zrl]'; - switch($obj->type) { - case ACTIVITY_OBJ_PHOTO: - $post_type = t('photo'); - break; - case ACTIVITY_OBJ_EVENT: - $post_type = t('event'); - break; - case ACTIVITY_OBJ_NOTE: - default: - $post_type = t('status'); - if($obj->id != $item['mid']) - $post_type = t('comment'); - break; - } - $plink = '[zrl=' . zid($item_url) . ']' . $post_type . '[/zrl]'; if(activity_match($item['verb'],ACTIVITY_LIKE)) { @@ -141,6 +151,8 @@ function localize_item(&$item){ $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); } $item['body'] = $item['localize'] = sprintf($bodyverb, $author, $objauthor, $plink); + if($Bphoto != "") + $item['body'] .= "\n\n\n" . '[zrl=' . chanlink_url($author_link) . '][zmg=80x80]' . $Bphoto . '[/zmg][/zrl]'; } @@ -148,7 +160,8 @@ function localize_item(&$item){ if (activity_match($item['verb'],ACTIVITY_FRIEND)) { - if ($item['obj_type']=="" || $item['obj_type']!== ACTIVITY_OBJ_PERSON) return; + +// if ($item['obj_type']=="" || $item['obj_type']!== ACTIVITY_OBJ_PERSON) return; $Aname = $item['author']['xchan_name']; $Alink = $item['author']['xchan_url']; @@ -349,7 +362,9 @@ function count_descendants($item) { function visible_activity($item) { - if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)) + // likes can apply to other things besides posts. Check if they are post children, in which case we handle them specially + + if((activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)) && ($item['mid'] != $item['parent_mid'])) return false; return true; } -- cgit v1.2.3 From 0b935b79dcb82bccd45bf8f68409b6cdf0fceb40 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 20:30:20 -0700 Subject: Support arbitrary likes - "David likes Bob's bicycle" or "Nancy likes Margaret's breasts" or whatever... This is a tricky activity to construct. You will need to set the object owner to the owner of the "thing" and the object title to the name of the "thing". The thing liked can include a photo if desired. This will probably have issues working correctly in other activitystreams environments. --- include/conversation.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 0b841aa77..e12aa1fbc 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -125,6 +125,19 @@ function localize_item(&$item){ $Bphoto = get_rel_link($obj['link'],'photo'); } break; + case ACTIVITY_OBJ_THING: + $post_type = $obj['title']; + $author_name = (($obj['owner'] && $obj['owner']['name']) ? $obj['owner']['name'] : ''); + if($obj['owner'] && $obj['owner']['link']) + $author_link = get_rel_link($obj['owner']['link'],'alternate'); + else + $author_link = ''; + + if($obj['link']) { + $Bphoto = get_rel_link($obj['link'],'photo'); + } + break; + case ACTIVITY_OBJ_NOTE: default: $post_type = t('status'); -- cgit v1.2.3 From 9d03da134807a55c74a5b15895356dc8990f01db Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 18 Jun 2013 21:52:54 -0700 Subject: fall back on object author/actor if no owner --- include/conversation.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index e12aa1fbc..410143a7a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -127,12 +127,12 @@ function localize_item(&$item){ break; case ACTIVITY_OBJ_THING: $post_type = $obj['title']; - $author_name = (($obj['owner'] && $obj['owner']['name']) ? $obj['owner']['name'] : ''); - if($obj['owner'] && $obj['owner']['link']) - $author_link = get_rel_link($obj['owner']['link'],'alternate'); - else - $author_link = ''; - + if($obj['owner']) { + if(array_key_exists('name',$obj['owner'])) + $obj['owner']['name']; + if(array_key_exists('link',$obj['owner'])) + $author_link = get_rel_link($obj['owner']['link'],'alternate'); + } if($obj['link']) { $Bphoto = get_rel_link($obj['link'],'photo'); } -- cgit v1.2.3 From 3b1e5e5204d7cade3afc320cc45b1eb4efa6743c Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 19 Jun 2013 21:50:14 -0700 Subject: source code re-org, move taxonomy to separate include --- include/taxonomy.php | 91 +++++++++++++++++ include/text.php | 282 +++------------------------------------------------ 2 files changed, 107 insertions(+), 266 deletions(-) create mode 100644 include/taxonomy.php (limited to 'include') diff --git a/include/taxonomy.php b/include/taxonomy.php new file mode 100644 index 000000000..5130ff9b7 --- /dev/null +++ b/include/taxonomy.php @@ -0,0 +1,91 @@ +','[',']'),array('%3c','%3e','%5b','%5d'),$s); +} + +function file_tag_decode($s) { + return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s); +} + +function file_tag_file_query($table,$s,$type = 'file') { + + if($type == 'file') + $termtype = TERM_FILE; + else + $termtype = TERM_CATEGORY; + + return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", + intval($termtype), + protect_sprintf(dbesc($s)) + ); +} + +function term_query($table,$s,$type = TERM_UNKNOWN) { + + return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", + intval($type), + protect_sprintf(dbesc($s)) + ); +} + + +function store_item_tag($uid,$iid,$otype,$type,$term,$url = '') { + if(! $term) + return false; + $r = q("select * from term + where uid = %d and oid = %d and otype = %d and type = %d + and term = '%s' and url = '%s' ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + if($r) + return false; + $r = q("insert into term (uid, oid, otype, type, term, url) + values( %d, %d, %d, %d, '%s', '%s') ", + intval($uid), + intval($iid), + intval($otype), + intval($type), + dbesc($term), + dbesc($url) + ); + return $r; +} + +function get_terms_oftype($arr,$type) { + $ret = array(); + if(! (is_array($arr) && count($arr))) + return $ret; + + if(! is_array($type)) + $type = array($type); + + foreach($type as $t) + foreach($arr as $x) + if($x['type'] == $t) + $ret[] = $x; + return $ret; +} + +function format_term_for_display($term) { + $s = ''; + if($term['type'] == TERM_HASHTAG) + $s .= '#'; + elseif($term['type'] == TERM_MENTION) + $s .= '@'; + + if($term['url']) $s .= '' . htmlspecialchars($term['term']) . ''; + else $s .= htmlspecialchars($term['term']); + return $s; +} + diff --git a/include/text.php b/include/text.php index c51ee0bd2..71268a793 100755 --- a/include/text.php +++ b/include/text.php @@ -1424,278 +1424,28 @@ function reltoabs($text, $base) } function item_post_type($item) { - if(intval($item['event-id'])) - return t('event'); - if(strlen($item['resource_id'])) - return t('photo'); - if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST) - return t('activity'); - if($item['id'] != $item['parent']) - return t('comment'); - return t('post'); -} - -// post categories and "save to file" use the same item.file table for storage. -// We will differentiate the different uses by wrapping categories in angle brackets -// and save to file categories in square brackets. -// To do this we need to escape these characters if they appear in our tag. - -function file_tag_encode($s) { - return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s); -} - -function file_tag_decode($s) { - return str_replace(array('%3c','%3e','%5b','%5d'),array('<','>','[',']'),$s); -} - -function file_tag_file_query($table,$s,$type = 'file') { - - if($type == 'file') - $termtype = TERM_FILE; - else - $termtype = TERM_CATEGORY; - - return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", - intval($termtype), - protect_sprintf(dbesc($s)) - ); -} - -function term_query($table,$s,$type = TERM_UNKNOWN) { - - return sprintf(" AND " . (($table) ? dbesc($table) . '.' : '') . "id in (select term.oid from term where term.type = %d and term.term = '%s' and term.uid = " . (($table) ? dbesc($table) . '.' : '') . "uid ) ", - intval($type), - protect_sprintf(dbesc($s)) - ); -} - -// ex. given music,video return