Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
NewSiteImageFileForm.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.tab.settings.form.SettingsFileUploadForm');
17 
19 
24  function NewSiteImageFileForm($imageSettingName) {
25  parent::SettingsFileUploadForm('controllers/tab/settings/form/newImageFileUploadForm.tpl');
26  $this->setFileSettingName($imageSettingName);
27  }
28 
29 
30  //
31  // Extend methods from Form.
32  //
36  function initData($request) {
37  $site = $request->getSite();
38  $fileSettingName = $this->getFileSettingName();
39 
40  $image = $site->getSetting($fileSettingName);
41  $imageAltText = array();
42 
44  foreach ($supportedLocales as $key => $locale) {
45  $imageAltText[$key] = $image[$key]['altText'];
46  }
47 
48  $this->setData('imageAltText', $imageAltText);
49  }
50 
51  //
52  // Extend methods from SettingsFileUploadForm.
53  //
57  function readInputData() {
58  $this->readUserVars(array('imageAltText'));
59 
60  parent::readInputData();
61  }
62 
66  function fetch($request) {
67  $params = array('fileType' => 'image');
68  return parent::fetch($request, $params);
69  }
70 
71 
72  //
73  // Extend methods from Form.
74  //
79  function execute($request) {
80  $temporaryFile = $this->fetchTemporaryFile($request);
81 
82  import('classes.file.PublicFileManager');
83  $publicFileManager = new PublicFileManager();
84 
85  if (is_a($temporaryFile, 'TemporaryFile')) {
86  $type = $temporaryFile->getFileType();
87  $extension = $publicFileManager->getImageExtension($type);
88  if (!$extension) {
89  return false;
90  }
91  $locale = AppLocale::getLocale();
92  $uploadName = $this->getFileSettingName() . '_' . $locale . $extension;
93  if ($publicFileManager->copyFile($temporaryFile->getFilePath(), $publicFileManager->getSiteFilesPath() . '/' . $uploadName)) {
94 
95  // Get image dimensions
96  $filePath = $publicFileManager->getSiteFilesPath();
97  list($width, $height) = getimagesize($filePath . '/' . $uploadName);
98 
99  $site = $request->getSite();
100  $siteDao = DAORegistry::getDAO('SiteDAO');
101  $value = $site->getSetting($this->getFileSettingName());
102  $imageAltText = $this->getData('imageAltText');
103 
104  $value[$locale] = array(
105  'originalFilename' => $temporaryFile->getOriginalFileName(),
106  'uploadName' => $uploadName,
107  'width' => $width,
108  'height' => $height,
109  'dateUploaded' => Core::getCurrentDate(),
110  'altText' => $imageAltText[$locale]
111  );
112 
113  $site->updateSetting($this->getFileSettingName(), $value, 'object', true);
114 
115  // Clean up the temporary file
116  $this->removeTemporaryFile($request);
117 
118  return true;
119  }
120  }
121  return false;
122  }
123 }
124 
125 ?>
static & getDAO($name, $dbconn=null)
setData($key, $value)
Definition: Form.inc.php:219
Wrapper class for uploading files to a site/press&#39; public directory.
readUserVars($vars)
Definition: Form.inc.php:364
static getSupportedLocales()
Base class for a settings upload file form.
getData($key)
Definition: Form.inc.php:210
static getLocale()
$supportedLocales
Definition: Form.inc.php:83
NewSiteImageFileForm($imageSettingName)
Form for upload an image.
static getCurrentDate($ts=null)
Definition: Core.inc.php:95