modweblink.class.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 redirect link.
  12. *
  13. * {@inheritdoc}
  14. *
  15. * @package modx
  16. */
  17. class modWebLink extends modResource implements modResourceInterface {
  18. /**
  19. * Overrides modResource::__construct to set the class key for this Resource type
  20. * @param xPDO $xpdo A reference to the xPDO|modX instance
  21. */
  22. function __construct(& $xpdo) {
  23. parent :: __construct($xpdo);
  24. $this->set('type', 'reference');
  25. $this->set('class_key', 'modWebLink');
  26. $this->showInContextMenu = true;
  27. }
  28. /**
  29. * Process the modWebLink and redirect to the specified resource.
  30. */
  31. public function process() {
  32. $this->_content= $this->get('content');
  33. if (empty ($this->_content)) {
  34. $this->xpdo->sendErrorPage();
  35. }
  36. if (!is_numeric($this->_content)) {
  37. $this->xpdo->getParser();
  38. $maxIterations= isset ($this->xpdo->config['parser_max_iterations']) ? intval($this->xpdo->config['parser_max_iterations']) : 10;
  39. $this->xpdo->parser->processElementTags($this->_tag, $this->_content, true, true, '[[', ']]', array(), $maxIterations);
  40. }
  41. if (is_numeric($this->_content)) {
  42. $this->_output= $this->xpdo->makeUrl(intval($this->_content), '', '', 'full');
  43. } else {
  44. $this->_output= $this->_content;
  45. }
  46. $this->xpdo->sendRedirect($this->_output, array('responseCode' => $this->getProperty('responseCode', 'core', $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently')));
  47. }
  48. /**
  49. * Get the full controller path for managing WebLinks in MODX
  50. * @static
  51. * @param xPDO $modx A reference to the modX instance
  52. * @return string The absolute path to the controller for managing WebLinks
  53. */
  54. public static function getControllerPath(xPDO &$modx) {
  55. $path = modResource::getControllerPath($modx);
  56. return $path.'weblink/';
  57. }
  58. /**
  59. * Use this in your extended Resource class to display the text for the context menu item, if showInContextMenu is
  60. * set to true.
  61. * @return array
  62. */
  63. public function getContextMenuText() {
  64. return array(
  65. 'text_create' => $this->xpdo->lexicon('weblink'),
  66. 'text_create_here' => $this->xpdo->lexicon('weblink_create_here'),
  67. );
  68. }
  69. /**
  70. * Use this in your extended Resource class to return a translatable name for the Resource Type.
  71. * @return string
  72. */
  73. public function getResourceTypeName() {
  74. return $this->xpdo->lexicon('weblink');
  75. }
  76. }