Guest User

Untitled

a guest
Nov 24th, 2015
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.87 KB | None | 0 0
  1. <?php
  2.  
  3. define( 'ONETONE_THEME_BASE_URL', get_template_directory_uri());
  4. define( 'ONETONE_OPTIONS_FRAMEWORK', get_template_directory().'/admin/' );
  5. define( 'ONETONE_OPTIONS_FRAMEWORK_URI', ONETONE_THEME_BASE_URL. '/admin/');
  6. define('ONETONE_OPTIONS_PREFIXED' ,'onetone_');
  7.  
  8. define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/admin/' );
  9. require_once dirname( __FILE__ ) . '/admin/options-framework.php';
  10. require_once get_template_directory() . '/includes/admin-options.php';
  11.  
  12.  
  13. /**
  14. * Required: include options framework.
  15. **/
  16. load_template( trailingslashit( get_template_directory() ) . 'admin/options-framework.php' );
  17.  
  18. /**
  19. * Mobile Detect Library
  20. **/
  21. if(!class_exists("Mobile_Detect")){
  22. load_template( trailingslashit( get_template_directory() ) . 'includes/Mobile_Detect.php' );
  23. }
  24. /**
  25. * Theme setup
  26. **/
  27.  
  28. load_template( trailingslashit( get_template_directory() ) . 'includes/theme-setup.php' );
  29.  
  30. /**
  31. * Theme Functions
  32. **/
  33.  
  34. load_template( trailingslashit( get_template_directory() ) . 'includes/theme-functions.php' );
  35.  
  36. /**
  37. * Theme breadcrumb
  38. */
  39. load_template( trailingslashit( get_template_directory() ) . 'includes/breadcrumb-trail.php');
  40.  
  41. /**
  42. * Theme widget
  43. **/
  44.  
  45. load_template( trailingslashit( get_template_directory() ) . 'includes/theme-widget.php' );
  46.  
  47. /**
  48. * Meta box
  49. **/
  50.  
  51. load_template( trailingslashit( get_template_directory() ) . 'includes/metabox-options.php' );
  52.  
  53.  
  54. /**
  55. * Include the TGM_Plugin_Activation class.
  56. */
  57. load_template( trailingslashit( get_template_directory() ) . 'includes/class-tgm-plugin-activation.php' );
  58.  
  59.  
  60. add_action( 'tgmpa_register', 'onetone_theme_register_required_plugins' );
  61.  
  62. /**
  63. * Register the required plugins for this theme.
  64. *
  65. * In this example, we register two plugins - one included with the TGMPA library
  66. * and one from the .org repo.
  67. *
  68. * The variable passed to tgmpa_register_plugins() should be an array of plugin
  69. * arrays.
  70. *
  71. * This function is hooked into tgmpa_init, which is fired within the
  72. * TGM_Plugin_Activation class constructor.
  73. */
  74. function onetone_theme_register_required_plugins() {
  75.  
  76. /**
  77. * Array of plugin arrays. Required keys are name and slug.
  78. * If the source is NOT from the .org repo, then source is also required.
  79. */
  80. $plugins = array(
  81. // This is an example of how to include a plugin pre-packaged with a theme
  82. array(
  83. 'name' => __('Magee Shortcodes','onetone'), // The plugin name
  84. 'slug' => 'magee-shortcodes', // The plugin slug (typically the folder name)
  85. 'source' => esc_url('https://downloads.wordpress.org/plugin/magee-shortcodes.zip'), // The plugin source
  86. 'required' => false, // If false, the plugin is only 'recommended' instead of required
  87. 'version' => '1.2.1', // E.g. 1.0.0. If set, the active plugin must be this version or higher, otherwise a notice is presented
  88. 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch
  89. 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins
  90. 'external_url' => '', // If set, overrides default API URL and points to an external URL
  91. ),
  92.  
  93. );
  94.  
  95. /**
  96. * Array of configuration settings. Amend each line as needed.
  97. * If you want the default strings to be available under your own theme domain,
  98. * leave the strings uncommented.
  99. * Some of the strings are added into a sprintf, so see the comments at the
  100. * end of each line for what each argument will be.
  101. */
  102. $config = array(
  103. 'id' => 'onetone', // Unique ID for hashing notices for multiple instances of TGMPA.
  104. 'default_path' => '', // Default absolute path to pre-packaged plugins.
  105. 'menu' => 'onetone-install-plugins', // Menu slug.
  106. 'has_notices' => true, // Show admin notices or not.
  107. 'dismissable' => true, // If false, a user cannot dismiss the nag message.
  108. 'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
  109. 'is_automatic' => false, // Automatically activate plugins after installation or not.
  110. 'message' => '', // Message to output right before the plugins table.
  111. 'strings' => array(
  112. 'page_title' => __( 'Install Required Plugins', 'onetone' ),
  113. 'menu_title' => __( 'Install Plugins', 'onetone' ),
  114. 'installing' => __( 'Installing Plugin: %s', 'onetone' ), // %s = plugin name.
  115. 'oops' => __( 'Something went wrong with the plugin API.', 'onetone' ),
  116. 'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'onetone' ), // %1$s = plugin name(s).
  117. 'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'onetone' ), // %1$s = plugin name(s).
  118. 'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'onetone' ), // %1$s = plugin name(s).
  119. 'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'onetone' ), // %1$s = plugin name(s).
  120. 'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'onetone' ), // %1$s = plugin name(s).
  121. 'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'onetone' ), // %1$s = plugin name(s).
  122. 'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'onetone' ), // %1$s = plugin name(s).
  123. 'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'onetone' ), // %1$s = plugin name(s).
  124. 'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'onetone' ),
  125. 'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'onetone' ),
  126. 'return' => __( 'Return to Required Plugins Installer', 'onetone' ),
  127. 'plugin_activated' => __( 'Plugin activated successfully.', 'onetone' ),
  128. 'complete' => __( 'All plugins installed and activated successfully. %s', 'onetone' ), // %s = dashboard link.
  129. 'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
  130. )
  131. );
  132.  
  133. tgmpa( $plugins, $config );
  134.  
  135. }
  136.  
  137. add_filter('widget_text', 'do_shortcode');
  138.  
  139. class Tribe_Advance_Minical
  140. {
  141. protected $target_date = false;
  142. /**
  143. * Sets up auto advance for minicalendar widgets. If an optional target date is provided that will be used to
  144. * set the month.
  145. *
  146. * @param bool $target_date
  147. */
  148. public function __construct( $target_date = false ) {
  149. if ( is_admin() ) return;
  150. $this->target_date = $target_date;
  151. add_action( 'wp_loaded', array( $this, 'set_target_date' ) );
  152. add_filter( 'widget_display_callback', array( $this, 'advance_minical' ), 20, 2 );
  153. }
  154. /**
  155. * Basic check to help filter out spurious date formats or automatically determine
  156. * the next most appropriate date to use.
  157. */
  158. public function set_target_date() {
  159. if ( ! is_string($this->target_date) || 1 !== preg_match( '#^\d{4}-\d{2}(-\d{2})?$# ', $this->target_date ) )
  160. $this->target_date = $this->next_upcoming_date();
  161. }
  162. public function advance_minical( $instance, $widget ) {
  163. if ( 'tribe-mini-calendar' !== $widget->id_base || isset( $instance['eventDate'] ) ) return $instance;
  164. if ( date( 'Y-m' ) === $this->target_date) return;
  165. add_action( 'tribe_before_get_template_part', array( $this, 'modify_list_query' ), 5 );
  166. $instance['eventDate'] = $this->target_date;
  167. return $instance;
  168. }
  169. public function modify_list_query( $template ) {
  170. if ( false === strpos( $template, 'mini-calendar/list.php' ) ) return;
  171. add_action( 'parse_query', array( $this, 'amend_list_query' ) );
  172. }
  173. public function amend_list_query( $query ) {
  174. remove_action( 'parse_query', array( $this, 'amend_list_query' ) ); // Run this once only
  175. $the_query = $query->query_vars;
  176. $the_query['start_date'] = $this->target_date . '-01';
  177. $last_day = Tribe__Events__Date_Utils::getLastDayOfMonth( strtotime( $the_query['start_date'] ) );
  178. $the_query['end_date'] = substr_replace( $the_query['start_date'], $last_day, -2 );
  179. $the_query['end_date'] = Tribe__Events__Date_Utils::endOfDay( $the_query['end_date'] );
  180. $query->query_vars = $the_query;
  181. }
  182. protected function next_upcoming_date() {
  183. $next_event = tribe_get_events( array(
  184. 'eventDisplay' => 'list',
  185. 'posts_per_page' => 1,
  186. 'start_date' => date( 'Y-m-d' )
  187. ));
  188. $start_date = date( 'Y-m' );
  189. if ( !empty( $next_event ) || isset( $next_event[0] ) ) {
  190. $next_event_date = tribe_get_start_date( $next_event[0]->ID, false, 'Y-m' );
  191. // Prevent calendar from rewinding to the start of a currently ongoing event
  192. $start_date = ( $next_event_date > $start_date ) ? $next_event_date : $start_date;
  193. }
  194. return $start_date;
  195. }
  196. }
  197.  
  198. /**
  199. * If we don't pass a parameter it will try to advance the calendar to the same month as the next upcoming event.
  200. * However, we can also pass in a specific month:
  201. *
  202. * new Tribe_Advance_Minical( '2014-12' ); // Set it to December 2014
  203. */
  204. new Tribe_Advance_Minical();
Advertisement
Add Comment
Please, Sign In to add comment