upgrade to Dotclear 2.28

This commit is contained in:
Jean-Christian Paul Denis 2023-10-19 20:32:57 +02:00
parent 2063f6e4f9
commit f38c7328a9
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
38 changed files with 620 additions and 750 deletions

View File

@ -1,3 +1,10 @@
kUtRL 2023.10.19
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1
* Upgrade to Dotclear 2.28
* Upgrade plugin activityReport
kUtRL 2023.08.21 kUtRL 2023.08.21
=========================================================== ===========================================================
* Require Dotclear 2.27 * Require Dotclear 2.27

View File

@ -1,8 +1,8 @@
# README # README
[![Release](https://img.shields.io/badge/release-2023.08.21-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/kUtRL/releases) [![Release](https://img.shields.io/badge/release-2023.10.19-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/kUtRL/releases)
![Date](https://img.shields.io/badge/date-2023.08.21-c44d58.svg) ![Date](https://img.shields.io/badge/date-2023.10.19-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-137bbb.svg)](https://fr.dotclear.org/download) [![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/kUtRL) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/kUtRL)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/kUtRL/src/branch/master/LICENSE) [![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/kUtRL/src/branch/master/LICENSE)
@ -14,7 +14,7 @@ _kUtRL_ is a plugin for the open-source web publishing software called [Dotclear
## REQUIREMENTS ## REQUIREMENTS
* Dotclear 2.27 * Dotclear 2.28
* PHP 8.1+ * PHP 8.1+
* Dotclear admin permission to configure * Dotclear admin permission to configure
* No specials permissions to shorten links on the fly * No specials permissions to shorten links on the fly

View File

@ -1,37 +1,29 @@
<?php <?php
/** /**
* @brief kUtRL, a plugin for Dotclear 2 * @file
* @brief The plugin kUtRL definition
* @ingroup kUtRL
* *
* @package Dotclear * @defgroup kUtRL Plugin kUtRL.
* @subpackage Plugin
* *
* @author Jean-Christian Denis and contributors * Use, create and serve short url on your blog.
* *
* @copyright Jean-Christian Denis * @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { declare(strict_types=1);
return null;
}
$this->registerModule( $this->registerModule(
'Links shortener', 'Links shortener',
'Use, create and serve short url on your blog', 'Use, create and serve short url on your blog',
'Jean-Christian Denis and contributors', 'Jean-Christian Denis and contributors',
'2023.08.21', '2023.10.19',
[ [
'requires' => [ 'requires' => [['core', '2.28']],
['core', '2.27'], 'permissions' => 'My',
['php', '8.1'], 'type' => 'plugin',
], 'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'permissions' => dcCore::app()->auth->makePermissions([ 'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
dcAuth::PERMISSION_USAGE, 'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
dcAuth::PERMISSION_CONTENT_ADMIN,
dcAuth::PERMISSION_ADMIN,
]),
'type' => 'plugin',
'support' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/issues',
'details' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/src/branch/master/README.md',
'repository' => 'https://git.dotclear.watch/JcDenis/' . basename(__DIR__) . '/raw/branch/master/dcstore.xml',
] ]
); );

View File

@ -1,20 +0,0 @@
<?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initkUtRL
{
public const KURL_TABLE_NAME = 'kutrl';
}

View File

@ -2,11 +2,11 @@
<modules xmlns:da="http://dotaddict.org/da/"> <modules xmlns:da="http://dotaddict.org/da/">
<module id="kUtRL"> <module id="kUtRL">
<name>Links shortener</name> <name>Links shortener</name>
<version>2023.08.21</version> <version>2023.10.19</version>
<author>Jean-Christian Denis and contributors</author> <author>Jean-Christian Denis and contributors</author>
<desc>Use, create and serve short url on your blog</desc> <desc>Use, create and serve short url on your blog</desc>
<file>https://git.dotclear.watch/JcDenis/kUtRL/releases/download/v2023.08.21/plugin-kUtRL.zip</file> <file>https://git.dotclear.watch/JcDenis/kUtRL/releases/download/v2023.10.19/plugin-kUtRL.zip</file>
<da:dcmin>2.27</da:dcmin> <da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/kUtRL/src/branch/master/README.md</da:details> <da:details>https://git.dotclear.watch/JcDenis/kUtRL/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/kUtRL/issues</da:support> <da:support>https://git.dotclear.watch/JcDenis/kUtRL/issues</da:support>
</module> </module>

View File

@ -1,17 +1,10 @@
<?php <?php
/** /**
* @brief kUtRL, a plugin for Dotclear 2 * @file
* @brief The plugin kUtRL locales resources
* @ingroup kUtRL
* *
* @package Dotclear * @author Jean-Christian Denis (author)
* @subpackage Plugin * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'kUtRL', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html';

View File

@ -1,17 +1,10 @@
<?php <?php
/** /**
* @brief kUtRL, a plugin for Dotclear 2 * @file
* @brief The plugin kUtRL locales resources
* @ingroup kUtRL
* *
* @package Dotclear * @author Jean-Christian Denis (author)
* @subpackage Plugin * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
if (!defined('DC_RC_PATH')) { \Dotclear\App::backend()->resources()->set('help', 'kUtRL', __DIR__ . '/help/help.html');
return;
}
dcCore::app()->resources['help']['kUtRL'] = __DIR__ . '/help/help.html';

View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL;
use Dotclear\Core\Process;
use Dotclear\Database\MetaRecord;
use Dotclear\Plugin\activityReport\{
Action,
ActivityReport,
Group
};
/**
* @brief kUtRL plugin activityReport class.
* @ingroup kUtRL
*
* Add links actions to the plugin activity report.
*
* @author Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ActivityReportAction extends Process
{
public static function init(): bool
{
return self::status(true);
}
public static function process(): bool
{
if (!self::status()) {
return false;
}
$group = new Group(My::id(), My::name());
# from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php
$group->add(new Action(
'kUtRLcreate',
__('Short link creation'),
__('New short link of type "%s" and hash "%s" was created.'),
'kutrlAfterCreateShortUrl',
function (MetaRecord $rs) {
ActivityReport::instance()->addLog(My::id(), 'kUtRLcreate', [$rs->type, $rs->hash]);
}
));
ActivityReport::instance()->groups->add($group);
return true;
}
}

View File

@ -1,31 +0,0 @@
<?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
# This file is used with plugin activityReport
if (!defined('DC_RC_PATH')) {
return null;
}
dcCore::app()->__get('activityReport')->addGroup('kutrl', __('Plugin kUtRL'));
# from BEHAVIOR kutrlAfterCreateShortUrl in kUtRL/inc/lib.kutrl.srv.php
dcCore::app()->__get('activityReport')->addAction(
'kutrl',
'create',
__('Short link creation'),
__('New short link of type "%s" and hash "%s" was created.'),
'kutrlAfterCreateShortUrl',
function ($rs) {
dcCore::app()->__get('activityReport')->addLog('kutrl', 'create', [$rs->type, $rs->hash]);
}
);

View File

@ -1,24 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* Backend prepend. * @brief kUtRL backend class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Backend extends Process class Backend extends Process
{ {
@ -38,29 +32,27 @@ class Backend extends Process
# Admin behaviors # Admin behaviors
if (My::settings()->get('active')) { if (My::settings()->get('active')) {
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'adminDashboardFavoritesV2' => [BackendBehaviors::class, 'antispamDashboardFavoritesV2'], 'adminDashboardFavoritesV2' => BackendBehaviors::antispamDashboardFavoritesV2(...),
'adminColumnsListsV2' => [BackendBehaviors::class, 'adminColumnsListsV2'], 'adminColumnsListsV2' => BackendBehaviors::adminColumnsListsV2(...),
'adminFiltersListsV2' => [BackendBehaviors::class, 'adminFiltersListsV2'], 'adminFiltersListsV2' => BackendBehaviors::adminFiltersListsV2(...),
'adminPostHeaders' => [BackendBehaviors::class, 'adminPostHeaders'], 'adminPostHeaders' => BackendBehaviors::adminPostHeaders(...),
'adminPostFormItems' => [BackendBehaviors::class, 'adminPostFormItems'], 'adminPostFormItems' => BackendBehaviors::adminPostFormItems(...),
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostUpdate'], // update existing short url 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostUpdate(...), // update existing short url
'adminAfterPostUpdate' => [BackendBehaviors::class, 'adminAfterPostCreate'], // create new short url 'adminAfterPostUpdate' => BackendBehaviors::adminAfterPostCreate(...), // create new short url
'adminAfterPostCreate' => [BackendBehaviors::class, 'adminAfterPostCreate'], 'adminAfterPostCreate' => BackendBehaviors::adminAfterPostCreate(...),
'adminBeforePostDelete' => [BackendBehaviors::class, 'adminBeforePostDelete'], 'adminBeforePostDelete' => BackendBehaviors::adminBeforePostDelete(...),
'adminPostsActions' => [BackendBehaviors::class, 'adminPostsActions'], 'adminPostsActions' => BackendBehaviors::adminPostsActions(...),
]); ]);
} }
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initShorten']); App::behavior()->addBehaviors([
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initRank']); 'initWidgets' => Widgets::init(...),
'exportFullV2' => ImportExportBehaviors::exportFullV2(...),
dcCore::app()->addBehaviors([ 'exportSingleV2' => ImportExportBehaviors::exportSingleV2(...),
'exportFullV2' => [ImportExportBehaviors::class, 'exportFullV2'], 'importInitV2' => ImportExportBehaviors::importInitV2(...),
'exportSingleV2' => [ImportExportBehaviors::class, 'exportSingleV2'], 'importSingleV2' => ImportExportBehaviors::importSingleV2(...),
'importInitV2' => [ImportExportBehaviors::class, 'importInitV2'], 'importFullV2' => ImportExportBehaviors::importFullV2(...),
'importSingleV2' => [ImportExportBehaviors::class, 'importSingleV2'],
'importFullV2' => [ImportExportBehaviors::class, 'importFullV2'],
]); ]);
return true; return true;

View File

@ -1,27 +1,20 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use ArrayObject; use ArrayObject;
use dcCore; use Dotclear\App;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Action\ActionsPosts, Action\ActionsPosts,
Favorites, Favorites,
Notices Notices
}; };
use Dotclear\Database\MetaRecord; use Dotclear\Database\{
Cursor,
MetaRecord
};
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -35,7 +28,13 @@ use Dotclear\Helper\Html\Form\{
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Exception; use Exception;
# Admin behaviors class /**
* @brief kUtRL backend behaviors.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class BackendBehaviors class BackendBehaviors
{ {
public static function antispamDashboardFavoritesV2(Favorites $favs): void public static function antispamDashboardFavoritesV2(Favorites $favs): void
@ -47,7 +46,7 @@ class BackendBehaviors
'url' => My::manageUrl(), 'url' => My::manageUrl(),
'small-icon' => My::icons(), 'small-icon' => My::icons(),
'large-icon' => My::icons(), 'large-icon' => My::icons(),
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), 'permissions' => App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]),
] ]
); );
} }
@ -182,7 +181,7 @@ class BackendBehaviors
return; return;
} }
$rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); $rs = App::blog()->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return; return;
} }
@ -205,7 +204,7 @@ class BackendBehaviors
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title); App::behavior()->callBehavior('adminAfterKutrlCreate', $rs, $title);
} }
} }
} }
@ -219,7 +218,7 @@ class BackendBehaviors
return; return;
} }
$rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); $rs = App::blog()->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return; return;
} }
@ -233,7 +232,7 @@ class BackendBehaviors
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, $title); App::behavior()->callBehavior('adminAfterKutrlCreate', $rs, $title);
} }
} }
@ -245,7 +244,7 @@ class BackendBehaviors
return; return;
} }
$rs = dcCore::app()->blog->getPosts(['post_id' => $post_id]); $rs = App::blog()->getPosts(['post_id' => $post_id]);
if ($rs->isEmpty()) { if ($rs->isEmpty()) {
return; return;
} }
@ -256,17 +255,17 @@ class BackendBehaviors
public static function adminPostsActions(ActionsPosts $pa): void public static function adminPostsActions(ActionsPosts $pa): void
{ {
if (!My::settings()->get('active') if (!My::settings()->get('active')
|| !dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id)) { || !App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]), App::blog()->id())) {
return; return;
} }
$pa->addAction( $pa->addAction(
[My::name() => [__('Create short link') => 'kutrl_create']], [My::name() => [__('Create short link') => 'kutrl_create']],
[self::class, 'callbackCreate'] self::callbackCreate(...)
); );
$pa->addAction( $pa->addAction(
[My::name() => [__('Delete short link') => 'kutrl_delete']], [My::name() => [__('Delete short link') => 'kutrl_delete']],
[self::class, 'callbackDelete'] self::callbackDelete(...)
); );
} }
@ -279,7 +278,7 @@ class BackendBehaviors
} }
# No right # No right
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id)) { if (!App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]), App::blog()->id())) {
throw new Exception(__('No enough right')); throw new Exception(__('No enough right'));
} }
@ -288,7 +287,7 @@ class BackendBehaviors
} }
# retrieve posts info and create hash # retrieve posts info and create hash
$posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); $posts = App::blog()->getPosts(['post_id' => $posts_ids]);
while ($posts->fetch()) { while ($posts->fetch()) {
$kut->hash($posts->getURL()); $kut->hash($posts->getURL());
} }
@ -306,7 +305,7 @@ class BackendBehaviors
} }
# No right # No right
if (!dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_ADMIN]), dcCore::app()->blog->id)) { if (!App::auth()->check(App::auth()->makePermissions([App::auth()::PERMISSION_ADMIN]), App::blog()->id())) {
throw new Exception(__('No enough right')); throw new Exception(__('No enough right'));
} }
@ -315,7 +314,7 @@ class BackendBehaviors
} }
# retrieve posts info and create hash # retrieve posts info and create hash
$posts = dcCore::app()->blog->getPosts(['post_id' => $posts_ids]); $posts = App::blog()->getPosts(['post_id' => $posts_ids]);
while ($posts->fetch()) { while ($posts->fetch()) {
$kut->remove($posts->getURL()); $kut->remove($posts->getURL());
} }

View File

@ -1,19 +1,16 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
/**
* @brief kUtRL combo.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Combo class Combo
{ {
/** /**

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Backend\Notices; use Dotclear\Core\Backend\Notices;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
@ -30,7 +20,11 @@ use Dotclear\Helper\Html\Form\{
use Exception; use Exception;
/** /**
* Backend module configuration. * @brief kUtRL config class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Config extends Process class Config extends Process
{ {
@ -92,18 +86,18 @@ class Config extends Process
$o->saveSettings(); $o->saveSettings();
} }
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
Notices::addSuccessNotice( Notices::addSuccessNotice(
__('Configuration successfully updated.') __('Configuration successfully updated.')
); );
dcCore::app()->admin->url->redirect( App::backend()->url()->redirect(
'admin.plugins', 'admin.plugins',
['module' => My::id(), 'conf' => 1, 'chk' => 1, 'redir' => dcCore::app()->admin->list->getRedir()] ['module' => My::id(), 'conf' => 1, 'chk' => 1, 'redir' => App::backend()->__get('list')->getRedir()]
); );
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }
@ -166,7 +160,7 @@ class Config extends Process
$img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name); $img_chk = $img_green . ' ' . sprintf(__('%s API is well configured and runing.'), $o->name);
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage())); App::error()->add(sprintf(__('Failed to test service %s: %s'), $o->name, $e->getMessage()));
} }
$s_items[] = (new Text(null, sprintf('<p><em>%s</em></p>', $img_chk) . $o->error->toHTML())); $s_items[] = (new Text(null, sprintf('<p><em>%s</em></p>', $img_chk) . $o->error->toHTML()));
} }

View File

@ -1,25 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* Frontend prepend. * @brief kUtRL frontend class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Frontend extends Process class Frontend extends Process
{ {
@ -34,41 +27,40 @@ class Frontend extends Process
return false; return false;
} }
dcCore::app()->tpl->setPath( App::frontend()->template()->setPath(
dcCore::app()->tpl->getPath(), App::frontend()->template()->getPath(),
My::path() . DIRECTORY_SEPARATOR . 'default-templates' My::path() . DIRECTORY_SEPARATOR . 'default-templates'
); );
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initShorten']);
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initRank']);
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'publicBeforeDocumentV2' => [FrontendBehaviors::class, 'publicBeforeDocumentV2'], 'initWidgets' => Widgets::init(...),
'publicHeadContent' => [FrontendBehaviors::class, 'publicHeadContent'], 'publicBeforeDocumentV2' => FrontendBehaviors::publicBeforeDocumentV2(...),
'publicBeforeContentFilterV2' => [FrontendBehaviors::class, 'publicBeforeContentFilterV2'], 'publicHeadContent' => FrontendBehaviors::publicHeadContent(...),
'templateBeforeValueV2' => [FrontendBehaviors::class, 'templateBeforeValueV2'], 'publicBeforeContentFilterV2' => FrontendBehaviors::publicBeforeContentFilterV2(...),
'templateAfterValueV2' => [FrontendBehaviors::class, 'templateAfterValueV2'], 'templateBeforeValueV2' => FrontendBehaviors::templateBeforeValueV2(...),
'templateAfterValueV2' => FrontendBehaviors::templateAfterValueV2(...),
]); ]);
dcCore::app()->tpl->addBlock('kutrlPageIf', [FrontendTemplate::class, 'pageIf']); App::frontend()->template()->addBlock('kutrlPageIf', FrontendTemplate::pageIf(...));
dcCore::app()->tpl->addBlock('kutrlMsgIf', [FrontendTemplate::class, 'pageMsgIf']); App::frontend()->template()->addBlock('kutrlMsgIf', FrontendTemplate::pageMsgIf(...));
dcCore::app()->tpl->addValue('kutrlPageURL', [FrontendTemplate::class, 'pageURL']); App::frontend()->template()->addValue('kutrlPageURL', FrontendTemplate::pageURL(...));
dcCore::app()->tpl->addValue('kutrlMsg', [FrontendTemplate::class, 'pageMsg']); App::frontend()->template()->addValue('kutrlMsg', FrontendTemplate::pageMsg(...));
dcCore::app()->tpl->addValue('kutrlHumanField', [FrontendTemplate::class, 'humanField']); App::frontend()->template()->addValue('kutrlHumanField', FrontendTemplate::humanField(...));
dcCore::app()->tpl->addValue('kutrlHumanFieldProtect', [FrontendTemplate::class, 'humanFieldProtect']); App::frontend()->template()->addValue('kutrlHumanFieldProtect', FrontendTemplate::humanFieldProtect(...));
dcCore::app()->tpl->addBlock('AttachmentKutrlIf', [FrontendTemplate::class, 'AttachmentKutrlIf']); App::frontend()->template()->addBlock('AttachmentKutrlIf', FrontendTemplate::AttachmentKutrlIf(...));
dcCore::app()->tpl->addValue('AttachmentKutrl', [FrontendTemplate::class, 'AttachmentKutrl']); App::frontend()->template()->addValue('AttachmentKutrl', FrontendTemplate::AttachmentKutrl(...));
dcCore::app()->tpl->addBlock('MediaKutrlIf', [FrontendTemplate::class, 'MediaKutrlIf']); App::frontend()->template()->addBlock('MediaKutrlIf', FrontendTemplate::MediaKutrlIf(...));
dcCore::app()->tpl->addValue('MediaKutrl', [FrontendTemplate::class, 'MediaKutrl']); App::frontend()->template()->addValue('MediaKutrl', FrontendTemplate::MediaKutrl(...));
dcCore::app()->tpl->addBlock('EntryAuthorKutrlIf', [FrontendTemplate::class, 'EntryAuthorKutrlIf']); App::frontend()->template()->addBlock('EntryAuthorKutrlIf', FrontendTemplate::EntryAuthorKutrlIf(...));
dcCore::app()->tpl->addValue('EntryAuthorKutrl', [FrontendTemplate::class, 'EntryAuthorKutrl']); App::frontend()->template()->addValue('EntryAuthorKutrl', FrontendTemplate::EntryAuthorKutrl(...));
dcCore::app()->tpl->addBlock('EntryKutrlIf', [FrontendTemplate::class, 'EntryKutrlIf']); App::frontend()->template()->addBlock('EntryKutrlIf', FrontendTemplate::EntryKutrlIf(...));
dcCore::app()->tpl->addValue('EntryKutrl', [FrontendTemplate::class, 'EntryKutrl']); App::frontend()->template()->addValue('EntryKutrl', FrontendTemplate::EntryKutrl(...));
dcCore::app()->tpl->addBlock('CommentAuthorKutrlIf', [FrontendTemplate::class, 'CommentAuthorKutrlIf']); App::frontend()->template()->addBlock('CommentAuthorKutrlIf', FrontendTemplate::CommentAuthorKutrlIf(...));
dcCore::app()->tpl->addValue('CommentAuthorKutrl', [FrontendTemplate::class, 'CommentAuthorKutrl']); App::frontend()->template()->addValue('CommentAuthorKutrl', FrontendTemplate::CommentAuthorKutrl(...));
dcCore::app()->tpl->addBlock('CommentPostKutrlIf', [FrontendTemplate::class, 'CommentPostKutrlIf']); App::frontend()->template()->addBlock('CommentPostKutrlIf', FrontendTemplate::CommentPostKutrlIf(...));
dcCore::app()->tpl->addValue('CommentPostKutrl', [FrontendTemplate::class, 'CommentPostKutrl']); App::frontend()->template()->addValue('CommentPostKutrl', FrontendTemplate::CommentPostKutrl(...));
return true; return true;
} }

View File

@ -1,30 +1,27 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use ArrayObject; use ArrayObject;
use dcCore; use Dotclear\App;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/**
* @brief kUtRL frontend behaviors.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class FrontendBehaviors class FrontendBehaviors
{ {
# Disable URL shoretning on filtered tag # Disable URL shoretning on filtered tag
public static function templateBeforeValueV2(string $tag, ArrayObject $attr): ?string public static function templateBeforeValueV2(string $tag, ArrayObject $attr): ?string
{ {
if (!empty($attr['disable_kutrl']) && in_array($tag, My::USED_TAGS)) { if (!empty($attr['disable_kutrl']) && in_array($tag, My::USED_TAGS)) {
return '<?php dcCore::app()->ctx->__set("disable_kutrl", true); ?>'; return '<?php App::frontend()->context()->__set("disable_kutrl", true); ?>';
} }
return null; return null;
@ -34,7 +31,7 @@ class FrontendBehaviors
public static function templateAfterValueV2(string $tag, ArrayObject $attr): ?string public static function templateAfterValueV2(string $tag, ArrayObject $attr): ?string
{ {
if (!empty($attr['disable_kutrl']) && in_array($tag, My::USED_TAGS)) { if (!empty($attr['disable_kutrl']) && in_array($tag, My::USED_TAGS)) {
return '<?php dcCore::app()->ctx->__set("disable_kutrl", false); ?>'; return '<?php App::frontend()->context()->__set("disable_kutrl", false); ?>';
} }
return null; return null;
@ -48,24 +45,24 @@ class FrontendBehaviors
return null; return null;
} }
# URL shortening is disabled by tag attribute # URL shortening is disabled by tag attribute
if (true !== dcCore::app()->ctx->__get('disable_kutrl')) { if (true !== App::frontend()->context()->__get('disable_kutrl')) {
# plugin is not activated # plugin is not activated
if (!My::settings()->get('active') if (!My::settings()->get('active')
|| !My::settings()->get('tpl_active') || !My::settings()->get('tpl_active')
|| !dcCore::app()->ctx->exists('kutrl') || !App::frontend()->context()->exists('kutrl')
) { ) {
return null; return null;
} }
# Existing # Existing
if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl($args[0]))) { if (false !== ($kutrl_rs = App::frontend()->context()->kutrl->isKnowUrl($args[0]))) {
$args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash; $args[0] = App::frontend()->context()->kutrl->url_base . $kutrl_rs->hash;
# New # New
} elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash($args[0]))) { } elseif (false !== ($kutrl_rs = App::frontend()->context()->kutrl->hash($args[0]))) {
$args[0] = dcCore::app()->ctx->kutrl->url_base . $kutrl_rs->hash; $args[0] = App::frontend()->context()->kutrl->url_base . $kutrl_rs->hash;
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($kutrl_rs)) { if (!empty($kutrl_rs)) {
dcCore::app()->callBehavior('publicAfterKutrlCreate', $kutrl_rs, __('New public short URL')); App::behavior()->callBehavior('publicAfterKutrlCreate', $kutrl_rs, __('New public short URL'));
} }
} }
} }
@ -76,7 +73,7 @@ class FrontendBehaviors
$s = My::settings(); $s = My::settings();
# Passive : all kutrl tag return long url # Passive : all kutrl tag return long url
dcCore::app()->ctx->kutrl_passive = (bool) $s->get('tpl_passive'); App::frontend()->context()->kutrl_passive = (bool) $s->get('tpl_passive');
if (!$s->get('active') if (!$s->get('active')
|| !$s->get('tpl_service') || !$s->get('tpl_service')
@ -85,7 +82,7 @@ class FrontendBehaviors
return; return;
} }
dcCore::app()->ctx->kutrl = $kut; App::frontend()->context()->kutrl = $kut;
} }
public static function publicHeadContent($_): void public static function publicHeadContent($_): void

View File

@ -1,39 +1,35 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use ArrayObject; use ArrayObject;
use dcCore; use Dotclear\App;
use dcTemplate;
/**
* @brief kUtRL frontend template.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class FrontendTemplate class FrontendTemplate
{ {
public static function pageURL(ArrayObject$attr): string public static function pageURL(ArrayObject$attr): string
{ {
$f = dcCore::app()->tpl->getFilters($attr); $f = App::frontend()->template()->getFilters($attr);
return '<?php echo ' . sprintf($f, 'dcCore::app()->blog->url.dcCore::app()->url->getBase("kutrl")') . '; ?>'; return '<?php echo ' . sprintf($f, 'App::blog()->url().App::url()->getBase("kutrl")') . '; ?>';
} }
public static function pageIf(ArrayObject $attr, string $content): string public static function pageIf(ArrayObject $attr, string $content): string
{ {
$operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? App::frontend()->template()->getOperator($attr['operator']) : '&&';
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (bool) $attr['is_active'] ? '' : '!'; $sign = (bool) $attr['is_active'] ? '' : '!';
$if[] = $sign . 'dcCore::app()->blog->settings->get("' . My::id() . '")->get("srv_local_public")'; $if[] = $sign . 'App::blog()->settings()->get("' . My::id() . '")->get("srv_local_public")';
} }
if (empty($if)) { if (empty($if)) {
return $content; return $content;
@ -47,11 +43,11 @@ class FrontendTemplate
public static function pageMsgIf(ArrayObject$attr, string $content): string public static function pageMsgIf(ArrayObject$attr, string $content): string
{ {
$operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? App::frontend()->template()->getOperator($attr['operator']) : '&&';
if (isset($attr['has_message'])) { if (isset($attr['has_message'])) {
$sign = (bool) $attr['has_message'] ? '!' : '='; $sign = (bool) $attr['has_message'] ? '!' : '=';
$if[] = '"" ' . $sign . '= dcCore::app()->ctx->kutrl_msg'; $if[] = '"" ' . $sign . '= App::frontend()->context()->kutrl_msg';
} }
if (empty($if)) { if (empty($if)) {
return $content; return $content;
@ -65,19 +61,19 @@ class FrontendTemplate
public static function pageMsg(ArrayObject$attr): string public static function pageMsg(ArrayObject$attr): string
{ {
return '<?php echo dcCore::app()->ctx->kutrl_msg; ?>'; return '<?php echo App::frontend()->context()->kutrl_msg; ?>';
} }
public static function humanField(ArrayObject $attr): string public static function humanField(ArrayObject $attr): string
{ {
return "<?php echo sprintf(__('Confirm by writing \"%s\" in next field:'),dcCore::app()->ctx->kutrl_hmf); ?>"; return "<?php echo sprintf(__('Confirm by writing \"%s\" in next field:'),App::frontend()->context()->kutrl_hmf); ?>";
} }
public static function humanFieldProtect(ArrayObject $attr): string public static function humanFieldProtect(ArrayObject $attr): string
{ {
return return
'<input type="hidden" name="hmfp" id="hmfp" value="<?php echo dcCore::app()->ctx->kutrl_hmfp; ?>" />' . '<input type="hidden" name="hmfp" id="hmfp" value="<?php echo App::frontend()->context()->kutrl_hmfp; ?>" />' .
'<?php echo dcCore::app()->formNonce(); ?>'; '<?php echo App::nonce()->getFormNonce(); ?>';
} }
public static function AttachmentKutrlIf(ArrayObject$attr, string $content): string public static function AttachmentKutrlIf(ArrayObject$attr, string $content): string
@ -92,69 +88,69 @@ class FrontendTemplate
public static function MediaKutrlIf(ArrayObject$attr, string $content): string public static function MediaKutrlIf(ArrayObject$attr, string $content): string
{ {
return self::genericKutrlIf('dcCore::app()->ctx->file_url', $attr, $content); return self::genericKutrlIf('App::frontend()->context()->file_url', $attr, $content);
} }
public static function MediaKutrl(ArrayObject $attr): string public static function MediaKutrl(ArrayObject $attr): string
{ {
return self::genericKutrl('dcCore::app()->ctx->file_url', $attr); return self::genericKutrl('App::frontend()->context()->file_url', $attr);
} }
public static function EntryAuthorKutrlIf(ArrayObject$attr, string $content): string public static function EntryAuthorKutrlIf(ArrayObject$attr, string $content): string
{ {
return self::genericKutrlIf('dcCore::app()->ctx->posts->user_url', $attr, $content); return self::genericKutrlIf('App::frontend()->context()->posts->user_url', $attr, $content);
} }
public static function EntryAuthorKutrl(ArrayObject $attr): string public static function EntryAuthorKutrl(ArrayObject $attr): string
{ {
return self::genericKutrl('dcCore::app()->ctx->posts->user_url', $attr); return self::genericKutrl('App::frontend()->context()->posts->user_url', $attr);
} }
public static function EntryKutrlIf(ArrayObject $attr, string $content): string public static function EntryKutrlIf(ArrayObject $attr, string $content): string
{ {
return self::genericKutrlIf('dcCore::app()->ctx->posts->getURL()', $attr, $content); return self::genericKutrlIf('App::frontend()->context()->posts->getURL()', $attr, $content);
} }
public static function EntryKutrl(ArrayObject $attr): string public static function EntryKutrl(ArrayObject $attr): string
{ {
return self::genericKutrl('dcCore::app()->ctx->posts->getURL()', $attr); return self::genericKutrl('App::frontend()->context()->posts->getURL()', $attr);
} }
public static function CommentAuthorKutrlIf(ArrayObject $attr, string $content): string public static function CommentAuthorKutrlIf(ArrayObject $attr, string $content): string
{ {
return self::genericKutrlIf('dcCore::app()->ctx->comments->getAuthorURL()', $attr, $content); return self::genericKutrlIf('App::frontend()->context()->comments->getAuthorURL()', $attr, $content);
} }
public static function CommentAuthorKutrl(ArrayObject $attr): string public static function CommentAuthorKutrl(ArrayObject $attr): string
{ {
return self::genericKutrl('dcCore::app()->ctx->comments->getAuthorURL()', $attr); return self::genericKutrl('App::frontend()->context()->comments->getAuthorURL()', $attr);
} }
public static function CommentPostKutrlIf(ArrayObject $attr, string $content): string public static function CommentPostKutrlIf(ArrayObject $attr, string $content): string
{ {
return self::genericKutrlIf('dcCore::app()->ctx->comments->getPostURL()', $attr, $content); return self::genericKutrlIf('App::frontend()->context()->comments->getPostURL()', $attr, $content);
} }
public static function CommentPostKutrl(ArrayObject $attr): string public static function CommentPostKutrl(ArrayObject $attr): string
{ {
return self::genericKutrl('dcCore::app()->ctx->comments->getPostURL()', $attr); return self::genericKutrl('App::frontend()->context()->comments->getPostURL()', $attr);
} }
protected static function genericKutrlIf(string $str, ArrayObject $attr, string $content): string protected static function genericKutrlIf(string $str, ArrayObject $attr, string $content): string
{ {
$operator = isset($attr['operator']) ? dcTemplate::getOperator($attr['operator']) : '&&'; $operator = isset($attr['operator']) ? App::fontend()->template()->getOperator($attr['operator']) : '&&';
if (isset($attr['is_active'])) { if (isset($attr['is_active'])) {
$sign = (bool) $attr['is_active'] ? '' : '!'; $sign = (bool) $attr['is_active'] ? '' : '!';
$if[] = $sign . 'dcCore::app()->ctx->exists("kutrl")'; $if[] = $sign . 'App::frontend()->context()->exists("kutrl")';
} }
if (isset($attr['passive_mode'])) { if (isset($attr['passive_mode'])) {
$sign = (bool) $attr['passive_mode'] ? '' : '!'; $sign = (bool) $attr['passive_mode'] ? '' : '!';
$if[] = $sign . 'dcCore::app()->ctx->kutrl_passive'; $if[] = $sign . 'App::frontend()->context()->kutrl_passive';
} }
if (isset($attr['has_kutrl'])) { if (isset($attr['has_kutrl'])) {
$sign = (bool) $attr['has_kutrl'] ? '!' : '='; $sign = (bool) $attr['has_kutrl'] ? '!' : '=';
$if[] = '(dcCore::app()->ctx->exists("kutrl") && false ' . $sign . '== dcCore::app()->ctx->kutrl->select(' . $str . ',null,null,"kutrl"))'; $if[] = '(App::frontend()->context()->exists("kutrl") && false ' . $sign . '== App::frontend()->context()->kutrl->select(' . $str . ',null,null,"kutrl"))';
} }
if (empty($if)) { if (empty($if)) {
return $content; return $content;
@ -168,32 +164,32 @@ class FrontendTemplate
protected static function genericKutrl(string $str, ArrayObject $attr): string protected static function genericKutrl(string $str, ArrayObject $attr): string
{ {
$f = dcCore::app()->tpl->getFilters($attr); $f = App::frontend()->template()->getFilters($attr);
return return
"<?php \n" . "<?php \n" .
# Preview # Preview
"if (dcCore::app()->ctx->preview) { \n" . "if (App::frontend()->context()->preview) { \n" .
' echo ' . sprintf($f, $str) . '; ' . ' echo ' . sprintf($f, $str) . '; ' .
"} else { \n" . "} else { \n" .
# Disable # Disable
"if (!dcCore::app()->ctx->exists('kutrl')) { \n" . "if (!App::frontend()->context()->exists('kutrl')) { \n" .
# Passive mode # Passive mode
' if (dcCore::app()->ctx->kutrl_passive) { ' . ' if (App::frontend()->context()->kutrl_passive) { ' .
' echo ' . sprintf($f, $str) . '; ' . ' echo ' . sprintf($f, $str) . '; ' .
" } \n" . " } \n" .
"} else { \n" . "} else { \n" .
# Existing # Existing
' if (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->isKnowUrl(' . $str . '))) { ' . ' if (false !== ($kutrl_rs = App::frontend()->context()->kutrl->isKnowUrl(' . $str . '))) { ' .
' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . ' echo ' . sprintf($f, 'App::frontend()->context()->kutrl->url_base.$kutrl_rs->hash') . '; ' .
" } \n" . " } \n" .
# New # New
' elseif (false !== ($kutrl_rs = dcCore::app()->ctx->kutrl->hash(' . $str . '))) { ' . ' elseif (false !== ($kutrl_rs = App::frontend()->context()->kutrl->hash(' . $str . '))) { ' .
' echo ' . sprintf($f, 'dcCore::app()->ctx->kutrl->url_base.$kutrl_rs->hash') . '; ' . ' echo ' . sprintf($f, 'App::frontend()->context()->kutrl->url_base.$kutrl_rs->hash') . '; ' .
# ex: Send new url to messengers # ex: Send new url to messengers
' if (!empty($kutrl_rs)) { ' . ' if (!empty($kutrl_rs)) { ' .
" dcCore::app()->callBehavior('publicAfterKutrlCreate',\$kutrl_rs,__('New public short URL')); " . " App::behavior()->callBehavior('publicAfterKutrlCreate',\$kutrl_rs,__('New public short URL')); " .
" } \n" . " } \n" .
" } \n" . " } \n" .

View File

@ -1,25 +1,22 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use dcUrlHandlers; use Dotclear\Core\Frontend\Url;
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Helper\Network\Http; use Dotclear\Helper\Network\Http;
class FrontendUrl extends dcUrlHandlers /**
* @brief kUtRL frontend URL handler.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class FrontendUrl extends Url
{ {
# Redirect !!! local !!! service only # Redirect !!! local !!! service only
public static function redirectUrl(?string $args): void public static function redirectUrl(?string $args): void
@ -37,16 +34,16 @@ class FrontendUrl extends dcUrlHandlers
return; return;
} }
$args = $m[3] ?? ''; $args = $m[3] ?? '';
dcCore::app()->ctx->kutrl_msg = ''; App::frontend()->context()->kutrl_msg = '';
dcCore::app()->ctx->kutrl_hmf = FrontendUtils::create(); App::frontend()->context()->kutrl_hmf = FrontendUtils::create();
dcCore::app()->ctx->kutrl_hmfp = FrontendUtils::protect(dcCore::app()->ctx->kutrl_hmf); App::frontend()->context()->kutrl_hmfp = FrontendUtils::protect(App::frontend()->context()->kutrl_hmf);
$kut = new Service\ServiceLocal(); $kut = new Service\ServiceLocal();
# Nothing on url # Nothing on url
if ($m[1] == '/') { if ($m[1] == '/') {
dcCore::app()->ctx->kutrl_msg = 'No link given.'; App::frontend()->context()->kutrl_msg = 'No link given.';
} }
# find suffix on redirect url # find suffix on redirect url
$suffix = ''; $suffix = '';
@ -62,7 +59,7 @@ class FrontendUrl extends dcUrlHandlers
} }
# Not find, go to kutrl 404 # Not find, go to kutrl 404
if (false === ($url = $kut->getUrl($args))) { if (false === ($url = $kut->getUrl($args))) {
//dcCore::app()->ctx->kutrl_msg = 'Failed to find short link.'; //App::frontend()->context()->kutrl_msg = 'Failed to find short link.';
//self::pageKutrl($kut); //self::pageKutrl($kut);
self::kutrl404(); self::kutrl404();
@ -75,7 +72,7 @@ class FrontendUrl extends dcUrlHandlers
return; return;
} }
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
Http::redirect($url . $suffix); Http::redirect($url . $suffix);
} }
@ -96,7 +93,7 @@ class FrontendUrl extends dcUrlHandlers
return; return;
} }
# Validation form # Validation form
$url = !empty($_POST['longurl']) ? trim(dcCore::app()->con->escapeStr((string) $_POST['longurl'])) : ''; $url = !empty($_POST['longurl']) ? trim(App::con()->escapeStr((string) $_POST['longurl'])) : '';
if (!empty($url)) { if (!empty($url)) {
$hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!'; $hmf = !empty($_POST['hmf']) ? $_POST['hmf'] : '!';
$hmfu = !empty($_POST['hmfp']) ? FrontendUtils::unprotect($_POST['hmfp']) : '?'; $hmfu = !empty($_POST['hmfp']) ? FrontendUtils::unprotect($_POST['hmfp']) : '?';
@ -104,45 +101,45 @@ class FrontendUrl extends dcUrlHandlers
$err = false; $err = false;
if (!$err) { if (!$err) {
if ($hmf != $hmfu) { if ($hmf != $hmfu) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('Failed to verify protected field.'); App::frontend()->context()->kutrl_msg = __('Failed to verify protected field.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->testService()) { if (!$kut->testService()) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('Service is not well configured.'); App::frontend()->context()->kutrl_msg = __('Service is not well configured.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isValidUrl($url)) { if (!$kut->isValidUrl($url)) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('This string is not a valid URL.'); App::frontend()->context()->kutrl_msg = __('This string is not a valid URL.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isLongerUrl($url)) { if (!$kut->isLongerUrl($url)) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('This link is too short.'); App::frontend()->context()->kutrl_msg = __('This link is too short.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->isProtocolUrl($url)) { if (!$kut->isProtocolUrl($url)) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('This type of link is not allowed.'); App::frontend()->context()->kutrl_msg = __('This type of link is not allowed.');
} }
} }
if (!$err) { if (!$err) {
if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) { if (!$kut->allow_external_url && !$kut->isBlogUrl($url)) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('Short links are limited to this blog URL.'); App::frontend()->context()->kutrl_msg = __('Short links are limited to this blog URL.');
} }
} }
if (!$err) { if (!$err) {
if ($kut->isServiceUrl($url)) { if ($kut->isServiceUrl($url)) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('This link is already a short link.'); App::frontend()->context()->kutrl_msg = __('This link is already a short link.');
} }
} }
if (!$err) { if (!$err) {
@ -152,7 +149,7 @@ class FrontendUrl extends dcUrlHandlers
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
dcCore::app()->ctx->kutrl_msg = sprintf( App::frontend()->context()->kutrl_msg = sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
Html::escapeHTML($url), Html::escapeHTML($url),
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
@ -161,28 +158,28 @@ class FrontendUrl extends dcUrlHandlers
} }
if (!$err) { if (!$err) {
if (false === ($rs = $kut->hash($url))) { if (false === ($rs = $kut->hash($url))) {
$err = true; $err = true;
dcCore::app()->ctx->kutrl_msg = __('Failed to create short link.'); App::frontend()->context()->kutrl_msg = __('Failed to create short link.');
} else { } else {
$url = $rs->url; $url = $rs->url;
$new_url = $kut->url_base . $rs->hash; $new_url = $kut->url_base . $rs->hash;
dcCore::app()->ctx->kutrl_msg = sprintf( App::frontend()->context()->kutrl_msg = sprintf(
__('Short link for %s is %s'), __('Short link for %s is %s'),
Html::escapeHTML($url), Html::escapeHTML($url),
'<a href="' . $new_url . '">' . $new_url . '</a>' '<a href="' . $new_url . '">' . $new_url . '</a>'
); );
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
dcCore::app()->callBehavior('publicAfterKutrlCreate', $rs, __('New public short URL')); App::behavior()->callBehavior('publicAfterKutrlCreate', $rs, __('New public short URL'));
} }
} }
} }
} }
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::path() . '/default-templates'); App::frontend()->template()->setPath(App::frontend()->template()->getPath(), My::path() . '/default-templates');
self::serveDocument('kutrl.html'); self::serveDocument('kutrl.html');
} }
@ -194,18 +191,18 @@ class FrontendUrl extends dcUrlHandlers
return; return;
} }
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::path() . '/default-templates'); App::frontend()->template()->setPath(App::frontend()->template()->getPath(), My::path() . '/default-templates');
header('Content-Type: text/html; charset=UTF-8'); header('Content-Type: text/html; charset=UTF-8');
Http::head(404, 'Not Found'); Http::head(404, 'Not Found');
dcCore::app()->url->type = '404'; App::url()->type = '404';
dcCore::app()->ctx->current_tpl = 'kutrl404.html'; App::frontend()->context()->current_tpl = 'kutrl404.html';
dcCore::app()->ctx->content_type = 'text/html'; App::frontend()->context()->content_type = 'text/html';
echo dcCore::app()->tpl->getData(dcCore::app()->ctx->current_tpl); echo App::frontend()->template()->getData(App::frontend()->context()->current_tpl);
# --BEHAVIOR-- publicAfterDocumentV2 # --BEHAVIOR-- publicAfterDocumentV2
dcCore::app()->callBehavior('publicAfterDocumentV2'); App::behavior()->callBehavior('publicAfterDocumentV2');
exit; exit;
} }
} }

View File

@ -1,19 +1,16 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
/**
* @brief kUtRL frontend utils.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class FrontendUtils class FrontendUtils
{ {
public static $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'; public static $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';

View File

@ -1,22 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
# Import/export behaviors for Import/export plugin /**
* @brief kUtRL importExport stuff.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ImportExportBehaviors class ImportExportBehaviors
{ {
public static function exportSingleV2($exp, $blog_id) public static function exportSingleV2($exp, $blog_id)
@ -25,7 +21,7 @@ class ImportExportBehaviors
My::TABLE_NAME, My::TABLE_NAME,
'SELECT kut_id, blog_id, kut_service, kut_type, ' . 'SELECT kut_id, blog_id, kut_service, kut_type, ' .
'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' . 'kut_hash, kut_url, kut_dt, kut_password, kut_counter ' .
'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ' . 'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' .
"WHERE blog_id = '" . $blog_id . "' " "WHERE blog_id = '" . $blog_id . "' "
); );
} }
@ -37,7 +33,7 @@ class ImportExportBehaviors
public static function importInitV2($bk) public static function importInitV2($bk)
{ {
$bk->cur_kutrl = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); $bk->cur_kutrl = App::con()->openCursor(App::con()->prefix() . My::TABLE_NAME);
$bk->kutrl = new Logs(); $bk->kutrl = new Logs();
} }

View File

@ -1,27 +1,20 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use dcNamespace;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Database\Structure; use Dotclear\Database\Structure;
use Exception; use Exception;
/** /**
* Module installation. * @brief kUtRL install class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Install extends Process class Install extends Process
{ {
@ -38,7 +31,7 @@ class Install extends Process
try { try {
// Table // Table
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix); $t = new Structure(App::con(), App::con()->prefix());
$t->{My::TABLE_NAME} $t->{My::TABLE_NAME}
->kut_id('bigint', 0, false) ->kut_id('bigint', 0, false)
->blog_id('varchar', 32, false) ->blog_id('varchar', 32, false)
@ -56,18 +49,18 @@ class Install extends Process
->index('idx_kut_service', 'btree', 'kut_service') ->index('idx_kut_service', 'btree', 'kut_service')
->index('idx_kut_type', 'btree', 'kut_type'); ->index('idx_kut_type', 'btree', 'kut_type');
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($t); (new Structure(App::con(), App::con()->prefix()))->synchronize($t);
// upgrade version < 2022.12.22 : upgrade settings id and ns and array // upgrade version < 2022.12.22 : upgrade settings id and ns and array
$current = dcCore::app()->getVersion(My::id()); $current = App::version()->getVersion(My::id());
if ($current && version_compare($current, '2022.12.22', '<')) { if ($current && version_compare($current, '2022.12.22', '<')) {
$record = dcCore::app()->con->select( $record = App::con()->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' . 'SELECT * FROM ' . App::con()->prefix() . App::blogWorkspace()::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'kUtRL' " "WHERE setting_ns = 'kUtRL' "
); );
while ($record->fetch()) { while ($record->fetch()) {
if (preg_match('/^kutrl_(.*?)$/', $record->setting_id, $match)) { if (preg_match('/^kutrl_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME); $cur = App::blogWorkspace()->openBlogWorkspace();
// avoid the use of serialize function // avoid the use of serialize function
if (in_array($record->setting_id, ['kutrl_srv_custom'])) { if (in_array($record->setting_id, ['kutrl_srv_custom'])) {
$cur->setting_value = json_encode(@unserialize(base64_decode((string) $record->setting_value))); $cur->setting_value = json_encode(@unserialize(base64_decode((string) $record->setting_value)));
@ -76,7 +69,7 @@ class Install extends Process
$cur->setting_ns = basename(__DIR__); $cur->setting_ns = basename(__DIR__);
$cur->update( $cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'kUtRL' " . "WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'kUtRL' " .
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escapeStr((string) $record->blog_id) . "' ")) 'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . App::con()->escapeStr((string) $record->blog_id) . "' "))
); );
} }
} }
@ -110,7 +103,7 @@ class Install extends Process
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
return false; return false;
} }

View File

@ -1,21 +1,11 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use ArrayObject; use ArrayObject;
use dcCore; use Dotclear\App;
use Dotclear\Core\Backend\Filter\Filters; use Dotclear\Core\Backend\Filter\Filters;
use Dotclear\Core\Backend\Listing\{ use Dotclear\Core\Backend\Listing\{
Listing, Listing,
@ -32,6 +22,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/**
* @brief kUtRL links listing.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class LinksListing extends Listing class LinksListing extends Listing
{ {
public function display(Filters $filter, string $enclose_block): void public function display(Filters $filter, string $enclose_block): void
@ -134,7 +131,7 @@ class LinksListing extends Listing
]), ]),
'kut_hash' => (new Text('td', $hash)) 'kut_hash' => (new Text('td', $hash))
->class('nowrap'), ->class('nowrap'),
'kut_dt' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, dcCore::app()->auth->getInfo('user_tz'))))) 'kut_dt' => (new Text('td', Html::escapeHTML(Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->kut_dt, App::auth()->getInfo('user_tz')))))
->class('nowrap'), ->class('nowrap'),
'kut_service' => (new Text('td', $type)) 'kut_service' => (new Text('td', $type))
->class('nowrap'), ->class('nowrap'),

View File

@ -1,22 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* This file contents class to acces local short links records
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Database\Statement\{ use Dotclear\Database\Statement\{
DeleteStatement, DeleteStatement,
@ -25,6 +13,13 @@ use Dotclear\Database\Statement\{
UpdateStatement UpdateStatement
}; };
/**
* @brief kUtRL logs class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Logs class Logs
{ {
public $table; public $table;
@ -32,8 +27,8 @@ class Logs
public function __construct() public function __construct()
{ {
$this->table = dcCore::app()->prefix . My::TABLE_NAME; $this->table = App::con()->prefix() . My::TABLE_NAME;
$this->con = dcCore::app()->con; $this->con = App::con();
} }
public function nextId(): int public function nextId(): int
@ -57,7 +52,7 @@ class Logs
try { try {
$cur->kut_id = $this->nextId(); $cur->kut_id = $this->nextId();
$cur->blog_id = dcCore::app()->blog->id; $cur->blog_id = App::blog()->id();
$cur->kut_url = (string) $url; $cur->kut_url = (string) $url;
$cur->kut_hash = (string) $hash; $cur->kut_hash = (string) $hash;
$cur->kut_type = (string) $type; $cur->kut_type = (string) $type;
@ -101,7 +96,7 @@ class Logs
$sql->as('kut_counter', 'counter'), $sql->as('kut_counter', 'counter'),
]) ])
->from($this->table) ->from($this->table)
->where('blog_id = ' . $sql->quote(dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('kut_service = ' . $sql->quote($service)) ->and('kut_service = ' . $sql->quote($service))
; ;
@ -135,7 +130,7 @@ class Logs
$cur->kut_counter = 0; $cur->kut_counter = 0;
$cur->update( $cur->update(
"WHERE blog_id='" . $this->con->escapeStr(dcCore::app()->blog->id) . "' " . "WHERE blog_id='" . $this->con->escapeStr(App::blog()->id()) . "' " .
"AND kut_id='" . $id . "' " "AND kut_id='" . $id . "' "
); );
$this->con->unlock(); $this->con->unlock();
@ -155,7 +150,7 @@ class Logs
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql $sql
->from($this->table) ->from($this->table)
->where('blog_id = ' . $sql->quote(dcCore::app()->blog->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('kut_id = ' . $id) ->and('kut_id = ' . $id)
->delete(); ->delete();
@ -168,7 +163,7 @@ class Logs
$rs = $sql $rs = $sql
->column('kut_counter') ->column('kut_counter')
->from($this->table) ->from($this->table)
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('kut_id = ' . $id) ->and('kut_id = ' . $id)
->select(); ->select();
@ -188,7 +183,7 @@ class Logs
$ret = $sql->ref($this->table) $ret = $sql->ref($this->table)
->column('kut_counter') ->column('kut_counter')
->value($counter) ->value($counter)
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)) ->where('blog_id = ' . $sql->quote(App::blog()->id()))
->and('kut_id = ' . $id) ->and('kut_id = ' . $id)
->update(); ->update();
@ -221,7 +216,7 @@ class Logs
$sql->from($params['from']); $sql->from($params['from']);
} }
$sql->where('S.blog_id = ' . $sql->quote(dcCore::app()->blog->id)); $sql->where('S.blog_id = ' . $sql->quote(App::blog()->id()));
if (isset($params['kut_service'])) { if (isset($params['kut_service'])) {
$sql->and('kut_service = ' . $sql->quote($params['kut_service'])); $sql->and('kut_service = ' . $sql->quote($params['kut_service']));

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Backend\{ use Dotclear\Core\Backend\{
Notices, Notices,
Page Page
@ -32,6 +22,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
/**
* @brief kUtRL manage class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Manage extends Process class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
@ -59,7 +56,7 @@ class Manage extends Process
if (null === $kut) { if (null === $kut) {
throw new Exception('Unknow service'); throw new Exception('Unknow service');
} }
$url = trim(dcCore::app()->con->escapeStr((string) $_POST['str'])); $url = trim(App::con()->escapeStr((string) $_POST['str']));
$hash = empty($_POST['custom']) ? null : $_POST['custom']; $hash = empty($_POST['custom']) ? null : $_POST['custom'];
if (empty($url)) { if (empty($url)) {
@ -117,12 +114,12 @@ class Manage extends Process
# ex: Send new url to messengers # ex: Send new url to messengers
if (!empty($rs)) { if (!empty($rs)) {
dcCore::app()->callBehavior('adminAfterKutrlCreate', $rs, __('New short URL')); App::behavior()->callBehavior('adminAfterKutrlCreate', $rs, __('New short URL'));
} }
} }
} }
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
return true; return true;

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Backend\Filter\{ use Dotclear\Core\Backend\Filter\{
Filters, Filters,
FiltersLibrary FiltersLibrary
@ -34,6 +24,13 @@ use Dotclear\Helper\Html\Form\{
Text Text
}; };
/**
* @brief kUtRL manage links class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ManageLinks extends Process class ManageLinks extends Process
{ {
private static Filters $kutrl_filter; private static Filters $kutrl_filter;
@ -69,7 +66,7 @@ class ManageLinks extends Process
$list_counter = $log->getLogs($params, true)->f(0); $list_counter = $log->getLogs($params, true)->f(0);
self::$kutrl_listing = new LinksListing($list_all, $list_counter); self::$kutrl_listing = new LinksListing($list_all, $list_counter);
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
if (!empty($_POST['deletelinks'])) { if (!empty($_POST['deletelinks'])) {
@ -85,12 +82,12 @@ class ManageLinks extends Process
$o->remove($rs->kut_url); $o->remove($rs->kut_url);
} }
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
Notices::addSuccessNotice(__('Links successfully deleted')); Notices::addSuccessNotice(__('Links successfully deleted'));
My::redirect(self::$kutrl_filter->values()); My::redirect(self::$kutrl_filter->values());
} catch (Exception $e) { } catch (Exception $e) {
dcCore::app()->error->add($e->getMessage()); App::error()->add($e->getMessage());
} }
} }

View File

@ -1,15 +1,5 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
@ -17,14 +7,26 @@ namespace Dotclear\Plugin\kUtRL;
use Dotclear\Module\MyPlugin; use Dotclear\Module\MyPlugin;
/** /**
* This module definitions. * @brief kUtRL My helper.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class My extends MyPlugin class My extends MyPlugin
{ {
/** @var string This module database table name */ /**
public const TABLE_NAME = \initkUtRL::KURL_TABLE_NAME; * This module database table name.
*
* @var string TABLE_NAME
*/
public const TABLE_NAME = 'kutrl';
/** @var array List of template tag which content URL that can be shorten */ /**
* List of template tag which content URL that can be shorten.
*
* @var array USED_TAGS
*/
public const USED_TAGS = [ public const USED_TAGS = [
'AttachmentURL', 'AttachmentURL',
'CategoryURL', 'CategoryURL',

View File

@ -1,24 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Core\Process; use Dotclear\Core\Process;
/** /**
* Module prepend. * @brief kUtRL prepend class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Prepend extends Process class Prepend extends Process
{ {
@ -51,46 +45,41 @@ class Prepend extends Process
} }
# Services # Services
dcCore::app()->addBehavior('kutrlService', fn () => ['default', Service\ServiceDefault::class]); App::behavior()->addBehavior('kutrlService', fn () => ['default', Service\ServiceDefault::class]);
if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) { if (!defined('SHORTEN_SERVICE_DISABLE_CUSTOM')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['custom', Service\ServiceCustom::class]); App::behavior()->addBehavior('kutrlService', fn () => ['custom', Service\ServiceCustom::class]);
} }
if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) { if (!defined('SHORTEN_SERVICE_DISABLE_LOCAL')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['local', Service\ServiceLocal::class]); App::behavior()->addBehavior('kutrlService', fn () => ['local', Service\ServiceLocal::class]);
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) { if (!defined('SHORTEN_SERVICE_DISABLE_BILBOLINKS')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['bilbolinks', Service\ServiceBilbolinks::class]); App::behavior()->addBehavior('kutrlService', fn () => ['bilbolinks', Service\ServiceBilbolinks::class]);
} }
if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) { if (!defined('SHORTEN_SERVICE_DISABLE_BITLY')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['bitly', Service\ServiceBitly::class]); App::behavior()->addBehavior('kutrlService', fn () => ['bitly', Service\ServiceBitly::class]);
} }
if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) { if (!defined('SHORTEN_SERVICE_DISABLE_ISGD')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['isgd', Service\ServiceIsgd::class]); App::behavior()->addBehavior('kutrlService', fn () => ['isgd', Service\ServiceIsgd::class]);
} }
if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) { if (!defined('SHORTEN_SERVICE_DISABLE_YOURLS')) {
dcCore::app()->addBehavior('kutrlService', fn () => ['yourls', Service\ServiceYourls::class]); App::behavior()->addBehavior('kutrlService', fn () => ['yourls', Service\ServiceYourls::class]);
} }
# Shorten url passed through wiki functions # Shorten url passed through wiki functions
dcCore::app()->addBehaviors([ App::behavior()->addBehaviors([
'coreInitWikiPost' => [Wiki::class, 'coreInitWiki'], 'coreInitWikiPost' => Wiki::coreInitWiki(...),
'coreInitWikiComment' => [Wiki::class, 'coreInitWiki'], 'coreInitWikiComment' => Wiki::coreInitWiki(...),
'coreInitWikiSimpleComment' => [Wiki::class,'coreInitWiki'], 'coreInitWikiSimpleComment' => Wiki::coreInitWiki(...),
]); ]);
# Public page # Public page
dcCore::app()->url->register( App::url()->register(
'kutrl', 'kutrl',
'go', 'go',
'^go(/(.*?)|)$', '^go(/(.*?)|)$',
[FrontendUrl::class, 'redirectUrl'] FrontendUrl::redirectUrl(...)
); );
# Add kUtRL events on plugin activityReport
if (defined('ACTIVITY_REPORT_V2')) {
require_once $d . 'lib.kutrl.activityreport.php';
}
return true; return true;
} }
} }

View File

@ -1,24 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* Generic class for shorten link service
* A service class must extends this one
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use dcError;
use Dotclear\Database\MetaRecord; use Dotclear\Database\MetaRecord;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
@ -26,6 +12,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Helper\Network\HttpClient; use Dotclear\Helper\Network\HttpClient;
/**
* @brief kUtRL service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Service class Service
{ {
public $error; public $error;
@ -38,7 +31,7 @@ class Service
{ {
$this->settings = My::settings(); $this->settings = My::settings();
$this->log = new Logs(); $this->log = new Logs();
$this->error = new dcError(); $this->error = App::error();
//$this->error->setHTMLFormat('%s', "%s\n"); //$this->error->setHTMLFormat('%s', "%s\n");
$this->init(); $this->init();
@ -144,7 +137,7 @@ class Service
# Test if an url is from current blog # Test if an url is from current blog
public function isBlogUrl(string $url): bool public function isBlogUrl(string $url): bool
{ {
$base = dcCore::app()->blog->url; $base = App::blog()->url();
$url = substr($url, 0, strlen($base)); $url = substr($url, 0, strlen($base));
return $url == $base; return $url == $base;
@ -177,7 +170,7 @@ class Service
*/ */
public function hash(string $url, ?string $hash = null) public function hash(string $url, ?string $hash = null)
{ {
$url = trim(dcCore::app()->con->escapeStr((string) $url)); $url = trim(App::con()->escapeStr((string) $url));
if ('undefined' === $this->id) { if ('undefined' === $this->id) {
return false; return false;
} }
@ -202,10 +195,10 @@ class Service
} }
$this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl'); $this->log->insert($rs->url, $rs->hash, $rs->type, 'kutrl');
dcCore::app()->blog->triggerBlog(); App::blog()->triggerBlog();
# --BEHAVIOR-- kutrlAfterCreateShortUrl # --BEHAVIOR-- kutrlAfterCreateShortUrl
dcCore::app()->callBehavior('kutrlAfterCreateShortUrl', $rs); App::behavior()->callBehavior('kutrlAfterCreateShortUrl', $rs);
} }
return $rs; return $rs;
@ -214,13 +207,27 @@ class Service
/** /**
* Create a hash for a given url (and its custom hash). * Create a hash for a given url (and its custom hash).
* *
* @return false|ArrayObject * @return false|MetaRecord
*/ */
public function createHash(string $url, ?string $hash = null) public function createHash(string $url, ?string $hash = null)
{ {
return false; return false;
} }
/**
* Get a shorlink record from values.
*
* @param string $hash The hash
* @param string $url The url
* @param string $type The type
*
* @return MetaRecord The link description record
*/
public function fromValue(string $hash, string $url, string $type): MetaRecord
{
return MetaRecord::newFromArray([['hash' => $hash, 'url' => $url, 'type' => $type]]);
}
/** /**
* Remove an url from list of know urls. * Remove an url from list of know urls.
*/ */

View File

@ -1,20 +1,9 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
Input, Input,
@ -24,6 +13,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL bilbolinks service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceBilbolinks extends Service class ServiceBilbolinks extends Service
{ {
protected $config = [ protected $config = [
@ -106,11 +102,10 @@ class ServiceBilbolinks extends Service
return false; return false;
} }
$rs = new ArrayObject(); return $this->fromValue(
$rs->hash = str_replace($this->url_base, '', $response); str_replace($this->url_base, '', $response),
$rs->url = $url; $url,
$rs->type = $this->id; $this->id
);
return $rs;
} }
} }

View File

@ -1,20 +1,9 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
Input, Input,
@ -24,6 +13,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL btily service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceBitly extends Service class ServiceBitly extends Service
{ {
protected $config = [ protected $config = [
@ -101,12 +97,11 @@ class ServiceBitly extends Service
$rsp = json_decode($response); $rsp = json_decode($response);
$rs = new ArrayObject(); return $this->fromValue(
$rs->hash = str_replace($this->url_base, '', (string) $rsp->link); str_replace($this->url_base, '', (string) $rsp->link),
$rs->url = (string) $rsp->long_url; (string) $rsp->long_url,
$rs->type = $this->id; $this->id
);
return $rs;
} }
private function headers() private function headers()

View File

@ -1,20 +1,9 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -25,6 +14,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL custom service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceCustom extends Service class ServiceCustom extends Service
{ {
protected $config = [ protected $config = [
@ -154,11 +150,11 @@ class ServiceCustom extends Service
return false; return false;
} }
$rs = new ArrayObject();
$rs->hash = str_replace($this->url_base, '', $response);
$rs->url = $url;
$rs->type = $this->id;
return $rs; return $this->fromValue(
str_replace($this->url_base, '', $response),
$url,
$this->id
);
} }
} }

View File

@ -1,20 +1,9 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
Note, Note,
@ -23,11 +12,18 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
# nb: "default" ne veut pas dire service par défaut /**
# mais service simple et rapide configuré par des constantes * @brief kUtRL default service class.
# cela permet de configurer ces constantes dans le fichier * @ingroup kUtRL
# config de Dotclear pour une plateforme complète. *
* Note: "default" ne veut pas dire service par défaut
* mais service simple et rapide configuré par des constantes
* cela permet de configurer ces constantes dans le fichier
* config de Dotclear pour une plateforme complète.
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceDefault extends Service class ServiceDefault extends Service
{ {
protected function init(): void protected function init(): void
@ -98,11 +94,10 @@ class ServiceDefault extends Service
return false; return false;
} }
$rs = new ArrayObject(); return $this->fromValue(
$rs->hash = str_replace($this->url_base, '', $response); str_replace($this->url_base, '', $response),
$rs->url = $url; $url,
$rs->type = $this->id; $this->id
);
return $rs;
} }
} }

