modplugin.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * Provides a non-cacheable modScript implementation representing plugins.
  12. *
  13. * {@inheritdoc}
  14. *
  15. * @field boolean $cache_type Deprecated.
  16. * @field string $plugincode The code of the Plugin
  17. * @field boolean $locked Whether or not this Plugin is locked from editing except by Administrators
  18. * @field array $properties An array of default properties for the Plugin
  19. * @field boolean $disabled Whether or not this Plugin is active.
  20. * @field string $moduleguid Deprecated.
  21. *
  22. * @package modx
  23. * @extends modScript
  24. */
  25. class modPlugin extends modScript {
  26. /**
  27. * Overrides xPDOObject::__construct to always set plugins as non-cacheable
  28. * @param xPDO $xpdo A reference to the xPDO|modX instance
  29. */
  30. function __construct(xPDO & $xpdo) {
  31. parent :: __construct($xpdo);
  32. $this->setCacheable(false);
  33. }
  34. /**
  35. * Overrides modElement::save to add custom error logging and fire
  36. * modX-specific events.
  37. *
  38. * {@inheritdoc}
  39. */
  40. public function save($cacheFlag = null) {
  41. $isNew = $this->isNew();
  42. if ($this->xpdo instanceof modX) {
  43. $this->xpdo->invokeEvent('OnPluginBeforeSave',array(
  44. 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
  45. 'plugin' => &$this,
  46. 'cacheFlag' => $cacheFlag,
  47. ));
  48. }
  49. $saved = parent::save($cacheFlag);
  50. if ($saved && $this->xpdo instanceof modX) {
  51. $this->xpdo->invokeEvent('OnPluginSave',array(
  52. 'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
  53. 'plugin' => &$this,
  54. 'cacheFlag' => $cacheFlag,
  55. ));
  56. } else if (!$saved && !empty($this->xpdo->lexicon)) {
  57. $msg = $isNew ? $this->xpdo->lexicon('plugin_err_create') : $this->xpdo->lexicon('plugin_err_save');
  58. $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,$msg.$this->toArray());
  59. }
  60. return $saved;
  61. }
  62. /**
  63. * Overrides modElement::remove to add custom error logging and fire
  64. * modX-specific events.
  65. *
  66. * {@inheritdoc}
  67. */
  68. public function remove(array $ancestors= array ()) {
  69. if ($this->xpdo instanceof modX) {
  70. $this->xpdo->invokeEvent('OnPluginBeforeRemove',array(
  71. 'plugin' => &$this,
  72. 'ancestors' => $ancestors,
  73. ));
  74. }
  75. $removed = parent :: remove($ancestors);
  76. if ($removed && $this->xpdo instanceof modX) {
  77. $this->xpdo->invokeEvent('OnPluginRemove',array(
  78. 'plugin' => &$this,
  79. 'ancestors' => $ancestors,
  80. ));
  81. } else if (!$removed && !empty($this->xpdo->lexicon)) {
  82. $this->xpdo->log(xPDO::LOG_LEVEL_ERROR,$this->xpdo->lexicon('plugin_err_remove').$this->toArray());
  83. }
  84. return $removed;
  85. }
  86. /**
  87. * Overrides modElement::getPropertySet to handle separate plugin event
  88. * property set calls.
  89. *
  90. * {@inheritdoc}
  91. */
  92. public function getPropertySet($setName = null) {
  93. if (empty($setName) && !empty($this->xpdo->event->propertySet)) {
  94. $setName = $this->xpdo->event->propertySet;
  95. }
  96. return parent :: getPropertySet($setName);
  97. }
  98. /**
  99. * Grabs a list of groups for the plugin.
  100. * @todo Implement this.
  101. *
  102. * @static
  103. * @param modResource $resource
  104. * @param array $sort
  105. * @param int $limit
  106. * @param int $offset
  107. * @return void
  108. */
  109. public static function listGroups(modResource &$resource, array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
  110. }
  111. }