streams/Code/Module/Filer.php

72 lines
2 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
2021-12-02 22:33:36 +00:00
use App;
2022-02-16 04:08:28 +00:00
use Code\Web\Controller;
use Code\Render\Theme;
2022-02-12 20:43:29 +00:00
2021-12-02 22:33:36 +00:00
2016-04-19 03:38:38 +00:00
require_once('include/security.php');
require_once('include/bbcode.php');
2021-12-02 23:02:31 +00:00
class Filer extends Controller
{
public function get()
{
if (!local_channel()) {
killme();
}
$term = unxmlify(trim($_GET['term']));
$item_id = ((App::$argc > 1) ? intval(App::$argv[1]) : 0);
logger('filer: tag ' . $term . ' item ' . $item_id);
if ($item_id && strlen($term)) {
// file item
store_item_tag(local_channel(), $item_id, TERM_OBJ_POST, TERM_FILE, $term, '');
// protect the entire conversation from periodic expiration
2021-12-03 03:01:39 +00:00
$r = q(
"select parent from item where id = %d and uid = %d limit 1",
2021-12-02 23:02:31 +00:00
intval($item_id),
intval(local_channel())
);
if ($r) {
2021-12-03 03:01:39 +00:00
$x = q(
"update item set item_retained = 1 where id = %d and uid = %d",
2021-12-02 23:02:31 +00:00
intval($r[0]['parent']),
intval(local_channel())
);
}
} else {
$filetags = [];
2021-12-03 03:01:39 +00:00
$r = q(
"select distinct(term) from term where uid = %d and ttype = %d order by term asc",
2021-12-02 23:02:31 +00:00
intval(local_channel()),
intval(TERM_FILE)
);
if (count($r)) {
2021-12-03 03:01:39 +00:00
foreach ($r as $rr) {
2021-12-02 23:02:31 +00:00
$filetags[] = $rr['term'];
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
}
2022-02-12 20:43:29 +00:00
$tpl = Theme::get_template("filer_dialog.tpl");
2022-09-04 01:35:50 +00:00
$o = replace_macros($tpl, [
'$field' => ['term', t('Enter a folder name'), '', '', $filetags, 'placeholder="' . t('or select an existing folder (doubleclick)') . '"'],
2021-12-02 23:02:31 +00:00
'$submit' => t('Save'),
'$title' => t('Save to Folder'),
'$cancel' => t('Cancel')
2022-09-04 01:35:50 +00:00
]);
2021-12-02 23:02:31 +00:00
echo $o;
}
killme();
}
2016-04-19 03:38:38 +00:00
}