예제 #1
0
    /**
     * Take a local channel.xml and parse it.
     * @param string file name, or xml string
     */
    function __construct($file, $isxml = false, $isremote = false)
    {
        $this->path = $file;
        $parser = new ChannelFile\Parser\v1;
        if ($isxml) {
            $data = $file;
        } elseif ($isremote) {
            if (strpos($file, 'http://') === 0 || strpos($file, 'https://') === 0) {
                $data = $this->_fromURL($file);
            } else {
                try {
                    $xml_url = 'https://' . $file . '/channel.xml';
                    $data = $this->_fromURL($xml_url);
                } catch (\Exception $e) {
                    // try insecure
                    try {
                        $xml_url = 'http://' . $file . '/channel.xml';
                        $data = $this->_fromURL($xml_url);
                    } catch (\Exception $e2) {
                        // failed, re-throw original error
                        throw $e;
                    }
                }
            }
        } else {
            $data = @file_get_contents($file);
        }

        if ($data === false || empty($data)) {
            throw new ChannelFile\Exception('Unable to open channel xml file '
                . $file . ' or file was empty.');
        }

        $this->info = $parser->parse($data);
    }
예제 #2
0
 /**
  * Take a local channel.xml and parse it.
  * @param string file name, or xml string
  */
 function __construct($file, $isxml = false, $isremote = false)
 {
     $this->path = $file;
     $parser = new ChannelFile\Parser\v1();
     if ($isxml) {
         $data = $file;
     } elseif ($isremote) {
         if (strpos($file, 'http://') === 0 || strpos($file, 'https://') === 0) {
             $data = $this->_fromURL($file);
         } else {
             try {
                 $xml_url = 'https://' . $file . '/channel.xml';
                 $data = $this->_fromURL($xml_url);
             } catch (\Exception $e) {
                 // try insecure
                 try {
                     $xml_url = 'http://' . $file . '/channel.xml';
                     $data = $this->_fromURL($xml_url);
                 } catch (\Exception $e2) {
                     // failed, re-throw original error
                     throw $e;
                 }
             }
         }
     } else {
         // Add extra check because of allow_url_fopen
         $schema = strtolower(parse_url($file, PHP_URL_SCHEME));
         $data = !in_array($schema, array('https', 'http', 'ftp', 'sftp')) ? @file_get_contents($file) : false;
     }
     if ($data === false || empty($data)) {
         throw new ChannelFile\Exception('Unable to open channel xml file ' . $file . ' or file was empty.');
     }
     $this->info = $parser->parse($data);
 }
예제 #3
0
파일: ChannelFile.php 프로젝트: helgi/Pyrus
 /**
  * Take a local channel.xml and parse it.
  * @param string file name, or xml string
  */
 function __construct($file)
 {
     if (is_string($file)) {
         $file = trim($file);
     }
     $data = false;
     $this->path = $file;
     $parser = new ChannelFile\Parser\v1();
     if (is_string($file) && substr($file, 0, 5) === '<?xml') {
         $data = $file;
     } elseif (is_string($file) && file_exists($file)) {
         // Local
         $data = $file;
     } elseif (is_string($file)) {
         if (strpos($file, 'http://') === 0 || strpos($file, 'https://') === 0) {
             $data = $this->_fromURL($file);
         } else {
             try {
                 $xml_url = 'https://' . $file . '/channel.xml';
                 $data = $this->_fromURL($xml_url);
             } catch (\Exception $e) {
                 // try insecure
                 try {
                     $xml_url = 'http://' . $file . '/channel.xml';
                     $data = $this->_fromURL($xml_url);
                 } catch (\Exception $e2) {
                     // failed, re-throw original error
                     throw $e;
                 }
             }
         }
     }
     if ($data === false || empty($data)) {
         throw new ChannelFile\Exception('Unable to open channel xml file ' . $file . ' or file was empty.');
     }
     $this->info = $parser->parse($data);
 }