modactiondom.class.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. * Adds custom manager adjustments based upon modAction objects
  12. *
  13. * @property int $set The modFormCustomizationSet this rule belongs to
  14. * @property int $action The modAction this rule occurs on
  15. * @property string $name The field this rule applies to
  16. * @property string $description A description of this rule, or alternate text
  17. * @property string $container The containing object the rule applies to
  18. * @property string $rule The type of rule
  19. * @property string $value The value stored for this rule
  20. * @property boolean $for_parent Whether or not to apply this rule to the parent object in question
  21. * @property int $rank The rank in which this rule should be applied
  22. *
  23. * @see modFormCustomizationSet
  24. * @package modx
  25. */
  26. class modActionDom extends modAccessibleSimpleObject {
  27. /**
  28. * Apply the rule to the current page.
  29. *
  30. * @access public
  31. * @param int|string $objId The PK of the object that the rule is being applied to.
  32. * @return string The generated code that applies the rule.
  33. */
  34. public function apply($objId = '') {
  35. $rule = '';
  36. $encoding = $this->xpdo->getOption('modx_charset',null,'UTF-8');
  37. /* now switch by types of rules */
  38. switch ($this->get('rule')) {
  39. case 'fieldVisible':
  40. if (!$this->get('value')) {
  41. $fields = explode(',',$this->get('name'));
  42. $rule = 'MODx.hideField("'.$this->get('container').'",'.$this->xpdo->toJSON($fields).');';
  43. }
  44. break;
  45. case 'fieldLabel':
  46. case 'fieldTitle':
  47. $fields = explode(',',$this->get('name'));
  48. $values = explode(',',$this->get('value'));
  49. foreach ($values as &$value) {
  50. $value = htmlspecialchars($value,ENT_COMPAT,$encoding);
  51. }
  52. $rule = 'MODx.renameLabel("'.$this->get('container').'",'.$this->xpdo->toJSON($fields).','.$this->xpdo->toJSON($values).');';
  53. break;
  54. case 'panelTitle':
  55. case 'tabTitle':
  56. case 'tabLabel':
  57. $rule = 'MODx.renameTab("'.$this->get('name').'","'.htmlspecialchars($this->get('value'),ENT_COMPAT,$encoding).'");';
  58. break;
  59. case 'tabVisible':
  60. if (!$this->get('value')) {
  61. $tabs = explode(',',$this->get('name'));
  62. $rule = '';
  63. foreach ($tabs as $tab) {
  64. $tab = trim($tab);
  65. $rule .= 'MODx.hideRegion("'.$this->get('container').'","'.$tab.'");';
  66. }
  67. }
  68. break;
  69. case 'tabNew':
  70. $title = $this->get('value');
  71. $rule = 'MODx.addTab("'.$this->get('container').'",{title:"'.htmlspecialchars($title,ENT_COMPAT,$encoding).'",id:"'.$this->get('name').'"});';
  72. break;
  73. case 'tvMove':
  74. $tvs = explode(',',$this->get('name'));
  75. $rule = 'MODx.moveTV('.$this->xpdo->toJSON($tvs).',"'.$this->get('value').'");';
  76. break;
  77. default: break;
  78. }
  79. return $rule;
  80. }
  81. }