/** * @group issue18073 * @link http://issues.ez.no/18073 */ public function testUnauthorizedContentByObject() { $this->setExpectedException('ezpContentAccessDeniedException'); // Let's take content node #5 / object #4 (users) as unauthorized content for anonymous user $unauthorizedObjectID = 4; $content = ezpContent::fromObject(eZContentObject::fetch($unauthorizedObjectID)); }
/** * Runs a content repository query using a given set of criteria * * @param ezpContentCriteria $criteria * @return ezpContentList */ public static function query(ezpContentCriteria $criteria) { $fetchParams = self::translateFetchParams($criteria); $nodes = eZContentObjectTreeNode::subTreeByNodeID($fetchParams->params, $fetchParams->rootNodeId); $return = array(); foreach ($nodes as $node) { $return[] = ezpContent::fromNode($node); } return $return; }
/** * Tests service links for content fields * @group restContentServices * @dataProvider requestObjectProvider * @param ezpRestRequest $request * @param int $nodeId */ public function testFieldsLinksByContent(ezpRestRequest $request, $nodeId) { $mvcConfig = new ezpMvcConfiguration(); $mvcConfig->runPreRoutingFilters($request); $baseUri = $request->getBaseURI(); $contentQueryString = $request->getContentQueryString(true); $content = ezpContent::fromNodeId($nodeId); $links = ezpRestContentModel::getFieldsLinksByContent($content, $request); self::assertInternalType(PHPUnit_Framework_Constraint_IsType::TYPE_ARRAY, $links); self::assertArrayHasKey('*', $links, 'Links for fields services must contain a wildcard (*) pointing to a service listing all fields content'); // * stands for all fields self::assertEquals($baseUri . '/fields' . $contentQueryString, $links['*']); // We must have one entry per field foreach ($content->fields as $fieldName => $field) { self::assertArrayHasKey($fieldName, $links, "Service link missing for {$fieldName}"); self::assertEquals($baseUri . '/field/' . $fieldName . $contentQueryString, $links[$fieldName], "Wrong service link for {$fieldName}"); } }
public function doViewFields() { $this->setDefaultResponseGroups(array(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)); $isNodeRequested = false; if (isset($this->nodeId)) { $content = ezpContent::fromNodeId($this->nodeId); $isNodeRequested = true; } else { if (isset($this->objectId)) { $content = ezpContent::fromObjectId($this->objectId); } } $result = new ezpRestMvcResult(); // translation parameter if ($this->hasContentVariable('Translation')) { $content->setActiveLanguage($this->getContentVariable('Translation')); } // Handle field values if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)) { $result->variables['fields'] = ITOpenDataContentModel::getFieldsByContent($content, $this->request, $this->getRouter()); } // Handle object/node metadata if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGORUP_METADATA)) { $objectMetadata = ITOpenDataContentModel::getMetadataByContent($content); if ($isNodeRequested) { $nodeMetadata = ITOpenDataContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId)); $objectMetadata = array_merge($objectMetadata, $nodeMetadata); } $result->variables['metadata'] = $objectMetadata; } return $result; }
/** * Handles a content unique field request through an object or node ID * * Requests: * - GET /api/content/node/:nodeId/field/:fieldIdentifier * - GET /api/content/object/:objectId/field/:fieldIdentifier * * @return ezpRestMvcResult */ public function doViewField() { $this->setDefaultResponseGroups(array(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)); $isNodeRequested = false; if (isset($this->nodeId)) { $isNodeRequested = true; $content = ezpContent::fromNodeId($this->nodeId); } else { if (isset($this->objectId)) { $content = ezpContent::fromObjectId($this->objectId); } } if (!isset($content->fields->{$this->fieldIdentifier})) { throw new ezpContentFieldNotFoundException("'{$this->fieldIdentifier}' field is not available for this content."); } // Translation parameter if ($this->hasContentVariable('Translation')) { $content->setActiveLanguage($this->getContentVariable('Translation')); } $result = new ezpRestMvcResult(); // Field data if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGROUP_FIELDVALUES)) { $result->variables['fields'][$this->fieldIdentifier] = ezpRestContentModel::attributeOutputData($content->fields->{$this->fieldIdentifier}); } // Handle object/node metadata if ($this->hasResponseGroup(self::VIEWFIELDS_RESPONSEGORUP_METADATA)) { $objectMetadata = ezpRestContentModel::getMetadataByContent($content, $isNodeRequested); if ($isNodeRequested) { $nodeMetadata = ezpRestContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId)); $objectMetadata = array_merge($objectMetadata, $nodeMetadata); } $result->variables['metadata'] = $objectMetadata; } return $result; }
/** * Handles a content unique field request through an object or node ID * * Requests: * - GET /api/content/node/:nodeId/field/:fieldIdentifier * - GET /api/content/object/:objectId/field/:fieldIdentifier * * @return ezcMvcResult */ public function doViewField() { try { if (isset($this->nodeId)) { $content = ezpContent::fromNodeId($this->nodeId); } elseif (isset($this->objectId)) { $content = ezpContent::fromObjectId($this->objectId); } } catch (Exception $e) { // @todo handle error die($e->getMessage()); } if (!isset($content->fields->{$this->fieldIdentifier})) { // @todo Handle error return false; } // translation parameter if (isset($this->request->variables['translation'])) { $content->setActiveLanguage($this->request->variables['translation']); } // object metadata $result = self::viewContent($content); // fieldd data $result->variables['fields'][$this->fieldIdentifier] = $this->attributeOutputData($content->fields->{$this->fieldIdentifier}); return $result; }
public static function attributeOutputData(ezpContentField $field, ezpRestRequest $currentRequest = null, ezcMvcRouter $router = null) { $attributeValue = $stringValue = array(); switch ($field->data_type_string) { case 'ezxmltext': $html = $field->content->attribute('output')->attribute('output_text'); $attributeValue = array($html); $stringValue = array(strip_tags($html)); break; case 'ezimage': if ($field->hasContent()) { $strRepImage = $field->toString(); $delimPos = strpos($strRepImage, '|'); if ($delimPos !== false) { $strRepImage = substr($strRepImage, 0, $delimPos); } $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $strRepImage); $stringValue = array($field->toString()); } break; case 'ezbinaryfile': if ($field->hasContent()) { $file = $field->content(); $filePath = "content/download/{$field->attribute('contentobject_id')}/{$field->attribute('id')}/{$field->content()->attribute('original_filename')}"; $attributeValue = array(self::getHostURIFromRequest($currentRequest) . '/' . $filePath); $stringValue = array($field->toString()); } else { $attributeValue = array(null); $stringValue = array(null); } break; case 'ezobjectrelationlist': $attributeValue = array(); $stringValueArray = array(); if ($currentRequest && $router) { if ($field->hasContent()) { $relations = $field->content(); foreach ($relations['relation_list'] as $relation) { $id = $relation['contentobject_id']; $object = eZContentObject::fetch($id); if ($object instanceof eZContentObject && $object->attribute('main_node') instanceof eZContentObjectTreeNode) { if ($object->attribute('can_read')) { $content = ezpContent::fromObject($object); $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content); $contentQueryString = $currentRequest->getContentQueryString(true); try { if ($content->main_node) { $node = $content->main_node; $location = ezpContentLocation::fromNode($node); $objectMetadata = array_merge($objectMetadata, self::getMetadataByLocation($location)); $stringValueArray[] = $id; } else { throw new Exception("Node not found for object id #{$id}"); } } catch (Exception $e) { } $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id)) . $contentQueryString; $attributeValue[] = $objectMetadata; } //else //{ // $attributeValue[] = "Access not allowed for content $id"; //} } } } } $stringValue = array(implode('-', $stringValueArray)); break; case 'ezobjectrelation': $attributeValue = array(); $stringValue = array($field->toString()); if ($currentRequest && $router) { if ($field->hasContent()) { $relation = $field->content(); if ($relation->attribute('can_read')) { $id = $relation->attribute('id'); $content = ezpContent::fromObject($relation); $objectMetadata = OCOpenDataContentModel::getMetadataByContent($content); $objectMetadata['link'] = self::getHostURIFromRequest($currentRequest) . $router->generateUrl('ezpObject', array('objectId' => $id)); $attributeValue[] = $objectMetadata; } } } break; default: $datatypeBlacklist = self::getDatatypeBlackList(); if (isset($datatypeBlacklist[$field->data_type_string])) { $attributeValue = array(null); $stringValue = array(null); } elseif ($field->hasContent()) { $attributeValue = array($field->toString()); $stringValue = array($field->toString()); } break; } if (count($attributeValue) == 0) { $attributeValue = false; } elseif (count($attributeValue) == 1) { $attributeValue = current($attributeValue); } if (count($stringValue) == 0) { $stringValue = false; } elseif (count($stringValue) == 1) { $stringValue = current($stringValue); } $return = array('name' => $field->contentclass_attribute_name, 'description' => $field->contentclass_attribute->attribute('description'), 'identifier' => $field->contentclass_attribute_identifier, 'id' => (int) $field->id, 'classattribute_id' => (int) $field->contentclassattribute_id, 'type' => $field->data_type_string, 'value' => $attributeValue, 'string_value' => $stringValue); return $return; }