From abb13080583932689ba01eade00705be2e543827 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 2 Sep 2021 20:35:25 +0200 Subject: [PATCH] clean up php files --- CHANGELOG.md | 141 +++++++++++++------------- _admin.php | 22 ++--- _define.php | 29 +++--- _install.php | 22 ++--- _prepend.php | 22 ++--- _public.php | 22 ++--- _uninstall.php | 22 ++--- _widgets.php | 22 ++--- inc/lib.epc.php | 208 +++++++++++++++++++-------------------- inc/lib.epc.records.php | 28 +++--- inc/lib.epc.update.php | 22 ++--- index.php | 24 ++--- locales/fr/main.lang.php | 3 +- 13 files changed, 298 insertions(+), 289 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5639cee..9014e6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,81 +1,90 @@ -enhancePostContent xxxx.xx.xx - * Not added priority on filters for replacement order - * Not added priority on lists of filters for replacement order - * Not added auto-find post title in content +xxxx.xx.xx +- [ ] add priority on filters for replacement order +- [ ] add priority on lists of filters for replacement order +- [ ] add auto-find post title in content +- [ ] split filters into modules +- [ ] fix filters on spaces after words -enhancePostContent 2021.08.24 - * switch to Dotclear 2.19 - * switch to php 7.3+ and php 8.0.x - * switch to Github - * update license - * update php code to PSR-2 and short array - * move settings from plugin to blog +2021.08.24.1 +- add links to blog prefs +- clean up php files style +- add dcstore.xml -enhancePostContent 2013.11.08 - * Switch to Dotclear 2.6 (admin styles and settings) - * Add dashboard icon - * Add widget options (content_only and class) - * Fix records list pager +2021.08.24 +- switch to Dotclear 2.19 +- switch to php 7.3+ and php 8.0.x +- switch to Github +- update license +- update php code to PSR-2 and short array +- move settings from plugin to blog +- fix widget rendering +- fix php strict warning on undeclared var on public content -enhancePostContent 2013.06.25 - * Fixed widget compatibility for php 5.4 +2013.11.08 +- Switch to Dotclear 2.6 (admin styles and settings) +- Add dashboard icon +- Add widget options (content_only and class) +- Fix records list pager -enhancePostContent 2013.05.11 - * Fixed bug with Twitter replacement and wiki synthax of blockquote - * Fixed page title +2013.06.25 +- Fixed widget compatibility for php 5.4 -enhancePostContent 2011.06.03 - * Added 'feeds pages' +2013.05.11 +- Fixed bug with Twitter replacement and wiki synthax of blockquote +- Fixed page title -enhancePostContent 0.9 - 2010-06-06 - * Switched to DC 2.2 +2011.06.03 +- Added 'feeds pages' -enhancePostContent 0.8.1 - 2010-03-31 - * Fixed some l10n - * Added option for default list order +0.9 - 2010-06-06 +- Switched to DC 2.2 -enhancePostContent 0.8 - 2010-03-31 - * Added admin lists sortable - * Added pager for admin lists - * Added update on records - * Changed title of HTML tag on links replacement - * Removed empty CSS from head - * Enhanced admin pages +0.8.1 - 2010-03-31 +- Fixed some l10n +- Added option for default list order -enhancePostContent 0.7 - 2010-01-12 - * Moved lists from setting to a new database +0.8 - 2010-03-31 +- Added admin lists sortable +- Added pager for admin lists +- Added update on records +- Changed title of HTML tag on links replacement +- Removed empty CSS from head +- Enhanced admin pages -enhancePostContent 0.6 - 2010-01-09 - * Fixed HTML tags to use standard tags. - * Fixed CSS class names - * Changed settings management - * Added widget (only for post page) - * Added some post enhancement +0.7 - 2010-01-12 +- Moved lists from setting to a new database -enhancePostContent 0.5 - 2009-12-28 - * Added support of comment content - * Added support of word replacement - * Added option for case sensitive - * Added option for plural - * Changed class from post-xxx to epc-xxx - * Changed names from acronyme to acronym - * Changed acronym html tag from to - * Changed all settings management +0.6 - 2010-01-09 +- Fixed HTML tags to use standard tags. +- Fixed CSS class names +- Changed settings management +- Added widget (only for post page) +- Added some post enhancement -enhancePostContent 0.4 - 2009-12-24 - * Merry Christmas! - * enhanced filters - * Added support of entry excerpt - * Added support of custom ignored HTML tags - * Added some help +0.5 - 2009-12-28 +- Added support of comment content +- Added support of word replacement +- Added option for case sensitive +- Added option for plural +- Changed class from post-xxx to epc-xxx +- Changed names from acronyme to acronym +- Changed acronym html tag from to +- Changed all settings management -enhancePostContent 0.3 - 2009-12-21 - * Fixed filter with punctuation (slow hack) - * Added word-to-link filter +0.4 - 2009-12-24 +- Merry Christmas! +- enhanced filters +- Added support of entry excerpt +- Added support of custom ignored HTML tags +- Added some help -enhancePostContent 0.2 - 2009-12-12 - * Fixed case sensitive definition - * Prepared DC 2.2 +0.3 - 2009-12-21 +- Fixed filter with punctuation (slow hack) +è Added word-to-link filter -enhancePostContent 0.1 - 2009-10-17 - * First release \ No newline at end of file +0.2 - 2009-12-12 +- Fixed case sensitive definition +- Prepared DC 2.2 + +0.1 - 2009-10-17 +- First release \ No newline at end of file diff --git a/_admin.php b/_admin.php index e05faae..428bfc1 100644 --- a/_admin.php +++ b/_admin.php @@ -1,15 +1,15 @@ registerModule( 'Enhance post content', 'Add features to words in post content', 'Jean-Christian Denis and Contributors', - '2021.08.24', + '2021.08.24.1', [ + 'requires' => [['core', '2.19']], 'permissions' => 'contentadmin', 'type' => 'plugin', - 'dc_min' => '2.18', 'support' => 'https://github.com/JcDenis/enhancePostContent', - 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent' + 'details' => 'https://plugins.dotaddict.org/dc2/details/enhancePostContent', + 'repository' => 'https://raw.githubusercontent.com/JcDenis/enhancePostContent/master/dcstore.xml' ] ); \ No newline at end of file diff --git a/_install.php b/_install.php index 9abee83..7294ec2 100644 --- a/_install.php +++ b/_install.php @@ -1,15 +1,15 @@ 'CommentContent', ]; } - + public static function blogAllowedTplValues() { global $core; @@ -41,11 +41,11 @@ class libEPC $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedtplvalues); return is_array($rs) ? $rs : $allowedtplvalues; } - + public static function defaultAllowedWidgetValues() { global $core; - + $rs = [ 'entry excerpt' => [ 'id' => 'entryexcerpt', @@ -60,12 +60,12 @@ class libEPC 'callback' => ['libEPC','widgetContentCommentContent'] ] ]; - + $core->callBehavior('enhancePostContentAllowedWidgetValues', $rs); - + return $rs; } - + public static function defaultAllowedPubPages() { return [ @@ -77,7 +77,7 @@ class libEPC 'RSS feeds' => 'rss2.xml' ]; } - + public static function blogAllowedPubPages() { global $core; @@ -86,24 +86,24 @@ class libEPC $rs = @unserialize($core->blog->settings->enhancePostContent->enhancePostContent_allowedpubpages); return is_array($rs) ? $rs : $allowedpubpages; } - + public static function defaultFilters() { global $core; - + $filters = [ 'Tag' => [ 'id' => 'tag', 'publicContentFilter' => ['libEPC', 'publicContentFilterTag'], 'widgetListFilter' => ['libEPC', 'widgetListTag'], - + 'help' => __('Highlight tags of your blog.'), 'has_list' => false, 'htmltag' => 'a', 'class' => ['a.epc-tag'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -115,13 +115,13 @@ class libEPC 'Search' => [ 'id' => 'search', 'publicContentFilter' => ['libEPC', 'publicContentFilterSearch'], - + 'help' => __('Highlight searched words.'), 'has_list' => false, 'htmltag' => '', 'class' => ['span.epc-search'], 'replace' => '%s', - + 'nocase' => true, 'plural' => true, 'limit' => 0, @@ -134,14 +134,14 @@ class libEPC 'id' => 'acronym', 'publicContentFilter' => ['libEPC', 'publicContentFilterAcronym'], 'widgetListFilter' => ['libEPC', 'widgetListAcronym'], - + 'help' => __('Explain some acronyms. First term of the list is the acornym and second term the explanation.'), 'has_list' => true, 'htmltag' => 'acronym', 'class' => ['acronym.epc-acronym'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -154,14 +154,14 @@ class libEPC 'id' => 'abbreviation', 'publicContentFilter' => ['libEPC', 'publicContentFilterAbbreviation'], 'widgetListFilter' => ['libEPC', 'widgetListAbbreviation'], - + 'help' => __('Explain some abbreviation. First term of the list is the abbreviation and second term the explanation.'), 'has_list' => true, 'htmltag' => 'a', 'class' => ['abbr.epc-abbr'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -174,14 +174,14 @@ class libEPC 'id' => 'definition', 'publicContentFilter' => ['libEPC', 'publicContentFilterDefinition'], 'widgetListFilter' => ['libEPC', 'widgetListDefinition'], - + 'help' => __('Explain some definition. First term of the list is the sample to define and second term the explanation.'), 'has_list' => true, 'htmltag' => 'dfn', 'class' => ['dfn.epc-dfn'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -194,14 +194,14 @@ class libEPC 'id' => 'citation', 'publicContentFilter' => ['libEPC', 'publicContentFilterCitation'], 'widgetListFilter' => ['libEPC', 'widgetListCitation'], - + 'help' => __('Highlight citation of people. First term of the list is the citation and second term the author.'), 'has_list' => true, 'htmltag' => 'cite', 'class' => ['cite.epc-cite'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => true, 'plural' => false, 'limit' => 0, @@ -214,14 +214,14 @@ class libEPC 'id' => 'link', 'publicContentFilter' => ['libEPC', 'publicContentFilterLink'], 'widgetListFilter' => ['libEPC', 'widgetListLink'], - + 'help' => __('Link some words. First term of the list is the term to link and second term the link.'), 'has_list' => true, 'htmltag' => 'a', 'class' => ['a.epc-link'], 'replace' => '%s', 'widget' => '%s', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -233,13 +233,13 @@ class libEPC 'Replace' => [ 'id' => 'replace', 'publicContentFilter' => ['libEPC', 'publicContentFilterReplace'], - + 'help' => __('Replace some text. First term of the list is the text to replace and second term the replacement.'), 'has_list' => true, 'htmltag' => '', 'class' => ['span.epc-replace'], 'replace' => '%s', - + 'nocase' => true, 'plural' => true, 'limit' => 0, @@ -251,13 +251,13 @@ class libEPC 'Update' => [ 'id' => 'update', 'publicContentFilter' => ['libEPC', 'publicContentFilterUpdate'], - + 'help' => __('Update and show terms. First term of the list is the term to update and second term the new term.'), 'has_list' => true, 'htmltag' => 'del,ins', 'class' => ['del.epc-update', 'ins.epc-update'], 'replace' => '%s %s', - + 'nocase' => true, 'plural' => true, 'limit' => 0, @@ -269,13 +269,13 @@ class libEPC 'Twitter' => [ 'id' => 'twitter', 'publicContentFilter' => ['libEPC', 'publicContentFilterTwitter'], - + 'help' => __('Add link to twitter user page. Every word started with "@" will be considered as twitter user.'), 'has_list' => false, 'htmltag' => 'a', 'class' => ['a.epc-twitter'], 'replace' => '', - + 'nocase' => false, 'plural' => false, 'limit' => 0, @@ -285,23 +285,23 @@ class libEPC 'pubPages' => ['post.html'] ] ]; - + $core->callBehavior('enhancePostContentDefaultFilters', $filters); - + return $filters; } - + public static function blogFilters($one = null) { global $core; $core->blog->settings->addNamespace('enhancePostContent'); $filters = self::defaultFilters(); - + foreach($filters as $name => $filter) { # Parse filters options $ns = 'enhancePostContent_' . $name; $opt[$name] = @unserialize($core->blog->settings->enhancePostContent->$ns); - + if (!is_array($opt[$name])) { $opt[$name] = []; } @@ -327,9 +327,9 @@ class libEPC $filters[$name]['pubPages'] = (array) $opt[$name]['pubPages']; } } - + $core->callBehavior('enhancePostContentBlogFilters', $filters); - + return $filters; } @@ -346,7 +346,7 @@ class libEPC && empty($args[2]) // remove html ; } - + public static function replaceString($p, $r, $s, $filter, $before = '\b', $after = '\b') { # Limit @@ -386,7 +386,7 @@ class libEPC # Clean rest return $s = preg_replace('#ççççç(.*?)ççççç#s', '$1', $s); } - + public static function matchString($p, $r, $s, $filter, $before = '\b', $after = '\b') { # Case sensitive @@ -399,7 +399,7 @@ class libEPC if (!$t) { return ['total' => 0, 'matches' => []]; } - + # Build array $m = []; $loop = 0; @@ -411,22 +411,22 @@ class libEPC } return ['total' => $t, 'matches' => $m]; } - + public static function quote($s) { return preg_quote($s, '#'); } - + public static function removeTags($m) { return $m[1] . preg_replace('#ççççç(?!ççççç)#s', '$1', $m[3]) . $m[4]; } - + public static function decodeTags($t) { return preg_match_all('#([A-Za-z0-9]+)#', (string) $t, $m) ? $m[1] : []; } - + public static function implode($a) { if (is_string($a)) { @@ -435,14 +435,14 @@ class libEPC if (!is_array($a)) { return []; } - + $r = ''; foreach($a as $k => $v) { $r .= $k . ':' . $v . ';'; } return $r; } - + public static function explode($s) { if (is_array($s)) { @@ -451,71 +451,71 @@ class libEPC if (!is_string($s)) { return ''; } - + $r = []; $s = explode(';', (string) $s); if (!is_array($s)) { return []; } - + foreach($s as $cpl) { $cur = explode(':', $cpl); - + if (!is_array($cur) || !isset($cur[1])) { continue; } - + $key = html::escapeHTML(trim($cur[0])); $val = html::escapeHTML(trim($cur[1])); - + if (empty($key) || empty($val)) { continue; } - + $r[$key] = $val; } return $r; } - + # # Widgets # - + public static function widgetContentEntryExcerpt($core, $w) { global $_ctx; if (!$_ctx->exists('posts')) { return; } - + $res = ''; while ($_ctx->posts->fetch()) { $res .= $_ctx->posts->post_excerpt; } return $res; } - + public static function widgetContentEntryContent() { global $_ctx; if (!$_ctx->exists('posts')) { return; } - + $res = ''; while ($_ctx->posts->fetch()) { $res .= $_ctx->posts->post_content; } return $res; } - + public static function widgetContentCommentContent() { global $core, $_ctx; if (!$_ctx->exists('posts')) { return; } - + $res = ''; $post_ids = []; while ($_ctx->posts->fetch()) { @@ -526,19 +526,19 @@ class libEPC } return $res; } - + # # Filters # - + public static function publicContentFilterTag($core, $filter, $tag, $args) { if (!$core->plugins->moduleExists('tags')) { return; } - + $metas = $core->meta->getMetadata(['meta_type' => 'tag']); - + while($metas->fetch()) { $k = $metas->meta_id; $args[0] = self::replaceString( @@ -550,7 +550,7 @@ class libEPC } return; } - + public static function widgetListTag($core, $filter, $content, $w, &$list) { if (!$core->plugins->moduleExists('tags')) { @@ -558,7 +558,7 @@ class libEPC } $metas = $core->meta->getMetadata(['meta_type' => 'tag']); - + while($metas->fetch()) { $k = $metas->meta_id; $list[] = self::matchString( @@ -570,15 +570,15 @@ class libEPC } return; } - + public static function publicContentFilterSearch($core, $filter, $tag, $args) { if (!isset($GLOBALS['_search'])) { return; } - + $searchs = explode(' ', $GLOBALS['_search']); - + foreach($searchs as $k => $v) { $args[0] = self::replaceString( $v, @@ -589,13 +589,13 @@ class libEPC } return; } - + public static function publicContentFilterAcronym($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], __($v), '\\1'), @@ -605,13 +605,13 @@ class libEPC } return; } - + public static function widgetListAcronym($core, $filter, $content, $w, &$list) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $list[] = self::matchString( $k, sprintf($filter['widget'], __($v), '\\1'), @@ -621,13 +621,13 @@ class libEPC } return; } - + public static function publicContentFilterAbbreviation($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], __($v), '\\1'), @@ -637,13 +637,13 @@ class libEPC } return; } - + public static function widgetListAbbreviation($core, $filter, $content, $w, &$list) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $list[] = self::matchString( $k, sprintf($filter['widget'], __($v), '\\1'), @@ -653,13 +653,13 @@ class libEPC } return; } - + public static function publicContentFilterDefinition($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], __($v), '\\1'), @@ -669,13 +669,13 @@ class libEPC } return; } - + public static function widgetListDefinition($core, $filter, $content, $w, &$list) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $list[] = self::matchString( $k, sprintf($filter['widget'], __($v), '\\1'), @@ -685,13 +685,13 @@ class libEPC } return; } - + public static function publicContentFilterCitation($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], __($v), '\\1'), @@ -701,13 +701,13 @@ class libEPC } return; } - + public static function widgetListCitation($core, $filter, $content, $w, &$list) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $list[] = self::matchString( $k, sprintf($filter['widget'], __($v), '\\1'), @@ -717,13 +717,13 @@ class libEPC } return; } - + public static function publicContentFilterLink($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], '\\1', $v, '\\1'), @@ -733,13 +733,13 @@ class libEPC } return; } - + public static function widgetListLink($core, $filter, $content, $w, &$list) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $list[] = self::matchString( $k, sprintf($filter['widget'], $v, $v, '\\1'), @@ -749,13 +749,13 @@ class libEPC } return; } - + public static function publicContentFilterReplace($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], $v, '\\2'), @@ -765,13 +765,13 @@ class libEPC } return; } - + public static function publicContentFilterUpdate($core, $filter, $tag, $args) { while($filter['list']->fetch()) { $k = $filter['list']->epc_key; $v = $filter['list']->epc_value; - + $args[0] = self::replaceString( $k, sprintf($filter['replace'], '\\1', $v), @@ -781,7 +781,7 @@ class libEPC } return; } - + public static function publicContentFilterTwitter($core, $filter, $tag, $args) { $args[0] = self::replaceString( diff --git a/inc/lib.epc.records.php b/inc/lib.epc.records.php index 2574e45..083ab6d 100644 --- a/inc/lib.epc.records.php +++ b/inc/lib.epc.records.php @@ -1,15 +1,15 @@ epc_id = $this->getNextId(); $cur->blog_id = $this->blog; $cur->epc_upddt = date('Y-m-d H:i:s'); - + $this->getCursor($cur); - + $cur->insert(); $this->con->unlock(); } catch (Exception $e) { @@ -120,7 +120,7 @@ class epcRecords return $cur->epc_id; } - + public function updRecord($id, $cur) { $id = (integer) $id; diff --git a/inc/lib.epc.update.php b/inc/lib.epc.update.php index 45b6741..5188973 100644 --- a/inc/lib.epc.update.php +++ b/inc/lib.epc.update.php @@ -1,15 +1,15 @@ enhancePostContent_list_sortby; $order = !empty($_GET['order']) ? $_GET['order'] : (string) $s->enhancePostContent_list_order; $page = !empty($_GET['page']) ? (integer) $_GET['page'] : 1; diff --git a/locales/fr/main.lang.php b/locales/fr/main.lang.php index 955aea0..ebb656f 100644 --- a/locales/fr/main.lang.php +++ b/locales/fr/main.lang.php @@ -210,5 +210,4 @@ $GLOBALS['__l10n']['Key:'] = 'Clé :'; #index.php:401 $GLOBALS['__l10n']['Value:'] = 'Valeur :'; -$GLOBALS['__l10n']['Configuration has been successfully updated.'] = 'La configuration a été mise à jour avec succés.'; - +$GLOBALS['__l10n']['Configuration has been successfully updated.'] = 'La configuration a été mise à jour avec succés.'; \ No newline at end of file