PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/public/wp-content/plugins/the-events-calendar/vendor/tickets/common/src/functions/template-tags/general.php

https://gitlab.com/kath.de/cibedo_cibedo.de
PHP | 456 lines | 201 code | 53 blank | 202 comment | 37 complexity | 61d87b3b6dc51b04591dddc7171e8967 MD5 | raw file
  1. <?php
  2. /**
  3. * Display functions (template-tags) for use in WordPress templates.
  4. */
  5. // Don't load directly
  6. if ( ! defined( 'ABSPATH' ) ) {
  7. die( '-1' );
  8. }
  9. if ( ! class_exists( 'Tribe__Main' ) ) {
  10. return;
  11. }
  12. if ( ! function_exists( 'tribe_get_option' ) ) {
  13. /**
  14. * Get Options
  15. *
  16. * Retrieve specific key from options array, optionally provide a default return value
  17. *
  18. * @category Events
  19. * @param string $optionName Name of the option to retrieve.
  20. * @param string $default Value to return if no such option is found.
  21. *
  22. * @return mixed Value of the option if found.
  23. * @todo Abstract this function out of template tags or otherwise secure it from other namespace conflicts.
  24. */
  25. function tribe_get_option( $optionName, $default = '' ) {
  26. return apply_filters( 'tribe_get_option', Tribe__Settings_Manager::get_option( $optionName, $default ), $optionName, $default );
  27. }
  28. }//end if
  29. if ( ! function_exists( 'tribe_update_option' ) ) {
  30. /**
  31. * Update Option
  32. *
  33. * Set specific key from options array, optionally provide a default return value
  34. *
  35. * @category Events
  36. * @param string $optionName Name of the option to retrieve.
  37. * @param string $value Value to save
  38. *
  39. * @return void
  40. */
  41. function tribe_update_option( $optionName, $value ) {
  42. Tribe__Settings_Manager::set_option( $optionName, $value );
  43. }
  44. }//end if
  45. if ( ! function_exists( 'tribe_get_network_option' ) ) {
  46. /**
  47. * Get Network Options
  48. *
  49. * Retrieve specific key from options array, optionally provide a default return value
  50. *
  51. * @category Events
  52. * @param string $optionName Name of the option to retrieve.
  53. * @param string $default Value to return if no such option is found.
  54. *
  55. * @return mixed Value of the option if found.
  56. * @todo Abstract this function out of template tags or otherwise secure it from other namespace conflicts.
  57. */
  58. function tribe_get_network_option( $optionName, $default = '' ) {
  59. return Tribe__Settings_Manager::get_network_option( $optionName, $default );
  60. }
  61. }
  62. if ( ! function_exists( 'tribe_resource_url' ) ) {
  63. /**
  64. * Returns or echoes a url to a file in the Events Calendar plugin resources directory
  65. *
  66. * @category Events
  67. * @param string $resource the filename of the resource
  68. * @param bool $echo whether or not to echo the url
  69. * @param string $root_dir directory to hunt for resource files (src or common)
  70. *
  71. * @return string
  72. **/
  73. function tribe_resource_url( $resource, $echo = false, $root_dir = 'src' ) {
  74. $extension = pathinfo( $resource, PATHINFO_EXTENSION );
  75. if ( 'src' !== $root_dir ) {
  76. $root_dir .= '/src';
  77. }
  78. $resources_path = $root_dir . '/resources/';
  79. switch ( $extension ) {
  80. case 'css':
  81. $resource_path = $resources_path .'css/';
  82. break;
  83. case 'js':
  84. $resource_path = $resources_path .'js/';
  85. break;
  86. case 'scss':
  87. $resource_path = $resources_path .'scss/';
  88. break;
  89. default:
  90. $resource_path = $resources_path;
  91. break;
  92. }
  93. $path = $resource_path . $resource;
  94. $plugin_path = trailingslashit( dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) );
  95. $plugin_dir = trailingslashit( basename( $plugin_path ) );
  96. $url = plugins_url( $plugin_dir );
  97. /**
  98. * Filters the resource URL
  99. *
  100. * @param $url
  101. * @param $resource
  102. */
  103. $url = apply_filters( 'tribe_resource_url', $url . $path, $resource );
  104. /**
  105. * Deprected the tribe_events_resource_url filter in 4.0 in favor of tribe_resource_url. Remove in 5.0
  106. */
  107. $url = apply_filters( 'tribe_events_resource_url', $url, $resource );
  108. if ( $echo ) {
  109. echo $url;
  110. }
  111. return $url;
  112. }
  113. }//end if
  114. if ( ! function_exists( 'tribe_multi_line_remove_empty_lines' ) ) {
  115. /**
  116. * helper function to remove empty lines from multi-line strings
  117. *
  118. * @category Events
  119. * @link http://stackoverflow.com/questions/709669/how-do-i-remove-blank-lines-from-text-in-php
  120. *
  121. * @param string $multi_line_string a multiline string
  122. *
  123. * @return string the same string without empty lines
  124. */
  125. function tribe_multi_line_remove_empty_lines( $multi_line_string ) {
  126. return preg_replace( "/^\n+|^[\t\s]*\n+/m", '', $multi_line_string );
  127. }
  128. }//end if
  129. if ( ! function_exists( 'tribe_get_date_format' ) ) {
  130. /**
  131. * Get the date format specified in the tribe options
  132. *
  133. * @category Events
  134. * @param bool $with_year
  135. *
  136. * @return mixed
  137. */
  138. function tribe_get_date_format( $with_year = false ) {
  139. if ( $with_year ) {
  140. $format = tribe_get_date_option( 'dateWithYearFormat', get_option( 'date_format' ) );
  141. } else {
  142. $format = tribe_get_date_option( 'dateWithoutYearFormat', 'F j' );
  143. }
  144. return apply_filters( 'tribe_date_format', $format );
  145. }
  146. }//end if
  147. if ( ! function_exists( 'tribe_get_datetime_format' ) ) {
  148. /**
  149. * Get the Datetime Format
  150. *
  151. * @category Events
  152. *
  153. * @param bool $with_year
  154. *
  155. * @return mixed|void
  156. */
  157. function tribe_get_datetime_format( $with_year = false ) {
  158. $separator = (array) str_split( tribe_get_option( 'dateTimeSeparator', ' @ ' ) );
  159. $format = tribe_get_date_format( $with_year );
  160. $format .= ( ! empty( $separator ) ? '\\' : '' ) . implode( '\\', $separator );
  161. $format .= get_option( 'time_format' );
  162. return apply_filters( 'tribe_datetime_format', $format );
  163. }
  164. }//end if
  165. if ( ! function_exists( 'tribe_get_time_format' ) ) {
  166. /**
  167. * Get the time format
  168. *
  169. * @category Events
  170. *
  171. * @return mixed|void
  172. */
  173. function tribe_get_time_format( ) {
  174. $format = get_option( 'time_format' );
  175. return apply_filters( 'tribe_time_format', $format );
  176. }
  177. }//end if
  178. if ( ! function_exists( 'tribe_get_days_between' ) ) {
  179. /**
  180. * Accepts two dates and returns the number of days between them
  181. *
  182. * @category Events
  183. *
  184. * @param string $start_date
  185. * @param string $end_date
  186. * @param string|bool $day_cutoff
  187. *
  188. * @return int
  189. * @see Tribe__Date_Utils::date_diff()
  190. **/
  191. function tribe_get_days_between( $start_date, $end_date, $day_cutoff = '00:00' ) {
  192. if ( $day_cutoff === false ) {
  193. $day_cutoff = '00:00';
  194. } elseif ( $day_cutoff === true ) {
  195. $day_cutoff = tribe_get_option( 'multiDayCutoff', '00:00' );
  196. }
  197. $start_date = new DateTime( $start_date );
  198. if ( $start_date < new DateTime( $start_date->format( 'Y-m-d ' . $day_cutoff ) ) ) {
  199. $start_date->modify( '-1 day' );
  200. }
  201. $end_date = new DateTime( $end_date );
  202. if ( $end_date <= new DateTime( $end_date->format( 'Y-m-d ' . $day_cutoff ) ) ) {
  203. $end_date->modify( '-1 day' );
  204. }
  205. return Tribe__Date_Utils::date_diff( $start_date->format( 'Y-m-d ' . $day_cutoff ), $end_date->format( 'Y-m-d ' . $day_cutoff ) );
  206. }
  207. }//end if
  208. if ( ! function_exists( 'tribe_prepare_for_json' ) ) {
  209. /**
  210. * Function to prepare content for use as a value in a json encoded string destined for storage on a html data attribute.
  211. * Hence the double quote fun, especially in case they pass html encoded &quot; along. Any of those getting through to the data att will break jquery's parseJSON method.
  212. * Themers can use this function to prepare data they may want to send to tribe_events_template_data() in the templates, and we use it in that function ourselves.
  213. *
  214. * @category Events
  215. *
  216. * @param $string
  217. *
  218. * @return string
  219. */
  220. function tribe_prepare_for_json( $string ) {
  221. $value = trim( htmlspecialchars( $string, ENT_QUOTES, 'UTF-8' ) );
  222. $value = str_replace( '&quot;', '"', $value );
  223. return $value;
  224. }
  225. }//end if
  226. if ( ! function_exists( 'tribe_prepare_for_json_deep' ) ) {
  227. /**
  228. * Recursively iterate through an nested structure, calling
  229. * tribe_prepare_for_json() on all scalar values
  230. *
  231. * @category Events
  232. *
  233. * @param mixed $value The data to be cleaned
  234. *
  235. * @return mixed The clean data
  236. */
  237. function tribe_prepare_for_json_deep( $value ) {
  238. if ( is_array( $value ) ) {
  239. $value = array_map( 'tribe_prepare_for_json_deep', $value );
  240. } elseif ( is_object( $value ) ) {
  241. $vars = get_object_vars( $value );
  242. foreach ( $vars as $key => $data ) {
  243. $value->{$key} = tribe_prepare_for_json_deep( $data );
  244. }
  245. } elseif ( is_string( $value ) ) {
  246. $value = tribe_prepare_for_json( $value );
  247. }
  248. return $value;
  249. }
  250. }//end if
  251. if ( ! function_exists( 'tribe_the_notices' ) ) {
  252. /**
  253. * Generates html for any notices that have been queued on the current view
  254. *
  255. * @category Events
  256. *
  257. * @param bool $echo Whether or not to echo the notices html
  258. *
  259. * @return void | string
  260. * @see Tribe__Notices::get()
  261. **/
  262. function tribe_the_notices( $echo = true ) {
  263. $notices = Tribe__Notices::get();
  264. $html = ! empty( $notices ) ? '<div class="tribe-events-notices"><ul><li>' . implode( '</li><li>', $notices ) . '</li></ul></div>' : '';
  265. /**
  266. * Deprecated the tribe_events_the_notices filter in 4.0 in favor of tribe_the_notices. Remove in 5.0
  267. */
  268. $the_notices = apply_filters( 'tribe_events_the_notices', $html, $notices );
  269. /**
  270. * filters the notices HTML
  271. */
  272. $the_notices = apply_filters( 'tribe_the_notices', $html, $notices );
  273. if ( $echo ) {
  274. echo $the_notices;
  275. } else {
  276. return $the_notices;
  277. }
  278. }
  279. }//end if
  280. if ( ! function_exists( 'tribe_is_bot' ) ) {
  281. /**
  282. * tribe_is_bot checks if the visitor is a bot and returns status
  283. *
  284. * @category Events
  285. *
  286. * @return bool
  287. */
  288. function tribe_is_bot() {
  289. // get the current user agent
  290. $user_agent = strtolower( $_SERVER['HTTP_USER_AGENT'] );
  291. // check if the user agent is empty since most browsers identify themselves, so possibly a bot
  292. if ( empty( $user_agent ) ) {
  293. return apply_filters( 'tribe_is_bot_status', true, $user_agent, null );
  294. }
  295. // declare known bot user agents (lowercase)
  296. $user_agent_bots = (array) apply_filters(
  297. 'tribe_is_bot_list', array(
  298. 'bot',
  299. 'slurp',
  300. 'spider',
  301. 'crawler',
  302. 'yandex',
  303. )
  304. );
  305. foreach ( $user_agent_bots as $bot ) {
  306. if ( stripos( $user_agent, $bot ) !== false ) {
  307. return apply_filters( 'tribe_is_bot_status', true, $user_agent, $bot );
  308. }
  309. }
  310. // we think this is probably a real human
  311. return apply_filters( 'tribe_is_bot_status', false, $user_agent, null );
  312. }
  313. }//end if
  314. if ( ! function_exists( 'tribe_count_hierarchical_keys' ) ) {
  315. /**
  316. * Count keys in a hierarchical array
  317. *
  318. * @param $value
  319. * @param $key
  320. * @todo - remove, only used in the meta walker
  321. */
  322. function tribe_count_hierarchical_keys( $value, $key ) {
  323. global $tribe_count_hierarchical_increment;
  324. $tribe_count_hierarchical_increment++;
  325. }
  326. }//end if
  327. if ( ! function_exists( 'tribe_count_hierarchical' ) ) {
  328. /**
  329. * Count items in a hierarchical array
  330. *
  331. * @param array $walk
  332. *
  333. * @return int
  334. * @todo - remove, only used in the meta walker
  335. */
  336. function tribe_count_hierarchical( array $walk ) {
  337. global $tribe_count_hierarchical_increment;
  338. $tribe_count_hierarchical_increment = 0;
  339. array_walk_recursive( $walk, 'tribe_count_hierarchical_keys' );
  340. return $tribe_count_hierarchical_increment;
  341. }
  342. }//end if
  343. if ( ! function_exists( 'tribe_get_mobile_breakpoint' ) ) {
  344. /**
  345. * Mobile breakpoint
  346. *
  347. * Get the breakpoint for switching to mobile styles. Defaults to 768.
  348. *
  349. * @category Events
  350. *
  351. * @param int $default The default width (in pixels) at which to break into mobile styles
  352. *
  353. * @return int
  354. */
  355. function tribe_get_mobile_breakpoint( $default = 768 ) {
  356. return apply_filters( 'tribe_events_mobile_breakpoint', $default );
  357. }
  358. }//end if
  359. if ( ! function_exists( 'tribe_format_currency' ) ) {
  360. /**
  361. * Receives a float and formats it with a currency symbol
  362. *
  363. * @category Cost
  364. * @param string $cost pricing to format
  365. * @param null|int $post_id
  366. * @param null|string $currency_symbol
  367. * @param null|bool $reverse_position
  368. *
  369. * @return string
  370. */
  371. function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, $reverse_position = null ) {
  372. $post_id = Tribe__Main::post_id_helper( $post_id );
  373. $currency_symbol = apply_filters( 'tribe_currency_symbol', $currency_symbol, $post_id );
  374. // if no currency symbol was passed, or we're not looking at a particular event,
  375. // let's get the default currency symbol
  376. if ( ! $post_id || ! $currency_symbol ) {
  377. $currency_symbol = tribe_get_option( 'defaultCurrencySymbol', '$' );
  378. }
  379. $reverse_position = apply_filters( 'tribe_reverse_currency_position', $reverse_position, $post_id );
  380. if ( ! $reverse_position || ! $post_id ) {
  381. $reverse_position = tribe_get_option( 'reverseCurrencyPosition', false );
  382. }
  383. $cost = $reverse_position ? $cost . $currency_symbol : $currency_symbol . $cost;
  384. return $cost;
  385. }
  386. }//end if
  387. if ( ! function_exists( 'tribe_get_date_option' ) ) {
  388. /**
  389. * Get a date option.
  390. *
  391. * Retrieve an option value taking care to escape it to preserve date format slashes.
  392. *
  393. * @category Events
  394. * @param string $optionName Name of the option to retrieve.
  395. * @param string $default Value to return if no such option is found.
  396. *
  397. * @return mixed Value of the option if found
  398. */
  399. function tribe_get_date_option( $optionName, $default = '' ) {
  400. $value = tribe_get_option( $optionName, $default );
  401. return Tribe__Date_Utils::unescape_date_format($value);
  402. }
  403. }