/** * 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(); }
/** * Install themes * * @throws \Exception * @return void */ public function install() { $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes'; $themes = $this->detectNew(false); $children = $this->detectChildren(false); if (!is_writable($themePath)) { throw new \Phire\Exception('Error: The theme folder is not writable.'); } $formats = Archive::getFormats(); foreach ($themes as $theme) { if (file_exists($themePath . '/' . $theme)) { $ext = null; $folder = null; if (substr($theme, -4) == '.zip') { $ext = 'zip'; $folder = substr($theme, 0, -4); } else { if (substr($theme, -4) == '.tgz') { $ext = 'tgz'; $folder = substr($theme, 0, -4); } else { if (substr($theme, -7) == '.tar.gz') { $ext = 'tar.gz'; $folder = substr($theme, 0, -7); } } } if (null !== $ext && null !== $folder && array_key_exists($ext, $formats)) { $archive = new Archive($themePath . '/' . $theme); $archive->extract($themePath); if (stripos($theme, 'gz') !== false && file_exists($themePath . '/' . $folder . '.tar')) { unlink($themePath . '/' . $folder . '.tar'); } if (file_exists($themePath . '/' . $folder)) { $style = null; $name = ''; $info = []; $version = 'N/A'; // Check for a style sheet if (file_exists($themePath . '/' . $folder . '/style.css')) { $style = $themePath . '/' . $folder . '/style.css'; } else { if (file_exists($themePath . '/' . $folder . '/styles.css')) { $style = $themePath . '/' . $folder . '/styles.css'; } else { if (file_exists($themePath . '/' . $folder . '/css/style.css')) { $style = $themePath . '/' . $folder . '/css/style.css'; } else { if (file_exists($themePath . '/' . $folder . '/css/styles.css')) { $style = $themePath . '/' . $folder . '/css/styles.css'; } else { if (file_exists($themePath . '/' . $folder . '/style/style.css')) { $style = $themePath . '/' . $folder . '/style/style.css'; } else { if (file_exists($themePath . '/' . $folder . '/style/styles.css')) { $style = $themePath . '/' . $folder . '/style/styles.css'; } else { if (file_exists($themePath . '/' . $folder . '/styles/style.css')) { $style = $themePath . '/' . $folder . '/styles/style.css'; } else { if (file_exists($themePath . '/' . $folder . '/styles/styles.css')) { $style = $themePath . '/' . $folder . '/styles/styles.css'; } } } } } } } } // Get theme info from config file if (null != $style) { $info = $this->getInfo(file_get_contents($style)); if (isset($info['version'])) { $version = $info['version']; } else { if (isset($info['Version'])) { $version = $info['Version']; } else { if (isset($info['VERSION'])) { $version = $info['VERSION']; } } } if (isset($info['name'])) { $name = $info['name']; } else { if (isset($info['Name'])) { $name = $info['Name']; } else { if (isset($info['NAME'])) { $name = $info['NAME']; } else { if (isset($info['theme name'])) { $name = $info['theme name']; } else { if (isset($info['Theme Name'])) { $name = $info['Theme Name']; } else { if (isset($info['THEME NAME'])) { $name = $info['THEME NAME']; } } } } } } } // Save theme in the database $thm = new Table\Themes(['name' => $name, 'file' => $theme, 'folder' => $folder, 'version' => $version, 'active' => 0, 'assets' => serialize(['info' => $info]), 'installed_on' => date('Y-m-d H:i:s')]); $thm->save(); $this->sendStats($name, $version); } } } } foreach ($children as $parent => $child) { $parentTheme = Table\Themes::findBy(['folder' => $parent]); if (isset($parentTheme->id) && file_exists($themePath . '/' . $child)) { $style = null; $info = []; // Check for a style sheet if (file_exists($themePath . '/' . $child . '/style.css')) { $style = $themePath . '/' . $child . '/style.css'; } else { if (file_exists($themePath . '/' . $child . '/styles.css')) { $style = $themePath . '/' . $child . '/styles.css'; } else { if (file_exists($themePath . '/' . $child . '/css/style.css')) { $style = $themePath . '/' . $child . '/css/style.css'; } else { if (file_exists($themePath . '/' . $child . '/css/styles.css')) { $style = $themePath . '/' . $child . '/css/styles.css'; } } } } // Get theme info from config file if (null != $style) { $info = $this->getInfo(file_get_contents($style)); } // Save theme in the database $thm = new Table\Themes(['parent_id' => $parentTheme->id, 'name' => $child, 'folder' => $child, 'active' => 0, 'assets' => serialize(['info' => $info]), 'installed_on' => date('Y-m-d H:i:s')]); $thm->save(); } } }
/** * 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(); } } } } } }
/** * 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); } } } } } }