public function changeEnvironmentModeAction() { if ($this->getRequest()->isPost() && $this->_getParam('environment_mode', false)) { $global_settings_file = APPLICATION_PATH . '/application/settings/general.php'; if (file_exists($global_settings_file)) { $g = (include $global_settings_file); if (!is_array($g)) { $g = (array) $g; } } else { $g = array(); } if (!is_writable($global_settings_file)) { // not writable; can we delete and re-create? if (is_writable(dirname($global_settings_file))) { @rename($global_settings_file, $global_settings_file . '_backup.php'); @touch($global_settings_file); @chmod($global_settings_file, 0666); if (!file_exists($global_settings_file) || !is_writable($global_settings_file)) { @rename($global_settings_file, $global_settings_file . '_delete.php'); @rename($global_settings_file . '_backup.php', $global_settings_file); @unlink($global_settings_file . '_delete.php'); } } if (!is_writable($global_settings_file)) { $this->view->success = false; $this->view->error = 'Unable to write to settings file; please CHMOD 666 the file /application/settings/general.php, then try again.'; return; } else { // it worked; continue. } } if ($this->_getParam('environment_mode') != @$g['environment_mode']) { $g['environment_mode'] = $this->_getParam('environment_mode'); $file_contents = "<?php defined('_ENGINE') or die('Access Denied'); return "; $file_contents .= var_export($g, true); $file_contents .= "; ?>"; $this->view->success = @file_put_contents($global_settings_file, $file_contents); // clear scaffold cache Core_Model_DbTable_Themes::clearScaffoldCache(); // Increment site counter $settings = Engine_Api::_()->getApi('settings', 'core'); $settings->core_site_counter = $settings->core_site_counter + 1; return; } else { $this->view->message = 'No change necessary'; $this->view->success = true; // no change } } $this->view->success = false; }
public function uploadAction() { $form = $this->view->form = new Core_Form_Admin_Themes_Upload(); if ($this->getRequest()->isPost() && $form->isValid($this->_getAllParams())) { if (!isset($_FILES['theme_file'])) { throw new Engine_Exception("Theme file was too large, or was not uploaded."); } if (!preg_match('/\\.tar$/', $_FILES['theme_file']['name'])) { throw new Engine_Exception("Invalid theme file format; must be a TAR file."); } // extract tar file to temporary directory $tmp_dir = tempnam(APPLICATION_PATH . '/temporary/', 'theme_import'); unlink($tmp_dir); mkdir($tmp_dir, 0777, true); $tar = new Archive_Tar($_FILES['theme_file']['tmp_name']); $tar->extract($tmp_dir); // find theme.css $dir = $tmp_dir; while (!file_exists("{$dir}/theme.css")) { $subdirs = glob("{$dir}/*", GLOB_ONLYDIR); $dir = $subdirs[0]; } // pull manifest.php data $meta = array('package' => array(), 'files' => array()); if (file_exists("{$dir}/manifest.php")) { $meta = (include "{$dir}/manifest.php"); $post = $this->_getAllParams(); // @todo meta key is deprecated and pending removal in 4.1.0; b/c removal in 4.2.0 if (isset($meta['package']['meta'])) { $meta['package'] = array_merge($meta['package']['meta'], $meta['package']); unset($meta['package']['meta']); } if (isset($post['title'])) { $meta['package']['title'] = $post['title']; $meta['package']['name'] = preg_replace('/[^a-z-0-9_]/', '', strtolower($post['title'])); } if (empty($meta['package']['name'])) { $meta['package']['name'] = basename($dir); } if (empty($meta['package']['title'])) { $meta['package']['title'] = ucwords(preg_replace('/_\\-/', ' ', basename($dir))); } if (isset($post['description'])) { $meta['package']['description'] = $post['description']; } } // move files over recursively $destination_dir = APPLICATION_PATH . '/application/themes/' . $meta['package']['name']; rename($dir, $destination_dir); chmod($destination_dir, 0777); foreach (self::rscandir($destination_dir) as $file) { chmod($file, 0777); } // re-write manifest according to POST paramters file_put_contents("{$destination_dir}/manifest.php", '<?php return ' . var_export($meta, true) . '; ?>'); // add to database table $table = Engine_Api::_()->getDbtable('themes', 'core'); $row = $table->createRow(); // @todo meta key is deprecated and pending removal in 4.1.0; b/c removal in 4.2.0 if (isset($meta['package']['meta'])) { $meta['package'] = array_merge($meta['package']['meta'], $meta['package']); unset($meta['package']['meta']); } $row->name = $meta['package']['name']; $row->title = $meta['package']['title']; $row->description = $meta['package']['description']; $row->active = $this->_getParam('enable', false); $row->save(); // delete temporary directory Engine_Package_Utilities::fsRmdirRecursive($tmp_dir, true); // clear scaffold cache Core_Model_DbTable_Themes::clearScaffoldCache(); // Increment site counter $settings = Engine_Api::_()->getApi('settings', 'core'); $settings->core_site_counter = $settings->core_site_counter + 1; // forward back to index $this->_forward('success', 'utility', 'core', array('redirect' => Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'index')), 'messages' => array(Zend_Registry::get('Zend_Translate')->_('Theme file has been uploaded.')), 'parentRefresh' => 2000)); } }
public function changeAction() { $themeName = $this->_getParam('theme'); $themeTable = Engine_Api::_()->getDbtable('themes', 'core'); $themeSelect = $themeTable->select()->orWhere('theme_id = ?', $themeName)->orWhere('name = ?', $themeName)->limit(1); $theme = $themeTable->fetchRow($themeSelect); if ($theme && $this->getRequest()->isPost()) { $db = $themeTable->getAdapter(); $db->beginTransaction(); try { $themeTable->update(array('active' => 0), array('1 = ?' => 1)); $theme->active = true; $theme->save(); $db->commit(); // flush Scaffold cache Core_Model_DbTable_Themes::clearScaffoldCache(); } catch (Exception $e) { $db->rollBack(); throw $e; } } return $this->_helper->redirector->gotoRoute(array('action' => 'index')); }