00001 <?php
00002
00015
00016
00017
00018 import("manager.form.setup.JournalSetupForm");
00019
00020 class JournalSetupStep5Form extends JournalSetupForm {
00021 var $images;
00022 var $image_settings;
00023
00027 function JournalSetupStep5Form() {
00028 $this->images = array(
00029 'homeHeaderTitleImage',
00030 'homeHeaderLogoImage',
00031 'homepageImage',
00032 'pageHeaderTitleImage',
00033 'pageHeaderLogoImage'
00034 );
00035
00036 $this->image_settings = array(
00037 'homeHeaderTitleImage' => 'homeHeaderTitleImageAltText',
00038 'homeHeaderLogoImage' => 'homeHeaderLogoImageAltText',
00039 'homepageImage' => 'homepageImageAltText',
00040 'pageHeaderTitleImage' => 'pageHeaderTitleImageAltText',
00041 'pageHeaderLogoImage' => 'pageHeaderLogoImageAltText'
00042 );
00043
00044 parent::JournalSetupForm(
00045 5,
00046 array(
00047 'homeHeaderTitleType' => 'int',
00048 'homeHeaderTitle' => 'string',
00049 'pageHeaderTitleType' => 'int',
00050 'pageHeaderTitle' => 'string',
00051 'readerInformation' => 'string',
00052 'authorInformation' => 'string',
00053 'librarianInformation' => 'string',
00054 'journalPageHeader' => 'string',
00055 'journalPageFooter' => 'string',
00056 'displayCurrentIssue' => 'bool',
00057 'additionalHomeContent' => 'string',
00058 'description' => 'string',
00059 'navItems' => 'object',
00060 'itemsPerPage' => 'int',
00061 'numPageLinks' => 'int',
00062 'journalTheme' => 'string'
00063 )
00064 );
00065 }
00066
00071 function getLocaleFieldNames() {
00072 return array('homeHeaderTitleType', 'homeHeaderTitle', 'pageHeaderTitleType', 'pageHeaderTitle', 'readerInformation', 'authorInformation', 'librarianInformation', 'journalPageHeader', 'journalPageFooter', 'homepageImage', 'additionalHomeContent', 'description', 'navItems');
00073 }
00074
00078 function readInputData() {
00079 $this->readUserVars(array_values($this->image_settings));
00080 parent::readInputData();
00081 }
00082
00086 function display() {
00087 $journal = &Request::getJournal();
00088
00089 $allThemes =& PluginRegistry::loadCategory('themes', true);
00090 $journalThemes = array();
00091 foreach ($allThemes as $key => $junk) {
00092 $plugin =& $allThemes[$key];
00093 $journalThemes[basename($plugin->getPluginPath())] =& $plugin;
00094 unset($plugin);
00095 }
00096
00097
00098 $templateMgr = &TemplateManager::getManager();
00099 $templateMgr->assign(array(
00100 'homeHeaderTitleImage' => $journal->getSetting('homeHeaderTitleImage'),
00101 'homeHeaderLogoImage'=> $journal->getSetting('homeHeaderLogoImage'),
00102 'pageHeaderTitleImage' => $journal->getSetting('pageHeaderTitleImage'),
00103 'pageHeaderLogoImage' => $journal->getSetting('pageHeaderLogoImage'),
00104 'homepageImage' => $journal->getSetting('homepageImage'),
00105 'journalStyleSheet' => $journal->getSetting('journalStyleSheet'),
00106 'readerInformation' => $journal->getSetting('readerInformation'),
00107 'authorInformation' => $journal->getSetting('authorInformation'),
00108 'librarianInformation' => $journal->getSetting('librarianInformation'),
00109 'journalThemes' => $journalThemes
00110 ));
00111
00112
00113 $templateMgr->initialize();
00114 $leftBlockPlugins = $disabledBlockPlugins = $rightBlockPlugins = array();
00115 $plugins =& PluginRegistry::getPlugins('blocks');
00116 foreach ($plugins as $key => $junk) {
00117 if (!$plugins[$key]->getEnabled() || $plugins[$key]->getBlockContext() == '') {
00118 if (count(array_intersect($plugins[$key]->getSupportedContexts(), array(BLOCK_CONTEXT_LEFT_SIDEBAR, BLOCK_CONTEXT_RIGHT_SIDEBAR))) > 0) $disabledBlockPlugins[] =& $plugins[$key];
00119 } else switch ($plugins[$key]->getBlockContext()) {
00120 case BLOCK_CONTEXT_LEFT_SIDEBAR:
00121 $leftBlockPlugins[] =& $plugins[$key];
00122 break;
00123 case BLOCK_CONTEXT_RIGHT_SIDEBAR:
00124 $rightBlockPlugins[] =& $plugins[$key];
00125 break;
00126 }
00127 }
00128 $templateMgr->assign(array(
00129 'disabledBlockPlugins' => &$disabledBlockPlugins,
00130 'leftBlockPlugins' => &$leftBlockPlugins,
00131 'rightBlockPlugins' => &$rightBlockPlugins
00132 ));
00133
00134 $templateMgr->setCacheability(CACHEABILITY_MUST_REVALIDATE);
00135 parent::display();
00136 }
00137
00143 function uploadImage($settingName, $locale) {
00144 $journal = &Request::getJournal();
00145 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00146
00147 import('file.PublicFileManager');
00148 $fileManager = &new PublicFileManager();
00149 if ($fileManager->uploadedFileExists($settingName)) {
00150 $type = $fileManager->getUploadedFileType($settingName);
00151 $extension = $fileManager->getImageExtension($type);
00152 if (!$extension) {
00153 return false;
00154 }
00155 $uploadName = $settingName . '_' . $locale . $extension;
00156 if ($fileManager->uploadJournalFile($journal->getJournalId(), $settingName, $uploadName)) {
00157
00158 $filePath = $fileManager->getJournalFilesPath($journal->getJournalId());
00159 list($width, $height) = getimagesize($filePath . '/' . $uploadName);
00160
00161 $value = $journal->getSetting($settingName);
00162 $value[$locale] = array(
00163 'name' => $fileManager->getUploadedFileName($settingName, $locale),
00164 'uploadName' => $uploadName,
00165 'width' => $width,
00166 'height' => $height,
00167 'dateUploaded' => Core::getCurrentDate()
00168 );
00169
00170 $settingsDao->updateSetting($journal->getJournalId(), $settingName, $value, 'object', true);
00171 return true;
00172 }
00173 }
00174
00175 return false;
00176 }
00177
00183 function deleteImage($settingName, $locale = null) {
00184 $journal = &Request::getJournal();
00185 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00186 $setting = $settingsDao->getSetting($journal->getJournalId(), $settingName);
00187
00188 import('file.PublicFileManager');
00189 $fileManager = &new PublicFileManager();
00190 if ($fileManager->removeJournalFile($journal->getJournalId(), $locale !== null ? $setting[$locale]['uploadName'] : $setting['uploadName'] )) {
00191 $returner = $settingsDao->deleteSetting($journal->getJournalId(), $settingName, $locale);
00192
00193 if ($returner) {
00194 $templateMgr = &TemplateManager::getManager();
00195 $templateMgr->assign(array(
00196 'displayPageHeaderTitle' => $journal->getJournalPageHeaderTitle(),
00197 'displayPageHeaderLogo' => $journal->getJournalPageHeaderLogo()
00198 ));
00199 }
00200 return $returner;
00201 } else {
00202 return false;
00203 }
00204 }
00205
00210 function uploadStyleSheet($settingName) {
00211 $journal = &Request::getJournal();
00212 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00213
00214 import('file.PublicFileManager');
00215 $fileManager = &new PublicFileManager();
00216 if ($fileManager->uploadedFileExists($settingName)) {
00217 $type = $fileManager->getUploadedFileType($settingName);
00218 if ($type != 'text/plain' && $type != 'text/css') {
00219 return false;
00220 }
00221
00222 $uploadName = $settingName . '.css';
00223 if($fileManager->uploadJournalFile($journal->getJournalId(), $settingName, $uploadName)) {
00224 $value = array(
00225 'name' => $fileManager->getUploadedFileName($settingName),
00226 'uploadName' => $uploadName,
00227 'dateUploaded' => date("Y-m-d g:i:s")
00228 );
00229
00230 $settingsDao->updateSetting($journal->getJournalId(), $settingName, $value, 'object');
00231 return true;
00232 }
00233 }
00234
00235 return false;
00236 }
00237
00238 function execute() {
00239
00240 $blockVars = array('blockSelectLeft', 'blockUnselected', 'blockSelectRight');
00241 foreach ($blockVars as $varName) {
00242 $$varName = split(' ', Request::getUserVar($varName));
00243 }
00244
00245 $plugins =& PluginRegistry::loadCategory('blocks');
00246 foreach ($plugins as $key => $junk) {
00247 $plugin =& $plugins[$key];
00248 $plugin->setEnabled(!in_array($plugin->getName(), $blockUnselected));
00249 if (in_array($plugin->getName(), $blockSelectLeft)) {
00250 $plugin->setBlockContext(BLOCK_CONTEXT_LEFT_SIDEBAR);
00251 $plugin->setSeq(array_search($key, $blockSelectLeft));
00252 }
00253 else if (in_array($plugin->getName(), $blockSelectRight)) {
00254 $plugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR);
00255 $plugin->setSeq(array_search($key, $blockSelectRight));
00256 }
00257 unset($plugin);
00258 }
00259
00260
00261 $journal = &Request::getJournal();
00262 $journalId = $journal->getJournalId();
00263 $locale = $this->getFormLocale();
00264 $settingsDao = &DAORegistry::getDAO('JournalSettingsDAO');
00265 $images = $this->images;
00266
00267 foreach($images as $settingName) {
00268 $value = $journal->getSetting($settingName);
00269 if (!empty($value)) {
00270 $imageAltText = $this->getData($this->image_settings[$settingName]);
00271 $value[$locale]['altText'] = $imageAltText[$locale];
00272 $settingsDao->updateSetting($journalId, $settingName, $value, 'object', true);
00273 }
00274 }
00275
00276
00277 return parent::execute();
00278 }
00279 }
00280
00281 ?>