PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/contact-form-7/includes/functions.php

https://gitlab.com/webkod3r/tripolis
PHP | 340 lines | 243 code | 89 blank | 8 comment | 42 complexity | 3c74e7636a2bca98633e72d23686c9c0 MD5 | raw file
  1. <?php
  2. function wpcf7_plugin_path( $path = '' ) {
  3. return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
  4. }
  5. function wpcf7_plugin_url( $path = '' ) {
  6. $url = plugins_url( $path, WPCF7_PLUGIN );
  7. if ( is_ssl() && 'http:' == substr( $url, 0, 5 ) ) {
  8. $url = 'https:' . substr( $url, 5 );
  9. }
  10. return $url;
  11. }
  12. function wpcf7_upload_dir( $type = false ) {
  13. $uploads = wp_upload_dir();
  14. $uploads = apply_filters( 'wpcf7_upload_dir', array(
  15. 'dir' => $uploads['basedir'],
  16. 'url' => $uploads['baseurl'] ) );
  17. if ( 'dir' == $type )
  18. return $uploads['dir'];
  19. if ( 'url' == $type )
  20. return $uploads['url'];
  21. return $uploads;
  22. }
  23. function wpcf7_ajax_loader() {
  24. $url = wpcf7_plugin_url( 'images/ajax-loader.gif' );
  25. return apply_filters( 'wpcf7_ajax_loader', $url );
  26. }
  27. function wpcf7_verify_nonce( $nonce, $action = -1 ) {
  28. if ( substr( wp_hash( $action, 'nonce' ), -12, 10 ) == $nonce )
  29. return true;
  30. return false;
  31. }
  32. function wpcf7_create_nonce( $action = -1 ) {
  33. return substr( wp_hash( $action, 'nonce' ), -12, 10 );
  34. }
  35. function wpcf7_blacklist_check( $target ) {
  36. $mod_keys = trim( get_option( 'blacklist_keys' ) );
  37. if ( empty( $mod_keys ) ) {
  38. return false;
  39. }
  40. $words = explode( "\n", $mod_keys );
  41. foreach ( (array) $words as $word ) {
  42. $word = trim( $word );
  43. if ( empty( $word ) || 256 < strlen( $word ) ) {
  44. continue;
  45. }
  46. $pattern = sprintf( '#%s#i', preg_quote( $word, '#' ) );
  47. if ( preg_match( $pattern, $target ) ) {
  48. return true;
  49. }
  50. }
  51. return false;
  52. }
  53. function wpcf7_array_flatten( $input ) {
  54. if ( ! is_array( $input ) )
  55. return array( $input );
  56. $output = array();
  57. foreach ( $input as $value )
  58. $output = array_merge( $output, wpcf7_array_flatten( $value ) );
  59. return $output;
  60. }
  61. function wpcf7_flat_join( $input ) {
  62. $input = wpcf7_array_flatten( $input );
  63. $output = array();
  64. foreach ( (array) $input as $value )
  65. $output[] = trim( (string) $value );
  66. return implode( ', ', $output );
  67. }
  68. function wpcf7_support_html5() {
  69. return (bool) apply_filters( 'wpcf7_support_html5', true );
  70. }
  71. function wpcf7_support_html5_fallback() {
  72. return (bool) apply_filters( 'wpcf7_support_html5_fallback', false );
  73. }
  74. function wpcf7_use_really_simple_captcha() {
  75. return apply_filters( 'wpcf7_use_really_simple_captcha',
  76. WPCF7_USE_REALLY_SIMPLE_CAPTCHA );
  77. }
  78. function wpcf7_validate_configuration() {
  79. return apply_filters( 'wpcf7_validate_configuration',
  80. WPCF7_VALIDATE_CONFIGURATION );
  81. }
  82. function wpcf7_load_js() {
  83. return apply_filters( 'wpcf7_load_js', WPCF7_LOAD_JS );
  84. }
  85. function wpcf7_load_css() {
  86. return apply_filters( 'wpcf7_load_css', WPCF7_LOAD_CSS );
  87. }
  88. function wpcf7_format_atts( $atts ) {
  89. $html = '';
  90. $prioritized_atts = array( 'type', 'name', 'value' );
  91. foreach ( $prioritized_atts as $att ) {
  92. if ( isset( $atts[$att] ) ) {
  93. $value = trim( $atts[$att] );
  94. $html .= sprintf( ' %s="%s"', $att, esc_attr( $value ) );
  95. unset( $atts[$att] );
  96. }
  97. }
  98. foreach ( $atts as $key => $value ) {
  99. $key = strtolower( trim( $key ) );
  100. if ( ! preg_match( '/^[a-z_:][a-z_:.0-9-]*$/', $key ) ) {
  101. continue;
  102. }
  103. $value = trim( $value );
  104. if ( '' !== $value ) {
  105. $html .= sprintf( ' %s="%s"', $key, esc_attr( $value ) );
  106. }
  107. }
  108. $html = trim( $html );
  109. return $html;
  110. }
  111. function wpcf7_link( $url, $anchor_text, $args = '' ) {
  112. $defaults = array(
  113. 'id' => '',
  114. 'class' => '' );
  115. $args = wp_parse_args( $args, $defaults );
  116. $args = array_intersect_key( $args, $defaults );
  117. $atts = wpcf7_format_atts( $args );
  118. $link = sprintf( '<a href="%1$s"%3$s>%2$s</a>',
  119. esc_url( $url ),
  120. esc_html( $anchor_text ),
  121. $atts ? ( ' ' . $atts ) : '' );
  122. return $link;
  123. }
  124. function wpcf7_get_request_uri() {
  125. static $request_uri = '';
  126. if ( empty( $request_uri ) ) {
  127. $request_uri = add_query_arg( array() );
  128. }
  129. return esc_url_raw( $request_uri );
  130. }
  131. function wpcf7_register_post_types() {
  132. if ( class_exists( 'WPCF7_ContactForm' ) ) {
  133. WPCF7_ContactForm::register_post_type();
  134. return true;
  135. } else {
  136. return false;
  137. }
  138. }
  139. function wpcf7_version( $args = '' ) {
  140. $defaults = array(
  141. 'limit' => -1,
  142. 'only_major' => false );
  143. $args = wp_parse_args( $args, $defaults );
  144. if ( $args['only_major'] ) {
  145. $args['limit'] = 2;
  146. }
  147. $args['limit'] = (int) $args['limit'];
  148. $ver = WPCF7_VERSION;
  149. $ver = strtr( $ver, '_-+', '...' );
  150. $ver = preg_replace( '/[^0-9.]+/', ".$0.", $ver );
  151. $ver = preg_replace( '/[.]+/', ".", $ver );
  152. $ver = trim( $ver, '.' );
  153. $ver = explode( '.', $ver );
  154. if ( -1 < $args['limit'] ) {
  155. $ver = array_slice( $ver, 0, $args['limit'] );
  156. }
  157. $ver = implode( '.', $ver );
  158. return $ver;
  159. }
  160. function wpcf7_version_grep( $version, array $input ) {
  161. $pattern = '/^' . preg_quote( (string) $version, '/' ) . '(?:\.|$)/';
  162. return preg_grep( $pattern, $input );
  163. }
  164. function wpcf7_enctype_value( $enctype ) {
  165. $enctype = trim( $enctype );
  166. if ( empty( $enctype ) ) {
  167. return '';
  168. }
  169. $valid_enctypes = array(
  170. 'application/x-www-form-urlencoded',
  171. 'multipart/form-data',
  172. 'text/plain' );
  173. if ( in_array( $enctype, $valid_enctypes ) ) {
  174. return $enctype;
  175. }
  176. $pattern = '%^enctype="(' . implode( '|', $valid_enctypes ) . ')"$%';
  177. if ( preg_match( $pattern, $enctype, $matches ) ) {
  178. return $matches[1]; // for back-compat
  179. }
  180. return '';
  181. }
  182. function wpcf7_rmdir_p( $dir ) {
  183. if ( is_file( $dir ) ) {
  184. @unlink( $dir );
  185. return true;
  186. }
  187. if ( ! is_dir( $dir ) ) {
  188. return false;
  189. }
  190. if ( $handle = @opendir( $dir ) ) {
  191. while ( false !== ( $file = readdir( $handle ) ) ) {
  192. if ( $file == "." || $file == ".." ) {
  193. continue;
  194. }
  195. wpcf7_rmdir_p( path_join( $dir, $file ) );
  196. }
  197. closedir( $handle );
  198. }
  199. return @rmdir( $dir );
  200. }
  201. /* From _http_build_query in wp-includes/functions.php */
  202. function wpcf7_build_query( $args, $key = '' ) {
  203. $sep = '&';
  204. $ret = array();
  205. foreach ( (array) $args as $k => $v ) {
  206. $k = urlencode( $k );
  207. if ( ! empty( $key ) ) {
  208. $k = $key . '%5B' . $k . '%5D';
  209. }
  210. if ( null === $v ) {
  211. continue;
  212. } elseif ( false === $v ) {
  213. $v = '0';
  214. }
  215. if ( is_array( $v ) || is_object( $v ) ) {
  216. array_push( $ret, wpcf7_build_query( $v, $k ) );
  217. } else {
  218. array_push( $ret, $k . '=' . urlencode( $v ) );
  219. }
  220. }
  221. return implode( $sep, $ret );
  222. }
  223. /**
  224. * Returns the number of code units in a string.
  225. *
  226. * @see http://www.w3.org/TR/html5/infrastructure.html#code-unit-length
  227. *
  228. * @return int|bool The number of code units, or false if mb_convert_encoding is not available.
  229. */
  230. function wpcf7_count_code_units( $string ) {
  231. static $use_mb = null;
  232. if ( is_null( $use_mb ) ) {
  233. $use_mb = function_exists( 'mb_convert_encoding' );
  234. }
  235. if ( ! $use_mb ) {
  236. return false;
  237. }
  238. $string = (string) $string;
  239. $encoding = mb_detect_encoding( $string, mb_detect_order(), true );
  240. if ( $encoding ) {
  241. $string = mb_convert_encoding( $string, 'UTF-16', $encoding );
  242. } else {
  243. $string = mb_convert_encoding( $string, 'UTF-16', 'UTF-8' );
  244. }
  245. $byte_count = mb_strlen( $string, '8bit' );
  246. return floor( $byte_count / 2 );
  247. }
  248. function wpcf7_is_localhost() {
  249. $server_name = strtolower( $_SERVER['SERVER_NAME'] );
  250. return in_array( $server_name, array( 'localhost', '127.0.0.1' ) );
  251. }