1
0
Fork 0

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 b2ffde3f6b
commit dfc2c1f805

View file

@ -52,21 +52,22 @@ class Item extends BaseObject {
$ssl_state = ((local_user()) ? true : false);
$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;
}
// Prepare the children
if(count($data['children'])) {
foreach($data['children'] as $item) {
if (count($data['children'])) {
foreach ($data['children'] as $item) {
/*
* Only add will be displayed
*/
if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue;
}
if(! visible_activity($item)) {
if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) {
continue;
} elseif (! visible_activity($item)) {
continue;
}
$item['pagedrop'] = $data['pagedrop'];
$child = new Item($item);
$this->add_child($child);
@ -111,7 +112,6 @@ class Item extends BaseObject {
$conv = $this->get_conversation();
$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')
@ -142,14 +142,16 @@ class Item extends BaseObject {
$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']);
if($item['author-link'] && (! $item['author-name']))
if ($item['author-link'] && (! $item['author-name'])) {
$profile_name = $item['author-link'];
}
$sp = false;
$profile_link = best_link_url($item,$sp);
if ($profile_link === 'mailbox') {
$profile_link = '';
}
if ($sp) {
$sparkle = ' sparkle';
} else {
@ -198,13 +200,14 @@ class Item extends BaseObject {
// process action responses - e.g. like/dislike/attend/agree/whatever
$response_verbs = array('like');
if(feature_enabled($conv->get_profile_owner(),'dislike'))
if (feature_enabled($conv->get_profile_owner(),'dislike')) {
$response_verbs[] = 'dislike';
if($item['object-type'] === ACTIVITY_OBJ_EVENT) {
}
if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
$response_verbs[] = 'attendyes';
$response_verbs[] = 'attendno';
$response_verbs[] = 'attendmaybe';
if($conv->is_writable()) {
if ($conv->is_writable()) {
$isevent = true;
$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);
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,11 +226,12 @@ class Item extends BaseObject {
*/
$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';
}
if($this->is_toplevel()) {
if($conv->get_profile_owner() == local_user()) {
if ($this->is_toplevel()) {
if ($conv->get_profile_owner() == local_user()) {
$isstarred = (($item['starred']) ? "starred" : "unstarred");
$star = array(
@ -266,17 +269,19 @@ class Item extends BaseObject {
$indent = 'comment';
}
if($conv->is_writable()) {
if ($conv->is_writable()) {
$buttons = array(
'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")) : ''),
);
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);
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';
}
@ -298,8 +303,9 @@ class Item extends BaseObject {
foreach ($languages as $language) {
$langdata = explode(";", $language);
if ($langstr != "")
if ($langstr != "") {
$langstr .= ", ";
}
//$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)";
$langstr .= round($langdata[1]*100, 1)."% ".$langdata[0];
@ -311,15 +317,14 @@ class Item extends BaseObject {
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);
$text_e = strip_tags(template_escape($body));
$name_e = template_escape($profile_name);
$title_e = template_escape($item['title']);
$location_e = template_escape($location);
$owner_name_e = template_escape($this->get_owner_name());
}
else {
} else {
$body_e = $body;
$text_e = strip_tags($body);
$name_e = $profile_name;
@ -334,28 +339,32 @@ class Item extends BaseObject {
$tagger = '';
}
if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"]))
if (($item["item_network"] == NETWORK_FEED) AND isset($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"]);
}
// Diaspora isn't able to do likes on comments - but red does
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"]);
}
// 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);
}
// 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"]);
}
$tmp_item = array(
'template' => $this->get_template(),
'type' => implode("",array_slice(explode("/",$item['verb']),-1)),
'tags' => $item['tags'],
'hashtags' => $item['hashtags'],
@ -427,21 +436,20 @@ class Item extends BaseObject {
$result['children'] = array();
$children = $this->get_children();
$nb_children = count($children);
if($nb_children > 0) {
foreach($children as $child) {
if ($nb_children > 0) {
foreach ($children as $child) {
$result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1);
}
// Collapse
if(($nb_children > 2) || ($thread_level > 1)) {
if (($nb_children > 2) || ($thread_level > 1)) {
$result['children'][0]['comment_firstcollapsed'] = true;
$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_text'] = tt('comment', 'comments', $total_children);
$result['children'][0]['hide_text'] = t('show more');
if($thread_level > 1) {
if ($thread_level > 1) {
$result['children'][$nb_children - 1]['comment_lastcollapsed'] = true;
}
else {
} else {
$result['children'][$nb_children - 3]['comment_lastcollapsed'] = true;
}
}
@ -455,11 +463,10 @@ class Item extends BaseObject {
$result['private'] = $item['private'];
$result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : '');
if($this->is_threaded()) {
if ($this->is_threaded()) {
$result['flatten'] = false;
$result['threaded'] = true;
}
else {
} else {
$result['flatten'] = true;
$result['threaded'] = false;
}
@ -478,23 +485,21 @@ class Item extends BaseObject {
/**
* Add a child item
*/
public function add_child($item) {
public function add_child(Item $item) {
$item_id = $item->get_id();
if(!$item_id) {
if (!$item_id) {
logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG);
return false;
}
if($this->get_child($item->get_id())) {
} elseif ($this->get_child($item->get_id())) {
logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG);
return false;
}
/*
* 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;
}
if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
} elseif (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) {
return false;
}
@ -507,10 +512,11 @@ class Item extends BaseObject {
* Get a child by its ID
*/
public function get_child($id) {
foreach($this->get_children() as $child) {
if($child->get_id() == $id)
foreach ($this->get_children() as $child) {
if ($child->get_id() == $id) {
return $child;
}
}
return null;
}
@ -546,8 +552,8 @@ class Item extends BaseObject {
*/
public function remove_child($item) {
$id = $item->get_id();
foreach($this->get_children() as $key => $child) {
if($child->get_id() == $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()
@ -575,9 +581,10 @@ class Item extends BaseObject {
$this->conversation = $conv;
// Set it on our children too
foreach($this->get_children() as $child)
foreach ($this->get_children() as $child) {
$child->set_conversation($conv);
}
}
/**
* get conversation
@ -603,7 +610,7 @@ class Item extends BaseObject {
* _ false on failure
*/
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);
return false;
}
@ -615,9 +622,7 @@ class Item extends BaseObject {
* Set template
*/
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);
return false;
}
@ -645,13 +650,14 @@ class Item extends BaseObject {
private function is_writable() {
$conv = $this->get_conversation();
if($conv) {
if ($conv) {
// 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.
// 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;
}
// this fixes for visitors
return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile'));
@ -665,8 +671,8 @@ class Item extends BaseObject {
private function count_descendants() {
$children = $this->get_children();
$total = count($children);
if($total > 0) {
foreach($children as $child) {
if ($total > 0) {
foreach ($children as $child) {
$total += $child->count_descendants();
}
}
@ -689,7 +695,7 @@ class Item extends BaseObject {
*/
private function get_comment_box($indent) {
$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 '';
}
@ -697,17 +703,17 @@ class Item extends BaseObject {
$conv = $this->get_conversation();
$template = get_markup_template($this->get_comment_box_template());
$ww = '';
if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
if ( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() )
$ww = 'ww';
if($conv->is_writable() && $this->is_writable()) {
if ($conv->is_writable() && $this->is_writable()) {
$qc = $qcomment = null;
/*
* Hmmm, code depending on the presence of a particular plugin?
* 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);
$qcomment = (($qc) ? explode("\n",$qc) : null);
}
@ -768,14 +774,13 @@ class Item extends BaseObject {
$this->owner_photo = $a->page_contact['thumb'];
$this->owner_name = $a->page_contact['name'];
$this->wall_to_wall = true;
}
else if($this->get_data_value('owner-link')) {
} elseif($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')));
$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'));
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)
// 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->wall_to_wall = true;
// 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->owner_url = $this->get_redirect_url();
}
else
} else {
$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->owner_url = '';
$this->owner_photo = '';
@ -830,8 +835,6 @@ class Item extends BaseObject {
return $this->visiting;
}
}
/// @TODO These are discouraged and should be removed:
?>