/public/wp-content/plugins/the-events-calendar/src/functions/template-tags/meta.php

https://gitlab.com/kath.de/cibedo_cibedo.de · PHP · 382 lines · 167 code · 59 blank · 156 comment · 30 complexity · 45b60da2080f1b81f9574626f6182524 MD5 · raw file

  1. <?php
  2. /**
  3. * Meta Factory Classes
  4. *
  5. * @uses Tribe__Events__Meta_Factory
  6. */
  7. // Don't load directly
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. die( '-1' );
  10. }
  11. if ( class_exists( 'Tribe__Events__Main' ) ) {
  12. /**
  13. * register a meta group
  14. *
  15. * @uses Tribe__Events__Meta_Factory::register()
  16. *
  17. * @param string $meta_group_id
  18. * @param array $args
  19. *
  20. * @return bool $success
  21. */
  22. function tribe_register_meta_group( $meta_group_id, $args = array() ) {
  23. // setup default for registering a meta group
  24. $defaults = array( 'register_type' => 'meta_group', 'register_overwrite' => true );
  25. // parse the $default and $args into the second param for registering a meta item
  26. return Tribe__Events__Meta_Factory::register( $meta_group_id, wp_parse_args( $args, $defaults ) );
  27. }
  28. /**
  29. * register a meta item
  30. *
  31. * @uses Tribe__Events__Meta_Factory::register()
  32. *
  33. * @param int $meta_id
  34. * @param array $args
  35. *
  36. * @return bool $success
  37. */
  38. function tribe_register_meta( $meta_id, $args = array() ) {
  39. return Tribe__Events__Meta_Factory::register( $meta_id, $args );
  40. }
  41. /**
  42. * Get the meta group.
  43. *
  44. * @param $meta_group_id
  45. * @param bool $is_the_meta
  46. *
  47. * @return bool|mixed|void
  48. */
  49. function tribe_get_meta_group( $meta_group_id, $is_the_meta = false ) {
  50. do_action( 'tribe_get_meta_group', $meta_group_id, $is_the_meta );
  51. $type = 'meta_group';
  52. // die silently if the requested meta group is not registered
  53. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_group_id, $type ) ) {
  54. return false;
  55. }
  56. $meta_group = Tribe__Events__Meta_Factory::get_args( $meta_group_id, $type );
  57. $meta_ids = Tribe__Events__Meta_Factory::get_order( $meta_group_id );
  58. $group_html = '';
  59. // internal check for hiding items in the meta
  60. if ( ! $meta_group['show_on_meta'] ) {
  61. return false;
  62. }
  63. $meta_pos_int = 0;
  64. $total_meta_items = tribe_count_hierarchical( $meta_ids );
  65. foreach ( $meta_ids as $meta_id_group ) {
  66. foreach ( $meta_id_group as $meta_id ) {
  67. $meta_pos_int ++;
  68. $group_html = tribe_separated_field( $group_html, $meta_group['wrap']['meta_separator'], tribe_get_meta( $meta_id, $is_the_meta ) );
  69. }
  70. }
  71. $params = array( $meta_group_id );
  72. if ( ! empty( $meta['filter_callback'] ) ) {
  73. return call_user_func_array( $meta['filter_callback'], $params );
  74. }
  75. if ( ! empty( $meta['callback'] ) ) {
  76. $value = call_user_func_array( $meta['callback'], $params );
  77. }
  78. $value = empty( $value ) ? $group_html : $value;
  79. $html = ! empty( $group_html ) ? Tribe__Events__Meta_Factory::template( $meta_group['label'], $value, $meta_group_id, 'meta_group' ) : '';
  80. return apply_filters( 'tribe_get_meta_group', $html, $meta_group_id );
  81. }
  82. /**
  83. * Get the meta.
  84. *
  85. * @param $meta_id
  86. * @param bool $is_the_meta
  87. *
  88. * @return bool|mixed|void
  89. */
  90. function tribe_get_meta( $meta_id, $is_the_meta = false ) {
  91. do_action( 'tribe_get_meta', $meta_id, $is_the_meta );
  92. // die silently if the requested meta item is not registered
  93. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id ) ) {
  94. return false;
  95. }
  96. $meta = Tribe__Events__Meta_Factory::get_args( $meta_id );
  97. // internal check for hiding items in the meta
  98. if ( ! $meta['show_on_meta'] ) {
  99. return false;
  100. }
  101. $params = array( $meta_id );
  102. if ( ! empty( $meta['filter_callback'] ) ) {
  103. return call_user_func_array( $meta['filter_callback'], $params );
  104. }
  105. if ( ! empty( $meta['callback'] ) ) {
  106. $value = call_user_func_array( $meta['callback'], $params );
  107. }
  108. $value = empty( $value ) ? $meta['meta_value'] : $value;
  109. // if we have a value let's build the html template
  110. $html = ! empty( $value ) ? Tribe__Events__Meta_Factory::template( $meta['label'], $value, $meta_id ) : '';
  111. return apply_filters( 'tribe_get_meta', $html, $meta_id );
  112. }
  113. /**
  114. * Get the args for a meta object.
  115. *
  116. * @param $meta_id
  117. * @param $arg_key
  118. * @param string $type
  119. *
  120. * @return bool
  121. */
  122. function tribe_get_meta_arg( $meta_id, $arg_key, $type = 'meta' ) {
  123. // die silently if the requested meta group is not registered
  124. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  125. return false;
  126. }
  127. $args = Tribe__Events__Meta_Factory::get_args( $meta_id, $type );
  128. // check if the arg exists
  129. if ( isset( $args[ $arg_key ] ) ) {
  130. return $args[ $arg_key ];
  131. } else {
  132. return false;
  133. }
  134. }
  135. /**
  136. * Get the template part for the meta object.
  137. *
  138. * @param $meta_id
  139. * @param $template_key
  140. * @param string $type
  141. *
  142. * @return bool
  143. */
  144. function tribe_get_meta_template_part( $meta_id, $template_key, $type = 'meta' ) {
  145. // die silently if the requested meta group is not registered
  146. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  147. return false;
  148. }
  149. $template = tribe_get_meta_arg( $meta_id, 'wrap', $type );
  150. if ( isset( $template[ $template_key ] ) ) {
  151. return $template[ $template_key ];
  152. } else {
  153. return false;
  154. }
  155. }
  156. /**
  157. * Set the visibility of the meta object.
  158. *
  159. * @param $meta_id
  160. * @param bool $status
  161. * @param string $type
  162. */
  163. function tribe_set_the_meta_visibility( $meta_id, $status = true, $type = 'meta' ) {
  164. Tribe__Events__Meta_Factory::set_visibility( $meta_id, $type, $status );
  165. }
  166. /**
  167. * Set the template for the meta object.
  168. *
  169. * @param $meta_id
  170. * @param array $template
  171. * @param string $type
  172. *
  173. * @return bool
  174. */
  175. function tribe_set_the_meta_template( $meta_id, $template = array(), $type = 'meta' ) {
  176. if ( is_array( $meta_id ) ) {
  177. foreach ( $meta_id as $id ) {
  178. tribe_set_the_meta_template( $id, $template, $type );
  179. }
  180. } else {
  181. global $_tribe_meta_factory;
  182. // die silently if the requested meta group is not registered
  183. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  184. return false;
  185. }
  186. if ( ! empty( $template ) ) {
  187. $_tribe_meta_factory->{$type}[ $meta_id ]['wrap'] = wp_parse_args( $template, $_tribe_meta_factory->{$type}[ $meta_id ]['wrap'] );
  188. }
  189. }
  190. }
  191. /**
  192. * Set the meta priority to manage positioning.
  193. *
  194. * @param $meta_id
  195. * @param int $priority
  196. * @param string $type
  197. *
  198. * @return bool
  199. */
  200. function tribe_set_meta_priority( $meta_id, $priority = 100, $type = 'meta' ) {
  201. if ( is_array( $meta_id ) ) {
  202. foreach ( $meta_id as $id => $priority ) {
  203. tribe_set_meta_priority( $id, $priority, $type );
  204. }
  205. } else {
  206. global $_tribe_meta_factory;
  207. // die silently if the requested meta group is not registered
  208. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  209. return false;
  210. }
  211. if ( ! empty( $priority ) ) {
  212. $_tribe_meta_factory->{$type}[ $meta_id ]['priority'] = $priority;
  213. }
  214. }
  215. }
  216. /**
  217. * Set meta value for meta object.
  218. *
  219. * @param $meta_id
  220. * @param $value
  221. * @param string $value_type
  222. * @param string $type
  223. *
  224. * @return bool
  225. */
  226. function tribe_set_meta_value( $meta_id, $value, $value_type = 'meta_value', $type = 'meta' ) {
  227. if ( is_array( $meta_id ) ) {
  228. foreach ( $meta_id as $id ) {
  229. tribe_set_meta_value( $id, $value, $value_type, $type );
  230. }
  231. } else {
  232. global $_tribe_meta_factory;
  233. // die silently if the requested meta group is not registered
  234. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  235. return false;
  236. }
  237. $_tribe_meta_factory->{$type}[ $meta_id ][ $value_type ] = $value;
  238. }
  239. }
  240. /**
  241. * Set the meta label for the meta object.
  242. *
  243. * @param $meta_id
  244. * @param string $label
  245. * @param string $type
  246. *
  247. * @return bool
  248. */
  249. function tribe_set_meta_label( $meta_id, $label = '', $type = 'meta' ) {
  250. if ( is_array( $meta_id ) ) {
  251. foreach ( $meta_id as $id => $label ) {
  252. tribe_set_meta_label( $id, $label, $type );
  253. }
  254. } else {
  255. global $_tribe_meta_factory;
  256. // die silently if the requested meta group is not registered
  257. if ( ! Tribe__Events__Meta_Factory::check_exists( $meta_id, $type ) ) {
  258. return false;
  259. }
  260. $_tribe_meta_factory->{$type}[ $meta_id ]['label'] = $label;
  261. }
  262. }
  263. /**
  264. * Get the event meta
  265. *
  266. * @return mixed|void
  267. */
  268. function tribe_get_the_event_meta() {
  269. $html = '';
  270. foreach ( Tribe__Events__Meta_Factory::get_order() as $meta_groups ) {
  271. foreach ( $meta_groups as $meta_group_id ) {
  272. $html .= tribe_get_meta_group( $meta_group_id, true );
  273. }
  274. }
  275. return apply_filters( 'tribe_get_the_event_meta', $html );
  276. }
  277. /**
  278. * Simple display of meta group tag
  279. *
  280. * @uses tribe_get_meta_group()
  281. * @return echo tribe_get_meta_group( $meta_group_id )
  282. */
  283. function tribe_display_the_event_meta() {
  284. echo apply_filters( 'tribe_display_the_event_meta', tribe_get_the_event_meta() );
  285. }
  286. /**
  287. * Simple diplay of meta group tag
  288. *
  289. * @uses tribe_get_meta_group()
  290. *
  291. * @param string $meta_group_id
  292. *
  293. * @return echo tribe_get_meta_group( $meta_group_id )
  294. */
  295. function tribe_display_meta_group( $meta_group_id ) {
  296. echo apply_filters( 'tribe_display_meta_group', tribe_get_meta_group( $meta_group_id ) );
  297. }
  298. /**
  299. * Simple diplay of meta tag
  300. *
  301. * @uses tribe_get_meta()
  302. *
  303. * @param string $meta_id
  304. *
  305. * @return echo tribe_get_meta( $meta_id )
  306. */
  307. function tribe_display_meta( $meta_id ) {
  308. echo apply_filters( 'tribe_display_meta', tribe_get_meta( $meta_id ) );
  309. }
  310. /**
  311. * Utility function to compile separated lists.
  312. *
  313. * @param string $body
  314. * @param string $separator
  315. * @param string $field
  316. *
  317. * @return string
  318. */
  319. function tribe_separated_field( $body, $separator, $field ) {
  320. $body_and_separator = $body ? $body . $separator : $body;
  321. return $field ? $body_and_separator . $field : $body;
  322. }
  323. }