]> git.mxchange.org Git - friendica.git/blobdiff - mod/network.php
Fix formatting and PHP notice in mod/photos
[friendica.git] / mod / network.php
index e09fdd8fec9e5ece5b04fb99c00dab3c3a5d4544..81e6754c235595faaef302d12030794c4d463559 100644 (file)
@@ -1,15 +1,20 @@
 <?php
-
+/**
+ * @file mod/network.php
+ */
 use Friendica\App;
+use Friendica\Content\Feature;
+use Friendica\Content\ForumManager;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
+use Friendica\Database\DBM;
+use Friendica\Model\Contact;
+use Friendica\Model\Group;
 
 require_once 'include/conversation.php';
-require_once 'include/group.php';
 require_once 'include/contact_widgets.php';
 require_once 'include/items.php';
-require_once 'include/ForumManager.php';
 require_once 'include/acl_selectors.php';
 
 function network_init(App $a) {
@@ -35,12 +40,18 @@ function network_init(App $a) {
        }
 
        $is_a_date_query = false;
+
+       $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
+
+       $cid = 0;
        if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
                $cid = $_GET['cid'];
                $_GET['nets'] = 'all';
-
+               $group_id = 0;
        }
 
+       PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
+
        if ($a->argc > 1) {
                for ($x = 1; $x < $a->argc; $x ++) {
                        if (is_a_date_arg($a->argv[$x])) {
@@ -141,16 +152,13 @@ function network_init(App $a) {
                unset($_GET['nets']);
        }
 
-       $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
-
-       PConfig::set(local_user(), 'network.view', 'group.selected', $group_id);
 
        if (!x($a->page, 'aside')) {
                $a->page['aside'] = '';
        }
 
-       $a->page['aside'] .= (feature_enabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
-       $a->page['aside'] .= (feature_enabled(local_user(),'forumlist_widget') ? ForumManager::widget(local_user(),$cid) : '');
+       $a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? Group::sidebarWidget('network/0','network','standard',$group_id) : '');
+       $a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
        $a->page['aside'] .= posted_date_widget('network',local_user(),false);
        $a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
        $a->page['aside'] .= saved_searches($search);
@@ -159,7 +167,7 @@ function network_init(App $a) {
 
 function saved_searches($search) {
 
-       if (!feature_enabled(local_user(),'savedsearch')) {
+       if (!Feature::isEnabled(local_user(),'savedsearch')) {
                return '';
        }
 
@@ -357,7 +365,7 @@ function networkConversation($a, $items, $mode, $update) {
        // Set this so that the conversation function can find out contact info for our wall-wall items
        $a->page_contact = $a->contact;
 
-       $o .= conversation($a, $items, $mode, $update);
+       $o = conversation($a, $items, $mode, $update);
 
        if (!$update) {
                if (PConfig::get(local_user(), 'system', 'infinite_scroll')) {
@@ -497,9 +505,9 @@ function networkThreadedView(App $a, $update = 0) {
        $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
 
        if (isset($_GET["last_received"]) && isset($_GET["last_commented"]) && isset($_GET["last_created"]) && isset($_GET["last_id"])) {
-               $last_received = dbm::date($_GET["last_received"]);
-               $last_commented = dbm::date($_GET["last_commented"]);
-               $last_created = dbm::date($_GET["last_created"]);
+               $last_received = DBM::date($_GET["last_received"]);
+               $last_commented = DBM::date($_GET["last_commented"]);
+               $last_created = DBM::date($_GET["last_created"]);
                $last_id = intval($_GET["last_id"]);
        } else {
                $last_received = '';
@@ -559,10 +567,10 @@ function networkThreadedView(App $a, $update = 0) {
                $o .= $tabs;
 
                if ($group) {
-                       if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
-                               notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
+                       if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
+                               notice(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
                                                "Warning: This group contains %s members from a network that doesn't allow non public messages.",
-                                               $t), $t).EOL);
+                                               $t) . EOL);
                                notice(t("Messages in this group won't be send to these receivers.").EOL);
                        }
                }
@@ -575,7 +583,7 @@ function networkThreadedView(App $a, $update = 0) {
                        // If $cid belongs to a communitity forum or a privat goup,.add a mention to the status editor
                        $condition = array("`id` = ? AND (`forum` OR `prv`)", $cid);
                        $contact = dba::select('contact', array('addr', 'nick'), $condition, array('limit' => 1));
-                       if (dbm::is_result($contact)) {
+                       if (DBM::is_result($contact)) {
                                if ($contact["addr"] != '') {
                                        $content = "!".$contact["addr"];
                                } else {
@@ -628,7 +636,7 @@ function networkThreadedView(App $a, $update = 0) {
 
        if ($group) {
                $r = dba::select('group', array('name'), array('id' => $group, 'uid' => $_SESSION['uid']), array('limit' => 1));
-               if (!dbm::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        if ($update)
                                killme();
                        notice(t('No such group') . EOL);
@@ -636,14 +644,14 @@ function networkThreadedView(App $a, $update = 0) {
                        // NOTREACHED
                }
 
-               $contacts = expand_groups(array($group));
+               $contacts = Group::expand(array($group));
 
                if ((is_array($contacts)) && count($contacts)) {
                        $contact_str_self = "";
 
                        $contact_str = implode(',',$contacts);
                        $self = dba::select('contact', array('id'), array('uid' => $_SESSION['uid'], 'self' => true), array('limit' => 1));
-                       if (dbm::is_result($self)) {
+                       if (DBM::is_result($self)) {
                                $contact_str_self = $self["id"];
                        }
 
@@ -656,7 +664,7 @@ function networkThreadedView(App $a, $update = 0) {
                }
 
                $o = replace_macros(get_markup_template("section_title.tpl"),array(
-                       '$title' => sprintf(t('Group: %s'), $r['name'])
+                       '$title' => t('Group: %s', $r['name'])
                )) . $o;
 
        } elseif ($cid) {
@@ -664,7 +672,7 @@ function networkThreadedView(App $a, $update = 0) {
                                'forum', 'prv', 'contact-type', 'addr', 'thumb', 'location');
                $condition = array("`id` = ? AND (NOT `blocked` OR `pending`)", $cid);
                $r = dba::select('contact', $fields, $condition, array('limit' => 1));
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $sql_extra = " AND ".$sql_table.".`contact-id` = ".intval($cid);
 
                        $entries[0] = array(
@@ -675,7 +683,7 @@ function networkThreadedView(App $a, $update = 0) {
                                'details' => $r['location'],
                        );
 
-                       $entries[0]["account_type"] = account_type($r);
+                       $entries[0]["account_type"] = Contact::getAccountType($r);
 
                        $o = replace_macros(get_markup_template("viewcontact_template.tpl"),array(
                                'contacts' => $entries,
@@ -708,13 +716,6 @@ function networkThreadedView(App $a, $update = 0) {
        $sql_order = "";
        $order_mode = "received";
 
-       if (strlen($file)) {
-               $sql_post_table .= sprintf("INNER JOIN (SELECT `oid` FROM `term` WHERE `term` = '%s' AND `otype` = %d AND `type` = %d AND `uid` = %d ORDER BY `tid` DESC) AS `term` ON `item`.`id` = `term`.`oid` ",
-                               dbesc(protect_sprintf($file)), intval(TERM_OBJ_POST), intval(TERM_FILE), intval(local_user()));
-               $sql_order = "`item`.`id`";
-               $order_mode = "id";
-       }
-
        if ($conv) {
                $sql_extra3 .= " AND $sql_table.`mention`";
        }
@@ -736,7 +737,7 @@ function networkThreadedView(App $a, $update = 0) {
                $sql_order = "$sql_table.$ordering";
        }
 
-       if (($_GET["offset"] != "")) {
+       if (x($_GET, 'offset')) {
                $sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
        }
 
@@ -808,9 +809,10 @@ function networkThreadedView(App $a, $update = 0) {
        $parents_str = '';
        $date_offset = "";
 
-       if (dbm::is_result($r)) {
+       $items = array();
+       if (DBM::is_result($r)) {
                foreach ($r as $rr) {
-                       if (!in_array($rr['item_id'],$parents_arr)) {
+                       if (!in_array($rr['item_id'], $parents_arr)) {
                                $parents_arr[] = $rr['item_id'];
                        }
                }
@@ -825,29 +827,27 @@ function networkThreadedView(App $a, $update = 0) {
                        $max_comments = 100;
                }
 
-               $items = array();
-
                foreach ($parents_arr AS $parents) {
-                       $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
+                       $thread_items = dba::p(item_query() . " AND `item`.`uid` = ?
                                AND `item`.`parent` = ?
-                               ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1),
+                               ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1),
                                local_user(),
                                $parents
                        );
 
-                       if (dbm::is_result($thread_items)) {
+                       if (DBM::is_result($thread_items)) {
                                $items = array_merge($items, dba::inArray($thread_items));
                        }
                }
-               $items = conv_sort($items,$ordering);
-       } else {
-               $items = array();
+               $items = conv_sort($items, $ordering);
        }
 
-       if ($_GET["offset"] == "") {
+       if (x($_GET, 'offset')) {
+               $date_offset = $_GET["offset"];
+       } elseif(count($items)) {
                $date_offset = $items[0][$order_mode];
        } else {
-               $date_offset = $_GET["offset"];
+               $date_offset = '';
        }
 
        $a->page_offset = $date_offset;
@@ -877,17 +877,19 @@ function networkThreadedView(App $a, $update = 0) {
  * @param App $a The global App
  * @return string Html of the networktab
  */
-function network_tabs(App $a) {
+function network_tabs(App $a)
+{
        // item filter tabs
        /// @TODO fix this logic, reduce duplication
        /// $a->page['content'] .= '<div class="tabs-wrapper">';
-
        list($no_active, $all_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active) = network_query_get_sel_tab($a);
+
        // if no tabs are selected, defaults to comments
-       if ($no_active=='active') $all_active='active';
+       if ($no_active == 'active') {
+               $all_active = 'active';
+       }
 
-       $cmd = (($datequery) ? '' : $a->cmd);
-       $len_naked_cmd = strlen(str_replace('/new','',$cmd));
+       $cmd = $a->cmd;
 
        // tabs
        $tabs = array(
@@ -909,7 +911,7 @@ function network_tabs(App $a) {
                ),
        );
 
-       if (feature_enabled(local_user(),'personal_tab')) {
+       if (Feature::isEnabled(local_user(),'personal_tab')) {
                $tabs[] = array(
                        'label' => t('Personal'),
                        'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&conv=1',
@@ -920,7 +922,7 @@ function network_tabs(App $a) {
                );
        }
 
-       if (feature_enabled(local_user(),'new_tab')) {
+       if (Feature::isEnabled(local_user(),'new_tab')) {
                $tabs[] = array(
                        'label' => t('New'),
                        'url'   => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
@@ -931,7 +933,7 @@ function network_tabs(App $a) {
                );
        }
 
-       if (feature_enabled(local_user(),'link_tab')) {
+       if (Feature::isEnabled(local_user(),'link_tab')) {
                $tabs[] = array(
                        'label' => t('Shared Links'),
                        'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&bmark=1',
@@ -942,7 +944,7 @@ function network_tabs(App $a) {
                );
        }
 
-       if (feature_enabled(local_user(),'star_posts')) {
+       if (Feature::isEnabled(local_user(),'star_posts')) {
                $tabs[] = array(
                        'label' => t('Starred'),
                        'url'   => str_replace('/new', '', $cmd) . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : '/?f=') . '&star=1',