Example #1
0
 public static function create($url, $xmlConfig = array())
 {
     $document = new Sabel_Xml_Document($xmlConfig);
     self::$documents[] = $document;
     $element = $document->loadXML(file_get_contents($url));
     if ($element === null) {
         // @todo exception?
     }
     switch (strtolower($element->tagName)) {
         case "rdf:rdf":
             return new Sabel_Rss_Reader_Rdf($element);
         case "rss":
             return new Sabel_Rss_Reader_Rss($element);
             break;
         case "feed":
             if ($element->getAttribute("version") === "0.3") {
                 return new Sabel_Rss_Reader_Atom03($element);
             } else {
                 return new Sabel_Rss_Reader_Atom10($element);
             }
             break;
         default:
             $message = "";
             throw new Sabel_Exception_Runtime($message);
     }
 }
Example #2
0
 public function __construct($config = array())
 {
     $this->config = $config;
     if (!defined("RUN_BASE")) {
         throw new Sabel_Exception_Runtime("RUN_BASE can't be undefined");
     }
     $preferencesDir = RUN_BASE . DS . "data" . DS . "preferences";
     if (isset($this->config["file"])) {
         $file = $this->config["file"];
         if (strpos($file, ".") === false) {
             $file .= ".xml";
         }
         if (isset($config["absolute"])) {
             $this->filepath = $file;
         } else {
             $this->filepath = $preferencesDir . DS . $file;
         }
     }
     if ($this->filepath === null) {
         $this->filepath = $preferencesDir . DS . "default.xml";
     }
     if (dirname($this->filepath) !== "." && !is_dir(dirname($this->filepath))) {
         if (!mkdir(dirname($this->filepath), 0755)) {
             throw new Sabel_Exception_Runtime("can't make directory " . dirname($this->filepath) . " check configuration");
         }
     }
     if (!is_readable($this->filepath)) {
         if (!touch($this->filepath, 0644)) {
             throw new Sabel_Exception_Runtime("can't create " . $this->filepath . " check configuration");
         }
         file_put_contents($this->filepath, '<?xml version="1.0" encoding="utf-8"?><preferences/>');
     }
     $this->document = Sabel_Xml_Document::create();
     $this->rootNode = $this->document->load("XML", $this->filepath);
 }
Example #3
0
 protected static function load($contents, $xmlConfig)
 {
     $document = Sabel_Xml_Document::create($xmlConfig);
     $element = $document->loadXML($contents);
     if ($element === null) {
         $message = __METHOD__ . "() invalid xml.";
         throw new Sabel_Exception_Runtime($message);
     }
     switch (strtolower($element->tagName)) {
         case "rdf:rdf":
             return new Sabel_Rss_Reader_Rdf($element);
         case "rss":
             return new Sabel_Rss_Reader_Rss($element);
             break;
         case "feed":
             if ($element->getAttribute("version") === "0.3") {
                 return new Sabel_Rss_Reader_Atom03($element);
             } else {
                 return new Sabel_Rss_Reader_Atom10($element);
             }
             break;
         default:
             $message = __METHOD__ . "() unknown feed format.";
             throw new Sabel_Exception_Runtime($message);
     }
 }
Example #4
0
 public function __construct(array $info)
 {
     $this->info = $info;
     $arg = array();
     if (array_isset("xmlVersion", $info)) {
         $arg["version"] = $info["xmlVersion"];
     }
     if (array_isset("encoding", $info)) {
         $arg["encoding"] = $info["encoding"];
     }
     $this->document = Sabel_Xml_Document::create($arg);
 }
Example #5
0
 protected function _installAddon($name, $xml)
 {
     $doc = new Sabel_Xml_Document();
     $root = $doc->loadXML($xml);
     if ($error = $root->getChild("error")) {
         $this->error($error->getNodeValue());
         $this->error("install failed.");
         return;
     }
     $version = $root->getChild("version")->getNodeValue();
     $addonName = ucfirst($name);
     $className = $addonName . "_Addon";
     if (class_exists($className, true)) {
         eval('$v = ' . $className . '::VERSION;');
         if ($v === (double) $version) {
             $this->message("{$addonName}_{$version} already installed.");
             return;
         } elseif ((double) $version > $v) {
             $_v = strpos($v, ".") === false ? "{$v}.0" : $v;
             $this->message("upgrade " . $addonName . " from {$_v} to {$version}.");
         } else {
             $this->message("nothing to install.");
             return;
         }
     }
     $files = $root->getChildren("file");
     foreach ($files as $i => $file) {
         $path = $file->getChild("path")->getNodeValue();
         $path = str_replace(":", DS, $path);
         $source = $file->getChild("source")->getNodeValue();
         if (!$this->fs->isFile($path)) {
             $this->fs->mkfile($path)->write($source)->save();
         } else {
             $this->fs->getFile($path)->write($source)->save();
         }
         $this->success($path);
     }
     $this->success("install ok: {$addonName}_{$version}");
 }
Example #6
0
 protected function _installAddon($name, $response)
 {
     if (substr($response, 0, 5) === "HEAD:") {
         return $this->installAddon($name, trim(substr($response, 5)));
     }
     $addon = Sabel_Xml_Document::create()->loadXML($response);
     if ($addon->tagName !== "addon") {
         $this->error("addon '{$name}' not found.");
         exit;
     }
     $name = $addon->at("name");
     $version = $addon->at("version");
     $files = $this->getAddonsFiles($addon);
     if (!isset($files["Addon.php"])) {
         $message = __METHOD__ . "() invalid addon. Addon.php not exists.";
     }
     $addonClass = ucfirst($name) . "_Addon";
     if (class_exists($addonClass, true)) {
         $v = constant($addonClass . "::VERSION");
         if ($v === (double) $version) {
             $this->message("{$name}_{$version} already installed.");
             return;
         } elseif ((double) $version > $v) {
             $_v = strpos($v, ".") === false ? "{$v}.0" : $v;
             $this->message("upgrade {$name} from {$_v} => {$version}.");
         } else {
             $this->message("nothing to install.");
             return;
         }
     }
     $fs = new Sabel_Util_FileSystem(RUN_BASE);
     foreach ($files as $path => $file) {
         $path = str_replace("/", DS, $path);
         if ($file["backup"] && $fs->isFile($path)) {
             $oldFile = $path . ".old";
             $fs->getFile($path)->copyTo(RUN_BASE . DS . $oldFile);
             $this->message("{$path} saved as {$oldFile}");
         }
         if (!$fs->isFile($path)) {
             $fs->mkfile($path)->write($file["source"])->save();
         } else {
             $fs->getFile($path)->write($file["source"])->save();
         }
         $this->success($path);
     }
     $this->success("install ok: {$name}_{$version}");
 }
Example #7
0
 protected function saveXML(Sabel_Xml_Document $xml, $name = "_tmp")
 {
     return $xml->saveXML(XML_TEST_DIR . DS . "xml" . DS . $name . ".xml");
 }