<?php
-function network_init(App &$a) {
+function network_init(App $a) {
if (! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
$is_a_date_query = false;
- if(x($_GET['cid']) && intval($_GET['cid']) != 0)
+ if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
$cid = $_GET['cid'];
+ }
- if($a->argc > 1) {
- for($x = 1; $x < $a->argc; $x ++) {
- if(is_a_date_arg($a->argv[$x])) {
+ if ($a->argc > 1) {
+ for ($x = 1; $x < $a->argc; $x ++) {
+ if (is_a_date_arg($a->argv[$x])) {
$is_a_date_query = true;
break;
}
parse_str($query_string, $query_array);
array_shift($query_array);
-
// fetch last used network view and redirect if needed
- if(! $is_a_date_query) {
+ if (! $is_a_date_query) {
$sel_tabs = network_query_get_sel_tab($a);
$sel_nets = network_query_get_sel_net();
$sel_groups = network_query_get_sel_group($a);
$net_baseurl = '/network';
$net_args = array();
- if($remember_group) {
+ if ($remember_group) {
$net_baseurl .= '/' . $last_sel_groups; // Note that the group number must come before the "/new" tab selection
- }
- else if($sel_groups !== false) {
+ } elseif($sel_groups !== false) {
$net_baseurl .= '/' . $sel_groups;
}
- if($remember_tab) {
+ if ($remember_tab) {
// redirect if current selected tab is '/network' and
// last selected tab is _not_ '/network?f=&order=comment'.
// and this isn't a date query
$k = array_search('active', $last_sel_tabs);
- $net_baseurl .= $tab_baseurls[$k];
+ if ($k != 3) {
+ $net_baseurl .= $tab_baseurls[$k];
- // parse out tab queries
- $dest_qa = array();
- $dest_qs = $tab_args[$k];
- parse_str( $dest_qs, $dest_qa);
- $net_args = array_merge($net_args, $dest_qa);
- }
- else if($sel_tabs[4] === 'active') {
+ // parse out tab queries
+ $dest_qa = array();
+ $dest_qs = $tab_args[$k];
+ parse_str($dest_qs, $dest_qa);
+ $net_args = array_merge($net_args, $dest_qa);
+ } else {
+ $remember_tab = false;
+ }
+ } elseif ($sel_tabs[4] === 'active') {
// The '/new' tab is selected
- $net_baseurl .= '/new';
+ $remember_group = false;
}
- if($remember_net) {
+ if ($remember_net) {
$net_args['nets'] = $last_sel_nets;
}
else if($sel_nets!==false) {
}
}
- if(x($_GET['nets']) && $_GET['nets'] === 'all')
+ // If nets is set to all, unset it
+ if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
unset($_GET['nets']);
+ }
$group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
- require_once('include/group.php');
- require_once('include/contact_widgets.php');
- require_once('include/items.php');
- require_once('include/ForumManager.php');
+ require_once 'include/group.php';
+ require_once 'include/contact_widgets.php';
+ require_once 'include/items.php';
+ require_once 'include/ForumManager.php';
- if(! x($a->page,'aside'))
+ if (! x($a->page, 'aside')) {
$a->page['aside'] = '';
+ }
- $search = ((x($_GET,'search')) ? escape_tags($_GET['search']) : '');
+ $search = ((x($_GET, 'search')) ? escape_tags($_GET['search']) : '');
- if(x($_GET,'save')) {
+ if (x($_GET, 'save')) {
$r = qu("SELECT * FROM `search` WHERE `uid` = %d AND `term` = '%s' LIMIT 1",
intval(local_user()),
dbesc($search)
);
}
}
- if(x($_GET,'remove')) {
+ if (x($_GET, 'remove')) {
q("DELETE FROM `search` WHERE `uid` = %d AND `term` = '%s'",
intval(local_user()),
dbesc($search)
}
// search terms header
- if(x($_GET,'search')) {
+ if (x($_GET, 'search')) {
$a->page['content'] .= replace_macros(get_markup_template("section_title.tpl"),array(
'$title' => sprintf( t('Results for: %s'), $search)
));
function saved_searches($search) {
- if(! feature_enabled(local_user(),'savedsearch'))
+ if (! feature_enabled(local_user(),'savedsearch')) {
return '';
+ }
$a = get_app();
$saved = array();
if (dbm::is_result($r)) {
- foreach($r as $rr) {
+ foreach ($r as $rr) {
$saved[] = array(
- 'id' => $rr['id'],
- 'term' => $rr['term'],
- 'encodedterm' => urlencode($rr['term']),
- 'delete' => t('Remove term'),
- 'selected' => ($search==$rr['term']),
+ 'id' => $rr['id'],
+ 'term' => $rr['term'],
+ 'encodedterm' => urlencode($rr['term']),
+ 'delete' => t('Remove term'),
+ 'selected' => ($search==$rr['term']),
);
}
}
$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,
+ '$title' => t('Saved Searches'),
+ '$add' => t('add'),
+ '$searchbox' => search($search,'netsearch-box',$srchurl,true),
+ '$saved' => $saved,
));
return $o;
*
* @return Array ( $no_active, $comment_active, $postord_active, $conv_active, $new_active, $starred_active, $bookmarked_active, $spam_active );
*/
-function network_query_get_sel_tab(App &$a) {
+function network_query_get_sel_tab(App $a) {
$no_active='';
$starred_active = '';
$new_active = '';
return $network;
}
-function network_query_get_sel_group(App &$a) {
+function network_query_get_sel_group(App $a) {
$group = false;
if($a->argc >= 2 && is_numeric($a->argv[1])) {
}
-function network_content(&$a, $update = 0) {
+function network_content(App $a, $update = 0) {
require_once('include/conversation.php');
$sql_order = "`item`.`id`";
$order_mode = "id";
} else {
- if (get_config('system','use_fulltext_engine'))
- $sql_extra = sprintf(" AND MATCH (`item`.`body`, `item`.`title`) AGAINST ('%s' in boolean mode) ", dbesc(protect_sprintf($search)));
- else
- $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
+ $sql_extra = sprintf(" AND `item`.`body` REGEXP '%s' ", dbesc(protect_sprintf(preg_quote($search))));
$sql_order = "`item`.`id`";
$order_mode = "id";
}
$pager_sql = '';
} else {
- if(get_config('system', 'old_pager')) {
- $r = qu("SELECT COUNT(*) AS `total`
- FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = $sql_table.`contact-id`
- AND (NOT `contact`.`blocked` OR `contact`.`pending`)
- WHERE $sql_table.`uid` = %d AND $sql_table.`visible` AND NOT $sql_table.`deleted`
- $sql_extra2 $sql_extra3
- $sql_extra $sql_nets ",
- intval($_SESSION['uid'])
- );
-
- if (dbm::is_result($r)) {
- $a->set_pager_total($r[0]['total']);
- }
- }
-
// check if we serve a mobile device and get the user settings
// accordingly
if ($a->is_mobile) {
intval($parents),
intval($max_comments + 1)
);
-
+
if (dbm::is_result($thread_items))
$items = array_merge($items, $thread_items);
}
// on they just get buried deeper. It has happened to me a couple of times also.
- if((! $group) && (! $cid) && (! $star)) {
+ if (!$group && !$cid && !$star) {
- $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `uid` = %d",
+ $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `uid` = %d LIMIT 1",
intval(local_user()));
- if ($unseen)
+ if (dbm::is_result($unseen)) {
$r = q("UPDATE `item` SET `unseen` = 0
WHERE `unseen` = 1 AND `uid` = %d",
intval(local_user())
);
- }
- else {
- if($update_unseen) {
+ }
+ } elseif ($update_unseen) {
- $unseen = q("SELECT `id` FROM `item` ".$update_unseen);
+ $unseen = q("SELECT `id` FROM `item` ".$update_unseen. " LIMIT 1");
- if ($unseen)
- $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
+ if (dbm::is_result($unseen)) {
+ $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen");
}
}
$mode = (($nouveau) ? 'network-new' : 'network');
- $o .= conversation($a,$items,$mode,$update);
+ $o .= conversation($a, $items, $mode, $update);
- if(!$update) {
- if(get_pconfig(local_user(),'system','infinite_scroll')) {
+ if (!$update) {
+ if (get_pconfig(local_user(), 'system', 'infinite_scroll')) {
$o .= scroll_loader();
- } elseif(!get_config('system', 'old_pager')) {
- $o .= alt_pager($a,count($items));
} else {
- $o .= paginate($a);
+ $o .= alt_pager($a, count($items));
}
}
/**
* @brief Get the network tabs menu
- *
+ *
* @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">';
);
}
- if(feature_enabled(local_user(),'new_tab')) {
+ if (feature_enabled(local_user(),'new_tab')) {
$tabs[] = array(
'label' => t('New'),
- 'url' => str_replace('/new', '', $cmd) . ($len_naked_cmd ? '/' : '') . 'new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
+ 'url' => 'network/new' . ((x($_GET,'cid')) ? '/?f=&cid=' . $_GET['cid'] : ''),
'sel' => $new_active,
'title' => t('Activity Stream - by date'),
'id' => 'activitiy-by-date-tab',
$arr = array('tabs' => $tabs);
call_hooks('network_tabs', $arr);
-
+
$tpl = get_markup_template('common_tabs.tpl');
return replace_macros($tpl, array('$tabs' => $arr['tabs']));