Guest User

Untitled

a guest
Oct 15th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.53 KB | None | 0 0
  1. <?php
  2.  
  3. App::uses('AppController', 'Controller');
  4.  
  5. class RssController extends AppController {
  6.  
  7.     public $components = array('RequestHandler');
  8.  
  9.     public function beforeFilter() {
  10.  
  11.         $this->autoRender = false;
  12.  
  13.         parent::beforeFilter();
  14.     }
  15.  
  16.     public function index() {
  17.  
  18.         $this->response->type('text/xml');
  19. //      $this->RequestHandler->respondAs('xml');
  20. //      $this->RequestHandler->renderAs($this, 'xml');
  21. //      $this->RequestHandler->setContent('xml');
  22. //      $this->RequestHandler->respondAs('xml');
  23. //      $this->RequestHandler->renderAs($this, 'xml');
  24.  
  25.         $this->channel_properties = array(
  26.             'title' => 'None',
  27.             'link' => 'http://www.example.com',
  28.             'description' => 'None',
  29.         );
  30.  
  31.         if ($this->request->query('feed_id') && $this->request->query('user_id')) {
  32.             $this->loadModel('Feeds');
  33.             $res = $this->Feeds->findAllByFeedIdAndUserAttribution($this->request->query('feed_id'), $this->request->query('user_id'));
  34.             if ($res) {
  35.                 foreach($res AS $entry) {
  36.                     preg_match_all('/<a.*?>(.*?)<\/a>/', $entry['Feeds']['feed'], $matches);
  37.                     if (isset($matches[0])) {
  38.                         foreach($matches[0] AS $key => $link) {
  39.                             if (stripos($link, 'vine.co') !== false) {
  40.                                 unset($matches[0][$key]);
  41.                             }
  42.                         }
  43.                         $matches[0][] = '[]';
  44.                         $entry['Feeds']['feed'] = str_replace($matches[0], '', $entry['Feeds']['feed']);
  45.                     }
  46.  
  47.                     $feed[] = array(
  48.                         'title' => 'No Name',
  49.                         'link' => 'http://www.example.com',
  50.                         'description' => $entry['Feeds']['feed'],
  51.                         'pubDate' => $entry['Feeds']['date_dt'],
  52. //                      'category' => $entry['Feeds']['date_dt']
  53.                     );
  54.                 }
  55.  
  56.                 $this->_createFeed($feed);
  57.             }
  58.         }
  59.     }
  60.  
  61.     private function _createFeed($feed) {
  62.  
  63.         $xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  64.  
  65.         $xml .= '<rss version="2.0"' . $this->xmlns . '>' . "\n";
  66.  
  67.         // channel required properties
  68.         $xml .= '<channel>' . "\n";
  69.         $xml .= '<title>' . $this->channel_properties["title"] . '</title>' . "\n";
  70.         $xml .= '<link>' . $this->channel_properties["link"] . '</link>' . "\n";
  71.         $xml .= '<description>' . $this->channel_properties["description"] . '</description>' . "\n";
  72.  
  73.         // channel optional properties
  74.         if (array_key_exists("language", $this->channel_properties)) {
  75.             $xml .= '<language>' . $this->channel_properties["language"] . '</language>' . "\n";
  76.         }
  77.         if (array_key_exists("image_title", $this->channel_properties)) {
  78.             $xml .= '<image>' . "\n";
  79.             $xml .= '<title>' . $this->channel_properties["image_title"] . '</title>' . "\n";
  80.             $xml .= '<link>' . $this->channel_properties["image_link"] . '</link>' . "\n";
  81.             $xml .= '<url>' . $this->channel_properties["image_url"] . '</url>' . "\n";
  82.             $xml .= '</image>' . "\n";
  83.         }
  84.  
  85.         // get RSS channel items
  86. //      $now = date("YmdHis"); // get current time  // configure appropriately to your environment
  87.  
  88.         foreach ($feed as $rss_item) {
  89.             $xml .= '<item>' . "\n";
  90.             $xml .= '<title>' . $rss_item['title'] . '</title>' . "\n";
  91.             $xml .= '<link>' . $rss_item['link'] . '</link>' . "\n";
  92.             $xml .= '<description><![CDATA[' . ($rss_item['description']) . ']]></description>' . "\n";
  93.             $xml .= '<pubDate>' . $rss_item['pubDate'] . '</pubDate>' . "\n";
  94. //          $xml .= '<category>' . $rss_item['category'] . '</category>' . "\n";
  95. //          $xml .= '<source>' . $rss_item['source'] . '</source>' . "\n";
  96.  
  97.             if ($this->full_feed) {
  98.                 $xml .= '<content:encoded>' . $rss_item['content'] . '</content:encoded>' . "\n";
  99.             }
  100.  
  101.             $xml .= '</item>' . "\n";
  102.         }
  103.  
  104.         $xml .= '</channel>';
  105.  
  106.         $xml .= '</rss>';
  107.  
  108.         echo $xml;
  109.     }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment