]> git.mxchange.org Git - friendica.git/blobdiff - mod/network.php
include diaspora mentions in personal (requires adding a Diaspora profile url because...
[friendica.git] / mod / network.php
index c168f96ebb92278bde73dd5a812f1072b4fe5144..2a3db597e838a5d118adecd337860bbb2b4ae38c 100644 (file)
@@ -17,12 +17,12 @@ function network_init(&$a) {
 
        // We need a better way of managing a growing argument list
 
-       $srchurl = '/network' 
-               . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') 
-               . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
-               . ((x($_GET,'order')) ? '?order=' . $_GET['order'] : '')
-               . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '');
-
+       // moved into savedsearches()
+       // $srchurl = '/network' 
+       //              . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') 
+       //              . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
+       //              . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '');
+       
        if(x($_GET,'save')) {
                $r = q("select * from `search` where `uid` = %d and `term` = '%s' limit 1",
                        intval(local_user()),
@@ -42,76 +42,64 @@ function network_init(&$a) {
                );
        }
 
-       $a->page['aside'] .= search($search,'netsearch-box',$srchurl,true);
-
-       $a->page['aside'] .= '<div id="network-new-link">';
-
-
-       $a->page['aside'] .= '<div id="network-view-link">';
-       if(($a->argc > 1 && $a->argv[1] === 'new') || ($a->argc > 2 && $a->argv[2] === 'new') || x($_GET,'search')) {
-               $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') . '">' . t('View Conversations') . '</a></div>';
-       }
-       else { 
-               $a->page['aside'] .= '<a href="' . $a->get_baseurl() . '/' . $a->cmd . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' . t('View New Items') . '</a></div>';
-
-               if(x($_GET,'star'))
-                       $a->page['aside'] .= '<div id="network-star-link">'
-                               . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd 
-                               . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '">' 
-                               . t('View Any Items') . '</a>' 
-                               . '<span class="network-star icon starred"></span>' 
-                               . '<span class="network-star icon unstarred"></span>' 
-                               . '<div class="clear"></div></div>';
-               else
-                       $a->page['aside'] .= '<div id="network-star-link">'
-                               . '<a class="network-star" href="' . $a->get_baseurl() . '/' . $a->cmd 
-                               . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1" >' 
-                               . t('View Starred Items') . '</a>'
-                               . '<span class="network-star icon starred"></span>' 
-                               . '<div class="clear"></div></div>';
-
-               if(! $_GET['bmark'])
-                       $a->page['aside'] .= '<div id="network-bmark-link">'
-                               . '<a class="network-bmark" href="' . $a->get_baseurl() . '/' . $a->cmd 
-                               . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&bmark=1" >' 
-                               . t('View Bookmarks') . '</a>'
-                               . '<div class="clear"></div></div>';
-
 
+       
+       // search terms header
+       if(x($_GET,'search')) {
+               $a->page['content'] .= '<h2>Search Results For: '  . $search . '</h2>';
        }
-
-       $a->page['aside'] .= '</div>';
-
+       
        $a->page['aside'] .= group_side('network','network',true,$group_id);
+       
+       // moved to saved searches to have it in the same div
+       //$a->page['aside'] .= search($search,'netsearch-box',$srchurl,true);
 
-       $a->page['aside'] .= saved_searches();
+       $a->page['aside'] .= saved_searches($search);
 
 }
 
-function saved_searches() {
+function saved_searches($search) {
 
+       $srchurl = '/network' 
+               . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : '') 
+               . ((x($_GET,'star')) ? '?star=' . $_GET['star'] : '')
+               . ((x($_GET,'bmark')) ? '?bmark=' . $_GET['bmark'] : '')
+               . ((x($_GET,'conv')) ? '?conv=' . $_GET['conv'] : '');
+       
        $o = '';
 
-       $r = q("select `term` from `search` WHERE `uid` = %d",
+       $r = q("select `id`,`term` from `search` WHERE `uid` = %d",
                intval(local_user())
        );
 
+       $saved = array();
+
        if(count($r)) {
-               $o .= '<h3>' . t('Saved Searches') . '</h3>' . "\r\n";
-               $o .= '<div id="saved-search-list"><ul id="saved-search-ul">' . "\r\n";
                foreach($r as $rr) {
-                       $o .= '<li class="saved-search-li clear"><a href="network/?f=&remove=1&search=' . $rr['term'] . '" class="icon drophide savedsearchdrop" title="' . t('Remove term') . '" onclick="return confirmDelete();" onmouseover="imgbright(this);" onmouseout="imgdull(this);" ></a> <a href="network/?f&search=' . $rr['term'] . '" class="savedsearchterm" >' . $rr['term'] . '</a></li>' . "\r\n";
+                       $saved[] = array(
+                               'id'            => $rr['id'],
+                               'term'                  => $rr['term'],
+                               'encodedterm'   => urlencode($rr['term']),
+                               'delete'                => t('Remove term'),
+                               'selected'              => ($search==$rr['term']),
+                       );
                }
-               $o .= '</ul></div>' . "\r\n";
        }               
 
+       
+       $tpl = get_markup_template("saved_searches_aside.tpl");
+       $o = replace_macros($tpl, array(
+               '$title'         => t('Saved Searches'),
+               '$add'           => t('add'),
+               '$searchbox' => search($search,'netsearch-box',$srchurl,true),
+               '$saved'         => $saved,
+       ));
+       
        return $o;
 
 }
 
 
-
-
 function network_content(&$a, $update = 0) {
 
        require_once('include/conversation.php');
@@ -121,6 +109,99 @@ function network_content(&$a, $update = 0) {
 
        $o = '';
 
+       // item filter tabs
+       // TODO: fix this logic, reduce duplication
+       //$a->page['content'] .= '<div class="tabs-wrapper">';
+       
+       $starred_active = '';
+       $new_active = '';
+       $bookmarked_active = '';
+       $all_active = '';
+       $search_active = '';
+       $conv_active = '';
+
+       if(($a->argc > 1 && $a->argv[1] === 'new') 
+               || ($a->argc > 2 && $a->argv[2] === 'new')) {
+                       $new_active = 'active';
+       }
+       
+       if(x($_GET,'search')) {
+               $search_active = 'active';
+       }
+       
+       if(x($_GET,'star')) {
+               $starred_active = 'active';
+       }
+       
+       if($_GET['bmark']) {
+               $bookmarked_active = 'active';
+       }
+
+       if($_GET['conv']) {
+               $conv_active = 'active';
+       }
+
+       
+       if (($new_active == '') 
+               && ($starred_active == '') 
+               && ($bookmarked_active == '')
+               && ($conv_active == '')
+               && ($search_active == '')) {
+                       $all_active = 'active';
+       }
+
+
+       $postord_active = '';
+
+       if($all_active && x($_GET,'order') && $_GET['order'] !== 'comment') {
+               $all_active = '';
+               $postord_active = 'active';
+       }
+                        
+
+       
+       // tabs
+       $tabs = array(
+               array(
+                       'label' => t('Commented Order'),
+                       'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '?cid=' . $_GET['cid'] : ''), 
+                       'sel'=>$all_active,
+               ),
+               array(
+                       'label' => t('Posted Order'),
+                       'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '?order=post' . ((x($_GET,'cid')) ? '&cid=' . $_GET['cid'] : ''), 
+                       'sel'=>$postord_active,
+               ),
+
+               array(
+                       'label' => t('Personal'),
+                       'url' => $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&conv=1',
+                       'sel' => $conv_active,
+               ),
+               array(
+                       'label' => t('New'),
+                       'url' => $a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . '/new' . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : ''),
+                       'sel' => $new_active,
+               ),
+               array(
+                       'label' => t('Starred'),
+                       'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&star=1',
+                       'sel'=>$starred_active,
+               ),
+               array(
+                       'label' => t('Bookmarks'),
+                       'url'=>$a->get_baseurl() . '/' . str_replace('/new', '', $a->cmd) . ((x($_GET,'cid')) ? '/?cid=' . $_GET['cid'] : '') . '&bmark=1',
+                       'sel'=>$bookmarked_active,
+               ),      
+       );
+       $tpl = get_markup_template('common_tabs.tpl');
+       $o .= replace_macros($tpl, array('$tabs'=>$tabs));
+       // --- end item filter tabs
+
+
+
+       
+
        $contact_id = $a->cid;
 
        $group = 0;
@@ -133,6 +214,7 @@ function network_content(&$a, $update = 0) {
        $bmark = ((x($_GET,'bmark')) ? intval($_GET['bmark']) : 0);
        $order = ((x($_GET,'order')) ? notags($_GET['order']) : 'comment');
        $liked = ((x($_GET,'liked')) ? intval($_GET['liked']) : 0);
+       $conv = ((x($_GET,'conv')) ? intval($_GET['conv']) : 0);
 
 
        if(($a->argc > 2) && $a->argv[2] === 'new')
@@ -162,7 +244,7 @@ function network_content(&$a, $update = 0) {
                        }
                }
 
-               $o .= '<script> $(document).ready(function() { $(\'#nav-network-link\').addClass(\'nav-selected\'); });</script>';
+               nav_set_selected('network');
 
                $_SESSION['return_url'] = $a->cmd;
 
@@ -182,23 +264,6 @@ function network_content(&$a, $update = 0) {
 
                $o .= status_editor($a,$x);
 
-               // The special div is needed for liveUpdate to kick in for this page.
-               // We only launch liveUpdate if you are on the front page, you aren't
-               // filtering by group and also you aren't writing a comment (the last
-               // criteria is discovered in javascript).
-
-                       $o .= '<div id="live-network"></div>' . "\r\n";
-                       $o .= "<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'] : '') 
-                               . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
-
        }
 
        // We aren't going to try and figure out at the item, group, and page
@@ -270,15 +335,54 @@ function network_content(&$a, $update = 0) {
                }
        }
 
-       if((! $group) && (! $cid) && (! $update))
+       if((! $group) && (! $cid) && (! $update)) {
                $o .= get_birthdays();
+               $o .= get_events();
+       }
+
+       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).
+
+               $o .= '<div id="live-network"></div>' . "\r\n";
+               $o .= "<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'] : '') 
+                       . "'; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+       }
 
        $sql_extra2 = (($nouveau) ? '' : " AND `item`.`parent` = `item`.`id` ");
 
-       if(x($_GET,'search'))
-               $sql_extra .= " AND `item`.`body` REGEXP '" . dbesc(escape_tags($_GET['search'])) . "' ";
+       if(x($_GET,'search')) {
+               $search = escape_tags($_GET['search']);
+               $sql_extra .= sprintf(" AND ( `item`.`body` REGEXP '%s' OR `item`.`tag` REGEXP '%s' ) ",
+                       dbesc($search),
+                       dbesc('\\]' . $search . '\\[')
+               );
+       }
+
+       if($conv) {
+               $myurl = $a->get_baseurl() . '/profile/'. $a->user['nickname'];
+               $myurl = substr($myurl,strpos($myurl,'://')+3);
+               $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl);
+               $diasp_url = str_replace('/profile/','/u/',$myurl);
+               $sql_extra .= sprintf(" AND `item`.`parent` IN (SELECT distinct(`parent`) from item where ( `author-link` regexp '%s' or `tag` regexp '%s' or tag regexp '%s' )) ",
+                       dbesc($myurl . '$'),
+                       dbesc($myurl . '\\]'),
+                       dbesc($diasp_url . '\\]')
+               );
+       }
+
+
 
-       
        $r = q("SELECT COUNT(*) AS `total`
                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
                WHERE `item`.`uid` = %d AND `item`.`visible` = 1 AND `item`.`deleted` = 0
@@ -358,7 +462,7 @@ function network_content(&$a, $update = 0) {
                                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                                AND `item`.`parent` = `parentitem`.`id` AND `item`.`parent` IN ( %s )
                                $sql_extra
-                               ORDER BY `parentitem`.$ordering DESC, `item`.`gravity` ASC, `item`.`created` ASC ",
+                               ORDER BY `parentitem`.$ordering DESC, `parentitem`.`id` ASC, `item`.`gravity` ASC, `item`.`created` ASC ",
                                intval(local_user()),
                                dbesc($parents_str)
                        );
@@ -374,7 +478,6 @@ function network_content(&$a, $update = 0) {
 
        if(! $update) {
                $o .= paginate($a);
-               $o .= cc_license();
        }
 
        return $o;