PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/public/wp-content/plugins/the-events-calendar/vendor/tickets/common/src/Tribe/Main.php

https://gitlab.com/kath.de/cibedo_cibedo.de
PHP | 296 lines | 172 code | 45 blank | 79 comment | 19 complexity | 88504e5a2f179197ed3765e4ec6711b3 MD5 | raw file
  1. <?php
  2. /**
  3. * Main Tribe Common class.
  4. */
  5. // Don't load directly
  6. if ( ! defined( 'ABSPATH' ) ) {
  7. die( '-1' );
  8. }
  9. if ( class_exists( 'Tribe__Main' ) ) {
  10. return;
  11. }
  12. class Tribe__Main {
  13. const EVENTSERROROPT = '_tribe_events_errors';
  14. const OPTIONNAME = 'tribe_events_calendar_options';
  15. const OPTIONNAMENETWORK = 'tribe_events_calendar_network_options';
  16. const VERSION = '4.1';
  17. const FEED_URL = 'https://theeventscalendar.com/feed/';
  18. protected $plugin_context;
  19. protected $plugin_context_class;
  20. protected $doing_ajax = false;
  21. public static $tribe_url = 'http://tri.be/';
  22. public static $tec_url = 'http://theeventscalendar.com/';
  23. public $plugin_dir;
  24. public $plugin_path;
  25. public $plugin_url;
  26. /**
  27. * constructor
  28. */
  29. public function __construct( $context = null ) {
  30. if ( is_object( $context ) ) {
  31. $this->plugin_context = $context;
  32. $this->plugin_context_class = get_class( $context );
  33. }
  34. $this->plugin_path = trailingslashit( dirname( dirname( dirname( __FILE__ ) ) ) );
  35. $this->plugin_dir = trailingslashit( basename( $this->plugin_path ) );
  36. $this->plugin_url = plugins_url( $this->plugin_dir );
  37. $this->init_autoloading();
  38. $this->init_libraries();
  39. $this->add_hooks();
  40. $this->doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
  41. }
  42. /**
  43. * Get's the instantiated context of this class. I.e. the object that instantiated this one.
  44. */
  45. public function context() {
  46. return $this->plugin_context;
  47. }
  48. /**
  49. * Setup the autoloader for common files
  50. */
  51. protected function init_autoloading() {
  52. if ( ! class_exists( 'Tribe__Autoloader' ) ) {
  53. require_once dirname( __FILE__ ) . '/Autoloader.php';
  54. }
  55. $prefixes = array( 'Tribe__' => dirname( __FILE__ ) );
  56. $autoloader = Tribe__Autoloader::instance();
  57. $autoloader->register_prefixes( $prefixes );
  58. $autoloader->register_autoloader();
  59. }
  60. /**
  61. * Get's the class name of the instantiated plugin context of this class. I.e. the class name of the object that instantiated this one.
  62. */
  63. public function context_class() {
  64. return $this->plugin_context_class;
  65. }
  66. /**
  67. * initializes all required libraries
  68. */
  69. public function init_libraries() {
  70. Tribe__Debug::instance();
  71. Tribe__Settings_Manager::instance();
  72. require_once $this->plugin_path . 'src/functions/template-tags/general.php';
  73. require_once $this->plugin_path . 'src/functions/template-tags/date.php';
  74. }
  75. /**
  76. * Registers resources that can/should be enqueued
  77. */
  78. public function register_resources() {
  79. $resources_url = plugins_url( 'src/resources', dirname( dirname( __FILE__ ) ) );
  80. wp_register_style(
  81. 'tribe-common-admin',
  82. $resources_url . '/css/tribe-common-admin.css',
  83. array(),
  84. apply_filters( 'tribe_events_css_version', self::VERSION )
  85. );
  86. wp_register_script(
  87. 'ba-dotimeout',
  88. $resources_url . '/js/jquery.ba-dotimeout.js',
  89. array(
  90. 'jquery',
  91. ),
  92. apply_filters( 'tribe_events_css_version', self::VERSION ),
  93. true
  94. );
  95. wp_register_script(
  96. 'tribe-inline-bumpdown',
  97. $resources_url . '/js/inline-bumpdown.js',
  98. array(
  99. 'ba-dotimeout',
  100. ),
  101. apply_filters( 'tribe_events_css_version', self::VERSION ),
  102. true
  103. );
  104. wp_register_script(
  105. 'tribe-notice-dismiss',
  106. $resources_url . '/js/notice-dismiss.js',
  107. array( 'jquery' ),
  108. apply_filters( 'tribe_events_css_version', self::VERSION ),
  109. true
  110. );
  111. }
  112. /**
  113. * Registers vendor assets that can/should be enqueued
  114. */
  115. public function register_vendor() {
  116. $vendor_base = plugins_url( 'vendor', dirname( dirname( __FILE__ ) ) );
  117. wp_register_style(
  118. 'tribe-jquery-ui-theme',
  119. $vendor_base . '/jquery/ui.theme.css',
  120. array(),
  121. apply_filters( 'tribe_events_css_version', self::VERSION )
  122. );
  123. wp_register_style(
  124. 'tribe-jquery-ui-datepicker',
  125. $vendor_base . '/jquery/ui.datepicker.css',
  126. array( 'tribe-jquery-ui-theme' ),
  127. apply_filters( 'tribe_events_css_version', self::VERSION )
  128. );
  129. }
  130. /**
  131. * Adds core hooks
  132. */
  133. public function add_hooks() {
  134. add_action( 'plugins_loaded', array( 'Tribe__App_Shop', 'instance' ) );
  135. add_action( 'init', array( $this, 'load_text_domain' ), 1 );
  136. // Register for the assets to be availble everywhere
  137. add_action( 'init', array( $this, 'register_resources' ), 1 );
  138. add_action( 'init', array( $this, 'register_vendor' ), 1 );
  139. // Enqueue only when needed (admin)
  140. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
  141. }
  142. /**
  143. * Loads the textdomain
  144. */
  145. public function load_text_domain() {
  146. $dir = basename( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/common/lang/';
  147. load_plugin_textdomain( 'tribe-common', false, $dir );
  148. }
  149. public function admin_enqueue_scripts() {
  150. wp_enqueue_script( 'tribe-inline-bumpdown' );
  151. wp_enqueue_script( 'tribe-notice-dismiss' );
  152. wp_enqueue_style( 'tribe-common-admin' );
  153. $helper = Tribe__Admin__Helpers::instance();
  154. if ( $helper->is_post_type_screen() ) {
  155. wp_enqueue_style( 'tribe-jquery-ui-datepicker' );
  156. }
  157. }
  158. /**
  159. * Returns the post types registered by Tribe plugins
  160. */
  161. public static function get_post_types() {
  162. // we default the post type array to empty in tribe-common. Plugins like TEC add to it
  163. return apply_filters( 'tribe_post_types', array() );
  164. }
  165. /**
  166. * Insert an array after a specified key within another array.
  167. *
  168. * @param $key
  169. * @param $source_array
  170. * @param $insert_array
  171. *
  172. * @return array
  173. *
  174. */
  175. public static function array_insert_after_key( $key, $source_array, $insert_array ) {
  176. if ( array_key_exists( $key, $source_array ) ) {
  177. $position = array_search( $key, array_keys( $source_array ) ) + 1;
  178. $source_array = array_slice( $source_array, 0, $position, true ) + $insert_array + array_slice( $source_array, $position, null, true );
  179. } else {
  180. // If no key is found, then add it to the end of the array.
  181. $source_array += $insert_array;
  182. }
  183. return $source_array;
  184. }
  185. /**
  186. * Insert an array immediately before a specified key within another array.
  187. *
  188. * @param $key
  189. * @param $source_array
  190. * @param $insert_array
  191. *
  192. * @return array
  193. */
  194. public static function array_insert_before_key( $key, $source_array, $insert_array ) {
  195. if ( array_key_exists( $key, $source_array ) ) {
  196. $position = array_search( $key, array_keys( $source_array ) );
  197. $source_array = array_slice( $source_array, 0, $position, true ) + $insert_array + array_slice( $source_array, $position, null, true );
  198. } else {
  199. // If no key is found, then add it to the end of the array.
  200. $source_array += $insert_array;
  201. }
  202. return $source_array;
  203. }
  204. /**
  205. * Helper function for getting Post Id. Accepts null or a post id. If no $post object exists, returns false to avoid a PHP NOTICE
  206. *
  207. * @param int $post (optional)
  208. *
  209. * @return int post ID or False
  210. */
  211. public static function post_id_helper( $post = null ) {
  212. if ( ! is_null( $post ) && is_numeric( $post ) > 0 ) {
  213. return (int) $post;
  214. } elseif ( is_object( $post ) && ! empty( $post->ID ) ) {
  215. return (int) $post->ID;
  216. } else {
  217. if ( ! empty( $GLOBALS['post'] ) && $GLOBALS['post'] instanceof WP_Post ) {
  218. return get_the_ID();
  219. } else {
  220. return false;
  221. }
  222. }
  223. }
  224. /**
  225. * Helper function to indicate whether the current execution context is AJAX
  226. *
  227. * This method exists to allow us test code that behaves differently depending on the execution
  228. * context.
  229. *
  230. * @since 4.0
  231. * @return boolean
  232. */
  233. public function doing_ajax( $doing_ajax = null ) {
  234. if ( ! is_null( $doing_ajax ) ) {
  235. $this->doing_ajax = $doing_ajax;
  236. }
  237. return $this->doing_ajax;
  238. }
  239. /**
  240. * Static Singleton Factory Method
  241. *
  242. * @return Tribe__Main
  243. */
  244. public static function instance() {
  245. static $instance;
  246. if ( ! $instance ) {
  247. $instance = new self;
  248. }
  249. return $instance;
  250. }
  251. }