public static function message($publishHandler, eZContentObject $object, $message, $messageLength = 400, $options)
 {
     $url = false;
     $share = array('title' => $object->attribute('name'));
     if (isset($options['include_url']) && (bool) $options['include_url'] === true) {
         $url = $object->attribute('main_node')->attribute('url_alias');
         eZURI::transformURI($url, true, 'full');
         if (isset($options['shorten_url']) && (bool) $options['shorten_url'] === true) {
             $urlReturned = $publishHandler->shorten($url, $options['shorten_handler']);
             if (is_string($urlReturned)) {
                 $url = $urlReturned;
             }
         }
         $messageLength = $messageLength - strlen($url) - 1;
         $share['submitted-url'] = $url;
     }
     if (class_exists('Normalizer')) {
         $message = Normalizer::normalize($message, Normalizer::FORM_C);
     }
     $message = mb_substr($message, 0, $messageLength);
     if ($url) {
         $message .= ' ' . $url;
     }
     $share['description'] = $message;
     return $share;
 }
Esempio n. 2
0
function unLock(eZContentObject $object)
{
    $filterConds = array('action' => 'creating_translation', 'param' => $object->attribute('id'));
    $rows = eZPersistentObject::fetchObjectList(eZPendingActions::definition(), null, $filterConds);
    foreach ($rows as $row) {
        $row->remove();
    }
}
Esempio n. 3
0
 /**
  * Adds a "pending clear cache" action if ViewCaching is disabled.
  * This method should be called at publish time.
  * Cache should then be cleared by a cronjob
  * @return void
  */
 public function addPendingClearCacheIfNeeded()
 {
     if (eZINI::instance()->variable('ContentSettings', 'ViewCaching') === 'disabled') {
         $rowPending = array('action' => self::ACTION_CLEAR_CACHE, 'created' => time(), 'param' => $this->contentObject->attribute('id'));
         $pendingItem = new eZPendingActions($rowPending);
         $pendingItem->store();
     }
 }
Esempio n. 4
0
 /**
  * Removes object $contentObject from the search database.
  *
  * @deprecated Since 5.0, use removeObjectById()
  * @param eZContentObject $contentObject the content object to remove
  * @param bool $commit Whether to commit after removing the object
  * @return bool True if the operation succeed.
  */
 static function removeObject($contentObject, $commit = null)
 {
     $searchEngine = eZSearch::getEngine();
     if ($searchEngine instanceof ezpSearchEngine) {
         return $searchEngine->removeObjectById($contentObject->attribute("id"), $commit);
     }
     return false;
 }
 /**
  * Appends additional node IDs.
  *
  * @param eZContentObject $contentObject
  * @param array $nodeIDList
  */
 private static function appendAdditionalNodeIDs(eZContentObject $contentObject, &$nodeIDList)
 {
     $contentObjectId = $contentObject->attribute('id');
     if (!isset(self::$additionalNodeIDsPerObject[$contentObjectId])) {
         return;
     }
     foreach (self::$additionalNodeIDsPerObject[$contentObjectId] as $nodeID) {
         $nodeIDList[] = $nodeID;
     }
 }
Esempio n. 6
0
 private function processXmlTextData($xml, $attribute)
 {
     $parser = new eZSimplifiedXMLInputParser($this->object->attribute('id'));
     $parser->ParseLineBreaks = true;
     $xml = $parser->process($xml);
     $xml = eZXMLTextType::domString($xml);
     $urlIdArray = $parser->getUrlIDArray();
     if (count($urlIdArray) > 0) {
         eZSimplifiedXMLInput::updateUrlObjectLinks($attribute, $urlIdArray);
     }
     return $xml;
 }
 protected function createNewVersionWithImage(eZContentObject $object)
 {
     $version = $object->createNewVersion(false, true, false, false, eZContentObjectVersion::STATUS_INTERNAL_DRAFT);
     $contentObjectAttributes = $version->contentObjectAttributes();
     foreach ($contentObjectAttributes as $contentObjectAttribute) {
         if ($contentObjectAttribute->attribute('contentclass_attribute_identifier') != 'image') {
             continue;
         }
         $contentObjectAttribute->fromString(self::IMAGE_FILE_PATH);
         $contentObjectAttribute->store();
         break;
     }
     $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $object->attribute('id'), 'version' => $version->attribute('version')));
     self::assertEquals(1, $operationResult['status']);
     return $this->forceFetchContentObject($object->attribute('id'));
 }
Esempio n. 8
0
 /**
  * The modify method gets the current content object AND the list of
  * Solr Docs (for each available language version).
  *
  *
  * @param eZContentObject $contentObect
  * @param array $docList
  */
 public function modify(eZContentObject $contentObject, &$docList)
 {
     $contentNode = $contentObject->attribute('main_node');
     $parentNode = $contentNode->attribute('parent');
     if ($parentNode instanceof eZContentObjectTreeNode) {
         $parentObject = $parentNode->attribute('object');
         $parentVersion = $parentObject->currentVersion();
         if ($parentVersion === false) {
             return;
         }
         $availableLanguages = $parentVersion->translationList(false, false);
         foreach ($availableLanguages as $languageCode) {
             $docList[$languageCode]->addField('extra_parent_node_name_t', $parentObject->name(false, $languageCode));
         }
     }
 }
 /**
  * Returns current draft for current content object.
  * If there is no current draft, a new one will be created in provided language.
  * @param string|bool $lang Valid locale xxx-XX. If not provided, default edit language will be used
  * @see eZContentObject::createNewVersionIn()
  * @return eZContentObjectVersion
  */
 public function getCurrentDraft($lang = false)
 {
     $currentDraft = null;
     $db = eZDB::instance();
     // First check if we already have a draft
     $aFilter = array('contentobject_id' => $this->contentObject->attribute('id'), 'status' => array(array(eZContentObjectVersion::STATUS_DRAFT, eZContentObjectVersion::STATUS_INTERNAL_DRAFT)));
     $res = eZContentObjectVersion::fetchFiltered($aFilter, null, null);
     if (count($res) > 0 && $res[0] instanceof eZContentObjectVersion) {
         $currentDraft = $res[0];
         // FIXME : Fetch may result several drafts. We should take the last one (highest version)
         $currentDraft->setAttribute('modified', eZDateTime::currentTimeStamp());
         $currentDraft->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
         $currentDraft->store();
     } else {
         $db->begin();
         $currentDraft = $this->contentObject->createNewVersionIn($lang, false, $this->contentObject->attribute('current_version'));
         $currentDraft->store();
         $db->commit();
     }
     return $currentDraft;
 }
