Skip to content

Commit 536609d

Browse files
committed
Version 1.4
2 parents 22bdf1a + 3cc71de commit 536609d

4 files changed

Lines changed: 109 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# (MODX)EvolutionCMS.snippets.ddStringTools changelog
22

33

4+
## Version 1.4 (2020-04-19)
5+
* \+ Added the ability to remove placeholders like `[+placeholder+]`.
6+
* \* Refactoring, the `$modx->getConfig` method is used instead of the `$modx->config` field.
7+
* \* README:
8+
* \* Style changes.
9+
* \* Documentation → Parameters description: Small order changes.
10+
* \+ Composer.json → Require.
11+
12+
13+
## Version 1.3 (2019-10-20)
14+
* \* Attention! EvolutionCMS.libraries.ddTools >= 0.27 is required (because not tested in older versions).
15+
* \* Attention! EvolutionCMS.snippets.ddTypograph >= 2.4 is required if the `typography` parameter is used.
16+
* \+ Added the ability to text typography (see the `typography` parameter).
17+
* \+ README → Documentation:
18+
* \+ Installation instructions.
19+
* \+ Parameters description.
20+
* \+ Examples.
21+
* \+ Composer.json.
22+
23+
424
## Version 1.2 (2019-08-09)
525
* \+ Added an ability to parse Markdown (see the `parseMarkdown` parameter).
626

README.md

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,36 @@
33
Tools for modifying strings.
44

55

