/** * Executes a custom action for an object attribute which was defined on the web page. * * @param eZHTTPTool $http * @param string $action * @param eZContentObjectAttribute $contentObjectAttribute * @param array $parameters */ function customObjectAttributeHTTPAction($http, $action, $contentObjectAttribute, $parameters) { $params = explode('-', $action); switch ($params[0]) { case 'new_zone_layout': if ($http->hasPostVariable('ContentObjectAttribute_ezpage_zone_allowed_type_' . $contentObjectAttribute->attribute('id'))) { $zoneMap = array(); if ($http->hasPostVariable('ContentObjectAttribute_ezpage_zone_map')) { $zoneMap = $http->postVariable('ContentObjectAttribute_ezpage_zone_map'); } $zoneINI = eZINI::instance('zone.ini'); $page = $contentObjectAttribute->content(); $zoneAllowedType = $http->postVariable('ContentObjectAttribute_ezpage_zone_allowed_type_' . $contentObjectAttribute->attribute('id')); if ($zoneAllowedType == $page->attribute('zone_layout')) { return false; } $allowedZones = $zoneINI->variable($zoneAllowedType, 'Zones'); $allowedZonesCount = count($allowedZones); $page->setAttribute('zone_layout', $zoneAllowedType); $existingZoneCount = $page->getZoneCount(); $zoneCountDiff = 0; if ($allowedZonesCount < $existingZoneCount) { $zoneCountDiff = $existingZoneCount - $allowedZonesCount; } if (count($zoneMap) > 0) { foreach ($page->attribute('zones') as $zoneIndex => $zone) { $zoneMapKey = array_search($zone->attribute('zone_identifier'), $zoneMap); if ($zoneMapKey) { $zone->setAttribute('action', 'modify'); $zone->setAttribute('zone_identifier', $zoneMapKey); } else { if ($zone->toBeAdded()) { $page->removeZone($zoneIndex); } else { $zone->setAttribute('action', 'remove'); } } } } else { foreach ($allowedZones as $index => $zoneIdentifier) { $existingZone = $page->getZone($index); if ($existingZone instanceof eZPageZone) { $existingZone->setAttribute('action', 'modify'); $existingZone->setAttribute('zone_identifier', $zoneIdentifier); } else { $newZone = $page->addZone(new eZPageZone()); $newZone->setAttribute('id', md5(mt_rand() . microtime() . $page->getZoneCount())); $newZone->setAttribute('zone_identifier', $zoneIdentifier); $newZone->setAttribute('action', 'add'); } } if ($zoneCountDiff > 0) { while ($zoneCountDiff != 0) { $existingZoneIndex = $existingZoneCount - $zoneCountDiff; $existingZone = $page->getZone($existingZoneIndex); if ($existingZone->toBeAdded()) { $page->removeZone($existingZoneIndex); } else { $existingZone->setAttribute('action', 'remove'); } $zoneCountDiff -= 1; } } } $page->sortZones(); } break; case 'set_rotation': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $rotationValue = $http->postVariable('RotationValue_' . $params[2]); $rotationUnit = $http->postVariable('RotationUnit_' . $params[2]); $rotationSuffle = $http->postVariable('RotationShuffle_' . $params[2]); if ($rotationValue == '') { $block->setAttribute('rotation', array('interval' => 0, 'type' => 0, 'value' => '', 'unit' => '')); } else { switch ($rotationUnit) { case '2': $rotationInterval = $rotationValue * 60; break; case '3': $rotationInterval = $rotationValue * 3600; break; case '4': $rotationInterval = $rotationValue * 86400; default: break; } $rotationType = 1; if ($rotationSuffle) { $rotationType = 2; } $block->setAttribute('rotation', array('interval' => $rotationInterval, 'type' => $rotationType, 'value' => $rotationValue, 'unit' => $rotationUnit)); } break; case 'remove_block': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if ($block->toBeAdded()) { $zone->removeBlock($params[2]); } else { $block->setAttribute('action', 'remove'); } break; case 'new_block': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); if ($http->hasPostVariable('ContentObjectAttribute_ezpage_block_type_' . $contentObjectAttribute->attribute('id') . '_' . $params[1])) { $blockType = $http->postVariable('ContentObjectAttribute_ezpage_block_type_' . $contentObjectAttribute->attribute('id') . '_' . $params[1]); } if ($http->hasPostVariable('ContentObjectAttribute_ezpage_block_name_' . $contentObjectAttribute->attribute('id') . '_' . $params[1])) { $blockName = $http->postVariable('ContentObjectAttribute_ezpage_block_name_' . $contentObjectAttribute->attribute('id') . '_' . $params[1]); } $block = $zone->addBlock(new eZPageBlock($blockName)); $block->setAttribute('action', 'add'); $block->setAttribute('id', md5(mt_rand() . microtime() . $zone->getBlockCount())); $block->setAttribute('zone_id', $zone->attribute('id')); $block->setAttribute('type', $blockType); break; case 'move_block_up': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $zone->moveBlockUp($params[2]); break; case 'move_block_down': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $zone->moveBlockDown($params[2]); break; case 'new_item': if ($http->hasPostVariable('SelectedNodeIDArray')) { if (!$http->hasPostVariable('BrowseCancelButton')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $page = $contentObjectAttribute->content(); $zone = null; $block = null; if (isset($params[1]) && $page instanceof eZPage) { $zone = $page->getZone($params[1]); } if ($zone instanceof eZPageZone) { $block = $zone->getBlock($params[2]); } if ($block instanceof eZPageBlock) { foreach ($selectedNodeIDArray as $index => $nodeID) { $object = eZContentObject::fetchByNodeID($nodeID); if (!$object instanceof eZContentObject) { return false; } $objectID = $object->attribute('id'); //judge the list if there is a same item in history $itemAdded = false; $itemValid = false; $historyItems = $block->attribute('archived'); foreach ($historyItems as $historyItem) { if ($historyItem->attribute('object_id') == $objectID) { $itemAdded = $historyItem; } } $validItems = $block->attribute('valid'); foreach ($validItems as $validItem) { if ($validItem->attribute('object_id') == $objectID) { $itemValid = $validItem; } } //judge if the item will be removed $itemToBeRemoved = false; if ($block->getItemCount() > 0) { foreach ($block->attribute('items') as $itemID => $item) { if ($item->attribute('object_id') == $objectID) { if ($item->toBeRemoved()) { $itemToBeRemoved = true; $itemAdded = $item; } } } } if ($itemAdded || $itemToBeRemoved) { //if there is same item in history, or item to be removed (in history or valid), set the item in history to be modified // if item is not to be removed, add to the block since it's not in block ,but in history or valid if (!$itemToBeRemoved) { $block->addItem($itemAdded); } $itemAdded->setXMLStorable(true); $itemAdded->setAttribute('node_id', $nodeID); $itemAdded->setAttribute('priority', $block->getItemCount()); $itemAdded->setAttribute('ts_publication', time()); $itemAdded->setAttribute('ts_visible', '0'); $itemAdded->setAttribute('ts_hidden', '0'); $itemAdded->setAttribute('action', 'modify'); } else { if (!$itemValid) { //if there is no same item in history and valid, also the item is not to be removed, add new $item = $block->addItem(new eZPageBlockItem()); $item->setAttribute('object_id', $objectID); $item->setAttribute('node_id', $nodeID); $item->setAttribute('priority', $block->getItemCount()); $item->setAttribute('ts_publication', time()); $item->setAttribute('action', 'add'); } } } } $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); } } break; case 'new_item_browse': $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $type = $block->attribute('type'); $blockINI = eZINI::instance('block.ini'); $classArray = false; if ($blockINI->hasVariable($type, 'AllowedClasses')) { $classArray = $blockINI->variable($type, 'AllowedClasses'); } eZContentBrowse::browse(array('class_array' => $classArray, 'action_name' => 'AddNewBlockItem', 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_new_item-' . $params[1] . '-' . $params[2] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'new_source': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if ($http->hasPostVariable('SelectedNodeIDArray')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $blockINI = eZINI::instance('block.ini'); $fetchParametersSelectionType = $blockINI->variable($block->attribute('type'), 'FetchParametersSelectionType'); $fetchParams = unserialize($block->attribute('fetch_params')); if ($fetchParametersSelectionType['Source'] == 'single') { $fetchParams['Source'] = $selectedNodeIDArray[0]; } else { $fetchParams['Source'] = $selectedNodeIDArray; } $block->setAttribute('fetch_params', serialize($fetchParams)); $persBlockObject = eZFlowBlock::fetch($block->attribute('id')); if ($persBlockObject instanceof eZFlowBlock) { $persBlockObject->setAttribute('last_update', 0); $persBlockObject->store(); } } $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); break; case 'new_source_browse': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $blockINI = eZINI::instance('block.ini'); $fetchParametersSelectionType = $blockINI->variable($block->attribute('type'), 'FetchParametersSelectionType'); $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; eZContentBrowse::browse(array('action_name' => 'AddNewBlockSource', 'selection' => $fetchParametersSelectionType['Source'], 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_new_source-' . $params[1] . '-' . $params[2] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'custom_attribute': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); if (!$http->hasPostVariable('BrowseCancelButton')) { $customAttributes = $block->attribute('custom_attributes'); if ($http->hasPostVariable('SelectedNodeIDArray')) { $selectedNodeIDArray = $http->postVariable('SelectedNodeIDArray'); $customAttributes[$params[3]] = $selectedNodeIDArray[0]; } $block->setAttribute('custom_attributes', $customAttributes); $contentObjectAttribute->setContent($page); $contentObjectAttribute->store(); } break; case 'custom_attribute_browse': $module = $parameters['module']; $redirectionURI = $redirectionURI = $parameters['current-redirection-uri']; eZContentBrowse::browse(array('action_name' => 'CustomAttributeBrowse', 'browse_custom_action' => array('name' => 'CustomActionButton[' . $contentObjectAttribute->attribute('id') . '_custom_attribute-' . $params[1] . '-' . $params[2] . '-' . $params[3] . ']', 'value' => $contentObjectAttribute->attribute('id')), 'from_page' => $redirectionURI, 'cancel_page' => $redirectionURI, 'persistent_data' => array('HasObjectInput' => 0)), $module); break; case 'remove_item': $page = $contentObjectAttribute->content(); $zone = $page->getZone($params[1]); $block = $zone->getBlock($params[2]); $deleteItemIDArray = $http->postVariable('DeleteItemIDArray'); if ($block->getItemCount() > 0) { foreach ($block->attribute('items') as $itemID => $item) { foreach ($deleteItemIDArray as $index => $deleteItemID) { if ($item->attribute('object_id') == $deleteItemID) { if ($item->toBeAdded()) { $block->removeItem($itemID); unset($deleteItemIDArray[$index]); } elseif ($item->toBeModified()) { $block->removeItem($itemID); } } } } } foreach ($deleteItemIDArray as $deleteItemID) { $item = $block->addItem(new eZPageBlockItem()); $item->setAttribute('object_id', $deleteItemID); $item->setAttribute('action', 'remove'); } break; default: break; } }
/** * Returns eZFlowBlock object for current pool item * * @return eZFlowBlock|null */ public function block() { return eZFlowBlock::fetch($this->attribute('block_id')); }