From 485f97b3d8937f219e2b9f3c662ee0e1966130eb Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 15 Nov 2011 20:30:34 -0800 Subject: [PATCH 01/10] tgroup relays --- include/items.php | 91 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 4 deletions(-) diff --git a/include/items.php b/include/items.php index b8e258d3f0..7ab7eeaa40 100644 --- a/include/items.php +++ b/include/items.php @@ -893,6 +893,8 @@ function item_store($arr,$force_parent = false) { ); } + tgroup_deliver($arr['uid'],$current_post); + return $current_post; } @@ -909,6 +911,64 @@ function get_item_contact($item,$contacts) { } +function tgroup_deliver($uid,$item_id) { + + $a = get_app(); + + $deliver_to_tgroup = false; + + $u = q("select * from user where uid = %d and `page-flags` = %d limit 1", + intval($uid), + intval(PAGE_COMMUNITY) + ); + if(! count($u)) + return; + + // We will only forward public tgroup posts, as this opens a second delivery chain + // and privacy can only be controlled by the first chain. + + $i = q("select * from item where id = %d and uid = %d and private = 0 limit 1", + intval($item_id), + intval($uid) + ); + if(! count($i)) + return; + + $item = $i[0]; + + // prevent delivery looping - only proceed + // if the message originated elsewhere + + if(($item['wall']) || ($item['origin'])) + return; + + + $link = normalise_link($a->get_baseurl() . '/profile/' . $u[0]['nickname']); + + $cnt = preg_match_all('/\@\[url\=(.*?)\](.*?)\[\/url\]/ism',$item['body'],$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + if(link_compare($link,$mtch[1])) { + $deliver_to_tgroup = true; + logger('tgroup_deliver: local group mention found: ' . $mtch[2]); + } + } + } + + if(! $deliver_to_tgroup) + return; + + // now deliver to all the tgroup members + + proc_run('php','include/notifier.php','tgroup',$item_id); + +} + + + + + + function dfrn_deliver($owner,$contact,$atom, $dissolve = false) { $a = get_app(); @@ -1962,18 +2022,31 @@ function local_delivery($importer,$data) { if($is_reply) { + $community = false; + + if($importer['page-flags'] == PAGE_COMMUNITY) { + $sql_extra = ''; + $community = true; + logger('local_delivery: community reply'); + } + else + $sql_extra = " and contact.self = 1 and item.wall = 1 "; + // was the top-level post for this reply written by somebody on this site? // Specifically, the recipient? - +dbg(1); $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - WHERE `contact`.`self` = 1 AND `item`.`wall` = 1 AND `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s' - AND `item`.`uid` = %d LIMIT 1", + WHERE `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s' + AND `item`.`uid` = %d + $sql_extra + LIMIT 1", dbesc($parent_uri), dbesc($parent_uri), intval($importer['importer_uid']) ); +dbg(0); if($r && count($r)) { logger('local_delivery: received remote comment'); @@ -1981,7 +2054,7 @@ function local_delivery($importer,$data) { // remote reply to our post. Import and then notify everybody else. $datarray = get_atom_elements($feed,$item); - if(! link_compare($datarray['author-link'],$importer['url'])) { + if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) { logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] ); // they won't know what to do so don't report an error. Just quietly die. return 0; @@ -2028,6 +2101,16 @@ function local_delivery($importer,$data) { } } + if($community) { + $newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]'; + if(! stristr($datarray['tag'],$newtag)) { + if(strlen($datarray['tag'])) + $datarray['tag'] .= ','; + $datarray['tag'] .= $newtag; + } + } + + $posted_id = item_store($datarray); $parent = 0; From fa4742e6eec1850f1bb53e38379cf2aac650cc3b Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 17 Nov 2011 15:42:56 -0800 Subject: [PATCH 02/10] comment boxes not work in alternate languages --- boot.php | 2 +- index.php | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/boot.php b/boot.php index 7d9337b2ed..74956e9f6a 100644 --- a/boot.php +++ b/boot.php @@ -9,7 +9,7 @@ require_once('include/nav.php'); require_once('include/cache.php'); define ( 'FRIENDIKA_PLATFORM', 'Friendica'); -define ( 'FRIENDIKA_VERSION', '2.3.1167' ); +define ( 'FRIENDIKA_VERSION', '2.3.1168' ); define ( 'DFRN_PROTOCOL_VERSION', '2.22' ); define ( 'DB_UPDATE_VERSION', 1104 ); diff --git a/index.php b/index.php index 78ceb6d770..e43d7332de 100644 --- a/index.php +++ b/index.php @@ -75,8 +75,6 @@ $a->timezone = (($default_timezone) ? $default_timezone : 'UTC'); date_default_timezone_set($a->timezone); -$a->init_pagehead(); - session_start(); /** @@ -95,6 +93,12 @@ if((x($_SESSION,'language')) && ($_SESSION['language'] !== $lang)) { load_translation_table($lang); } +/* + * Create the page head after setting the language + * + */ + +$a->init_pagehead(); /** * From d53db63d41d2f253c9aff806d9830167c9dd7a8d Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 18 Nov 2011 21:55:00 -0800 Subject: [PATCH 03/10] forum split delivery flag --- boot.php | 4 ++-- database.sql | 2 ++ mod/item.php | 4 ++-- update.php | 9 ++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/boot.php b/boot.php index 74956e9f6a..61383f0afd 100644 --- a/boot.php +++ b/boot.php @@ -9,9 +9,9 @@ require_once('include/nav.php'); require_once('include/cache.php'); define ( 'FRIENDIKA_PLATFORM', 'Friendica'); -define ( 'FRIENDIKA_VERSION', '2.3.1168' ); +define ( 'FRIENDIKA_VERSION', '2.3.1169' ); define ( 'DFRN_PROTOCOL_VERSION', '2.22' ); -define ( 'DB_UPDATE_VERSION', 1104 ); +define ( 'DB_UPDATE_VERSION', 1105 ); define ( 'EOL', "
\r\n" ); define ( 'ATOM_TIME', 'Y-m-d\TH:i:s\Z' ); diff --git a/database.sql b/database.sql index 924cc49b23..98067d8d60 100644 --- a/database.sql +++ b/database.sql @@ -226,6 +226,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `unseen` tinyint(1) NOT NULL DEFAULT '1', `deleted` tinyint(1) NOT NULL DEFAULT '0', `origin` tinyint(1) NOT NULL DEFAULT '0', + `forum_mode` tinyint(1) NOT NULL DEFAULT '0', `last-child` tinyint(1) unsigned NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `guid` (`guid`), @@ -244,6 +245,7 @@ CREATE TABLE IF NOT EXISTS `item` ( KEY `starred` (`starred`), KEY `deleted` (`deleted`), KEY `origin` (`origin`), + KEY `forum_mode` (`forum_mode`), KEY `last-child` (`last-child`), KEY `unseen` (`unseen`), KEY `wall` (`wall`), diff --git a/mod/item.php b/mod/item.php index ee3bdca992..145c42cec9 100644 --- a/mod/item.php +++ b/mod/item.php @@ -865,12 +865,12 @@ function item_post(&$a) { $addr = trim($recip); if(! strlen($addr)) continue; - $disclaimer = '
' . sprintf( t('This message was sent to you by %s, a member of the Friendika social network.'),$a->user['username']) + $disclaimer = '
' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'),$a->user['username']) . '
'; $disclaimer .= sprintf( t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL; - $subject = '[Friendika]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']); + $subject = '[Friendica]' . ' ' . sprintf( t('%s posted an update.'),$a->user['username']); $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n"; diff --git a/update.php b/update.php index 14d68ea12c..96fdec6911 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Fri, 18 Nov 2011 22:03:49 -0800 Subject: [PATCH 04/10] update user-agent string for remote http requests --- include/network.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/network.php b/include/network.php index e89eb94da2..78ed240743 100644 --- a/include/network.php +++ b/include/network.php @@ -22,7 +22,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ } @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - @curl_setopt($ch, CURLOPT_USERAGENT, "Friendika"); + @curl_setopt($ch, CURLOPT_USERAGENT, "Friendica"); if(intval($timeout)) { @@ -105,7 +105,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$params); - curl_setopt($ch, CURLOPT_USERAGENT, "Friendika"); + curl_setopt($ch, CURLOPT_USERAGENT, "Friendica"); if(intval($timeout)) { curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); From 64635438326e34710138e3e270cb3bbfc55d76a1 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 18 Nov 2011 22:20:08 -0800 Subject: [PATCH 05/10] new approach to secondary delivery fork --- include/items.php | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/include/items.php b/include/items.php index 72c1a8b324..381032629a 100644 --- a/include/items.php +++ b/include/items.php @@ -913,6 +913,9 @@ function get_item_contact($item,$contacts) { function tgroup_deliver($uid,$item_id) { + + // setup a second delivery chain for forum/community posts if appropriate + $a = get_app(); $deliver_to_tgroup = false; @@ -937,9 +940,9 @@ function tgroup_deliver($uid,$item_id) { $item = $i[0]; // prevent delivery looping - only proceed - // if the message originated elsewhere + // if the message originated elsewhere and is a top-level post - if(($item['wall']) || ($item['origin'])) + if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent'])) return; @@ -958,7 +961,12 @@ function tgroup_deliver($uid,$item_id) { if(! $deliver_to_tgroup) return; - // now deliver to all the tgroup members + // now change this post to a forum head message and deliver to all the tgroup members + + + q("update item set wall = 1, origin = 1, forum_mode = 1 where id = %d limit 1", + intval($item_id) + ); proc_run('php','include/notifier.php','tgroup',$item_id); @@ -2025,17 +2033,18 @@ function local_delivery($importer,$data) { $community = false; - if($importer['page-flags'] == PAGE_COMMUNITY) { - $sql_extra = ''; - $community = true; - logger('local_delivery: community reply'); - } - else +// if($importer['page-flags'] == PAGE_COMMUNITY) { +// $sql_extra = ''; +// $community = true; +// logger('local_delivery: community reply'); +// } +// else + $sql_extra = " and contact.self = 1 and item.wall = 1 "; // was the top-level post for this reply written by somebody on this site? // Specifically, the recipient? -dbg(1); +//dbg(1); $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` @@ -2047,7 +2056,7 @@ dbg(1); dbesc($parent_uri), intval($importer['importer_uid']) ); -dbg(0); +//dbg(0); if($r && count($r)) { logger('local_delivery: received remote comment'); @@ -2055,11 +2064,11 @@ dbg(0); // remote reply to our post. Import and then notify everybody else. $datarray = get_atom_elements($feed,$item); - if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) { - logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] ); +// if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) { +// logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] ); // they won't know what to do so don't report an error. Just quietly die. - return 0; - } +// return 0; +// } $datarray['type'] = 'remote-comment'; $datarray['wall'] = 1; From d4911f15e97123590ad6ecdfd32c84a334134528 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 18 Nov 2011 23:02:07 -0800 Subject: [PATCH 06/10] don't allow space in autocomplete nickname --- js/fk.autocomplete.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/fk.autocomplete.js b/js/fk.autocomplete.js index 545fd16454..85b51baeb3 100644 --- a/js/fk.autocomplete.js +++ b/js/fk.autocomplete.js @@ -80,7 +80,7 @@ ACPopup.prototype._search = function(){ that.cont.show(); $(data.items).each(function(){ html = "{1} ({2})".format(this.photo, this.name, this.nick) - that.add(html, this.nick + '+' + this.id + ' - ' + this.link); + that.add(html, this.nick.replace(' ','') + '+' + this.id + ' - ' + this.link); }); } else { that.cont.hide(); From 72dd6457b014e504c79dbe494ac6095cadd9b942 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 19 Nov 2011 03:06:15 -0800 Subject: [PATCH 07/10] first forum test --- include/items.php | 29 ++++++++++++++--------------- include/notifier.php | 12 ++++++++++++ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/include/items.php b/include/items.php index 381032629a..caf4973457 100644 --- a/include/items.php +++ b/include/items.php @@ -2033,13 +2033,12 @@ function local_delivery($importer,$data) { $community = false; -// if($importer['page-flags'] == PAGE_COMMUNITY) { -// $sql_extra = ''; -// $community = true; -// logger('local_delivery: community reply'); -// } -// else - + if($importer['page-flags'] == PAGE_COMMUNITY) { + $sql_extra = ''; + $community = true; + logger('local_delivery: community reply'); + } + else $sql_extra = " and contact.self = 1 and item.wall = 1 "; // was the top-level post for this reply written by somebody on this site? @@ -2113,14 +2112,14 @@ function local_delivery($importer,$data) { } } - if($community) { - $newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]'; - if(! stristr($datarray['tag'],$newtag)) { - if(strlen($datarray['tag'])) - $datarray['tag'] .= ','; - $datarray['tag'] .= $newtag; - } - } +// if($community) { +// $newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]'; +// if(! stristr($datarray['tag'],$newtag)) { +// if(strlen($datarray['tag'])) +// $datarray['tag'] .= ','; +// $datarray['tag'] .= $newtag; +// } +// } $posted_id = item_store($datarray); diff --git a/include/notifier.php b/include/notifier.php index a4fe9b71e0..c81ca2d153 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -218,6 +218,11 @@ function notifier_run($argv, $argc){ $relay_to_owner = true; } + + if(($cmd === 'uplink') && (intval($parent['forum_mode'])) && (! $top_level)) { + $relay_to_owner = true; + } + // until the 'origin' flag has been in use for several months // we will just use it as a fallback test // later we will be able to use it as the primary test of whether or not to relay. @@ -259,6 +264,13 @@ function notifier_run($argv, $argc){ $deny_people = expand_acl($parent['deny_cid']); $deny_groups = expand_groups(expand_acl($parent['deny_gid'])); + // if our parent is a forum, uplink to the origonal author causing + // a delivery fork + + if(intval($parent['forum_mode']) && (! $top_level) && ($cmd !== 'uplink')) { + proc_run('php','include/notifier','uplink',$item_id); + } + $conversants = array(); foreach($items as $item) { From 191a9b048f3afa28b08a2e3cd2b277fc84956876 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 19 Nov 2011 03:13:46 -0800 Subject: [PATCH 08/10] forum cleanup --- include/items.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/items.php b/include/items.php index caf4973457..8ea43efeb2 100644 --- a/include/items.php +++ b/include/items.php @@ -927,10 +927,7 @@ function tgroup_deliver($uid,$item_id) { if(! count($u)) return; - // We will only forward public tgroup posts, as this opens a second delivery chain - // and privacy can only be controlled by the first chain. - - $i = q("select * from item where id = %d and uid = %d and private = 0 limit 1", + $i = q("select * from item where id = %d and uid = %d limit 1", intval($item_id), intval($uid) ); @@ -961,7 +958,7 @@ function tgroup_deliver($uid,$item_id) { if(! $deliver_to_tgroup) return; - // now change this post to a forum head message and deliver to all the tgroup members + // now change this copy of the post to a forum head message and deliver to all the tgroup members q("update item set wall = 1, origin = 1, forum_mode = 1 where id = %d limit 1", From 44dcef29484c1f27f15d3ce1ae63a9d24cd1f5e7 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 19 Nov 2011 13:37:10 -0800 Subject: [PATCH 09/10] revup --- boot.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boot.php b/boot.php index 61383f0afd..7734226379 100644 --- a/boot.php +++ b/boot.php @@ -9,7 +9,7 @@ require_once('include/nav.php'); require_once('include/cache.php'); define ( 'FRIENDIKA_PLATFORM', 'Friendica'); -define ( 'FRIENDIKA_VERSION', '2.3.1169' ); +define ( 'FRIENDIKA_VERSION', '2.3.1170' ); define ( 'DFRN_PROTOCOL_VERSION', '2.22' ); define ( 'DB_UPDATE_VERSION', 1105 ); From aaedac8f574278fba89cd11d3d8f1adaeb6b030e Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 19 Nov 2011 13:45:20 -0800 Subject: [PATCH 10/10] community forums cleanup --- include/items.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/items.php b/include/items.php index 8ea43efeb2..4e56176277 100644 --- a/include/items.php +++ b/include/items.php @@ -2040,7 +2040,7 @@ function local_delivery($importer,$data) { // was the top-level post for this reply written by somebody on this site? // Specifically, the recipient? -//dbg(1); + $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, `contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` @@ -2052,7 +2052,7 @@ function local_delivery($importer,$data) { dbesc($parent_uri), intval($importer['importer_uid']) ); -//dbg(0); + if($r && count($r)) { logger('local_delivery: received remote comment'); @@ -2060,6 +2060,9 @@ function local_delivery($importer,$data) { // remote reply to our post. Import and then notify everybody else. $datarray = get_atom_elements($feed,$item); + + // TODO: make this next part work against both delivery threads of a community post + // if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) { // logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] ); // they won't know what to do so don't report an error. Just quietly die.