/wp-content/themes/method/lib/functions/scripts.php

https://github.com/Canuckaholic/Pop-Digital · PHP · 397 lines · 244 code · 96 blank · 57 comment · 97 complexity · 411a315bb243513b12ea36982098a434 MD5 · raw file

  1. <?php
  2. /**
  3. *
  4. */
  5. function mysite_register_script() {
  6. if( is_admin() ) return;
  7. # For Tabs
  8. wp_register_script( MYSITE_PREFIX . '_jquery_tools_tabs', esc_url ( THEME_JS . '/tabs.min.js' ), array( 'jquery' ), THEME_VERSION );
  9. # For Scrolling Slider
  10. wp_register_script( MYSITE_PREFIX . '_jquery_tools_scrolling', esc_url ( THEME_JS . '/scrollable.min.js' ), array( 'jquery' ), THEME_VERSION );
  11. # For Nivo Slider
  12. wp_register_script( MYSITE_PREFIX . '_nivo', esc_url ( THEME_JS . '/jquery.nivo.slider.js' ), array( 'jquery' ), THEME_VERSION );
  13. # For galleria
  14. wp_register_style( MYSITE_PREFIX . '_galleria', esc_url( THEME_JS . '/galleria/themes/classic/galleria.classic.css' ), false, THEME_VERSION, 'screen' );
  15. wp_register_script( MYSITE_PREFIX . '_galleria', esc_url ( THEME_JS . '/galleria/galleria-1.2.7.min.js' ), array('jquery'), THEME_VERSION );
  16. wp_register_script( MYSITE_PREFIX . '_galleria_classic', esc_url ( THEME_JS . '/galleria/themes/classic/galleria.classic.min.js' ), array('jquery'), THEME_VERSION );
  17. # For cluetip
  18. wp_register_script( MYSITE_PREFIX . '_cluetip', esc_url ( THEME_JS . '/cluetip/jquery.cluetip.js' ), array('jquery'), THEME_VERSION );
  19. # For contact form
  20. wp_register_script( MYSITE_PREFIX . '_jquery_form', esc_url ( THEME_JS . '/jquery.form.js' ), array('jquery'), THEME_VERSION );
  21. # For jCarousel
  22. wp_register_script( MYSITE_PREFIX . '_jcarousel', esc_url ( THEME_JS . '/jcarousel/lib/jquery.jcarousel.min.js' ), array('jquery'), THEME_VERSION , true );
  23. # For prettyPhoto
  24. wp_register_style( MYSITE_PREFIX . '_prettyphoto', esc_url( THEME_JS . '/prettyphoto/css/prettyPhoto.css' ), false, THEME_VERSION, 'screen' );
  25. wp_register_script( MYSITE_PREFIX . '_prettyphoto', esc_url ( THEME_JS . '/prettyphoto/js/jquery.prettyPhoto.js' ), array('jquery'), THEME_VERSION, true );
  26. # For Flexslider
  27. wp_register_style( MYSITE_PREFIX . '_flexslider', esc_url( THEME_JS . '/flexslider/flexslider.css' ), false, THEME_VERSION, 'screen' );
  28. wp_register_script( MYSITE_PREFIX . '_flexslider', esc_url ( THEME_JS . '/flexslider/jquery.flexslider-min.js' ), array('jquery'), THEME_VERSION, true );
  29. # Mysite Custom
  30. wp_register_script( MYSITE_PREFIX . '_custom', esc_url ( THEME_JS . '/custom.js' ), array( 'jquery' ), THEME_VERSION );
  31. }
  32. /**
  33. *
  34. */
  35. function mysite_enqueue_script() {
  36. global $wp_query;
  37. # Styles array
  38. $mysite_styles = array(
  39. 'prettyphoto' => MYSITE_PREFIX . '_prettyphoto',
  40. 'galleria' => MYSITE_PREFIX . '_galleria',
  41. 'flexslider' => MYSITE_PREFIX . '_flexslider'
  42. );
  43. # Scripts array
  44. $mysite_script = array(
  45. 'comments' => 'comment-reply',
  46. 'tabs' => MYSITE_PREFIX . '_jquery_tools_tabs',
  47. 'scrolling' => MYSITE_PREFIX . '_jquery_tools_scrolling',
  48. 'nivo' => MYSITE_PREFIX . '_nivo',
  49. 'galleria' => MYSITE_PREFIX . '_galleria',
  50. 'galleria_classic' => MYSITE_PREFIX . '_galleria_classic',
  51. 'cluetip' => MYSITE_PREFIX . '_cluetip',
  52. 'form' => MYSITE_PREFIX . '_jquery_form',
  53. 'jcarousel' => MYSITE_PREFIX . '_jcarousel',
  54. 'prettyphoto' => MYSITE_PREFIX . '_prettyphoto',
  55. 'flexslider' => MYSITE_PREFIX . '_flexslider',
  56. 'custom' => MYSITE_PREFIX . '_custom'
  57. );
  58. $options = get_option( MYSITE_SETTINGS );
  59. $slider_type = apply_filters( 'mysite_slider_type', mysite_get_setting( 'homepage_slider' ) );
  60. $post_obj = $wp_query->get_queried_object();
  61. # Front page
  62. if( is_front_page() ) {
  63. # galleria hompage check
  64. if( strpos( $options['homepage_teaser_text'], '[galleria' ) === false &&
  65. strpos( $options['extra_header'], '[galleria' ) === false &&
  66. strpos( $options['teaser_button_text'], '[galleria' ) === false &&
  67. strpos( $options['content'], '[galleria' ) === false &&
  68. strpos( $options['homepage_footer_teaser'], '[galleria' ) === false ) { $galleria_unset = true; }
  69. # cluetip hompage check
  70. if( strpos( $options['homepage_teaser_text'], '[tooltip' ) === false &&
  71. strpos( $options['extra_header'], '[tooltip' ) === false &&
  72. strpos( $options['teaser_button_text'], '[tooltip' ) === false &&
  73. strpos( $options['content'], '[tooltip' ) === false &&
  74. strpos( $options['homepage_footer_teaser'], '[tooltip' ) === false ) { $cluetip_unset = true; }
  75. # contactform hompage check
  76. if( strpos( $options['homepage_teaser_text'], '[contactform' ) === false &&
  77. strpos( $options['extra_header'], '[contactform' ) === false &&
  78. strpos( $options['teaser_button_text'], '[contactform' ) === false &&
  79. strpos( $options['content'], '[contactform' ) === false &&
  80. strpos( $options['homepage_footer_teaser'], '[contactform' ) === false ) { $contactform_unset = true; }
  81. # jCarousel hompage check
  82. if( strpos( $options['homepage_teaser_text'], '[jcarousel' ) === false &&
  83. strpos( $options['extra_header'], '[jcarousel' ) === false &&
  84. strpos( $options['teaser_button_text'], '[jcarousel' ) === false &&
  85. strpos( $options['content'], '[jcarousel' ) === false &&
  86. strpos( $options['homepage_footer_teaser'], '[jcarousel' ) === false ) { $jcarousel_unset = true; }
  87. # nivo hompage check
  88. if( strpos( $options['homepage_teaser_text'], '[nivo' ) === false &&
  89. strpos( $options['extra_header'], '[nivo' ) === false &&
  90. strpos( $options['teaser_button_text'], '[nivo' ) === false &&
  91. strpos( $options['content'], '[nivo' ) === false &&
  92. strpos( $options['homepage_footer_teaser'], '[nivo' ) === false &&
  93. $slider_type != 'nivo_slider' ) { $nivo_unset = true; }
  94. # tabs/fading slider hompage check
  95. if( strpos( $options['homepage_teaser_text'], '[tab' ) === false &&
  96. strpos( $options['extra_header'], '[tab' ) === false &&
  97. strpos( $options['teaser_button_text'], '[tab' ) === false &&
  98. strpos( $options['content'], '[tab' ) === false &&
  99. strpos( $options['homepage_footer_teaser'], '[tab' ) === false &&
  100. $slider_type != 'fading_slider' ) { $tabs_unset = true; }
  101. # scrolling slider check
  102. if( $slider_type != 'scrolling_slider' )
  103. $scrolling_unset = true;
  104. # flexslider check
  105. if( $slider_type != 'responsive_slider' )
  106. $flexslider_unset = true;
  107. # check widgets for shortcodes
  108. if( is_active_sidebar( 'home' ) ) {
  109. $widget_sc = mysite_sc_widget_text();
  110. if( in_array( 'galleria', $widget_sc ) )
  111. $galleria_unset = false;
  112. if( in_array( 'nivo', $widget_sc ) )
  113. $nivo_unset = false;
  114. if( in_array( 'tabs', $widget_sc ) )
  115. $tabs_unset = false;
  116. if( in_array( 'tooltip', $widget_sc ) )
  117. $cluetip_unset = false;
  118. if( in_array( 'jcarousel', $widget_sc ) )
  119. $jcarousel_unset = false;
  120. }
  121. # contact form widget is active
  122. if ( is_active_widget( false, false, 'contact_form', true ) )
  123. $contactform_unset = false;
  124. }
  125. # Singular post/page
  126. if( is_singular() ) {
  127. $dependencies = get_post_meta( $post_obj->ID, '_dependencies', true );
  128. $dependencies = ( empty( $dependencies ) ) ? get_post_meta( $post_obj->ID, '_' . THEME_SLUG .'_dependencies', true ) : $dependencies;
  129. # check post meta for scripts
  130. if( strpos( $dependencies, 'all_scripts' ) === false && ( $options['blog_page'] != $post_obj->ID || empty( $options['display_full'] ) ) ) {
  131. if( strpos( $dependencies, 'galleria' ) === false )
  132. $galleria_unset = true;
  133. if( strpos( $dependencies, 'nivo' ) === false )
  134. $nivo_unset = true;
  135. if( strpos( $dependencies, 'tabs' ) === false )
  136. $tabs_unset = true;
  137. if( strpos( $dependencies, 'tooltip' ) === false )
  138. $cluetip_unset = true;
  139. if( strpos( $dependencies, 'contactform' ) === false )
  140. $contactform_unset = true;
  141. if( strpos( $dependencies, 'jcarousel' ) === false )
  142. $jcarousel_unset = true;
  143. # setting options
  144. if( strpos( $options['custom_teaser'], '[galleria' ) !== false ||
  145. strpos( $options['extra_header'], '[galleria' ) !== false ||
  146. strpos( $options['footer_teaser'], '[galleria' ) !== false ||
  147. strpos( $options['footer_text'], '[galleria' ) !== false ) { $galleria_unset = false; }
  148. if( strpos( $options['custom_teaser'], '[nivo' ) !== false ||
  149. strpos( $options['extra_header'], '[nivo' ) !== false ||
  150. strpos( $options['footer_teaser'], '[nivo' ) !== false ||
  151. strpos( $options['footer_text'], '[nivo' ) !== false ) { $nivo_unset = false; }
  152. if( strpos( $options['custom_teaser'], '[tab' ) !== false ||
  153. strpos( $options['extra_header'], '[tab' ) !== false ||
  154. strpos( $options['footer_teaser'], '[tab' ) !== false ||
  155. strpos( $options['footer_text'], '[tab' ) !== false ) { $tabs_unset = false; }
  156. if( strpos( $options['custom_teaser'], '[tooltip' ) !== false ||
  157. strpos( $options['extra_header'], '[tooltip' ) !== false ||
  158. strpos( $options['footer_teaser'], '[tooltip' ) !== false ||
  159. strpos( $options['footer_text'], '[tooltip' ) !== false ) { $cluetip_unset = false; }
  160. if( strpos( $options['custom_teaser'], '[contactform' ) !== false ||
  161. strpos( $options['extra_header'], '[contactform' ) !== false ||
  162. strpos( $options['footer_teaser'], '[contactform' ) !== false ||
  163. strpos( $options['footer_text'], '[contactform' ) !== false ) { $contactform_unset = false; }
  164. if( strpos( $options['custom_teaser'], '[jcarousel' ) !== false ||
  165. strpos( $options['extra_header'], '[jcarousel' ) !== false ||
  166. strpos( $options['footer_teaser'], '[jcarousel' ) !== false ||
  167. strpos( $options['footer_text'], '[jcarousel' ) !== false ) { $jcarousel_unset = false; }
  168. }
  169. # post comment styles set to tab
  170. if( apply_atomic( 'post_comment_styles', $options['post_comment_styles'] ) == 'tab' && is_single() )
  171. $tabs_unset = false;
  172. # post comment styles set to tab & page comments enabled
  173. if( apply_atomic( 'post_comment_styles', $options['post_comment_styles'] ) == 'tab' && !mysite_get_setting( 'disable_page_comments' ) && is_page() )
  174. $tabs_unset = false;
  175. # popular/related post set to tab
  176. if( apply_atomic( 'post_like_module', $options['post_like_module'] ) == 'tab' && is_single() )
  177. $tabs_unset = false;
  178. # scrolling slider check
  179. if( $slider_type != 'scrolling_slider' )
  180. $scrolling_unset = true;
  181. # flexslider check
  182. if( $slider_type != 'responsive_slider' )
  183. $flexslider_unset = true;
  184. }
  185. # if search, archive or 404 page
  186. if( is_archive() || is_search() || is_404() ) {
  187. $galleria_unset = true;
  188. $nivo_unset = true;
  189. $tabs_unset = true;
  190. $cluetip_unset = true;
  191. $contactform_unset = true;
  192. $scrolling_unset = true;
  193. $jcarousel_unset = true;
  194. }
  195. # check text widgets for shortcodes
  196. if( !is_front_page() ) {
  197. $widget_sc = mysite_sc_widget_text();
  198. if( in_array( 'galleria', $widget_sc ) )
  199. $galleria_unset = false;
  200. if( in_array( 'nivo', $widget_sc ) )
  201. $nivo_unset = false;
  202. if( in_array( 'tabs', $widget_sc ) )
  203. $tabs_unset = false;
  204. if( in_array( 'tooltip', $widget_sc ) )
  205. $cluetip_unset = false;
  206. if( in_array( 'jcarousel', $widget_sc ) )
  207. $jcarousel_unset = false;
  208. # contact form widget is active
  209. if ( is_active_widget( false, false, 'contact_form', true ) )
  210. $contactform_unset = false;
  211. }
  212. # If slider on every page option enabled
  213. if( apply_filters( 'mysite_slider_page', mysite_get_setting( 'slider_page' ) ) ) {
  214. if( $slider_type == 'fading_slider' )
  215. $tabs_unset = false;
  216. if( $slider_type == 'nivo_slider' )
  217. $nivo_unset = false;
  218. if( $slider_type == 'scrolling_slider' )
  219. $scrolling_unset = false;
  220. # flexslider check
  221. if( $slider_type == 'responsive_slider' )
  222. $flexslider_unset = false;
  223. }
  224. # unset tabs/fading slider
  225. if( !empty( $tabs_unset ) )
  226. unset( $mysite_script['tabs'] );
  227. # unset scrolling slider
  228. if( !empty( $scrolling_unset ) )
  229. unset( $mysite_script['scrolling'] );
  230. # unset nivo
  231. if( !empty( $nivo_unset ) )
  232. unset( $mysite_script['nivo'] );
  233. # unset cluetip
  234. if( !empty( $cluetip_unset ) )
  235. unset( $mysite_script['cluetip'] );
  236. # unset form
  237. if( !empty( $contactform_unset ) )
  238. unset( $mysite_script['form'] );
  239. # unset form
  240. if( !empty( $jcarousel_unset ) )
  241. unset( $mysite_script['jcarousel'] );
  242. # unset galleria
  243. if( !empty( $galleria_unset ) ) {
  244. unset( $mysite_styles['galleria'] );
  245. unset( $mysite_script['galleria'] );
  246. unset( $mysite_script['galleria_classic'] );
  247. }
  248. # unset flexslider
  249. if( !empty( $flexslider_unset ) ) {
  250. unset( $mysite_script['flexslider'] );
  251. unset( $mysite_styles['flexslider'] );
  252. }
  253. # unset WP comment-reply
  254. if ( !is_singular() || !comments_open() || ( get_option( 'thread_comments' ) != 1 ) )
  255. unset( $mysite_script['comments'] );
  256. # Styles filter
  257. $enqueue_styles = apply_atomic( 'styles', $mysite_styles );
  258. if( !empty( $enqueue_styles ) )
  259. foreach( $enqueue_styles as $style )
  260. wp_enqueue_style( $style );
  261. # Scripts filter
  262. $enqueue_script = apply_atomic( 'scripts', $mysite_script );
  263. if( !empty( $enqueue_script ) )
  264. foreach( $enqueue_script as $script )
  265. wp_enqueue_script( $script );
  266. # Custom Cufon Fonts
  267. $disable = apply_atomic( 'disable_cufon', mysite_get_setting( 'disable_cufon' ) );
  268. if( empty( $disable ) ) {
  269. $active_cufon = apply_filters( 'mysite_active_skin', get_option( MYSITE_ACTIVE_SKIN ) );
  270. if( !empty( $active_cufon['cufon_gradients_fonts'] ) )
  271. $active_cufon['fonts'] = array_merge( $active_cufon['fonts'], $active_cufon['cufon_gradients_fonts'] );
  272. if( is_array( $active_cufon ) && !empty( $active_cufon ) ) {
  273. foreach( $active_cufon['fonts'] as $font ) {
  274. wp_enqueue_script( MYSITE_PREFIX . '_cufon', esc_url ( THEME_JS . '/cufon-yui.js' ), array( 'jquery' ), THEME_VERSION );
  275. wp_enqueue_script( MYSITE_PREFIX . "_{$font}", esc_url ( THEME_JS . "/fonts/{$font}.js" ), array('jquery'), THEME_VERSION );
  276. }
  277. }
  278. }
  279. }
  280. /**
  281. *
  282. */
  283. function mysite_sc_widget_text() {
  284. $text_widgets = get_option( 'widget_text' );
  285. if( empty( $text_widgets ) ) return array();
  286. $widget_sc = array();
  287. foreach ( $text_widgets as $widget ) {
  288. if( !empty( $widget['text'] ) ) {
  289. if( strpos( $widget['text'], '[galleria' ) !== false )
  290. $widget_sc['galleria'] = 'galleria';
  291. if( strpos( $widget['text'], '[nivo' ) !== false )
  292. $widget_sc['nivo'] = 'nivo';
  293. if( strpos( $widget['text'], '[tab' ) !== false )
  294. $widget_sc['tabs'] = 'tabs';
  295. if( strpos( $widget['text'], '[tooltip' ) !== false )
  296. $widget_sc['tooltip'] = 'tooltip';
  297. }
  298. }
  299. return $widget_sc;
  300. }
  301. ?>