public function fetch($parameters, $publishedAfter, $publishedBeforeOrAt)
 {
     if (isset($parameters['Source'])) {
         $nodeID = $parameters['Source'];
         $node = eZContentObjectTreeNode::fetch($nodeID, false, false);
         // not as an object
         if ($node && $node['modified_subnode'] <= $publishedAfter) {
             return array();
         }
     } else {
         $nodeID = 0;
     }
     $subTreeParameters = array();
     $subTreeParameters['AsObject'] = false;
     $subTreeParameters['SortBy'] = array('published', false);
     // first the latest
     $subTreeParameters['AttributeFilter'] = array('and', array('published', '>', $publishedAfter), array('published', '<=', $publishedBeforeOrAt), array('visibility', '=', true));
     if (isset($parameters['Class'])) {
         $subTreeParameters['ClassFilterType'] = 'include';
         $subTreeParameters['ClassFilterArray'] = explode(';', $parameters['Class']);
     }
     if (isset($parameters['Limit'])) {
         $subTreeParameters['Limit'] = (int) $parameters['Limit'];
     }
     $result = eZContentObjectTreeNode::subTreeByNodeID($subTreeParameters, $nodeID);
     if ($result === null) {
         return array();
     }
     $fetchResult = array();
     foreach ($result as $item) {
         $fetchResult[] = array('object_id' => $item['id'], 'node_id' => $item['node_id'], 'ts_publication' => $item['published']);
     }
     return $fetchResult;
 }
 function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     $parentNodeID = $namedParameters['parent_node_id'];
     switch ($operatorName) {
         case 'ezkeywordlist':
             include_once 'lib/ezdb/classes/ezdb.php';
             $db = eZDB::instance();
             if ($parentNodeID) {
                 $node = eZContentObjectTreeNode::fetch($parentNodeID);
                 if ($node) {
                     $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute('path_string') . "%'";
                 }
                 $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int) $parentNodeID;
             }
             $showInvisibleNodesCond = eZContentObjectTreeNode::createShowInvisibleSQLString(true, false);
             $limitation = false;
             $limitationList = eZContentObjectTreeNode::getLimitationList($limitation);
             $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL($limitationList);
             $versionNameJoins = " AND ezcontentobject_tree.contentobject_id = ezcontentobject_name.contentobject_id AND\n                                            ezcontentobject_tree.contentobject_version = ezcontentobject_name.content_version AND ";
             $languageFilter = " AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject');
             $versionNameJoins .= eZContentLanguage::sqlFilter('ezcontentobject_name', 'ezcontentobject');
             $quotedClassIdentifiers = array();
             foreach ((array) $namedParameters['class_identifier'] as $classIdentifier) {
                 $quotedClassIdentifiers[] = "'" . $db->escapeString($classIdentifier) . "'";
             }
             $rs = $db->arrayQuery("SELECT DISTINCT ezkeyword.keyword\n                                            FROM ezkeyword_attribute_link,\n                                                 ezkeyword,\n                                                 ezcontentobject,\n                                                 ezcontentobject_name,\n                                                 ezcontentobject_attribute,\n                                                 ezcontentobject_tree,\n                                                 ezcontentclass\n                                                 {$sqlPermissionChecking['from']}\n                                            WHERE ezkeyword.id = ezkeyword_attribute_link.keyword_id\n                                                AND ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id\n                                                AND ezcontentobject_tree.contentobject_id = ezcontentobject_attribute.contentobject_id\n                                                AND ezkeyword.class_id = ezcontentclass.id\n                                                AND " . $db->generateSQLINStatement($quotedClassIdentifiers, 'ezcontentclass.identifier') . "\n                                                {$pathString}\n                                                {$parentNodeIDSQL} " . ($namedParameters['depth'] > 0 ? "AND ezcontentobject_tree.depth=" . (int) $namedParameters['depth'] : '') . "\n                                                {$showInvisibleNodesCond}\n                                                {$sqlPermissionChecking['where']}\n                                                {$languageFilter}\n                                                {$versionNameJoins}\n                                            ORDER BY ezkeyword.keyword ASC");
             $operatorValue = $rs;
             break;
     }
 }
 public function execute($process, $event)
 {
     $params = $process->attribute('parameter_list');
     $object_id = $params['object_id'];
     $object = eZContentObject::fetch($object_id);
     if (!is_object($object)) {
         eZDebug::writeError("Unable to fetch object: '{$object_id}'", __METHOD__);
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
     // current parent node(s)
     $parentNodeIds = $object->attribute('parent_nodes');
     $checkedObjs = array();
     foreach ($parentNodeIds as $parentNodeId) {
         //eZDebug::writeDebug( "Checking parent node: " . $parentNodeId, __METHOD__ );
         $parentNode = eZContentObjectTreeNode::fetch($parentNodeId);
         $parentObj = $parentNode->attribute('object');
         if (!in_array($parentObj->attribute('id'), $checkedObjs)) {
             //eZDebug::writeDebug( "Checking all nodes of parent obj: " . $parentObj->attribute( 'id' ), __METHOD__ );
             foreach ($parentObj->attribute('assigned_nodes') as $node) {
                 if (!in_array($node->attribute('node_id'), $parentNodeIds)) {
                     //eZDebug::writeDebug( "Found a node which is not parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ );
                     // the current obj has no node which is children of the given node of one of its parent objects
                     $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $object->attribute('main_node_id'), 'object_id' => $object->attribute('id'), 'select_node_id_array' => array($node->attribute('node_id'))), null, true);
                     if ($operationResult == null || $operationResult['status'] != true) {
                         eZDebug::writeError("Unable to add new location to object: " . $object->attribute('id'), __METHOD__);
                     }
                 } else {
                     //eZDebug::writeDebug( "Found a node which is already parent of current obj: " . $node->attribute( 'node_id' ), __METHOD__ );
                 }
             }
         }
         $checkedObjs[] = $parentObj->attribute('id');
     }
     return eZWorkflowType::STATUS_ACCEPTED;
 }
    public static function getMetaTitle( $pathArray )
    {
        $metaINI = eZINI::instance( 'ezmetadata.ini' );
        $allowedClasses = $metaINI->variable( 'TitleSettings', 'ParentClasses' );
        $maxDepth = $metaINI->variable( 'TitleSettings', 'MaxDepth' );
        $separator = ' '.$metaINI->variable( 'TitleSettings', 'PathSeparator' ).' ';

        $contentINI = eZINI::instance( 'content.ini' );
        $rootNodeID = $contentINI->variable( 'NodeSettings', 'RootNode' );

        $titleArray = array();
        $depth = -1;
        $currentItem = array_pop( $pathArray );

        foreach ( $pathArray as $item )
        {
            if ( $item['node_id'] == $rootNodeID ) $depth = 0;
            if ( $depth < 0 ) continue;

            $itemNode = eZContentObjectTreeNode::fetch( $item['node_id'] );
            $itemClass = $itemNode->attribute( 'class_identifier' );

            if ( in_array( $itemClass,  $allowedClasses ) )
            {
                $titleArray[] = self::getMetaTitleItem( $itemNode );
                $depth++;
                if ( $depth >= $maxDepth ) break;
            }
        }
        $itemNode = eZContentObjectTreeNode::fetch( $currentItem['node_id'] );
        if ( $itemNode ) $titleArray[] = self::getMetaTitleItem( $itemNode );

        $titleArray = array_reverse( $titleArray ); 
        return implode( $separator, $titleArray );
    }
 /**
  * Create a copy of an object.
  *
  * The basis for this method is taken from kernel/content/copy.php
  *
  * @todo Merge this method into kernel wrapper's object class.
  *
  * @param eZContentObject $object
  * @param int $newParentNodeID
  * @return eZContentObject
  */
 public static function copyObject($object, $newParentNodeID)
 {
     $newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID);
     $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);
     $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 $newObject;
 }
 /**
  * @group issue18073
  * @link http://issues.ez.no/18073
  */
 public function testUnauthorizedContentByNode()
 {
     $this->setExpectedException('ezpContentAccessDeniedException');
     // Let's take content node #5 / object #4 (users) as unauthorized content for anonymous user
     $unauthorizedNodeID = 5;
     $content = ezpContent::fromNode(eZContentObjectTreeNode::fetch($unauthorizedNodeID));
 }
    /**
     * Tests that the output process works with objects.
     *
     * There should be no crash from casting errors.
     * @group templateOperators
     * @group attributeOperator
     */
    public function testDisplayVariableWithObject()
    {
        $db = eZDB::instance();

        // STEP 1: Add test folder
        $folder = new ezpObject( "folder", 2 );
        $folder->name = __METHOD__;
        $folder->publish();

        $nodeId = $folder->mainNode->node_id;

        $node = eZContentObjectTreeNode::fetch( $nodeId );
        $attrOp = new eZTemplateAttributeOperator();
        $outputTxt = '';
        $formatterMock = $this->getMock( 'ezpAttributeOperatorFormatterInterface' );
        $formatterMock->expects( $this->any() )
                      ->method( 'line' )
                      ->will( $this->returnValue( __METHOD__ ) );

        try
        {
            $attrOp->displayVariable( $node, $formatterMock, true, 2, 0, $outputTxt );
        }
        catch ( PHPUnit_Framework_Error $e )
        {
            self::fail( "eZTemplateAttributeOperator raises an error when working with objects." );
        }

        self::assertNotNull( $outputTxt, "Output text is empty." );
        // this is an approxmiate test. The output shoudl contain the name of the object it has been generated correctly.
        self::assertContains( __METHOD__, $outputTxt, "There is something wrong with the output of the attribute operator. Object name not found." );
    }
 /**
  * Returns block item XHTML
  *
  * @param mixed $args
  * @return array
  */
 public static function getNextItems($args)
 {
     $http = eZHTTPTool::instance();
     $tpl = eZTemplate::factory();
     $result = array();
     $galleryID = $http->postVariable('gallery_id');
     $offset = $http->postVariable('offset');
     $limit = $http->postVariable('limit');
     $galleryNode = eZContentObjectTreeNode::fetch($galleryID);
     if ($galleryNode instanceof eZContentObjectTreeNode) {
         $params = array('Depth' => 1, 'Offset' => $offset, 'Limit' => $limit);
         $pictureNodes = $galleryNode->subtree($params);
         foreach ($pictureNodes as $validNode) {
             $tpl->setVariable('node', $validNode);
             $tpl->setVariable('view', 'block_item');
             $tpl->setVariable('image_class', 'blockgallery1');
             $content = $tpl->fetch('design:node/view/view.tpl');
             $result[] = $content;
             if ($counter === $limit) {
                 break;
             }
         }
     }
     return $result;
 }
 public function fetch($parameters, $publishedAfter, $publishedBeforeOrAt)
 {
     if (isset($parameters['Source'])) {
         $nodeID = $parameters['Source'];
         $node = eZContentObjectTreeNode::fetch($nodeID, false, false);
         // not as an object
         if ($node && $node['modified_subnode'] <= $publishedAfter) {
             return array();
         }
     } else {
         $nodeID = 0;
     }
     $subTreeParameters = array();
     $subTreeParameters['AsObject'] = false;
     $subTreeParameters['SortBy'] = array('published', true);
     // first the oldest
     $subTreeParameters['AttributeFilter'] = array('and', array('published', '>', $publishedAfter), array('published', '<=', $publishedBeforeOrAt));
     if (isset($parameters['Classes'])) {
         $subTreeParameters['ClassFilterType'] = 'include';
         $subTreeParameters['ClassFilterArray'] = explode(',', $parameters['Classes']);
     }
     // Do not fetch hidden nodes even when ShowHiddenNodes=true
     $subTreeParameters['AttributeFilter'] = array('and', array('visibility', '=', true));
     $nodes = eZContentObjectTreeNode::subTreeByNodeID($subTreeParameters, $nodeID);
     if ($nodes === null) {
         return array();
     }
     $fetchResult = array();
     foreach ($nodes as $node) {
         $fetchResult[] = array('object_id' => $node['contentobject_id'], 'node_id' => $node['node_id'], 'ts_publication' => $node['published']);
     }
     return $fetchResult;
 }
Пример #10
0
 /**
  * Return valid items for block with given $blockID
  * 
  * @static
  * @param string $blockID
  * @param bool $asObject
  * @return array(eZContentObjectTreeNode)
  */
 static function validNodes($blockID, $asObject = true)
 {
     if (isset($GLOBALS['eZFlowPool']) === false) {
         $GLOBALS['eZFlowPool'] = array();
     }
     if (isset($GLOBALS['eZFlowPool'][$blockID])) {
         return $GLOBALS['eZFlowPool'][$blockID];
     }
     $visibilitySQL = "";
     if (eZINI::instance('site.ini')->variable('SiteAccessSettings', 'ShowHiddenNodes') !== 'true') {
         $visibilitySQL = "AND ezcontentobject_tree.is_invisible = 0 ";
     }
     $db = eZDB::instance();
     $validNodes = $db->arrayQuery("SELECT ezm_pool.node_id\n                                        FROM ezm_pool, ezcontentobject_tree, ezcontentobject\n                                        WHERE ezm_pool.block_id='{$blockID}'\n                                          AND ezm_pool.ts_visible>0\n                                          AND ezm_pool.ts_hidden=0\n                                          AND ezcontentobject_tree.node_id = ezm_pool.node_id\n                                          AND ezcontentobject.id = ezm_pool.object_id\n                                          AND " . eZContentLanguage::languagesSQLFilter('ezcontentobject') . "\n                                          {$visibilitySQL}\n                                        ORDER BY ezm_pool.priority DESC");
     if ($asObject && !empty($validNodes)) {
         $validNodesObjects = array();
         foreach ($validNodes as $node) {
             $validNodeObject = eZContentObjectTreeNode::fetch($node['node_id']);
             if ($validNodeObject instanceof eZContentObjectTreeNode && $validNodeObject->canRead()) {
                 $validNodesObjects[] = $validNodeObject;
             }
         }
         $GLOBALS['eZFlowPool'][$blockID] = $validNodesObjects;
         return $validNodesObjects;
     } else {
         return $validNodes;
     }
 }
    /**
     * Kicks of the process of purging orphan nodes
     *
     * We delete orphans in a two step process:
     * - 1. Iterate over a subtree and check if the node is an orphan and
     * store it's node id if it is
     * - 2. Loop over all node ids of orhpant nodes found in step 1 and delete
     * them.
     *
     * This is needed as we cannot directly fetch a list of orphan nodes. This
     * also prevents issues with using offset when fetching a list of nodes we
     * intend to delete.
     **/
    public function process()
    {
        $iterator = $this->getSubtreeIterator();
        $this->output->outputText(
            'Looking for orphans under ' . $this->subTreeNode->urlAlias(). "\n", 'info'
        );
        $this->output->outputText(
            'Will search ' . $iterator->count() . " objects for orphans ", 'info'
        );

        $orphanIds = array();
        foreach( $iterator as $node )
        {
            if ( !$this->isNodeOrphan( $node ) )
                continue;

            $orphanIds[] = $node->NodeID;
            $this->output->outputText( "." );
        }

        $orphanCount = count($orphanIds);
        $this->output->outputText( "\nFound {$orphanCount} orphan objects\n", 'info' );
        $count = 0;
        foreach( $orphanIds as $nodeId )
        {
            if ($count % 200 == 0)
            {
                $this->output->outputText(
                    "Treated : {$count} / {$orphanCount}\n" , 'success'
                );
            }

            $node = eZContentObjectTreeNode::fetch( $nodeId );
            if ( !$node )
            {
                $this->output->outputText(
                    "Could not fetch node with id {$nodeId}'\n", 'error'
                );
                continue;
            }
            if ( $this->isDryRun )
            {
                $this->output->outputText(
                    "Found orphan, but not deleting {$nodeId} '" . $node->urlAlias() . "'\n"
                );
            }
            else
            {
                $this->output->outputText(
                    "Deleting orphan {$nodeId} '" . $node->urlAlias() . "'\n"
                );
                $this->deleteNode( $node );
            }

            $count++;
            if ( $count % 1000 == 0 )
                eZContentObject::clearCache();
        }
    }
Пример #12
0
 /**
  * Creates a user with provided auth data
  *
  * @param array $authResult
  *
  * @return bool|eZUser
  */
 public static function createUser($authResult)
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $siteINI = eZINI::instance('site.ini');
     $defaultUserPlacement = $ngConnectINI->variable('LoginMethod_' . $authResult['login_method'], 'DefaultUserPlacement');
     $placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement);
     if (!$placementNode instanceof eZContentObjectTreeNode) {
         $defaultUserPlacement = $siteINI->variable('UserSettings', 'DefaultUserPlacement');
         $placementNode = eZContentObjectTreeNode::fetch($defaultUserPlacement);
         if (!$placementNode instanceof eZContentObjectTreeNode) {
             return false;
         }
     }
     $contentClass = eZContentClass::fetch($siteINI->variable('UserSettings', 'UserClassID'));
     $userCreatorID = $siteINI->variable('UserSettings', 'UserCreatorID');
     $defaultSectionID = $siteINI->variable('UserSettings', 'DefaultSectionID');
     $db = eZDB::instance();
     $db->begin();
     $contentObject = $contentClass->instantiate($userCreatorID, $defaultSectionID);
     $contentObject->store();
     $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => 1, 'parent_node' => $placementNode->attribute('node_id'), 'is_main' => 1));
     $nodeAssignment->store();
     $currentTimeStamp = eZDateTime::currentTimeStamp();
     /** @var eZContentObjectVersion $version */
     $version = $contentObject->currentVersion();
     $version->setAttribute('modified', $currentTimeStamp);
     $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
     $version->store();
     $dataMap = $version->dataMap();
     self::fillUserObject($version->dataMap(), $authResult);
     if (!isset($dataMap['user_account'])) {
         $db->rollback();
         return false;
     }
     $userLogin = '******' . $authResult['login_method'] . '_' . $authResult['id'];
     $userPassword = (string) rand() . 'ngconnect_' . $authResult['login_method'] . '_' . $authResult['id'] . (string) rand();
     $userExists = false;
     if (eZUser::requireUniqueEmail()) {
         $userExists = eZUser::fetchByEmail($authResult['email']) instanceof eZUser;
     }
     if (empty($authResult['email']) || $userExists) {
         $email = md5('ngconnect_' . $authResult['login_method'] . '_' . $authResult['id']) . '@localhost.local';
     } else {
         $email = $authResult['email'];
     }
     $user = new eZUser(array('contentobject_id' => $contentObject->attribute('id'), 'email' => $email, 'login' => $userLogin, 'password_hash' => md5("{$userLogin}\n{$userPassword}"), 'password_hash_type' => 1));
     $user->store();
     $userSetting = new eZUserSetting(array('is_enabled' => true, 'max_login' => 0, 'user_id' => $contentObject->attribute('id')));
     $userSetting->store();
     $dataMap['user_account']->setContent($user);
     $dataMap['user_account']->store();
     $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObject->attribute('id'), 'version' => $version->attribute('version')));
     if (array_key_exists('status', $operationResult) && $operationResult['status'] == eZModuleOperationInfo::STATUS_CONTINUE) {
         $db->commit();
         return $user;
     }
     $db->rollback();
     return false;
 }
 protected static function getNode($parentNodeId)
 {
     $parentNode = $parentNodeId;
     if (!$parentNode instanceof eZContentObjectTreeNode) {
         $parentNode = eZContentObjectTreeNode::fetch($parentNodeId);
     }
     return $parentNode instanceof eZContentObjectTreeNode ? $parentNode : null;
 }
