2011-12-13 09:34:43 +00:00
|
|
|
<?php
|
2012-08-17 10:20:55 +00:00
|
|
|
class Pref_Labels extends Handler_Protected {
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2011-12-26 08:02:52 +00:00
|
|
|
function csrf_ignore($method) {
|
2021-02-12 15:38:26 +00:00
|
|
|
$csrf_ignored = array("index", "getlabeltree");
|
2011-12-26 08:02:52 +00:00
|
|
|
|
|
|
|
return array_search($method, $csrf_ignored) !== false;
|
|
|
|
}
|
|
|
|
|
2011-12-13 09:34:43 +00:00
|
|
|
function edit() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$label_id = clean($_REQUEST['id']);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color FROM ttrss_labels2 WHERE
|
2017-12-02 09:45:33 +00:00
|
|
|
id = ? AND owner_uid = ?");
|
|
|
|
$sth->execute([$label_id, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2021-02-13 10:17:34 +00:00
|
|
|
if ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
|
|
|
|
print json_encode($line);
|
|
|
|
} else {
|
|
|
|
print json_encode(["error" => "LABEL_NOT_FOUND"]);
|
2017-12-02 09:45:33 +00:00
|
|
|
}
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function getlabeltree() {
|
|
|
|
$root = array();
|
|
|
|
$root['id'] = 'root';
|
|
|
|
$root['name'] = __('Labels');
|
|
|
|
$root['items'] = array();
|
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT *
|
2011-12-13 09:34:43 +00:00
|
|
|
FROM ttrss_labels2
|
2017-12-02 09:45:33 +00:00
|
|
|
WHERE owner_uid = ?
|
2011-12-13 09:34:43 +00:00
|
|
|
ORDER BY caption");
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth->execute([$_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2011-12-13 09:34:43 +00:00
|
|
|
$label = array();
|
|
|
|
$label['id'] = 'LABEL:' . $line['id'];
|
|
|
|
$label['bare_id'] = $line['id'];
|
|
|
|
$label['name'] = $line['caption'];
|
|
|
|
$label['fg_color'] = $line['fg_color'];
|
|
|
|
$label['bg_color'] = $line['bg_color'];
|
|
|
|
$label['type'] = 'label';
|
|
|
|
$label['checkbox'] = false;
|
|
|
|
|
|
|
|
array_push($root['items'], $label);
|
|
|
|
}
|
|
|
|
|
|
|
|
$fl = array();
|
|
|
|
$fl['identifier'] = 'id';
|
|
|
|
$fl['label'] = 'name';
|
|
|
|
$fl['items'] = array($root);
|
|
|
|
|
|
|
|
print json_encode($fl);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function colorset() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$kind = clean($_REQUEST["kind"]);
|
|
|
|
$ids = explode(',', clean($_REQUEST["ids"]));
|
|
|
|
$color = clean($_REQUEST["color"]);
|
|
|
|
$fg = clean($_REQUEST["fg"]);
|
|
|
|
$bg = clean($_REQUEST["bg"]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
|
|
|
|
if ($kind == "fg" || $kind == "bg") {
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
|
|
|
|
${kind}_color = ? WHERE id = ?
|
|
|
|
AND owner_uid = ?");
|
|
|
|
|
|
|
|
$sth->execute([$color, $id, $_SESSION['uid']]);
|
|
|
|
|
2011-12-13 09:34:43 +00:00
|
|
|
} else {
|
2017-12-02 09:45:33 +00:00
|
|
|
|
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
|
|
|
|
fg_color = ?, bg_color = ? WHERE id = ?
|
|
|
|
AND owner_uid = ?");
|
|
|
|
|
|
|
|
$sth->execute([$fg, $bg, $id, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove cached data */
|
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = ''
|
2018-12-06 05:29:32 +00:00
|
|
|
WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function colorreset() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$ids = explode(',', clean($_REQUEST["ids"]));
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
|
|
|
|
fg_color = '', bg_color = '' WHERE id = ?
|
|
|
|
AND owner_uid = ?");
|
|
|
|
$sth->execute([$id, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
/* Remove cached data */
|
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_user_entries SET label_cache = ''
|
2018-12-06 05:29:32 +00:00
|
|
|
WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
|
2017-12-03 20:35:38 +00:00
|
|
|
$id = clean($_REQUEST["id"]);
|
2021-02-05 20:41:32 +00:00
|
|
|
$caption = clean($_REQUEST["caption"]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$this->pdo->beginTransaction();
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT caption FROM ttrss_labels2
|
|
|
|
WHERE id = ? AND owner_uid = ?");
|
|
|
|
$sth->execute([$id, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
$old_caption = $row["caption"];
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("SELECT id FROM ttrss_labels2
|
|
|
|
WHERE caption = ? AND owner_uid = ?");
|
|
|
|
$sth->execute([$caption, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
if (!$sth->fetch()) {
|
2011-12-13 09:34:43 +00:00
|
|
|
if ($caption) {
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET
|
|
|
|
caption = ? WHERE id = ? AND
|
|
|
|
owner_uid = ?");
|
|
|
|
$sth->execute([$caption, $id, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
/* Update filters that reference label being renamed */
|
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET
|
|
|
|
action_param = ? WHERE action_param = ?
|
2011-12-13 09:34:43 +00:00
|
|
|
AND action_id = 7
|
2017-12-02 09:45:33 +00:00
|
|
|
AND filter_id IN (SELECT id FROM ttrss_filters2 WHERE owner_uid = ?)");
|
|
|
|
|
|
|
|
$sth->execute([$caption, $old_caption, $_SESSION['uid']]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
2021-02-13 10:50:53 +00:00
|
|
|
print clean($_REQUEST["caption"]);
|
2011-12-13 09:34:43 +00:00
|
|
|
} else {
|
|
|
|
print $old_caption;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print $old_caption;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-02 09:45:33 +00:00
|
|
|
$this->pdo->commit();
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove() {
|
|
|
|
|
2017-12-03 20:35:38 +00:00
|
|
|
$ids = explode(",", clean($_REQUEST["ids"]));
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
2017-05-04 12:57:40 +00:00
|
|
|
Labels::remove($id, $_SESSION["uid"]);
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function add() {
|
2017-12-03 20:35:38 +00:00
|
|
|
$caption = clean($_REQUEST["caption"]);
|
|
|
|
$output = clean($_REQUEST["output"]);
|
2011-12-13 09:34:43 +00:00
|
|
|
|
|
|
|
if ($caption) {
|
|
|
|
|
2017-05-04 12:57:40 +00:00
|
|
|
if (Labels::create($caption)) {
|
2011-12-13 09:34:43 +00:00
|
|
|
if (!$output) {
|
|
|
|
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($output == "select") {
|
|
|
|
header("Content-Type: text/xml");
|
|
|
|
|
|
|
|
print "<rpc-reply><payload>";
|
|
|
|
|
2013-04-17 14:34:18 +00:00
|
|
|
print_label_select("select_label",
|
2011-12-13 09:34:43 +00:00
|
|
|
$caption, "");
|
|
|
|
|
|
|
|
print "</payload></rpc-reply>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function index() {
|
2021-02-13 10:26:17 +00:00
|
|
|
?>
|
|
|
|
<div dojoType='dijit.layout.BorderContainer' gutters='false'>
|
|
|
|
<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>
|
|
|
|
<div dojoType='fox.Toolbar'>
|
|
|
|
<div dojoType='fox.form.DropDownButton'>
|
2021-02-14 06:15:51 +00:00
|
|
|
<span><?= __('Select') ?></span>
|
2021-02-13 10:26:17 +00:00
|
|
|
<div dojoType='dijit.Menu' style='display: none'>
|
|
|
|
<div onclick="dijit.byId('labelTree').model.setAllChecked(true)"
|
2021-02-14 06:15:51 +00:00
|
|
|
dojoType='dijit.MenuItem'><?=('All') ?></div>
|
2021-02-13 10:26:17 +00:00
|
|
|
<div onclick="dijit.byId('labelTree').model.setAllChecked(false)"
|
2021-02-14 06:15:51 +00:00
|
|
|
dojoType='dijit.MenuItem'><?=('None') ?></div>
|
2021-02-13 10:26:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick='CommonDialogs.addLabel()'>
|
2021-02-14 06:15:51 +00:00
|
|
|
<?=('Create label') ?></button dojoType='dijit.form.Button'>
|
2021-02-13 10:26:17 +00:00
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick="dijit.byId('labelTree').removeSelected()">
|
2021-02-14 06:15:51 +00:00
|
|
|
<?=('Remove') ?></button dojoType='dijit.form.Button'>
|
2021-02-13 10:26:17 +00:00
|
|
|
|
|
|
|
<button dojoType='dijit.form.Button' onclick="dijit.byId('labelTree').resetColors()">
|
2021-02-14 06:15:51 +00:00
|
|
|
<?=('Clear colors') ?></button dojoType='dijit.form.Button'>
|
2021-02-13 10:26:17 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>
|
|
|
|
<div dojoType='dojo.data.ItemFileWriteStore' jsId='labelStore'
|
|
|
|
url='backend.php?op=pref-labels&method=getlabeltree'>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div dojoType='lib.CheckBoxStoreModel' jsId='labelModel' store='labelStore'
|
|
|
|
query="{id:'root'}" rootId='root'
|
|
|
|
childrenAttrs='items' checkboxStrict='false' checkboxAll='false'>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div dojoType='fox.PrefLabelTree' id='labelTree' model='labelModel' openOnClick='true'>
|
|
|
|
<script type='dojo/method' event='onClick' args='item'>
|
|
|
|
var id = String(item.id);
|
|
|
|
var bare_id = id.substr(id.indexOf(':')+1);
|
|
|
|
|
|
|
|
if (id.match('LABEL:')) {
|
|
|
|
dijit.byId('labelTree').editLabel(bare_id);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefLabels") ?>
|
2011-12-13 09:34:43 +00:00
|
|
|
</div>
|
2021-02-13 10:26:17 +00:00
|
|
|
<?php
|
2011-12-13 09:34:43 +00:00
|
|
|
}
|
2018-12-02 22:15:31 +00:00
|
|
|
}
|