Download the PHP package dd/evolutioncms-snippets-ddstringtools without Composer
On this page you can find all versions of the php package dd/evolutioncms-snippets-ddstringtools. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dd/evolutioncms-snippets-ddstringtools
More information about dd/evolutioncms-snippets-ddstringtools
Files in dd/evolutioncms-snippets-ddstringtools
Package evolutioncms-snippets-ddstringtools
Short Description Tools for modifying strings.
License
Homepage https://code.divandesign.ru/modx/ddstringtools
Informations about the package evolutioncms-snippets-ddstringtools
(MODX)EvolutionCMS.snippets.ddStringTools
Tools for modifying strings.
Requires
- PHP >= 5.6
- (MODX)EvolutionCMS >= 1.1
- (MODX)EvolutionCMS.libraries.ddTools >= 0.60
- (MODX)EvolutionCMS.snippets.ddtypograph >= 2.6 (if the
tools->typographer
parameter is used) - PHP.libraries.Parsedown >= 1.8.0-beta-7 (contains in archive)
Installation
Using (MODX)EvolutionCMS.libraries.ddInstaller
Just run the following PHP code in your sources or Console:
- If
ddStringTools
is not exist on your site,ddInstaller
will just install it. - If
ddStringTools
is already exist on your site,ddInstaller
will check it version and update it if needed.
Manually
1. Elements → Snippets: Create a new snippet with the following data
- Snippet name:
ddStringTools
. - Description:
<b>2.1</b> Tools for modifying strings.
. - Category:
Core
. - Parse DocBlock:
no
. - Snippet code (php): Insert content of the
ddStringTools_snippet.php
file from the archive.
2. Elements → Manage Files:
- Create a new folder
assets/snippets/ddStringTools/
. - Extract the archive to the folder (except
ddStringTools_snippet.php
).
Parameters description
-
inputString
- Desctription: The input string.
- Valid values:
string
- The input string can also be set as a PHP object or array (e. g. for calls through
$modx->runSnippet
). In this case, it will be converted to JSON first.object
array
- Default value:
''
-
tools
- Desctription: List of string tools to be applied to
inputString
. Tools are called in accordance with the specified order. - Valid values:
stirngJsonObject
— as JSONstringHjsonObject
— as HJSONstringQueryFormated
— as Query string- It can also be set as a PHP object or array (e. g. for calls through
$modx->runSnippet
).arrayAssociative
object
- Default value:
'{}'
- Desctription: List of string tools to be applied to
tools->{$toolName}
- Desctription: A tool, when the key is the tool name and the value is the tool parameters.
Tool names are case insensitive (the following names are equal:caseConverter
,Caseconverter
,caseconverter
, etc). - Valid values:
object
— an object with tool parameters (see below)boolean
— for simple tools without parameters or if you need to use default parameters (if possible), just passtrue
- Default value: —.
- Desctription: A tool, when the key is the tool name and the value is the tool parameters.
Case converter
-
tools->caseConverter
- Desctription: Perform case folding on a string. Unicode is supported.
- Valid values:
object
- Default value: —.
-
tools->caseConverter->toLower
- Desctription: Make a string lowercase.
- Valid values:
boolean
- Default value:
false
tools->caseConverter->toUpper
- Desctription: Make a string uppercase.
- Valid values:
boolean
- Default value:
false
Markdown parser
-
tools->markdownParser
- Desctription: Parse Markdown using Parsedown library.
- Valid values:
boolean
— if you need to parse with default params, just passtrue
object
— or an object with parameters (see below)
- Default value:
false
tools->markdownParser->parseInline
- Desctription: Parse only inline elements.
- Valid values:
boolean
- Default value:
false
Typographer
-
tools->typographer
- Desctription: Typography text using EvolutionCMS.snippets.ddTypograph.
Parameters have to be passed to EvolutionCMS.snippets.ddTypograph. More info in its documentation. - Valid values:
boolean
— if you need to typography with default params, just passtrue
object
— or an object with parameters (see below)
- Default value:
false
- Desctription: Typography text using EvolutionCMS.snippets.ddTypograph.
-
tools->typographer->optAlign
- Desctription: Optical alignment (hanging punctuation).
- Valid values:
boolean
- Default value:
false
-
tools->typographer->optAlign_useClasses
-
Desctription: Use CSS classes instead of inline styles for optical alignment (
<span class="oa_comma_b">
instead of<span style="margin-right:-0.2em;">
).
If the parameter is enabled, don't forget to specify the following CSS rules on your site: - Valid values:
0
1
- Default value:
0
-
-
tools->typographer->text_paragraphs
- Desctription: Section signs and line breaks insertion.
- Valid values:
boolean
- Default value:
false
-
tools->typographer->text_autoLinks
- Desctription: Marking links (including email ones).
- Valid values:
boolean
- Default value:
false
-
tools->typographer->etc_unicodeConvert
- Desctription: Convert HTML entities into Unicode (
—
instead of—
, etc). - Valid values:
boolean
- Default value:
true
- Desctription: Convert HTML entities into Unicode (
-
tools->typographer->noTags
- Desctription: Whether HTML element insertion is allowed or not.
There are cases when using tags causes the text to be invalid, for example, using the snippet inside of an HTML attribute. - Valid values:
boolean
- Default value:
false
- Desctription: Whether HTML element insertion is allowed or not.
tools->typographer->excludeTags
- Desctription: HTML tags which content will be ignored by snippet.
- Valid values:
stringCommaSeparated
- Default value:
'notg,code'
Tag remover
-
tools->tagRemover
- Desctription: Strip HTML and PHP tags from a string.
- Valid values:
boolean
— if you need to remove all tags, just passtrue
object
— or an object with parameters (see below)
- Default value:
false
tools->tagRemover->allowed
- Desctription: Use the parameter to specify tags which should not be stripped (e. g.
<p><div>
). - Valid values:
string
- Default value:
''
- Desctription: Use the parameter to specify tags which should not be stripped (e. g.
Special char converter
tools->specialCharConverter
- Desctription: Convert special characters to HTML entities.
- Valid values:
boolean
- Default value:
false
Chars escaper (e. g. for JS)
-
tools->charEscaper
- Desctription: Escape special characters for JS.
- Valid values:
boolean
— if you need to escape with default params, just passtrue
object
— or an object with parameters (see below)
- Default value:
false
-
tools->charEscaper->backslashes
- Desctription: Escape backslashes (
'\\'
will be replaced to'\\\\'
). - Valid values:
boolean
- Default value:
true
- Desctription: Escape backslashes (
-
tools->charEscaper->lineBreaks
- Desctription: Escape line breaks (
"\r\n"
,"\r"
,"\n"
will be replaced to'\r\n'
). - Valid values:
boolean
- Default value:
true
- Desctription: Escape line breaks (
-
tools->charEscaper->tabs
- Desctription: Escape tabs (
' '
(tab) will be replaced to' '
(space)). - Valid values:
boolean
- Default value:
true
- Desctription: Escape tabs (
-
tools->charEscaper->modxPlaceholders
- Desctription: Escape (MODX)EvolutionCMS placeholders (
'[+'
and'+]'
will be replaced to'\[\+'
and'\+\]'
). - Valid values:
boolean
- Default value:
true
- Desctription: Escape (MODX)EvolutionCMS placeholders (
tools->charEscaper->quotes
- Desctription: Escape quotes (
"'"
and'"'
will be replaced to"\'"
and'\"'
). - Valid values:
boolean
- Default value:
true
- Desctription: Escape quotes (
URL encoder
tools->urlEncoder
- Desctription: URL-encode according to RFC 3986.
- Valid values:
boolean
- Default value:
false
Placeholder remover
tools->placeholderRemover
- Desctription: Remove placeholders like
[+placeholder+]
. - Valid values:
boolean
- Default value:
false
- Desctription: Remove placeholders like
Preg replacer
-
tools->pregReplacer
- Desctription: Perform a regular expression search and replace.
- Valid values:
object
- Default value: —
-
tools->pregReplacer->pattern
- Desctription: The pattern to search for.
- Valid values:
string
- Required
tools->pregReplacer->replacement
- Desctription: The string to replace.
- Valid values:
string
- Default value:
''
Tpl parser
-
tools->tplParser
- Desctription: Gets the chunk contents by its name and parse it.
IfinputString
is empty, the chunk content will not be returned, just an empty string. - Valid values:
object
- Default value: —
- Desctription: Gets the chunk contents by its name and parse it.
-
tools->tplParser->tpl
- Desctription: Chunk name or code via
@CODE:
prefix.
Available placeholders:[+snippetResult+]
— theinputString
modified by previous tools
- Valid values:
stringChunkName
string
— use inline templates starting with@CODE:
- Required
- Desctription: Chunk name or code via
tools->tplParser->placeholders
- Desctription:
Additional data has to be passed into the
tools->tplParser->tpl
.
Nested objects and arrays are supported too:{"someOne": "1", "someTwo": "test" }
=>[+someOne+], [+someTwo+]
.{"some": {"a": "one", "b": "two"} }
=>[+some.a+]
,[+some.b+]
.{"some": ["one", "two"] }
=>[+some.0+]
,[+some.1+]
.
- Valid values:
object
- Default value: —
- Desctription:
Additional data has to be passed into the
Examples
Convert characters to lowercase (tools->caseConverter->toLower
)
Returns:
Strip HTML and PHP tags from a string (tools->tagRemover
)
Remove all tags completely
Returns:
Remove all tags except <p>
and <a>
(tools->tagRemover->allowed
)
If you want to preserve some tags, pass an object with property allowed
instead of true
.
Returns:
Convert special characters to HTML entities (tools->specialCharConverter
)
Returns:
URL-encode according to RFC 3986 (tools->urlEncoder
)
Returns:
Escape special characters for JavaScript (tools->charEscaper
)
Returns:
Convert Markdown to HTML (tools->markdownParser
)
Returns:
You can also parse inline markdown only (tools->markdownParser->parseInline
)
Returns:
Typography text (tools->typographer
)
With optical alignment (tools->typographer->optAlign
)
Returns:
Simple call with default parameters
Remove placeholders like [+placeholder+]
(tools->placeholderRemover
)
Returns:
Thumbnail suffix (tools->pregReplacer
)
Returns:
Get the chunk content and pass some placeholders (tools->tplParser
)
Returns:
Use multiple tools together
Tools are called in accordance with the specified order:
- First placeholders like
[+somePlaceholder+]
will removed, then - Text will typographied,
- All HTML tags except
<p>
and<a>
will removed, - Text will converted to lowercase,
- And escaped for JS.
Pass inputString
as an array through $modx->runSnippet
The input string can also be set as a PHP object or array (e. g. for calls through $modx->runSnippet
).
In this case, it will be converted to JSON first.
Returns:
Run the snippet through \DDTools\Snippet::runSnippet
without DB and eval
Links
All versions of evolutioncms-snippets-ddstringtools with dependencies
dd/evolutioncms-libraries-ddtools Version >=0.60.0
dd/evolutioncms-snippets-ddtypograph Version >=2.6.0