00001 <?php
00002
00015 import('controllers.tab.settings.form.SettingsFileUploadForm');
00016
00017 class NewPressImageFileForm extends SettingsFileUploadForm {
00018
00023 function NewPressImageFileForm($imageSettingName) {
00024 parent::SettingsFileUploadForm('controllers/tab/settings/form/newImageFileUploadForm.tpl');
00025 $this->setFileSettingName($imageSettingName);
00026 }
00027
00028
00029
00030
00031
00035 function fetch(&$request) {
00036 $params = array('fileType' => 'image');
00037 return parent::fetch($request, $params);
00038 }
00039
00040
00041
00042
00043
00047 function getLocaleFieldNames() {
00048 return array('imageAltText');
00049 }
00050
00054 function initData(&$request) {
00055 $press =& $request->getPress();
00056 $fileSettingName = $this->getFileSettingName();
00057
00058 $image = $press->getSetting($fileSettingName);
00059 $imageAltText = array();
00060
00061 $supportedLocales = AppLocale::getSupportedLocales();
00062 foreach ($supportedLocales as $key => $locale) {
00063 $imageAltText[$key] = $image[$key]['altText'];
00064 }
00065
00066 $this->setData('imageAltText', $imageAltText);
00067 }
00068
00072 function readInputData() {
00073 $this->readUserVars(array('imageAltText'));
00074
00075 parent::readInputData();
00076 }
00077
00082 function execute(&$request) {
00083 $temporaryFile = $this->fetchTemporaryFile($request);
00084
00085 import('classes.file.PublicFileManager');
00086 $publicFileManager = new PublicFileManager();
00087
00088 if (is_a($temporaryFile, 'TemporaryFile')) {
00089 $type = $temporaryFile->getFileType();
00090 $extension = $publicFileManager->getImageExtension($type);
00091 if (!$extension) {
00092 return false;
00093 }
00094 $locale = AppLocale::getLocale();
00095 $press = $request->getPress();
00096
00097 $uploadName = $this->getFileSettingName() . '_' . $locale . $extension;
00098 if($publicFileManager->copyPressFile($press->getId(), $temporaryFile->getFilePath(), $uploadName)) {
00099
00100
00101 $filePath = $publicFileManager->getPressFilesPath($press->getId());
00102 list($width, $height) = getimagesize($filePath . '/' . $uploadName);
00103
00104 $value = $press->getSetting($this->getFileSettingName());
00105 $imageAltText = $this->getData('imageAltText');
00106
00107 $value[$locale] = array(
00108 'name' => $temporaryFile->getOriginalFileName(),
00109 'uploadName' => $uploadName,
00110 'width' => $width,
00111 'height' => $height,
00112 'dateUploaded' => Core::getCurrentDate(),
00113 'altText' => $imageAltText[$locale]
00114 );
00115
00116 $settingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00117 $settingsDao->updateSetting($press->getId(), $this->getFileSettingName(), $value, 'object', true);
00118
00119
00120 $this->removeTemporaryFile($request);
00121
00122 return true;
00123 }
00124 }
00125 return false;
00126 }
00127 }
00128
00129 ?>