6-
## # Requires
6+
## Requires
7+
78
* PHP >= 5.4
89
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1
910
* [(MODX)EvolutionCMS.libraries.ddTools](http://code.divandesign.biz/modx/ddtools) >= 0.27
1011
* [(MODX)EvolutionCMS.snippets.ddTypograph](https://code.divandesign.biz/modx/ddtypograph) >= 2.4 (if the `typography` parameter is used)
1112
* [PHP.libraries.Parsedown](https://github.com/erusev/parsedown) >= 1.8.0-beta-7 (contains in archive)
1213

1314

14-
## # Documentation
15+
## Documentation
16+
17+
18+
### Installation
19+
1520

21+
#### 1. Elements → Snippets: Create a new snippet with the following data
1622

17-
### ## Installation
18-
1. Elements → Snippets: Create a new snippet with the following data:
19-
1. Snippet name: `ddStringTools`.
20-
2. Description: `<b>1.3</b> Tools for modifying strings.`.
21-
3. Category: `Core`.
22-
4. Parse DocBlock: `no`.
23-
5. Snippet code (php): Insert content of the `ddStringTools_snippet.php` file from the archive.
24-
2. Elements → Manage Files:
25-
1. Create a new folder `assets/snippets/ddStringTools/`.
26-
2. Extract the archive to the folder (except `ddStringTools_snippet.php`).
23+
1. Snippet name: `ddStringTools`.
24+
2. Description: `<b>1.4</b> Tools for modifying strings.`.
25+
3. Category: `Core`.
26+
4. Parse DocBlock: `no`.
27+
5. Snippet code (php): Insert content of the `ddStringTools_snippet.php` file from the archive.
2728

29+
#### 2. Elements → Manage Files:
2830

29-
### ## Parameters description
31+
1. Create a new folder `assets/snippets/ddStringTools/`.
32+
2. Extract the archive to the folder (except `ddStringTools_snippet.php`).
33+
34+
35+
### Parameters description
3036

3137
* `inputString`
3238
* Desctription: The input string.
@@ -87,8 +93,8 @@ Tools for modifying strings.
8793
* `1`
8894
* Default value: `0`
8995

90-
* `URLEncode`
91-
* Desctription: URL-encode according to RFC 3986.
96+
* `removePlaceholders`
97+
* Desctription: Remove placeholders like `[+placeholder+]`.
9298
* Valid values:
9399
* `0`
94100
* `1`
@@ -100,12 +106,19 @@ Tools for modifying strings.
100106
* `0`
101107
* `1`
102108
* Default value: `0`
109+
110+
* `URLEncode`
111+
* Desctription: URL-encode according to RFC 3986.
112+
* Valid values:
113+
* `0`
114+
* `1`
115+
* Default value: `0`
103116

104117

105-
### ## Examples
118+
### Examples
106119

107120

108-
#### ### Convert characters to lowercase
121+
#### Convert characters to lowercase
109122

110123
```
111124
[[ddStringTools?
@@ -121,7 +134,7 @@ some string with different case
121134
```
122135

123136

124-
#### ### Strip HTML and PHP tags from a string excluding `<p>` и `<a>`
137+
#### Strip HTML and PHP tags from a string excluding `<p>` и `<a>`
125138

126139
```html
127140
[[ddStringTools?
@@ -138,7 +151,7 @@ Returns
138151
```
139152

140153

141-
#### ### Convert special characters to HTML entities
154+
#### Convert special characters to HTML entities
142155

143156
```html
144157
[[ddStringTools?
@@ -154,7 +167,7 @@ Returns
154167
```
155168

156169

157-
#### ### URL-encode according to RFC 3986
170+
#### URL-encode according to RFC 3986
158171

159172
```
160173
[[ddStringTools?
@@ -170,7 +183,7 @@ tags%5B%5D%3DMaps%26tags%5B%5D%3DURLs
170183
```
171184

172185

173-
#### ### Escape special characters for JavaScript
186+
#### Escape special characters for JavaScript
174187

175188
```html
176189
<script>
@@ -193,7 +206,7 @@ Returns
193206
```
194207
195208
196-
#### ### Convert Markdown to HTML
209+
#### Convert Markdown to HTML
197210
198211
```
199212
[[ddStringTools?
@@ -214,7 +227,7 @@ Returns
214227
```
215228
216229
217-
#### ### Typography text with optical alignment
230+
#### Typography text with optical alignment
218231
219232
```html
220233
[[ddStringTools?
@@ -233,4 +246,23 @@ Returns
233246
```
234247
235248
236-
## # [Home page →](http://code.divandesign.biz/modx/ddstringtools)
249+
#### Remove placeholders like `[+placeholder+]`
250+
251+
```html
252+
[[ddStringTools?
253+
&inputString=`Some [+thing+] with [+placeholder1+] and [+placeholder2+].`
254+
&removePlaceholders=`1`
255+
]]
256+
```
257+
258+
Returns
259+
260+
```html
261+
Some with and .
262+
```
263+
264+
265+
## [Home page →](http://code.divandesign.biz/modx/ddstringtools)
266+
267+
268+
<link rel="stylesheet" type="text/css" href="https://DivanDesign.ru/assets/files/ddMarkdown.css" />

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dd/evolutioncms-snippets-ddstringtools",
33
"type": "modxevo-snippet",
4-
"version": "1.3",
4+
"version": "1.4",
55
"description": "Tools for modifying strings.",
66
"keywords": [
77
"modx",
@@ -21,5 +21,10 @@
2121
"escape for js",
2222
"js escaping",
2323
"url encode"
24-
]
24+
],
25+
"require": {
26+
"php": ">=5.4.0",
27+
"dd/modxevo-library-ddtools": ">=0.27",
28+
"dd/modxevo-snippet-ddtypograph": ">=2.4"
29+
}
2530
}

ddStringTools_snippet.php

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
<?php
22
/**
33
* ddStringTools
4-
* @version 1.3 (2019-10-20)
4+
* @version 1.4 (2020-04-19)
55
*
66
* @see README.md
77
*
8-
* @copyright 2016–2019 DivanDesign {@link http://www.DivanDesign.biz }
8+
* @copyright 2016–2020 DivanDesign {@link http://www.DivanDesign.biz }
99
*/
1010

1111
//Include (MODX)EvolutionCMS.libraries.ddTools
12-
require_once($modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php');
12+
require_once(
13+
$modx->getConfig('base_path') .
14+
'assets/libs/ddTools/modx.ddtools.class.php'
15+
);
1316

1417
//Inclide Parsedown lib
15-
require_once($modx->getConfig('base_path') . 'assets/snippets/ddStringTools/src/Parsedown/Parsedown.php');
18+
require_once(
19+
$modx->getConfig('base_path') .
20+
'assets/snippets/ddStringTools/src/Parsedown/Parsedown.php'
21+
);
1622

1723
if (!isset($inputString)){
1824
$inputString = '';
@@ -25,7 +31,7 @@
2531
){
2632
$inputString = mb_strtolower(
2733
$inputString,
28-
$modx->config['modx_charset']
34+
$modx->getConfig('modx_charset')
2935
);
3036
}
3137

@@ -36,7 +42,7 @@
3642
){
3743
$inputString = mb_strtoupper(
3844
$inputString,
39-
$modx->config['modx_charset']
45+
$modx->getConfig('modx_charset')
4046
);
4147
}
4248

@@ -62,7 +68,7 @@
6268
array_merge(
6369
(
6470
isset($typography_params) ?
65-
ddTools::encodedStringToArray($typography_params) :
71+
\ddTools::encodedStringToArray($typography_params) :
6672
[]
6773
),
6874
[
@@ -98,12 +104,24 @@
98104
$inputString = htmlspecialchars($inputString);
99105
}
100106

107+
//Remove placeholders like [+placeholder+]
108+
if (
109+
isset($removePlaceholders) &&
110+
$removePlaceholders == '1'
111+
){
112+
$inputString = preg_replace(
113+
'/(\[\+\S+?\+\])/m',
114+
'',
115+
$inputString
116+
);
117+
}
118+
101119
//Escape special characters for JS
102120
if (
103121
isset($escapeForJS) &&
104122
$escapeForJS == '1'
105123
){
106-
$inputString = ddTools::escapeForJS($inputString);
124+
$inputString = \ddTools::escapeForJS($inputString);
107125
}
108126

109127
//URL-encode according to RFC 3986

0 commit comments

Comments
 (0)