/** * Aggiorna la selezione delle tematiche da sincronizzare * @param eZHTTPTool $http */ public function modifySelection($http) { if ($http->hasPostVariable('BrowseActionName') && $http->postVariable('BrowseActionName') == 'SelectDestinationNodeID') { // Scelta del nodo di destinazione $nodeIDArray = $http->postVariable('SelectedNodeIDArray'); $this->object->setAttribute('destination_node_id', $nodeIDArray[0]); $this->object->store(); } else { // Abilitazione e disabilitazione delle tematiche $tematicheChanged = false; foreach ($http->attribute('post') as $key => $value) { $action = explode('_', $key); if ($action[0] == 'DisableTag') { if (($_key = array_search($value, $this->getTematiche())) !== false) { $_tematiche = $this->getTematiche(); unset($_tematiche[$_key]); $this->object->setAttribute('tags', implode(';', $_tematiche)); } $tematicheChanged = true; } else { if ($action[0] == 'EnableTag') { $_tematiche = $this->getTematiche(); $_tematiche[] = $value; $this->object->setAttribute('tags', implode(';', $_tematiche)); $tematicheChanged = true; } } } if ($tematicheChanged) { $this->object->store(); } } }
public static function getDateConditions(eZHTTPTool $http) { $start = false; $end = false; $days = false; $condition = null; $cieINI = eZINI::instance('cie.ini'); $exportUsingDaysCalcualation = $cieINI->variable('CieSettings', 'ExportUsingDaysCalcualation') == 'enabled' ? true : false; if ($http->hasPostVariable("start_year") && $http->postVariable("start_year") != '') { $start = mktime(0, 0, 0, (int) $http->postVariable("start_month"), (int) $http->postVariable("start_day"), (int) $http->postVariable("start_year")); } if ($http->hasPostVariable("end_year") && $http->postVariable("end_year") != '') { $end = mktime(23, 59, 59, (int) $http->postVariable("end_month"), (int) $http->postVariable("end_day"), (int) $http->postVariable("end_year")); } if ($exportUsingDaysCalcualation && ($start !== false and $end !== false)) { $days = round(abs($start - $end) / 86400); } if ($start !== false and $end !== false) { $condition = array(false, array($start, $end)); } elseif ($start !== false and $end === false) { $condition = array('>', $start); } elseif ($start === false and $end !== false) { $condition = array('<', $end); } return array('conditions' => $condition, 'days' => $days); }
protected static function validateConfirmation(eZHTTPTool $http, $base, eZContentObjectAttribute $attribute, $isCollection = false) { $field = $attributeName = $base . '_attributeconfirmation_' . $attribute->attribute('id'); $value = $http->postVariable($field, null); if (empty($value)) { if ((bool) $attribute->attribute('is_required')) { $attribute->setValidationError(ezpI18n::tr('extension/attributeconfirmation', 'Input required.')); return eZInputValidator::STATE_INVALID; } else { return eZInputValidator::STATE_ACCEPTED; } } $attributeToConfirm = $attribute->attribute('contentclass_attribute')->attribute(self::FIELD_ATTRIBUTE); $attributeToConfirmValue = null; $version = $attribute->attribute('object_version'); $dataMap = $version->attribute('data_map'); if ($isCollection) { if (isset($dataMap[$attributeToConfirm])) { $attributeID = $dataMap[$attributeToConfirm]->attribute('id'); $fields = array_keys($_POST); foreach ($fields as $field) { if (preg_match('/^' . $base . '.*' . $attributeID . '$/i', $field) === 1) { $attributeToConfirmValue = $http->postVariable($field, null); break; } } } } else { if (isset($dataMap[$attributeToConfirm])) { $attributeToConfirmValue = $dataMap[$attributeToConfirm]->attribute('content'); } } if (empty($attributeToConfirmValue)) { return eZInputValidator::STATE_ACCEPTED; } if ($attributeToConfirmValue != $value) { $attribute->setValidationError(ezpI18n::tr('extension/attributeconfirmation', 'Input does not match.')); return eZInputValidator::STATE_INVALID; } return eZInputValidator::STATE_ACCEPTED; }
/** * Fetches the HTTP POST input and stores it in the data instance * * @param eZHTTPTool $http * @param string $base * @param eZContentObjectAttribute $contentObjectAttribute * * @return bool */ function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute) { $classList = $http->postVariable($base . self::CLASS_LIST_VARIABLE . $contentObjectAttribute->attribute("id"), array()); $classList = !is_array($classList) ? array() : $classList; $validClassIdentifiers = array(); foreach ($classList as $classIdentifier) { if (eZContentClass::exists($classIdentifier, eZContentClass::VERSION_STATUS_DEFINED, false, true)) { $validClassIdentifiers[] = $classIdentifier; } } if (!empty($validClassIdentifiers)) { $contentObjectAttribute->setAttribute(self::CLASS_LIST_FIELD, implode(",", $validClassIdentifiers)); } else { $contentObjectAttribute->setAttribute(self::CLASS_LIST_FIELD, ""); } return true; }
/** * Checks if a post variable exitst and has a value * * @param eZHTTPTool $http * @param string $key * @return bool */ protected static function hasPostValue(eZHTTPTool $http, $key, $falseValue = '') { return $http->hasPostVariable($key) && $http->postVariable($key) !== $falseValue; }
/** * 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; } }
/** * Checks if current HTTP request is asking for current binary file deletion * @param eZHTTPTool $http * @param eZContentObjectAttribute $contentObjectAttribute * @return bool */ private function isDeletingFile( eZHTTPTool $http, eZContentObjectAttribute $contentObjectAttribute ) { $isDeletingFile = false; if ( $http->hasPostVariable( 'CustomActionButton' ) ) { $customActionArray = $http->postVariable( 'CustomActionButton' ); $attributeID = $contentObjectAttribute->attribute( 'id' ); if ( isset( $customActionArray[$attributeID . '_delete_binary'] ) ) { $isDeletingFile = true; } } return $isDeletingFile; }
/** * Loops over the HTTP post variables with $base_name as the base. * It examines the HTTP post variable $base_name "_" $cond "_checked" * which should contain an array of ids. The ids are then matched against * the objects attribute $cond. If they match the object is moved to the * $rejects array otherwise the $keepers array. * * @param string $base_name * @param object[] $objects * @param eZHTTPTool $http * @param $cond * @param $keepers * @param $rejects * @return boolean */ static function splitSelected( $base_name, $objects, eZHTTPTool $http, $cond, &$keepers, &$rejects ) { $keepers = array(); $rejects = array(); $post_var = $base_name . "_" . $cond . "_checked"; if ( $http->hasPostVariable( $post_var ) ) { $checks = $http->postVariable( $post_var ); } else { return false; } foreach( $objects as $object ) { if ( $object->hasAttribute( $cond ) ) { $val = $object->attribute( $cond ); if ( in_array( $val, $checks ) ) { $rejects[] = $object; } else { $keepers[] = $object; } } else { $keepers[] = $object; } } return true; }
/** * Fetches the HTTP POST input and stores it in the data instance * * @param eZInformationCollection $collection * @param eZInformationCollectionAttribute $collectionAttribute * @param eZHTTPTool $http * @param string $base * @param eZContentObjectAttribute $contentObjectAttribute * * @return bool */ function fetchCollectionAttributeHTTPInput($collection, $collectionAttribute, $http, $base, $contentObjectAttribute) { if ($http->hasPostVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id"))) { $data = trim($http->postVariable($base . self::OIB_VARIABLE . $contentObjectAttribute->attribute("id"))); $collectionAttribute->setAttribute(self::OIB_FIELD, $data); return true; } return false; }
/** * Fetches class attribute HTTP input and stores it * * @param eZHTTPTool $http * @param string $base * @param eZContentClassAttribute $attribute * * @return bool */ public function fetchClassAttributeHTTPInput($http, $base, $attribute) { $classAttributeID = $attribute->attribute('id'); $subTreeLimit = (int) $http->postVariable($base . self::SUBTREE_LIMIT_VARIABLE . $classAttributeID, -1); $maxTags = (int) trim($http->postVariable($base . self::MAX_TAGS_VARIABLE . $classAttributeID, -1)); if ($subTreeLimit < 0 || $maxTags < 0) { return false; } $showDropdown = (int) $http->hasPostVariable($base . self::SHOW_DROPDOWN_VARIABLE . $classAttributeID); $hideRootTag = (int) $http->hasPostVariable($base . self::HIDE_ROOT_TAG_VARIABLE . $classAttributeID); $attribute->setAttribute(self::SUBTREE_LIMIT_FIELD, $subTreeLimit); $attribute->setAttribute(self::SHOW_DROPDOWN_FIELD, $showDropdown); $attribute->setAttribute(self::HIDE_ROOT_TAG_FIELD, $hideRootTag); $attribute->setAttribute(self::MAX_TAGS_FIELD, $maxTags); return true; }
/** * @param eZHTTPTool $http * @param $base * @param eZWorkflowEvent $workflowEvent * @param $validation * * @return bool|int */ function validateHTTPInput($http, $base, $workflowEvent, &$validation) { $returnState = eZInputValidator::STATE_ACCEPTED; $reason = array(); if (!$http->hasSessionVariable('BrowseParameters')) { // No validation when deleting to avoid blocking deletion of invalid items if ($http->hasPostVariable('DeleteApproveUserIDArray_' . $workflowEvent->attribute('id')) || $http->hasPostVariable('DeleteApproveGroupIDArray_' . $workflowEvent->attribute('id'))) { return eZInputValidator::STATE_ACCEPTED; } // check approve-users $approversIDs = array_unique($this->attributeDecoder($workflowEvent, 'approve_users')); if (is_array($approversIDs) and count($approversIDs) > 0) { $returnState = eZApproveType::validateUserIDList($approversIDs, $reason); } else { $returnState = false; } if ($returnState != eZInputValidator::STATE_INVALID) { // check approve-groups $userGroupIDList = array_unique($this->attributeDecoder($workflowEvent, 'approve_groups')); if (is_array($userGroupIDList) and count($userGroupIDList) > 0) { $returnState = eZApproveType::validateGroupIDList($userGroupIDList, $reason); } else { if ($returnState === false) { // if no one user or user-group was passed as approvers $returnState = eZInputValidator::STATE_INVALID; $reason['text'] = "There must be passed at least one valid user or user group who approves content for the event."; } } // check excluded-users /* if ( $returnState != eZInputValidator::STATE_INVALID ) { // TODO: // .... } */ // check excluded-groups if ($returnState != eZInputValidator::STATE_INVALID) { $userGroupIDList = array_unique($this->attributeDecoder($workflowEvent, 'selected_usergroups')); if (is_array($userGroupIDList) and count($userGroupIDList) > 0) { $returnState = eZApproveType::validateGroupIDList($userGroupIDList, $reason); } } } } else { $browseParameters = $http->sessionVariable('BrowseParameters'); if (isset($browseParameters['custom_action_data'])) { $customData = $browseParameters['custom_action_data']; if (isset($customData['event_id']) and $customData['event_id'] == $workflowEvent->attribute('id')) { if (!$http->hasPostVariable('BrowseCancelButton') and $http->hasPostVariable('SelectedObjectIDArray')) { $objectIDArray = $http->postVariable('SelectedObjectIDArray'); if (is_array($objectIDArray) and count($objectIDArray) > 0) { switch ($customData['browse_action']) { case "AddApproveUsers": $returnState = eZApproveType::validateUserIDList($objectIDArray, $reason); break; case 'AddApproveGroups': case 'AddExcludeUser': $returnState = eZApproveType::validateGroupIDList($objectIDArray, $reason); break; case 'AddExcludedGroups': // TODO: // ..... break; } } } } } } if ($returnState == eZInputValidator::STATE_INVALID) { $validation['processed'] = true; $validation['events'][] = array('id' => $workflowEvent->attribute('id'), 'placement' => $workflowEvent->attribute('placement'), 'workflow_type' => &$this, 'reason' => $reason); } return $returnState; }
<?php $Module = $Params['Module']; $NodeID = $Params['NodeID']; $node = false; $tpl = eZTemplate::factory(); $errors = array(); /// @todo send more errors in case node/object does not exist, etc... if ($node = eZContentObjectTreeNode::fetch($NodeID)) { if ($Module->currentAction() == 'UpdateRemoteID') { // test values $inputObjectName = 'jcremoteid_object'; $inputNodeListName = 'jcremoteid_node_list'; $http = new eZHTTPTool(); $object = $node->attribute('object'); if ($http->hasPostVariable($inputObjectName) && jcRemoteID::isValidObjectRemoteID($http->postVariable($inputObjectName), $object->attribute('id'), $errors)) { $object->setAttribute('remote_id', $http->postVariable($inputObjectName)); $object->store(); } if ($http->hasPostVariable($inputNodeListName) && is_array($http->postVariable($inputNodeListName))) { $remoteIDNodeList = $http->postVariable($inputNodeListName); foreach ($object->attribute('assigned_nodes') as $node_item) { $node_item_id = $node_item->attribute('node_id'); if (isset($remoteIDNodeList[$node_item_id]) && jcRemoteID::isValidNodeRemoteID($remoteIDNodeList[$node_item_id], $node_item_id, $errors)) { $node_item->setAttribute('remote_id', $remoteIDNodeList[$node_item_id]); $node_item->store(); if ($node_item_id == $NodeID) { //update $node for template if errors $node = $node_item; } }
/** * Fetches class attribute HTTP input and stores it * * @param eZHTTPTool $http * @param string $base * @param eZContentClassAttribute $attribute * @return bool */ function fetchClassAttributeHTTPInput($http, $base, $attribute) { $maxTagsName = $base . self::MAX_TAGS_VARIABLE . $attribute->attribute('id'); if (!$http->hasPostVariable($maxTagsName) || !is_numeric($http->postVariable($maxTagsName)) && trim($http->postVariable($maxTagsName)) != '') { return false; } $subTreeLimitName = $base . self::SUBTREE_LIMIT_VARIABLE . $attribute->attribute('id'); if (!$http->hasPostVariable($subTreeLimitName) || (int) $http->postVariable($subTreeLimitName) < 0) { return false; } $data = (int) $http->postVariable($subTreeLimitName); $data2 = 0; if ($http->hasPostVariable($base . self::SHOW_DROPDOWN_VARIABLE . $attribute->attribute('id'))) { $data2 = 1; } $data3 = 0; if ($http->hasPostVariable($base . self::HIDE_ROOT_TAG_VARIABLE . $attribute->attribute('id'))) { $data3 = 1; } $data4 = (int) trim($http->postVariable($maxTagsName)); $attribute->setAttribute(self::SUBTREE_LIMIT_FIELD, $data); $attribute->setAttribute(self::SHOW_DROPDOWN_FIELD, $data2); $attribute->setAttribute(self::HIDE_ROOT_TAG_FIELD, $data3); $attribute->setAttribute(self::MAX_TAGS_FIELD, $data4 < 0 ? 0 : $data4); return true; }
/** * @param eZHTTPTool $http * @param eZModule $module * @return void */ function fetchHttpInput($http, $module) { if ($http->hasPostVariable('RemoveRule_' . self::NOTIFICATION_HANDLER_ID)) { $user = eZUser::currentUser(); $listID = array(); $userList = ITNewsletterNotificationRule::fetchList($user->attribute('contentobject_id'), false); foreach ($userList as $userRow) { $listID[] = $userRow['id']; } $ruleIDList = $http->postVariable('RemoveRule_' . self::NOTIFICATION_HANDLER_ID); foreach ($ruleIDList as $ruleID) { if (in_array($ruleID, $listID)) { eZPersistentObject::removeObject(ITNewsletterNotificationRule::definition(), array('id' => $ruleID)); } } } else { if ($http->hasPostVariable('SaveRule_' . self::NOTIFICATION_HANDLER_ID)) { $tagID = $http->postVariable('SaveRule_' . self::NOTIFICATION_HANDLER_ID); $user = eZUser::currentUser(); $existingTags = ITNewsletterNotificationRule::fetchTagsForUserID($user->attribute('contentobject_id'), false); if (!in_array($tagID, $existingTags)) { $rule = ITNewsletterNotificationRule::create($tagID, $user->attribute('contentobject_id')); $rule->store(); } } } }
/** * Fetches class attribute HTTP input and stores it * * @param eZHTTPTool $http * @param string $base * @param eZContentClassAttribute $attribute * * @return bool */ function fetchClassAttributeHTTPInput($http, $base, $attribute) { $base; // Just for phpcs if ($http->hasPostVariable("ContentClass_novaseometas_keyvalue_{$attribute->attribute('id')}")) { $metasKv = $http->postVariable("ContentClass_novaseometas_keyvalue_{$attribute->attribute('id')}"); $attribute->setContent($metasKv); } return true; }
/** * Fetches all variables from the object and handles them * Data store can be done here * @param eZHTTPTool $http * @param string $base POST variable name prefix (Always "ContentObjectAttribute") * @param eZContentObjectAttribute $contentObjectAttribute * @return true if fetching of class attributes are successfull, false if not */ public function fetchObjectAttributeHTTPInput($http, $base, $contentObjectAttribute) { if ($http->hasPostVariable($base . '_accolorpicker_data_text_' . $contentObjectAttribute->attribute('id'))) { $data = $http->postVariable($base . '_accolorpicker_data_text_' . $contentObjectAttribute->attribute('id')); $contentObjectAttribute->setAttribute('data_text', $data); } return true; }
/** * Validates input from user registration form * * @param eZHTTPTool $http * * @return array */ public static function validateUserInput($http) { if ($http->hasPostVariable('data_user_login') && $http->hasPostVariable('data_user_email') && $http->hasPostVariable('data_user_password') && $http->hasPostVariable('data_user_password_confirm')) { $loginName = $http->postVariable('data_user_login'); $email = $http->postVariable('data_user_email'); $password = $http->postVariable('data_user_password'); $passwordConfirm = $http->postVariable('data_user_password_confirm'); if (trim($loginName) == '') { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The username must be specified.')); } else { $existUser = eZUser::fetchByName($loginName); if ($existUser != null) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The username already exists, please choose another one.')); } // validate user email $isValidate = eZMail::validate($email); if (!$isValidate) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The email address is not valid.')); } $authenticationMatch = eZUser::authenticationMatch(); if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) { if (eZUser::requireUniqueEmail()) { $userByEmail = eZUser::fetchByEmail($email); if ($userByEmail != null) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'A user with this email already exists.')); } } } // validate user name if (!eZUser::validateLoginName($loginName, $errorText)) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', $errorText)); } // validate user password $ini = eZINI::instance(); $generatePasswordIfEmpty = $ini->variable("UserSettings", "GeneratePasswordIfEmpty") == 'true'; if (!$generatePasswordIfEmpty || $password != "") { if ($password == "") { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password cannot be empty.', 'eZUserType')); } if ($password != $passwordConfirm) { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The passwords do not match.', 'eZUserType')); } if (!eZUser::validatePassword($password)) { $minPasswordLength = $ini->hasVariable('UserSettings', 'MinPasswordLength') ? $ini->variable('UserSettings', 'MinPasswordLength') : 3; return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password must be at least %1 characters long.', null, array($minPasswordLength))); } if (strtolower($password) == 'password') { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'The password must not be "password".')); } } } } else { return array('status' => 'error', 'message' => ezpI18n::tr('kernel/classes/datatypes', 'Input required.')); } return array('status' => 'success'); }
/** * Validates content object attribute HTTP input * * @param eZHTTPTool $http * @param string $base * @param eZContentObjectAttribute $contentObjectAttribute * @param bool $isInformationCollection * * @return int */ protected function validateAttributeHTTPInput($http, $base, $contentObjectAttribute, $isInformationCollection = false) { /** @var eZContentClassAttribute $classAttribute */ $classAttribute = $contentObjectAttribute->contentClassAttribute(); $classContent = $classAttribute->content(); $infoCollectionCheck = $isInformationCollection == $classAttribute->attribute('is_information_collector'); $isRequired = $contentObjectAttribute->validateIsRequired(); $selectionName = join('_', array($base, 'sckenhancedselection_selection', $contentObjectAttribute->attribute('id'))); if ($http->hasPostVariable($selectionName)) { $selection = $http->postVariable($selectionName); if ($infoCollectionCheck) { switch (true) { case $isRequired === true && count($selection) == 0: case $isRequired === true && count($selection) == 1 && empty($selection[0]): $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.')); return eZInputValidator::STATE_INVALID; } } } else { if ($infoCollectionCheck && $isRequired && $classContent['is_multiselect'] == 1) { $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'This is a required field.')); } else { if ($infoCollectionCheck && $isRequired) { $contentObjectAttribute->setValidationError(ezpI18n::tr('extension/enhancedselection2/datatypes', 'No POST variable. Please check your configuration.')); } else { return eZInputValidator::STATE_ACCEPTED; } } return eZInputValidator::STATE_INVALID; } return eZInputValidator::STATE_ACCEPTED; }
/** * Set parameters from post data, expects post data to be validated by * {@link eZGmapLocationType::validateObjectAttributeHTTPInput()} * * @param eZHTTPTool $http * @param string $base * @param eZContentObjectAttribute $contentObjectAttribute */ function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) { $validPostData = false; if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) && $http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) ) { $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ); $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ); $validPostData = $latitude !== '' && $longitude !== '' && is_numeric( $latitude ) && is_numeric( $longitude ); } if ( $validPostData ) { $address = ''; if ( $http->hasPostVariable( $base . '_data_gmaplocation_address_' . $contentObjectAttribute->attribute( 'id' ) ) ) { $address = $http->postVariable( $base . '_data_gmaplocation_address_' . $contentObjectAttribute->attribute( 'id' ) ); $address = htmlentities( $address, ENT_QUOTES , 'UTF-8' ); } if ( $contentObjectAttribute->attribute( 'data_int' ) != 0 ) { $location = eZGmapLocation::fetch( $contentObjectAttribute->attribute('id'), $contentObjectAttribute->attribute('version') ); $location->setAttribute( 'latitude', $latitude ); $location->setAttribute( 'longitude', $longitude ); $location->setAttribute( 'address', $address ); } else { $location = new eZGmapLocation( array( 'contentobject_attribute_id' => $contentObjectAttribute->attribute('id'), 'contentobject_version' => $contentObjectAttribute->attribute('version'), 'latitude' => $latitude, 'longitude' => $longitude, 'address' => $address ) ); $contentObjectAttribute->setAttribute( 'data_int', 1 ); } $contentObjectAttribute->setContent( $location ); } else if ( $contentObjectAttribute->attribute( 'data_int' ) != 0 ) { $contentObjectAttribute->setAttribute( 'data_int', 0 ); eZGmapLocation::removeById( $contentObjectAttribute->attribute('id'), $contentObjectAttribute->attribute('version') ); } return true; }
function isHuman(eZHTTPTool $http, $secretKey) { if (!$http->hasPostVariable('g-recaptcha-response')) { return false; } $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretKey . "&response=" . $http->postVariable('g-recaptcha-response')), true); return $response["success"]; }