diff --git a/src/Backend.php b/src/Backend.php index 3d7117a..6fed614 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -40,6 +40,7 @@ class Backend extends dcNsProcess return false; } + // backend sidebar menu icon dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem( My::name(), dcCore::app()->adminurl->get('admin.plugin.' . My::id()), @@ -48,6 +49,7 @@ class Backend extends dcNsProcess dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id) ); + // backend user dashboard icon dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void { // nullsafe if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) { diff --git a/src/Frontend.php b/src/Frontend.php index c577b46..59d8a0c 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -32,10 +32,12 @@ class Frontend extends dcNsProcess return false; } + // add path to template dcCore::app()->tpl->setPath( dcCore::app()->tpl->getPath(), My::path() . DIRECTORY_SEPARATOR . 'default-templates' ); + // register template value for file alias dcCore::app()->tpl->addValue( 'fileAliasURL', [FrontendTemplate::class, 'fileAliasURL'] diff --git a/src/FrontendTemplate.php b/src/FrontendTemplate.php index 4b5afb4..79790b5 100644 --- a/src/FrontendTemplate.php +++ b/src/FrontendTemplate.php @@ -17,8 +17,22 @@ namespace Dotclear\Plugin\filesAlias; use ArrayObject; use dcCore; +/** + * File alias frontend template. + */ class FrontendTemplate { + /** + * Display file alias URL. + * + * attributes: + * + * - any filters See dcTemplate::getFilters() + * + * @param ArrayObject $attr The attributes + * + * @return string + */ public static function fileAliasURL(ArrayObject $attr): string { return 'url->register( 'filesalias', 'pub', diff --git a/src/UrlHandler.php b/src/UrlHandler.php index d682f66..2e35ed9 100644 --- a/src/UrlHandler.php +++ b/src/UrlHandler.php @@ -18,8 +18,16 @@ use dcCore; use dcMedia; use dcUrlHandlers; +/** + * File alias frontend URL handler. + */ class UrlHandler extends dcUrlHandlers { + /** + * File alias page. + * + * @param string $args The arguments + */ public static function alias(string $args): void { // nullsafe @@ -53,7 +61,14 @@ class UrlHandler extends dcUrlHandlers } } - public static function servefile(string $target, string $alias, bool $delete = false): void + /** + * File alias frontend file server. + * + * @param string $target The media file name + * @param string $alias The alias + * @param bool $delete Delete after serve + */ + private static function servefile(string $target, string $alias, bool $delete = false): void { $media = Utils::getMediaId($target); diff --git a/src/Utils.php b/src/Utils.php index 0a3bb43..a54f1ff 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -23,8 +23,16 @@ use Dotclear\Database\Statement\{ }; use Exception; +/** + * fileAlias records utils + */ class Utils { + /** + * Get aliases records. + * + * @return dcRecord The file alias records + */ public static function getAliases(): dcRecord { // nullsafe @@ -45,6 +53,11 @@ class Utils return is_null($rs) ? dcRecord::newFromArray([]) : $rs; } + /** + * Get alias record. + * + * @return dcRecord The alias record + */ public static function getAlias(string $url): dcRecord { // nullsafe @@ -66,6 +79,22 @@ class Utils return is_null($rs) ? dcRecord::newFromArray([]) : $rs; } + /** + * Update aliases. + * + * This remove all aliases on current blog + * before creating new ones. + * + * Each $aliases entry looks like: + * [ + * filesalias_url => string, + * filesalias_destination => string, + * filesalias_disposable => bool + * filesalias_password => string + * ] + * + * @param array $aliases The new aliases + */ public static function updateAliases(array $aliases): void { dcCore::app()->con->begin(); @@ -87,6 +116,14 @@ class Utils } } + /** + * Create an alias. + * + * @param string $url The URL + * @param string $destination The destination + * @param bool $disposable Is disposable + * @param null|string $password The optionnal password + */ public static function createAlias(string $url, string $destination, bool $disposable = false, ?string $password = null): void { if (empty($url)) { @@ -109,6 +146,9 @@ class Utils $cur->insert(); } + /** + * Delete all aliases. + */ public static function deleteAliases(): void { // nullsafe @@ -120,6 +160,11 @@ class Utils ->delete(); } + /** + * Dlete an alias. + * + * @param string $url The alias URL + */ public static function deleteAlias(string $url): void { // nullsafe @@ -132,6 +177,13 @@ class Utils ->delete(); } + /** + * Get media id. + * + * @param string $target The media file name + * + * @return int The media ID + */ public static function getMediaId(string $target): int { // nullsafe