move to namespace

This commit is contained in:
Jean-Christian Denis 2023-03-12 10:53:37 +01:00
parent 03685ed43c
commit cf381122f9
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
3 changed files with 114 additions and 84 deletions

View file

@ -10,8 +10,30 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @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_CONTEXT_ADMIN')) { declare(strict_types=1);
return null;
}
require_once __DIR__ . '/_widgets.php'; namespace Dotclear\Plugin\entryPhotoExifWidget;
use dcCore;
use dcNsProcess;
class Backend extends dcNsProcess
{
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN');
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
return true;
}
}

View file

@ -10,8 +10,30 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @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;
}
require_once __DIR__ . '/_widgets.php'; namespace Dotclear\Plugin\entryPhotoExifWidget;
use dcCore;
use dcNsProcess;
class Frontend extends dcNsProcess
{
public static function init(): bool
{
self::$init = defined('DC_RC_PATH');
return self::$init;
}
public static function process(): bool
{
if (!self::$init) {
return false;
}
dcCore::app()->addBehavior('initWidgets', [Widgets::class, 'initWidgets']);
return true;
}
}

View file

@ -10,20 +10,26 @@
* @copyright Jean-Christian Denis * @copyright Jean-Christian Denis
* @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;
}
dcCore::app()->addBehavior('initWidgets', ['entryPhotoExifWidget', 'setWidget']); namespace Dotclear\Plugin\entryPhotoExifWidget;
class entryPhotoExifWidget use dcCore;
use Dotclear\Plugin\widgets\WidgetsElement;
use Dotclear\Plugin\widgets\WidgetsStack;
use dt;
use html;
use imageMeta;
use path;
class Widgets
{ {
public static $supported_post_type = ['post', 'page', 'gal', 'galitem']; public static $supported_post_type = ['post', 'page', 'gal', 'galitem'];
public static $widget_content = '<ul>%s</ul>'; public static $widget_content = '<ul>%s</ul>';
public static $widget_text = '<li class="epew-%s"><strong>%s</strong> %s</li>'; public static $widget_text = '<li class="epew-%s"><strong>%s</strong> %s</li>';
public static $widget_thumb = '<li><img class="img-thumbnail" alt="%s" src="%s" /></li>'; public static $widget_thumb = '<li><img class="img-thumbnail" alt="%s" src="%s" /></li>';
public static function setWidget($w) public static function initWidgets(WidgetsStack $w): void
{ {
$categories_combo = ['-' => '', __('Uncategorized') => 'null']; $categories_combo = ['-' => '', __('Uncategorized') => 'null'];
$categories = dcCore::app()->blog->getCategories(); $categories = dcCore::app()->blog->getCategories();
@ -42,162 +48,142 @@ class entryPhotoExifWidget
$w->create( $w->create(
'epew', 'epew',
__('Entry Photo Exif'), __('Entry Photo EXIF'),
['entryPhotoExifWidget', 'getWidget'], [Widgets::class, 'renderWidget'],
null, null,
__('Show images exif of an entry') __('Show images exif of an entry')
); )
->addTitle(__('Photos EXIF'))
$w->epew->setting( ->setting(
'title',
__('Title:'),
__('Photos EXIF'),
'text'
);
$w->epew->setting(
'showmeta_Title', 'showmeta_Title',
sprintf(__('Show metadata: %s'), __('Title')), sprintf(__('Show metadata: %s'), __('Title')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Description', 'showmeta_Description',
sprintf(__('Show metadata: %s'), __('Descritpion')), sprintf(__('Show metadata: %s'), __('Descritpion')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Location', 'showmeta_Location',
sprintf(__('Show metadata: %s'), __('Location')), sprintf(__('Show metadata: %s'), __('Location')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_DateTimeOriginal', 'showmeta_DateTimeOriginal',
sprintf(__('Show metadata: %s'), __('Date')), sprintf(__('Show metadata: %s'), __('Date')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Make', 'showmeta_Make',
sprintf(__('Show metadata: %s'), __('Manufacturer')), sprintf(__('Show metadata: %s'), __('Manufacturer')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Model', 'showmeta_Model',
sprintf(__('Show metadata: %s'), __('Model')), sprintf(__('Show metadata: %s'), __('Model')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Lens', 'showmeta_Lens',
sprintf(__('Show metadata: %s'), __('Lens')), sprintf(__('Show metadata: %s'), __('Lens')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_ExposureProgram', 'showmeta_ExposureProgram',
sprintf(__('Show metadata: %s'), __('Exposure program')), sprintf(__('Show metadata: %s'), __('Exposure program')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_Exposure', 'showmeta_Exposure',
sprintf(__('Show metadata: %s'), __('Exposure time')), sprintf(__('Show metadata: %s'), __('Exposure time')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_FNumber', 'showmeta_FNumber',
sprintf(__('Show metadata: %s'), __('Aperture')), sprintf(__('Show metadata: %s'), __('Aperture')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_ISOSpeedRatings', 'showmeta_ISOSpeedRatings',
sprintf(__('Show metadata: %s'), __('Iso speed rating')), sprintf(__('Show metadata: %s'), __('Iso speed rating')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_FocalLength', 'showmeta_FocalLength',
sprintf(__('Show metadata: %s'), __('Focal lengh')), sprintf(__('Show metadata: %s'), __('Focal lengh')),
1, 1,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_ExposureBiasValue', 'showmeta_ExposureBiasValue',
sprintf(__('Show metadata: %s'), __('Exposure bias value')), sprintf(__('Show metadata: %s'), __('Exposure bias value')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta_MeteringMode', 'showmeta_MeteringMode',
sprintf(__('Show metadata: %s'), __('Metering mode')), sprintf(__('Show metadata: %s'), __('Metering mode')),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'showmeta', 'showmeta',
__('Show empty metadata'), __('Show empty metadata'),
0, 0,
'check' 'check'
); )
$w->epew->setting( ->setting(
'category', 'category',
__('Category limit:'), __('Category limit:'),
'', '',
'combo', 'combo',
$categories_combo $categories_combo
); )
$w->epew->setting( ->setting(
'thumbsize', 'thumbsize',
__('Thumbnail size:'), __('Thumbnail size:'),
't', 't',
'combo', 'combo',
$thumbnail_combo $thumbnail_combo
); )
$w->epew->setting( ->addContentOnly()
'content_only', ->addClass()
__('Content only'), ->addOffline();
0,
'check'
);
$w->epew->setting(
'class',
__('CSS class:'),
''
);
$w->epew->setting(
'offline',
__('Offline'),
0,
'check'
);
} }
public static function getWidget($w) public static function renderWidget(WidgetsElement $w): string
{ {
# Widget is offline # Widget is offline
if ($w->offline) { if ($w->offline) {
return null; return '';
} }
# Not in post context # Not in post context
if (!dcCore::app()->ctx->exists('posts') || !dcCore::app()->ctx->posts->post_id) { if (!dcCore::app()->ctx->exists('posts') || !dcCore::app()->ctx->posts->post_id) {
return null; return '';
} }
# Not supported post type # Not supported post type
if (!in_array(dcCore::app()->ctx->posts->post_type, self::$supported_post_type)) { if (!in_array(dcCore::app()->ctx->posts->post_type, self::$supported_post_type)) {
return null; return '';
} }
# Category limit # Category limit
if ($w->category == 'null' && dcCore::app()->ctx->posts->cat_id !== null if ($w->category == 'null' && dcCore::app()->ctx->posts->cat_id !== null
|| $w->category != 'null' && $w->category != '' && $w->category != dcCore::app()->ctx->posts->cat_id) { || $w->category != 'null' && $w->category != '' && $w->category != dcCore::app()->ctx->posts->cat_id) {
return null; return '';
} }
# Content lookup # Content lookup
@ -208,7 +194,7 @@ class entryPhotoExifWidget
# No images # No images
if (empty($images)) { if (empty($images)) {
return null; return '';
} }
$contents = ''; $contents = '';
@ -229,7 +215,7 @@ class entryPhotoExifWidget
# No meta # No meta
if (empty($content)) { if (empty($content)) {
return null; return '';
} }
# Thumbnail # Thumbnail
@ -242,12 +228,12 @@ class entryPhotoExifWidget
# Nothing found # Nothing found
if (empty($contents)) { if (empty($contents)) {
return null; return '';
} }
# Paste widget # Paste widget
return $w->renderDiv( return $w->renderDiv(
$w->content_only, (bool) $w->content_only,
'photoExifWidget ' . $w->class, 'photoExifWidget ' . $w->class,
'', '',
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') . ($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .