aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/api.php9
-rw-r--r--include/bb2diaspora.php60
-rw-r--r--include/bbcode.php55
-rw-r--r--include/conversation.php2
-rw-r--r--include/dba.php18
-rwxr-xr-xinclude/items.php267
-rw-r--r--include/markdownify/markdownify.php10
-rw-r--r--include/network.php31
-rw-r--r--include/onepoll.php223
-rw-r--r--include/text.php1
10 files changed, 187 insertions, 489 deletions
diff --git a/include/api.php b/include/api.php
index d790b4b87..7d230629b 100644
--- a/include/api.php
+++ b/include/api.php
@@ -156,6 +156,7 @@
//echo "<pre>"; var_dump($r); die();
}
}
+ header("HTTP/1.1 404 Not Found");
logger('API call not implemented: '.$a->query_string." - ".print_r($_REQUEST,true));
$r = '<status><error>not implemented</error></status>';
switch($type){
@@ -490,7 +491,8 @@
$_REQUEST['type'] = 'wall';
$_REQUEST['profile_uid'] = local_user();
$_REQUEST['api_source'] = true;
- $txt = urldecode(requestdata('status'));
+ $txt = requestdata('status');
+ //$txt = urldecode(requestdata('status'));
require_once('library/HTMLPurifier.auto.php');
require_once('include/html2bbcode.php');
@@ -554,7 +556,8 @@
}
else
- $_REQUEST['body'] = urldecode(requestdata('status'));
+ $_REQUEST['body'] = requestdata('status');
+ //$_REQUEST['body'] = urldecode(requestdata('status'));
$parent = requestdata('in_reply_to_status_id');
if(ctype_digit($parent))
@@ -1725,4 +1728,6 @@ notifications/follow
notifications/leave
blocks/exists
blocks/blocking
+lists
*/
+
diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php
index b5feacea8..b95dee8f3 100644
--- a/include/bb2diaspora.php
+++ b/include/bb2diaspora.php
@@ -190,63 +190,40 @@ function diaspora_ol($s) {
}
-function bb2diaspora($Text,$preserve_nl = false) {
+function bb2diaspora($Text,$preserve_nl = false, $fordiaspora = true) {
-//////////////////////
-// An attempt was made to convert bbcode to html and then to markdown
-// consisting of the following lines.
-// I'm undoing this as we have a lot of bbcode constructs which
-// were simply getting lost, for instance bookmark, vimeo, video, youtube, events, etc.
-// We can try this again, but need a very good test sequence to verify
-// all the major bbcode constructs that we use are getting through.
-//////////////////////
-/*
- // bbcode() will convert "[*]" into "<li>" with no closing "</li>"
- // Markdownify() is unable to handle these, as it makes each new
- // "<li>" into a deeper nested element until it crashes. So pre-format
- // the lists as Diaspora lists before sending the $Text to bbcode()
- //
- // Note that to get nested lists to work for Diaspora, we would need
- // to define the closing tag for the list elements. So nested lists
- // are going to be flattened out in Diaspora for now
+ // Re-enabling the converter again.
+ // The bbcode parser now handles youtube-links (and the other stuff) correctly.
+ // Additionally the html code is now fixed so that lists are now working.
- $endlessloop = 0;
- while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
- ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) ||
- ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false))) && (++$endlessloop < 20)) {
- $Text = preg_replace_callback("/\[list\](.*?)\[\/list\]/is", 'diaspora_ul', $Text);
- $Text = preg_replace_callback("/\[list=1\](.*?)\[\/list\]/is", 'diaspora_ol', $Text);
- $Text = preg_replace_callback("/\[list=i\](.*?)\[\/list\]/s",'diaspora_ol', $Text);
- $Text = preg_replace_callback("/\[list=I\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
- $Text = preg_replace_callback("/\[list=a\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
- $Text = preg_replace_callback("/\[list=A\](.*?)\[\/list\]/s", 'diaspora_ol', $Text);
- $Text = preg_replace_callback("/\[ul\](.*?)\[\/ul\]/is", 'diaspora_ul', $Text);
- $Text = preg_replace_callback("/\[ol\](.*?)\[\/ol\]/is", 'diaspora_ol', $Text);
- }
+ // Converting images with size parameters to simple images. Markdown doesn't know it.
+ $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $Text);
-*/
+ // the following was added on 10-January-2012 due to an inability of Diaspora's
+ // new javascript markdown processor to handle links with images as the link "text"
+ // It is not optimal and may be removed if this ability is restored in the future
+ if ($fordiaspora)
+ $Text = preg_replace("/\[url\=([^\[\]]*)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\]/ism",
+ "[url]$1[/url]\n[img]$2[/img]", $Text);
// Convert it to HTML - don't try oembed
-// $Text = bbcode($Text, $preserve_nl, false);
+ $Text = bbcode($Text, $preserve_nl, false);
// Now convert HTML to Markdown
-// $md = new Markdownify(false, false, false);
-// $Text = $md->parseString($Text);
+ $md = new Markdownify(false, false, false);
+ $Text = $md->parseString($Text);
// If the text going into bbcode() has a plain URL in it, i.e.
// with no [url] tags around it, it will come out of parseString()
// looking like: <http://url.com>, which gets removed by strip_tags().
// So take off the angle brackets of any such URL
-// $Text = preg_replace("/<http(.*?)>/is", "http$1", $Text);
+ $Text = preg_replace("/<http(.*?)>/is", "http$1", $Text);
// Remove all unconverted tags
-// $Text = strip_tags($Text);
-
-//////
-// end of bb->html->md conversion attempt
-//////
+ $Text = strip_tags($Text);
+/* Old routine
$ev = bbtoevent($Text);
@@ -422,6 +399,7 @@ function bb2diaspora($Text,$preserve_nl = false) {
$Text = preg_replace_callback('/\[(.*?)\]\((.*?)\)/ism','unescape_underscores_in_links',$Text);
+*/
// Remove any leading or trailing whitespace, as this will mess up
// the Diaspora signature verification and cause the item to disappear
diff --git a/include/bbcode.php b/include/bbcode.php
index 96f0f93c5..de848de99 100644
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -115,6 +115,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$a = get_app();
+ // Move all spaces out of the tags
+ $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
+ $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
+
// Hide all [noparse] contained bbtags by spacefying them
// POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
@@ -313,21 +317,25 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
- $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
-
- $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
-
// Try to Oembed
if ($tryoembed) {
+ $Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '<video src="$1" controls="controls" width="425" height="350"><a href="$1">$1</a></video>', $Text);
+ $Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
+
$Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
+ } else {
+ $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text);
+ $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text);
}
// html5 video and audio
- $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
-
+ if ($tryoembed)
+ $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<iframe src="$1" width="425" height="350"><a href="$1">$1</a></iframe>', $Text);
+ else
+ $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<a href="$1">$1</a>', $Text);
// Youtube extensions
if ($tryoembed) {
@@ -340,7 +348,10 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
- $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="425" height="350" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
+ if ($tryoembed)
+ $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="425" height="350" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
+ else
+ $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text);
if ($tryoembed) {
@@ -349,8 +360,12 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
}
$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
- $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
- $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="425" height="350" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
+ $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
+
+ if ($tryoembed)
+ $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="425" height="350" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
+ else
+ $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $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);
@@ -358,6 +373,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
// oembed tag
$Text = oembed_bbcode2html($Text);
+ // Avoid triple linefeeds through oembed
+ $Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
+
// If we found an event earlier, strip out all the event code and replace with a reformatted version.
// Replace the event-start section with the entire formatted event. The other bbcode is stripped.
// Summary (e.g. title) is required, earlier revisions only required description (in addition to
@@ -392,6 +410,25 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
if($saved_image)
$Text = bb_replace_images($Text, $saved_image);
+ // Clean up the HTML by loading and saving the HTML with the DOM
+ // Only do it when it has to be done - for performance reasons
+ if (!$tryoembed) {
+ $doc = new DOMDocument();
+ $doc->preserveWhiteSpace = false;
+
+ $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8");
+
+ $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
+ @$doc->loadHTML($doctype."<html><body>".$Text."</body></html>");
+
+ $Text = $doc->saveHTML();
+ $Text = str_replace(array("<html><body>", "</body></html>", $doctype), array("", "", ""), $Text);
+
+ $Text = str_replace('<br></li>','</li>', $Text);
+
+ $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
+ }
+
call_hooks('bbcode',$Text);
return $Text;
diff --git a/include/conversation.php b/include/conversation.php
index ca7d9cc4c..679606933 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -642,7 +642,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$qcomment = (($qc) ? explode("\n",$qc) : null);
}
- if(($show_comment_box) || (($show_comment_box == false) && ($override_comment_box == false) && ($item['last-child']))) {
+ if($show_comment_box) {
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
'$jsreload' => (($mode === 'display') ? $_SESSION['return_url'] : ''),
diff --git a/include/dba.php b/include/dba.php
index 71c1ba859..879d7e67e 100644
--- a/include/dba.php
+++ b/include/dba.php
@@ -71,22 +71,32 @@ class dba {
}
public function q($sql) {
+ global $a;
if((! $this->db) || (! $this->connected))
return false;
$this->error = '';
- //if (get_config("system", "db_log") != "")
- // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Start '.$sql."\n", FILE_APPEND);
+ if ($a->config["system"]["db_log"] != "")
+ $stamp1 = microtime(true);
if($this->mysqli)
$result = @$this->db->query($sql);
else
$result = @mysql_query($sql,$this->db);
- //if (get_config("system", "db_log") != "")
- // @file_put_contents(get_config("system", "db_log"), datetime_convert().':'.session_id(). ' Stop '."\n", FILE_APPEND);
+ if ($a->config["system"]["db_log"] != "") {
+ $stamp2 = microtime(true);
+ $duration = round($stamp2-$stamp1, 3);
+ if ($duration > $a->config["system"]["db_loglimit"]) {
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ @file_put_contents($a->config["system"]["db_log"], $duration."\t".
+ basename($backtrace[1]["file"])."\t".
+ $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
+ substr($sql, 0, 2000)."\n", FILE_APPEND);
+ }
+ }
if($this->mysqli) {
if($this->db->errno)
diff --git a/include/items.php b/include/items.php
index 683dbae99..21b7d9433 100755
--- a/include/items.php
+++ b/include/items.php
@@ -375,6 +375,29 @@ function limit_body_size($body) {
return $body;
}}
+function title_is_body($title, $body) {
+
+ $title = strip_tags($title);
+ $title = trim($title);
+ $title = str_replace(array("\n", "\r", "\t", " "), array("","","",""), $title);
+
+ $body = strip_tags($body);
+ $body = trim($body);
+ $body = str_replace(array("\n", "\r", "\t", " "), array("","","",""), $body);
+
+ if (strlen($title) < strlen($body))
+ $body = substr($body, 0, strlen($title));
+
+ if (($title != $body) and (substr($title, -3) == "...")) {
+ $pos = strrpos($title, "...");
+ if ($pos > 0) {
+ $title = substr($title, 0, $pos);
+ $body = substr($body, 0, $pos);
+ }
+ }
+
+ return($title == $body);
+}
@@ -401,6 +424,11 @@ function get_atom_elements($feed,$item) {
$res['body'] = unxmlify($item->get_content());
$res['plink'] = unxmlify($item->get_link(0));
+ // removing the content of the title if its identically to the body
+ // This helps with auto generated titles e.g. from tumblr
+ if (title_is_body($res["title"], $res["body"]))
+ $res['title'] = "";
+
if($res['plink'])
$base_url = implode('/', array_slice(explode('/',$res['plink']),0,3));
else
@@ -419,7 +447,7 @@ function get_atom_elements($feed,$item) {
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
- }
+ }
$rawactor = $item->get_item_tags(NAMESPACE_ACTIVITY, 'actor');
@@ -451,7 +479,7 @@ function get_atom_elements($feed,$item) {
$res['author-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
- }
+ }
$rawactor = $feed->get_feed_tags(NAMESPACE_ACTIVITY, 'subject');
@@ -533,24 +561,12 @@ function get_atom_elements($feed,$item) {
$res['body'] = escape_tags($res['body']);
}
- // this tag is obsolete but we keep it for really old sites
-
- $allow = $item->get_item_tags(NAMESPACE_DFRN,'comment-allow');
- if($allow && $allow[0]['data'] == 1)
- $res['last-child'] = 1;
- else
- $res['last-child'] = 0;
-
$private = $item->get_item_tags(NAMESPACE_DFRN,'private');
if($private && intval($private[0]['data']) > 0)
$res['private'] = intval($private[0]['data']);
else
$res['private'] = 0;
- $extid = $item->get_item_tags(NAMESPACE_DFRN,'extid');
- if($extid && $extid[0]['data'])
- $res['extid'] = $extid[0]['data'];
-
$rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location');
if($rawlocation)
$res['location'] = unxmlify($rawlocation[0]['data']);
@@ -601,7 +617,7 @@ function get_atom_elements($feed,$item) {
foreach($base as $link) {
if(!x($res, 'owner-avatar') || !$res['owner-avatar']) {
- if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
+ if($link['attribs']['']['rel'] === 'photo' || $link['attribs']['']['rel'] === 'avatar')
$res['owner-avatar'] = unxmlify($link['attribs']['']['href']);
}
}
@@ -755,10 +771,41 @@ function get_atom_elements($feed,$item) {
$res['target'] .= '</target>' . "\n";
}
+ // This is some experimental stuff. By now retweets are shown with "RT:"
+ // But: There is data so that the message could be shown similar to native retweets
+ // There is some better way to parse this array - but it didn't worked for me.
+ $child = $item->feed->data["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["feed"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["entry"][0]["child"]["http://activitystrea.ms/spec/1.0/"][object][0]["child"];
+ if (is_array($child)) {
+ $message = $child["http://activitystrea.ms/spec/1.0/"]["object"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10]["content"][0]["data"];
+ $author = $child[SIMPLEPIE_NAMESPACE_ATOM_10]["author"][0]["child"][SIMPLEPIE_NAMESPACE_ATOM_10];
+ $uri = $author["uri"][0]["data"];
+ $name = $author["name"][0]["data"];
+ $avatar = @array_shift($author["link"][2]["attribs"]);
+ $avatar = $avatar["href"];
+
+ if (($name != "") and ($uri != "") and ($avatar != "") and ($message != "")) {
+ $res["owner-name"] = $res["author-name"];
+ $res["owner-link"] = $res["author-link"];
+ $res["owner-avatar"] = $res["author-avatar"];
+
+ $res["author-name"] = $name;
+ $res["author-link"] = $uri;
+ $res["author-avatar"] = $avatar;
+
+ $res["body"] = html2bbcode($message);
+ }
+ }
+
$arr = array('feed' => $feed, 'item' => $item, 'result' => $res);
call_hooks('parse_atom', $arr);
+ //if (($res["title"] != "") or (strpos($res["body"], "RT @") > 0)) {
+ //if (strpos($res["body"], "RT @") !== false) {
+ // $debugfile = tempnam("/home/ike/log", "item-res2-");
+ // file_put_contents($debugfile, serialize($arr));
+ //}
+
return $res;
}
@@ -827,7 +874,6 @@ function item_store($arr,$force_parent = false) {
$arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
$arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
- $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : '');
$arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
$arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
$arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
@@ -842,7 +888,6 @@ function item_store($arr,$force_parent = false) {
$arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
$arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
$arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
- $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
$arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
$arr['deleted'] = 0;
$arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
@@ -861,7 +906,6 @@ 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['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
- $arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid());
if($arr['parent-uri'] === $arr['uri']) {
$parent_id = 0;
@@ -1067,20 +1111,6 @@ function item_store($arr,$force_parent = false) {
);
}
-
-
- /**
- * If this is now the last-child, force all _other_ children of this parent to *not* be last-child
- */
-
- if($arr['last-child']) {
- $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d AND `id` != %d",
- dbesc($arr['uri']),
- intval($arr['uid']),
- intval($current_post)
- );
- }
-
tag_deliver($arr['uid'],$current_post);
return $current_post;
@@ -1709,25 +1739,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
dbesc($uri),
intval($importer['uid'])
);
- if($item['last-child']) {
- // ensure that last-child is set in case the comment that had it just got wiped.
- q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
- dbesc(datetime_convert()),
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- // who is the last child now?
- $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `moderated` = 0 AND `uid` = %d
- ORDER BY `created` DESC LIMIT 1",
- dbesc($item['parent-uri']),
- intval($importer['uid'])
- );
- if(count($r)) {
- q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
- intval($r[0]['id'])
- );
- }
- }
}
}
}
@@ -1736,7 +1747,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
// Now process the feed
- if($feed->get_item_quantity()) {
+ if($feed->get_item_quantity()) {
logger('consume_feed: feed item count = ' . $feed->get_item_quantity());
@@ -1749,7 +1760,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
foreach($items as $item) {
- $is_reply = false;
+ $is_reply = false;
$item_id = $item->get_id();
$rawthread = $item->get_item_tags( NAMESPACE_THREAD,'in-reply-to');
if(isset($rawthread[0]['attribs']['']['ref'])) {
@@ -1763,11 +1774,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
continue;
// Have we seen it? If not, import it.
-
+
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
-
if((! x($datarray,'author-name')) && ($contact['network'] != NETWORK_DFRN))
$datarray['author-name'] = $contact['name'];
if((! x($datarray,'author-link')) && ($contact['network'] != NETWORK_DFRN))
@@ -1780,22 +1790,8 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
continue;
}
- $force_parent = false;
- if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
- if($contact['network'] === NETWORK_OSTATUS)
- $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",
- dbesc(datetime_convert()),
- dbesc($parent_uri),
- intval($importer['uid'])
- );
- $datarray['last-child'] = 1;
- }
-
- $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
);
@@ -1818,30 +1814,10 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
);
}
- // update last-child if it changes
-
- $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
- if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
- $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(datetime_convert()),
- dbesc($parent_uri),
- intval($importer['uid'])
- );
- $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- intval($allow[0]['data']),
- dbesc(datetime_convert()),
- dbesc($item_id),
- intval($importer['uid'])
- );
- }
continue;
}
- if(($contact['network'] === 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'];
@@ -1934,14 +1910,7 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
}
}
- if($contact['network'] === NETWORK_OSTATUS || stristr($contact['url'],'twitter.com')) {
- if(strlen($datarray['title']))
- unset($datarray['title']);
- $datarray['last-child'] = 1;
- }
-
-
- $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['uid'])
);
@@ -1964,17 +1933,6 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
);
}
- // update last-child if it changes
-
- $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
- if($allow && $allow[0]['data'] != $r[0]['last-child']) {
- $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- intval($allow[0]['data']),
- dbesc(datetime_convert()),
- dbesc($item_id),
- intval($importer['uid'])
- );
- }
continue;
}
@@ -2003,21 +1961,11 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0)
return;
- if(($contact['network'] === NETWORK_FEED) || (! strlen($contact['notify']))) {
- // one way feed - no remote comment ability
- $datarray['last-child'] = 0;
- }
- if($contact['network'] === NETWORK_FEED)
- $datarray['private'] = 2;
-
// This is my contact on another system, but it's really me.
// Turn this into a wall post.
if($contact['remote_self']) {
$datarray['wall'] = 1;
- if($contact['network'] === NETWORK_FEED) {
- $datarray['private'] = 0;
- }
}
$datarray['parent-uri'] = $item_id;
@@ -2408,25 +2356,7 @@ function local_delivery($importer,$data) {
dbesc($uri),
intval($importer['importer_uid'])
);
- if($item['last-child']) {
- // ensure that last-child is set in case the comment that had it just got wiped.
- q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
- dbesc(datetime_convert()),
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- // who is the last child now?
- $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d
- ORDER BY `created` DESC LIMIT 1",
- dbesc($item['parent-uri']),
- intval($importer['importer_uid'])
- );
- if(count($r)) {
- q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
- intval($r[0]['id'])
- );
- }
- }
+
// if this is a relayed delete, propagate it to other recipients
if($is_a_remote_delete)
@@ -2499,7 +2429,7 @@ function local_delivery($importer,$data) {
$datarray = get_atom_elements($feed,$item);
- $r = q("SELECT `id`, `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `id`, `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['importer_uid'])
);
@@ -2559,7 +2489,7 @@ function local_delivery($importer,$data) {
$is_like = true;
$datarray['type'] = 'activity';
$datarray['gravity'] = GRAVITY_LIKE;
- $datarray['last-child'] = 0;
+
// only one like or dislike per person
$r = q("select id from item where uid = %d and `contact-id` = %d and verb = '%s' and (`thr-parent` = '%s' or `parent-uri` = '%s') and deleted = 0 limit 1",
intval($datarray['uid']),
@@ -2631,13 +2561,13 @@ function local_delivery($importer,$data) {
$parent = $r[0]['parent'];
if(! $is_like) {
- $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
+ $r1 = q("UPDATE `item` SET `changed` = '%s' WHERE `uid` = %d AND `parent` = %d",
dbesc(datetime_convert()),
intval($importer['importer_uid']),
intval($r[0]['parent'])
);
- $r2 = q("UPDATE `item` SET `last-child` = 1, `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
+ $r2 = q("UPDATE `item` SET `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
dbesc(datetime_convert()),
intval($importer['importer_uid']),
intval($posted_id)
@@ -2685,7 +2615,7 @@ function local_delivery($importer,$data) {
$item_id = $item->get_id();
$datarray = get_atom_elements($feed,$item);
- $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['importer_uid'])
);
@@ -2708,22 +2638,6 @@ function local_delivery($importer,$data) {
);
}
- // update last-child if it changes
-
- $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
- if(($allow) && ($allow[0]['data'] != $r[0]['last-child'])) {
- $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc(datetime_convert()),
- dbesc($parent_uri),
- intval($importer['importer_uid'])
- );
- $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- intval($allow[0]['data']),
- dbesc(datetime_convert()),
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
- }
continue;
}
@@ -2857,7 +2771,7 @@ function local_delivery($importer,$data) {
}
}
- $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ $r = q("SELECT `uid`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
dbesc($item_id),
intval($importer['importer_uid'])
);
@@ -2880,17 +2794,6 @@ function local_delivery($importer,$data) {
);
}
- // update last-child if it changes
-
- $allow = $item->get_item_tags( NAMESPACE_DFRN, 'comment-allow');
- if($allow && $allow[0]['data'] != $r[0]['last-child']) {
- $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
- intval($allow[0]['data']),
- dbesc(datetime_convert()),
- dbesc($item_id),
- intval($importer['importer_uid'])
- );
- }
continue;
}
@@ -3141,8 +3044,6 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
$o .= '<dfrn:env>' . base64url_encode($body, true) . '</dfrn:env>' . "\r\n";
$o .= '<content type="' . $type . '" >' . xmlify((($type === 'html') ? bbcode($body) : $body)) . '</content>' . "\r\n";
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id']) . '" />' . "\r\n";
- if($comment)
- $o .= '<dfrn:comment-allow>' . intval($item['last-child']) . '</dfrn:comment-allow>' . "\r\n";
if($item['location']) {
$o .= '<dfrn:location>' . xmlify($item['location']) . '</dfrn:location>' . "\r\n";
@@ -3155,8 +3056,6 @@ function atom_entry($item,$type,$author,$owner,$comment = false,$cid = 0) {
if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid']))
$o .= '<dfrn:private>' . (($item['private']) ? $item['private'] : 1) . '</dfrn:private>' . "\r\n";
- if($item['extid'])
- $o .= '<dfrn:extid>' . xmlify($item['extid']) . '</dfrn:extid>' . "\r\n";
if($item['app'])
$o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n";
@@ -3552,25 +3451,7 @@ function drop_item($id,$interactive = true) {
);
// ignore the result
}
- else {
- // ensure that last-child is set in case the comment that had it just got wiped.
- q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
- dbesc(datetime_convert()),
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- // who is the last child now?
- $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d ORDER BY `edited` DESC LIMIT 1",
- dbesc($item['parent-uri']),
- intval($item['uid'])
- );
- if(count($r)) {
- q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
- intval($r[0]['id'])
- );
- }
- }
$drop_id = intval($item['id']);
// send the notification upstream/downstream as the case may be
diff --git a/include/markdownify/markdownify.php b/include/markdownify/markdownify.php
index 43730cb77..7bbf1cbbe 100644
--- a/include/markdownify/markdownify.php
+++ b/include/markdownify/markdownify.php
@@ -735,6 +735,13 @@ class Markdownify {
$this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']);
}
+// ![Alt text](/path/to/img.jpg "Optional title")
+ if ($this->parser->tagAttributes['title'] != "")
+ $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].'"'.$this->parser->tagAttributes['title'].'")', true);
+ else
+ $this->out('!['.$this->parser->tagAttributes['alt'].']('.$this->parser->tagAttributes['src'].')', true);
+
+/*
# [This link][id]
$link_id = false;
if (!empty($this->stack['a'])) {
@@ -759,6 +766,7 @@ class Markdownify {
}
$this->out('!['.$this->parser->tagAttributes['alt'].']['.$link_id.']', true);
+*/
}
/**
* handle <code> tags
@@ -1181,4 +1189,4 @@ class Markdownify {
function parent() {
return end($this->parser->openTags);
}
-} \ No newline at end of file
+}
diff --git a/include/network.php b/include/network.php
index 221906296..54e7e023d 100644
--- a/include/network.php
+++ b/include/network.php
@@ -14,15 +14,16 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
return false;
@curl_setopt($ch, CURLOPT_HEADER, true);
-
+
if (!is_null($accept_content)){
curl_setopt($ch,CURLOPT_HTTPHEADER, array (
"Accept: " . $accept_content
));
}
-
+
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- @curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
+ //@curl_setopt($ch, CURLOPT_USERAGENT, "Friendica");
+ @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; Friendica)");
if(intval($timeout)) {
@@ -59,7 +60,6 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
$base = $s;
$curl_info = @curl_getinfo($ch);
$http_code = $curl_info['http_code'];
-
// logger('fetch_url:' . $http_code . ' data: ' . $s);
$header = '';
@@ -73,24 +73,22 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_
}
if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) {
- $matches = array();
- preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
- $newurl = trim(array_pop($matches));
+ $matches = array();
+ preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
+ $newurl = trim(array_pop($matches));
if(strpos($newurl,'/') === 0)
$newurl = $url . $newurl;
- $url_parsed = @parse_url($newurl);
- if (isset($url_parsed)) {
- $redirects++;
- return fetch_url($newurl,$binary,$redirects,$timeout);
- }
- }
+ $url_parsed = @parse_url($newurl);
+ if (isset($url_parsed)) {
+ $redirects++;
+ return fetch_url($newurl,$binary,$redirects,$timeout);
+ }
+ }
$a->set_curl_code($http_code);
$body = substr($s,strlen($header));
-
$a->set_curl_headers($header);
-
@curl_close($ch);
return($body);
}}
@@ -798,6 +796,9 @@ function scale_external_images($s, $include_link = true, $scale_replace = false)
$a = get_app();
+ // Picture addresses can contain special characters
+ $s = htmlspecialchars_decode($s);
+
$matches = null;
$c = preg_match_all('/\[img\](.*?)\[\/img\]/ism',$s,$matches,PREG_SET_ORDER);
if($c) {
diff --git a/include/onepoll.php b/include/onepoll.php
index 09e7bb763..4ba2df515 100644
--- a/include/onepoll.php
+++ b/include/onepoll.php
@@ -54,19 +54,14 @@ function onepoll_run($argv, $argc){
$d = datetime_convert();
// Only poll from those with suitable relationships,
- // and which have a polling address and ignore Diaspora since
- // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
$contacts = q("SELECT `contact`.* FROM `contact`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
- AND NOT `network` IN ( '%s', '%s' )
AND `contact`.`id` = %d
AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
AND `contact`.`archive` = 0 LIMIT 1",
intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND),
- dbesc(NETWORK_DIASPORA),
- dbesc(NETWORK_FACEBOOK),
intval($contact_id)
);
@@ -228,224 +223,6 @@ function onepoll_run($argv, $argc){
$xml = post_url($contact['poll'],$postvars);
}
- elseif(($contact['network'] === NETWORK_OSTATUS)
- || ($contact['network'] === NETWORK_DIASPORA)
- || ($contact['network'] === NETWORK_FEED) ) {
-
- // Upgrading DB fields from an older Friendica version
- // Will only do this once per notify-enabled OStatus contact
- // or if relationship changes
-
- $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0);
-
- if($stat_writeable != $contact['writable']) {
- q("UPDATE `contact` SET `writable` = %d WHERE `id` = %d LIMIT 1",
- intval($stat_writeable),
- intval($contact['id'])
- );
- }
-
- // Are we allowed to import from this person?
-
- if($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked'] || $contact['readonly'])
- return;
-
- $xml = fetch_url($contact['poll']);
- }
- elseif($contact['network'] === NETWORK_MAIL || $contact['network'] === NETWORK_MAIL2) {
-
- logger("onepoll: mail: Fetching", LOGGER_DEBUG);
-
- $mail_disabled = ((function_exists('imap_open') && (! get_config('system','imap_disabled'))) ? 0 : 1);
- if($mail_disabled)
- return;
-
- logger("onepoll: Mail: Enabled", LOGGER_DEBUG);
-
- $mbox = null;
- $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1",
- intval($importer_uid)
- );
- $mailconf = q("SELECT * FROM `mailacct` WHERE `server` != '' AND `uid` = %d LIMIT 1",
- intval($importer_uid)
- );
- if(count($x) && count($mailconf)) {
- $mailbox = construct_mailbox_name($mailconf[0]);
- $password = '';
- openssl_private_decrypt(hex2bin($mailconf[0]['pass']),$password,$x[0]['prvkey']);
- $mbox = email_connect($mailbox,$mailconf[0]['user'],$password);
- unset($password);
- logger("Mail: Connect");
- if($mbox) {
- q("UPDATE `mailacct` SET `last_check` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
- dbesc(datetime_convert()),
- intval($mailconf[0]['id']),
- intval($importer_uid)
- );
- }
- }
- if($mbox) {
-
- $msgs = email_poll($mbox,$contact['addr']);
-
- if(count($msgs)) {
- logger("Mail: Parsing ".count($msgs)." mails.", LOGGER_DEBUG);
-
- foreach($msgs as $msg_uid) {
- logger("Mail: Parsing mail ".$msg_uid, LOGGER_DATA);
-
- $datarray = array();
- $meta = email_msg_meta($mbox,$msg_uid);
- $headers = email_msg_headers($mbox,$msg_uid);
-
- // look for a 'references' header and try and match with a parent item we have locally.
-
- $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
- $datarray['uri'] = msgid2iri(trim($meta->message_id,'<>'));
-
- if($raw_refs) {
- $refs_arr = explode(' ', $raw_refs);
- if(count($refs_arr)) {
- for($x = 0; $x < count($refs_arr); $x ++)
- $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
- }
- $qstr = implode(',',$refs_arr);
- $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
- intval($importer_uid)
- );
- if(count($r))
- $datarray['parent-uri'] = $r[0]['uri'];
- }
-
-
- if(! x($datarray,'parent-uri'))
- $datarray['parent-uri'] = $datarray['uri'];
-
- // Have we seen it before?
- $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
- intval($importer_uid),
- dbesc($datarray['uri'])
- );
-
- if(count($r)) {
-// logger("Mail: Seen before ".$msg_uid);
- if($meta->deleted && ! $r[0]['deleted']) {
- q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
- dbesc(datetime_convert()),
- intval($r[0]['id'])
- );
- }
- switch ($mailconf[0]['action']) {
- case 0:
- break;
- case 1:
- logger("Mail: Deleting ".$msg_uid);
- imap_delete($mbox, $msg_uid, FT_UID);
- break;
- case 2:
- logger("Mail: Mark as seen ".$msg_uid);
- imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
- break;
- case 3:
- logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
- imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
- if ($mailconf[0]['movetofolder'] != "")
- imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
- break;
- }
- continue;
- }
-
- // Decoding the header
- $subject = imap_mime_header_decode($meta->subject);
- $datarray['title'] = "";
- foreach($subject as $subpart)
- if ($subpart->charset != "default")
- $datarray['title'] .= iconv($subpart->charset, 'UTF-8//IGNORE', $subpart->text);
- else
- $datarray['title'] .= $subpart->text;
-
- $datarray['title'] = notags(trim($datarray['title']));
-
- //$datarray['title'] = notags(trim($meta->subject));
- $datarray['created'] = datetime_convert('UTC','UTC',$meta->date);
-
- // Is it reply?
- $reply = ((substr(strtolower($datarray['title']), 0, 3) == "re:") or
- (substr(strtolower($datarray['title']), 0, 3) == "re-") or
- (raw_refs != ""));
-
- $r = email_get_msg($mbox,$msg_uid, $reply);
- if(! $r) {
- logger("Mail: can't fetch msg ".$msg_uid);
- continue;
- }
- $datarray['body'] = escape_tags($r['body']);
-
- logger("Mail: Importing ".$msg_uid);
-
- // some mailing lists have the original author as 'from' - add this sender info to msg body.
- // todo: adding a gravatar for the original author would be cool
-
- if(! stristr($meta->from,$contact['addr'])) {
- $from = imap_mime_header_decode($meta->from);
- $fromdecoded = "";
- foreach($from as $frompart)
- if ($frompart->charset != "default")
- $fromdecoded .= iconv($frompart->charset, 'UTF-8//IGNORE', $frompart->text);
- else
- $fromdecoded .= $frompart->text;
-
- $datarray['body'] = "[b]".t('From: ') . escape_tags($fromdecoded) . "[/b]\n\n" . $datarray['body'];
- }
-
- $datarray['uid'] = $importer_uid;
- $datarray['contact-id'] = $contact['id'];
- if($datarray['parent-uri'] === $datarray['uri'])
- $datarray['private'] = 1;
- if(($contact['network'] === NETWORK_MAIL) && (! get_pconfig($importer_uid,'system','allow_public_email_replies'))) {
- $datarray['private'] = 1;
- $datarray['allow_cid'] = '<' . $contact['id'] . '>';
- }
- $datarray['author-name'] = $contact['name'];
- $datarray['author-link'] = 'mailbox';
- $datarray['author-avatar'] = $contact['photo'];
-
- $stored_item = item_store($datarray);
- q("UPDATE `item` SET `last-child` = 0 WHERE `parent-uri` = '%s' AND `uid` = %d",
- dbesc($datarray['parent-uri']),
- intval($importer_uid)
- );
- q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
- intval($stored_item)
- );
- switch ($mailconf[0]['action']) {
- case 0:
- break;
- case 1:
- logger("Mail: Deleting ".$msg_uid);
- imap_delete($mbox, $msg_uid, FT_UID);
- break;
- case 2:
- logger("Mail: Mark as seen ".$msg_uid);
- imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
- break;
- case 3:
- logger("Mail: Moving ".$msg_uid." to ".$mailconf[0]['movetofolder']);
- imap_setflag_full($mbox, $msg_uid, "\\Seen", ST_UID);
- if ($mailconf[0]['movetofolder'] != "")
- imap_mail_move($mbox, $msg_uid, $mailconf[0]['movetofolder'], FT_UID);
- break;
- }
- }
- }
- imap_close($mbox);
- }
- }
- elseif($contact['network'] === NETWORK_FACEBOOK) {
- // This is picked up by the Facebook plugin on a cron hook.
- // Ignored here.
- }
if($xml) {
logger('poller: received xml : ' . $xml, LOGGER_DATA);
diff --git a/include/text.php b/include/text.php
index d7fc5808f..fe36e1319 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1617,6 +1617,7 @@ function undo_post_tagging($s) {
function fix_mce_lf($s) {
$s = str_replace("\r\n","\n",$s);
+ $s = str_replace("\n\n","\n",$s);
return $s;
}