Esempio n. 10
0
 /**
  * Checks if the current user has a 'self' edit/delete policy
  *
  * @param eZContentObject $contentObject Used to check with a possible section
  *
  * @return array An array with edit and delete as keys, and booleans as values
  */
 public static function selfPolicies($contentObject)
 {
     $return = array('edit' => false, 'delete' => false);
     $sectionID = $contentObject->attribute('section_id');
     $user = eZUser::currentUser();
     foreach (array_keys($return) as $functionName) {
         $policies = $user->hasAccessTo(self::$moduleName, $functionName);
         // unlimited policy, not personal
         if ($policies['accessWord'] !== 'limited') {
             $return[$functionName] = false;
         } else {
             // scan limited policies
             foreach ($policies['policies'] as $limitationArray) {
                 // a self limitation exists
                 if (isset($limitationArray[self::$commentCreatorKey])) {
                     // but it also has a section limitation
                     if (isset($limitationArray[self::$sectionKey])) {
                         if (in_array($sectionID, $limitationArray[self::$sectionKey])) {
                             $return[$functionName] = true;
                             break;
                         }
                     } else {
                         $return[$functionName] = true;
                         break;
                     }
                 }
             }
         }
     }
     return array('result' => $return);
 }
 /**
  * Serialize the eZContentObject to be used to build the result in
  * JavaScript
  *
  * @param eZContentObject $object
  * @return array
  */
 public function serializeObject(eZContentObject $contentObject)
 {
     $section = eZSection::fetch($contentObject->attribute('section_id'));
     return array('object_info' => array('id' => $contentObject->attribute('id'), 'name' => $contentObject->attribute('name'), 'class_name' => $contentObject->attribute('class_name'), 'section_name' => $section->attribute('name'), 'published' => ezpI18n::tr('design/standard/content/datatype', 'Yes')));
 }
    /**
     * @param eZContentObject $contentObject
     * @param bool|null $parentIsInvisible Only defined as boolean true|false if we are recursively going in a child
     */
    public static function updateGlobalLimitation ( $contentObject, $parentIsInvisible = null )
    {
        /* @type $contentMainNode eZContentObjectTreeNode */
        $db              = eZDB::instance();
        $contentObjectID = $contentObject->attribute('id');
        $contentMainNode = $contentObject->mainNode();

        if ( !($contentMainNode instanceof eZContentObjectTreeNode) )
            return;

        /* @type $dm eZContentObjectAttribute[] */
        $contentDepth         = $contentMainNode->attribute('depth');
        $merckINI             = eZINI::instance('merck.ini');
        $onlineDateAttribute  = $merckINI->variable("ArticleVisibility","OnlineDate");
        $offlineDateAttribute = $merckINI->variable("ArticleVisibility","OfflineDate");
        $dm                   = $contentObject->attribute("data_map");

        if ( !is_array($dm) )
            return;

        /* @type $onlineDateContent eZDateTime */
        /* @type $offlineDateContent eZDateTime */
        $onlineDateContent    = $dm[$onlineDateAttribute]->content();
        $onlineDate           = $onlineDateContent->timeStamp();
        $offlineDateContent   = $dm[$offlineDateAttribute]->content();
        $offlineDate          = $offlineDateContent->timeStamp();
        $visibility           = MMEventManager::visibilityDates($contentObject);
        $isInvisible          = !$visibility;

        // We have a parent article, we check its visibility
        if ( !$isInvisible && $parentIsInvisible === null && $contentDepth > 4 )
        {
            $parentNode  = $contentMainNode->fetchParent();
            $isInvisible = self::isGloballyLimited( $parentNode->attribute('contentobject_id') );
        }
        elseif ( !$isInvisible )
        {
            if ( $parentIsInvisible !== null && $parentIsInvisible === true )
                $isInvisible = true;
        }

        $db->beginQuery();

        $visibilityChange = self::updateGlobalLimitationEntry( $contentObjectID, $offlineDate, $onlineDate, $visibility, $isInvisible);

        if ( $visibilityChange && $visibility && !$isInvisible )
        {
            eZSearch::updateNodeVisibility($contentObject->mainNodeID(), 'show');
        }
        elseif ( $visibilityChange && ( !$visibility || $isInvisible ) )
        {
            eZSearch::updateNodeVisibility($contentObject->mainNodeID(), 'hide');
        }

        if ( $visibilityChange )
            self::spreadGlobalLimitationChange( $contentMainNode, $isInvisible );

        $db->commitQuery();
    }
    /**
     * Check state of all medias related to the article
     * @param eZContentObject $articleContentObject
     * @return bool
     */
    private static function checkMediaFromArticle( $articleContentObject )
    {
        /* @type $mediaClassIdentifiers array */
        $siteIni               = eZINI::instance( 'site.ini' );
        $mediaClassIdentifiers = $siteIni->variable( 'EventManager', 'MediaClassIdentifiers' );

        //Retrieve all media related to the article
        /* @type $articleDataMap eZContentObjectAttribute[] */
        $articleDataMap = $articleContentObject->dataMap();

        if( !isset( $articleDataMap['media_content'] ) )
            return true;

        $mediaContent = $articleDataMap['media_content']->content();

        if( empty( $mediaContent['relation_list'] ) )
            return true;

        foreach( $mediaContent['relation_list'] as $mediaData )
        {
            if( !in_array( $mediaData['contentclass_identifier'], $mediaClassIdentifiers ) )
                continue;

            if(!self::mediaIsCompleted($mediaData['contentobject_id']))
                return false;
        }

        // retrieve all medias in core content related to the article
        $relatedCoreContentList = RelatedCoreContent::getMediasFromArticle($articleContentObject->attribute("id"), $articleContentObject->currentLanguage());
        /** @var RelatedCoreContent $relatedCoreContent */
        foreach($relatedCoreContentList as $relatedCoreContent)
        {
            if(!self::mediaIsCompleted($relatedCoreContent->attribute("media_object_id")))
                return false;
        }

        return true;
    }
Esempio n. 14
0
 /**
  * Instanciates an ezpContent from an eZContentObject
  * @param eZContentObject $objectId
  * @return ezpContent
  */
 public static function fromObject(eZContentObject $object, $checkAccess = true)
 {
     if ($checkAccess && !$object->attribute('can_read')) {
         throw new ezpContentAccessDeniedException($object->attribute('id'));
     }
     $content = new ezpContent();
     $content->fields = ezpContentFieldSet::fromContentObject($object);
     $content->object = $object;
     return $content;
 }
 protected function checkAccess()
 {
     $user = eZUser::currentUser();
     $userID = $user->attribute('contentobject_id');
     $accessResult = $user->hasAccessTo('exportas', $this->functionName);
     $accessWord = $accessResult['accessWord'];
     if ($accessWord == 'yes') {
         return true;
     } else {
         if ($accessWord == 'no') {
             return false;
         } else {
             $policies =& $accessResult['policies'];
             $access = 'denied';
             foreach (array_keys($policies) as $pkey) {
                 $limitationArray =& $policies[$pkey];
                 if ($access == 'allowed') {
                     break;
                 }
                 $limitationList = array();
                 if (isset($limitationArray['Subtree'])) {
                     $checkedSubtree = false;
                 } else {
                     $checkedSubtree = true;
                     $accessSubtree = false;
                 }
                 if (isset($limitationArray['Node'])) {
                     $checkedNode = false;
                 } else {
                     $checkedNode = true;
                     $accessNode = false;
                 }
                 foreach (array_keys($limitationArray) as $key) {
                     $access = 'denied';
                     switch ($key) {
                         case 'Class':
                             if (!$this->mainClass) {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $limitationArray[$key]);
                             } elseif (in_array($this->mainClass->attribute('id'), $limitationArray[$key])) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $limitationArray[$key]);
                             }
                             break;
                         case 'Section':
                         case 'User_Section':
                             if (in_array($this->mainObject->attribute('section_id'), $limitationArray[$key])) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $limitationArray[$key]);
                             }
                             break;
                         case 'Node':
                             $accessNode = false;
                             $mainNodeID = $this->mainObject->attribute('main_node_id');
                             foreach ($limitationArray[$key] as $nodeID) {
                                 $node = eZContentObjectTreeNode::fetch($nodeID, false, false);
                                 $limitationNodeID = $node['main_node_id'];
                                 if ($mainNodeID == $limitationNodeID) {
                                     $access = 'allowed';
                                     $accessNode = true;
                                     break;
                                 }
                             }
                             $checkedNode = true;
                             break;
                         default:
                             if (strncmp($key, 'StateGroup_', 11) === 0) {
                                 if (count(array_intersect($limitationArray[$key], $this->mainObject->attribute('state_id_array'))) == 0) {
                                     $access = 'denied';
                                     $limitationList = array('Limitation' => $key, 'Required' => $limitationArray[$key]);
                                 } else {
                                     $access = 'allowed';
                                 }
                             }
                     }
                     if ($access == 'denied') {
                         break;
                     }
                 }
                 $policyList[] = array('PolicyID' => $pkey, 'LimitationList' => $limitationList);
             }
             if ($access == 'denied') {
                 return array('FunctionRequired' => array('Module' => 'exportas', 'Function' => $this->functionName), 'PolicyList' => $policyList);
             } else {
                 return true;
             }
         }
     }
 }
 /**
  * Create NameList element.
  *
  * @param DOMDocument Owner DOMDocument
  * @param eZContentObject eZContentObject object.
  *
  * @return DOMElement NameList DOMDocument, example:
  *
  *     <NameList>
  *         <Name locale="eng-GB">eZ Publish rocks</Name>
  *     </NameList>
  */
 protected function createNameListDOMElementFromContentObject(DOMDocument $domDocument, eZContentObject $object)
 {
     $languageListElement = $domDocument->createElement('NameList');
     // Add language names.
     foreach ($object->attribute('current')->translationList(false, false) as $locale) {
         $languageElement = $domDocument->createElement('Name');
         $languageElement->setAttribute('locale', $locale);
         $languageElement->appendChild($domDocument->createTextNode($object->name(false, $locale)));
         $languageListElement->appendChild($languageElement);
     }
     return $languageListElement;
 }
 /**
  * Returns a siteaccess list where the content object can be viewed. This
  * list is based on the locale settings and/or on the always available
  * flag of the content object.
  *
  * @param mixed $locale
  * @param eZContentObject $object
  * @return array( siteaccessName1 => siteaccessName1, ... )
  */
 protected static function getSiteaccessList($locale, eZContentObject $object)
 {
     $ini = eZINI::instance('site.ini');
     $availableSA = array_unique($ini->variable('SiteAccessSettings', 'RelatedSiteAccessList'));
     $alwaysAvailable = $object->attribute('always_available');
     $dedicatedSA = array();
     $canShowSA = array();
     $showAllSA = array();
     foreach ($availableSA as $sa) {
         $saINI = eZSiteAccess::getIni($sa, 'site.ini');
         $saLanguagesList = $saINI->variable('RegionalSettings', 'SiteLanguageList');
         if ($locale === $saINI->variable('RegionalSettings', 'ContentObjectLocale') || is_array($saLanguagesList) && $saLanguagesList[0] === $locale) {
             $dedicatedSA[$sa] = $sa;
         } else {
             if (in_array($locale, $saINI->variable('RegionalSettings', 'SiteLanguageList'))) {
                 $canShowSA[$sa] = $sa;
             } else {
                 if ($saINI->variable('RegionalSettings', 'ShowUntranslatedObjects') === 'enabled' || $alwaysAvailable) {
                     $showAllSA[$sa] = $sa;
                 }
             }
         }
     }
     return $dedicatedSA + $canShowSA + $showAllSA;
 }
Esempio n. 18
0
 /**
  * Removes object $contentObject from the search database.
  *
  * @deprecated Since 5.0, use removeObjectById()
  * @param eZContentObject $contentObject the content object to remove
  * @param bool $commit Whether to commit after removing the object
  * @return bool True if the operation succeed.
  */
 public function removeObject($contentObject, $commit = true)
 {
     return $this->removeObjectById($contentObject->attribute("id"), $commit);
 }
Esempio n. 19
0
 /**
  * Computes the unique ID of a content object language version
  *
  * @param eZContentObject $contentObject The content object
  * @param string $languageCode
  * @return string guid
  */
 function guid( $contentObject, $languageCode = '' )
 {
     return md5( self::installationID() . '-' . $contentObject->attribute( 'id' ) . '-' . $languageCode );
 }
 /**
  * Retourne les éléments de sitemap image pour un content object $object donné
  * @param eZContentObject $object
  * @return array(xrowSitemapItemImage)
  */
 private static function getSitemapImageItems(eZContentObject $object)
 {
     $images = array();
     // D'abord depuis la datamap
     $images = array_merge($images, self::getSitemapImageItemFromDataMap($object->dataMap()));
     // Puis avec les related objects
     $aParamsRelated = array('object_id' => $object->attribute('id'), 'all_relations' => true);
     $aImageObjectIDs = array();
     $relatedObjects = eZFunctionHandler::execute('content', 'related_objects', $aParamsRelated);
     $imagesRelated = array();
     foreach ($relatedObjects as $relatedObject) {
         switch ($relatedObject->attribute('class_identifier')) {
             case 'image':
                 $imagesRelated = array_merge($imagesRelated, self::getSitemapImageItemFromDataMap($relatedObject->dataMap()));
                 break;
         }
     }
     // Puis les children (gallery)
     $imagesChildren = array();
     $aParamsChildren = array('class_filter_type' => 'include', 'class_filter_array' => array('image'), 'parent_node_id' => $object->attribute('main_node_id'));
     $aChildren = eZFunctionHandler::execute('content', 'list', $aParamsChildren);
     foreach ($aChildren as $child) {
         $imagesChildren = array_merge($imagesChildren, self::getSitemapImageItemFromDataMap($child->object()->dataMap()));
     }
     return array_merge($images, $imagesRelated, $imagesChildren);
 }
 /**
  * Copies the specified object to the same folder, with optional $destinationName.
  *
  * @param eZContentObject $object
  * @param eZContentObject $newParentNode
  * @param string $destinationName
  * @return bool
  */
 protected function copyObjectSameDirectory($object, $newParentNode, $destinationName = null)
 {
     $object = $object->ContentObject;
     $newParentNodeID = $newParentNode->attribute('node_id');
     $classID = $object->attribute('contentclass_id');
     if (!$newParentNode->checkAccess('create', $classID)) {
         $objectID = $object->attribute('id');
         return false;
     }
     $db = eZDB::instance();
     $db->begin();
     $newObject = $object->copy(true);
     // We should reset section that will be updated in updateSectionID().
     // If sectionID is 0 than the object has been newly created
     $newObject->setAttribute('section_id', 0);
     // @as 2009-01-08 - Added check for destination name the same as the source name
     // (this was causing problems with nodes disappearing after renaming)
     $newName = $destinationName;
     if ($destinationName === null || strtolower($destinationName) === strtolower($object->attribute('name'))) {
         $newName = 'Copy of ' . $object->attribute('name');
     }
     // @todo @as avoid using [0] (could be another index in some classes)
     $contentObjectAttributes = $newObject->contentObjectAttributes();
     $contentObjectAttributes[0]->setAttribute('data_text', $newName);
     $contentObjectAttributes[0]->store();
     $newObject->store();
     $curVersion = $newObject->attribute('current_version');
     $curVersionObject = $newObject->attribute('current');
     $newObjAssignments = $curVersionObject->attribute('node_assignments');
     unset($curVersionObject);
     // remove old node assignments
     foreach ($newObjAssignments as $assignment) {
         $assignment->purge();
     }
     // and create a new one
     $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1));
     $nodeAssignment->store();
     // publish the newly created object
     eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion));
     // Update "is_invisible" attribute for the newly created node.
     $newNode = $newObject->attribute('main_node');
     eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode);
     $db->commit();
     return true;
 }
 /**
  * @param eZContentObjectTreeNode|eZContentObject $object
  * @param string $identifier
  *
  * @return bool|eZContentObjectAttribute
  */
 public function hasContentObjectAttribute($object, $identifier)
 {
     if ($object instanceof eZContentObjectTreeNode || $object instanceof eZContentObject) {
         /** @var eZContentObjectTreeNode|eZContentObject $object */
         /** @var eZContentObjectAttribute[] $dataMap */
         $dataMap = $object->attribute('data_map');
         if (isset($dataMap[$identifier])) {
             if ($dataMap[$identifier] instanceof eZContentObjectAttribute) {
                 //eZDebug::writeError( $object->attribute( 'class_identifier' ) . ' ' . $dataMap[$identifier]->attribute( 'data_type_string' ) . ' ' . $identifier, __METHOD__ );
                 if ($identifier == 'image' && $dataMap[$identifier]->attribute('data_type_string') == 'ezobjectrelationlist' && $dataMap[$identifier]->attribute('has_content')) {
                     $content = explode('-', $dataMap[$identifier]->toString());
                     $firstImage = array_shift($content);
                     $imageObject = eZContentObject::fetch($firstImage);
                     return $this->hasContentObjectAttribute($imageObject, 'image');
                 }
                 if ($identifier == 'image' && $dataMap[$identifier]->attribute('data_type_string') == 'ezobjectrelation' && $dataMap[$identifier]->attribute('has_content')) {
                     $imageObject = $dataMap[$identifier]->content();
                     return $this->hasContentObjectAttribute($imageObject, 'image');
                 }
                 switch ($dataMap[$identifier]->attribute('data_type_string')) {
                     case 'ezcomcomments':
                         return $dataMap[$identifier];
                         break;
                     case 'ezboolean':
                         if ($dataMap[$identifier]->attribute('data_int') == 1) {
                             return $dataMap[$identifier];
                         }
                         break;
                     default:
                         if ($dataMap[$identifier]->attribute('has_content')) {
                             return $dataMap[$identifier];
                         }
                 }
             }
         }
     }
     return false;
 }
