streams/Code/Module/Apps.php

67 lines
1.9 KiB
PHP
Raw Normal View History

2016-04-19 03:38:38 +00:00
<?php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2016-04-19 03:38:38 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Lib as Zlib;
use Code\Web\Controller;
use Code\Lib\Channel;
use Code\Lib\Navbar;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2016-04-19 03:38:38 +00:00
2021-12-02 23:02:31 +00:00
class Apps extends Controller
{
public function get()
{
2022-01-25 04:16:38 +00:00
Navbar::set_selected('Apps');
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
if (argc() == 2 && argv(1) == 'edit') {
2021-12-02 23:02:31 +00:00
$mode = 'edit';
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$mode = 'list';
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$available = ((argc() == 2 && argv(1) === 'available') ? true : false);
$_SESSION['return_url'] = App::$query_string;
$apps = [];
if (local_channel()) {
Zlib\Apps::import_system_apps();
$syslist = [];
$cat = ((array_key_exists('cat', $_GET) && $_GET['cat']) ? [escape_tags($_GET['cat'])] : '');
2022-01-25 01:26:12 +00:00
$list = Zlib\Apps::app_list(($available || Channel::is_system(local_channel()) ? 0 : local_channel()), (($mode == 'edit') ? true : false), $cat);
2021-12-02 23:02:31 +00:00
if ($list) {
foreach ($list as $x) {
$syslist[] = Zlib\Apps::app_encode($x);
}
}
Zlib\Apps::translate_system_apps($syslist);
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$syslist = Zlib\Apps::get_system_apps(true);
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2022-02-16 04:08:28 +00:00
usort($syslist, 'Code\\Lib\\Apps::app_name_compare');
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
// logger('apps: ' . print_r($syslist,true));
2021-12-02 23:02:31 +00:00
foreach ($syslist as $app) {
$apps[] = Zlib\Apps::app_render($app, (($available) ? 'install' : $mode));
}
2022-09-04 00:20:42 +00:00
return replace_macros(Theme::get_template('myapps.tpl'), [
2021-12-02 23:02:31 +00:00
'$sitename' => get_config('system', 'sitename'),
'$cat' => $cat,
'$title' => (($available) ? t('Available Apps') : t('Installed Apps')),
'$apps' => $apps,
'$authed' => ((local_channel()) ? true : false),
'$manage' => (($available) ? EMPTY_STR : t('Manage apps')),
2021-12-02 23:02:31 +00:00
'$create' => (($mode == 'edit') ? t('Create Custom App') : '')
2022-09-04 00:20:42 +00:00
]);
2021-12-02 23:02:31 +00:00
}
2016-04-19 03:38:38 +00:00
}