streams/Code/Widget/Categories.php

198 lines
6 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
2018-09-10 11:34:05 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib\Apps;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2018-09-10 11:34:05 +00:00
2021-12-02 23:02:31 +00:00
class Categories
{
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-02 23:02:31 +00:00
$cards = ((array_key_exists('cards', $arr) && $arr['cards']) ? true : false);
2017-08-23 07:01:02 +00:00
2021-12-03 03:01:39 +00:00
if (($cards) && (!Apps::system_app_installed(App::$profile['profile_uid'], 'Cards'))) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-08-23 07:01:02 +00:00
2021-12-02 23:02:31 +00:00
$articles = ((array_key_exists('articles', $arr) && $arr['articles']) ? true : false);
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if (($articles) && (!Apps::addon_app_installed(App::$profile['profile_uid'], 'articles'))) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2017-11-22 23:39:06 +00:00
2021-12-03 03:01:39 +00:00
if (
(!App::$profile['profile_uid'])
|| (!perm_is_allowed(App::$profile['profile_uid'], get_observer_hash(), (($cards || $articles) ? 'view_pages' : 'view_articles')))
) {
2021-12-02 23:02:31 +00:00
return '';
}
2017-03-16 03:11:28 +00:00
2021-12-02 23:02:31 +00:00
$cat = ((x($_REQUEST, 'cat')) ? htmlspecialchars($_REQUEST['cat'], ENT_COMPAT, 'UTF-8') : '');
$srchurl = (($cards) ? App::$argv[0] . '/' . App::$argv[1] : App::$query_string);
$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-03 03:01:39 +00:00
if ($cards) {
2021-12-02 23:02:31 +00:00
return self::cardcategories_widget($srchurl, $cat);
2021-12-03 03:01:39 +00:00
} elseif ($articles) {
2021-12-02 23:02:31 +00:00
return self::articlecategories_widget($srchurl, $cat);
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
return self::categories_widget($srchurl, $cat);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2019-01-18 21:04:05 +00:00
2021-12-02 23:02:31 +00:00
public static function articlecategories_widget($baseurl, $selected = '')
{
2019-01-18 21:04:05 +00:00
2021-12-03 03:01:39 +00:00
if (!Apps::system_app_installed(App::$profile['profile_uid'], 'Categories')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2019-01-18 21:04:05 +00:00
2021-12-02 23:02:31 +00:00
$sql_extra = item_permissions_sql(App::$profile['profile_uid']);
$item_normal = "and item.item_hidden = 0 and item.item_type = 7 and item.item_deleted = 0
2019-01-18 21:04:05 +00:00
and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
and item.item_blocked = 0 ";
2017-08-23 07:01:02 +00:00
2021-12-02 23:02:31 +00:00
$terms = [];
2021-12-03 03:01:39 +00:00
$r = q(
"select distinct(term.term)
2019-01-18 21:04:05 +00:00
from term join item on term.oid = item.id
where item.uid = %d
and term.uid = item.uid
and term.ttype = %d
and term.otype = %d
and item.owner_xchan = '%s'
$item_normal
$sql_extra
order by term.term asc",
2021-12-02 23:02:31 +00:00
intval(App::$profile['profile_uid']),
intval(TERM_CATEGORY),
intval(TERM_OBJ_POST),
dbesc(App::$profile['channel_hash'])
);
if ($r && count($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' => $baseurl,
));
}
return '';
}
public static function cardcategories_widget($baseurl, $selected = '')
{
2021-12-03 03:01:39 +00:00
if (!Apps::system_app_installed(App::$profile['profile_uid'], 'Categories')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$sql_extra = item_permissions_sql(App::$profile['profile_uid']);
$item_normal = "and item.item_hidden = 0 and item.item_type = 6 and item.item_deleted = 0
2019-01-18 21:04:05 +00:00
and item.item_unpublished = 0 and item.item_delayed = 0 and item.item_pending_remove = 0
and item.item_blocked = 0 ";
2021-12-02 23:02:31 +00:00
$terms = [];
2021-12-03 03:01:39 +00:00
$r = q(
"select distinct(term.term)
2019-01-18 21:04:05 +00:00
from term join item on term.oid = item.id
where item.uid = %d
and term.uid = item.uid
and term.ttype = %d
and term.otype = %d
and item.owner_xchan = '%s'
$item_normal
$sql_extra
order by term.term asc",
2021-12-02 23:02:31 +00:00
intval(App::$profile['profile_uid']),
intval(TERM_CATEGORY),
intval(TERM_OBJ_POST),
dbesc(App::$profile['channel_hash'])
);
if ($r && count($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' => $baseurl,
));
}
return '';
}
public static function categories_widget($baseurl, $selected = '')
{
2021-12-03 03:01:39 +00:00
if (!Apps::system_app_installed(App::$profile['profile_uid'], 'Categories')) {
2021-12-02 23:02:31 +00:00
return '';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
require_once('include/security.php');
$sql_extra = item_permissions_sql(App::$profile['profile_uid']);
$item_normal = item_normal();
$terms = [];
2021-12-03 03:01:39 +00:00
$r = q(
"select distinct(term.term) from term join item on term.oid = item.id
2019-01-18 21:04:05 +00:00
where item.uid = %d
and term.uid = item.uid
and term.ttype = %d
and term.otype = %d
and item.owner_xchan = '%s'
and item.item_wall = 1
and item.verb != '%s'
$item_normal
$sql_extra
order by term.term asc",
2021-12-02 23:02:31 +00:00
intval(App::$profile['profile_uid']),
intval(TERM_CATEGORY),
intval(TERM_OBJ_POST),
dbesc(App::$profile['channel_hash']),
dbesc(ACTIVITY_UPDATE)
);
if ($r && count($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' => $baseurl,
));
}
return '';
}
2017-03-16 03:11:28 +00:00
}