Skip to content

Commit

Permalink
Version 0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilyas Ronef committed Jul 6, 2017
2 parents 547627b + d952cfb commit e9b1b8d
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions modx.ddtools.class.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php
/**
* MODXEvo.library.ddTools
* @version 0.19 (2017-05-28)
* @version 0.20 (2017-07-06)
*
* @uses PHP >= 5.4.
* @uses MODXEvo >= 1.0.10.
*
* @link http://code.divandesign.biz/modx/ddtools/0.19
* @link http://code.divandesign.biz/modx/ddtools/0.20
*
* @copyright 2012–2017 DivanDesign {@link http://www.DivanDesign.biz }
*/
Expand Down Expand Up @@ -389,7 +389,6 @@ public static function generateRandomString($length = 8, $chars = 'abcdefghijklm
return $string;
}


/**
* screening
* @deprecated Use ddTools::escapeForJS.
Expand All @@ -404,7 +403,7 @@ public static function screening($str){

/**
* escapingForJS
* @version 1.1 (2017-05-24)
* @version 1.1.1 (2017-07-06)
*
* @desc Escaping chars in string for JS.
*
Expand All @@ -413,6 +412,8 @@ public static function screening($str){
* @return {string}
*/
public static function escapeForJS($str){
//Backslach escaping (see issue #1)
$str = str_replace('\\', '\\\\', $str);
//Line breaks
$str = str_replace("\r\n", ' ', $str);
$str = str_replace("\n", ' ', $str);
Expand All @@ -426,8 +427,6 @@ public static function escapeForJS($str){
//Quotes
$str = str_replace("'", "\'", $str);
$str = str_replace('"', '\"', $str);
//Backslach escaping (see issue #1)
$str = str_replace('\\', '\\\\', $str);

return $str;
}
Expand Down Expand Up @@ -475,6 +474,43 @@ public static function encodedStringToArray($inputString){

return $result;
}

/**
* getPlaceholdersFromText
* @version 1.0 (2017-07-06)
*
* @desc Finds all placeholders' names and returns them as an array.
*
* @param $params {array_associative|stdClass} — The object of params. @required
* @param $params['text'] {string} — Source string. @required
* @param $params['placeholderPrefix'] {string} — Placeholders prefix. Default: '[+'.
* @param $params['placeholderSuffix'] {string} — Placeholders suffix. Default: '+]'.
*
* @return {array}
*/
public static function getPlaceholdersFromText($params = []){
//Defaults
$params = (object) array_merge([
'text' => '',
'placeholderPrefix' => '[+',
'placeholderSuffix' => '+]'
], (array) $params);

$params->placeholderPrefix = preg_quote($params->placeholderPrefix);
$params->placeholderSuffix = preg_quote($params->placeholderSuffix);

$result = [];

preg_match_all(
'/'.$params->placeholderPrefix.'(.*?)'.$params->placeholderSuffix.'/',
$params->text,
$result
);

$result = array_unique($result[1]);

return $result;
}

/**
* logEvent
Expand Down

0 comments on commit e9b1b8d

Please sign in to comment.