/** * Displays the form to either upload a file, or add an external * media item (such as YouTube) * * @return string */ public function indexSection() { $this->setTitle(t('Add/upload media item')); // Get details for the category we'll be adding to try { $cid = $this->_input->get('cid'); $category = $this->_model()->getCategory($cid); if (!$this->_acl->check('media-cat_upload_' . $category['id'])) { throw new Module_NoPermission(); } $view = $this->loadView('add/form.html'); $view->assignHtml(array('csrf' => $this->_input->createToken(true))); $view->assign(array('cid' => $cid, 'max_fs' => $this->_config->get('media/max_fs'), 'zip_supported' => zula_supports('zipExtraction'))); return $view->getOutput(); } catch (Input_KeyNoExist $e) { $this->_event->error(t('No media category selected')); } catch (Media_CategoryNoExist $e) { $this->_event->error(t('Media category does not exist')); } return zula_redirect($this->_router->makeUrl('media')); }
/** * Update the settings based on the post-data provided * * @param string $name * @param array $args * @return string */ public function __call($name, $args) { $name = substr($name, 0, -7); if (!$this->_acl->check('settings_update')) { throw new Module_NoPermission(); } else { if (!in_array($name, $this->categories)) { throw new Module_ControllerNoExist(); } else { if (!$this->_input->checkToken()) { $this->_event->error(Input::csrfMsg()); return zula_redirect($this->_router->makeUrl('settings', $name)); } } } $this->setTitle(t('Update settings')); // Update all of the provided settings, or insert if they don't exist foreach ($this->_input->post('setting') as $key => $val) { if (strpos($key, 'cache') !== 0) { if (substr($key, 8, 9) == 'mail/smtp' && !$this->_acl->check('settings_access_smtp')) { continue; } try { $this->_config_sql->update($key, $val); } catch (Config_KeyNoExist $e) { $this->_sql->insert('config', array('name' => $key, 'value' => $val)); } } } /** * Category specific things to do when updating * the settings or other things (ACL forms etc). */ switch ($name) { case 'general': $this->_cache->delete('view_default_tags'); break; case 'cache': try { $this->_config_ini->update('cache/type', $this->_input->post('setting/cache\\/type')); $this->_config_ini->update('cache/ttl', $this->_input->post('setting/cache\\/ttl')); $this->_config_ini->update('cache/js_aggregate', $this->_input->post('setting/cache\\/js_aggregate')); $this->_config_ini->update('cache/google_cdn', $this->_input->post('setting/cache\\/google_cdn')); $this->_config_ini->writeIni(); // Clear cache if needbe if ($this->_input->post('cache_purge')) { $this->_cache->purge(); } } catch (Exception $e) { $this->_event->error($e->getMessage()); $this->_log->message($e->getMessage(), Log::L_WARNING); } break; case 'locale': try { $this->_config_ini->update('locale/default', $this->_input->post('setting/locale\\/default')); $this->_config_ini->writeIni(); } catch (Exception $e) { $this->_event->error($e->getMessage()); $this->_log->message($e->getMessage(), Log::L_WARNING); } if (($pkg = $this->_input->post('lang_pkg')) !== 'none') { // Download and install a new locale if (!zula_supports('zipExtraction')) { $this->_event->error(t('Cannot install locale, server does not support zip extraction')); } else { if (!preg_match('#^[a-z]{2}_[A-Z]{2}$#', $pkg)) { $this->_event->error(t('Provided locale is invalid, unable to install')); } else { if (!zula_is_writable($this->_zula->getDir('locale'))) { $this->_event->error(t('Locale directory is not writable, unable to install')); } else { $version = str_replace('-', '/', zula_version_map(_PROJECT_VERSION)); $zipDest = $this->_zula->getDir('tmp') . '/i18n-' . $pkg . '.zip'; $copyResult = @copy('http://releases.tangocms.org/' . $version . '/i18n/' . $pkg . '.zip', $zipDest); if ($copyResult) { // Extract the archive to the locale dir $zip = new ZipArchive(); if ($zip->open($zipDest)) { $zip->extractTo($this->_zula->getDir('locale')); $zip->close(); $this->_event->success(t('Locale successfully installed')); } else { $this->_event->error(t('Could not install locale, zip extraction failed')); } unlink($zipDest); } else { $this->_event->error(t('Failed to get remote language archive')); } } } } } break; } $this->_event->success(t('Updated settings')); return zula_redirect($this->_router->makeUrl('settings', $name)); }
/** * Allow archives (currently only .zip) to be uploaded and the contents * extracted. Each file in the archive must match the allowed mime * types and file size, if they don't they will not be kept. * * bool false will be returned if there is no method for extracting the * supported archive types. * * @param bool $extract * @return object|bool */ public function extractArchives($extract = true) { if ($extract && zula_supports('zipExtraction')) { $this->config['extractArchives'] = true; $this->config['allowedMime'][] = 'application/zip'; return $this; } else { $this->config['extractArchives'] = false; return $this; } }