Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AppearanceForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.tab.settings.form.ContextSettingsForm');
17 
19 
21  var $_imagesSettingsName;
22 
28  function AppearanceForm($wizardMode = false, $additionalSettings = array()) {
29 
30  $settings = array_merge($additionalSettings, array(
31  'pageHeaderTitleType' => 'int',
32  'pageHeaderTitle' => 'string',
33  'additionalHomeContent' => 'string',
34  'pageHeader' => 'string',
35  'pageFooter' => 'string',
36  'navItems' => 'object',
37  'itemsPerPage' => 'int',
38  'numPageLinks' => 'int',
39  'themePluginPath' => 'string',
40  ));
41 
42  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
43 
44  parent::ContextSettingsForm($settings, 'controllers/tab/settings/appearance/form/appearanceForm.tpl', $wizardMode);
45  }
46 
47 
48  //
49  // Getters and Setters
50  //
55  function getImagesSettingsName() {
56  return array(
57  'homepageImage' => 'common.homepageImage.altText',
58  'pageHeaderTitleImage' => 'common.pageHeader.altText',
59  'pageHeaderLogoImage' => 'common.pageHeaderLogo.altText',
60  );
61  }
62 
63  //
64  // Implement template methods from Form.
65  //
69  function getLocaleFieldNames() {
70  return array(
71  'pageHeaderTitleType',
72  'pageHeaderTitle',
73  'additionalHomeContent',
74  'pageHeader',
75  'pageFooter',
76  );
77  }
78 
79 
80  //
81  // Extend methods from ContextSettingsForm.
82  //
86  function fetch($request) {
87  // Get all upload form image link actions.
88  $uploadImageLinkActions = array();
89  foreach ($this->getImagesSettingsName() as $settingName => $altText) {
90  $uploadImageLinkActions[$settingName] = $this->_getFileUploadLinkAction($settingName, 'image', $request);
91  }
92  // Get the css upload link action.
93  $uploadCssLinkAction = $this->_getFileUploadLinkAction('styleSheet', 'css', $request);
94 
95  $imagesViews = $this->_renderAllFormImagesViews($request);
96  $cssView = $this->renderFileView('styleSheet', $request);
97 
98  $templateMgr = TemplateManager::getManager($request);
99  $templateMgr->assign('uploadImageLinkActions', $uploadImageLinkActions);
100  $templateMgr->assign('uploadCssLinkAction', $uploadCssLinkAction);
101 
102  $themePlugins = PluginRegistry::loadCategory('themes');
103  $themePluginOptions = array();
104  foreach ($themePlugins as $themePlugin) {
105  $themePluginOptions[basename($themePlugin->getPluginPath())] = $themePlugin->getDisplayName();
106  }
107  $templateMgr->assign('themePluginOptions', $themePluginOptions);
108 
109  $params = array(
110  'imagesViews' => $imagesViews,
111  'styleSheetView' => $cssView,
112  'locale' => AppLocale::getLocale()
113  );
114 
115  return parent::fetch($request, $params);
116  }
117 
118 
119  //
120  // Public methods.
121  //
129  function renderFileView($fileSettingName, $request) {
130  $file = $this->getData($fileSettingName);
131  $locale = AppLocale::getLocale();
133  // Check if the file is localized.
134  if (!is_null($file) && key_exists($locale, $file)) {
135  // We use the current localized file value.
136  $file = $file[$locale];
137  }
138 
139  // Only render the file view if we have a file.
140  if (is_array($file)) {
141  $templateMgr = TemplateManager::getManager($request);
142  $deleteLinkAction = $this->_getDeleteFileLinkAction($fileSettingName, $request);
143 
144  // Get the right template to render the view.
145  $imagesSettingsName = $this->getImagesSettingsName();
146  if (in_array($fileSettingName, array_keys($imagesSettingsName))) {
147  $template = 'controllers/tab/settings/formImageView.tpl';
148 
149  // Get the common alternate text for the image.
150  $localeKey = $imagesSettingsName[$fileSettingName];
151  $commonAltText = __($localeKey);
152  $templateMgr->assign('commonAltText', $commonAltText);
153  } else {
154  $template = 'controllers/tab/settings/formFileView.tpl';
155  }
156 
157  $templateMgr->assign('file', $file);
158  $templateMgr->assign('deleteLinkAction', $deleteLinkAction);
159  $templateMgr->assign('fileSettingName', $fileSettingName);
160 
161  return $templateMgr->fetch($template);
162  } else {
163  return null;
164  }
165  }
166 
173  function deleteFile($fileSettingName, $request) {
174  $context = $request->getContext();
175  $locale = AppLocale::getLocale();
177  // Get the file.
178  $file = $this->getData($fileSettingName);
179 
180  // Check if the file is localized.
181  if (key_exists($locale, $file)) {
182  // We use the current localized file value.
183  $file = $file[$locale];
184  } else {
185  $locale = null;
186  }
187 
188  // Deletes the file and its settings.
189  import('classes.file.PublicFileManager');
190  $publicFileManager = new PublicFileManager();
191  if ($publicFileManager->removeContextFile($context->getAssocType(), $context->getId(), $file['uploadName'])) {
192  $settingsDao = $context->getSettingsDao();
193  $settingsDao->deleteSetting($context->getId(), $fileSettingName, $locale);
194  return true;
195  } else {
196  return false;
197  }
198  }
199 
203  function execute($request) {
204  parent::execute($request);
205 
206  // Save block plugins context positions.
207  import('lib.pkp.classes.controllers.listbuilder.ListbuilderHandler');
208  ListbuilderHandler::unpack($request, $request->getUserVar('blocks'));
209 
210  // Activate the selected theme plugin
211  $context = $request->getContext();
212  $themePlugins = PluginRegistry::loadCategory('themes');
213  $selectedThemePluginPath = $this->getData('themePluginPath');
214  $selectedThemePlugin = null;
215  foreach ($themePlugins as $themePlugin) {
216  if (basename($themePlugin->getPluginPath()) != $selectedThemePluginPath) {
217  if ($themePlugin->getEnabled()) {
218  $themePlugin->setEnabled(false);
219  }
220  } else {
221  $selectedThemePlugin = $themePlugin;
222  }
223  }
224  if ($selectedThemePlugin) {
225  // Activate the selected theme to trigger a CSS recompile.
226  $selectedThemePlugin->setEnabled(true);
227  } else {
228  assert(false); // Couldn't identify the selected theme plugin
229  }
230  }
231 
238  function updateEntry($request, $rowId, $newRowId) {
239  $plugins =& PluginRegistry::loadCategory('blocks');
240  $plugin =& $plugins[$rowId]; // Ref hack
241  switch ($newRowId['listId']) {
242  case 'unselected':
243  $plugin->setEnabled(false);
244  break;
245  case 'leftContext':
246  $plugin->setEnabled(true);
247  $plugin->setBlockContext(BLOCK_CONTEXT_LEFT_SIDEBAR);
248  $plugin->setSeq((int) $newRowId['sequence']);
249  break;
250  case 'rightContext':
251  $plugin->setEnabled(true);
252  $plugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR);
253  $plugin->setSeq((int) $newRowId['sequence']);
254  break;
255  default:
256  assert(false);
257  }
258  }
259 
263  function deleteEntry() {
264  return false;
265  }
270  function insertEntry() {
271  return false;
272  }
274 
275  //
276  // Private helper methods
277  //
283  function _renderAllFormImagesViews($request) {
284  $imagesViews = array();
285  foreach ($this->getImagesSettingsName() as $imageSettingName => $altText) {
286  $imagesViews[$imageSettingName] = $this->renderFileView($imageSettingName, $request);
287  }
288 
289  return $imagesViews;
290  }
291 
299  function _getFileUploadLinkAction($settingName, $fileType, $request) {
300  $router = $request->getRouter();
301  import('lib.pkp.classes.linkAction.request.AjaxModal');
302  import('lib.pkp.classes.linkAction.LinkAction');
303  return new LinkAction(
304  'uploadFile-' . $settingName,
305  new AjaxModal(
306  $router->url(
307  $request, null, null, 'showFileUploadForm', null, array(
308  'fileSettingName' => $settingName,
309  'fileType' => $fileType
310  )
311  ),
312  __('common.upload'),
313  'modal_add_file'
314  ),
315  __('common.upload'),
316  'add'
317  );
318  }
319 
326  function _getDeleteFileLinkAction($settingName, $request) {
327  $router = $request->getRouter();
328  import('lib.pkp.classes.linkAction.request.RemoteActionConfirmationModal');
330  return new LinkAction(
331  'deleteFile-' . $settingName,
333  __('common.confirmDelete'), null,
334  $router->url(
335  $request, null, null, 'deleteFile', null, array(
336  'fileSettingName' => $settingName,
337  'tab' => 'appearance'
338  )
339  ),
340  'modal_delete'
341  ),
342  __('common.delete'),
343  null
344  );
345  }
346 }
347 
348 ?>
_getFileUploadLinkAction($settingName, $fileType, $request)
Wrapper class for uploading files to a site/press&#39; public directory.
static requireComponents()
deleteFile($fileSettingName, $request)
static & loadCategory($category, $enabledOnly=false, $mainContextId=null)
_getDeleteFileLinkAction($settingName, $request)
getData($key)
Definition: Form.inc.php:210
A modal that retrieves its content from via AJAX.
static getLocale()
updateEntry($request, $rowId, $newRowId)
Base class for forms that manage context settings data.
Class defining a simple confirmation modal with a remote action and ok/cancel buttons.
Form to edit appearance settings.
_renderAllFormImagesViews($request)
AppearanceForm($wizardMode=false, $additionalSettings=array())
renderFileView($fileSettingName, $request)
unpack($request, $data, $deletionCallback=null, $insertionCallback=null, $updateCallback=null)
Base class defining an action that can be performed by the user in the user interface.