View difference between Paste ID: MgNu873z and
SHOW: | | - or go back to the newest paste.
1-
1+
<?php
2
/**
3
*	Custom function to get current URL
4
**/
5
function curPageURL() {
6
 	$pageURL = 'http';
7
 	if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
8
 	$pageURL .= "://";
9
 	if ($_SERVER["SERVER_PORT"] != "80") {
10
 	 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
11
 	} else {
12
 	 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
13
 	}
14
 	return $pageURL;
15
}
16
    
17
function pp_debug($arr)
18
{
19
	echo '<pre>';
20
	print_r($arr);
21
	echo '</pre>';
22
}
23
24
function gen_pagination($total,$currentPage,$baseLink,$nextPrev=true,$limit=10) 
25
{ 
26
    if(!$total OR !$currentPage OR !$baseLink) 
27
    { 
28
        return false; 
29
    } 
30
31
    //Total Number of pages 
32
    $totalPages = ceil($total/$limit); 
33
     
34
    //Text to use after number of pages 
35
    //$txtPagesAfter = ($totalPages==1)? " page": " pages"; 
36
     
37
    //Start off the list. 
38
    //$txtPageList = '<br />'.$totalPages.$txtPagesAfter.' : <br />'; 
39
     
40
    //Show only 3 pages before current page(so that we don't have too many pages) 
41
    $min = ($page - 3 < $totalPages && $currentPage-3 > 0) ? $currentPage-3 : 1; 
42
     
43
    //Show only 3 pages after current page(so that we don't have too many pages) 
44
    $max = ($page + 3 > $totalPages) ? $totalPages : $currentPage+3; 
45
     
46
    //Variable for the actual page links 
47
    $pageLinks = ""; 
48
    
49
    $baseLinkArr = parse_url($baseLink);
50
    $start = '';
51
    
52
    if(isset($baseLinkArr['query']) && !empty($baseLinkArr['query']))
53
    {
54
    	$start = '&';
55
    }
56
    else
57
    {
58
    	$start = '?';
59
    }
60
     
61
    //Loop to generate the page links 
62
    for($i=$min;$i<=$max;$i++) 
63
    { 
64
        if($currentPage==$i) 
65
        { 
66
            //Current Page 
67
            $pageLinks .= '<a href="#" class="active">'.$i.'</a>';  
68
        } 
69
        elseif($max <= $totalPages OR $i <= $totalPages) 
70
        { 
71
            $pageLinks .= '<a href="'.$baseLink.$start.'page='.$i.'" class="slide">'.$i.'</a>'; 
72
        } 
73
    } 
74
     
75
    if($nextPrev) 
76
    { 
77
        //Next and previous links 
78
        $next = ($currentPage + 1 > $totalPages) ? false : '<a href="'.$baseLink.$start.'page='.($currentPage + 1).'" class="slide">Next</a>'; 
79
         
80
        $prev = ($currentPage - 1 <= 0 ) ? false : '<a href="'.$baseLink.$start.'page='.($currentPage - 1).'" class="slide">Previous</a>'; 
81
    } 
82
     
83
    if($totalPages > 1)
84
    {
85
    	return '<br class="clear"/><div class="pagination">'.$txtPageList.$prev.$pageLinks.$next.'</div>'; 
86
    }
87
    else
88
    {
89
    	return '';
90
    }
91
     
92
} 
93
94
function count_shortcode($content = '')
95
{
96
	$return = array();
97
	
98
	if(!empty($content))
99
	{
100
		$pattern = get_shortcode_regex();
101
    	$count = preg_match_all('/'.$pattern.'/s', $content, $matches);
102
    	
103
    	$return['total'] = $count;
104
    	
105
    	if(isset($matches[0]))
106
    	{
107
    		foreach($matches[0] as $match)
108
    		{
109
    			$return['content'][] = substr_replace($match ,"",-1);
110
    		}
111
    	}
112
	}
113
	
114
	return $return;
115
}
116
117
function pp_breadcrumbs() {
118
 
119
  $delimiter = '&raquo;';
120
  $name = get_bloginfo('name'); //text for the 'Home' link
121
  $currentBefore = '<span class="current">';
122
  $currentAfter = '</span>';
123
 
124
  if ( !is_home() && !is_front_page() || is_paged() ) {
125
 
126
    echo '<div id="crumbs">';
127
 
128
    global $post;
129
    $home = get_bloginfo('url');
130
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';
131
 
132
    if ( is_category() ) {
133
      global $wp_query;
134
      $cat_obj = $wp_query->get_queried_object();
135
      $thisCat = $cat_obj->term_id;
136
      $thisCat = get_category($thisCat);
137
      $parentCat = get_category($thisCat->parent);
138
      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
139
      echo $currentBefore . 'Archive by category &#39;';
140
      single_cat_title();
141
      echo '&#39;' . $currentAfter;
142
 
143
    } elseif ( is_day() ) {
144
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
145
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
146
      echo $currentBefore . get_the_time('d') . $currentAfter;
147
 
148
    } elseif ( is_month() ) {
149
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
150
      echo $currentBefore . get_the_time('F') . $currentAfter;
151
 
152
    } elseif ( is_year() ) {
153
      echo $currentBefore . get_the_time('Y') . $currentAfter;
154
 
155
    } elseif ( is_single() && !is_attachment() ) {
156
      $cat = get_the_category(); $cat = $cat[0];
157
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
158
      echo $currentBefore;
159
      the_title();
160
      echo $currentAfter;
161
 
162
    } elseif ( is_attachment() ) {
163
      $parent = get_post($post->post_parent);
164
      $cat = get_the_category($parent->ID); $cat = $cat[0];
165
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
166
      echo '<a href="' . get_permalink($parent) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
167
      echo $currentBefore;
168
      the_title();
169
      echo $currentAfter;
170
 
171
    } elseif ( is_page() && !$post->post_parent ) {
172
      echo $currentBefore;
173
      the_title();
174
      echo $currentAfter;
175
 
176
    } elseif ( is_page() && $post->post_parent ) {
177
      $parent_id  = $post->post_parent;
178
      $breadcrumbs = array();
179
      while ($parent_id) {
180
        $page = get_page($parent_id);
181
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
182
        $parent_id  = $page->post_parent;
183
      }
184
      $breadcrumbs = array_reverse($breadcrumbs);
185
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
186
      echo $currentBefore;
187
      the_title();
188
      echo $currentAfter;
189
 
190
    } elseif ( is_search() ) {
191
      echo $currentBefore . 'Search results for &#39;' . get_search_query() . '&#39;' . $currentAfter;
192
 
193
    } elseif ( is_tag() ) {
194
      echo $currentBefore . 'Posts tagged &#39;';
195
      single_tag_title();
196
      echo '&#39;' . $currentAfter;
197
 
198
    } elseif ( is_author() ) {
199
       global $author;
200
      $userdata = get_userdata($author);
201
      echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;
202
 
203
    } elseif ( is_404() ) {
204
      echo $currentBefore . 'Error 404' . $currentAfter;
205
    }
206
 
207
    if ( get_query_var('paged') ) {
208
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
209
      echo __('Page') . ' ' . get_query_var('paged');
210
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
211
    }
212
 
213
    echo '</div>';
214
 
215
  }
216
}
217
    
