PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/contact-form-7-to-database-extension/CFDBPermittedFunctions.php

https://gitlab.com/mattswann/launch-housing
PHP | 237 lines | 189 code | 19 blank | 29 comment | 5 complexity | a14a3b9ffafd770f0354fbb2598b7c4d MD5 | raw file
  1. <?php
  2. /*
  3. "Contact Form to Database" Copyright (C) 2011-2014 Michael Simpson (email : michael.d.simpson@gmail.com)
  4. This file is part of Contact Form to Database.
  5. Contact Form to Database is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Contact Form to Database is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Contact Form to Database.
  15. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * @singleton
  19. */
  20. class CFDBPermittedFunctions {
  21. var $permitAllFunctions = false;
  22. var $permittedFunctions;
  23. static $defaultPermitted = array(
  24. // PHP functions
  25. 'addcslashes',
  26. 'addslashes',
  27. 'chop',
  28. 'chr',
  29. 'count_chars',
  30. 'localeconv',
  31. 'ltrim',
  32. 'md5',
  33. 'money_format',
  34. 'nl2br',
  35. 'number_format',
  36. 'rtrim',
  37. 'sha1',
  38. 'str_ireplace',
  39. 'str_pad',
  40. 'str_repeat',
  41. 'str_replace',
  42. 'str_shuffle',
  43. 'str_word_count',
  44. 'strcasecmp',
  45. 'strchr',
  46. 'strcmp',
  47. 'strcoll',
  48. 'strcspn',
  49. 'strip_tags',
  50. 'stripcslashes',
  51. 'stripos',
  52. 'strlen',
  53. 'strnatcasecmp',
  54. 'strnatcmp',
  55. 'strncasecmp',
  56. 'strncmp',
  57. 'strpbrk',
  58. 'strpos',
  59. 'strspn',
  60. 'strrev',
  61. 'strstr',
  62. 'strtok',
  63. 'strtolower',
  64. 'strtoupper',
  65. 'strtr',
  66. 'substr',
  67. 'substr_compare',
  68. 'substr_count',
  69. 'substr_replace',
  70. 'trim',
  71. 'ucfirst',
  72. 'ucwords',
  73. 'wordwrap',
  74. 'date',
  75. 'microtime',
  76. 'strtotime',
  77. 'idate',
  78. 'gmstrftime',
  79. 'mktime',
  80. 'strftime',
  81. 'time',
  82. 'intval',
  83. 'boolval',
  84. 'floatval',
  85. 'strval',
  86. 'bcmul',
  87. 'bcdiv',
  88. 'abs',
  89. 'acos',
  90. 'acoh',
  91. 'asin',
  92. 'asinh',
  93. 'atan2',
  94. 'atan',
  95. 'atanh',
  96. 'base_convert',
  97. 'bindec',
  98. 'ceil',
  99. 'cos',
  100. 'cosh',
  101. 'decbin',
  102. 'dechex',
  103. 'decoct',
  104. 'deg2rad',
  105. 'exp',
  106. 'expm1',
  107. 'floor',
  108. 'fmod',
  109. 'getrandmax',
  110. 'hexdec',
  111. 'hypot',
  112. 'intdiv',
  113. 'is_finite',
  114. 'is_infinite',
  115. 'is_nan',
  116. 'lcg_value',
  117. 'log10',
  118. 'log1p',
  119. 'log',
  120. 'max',
  121. 'min',
  122. 'mb_strtolower',
  123. 'mb_check_encoding',
  124. 'mb_convert_case',
  125. 'mb_convert_encoding',
  126. 'mb_convert_kana',
  127. 'mb_decode_numericentity',
  128. 'mb_detect_encoding',
  129. 'mb_detect_order',
  130. 'mb_encode_numericentity',
  131. 'mb_ereg_match',
  132. 'mb_ereg_replace',
  133. 'mb_ereg_search_getpos',
  134. 'mb_ereg_search_pos',
  135. 'mb_ereg_search',
  136. 'mb_ereg',
  137. 'mb_eregi_replace',
  138. 'mb_eregi',
  139. 'mb_internal_encoding',
  140. 'mb_language',
  141. 'mb_preferred_mime_name',
  142. 'mb_regex_encoding',
  143. 'mb_regex_set_options',
  144. 'mb_strcut',
  145. 'mb_strimwidth',
  146. 'mb_stripos',
  147. 'mb_stristr',
  148. 'mb_strlen',
  149. 'mb_strpos',
  150. 'mb_strrchr',
  151. 'mb_strrichr',
  152. 'mb_strripos',
  153. 'mb_strstr',
  154. 'mb_strtolower',
  155. 'mb_strtoupper',
  156. 'mb_strwidth',
  157. 'mb_substr_count',
  158. 'mb_substr',
  159. 'mt_getrandmax',
  160. 'mt_rand',
  161. 'mt_srand',
  162. 'octdec',
  163. 'pi',
  164. 'pow',
  165. 'rad2deg',
  166. 'rand',
  167. 'round',
  168. 'sin',
  169. 'sqrt',
  170. 'srand',
  171. 'tan',
  172. 'tanh',
  173. // WordPress-defined functions
  174. 'human_time_diff',
  175. 'current_time',
  176. // CFDB-defined functions
  177. 'concat',
  178. 'sum',
  179. 'multiply'
  180. );
  181. public function init() {
  182. $this->permittedFunctions = CFDBPermittedFunctions::$defaultPermitted;
  183. }
  184. public static function getInstance() {
  185. static $inst = null;
  186. if ($inst === null) {
  187. $inst = new CFDBPermittedFunctions();
  188. $inst->init();
  189. }
  190. return $inst;
  191. }
  192. public function setPermitAllFunctions($trueOrFalse) {
  193. $this->permitAllFunctions = $trueOrFalse;
  194. }
  195. public function isFunctionPermitted($functionName) {
  196. if ($this->permitAllFunctions === true) {
  197. return true;
  198. } else {
  199. return in_array($functionName, $this->permittedFunctions);
  200. }
  201. }
  202. public function addPermittedFunction($functionName) {
  203. if ($functionName && !in_array($functionName, $this->permittedFunctions)) {
  204. $this->permittedFunctions[] = $functionName;
  205. }
  206. }
  207. }
  208. /**
  209. * A function wrapper to register function names in a CFDBPermittedFunctions singleton
  210. * @param $function_name
  211. */
  212. function cfdb_register_function($function_name) {
  213. CFDBPermittedFunctions::getInstance()->addPermittedFunction($function_name);
  214. }