Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Pure Line Basic Functions

By: a guest on Jan 27th, 2013  |  syntax: PHP  |  size: 11.42 KB  |  views: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. add_theme_support( 'automatic-feed-links' );
  3. add_theme_support( 'post-thumbnails' );
  4. set_post_thumbnail_size( 220, 100, true );
  5. add_editor_style('editor-style.css');
  6.  
  7. define( 'HEADER_TEXTCOLOR', '' );
  8.  
  9.  
  10. define( 'NO_HEADER_TEXT', true );
  11.  
  12.  
  13. if ( pureline_is_wp_version( '3.4' ) ) {  
  14.               add_theme_support( 'custom-header' );
  15.         } else {
  16.         add_custom_image_header( '', 'pureline_admin_header_style' ); }
  17.  
  18. function pureline_admin_header_style() {}
  19.  
  20. define( 'HEADER_IMAGE_WIDTH', apply_filters( 'pureline_header_image_width', 990 ) );
  21. define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'pureline_header_image_height', 170 ) );
  22.  
  23. // checks is WP is at least a certain version (makes sure it has sufficient comparison decimals
  24.         function pureline_is_wp_version( $is_ver ) {  
  25.                 $wp_ver = explode( '.', get_bloginfo( 'version' ) );
  26.                 $is_ver = explode( '.', $is_ver );
  27.                 for( $i = 0; $i; )  if ( !isset( $wp_ver[$i] ) ) array_push( $wp_ver, 0 );  
  28.                  
  29.         foreach( $is_ver as $i => $is_val )
  30.         if( $wp_ver[$i] < $is_val ) return false;
  31.         return true;  
  32.                 }
  33.  
  34. $purelineoptions = get_option('pureline');
  35.  
  36. $pureline_layout = pureline_get_option('pureline_layout','2cl');
  37. $pureline_width_layout = pureline_get_option('pureline_width_layout','fixed');
  38.  
  39.  
  40. if ( ($pureline_layout == "2cl" || $pureline_layout == "2cr" ) && $pureline_width_layout == "fixed") {
  41. if ( ! isset( $content_width ) )
  42.         $content_width = 620;
  43. }
  44. if ( ( ($pureline_layout == "3cl" || $pureline_layout == "3cr" ) && $pureline_width_layout == "fixed") ||
  45. ( ($pureline_layout == "3cm" ) && $pureline_width_layout == "fixed")
  46. ) {
  47. if ( ! isset( $content_width ) )
  48.         $content_width = 506;
  49. }
  50. if ( $pureline_width_layout == "fixed" && $pureline_layout == "1c" ) {
  51. if ( ! isset( $content_width ) )
  52.         $content_width = 960;
  53. }
  54. if ( $pureline_width_layout == "fluid" ) {
  55. if ( ! isset( $content_width ) )
  56.         $content_width = 700;
  57. }
  58. else {
  59. if ( ! isset( $content_width ) )
  60.         $content_width = 620;
  61. }
  62.  
  63.         load_theme_textdomain( 'pure-line', get_template_directory() . '/languages' );
  64.         $locale = get_locale();
  65.         $locale_file = get_template_directory() . "/languages/$locale.php";
  66.         if ( is_readable( $locale_file ) )
  67.                 require_once( $locale_file );
  68.    
  69.    
  70. /**
  71.  * Functions - pureline gatekeeper
  72.  *
  73.  * This file defines a few constants variables, loads up the core pureline file,
  74.  * and finally initialises the main WP pureline Class.
  75.  *
  76.  * @package pureline
  77.  * @subpackage Functions
  78.  */
  79.  
  80. define( 'WP_pureline', '0.2.4' ); // Defines current version for WP pureline
  81.        
  82.         /* Blast you red baron! Initialise WP pureline */
  83.         require_once( get_template_directory() . '/library/pureline.php' );
  84.         WPpureline::pureline_init();
  85.  
  86.  
  87.  
  88. /* pureline_truncate */
  89.  
  90. function pureline_truncate ($str, $length=10, $trailing='..')
  91. {
  92.  $length-=mb_strlen($trailing);
  93.  if (mb_strlen($str)> $length)
  94.           {
  95.  return mb_substr($str,0,$length).$trailing;
  96.   }
  97.  else
  98.   {
  99.  $res = $str;
  100.   }
  101.  return $res;
  102. }
  103.  
  104.  
  105. /* Get first image */
  106.  
  107. function pureline_get_first_image() {
  108.  global $post, $posts;
  109.  $first_img = '';
  110.  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  111.  if(isset($matches[1][0])){
  112.  $first_img = $matches [1][0];
  113.  return $first_img;
  114.  }  
  115. }  
  116.  
  117.  
  118. /* Custom Menu */  
  119.  
  120. add_action( 'after_setup_theme', 'pureline_register_my_menu' );
  121.  
  122. function pureline_register_my_menu() {
  123.         register_nav_menu( 'primary-menu', __( 'Primary Menu', 'pure-line' ) );
  124. }    
  125.  
  126.  
  127.  
  128. // Tiny URL
  129.  
  130. function pureline_tinyurl($url) {
  131.     $response = esc_url(wp_remote_retrieve_body(wp_remote_get('http://tinyurl.com/api-create.php?url='.$url)));
  132.     return $response;
  133. }
  134.  
  135.  
  136. // Similar Posts
  137.  
  138. function pureline_similar_posts() {
  139.  
  140. $post = '';
  141. $orig_post = $post;
  142. global $post;
  143.  
  144. $pureline_options = get_option('pureline'); if ($pureline_options['pureline_similar_posts'] == "category") {
  145. $matchby = get_the_category($post->ID);
  146. $matchin = 'category';
  147. } else {
  148. $matchby = wp_get_post_tags($post->ID);
  149. $matchin = 'tag'; }
  150.  
  151.  
  152. if ($matchby) {
  153.         $matchby_ids = array();
  154.         foreach($matchby as $individual_matchby) $matchby_ids[] = $individual_matchby->term_id;
  155.  
  156.         $args=array(
  157.                 $matchin.'__in' => $matchby_ids,
  158.                 'post__not_in' => array($post->ID),
  159.                 'showposts'=>5, // Number of related posts that will be shown.
  160.                 'ignore_sticky_posts'=>1
  161.         );  
  162.  
  163.         $my_query = new wp_query($args);
  164.         if( $my_query->have_posts() ) {
  165. _e( '<div class="similar-posts"><h5>Similar posts</h5><ul>', 'pure-line' );
  166.                 while ($my_query->have_posts()) {
  167.                         $my_query->the_post();
  168.                 ?>
  169.                         <li>
  170.      
  171.      <a class="similar-title" href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
  172. <?php
  173.  
  174. if ( get_the_title() ){ $title = the_title('', '', false);
  175. echo pureline_truncate($title, 40, '...'); } else { echo __('Untitled', 'pure-line' ); }
  176.  
  177.  
  178.  ?></a>
  179.  
  180.  
  181.      
  182.       </li>
  183.                 <?php
  184.                 }
  185.                 echo '</ul></div>';
  186.         }
  187. }
  188. $post = $orig_post;
  189. wp_reset_query();  
  190.  
  191. }
  192.  
  193.  
  194. function pureline_footer_hooks() { ?>
  195.  
  196.  <script type="text/javascript" charset="utf-8">      
  197.       var $zoom = jQuery.noConflict();
  198.     $zoom(function() {
  199. // OPACITY OF BUTTON SET TO 0%
  200. $zoom(".roll").css("opacity","0");
  201.  
  202. // ON MOUSE OVER
  203. $zoom(".roll").hover(function () {
  204.  
  205. // SET OPACITY TO 70%
  206. $zoom(this).stop().animate({
  207. opacity: 1
  208. }, "fast");
  209. },
  210.  
  211. // ON MOUSE OUT
  212. function () {
  213.  
  214. // SET OPACITY BACK TO 50%
  215. $zoom(this).stop().animate({
  216. opacity: 0
  217. }, "fast");
  218. });
  219. });
  220.       $zoom ('.post-thumbnail').append('<span class="roll"></span>');
  221. </script>
  222.  
  223.  
  224. <script type="text/javascript" charset="utf-8">
  225. var $jx = jQuery.noConflict();
  226.   $jx("div.post").mouseover(function() {
  227.     $jx(this).find("span.edit-post").css('visibility', 'visible');
  228.   }).mouseout(function(){
  229.     $jx(this).find("span.edit-post").css('visibility', 'hidden');
  230.   });
  231.  
  232.     $jx("div.type-page").mouseover(function() {
  233.     $jx(this).find("span.edit-page").css('visibility', 'visible');
  234.   }).mouseout(function(){
  235.     $jx(this).find("span.edit-page").css('visibility', 'hidden');
  236.   });
  237.  
  238.       $jx("div.type-attachment").mouseover(function() {
  239.     $jx(this).find("span.edit-post").css('visibility', 'visible');
  240.   }).mouseout(function(){
  241.     $jx(this).find("span.edit-post").css('visibility', 'hidden');
  242.   });
  243.  
  244.   $jx("li.comment").mouseover(function() {
  245.     $jx(this).find("span.edit-comment").css('visibility', 'visible');
  246.   }).mouseout(function(){
  247.     //$jx(this).find("span.edit-comment").css('visibility', 'hidden');
  248.   });
  249. </script>
  250.  
  251. <script type="text/javascript" charset="utf-8">
  252. var $j = jQuery.noConflict();
  253.   $j(document).ready(function(){  
  254.     $j('.tipsytext').tipsy({gravity:'n',fade:true,offset:5,opacity:1});
  255.    });
  256.    </script>
  257.  
  258. <?php echo pureline_copy(); }
  259.        
  260.  
  261. /* Redirect after activation */
  262.  
  263. if ( is_admin() && isset($_GET['activated'] ) && $pagenow ==    "themes.php" )
  264.         wp_redirect( 'themes.php?page=theme_options' );
  265.  
  266. $pureline_custom_background = pureline_get_option('pureline_custom_background','0');
  267.  
  268. if ($pureline_custom_background == "1") {
  269.  
  270. // This theme allows users to set a custom background
  271. add_theme_support('custom-background');
  272.  
  273. }  
  274.  
  275. function pureline_filter_wp_title( $title ) {
  276.    
  277.     global $page, $paged;
  278.    
  279.     // Get the Site Name
  280.     $site_name = get_bloginfo( 'name' );
  281.     // Prepend name
  282.     $filtered_title = $site_name . $title;
  283.     // Get the Site Description
  284.         $site_description = get_bloginfo( 'description' );
  285.     // If site front page, append description
  286.     if ( $site_description && ( is_home() || is_front_page() ) ) {
  287.         // Append Site Description to title
  288.         $filtered_title .= ' - ' .$site_description;
  289.        
  290.     }
  291.     if ( $paged >= 2 || $page >= 2 ) {
  292.         $filtered_title .= ' - ' . sprintf( __( 'Page %s', 'pure-line' ), max( $paged, $page ) );
  293.         }
  294.     // Return the modified title
  295.     return $filtered_title;
  296. }
  297. // Hook into 'wp_title'
  298. add_filter( 'wp_title', 'pureline_filter_wp_title' );
  299.  
  300.  
  301. function pureline_enqueue_comment_reply() {
  302.         if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  303.                 wp_enqueue_script( 'comment-reply' );
  304.         }
  305.     }
  306.     add_action( 'wp_enqueue_scripts', 'pureline_enqueue_comment_reply' );
  307.  
  308.  
  309.  // Share This Buttons
  310.  
  311. function pureline_sharethis() { ?>
  312.     <div class="share-this tipsytext" original-title="<?php echo __('Share This','pure-line');?>">
  313.           <img class="share-img" src="<?php echo get_template_directory_uri(); ?>/library/media/images/share.png" width="14" height="20" />
  314.           <a rel="nofollow" target="_blank" class="share-twitter" href="http://twitter.com/intent/tweet?status=<?php the_title_attribute(); ?>+&raquo;+<?php echo esc_url(pureline_tinyurl(get_permalink())); ?>">Twitter</a>
  315.           &bull; <a rel="nofollow" target="_blank" class="share-facebook" href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>&amp;t=<?php the_title_attribute(); ?>">Facebook</a>
  316.           &bull; <a rel="nofollow" target="_blank" class="share-delicious" href="http://del.icio.us/post?url=<?php the_permalink(); ?>&amp;title=<?php the_title_attribute(); ?>">Delicious</a>
  317.           &bull; <a rel="nofollow" target="_blank" class="share-stumble" href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&amp;title=<?php the_title_attribute(); ?>">StumbleUpon</a>
  318.           &bull; <a rel="nofollow" target="_blank" class="share-email" href="http://www.addtoany.com/email?linkurl=<?php the_permalink(); ?>&linkname=<?php the_title_attribute(); ?>"><?php _e( 'E-mail', 'pure-line' ); ?></a>
  319.           <a rel="nofollow" class="tipsytext more-options" title="<?php _e( 'More options', 'pure-line' ); ?>" target="_blank" href="http://www.addtoany.com/share_save#url=<?php the_permalink(); ?>&linkname=<?php the_title_attribute(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/library/media/images/share-more.png" /></a>
  320.           </div>
  321. <?php }
  322.  
  323. function t4p_more_themes() { ?>
  324.         <div class="wrap">
  325.         <h2>Theme4Press Themes</h2>
  326.   <?php include_once(ABSPATH . WPINC . '/feed.php' );
  327.                 $rss = fetch_feed( 'http://www.theme4press.com/feed' );
  328.           $output = '';
  329.                 // If the RSS is failed somehow.
  330.                 if ( is_wp_error($rss) ) {
  331.                     $error = $rss->get_error_code();
  332.                     echo "<div class='updated fade'><p>An error has occured with the RSS feed. (<code>". $error ."</code>)</p></div>";
  333.                
  334.                     return;
  335.                  }
  336.                $output .= '<div class="info"><a href="http://theme4press.com/tag/free/">FREE Themes</a><a href="http://theme4press.com/tag/premium/">Premium Themes</a></div>';
  337.  
  338.                
  339.  
  340.                 $maxitems = $rss->get_item_quantity(10);
  341.                 $items = $rss->get_items(0, 10);
  342.  
  343.                
  344.                 $output .= '<ul class="themes">';
  345.                 if (empty($items)) $output .= '<li>No items</li>';
  346.                 else
  347.                 foreach ( $items as $item ) :
  348.                   $output .= '<li class="theme"><div><h2><a href="'.$item->get_permalink().'">'.$item->get_title().'</a></h2>';
  349.              
  350.              $output .= $item->get_description();
  351.                  
  352.               $output .= '<br /><a class="view-theme" href="'.$item->get_permalink().'">VIEW THEME</a>';  
  353.                  
  354.               $output .= '</div></li>';
  355.              
  356.                
  357.                 endforeach;
  358.                 $output .= '</ul>';  
  359.          
  360.           echo $output;
  361.  
  362. ?></div><?php } ?>
clone this paste RAW Paste Data