2011-04-11 06:21:16 +02:00
|
|
|
<?php
|
2017-11-16 19:24:59 +01:00
|
|
|
/**
|
|
|
|
* @file include/conversation.php
|
|
|
|
*/
|
2018-01-25 03:08:45 +01:00
|
|
|
|
2017-04-30 06:07:00 +02:00
|
|
|
use Friendica\App;
|
2018-01-10 04:42:04 +01:00
|
|
|
use Friendica\Content\ContactSelector;
|
2017-12-04 15:04:36 +01:00
|
|
|
use Friendica\Content\Feature;
|
2018-02-05 01:23:49 +01:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-01-17 19:42:40 +01:00
|
|
|
use Friendica\Core\Addon;
|
2017-11-07 03:22:52 +01:00
|
|
|
use Friendica\Core\Config;
|
2018-01-21 23:15:52 +01:00
|
|
|
use Friendica\Core\L10n;
|
2017-11-07 03:22:52 +01:00
|
|
|
use Friendica\Core\PConfig;
|
2017-08-26 08:04:21 +02:00
|
|
|
use Friendica\Core\System;
|
2017-11-08 04:57:46 +01:00
|
|
|
use Friendica\Database\DBM;
|
2017-12-08 05:33:36 +01:00
|
|
|
use Friendica\Model\Contact;
|
2018-01-15 03:22:39 +01:00
|
|
|
use Friendica\Model\Profile;
|
2017-12-08 05:33:36 +01:00
|
|
|
use Friendica\Object\Post;
|
2018-01-25 03:08:45 +01:00
|
|
|
use Friendica\Object\Thread;
|
2018-01-27 03:38:34 +01:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2018-02-03 18:25:58 +01:00
|
|
|
use Friendica\Util\Temporal;
|
|
|
|
use Friendica\Util\XML;
|
2017-04-30 06:07:00 +02:00
|
|
|
|
2012-07-08 00:20:24 +02:00
|
|
|
function item_extract_images($body) {
|
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
$saved_image = [];
|
2012-09-10 10:36:30 +02:00
|
|
|
$orig_body = $body;
|
|
|
|
$new_body = '';
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$cnt = 0;
|
|
|
|
$img_start = strpos($orig_body, '[img');
|
|
|
|
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
|
|
|
|
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
|
2017-04-04 19:46:56 +02:00
|
|
|
while (($img_st_close !== false) && ($img_end !== false)) {
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$img_st_close++; // make it point to AFTER the closing bracket
|
|
|
|
$img_end += $img_start;
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2018-02-27 10:29:11 +01:00
|
|
|
if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
|
2012-09-10 10:36:30 +02:00
|
|
|
// This is an embedded image
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
|
|
|
|
$new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
|
2012-07-08 02:47:13 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$cnt++;
|
2017-04-08 19:05:50 +02:00
|
|
|
} else {
|
2012-09-10 10:36:30 +02:00
|
|
|
$new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
|
2017-04-08 19:05:50 +02:00
|
|
|
}
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$orig_body = substr($orig_body, $img_end + strlen('[/img]'));
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
if ($orig_body === false) {
|
|
|
|
// in case the body ends on a closing image tag
|
2012-09-10 10:36:30 +02:00
|
|
|
$orig_body = '';
|
2017-04-08 19:05:50 +02:00
|
|
|
}
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$img_start = strpos($orig_body, '[img');
|
|
|
|
$img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
|
|
|
|
$img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
|
|
|
|
}
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$new_body = $new_body . $orig_body;
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2018-01-15 14:05:12 +01:00
|
|
|
return ['body' => $new_body, 'images' => $saved_image];
|
2017-12-12 05:52:33 +01:00
|
|
|
}
|
2012-07-08 00:20:24 +02:00
|
|
|
|
|
|
|
function item_redir_and_replace_images($body, $images, $cid) {
|
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$origbody = $body;
|
|
|
|
$newbody = '';
|
|
|
|
|
|
|
|
$cnt = 1;
|
2018-02-05 01:23:49 +01:00
|
|
|
$pos = BBCode::getTagPosition($origbody, 'url', 0);
|
2017-04-04 19:46:56 +02:00
|
|
|
while ($pos !== false && $cnt < 1000) {
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
|
2017-08-26 09:32:10 +02:00
|
|
|
$replace = '[url=' . System::baseUrl() . '/redir/' . $cid
|
2012-09-10 10:36:30 +02:00
|
|
|
. '?f=1&url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
|
|
|
|
|
|
|
|
$newbody .= substr($origbody, 0, $pos['start']['open']);
|
|
|
|
$subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
|
|
|
|
$origbody = substr($origbody, $pos['end']['close']);
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($origbody === false) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$origbody = '';
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$subject = preg_replace($search, $replace, $subject);
|
|
|
|
$newbody .= $subject;
|
|
|
|
|
|
|
|
$cnt++;
|
2018-02-05 01:23:49 +01:00
|
|
|
// Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
|
|
|
|
$pos = BBCode::getTagPosition($origbody, 'url', 0);
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
$newbody .= $origbody;
|
|
|
|
|
|
|
|
$cnt = 0;
|
2016-12-20 21:13:50 +01:00
|
|
|
foreach ($images as $image) {
|
2017-04-08 19:05:50 +02:00
|
|
|
/*
|
|
|
|
* We're depending on the property of 'foreach' (specified on the PHP website) that
|
|
|
|
* it loops over the array starting from the first element and going sequentially
|
|
|
|
* to the last element.
|
|
|
|
*/
|
2012-09-10 10:36:30 +02:00
|
|
|
$newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
|
|
|
|
$cnt++;
|
|
|
|
}
|
|
|
|
return $newbody;
|
2017-12-12 05:52:33 +01:00
|
|
|
}
|
2012-07-08 00:20:24 +02:00
|
|
|
|
2011-04-18 17:37:02 +02:00
|
|
|
/**
|
|
|
|
* Render actions localized
|
|
|
|
*/
|
2017-04-08 20:00:54 +02:00
|
|
|
function localize_item(&$item) {
|
2012-02-15 03:07:13 +01:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$extracted = item_extract_images($item['body']);
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($extracted['images']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
/// @TODO Separted ???
|
2017-04-08 20:00:54 +02:00
|
|
|
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
2017-04-08 19:05:50 +02:00
|
|
|
if (activity_match($item['verb'], ACTIVITY_LIKE)
|
|
|
|
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
|
|
|
|
|| activity_match($item['verb'], ACTIVITY_ATTEND)
|
|
|
|
|| activity_match($item['verb'], ACTIVITY_ATTENDNO)
|
2017-04-08 20:00:54 +02:00
|
|
|
|| activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
/// @TODO may hurt performance
|
|
|
|
$r = q("SELECT * FROM `item`, `contact`
|
|
|
|
WHERE `item`.`contact-id`=`contact`.`id`
|
|
|
|
AND `item`.`uri`='%s'",
|
|
|
|
dbesc($item['parent-uri']));
|
2017-11-08 04:57:46 +01:00
|
|
|
if (!DBM::is_result($r)) {
|
2017-04-08 19:05:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$obj = $r[0];
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
|
|
|
|
$objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]';
|
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
switch ($obj['verb']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case ACTIVITY_POST:
|
2017-04-08 19:05:50 +02:00
|
|
|
switch ($obj['object-type']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case ACTIVITY_OBJ_EVENT:
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('event');
|
2012-09-10 10:36:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('status');
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-04-08 19:05:50 +02:00
|
|
|
if ($obj['resource-id']) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('photo');
|
2018-01-15 14:05:12 +01:00
|
|
|
$m = [];
|
2017-04-08 19:05:50 +02:00
|
|
|
preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
|
2012-09-10 10:36:30 +02:00
|
|
|
$rr['plink'] = $m[1];
|
|
|
|
} else {
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('status');
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
}
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
if (activity_match($item['verb'], ACTIVITY_LIKE)) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
|
2017-04-08 19:05:50 +02:00
|
|
|
} elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
|
2017-04-08 19:05:50 +02:00
|
|
|
} elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
|
2017-04-08 19:05:50 +02:00
|
|
|
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
|
2017-04-08 19:05:50 +02:00
|
|
|
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
|
2015-10-08 22:23:09 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
2017-04-08 19:05:50 +02:00
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
|
|
|
|
|
|
|
|
$Aname = $item['author-name'];
|
|
|
|
$Alink = $item['author-link'];
|
|
|
|
|
|
|
|
$xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
|
|
|
|
|
2018-01-27 17:13:41 +01:00
|
|
|
$obj = XML::parseString($xmlhead.$item['object']);
|
|
|
|
$links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$Bname = $obj->title;
|
|
|
|
$Blink = ""; $Bphoto = "";
|
2017-04-08 20:00:54 +02:00
|
|
|
foreach ($links->link as $l) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$atts = $l->attributes();
|
2017-04-08 20:00:54 +02:00
|
|
|
switch ($atts['rel']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case "alternate": $Blink = $atts['href'];
|
|
|
|
case "photo": $Bphoto = $atts['href'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 03:22:39 +01:00
|
|
|
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
|
|
|
|
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($Bphoto != "") {
|
2018-01-15 03:22:39 +01:00
|
|
|
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2018-01-24 13:18:21 +01:00
|
|
|
$item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
}
|
2017-04-08 19:05:50 +02:00
|
|
|
if (stristr($item['verb'], ACTIVITY_POKE)) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1));
|
2018-02-27 10:29:11 +01:00
|
|
|
if (!$verb) {
|
2012-09-10 10:36:30 +02:00
|
|
|
return;
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
|
|
|
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$Aname = $item['author-name'];
|
|
|
|
$Alink = $item['author-link'];
|
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2018-01-27 17:13:41 +01:00
|
|
|
$obj = XML::parseString($xmlhead.$item['object']);
|
|
|
|
$links = XML::parseString($xmlhead."<links>".unxmlify($obj->link)."</links>");
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$Bname = $obj->title;
|
2017-04-08 20:00:54 +02:00
|
|
|
$Blink = "";
|
|
|
|
$Bphoto = "";
|
|
|
|
foreach ($links->link as $l) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$atts = $l->attributes();
|
2017-04-08 20:00:54 +02:00
|
|
|
switch ($atts['rel']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case "alternate": $Blink = $atts['href'];
|
|
|
|
case "photo": $Bphoto = $atts['href'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-15 03:22:39 +01:00
|
|
|
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
|
|
|
|
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($Bphoto != "") {
|
2018-01-15 03:22:39 +01:00
|
|
|
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
/*
|
|
|
|
* we can't have a translation string with three positions but no distinguishable text
|
|
|
|
* So here is the translate string.
|
|
|
|
*/
|
2018-01-21 17:38:01 +01:00
|
|
|
$txt = L10n::t('%1$s poked %2$s');
|
2015-10-04 21:17:28 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
// now translate the verb
|
2017-04-08 20:00:54 +02:00
|
|
|
$poked_t = trim(sprintf($txt, "", ""));
|
2018-01-21 17:38:01 +01:00
|
|
|
$txt = str_replace( $poked_t, L10n::t($verb), $txt);
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
// then do the sprintf on the translation string
|
|
|
|
|
|
|
|
$item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
if (activity_match($item['verb'], ACTIVITY_TAG)) {
|
2017-04-08 20:00:54 +02:00
|
|
|
/// @TODO may hurt performance "joining" two tables + asterisk
|
|
|
|
$r = q("SELECT * FROM `item`, `contact`
|
|
|
|
WHERE `item`.`contact-id`=`contact`.`id`
|
|
|
|
AND `item`.`uri`='%s'",
|
|
|
|
dbesc($item['parent-uri']));
|
|
|
|
|
2017-11-08 04:57:46 +01:00
|
|
|
if (!DBM::is_result($r)) {
|
2017-04-08 20:00:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = $r[0];
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2018-01-15 03:22:39 +01:00
|
|
|
$author = '[url=' . Profile::zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
|
|
|
|
$objauthor = '[url=' . Profile::zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
switch ($obj['verb']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case ACTIVITY_POST:
|
2017-04-08 20:00:54 +02:00
|
|
|
switch ($obj['object-type']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
case ACTIVITY_OBJ_EVENT:
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('event');
|
2012-09-10 10:36:30 +02:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('status');
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($obj['resource-id']) {
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('photo');
|
2018-01-15 14:05:12 +01:00
|
|
|
$m=[]; preg_match("/\[url=([^]]*)\]/", $obj['body'], $m);
|
2012-09-10 10:36:30 +02:00
|
|
|
$rr['plink'] = $m[1];
|
|
|
|
} else {
|
2018-01-21 17:38:01 +01:00
|
|
|
$post_type = L10n::t('status');
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
2017-04-08 20:00:54 +02:00
|
|
|
// Let's break everthing ... ;-)
|
|
|
|
break;
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
$plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]';
|
|
|
|
|
2018-01-27 17:13:41 +01:00
|
|
|
$parsedobj = XML::parseString($xmlhead.$item['object']);
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content);
|
2018-01-24 13:18:21 +01:00
|
|
|
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-04-08 19:05:50 +02:00
|
|
|
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
|
2017-04-08 20:00:54 +02:00
|
|
|
if ($item['object-type'] == "") {
|
2012-09-10 10:36:30 +02:00
|
|
|
return;
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
$Aname = $item['author-name'];
|
|
|
|
$Alink = $item['author-link'];
|
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
2012-09-10 10:36:30 +02:00
|
|
|
|
2018-01-27 17:13:41 +01:00
|
|
|
$obj = XML::parseString($xmlhead.$item['object']);
|
2017-04-04 19:46:56 +02:00
|
|
|
if (strlen($obj->id)) {
|
2017-04-08 20:00:54 +02:00
|
|
|
$r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
|
2012-09-10 10:36:30 +02:00
|
|
|
dbesc($obj->id),
|
|
|
|
intval($item['uid'])
|
|
|
|
);
|
2017-04-08 20:00:54 +02:00
|
|
|
|
2017-11-08 04:57:46 +01:00
|
|
|
if (DBM::is_result($r) && $r[0]['plink']) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$target = $r[0];
|
|
|
|
$Bname = $target['author-name'];
|
|
|
|
$Blink = $target['author-link'];
|
2018-01-15 03:22:39 +01:00
|
|
|
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
|
|
|
|
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
|
2018-01-21 17:38:01 +01:00
|
|
|
$P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
|
2018-01-24 13:18:21 +01:00
|
|
|
$item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$matches = null;
|
2017-04-08 20:00:54 +02:00
|
|
|
if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
|
2017-04-04 19:46:56 +02:00
|
|
|
foreach ($matches as $mtch) {
|
2018-02-27 10:29:11 +01:00
|
|
|
if (!strpos($mtch[1], 'zrl=')) {
|
2018-01-15 03:22:39 +01:00
|
|
|
$item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']);
|
2017-04-08 20:00:54 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add zrl's to public images
|
2016-01-15 23:32:13 +01:00
|
|
|
$photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
|
2017-04-08 20:00:54 +02:00
|
|
|
if (preg_match($photo_pattern, $item['body'])) {
|
2018-01-15 03:22:39 +01:00
|
|
|
$photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
|
2018-02-05 01:23:49 +01:00
|
|
|
$item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
|
2016-01-15 23:32:13 +01:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
|
|
|
|
// add sparkle links to appropriate permalinks
|
|
|
|
|
|
|
|
$x = stristr($item['plink'],'/display/');
|
2016-12-20 11:38:16 +01:00
|
|
|
if ($x) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$sparkle = false;
|
2017-08-19 11:22:50 +02:00
|
|
|
$y = best_link_url($item, $sparkle);
|
2016-12-20 11:38:16 +01:00
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
if (strstr($y, '/redir/')) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$item['plink'] = $y . '?f=&url=' . $item['plink'];
|
2016-12-20 11:38:16 +01:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
}
|
2011-04-18 17:37:02 +02:00
|
|
|
}
|
|
|
|
|
2012-08-07 09:53:53 +02:00
|
|
|
/**
|
|
|
|
* Count the total of comments on this item and its desendants
|
2017-04-08 20:00:54 +02:00
|
|
|
* @TODO proper type-hint + doc-tag
|
2012-08-07 09:53:53 +02:00
|
|
|
*/
|
|
|
|
function count_descendants($item) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$total = count($item['children']);
|
|
|
|
|
2017-04-04 19:46:56 +02:00
|
|
|
if ($total > 0) {
|
|
|
|
foreach ($item['children'] as $child) {
|
2018-02-27 10:29:11 +01:00
|
|
|
if (!visible_activity($child)) {
|
2012-09-10 10:36:30 +02:00
|
|
|
$total --;
|
2017-04-08 20:03:21 +02:00
|
|
|
}
|
2012-09-10 10:36:30 +02:00
|
|
|
$total += count_descendants($child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $total;
|
2012-08-07 09:53:53 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 05:12:55 +02:00
|
|
|
function visible_activity($item) {
|
|
|
|
|
2017-04-08 20:00:54 +02:00
|
|
|
/*
|
|
|
|
* likes (etc.) can apply to other things besides posts. Check if they are post children,
|
|
|
|
* in which case we handle them specially
|
|
|
|
*/
|
2018-01-15 14:05:12 +01:00
|
|
|
$hidden_activities = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
|
2017-04-04 19:46:56 +02:00
|
|
|
foreach ($hidden_activities as $act) {
|
2017-04-09 00:28:24 +02:00
|
|
|
if (activity_match($item['verb'], $act)) {
|
2015-06-01 01:23:04 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-09-19 05:12:55 +02:00
|
|
|
|
2018-05-14 22:25:39 +02:00
|
|
|
// @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
|
|
|
|
if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
|
2018-05-13 16:58:40 +02:00
|
|
|
return false;
|
2012-09-28 04:53:55 +02:00
|
|
|
}
|
2012-09-19 05:12:55 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-19 01:07:20 +02:00
|
|
|
/**
|
|
|
|
* @brief SQL query for items
|
2018-05-26 20:07:27 +02:00
|
|
|
*
|
|
|
|
* @param int $uid user id
|
2016-06-19 01:07:20 +02:00
|
|
|
*/
|
2018-05-26 20:07:27 +02:00
|
|
|
function item_query($uid = 0) {
|
2017-04-09 00:28:24 +02:00
|
|
|
return "SELECT " . item_fieldlists() . " FROM `item` " .
|
2018-05-26 20:07:27 +02:00
|
|
|
item_joins($uid) . " WHERE " . item_condition();
|
2016-06-19 01:07:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-06-19 08:32:38 +02:00
|
|
|
* @brief List of all data fields that are needed for displaying items
|
2016-06-19 01:07:20 +02:00
|
|
|
*/
|
|
|
|
function item_fieldlists() {
|
|
|
|
|
2016-06-13 22:20:09 +02:00
|
|
|
/*
|
|
|
|
These Fields are not added below (yet). They are here to for bug search.
|
|
|
|
`item`.`type`,
|
|
|
|
`item`.`extid`,
|
|
|
|
`item`.`changed`,
|
2016-06-19 01:07:20 +02:00
|
|
|
`item`.`moderated`,
|
2016-06-13 22:20:09 +02:00
|
|
|
`item`.`target-type`,
|
|
|
|
`item`.`target`,
|
|
|
|
`item`.`resource-id`,
|
|
|
|
`item`.`tag`,
|
|
|
|
`item`.`inform`,
|
|
|
|
`item`.`pubmail`,
|
|
|
|
`item`.`visible`,
|
|
|
|
`item`.`spam`,
|
|
|
|
`item`.`bookmark`,
|
|
|
|
`item`.`unseen`,
|
|
|
|
`item`.`deleted`,
|
|
|
|
`item`.`forum_mode`,
|
|
|
|
`item`.`mention`,
|
|
|
|
`item`.`global`,
|
|
|
|
`item`.`shadow`,
|
|
|
|
*/
|
|
|
|
|
2017-03-06 11:07:17 +01:00
|
|
|
return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
|
|
|
|
`item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
|
2016-06-19 08:32:38 +02:00
|
|
|
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
|
2018-03-14 23:28:35 +01:00
|
|
|
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`,
|
2017-07-31 08:04:37 +02:00
|
|
|
`item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
|
2016-06-19 08:32:38 +02:00
|
|
|
`item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`,
|
2018-05-15 23:06:34 +02:00
|
|
|
`item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, `item`.`origin`,
|
2016-06-19 08:32:38 +02:00
|
|
|
`item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`,
|
2016-09-04 18:06:07 +02:00
|
|
|
`item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`,
|
2016-09-03 12:48:51 +02:00
|
|
|
`item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`,
|
2016-06-19 08:32:38 +02:00
|
|
|
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
|
|
|
|
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
|
|
|
|
|
|
|
|
`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
|
|
|
|
|
|
|
|
`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
|
2017-10-11 21:51:18 +02:00
|
|
|
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
|
|
|
|
|
|
|
|
`event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`,
|
|
|
|
`event`.`start` AS `event-start`,`event`.`finish` AS `event-finish`,
|
|
|
|
`event`.`summary` AS `event-summary`,`event`.`desc` AS `event-desc`,
|
|
|
|
`event`.`location` AS `event-location`, `event`.`type` AS `event-type`,
|
|
|
|
`event`.`nofinish` AS `event-nofinish`,`event`.`adjust` AS `event-adjust`,
|
2017-10-11 22:45:03 +02:00
|
|
|
`event`.`ignore` AS `event-ignore`, `event`.`id` AS `event-id`";
|
2016-06-12 21:04:55 +02:00
|
|
|
}
|
2012-09-19 17:38:32 +02:00
|
|
|
|
2016-06-12 23:06:48 +02:00
|
|
|
/**
|
2016-06-19 08:32:38 +02:00
|
|
|
* @brief SQL join for contacts that are needed for displaying items
|
2018-05-26 20:07:27 +02:00
|
|
|
*
|
|
|
|
* @param int $uid user id
|
2016-06-19 08:32:38 +02:00
|
|
|
*/
|
2018-05-26 20:07:27 +02:00
|
|
|
function item_joins($uid = 0) {
|
2018-04-28 13:47:02 +02:00
|
|
|
return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
2018-04-29 18:32:46 +02:00
|
|
|
AND NOT `contact`.`blocked`
|
|
|
|
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
|
2018-05-11 00:06:34 +02:00
|
|
|
OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0)
|
2018-05-04 23:27:20 +02:00
|
|
|
INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
|
|
|
|
INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
|
2018-05-26 20:07:27 +02:00
|
|
|
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
|
2018-04-28 13:47:02 +02:00
|
|
|
LEFT JOIN `event` ON `event-id` = `event`.`id`",
|
2018-05-26 20:07:27 +02:00
|
|
|
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid)
|
2018-04-28 13:47:02 +02:00
|
|
|
);
|
2016-06-19 08:32:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SQL condition for items that are needed for displaying items
|
2016-06-12 23:06:48 +02:00
|
|
|
*/
|
|
|
|
function item_condition() {
|
2018-05-26 20:07:27 +02:00
|
|
|
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
|
2016-06-12 23:06:48 +02:00
|
|
|
}
|
|
|
|
|
2011-04-13 02:58:16 +02:00
|
|
|
/**
|
|
|
|
* "Render" a conversation or list of items for HTML display.
|
|
|
|
* There are two major forms of display:
|
|
|
|
* - Sequential or unthreaded ("New Item View" or search results)
|
|
|
|
* - conversation view
|
|
|
|
* The $mode parameter decides between the various renderings and also
|
2012-09-10 09:19:08 +02:00
|
|
|
* figures out how to determine page owner and other contextual items
|
2011-04-13 02:58:16 +02:00
|
|
|
* that are based on unique features of the calling module.
|
|
|
|
*
|
|
|
|
*/
|
2018-05-26 20:07:27 +02:00
|
|
|
function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) {
|
2017-04-08 19:05:50 +02:00
|
|
|
require_once 'mod/proxy.php';
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$ssl_state = ((local_user()) ? true : false);
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$profile_owner = 0;
|
2012-10-09 17:41:33 +02:00
|
|
|
$live_update_div = '';
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2013-04-29 06:02:53 +02:00
|
|
|
$arr_blocked = null;
|
|
|
|
|
2017-04-04 19:46:56 +02:00
|
|
|
if (local_user()) {
|
2017-11-07 03:22:52 +01:00
|
|
|
$str_blocked = PConfig::get(local_user(), 'system', 'blocked');
|
2017-04-04 19:46:56 +02:00
|
|
|
if ($str_blocked) {
|
2017-04-08 20:05:32 +02:00
|
|
|
$arr_blocked = explode(',', $str_blocked);
|
2017-04-04 19:46:56 +02:00
|
|
|
for ($x = 0; $x < count($arr_blocked); $x ++) {
|
2013-04-29 06:02:53 +02:00
|
|
|
$arr_blocked[$x] = trim($arr_blocked[$x]);
|
2017-04-04 19:46:56 +02:00
|
|
|
}
|
2013-04-29 06:02:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-09-10 10:36:30 +02:00
|
|
|
$previewing = (($preview) ? ' preview ' : '');
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2017-04-04 19:46:56 +02:00
|
|
|
if ($mode === 'network') {
|
2018-05-26 20:07:27 +02:00
|
|
|
$items = conversation_add_children($items, false, $order, $uid);
|
2012-09-10 10:36:30 +02:00
|
|
|
$profile_owner = local_user();
|
2017-04-04 19:46:56 +02:00
|
|
|
if (!$update) {
|
2017-04-08 19:05:50 +02:00
|
|
|
/*
|
|
|
|
* The special div is needed for liveUpdate to kick in for this page.
|
|
|
|
* We only launch liveUpdate if you aren't filtering in some incompatible
|
|
|
|
* way and also you aren't writing a comment (discovered in javascript).
|
|
|
|
*/
|
2012-10-09 17:41:33 +02:00
|
|
|
$live_update_div = '<div id="live-network"></div>' . "\r\n"
|
2015-10-08 00:25:55 +02:00
|
|
|
. "<script> var profile_uid = " . $_SESSION['uid']
|
2017-04-08 19:05:50 +02:00
|
|
|
. "; var netargs = '" . substr($a->cmd, 8)
|
2012-10-09 17:41:33 +02:00
|
|
|
. '?f='
|
2017-04-08 19:05:50 +02:00
|
|
|
. ((x($_GET, 'cid')) ? '&cid=' . $_GET['cid'] : '')
|
|
|
|
. ((x($_GET, 'search')) ? '&search=' . $_GET['search'] : '')
|
|
|
|
. ((x($_GET, 'star')) ? '&star=' . $_GET['star'] : '')
|
|
|
|
. ((x($_GET, 'order')) ? '&order=' . $_GET['order'] : '')
|
|
|
|
. ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
|
|
|
|
. ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
|
|
|
|
. ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
|
|
|
|
. ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
|
|
|
|
. ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
|
|
|
|
. ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
|
|
|
|
. ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
|
|
|
|
. ((x($_GET, 'file')) ? '&file=' . $_GET['file'] : '')
|
2012-10-09 17:41:33 +02:00
|
|
|
|
|
|
|
. "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
|
|
|
|
}
|
2017-04-08 19:05:50 +02:00
|
|
|
} elseif ($mode === 'profile') {
|
2012-09-10 10:36:30 +02:00
|
|
|
$profile_owner = $a->profile['profile_uid'];
|
2012-09-10 09:19:08 +02:00
|
|
|
|
2017-04-04 19:46:56 +02:00
|
|
|
if (!$update) {
|
2018-01-01 21:27:33 +01:00
|
|
|
$tab = 'posts';
|
|
|
|
if (x($_GET, 'tab')) {
|
|
|
|
$tab = notags(trim($_GET['tab']));
|
|
|
|
}
|
2017-04-04 19:46:56 +02:00
|
|
|
if ($tab === 'posts') {
|
2017-04-08 19:05:50 +02:00
|
|
|
/*
|
|
|
|
* This is ugly, but we can't pass the profile_uid through the session to the ajax updater,
|
|
|
|