Merge pull request #7090 from nupplaphil/task/mod_like
[friendica.git/.git] / src / Module / Filer.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\L10n;
7 use Friendica\Core\PConfig;
8 use Friendica\Core\Renderer;
9 use Friendica\Model;
10 use Friendica\Util\XML;
11
12 /**
13  * Shows a dialog for adding tags to a file
14  */
15 class Filer extends BaseModule
16 {
17         public static function init()
18         {
19                 if (!local_user()) {
20                         info(L10n::t('You must be logged in to use this module'));
21                         self::getApp()->internalRedirect();
22                 }
23         }
24
25         public static function rawContent()
26         {
27                 $a = self::getApp();
28                 $logger = $a->getLogger();
29
30                 $term = XML::unescape(trim(defaults($_GET, 'term', '')));
31                 // @TODO: Replace with parameter from router
32                 $item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
33
34                 $logger->info('filer', ['tag' => $term, 'item' => $item_id]);
35
36                 if ($item_id && strlen($term)) {
37                         // file item
38                         Model\FileTag::saveFile(local_user(), $item_id, $term);
39                         info(L10n::t('Filetag %s saved to item', $term));
40                 }
41
42                 // return filer dialog
43                 $filetags = PConfig::get(local_user(), 'system', 'filetags');
44                 $filetags = Model\FileTag::fileToList($filetags, 'file');
45                 $filetags = explode(",", $filetags);
46
47                 $tpl = Renderer::getMarkupTemplate("filer_dialog.tpl");
48                 echo Renderer::replaceMacros($tpl, [
49                         '$field' => ['term', L10n::t("Save to Folder:"), '', '', $filetags, L10n::t('- select -')],
50                         '$submit' => L10n::t('Save'),
51                 ]);
52
53                 exit;
54         }
55 }