File indexing completed on 2025-05-04 05:29:07
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class RssController extends Local_Controller_Action_DomainSwitch 0024 { 0025 0026 public function rssAction() 0027 { 0028 $this->_helper->layout()->disableLayout(); 0029 $this->_helper->viewRenderer->setNoRender(true); 0030 0031 $latestActions = $this->getLatestActivitiesForHost(); 0032 0033 $rssWriter = Zend_Feed::importArray($latestActions); 0034 $rssWriter->send(); 0035 } 0036 0037 private function getLatestActivitiesForHost() 0038 { 0039 return $this->createBaseInformation('Latest Events'); 0040 } 0041 0042 private function createBaseInformation($title) 0043 { 0044 $storeConfig = Zend_Registry::isRegistered('store_template') ? Zend_Registry::get('store_template') : null; 0045 return $importArray = array( 0046 'title' => $storeConfig['head']['browser_title_prepend'] . ' ' . $title, //required 0047 'link' => 'https://' . $_SERVER['HTTP_HOST'] . '/content.rdf', //required 0048 'lastUpdate' => time(), // optional 0049 // 'published' => time(), //optional 0050 'charset' => 'utf-8', // required 0051 // 'description' => 'short description of the feed', //optional 0052 'author' => $storeConfig['head']['meta_author'], //optional 0053 'email' => 'contact@opendesktop.org', //optional 0054 'copyright' => 'All rights reserved. All trademarks are copyright by their respective owners. All contributors are responsible for their uploads.', //optional 0055 'image' => 'https://' . $_SERVER['HTTP_HOST'] . $storeConfig['logo'], //optional 0056 'generator' => $_SERVER['HTTP_HOST'] . ' atom feed generator', // optional 0057 'language' => 'en-us', // optional 0058 'ttl' => '15' // optional, ignored if atom is used 0059 ); 0060 } 0061 0062 public function rdfAction() 0063 { 0064 throw new Zend_Controller_Action_Exception('deprecated method call'); 0065 0066 //$this->_helper->layout()->disableLayout(); 0067 //$this->_helper->viewRenderer->setNoRender(true); 0068 // 0069 //$latestProducts = $this->getLatestProductsForHost(); 0070 // 0071 //$rssWriter = Zend_Feed::importArray($latestProducts); 0072 //$rssWriter->send(); 0073 } 0074 0075 private function getLatestProductsForHost() 0076 { 0077 $storeCatIds = Zend_Registry::isRegistered('store_category_list') ? Zend_Registry::get('store_category_list') : null; 0078 $filter['category'] = $storeCatIds; 0079 $filter['order'] = 'latest'; 0080 $pageLimit = 10; 0081 $offset = 0; 0082 0083 $tagFilter = Zend_Registry::isRegistered('config_store_tags') ? Zend_Registry::get('config_store_tags') : null; 0084 if ($tagFilter) { 0085 $filter['tag'] = $tagFilter; 0086 } 0087 0088 $modelProject = new Default_Model_Project(); 0089 $requestedElements = $modelProject->fetchProjectsByFilter($filter, $pageLimit, $offset); 0090 0091 $importArray = $this->createBaseInformation('Latest Products'); 0092 $importArray['entries'] = $this->generateFeedData($requestedElements['elements']); 0093 0094 return $importArray; 0095 } 0096 0097 private function generateFeedData($requestedElements) 0098 { 0099 $helperBuildUrl = new Default_View_Helper_BuildProductUrl(); 0100 $helperTruncate = new Default_View_Helper_Truncate(); 0101 $returnValues = array(); 0102 foreach ($requestedElements as $requestedElement) { 0103 $returnValues[] = 0104 array( 0105 'title' => $requestedElement->title, //required 0106 'link' => $helperBuildUrl->buildProductUrl($requestedElement->project_id, '', null, true, 'https'), //required 0107 'description' => $helperTruncate->truncate(strip_tags($requestedElement->description)), // only text, no html, required 0108 // 'guid' => 'id of the article, if not given link value will used', //optional 0109 'content' => $this->createContent($requestedElement), // can contain html, optional 0110 'lastUpdate' => strtotime($requestedElement->project_changed_at), // optional 0111 // 'comments' => 'comments page of the feed entry', // optional 0112 // 'commentRss' => 'the feed url of the associated comments', // optional 0113 'category' => array( 0114 array( 0115 'term' => $requestedElement->cat_title, // required, 0116 ), 0117 ), 0118 // list of the attached categories // optional 0119 // 'enclosure' => array( 0120 // array( 0121 // 'url' => 'url of the linked enclosure', // required 0122 // 'type' => 'mime type of the enclosure', // optional 0123 // 'length' => 'length of the linked content in octets', // optional 0124 // ), 0125 // ) // list of the enclosures of the feed entry // optional 0126 ); 0127 } 0128 return $returnValues; 0129 } 0130 0131 private function createContent($requestedElement) 0132 { 0133 $helperBuildUrl = new Default_View_Helper_BuildProductUrl(); 0134 $link = $helperBuildUrl->buildProductUrl($requestedElement->project_id, '', null, true, 'https'); 0135 $helperImage = new Default_View_Helper_Image(); 0136 $image = $helperImage->Image($requestedElement->image_small, array('height' => 40, 'width' => 40)); 0137 return '<a href="' . $link . '"><img src="' . $image . '" alt="Thumbnail" class="thumbnail" align="left" hspace="10" vspace="10" border="0" /></a><b><big><a href="' . $link . '" style="font-weight:bold;color:#333333;text-decoration:none;">' . $requestedElement->title . '</a></big></b><br /> (' . $requestedElement->cat_title . ')<br />' . $requestedElement->description . '<br /><br /><a href="' . $link . '" style="font-weight:bold;color:#333333;text-decoration:none;">[read more]</a><br /><br />'; 0138 } 0139 0140 }