Ejemplo n.º 1
0
 /**
  * Return true if the content filtering is enabled.
  *
  * @return bool
  */
 public function isFilteringEnabled()
 {
     if ($this->config === null) {
         return $this->enable_filter;
     }
     return $this->config->getContentFiltering($this->enable_filter);
 }
Ejemplo n.º 2
0
 /**
  * Get the list of folders that contains rules.
  *
  * @return array
  */
 public function getRulesFolders()
 {
     $folders = array(__DIR__ . '/../Rules');
     if ($this->config !== null && $this->config->getGrabberRulesFolder() !== null) {
         $folders[] = $this->config->getGrabberRulesFolder();
     }
     return $folders;
 }
Ejemplo n.º 3
0
 /**
  * Get a parser instance.
  *
  * @param string $url      Site url
  * @param string $content  Feed content
  * @param string $encoding HTTP encoding
  *
  * @return \AsteFeed\Parser\Parser
  */
 public function getParser($url, $content, $encoding)
 {
     $format = $this->detectFormat($content);
     if (empty($format)) {
         throw new UnsupportedFeedFormatException('Unable to detect feed format');
     }
     $className = '\\AsteFeed\\Parser\\' . $format;
     $parser = new $className($content, $encoding, $url);
     $parser->setHashAlgo($this->config->getParserHashAlgo());
     $parser->setTimezone($this->config->getTimezone());
     $parser->setConfig($this->config);
     return $parser;
 }
Ejemplo n.º 4
0
 /**
  * Set config object.
  *
  * @param \AsteFeed\Config\Config $config Config instance
  *
  * @return \AsteFeed\Filter\Html
  */
 public function setConfig($config)
 {
     $this->config = $config;
     if ($this->config !== null) {
         $this->attribute->setImageProxyCallback($this->config->getFilterImageProxyCallback());
         $this->attribute->setImageProxyUrl($this->config->getFilterImageProxyUrl());
         $this->attribute->setImageProxyProtocol($this->config->getFilterImageProxyProtocol());
         $this->attribute->setIframeWhitelist($this->config->getFilterIframeWhitelist(array()));
         $this->attribute->setIntegerAttributes($this->config->getFilterIntegerAttributes(array()));
         $this->attribute->setAttributeOverrides($this->config->getFilterAttributeOverrides(array()));
         $this->attribute->setRequiredAttributes($this->config->getFilterRequiredAttributes(array()));
         $this->attribute->setMediaBlacklist($this->config->getFilterMediaBlacklist(array()));
         $this->attribute->setMediaAttributes($this->config->getFilterMediaAttributes(array()));
         $this->attribute->setSchemeWhitelist($this->config->getFilterSchemeWhitelist(array()));
         $this->attribute->setWhitelistedAttributes($this->config->getFilterWhitelistedTags(array()));
         $this->tag->setWhitelistedTags(array_keys($this->config->getFilterWhitelistedTags(array())));
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * Download the HTML content.
  *
  * @return bool
  */
 public function download()
 {
     if (!empty($this->url)) {
         // Clear everything
         $this->html = '';
         $this->content = '';
         $this->encoding = '';
         try {
             $client = Client::getInstance();
             $client->setConfig($this->config);
             $client->setTimeout($this->config->getGrabberTimeout());
             $client->setUserAgent($this->config->getGrabberUserAgent());
             $client->execute($this->url);
             $this->url = $client->getUrl();
             $this->html = $client->getContent();
             $this->encoding = $client->getEncoding();
             return true;
         } catch (ClientException $e) {
             Logger::setMessage(get_called_class() . ': ' . $e->getMessage());
         }
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * Check if a tag is on the whitelist.
  *
  * @param string $tag Tag name
  *
  * @return bool
  */
 public function isAllowedTag($tag)
 {
     return in_array($tag, array_merge($this->tag_whitelist, array_keys($this->config->getFilterWhitelistedTags(array()))));
 }
Ejemplo n.º 7
0
 /**
  * Set config object.
  *
  * @param \AsteFeed\Config\Config $config Config instance
  *
  * @return \AsteFeed\Client\Client
  */
 public function setConfig(Config $config)
 {
     if ($config !== null) {
         $this->setTimeout($config->getClientTimeout());
         $this->setUserAgent($config->getClientUserAgent());
         $this->setMaxRedirections($config->getMaxRedirections());
         $this->setMaxBodySize($config->getMaxBodySize());
         $this->setProxyHostname($config->getProxyHostname());
         $this->setProxyPort($config->getProxyPort());
         $this->setProxyUsername($config->getProxyUsername());
         $this->setProxyPassword($config->getProxyPassword());
     }
     return $this;
 }