[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Created on: <17-Apr-2002 10:34:48 bf> 4 // 5 // SOFTWARE NAME: eZ publish 6 // SOFTWARE RELEASE: 3.9.0 7 // BUILD VERSION: 17785 8 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 9 // SOFTWARE LICENSE: GNU General Public License v2.0 10 // NOTICE: > 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of version 2.0 of the GNU General 13 // Public License as published by the Free Software Foundation. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of version 2.0 of the GNU General 21 // Public License along with this program; if not, write to the Free 22 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 23 // MA 02110-1301, USA. 24 // 25 // 26 27 /*! 28 \file attribute_edit.php 29 This file is a shared code file which is used by different parts of the system 30 to edit objects. This file only implements editing of attributes and uses 31 hooks to allow external code to add functionality. 32 \param $Module must be set by the code which includes this file 33 */ 34 35 include_once ( 'kernel/classes/ezcontentclass.php' ); 36 include_once ( 'kernel/classes/ezcontentclassattribute.php' ); 37 38 include_once ( 'kernel/classes/ezcontentobject.php' ); 39 include_once ( 'kernel/classes/ezcontentobjectversion.php' ); 40 include_once ( 'kernel/classes/ezcontentobjectattribute.php' ); 41 42 include_once ( 'lib/ezutils/classes/ezhttptool.php' ); 43 44 include_once ( 'kernel/common/template.php' ); 45 46 include_once ( 'kernel/classes/ezpreferences.php' ); 47 48 if ( isset( $Module ) ) 49 $Module =& $Params['Module']; 50 $ObjectID =& $Params['ObjectID']; 51 if ( !isset( $EditVersion ) ) 52 $EditVersion =& $Params['EditVersion']; 53 54 if ( !isset( $EditLanguage ) and 55 isset( $Params['EditLanguage'] ) ) 56 $EditLanguage = $Params['EditLanguage']; 57 if ( !isset( $EditLanguage ) or 58 !is_string( $EditLanguage ) or 59 strlen( $EditLanguage ) == 0 ) 60 $EditLanguage = false; 61 62 if ( !isset( $FromLanguage ) and 63 isset( $Params['FromLanguage'] ) ) 64 $FromLanguage = $Params['FromLanguage']; 65 if ( !isset( $FromLanguage ) or 66 !is_string( $FromLanguage ) or 67 strlen( $FromLanguage ) == 0 ) 68 $FromLanguage = false; 69 70 if ( $Module->runHooks( 'pre_fetch', array( $ObjectID, &$EditVersion, &$EditLanguage, &$FromLanguage ) ) ) 71 return; 72 73 $object =& eZContentObject::fetch( $ObjectID ); 74 if ( $object === null ) 75 return $Module->handleError( EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel' ); 76 77 78 $version =& $object->version( $EditVersion ); 79 $classID = $object->attribute( 'contentclass_id' ); 80 81 $attributeDataBaseName = 'ContentObjectAttribute'; 82 83 84 $class = eZContentClass::fetch( $classID ); 85 $contentObjectAttributes =& $version->contentObjectAttributes( $EditLanguage ); 86 if ( $contentObjectAttributes === null or 87 count( $contentObjectAttributes ) == 0 ) 88 { 89 $contentObjectAttributes =& $version->contentObjectAttributes(); 90 $EditLanguage = $version->initialLanguageCode(); 91 } 92 93 $fromContentObjectAttributes = false; 94 $isTranslatingContent = false; 95 if ( $FromLanguage !== false ) 96 { 97 $isTranslatingContent = true; 98 $fromContentObjectAttributes =& $object->contentObjectAttributes( true, false, $FromLanguage ); 99 if ( $fromContentObjectAttributes === null or 100 count( $fromContentObjectAttributes ) == 0 ) 101 { 102 unset( $fromContentObjectAttributes ); 103 $fromContentObjectAttributes = false; 104 $isTranslatingContent = false; 105 } 106 } 107 108 $http =& eZHTTPTool::instance(); 109 110 $validation = array( 'processed' => false, 111 'attributes' => array(), 112 'placement' => array( ) ); 113 114 if ( $Module->runHooks( 'post_fetch', array( &$class, &$object, &$version, &$contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage, &$validation ) ) ) 115 return; 116 117 // Checking if user chose placement of object from browse page (when restoring from the TRASH), 118 // if yes object must be published without returning to edit mode. 119 if ( ( $http->hasSessionVariable( 'LastCurrentAction' ) ) and 120 ( $http->sessionVariable( 'LastCurrentAction' ) == 'Publish' ) and 121 ( $Module->isCurrentAction( 'AddNodeAssignment' ) || 122 $Module->isCurrentAction( 'AddPrimaryNodeAssignment' ) ) 123 ) 124 { 125 $http->removeSessionVariable( 'LastCurrentAction' ); 126 // Publish object 127 $Module->setCurrentAction( 'Publish' ); 128 if ( $http->hasSessionVariable( 'BrowseForNodes_POST' ) ) 129 { 130 // Restore post vars 131 $_POST = array_merge( $_POST, $http->sessionVariable( 'BrowseForNodes_POST' ) ); 132 $http->removeSessionVariable( 'BrowseForNodes_POST' ); 133 } 134 } 135 else 136 { 137 // Clean up session vars 138 $http->removeSessionVariable( 'LastCurrentAction' ); 139 $http->removeSessionVariable( 'BrowseForNodes_POST' ); 140 } 141 142 // Checking if object has at least one placement, if not user needs to choose it from browse page 143 $assignments =& $version->attribute( 'parent_nodes' ); 144 $assignedNodes =& $object->attribute( 'assigned_nodes' ); 145 146 // Figure out how many locations it has (or will get) 147 $locationIDList = array(); 148 foreach ( $assignedNodes as $node ) 149 { 150 $locationIDList[$node->attribute( 'parent_node_id' )] = true; 151 } 152 foreach ( $assignments as $assignment ) 153 { 154 if ( $assignment->attribute( 'op_code' ) == EZ_NODE_ASSIGNMENT_OP_CODE_CREATE || 155 $assignment->attribute( 'op_code' ) == EZ_NODE_ASSIGNMENT_OP_CODE_SET ) 156 { 157 $locationIDList[$assignment->attribute( 'parent_node' )] = true; 158 } 159 elseif ( $assignment->attribute( 'op_code' ) == EZ_NODE_ASSIGNMENT_OP_CODE_REMOVE ) 160 { 161 unset( $locationIDList[$assignment->attribute( 'parent_node' )] ); 162 } 163 } 164 $locationCount = count( $locationIDList ); 165 166 // If there are no locations we need to browse for one. 167 if ( $locationCount < 1 && $Module->isCurrentAction( 'Publish' ) ) 168 { 169 // if ( $object->attribute( 'status' ) == EZ_CONTENT_OBJECT_STATUS_DRAFT ) 170 { 171 $Module->setCurrentAction( 'BrowseForPrimaryNodes' ); 172 // Store currentAction 173 $http->setSessionVariable( 'LastCurrentAction', 'Publish' ); 174 // Store post vars 175 $http->setSessionVariable( 'BrowseForNodes_POST', $_POST ); 176 } 177 } 178 179 180 181 // Custom Action Code Start 182 $customAction = false; 183 $customActionAttributeArray = array(); 184 // Check for custom actions 185 if ( $http->hasPostVariable( "CustomActionButton" ) ) 186 { 187 $customActionArray = $http->postVariable( "CustomActionButton" ); 188 foreach ( $customActionArray as $customActionKey => $customActionValue ) 189 { 190 $customActionString = $customActionKey; 191 192 if ( preg_match( "#^([0-9]+)_(.*)$#", $customActionString, $matchArray ) ) 193 { 194 $customActionAttributeID = $matchArray[1]; 195 $customAction = $matchArray[2]; 196 $customActionAttributeArray[$customActionAttributeID] = array( 'id' => $customActionAttributeID, 197 'value' => $customAction ); 198 } 199 } 200 } 201 202 include_once ( 'kernel/classes/ezcontentobjectedithandler.php' ); 203 eZContentObjectEditHandler::initialize(); 204 205 $storeActions = array( 'Preview', 206 'Translate', 207 'TranslateLanguage', 208 'VersionEdit', 209 'Apply', 210 'Publish', 211 'Store', 212 'StoreExit', 213 // 'Discard', 214 // 'CustomAction', 215 'EditLanguage', 216 'FromLanguage', 217 'BrowseForObjects', 218 'UploadFileRelation', 219 'NewObject', 220 'BrowseForNodes', 221 'BrowseForPrimaryNodes', 222 'RemoveAssignments', 223 'DeleteRelation', 224 'DeleteNode', 225 'SectionEdit', 226 'MoveNode' ); 227 $storingAllowed = ( in_array( $Module->currentAction(), $storeActions ) || 228 eZContentObjectEditHandler::isStoreAction() ); 229 if ( $http->hasPostVariable( 'CustomActionButton' ) ) 230 $storingAllowed = true; 231 232 $hasObjectInput = true; 233 if ( $http->hasPostVariable( 'HasObjectInput' ) ) 234 $hasObjectInput = $http->postVariable( 'HasObjectInput' ); 235 236 // These variables will be modified according to validation 237 $inputValidated = true; 238 $requireFixup = false; 239 $validatedAttributes = array(); 240 241 if ( $storingAllowed && $hasObjectInput) 242 { 243 // Disable checking 'is_required' flag for some actions. 244 $validationParameters = array( 'skip-isRequired' => false ); 245 if ( $Module->isCurrentAction( 'Store' ) || // 'store draft' 246 $http->hasPostVariable( 'CustomActionButton' ) ) // 'custom action' like 'Find object' for 'object relation' datatype. 247 { 248 $validationParameters['skip-isRequired'] = true; 249 } 250 251 // Validate input 252 include_once ( 'lib/ezutils/classes/ezinputvalidator.php' ); 253 $validationResult = $object->validateInput( $contentObjectAttributes, $attributeDataBaseName, false, $validationParameters ); 254 $unvalidatedAttributes = $validationResult['unvalidated-attributes']; 255 $validatedAttributes = $validationResult['validated-attributes']; 256 $inputValidated = $validationResult['input-validated']; 257 258 // Fixup input 259 if ( $validationResult['require-fixup'] ) 260 $object->fixupInput( $contentObjectAttributes, $attributeDataBaseName ); 261 262 // Check extension input handlers 263 eZContentObjectEditHandler::executeInputHandlers( $Module, $class, $object, $version, $contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage ); 264 265 // If no redirection uri we assume it's content/edit 266 if ( !isset( $currentRedirectionURI ) ) 267 $currentRedirectionURI = $Module->redirectionURI( 'content', 'edit', array( $ObjectID, $EditVersion, $EditLanguage ) ); 268 269 $fetchResult = $object->fetchInput( $contentObjectAttributes, $attributeDataBaseName, 270 $customActionAttributeArray, 271 array( 'module' => &$Module, 272 'current-redirection-uri' => $currentRedirectionURI ) ); 273 $attributeInputMap =& $fetchResult['attribute-input-map']; 274 if ( $Module->isCurrentAction( 'Discard' ) ) 275 $inputValidated = true; 276 277 // If an input is invalid, prevent from redirection that might be set by a custom action 278 if ( !$inputValidated && $Module->exitStatus() == EZ_MODULE_STATUS_REDIRECT ) 279 $Module->setExitStatus( EZ_MODULE_STATUS_OK ); 280 281 if ( $inputValidated and count( $attributeInputMap ) > 0 ) 282 { 283 if ( $Module->runHooks( 'pre_commit', array( &$class, &$object, &$version, &$contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage ) ) ) 284 return; 285 $version->setAttribute( 'modified', time() ); 286 $version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); 287 288 $db =& eZDB::instance(); 289 $db->begin(); 290 $version->store(); 291 // print( "storing<br/>" ); 292 // Tell attributes to store themselves if necessary 293 $object->storeInput( $contentObjectAttributes, 294 $attributeInputMap ); 295 $db->commit(); 296 } 297 298 $validation['processed'] = true; 299 $validation['attributes'] = $unvalidatedAttributes; 300 301 $db =& eZDB::instance(); 302 $db->begin(); 303 $object->setName( $class->contentObjectName( $object ), $version->attribute( 'version' ), $EditLanguage ); 304 $db->commit(); 305 } 306 elseif ( $storingAllowed ) 307 { 308 if ( !isset( $currentRedirectionURI ) ) 309 $currentRedirectionURI = $Module->redirectionURI( 'content', 'edit', array( $ObjectID, $EditVersion, $EditLanguage ) ); 310 eZContentObject::recursionProtectionStart(); 311 foreach( array_keys( $contentObjectAttributes ) as $key ) 312 { 313 $contentObjectAttribute =& $contentObjectAttributes[$key]; 314 $object->handleCustomHTTPActions( $contentObjectAttribute, $attributeDataBaseName, 315 $customActionAttributeArray, 316 array( 'module' => &$Module, 317 'current-redirection-uri' => $currentRedirectionURI ) ); 318 $contentObjectAttribute->setContent( $contentObjectAttribute->attribute( 'content' ) ); 319 } 320 eZContentObject::recursionProtectionEnd(); 321 } 322 323 $invalidNodeAssignmentList = array(); 324 if ( $Module->isCurrentAction( 'Publish' ) ) 325 { 326 $mainFound = false; 327 $assignments =& $version->attribute( 'parent_nodes' ); 328 $db =& eZDB::instance(); 329 $db->begin(); 330 foreach ( array_keys( $assignments ) as $key ) 331 { 332 // Check that node assignment node exists. 333 if ( !$assignments[$key]->attribute( 'parent_node_obj' ) ) 334 { 335 $validation[ 'placement' ][] = array( 'text' => ezi18n( 'kernel/content', 'A node in the node assignment list has been deleted.' ) ); 336 $validation[ 'processed' ] = true; 337 $inputValidated = false; 338 $invalidNodeAssignmentList[] = $assignments[$key]->attribute( 'parent_node' ); 339 $assignments[$key]->remove(); 340 unset( $assignments[$key] ); 341 eZDebugSetting::writeDebug( 'kernel-content-edit', "placement is not validated" ); 342 } 343 344 if ( isset( $assignments[$key] ) && 345 $assignments[$key]->attribute( 'is_main' ) == 1 ) 346 { 347 $mainFound = true; 348 break; 349 } 350 } 351 $db->commit(); 352 if ( !$mainFound and count( $assignments ) > 0 ) 353 { 354 if( eZPreferences::value( 'admin_edit_show_locations' ) == '0' ) 355 { 356 $validation[ 'placement' ][] = array( 'text' => ezi18n( 'kernel/content', 'No main node selected, please select one.' ) ); 357 $validation[ 'processed' ] = true; 358 $inputValidated = false; 359 eZDebugSetting::writeDebug( 'kernel-content-edit', "placement is not validated" ); 360 } 361 } 362 else 363 eZDebugSetting::writeDebug( 'kernel-content-edit', "placement is validated" ); 364 365 } 366 367 // After the object has been validated we can check for other actions 368 $Result = ''; 369 if ( $inputValidated == true ) 370 { 371 if ( $validatedAttributes == null ) 372 { 373 if ( $Module->runHooks( 'action_check', array( &$class, &$object, &$version, &$contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage, &$Result ) ) ) 374 return; 375 } 376 } 377 378 if ( isset( $Params['TemplateObject'] ) ) 379 $tpl =& $Params['TemplateObject']; 380 381 if ( !isset( $tpl ) || get_class( $tpl ) != 'eztemplate' ) 382 $tpl =& templateInit(); 383 384 $tpl->setVariable( 'validation', $validation ); 385 $tpl->setVariable( 'validation_log', $validatedAttributes ); 386 387 $tpl->setVariable( 'invalid_node_assignment_list', $invalidNodeAssignmentList ); 388 389 $Module->setTitle( 'Edit ' . $class->attribute( 'name' ) . ' - ' . $object->attribute( 'name' ) ); 390 $res =& eZTemplateDesignResource::instance(); 391 392 $assignments =& $version->attribute( 'parent_nodes' ); 393 $mainAssignment = false; 394 foreach ( array_keys( $assignments ) as $key ) 395 { 396 if ( $assignments[$key]->attribute( 'is_main' ) == 1 ) 397 { 398 $mainAssignment =& $assignments[$key]; 399 break; 400 } 401 } 402 403 $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), 404 array( 'class', $class->attribute( 'id' ) ), 405 array( 'class_identifier', $class->attribute( 'identifier' ) ) 406 ) ); 407 408 if ( $mainAssignment ) 409 { 410 $parentNode =& $mainAssignment->attribute( 'parent_node_obj' ); 411 if ( $parentNode ) 412 { 413 $parentObject =& $parentNode->attribute( 'object' ); 414 if ( $parentObject ) 415 { 416 $parentClass =& $parentObject->attribute( 'content_class' ); 417 if ( $parentClass ) 418 { 419 $res->setKeys( array( array( 'parent_class', $parentClass->attribute( 'id' ) ), 420 array( 'parent_class_identifier', $parentClass->attribute( 'identifier' ) ) 421 ) ); 422 } 423 } 424 } 425 } 426 427 if ( !isset( $OmitSectionSetting ) ) 428 $OmitSectionSetting = false; 429 if ( $OmitSectionSetting !== true ) 430 { 431 include_once ( 'kernel/classes/ezsection.php' ); 432 eZSection::setGlobalID( $object->attribute( 'section_id' ) ); 433 } 434 435 $contentObjectDataMap = array(); 436 foreach ( array_keys( $contentObjectAttributes ) as $contentObjectAttributeKey ) 437 { 438 $contentObjectAttribute =& $contentObjectAttributes[$contentObjectAttributeKey]; 439 $contentObjectAttributeIdentifier = $contentObjectAttribute->attribute( 'contentclass_attribute_identifier' ); 440 $contentObjectDataMap[$contentObjectAttributeIdentifier] =& $contentObjectAttribute; 441 } 442 443 $object->setCurrentLanguage( $EditLanguage ); 444 445 $tpl->setVariable( 'edit_version', $EditVersion ); 446 $tpl->setVariable( 'edit_language', $EditLanguage ); 447 $tpl->setVariable( 'from_language', $FromLanguage ); 448 $tpl->setVariable( 'content_version', $version ); 449 $tpl->setVariable( 'http', $http ); 450 $tpl->setVariable( 'content_attributes', $contentObjectAttributes ); 451 $tpl->setVariable( 'from_content_attributes', $fromContentObjectAttributes ); 452 $tpl->setVariable( 'is_translating_content', $isTranslatingContent ); 453 $tpl->setVariable( 'content_attributes_data_map', $contentObjectDataMap ); 454 $tpl->setVariable( 'class', $class ); 455 $tpl->setVariable( 'object', $object ); 456 $tpl->setVariable( 'attribute_base', $attributeDataBaseName ); 457 458 $locationUIEnabled = true; 459 // If the object has been published we disable the location UI 460 if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_DRAFT ) 461 { 462 $locationUIEnabled = false; 463 } 464 $tpl->setVariable( "location_ui_enabled", $locationUIEnabled ); 465 466 467 if ( $Module->runHooks( 'pre_template', array( &$class, &$object, &$version, &$contentObjectAttributes, $EditVersion, $EditLanguage, &$tpl, $FromLanguage ) ) ) 468 return; 469 470 $templateName = 'design:content/edit.tpl'; 471 472 if ( isset( $Params['TemplateName'] ) ) 473 $templateName = $Params['TemplateName']; 474 475 if ( isset( $Params['UserParameters'] ) ) 476 { 477 $UserParameters = $Params['UserParameters']; 478 } 479 else 480 { 481 $UserParameters = array(); 482 } 483 // $viewParameters contains $UserParameters only 484 $viewParameters = $UserParameters; 485 // "view_parameters" is available also in edit.tpl's templates 486 $tpl->setVariable( 'view_parameters', $viewParameters ); 487 488 $Result = array(); 489 $Result['content'] =& $tpl->fetch( $templateName ); 490 // $Result['path'] = array( array( 'text' => ezi18n( 'kernel/content', 'Content' ), 491 // 'url' => false ), 492 // array( 'text' => ezi18n( 'kernel/content', 'Edit' ), 493 // 'url' => false ), 494 // array( 'text' => $object->attribute( 'name' ), 495 // 'url' => false ) ); 496 497 $path = array(); 498 $titlePath = array(); 499 500 $hasPath = false; 501 if ( $mainAssignment ) 502 { 503 $parentNode =& $mainAssignment->attribute( 'parent_node_obj' ); 504 if ( $parentNode ) 505 { 506 $parents =& $parentNode->attribute( 'path' ); 507 508 foreach ( $parents as $parent ) 509 { 510 $path[] = array( 'text' => $parent->attribute( 'name' ), 511 'url' => '/content/view/full/' . $parent->attribute( 'node_id' ), 512 'url_alias' => $parent->attribute( 'url_alias' ), 513 'node_id' => $parent->attribute( 'node_id' ) 514 ); 515 } 516 517 if ( $parentNode->attribute( 'name' ) != null ) 518 { 519 $path[] = array( 'text' => $parentNode->attribute( 'name' ), 520 'url' => '/content/view/full/' . $parentNode->attribute( 'node_id' ), 521 'url_alias' => $parentNode->attribute( 'url_alias' ), 522 'node_id' => $parentNode->attribute( 'node_id' ) ); 523 } 524 525 $objectPathElement = array( 'text' => $object->attribute( 'name' ), 526 'url' => false, 527 'url_alias' => false ); 528 $existingNode = $object->attribute( 'main_node' ); 529 if ( $existingNode ) 530 { 531 $objectPathElement['url'] = '/content/view/full/' . $existingNode->attribute( 'node_id' ); 532 $objectPathElement['url_alias'] = $existingNode->attribute( 'url_alias' ); 533 $objectPathElement['node_id'] = $existingNode->attribute( 'node_id' ); 534 } 535 $path[] = $objectPathElement; 536 $hasPath = true; 537 } 538 } 539 if ( !$hasPath ) 540 { 541 $existingNode = $object->attribute( 'main_node' ); 542 if ( $existingNode ) 543 { 544 $parents =& $existingNode->attribute( 'path' ); 545 546 foreach ( $parents as $parent ) 547 { 548 $path[] = array( 'text' => $parent->attribute( 'name' ), 549 'url' => '/content/view/full/' . $parent->attribute( 'node_id' ), 550 'url_alias' => $parent->attribute( 'url_alias' ), 551 'node_id' => $parent->attribute( 'node_id' ) 552 ); 553 } 554 $path[] = array( 'text' => $existingNode->attribute( 'name' ), 555 'url' => '/content/view/full/' . $existingNode->attribute( 'node_id' ), 556 'url_alias' => $existingNode->attribute( 'url_alias' ), 557 'node_id' => $existingNode->attribute( 'node_id' ) ); 558 $hasPath = true; 559 } 560 } 561 if ( !$hasPath ) 562 { 563 $path[] = array( 'text' => $object->attribute( 'name' ), 564 'url' => false ); 565 } 566 567 $Result['path'] = $path; 568 569 include_once ( 'kernel/classes/ezsection.php' ); 570 $section = eZSection::fetch( $object->attribute( 'section_id' ) ); 571 if ( $section ) 572 $Result['navigation_part'] = $section->attribute( 'navigation_part_identifier' ); 573 574 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |