]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Reset network when showing a contact's posts
[friendica.git] / include / conversation.php
index 57fe0d66e692fe42ad5c0b423da094c115dc60db..5296011bb37e080a220f4eb024455b79115ac13c 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 
 require_once("include/bbcode.php");
+require_once("include/acl_selectors.php");
 
 
 // Note: the code in 'item_extract_images' and 'item_redir_and_replace_images'
@@ -341,11 +342,14 @@ function count_descendants($item) {
 
 function visible_activity($item) {
 
-       if(activity_match($child['verb'],ACTIVITY_LIKE) || activity_match($child['verb'],ACTIVITY_DISLIKE))
+       if(activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE))
                return false;
 
-       if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && $item['uid'] != local_user())
-               return false;
+       if(activity_match($item['verb'],ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
+               if(! (($item['self']) && ($item['uid'] == local_user()))) {
+                       return false;
+               }
+       }
 
        return true;
 }
@@ -366,38 +370,89 @@ if(!function_exists('conversation')) {
 function conversation(&$a, $items, $mode, $update, $preview = false) {
 
 
-       require_once('bbcode.php');
+       require_once('include/bbcode.php');
 
        $ssl_state = ((local_user()) ? true : false);
 
        $profile_owner = 0;
-       $page_writeable      = false;
+       $page_writeable = false;
+       $live_update_div = '';
 
        $previewing = (($preview) ? ' preview ' : '');
 
        if($mode === 'network') {
                $profile_owner = local_user();
                $page_writeable = true;
+               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).
+
+                       $live_update_div = '<div id="live-network"></div>' . "\r\n"
+                               . "<script> var profile_uid = " . $_SESSION['uid'] 
+                               . "; var netargs = '" . substr($a->cmd,8)
+                               . '?f='
+                               . ((x($_GET,'cid'))    ? '&cid='    . $_GET['cid']    : '')
+                               . ((x($_GET,'search')) ? '&search=' . $_GET['search'] : '') 
+                               . ((x($_GET,'star'))   ? '&star='   . $_GET['star']   : '') 
+                               . ((x($_GET,'order'))  ? '&order='  . $_GET['order']  : '') 
+                               . ((x($_GET,'bmark'))  ? '&bmark='  . $_GET['bmark']  : '') 
+                               . ((x($_GET,'liked'))  ? '&liked='  . $_GET['liked']  : '') 
+                               . ((x($_GET,'conv'))   ? '&conv='   . $_GET['conv']   : '') 
+                               . ((x($_GET,'spam'))   ? '&spam='   . $_GET['spam']   : '') 
+                               . ((x($_GET,'nets'))   ? '&nets='   . $_GET['nets']   : '') 
+                               . ((x($_GET,'cmin'))   ? '&cmin='   . $_GET['cmin']   : '') 
+                               . ((x($_GET,'cmax'))   ? '&cmax='   . $_GET['cmax']   : '') 
+                               . ((x($_GET,'file'))   ? '&file='   . $_GET['file']   : '') 
+
+                               . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+               }
        }
