*/ /** * @package Mime * @subpackage Administration */ class MimeEditController extends GalleryController { /** * @see GalleryController::handleRequest */ function handleRequest($form) { global $gallery; $ret = GalleryCoreApi::assertUserIsSiteAdministrator(); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } $error = array(); $status = array(); if (isset($form['action']['save']) || isset($form['action']['apply'])) { if (empty($form['mimeType'])) { $error[] = 'form[error][mimeType][missing]'; } $form['mimeType'] = strtolower($form['mimeType']); $allEmpty = true; foreach ($form['extensions'] as $ext) { if (!empty($ext)) { $allEmpty = false; $ext = strtolower($ext); $mimeTypeMap[] = array( 'extension' => $ext, 'mimeType' => $form['mimeType'], 'viewable' => (int) isset($form['viewable'])); list ($ret, $existingMimeType) = GalleryCoreApi::convertExtensionToMime($ext); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } if ($existingMimeType != $form['mimeType'] && $existingMimeType != 'application/unknown') { $error[] = 'form[error][extensions][inuse][' . $ext . ']'; } } } if ($allEmpty) { $error[] = 'form[error][extensions][missing]'; } if (empty($error)) { $ret = GalleryCoreApi::removeMimeType(array('mimeType' => $form['mimeType'])); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } foreach ($mimeTypeMap as $mimeType) { $ret = GalleryCoreApi::addMimeType( $mimeType['extension'], $mimeType['mimeType'], $mimeType['viewable']); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } } $status['saved'] = true; } } if (empty($error)) { if (isset($form['action']['apply'])) { $results['redirect'] = array('view' => 'core.SiteAdmin', 'subView' => 'mime.MimeEdit', 'mimeType' => $form['mimeType']); } else { $results['redirect'] = array('view' => 'core.SiteAdmin', 'subView' => 'mime.MimeAdmin'); } } else { $results['delegate'] = array('view' => 'core.SiteAdmin', 'subView' => 'mime.MimeEdit'); } $results['status'] = $status; $results['error'] = $error; return array(null, $results); } } /** * @package Mime * @subpackage Administration */ class MimeEditView extends GalleryView { /** * @see GalleryView::loadTemplate */ function loadTemplate(&$template, &$form) { global $gallery; $mimeType = GalleryUtilities::getRequestVariables('mimeType'); if ($form['formName'] != 'MimeEdit') { $form['formName'] = 'MimeEdit'; $form['mimeType'] = $mimeType; if ($mimeType) { list ($ret, $form['extensions']) = GalleryCoreApi::convertMimeToExtensions($mimeType); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } list ($ret, $form['viewable']) = GalleryCoreApi::isViewableMimeType($mimeType); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null); } } else { $form['viewable'] = false; $form['extensions'] = array(); } } else { /* * Force our checkbox to be false on empty (since browsers don't send a value * if the checkbox is not checked. */ if (empty($form['viewable'])) { $form['viewable'] = false; } /* Prune empty extension boxes */ $tmp = array(); foreach ($form['extensions'] as $extension) { if (!empty($extension)) { $tmp[] = $extension; } } $form['extensions'] = $tmp; } $template->setVariable('controller', 'mime.MimeEdit'); return array(null, array('body' => 'modules/mime/templates/MimeEdit.tpl')); } } ?>