Guest User

Untitled

a guest
Jun 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. <?php
  2. $output = '';
  3.  
  4. $properties =& $scriptProperties;
  5. $properties['element'] = empty($element) ? '' : $element;
  6. $properties['elementClass'] = empty($elementClass) ? 'modChunk' : $elementClass;
  7. $properties[xPDO::OPT_CACHE_KEY] = $modx->getOption('cache_resource_key', $properties, 'default');
  8. $properties[xPDO::OPT_CACHE_HANDLER] = $modx->getOption('cache_resource_handler', $properties, 'xPDOFileCache');
  9. $properties[xPDO::OPT_CACHE_EXPIRES] = (integer) $modx->getOption(xPDO::OPT_CACHE_EXPIRES, $properties, 0);
  10. $properties['cacheElementKey'] = $modx->resource->getCacheKey() . '/' . md5($modx->toJSON($properties)) . '/' . md5(implode('', $modx->request->getParameters()));
  11. $properties['cacheOptions'] = array(
  12. xPDO::OPT_CACHE_KEY => $properties[xPDO::OPT_CACHE_KEY],
  13. xPDO::OPT_CACHE_HANDLER => $properties[xPDO::OPT_CACHE_HANDLER],
  14. xPDO::OPT_CACHE_EXPIRES => $properties[xPDO::OPT_CACHE_EXPIRES],
  15. );
  16.  
  17. $cached = false;
  18. if ($properties['cache']) {
  19. if ($modx->getCacheManager()) {
  20. $cached = $modx->cacheManager->get($properties['cacheElementKey'], $properties['cacheOptions']);
  21. }
  22. }
  23. if (!isset($cached['properties']) || !isset($cached['output'])) {
  24. $elementObj = $modx->getObject($properties['elementClass'], array('name' => $properties['element']));
  25. if ($elementObj) {
  26. $elementObj->setCacheable(false);
  27. if (!empty($properties['toPlaceholder'])) {
  28. $elementObj->process($properties);
  29. $output = $modx->getPlaceholder($properties['toPlaceholder']);
  30. } else {
  31. $output = $elementObj->process($properties);
  32. }
  33. }
  34.  
  35. if ($modx->getCacheManager()) {
  36. $cached = array('properties' => $properties, 'output' => $output);
  37. $modx->cacheManager->set($properties['cacheElementKey'], $cached, $properties[xPDO::OPT_CACHE_EXPIRES], $properties['cacheOptions']);
  38. }
  39. } else {
  40. $properties = $cached['properties'];
  41. $output = $cached['output'];
  42. }
  43. $modx->setPlaceholders($properties, $properties['namespace']);
  44. if (!empty($properties['toPlaceholder'])) {
  45. $modx->setPlaceholder($properties['toPlaceholder'], $output);
  46. $output = '';
  47. }
  48.  
  49. return $output;
  50. ?>
Add Comment
Please, Sign In to add comment