/**
  * Creates a RSS/ATOM Feed export for a node
  *
  * @param int $nodeID Node ID
  *
  * @since 4.3
  */
 public static function createFeedForNode($nodeID)
 {
     $hasExport = eZRSSFunctionCollection::hasExportByNode($nodeID);
     if (isset($hasExport['result']) && $hasExport['result']) {
         eZDebug::writeError('There is already a rss/atom export feed for this node: ' . $nodeID, __METHOD__);
         return array('status' => false);
     }
     $node = eZContentObjectTreeNode::fetch($nodeID);
     $currentClassIdentifier = $node->attribute('class_identifier');
     $config = eZINI::instance('site.ini');
     $feedItemClasses = $config->variable('RSSSettings', 'DefaultFeedItemClasses');
     if (!$feedItemClasses || !isset($feedItemClasses[$currentClassIdentifier])) {
         eZDebug::writeError("EnableRSS: content class {$currentClassIdentifier} is not defined in site.ini[RSSSettings]DefaultFeedItemClasses[<class_id>].", __METHOD__);
         return array('status' => false);
     }
     $object = $node->object();
     $objectID = $object->attribute('id');
     $currentUserID = eZUser::currentUserID();
     $rssExportItems = array();
     $db = eZDB::instance();
     $db->begin();
     $rssExport = eZRSSExport::create($currentUserID);
     $rssExport->setAttribute('access_url', 'rss_feed_' . $nodeID);
     $rssExport->setAttribute('node_id', $nodeID);
     $rssExport->setAttribute('main_node_only', '1');
     $rssExport->setAttribute('number_of_objects', $config->variable('RSSSettings', 'NumberOfObjectsDefault'));
     $rssExport->setAttribute('rss_version', $config->variable('RSSSettings', 'DefaultVersion'));
     $rssExport->setAttribute('status', eZRSSExport::STATUS_VALID);
     $rssExport->setAttribute('title', $object->name());
     $rssExport->store();
     $rssExportID = $rssExport->attribute('id');
     foreach (explode(';', $feedItemClasses[$currentClassIdentifier]) as $classIdentifier) {
         $iniSection = 'RSSSettings_' . $classIdentifier;
         if ($config->hasVariable($iniSection, 'FeedObjectAttributeMap')) {
             $feedObjectAttributeMap = $config->variable($iniSection, 'FeedObjectAttributeMap');
             $subNodesMap = $config->hasVariable($iniSection, 'Subnodes') ? $config->variable($iniSection, 'Subnodes') : array();
             $rssExportItem = eZRSSExportItem::create($rssExportID);
             $rssExportItem->setAttribute('class_id', eZContentObjectTreeNode::classIDByIdentifier($classIdentifier));
             $rssExportItem->setAttribute('title', $feedObjectAttributeMap['title']);
             if (isset($feedObjectAttributeMap['description'])) {
                 $rssExportItem->setAttribute('description', $feedObjectAttributeMap['description']);
             }
             if (isset($feedObjectAttributeMap['category'])) {
                 $rssExportItem->setAttribute('category', $feedObjectAttributeMap['category']);
             }
             if (isset($feedObjectAttributeMap['enclosure'])) {
                 $rssExportItem->setAttribute('enclosure', $feedObjectAttributeMap['enclosure']);
             }
             $rssExportItem->setAttribute('source_node_id', $nodeID);
             $rssExportItem->setAttribute('status', eZRSSExport::STATUS_VALID);
             $rssExportItem->setAttribute('subnodes', isset($subNodesMap[$currentClassIdentifier]) && $subNodesMap[$currentClassIdentifier] === 'true');
             $rssExportItem->store();
         } else {
             eZDebug::writeError("site.ini[{$iniSection}]Source[] setting is not defined.", __METHOD__);
         }
     }
     $db->commit();
     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
     return array('status' => true);
 }