Пример #14
0
 protected function mainNode()
 {
     if ( is_null($this->_mainNode) )
     {
         $this->_mainNode = eZContentObjectTreeNode::fetch( $this->mainNodeId );
     }
     return $this->_mainNode;
 }
 static function move($nodeID, $newParentNodeID)
 {
     $result = false;
     if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) {
         return false;
     }
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return false;
     }
     $object = $node->object();
     if (!$object) {
         return false;
     }
     $objectID = $object->attribute('id');
     $oldParentNode = $node->fetchParent();
     $oldParentObject = $oldParentNode->object();
     // clear user policy cache if this is a user object
     if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) {
         eZUser::purgeUserCacheByUserId($object->attribute('id'));
     }
     // clear cache for old placement.
     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     $db = eZDB::instance();
     $db->begin();
     $node->move($newParentNodeID);
     $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID);
     if ($newNode) {
         $newNode->updateSubTreePath(true, true);
         if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) {
             // If the main node is moved we need to check if the section ID must change
             $newParentNode = $newNode->fetchParent();
             $newParentObject = $newParentNode->object();
             if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) {
                 eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id'));
             }
         }
         // modify assignment
         $curVersion = $object->attribute('current_version');
         $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id'));
         if ($nodeAssignment) {
             $nodeAssignment->setAttribute('parent_node', $newParentNodeID);
             $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE);
             $nodeAssignment->store();
             // update search index
             $nodeIDList = array($nodeID);
             eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList);
             eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList);
         }
         $result = true;
     } else {
         eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed");
     }
     $db->commit();
     // clear cache for new placement.
     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     return $result;
 }
