Advertisement
Guest User

Untitled

a guest
Mar 27th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.86 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  
  5. *
  6.  
  7. * This program is a free software; you can use it and/or modify it under the terms of the GNU
  8.  
  9. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  10.  
  11. * or (at your option) any later version.
  12.  
  13. *
  14.  
  15. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  16.  
  17. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18.  
  19. *
  20.  
  21. * You should have received a copy of the GNU General Public License along with this program; if not, write
  22.  
  23. * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  24.  
  25. *
  26.  
  27. * @package Customizr
  28.  
  29. * @subpackage functions
  30.  
  31. * @since 1.0
  32.  
  33. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  34.  
  35. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  36.  
  37. * @link http://themesandco.com/customizr
  38.  
  39. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  40.  
  41. */
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /**
  50.  
  51. * This is where Customizr starts. This file defines and loads the theme's components :
  52.  
  53. * 1) A function tc__f() used everywhere in the theme, extension of WP built-in apply_filters()
  54.  
  55. * 2) Constants : CUSTOMIZR_VER, TC_BASE, TC_BASE_CHILD, TC_BASE_URL, TC_BASE_URL_CHILD, THEMENAME, TC_WEBSITE
  56.  
  57. * 3) Default filtered values : images sizes, skins, featured pages, social networks, widgets, post list layout
  58.  
  59. * 4) Text Domain
  60.  
  61. * 5) Theme supports : editor style, automatic-feed-links, post formats, navigation menu, post-thumbnails, retina support
  62.  
  63. * 6) Plugins compatibility : jetpack, bbpress, qtranslate, woocommerce and more to come
  64.  
  65. * 7) Default filtered options for the customizer
  66.  
  67. * 8) Customizr theme's hooks API : front end components are rendered with action and filter hooks
  68.  
  69. *
  70.  
  71. * The method TC__::tc__() loads the php files and instanciates all theme's classes.
  72.  
  73. * All classes files (except the class__.php file which loads the other) are named with the following convention : class-[group]-[class_name].php
  74.  
  75. *
  76.  
  77. * The theme is entirely built on an extensible filter and action hooks API, which makes customizations easy as breeze, without ever needing to modify the core structure.
  78.  
  79. * Customizr's code acts like a collection of plugins that can be enabled, disabled or extended.
  80.  
  81. *
  82.  
  83. */
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. /**
  92.  
  93. * The best and safest way to extend Customizr with your own custom functions is to create a child theme.
  94.  
  95. * You can add functions here but they will be lost on upgrade. If you use a child theme, you are safe!
  96.  
  97. * More informations on how to create a child theme with Customizr here : http://themesandco.com/customizr/#child-theme
  98.  
  99. */
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. /**
  108.  
  109. * The tc__f() function is an extension of WP built-in apply_filters() where the $value param becomes optional.
  110.  
  111. * It is shorter than the original apply_filters() and only used on already defined filters.
  112.  
  113. *
  114.  
  115. * By convention in Customizr, filter hooks are used as follow :
  116.  
  117. * 1) declared with add_filters in class constructors (mainly) to hook on WP built-in callbacks or create "getters" used everywhere
  118.  
  119. * 2) declared with apply_filters in methods to make the code extensible for developers
  120.  
  121. * 3) accessed with tc__f() to return values (while front end content is handled with action hooks)
  122.  
  123. *
  124.  
  125. * Used everywhere in Customizr. Can pass up to five variables to the filter callback.
  126.  
  127. *
  128.  
  129. * @since Customizr 3.0
  130.  
  131. */
  132.  
  133. if( !function_exists( 'tc__f' )) :
  134.  
  135. function tc__f ( $tag , $value = null , $arg_one = null , $arg_two = null , $arg_three = null , $arg_four = null , $arg_five = null) {
  136.  
  137. return apply_filters( $tag , $value , $arg_one , $arg_two , $arg_three , $arg_four , $arg_five );
  138.  
  139. }
  140.  
  141. endif;
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149. /**
  150.  
  151. * Fires the theme : constants definition, core classes loading
  152.  
  153. *
  154.  
  155. *
  156.  
  157. * @package Customizr
  158.  
  159. * @subpackage classes
  160.  
  161. * @since 3.0
  162.  
  163. * @author Nicolas GUILLAUME <nicolas@themesandco.com>
  164.  
  165. * @copyright Copyright (c) 2013, Nicolas GUILLAUME
  166.  
  167. * @link http://themesandco.com/customizr
  168.  
  169. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  170.  
  171. */
  172.  
  173.  
  174.  
  175. class TC___ {
  176.  
  177.  
  178.  
  179. //Access any method or var of the class with classname::$instance -> var or method():
  180.  
  181. static $instance;
  182.  
  183.  
  184.  
  185. public $tc_core;
  186.  
  187.  
  188.  
  189. function __construct () {
  190.  
  191.  
  192.  
  193. self::$instance =& $this;
  194.  
  195.  
  196.  
  197. //this is the structure of the Customizr code : groups => ('path' , 'class_suffix')
  198.  
  199. $this -> tc_core = apply_filters( 'tc_core',
  200.  
  201. array(
  202.  
  203. 'fire' => array(
  204.  
  205. array('inc' , 'init'),//defines default values (layout, socials, default slider...) and theme supports (after_setup_theme)
  206.  
  207. array('inc' , 'resources'),//loads style (skins) and scripts
  208.  
  209. array('inc' , 'utils'),//those are helpers used everywhere
  210.  
  211. array('inc' , 'widgets'),//widget factory
  212.  
  213. array('inc/admin' , 'admin_init'),//fires the customizer and the metaboxes for slider and layout options
  214.  
  215. ),
  216.  
  217. //the following files/classes define the action hooks for front end rendering : header, main content, footer
  218.  
  219. 'header' => array(
  220.  
  221. array('parts' , 'header_main'),
  222.  
  223. array('parts' , 'menu'),
  224.  
  225. array('parts' , 'nav_walker'),
  226.  
  227. ),
  228.  
  229. 'content' => array(
  230.  
  231. array('parts', '404'),
  232.  
  233. array('parts', 'attachment'),
  234.  
  235. array('parts', 'breadcrumb'),
  236.  
  237. array('parts', 'comments'),
  238.  
  239. array('parts', 'featured_pages'),
  240.  
  241. array('parts', 'gallery'),
  242.  
  243. array('parts', 'headings'),
  244.  
  245. array('parts', 'no_results'),
  246.  
  247. array('parts', 'page'),
  248.  
  249. array('parts', 'post'),
  250.  
  251. array('parts', 'post_list'),
  252.  
  253. array('parts', 'post_metas'),
  254.  
  255. array('parts', 'post_navigation'),
  256.  
  257. array('parts', 'sidebar'),
  258.  
  259. array('parts', 'slider'),
  260.  
  261. ),
  262.  
  263. 'footer' => array(
  264.  
  265. array('parts', 'footer_main'),
  266.  
  267. ),
  268.  
  269. 'addons' => apply_filters('tc_addons_classes' , array() )
  270.  
  271. )//end of array
  272.  
  273. );//end of filter
  274.  
  275.  
  276.  
  277. /* GETS INFORMATIONS FROM STYLE.CSS */
  278.  
  279. // get themedata version wp 3.4+
  280.  
  281. if( function_exists( 'wp_get_theme' ) )
  282.  
  283. {
  284.  
  285. //get WP_Theme object of customizr
  286.  
  287. $tc_theme = wp_get_theme();
  288.  
  289.  
  290.  
  291. //Get infos from parent theme if using a child theme
  292.  
  293. $tc_theme = $tc_theme -> parent() ? $tc_theme -> parent() : $tc_theme;
  294.  
  295.  
  296.  
  297. $tc_base_data['prefix'] = $tc_base_data['title'] = $tc_theme -> name;
  298.  
  299. $tc_base_data['version'] = $tc_theme -> version;
  300.  
  301. $tc_base_data['authoruri'] = $tc_theme -> {'Author URI'};
  302.  
  303. }
  304.  
  305.  
  306.  
  307. // get themedata for lower versions (get_stylesheet_directory() points to the current theme root, child or parent)
  308.  
  309. else
  310.  
  311. {
  312.  
  313. $tc_base_data = get_theme_data( get_stylesheet_directory().'/style.css' );
  314.  
  315. $tc_base_data['prefix'] = $tc_base_data['title'];
  316.  
  317. }
  318.  
  319.  
  320.  
  321. /* CUSTOMIZR_VER is the Version */
  322.  
  323. if( ! defined( 'CUSTOMIZR_VER' ) ) { define( 'CUSTOMIZR_VER' , $tc_base_data['version'] ); }
  324.  
  325.  
  326.  
  327. /* TC_BASE is the root server path of the parent theme */
  328.  
  329. if( ! defined( 'TC_BASE' ) ) { define( 'TC_BASE' , get_template_directory().'/' ); }
  330.  
  331.  
  332.  
  333. /* TC_BASE_CHILD is the root server path of the child theme */
  334.  
  335. if( ! defined( 'TC_BASE_CHILD' ) ) { define( 'TC_BASE_CHILD' , get_stylesheet_directory().'/' ); }
  336.  
  337.  
  338.  
  339. /* TC_BASE_URL http url of the loaded parent theme*/
  340.  
  341. if( ! defined( 'TC_BASE_URL' ) ) { define( 'TC_BASE_URL' , get_template_directory_uri() . '/' ); }
  342.  
  343.  
  344.  
  345. /* TC_BASE_URL_CHILD http url of the loaded child theme*/
  346.  
  347. if( ! defined( 'TC_BASE_URL_CHILD' ) ) { define( 'TC_BASE_URL_CHILD' , get_stylesheet_directory_uri() . '/' ); }
  348.  
  349.  
  350.  
  351. /* THEMENAME contains the Name of the currently loaded theme */
  352.  
  353. if( ! defined( 'THEMENAME' ) ) { define( 'THEMENAME' , $tc_base_data['title'] ); }
  354.  
  355.  
  356.  
  357. /* TC_WEBSITE is the home website of Customizr */
  358.  
  359. if( ! defined( 'TC_WEBSITE' ) ) { define( 'TC_WEBSITE' , $tc_base_data['authoruri'] ); }
  360.  
  361.  
  362.  
  363. /* theme class groups instanciation */
  364.  
  365. $this -> tc__ ( $this -> tc_core );
  366.  
  367.  
  368.  
  369. }//end of __construct()
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377. /**
  378.  
  379. * Class instanciation with a singleton factory :
  380.  
  381. * Thanks to Ben Doherty (https://github.com/bendoh) for the great programming approach
  382.  
  383. *
  384.  
  385. *
  386.  
  387. * @since Customizr 3.0
  388.  
  389. */
  390.  
  391. function tc__ ( $load ) {
  392.  
  393.  
  394.  
  395. static $instances;
  396.  
  397.  
  398.  
  399. foreach ( $load as $group => $files ) {
  400.  
  401. foreach ($files as $path_suffix ) {
  402.  
  403. //checks if a child theme is used and if the required file has to be overriden
  404.  
  405. if ( $this -> tc_is_child() && file_exists( TC_BASE_CHILD . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ) {
  406.  
  407. require_once ( TC_BASE_CHILD . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ;
  408.  
  409. }
  410.  
  411. else {
  412.  
  413. require_once ( TC_BASE . $path_suffix[0] . '/class-' . $group . '-' .$path_suffix[1] .'.php') ;
  414.  
  415. }
  416.  
  417.  
  418.  
  419. $classname = 'TC_' . $path_suffix[1];
  420.  
  421. if( ! isset( $instances[ $classname ] ) )
  422.  
  423. {
  424.  
  425. $instances[ $classname ] = class_exists($classname) ? new $classname : '';
  426.  
  427. }
  428.  
  429. }
  430.  
  431. }
  432.  
  433.  
  434.  
  435. return $instances[ $classname ];
  436.  
  437. }
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445. /**
  446.  
  447. * Checks if we use a child theme. Uses a deprecated WP functions (get_theme_data) for versions <3.4
  448.  
  449. * @return boolean
  450.  
  451. *
  452.  
  453. * @since Customizr 3.0.11
  454.  
  455. */
  456.  
  457. function tc_is_child() {
  458.  
  459. // get themedata version wp 3.4+
  460.  
  461. if( function_exists( 'wp_get_theme' ) ) {
  462.  
  463. //get WP_Theme object of customizr
  464.  
  465. $tc_theme = wp_get_theme();
  466.  
  467. //define a boolean if using a child theme
  468.  
  469. $is_child = ( $tc_theme -> parent() ) ? true : false;
  470.  
  471. }
  472.  
  473. else {
  474.  
  475. $tc_theme = get_theme_data( get_stylesheet_directory() . '/style.css' );
  476.  
  477. $is_child = ( ! empty($tc_theme['Template']) ) ? true : false;
  478.  
  479. }
  480.  
  481.  
  482.  
  483. return $is_child;
  484.  
  485. }
  486.  
  487.  
  488.  
  489. }//end of class
  490.  
  491.  
  492.  
  493. //Creates a new instance
  494.  
  495. new TC___;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement