Esempio n. 1
0
 /**
  * Parse XML into array
  */
 protected function _parse()
 {
     if (empty($this->xml->module)) {
         return;
     }
     foreach ($this->xml->module as $i) {
         $attrs = $i->attributes();
         $item = array();
         # DC/DA shared markers
         $item['id'] = (string) $attrs['id'];
         $item['file'] = (string) $i->file;
         $item['label'] = (string) $i->name;
         // deprecated
         $item['name'] = (string) $i->name;
         $item['version'] = (string) $i->version;
         $item['author'] = (string) $i->author;
         $item['desc'] = (string) $i->desc;
         # DA specific markers
         $item['dc_min'] = (string) $i->children(self::$bloc)->dcmin;
         $item['details'] = (string) $i->children(self::$bloc)->details;
         $item['section'] = (string) $i->children(self::$bloc)->section;
         $item['support'] = (string) $i->children(self::$bloc)->support;
         $item['sshot'] = (string) $i->children(self::$bloc)->sshot;
         $tags = array();
         foreach ($i->children(self::$bloc)->tags as $t) {
             $tags[] = (string) $t->tag;
         }
         $item['tags'] = implode(', ', $tags);
         # First filter right now. If DC_DEV is set all modules are parse
         if (defined('DC_DEV') && DC_DEV === true || dcUtils::versionsCompare(DC_VERSION, $item['dc_min'], '>=', false)) {
             $this->items[$item['id']] = $item;
         }
     }
 }
Esempio n. 2
0
 /**
  * Check repository.
  *
  * @param	boolean	$force		Force query repository
  * @return	boolean	True if get feed or cache
  */
 public function check($force = false)
 {
     if (!$this->xml_url) {
         return false;
     }
     if (($parser = dcStoreReader::quickParse($this->xml_url, DC_TPL_CACHE, $force)) === false) {
         return false;
     }
     $raw_datas = $parser->getModules();
     uasort($raw_datas, array('self', 'sort'));
     $skipped = array_keys($this->modules->getDisabledModules());
     foreach ($skipped as $p_id) {
         if (isset($raw_datas[$p_id])) {
             unset($raw_datas[$p_id]);
         }
     }
     $updates = array();
     $current = $this->modules->getModules();
     foreach ($current as $p_id => $p_infos) {
         if (isset($raw_datas[$p_id])) {
             if (dcUtils::versionsCompare($raw_datas[$p_id]['version'], $p_infos['version'], '>')) {
                 $updates[$p_id] = $raw_datas[$p_id];
                 $updates[$p_id]['root'] = $p_infos['root'];
                 $updates[$p_id]['root_writable'] = $p_infos['root_writable'];
                 $updates[$p_id]['current_version'] = $p_infos['version'];
             }
             unset($raw_datas[$p_id]);
         }
     }
     $this->data = array('new' => $raw_datas, 'update' => $updates);
     return true;
 }
Esempio n. 3
0
 public static function installPackage($zip_file, dcModules &$modules)
 {
     $zip = new fileUnzip($zip_file);
     $zip->getList(false, '#(^|/)(__MACOSX|\\.svn|\\.hg|\\.git|\\.DS_Store|\\.directory|Thumbs\\.db)(/|$)#');
     $zip_root_dir = $zip->getRootDir();
     $define = '';
     if ($zip_root_dir != false) {
         $target = dirname($zip_file);
         $destination = $target . '/' . $zip_root_dir;
         $define = $zip_root_dir . '/_define.php';
         $has_define = $zip->hasFile($define);
     } else {
         $target = dirname($zip_file) . '/' . preg_replace('/\\.([^.]+)$/', '', basename($zip_file));
         $destination = $target;
         $define = '_define.php';
         $has_define = $zip->hasFile($define);
     }
     if ($zip->isEmpty()) {
         $zip->close();
         unlink($zip_file);
         throw new Exception(__('Empty module zip file.'));
     }
     if (!$has_define) {
         $zip->close();
         unlink($zip_file);
         throw new Exception(__('The zip file does not appear to be a valid Dotclear module.'));
     }
     $ret_code = 1;
     if (!is_dir($destination)) {
         try {
             files::makeDir($destination, true);
             $sandbox = clone $modules;
             $zip->unzip($define, $target . '/_define.php');
             $sandbox->resetModulesList();
             $sandbox->requireDefine($target, basename($destination));
             unlink($target . '/_define.php');
             $new_errors = $sandbox->getErrors();
             if (!empty($new_errors)) {
                 $new_errors = is_array($new_errors) ? implode(" \n", $new_errors) : $new_errors;
                 throw new Exception($new_errors);
             }
             files::deltree($destination);
         } catch (Exception $e) {
             $zip->close();
             unlink($zip_file);
             files::deltree($destination);
             throw new Exception($e->getMessage());
         }
     } else {
         # test for update
         $sandbox = clone $modules;
         $zip->unzip($define, $target . '/_define.php');
         $sandbox->resetModulesList();
         $sandbox->requireDefine($target, basename($destination));
         unlink($target . '/_define.php');
         $new_modules = $sandbox->getModules();
         if (!empty($new_modules)) {
             $tmp = array_keys($new_modules);
             $id = $tmp[0];
             $cur_module = $modules->getModules($id);
             if (!empty($cur_module) && (defined('DC_DEV') && DC_DEV === true || dcUtils::versionsCompare($new_modules[$id]['version'], $cur_module['version'], '>', true))) {
                 # delete old module
                 if (!files::deltree($destination)) {
                     throw new Exception(__('An error occurred during module deletion.'));
                 }
                 $ret_code = 2;
             } else {
                 $zip->close();
                 unlink($zip_file);
                 throw new Exception(sprintf(__('Unable to upgrade "%s". (older or same version)'), basename($destination)));
             }
         } else {
             $zip->close();
             unlink($zip_file);
             throw new Exception(sprintf(__('Unable to read new _define.php file')));
         }
     }
     $zip->unzipAll($target);
     $zip->close();
     unlink($zip_file);
     return $ret_code;
 }