2010-11-08 22:37:58 +00:00
|
|
|
<?php
|
2018-01-21 18:33:59 +00:00
|
|
|
/**
|
|
|
|
* @file mod/tagrm.php
|
|
|
|
*/
|
2018-02-15 02:33:55 +00:00
|
|
|
|
2017-04-30 04:07:00 +00:00
|
|
|
use Friendica\App;
|
2018-02-15 02:33:55 +00:00
|
|
|
use Friendica\Content\Text\BBCode;
|
2018-01-21 18:33:59 +00:00
|
|
|
use Friendica\Core\L10n;
|
2017-08-26 06:04:21 +00:00
|
|
|
use Friendica\Core\System;
|
2017-11-08 03:57:46 +00:00
|
|
|
use Friendica\Database\DBM;
|
2018-02-06 12:40:22 +00:00
|
|
|
use Friendica\Model\Item;
|
2017-04-30 04:07:00 +00:00
|
|
|
|
2017-01-09 12:14:55 +00:00
|
|
|
function tagrm_post(App $a) {
|
2010-11-08 22:37:58 +00:00
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!local_user()) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2016-12-20 11:35:18 +00:00
|
|
|
}
|
2010-11-08 22:37:58 +00:00
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
if ((x($_POST,'submit')) && ($_POST['submit'] === L10n::t('Cancel'))) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2016-12-20 11:35:18 +00:00
|
|
|
}
|
2010-11-08 22:37:58 +00:00
|
|
|
|
|
|
|
$tag = ((x($_POST,'tag')) ? hex2bin(notags(trim($_POST['tag']))) : '');
|
|
|
|
$item = ((x($_POST,'item')) ? intval($_POST['item']) : 0 );
|
|
|
|
|
|
|
|
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
|
|
|
intval($item),
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!DBM::is_result($r)) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2016-12-20 09:10:33 +00:00
|
|
|
}
|
2010-11-08 22:37:58 +00:00
|
|
|
|
|
|
|
$arr = explode(',', $r[0]['tag']);
|
2016-12-20 11:35:18 +00:00
|
|
|
for ($x = 0; $x < count($arr); $x ++) {
|
|
|
|
if ($arr[$x] === $tag) {
|
2010-11-08 22:37:58 +00:00
|
|
|
unset($arr[$x]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$tag_str = implode(',',$arr);
|
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
Item::update(['tag' => $tag_str], ['id' => $item]);
|
2010-11-08 22:37:58 +00:00
|
|
|
|
2018-01-21 18:33:59 +00:00
|
|
|
info(L10n::t('Tag removed') . EOL );
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2017-01-09 12:14:55 +00:00
|
|
|
|
2016-02-05 20:52:39 +00:00
|
|
|
// NOTREACHED
|
2010-11-08 22:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-07 14:11:34 +00:00
|
|
|
|
2017-01-09 12:14:55 +00:00
|
|
|
function tagrm_content(App $a) {
|
2010-11-08 22:37:58 +00:00
|
|
|
|
|
|
|
$o = '';
|
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!local_user()) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2010-11-08 22:37:58 +00:00
|
|
|
// NOTREACHED
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = (($a->argc > 1) ? intval($a->argv[1]) : 0);
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!$item) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2010-11-08 22:37:58 +00:00
|
|
|
// NOTREACHED
|
|
|
|
}
|
|
|
|
|
|
|
|
$r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
|
|
|
intval($item),
|
|
|
|
intval(local_user())
|
|
|
|
);
|
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!DBM::is_result($r)) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2016-12-20 09:10:33 +00:00
|
|
|
}
|
2010-11-08 22:37:58 +00:00
|
|
|
|
|
|
|
$arr = explode(',', $r[0]['tag']);
|
|
|
|
|
2018-02-06 12:40:22 +00:00
|
|
|
if (!count($arr)) {
|
2017-08-26 07:32:10 +00:00
|
|
|
goaway(System::baseUrl() . '/' . $_SESSION['photo_return']);
|
2016-12-20 10:56:34 +00:00
|
|
|
}
|
2010-11-08 22:37:58 +00:00
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
$o .= '<h3>' . L10n::t('Remove Item Tag') . '</h3>';
|
2010-11-08 22:37:58 +00:00
|
|
|
|
2018-01-22 14:16:25 +00:00
|
|
|
$o .= '<p id="tag-remove-desc">' . L10n::t('Select a tag to remove: ') . '</p>';
|
2010-11-08 22:37:58 +00:00
|
|
|
|
|
|
|
$o .= '<form id="tagrm" action="tagrm" method="post" >';
|
|
|
|
$o .= '<input type="hidden" name="item" value="' . $item . '" />';
|
|
|
|
$o .= '<ul>';
|
|
|
|
|
2016-12-20 20:31:05 +00:00
|
|
|
foreach ($arr as $x) {
|
2018-02-15 02:33:55 +00:00
|
|
|
$o .= '<li><input type="checkbox" name="tag" value="' . bin2hex($x) . '" >' . BBCode::convert($x) . '</input></li>';
|
2010-11-08 22:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$o .= '</ul>';
|
2018-01-22 14:16:25 +00:00
|
|
|
$o .= '<input id="tagrm-submit" type="submit" name="submit" value="' . L10n::t('Remove') .'" />';
|
|
|
|
$o .= '<input id="tagrm-cancel" type="submit" name="submit" value="' . L10n::t('Cancel') .'" />';
|
2010-11-08 22:37:58 +00:00
|
|
|
$o .= '</form>';
|
|
|
|
|
|
|
|
return $o;
|
2016-12-20 20:31:05 +00:00
|
|
|
|
2011-05-23 09:39:57 +00:00
|
|
|
}
|