/** * RssFeed constructor. * @param $url_or_file */ function __construct($url_or_file) { $this->url = $this->resolveFile($url_or_file); //DEBUG--------- //$this->url = $url_or_file; //$xmlFile = simplexml_load_file($this->url); //----------DEBUG //echo '<br/>' . $this->url . '<br/>'; if (!($xmlFile = simplexml_load_file($this->url))) { return; } $data = $xmlFile->channel; foreach ($data->item as $item) { $post = new RSSPost(); if (isset($item->link)) { $post->setLink($item->link); } if (isset($item->title)) { $post->setTitle($item->title); } if (isset($item->pubDate)) { $post->setPubDate($item->pubDate); } if (isset($item->description)) { $post->setDescription($item->description); } if (isset($item->guid)) { $post->setGuid($item->guid); } if (isset($item->author)) { $post->setAuthor($item->author); } if (isset($item->category)) { $post->setCategory($item->category); } $post->summarizeText(100); $this->rssPosts[] = $post; } }
/** * RssFeed constructor. * @param $url_or_file */ public function __construct($account) { $url = 'https://twitrss.me/twitter_user_to_rss/?user='******'&replies=on'; $this->account = $this->resolveFile($url); $saved = libxml_use_internal_errors(true); if (false === ($xmlFile = simplexml_load_file($this->account))) { $errors = libxml_get_errors(); libxml_use_internal_errors($saved); //var_dump($errors); throw new Exception("Unable to process this RSS with url:" . $url, 20001); } foreach ($xmlFile->channel as $data) { if (isset($data->title)) { $this->setTitle('@' . substr($data->title, 17)); } if (isset($data->description)) { $this->summarizeText($data->description); $this->setDescription($data->description); } if (isset($data->link)) { $this->setLink($data->link); } if (isset($data->pubDate)) { $this->setPubDate($data->pubDate); } if (isset($data->lastBuildDate)) { $this->setLastBuildDate($data->lastBuildDate); } if (isset($data->image)) { $this->image = new rssImage(); if (isset($data->image->title)) { $this->image->setTitle($data->image->title); } if (isset($data->image->link)) { $this->image->setUrl($data->image->url); } } if (isset($data->language)) { $this->setLanguage($data->language); } if (isset($data->enclosure)) { $this->setEnclosure($data->enclosure); } foreach ($data->item as $item) { $post = new RSSPost(); if (isset($item->link)) { $post->setLink($item->link); } if (isset($item->title)) { $post->setTitle($item->title); } if (isset($item->pubDate)) { $post->setPubDate($item->pubDate); } if (isset($item->description)) { $post->setDescription($item->description); } if (isset($item->guid)) { $post->setGuid($item->guid); } if (isset($item->author)) { $post->setAuthor($item->author); } if (isset($item->category)) { $post->setCategory($item->category); } if (isset($item->comments)) { $post->setComments($item->comments); } if (isset($item->enclosure) && isset($item->enclosure['url']) && isset($item->enclosure['type'])) { $format = preg_replace('/\\/\\w*/', '', $item->enclosure['type']); try { $enclosure = EnclosureFactorys::getEnclosure($format); if ($enclosure instanceof IEnslosureHandler) { $enclosure->setVariables($item->enclosure['url'], $format); $post->setEnclosure($enclosure); } } catch (Exception $e) { $post->setEnclosure($e->getMessage()); } } $post->summarizeText(100); $this->rssPosts[] = $post; } } }