BxBaseConfig.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php defined('BX_DOL') or defined('BX_DOL_INSTALL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. class BxBaseConfig extends BxDol implements iBxDolSingleton
  10. {
  11. protected $_aConfig = array (
  12. 'bAllowUnicodeInPreg' => false, ///< allow unicode in regular expressions
  13. 'aLessConfig' => array (
  14. 'bx-page-width' => '1000px',
  15. 'bx-margin' => '20px',
  16. 'bx-margin-sec' => '10px',
  17. 'bx-margin-thd' => '5px',
  18. 'bx-padding' => '20px',
  19. 'bx-padding-sec' => '10px',
  20. 'bx-padding-thd' => '5px',
  21. 'bx-font-family' => 'Helvetica, Arial, sans-serif',
  22. 'bx-size-avatar' => '96px',
  23. 'bx-size-thumb' => '48px',
  24. 'bx-size-icon' => '32px',
  25. 'bx-size-gallery-img-width' => '300px',
  26. 'bx-size-gallery-img-height' => '200px',
  27. 'bx-color-page' => '#fff',
  28. 'bx-color-block' => '#fff',
  29. 'bx-color-box' => 'rgba(242, 242, 242, 1.0)',
  30. 'bx-color-box-hover' => 'rgba(242, 242, 242, 0.8)',
  31. 'bx-color-sec' => '#f2f2f2',
  32. 'bx-color-hl' => 'rgba(196, 248, 156, 0.2)',
  33. 'bx-color-active' => 'rgba(196, 248, 156, 0.4)',
  34. 'bx-border-width' => '1px',
  35. 'bx-border-type' => 'solid',
  36. 'bx-border-color' => '#d0d0d0',
  37. 'bx-font-size-default' => '18px',
  38. 'bx-font-size-small' => '14px',
  39. 'bx-font-size-middle' => '16px',
  40. 'bx-font-size-large' => '22px',
  41. 'bx-font-size-h1' => '38px',
  42. 'bx-font-size-h2' => '24px',
  43. 'bx-font-size-h3' => '18px',
  44. 'bx-font-color-default' => '#333',
  45. 'bx-font-color-grayed' => '#999',
  46. 'bx-font-color-contrasted' => '#fff',
  47. 'bx-round-corners-radius' => '3px',
  48. ),
  49. );
  50. function __construct()
  51. {
  52. parent::__construct();
  53. }
  54. public static function getInstance()
  55. {
  56. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  57. $GLOBALS['bxDolClasses'][__CLASS__] = new BxTemplConfig();
  58. return $GLOBALS['bxDolClasses'][__CLASS__];
  59. }
  60. public function __get($sName)
  61. {
  62. if (array_key_exists($sName, $this->_aConfig))
  63. return $this->_aConfig[$sName];
  64. trigger_error('Undefined property "' . $sName . '" in ' . get_class($this), E_USER_ERROR);
  65. return null;
  66. }
  67. public function __isset($sName)
  68. {
  69. return isset($this->_aConfig[$sName]);
  70. }
  71. protected function setPageWidth($sParamName)
  72. {
  73. if(!class_exists('BxDolDb') || !BxDolDb::getInstance() || empty($sParamName))
  74. return;
  75. $mixedWidth = getParam($sParamName);
  76. if(is_numeric($mixedWidth))
  77. $mixedWidth .= 'px';
  78. $this->_aConfig['aLessConfig']['bx-page-width'] = $mixedWidth;
  79. }
  80. protected function _setValue($sKey, $sDefault = '')
  81. {
  82. $sValue = trim(getParam($sKey));
  83. if(!$this->_isModule || empty($sValue))
  84. $sValue = $sDefault;
  85. return $sValue;
  86. }
  87. protected function _setSize($sKey, $sDefault = '')
  88. {
  89. if(empty($sDefault))
  90. $sDefault = '0px';
  91. $sPattern = "/([0-9\.]+\s*((px)|(rem)|(vh))){1}/";
  92. $sValue = trim(getParam($sKey));
  93. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  94. $sValue = $sDefault;
  95. return $sValue;
  96. }
  97. protected function _setSizeDivided($sValue)
  98. {
  99. $aEmpty = array(0, 0, 0, 0);
  100. $aValues = explode(' ', $sValue);
  101. if(empty($aValues) || !is_array($aValues))
  102. return $aEmpty;
  103. $aResult = $aEmpty;
  104. switch(count($aValues)) {
  105. case 1:
  106. $aResult = array($aValues[0], $aValues[0], $aValues[0], $aValues[0]);
  107. break;
  108. case 2:
  109. $aResult = array($aValues[0], $aValues[1], $aValues[0], $aValues[1]);
  110. break;
  111. case 3:
  112. $aResult = array($aValues[0], $aValues[1], $aValues[2], $aValues[1]);
  113. break;
  114. case 4:
  115. $aResult = array($aValues[0], $aValues[1], $aValues[2], $aValues[3]);
  116. break;
  117. }
  118. return $aResult;
  119. }
  120. protected function _setMargin($sKey, $sDefault = '')
  121. {
  122. if(empty($sDefault))
  123. $sDefault = '0px';
  124. $sPattern = "/([0-9\.]+\s*((px)|(rem))\s*){1,4}/";
  125. $sValue = trim(getParam($sKey));
  126. if(!$this->_isModule || empty($sValue) || ($sValue != 'inherit' && !preg_match($sPattern, $sValue)))
  127. $sValue = $sDefault;
  128. return $sValue;
  129. }
  130. protected function _setColorRgb($sKey, $sDefault = '')
  131. {
  132. if(empty($sDefault))
  133. $sDefault = 'rgb(51, 51, 51)';
  134. $sPattern = "/rgb\s*\(\s*[0-9]{1,3}\s*,\s*[0-9]{1,3}\s*,\s*[0-9]{1,3}\s*\)/";
  135. $sValue = trim(getParam($sKey));
  136. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  137. $sValue = $sDefault;
  138. return $sValue;
  139. }
  140. protected function _setColorRgba($sKey, $sDefault = '')
  141. {
  142. if(empty($sDefault))
  143. $sDefault = 'rgba(51, 51, 51, 1.0)';
  144. $sPattern = "/rgba?\s*\(\s*([0-9]{1,3}\s*,?\s*){3}\s*([0-9\.]+)?\s*\)/";
  145. $sValue = trim(getParam($sKey));
  146. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  147. $sValue = $sDefault;
  148. return $sValue;
  149. }
  150. protected function _setBgUrl($sKey, $oStorage = null)
  151. {
  152. if(empty($oStorage))
  153. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  154. $iImageId = (int)getParam($sKey);
  155. if(empty($iImageId))
  156. return "none";
  157. $sImageUrl = $oStorage->getFileUrlById($iImageId);
  158. if(empty($sImageUrl))
  159. return "none";
  160. return "url('" . $sImageUrl . "')";
  161. }
  162. protected function _setBgRepeat($sKey, $sDefault = '')
  163. {
  164. if(empty($sDefault))
  165. $sDefault = 'repeat';
  166. $sValue = trim(getParam($sKey));
  167. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('no-repeat', 'repeat', 'repeat-x', 'repeat-y')))
  168. $sValue = $sDefault;
  169. return $sValue;
  170. }
  171. protected function _setBgAttachment($sKey, $sDefault = '')
  172. {
  173. if(empty($sDefault))
  174. $sDefault = 'scroll';
  175. $sValue = trim(getParam($sKey));
  176. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('fixed', 'scroll', 'local')))
  177. $sValue = $sDefault;
  178. return $sValue;
  179. }
  180. protected function _setBgSize($sKey, $sDefault = '')
  181. {
  182. if(empty($sDefault))
  183. $sDefault = 'auto';
  184. $sValue = trim(getParam($sKey));
  185. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('auto', 'cover', 'contain')))
  186. $sValue = $sDefault;
  187. return $sValue;
  188. }
  189. protected function _setShadow($sKey, $sDefault = '')
  190. {
  191. if(empty($sDefault))
  192. $sDefault = '0px 1px 3px 0px rgba(0, 0, 0, 0.25)';
  193. $sPattern = "/((-?[0-9]+\s*px\s*){4}\s*rgba\s*\(\s*([0-9]{1,3}\s*,\s*){3}\s*[0-9\.]+\s*\)\s*,?\s*)+/";
  194. $sValue = trim(getParam($sKey));
  195. if(!$this->_isModule || empty($sValue) || $sValue == 'none')
  196. $sValue = 'none';
  197. else if(!preg_match($sPattern, $sValue))
  198. $sValue = $sDefault;
  199. return $sValue;
  200. }
  201. protected function _setShadowFont($sKey, $sDefault = '')
  202. {
  203. if(empty($sDefault))
  204. $sDefault = '0px 1px 3px rgba(0, 0, 0, 0.25)';
  205. $sPattern = "/(-?[0-9]+\s*px\s*){3}\s*rgba\s*\(\s*([0-9]{1,3}\s*,\s*){3}\s*[0-9\.]+\s*\)/";
  206. $sValue = trim(getParam($sKey));
  207. if(!$this->_isModule || empty($sValue) || $sValue == 'none')
  208. $sValue = 'none';
  209. else if(!preg_match($sPattern, $sValue))
  210. $sValue = $sDefault;
  211. return $sValue;
  212. }
  213. protected function _setAlign($sKey, $sDefault = '')
  214. {
  215. if(empty($sDefault))
  216. $sDefault = 'left';
  217. $sValue = trim(getParam($sKey));
  218. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('left', 'center', 'right')))
  219. $sValue = $sDefault;
  220. return $sValue;
  221. }
  222. }
  223. /** @} */