mode is handled by Conversation

This commit is contained in:
Domovoy 2012-08-11 18:12:35 +02:00
parent 1c36d14673
commit 9b6e99a6ba
2 changed files with 99 additions and 68 deletions

View File

@ -15,9 +15,62 @@ require_once('include/text.php');
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;
}
/**
@ -37,6 +90,7 @@ class Conversation extends BaseObject {
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);
}
@ -56,7 +110,7 @@ class Conversation extends BaseObject {
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;

View File

@ -16,13 +16,11 @@ class Item extends BaseObject {
'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;
@ -44,13 +42,11 @@ class Item extends BaseObject {
* _ 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 = '';
@ -67,13 +63,15 @@ class Item extends BaseObject {
$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
@ -87,7 +85,7 @@ class Item extends BaseObject {
'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']);
@ -126,7 +124,7 @@ class Item extends BaseObject {
$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.
@ -172,7 +170,7 @@ class Item extends BaseObject {
$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(
@ -203,7 +201,7 @@ class Item extends BaseObject {
}
}
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")),
@ -220,12 +218,12 @@ class Item extends BaseObject {
}
$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'],
@ -241,7 +239,7 @@ class Item extends BaseObject {
'$edvideo' => t('Video'),
'$preview' => t('Preview'),
'$sourceapp' => t($a->sourcename),
'$ww' => (($this->get_mode() === 'network') ? $commentww : '')
'$ww' => (($conv->get_mode() === 'network') ? $commentww : '')
));
}
}
@ -309,7 +307,7 @@ class Item extends BaseObject {
$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' : '');
@ -380,6 +378,15 @@ class Item extends BaseObject {
$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;
}
/**
@ -389,6 +396,7 @@ class Item extends BaseObject {
$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);
@ -406,6 +414,24 @@ class Item extends BaseObject {
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
*
@ -431,55 +457,6 @@ class Item extends BaseObject {
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
*/