preserved.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php return array (
  2. 'f260ccebd457d433ccc7744e23c9bdfb' =>
  3. array (
  4. 'criteria' =>
  5. array (
  6. 'name' => 'personalize',
  7. ),
  8. 'object' =>
  9. array (
  10. 'name' => 'personalize',
  11. 'path' => '{core_path}components/personalize/',
  12. 'assets_path' => '',
  13. ),
  14. ),
  15. '0899ec3ea44ef23cf61ab453f6477ef2' =>
  16. array (
  17. 'criteria' =>
  18. array (
  19. 'category' => 'personalize',
  20. ),
  21. 'object' =>
  22. array (
  23. 'id' => 9,
  24. 'parent' => 0,
  25. 'category' => 'personalize',
  26. 'rank' => 0,
  27. ),
  28. ),
  29. 'b65ea24db98ebfeaffae6b3580149f14' =>
  30. array (
  31. 'criteria' =>
  32. array (
  33. 'name' => 'Personalize',
  34. ),
  35. 'object' =>
  36. array (
  37. 'id' => 27,
  38. 'source' => 0,
  39. 'property_preprocess' => 0,
  40. 'name' => 'Personalize',
  41. 'description' => 'Snippet to show different chunks to logged-in- and not-logged-in users.',
  42. 'editor_type' => 0,
  43. 'category' => 9,
  44. 'cache_type' => 0,
  45. 'snippet' => '/**
  46. * Personalize snippet for MODx Revolution
  47. *
  48. * Personalize is free software; you can redistribute it and/or modify it
  49. * under the terms of the GNU General Public License as published by the Free
  50. * Software Foundation; either version 2 of the License, or (at your option) any
  51. * later version.
  52. *
  53. * Personalize is distributed in the hope that it will be useful, but WITHOUT ANY
  54. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  55. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  56. *
  57. * You should have received a copy of the GNU General Public License along with
  58. * Personalize; if not, write to the Free Software Foundation, Inc., 59 Temple
  59. * Place, Suite 330, Boston, MA 02111-1307 USA
  60. *
  61. * @package personalize
  62. */
  63. /**
  64. * MODx Personalize Snippet
  65. *
  66. *
  67. * @package personalize
  68. *
  69. * Properties
  70. *
  71. * @property yesChunk string (REQUIRED) Name of chunk or
  72. * inline HTML to show for LOGGED-in users
  73. *
  74. * @property noChunk string (optional) Name of chunk or
  75. * inline HTML to show for NOT logged-in users
  76. *
  77. * @property ph string (optional) Placeholder for placing
  78. * the username
  79. * ATTENTION!: ph placeholder will *not* be set in noChunk!
  80. *
  81. * @property fullName boolean (optional) Use full name
  82. * instead of username in placeholder
  83. *
  84. * @property ifIds string (optional) comma separated
  85. * list of users ids; yesChunk will only be shown
  86. * to users in the list
  87. *
  88. * @property allowedGroups string (optional) comma separated
  89. * list of allowed groups; yesChunk will only only shows
  90. * users are in one of these groups
  91. *
  92. * @property context (optional) context the user must be
  93. * logged in to to see the yesChunk; defaults to
  94. * current context.
  95. *
  96. *
  97. */
  98. /* Personalize Snippet for Revolution */
  99. /* ::::::::::::::::::::::::::::::::::::::::
  100. * Snippet Name: Personalize
  101. * Short Desc: returns a chunk if the user is logged in, otherwise calls another
  102. *::::::::::::::::::::::::::::::::::::::::
  103. * Description:
  104. * Checks to see if users are logged in and displays yesChunk if the user
  105. * is logged or noChunk if user is not logged. Insert only the chunk name as
  106. * param, without any tags. Can use a placeholder to output the username.
  107. *
  108. * TESTED: can be used more than once per page.
  109. * TESTED: chunks can contain snippets.
  110. *
  111. * Example Usage:
  112. *
  113. * [[!Personalize?
  114. * &yesChunk=`HelloUser`
  115. * &noChunk=`Register`
  116. * &ph=`name`
  117. * ]]
  118. *
  119. * Create Chunks named HelloUser and Register, the first will be
  120. * shown to a user logged on in the current context,
  121. * the second to other users.
  122. *
  123. * ADDED in 3.3.1 by Vasia123:
  124. *
  125. * 1. &noChunk=`@CODE:<b>Please login!</b>` - inline snippets
  126. * 2. &ifIds=`1,3` - additional check for users ids. yesChunk will
  127. * only be shown to logged-in users in the list.
  128. *
  129. * ADDED in 3.6.0 by Vasia123:
  130. *
  131. * 1. &allowedGroups=`Editor,Administrator` - check if user is
  132. * in any allowed group
  133. *
  134. *
  135. * Placeholder [[+name]] will show the user\'s name in the yesChunk or
  136. * elsewhere on the page.
  137. *
  138. *
  139. *:::::::::::::::::::::::::::::::::::::::: */
  140. /* @var $modx modX */
  141. /* @var $profile modUserProfile */
  142. /* Prepare params and variables */
  143. $output = \'\';
  144. $sp =& $scriptProperties;
  145. $yesChunk = $modx->getOption(\'yesChunk\',$sp, null);
  146. $noChunk = $modx->getOption(\'noChunk\',$scriptProperties, null);
  147. $fullName = (bool) $modx->getOption(\'fullName\', $sp, false);
  148. $firstName = (bool) $modx->getOption(\'firstName\', $sp, false);
  149. $ph = $modx->getOption(\'ph\',$sp, null);
  150. $ifIds = $modx->getOption(\'ifIds\',$sp, null);
  151. $allowedGroups = $modx->getOption(\'allowedGroups\',$sp, null);
  152. $context = $modx->getOption(\'context\', $sp, $modx->context->get(\'key\') );
  153. if( $fullName || $firstName ) {
  154. $profile = $modx->user->getOne(\'Profile\');
  155. }
  156. /* check if user logged in */
  157. $is_logged_in = $modx->user->hasSessionContext($context);
  158. /* Set $ifIds to true if user id is allowed or ifIds is not set */
  159. $ifIds = array_filter(array_map(\'trim\',explode(\',\',$ifIds)));
  160. $ifIds = (!empty($ifIds)) ? in_array($modx->user->get(\'id\'), $ifIds) : true;
  161. // Set $groups to true is use in in allowed group or $groups is not set
  162. $groups = array_filter(array_map(\'trim\',explode(\',\',$allowedGroups)));
  163. if (!empty($groups)) {
  164. $inGroups = false;
  165. foreach($groups as $group) {
  166. if ($modx->user->isMember($group)) $inGroups = true;
  167. }
  168. } else {
  169. $inGroups = true;
  170. }
  171. /* Do the work */
  172. if ($is_logged_in && $ifIds && $inGroups) {
  173. if (preg_match(\'/^@CODE:/\',$yesChunk)) {
  174. $output = substr($yesChunk, 6);
  175. } else {
  176. $output = $modx->getChunk($yesChunk, $scriptProperties);
  177. }
  178. if (! empty($ph)) {
  179. if ($fullName && $profile) {
  180. $name = trim($profile->get(\'fullname\'));
  181. } elseif ($firstName && $profile) {
  182. $full = trim($profile->get(\'fullname\'));
  183. $pos = strpos($full, \' \');
  184. $name = ($pos === false) ? $full : substr($full, 0, $pos);
  185. } else {
  186. $name = $modx->user->get(\'username\');
  187. }
  188. $modx->setPlaceholder($ph, $name);
  189. }
  190. } elseif( !empty ($noChunk) ) {
  191. if (preg_match(\'/^@CODE:/\',$noChunk)) {
  192. $output = substr($noChunk, 6);
  193. } else {
  194. $output = $modx->getChunk($noChunk);
  195. }
  196. }
  197. return empty($output)? \'\': $output;',
  198. 'locked' => 0,
  199. 'properties' => 'a:6:{s:8:"yesChunk";a:7:{s:4:"name";s:8:"yesChunk";s:4:"desc";s:25:"personalize_yeschunk_desc";s:4:"type";s:9:"textfield";s:7:"options";s:0:"";s:5:"value";s:0:"";s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}s:7:"noChunk";a:7:{s:4:"name";s:7:"noChunk";s:4:"desc";s:24:"personalize_nochunk_desc";s:4:"type";s:9:"textfield";s:7:"options";s:0:"";s:5:"value";s:0:"";s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}s:2:"ph";a:7:{s:4:"name";s:2:"ph";s:4:"desc";s:19:"personalize_ph_desc";s:4:"type";s:9:"textfield";s:7:"options";s:0:"";s:5:"value";s:0:"";s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}s:8:"fullName";a:7:{s:4:"name";s:8:"fullName";s:4:"desc";s:25:"personalize_fullname_desc";s:4:"type";s:13:"combo-boolean";s:7:"options";s:0:"";s:5:"value";b:0;s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}s:9:"firstName";a:7:{s:4:"name";s:9:"firstName";s:4:"desc";s:26:"personalize_firstname_desc";s:4:"type";s:13:"combo-boolean";s:7:"options";s:0:"";s:5:"value";b:0;s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}s:5:"ifIds";a:7:{s:4:"name";s:5:"ifIds";s:4:"desc";s:22:"personalize_ifIds_desc";s:4:"type";s:9:"textfield";s:7:"options";s:0:"";s:5:"value";s:0:"";s:7:"lexicon";s:22:"personalize:properties";s:4:"area";s:0:"";}}',
  200. 'moduleguid' => '',
  201. 'static' => 0,
  202. 'static_file' => '',
  203. 'content' => '/**
  204. * Personalize snippet for MODx Revolution
  205. *
  206. * Personalize is free software; you can redistribute it and/or modify it
  207. * under the terms of the GNU General Public License as published by the Free
  208. * Software Foundation; either version 2 of the License, or (at your option) any
  209. * later version.
  210. *
  211. * Personalize is distributed in the hope that it will be useful, but WITHOUT ANY
  212. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  213. * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  214. *
  215. * You should have received a copy of the GNU General Public License along with
  216. * Personalize; if not, write to the Free Software Foundation, Inc., 59 Temple
  217. * Place, Suite 330, Boston, MA 02111-1307 USA
  218. *
  219. * @package personalize
  220. */
  221. /**
  222. * MODx Personalize Snippet
  223. *
  224. *
  225. * @package personalize
  226. *
  227. * Properties
  228. *
  229. * @property yesChunk string (REQUIRED) Name of chunk or
  230. * inline HTML to show for LOGGED-in users
  231. *
  232. * @property noChunk string (optional) Name of chunk or
  233. * inline HTML to show for NOT logged-in users
  234. *
  235. * @property ph string (optional) Placeholder for placing
  236. * the username
  237. * ATTENTION!: ph placeholder will *not* be set in noChunk!
  238. *
  239. * @property fullName boolean (optional) Use full name
  240. * instead of username in placeholder
  241. *
  242. * @property ifIds string (optional) comma separated
  243. * list of users ids; yesChunk will only be shown
  244. * to users in the list
  245. *
  246. * @property allowedGroups string (optional) comma separated
  247. * list of allowed groups; yesChunk will only only shows
  248. * users are in one of these groups
  249. *
  250. * @property context (optional) context the user must be
  251. * logged in to to see the yesChunk; defaults to
  252. * current context.
  253. *
  254. *
  255. */
  256. /* Personalize Snippet for Revolution */
  257. /* ::::::::::::::::::::::::::::::::::::::::
  258. * Snippet Name: Personalize
  259. * Short Desc: returns a chunk if the user is logged in, otherwise calls another
  260. *::::::::::::::::::::::::::::::::::::::::
  261. * Description:
  262. * Checks to see if users are logged in and displays yesChunk if the user
  263. * is logged or noChunk if user is not logged. Insert only the chunk name as
  264. * param, without any tags. Can use a placeholder to output the username.
  265. *
  266. * TESTED: can be used more than once per page.
  267. * TESTED: chunks can contain snippets.
  268. *
  269. * Example Usage:
  270. *
  271. * [[!Personalize?
  272. * &yesChunk=`HelloUser`
  273. * &noChunk=`Register`
  274. * &ph=`name`
  275. * ]]
  276. *
  277. * Create Chunks named HelloUser and Register, the first will be
  278. * shown to a user logged on in the current context,
  279. * the second to other users.
  280. *
  281. * ADDED in 3.3.1 by Vasia123:
  282. *
  283. * 1. &noChunk=`@CODE:<b>Please login!</b>` - inline snippets
  284. * 2. &ifIds=`1,3` - additional check for users ids. yesChunk will
  285. * only be shown to logged-in users in the list.
  286. *
  287. * ADDED in 3.6.0 by Vasia123:
  288. *
  289. * 1. &allowedGroups=`Editor,Administrator` - check if user is
  290. * in any allowed group
  291. *
  292. *
  293. * Placeholder [[+name]] will show the user\'s name in the yesChunk or
  294. * elsewhere on the page.
  295. *
  296. *
  297. *:::::::::::::::::::::::::::::::::::::::: */
  298. /* @var $modx modX */
  299. /* @var $profile modUserProfile */
  300. /* Prepare params and variables */
  301. $output = \'\';
  302. $sp =& $scriptProperties;
  303. $yesChunk = $modx->getOption(\'yesChunk\',$sp, null);
  304. $noChunk = $modx->getOption(\'noChunk\',$scriptProperties, null);
  305. $fullName = (bool) $modx->getOption(\'fullName\', $sp, false);
  306. $firstName = (bool) $modx->getOption(\'firstName\', $sp, false);
  307. $ph = $modx->getOption(\'ph\',$sp, null);
  308. $ifIds = $modx->getOption(\'ifIds\',$sp, null);
  309. $allowedGroups = $modx->getOption(\'allowedGroups\',$sp, null);
  310. $context = $modx->getOption(\'context\', $sp, $modx->context->get(\'key\') );
  311. if( $fullName || $firstName ) {
  312. $profile = $modx->user->getOne(\'Profile\');
  313. }
  314. /* check if user logged in */
  315. $is_logged_in = $modx->user->hasSessionContext($context);
  316. /* Set $ifIds to true if user id is allowed or ifIds is not set */
  317. $ifIds = array_filter(array_map(\'trim\',explode(\',\',$ifIds)));
  318. $ifIds = (!empty($ifIds)) ? in_array($modx->user->get(\'id\'), $ifIds) : true;
  319. // Set $groups to true is use in in allowed group or $groups is not set
  320. $groups = array_filter(array_map(\'trim\',explode(\',\',$allowedGroups)));
  321. if (!empty($groups)) {
  322. $inGroups = false;
  323. foreach($groups as $group) {
  324. if ($modx->user->isMember($group)) $inGroups = true;
  325. }
  326. } else {
  327. $inGroups = true;
  328. }
  329. /* Do the work */
  330. if ($is_logged_in && $ifIds && $inGroups) {
  331. if (preg_match(\'/^@CODE:/\',$yesChunk)) {
  332. $output = substr($yesChunk, 6);
  333. } else {
  334. $output = $modx->getChunk($yesChunk, $scriptProperties);
  335. }
  336. if (! empty($ph)) {
  337. if ($fullName && $profile) {
  338. $name = trim($profile->get(\'fullname\'));
  339. } elseif ($firstName && $profile) {
  340. $full = trim($profile->get(\'fullname\'));
  341. $pos = strpos($full, \' \');
  342. $name = ($pos === false) ? $full : substr($full, 0, $pos);
  343. } else {
  344. $name = $modx->user->get(\'username\');
  345. }
  346. $modx->setPlaceholder($ph, $name);
  347. }
  348. } elseif( !empty ($noChunk) ) {
  349. if (preg_match(\'/^@CODE:/\',$noChunk)) {
  350. $output = substr($noChunk, 6);
  351. } else {
  352. $output = $modx->getChunk($noChunk);
  353. }
  354. }
  355. return empty($output)? \'\': $output;',
  356. ),
  357. ),
  358. );