/** * Traverses Files and Directories inside given path Recursively * @param $path to traverse */ public function traverseDirFiles($path) { $dir = opendir($path); $files = array(); $f = array(); $skip = array(Fox::getDirectoryPath() . DS . "var", Fox::getDirectoryPath() . DS . "library" . DS . "Zend", Fox::getExtensionDirectoryPath(), Fox::getDirectoryPath() . DS . "theme" . DS . "installer", APPLICATION_PATH . DS . "views" . DS . "installer"); while ($ft = readdir($dir)) { if (in_array($ft, array(".", "..")) || in_array($path . DS . $ft, $skip)) { continue; } $f[] = $ft; } sort($f); foreach ($f as $file) { if (filetype($path . DS . $file) != "dir") { $files[] = $file; } else { $this->traverseDirFiles($path . DS . $file); } } foreach ($files as $f) { $this->processFiles($path, $f); } closedir($dir); }
/** * Uninstall package * * @param string $key valid package key */ public function uninstallPackage($key) { $config = $this->getConfig(); if (!file_exists($config->getInstalledPkgPath() . DS . $key . '.xml')) { throw new Exception("Installation not found."); } $this->setStatus(Fox_Extensionmanager_Model_Package_Status::UNINSTALLING); $packageXml = $config->getInstalledPkgPath() . DS . $key . '.xml'; $document = new Uni_Data_XDOMDocument(); $document->load($packageXml); /*removing package files*/ $xpath = new DomXpath($document); foreach ($xpath->query('//item[@rel="file"]') as $file) { $filePath = Fox::getDirectoryPath() . $file->getAttribute("path"); if (file_exists($filePath) && !is_dir($filePath)) { try { @unlink($filePath); } catch (Exception $e) { } } } /*listing directories to remove*/ $dirs = array(); foreach ($xpath->query('//item[@rel="dir"]') as $file) { $dirPath = Fox::getDirectoryPath() . $file->getAttribute("path"); if (file_exists($dirPath) && is_dir($dirPath)) { try { $dirs[] = $dirPath; } catch (Exception $e) { } } } /*removing empty directories in $dir list*/ if ($dirs) { $dirs = array_reverse($dirs); foreach ($dirs as $dir) { @rmdir($dir); } } /*removing package from installed directory*/ @unlink($packageXml); $this->clearCache(); $this->setStatus(Fox_Extensionmanager_Model_Package_Status::UNINSTALLED); }
/** * Get Xml of site directories/files * * @param bool $cache if true gets xml from cache otherwise regenerates * @return string xml string */ public function getSiteXml($cache = true) { $xml = ''; $conf = $this->getConfig()->getConfiguration(); $cachePath = Fox::getExtensionDirectoryPath() . DS . $conf->extensionmanager->dir_name . DS . $conf->extensionmanager->cache; if (!file_exists($cachePath)) { @mkdir($cachePath, 0777, true); } $fileName = $cachePath . DS . $conf->extensionmanager->cache_file; if ($cache && file_exists($fileName)) { $xml = file_get_contents($fileName); } else { $path = Fox::getDirectoryPath(); $Obj = new Fox_Extensionmanager_Model_Generate_DirectoryToXml($path); $Obj->traverseDirFiles($path); $Obj->setArray($Obj->arr); if (!($xml = $Obj->saveArrayToXml())) { throw new Exception("Unable to load content tree data."); } $dom = $Obj->getXMLDom(); $dom->save($fileName); @chmod($fileName, 0777); } return trim(preg_replace('/<\\?xml.*\\?>/', '', $xml, 1)); }