Item: new method is_toplevel

This commit is contained in:
Domovoy 2012-08-11 17:09:35 +02:00
parent 1ffca59a9e
commit 531801ff50

View file

@ -19,10 +19,12 @@ class Item extends BaseObject {
private $mode = null; private $mode = null;
private $page_writeable = false; private $page_writeable = false;
private $profile_owner = 0; private $profile_owner = 0;
private $toplevel = false;
public function __construct($data) { public function __construct($data) {
$this->data = $data; $this->data = $data;
$this->set_template('wall'); $this->set_template('wall');
$this->toplevel = ($this->get_id() == $this->get_parent());
} }
/** /**
@ -55,7 +57,6 @@ class Item extends BaseObject {
$firstcollapsed = false; $firstcollapsed = false;
$total_children += count_descendants($item); $total_children += count_descendants($item);
$toplevelpost = (($item['id'] == $item['parent']) ? true : false);
$item_writeable = (($item['writable'] || $item['self']) ? true : false); $item_writeable = (($item['writable'] || $item['self']) ? true : false);
$show_comment_box = ((($this->is_page_writeable()) && ($item_writeable)) ? true : false); $show_comment_box = ((($this->is_page_writeable()) && ($item_writeable)) ? true : false);
$lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
@ -115,7 +116,7 @@ class Item extends BaseObject {
$like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : '');
$dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
if($toplevelpost) { if($this->is_toplevel()) {
if((! $item['self']) && ($this->get_mode() !== 'profile')) { if((! $item['self']) && ($this->get_mode() !== 'profile')) {
if($item['wall']) { if($item['wall']) {
@ -302,7 +303,7 @@ class Item extends BaseObject {
$item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), $alike, $dlike, ($thread_level + 1)); $item_result['children'] = prepare_threads_body($a, $item['children'], $cmnt_tpl, $this->is_page_writeable(), $this->get_mode(), $this->get_profile_owner(), $alike, $dlike, ($thread_level + 1));
} }
$item_result['private'] = $item['private']; $item_result['private'] = $item['private'];
$item_result['toplevel'] = ($toplevelpost ? 'toplevel_item' : ''); $item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
if(get_config('system','thread_allow')) { if(get_config('system','thread_allow')) {
$item_result['flatten'] = false; $item_result['flatten'] = false;
@ -311,7 +312,7 @@ class Item extends BaseObject {
else { else {
$item_result['flatten'] = true; $item_result['flatten'] = true;
$item_result['threaded'] = false; $item_result['threaded'] = false;
if(!$toplevelpost) { if(!$htis->is_toplevel()) {
$item_result['comment'] = false; $item_result['comment'] = false;
} }
} }
@ -336,6 +337,10 @@ class Item extends BaseObject {
public function get_thumb() { public function get_thumb() {
return $this->get_data_value('thumb'); return $this->get_data_value('thumb');
} }
public function get_parent() {
return $this->get_data_value('parent');
}
/** /**
* Get raw data * Get raw data
@ -428,5 +433,12 @@ class Item extends BaseObject {
private function get_template() { private function get_template() {
return $this->template; return $this->template;
} }
/**
* Check if this is a toplevel post
*/
private function is_toplevel() {
return $this->toplevel;
}
} }
?> ?>