public function performanceAction() { $setting_file = APPLICATION_PATH . '/application/settings/cache.php'; $default_file_path = APPLICATION_PATH . '/temporary/cache'; if (file_exists($setting_file)) { $current_cache = (include $setting_file); } else { $current_cache = array('default_backend' => 'File', 'frontend' => array('core' => array('automatic_serialization' => true, 'cache_id_prefix' => 'Engine4_', 'lifetime' => '300', 'caching' => true, 'gzip' => 1)), 'backend' => array('File' => array('cache_dir' => APPLICATION_PATH . '/temporary/cache'))); } $current_cache['default_file_path'] = $default_file_path; $this->view->form = $form = new Core_Form_Admin_Settings_Performance(); // pre-fill form with proper cache type $form->populate($current_cache); // disable caching types not supported $disabled_type_options = $removed_type_options = array(); foreach ($form->getElement('type')->options as $i => $backend) { if ('Apc' == $backend && !extension_loaded('apc')) { $disabled_type_options[] = $backend; } if ('Memcached' == $backend && !extension_loaded('memcache')) { $disabled_type_options[] = $backend; } if ('Xcache' == $backend && !extension_loaded('xcache')) { $disabled_type_options[] = $backend; } } $form->getElement('type')->setAttrib('disable', $disabled_type_options); // set required elements before checking for validity switch ($this->getRequest()->getPost('type')) { case 'File': $form->getElement('file_path')->setRequired(true)->setAllowEmpty(false); break; case 'Memcached': $form->getElement('memcache_host')->setRequired(true)->setAllowEmpty(false); $form->getElement('memcache_port')->setRequired(true)->setAllowEmpty(false); break; case 'Xcache': $form->getElement('xcache_username')->setRequired(true)->setAllowEmpty(false); $form->getElement('xcache_password')->setRequired(true)->setAllowEmpty(false); break; } if (is_writable($setting_file) || is_writable(dirname($setting_file)) && !file_exists($setting_file)) { // do nothing } else { //if( (is_file($setting_file) && !is_writable($setting_file)) // || (!is_file($setting_file) && is_dir(dirname($setting_file)) && !is_writable(dirname($setting_file))) ) { $phrase = Zend_Registry::get('Zend_Translate')->_('Changes made to this form will not be saved. Please adjust the permissions (CHMOD) of file %s to 777 and try again.'); $form->addError(sprintf($phrase, '/application/settings/cache.php')); return; } if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->isPost = true; $code = "<?php\ndefined('_ENGINE') or die('Access Denied');\nreturn "; $do_flush = false; foreach ($form->getElement('type')->options as $type => $label) { if (array_key_exists($type, $current_cache['backend']) && $type != $this->_getParam('type')) { $do_flush = true; } } $options = array(); switch ($this->getRequest()->getPost('type')) { case 'File': $options['file_locking'] = (bool) $this->_getParam('file_locking'); $options['cache_dir'] = $this->_getParam('file_path'); if (!is_writable($options['cache_dir'])) { $options['cache_dir'] = $default_file_path; $form->getElement('file_path')->setValue($default_file_path); } break; case 'Memcached': $options['servers'][] = array('host' => $this->_getParam('memcache_host'), 'port' => (int) $this->_getParam('memcache_port')); $options['compression'] = (bool) $this->_getParam('memcache_compression'); } $current_cache['backend'] = array($this->_getParam('type') => $options); $current_cache['frontend']['core']['lifetime'] = $this->_getParam('lifetime'); $current_cache['frontend']['core']['caching'] = (bool) $this->_getParam('enable'); $current_cache['frontend']['core']['gzip'] = (bool) $this->_getParam('gzip_html'); $code .= var_export($current_cache, true); $code .= '; ?>'; // test write+read before saving to file $backend = null; if (!$current_cache['frontend']['core']['caching']) { $this->view->success = true; } else { $backend = Zend_Cache::_makeBackend($this->_getParam('type'), $options); if ($current_cache['frontend']['core']['caching'] && @$backend->save('test_value', 'test_id') && @$backend->test('test_id')) { #$backend->remove('test_id'); $this->view->success = true; } else { $this->view->success = false; $form->getElement('type')->setErrors(array('Unable to use this backend. Please check your settings or try another one.')); } } // write settings to file if ($this->view->success && file_put_contents($setting_file, $code)) { $form->addNotice('Your changes have been saved.'); } elseif ($this->view->success) { $form->addError('Your settings were unable to be saved to the cache file. Please log in through FTP and either CHMOD 777 the file <em>/application/settings/cache.php</em>, or edit that file and replace the existing code with the following:<br/> <code>' . htmlspecialchars($code) . '</code>'); } if ($backend instanceof Zend_Cache_Backend && ($do_flush || $form->getElement('flush')->getValue())) { $backend->clean(); $form->getElement('flush')->setValue(0); $form->addNotice('Cache has been flushed.'); } } /* CHANGE TRANSLATION METHOD TO ARRAY */ $db = Engine_Db_Table::getDefaultAdapter(); if ($form->getElement('translate_array')->getValue() == 1 && $this->getRequest()->isPost()) { // Check For Array Files $languagePath = APPLICATION_PATH . '/application/languages'; // Get List of Folders $languageFolders = array_filter(glob($languagePath . DIRECTORY_SEPARATOR . '*'), 'is_dir'); // Look inside Folders foreach ($languageFolders as $folder) { // Get Locale code $locale_code = str_replace($languagePath . DIRECTORY_SEPARATOR, "", $folder); // If Array files do not exist, Create Them and check syntax $array_check = $this->csv_folder_to_array($folder, $locale_code); if (!$array_check) { $db->update('engine4_core_settings', array('value' => 'csv'), array('name = ?' => 'core.translate.adapter')); $form->getElement('translate_array')->setValue(0); $form->addError('Language packs could not be converted to PHP Arrays.'); return; } } // Update DB Parameter to Array $db->update('engine4_core_settings', array('value' => 'array'), array('name = ?' => 'core.translate.adapter')); $form->addNotice('Language Packs successfully converted to PHP Arrays.'); } else { if ($this->getRequest()->isPost()) { // Switch DB Parameter back to CSV $db->update('engine4_core_settings', array('value' => 'csv'), array('name = ?' => 'core.translate.adapter')); } } /* END OF TRANSLATION CHANGES */ }
public function performanceAction() { $setting_file = APPLICATION_PATH . '/application/settings/cache.php'; $default_file_path = APPLICATION_PATH . '/temporary/cache'; if (file_exists($setting_file)) { $current_cache = (include $setting_file); } else { $current_cache = array('default_backend' => 'File', 'frontend' => array('core' => array('automatic_serialization' => true, 'cache_id_prefix' => 'Engine4_', 'lifetime' => '300', 'caching' => true)), 'backend' => array('File' => array('cache_dir' => APPLICATION_PATH . '/temporary/cache'))); } $current_cache['default_file_path'] = $default_file_path; $this->view->form = $form = new Core_Form_Admin_Settings_Performance(); // pre-fill form with proper cache type $form->populate($current_cache); // disable caching types not supported $disabled_type_options = $removed_type_options = array(); foreach ($form->getElement('type')->options as $i => $backend) { if ('Apc' == $backend && !extension_loaded('apc')) { $disabled_type_options[] = $backend; } if ('Memcached' == $backend && !extension_loaded('memcache')) { $disabled_type_options[] = $backend; } if ('Xcache' == $backend && !extension_loaded('xcache')) { $disabled_type_options[] = $backend; } } $form->getElement('type')->setAttrib('disable', $disabled_type_options); // set required elements before checking for validity switch ($this->getRequest()->getPost('type')) { case 'File': $form->getElement('file_path')->setRequired(true)->setAllowEmpty(false); break; case 'Memcached': $form->getElement('memcache_host')->setRequired(true)->setAllowEmpty(false); $form->getElement('memcache_port')->setRequired(true)->setAllowEmpty(false); break; case 'Memcached': $form->getElement('xcache_username')->setRequired(true)->setAllowEmpty(false); $form->getElement('xcache_password')->setRequired(true)->setAllowEmpty(false); break; } if (is_writable($setting_file) || is_writable(dirname($setting_file)) && !file_exists($setting_file)) { // do nothing } else { //if( (is_file($setting_file) && !is_writable($setting_file)) // || (!is_file($setting_file) && is_dir(dirname($setting_file)) && !is_writable(dirname($setting_file))) ) { $phrase = Zend_Registry::get('Zend_Translate')->_('Changes made to this form will not be saved. Please adjust the permissions (CHMOD) of file %s to 777 and try again.'); $form->addError(sprintf($phrase, '/application/settings/cache.php')); return; } if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { $this->view->isPost = true; $code = "<?php\ndefined('_ENGINE') or die('Access Denied');\nreturn "; $do_flush = false; foreach ($form->getElement('type')->options as $type => $label) { if (array_key_exists($type, $current_cache['backend']) && $type != $this->_getParam('type')) { $do_flush = true; } } $options = array(); switch ($this->getRequest()->getPost('type')) { case 'File': $options['file_locking'] = (bool) $this->_getParam('file_locking'); $options['cache_dir'] = $this->_getParam('file_path'); if (!is_writable($options['cache_dir'])) { $options['cache_dir'] = $default_file_path; $form->getElement('file_path')->setValue($default_file_path); } break; case 'Memcached': $options['servers'][] = array('host' => $this->_getParam('memcache_host'), 'port' => (int) $this->_getParam('memcache_port')); $options['compression'] = (bool) $this->_getParam('memcache_compression'); } $current_cache['backend'] = array($this->_getParam('type') => $options); $current_cache['frontend']['core']['lifetime'] = $this->_getParam('lifetime'); $current_cache['frontend']['core']['caching'] = (bool) $this->_getParam('enable'); $code .= var_export($current_cache, true); $code .= '; ?>'; // test write+read before saving to file $backend = null; if (!$current_cache['frontend']['core']['caching']) { $this->view->success = true; } else { $backend = Zend_Cache::_makeBackend($this->_getParam('type'), $options); if ($current_cache['frontend']['core']['caching'] && @$backend->save('test_value', 'test_id') && @$backend->test('test_id')) { #$backend->remove('test_id'); $this->view->success = true; } else { $this->view->success = false; $form->getElement('type')->setErrors(array('Unable to use this backend. Please check your settings or try another one.')); } } // write settings to file if ($this->view->success && file_put_contents($setting_file, $code)) { $form->addNotice('Your changes have been saved.'); } elseif ($this->view->success) { $form->addError('Your settings were unable to be saved to the cache file. Please log in through FTP and either CHMOD 777 the file <em>/application/settings/cache.php</em>, or edit that file and replace the existing code with the following:<br/> <code>' . htmlspecialchars($code) . '</code>'); } if ($backend instanceof Zend_Cache_Backend && ($do_flush || $form->getElement('flush')->getValue())) { $backend->clean(); $form->getElement('flush')->setValue(0); $form->addNotice('Cache has been flushed.'); } } }