-
-       if($mode === 'profile') {
+       else if($mode === 'profile') {
                $profile_owner = $a->profile['profile_uid'];
                $page_writeable = can_write_wall($a,$profile_owner);
-       }
 
-       if($mode === 'notes') {
+               if(!$update) {
+                       $tab = notags(trim($_GET['tab']));
+                       $tab = ( $tab ? $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.
+
+                               $live_update_div = '<div id="live-profile"></div>' . "\r\n"
+                                       . "<script> var profile_uid = " . $a->profile['profile_uid'] 
+                                       . "; var netargs = '?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+                       }
+               }
+       }
+       else if($mode === 'notes') {
                $profile_owner = local_user();
                $page_writeable = true;
+               if(!$update) {
+                       $live_update_div = '<div id="live-notes"></div>' . "\r\n"
+                               . "<script> var profile_uid = " . local_user() 
+                               . "; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+               }
        }
-
-       if($mode === 'display') {
+       else if($mode === 'display') {
                $profile_owner = $a->profile['uid'];
                $page_writeable = can_write_wall($a,$profile_owner);
+               if(!$update) {
+                       $live_update_div = '<div id="live-display"></div>' . "\r\n"
+                               . "<script> var profile_uid = " . $_SESSION['uid'] . ";"
+                               . " var profile_page = 1; </script>";
+               }
        }
-
-       if($mode === 'community') {
+       else if($mode === 'community') {
                $profile_owner = 0;
                $page_writeable = false;
+               if(!$update) {
+                       $live_update_div = '<div id="live-community"></div>' . "\r\n"
+                               . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+               }
+       }
+       else if($mode === 'search') {
+               $live_update_div = '<div id="live-search"></div>' . "\r\n";
        }
 
        $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
@@ -527,33 +582,54 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
                                list($categories, $folders) = get_cats_and_terms($item);
 
+                               if($a->theme['template_engine'] === 'internal') {
+                                       $profile_name_e = template_escape($profile_name);
+                                       $item['title_e'] = template_escape($item['title']);
+                                       $body_e = template_escape($body);
+                                       $tags_e = template_escape($tags);
+                                       $hashtags_e = template_escape($hashtags);
+                                       $mentions_e = template_escape($mentions);
+                                       $location_e = template_escape($location);
+                                       $owner_name_e = template_escape($owner_name);
+                               }
+                               else {
+                                       $profile_name_e = $profile_name;
+                                       $item['title_e'] = $item['title'];
+                                       $body_e = $body;
+                                       $tags_e = $tags;
+                                       $hashtags_e = $hashtags;
+                                       $mentions_e = $mentions;
+                                       $location_e = $location;
+                                       $owner_name_e = $owner_name;
+                               }
+
                                $tmp_item = array(
                                        'template' => $tpl,
                                        'id' => (($preview) ? 'P0' : $item['item_id']),
                                        'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        'profile_url' => $profile_link,
                                        'item_photo_menu' => item_photo_menu($item),
-                                       'name' => template_escape($profile_name),
+                                       'name' => $profile_name_e,
                                        'sparkle' => $sparkle,
                                        'lock' => $lock,
                                        'thumb' => $profile_avatar,
-                                       'title' => template_escape($item['title']),
-                                       'body' => template_escape($body),
-                                       'tags' => template_escape($tags),
-                                       'hashtags' => template_escape($hashtags),
-                                       'mentions' => template_escape($mentions),
+                                       'title' => $item['title_e'],
+                                       'body' => $body_e,
+                                       'tags' => $tags_e,
+                                       'hashtags' => $hashtags_e,
+                                       'mentions' => $mentions_e,
                                        'txt_cats' => t('Categories:'),
                                        'txt_folders' => t('Filed under:'),
                                        'has_cats' => ((count($categories)) ? 'true' : ''),
                                        'has_folders' => ((count($folders)) ? 'true' : ''),
                                        'categories' => $categories,
                                        'folders' => $folders,
-                                       'text' => strip_tags(template_escape($body)),
+                                       'text' => strip_tags($body_e),
                                        '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'])),
-                                       'location' => template_escape($location),
+                                       'location' => $location_e,
                                        'indent' => '',
-                                       'owner_name' => template_escape($owner_name),
+                                       'owner_name' => $owner_name_e,
                                        'owner_url' => $owner_url,
                                        'owner_photo' => $owner_photo,
                                        'plink' => get_plink($item),
@@ -609,6 +685,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
                                        continue;
                                }
 
+                               call_hooks('display_item', $arr);
+
                                $item['pagedrop'] = $page_dropping;
 
                                if($item['id'] == $item['parent']) {
@@ -627,11 +705,13 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
 
        $o = replace_macros($page_template, array(
                '$baseurl' => $a->get_baseurl($ssl_state),
-        '$remove' => t('remove'),
+               '$return_path' => $a->query_string,
+               '$live_update' => $live_update_div,
+               '$remove' => t('remove'),
                '$mode' => $mode,
                '$user' => $a->user,
                '$threads' => $threads,
-               '$dropping' => ($page_dropping?t('Delete Selected Items'):False),
+               '$dropping' => ($page_dropping && feature_enabled(local_user(),'multi_delete') ? t('Delete Selected Items') : False),
        ));
 
        return $o;
@@ -678,6 +758,7 @@ function item_photo_menu($item){
                 if(! count($a->contacts))
                        load_contact_links(local_user());
        }
+       $sub_link="";
        $poke_link="";
        $contact_url="";
        $pm_url="";
@@ -685,6 +766,10 @@ function item_photo_menu($item){
        $photos_link="";
        $posts_link="";
 
+       if((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
+               $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
+       }
+
        $sparkle = false;
        $profile_link = best_link_url($item,$sparkle,$ssl_state);
        if($profile_link === 'mailbox')
@@ -710,7 +795,7 @@ function item_photo_menu($item){
        if(($cid) && (! $item['self'])) {
                $poke_link = $a->get_baseurl($ssl_state) . '/poke/?f=&c=' . $cid;
                $contact_url = $a->get_baseurl($ssl_state) . '/contacts/' . $cid;
-               $posts_link = $a->get_baseurl($ssl_state) . '/network/?cid=' . $cid;
+               $posts_link = $a->get_baseurl($ssl_state) . '/network/0?nets=all&cid=' . $cid;
 
                $clean_url = normalise_link($item['author-link']);
 
@@ -725,6 +810,7 @@ function item_photo_menu($item){
        }
 
        $menu = Array(
+               t("Follow Thread") => $sub_link,
                t("View Status") => $status_link,
                t("View Profile") => $profile_link,
                t("View Photos") => $photos_link,
@@ -743,7 +829,11 @@ function item_photo_menu($item){
 
        $o = "";
        foreach($menu as $k=>$v){
-               if ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
+               if(strpos($v,'javascript:') === 0) {
+                       $v = substr($v,11);
+                       $o .= "<li><a href=\"#\" onclick=\"$v\">$k</a></li>\n";
+               }
+               elseif ($v!="") $o .= "<li><a href=\"$v\">$k</a></li>\n";
        }
        return $o;
 }}
@@ -791,22 +881,36 @@ function format_like($cnt,$arr,$type,$id) {
        if($cnt == 1)
                $o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
        else {
-               $spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
-               $o .= (($type === 'like') ?
-                                       sprintf( t('<span  %1$s>%2$d people</span> like this.'), $spanatts, $cnt)
-                                        :
-                                       sprintf( t('<span  %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt) );
-               $o .= EOL ;
+               $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
+               switch($type) {
+                       case 'like':
+                               $phrase = sprintf( t('<span  %1$s>%2$d people</span> like this'), $spanatts, $cnt);
+                               break;
+                       case 'dislike':
+                               $phrase = sprintf( t('<span  %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
+                               break;
+               }
+               $phrase .= EOL ;
+               $o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
+                       '$phrase' => $phrase,
+                       '$type' => $type,
+                       '$id' => $id
+               ));
+
                $total = count($arr);
                if($total >= MAX_LIKERS)
                        $arr = array_slice($arr, 0, MAX_LIKERS - 1);
-               if($total < MAX_LIKERS)
-                       $arr[count($arr)-1] = t('and') . ' ' . $arr[count($arr)-1];
-               $str = implode(', ', $arr);
-               if($total >= MAX_LIKERS)
+               if($total < MAX_LIKERS) {
+                       $last = t('and') . ' ' . $arr[count($arr)-1];
+                       $arr2 = array_slice($arr, 0, -1);
+                       $str = implode(', ', $arr2) . ' ' . $last;
+               }
+               if($total >= MAX_LIKERS) {
+                       $str = implode(', ', $arr);
                        $str .= sprintf( t(', and %d other people'), $total - MAX_LIKERS );
+               }
                $str = (($type === 'like') ? sprintf( t('%s like this.'), $str) : sprintf( t('%s don\'t like this.'), $str));
-               $o .= "\t" . '<div id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
+               $o .= "\t" . '<div class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $str . '</div>';
        }
        return $o;
 }}
@@ -816,11 +920,14 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
 
        $o = '';
 
-       $geotag = (($x['allow_location']) ? get_markup_template('jot_geotag.tpl') : '');
+       $geotag = (($x['allow_location']) ? replace_macros(get_markup_template('jot_geotag.tpl'), array()) : '');
 
-       $plaintext = false;
-       if(local_user() && intval(get_pconfig(local_user(),'system','plaintext')))
-               $plaintext = true;
+/*     $plaintext = false;
+       if( local_user() && (intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext')) )
+               $plaintext = true;*/
+       $plaintext = true;
+       if( local_user() && feature_enabled(local_user(),'richtext') )
+               $plaintext = false;
 
        $tpl = get_markup_template('jot-header.tpl');
        $a->page['htmlhead'] .= replace_macros($tpl, array(
@@ -835,7 +942,8 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$audurl' => t("Please enter an audio link/URL:"),
                '$term' => t('Tag term:'),
                '$fileas' => t('Save to Folder:'),
-               '$whereareu' => t('Where are you right now?')
+               '$whereareu' => t('Where are you right now?'),
+               '$delitems' => t('Delete item(s)?')
        ));
 
 
@@ -856,8 +964,6 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
        ));
 
 
-       $tpl = get_markup_template("jot.tpl");
-
        $jotplugins = '';
        $jotnets = '';
 
@@ -888,10 +994,31 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
        if($notes_cid)
                $jotnets .= '<input type="hidden" name="contact_allow[]" value="' . $notes_cid .'" />';
 
-       $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
+
+       // Private/public post links for the non-JS ACL form
+       $private_post = 1;
+       if($_REQUEST['public'])
+               $private_post = 0;
+
+       $query_str = $a->query_string;
+       if(strpos($query_str, 'public=1') !== false)
+               $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
+
+       // I think $a->query_string may never have ? in it, but I could be wrong
+       // It looks like it's from the index.php?q=[etc] rewrite that the web
+       // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
+       if(strpos($query_str, '?') === false)
+               $public_post_link = '?public=1';
+       else
+               $public_post_link = '&public=1';
+
+
+
+//     $tpl = replace_macros($tpl,array('$jotplugins' => $jotplugins));
+       $tpl = get_markup_template("jot.tpl");
 
        $o .= replace_macros($tpl,array(
-               '$return_path' => $a->query_string,
+               '$return_path' => $query_str,
                '$action' =>  $a->get_baseurl(true) . '/item',
                '$share' => (x($x,'button') ? $x['button'] : t('Share')),
                '$upload' => t('Upload photo'),
@@ -911,7 +1038,7 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$title' => "",
                '$placeholdertitle' => t('Set title'),
                '$category' => "",
-               '$placeholdercategory' => t('Categories (comma-separated list)'),
+               '$placeholdercategory' => (feature_enabled(local_user(),'categories') ? t('Categories (comma-separated list)') : ''),
                '$wait' => t('Please wait'),
                '$permset' => t('Permission settings'),
                '$shortpermset' => t('permissions'),
@@ -927,12 +1054,22 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
                '$jotnets' => $jotnets,
                '$emtitle' => t('Example: bob@example.com, mary@example.com'),
                '$lockstate' => $x['lockstate'],
-               '$acl' => $x['acl'],
                '$bang' => $x['bang'],
                '$profile_uid' => $x['profile_uid'],
-               '$preview' => t('Preview'),
+               '$preview' => ((feature_enabled($x['profile_uid'],'preview')) ? t('Preview') : ''),
+               '$jotplugins' => $jotplugins,
                '$sourceapp' => t($a->sourcename),
-               '$cancel' => t('Cancel')
+               '$cancel' => t('Cancel'),
+               '$rand_num' => random_digits(12),
+
+               // ACL permissions box
+               '$acl' => $x['acl'],
+               '$acl_data' => $x['acl_data'],
+               '$group_perms' => t('Post to Groups'),
+               '$contact_perms' => t('Post to Contacts'),
+               '$private' => t('Private post'),
+               '$is_private' => $private_post,
+               '$public_link' => $public_post_link,
        ));
 
 
@@ -947,9 +1084,10 @@ function status_editor($a,$x, $notes_cid = 0, $popup=false) {
 
 function get_item_children($arr, $parent) {
        $children = array();
+       $a = get_app();
        foreach($arr as $item) {
                if($item['id'] != $item['parent']) {
-                       if(get_config('system','thread_allow')) {
+                       if(get_config('system','thread_allow') && $a->theme_thread_allow) {
                                // Fallback to parent-uri if thr-parent is not set
                                $thr_parent = $item['thr-parent'];
                                if($thr_parent == '')