web/wp-content/plugins/wptouch/themes/default/functions.php
changeset 136 bde1974c263b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php 
       
     2 include( dirname(__FILE__) . '/../core/core-functions.php' ); 
       
     3 
       
     4 //---------------- Custom Drop-Down Tags Function ----------------// 
       
     5 //  function dropdown_tag_cloud( $args = '' ) {
       
     6 //  	$defaults = array(
       
     7 //  		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
       
     8 //  		'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC',
       
     9 //  		'exclude' => '', 'include' => ''
       
    10 //  	);
       
    11 //  	$args = wp_parse_args( $args, $defaults );
       
    12 //  
       
    13 //  	$tags = get_tags( array_merge($args, array('orderby' => 'count', 'order' => 'DESC')) ); // Always query top tags
       
    14 //  
       
    15 //  	if ( empty($tags) )
       
    16 //  		return;
       
    17 //  
       
    18 //  	$return = core_header_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
       
    19 //  	if ( is_wp_error( $return ) )
       
    20 //  		return false;
       
    21 //  	else
       
    22 //  		echo apply_filters( 'dropdown_tag_cloud', $return, $args );
       
    23 //  }
       
    24 //  
       
    25 //  function core_header_tag_cloud( $tags, $args = '' ) {
       
    26 //  	global $wp_rewrite;
       
    27 //  	$defaults = array(
       
    28 //  		'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
       
    29 //  		'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC'
       
    30 //  	);
       
    31 //  	$args = wp_parse_args( $args, $defaults );
       
    32 //  	extract($args);
       
    33 //  
       
    34 //  	if ( !$tags )
       
    35 //  		return;
       
    36 //  	$counts = $tag_links = array();
       
    37 //  	foreach ( (array) $tags as $tag ) {
       
    38 //  		$counts[$tag->name] = $tag->count;
       
    39 //  		$tag_links[$tag->name] = get_tag_link( $tag->term_id );
       
    40 //  		if ( is_wp_error( $tag_links[$tag->name] ) )
       
    41 //  			return $tag_links[$tag->name];
       
    42 //  		$tag_ids[$tag->name] = $tag->term_id;
       
    43 //  	}
       
    44 //  
       
    45 //  	$min_count = min($counts);
       
    46 //  	$spread = max($counts) - $min_count;
       
    47 //  	if ( $spread <= 0 )
       
    48 //  		$spread = 1;
       
    49 //  	$font_spread = $largest - $smallest;
       
    50 //  	if ( $font_spread <= 0 )
       
    51 //  		$font_spread = 1;
       
    52 //  	$font_step = $font_spread / $spread;
       
    53 //  
       
    54 //  	// SQL cannot save you; this is a second (potentially different) sort on a subset of data.
       
    55 //  	if ( 'name' == $orderby )
       
    56 //  		uksort($counts, 'strnatcasecmp');
       
    57 //  	else
       
    58 //  		asort($counts);
       
    59 //  
       
    60 //  	if ( 'DESC' == $order )
       
    61 //  		$counts = array_reverse( $counts, true );
       
    62 //  
       
    63 //  	$a = array();
       
    64 //  
       
    65 //  	$rel = ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) ? ' rel="tag"' : '';
       
    66 //  
       
    67 //  	foreach ( $counts as $tag => $count ) {
       
    68 //  		$tag_id = $tag_ids[$tag];
       
    69 //  		$tag_link = clean_url($tag_links[$tag]);
       
    70 //  		$tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
       
    71 //  		$a[] = "\t<option value='$tag_link'>$tag ($count)</option>";
       
    72 //  	}
       
    73 //  
       
    74 //  	switch ( $format ) :
       
    75 //  	case 'array' :
       
    76 //  		$return =& $a;
       
    77 //  		break;
       
    78 //  	case 'list' :
       
    79 //  		$return = "<ul class='wp-tag-cloud'>\n\t<li>";
       
    80 //  		$return .= join("</li>\n\t<li>", $a);
       
    81 //  		$return .= "</li>\n</ul>\n";
       
    82 //  		break;
       
    83 //  	default :
       
    84 //  		$return = join("\n", $a);
       
    85 //  		break;
       
    86 //  	endswitch;
       
    87 //  
       
    88 //  	return apply_filters( 'core_header_tag_cloud', $return, $tags, $args );
       
    89 //  }
       
    90 
       
    91 //---------------- Custom Exclude Cats Function ----------------//
       
    92 function exclude_category($query) {
       
    93 	$cats = wptouch_excluded_cats();
       
    94 	$icats = explode( ",", $cats );
       
    95 	$new_cats = array();
       
    96 	foreach( $icats as $icat ) {
       
    97 		$new_cats[] = "-" . $icat;
       
    98 }
       
    99 	$cats = implode( ",",  $new_cats );
       
   100 	
       
   101 	if ( $query->is_home ) {
       
   102 	$query->set('cat', $cats);
       
   103 	}
       
   104 return $query;
       
   105 }
       
   106 
       
   107 add_filter('pre_get_posts', 'exclude_category');
       
   108 
       
   109 
       
   110 //---------------- Custom Excerpts Function ----------------//
       
   111 function wptouch_trim_excerpt($text) {
       
   112 	$raw_excerpt = $text;
       
   113 	if ( '' == $text ) {
       
   114 		$text = get_the_content('');
       
   115 		$text = strip_shortcodes( $text );
       
   116 		$text = apply_filters('the_content', $text);
       
   117 		$text = str_replace(']]>', ']]&gt;', $text);
       
   118 		$text = strip_tags($text);
       
   119 		$excerpt_length = apply_filters('excerpt_length', 30);
       
   120 		$words = explode(' ', $text, $excerpt_length + 1);
       
   121 		if (count($words) > $excerpt_length) {
       
   122 			array_pop($words);
       
   123 			array_push($words, '...');
       
   124 			$text = implode(' ', $words);
       
   125 			$text = force_balance_tags( $text );
       
   126 		}
       
   127 	}
       
   128 	return apply_filters('wptouch_trim_excerpt', $text, $raw_excerpt);
       
   129 }
       
   130 
       
   131 
       
   132 //---------------- Custom Time Since Function ----------------//
       
   133 
       
   134 function time_since($older_date, $newer_date = false)
       
   135 	{
       
   136 	// array of time period chunks
       
   137 	$chunks = array(
       
   138 //	array(60 * 60 * 24 * 365 , 'yr'),
       
   139 	array(60 * 60 * 24 * 30 , 'mo'),
       
   140 	array(60 * 60 * 24 * 7, 'wk'),
       
   141 	array(60 * 60 * 24 , 'day'),
       
   142 	array(60 * 60 , 'hr'),
       
   143 	array(60 , 'min'),
       
   144 	);
       
   145 	
       
   146 	// $newer_date will equal false if we want to know the time elapsed between a date and the current time
       
   147 	// $newer_date will have a value if we want to work out time elapsed between two known dates
       
   148 	$newer_date = ($newer_date == false) ? (time()+(60*60*get_settings("gmt_offset"))) : $newer_date;
       
   149 	
       
   150 	// difference in seconds
       
   151 	$since = $newer_date - $older_date;
       
   152 	
       
   153 	// we only want to output two chunks of time here, eg:
       
   154 	// x years, xx months
       
   155 	// x days, xx hours
       
   156 	// so there's only two bits of calculation below:
       
   157 
       
   158 	// step one: the first chunk
       
   159 	for ($i = 0, $j = count($chunks); $i < $j; $i++)
       
   160 		{
       
   161 		$seconds = $chunks[$i][0];
       
   162 		$name = $chunks[$i][1];
       
   163 
       
   164 		// finding the biggest chunk (if the chunk fits, break)
       
   165 		if (($count = floor($since / $seconds)) != 0)
       
   166 			{
       
   167 			break;
       
   168 			}
       
   169 		}
       
   170 
       
   171 	// set output var
       
   172 	$output = ($count == 1) ? '1 '.$name : "$count {$name}s";
       
   173 
       
   174 	// step two: the second chunk
       
   175 	if ($i + 1 < $j)
       
   176 		{
       
   177 		$seconds2 = $chunks[$i + 1][0];
       
   178 		$name2 = $chunks[$i + 1][1];
       
   179 		
       
   180 		if (($count2 = floor(($since - ($seconds * $count)) / $seconds2)) != 0)
       
   181 			{
       
   182 			// add to output var
       
   183 			$output .= ($count2 == 1) ? ', 1 '.$name2 : ", $count2 {$name2}s";
       
   184 			}
       
   185 		}
       
   186 	
       
   187 	return $output;
       
   188 	}
       
   189 
       
   190 remove_filter('get_the_excerpt', 'wp_trim_excerpt');
       
   191 add_filter('get_the_excerpt', 'wptouch_trim_excerpt');
       
   192 ?>