use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\Exception\BookmarkNotFoundException;
use Shaarli\Formatter\BookmarkMarkdownFormatter;
+use Shaarli\Render\TemplatePage;
use Shaarli\Thumbnailer;
use Slim\Http\Request;
use Slim\Http\Response;
t('Shaare a new link') .' - '. $this->container->conf->get('general.title', 'Shaarli')
);
- return $response->write($this->render('addlink'));
+ return $response->write($this->render(TemplatePage::ADDLINK));
}
/**
$retrieveDescription
)
);
- if (! empty($title) && strtolower($charset) !== 'utf-8') {
+ if (! empty($title) && strtolower($charset) !== 'utf-8' && mb_check_encoding($charset)) {
$title = mb_convert_encoding($title, 'utf-8', $charset);
}
}
$title = $this->container->conf->get('general.default_note_title', t('Note: '));
}
- $link = escape([
+ $link = [
'title' => $title,
'url' => $url ?? '',
'description' => $description ?? '',
'tags' => $tags ?? '',
'private' => $private,
- ]);
+ ];
} else {
$formatter = $this->container->formatterFactory->getFormatter('raw');
$link = $formatter->format($bookmark);
$this->checkToken($request);
// lf_id should only be present if the link exists.
- $id = $request->getParam('lf_id') ? intval(escape($request->getParam('lf_id'))) : null;
+ $id = $request->getParam('lf_id') !== null ? intval(escape($request->getParam('lf_id'))) : null;
if (null !== $id && true === $this->container->bookmarkService->exists($id)) {
// Edit
$bookmark = $this->container->bookmarkService->get($id);
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$formatter = $this->container->formatterFactory->getFormatter('raw');
$data = $formatter->format($bookmark);
- $data = $this->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark);
return $this->redirectFromReferer(
$request,
$response,
- ['add-shaare', 'shaare'], ['addlink', 'post', 'edit_link'],
+ ['/admin/add-shaare', '/admin/shaare'], ['addlink', 'post', 'edit_link'],
$bookmark->getShortUrl()
);
}
}
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('delete_link', $data);
+ $this->executePageHooks('delete_link', $data);
$this->container->bookmarkService->remove($bookmark, false);
++ $count;
}
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark, false);
// To preserve backward compatibility with 3rd parties, plugins still use arrays
$data = $formatter->format($bookmark);
- $this->container->pluginManager->executeHooks('save_link', $data);
+ $this->executePageHooks('save_link', $data);
$bookmark->fromArray($data);
$this->container->bookmarkService->set($bookmark);
$tags[BookmarkMarkdownFormatter::NO_MD_TAG] = 1;
}
- $data = [
+ $data = escape([
'link' => $link,
'link_is_new' => $isNew,
- 'http_referer' => escape($this->container->environment['HTTP_REFERER'] ?? ''),
+ 'http_referer' => $this->container->environment['HTTP_REFERER'] ?? '',
'source' => $request->getParam('source') ?? '',
'tags' => $tags,
'default_private_links' => $this->container->conf->get('privacy.default_private_links', false),
- ];
+ ]);
- $data = $this->executeHooks('render_editlink', $data);
+ $this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
foreach ($data as $key => $value) {
$this->assignView($key, $value);
$editLabel . t('Shaare') .' - '. $this->container->conf->get('general.title', 'Shaarli')
);
- return $response->write($this->render('editlink'));
- }
-
- /**
- * @param mixed[] $data Variables passed to the template engine
- *
- * @return mixed[] Template data after active plugins render_picwall hook execution.
- */
- protected function executeHooks(string $hook, array $data): array
- {
- $this->container->pluginManager->executeHooks(
- $hook,
- $data
- );
-
- return $data;
+ return $response->write($this->render(TemplatePage::EDIT_LINK));
}
}