streams/Zotlabs/Widget/Stream_order.php

139 lines
2.8 KiB
PHP
Raw Normal View History

2018-05-30 12:06:18 +00:00
<?php
namespace Zotlabs\Widget;
2018-09-05 01:44:02 +00:00
use Zotlabs\Lib\Apps;
use App;
class Stream_order {
2018-05-30 12:06:18 +00:00
function widget($arr) {
if(! local_channel())
return '';
2018-09-05 01:44:02 +00:00
$module = 'mod_' . App::$module;
if(! Apps::addon_app_installed(local_channel(),'stream_order')) {
set_pconfig(local_channel(), $module, 'order', 0);
2018-05-30 12:06:18 +00:00
return '';
}
$commentord_active = '';
$postord_active = '';
$unthreaded_active = '';
if(x($_GET, 'order')) {
switch($_GET['order']){
case 'post':
$postord_active = 'active';
2018-09-05 01:44:02 +00:00
set_pconfig(local_channel(), $module, 'order', 1);
2018-05-30 12:06:18 +00:00
break;
case 'comment':
$commentord_active = 'active';
2018-09-05 01:44:02 +00:00
set_pconfig(local_channel(), $module, 'order', 0);
2018-05-30 12:06:18 +00:00
break;
case 'unthreaded':
$unthreaded_active = 'active';
2018-09-05 01:44:02 +00:00
set_pconfig(local_channel(), $module, 'order', 2);
2018-05-30 12:06:18 +00:00
break;
default:
$commentord_active = 'active';
2018-08-01 23:12:44 +00:00
break;
2018-05-30 12:06:18 +00:00
}
}
else {
2018-09-05 01:44:02 +00:00
$order = get_pconfig(local_channel(), $module, 'order', 0);
2018-05-30 12:06:18 +00:00
switch($order) {
case 0:
$commentord_active = 'active';
break;
case 1:
$postord_active = 'active';
break;
case 2:
$unthreaded_active = 'active';
break;
default:
$commentord_active = 'active';
}
}
// override order for search, filer and cid results
if(x($_GET,'search') || x($_GET,'file') || (! x($_GET,'pf') && x($_GET,'cid'))) {
$unthreaded_active = 'active';
$commentord_active = $postord_active = 'disabled';
}
2018-09-05 01:44:02 +00:00
$cmd = App::$cmd;
2018-05-30 12:06:18 +00:00
$filter = '';
if(x($_GET,'cid'))
$filter .= '&cid=' . $_GET['cid'];
if(x($_GET,'gid'))
$filter .= '&gid=' . $_GET['gid'];
if(x($_GET,'star'))
$filter .= '&star=' . $_GET['star'];
if(x($_GET,'conv'))
$filter .= '&conv=' . $_GET['conv'];
if(x($_GET,'file'))
$filter .= '&file=' . $_GET['file'];
2018-08-01 23:12:44 +00:00
if(x($_GET,'pf'))
$filter .= '&pf=' . $_GET['pf'];
2018-05-30 12:06:18 +00:00
// tabs
$tabs = [];
$tabs[] = [
'label' => t('Commented Date'),
2018-06-01 11:30:02 +00:00
'icon' => '',
2018-05-30 12:06:18 +00:00
'url'=>z_root() . '/' . $cmd . '?f=&order=comment' . $filter,
'sel'=> $commentord_active,
2018-05-31 11:13:46 +00:00
'title' => t('Order by last commented date'),
2018-05-30 12:06:18 +00:00
];
$tabs[] = [
'label' => t('Posted Date'),
2018-06-01 11:30:02 +00:00
'icon' => '',
2018-05-30 12:06:18 +00:00
'url'=>z_root() . '/' . $cmd . '?f=&order=post' . $filter,
'sel'=> $postord_active,
2018-05-31 11:13:46 +00:00
'title' => t('Order by last posted date'),
2018-05-30 12:06:18 +00:00
];
$tabs[] = array(
'label' => t('Date Unthreaded'),
2018-06-01 11:30:02 +00:00
'icon' => '',
2018-05-30 12:06:18 +00:00
'url' => z_root() . '/' . $cmd . '?f=&order=unthreaded' . $filter,
'sel' => $unthreaded_active,
2018-05-31 11:13:46 +00:00
'title' => t('Order unthreaded by date'),
2018-05-30 12:06:18 +00:00
);
$arr = ['tabs' => $tabs];
call_hooks('activity_order', $arr);
2018-05-30 12:06:18 +00:00
2018-06-01 10:11:07 +00:00
$o = '';
2018-05-30 12:06:18 +00:00
if($arr['tabs']) {
2018-06-01 10:11:07 +00:00
$content = replace_macros(get_markup_template('common_pills.tpl'), [
'$pills' => $arr['tabs'],
]);
$o = replace_macros(get_markup_template('common_widget.tpl'), [
2018-09-05 01:44:02 +00:00
'$title' => t('Stream Order'),
2018-06-01 10:11:07 +00:00
'$content' => $content,
2018-05-30 12:06:18 +00:00
]);
}
2018-06-01 10:11:07 +00:00
return $o;
2018-05-30 12:06:18 +00:00
}
}