streams/Code/Widget/Appcategories.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2017-03-16 03:11:28 +00:00
<?php
2022-02-16 04:08:28 +00:00
namespace Code\Widget;
2017-03-16 03:11:28 +00:00
2022-02-16 04:08:28 +00:00
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2021-12-02 23:02:31 +00:00
class Appcategories
{
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
public function widget($arr)
{
2017-03-16 03:11:28 +00:00
2021-12-03 03:01:39 +00:00
if (!local_channel()) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
$selected = ((x($_REQUEST, 'cat')) ? htmlspecialchars($_REQUEST['cat'], ENT_COMPAT, 'UTF-8') : '');
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
// @FIXME ??? $srchurl undefined here - commented out until is reviewed
//$srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is','',$srchurl),'&');
//$srchurl = str_replace(array('?f=','&f='),array('',''),$srchurl);
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
// Leaving this line which negates the effect of the two invalid lines prior
$srchurl = z_root() . '/apps';
2021-12-03 03:01:39 +00:00
if (argc() > 1 && argv(1) === 'available') {
2021-12-02 23:02:31 +00:00
$srchurl .= '/available';
2021-12-03 03:01:39 +00:00
}
2018-07-05 05:56:43 +00:00
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
$terms = [];
2017-03-16 03:11:28 +00:00
2021-12-03 03:01:39 +00:00
$r = q(
"select distinct(term.term)
2017-03-16 03:11:28 +00:00
from term join app on term.oid = app.id
where app_channel = %d
and term.uid = app_channel
and term.otype = %d
and term.term != 'nav_featured_app'
and term.term != 'nav_pinned_app'
2017-03-16 03:11:28 +00:00
order by term.term asc",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval(TERM_OBJ_APP)
);
if ($r) {
2021-12-03 03:01:39 +00:00
foreach ($r as $rr) {
2021-12-02 23:02:31 +00:00
$terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : ''));
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2022-02-12 20:43:29 +00:00
return replace_macros(Theme::get_template('categories_widget.tpl'), array(
2021-12-02 23:02:31 +00:00
'$title' => t('Categories'),
'$desc' => '',
'$sel_all' => (($selected == '') ? 'selected' : ''),
'$all' => t('Everything'),
'$terms' => $terms,
'$base' => $srchurl,
));
}
}
2017-03-16 03:11:28 +00:00
}