class Conversation extends BaseObject {
private $threads = array();
private $mode = null;
+ private $writeable = false;
+ private $profile_owner = 0;
public function __construct($mode) {
- $this->mode = $mode;
+ $this->set_mode($mode);
+ }
+
+ /**
+ * Set the mode we'll be displayed on
+ */
+ private function set_mode($mode) {
+ if($this->get_mode() == $mode)
+ return;
+
+ $a = $this->get_app();
+
+ switch($mode) {
+ case 'network':
+ case 'notes':
+ $this->profile_owner = local_user();
+ $this->writeable = true;
+ break;
+ case 'profile':
+ $this->profile_owner = $a->profile['profile_uid'];
+ $this->writeable = can_write_wall($a,$this->profile_owner);
+ break;
+ case 'display':
+ $this->profile_owner = $a->profile['uid'];
+ $this->writeable = can_write_wall($a,$this->profile_owner);
+ break;
+ default:
+ logger('[ERROR] Conversation::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
+ return false;
+ break;
+ }
+ }
+
+ /**
+ * Get mode
+ */
+ public function get_mode() {
+ return $this->mode;
+ }
+
+ /**
+ * Check if page is writeable
+ */
+ public function is_writeable() {
+ return $this->writeable;
+ }
+
+ /**
+ * Get profile owner
+ */
+ public function get_profile_owner() {
+ return $this->profile_owner;
}
/**
logger('[WARN] Conversation::add_thread : Thread already exists ('. $item->get_id() .').', LOGGER_DEBUG);
return false;
}
+ $item->set_conversation($this);
$this->threads[] = $item;
return end($this->threads);
}
foreach($this->threads as $item) {
if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid'))
continue;
- $item_data = $item->get_template_data($cmnt_tpl, $this->mode, $alike, $dlike);
+ $item_data = $item->get_template_data($cmnt_tpl, $alike, $dlike);
if(!$item_data) {
logger('[ERROR] Conversation::get_template_data : Failed to get item template data ('. $item->get_id() .').', LOGGER_DEBUG);
return false;
'wall' => 'wall_thread.tpl',
'wall2wall' => 'wallwall_thread.tpl'
);
- private $mode = null;
- private $page_writeable = false;
- private $profile_owner = 0;
private $toplevel = false;
private $writeable = false;
private $children = array();
private $parent = null;
+ private $conversation = null;
public function __construct($data) {
$this->data = $data;
* _ The data requested on success
* _ false on failure
*/
- public function get_template_data($cmnt_tpl, $mode, $alike, $dlike) {
+ public function get_template_data($cmnt_tpl, $alike, $dlike) {
$result = array();
$a = $this->get_app();
- $this->set_mode($mode);
-
$item = $this->get_data();
$comment = '';
$firstcollapsed = false;
$total_children = $this->count_descendants();
- $show_comment_box = ((($this->is_page_writeable()) && ($this->is_writeable())) ? true : false);
+ $conv = $this->get_conversation();
+
+ $show_comment_box = ((($conv->is_writeable()) && ($this->is_writeable())) ? true : false);
$lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid'])
|| strlen($item['deny_cid']) || strlen($item['deny_gid']))))
? t('Private Message')
: false);
$redirect_url = $a->get_baseurl($ssl_state) . '/redir/' . $item['cid'] ;
- $shareable = ((($this->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false);
+ $shareable = ((($conv->get_profile_owner() == local_user()) && ($item['private'] != 1)) ? true : false);
if(local_user() && link_compare($a->contact['url'],$item['author-link']))
$edpost = array($a->get_baseurl($ssl_state)."/editpost/".$item['id'], t("Edit"));
else
'delete' => t('Delete'),
);
- $filer = (($this->get_profile_owner() == local_user()) ? t("save to folder") : false);
+ $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false);
$diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
$profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
$dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : '');
if($this->is_toplevel()) {
- if((! $item['self']) && ($this->get_mode() !== 'profile')) {
+ if((! $item['self']) && ($conv->get_mode() !== 'profile')) {
if($item['wall']) {
// On the network page, I am the owner. On the display page it will be the profile owner.
$owner_url = zrl($owner_url);
}
}
- if($this->get_profile_owner() == local_user()) {
+ if($conv->get_profile_owner() == local_user()) {
$isstarred = (($item['starred']) ? "starred" : "unstarred");
$star = array(
}
}
- if($this->is_page_writeable()) {
+ if($conv->is_writeable()) {
$buttons = array(
'like' => array( t("I like this \x28toggle\x29"), t("like")),
'dislike' => array( t("I don't like this \x28toggle\x29"), t("dislike")),
}
$comment = replace_macros($cmnt_tpl,array(
'$return_path' => '',
- '$jsreload' => (($this->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
- '$type' => (($this->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
+ '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
+ '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
'$id' => $item['item_id'],
'$parent' => $item['item_id'],
'$qcomment' => $qcomment,
- '$profile_uid' => $this->get_profile_owner(),
+ '$profile_uid' => $conv->get_profile_owner(),
'$mylink' => $a->contact['url'],
'$mytitle' => t('This is you'),
'$myphoto' => $a->contact['thumb'],
'$edvideo' => t('Video'),
'$preview' => t('Preview'),
'$sourceapp' => t($a->sourcename),
- '$ww' => (($this->get_mode() === 'network') ? $commentww : '')
+ '$ww' => (($conv->get_mode() === 'network') ? $commentww : '')
));
}
}
$item_result['children'] = array();
if(count($item['children'])) {
- $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, $conv->is_writeable(), $conv->get_mode(), $conv->get_profile_owner(), $alike, $dlike, ($thread_level + 1));
}
$item_result['private'] = $item['private'];
$item_result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
$parent->remove_child($this);
}
$this->parent = $item;
+ $this->set_conversation($item->get_conversation());
+ }
+
+ /**
+ * Remove our parent
+ */
+ protected function remove_parent() {
+ $this->parent = null;
+ $this->conversation = null;
}
/**
$id = $item->get_id();
foreach($this->get_children() as $key => $child) {
if($child->get_id() == $id) {
+ $child->remove_parent();
unset($this->children[$key]);
// Reindex the array, in order to make sure there won't be any trouble on loops using count()
$this->children = array_values($this->children);
return $this->parent;
}
+ /**
+ * set conversation
+ */
+ public function set_conversation($conv) {
+ $this->conversation = $conv;
+
+ // Set it on our children too
+ foreach($this->get_children() as $child)
+ $child->set_conversation($conv);
+ }
+
+ /**
+ * get conversation
+ */
+ public function get_conversation() {
+ return $this->conversation;
+ }
+
/**
* Get raw data
*
return $this->data[$name];
}
- /**
- * Set the mode we'll be displayed on
- */
- private function set_mode($mode) {
- if($this->get_mode() == $mode)
- return;
-
- switch($mode) {
- case 'network':
- case 'notes':
- $this->profile_owner = local_user();
- $this->page_writeable = true;
- break;
- case 'profile':
- $this->profile_owner = $a->profile['profile_uid'];
- $this->page_writeable = can_write_wall($a,$this->profile_owner);
- break;
- case 'display':
- $this->profile_owner = $a->profile['uid'];
- $this->page_writeable = can_write_wall($a,$this->profile_owner);
- break;
- default:
- logger('[ERROR] Item::set_mode : Unhandled mode ('. $mode .').', LOGGER_DEBUG);
- return false;
- break;
- }
- }
-
- /**
- * Get mode
- */
- private function get_mode() {
- return $this->mode;
- }
-
- /**
- * Get profile owner
- */
- private function get_profile_owner() {
- return $this->profile_owner;
- }
-
- /**
- * Get page writable
- */
- private function is_page_writeable() {
- return $this->page_writeable;
- }
-
/**
* Set template
*/