2010-07-18 09:02:55 -04:00
|
|
|
|
<?php
|
2016-11-23 19:11:22 -05:00
|
|
|
|
/**
|
|
|
|
|
* @file include/items.php
|
|
|
|
|
*/
|
2018-01-24 21:08:45 -05:00
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
use Friendica\BaseObject;
|
2017-12-04 09:04:36 -05:00
|
|
|
|
use Friendica\Content\Feature;
|
2018-01-17 13:42:40 -05:00
|
|
|
|
use Friendica\Core\Addon;
|
2017-07-23 01:51:55 -04:00
|
|
|
|
use Friendica\Core\Config;
|
2018-01-21 13:33:59 -05:00
|
|
|
|
use Friendica\Core\L10n;
|
2018-10-29 17:20:46 -04:00
|
|
|
|
use Friendica\Core\Logger;
|
2017-11-06 21:22:52 -05:00
|
|
|
|
use Friendica\Core\PConfig;
|
2018-08-11 16:40:44 -04:00
|
|
|
|
use Friendica\Core\Protocol;
|
2018-10-31 10:35:50 -04:00
|
|
|
|
use Friendica\Core\Renderer;
|
2017-11-15 10:53:16 -05:00
|
|
|
|
use Friendica\Core\System;
|
2018-07-20 08:19:26 -04:00
|
|
|
|
use Friendica\Database\DBA;
|
2018-01-24 21:08:45 -05:00
|
|
|
|
use Friendica\Model\Item;
|
2017-11-07 22:57:46 -05:00
|
|
|
|
use Friendica\Protocol\DFRN;
|
2017-12-13 02:02:52 -05:00
|
|
|
|
use Friendica\Protocol\Feed;
|
2018-01-24 21:08:45 -05:00
|
|
|
|
use Friendica\Protocol\OStatus;
|
2018-01-26 21:38:34 -05:00
|
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
|
use Friendica\Util\Network;
|
2018-01-04 12:03:15 -05:00
|
|
|
|
use Friendica\Util\ParseUrl;
|
2018-11-08 08:45:46 -05:00
|
|
|
|
use Friendica\Util\Strings;
|
2018-02-03 12:25:58 -05:00
|
|
|
|
use Friendica\Util\Temporal;
|
2016-11-23 19:11:22 -05:00
|
|
|
|
|
2017-04-08 13:30:35 -04:00
|
|
|
|
require_once 'include/text.php';
|
|
|
|
|
require_once 'mod/share.php';
|
|
|
|
|
require_once 'include/enotify.php';
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function add_page_info_data(array $data, $no_photos = false)
|
|
|
|
|
{
|
2018-01-17 13:42:40 -05:00
|
|
|
|
Addon::callHooks('page_info_data', $data);
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2018-08-24 07:09:58 -04:00
|
|
|
|
if (empty($data['type'])) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 04:52:53 -04:00
|
|
|
|
// It maybe is a rich content, but if it does have everything that a link has,
|
|
|
|
|
// then treat it that way
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (($data["type"] == "rich") && is_string($data["title"]) &&
|
2018-05-17 01:35:58 -04:00
|
|
|
|
is_string($data["text"]) && !empty($data["images"])) {
|
2014-04-04 04:52:53 -04:00
|
|
|
|
$data["type"] = "link";
|
2016-11-13 14:09:47 -05:00
|
|
|
|
}
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
$data["title"] = defaults($data, "title", "");
|
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if ((($data["type"] != "link") && ($data["type"] != "video") && ($data["type"] != "photo")) || ($data["title"] == $data["url"])) {
|
2016-11-13 03:50:01 -05:00
|
|
|
|
return "";
|
2016-11-12 15:23:00 -05:00
|
|
|
|
}
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if ($no_photos && ($data["type"] == "photo")) {
|
2016-11-13 14:09:47 -05:00
|
|
|
|
return "";
|
|
|
|
|
}
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2016-04-17 14:43:41 -04:00
|
|
|
|
// Escape some bad characters
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$data["url"] = str_replace(["[", "]"], ["[", "]"], htmlentities($data["url"], ENT_QUOTES, 'UTF-8', false));
|
|
|
|
|
$data["title"] = str_replace(["[", "]"], ["[", "]"], htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false));
|
2016-04-17 14:43:41 -04:00
|
|
|
|
|
|
|
|
|
$text = "[attachment type='".$data["type"]."'";
|
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
if (empty($data["text"])) {
|
2016-11-12 15:23:00 -05:00
|
|
|
|
$data["text"] = $data["title"];
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
if (empty($data["text"])) {
|
2016-11-12 15:23:00 -05:00
|
|
|
|
$data["text"] = $data["url"];
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
if (!empty($data["url"])) {
|
2016-04-17 14:43:41 -04:00
|
|
|
|
$text .= " url='".$data["url"]."'";
|
2016-11-13 14:09:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
if (!empty($data["title"])) {
|
2016-04-17 14:43:41 -04:00
|
|
|
|
$text .= " title='".$data["title"]."'";
|
2016-11-13 14:09:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 03:48:44 -04:00
|
|
|
|
// Only embedd a picture link when it seems to be a valid picture ("width" is set)
|
|
|
|
|
if (!empty($data["images"]) && !empty($data["images"][0]["width"])) {
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$preview = str_replace(["[", "]"], ["[", "]"], htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
|
2016-04-17 14:43:41 -04:00
|
|
|
|
// if the preview picture is larger than 500 pixels then show it in a larger mode
|
|
|
|
|
// But only, if the picture isn't higher than large (To prevent huge posts)
|
2017-11-25 05:07:49 -05:00
|
|
|
|
if (!Config::get('system', 'always_show_preview') && ($data["images"][0]["width"] >= 500)
|
|
|
|
|
&& ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
|
2016-04-17 14:43:41 -04:00
|
|
|
|
$text .= " image='".$preview."'";
|
2016-11-13 14:09:47 -05:00
|
|
|
|
} else {
|
2016-04-17 14:43:41 -04:00
|
|
|
|
$text .= " preview='".$preview."'";
|
2016-11-13 14:09:47 -05:00
|
|
|
|
}
|
2014-06-15 17:33:25 -04:00
|
|
|
|
}
|
2016-11-13 14:09:47 -05:00
|
|
|
|
|
2016-04-17 14:43:41 -04:00
|
|
|
|
$text .= "]".$data["text"]."[/attachment]";
|
2014-04-04 04:52:53 -04:00
|
|
|
|
|
2014-10-03 06:18:33 -04:00
|
|
|
|
$hashtags = "";
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (isset($data["keywords"]) && count($data["keywords"])) {
|
2014-10-03 07:02:15 -04:00
|
|
|
|
$hashtags = "\n";
|
2018-07-30 21:02:34 -04:00
|
|
|
|
foreach ($data["keywords"] as $keyword) {
|
2018-01-20 18:52:54 -05:00
|
|
|
|
/// @TODO make a positive list of allowed characters
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$hashtag = str_replace([" ", "+", "/", ".", "#", "'", "’", "`", "(", ")", "„", "“"],
|
|
|
|
|
["", "", "", "", "", "", "", "", "", "", "", ""], $keyword);
|
2017-08-26 03:32:10 -04:00
|
|
|
|
$hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url] ";
|
2014-10-03 07:02:15 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-03 06:18:33 -04:00
|
|
|
|
|
2016-04-17 14:43:41 -04:00
|
|
|
|
return "\n".$text.$hashtags;
|
2014-04-04 04:52:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function query_page_info($url, $photo = "", $keywords = false, $keyword_blacklist = "")
|
|
|
|
|
{
|
2016-11-23 19:11:22 -05:00
|
|
|
|
$data = ParseUrl::getSiteinfoCached($url, true);
|
2014-10-20 02:03:47 -04:00
|
|
|
|
|
2017-04-08 13:30:35 -04:00
|
|
|
|
if ($photo != "") {
|
2014-12-17 15:57:38 -05:00
|
|
|
|
$data["images"][0]["src"] = $photo;
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2014-12-17 15:57:38 -05:00
|
|
|
|
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log('fetch page info for ' . $url . ' ' . print_r($data, true), Logger::DEBUG);
|
2014-10-20 02:03:47 -04:00
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (!$keywords && isset($data["keywords"])) {
|
2014-10-20 02:03:47 -04:00
|
|
|
|
unset($data["keywords"]);
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2014-10-20 02:03:47 -04:00
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (($keyword_blacklist != "") && isset($data["keywords"])) {
|
2017-04-08 13:30:35 -04:00
|
|
|
|
$list = explode(", ", $keyword_blacklist);
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
|
|
|
|
foreach ($list as $keyword) {
|
2014-10-29 19:24:23 -04:00
|
|
|
|
$keyword = trim($keyword);
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
2014-10-29 19:24:23 -04:00
|
|
|
|
$index = array_search($keyword, $data["keywords"]);
|
2017-04-08 13:30:35 -04:00
|
|
|
|
if ($index !== false) {
|
2014-10-29 19:24:23 -04:00
|
|
|
|
unset($data["keywords"][$index]);
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2014-10-29 19:24:23 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
return $data;
|
2015-01-20 16:54:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blacklist = "")
|
|
|
|
|
{
|
2018-02-11 21:56:20 -05:00
|
|
|
|
$data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
|
2015-01-20 16:54:25 -05:00
|
|
|
|
|
|
|
|
|
$tags = "";
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (isset($data["keywords"]) && count($data["keywords"])) {
|
2018-07-30 21:02:34 -04:00
|
|
|
|
foreach ($data["keywords"] as $keyword) {
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$hashtag = str_replace([" ", "+", "/", ".", "#", "'"],
|
|
|
|
|
["", "", "", "", "", ""], $keyword);
|
2015-01-20 16:54:25 -05:00
|
|
|
|
|
2017-04-08 13:30:35 -04:00
|
|
|
|
if ($tags != "") {
|
|
|
|
|
$tags .= ", ";
|
|
|
|
|
}
|
2015-01-20 16:54:25 -05:00
|
|
|
|
|
2017-08-26 03:32:10 -04:00
|
|
|
|
$tags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
|
2015-01-20 16:54:25 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
return $tags;
|
2015-01-20 16:54:25 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "")
|
|
|
|
|
{
|
2018-02-11 21:56:20 -05:00
|
|
|
|
$data = query_page_info($url, $photo, $keywords, $keyword_blacklist);
|
2015-01-20 16:54:25 -05:00
|
|
|
|
|
2018-07-30 22:24:32 -04:00
|
|
|
|
$text = '';
|
|
|
|
|
|
|
|
|
|
if (is_array($data)) {
|
|
|
|
|
$text = add_page_info_data($data, $no_photos);
|
|
|
|
|
}
|
2014-10-20 02:03:47 -04:00
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
return $text;
|
2014-10-20 02:03:47 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function add_page_info_to_body($body, $texturl = false, $no_photos = false)
|
|
|
|
|
{
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log('add_page_info_to_body: fetch page info for body ' . $body, Logger::DEBUG);
|
2014-04-04 04:52:53 -04:00
|
|
|
|
|
2014-06-15 17:33:25 -04:00
|
|
|
|
$URLSearchString = "^\[\]";
|
2014-04-04 04:52:53 -04:00
|
|
|
|
|
2016-12-12 01:46:02 -05:00
|
|
|
|
// Fix for Mastodon where the mentions are in a different format
|
|
|
|
|
$body = preg_replace("/\[url\=([$URLSearchString]*)\]([#!@])(.*?)\[\/url\]/ism",
|
2017-04-14 10:59:51 -04:00
|
|
|
|
'$2[url=$1]$3[/url]', $body);
|
2016-12-12 01:46:02 -05:00
|
|
|
|
|
2014-06-15 17:33:25 -04:00
|
|
|
|
// Adding these spaces is a quick hack due to my problems with regular expressions :)
|
2017-04-14 10:59:51 -04:00
|
|
|
|
preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " " . $body, $matches);
|
2014-04-04 04:52:53 -04:00
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
if (!$matches) {
|
|
|
|
|
preg_match("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " " . $body, $matches);
|
|
|
|
|
}
|
2014-04-04 04:52:53 -04:00
|
|
|
|
|
|
|
|
|
// Convert urls without bbcode elements
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (!$matches && $texturl) {
|
2014-04-04 04:52:53 -04:00
|
|
|
|
preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2014-04-04 04:52:53 -04:00
|
|
|
|
// Yeah, a hack. I really hate regular expressions :)
|
2017-04-14 10:59:51 -04:00
|
|
|
|
if ($matches) {
|
2014-06-15 17:33:25 -04:00
|
|
|
|
$matches[1] = $matches[2];
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2014-01-05 10:10:02 -05:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
if ($matches) {
|
2014-07-27 10:10:09 -04:00
|
|
|
|
$footer = add_page_info($matches[1], $no_photos);
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2014-07-27 10:10:09 -04:00
|
|
|
|
|
|
|
|
|
// Remove the link from the body if the link is attached at the end of the post
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (isset($footer) && (trim($footer) != "") && (strpos($footer, $matches[1]))) {
|
2014-07-27 10:10:09 -04:00
|
|
|
|
$removedlink = trim(str_replace($matches[1], "", $body));
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (($removedlink == "") || strstr($body, $removedlink)) {
|
2014-07-27 10:10:09 -04:00
|
|
|
|
$body = $removedlink;
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2014-07-27 10:10:09 -04:00
|
|
|
|
|
2018-02-16 11:12:41 -05:00
|
|
|
|
$url = str_replace(['/', '.'], ['\/', '\.'], $matches[1]);
|
|
|
|
|
$removedlink = preg_replace("/\[url\=" . $url . "\](.*?)\[\/url\]/ism", '', $body);
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (($removedlink == "") || strstr($body, $removedlink)) {
|
2014-07-27 10:10:09 -04:00
|
|
|
|
$body = $removedlink;
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2014-07-27 10:10:09 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the page information to the bottom
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (isset($footer) && (trim($footer) != "")) {
|
2014-07-27 10:10:09 -04:00
|
|
|
|
$body .= $footer;
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2014-01-05 10:10:02 -05:00
|
|
|
|
|
2014-06-15 17:33:25 -04:00
|
|
|
|
return $body;
|
2014-01-05 10:10:02 -05:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 00:16:39 -05:00
|
|
|
|
/**
|
2010-10-22 00:48:22 -04:00
|
|
|
|
*
|
|
|
|
|
* consume_feed - process atom feed and update anything/everything we might need to update
|
|
|
|
|
*
|
2011-02-08 00:16:39 -05:00
|
|
|
|
* $xml = the (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
|
|
|
|
|
*
|
2010-10-22 00:48:22 -04:00
|
|
|
|
* $importer = the contact_record (joined to user_record) of the local user who owns this relationship.
|
|
|
|
|
* It is this person's stuff that is going to be updated.
|
|
|
|
|
* $contact = the person who is sending us stuff. If not set, we MAY be processing a "follow" activity
|
2014-05-12 13:02:03 -04:00
|
|
|
|
* from an external network and MAY create an appropriate contact record. Otherwise, we MUST
|
2010-10-22 00:48:22 -04:00
|
|
|
|
* have a contact record.
|
2014-05-12 13:02:03 -04:00
|
|
|
|
* $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
|
2010-10-22 00:48:22 -04:00
|
|
|
|
* might not) try and subscribe to it.
|
2011-10-04 07:38:58 -04:00
|
|
|
|
* $datedir sorts in reverse order
|
2014-05-12 13:02:03 -04:00
|
|
|
|
* $pass - by default ($pass = 0) we cannot guarantee that a parent item has been
|
2011-10-04 07:38:58 -04:00
|
|
|
|
* imported prior to its children being seen in the stream unless we are certain
|
|
|
|
|
* of how the feed is arranged/ordered.
|
|
|
|
|
* With $pass = 1, we only pull parent items out of the stream.
|
|
|
|
|
* With $pass = 2, we only pull children (comments/likes).
|
2010-10-22 00:48:22 -04:00
|
|
|
|
*
|
2011-10-04 07:38:58 -04:00
|
|
|
|
* So running this twice, first with pass 1 and then with pass 2 will do the right
|
|
|
|
|
* thing regardless of feed ordering. This won't be adequate in a fully-threaded
|
|
|
|
|
* model where comments can have sub-threads. That would require some massive sorting
|
|
|
|
|
* to get all the feed items into a mostly linear ordering, and might still require
|
2014-03-16 12:12:56 -04:00
|
|
|
|
* recursion.
|
2010-10-22 00:48:22 -04:00
|
|
|
|
*/
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function consume_feed($xml, array $importer, array $contact, &$hub, $datedir = 0, $pass = 0)
|
|
|
|
|
{
|
2018-08-11 16:40:44 -04:00
|
|
|
|
if ($contact['network'] === Protocol::OSTATUS) {
|
2015-06-07 17:18:02 -04:00
|
|
|
|
if ($pass < 2) {
|
2015-12-03 08:38:04 -05:00
|
|
|
|
// Test - remove before flight
|
|
|
|
|
//$tempfile = tempnam(get_temppath(), "ostatus2");
|
|
|
|
|
//file_put_contents($tempfile, $xml);
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log("Consume OStatus messages ", Logger::DEBUG);
|
2017-11-15 23:09:11 -05:00
|
|
|
|
OStatus::import($xml, $importer, $contact, $hub);
|
2015-06-07 17:18:02 -04:00
|
|
|
|
}
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
2015-06-07 17:18:02 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-30 22:41:22 -04:00
|
|
|
|
|
2018-08-11 16:40:44 -04:00
|
|
|
|
if ($contact['network'] === Protocol::FEED) {
|
2015-09-27 08:02:05 -04:00
|
|
|
|
if ($pass < 2) {
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log("Consume feeds", Logger::DEBUG);
|
2017-12-13 02:02:52 -05:00
|
|
|
|
Feed::import($xml, $importer, $contact, $hub);
|
2015-09-27 08:02:05 -04:00
|
|
|
|
}
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
2015-09-27 08:02:05 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-04 17:52:06 -05:00
|
|
|
|
|
2018-08-11 16:40:44 -04:00
|
|
|
|
if ($contact['network'] === Protocol::DFRN) {
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log("Consume DFRN messages", Logger::DEBUG);
|
2018-08-19 09:37:56 -04:00
|
|
|
|
$dfrn_importer = DFRN::getImporter($contact["id"], $importer["uid"]);
|
|
|
|
|
if (!empty($dfrn_importer)) {
|
2018-10-29 17:20:46 -04:00
|
|
|
|
Logger::log("Now import the DFRN feed");
|
2018-08-19 09:37:56 -04:00
|
|
|
|
DFRN::import($xml, $dfrn_importer, true);
|
2016-02-03 17:04:52 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-05 15:25:20 -05:00
|
|
|
|
}
|
2016-02-04 17:52:06 -05:00
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'subscribe')
|
|
|
|
|
{
|
2017-04-14 10:59:51 -04:00
|
|
|
|
/*
|
|
|
|
|
* Diaspora has different message-ids in feeds than they do
|
|
|
|
|
* through the direct Diaspora protocol. If we try and use
|
|
|
|
|
* the feed, we'll get duplicates. So don't.
|
|
|
|
|
*/
|
2018-08-19 08:46:11 -04:00
|
|
|
|
if ($contact['network'] === Protocol::DIASPORA) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Without an importer we don't have a user id - so we quit
|
|
|
|
|
if (empty($importer)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$a = BaseObject::getApp();
|
|
|
|
|
|
|
|
|
|
$user = DBA::selectFirst('user', ['nickname'], ['uid' => $importer['uid']]);
|
|
|
|
|
|
|
|
|
|
// No user, no nickname, we quit
|
|
|
|
|
if (!DBA::isResult($user)) {
|
2010-10-01 00:38:45 -04:00
|
|
|
|
return;
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2010-10-01 00:38:45 -04:00
|
|
|
|
|
2018-08-19 08:46:11 -04:00
|
|
|
|
$push_url = System::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
|
2010-10-01 00:38:45 -04:00
|
|
|
|
|
2010-10-15 07:20:42 -04:00
|
|
|
|
// Use a single verify token, even if multiple hubs
|
2018-11-08 08:45:46 -05:00
|
|
|
|
$verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
|
2010-10-01 00:38:45 -04:00
|
|
|
|
|
2011-09-22 07:11:39 -04:00
|
|
|
|
$params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
|
2010-10-01 00:38:45 -04:00
|
|
|
|
|
2018-10-29 17:20:46 -04:00
|
|
|
|
Logger::log('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
|
2010-11-04 23:47:44 -04:00
|
|
|
|
|
2017-06-07 22:00:59 -04:00
|
|
|
|
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
|
2018-07-20 08:19:26 -04:00
|
|
|
|
DBA::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
|
2010-10-15 07:20:42 -04:00
|
|
|
|
}
|
2010-10-01 00:38:45 -04:00
|
|
|
|
|
2018-10-10 15:15:26 -04:00
|
|
|
|
$postResult = Network::post($url, $params);
|
2012-06-07 02:10:32 -04:00
|
|
|
|
|
2018-10-30 09:58:45 -04:00
|
|
|
|
Logger::log('subscribe_to_hub: returns: ' . $postResult->getReturnCode(), Logger::DEBUG);
|
2013-01-10 19:20:16 -05:00
|
|
|
|
|
2010-10-01 00:38:45 -04:00
|
|
|
|
return;
|
|
|
|
|
|
2010-11-01 20:56:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function drop_items(array $items)
|
|
|
|
|
{
|
2011-06-15 23:43:39 -04:00
|
|
|
|
$uid = 0;
|
|
|
|
|
|
2018-01-17 18:22:01 -05:00
|
|
|
|
if (!local_user() && !remote_user()) {
|
2012-01-24 21:59:55 -05:00
|
|
|
|
return;
|
2017-04-14 10:59:51 -04:00
|
|
|
|
}
|
2012-01-24 21:59:55 -05:00
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
if (!empty($items)) {
|
2017-04-14 10:59:51 -04:00
|
|
|
|
foreach ($items as $item) {
|
2018-05-29 01:22:57 -04:00
|
|
|
|
$owner = Item::deleteForUser(['id' => $item], local_user());
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
|
|
|
|
if ($owner && !$uid) {
|
2011-06-15 23:43:39 -04:00
|
|
|
|
$uid = $owner;
|
2018-07-30 21:02:34 -04:00
|
|
|
|
}
|
2011-06-15 23:43:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-26 09:00:15 -04:00
|
|
|
|
function drop_item($id, $return = '')
|
2018-07-30 21:02:34 -04:00
|
|
|
|
{
|
|
|
|
|
$a = BaseObject::getApp();
|
2011-06-15 23:43:39 -04:00
|
|
|
|
|
|
|
|
|
// locate item to be deleted
|
|
|
|
|
|
2018-11-18 06:43:26 -05:00
|
|
|
|
$fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', parent];
|
2018-06-18 16:36:34 -04:00
|
|
|
|
$item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
|
2011-06-15 23:43:39 -04:00
|
|
|
|
|
2018-07-21 08:46:04 -04:00
|
|
|
|
if (!DBA::isResult($item)) {
|
2018-01-21 13:33:59 -05:00
|
|
|
|
notice(L10n::t('Item not found.') . EOL);
|
2018-10-19 14:11:27 -04:00
|
|
|
|
$a->internalRedirect('network');
|
2011-06-15 23:43:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-20 23:49:05 -04:00
|
|
|
|
if ($item['deleted']) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:49:51 -05:00
|
|
|
|
$contact_id = 0;
|
2012-09-05 01:50:28 -04:00
|
|
|
|
|
2011-06-15 23:43:39 -04:00
|
|
|
|
// check if logged in user is either the author or owner of this item
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
if (!empty($_SESSION['remote'])) {
|
2017-04-14 10:59:51 -04:00
|
|
|
|
foreach ($_SESSION['remote'] as $visitor) {
|
2016-10-22 06:14:41 -04:00
|
|
|
|
if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
|
2016-11-14 12:49:51 -05:00
|
|
|
|
$contact_id = $visitor['cid'];
|
2012-09-05 01:50:28 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 18:22:01 -05:00
|
|
|
|
if ((local_user() == $item['uid']) || $contact_id) {
|
2013-01-26 14:52:21 -05:00
|
|
|
|
// Check if we should do HTML-based delete confirmation
|
2018-08-21 11:35:09 -04:00
|
|
|
|
if (!empty($_REQUEST['confirm'])) {
|
2013-01-26 14:52:21 -05:00
|
|
|
|
// <form> can't take arguments in its "action" parameter
|
|
|
|
|
// so add any arguments as hidden inputs
|
|
|
|
|
$query = explode_querystring($a->query_string);
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$inputs = [];
|
2018-07-30 21:02:34 -04:00
|
|
|
|
|
2017-04-14 10:59:51 -04:00
|
|
|
|
foreach ($query['args'] as $arg) {
|
2016-10-22 06:14:41 -04:00
|
|
|
|
if (strpos($arg, 'confirm=') === false) {
|
2013-01-26 14:52:21 -05:00
|
|
|
|
$arg_parts = explode('=', $arg);
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
|
2013-01-26 14:52:21 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-31 10:44:06 -04:00
|
|
|
|
return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
|
2013-01-26 14:52:21 -05:00
|
|
|
|
'$method' => 'get',
|
2018-01-21 13:33:59 -05:00
|
|
|
|
'$message' => L10n::t('Do you really want to delete this item?'),
|
2013-01-26 14:52:21 -05:00
|
|
|
|
'$extra_inputs' => $inputs,
|
2018-01-21 13:33:59 -05:00
|
|
|
|
'$confirm' => L10n::t('Yes'),
|
2013-01-26 14:52:21 -05:00
|
|
|
|
'$confirm_url' => $query['base'],
|
|
|
|
|
'$confirm_name' => 'confirmed',
|
2018-01-21 13:33:59 -05:00
|
|
|
|
'$cancel' => L10n::t('Cancel'),
|
2018-01-15 08:05:12 -05:00
|
|
|
|
]);
|
2013-01-26 14:52:21 -05:00
|
|
|
|
}
|
|
|
|
|
// Now check how the user responded to the confirmation query
|
2018-08-21 11:35:09 -04:00
|
|
|
|
if (!empty($_REQUEST['canceled'])) {
|
2018-10-19 14:11:27 -04:00
|
|
|
|
$a->internalRedirect('display/' . $item['guid']);
|
2013-01-26 14:52:21 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-17 07:56:58 -05:00
|
|
|
|
$is_comment = ($item['gravity'] == GRAVITY_COMMENT) ? true : false;
|
2018-11-18 06:43:26 -05:00
|
|
|
|
$parentitem = null;
|
|
|
|
|
if (!empty($item['parent'])){
|
|
|
|
|
$fields = ['guid'];
|
|
|
|
|
$parentitem = Item::selectFirstForUser(local_user(), $fields, ['id' => $item['parent']]);
|
|
|
|
|
}
|
2018-11-17 07:56:58 -05:00
|
|
|
|
|
2011-06-15 23:43:39 -04:00
|
|
|
|
// delete the item
|
2018-05-29 01:22:57 -04:00
|
|
|
|
Item::deleteForUser(['id' => $item['id']], local_user());
|
2011-06-15 23:43:39 -04:00
|
|
|
|
|
2018-10-25 17:57:26 -04:00
|
|
|
|
$return_url = hex2bin($return);
|
2018-11-06 15:37:10 -05:00
|
|
|
|
|
|
|
|
|
// removes update_* from return_url to ignore Ajax refresh
|
|
|
|
|
$return_url = str_replace("update_", "", $return_url);
|
|
|
|
|
|
2018-11-18 06:43:26 -05:00
|
|
|
|
// Check if delete a comment
|
|
|
|
|
if ($is_comment) {
|
|
|
|
|
// Return to parent guid
|
|
|
|
|
if (!empty($parentitem)) {
|
|
|
|
|
$a->internalRedirect('display/' . $parentitem['guid']);
|
|
|
|
|
//NOTREACHED
|
|
|
|
|
}
|
2018-10-25 17:57:26 -04:00
|
|
|
|
}
|
|
|
|
|
else {
|
2018-11-18 06:43:26 -05:00
|
|
|
|
// if unknown location or deleting top level post called from display
|
|
|
|
|
if (empty($return_url) || strpos($return_url, 'display') !== false) {
|
|
|
|
|
$a->internalRedirect('network');
|
|
|
|
|
//NOTREACHED
|
|
|
|
|
} else {
|
|
|
|
|
$a->internalRedirect($return_url);
|
|
|
|
|
//NOTREACHED
|
|
|
|
|
}
|
2018-10-25 17:57:26 -04:00
|
|
|
|
}
|
2016-10-22 06:14:41 -04:00
|
|
|
|
} else {
|
2018-01-21 13:33:59 -05:00
|
|
|
|
notice(L10n::t('Permission denied.') . EOL);
|
2018-10-19 14:11:27 -04:00
|
|
|
|
$a->internalRedirect('display/' . $item['guid']);
|
2011-06-15 23:43:39 -04:00
|
|
|
|
//NOTREACHED
|
|
|
|
|
}
|
2011-10-23 03:24:37 -04:00
|
|
|
|
}
|
2012-06-12 23:46:30 -04:00
|
|
|
|
|
2018-01-20 18:52:54 -05:00
|
|
|
|
/* arrange the list in years */
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function list_post_dates($uid, $wall)
|
|
|
|
|
{
|
2018-01-26 21:38:34 -05:00
|
|
|
|
$dnow = DateTimeFormat::localNow('Y-m-d');
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2018-01-28 06:18:08 -05:00
|
|
|
|
$dthen = Item::firstPostDate($uid, $wall);
|
|
|
|
|
if (!$dthen) {
|
2018-01-15 08:05:12 -05:00
|
|
|
|
return [];
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2015-05-18 19:03:08 -04:00
|
|
|
|
// Set the start and end date to the beginning of the month
|
2017-04-14 10:59:51 -04:00
|
|
|
|
$dnow = substr($dnow, 0, 8) . '01';
|
|
|
|
|
$dthen = substr($dthen, 0, 8) . '01';
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$ret = [];
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2017-04-08 13:30:35 -04:00
|
|
|
|
/*
|
|
|
|
|
* Starting with the current month, get the first and last days of every
|
|
|
|
|
* month down to and including the month of the first post
|
|
|
|
|
*/
|
|
|
|
|
while (substr($dnow, 0, 7) >= substr($dthen, 0, 7)) {
|
2017-04-14 10:59:51 -04:00
|
|
|
|
$dyear = intval(substr($dnow, 0, 4));
|
|
|
|
|
$dstart = substr($dnow, 0, 8) . '01';
|
2018-02-03 12:25:58 -05:00
|
|
|
|
$dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
|
2018-01-26 21:38:34 -05:00
|
|
|
|
$start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
|
|
|
|
|
$end_month = DateTimeFormat::utc($dend, 'Y-m-d');
|
2018-11-06 09:52:10 -05:00
|
|
|
|
$str = L10n::getDay(DateTimeFormat::utc($dnow, 'F'));
|
2018-07-13 15:47:14 -04:00
|
|
|
|
|
2018-07-10 08:27:56 -04:00
|
|
|
|
if (empty($ret[$dyear])) {
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$ret[$dyear] = [];
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2018-07-13 15:47:14 -04:00
|
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
|
$ret[$dyear][] = [$str, $end_month, $start_month];
|
2018-01-26 21:38:34 -05:00
|
|
|
|
$dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
|
2015-05-18 19:03:08 -04:00
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
function posted_date_widget($url, $uid, $wall)
|
|
|
|
|
{
|
2012-06-12 23:46:30 -04:00
|
|
|
|
$o = '';
|
2012-06-13 19:17:45 -04:00
|
|
|
|
|
2018-01-28 06:18:08 -05:00
|
|
|
|
if (!Feature::isEnabled($uid, 'archives')) {
|
2012-11-22 11:14:22 -05:00
|
|
|
|
return $o;
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2012-11-22 11:14:22 -05:00
|
|
|
|
|
2012-06-13 19:17:45 -04:00
|
|
|
|
// For former Facebook folks that left because of "timeline"
|
2017-04-14 10:59:51 -04:00
|
|
|
|
/*
|
|
|
|
|
* @TODO old-lost code?
|
2017-11-06 21:22:52 -05:00
|
|
|
|
if ($wall && intval(PConfig::get($uid, 'system', 'no_wall_archive_widget')))
|
2017-04-14 10:59:51 -04:00
|
|
|
|
return $o;
|
|
|
|
|
*/
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2018-07-30 21:02:34 -04:00
|
|
|
|
$visible_years = PConfig::get($uid, 'system', 'archive_visible_years', 5);
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2017-04-08 13:30:35 -04:00
|
|
|
|
$ret = list_post_dates($uid, $wall);
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2018-07-21 08:46:04 -04:00
|
|
|
|
if (!DBA::isResult($ret)) {
|
2012-06-12 23:46:30 -04:00
|
|
|
|
return $o;
|
2017-04-08 13:30:35 -04:00
|
|
|
|
}
|
2012-06-12 23:46:30 -04:00
|
|
|
|
|
2018-01-26 21:38:34 -05:00
|
|
|
|
$cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
|
2017-04-08 13:30:35 -04:00
|
|
|
|
$cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
|
2015-06-02 12:59:46 -04:00
|
|
|
|
|
2018-10-31 10:44:06 -04:00
|
|
|
|
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('posted_date_widget.tpl'),[
|
2018-01-21 13:33:59 -05:00
|
|
|
|
'$title' => L10n::t('Archives'),
|
2015-05-18 19:03:08 -04:00
|
|
|
|
'$size' => $visible_years,
|
|
|
|
|
'$cutoff_year' => $cutoff_year,
|
|
|
|
|
'$cutoff' => $cutoff,
|
2012-06-12 23:46:30 -04:00
|
|
|
|
'$url' => $url,
|
2015-05-18 19:03:08 -04:00
|
|
|
|
'$dates' => $ret,
|
2018-01-21 13:33:59 -05:00
|
|
|
|
'$showmore' => L10n::t('show more')
|
2015-05-18 19:03:08 -04:00
|
|
|
|
|
2018-01-15 08:05:12 -05:00
|
|
|
|
]);
|
2012-06-12 23:46:30 -04:00
|
|
|
|
return $o;
|
2012-06-29 15:40:54 -04:00
|
|
|
|
}
|