fix nullsafe warning
This commit is contained in:
parent
ec12058099
commit
1f819070ce
@ -34,6 +34,7 @@ class Backend extends dcNsProcess
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& My::phpCompliant()
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
@ -50,10 +51,10 @@ class Backend extends dcNsProcess
|
||||
# Admin menu
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
My::name(),
|
||||
dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||
dcPage::getPF(My::id() . '/icon.svg'),
|
||||
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
|
||||
preg_match('/' . preg_quote((string) dcCore::app()->adminurl?->get('admin.plugin.' . My::id())) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||
dcCore::app()->auth?->check(dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog?->id)
|
||||
);
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
@ -61,10 +62,10 @@ class Backend extends dcNsProcess
|
||||
'adminDashboardFavoritesV2' => function (dcFavorites $favs): void {
|
||||
$favs->register(My::id(), [
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'permissions' => dcCore::app()->auth->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
|
||||
'permissions' => dcCore::app()->auth?->makePermissions([dcCore::app()->auth::PERMISSION_CONTENT_ADMIN]),
|
||||
]);
|
||||
},
|
||||
# Preference form
|
||||
@ -85,7 +86,7 @@ class Backend extends dcNsProcess
|
||||
'<p class="form-note">' .
|
||||
__('This enable public widgets and contents filter.') .
|
||||
'</p>' .
|
||||
'<p><a href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '">' .
|
||||
'<p><a href="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '">' .
|
||||
__('Set content filters') . '</a></p>' .
|
||||
'</div>' .
|
||||
'<div class="col">' .
|
||||
|
@ -17,11 +17,10 @@ namespace Dotclear\Plugin\enhancePostContent;
|
||||
use adminGenericFilterV2;
|
||||
use adminGenericListV2;
|
||||
use dcPager;
|
||||
use Dotclear\Helper\Date;
|
||||
use Dotclear\Helper\Html\Form\Checkbox;
|
||||
use Dotclear\Helper\Html\Html;
|
||||
|
||||
use dt;
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_PERIODICAL
|
||||
* @brief Periodical - admin pager methods.
|
||||
@ -79,7 +78,7 @@ class BackendList extends adminGenericListV2
|
||||
'check' => '<td class="nowrap">' . (new Checkbox(['epc_id[]'], $checked))->value($this->rs->epc_id)->render() . '</td>',
|
||||
'key' => '<td class="nowrap">' . Html::escapeHTML($this->rs->epc_key) . '</td>',
|
||||
'value' => '<td class="maximal">' . Html::escapeHTML($this->rs->epc_value) . '</td>',
|
||||
'date' => '<td class="nowrap count">' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '</td>',
|
||||
'date' => '<td class="nowrap count">' . Date::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . '</td>',
|
||||
];
|
||||
|
||||
return
|
||||
|
55
src/Epc.php
55
src/Epc.php
@ -56,7 +56,7 @@ class Epc
|
||||
|
||||
public static function blogAllowedTplValues(): array
|
||||
{
|
||||
$rs = json_decode(dcCore::app()->blog->settings->get(My::id())->get('allowedtplvalues'));
|
||||
$rs = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get('allowedtplvalues'), true);
|
||||
|
||||
return is_array($rs) ? $rs : self::defaultAllowedTplValues();
|
||||
}
|
||||
@ -103,12 +103,12 @@ class Epc
|
||||
|
||||
public static function blogAllowedPubPages(): array
|
||||
{
|
||||
$rs = json_decode(dcCore::app()->blog->settings->get(My::id())->get('allowedpubpages'));
|
||||
$rs = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get('allowedpubpages'), true);
|
||||
|
||||
return is_array($rs) ? $rs : self::defaultAllowedPubPages();
|
||||
}
|
||||
|
||||
public static function getFilters(): ?array
|
||||
public static function getFilters(): array
|
||||
{
|
||||
if (empty(self::$default_filters)) {
|
||||
$final = $sort = [];
|
||||
@ -137,7 +137,7 @@ class Epc
|
||||
|
||||
public static function testContext(string $tag, array $args, EpcFilter $filter): bool
|
||||
{
|
||||
return in_array(dcCore::app()->ctx->current_tpl, $filter->pubPages)
|
||||
return in_array((string) dcCore::app()->ctx?->__get('current_tpl'), $filter->pubPages)
|
||||
&& in_array($tag, $filter->tplValues)
|
||||
&& $args[0] != '' //content
|
||||
&& empty($args['encode_xml'])
|
||||
@ -163,11 +163,12 @@ class Epc
|
||||
# Plural
|
||||
$x = $filter->plural ? $p . 's|' . $p : $p;
|
||||
# Mark words
|
||||
$s = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#su' . $i, '$1ççççç$2ççççç$3', $s, -1, $count);
|
||||
$ret = preg_replace('#(' . $before . ')(' . $x . ')(' . $after . ')#su' . $i, '$1ççççç$2ççççç$3', $s, -1, $count);
|
||||
# Nothing to parse
|
||||
if (!$count) {
|
||||
if (!is_string($ret) || !$count) {
|
||||
return $s;
|
||||
}
|
||||
$s = $ret;
|
||||
# Remove words that are into unwanted html tags
|
||||
$tags = '';
|
||||
$ignore_tags = array_merge(self::decodeTags($filter->htmltag), self::decodeTags($filter->notag));
|
||||
@ -175,16 +176,30 @@ class Epc
|
||||
$tags = implode('|', $ignore_tags);
|
||||
}
|
||||
if (!empty($tags)) {
|
||||
$s = preg_replace_callback('#(<(' . $tags . ')[^>]*?>)(.*?)(</\\2>)#s', [self::class, 'removeTags'], $s);
|
||||
$ret = preg_replace_callback('#(<(' . $tags . ')[^>]*?>)(.*?)(</\\2>)#s', [self::class, 'removeTags'], $s);
|
||||
if (is_string($ret)) {
|
||||
$s = $ret;
|
||||
}
|
||||
}
|
||||
# Remove words inside html tag (class, title, alt, href, ...)
|
||||
$s = preg_replace('#(ççççç(' . $p . '(s|))ççççç)(?=[^<]+>)#s' . $i, '$2$4', $s);
|
||||
$ret = preg_replace('#(ççççç(' . $p . '(s|))ççççç)(?=[^<]+>)#s' . $i, '$2$4', $s);
|
||||
if (is_string($ret)) {
|
||||
$s = $ret;
|
||||
}
|
||||
# Replace words by what you want (with limit)
|
||||
$s = preg_replace('#ççççç(' . $p . '(s|))ççççç#s' . $i, $r, $s, $limit, $count);
|
||||
$ret = preg_replace('#ççççç(' . $p . '(s|))ççççç#s' . $i, $r, $s, $limit, $count);
|
||||
if (is_string($ret)) {
|
||||
$s = $ret;
|
||||
}
|
||||
# update limit
|
||||
self::$epcFilterLimit[$filter->id() . '_' . $p] = $limit - $count;
|
||||
# Clean rest
|
||||
return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s);
|
||||
$ret = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s);
|
||||
if (is_string($ret)) {
|
||||
$s = $ret;
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
public static function matchString(string $p, string $r, string $s, EpcFilter $filter, string $before = '\b', string $after = '\b'): array
|
||||
@ -286,13 +301,13 @@ class Epc
|
||||
|
||||
public static function widgetContentEntryExcerpt(?WidgetsElement $w = null): string
|
||||
{
|
||||
if (!dcCore::app()->ctx->exists('posts')) {
|
||||
if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$res = '';
|
||||
while (dcCore::app()->ctx->posts->fetch()) {
|
||||
$res .= dcCore::app()->ctx->posts->f('post_excerpt');
|
||||
while (dcCore::app()->ctx->__get('posts')?->fetch()) {
|
||||
$res .= dcCore::app()->ctx->__get('posts')->f('post_excerpt');
|
||||
}
|
||||
|
||||
return $res;
|
||||
@ -300,13 +315,13 @@ class Epc
|
||||
|
||||
public static function widgetContentEntryContent(): string
|
||||
{
|
||||
if (!dcCore::app()->ctx->exists('posts')) {
|
||||
if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$res = '';
|
||||
while (dcCore::app()->ctx->posts->fetch()) {
|
||||
$res .= dcCore::app()->ctx->posts->f('post_content');
|
||||
while (dcCore::app()->ctx->__get('posts')?->fetch()) {
|
||||
$res .= dcCore::app()->ctx->__get('posts')->f('post_content');
|
||||
}
|
||||
|
||||
return $res;
|
||||
@ -314,15 +329,15 @@ class Epc
|
||||
|
||||
public static function widgetContentCommentContent(): string
|
||||
{
|
||||
if (!dcCore::app()->ctx->exists('posts')) {
|
||||
if (is_null(dcCore::app()->ctx) || !dcCore::app()->ctx->exists('posts')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$res = '';
|
||||
$post_ids = [];
|
||||
while (dcCore::app()->ctx->posts->fetch()) {
|
||||
$comments = dcCore::app()->blog->getComments(['post_id' => dcCore::app()->ctx->posts->f('post_id')]);
|
||||
while ($comments->fetch()) {
|
||||
while (dcCore::app()->ctx->__get('posts')?->fetch()) {
|
||||
$comments = dcCore::app()->blog?->getComments(['post_id' => dcCore::app()->ctx->__get('posts')->f('post_id')]);
|
||||
while ($comments?->fetch()) {
|
||||
$res .= $comments->getContent();
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ abstract class EpcFilter
|
||||
}
|
||||
|
||||
// get blog settings
|
||||
$s = json_decode((string) dcCore::app()->blog->settings->get(My::id())->get($this->id), true);
|
||||
$s = json_decode((string) dcCore::app()->blog?->settings->get(My::id())->get($this->id), true);
|
||||
if (empty($s)) {
|
||||
$s = [];
|
||||
}
|
||||
@ -110,13 +110,13 @@ abstract class EpcFilter
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
final public function records(): ?dcRecord
|
||||
final public function records(): dcRecord
|
||||
{
|
||||
if ($this->records === null && $this->has_list) {
|
||||
$this->records = EpcRecord::getRecords(['epc_filter' => $this->id()]);
|
||||
}
|
||||
|
||||
return $this->records;
|
||||
return $this->records ?? dcRecord::newFromArray([]);
|
||||
}
|
||||
|
||||
public function publicContent(string $tag, array $args): void
|
||||
|
@ -41,7 +41,7 @@ class EpcRecord
|
||||
$strReq .= $params['from'] . ' ';
|
||||
}
|
||||
|
||||
$strReq .= "WHERE E.blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' ";
|
||||
$strReq .= "WHERE E.blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' ";
|
||||
|
||||
if (isset($params['epc_type'])) {
|
||||
if (is_array($params['epc_type']) && !empty($params['epc_type'])) {
|
||||
@ -105,7 +105,7 @@ class EpcRecord
|
||||
|
||||
try {
|
||||
$cur->setField('epc_id', self::getNextId());
|
||||
$cur->setField('blog_id', dcCore::app()->blog->id);
|
||||
$cur->setField('blog_id', (string) dcCore::app()->blog?->id);
|
||||
$cur->setField('epc_upddt', date('Y-m-d H:i:s'));
|
||||
|
||||
self::getCursor($cur);
|
||||
@ -133,7 +133,7 @@ class EpcRecord
|
||||
|
||||
$cur->setField('epc_upddt', date('Y-m-d H:i:s'));
|
||||
|
||||
$cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' ");
|
||||
$cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' ");
|
||||
self::trigger();
|
||||
|
||||
# --BEHAVIOR-- enhancePostContentAfterUpdRecord : cursor, int
|
||||
@ -161,7 +161,7 @@ class EpcRecord
|
||||
dcCore::app()->con->execute(
|
||||
'DELETE FROM ' . dcCore::app()->prefix . My::TABLE_NAME . ' ' .
|
||||
'WHERE epc_id = ' . $id . ' ' .
|
||||
"AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog->id) . "' "
|
||||
"AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' "
|
||||
);
|
||||
|
||||
self::trigger();
|
||||
@ -194,6 +194,6 @@ class EpcRecord
|
||||
|
||||
private static function trigger(): void
|
||||
{
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcCore::app()->blog?->triggerBlog();
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class EpcFilterTag extends EpcFilter
|
||||
while ($metas->fetch()) {
|
||||
$args[0] = Epc::replaceString(
|
||||
$metas->f('meta_id'),
|
||||
sprintf($this->replace, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
|
||||
sprintf($this->replace, dcCore::app()->blog?->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
|
||||
$args[0],
|
||||
$this
|
||||
);
|
||||
@ -76,7 +76,7 @@ class EpcFilterTag extends EpcFilter
|
||||
while ($metas->fetch()) {
|
||||
$list[] = Epc::matchString(
|
||||
$metas->f('meta_id'),
|
||||
sprintf($this->widget, dcCore::app()->blog->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
|
||||
sprintf($this->widget, dcCore::app()->blog?->url . dcCore::app()->url->getBase('tag') . '/' . $metas->f('meta_id'), '\\1'),
|
||||
$content,
|
||||
$this
|
||||
);
|
||||
|
@ -33,20 +33,18 @@ class Frontend extends dcNsProcess
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dcCore::app()->blog->settings->get(My::id())->get('active')) {
|
||||
if (!dcCore::app()->blog?->settings->get(My::id())->get('active')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehaviors([
|
||||
// add CSS URL to header
|
||||
'publicHeadContent' => function (): void {
|
||||
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('epccss'));
|
||||
echo dcUtils::cssLoad(dcCore::app()->blog?->url . dcCore::app()->url->getURLFor('epccss'));
|
||||
},
|
||||
// Filter template blocks content
|
||||
'publicBeforeContentFilterV2' => function (string $tag, array $args): void {
|
||||
$filters = Epc::getFilters();
|
||||
|
||||
foreach ($filters as $id => $filter) {
|
||||
foreach (Epc::getFilters() as $id => $filter) {
|
||||
if (!Epc::testContext($tag, $args, $filter)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -62,7 +62,10 @@ class Install extends dcNsProcess
|
||||
self::growUp();
|
||||
|
||||
// Settings
|
||||
$s = dcCore::app()->blog->settings->get(My::id());
|
||||
$s = dcCore::app()->blog?->settings->get(My::id());
|
||||
if (is_null($s)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$s->put('active', false, 'boolean', 'Enable enhancePostContent', false, true);
|
||||
$s->put('list_sortby', 'epc_key', 'string', 'Admin records list field order', false, true);
|
||||
@ -72,8 +75,7 @@ class Install extends dcNsProcess
|
||||
$s->put('allowedpubpages', json_encode(Epc::defaultAllowedPubPages()), 'string', 'List of allowed template pages', false, true);
|
||||
|
||||
// Filters settings
|
||||
$filters = Epc::getFilters();
|
||||
foreach ($filters as $id => $filter) {
|
||||
foreach (Epc::getFilters() as $id => $filter) {
|
||||
// Only editable options
|
||||
$opt = [
|
||||
'nocase' => $filter->nocase,
|
||||
@ -162,7 +164,7 @@ class Install extends dcNsProcess
|
||||
$cur->setField('epc_filter', strtolower($record->f('epc_filter')));
|
||||
|
||||
$cur->update('WHERE epc_id = ' . $record->f('epc_id') . ' ');
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcCore::app()->blog?->triggerBlog();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@ class Manage extends dcNsProcess
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& My::phpCompliant()
|
||||
&& !is_null(dcCore::app()->auth) && !is_null(dcCore::app()->blog)
|
||||
&& dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([
|
||||
dcCore::app()->auth::PERMISSION_CONTENT_ADMIN,
|
||||
]), dcCore::app()->blog->id);
|
||||
@ -56,6 +57,10 @@ class Manage extends dcNsProcess
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$current = ManageVars::init();
|
||||
|
||||
if (dcCore::app()->error->flag()) {
|
||||
@ -163,6 +168,10 @@ class Manage extends dcNsProcess
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current = ManageVars::init();
|
||||
|
||||
# -- Prepare page --
|
||||
|
@ -33,14 +33,15 @@ class ManageVars
|
||||
$_filters = Epc::getFilters();
|
||||
|
||||
$filters_id = $filters_combo = [];
|
||||
foreach ($_filters as $id => $filter) {
|
||||
$filters_id[$id] = $filter->name;
|
||||
$filters_combo[$filter->name] = $id;
|
||||
if (!empty($_filters)) {
|
||||
foreach ($_filters as $id => $filter) {
|
||||
$filters_id[$id] = $filter->name;
|
||||
$filters_combo[$filter->name] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
$part = $_REQUEST['part'] ?? key($filters_id);
|
||||
|
||||
if (!isset($filters_id[$part])) {
|
||||
if (!isset($_filters[$part])) {
|
||||
throw new Exception(__('no filters'));
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,9 @@ class Prepend extends dcNsProcess
|
||||
function (string $args): void {
|
||||
$css = [];
|
||||
$filters = Epc::getFilters();
|
||||
if (empty($filters)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($filters as $id => $filter) {
|
||||
if ('' == $filter->class || '' == $filter->style) {
|
||||
|
@ -22,7 +22,7 @@ class Uninstall extends dcNsProcess
|
||||
{
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_RC_PATH');
|
||||
static::$init = defined('DC_CONTEXT_ADMIN');
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
@ -51,9 +51,8 @@ class Widgets
|
||||
'text'
|
||||
);
|
||||
# Type
|
||||
$filters = Epc::getFilters();
|
||||
$types = [];
|
||||
foreach ($filters as $id => $filter) {
|
||||
$types = [];
|
||||
foreach (Epc::getFilters() as $id => $filter) {
|
||||
if ($filter->widget != '') {
|
||||
$types[$filter->name] = $id;
|
||||
}
|
||||
@ -66,8 +65,7 @@ class Widgets
|
||||
$types
|
||||
);
|
||||
# Content
|
||||
$contents = Epc::defaultAllowedWidgetValues();
|
||||
foreach ($contents as $k => $v) {
|
||||
foreach (Epc::defaultAllowedWidgetValues() as $k => $v) {
|
||||
$w->epclist->setting(
|
||||
'content' . $v['id'],
|
||||
sprintf(__('Enable filter on %s'), __($k)),
|
||||
@ -101,8 +99,8 @@ class Widgets
|
||||
}
|
||||
|
||||
# Page
|
||||
if (!dcCore::app()->blog->settings->get(My::id())->get('active')
|
||||
|| !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html'])
|
||||
if (!dcCore::app()->blog?->settings->get(My::id())->get('active')
|
||||
|| !in_array(dcCore::app()->ctx?->__get('current_tpl'), ['post.html', 'page.html'])
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user