1. <?php
  2.  
  3. //sidebars
  4. include(get_template_directory().'/functions/rt_ud_sidebars.php');
  5.  
  6. //custom post types - taxonomies
  7. include(get_template_directory().'/functions/rt_custom_posts.php');
  8. rt_theme_custom_posts(); //call custom post types
  9.  
  10. //admin panel options
  11. if(is_admin()):
  12. include(get_template_directory().'/rttheme_options/includes.php');
  13. endif;
  14.  
  15. if(!is_admin()):
  16. //vt resize
  17. include(get_template_directory().'/rttheme_options/plugins/vt_resize.php');
  18.  
  19. //breadcrumb function
  20. include(get_template_directory().'/functions/rt_breadcrumb.php');
  21.  
  22. //shortcodes
  23. include(get_template_directory().'/functions/rt_shortcodes.php');
  24.  
  25. //comments
  26. include(get_template_directory().'/functions/rt_comments.php');
  27. endif;
  28.  
  29. if ( ! isset( $content_width ) ) $content_width = 680;
  30.  
  31.  
  32. // Load text domain
  33. load_theme_textdomain('rt_theme', get_template_directory().'/languages' );
  34.  
  35. // Automatic Feed Links
  36. add_theme_support( 'automatic-feed-links' );
  37.  
  38. /*
  39. *
  40. * Loading Theme Scripts
  41. *
  42. */
  43.  
  44. function rt_theme_load_scripts(){
  45.     global $tabbed_page;
  46.    
  47.     $template_directory = get_template_directory_uri();
  48.    
  49.     if (!is_admin()) {//load theme scripts
  50.        wp_deregister_script( 'jquery' );     
  51.        wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js' , false, '');  
  52.        wp_enqueue_script('jquery-easing', $template_directory  . '/js/jquery.easing.1.3.js', array('jquery') );    
  53.        wp_enqueue_script('jquery-cycle', $template_directory  . '/js/jquery.cycle.all.min.js', array('jquery') );
  54.        wp_enqueue_script('jquery-validate', $template_directory  . '/js/jquery.validate.js', array('jquery') );
  55.        wp_enqueue_script('jquery-prettyphoto', $template_directory  . '/js/jquery.prettyPhoto.js', array('jquery') );
  56.        
  57.        if(!get_option('rttheme_disable_cufon')){//if cufon is active
  58.           wp_enqueue_script('cufon', $template_directory  . '/js/cufon.js', array('jquery') );
  59.           wp_enqueue_script('aller-cufon-fonts', $template_directory  . '/js/vegur_font.js', array('jquery') );
  60.        }
  61.  
  62.        wp_enqueue_script('tools', $template_directory  . '/js/jquery.tools.min.js', array('jquery') );
  63.        wp_enqueue_script('rt-theme-scripts', $template_directory  . '/js/script.js', array('jquery') );
  64.        wp_enqueue_script('jquery-form');
  65.  
  66.     }
  67. }
  68.  
  69. add_action('init', 'rt_theme_load_scripts');
  70.  
  71. /*
  72. Theme color selection
  73. */
  74. if (get_option('rttheme_style')){
  75.     $which_theme=get_option('rttheme_style');
  76. }else{
  77.     $which_theme="1";      
  78. }
  79.  
  80. /*
  81. Post Thumbnails Support
  82. */
  83. add_theme_support( 'post-thumbnails', array( 'post' ) ); // Add it for posts
  84.  
  85. /*
  86. WP 3.0  custom menu
  87. */
  88. add_action( 'init', 'rt_theme_navigations' );
  89.  
  90. function rt_theme_navigations() {
  91.     register_nav_menu( 'rt-theme-left-navigation', __( 'RT Theme Left Navigation' ) );
  92.     register_nav_menu( 'rt-theme-top-navigation', __( 'RT Theme Top Navigation' ) );
  93.     register_nav_menu( 'rt-theme-footer-navigation', __( 'RT Theme Footer Navigation' ) );
  94. }
  95.  
  96. wp_create_nav_menu( 'RT Theme Left Navigation Menu', array( 'slug' => 'rt-theme-left-menu' ) );
  97. wp_create_nav_menu( 'RT Theme Top Navigation Menu', array( 'slug' => 'rt-theme-top-menu' ) );
  98. wp_create_nav_menu( 'RT Theme Footer Navigation Menu', array( 'slug' => 'rt-theme-footer-menu') );
  99.  
  100.  
  101. /*
  102. Flush  old re-write rules
  103. note : this function can be removed after develop period - Tolga Can
  104. */
  105.  
  106. function rt_flush_rewrite_rules()
  107. {
  108.    global $wp_rewrite;
  109.    $wp_rewrite->flush_rules();
  110. }
  111.  
  112. add_action('admin_init', 'rt_flush_rewrite_rules');
  113.  
  114.  
  115. /*
  116. Pagination
  117. */
  118. function get_pagination($range = 7){
  119.   global $paged, $wp_query;
  120.   if ( !isset( $max_page ) ) {
  121.     $max_page = $wp_query->max_num_pages;
  122.   }
  123.   if($max_page > 1){
  124.     if(!$paged){
  125.       $paged = 1;
  126.     }
  127.    
  128.     if ($paged > 1){
  129.         echo "<li class=\"arrow\">";
  130.             previous_posts_link('&laquo;');
  131.         echo "</li>\n";
  132.     }
  133.     if($max_page > $range){
  134.       if($paged < $range){
  135.         for($i = 1; $i <= ($range + 1); $i++){
  136.           echo "<li";
  137.           if($i==$paged) echo " class='active'";
  138.           echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  139.           echo "</li>\n";
  140.         }
  141.       }
  142.       elseif($paged >= ($max_page - ceil(($range/2)))){
  143.         for($i = $max_page - $range; $i <= $max_page; $i++){
  144.           echo "<li";
  145.           if($i==$paged) echo " class='active'";
  146.           echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  147.           echo "</li>\n";
  148.         }
  149.       }
  150.       elseif($paged >= $range && $paged < ($max_page - ceil(($range/2)))){
  151.         for($i = ($paged - ceil($range/2)); $i <= ($paged + ceil(($range/2))); $i++){
  152.  
  153.           echo "<li";
  154.           if($i==$paged) echo " class='active'";
  155.           echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  156.           echo "</li>\n";
  157.  
  158.         }
  159.       }
  160.     }
  161.     else{
  162.       for($i = 1; $i <= $max_page; $i++){
  163.           echo "<li";
  164.           if($i==$paged) echo " class=\"active\" ";
  165.           echo "><a href='" . get_pagenum_link($i) ."'>$i</a>";
  166.           echo "</li>\n";
  167.       }
  168.     }
  169.     if ($paged != $max_page){
  170.         echo "<li class=\"arrow\">";
  171.          next_posts_link('&raquo;');
  172.         echo "</li>\n";
  173.     }
  174.  
  175.   }
  176. }
  177.  
  178.  
  179. /*
  180.  add a class to active product and portolio links
  181. */
  182.  
  183. function rt_nav($link_page,$link_cat){
  184. global $current_page_link,$current_cat_link;
  185.    
  186.     $current_page_link=$link_page;
  187.     $current_cat_link=$link_cat;
  188.  
  189.        
  190.     //page
  191.     function add_class_page($output) {
  192.         global $current_page_link,$current_cat_link;
  193.         $bul=str_replace('/','\\/','"><a href="'.$current_page_link.'">');
  194.         $bul=str_replace('?','\\?',$bul);
  195.         $degistir=' current-menu-item"><a href="'.$current_page_link.'">';
  196.         return preg_replace('/'.$bul.'/', $degistir, $output, 20);
  197.     }
  198.      
  199.  
  200.     //term in page
  201.     function add_class_cat2($output) {
  202.         global $current_page_link,$current_cat_link;
  203.        
  204.         $bul=str_replace('/','\\/','"><a href="'.$current_cat_link.'">');
  205.         $bul=str_replace('?','\\?',$bul);
  206.        
  207.         $degistir=' current-menu-item"><a href="'.$current_cat_link.'">';
  208.        
  209.         return preg_replace('/'.$bul.'/', $degistir, $output, 20);
  210.     }  
  211.            
  212.            
  213.     //call the left menu
  214.  
  215.     if ( has_nav_menu( 'rt-theme-left-navigation' ) ){        
  216.         $menuVars = array(
  217.             'menu_id'         => 'menu',
  218.             'echo'            => false,
  219.             'container_id'    => 'dropdown_menu',
  220.             'theme_location'  => 'rt-theme-left-navigation'
  221.         );
  222.     }else{
  223.         $menuVars = array(
  224.             'menu'            => 'RT Theme Left Navigation Menu',  
  225.             'menu_id'         => 'menu',
  226.             'echo'            => false,
  227.             'container_id'    => 'dropdown_menu',                                  
  228.             'theme_location'  => 'rt-theme-left-navigation'
  229.         ); 
  230.     }
  231.    
  232.     if($link_page && $link_cat){
  233.        
  234.         $dd = add_filter('wp_nav_menu', 'add_class_page');
  235.         $dd = add_filter('wp_nav_menu', 'add_class_cat2');
  236.    
  237.     }
  238.    
  239.     echo wp_nav_menu($menuVars);
  240. }
  241.  
  242.  
  243.  
  244. /*
  245. get the post thumbnail url
  246. */
  247.  
  248. function get_post_thumbnail() {
  249. $files = get_children('post_parent='.get_the_ID().'&post_type=attachment&post_mime_type=image');
  250. if($files) :
  251.     $keys = array_reverse(array_keys($files));
  252.     $j=0;
  253.     $num = $keys[$j];
  254.     $image=wp_get_attachment_image($num, 'large', false);
  255.     $imagepieces = explode('"', $image);
  256.     $imagepath = $imagepieces[1];
  257.     $url=wp_get_attachment_thumb_url($num);
  258.     return $url;
  259. endif;
  260. }
  261.  
  262.  
  263. //installing RT-THEME WIDGETS
  264. require_once(get_template_directory() . '/rttheme_options/widgets/rt-theme-box-widget.php');
  265. require_once(get_template_directory() . '/rttheme_options/widgets/rt-theme-slider-widget.php');
  266. require_once(get_template_directory() . '/rttheme_options/widgets/rt-theme-news-widget.php');
  267.  
  268.  
  269.  
  270.  
  271. #
  272. # WPML match post id
  273. #
  274. function wpml_post_id($id){
  275.     if(function_exists('icl_object_id')) {
  276.         return icl_object_id($id,'post',false);
  277.     } else {
  278.         return $id;
  279.     }
  280. }
  281.  
  282. #
  283. # WPML match page id
  284. #
  285. function wpml_page_id($id){
  286.     if(function_exists('icl_object_id')) {
  287.         return icl_object_id($id,'page',true);
  288.     } else {
  289.         return $id;
  290.     }
  291. }
  292.  
  293. #
  294. # WPML match categories
  295. #
  296. function wpml_lang_object_ids($ids_array, $type) {
  297.     if(function_exists('icl_object_id')) {
  298.         $res = array();
  299.        
  300.         if(!empty($ids_array) && is_array($ids_array)){
  301.             foreach ($ids_array as $id) {
  302.                 $xlat = icl_object_id($id,$type,false);
  303.                 if(!is_null($xlat)) $res[] = $xlat;
  304.             }
  305.         }
  306.        
  307.         return $res;
  308.     } else {
  309.         return $ids_array;
  310.     }
  311. }
  312.  
  313.  
  314.  
  315.  
  316. #
  317. # gets orginal paths of images when multi site mode active
  318. #
  319. function find_image_org_path($image) {
  320.     if(is_multisite()){
  321.         global $blog_id;
  322.         if (isset($blog_id) && $blog_id > 0) {
  323.             if(strpos($image,get_bloginfo('wpurl'))!==false){//image is local
  324.                 $the_image_path = get_current_site(1)->path.str_replace(get_blog_option($blog_id,'fileupload_url'),get_blog_option($blog_id,'upload_path'),$image);
  325.             }else{
  326.                 $the_image_path = $image;
  327.             }
  328.         }else{
  329.             $the_image_path = $image;
  330.         }
  331.     }else{
  332.         $the_image_path = $image;
  333.     }
  334.    
  335.     return $the_image_path;
  336. }
  337.  
  338.  
  339. #
  340. # returns a post ID from a url
  341. #
  342.  
  343. function rt_get_attachment_id_from_src ($image_src) {
  344.         global $wpdb;
  345.         $query = "SELECT ID FROM {$wpdb->posts} WHERE guid='$image_src'";
  346.         $id    = $wpdb->get_var($query);
  347.         return $id;
  348. }
  349. ?>