Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2012
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.71 KB | None | 0 0
  1. <?php
  2. /**
  3. * Misc functions breadcrumbs / pagination / transient data /back to top button
  4. *
  5. * @package mantra
  6. * @subpackage Functions
  7. */
  8.  
  9. if ( ! function_exists( 'mantra_header_scripts' ) ) :
  10. /**
  11. * Loads necessary scripts
  12. * Adds HTML5 tags for IE8
  13. * Used in header.php
  14. */
  15. function mantra_header_scripts() {
  16. $mantra_options= mantra_get_theme_options();
  17. foreach ($mantra_options as $key => $value) {
  18. ${"$key"} = $value ;
  19. }
  20. ?>
  21. <!--[if lt IE 9]>
  22. <script>
  23. document.createElement('header');
  24. document.createElement('nav');
  25. document.createElement('section');
  26. document.createElement('article');
  27. document.createElement('aside');
  28. document.createElement('footer');
  29. document.createElement('hgroup');
  30. </script>
  31. <![endif]-->
  32. <script type="text/javascript">
  33. jQuery(document).ready(function() {
  34. // Add custom borders to images
  35. jQuery("#content img").addClass("<?php echo 'image'.$mantra_image;?>");
  36.  
  37. <?php if ($mantra_mobile=="Enable") { // If mobile view is enabled ?>
  38. jQuery(function () {
  39. // Add select navigation to small screens
  40. jQuery("#prime_nav").tinyNav({
  41. header: true // Show header instead of the active item
  42. });
  43. });
  44. // Add responsive videos
  45. jQuery("#content").fitVids();
  46. <?php }
  47. // Check if sidebars have user colors and if so equalize their heights
  48. if (($mantra_s1bg || $mantra_s2bg) ) { ?>
  49. equalizeHeights();
  50. <?php } ?>
  51. }); // document ready
  52.  
  53. </script>
  54. <?php
  55. }
  56. endif;
  57.  
  58. add_action('wp_footer','mantra_header_scripts',100);
  59.  
  60.  
  61. if ( ! function_exists( 'mantra_link_header' ) ) :
  62. /**
  63. * Creates invisible div over header making it link to home page
  64. * Used in header.php
  65. */
  66. function mantra_link_header() {
  67. echo '<a href="'.home_url( '/' ).'" id="linky"> </a>' ;
  68.  
  69. }
  70. endif;
  71.  
  72. if ($mantra_options['mantra_linkheader']=="Enable") add_action('cryout_branding_hook','mantra_link_header');
  73.  
  74.  
  75. if ( ! function_exists( 'mantra_title_and_description' ) ) :
  76. /**
  77. * Adds title and description to heaer
  78. * Used in header.php
  79. */
  80. function mantra_title_and_description() {
  81. // Site Title
  82. $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div';
  83. echo '<'.$heading_tag.' id="site-title">';
  84. echo '<span> <a href="'.home_url( '/' ).'" title="'.esc_attr( get_bloginfo( 'name', 'display' ) ).'" rel="home">'.get_bloginfo( 'name' ).'</a> </span>';
  85. echo '</'.$heading_tag.'>';
  86. // Site Description
  87. echo '<div id="site-description" >'.get_bloginfo( 'description' ).'</div>';
  88. }
  89. endif;
  90.  
  91. add_action ('cryout_branding_hook','mantra_title_and_description');
  92.  
  93. /**
  94. * Add social icons in header / undermneu left / undermenu right / footer
  95. * Used in header.php and footer.php
  96. */
  97. function mantra_header_socials() {
  98. mantra_set_social_icons('sheader');
  99. }
  100.  
  101. function mantra_smenul_socials() {
  102. mantra_set_social_icons('smenul');
  103. }
  104.  
  105. function mantra_smenur_socials() {
  106. mantra_set_social_icons('smenur');
  107. }
  108.  
  109. function mantra_footer_socials() {
  110. mantra_set_social_icons('sfooter');
  111. }
  112.  
  113. if($mantra_socialsdisplay0) add_action('cryout_branding_hook', 'mantra_header_socials');
  114. if($mantra_socialsdisplay1) add_action('cryout_forbottom_hook', 'mantra_smenul_socials');
  115. if($mantra_socialsdisplay2) add_action('cryout_forbottom_hook', 'mantra_smenur_socials');
  116. if($mantra_socialsdisplay3) add_action('cryout_footer_hook', 'mantra_footer_socials',13);
  117.  
  118.  
  119. if ( ! function_exists( 'mantra_set_social_icons' ) ) :
  120. /**
  121. * Social icons function
  122. */
  123. function mantra_set_social_icons($id) {
  124. global $mantra_options;
  125. foreach ($mantra_options as $key => $value) {
  126. ${"$key"} = $value ;
  127. }
  128. echo '<div class="socials" id="'.$id.'">';
  129. for ($i=1; $i<=9; $i+=2) {
  130. $j=$i+1;
  131. if ( ${"mantra_social$j"} ) {?>
  132. <a target="_blank" rel="nofollow" href="<?php echo esc_url(${"mantra_social$j"}); ?>" class="socialicons social-<?php echo esc_attr(${"mantra_social$i"}); ?>" title="<?php echo esc_attr(${"mantra_social$i"}); ?>"><img alt="<?php echo esc_attr(${"mantra_social$i"}); ?>" src="<?php echo get_template_directory_uri().'/images/socials/'.${"mantra_social$i"}.'.png'; ?>" /></a><?php
  133. }
  134. }
  135. echo '</div>';
  136. }
  137. endif;
  138.  
  139. // Get any existing copy of our transient data
  140. if ( false === ( $cryout_theme_info = get_transient( 'cryout_theme_info' ) ) ) {
  141. // It wasn't there, so regenerate the data and save the transient
  142. if ( ! function_exists( 'get_custom_header' ) ) { $cryout_theme_info = get_theme_data( get_theme_root() . '/mantra/style.css' ); }
  143. else { $cryout_theme_info = wp_get_theme( );}
  144.  
  145. set_transient( 'cryout_theme_info', $cryout_theme_info ,60*60);
  146. }
  147.  
  148. if ( ! function_exists( 'mantra_header_featured_image' ) ) :
  149. /**
  150. * Replaces header image with featured image if there is one for single pages
  151. * Used in header.php
  152. */
  153. function mantra_header_featured_image() {
  154. global $post;
  155. global $mantra_options;
  156. foreach ($mantra_options as $key => $value) {
  157. ${"$key"} = $value ;
  158. }
  159. // Check if this is a post or page, if it has a thumbnail, and if it's a big one
  160. if ( is_singular() && has_post_thumbnail( $post->ID ) && $mantra_fheader == "Enable" &&
  161. ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
  162. $image[1] >= HEADER_IMAGE_WIDTH ) :
  163. // Houston, we have a new header image!
  164. //echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
  165. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array(HEADER_IMAGE_WIDTH,HEADER_IMAGE_HEIGHT) );
  166. endif;
  167. }
  168. endif;
  169.  
  170. add_action ('cryout_branding_hook','mantra_header_featured_image');
  171.  
  172. if ( ! function_exists( 'mantra_back_top' ) ) :
  173. /**
  174. * Mantra back to top button
  175. * Creates div for js
  176. */
  177. function mantra_back_top() {
  178. echo '<div id="toTop"> </div>';
  179. }
  180. endif;
  181.  
  182. if ($mantra_backtop=="Enable") add_action ('cryout_body_hook','mantra_back_top');
  183.  
  184.  
  185. if ( ! function_exists( 'mantra_breadcrumbs' ) ) :
  186. /**
  187. * Creates breadcrumns with page sublevels and category sublevels.
  188. */
  189. function mantra_breadcrumbs() {
  190. $mantra_options= mantra_get_theme_options();
  191. foreach ($mantra_options as $key => $value) {
  192. ${"$key"} = $value ;
  193. }
  194. global $post;
  195. echo '<div class="breadcrumbs">';
  196. if (is_page() && !is_front_page() || is_single() || is_category() || is_archive()) {
  197. echo '<a href="'.get_bloginfo('url').'">'.get_bloginfo('name').' &raquo; </a>';
  198.  
  199. if (is_page()) {
  200. $ancestors = get_post_ancestors($post);
  201.  
  202. if ($ancestors) {
  203. $ancestors = array_reverse($ancestors);
  204.  
  205. foreach ($ancestors as $crumb) {
  206. echo '<a href="'.get_permalink($crumb).'">'.get_the_title($crumb).' &raquo; </a>';
  207. }
  208. }
  209. }
  210.  
  211. if (is_single()) {
  212. if(has_category()) { $category = get_the_category();
  213. echo '<a href="'.get_category_link($category[0]->cat_ID).'">'.$category[0]->cat_name.' &raquo; </a>';
  214. }
  215. }
  216.  
  217. if (is_category()) {
  218. $category = get_the_category();
  219. echo ''.$category[0]->cat_name.'';
  220. }
  221.  
  222.  
  223.  
  224. // Current page
  225. if (is_page() || is_single()) {
  226. echo ''.get_the_title().'';
  227. }
  228. echo '';
  229. } elseif (is_home() && $mantra_frontpage!="Enable" ) {
  230. // Front page
  231. echo '';
  232. echo '<a href="'.get_bloginfo('url').'">'.get_bloginfo('name').'</a> '."&raquo; ";
  233. _e('Home Page','mantra');
  234. echo '';
  235. }
  236. echo '</div>';
  237. }
  238. endif;
  239.  
  240. if($mantra_breadcrumbs=="Enable") add_action ('cryout_breadcrumbs_hook','mantra_breadcrumbs');
  241.  
  242.  
  243. if ( ! function_exists( 'mantra_pagination' ) ) :
  244. /**
  245. * Creates pagination for blog pages.
  246. */
  247. function mantra_pagination($pages = '', $range = 2, $prefix ='')
  248. {
  249. $showitems = ($range * 2)+1;
  250.  
  251. global $paged;
  252. if(empty($paged)) $paged = 1;
  253.  
  254. if($pages == '')
  255. {
  256. global $wp_query;
  257. $pages = $wp_query->max_num_pages;
  258. if(!$pages)
  259. {
  260. $pages = 1;
  261. }
  262. }
  263.  
  264. if(1 != $pages)
  265. {
  266. echo "<div class='pagination_container'><nav class='pagination'>";
  267. if ($prefix) {echo "<span id='paginationPrefix'>$prefix </span>";}
  268. if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>&laquo;</a>";
  269. if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo;</a>";
  270.  
  271. for ($i=1; $i <= $pages; $i++)
  272. {
  273. if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
  274. {
  275. echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
  276. }
  277. }
  278.  
  279. if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>&rsaquo;</a>";
  280. if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>&raquo;</a>";
  281. echo "</nav></div>\n";
  282. }
  283. }
  284. endif;
  285.  
  286. if ( ! function_exists( 'mantra_site_info' ) ) :
  287. /**
  288. * Site info
  289. */
  290. function mantra_site_info() {
  291. $mantra_options= mantra_get_theme_options();
  292. foreach ($mantra_options as $key => $value) {
  293. ${"$key"} = $value ;
  294. } //delete_transient( 'cryout_theme_info');
  295. $mantra_theme_data = get_transient( 'cryout_theme_info');
  296. ?>
  297. <div id="site-info" >
  298. <a href="<?php echo home_url( '/' ) ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
  299. <?php bloginfo( 'name' ); ?></a> | Theme by <a href="<?php echo $mantra_theme_data['Author URI']?>" title="<?php echo $mantra_theme_data['Name'].
  300. ' by '.strip_tags($mantra_theme_data->Author);?>"> <?php echo $mantra_theme_data['Name'] ?>
  301.  
  302. </a>
  303. </div><!-- #site-info -->
  304. <?php }
  305. endif;
  306.  
  307. add_action('cryout_footer_hook','mantra_site_info',11);
  308.  
  309. if ( ! function_exists( 'mantra_copyright' ) ) :
  310. /**
  311. * Copyright text
  312. */
  313. function mantra_copyright() {
  314. $mantra_options= mantra_get_theme_options();
  315. foreach ($mantra_options as $key => $value) {
  316. ${"$key"} = $value ;
  317. }
  318. echo '<div id="site-copyright">'.$mantra_copyright.'</div>';
  319. }
  320. endif;
  321.  
  322. if ($mantra_copyright != '') add_action('cryout_footer_hook','mantra_copyright',12);
  323.  
  324. add_action('wp_ajax_nopriv_do_ajax', 'mantra_ajax_function');
  325. add_action('wp_ajax_do_ajax', 'mantra_ajax_function');
  326.  
  327. if ( ! function_exists( 'mantra_ajax_function' ) ) :
  328.  
  329. function mantra_ajax_function(){
  330. ob_clean();
  331.  
  332. // the first part is a SWTICHBOARD that fires specific functions
  333. // according to the value of Query Var 'fn'
  334.  
  335. switch($_REQUEST['fn']){
  336. case 'get_latest_posts':
  337. $output = mantra_ajax_get_latest_posts($_REQUEST['count'],$_REQUEST['categName']);
  338. break;
  339. default:
  340. $output = 'No function specified, check your jQuery.ajax() call';
  341. break;
  342.  
  343. }
  344.  
  345. // at this point, $output contains some sort of valuable data!
  346. // Now, convert $output to JSON and echo it to the browser
  347. // That way, we can recapture it with jQuery and run our success function
  348.  
  349. $output=json_encode($output);
  350. if(is_array($output)){
  351. print_r($output);
  352. }
  353. else{
  354. echo $output;
  355. }
  356. die;
  357. }
  358. endif;
  359.  
  360. if ( ! function_exists( 'mantra_ajax_get_latest_posts' ) ) :
  361. function mantra_ajax_get_latest_posts($count,$categName){
  362. $testVar='';
  363. // The Query
  364. query_posts( 'category_name='.$categName);
  365. // The Loop
  366. if ( have_posts() ) : while ( have_posts() ) : the_post();
  367. $testVar .=the_title("<option>","</option>",0);
  368. endwhile; else: endif;
  369.  
  370. // Reset Query
  371. wp_reset_query();
  372.  
  373. return $testVar;
  374. }
  375. endif;
  376. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement