/** * Return valid eZRSSExport object for a specific node if it exists. * * @param int $nodeID * @return eZRSSExport|false Return value is inside a array with return value on result, as this is used as template fetch function. */ static function exportByNode($nodeID) { if (!$nodeID) { return array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND)); } $rssExport = eZPersistentObject::fetchObject(eZRSSExport::definition(), null, array('node_id' => $nodeID, 'status' => eZRSSExport::STATUS_VALID), true); return array('result' => $rssExport); }
/** * Removes a RSS/ATOM Feed export for a node * * @param int $nodeID Node ID * * @since 4.3 */ public static function removeFeedForNode($nodeID) { $rssExport = eZPersistentObject::fetchObject(eZRSSExport::definition(), null, array('node_id' => $nodeID, 'status' => eZRSSExport::STATUS_VALID), true); if (!$rssExport instanceof eZRSSExport) { eZDebug::writeError('DisableRSS: There is no rss/atom feeds left to delete for this node: ' . $nodeID, __METHOD__); return array('status' => false); } $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node instanceof eZContentObjectTreeNode) { eZDebug::writeError('DisableRSS: Could not fetch node: ' . $nodeID, __METHOD__); return array('status' => false); } $objectID = $node->attribute('contentobject_id'); $rssExport->removeThis(); eZContentCacheManager::clearContentCacheIfNeeded($objectID); return array('status' => true); }
static function storeRSSExport($Module, $http, $publish = false, $skipValuesID = null) { $valid = true; $validationErrors = array(); /* Kill the RSS cache in all siteaccesses */ $config = eZINI::instance('site.ini'); $cacheDir = eZSys::cacheDirectory(); $availableSiteAccessList = $config->variable('SiteAccessSettings', 'AvailableSiteAccessList'); foreach ($availableSiteAccessList as $siteAccess) { $cacheFilePath = $cacheDir . '/rss/' . md5($siteAccess . $http->postVariable('Access_URL')) . '.xml'; $cacheFile = eZClusterFileHandler::instance($cacheFilePath); if ($cacheFile->exists()) { $cacheFile->delete(); } } $db = eZDB::instance(); $db->begin(); /* Create the new RSS feed */ for ($itemCount = 0; $itemCount < $http->postVariable('Item_Count'); $itemCount++) { if ($skipValuesID == $http->postVariable('Item_ID_' . $itemCount)) { continue; } $rssExportItem = eZRSSExportItem::fetch($http->postVariable('Item_ID_' . $itemCount), true, eZRSSExport::STATUS_DRAFT); if ($rssExportItem == null) { continue; } // RSS is supposed to feed certain objects from the subnodes if ($http->hasPostVariable('Item_Subnodes_' . $itemCount)) { $rssExportItem->setAttribute('subnodes', 1); } else { $rssExportItem->setAttribute('subnodes', 0); } $rssExportItem->setAttribute('class_id', $http->postVariable('Item_Class_' . $itemCount)); $class = eZContentClass::fetch($http->postVariable('Item_Class_' . $itemCount)); $titleClassAttributeIdentifier = $http->postVariable('Item_Class_Attribute_Title_' . $itemCount); $descriptionClassAttributeIdentifier = $http->postVariable('Item_Class_Attribute_Description_' . $itemCount); $categoryClassAttributeIdentifier = $http->postVariable('Item_Class_Attribute_Category_' . $itemCount); if (!$class) { $validated = false; $validationErrors[] = ezpI18n::tr('kernel/rss/edit_export', 'Selected class does not exist'); } else { $dataMap = $class->attribute('data_map'); if (!isset($dataMap[$titleClassAttributeIdentifier])) { $valid = false; $validationErrors[] = ezpI18n::tr('kernel/rss/edit_export', 'Invalid selection for title class %1 does not have attribute "%2"', null, array($class->attribute('name'), $titleClassAttributeIdentifier)); } if ($descriptionClassAttributeIdentifier != '' && !isset($dataMap[$descriptionClassAttributeIdentifier])) { $valid = false; $validationErrors[] = ezpI18n::tr('kernel/rss/edit_export', 'Invalid selection for description class %1 does not have attribute "%2"', null, array($class->attribute('name'), $descriptionClassAttributeIdentifier)); } if ($categoryClassAttributeIdentifier != '' && !isset($dataMap[$categoryClassAttributeIdentifier])) { $valid = false; $validationErrors[] = ezpI18n::tr('kernel/rss/edit_export', 'Invalid selection for category class %1 does not have attribute "%2"', null, array($class->attribute('name'), $categoryClassAttributeIdentifier)); } } $rssExportItem->setAttribute('title', $http->postVariable('Item_Class_Attribute_Title_' . $itemCount)); $rssExportItem->setAttribute('description', $http->postVariable('Item_Class_Attribute_Description_' . $itemCount)); $rssExportItem->setAttribute('category', $http->postVariable('Item_Class_Attribute_Category_' . $itemCount)); if ($http->hasPostVariable('Item_Class_Attribute_Enclosure_' . $itemCount)) { $rssExportItem->setAttribute('enclosure', $http->postVariable('Item_Class_Attribute_Enclosure_' . $itemCount)); } if ($publish && $valid) { $rssExportItem->setAttribute('status', eZRSSExport::STATUS_VALID); $rssExportItem->store(); // delete drafts $rssExportItem->setAttribute('status', eZRSSExport::STATUS_DRAFT); $rssExportItem->remove(); } else { $rssExportItem->store(); } } $rssExport = eZRSSExport::fetch($http->postVariable('RSSExport_ID'), true, eZRSSExport::STATUS_DRAFT); $rssExport->setAttribute('title', $http->postVariable('title')); $rssExport->setAttribute('url', $http->postVariable('url')); // $rssExport->setAttribute( 'site_access', $http->postVariable( 'SiteAccess' ) ); $rssExport->setAttribute('description', $http->postVariable('Description')); $rssExport->setAttribute('rss_version', $http->postVariable('RSSVersion')); $rssExport->setAttribute('number_of_objects', $http->postVariable('NumberOfObjects')); $rssExport->setAttribute('image_id', $http->postVariable('RSSImageID')); if ($http->hasPostVariable('active')) { $rssExport->setAttribute('active', 1); } else { $rssExport->setAttribute('active', 0); } $rssExport->setAttribute('access_url', str_replace(array('/', '?', '&', '>', '<'), '', $http->postVariable('Access_URL'))); if ($http->hasPostVariable('MainNodeOnly')) { $rssExport->setAttribute('main_node_only', 1); } else { $rssExport->setAttribute('main_node_only', 0); } $published = false; if ($publish && $valid) { $rssExport->store(true); // remove draft $rssExport->remove(); $published = true; } else { $rssExport->store(); } $db->commit(); return array('valid' => $valid, 'published' => $published, 'validation_errors' => $validationErrors); }
} break; case 'ImageSource': $imageNodeIDArray = $http->hasPostVariable('SelectedNodeIDArray') ? $http->postVariable('SelectedNodeIDArray') : null; 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();
foreach ($deleteArray as $deleteID) { $rssImport = eZRSSImport::fetch($deleteID, true, eZRSSImport::STATUS_DRAFT); if ($rssImport) { $rssImport->remove(); } $rssImport = eZRSSImport::fetch($deleteID, true, eZRSSImport::STATUS_VALID); if ($rssImport) { $rssImport->remove(); } } } } } } // Get all RSS Exports $exportArray = eZRSSExport::fetchList(); $exportList = array(); foreach ($exportArray as $export) { $exportList[$export->attribute('id')] = $export; } // Get all RSS imports $importArray = eZRSSImport::fetchList(); $importList = array(); foreach ($importArray as $import) { $importList[$import->attribute('id')] = $import; } $tpl = eZTemplate::factory(); $tpl->setVariable('rssexport_list', $exportList); $tpl->setVariable('rssimport_list', $importList); $Result = array(); $Result['content'] = $tpl->fetch("design:rss/list.tpl");
<?php /** * @copyright Copyright (C) 1999-2013 eZ Systems AS. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 * @version //autogentag// * @package kernel */ $Module = $Params['Module']; if (!isset($Params['RSSFeed'])) { eZDebug::writeError('No RSS feed specified'); return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $feedName = $Params['RSSFeed']; $RSSExport = eZRSSExport::fetchByName($feedName); // Get and check if RSS Feed exists if (!$RSSExport) { eZDebug::writeError('Could not find RSSExport : ' . $Params['RSSFeed']); return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel'); } $config = eZINI::instance('site.ini'); $cacheTime = intval($config->variable('RSSSettings', 'CacheTime')); $lastModified = gmdate('D, d M Y H:i:s', time()) . ' GMT'; eZURI::setTransformURIMode('full'); if ($cacheTime <= 0) { $xmlDoc = $RSSExport->attribute('rss-xml-content'); $rssContent = $xmlDoc; } else { $cacheDir = eZSys::cacheDirectory(); $currentSiteAccessName = $GLOBALS['eZCurrentAccess']['name']; $cacheFilePath = $cacheDir . '/rss/' . md5($currentSiteAccessName . $feedName) . '.xml';
static function fetchList( $asObject = true ) { return eZPersistentObject::fetchObjectList( eZRSSExport::definition(), null, array( 'status' => self::STATUS_VALID ), null, null, $asObject ); }
/** * 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; }
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; }