Пример #16
0
function copyObject( $Module, $object, $allVersions, $newParentNodeID )
{
    if ( !$newParentNodeID )
        return $Module->redirectToView( 'view', array( 'full', 2 ) );

    // check if we can create node under the specified parent node
    if( ( $newParentNode = eZContentObjectTreeNode::fetch( $newParentNodeID ) ) === null )
        return $Module->redirectToView( 'view', array( 'full', 2 ) );

    $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' );
        return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' );
    }

    $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 )
    {
        $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 $Module->redirectToView( 'view', array( 'full', $newParentNodeID ) );
}
Пример #17
0
    /**
     * @param eZContentObjectTreeNode $node
     * @return eZContentObjectTreeNode
     */
    public static function getPublisherNodeFromNode( $node )
    {
        if ( !$node instanceof eZContentObjectTreeNode )
            return null;

        $publisherFolderNodeId = PublisherFolderTool::getPublisherNodeIdFromArticleNode($node);

        return eZContentObjectTreeNode::fetch( $publisherFolderNodeId );
    }
Пример #18
0
    function execute( $xmlNode )
    {
        $action = $xmlNode->getAttribute( 'action' );
        $xmlNodeID = $xmlNode->getAttribute( 'nodeID' );

        $nodeID = $this->getReferenceID( $xmlNodeID );
        if ( !$nodeID )
        {
            $this->writeMessage( "\tInvalid node $nodeID does not exist.", 'warning' );
            return false;
        }

        if ( !$action )
        {
            $action = 'toogle';
        }
        $node = eZContentObjectTreeNode::fetch( $nodeID );
        if ( !$node )
        {
            $this->writeMessage( "\tNo node defined.", 'error' );
            return false;
        }

        switch ( $action )
        {
            case 'unhide':
            {
                if ( $node->attribute( 'is_hidden' ) )
                {
                    eZContentObjectTreeNode::unhideSubTree( $node );
                    $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be unhidden.", 'error' );
                }
            } break;
            case 'hide':
            {
                if ( !$node->attribute( 'is_hidden' ) )
                {
                    eZContentObjectTreeNode::hideSubTree( $node );
                    $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be hidden.", 'error' );
                }
            } break;
            case 'toogle':
            {
                if ( $node->attribute( 'is_hidden' ) )
                {
                    eZContentObjectTreeNode::unhideSubTree( $node );
                    $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be unhidden.", 'error' );
                }
                else
                {
                    eZContentObjectTreeNode::hideSubTree( $node );
                    $this->writeMessage( "\tNode " . $node->attribute( 'name' ) . " has be hidden.", 'error' );
                }
            } break;
        }
    }
Пример #19
0
 /**
  * Returns the ezpContentLocation object for a particular node by ID
  * @param int $nodeId
  * @return ezpContentLocation
  * @throws ezcBaseException When the node is not found
  */
 public static function fetchByNodeId($nodeId)
 {
     $node = eZContentObjectTreeNode::fetch($nodeId);
     if ($node instanceof eZContentObjectTreeNode) {
         return self::fromNode($node);
     } else {
         // @TODO Currently this exception is only in rest package. Needs to be fixed.
         throw new ezpContentNotFoundException("Unable to find node with ID {$nodeId}");
     }
 }
