BxBaseConfig.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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-label' => '#e8e8e8',
  32. 'bx-color-label-menu' => '#999999',
  33. 'bx-color-sec' => '#f2f2f2',
  34. 'bx-color-hl' => 'rgba(196, 248, 156, 0.2)',
  35. 'bx-color-active' => 'rgba(196, 248, 156, 0.4)',
  36. 'bx-border-width' => '1px',
  37. 'bx-border-type' => 'solid',
  38. 'bx-border-color' => '#d0d0d0',
  39. 'bx-border-color-hr' => 'rgba(232, 232, 232, 0.8)',
  40. 'bx-font-size-default' => '18px',
  41. 'bx-font-size-small' => '14px',
  42. 'bx-font-size-middle' => '16px',
  43. 'bx-font-size-large' => '22px',
  44. 'bx-font-size-h1' => '38px',
  45. 'bx-font-size-h2' => '24px',
  46. 'bx-font-size-h3' => '18px',
  47. 'bx-font-color-default' => '#333',
  48. 'bx-font-color-grayed' => '#999',
  49. 'bx-font-color-contrasted' => '#fff',
  50. 'bx-round-corners-radius' => '3px',
  51. 'bx-round-corners-radius-label' => '4px',
  52. 'bx-round-corners-radius-label-menu' => '12px',
  53. ),
  54. );
  55. function __construct()
  56. {
  57. parent::__construct();
  58. }
  59. public static function getInstance()
  60. {
  61. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  62. $GLOBALS['bxDolClasses'][__CLASS__] = new BxTemplConfig();
  63. return $GLOBALS['bxDolClasses'][__CLASS__];
  64. }
  65. public function __get($sName)
  66. {
  67. if (array_key_exists($sName, $this->_aConfig))
  68. return $this->_aConfig[$sName];
  69. trigger_error('Undefined property "' . $sName . '" in ' . get_class($this), E_USER_ERROR);
  70. return null;
  71. }
  72. public function __isset($sName)
  73. {
  74. return isset($this->_aConfig[$sName]);
  75. }
  76. protected function setPageWidth($sParamName)
  77. {
  78. if(!class_exists('BxDolDb') || !BxDolDb::getInstance() || empty($sParamName))
  79. return;
  80. $mixedWidth = getParam($sParamName);
  81. if(is_numeric($mixedWidth))
  82. $mixedWidth .= 'px';
  83. $this->_aConfig['aLessConfig']['bx-page-width'] = $mixedWidth;
  84. }
  85. protected function _setValue($sKey, $sDefault = '')
  86. {
  87. $sValue = trim(getParam($sKey));
  88. if(!$this->_isModule || empty($sValue))
  89. $sValue = $sDefault;
  90. return $sValue;
  91. }
  92. protected function _setSize($sKey, $sDefault = '')
  93. {
  94. if(empty($sDefault))
  95. $sDefault = '0px';
  96. $sPattern = "/([0-9\.]+\s*((px)|(rem)|(vh))){1}/";
  97. $sValue = trim(getParam($sKey));
  98. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  99. $sValue = $sDefault;
  100. return $sValue;
  101. }
  102. protected function _setSizeDivided($sValue)
  103. {
  104. $aEmpty = array(0, 0, 0, 0);
  105. $aValues = explode(' ', $sValue);
  106. if(empty($aValues) || !is_array($aValues))
  107. return $aEmpty;
  108. $aResult = $aEmpty;
  109. switch(count($aValues)) {
  110. case 1:
  111. $aResult = array($aValues[0], $aValues[0], $aValues[0], $aValues[0]);
  112. break;
  113. case 2:
  114. $aResult = array($aValues[0], $aValues[1], $aValues[0], $aValues[1]);
  115. break;
  116. case 3:
  117. $aResult = array($aValues[0], $aValues[1], $aValues[2], $aValues[1]);
  118. break;
  119. case 4:
  120. $aResult = array($aValues[0], $aValues[1], $aValues[2], $aValues[3]);
  121. break;
  122. }
  123. return $aResult;
  124. }
  125. protected function _setInnerSizeDivided($sValue, $aReductor = array('px' => 1, 'rem' => 0.0625))
  126. {
  127. $aEmpty = array(0, 0, 0, 0);
  128. $aValues = explode(' ', $sValue);
  129. if(empty($aValues) || !is_array($aValues))
  130. return $aEmpty;
  131. $aResult = $aEmpty;
  132. switch(count($aValues)) {
  133. case 1:
  134. $sValue0 = $this->_decreaseValue($aValues[0], $aReductor);
  135. $aResult = array($sValue0, $sValue0, $sValue0, $sValue0);
  136. break;
  137. case 2:
  138. $sValue0 = $this->_decreaseValue($aValues[0], $aReductor);
  139. $sValue1 = $this->_decreaseValue($aValues[1], $aReductor);
  140. $aResult = array($sValue0, $sValue1, $sValue0, $sValue1);
  141. break;
  142. case 3:
  143. $sValue0 = $this->_decreaseValue($aValues[0], $aReductor);
  144. $sValue1 = $this->_decreaseValue($aValues[1], $aReductor);
  145. $sValue2 = $this->_decreaseValue($aValues[2], $aReductor);
  146. $aResult = array($sValue0, $sValue1, $sValue2, $sValue1);
  147. break;
  148. case 4:
  149. $sValue0 = $this->_decreaseValue($aValues[0], $aReductor);
  150. $sValue1 = $this->_decreaseValue($aValues[1], $aReductor);
  151. $sValue2 = $this->_decreaseValue($aValues[2], $aReductor);
  152. $sValue3 = $this->_decreaseValue($aValues[3], $aReductor);
  153. $aResult = array($sValue0, $sValue1, $sValue2, $sValue3);
  154. break;
  155. }
  156. return $aResult;
  157. }
  158. protected function _decreaseValue($sValue, $aReductor = array('px' => 1, 'rem' => 0.0625))
  159. {
  160. $sPattern = "/(([0-9\.]+)\s*((px)|(rem))){1}/";
  161. $aMatches = array();
  162. if(!preg_match($sPattern, $sValue, $aMatches))
  163. return $sValue;
  164. if(!isset($aMatches[2]) || empty($aMatches[4]))
  165. return $sValue;
  166. if(!isset($aReductor[$aMatches[4]]))
  167. return $sValue;
  168. return ($aMatches[2] - $aReductor[$aMatches[4]]) . $aMatches[4];
  169. }
  170. protected function _setMargin($sKey, $sDefault = '')
  171. {
  172. if(empty($sDefault))
  173. $sDefault = '0px';
  174. $sPattern = "/([0-9\.]+\s*((px)|(rem))\s*){1,4}/";
  175. $sValue = trim(getParam($sKey));
  176. if(!$this->_isModule || empty($sValue) || ($sValue != 'inherit' && !preg_match($sPattern, $sValue)))
  177. $sValue = $sDefault;
  178. return $sValue;
  179. }
  180. protected function _setColorRgb($sKey, $sDefault = '')
  181. {
  182. if(empty($sDefault))
  183. $sDefault = 'rgb(51, 51, 51)';
  184. $sPattern = "/rgb\s*\(\s*[0-9]{1,3}\s*,\s*[0-9]{1,3}\s*,\s*[0-9]{1,3}\s*\)/";
  185. $sValue = trim(getParam($sKey));
  186. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  187. $sValue = $sDefault;
  188. return $sValue;
  189. }
  190. protected function _setColorRgba($sKey, $sDefault = '')
  191. {
  192. if(empty($sDefault))
  193. $sDefault = 'rgba(51, 51, 51, 1.0)';
  194. $sPattern = "/rgba?\s*\(\s*([0-9]{1,3}\s*,?\s*){3}\s*([0-9\.]+)?\s*\)/";
  195. $sValue = trim(getParam($sKey));
  196. if(!$this->_isModule || empty($sValue) || !preg_match($sPattern, $sValue))
  197. $sValue = $sDefault;
  198. return $sValue;
  199. }
  200. protected function _setBgUrl($sKey, $oStorage = null)
  201. {
  202. if(empty($oStorage))
  203. $oStorage = BxDolStorage::getObjectInstance('sys_images_custom');
  204. $iImageId = (int)getParam($sKey);
  205. if(empty($iImageId))
  206. return "none";
  207. $sImageUrl = $oStorage->getFileUrlById($iImageId);
  208. if(empty($sImageUrl))
  209. return "none";
  210. return "url('" . $sImageUrl . "')";
  211. }
  212. protected function _setBgRepeat($sKey, $sDefault = '')
  213. {
  214. if(empty($sDefault))
  215. $sDefault = 'repeat';
  216. $sValue = trim(getParam($sKey));
  217. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('no-repeat', 'repeat', 'repeat-x', 'repeat-y')))
  218. $sValue = $sDefault;
  219. return $sValue;
  220. }
  221. protected function _setBgAttachment($sKey, $sDefault = '')
  222. {
  223. if(empty($sDefault))
  224. $sDefault = 'scroll';
  225. $sValue = trim(getParam($sKey));
  226. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('fixed', 'scroll', 'local')))
  227. $sValue = $sDefault;
  228. return $sValue;
  229. }
  230. protected function _setBgSize($sKey, $sDefault = '')
  231. {
  232. if(empty($sDefault))
  233. $sDefault = 'auto';
  234. $sValue = trim(getParam($sKey));
  235. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('auto', 'cover', 'contain')))
  236. $sValue = $sDefault;
  237. return $sValue;
  238. }
  239. protected function _setShadow($sKey, $sDefault = '')
  240. {
  241. if(empty($sDefault))
  242. $sDefault = '0px 1px 3px 0px rgba(0, 0, 0, 0.25)';
  243. $sPattern = "/((-?[0-9]+\s*px\s*){4}\s*rgba\s*\(\s*([0-9]{1,3}\s*,\s*){3}\s*[0-9\.]+\s*\)\s*,?\s*)+/";
  244. $sValue = trim(getParam($sKey));
  245. if(!$this->_isModule || empty($sValue) || $sValue == 'none')
  246. $sValue = 'none';
  247. else if(!preg_match($sPattern, $sValue))
  248. $sValue = $sDefault;
  249. return $sValue;
  250. }
  251. protected function _setShadowFont($sKey, $sDefault = '')
  252. {
  253. if(empty($sDefault))
  254. $sDefault = '0px 1px 3px rgba(0, 0, 0, 0.25)';
  255. $sPattern = "/(-?[0-9]+\s*px\s*){3}\s*rgba\s*\(\s*([0-9]{1,3}\s*,\s*){3}\s*[0-9\.]+\s*\)/";
  256. $sValue = trim(getParam($sKey));
  257. if(!$this->_isModule || empty($sValue) || $sValue == 'none')
  258. $sValue = 'none';
  259. else if(!preg_match($sPattern, $sValue))
  260. $sValue = $sDefault;
  261. return $sValue;
  262. }
  263. protected function _setAlign($sKey, $sDefault = '')
  264. {
  265. if(empty($sDefault))
  266. $sDefault = 'left';
  267. $sValue = trim(getParam($sKey));
  268. if(!$this->_isModule || empty($sValue) || !in_array($sValue, array('left', 'center', 'right')))
  269. $sValue = $sDefault;
  270. return $sValue;
  271. }
  272. }
  273. /** @} */