streams/Code/Module/Apporder.php

74 lines
2.4 KiB
PHP
Raw Normal View History

<?php
2022-02-16 04:08:28 +00:00
namespace Code\Module;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Lib\Apps;
use Code\Lib\Navbar;
2023-09-30 22:47:56 +00:00
use Code\Lib\PConfig;
2022-02-16 04:08:28 +00:00
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2021-12-02 22:33:36 +00:00
class Apporder extends Controller
{
2021-12-02 23:02:31 +00:00
public function get()
{
if (!local_channel()) {
2022-08-26 22:37:04 +00:00
return '';
2021-12-02 23:02:31 +00:00
}
2023-10-20 08:08:54 +00:00
if (get_pconfig(local_channel(), 'system', 'import_system_apps') !== datetime_convert('UTC', 'UTC', 'now', 'Y-m-d')) {
Apps::import_system_apps();
set_pconfig(local_channel(), 'system', 'import_system_apps', datetime_convert('UTC', 'UTC', 'now', 'Y-m-d'));
}
2022-01-25 04:16:38 +00:00
Navbar::set_selected('Order Apps');
2021-12-02 23:02:31 +00:00
2022-02-20 08:12:31 +00:00
$nav_apps = [];
$navbar_apps = [];
2023-09-30 22:47:56 +00:00
if (argc() > 1 && argv(1) === 'reset') {
PConfig::Delete(local_channel(), 'system', 'import_system_apps');
PConfig::Delete(local_channel(), 'system', 'app_order');
PConfig::Delete(local_channel(), 'system', 'app_pin_order');
goaway(z_root() . '/apporder');
}
2021-12-02 23:02:31 +00:00
foreach (['nav_featured_app', 'nav_pinned_app'] as $l) {
$syslist = [];
$list = Apps::app_list(local_channel(), false, [$l]);
if ($list) {
foreach ($list as $li) {
$syslist[] = Apps::app_encode($li);
}
}
Apps::translate_system_apps($syslist);
2022-02-16 04:08:28 +00:00
usort($syslist, 'Code\\Lib\\Apps::app_name_compare');
2021-12-02 23:02:31 +00:00
$syslist = Apps::app_order(local_channel(), $syslist, $l);
foreach ($syslist as $app) {
if ($l === 'nav_pinned_app') {
$navbar_apps[] = Apps::app_render($app, 'nav-order-pinned');
2022-02-20 08:12:31 +00:00
}
else {
2021-12-02 23:02:31 +00:00
$nav_apps[] = Apps::app_render($app, 'nav-order');
}
}
}
2022-02-12 20:43:29 +00:00
return replace_macros(Theme::get_template('apporder.tpl'), [
'$arrange' => t('Arrange Apps'),
2023-09-30 22:47:56 +00:00
'$reset' => t('Reset to site default order'),
'$header' => [t('Change order of pinned navbar apps'), t('Change order of app tray apps')],
2021-12-02 23:02:31 +00:00
'$desc' => [t('Use arrows to move the corresponding app left (top) or right (bottom) in the navbar'),
t('Use arrows to move the corresponding app up or down in the app tray')],
'$nav_apps' => $nav_apps,
'$navbar_apps' => $navbar_apps
]);
}
}