public function testAdapter() { $tar = false; $includePath = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePath as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) { $tar = true; } } if ($tar) { $a = Archive::factory(__DIR__ . '/../tmp/test.tar'); $this->assertInstanceOf('Pop\\Archive\\Adapter\\Tar', $a->adapter()); $this->assertInstanceOf('Archive_Tar', $a->archive()); $files = $a->listFiles(); $files = $a->listFiles(true); $this->assertTrue(is_array($files)); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } } if (class_exists('ZipArchive', false)) { $a = new Archive('test.zip'); $this->assertInstanceOf('Pop\\Archive\\Adapter\\Zip', $a->adapter()); $this->assertInstanceOf('ZipArchive', $a->archive()); } }
/** * Instantiate an archive adapter object * * @param \Pop\Archive\Archive $archive * @param string $password * @throws Exception * @return Rar */ public function __construct(\Pop\Archive\Archive $archive, $password = null) { $this->path = $archive->getFullpath(); $this->password = $password; if (file_exists($this->path)) { $this->archive = \RarArchive::open($this->path, $this->password); } else { throw new Exception('Due to licensing restrictions, RAR files cannot be created and can only be extracted.'); } }
/** * Method to instantiate an archive adapter object * * @param \Pop\Archive\Archive $archive * @return \Pop\Archive\Adapter\Tar */ public function __construct(\Pop\Archive\Archive $archive) { if (stripos($archive->getExt(), 'bz') !== false) { $this->compression = 'bz'; } else { if (stripos($archive->getExt(), 'gz') !== false) { $this->compression = 'gz'; } } $this->path = $archive->getFullpath(); $this->archive = new \Archive_Tar($this->path); }
public function testBzip2WithTarFile() { $tar = false; $includePath = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePath as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) { $tar = true; } } if ($tar && function_exists('bzopen')) { $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $compressed = Bzip2::compress(__DIR__ . '/../tmp/test.tar'); copy($compressed, __DIR__ . '/../tmp/test.tbz2'); copy($compressed, __DIR__ . '/../tmp/test.tbz'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); $this->fileExists(__DIR__ . '/../tmp/test.tar.bz2'); $this->fileExists(__DIR__ . '/../tmp/test.tbz2'); $this->fileExists(__DIR__ . '/../tmp/test.tbz'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } // Test *.tar.bz2 $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tar.bz2'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tar.bz2')) { unlink(__DIR__ . '/../tmp/test.tar.bz2'); } // Test *.tbz2 $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tbz2'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tbz2')) { unlink(__DIR__ . '/../tmp/test.tbz2'); } // Test *.tbz $decompressed = Bzip2::decompress(__DIR__ . '/../tmp/test.tbz'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } if (file_exists(__DIR__ . '/../tmp/test.tbz')) { unlink(__DIR__ . '/../tmp/test.tbz'); } } }
public function testZipExtract() { if (class_exists('ZipArchive', false)) { $a = new Archive(__DIR__ . '/../tmp/test.zip'); $a->addFiles(__DIR__ . '/../tmp'); mkdir(__DIR__ . '/../tmp/test'); chmod(__DIR__ . '/../tmp/test', 0777); chmod(__DIR__ . '/../tmp/test.zip', 0777); $a->extract(__DIR__ . '/../tmp/test'); unset($a); $dir = new Dir(__DIR__ . '/../tmp/test'); $this->assertGreaterThan(0, count($dir->getFiles())); $dir->emptyDir(); rmdir(__DIR__ . '/../tmp/test'); if (file_exists(__DIR__ . '/../tmp/test.zip')) { unlink(__DIR__ . '/../tmp/test.zip'); } } }
/** * Perform update * * @return void */ protected function update() { echo 'System Update' . PHP_EOL; echo '-------------' . PHP_EOL; echo PHP_EOL; if (!isset($this->args[2])) { $this->argNotFound('update'); } else { if (!in_array($this->args[2], $this->arguments['update'])) { $this->argInvalid('update', $this->args[2]); } else { $type = $this->args[2]; $name = isset($this->args[3]) ? $this->args[3] : 'phire'; $version = null; if ($type == 'system') { $version = \Phire\Project::VERSION; } else { $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } $format = null; $formats = \Pop\Archive\Archive::formats(); if (isset($formats['zip'])) { $format = 'zip'; } else { if (isset($formats['tar']) && isset($formats['gz'])) { $format = 'tar.gz'; } } $writable = false; if ($type == 'system' && is_writable(__DIR__ . '/../../../../')) { $writable = true; } else { if ($type == 'module' && is_writable(__DIR__ . '/../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules')) { $writable = true; } } if ($writable) { $config = new Model\Config(); $config->getUpdate(array('type' => $type, 'name' => $name, 'version' => $version, 'format' => $format), true); if (null !== $config->error) { echo ' ' . strip_tags($config->error) . PHP_EOL . PHP_EOL; } else { echo ' ' . strip_tags($config->msg) . PHP_EOL . PHP_EOL; } } else { echo ' The ' . $type . ' folder must be writable to perform the update.' . PHP_EOL . PHP_EOL; } } } }
<?php require_once '../../bootstrap.php'; use Pop\Archive\Archive; try { // Create a new ZIP archive and add some files to it // (Make sure the '../tmp' folder is writable) $archive = new Archive('../tmp/test.zip'); $archive->addFiles('../assets'); // Display the new archive file size echo $archive->getBasename() . ': compressed file size => ' . $archive->getSize() . '<br /> ' . PHP_EOL; echo 'Done.'; } catch (\Exception $e) { echo $e->getMessage() . PHP_EOL . PHP_EOL; }
/** * Instantiate an archive adapter object * * @param \Pop\Archive\Archive $archive * @return Zip */ public function __construct(\Pop\Archive\Archive $archive) { if (strpos($archive->getFullpath(), '/.') !== false) { $this->workingDir = substr($archive->getFullpath(), 0, strpos($archive->getFullpath(), '/.')); } else { if (strpos($archive->getFullpath(), '\\.') !== false) { $this->workingDir = substr($archive->getFullpath(), 0, strpos($archive->getFullpath(), '\\.')); } else { $this->workingDir = getcwd(); } } if (substr($archive->getFullpath(), 0, 1) != '/' && substr($archive->getFullpath(), 1, 1) != ':') { $this->path = $this->workingDir . DIRECTORY_SEPARATOR . $archive->getFullpath(); } else { $this->path = realpath(dirname($archive->getFullpath())) . DIRECTORY_SEPARATOR . $archive->getBasename(); } $this->archive = new \ZipArchive(); }
/** * batch action method * * @param int $lid * @return void */ public function batch($lid) { $library = new Model\MediaLibrary(); $library->getById($lid); if (!isset($library->id)) { $this->redirect(BASE_PATH . APP_URI . '/media'); } $browser = new Browser(); $dragAndDrop = !($browser->isMsie() && $browser->getVersion() <= 9); if (null !== $this->request->getQuery('basic') && $this->request->getQuery('basic')) { $this->prepareView('media/batch.phtml'); $this->view->title = 'Media : ' . $library->name . ' : Batch Upload'; $this->view->lid = $lid; $this->view->max = $library->getMaxFilesize(); $this->view->dragAndDrop = $dragAndDrop; $fields = $this->application->config()['forms']['Phire\\Media\\Form\\Batch']; $fields[0]['library_id']['value'] = $lid; $fields[2]['batch_archive']['label'] = 'Batch Archive File <span class="batch-formats">(' . implode(', ', array_keys(\Pop\Archive\Archive::getFormats())) . ')</span>'; $fields[2]['batch_archive']['validators'] = new \Pop\Validator\RegEx('/^.*\\.(' . implode('|', array_keys(\Pop\Archive\Archive::getFormats())) . ')$/i', 'That file archive type is not allowed.'); $this->view->form = new Form\Batch($fields); if ($this->request->isPost()) { $settings = $library->getSettings(); $folder = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder; if (!file_exists($folder)) { $library->createFolder($library->folder); } $values = !empty($_FILES['file_1']) && !empty($_FILES['file_1']['name']) ? array_merge($this->request->getPost(), ['file_1' => $_FILES['file_1']['name']]) : $this->request->getPost(); $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($values, $settings); if ($this->view->form->isValid()) { $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter(); $media = new Model\Media(); $media->batch($_FILES, $this->view->form->getFields()); $this->view->id = $media->ids; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/media/' . $lid . '?basic=1'); } } } else { if (!$dragAndDrop) { $this->redirect(BASE_PATH . APP_URI . '/media/batch/' . $lid . '?basic=1'); } else { $this->prepareView('media/batch-ajax.phtml'); $this->view->title = 'Media : ' . $library->name . ' : Batch Upload'; $this->view->lid = $lid; $this->view->max = $library->getMaxFilesize(); $this->view->categoriesForBatch = null; if (class_exists('Phire\\Categories\\Model\\Category')) { $config = $this->application->module('phire-categories'); $cat = new \Phire\Categories\Model\Category([], $config); $cat->getAll(); if (count($cat->getFlatMap()) > 0) { $categoryValues = $cat->getCategoryValues(); $categories = new \Pop\Form\Element\CheckboxSet('categories', $categoryValues); $categories->setLabel('Categories'); $this->view->categoriesForBatch = $categories; } } } } $this->send(); }
/** * Upload template * * @param array $file * @return void */ public function upload($file) { $templatePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/templates'; if (!file_exists($templatePath)) { mkdir($templatePath); chmod($templatePath, 0777); if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html')) { copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html', $templatePath . '/index.html'); chmod($templatePath . '/index.html', 0777); } } $upload = new Upload($templatePath); $template = $upload->upload($file); $formats = Archive::getFormats(); if (file_exists($templatePath . '/' . $template)) { $ext = null; $name = null; if (substr($template, -4) == '.zip') { $ext = 'zip'; $name = substr($template, 0, -4); } else { if (substr($template, -4) == '.tgz') { $ext = 'tgz'; $name = substr($template, 0, -4); } else { if (substr($template, -7) == '.tar.gz') { $ext = 'tar.gz'; $name = substr($template, 0, -7); } } } if (null !== $ext && null !== $name && array_key_exists($ext, $formats)) { $archive = new Archive($templatePath . '/' . $template); $archive->extract($templatePath); if (stripos($template, 'gz') !== false && file_exists($templatePath . '/' . $name . '.tar')) { unlink($templatePath . '/' . $name . '.tar'); } if (file_exists($templatePath . '/' . $name)) { $dir = new Dir($templatePath . '/' . $name, ['filesOnly' => true]); foreach ($dir->getFiles() as $file) { if (substr($file, -5) == '.html') { $isVisible = stripos($file, 'category') === false && stripos($file, 'error') === false && stripos($file, 'tag') === false && stripos($file, 'search') === false && stripos($file, 'sidebar') === false && stripos($file, 'header') === false && stripos($file, 'footer') === false; $template = new Table\Templates(['parent_id' => null, 'name' => ucwords(str_replace(['-', '_'], [' ', ' '], substr(strtolower($file), 0, -5))), 'device' => 'desktop', 'template' => file_get_contents($templatePath . '/' . $name . '/' . $file), 'history' => null, 'visible' => (int) $isVisible]); $template->save(); } } } } } }
/** * Config update method * * @return void */ public function update() { $this->prepareView('update.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'))); if (null !== $this->request->getQuery('module')) { $type = 'module'; $name = $this->request->getQuery('module'); $version = null; $title = $this->view->i18n->__('Module Update') . ' ' . $this->view->separator . ' ' . $name; $linkParam = '&module=' . $name; $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } else { if (null !== $this->request->getQuery('theme')) { $type = 'theme'; $name = $this->request->getQuery('theme'); $version = null; $title = $this->view->i18n->__('Theme Update') . ' ' . $this->view->separator . ' ' . $name; $linkParam = '&theme=' . $name; $ext = Table\Extensions::findBy(array('name' => $name)); if (isset($ext->id)) { $assets = unserialize($ext->assets); $version = $assets['info']['Version']; } } else { $type = 'system'; $name = 'phire'; $version = \Phire\Project::VERSION; $title = $this->view->i18n->__('System Update'); $linkParam = null; } } $format = null; $formats = \Pop\Archive\Archive::formats(); if (isset($formats['zip'])) { $format = 'zip'; } else { if (isset($formats['tar']) && isset($formats['gz'])) { $format = 'tar.gz'; } } $this->view->set('title', $this->view->i18n->__('Configuration') . ' ' . $this->view->separator . ' ' . $title); $config = new Model\Config(); $writable = false; if ($type == 'system' && is_writable(__DIR__ . '/../../../../../../../')) { $writable = true; } else { if ($type == 'module' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules')) { $writable = true; } else { if ($type == 'theme' && is_writable(__DIR__ . '/../../../../../../../../' . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes')) { $writable = true; } } } if ($writable) { if (null !== $this->request->getQuery('writable')) { $config->getUpdate(array('type' => $type, 'name' => $name, 'version' => $version, 'format' => $format)); if (null !== $config->error) { $this->view->set('msg', $config->error); $this->send(); } else { $this->view->set('msg', $config->msg); $this->send(); } } else { $link = $this->request->getFullUri() . '?writable=1' . $linkParam; $form = '<div id="update-form">' . $this->view->i18n->__('The %1 folder has been detected as writable.', $type) . ' ' . $this->view->i18n->__('You can proceed with the %1 update by clicking the update button below.', $type) . '<br /><br /><a href="' . $link . '" class="save-btn" style="display: block; width: 220px; height: 20px; color: #fff; text-decoration: none;">' . $this->view->i18n->__('UPDATE') . '</a></div>'; $this->view->set('form', $form); $this->send(); } } else { $form = new Form\Update($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $type, $name, $version, $format); if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('htmlentities' => array(ENT_QUOTES, 'UTF-8'))); if ($form->isValid()) { $config->getUpdate($this->request->getPost()); if (null !== $config->error) { $this->view->set('msg', $config->error); $this->send(); } else { $this->view->set('msg', $config->msg); $this->send(); } } else { $this->view->set('form', $form); $this->send(); } } else { $this->view->set('form', $form); $this->send(); } } }
/** * Method to get update for one-click update * * @param string $module * @param string $new * @param string $old * @param int $id * @return void */ public function getUpdate($module = null, $new = null, $old = null, $id = null) { if (null === $module) { if (file_exists(CONTENT_ABS_PATH . '/assets/phire')) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/phire'); $dir->emptyDir(true); } if (file_exists(CONTENT_ABS_PATH . '/assets/default')) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/default'); $dir->emptyDir(true); } if (file_exists(CONTENT_ABS_PATH . '/assets/default-flat')) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-flat'); $dir->emptyDir(true); } if (file_exists(CONTENT_ABS_PATH . '/assets/default-top')) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-top'); $dir->emptyDir(true); } if (file_exists(CONTENT_ABS_PATH . '/assets/default-top-flat')) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-top-flat'); $dir->emptyDir(true); } file_put_contents(CONTENT_ABS_PATH . '/updates/phirecms.zip', fopen('http://updates.phirecms.org/releases/phire/phirecms.zip', 'r')); $basePath = realpath(CONTENT_ABS_PATH . '/updates/'); $archive = new Archive($basePath . '/phirecms.zip'); $archive->extract($basePath); unlink(CONTENT_ABS_PATH . '/updates/phirecms.zip'); $json = json_decode(stream_get_contents(fopen('http://updates.phirecms.org/releases/phire/phire.json', 'r')), true); foreach ($json as $file) { if (!file_exists(__DIR__ . '/../' . $file) && !file_exists(dirname(__DIR__ . '/../' . $file))) { mkdir(dirname(__DIR__ . '/../' . $file), 0755, true); } copy(CONTENT_ABS_PATH . '/updates/phire-cms/' . $file, __DIR__ . '/../' . $file); } $dir = new Dir(CONTENT_ABS_PATH . '/updates/phire-cms/'); $dir->emptyDir(true); } else { if (file_exists(MODULES_ABS_PATH . '/' . $module . '-' . $old . '.zip')) { unlink(MODULES_ABS_PATH . '/' . $module . '-' . $old . '.zip'); } if (file_exists(MODULES_ABS_PATH . '/' . $module . '-' . $old)) { $dir = new Dir(MODULES_ABS_PATH . '/' . $module . '-' . $old); $dir->emptyDir(true); } if (file_exists(CONTENT_ABS_PATH . '/assets/' . $module)) { $dir = new Dir(CONTENT_ABS_PATH . '/assets/' . $module); $dir->emptyDir(true); } file_put_contents(MODULES_ABS_PATH . '/' . $module . '-' . $new . '.zip', fopen('http://updates.phirecms.org/releases/modules/' . $module . '-' . $new . '.zip', 'r')); $basePath = realpath(MODULES_ABS_PATH . '/'); $archive = new Archive($basePath . '/' . $module . '-' . $new . '.zip'); $archive->extract($basePath); $mod = Table\Modules::findById($id); $assets = unserialize($mod->assets); if (isset($assets['info']['version'])) { $assets['info']['version'] = $new; } else { if (isset($assets['info']['Version'])) { $assets['info']['Version'] = $new; } else { if (isset($assets['info']['VERSION'])) { $assets['info']['VERSION'] = $new; } } } $mod->file = $module . '-' . $new . '.zip'; $mod->folder = $module . '-' . $new; $mod->assets = serialize($assets); $mod->save(); } }
/** * Process batch archive file * * @param string $file * @param array $fields * @return void */ public function processBatch($file, array $fields) { $tmp = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp'; mkdir($tmp); chmod($tmp, 0777); $batchFileName = (new Upload($tmp))->upload($file); $archive = new Archive($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName); $archive->extract($tmp); if (stripos($archive->getFilename(), '.tar') !== false && $archive->getFilename() != $batchFileName && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename())) { unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename()); } if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName)) { unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName); } $library = new MediaLibrary(); $library->getById($fields['library_id']); $settings = $library->getSettings(); $dir = new Dir($tmp, ['absolute' => true, 'recursive' => true, 'filesOnly' => true]); $upload = new Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']); foreach ($dir->getFiles() as $file) { $basename = basename($file); $testFile = ['name' => $basename, 'size' => filesize($file), 'error' => 0]; if ($upload->test($testFile)) { $fileName = $upload->checkFilename($basename); copy($file, $settings['folder'] . '/' . $fileName); $title = ucwords(str_replace(['_', '-'], [' ', ' '], substr($fileName, 0, strrpos($fileName, '.')))); if (null !== $library->adapter) { $class = 'Pop\\Image\\' . $library->adapter; $formats = array_keys($class::getFormats()); $fileParts = pathinfo($fileName); if (!empty($fileParts['extension']) && in_array(strtolower($fileParts['extension']), $formats)) { $this->processImage($fileName, $library); } } $media = new Table\Media(['library_id' => $fields['library_id'], 'title' => $title, 'file' => $fileName, 'size' => filesize($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder . DIRECTORY_SEPARATOR . $fileName), 'uploaded' => date('Y-m-d H:i:s'), 'order' => 0]); $media->save(); $this->data['ids'][] = $media->id; } } $dir->emptyDir(true); }
/** * Install modules * * @param \Pop\Service\Locator $services * @throws \Exception * @return void */ public function install(\Pop\Service\Locator $services) { $modulesPath = MODULES_ABS_PATH; $modules = $this->detectNew(false); if (strpos($modulesPath, 'vendor') !== false) { foreach ($modules as $module) { $this->finalizeInstall('', $module, $modulesPath, $services); } } else { if (!is_writable($modulesPath)) { throw new \Phire\Exception('Error: The module folder is not writable.'); } $formats = Archive::getFormats(); foreach ($modules as $module) { if (file_exists($modulesPath . '/' . $module)) { $ext = null; $folder = null; if (substr($module, -4) == '.zip') { $ext = 'zip'; $folder = substr($module, 0, -4); } else { if (substr($module, -4) == '.tgz') { $ext = 'tgz'; $folder = substr($module, 0, -4); } else { if (substr($module, -7) == '.tar.gz') { $ext = 'tar.gz'; $folder = substr($module, 0, -7); } } } if (null !== $ext && null !== $folder && array_key_exists($ext, $formats)) { $archive = new Archive($modulesPath . '/' . $module); $archive->extract($modulesPath); if (stripos($module, 'gz') !== false && file_exists($modulesPath . '/' . $folder . '.tar')) { unlink($modulesPath . '/' . $folder . '.tar'); } if (file_exists($modulesPath . '/' . $folder) && file_exists($modulesPath . '/' . $folder . '/config/module.php')) { $this->finalizeInstall($module, $folder, $modulesPath, $services); } } } } } }
/** * Method to instantiate an archive adapter object * * @param \Pop\Archive\Archive $archive * @return \Pop\Archive\Adapter\Phar */ public function __construct(\Pop\Archive\Archive $archive) { $this->path = $archive->getFullpath(); $this->archive = new \Phar($this->path); }
/** * Get theme update * * @param string $new * @param string $old * @param string $version * @return void */ public function getUpdate($new, $old, $version) { if (file_exists(__DIR__ . '/../../../../themes/' . $old . '.zip')) { unlink(__DIR__ . '/../../../../themes/' . $old . '.zip'); } if (file_exists(__DIR__ . '/../../../../themes/' . $old)) { $dir = new Dir(__DIR__ . '/../../../../themes/' . $old); $dir->emptyDir(true); } file_put_contents(__DIR__ . '/../../../../themes/' . $new . '.zip', fopen('http://updates.phirecms.org/releases/themes/' . $new . '.zip', 'r')); $basePath = realpath(__DIR__ . '/../../../../themes/'); $archive = new Archive($basePath . '/' . $new . '.zip'); $archive->extract($basePath); $theme = Table\Themes::findById($this->id); $assets = unserialize($theme->assets); if (isset($assets['info']['version'])) { $assets['info']['version'] = $version; } else { if (isset($assets['info']['Version'])) { $assets['info']['Version'] = $version; } else { if (isset($assets['info']['VERSION'])) { $assets['info']['VERSION'] = $version; } } } $theme->file = $new . '.zip'; $theme->folder = $new; $theme->version = $version; $theme->assets = serialize($assets); $theme->updated_on = date('Y-m-d H:i:s'); $theme->save(); $this->getById($this->id); }
/** * Install modules method * * @throws \Phire\Exception * @return void */ public function installModules() { try { $path = BASE_PATH . APP_URI; if ($path == '') { $path = '/'; } $modulePath1 = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules'; $modulePath2 = __DIR__ . '/../../../../../module'; $formats = Archive::formats(); $phireCookie = null; foreach ($this->data['new'] as $name => $module) { $ext = substr($module, strrpos($module, '.') + 1); if (array_key_exists($ext, $formats)) { $modPath = file_exists($modulePath1 . '/' . $module) ? $modulePath1 : $modulePath2; if (!is_writable($modPath)) { throw new \Phire\Exception($this->i18n->__('The modules folder is not writable.')); } $archive = new Archive($modPath . '/' . $module); $archive->extract($modPath . '/'); if ((stripos($module, 'gz') || stripos($module, 'bz')) && file_exists($modPath . '/' . $name . '.tar')) { unlink($modPath . '/' . $name . '.tar'); } $dbType = Table\Extensions::getSql()->getDbType(); if ($dbType == \Pop\Db\Sql::SQLITE) { $type = 'sqlite'; } else { if ($dbType == \Pop\Db\Sql::PGSQL) { $type = 'pgsql'; } else { $type = 'mysql'; } } $sqlFile = $modPath . '/' . $name . '/data/' . strtolower($name) . '.' . $type . '.sql'; $cfg = null; $tables = array(); $info = array(); // Check for a config and try to get info out of it if (file_exists($modPath . '/' . $name . '/config') && file_exists($modPath . '/' . $name . '/config/module.php')) { $cfg = file_get_contents($modPath . '/' . $name . '/config/module.php'); if (strpos($cfg, '*/') !== false) { $cfgHeader = substr($cfg, 0, strpos($cfg, '*/')); $cfgHeader = substr($cfgHeader, strpos($cfgHeader, '/*') + 2); $cfgHeaderAry = explode("\n", $cfgHeader); foreach ($cfgHeaderAry as $line) { if (strpos($line, ':')) { $ary = explode(':', $line); if (isset($ary[0]) && isset($ary[1])) { $key = trim(str_replace('*', '', $ary[0])); $value = trim(str_replace('*', '', $ary[1])); $info[$key] = $value; } } } } } if (file_exists($sqlFile)) { // Get any tables required and created by this module $sql = file_get_contents($sqlFile); $tables = array(); $matches = array(); preg_match_all('/^CREATE TABLE(.*)$/mi', $sql, $matches); if (isset($matches[0]) && isset($matches[0][0])) { foreach ($matches[0] as $table) { if (strpos($table, '`') !== false) { $table = substr($table, strpos($table, '`') + 1); $table = substr($table, 0, strpos($table, '`')); } else { if (strpos($table, '"') !== false) { $table = substr($table, strpos($table, '"') + 1); $table = substr($table, 0, strpos($table, '"')); } else { if (strpos($table, "'") !== false) { $table = substr($table, strpos($table, "'") + 1); $table = substr($table, 0, strpos($table, "'")); } else { if (stripos($table, 'EXISTS') !== false) { $table = substr($table, stripos($table, 'EXISTS') + 6); } else { $table = substr($table, stripos($table, 'TABLE') + 5); } if (strpos($table, '(') !== false) { $table = substr($table, 0, strpos($table, '(')); } $table = trim($table); } } } $tables[] = str_replace('[{prefix}]', DB_PREFIX, $table); } } $ext = new Table\Extensions(array('name' => $name, 'file' => $module, 'type' => 1, 'active' => 1, 'assets' => serialize(array('tables' => $tables, 'info' => $info)))); $ext->save(); // If DB is SQLite if (stripos($type, 'Sqlite') !== false) { $dbName = realpath($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/.htphire.sqlite'); $dbUser = null; $dbPassword = null; $dbHost = null; $installFile = $dbName; } else { $dbName = DB_NAME; $dbUser = DB_USER; $dbPassword = DB_PASS; $dbHost = DB_HOST; $installFile = null; } $db = array('database' => $dbName, 'username' => $dbUser, 'password' => $dbPassword, 'host' => $dbHost, 'prefix' => DB_PREFIX, 'type' => DB_INTERFACE == 'Pdo' ? 'Pdo_' . ucfirst(DB_TYPE) : DB_INTERFACE); Dbs::install($dbName, $db, $sqlFile, $installFile, true, false); } else { $ext = new Table\Extensions(array('name' => $name, 'type' => 1, 'active' => 1, 'assets' => serialize(array('tables' => $tables, 'info' => $info)))); $ext->save(); } if (null !== $cfg) { $config = (include $modPath . '/' . $name . '/config/module.php'); if (null !== $config[$name]->install) { $installFunc = $config[$name]->install; $installFunc(); } } if (php_sapi_name() != 'cli') { $cookie = Cookie::getInstance(array('path' => $path)); if (isset($cookie->phire)) { if (null === $phireCookie) { $phireCookie = $cookie->phire; } $i18n = file_exists($modPath . '/' . $name . '/data/assets/i18n'); $modules = (array) $phireCookie->modules; $modules[] = array('name' => $name, 'i18n' => $i18n); $phireCookie->modules = $modules; } } } } if (null !== $phireCookie) { $cookie = Cookie::getInstance(array('path' => $path)); $cookie->set('phire', $phireCookie); } } catch (\Exception $e) { $this->data['error'] = $e->getMessage(); } }
public function testNoCompress() { $tar = false; $includePath = explode(PATH_SEPARATOR, get_include_path()); foreach ($includePath as $path) { if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) { $tar = true; } } if ($tar) { $a = new Archive(__DIR__ . '/../tmp/test.tar'); $a->addFiles(__DIR__ . '/../tmp'); $a->compress('.noext'); $this->fileExists(__DIR__ . '/../tmp/test.tar'); if (file_exists(__DIR__ . '/../tmp/test.tar')) { unlink(__DIR__ . '/../tmp/test.tar'); } } }