2010-07-18 13:02:55 +00:00
|
|
|
|
<?php
|
2016-11-24 00:11:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* @file include/items.php
|
|
|
|
|
*/
|
2018-01-25 02:08:45 +00:00
|
|
|
|
|
2017-12-04 14:04:36 +00:00
|
|
|
|
use Friendica\Content\Feature;
|
2018-01-17 18:42:40 +00:00
|
|
|
|
use Friendica\Core\Addon;
|
2017-07-23 05:51:55 +00:00
|
|
|
|
use Friendica\Core\Config;
|
2018-01-21 18:33:59 +00:00
|
|
|
|
use Friendica\Core\L10n;
|
2017-11-07 02:22:52 +00:00
|
|
|
|
use Friendica\Core\PConfig;
|
2017-11-15 15:53:16 +00:00
|
|
|
|
use Friendica\Core\System;
|
2017-11-08 03:57:46 +00:00
|
|
|
|
use Friendica\Database\DBM;
|
2018-01-25 02:08:45 +00:00
|
|
|
|
use Friendica\Model\Item;
|
2017-11-08 03:57:46 +00:00
|
|
|
|
use Friendica\Protocol\DFRN;
|
2017-12-13 07:02:52 +00:00
|
|
|
|
use Friendica\Protocol\Feed;
|
2018-01-25 02:08:45 +00:00
|
|
|
|
use Friendica\Protocol\OStatus;
|
2018-01-27 02:38:34 +00:00
|
|
|
|
use Friendica\Util\DateTimeFormat;
|
|
|
|
|
use Friendica\Util\Network;
|
2018-01-04 17:03:15 +00:00
|
|
|
|
use Friendica\Util\ParseUrl;
|
2016-11-24 00:11:22 +00:00
|
|
|
|
|
2017-04-08 17:30:35 +00:00
|
|
|
|
require_once 'include/bbcode.php';
|
|
|
|
|
require_once 'include/tags.php';
|
|
|
|
|
require_once 'include/text.php';
|
|
|
|
|
require_once 'include/threads.php';
|
|
|
|
|
require_once 'mod/share.php';
|
|
|
|
|
require_once 'include/enotify.php';
|
|
|
|
|
|
2014-10-20 06:03:47 +00:00
|
|
|
|
function add_page_info_data($data) {
|
2018-01-17 18:42:40 +00:00
|
|
|
|
Addon::callHooks('page_info_data', $data);
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2014-04-04 08:52:53 +00:00
|
|
|
|
// It maybe is a rich content, but if it does have everything that a link has,
|
|
|
|
|
// then treat it that way
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (($data["type"] == "rich") && is_string($data["title"]) &&
|
|
|
|
|
is_string($data["text"]) && (sizeof($data["images"]) > 0)) {
|
2014-04-04 08:52:53 +00:00
|
|
|
|
$data["type"] = "link";
|
2016-11-13 19:09:47 +00:00
|
|
|
|
}
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if ((($data["type"] != "link") && ($data["type"] != "video") && ($data["type"] != "photo")) || ($data["title"] == $data["url"])) {
|
2016-11-13 08:50:01 +00:00
|
|
|
|
return "";
|
2016-11-12 20:23:00 +00:00
|
|
|
|
}
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if ($no_photos && ($data["type"] == "photo")) {
|
2016-11-13 19:09:47 +00:00
|
|
|
|
return "";
|
|
|
|
|
}
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2016-04-17 18:43:41 +00:00
|
|
|
|
// Escape some bad characters
|
2018-01-15 13:05:12 +00: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 18:43:41 +00:00
|
|
|
|
|
|
|
|
|
$text = "[attachment type='".$data["type"]."'";
|
|
|
|
|
|
2016-11-12 20:23:00 +00:00
|
|
|
|
if ($data["text"] == "") {
|
|
|
|
|
$data["text"] = $data["title"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($data["text"] == "") {
|
|
|
|
|
$data["text"] = $data["url"];
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-13 19:09:47 +00:00
|
|
|
|
if ($data["url"] != "") {
|
2016-04-17 18:43:41 +00:00
|
|
|
|
$text .= " url='".$data["url"]."'";
|
2016-11-13 19:09:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($data["title"] != "") {
|
2016-04-17 18:43:41 +00:00
|
|
|
|
$text .= " title='".$data["title"]."'";
|
2016-11-13 19:09:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 18:43:41 +00:00
|
|
|
|
if (sizeof($data["images"]) > 0) {
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$preview = str_replace(["[", "]"], ["[", "]"], htmlentities($data["images"][0]["src"], ENT_QUOTES, 'UTF-8', false));
|
2016-04-17 18:43:41 +00: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 10:07:49 +00:00
|
|
|
|
if (!Config::get('system', 'always_show_preview') && ($data["images"][0]["width"] >= 500)
|
|
|
|
|
&& ($data["images"][0]["width"] >= $data["images"][0]["height"])) {
|
2016-04-17 18:43:41 +00:00
|
|
|
|
$text .= " image='".$preview."'";
|
2016-11-13 19:09:47 +00:00
|
|
|
|
} else {
|
2016-04-17 18:43:41 +00:00
|
|
|
|
$text .= " preview='".$preview."'";
|
2016-11-13 19:09:47 +00:00
|
|
|
|
}
|
2014-06-15 21:33:25 +00:00
|
|
|
|
}
|
2016-11-13 19:09:47 +00:00
|
|
|
|
|
2016-04-17 18:43:41 +00:00
|
|
|
|
$text .= "]".$data["text"]."[/attachment]";
|
2014-04-04 08:52:53 +00:00
|
|
|
|
|
2014-10-03 10:18:33 +00:00
|
|
|
|
$hashtags = "";
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (isset($data["keywords"]) && count($data["keywords"])) {
|
2014-10-03 11:02:15 +00:00
|
|
|
|
$hashtags = "\n";
|
|
|
|
|
foreach ($data["keywords"] AS $keyword) {
|
2018-01-20 23:52:54 +00:00
|
|
|
|
/// @TODO make a positive list of allowed characters
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$hashtag = str_replace([" ", "+", "/", ".", "#", "'", "’", "`", "(", ")", "„", "“"],
|
|
|
|
|
["", "", "", "", "", "", "", "", "", "", "", ""], $keyword);
|
2017-08-26 07:32:10 +00:00
|
|
|
|
$hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url] ";
|
2014-10-03 11:02:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-03 10:18:33 +00:00
|
|
|
|
|
2016-04-17 18:43:41 +00:00
|
|
|
|
return "\n".$text.$hashtags;
|
2014-04-04 08:52:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-20 21:54:25 +00:00
|
|
|
|
function query_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
|
2014-10-20 06:03:47 +00:00
|
|
|
|
|
2016-11-24 00:11:22 +00:00
|
|
|
|
$data = ParseUrl::getSiteinfoCached($url, true);
|
2014-10-20 06:03:47 +00:00
|
|
|
|
|
2017-04-08 17:30:35 +00:00
|
|
|
|
if ($photo != "") {
|
2014-12-17 20:57:38 +00:00
|
|
|
|
$data["images"][0]["src"] = $photo;
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2014-12-17 20:57:38 +00:00
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
logger('fetch page info for ' . $url . ' ' . print_r($data, true), LOGGER_DEBUG);
|
2014-10-20 06:03:47 +00:00
|
|
|
|
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (!$keywords && isset($data["keywords"])) {
|
2014-10-20 06:03:47 +00:00
|
|
|
|
unset($data["keywords"]);
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2014-10-20 06:03:47 +00:00
|
|
|
|
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (($keyword_blacklist != "") && isset($data["keywords"])) {
|
2017-04-08 17:30:35 +00:00
|
|
|
|
$list = explode(", ", $keyword_blacklist);
|
2014-10-29 23:24:23 +00:00
|
|
|
|
foreach ($list AS $keyword) {
|
|
|
|
|
$keyword = trim($keyword);
|
|
|
|
|
$index = array_search($keyword, $data["keywords"]);
|
2017-04-08 17:30:35 +00:00
|
|
|
|
if ($index !== false) {
|
2014-10-29 23:24:23 +00:00
|
|
|
|
unset($data["keywords"][$index]);
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2014-10-29 23:24:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
return $data;
|
2015-01-20 21:54:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add_page_keywords($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
|
|
|
|
|
$data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist);
|
|
|
|
|
|
|
|
|
|
$tags = "";
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (isset($data["keywords"]) && count($data["keywords"])) {
|
2015-01-20 21:54:25 +00:00
|
|
|
|
foreach ($data["keywords"] AS $keyword) {
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$hashtag = str_replace([" ", "+", "/", ".", "#", "'"],
|
|
|
|
|
["", "", "", "", "", ""], $keyword);
|
2015-01-20 21:54:25 +00:00
|
|
|
|
|
2017-04-08 17:30:35 +00:00
|
|
|
|
if ($tags != "") {
|
|
|
|
|
$tags .= ", ";
|
|
|
|
|
}
|
2015-01-20 21:54:25 +00:00
|
|
|
|
|
2017-08-26 07:32:10 +00:00
|
|
|
|
$tags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
|
2015-01-20 21:54:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
return $tags;
|
2015-01-20 21:54:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function add_page_info($url, $no_photos = false, $photo = "", $keywords = false, $keyword_blacklist = "") {
|
|
|
|
|
$data = query_page_info($url, $no_photos, $photo, $keywords, $keyword_blacklist);
|
|
|
|
|
|
2014-10-20 06:03:47 +00:00
|
|
|
|
$text = add_page_info_data($data);
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
return $text;
|
2014-10-20 06:03:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-04 08:52:53 +00:00
|
|
|
|
function add_page_info_to_body($body, $texturl = false, $no_photos = false) {
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
logger('add_page_info_to_body: fetch page info for body ' . $body, LOGGER_DEBUG);
|
2014-04-04 08:52:53 +00:00
|
|
|
|
|
2014-06-15 21:33:25 +00:00
|
|
|
|
$URLSearchString = "^\[\]";
|
2014-04-04 08:52:53 +00:00
|
|
|
|
|
2016-12-12 06:46:02 +00:00
|
|
|
|
// Fix for Mastodon where the mentions are in a different format
|
|
|
|
|
$body = preg_replace("/\[url\=([$URLSearchString]*)\]([#!@])(.*?)\[\/url\]/ism",
|
2017-04-14 14:59:51 +00:00
|
|
|
|
'$2[url=$1]$3[/url]', $body);
|
2016-12-12 06:46:02 +00:00
|
|
|
|
|
2014-06-15 21:33:25 +00:00
|
|
|
|
// Adding these spaces is a quick hack due to my problems with regular expressions :)
|
2017-04-14 14:59:51 +00:00
|
|
|
|
preg_match("/[^!#@]\[url\]([$URLSearchString]*)\[\/url\]/ism", " " . $body, $matches);
|
2014-04-04 08:52:53 +00:00
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
if (!$matches) {
|
|
|
|
|
preg_match("/[^!#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " " . $body, $matches);
|
|
|
|
|
}
|
2014-04-04 08:52:53 +00:00
|
|
|
|
|
|
|
|
|
// Convert urls without bbcode elements
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (!$matches && $texturl) {
|
2014-04-04 08:52:53 +00:00
|
|
|
|
preg_match("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", " ".$body, $matches);
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2014-04-04 08:52:53 +00:00
|
|
|
|
// Yeah, a hack. I really hate regular expressions :)
|
2017-04-14 14:59:51 +00:00
|
|
|
|
if ($matches) {
|
2014-06-15 21:33:25 +00:00
|
|
|
|
$matches[1] = $matches[2];
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2014-01-05 15:10:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
if ($matches) {
|
2014-07-27 14:10:09 +00:00
|
|
|
|
$footer = add_page_info($matches[1], $no_photos);
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2014-07-27 14:10:09 +00:00
|
|
|
|
|
|
|
|
|
// Remove the link from the body if the link is attached at the end of the post
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (isset($footer) && (trim($footer) != "") && (strpos($footer, $matches[1]))) {
|
2014-07-27 14:10:09 +00:00
|
|
|
|
$removedlink = trim(str_replace($matches[1], "", $body));
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (($removedlink == "") || strstr($body, $removedlink)) {
|
2014-07-27 14:10:09 +00:00
|
|
|
|
$body = $removedlink;
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2014-07-27 14:10:09 +00:00
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$url = str_replace(['/', '.'], ['\/', '\.'], $matches[1]);
|
2017-04-14 14:59:51 +00:00
|
|
|
|
$removedlink = preg_replace("/\[url\=" . $url . "\](.*?)\[\/url\]/ism", '', $body);
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (($removedlink == "") || strstr($body, $removedlink)) {
|
2014-07-27 14:10:09 +00:00
|
|
|
|
$body = $removedlink;
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2014-07-27 14:10:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add the page information to the bottom
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (isset($footer) && (trim($footer) != "")) {
|
2014-07-27 14:10:09 +00:00
|
|
|
|
$body .= $footer;
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2014-01-05 15:10:02 +00:00
|
|
|
|
|
2014-06-15 21:33:25 +00:00
|
|
|
|
return $body;
|
2014-01-05 15:10:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-08 05:16:39 +00:00
|
|
|
|
/**
|
2010-10-22 04:48:22 +00:00
|
|
|
|
*
|
|
|
|
|
* consume_feed - process atom feed and update anything/everything we might need to update
|
|
|
|
|
*
|
2011-02-08 05:16:39 +00:00
|
|
|
|
* $xml = the (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
|
|
|
|
|
*
|
2010-10-22 04:48:22 +00: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 17:02:03 +00:00
|
|
|
|
* from an external network and MAY create an appropriate contact record. Otherwise, we MUST
|
2010-10-22 04:48:22 +00:00
|
|
|
|
* have a contact record.
|
2014-05-12 17:02:03 +00:00
|
|
|
|
* $hub = should we find a hub declation in the feed, pass it back to our calling process, who might (or
|
2010-10-22 04:48:22 +00:00
|
|
|
|
* might not) try and subscribe to it.
|
2011-10-04 11:38:58 +00:00
|
|
|
|
* $datedir sorts in reverse order
|
2014-05-12 17:02:03 +00:00
|
|
|
|
* $pass - by default ($pass = 0) we cannot guarantee that a parent item has been
|
2011-10-04 11:38:58 +00: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 04:48:22 +00:00
|
|
|
|
*
|
2011-10-04 11:38:58 +00: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 16:12:56 +00:00
|
|
|
|
* recursion.
|
2017-04-14 14:59:51 +00:00
|
|
|
|
*
|
2018-01-20 23:52:54 +00:00
|
|
|
|
* @TODO find proper type-hints
|
2010-10-22 04:48:22 +00:00
|
|
|
|
*/
|
2017-04-14 14:59:51 +00:00
|
|
|
|
function consume_feed($xml, $importer, &$contact, &$hub, $datedir = 0, $pass = 0) {
|
2015-06-07 21:18:02 +00:00
|
|
|
|
if ($contact['network'] === NETWORK_OSTATUS) {
|
|
|
|
|
if ($pass < 2) {
|
2015-12-03 13:38:04 +00:00
|
|
|
|
// Test - remove before flight
|
|
|
|
|
//$tempfile = tempnam(get_temppath(), "ostatus2");
|
|
|
|
|
//file_put_contents($tempfile, $xml);
|
2015-06-07 21:18:02 +00:00
|
|
|
|
logger("Consume OStatus messages ", LOGGER_DEBUG);
|
2017-11-16 04:09:11 +00:00
|
|
|
|
OStatus::import($xml, $importer, $contact, $hub);
|
2015-06-07 21:18:02 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-10-01 02:41:22 +00:00
|
|
|
|
|
2015-09-27 12:02:05 +00:00
|
|
|
|
if ($contact['network'] === NETWORK_FEED) {
|
|
|
|
|
if ($pass < 2) {
|
|
|
|
|
logger("Consume feeds", LOGGER_DEBUG);
|
2017-12-13 07:02:52 +00:00
|
|
|
|
Feed::import($xml, $importer, $contact, $hub);
|
2015-09-27 12:02:05 +00:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-02-04 22:52:06 +00:00
|
|
|
|
|
2016-02-03 22:04:52 +00:00
|
|
|
|
if ($contact['network'] === NETWORK_DFRN) {
|
|
|
|
|
logger("Consume DFRN messages", LOGGER_DEBUG);
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
$r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
|
2016-04-17 18:43:41 +00:00
|
|
|
|
`contact`.`pubkey` AS `cpubkey`,
|
|
|
|
|
`contact`.`prvkey` AS `cprvkey`,
|
|
|
|
|
`contact`.`thumb` AS `thumb`,
|
|
|
|
|
`contact`.`url` as `url`,
|
|
|
|
|
`contact`.`name` as `senderName`,
|
|
|
|
|
`user`.*
|
|
|
|
|
FROM `contact`
|
|
|
|
|
LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
|
|
|
|
|
WHERE `contact`.`id` = %d AND `user`.`uid` = %d",
|
|
|
|
|
dbesc($contact["id"]), dbesc($importer["uid"])
|
|
|
|
|
);
|
2017-11-08 03:57:46 +00:00
|
|
|
|
if (DBM::is_result($r)) {
|
2016-02-04 22:52:06 +00:00
|
|
|
|
logger("Now import the DFRN feed");
|
2017-11-08 03:57:46 +00:00
|
|
|
|
DFRN::import($xml, $r[0], true);
|
2016-02-03 22:04:52 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-02-05 20:25:20 +00:00
|
|
|
|
}
|
2016-02-04 22:52:06 +00:00
|
|
|
|
|
2017-03-31 18:41:32 +00:00
|
|
|
|
function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
|
2010-10-01 04:38:45 +00:00
|
|
|
|
|
2012-06-07 06:10:32 +00:00
|
|
|
|
$a = get_app();
|
|
|
|
|
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if (is_array($importer)) {
|
2010-10-01 04:38:45 +00:00
|
|
|
|
$r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
|
|
|
|
|
intval($importer['uid'])
|
|
|
|
|
);
|
|
|
|
|
}
|
2011-09-22 11:11:39 +00:00
|
|
|
|
|
2017-04-14 14:59:51 +00: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-01-28 11:18:08 +00:00
|
|
|
|
if ((!DBM::is_result($r)) || $contact['network'] === NETWORK_DIASPORA) {
|
2010-10-01 04:38:45 +00:00
|
|
|
|
return;
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2010-10-01 04:38:45 +00:00
|
|
|
|
|
2017-11-07 02:22:52 +00:00
|
|
|
|
$push_url = Config::get('system','url') . '/pubsub/' . $r[0]['nickname'] . '/' . $contact['id'];
|
2010-10-01 04:38:45 +00:00
|
|
|
|
|
2010-10-15 11:20:42 +00:00
|
|
|
|
// Use a single verify token, even if multiple hubs
|
|
|
|
|
$verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
|
2010-10-01 04:38:45 +00:00
|
|
|
|
|
2011-09-22 11:11:39 +00: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 04:38:45 +00:00
|
|
|
|
|
2011-10-05 01:53:56 +00:00
|
|
|
|
logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: ' . $push_url . ' with verifier ' . $verify_token);
|
2010-11-05 03:47:44 +00:00
|
|
|
|
|
2017-06-08 02:00:59 +00:00
|
|
|
|
if (!strlen($contact['hub-verify']) || ($contact['hub-verify'] != $verify_token)) {
|
2018-01-15 13:05:12 +00:00
|
|
|
|
dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]);
|
2010-10-15 11:20:42 +00:00
|
|
|
|
}
|
2010-10-01 04:38:45 +00:00
|
|
|
|
|
2018-01-27 16:13:41 +00:00
|
|
|
|
Network::post($url, $params);
|
2012-06-07 06:10:32 +00:00
|
|
|
|
|
|
|
|
|
logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG);
|
2013-01-11 00:20:16 +00:00
|
|
|
|
|
2010-10-01 04:38:45 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2010-11-02 00:56:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-14 14:59:51 +00:00
|
|
|
|
/// @TODO type-hint is array
|
2011-06-16 03:43:39 +00:00
|
|
|
|
function drop_items($items) {
|
|
|
|
|
$uid = 0;
|
|
|
|
|
|
2018-01-17 23:22:01 +00:00
|
|
|
|
if (!local_user() && !remote_user()) {
|
2012-01-25 02:59:55 +00:00
|
|
|
|
return;
|
2017-04-14 14:59:51 +00:00
|
|
|
|
}
|
2012-01-25 02:59:55 +00:00
|
|
|
|
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if (count($items)) {
|
2017-04-14 14:59:51 +00:00
|
|
|
|
foreach ($items as $item) {
|
2018-01-17 23:22:01 +00:00
|
|
|
|
$owner = Item::delete($item);
|
2018-01-28 11:18:08 +00:00
|
|
|
|
if ($owner && !$uid)
|
2011-06-16 03:43:39 +00:00
|
|
|
|
$uid = $owner;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 23:22:01 +00:00
|
|
|
|
function drop_item($id) {
|
2011-06-16 03:43:39 +00:00
|
|
|
|
|
|
|
|
|
$a = get_app();
|
|
|
|
|
|
|
|
|
|
// locate item to be deleted
|
|
|
|
|
|
|
|
|
|
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
|
|
|
|
|
intval($id)
|
|
|
|
|
);
|
|
|
|
|
|
2018-01-17 23:22:01 +00:00
|
|
|
|
if (!DBM::is_result($r)) {
|
2018-01-21 18:33:59 +00:00
|
|
|
|
notice(L10n::t('Item not found.') . EOL);
|
2017-08-26 07:32:10 +00:00
|
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
|
2011-06-16 03:43:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$item = $r[0];
|
|
|
|
|
|
2017-06-21 03:49:05 +00:00
|
|
|
|
if ($item['deleted']) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 17:49:51 +00:00
|
|
|
|
$contact_id = 0;
|
2012-09-05 05:50:28 +00:00
|
|
|
|
|
2011-06-16 03:43:39 +00:00
|
|
|
|
// check if logged in user is either the author or owner of this item
|
|
|
|
|
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if (is_array($_SESSION['remote'])) {
|
2017-04-14 14:59:51 +00:00
|
|
|
|
foreach ($_SESSION['remote'] as $visitor) {
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if ($visitor['uid'] == $item['uid'] && $visitor['cid'] == $item['contact-id']) {
|
2016-11-14 17:49:51 +00:00
|
|
|
|
$contact_id = $visitor['cid'];
|
2012-09-05 05:50:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 23:22:01 +00:00
|
|
|
|
if ((local_user() == $item['uid']) || $contact_id) {
|
2011-06-16 03:43:39 +00:00
|
|
|
|
|
2013-01-26 19:52:21 +00:00
|
|
|
|
// Check if we should do HTML-based delete confirmation
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if ($_REQUEST['confirm']) {
|
2013-01-26 19:52:21 +00: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 13:05:12 +00:00
|
|
|
|
$inputs = [];
|
2017-04-14 14:59:51 +00:00
|
|
|
|
foreach ($query['args'] as $arg) {
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if (strpos($arg, 'confirm=') === false) {
|
2013-01-26 19:52:21 +00:00
|
|
|
|
$arg_parts = explode('=', $arg);
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$inputs[] = ['name' => $arg_parts[0], 'value' => $arg_parts[1]];
|
2013-01-26 19:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
|
return replace_macros(get_markup_template('confirm.tpl'), [
|
2013-01-26 19:52:21 +00:00
|
|
|
|
'$method' => 'get',
|
2018-01-21 18:33:59 +00:00
|
|
|
|
'$message' => L10n::t('Do you really want to delete this item?'),
|
2013-01-26 19:52:21 +00:00
|
|
|
|
'$extra_inputs' => $inputs,
|
2018-01-21 18:33:59 +00:00
|
|
|
|
'$confirm' => L10n::t('Yes'),
|
2013-01-26 19:52:21 +00:00
|
|
|
|
'$confirm_url' => $query['base'],
|
|
|
|
|
'$confirm_name' => 'confirmed',
|
2018-01-21 18:33:59 +00:00
|
|
|
|
'$cancel' => L10n::t('Cancel'),
|
2018-01-15 13:05:12 +00:00
|
|
|
|
]);
|
2013-01-26 19:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
// Now check how the user responded to the confirmation query
|
2016-10-22 10:14:41 +00:00
|
|
|
|
if ($_REQUEST['canceled']) {
|
2017-08-26 07:32:10 +00:00
|
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
|
2013-01-26 19:52:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-16 03:43:39 +00:00
|
|
|
|
// delete the item
|
2018-01-17 23:22:01 +00:00
|
|
|
|
Item::delete($item['id']);
|
2011-06-16 03:43:39 +00:00
|
|
|
|
|
2017-08-26 07:32:10 +00:00
|
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
|
2011-06-16 03:43:39 +00:00
|
|
|
|
//NOTREACHED
|
2016-10-22 10:14:41 +00:00
|
|
|
|
} else {
|
2018-01-21 18:33:59 +00:00
|
|
|
|
notice(L10n::t('Permission denied.') . EOL);
|
2017-08-26 07:32:10 +00:00
|
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
|
2011-06-16 03:43:39 +00:00
|
|
|
|
//NOTREACHED
|
|
|
|
|
}
|
2011-10-23 07:24:37 +00:00
|
|
|
|
}
|
2012-06-13 03:46:30 +00:00
|
|
|
|
|
2018-01-20 23:52:54 +00:00
|
|
|
|
/* arrange the list in years */
|
2015-05-18 23:03:08 +00:00
|
|
|
|
function list_post_dates($uid, $wall) {
|
2018-01-27 02:38:34 +00:00
|
|
|
|
$dnow = DateTimeFormat::localNow('Y-m-d');
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2018-01-28 11:18:08 +00:00
|
|
|
|
$dthen = Item::firstPostDate($uid, $wall);
|
|
|
|
|
if (!$dthen) {
|
2018-01-15 13:05:12 +00:00
|
|
|
|
return [];
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2015-05-18 23:03:08 +00:00
|
|
|
|
// Set the start and end date to the beginning of the month
|
2017-04-14 14:59:51 +00:00
|
|
|
|
$dnow = substr($dnow, 0, 8) . '01';
|
|
|
|
|
$dthen = substr($dthen, 0, 8) . '01';
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$ret = [];
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2017-04-08 17:30:35 +00: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 14:59:51 +00:00
|
|
|
|
$dyear = intval(substr($dnow, 0, 4));
|
|
|
|
|
$dstart = substr($dnow, 0, 8) . '01';
|
|
|
|
|
$dend = substr($dnow, 0, 8) . get_dim(intval($dnow), intval(substr($dnow, 5)));
|
2018-01-27 02:38:34 +00:00
|
|
|
|
$start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
|
|
|
|
|
$end_month = DateTimeFormat::utc($dend, 'Y-m-d');
|
|
|
|
|
$str = day_translate(DateTimeFormat::utc($dnow, 'F'));
|
2017-04-08 17:30:35 +00:00
|
|
|
|
if (!$ret[$dyear]) {
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$ret[$dyear] = [];
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$ret[$dyear][] = [$str, $end_month, $start_month];
|
2018-01-27 02:38:34 +00:00
|
|
|
|
$dnow = DateTimeFormat::utc($dnow . ' -1 month', 'Y-m-d');
|
2015-05-18 23:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-08 17:30:35 +00:00
|
|
|
|
function posted_date_widget($url, $uid, $wall) {
|
2012-06-13 03:46:30 +00:00
|
|
|
|
$o = '';
|
2012-06-13 23:17:45 +00:00
|
|
|
|
|
2018-01-28 11:18:08 +00:00
|
|
|
|
if (!Feature::isEnabled($uid, 'archives')) {
|
2012-11-22 16:14:22 +00:00
|
|
|
|
return $o;
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2012-11-22 16:14:22 +00:00
|
|
|
|
|
2012-06-13 23:17:45 +00:00
|
|
|
|
// For former Facebook folks that left because of "timeline"
|
2017-04-14 14:59:51 +00:00
|
|
|
|
/*
|
|
|
|
|
* @TODO old-lost code?
|
2017-11-07 02:22:52 +00:00
|
|
|
|
if ($wall && intval(PConfig::get($uid, 'system', 'no_wall_archive_widget')))
|
2017-04-14 14:59:51 +00:00
|
|
|
|
return $o;
|
|
|
|
|
*/
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2017-11-07 02:22:52 +00:00
|
|
|
|
$visible_years = PConfig::get($uid,'system','archive_visible_years');
|
2018-01-28 11:18:08 +00:00
|
|
|
|
if (!$visible_years) {
|
2015-06-02 16:59:46 +00:00
|
|
|
|
$visible_years = 5;
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2017-04-08 17:30:35 +00:00
|
|
|
|
$ret = list_post_dates($uid, $wall);
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2018-01-28 11:18:08 +00:00
|
|
|
|
if (!DBM::is_result($ret)) {
|
2012-06-13 03:46:30 +00:00
|
|
|
|
return $o;
|
2017-04-08 17:30:35 +00:00
|
|
|
|
}
|
2012-06-13 03:46:30 +00:00
|
|
|
|
|
2018-01-27 02:38:34 +00:00
|
|
|
|
$cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
|
2017-04-08 17:30:35 +00:00
|
|
|
|
$cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
|
2015-06-02 16:59:46 +00:00
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
|
$o = replace_macros(get_markup_template('posted_date_widget.tpl'),[
|
2018-01-21 18:33:59 +00:00
|
|
|
|
'$title' => L10n::t('Archives'),
|
2015-05-18 23:03:08 +00:00
|
|
|
|
'$size' => $visible_years,
|
|
|
|
|
'$cutoff_year' => $cutoff_year,
|
|
|
|
|
'$cutoff' => $cutoff,
|
2012-06-13 03:46:30 +00:00
|
|
|
|
'$url' => $url,
|
2015-05-18 23:03:08 +00:00
|
|
|
|
'$dates' => $ret,
|
2018-01-21 18:33:59 +00:00
|
|
|
|
'$showmore' => L10n::t('show more')
|
2015-05-18 23:03:08 +00:00
|
|
|
|
|
2018-01-15 13:05:12 +00:00
|
|
|
|
]);
|
2012-06-13 03:46:30 +00:00
|
|
|
|
return $o;
|
2012-06-29 19:40:54 +00:00
|
|
|
|
}
|