aleistershadow

error579

Aug 25th, 2015
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 78.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * WordPress booster V 3.1 by tagDiv
  4. */
  5.  
  6. do_action('td_wp_booster_before'); //@todo is probably not used by anyone
  7.  
  8.  
  9. if (TD_DEPLOY_MODE == 'dev') {
  10. require_once('external/kint/Kint.class.php');
  11. }
  12.  
  13. // theme utility files
  14. require_once('td_global.php');
  15. require_once('td_util.php');
  16.  
  17. // load the wp_booster_api
  18. require_once('td_api.php');
  19.  
  20. // hook here to use the theme api
  21. do_action('td_global_after');
  22.  
  23.  
  24. require_once('td_global_blocks.php');
  25. require_once('td_menu.php'); //theme menu support
  26. require_once('td_social_icons.php'); // The social icons
  27. require_once('td_review.php'); // Review js buffer class //@todo de vazut pt autoload
  28. require_once('td_js_buffer.php'); // page generator
  29. require_once('td_unique_posts.php'); //unique posts (uses hooks + do_action('td_wp_boost_new_module'); )
  30. require_once('td_data_source.php'); // data source
  31. require_once('td_page_views.php'); // page views counter
  32. require_once('td_module.php'); // module builder
  33. require_once('td_block.php'); // block builder
  34. require_once('td_cake.php');
  35. require_once('td_widget_builder.php'); // widget builder
  36. require_once('td_first_install.php'); //the code that runs on the first install of the theme
  37. require_once("td_fonts.php"); //fonts support
  38. require_once("td_ajax.php"); // ajax
  39. require_once('td_video_support.php'); // video thumbnail support
  40. require_once('td_video_playlist_support.php'); //video playlist support
  41. require_once('td_css_buffer.php'); // css buffer class
  42. require_once('td_js_generator.php'); // ~ app config ~ css generator
  43. require_once('td_more_article_box.php'); //handles more articles box
  44. require_once('td_block_widget.php'); //used to make widgets from our blocks
  45. require_once('td_background.php'); // background support - is not autoloaded due to issues
  46. require_once('td_background_render.php');
  47.  
  48.  
  49.  
  50. require_once('td_autoload_classes.php'); //used to autoload classes [modules, blocks]
  51. // Every class after this (that has td_ in the name) is auto loaded only when it's required
  52. td_api_autoload::add('td_css_inline', td_global::$get_template_directory . '/includes/wp_booster/td_css_inline.php');
  53. td_api_autoload::add('td_login', td_global::$get_template_directory . '/includes/wp_booster/td_login.php');
  54. td_api_autoload::add('td_category_template', td_global::$get_template_directory . '/includes/wp_booster/td_category_template.php');
  55. td_api_autoload::add('td_category_top_posts_style', td_global::$get_template_directory . '/includes/wp_booster/td_category_top_posts_style.php');
  56. td_api_autoload::add('td_page_generator', td_global::$get_template_directory . '/includes/wp_booster/td_page_generator.php'); //not used on some homepages
  57. td_api_autoload::add('td_block_layout', td_global::$get_template_directory . '/includes/wp_booster/td_block_layout.php');
  58. td_api_autoload::add('td_template_layout', td_global::$get_template_directory . '/includes/wp_booster/td_template_layout.php');
  59. td_api_autoload::add('td_css_compiler', td_global::$get_template_directory . '/includes/wp_booster/td_css_compiler.php');
  60. td_api_autoload::add('td_module_single_base', td_global::$get_template_directory . '/includes/wp_booster/td_module_single_base.php');
  61. td_api_autoload::add('td_smart_list', td_global::$get_template_directory . '/includes/wp_booster/td_smart_list.php');
  62.  
  63. // aurora framework ??
  64. td_api_autoload::add('tdx_api_plugin', td_global::$get_template_directory . '/includes/wp_booster/aurora/tdx_api_plugin.php');
  65. td_api_autoload::add('tdx_api_panel', td_global::$get_template_directory . '/includes/wp_booster/aurora/tdx_api_panel.php');
  66. td_api_autoload::add('tdx_util', td_global::$get_template_directory . '/includes/wp_booster/aurora/tdx_util.php');
  67. td_api_autoload::add('tdx_options', td_global::$get_template_directory . '/includes/wp_booster/aurora/tdx_options.php');
  68.  
  69. /*
  70. // want to see the autoload status? uncomment this :)
  71. add_action('wp_footer', 'td_wp_footer_debug');
  72. function td_wp_footer_debug() {
  73. td_api_base::_debug_show_autoloaded_components();
  74. }
  75. */
  76.  
  77.  
  78.  
  79. if (TD_DEBUG_IOS_REDIRECT) {
  80. require_once('td_ios_redirect.php' );
  81. }
  82.  
  83. // at this point it's not safe to update the Theme API because it's already used
  84. do_action('td_wp_booster_loaded'); //used by our plugins
  85.  
  86.  
  87.  
  88. /* ----------------------------------------------------------------------------
  89. * Add theme support for features
  90. */
  91. add_theme_support('post-thumbnails');
  92. add_theme_support('post-formats', array('video'));
  93. add_theme_support('automatic-feed-links');
  94. add_theme_support('html5', array('comment-list', 'comment-form', 'search-form', 'gallery', 'caption'));
  95. add_theme_support('woocommerce');
  96.  
  97.  
  98.  
  99.  
  100. /* ----------------------------------------------------------------------------
  101. * front end js composer file @todo - check it why is this way
  102. */
  103. add_action('wp_enqueue_scripts', 'load_js_composer_front', 1000);
  104. function load_js_composer_front() {
  105. wp_enqueue_style('js_composer_front');
  106. }
  107.  
  108.  
  109.  
  110.  
  111. /* ----------------------------------------------------------------------------
  112. * front end css files
  113. */
  114. add_action('wp_enqueue_scripts', 'load_front_css', 1001); // 1001 priority because visual composer uses 1000
  115. function load_front_css() {
  116. if (TD_DEBUG_USE_LESS) {
  117. wp_enqueue_style('td-theme', td_global::$get_template_directory_uri . '/td_less_style.css.php', '', TD_THEME_VERSION, 'all' );
  118. if (td_global::$is_woocommerce_installed === true) {
  119. wp_enqueue_style('td-theme-woo', td_global::$get_template_directory_uri . '/td_less_style.css.php?part=woocommerce', '', TD_THEME_VERSION, 'all');
  120. }
  121. } else {
  122. wp_enqueue_style('td-theme', get_stylesheet_uri(), '', TD_THEME_VERSION, 'all' );
  123. if (td_global::$is_woocommerce_installed === true) {
  124. wp_enqueue_style('td-theme-woo', td_global::$get_template_directory_uri . '/style-woocommerce.css', '', TD_THEME_VERSION, 'all' );
  125. }
  126.  
  127. }
  128. }
  129.  
  130. /** ---------------------------------------------------------------------------
  131. * front end user compiled css @see td_css_generator.php
  132. */
  133. function td_include_user_compiled_css() {
  134. if (!is_admin()) {
  135. td_css_buffer::add_to_header(td_util::get_option('tds_user_compile_css'));
  136. }
  137. }
  138. add_action('wp_head', 'td_include_user_compiled_css', 10);
  139.  
  140.  
  141. /* ----------------------------------------------------------------------------
  142. * CSS fonts / google fonts in front end
  143. */
  144. add_action('wp_enqueue_scripts', 'td_load_css_fonts');
  145. function td_load_css_fonts() {
  146.  
  147. $td_user_fonts_list = array();
  148. $td_user_fonts_db = td_util::get_option('td_fonts');
  149.  
  150. if(!empty($td_user_fonts_db)) {
  151. foreach($td_user_fonts_db as $td_font_setting_key => $td_font_setting_val) {
  152. if(!empty($td_font_setting_val) and !empty($td_font_setting_val['font_family'])) {
  153. $td_user_fonts_list[] = $td_font_setting_val['font_family'];
  154. }
  155. }
  156. }
  157.  
  158.  
  159. foreach (td_global::$default_google_fonts_list as $default_font_id => $default_font_params) {
  160. if(!in_array('g_' . $default_font_id, $td_user_fonts_list)) {
  161. wp_enqueue_style($default_font_params['css_style_id'], $default_font_params['url'] . td_fonts::get_google_fonts_subset_query()); //used on menus/small text
  162. }
  163. }
  164.  
  165. /*
  166. * add the google link for fonts used by user
  167. *
  168. * td_fonts_css_files : holds the link to fonts.googleapis.com in the database
  169. *
  170. * this section will appear in the header of the source of the page
  171. */
  172. $td_fonts_css_files = td_util::get_option('td_fonts_css_files');
  173. if(!empty($td_fonts_css_files)) {
  174. wp_enqueue_style('google-fonts-style', td_global::$http_or_https . $td_fonts_css_files);
  175. }
  176. }
  177.  
  178.  
  179.  
  180.  
  181. /* ----------------------------------------------------------------------------
  182. * front end javascript files
  183. */
  184. add_action('wp_enqueue_scripts', 'load_front_js');
  185. function load_front_js() {
  186. $td_deploy_mode = TD_DEPLOY_MODE;
  187.  
  188. //switch the deploy mode to demo if we have tagDiv speed booster
  189. if (defined('TD_SPEED_BOOSTER')) {
  190. $td_deploy_mode = 'demo';
  191. }
  192.  
  193. switch ($td_deploy_mode) {
  194. default: //deploy
  195. wp_enqueue_script('td-site', td_global::$get_template_directory_uri . '/js/tagdiv_theme.js', array('jquery'), TD_THEME_VERSION, true);
  196. break;
  197.  
  198. case 'demo':
  199. wp_enqueue_script('td-site-min', td_global::$get_template_directory_uri . '/js/tagdiv_theme.min.js', array('jquery'), TD_THEME_VERSION, true);
  200. break;
  201.  
  202. case 'dev':
  203. // dev version - load each file separately
  204. $last_js_file_id = '';
  205. foreach (td_global::$js_files as $js_file_id => $js_file) {
  206. if ($last_js_file_id == '') {
  207. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array('jquery'), TD_THEME_VERSION, true); //first, load it with jQuery dependency
  208. } else {
  209. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array($last_js_file_id), TD_THEME_VERSION, true); //not first - load with the last file dependency
  210. }
  211. $last_js_file_id = $js_file_id;
  212. }
  213. break;
  214.  
  215. }
  216.  
  217. //add the comments reply to script on single pages
  218. if (is_singular()) {
  219. wp_enqueue_script('comment-reply');
  220. }
  221. }
  222.  
  223.  
  224.  
  225.  
  226. /* ----------------------------------------------------------------------------
  227. * css for wp-admin / backend
  228. */
  229. add_action('admin_enqueue_scripts', 'load_wp_admin_css');
  230. function load_wp_admin_css() {
  231. //load the panel font in wp-admin
  232. $td_protocol = is_ssl() ? 'https' : 'http';
  233. wp_enqueue_style('google-font-ubuntu', $td_protocol . '://fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,300italic,400italic,500italic,700italic&amp;subset=latin,cyrillic-ext,greek-ext,greek,latin-ext,cyrillic'); //used on content
  234. wp_enqueue_style('td-wp-admin-td-panel-2', td_global::$get_template_directory_uri . '/includes/wp_booster/wp-admin/css/wp-admin.css', false, TD_THEME_VERSION, 'all' );
  235.  
  236. //load the colorpicker
  237. wp_enqueue_style( 'wp-color-picker' );
  238. }
  239.  
  240.  
  241.  
  242.  
  243. /* ----------------------------------------------------------------------------
  244. * js for wp-admin / backend admin js
  245. */
  246. add_action('admin_enqueue_scripts', 'load_wp_admin_js');
  247. function load_wp_admin_js() {
  248.  
  249. // dev version - load each file separately
  250. $last_js_file_id = '';
  251. foreach (td_global::$js_files_for_wp_admin as $js_file_id => $js_file) {
  252. if ($last_js_file_id == '') {
  253. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array('jquery', 'wp-color-picker'), TD_THEME_VERSION, false); //first, load it with jQuery dependency
  254. } else {
  255. wp_enqueue_script($js_file_id, td_global::$get_template_directory_uri . $js_file, array($last_js_file_id), TD_THEME_VERSION, false); //not first - load with the last file dependency
  256. }
  257. $last_js_file_id = $js_file_id;
  258. }
  259.  
  260. wp_enqueue_script('thickbox');
  261. add_thickbox();
  262. }
  263.  
  264.  
  265.  
  266.  
  267. /* ----------------------------------------------------------------------------
  268. * Prepare head related links
  269. */
  270. add_action('wp_head', 'hook_wp_head', 1); //hook on wp_head -> 1 priority, we are first
  271. function hook_wp_head() {
  272. if (is_single()) {
  273. global $post;
  274.  
  275. // facebook sharing fix for videos, we add the custom meta data
  276. if (has_post_thumbnail($post->ID)) {
  277. $td_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
  278. if (!empty($td_image[0])) {
  279. echo '<meta property="og:image" content="' . $td_image[0] . '" />';
  280. }
  281. }
  282.  
  283. // show author meta tag on sigle pages
  284. $td_post_author = get_the_author_meta('display_name', $post->post_author);
  285. if ($td_post_author) {
  286. echo '<meta name="author" content="'.$td_post_author.'">'."\n";
  287. }
  288. }
  289.  
  290. // fav icon support
  291. $tds_favicon_upload = td_util::get_option('tds_favicon_upload');
  292. if (!empty($tds_favicon_upload)) {
  293. echo '<link rel="icon" type="image/png" href="' . $tds_favicon_upload . '">';
  294. }
  295.  
  296.  
  297. // ios bookmark icon support
  298. $tds_ios_76 = td_util::get_option('tds_ios_icon_76');
  299. $tds_ios_120 = td_util::get_option('tds_ios_icon_120');
  300. $tds_ios_152 = td_util::get_option('tds_ios_icon_152');
  301. $tds_ios_114 = td_util::get_option('tds_ios_icon_114');
  302. $tds_ios_144 = td_util::get_option('tds_ios_icon_144');
  303.  
  304. if(!empty($tds_ios_76)) {
  305. echo '<link rel="apple-touch-icon-precomposed" sizes="76x76" href="' . $tds_ios_76 . '"/>';
  306. }
  307.  
  308. if(!empty($tds_ios_120)) {
  309. echo '<link rel="apple-touch-icon-precomposed" sizes="120x120" href="' . $tds_ios_120 . '"/>';
  310. }
  311.  
  312. if(!empty($tds_ios_152)) {
  313. echo '<link rel="apple-touch-icon-precomposed" sizes="152x152" href="' . $tds_ios_152 . '"/>';
  314. }
  315.  
  316. if(!empty($tds_ios_114)) {
  317. echo '<link rel="apple-touch-icon-precomposed" sizes="114x114" href="' . $tds_ios_114 . '"/>';
  318. }
  319.  
  320. if(!empty($tds_ios_144)) {
  321. echo '<link rel="apple-touch-icon-precomposed" sizes="144x144" href="' . $tds_ios_144 . '"/>';
  322. }
  323.  
  324.  
  325.  
  326. // js variable td_viewport_interval_list added to the window object
  327. td_js_buffer::add_variable('td_viewport_interval_list', td_global::$td_viewport_intervals);
  328.  
  329.  
  330.  
  331. // @todo aici se va schimba setarea, iar userii isi pierd setarea existenta
  332. // lazy loading images - animation effect
  333. //$tds_lazy_loading_image = td_util::get_option('tds_lazy_loading_image');
  334. $tds_animation_stack = td_util::get_option('tds_animation_stack');
  335.  
  336. // the body css supplementary classes and the global js animation effects variables are set only if the option 'tds_animation_stack' is set
  337. if (empty($tds_animation_stack)) {
  338.  
  339. // js variable td_animation_stack_effect added to the window object
  340. $td_animation_stack_effect_type = 'type0';
  341. if (!empty(td_global::$td_options['tds_animation_stack_effect'])) {
  342. $td_animation_stack_effect_type = td_global::$td_options['tds_animation_stack_effect'];
  343. }
  344.  
  345. td_js_buffer::add_variable('td_animation_stack_effect', $td_animation_stack_effect_type);
  346. td_js_buffer::add_variable('tds_animation_stack', true);
  347.  
  348. foreach (td_global::$td_animation_stack_effects as $td_animation_stack_effect) {
  349. if ((($td_animation_stack_effect['val'] == '') and ($td_animation_stack_effect_type == 'type0')) ||
  350. ($td_animation_stack_effect['val'] == $td_animation_stack_effect_type)) {
  351.  
  352. td_js_buffer::add_variable('td_animation_stack_specific_selectors', $td_animation_stack_effect['specific_selectors']);
  353. td_js_buffer::add_variable('td_animation_stack_general_selectors', $td_animation_stack_effect['general_selectors']);
  354.  
  355. break;
  356. }
  357. }
  358. add_filter('body_class','td_hook_add_custom_body_class');
  359. }
  360.  
  361. // if speed booster is active, the body animation classes are added into the head style, otherwise they are applied too late (the same is td-backstretch)
  362. // if (defined('TD_SPEED_BOOSTER')) {
  363. // echo '<style type="text/css">
  364. // body.td-animation-stack-type0 .td-animation-stack .entry-thumb,
  365. // body.td-animation-stack-type0 .post img {
  366. // opacity: 0;
  367. // }
  368. //
  369. // body.td-animation-stack-type1 .td-animation-stack .entry-thumb,
  370. // body.td-animation-stack-type1 .post .entry-thumb,
  371. // body.td-animation-stack-type1 .post img[class*="wp-image-"],
  372. // body.td-animation-stack-type1 .post a.td-sml-link-to-image > img {
  373. // opacity: 0;
  374. // transform: scale(0.95);
  375. // }
  376. //
  377. // body.td-animation-stack-type2 .td-animation-stack .entry-thumb,
  378. // body.td-animation-stack-type2 .post .entry-thumb,
  379. // body.td-animation-stack-type2 .post img[class*="wp-image-"],
  380. // body.td-animation-stack-type2 .post a.td-sml-link-to-image > img {
  381. // opacity: 0;
  382. // .transform(translate(0px,10px));
  383. // }
  384. //
  385. // .td-backstretch {
  386. // display: block;
  387. // max-width: none;
  388. // opacity: 0;
  389. // transition: opacity 2s ease 0s;
  390. // }</style>';
  391. // }
  392.  
  393.  
  394.  
  395. $tds_general_modal_image = td_util::get_option('tds_general_modal_image');
  396.  
  397. if (!empty($tds_general_modal_image)) {
  398. td_js_buffer::add_variable('tds_general_modal_image', $tds_general_modal_image);
  399. }
  400. }
  401.  
  402.  
  403. /** ----------------------------------------------------------------------------
  404. * The function hook to alter body css classes.
  405. * It applies the necessary animation images effect to body @see animation-stack.less
  406. *
  407. * @param $classes
  408. *
  409. * @return array
  410. */
  411. function td_hook_add_custom_body_class($classes) {
  412.  
  413. if (empty(td_global::$td_options['tds_animation_stack'])) {
  414.  
  415. $td_animation_stack_effect_type = 'type0';
  416. if (!empty(td_global::$td_options['tds_animation_stack_effect'])) {
  417. $td_animation_stack_effect_type = td_global::$td_options['tds_animation_stack_effect'];
  418. }
  419.  
  420. $classes[] = 'td-animation-stack-' . $td_animation_stack_effect_type;
  421. }
  422. return $classes;
  423. }
  424.  
  425.  
  426.  
  427. /* ----------------------------------------------------------------------------
  428. * localization
  429. */
  430. add_action('after_setup_theme', 'td_load_text_domains');
  431. function td_load_text_domains() {
  432. load_theme_textdomain(TD_THEME_NAME, get_template_directory() . '/translation');
  433.  
  434. // theme specific config values
  435. require_once('td_translate.php');
  436.  
  437. }
  438.  
  439.  
  440.  
  441.  
  442. /* ----------------------------------------------------------------------------
  443. Custom <title> wp_title - seo
  444. */
  445. add_filter( 'wp_title', 'td_wp_title', 10, 2 );
  446. function td_wp_title( $title, $sep ) {
  447. global $paged, $page;
  448.  
  449. if ( is_feed() )
  450. return $title;
  451.  
  452. // Add the site name.
  453. $title .= get_bloginfo( 'name' );
  454.  
  455. // Add the site description for the home/front page.
  456. $site_description = get_bloginfo( 'description', 'display' );
  457. if ( $site_description && ( is_home() || is_front_page() ) )
  458. $title = "$title $sep $site_description";
  459.  
  460. // Add a page number if necessary.
  461. if ( $paged >= 2 || $page >= 2 )
  462. $title = "$title $sep " . __td('Page', TD_THEME_NAME) . ' ' . max( $paged, $page );
  463.  
  464. return $title;
  465. }
  466.  
  467. /**
  468. * - filter 'wpseo_title' is used by WordPress SEO plugin and, by default, it returns a seo title that hasn't the page number inside of it,
  469. * when it's used on td pages [those who have a custom pagination]. At that seo title is added the page info, and just for pages greater than 1
  470. */
  471. add_filter('wpseo_title', 'td_wpseo_title', 10, 1);
  472. function td_wpseo_title($seo_title) {
  473.  
  474. // outside the loop, it's reliable to check the page template
  475. if (!in_the_loop() && is_page_template('page-pagebuilder-latest.php')) {
  476.  
  477. $td_page = (get_query_var('page')) ? get_query_var('page') : 1; //rewrite the global var
  478. $td_paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //rewrite the global var
  479.  
  480. if ($td_paged > $td_page) {
  481. $local_paged = $td_paged;
  482. } else {
  483. $local_paged = $td_page;
  484. }
  485.  
  486. // the custom title is when the pagination is greater than 1
  487. if ($local_paged > 1) {
  488. return $seo_title . ' - ' . __td('Page', TD_THEME_NAME) . ' ' . $local_paged;
  489. }
  490. }
  491.  
  492. // otherwise, the param $seo_title is returned as it is
  493. return $seo_title;
  494. }
  495.  
  496.  
  497.  
  498.  
  499. /** ----------------------------------------------------------------------------
  500. archive widget - adds .current class in the archive widget and maybe it's used in other places too!
  501. */
  502. add_filter('get_archives_link', 'theme_get_archives_link');
  503. function theme_get_archives_link ( $link_html ) {
  504. global $wp;
  505. static $current_url;
  506. if ( empty( $current_url ) ) {
  507. $current_url = esc_url(add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) ));
  508. }
  509. if ( stristr( $current_url, 'page' ) !== false ) {
  510. $current_url = substr($current_url, 0, strrpos($current_url, 'page'));
  511. }
  512. if ( stristr( $link_html, $current_url ) !== false ) {
  513. $link_html = preg_replace( '/(<[^\s>]+)/', '\1 class="current"', $link_html, 1 );
  514. }
  515. return $link_html;
  516. }
  517.  
  518.  
  519.  
  520.  
  521. /* ----------------------------------------------------------------------------
  522. add span wrap for category number in widget
  523. */
  524. add_filter('wp_list_categories', 'cat_count_span');
  525. function cat_count_span($links) {
  526. $links = str_replace('</a> (', '<span class="td-widget-no">', $links);
  527. $links = str_replace(')', '</span></a>', $links);
  528. return $links;
  529. }
  530.  
  531.  
  532.  
  533.  
  534. /* ----------------------------------------------------------------------------
  535. remove gallery style css
  536. */
  537. add_filter( 'use_default_gallery_style', '__return_false' );
  538.  
  539.  
  540.  
  541.  
  542. /* ----------------------------------------------------------------------------
  543. more text
  544. */
  545. add_filter('excerpt_more', 'new_excerpt_more');
  546. function new_excerpt_more($text){
  547. return ' ';
  548. }
  549.  
  550.  
  551.  
  552.  
  553. /* ----------------------------------------------------------------------------
  554. editor style
  555. */
  556. add_action( 'after_setup_theme', 'my_theme_add_editor_styles' );
  557. function my_theme_add_editor_styles() {
  558. add_editor_style('td_less_editor-style.php');
  559. }
  560.  
  561.  
  562.  
  563.  
  564. /* ----------------------------------------------------------------------------
  565. the bottom code for css
  566. */
  567. add_action('wp_footer', 'td_bottom_code');
  568. function td_bottom_code() {
  569. global $post;
  570.  
  571. // try to detect speed booster
  572. $speed_booster = '';
  573. if (defined('TD_SPEED_BOOSTER')) {
  574. $speed_booster = 'Speed booster: ' . TD_SPEED_BOOSTER . "\n";
  575. }
  576.  
  577. echo '
  578.  
  579. <!--
  580.  
  581. Theme: ' . TD_THEME_NAME .' by tagDiv 2015
  582. Version: ' . TD_THEME_VERSION . ' (rara)
  583. Deploy mode: ' . TD_DEPLOY_MODE . '
  584. ' . $speed_booster . '
  585. uid: ' . uniqid() . '
  586. -->
  587.  
  588. ';
  589.  
  590.  
  591. // get and paste user custom css
  592. $td_custom_css = stripslashes(td_util::get_option('tds_custom_css'));
  593.  
  594.  
  595. // get the custom css for the responsive values
  596. $responsive_css_values = array();
  597. foreach (td_global::$theme_panel_custom_css_fields_list as $option_id => $css_params) {
  598. $responsive_css = td_util::get_option($option_id);
  599. if ($responsive_css != '') {
  600. $responsive_css_values[$css_params['media_query']] = $responsive_css;
  601. }
  602. }
  603.  
  604.  
  605.  
  606. // check if we have to show any css
  607. if (!empty($td_custom_css) or count($responsive_css_values) > 0) {
  608. $css_buffy = PHP_EOL . '<!-- Custom css form theme panel -->';
  609. $css_buffy .= PHP_EOL . '<style type="text/css" media="screen">';
  610.  
  611. //paste custom css
  612. if(!empty($td_custom_css)) {
  613. $css_buffy .= PHP_EOL . '/* custom css theme panel */' . PHP_EOL;
  614. $css_buffy .= $td_custom_css . PHP_EOL;
  615. }
  616.  
  617. foreach ($responsive_css_values as $media_query => $responsive_css) {
  618. $css_buffy .= PHP_EOL . PHP_EOL . '/* custom responsive css from theme panel (Advanced CSS) */';
  619. $css_buffy .= PHP_EOL . $media_query . ' {' . PHP_EOL;
  620. $css_buffy .= $responsive_css;
  621. $css_buffy .= PHP_EOL . '}' . PHP_EOL;
  622. }
  623. $css_buffy .= '</style>' . PHP_EOL . PHP_EOL;
  624.  
  625. // echo the css buffer
  626. echo $css_buffy;
  627. }
  628.  
  629.  
  630. //get and paste user custom javascript
  631. $td_custom_javascript = stripslashes(td_util::get_option('tds_custom_javascript'));
  632. if(!empty($td_custom_javascript)) {
  633. echo '<script type="text/javascript">'
  634. .$td_custom_javascript.
  635. '</script>';
  636. }
  637.  
  638. //AJAX POST VIEW COUNT
  639. if(td_util::get_option('tds_ajax_post_view_count') == 'enabled') {
  640.  
  641. //Ajax get & update counter views
  642. if(is_single()) {
  643. //echo 'post page: '. $post->ID;
  644. if($post->ID > 0) {
  645. td_js_buffer::add_to_footer('
  646. jQuery().ready(function jQuery_ready() {
  647. td_ajax_count.td_get_views_counts_ajax("post",' . json_encode('[' . $post->ID . ']') . ');
  648. });
  649. ');
  650. }
  651. }
  652. }
  653.  
  654.  
  655.  
  656.  
  657. if (TD_DEBUG_USE_LESS) {
  658. $style_sheet_path = td_global::$get_template_directory_uri . '/td_less_style.css.php';
  659. } else {
  660. $style_sheet_path = get_stylesheet_uri();
  661. }
  662.  
  663. /**
  664. * javascript splitter js split for IE8 and IE9.
  665. * It searches in the stylesheet for #td_css_split_separator and adds it in two pieces for ie8 ie9 selector bug
  666. */
  667. ob_start();
  668. ?>
  669. <script>
  670.  
  671. (function(){
  672. var html_jquery_obj = jQuery('html');
  673.  
  674. if (html_jquery_obj.length && (html_jquery_obj.is('.ie8') || html_jquery_obj.is('.ie9'))) {
  675.  
  676. var path = '<?php echo $style_sheet_path; ?>';
  677.  
  678. jQuery.get(path, function(data) {
  679.  
  680. var str_split_separator = '#td_css_split_separator';
  681. var arr_splits = data.split(str_split_separator);
  682. var arr_length = arr_splits.length;
  683.  
  684. if (arr_length > 1) {
  685.  
  686. var dir_path = '<?php echo get_template_directory_uri() ?>';
  687. var splited_css = '';
  688.  
  689. for (var i = 0; i < arr_length; i++) {
  690. if (i > 0) {
  691. arr_splits[i] = str_split_separator + ' ' + arr_splits[i];
  692. }
  693. //jQuery('head').append('<style>' + arr_splits[i] + '</style>');
  694.  
  695. var formated_str = arr_splits[i].replace(/\surl\(\'(?!data\:)/gi, function regex_function(str) {
  696. return ' url(\'' + dir_path + '/' + str.replace(/url\(\'/gi, '').replace(/^\s+|\s+$/gm,'');
  697. });
  698.  
  699. splited_css += "<style>" + formated_str + "</style>";
  700. }
  701.  
  702. var td_theme_css = jQuery('link#td-theme-css');
  703.  
  704. if (td_theme_css.length) {
  705. td_theme_css.after(splited_css);
  706. }
  707. }
  708. });
  709. }
  710. })();
  711.  
  712. </script>
  713. <?php
  714. $script_buffer = ob_get_clean();
  715. $js_script = "\n". td_util::remove_script_tag($script_buffer);
  716. td_js_buffer::add_to_footer($js_script);
  717. }
  718.  
  719.  
  720.  
  721.  
  722. /* ----------------------------------------------------------------------------
  723. google analytics
  724. */
  725. add_action('wp_head', 'td_header_analytics_code', 40);
  726. function td_header_analytics_code() {
  727. $td_analytics = td_util::get_option('td_analytics');
  728. echo stripslashes($td_analytics);
  729.  
  730. }
  731.  
  732.  
  733.  
  734.  
  735. /* ----------------------------------------------------------------------------
  736. Append page slugs to the body class
  737. */
  738. add_filter('body_class', 'add_slug_to_body_class');
  739. function add_slug_to_body_class( $classes ) {
  740. global $post;
  741. if( is_home() ) {
  742. $key = array_search( 'blog', $classes );
  743. if($key > -1) {
  744. unset( $classes[$key] );
  745. };
  746. } elseif( is_page() ) {
  747. $classes[] = sanitize_html_class( $post->post_name );
  748. } elseif(is_singular()) {
  749. $classes[] = sanitize_html_class( $post->post_name );
  750. };
  751.  
  752. $i = 0;
  753. foreach ($classes as $key => $value) {
  754. $pos = strripos($value, 'span');
  755. if ($pos !== false) {
  756. unset($classes[$i]);
  757. }
  758.  
  759. $pos = strripos($value, 'row');
  760. if ($pos !== false) {
  761. unset($classes[$i]);
  762. }
  763.  
  764. $pos = strripos($value, 'container');
  765. if ($pos !== false) {
  766. unset($classes[$i]);
  767. }
  768. $i++;
  769. }
  770. return $classes;
  771. }
  772.  
  773.  
  774.  
  775.  
  776. /* ----------------------------------------------------------------------------
  777. remove span row container classes from post_class()
  778. */
  779. add_filter('post_class', 'add_slug_to_post_class');
  780. function add_slug_to_post_class($classes) {
  781. global $post;
  782.  
  783. // on custom post types, we add the .post class for better css compatibility
  784. if (is_single() and $post->post_type != 'post') {
  785. $classes[]= 'post';
  786. }
  787.  
  788. $i = 0;
  789. foreach ($classes as $key => $value) {
  790. $pos = strripos($value, 'span');
  791. if ($pos !== false) {
  792. unset($classes[$i]);
  793. }
  794.  
  795. $pos = strripos($value, 'row');
  796. if ($pos !== false) {
  797. unset($classes[$i]);
  798. }
  799.  
  800. $pos = strripos($value, 'container');
  801. if ($pos !== false) {
  802. unset($classes[$i]);
  803. }
  804. $i++;
  805. }
  806. return $classes;
  807. }
  808.  
  809.  
  810.  
  811.  
  812. /* -----------------------------------------------------------------------------
  813. Our custom admin bar
  814. */
  815. add_action('admin_bar_menu', 'td_custom_menu', 1000);
  816. function td_custom_menu() {
  817. global $wp_admin_bar;
  818. if(!is_super_admin() || !is_admin_bar_showing()) return;
  819.  
  820. $wp_admin_bar->add_menu(array(
  821. 'parent' => 'site-name',
  822. 'title' => '<span class="td-admin-bar-red">Theme panel</span>',
  823. 'href' => admin_url('admin.php?page=td_theme_panel'),
  824. 'id' => 'td-menu1'
  825. ));
  826.  
  827. $wp_admin_bar->add_menu( array(
  828. 'id' => 'our_support_item',
  829. 'meta' => array('title' => 'Theme support', 'target' => '_blank'),
  830. 'title' => 'Theme support',
  831. 'href' => 'http://forum.tagdiv.com' ));
  832.  
  833. }
  834.  
  835.  
  836.  
  837.  
  838. /* -----------------------------------------------------------------------------
  839. * Add prev and next links to a numbered link list - the pagination on single.
  840. */
  841. add_filter('wp_link_pages_args', 'wp_link_pages_args_prevnext_add');
  842. function wp_link_pages_args_prevnext_add($args)
  843. {
  844. global $page, $numpages, $more, $pagenow;
  845.  
  846. if (!$args['next_or_number'] == 'next_and_number')
  847. return $args; # exit early
  848.  
  849. $args['next_or_number'] = 'number'; # keep numbering for the main part
  850. if (!$more)
  851. return $args; # exit early
  852.  
  853. if($page-1) # there is a previous page
  854. $args['before'] .= _wp_link_page($page-1)
  855. . $args['link_before']. $args['previouspagelink'] . $args['link_after'] . '</a>'
  856. ;
  857.  
  858. if ($page<$numpages) # there is a next page
  859. $args['after'] = _wp_link_page($page+1)
  860. . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '</a>'
  861. . $args['after']
  862. ;
  863.  
  864. return $args;
  865. }
  866.  
  867.  
  868.  
  869.  
  870. /* -----------------------------------------------------------------------------
  871. * Add, on theme body element, the custom classes from Theme Panel -> Custom Css -> Custom Body class(s)
  872. */
  873. add_filter('body_class','td_my_custom_class_names_on_body');
  874. function td_my_custom_class_names_on_body($classes) {
  875. //get the custom classes from theme options
  876. $custom_classes = td_util::get_option('td_body_classes');
  877.  
  878. if(!empty($custom_classes)) {
  879. // add 'custom classes' to the $classes array
  880. $classes[] = $custom_classes;
  881. }
  882.  
  883. // return the $classes array
  884. return $classes;
  885. }
  886.  
  887.  
  888.  
  889.  
  890. /* ----------------------------------------------------------------------------
  891. used by ie8 - there is no other way to add js for ie8 only
  892. */
  893. add_action('wp_head', 'add_ie_html5_shim');
  894. function add_ie_html5_shim () {
  895. echo '<!--[if lt IE 9]>';
  896. echo '<script src="' . td_global::$http_or_https . '://html5shim.googlecode.com/svn/trunk/html5.js"></script>';
  897. echo '<![endif]-->
  898. ';
  899. }
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907. /* ----------------------------------------------------------------------------
  908. add extra contact information for author in wp-admin -> users -> your profile
  909. */
  910. add_filter('user_contactmethods', 'td_extra_contact_info_for_author');
  911. function td_extra_contact_info_for_author($contactmethods) {
  912. unset($contactmethods['aim']);
  913. unset($contactmethods['yim']);
  914. unset($contactmethods['jabber']);
  915. foreach (td_social_icons::$td_social_icons_array as $td_social_id => $td_social_name) {
  916. $contactmethods[$td_social_id] = $td_social_name;
  917. }
  918. return $contactmethods;
  919. }
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. /* ----------------------------------------------------------------------------
  929. * shortcodes in widgets
  930. */
  931. add_filter('widget_text', 'do_shortcode');
  932.  
  933.  
  934.  
  935.  
  936. /* ----------------------------------------------------------------------------
  937. * FILTER - the_content_more_link - read more - ?
  938. */
  939. add_filter('the_content_more_link', 'td_remove_more_link_scroll');
  940. function td_remove_more_link_scroll($link) {
  941. $link = preg_replace('|#more-[0-9]+|', '', $link);
  942. $link = '<div class="more-link-wrap">' . $link . '</div>';
  943. return $link;
  944. }
  945.  
  946.  
  947.  
  948.  
  949. /* ----------------------------------------------------------------------------
  950. * Visual Composer init
  951. */
  952. register_activation_hook('js_composer/js_composer.php', 'td_vc_kill_welcome', 11);
  953. function td_vc_kill_welcome() {
  954. remove_action('vc_activation_hook', 'vc_page_welcome_set_redirect');
  955. }
  956.  
  957.  
  958. /**
  959. * visual composer rewrite classes
  960. * Filter to Replace default css class for vc_row shortcode and vc_column
  961. */
  962. add_filter('vc_shortcodes_css_class', 'custom_css_classes_for_vc_row_and_vc_column', 10, 2);
  963. function custom_css_classes_for_vc_row_and_vc_column($class_string, $tag) {
  964. //vc_span4
  965. if ($tag == 'vc_row' || $tag == 'vc_row_inner') {
  966. $class_string = str_replace('vc_row-fluid', 'td-pb-row', $class_string);
  967. }
  968. if ($tag == 'vc_column' || $tag == 'vc_column_inner') {
  969. $class_string = preg_replace('/vc_col-sm-(\d{1,2})/', 'td-pb-span$1', $class_string);
  970. //$class_string = preg_replace('/vc_span(\d{1,2})/', 'td-pb-span$1', $class_string);
  971. }
  972. return $class_string;
  973. }
  974.  
  975. add_action('vc_load_default_templates','my_custom_template_for_vc');
  976. function my_custom_template_for_vc($templates) {
  977.  
  978. require_once(get_template_directory() . '/includes/td_templates_builder.php');
  979.  
  980. global $td_vc_templates;
  981. global $vc_manager;
  982.  
  983. if (isset($vc_manager) and is_object($vc_manager) and method_exists($vc_manager, 'vc')) {
  984. $vc = $vc_manager->vc();
  985.  
  986. if (isset($vc) and is_object($vc) and method_exists($vc, 'templatesPanelEditor')) {
  987. $vc_template_panel_editor = $vc->templatesPanelEditor();
  988.  
  989. if (isset($vc_template_panel_editor)
  990. and is_object($vc_template_panel_editor)
  991. and has_filter('vc_load_default_templates_welcome_block', array($vc_template_panel_editor, 'loadDefaultTemplatesLimit'))) {
  992.  
  993. remove_filter('vc_load_default_templates_welcome_block', array($vc_template_panel_editor, 'loadDefaultTemplatesLimit'));
  994. }
  995. }
  996. }
  997. return $td_vc_templates;
  998. }
  999.  
  1000.  
  1001. td_vc_init();
  1002. function td_vc_init() {
  1003.  
  1004. // Force Visual Composer to initialize as "built into the theme". This will hide certain tabs under the Settings->Visual Composer page
  1005. if (function_exists('vc_set_as_theme')) {
  1006. vc_set_as_theme(true);
  1007. }
  1008.  
  1009. if (function_exists('wpb_map')) {
  1010. //map all of our blocks in page builder
  1011. td_global_blocks::wpb_map_all();
  1012. }
  1013.  
  1014. if (function_exists('vc_disable_frontend')) {
  1015. vc_disable_frontend();
  1016. }
  1017.  
  1018.  
  1019. // @todo - this may not be requiered anynmore
  1020. if (class_exists('WPBakeryVisualComposer')) { //disable visual composer updater
  1021. $td_composer = WPBakeryVisualComposer::getInstance();
  1022. $td_composer->disableUpdater();
  1023. }
  1024.  
  1025. }
  1026.  
  1027.  
  1028.  
  1029.  
  1030. /* ----------------------------------------------------------------------------
  1031. * TagDiv gallery - tinyMCE hooks
  1032. */
  1033. add_action('print_media_templates', 'td_custom_gallery_settings_hook');
  1034. add_action('print_media_templates', 'td_change_backbone_js_hook');
  1035. /**
  1036. * custom gallery setting
  1037. */
  1038. function td_custom_gallery_settings_hook () {
  1039. // define your backbone template;
  1040. // the "tmpl-" prefix is required,
  1041. // and your input field should have a data-setting attribute
  1042. // matching the shortcode name
  1043. ?>
  1044. <script type="text/html" id="tmpl-td-custom-gallery-setting">
  1045. <label class="setting">
  1046. <span>Gallery Type</span>
  1047. <select data-setting="td_select_gallery_slide">
  1048. <option value="">Default </option>
  1049. <option value="slide">TagDiv Slide Gallery</option>
  1050. </select>
  1051. </label>
  1052.  
  1053. <label class="setting">
  1054. <span>Gallery Title</span>
  1055. <input type="text" value="" data-setting="td_gallery_title_input" />
  1056. </label>
  1057. </script>
  1058.  
  1059. <script>
  1060.  
  1061. jQuery(document).ready(function(){
  1062.  
  1063. // add your shortcode attribute and its default value to the
  1064. // gallery settings list; $.extend should work as well...
  1065. _.extend(wp.media.gallery.defaults, {
  1066. td_select_gallery_slide: '', td_gallery_title_input: ''
  1067. });
  1068.  
  1069. // merge default gallery settings template with yours
  1070. wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({
  1071. template: function(view){
  1072. return wp.media.template('gallery-settings')(view)
  1073. + wp.media.template('td-custom-gallery-setting')(view);
  1074. }
  1075. // ,initialize: function() {
  1076. // if (typeof this.model.get('td_select_gallery_slide') == 'undefined') {
  1077. // this.model.set({td_select_gallery_slide: 'slide'});
  1078. // }
  1079. // }
  1080. });
  1081.  
  1082. //console.log();
  1083. // wp.media.model.Attachments.trigger('change')
  1084. });
  1085.  
  1086. </script>
  1087. <?php
  1088. }
  1089.  
  1090.  
  1091. /**
  1092. * td-modal-image support in tinymce
  1093. */
  1094. function td_change_backbone_js_hook() {
  1095. //change the backbone js template
  1096.  
  1097.  
  1098. // make the buffer for the dropdown
  1099. $image_styles_buffer_for_select = '';
  1100. $image_styles_buffer_for_switch = '';
  1101.  
  1102.  
  1103. foreach (td_global::$tiny_mce_image_style_list as $tiny_mce_image_style_id => $tiny_mce_image_style_params) {
  1104. $image_styles_buffer_for_select .= "'<option value=\"" . $tiny_mce_image_style_id . "\">" . $tiny_mce_image_style_params['text'] . "</option>' + ";
  1105. $image_styles_buffer_for_switch .= "
  1106. case '$tiny_mce_image_style_id':
  1107. td_clear_all_classes(); //except the modal one
  1108. td_add_image_css_class('" . $tiny_mce_image_style_params['class'] . "');
  1109. break;
  1110. ";
  1111. }
  1112.  
  1113.  
  1114. ?>
  1115. <script type="text/javascript">
  1116.  
  1117. (function (){
  1118.  
  1119. var td_template_content = jQuery('#tmpl-image-details').text();
  1120.  
  1121. var td_our_content = '' +
  1122. '<div class="setting">' +
  1123. '<span>Modal image</span>' +
  1124. '<div class="button-large button-group" >' +
  1125. '<button class="button active td-modal-image-off" value="left">Off</button>' +
  1126. '<button class="button td-modal-image-on" value="left">On</button>' +
  1127. '</div><!-- /setting -->' +
  1128. '<div class="setting">' +
  1129. '<span>tagDiv image style</span>' +
  1130. '<select class="size td-wp-image-style">' +
  1131. '<option value="">Default</option>' +
  1132. <?php echo $image_styles_buffer_for_select ?>
  1133. '</select>' +
  1134. '</div>' +
  1135. '</div>';
  1136.  
  1137. //inject our settings in the template - before <div class="setting align">
  1138. td_template_content = td_template_content.replace('<div class="setting align">', td_our_content + '<div class="setting align">');
  1139.  
  1140. //save the template
  1141. jQuery('#tmpl-image-details').html(td_template_content);
  1142.  
  1143. //modal off - click event
  1144. jQuery(".td-modal-image-on").live( "click", function() {
  1145. if (jQuery(this).hasClass('active')) {
  1146. return;
  1147. }
  1148. td_add_image_css_class('td-modal-image');
  1149.  
  1150. jQuery(".td-modal-image-off").removeClass('active');
  1151. jQuery(".td-modal-image-on").addClass('active');
  1152. });
  1153.  
  1154. //modal on - click event
  1155. jQuery(".td-modal-image-off").live( "click", function() {
  1156. if (jQuery(this).hasClass('active')) {
  1157. return;
  1158. }
  1159.  
  1160. td_remove_image_css_class('td-modal-image');
  1161.  
  1162. jQuery(".td-modal-image-off").addClass('active');
  1163. jQuery(".td-modal-image-on").removeClass('active');
  1164. });
  1165.  
  1166. // select change event
  1167. jQuery(".td-wp-image-style").live( "change", function() {
  1168. switch (jQuery( ".td-wp-image-style").val()) {
  1169.  
  1170. <?php echo $image_styles_buffer_for_switch; ?>
  1171.  
  1172. default:
  1173. td_clear_all_classes(); //except the modal one
  1174. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1175. }
  1176. });
  1177.  
  1178. //util functions to edit the image details in wp-admin
  1179. function td_add_image_css_class(new_class) {
  1180. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1181. jQuery('*[data-setting="extraClasses"]').val(td_extra_classes_value + ' ' + new_class);
  1182. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1183. }
  1184.  
  1185. function td_remove_image_css_class(new_class) {
  1186. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1187.  
  1188. //try first with a space before the class
  1189. var td_regex = new RegExp(" " + new_class,"g");
  1190. td_extra_classes_value = td_extra_classes_value.replace(td_regex, '');
  1191.  
  1192. var td_regex = new RegExp(new_class,"g");
  1193. td_extra_classes_value = td_extra_classes_value.replace(td_regex, '');
  1194.  
  1195. jQuery('*[data-setting="extraClasses"]').val(td_extra_classes_value);
  1196. jQuery('*[data-setting="extraClasses"]').change(); //trigger the change event for backbonejs
  1197. }
  1198.  
  1199. //clears all classes except the modal image one
  1200. function td_clear_all_classes() {
  1201. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1202. if (td_extra_classes_value.indexOf('td-modal-image') > -1) {
  1203. //we have the modal image one - keep it, remove the others
  1204. jQuery('*[data-setting="extraClasses"]').val('td-modal-image');
  1205. } else {
  1206. jQuery('*[data-setting="extraClasses"]').val('');
  1207. }
  1208. }
  1209.  
  1210. //monitor the backbone template for the current status of the picture
  1211. setInterval(function(){
  1212. var td_extra_classes_value = jQuery('*[data-setting="extraClasses"]').val();
  1213. if (typeof td_extra_classes_value !== 'undefined' && td_extra_classes_value != '') {
  1214. // if we have modal on, switch the toggle
  1215. if (td_extra_classes_value.indexOf('td-modal-image') > -1) {
  1216. jQuery(".td-modal-image-off").removeClass('active');
  1217. jQuery(".td-modal-image-on").addClass('active');
  1218. }
  1219.  
  1220. <?php
  1221.  
  1222. foreach (td_global::$tiny_mce_image_style_list as $tiny_mce_image_style_id => $tiny_mce_image_style_params) {
  1223. ?>
  1224. //change the select
  1225. if (td_extra_classes_value.indexOf('<?php echo $tiny_mce_image_style_params['class'] ?>') > -1) {
  1226. jQuery(".td-wp-image-style").val('<?php echo $tiny_mce_image_style_id ?>');
  1227. }
  1228. <?php
  1229. }
  1230.  
  1231. ?>
  1232.  
  1233. }
  1234. }, 1000);
  1235. })(); //end anon function
  1236. </script>
  1237. <?php
  1238. }
  1239.  
  1240.  
  1241.  
  1242.  
  1243. /* ----------------------------------------------------------------------------
  1244. * TagDiv gallery - front end hooks
  1245. */
  1246. add_filter('post_gallery', 'my_gallery_shortcode', 10, 4);
  1247. /**
  1248. * @param string $output - is empty !!!
  1249. * @param $atts
  1250. * @param bool $content
  1251. * @param bool $tag
  1252. * @return mixed
  1253. */
  1254. function my_gallery_shortcode($output = '', $atts, $content = false, $tag = false) {
  1255.  
  1256. //print_r($atts);
  1257. $buffy = '';
  1258.  
  1259. //check for gallery = slide
  1260. if(!empty($atts) and !empty($atts['td_select_gallery_slide']) and $atts['td_select_gallery_slide'] == 'slide') {
  1261.  
  1262. $td_double_slider2_no_js_limit = 7;
  1263. $td_nr_columns_slide = 'td-slide-on-2-columns';
  1264. $nr_title_chars = 95;
  1265.  
  1266. //check to see if we have or not sidebar on the page, to set the small images when need to show them on center
  1267. if(td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  1268. $td_double_slider2_no_js_limit = 11;
  1269. $td_nr_columns_slide = 'td-slide-on-3-columns';
  1270. $nr_title_chars = 170;
  1271. }
  1272.  
  1273. $title_slide = '';
  1274. //check for the title
  1275. if(!empty($atts['td_gallery_title_input'])) {
  1276. $title_slide = $atts['td_gallery_title_input'];
  1277.  
  1278. //check how many chars the tile have, if more then 84 then that cut it and add ... after
  1279. if(mb_strlen ($title_slide, 'UTF-8') > $nr_title_chars) {
  1280. $title_slide = mb_substr($title_slide, 0, $nr_title_chars, 'UTF-8') . '...';
  1281. }
  1282. }
  1283.  
  1284. $slide_images_thumbs_css = '';
  1285. $slide_display_html = '';
  1286. $slide_cursor_html = '';
  1287.  
  1288. $image_ids = explode(',', $atts['ids']);
  1289.  
  1290. //check to make sure we have images
  1291. if (count($image_ids) == 1 and !is_numeric($image_ids[0])) {
  1292. return;
  1293. }
  1294.  
  1295. $image_ids = array_map('trim', $image_ids);//trim elements of the $ids_gallery array
  1296.  
  1297. //generate unique gallery slider id
  1298. $gallery_slider_unique_id = td_global::td_generate_unique_id();
  1299.  
  1300. $cur_item_nr = 1;
  1301. foreach($image_ids as $image_id) {
  1302.  
  1303. //get the info about attachment
  1304. $image_attachment = td_util::attachment_get_full_info($image_id);
  1305.  
  1306. //get images url
  1307. $td_temp_image_url_80x60 = wp_get_attachment_image_src($image_id, 'td_80x60'); //for the slide - for small images slide popup
  1308. $td_temp_image_url_full = $image_attachment['src']; //default big image - for magnific popup
  1309.  
  1310. //if we are on full wight (3 columns use the default images not the resize ones)
  1311. if(td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  1312.  
  1313. $td_temp_image_url = wp_get_attachment_image_src($image_id, 'td_1021x580'); //1021x580 images - for big slide
  1314. } else {
  1315. $td_temp_image_url = wp_get_attachment_image_src($image_id, 'td_0x420'); //0x420 image sizes - for big slide
  1316. }
  1317.  
  1318.  
  1319. //check if we have all the images
  1320. if(!empty($td_temp_image_url[0]) and !empty($td_temp_image_url_80x60[0]) and !empty($td_temp_image_url_full)) {
  1321.  
  1322. //css for display the small cursor image
  1323. $slide_images_thumbs_css .= '
  1324. #' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-item' . $cur_item_nr . ' {
  1325. background: url(' . $td_temp_image_url_80x60[0] . ') 0 0 no-repeat;
  1326. }';
  1327.  
  1328. //html for display the big image
  1329. $class_post_content = '';
  1330.  
  1331. if(!empty($image_attachment['description']) or !empty($image_attachment['caption'])) {
  1332. $class_post_content = 'td-gallery-slide-content';
  1333. }
  1334.  
  1335. //if picture has caption & description
  1336. $figcaption = '';
  1337.  
  1338. if(!empty($image_attachment['caption']) or !empty($image_attachment['description'])) {
  1339. $figcaption = '<figcaption class = "td-slide-caption ' . $class_post_content . '">';
  1340.  
  1341. if(!empty($image_attachment['caption'])) {
  1342. $figcaption .= '<div class = "td-gallery-slide-copywrite">' . $image_attachment['caption'] . '</div>';
  1343. }
  1344.  
  1345. if(!empty($image_attachment['description'])) {
  1346. $figcaption .= '<span>' . $image_attachment['description'] . '</span>';
  1347. }
  1348.  
  1349. $figcaption .= '</figcaption>';
  1350. }
  1351.  
  1352. $slide_display_html .= '
  1353. <div class = "td-slide-item td-item' . $cur_item_nr . '">
  1354. <figure class="td-slide-galery-figure td-slide-popup-gallery">
  1355. <a class="slide-gallery-image-link" href="' . $td_temp_image_url_full . '" title="' . $image_attachment['title'] . '" data-caption="' . esc_attr($image_attachment['caption'], ENT_QUOTES) . '" data-description="' . htmlentities($image_attachment['description'], ENT_QUOTES) . '">
  1356. <img src="' . $td_temp_image_url[0] . '" alt="' . htmlentities($image_attachment['alt'], ENT_QUOTES) . '">
  1357. </a>
  1358. ' . $figcaption . '
  1359. </figure>
  1360. </div>';
  1361.  
  1362. //html for display the small cursor image
  1363. $slide_cursor_html .= '
  1364. <div class = "td-button td-item' . $cur_item_nr . '">
  1365. <div class = "td-border"></div>
  1366. </div>';
  1367.  
  1368. $cur_item_nr++;
  1369. }//end check for images
  1370. }//end foreach
  1371.  
  1372. //check if we have html code for the slider
  1373. if(!empty($slide_display_html) and !empty($slide_cursor_html)) {
  1374.  
  1375. //get the number of slides
  1376. $nr_of_slides = count($image_ids);
  1377. if($nr_of_slides < 0) {
  1378. $nr_of_slides = 0;
  1379. }
  1380.  
  1381. $buffy = '
  1382. <style type="text/css">
  1383. ' .
  1384. $slide_images_thumbs_css . '
  1385. </style>
  1386.  
  1387. <div id="' . $gallery_slider_unique_id . '" class="' . $td_nr_columns_slide . '">
  1388. <div class="post_td_gallery">
  1389. <div class="td-gallery-slide-top">
  1390. <div class="td-gallery-title">' . $title_slide . '</div>
  1391.  
  1392. <div class="td-gallery-controls-wrapper">
  1393. <div class="td-gallery-slide-count"><span class="td-gallery-slide-item-focus">1</span> ' . __td('of', TD_THEME_NAME) . ' ' . $nr_of_slides . '</div>
  1394. <div class="td-gallery-slide-prev-next-but">
  1395. <i class = "td-icon-left doubleSliderPrevButton"></i>
  1396. <i class = "td-icon-right doubleSliderNextButton"></i>
  1397. </div>
  1398. </div>
  1399. </div>
  1400.  
  1401. <div class = "td-doubleSlider-1 ">
  1402. <div class = "td-slider">
  1403. ' . $slide_display_html . '
  1404. </div>
  1405. </div>
  1406.  
  1407. <div class = "td-doubleSlider-2">
  1408. <div class = "td-slider">
  1409. ' . $slide_cursor_html . '
  1410. </div>
  1411. </div>
  1412.  
  1413. </div>
  1414.  
  1415. </div>
  1416. ';
  1417.  
  1418. $slide_javascript = '
  1419. //total number of slides
  1420. var ' . $gallery_slider_unique_id . '_nr_of_slides = ' . $nr_of_slides . ';
  1421.  
  1422. jQuery(document).ready(function() {
  1423. //magnific popup
  1424. jQuery("#' . $gallery_slider_unique_id . ' .td-slide-popup-gallery").magnificPopup({
  1425. delegate: "a",
  1426. type: "image",
  1427. tLoading: "Loading image #%curr%...",
  1428. mainClass: "mfp-img-mobile",
  1429. gallery: {
  1430. enabled: true,
  1431. navigateByImgClick: true,
  1432. preload: [0,1],
  1433. tCounter: \'%curr% ' . __td('of', TD_THEME_NAME) . ' %total%\'
  1434. },
  1435. image: {
  1436. tError: "<a href=\'%url%\'>The image #%curr%</a> could not be loaded.",
  1437. titleSrc: function(item) {//console.log(item.el);
  1438. //alert(jQuery(item.el).data("caption"));
  1439. return item.el.attr("data-caption") + "<div>" + item.el.attr("data-description") + "<div>";
  1440. }
  1441. },
  1442. zoom: {
  1443. enabled: true,
  1444. duration: 300,
  1445. opener: function(element) {
  1446. return element.find("img");
  1447. }
  1448. },
  1449.  
  1450. callbacks: {
  1451. change: function() {
  1452. // Will fire when popup is closed
  1453. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("goToSlide", this.currItem.index + 1 );
  1454. }
  1455. }
  1456.  
  1457. });
  1458.  
  1459. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider({
  1460. scrollbar: true,
  1461. snapToChildren: true,
  1462. desktopClickDrag: true,
  1463. infiniteSlider: true,
  1464. responsiveSlides: true,
  1465. navPrevSelector: jQuery("#' . $gallery_slider_unique_id . ' .doubleSliderPrevButton"),
  1466. navNextSelector: jQuery("#' . $gallery_slider_unique_id . ' .doubleSliderNextButton"),
  1467. scrollbarHeight: "2",
  1468. scrollbarBorderRadius: "0",
  1469. scrollbarOpacity: "0.5",
  1470. onSliderResize: td_gallery_resize_update_vars_' . $gallery_slider_unique_id . ',
  1471. onSliderLoaded: doubleSlider2Load_' . $gallery_slider_unique_id . ',
  1472. onSlideChange: doubleSlider2Load_' . $gallery_slider_unique_id . ',
  1473. keyboardControls:true
  1474. });
  1475.  
  1476. //small image slide
  1477. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button").each(function(i) {
  1478. jQuery(this).bind("click", function() {
  1479. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("goToSlide", i+1);
  1480. });
  1481. });
  1482.  
  1483. //check the number of slides
  1484. if(' . $gallery_slider_unique_id . '_nr_of_slides > ' . $td_double_slider2_no_js_limit . ') {
  1485. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").iosSlider({
  1486. desktopClickDrag: true,
  1487. snapToChildren: true,
  1488. snapSlideCenter: true,
  1489. infiniteSlider: true
  1490. });
  1491. } else {
  1492. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").addClass("td_center_slide2");
  1493. }
  1494.  
  1495. function doubleSlider2Load_' . $gallery_slider_unique_id . '(args) {
  1496. //var currentSlide = args.currentSlideNumber;
  1497. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2").iosSlider("goToSlide", args.currentSlideNumber);
  1498.  
  1499.  
  1500. //put a transparent border around all small sliders
  1501. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button .td-border").css("border", "3px solid #ffffff").css("opacity", "0.5");
  1502. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button").css("border", "0");
  1503.  
  1504. //put a white border around the focused small slide
  1505. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button:eq(" + (args.currentSlideNumber-1) + ") .td-border").css("border", "3px solid #ffffff").css("opacity", "1");
  1506. //jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-2 .td-button:eq(" + (args.currentSlideNumber-1) + ")").css("border", "3px solid #ffffff");
  1507.  
  1508. //write the current slide number
  1509. td_gallery_write_current_slide_' . $gallery_slider_unique_id . '(args.currentSlideNumber);
  1510. }
  1511.  
  1512. //writes the current slider beside to prev and next buttons
  1513. function td_gallery_write_current_slide_' . $gallery_slider_unique_id . '(slide_nr) {
  1514. jQuery("#' . $gallery_slider_unique_id . ' .td-gallery-slide-item-focus").html(slide_nr);
  1515. }
  1516.  
  1517.  
  1518. /*
  1519. * Resize the iosSlider when the page is resided (fixes bug on Android devices)
  1520. */
  1521. function td_gallery_resize_update_vars_' . $gallery_slider_unique_id . '(args) {
  1522. if(td_detect.is_android) {
  1523. setTimeout(function(){
  1524. jQuery("#' . $gallery_slider_unique_id . ' .td-doubleSlider-1").iosSlider("update");
  1525. }, 1500);
  1526. }
  1527. }
  1528. });';
  1529.  
  1530. td_js_buffer::add_to_footer($slide_javascript);
  1531. }//end check if we have html code for the slider
  1532. }//end if slide
  1533.  
  1534. //!!!!!! WARNING
  1535. //$return has to be != empty to overwride the default output
  1536. return $buffy;
  1537. }
  1538.  
  1539.  
  1540.  
  1541.  
  1542. /* ----------------------------------------------------------------------------
  1543. * filter the gallery shortcode
  1544. */
  1545. add_filter('shortcode_atts_gallery', 'my_gallery_atts_modifier', 1); //run with 1 priority, allow anyone to overwrite our hook.
  1546. /**
  1547. * @todo trebuie fixuite toate tipurile de imagini din gallerie in functie de setarile template-ului
  1548. */
  1549. function my_gallery_atts_modifier($out) {
  1550.  
  1551. // td_global::$cur_single_template_sidebar_pos; //is set in single.php @todo set it also on the page template
  1552. // link to files instead of no link or attachement. The file is used by magnific pupup
  1553. $out['link'] = 'file';
  1554.  
  1555. if (!isset($out['columns'])) {
  1556. $out['columns'] = '';
  1557. }
  1558.  
  1559. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  1560. if ($out['columns'] == 1) {
  1561. $out['size'] = 'td_1021x580';
  1562. }
  1563. } else {
  1564. if ($out['columns'] == 1) {
  1565. $out['size'] = 'td_640x350';
  1566. }
  1567. }
  1568. return $out;
  1569. }
  1570.  
  1571.  
  1572.  
  1573.  
  1574. /* ----------------------------------------------------------------------------
  1575. * add custom classes to the single templates, also mix fixes for white menu and white grid
  1576. */
  1577. add_filter('body_class', 'td_add_single_template_class');
  1578. function td_add_single_template_class($classes) {
  1579.  
  1580. if (is_single()) {
  1581. global $post;
  1582.  
  1583. $active_single_template = '';
  1584. $td_post_theme_settings = get_post_meta($post->ID, 'td_post_theme_settings', true);
  1585.  
  1586. if (!empty($td_post_theme_settings['td_post_template'])) {
  1587. // we have a post template set in the post
  1588. $active_single_template = $td_post_theme_settings['td_post_template'];
  1589. } else {
  1590. // we may have a global post template form td panel
  1591. $td_default_site_post_template = td_util::get_option('td_default_site_post_template');
  1592. if(!empty($td_default_site_post_template)) {
  1593. $active_single_template = $td_default_site_post_template;
  1594. }
  1595. }
  1596.  
  1597.  
  1598. // add the class if we have a post template
  1599. if (!empty($active_single_template)) {
  1600. td_global::$cur_single_template = $active_single_template;
  1601. $classes []= sanitize_html_class($active_single_template);
  1602. }
  1603.  
  1604. }
  1605.  
  1606. // if main menu background color is white to fix the menu appearance on all headers
  1607. if (td_util::get_option('tds_menu_color') == '#ffffff' or td_util::get_option('tds_menu_color') == 'ffffff') {
  1608. $classes[] = 'white-menu';
  1609. }
  1610.  
  1611. // if grid color is white to fix the menu appearance on all headers
  1612. if (td_util::get_option('tds_grid_line_color') == '#ffffff' or td_util::get_option('tds_grid_line_color') == 'ffffff') {
  1613. $classes[] = 'white-grid';
  1614. }
  1615. return $classes;
  1616. }
  1617.  
  1618.  
  1619.  
  1620.  
  1621. /* ----------------------------------------------------------------------------
  1622. * add custom classes to the single templates, also mix fixes for white menu and white grid
  1623. */
  1624. add_filter('body_class', 'td_add_category_template_class');
  1625. function td_add_category_template_class($classes) {
  1626. if(!is_admin() and is_category()) {
  1627. $classes [] = sanitize_html_class(td_api_category_template::_helper_get_active_id());
  1628. $classes [] = sanitize_html_class(td_api_category_top_posts_style::_helper_get_active_id());
  1629. }
  1630. return $classes;
  1631. }
  1632.  
  1633.  
  1634.  
  1635.  
  1636. /* ----------------------------------------------------------------------------
  1637. * add `filter_by` URL variable so I can retrieve it with `get_query_var` function
  1638. */
  1639. add_filter('query_vars', 'td_category_big_grid_add_query_vars_filter');
  1640. function td_category_big_grid_add_query_vars_filter($vars) {
  1641. $vars[] = "filter_by";
  1642. return $vars;
  1643. }
  1644.  
  1645.  
  1646.  
  1647.  
  1648. /* ----------------------------------------------------------------------------
  1649. * modify the main query for category pages
  1650. */
  1651. add_action('pre_get_posts', 'td_modify_main_query_for_category_page');
  1652. function td_modify_main_query_for_category_page2($query) {
  1653.  
  1654.  
  1655. //checking for category page and main query
  1656. if(!is_admin() and is_category() and $query->is_main_query()and (is_front_page() and is_home())) {
  1657.  
  1658. // get the category object - with or without permalinks
  1659. if (empty($query->query_vars['cat'])) {
  1660. td_global::$current_category_obj = get_category_by_path(get_query_var('category_name'), false); // when we have permalinks, we have to get the category object like this.
  1661. } else {
  1662. td_global::$current_category_obj = get_category($query->query_vars['cat']);
  1663. }
  1664.  
  1665.  
  1666. // we are on a category page with an ID that doesn't exists - wp will show a 404 and we do nothing
  1667. if (is_null(td_global::$current_category_obj)) {
  1668. return;
  1669. }
  1670.  
  1671.  
  1672. //get the number of page where on
  1673. $paged = get_query_var('paged');
  1674.  
  1675. //get the `filter_by` URL($_GET) variable
  1676. $filter_by = get_query_var('filter_by');
  1677.  
  1678. //get the limit of posts on the category page
  1679. $limit = get_option('posts_per_page');
  1680.  
  1681.  
  1682. //echo $filter_by;
  1683. switch ($filter_by) {
  1684. case 'featured':
  1685. //get the category object
  1686. $query->set('category_name', td_global::$current_category_obj->slug);
  1687. $query->set('cat', get_cat_ID(TD_FEATURED_CAT)); //add the fetured cat
  1688. break;
  1689.  
  1690. case 'popular':
  1691. $query->set('meta_key', td_page_views::$post_view_counter_key);
  1692. $query->set('orderby', 'meta_value_num');
  1693. $query->set('order', 'DESC');
  1694. break;
  1695.  
  1696. case 'popular7':
  1697. $query->set('meta_key', td_page_views::$post_view_counter_7_day_total);
  1698. $query->set('orderby', 'meta_value_num');
  1699. $query->set('order', 'DESC');
  1700. break;
  1701.  
  1702. case 'review_high':
  1703. $query->set('meta_key', td_review::$td_review_key);
  1704. $query->set('orderby', 'meta_value_num');
  1705. $query->set('order', 'DESC');
  1706. break;
  1707.  
  1708. case 'random_posts':
  1709. $query->set('orderby', 'rand');
  1710. break;
  1711. }//end switch
  1712.  
  1713.  
  1714. // how many posts are we showing in the big grid for this category
  1715. $offset = 5;
  1716.  
  1717.  
  1718. // offset + custom pagination - if we have offset, WordPress overwrites the pagination and works with offset + limit
  1719. if(empty($query->is_feed)) {
  1720. if ( ! empty( $offset ) and $paged > 1 ) {
  1721. $query->set( 'offset', $offset + ( ( $paged - 1 ) * $limit ) );
  1722. } else {
  1723. $query->set( 'offset', $offset );
  1724. }
  1725. }
  1726. //print_r($query);
  1727. }//end if main query
  1728. }
  1729.  
  1730.  
  1731.  
  1732.  
  1733. /** ----------------------------------------------------------------------------
  1734. * update category shared terms
  1735. * @since WordPress 4.2
  1736. * @link https://make.wordpress.org/core/2015/02/16/taxonomy-term-splitting-in-4-2-a-developer-guide/
  1737. */
  1738. add_action('split_shared_term', 'td_category_split_shared_term', 10, 4);
  1739. function td_category_split_shared_term($term_id, $new_term_id, $term_taxonomy_id, $taxonomy) {
  1740. if (($taxonomy === 'category') and (isset(td_global::$td_options['category_options'][$term_id]))) {
  1741.  
  1742. $current_settings = td_global::$td_options['category_options'][$term_id];
  1743. td_global::$td_options['category_options'][$new_term_id] = $current_settings;
  1744. unset(td_global::$td_options['category_options'][$term_id]);
  1745.  
  1746. update_option(TD_THEME_OPTIONS_NAME, td_global::$td_options);
  1747. }
  1748. }
  1749.  
  1750.  
  1751.  
  1752.  
  1753. /* ----------------------------------------------------------------------------
  1754. * TagDiv WordPress booster init
  1755. */
  1756.  
  1757. td_init_booster();
  1758. function td_init_booster() {
  1759.  
  1760. global $content_width;
  1761.  
  1762. // content width - this is overwritten in post
  1763. if (!isset($content_width)) {
  1764. $content_width = 640;
  1765. }
  1766.  
  1767. /* ----------------------------------------------------------------------------
  1768. * add_image_size for WordPress - register all the thumbs from the thumblist
  1769. */
  1770. foreach (td_api_thumb::get_all() as $thumb_array) {
  1771. if (td_util::get_option('tds_thumb_' . $thumb_array['name']) != '') {
  1772. add_image_size($thumb_array['name'], $thumb_array['width'], $thumb_array['height'], $thumb_array['crop']);
  1773. }
  1774. }
  1775.  
  1776.  
  1777. /* ----------------------------------------------------------------------------
  1778. * Add lazy shortcodes of the registered blocks
  1779. */
  1780. foreach (td_api_block::get_all() as $block_settings_key => $block_settings_value) {
  1781. td_global_blocks::add_lazy_shortcode($block_settings_key);
  1782. }
  1783.  
  1784.  
  1785. /* ----------------------------------------------------------------------------
  1786. * register the default sidebars + dynamic ones
  1787. */
  1788. register_sidebar(array(
  1789. 'name'=> TD_THEME_NAME . ' default',
  1790. 'id' => 'td-default', //the id is used by the importer
  1791. 'before_widget' => '<aside class="widget %2$s">',
  1792. 'after_widget' => '</aside>',
  1793. 'before_title' => '<div class="block-title"><span>',
  1794. 'after_title' => '</span></div>'
  1795. ));
  1796.  
  1797. register_sidebar(array(
  1798. 'name'=>'Footer 1',
  1799. 'id' => 'td-footer-1',
  1800. 'before_widget' => '<aside class="widget %2$s">',
  1801. 'after_widget' => '</aside>',
  1802. 'before_title' => '<div class="block-title"><span>',
  1803. 'after_title' => '</span></div>'
  1804. ));
  1805.  
  1806. register_sidebar(array(
  1807. 'name'=>'Footer 2',
  1808. 'id' => 'td-footer-2',
  1809. 'before_widget' => '<aside class="widget %2$s">',
  1810. 'after_widget' => '</aside>',
  1811. 'before_title' => '<div class="block-title"><span>',
  1812. 'after_title' => '</span></div>'
  1813. ));
  1814.  
  1815. register_sidebar(array(
  1816. 'name'=>'Footer 3',
  1817. 'id' => 'td-footer-3',
  1818. 'before_widget' => '<aside class="widget %2$s">',
  1819. 'after_widget' => '</aside>',
  1820. 'before_title' => '<div class="block-title"><span>',
  1821. 'after_title' => '</span></div>'
  1822. ));
  1823.  
  1824. //get our custom dynamic sidebars
  1825. $currentSidebars = td_util::get_option('sidebars');
  1826.  
  1827. //if we have user made sidebars, register them in wp
  1828. if (!empty($currentSidebars)) {
  1829. foreach ($currentSidebars as $sidebar) {
  1830. register_sidebar(array(
  1831. 'name' => $sidebar,
  1832. 'id' => 'td-' . td_util::sidebar_name_to_id($sidebar),
  1833. 'before_widget' => '<aside class="widget %2$s">',
  1834. 'after_widget' => '</aside>',
  1835. 'before_title' => '<div class="block-title"><span>',
  1836. 'after_title' => '</span></div>',
  1837. ));
  1838. } //end foreach
  1839. }
  1840.  
  1841. $smooth_scroll = td_util::get_option('tds_smooth_scroll');
  1842.  
  1843. if (!empty($smooth_scroll)) {
  1844. td_js_buffer::add_variable('tds_smooth_scroll', true);
  1845. }
  1846. }
  1847.  
  1848.  
  1849.  
  1850.  
  1851. /* ----------------------------------------------------------------------------
  1852. check to see if we are on the backend
  1853. */
  1854. if (is_admin()) {
  1855.  
  1856.  
  1857. // demo inmporter
  1858. require_once('wp-admin/panel/td_demo_installer.php');
  1859. require_once('wp-admin/panel/td_demo_util.php');
  1860.  
  1861.  
  1862.  
  1863. /* ----------------------------------------------------------------------------
  1864. The theme panel + plugins panels
  1865. */
  1866. require_once('wp-admin/panel/panel_core/td_panel_core.php');
  1867. require_once('wp-admin/panel/panel_core/td_panel_generator.php');
  1868. require_once('wp-admin/panel/panel_core/td_panel_data_source.php');
  1869.  
  1870. if (current_user_can('switch_themes')) {
  1871. // add the theme panel only if we have permissions
  1872. require_once('wp-admin/panel/td_panel.php');
  1873. require_once('wp-admin/panel/td_panel_woo.php'); //add the woocommerce panel
  1874. }
  1875.  
  1876.  
  1877.  
  1878.  
  1879.  
  1880.  
  1881. /**
  1882. * the wp-admin TinyMCE editor buttons
  1883. */
  1884. require_once('wp-admin/tinymce/tinymce.php');
  1885.  
  1886. /**
  1887. * get tinymce formats
  1888. */
  1889. td_api_tinymce_formats::_helper_get_tinymce_format();
  1890.  
  1891. /**
  1892. * Custom content metaboxes (the select sidebar dropdown/post etc)
  1893. */
  1894. require_once('td_metabox_generator.php');
  1895. require_once('wp-admin/content-metaboxes/td_templates_settings.php');
  1896.  
  1897. /**
  1898. * Helper pointers
  1899. */
  1900. require_once('td_help_pointers.php');
  1901.  
  1902. add_action('admin_enqueue_scripts', 'td_help_pointers');
  1903. function td_help_pointers()
  1904. {
  1905. //First we define our pointers
  1906. $pointers = array(
  1907. array(
  1908. 'id' => 'vc_columns_pointer', // unique id for this pointer
  1909. 'screen' => 'page', // this is the page hook we want our pointer to show on
  1910. 'target' => '.composer-switch', // the css selector for the pointer to be tied to, best to use ID's
  1911. 'title' => TD_THEME_NAME . ' (tagDiv) tip',
  1912. 'content' => '<img class="td-tip-vc-columns" style="max-width:100%" src="' . td_global::$get_template_directory_uri . '/includes/wp_booster/wp-admin/images/td_helper_pointers/vc-columns.png' . '">',
  1913. 'position' => array(
  1914. 'edge' => 'top', //top, bottom, left, right
  1915. 'align' => 'left' //top, bottom, left, right, middle
  1916. )
  1917. )
  1918. // more as needed
  1919. );
  1920. //Now we instantiate the class and pass our pointer array to the constructor
  1921. $myPointers = new td_help_pointers($pointers);
  1922. }
  1923.  
  1924. /* -----------------------------------------------------------------------------
  1925. TGM_Plugin_Activation
  1926. */
  1927. require_once 'external/class-tgm-plugin-activation.php';
  1928.  
  1929.  
  1930.  
  1931.  
  1932. add_action('tgmpa_register', 'td_required_plugins');
  1933. function td_required_plugins() {
  1934. $config = array(
  1935. 'domain' => TD_THEME_NAME, // Text domain - likely want to be the same as your theme.
  1936. 'default_path' => '', // Default absolute path to pre-packaged plugins
  1937. 'parent_menu_slug' => 'themes.php', // Default parent menu slug
  1938. 'parent_url_slug' => 'themes.php', // Default parent URL slug
  1939. 'menu' => 'td_plugins', // Menu slug
  1940. 'has_notices' => false, // Show admin notices or not
  1941. 'is_automatic' => true, // Automatically activate plugins after installation or not
  1942. 'message' => '', // Message to output right before the plugins table
  1943. 'strings' => array(
  1944. 'page_title' => __('Install Required Plugins', TD_THEME_NAME),
  1945. 'menu_title' => __('Install Plugins', TD_THEME_NAME),
  1946. 'installing' => __('Installing Plugin: %s', TD_THEME_NAME), // %1$s = plugin name
  1947. 'oops' => __('Something went wrong with the plugin API.', TD_THEME_NAME),
  1948. 'notice_can_install_required' => _n_noop('<span class="td-tgma-tip">' . TD_THEME_NAME . ' theme:</span> Hi, sorry to bother you but please install %1$s plugin. It\'s included with the theme and no aditional purchase is requiered!', 'This theme requires the following plugins: %1$s.'), // %1$s = plugin name(s)
  1949. 'notice_can_install_recommended' => _n_noop('If you need social icons, you can install %1$s.', 'This theme recommends the following plugins: %1$s.'), // %1$s = plugin name(s)
  1950. '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.'), // %1$s = plugin name(s)
  1951. 'notice_can_activate_required' => _n_noop('<span class="td-tgma-tip">' . TD_THEME_NAME . ' theme:</span> Hi, please activate %1$s. Our theme works best with it.', 'The following required plugins are currently inactive: %1$s.'), // %1$s = plugin name(s)
  1952. 'notice_can_activate_recommended' => _n_noop('<span class="td-tgma-tip">' . TD_THEME_NAME . ' theme:</span> The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.'), // %1$s = plugin name(s)
  1953. '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.'), // %1$s = plugin name(s)
  1954. '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.'), // %1$s = plugin name(s)
  1955. '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.'), // %1$s = plugin name(s)
  1956. 'install_link' => _n_noop('Go to plugin instalation', ' Begin installing plugins'),
  1957. 'activate_link' => _n_noop('Go to activation panel', 'Activate installed plugins'),
  1958. 'return' => __('Return to tagDiv plugins panel', TD_THEME_NAME),
  1959. 'plugin_activated' => __('Plugin activated successfully.', TD_THEME_NAME),
  1960. 'complete' => __('All plugins installed and activated successfully. %s', TD_THEME_NAME), // %1$s = dashboard link
  1961. 'nag_type' => 'updated' // Determines admin notice type - can only be 'updated' or 'error'
  1962. )
  1963. );
  1964. tgmpa(td_global::$theme_plugins_list, $config);
  1965.  
  1966.  
  1967. }
  1968. }
  1969.  
  1970.  
  1971. /**
  1972. * - wordpress filter hook used to switch single theme post types and custom post types, and also woocommerce single products
  1973. * - we need to use 'template_include' and not 'single_template' (which runs just for single and before 'template_include'),
  1974. * because of not using more than one hook for this split operation and because the $template_path is the path already
  1975. * established by wordpress and woocommerce plugin
  1976. */
  1977. add_filter( 'template_include', 'td_template_include_filter');
  1978. function td_template_include_filter( $wordpress_template_path ) {
  1979.  
  1980. // intercept the WordPress requested template, and if it's single we put our own.
  1981. if (is_single() and
  1982. (($wordpress_template_path == TEMPLATEPATH . '/single.php') or ($wordpress_template_path == STYLESHEETPATH . '/single.php'))) {
  1983.  
  1984. global $post;
  1985.  
  1986. // if we are on a custom post type, leave the defaul loaded wordpress template
  1987. if ($post->post_type != 'post') {
  1988. return $wordpress_template_path;
  1989. }
  1990.  
  1991. // read the global setting
  1992. $single_template_id = td_util::get_option('td_default_site_post_template');
  1993.  
  1994. // check if we have a specific template
  1995. $td_post_theme_settings = get_post_meta($post->ID, 'td_post_theme_settings', true);
  1996. if (!empty($td_post_theme_settings['td_post_template'])) {
  1997. $single_template_id = $td_post_theme_settings['td_post_template'];
  1998. }
  1999.  
  2000. if (!empty($single_template_id)) {
  2001. // try to find the template in the API
  2002. $single_template_path = '';
  2003. try {
  2004. $single_template_path = td_api_single_template::get_key($single_template_id, 'file');
  2005. } catch (ErrorException $ex) {
  2006. td_util::error(__FILE__, "The template $single_template_id isn't set. Did you disable a tagDiv plugin?"); // this does not stop execution
  2007. }
  2008.  
  2009. // we have the file in the API, now we make sure that the file exists on disk
  2010. if (!empty($single_template_path) and file_exists($single_template_path)) {
  2011. $wordpress_template_path = $single_template_path;
  2012. } else {
  2013. td_util::error(__FILE__, "The path $single_template_path of the $single_template_id template not found. Did you disable a tagDiv plugin?"); // this does not stop execution
  2014. }
  2015. }
  2016.  
  2017. } else if (td_global::$is_woocommerce_installed
  2018. and is_single()
  2019. and (($wordpress_template_path == TEMPLATEPATH . '/woocommerce/single-product.php')
  2020. or ($wordpress_template_path == STYLESHEETPATH . '/woocommerce/single-product.php'))) {
  2021.  
  2022.  
  2023. //echo 'SINGLE PRODUCT detected<br>';
  2024. }
  2025.  
  2026. return $wordpress_template_path;
  2027. }
Advertisement
Add Comment
Please, Sign In to add comment