modsymlink.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * A modResource derivative the represents a symbolic link.
  12. *
  13. * {@inheritdoc}
  14. *
  15. * @package modx
  16. * @extends modResource
  17. */
  18. class modSymLink extends modResource implements modResourceInterface {
  19. /**
  20. * Overrides modResource::__construct to set the class key for this Resource type
  21. * @param xPDO $xpdo A reference to the xPDO|modX instance
  22. */
  23. function __construct(xPDO & $xpdo) {
  24. parent :: __construct($xpdo);
  25. $this->set('type', 'reference');
  26. $this->set('class_key', 'modSymLink');
  27. $this->showInContextMenu = true;
  28. }
  29. /**
  30. * Process the modSymLink and forward to the specified resource.
  31. *
  32. * {@inheritDoc}
  33. */
  34. public function process() {
  35. $this->_content= $this->get('content');
  36. if (empty ($this->_content) || $this->get('id') == $this->_content) {
  37. $this->xpdo->sendErrorPage();
  38. }
  39. if (is_numeric($this->_content)) {
  40. $this->_output= intval($this->_content);
  41. } else {
  42. $this->xpdo->getParser();
  43. $maxIterations= intval($this->xpdo->getOption('parser_max_iterations',null,10));
  44. $this->xpdo->parser->processElementTags($this->_tag, $this->_content, true, true, '[[', ']]', array(), $maxIterations);
  45. }
  46. if (is_numeric($this->_content)) {
  47. $this->_output= intval($this->_content);
  48. } else {
  49. $this->_output= $this->_content;
  50. }
  51. $forwardOptions = array('merge' => $this->xpdo->getOption('symlink_merge_fields', null, true));
  52. $this->xpdo->sendForward($this->_output, $forwardOptions);
  53. }
  54. /**
  55. * Gets the manager controller path for the Symlink
  56. * @static
  57. * @param xPDO $modx A reference to the modX instance
  58. * @return string
  59. */
  60. public static function getControllerPath(xPDO &$modx) {
  61. $path = modResource::getControllerPath($modx);
  62. return $path.'symlink/';
  63. }
  64. /**
  65. * Use this in your extended Resource class to display the text for the context menu item, if showInContextMenu is
  66. * set to true.
  67. * @return array
  68. */
  69. public function getContextMenuText() {
  70. return array(
  71. 'text_create' => $this->xpdo->lexicon('symlink'),
  72. 'text_create_here' => $this->xpdo->lexicon('symlink_create_here'),
  73. );
  74. }
  75. /**
  76. * Use this in your extended Resource class to return a translatable name for the Resource Type.
  77. * @return string
  78. */
  79. public function getResourceTypeName() {
  80. return $this->xpdo->lexicon('symlink');
  81. }
  82. }