00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 include_once( "lib/ezutils/classes/ezdebug.php" );
00039
00040 define( "EZ_MODULE_STATUS_IDLE", 0 );
00041 define( "EZ_MODULE_STATUS_OK", 1 );
00042 define( "EZ_MODULE_STATUS_FAILED", 2 );
00043 define( "EZ_MODULE_STATUS_REDIRECT", 3 );
00044 define( "EZ_MODULE_STATUS_RERUN", 4 );
00045
00046 define( "EZ_MODULE_HOOK_STATUS_OK", 0 );
00047 define( "EZ_MODULE_HOOK_STATUS_CANCEL_RUN", 1 );
00048 define( "EZ_MODULE_HOOK_STATUS_FAILED", 2 );
00049
00050 class eZModule
00051 {
00052 function eZModule( $path, $file, $moduleName )
00053 {
00054 $this->initialize( $path, $file, $moduleName );
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 function initialize( $path, $file, $moduleName )
00065 {
00066 if ( file_exists( $file ) )
00067 {
00068 unset( $FunctionList );
00069 unset( $Module );
00070 unset( $ViewList );
00071 include( $file );
00072 $this->Functions = $ViewList;
00073 if ( isset( $FunctionList ) and
00074 is_array( $FunctionList ) and
00075 count( $FunctionList ) > 0 )
00076 {
00077 ksort( $FunctionList, SORT_STRING );
00078 $this->FunctionList = $FunctionList;
00079 }
00080 else
00081 {
00082 $this->FunctionList = array();
00083 }
00084 $this->Module =& $Module;
00085 $this->Name = $moduleName;
00086 $this->Path = $path;
00087 $this->Title = "";
00088 $this->UIContext = 'navigation';
00089 $this->UIComponent = $moduleName;
00090
00091 $uiComponentMatch = 'module';
00092 if ( isset( $this->Module['ui_component_match'] ) )
00093 {
00094 $uiComponentMatch = $this->Module['ui_component_match'];
00095 }
00096 $this->UIComponentMatch = $uiComponentMatch;
00097
00098 foreach ( $this->Functions as $key => $dummy )
00099 {
00100 $this->Functions[$key]["uri"] = "/$moduleName/$key";
00101 }
00102 }
00103 else
00104 {
00105 $this->Functions = array();
00106 $this->Module = array( "name" => "null",
00107 "variable_params" => false,
00108 "function" => array() );
00109 $this->Name = $moduleName;
00110 $this->Path = $path;
00111 $this->Title = "";
00112 $this->UIContext = 'navigation';
00113 $this->UIComponent = $moduleName;
00114 $this->UIComponentMatch = 'module';
00115 }
00116 $this->HookList = array();
00117 $this->ExitStatus = EZ_MODULE_STATUS_IDLE;
00118 $this->ErrorCode = 0;
00119 $this->ViewActions = array();
00120 $this->OriginalParameters = null;
00121 $this->UserParameters = array();
00122
00123
00124 $ini =& eZINI::instance( 'module.ini' );
00125 $this->NavigationParts = $ini->variable( 'ModuleOverrides', 'NavigationPart' );
00126 }
00127
00128
00129
00130
00131
00132 function uri()
00133 {
00134 return "/" . $this->Name;
00135 }
00136
00137
00138
00139
00140
00141
00142 function functionURI( $function )
00143 {
00144 if ( $this->singleFunction() or
00145 $function == '' )
00146 return $this->uri();
00147 if ( isset( $this->Functions[$function] ) )
00148 return $this->Functions[$function]["uri"];
00149 else
00150 return null;
00151 }
00152
00153
00154
00155
00156
00157 function title()
00158 {
00159 return $this->Title;
00160 }
00161
00162
00163
00164
00165 function setTitle( $title )
00166 {
00167 $this->Title = $title;
00168 }
00169
00170
00171
00172
00173 function setCurrentName( $name )
00174 {
00175 $this->Name = $name;
00176 foreach ( $this->Functions as $key => $dummy )
00177 {
00178 $this->Functions[$key]["uri"] = "/$name/$key";
00179 }
00180 }
00181
00182
00183
00184
00185 function setCurrentView( $name )
00186 {
00187 $GLOBALS['eZModuleCurrentView'] = $name;
00188 }
00189
00190
00191
00192
00193 function singleFunction()
00194 {
00195 return count( $this->Functions ) == 0;
00196 }
00197
00198
00199
00200
00201
00202
00203 function uiContextName()
00204 {
00205 return $this->UIContext;
00206 }
00207
00208
00209
00210
00211
00212
00213 function uiComponentName()
00214 {
00215 return $this->UIComponent;
00216 }
00217
00218
00219
00220
00221 function setUIContextName( $context )
00222 {
00223 $this->UIContext = $context;
00224 }
00225
00226
00227
00228
00229 function setUIComponentName( $component )
00230 {
00231 $this->UIComponent = $component;
00232 }
00233
00234
00235
00236
00237 function exitStatus()
00238 {
00239 return $this->ExitStatus;
00240 }
00241
00242
00243
00244
00245
00246 function setExitStatus( $stat )
00247 {
00248 $this->ExitStatus = $stat;
00249 }
00250
00251
00252
00253
00254
00255 function errorCode()
00256 {
00257 return $this->ErrorCode;
00258 }
00259
00260
00261
00262
00263
00264
00265 function setErrorCode( $errorCode )
00266 {
00267 $this->ErrorCode = $errorCode;
00268 }
00269
00270
00271
00272
00273
00274
00275 function errorModule()
00276 {
00277 $globalErrorModule =& $GLOBALS['eZModuleGlobalErrorModule'];
00278 if ( !isset( $globalErrorModule ) )
00279 $globalErrorModule = array( 'module' => 'error',
00280 'view' => 'view' );
00281 return $globalErrorModule;
00282 }
00283
00284
00285
00286
00287
00288 function setErrorModule( $moduleName, $viewName )
00289 {
00290 $globalErrorModule =& $GLOBALS['eZModuleGlobalErrorModule'];
00291 $globalErrorModule = array( 'module' => $moduleName,
00292 'view' => $viewName );
00293 }
00294
00295
00296
00297
00298
00299 function &handleError( $errorCode, $errorType = false, $parameters = array(), $userParameters = false )
00300 {
00301 if ( !$errorType )
00302 {
00303 eZDebug::writeWarning( "No error type specified for error code $errorCode, assuming kernel.\nA specific error type should be supplied, please check your code.",
00304 'eZModule::handleError' );
00305 $errorType = 'kernel';
00306 }
00307 $errorModule = eZModule::errorModule();
00308 $module =& eZModule::findModule( $errorModule['module'], $this );
00309
00310 if ( $module === null )
00311 {
00312 $retValue = false;
00313 return $retValue;
00314 }
00315
00316 $result =& $module->run( $errorModule['view'], array( $errorType, $errorCode, $parameters, $userParameters ) );
00317
00318 if ( $this->exitStatus() != EZ_MODULE_STATUS_REDIRECT and
00319 $this->exitStatus() != EZ_MODULE_STATUS_RERUN )
00320 {
00321 $this->setExitStatus( EZ_MODULE_STATUS_FAILED );
00322 $this->setErrorCode( $errorCode );
00323 }
00324 return $result;
00325 }
00326
00327
00328
00329
00330
00331
00332
00333
00334 function redirect( $moduleName, $viewName, $parameters = array(),
00335 $unorderedParameters = null, $userParameters = false,
00336 $anchor = false )
00337 {
00338 $module =& eZModule::exists( $moduleName );
00339 if ( $module )
00340 {
00341 return $this->redirectModule( $module, $viewName, $parameters,
00342 $unorderedParameters, $userParameters, $anchor );
00343 }
00344 else
00345 {
00346 eZDebug::writeError( 'Undefined module: ' . $moduleName, 'eZModule::redirect' );
00347 }
00348 return false;
00349 }
00350
00351
00352
00353
00354 function redirectToView( $viewName = '', $parameters = array(),
00355 $unorderedParameters = null, $userParameters = false,
00356 $anchor = false )
00357 {
00358 return $this->redirectModule( $this, $viewName, $parameters,
00359 $unorderedParameters, $userParameters, $anchor );
00360 }
00361
00362
00363
00364
00365 function redirectModule( &$module, $viewName, $parameters = array(),
00366 $unorderedParameters = null, $userParameters = false,
00367 $anchor = false )
00368 {
00369 $uri = $this->redirectionURIForModule( $module, $viewName, $parameters,
00370 $unorderedParameters, $userParameters, $anchor );
00371 $this->redirectTo( $uri );
00372 return true;
00373 }
00374
00375
00376
00377
00378
00379
00380 function redirectionURI( $moduleName, $viewName, $parameters = array(),
00381 $unorderedParameters = null, $userParameters = false,
00382 $anchor = false )
00383 {
00384 $module =& eZModule::exists( $moduleName );
00385 if ( $module )
00386 {
00387 return $this->redirectionURIForModule( $module, $viewName, $parameters,
00388 $unorderedParameters, $userParameters, $anchor );
00389 }
00390 else
00391 eZDebug::writeError( 'Undefined module: ' . $moduleName, 'eZModule::redirectionURI' );
00392 return false;
00393 }
00394
00395
00396
00397
00398 function currentRedirectionURI()
00399 {
00400 $module =& $this;
00401 $viewName = eZModule::currentView();
00402 $parameters = $this->OriginalViewParameters;
00403 $unorderedParameters = $this->OriginalUnorderedParameters;
00404 $userParameters = $this->UserParameters;
00405 return $this->redirectionURIForModule( $module, $viewName, $parameters,
00406 $unorderedParameters, $userParameters );
00407 }
00408
00409
00410
00411
00412
00413
00414
00415 function redirectCurrent()
00416 {
00417 $this->redirectTo( $this->currentRedirectionURI() );
00418 }
00419
00420
00421
00422
00423 function redirectionURIForModule( &$module, $viewName, $parameters = array(),
00424 $unorderedParameters = null, $userParameters = false,
00425 $anchor = false )
00426 {
00427 if ( $viewName == '' )
00428 $viewName = eZModule::currentView();
00429 $uri = $module->functionURI( $viewName );
00430 $uri .= '/';
00431 $viewParameters =& $module->parameters( $viewName );
00432 $parameterIndex = 0;
00433 $unorderedURI = '';
00434 $hasUnorderedParameter = false;
00435 if ( $unorderedParameters !== null )
00436 {
00437 $unorderedViewParameters =& $module->unorderedParameters( $viewName );
00438 if ( is_array( $unorderedViewParameters ) )
00439 {
00440 foreach ( $unorderedViewParameters as $unorderedViewParameterName => $unorderedViewParameterVariable )
00441 {
00442 if ( isset( $unorderedParameters[$unorderedViewParameterVariable] ) )
00443 {
00444 $unorderedURI .= $unorderedViewParameterName . '/' . $unorderedParameters[$unorderedViewParameterVariable] . '/';
00445 $hasUnorderedParameter = true;
00446 }
00447 }
00448 }
00449 }
00450
00451 if( !isset( $viewParameters ) )
00452 $viewParameters = array();
00453
00454 foreach ( $viewParameters as $viewParameter )
00455 {
00456 if ( !isset( $parameters[$parameterIndex] ) )
00457 {
00458
00459
00460
00461
00462
00463 }
00464 else
00465 $uri .= $parameters[$parameterIndex] . '/';
00466 ++$parameterIndex;
00467 }
00468 if ( $hasUnorderedParameter )
00469 {
00470 $uri .= $unorderedURI;
00471 }
00472
00473 if ( is_array( $userParameters ) )
00474 {
00475 foreach ( $userParameters as $name => $value )
00476 {
00477 $uri .= '/(' . $name . ')/' . $value;
00478 }
00479 }
00480
00481 $uri = preg_replace( "#(^.*)(//+)$#", "\$1", $uri );
00482 if ( $anchor !== false )
00483 $uri .= '#' . urlencode( $anchor );
00484 return $uri;
00485 }
00486
00487
00488
00489
00490
00491
00492 function ¶meters( $viewName = '' )
00493 {
00494 if ( $viewName == '' )
00495 $viewName = eZModule::currentView();
00496 $viewData =& $this->viewData( $viewName );
00497 if ( isset( $viewData['params'] ) )
00498 return $viewData['params'];
00499 $retValue = null;
00500 return $retValue;
00501 }
00502
00503
00504
00505
00506
00507
00508 function &unorderedParameters( $viewName = '' )
00509 {
00510 if ( $viewName == '' )
00511 $viewName = eZModule::currentView();
00512 $viewData =& $this->viewData( $viewName );
00513 if ( isset( $viewData['unordered_params'] ) )
00514 return $viewData['unordered_params'];
00515 $retValue = null;
00516 return $retValue;
00517 }
00518
00519
00520
00521
00522
00523
00524 function &viewData( $viewName = '' )
00525 {
00526 if ( $viewName == '' )
00527 $viewName = eZModule::currentView();
00528 if ( $this->singleFunction() )
00529 $viewData =& $this->Module["function"];
00530 else
00531 $viewData =& $this->Functions[$viewName];
00532 return $viewData;
00533 }
00534
00535
00536
00537
00538
00539 function redirectTo( $uri )
00540 {
00541 $originalURI = $uri;
00542 $uri = preg_replace( "#(^.*)(/+)$#", "\$1", $uri );
00543 if ( strlen( $originalURI ) != 0 and
00544 strlen( $uri ) == 0 )
00545 $uri = '/';
00546 $this->RedirectURI = $uri;
00547 $this->setExitStatus( EZ_MODULE_STATUS_REDIRECT );
00548 }
00549
00550
00551
00552
00553 function redirectURI()
00554 {
00555 return $this->RedirectURI;
00556 }
00557
00558
00559
00560
00561 function setRedirectURI( $uri )
00562 {
00563 $this->RedirectURI = $uri;
00564 }
00565
00566
00567
00568
00569 function redirectStatus()
00570 {
00571 return $this->RedirectStatus;
00572 }
00573
00574
00575
00576
00577
00578 function setRedirectStatus( $status )
00579 {
00580 $this->RedirectStatus = $status;
00581 }
00582
00583
00584
00585
00586 function attributes()
00587 {
00588 return array( "uri",
00589 "functions",
00590 'views',
00591 "name",
00592 "path",
00593 "info",
00594 "aviable_functions",
00595 "available_functions" );
00596 }
00597
00598
00599
00600
00601 function hasAttribute( $attr )
00602 {
00603 return in_array( $attr, $this->attributes() );
00604 }
00605
00606
00607
00608
00609 function &attribute( $attr )
00610 {
00611 switch( $attr )
00612 {
00613 case "uri":
00614 $retValue = $this->uri();
00615 break;
00616 case "functions":
00617 return $this->Functions;
00618 case "views":
00619 return $this->Functions;
00620 case "name":
00621 return $this->Name;
00622 case "path":
00623 return $this->Path;
00624 case "info":
00625 return $this->Module;
00626 case 'aviable_functions':
00627 case 'available_functions':
00628 return $this->FunctionList;
00629 default:
00630 {
00631 eZDebug::writeError( "Attribute '$attr' does not exist", 'eZModule::attribute' );
00632 $retValue = null;
00633 }
00634 break;
00635 }
00636 return $retValue;
00637 }
00638
00639
00640
00641
00642
00643 function setCurrentAction( $actionName, $view = '' )
00644 {
00645 if ( $view == '' )
00646 $view = eZModule::currentView();
00647 if ( $view == '' or $actionName == '' )
00648 return false;
00649 $this->ViewActions[$view] = $actionName;
00650 }
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673 function currentAction( $view = '' )
00674 {
00675 if ( $view == '' )
00676 $view = eZModule::currentView();
00677 if ( isset( $this->ViewActions[$view] ) )
00678 return $this->ViewActions[$view];
00679 include_once( "lib/ezutils/classes/ezhttptool.php" );
00680 $http =& eZHTTPTool::instance();
00681 if ( isset( $this->Functions[$view]['default_action'] ) )
00682 {
00683 $defaultAction = $this->Functions[$view]['default_action'];
00684 foreach ( $defaultAction as $defaultActionStructure )
00685 {
00686 $actionName = $defaultActionStructure['name'];
00687 $type = $defaultActionStructure['type'];
00688 if ( $type == 'post' )
00689 {
00690 $parameters = array();
00691 if ( isset( $defaultActionStructure['parameters'] ) )
00692 $parameters = $defaultActionStructure['parameters'];
00693 $hasParameters = true;
00694 foreach ( $parameters as $parameterName )
00695 {
00696 if ( !$http->hasPostVariable( $parameterName ) )
00697 {
00698 $hasParameters = false;
00699 break;
00700 }
00701 }
00702 if ( $hasParameters )
00703 {
00704 $this->ViewActions[$view] = $actionName;
00705 return $this->ViewActions[$view];
00706 }
00707 }
00708 else
00709 {
00710 eZDebug::writeWarning( 'Unknown default action type: ' . $type, 'eZModule::currentAction' );
00711 }
00712 }
00713 }
00714 if ( isset( $this->Functions[$view]['single_post_actions'] ) )
00715 {
00716 $singlePostActions =& $this->Functions[$view]['single_post_actions'];
00717 foreach ( $singlePostActions as $postActionName => $realActionName )
00718 {
00719 if ( $http->hasPostVariable( $postActionName ) )
00720 {
00721 $this->ViewActions[$view] = $realActionName;
00722 return $this->ViewActions[$view];
00723 }
00724 }
00725 }
00726 if ( isset( $this->Functions[$view]['post_actions'] ) )
00727 {
00728 $postActions =& $this->Functions[$view]['post_actions'];
00729 foreach ( $postActions as $postActionName )
00730 {
00731 if ( $http->hasPostVariable( $postActionName ) )
00732 {
00733 $this->ViewActions[$view] = $http->postVariable( $postActionName );
00734 return $this->ViewActions[$view];
00735 }
00736 }
00737 }
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752 $this->ViewActions[$view] = false;
00753 return false;
00754 }
00755
00756 function setActionParameter( $parameterName, $parameterValue, $view = '' )
00757 {
00758 if ( $view == '' )
00759 $view = eZModule::currentView();
00760 $this->ViewActionParameters[$view][$parameterName] = $parameterValue;
00761 }
00762
00763 function actionParameter( $parameterName, $view = '' )
00764 {
00765 if ( $view == '' )
00766 $view = eZModule::currentView();
00767 if ( isset( $this->ViewActionParameters[$view][$parameterName] ) )
00768 return $this->ViewActionParameters[$view][$parameterName];
00769 $currentAction = $this->currentAction( $view );
00770 include_once( "lib/ezutils/classes/ezhttptool.php" );
00771 $http =& eZHTTPTool::instance();
00772 if ( isset( $this->Functions[$view]['post_action_parameters'][$currentAction] ) )
00773 {
00774 $postParameters =& $this->Functions[$view]['post_action_parameters'][$currentAction];
00775 if ( isset( $postParameters[$parameterName] ) and
00776 $http->hasPostVariable( $postParameters[$parameterName] ) )
00777 return $http->postVariable( $postParameters[$parameterName] );
00778 eZDebug::writeError( "No such action parameter: $parameterName", 'eZModule::actionParameter' );
00779 }
00780 if ( isset( $this->Functions[$view]['post_value_action_parameters'][$currentAction] ) )
00781 {
00782 $postParameters =& $this->Functions[$view]['post_value_action_parameters'][$currentAction];
00783 if ( isset( $postParameters[$parameterName] ) )
00784 {
00785 $postVariables =& $http->attribute( 'post' );
00786 $postVariableNameMatch = $postParameters[$parameterName];
00787 $regMatch = "/^" . $postVariableNameMatch . "_(.+)$/";
00788 foreach ( $postVariables as $postVariableName => $postVariableValue )
00789 {
00790 if ( preg_match( $regMatch, $postVariableName, $matches ) )
00791 {
00792 $parameterValue = $matches[1];
00793 $this->ViewActionParameters[$view][$parameterName] = $parameterValue;
00794 return $parameterValue;
00795 }
00796 }
00797 eZDebug::writeError( "No such action parameter: $parameterName", 'eZModule::actionParameter' );
00798 }
00799 }
00800 return null;
00801 }
00802
00803 function hasActionParameter( $parameterName, $view = '' )
00804 {
00805 if ( $view == '' )
00806 $view = eZModule::currentView();
00807 if ( isset( $this->ViewActionParameters[$view][$parameterName] ) )
00808 return true;
00809 $currentAction = $this->currentAction( $view );
00810 include_once( "lib/ezutils/classes/ezhttptool.php" );
00811 $http =& eZHTTPTool::instance();
00812 if ( isset( $this->Functions[$view]['post_action_parameters'][$currentAction] ) )
00813 {
00814 $postParameters =& $this->Functions[$view]['post_action_parameters'][$currentAction];
00815 if ( isset( $postParameters[$parameterName] ) and
00816 $http->hasPostVariable( $postParameters[$parameterName] ) )
00817 return true;
00818 }
00819 if ( isset( $this->Functions[$view]['post_value_action_parameters'][$currentAction] ) )
00820 {
00821 $postParameters =& $this->Functions[$view]['post_value_action_parameters'][$currentAction];
00822 if ( isset( $postParameters[$parameterName] ) )
00823 {
00824 $postVariables =& $http->attribute( 'post' );
00825 $postVariableNameMatch = $postParameters[$parameterName];
00826 $regMatch = "/^" . $postVariableNameMatch . "_(.+)$/";
00827 foreach ( $postVariables as $postVariableName => $postVariableValue )
00828 {
00829 if ( preg_match( $regMatch, $postVariableName, $matches ) )
00830 {
00831 $parameterValue = $matches[1];
00832 $this->ViewActionParameters[$view][$parameterName] = $parameterValue;
00833 return true;
00834 }
00835 }
00836 }
00837 }
00838 return false;
00839 }
00840
00841
00842
00843
00844
00845
00846 function isCurrentAction( $actionName, $view = '' )
00847 {
00848 if ( $view == '' )
00849 $view = eZModule::currentView();
00850 if ( $view == '' or $actionName == '' )
00851 return false;
00852 return $this->currentAction( $view ) == $actionName;
00853 }
00854
00855
00856
00857
00858
00859
00860
00861
00862
00863 function addHook( $hookName, $function, $priority = 1, $expandParameters = true, $append = false )
00864 {
00865 $hookEntries =& $this->HookList[$hookName];
00866 if ( !is_array( $hookEntries ) )
00867 $hookEntries = array();
00868 $entry = array( 'function' => $function,
00869 'expand_parameters' => $expandParameters );
00870
00871 $position = $priority;
00872 if ( $append )
00873 {
00874 while ( isset( $hookEntries[$position] ) )
00875 ++$position;
00876 }
00877 else
00878 {
00879 while ( isset( $hookEntries[$position] ) )
00880 --$position;
00881 }
00882 $hookEntries[$position] = $entry;
00883 }
00884
00885
00886
00887
00888
00889 function runHooks( $hookName, $parameters = null )
00890 {
00891 $status = null;
00892 $hookEntries =& $this->HookList[$hookName];
00893 if ( isset( $hookEntries ) and
00894 is_array( $hookEntries ) )
00895 {
00896 ksort( $hookEntries );
00897 foreach ( array_keys( $hookEntries ) as $hookKey )
00898 {
00899 $hookEntry =& $hookEntries[$hookKey];
00900 $function =& $hookEntry['function'];
00901 $expandParameters =& $hookEntry['expand_parameters'];
00902 if ( is_string( $function ) )
00903 {
00904 $functionName = $function;
00905 if ( function_exists( $functionName ) )
00906 {
00907 if ( $parameters === null or $expandParameters === null )
00908 $retVal =& $functionName( $this );
00909 else if ( $expandParameters )
00910 $retVal = call_user_func_array( $functionName, array_merge( array( &$this ), $parameters ) );
00911 else
00912 $retVal =& $functionName( $this, $parameters );
00913 }
00914 else
00915 eZDebug::writeError( "Unknown hook function '$functionName' in hook: $hookName", 'eZModule::runHooks' );
00916 }
00917 else if ( is_array( $function ) )
00918 {
00919 if ( isset( $function[0] ) and
00920 isset( $function[1] ) )
00921 {
00922 $object =& $function[0];
00923 $functionName = $function[1];
00924 if ( method_exists( $object, $functionName ) )
00925 {
00926 if ( $parameters === null )
00927 $retVal =& $object->$function( $this );
00928 else if ( $expandParameters )
00929 $retVal = call_user_method_array( $functionName, $object, array_merge( array( &$this ), $parameters ) );
00930 else
00931 $retVal =& $object->$functionName( $this, $parameters );
00932 }
00933 else
00934 eZDebug::writeError( "Unknown hook method '$functionName' in class '" . get_class( $object ) . "' in hook: $hookName", 'eZModule::runHooks' );
00935 }
00936 else
00937 eZDebug::writeError( "Missing data for method handling in hook: $hookName", 'eZModule::runHooks' );
00938 }
00939 else
00940 eZDebug::writeError( 'Unknown entry type ' . gettype( $function ) . 'in hook: ' . $hookName, 'eZModule::runHooks' );
00941
00942 switch( $retVal )
00943 {
00944 case EZ_MODULE_HOOK_STATUS_OK:
00945 break;
00946 case EZ_MODULE_HOOK_STATUS_FAILED:
00947 {
00948 eZDebug::writeWarning( 'Hook execution failed in hook: ' . $hookName, 'eZModule::runHooks' );
00949 break;
00950 }
00951 case EZ_MODULE_HOOK_STATUS_CANCEL_RUN:
00952 {
00953 $status = $retVal;
00954 return $status;
00955 break;
00956 }
00957 }
00958 }
00959 }
00960 return $status;
00961 }
00962
00963 function setViewResult( &$result, $view = '' )
00964 {
00965 if ( $view == '' )
00966 $view = $this->currentView();
00967 $this->ViewResult[$view] =& $result;
00968 }
00969
00970 function hasViewResult( $view = '' )
00971 {
00972 if ( $view == '' )
00973 $view = $this->currentView();
00974 return isset( $this->ViewResult[$view] );
00975 }
00976
00977 function &viewResult( $view = '' )
00978 {
00979 if ( $view == '' )
00980 $view = $this->currentView();
00981 if ( isset( $this->ViewResult[$view] ) )
00982 return $this->ViewResult[$view];
00983 $retValue = null;
00984 return $retValue;
00985 }
00986
00987 function &forward( &$module, $functionName, $parameters = false )
00988 {
00989 $Return = null;
00990 if ( $module && $functionName )
00991 {
00992 $viewName = eZModule::currentView();
00993
00994 if ( $parameters === false)
00995 {
00996 $parameters = array();
00997 }
00998
00999 $parameters = array_merge( $parameters, $this->OriginalViewParameters );
01000 $unorderedParameters = $this->OriginalUnorderedParameters;
01001 $userParameters = $this->UserParameters;
01002
01003 $Return =& $module->run( $functionName, $parameters, $unorderedParameters, $userParameters );
01004
01005
01006 if ( $Return['is_default_navigation_part'] === true )
01007 {
01008 if ( $this->singleFunction() )
01009 $function =& $this->Module["function"];
01010 else
01011 $function =& $this->Functions[$functionName];
01012
01013 if ( isset( $function['default_navigation_part'] ) )
01014 {
01015 $Return['navigation_part'] = $function['default_navigation_part'];
01016 }
01017 }
01018
01019 $this->RedirectURI = $module->redirectURI();
01020 $this->setExitStatus( $module->exitStatus() );
01021 }
01022 return $Return;
01023 }
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037 function &run( $functionName, $parameters, $overrideParameters = false, $userParameters = false )
01038 {
01039 if ( count( $this->Functions ) > 0 and
01040 !isset( $this->Functions[$functionName] ) )
01041 {
01042 eZDebug::writeError( "Undefined view: " . $this->Module["name"] . "::$functionName ",
01043 "eZModule" );
01044 $this->setExitStatus( EZ_MODULE_STATUS_FAILED );
01045 $Return = null;
01046 return $Return;
01047 }
01048 if ( $this->singleFunction() )
01049 $function =& $this->Module["function"];
01050 else
01051 $function =& $this->Functions[$functionName];
01052 $functionParameterDefinitions =& $function["params"];
01053 $params = array();
01054 $i = 0;
01055 $parameterValues = array();
01056 if ( isset( $functionParameterDefinitions ) )
01057 {
01058 foreach ( $functionParameterDefinitions as $param )
01059 {
01060 if ( isset( $parameters[$i] ) )
01061 {
01062 $params[$param] = $parameters[$i];
01063 $parameterValues[] = $parameters[$i];
01064 }
01065 else
01066 {
01067 $params[$param] = null;
01068 $parameterValues[] = null;
01069 }
01070 ++$i;
01071 }
01072 }
01073
01074 $this->ViewParameters =& $parameters;
01075 $this->OriginalParameters = $parameters;
01076 $this->OriginalViewParameters = $parameterValues;
01077 $this->NamedParameters = $params;
01078
01079 $GLOBALS['eZRequestedModuleParams'] = array( 'module_name' => $this->Name,
01080 'function_name' => $functionName,
01081 'parameters' => $params );
01082
01083 $this->UserParameters = $userParameters;
01084
01085 if ( isset( $function['ui_context'] ) )
01086 {
01087 $this->UIContext = $function['ui_context'];
01088 }
01089 if ( isset( $function['ui_component'] ) )
01090 {
01091 $this->UIComponent = $function['ui_component'];
01092 }
01093 else if ( $this->UIComponentMatch == 'view' )
01094 {
01095 $this->UIComponent = $functionName;
01096 }
01097
01098 if ( array_key_exists( 'Limitation', $parameters ) )
01099 {
01100 $params['Limitation'] =& $parameters[ 'Limitation' ];
01101 }
01102
01103
01104 $unorderedParametersList = array();
01105 $unorderedParameters = array();
01106 if ( isset( $function["unordered_params"] ) )
01107 {
01108 $unorderedParams =& $function["unordered_params"];
01109
01110 foreach ( $unorderedParams as $urlParamName => $variableParamName )
01111 {
01112 if ( in_array( $urlParamName, $parameters ) )
01113 {
01114 $pos = array_search( $urlParamName, $parameters );
01115
01116 $params[$variableParamName] = $parameters[$pos + 1];
01117 $unorderedParameters[$variableParamName] = $parameters[$pos + 1];
01118 $unorderedParametersList[$variableParamName] = $parameters[$pos + 1];
01119 }
01120 else
01121 {
01122 $params[$variableParamName] = false;
01123 $unorderedParameters[$variableParamName] = false;
01124 }
01125 }
01126 }
01127
01128
01129 if ( $userParameters !== false )
01130 {
01131 if ( !isset( $params['UserParameters'] ) or
01132 !is_array( $params['UserParameters'] ) )
01133 {
01134 $params['UserParameters'] = array();
01135 }
01136
01137 if ( is_array( $userParameters ) && count( $userParameters ) > 0 )
01138 {
01139 foreach ( array_keys( $userParameters ) as $paramKey )
01140 {
01141 if( isset( $function['unordered_params'] ) &&
01142 $unorderedParams != null )
01143 {
01144 if ( array_key_exists( $paramKey, $unorderedParams ) )
01145 {
01146 $params[$unorderedParams[$paramKey]] = $userParameters[$paramKey];
01147 $unorderedParametersList[$unorderedParams[$paramKey]] = $userParameters[$paramKey];
01148 }
01149 }
01150
01151 $params['UserParameters'][$paramKey] = $userParameters[$paramKey];
01152 }
01153 }
01154 }
01155
01156 $this->OriginalUnorderedParameters = $unorderedParametersList;
01157
01158 if ( is_array( $overrideParameters ) )
01159 {
01160 foreach ( $overrideParameters as $param => $value )
01161 {
01162 $params[$param] = $value;
01163 }
01164 }
01165 $params["Module"] =& $this;
01166 $params["ModuleName"] = $this->Name;
01167 $params["FunctionName"] = $functionName;
01168 $params["Parameters"] =& $parameters;
01169 $params_as_var = isset( $this->Module["variable_params"] ) ? $this->Module["variable_params"] : false;
01170 include_once( "lib/ezutils/classes/ezprocess.php" );
01171 $this->ExitStatus = EZ_MODULE_STATUS_OK;
01172
01173
01174
01175 $currentView =& $GLOBALS['eZModuleCurrentView'];
01176 $viewStack =& $GLOBALS['eZModuleViewStack'];
01177 if ( !isset( $currentView ) )
01178 $currentView = false;
01179 if ( !isset( $viewStack ) )
01180 $viewStack = array();
01181 if ( is_array( $currentView ) )
01182 $viewStack[] = $currentView;
01183 $currentView = array( 'view' => $functionName,
01184 'module' => $this->Name );
01185 $Return = eZProcess::run( $this->Path . "/" . $this->Name . "/" . $function["script"],
01186 $params,
01187 $params_as_var );
01188
01189 if ( $this->hasViewResult( $functionName ) )
01190 {
01191 $Return = $this->viewResult( $functionName );
01192 }
01193
01194 if ( count( $viewStack ) > 0 )
01195 $currentView = array_pop( $viewStack );
01196 else
01197 $currentView = false;
01198
01199
01200 if ( !isset( $Return['navigation_part'] ) )
01201 {
01202 $Return['is_default_navigation_part'] = true;
01203 if ( isset( $function['default_navigation_part'] ) )
01204 $Return['navigation_part'] = $function['default_navigation_part'];
01205
01206 }
01207 else
01208 {
01209 $Return['is_default_navigation_part'] = false;
01210 }
01211
01212
01213 $viewName = $this->Name . '/' . $functionName;
01214 if ( isset( $this->NavigationParts[$viewName] ) )
01215 {
01216 $Return['is_default_navigation_part'] = false;
01217 $Return['navigation_part'] = $this->NavigationParts[$viewName];
01218 }
01219 else if ( isset( $this->NavigationParts[$this->Name] ) )
01220 {
01221 $Return['is_default_navigation_part'] = false;
01222 $Return['navigation_part'] = $this->NavigationParts[$this->Name];
01223 }
01224
01225 return $Return;
01226 }
01227
01228
01229
01230
01231
01232
01233 function currentView()
01234 {
01235 $currentView =& $GLOBALS['eZModuleCurrentView'];
01236 if ( $currentView !== false )
01237 return $currentView['view'];
01238 return false;
01239 }
01240
01241
01242
01243
01244
01245
01246 function currentModule()
01247 {
01248 $currentView =& $GLOBALS['eZModuleCurrentView'];
01249 if ( $currentView !== false )
01250 return $currentView['module'];
01251 return false;
01252 }
01253
01254
01255
01256
01257
01258
01259
01260 function globalPathList()
01261 {
01262 if ( !isset( $GLOBALS['eZModuleGlobalPathList'] ) )
01263 return null;
01264 return $GLOBALS['eZModuleGlobalPathList'];
01265 }
01266
01267
01268
01269
01270
01271 function activeModuleRepositories( $useExtensions = true )
01272 {
01273 include_once( 'lib/ezutils/classes/ezini.php' );
01274 include_once( 'lib/ezutils/classes/ezextension.php' );
01275 $moduleINI =& eZINI::instance( 'module.ini' );
01276 $moduleRepositories = $moduleINI->variable( 'ModuleSettings', 'ModuleRepositories' );
01277
01278 if ( $useExtensions )
01279 {
01280 $extensionRepositories = $moduleINI->variable( 'ModuleSettings', 'ExtensionRepositories' );
01281 $extensionDirectory = eZExtension::baseDirectory();
01282 $activeExtensions = eZExtension::activeExtensions();
01283 $globalExtensionRepositories = array();
01284
01285 foreach ( $extensionRepositories as $extensionRepository )
01286 {
01287 $extPath = $extensionDirectory . '/' . $extensionRepository;
01288 $modulePath = $extPath . '/modules';
01289 if ( file_exists( $modulePath ) )
01290 {
01291 $globalExtensionRepositories[] = $modulePath;
01292 }
01293 else if ( !file_exists( $extPath ) )
01294 {
01295 eZDebug::writeWarning( "Extension '$extensionRepository' was reported to have modules but the extension itself does not exist.\n" .
01296 "Check the setting ModuleSettings/ExtensionRepositories in module.ini for your extensions.\n" .
01297 "You should probably remove this extension from the list." );
01298 }
01299 else if ( !in_array( $extensionRepository, $activeExtensions ) )
01300 {
01301 eZDebug::writeWarning( "Extension '$extensionRepository' was reported to have modules but has not yet been activated.\n" .
01302 "Check the setting ModuleSettings/ExtensionRepositories in module.ini for your extensions\n" .
01303 "or make sure it is activated in the setting ExtensionSettings/ActiveExtensions in site.ini." );
01304 }
01305 else
01306 {
01307 eZDebug::writeWarning( "Extension '$extensionRepository' does not have the subdirectory 'modules' allthough it reported it had modules.\n" .
01308 "Looked for directory '" . $modulePath . "'\n" .
01309 "Check the setting ModuleSettings/ExtensionRepositories in module.ini for your extension." );
01310 }
01311 }
01312
01313 $moduleRepositories = array_merge( $moduleRepositories, $globalExtensionRepositories );
01314 }
01315
01316 return $moduleRepositories;
01317 }
01318
01319
01320
01321
01322
01323
01324
01325 function setGlobalPathList( $pathList )
01326 {
01327 $globalPathList =& $GLOBALS['eZModuleGlobalPathList'];
01328 if ( !is_array( $pathList ) )
01329 $pathList = array( $pathList );
01330 $globalPathList = $pathList;
01331 }
01332
01333
01334
01335
01336
01337
01338
01339 function addGlobalPathList( $pathList )
01340 {
01341 $globalPathList =& $GLOBALS['eZModuleGlobalPathList'];
01342 if ( !is_array( $globalPathList ) )
01343 $globalPathList = array();
01344 if ( !is_array( $pathList ) )
01345 $pathList = array( $pathList );
01346 $globalPathList = array_merge( $globalPathList, $pathList );
01347 }
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359 function &exists( $moduleName, $pathList = null )
01360 {
01361 $module = null;
01362 eZModule::findModule( $moduleName, $module, $pathList );
01363 return $module;
01364 }
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377 function &findModule( $moduleName, &$module, $pathList = null )
01378 {
01379 if ( $pathList === null )
01380 $pathList = array();
01381 else if ( !is_array( $pathList ) )
01382 $pathList = array( $pathList );
01383 $searchPathList = eZModule::globalPathList();
01384 if ( $searchPathList === null )
01385 $searchPathList = array();
01386 $searchPathList = array_merge( $searchPathList, $pathList );
01387 $triedList = array();
01388 $triedDirList = array();
01389 $foundADir = false;
01390 foreach ( $searchPathList as $path )
01391 {
01392 $dir = "$path/$moduleName";
01393 $file = "$dir/module.php";
01394 if ( file_exists( $file ) )
01395 {
01396 if ( $module === null )
01397 $module = new eZModule( $path, $file, $moduleName );
01398 else
01399 $module->initialize( $path, $file, $moduleName );
01400 return $module;
01401 }
01402 else if ( !file_exists( $dir ) )
01403 {
01404 $triedDirList[] = $dir;
01405 }
01406 else
01407 {
01408 $foundADir = true;
01409 $triedList[] = $dir;
01410 }
01411 }
01412
01413 $msg = "Could not find module named '$moduleName'";
01414 if ( $foundADir )
01415 {
01416 $msg = "\nThese directories had a directory named '$moduleName' but did not contain the module.php file:\n" .
01417 implode( ", ", $triedList ) . "\n" .
01418 "This usually means it is missing or has a wrong name.";
01419 if ( count( $triedDirList ) > 0 )
01420 $msg .= "\n\nThese directories were tried too but none of them exists:\n" . implode( ', ', $triedDirList );
01421 }
01422 else
01423 {
01424 if ( count( $triedDirList ) > 0 )
01425 $msg.= "\nThese directories were tried but none of them exists:\n" . implode( ", ", $triedDirList );
01426 }
01427 eZDebug::writeWarning( $msg );
01428
01429 $retValue = null;
01430 return $retValue;
01431 }
01432
01433 function &getNamedParameters()
01434 {
01435 return $this->NamedParameters;
01436 }
01437
01438
01439 var $Functions;
01440 var $Module;
01441 var $Name;
01442 var $Path;
01443 var $ExitStatus;
01444 var $ErrorCode;
01445 var $RedirectURI;
01446 var $RedirectStatus;
01447 var $Title;
01448 var $HookList;
01449 var $ViewActions;
01450 var $ViewResult;
01451 var $ViewParameters;
01452 var $OriginalParameters;
01453 var $OriginalViewParameters;
01454 var $NamedParameters;
01455 var $OriginalUnorderedParameters;
01456 var $UserParameters;
01457
01458
01459 var $UIContext;
01460
01461 var $UIComponent;
01462
01463 var $UIComponentMatch;
01464 }
01465
01466 ?>