aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/Contact.php6
-rw-r--r--include/Scrape.php106
-rw-r--r--include/acl_selectors.php22
-rw-r--r--include/bbcode.php11
-rw-r--r--include/directory.php36
-rw-r--r--include/html2bbcode.php4
-rw-r--r--include/items.php181
-rw-r--r--include/main.js14
-rw-r--r--include/notifier.php255
-rw-r--r--include/oembed.php97
-rw-r--r--include/poller.php67
-rw-r--r--include/queue.php35
-rw-r--r--include/salmon.php14
13 files changed, 630 insertions, 218 deletions
diff --git a/include/Contact.php b/include/Contact.php
index 98d3e7c0b..7cac3c0e0 100644
--- a/include/Contact.php
+++ b/include/Contact.php
@@ -6,6 +6,10 @@
// authorisation to do this.
function user_remove($uid) {
+ if(! $uid)
+ return;
+ $a = get_app();
+ logger('Removing user: ' . $uid);
q("DELETE FROM `contact` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group` WHERE `uid` = %d", intval($uid));
q("DELETE FROM `group_member` WHERE `uid` = %d", intval($uid));
@@ -19,7 +23,7 @@ function user_remove($uid) {
if($uid == local_user()) {
unset($_SESSION['authenticated']);
unset($_SESSION['uid']);
- killme();
+ goaway($a->get_baseurl());
}
}
diff --git a/include/Scrape.php b/include/Scrape.php
index 10ec54d13..ff9899252 100644
--- a/include/Scrape.php
+++ b/include/Scrape.php
@@ -5,12 +5,31 @@ require_once('library/HTML5/Parser.php');
if(! function_exists('scrape_dfrn')) {
function scrape_dfrn($url) {
+ $a = get_app();
+
$ret = array();
+
+ logger('scrape_dfrn: url=' . $url);
+
$s = fetch_url($url);
if(! $s)
return $ret;
+ $headers = $a->get_curl_headers();
+ logger('scrape_dfrn: headers=' . $headers, LOGGER_DEBUG);
+
+
+ $lines = explode("\n",$headers);
+ if(count($lines)) {
+ foreach($lines as $line) {
+ // don't try and run feeds through the html5 parser
+ if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
+ return ret;
+ }
+ }
+
+
$dom = HTML5_Parser::parse($s);
if(! $dom)
@@ -22,6 +41,8 @@ function scrape_dfrn($url) {
foreach($items as $item) {
$x = $item->getAttribute('rel');
+ if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
+ $ret['feed_atom'] = $item->getAttribute('href');
if(substr($x,0,5) == "dfrn-")
$ret[$x] = $item->getAttribute('href');
if($x === 'lrdd') {
@@ -75,12 +96,31 @@ function validate_dfrn($a) {
if(! function_exists('scrape_meta')) {
function scrape_meta($url) {
+ $a = get_app();
+
$ret = array();
+
+ logger('scrape_meta: url=' . $url);
+
$s = fetch_url($url);
if(! $s)
return $ret;
+ $headers = $a->get_curl_headers();
+ logger('scrape_meta: headers=' . $headers, LOGGER_DEBUG);
+
+ $lines = explode("\n",$headers);
+ if(count($lines)) {
+ foreach($lines as $line) {
+ // don't try and run feeds through the html5 parser
+ if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
+ return ret;
+ }
+ }
+
+
+
$dom = HTML5_Parser::parse($s);
if(! $dom)
@@ -103,12 +143,27 @@ function scrape_meta($url) {
if(! function_exists('scrape_vcard')) {
function scrape_vcard($url) {
+ $a = get_app();
+
$ret = array();
+
+ logger('scrape_vcard: url=' . $url);
+
$s = fetch_url($url);
if(! $s)
return $ret;
+ $headers = $a->get_curl_headers();
+ $lines = explode("\n",$headers);
+ if(count($lines)) {
+ foreach($lines as $line) {
+ // don't try and run feeds through the html5 parser
+ if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
+ return ret;
+ }
+ }
+
$dom = HTML5_Parser::parse($s);
if(! $dom)
@@ -135,3 +190,54 @@ function scrape_vcard($url) {
return $ret;
}}
+
+
+if(! function_exists('scrape_feed')) {
+function scrape_feed($url) {
+
+ $a = get_app();
+
+ $ret = array();
+ $s = fetch_url($url);
+
+ if(! $s)
+ return $ret;
+
+ $headers = $a->get_curl_headers();
+ logger('scrape_feed: headers=' . $headers, LOGGER_DEBUG);
+
+ $lines = explode("\n",$headers);
+ if(count($lines)) {
+ foreach($lines as $line) {
+ if(stristr($line,'content-type:')) {
+ if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
+ $ret['feed_atom'] = $url;
+ return $ret;
+ }
+ if(stristr($line,'application/rss+xml') || stristr($s,'<rss')) {
+ $ret['feed_rss'] = $url;
+ return ret;
+ }
+ }
+ }
+ }
+
+ $dom = HTML5_Parser::parse($s);
+
+ if(! $dom)
+ return $ret;
+
+ $items = $dom->getElementsByTagName('link');
+
+ // get Atom link elements
+
+ foreach($items as $item) {
+ $x = $item->getAttribute('rel');
+ if(($x === 'alternate') && ($item->getAttribute('type') === 'application/atom+xml'))
+ $ret['feed_atom'] = $item->getAttribute('href');
+ if(($x === 'alternate') && ($item->getAttribute('type') === 'application/rss+xml'))
+ $ret['feed_rss'] = $item->getAttribute('href');
+ }
+
+ return $ret;
+}} \ No newline at end of file
diff --git a/include/acl_selectors.php b/include/acl_selectors.php
index d0952421e..269dc3e34 100644
--- a/include/acl_selectors.php
+++ b/include/acl_selectors.php
@@ -17,8 +17,9 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
$selected = " selected=\"selected\" ";
else
$selected = '';
+ $trimmed = substr($rr['name'],0,12);
- $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['name']}</option>\r\n";
+ $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}\" >$trimmed</option>\r\n";
}
}
@@ -30,7 +31,7 @@ function group_select($selname,$selclass,$preselected = false,$size = 4) {
-function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false) {
+function contact_select($selname, $selclass, $preselected = false, $size = 4, $privmail = false, $celeb = false, $privatenet = false) {
$o = '';
@@ -43,6 +44,10 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$sql_extra .= sprintf(" AND `rel` = %d ", intval(REL_BUD));
}
+ if($privmail || $privatenet) {
+ $sql_extra .= " AND `network` IN ( 'dfrn' ) ";
+ }
+
if($privmail)
$o .= "<select name=\"$selname\" id=\"$selclass\" class=\"$selclass\" size=\"$size\" >\r\n";
else
@@ -61,11 +66,10 @@ function contact_select($selname, $selclass, $preselected = false, $size = 4, $p
$selected = " selected=\"selected\" ";
else
$selected = '';
- if(($privmail) && ($rr['network'] === 'stat'))
- $disabled = ' disabled="true" ' ;
- else
- $disabled = '';
- $o .= "<option value=\"{$rr['id']}\" $selected $disabled title=\"{$rr['url']}\" >{$rr['name']}</option>\r\n";
+
+ $trimmed = substr($rr['name'],0,22);
+
+ $o .= "<option value=\"{$rr['id']}\" $selected title=\"{$rr['name']}|{$rr['url']}\" >$trimmed</option>\r\n";
}
}
@@ -110,7 +114,7 @@ function populate_acl($user = null,$celeb = false) {
$o .= '</div>';
$o .= '<div id="contact_allow_wrapper">';
$o .= '<label id="acl-allow-contact-label" for="contact_allow" >' . t('Contacts') . '</label>';
- $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb);
+ $o .= contact_select('contact_allow','contact_allow',$allow_cid,4,false,$celeb,true);
$o .= '</div>';
$o .= '</div>' . "\r\n";
$o .= '<div id="acl-allow-end"></div>' . "\r\n";
@@ -125,7 +129,7 @@ function populate_acl($user = null,$celeb = false) {
$o .= '</div>';
$o .= '<div id="contact_deny_wrapper" >';
$o .= '<label id="acl-deny-contact-label" for="contact_deny" >' . t('Contacts') . '</label>';
- $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb);
+ $o .= contact_select('contact_deny','contact_deny', $deny_cid,4,false, $celeb,true);
$o .= '</div>';
$o .= '</div>' . "\r\n";
$o .= '<div id="acl-deny-end"></div>' . "\r\n";
diff --git a/include/bbcode.php b/include/bbcode.php
index 81b581cdb..eb0806dc5 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -1,5 +1,5 @@
<?php
-
+require_once("include/oembed.php");
// BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendika - Mike Macgirvin
@@ -22,10 +22,10 @@ function bbcode($Text) {
// Perform URL Search
- $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%]*)/", ' <a href="$2" >$2</a>', $Text);
+ $Text = preg_replace("/([^\]\=]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%]+)/", ' <a href="$2" target="external-link">$2</a>', $Text);
- $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" >$1</a>', $Text);
- $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" >$2</a>', $Text);
+ $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="external-link">$1</a>', $Text);
+ $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="external-link">$2</a>', $Text);
//$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
@@ -93,6 +93,9 @@ function bbcode($Text) {
$Text = preg_replace("/\[youtube\]http:\/\/www.youtube.com\/watch\?v\=(.+?)\[\/youtube\]/",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\](.+?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
+ // oembed tag
+ $Text = oembed_bbcode2html($Text);
+
call_hooks('bbcode',$Text);
return $Text;
diff --git a/include/directory.php b/include/directory.php
index 5f835dc4b..2c9daa5ea 100644
--- a/include/directory.php
+++ b/include/directory.php
@@ -1,17 +1,22 @@
<?php
-
- require_once("boot.php");
-
- $a = new App;
-
- @include(".htconfig.php");
- require_once("dba.php");
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
-
+require_once("boot.php");
+
+function directory_run($argv, $argc){
+ global $a, $db;
+
+ if(is_null($a)){
+ $a = new App;
+ }
+
+ if(is_null($db)){
+ @include(".htconfig.php");
+ require_once("dba.php");
+ $db = new dba($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+ };
if($argc != 2)
- exit;
+ return;
load_config('system');
@@ -20,9 +25,14 @@
$dir = get_config('system','directory_submit_url');
if(! strlen($dir))
- exit;
+ return;
fetch_url($dir . '?url=' . bin2hex($argv[1]));
- exit;
+ return;
+}
+if (array_search(__file__,get_included_files())===0){
+ directory_run($argv,$argc);
+ killme();
+}
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 65cbcec41..6af8df824 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -23,7 +23,7 @@ function html2bbcode($s) {
'/\<div(.*?)\>(.*?)\<\/div\>/is',
'/\<br(.*?)\>/is',
'/\<strong\>(.*?)\<\/strong\>/is',
- '/\<a href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
+ '/\<a (.*?)href=\"(.*?)\"(.*?)\>(.*?)\<\/a\>/is',
'/\<code\>(.*?)\<\/code\>/is',
'/\<span style=\"color:(.*?)\"\>(.*?)\<\/span\>/is',
'/\<blockquote\>(.*?)\<\/blockquote\>/is',
@@ -48,7 +48,7 @@ function html2bbcode($s) {
'$2',
"\n",
'[b]$1[/b]',
- '[url=$1]$3[/url]',
+ '[url=$2]$4[/url]',
'[code]$1[/code]',
'[color="$1"]$2[/color]',
'[quote]$1[/quote]',
diff --git a/include/items.php b/include/items.php
index 5f8264beb..359378ff7 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1,6 +1,8 @@
<?php
require_once('bbcode.php');
+require_once('oembed.php');
+require_once('include/salmon.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
@@ -375,6 +377,21 @@ function get_atom_elements($feed,$item) {
}
+ /**
+ * If there's a copy of the body content which is guaranteed to have survived mangling in transit, use it.
+ */
+
+ $have_real_body = false;
+
+ $rawenv = $item->get_item_tags(NAMESPACE_DFRN, 'env');
+ if($rawenv) {
+ $have_real_body = true;
+ $res['body'] = $rawenv[0]['data'];
+ $res['body'] = str_replace(array(' ',"\t","\r","\n"), array('','','',''),$res['body']);
+ // make sure nobody is trying to sneak some html tags by us
+ $res['body'] = notags(base64url_decode($res['body']));
+ }
+
$maxlen = get_max_import_size();
if($maxlen && (strlen($res['body']) > $maxlen))
$res['body'] = substr($res['body'],0, $maxlen);
@@ -390,11 +407,13 @@ function get_atom_elements($feed,$item) {
// html.
- if((strpos($res['body'],'<')) || (strpos($res['body'],'>'))) {
+ if((strpos($res['body'],'<') !== false) || (strpos($res['body'],'>') !== false)) {
$res['body'] = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $res['body']);
+ $res['body'] = oembed_html2bbcode($res['body']);
+
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
@@ -407,10 +426,7 @@ function get_atom_elements($feed,$item) {
$res['body'] = html2bbcode($res['body']);
}
- else
- $res['body'] = escape_tags($res['body']);
-
$allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
if($allow && $allow[0]['data'] == 1)
$res['last-child'] = 1;
@@ -423,18 +439,30 @@ function get_atom_elements($feed,$item) {
else
$res['private'] = 0;
- $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
- if($rawcreated)
- $res['created'] = unxmlify($rawcreated[0]['data']);
$rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
if($rawlocation)
$res['location'] = unxmlify($rawlocation[0]['data']);
+ $rawcreated = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'published');
+ if($rawcreated)
+ $res['created'] = unxmlify($rawcreated[0]['data']);
+
+
$rawedited = $item->get_item_tags(SIMPLEPIE_NAMESPACE_ATOM_10,'updated');
if($rawedited)
- $res['edited'] = unxmlify($rawcreated[0]['data']);
+ $res['edited'] = unxmlify($rawedited[0]['data']);
+
+ if((x($res,'edited')) && (! (x($res,'created'))))
+ $res['created'] = $res['edited'];
+
+ if(! $res['created'])
+ $res['created'] = $item->get_date('c');
+
+ if(! $res['edited'])
+ $res['edited'] = $item->get_date('c');
+
$rawowner = $item->get_item_tags(NAMESPACE_DFRN, 'owner');
if($rawowner[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['name'][0]['data'])
@@ -497,7 +525,7 @@ function get_atom_elements($feed,$item) {
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
// preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
$res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
- if((strpos($body,'<')) || (strpos($body,'>'))) {
+ if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
@@ -509,8 +537,6 @@ function get_atom_elements($feed,$item) {
$body = $purifier->purify($body);
$body = html2bbcode($body);
}
- else
- $body = escape_tags($body);
$res['object'] .= '<content>' . $body . '</content>' . "\n";
}
@@ -538,7 +564,7 @@ function get_atom_elements($feed,$item) {
$body = $rawobj[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10]['summary'][0]['data'];
// preserve a copy of the original body content in case we later need to parse out any microformat information, e.g. events
$res['object'] .= '<orig>' . xmlify($body) . '</orig>' . "\n";
- if((strpos($body,'<')) || (strpos($body,'>'))) {
+ if((strpos($body,'<') !== false) || (strpos($body,'>') !== false)) {
$body = preg_replace('#<object[^>]+>.+?' . 'http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+).+?</object>#s',
'[youtube]$1[/youtube]', $body);
@@ -550,8 +576,6 @@ function get_atom_elements($feed,$item) {
$body = $purifier->purify($body);
$body = html2bbcode($body);
}
- else
- $body = escape_tags($body);
$res['target'] .= '<content>' . $body . '</content>' . "\n";
}
@@ -587,7 +611,7 @@ function encode_rel_links($links) {
return xmlify($o);
}
-function item_store($arr) {
+function item_store($arr,$force_parent = false) {
if($arr['gravity'])
$arr['gravity'] = intval($arr['gravity']);
@@ -600,6 +624,13 @@ function item_store($arr) {
if(! x($arr,'type'))
$arr['type'] = 'remote';
+
+ // Shouldn't happen but we want to make absolutely sure it doesn't leak from a plugin.
+
+ if((strpos($arr['body'],'<') !== false) || (strpos($arr['body'],'>') !== false))
+ $arr['body'] = strip_tags($arr['body']);
+
+
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
$arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
@@ -628,20 +659,7 @@ function item_store($arr) {
$arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
$arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
- $arr['body'] = ((x($arr,'body')) ? escape_tags(trim($arr['body'])) : '');
-
- // The content body has been through a lot of filtering and transport escaping by now.
- // We don't want to skip any filters, however a side effect of all this filtering
- // is that ampersands and <> may have been double encoded, depending on which filter chain
- // they came through.
-
- $arr['body'] = str_replace(
- array('&amp;amp;', '&amp;gt;', '&amp;lt;', '&amp;quot;'),
- array('&amp;' , '&gt;' , '&lt;', '&quot;'),
- $arr['body']
- );
-
-
+ $arr['body'] = ((x($arr,'body')) ? trim($arr['body']) : '');
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
@@ -670,15 +688,28 @@ function item_store($arr) {
$arr['parent-uri'] = $r[0]['parent-uri'];
}
- $parent_id = $r[0]['id'];
- $allow_cid = $r[0]['allow_cid'];
- $allow_gid = $r[0]['allow_gid'];
- $deny_cid = $r[0]['deny_cid'];
- $deny_gid = $r[0]['deny_gid'];
+ $parent_id = $r[0]['id'];
+ $parent_deleted = $r[0]['deleted'];
+ $allow_cid = $r[0]['allow_cid'];
+ $allow_gid = $r[0]['allow_gid'];
+ $deny_cid = $r[0]['deny_cid'];
+ $deny_gid = $r[0]['deny_gid'];
}
else {
- logger('item_store: item parent was not found - ignoring item');
- return 0;
+
+ // Allow one to see reply tweets from status.net even when
+ // we don't have or can't see the original post.
+
+ if($force_parent) {
+ logger('item_store: $force_parent=true, reply converted to top-level post.');
+ $parent_id = 0;
+ $arr['thr-parent'] = $arr['parent-uri'];
+ $arr['parent-uri'] = $arr['uri'];
+ }
+ else {
+ logger('item_store: item parent was not found - ignoring item');
+ return 0;
+ }
}
}
@@ -709,10 +740,10 @@ function item_store($arr) {
return 0;
}
- if($arr['parent-uri'] === $arr['uri'])
+ if((! $parent_id) || ($arr['parent-uri'] === $arr['uri']))
$parent_id = $current_post;
-
- if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
+
+ if(strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid))
$private = 1;
else
$private = $arr['private'];
@@ -720,13 +751,14 @@ function item_store($arr) {
// Set parent id - and also make sure to inherit the parent's ACL's.
$r = q("UPDATE `item` SET `parent` = %d, `allow_cid` = '%s', `allow_gid` = '%s',
- `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d WHERE `id` = %d LIMIT 1",
+ `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d, `deleted` = %d WHERE `id` = %d LIMIT 1",
intval($parent_id),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
intval($private),
+ intval($parent_deleted),
intval($current_post)
);
@@ -746,11 +778,11 @@ function get_item_contact($item,$contacts) {
}
-function dfrn_deliver($owner,$contact,$atom) {
+function dfrn_deliver($owner,$contact,$atom, $dissolve = false) {
$a = get_app();
- if((! strlen($contact['dfrn-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
+ if((! strlen($contact['issued-id'])) && (! $contact['duplex']) && (! ($owner['page-flags'] == PAGE_COMMUNITY)))
return 3;
$idtosend = $orig_id = (($contact['dfrn-id']) ? $contact['dfrn-id'] : $contact['issued-id']);
@@ -782,6 +814,12 @@ function dfrn_deliver($owner,$contact,$atom) {
if(! $xml)
return 3;
+ if(strpos($xml,'<?xml') === false) {
+ logger('dfrn_deliver: no valid XML returned');
+ logger('dfrn_deliver: returned XML: ' . $xml, LOGGER_DATA);
+ return 3;
+ }
+
$res = simplexml_load_string($xml);
if((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id)))
@@ -790,19 +828,20 @@ function dfrn_deliver($owner,$contact,$atom) {
$postvars = array();
$sent_dfrn_id = hex2bin((string) $res->dfrn_id);
$challenge = hex2bin((string) $res->challenge);
+ $dfrn_version = (float) (($res->dfrn_version) ? $res->dfrn_version : 2.0);
$rino_allowed = ((intval($res->rino) === 1) ? 1 : 0);
$final_dfrn_id = '';
- if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
- openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
- openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
- }
- else {
+ if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
openssl_public_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['pubkey']);
openssl_public_decrypt($challenge,$postvars['challenge'],$contact['pubkey']);
}
+ else {
+ openssl_private_decrypt($sent_dfrn_id,$final_dfrn_id,$contact['prvkey']);
+ openssl_private_decrypt($challenge,$postvars['challenge'],$contact['prvkey']);
+ }
$final_dfrn_id = substr($final_dfrn_id, 0, strpos($final_dfrn_id, '.'));
@@ -817,6 +856,8 @@ function dfrn_deliver($owner,$contact,$atom) {
$postvars['dfrn_id'] = $idtosend;
$postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION;
+ if($dissolve)
+ $postvars['dissolve'] = '1';
if(($contact['rel']) && ($contact['rel'] != REL_FAN) && (! $contact['blocked']) && (! $contact['readonly'])) {
$postvars['data'] = $atom;
@@ -828,17 +869,28 @@ function dfrn_deliver($owner,$contact,$atom) {
$postvars['data'] = str_replace('<dfrn:comment-allow>1','<dfrn:comment-allow>0',$atom);
}
- if($rino && $rino_allowed) {
+ if($rino && $rino_allowed && (! $dissolve)) {
$key = substr(random_string(),0,16);
$data = bin2hex(aes_encrypt($postvars['data'],$key));
$postvars['data'] = $data;
logger('rino: sent key = ' . $key);
- if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
- openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+
+ if($dfrn_version >= 2.1) {
+ if(($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+ openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+ }
+ else {
+ openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+ }
}
else {
- openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+ if(($contact['duplex'] && strlen($contact['prvkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) {
+ openssl_private_encrypt($key,$postvars['key'],$contact['prvkey']);
+ }
+ else {
+ openssl_public_encrypt($key,$postvars['key'],$contact['pubkey']);
+ }
}
logger('md5 rawkey ' . md5($postvars['key']));
@@ -856,6 +908,13 @@ function dfrn_deliver($owner,$contact,$atom) {
if((! $curl_stat) || (! strlen($xml)))
return(-1); // timed out
+
+ if(strpos($xml,'<?xml') === false) {
+ logger('dfrn_deliver: phase 2: no valid XML returned');
+ logger('dfrn_deliver: phase 2: returned XML: ' . $xml, LOGGER_DATA);
+ return 3;
+ }
+
$res = simplexml_load_string($xml);
return $res->status;
@@ -891,6 +950,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
$feed->enable_order_by_date(false);
$feed->init();
+ if($feed->error())
+ logger('consume_feed: Error parsing XML: ' . $feed->error());
+
+
// Check at the feed level for updated contact name and/or photo
$name_updated = '';
@@ -1145,7 +1208,9 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
continue;
}
$datarray = get_atom_elements($feed,$item);
+ $force_parent = false;
if($contact['network'] === 'stat') {
+ $force_parent = true;
if(strlen($datarray['title']))
unset($datarray['title']);
$r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
@@ -1155,6 +1220,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
);
$datarray['last-child'] = 1;
}
+
+ if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ // one way feed - no remote comment ability
+ $datarray['last-child'] = 0;
+ }
$datarray['parent-uri'] = $parent_uri;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
@@ -1163,7 +1233,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
$datarray['gravity'] = GRAVITY_LIKE;
}
- $r = item_store($datarray);
+ $r = item_store($datarray,$force_parent);
continue;
}
@@ -1207,6 +1277,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
$datarray['last-child'] = 1;
}
+ if(($contact['network'] === 'feed') || (! strlen($contact['notify']))) {
+ // one way feed - no remote comment ability
+ $datarray['last-child'] = 0;
+ }
+
$datarray['parent-uri'] = $item_id;
$datarray['uid'] = $importer['uid'];
$datarray['contact-id'] = $contact['id'];
@@ -1216,7 +1291,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0) {
}
}
}
-
}
function new_follower($importer,$contact,$datarray,$item) {
@@ -1392,6 +1466,7 @@ function atom_entry($item,$type,$author,$owner,$comment = false) {
$o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
$o .= '<published>' . xmlify(datetime_convert('UTC','UTC',$item['created'] . '+00:00',ATOM_TIME)) . '</published>' . "\r\n";
$o .= '<updated>' . xmlify(datetime_convert('UTC','UTC',$item['edited'] . '+00:00',ATOM_TIME)) . '</updated>' . "\r\n";
+ $o .= '<dfrn:env>' . base64url_encode($item['body'], true) . '</dfrn:env>' . "\r\n";
$o .= '<content type="' . $type . '" >' . xmlify(($type === 'html') ? bbcode($item['body']) : $item['body']) . '</content>' . "\r\n";
$o .= '<link rel="alternate" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
if($comment)
diff --git a/include/main.js b/include/main.js
index fcd1d6fee..63b34bd21 100644
--- a/include/main.js
+++ b/include/main.js
@@ -44,12 +44,14 @@
$('#pause').html('');
}
}
- if(event.keyCode == '36' && event.shiftKey == true) {
- if(homebase !== undefined) {
- event.preventDefault();
- document.location = homebase;
- }
- }
+// this is shift-home on FF, but $ on IE, disabling until I figure out why the diff.
+// update: incompatible usage of onKeyDown vs onKeyPress
+// if(event.keyCode == '36' && event.shiftKey == true) {
+// if(homebase !== undefined) {
+// event.preventDefault();
+// document.location = homebase;
+// }
+// }
});
});
diff --git a/include/notifier.php b/include/notifier.php
index 4efdad4ce..a71da853d 100644
--- a/include/notifier.php
+++ b/include/notifier.php
@@ -1,14 +1,19 @@
<?php
+require_once("boot.php");
- require_once("boot.php");
-
- $a = new App;
-
- @include(".htconfig.php");
- require_once("dba.php");
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
+function notifier_run($argv, $argc){
+ global $a, $db;
+ if(is_null($a)){
+ $a = new App;
+ }
+
+ if(is_null($db)) {
+ @include(".htconfig.php");
+ require_once("dba.php");
+ $db = new dba($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+ }
require_once("session.php");
require_once("datetime.php");
@@ -16,7 +21,7 @@
require_once('include/bbcode.php');
if($argc < 3)
- exit;
+ return;
$a->set_baseurl(get_config('system','url'));
@@ -29,8 +34,9 @@
case 'mail':
default:
$item_id = intval($argv[2]);
- if(! $item_id)
- killme();
+ if(! $item_id){
+ return;
+ }
break;
}
@@ -42,23 +48,26 @@
$message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
intval($item_id)
);
- if(! count($message))
- killme();
+ if(! count($message)){
+ return;
+ }
$uid = $message[0]['uid'];
$recipients[] = $message[0]['contact-id'];
$item = $message[0];
}
else {
- // find ancestors
+ // find ancestors
$r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
intval($item_id)
);
- if(! count($r))
- killme();
- $parent_id = $r[0]['parent'];
+ if((! count($r)) || (! intval($r[0]['parent']))) {
+ return;
+ }
+
+ $parent_id = intval($r[0]['parent']);
$uid = $r[0]['uid'];
$updated = $r[0]['edited'];
@@ -66,8 +75,16 @@
intval($parent_id)
);
- if(! count($items))
- killme();
+ if(! count($items)){
+ return;
+ }
+
+ // avoid race condition with deleting entries
+
+ if($items[0]['deleted']) {
+ foreach($items as $item)
+ $item['deleted'] = 1;
+
}
$r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`
@@ -78,9 +95,9 @@
if(count($r))
$owner = $r[0];
- else
- killme();
-
+ else {
+ return;
+ }
$hub = get_config('system','huburl');
// If this is a public conversation, notify the feed hub
@@ -113,8 +130,8 @@
$allow_people = expand_acl($parent['allow_cid']);
$allow_groups = expand_groups(expand_acl($parent['allow_gid']));
- $deny_people = expand_acl($parent['deny_cid']);
- $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
+ $deny_people = expand_acl($parent['deny_cid']);
+ $deny_groups = expand_groups(expand_acl($parent['deny_gid']));
$conversants = array();
@@ -150,10 +167,12 @@
$r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
- if( ! count($r))
- killme();
+// if( ! count($r)){
+// return;
+// }
- $contacts = $r;
+ if(count($r))
+ $contacts = $r;
}
$feed_template = load_view_file('view/atom_feed.tpl');
@@ -209,6 +228,8 @@
else {
if($followup) {
foreach($items as $item) { // there is only one item
+ if(! $item['parent'])
+ continue;
if($item['id'] == $item_id) {
logger('notifier: followup: item: ' . print_r($item,true), LOGGER_DATA);
$slap = atom_entry($item,'html',$owner,$owner,false);
@@ -218,6 +239,9 @@
}
else {
foreach($items as $item) {
+ if(! $item['parent'])
+ continue;
+
$contact = get_item_contact($item,$contacts);
if(! $contact)
continue;
@@ -245,90 +269,90 @@
$recip_str = implode(', ', $recipients);
- $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 ",
+ $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 AND `pending` = 0 ",
dbesc($recip_str)
);
- if(! count($r))
- killme();
// delivery loop
require_once('include/salmon.php');
- foreach($r as $contact) {
- if($contact['self'])
- continue;
+ if(count($r)) {
+ foreach($r as $contact) {
+ if($contact['self'])
+ continue;
- $deliver_status = 0;
+ $deliver_status = 0;
- switch($contact['network']) {
- case 'dfrn':
- logger('notifier: dfrndelivery: ' . $contact['name']);
- $deliver_status = dfrn_deliver($owner,$contact,$atom);
-
- logger('notifier: dfrn_delivery returns ' . $deliver_status);
-
- if($deliver_status == (-1)) {
- logger('notifier: delivery failed: queuing message');
- // queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($atom)
- );
- }
- break;
- case 'stat':
- if($followup && $contact['notify']) {
- logger('notifier: slapdelivery: ' . $contact['name']);
- $deliver_status = slapper($owner,$contact['notify'],$slap);
+ switch($contact['network']) {
+ case 'dfrn':
+ logger('notifier: dfrndelivery: ' . $contact['name']);
+ $deliver_status = dfrn_deliver($owner,$contact,$atom);
+ logger('notifier: dfrn_delivery returns ' . $deliver_status);
+
if($deliver_status == (-1)) {
+ logger('notifier: delivery failed: queuing message');
// queue message for redelivery
q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
VALUES ( %d, '%s', '%s', '%s') ",
intval($contact['id']),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
- dbesc($slap)
+ dbesc($atom)
);
-
}
+ break;
+ case 'stat':
+ if($followup && $contact['notify']) {
+ logger('notifier: slapdelivery: ' . $contact['name']);
+ $deliver_status = slapper($owner,$contact['notify'],$slap);
+
+ if($deliver_status == (-1)) {
+ // queue message for redelivery
+ q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
+ VALUES ( %d, '%s', '%s', '%s') ",
+ intval($contact['id']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($slap)
+ );
+ }
+
- }
- else {
-
- // only send salmon if public - e.g. if it's ok to notify
- // a public hub, it's ok to send a salmon
-
- if(count($slaps) && $notify_hub) {
- logger('notifier: slapdelivery: ' . $contact['name']);
- foreach($slaps as $slappy) {
- if($contact['notify']) {
- $deliver_status = slapper($owner,$contact['notify'],$slappy);
- if($deliver_status == (-1)) {
- // queue message for redelivery
- q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
- VALUES ( %d, '%s', '%s', '%s') ",
- intval($contact['id']),
- dbesc(datetime_convert()),
- dbesc(datetime_convert()),
- dbesc($slappy)
- );
+ }
+ else {
+
+ // only send salmon if public - e.g. if it's ok to notify
+ // a public hub, it's ok to send a salmon
+
+ if(count($slaps) && $notify_hub) {
+ logger('notifier: slapdelivery: ' . $contact['name']);
+ foreach($slaps as $slappy) {
+ if($contact['notify']) {
+ $deliver_status = slapper($owner,$contact['notify'],$slappy);
+ if($deliver_status == (-1)) {
+ // queue message for redelivery
+ q("INSERT INTO `queue` ( `cid`, `created`, `last`, `content`)
+ VALUES ( %d, '%s', '%s', '%s') ",
+ intval($contact['id']),
+ dbesc(datetime_convert()),
+ dbesc(datetime_convert()),
+ dbesc($slappy)
+ );
+ }
}
}
}
}
- }
- break;
- case 'mail':
- case 'dspr':
- case 'feed':
- default:
- break;
+ break;
+ case 'mail':
+ case 'dspr':
+ case 'feed':
+ default:
+ break;
+ }
}
}
@@ -353,12 +377,67 @@
continue;
$params = 'hub.mode=publish&hub.url=' . urlencode($a->get_baseurl() . '/dfrn_poll/' . $owner['nickname'] );
post_url($h,$params);
- logger('pubsub: publish: ' . $h . ' returned ' . $a->get_curl_code());
+ logger('pubsub: publish: ' . $h . ' ' . $params . ' returned ' . $a->get_curl_code());
if(count($hubs) > 1)
sleep(7); // try and avoid multiple hubs responding at precisely the same time
}
}
}
- killme();
+ if($notify_hub) {
+
+ /**
+ *
+ * If you have less than 150 dfrn friends and it's a public message,
+ * we'll just go ahead and push them out securely with dfrn/rino.
+ * If you've got more than that, you'll have to rely on PuSH delivery.
+ *
+ */
+
+ $max_allowed = ((get_config('system','maxpubdeliver') === false) ? 150 : intval(get_config('system','maxdeliver')));
+
+ /**
+ *
+ * Only get the bare essentials and go back for the full record.
+ * If you've got a lot of friends and we grab all the details at once it could exhaust memory.
+ *
+ */
+
+ $r = q("SELECT `id`, `name` FROM `contact`
+ WHERE `network` = 'dfrn' AND `uid` = %d AND `blocked` = 0 AND `pending` = 0
+ AND `rel` != %d ",
+ intval($owner['uid']),
+ intval(REL_FAN)
+ );
+
+ if((count($r)) && (($max_allowed == 0) || (count($r) < $max_allowed))) {
+
+ foreach($r as $rr) {
+
+ /* Don't deliver to folks who have already been delivered to */
+
+ if(! in_array($rr['id'], $conversants)) {
+ $n = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
+ intval($rr['id'])
+ );
+
+ if(count($n)) {
+
+ logger('notifier: dfrnpubdelivery: ' . $n[0]['name']);
+ $deliver_status = dfrn_deliver($owner,$n[0],$atom);
+ }
+ }
+ else
+ logger('notifier: dfrnpubdelivery: ignoring ' . $rr['name']);
+ }
+ }
+ }
+
+ return;
+}
+if (array_search(__file__,get_included_files())===0){
+ echo "run!";
+ notifier_run($argv,$argc);
+ killme();
+}
diff --git a/include/oembed.php b/include/oembed.php
new file mode 100644
index 000000000..37923a877
--- /dev/null
+++ b/include/oembed.php
@@ -0,0 +1,97 @@
+<?php
+function oembed_replacecb($matches){
+ $embedurl=$matches[1];
+
+ $r = q("SELECT v FROM `cache` WHERE k='%s'",
+ dbesc($embedurl));
+ if(count($r)){
+ $txt = $r[0]['v'];
+ } else {
+ $ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl);
+ $txt = fetch_url($ourl);
+ //save in cache
+ q("INSERT INTO `cache` VALUES ('%s','%s','%s')",
+ dbesc($embedurl),
+ dbesc($txt),
+ dbesc(datetime_convert()));
+ }
+ $j = json_decode($txt);
+ $ret="<span class='oembed'>";
+ switch ($j->type) {
+ case "video": {
+ if (isset($j->thumbnail_url)) {
+ $tw = (isset($j->thumbnail_width)) ? $j->thumbnail_width:200;
+ $th = (isset($j->thumbnail_height)) ? $j->thumbnail_height:180;
+ $ret = "<a href='".$embedurl."' onclick='this.innerHTML=unescape(\"".urlencode($j->html)."\").replace(/\+/g,\" \"); return false;' >";
+ $ret.= "<img width='$tw' height='$th' src='".$j->thumbnail_url."'>";
+ $ret.= "</a>";
+ } else {
+ $ret=$j->html;
+ }
+ $ret.="<br>";
+ }; break;
+ case "photo": {
+ $ret = "<img width='".$j->width."' height='".$j->height."' src='".$j->url."'>";
+ $ret.="<br>";
+ }; break;
+ case "link": {
+ //$ret = "<a href='".$embedurl."'>".$j->title."</a>";
+ }; break;
+ case "rich": {
+ // not so safe..
+ $ret = "<blockquote>".$j->html."</blockquote>";
+ }; break;
+ }
+
+ $embedlink = (isset($j->title))?$j->title:$embedurl;
+ $ret .= "<a href='$embedurl' rel='oembed'>$embedlink</a>";
+ if (isset($j->author_name)) $ret.=" by ".$j->author_name;
+ if (isset($j->provider_name)) $ret.=" on ".$j->provider_name;
+ $ret.="</span>";
+ return $ret;
+}
+
+function oembed_bbcode2html($text){
+ $stopoembed = get_config("system","no_oembed");
+ if ($stopoembed == true){
+ return preg_replace("/\[embed\](.+?)\[\/embed\]/is", "<!-- oembed $1 --><i>". t('Embedding disabled') ." : $1</i><!-- /oembed $1 -->" ,$text);
+ }
+ return preg_replace_callback("/\[embed\](.+?)\[\/embed\]/is", 'oembed_replacecb' ,$text);
+}
+
+
+function oe_build_xpath($attr, $value){
+ // http://westhoffswelt.de/blog/0036_xpath_to_select_html_by_class.html
+ return "contains( normalize-space( @$attr ), ' $value ' ) or substring( normalize-space( @$attr ), 1, string-length( '$value' ) + 1 ) = '$value ' or substring( normalize-space( @$attr ), string-length( @$attr ) - string-length( '$value' ) ) = ' $value' or @$attr = '$value'";
+}
+
+function oe_get_inner_html( $node ) {
+ $innerHTML= '';
+ $children = $node->childNodes;
+ foreach ($children as $child) {
+ $innerHTML .= $child->ownerDocument->saveXML( $child );
+ }
+ return $innerHTML;
+}
+
+/**
+ * Find <span class='oembed'>..<a href='url' rel='oembed'>..</a></span>
+ * and replace it with [embed]url[/embed]
+ */
+function oembed_html2bbcode($text) {
+ $dom = DOMDocument::loadHTML($text);
+ $xpath = new DOMXPath($dom);
+ $attr = "oembed";
+
+ $xattr = oe_build_xpath("class","oembed");
+ $entries = $xpath->query("//span[$xattr]");
+
+ $xattr = oe_build_xpath("rel","oembed");
+ foreach($entries as $e) {
+ $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
+ if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[embed]"), $e);
+ }
+ return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
+}
+
+?> \ No newline at end of file
diff --git a/include/poller.php b/include/poller.php
index 8234becbb..20c84990e 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -1,14 +1,19 @@
<?php
-
-
- require_once('boot.php');
-
- $a = new App;
-
- @include('.htconfig.php');
- require_once('dba.php');
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
+require_once("boot.php");
+
+function poller_run($argv, $argc){
+ global $a, $db;
+
+ if(is_null($a)){
+ $a = new App;
+ }
+
+ if(is_null($db)){
+ @include(".htconfig.php");
+ require_once("dba.php");
+ $db = new dba($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+ };
require_once('session.php');
require_once('datetime.php');
@@ -19,30 +24,47 @@
$a->set_baseurl(get_config('system','url'));
logger('poller: start');
-
+
// run queue delivery process in the background
$php_path = ((x($a->config,'php_path') && strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
- proc_close(proc_open("\"$php_path\" \"include/queue.php\" &", array(), $foo));
-
+ //proc_close(proc_open("\"$php_path\" \"include/queue.php\" &", array(), $foo));
+ proc_run($php_path,"include/queue.php");
+
+ // clear old cache
+ q("DELETE FROM `cache` WHERE `updated`<'%s'",
+ dbesc(datetime_convert('UTC','UTC',"now - 30 days")));
+ $manual_id = 0;
$hub_update = false;
- $force = false;
+ $force = false;
if(($argc > 1) && ($argv[1] == 'force'))
$force = true;
+ if(($argc > 1) && intval($argv[1])) {
+ $manual_id = intval($argv[1]);
+ $force = true;
+ }
+
+ $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
+
// 'stat' clause is a temporary measure until we have federation subscriptions working both directions
$contacts = q("SELECT * FROM `contact`
WHERE ( ( `network` = 'dfrn' AND ( `dfrn-id` != '' OR (`issued-id` != '' AND `duplex` = 1)))
- OR ( `network` IN ( 'stat', 'feed' ) AND `poll` != '' ))
+ OR ( `network` IN ( 'stat', 'feed' ) AND `poll` != '' ))
+ $sql_extra
AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
- if(! count($contacts))
- killme();
+ if(! count($contacts)){
+ return;
+ }
foreach($contacts as $contact) {
+ if($manual_id)
+ $contact['last-update'] = '0000-00-00 00:00:00';
+
if($contact['priority'] || $contact['subhub']) {
$hub_update = true;
@@ -61,7 +83,7 @@
$contact['priority'] = (($interval !== false) ? intval($interval) : 3);
$hub_update = false;
- if(datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day"))
+ if((datetime_convert('UTC','UTC', 'now') > datetime_convert('UTC','UTC', $t . " + 1 day")) || $force)
$hub_update = true;
}
@@ -257,7 +279,10 @@
// loop - next contact
}
- killme();
-
-
+ return;
+}
+if (array_search(__file__,get_included_files())===0){
+ poller_run($argv,$argc);
+ killme();
+}
diff --git a/include/queue.php b/include/queue.php
index 96ddfa81b..d4fc7dbd6 100644
--- a/include/queue.php
+++ b/include/queue.php
@@ -1,5 +1,5 @@
<?php
-
+require_once("boot.php");
function update_queue_time($id) {
logger('queue: requeue item ' . $id);
@@ -16,14 +16,19 @@ function remove_queue_item($id) {
);
}
- require_once("boot.php");
-
- $a = new App;
+function queue_run($argv, $argc){
+ global $a, $db;
- @include(".htconfig.php");
- require_once("dba.php");
- $db = new dba($db_host, $db_user, $db_pass, $db_data);
- unset($db_host, $db_user, $db_pass, $db_data);
+ if(is_null($a)){
+ $a = new App;
+ }
+
+ if(is_null($db)){
+ @include(".htconfig.php");
+ require_once("dba.php");
+ $db = new dba($db_host, $db_user, $db_pass, $db_data);
+ unset($db_host, $db_user, $db_pass, $db_data);
+ };
require_once("session.php");
@@ -50,9 +55,9 @@ function remove_queue_item($id) {
$r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ");
- if(! count($r))
- killme();
-
+ if(! count($r)){
+ return;
+ }
// delivery loop
require_once('include/salmon.php');
@@ -118,7 +123,11 @@ function remove_queue_item($id) {
}
}
- killme();
+ return;
- // NOTREACHED
+}
+if (array_search(__file__,get_included_files())===0){
+ queue_run($argv,$argc);
+ killme();
+}
diff --git a/include/salmon.php b/include/salmon.php
index 49384efea..8a56882ad 100644
--- a/include/salmon.php
+++ b/include/salmon.php
@@ -18,15 +18,13 @@ function salmon_key($pubkey) {
}
-function base64url_encode($s) {
+function base64url_encode($s, $strip_padding = false) {
+
$s = strtr(base64_encode($s),'+/','-_');
-/*
- * // placeholder for un-padded base64url_encode
- * // per latest salmon rev
- *
- * $s = str_replace('=','',$s);
- *
- */
+
+ if($strip_padding)
+ $s = str_replace('=','',$s);
+
return $s;
}