BxDolInstallerUtils.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolIO');
  10. class BxDolInstallerUtils extends BxDolIO
  11. {
  12. function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. function isXsltEnabled()
  17. {
  18. if (((int)phpversion()) >= 5) {
  19. if (class_exists ('DOMDocument') && class_exists ('XsltProcessor'))
  20. return true;
  21. } else {
  22. if (function_exists('domxml_xslt_stylesheet_file'))
  23. return true;
  24. elseif (function_exists ('xslt_create'))
  25. return true;
  26. }
  27. return false;
  28. }
  29. function isAllowUrlInclude()
  30. {
  31. if (version_compare(phpversion(), "5.2", ">") == 1) {
  32. $sAllowUrlInclude = ini_get('allow_url_include');
  33. return !($sAllowUrlInclude == 0);
  34. };
  35. return false;
  36. }
  37. function isModuleInstalled($sUri)
  38. {
  39. bx_import('BxDolModuleQuery');
  40. return BxDolModuleQuery::getInstance()->isModule($sUri);
  41. }
  42. function addHtmlFields ($a)
  43. {
  44. $this->_addFields ('html', $a);
  45. }
  46. function removeHtmlFields ()
  47. {
  48. $this->_removeFields('html');
  49. }
  50. function addJsonFields ($a)
  51. {
  52. $this->_addFields ('json', $a);
  53. }
  54. function removeJsonFields ()
  55. {
  56. $this->_removeFields('json');
  57. }
  58. function addExceptionsFields ($a)
  59. {
  60. $this->_addFields ('exceptions', $a);
  61. }
  62. function removeExceptionsFields ()
  63. {
  64. $this->_removeFields('exceptions');
  65. }
  66. function updateSystemExceptions ()
  67. {
  68. $s = getParam('sys_exceptions_fields');
  69. if (!$s) {
  70. $a = array ();
  71. } else {
  72. $a = unserialize($s);
  73. unset($a['system']);
  74. }
  75. $a['system'] = array(
  76. 'COOKIE.memberSession',
  77. );
  78. $s = serialize ($a);
  79. setParam ('sys_exceptions_fields', $s);
  80. // recreate cache
  81. $GLOBALS['MySQL']->cleanCache ('sys_exceptions_fields');
  82. $GLOBALS['MySQL']->fromCache ('sys_exceptions_fields', 'getOne', "SELECT `VALUE` FROM `sys_options` WHERE `Name` = 'sys_exceptions_fields' LIMIT 1");
  83. }
  84. function updateEmailTemplatesExceptions ()
  85. {
  86. $s = getParam('sys_exceptions_fields');
  87. if (!$s) {
  88. $a = array ();
  89. } else {
  90. $a = unserialize($s);
  91. unset($a['system_email_templates']);
  92. }
  93. $a['system_email_templates'] = $this->_getEmailTemplatesHtmlFields();
  94. $s = serialize ($a);
  95. setParam ('sys_exceptions_fields', $s);
  96. // recreate cache
  97. $oDb = BxDolDb::getInstance();
  98. $oDb->cleanCache ('sys_exceptions_fields');
  99. $oDb->fromCache ('sys_exceptions_fields', 'getOne', "SELECT `VALUE` FROM `sys_options` WHERE `Name` = 'sys_exceptions_fields' LIMIT 1");
  100. }
  101. function updateProfileFieldsHtml ()
  102. {
  103. $s = getParam('sys_html_fields');
  104. if (!$s) {
  105. $a = array ();
  106. } else {
  107. $a = unserialize($s);
  108. unset($a['system_profile_html']);
  109. }
  110. $a['system_profile_html'] = $this->_getSystemProfileHtmlFields();
  111. $s = serialize ($a);
  112. setParam ('sys_html_fields', $s);
  113. // recreate cache
  114. $oDb = BxDolDb::getInstance();
  115. $oDb->cleanCache ('sys_html_fields');
  116. $oDb->fromCache ('sys_html_fields', 'getOne', "SELECT `VALUE` FROM `sys_options` WHERE `Name` = 'sys_html_fields' LIMIT 1");
  117. }
  118. //--- Protected methods ---//
  119. function _getEmailTemplatesHtmlFields ()
  120. {
  121. $oDb = BxDolDb::getInstance();
  122. $aRet = array ();
  123. $a = $oDb->getAll ("SELECT `Name` FROM `sys_email_templates`");
  124. foreach ($a as $r) {
  125. $aRet[] = 'POST.' . $r['Name'] . '_Body';
  126. $aRet[] = 'REQUEST.' . $r['Name'] . '_Body';
  127. $aRet[] = 'POST.' . $r['Name'] . '_Subject';
  128. $aRet[] = 'REQUEST.' . $r['Name'] . '_Subject';
  129. }
  130. return $aRet;
  131. }
  132. function _getSystemProfileHtmlFields ()
  133. {
  134. $oDb = BxDolDb::getInstance();
  135. $aRet = array ();
  136. $a = $oDb->getAll ("SELECT `Name` FROM `sys_profile_fields` WHERE `Type` = 'html_area'");
  137. foreach ($a as $r) {
  138. $aRet[] = 'POST.' . $r['Name'];
  139. $aRet[] = 'REQUEST.' . $r['Name'];
  140. }
  141. return $aRet;
  142. }
  143. function _addFields ($sType, $a)
  144. {
  145. switch ($sType) {
  146. case 'html':
  147. case 'json':
  148. case 'exceptions':
  149. break;
  150. default:
  151. return array();
  152. }
  153. $s = getParam("sys_{$sType}_fields");
  154. if (!$s) {
  155. $a = array ($this->_aConfig['home_uri'] => $a);
  156. } else {
  157. $a = array_merge (unserialize($s), array ($this->_aConfig['home_uri'] => $a));
  158. }
  159. $s = serialize ($a);
  160. setParam ("sys_{$sType}_fields", $s);
  161. }
  162. function _removeFields ($sType)
  163. {
  164. switch ($sType) {
  165. case 'html':
  166. case 'json':
  167. case 'exceptions':
  168. break;
  169. default:
  170. return array();
  171. }
  172. $s = getParam("sys_{$sType}_fields");
  173. if (!$s) {
  174. return;
  175. }
  176. $a = unserialize($s);
  177. unset ($a[$this->_aConfig['home_uri']]);
  178. $s = serialize ($a);
  179. setParam ("sys_{$sType}_fields", $s);
  180. }
  181. }
  182. /** @} */