Guest User

Untitled

a guest
Jan 14th, 2013
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 55.60 KB | None | 0 0
  1. <?php
  2. /* ----------------------------------------------------------------------------------- */
  3. // All functions and configuration of the theme
  4. /* ----------------------------------------------------------------------------------- */
  5.  
  6. define('TT_SHORTNAME', 'mysite');
  7. define('TT_THEMENAME', 'mysite');
  8. define('THEMENAME', 'mysite');
  9.  
  10. define('FRAMEWORKPATH', TEMPLATEPATH . '/framework');
  11. define('FRAMEWORKURL', get_template_directory_uri() . '/framework');
  12.  
  13. /* ------------------------------------------ */
  14. /* Options Framework
  15.   /*------------------------------------------ */
  16.  
  17. require_once (TEMPLATEPATH . '/admin/index.php');
  18.  
  19.  
  20. $s_layout = Array(
  21.     array('title' => 'Full', 'value' => '0-1-1', 'image' => FRAMEWORKURL . '/images/layouts/s0.png'),
  22.     array('title' => 'Right sidebar', 'value' => '1-1-1', 'image' => FRAMEWORKURL . '/images/layouts/s12.png'),
  23. );
  24. $social_url = get_template_directory_uri() . '/framework/images/social-option/';
  25. $social_position = Array(
  26.     $social_url . '01.png' => 'bottom',
  27.     $social_url . '02.png' => 'top',
  28.     $social_url . '03.png' => 'left',
  29.     $social_url . '04.png' => 'right',
  30. );
  31. $images_url = get_template_directory_uri() . '/images/skin/';
  32. $post_style = Array(
  33.     $images_url . '01.png' => 'post-default',
  34.     $images_url . '02.png' => 'post-minimal',
  35.     $images_url . '03.png' => 'post-classic-light',
  36.     $images_url . '04.png' => 'post-classic-dark',
  37. );
  38. $size_url = get_template_directory_uri() . '/framework/images/post-size/';
  39. $item_size = Array(
  40.     $size_url . '01.png' => 'small',
  41.     $size_url . '02.png' => 'medium',
  42.     $size_url . '03.png' => 'large',
  43.     $size_url . '04.png' => 'x-large',
  44. );
  45. $footerGrid = Array(
  46.     '1' => '12',
  47.     '2' => '6-6',
  48.     '7' => '6-3-3',
  49.     '70' => '3-3-6',
  50.     '4' => '3-3-3-3'
  51. );
  52.  
  53. global $data;
  54. $sides = isset($data['custom_sidebar']) ? $data['custom_sidebar'] : ""; //get the slides array
  55. $sidebar = array('Default sidebar');
  56. if ($sides) {
  57.     foreach ($sides as $side) {
  58.         if ($side['title'] != "") {
  59.             $sidebar = array_merge($sidebar, (array) $side['title']);
  60.         }
  61.     }
  62. }
  63.  
  64. require_once FRAMEWORKPATH . '/framework.php';
  65. require_once FRAMEWORKPATH . '/' . TT_SHORTNAME . '.php';
  66. require_once TEMPLATEPATH . '/social-connect/social-connect.php';
  67. require_once( ADMIN_PATH . 'functions/seo.php' );
  68. require_once ( ADMIN_PATH  . '/composer/js_composer.php');
  69.  
  70.  
  71. if (!function_exists('get_post_image')) :
  72.  
  73.     function get_post_image() {
  74.         global $post;
  75.         $first_img = '';
  76.         if (has_post_thumbnail($post->ID)) {
  77.             $post_image_tumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');
  78.             return $post_image_tumb[0];
  79.         }
  80.         return $first_img;
  81.     }
  82.  
  83. endif;
  84.  
  85. if (!function_exists('get_post_image_for_nextprev')) :
  86.  
  87.     function get_post_image_for_nextprev() {
  88.         global $post;
  89.         $first_img = '';
  90.         if (has_post_thumbnail($post->ID)) {
  91.             $post_image_tumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail');
  92.             return $post_image_tumb[0];
  93.         }
  94.         return $first_img;
  95.     }
  96.  
  97. endif;
  98.  
  99. if (!function_exists('get_post_first_image')) :
  100.  
  101.     function get_post_first_image() {
  102.         global $post;
  103.         $first_img = '';
  104.         if ($post->post_content) {
  105.             $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  106.             $first_img = isset($matches[1][0]) ? $matches[1][0] : '';
  107.         }
  108.         return $first_img;
  109.     }
  110.  
  111. endif;
  112.  
  113. if (!function_exists('get_post_content_image')) :
  114.  
  115.     function get_post_content_image() {
  116.         global $post;
  117.         $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  118.         $first_img = isset($matches[1][0]) ? $matches[1][0] : '';
  119.         return $first_img;
  120.     }
  121.  
  122. endif;
  123.  
  124. register_nav_menus(array(
  125.     'primary-menu' => __('Primary Navigation', 'mysite'),
  126.     'footer-menu' => __('Footer Navigation', 'mysite')
  127. ));
  128. add_action('widgets_init', 'widgets_init');
  129. add_theme_support('post-thumbnails');
  130. add_theme_support('post-formats', array('video', 'audio', 'quote', 'status', 'link'));
  131. add_image_size('theme-thumb', 520, 497, true);
  132. add_filter('widget_text', 'do_shortcode');
  133. add_filter('wp_get_attachment_link', 'gallery_prettyPhoto');
  134.  
  135. if (!function_exists('gallery_prettyPhoto')) :
  136.  
  137.     function gallery_prettyPhoto($content) {
  138.         // add checks if you want to add prettyPhoto on certain places (archives etc).
  139.         return str_replace("<a", "<a title='' alt='' rel='prettyPhoto[x]'", $content);
  140.     }
  141.  
  142. endif;
  143.  
  144. add_action('after_setup_theme', 'mysite_setup');
  145. if (!function_exists('mysite_setup')) {
  146.  
  147.     function mysite_setup() {
  148.         add_editor_style();
  149.         add_theme_support('post-thumbnails');
  150.         add_theme_support('automatic-feed-links');
  151.         load_theme_textdomain('mysite', get_template_directory() . '/languages');
  152.     }
  153.  
  154. }
  155. /*
  156.   if (!isset($content_width))
  157.   $content_width = 900;
  158.  */
  159. if (!function_exists('widgets_init')) :
  160.  
  161.     function widgets_init() {
  162.         global $footerGrid, $data;
  163.         // Default sidebar.
  164.         register_sidebar(array(
  165.             'name' => __('Default sidebar', 'mysite'),
  166.             'id' => 'default-sidebar',
  167.             'description' => __('The default sidebar widget area', 'mysite'),
  168.             'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  169.             'after_widget' => '</aside>',
  170.             'before_title' => '<h3 class="widget-title">',
  171.             'after_title' => '</h3>',
  172.         ));
  173.  
  174.         // Header sidebar.
  175.         register_sidebar(array(
  176.             'name' => __('Header sidebar', 'mysite'),
  177.             'id' => 'header-sidebar',
  178.             'description' => __('The header sidebar widget area', 'mysite'),
  179.             'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  180.             'after_widget' => '</aside>',
  181.             'before_title' => '<h3 class="widget-title">',
  182.             'after_title' => '</h3>',
  183.         ));
  184.  
  185.  
  186.         // Footer sidebar
  187.         if (isset($data['show_footer']) && $data['show_footer']) {
  188.             $grid = (isset($data['footer_layout']) && $data['footer_layout'] != '') ? $data['footer_layout'] : '4';
  189.             $grid = $footerGrid[$grid];
  190.             $bagana = count(split('-', $grid)) - 1;
  191.             $x = (940 - (30 * $bagana)) / 24;
  192.             $i = 1;
  193.  
  194.             foreach (split('-', $grid) as $g) {
  195.  
  196.                 $last = $i == ($bagana + 1) ? ' margin-right: 0px;' : ' margin-right: 30px;';
  197.                 register_sidebar(array(
  198.                     'name' => __("Footer sidebar $i", "mysite"),
  199.                     'id' => "footer-sidebar-$i",
  200.                     'description' => __('The footer sidebar widget area', 'mysite'),
  201.                     'before_widget' => '<div id="%1$s"  class="widget %2$s">',
  202.                     'after_widget' => '</div>',
  203.                     'before_title' => '<h3 class="widget-title">',
  204.                     'after_title' => '</h3>',
  205.                 ));
  206.  
  207.                 $i++;
  208.             }
  209.         }
  210.         // Custom Sidebar
  211.         $name = 'custom_sidebar';
  212.         if (!empty($data[$name])) {
  213.             foreach ($data[$name] as $row) {
  214.                 if ($row != "" && $row['title'] != "") {
  215.                     register_sidebar(array(
  216.                         'name' => $row['title'],
  217.                         'id' => $row['title'],
  218.                         'description' => __('The page widget area', 'energy'),
  219.                         'before_widget' => '<aside id="%1$s" class="dynamic_sidebar widget %2$s">',
  220.                         'after_widget' => '</aside>',
  221.                         'before_title' => '<h3 class="widget-title">',
  222.                         'after_title' => '</h3><div class="widget-content">',
  223.                     ));
  224.                 }
  225.             }
  226.         }
  227.     }
  228.  
  229. endif;
  230.  
  231. if (!function_exists('mytheme_comment')) :
  232.  
  233.     function mytheme_comment($comment, $args, $depth) {
  234.         $GLOBALS['comment'] = $comment;
  235.         print '<div class="comment-block">';
  236.         ?> 
  237.         <div class="comment">
  238.             <div class="comment-author">
  239.                 <?php tt_get_user_avatar(get_userdata($comment->user_id),'28'); ?>
  240.                 <span class="comment-author-link"><span class="author-link-span">
  241.                     <?php print get_comment_author_link(); ?></span>
  242.                 </span>
  243.                 <div class="comment-meta">
  244.                     <span class="comment-date"><?php printf(__('%1$s', 'mysite'), get_comment_date()) ?></span>
  245.                     <span class="comment-replay-link"><?php comment_reply_link(array_merge($args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?></span>
  246.                 </div>
  247.                 <div class="clearfix"></div>
  248.             </div>
  249.             <div class="comment-body">
  250.                 <?php comment_text() ?>
  251.             </div>
  252.         </div><?php
  253.     }
  254.  
  255. endif;
  256.  
  257. if (!function_exists('get_sticky_posts_count')) :
  258.  
  259.     function get_sticky_posts_count() {
  260.         global $wpdb;
  261.         $sticky_posts = array_map('absint', (array) get_option('sticky_posts'));
  262.         return count($sticky_posts) > 0 ? $wpdb->get_var($wpdb->prepare("SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (" . implode(',', $sticky_posts) . ")")) : 0;
  263.     }
  264.  
  265. endif;
  266.  
  267. if (function_exists('add_theme_support')) {
  268.     add_theme_support('post-thumbnails');
  269.     set_post_thumbnail_size(150, 250); // default Post Thumbnail dimensions
  270. }
  271.  
  272. if (function_exists('add_image_size')) {
  273.     add_image_size('post-thumb', 310, 9999); //300 pixels wide (and unlimited height)
  274.     add_image_size('widget-thumb', 220, 180, true); //(cropped)
  275. }
  276.  
  277. if (!function_exists('give_linked_images_class')) :
  278.  
  279.     /**     * Attach a class to linked images' parent anchors * e.g. a img => a.img img */
  280.     function give_linked_images_class($html, $id, $caption, $title, $align, $url, $size, $alt = '') {
  281.         $classes = 'preload'; // separated by spaces, e.g. 'img image-link'
  282.         //// check if there are already classes assigned to the anchor
  283.         if (preg_match('/<a.*? class=".*?">/', $html)) {
  284.             $html = preg_replace('/(<a.*? class=".*?)(".*?>)/', 'rel="prettyphoto" title="" $1 ' . $classes . '$2', $html);
  285.         } else {
  286.             $html = preg_replace('/(<a.*?)>/', '$1 class="preload" rel="prettyphoto" title="" >', $html);
  287.         }
  288.         return $html;
  289.     }
  290.  
  291.     add_filter('image_send_to_editor', 'give_linked_images_class', 10, 8);
  292. endif;
  293.  
  294. /*
  295.  *  -------------- Added oembed instagram status ------------------------------------- */
  296. if (!function_exists('wp_oembed_instagram')) :
  297.  
  298.     function wp_oembed_instagram($matches, $attr, $url, $rawattr) {
  299.         global $post;
  300.         $img_before = $img_after = "";
  301.         if (is_single())
  302.             $size = ( isset($attr['size']) ) ? $attr['size'] : 'l';
  303.         else
  304.             $size = ( isset($attr['size']) ) ? $attr['size'] : 'm';
  305.         if (!is_single() && !is_page()) {
  306.             $img_before = '<a title="' . get_the_title() . '" href="' . get_permalink() . '" class="preload iconInstagram item-preview item-click-modal">';
  307.             $img_after = '</a>';
  308.         }
  309.         return apply_filters('embed_instagram', '<div class="instagram-photo clearfix"><div class="hover-content">' . $img_before . '<img src="http://instagr.am/p/' . $matches[2] . '/media?size=' . $size . '" alt="Instagram" id="instagram-' . $matches[2] . '" class="instagram-size-' . $size . '">' . $img_after . '<a class="instagram-link" href="' . $url . '"><img alt="Instagram" src="' . get_template_directory_uri() . '/images/instagram-icon.png"></a></div></div>', $matches, $attr, $url, $rawattr);
  310.     }
  311.  
  312.     wp_embed_register_handler('instagram', '#http://(instagr\.am|instagram.com)/p/(.*)/#i', 'wp_oembed_instagram');
  313. endif;
  314.  
  315. if (!function_exists('import_scripts')) :
  316.  
  317.     function import_scripts() {
  318.         global $data;
  319.         wp_register_script('bootstrap', get_template_directory_uri() . '/js/bootstrap.min.js');
  320.         wp_register_script('easing', get_template_directory_uri() . '/js/jquery.easing.1.3.js');
  321.         wp_register_script('validate', get_template_directory_uri() . '/js/jquery.validate.min.js');
  322.         wp_register_script('jplayer', get_template_directory_uri() . '/js/jquery.jplayer.min.js');
  323.         wp_register_script('preloader', get_template_directory_uri() . '/js/jquery.preloader.js');
  324.         wp_register_script('nicescroll', get_template_directory_uri() . '/js/jquery.nicescroll.min.js');
  325.         wp_register_script('flexslider', get_template_directory_uri() . '/js/jquery.flexslider-min.js');
  326.         wp_register_script('plusIsotope', get_template_directory_uri() . '/js/jquery.isotope.min.js');
  327.         wp_register_script('fbc', 'http://connect.facebook.net/en_US/all.js#xfbml=1&appId=' . (isset($data['facebook_app_id']) ? $data['facebook_app_id'] : ""));
  328.         wp_register_script('infinitescroll', get_template_directory_uri() . '/js/jquery.infinitescroll.min.js');
  329.         wp_register_script('touchswipe', get_template_directory_uri() . '/js/jquery.touchSwipe-1.2.5.js');
  330.         wp_register_script('theme', get_template_directory_uri() . '/js/scripts.js');
  331.         wp_register_script('prettyPhoto', get_template_directory_uri() . '/js/jquery.prettyPhoto.js');
  332.  
  333.         wp_enqueue_script('jquery');
  334.         wp_enqueue_script('prettyPhoto');
  335.         wp_enqueue_script('bootstrap');
  336.         wp_enqueue_script('easing');
  337.         wp_enqueue_script('validate');
  338.         wp_enqueue_script('jplayer');
  339.         wp_enqueue_script('preloader');
  340.         wp_enqueue_script('nicescroll');
  341.         wp_enqueue_script('flexslider');
  342.         wp_enqueue_script('plusIsotope');
  343.         wp_enqueue_script('infinitescroll');
  344.         wp_enqueue_script('touchswipe');
  345.         wp_enqueue_script('thickbox');
  346.         if (isset($data['facebook_comment']) && $data['facebook_comment'])
  347.             wp_enqueue_script('fbc');
  348.         wp_enqueue_script('theme');
  349.     }
  350.  
  351. endif;
  352.  
  353. if (!function_exists('get_format_audio_feature')) :
  354.  
  355.     function get_format_audio_feature($current_post_id) {
  356.         global $post;
  357.         if (get_post_meta($current_post_id, 'tt-audio-type', true) != 'url') {
  358.             echo get_post_meta($current_post_id, 'tt-audio-embed', true);
  359.         } else {
  360.                     ?>
  361.             <div id="jquery_jplayer_<?php echo $current_post_id; ?>" pid="<?php echo $current_post_id; ?>" class="jp-jplayer jp-jplayer-audio" src="<?php echo get_post_meta($current_post_id, 'tt-audio-url', true); ?>" style="width: 0px; height: 0px; "></div>
  362.             <div class="jp-audio-container">
  363.                 <div class="jp-audio">
  364.                     <div class="jp-type-single">
  365.                         <div id="jp_interface_<?php echo $current_post_id; ?>" class="jp-interface">
  366.                             <ul class="jp-controls">
  367.                                 <li><div class="seperator-first"></div></li>
  368.                                 <li><div class="seperator-second"></div></li>
  369.                                 <li><a href="#" class="jp-play" tabindex="1" style="display: block; ">play</a></li>
  370.                                 <li><a href="#" class="jp-pause" tabindex="1" style="display: none; ">pause</a></li>
  371.                                 <li><a href="#" class="jp-mute" tabindex="1">mute</a></li>
  372.                                 <li><a href="#" class="jp-unmute" tabindex="1" style="display: none; ">unmute</a></li>
  373.                             </ul>
  374.                             <div class="jp-progress-container">
  375.                                 <div class="jp-progress">
  376.                                     <div class="jp-seek-bar" style="width: 100%; ">
  377.                                         <div class="jp-play-bar" style="width: 1.18944845234691%; "></div>
  378.                                     </div>
  379.                                 </div>
  380.                             </div>
  381.                             <div class="jp-volume-bar-container">
  382.                                 <div class="jp-volume-bar">
  383.                                     <div class="jp-volume-bar-value" style="width: 80%; "></div>
  384.                                 </div>
  385.                             </div>
  386.                         </div>
  387.                     </div>
  388.                 </div>
  389.             </div>    
  390.             <?php
  391.         }
  392.     }
  393.  
  394. endif;
  395.  
  396. if (!function_exists('tt_get_filter_list')) :
  397.  
  398. //tt_get_post_format_filter() ->
  399.     function tt_get_filter_list($isBlog = false) {
  400.         global $data, $post;
  401.         if (!isset($data['left_sidebar']) || $data['left_sidebar']) {
  402.             ?>
  403.             <!-- Start Filter --><?php
  404.             if ($isBlog) {
  405.                 $filter = get_post_meta($post->ID, 'mysite_additional_options', true);
  406.                 if (isset($filter['show_filter'])) {
  407.                     ?>
  408.                     <div id="options" class="category-list clearfix">
  409.                         <div class="container">
  410.                             <h3><?php _e('Post Filter', 'mysite') ?></h3>
  411.                             <ul id="filters" class="option-set clearfix post-category" data-option-key="filter"><?php if (!empty($filter['filter_text'])) { ?>
  412.                                     <li><a href="#filter" data-option-value="*" class="selected"><?php echo $filter['filter_text']; ?></a></li><?php
  413.                     }
  414.                     $filters = isset($filter['blog_categories']) ? $filter['blog_categories'] : get_categories();
  415.                     foreach ($filters as $catSlug) {
  416.                         if (!isset($filter['blog_categories'])) {
  417.                             $catSlug = $catSlug->slug;
  418.                         }
  419.                         $category = get_term_by('slug', $catSlug, 'category');
  420.                         echo'<li class="hide"><a href="#filter" data-option-value=".category-' . $catSlug . '" title="' . $category->name . '" ' . ' class="post-category-item">' . $category->name . '</a></li>';
  421.                     }
  422.                     ?>
  423.                             </ul>
  424.                         </div>
  425.                     </div><?php
  426.                 }
  427.             }
  428.             ?>
  429.             <!-- End Filter --><?php
  430.         }
  431.     }
  432.  
  433. endif;
  434.  
  435. if (!function_exists('tt_get_post_category_list')) :
  436.  
  437.     function tt_get_post_category_list() {
  438.         if (get_the_category_list()) {
  439.             echo get_the_category_list(', ');
  440.         }
  441.         if (is_single() && get_the_tag_list()) {
  442.             echo " ";
  443.             echo get_the_tag_list('<span>' . __('Tagged: ', 'mysite') . '</span>', ', ', '');
  444.         }
  445.     }
  446.  
  447. endif;
  448.  
  449. // mysite Mega Menu
  450. require_once FRAMEWORKPATH . '/admin/lib/mysite_mega_menu.php';
  451. if (!function_exists('get_attachment_id_from_src')) :
  452.  
  453.     function get_attachment_id_from_src($image_src) {
  454.         global $wpdb;
  455.         $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
  456.         $id = $wpdb->get_var($query);
  457.         return $id;
  458.     }
  459.  
  460. endif;
  461.  
  462. if (!function_exists('get_youtube_vimeo_thumb_url')) :
  463.  
  464.     function get_youtube_vimeo_thumb_url($embed) {
  465.         $search = 'src="http://www.youtube.com/embed/';
  466.         $posStart = strpos($embed, $search);
  467.         $thumb_url = false;
  468.         if ($posStart !== false) {
  469.             $posStart+=strlen($search);
  470.             $posEnd = (strpos($embed, '?', $posStart) > -1) ? strpos($embed, '?', $posStart) : strpos($embed, '"', $posStart);
  471.             if ($posEnd !== false) {
  472.                 $thumb_url = substr($embed, $posStart, $posEnd - $posStart);
  473.                 $thumb_url = 'http://img.youtube.com/vi/' . $thumb_url . '/0.jpg';
  474.             }
  475.         }
  476.  
  477.         if ($thumb_url === false) {
  478.             $search = 'src="http://player.vimeo.com/video/';
  479.             $posStart = strpos($embed, $search);
  480.             if ($posStart !== false) {
  481.                 $posStart+=strlen($search);
  482.                 $posEnd = strpos($embed, '?', $posStart);
  483.                 if ($posEnd !== false) {
  484.                     $thumb_url = substr($embed, $posStart, $posEnd - $posStart);
  485.                     $thumb_url = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $thumb_url . ".php"));
  486.                     $thumb_url = $thumb_url[0]['thumbnail_large'];
  487.                 }
  488.             }
  489.         }
  490.         return $thumb_url;
  491.     }
  492.  
  493. endif;
  494.  
  495. if (!function_exists('blog_open_graph_meta')) :
  496.  
  497.     function blog_open_graph_meta() {
  498.         global $data, $post, $paged, $page;
  499.         $ogImg = false;
  500. //    if(is_page_template('page.php') || is_single()) {
  501.         if (is_page() || is_single()) {
  502.             $ogImg = get_post_image();
  503.             if (!$ogImg) {
  504.                 $ogImg = get_post_first_image();
  505.             }
  506.             if (!$ogImg) {
  507.                 $ogImg = get_youtube_vimeo_thumb_url(get_post_meta($post->ID, 'tt-video-embed', true));
  508.             }
  509.             if (!$ogImg) {
  510.                 $slide_imgs = get_post_meta($post->ID, 'tt_slide_images', true);
  511.                 $ogImg      = !empty($slide_imgs[0]['image'])?$slide_imgs[0]['image']:false;
  512.             }
  513.         }
  514.         ?>
  515.         <!-- START - Open Graph Meta -->
  516.         <meta property='og:title'       content='<?php
  517.         wp_title('|', true, 'right');
  518.         bloginfo('name');
  519.         $site_description = get_bloginfo('description', 'display');
  520.         if ($site_description && ( is_home() || is_front_page() ))
  521.             echo " | $site_description";
  522.         if ($paged >= 2 || $page >= 2)
  523.             echo ' | ' . sprintf(__('Page %s', 'mysite'), max($paged, $page));
  524.         ?>'/>
  525.         <meta property='og:image'   content='<?php echo $ogImg ? $ogImg : ''; ?>'/>
  526.         <meta property='og:site_name'   content='<?php bloginfo('name'); ?>'/>
  527.         <meta property='og:description' content='<?php echo get_bloginfo('description'); ?>'/>
  528.         <!-- END   - Open Graph Meta --><?php
  529.     }
  530.  
  531. endif;
  532.  
  533. // Fixing duplicating issue when has Ramdom post order
  534. global $data;
  535. if (!is_admin() && isset($data['order_type']) && $data['order_type'] == 'Random') {
  536.  
  537.     add_filter('posts_orderby', 'edit_posts_orderby');
  538.  
  539.     if (!function_exists('edit_posts_orderby')) :
  540.  
  541.         function edit_posts_orderby($orderby_statement) {
  542.             if (isset($_SESSION['expiretime'])) {
  543.                 if ($_SESSION['expiretime'] < time())
  544.                     session_unset();
  545.             } else
  546.                 $_SESSION['expiretime'] = time() + 300;
  547.  
  548.             $seed = isset($_SESSION['seed']) ? $_SESSION['seed'] : '';
  549.             if (empty($seed)) {
  550.                 $seed = rand();
  551.                 $_SESSION['seed'] = $seed;
  552.             }
  553.             $orderby_statement = 'RAND(' . $seed . ')';
  554.  
  555.             return $orderby_statement;
  556.         }
  557.  
  558.     endif;
  559. }
  560.  
  561. if (!function_exists('remove_category_list_rel')) :
  562.  
  563. // Remove rel attribute from the category list
  564.     function remove_category_list_rel($output) {
  565.         $output = str_replace(' rel="category tag"', '', $output);
  566.         $output = str_replace(' rel="category"', '', $output);
  567.         $output = str_replace(' rel="tag"', '', $output);
  568.         return $output;
  569.     }
  570.  
  571.     add_filter('wp_list_categories', 'remove_category_list_rel');
  572.     add_filter('the_category', 'remove_category_list_rel');
  573.  
  574. // Feature Pointers
  575.     add_action('admin_enqueue_scripts', 'tt_theme_feature_pointer_header');
  576. endif;
  577.  
  578. if (!function_exists('tt_theme_feature_pointer_header')) :
  579.  
  580.     function tt_theme_feature_pointer_header() {
  581.         global $pagenow;
  582.         $enqueue = false;
  583.  
  584.         $dismissedStr = (string) get_user_meta(get_current_user_id(), 'dismissed_wp_pointers', true);
  585.         $dismissed = explode(',', $dismissedStr);
  586.  
  587.         // with activate istall option
  588.         if (is_admin() && isset($_GET['activated']) && $pagenow == 'themes.php') {
  589.             $removed = str_replace(",tt_feature_pointer", "", $dismissedStr);
  590.             $dismissed = explode(',', $removed);
  591.             update_user_meta(get_current_user_id(), 'dismissed_wp_pointers', $removed);
  592.         }
  593.  
  594.         if (!in_array('tt_feature_pointer', $dismissed)) {
  595.             $enqueue = true;
  596.             add_action('admin_print_footer_scripts', 'tt_feature_pointer');
  597.         }
  598.  
  599.         if ($enqueue) {
  600.             // Enqueue pointers
  601.             wp_enqueue_script('wp-pointer');
  602.             wp_enqueue_style('wp-pointer');
  603.         }
  604.     }
  605.  
  606. endif;
  607.  
  608. if (!function_exists('tt_feature_pointer')) :
  609.  
  610.     function tt_feature_pointer() {
  611.         global $pagenowglobal;
  612.         $back_end_pointer_message = array(
  613.             'tt_option_group' => array(
  614.                 'selector' => '#toplevel_page_mysite-options',
  615.                 'content' => '<h3>mysite options panel</h3><p>Check out our admin panel where you have access to over 70+ options.  We have split these options up into 3 different sections to help you customize your site.</p><a class="button-primary" href="admin.php?page=mysite-options">next</a>'),
  616.             'mysite-options' => array(
  617.                 'selector' => '#toplevel_page_mysite-options li.tt-theme-options',
  618.                 'content' => '<h3>Themes Options</h3><p>It has options relevant to the entire site such as logo, favicon, skin and more, without having to change any code. Ex: The Footer tab will let you customize everything about your footer choose between 4 different layouts!</p><a class="button-primary" href="admin.php?page=seooptions">next</a>'),
  619.             'seooptions' => array(
  620.                 'selector' => '#toplevel_page_mysite-options li.tt-theme-seo',
  621.                 'content' => '<h3>SEO options</h3><p>If you fully configure Theme SEO option then your sites getting high traffic. The panel gives you control over title tags, noindex, meta tags, slugs, image and much more.</p><a class="button-primary" href="admin.php?page=comp-options">next</a>'),
  622.             'comp-options' => array(
  623.                 'selector' => '#toplevel_page_mysite-options li.tt-theme-elements',
  624.                 'content' => '<h3>Theme Elements</h3><p>Select for which content types Theme Element (visual shortcode) should be available during post creation/editing. Also you can disable Theme Elements.</p><a class="button-primary" href="post-new.php?post_type=page">next</a>'),
  625.             'tt_pointer' => array(
  626.                 'selector' => '.wpb_switch-to-composer',
  627.                 'content' => '<h3>Theme Elements</h3><p>It will save you tons of time working on the site content. Now you’ll be able to create complex layouts within minutes!</p>'),
  628.         );
  629.         ?>
  630.         <script type="text/javascript">
  631.             jQuery(document).ready(function($) { <?php
  632.         $tt_pointer_page = 'tt_option_group';
  633.         if (isset($_REQUEST['post_type'])) {
  634.             $tt_pointer_page = 'tt_pointer';
  635.         } elseif (isset($_REQUEST['page'])) {
  636.             $tt_pointer_page = $_REQUEST['page'];
  637.         }
  638.  
  639.         if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] == 'slidercatalog' && isset($_REQUEST['post_type']) && $_REQUEST['post_type'] == 'slider') {
  640.             $tt_pointer_page = 'slider_adding';
  641.         }
  642.         ?>
  643.                                
  644.                 $page='<?php echo $tt_pointer_page; ?>';
  645.  
  646.                 $('#toplevel_page_mysite-options>.wp-submenu li').each(function(i){
  647.                     liClass='';
  648.                     switch(i){
  649.                         case 0: liClass="tt-theme-options";  break;
  650.                         case 1: liClass="tt-theme-seo";      break;
  651.                         case 2: liClass="tt-theme-elements"; break;
  652.                         case 3: liClass="tt-theme-guide";    break;
  653.                     }
  654.                     $(this).addClass(liClass);
  655.                 });
  656.  
  657.                 function tt_dismiss_wp_pointer(){
  658.                     $.post( ajaxurl, {
  659.                         pointer: 'tt_feature_pointer',
  660.                         action: 'dismiss-wp-pointer'
  661.                     });
  662.                 }
  663.  
  664.                 function tt_open_wp_pointer(){
  665.                     $('<?php echo $back_end_pointer_message[$tt_pointer_page]['selector']; ?>').pointer({
  666.                         content: '<?php echo $back_end_pointer_message[$tt_pointer_page]['content']; ?>',
  667.                         position: {
  668.                             edge: 'left',
  669.                             align: 'center'
  670.                         },
  671.                         close: function() { tt_dismiss_wp_pointer(); }
  672.                     }).pointer('open');
  673.                 }
  674.  
  675.                 switch($page){
  676.                     case 'tt_option_group':
  677.                     case 'mysite-options' :
  678.                     case 'seooptions'     :
  679.                     //                case 'guide'          : { $('#toplevel_page_mysite-options li.tt-theme-guide').pointer('open');    break; }
  680.                 case 'guide'          :
  681.                 case 'tt_pointer'     :
  682.                 case 'slider_adding'  :{tt_open_wp_pointer(); break;}
  683.                 case 'comp-options'   : {
  684.                         $('.controls input').each(function(){
  685.                             if($(this).attr('name')=='check_composer[page]' && $(this).attr('checked')!='checked'){
  686.                                 $(this).attr('checked','checked');
  687.                                 $('#c_of_save').click();
  688.                             }
  689.                         });
  690.                         tt_open_wp_pointer();
  691.                         break;
  692.                     }
  693.             }
  694.         });
  695.         </script><?php
  696.     }
  697.  
  698. endif;
  699.  
  700. if (!function_exists('infiniteScroll')) :
  701.  
  702. // Infinite Scroll
  703.     function infiniteScroll() {
  704.         global $wp_query, $data;
  705.         $pages = $wp_query->max_num_pages;
  706.         $post_count = $wp_query->post_count;
  707.         $post_found = $wp_query->found_posts;
  708.         if (!$pages) {
  709.             $pages = 1;
  710.         }
  711.         if (1 < $pages) {
  712.             $auto_infinite_scroll = (isset($data['auto_infinite_scroll']) && $data['auto_infinite_scroll']) ? true : false;
  713.             echo '<nav id="page_nav"><a href=""></a></nav>';
  714.             if (!$auto_infinite_scroll) {
  715.                 ?>
  716.                 <nav class="manual-infinite-scroll">
  717.                     <div class="container">
  718.                         <div class="row">
  719.                             <div class="span12">
  720.                                 <div class="to-top">
  721.                                     <a class="pager-item anchorLink" style="cursor:pointer;">
  722.                                         <?php _e('Back to top', 'mysite') ?>
  723.                                     </a>
  724.                                 </div>
  725.                                 <div class="infinite-button">
  726.                                     <a class="next-items" style="cursor:pointer;"><?php _e('Load more', 'mysite'); ?></a>
  727.                                 </div>
  728.                                 <div class="remaining clearfix" data-count="<?php echo $post_count; ?>" data-found="<?php echo $post_found; ?>" data-many="<?php _e('remaining', 'mysite'); ?>" data-one="<?php _e('remaining', 'mysite'); ?>" data-no="<?php _e('No more posts', 'mysite'); ?>"></div>
  729.                             </div>
  730.                         </div>
  731.                     </div>
  732.                 </nav><?php
  733.                     }
  734.                 }
  735.             }
  736.  
  737.         endif;
  738.  
  739.         if (!function_exists('tt_prev_next_post')) :
  740.  
  741. // Next prev post
  742.             function tt_prev_next_post() {
  743.                 global $formatimg, $format;
  744.                 //Get Previous
  745.                 $next_post = get_next_post();
  746.                 if (!empty($next_post)) {
  747.                     query_posts('p=' . $next_post->ID);
  748.                     if (have_posts()) {
  749.                         the_post();
  750.                         $format = get_post_format();
  751.                         $formatimg = $format == '' ? 'standart' : "format-$format";
  752.                         $btnImg = get_post_image_for_nextprev();
  753.                         if (!$btnImg) {
  754.                             $btnImg = get_post_first_image();
  755.                         }
  756.                         if (!$btnImg) {
  757.                             $btnImg = get_youtube_vimeo_thumb_url(get_post_meta($next_post->ID, 'tt-video-embed', true));
  758.                         }
  759.                                         ?>
  760.                 <div id="prev" class="<?php
  761.                 if (!$btnImg) {
  762.                     echo 'no-thumb';
  763.                 }
  764.                                         ?>">
  765.                     <a href="<?php the_permalink(); ?>">
  766.                         <div class="lightBoxNav navLeft"></div>
  767.                     </a>
  768.                     <a href="<?php the_permalink(); ?>" class="link-content">
  769.                         <div class="prev_post"><h3 class="item-title"><?php the_title(); ?></h3><?php
  770.                 if ($btnImg) {
  771.                     echo '<img src="' . $btnImg . '" alt="">';
  772.                 }
  773.                                         ?>    </div>
  774.                     </a>
  775.                 </div><?php
  776.             }
  777.             wp_reset_query();
  778.         }
  779.         //Get Next
  780.         $prev_post = get_previous_post();
  781.         if (!empty($prev_post)) {
  782.             query_posts('p=' . $prev_post->ID);
  783.             if (have_posts()) {
  784.                 the_post();
  785.                 $format = get_post_format();
  786.                 $formatimg = $format == '' ? 'standart' : "format-$format";
  787.                 $btnImg = get_post_image_for_nextprev();
  788.                 if (!$btnImg) {
  789.                     $btnImg = get_post_first_image();
  790.                 }
  791.                 if (!$btnImg) {
  792.                     $btnImg = get_youtube_vimeo_thumb_url(get_post_meta($prev_post->ID, 'tt-video-embed', true));
  793.                 }
  794.                                         ?>
  795.                 <div id="next" class="<?php
  796.                 if (!$btnImg) {
  797.                     echo 'no-thumb';
  798.                 }
  799.                                         ?>">
  800.                     <a href="<?php the_permalink(); ?>">
  801.                         <div class="lightBoxNav navRight"></div>
  802.                     </a>
  803.                     <a href="<?php the_permalink(); ?>" class="link-content">
  804.                         <div class="next_post">
  805.                             <h3 class="item-title"><?php the_title(); ?></h3><?php
  806.                 if ($btnImg) {
  807.                     echo '<img src="' . $btnImg . '" alt="">';
  808.                 }
  809.                                         ?>    </div>
  810.                     </a>
  811.                 </div><?php
  812.             }
  813.             wp_reset_query();
  814.         }
  815.     }
  816.  
  817. endif;
  818.  
  819. if (!function_exists('aq_resize')) :
  820.  
  821.     function aq_resize($url, $width, $height = null, $crop = null, $single = true) {
  822.         //validate inputs
  823.         if (!$url OR !$width)
  824.             return false;
  825.  
  826.         //define upload path & dir
  827.         $upload_info = wp_upload_dir();
  828.         $upload_dir = $upload_info['basedir'];
  829.         $upload_url = $upload_info['baseurl'];
  830.  
  831.         //check if $img_url is local
  832.         if (strpos($url, $upload_url) === false)
  833.             return false;
  834.  
  835.         //define path of image
  836.         $rel_path = str_replace($upload_url, '', $url);
  837.         $img_path = $upload_dir . $rel_path;
  838.  
  839.         //check if img path exists, and is an image indeed
  840.         if (!file_exists($img_path) OR !getimagesize($img_path))
  841.             return false;
  842.  
  843.         //get image info
  844.         $info = pathinfo($img_path);
  845.         $ext = $info['extension'];
  846.         list($orig_w, $orig_h) = getimagesize($img_path);
  847.  
  848.         //get image size after cropping
  849.         $dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
  850.         $dst_w = $dims[4];
  851.         $dst_h = $dims[5];
  852.  
  853.         //use this to check if cropped image already exists, so we can return that instead
  854.         $suffix = "{$dst_w}x{$dst_h}";
  855.         $dst_rel_path = str_replace('.' . $ext, '', $rel_path);
  856.         $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
  857.  
  858.         //if orig size is smaller
  859.         if ($width >= $orig_w) {
  860.             if (!$dst_h) :
  861.                 //can't resize, so return original url
  862.                 $img_url = $url;
  863.                 $dst_w = $orig_w;
  864.                 $dst_h = $orig_h;
  865.             else :
  866.                 //else check if cache exists
  867.                 if (file_exists($destfilename) && getimagesize($destfilename)) {
  868.                     $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
  869.                 }
  870.                 //else resize and return the new resized image url
  871.                 else {
  872.                     $resized_img_path = image_resize($img_path, $width, $height, $crop);
  873.                     $resized_rel_path = str_replace($upload_dir, '', $resized_img_path);
  874.                     $img_url = $upload_url . $resized_rel_path;
  875.                 }
  876.             endif;
  877.         }
  878.         //else check if cache exists
  879.         elseif (file_exists($destfilename) && getimagesize($destfilename)) {
  880.             $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
  881.         }
  882.         //else, we resize the image and return the new resized image url
  883.         else {
  884.             $resized_img_path = image_resize($img_path, $width, $height, $crop);
  885.             $resized_rel_path = str_replace($upload_dir, '', $resized_img_path);
  886.             $img_url = $upload_url . $resized_rel_path;
  887.         }
  888.  
  889.         //return the output
  890.         if ($single) {
  891.             //str return
  892.             $image = $img_url;
  893.         } else {
  894.             //array return
  895.             $image = array(
  896.                 0 => $img_url,
  897.                 1 => $dst_w,
  898.                 2 => $dst_h
  899.             );
  900.         }
  901.         return $image;
  902.     }
  903.  
  904. endif;
  905.  
  906. if (!function_exists('user_bar')) :
  907.  
  908.     function user_bar($is_widget = false) {
  909. //    tt_social_message('user_name_exists');
  910.         global $data;
  911.                                 ?>
  912.         <div class="user-bar <?php echo $is_widget ? 'user-widget clearfix' : ''; ?>"><?php
  913.         if (is_user_logged_in()) {
  914.             $log_out_url = isset($data['logout_redirect_page']) && $data['logout_redirect_page'] != 'no' && $data['logout_redirect_page'] != '' ? get_permalink($data['logout_redirect_page']) : home_url();
  915.             $current_user = wp_get_current_user();
  916.             $user_id = $current_user->ID;
  917.             $user_login = $current_user->user_login;
  918.                                     ?>
  919.                 <div class="user-online pull-right">
  920.                     <a href="<?php echo get_author_posts_url($user_id); ?>" class="tt-author2">
  921.                         <div class="author-avatar">
  922.                             <?php tt_get_user_avatar(); ?>
  923.                         </div>
  924.                         <div class="author-content">
  925.                             <span class="user-name"><?php echo $user_login; ?></span><b class="caret"></b>
  926.                             <span class="user-caps"><?php echo key($current_user->caps); ?></span>
  927.                         </div>
  928.                     </a>
  929.                     <ul class="user-bar-dropdown clearfix <?php echo $is_widget ? '' : 'dropdown-menu'; ?>">
  930.                         <li><a href="<?php echo get_author_posts_url(get_current_user_id()); ?>" class="user-my-profile"><i class="icon-user"></i><?php _e('My profile', 'mysite'); ?></a></li>
  931.                         <?php if (isset($data['profile_options_page']) && $data['profile_options_page'] !== 'no' && $data['profile_options_page'] !== '') { ?>
  932.                             <li><a href="<?php echo get_permalink($data['profile_options_page']); ?>" class="user-my-settings"><i class="icon-wrench"></i><?php _e('My settings', 'mysite'); ?></a></li>
  933.                         <?php } ?>
  934.                         <?php if (isset($data['frontend_editor_page']) && $data['frontend_editor_page'] !== 'no' && $data['frontend_editor_page'] !== '') { ?>
  935.                             <li><a href="<?php echo get_permalink($data['frontend_editor_page']); ?>" class="user-add-post"><i class="icon-pencil"></i><?php _e('Add Post', 'mysite'); ?></a></li>
  936.                         <?php } ?>
  937.                         <?php if (isset($data['favorite_page']) && $data['favorite_page'] != 'no' && $data['favorite_page'] != '') { ?>
  938.                             <li><a href="<?php echo get_permalink($data['favorite_page']); ?>" class="user-favorite-posts"><i class="icon-star"></i><?php _e('Favorite posts', 'mysite'); ?></a></li>
  939.                         <?php } ?>
  940.                         <li class="divider"></li>
  941.                         <li><a href="<?php echo wp_logout_url($log_out_url); ?>" class="user-log-out"><i class="icon-remove-sign"></i><?php _e('Log out', 'mysite'); ?></a></li>
  942.                     </ul>
  943.                 </div><?php } else {
  944.                         ?>
  945.                 <div class="user-offline">
  946.                     <div class="user-join">
  947.                         <?php _e('Not a Member?', 'mysite'); ?>
  948.                         <a href="#">
  949.                             <?php _e('Join Now', 'mysite'); ?>
  950.                         </a>
  951.                     </div>
  952.                     <div class="user-login-buton pull-right"><?php
  953.                 if (isset($data['fb_connect']) && $data['fb_connect'] && isset($data['fb_app_id']) && !empty($data['fb_app_id']) && isset($data['fb_app_secret']) && !empty($data['fb_app_secret'])) {
  954.                     global $facebook;
  955.                                 ?><a href="<?php echo $facebook->getLoginUrl(array('scope' => 'email')); ?>" class="fb"><img alt="Login with facebook" src="<?php echo get_template_directory_uri(); ?>/images/facebook-login.png" /></a><?php
  956.             }
  957.             if (isset($data['tw_connect']) && $data['tw_connect'] && isset($data['tw_consumer_key']) && !empty($data['tw_consumer_key']) && isset($data['tw_consumer_secret']) && !empty($data['tw_consumer_secret'])) {
  958.                 echo'<a href="' . home_url() . '?tt_tw_redirect=true" class="tw"><img alt="Login with twitter" src="' . get_template_directory_uri() . '/images/twitter-login.png"/></a>';
  959.             }
  960.             if (!$is_widget) {
  961.                                 ?>
  962.                             <a href="#" class="btn wp dropdown-toggle"><?php _e('Sign In', 'mysite'); ?></a><?php }
  963.                             ?>
  964.                         <div class="user-form-container <?php echo $is_widget ? '' : 'dropdown-menu'; ?>">
  965.                             <?php user_login_form(); ?>
  966.                         </div>
  967.                     </div>
  968.                 </div><?php }
  969.                         ?>
  970.         </div><?php
  971.     }
  972.  
  973. endif;
  974.  
  975. if (!function_exists('style_search_form')) :
  976.  
  977. // Customize the search form
  978.     function style_search_form($form) {
  979.         $form = '<form method="get" id="searchform" class="form-search " action="' . home_url() . '/" >
  980.            <div class="input-append">';
  981.         $form .= '<button type="submit" id="searchsubmit"></button>';
  982.         if (is_search()) {
  983.             $form .='<input type="search" value="' . esc_attr(apply_filters('the_search_query', get_search_query())) . '" name="s" class="span2" id="appendedInputButton" onfocus="if(this.value==this.defaultValue)this.value=\'\';" onblur="if(this.value==\'\')this.value=this.defaultValue;"/>';
  984.         } else {
  985.             $form .='<input type="search" name="s" class="span2" id="appendedInputButton" onfocus="if(this.value==this.defaultValue)this.value=\'\';" onblur="if(this.value==\'\')this.value=this.defaultValue;"/>';
  986.         }
  987.         $form .= '</div>
  988.            </form>';
  989.         return $form;
  990.     }
  991.  
  992.     add_filter('get_search_form', 'style_search_form');
  993. endif;
  994.  
  995. if (!function_exists('exclude_pages_from_search')) :
  996.  
  997.     function exclude_pages_from_search($query) {
  998.         if ($query->is_search) {
  999.             $query->set('post_type', 'post');
  1000.         }
  1001.         return $query;
  1002.     }
  1003.  
  1004.     add_filter('pre_get_posts', 'exclude_pages_from_search');
  1005. endif;
  1006.  
  1007. if (!function_exists('is_mobile')) :
  1008.  
  1009.     function is_mobile() {
  1010.         if (preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|sagem|sharp|sie-|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
  1011.             return true;
  1012.         else
  1013.             return false;
  1014.     }
  1015.  
  1016. endif;
  1017.  
  1018. if (!function_exists('adjustBrightness')) :
  1019.  
  1020.     function adjustBrightness($hex, $steps) {
  1021.         // Steps should be between -255 and 255. Negative = darker, positive = lighter
  1022.         $steps = max(-255, min(255, $steps));
  1023.  
  1024.         // Format the hex color string
  1025.         $hex = str_replace('#', '', $hex);
  1026.         if (strlen($hex) == 3) {
  1027.             $hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
  1028.         }
  1029.  
  1030.         // Get decimal values
  1031.         $r = hexdec(substr($hex, 0, 2));
  1032.         $g = hexdec(substr($hex, 2, 2));
  1033.         $b = hexdec(substr($hex, 4, 2));
  1034.  
  1035.         // Adjust number of steps and keep it inside 0 to 255
  1036.         $r = max(0, min(255, $r + $steps));
  1037.         $g = max(0, min(255, $g + $steps));
  1038.         $b = max(0, min(255, $b + $steps));
  1039.  
  1040.         $r_hex = str_pad(dechex($r), 2, '0', STR_PAD_LEFT);
  1041.         $g_hex = str_pad(dechex($g), 2, '0', STR_PAD_LEFT);
  1042.         $b_hex = str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
  1043.  
  1044.         return '#' . $r_hex . $g_hex . $b_hex;
  1045.     }
  1046.  
  1047. endif;
  1048.  
  1049. if (!function_exists('getContrast50')) :
  1050.  
  1051.     function getContrast50($hexcolor) {
  1052.         return (hexdec($hexcolor) > (0xffffff / 2 + 0xffffff / 10)) ? 'light' : 'dark';
  1053.     }
  1054.  
  1055. endif;
  1056.  
  1057. if (!function_exists('tt_save_post')) :
  1058.  
  1059. // START - Auto Delete Posts
  1060.     function tt_save_post($post_id) {
  1061.         global $data;
  1062.         if (isset($data['auto_delete']) && $data['auto_delete']) {
  1063.             if (!wp_is_post_revision($post_id)) {
  1064.                 if (get_post_meta($post_id, 'tt_insert', true)) {
  1065.                     if (get_post_status($post_id) == 'publish') {
  1066.                         update_post_meta($post_id, 'tt_insert', ('ok'));
  1067.                     }
  1068.                 } else {
  1069.                     update_post_meta($post_id, 'tt_insert', (get_post_status($post_id) == 'publish' ? 'ok' : time()));
  1070.                 }
  1071.             }
  1072.         }
  1073.     }
  1074.  
  1075. endif;
  1076.  
  1077. if (!function_exists('delete_expired_posts')) :
  1078.  
  1079.     function delete_expired_posts() {
  1080.         global $data;
  1081.         if (isset($data['auto_delete']) && $data['auto_delete'] && isset($data['auto_delete_day'])) {
  1082.             $args = array(
  1083.                 'posts_per_page' => -1,
  1084.                 'post_type' => 'any',
  1085.                 'post_status' => 'any',
  1086.                 'meta_query' => array(
  1087.                     array(
  1088.                         'key' => 'tt_insert',
  1089.                         'value' => 'ok',
  1090.                         'compare' => '!='
  1091.                     )
  1092.                 )
  1093.             );
  1094.             $the_query = new WP_Query($args);
  1095.             while ($the_query->have_posts()) {
  1096.                 $the_query->the_post();
  1097.                 $post_id = $the_query->post->ID;
  1098.                 if ($post_tt_insert = get_post_meta($post_id, 'tt_insert', true)) {
  1099.                     if (is_numeric($post_tt_insert) && $post_tt_insert = intval($post_tt_insert)) {
  1100.                         $day = 24 * 60 * 60;
  1101.                         if ($post_tt_insert + ($data['auto_delete_day'] * $day) < time()) {
  1102. //                        wp_delete_post($post_id,true);
  1103.                             $post_id = wp_update_post(array('ID' => $post_id, 'post_status' => 'trash'));
  1104.                         }
  1105.                     } else {
  1106.                         update_post_meta($post_id, 'tt_insert', 'ok');
  1107.                     }
  1108.                 }
  1109.             }
  1110.             wp_reset_postdata();
  1111.         }
  1112.     }
  1113.  
  1114. endif;
  1115. if (isset($data['auto_delete']) && $data['auto_delete'] && isset($data['auto_delete_day'])) {
  1116.     add_action('save_post', 'tt_save_post');
  1117.     add_action('init', 'delete_expired_posts');
  1118. }
  1119.  
  1120. // END   - Auto Delete Posts
  1121.  
  1122.  
  1123. if (!function_exists('my_comment_form')) {
  1124.  
  1125.     function my_comment_form($fields) {
  1126.         $fields['author'] =
  1127.                 '<div class="control-group overlabel-wrapper">' .
  1128.                 '<input type="text" name="author" id="author" class="span3 required" value="" tabindex="1" />' .
  1129.                 '<label for="author" class="overlabel">' . __('Name', 'mysite') . ' (*)</label>' .
  1130.                 '</div>';
  1131.         $fields['email'] =
  1132.                 '<div class="control-group overlabel-wrapper">' .
  1133.                 '<input type="text" name="email" id="email" class="required email span3" value="" tabindex="2"/>' .
  1134.                 '<label for="email" class="overlabel">' . __('Email', 'mysite') . ' (*)</label>
  1135.            </div>';
  1136.         $fields['url'] =
  1137.                 '<div class="control-group overlabel-wrapper">' .
  1138.                 '<input type="text" name="url" id="url" class="span3" value="" tabindex="3" />' .
  1139.                 '<label for="url" class="overlabel">' . __('Website', 'mysite') . '</label>' .
  1140.                 '</div>';
  1141.         return $fields;
  1142.     }
  1143.  
  1144.     add_filter('comment_form_default_fields', 'my_comment_form');
  1145. }
  1146.  
  1147. if (!function_exists('custom_upload_mimes')) {
  1148.     add_filter('upload_mimes', 'custom_upload_mimes');
  1149.  
  1150.     function custom_upload_mimes($existing_mimes = array()) {
  1151.         $existing_mimes['ico'] = "image/x-icon";
  1152.         return $existing_mimes;
  1153.     }
  1154.  
  1155. }
  1156.  
  1157. function theme_time_ago() {
  1158.  
  1159.     global $post;
  1160.  
  1161.     $date = get_post_time('G', true, $post);
  1162.        
  1163.         if(empty($date)){return __('Pending Post','mysite');}
  1164.        
  1165.  
  1166.     $chunks = array(
  1167.         array( 60 * 60 * 24 * 365 , __( 'year', 'mysite' ), __( 'years', 'mysite' ) ),
  1168.         array( 60 * 60 * 24 * 30 , __( 'month', 'mysite' ), __( 'months', 'mysite' ) ),
  1169.         array( 60 * 60 * 24 * 7, __( 'week', 'mysite' ), __( 'weeks', 'mysite' ) ),
  1170.         array( 60 * 60 * 24 , __( 'day', 'mysite' ), __( 'days', 'mysite' ) ),
  1171.         array( 60 * 60 , __( 'hour', 'mysite' ), __( 'hours', 'mysite' ) ),
  1172.         array( 60 , __( 'minute', 'mysite' ), __( 'minutes', 'mysite' ) ),
  1173.         array( 1, __( 'second', 'mysite' ), __( 'seconds', 'mysite' ) )
  1174.     );
  1175.  
  1176.     if ( !is_numeric( $date ) ) {
  1177.         $time_chunks = explode( ':', str_replace( ' ', ':', $date ) );
  1178.         $date_chunks = explode( '-', str_replace( ' ', '-', $date ) );
  1179.         $date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
  1180.     }
  1181.  
  1182.     $current_time = current_time( 'mysql', $gmt = 0 );
  1183.     $newer_date = strtotime( $current_time );
  1184.  
  1185.     // Difference in seconds
  1186.     $since = $newer_date - $date;
  1187.  
  1188.     // Something went wrong with date calculation and we ended up with a negative date.
  1189.     if ( 0 > $since )
  1190.         return __( 'sometime', 'mysite' );
  1191.  
  1192.     /**
  1193.      * We only want to output one chunks of time here, eg:
  1194.      * x years
  1195.      * xx months
  1196.      * so there's only one bit of calculation below:
  1197.      */
  1198.  
  1199.     //Step one: the first chunk
  1200.     for ( $i = 0, $j = count($chunks); $i < $j; $i++) {
  1201.         $seconds = $chunks[$i][0];
  1202.  
  1203.         // Finding the biggest chunk (if the chunk fits, break)
  1204.         if ( ( $count = floor($since / $seconds) ) != 0 )
  1205.             break;
  1206.     }
  1207.  
  1208.     // Set output var
  1209.     $output = ( 1 == $count ) ? '1 '. $chunks[$i][1] : $count . ' ' . $chunks[$i][2];
  1210.  
  1211.  
  1212.     if ( !(int)trim($output) ){
  1213.         $output = '0 ' . __( 'seconds', 'mysite' );
  1214.     }
  1215.  
  1216.     $output .= __(' ago', 'mysite');
  1217.  
  1218.     return $output;
  1219. }
  1220. /** RSS_thumbnail */
  1221. function RSS_thumbnail($content)
  1222. {
  1223.     global $post;
  1224.    
  1225.     if(has_post_thumbnail($post->ID))
  1226.     {
  1227.         $post_content = '<p>' . get_the_post_thumbnail($post->ID, 'thumbnail') . '</p>' . $content;
  1228.     }
  1229.    
  1230.     return $post_content;
  1231. }
  1232.  
  1233. add_filter('the_excerpt_rss', 'RSS_thumbnail');
  1234. add_filter('the_content_feed', 'RSS_thumbnail');
  1235. function get_representative_images() {
  1236.     global $post;
  1237.     $images = array('http://mysite.com/mysite-logo.png');
  1238.     if ( has_post_thumbnail($post->ID) ) { // check if the post has a Post Thumbnail assigned to it.
  1239.         $image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail');
  1240.         array_unshift($images, $image_url[0]);
  1241.     }
  1242.     return $images;
  1243. }
  1244. /** changing default wordpres email settings */
  1245.  
  1246. add_filter('wp_mail_from', 'new_mail_from');
  1247. add_filter('wp_mail_from_name', 'new_mail_from_name');
  1248.  
  1249. function new_mail_from($old) {
  1250.  return 'info@mysite.com';
  1251. }
  1252. function new_mail_from_name($old) {
  1253.  return 'mysite.com';
  1254. }
  1255. /**
  1256.  * find if content has wide shortcode in it.
  1257.  */
  1258. function mysite_has_wide_shortcode() {
  1259.     global $post;
  1260.  
  1261.     if ( ! Is_single() )
  1262.         return;
  1263.  
  1264.     if ( false === strpos( $post->post_content, '[wide]' ) )
  1265.         return false;
  1266.  
  1267.     return true;
  1268. }  
  1269. add_filter( 'coauthors_guest_author_avatar_sizes', 'dbx_avatar_sizes' );
  1270. function dbx_avatar_sizes() {
  1271.     return array();
  1272. }
  1273. //Google Maps Shortcode
  1274. function do_googleMaps($atts, $content = null) {
  1275.    extract(shortcode_atts(array(
  1276.       "width" => '100%',
  1277.       "height" => '400',
  1278.       "src" => ''
  1279.    ), $atts));
  1280.    return '<iframe width="'.$width.'" height="'.$height.'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="'.$src.'&amp;output=embed" ></iframe>';
  1281. }
  1282. add_shortcode("googlemap", "do_googleMaps");
  1283. add_filter('widget_text', 'do_shortcode');
  1284. // Customize login styles
  1285. function mysite_custom_login_styles(){
  1286. ?> <style type="text/css">
  1287. /* Change login page background */
  1288. /* Make sure you change image paths to yours */
  1289. body.login{ background: #000  }
  1290.  
  1291. /* Make sure you change image paths to yours */
  1292. body.login h1 a { background: url("http://mysite.com/mysite-logo.png") no-repeat top center; }
  1293.  
  1294. /* Optional : Change link color & shadow if needed */
  1295. .login #nav a, .login #backtoblog a { color: #999!important; text-decoration:none; text-shadow:#000 1px 1px 0; }
  1296. .login #nav a:hover, .login #backtoblog a:hover { color: #fff!important; text-decoration:none; text-shadow:#000 1px 1px 0; }
  1297.  
  1298. /* Optional : Add some shadow to message boxes and login box */
  1299. .login form, p.message {
  1300. -moz-box-shadow: rgba(0,0,0,0.5) 0 2px 8px;
  1301. -webkit-box-shadow: rgba(0,0,0,0.5) 0 2px 8px;
  1302. box-shadow: rgba(0,0,0,0.5) 0 2px 8px;
  1303. }
  1304. </style><?php
  1305. }
  1306. add_action('login_head', 'mysite_custom_login_styles');
  1307. // Customize login header link
  1308. function mysite_login_header_url(){
  1309.     return "http://mysite.com";
  1310. } add_action('login_headerurl', 'mysite_login_header_url');
  1311.  
  1312. function mysite_login_header_link_title(){
  1313.     return "Mysite";
  1314. } add_action('login_headertitle', 'mysite_login_header_link_title');
  1315. // Add a login message
  1316. function mysite_login_message($msg){
  1317.     return $msg . "<p class=\"message\">Welcome <strong>".get_bloginfo('name')."</strong>. Login Plz.</p>";
  1318. } add_action('login_message', 'mysite_login_message');
  1319. function remove_admin_bar_links() {
  1320.     global $wp_admin_bar;
  1321.     $wp_admin_bar->remove_menu('wp-logo');
  1322.     $wp_admin_bar->remove_menu('updates');  
  1323. }
  1324. add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );?>
  1325. <?php
  1326.  remove_action('wp_head', 'wp_generator');
  1327.  function blank_version() {
  1328.     return '';
  1329.  }
  1330.  add_filter('the_generator','blank_version');
  1331. ?>
  1332. <?php
  1333. /* No Self Pings */
  1334. //Pass the variable by reference to the function, so the function can modify the variable.
  1335. function no_self_ping (&$links) {
  1336. $home = get_option( 'home' );
  1337. foreach ( $links as $l => $link )
  1338.     //Find the position of the first occurrence of a substring in a string.
  1339.     //($a === $b) Identical operator. TRUE if $a is equal to $b, and they are of the same type.
  1340.     if ( 0 === strpos( $link, $home ) )
  1341.         //Unset the variable
  1342.         unset($links[$l]);
  1343. }
  1344. //Hooks the function to the specific action (pre_ping)
  1345. add_action( 'pre_ping', 'no_self_ping' );
  1346. ?>
Add Comment
Please, Sign In to add comment