Example #2
0
            if (isset($imageNodeIDArray) && !$http->hasPostVariable('BrowseCancelButton')) {
                $rssExport->setAttribute('image_id', $imageNodeIDArray[0]);
            }
            break;
    }
} else {
    $user = eZUser::currentUser();
    $user_id = $user->attribute("contentobject_id");
    $db = eZDB::instance();
    $db->begin();
    // Create default rssExport object to use
    $rssExport = eZRSSExport::create($user_id);
    $rssExport->store();
    $rssExportID = $rssExport->attribute('id');
    // Create One empty export item
    $rssExportItem = eZRSSExportItem::create($rssExportID);
    $rssExportItem->store();
    $db->commit();
}
$tpl = eZTemplate::factory();
$config = eZINI::instance('site.ini');
$rssVersionArray = $config->variable('RSSSettings', 'AvailableVersionList');
$rssDefaultVersion = $config->variable('RSSSettings', 'DefaultVersion');
$numberOfObjectsArray = $config->variable('RSSSettings', 'NumberOfObjectsList');
$numberOfObjectsDefault = $config->variable('RSSSettings', 'NumberOfObjectsDefault');
// Get Classes and class attributes
$classArray = eZContentClass::fetchList();
$tpl->setVariable('rss_version_array', $rssVersionArray);
$tpl->setVariable('rss_version_default', $rssDefaultVersion);
$tpl->setVariable('number_of_objects_array', $numberOfObjectsArray);
$tpl->setVariable('number_of_objects_default', $numberOfObjectsDefault);
Example #3
0
 /**
  * Set RSSExportItem defaults based on site.ini [RSSSettings] settings
  *
  * @param eZRSSExportItem $rssExportItem
  * @return bool True if changes where made
  */
 static function setItemDefaults(eZRSSExportItem $rssExportItem)
 {
     $nodeId = $rssExportItem->attribute('source_node_id');
     $node = $nodeId ? eZContentObjectTreeNode::fetch($nodeId) : null;
     if (!$node instanceof eZContentObjectTreeNode) {
         return false;
     }
     $config = eZINI::instance('site.ini');
     $nodeClassIdentifier = $node->attribute('class_identifier');
     $defaultFeedItemClasses = $config->variable('RSSSettings', 'DefaultFeedItemClasses');
     if (!isset($defaultFeedItemClasses[$nodeClassIdentifier])) {
         return false;
     }
     $feedItemClasses = explode(';', $defaultFeedItemClasses[$nodeClassIdentifier]);
     $iniSection = 'RSSSettings_' . $feedItemClasses[0];
     if (!$config->hasVariable($iniSection, 'FeedObjectAttributeMap')) {
         return false;
     }
     $feedObjectAttributeMap = $config->variable($iniSection, 'FeedObjectAttributeMap');
     $subNodesMap = $config->hasVariable($iniSection, 'Subnodes') ? $config->variable($iniSection, 'Subnodes') : array();
     $rssExportItem->setAttribute('class_id', eZContentObjectTreeNode::classIDByIdentifier($feedItemClasses[0]));
     $rssExportItem->setAttribute('title', $feedObjectAttributeMap['title']);
     if (isset($feedObjectAttributeMap['description'])) {
         $rssExportItem->setAttribute('description', $feedObjectAttributeMap['description']);
     }
     if (isset($feedObjectAttributeMap['category'])) {
         $rssExportItem->setAttribute('category', $feedObjectAttributeMap['category']);
     }
     if (isset($feedObjectAttributeMap['enclosure'])) {
         $rssExportItem->setAttribute('enclosure', $feedObjectAttributeMap['enclosure']);
     }
     $rssExportItem->setAttribute('subnodes', isset($subNodesMap[$nodeClassIdentifier]) && $subNodesMap[$nodeClassIdentifier] === 'true');
     $rssExportItem->store();
 }
Example #4
0
 static function fetchFilteredList($cond, $asObject = true, $status = eZRSSExport::STATUS_VALID)
 {
     return eZPersistentObject::fetchObjectList(eZRSSExportItem::definition(), null, $cond, array('id' => 'asc', 'status' => $status), null, $asObject);
 }
Example #5
0
    /**
     * Generates an RSS feed document with type $type and returns it as a string.
     *
     * It uses the Feed component from eZ Components.
     *
     * Supported types: 'rss1', 'rss2', 'atom'.
     *
     * @since 4.2
     * @param string $type One of 'rss1', 'rss2' and 'atom'
     * @return string XML document as a string
     */
    function generateFeed( $type )
    {
        $locale = eZLocale::instance();

        // Get URL Translation settings.
        $config = eZINI::instance();
        if ( $config->variable( 'URLTranslator', 'Translation' ) == 'enabled' )
        {
            $useURLAlias = true;
        }
        else
        {
            $useURLAlias = false;
        }

        if ( $this->attribute( 'url' ) == '' )
        {
            $baseItemURL = '';
            eZURI::transformURI( $baseItemURL, false, 'full' );
            $baseItemURL .= '/';
        }
        else
        {
            $baseItemURL = $this->attribute( 'url' ) . '/'; //.$this->attribute( 'site_access' ).'/';
        }

        $feed = new ezcFeed();

        $feed->title = $this->attribute( 'title' );

        $link = $feed->add( 'link' );
        $link->href = $baseItemURL;

        $feed->description = $this->attribute( 'description' );
        $feed->language = $locale->httpLocaleCode();

        // to add the <atom:link> element needed for RSS2
        $feed->id = $baseItemURL . 'rss/feed/' . $this->attribute( 'access_url' );

        // required for ATOM
        $feed->updated = time();
        $author        = $feed->add( 'author' );
        $author->email = $config->variable( 'MailSettings', 'AdminEmail' );
        $creatorObject = eZContentObject::fetch( $this->attribute( 'creator_id' ) );
        if ( $creatorObject instanceof eZContentObject )
        {
            $author->name = $creatorObject->attribute('name');
        }

        $imageURL = $this->fetchImageURL();
        if ( $imageURL !== false )
        {
            $image = $feed->add( 'image' );

            // Required for RSS1
            $image->about = $imageURL;

            $image->url = $imageURL;
            $image->title = $this->attribute( 'title' );
            $image->link = $baseItemURL;
        }

        $cond = array(
                    'rssexport_id'  => $this->ID,
                    'status'        => $this->Status
                    );
        $rssSources = eZRSSExportItem::fetchFilteredList( $cond );

        $nodeArray = eZRSSExportItem::fetchNodeList( $rssSources, $this->getObjectListFilter() );

        if ( is_array( $nodeArray ) && count( $nodeArray ) )
        {
            $attributeMappings = eZRSSExportItem::getAttributeMappings( $rssSources );

            foreach ( $nodeArray as $node )
            {
                if ( $node->attribute('is_hidden') && !eZContentObjectTreeNode::showInvisibleNodes() )
                {
                    // if the node is hidden skip past it and don't add it to the RSS export
                    continue;
                }
                $object = $node->attribute( 'object' );
                $dataMap = $object->dataMap();
                if ( $useURLAlias === true )
                {
                    $nodeURL = $this->urlEncodePath( $baseItemURL . $node->urlAlias() );
                }
                else
                {
                    $nodeURL = $baseItemURL . 'content/view/full/' . $node->attribute( 'node_id' );
                }

                // keep track if there's any match
                $doesMatch = false;
                // start mapping the class attribute to the respective RSS field
                foreach ( $attributeMappings as $attributeMapping )
                {
                    // search for correct mapping by path
                    if ( $attributeMapping[0]->attribute( 'class_id' ) == $object->attribute( 'contentclass_id' ) and
                         in_array( $attributeMapping[0]->attribute( 'source_node_id' ), $node->attribute( 'path_array' ) ) )
                    {
                        // found it
                        $doesMatch = true;
                        // now fetch the attributes
                        $title =  $dataMap[$attributeMapping[0]->attribute( 'title' )];
                        // description is optional
                        $descAttributeIdentifier = $attributeMapping[0]->attribute( 'description' );
                        $description = $descAttributeIdentifier ? $dataMap[$descAttributeIdentifier] : false;
                        // category is optional
                        $catAttributeIdentifier = $attributeMapping[0]->attribute( 'category' );
                        $category = $catAttributeIdentifier ? $dataMap[$catAttributeIdentifier] : false;
                        // enclosure is optional
                        $enclosureAttributeIdentifier = $attributeMapping[0]->attribute( 'enclosure' );
                        $enclosure = $enclosureAttributeIdentifier ? $dataMap[$enclosureAttributeIdentifier] : false;
                        break;
                    }
                }

                if( !$doesMatch )
                {
                    // no match
                    eZDebug::writeError( 'Cannot find matching RSS attributes for datamap on node: ' . $node->attribute( 'node_id' ), __METHOD__ );
                    return null;
                }

                // title RSS element with respective class attribute content
                $titleContent =  $title->attribute( 'content' );
                if ( $titleContent instanceof eZXMLText )
                {
                    $outputHandler = $titleContent->attribute( 'output' );
                    $itemTitleText = $outputHandler->attribute( 'output_text' );
                }
                else
                {
                    $itemTitleText = $titleContent;
                }

                $item = $feed->add( 'item' );

                $item->title = $itemTitleText;

                $link = $item->add( 'link' );
                $link->href = $nodeURL;

                switch ( $type )
                {
                    case 'rss2':
                        $item->id = $object->attribute( 'remote_id' );
                        $item->id->isPermaLink = false;
                        break;
                    default:
                        $item->id = $nodeURL;
                }

                $itemCreatorObject = $node->attribute('creator');
                if ( $itemCreatorObject instanceof eZContentObject )
                {
                    $author = $item->add( 'author' );
                    $author->name = $itemCreatorObject->attribute('name');
                    $author->email = $config->variable( 'MailSettings', 'AdminEmail' );
                }

                // description RSS element with respective class attribute content
                if ( $description )
                {
                    $descContent = $description->attribute( 'content' );
                    if ( $descContent instanceof eZXMLText )
                    {
                        $outputHandler =  $descContent->attribute( 'output' );
                        $itemDescriptionText = str_replace( '&nbsp;', '&amp;nbsp;', $outputHandler->attribute( 'output_text' ) );
                    }
                    else if ( $descContent instanceof eZImageAliasHandler )
                    {
                        $itemImage   = $descContent->hasAttribute( 'rssitem' ) ? $descContent->attribute( 'rssitem' ) : $descContent->attribute( 'rss' );
                        $origImage   = $descContent->attribute( 'original' );
                        eZURI::transformURI( $itemImage['full_path'], true, 'full' );
                        eZURI::transformURI( $origImage['full_path'], true, 'full' );
                        $itemDescriptionText = '&lt;a href="' . htmlspecialchars( $origImage['full_path'] )
                                             . '"&gt;&lt;img alt="' . htmlspecialchars( $descContent->attribute( 'alternative_text' ) )
                                             . '" src="' . htmlspecialchars( $itemImage['full_path'] )
                                             . '" width="' . $itemImage['width']
                                             . '" height="' . $itemImage['height']
                                             . '" /&gt;&lt;/a&gt;';
                    }
                    else
                    {
                        $itemDescriptionText = $descContent;
                    }
                    $item->description = $itemDescriptionText;
                }

                // category RSS element with respective class attribute content
                if ( $category )
                {
                    $categoryContent =  $category->attribute( 'content' );
                    if ( $categoryContent instanceof eZXMLText )
                    {
                        $outputHandler = $categoryContent->attribute( 'output' );
                        $itemCategoryText = $outputHandler->attribute( 'output_text' );
                    }
                    elseif ( $categoryContent instanceof eZKeyword )
                    {
                        $itemCategoryText = $categoryContent->keywordString();
                    }
                    else
                    {
                        $itemCategoryText = $categoryContent;
                    }

                    if ( $itemCategoryText )
                    {
                        $cat = $item->add( 'category' );
                        $cat->term = $itemCategoryText;
                    }
                }

                // enclosure RSS element with respective class attribute content
                if ( $enclosure )
                {
                    $encItemURL       = false;
                    $enclosureContent = $enclosure->attribute( 'content' );
                    if ( $enclosureContent instanceof eZMedia )
                    {
                        $enc         = $item->add( 'enclosure' );
                        $enc->length = $enclosureContent->attribute('filesize');
                        $enc->type   = $enclosureContent->attribute('mime_type');
                        $encItemURL = 'content/download/' . $enclosure->attribute('contentobject_id')
                                    . '/' . $enclosureContent->attribute( 'contentobject_attribute_id' )
                                    . '/' . urlencode( $enclosureContent->attribute( 'original_filename' ) );
                        eZURI::transformURI( $encItemURL, false, 'full' );
                    }
                    else if ( $enclosureContent instanceof eZBinaryFile )
                    {
                        $enc         = $item->add( 'enclosure' );
                        $enc->length = $enclosureContent->attribute('filesize');
                        $enc->type   = $enclosureContent->attribute('mime_type');
                        $encItemURL = 'content/download/' . $enclosure->attribute('contentobject_id')
                                    . '/' . $enclosureContent->attribute( 'contentobject_attribute_id' )
                                    . '/version/' . $enclosureContent->attribute( 'version' )
                                    . '/file/' . urlencode( $enclosureContent->attribute( 'original_filename' ) );
                        eZURI::transformURI( $encItemURL, false, 'full' );
                    }
                    else if ( $enclosureContent instanceof eZImageAliasHandler )
                    {
                        $enc         = $item->add( 'enclosure' );
                        $origImage   = $enclosureContent->attribute( 'original' );
                        $enc->length = $origImage['filesize'];
                        $enc->type   = $origImage['mime_type'];
                        $encItemURL  = $origImage['full_path'];
                        eZURI::transformURI( $encItemURL, true, 'full' );
                    }

                    if ( $encItemURL )
                    {
                        $enc->url = $encItemURL;
                    }
                }

                $item->published = $object->attribute( 'published' );
                $item->updated = $object->attribute( 'published' );
            }
        }
        return $feed->generate( $type );
    }
 /**
  * Creates an RSS export object and returns it.
  *
  * @param string $version One of '1.0', '2.0' or 'ATOM'
  * @param int $folderId
  * @param string $title
  * @param string $description
  * @return eZRSSExport
  */
 public function createEZPRSSExport($version, $folderId, $title, $description)
 {
     // Create default rssExport object to use
     $rssExport = eZRSSExport::create($this->ezp_admin_id);
     $rssExport->setAttribute('node_id', $folderId);
     $rssExport->setAttribute('rss_version', $version);
     $rssExport->setAttribute('title', $title);
     $rssExport->setAttribute('description', $description);
     $rssExport->store();
     $rssExportID = $rssExport->attribute('id');
     // Create one empty export item
     $rssExportItem = eZRSSExportItem::create($this->ezp_admin_id);
     $rssExportItem->setAttribute('title', 'title');
     $rssExportItem->setAttribute('class_id', 2);
     // 2 = article
     $rssExportItem->setAttribute('rssexport_id', $rssExportID);
     $rssExportItem->setAttribute('description', 'intro');
     $rssExportItem->setAttribute('source_node_id', $folderId);
     $rssExportItem->store();
     return $rssExport;
 }
