Open Monograph Press  3.3.0
TemplateManager.inc.php
1 <?php
2 
18 import('classes.file.PublicFileManager');
19 import('lib.pkp.classes.template.PKPTemplateManager');
20 
26  public function initialize($request) {
27  parent::initialize($request);
28  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
29 
30  if (!defined('SESSION_DISABLE_INIT')) {
37  $context = $request->getContext();
38  $site = $request->getSite();
39 
40  $publicFileManager = new PublicFileManager();
41  $siteFilesDir = $request->getBaseUrl() . '/' . $publicFileManager->getSiteFilesPath();
42  $this->assign('sitePublicFilesDir', $siteFilesDir);
43  $this->assign('publicFilesDir', $siteFilesDir); // May be overridden by press
44 
45  // Pass app-specific details to template
46  $this->assign([
47  'brandImage' => 'templates/images/omp_brand.png',
48  'packageKey' => 'common.software',
49  ]);
50 
51  // Get a count of unread tasks.
52  if ($user = $request->getUser()) {
53  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
54  // Exclude certain tasks, defined in the notifications grid handler
55  import('lib.pkp.controllers.grid.notifications.TaskNotificationsGridHandler');
56  $this->assign('unreadNotificationCount', $notificationDao->getNotificationCount(false, $user->getId(), null, NOTIFICATION_LEVEL_TASK));
57  }
58 
59  if (isset($context)) {
60  $this->assign([
61  'currentPress' => $context,
62  'siteTitle' => $context->getLocalizedName(),
63  'publicFilesDir' => $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId()),
64  'primaryLocale' => $context->getPrimaryLocale(),
65  'supportedLocales' => $context->getSupportedLocaleNames(),
66  'displayPageHeaderTitle' => $context->getLocalizedPageHeaderTitle(),
67  'displayPageHeaderLogo' => $context->getLocalizedPageHeaderLogo(),
68  'displayPageHeaderLogoAltText' => $context->getLocalizedData('pageHeaderLogoImageAltText'),
69  'numPageLinks' => $context->getData('numPageLinks'),
70  'itemsPerPage' => $context->getData('itemsPerPage'),
71  'enableAnnouncements' => $context->getData('enableAnnouncements'),
72  'disableUserReg' => $context->getData('disableUserReg'),
73  ]);
74 
75  // Assign stylesheets and footer
76  $contextStyleSheet = $context->getData('styleSheet');
77  if ($contextStyleSheet) {
78  $this->addStyleSheet(
79  'contextStylesheet',
80  $request->getBaseUrl() . '/' . $publicFileManager->getContextFilesPath($context->getId()) . '/' . $contextStyleSheet['uploadName'],
81  ['priority' => STYLE_SEQUENCE_LAST]
82  );
83  }
84 
85  $this->assign('pageFooter', $context->getLocalizedData('pageFooter'));
86  } else {
87  // Check if registration is open for any contexts
88  $contextDao = Application::getContextDAO();
89  $contexts = $contextDao->getAll(true)->toArray();
90  $contextsForRegistration = [];
91  foreach($contexts as $context) {
92  if (!$context->getData('disableUserReg')) {
93  $contextsForRegistration[] = $context;
94  }
95  }
96 
97  $this->assign([
98  'contexts' => $contextsForRegistration,
99  'disableUserReg' => empty($contextsForRegistration),
100  'displayPageHeaderTitle' => $site->getLocalizedPageHeaderTitle(),
101  'displayPageHeaderLogo' => $site->getLocalizedData('pageHeaderTitleImage'),
102  'siteTitle' => $site->getLocalizedTitle(),
103  'primaryLocale' => $site->getPrimaryLocale(),
104  'supportedLocales' => $site->getSupportedLocaleNames(),
105  'pageFooter' => $site->getLocalizedData('pageFooter'),
106  ]);
107  }
108  }
109  }
110 
114  function setupBackendPage() {
115  parent::setupBackendPage();
116 
117  $request = Application::get()->getRequest();
118  if (defined('SESSION_DISABLE_INIT')
119  || !$request->getContext()
120  || !$request->getUser()) {
121  return;
122  }
123 
124  $router = $request->getRouter();
125  $handler = $router->getHandler();
126  $userRoles = (array) $handler->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES);
127 
128  $menu = (array) $this->getState('menu');
129 
130  // Add catalog after submissions items
131  if (in_array(ROLE_ID_MANAGER, $userRoles)) {
132  $catalogLink = [
133  'name' => __('navigation.catalog'),
134  'url' => $router->url($request, null, 'manageCatalog'),
135  'isCurrent' => $request->getRequestedPage() === 'manageCatalog',
136  ];
137 
138  $index = array_search('submissions', array_keys($menu));
139  if ($index === false || count($menu) <= ($index + 1)) {
140  $menu['catalog'] = $catalogLink;
141  } else {
142  $menu = array_slice($menu, 0, $index + 1, true) +
143  ['catalog' => $catalogLink] +
144  array_slice($menu, $index + 1, null, true);
145  }
146  }
147 
148  $this->setState(['menu' => $menu]);
149  }
150 }
PKPTemplateManager\addStyleSheet
addStyleSheet($name, $style, $args=[])
Definition: PKPTemplateManager.inc.php:468
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:145
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPTemplateManager
Definition: PKPTemplateManager.inc.php:50
PKPTemplateManager\getState
getState($key)
Definition: PKPTemplateManager.inc.php:581
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPTemplateManager\setState
setState($data)
Definition: PKPTemplateManager.inc.php:592
PublicFileManager
Wrapper class for uploading files to a site/press' public directory.
Definition: PublicFileManager.inc.php:19
TemplateManager\initialize
initialize($request)
Definition: TemplateManager.inc.php:26
TemplateManager
Class for accessing the underlying template engine. Currently integrated with Smarty (from http://sma...
Definition: TemplateManager.inc.php:21
TemplateManager\setupBackendPage
setupBackendPage()
Definition: TemplateManager.inc.php:114
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235