PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/kernel/classes/ezcontentobjectedithandler.php

https://github.com/granitegreg/ezpublish
PHP | 239 lines | 129 code | 26 blank | 84 comment | 7 complexity | 60a4fd32cbf87d8ba57721c6fe3bb260 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. //
  3. // Definition of eZContentObjectEditHandler class
  4. //
  5. // Created on: <20-Dec-2005 14:19:36 hovik>
  6. //
  7. // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  8. // SOFTWARE NAME: eZ Publish
  9. // SOFTWARE RELEASE: 4.1.x
  10. // COPYRIGHT NOTICE: Copyright (C) 1999-2011 eZ Systems AS
  11. // SOFTWARE LICENSE: GNU General Public License v2.0
  12. // NOTICE: >
  13. // This program is free software; you can redistribute it and/or
  14. // modify it under the terms of version 2.0 of the GNU General
  15. // Public License as published by the Free Software Foundation.
  16. //
  17. // This program is distributed in the hope that it will be useful,
  18. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. // GNU General Public License for more details.
  21. //
  22. // You should have received a copy of version 2.0 of the GNU General
  23. // Public License along with this program; if not, write to the Free
  24. // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. // MA 02110-1301, USA.
  26. //
  27. //
  28. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
  29. //
  30. /*! \file
  31. */
  32. /*!
  33. \class eZContentObjectEditHandler ezcontentobjectedithandler.php
  34. \brief The class eZContentObjectEditHandler provides a framework for handling
  35. content/edit view specific things in extensions.
  36. */
  37. class eZContentObjectEditHandler
  38. {
  39. /*!
  40. Constructor
  41. */
  42. function eZContentObjectEditHandler()
  43. {
  44. }
  45. /*!
  46. Override this function in the extension to handle edit input parameters.
  47. */
  48. function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
  49. {
  50. }
  51. /*!
  52. Return list of HTTP postparameters which should trigger store action.
  53. */
  54. static function storeActionList()
  55. {
  56. return array();
  57. }
  58. /*!
  59. Do content object publish operations.
  60. */
  61. function publish( $contentObjectID, $contentObjectVersion )
  62. {
  63. }
  64. /*!
  65. Override this function in the extension to handle input validation.
  66. Result with warnings are expected in the following format:
  67. array( 'is_valid' => false, 'warnings' => array( array( 'text' => 'Input parameter <some_id> must be an integer.' ) ) );
  68. */
  69. function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
  70. {
  71. $result = array( 'is_valid' => true, 'warnings' => array() );
  72. return $result;
  73. }
  74. /*!
  75. \static
  76. Initialize all extension input handler.
  77. */
  78. static function initialize()
  79. {
  80. $contentINI = eZINI::instance( 'content.ini' );
  81. foreach( array_unique( $contentINI->variable( 'EditSettings', 'ExtensionDirectories' ) ) as $extensionDirectory )
  82. {
  83. $fileName = eZExtension::baseDirectory() . '/' . $extensionDirectory . '/content/' . $extensionDirectory . 'handler.php';
  84. if ( file_exists( $fileName ) )
  85. {
  86. include_once( $fileName );
  87. $className = $extensionDirectory . 'Handler';
  88. $storeActionList = call_user_func_array( array( $className, 'storeActionList' ), array() );
  89. foreach( $storeActionList as $storeAction )
  90. {
  91. eZContentObjectEditHandler::addStoreAction( $storeAction );
  92. }
  93. }
  94. else
  95. {
  96. eZDebug::writeError( 'Cound not find content object edit handler ( defined in content.ini ) : ' . $fileName );
  97. }
  98. }
  99. }
  100. /*!
  101. \static
  102. Execute handler $functionName function with given $params parameters
  103. */
  104. static function executeHandlerFunction( $functionName, $params )
  105. {
  106. $result = array();
  107. $contentINI = eZINI::instance( 'content.ini' );
  108. foreach( array_unique( $contentINI->variable( 'EditSettings', 'ExtensionDirectories' ) ) as $extensionDirectory )
  109. {
  110. $fileName = eZExtension::baseDirectory() . '/' . $extensionDirectory . '/content/' . $extensionDirectory . 'handler.php';
  111. if ( file_exists( $fileName ) )
  112. {
  113. include_once( $fileName );
  114. $className = $extensionDirectory . 'Handler';
  115. $inputHandler = new $className();
  116. $functionResult = call_user_func_array( array( $inputHandler, $functionName ), $params );
  117. $result[] = array( 'handler' => $className,
  118. 'function' => array( 'name' => $functionName, 'value' => $functionResult ) );
  119. }
  120. }
  121. return $result;
  122. }
  123. /*!
  124. \static
  125. Calls all extension object edit input handler, and executes this the fetchInput function
  126. */
  127. static function executeInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
  128. {
  129. $http = eZHTTPTool::instance();
  130. $functionName = 'fetchInput';
  131. $params = array( $http,
  132. &$module,
  133. &$class,
  134. $object,
  135. &$version,
  136. $contentObjectAttributes,
  137. $editVersion,
  138. $editLanguage,
  139. $fromLanguage );
  140. self::executeHandlerFunction( $functionName, $params );
  141. }
  142. /*!
  143. \static
  144. Calls all publish functions.
  145. */
  146. static function executePublish( $contentObjectID, $contentObjectVersion )
  147. {
  148. $functionName = 'publish';
  149. $params = array( $contentObjectID, $contentObjectVersion );
  150. self::executeHandlerFunction( $functionName, $params );
  151. }
  152. /*!
  153. \static
  154. Calls all input validation functions.
  155. */
  156. static function validateInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
  157. {
  158. $result = array( 'validated' => true, 'warnings' => array() );
  159. $validated =& $result['validated'];
  160. $warnings =& $result['warnings'];
  161. $http = eZHTTPTool::instance();
  162. $functionName = 'validateInput';
  163. $params = array( $http,
  164. &$module,
  165. &$class,
  166. $object,
  167. &$version,
  168. $contentObjectAttributes,
  169. $editVersion,
  170. $editLanguage,
  171. $fromLanguage,
  172. $validationParameters );
  173. $validationResults = self::executeHandlerFunction( $functionName, $params );
  174. foreach( $validationResults as $validationResult )
  175. {
  176. $value = $validationResult['function']['value'];
  177. if ( $value['is_valid'] == false )
  178. {
  179. if ( $value['warnings'] )
  180. $warnings = array_merge( $warnings, $value['warnings'] );
  181. $validated = false;
  182. }
  183. }
  184. return $result;
  185. }
  186. /*!
  187. \static
  188. Set custom HTTP post parameters which should trigger store acrtions.
  189. \param HTTP post parameter name
  190. */
  191. static function addStoreAction( $name )
  192. {
  193. if ( !isset( $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) )
  194. {
  195. $GLOBALS['eZContentObjectEditHandler_StoreAction'] = array();
  196. }
  197. $GLOBALS['eZContentObjectEditHandler_StoreAction'][] = $name;
  198. }
  199. /*!
  200. \static
  201. Check if any HTTP input trigger store action
  202. */
  203. static function isStoreAction()
  204. {
  205. if ( !isset( $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) )
  206. return 0;
  207. return count( array_intersect( array_keys( $_POST ), $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) ) > 0;
  208. }
  209. }
  210. ?>