-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e8295fd
Showing
4 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# (MODX)EvolutionCMS.snippets.ddStash changelog | ||
|
||
|
||
## Version 1.0 (2019-10-31) | ||
* \+ The first release. | ||
|
||
|
||
<style>ul{list-style:none;}</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# (MODX)EvolutionCMS.snippets.ddStash | ||
|
||
Сохранение данных для последующего использования. | ||
|
||
|
||
## # Requires | ||
* PHP >= 5.4 | ||
* [(MODX)EvolutionCMS](https://github.com/evolution-cms/evolution) >= 1.1 | ||
* [(MODX)EvolutionCMS.libraries.ddTools](http://code.divandesign.biz/modx/ddtools) >= 0.28 | ||
|
||
|
||
## # Documentation | ||
|
||
|
||
### ## Installation | ||
|
||
Elements → Snippets: Create a new snippet with the following data: | ||
|
||
1. Snippet name: `ddStash`. | ||
2. Description: `<b>1.0</b> Сохранение данных для последующего использования.`. | ||
3. Category: `Core`. | ||
4. Parse DocBlock: `no`. | ||
5. Snippet code (php): Insert content of the `ddStash_snippet.php` file from the archive. | ||
|
||
|
||
### ## Parameters description | ||
|
||
* `save` | ||
* Desctription: Data to save in stash. Arrays are supported too: `some[a]=one&some[b]=two` => `[+some.a+]`, `[+some.b+]`; `some[]=one&some[]=two` => `[+some.0+]`, `[some.1]`. | ||
* Valid values: | ||
* `stirng_json` — as [JSON](https://en.wikipedia.org/wiki/JSON) | ||
* `string_queryFormated` — as [Query string](https://en.wikipedia.org/wiki/Query_string) | ||
* Default value: — | ||
|
||
* `get` | ||
* Desctription: Data key for getting from stash. | ||
* Valid values: `string` | ||
* Default value: — | ||
|
||
* `get_tpl` | ||
* Desctription: Output template. | ||
Available placeholders: | ||
* `[+snippetResult+]` — Data from stash. | ||
* Valid values: | ||
* `string_chunkName` | ||
* `string` — use inline templates starting with `@CODE:` | ||
* Default value: `'@CODE:[+snippetResult+]'` | ||
|
||
* `storage` | ||
* Desctription: Data storage. | ||
* Valid values: | ||
* `'post'` — `$_POST` | ||
* `'session'` — `$_SESSION` | ||
* Default value: `'post'` | ||
|
||
|
||
### ## Examples | ||
|
||
|
||
#### ### Save some data | ||
|
||
``` | ||
[[ddStash? | ||
&save=`{ | ||
"userData": { | ||
"name": "John", | ||
"photo": "[[ddGetDocumentField? | ||
&docId=`1` | ||
&docField=`photo` | ||
]]" | ||
}, | ||
"someData": "someValue" | ||
}` | ||
]] | ||
``` | ||
|
||
|
||
#### ### Get saved data | ||
|
||
``` | ||
[[ddStash? &get=`userData.name`]] | ||
``` | ||
|
||
Returns `John`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "dd/evolutioncms-snippets-ddstash", | ||
"type": "modxevo-snippet", | ||
"version": "1.0", | ||
"description": "Сохранение данных для последующего использования.", | ||
"keywords": [ | ||
"modx", | ||
"modx evo", | ||
"modx evolution", | ||
"evo", | ||
"evo cms", | ||
"evolution cms", | ||
"ddstash" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* ddStash | ||
* @version 1.0 (2019-10-31) | ||
* | ||
* @see README.md | ||
* | ||
* @copyright 2019 DivanDesign {@link http://www.DivanDesign.biz } | ||
*/ | ||
|
||
//Include (MODX)EvolutionCMS.libraries.ddTools | ||
require_once($modx->getConfig('base_path') . 'assets/libs/ddTools/modx.ddtools.class.php'); | ||
|
||
//The snippet must return an empty string even if result is absent | ||
$snippetResult = ''; | ||
|
||
|
||
//Prepare storage | ||
if (!isset($storage)){ | ||
$storage = 'post'; | ||
} | ||
|
||
switch ($storage){ | ||
case 'session': | ||
$storage = &$_SESSION; | ||
break; | ||
|
||
case 'post': | ||
default: | ||
$storage = &$_POST; | ||
break; | ||
} | ||
|
||
|
||
//Save to stash | ||
if (isset($save)){ | ||
$save = \ddTools::unfoldArray(\ddTools::encodedStringToArray($save)); | ||
|
||
foreach ( | ||
$save as | ||
$dataName => | ||
$dataValue | ||
){ | ||
$storage['ddStash.' . $dataName] = $dataValue; | ||
} | ||
} | ||
|
||
|
||
//Get from stash | ||
if ( | ||
isset($get) && | ||
isset($storage['ddStash.' . $get]) | ||
){ | ||
$snippetResult = $storage['ddStash.' . $get]; | ||
|
||
if ( | ||
//If template is used | ||
isset($get_tpl) && | ||
//And result is not empty | ||
!empty($snippetResult) | ||
){ | ||
$snippetResult = \ddTools::parseText([ | ||
'text' => $modx->getTpl($get_tpl), | ||
'data' => [ | ||
'snippetResult' => $snippetResult | ||
] | ||
]); | ||
} | ||
} | ||
|
||
|
||
return $snippetResult; | ||
?> |