Advertisement
Guest User

Untitled

a guest
Jan 4th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.45 KB | None | 0 0
  1. <?php
  2. /**
  3. * Customizr functions
  4. *
  5. * The best way to add your own functions to Customizr is to create a child theme
  6. * http://codex.wordpress.org/Child_Themes
  7. *
  8. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
  9. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  10. * or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  13. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * You should have received a copy of the GNU General Public License along with this program; if not, write
  16. * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. *
  18. * @package Customizr
  19. * @subpackage functions
  20. * @since 3.0
  21. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  22. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  23. * @link http://themesandco.com/customizr
  24. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  25. */
  26.  
  27.  
  28. /**
  29. * Singleton factory : on demand class single instanciation
  30. * Thanks to Ben Doherty (https://github.com/bendoh) for the great programming approach
  31. *
  32. *
  33. * @since Customizr 3.0
  34. */
  35. if ( !function_exists( 'tc__' ) ) :
  36. function tc__ ( $instance_groups = null, $class = null ) {
  37.  
  38. static $instances;
  39.  
  40. $classname = '';
  41.  
  42. $instance_groups = is_array($instance_groups) ? $instance_groups : array($instance_groups);
  43.  
  44. //get the class file(s) array by group and name (if defined)
  45. $parent_files = tc_get_classes ( $instance_groups, $path = null ,$class );
  46. //Do we have to include some child theme classes?
  47. $child_files = tc_is_child() ? tc_get_classes ( $instance_groups, $path = null ,$class, $child=true) : array();
  48. $files = array_merge($parent_files, $child_files);
  49.  
  50. foreach ( $files as $f )
  51. {
  52. //load class files
  53. locate_template ( $f , true , true );//name, load, require_once
  54.  
  55. $classname = 'TC_'.tc_get_file_class( $f );
  56.  
  57. //instanciation
  58. if( !isset( $instances[ $classname ] ) )
  59. {
  60. $instances[ $classname ] = class_exists($classname) ? new $classname : '';
  61. }
  62. }//end foreach
  63. return $instances[ $classname ];
  64. }
  65. endif;
  66.  
  67. /**
  68. * *Center the logo from Customizr Code Snippet
  69. * */
  70. add_filter('tc_logo_title_display', 'your_logo_display');
  71. function your_logo_display($output) {
  72. return preg_replace('/brand span3/', 'brand span10 offset1', $output, -1);
  73. }
  74.  
  75.  
  76.  
  77.  
  78. /**
  79. * Checks if we use a child theme. Uses a deprecated WP functions (get_theme_data) for versions <3.4
  80. * @return boolean
  81. *
  82. * @since Customizr 3.0.11
  83. */
  84. if ( !function_exists( 'tc_is_child' ) ) :
  85. function tc_is_child() {
  86. // get themedata version wp 3.4+
  87. if( function_exists( 'wp_get_theme' ) ) {
  88. //CHECK IF WE ARE USING A CHILD THEME
  89. //get WP_Theme object of customizr
  90. $tc_theme = wp_get_theme();
  91. //define a boolean if using a child theme
  92. $is_child = ( $tc_theme -> parent() ) ? true : false;
  93. }
  94. else {
  95. $tc_theme = get_theme_data( get_stylesheet_directory() . '/style.css' );
  96. $is_child = ( !empty($tc_theme['Template']) ) ? true : false;
  97. }
  98.  
  99. return $is_child;
  100. }
  101. endif;
  102.  
  103.  
  104.  
  105.  
  106. /**
  107. * Recursive function, takes 4 parameters ( $group is required, $class, $path and $child are optional)
  108. * Scans the theme folder and returns an array of class file names according to their group/name
  109. *
  110. * @since Customizr 3.0
  111. */
  112. if ( !function_exists( 'tc_get_classes' ) ) :
  113. function tc_get_classes( $instance_groups , $path = null , $class = null, $child = null ) {
  114.  
  115. /* TC_BASE is the root server path of parent theme */
  116. if ( ! defined( 'TC_BASE' ) ) { define( 'TC_BASE' , get_template_directory().'/' ); }
  117.  
  118. if ( ! defined( 'TC_BASE_CHILD' ) ) { define( 'TC_BASE_CHILD' , get_stylesheet_directory().'/' ); }
  119.  
  120. //which folder are we scanning, parent or child?
  121. $tc_base = ($child) ? TC_BASE_CHILD: TC_BASE ;
  122.  
  123. //initializes the class files array
  124. $classes = array();
  125.  
  126. //root class instanciation : in this case we don't want to loop through all files
  127. if ( in_array('customizr', $instance_groups) ) {
  128. $classes[] = '/inc/class-customizr-__.php';
  129. }
  130.  
  131. //all other cases
  132. else {
  133.  
  134. $files = scandir($tc_base.$path) ;
  135.  
  136. foreach ( $files as $file)
  137. {
  138. if ( $file[0] != '.' )
  139. {
  140. if ( is_dir($tc_base.$path.$file) )
  141. {
  142. $classes = array_merge( $classes, tc_get_classes( $instance_groups, $path.$file.'/' , $class, $child));
  143. }
  144.  
  145. else if ( substr( $file, -4) == '.php' )
  146. {
  147. switch ( $class)
  148. {
  149. //if the class is not defined
  150. case null:
  151. if ( in_array( tc_get_file_group($file), $instance_groups) )
  152. {
  153. $classes[] = $path.$file;
  154. }
  155. break;
  156.  
  157. default:
  158. if ( tc_get_file_class($file) == $class)
  159. {
  160. $classes[] = $path.$file;
  161. }
  162. break;
  163. }//end switch
  164. }//end if
  165. } //end if
  166. }//end for each
  167. }//end if
  168.  
  169. return $classes;
  170.  
  171. }//end of function
  172. endif;
  173.  
  174.  
  175.  
  176.  
  177.  
  178. /**
  179. * Returns the class group from the file name
  180. *
  181. *
  182. * @since Customizr 3.0
  183. */
  184. if ( !function_exists( 'tc_get_file_group' ) ) :
  185. function tc_get_file_group( $file) {
  186.  
  187. $group = preg_match_all( '/\-(.*?)\-/' , $file , $match );
  188.  
  189. if ( isset( $match[1][0] ) )
  190. {
  191. return $match[1][0];
  192. }
  193. }
  194. endif;
  195.  
  196. /**
  197. *To add accordian slider to home page
  198. * *
  199. * /
  200. add_action ('__after_header', 'accordion_slider');
  201. function accordion_slider() {
  202. //checks that we display the home page
  203. if ( !tc__f('__is_home') )
  204. return;
  205.  
  206. //renders the new slider
  207. YOUR_SLIDER_RENDERING_FUNCTION()//if it is a shortcode, then use the do_shortcode() function
  208. }
  209.  
  210.  
  211.  
  212.  
  213. /**
  214. * Accordian Slider addition
  215. *
  216. * /
  217.  
  218. <?php
  219. add_action('wp_enqueue_scripts', 'load_accordion_slider_scripts');
  220. add_action('wp_footer', 'instantiate_accordion_slider');
  221.  
  222.  
  223. function load_accordion_slider_scripts() {
  224. wp_enqueue_style('accordion-slider-css', get_bloginfo('template_directory') . '/accordion-slider/css/accordion-slider.min.css');
  225.  
  226. wp_enqueue_script('jquery');
  227. wp_enqueue_script('accordion-slider-js', get_bloginfo('template_directory') . '/accordion-slider/js/jquery.accordionSlider.min.js');
  228. }
  229.  
  230.  
  231. function instantiate_accordion_slider() {
  232. ?>
  233. <script>
  234. jQuery(document).ready(function($){
  235. $('.accordion-slider').accordionSlider({
  236. width:960,
  237. height:300
  238. });
  239. });
  240. </script>
  241. <?php
  242. }
  243. ?>
  244.  
  245.  
  246.  
  247. /**
  248. * Returns the class name from the file name
  249. *
  250. *
  251. * @since Customizr 3.0
  252. */
  253. if ( !function_exists( 'tc_get_file_class' ) ) :
  254. function tc_get_file_class( $file) {
  255. //find the name of the class=>after last occurence of '-' and remove .php
  256. $pos = strripos( $haystack = $file , $needle = '-' );
  257. //get the part of the string containing the class name
  258. $classname = substr( $file , $pos + 1);
  259. //get rid of '.php'
  260. $classname = substr_replace( $classname , '' , -4 , 4);
  261.  
  262. return $classname;
  263. }
  264. endif;
  265.  
  266.  
  267.  
  268.  
  269. /**
  270. * Allows WP apply_filter() function to accept up to 4 optional arguments
  271. *
  272. *
  273. * @since Customizr 3.0
  274. */
  275. if( !function_exists( 'tc__f' )) :
  276. function tc__f ( $filter , $arg1 = null , $arg2 = null , $arg3 = null, $arg4 = null) {
  277.  
  278. return apply_filters( $filter , $arg1 , $arg2 , $arg3, $arg4 );
  279.  
  280. }
  281. endif;
  282.  
  283.  
  284.  
  285. /* Gets the saved options array and make it global */
  286. $tc_saved_options = get_option( 'tc_theme_options');
  287. global $tc_saved_options;
  288.  
  289. /* Loads the theme classes framework */
  290. tc__( 'customizr' );//fires the theme
  291.  
  292. /* Starts recording for server execution timeline in dev tools */
  293. tc__f( 'rec' , __FILE__ );
  294.  
  295.  
  296.  
  297.  
  298. /*
  299. * The best and safest way to add your own functions to Customizr is to create a child theme
  300. * You can add functions here but it will be lost on upgrade. If you use a child theme, you are safe!
  301. * http://codex.wordpress.org/Child_Themes
  302. */
  303.  
  304. add_action('wp_enqueue_scripts', 'load_accordion_slider_scripts');
  305. add_action('wp_footer', 'instantiate_accordion_slider');
  306.  
  307.  
  308. function load_accordion_slider_scripts() {
  309. wp_enqueue_style('accordion-slider-css', get_stylesheet_directory_uri() . '/accordion-slider/css/accordion-slider.min.css');
  310.  
  311. wp_enqueue_script('jquery');
  312. wp_enqueue_script('accordion-slider-js', get_stylesheet_directory_uri() . '/accordion-slider/js/jquery.accordionSlider.min.js');
  313. }
  314.  
  315.  
  316. function instantiate_accordion_slider() {
  317. ?>
  318. <script>
  319. jQuery(document).ready(function($){
  320. $('.accordion-slider').accordionSlider({
  321. width:720,
  322. height:300,
  323. startPanel:0,
  324. openPanelDuration:500
  325. });
  326. });
  327. </script>
  328. <?php
  329. }
  330. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement