public static function fetchContentObject($objectID, $remoteID = false) { if ($objectID === false && $remoteID !== false) { $contentObject = eZContentObject::fetchByRemoteID($remoteID); } else { $contentObject = eZContentObject::fetch($objectID); } if ($contentObject === null) { $result = array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND)); } else { $result = array('result' => $contentObject); } return $result; }
/** * test if the new object remote id is available (or already used by this object) * @param string $remoteID * @param int $currentObjectID * @param array $errors * @return boolean */ public static function isValidObjectRemoteID($remoteID, $currentObjectID = false, &$errors = array()) { if (!self::isValidRemoteIDText($remoteID, $errors)) { return false; } if ($existingObject = eZContentObject::fetchByRemoteID($remoteID, false)) { if ($existingObject['id'] != $currentObjectID) { $errors[] = ezpI18n::tr('remoteid/update', 'Object Remote ID %1 already used by object %2', '', array('%1' => $remoteID, '%2' => $existingObject['id'])); eZDebug::writeDebug('Object Remote ID ' . $remoteID . ' used by object ' . $existingObject['id'], '', __CLASS__); return false; } } return true; }
public function getContent($forceSynchronization=true) { if (!$this->content) { $contentObject = eZContentObject::fetchByRemoteID( $this->remoteId() ); if ($contentObject instanceof eZContentObject) { $this->content = SQLIContent::fromContentObject( $contentObject ); } if (!$contentObject || $forceSynchronization || $this->synchronizer->option('ForceSynchronization')) { $this->synchronize(); } } return $this->content; }
public function __construct( $params, $outputType, $blockName, $applicationName, $applicationObject, $applicationLocalized ) { parent::__construct( $params, $outputType, $blockName, $applicationName, $applicationObject, $applicationLocalized ); foreach( $this->applicationLocalized()->publisherFolders as $publisherFolder ) { /* @var $publisherFolder PublisherFolder */ $publisherFolderObject = eZContentObject::fetchByRemoteID( 'publisher_folder-'.$publisherFolder->attribute('path') ); /* @var $publisherFolderNode eZContentObjectTreeNode */ $publisherFolderNode = $publisherFolderObject->mainNode(); foreach( $publisherFolderNode->children() as $child ) { /* @var $child eZContentObjectTreeNode */ if( $child->classIdentifier() == 'article' ) { $this->node = $child; $this->isFull = true; header('x-ez-node: ' . 'P'.$this->node->attribute('node_id').'P' ); } } } }
function installFetchAliases( $fetchAliasListNode, &$parameters ) { if ( !$fetchAliasListNode ) { return true; } $fetchAliasINIArray = array(); foreach( $fetchAliasListNode->getElementsByTagName( 'fetch-alias' ) as $blockNode ) { if ( isset( $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )] ) ) { $newSiteAccess = $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )]; } else { $newSiteAccess = $parameters['site_access_map']['*']; } if ( !isset( $fetchAliasINIArray[$newSiteAccess] ) ) { $fetchAliasINIArray[$newSiteAccess] = eZINI::instance( 'fetchalias.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true ); } $blockArray = array(); $blockName = $blockNode->getAttribute( 'name' ); $blockArray[$blockName] = eZContentObjectPackageHandler::createArrayFromDOMNode( $blockNode->getElementsByTagName( $blockName )->item( 0 ) ); //$blockArray[$blockName] = $blockArray[$blockName][0]; if ( isset( $blockArray[$blockName]['Constant'] ) && is_array( $blockArray[$blockName]['Constant'] ) && count( $blockArray[$blockName]['Constant'] ) > 0 ) { foreach( $blockArray[$blockName]['Constant'] as $matchKey => $value ) { if ( strpos( $matchKey, 'class_' ) === 0 && is_int( $value ) ) { $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName]['Constant']['class_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentClass->attribute( 'id' ); unset( $blockArray[$blockName]['Constant']['class_remote_id'] ); } if( strpos( $matchKey, 'node_' ) === 0 && is_int( $value ) ) { $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['node_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' ); unset( $blockArray[$blockName]['Constant']['node_remote_id'] ); } if( strpos( $matchKey, 'parent_node_' ) === 0 && is_int( $value ) ) { $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['parent_node_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' ); unset( $blockArray[$blockName]['Constant']['parent_node_remote_id'] ); } if( strpos( $matchKey, 'object_' ) === 0 && is_int( $value ) ) { $contentObject = eZContentObject::fetchByRemoteID( $blockArray[$blockName]['Constant']['object_remote_id'] ); $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'id' ); unset( $blockArray[$blockName]['Constant']['object_remote_id'] ); } } } $fetchAliasINIArray[$newSiteAccess]->setVariables( $blockArray ); } foreach( $fetchAliasINIArray as $siteAccess => $iniFetchAlias ) { $fetchAliasINIArray[$siteAccess]->save(); } return true; }
function postUnserializeContentObjectAttribute($package, $objectAttribute) { $xmlString = $objectAttribute->attribute('data_text'); $doc = $this->parseXML($xmlString); $rootNode = $doc->documentElement; $relationList = $rootNode->getElementsByTagName('relation-list')->item(0); if (!$relationList) { return false; } $relationItems = $relationList->getElementsByTagName('relation-item'); for ($i = $relationItems->length - 1; $i >= 0; $i--) { $relationItem = $relationItems->item($i); $relatedObjectRemoteID = $relationItem->getAttribute('contentobject-remote-id'); $object = eZContentObject::fetchByRemoteID($relatedObjectRemoteID); if ($object === null) { eZDebug::writeWarning("Object with remote id '{$relatedObjectRemoteID}' not found: removing the link.", __METHOD__); $relationItem->parentNode->removeChild($relationItem); continue; } $relationItem->setAttribute('contentobject-id', $object->attribute('id')); $relationItem->setAttribute('contentobject-version', $object->attribute('current_version')); $relationItem->setAttribute('node-id', $object->attribute('main_node_id')); $relationItem->setAttribute('parent-node-id', $object->attribute('main_parent_node_id')); $relationItem->setAttribute('contentclass-id', $object->attribute('contentclass_id')); $relationItem->setAttribute('contentclass-identifier', $object->attribute('class_identifier')); } $newXmlString = $doc->saveXML($rootNode); $objectAttribute->setAttribute('data_text', $newXmlString); return true; }
static function loginUser($login, $password, $authenticationMatch = false) { $http = eZHTTPTool::instance(); $db = eZDB::instance(); if ($authenticationMatch === false) { $authenticationMatch = eZUser::authenticationMatch(); } $loginEscaped = $db->escapeString($login); $passwordEscaped = $db->escapeString($password); $loginArray = array(); if ($authenticationMatch & eZUser::AUTHENTICATE_LOGIN) { $loginArray[] = "login='******'"; } if ($authenticationMatch & eZUser::AUTHENTICATE_EMAIL) { $loginArray[] = "email='{$loginEscaped}'"; } if (count($loginArray) == 0) { $loginArray[] = "login='******'"; } $loginText = implode(' OR ', $loginArray); $contentObjectStatus = eZContentObject::STATUS_PUBLISHED; $ini = eZINI::instance(); $textFileIni = eZINI::instance('textfile.ini'); $databaseName = $db->databaseName(); // if mysql if ($databaseName === 'mysql') { $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ( ezcontentobject.id=contentobject_id OR ( password_hash_type=4 AND ( {$loginText} ) AND password_hash=PASSWORD('{$passwordEscaped}') ) )"; } else { $query = "SELECT contentobject_id, password_hash, password_hash_type, email, login\n FROM ezuser, ezcontentobject\n WHERE ( {$loginText} ) AND\n ezcontentobject.status='{$contentObjectStatus}' AND\n ezcontentobject.id=contentobject_id"; } $users = $db->arrayQuery($query); $exists = false; if (count($users) >= 1) { foreach ($users as $userRow) { $userID = $userRow['contentobject_id']; $hashType = $userRow['password_hash_type']; $hash = $userRow['password_hash']; $exists = eZUser::authenticateHash($userRow['login'], $password, eZUser::site(), $hashType, $hash); // If hash type is MySql if ($hashType == eZUser::PASSWORD_HASH_MYSQL and $databaseName === 'mysql') { $queryMysqlUser = "******"; $mysqlUsers = $db->arrayQuery($queryMysqlUser); if (count($mysqlUsers) >= 1) { $exists = true; } } eZDebugSetting::writeDebug('kernel-user', eZUser::createHash($userRow['login'], $password, eZUser::site(), $hashType), "check hash"); eZDebugSetting::writeDebug('kernel-user', $hash, "stored hash"); // If current user has been disabled after a few failed login attempts. $canLogin = eZUser::isEnabledAfterFailedLogin($userID); if ($exists) { // We should store userID for warning message. $GLOBALS['eZFailedLoginAttemptUserID'] = $userID; $userSetting = eZUserSetting::fetch($userID); $isEnabled = $userSetting->attribute("is_enabled"); if ($hashType != eZUser::hashType() and strtolower($ini->variable('UserSettings', 'UpdateHash')) == 'true') { $hashType = eZUser::hashType(); $hash = eZUser::createHash($login, $password, eZUser::site(), $hashType); $db->query("UPDATE ezuser SET password_hash='{$hash}', password_hash_type='{$hashType}' WHERE contentobject_id='{$userID}'"); } break; } } } if ($exists and $isEnabled and $canLogin) { eZDebugSetting::writeDebug('kernel-user', $userRow, 'user row'); $user = new eZUser($userRow); eZDebugSetting::writeDebug('kernel-user', $user, 'user'); $userID = $user->attribute('contentobject_id'); eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($user, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); return $user; } else { if ($textFileIni->variable('TextFileSettings', 'TextFileEnabled') == "true") { $fileName = $textFileIni->variable('TextFileSettings', 'FileName'); $filePath = $textFileIni->variable('TextFileSettings', 'FilePath'); $defaultUserPlacement = $ini->variable("UserSettings", "DefaultUserPlacement"); $separator = $textFileIni->variable("TextFileSettings", "FileFieldSeparator"); $loginColumnNr = $textFileIni->variable("TextFileSettings", "LoginAttribute"); $passwordColumnNr = $textFileIni->variable("TextFileSettings", "PasswordAttribute"); $emailColumnNr = $textFileIni->variable("TextFileSettings", "EmailAttribute"); $lastNameColumnNr = $textFileIni->variable("TextFileSettings", "LastNameAttribute"); $firstNameColumnNr = $textFileIni->variable("TextFileSettings", "FirstNameAttribute"); if ($textFileIni->hasVariable('TextFileSettings', 'DefaultUserGroupType')) { $UserGroupType = $textFileIni->variable('TextFileSettings', 'DefaultUserGroupType'); $UserGroup = $textFileIni->variable('TextFileSettings', 'DefaultUserGroup'); } if ($UserGroupType != null) { if ($UserGroupType == "name") { $groupName = $UserGroup; $groupQuery = "SELECT ezcontentobject_tree.node_id\n FROM ezcontentobject, ezcontentobject_tree\n WHERE ezcontentobject.name='{$groupName}'\n AND ezcontentobject.id=ezcontentobject_tree.contentobject_id"; $groupObject = $db->arrayQuery($groupQuery); if (count($groupObject) > 0) { $defaultUserPlacement = $groupObject[0]['node_id']; } } else { if ($UserGroupType == "id") { $groupID = $UserGroup; $groupQuery = "SELECT ezcontentobject_tree.node_id\n FROM ezcontentobject, ezcontentobject_tree\n WHERE ezcontentobject.id='{$groupID}'\n AND ezcontentobject.id=ezcontentobject_tree.contentobject_id"; $groupObject = $db->arrayQuery($groupQuery); if (count($groupObject) > 0) { $defaultUserPlacement = $groupObject[0]['node_id']; } } } } if ($filePath != "root" and $filePath != null) { $fileName = $filePath . "/" . $fileName; } if (file_exists($fileName)) { $handle = fopen($fileName, "r"); } else { // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; } while (!feof($handle)) { $line = trim(fgets($handle, 4096)); if ($line === '') { continue; } if ($separator == "tab") { $userArray = explode("\t", $line); } else { $userArray = explode($separator, $line); } $uid = $userArray[$loginColumnNr - 1]; $email = $userArray[$emailColumnNr - 1]; $pass = $userArray[$passwordColumnNr - 1]; $firstName = $userArray[$firstNameColumnNr - 1]; $lastName = $userArray[$lastNameColumnNr - 1]; if ($login == $uid) { if (trim($pass) == $password) { $createNewUser = true; $existUser = eZUser::fetchByName($login); if ($existUser != null) { $createNewUser = false; } if ($createNewUser) { $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $remoteID = "TextFile_" . $login; $db->begin(); // The content object may already exist if this process has failed once before, before the eZUser object was created. // Therefore we try to fetch the eZContentObject before instantiating it. $contentObject = eZContentObject::fetchByRemoteID($remoteID); if (!is_object($contentObject)) { $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); } $contentObject->setAttribute('remote_id', $remoteID); $contentObject->store(); $contentObjectID = $contentObject->attribute('id'); $userID = $contentObjectID; $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $defaultUserPlacement, 'is_main' => 1)); $nodeAssignment->store(); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $contentObjectID = $contentObject->attribute('id'); $contentObjectAttributes = $version->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute('data_text', $firstName); $contentObjectAttributes[0]->store(); $contentObjectAttributes[1]->setAttribute('data_text', $lastName); $contentObjectAttributes[1]->store(); $user = eZUser::create($userID); $user->setAttribute('login', $login); $user->setAttribute('email', $email); $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($user, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); $db->commit(); return $user; } else { $db->begin(); // Update user information $userID = $existUser->attribute('contentobject_id'); $contentObject = eZContentObject::fetch($userID); $parentNodeID = $contentObject->attribute('main_parent_node_id'); $currentVersion = $contentObject->attribute('current_version'); $version = $contentObject->attribute('current'); $contentObjectAttributes = $version->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute('data_text', $firstName); $contentObjectAttributes[0]->store(); $contentObjectAttributes[1]->setAttribute('data_text', $lastName); $contentObjectAttributes[1]->store(); $existUser = eZUser::fetch($userID); $existUser->setAttribute('email', $email); $existUser->setAttribute('password_hash', ""); $existUser->setAttribute('password_hash_type', 0); $existUser->store(); if ($defaultUserPlacement != $parentNodeID) { $newVersion = $contentObject->createNewVersion(); $newVersion->assignToNode($defaultUserPlacement, 1); $newVersion->removeAssignment($parentNodeID); $newVersionNr = $newVersion->attribute('version'); $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $userID, 'version' => $newVersionNr)); } eZUser::updateLastVisit($userID); eZUser::setCurrentlyLoggedInUser($existUser, $userID); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); $db->commit(); return $existUser; } } else { // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; } } } fclose($handle); } } // Increase number of failed login attempts. if (isset($userID)) { eZUser::setFailedLoginAttempts($userID); } return false; }
function handleInlineNode($childNode, $nextLineBreak = false, $prevLineBreak = false) { $localName = $childNode->localName; if ($localName == '') { $localName = $childNode->nodeName; } // Get the real name $paragraphContent = ''; switch ($localName) { case "frame": $frameContent = ""; foreach ($childNode->childNodes as $imageNode) { switch ($imageNode->localName) { case "image": $href = ltrim($imageNode->getAttributeNS(self::NAMESPACE_XLINK, 'href'), '#'); if (0 < preg_match('@^(?:http://)([^/]+)@i', $href)) { eZDebug::writeDebug("handling http url: {$href}", __METHOD__); $matches = array(); if (0 < preg_match('/.*\\/(.*)?/i', $href, $matches)) { $fileName = $matches[1]; if (false != ($imageData = file_get_contents($href))) { $href = $this->ImportDir . $fileName; $fileOut = fopen($href, "wb"); if (fwrite($fileOut, $imageData)) { eZDebug::writeNotice("External image stored in {$href}", __METHOD__); } else { eZDebug::writeError("Could not save file {$href}", __METHOD__); } fclose($fileOut); } else { eZDebug::writeError("Downloading external image from {$href} has failed, broken link?", __METHOD__); } } else { eZDebug::writeError("Could not match filename in {$href}", __METHOD__); } } else { $href = $this->ImportDir . $href; } // Check image name $imageName = $childNode->getAttributeNS(self::NAMESPACE_DRAWING, 'name'); if (!$imageName) { // set default image name $imageName = "Imported Image"; } $imageSize = "medium"; $imageAlignment = "center"; // Check image size $imageSize = "large"; $pageWidth = 6; $width = $childNode->getAttributeNS(self::NAMESPACE_SVG_COMPATIBLE, 'width'); $sizePercentage = $width / $pageWidth * 100; if ($sizePercentage < 80 and $sizePercentage > 30) { $imageSize = 'medium'; } if ($sizePercentage <= 30) { $imageSize = 'small'; } // Check if image should be set to original $sizeArray = getimagesize($href); if ($imageSize != "small" and $sizeArray[0] < 650) { $imageSize = "original"; } $styleName = $childNode->getAttributeNS(self::NAMESPACE_DRAWING, 'style-name'); // Check for style definitions $imageAlignment = "center"; foreach ($this->AutomaticStyles as $style) { if ($style->nodeType !== XML_ELEMENT_NODE) { continue; } $tmpStyleName = $style->getAttributeNS(self::NAMESPACE_STYLE, "name"); if ($styleName == $tmpStyleName) { if ($style->childNodes->length == 1) { $properties = $style->childNodes->item(0); $alignment = $properties->getAttributeNS(self::NAMESPACE_STYLE, "horizontal-pos"); } // Check image alignment switch ($alignment) { case "left": $imageAlignment = "left"; break; case "right": $imageAlignment = "right"; break; default: $imageAlignment = "center"; break; } break; } } if (file_exists($href)) { // Calculate RemoteID based on image md5: $remoteID = "ezoo-" . md5(file_get_contents($href)); /* // Check if an image with the same remote ID already exists $db = eZDB::instance(); $imageParentNodeID = $GLOBALS["OOImportObjectID"]; $resultArray = $db->arrayQuery( 'SELECT id, node_id, ezcontentobject.remote_id FROM ezcontentobject, ezcontentobject_tree WHERE ezcontentobject.remote_id = "' . $remoteID. '" AND ezcontentobject.id=ezcontentobject_tree.contentobject_id AND ezcontentobject_tree.parent_node_id=' . $imageParentNodeID ); $contentObject = false; if ( count( $resultArray ) >= 1 ) { $contentObject = eZContentObject::fetch( $resultArray[0]['id'], true ); $contentObjectID = $resultArray[0]['id']; } */ $contentObject = eZContentObject::fetchByRemoteID($remoteID); // If image does not already exist, create it as an object if (!$contentObject) { // Import image $ooINI = eZINI::instance('odf.ini'); $imageClassIdentifier = $ooINI->variable("ODFImport", "DefaultImportImageClass"); $class = eZContentClass::fetchByIdentifier($imageClassIdentifier); $creatorID = $this->currentUserID; $contentObject = $class->instantiate($creatorID, 1); $contentObject->setAttribute("remote_id", $remoteID); $contentObject->store(); $version = $contentObject->version(1); $version->setAttribute('modified', eZDateTime::currentTimeStamp()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $contentObjectID = $contentObject->attribute('id'); $dataMap = $contentObject->dataMap(); // set image name $dataMap['name']->setAttribute('data_text', $imageName); $dataMap['name']->store(); // set image caption if (isset($dataMap['caption'])) { $captionContentAttibute = $dataMap['caption']; $captionText = "{$imageName}"; // create new xml for caption $xmlInputParser = new eZXMLInputParser(); $dom = $xmlInputParser->createRootNode(); $captionNode = $dom->createElement('paragraph', $captionText); $dom->documentElement->appendChild($captionNode); $xmlString = $dom->saveXML(); $captionContentAttibute->setAttribute('data_text', $xmlString); $captionContentAttibute->store(); } else { eZDebug::writeWarning("The image class does not have 'caption' attribute", 'ODF import'); } // set image $imageContent = $dataMap['image']->attribute('content'); //echo "Initializing Image from $href<br />"; $imageContent->initializeFromFile($href, false, basename($href)); $dataMap['image']->store(); } else { $contentObjectID = $contentObject->attribute('id'); } $this->RelatedImageArray[] = array("ID" => $contentObjectID, "ContentObject" => $contentObject); $frameContent .= "<embed object_id='{$contentObjectID}' align='{$imageAlignment}' size='{$imageSize}' />"; } break; } } // Textboxes are defined inside paragraphs. $paragraphContent .= "{$frameContent}"; break; case "text-box": foreach ($childNode->childNodes as $textBoxNode) { $boxContent .= self::handleNode($textBoxNode, $sectionLevel); } // Textboxes are defined inside paragraphs. $paragraphContent .= "</paragraph>{$boxContent}<paragraph>"; break; case 'sequence': case 'date': case 'initial-creator': $paragraphContent .= $childNode->textContent; break; case "s": $paragraphContent .= " "; break; case "a": $href = $childNode->getAttributeNS(self::NAMESPACE_XLINK, 'href'); $paragraphContent .= "<link href='{$href}'>" . $childNode->textContent . "</link>"; break; case "#text": $tagContent = str_replace("&", "&", $childNode->textContent); $tagContent = str_replace(">", ">", $tagContent); $tagContent = str_replace("<", "<", $tagContent); $tagContent = str_replace("'", "'", $tagContent); $tagContent = str_replace('"', """, $tagContent); $paragraphContent .= $tagContent; break; case "span": // Fetch the style from the span $styleName = $childNode->getAttributeNS(self::NAMESPACE_TEXT, 'style-name'); // Check for bold and italic styles $fontWeight = false; $fontStyle = false; foreach ($this->AutomaticStyles as $style) { if ($style->nodeType !== XML_ELEMENT_NODE) { continue; } $tmpStyleName = $style->getAttributeNS(self::NAMESPACE_STYLE, "name"); if ($styleName == $tmpStyleName) { if ($style->childNodes->length >= 1) { foreach ($style->childNodes as $styleChild) { if ($styleChild->nodeType !== XML_ELEMENT_NODE || !$styleChild->hasAttributes()) { continue; } $fontWeight = $styleChild->getAttributeNS(self::NAMESPACE_FO, 'font-weight'); $fontStyle = $styleChild->getAttributeNS(self::NAMESPACE_FO, 'font-style'); } } } } $inlineCustomTagName = false; if (substr($styleName, 0, 18) == "eZCustominline_20_") { $inlineCustomTagName = substr($styleName, 18); } if ($inlineCustomTagName != false) { $paragraphContent .= "<custom name='{$inlineCustomTagName}'>"; } if ($fontWeight == "bold") { $paragraphContent .= "<strong>"; } if ($fontStyle == "italic") { $paragraphContent .= "<emphasize>"; } $paragraphContent .= $childNode->textContent; if ($fontStyle == "italic") { $paragraphContent .= "</emphasize>"; } if ($fontWeight == "bold") { $paragraphContent .= "</strong>"; } if ($inlineCustomTagName != false) { $paragraphContent .= "</custom>"; } break; default: eZDebug::writeError("Unsupported node: '" . $localName . "'"); break; } if ($nextLineBreak) { $paragraphContent = '<line>' . $paragraphContent . '</line>'; } elseif ($prevLineBreak && $paragraphContent) { $paragraphContent = '<line>' . $paragraphContent . '</line>'; } return $paragraphContent; }
protected function getNamedContent($name, $forceSynchronization) { $contentName = 'content' . $name; if (!$this->$contentName) { $contentObject = eZContentObject::fetchByRemoteID( $this->{'remoteId' . $name}() ); if ( !$forceSynchronization && !$this->synchronizer->option('ForceSynchronization') && $contentObject instanceof eZContentObject ) { $this->$contentName = SQLIContent::fromContentObject( $contentObject ); if ($this->$contentName instanceof SQLIContent) { $this->{$contentName}->setActiveLanguage($this->source['pf_default_language']); } } else { $this->synchronize(); } } return $this->$contentName; }
private function fetchbyremoteid($remoteId) { $contentObject = eZContentObject::fetchByRemoteID($remoteId); $this->dumpContentObjectInfo($contentObject); }
public function run($remove = false, $useStateHashes = true, $update = true, $create = true) { $contentClass = $this->config->getContentClass(); $allOjectsInFeedRemoteIDs = array(); $dataList = $this->config->getDataList(); $dataListCount = count($dataList); if ($dataListCount > 0) { foreach ($dataList as $key => &$objectData) { $memoryUsage = number_format(memory_get_usage(true) / (1024 * 1024), 2); $this->debug(number_format($key / $dataListCount * 100, 2) . '% (' . ($key + 1) . '/' . $dataListCount . '), Memory usage: ' . $memoryUsage . ' Mb', array('red')); $objectData['remoteID'] = $this->config->getObjectRemoteID($objectData); $objectData['mainParentNodeID'] = $this->config->getMainParentNodeID($objectData); $objectData['adittionalParentNodeIDs'] = (array) $this->config->getAdittionalParentNodeIDs($objectData); $objectData['attributes'] = (array) $this->config->transformObjectAttributes($objectData); $objectData['language'] = $this->config->getLanguage($objectData); $objectData['versionStatus'] = $this->config->getVersionStatus($objectData); $objectData['mainNodePriority'] = $this->config->getMainNodePriority($objectData); $objectData['visibility'] = $this->config->isVisible($objectData); $currentStateHash = $this->config->getStateHash($objectData); $allOjectsInFeedRemoteIDs[] = $objectData['remoteID']; $object = eZContentObject::fetchByRemoteID($objectData['remoteID']); $result = $this->config->preProcessCallback($object, $objectData); if ($result === false) { $this->debug('[Skipped by preProcessCallback] Remote ID: "' . $objectData['remoteID'] . '"', array('blue')); $this->skip($object, $objectData); continue; } $skipped = false; if ($object instanceof eZContentObject) { if ($update === false) { $this->debug('[Skipped] "' . $object->attribute('name') . '"', array('blue')); $this->skip($object, $objectData); $skipped = true; } else { $storedStateHash = nxcImportStateHash::get($objectData['remoteID']); if ($currentStateHash == $storedStateHash && $useStateHashes === true) { $this->debug('[Skipped] "' . $object->attribute('name') . '" (Node ID: ' . $object->attribute('main_node_id') . ')', array('blue')); $this->skip($object, $objectData); $skipped = true; } else { $parentNode = false; if ($objectData['mainParentNodeID'] !== false) { $parentNode = eZContentObjectTreeNode::fetch($objectData['mainParentNodeID']); } if ($objectData['mainParentNodeID'] !== false && $parentNode instanceof eZContentObjectTreeNode === false) { $this->remove($object, $objectData); nxcImportStateHash::remove($object->attribute('remote_id')); $this->pcHandler->removeObject($object); } else { $params = array('object' => $object, 'attributes' => $objectData['attributes'], 'additionalParentNodeIDs' => $objectData['adittionalParentNodeIDs'], 'visibility' => (bool) $objectData['visibility']); if ($objectData['mainParentNodeID'] !== false) { $params['parentNode'] = $parentNode; } $this->pcHandler->updateObject($params); $this->update($object, $objectData); nxcImportStateHash::update($objectData['remoteID'], $currentStateHash); $object->resetDataMap(); eZContentObject::clearCache($object->attribute('id')); } } } } else { if ($create === false) { $this->debug('[Skipped]', array('blue')); $this->skip($object, $objectData); $skipped = true; } else { $object = $this->pcHandler->createObject(array('class' => $contentClass, 'parentNodeID' => $objectData['mainParentNodeID'], 'attributes' => $objectData['attributes'], 'remoteID' => $objectData['remoteID'], 'additionalParentNodeIDs' => $objectData['adittionalParentNodeIDs'], 'languageLocale' => isset($objectData['language']) ? $objectData['language'] : false, 'visibility' => (bool) $objectData['visibility'])); if ($object instanceof eZContentObject) { $this->create($object, $objectData); nxcImportStateHash::update($objectData['remoteID'], $currentStateHash); if ($objectData['mainNodePriority'] !== false) { $mainNode = $object->attribute('main_node'); $mainNode->setAttribute('priority', $objectData['mainNodePriority']); $mainNode->store(); } $object->resetDataMap(); eZContentObject::clearCache($object->attribute('id')); } } } $this->config->postProcessCallback($object, $objectData, $skipped); } $allOjectsInFeedRemoteIDs = array_unique($allOjectsInFeedRemoteIDs); if ($remove && count($allOjectsInFeedRemoteIDs) > 0) { $publishedObjects = $contentClass->objectList(); foreach ($publishedObjects as $object) { if (in_array($object->attribute('remote_id'), $allOjectsInFeedRemoteIDs) === false) { $this->remove($object, $objectData); nxcImportStateHash::remove($object->attribute('remote_id')); $this->pcHandler->removeObject($object); } } } } }
$cli->error( "You must specify a --clusterIdentifier\n" ); $script->showHelp(); $script->shutdown( 1 ); } $db = MMDB::instance(); $remoteIDsToFetch = array( "html-$clusterIdentifier-footer1", "html-$clusterIdentifier-footer2", "html-$clusterIdentifier-footer2_for_cookie_law" ); $exportedPagesCount = 0; foreach( $remoteIDsToFetch as $remoteID ) { $footersObject = eZContentObject::fetchByRemoteID( $remoteID ); if( $footersObject ) { $dm = $footersObject->DataMap(); if( $dm ) { $queryDelete = sprintf( 'DELETE FROM mm_footer WHERE cluster_identifier = "%s" AND block_identifier = "%s"', $clusterIdentifier, array_pop( explode( '-', $remoteID ) ) ); $db->query( $queryDelete ); $queryInsert = sprintf( 'INSERT INTO mm_footer (`cluster_identifier`, `block_identifier`, `content`) VALUES ("%s", "%s", "%s")', $clusterIdentifier,
$mdb = eZDB::instance(); $query = 'SELECT remote_id, cluster_identifier, count FROM mm_readcount_remote WHERE to_reindex = 1 GROUP BY remote_id'; $i = 0; /* We construct an array of [ object_id_1 => [node_id_1, node_id_2, ..], * object_id_2 => [node_id_1, node_id_2, node_id_3, ..] * ...] */ $objectIds = array(); $varnish_node_ids = array(); $solrJsonObjects = array(); foreach($mdb->arrayQuery($query) as $row) { $object = eZContentObject::fetchByRemoteID($row["remote_id"]); if($object) { $objectId = $object->attribute("id"); $objectIds[] = $objectId; $varnish_node_ids[] = $object->mainNode()->attribute('parent_node_id'); } else { //test if solrObject $fields = array( 'views' => 'attr_view_counter_'.$row['cluster_identifier'].'_i', );
<?php $module = $Params['ObjectID']; $tpl = eZTemplate::factory(); $error = false; $info = false; $detail = false; $xml = false; $solr = false; $objectID = $Params['ObjectID']; if (NULL == $Params['ObjectID']) { $error = "Object ID or object remote_id not found"; } else { $object = eZContentObject::fetch(intval($objectID)); if (!$object instanceof eZContentObject) { $object = eZContentObject::fetchByRemoteID($objectID); } if ($object instanceof eZContentObject) { if ($object->attribute('can_read')) { $searchEngine = new eZSolr(); $result = $searchEngine->addObject($object, true); $xmlData = fakeAddObject($object); if ($xmlData == false) { $result = false; $xmlData = array(); } $info = array('object' => $object, 'result' => $result); $detail = array(); $attributes = $object->dataMap(); foreach ($attributes as $attribute) { $isSearchable = $attribute->attribute('contentclass_attribute')->attribute('is_searchable');
public function loadLocalObjectsByRemoteId($unparsed_json) { $json_array = json_decode($unparsed_json, true); $returnArray = array(); foreach ($json_array as $key => $arrayRemoteId) { foreach ($arrayRemoteId as $remoteId) { $eZContentObject = eZContentObject::fetchByRemoteID($remoteId); if ($eZContentObject instanceof eZContentObject) { array_push($returnArray, $eZContentObject); } } } if (itobjectsutils::isEmptyArray($returnArray)) { return array(); } return $this->itFiltersUtil->updatablestatusobjects($returnArray); }
public function doViewContent() { $this->setDefaultResponseGroups(array(self::VIEWCONTENT_RESPONSEGROUP_METADATA, self::VIEWCONTENT_RESPONSEGROUP_FIELDS, self::VIEWCONTENT_RESPONSEGROUP_LOCATIONS)); $content = false; $isNodeRequested = false; if (isset($this->nodeId)) { $content = ezpContent::fromNodeId($this->nodeId); $isNodeRequested = true; } else { if (isset($this->objectId)) { $object = eZContentObject::fetch($this->objectId); if (!$object instanceof eZContentObject) { $object = eZContentObject::fetchByRemoteID($this->objectId); } if ($object instanceof eZContentObject) { $content = ezpContent::fromObject($object, true); } else { throw new ezpContentNotFoundException("Unable to find an eZContentObject with ID {$this->objectId}"); } } } if (!$content instanceof ezpContent) { throw new ezpContentNotFoundException("Unable to find content"); } $result = new ezpRestMvcResult(); // translation parameter if ($this->hasContentVariable('Translation')) { $content->setActiveLanguage($this->getContentVariable('Translation')); } // Handle metadata if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_METADATA)) { $objectMetadata = ITOpenDataContentModel::getMetadataByContent($content); if ($isNodeRequested) { $nodeMetadata = ITOpenDataContentModel::getMetadataByLocation(ezpContentLocation::fetchByNodeId($this->nodeId)); $objectMetadata = array_merge($objectMetadata, $nodeMetadata); } $result->variables['metadata'] = $objectMetadata; } // Handle locations if requested if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_LOCATIONS)) { $result->variables['locations'] = ITOpenDataContentModel::getLocationsByContent($content); } // Handle fields content if requested if ($this->hasResponseGroup(self::VIEWCONTENT_RESPONSEGROUP_FIELDS)) { $result->variables['fields'] = ITOpenDataContentModel::getFieldsByContent($content, $this->request, $this->getRouter()); } // Add links to fields resources $result->variables['links'] = ITOpenDataContentModel::getFieldsLinksByContent($content, $this->request); if ($outputFormat = $this->getContentVariable('OutputFormat')) { $renderer = ezpRestContentRenderer::getRenderer($outputFormat, $content, $this); $result->variables['renderedOutput'] = $renderer->render(); } return $result; }
function postUnserializeContentObjectAttribute($package, $objectAttribute) { $attributeChanged = false; $relatedObjectID = $objectAttribute->attribute('data_int'); if (!$relatedObjectID) { // Restore cross-relations using preserved remoteID $relatedObjectRemoteID = $objectAttribute->attribute('data_text'); if ($relatedObjectRemoteID) { $object = eZContentObject::fetchByRemoteID($relatedObjectRemoteID); $relatedObjectID = $object !== null ? $object->attribute('id') : null; if ($relatedObjectID) { $objectAttribute->setAttribute('data_int', $relatedObjectID); $attributeChanged = true; } } } return $attributeChanged; }
/** * @return array */ public static function selectionList() { $userSelections = array(); $selections = MMSelections::fetchUserSelection(null, null, false); /* @type $selection MMSelections */ while ( list(, $selection) = each($selections) ) { $object = eZContentObject::fetchByRemoteID($selection->attribute('remote_id')); if ( $object instanceof eZContentObject ) { $node = $object->mainNode(); /* @type $dataMap eZContentObjectAttribute[] */ $dataMap = $node->dataMap(); // Get first promo_image $image = false; if ( isset($dataMap['promo_image']) && $dataMap['promo_image']->hasContent() ) { $content = $dataMap['promo_image']->content(); $relationList = $content['relation_list']; if ( isset($relationList[0]['node_id']) ) { /* @type $imageDataMap eZContentObjectAttribute[] */ $imageNode = eZContentObjectTreeNode::fetch($relationList[0]['node_id']); $imageDataMap = $imageNode->dataMap(); if ( isset($imageDataMap['file']) && $imageDataMap['file']->hasContent() ) { /* @type $imageFileContent eZImageAliasHandler */ $imageFileContent = $imageDataMap['file']->content(); $imageFileAlias = $imageFileContent->imageAlias('original'); $image = $imageFileAlias['url']; } } } $applicationLocalized = CacheApplicationTool::buildLocalizedApplicationByIdentifier($selection->attribute('application')); $applicationObject = $applicationLocalized->applicationObject(); $userSelections[] = array( 'headline' => $node->getName(), 'nodeId' => $selection->attribute('node_id'), 'date' => date(DATE_ATOM, $selection->attribute('add_date')), 'application' => $applicationObject->attribute('id'), 'applicationName' => $applicationLocalized->attribute("name"), 'description' => $selection->attribute('description'), 'image' => '/' . $image, 'url' => NodeOperatorHelper::getUrlNode($selection->attribute('application'), $node) ); } } return array( 'selection' => $userSelections, 'count' => MMSelections::countTotalFromUserSelection() ); }
/** * Returns Merck Manual for given cluster identifier or null if doesn't exist * @param string $clusterIdentifier * @return NULL|eZContentObject */ function getMerckManualShowcase( $clusterIdentifier ) { $object = eZContentObject::fetchByRemoteID( 'application_folder-' . $clusterIdentifier . '-' . IDENTIFIER_MERCK_MANUAL_SHOWCASE ); if ( !$object instanceof eZContentObject ) { return null; } return $object; }
/** * Adds an application folder to the publisher folder if it's not yet added * @param mixed $applicationId * @param mixed $publisherFolderId * @param eZCLI $cli */ function alignApplicationWithPublisherFolder( $applicationId, $publisherFolderId, eZCLI $cli ) { $application = $applicationId; $publisherFolder = $publisherFolderId; if (! $application instanceof ApplicationLocalized ) { $application = ApplicationLocalized::getLocalizedApplicationById( $applicationId, false ); } if ( $application == null ) { throw new Exception( "Application localized with id {$applicationId} does not exist." ); } if (! $publisherFolder instanceof MMSynchPublisherFolder ) { $publisherFolder = MMSynchPublisherFolder::fetch( $publisherFolderId ); } if ( $publisherFolder == null ) { throw new Exception( "Publisher folder with id {$publisherFolderId} does not exist." ); } $remoteId = 'application_folder-' . $application->cluster_identifier . '-' . $application->applicationObject->identifier; $applicationFolderObject = eZContentObject::fetchByRemoteID( $remoteId ); if ( $applicationFolderObject == null ) { throw new Exception( "Application folder object with remote id {$remoteId} doesn't exist" ); } $applicationFolderId = $applicationFolderObject->attribute( 'id' ); //use getContent with true to create problems $path = $publisherFolder->getContent( )->fields->path->toString(); if ( $path ) { $contentobject = $publisherFolder->getContent()->getRawContentObject(); $languages = $contentobject->availableLanguages(); foreach ( $languages as $language ) { $dataMap = $contentobject->dataMap(); $contentObjectAttributeTargetCS = $dataMap['target_cs']; $objectIds = explode( '-', $contentObjectAttributeTargetCS->toString() ); if ( !in_array( $applicationFolderId, $objectIds ) ) { $objectIds[] = $applicationFolderId; $contentObjectAttributeTargetCS->fromString( implode( '-', $objectIds ) ); $contentObjectAttributeTargetCS->store(); } else { $cli->notice( "Ommiting application folder with path {$remoteId}" ); } } } }
/** * Initializes an object from RemoteID. * If no content object can be found, returns null * @param int $remoteID * @return SQLIContent|null */ public static function fromRemoteID($remoteID) { $contentObject = eZContentObject::fetchByRemoteID($remoteID); $content = null; if ($contentObject instanceof eZContentObject) { $content = self::fromContentObject($contentObject); } else { SQLIImportLogger::logWarning("Unable to find an eZContentObject with RemoteID {$remoteID}", false); } return $content; }
/** * @param string $path * @param MerckManualShowcase $app * @return bool|eZContentObjectTreeNode */ public static function findNodeFromPath( $path, &$app ) { /* We remove the publisher folder id at the beginning of the url as we already have it */ $path = preg_replace('#^/\d+/#', '/', $path ); $manualAppNode = eZContentObjectTreeNode::fetch( self::rootNodeId() ); $manualAppNodePathName = $manualAppNode->pathWithNames(); $tabNodePath = explode('/', substr($path, 1)); $remoteId = end($tabNodePath); if(preg_match('/^[a-f0-9]{32}$/', $remoteId)) { $nodeRemote = eZContentObjectTreeNode::fetchByRemoteID($remoteId); if($nodeRemote instanceof eZContentObjectTreeNode) { $app->fullContext = 'topic'; return $nodeRemote; } } $pathParts = explode('/', substr($path, 1)); if ( $pathParts[0] == 'table' ) { $app->fullContext = 'table'; return eZContentObjectTreeNode::fetch($pathParts[1]); } // Url with topic list($sectionName, $chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; // Url without topic $matches = array(); if ( preg_match('/media-([a-z]+)/', $topicName, $matches) ) { list($sectionName, $chapterName, $mediaType, $mediaName, $other) = $pathParts; $topicName = null; } // Full section if ( $sectionName != null && is_null( $chapterName ) && is_null( $topicName ) ) { $app->fullContext = 'section'; $app->section = MerckManualFunctionCollection::fetchSection('url', $sectionName); return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId()); } if ( $sectionName == 'about-us' ) { list($chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts; } $path = $manualAppNodePathName; // Full of chapter if ( $chapterName ) { $app->fullContext = 'chapter'; $path .= '/' . $chapterName; } // Full of topic if ( $topicName ) { $app->fullContext = 'topic'; $path .= '/' . $topicName; } $nodeId = eZURLAliasML::fetchNodeIDByPath($path); if ( $nodeId ) { if ( $mediaName ) { $mediaType = str_replace('media-', '', $mediaType); // Get media node // Full of html table image // /topic_name/(media-image-file)/oscar2/filename if ( $mediaType == 'image-file' ) { $app->fullContext = $mediaType; $app->oscarFolder = $mediaName; $app->mediaName = $other; } // Full of inline audio, video, image elseif ( $mediaType ) { // Construct the remote_id of the media folder /* @type $dataMap eZContentObjectAttribute[] */ $contentObject = eZContentObject::fetchByNodeID($nodeId); $dataMap = $contentObject->dataMap(); $publisherAttrContent = $dataMap['publisher']->content(); if ( isset($publisherAttrContent['relation_list'][0]['contentobject_remote_id']) ) { // Get media folder $mediaFolderRemoteId = sprintf('%s_media_%s', $publisherAttrContent['relation_list'][0]['contentobject_remote_id'], $mediaType); $mediaFolder = eZContentObject::fetchByRemoteID($mediaFolderRemoteId); if ( $mediaFolder ) { // Get media $mediaFolderPathName = $mediaFolder->mainNode()->pathWithNames(); $nodeId = eZURLAliasML::fetchNodeIDByPath($mediaFolderPathName . '/' . $mediaName); $app->fullContext = $mediaType; } } } } } if ( $nodeId ) { // Full of chapter must not be accessible, show first topic if ( $app->fullContext == 'chapter' ) { $params = array( 'Depth' => 1, 'DepthOperator' => 'eq', 'SortBy' => array(array('priority', 'asc')), 'Limit' => 1 ); $children = eZContentObjectTreeNode::subTreeByNodeID($params, $nodeId); if ( isset($children[0]) && $children[0] instanceof eZContentObjectTreeNode ) { $node = $children[0]; $app->fullContext = 'topic'; } else $node = null; } else { $node = eZContentObjectTreeNode::fetch($nodeId); } return $node; } return false; }
/** * Unserialize xml structure. Creates an object from xml input. * * Transaction unsafe. If you call several transaction unsafe methods you must enclose * the calls within a db transaction; thus within db->begin and db->commit. * * @param mixed $package * @param DOMElement $domNode * @param array $options * @param int|bool $ownerID Override owner ID, null to use XML owner id (optional) * @param string $handlerType * @return array|bool|eZContentObject|null created object, false if could not create object/xml invalid */ static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' ) { if ( $domNode->localName != 'object' ) { $retValue = false; return $retValue; } $initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options ); if( $initialLanguage === 'skip' ) { $retValue = true; return $retValue; } $sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' ); if ( $ownerID === false ) { $ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' ); } $remoteID = $domNode->getAttribute( 'remote_id' ); $name = $domNode->getAttribute( 'name' ); $classRemoteID = $domNode->getAttribute( 'class_remote_id' ); $classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' ); $alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' ); $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID ); if ( !$contentClass ) { $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier ); } if ( !$contentClass ) { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS, 'element_id' => $remoteID, 'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." ); $retValue = false; return $retValue; } /** @var DOMElement $versionListNode */ $versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 ); $importedLanguages = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { /** @var DOMElement $versionDOMNode */ foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild ) { /** @var DOMElement $versionDOMNodeChild */ $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options ); $language = eZContentLanguage::fetchByLocale( $importedLanguage ); // Check if the language is allowed in this setup. if ( $language ) { $hasTranslation = true; } else { if ( $importedLanguage == 'skip' ) continue; // if there is no needed translation in system then add it $locale = eZLocale::instance( $importedLanguage ); $translationName = $locale->internationalLanguageName(); $translationLocale = $locale->localeCode(); if ( $locale->isValid() ) { eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); $hasTranslation = true; } else $hasTranslation = false; } if ( $hasTranslation ) { $importedLanguages[] = $importedLanguage; $importedLanguages = array_unique( $importedLanguages ); } } } // If object exists we return a error. // Minimum install element is an object now. $contentObject = eZContentObject::fetchByRemoteID( $remoteID ); // Figure out initial language if ( !$initialLanguage || !in_array( $initialLanguage, $importedLanguages ) ) { $initialLanguage = false; foreach ( eZContentLanguage::prioritizedLanguages() as $language ) { if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) ) { $initialLanguage = $language->attribute( 'locale' ); break; } } } if ( !$contentObject ) { $firstVersion = true; $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); } else { $firstVersion = false; $description = "Object '$name' already exists."; $choosenAction = eZPackageHandler::errorChoosenAction( self::PACKAGE_ERROR_EXISTS, $options, $description, $handlerType, false ); switch( $choosenAction ) { case eZPackage::NON_INTERACTIVE: case self::PACKAGE_UPDATE: { // Keep existing contentobject. } break; case self::PACKAGE_REPLACE: { eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) ); unset( $contentObject ); $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); $firstVersion = true; } break; case self::PACKAGE_SKIP: { $retValue = true; return $retValue; } break; case self::PACKAGE_NEW: { $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) ); $contentObject->store(); unset( $contentObject ); $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID ); $firstVersion = true; } break; default: { $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_EXISTS, 'element_id' => $remoteID, 'description' => $description, 'actions' => array( self::PACKAGE_REPLACE => ezpI18n::tr( 'kernel/classes', 'Replace existing object' ), self::PACKAGE_SKIP => ezpI18n::tr( 'kernel/classes', 'Skip object' ), self::PACKAGE_NEW => ezpI18n::tr( 'kernel/classes', 'Keep existing and create a new one' ), self::PACKAGE_UPDATE => ezpI18n::tr( 'kernel/classes', 'Update existing object' ) ) ); $retValue = false; return $retValue; } break; } } $db = eZDB::instance(); $db->begin(); if ( $alwaysAvailable ) { // Make sure always available bit is set. $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 ); } $contentObject->setAttribute( 'section_id', $sectionID ); $contentObject->store(); $activeVersion = false; $lastVersion = false; $versionListActiveVersion = $versionListNode->getAttribute( 'active_version' ); $contentObject->setAttribute( 'remote_id', $remoteID ); $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) ); $contentObject->store(); $sectionObject = eZSection::fetch( $sectionID ); if ( $sectionObject instanceof eZSection ) { $updateWithParentSection = false; } else { $updateWithParentSection = true; } $options['language_array'] = $importedLanguages; $versionList = array(); foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode ) { unset( $nodeList ); $nodeList = array(); $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode, $contentObject, $ownerID, $sectionID, $versionListActiveVersion, $firstVersion, $nodeList, $options, $package, 'ezcontentobject', $initialLanguage ); if ( !$contentObjectVersion ) { $db->commit(); $retValue = false; return $retValue; } $versionStatus = $versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'status' ); $versionList[$versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'version' )] = array( 'node_list' => $nodeList, 'status' => $versionStatus ); unset( $versionStatus ); $firstVersion = false; $lastVersion = $contentObjectVersion->attribute( 'version' ); if ( $versionDOMNode->getAttribute( 'version' ) == $versionListActiveVersion ) { $activeVersion = $contentObjectVersion->attribute( 'version' ); } eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion ); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $lastVersion ) ); $mainNodeInfo = null; foreach ( $nodeList as $nodeInfo ) { if ( $nodeInfo['is_main'] ) { $mainNodeInfo =& $nodeInfo; break; } } if ( $mainNodeInfo ) { $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false ); if ( $existingMainNode ) { eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'], $mainNodeInfo['contentobject_id'], $mainNodeInfo['contentobject_version'], $mainNodeInfo['parent_node'], $updateWithParentSection ); } } unset( $mainNodeInfo ); // Refresh $contentObject from DB. $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) ); } if ( !$activeVersion ) { $activeVersion = $lastVersion; } /* $contentObject->setAttribute( 'current_version', $activeVersion ); */ $contentObject->setAttribute( 'name', $name ); if ( isset( $options['use_dates_from_package'] ) && $options['use_dates_from_package'] ) { $contentObject->setAttribute( 'published', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'published' ) ) ); $contentObject->setAttribute( 'modified', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ) ); } $contentObject->store(); $versions = $contentObject->versions(); $objectName = $contentObject->name(); $objectID = $contentObject->attribute( 'id' ); foreach ( $versions as $version ) { $versionNum = $version->attribute( 'version' ); $oldVersionStatus = $version->attribute( 'status' ); $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null; // set the correct status for non-published versions if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != eZContentObjectVersion::STATUS_PUBLISHED ) { $version->setAttribute( 'status', $newVersionStatus ); $version->store( array( 'status' ) ); } // when translation does not have object name set then we copy object name from the current object version $translations = $version->translations( false ); if ( !$translations ) continue; foreach ( $translations as $translation ) { if ( ! $contentObject->name( $versionNum, $translation ) ) { eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)" ); $contentObject->setName( $objectName, $versionNum, $translation ); } } } foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo ) { unset( $parentNode ); $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ), $nodeInfo['parent_node'] ); if ( is_object( $parentNode ) ) { $parentNode->setAttribute( 'priority', $nodeInfo['priority'] ); $parentNode->store( array( 'priority' ) ); } } $db->commit(); return $contentObject; }
$script->initialize(); $query = "select f.id, f.path as path from mm_application_has_publisher_folder as h left join mm_publisher_folder as f on h.publisher_folder_id = f.id order by f.id"; $db = MMDB::instance(); $allResults = $db->arrayQuery( $query ); $folders = array(); $interactiveQuestion = new QuestionInteractiveCli(); $cli = eZCLI::instance(); foreach ( $allResults as $row ) { $exists = ( is_array(eZContentObject::fetchByRemoteID( 'publisher_folder-' . $row['path'], false )) ); if ( $exists ) $folders[$row['id']] = $row['path']; } if ( isset($options['publisherFolders']) ) { $folderList = explode(',', $options['publisherFolders'] ); $replies = array(); foreach ($folderList as $folder) { if ( ($key = array_search($folder, $folders)) !== false ) { $replies[] = $key; }
static function transformRemoteLinksToLinks(DOMNodeList $nodeList, $objectAttribute) { $modified = false; $contentObject = $objectAttribute->attribute('object'); foreach ($nodeList as $node) { $objectRemoteID = $node->getAttribute('object_remote_id'); $nodeRemoteID = $node->getAttribute('node_remote_id'); if ($objectRemoteID) { $objectArray = eZContentObject::fetchByRemoteID($objectRemoteID, false); if (!is_array($objectArray)) { eZDebug::writeWarning("Can't fetch object with remoteID = {$objectRemoteID}", __METHOD__); continue; } $objectID = $objectArray['id']; if ($node->localName == 'object') { $node->setAttribute('id', $objectID); } else { $node->setAttribute('object_id', $objectID); } $node->removeAttribute('object_remote_id'); $modified = true; // add as related object if ($contentObject) { $relationType = $node->localName == 'link' ? eZContentObject::RELATION_LINK : eZContentObject::RELATION_EMBED; $contentObject->addContentObjectRelation($objectID, $objectAttribute->attribute('version'), 0, $relationType); } } elseif ($nodeRemoteID) { $nodeArray = eZContentObjectTreeNode::fetchByRemoteID($nodeRemoteID, false); if (!is_array($nodeArray)) { eZDebug::writeWarning("Can't fetch node with remoteID = {$nodeRemoteID}", __METHOD__); continue; } $node->setAttribute('node_id', $nodeArray['node_id']); $node->removeAttribute('node_remote_id'); $modified = true; // add as related object if ($contentObject) { $relationType = $node->nodeName == 'link' ? eZContentObject::RELATION_LINK : eZContentObject::RELATION_EMBED; $contentObject->addContentObjectRelation($nodeArray['contentobject_id'], $objectAttribute->attribute('version'), 0, $relationType); } } } return $modified; }
/** * @param string $uuid * @param string $country */ static function updateELstatus( $uuid, $country ) { // elearning status update $elearningSelection = self::fetchUserSelectionByApps( $uuid, $country, array('e-learning'), array( self::ELEARNING_STATUS_STARTED ) ); if( count($elearningSelection) ) { // we build an array => [ courseId => selection ] $selectionsByCourseId = array(); /* @var $elearningSelection MMSelections[] */ foreach( $elearningSelection as $s ) { /* @var $s MMSelections */ $object = eZContentObject::fetchByRemoteID( $s->attribute('remote_id') ); if( $object ) { /* @type $dataMap eZContentObjectAttribute[] */ $dataMap = $object->dataMap(); $selectionsByCourseId[$dataMap['publisher_internal_id']->content()] = $s; } } } }
public function execute( $process, $event ) { $parameters = $process->attribute( 'parameter_list' ); $object = eZContentObject::fetch( $parameters['object_id'] ); $attribute = false; $dataMap = $object->attribute( 'data_map' ); foreach ( $dataMap as $attr ) { $dataType = $attr->attribute( 'data_type_string' ); if ( $dataType == 'ezfeatureselect' ) { $attribute = $attr; continue; } } // if object does not have a featureselect attribute. if ( $attribute == false ) { return eZWorkflowType::STATUS_ACCEPTED; } // if we have not the first version published, we only need to enable/disable features if ( $object->attribute( 'modified' ) != $object->attribute( 'published' ) ) { $attributeContent = $attribute->attribute( 'content' ); $installedFeatureList = $attributeContent['installed_feature_list']; $availibleFeatureList = $attributeContent['availible_feature_list']; $mainNodeID = $object->attribute( 'main_node_id' ); foreach( $availibleFeatureList as $feature => $featureName ) { $featureObject = eZContentObject::fetchByRemoteID( $mainNodeID . '_' . $feature ); if( !$featureObject ) { eZDebug::writeError( "Cannot find feature object", "eZXMLPublisherType::execute" ); continue; } $featureNode = $featureObject->attribute( 'main_node' ); if( !$featureNode ) { eZDebug::writeError( "Cannot find feature node", "eZXMLPublisherType::execute" ); continue; } if ( in_array( $feature, $installedFeatureList ) ) { if ( $featureNode->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::unhideSubTree( $featureNode ); } $featureObject = $featureNode->attribute( 'object' ); $list = $featureObject->reverseRelatedObjectList( false, 0, false, array( 'AllRelations' => eZContentObject::RELATION_ATTRIBUTE, 'IgnoreVisibility' => true ) ); if ( is_array( $list ) ) { foreach ( $list as $reverseRelatedContentObject ) { $reverseRelatedMainNode = $reverseRelatedContentObject->attribute( 'main_node' ); eZContentObjectTreeNode::unhideSubTree( $reverseRelatedMainNode ); } } } elseif ( !in_array( $feature, $installedFeatureList ) && !$featureNode->attribute( 'is_hidden' ) ) { if ( !$featureNode->attribute( 'is_hidden' ) ) { eZContentObjectTreeNode::hideSubTree( $featureNode ); } $featureObject = $featureNode->attribute( 'object' ); $list = $featureObject->reverseRelatedObjectList( false, 0, false, array( 'AllRelations' => eZContentObject::RELATION_ATTRIBUTE, 'IgnoreVisibility' => true ) ); if ( is_array( $list ) ) { foreach ( $list as $reverseRelatedContentObject ) { $reverseRelatedMainNode = $reverseRelatedContentObject->attribute( 'main_node' ); eZContentObjectTreeNode::hideSubTree( $reverseRelatedMainNode ); } } } } } // defer to cron, this is safer because we might do a lot of things here include_once( 'lib/ezutils/classes/ezsys.php' ); if ( eZSys::isShellExecution() == false ) { return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT; } // if we have the first version published, we need to set up the related things. if ( $object->attribute( 'modified' ) == $object->attribute( 'published' ) ) { $classAttribute = $attribute->attribute( 'contentclass_attribute' ); $templateName = $classAttribute->attribute( 'data_text1' ); $attributeContent = $attribute->attribute( 'content' ); $installedFeatureList = $attributeContent['installed_feature_list']; $availibleFeatureList = $attributeContent['availible_feature_list']; if( $templateName == '' ) { return eZWorkflowType::STATUS_ACCEPTED; } $template = 'design:' . $templateName; $tpl = eZTemplate::factory(); $tpl->setVariable( 'tpl_info', false ); $content = $tpl->fetch( $template ); $tpl->setVariable( 'install_features', $installedFeatureList ); $userID = $object->attribute( 'owner_id' ); $tpl->setVariable( 'owner_object_id', $userID ); $nodeID = $object->attribute( 'main_node_id' ); $tpl->setVariable( 'main_node_id', $nodeID ); $content = $tpl->fetch( $template ); $xml = $tpl->variable( "xml_data" ); $doc = new DOMDocument( '1.0', 'utf-8' ); if( !$doc->loadXML( $xml ) ) { eZDebug::writeError( "Cannot parse XML", "eZXMLPublisherType::execute" ); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } $xmlInstaller = new eZXMLInstaller( $doc ); if (! $xmlInstaller->proccessXML() ) { eZDebug::writeError( "Cannot proccess XML", "eZXMLPublisherType::execute" ); return eZWorkflowType::STATUS_WORKFLOW_CANCELLED; } return eZWorkflowType::STATUS_ACCEPTED; } // otherwise we need only to enable, disable the selected features. else { } return eZWorkflowType::STATUS_ACCEPTED; }
static function unserialize( $domNode, $contentObject, $ownerID, $sectionID, $activeVersion, $firstVersion, &$nodeList, &$options, $package, $handlerType = 'ezcontentobject' ) { $oldVersion = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'version' ); $status = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'status' ); $languageNodeArray = $domNode->getElementsByTagName( 'object-translation' ); $initialLanguage = false; $importedLanguages = $options['language_array']; $currentLanguages = array(); foreach( $languageNodeArray as $languageNode ) { $language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options ); if ( in_array( $language, $importedLanguages ) ) { $currentLanguages[] = $language; } } foreach ( eZContentLanguage::prioritizedLanguages() as $language ) { if ( in_array( $language->attribute( 'locale' ), $currentLanguages ) ) { $initialLanguage = $language->attribute( 'locale' ); break; } } if ( !$initialLanguage ) { $initialLanguage = $currentLanguages[0]; } if ( $firstVersion ) { $contentObjectVersion = $contentObject->version( 1 ); } else { // Create new version in specific language but with empty data. $contentObjectVersion = $contentObject->createNewVersionIn( $initialLanguage ); } $created = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'created' ) ); $modified = eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ); $contentObjectVersion->setAttribute( 'created', $created ); $contentObjectVersion->setAttribute( 'modified', $modified ); $contentObjectVersion->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT ); $contentObjectVersion->store(); $db = eZDB::instance(); $db->begin(); foreach( $languageNodeArray as $languageNode ) { $language = eZContentObjectVersion::mapLanguage( $languageNode->getAttribute( 'language' ), $options ); // Only import allowed languages. if ( !in_array( $language, $importedLanguages ) ) { continue; } $attributeArray = $contentObjectVersion->contentObjectAttributes( $language ); if ( count( $attributeArray ) == 0) { $hasTranslation = eZContentLanguage::fetchByLocale( $language ); if ( !$hasTranslation ) { // if there is no needed translation in system then add it $locale = eZLocale::instance( $language ); if ( $locale->isValid() ) { eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() ); $hasTranslation = true; } else $hasTranslation = false; } if ( $hasTranslation ) { // Add translated attributes for the translation $originalContentAttributes = $contentObjectVersion->contentObjectAttributes( $initialLanguage ); foreach ( $originalContentAttributes as $originalContentAttribute ) { $contentAttribute = $originalContentAttribute->translateTo( $language ); $contentAttribute->sync(); $attributeArray[] = $contentAttribute; } } // unserialize object name in current version-translation $objectName = $languageNode->getAttribute( 'object_name' ); if ( $objectName ) $contentObject->setName( $objectName, $contentObjectVersion->attribute( 'version' ), $language ); } $xpath = new DOMXPath( $domNode->ownerDocument ); $xpath->registerNamespace( 'ezobject', 'http://ez.no/object/' ); $xpath->registerNamespace( 'ezremote', 'http://ez.no/ezobject' ); foreach( $attributeArray as $attribute ) { $attributeIdentifier = $attribute->attribute( 'contentclass_attribute_identifier' ); $xpathQuery = "ezobject:attribute[@ezremote:identifier='$attributeIdentifier']"; $attributeDomNodes = $xpath->query( $xpathQuery, $languageNode ); $attributeDomNode = $attributeDomNodes->item( 0 ); if ( !$attributeDomNode ) { continue; } $attribute->unserialize( $package, $attributeDomNode ); $attribute->store(); } } $objectRelationList = $domNode->getElementsByTagName( 'object-relation-list' )->item( 0 ); if ( $objectRelationList ) { $objectRelationArray = $objectRelationList->getElementsByTagName( 'related-object-remote-id' ); foreach( $objectRelationArray as $objectRelation ) { $relatedObjectRemoteID = $objectRelation->textContent; if ( $relatedObjectRemoteID ) { $object = eZContentObject::fetchByRemoteID( $relatedObjectRemoteID ); $relatedObjectID = ( $object !== null ) ? $object->attribute( 'id' ) : null; if ( $relatedObjectID ) { $contentObject->addContentObjectRelation( $relatedObjectID, $contentObjectVersion->attribute( 'version' ) ); } else { if ( !isset( $options['suspended-relations'] ) ) { $options['suspended-relations'] = array(); } $options['suspended-relations'][] = array( 'related-object-remote-id' => $relatedObjectRemoteID, 'contentobject-id' => $contentObject->attribute( 'id' ), 'contentobject-version' => $contentObjectVersion->attribute( 'version' ) ); } } } } $nodeAssignmentNodeList = $domNode->getElementsByTagName( 'node-assignment-list' )->item( 0 ); $nodeAssignmentNodeArray = $nodeAssignmentNodeList->getElementsByTagName( 'node-assignment' ); foreach( $nodeAssignmentNodeArray as $nodeAssignmentNode ) { $result = eZContentObjectTreeNode::unserialize( $nodeAssignmentNode, $contentObject, $contentObjectVersion->attribute( 'version' ), ( $oldVersion == $activeVersion ? 1 : 0 ), $nodeList, $options, $handlerType ); if ( $result === false ) { $db->commit(); $retValue = false; return $retValue; } } $contentObjectVersion->store(); $db->commit(); return $contentObjectVersion; }
$cli->output(sprintf('%s article to check', count($result))); while(list(,$row) = each($result)) { $article = false; try { $db->begin(); $article = MMSynchArticle::fetch($row['a_id']); if ($article) { $remoteId = $article->remoteId(); $object = eZContentObject::fetchByRemoteID($remoteId, true); if ($object) { $logPrefix = sprintf('Synchronize object[%s] %s with article %s', $row['a_language'], $object->ID, $row['a_id'] ); $dataMap = $object->fetchDataMap(false, $row['a_language']); if (!$dataMap) throw new Exception(sprintf('DataMap not fetchable for object[%s] %s with article %s', $row['a_language'], $object->ID, $row['a_id'])); $str = implode('-', MMSynchArticle::fetchIdsToObjectIds('MMSynchMediaImage', explode(',', $article->source['a_promo_image']))); if ($str != $dataMap['promo_image']->toString()) { $cli->output(sprintf($logPrefix . ' change promo_image %s => %s', $dataMap['promo_image']->toString(), $str)); if ($options['apply'] == true)
$script->shutdown( 1 , 'publisher must be the numeric id' ); } $mustDelete = isset($options['delete']); $node = eZContentObjectTreeNode::fetch($publisherID); if ($node) { if ($node->classIdentifier() != 'publisher_folder') { $cli->warning('Is not a publisher_folder'); $script->shutdown(true); } $remoteId = $node->object()->attribute('remote_id'); $objectMedia = eZContentObject::fetchByRemoteID($remoteId . '_media'); $nodeIds = array( $node->attribute('node_id'), $objectMedia->attribute('main_node_id') ); $params = array( 'Limitation' => array(), 'SortBy' => array( 'path' , false ), 'Offset' => 0, 'Limit' => 100, 'IgnoreVisibility' => true, 'ClassFilterType' => 'exclude', 'ClassFilterArray' => array('folder', 'publisher_folder'), 'Depth' => 10 );