Esempio n. 23
0
 /**
  * The purge the image aliases in all versions of the content object.
  *
  * @param array $cacheItem
  * @param eZContentObject $object
  * @param array $imageIdentifiers array of ezimage attribute identifiers
  */
 private static function purgeImageAliasForObject(array $cacheItem, eZContentObject $object, array $imageIdentifiers)
 {
     $versions = $object->attribute('versions');
     foreach ($versions as $version) {
         $dataMap = $version->attribute('data_map');
         foreach ($imageIdentifiers as $identifier) {
             $attr = $dataMap[$identifier];
             if (!$attr instanceof eZContentObjectAttribute) {
                 eZDebug::writeError("Missing attribute {$identifier} in object " . $object->attribute('id') . ", version " . $version->attribute('version') . ". This indicates data corruption.", __METHOD__);
             } elseif ($attr->attribute('has_content')) {
                 $attr->attribute('content')->purgeAllAliases($attr);
             }
         }
     }
 }
 /**
  * Returns a siteaccess list where the content object can be viewed. This
  * list is based on the locale settings and/or on the always available
  * flag of the content object.
  *
  * @param mixed $locale
  * @param eZContentObject $object
  * @return array( siteaccessName1 => siteaccessName1, ... )
  */
 protected static function getSiteaccessList($locale, eZContentObject $object)
 {
     $ini = eZINI::instance('site.ini');
     $availableSA = $ini->variable('SiteAccessSettings', 'AvailableSiteAccessList');
     if ($object->attribute('always_available')) {
         return $availableSA;
     }
     $result = array();
     foreach ($availableSA as $sa) {
         $saINI = eZSiteAccess::getIni($sa, 'site.ini');
         if ($locale === $saINI->variable('RegionalSettings', 'ContentObjectLocale') || in_array($locale, $saINI->variable('RegionalSettings', 'SiteLanguageList')) || $saINI->variable('RegionalSettings', 'ShowUntranslatedObjects') === 'enabled') {
             $result[$sa] = $sa;
         }
     }
     return $result;
 }
 /**
  * Generate result data for a node view
  *
  * @param eZTemplate $tpl
  * @param eZContentObjectTreeNode $node
  * @param eZContentObject $object
  * @param bool|string $languageCode
  * @param string $viewMode
  * @param int $offset
  * @param array $viewParameters
  * @param bool|array $collectionAttributes
  * @param bool $validation
  * @return array Result array for view
  */
 static function generateNodeViewData(eZTemplate $tpl, eZContentObjectTreeNode $node, eZContentObject $object, $languageCode, $viewMode, $offset, array $viewParameters = array('offset' => 0, 'year' => false, 'month' => false, 'day' => false), $collectionAttributes = false, $validation = false)
 {
     $section = eZSection::fetch($object->attribute('section_id'));
     if ($section) {
         $navigationPartIdentifier = $section->attribute('navigation_part_identifier');
         $sectionIdentifier = $section->attribute('identifier');
     } else {
         $navigationPartIdentifier = null;
         $sectionIdentifier = null;
     }
     $keyArray = array(array('object', $object->attribute('id')), array('node', $node->attribute('node_id')), array('parent_node', $node->attribute('parent_node_id')), array('class', $object->attribute('contentclass_id')), array('class_identifier', $node->attribute('class_identifier')), array('view_offset', $offset), array('viewmode', $viewMode), array('remote_id', $object->attribute('remote_id')), array('node_remote_id', $node->attribute('remote_id')), array('navigation_part_identifier', $navigationPartIdentifier), array('depth', $node->attribute('depth')), array('url_alias', $node->attribute('url_alias')), array('class_group', $object->attribute('match_ingroup_id_list')), array('state', $object->attribute('state_id_array')), array('state_identifier', $object->attribute('state_identifier_array')), array('section', $object->attribute('section_id')), array('section_identifier', $sectionIdentifier));
     $parentClassID = false;
     $parentClassIdentifier = false;
     $parentNodeRemoteID = false;
     $parentObjectRemoteID = false;
     $parentNode = $node->attribute('parent');
     if (is_object($parentNode)) {
         $parentNodeRemoteID = $parentNode->attribute('remote_id');
         $keyArray[] = array('parent_node_remote_id', $parentNodeRemoteID);
         $parentObject = $parentNode->attribute('object');
         if (is_object($parentObject)) {
             $parentObjectRemoteID = $parentObject->attribute('remote_id');
             $keyArray[] = array('parent_object_remote_id', $parentObjectRemoteID);
             $parentClass = $parentObject->contentClass();
             if (is_object($parentClass)) {
                 $parentClassID = $parentClass->attribute('id');
                 $parentClassIdentifier = $parentClass->attribute('identifier');
                 $keyArray[] = array('parent_class', $parentClassID);
                 $keyArray[] = array('parent_class_identifier', $parentClassIdentifier);
             }
         }
     }
     $res = eZTemplateDesignResource::instance();
     $res->setKeys($keyArray);
     if ($languageCode) {
         $oldLanguageCode = $node->currentLanguage();
         $node->setCurrentLanguage($languageCode);
     }
     $tpl->setVariable('node', $node);
     $tpl->setVariable('viewmode', $viewMode);
     $tpl->setVariable('language_code', $languageCode);
     if (isset($viewParameters['_custom'])) {
         foreach ($viewParameters['_custom'] as $customVarName => $customValue) {
             $tpl->setVariable($customVarName, $customValue);
         }
         unset($viewParameters['_custom']);
     }
     $tpl->setVariable('view_parameters', $viewParameters);
     $tpl->setVariable('collection_attributes', $collectionAttributes);
     $tpl->setVariable('validation', $validation);
     $tpl->setVariable('persistent_variable', false);
     $parents = $node->attribute('path');
     $path = array();
     $titlePath = array();
     foreach ($parents as $parent) {
         $path[] = array('text' => $parent->attribute('name'), 'url' => '/content/view/full/' . $parent->attribute('node_id'), 'url_alias' => $parent->attribute('url_alias'), 'node_id' => $parent->attribute('node_id'));
     }
     $titlePath = $path;
     $path[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false, 'node_id' => $node->attribute('node_id'));
     $titlePath[] = array('text' => $object->attribute('name'), 'url' => false, 'url_alias' => false);
     $tpl->setVariable('node_path', $path);
     $event = ezpEvent::getInstance();
     $event->notify('content/pre_rendering', array($node, $tpl, $viewMode));
     $Result = array();
     $Result['content'] = $tpl->fetch('design:node/view/' . $viewMode . '.tpl');
     $Result['view_parameters'] = $viewParameters;
     $Result['path'] = $path;
     $Result['title_path'] = $titlePath;
     $Result['section_id'] = $object->attribute('section_id');
     $Result['node_id'] = $node->attribute('node_id');
     $Result['navigation_part'] = $navigationPartIdentifier;
     $contentInfoArray = array();
     $contentInfoArray['object_id'] = $object->attribute('id');
     $contentInfoArray['node_id'] = $node->attribute('node_id');
     $contentInfoArray['parent_node_id'] = $node->attribute('parent_node_id');
     $contentInfoArray['class_id'] = $object->attribute('contentclass_id');
     $contentInfoArray['class_identifier'] = $node->attribute('class_identifier');
     $contentInfoArray['remote_id'] = $object->attribute('remote_id');
     $contentInfoArray['node_remote_id'] = $node->attribute('remote_id');
     $contentInfoArray['offset'] = $offset;
     $contentInfoArray['viewmode'] = $viewMode;
     $contentInfoArray['navigation_part_identifier'] = $navigationPartIdentifier;
     $contentInfoArray['node_depth'] = $node->attribute('depth');
     $contentInfoArray['url_alias'] = $node->attribute('url_alias');
     $contentInfoArray['current_language'] = $object->attribute('current_language');
     $contentInfoArray['language_mask'] = $object->attribute('language_mask');
     $contentInfoArray['main_node_id'] = $node->attribute('main_node_id');
     $contentInfoArray['main_node_url_alias'] = false;
     // Add url alias for main node if it is not current node and user has access to it
     if (!$node->isMain()) {
         $mainNode = $object->mainNode();
         if ($mainNode->canRead()) {
             $contentInfoArray['main_node_url_alias'] = $mainNode->attribute('url_alias');
         }
     }
     $contentInfoArray['persistent_variable'] = false;
     if ($tpl->variable('persistent_variable') !== false) {
         $contentInfoArray['persistent_variable'] = $tpl->variable('persistent_variable');
         $keyArray[] = array('persistent_variable', $contentInfoArray['persistent_variable']);
         $res->setKeys($keyArray);
     }
     $contentInfoArray['class_group'] = $object->attribute('match_ingroup_id_list');
     $contentInfoArray['state'] = $object->attribute('state_id_array');
     $contentInfoArray['state_identifier'] = $object->attribute('state_identifier_array');
     $contentInfoArray['parent_class_id'] = $parentClassID;
     $contentInfoArray['parent_class_identifier'] = $parentClassIdentifier;
     $contentInfoArray['parent_node_remote_id'] = $parentNodeRemoteID;
     $contentInfoArray['parent_object_remote_id'] = $parentObjectRemoteID;
     $Result['content_info'] = $contentInfoArray;
     // Store which templates were used to make this cache.
     $Result['template_list'] = $tpl->templateFetchList();
     // Check if time to live is set in template
     if ($tpl->hasVariable('cache_ttl')) {
         $cacheTTL = $tpl->variable('cache_ttl');
     }
     if (!isset($cacheTTL)) {
         $cacheTTL = -1;
     }
     $Result['cache_ttl'] = $cacheTTL;
     // if cache_ttl is set to 0 from the template, we need to add a no-cache advice
     // to the node's data. That way, the retrieve callback on the next calls
     // will be able to determine earlier that no cache generation should be started
     // for this node
     if ($cacheTTL == 0) {
         $Result['no_cache'] = true;
     }
     if ($languageCode) {
         $node->setCurrentLanguage($oldLanguageCode);
     }
     return $Result;
 }
 /**
  * Updates an existing content object.
  *
  * This function works like createAndPublishObject
  *
  * Here is an example
  * <code>
  *
  * <?php
  * $contentObjectID = 1;
  * $contentObject = eZContentObject::fetch( $contentObjectID );
  *
  * if( $contentObject instanceof eZContentObject )
  * {
  *     $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>
  *                         <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
  *                                  xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
  *                                  xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">';
  *
  *     $now = $now = date( 'Y/m/d H:i:s', time() );
  *     $xmlDeclaration = '<?xml version="1.0" encoding="utf-8"?>
  *                     <section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
  *                                 xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
  *                                 xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">';
  *
  *     $attributeList = array( 'name'              => 'Name ' . $now,
  *                             'short_name'        => 'Short name ' . $now,
  *                             'short_description' => $xmlDeclaration . '<paragraph>Short description '. $now . '</paragraph></section>',
  *                             'description'       => $xmlDeclaration . '<paragraph>Description '. $now . '</paragraph></section>',
  *                             'show_children'     => false);
  *
  *     $params = array();
  *     $params['attributes'] = $attributeList;
  *     // $params['remote_id'] = $now;
  *     // $params['section_id'] = 3;
  *     // $params['language']  = 'ger-DE';
  *
  *     $result = eZContentFunctions::updateAndPublishObject( $contentObject, $params );
  *
  *     if( $result )
  *         print( 'Update OK' );
  *     else
  *         print( 'Failed' );
  * }
  * ?>
  * </code>
  * @param eZContentObject an eZContentObject object
  * @param array an array with the attributes to update
  * @static
  * @return bool true if the object has been successfully updated, false otherwise
  */
 public static function updateAndPublishObject(eZContentObject $object, array $params)
 {
     if (!array_key_exists('attributes', $params) and !is_array($params['attributes']) and count($params['attributes']) > 0) {
         eZDebug::writeError('No attributes specified for object' . $object->attribute('id'), __METHOD__);
         return false;
     }
     $storageDir = '';
     $languageCode = false;
     $mustStore = false;
     if (array_key_exists('remote_id', $params)) {
         $object->setAttribute('remote_id', $params['remote_id']);
         $mustStore = true;
     }
     if (array_key_exists('section_id', $params)) {
         $object->setAttribute('section_id', $params['section_id']);
         $mustStore = true;
     }
     if ($mustStore) {
         $object->store();
     }
     if (array_key_exists('storage_dir', $params)) {
         $storageDir = $params['storage_dir'];
     }
     if (array_key_exists('language', $params) and $params['language'] != false) {
         $languageCode = $params['language'];
     } else {
         $initialLanguageID = $object->attribute('initial_language_id');
         $language = eZContentLanguage::fetch($initialLanguageID);
         $languageCode = $language->attribute('locale');
     }
     $db = eZDB::instance();
     $db->begin();
     $newVersion = $object->createNewVersion(false, true, $languageCode);
     if (!$newVersion instanceof eZContentObjectVersion) {
         eZDebug::writeError('Unable to create a new version for object ' . $object->attribute('id'), __METHOD__);
         $db->rollback();
         return false;
     }
     $newVersion->setAttribute('modified', time());
     $newVersion->store();
     $attributeList = $newVersion->attribute('contentobject_attributes');
     $attributesData = $params['attributes'];
     foreach ($attributeList as $attribute) {
         $attributeIdentifier = $attribute->attribute('contentclass_attribute_identifier');
         if (array_key_exists($attributeIdentifier, $attributesData)) {
             $dataString = $attributesData[$attributeIdentifier];
             switch ($datatypeString = $attribute->attribute('data_type_string')) {
                 case 'ezimage':
                 case 'ezbinaryfile':
                 case 'ezmedia':
                     $dataString = $storageDir . $dataString;
                     break;
                 default:
             }
             $attribute->fromString($dataString);
             $attribute->store();
         }
     }
     $db->commit();
     $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $newVersion->attribute('contentobject_id'), 'version' => $newVersion->attribute('version')));
     if ($operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE) {
         return true;
     }
     return false;
 }
 /**
  * Removes object $contentObject from the search database.
  *
  * @param eZContentObject $contentObject the content object to remove
  * @param bool $commit Whether to commit after removing the object
  * @return bool True if the operation succeed.
  */
 public function removeObject($contentObject, $commit = true)
 {
     $db = eZDB::instance();
     $objectID = $contentObject->attribute("id");
     $doDelete = false;
     $db->begin();
     if ($db->databaseName() == 'mysql') {
         // fetch all the words and decrease the object count on all the words
         $wordArray = $db->arrayQuery("SELECT word_id FROM ezsearch_object_word_link WHERE contentobject_id='{$objectID}'");
         $wordIDList = array();
         foreach ($wordArray as $word) {
             $wordIDList[] = $word["word_id"];
         }
         if (count($wordIDList) > 0) {
             $wordIDString = implode(',', $wordIDList);
             $db->query("UPDATE ezsearch_word SET object_count=( object_count - 1 ) WHERE id in ( {$wordIDString} )");
             $doDelete = true;
         }
     } else {
         $cnt = $db->arrayQuery("SELECT COUNT( word_id ) AS cnt FROM ezsearch_object_word_link WHERE contentobject_id='{$objectID}'");
         if ($cnt[0]['cnt'] > 0) {
             $db->query("UPDATE ezsearch_word SET object_count=( object_count - 1 ) WHERE id in ( SELECT word_id FROM ezsearch_object_word_link WHERE contentobject_id='{$objectID}' )");
             $doDelete = true;
         }
     }
     if ($doDelete) {
         $db->query("DELETE FROM ezsearch_word WHERE object_count='0'");
         $db->query("DELETE FROM ezsearch_object_word_link WHERE contentobject_id='{$objectID}'");
     }
     $db->commit();
 }
 /**
  * Removes object $contentObject from the search database.
  *
  * @deprecated Since 5.0, use removeObjectById()
  *
  * @param \eZContentObject $contentObject the content object to remove
  * @param bool $commit Whether to commit after removing the object
  *
  * @return bool True if the operation succeeded
  */
 public function removeObject($contentObject, $commit = null)
 {
     return $this->removeObjectById($contentObject->attribute('id'), $commit);
 }
 /**
  * @param eZContentObject $object
  * @param bool $allVersions
  * @param int $newParentNodeID
  * @throws Exception
  * @return eZContentObject
  */
 public static function copyObject(eZContentObject $object, $allVersions = false, $newParentNodeID = null)
 {
     if (!$object instanceof eZContentObject) {
         throw new InvalidArgumentException('Object not found');
     }
     if (!$newParentNodeID) {
         $newParentNodeID = $object->attribute('main_parent_node_id');
     }
     // check if we can create node under the specified parent node
     if (($newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID)) === null) {
         throw new InvalidArgumentException('Parent node not found');
     }
     $classID = $object->attribute('contentclass_id');
     if (!$newParentNode->checkAccess('create', $classID)) {
         $objectID = $object->attribute('id');
         eZDebug::writeError("Cannot copy object {$objectID} to node {$newParentNodeID}, " . "the current user does not have create permission for class ID {$classID}", 'content/copy');
         throw new Exception('Object not found');
     }
     $db = eZDB::instance();
     $db->begin();
     $newObject = $object->copy($allVersions);
     // We should reset section that will be updated in updateSectionID().
     // If sectionID is 0 then the object has been newly created
     $newObject->setAttribute('section_id', 0);
     $newObject->store();
     $curVersion = $newObject->attribute('current_version');
     $curVersionObject = $newObject->attribute('current');
     $newObjAssignments = $curVersionObject->attribute('node_assignments');
     unset($curVersionObject);
     // remove old node assignments
     foreach ($newObjAssignments as $assignment) {
         /** @var eZNodeAssignment $assignment */
         $assignment->purge();
     }
     // and create a new one
     $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1));
     $nodeAssignment->store();
     $db->commit();
     return $newObject;
 }
 protected function getArrayRelatedObject(eZContentObject $relatedObject, $contentClassAttribute, $metaData = null)
 {
     if ($metaData === null) {
         $metaData = array();
     }
     if ($relatedObject instanceof eZContentObject && $relatedObject->attribute('main_node_id') > 0) {
         $objectName = $relatedObject->name(false, $this->ContentObjectAttribute->attribute('language_code'));
         $fieldName = parent::generateSubattributeFieldName($contentClassAttribute, 'name', self::DEFAULT_SUBATTRIBUTE_TYPE);
         if (isset($metaData[$fieldName])) {
             $metaData[$fieldName] = array_merge($metaData[$fieldName], array($objectName));
         } else {
             $metaData[$fieldName] = array($objectName);
         }
         /** @var ezfSolrDocumentFieldBase[] $baseList */
         $baseList = $this->getBaseList($relatedObject->attribute('current'));
         foreach ($baseList as $field) {
             /** @var eZContentClassAttribute $tmpClassAttribute */
             $tmpClassAttribute = $field->ContentObjectAttribute->attribute('contentclass_attribute');
             $fieldName = $field->ContentObjectAttribute->attribute('contentclass_attribute_identifier');
             $fieldNameArray = array();
             foreach (array_keys(eZSolr::$fieldTypeContexts) as $context) {
                 $fieldNameArray[] = parent::generateSubattributeFieldName($contentClassAttribute, $fieldName, ezfSolrDocumentFieldBase::getClassAttributeType($tmpClassAttribute, null, $context));
             }
             $fieldNameArray = array_unique($fieldNameArray);
             if ($tmpClassAttribute->attribute('data_type_string') == 'ezobjectrelation' or $tmpClassAttribute->attribute('data_type_string') == 'ezobjectrelationlist') {
                 /** @var self $field */
                 $finalValue = $field->getPlainTextRepresentation();
             } else {
                 $finalValue = $this->preProcessValue($field->ContentObjectAttribute->metaData(), parent::getClassAttributeType($tmpClassAttribute));
             }
             foreach ($fieldNameArray as $fieldNameValue) {
                 //eZCLI::instance()->output(var_dump($metaData));
                 if (is_array($finalValue)) {
                     $finalValue = self::recursive_implode($finalValue);
                 }
                 $finalValue = trim($finalValue, "\t\r\n ");
                 if (!empty($finalValue)) {
                     if (isset($metaData[$fieldNameValue])) {
                         $metaData[$fieldNameValue] = array_merge($metaData[$fieldNameValue], array($finalValue));
                     } else {
                         $metaData[$fieldNameValue] = array($finalValue);
                     }
                 }
             }
         }
         $metaAttributeValues = eZSolr::getMetaAttributesForObject($relatedObject);
         foreach ($metaAttributeValues as $metaInfo) {
             $value = ezfSolrDocumentFieldBase::preProcessValue($metaInfo['value'], $metaInfo['fieldType']);
             if (!is_array($value)) {
                 $value = array($value);
             }
             $metaData[ezfSolrDocumentFieldBase::generateSubmetaFieldName($metaInfo['name'], $contentClassAttribute)] = $value;
         }
     }
     return $metaData;
 }