Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
/ lezrss Public archive

Commit

Permalink
Add 1.0-RC1 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
llaumgui committed Feb 27, 2010
0 parents commit d8ca1cf
Show file tree
Hide file tree
Showing 16 changed files with 1,019 additions and 0 deletions.
272 changes: 272 additions & 0 deletions classes/lezrssexport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
<?php
//
// Created on: <01-Sep-2008 19:00:00 GKUL>
//
// ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
// SOFTWARE NAME: leZRSS
// SOFTWARE RELEASE: 1.0
// BUILD VERSION:
// COPYRIGHT NOTICE: Copyright (c) 2008-2010 Guillaume Kulakowski and contributors
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2.0 of the GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of version 2.0 of the GNU General
// Public License along with this program; if not, write to the Free
// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
//
// ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
//

class leZRSSExport extends eZRSSExport
{

static function definition()
{
$definition = parent::definition();
$definition['class_name'] = 'leZRSSExport';
return $definition;
}



/**
* Fetches the RSS Export by ID.
*
* @param RSS Export ID
* @return leZRSSExport
*/
static function fetch( $id, $asObject = true, $status = leZRSSExport::STATUS_VALID )
{
return eZPersistentObject::fetchObject( leZRSSExport::definition(),
null,
array( "id" => $id, 'status' => $status ),
$asObject );
}



/**
* Fetches the RSS Export by feed access url and is active.
*
* @param RSS Export access url
* @return leZRSSExport
*/
static function fetchByName( $access_url, $asObject = true )
{
return eZPersistentObject::fetchObject( leZRSSExport::definition(),
null,
array( 'access_url' => $access_url,
'active' => 1,
'status' => 1 ),
$asObject );
}



/**
* Get a RSS xml document based on rss2 template based on the RSS Export settings defined by this object
*
* @return RSS XML document
*/
function tplRSS( $lastModified = null )
{
if ( is_null($lastModified) )
$lastModified = gmdate( 'D, d M Y H:i:s', time() ) . ' GMT';

// eZP 4.3
if ( is_callable( array( 'eZTemplate', 'factory') ) )
{
$tpl = ezTemplate::factory();
}
// Deprecated on eZP 4.3
else
{
include_once( 'kernel/common/template.php' );
$tpl = templateInit();
}

$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' ).'/';
}

$metaDataArray = $config->variable('SiteSettings','MetaDataArray');

/*
* Channel informations
*/
$channel = array(
'atom:link' => array(
'href' => $baseItemURL . "rss/feed/" . $this->attribute( 'access_url' ),
'rel' => 'self',
'type' => 'application/rss+xml'
),
'title' => $this->attribute( 'title' ),
'link' => $this->attribute( 'url' ),
'description' => $this->attribute( 'description' ),
'language' => $locale->httpLocaleCode(),
'pubDate' => $lastModified,
'copyright' => $metaDataArray['copyright'],
'generator' => 'eZ Publish (leZRSS)'
);

$imageURL = $this->fetchImageURL();
if ( $imageURL !== false )
{
$channel['image'] = array(
'url' => $imageURL,
'title' => $this->attribute( 'title' ),
'link' => $this->attribute( 'url' )
);
}
$tpl->setVariable('channel', $channel );

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

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

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

foreach ( $nodeArray as $key => $node )
{
$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 = $dataMap[$attributeMapping[0]->attribute( 'description' )];
// category is optional
$catAttributeIdentifier = $attributeMapping[0]->attribute( 'category' );
$category = $catAttributeIdentifier ? $dataMap[$catAttributeIdentifier] : false;
break;
}
}

if( !$doesMatch )
{
// no match
eZDebug::writeWarning( __METHOD__ . ': Cannot find matching RSS source node for content object in '.__FILE__.', Line '.__LINE__ );
$retValue = null;
return $retValue;
}

// 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;
}

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

// category RSS element with respective class attribute content
$itemCategoryText = '';
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;
}
}

$itemPubDate = gmdate( 'D, d M Y H:i:s', $object->attribute( 'published' ) ) .' GMT';

