/**
  * Returns block item XHTML 
  * 
  * @param mixed $args
  * @return array
  */
 public static function getValidItems($args)
 {
     include_once 'kernel/common/template.php';
     $http = eZHTTPTool::instance();
     $tpl = templateInit();
     $result = array();
     $blockID = $http->postVariable('block_id');
     $offset = $http->postVariable('offset');
     $limit = $http->postVariable('limit');
     $validNodes = eZFlowPool::validNodes($blockID);
     $counter = 0;
     foreach ($validNodes as $validNode) {
         $counter++;
         if ($counter <= $offset) {
             continue;
         }
         $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;
 }
 /**
  * Returns block item XHTML
  *
  * @param mixed $args
  * @return array
  */
 public static function getValidItems($args)
 {
     $http = eZHTTPTool::instance();
     $tpl = eZTemplate::factory();
     $result = array();
     $blockID = $http->postVariable('block_id');
     $offset = $http->postVariable('offset');
     $limit = $http->postVariable('limit');
     $validNodes = eZFlowPool::validNodes($blockID);
     $counter = 0;
     foreach ($validNodes as $validNode) {
         if (!$validNode->attribute('can_read')) {
             continue;
         }
         $counter++;
         if ($counter <= $offset) {
             continue;
         }
         $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;
 }
示例#3
0
 function fetchValidNodes($blockID)
 {
     $result = array('result' => eZFlowPool::validNodes($blockID));
     return $result;
 }
示例#4
0
 /**
  * Update block pool for block with given $blockID
  *
  * @static
  * @param string $blockID
  * @param integer $publishedBeforeOrAt
  * @return integer
  */
 public static function updateBlockPoolByBlockID($block, $publishedBeforeOrAt = false)
 {
     $db = eZDB::instance();
     $blockINI = eZINI::instance('block.ini');
     if (!$publishedBeforeOrAt) {
         $publishedBeforeOrAt = time();
     }
     if (!$blockINI->hasVariable($block['block_type'], 'FetchClass')) {
         // Pure manual block, nothing is going to be fetched, but we need to update last_update as it is used for rotations
         if ($block['rotation_type'] != self::ROTATION_NONE) {
             $db->query("UPDATE ezm_block SET last_update={$publishedBeforeOrAt} WHERE id='" . $block['id'] . "'");
         }
         return 0;
     }
     $fetchClassOptions = new ezpExtensionOptions();
     $fetchClassOptions->iniFile = 'block.ini';
     $fetchClassOptions->iniSection = $block['block_type'];
     $fetchClassOptions->iniVariable = 'FetchClass';
     $fetchInstance = eZExtension::getHandlerClass($fetchClassOptions);
     if (!$fetchInstance instanceof eZFlowFetchInterface) {
         eZDebug::writeWarning("Can't create an instance of the {$fetchClass} class", "eZFlowOperations::updateBlockPoolByBlockID('" . $block['id'] . "')");
         return false;
     }
     $fetchFixedParameters = array();
     if ($blockINI->hasVariable($block['block_type'], 'FetchFixedParameters')) {
         $fetchFixedParameters = $blockINI->variable($block['block_type'], 'FetchFixedParameters');
     }
     $fetchParameters = unserialize($block['fetch_params']);
     if (!is_array($fetchParameters)) {
         // take care of blocks existing in db where ini definition changed
         eZDebug::writeWarning("Found existing block which has no necessary parameters serialized in the db (block needs updating)", "eZFlowOperations::updateBlockPoolByBlockID('" . $block['id'] . "')");
         $fetchParameters = array();
     }
     $parameters = array_merge($fetchFixedParameters, $fetchParameters);
     $newItems = array();
     foreach ($fetchInstance->fetch($parameters, $block['last_update'], $publishedBeforeOrAt) as $item) {
         $newItems[] = array('blockID' => $block['id'], 'objectID' => $item['object_id'], 'nodeID' => $item['node_id'], 'priority' => 0, 'timestamp' => $item['ts_publication']);
     }
     if (!empty($newItems)) {
         $db->begin();
         eZFlowPool::insertItems($newItems);
         $db->query("UPDATE ezm_block SET last_update={$publishedBeforeOrAt} WHERE id='" . $block['id'] . "'");
         $db->commit();
     }
     return count($newItems);
 }
    /**
     * Performs necessary actions with attribute data after object is published,
     * it means that you have access to published nodes.
     *
     * @param eZContentObjectAttribute $contentObjectAttribute
     * @param eZContentObject $contentObject
     * @param array(eZContentObjectTreeNode) $publishedNodes
     * @return bool
     */
    function onPublish( $contentObjectAttribute, $contentObject, $publishedNodes )
    {
        $db = eZDB::instance();
        $page = $contentObjectAttribute->content();

        foreach ( $publishedNodes as $publishedNode )
        {
            if ( $publishedNode->isMain() )
                $mainNode = $publishedNode;
        }

        foreach ( $publishedNodes as $node )
        {
            $nodeID = $node->attribute( 'node_id' );

            if ( $page->getZoneCount() != 0 )
            {
                foreach ( $page->attribute( 'zones' ) as $zone )
                {
                    if ( $zone->getBlockCount() != 0 )
                    {
                        if ( $zone->toBeRemoved() )
                        {
                            foreach ( $zone->attribute( 'blocks' ) as $index => $block )
                            {
                                $block->setAttribute( 'action', 'remove' );
                            }
                        }

                        $newItems = array();

                        foreach ( $zone->attribute( 'blocks' ) as $block )
                        {
                            $blockID = $block->attribute( 'id' );
                            $fetchParams = $block->attribute( 'fetch_params' );
                            $escapedBlockName = $db->escapeString( $block->attribute( 'name' ) );

                            switch ( $block->attribute( 'action' ) )
                            {
                                case 'remove':
                                    $db->query( "UPDATE ezm_block SET is_removed='1' WHERE id='" . $blockID . "'" );
                                    break;

                                case 'add':
                                    $blockCount = $db->arrayQuery( "SELECT COUNT( id ) as count FROM ezm_block WHERE id='" . $blockID ."'" );

                                    if ( $blockCount[0]['count'] == 0 )
                                    {
                                        $rotationType = 0;
                                        $rotationInterval = 0;
                                        $overflowID = null;

                                        if ( $block->hasAttribute( 'rotation' ) )
                                        {
                                            $rotation = $block->attribute( 'rotation' );

                                            $rotationType = $rotation['type'];
                                            $rotationInterval = $rotation['interval'];
                                        }


                                        if ( $block->hasAttribute( 'overflow_id' ) )
                                        $overflowID = $block->attribute( 'overflow_id' );

                                        $db->query( "INSERT INTO ezm_block ( id, zone_id, name, node_id, overflow_id, block_type, fetch_params, rotation_type, rotation_interval )
                                                                    VALUES ( '" . $blockID . "',
                                                                             '" . $block->attribute( 'zone_id' ) . "',
                                                                             '" . $escapedBlockName . "',
                                                                             '" . $nodeID . "',
                                                                             '" . $overflowID . "',
                                                                             '" . $db->escapeString( $block->attribute( 'type' ) ) . "',
                                                                             '" . $fetchParams . "',
                                                                             '" . $rotationType . "',
                                                                             '" . $rotationInterval . "' )" );
                                    }
                                    break;

                                default:
                                    $rotationType = 0;
                                    $rotationInterval = 0;
                                    $overflowID = null;

                                    if ( $block->hasAttribute( 'rotation' ) )
                                    {
                                        $rotation = $block->attribute( 'rotation' );

                                        $rotationType = $rotation['type'];
                                        $rotationInterval = $rotation['interval'];
                                    }

                                    if ( $block->hasAttribute( 'overflow_id' ) )
                                        $overflowID = $block->attribute( 'overflow_id' );

                                    // Fixes http://jira.ez.no/browse/EZP-23124 where ezm_block.node_id might be = 0
                                    // due to the way staging handles ezflow
                                    // If the block's node id is set to 0, it gets set to the main node ID
                                    $blockNodeId = $block->attribute( 'node_id' ) ?: $mainNode->attribute( 'node_id' );

                                    $db->query( "UPDATE ezm_block SET name='" . $escapedBlockName . "',
                                                                      overflow_id='" . $overflowID . "',
                                                                      fetch_params='" . $fetchParams . "',
                                                                      rotation_type='" . $rotationType . "',
                                                                      rotation_interval='" . $rotationInterval ."',
                                                                      node_id='" . $blockNodeId. "'
                                                            WHERE id='" . $blockID . "'" );
                                    break;
                            }

                            if ( $block->getItemCount() != 0 )
                            {
                                foreach ( $block->attribute( 'items' ) as $item )
                                {
                                    switch ( $item->attribute( 'action' ) )
                                    {
                                        case 'remove':

                                            $db->query( "DELETE FROM ezm_pool
                                                            WHERE object_id='" . $item->attribute( 'object_id' ) . "'
                                                            AND block_id='" . $blockID . "'" );
                                            break;

                                        case 'add':
                                            $newItems[] =  array(
                                                'blockID' => $blockID,
                                                'objectID' => $item->attribute( 'object_id' ),
                                                'nodeID' => $item->attribute( 'node_id' ),
                                                'priority' => $item->attribute( 'priority' ),
                                                'timestamp' => $item->attribute( 'ts_publication' ),
                                            );
                                            break;

                                        case 'modify':
                                            $updateQuery = array();

                                            if ( $item->hasAttribute( 'ts_publication' ) )
                                            {
                                                $updateQuery[] = " ts_publication="
                                                    . (int)$item->attribute( 'ts_publication' );
                                            }

                                            //make sure to update different node locations of the same object
                                            if ( $item->hasAttribute( 'node_id' ) )
                                            {
                                                $updateQuery[] = " node_id="
                                                    . (int)$item->attribute( 'node_id' );
                                            }

                                            if ( $item->hasAttribute( 'priority' ) )
                                            {
                                                $updateQuery[] = " priority="
                                                    . (int)$item->attribute( 'priority' );
                                            }

                                            //if there is ts_hidden and ts_visible, update the two fields. This is the case when add items from history
                                            if ( $item->hasAttribute( 'ts_hidden' ) && $item->hasAttribute( 'ts_visible' ) )
                                            {
                                                $updateQuery[] = " ts_hidden="
                                                    . (int)$item->attribute( 'ts_hidden' )
                                                    . ", ts_visible="
                                                    . (int)$item->attribute( 'ts_visible' );
                                            }

                                            if ( !empty( $updateQuery ) )
                                            {
                                                $db->query(
                                                    "UPDATE ezm_pool SET "
                                                    . join( ", ", $updateQuery )
                                                    . " WHERE object_id="
                                                    . (int)$item->attribute( 'object_id' )
                                                    . " AND block_id='" . $blockID ."'"
                                                );
                                            }
                                            break;
                                    }
                                }
                            }
                        }

                        if ( !empty( $newItems ) )
                        {
                            eZFlowPool::insertItems( $newItems );
                        }
                    }
                }
            }
        }

        if ( eZFlowOperations::updateOnPublish() )
        {
            $nodeArray = array();
            foreach ( $publishedNodes as $node )
            {
                $nodeArray[] = $node->attribute( 'node_id' );
            }
            eZFlowOperations::update( $nodeArray );
        }

        foreach ( $publishedNodes as $node )
        {
            $url = $node->attribute( 'path_identification_string' );
            eZURI::transformURI( $url, false, 'full' );
            eZHTTPCacheManager::execute( $url );
        }

        $page->removeProcessed();

        $contentObjectAttribute->content( $page );
        $contentObjectAttribute->store();

        return true;
    }
 /**
  * Fetches archived items and do merge with those already available
  *
  * @return array(eZPageBlockItem)
  */
 protected function getArchivedItems()
 {
     $archivedItems = eZFlowPool::archivedItems( $this->id() );
     return $this->merge( $archivedItems );
 }
示例#7
0
<?php

$Module = $Params['Module'];
$nodeID = $Params['NodeID'];
$node = eZContentObjectTreeNode::fetch($nodeID);
if ($node instanceof eZContentObjectTreeNode) {
    $object = $node->object();
} else {
    $object = false;
}
if ($Module->isCurrentAction('Store') && $Module->hasActionParameter('PlacementList')) {
    $newItems = array();
    foreach ($Module->actionParameter('PlacementList') as $zones) {
        foreach ($zones as $blocks) {
            foreach ($blocks as $blockID => $timestamp) {
                $newItems[] = array('blockID' => $blockID, 'objectID' => $object->attribute('id'), 'nodeID' => $node->attribute('node_id'), 'priority' => 0, 'timestamp' => $timestamp);
            }
        }
    }
    if (!empty($newItems)) {
        eZFlowPool::insertItems($newItems);
    }
    $Module->redirectTo($node->urlAlias());
}
$tpl = eZTemplate::factory();
$tpl->setVariable('node', $node);
$Result['path'] = array(array('url' => false, 'text' => ezpI18n::tr('ezflow/push', 'Push to block')));
$Result['content'] = $tpl->fetch('design:page/push.tpl');
示例#8
0
switch (strtolower($output)) {
    case 'json':
        $template = 'design:page/preview.tpl';
        $obj = new stdClass();
        foreach ($block->attributes() as $attr) {
            if (!in_array($attr, array('waiting', 'valid', 'valid_nodes', 'archived'))) {
                $obj->{$attr} = $block->attribute($attr);
            }
        }
        $obj->html = htmlentities($tpl->fetch($template), ENT_QUOTES);
        header('Content-type: application/json');
        echo json_encode(array('block' => $obj));
        break;
    case 'xml':
        $dom = new DOMDocument('1.0', 'utf-8');
        $dom->formatOutput = true;
        $items = eZFlowPool::validItems($blockID);
        foreach ($items as $item) {
            $block->addItem(new eZPageBlockItem($item, true));
        }
        $block->setAttribute('xhtml', $tpl->fetch($template));
        $blockElement = $block->toXML($dom);
        $dom->appendChild($blockElement);
        echo $dom->saveXML();
        break;
    case 'xhtml':
    default:
        echo $tpl->fetch($template);
        break;
}
eZExecution::cleanExit();
示例#9
0
 /**
  * Performs necessary actions with attribute data after object is published,
  * it means that you have access to published nodes.
  *
  * @param eZContentObjectAttribute $contentObjectAttribute
  * @param eZContentObject $contentObject
  * @param array(eZContentObjectTreeNode) $publishedNodes
  * @return bool
  */
 function onPublish($contentObjectAttribute, $contentObject, $publishedNodes)
 {
     $db = eZDB::instance();
     $page = $contentObjectAttribute->content();
     foreach ($publishedNodes as $node) {
         $nodeID = $node->attribute('node_id');
         if ($page->getZoneCount() != 0) {
             foreach ($page->attribute('zones') as $zone) {
                 if ($zone->getBlockCount() != 0) {
                     if ($zone->toBeRemoved()) {
                         foreach ($zone->attribute('blocks') as $index => $block) {
                             $block->setAttribute('action', 'remove');
                         }
                     }
                     $newItems = array();
                     foreach ($zone->attribute('blocks') as $block) {
                         $blockID = $block->attribute('id');
                         $fetchParams = $block->attribute('fetch_params');
                         $escapedBlockName = $db->escapeString($block->attribute('name'));
                         switch ($block->attribute('action')) {
                             case 'remove':
                                 $db->query("UPDATE ezm_block SET is_removed='1' WHERE id='" . $blockID . "'");
                                 break;
                             case 'add':
                                 $blockCount = $db->arrayQuery("SELECT COUNT( id ) as count FROM ezm_block WHERE id='" . $blockID . "'");
                                 if ($blockCount[0]['count'] == 0) {
                                     $rotationType = 0;
                                     $rotationInterval = 0;
                                     $overflowID = null;
                                     if ($block->hasAttribute('rotation')) {
                                         $rotation = $block->attribute('rotation');
                                         $rotationType = $rotation['type'];
                                         $rotationInterval = $rotation['interval'];
                                     }
                                     if ($block->hasAttribute('overflow_id')) {
                                         $overflowID = $block->attribute('overflow_id');
                                     }
                                     $db->query("INSERT INTO ezm_block ( id, zone_id, name, node_id, overflow_id, block_type, fetch_params, rotation_type, rotation_interval )\n                                                                    VALUES ( '" . $blockID . "',\n                                                                             '" . $block->attribute('zone_id') . "',\n                                                                             '" . $escapedBlockName . "',\n                                                                             '" . $nodeID . "',\n                                                                             '" . $overflowID . "',\n                                                                             '" . $db->escapeString($block->attribute('type')) . "',\n                                                                             '" . $fetchParams . "',\n                                                                             '" . $rotationType . "',\n                                                                             '" . $rotationInterval . "' )");
                                 }
                                 break;
                             default:
                                 $rotationType = 0;
                                 $rotationInterval = 0;
                                 $overflowID = null;
                                 if ($block->hasAttribute('rotation')) {
                                     $rotation = $block->attribute('rotation');
                                     $rotationType = $rotation['type'];
                                     $rotationInterval = $rotation['interval'];
                                 }
                                 if ($block->hasAttribute('overflow_id')) {
                                     $overflowID = $block->attribute('overflow_id');
                                 }
                                 $db->query("UPDATE ezm_block SET name='" . $escapedBlockName . "',\n                                                                      overflow_id='" . $overflowID . "',\n                                                                      fetch_params='" . $fetchParams . "',\n                                                                      rotation_type='" . $rotationType . "',\n                                                                      rotation_interval='" . $rotationInterval . "'\n                                                            WHERE id='" . $blockID . "'");
                                 break;
                         }
                         if ($block->getItemCount() != 0) {
                             foreach ($block->attribute('items') as $item) {
                                 switch ($item->attribute('action')) {
                                     case 'remove':
                                         $db->query("DELETE FROM ezm_pool\n                                                            WHERE object_id='" . $item->attribute('object_id') . "'\n                                                            AND block_id='" . $blockID . "'");
                                         break;
                                     case 'add':
                                         $newItems[] = array('blockID' => $blockID, 'objectID' => $item->attribute('object_id'), 'nodeID' => $item->attribute('node_id'), 'priority' => $item->attribute('priority'), 'timestamp' => $item->attribute('ts_publication'));
                                         break;
                                     case 'modify':
                                         if ($item->hasAttribute('ts_publication')) {
                                             $db->query("UPDATE ezm_pool SET ts_publication='" . $item->attribute('ts_publication') . "'\n                                                                WHERE object_id='" . $item->attribute('object_id') . "'\n                                                                    AND block_id='" . $blockID . "'");
                                         }
                                         if ($item->hasAttribute('priority')) {
                                             $db->query("UPDATE ezm_pool SET priority='" . $item->attribute('priority') . "'\n                                                                WHERE object_id='" . $item->attribute('object_id') . "'\n                                                                    AND block_id='" . $blockID . "'");
                                         }
                                         //if there is ts_hidden and ts_visible, update the two fields. This is the case when add items from history
                                         if ($item->hasAttribute('ts_hidden') && $item->hasAttribute('ts_visible')) {
                                             $db->query("UPDATE ezm_pool SET ts_hidden='" . $item->attribute('ts_hidden') . "',\n                                                             ts_visible='" . $item->attribute('ts_visible') . "'\n                                                                WHERE object_id='" . $item->attribute('object_id') . "'\n                                                                    AND block_id='" . $blockID . "'");
                                         }
                                         break;
                                 }
                             }
                         }
                     }
                     if (!empty($newItems)) {
                         eZFlowPool::insertItems($newItems);
                     }
                 }
             }
         }
     }
     if (eZFlowOperations::updateOnPublish()) {
         $nodeArray = array();
         foreach ($publishedNodes as $node) {
             $nodeArray[] = $node->attribute('node_id');
         }
         eZFlowOperations::update($nodeArray);
     }
     foreach ($publishedNodes as $node) {
         $url = $node->attribute('path_identification_string');
         eZURI::transformURI($url, false, 'full');
         eZHTTPCacheManager::execute($url);
     }
     $page->removeProcessed();
     $contentObjectAttribute->content($page);
     $contentObjectAttribute->store();
     return true;
 }