Пример #20
0
 static function validateContentNodeId($id)
 {
     if (is_numeric($id) && 0 < (int) $id) {
         $id = (int) $id;
         if (eZContentObjectTreeNode::fetch($id, false, false, false)) {
             return true;
         }
     }
     return false;
 }
 function execute($process, $event)
 {
     $user = eZUser::currentUser();
     if ($user->isLoggedIn()) {
         return eZWorkflowType::STATUS_ACCEPTED;
     }
     $http = eZHTTPTool::instance();
     // Get current content object ID.
     $parameters = $process->attribute('parameter_list');
     $nodeID = $parameters['node_id'];
     $node = eZContentObjectTreeNode::fetch($nodeID);
     if (!$node) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $objectID = $node->attribute('contentobject_id');
     // Get newsletter hash
     $uri = $GLOBALS['eZRequestedURI'];
     $userParameters = $uri->userParameters();
     $hash = isset($userParameters['hash']) ? $userParameters['hash'] : false;
     $sendItem = eZSendNewsletterItem::fetchByHash($hash);
     if ($http->hasSessionVariable('NewsletterNodeIDArray')) {
         $globalNodeIDList = $http->sessionVariable('NewsletterNodeIDArray');
         if (in_array($nodeID, $http->sessionVariable('NewsletterNodeIDArray'))) {
             $sendID = $http->sessionVariable('NewletterNodeMap_' . $nodeID);
             $sendItem = eZSendNewsletterItem::fetch($sendID);
             $sendItem->addObjectRead($objectID);
             return eZWorkflowType::STATUS_ACCEPTED;
         }
     }
     // Get send item, and check that is contains the object id.
     if (!$sendItem) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendItemIDList = $sendItem->attribute('newsletter_related_object_list');
     if (!$sendItemIDList || !in_array($objectID, $sendItemIDList)) {
         return eZWorkflowType::STATUS_REJECTED;
     }
     $sendNodeIDArray = array();
     // Set session variables
     foreach ($sendItemIDList as $sendObjectID) {
         $sendObject = eZContentObject::fetch($sendObjectID);
         if ($sendObject) {
             foreach ($sendObject->assignedNodes(false) as $nodeArray) {
                 $http->setSessionVariable('NewletterNodeMap_' . $nodeArray['node_id'], $sendItem->attribute('id'));
                 $sendNodeIDArray[] = $nodeArray['node_id'];
             }
         }
     }
     $globalNodeIDList = array_unique(array_merge($globalNodeIDList, $sendNodeIDArray));
     $http->setSessionVariable('NewsletterNodeIDArray', $globalNodeIDList);
     // Add object read
     $sendItem->addObjectRead($objectID);
     return eZWorkflowType::STATUS_ACCEPTED;
 }
 public function __construct($parentNodeID, $classIdentifier)
 {
     parent::__construct($parentNodeID, $classIdentifier);
     $this->parentNodeID = $parentNodeID;
     //dati del parent (pagina trasparenza
     $parentNode = eZContentObjectTreeNode::fetch($this->parentNodeID);
     $parenObject = $parentNode->attribute('object');
     $parent_data_map = $parenObject->dataMap();
     if ($parent_data_map['anno_riferimento']) {
         $this->anno_pubblicazione = $parent_data_map['anno_riferimento']->content();
     }
     $this->createCSVHeader();
     $this->createErrorDescriptor();
 }
Пример #23
0
 public function fetchTopList($classes, $parent_node_id, $limit, $offset)
 {
     $result = array();
     $parentNode = eZContentObjectTreeNode::fetch($parent_node_id);
     $path_string = $parentNode->attribute('path_string');
     $db = eZDB::instance();
     $sql = "SELECT evc.node_id FROM ezview_counter evc\n        LEFT JOIN ezcontentobject_tree ecot ON evc.node_id = ecot.node_id\n        LEFT JOIN ezcontentobject eco ON ecot.contentobject_id = eco.id\n        LEFT JOIN ezcontentclass ecc ON eco.contentclass_id = ecc.id\n        WHERE ecc.identifier IN ('" . implode("', '", $classes) . "')\n        AND ecot.path_string LIKE '" . $path_string . "%'\n        AND ecot.is_hidden = 0 AND ecot.is_invisible = 0\n        ORDER BY evc.count DESC LIMIT " . $offset . ", " . $limit;
     $queryRes = $db->arrayQuery($sql);
     foreach ($queryRes as $res) {
         $node = eZContentObjectTreeNode::fetch($res['node_id']);
         $result[] = $node;
     }
     return array('result' => $result);
 }
Пример #24
0
 static function cleanupByNodeIDs(&$nodeIDList)
 {
     if (!is_array($nodeIDList) || count($nodeIDList) === 0) {
         eZSubtreeCache::cleanupAll();
     } else {
         $nodeList = eZContentObjectTreeNode::fetch($nodeIDList);
         if ($nodeList) {
             if (!is_array($nodeList)) {
                 $nodeList = array($nodeList);
             }
             eZSubtreeCache::cleanup($nodeList);
         }
     }
 }
    /**
     * @param eZContentObjectTreeNode $node
     * @param string|ApplicationLocalized $application
     * @param boolean $isSolrData
     * @return PublisherFolder
     */
    public static function getPublisherFolder ( $node, $application, $isSolrData = false )
    {
        if( is_string( $application ) )
            $application = CacheApplicationTool::buildLocalizedApplicationByIdentifier($application);

        if ( !($application instanceof ApplicationLocalized) )
            return null;

        $publisherPath = "";

        switch ( true )
        {
            case $isSolrData :
                if ( !is_array($node) || !isset( $node['publisher_path']) )
                    return null;

                $publisherPath = $node['publisher_path'];
                break;
            case ( is_numeric( $node ) && $node > 0 ) :
                $node = eZContentObjectTreeNode::fetch($node);

                if ( !($node instanceof eZContentObjectTreeNode) )
                    return null;

            // No break as we want to use the next step as well
            case ( $node instanceof eZContentObjectTreeNode ) :
            {
                /* @var $node eZContentObjectTreeNode */
                if ( $node->ClassIdentifier != 'publisher_folder' )
                    $publisherPath = PublisherFolderTool::getPublisherFolderPathFromArticleNode($node);
                else
                {
                    $publisherInfo = PublisherFolderTool::getPublisherFolderInfosFromNodeId(
                        $node->attribute('node_id')
                    );
                    $publisherPath = $publisherInfo['path'];
                }
            }
                break;
            case is_string( $node ) :
                $publisherPath = $node;
                break;
        }

        return PublisherFolder::getPublisherFromPath($publisherPath);
//        return $application->getPublisherFolderFromPath($publisherPath);
    }
 function modify($tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters)
 {
     switch ($operatorName) {
         case 'metadata':
             if (isset($namedParameters['node_id'])) {
                 $node = eZContentObjectTreeNode::fetch($namedParameters['node_id']);
                 if ($node instanceof eZContentObjectTreeNode) {
                     $operatorValue = xrowMetaDataFunctions::fetchByObject($node->attribute('object'));
                 } else {
                     $operatorValue = false;
                 }
             } else {
                 $operatorValue = false;
             }
             break;
     }
 }
    /**
    * 
    * Récupère la liste des mots clés associés à un ou des noeuds
    * @param $nodeIDs : un identifiant de noeud ou une liste d'identifiants de noeuds dans lesquels chercher les mots clés
    * @param $attributes : si non vide, la liste des identifiants des attributs sur lesquels filtrer la recherche
    * @return un tableau contenant la liste des mots clés associés aux noeuds.
    *
    */
	public function getKeywords( $nodeIDs, $filterAttributes = '' )
	{
        
        $result = array();
        if (! is_array( $nodeIDs ) )
        {
            $nodeIDs = array( $nodeIDs );
        }
        if ( ! empty($filterAttributes) && ! is_array( $filterAttributes ) )
        {
            $filterAttributes = array( $filterAttributes );
        }
        
        foreach ( $nodeIDs as $nodeID )
        {
            $node = eZContentObjectTreeNode::fetch( $nodeID );
            if (! empty( $node ) )
            {
                $dataMap = $node->dataMap();
                foreach ( $dataMap as $attribute )
                {
                    $contentClassAttribute = $attribute->contentClassAttribute();
                    switch ( $contentClassAttribute->DataTypeString )
                    {
                    case 'ezkeyword' :
                        if ( empty( $filterAttributes ) || in_array( $contentClassAttribute->Identifier, $filterAttributes ) )
                        {
                            $keywords = $attribute->attribute( 'content' );
                            foreach ( $keywords->KeywordArray as $keyword )
                            {
                                if (! in_array( $keyword, $result ) )
                                {
                                    $result[] = $keyword;
                                }
                            }
                        }
                        break;
                    }
                }
            }
        }
        
        
        return array( 'result' => $result );
        
	}