$items[$key] = array(
'title' => $itemTitleText,
'link' => $nodeURL,
'guid' => $nodeURL,
'description' => $itemDescriptionText,
'category' => $itemCategoryText,
'pubDate' => $itemPubDate,
);
}
}
$tpl->setVariable( 'node_array', $nodeArray );
$tpl->setVariable( 'items', $items );
return $tpl->fetch('design:rss2/channel.tpl');
}

}

?>
21 changes: 21 additions & 0 deletions design/standard/override/templates/rss2/example.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{def $image = concat( ""|ezroot('no', 'full'), 'people_default.png'|ezimage('no', 'true') )}
{if $node.object.owner.current.data_map.image.content.is_valid}
{set $image = $node.object.owner.current.data_map.image.content.hackergotchi.url|ezroot('no', 'full')}
{/if}
{set $image = concat( '<img src="', $image, '" alt="', $node.object.owner.name, '" style="float: right" />' )}
<item>
<pubDate>{$item.pubDate}</pubDate>
<title>{$node.object.owner.current.name|wash()} : {$item.title|wash()}</title>
<link>{$node.data_map.location.content}</link>
{if or( $node.data_map.guid.has_content|not(), $node.data_map.guid.content|begins_with('http:https://') )}
<guid>{$node.data_map.location.content}</guid>
{else}
<guid isPermaLink="false">{$node.data_map.guid.content}</guid>
{/if}
<description>
<![CDATA[{$image}{$item.description}]]>
</description>
{if $item.category}<category>{$item.category|wash()}</category>{/if}

</item>
{undef $image}
12 changes: 12 additions & 0 deletions design/standard/templates/node/view/rss2.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<item>
<pubDate>{$item.pubDate}</pubDate>
<title>{$item.title|wash()}</title>
<link>{$item.link}</link>
<guid>{$item.guid}</guid>
<description>
<![CDATA[{$item.description}]]>
</description>
{if $item.category}<category>{$item.category|wash()}</category>{/if}

</item>
23 changes: 23 additions & 0 deletions design/standard/templates/rss2/channel.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http:https://www.w3.org/2005/Atom">
<channel>
<title>{$channel['title']}</title>
<link>{$channel['link']}</link>
<atom:link href="{$channel['atom:link']['href']}" rel="{$channel['atom:link']['rel']}" type="{$channel['atom:link']['type']}"/>
<description>{$channel['description']}</description>
<language>{$channel['language']}</language>
<pubDate>{$channel['pubDate']}</pubDate>
<copyright>{$channel['copyright']}</copyright>
<generator>{$channel['generator']}</generator>

{if is_set( $channel['image'] )}<image>
<url>{$channel['image']['url']}</url>
<title>{$channel['image']['title']}</title>
<link>{$channel['image']['link']}</link>
</image>{/if}

{foreach $node_array as $key => $node}
{node_view_gui view='rss2' content_node=$node item=$items[$key]}
{/foreach}
</channel>
</rss>
5 changes: 5 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ChangeLog
---------

- leZRSS 1.0
* First release
36 changes: 36 additions & 0 deletions doc/INSTALL
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
leZRSS 1.0 extension installation documentation

About leZRSS
------------

leZRSS is an improvement of eZRSS native function :

* Adds fetch for get all RSS feed defined
* Adds module rss2 for use template system in RSS



Installation
------------

1. Unpack/unzip

Unpack the downloaded tar.gz package into the 'extension' directory of your
eZ Publish installation.

2. Activate extension

Activate the extension by using the admin interface ( Setup -> Extensions ) or by
prepending lezrss to ActiveExtensions[] in settings/override/site.ini.append.php:

[ExtensionSettings]
ActiveExtensions[]=lezrss

3. Regenerate autoload array

Check the eZ Publish docs for your version on how this is done.
Or go to Setup -> Extensions and click on the button there.

4. Clear caches

Clear INI and template caches (from admin 'Setup' tab or commandline).
Loading

0 comments on commit d8ca1cf

Please sign in to comment.