+ $nouveau = false;
+
+ if ($a->argc > 1) {
+ for ($x = 1; $x < $a->argc; $x ++) {
+ if ($a->argv[$x] === 'new') {
+ $nouveau = true;
+ }
+ }
+ }
+
+ if (x($_GET,'file')) {
+ $nouveau = true;
+ }
+
+ if ($nouveau) {
+ $o = networkFlatView($a, $update);
+ } else {
+ $o = networkThreadedView($a, $update);
+ }
+
+ return $o;
+}
+
+/**
+ * @brief Get the network content in flat view
+ *
+ * @param App $a The global App
+ * @param integer $update Used for the automatic reloading
+ * @return string HTML of the network content in flat view
+ */
+function networkFlatView(App $a, $update = 0) {
+
+ // Rawmode is used for fetching new content at the end of the page
+ $rawmode = (isset($_GET["mode"]) AND ($_GET["mode"] == "raw"));
+
+ if (isset($_GET["last_id"])) {
+ $last_id = intval($_GET["last_id"]);
+ } else {
+ $last_id = 0;
+ }
+
+ $o = '';
+
+ $file = ((x($_GET,'file')) ? $_GET['file'] : '');
+
+ PConfig::set(local_user(), 'network.view', 'net.selected', 'all');
+
+ if (!$update && !$rawmode) {
+ $tabs = network_tabs($a);
+ $o .= $tabs;
+
+ nav_set_selected('network');
+
+ $x = array(
+ 'is_owner' => true,
+ 'allow_location' => $a->user['allow_location'],
+ 'default_location' => $a->user['default-location'],
+ 'nickname' => $a->user['nickname'],
+ 'lockstate'=> (((is_array($a->user) &&
+ ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) ||
+ (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid']))))) ? 'lock' : 'unlock'),
+ 'default_perms' => get_acl_permissions($a->user),
+ 'acl' => populate_acl($a->user, true),
+ 'bang' => '',
+ 'visitor' => 'block',
+ 'profile_uid' => local_user(),
+ 'acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
+ 'content' => '',
+ );
+
+ $o .= status_editor($a,$x);
+
+ if (!Config::get('theme','hide_eventlist')) {
+ $o .= get_birthdays();
+ $o .= get_events();
+ }
+ }
+
+ 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()));
+ } else {
+ $sql_post_table = " INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`";
+ }
+
+ $pager_sql = networkPager($a, $update);
+
+ // show all items unthreaded in reverse created date order
+ $items = q("SELECT %s FROM `item` $sql_post_table %s
+ WHERE %s AND `item`.`uid` = %d
+ ORDER BY `item`.`id` DESC $pager_sql ",
+ item_fieldlists(), item_joins(), item_condition(),
+ intval($_SESSION['uid'])
+ );
+
+ $condition = array('unseen' => true, 'uid' => local_user());
+ networkSetSeen($condition);
+
+ $mode = 'network-new';
+ $o .= networkConversation($a, $items, $mode, $update);
+
+ return $o;
+}
+
+/**
+ * @brief Get the network content in threaded view
+ *
+ * @param App $a The global App
+ * @param integer $update Used for the automatic reloading
+ * @return string HTML of the network content in flat view
+ */
+function networkThreadedView(App $a, $update = 0) {
+
+ // Rawmode is used for fetching new content at the end of the page
+ $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_id = intval($_GET["last_id"]);
+ } else {
+ $last_received = '';
+ $last_commented = '';
+ $last_created = '';
+ $last_id = 0;
+ }