PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/pkp/classes/site/Site.inc.php

https://github.com/lib-uoguelph-ca/ocs
PHP | 297 lines | 138 code | 44 blank | 115 comment | 15 complexity | 3cebb60e2f89b729b9da1ecaa5815783 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * @defgroup site
  4. */
  5. /**
  6. * @file classes/site/Site.inc.php
  7. *
  8. * Copyright (c) 2000-2012 John Willinsky
  9. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  10. *
  11. * @class Site
  12. * @ingroup site
  13. * @see SiteDAO
  14. *
  15. * @brief Describes system-wide site properties.
  16. */
  17. // $Id$
  18. class Site extends DataObject {
  19. /**
  20. * Constructor.
  21. */
  22. function Site() {
  23. parent::DataObject();
  24. }
  25. /**
  26. * Return associative array of all locales supported by the site.
  27. * These locales are used to provide a language toggle on the main site pages.
  28. * @return array
  29. */
  30. function &getSupportedLocaleNames() {
  31. $supportedLocales =& Registry::get('siteSupportedLocales', true, null);
  32. if ($supportedLocales === null) {
  33. $supportedLocales = array();
  34. $localeNames =& AppLocale::getAllLocales();
  35. $locales = $this->getSupportedLocales();
  36. foreach ($locales as $localeKey) {
  37. $supportedLocales[$localeKey] = $localeNames[$localeKey];
  38. }
  39. asort($supportedLocales);
  40. }
  41. return $supportedLocales;
  42. }
  43. //
  44. // Get/set methods
  45. //
  46. /**
  47. * Get localized site title.
  48. */
  49. function getLocalizedTitle() {
  50. return $this->getLocalizedSetting('title');
  51. }
  52. function getSiteTitle() {
  53. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  54. return $this->getLocalizedTitle();
  55. }
  56. /**
  57. * Get "localized" site page title (if applicable).
  58. * @return string
  59. */
  60. function getLocalizedPageHeaderTitle() {
  61. $typeArray = $this->getSetting('pageHeaderTitleType');
  62. $imageArray = $this->getSetting('pageHeaderTitleImage');
  63. $titleArray = $this->getSetting('title');
  64. $title = null;
  65. foreach (array(AppLocale::getLocale(), AppLocale::getPrimaryLocale()) as $locale) {
  66. if (isset($typeArray[$locale]) && $typeArray[$locale]) {
  67. if (isset($imageArray[$locale])) $title = $imageArray[$locale];
  68. }
  69. if (empty($title) && isset($titleArray[$locale])) $title = $titleArray[$locale];
  70. if (!empty($title)) return $title;
  71. }
  72. return null;
  73. }
  74. function getSitePageHeaderTitle() {
  75. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  76. return $this->getLocalizedPageHeaderTitle();
  77. }
  78. /**
  79. * Get localized site logo type.
  80. * @return boolean
  81. */
  82. function getLocalizedPageHeaderTitleType() {
  83. return $this->getLocalizedData('pageHeaderTitleType');
  84. }
  85. function getSitePageHeaderTitleType() {
  86. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  87. return $this->getLocalizedPageHeaderTitleType();
  88. }
  89. /**
  90. * Get original site stylesheet filename.
  91. * @return string
  92. */
  93. function getOriginalStyleFilename() {
  94. return $this->getData('originalStyleFilename');
  95. }
  96. /**
  97. * Set original site stylesheet filename.
  98. * @param $originalStyleFilename string
  99. */
  100. function setOriginalStyleFilename($originalStyleFilename) {
  101. return $this->setData('originalStyleFilename', $originalStyleFilename);
  102. }
  103. /**
  104. * Get localized site intro.
  105. */
  106. function getLocalizedIntro() {
  107. return $this->getLocalizedSetting('intro');
  108. }
  109. function getSiteIntro() {
  110. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  111. return $this->getLocalizedIntro();
  112. }
  113. /**
  114. * Get redirect
  115. * @return int
  116. */
  117. function getRedirect() {
  118. return $this->getData('redirect');
  119. }
  120. /**
  121. * Set redirect
  122. * @param $redirect int
  123. */
  124. function setRedirect($redirect) {
  125. return $this->setData('redirect', (int)$redirect);
  126. }
  127. /**
  128. * Get localized site about statement.
  129. */
  130. function getLocalizedAbout() {
  131. return $this->getLocalizedSetting('about');
  132. }
  133. function getSiteAbout() {
  134. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  135. return $this->getLocalizedAbout();
  136. }
  137. /**
  138. * Get localized site contact name.
  139. */
  140. function getLocalizedContactName() {
  141. return $this->getLocalizedSetting('contactName');
  142. }
  143. function getSiteContactName() {
  144. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  145. return $this->getLocalizedContactName();
  146. }
  147. /**
  148. * Get localized site contact email.
  149. */
  150. function getLocalizedContactEmail() {
  151. return $this->getLocalizedSetting('contactEmail');
  152. }
  153. function getSiteContactEmail() {
  154. if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
  155. return $this->getLocalizedContactEmail();
  156. }
  157. /**
  158. * Get minimum password length.
  159. * @return int
  160. */
  161. function getMinPasswordLength() {
  162. return $this->getData('minPasswordLength');
  163. }
  164. /**
  165. * Set minimum password length.
  166. * @param $minPasswordLength int
  167. */
  168. function setMinPasswordLength($minPasswordLength) {
  169. return $this->setData('minPasswordLength', $minPasswordLength);
  170. }
  171. /**
  172. * Get primary locale.
  173. * @return string
  174. */
  175. function getPrimaryLocale() {
  176. return $this->getData('primaryLocale');
  177. }
  178. /**
  179. * Set primary locale.
  180. * @param $primaryLocale string
  181. */
  182. function setPrimaryLocale($primaryLocale) {
  183. return $this->setData('primaryLocale', $primaryLocale);
  184. }
  185. /**
  186. * Get installed locales.
  187. * @return array
  188. */
  189. function getInstalledLocales() {
  190. $locales = $this->getData('installedLocales');
  191. return isset($locales) ? $locales : array();
  192. }
  193. /**
  194. * Set installed locales.
  195. * @param $installedLocales array
  196. */
  197. function setInstalledLocales($installedLocales) {
  198. return $this->setData('installedLocales', $installedLocales);
  199. }
  200. /**
  201. * Get array of all supported locales (for static text).
  202. * @return array
  203. */
  204. function getSupportedLocales() {
  205. $locales = $this->getData('supportedLocales');
  206. return isset($locales) ? $locales : array();
  207. }
  208. /**
  209. * Set array of all supported locales (for static text).
  210. * @param $supportedLocales array
  211. */
  212. function setSupportedLocales($supportedLocales) {
  213. return $this->setData('supportedLocales', $supportedLocales);
  214. }
  215. /**
  216. * Get the local name under which the site-wide locale file is stored.
  217. * @return string
  218. */
  219. function getSiteStyleFilename() {
  220. return 'sitestyle.css';
  221. }
  222. /**
  223. * Retrieve a site setting value.
  224. * @param $name string
  225. * @param $locale string
  226. * @return mixed
  227. */
  228. function &getSetting($name, $locale = null) {
  229. $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
  230. $setting =& $siteSettingsDao->getSetting($name, $locale);
  231. return $setting;
  232. }
  233. function getLocalizedSetting($name) {
  234. $returner = $this->getSetting($name, AppLocale::getLocale());
  235. if ($returner === null) {
  236. unset($returner);
  237. $returner = $this->getSetting($name, AppLocale::getPrimaryLocale());
  238. }
  239. return $returner;
  240. }
  241. /**
  242. * Update a site setting value.
  243. * @param $name string
  244. * @param $value mixed
  245. * @param $type string optional
  246. * @param $isLocalized boolean optional
  247. */
  248. function updateSetting($name, $value, $type = null, $isLocalized = false) {
  249. $siteSettingsDao =& DAORegistry::getDAO('SiteSettingsDAO');
  250. return $siteSettingsDao->updateSetting($name, $value, $type, $isLocalized);
  251. }
  252. }
  253. ?>