218
/**
219
*	Setup blog comment style
220
**/
221
function pp_comment($comment, $args, $depth) 
222
{
223
	$GLOBALS['comment'] = $comment; ?>
224
   
225
	<div class="comment" id="comment-<?php comment_ID() ?>">
226
		<div class="left">
227
         	<?php echo get_avatar($comment,$size='50',$default='<path_to_url>' ); ?>
228
      	</div>
229
      
230
231
      	<div class="right">
232
			<?php if ($comment->comment_approved == '0') : ?>
233
         		<em><?php _e('(Your comment is awaiting moderation.)') ?></em>
234
         		<br />
235
      		<?php endif; ?>
236
			
237
			<strong><i><?php printf(__('By %1$s on %2$s at %3$s'),
238
					get_comment_author_link(),
239
					get_comment_date('d M Y'),
240
					get_comment_time('g:i a')); ?></i></strong>
241
      		<?php ' '.comment_text() ?>
242
      		<p class="comment-reply-link"><?php comment_reply_link(array_merge( $args, array('depth' => $depth,
243
'reply_text' => '
244
Reply', 'login_text' => 'Log in to reply to this', 'max_depth' => $args['max_depth']))) ?></p>
245
246
      	</div>
247
    </div>
248
<?php
249
}
250
251
function pp_ago($timestamp){
252
   $difference = time() - $timestamp;
253
   $periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
254
   $lengths = array("60","60","24","7","4.35","12","10");
255
   for($j = 0; $difference >= $lengths[$j]; $j++)
256
   $difference /= $lengths[$j];
257
   $difference = round($difference);
258
   if($difference != 1) $periods[$j].= "s";
259
   $text = "$difference $periods[$j] ago";
260
   return $text;
261
}
262
263
264
// Substring without losing word meaning and
265
// tiny words (length 3 by default) are included on the result.
266
// "..." is added if result do not reach original string length
267
268
function pp_substr($str, $length, $minword = 3)
269
{
270
    $sub = '';
271
    $len = 0;
272
    
273
    foreach (explode(' ', $str) as $word)
274
    {
275
        $part = (($sub != '') ? ' ' : '') . $word;
276
        $sub .= $part;
277
        $len += strlen($part);
278
        
279
        if (strlen($word) > $minword && strlen($sub) >= $length)
280
        {
281
            break;
282
        }
283
    }
284
    
285
    return $sub . (($len < strlen($str)) ? '...' : '');
286
}
287
288
289
/**
290
*	Setup recent posts widget
291
**/
292
function pp_posts($sort = 'recent', $items = 3, $echo = TRUE, $bg_color = 'black' , $echo_title = TRUE) 
293
{
294
	$return_html = '';
295
	
296
	if($sort == 'recent')
297
	{
298
		$posts = get_posts('numberposts='.$items.'&order=DESC&orderby=date&post_type=post&post_status=publish');
299
		$title = 'Recent Posts';
300
	}
301
	else
302
	{
303
		global $wpdb;
304
		
305
		$query = "SELECT ID, post_title, post_content FROM {$wpdb->prefix}posts WHERE post_type = 'post' AND post_status= 'publish' ORDER BY comment_count DESC LIMIT 0,".$items;
306
		$posts = $wpdb->get_results($query);
307
		$title = 'Popular Posts'; 
308
	}
309
	
310
	if(!empty($posts))
311
	{
312
		if($echo_title)
313
		{
314
			$return_html.= '<h2 class="widgettitle">'.$title.'</h2>';
315
		}
316
		
317
		$return_html.= '<ul class="posts blog '.$bg_color.'_wrapper">';
318
319
			foreach($posts as $post)
320
			{
321
				$image_thumb = '';
322
								
323
				if(has_post_thumbnail($post->ID, 'large'))
324
				{
325
				    $image_id = get_post_thumbnail_id($post->ID);
326
				    $image_thumb = wp_get_attachment_image_src($image_id, 'large', true);
327
				}
328
				
329
				$return_html.= '<li>';
330
				
331
				if(!empty($image_thumb))
332
				{
333
					$return_html.= '<a href="'.get_permalink($post->ID).'"><img src="'.get_bloginfo( 'stylesheet_directory' ).'/timthumb.php?src='.$image_thumb[0].'&h=75&w=75&zc=1" alt="" class="frame" /></a>';
334
				}
335
				$return_html.= '<strong class="header"><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></strong><br/>';
336
				$return_html.= pp_substr(strip_tags(strip_shortcodes($post->post_content)), 80).'</li>';
337
338
			}	
339
340
		$return_html.= '</ul>';
341
342
	}
343
	
344
	if($echo)
345
	{
346
		echo $return_html;
347
	}
348
	else
349
	{
350
		return $return_html;
351
	}
352
}
353
354
function _substr($str, $length, $minword = 3)
355
{
356
    $sub = '';
357
    $len = 0;
358
    
359
    foreach (explode(' ', $str) as $word)
360
    {
361
        $part = (($sub != '') ? ' ' : '') . $word;
362
        $sub .= $part;
363
        $len += strlen($part);
364
        
365
        if (strlen($word) > $minword && strlen($sub) >= $length)
366
        {
367
            break;
368
        }
369
    }
370
    
371
    return $sub . (($len < strlen($str)) ? '...' : '');
372
}
373
374
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
375
376
	$pp_blog_read_more_title = get_option('pp_blog_read_more_title'); 		
377
	if(empty($pp_blog_read_more_title))
378
	{
379
	    $pp_blog_read_more_title = 'Read More';
380
	}
381
382
	$content = get_the_content('', $stripteaser, $more_file);
383
	$content = strip_shortcodes($content);
384
	$content = str_replace(']]>', ']]&gt;', $content);
385
	$content = _substr(strip_tags(strip_shortcodes($content)), 600);
386
	$content.= '<br/><br/><br/><a class="button" href="'.get_permalink().'">'.$pp_blog_read_more_title.'</a>';
387
	return $content;
388
}
389
390
function image_from_description($data) {
391
    preg_match_all('/<img src="([^"]*)"([^>]*)>/i', $data, $matches);
392
    return $matches[1][0];
393
}
394
395
396
function select_image($img, $size) {
397
    $img = explode('/', $img);
398
    $filename = array_pop($img);
399
400
    // The sizes listed here are the ones Flickr provides by default.  Pass the array index in the
401
402
    // 0 for square, 1 for thumb, 2 for small, etc.
403
    $s = array(
404
        '_s.', // square
405
        '_t.', // thumb
406
        '_m.', // small
407
        '.',   // medium
408
        '_b.'  // large
409
    );
410
411
    $img[] = preg_replace('/(_(s|t|m|b))?\./i', $s[$size], $filename);
412
    return implode('/', $img);
413
}
414
415
416
function get_flickr($settings) {
417
	if (!function_exists('MagpieRSS')) {
418
	    // Check if another plugin is using RSS, may not work
419
	    include_once (ABSPATH . WPINC . '/class-simplepie.php');
420
	    error_reporting(E_ERROR);
421
	}
422
	
423
	if(!isset($settings['items']) || empty($settings['items']))
424
	{
425
		$settings['items'] = 9;
426
	}
427
	
428
	// get the feeds
429
	if ($settings['type'] == "user") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $settings['id'] . '&tags=' . $settings['tags'] . '&per_page='.$settings['items'].'&format=rss_200'; }
430
	elseif ($settings['type'] == "favorite") { $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $settings['id'] . '&format=rss_200'; }
431
	elseif ($settings['type'] == "set") { $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $settings['set'] . '&nsid=' . $settings['id'] . '&format=rss_200'; }
432
	elseif ($settings['type'] == "group") { $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $settings['id'] . '&format=rss_200'; }
433
	elseif ($settings['type'] == "public" || $settings['type'] == "community") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $settings['tags'] . '&format=rss_200'; }
434
	else {
435
	    print '<strong>No "type" parameter has been setup. Check your settings, or provide the parameter as an argument.</strong>';
436
	    die();
437
	}
438
	# get rss file
439
440
	$feed = new SimplePie($rss_url);
441
	$photos_arr = array();
442
	
443
	foreach ($feed->get_items() as $key => $item)
444
	{
445
		$enclosure = $item->get_enclosure();
446
		$img = image_from_description($item->get_description()); 
447
		$thumb_url = select_image($img, 0);
448
		$large_url = select_image($img, 4);
449
		
450
		$photos_arr[] = array(
451
			'title' => $enclosure->get_title(),
452
			'thumb_url' => $thumb_url,
453
			'url' => $large_url,
454
		);
455
		
456
		$current = intval($key+1);
457
		
458
		if($current == $settings['items'])
459
		{
460
			break;
461
		}
462
	}  
463
464
	return $photos_arr;
465
}
466
467
function html2rgb($color)
468
{
469
    if ($color[0] == '#')
470
        $color = substr($color, 1);
471
472
    if (strlen($color) == 6)
473
        list($r, $g, $b) = array($color[0].$color[1],
474
                                 $color[2].$color[3],
475
                                 $color[4].$color[5]);
476
    elseif (strlen($color) == 3)
477
        list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
478
    else
479
        return false;
480
481
    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
482
483
    return array($r, $g, $b);
484
}
485
486
function hex_lighter($hex,$factor = 30) 
487
    { 
488
    $new_hex = ''; 
489
     
490
    $base['R'] = hexdec($hex{0}.$hex{1}); 
491
    $base['G'] = hexdec($hex{2}.$hex{3}); 
492
    $base['B'] = hexdec($hex{4}.$hex{5}); 
493
     
494
    foreach ($base as $k => $v) 
495
        { 
496
        $amount = 255 - $v; 
497
        $amount = $amount / 100; 
498
        $amount = round($amount * $factor); 
499
        $new_decimal = $v + $amount; 
500
     
501
        $new_hex_component = dechex($new_decimal); 
502
        if(strlen($new_hex_component) < 2) 
503
            { $new_hex_component = "0".$new_hex_component; } 
504
        $new_hex .= $new_hex_component; 
505
        } 
506
         
507
    return $new_hex;     
508
} 
509
510
function hex_darker($hex,$factor = 30)
511
{
512
        $new_hex = '';
513
        
514
        $base['R'] = hexdec($hex{0}.$hex{1});
515
        $base['G'] = hexdec($hex{2}.$hex{3});
516
        $base['B'] = hexdec($hex{4}.$hex{5});
517
        
518
        foreach ($base as $k => $v)
519
                {
520
                $amount = $v / 100;
521
                $amount = round($amount * $factor);
522
                $new_decimal = $v - $amount;
523
        
524
                $new_hex_component = dechex($new_decimal);
525
                if(strlen($new_hex_component) < 2)
526
                        { $new_hex_component = "0".$new_hex_component; }
527
                $new_hex .= $new_hex_component;
528
                }
529
                
530
        return $new_hex;        
531
}
532
533
function theme_queue_js(){
534
  if (!is_admin()){
535
    if (!is_page() AND is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
536
      wp_enqueue_script( 'comment-reply' );
537
    }
538
  }
539
}
540
add_action('get_header', 'theme_queue_js');
541
542
?>