BxBaseConfig.php 11 KB

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