diff --git a/include/attach.php b/include/attach.php index 7d0b99c05..04fd25ace 100644 --- a/include/attach.php +++ b/include/attach.php @@ -275,7 +275,11 @@ function attach_by_hash($hash, $rev = 0) { * * @see attach_by_hash() * @param $hash - * @param $ref + * @param $rev revision default 0 + * @return array Everything except data. + * * \e boolean \b success boolean true or false + * * \e string \b message (optional) only when success is false + * * \e array \b data array of attach DB entry without data component */ function attach_by_hash_nodata($hash, $rev = 0) { @@ -318,6 +322,7 @@ function attach_by_hash_nodata($hash, $rev = 0) { $ret['success'] = true; $ret['data'] = $r[0]; + return $ret; } @@ -361,6 +366,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $existing_size = 0; if($options === 'replace') { + /** @BUG $replace is undefined here */ $x = q("select id, hash, filesize from attach where id = %d and uid = %d limit 1", intval($replace), intval($channel_id) @@ -373,7 +379,7 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { $existing_size = intval($x[0]['filesize']); $hash = $x[0]['hash']; } - + if($options === 'revise' || $options === 'update') { $sql_options = " order by revision desc "; if($options === 'update' && $arr && array_key_exists('revision',$arr)) @@ -513,22 +519,24 @@ function attach_store($channel, $observer_hash, $options = '', $arr = null) { } /** - * Read a virtual directory and return contents, checking permissions of all parent components. - * @function z_readdir + * @brief Read a virtual directory and return contents. + * + * Also checking permissions of all parent components. + * * @param integer $channel_id * @param string $observer_hash hash of current observer * @param string $pathname * @param string $parent_hash (optional) * - * @returns array $ret - * $ret['success'] = boolean true or false - * $ret['message'] = error message if success is false - * $ret['data'] = array of attach DB entries without data component + * @return array $ret + * * \e boolean \b success boolean true or false + * * \e string \b message error message if success is false + * * \e array \b data array of attach DB entries without data component */ function z_readdir($channel_id, $observer_hash, $pathname, $parent_hash = '') { $ret = array('success' => false); - if(! perm_is_allowed($r[0]['uid'], get_observer_hash(), 'view_storage')) { + if(! perm_is_allowed($channel_id, get_observer_hash(), 'view_storage')) { $ret['message'] = t('Permission denied.'); return $ret; } @@ -833,12 +841,14 @@ function attach_delete($channel_id, $resource) { /** * @brief Returns path to file in cloud/. - * This function cannot be used with mod/dav as it always returns a path valid under mod/cloud + * + * @warning This function cannot be used with mod/dav as it always returns a + * path valid under mod/cloud. * - * @param array - * $arr[uid] int the channels uid - * $arr[folder] string - * $arr[filename]] string + * @param array assoziative array with: + * * \e int \b uid the channel's uid + * * \e string \b folder + * * \e string \b filename * @return string * path to the file in cloud/ */ @@ -895,6 +905,7 @@ function get_cloudpath($arr) { * @return string with the full folder path */ function get_parent_cloudpath($channel_id, $channel_name, $attachHash) { + $parentFullPath = ''; // build directory tree $parentHash = $attachHash; do { @@ -933,9 +944,9 @@ function find_folder_hash_by_attach_hash($channel_id, $attachHash) { /** * @brief Returns the filename of an attachment in a given channel. * - * @param mixed $channel_id + * @param int $channel_id * The id of the channel - * @param mixed $attachHash + * @param string $attachHash * The hash of the attachment * @return string * The filename of the attachment @@ -949,6 +960,7 @@ function find_filename_by_hash($channel_id, $attachHash) { if ($r) { $filename = $r[0]['filename']; } + return $filename; } @@ -1172,8 +1184,10 @@ function get_file_activity_object($channel_id, $hash, $cloudpath) { } -function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { +function recursive_activity_recipients($arr_allow_cid, $arr_allow_gid, $arr_deny_cid, $arr_deny_gid, $folder_hash) { + $ret = array(); + $parent_arr = array(); $poster = get_app()->get_observer(); //turn allow_gid into allow_cid's @@ -1194,8 +1208,10 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ $parent_arr['allow_cid'][] = expand_acl($x[0]['allow_cid']); $parent_arr['allow_gid'][] = expand_acl($x[0]['allow_gid']); - //TODO: should find a much better solution for the allow_cid <-> allow_gid problem. - //Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid. + /** + * @TODO should find a much better solution for the allow_cid <-> allow_gid problem. + * Do not use allow_gid for now. Instead lookup the members of the group directly and add them to allow_cid. + * */ if($parent_arr['allow_gid']) { foreach($parent_arr['allow_gid'][$count] as $gid) { $in_group = in_group($gid); @@ -1207,11 +1223,9 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ $parent_arr['deny_gid'][] = expand_acl($x[0]['deny_gid']); $count++; - } $folder_hash = $x[0]['folder']; - } //if none of the parent folders is private just return file perms @@ -1279,11 +1293,12 @@ function recursive_activity_recipients($arr_allow_cid, $arr_llow_gid, $arr_deny_ } return $ret; - } function in_group($group_id) { - //TODO: make these two queries one with a join. + $group_members = array(); + + /** @TODO make these two queries one with a join. */ $x = q("SELECT id FROM groups WHERE hash = '%s'", dbesc($group_id) ); diff --git a/include/conversation.php b/include/conversation.php index a85d582ce..8a834f339 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -205,22 +205,22 @@ function localize_item(&$item){ $item['body'] .= "\n\n\n" . $Bphoto; } - if (stristr($item['verb'],ACTIVITY_POKE)) { + if (stristr($item['verb'], ACTIVITY_POKE)) { - // FIXME for obscured private posts, until then leave untranslated + /** @FIXME for obscured private posts, until then leave untranslated */ return; $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); if(! $verb) return; + if ($item['obj_type']=="" || $item['obj_type']!== ACTIVITY_OBJ_PERSON) return; $Aname = $item['author']['xchan_name']; $Alink = $item['author']['xchan_url']; - $obj= json_decode_plus($item['object']); - + $Blink = $Bphoto = ''; if($obj['link']) { @@ -246,7 +246,6 @@ function localize_item(&$item){ $item['body'] = $item['localize'] = sprintf($txt, $A, $B); $item['body'] .= "\n\n\n" . $Bphoto; - } if (stristr($item['verb'],ACTIVITY_MOOD)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); @@ -375,54 +374,72 @@ function localize_item(&$item){ && strlen($item['body']) && (! strpos($item['body'],'data'))) { $item['body'] = json_encode(crypto_encapsulate($item['body'],get_config('system','pubkey'))); } - } /** - * Count the total of comments on this item and its desendants + * @brief Count the total of comments on this item and its desendants. + * + * @param array $item an assoziative item-array which provides: + * * \e array \b children + * @return number */ function count_descendants($item) { $total = count($item['children']); - if($total > 0) { - foreach($item['children'] as $child) { - if(! visible_activity($child)) - $total --; - $total += count_descendants($child); - } - } + if ($total > 0) { + foreach ($item['children'] as $child) { + if (! visible_activity($child)) + $total --; + + $total += count_descendants($child); + } + } return $total; } +/** + * @brief Check if the activity of the item is visible. + * + * likes (etc.) can apply to other things besides posts. Check if they are post + * children, in which case we handle them specially. + * + * @param array $item + * @return boolean + */ function visible_activity($item) { - - // likes (etc.) can apply to other things besides posts. Check if they are post children, - // in which case we handle them specially - $hidden_activities = array(ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_AGREE, ACTIVITY_DISAGREE, ACTIVITY_ABSTAIN, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE); - foreach($hidden_activities as $act) { - if((activity_match($item['verb'],$act)) && ($item['mid'] != $item['parent_mid'])) { + + foreach ($hidden_activities as $act) { + if ((activity_match($item['verb'], $act)) && ($item['mid'] != $item['parent_mid'])) { return false; } } + return true; } /** - * "Render" a conversation or list of items for HTML display. + * @brief "Render" a conversation or list of items for HTML display. + * * There are two major forms of display: - * - Sequential or unthreaded ("New Item View" or search results) - * - conversation view + * - Sequential or unthreaded ("New Item View" or search results) + * - conversation view + * * The $mode parameter decides between the various renderings and also * figures out how to determine page owner and other contextual items * that are based on unique features of the calling module. * + * @param App &$a + * @param array $items + * @param string $mode + * @param boolean $update + * @param string $page_mode default traditional + * @param string $prepared_item + * @return string */ - - function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $prepared_item = '') { $content_html = ''; @@ -432,39 +449,38 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $ssl_state = ((local_channel()) ? true : false); - if(local_channel()) + if (local_channel()) load_pconfig(local_channel(),''); $arr_blocked = null; - if(local_channel()) + if (local_channel()) $str_blocked = get_pconfig(local_channel(),'system','blocked'); - if(! local_channel() && ($mode == 'network')) { + if (! local_channel() && ($mode == 'network')) { $sys = get_sys_channel(); $id = $sys['channel_id']; $str_blocked = get_pconfig($id,'system','blocked'); } - - if($str_blocked) { - $arr_blocked = explode(',',$str_blocked); - for($x = 0; $x < count($arr_blocked); $x ++) + + if ($str_blocked) { + $arr_blocked = explode(',',$str_blocked); + for ($x = 0; $x < count($arr_blocked); $x ++) $arr_blocked[$x] = trim($arr_blocked[$x]); } - - $profile_owner = 0; - $page_writeable = false; + $profile_owner = 0; + $page_writeable = false; $live_update_div = ''; $preview = (($page_mode === 'preview') ? true : false); $previewing = (($preview) ? ' preview ' : ''); - if($mode === 'network') { + if ($mode === 'network') { $profile_owner = local_channel(); $page_writeable = true; - if(!$update) { + if (!$update) { // The special div is needed for liveUpdate to kick in for this page. // We only launch liveUpdate if you aren't filtering in some incompatible // way and also you aren't writing a comment (discovered in javascript). @@ -490,13 +506,13 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ } } - elseif($mode === 'channel') { + elseif ($mode === 'channel') { $profile_owner = $a->profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); - if(!$update) { + if (!$update) { $tab = notags(trim($_GET['tab'])); - if($tab === 'posts') { + if ($tab === 'posts') { // This is ugly, but we can't pass the profile_uid through the session to the ajax updater, // because browser prefetching might change it on us. We have to deliver it with the page. @@ -507,23 +523,23 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ } } - elseif($mode === 'display') { + elseif ($mode === 'display') { $profile_owner = local_channel(); $page_writeable = false; $live_update_div = '
' . "\r\n"; } - elseif($mode === 'page') { + elseif ($mode === 'page') { $profile_owner = $a->profile['uid']; $page_writeable = ($profile_owner == local_channel()); $live_update_div = '' . "\r\n"; } - elseif($mode === 'search') { + elseif ($mode === 'search') { $live_update_div = '' . "\r\n"; } - elseif($mode === 'photos') { + elseif ($mode === 'photos') { $profile_onwer = $a->profile['profile_uid']; $page_writeable = ($profile_owner == local_channel()); $live_update_div = '' . "\r\n"; @@ -533,12 +549,12 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $page_dropping = ((local_channel() && local_channel() == $profile_owner) ? true : false); - if(! feature_enabled($profile_owner,'multi_delete')) + if (! feature_enabled($profile_owner,'multi_delete')) $page_dropping = false; $channel = $a->get_channel(); - $observer = $a->get_observer(); + $observer = $a->get_observer(); if($update) $return_url = $_SESSION['return_url']; @@ -637,7 +653,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ else $dropping = false; - $drop = array( 'pagedropping' => $page_dropping, 'dropping' => $dropping, @@ -647,7 +662,7 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $star = false; $isstarred = "unstarred icon-star-empty"; - + $lock = (($item['item_private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) ? t('Private Message') : false @@ -659,17 +674,14 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ $verified = (($item['item_flags'] & ITEM_VERIFIED) ? t('Message signature validated') : ''); $forged = ((($item['sig']) && (! ($item['item_flags'] & ITEM_VERIFIED))) ? t('Message signature incorrect') : ''); - $unverified = ''; - $tags=array(); $terms = get_terms_oftype($item['term'],array(TERM_HASHTAG,TERM_MENTION,TERM_UNKNOWN)); if(count($terms)) foreach($terms as $tag) $tags[] = format_term_for_display($tag); - $body = prepare_body($item,true); $tmp_item = array( @@ -731,12 +743,9 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ // $threads[$threadsid]['id'] = $item['item_id']; $threads[] = $arr['output']; - } - } - else - { + else { // Normal View // logger('conv: items: ' . print_r($items,true)); @@ -751,7 +760,6 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ if($mode === 'display' && $items) $conv->set_profile_owner($items[0]['uid']); - // get all the topmost parents // this shouldn't be needed, as we should have only them in our array // But for now, this array respects the old style, just in case @@ -831,20 +839,19 @@ function conversation(&$a, $items, $mode, $update, $page_mode = 'traditional', $ // logger('nouveau: ' . print_r($threads,true)); - $o .= replace_macros($page_template, array( - '$baseurl' => $a->get_baseurl($ssl_state), + $o .= replace_macros($page_template, array( + '$baseurl' => $a->get_baseurl($ssl_state), '$photo_item' => $content_html, - '$live_update' => $live_update_div, - '$remove' => t('remove'), - '$mode' => $mode, - '$user' => $a->user, - '$threads' => $threads, + '$live_update' => $live_update_div, + '$remove' => t('remove'), + '$mode' => $mode, + '$user' => $a->user, + '$threads' => $threads, '$wait' => t('Loading...'), - '$dropping' => ($page_dropping?t('Delete Selected Items'):False), - )); + '$dropping' => ($page_dropping?t('Delete Selected Items'):False), + )); return $o; - } @@ -892,7 +899,6 @@ function item_photo_menu($item){ $vsrc_link = ""; $follow_url = ""; - $local_channel = local_channel(); if($local_channel) { @@ -910,7 +916,7 @@ function item_photo_menu($item){ } } - $profile_link = chanlink_hash($item['author_xchan']); + $profile_link = chanlink_hash($item['author_xchan']); if($item['uid'] > 0) $pm_url = $a->get_baseurl($ssl_state) . '/mail/new/?f=&hash=' . $item['author_xchan']; @@ -927,7 +933,6 @@ function item_photo_menu($item){ $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $contact['abook_id']; $clean_url = normalise_link($item['author-link']); - } $menu = Array( @@ -943,7 +948,6 @@ function item_photo_menu($item){ t("Poke") => $poke_link ); - $args = array('item' => $item, 'menu' => $menu); call_hooks('item_photo_menu', $args); @@ -958,17 +962,17 @@ function item_photo_menu($item){ } elseif ($v!="") $o .= "