eZ Publish  [trunk]
ezcontentobjectedithandler.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZContentObjectEditHandler class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /*!
00012   \class eZContentObjectEditHandler ezcontentobjectedithandler.php
00013   \brief The class eZContentObjectEditHandler provides a framework for handling
00014   content/edit view specific things in extensions.
00015 
00016 */
00017 
00018 class eZContentObjectEditHandler
00019 {
00020     /*!
00021      Constructor
00022     */
00023     function eZContentObjectEditHandler()
00024     {
00025     }
00026 
00027     /*!
00028      Override this function in the extension to handle edit input parameters.
00029     */
00030     function fetchInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
00031     {
00032     }
00033 
00034     /*!
00035      Return list of HTTP postparameters which should trigger store action.
00036     */
00037     static function storeActionList()
00038     {
00039         return array();
00040     }
00041 
00042     /*!
00043      Do content object publish operations.
00044     */
00045     function publish( $contentObjectID, $contentObjectVersion )
00046     {
00047     }
00048 
00049     /*!
00050      Override this function in the extension to handle input validation.
00051 
00052      Result with warnings are expected in the following format:
00053      array( 'is_valid' => false, 'warnings' => array( array( 'text' => 'Input parameter <some_id> must be an integer.' ) ) );
00054     */
00055     function validateInput( $http, &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
00056     {
00057         $result = array( 'is_valid' => true, 'warnings' => array() );
00058 
00059         return $result;
00060     }
00061 
00062     /*!
00063      \static
00064      Initialize all extension input handler.
00065     */
00066     static function initialize()
00067     {
00068         $contentINI = eZINI::instance( 'content.ini' );
00069         foreach( array_unique( $contentINI->variable( 'EditSettings', 'ExtensionDirectories' ) ) as $extensionDirectory )
00070         {
00071             $fileName = eZExtension::baseDirectory() . '/' . $extensionDirectory . '/content/' . $extensionDirectory . 'handler.php';
00072             if ( file_exists( $fileName ) )
00073             {
00074                 include_once( $fileName );
00075                 $className = $extensionDirectory . 'Handler';
00076                 $storeActionList = call_user_func_array( array( $className, 'storeActionList' ), array() );
00077                 foreach( $storeActionList as $storeAction )
00078                 {
00079                     eZContentObjectEditHandler::addStoreAction( $storeAction );
00080                 }
00081             }
00082             else
00083             {
00084                 eZDebug::writeError( 'Cound not find content object edit handler ( defined in content.ini ) : ' . $fileName );
00085             }
00086         }
00087     }
00088 
00089     /*!
00090      \static
00091      Execute handler $functionName function with given $params parameters
00092     */
00093     static function executeHandlerFunction( $functionName, $params )
00094     {
00095         $result = array();
00096         $contentINI = eZINI::instance( 'content.ini' );
00097         foreach( array_unique( $contentINI->variable( 'EditSettings', 'ExtensionDirectories' ) ) as $extensionDirectory )
00098         {
00099             $fileName = eZExtension::baseDirectory() . '/' . $extensionDirectory . '/content/' . $extensionDirectory . 'handler.php';
00100             if ( file_exists( $fileName ) )
00101             {
00102                 include_once( $fileName );
00103                 $className = $extensionDirectory . 'Handler';
00104                 $inputHandler = new $className();
00105                 $functionResult = call_user_func_array( array( $inputHandler, $functionName ), $params );
00106                 $result[] = array( 'handler' => $className,
00107                                    'function' => array( 'name' => $functionName, 'value' => $functionResult ) );
00108             }
00109         }
00110 
00111         return $result;
00112     }
00113 
00114     /*!
00115      \static
00116      Calls all extension object edit input handler, and executes this the fetchInput function
00117     */
00118     static function executeInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage )
00119     {
00120         $http = eZHTTPTool::instance();
00121         $functionName = 'fetchInput';
00122         $params = array( $http,
00123                          &$module,
00124                          &$class,
00125                          $object,
00126                          &$version,
00127                          $contentObjectAttributes,
00128                          $editVersion,
00129                          $editLanguage,
00130                          $fromLanguage );
00131 
00132        self::executeHandlerFunction( $functionName, $params );
00133     }
00134 
00135     /*!
00136      \static
00137      Calls all publish functions.
00138     */
00139     static function executePublish( $contentObjectID, $contentObjectVersion )
00140     {
00141         $functionName = 'publish';
00142         $params = array( $contentObjectID, $contentObjectVersion );
00143 
00144         self::executeHandlerFunction( $functionName, $params );
00145     }
00146 
00147     /*!
00148      \static
00149      Calls all input validation functions.
00150     */
00151     static function validateInputHandlers( &$module, &$class, $object, &$version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage, $validationParameters )
00152     {
00153         $result = array( 'validated' => true, 'warnings' => array() );
00154         $validated =& $result['validated'];
00155         $warnings =& $result['warnings'];
00156 
00157         $http = eZHTTPTool::instance();
00158 
00159         $functionName = 'validateInput';
00160         $params = array( $http,
00161                          &$module,
00162                          &$class,
00163                          $object,
00164                          &$version,
00165                          $contentObjectAttributes,
00166                          $editVersion,
00167                          $editLanguage,
00168                          $fromLanguage,
00169                          $validationParameters );
00170 
00171         $validationResults = self::executeHandlerFunction( $functionName, $params );
00172 
00173         foreach( $validationResults as $validationResult )
00174         {
00175             $value = $validationResult['function']['value'];
00176 
00177             if ( $value['is_valid'] == false )
00178             {
00179                 if ( $value['warnings'] )
00180                     $warnings = array_merge( $warnings, $value['warnings'] );
00181 
00182                 $validated = false;
00183             }
00184         }
00185 
00186         return $result;
00187     }
00188 
00189     /*!
00190      \static
00191      Set custom HTTP post parameters which should trigger store acrtions.
00192 
00193      \param HTTP post parameter name
00194     */
00195     static function addStoreAction( $name )
00196     {
00197         if ( !isset( $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) )
00198         {
00199             $GLOBALS['eZContentObjectEditHandler_StoreAction'] = array();
00200         }
00201         $GLOBALS['eZContentObjectEditHandler_StoreAction'][] = $name;
00202     }
00203 
00204     /*!
00205      \static
00206      Check if any HTTP input trigger store action
00207     */
00208     static function isStoreAction()
00209     {
00210         if ( !isset( $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) )
00211             return 0;
00212         return count( array_intersect( array_keys( $_POST ), $GLOBALS['eZContentObjectEditHandler_StoreAction'] ) ) > 0;
00213     }
00214 }
00215 
00216 ?>