Example #7
0
    function setRSSExport( $params )
    {


        // Create default rssExport object to use
        $rssExport = eZRSSExport::create( $params['creator'] );
        $rssExport->setAttribute( 'access_url', $params['access_url'] );
        $rssExport->setAttribute( 'main_node_only', $params['main_node_only'] );
        $rssExport->setAttribute( 'number_of_objects', $params['number_of_objects'] );
        $rssExport->setAttribute( 'rss_version', $params['rss_version'] );
        $rssExport->setAttribute( 'status', $params['status'] );
        $rssExport->setAttribute( 'title', $params['title'] );
        $rssExport->store();

        $rssExportID = $rssExport->attribute( 'id' );

        foreach( $params['rss_export_itmes'] as $item )
        {
            // Create One empty export item
            $rssExportItem = eZRSSExportItem::create( $rssExportID );
            $rssExportItem->setAttribute( 'class_id', $item['class_id'] );
            $rssExportItem->setAttribute( 'description', $item['description'] );
            $rssExportItem->setAttribute( 'source_node_id', $item['source_node_id'] );
            $rssExportItem->setAttribute( 'status', $item['status'] );
            $rssExportItem->setAttribute( 'title', $item['title'] );
            if ( isset( $item['enclosure'] ) )
            {
                $rssExportItem->setAttribute( 'enclosure', $item['enclosure'] );
            }
            $rssExportItem->store();
        }
    }
 /**
  * Creates an RSS export object and returns it.
  *
  * @param string $version One of '1.0', '2.0' or 'ATOM'
  * @param int $folderId
  * @param string $title
  * @param string $description
  * @return eZRSSExport
  */
 public function createEZPRSSExport($version, $folderId, $title, $description)
 {
     $userId = $this->loginEZPUser($GLOBALS['ezp_username'], $GLOBALS['ezp_password']);
     // Create default rssExport object to use
     $rssExport = eZRSSExport::create($userId);
     $rssExport->setAttribute('node_id', $folderId);
     $rssExport->setAttribute('rss_version', $version);
     $rssExport->setAttribute('title', $title);
     $rssExport->setAttribute('description', $description);
     $rssExport->store();
     $rssExportID = $rssExport->attribute('id');
     // Create one empty export item
     $rssExportItem = eZRSSExportItem::create($userId);
     $rssExportItem->setAttribute('title', 'title');
     $rssExportItem->setAttribute('class_id', 2);
     // 2 = article
     $rssExportItem->setAttribute('rssexport_id', $rssExportID);
     $rssExportItem->setAttribute('description', 'intro');
     $rssExportItem->setAttribute('source_node_id', $folderId);
     $rssExportItem->store();
     return $rssExport;
 }