Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- App::uses('AppController', 'Controller');
- class RssController extends AppController {
- public $components = array('RequestHandler');
- public function beforeFilter() {
- $this->autoRender = false;
- parent::beforeFilter();
- }
- public function index() {
- $this->response->type('text/xml');
- // $this->RequestHandler->respondAs('xml');
- // $this->RequestHandler->renderAs($this, 'xml');
- // $this->RequestHandler->setContent('xml');
- // $this->RequestHandler->respondAs('xml');
- // $this->RequestHandler->renderAs($this, 'xml');
- $this->channel_properties = array(
- 'title' => 'None',
- 'link' => 'http://www.example.com',
- 'description' => 'None',
- );
- if ($this->request->query('feed_id') && $this->request->query('user_id')) {
- $this->loadModel('Feeds');
- $res = $this->Feeds->findAllByFeedIdAndUserAttribution($this->request->query('feed_id'), $this->request->query('user_id'));
- if ($res) {
- foreach($res AS $entry) {
- preg_match_all('/<a.*?>(.*?)<\/a>/', $entry['Feeds']['feed'], $matches);
- if (isset($matches[0])) {
- foreach($matches[0] AS $key => $link) {
- if (stripos($link, 'vine.co') !== false) {
- unset($matches[0][$key]);
- }
- }
- $matches[0][] = '[]';
- $entry['Feeds']['feed'] = str_replace($matches[0], '', $entry['Feeds']['feed']);
- }
- $feed[] = array(
- 'title' => 'No Name',
- 'link' => 'http://www.example.com',
- 'description' => $entry['Feeds']['feed'],
- 'pubDate' => $entry['Feeds']['date_dt'],
- // 'category' => $entry['Feeds']['date_dt']
- );
- }
- $this->_createFeed($feed);
- }
- }
- }
- private function _createFeed($feed) {
- $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
- $xml .= '<rss version="2.0"' . $this->xmlns . '>' . "\n";
- // channel required properties
- $xml .= '<channel>' . "\n";
- $xml .= '<title>' . $this->channel_properties["title"] . '</title>' . "\n";
- $xml .= '<link>' . $this->channel_properties["link"] . '</link>' . "\n";
- $xml .= '<description>' . $this->channel_properties["description"] . '</description>' . "\n";
- // channel optional properties
- if (array_key_exists("language", $this->channel_properties)) {
- $xml .= '<language>' . $this->channel_properties["language"] . '</language>' . "\n";
- }
- if (array_key_exists("image_title", $this->channel_properties)) {
- $xml .= '<image>' . "\n";
- $xml .= '<title>' . $this->channel_properties["image_title"] . '</title>' . "\n";
- $xml .= '<link>' . $this->channel_properties["image_link"] . '</link>' . "\n";
- $xml .= '<url>' . $this->channel_properties["image_url"] . '</url>' . "\n";
- $xml .= '</image>' . "\n";
- }
- // get RSS channel items
- // $now = date("YmdHis"); // get current time // configure appropriately to your environment
- foreach ($feed as $rss_item) {
- $xml .= '<item>' . "\n";
- $xml .= '<title>' . $rss_item['title'] . '</title>' . "\n";
- $xml .= '<link>' . $rss_item['link'] . '</link>' . "\n";
- $xml .= '<description><![CDATA[' . ($rss_item['description']) . ']]></description>' . "\n";
- $xml .= '<pubDate>' . $rss_item['pubDate'] . '</pubDate>' . "\n";
- // $xml .= '<category>' . $rss_item['category'] . '</category>' . "\n";
- // $xml .= '<source>' . $rss_item['source'] . '</source>' . "\n";
- if ($this->full_feed) {
- $xml .= '<content:encoded>' . $rss_item['content'] . '</content:encoded>' . "\n";
- }
- $xml .= '</item>' . "\n";
- }
- $xml .= '</channel>';
- $xml .= '</rss>';
- echo $xml;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment