code doc
parent
6929028c71
commit
5e734c25f4
|
@ -40,6 +40,7 @@ class Backend extends dcNsProcess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// backend sidebar menu icon
|
||||||
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
|
dcCore::app()->menu[dcAdmin::MENU_BLOG]->addItem(
|
||||||
My::name(),
|
My::name(),
|
||||||
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
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)
|
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 {
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
||||||
// nullsafe
|
// nullsafe
|
||||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->adminurl)) {
|
||||||
|
|
|
@ -32,10 +32,12 @@ class Frontend extends dcNsProcess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add path to template
|
||||||
dcCore::app()->tpl->setPath(
|
dcCore::app()->tpl->setPath(
|
||||||
dcCore::app()->tpl->getPath(),
|
dcCore::app()->tpl->getPath(),
|
||||||
My::path() . DIRECTORY_SEPARATOR . 'default-templates'
|
My::path() . DIRECTORY_SEPARATOR . 'default-templates'
|
||||||
);
|
);
|
||||||
|
// register template value for file alias
|
||||||
dcCore::app()->tpl->addValue(
|
dcCore::app()->tpl->addValue(
|
||||||
'fileAliasURL',
|
'fileAliasURL',
|
||||||
[FrontendTemplate::class, 'fileAliasURL']
|
[FrontendTemplate::class, 'fileAliasURL']
|
||||||
|
|
|
@ -17,8 +17,22 @@ namespace Dotclear\Plugin\filesAlias;
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File alias frontend template.
|
||||||
|
*/
|
||||||
class FrontendTemplate
|
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
|
public static function fileAliasURL(ArrayObject $attr): string
|
||||||
{
|
{
|
||||||
return '<?php echo ' . sprintf(
|
return '<?php echo ' . sprintf(
|
||||||
|
|
|
@ -32,6 +32,7 @@ class Prepend extends dcNsProcess
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// register file alias frontend URL handler
|
||||||
dcCore::app()->url->register(
|
dcCore::app()->url->register(
|
||||||
'filesalias',
|
'filesalias',
|
||||||
'pub',
|
'pub',
|
||||||
|
|
|
@ -18,8 +18,16 @@ use dcCore;
|
||||||
use dcMedia;
|
use dcMedia;
|
||||||
use dcUrlHandlers;
|
use dcUrlHandlers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File alias frontend URL handler.
|
||||||
|
*/
|
||||||
class UrlHandler extends dcUrlHandlers
|
class UrlHandler extends dcUrlHandlers
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* File alias page.
|
||||||
|
*
|
||||||
|
* @param string $args The arguments
|
||||||
|
*/
|
||||||
public static function alias(string $args): void
|
public static function alias(string $args): void
|
||||||
{
|
{
|
||||||
// nullsafe
|
// 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);
|
$media = Utils::getMediaId($target);
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,16 @@ use Dotclear\Database\Statement\{
|
||||||
};
|
};
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fileAlias records utils
|
||||||
|
*/
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Get aliases records.
|
||||||
|
*
|
||||||
|
* @return dcRecord The file alias records
|
||||||
|
*/
|
||||||
public static function getAliases(): dcRecord
|
public static function getAliases(): dcRecord
|
||||||
{
|
{
|
||||||
// nullsafe
|
// nullsafe
|
||||||
|
@ -45,6 +53,11 @@ class Utils
|
||||||
return is_null($rs) ? dcRecord::newFromArray([]) : $rs;
|
return is_null($rs) ? dcRecord::newFromArray([]) : $rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get alias record.
|
||||||
|
*
|
||||||
|
* @return dcRecord The alias record
|
||||||
|
*/
|
||||||
public static function getAlias(string $url): dcRecord
|
public static function getAlias(string $url): dcRecord
|
||||||
{
|
{
|
||||||
// nullsafe
|
// nullsafe
|
||||||
|
@ -66,6 +79,22 @@ class Utils
|
||||||
return is_null($rs) ? dcRecord::newFromArray([]) : $rs;
|
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
|
public static function updateAliases(array $aliases): void
|
||||||
{
|
{
|
||||||
dcCore::app()->con->begin();
|
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
|
public static function createAlias(string $url, string $destination, bool $disposable = false, ?string $password = null): void
|
||||||
{
|
{
|
||||||
if (empty($url)) {
|
if (empty($url)) {
|
||||||
|
@ -109,6 +146,9 @@ class Utils
|
||||||
$cur->insert();
|
$cur->insert();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all aliases.
|
||||||
|
*/
|
||||||
public static function deleteAliases(): void
|
public static function deleteAliases(): void
|
||||||
{
|
{
|
||||||
// nullsafe
|
// nullsafe
|
||||||
|
@ -120,6 +160,11 @@ class Utils
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dlete an alias.
|
||||||
|
*
|
||||||
|
* @param string $url The alias URL
|
||||||
|
*/
|
||||||
public static function deleteAlias(string $url): void
|
public static function deleteAlias(string $url): void
|
||||||
{
|
{
|
||||||
// nullsafe
|
// nullsafe
|
||||||
|
@ -132,6 +177,13 @@ class Utils
|
||||||
->delete();
|
->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get media id.
|
||||||
|
*
|
||||||
|
* @param string $target The media file name
|
||||||
|
*
|
||||||
|
* @return int The media ID
|
||||||
|
*/
|
||||||
public static function getMediaId(string $target): int
|
public static function getMediaId(string $target): int
|
||||||
{
|
{
|
||||||
// nullsafe
|
// nullsafe
|
||||||
|
|
Loading…
Reference in New Issue