Пример #28
0
    function modify( $tpl, $operatorName, $operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        $parentNodeID = $namedParameters['parent_node_id'];

        switch ( $operatorName )
        {
            case 'ezkeywordlist':
            {
                include_once( 'lib/ezdb/classes/ezdb.php' );
                $db = eZDB::instance();
                
                if( $parentNodeID )
                {
                    $node = eZContentObjectTreeNode::fetch( $parentNodeID );
                    if ( $node )
                        $pathString = "AND ezcontentobject_tree.path_string like '" . $node->attribute( 'path_string' ) . "%'";
                    $parentNodeIDSQL = "AND ezcontentobject_tree.node_id != " . (int)$parentNodeID;
                }

                $limitation = false;
                $sqlPermissionChecking = eZContentObjectTreeNode::createPermissionCheckingSQL( eZContentObjectTreeNode::getLimitationList( $limitation ) );

                // eZContentObjectTreeNode::classIDByIdentifier() might need to be used for eZ Publish < 4.1
                $classIDs = eZContentClass::classIDByIdentifier( $namedParameters['class_identifier'] );

                $operatorValue = $db->arrayQuery(
                    "SELECT DISTINCT ezkeyword.keyword
                     FROM ezkeyword
                          JOIN ezkeyword_attribute_link ON ezkeyword.id = ezkeyword_attribute_link.keyword_id
                          JOIN ezcontentobject_attribute ON ezkeyword_attribute_link.objectattribute_id = ezcontentobject_attribute.id
                          JOIN ezcontentobject ON ezcontentobject_attribute.contentobject_id = ezcontentobject.id
                          JOIN ezcontentobject_name ON ezcontentobject.id = ezcontentobject_name.contentobject_id
                          JOIN ezcontentobject_tree ON ezcontentobject_name.contentobject_id = ezcontentobject_tree.contentobject_id AND ezcontentobject_name.content_version = ezcontentobject_tree.contentobject_version
                          $sqlPermissionChecking[from]
                     WHERE " . eZContentLanguage::languagesSQLFilter( 'ezcontentobject' ) . "
                         AND " . eZContentLanguage::sqlFilter( 'ezcontentobject_name', 'ezcontentobject' ) .
                         ( empty( $classIDs ) ? '' : ( ' AND ' . $db->generateSQLINStatement( $classIDs, 'ezkeyword.class_id' ) ) ) . "
                         $pathString
                         $parentNodeIDSQL " .
                         ( $namedParameters['depth'] > 0 ? ("AND ezcontentobject_tree.depth=" . (int)$namedParameters['depth']) : '' ) . "
                         " . eZContentObjectTreeNode::createShowInvisibleSQLString( true, false ) . "
                         $sqlPermissionChecking[where]
                     ORDER BY ezkeyword.keyword ASC" );
            } break;
        }
    }
 /**
  * Executes the PHP function for the operator cleanup and modifies $operatorValue.
  *
  * @return bool Return true|fase based on success of operation.
  */
 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         // The node parameter can either be an eZContentObjectTreeNode, or a node ID
         case 'rssfeed':
             $operatorValue = '';
             if (is_numeric($namedParameters['node'])) {
                 // If the parameter was not provided, we use node 2
                 if ($namedParameters['node'] == 0) {
                     $node = eZContentObjectTreeNode::fetch(2);
                 } else {
                     $node = eZContentObjectTreeNode::fetch($namedParameters['node']);
                 }
             } else {
                 $node = $namedParameters['node'];
             }
             if (!is_a($node, 'ezcontentobjecttreenode')) {
                 return false;
             }
             $rssINI = eZINI::instance('bcrssfeeds.ini');
             $supportedClasses = $rssINI->variable('Settings', 'ContentClasses');
             $path = $node->fetchPath();
             $path[] = $node;
             // We scan the node's path up until we find a supported content class
             for ($depth = $node->attribute('depth') - 1; $depth >= 0; $depth--) {
                 $currentNode =& $path[$depth];
                 if (in_array($currentNode->classIdentifier(), $supportedClasses)) {
                     $dataMap = $currentNode->dataMap();
                     if (!isset($dataMap['rss_feed'])) {
                         eZDebug::writeError('Content node #' . $node->attribute('node_id') . ' is configured as a RSS content class (' . $currentNode->classIdentifier() . '), but has no \'rss_feed\' attribute', 'BCRssFeedOperator');
                         continue;
                     }
                     if ($dataMap['rss_feed']->hasContent()) {
                         $feedObject = $dataMap['rss_feed']->content();
                         $feedObjectDataMap = $feedObject->dataMap();
                         $title = htmlspecialchars($feedObjectDataMap['title']->content(), ENT_QUOTES);
                         $url = htmlspecialchars($feedObjectDataMap['url']->content(), ENT_QUOTES);
                         $operatorValue = '<link rel="Alternate" type="application/rss+xml" title="' . $title . '" href="' . $url . '" />';
                         return true;
                     }
                 }
             }
             break;
     }
 }
 /**
  * Trasforma le variabili $_GET in view_parameters e redirige la richiesta in base al parametro $_GET['RedirectUrlAlias']
  *
  * @see modules/ocsearch/action.php
  * @param array $requestFields
  * @param eZModule $module
  */
 public static function redirect(array $requestFields, eZModule $module = null)
 {
     $result = new OCClassSearchFormFetcher();
     $result->setRequestFields($requestFields);
     if ($module) {
         $redirect = '/';
         if (isset($requestFields['RedirectUrlAlias'])) {
             $redirect = $requestFields['RedirectUrlAlias'];
         } elseif (isset($requestFields['RedirectNodeID'])) {
             $node = eZContentObjectTreeNode::fetch($requestFields['RedirectNodeID']);
             if ($node instanceof eZContentObjectTreeNode) {
                 $redirect = $node->attribute('url_alias');
             }
         }
         $redirect = rtrim($redirect, '/') . $result->getViewParametersString();
         $module->redirectTo($redirect);
     }
 }