Beatification/coding convention:

- added a lot spaces to make it look nicer
- added curly braces (coding convention)
- added needed spaces (coding convention)get_id
- removed obsolete $a = get_app() call

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-22 11:21:50 +01:00
parent d242e72c65
commit 41da37ae67

View file

@ -52,21 +52,22 @@ class Item extends BaseObject {
$ssl_state = ((local_user()) ? true : false); $ssl_state = ((local_user()) ? true : false);
$this->redirect_url = 'redir/' . $this->get_data_value('cid') ; $this->redirect_url = 'redir/' . $this->get_data_value('cid') ;
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 will be displayed
*/ */
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue; continue;
} } elseif (! visible_activity($item)) {
if(! visible_activity($item)) {
continue; continue;
} }
$item['pagedrop'] = $data['pagedrop']; $item['pagedrop'] = $data['pagedrop'];
$child = new Item($item); $child = new Item($item);
$this->add_child($child); $this->add_child($child);
@ -91,11 +92,11 @@ class Item extends BaseObject {
$item = $this->get_data(); $item = $this->get_data();
$edited = false; $edited = false;
if (strcmp($item['created'], $item['edited'])<>0) { if (strcmp($item['created'], $item['edited'])<>0) {
$edited = array( $edited = array(
'label' => t('This entry was edited'), 'label' => t('This entry was edited'),
'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'),
'relative' => relative_date($item['edited']) 'relative' => relative_date($item['edited'])
); );
} }
$commentww = ''; $commentww = '';
$sparkle = ''; $sparkle = '';
@ -111,7 +112,6 @@ 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['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')
@ -134,22 +134,24 @@ class Item extends BaseObject {
$drop = array( $drop = array(
'dropping' => $dropping, 'dropping' => $dropping,
'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''), 'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''),
'select' => t('Select'), 'select' => t('Select'),
'delete' => t('Delete'), 'delete' => t('Delete'),
); );
$filer = (($conv->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); $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true);
$profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); $profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
if($item['author-link'] && (! $item['author-name'])) if ($item['author-link'] && (! $item['author-name'])) {
$profile_name = $item['author-link']; $profile_name = $item['author-link'];
}
$sp = false; $sp = false;
$profile_link = best_link_url($item,$sp); $profile_link = best_link_url($item,$sp);
if ($profile_link === 'mailbox') { if ($profile_link === 'mailbox') {
$profile_link = ''; $profile_link = '';
} }
if ($sp) { if ($sp) {
$sparkle = ' sparkle'; $sparkle = ' sparkle';
} else { } else {
@ -198,13 +200,14 @@ class Item extends BaseObject {
// process action responses - e.g. like/dislike/attend/agree/whatever // process action responses - e.g. like/dislike/attend/agree/whatever
$response_verbs = array('like'); $response_verbs = array('like');
if(feature_enabled($conv->get_profile_owner(),'dislike')) if (feature_enabled($conv->get_profile_owner(),'dislike')) {
$response_verbs[] = 'dislike'; $response_verbs[] = 'dislike';
if($item['object-type'] === ACTIVITY_OBJ_EVENT) { }
if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
$response_verbs[] = 'attendyes'; $response_verbs[] = 'attendyes';
$response_verbs[] = 'attendno'; $response_verbs[] = 'attendno';
$response_verbs[] = 'attendmaybe'; $response_verbs[] = 'attendmaybe';
if($conv->is_writable()) { if ($conv->is_writable()) {
$isevent = true; $isevent = true;
$attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); $attend = array( t('I will attend'), t('I will not attend'), t('I might attend'));
} }
@ -213,8 +216,7 @@ class Item extends BaseObject {
$responses = get_responses($conv_responses,$response_verbs,$this,$item); $responses = get_responses($conv_responses,$response_verbs,$this,$item);
foreach ($response_verbs as $value=>$verbs) { foreach ($response_verbs as $value=>$verbs) {
$responses[$verbs][output] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : ''); $responses[$verbs]['output'] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : '');
} }
/* /*
@ -224,20 +226,21 @@ class Item extends BaseObject {
*/ */
$this->check_wall_to_wall(); $this->check_wall_to_wall();
if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) if ($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) {
$osparkle = ' sparkle'; $osparkle = ' sparkle';
}
if($this->is_toplevel()) { if ($this->is_toplevel()) {
if($conv->get_profile_owner() == local_user()) { if ($conv->get_profile_owner() == local_user()) {
$isstarred = (($item['starred']) ? "starred" : "unstarred"); $isstarred = (($item['starred']) ? "starred" : "unstarred");
$star = array( $star = array(
'do' => t("add star"), 'do' => t("add star"),
'undo' => t("remove star"), 'undo' => t("remove star"),
'toggle' => t("toggle star status"), 'toggle' => t("toggle star status"),
'classdo' => (($item['starred']) ? "hidden" : ""), 'classdo' => (($item['starred']) ? "hidden" : ""),
'classundo' => (($item['starred']) ? "" : "hidden"), 'classundo' => (($item['starred']) ? "" : "hidden"),
'starred' => t('starred'), 'starred' => t('starred'),
); );
$r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1",
intval($item['uid']), intval($item['uid']),
@ -245,19 +248,19 @@ class Item extends BaseObject {
); );
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$ignore = array( $ignore = array(
'do' => t("ignore thread"), 'do' => t("ignore thread"),
'undo' => t("unignore thread"), 'undo' => t("unignore thread"),
'toggle' => t("toggle ignore status"), 'toggle' => t("toggle ignore status"),
'classdo' => (($r[0]['ignored']) ? "hidden" : ""), 'classdo' => (($r[0]['ignored']) ? "hidden" : ""),
'classundo' => (($r[0]['ignored']) ? "" : "hidden"), 'classundo' => (($r[0]['ignored']) ? "" : "hidden"),
'ignored' => t('ignored'), 'ignored' => t('ignored'),
); );
} }
$tagger = ''; $tagger = '';
if(feature_enabled($conv->get_profile_owner(),'commtag')) { if(feature_enabled($conv->get_profile_owner(),'commtag')) {
$tagger = array( $tagger = array(
'add' => t("add tag"), 'add' => t("add tag"),
'class' => "", 'class' => "",
); );
} }
@ -266,17 +269,19 @@ class Item extends BaseObject {
$indent = 'comment'; $indent = 'comment';
} }
if($conv->is_writable()) { if ($conv->is_writable()) {
$buttons = array( $buttons = array(
'like' => array( t("I like this \x28toggle\x29"), t("like")), 'like' => array( t("I like this \x28toggle\x29"), t("like")),
'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''),
); );
if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); if ($shareable) {
$buttons['share'] = array( t('Share this'), t('share'));
}
} }
$comment = $this->get_comment_box($indent); $comment = $this->get_comment_box($indent);
if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){ if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){
$shiny = 'shiny'; $shiny = 'shiny';
} }
@ -298,8 +303,9 @@ class Item extends BaseObject {
foreach ($languages as $language) { foreach ($languages as $language) {
$langdata = explode(";", $language); $langdata = explode(";", $language);
if ($langstr != "") if ($langstr != "") {
$langstr .= ", "; $langstr .= ", ";
}
//$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)"; //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
$langstr .= round($langdata[1]*100, 1)."% ".$langdata[0]; $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
@ -311,20 +317,19 @@ class Item extends BaseObject {
list($categories, $folders) = get_cats_and_terms($item); list($categories, $folders) = get_cats_and_terms($item);
if($a->theme['template_engine'] === 'internal') { if ($a->theme['template_engine'] === 'internal') {
$body_e = template_escape($body); $body_e = template_escape($body);
$text_e = strip_tags(template_escape($body)); $text_e = strip_tags(template_escape($body));
$name_e = template_escape($profile_name); $name_e = template_escape($profile_name);
$title_e = template_escape($item['title']); $title_e = template_escape($item['title']);
$location_e = template_escape($location); $location_e = template_escape($location);
$owner_name_e = template_escape($this->get_owner_name()); $owner_name_e = template_escape($this->get_owner_name());
} } else {
else { $body_e = $body;
$body_e = $body; $text_e = strip_tags($body);
$text_e = strip_tags($body); $name_e = $profile_name;
$name_e = $profile_name; $title_e = $item['title'];
$title_e = $item['title']; $location_e = $location;
$location_e = $location;
$owner_name_e = $this->get_owner_name(); $owner_name_e = $this->get_owner_name();
} }
@ -334,89 +339,93 @@ class Item extends BaseObject {
$tagger = ''; $tagger = '';
} }
if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);
}
if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);
}
// Diaspora isn't able to do likes on comments - but red does // Diaspora isn't able to do likes on comments - but red does
if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
!diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);
}
// Diaspora doesn't has multithreaded comments // Diaspora doesn't has multithreaded comments
if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) {
unset($comment); unset($comment);
}
// Facebook can like comments - but it isn't programmed in the connector yet. // Facebook can like comments - but it isn't programmed in the connector yet.
if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);
}
$tmp_item = array( $tmp_item = array(
'template' => $this->get_template(), 'template' => $this->get_template(),
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
'type' => implode("",array_slice(explode("/",$item['verb']),-1)), 'tags' => $item['tags'],
'tags' => $item['tags'], 'hashtags' => $item['hashtags'],
'hashtags' => $item['hashtags'], 'mentions' => $item['mentions'],
'mentions' => $item['mentions'], 'txt_cats' => t('Categories:'),
'txt_cats' => t('Categories:'), 'txt_folders' => t('Filed under:'),
'txt_folders' => t('Filed under:'), 'has_cats' => ((count($categories)) ? 'true' : ''),
'has_cats' => ((count($categories)) ? 'true' : ''), 'has_folders' => ((count($folders)) ? 'true' : ''),
'has_folders' => ((count($folders)) ? 'true' : ''), 'categories' => $categories,
'categories' => $categories, 'folders' => $folders,
'folders' => $folders, 'body' => $body_e,
'body' => $body_e, 'text' => $text_e,
'text' => $text_e, 'id' => $this->get_id(),
'id' => $this->get_id(), 'guid' => urlencode($item['guid']),
'guid' => urlencode($item['guid']), 'isevent' => $isevent,
'isevent' => $isevent, 'attend' => $attend,
'attend' => $attend, 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])),
'olinktitle' => sprintf( t('View %s\'s profile @ %s'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), 'to' => t('to'),
'to' => t('to'), 'via' => t('via'),
'via' => t('via'), 'wall' => t('Wall-to-Wall'),
'wall' => t('Wall-to-Wall'), 'vwall' => t('via Wall-To-Wall:'),
'vwall' => t('via Wall-To-Wall:'), 'profile_url' => $profile_link,
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item), 'item_photo_menu' => item_photo_menu($item),
'name' => $name_e, 'name' => $name_e,
'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
'osparkle' => $osparkle, 'osparkle' => $osparkle,
'sparkle' => $sparkle, 'sparkle' => $sparkle,
'title' => $title_e, 'title' => $title_e,
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
'app' => $item['app'], 'app' => $item['app'],
'created' => relative_date($item['created']), 'created' => relative_date($item['created']),
'lock' => $lock, 'lock' => $lock,
'location' => $location_e, 'location' => $location_e,
'indent' => $indent, 'indent' => $indent,
'shiny' => $shiny, 'shiny' => $shiny,
'owner_url' => $this->get_owner_url(), 'owner_url' => $this->get_owner_url(),
'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
'owner_name' => htmlentities($owner_name_e), 'owner_name' => htmlentities($owner_name_e),
'plink' => get_plink($item), 'plink' => get_plink($item),
'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''),
'isstarred' => $isstarred, 'isstarred' => $isstarred,
'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''), 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''),
'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''), 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''),
'tagger' => $tagger, 'tagger' => $tagger,
'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''), 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''),
'drop' => $drop, 'drop' => $drop,
'vote' => $buttons, 'vote' => $buttons,
'like' => $responses['like']['output'], 'like' => $responses['like']['output'],
'dislike' => $responses['dislike']['output'], 'dislike' => $responses['dislike']['output'],
'responses' => $responses, 'responses' => $responses,
'switchcomment' => t('Comment'), 'switchcomment' => t('Comment'),
'comment' => $comment, 'comment' => $comment,
'previewing' => ($conv->is_preview() ? ' preview ' : ''), 'previewing' => ($conv->is_preview() ? ' preview ' : ''),
'wait' => t('Please wait'), 'wait' => t('Please wait'),
'thread_level' => $thread_level, 'thread_level' => $thread_level,
'postopts' => $langstr, 'postopts' => $langstr,
'edited' => $edited, 'edited' => $edited,
'network' => $item["item_network"], 'network' => $item["item_network"],
'network_name' => network_to_name($item['item_network'], $profile_link), 'network_name' => network_to_name($item['item_network'], $profile_link),
); );
$arr = array('item' => $item, 'output' => $tmp_item); $arr = array('item' => $item, 'output' => $tmp_item);
@ -427,39 +436,37 @@ class Item extends BaseObject {
$result['children'] = array(); $result['children'] = array();
$children = $this->get_children(); $children = $this->get_children();
$nb_children = count($children); $nb_children = count($children);
if($nb_children > 0) { if ($nb_children > 0) {
foreach($children as $child) { foreach ($children as $child) {
$result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1); $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
} }
// Collapse // Collapse
if(($nb_children > 2) || ($thread_level > 1)) { if (($nb_children > 2) || ($thread_level > 1)) {
$result['children'][0]['comment_firstcollapsed'] = true; $result['children'][0]['comment_firstcollapsed'] = true;
$result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children );
$result['children'][0]['hidden_comments_num'] = $total_children; $result['children'][0]['hidden_comments_num'] = $total_children;
$result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children); $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children);
$result['children'][0]['hide_text'] = t('show more'); $result['children'][0]['hide_text'] = t('show more');
if($thread_level > 1) { if ($thread_level > 1) {
$result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
} } else {
else {
$result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
} }
} }
} }
if ($this->is_toplevel()) { if ($this->is_toplevel()) {
$result['total_comments_num'] = "$total_children"; $result['total_comments_num'] = "$total_children";
$result['total_comments_text'] = tt('comment', 'comments', $total_children); $result['total_comments_text'] = tt('comment', 'comments', $total_children);
} }
$result['private'] = $item['private']; $result['private'] = $item['private'];
$result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
if($this->is_threaded()) { if ($this->is_threaded()) {
$result['flatten'] = false; $result['flatten'] = false;
$result['threaded'] = true; $result['threaded'] = true;
} } else {
else {
$result['flatten'] = true; $result['flatten'] = true;
$result['threaded'] = false; $result['threaded'] = false;
} }
@ -478,23 +485,21 @@ class Item extends BaseObject {
/** /**
* Add a child item * Add a child item
*/ */
public function add_child($item) { public function add_child(Item $item) {
$item_id = $item->get_id(); $item_id = $item->get_id();
if(!$item_id) { if (!$item_id) {
logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG); logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
return false; return false;
} } elseif ($this->get_child($item->get_id())) {
if($this->get_child($item->get_id())) {
logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG); logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
return false; return false;
} }
/* /*
* Only add what will be displayed * Only add what will be displayed
*/ */
if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) {
return false; return false;
} } elseif (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
return false; return false;
} }
@ -507,9 +512,10 @@ class Item extends BaseObject {
* Get a child by its ID * Get a child by its ID
*/ */
public function get_child($id) { public function get_child($id) {
foreach($this->get_children() as $child) { foreach ($this->get_children() as $child) {
if($child->get_id() == $id) if ($child->get_id() == $id) {
return $child; return $child;
}
} }
return null; return null;
} }
@ -546,8 +552,8 @@ class Item extends BaseObject {
*/ */
public function remove_child($item) { public function remove_child($item) {
$id = $item->get_id(); $id = $item->get_id();
foreach($this->get_children() as $key => $child) { foreach ($this->get_children() as $key => $child) {
if($child->get_id() == $id) { if ($child->get_id() == $id) {
$child->remove_parent(); $child->remove_parent();
unset($this->children[$key]); unset($this->children[$key]);
// Reindex the array, in order to make sure there won't be any trouble on loops using count() // Reindex the array, in order to make sure there won't be any trouble on loops using count()
@ -575,8 +581,9 @@ class Item extends BaseObject {
$this->conversation = $conv; $this->conversation = $conv;
// Set it on our children too // Set it on our children too
foreach($this->get_children() as $child) foreach ($this->get_children() as $child) {
$child->set_conversation($conv); $child->set_conversation($conv);
}
} }
/** /**
@ -603,7 +610,7 @@ class Item extends BaseObject {
* _ false on failure * _ false on failure
*/ */
public function get_data_value($name) { public function get_data_value($name) {
if(!isset($this->data[$name])) { if (!isset($this->data[$name])) {
// logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); // logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG);
return false; return false;
} }
@ -615,9 +622,7 @@ class Item extends BaseObject {
* Set template * Set template
*/ */
private function set_template($name) { private function set_template($name) {
$a = get_app(); if (!x($this->available_templates, $name)) {
if(!x($this->available_templates, $name)) {
logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG); logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG);
return false; return false;
} }
@ -645,13 +650,14 @@ class Item extends BaseObject {
private function is_writable() { private function is_writable() {
$conv = $this->get_conversation(); $conv = $this->get_conversation();
if($conv) { 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.
// bug #517 - this fixes for conversation owner // bug #517 - this fixes for conversation owner
if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) if ($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) {
return true; return true;
}
// this fixes for visitors // this fixes for visitors
return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile')); return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
@ -665,8 +671,8 @@ class Item extends BaseObject {
private function count_descendants() { private function count_descendants() {
$children = $this->get_children(); $children = $this->get_children();
$total = count($children); $total = count($children);
if($total > 0) { if ($total > 0) {
foreach($children as $child) { foreach ($children as $child) {
$total += $child->count_descendants(); $total += $child->count_descendants();
} }
} }
@ -689,7 +695,7 @@ class Item extends BaseObject {
*/ */
private function get_comment_box($indent) { private function get_comment_box($indent) {
$a = $this->get_app(); $a = $this->get_app();
if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) { if (!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) {
return ''; return '';
} }
@ -697,48 +703,48 @@ class Item extends BaseObject {
$conv = $this->get_conversation(); $conv = $this->get_conversation();
$template = get_markup_template($this->get_comment_box_template()); $template = get_markup_template($this->get_comment_box_template());
$ww = ''; $ww = '';
if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) if ( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
$ww = 'ww'; $ww = 'ww';
if($conv->is_writable() && $this->is_writable()) { if ($conv->is_writable() && $this->is_writable()) {
$qc = $qcomment = null; $qc = $qcomment = null;
/* /*
* Hmmm, code depending on the presence of a particular plugin? * Hmmm, code depending on the presence of a particular plugin?
* This should be better if done by a hook * This should be better if done by a hook
*/ */
if(in_array('qcomment',$a->plugins)) { if (in_array('qcomment',$a->plugins)) {
$qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null);
$qcomment = (($qc) ? explode("\n",$qc) : null); $qcomment = (($qc) ? explode("\n",$qc) : null);
} }
$comment_box = replace_macros($template,array( $comment_box = replace_macros($template,array(
'$return_path' => $a->query_string, '$return_path' => $a->query_string,
'$threaded' => $this->is_threaded(), '$threaded' => $this->is_threaded(),
// '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), // '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''),
'$jsreload' => '', '$jsreload' => '',
'$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'),
'$id' => $this->get_id(), '$id' => $this->get_id(),
'$parent' => $this->get_id(), '$parent' => $this->get_id(),
'$qcomment' => $qcomment, '$qcomment' => $qcomment,
'$profile_uid' => $conv->get_profile_owner(), '$profile_uid' => $conv->get_profile_owner(),
'$mylink' => $a->remove_baseurl($a->contact['url']), '$mylink' => $a->remove_baseurl($a->contact['url']),
'$mytitle' => t('This is you'), '$mytitle' => t('This is you'),
'$myphoto' => $a->remove_baseurl($a->contact['thumb']), '$myphoto' => $a->remove_baseurl($a->contact['thumb']),
'$comment' => t('Comment'), '$comment' => t('Comment'),
'$submit' => t('Submit'), '$submit' => t('Submit'),
'$edbold' => t('Bold'), '$edbold' => t('Bold'),
'$editalic' => t('Italic'), '$editalic' => t('Italic'),
'$eduline' => t('Underline'), '$eduline' => t('Underline'),
'$edquote' => t('Quote'), '$edquote' => t('Quote'),
'$edcode' => t('Code'), '$edcode' => t('Code'),
'$edimg' => t('Image'), '$edimg' => t('Image'),
'$edurl' => t('Link'), '$edurl' => t('Link'),
'$edvideo' => t('Video'), '$edvideo' => t('Video'),
'$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''),
'$indent' => $indent, '$indent' => $indent,
'$sourceapp' => t($a->sourcename), '$sourceapp' => t($a->sourcename),
'$ww' => (($conv->get_mode() === 'network') ? $ww : ''), '$ww' => (($conv->get_mode() === 'network') ? $ww : ''),
'$rand_num' => random_digits(12) '$rand_num' => random_digits(12)
)); ));
} }
@ -768,14 +774,13 @@ class Item extends BaseObject {
$this->owner_photo = $a->page_contact['thumb']; $this->owner_photo = $a->page_contact['thumb'];
$this->owner_name = $a->page_contact['name']; $this->owner_name = $a->page_contact['name'];
$this->wall_to_wall = true; $this->wall_to_wall = true;
} } elseif($this->get_data_value('owner-link')) {
else if($this->get_data_value('owner-link')) {
$owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link')));
$alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link')));
$owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name')); $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name'));
if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) {
// The author url doesn't match the owner (typically the contact) // The author url doesn't match the owner (typically the contact)
// and also doesn't match the contact alias. // and also doesn't match the contact alias.
@ -791,18 +796,18 @@ class Item extends BaseObject {
$this->owner_name = $this->get_data_value('owner-name'); $this->owner_name = $this->get_data_value('owner-name');
$this->wall_to_wall = true; $this->wall_to_wall = true;
// If it is our contact, use a friendly redirect link // If it is our contact, use a friendly redirect link
if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) if ((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url')))
&& ($this->get_data_value('network') === NETWORK_DFRN)) { && ($this->get_data_value('network') === NETWORK_DFRN)) {
$this->owner_url = $this->get_redirect_url(); $this->owner_url = $this->get_redirect_url();
} } else {
else
$this->owner_url = zrl($this->get_data_value('owner-link')); $this->owner_url = zrl($this->get_data_value('owner-link'));
}
} }
} }
} }
} }
if(!$this->wall_to_wall) { if (!$this->wall_to_wall) {
$this->set_template('wall'); $this->set_template('wall');
$this->owner_url = ''; $this->owner_url = '';
$this->owner_photo = ''; $this->owner_photo = '';
@ -830,8 +835,6 @@ class Item extends BaseObject {
return $this->visiting; return $this->visiting;
} }
} }
/// @TODO These are discouraged and should be removed:
?> ?>