View File

@ -1,22 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL is.gd service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceIsgd extends Service class ServiceIsgd extends Service
{ {
protected $config = [ protected $config = [
@ -51,11 +47,10 @@ class ServiceIsgd extends Service
return false; return false;
} }
$rs = new ArrayObject(); return $this->fromValue(
$rs->hash = str_replace($this->url_base, '', $response); str_replace($this->url_base, '', $response),
$rs->url = $url; $url,
$rs->type = $this->id; $this->id
);
return $rs;
} }
} }

View File

@ -1,21 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject; use Dotclear\App;
use dcCore;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -29,6 +18,13 @@ use Dotclear\Helper\Html\Form\{
use Dotclear\Helper\Html\Html; use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL local service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceLocal extends Service class ServiceLocal extends Service
{ {
protected $config = [ protected $config = [
@ -44,7 +40,7 @@ class ServiceLocal extends Service
$protocols = (string) $this->settings->get('srv_local_protocols'); $protocols = (string) $this->settings->get('srv_local_protocols');
$this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols); $this->config['allow_protocols'] = empty($protocols) ? [] : explode(',', $protocols);
$this->config['url_base'] = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/'; $this->config['url_base'] = App::blog()->url() . App::url()->getBase('kutrl') . '/';
$this->config['url_min_len'] = strlen($this->url_base) + 2; $this->config['url_min_len'] = strlen($this->url_base) + 2;
} }
@ -159,19 +155,19 @@ class ServiceLocal extends Service
public function createHash(string $url, ?string $hash = null) public function createHash(string $url, ?string $hash = null)
{ {
# Create response object # Create response object
$rs = new ArrayObject(); $rs_hash = '';
$rs->type = 'local'; $rs_type = 'local';
$rs->url = $url; $rs_url = $url;
# Normal link # Normal link
if ($hash === null) { if ($hash === null) {
$type = 'localnormal'; $type = 'localnormal';
$rs->hash = $this->next($this->last('localnormal')); $rs_hash = $this->next($this->last('localnormal'));
# Mixed custom link # Mixed custom link
} elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/', $hash, $m)) { } elseif (preg_match('/^([A-Za-z0-9]{2,})\!\!$/', $hash, $m)) {
$type = 'localmix'; $type = 'localmix';
$rs->hash = $m[1] . $this->next(-1, $m[1]); $rs_hash = $m[1] . $this->next(-1, $m[1]);
# Custom link # Custom link
} elseif (preg_match('/^[A-Za-z0-9\.\-\_]{2,}$/', $hash)) { } elseif (preg_match('/^[A-Za-z0-9\.\-\_]{2,}$/', $hash)) {
@ -181,7 +177,7 @@ class ServiceLocal extends Service
return false; return false;
} }
$type = 'localcustom'; $type = 'localcustom';
$rs->hash = $hash; $rs_hash = $hash;
# Wrong char in custom hash # Wrong char in custom hash
} else { } else {
@ -192,9 +188,13 @@ class ServiceLocal extends Service
# Save link # Save link
try { try {
$this->log->insert($rs->url, $rs->hash, $type, $rs->type); $this->log->insert($rs_url, $rs_hash, $type, $rs_type);
return $rs; return $this->fromValue(
$rs_hash,
$rs_url,
$rs_type
);
} catch (Exception $e) { } catch (Exception $e) {
$this->error->add(__('Failed to save link.')); $this->error->add(__('Failed to save link.'));
} }

View File

@ -1,20 +1,9 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL\Service; namespace Dotclear\Plugin\kUtRL\Service;
use ArrayObject;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Div, Div,
Input, Input,
@ -24,6 +13,13 @@ use Dotclear\Helper\Html\Form\{
}; };
use Dotclear\Plugin\kUtRL\Service; use Dotclear\Plugin\kUtRL\Service;
/**
* @brief kUtRL yourls service class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class ServiceYourls extends Service class ServiceYourls extends Service
{ {
protected $config = [ protected $config = [
@ -142,12 +138,11 @@ class ServiceYourls extends Service
$rsp = @simplexml_load_string($response); $rsp = @simplexml_load_string($response);
if ($rsp && $rsp->status == 'success') { if ($rsp && $rsp->status == 'success') {
$rs = new ArrayObject(); return $this->fromValue(
$rs->hash = $rsp->url[0]->keyword; $rsp->url[0]->keyword,
$rs->url = $url; $url,
$rs->type = $this->id; $this->id
);
return $rs;
} }
$this->error->add(__('Unreadable service response.')); $this->error->add(__('Unreadable service response.'));

View File

@ -1,25 +1,18 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore;
use Dotclear\Core\Process; use Dotclear\Core\Process;
use Dotclear\Plugin\Uninstaller\Uninstaller; use Dotclear\Plugin\Uninstaller\Uninstaller;
/** /**
* Plugin Uninstaller actions. * @brief kUtRL uninstall class.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/ */
class Uninstall extends Process class Uninstall extends Process
{ {
@ -30,7 +23,7 @@ class Uninstall extends Process
public static function process(): bool public static function process(): bool
{ {
if (!self::status() || !dcCore::app()->plugins->moduleExists('Uninstaller')) { if (!self::status()) {
return false; return false;
} }

View File

@ -1,24 +1,19 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* Generic class to play easily with services
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Exception; use Exception;
/**
* @brief kUtRL utils.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Utils class Utils
{ {
/** /**
@ -28,7 +23,7 @@ class Utils
*/ */
public static function getServices(): ?array public static function getServices(): ?array
{ {
$list = dcCore::app()->getBehaviors('kutrlService'); $list = App::behavior()->getBehavior('kutrlService');
if (empty($list)) { if (empty($list)) {
return []; return [];

View File

@ -1,20 +1,10 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Form, Form,
Hidden, Hidden,
@ -27,30 +17,34 @@ use Dotclear\Helper\Html\Html;
use Dotclear\Plugin\widgets\WidgetsStack; use Dotclear\Plugin\widgets\WidgetsStack;
use Dotclear\Plugin\widgets\WidgetsElement; use Dotclear\Plugin\widgets\WidgetsElement;
/**
* @brief kUtRL widgets.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Widgets class Widgets
{ {
public static function initShorten(WidgetsStack $w): void public static function init(WidgetsStack $w): void
{ {
$w $w
->create( ->create(
'shortenkutrl', 'shortenkutrl',
My::name(), My::name(),
[self::class, 'parseShorten'] self::parseShorten(...)
) )
->addTitle(__('Shorten link')) ->addTitle(__('Shorten link'))
->addHomeOnly() ->addHomeOnly()
->addContentOnly() ->addContentOnly()
->addClass() ->addClass()
->addOffline(); ->addOffline();
}
public static function initRank(WidgetsStack $w): void
{
$w $w
->create( ->create(
'rankkutrl', 'rankkutrl',
__('Top of short links'), __('Top of short links'),
[self::class, 'parseRank'] self::parseRank(...)
) )
->addTitle(__('Top of short links')) ->addTitle(__('Top of short links'))
->setting( ->setting(
@ -128,8 +122,8 @@ class Widgets
if (!$s->get('active') if (!$s->get('active')
|| !$s->get('srv_local_public') || !$s->get('srv_local_public')
|| !$w->checkHomeOnly(dcCore::app()->url->type) || !$w->checkHomeOnly(App::url()->type)
|| dcCore::app()->url->type == 'kutrl') { || App::url()->type == 'kutrl') {
return ''; return '';
} }
@ -143,7 +137,7 @@ class Widgets
($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(Html::escapeHTML($w->title)) : '') .
(new Form(['shortenkutrlwidget'])) (new Form(['shortenkutrlwidget']))
->method('post') ->method('post')
->action(dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl')) ->action(App::blog()->url() . App::url()->getBase('kutrl'))
->fields([ ->fields([
(new Para()) (new Para())
->items([ ->items([
@ -168,7 +162,7 @@ class Widgets
(new Submit('submiturl')) (new Submit('submiturl'))
->value(__('Shorten')), ->value(__('Shorten')),
(new Hidden('hmfp', $hmfp)), (new Hidden('hmfp', $hmfp)),
dcCore::app()->formNonce(false), App::nonce()->formNonce(),
]), ]),
]) ])
->render() ->render()
@ -179,19 +173,19 @@ class Widgets
{ {
$s = My::settings(); $s = My::settings();
if (!$s->get('active') || !$w->checkHomeOnly(dcCore::app()->url->type)) { if (!$s->get('active') || !$w->checkHomeOnly(App::url()->type)) {
return ''; return '';
} }
$type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ? $type = in_array($w->type, ['localnormal', 'localmix', 'localcustom']) ?
"AND kut_type ='" . $w->type . "' " : "AND kut_type ='" . $w->type . "' " :
'AND kut_type ' . dcCore::app()->con->in(['localnormal', 'localmix', 'localcustom']) . ' '; 'AND kut_type ' . App::con()->in(['localnormal', 'localmix', 'localcustom']) . ' ';
$hide = (bool) $w->hideempty ? 'AND kut_counter > 0 ' : ''; $hide = (bool) $w->hideempty ? 'AND kut_counter > 0 ' : '';
$more = ''; $more = '';
if ($w->type == 'localmix' && '' != $w->mixprefix) { if ($w->type == 'localmix' && '' != $w->mixprefix) {
$more = "AND kut_hash LIKE '" . dcCore::app()->con->escapeStr((string) $w->mixprefix) . "%' "; $more = "AND kut_hash LIKE '" . App::con()->escapeStr((string) $w->mixprefix) . "%' ";
} }
$order = ($w->sortby && in_array($w->sortby, ['kut_dt', 'kut_counter', 'kut_hash'])) ? $order = ($w->sortby && in_array($w->sortby, ['kut_dt', 'kut_counter', 'kut_hash'])) ?
@ -199,12 +193,12 @@ class Widgets
$order .= $w->sort == 'desc' ? ' DESC' : ' ASC'; $order .= $w->sort == 'desc' ? ' DESC' : ' ASC';
$limit = dcCore::app()->con->limit(abs((int) $w->limit)); $limit = App::con()->limit(abs((int) $w->limit));
$rs = dcCore::app()->con->select( $rs = App::con()->select(
'SELECT kut_counter, kut_hash ' . 'SELECT kut_counter, kut_hash ' .
'FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ' . 'FROM ' . App::con()->prefix() . My::TABLE_NAME . ' ' .
"WHERE blog_id='" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' " . "WHERE blog_id='" . App::con()->escapeStr(App::blog()->id()) . "' " .
"AND kut_service = 'local' " . "AND kut_service = 'local' " .
$type . $hide . $more . 'ORDER BY ' . $order . $limit $type . $hide . $more . 'ORDER BY ' . $order . $limit
); );
@ -220,7 +214,7 @@ class Widgets
$rank = '<span class="rankkutrl-rank">' . $i . '</span>'; $rank = '<span class="rankkutrl-rank">' . $i . '</span>';
$hash = $rs->kut_hash; $hash = $rs->kut_hash;
$url = dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/' . $hash; $url = App::blog()->url() . App::url()->getBase('kutrl') . '/' . $hash;
$cut_len = - abs((int) $w->urllen); $cut_len = - abs((int) $w->urllen);
if (strlen($url) > $cut_len) { if (strlen($url) > $cut_len) {
@ -240,7 +234,7 @@ class Widgets
} }
$content .= '<li><a href="' . $content .= '<li><a href="' .
dcCore::app()->blog->url . dcCore::app()->url->getBase('kutrl') . '/' . $rs->kut_hash . App::blog()->url() . App::url()->getBase('kutrl') . '/' . $rs->kut_hash .
'">' . '">' .
str_replace( str_replace(
['%rank%', '%hash%', '%url%', '%count%', '%counttext%'], ['%rank%', '%hash%', '%url%', '%count%', '%counttext%'],

View File

@ -1,31 +1,26 @@
<?php <?php
/**
* @brief kUtRL, a plugin for Dotclear 2
*
* This file contents class to shorten url pass through wiki
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1); declare(strict_types=1);
namespace Dotclear\Plugin\kUtRL; namespace Dotclear\Plugin\kUtRL;
use dcCore; use Dotclear\App;
use Dotclear\Helper\Html\WikiToHtml; use Dotclear\Helper\Html\WikiToHtml;
/**
* @brief kUtRL wiki stuff.
* @ingroup kUtRL
*
* @author Jean-Christian Denis (author)
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
class Wiki class Wiki
{ {
public static function coreInitWiki(WikiToHtml $wiki2xhtml): void public static function coreInitWiki(WikiToHtml $wiki2xhtml): void
{ {
# Do nothing on comment preview and post preview # Do nothing on comment preview and post preview
if (!empty($_POST['preview']) if (!empty($_POST['preview'])
|| isset(dcCore::app()->ctx) && dcCore::app()->ctx->preview || (App::task()->checkContext('FRONTEND') && App::frontend()->context()->preview)
|| !My::settings()?->get('active') || !My::settings()?->get('active')
) { ) {
return; return;
@ -36,7 +31,7 @@ class Wiki
foreach ($kut->allow_protocols as $protocol) { foreach ($kut->allow_protocols as $protocol) {
$wiki2xhtml->registerFunction( $wiki2xhtml->registerFunction(
'url:' . $protocol, 'url:' . $protocol,
[self::class, 'transform'] self::transform(...)
); );
} }
} }
@ -70,7 +65,7 @@ class Wiki
$res['content'] = $res['url']; $res['content'] = $res['url'];
} }
dcCore::app()->callBehavior('wikiAfterKutrlCreate', $rs, __('New short URL')); App::behavior()->callBehavior('wikiAfterKutrlCreate', $rs, __('New short URL'));
return $res; return $res;
} }