Preparation for being able to comment every public item

This commit is contained in:
Michael 2017-12-19 17:15:56 +00:00
parent 6f7f839c67
commit b457ed6876
5 changed files with 80 additions and 71 deletions

View file

@ -497,7 +497,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$ssl_state = ((local_user()) ? true : false); $ssl_state = ((local_user()) ? true : false);
$profile_owner = 0; $profile_owner = 0;
$page_writeable = false;
$live_update_div = ''; $live_update_div = '';
$arr_blocked = null; $arr_blocked = null;
@ -517,7 +516,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
if ($mode === 'network') { if ($mode === 'network') {
$profile_owner = local_user(); $profile_owner = local_user();
$page_writeable = true;
if (!$update) { if (!$update) {
/* /*
* The special div is needed for liveUpdate to kick in for this page. * The special div is needed for liveUpdate to kick in for this page.
@ -545,7 +543,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
} }
} elseif ($mode === 'profile') { } elseif ($mode === 'profile') {
$profile_owner = $a->profile['profile_uid']; $profile_owner = $a->profile['profile_uid'];
$page_writeable = can_write_wall($a,$profile_owner);
if (!$update) { if (!$update) {
$tab = notags(trim($_GET['tab'])); $tab = notags(trim($_GET['tab']));
@ -563,7 +560,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
} }
} elseif ($mode === 'notes') { } elseif ($mode === 'notes') {
$profile_owner = local_user(); $profile_owner = local_user();
$page_writeable = true;
if (!$update) { if (!$update) {
$live_update_div = '<div id="live-notes"></div>' . "\r\n" $live_update_div = '<div id="live-notes"></div>' . "\r\n"
. "<script> var profile_uid = " . local_user() . "<script> var profile_uid = " . local_user()
@ -571,7 +567,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
} }
} elseif ($mode === 'display') { } elseif ($mode === 'display') {
$profile_owner = $a->profile['uid']; $profile_owner = $a->profile['uid'];
$page_writeable = can_write_wall($a,$profile_owner);
if (!$update) { if (!$update) {
$live_update_div = '<div id="live-display"></div>' . "\r\n" $live_update_div = '<div id="live-display"></div>' . "\r\n"
. "<script> var profile_uid = " . $_SESSION['uid'] . ";" . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
@ -579,7 +574,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
} }
} elseif ($mode === 'community') { } elseif ($mode === 'community') {
$profile_owner = 0; $profile_owner = 0;
$page_writeable = false;
if (!$update) { if (!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n" $live_update_div = '<div id="live-community"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n"; . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
@ -617,6 +611,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
$page_template = get_markup_template("conversation.tpl"); $page_template = get_markup_template("conversation.tpl");
if ($items && count($items)) { if ($items && count($items)) {
// Currently disabled. This is a preparation for the ability to comment and share every public item.
// $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA));
$writable = false;
if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') { if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
@ -832,7 +829,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
// Normal View // Normal View
$page_template = get_markup_template("threaded_conversation.tpl"); $page_template = get_markup_template("threaded_conversation.tpl");
$conv = new Thread($mode, $preview); $conv = new Thread($mode, $preview, $writable);
/* /*
* get all the topmost parents * get all the topmost parents

View file

@ -30,10 +30,11 @@ function display_init(App $a) {
} }
} }
$r = false;
// If there is only one parameter, then check if this parameter could be a guid // If there is only one parameter, then check if this parameter could be a guid
if ($a->argc == 2) { if ($a->argc == 2) {
$nick = ""; $nick = "";
$itemuid = 0;
$r = false; $r = false;
// Does the local user have this item? // Does the local user have this item?
@ -44,7 +45,6 @@ function display_init(App $a) {
AND `guid` = ? AND `uid` = ? LIMIT 1", $a->argv[1], local_user()); AND `guid` = ? AND `uid` = ? LIMIT 1", $a->argv[1], local_user());
if (DBM::is_result($r)) { if (DBM::is_result($r)) {
$nick = $a->user["nickname"]; $nick = $a->user["nickname"];
$itemuid = local_user();
} }
} }
@ -71,8 +71,22 @@ function display_init(App $a) {
AND `item`.`guid` = ? LIMIT 1", $a->argv[1]); AND `item`.`guid` = ? LIMIT 1", $a->argv[1]);
} }
if (DBM::is_result($r)) { if (!DBM::is_result($r)) {
$a->error = 404;
notice(t('Item not found.') . EOL);
return;
}
} elseif (($a->argc == 3) && ($nick == '_feed_')) {
$r = dba::fetch_first("SELECT `id`, `parent`, `author-name`, `author-link`,
`author-avatar`, `network`, `body`, `uid`, `owner-link`
FROM `item` WHERE `visible` AND NOT `deleted` AND NOT `moderated`
AND `allow_cid` = '' AND `allow_gid` = ''
AND `deny_cid` = '' AND `deny_gid` = ''
AND NOT `private` AND `uid` = 0
AND `id` = ? LIMIT 1", $a->argv[2]);
}
if (DBM::is_result($r)) {
if (strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) { if (strstr($_SERVER['HTTP_ACCEPT'], 'application/atom+xml')) {
logger('Directly serving XML for id '.$r["id"], LOGGER_DEBUG); logger('Directly serving XML for id '.$r["id"], LOGGER_DEBUG);
displayShowFeed($r["id"], false); displayShowFeed($r["id"], false);
@ -103,11 +117,6 @@ function display_init(App $a) {
$profiledata = array(); $profiledata = array();
} }
} }
} else {
$a->error = 404;
notice(t('Item not found.') . EOL);
return;
}
} }
profile_load($a, $nick, 0, $profiledata); profile_load($a, $nick, 0, $profiledata);
@ -223,6 +232,7 @@ function display_content(App $a, $update = 0) {
$item_id = (($a->argc > 2) ? $a->argv[2] : 0); $item_id = (($a->argc > 2) ? $a->argv[2] : 0);
if ($a->argc == 2) { if ($a->argc == 2) {
$item_parent = 0;
$nick = ""; $nick = "";
if (local_user()) { if (local_user()) {
@ -236,7 +246,19 @@ function display_content(App $a, $update = 0) {
} }
} }
if ($nick == "") { if ($item_parent == 0) {
$r = dba::fetch_first("SELECT `item`.`id`, `item`.`parent` FROM `item`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND NOT `item`.`private` AND `item`.`uid` = 0
AND `item`.`guid` = ?", $a->argv[1]);
if (DBM::is_result($r)) {
$item_id = $r["id"];
$item_parent = $r["parent"];
}
}
if ($item_parent == 0) {
$r = dba::fetch_first("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` $r = dba::fetch_first("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent` FROM `item` STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
@ -249,18 +271,6 @@ function display_content(App $a, $update = 0) {
$nick = $r["nickname"]; $nick = $r["nickname"];
} }
} }
if ($nick == "") {
$r = dba::fetch_first("SELECT `item`.`id`, `item`.`parent` FROM `item`
WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`
AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND NOT `item`.`private` AND `item`.`uid` = 0
AND `item`.`guid` = ?", $a->argv[1]);
if (DBM::is_result($r)) {
$item_id = $r["id"];
$item_parent = $r["parent"];
}
}
} }
} }
@ -283,6 +293,10 @@ function display_content(App $a, $update = 0) {
// We are displaying an "alternate" link if that post was public. See issue 2864 // We are displaying an "alternate" link if that post was public. See issue 2864
$is_public = dba::exists('item', array('id' => $item_id, 'private' => false)); $is_public = dba::exists('item', array('id' => $item_id, 'private' => false));
if ($is_public) { if ($is_public) {
// For the atom feed the nickname doesn't matter at all, we only need the item id.
if ($nick == '') {
$nick = '_feed_';
}
$alternate = System::baseUrl().'/display/'.$nick.'/'.$item_id.'.atom'; $alternate = System::baseUrl().'/display/'.$nick.'/'.$item_id.'.atom';
$conversation = System::baseUrl().'/display/'.$nick.'/'.$item_parent.'/conversation.atom'; $conversation = System::baseUrl().'/display/'.$nick.'/'.$item_parent.'/conversation.atom';
} else { } else {

View file

@ -145,7 +145,8 @@ class Post extends BaseObject
|| strlen($item['deny_cid']) || strlen($item['deny_gid'])))) || strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? t('Private Message') ? t('Private Message')
: false); : false);
$shareable = ((($conv->getProfileOwner() == local_user()) && ($item['private'] != 1)) ? true : false); $shareable = ((in_array($conv->getProfileOwner(), [0, local_user()]) && ($item['private'] != 1)) ? true : false);
if (local_user() && link_compare($a->contact['url'], $item['author-link'])) { if (local_user() && link_compare($a->contact['url'], $item['author-link'])) {
if ($item["event-id"] != 0) { if ($item["event-id"] != 0) {
$edpost = array("events/event/".$item['event-id'], t("Edit")); $edpost = array("events/event/".$item['event-id'], t("Edit"));

View file

@ -29,9 +29,9 @@ class Thread extends BaseObject
* @param string $mode The mode * @param string $mode The mode
* @param boolean $preview boolean value * @param boolean $preview boolean value
*/ */
public function __construct($mode, $preview) public function __construct($mode, $preview, $writable = false)
{ {
$this->setMode($mode); $this->setMode($mode, $writable);
$this->preview = $preview; $this->preview = $preview;
} }
@ -42,7 +42,7 @@ class Thread extends BaseObject
* *
* @return void * @return void
*/ */
private function setMode($mode) private function setMode($mode, $writable)
{ {
if ($this->getMode() == $mode) { if ($this->getMode() == $mode) {
return; return;
@ -62,7 +62,7 @@ class Thread extends BaseObject
break; break;
case 'display': case 'display':
$this->profile_owner = $a->profile['uid']; $this->profile_owner = $a->profile['uid'];
$this->writable = can_write_wall($a, $this->profile_owner); $this->writable = can_write_wall($a, $this->profile_owner) || $writable;
break; break;
default: default:
logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG); logger('[ERROR] Conversation::setMode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);

View file

@ -15,6 +15,7 @@ use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Protocol\OStatus; use Friendica\Protocol\OStatus;
use Friendica\Util\XML; use Friendica\Util\XML;
@ -341,18 +342,14 @@ class DFRN
$items = $r; $items = $r;
$item = $r[0]; $item = $r[0];
$r = q( if ($item['uid'] != 0) {
"SELECT `contact`.*, `user`.`nickname`, `user`.`timezone`, `user`.`page-flags`, `user`.`account-type` $owner = User::getOwnerDataById($item['uid']);
FROM `contact` INNER JOIN `user` ON `user`.`uid` = `contact`.`uid` if (!$owner) {
WHERE `contact`.`self` AND `user`.`uid` = %d LIMIT 1",
intval($item['uid'])
);
if (!DBM::is_result($r)) {
killme(); killme();
} }
else {
$owner = $r[0]; $owner = ['uid' => 0, 'nick' => '_feed_'];
}
$doc = new DOMDocument('1.0', 'utf-8'); $doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true; $doc->formatOutput = true;