taming the wild mod_display

This commit is contained in:
friendica 2013-02-10 17:03:33 -08:00
parent 2cfd73c57d
commit 90c1ecca24
2 changed files with 36 additions and 37 deletions

View File

@ -15,6 +15,7 @@ class Item extends BaseObject {
private $comment_box_template = 'comment_item.tpl'; private $comment_box_template = 'comment_item.tpl';
private $toplevel = false; private $toplevel = false;
private $writable = false; private $writable = false;
private $commentable = false;
private $children = array(); private $children = array();
private $parent = null; private $parent = null;
private $conversation = null; private $conversation = null;
@ -37,35 +38,31 @@ class Item extends BaseObject {
$this->toplevel = ($this->get_id() == $this->get_data_value('parent')); $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
// if(is_array($_SESSION['remote'])) {
// foreach($_SESSION['remote'] as $visitor) {
// if($visitor['cid'] == $this->get_data_value('contact-id')) {
// $this->visiting = true;
// break;
// }
// }
// }
// fixme $this->writable = (((local_user()) && ($this->channel['channel_hash'] === $this->data['owner_xchan'])) ? true : false);
$this->writable = ($this->get_data_value('writable') || $this->get_data_value('self')); $this->commentable = $this->writable;
// FIXME - base this on observer permissions
$this->writable = ((local_user() && $channel['channel_hash'] === $item['owner_xchan']) ? true : false); if(($this->observer) && (! $this->writable)) {
$this->commentable = perm_is_allowed($this->data['uid'],$this->observer['xchan_hash'],'post_comments');
}
// logger('writable: ' . $this->writable);
// logger('commentable: ' . $this->commentable . ' uid=' . $this->data['uid'] . ' observer=' . $this->observer['xchan_hash']);
if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) // if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel())
$this->threaded = true; // $this->threaded = true;
// Prepare the children // Prepare the children
if(count($data['children'])) { if(count($data['children'])) {
foreach($data['children'] as $item) { foreach($data['children'] as $item) {
/* /*
* Only add will be displayed * Only add thos that will be displayed
*/ */
if(! visible_activity($item)) { if(! visible_activity($item)) {
continue; continue;
} }
$child = new Item($item); $child = new Item($item);
$this->add_child($child); $this->add_child($child);
} }
@ -102,11 +99,11 @@ class Item extends BaseObject {
$conv = $this->get_conversation(); $conv = $this->get_conversation();
$lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) $lock = ((($item['item_private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| 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->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false); $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['item_private'] != 1)) ? true : false);
if(local_user() && $observer['xchan_hash'] === $item['author_xchan']) if(local_user() && $observer['xchan_hash'] === $item['author_xchan'])
$edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit")); $edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
@ -177,7 +174,7 @@ class Item extends BaseObject {
$indent = 'comment'; $indent = 'comment';
} }
if($conv->is_writable()) { if($this->is_writable()) {
$like = array( t("I like this \x28toggle\x29"), t("like")); $like = array( t("I like this \x28toggle\x29"), t("like"));
$dislike = array( t("I don't like this \x28toggle\x29"), t("dislike")); $dislike = array( t("I don't like this \x28toggle\x29"), t("dislike"));
if ($shareable) if ($shareable)
@ -458,16 +455,22 @@ class Item extends BaseObject {
* Check if this is writable * Check if this is writable
*/ */
private function is_writable() { private function is_writable() {
$conv = $this->get_conversation();
return true; return $this->writable;
// $conv = $this->get_conversation();
if($conv) { // return true;
// if($conv) {
// This will allow us to comment on wall-to-wall items owned by our friends // This will allow us to comment on wall-to-wall items owned by our friends
// and community forums even if somebody else wrote the post. // and community forums even if somebody else wrote the post.
return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'channel')); // return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'channel'));
} // }
return $this->writable; }
private function is_commentable() {
return $this->commentable;
} }
/** /**
@ -507,11 +510,10 @@ class Item extends BaseObject {
$comment_box = ''; $comment_box = '';
$conv = $this->get_conversation(); $conv = $this->get_conversation();
$observer = get_app()->get_observer(); if(! $this->is_commentable())
if(! perm_is_allowed($conv->get_profile_owner(),$observer['xchan_hash'],'post_comments')) return;
return '';
if($conv->is_writable() && $this->is_writable()) { if($conv->is_writable() || $this->is_writable()) {
$template = get_markup_template($this->get_comment_box_template()); $template = get_markup_template($this->get_comment_box_template());
$a = $this->get_app(); $a = $this->get_app();

View File

@ -14,7 +14,6 @@ function display_content(&$a, $update = 0, $load = false) {
require_once('include/acl_selectors.php'); require_once('include/acl_selectors.php');
require_once('include/items.php'); require_once('include/items.php');
// $o = '<div id="live-display"></div>' . "\r\n";
$a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array()); $a->page['htmlhead'] .= replace_macros(get_markup_template('display-head.tpl'), array());
@ -43,11 +42,11 @@ function display_content(&$a, $update = 0, $load = false) {
// find a copy of the item somewhere // find a copy of the item somewhere
$target_item = null; $target_item = null;
dbg(1);
$r = q("select uri, parent_uri from item where uri = '%s' limit 1", $r = q("select uri, parent_uri from item where uri = '%s' limit 1",
dbesc($item_hash) dbesc($item_hash)
); );
dbg(0);
if($r) { if($r) {
$target_item = $r[0]; $target_item = $r[0];
} }
@ -94,7 +93,7 @@ dbg(0);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
if($load) { if($load) {
dbg(1);
$r = q("SELECT * from item $r = q("SELECT * from item
WHERE item_restrict = 0 WHERE item_restrict = 0
and uri = '%s' and uri = '%s'
@ -105,7 +104,7 @@ dbg(1);
group by uri limit 1", group by uri limit 1",
dbesc($target_item['parent_uri']) dbesc($target_item['parent_uri'])
); );
dbg(0);
} }
else { else {
$r = array(); $r = array();
@ -116,7 +115,6 @@ dbg(0);
$parents_str = ids_to_querystr($r,'id'); $parents_str = ids_to_querystr($r,'id');
if($parents_str) { if($parents_str) {
dbg(1);
$items = q("SELECT `item`.*, `item`.`id` AS `item_id` $items = q("SELECT `item`.*, `item`.`id` AS `item_id`
FROM `item` FROM `item`
@ -124,7 +122,6 @@ dbg(0);
dbesc($parents_str) dbesc($parents_str)
); );
dbg(0);
xchan_query($items); xchan_query($items);
$items = fetch_post_tags($items); $items = fetch_post_tags($items);
$items = conv_sort($items,'created'); $items = conv_sort($items,'created');