· 5 years ago · Nov 15, 2020, 12:34 AM
1<?php
2// File Security Check
3if ( ! defined( 'ABSPATH' ) ) exit;
4?>
5<?php
6/*-----------------------------------------------------------------------------------
7
8TABLE OF CONTENTS
9
10- woo_image - Get Image from custom field
11 - vt_resize - Resize post thumbnail
12 - woo_get_youtube_video_image - Get thumbnail from YouTube
13- Add default filters to woo_embed()
14- woo_get_embed - Get Video
15- Woo Show Page Menu
16- Get the style path currently selected
17- Get page ID
18- Tidy up the image source url
19- Show image in RSS feed
20- Show analytics code footer
21- Browser detection body_class() output
22- Twitter's Blogger.js output for Twitter widgets
23- Template Detector
24- Framework Updater
25 - WooFramework Update Page
26 - WooFramework Update Head
27 - WooFramework Version Getter
28- Woo URL shortener
29- SEO - woo_title()
30- SEO - Strip slashes from the display of the website/page title
31- SEO - woo_meta()
32- Woo Text Trimmer
33- Google Webfonts array
34- Google Fonts Stylesheet Generator
35- Enable Home link in WP Menus
36- Buy Themes page
37- Detects the Charset of String and Converts it to UTF-8
38- WP Login logo
39- WP Login logo URL
40- WP Login logo title
41- woo_pagination()
42- woo_breadcrumbs()
43-- woo_breadcrumbs_get_parents()
44-- woo_breadcrumbs_get_term_parents()
45- WordPress Admin Bar-related
46-- Disable WordPress Admin Bar
47-- Enhancements to the WordPress Admin Bar
48- woo_prepare_category_ids_from_option()
49- Move tracking code from footer to header.
50- woo_get_dynamic_values()
51- woo_get_posts_by_taxonomy()
52- If the user has specified a "posts page", load the "Blog" page template there
53- PressTrends API Integration
54- WooDojo Download Banner
55- wooframework_add_woodojo_banner()
56- wooframework_ajax_banner_close()
57- WooSEO Deprecation Banner
58- wooframework_add_wooseo_banner()
59- WooSidebars Deprecation Banner
60- wooframework_add_woosbm_banner()
61- Static Front Page Detection Banner
62- wooframework_get_theme_version_data()
63- wooframework_display_theme_version_data()
64-----------------------------------------------------------------------------------*/
65
66/*-----------------------------------------------------------------------------------*/
67/* woo_image - Get Image from custom field */
68/*-----------------------------------------------------------------------------------*/
69
70/*
71This function retrieves/resizes the image to be used with the post in this order:
72
731. Image passed through parameter 'src'
742. WP Post Thumbnail (if option activated)
753. Custom field
764. First attached image in post (if option activated)
775. First inline image in post (if option activated)
78
79Resize options (enabled in options panel):
80- vt_resize() is used to natively resize #2 and #4
81- Thumb.php is used to resize #1, #3, #4 (only if vt_resize is disabled) and #5
82
83Parameters:
84 $key = Custom field key eg. "image"
85 $width = Set width manually without using $type
86 $height = Set height manually without using $type
87 $class = CSS class to use on the img tag eg. "alignleft". Default is "thumbnail"
88 $quality = Enter a quality between 80-100. Default is 90
89 $id = Assign a custom ID, if alternative is required.
90 $link = Echo with anchor ( 'src'), without anchor ( 'img') or original image URL ( 'url').
91 $repeat = Auto Img Function. Adjust amount of images to return for the post attachments.
92 $offset = Auto Img Function. Offset the $repeat with assigned amount of objects.
93 $before = Auto Img Function. Add Syntax before image output.
94 $after = Auto Img Function. Add Syntax after image output.
95 $single = (true/false) Force thumbnail to link to the post instead of the image.
96 $force = Force smaller images to not be effected with image width and height dimensions (proportions fix)
97 $return = Return results instead of echoing out.
98 $src = A parameter that accepts a img url for resizing. (No anchor)
99 $meta = Add a custom meta text to the image and anchor of the image.
100 $alignment = Crop alignment for thumb.php (l, r, t, b)
101 $size = Custom pre-defined size for WP Thumbnail (string)
102 $noheight = Don't output the height on img tag (for responsive designs)
103*/
104
105if ( !function_exists('woo_image') ) {
106function woo_image($args) {
107
108 /* ------------------------------------------------------------------------- */
109 /* SET VARIABLES */
110 /* ------------------------------------------------------------------------- */
111
112 global $post;
113 global $woo_options;
114
115 //Defaults
116 $key = 'image';
117 $width = null;
118 $height = null;
119 $class = '';
120 $quality = 90;
121 $id = null;
122 $link = 'src';
123 $repeat = 1;
124 $offset = 0;
125 $before = '';
126 $after = '';
127 $single = false;
128 $force = false;
129 $return = false;
130 $is_auto_image = false;
131 $src = '';
132 $meta = '';
133 $alignment = '';
134 $size = '';
135 $noheight = '';
136
137 $alt = '';
138 $img_link = '';
139
140 $attachment_id = array();
141 $attachment_src = array();
142
143 if ( ! is_array( $args ) )
144 parse_str( $args, $args );
145
146 extract( $args );
147
148 // Set post ID
149 if ( empty( $id ) ) {
150 $id = $post->ID;
151 }
152
153 $thumb_id = esc_html( get_post_meta( $id, '_thumbnail_id', true ) );
154
155 // Set alignment
156 if ( $alignment == '' )
157 $alignment = esc_html( get_post_meta( $id, '_image_alignment', true ) );
158
159 // Get standard sizes
160 if ( ! $width && ! $height ) {
161 $width = '100';
162 $height = '100';
163 }
164
165 // Cast $width and $height to integer
166 $width = intval( $width );
167 $height = intval( $height );
168
169 /* ------------------------------------------------------------------------- */
170 /* FIND IMAGE TO USE */
171 /* ------------------------------------------------------------------------- */
172
173 // When a custom image is sent through
174 if ( $src != '' ) {
175 $custom_field = esc_url( $src );
176 $link = 'img';
177
178 // WP 2.9 Post Thumbnail support
179 } elseif ( get_option( 'woo_post_image_support' ) == 'true' && ! empty( $thumb_id ) ) {
180
181 if ( get_option( 'woo_pis_resize' ) == 'true' ) {
182
183 if ( 0 == $height ) {
184 $img_data = wp_get_attachment_image_src( $thumb_id, array( intval( $width ), 9999 ) );
185 $height = $img_data[2];
186 }
187
188 // Dynamically resize the post thumbnail
189 $vt_crop = get_option( 'woo_pis_hard_crop' );
190 if ($vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
191 $vt_image = vt_resize( $thumb_id, '', $width, $height, $vt_crop );
192
193 // Set fields for output
194 $custom_field = esc_url( $vt_image['url'] );
195 $width = $vt_image['width'];
196 $height = $vt_image['height'];
197
198 } else {
199 // Use predefined size string
200 if ( $size )
201 $thumb_size = $size;
202 else
203 $thumb_size = array( $width, $height );
204
205 $img_link = get_the_post_thumbnail( $id, $thumb_size, array( 'class' => 'woo-image ' . esc_attr( $class ) ) );
206 }
207
208 // Grab the image from custom field
209 } else {
210 $custom_field = esc_url( get_post_meta( $id, $key, true ) );
211 }
212
213 // Automatic Image Thumbs - get first image from post attachment
214 if ( empty( $custom_field ) && get_option( 'woo_auto_img' ) == 'true' && empty( $img_link ) && ! ( is_singular() && in_the_loop() && $link == 'src' ) ) {
215
216 if( $offset >= 1 )
217 $repeat = $repeat + $offset;
218
219 $attachments = get_children( array( 'post_parent' => $id,
220 'numberposts' => $repeat,
221 'post_type' => 'attachment',
222 'post_mime_type' => 'image',
223 'order' => 'DESC',
224 'orderby' => 'menu_order date')
225 );
226
227 // Search for and get the post attachment
228 if ( ! empty( $attachments ) ) {
229 $counter = -1;
230 foreach ( $attachments as $att_id => $attachment ) {
231 $counter++;
232 if ( $counter < $offset )
233 continue;
234
235 if ( get_option( 'woo_post_image_support' ) == 'true' && get_option( 'woo_pis_resize' ) == 'true' ) {
236 // Dynamically resize the post thumbnail
237 $vt_crop = get_option( 'woo_pis_hard_crop' );
238 if ( $vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
239 $vt_image = vt_resize( $att_id, '', $width, $height, $vt_crop );
240
241 // Set fields for output
242 $custom_field = esc_url( $vt_image['url'] );
243 $width = $vt_image['width'];
244 $height = $vt_image['height'];
245 } else {
246 $src = wp_get_attachment_image_src( $att_id, 'large', true );
247 $custom_field = esc_url( $src[0] );
248 $attachment_id[] = $att_id;
249 $src_arr[] = $custom_field;
250 }
251 $thumb_id = $att_id;
252 $is_auto_image = true;
253 }
254
255 // Get the first img tag from content
256 } else {
257
258 $first_img = '';
259 $post = get_post( $id );
260 ob_start();
261 ob_end_clean();
262 $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
263 if ( !empty($matches[1][0]) ) {
264
265 // Save Image URL
266 $custom_field = esc_url( $matches[1][0] );
267
268 // Search for ALT tag
269 $output = preg_match_all( '/<img.+alt=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
270 if ( !empty($matches[1][0]) ) {
271 $alt = esc_attr( $matches[1][0] );
272 }
273 }
274
275 }
276
277 }
278
279 // Check if there is YouTube embed
280 if ( empty( $custom_field ) && empty( $img_link ) ) {
281 $embed = esc_html( get_post_meta( $id, 'embed', true ) );
282 if ( $embed )
283 $custom_field = esc_url( woo_get_video_image( $embed ) );
284 }
285
286 // Return if there is no attachment or custom field set
287 if ( empty( $custom_field ) && empty( $img_link ) ) {
288
289 // Check if default placeholder image is uploaded
290 $placeholder = get_option( 'framework_woo_default_image' );
291 if ( $placeholder && !(is_singular() && in_the_loop()) ) {
292 $custom_field = esc_url( $placeholder );
293
294 // Resize the placeholder if
295 if ( get_option( 'woo_post_image_support' ) == 'true' && get_option( 'woo_pis_resize' ) == 'true' ) {
296 // Dynamically resize the post thumbnail
297 $vt_crop = get_option( 'woo_pis_hard_crop' );
298 if ($vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
299 $vt_image = vt_resize( '', $placeholder, $width, $height, $vt_crop );
300
301 // Set fields for output
302 $custom_field = esc_url( $vt_image['url'] );
303 $width = $vt_image['width'];
304 $height = $vt_image['height'];
305 }
306 } else {
307 return;
308 }
309 }
310
311 if(empty( $src_arr ) && empty( $img_link ) ) { $src_arr[] = $custom_field; }
312
313 /* ------------------------------------------------------------------------- */
314 /* BEGIN OUTPUT */
315 /* ------------------------------------------------------------------------- */
316
317 $output = '';
318
319 // Set output height and width
320 $set_width = ' width="' . esc_attr( $width ) . '" ';
321 $set_height = '';
322
323 if ( ! $noheight && 0 < $height )
324 $set_height = ' height="' . esc_attr( $height ) . '" ';
325
326 // Set standard class
327 if ( $class ) $class = 'woo-image ' . esc_attr( $class ); else $class = 'woo-image';
328
329 // Do check to verify if images are smaller then specified.
330 if($force == true){ $set_width = ''; $set_height = ''; }
331
332 // WP Post Thumbnail
333 if( ! empty( $img_link ) ) {
334
335 if( $link == 'img' ) { // Output the image without anchors
336 $output .= wp_kses_post( $before );
337 $output .= $img_link;
338 $output .= wp_kses_post( $after );
339 } elseif( $link == 'url' ) { // Output the large image
340 $src = wp_get_attachment_image_src( $thumb_id, 'large', true );
341 $custom_field = esc_url( $src[0] );
342 $output .= $custom_field;
343 } else { // Default - output with link
344 if ( ( is_single() || is_page() ) && $single == false ) {
345 $rel = 'rel="lightbox"';
346 $href = false;
347 } else {
348 $href = get_permalink( $id );
349 $rel = '';
350 }
351
352 $title = 'title="' . esc_attr( get_the_title( $id ) ) .'"';
353
354 $output .= wp_kses_post( $before );
355 if($href == false){
356 $output .= $img_link;
357 } else {
358 $output .= '<a ' . $title . ' href="' . esc_url( $href ) . '" '. $rel .'>' . $img_link . '</a>';
359 }
360
361 $output .= wp_kses_post( $after );
362 }
363 }
364
365 // Use thumb.php to resize. Skip if image has been natively resized with vt_resize.
366 elseif ( get_option( 'woo_resize') == 'true' && empty( $vt_image['url'] ) ) {
367
368 foreach( $src_arr as $key => $custom_field ) {
369
370 // Clean the image URL
371 $href = esc_url( $custom_field );
372 $custom_field = cleanSource( $custom_field );
373
374 // Check if WPMU and set correct path AND that image isn't external
375 if ( function_exists( 'get_current_site') ) {
376 get_current_site();
377 //global $blog_id; Breaks with WP3 MS
378 if ( !$blog_id ) {
379 global $current_blog;
380 $blog_id = $current_blog->blog_id;
381 }
382 if ( isset($blog_id) && $blog_id > 0 ) {
383 $imageParts = explode( 'files/', $custom_field );
384 if ( isset( $imageParts[1] ) )
385 $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
386 }
387 }
388
389 //Set the ID to the Attachment's ID if it is an attachment
390 if($is_auto_image == true){
391 $quick_id = $attachment_id[$key];
392 } else {
393 $quick_id = $id;
394 }
395
396 //Set custom meta
397 if ($meta) {
398 $alt = $meta;
399 $title = 'title="' . esc_attr( $meta ) . '"';
400 } else {
401 if ( ( $alt != '' ) || ! ( $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) ) ) {
402 $alt = esc_attr( get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) );
403 } else {
404 $alt = esc_attr( get_the_title( $quick_id ) );
405 }
406 $title = 'title="'. esc_attr( get_the_title( $quick_id ) ) .'"';
407 }
408
409 // Set alignment parameter
410 if ( $alignment != '' )
411 $alignment = '&a=' . urlencode( $alignment );
412
413 $img_url = esc_url( get_template_directory_uri() . '/functions/thumb.php?src=' . $custom_field . '&w=' . $width . '&h=' . $height . '&zc=1&q=' . $quality . $alignment );
414 $img_link = '<img src="' . $img_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( stripslashes( $class ) ) . '" ' . $set_width . $set_height . ' />';
415
416 if( $link == 'img' ) { // Just output the image
417 $output .= wp_kses_post( $before );
418 $output .= $img_link;
419 $output .= wp_kses_post( $after );
420
421 } elseif( $link == 'url' ) { // Output the image without anchors
422
423 if($is_auto_image == true){
424 $src = wp_get_attachment_image_src($thumb_id, 'large', true);
425 $custom_field = esc_url( $src[0] );
426 }
427 $output .= $href;
428
429 } else { // Default - output with link
430
431 if ( ( is_single() || is_page() ) && $single == false ) {
432 $rel = 'rel="lightbox"';
433 } else {
434 $href = get_permalink( $id );
435 $rel = '';
436 }
437
438 $output .= wp_kses_post( $before );
439 $output .= '<a ' . $title . ' href="' . esc_url( $href ) . '" ' . $rel . '>' . $img_link . '</a>';
440 $output .= wp_kses_post( $after );
441 }
442 }
443
444 // No dynamic resizing
445 } else {
446 foreach( $src_arr as $key => $custom_field ) {
447
448 //Set the ID to the Attachment's ID if it is an attachment
449 if( $is_auto_image == true && isset( $attachment_id[$key] ) ){
450 $quick_id = $attachment_id[$key];
451 } else {
452 $quick_id = $id;
453 }
454
455 //Set custom meta
456 if ($meta) {
457 $alt = esc_attr( $meta );
458 $title = 'title="'. esc_attr( $meta ) .'"';
459 } else {
460 if ($alt == '') $alt = esc_attr( get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) );
461 $title = 'title="'. esc_attr( get_the_title( $quick_id ) ) .'"';
462 }
463
464 $img_link = '<img src="'. esc_url( $custom_field ) . '" alt="' . esc_attr( $alt ) . '" ' . $set_width . $set_height . ' class="' . esc_attr( stripslashes( $class ) ) . '" />';
465
466 if ( $link == 'img' ) { // Just output the image
467 $output .= wp_kses_post( $before );
468 $output .= $img_link;
469 $output .= wp_kses_post( $after );
470
471 } elseif( $link == 'url' ) { // Output the URL to original image
472 if ( $vt_image['url'] || $is_auto_image ) {
473 $src = wp_get_attachment_image_src( $thumb_id, 'full', true );
474 $custom_field = esc_url( $src[0] );
475 }
476 $output .= $custom_field;
477
478 } else { // Default - output with link
479
480 if ( ( is_single() || is_page() ) && $single == false ) {
481
482 // Link to the large image if single post
483 if ( $vt_image['url'] || $is_auto_image ) {
484 $src = wp_get_attachment_image_src( $thumb_id, 'full', true );
485 $custom_field = esc_url( $src[0] );
486 }
487
488 $href = $custom_field;
489 $rel = 'rel="lightbox"';
490 } else {
491 $href = get_permalink( $id );
492 $rel = '';
493 }
494
495 $output .= wp_kses_post( $before );
496 $output .= '<a href="' . esc_url( $href ) . '" ' . $rel . ' ' . $title . '>' . $img_link . '</a>';
497 $output .= wp_kses_post( $after );
498 }
499 }
500 }
501
502 // Remove no height attribute - IE fix when no height is set
503 $output = str_replace( 'height=""', '', $output );
504 $output = str_replace( 'height="0"', '', $output );
505
506 // Return or echo the output
507 if ( $return == TRUE )
508 return $output;
509 else
510 echo $output; // Done
511
512}
513}
514
515/* Get thumbnail from Video Embed code */
516if ( ! function_exists( 'woo_get_video_image' ) ) {
517function woo_get_video_image( $embed ) {
518 $video_thumb = '';
519
520 // YouTube - get the video code if this is an embed code (old embed)
521 preg_match( '/youtube\.com\/v\/([\w\-]+)/', $embed, $match );
522
523 // YouTube - if old embed returned an empty ID, try capuring the ID from the new iframe embed
524 if( ! isset( $match[1] ) )
525 preg_match( '/youtube\.com\/embed\/([\w\-]+)/', $embed, $match );
526
527 // YouTube - if it is not an embed code, get the video code from the youtube URL
528 if( ! isset( $match[1] ) )
529 preg_match( '/v\=(.+)&/', $embed, $match );
530
531 // YouTube - get the corresponding thumbnail images
532 if( isset( $match[1] ) )
533 $video_thumb = "http://img.youtube.com/vi/" . urlencode( $match[1] ) . "/0.jpg";
534
535 // return whichever thumbnail image you would like to retrieve
536 return $video_thumb;
537} // End woo_get_video_image()
538}
539
540
541/*-----------------------------------------------------------------------------------*/
542/* vt_resize - Resize images dynamically using wp built in functions
543/*-----------------------------------------------------------------------------------*/
544/*
545 * Resize images dynamically using wp built in functions
546 * Victor Teixeira
547 *
548 * php 5.2+
549 *
550 * Exemplo de uso:
551 *
552 * <?php
553 * $thumb = get_post_thumbnail_id();
554 * $image = vt_resize( $thumb, '', 140, 110, true );
555 * ?>
556 * <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
557 *
558 * @param int $attach_id
559 * @param string $img_url
560 * @param int $width
561 * @param int $height
562 * @param bool $crop
563 * @return array
564 */
565if ( ! function_exists( 'vt_resize' ) ) {
566 function vt_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
567
568 // Cast $width and $height to integer
569 $width = intval( $width );
570 $height = intval( $height );
571
572 // this is an attachment, so we have the ID
573 if ( $attach_id ) {
574 $image_src = wp_get_attachment_image_src( $attach_id, 'full' );
575 $file_path = get_attached_file( $attach_id );
576 // this is not an attachment, let's use the image url
577 } else if ( $img_url ) {
578 $file_path = parse_url( esc_url( $img_url ) );
579 $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
580
581 //$file_path = ltrim( $file_path['path'], '/' );
582 //$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
583
584 $orig_size = getimagesize( $file_path );
585
586 $image_src[0] = $img_url;
587 $image_src[1] = $orig_size[0];
588 $image_src[2] = $orig_size[1];
589 }
590
591 $file_info = pathinfo( $file_path );
592
593 // check if file exists
594 if ( !isset( $file_info['dirname'] ) && !isset( $file_info['filename'] ) && !isset( $file_info['extension'] ) )
595 return;
596
597 $base_file = isset($file_info['dirname']).'/'.isset($file_info['filename']).'.'.isset($file_info['extension']);
598 if ( !file_exists($base_file) )
599 return;
600
601 $extension = '.'. $file_info['extension'];
602
603 // the image path without the extension
604 $no_ext_path = $file_info['dirname'].'/'.$file_info['filename'];
605
606 $cropped_img_path = $no_ext_path.'-'.$width.'x'.$height.$extension;
607
608 // checking if the file size is larger than the target size
609 // if it is smaller or the same size, stop right here and return
610 if ( $image_src[1] > $width ) {
611 // the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
612 if ( file_exists( $cropped_img_path ) ) {
613 $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
614
615 $vt_image = array (
616 'url' => $cropped_img_url,
617 'width' => $width,
618 'height' => $height
619 );
620 return $vt_image;
621 }
622
623 // $crop = false or no height set
624 if ( $crop == false OR !$height ) {
625 // calculate the size proportionaly
626 $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
627 $resized_img_path = $no_ext_path.'-'.$proportional_size[0].'x'.$proportional_size[1].$extension;
628
629 // checking if the file already exists
630 if ( file_exists( $resized_img_path ) ) {
631 $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
632
633 $vt_image = array (
634 'url' => $resized_img_url,
635 'width' => $proportional_size[0],
636 'height' => $proportional_size[1]
637 );
638 return $vt_image;
639 }
640 }
641
642 // check if image width is smaller than set width
643 $img_size = getimagesize( $file_path );
644 if ( $img_size[0] <= $width ) $width = $img_size[0];
645
646 // Check if GD Library installed
647 if ( ! function_exists ( 'imagecreatetruecolor' ) ) {
648 echo 'GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library';
649 return;
650 }
651
652 // no cache files - let's finally resize it
653 if ( function_exists( 'wp_get_image_editor' ) ) {
654 $image = wp_get_image_editor( $file_path );
655 if ( ! is_wp_error( $image ) ) {
656 $image->resize( $width, $height, $crop );
657 $save_data = $image->save();
658 if ( isset( $save_data['path'] ) ) $new_img_path = $save_data['path'];
659 }
660 } else {
661 $new_img_path = wp_get_image_editor( $file_path, $width, $height, $crop );
662 }
663
664 $new_img_size = getimagesize( $new_img_path );
665 $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
666
667 // resized output
668 $vt_image = array (
669 'url' => $new_img,
670 'width' => $new_img_size[0],
671 'height' => $new_img_size[1]
672 );
673
674 return $vt_image;
675 }
676
677 // default output - without resizing
678 $vt_image = array (
679 'url' => $image_src[0],
680 'width' => $width,
681 'height' => $height
682 );
683
684 return $vt_image;
685 }
686}
687
688/*-----------------------------------------------------------------------------------*/
689/* Depreciated - woo_get_image - Get Image from custom field */
690/*-----------------------------------------------------------------------------------*/
691
692// Depreciated
693function woo_get_image($key = 'image', $width = null, $height = null, $class = "thumbnail", $quality = 90,$id = null,$link = 'src',$repeat = 1,$offset = 0,$before = '', $after = '',$single = false, $force = false, $return = false) {
694 // Run new function
695 woo_image( 'key='.$key.'&width='.$width.'&height='.$height.'&class='.$class.'&quality='.$quality.'&id='.$id.'&link='.$link.'&repeat='.$repeat.'&offset='.$offset.'&before='.$before.'&after='.$after.'&single='.$single.'&fore='.$force.'&return='.$return );
696 return;
697} // End woo_get_image()
698
699/*-----------------------------------------------------------------------------------*/
700/* woo_embed - Get Video embed code from custom field */
701/*-----------------------------------------------------------------------------------*/
702
703/*
704Get Video
705This function gets the embed code from the custom field
706Parameters:
707 $key = Custom field key eg. "embed"
708 $width = Set width manually without using $type
709 $height = Set height manually without using $type
710 $class = Custom class to apply to wrapping div
711 $id = ID from post to pull custom field from
712*/
713
714if ( ! function_exists( 'woo_embed' ) ) {
715function woo_embed($args) {
716 //Defaults
717 $key = 'embed';
718 $width = null;
719 $height = null;
720 $class = 'video';
721 $id = null;
722
723 if ( ! is_array( $args ) )
724 parse_str( $args, $args );
725
726 extract( $args );
727
728 if( empty( $id ) ) {
729 global $post;
730 $id = $post->ID;
731 }
732
733// Cast $width and $height to integer
734$width = intval( $width );
735$height = intval( $height );
736
737$custom_field = esc_textarea( get_post_meta( $id, $key, true ) );
738
739if ($custom_field) :
740 $custom_field = html_entity_decode( $custom_field ); // Decode HTML entities.
741
742 $org_width = $width;
743 $org_height = $height;
744 $calculated_height = '';
745 $embed_width = '';
746 $embed_height = '';
747
748 // Get custom width and height
749 $custom_width = esc_html( get_post_meta( $id, 'width', true ) );
750 $custom_height = esc_html( get_post_meta( $id, 'height', true ) );
751
752 //Dynamic Height Calculation
753 if ($org_height == '' && $org_width != '') {
754 $raw_values = explode( ' ', $custom_field);
755
756 foreach ( $raw_values as $raw ) {
757 $embed_params = explode( '=', $raw );
758 if ( $embed_params[0] == 'width' ) {
759 $embed_width = preg_replace( '/[^0-9]/', '', $embed_params[1]);
760 }
761 elseif ( $embed_params[0] == 'height' ) {
762 $embed_height = preg_replace( '/[^0-9]/', '', $embed_params[1]);
763 }
764 }
765
766 $float_width = floatval( $embed_width );
767 $float_height = floatval( $embed_height );
768 @$float_ratio = $float_height / $float_width;
769 $calculated_height = intval( $float_ratio * $width );
770 }
771
772 // Set values: width="XXX", height="XXX"
773 if ( ! $custom_width ) $width = 'width="' . esc_attr( $width ) . '"'; else $width = 'width="' . esc_attr( $custom_width ) . '"';
774 if ( $height == '' ) { $height = 'height="' . esc_attr( $calculated_height ) . '"'; } else { if ( ! $custom_height ) { $height = 'height="' . esc_attr( $height ) . '"'; } else { $height = 'height="' . esc_attr( $custom_height ) . '"'; } }
775 $custom_field = stripslashes($custom_field);
776 $custom_field = preg_replace( '/width="([0-9]*)"/' , $width , $custom_field );
777 $custom_field = preg_replace( '/height="([0-9]*)"/' , $height, $custom_field );
778
779 // Set values: width:XXXpx, height:XXXpx
780 if ( ! $custom_width ) $width = 'width:' . esc_attr( $org_width ) . 'px'; else $width = 'width:' . esc_attr( $custom_width ) . 'px';
781 if ( $height == '' ) { $height = 'height:' . esc_attr( $calculated_height ) . 'px'; } else { if ( ! $custom_height ) { $height = 'height:' . esc_attr( $org_height ) . 'px'; } else { $height = 'height:' . esc_attr( $custom_height ) . 'px'; } }
782 $custom_field = stripslashes($custom_field);
783 $custom_field = preg_replace( '/width:([0-9]*)px/' , $width , $custom_field );
784 $custom_field = preg_replace( '/height:([0-9]*)px/' , $height, $custom_field );
785
786 // Suckerfish menu hack
787 $custom_field = str_replace( '<embed ', '<param name="wmode" value="transparent"></param><embed wmode="transparent" ', $custom_field );
788 $custom_field = str_replace( '<iframe ', '<iframe wmode="transparent" ', $custom_field );
789 $custom_field = str_replace( '" frameborder="', '?wmode=transparent" frameborder="', $custom_field );
790
791 // Find and sanitize video URL. Add "wmode=transparent" to URL.
792 $video_url = preg_match( '/src=["\']?([^"\' ]*)["\' ]/is', $custom_field, $matches );
793 if ( isset( $matches[1] ) ) {
794 $custom_field = str_replace( $matches[0], 'src="' . esc_url( add_query_arg( 'wmode', 'transparent', $matches[1] ) ) . '"', $custom_field );
795 }
796
797 $output = '';
798 $output .= '<div class="'. esc_attr( $class ) .'">' . $custom_field . '</div>';
799
800 return apply_filters( 'woo_embed', $output );
801else :
802 return false;
803endif;
804}
805}
806
807/*-----------------------------------------------------------------------------------*/
808/* Add default filters to woo_embed() */
809/*-----------------------------------------------------------------------------------*/
810
811add_filter( 'woo_embed', 'do_shortcode' );
812
813/*-----------------------------------------------------------------------------------*/
814/* Depreciated - woo_get_embed - Get Video embed code from custom field */
815/*-----------------------------------------------------------------------------------*/
816// Depreciated
817function woo_get_embed($key = 'embed', $width, $height, $class = 'video', $id = null) {
818 // Run new function
819 return woo_embed( 'key='.$key.'&width='.$width.'&height='.$height.'&class='.$class.'&id='.$id );
820
821}
822
823/*-----------------------------------------------------------------------------------*/
824/* Woo Show Page Menu */
825/*-----------------------------------------------------------------------------------*/
826// Show menu in header.php
827// Exlude the pages from the slider
828function woo_show_pagemenu( $exclude = '' ) {
829 // Split the featured pages from the options, and put in an array
830 if ( get_option( 'woo_ex_featpages') ) {
831 $menupages = get_option( 'woo_featpages' );
832 $exclude = $menupages . ',' . $exclude;
833 }
834
835 $pages = wp_list_pages( 'sort_column=menu_order&title_li=&echo=0&depth=1&exclude=' . $exclude );
836 $pages = preg_replace( '%<a ([^>]+)>%U','<a $1><span>', $pages );
837 $pages = str_replace( '</a>','</span></a>', $pages );
838 echo $pages;
839} // End woo_show_pagemenu()
840
841/*-----------------------------------------------------------------------------------*/
842/* Get the style path currently selected */
843/*-----------------------------------------------------------------------------------*/
844function woo_style_path() {
845 $return = '';
846
847 $style = $_REQUEST['style'];
848
849 // Sanitize request input.
850 $style = esc_attr( strtolower( trim( strip_tags( $style ) ) ) );
851
852 if ( $style != '' ) {
853 $style_path = $style;
854 } else {
855 $stylesheet = esc_attr( get_option( 'woo_alt_stylesheet' ) );
856
857 // Prevent against an empty return to $stylesheet.
858 if ( $stylesheet == '' ) {
859 $stylesheet = 'default.css';
860 }
861
862 $style_path = str_replace( '.css', '', $stylesheet );
863 }
864
865 if ( $style_path == 'default' ) {
866 $return = 'images';
867 } else {
868 $return = 'styles/' . $style_path;
869 }
870
871 echo esc_html( $return );
872} // End woo_style_path()
873
874
875/*-----------------------------------------------------------------------------------*/
876/* Get page ID */
877/*-----------------------------------------------------------------------------------*/
878function get_page_id( $page_slug ) {
879 $page_id = get_page_by_path( $page_slug );
880 if ($page_id) {
881 return $page_id->ID;
882 } else {
883 return null;
884 }
885} // End get_page_id()
886
887/*-----------------------------------------------------------------------------------*/
888/* Tidy up the image source url */
889/*-----------------------------------------------------------------------------------*/
890function cleanSource( $src ) {
891 // remove slash from start of string
892 if(strpos($src, "/") == 0) {
893 $src = substr($src, -(strlen($src) - 1));
894 }
895
896 // Check if same domain so it doesn't strip external sites
897 $host = str_replace( 'www.', '', $_SERVER['HTTP_HOST'] );
898 if ( ! strpos( $src, $host ) )
899 return $src;
900
901
902 $regex = "/^((ht|f)tp(s|):\/\/)(www\.|)" . $host . "/i";
903 $src = preg_replace ( $regex, '', $src );
904 $src = htmlentities ( $src );
905
906 // remove slash from start of string
907 if ( strpos( $src, '/' ) === 0 ) {
908 $src = substr ( $src, -( strlen( $src ) - 1 ) );
909 }
910
911 return $src;
912} // End cleanSource()
913
914/*-----------------------------------------------------------------------------------*/
915/* Show image in RSS feed */
916/* Original code by Justin Tadlock */
917/*-----------------------------------------------------------------------------------*/
918if ( get_option( 'woo_rss_thumb' ) == 'true' ) {
919 if ( get_option( 'rss_use_excerpt' ) )
920 add_filter( 'the_excerpt_rss', 'add_image_RSS' );
921 else
922 add_filter( 'the_content', 'add_image_RSS' );
923}
924
925function add_image_RSS( $content ) {
926
927 global $post, $id;
928 $blog_key = substr( md5( home_url( '/' ) ), 0, 16 );
929 if ( ! is_feed() ) return $content;
930
931 // Get the "image" from custom field
932 //$image = get_post_meta($post->ID, 'image', $single = true);
933 $image = woo_image( 'return=true&link=url' );
934 $image_width = '240';
935
936 // If there's an image, display the image with the content
937 if( $image != '' ) {
938 $content = '<p style="float:right; margin:0 0 10px 15px; width:' . esc_attr( $image_width ) . 'px;">
939 <img src="' . esc_url( $image ) . '" width="' . esc_attr( $image_width ) . '" />
940 </p>' . $content;
941 return $content;
942 } else {
943 // If there's not an image, just display the content
944 $content = $content;
945 return $content;
946 }
947} // End add_image_RSS()
948
949
950
951/*-----------------------------------------------------------------------------------*/
952/* Show analytics code in footer */
953/*-----------------------------------------------------------------------------------*/
954function woo_analytics(){
955 $output = get_option( 'woo_google_analytics' );
956 if ( $output != '' )
957 echo stripslashes( $output ) . "\n";
958} // End woo_analytics()
959add_action( 'wp_footer','woo_analytics' );
960
961
962
963/*-----------------------------------------------------------------------------------*/
964/* Browser detection body_class() output */
965/*-----------------------------------------------------------------------------------*/
966add_filter( 'body_class','browser_body_class' );
967function browser_body_class( $classes ) {
968 global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
969
970 if($is_lynx) $classes[] = 'lynx';
971 elseif($is_gecko) $classes[] = 'gecko';
972 elseif($is_opera) $classes[] = 'opera';
973 elseif($is_NS4) $classes[] = 'ns4';
974 elseif($is_safari) $classes[] = 'safari';
975 elseif($is_chrome) $classes[] = 'chrome';
976 elseif($is_IE) {
977 $browser = $_SERVER['HTTP_USER_AGENT'];
978 $browser = substr( "$browser", 25, 8);
979 if ($browser == "MSIE 7.0" ) {
980 $classes[] = 'ie7';
981 $classes[] = 'ie';
982 } elseif ($browser == "MSIE 6.0" ) {
983 $classes[] = 'ie6';
984 $classes[] = 'ie';
985 } elseif ($browser == "MSIE 8.0" ) {
986 $classes[] = 'ie8';
987 $classes[] = 'ie';
988 } elseif ($browser == "MSIE 9.0" ) {
989 $classes[] = 'ie9';
990 $classes[] = 'ie';
991 } else {
992 $classes[] = 'ie';
993 }
994 }
995 else $classes[] = 'unknown';
996
997 if( $is_iphone ) $classes[] = 'iphone';
998
999 // Alternative style body class.
1000 $style = get_option( 'woo_alt_stylesheet', 'default' );
1001 $style = str_replace( '.css', '', $style );
1002 if ( '' != $style ) {
1003 $classes[] = 'alt-style-' . esc_attr( $style );
1004 }
1005 return $classes;
1006} // End browser_body_class()
1007
1008/*-----------------------------------------------------------------------------------*/
1009/* Twitter's Blogger.js output for Twitter widgets */
1010/*-----------------------------------------------------------------------------------*/
1011
1012if ( ! function_exists( 'woo_twitter_script' ) ) {
1013 function woo_twitter_script($unique_id,$username,$limit) {
1014 ?>
1015 <script type="text/javascript">
1016 <!--//--><![CDATA[//><!--
1017
1018 function twitterCallback2(twitters) {
1019
1020 var statusHTML = [];
1021 for (var i=0; i<twitters.length; i++){
1022 var username = twitters[i].user.screen_name;
1023 var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
1024 return '<a href="'+url+'">'+url+'</a>';
1025 }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
1026 return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
1027 });
1028 statusHTML.push( '<li><span class="content">'+status+'</span> <a style="font-size:85%" class="time" href="http://twitter.com/'+username+'/statuses/'+twitters[i].id_str+'">'+relative_time(twitters[i].created_at)+'</a></li>' );
1029 }
1030 document.getElementById( 'twitter_update_list_<?php echo esc_attr( $unique_id ); ?>').innerHTML = statusHTML.join( '' );
1031 }
1032
1033 function relative_time(time_value) {
1034 var values = time_value.split( " " );
1035 time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
1036 var parsed_date = Date.parse(time_value);
1037 var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
1038 var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
1039 delta = delta + (relative_to.getTimezoneOffset() * 60);
1040
1041 if (delta < 60) {
1042 return '<?php esc_attr_e( 'less than a minute ago', 'woothemes' ); ?>';
1043 } else if(delta < 120) {
1044 return '<?php esc_attr_e( 'about a minute ago', 'woothemes' ); ?>';
1045 } else if(delta < (60*60)) {
1046 return (parseInt(delta / 60)).toString() + ' <?php esc_attr_e( 'minutes ago', 'woothemes' ); ?>';
1047 } else if(delta < (120*60)) {
1048 return 'about an hour ago';
1049 } else if(delta < (24*60*60)) {
1050 return 'about ' + (parseInt(delta / 3600)).toString() + ' <?php esc_attr_e( 'hours ago', 'woothemes' ); ?>';
1051 } else if(delta < (48*60*60)) {
1052 return '1 day ago';
1053 } else {
1054 return (parseInt(delta / 86400)).toString() + ' <?php esc_attr_e( 'days ago', 'woothemes' ); ?>';
1055 }
1056 }
1057 //-->!]]>
1058 </script>
1059 <script type="text/javascript" src="http<?php if (is_ssl()) { echo 's'; } ?>://api.twitter.com/1/statuses/user_timeline/<?php echo esc_attr( $username ); ?>.json?callback=twitterCallback2&count=<?php echo esc_attr( $limit ); ?>&include_rts=t"></script>
1060 <?php
1061 } // End woo_twitter_script()
1062}
1063
1064/*-----------------------------------------------------------------------------------*/
1065/* Deprecated: Template Detector */
1066/*-----------------------------------------------------------------------------------*/
1067function woo_active_template( $filename = null ) {
1068
1069 trigger_error( sprintf( __( '%1$s is <strong>deprecated</strong> since version %2$s of the WooFramework! Please upgrade your Theme to the latest version.', 'woothemes' ), 'woo_active_template', '5.4' ) );
1070 return false; // No $filename argument was set
1071
1072} // End woo_active_template()
1073
1074/*-----------------------------------------------------------------------------------*/
1075/* WooFramework Update Page */
1076/*-----------------------------------------------------------------------------------*/
1077
1078function woothemes_framework_update_page() {
1079
1080 // Clear transients.
1081 delete_transient( 'woo_framework_critical_update' );
1082 delete_transient( 'woo_framework_critical_update_data' );
1083 delete_transient( 'wooframework_version_data' );
1084
1085 $method = get_filesystem_method();
1086
1087 $to = ABSPATH . 'wp-content/themes/' . get_option( 'template' ) . '/functions/';
1088 if(isset($_POST['password'])){
1089
1090 $cred = $_POST;
1091 $filesystem = WP_Filesystem($cred);
1092
1093 }
1094 elseif(isset($_POST['woo_ftp_cred'])){
1095
1096 $cred = unserialize(base64_decode($_POST['woo_ftp_cred']));
1097 $filesystem = WP_Filesystem($cred);
1098
1099 } else {
1100
1101 $filesystem = WP_Filesystem();
1102
1103 };
1104 $url = admin_url( 'admin.php?page=woothemes_framework_update' );
1105 ?>
1106 <div class="wrap themes-page">
1107 <?php
1108 if($filesystem == false){
1109
1110 request_filesystem_credentials ( $url );
1111
1112 } else {
1113
1114 // Clear the transient to force a fresh update.
1115 delete_transient( 'wooframework_version_data' );
1116
1117 $localversion = esc_html( get_option( 'woo_framework_version' ) );
1118 $remoteversion = woo_get_fw_version();
1119
1120 // Test if new version
1121 $upd = false;
1122 $loc = explode( '.',$localversion);
1123 $rem = explode( '.',$remoteversion['version']);
1124
1125 if( $loc[0] < $rem[0] )
1126 $upd = true;
1127 elseif ( $loc[1] < $rem[1] )
1128 $upd = true;
1129 elseif( $loc[2] < $rem[2] )
1130 $upd = true;
1131
1132 ?>
1133 <?php screen_icon( 'tools' ); ?>
1134 <h2>Framework Update</h2>
1135 <span style="display:none"><?php echo $method; ?></span>
1136 <form method="post" enctype="multipart/form-data" id="wooform" action="<?php /* echo $url; */ ?>">
1137
1138 <?php if( $upd ) { ?>
1139 <?php wp_nonce_field( 'update-options' ); ?>
1140 <h3>A new version of WooFramework is available.</h3>
1141 <p>This updater will download and extract the latest WooFramework files to your current theme's functions folder. </p>
1142 <p>We recommend backing up your theme files and updating WordPress to latest version before proceeding.</p>
1143 <p>→ <strong>Your version:</strong> <?php echo $localversion; ?></p>
1144
1145 <p>→ <strong>Current Version:</strong> <?php echo $remoteversion['version']; ?></p>
1146
1147 <input type="submit" class="button" value="Update Framework" />
1148 <?php } else { ?>
1149 <h3>You have the latest version of WooFramework</h3>
1150 <p>→ <strong>Your version:</strong> <?php echo $localversion; ?></p>
1151 <?php } ?>
1152 <input type="hidden" name="woo_update_save" value="save" />
1153 <input type="hidden" name="woo_ftp_cred" value="<?php echo esc_attr( base64_encode(serialize($_POST))); ?>" />
1154
1155 </form>
1156 <?php } ?>
1157 </div>
1158 <?php
1159};
1160
1161/*-----------------------------------------------------------------------------------*/
1162/* WooFramework Update Head */
1163/*-----------------------------------------------------------------------------------*/
1164
1165function woothemes_framework_update_head() {
1166 if( isset( $_REQUEST['page'] ) ) {
1167 // Sanitize page being requested.
1168 $_page = esc_attr( $_REQUEST['page'] );
1169
1170 if( $_page == 'woothemes_framework_update' ) {
1171 //Setup Filesystem
1172 $method = get_filesystem_method();
1173
1174 if( isset( $_POST['woo_ftp_cred'] ) ) {
1175 $cred = unserialize( base64_decode( $_POST['woo_ftp_cred'] ) );
1176 $filesystem = WP_Filesystem($cred);
1177 } else {
1178 $filesystem = WP_Filesystem();
1179 }
1180
1181 if( $filesystem == false && $_POST['upgrade'] != 'Proceed' ) {
1182
1183 function woothemes_framework_update_filesystem_warning() {
1184 $method = get_filesystem_method();
1185 echo "<div id='filesystem-warning' class='updated fade'><p>Failed: Filesystem preventing downloads. ( ". $method .")</p></div>";
1186 }
1187 add_action( 'admin_notices', 'woothemes_framework_update_filesystem_warning' );
1188 return;
1189 }
1190 if(isset($_REQUEST['woo_update_save'])){
1191
1192 // Sanitize action being requested.
1193 $_action = esc_attr( $_REQUEST['woo_update_save'] );
1194
1195 if( $_action == 'save' ) {
1196
1197 $temp_file_addr = download_url( esc_url( 'http://www.woothemes.com/updates/framework.zip' ) );
1198
1199 if ( is_wp_error($temp_file_addr) ) {
1200
1201 $error = esc_html( $temp_file_addr->get_error_code() );
1202
1203 if( $error == 'http_no_url' ) {
1204 //The source file was not found or is invalid
1205 function woothemes_framework_update_missing_source_warning() {
1206 echo "<div id='source-warning' class='updated fade'><p>Failed: Invalid URL Provided</p></div>";
1207 }
1208 add_action( 'admin_notices', 'woothemes_framework_update_missing_source_warning' );
1209 } else {
1210 function woothemes_framework_update_other_upload_warning() {
1211 echo "<div id='source-warning' class='updated fade'><p>Failed: Upload - $error</p></div>";
1212 }
1213 add_action( 'admin_notices', 'woothemes_framework_update_other_upload_warning' );
1214
1215 }
1216
1217 return;
1218
1219 }
1220 //Unzip it
1221 global $wp_filesystem;
1222 $to = $wp_filesystem->wp_content_dir() . "/themes/" . get_option( 'template' ) . "/functions/";
1223
1224 $dounzip = unzip_file($temp_file_addr, $to);
1225
1226 unlink($temp_file_addr); // Delete Temp File
1227
1228 if ( is_wp_error($dounzip) ) {
1229
1230 //DEBUG
1231 $error = esc_html( $dounzip->get_error_code() );
1232 $data = $dounzip->get_error_data($error);
1233 //echo $error. ' - ';
1234 //print_r($data);
1235
1236 if($error == 'incompatible_archive') {
1237 //The source file was not found or is invalid
1238 function woothemes_framework_update_no_archive_warning() {
1239 echo "<div id='woo-no-archive-warning' class='updated fade'><p>Failed: Incompatible archive</p></div>";
1240 }
1241 add_action( 'admin_notices', 'woothemes_framework_update_no_archive_warning' );
1242 }
1243 if($error == 'empty_archive') {
1244 function woothemes_framework_update_empty_archive_warning() {
1245 echo "<div id='woo-empty-archive-warning' class='updated fade'><p>Failed: Empty Archive</p></div>";
1246 }
1247 add_action( 'admin_notices', 'woothemes_framework_update_empty_archive_warning' );
1248 }
1249 if($error == 'mkdir_failed') {
1250 function woothemes_framework_update_mkdir_warning() {
1251 echo "<div id='woo-mkdir-warning' class='updated fade'><p>Failed: mkdir Failure</p></div>";
1252 }
1253 add_action( 'admin_notices', 'woothemes_framework_update_mkdir_warning' );
1254 }
1255 if($error == 'copy_failed') {
1256 function woothemes_framework_update_copy_fail_warning() {
1257 echo "<div id='woo-copy-fail-warning' class='updated fade'><p>Failed: Copy Failed</p></div>";
1258 }
1259 add_action( 'admin_notices', 'woothemes_framework_update_copy_fail_warning' );
1260 }
1261
1262 return;
1263
1264 }
1265
1266 function woothemes_framework_updated_success() {
1267 echo "<div id='framework-upgraded' class='updated fade'><p>New framework successfully downloaded, extracted and updated.</p></div>";
1268 }
1269
1270 add_action( 'admin_notices', 'woothemes_framework_updated_success' );
1271
1272 }
1273 }
1274 } //End user input save part of the update
1275 }
1276}
1277
1278add_action( 'admin_head', 'woothemes_framework_update_head' );
1279
1280/*-----------------------------------------------------------------------------------*/
1281/* WooFramework Version Getter */
1282/*-----------------------------------------------------------------------------------*/
1283
1284function woo_get_fw_version( $url = '', $check_if_critical = false ) {
1285
1286 if( ! empty( $url ) ) {
1287 $fw_url = $url;
1288 } else {
1289 $fw_url = 'http://www.woothemes.com/updates/functions-changelog.txt';
1290 }
1291
1292 $output = array( 'version' => '', 'is_critical' => false );
1293
1294 $version_data = get_transient( 'wooframework_version_data' );
1295
1296 if ( $version_data != '' && $check_if_critical == false ) { return $version_data; }
1297
1298 $temp_file_addr = download_url( $fw_url );
1299 if( ! is_wp_error( $temp_file_addr ) && $file_contents = file( $temp_file_addr ) ) {
1300 foreach ( $file_contents as $line_num => $line ) {
1301 $current_line = $line;
1302
1303 if( $line_num > 1 ) { // Not the first or second... dodgy :P
1304
1305 if ( preg_match( '/^[0-9]/', $line ) ) {
1306
1307 // Do critical update check.
1308 if ( $check_if_critical && ( strtolower( trim( substr( $line, -10 ) ) ) == 'critical' ) ) {
1309 $output['is_critical'] = true;
1310 }
1311
1312 $current_line = stristr( $current_line, 'version' );
1313 $current_line = preg_replace( '~[^0-9,.]~','',$current_line );
1314 $output['version'] = $current_line;
1315 break;
1316 }
1317 }
1318 }
1319 unlink( $temp_file_addr );
1320 } else {
1321 $output['version'] = get_option( 'woo_framework_version' );
1322 }
1323
1324 // Set the transient containing the latest version number.
1325 set_transient( 'wooframework_version_data', $output , 60*60*24 );
1326
1327 return $output;
1328} // End woo_get_fw_version()
1329
1330
1331/*-----------------------------------------------------------------------------------*/
1332/* WooFramework Version Checker */
1333/*-----------------------------------------------------------------------------------*/
1334
1335function woo_framework_version_checker( $local_version, $check_if_critical = false ) {
1336 $data = array( 'is_update' => false, 'version' => '1.0.0', 'status' => 'none' );
1337
1338 if ( ! $local_version ) { return $data; }
1339
1340 $version_data = woo_get_fw_version( '', $check_if_critical );
1341
1342 $check = version_compare( $version_data['version'], $local_version ); // Returns 1 if there is an update available.
1343
1344 if ( $check == 1 ) {
1345 $data['is_update'] = true;
1346 $data['version'] = $version_data['version'];
1347 $data['is_critical'] = $version_data['is_critical'];
1348 }
1349
1350 return $data;
1351} // End woo_framework_version_checker()
1352
1353/*-----------------------------------------------------------------------------------*/
1354/* Woo URL shortener */
1355/*-----------------------------------------------------------------------------------*/
1356
1357function woo_short_url($url) {
1358 $service = get_option( 'woo_url_shorten' );
1359 $bitlyapilogin = get_option( 'woo_bitly_api_login' );;
1360 $bitlyapikey = get_option( 'woo_bitly_api_key' );;
1361 if (isset($service)) {
1362 switch ($service)
1363 {
1364 case 'TinyURL':
1365 $shorturl = getTinyUrl($url);
1366 break;
1367 case 'Bit.ly':
1368 if (isset($bitlyapilogin) && isset($bitlyapikey) && ($bitlyapilogin != '') && ($bitlyapikey != '')) {
1369 $shorturl = make_bitly_url($url,$bitlyapilogin,$bitlyapikey,'json' );
1370 }
1371 else {
1372 $shorturl = getTinyUrl($url);
1373 }
1374 break;
1375 case 'Off':
1376 $shorturl = $url;
1377 break;
1378 default:
1379 $shorturl = $url;
1380 break;
1381 }
1382 }
1383 else {
1384 $shorturl = $url;
1385 }
1386 return $shorturl;
1387}
1388
1389//TinyURL
1390function getTinyUrl($url) {
1391 $tinyurl = file_get_contents_curl( "http://tinyurl.com/api-create.php?url=".$url);
1392 return $tinyurl;
1393}
1394
1395//Bit.ly
1396function make_bitly_url($url,$login,$appkey,$format = 'xml',$version = '2.0.1')
1397{
1398 //create the URL
1399 $bitly = 'http://api.bit.ly/shorten?version='.$version.'&longUrl='.urlencode($url).'&login='.$login.'&apiKey='.$appkey.'&format='.$format;
1400
1401 //get the url
1402 //could also use cURL here
1403 $response = file_get_contents_curl($bitly);
1404
1405 //parse depending on desired format
1406 if(strtolower($format) == 'json')
1407 {
1408 $json = @json_decode($response,true);
1409 return $json['results'][$url]['shortUrl'];
1410 }
1411 else //xml
1412 {
1413 $xml = simplexml_load_string($response);
1414 return 'http://bit.ly/'.$xml->results->nodeKeyVal->hash;
1415 }
1416}
1417
1418//Alternative CURL function
1419function file_get_contents_curl($url) {
1420 if ( $url == '' || $url == null ) { return ''; }
1421 $data = '';
1422
1423 $response = wp_remote_get( $url );
1424
1425 if ( is_wp_error( $response ) ) {
1426 $data = $url;
1427 } else {
1428 $data = $response['body'];
1429 }
1430
1431 return $data;
1432} // End file_get_contents_curl()
1433
1434// Checks for presence of the cURL extension.
1435function _iscurlinstalled() {
1436 if (in_array ( 'curl', get_loaded_extensions())) {
1437 if (function_exists( 'curl_init')) {
1438 return true;
1439 } else {
1440 return false;
1441 }
1442 }
1443 else{
1444 if (function_exists( 'curl_init')) {
1445 return true;
1446 } else {
1447 return false;
1448 }
1449 }
1450}
1451
1452/*-----------------------------------------------------------------------------------*/
1453/* woo_title() */
1454/*-----------------------------------------------------------------------------------*/
1455
1456function woo_title () {
1457 $sep = '|';
1458 $raw_title = wp_title( $sep, false, 'right' );
1459 $title = $raw_title . get_bloginfo( 'name' );
1460
1461 // Allow child themes/plugins to filter the title value.
1462 $title = apply_filters( 'woo_title', $title, $sep, $raw_title );
1463
1464 // Display the formatted title.
1465 echo $title;
1466} // End woo_title()
1467
1468/*-----------------------------------------------------------------------------------*/
1469/* woo_meta() */
1470/*-----------------------------------------------------------------------------------*/
1471
1472function woo_meta () {
1473 echo '<meta http-equiv="Content-Type" content="'. esc_attr( get_bloginfo( 'html_type' ) ) . '; charset=' . esc_attr( get_bloginfo( 'charset' ) ) . '" />' . "\n";
1474
1475 do_action( 'woo_meta' );
1476} // End woo_meta()
1477
1478/*-----------------------------------------------------------------------------------*/
1479/* Woo Text Trimmer */
1480/*-----------------------------------------------------------------------------------*/
1481
1482if ( ! function_exists( 'woo_text_trim' ) ) {
1483 function woo_text_trim( $text, $words = 50 ) {
1484 $matches = preg_split( "/\s+/", $text, $words + 1);
1485 $sz = count($matches);
1486 if ($sz > $words)
1487 {
1488 unset($matches[$sz-1]);
1489 return implode( ' ',$matches)." ...";
1490 }
1491 return $text;
1492 } // End woo_text_trim()
1493}
1494
1495/*-----------------------------------------------------------------------------------*/
1496/* Google Webfonts Array */
1497/* Documentation:
1498/*
1499/* name: The name of the Google Font.
1500/* variant: The Google Font API variants available for the font.
1501/*-----------------------------------------------------------------------------------*/
1502
1503// Available Google webfont names
1504$google_fonts = array( array( 'name' => "Cantarell", 'variant' => ':r,b,i,bi'),
1505 array( 'name' => "Cardo", 'variant' => ''),
1506 array( 'name' => "Crimson Text", 'variant' => ''),
1507 array( 'name' => "Droid Sans", 'variant' => ':r,b'),
1508 array( 'name' => "Droid Sans Mono", 'variant' => ''),
1509 array( 'name' => "Droid Serif", 'variant' => ':r,b,i,bi'),
1510 array( 'name' => "IM Fell DW Pica", 'variant' => ':r,i'),
1511 array( 'name' => "Inconsolata", 'variant' => ''),
1512 array( 'name' => "Josefin Sans", 'variant' => ':400,400italic,700,700italic'),
1513 array( 'name' => "Josefin Slab", 'variant' => ':r,b,i,bi'),
1514 array( 'name' => "Lobster", 'variant' => ''),
1515 array( 'name' => "Molengo", 'variant' => ''),
1516 array( 'name' => "Nobile", 'variant' => ':r,b,i,bi'),
1517 array( 'name' => "OFL Sorts Mill Goudy TT", 'variant' => ':r,i'),
1518 array( 'name' => "Old Standard TT", 'variant' => ':r,b,i'),
1519 array( 'name' => "Reenie Beanie", 'variant' => ''),
1520 array( 'name' => "Tangerine", 'variant' => ':r,b'),
1521 array( 'name' => "Vollkorn", 'variant' => ':r,b'),
1522 array( 'name' => "Yanone Kaffeesatz", 'variant' => ':r,b'),
1523 array( 'name' => "Cuprum", 'variant' => ''),
1524 array( 'name' => "Neucha", 'variant' => ''),
1525 array( 'name' => "Neuton", 'variant' => ''),
1526 array( 'name' => "PT Sans", 'variant' => ':r,b,i,bi'),
1527 array( 'name' => "PT Sans Caption", 'variant' => ':r,b'),
1528 array( 'name' => "PT Sans Narrow", 'variant' => ':r,b'),
1529 array( 'name' => "Philosopher", 'variant' => ''),
1530 array( 'name' => "Allerta", 'variant' => ''),
1531 array( 'name' => "Allerta Stencil", 'variant' => ''),
1532 array( 'name' => "Arimo", 'variant' => ':r,b,i,bi'),
1533 array( 'name' => "Arvo", 'variant' => ':r,b,i,bi'),
1534 array( 'name' => "Bentham", 'variant' => ''),
1535 array( 'name' => "Coda", 'variant' => ':800'),
1536 array( 'name' => "Cousine", 'variant' => ''),
1537 array( 'name' => "Covered By Your Grace", 'variant' => ''),
1538 array( 'name' => "Geo", 'variant' => ''),
1539 array( 'name' => "Just Me Again Down Here", 'variant' => ''),
1540 array( 'name' => "Puritan", 'variant' => ':r,b,i,bi'),
1541 array( 'name' => "Raleway", 'variant' => ':100'),
1542 array( 'name' => "Tinos", 'variant' => ':r,b,i,bi'),
1543 array( 'name' => "UnifrakturCook", 'variant' => ':bold'),
1544 array( 'name' => "UnifrakturMaguntia", 'variant' => ''),
1545 array( 'name' => "Mountains of Christmas", 'variant' => ''),
1546 array( 'name' => "Lato", 'variant' => ':400,700,400italic'),
1547 array( 'name' => "Orbitron", 'variant' => ':r,b,i,bi'),
1548 array( 'name' => "Allan", 'variant' => ':bold'),
1549 array( 'name' => "Anonymous Pro", 'variant' => ':r,b,i,bi'),
1550 array( 'name' => "Copse", 'variant' => ''),
1551 array( 'name' => "Kenia", 'variant' => ''),
1552 array( 'name' => "Ubuntu", 'variant' => ':r,b,i,bi'),
1553 array( 'name' => "Vibur", 'variant' => ''),
1554 array( 'name' => "Sniglet", 'variant' => ':800'),
1555 array( 'name' => "Syncopate", 'variant' => ''),
1556 array( 'name' => "Cabin", 'variant' => ':400,400italic,700,700italic,'),
1557 array( 'name' => "Merriweather", 'variant' => ''),
1558 array( 'name' => "Maiden Orange", 'variant' => ''),
1559 array( 'name' => "Just Another Hand", 'variant' => ''),
1560 array( 'name' => "Kristi", 'variant' => ''),
1561 array( 'name' => "Corben", 'variant' => ':b'),
1562 array( 'name' => "Gruppo", 'variant' => ''),
1563 array( 'name' => "Buda", 'variant' => ':light'),
1564 array( 'name' => "Lekton", 'variant' => ''),
1565 array( 'name' => "Luckiest Guy", 'variant' => ''),
1566 array( 'name' => "Crushed", 'variant' => ''),
1567 array( 'name' => "Chewy", 'variant' => ''),
1568 array( 'name' => "Coming Soon", 'variant' => ''),
1569 array( 'name' => "Crafty Girls", 'variant' => ''),
1570 array( 'name' => "Fontdiner Swanky", 'variant' => ''),
1571 array( 'name' => "Permanent Marker", 'variant' => ''),
1572 array( 'name' => "Rock Salt", 'variant' => ''),
1573 array( 'name' => "Sunshiney", 'variant' => ''),
1574 array( 'name' => "Unkempt", 'variant' => ''),
1575 array( 'name' => "Calligraffitti", 'variant' => ''),
1576 array( 'name' => "Cherry Cream Soda", 'variant' => ''),
1577 array( 'name' => "Homemade Apple", 'variant' => ''),
1578 array( 'name' => "Irish Growler", 'variant' => ''),
1579 array( 'name' => "Kranky", 'variant' => ''),
1580 array( 'name' => "Schoolbell", 'variant' => ''),
1581 array( 'name' => "Slackey", 'variant' => ''),
1582 array( 'name' => "Walter Turncoat", 'variant' => ''),
1583 array( 'name' => "Radley", 'variant' => ''),
1584 array( 'name' => "Meddon", 'variant' => ''),
1585 array( 'name' => "Kreon", 'variant' => ':r,b'),
1586 array( 'name' => "Dancing Script", 'variant' => ''),
1587 array( 'name' => "Goudy Bookletter 1911", 'variant' => ''),
1588 array( 'name' => "PT Serif Caption", 'variant' => ':r,i'),
1589 array( 'name' => "PT Serif", 'variant' => ':r,b,i,bi'),
1590 array( 'name' => "Astloch", 'variant' => ':b'),
1591 array( 'name' => "Bevan", 'variant' => ''),
1592 array( 'name' => "Anton", 'variant' => ''),
1593 array( 'name' => "Expletus Sans", 'variant' => ':b'),
1594 array( 'name' => "VT323", 'variant' => ''),
1595 array( 'name' => "Pacifico", 'variant' => ''),
1596 array( 'name' => "Candal", 'variant' => ''),
1597 array( 'name' => "Architects Daughter", 'variant' => ''),
1598 array( 'name' => "Indie Flower", 'variant' => ''),
1599 array( 'name' => "League Script", 'variant' => ''),
1600 array( 'name' => "Quattrocento", 'variant' => ''),
1601 array( 'name' => "Amaranth", 'variant' => ''),
1602 array( 'name' => "Irish Grover", 'variant' => ''),
1603 array( 'name' => "Oswald", 'variant' => ':400,300,700'),
1604 array( 'name' => "EB Garamond", 'variant' => ''),
1605 array( 'name' => "Nova Round", 'variant' => ''),
1606 array( 'name' => "Nova Slim", 'variant' => ''),
1607 array( 'name' => "Nova Script", 'variant' => ''),
1608 array( 'name' => "Nova Cut", 'variant' => ''),
1609 array( 'name' => "Nova Mono", 'variant' => ''),
1610 array( 'name' => "Nova Oval", 'variant' => ''),
1611 array( 'name' => "Nova Flat", 'variant' => ''),
1612 array( 'name' => "Terminal Dosis Light", 'variant' => ''),
1613 array( 'name' => "Michroma", 'variant' => ''),
1614 array( 'name' => "Miltonian", 'variant' => ''),
1615 array( 'name' => "Miltonian Tattoo", 'variant' => ''),
1616 array( 'name' => "Annie Use Your Telescope", 'variant' => ''),
1617 array( 'name' => "Dawning of a New Day", 'variant' => ''),
1618 array( 'name' => "Sue Ellen Francisco", 'variant' => ''),
1619 array( 'name' => "Waiting for the Sunrise", 'variant' => ''),
1620 array( 'name' => "Special Elite", 'variant' => ''),
1621 array( 'name' => "Quattrocento Sans", 'variant' => ''),
1622 array( 'name' => "Smythe", 'variant' => ''),
1623 array( 'name' => "The Girl Next Door", 'variant' => ''),
1624 array( 'name' => "Aclonica", 'variant' => ''),
1625 array( 'name' => "News Cycle", 'variant' => ''),
1626 array( 'name' => "Damion", 'variant' => ''),
1627 array( 'name' => "Wallpoet", 'variant' => ''),
1628 array( 'name' => "Over the Rainbow", 'variant' => ''),
1629 array( 'name' => "MedievalSharp", 'variant' => ''),
1630 array( 'name' => "Six Caps", 'variant' => ''),
1631 array( 'name' => "Swanky and Moo Moo", 'variant' => ''),
1632 array( 'name' => "Bigshot One", 'variant' => ''),
1633 array( 'name' => "Francois One", 'variant' => ''),
1634 array( 'name' => "Sigmar One", 'variant' => ''),
1635 array( 'name' => "Carter One", 'variant' => ''),
1636 array( 'name' => "Holtwood One SC", 'variant' => ''),
1637 array( 'name' => "Paytone One", 'variant' => ''),
1638 array( 'name' => "Monofett", 'variant' => ''),
1639 array( 'name' => "Rokkitt", 'variant' => ':400,700'),
1640 array( 'name' => "Megrim", 'variant' => ''),
1641 array( 'name' => "Judson", 'variant' => ':r,ri,b'),
1642 array( 'name' => "Didact Gothic", 'variant' => ''),
1643 array( 'name' => "Play", 'variant' => ':r,b'),
1644 array( 'name' => "Ultra", 'variant' => ''),
1645 array( 'name' => "Metrophobic", 'variant' => ''),
1646 array( 'name' => "Mako", 'variant' => ''),
1647 array( 'name' => "Shanti", 'variant' => ''),
1648 array( 'name' => "Caudex", 'variant' => ':r,b,i,bi'),
1649 array( 'name' => "Jura", 'variant' => ''),
1650 array( 'name' => "Ruslan Display", 'variant' => ''),
1651 array( 'name' => "Brawler", 'variant' => ''),
1652 array( 'name' => "Nunito", 'variant' => ''),
1653 array( 'name' => "Wire One", 'variant' => ''),
1654 array( 'name' => "Podkova", 'variant' => ''),
1655 array( 'name' => "Muli", 'variant' => ''),
1656 array( 'name' => "Maven Pro", 'variant' => ':400,500,700'),
1657 array( 'name' => "Tenor Sans", 'variant' => ''),
1658 array( 'name' => "Limelight", 'variant' => ''),
1659 array( 'name' => "Playfair Display", 'variant' => ''),
1660 array( 'name' => "Artifika", 'variant' => ''),
1661 array( 'name' => "Lora", 'variant' => ''),
1662 array( 'name' => "Kameron", 'variant' => ':r,b'),
1663 array( 'name' => "Cedarville Cursive", 'variant' => ''),
1664 array( 'name' => "Zeyada", 'variant' => ''),
1665 array( 'name' => "La Belle Aurore", 'variant' => ''),
1666 array( 'name' => "Shadows Into Light", 'variant' => ''),
1667 array( 'name' => "Lobster Two", 'variant' => ':r,b,i,bi'),
1668 array( 'name' => "Nixie One", 'variant' => ''),
1669 array( 'name' => "Redressed", 'variant' => ''),
1670 array( 'name' => "Bangers", 'variant' => ''),
1671 array( 'name' => "Open Sans Condensed", 'variant' => ':300italic,400italic,700italic,400,300,700'),
1672 array( 'name' => "Open Sans", 'variant' => ':r,i,b,bi'),
1673 array( 'name' => "Varela", 'variant' => ''),
1674 array( 'name' => "Goblin One", 'variant' => ''),
1675 array( 'name' => "Asset", 'variant' => ''),
1676 array( 'name' => "Gravitas One", 'variant' => ''),
1677 array( 'name' => "Hammersmith One", 'variant' => ''),
1678 array( 'name' => "Stardos Stencil", 'variant' => ''),
1679 array( 'name' => "Love Ya Like A Sister", 'variant' => ''),
1680 array( 'name' => "Loved by the King", 'variant' => ''),
1681 array( 'name' => "Bowlby One SC", 'variant' => ''),
1682 array( 'name' => "Forum", 'variant' => ''),
1683 array( 'name' => "Patrick Hand", 'variant' => ''),
1684 array( 'name' => "Varela Round", 'variant' => ''),
1685 array( 'name' => "Yeseva One", 'variant' => ''),
1686 array( 'name' => "Give You Glory", 'variant' => ''),
1687 array( 'name' => "Modern Antiqua", 'variant' => ''),
1688 array( 'name' => "Bowlby One", 'variant' => ''),
1689 array( 'name' => "Tienne", 'variant' => ''),
1690 array( 'name' => "Istok Web", 'variant' => ':r,b,i,bi'),
1691 array( 'name' => "Yellowtail", 'variant' => ''),
1692 array( 'name' => "Pompiere", 'variant' => ''),
1693 array( 'name' => "Unna", 'variant' => ''),
1694 array( 'name' => "Rosario", 'variant' => ''),
1695 array( 'name' => "Leckerli One", 'variant' => ''),
1696 array( 'name' => "Snippet", 'variant' => ''),
1697 array( 'name' => "Ovo", 'variant' => ''),
1698 array( 'name' => "IM Fell English", 'variant' => ':r,i'),
1699 array( 'name' => "IM Fell English SC", 'variant' => ''),
1700 array( 'name' => "Gloria Hallelujah", 'variant' => ''),
1701 array( 'name' => "Kelly Slab", 'variant' => ''),
1702 array( 'name' => "Black Ops One", 'variant' => ''),
1703 array( 'name' => "Carme", 'variant' => ''),
1704 array( 'name' => "Aubrey", 'variant' => ''),
1705 array( 'name' => "Federo", 'variant' => ''),
1706 array( 'name' => "Delius", 'variant' => ''),
1707 array( 'name' => "Rochester", 'variant' => ''),
1708 array( 'name' => "Rationale", 'variant' => ''),
1709 array( 'name' => "Abel", 'variant' => ''),
1710 array( 'name' => "Marvel", 'variant' => ':r,b,i,bi'),
1711 array( 'name' => "Actor", 'variant' => ''),
1712 array( 'name' => "Delius Swash Caps", 'variant' => ''),
1713 array( 'name' => "Smokum", 'variant' => ''),
1714 array( 'name' => "Tulpen One", 'variant' => ''),
1715 array( 'name' => "Coustard", 'variant' => ':r,b'),
1716 array( 'name' => "Andika", 'variant' => ''),
1717 array( 'name' => "Alice", 'variant' => ''),
1718 array( 'name' => "Questrial", 'variant' => ''),
1719 array( 'name' => "Comfortaa", 'variant' => ':r,b'),
1720 array( 'name' => "Geostar", 'variant' => ''),
1721 array( 'name' => "Geostar Fill", 'variant' => ''),
1722 array( 'name' => "Volkhov", 'variant' => ''),
1723 array( 'name' => "Voltaire", 'variant' => ''),
1724 array( 'name' => "Montez", 'variant' => ''),
1725 array( 'name' => "Short Stack", 'variant' => ''),
1726 array( 'name' => "Vidaloka", 'variant' => ''),
1727 array( 'name' => "Aldrich", 'variant' => ''),
1728 array( 'name' => "Numans", 'variant' => ''),
1729 array( 'name' => "Days One", 'variant' => ''),
1730 array( 'name' => "Gentium Book Basic", 'variant' => ''),
1731 array( 'name' => "Monoton", 'variant' => ''),
1732 array( 'name' => "Alike", 'variant' => ''),
1733 array( 'name' => "Delius Unicase", 'variant' => ''),
1734 array( 'name' => "Abril Fatface", 'variant' => ''),
1735 array( 'name' => "Dorsa", 'variant' => ''),
1736 array( 'name' => "Antic", 'variant' => ''),
1737 array( 'name' => "Passero One", 'variant' => ''),
1738 array( 'name' => "Fanwood Text", 'variant' => ''),
1739 array( 'name' => "Prociono", 'variant' => ''),
1740 array( 'name' => "Merienda One", 'variant' => ''),
1741 array( 'name' => "Changa One", 'variant' => ''),
1742 array( 'name' => "Julee", 'variant' => ''),
1743 array( 'name' => "Prata", 'variant' => ''),
1744 array( 'name' => "Adamina", 'variant' => ''),
1745 array( 'name' => "Sorts Mill Goudy", 'variant' => ''),
1746 array( 'name' => "Terminal Dosis", 'variant' => ''),
1747 array( 'name' => "Sansita One", 'variant' => ''),
1748 array( 'name' => "Chivo", 'variant' => ''),
1749 array( 'name' => "Spinnaker", 'variant' => ''),
1750 array( 'name' => "Poller One", 'variant' => ''),
1751 array( 'name' => "Alike Angular", 'variant' => ''),
1752 array( 'name' => "Gochi Hand", 'variant' => ''),
1753 array( 'name' => "Poly", 'variant' => ''),
1754 array( 'name' => "Andada", 'variant' => ''),
1755 array( 'name' => "Federant", 'variant' => ''),
1756 array( 'name' => "Ubuntu Condensed", 'variant' => ''),
1757 array( 'name' => "Ubuntu Mono", 'variant' => ''),
1758 array( 'name' => "Sancreek", 'variant' => ''),
1759 array( 'name' => "Coda", 'variant' => ''),
1760 array( 'name' => "Rancho", 'variant' => ''),
1761 array( 'name' => "Satisfy", 'variant' => ''),
1762 array( 'name' => "Pinyon Script", 'variant' => ''),
1763 array( 'name' => "Vast Shadow", 'variant' => ''),
1764 array( 'name' => "Marck Script", 'variant' => ''),
1765 array( 'name' => "Salsa", 'variant' => ''),
1766 array( 'name' => "Amatic SC", 'variant' => ''),
1767 array( 'name' => "Quicksand", 'variant' => ''),
1768 array( 'name' => "Linden Hill", 'variant' => ''),
1769 array( 'name' => "Corben", 'variant' => ''),
1770 array( 'name' => "Creepster Caps", 'variant' => ''),
1771 array( 'name' => "Butcherman Caps", 'variant' => ''),
1772 array( 'name' => "Eater Caps", 'variant' => ''),
1773 array( 'name' => "Nosifer Caps", 'variant' => ''),
1774 array( 'name' => "Atomic Age", 'variant' => ''),
1775 array( 'name' => "Contrail One", 'variant' => ''),
1776 array( 'name' => "Jockey One", 'variant' => ''),
1777 array( 'name' => "Cabin Sketch", 'variant' => ':r,b'),
1778 array( 'name' => "Cabin Condensed", 'variant' => ':r,b'),
1779 array( 'name' => "Fjord One", 'variant' => ''),
1780 array( 'name' => "Rametto One", 'variant' => ''),
1781 array( 'name' => "Mate", 'variant' => ':r,i'),
1782 array( 'name' => "Mate SC", 'variant' => ''),
1783 array( 'name' => "Arapey", 'variant' => ':r,i'),
1784 array( 'name' => "Supermercado One", 'variant' => ''),
1785 array( 'name' => "Petrona", 'variant' => ''),
1786 array( 'name' => "Lancelot", 'variant' => ''),
1787 array( 'name' => "Convergence", 'variant' => ''),
1788 array( 'name' => "Cutive", 'variant' => ''),
1789 array( 'name' => "Karla", 'variant' => ':400,400italic,700,700italic'),
1790 array( 'name' => "Bitter", 'variant' => ':r,i,b'),
1791 array( 'name' => "Asap", 'variant' => ':400,700,400italic,700italic'),
1792 array( 'name' => "Bree Serif", 'variant' => '')
1793
1794);
1795
1796
1797/*-----------------------------------------------------------------------------------*/
1798/* Google Webfonts Stylesheet Generator */
1799/*-----------------------------------------------------------------------------------*/
1800/*
1801INSTRUCTIONS: Needs to be loaded for the Google Fonts options to work for font options. Add this to
1802the specific themes includes/theme-actions.php or functions.php:
1803
1804add_action( 'wp_head', 'woo_google_webfonts' );
1805*/
1806
1807if ( ! function_exists( 'woo_google_webfonts' ) ) {
1808 function woo_google_webfonts() {
1809 global $google_fonts;
1810 $fonts = '';
1811 $output = '';
1812
1813 // Setup Woo Options array
1814 global $woo_options;
1815
1816 // Go through the options
1817 if ( !empty($woo_options) ) {
1818 foreach ( $woo_options as $option ) {
1819 // Check if option has "face" in array
1820 if ( is_array($option) && isset($option['face']) ) {
1821 // Go through the google font array
1822 foreach ($google_fonts as $font) {
1823 // Check if the google font name exists in the current "face" option
1824 if ( $option['face'] == $font['name'] AND !strstr($fonts, $font['name']) ) {
1825 // Add google font to output
1826 // $fonts .= $font['name'].$font['variant']."|";
1827 $fonts .= $font['name'].":100,100i,300,300i,400,400i,500,500i,700,700i,800,800i,900,900i"."|";
1828 } // End If Statement
1829 } // End Foreach Loop
1830 } // End If Statement
1831 } // End Foreach Loop
1832
1833 // Output google font css in header
1834 if ( $fonts ) {
1835 $fonts = str_replace( " ","+",$fonts);
1836 $output .= "\n<!-- Google Webfonts -->\n";
1837 $output .= '<link href="http'. ( is_ssl() ? 's' : '' ) .'://fonts.googleapis.com/css?family=' . $fonts .'" rel="stylesheet" type="text/css" />'."\n";
1838 $output = str_replace( '|"','"',$output);
1839
1840 echo $output;
1841 }
1842 }
1843 } // End woo_google_webfonts()
1844}
1845
1846
1847/*-----------------------------------------------------------------------------------*/
1848/* Enable Home link in WP Menus
1849/*-----------------------------------------------------------------------------------*/
1850if ( !function_exists( 'woo_home_page_menu_args' ) ) {
1851 function woo_home_page_menu_args( $args ) {
1852 $args['show_home'] = true;
1853 return $args;
1854 } // End woo_home_page_menu_args()
1855 add_filter( 'wp_page_menu_args', 'woo_home_page_menu_args' );
1856}
1857
1858/*---------------------------------------------------------------------------------*/
1859/* Detects the Charset of String and Converts it to UTF-8 */
1860/*---------------------------------------------------------------------------------*/
1861if ( !function_exists( 'woo_encoding_convert') ) {
1862 function woo_encoding_convert($str_to_convert) {
1863 if ( function_exists( 'mb_detect_encoding') ) {
1864 $str_lang_encoding = mb_detect_encoding($str_to_convert);
1865 //if no encoding detected, assume UTF-8
1866 if (!$str_lang_encoding) {
1867 //UTF-8 assumed
1868 $str_lang_converted_utf = $str_to_convert;
1869 } else {
1870 //Convert to UTF-8
1871 $str_lang_converted_utf = mb_convert_encoding($str_to_convert, 'UTF-8', $str_lang_encoding);
1872 }
1873 } else {
1874 $str_lang_converted_utf = $str_to_convert;
1875 }
1876
1877 return $str_lang_converted_utf;
1878 }
1879}
1880
1881/*---------------------------------------------------------------------------------*/
1882/* WP Login logo */
1883/*---------------------------------------------------------------------------------*/
1884if ( !function_exists( 'woo_custom_login_logo' ) ) {
1885 function woo_custom_login_logo() {
1886 $logo = get_option( 'framework_woo_custom_login_logo' );
1887 $dimensions = @getimagesize( $logo );
1888 $background_size = 'background-size: auto;';
1889 if ( 0 >= $dimensions[1] ) {
1890 $dimensions[1] = '67';
1891 $background_size = '';
1892 }
1893
1894 echo '<style type="text/css">body #login h1 a { background-image:url( ' . esc_url( $logo ) . ' ); height: ' . intval( $dimensions[1] ) . 'px; width: auto; ' . $background_size . ' }</style>';
1895 } // End woo_custom_login_logo()
1896 if ( '' != get_option( 'framework_woo_custom_login_logo') ) {
1897 add_action( 'login_head', 'woo_custom_login_logo' );
1898 }
1899}
1900
1901/*---------------------------------------------------------------------------------*/
1902/* WP Login logo URL */
1903/*---------------------------------------------------------------------------------*/
1904if ( ! function_exists( 'woo_custom_login_logo_url' ) ) {
1905 function woo_custom_login_logo_url( $text ) {
1906 return get_option( 'framework_woo_custom_login_logo_url' ); // Escaping via esc_url() is done in wp-login.php.
1907 } // End woo_custom_login_logo_url()
1908
1909 if ( '' != get_option( 'framework_woo_custom_login_logo_url' ) ) {
1910 add_filter( 'login_headerurl', 'woo_custom_login_logo_url', 10 );
1911 }
1912}
1913
1914/*---------------------------------------------------------------------------------*/
1915/* WP Login logo title */
1916/*---------------------------------------------------------------------------------*/
1917if ( ! function_exists( 'woo_custom_login_logo_title' ) ) {
1918 function woo_custom_login_logo_title( $text ) {
1919 return get_option( 'framework_woo_custom_login_logo_title' ); // Escaping via esc_attr() is done in wp-login.php.
1920 } // End woo_custom_login_logo_title()
1921
1922 if ( '' != get_option( 'framework_woo_custom_login_logo_title' ) ) {
1923 add_filter( 'login_headertitle', 'woo_custom_login_logo_title', 10 );
1924 }
1925}
1926
1927/*-----------------------------------------------------------------------------------*/
1928/* woo_pagination() - Custom loop pagination function */
1929/*-----------------------------------------------------------------------------------*/
1930/*
1931/* Additional documentation: http://codex.wordpress.org/Function_Reference/paginate_links
1932/*
1933/* Params:
1934/*
1935/* Arguments Array:
1936/*
1937/* 'base' (optional) - The query argument on which to determine the pagination (for advanced users)
1938/* 'format' (optional) - The format in which the query argument is formatted in it's raw format (for advanced users)
1939/* 'total' (optional) - The total amount of pages
1940/* 'current' (optional) - The current page number
1941/* 'prev_next' (optional) - Whether to include the previous and next links in the list or not.
1942/* 'prev_text' (optional) - The previous page text. Works only if 'prev_next' argument is set to true.
1943/* 'next_text' (optional) - The next page text. Works only if 'prev_next' argument is set to true.
1944/* 'show_all' (optional) - If set to True, then it will show all of the pages instead of a short list of the pages near the current page. By default, the 'show_all' is set to false and controlled by the 'end_size' and 'mid_size' arguments.
1945/* 'end_size' (optional) - How many numbers on either the start and the end list edges.
1946/* 'mid_size' (optional) - How many numbers to either side of current page, but not including current page.
1947/* 'add_fragment' (optional) - An array of query args to add using add_query_arg().
1948/* 'type' (optional) - Controls format of the returned value. Possible values are:
1949 'plain' - A string with the links separated by a newline character.
1950 'array' - An array of the paginated link list to offer full control of display.
1951 'list' - Unordered HTML list.
1952/* 'before' (optional) - The HTML to display before the paginated links.
1953/* 'after' (optional) - The HTML to display after the paginated links.
1954/* 'echo' (optional) - Whether or not to display the paginated links (alternative is to "return").
1955/* 'use_search_permastruct' (optiona;) - Whether or not to use the "pretty" URL permastruct for search URLs.
1956/*
1957/* Query Parameter (optional) - Specify a custom query which you'd like to paginate.
1958/*
1959/*-----------------------------------------------------------------------------------*/
1960/**
1961 * woo_pagination() is used for paginating the various archive pages created by WordPress. This is not
1962 * to be used on single.php or other single view pages.
1963 *
1964 * @since 3.7.0
1965 * @uses paginate_links() Creates a string of paginated links based on the arguments given.
1966 * @param array $args Arguments to customize how the page links are output.
1967 * @param object $query An optional custom query to paginate.
1968 */
1969
1970if ( ! function_exists( 'woo_pagination' ) ) {
1971 function woo_pagination( $args = array(), $query = '' ) {
1972 global $wp_rewrite, $wp_query;
1973
1974 do_action( 'woo_pagination_start' );
1975
1976 if ( $query ) {
1977
1978 $wp_query = $query;
1979
1980 } // End IF Statement
1981
1982 /* If there's not more than one page, return nothing. */
1983 if ( 1 >= $wp_query->max_num_pages )
1984 return;
1985
1986 /* Get the current page. */
1987 $current = ( get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1 );
1988
1989 /* Get the max number of pages. */
1990 $max_num_pages = intval( $wp_query->max_num_pages );
1991
1992 /* Set up some default arguments for the paginate_links() function. */
1993 $defaults = array(
1994 'base' => add_query_arg( 'paged', '%#%' ),
1995 'format' => '',
1996 'total' => $max_num_pages,
1997 'current' => $current,
1998 'prev_next' => true,
1999 'prev_text' => __( '<i class="fa fa-caret-left"></i>', 'woothemes' ), // Translate in WordPress. This is the default.
2000 'next_text' => __( '<i class="fa fa-caret-right"></i>', 'woothemes' ), // Translate in WordPress. This is the default.
2001 'show_all' => false,
2002 'end_size' => 1,
2003 'mid_size' => 1,
2004 'add_fragment' => '',
2005 'type' => 'plain',
2006 'before' => '<div class="pagination woo-pagination">', // Begin woo_pagination() arguments.
2007 'after' => '</div>',
2008 'echo' => true,
2009 'use_search_permastruct' => true
2010 );
2011
2012 /* Allow themes/plugins to filter the default arguments. */
2013 $defaults = apply_filters( 'woo_pagination_args_defaults', $defaults );
2014
2015 /* Add the $base argument to the array if the user is using permalinks. */
2016 if( $wp_rewrite->using_permalinks() && ! is_search() )
2017 $defaults['base'] = user_trailingslashit( trailingslashit( get_pagenum_link() ) . 'page/%#%' );
2018
2019 /* Force search links to use raw permastruct for more accurate multi-word searching. */
2020 if ( is_search() )
2021 $defaults['use_search_permastruct'] = false;
2022
2023 /* If we're on a search results page, we need to change this up a bit. */
2024 if ( is_search() ) {
2025 /* If we're in BuddyPress, or the user has selected to do so, use the default "unpretty" URL structure. */
2026 if ( class_exists( 'BP_Core_User' ) || $defaults['use_search_permastruct'] == false ) {
2027 $search_query = get_query_var( 's' );
2028 $paged = get_query_var( 'paged' );
2029 $base = add_query_arg( 's', urlencode( $search_query ) );
2030 $base = add_query_arg( 'paged', '%#%' );
2031 $defaults['base'] = $base;
2032 } else {
2033 $search_permastruct = $wp_rewrite->get_search_permastruct();
2034 if ( ! empty( $search_permastruct ) ) {
2035 $base = get_search_link();
2036 $base = add_query_arg( 'paged', '%#%', $base );
2037 $defaults['base'] = $base;
2038 }
2039 }
2040 }
2041
2042 /* Merge the arguments input with the defaults. */
2043 $args = wp_parse_args( $args, $defaults );
2044
2045 /* Allow developers to overwrite the arguments with a filter. */
2046 $args = apply_filters( 'woo_pagination_args', $args );
2047
2048 /* Don't allow the user to set this to an array. */
2049 if ( 'array' == $args['type'] )
2050 $args['type'] = 'plain';
2051
2052 /* Make sure raw querystrings are displayed at the end of the URL, if using pretty permalinks. */
2053 $pattern = '/\?(.*?)\//i';
2054
2055 preg_match( $pattern, $args['base'], $raw_querystring );
2056
2057 if( $wp_rewrite->using_permalinks() && $raw_querystring )
2058 $raw_querystring[0] = str_replace( '', '', $raw_querystring[0] );
2059 @$args['base'] = str_replace( isset($raw_querystring[0]), '', $args['base'] );
2060 @$args['base'] .= substr( isset($raw_querystring[0]), 0, -1 );
2061
2062 /* Get the paginated links. */
2063 $page_links = paginate_links( $args );
2064
2065 /* Remove 'page/1' from the entire output since it's not needed. */
2066 $page_links = str_replace( array( '&paged=1\'', '/page/1\'' ), '\'', $page_links );
2067
2068 /* Wrap the paginated links with the $before and $after elements. */
2069 $page_links = $args['before'] . $page_links . $args['after'];
2070
2071 /* Allow devs to completely overwrite the output. */
2072 $page_links = apply_filters( 'woo_pagination', $page_links );
2073
2074 do_action( 'woo_pagination_end' );
2075
2076 /* Return the paginated links for use in themes. */
2077 if ( $args['echo'] )
2078 echo $page_links;
2079 else
2080 return $page_links;
2081 } // End woo_pagination()
2082} // End IF Statement
2083
2084/*-----------------------------------------------------------------------------------*/
2085/* woo_breadcrumbs() - Custom breadcrumb generator function */
2086/*
2087/* Params:
2088/*
2089/* Arguments Array:
2090/*
2091/* 'separator' - The character to display between the breadcrumbs.
2092/* 'before' - HTML to display before the breadcrumbs.
2093/* 'after' - HTML to display after the breadcrumbs.
2094/* 'front_page' - Include the front page at the beginning of the breadcrumbs.
2095/* 'show_home' - If $show_home is set and we're not on the front page of the site, link to the home page.
2096/* 'echo' - Specify whether or not to echo the breadcrumbs. Alternative is "return".
2097/* 'show_posts_page' - If a static front page is set and there is a posts page, toggle whether or not to display that page's tree.
2098/*
2099/*-----------------------------------------------------------------------------------*/
2100/**
2101 * The code below is inspired by Justin Tadlock's Hybrid Core.
2102 *
2103 * woo_breadcrumbs() shows a breadcrumb for all types of pages. Themes and plugins can filter $args or input directly.
2104 * Allow filtering of only the $args using get_the_breadcrumb_args.
2105 *
2106 * @since 3.7.0
2107 * @param array $args Mixed arguments for the menu.
2108 * @return string Output of the breadcrumb menu.
2109 */
2110function woo_breadcrumbs( $args = array() ) {
2111 global $wp_query, $wp_rewrite;
2112
2113 /* Create an empty variable for the breadcrumb. */
2114 $breadcrumb = '';
2115
2116 /* Create an empty array for the trail. */
2117 $trail = array();
2118 $path = '';
2119
2120 /* Set up the default arguments for the breadcrumb. */
2121 $defaults = array(
2122 'separator' => '>',
2123 'before' => '<span class="breadcrumb-title">' . __( 'You are here:', 'woothemes' ) . '</span>',
2124 'after' => false,
2125 'front_page' => false,
2126 'show_home' => __( 'Home', 'woothemes' ),
2127 'echo' => true,
2128 'show_posts_page' => true
2129 );
2130
2131 /* Allow singular post views to have a taxonomy's terms prefixing the trail. */
2132 if ( is_singular() )
2133 $defaults["singular_{$wp_query->post->post_type}_taxonomy"] = false;
2134
2135 /* Apply filters to the arguments. */
2136 $args = apply_filters( 'woo_breadcrumbs_args', $args );
2137
2138 /* Parse the arguments and extract them for easy variable naming. */
2139 extract( wp_parse_args( $args, $defaults ) );
2140
2141 /* If $show_home is set and we're not on the front page of the site, link to the home page. */
2142 if ( !is_front_page() && $show_home )
2143 $trail[] = '<a href="' . esc_url( home_url() ) . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '" rel="home" class="trail-begin">' . esc_html( $show_home ) . '</a>';
2144
2145 /* If viewing the front page of the site. */
2146 if ( is_front_page() ) {
2147 if ( !$front_page )
2148 $trail = false;
2149 elseif ( $show_home )
2150 $trail['trail_end'] = "{$show_home}";
2151 }
2152
2153 /* If viewing the "home"/posts page. */
2154 elseif ( is_home() ) {
2155 $home_page = get_page( $wp_query->get_queried_object_id() );
2156 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( $home_page->post_parent, '' ) );
2157 $trail['trail_end'] = get_the_title( $home_page->ID );
2158 }
2159
2160 /* If viewing a singular post (page, attachment, etc.). */
2161 elseif ( is_singular() ) {
2162
2163 /* Get singular post variables needed. */
2164 $post = $wp_query->get_queried_object();
2165 $post_id = absint( $wp_query->get_queried_object_id() );
2166 $post_type = $post->post_type;
2167 $parent = $post->post_parent;
2168
2169 /* If a custom post type, check if there are any pages in its hierarchy based on the slug. */
2170 if ( 'page' !== $post_type && 'post' !== $post_type ) {
2171
2172 $post_type_object = get_post_type_object( $post_type );
2173
2174 /* If $front has been set, add it to the $path. */
2175 if ( 'post' == $post_type || 'attachment' == $post_type || ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front ) )
2176 $path .= trailingslashit( $wp_rewrite->front );
2177
2178 /* If there's a slug, add it to the $path. */
2179 if ( !empty( $post_type_object->rewrite['slug'] ) )
2180 $path .= $post_type_object->rewrite['slug'];
2181
2182 /* If there's a path, check for parents. */
2183 if ( !empty( $path ) && '/' != $path )
2184 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( '', $path ) );
2185
2186 /* If there's an archive page, add it to the trail. */
2187 if ( !empty( $post_type_object->has_archive ) && function_exists( 'get_post_type_archive_link' ) )
2188 $trail[] = '<a href="' . get_post_type_archive_link( $post_type ) . '" title="' . esc_attr( $post_type_object->labels->name ) . '">' . $post_type_object->labels->name . '</a>';
2189 }
2190
2191 /* If the post type path returns nothing and there is a parent, get its parents. */
2192 if ( empty( $path ) && 0 !== $parent || 'attachment' == $post_type )
2193 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( $parent, '' ) );
2194
2195 /* Toggle the display of the posts page on single blog posts. */
2196 if ( 'post' == $post_type && $show_posts_page == true && 'page' == get_option( 'show_on_front' ) ) {
2197 $posts_page = get_option( 'page_for_posts' );
2198 if ( $posts_page != '' && is_numeric( $posts_page ) ) {
2199 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( $posts_page, '' ) );
2200 }
2201 }
2202
2203 /* Display terms for specific post type taxonomy if requested. */
2204 if ( isset( $args["singular_{$post_type}_taxonomy"] ) && $terms = get_the_term_list( $post_id, $args["singular_{$post_type}_taxonomy"], '', ', ', '' ) )
2205 $trail[] = $terms;
2206
2207 /* End with the post title. */
2208 $post_title = get_the_title( $post_id ); // Force the post_id to make sure we get the correct page title.
2209 if ( !empty( $post_title ) )
2210 $trail['trail_end'] = $post_title;
2211 }
2212
2213 /* If we're viewing any type of archive. */
2214 elseif ( is_archive() ) {
2215
2216 /* If viewing a taxonomy term archive. */
2217 if ( is_tax() || is_category() || is_tag() ) {
2218
2219 /* Get some taxonomy and term variables. */
2220 $term = $wp_query->get_queried_object();
2221 $taxonomy = get_taxonomy( $term->taxonomy );
2222
2223 /* Get the path to the term archive. Use this to determine if a page is present with it. */
2224 if ( is_category() )
2225 $path = get_option( 'category_base' );
2226 elseif ( is_tag() )
2227 $path = get_option( 'tag_base' );
2228 else {
2229 if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
2230 $path = trailingslashit( $wp_rewrite->front );
2231 $path .= $taxonomy->rewrite['slug'];
2232 }
2233
2234 /* Get parent pages by path if they exist. */
2235 if ( $path )
2236 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( '', $path ) );
2237
2238 /* If the taxonomy is hierarchical, list its parent terms. */
2239 if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
2240 $trail = array_merge( $trail, woo_breadcrumbs_get_term_parents( $term->parent, $term->taxonomy ) );
2241
2242 /* Add the term name to the trail end. */
2243 $trail['trail_end'] = $term->name;
2244 }
2245
2246 /* If viewing a post type archive. */
2247 elseif ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
2248
2249 /* Get the post type object. */
2250 $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
2251
2252 /* If $front has been set, add it to the $path. */
2253 if ( $post_type_object->rewrite['with_front'] && $wp_rewrite->front )
2254 $path .= trailingslashit( $wp_rewrite->front );
2255
2256 /* If there's a slug, add it to the $path. */
2257 if ( !empty( $post_type_object->rewrite['archive'] ) )
2258 $path .= $post_type_object->rewrite['archive'];
2259
2260 /* If there's a path, check for parents. */
2261 if ( !empty( $path ) && '/' != $path )
2262 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( '', $path ) );
2263
2264 /* Add the post type [plural] name to the trail end. */
2265 $trail['trail_end'] = $post_type_object->labels->name;
2266 }
2267
2268 /* If viewing an author archive. */
2269 elseif ( is_author() ) {
2270
2271 /* If $front has been set, add it to $path. */
2272 if ( !empty( $wp_rewrite->front ) )
2273 $path .= trailingslashit( $wp_rewrite->front );
2274
2275 /* If an $author_base exists, add it to $path. */
2276 if ( !empty( $wp_rewrite->author_base ) )
2277 $path .= $wp_rewrite->author_base;
2278
2279 /* If $path exists, check for parent pages. */
2280 if ( !empty( $path ) )
2281 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( '', $path ) );
2282
2283 /* Add the author's display name to the trail end. */
2284 $trail['trail_end'] = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
2285 }
2286
2287 /* If viewing a time-based archive. */
2288 elseif ( is_time() ) {
2289
2290 if ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
2291 $trail['trail_end'] = get_the_time( __( 'g:i a', 'woothemes' ) );
2292
2293 elseif ( get_query_var( 'minute' ) )
2294 $trail['trail_end'] = sprintf( __( 'Minute %1$s', 'woothemes' ), get_the_time( __( 'i', 'woothemes' ) ) );
2295
2296 elseif ( get_query_var( 'hour' ) )
2297 $trail['trail_end'] = get_the_time( __( 'g a', 'woothemes' ) );
2298 }
2299
2300 /* If viewing a date-based archive. */
2301 elseif ( is_date() ) {
2302
2303 /* If $front has been set, check for parent pages. */
2304 if ( $wp_rewrite->front )
2305 $trail = array_merge( $trail, woo_breadcrumbs_get_parents( '', $wp_rewrite->front ) );
2306
2307 if ( is_day() ) {
2308 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', 'woothemes' ) ) . '">' . get_the_time( __( 'Y', 'woothemes' ) ) . '</a>';
2309 $trail[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . get_the_time( esc_attr__( 'F', 'woothemes' ) ) . '">' . get_the_time( __( 'F', 'woothemes' ) ) . '</a>';
2310 $trail['trail_end'] = get_the_time( __( 'j', 'woothemes' ) );
2311 }
2312
2313 elseif ( get_query_var( 'w' ) ) {
2314 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', 'woothemes' ) ) . '">' . get_the_time( __( 'Y', 'woothemes' ) ) . '</a>';
2315 $trail['trail_end'] = sprintf( __( 'Week %1$s', 'woothemes' ), get_the_time( esc_attr__( 'W', 'woothemes' ) ) );
2316 }
2317
2318 elseif ( is_month() ) {
2319 $trail[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . get_the_time( esc_attr__( 'Y', 'woothemes' ) ) . '">' . get_the_time( __( 'Y', 'woothemes' ) ) . '</a>';
2320 $trail['trail_end'] = get_the_time( __( 'F', 'woothemes' ) );
2321 }
2322
2323 elseif ( is_year() ) {
2324 $trail['trail_end'] = get_the_time( __( 'Y', 'woothemes' ) );
2325 }
2326 }
2327 }
2328
2329 /* If viewing search results. */
2330 elseif ( is_search() )
2331 $trail['trail_end'] = sprintf( __( 'Search results for "%1$s"', 'woothemes' ), esc_attr( get_search_query() ) );
2332
2333 /* If viewing a 404 error page. */
2334 elseif ( is_404() )
2335 $trail['trail_end'] = __( '404 Not Found', 'woothemes' );
2336
2337 /* Allow child themes/plugins to filter the trail array. */
2338 $trail = apply_filters( 'woo_breadcrumbs_trail', $trail, $args );
2339
2340 /* Connect the breadcrumb trail if there are items in the trail. */
2341 if ( is_array( $trail ) ) {
2342
2343 /* Open the breadcrumb trail containers. */
2344 $breadcrumb = '<div class="breadcrumb breadcrumbs woo-breadcrumbs"><div class="breadcrumb-trail">';
2345
2346 /* If $before was set, wrap it in a container. */
2347 if ( !empty( $before ) )
2348 $breadcrumb .= '<span class="trail-before">' . wp_kses_post( $before ) . '</span> ';
2349
2350 /* Wrap the $trail['trail_end'] value in a container. */
2351 if ( !empty( $trail['trail_end'] ) )
2352 $trail['trail_end'] = '<span class="trail-end">' . wp_kses_post( $trail['trail_end'] ) . '</span>';
2353
2354 /* Format the separator. */
2355 if ( !empty( $separator ) )
2356 $separator = '<span class="sep">' . wp_kses_post( $separator ) . '</span>';
2357
2358 /* Join the individual trail items into a single string. */
2359 $breadcrumb .= join( " {$separator} ", $trail );
2360
2361 /* If $after was set, wrap it in a container. */
2362 if ( !empty( $after ) )
2363 $breadcrumb .= ' <span class="trail-after">' . wp_kses_post( $after ) . '</span>';
2364
2365 /* Close the breadcrumb trail containers. */
2366 $breadcrumb .= '</div></div>';
2367 }
2368
2369 /* Allow developers to filter the breadcrumb trail HTML. */
2370 $breadcrumb = apply_filters( 'woo_breadcrumbs', $breadcrumb );
2371
2372 /* Output the breadcrumb. */
2373 if ( $echo )
2374 echo $breadcrumb;
2375 else
2376 return $breadcrumb;
2377} // End woo_breadcrumbs()
2378
2379if ( ! function_exists( 'wf_maybe_add_shop_page_link' ) ) {
2380/**
2381 * If WooCommerce is present, and we've got a post_type_archive_link, replace it with the shop page.
2382 * @since 6.0.0
2383 * @param array $trail The breadcrumb trail array.
2384 * @return array The modified breadcrumb trail array.
2385 */
2386function wf_maybe_add_shop_page_link ( $trail ) {
2387 if ( is_singular() && 'product' == get_post_type() && function_exists( 'wc_get_page_id' ) ) {
2388 $permalinks = get_option( 'woocommerce_permalinks' );
2389 $shop_page_id = wc_get_page_id( 'shop' );
2390 $shop_page = get_post( $shop_page_id );
2391
2392 // If permalinks contain the shop page in the URI prepend the breadcrumb with shop
2393 if ( isset( $trail['post_type_archive_link'] ) ) {
2394 if ( $shop_page_id && $shop_page && strstr( $permalinks['product_base'], '/' . $shop_page->post_name ) && get_option( 'page_on_front' ) !== $shop_page_id ) {
2395 $trail['post_type_archive_link'] = '<a href="' . esc_url( get_permalink( $shop_page_id ) ) . '" title="' . esc_attr( $shop_page->post_title ) . '">' . esc_html( $shop_page->post_title ) . '</a>';
2396 } else {
2397 if ( true == (bool)apply_filters( 'wf_hide_product_post_type_archive_link', false ) ) {
2398 unset( $trail['post_type_archive_link'] );
2399 }
2400 }
2401 }
2402 }
2403 return $trail;
2404} // End wf_set_default_breadcrumb_taxonomies()
2405}
2406add_filter( 'woo_breadcrumbs_trail', 'wf_maybe_add_shop_page_link' );
2407
2408/*-----------------------------------------------------------------------------------*/
2409/* woo_breadcrumbs_get_parents() - Retrieve the parents of the current page/post */
2410/*-----------------------------------------------------------------------------------*/
2411/**
2412 * Gets parent pages of any post type or taxonomy by the ID or Path. The goal of this function is to create
2413 * a clear path back to home given what would normally be a "ghost" directory. If any page matches the given
2414 * path, it'll be added. But, it's also just a way to check for a hierarchy with hierarchical post types.
2415 *
2416 * @since 3.7.0
2417 * @param int $post_id ID of the post whose parents we want.
2418 * @param string $path Path of a potential parent page.
2419 * @return array $trail Array of parent page links.
2420 */
2421function woo_breadcrumbs_get_parents( $post_id = '', $path = '' ) {
2422 /* Set up an empty trail array. */
2423 $trail = array();
2424
2425 /* If neither a post ID nor path set, return an empty array. */
2426 if ( empty( $post_id ) && empty( $path ) )
2427 return $trail;
2428
2429 /* If the post ID is empty, use the path to get the ID. */
2430 if ( empty( $post_id ) ) {
2431
2432 /* Get parent post by the path. */
2433 $parent_page = get_page_by_path( $path );
2434
2435 /* ********************************************************************
2436 Modification: The above line won't get the parent page if
2437 the post type slug or parent page path is not the full path as required
2438 by get_page_by_path. By using get_page_with_title, the full parent
2439 trail can be obtained. This may still be buggy for page names that use
2440 characters or long concatenated names.
2441 Author: Byron Rode
2442 Date: 06 June 2011
2443 ******************************************************************* */
2444
2445 if( empty( $parent_page ) )
2446 // search on page name (single word)
2447 $parent_page = get_page_by_title ( $path );
2448
2449 if( empty( $parent_page ) )
2450 // search on page title (multiple words)
2451 $parent_page = get_page_by_title ( str_replace( array('-', '_'), ' ', $path ) );
2452
2453 /* End Modification */
2454
2455 /* If a parent post is found, set the $post_id variable to it. */
2456 if ( !empty( $parent_page ) )
2457 $post_id = $parent_page->ID;
2458 }
2459
2460 /* If a post ID and path is set, search for a post by the given path. */
2461 if ( $post_id == 0 && !empty( $path ) ) {
2462
2463 /* Separate post names into separate paths by '/'. */
2464 $path = trim( $path, '/' );
2465 preg_match_all( "/\/.*?\z/", $path, $matches );
2466
2467 /* If matches are found for the path. */
2468 if ( isset( $matches ) ) {
2469
2470 /* Reverse the array of matches to search for posts in the proper order. */
2471 $matches = array_reverse( $matches );
2472
2473 /* Loop through each of the path matches. */
2474 foreach ( $matches as $match ) {
2475
2476 /* If a match is found. */
2477 if ( isset( $match[0] ) ) {
2478
2479 /* Get the parent post by the given path. */
2480 $path = str_replace( $match[0], '', $path );
2481 $parent_page = get_page_by_path( trim( $path, '/' ) );
2482
2483 /* If a parent post is found, set the $post_id and break out of the loop. */
2484 if ( !empty( $parent_page ) && $parent_page->ID > 0 ) {
2485 $post_id = $parent_page->ID;
2486 break;
2487 }
2488 }
2489 }
2490 }
2491 }
2492
2493 /* While there's a post ID, add the post link to the $parents array. */
2494 while ( $post_id ) {
2495 /* Get the post by ID. */
2496 $page = get_page( $post_id );
2497
2498 /* Add the formatted post link to the array of parents. */
2499 $parents[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . esc_html( get_the_title( $post_id ) ) . '</a>';
2500
2501 /* Set the parent post's parent to the post ID. */
2502 $post_id = $page->post_parent;
2503 }
2504
2505 /* If we have parent posts, reverse the array to put them in the proper order for the trail. */
2506 if ( isset( $parents ) )
2507 $trail = array_reverse( $parents );
2508
2509 /* Return the trail of parent posts. */
2510 return $trail;
2511} // End woo_breadcrumbs_get_parents()
2512
2513/*-----------------------------------------------------------------------------------*/
2514/* woo_breadcrumbs_get_term_parents() - Retrieve the parents of the current term */
2515/*-----------------------------------------------------------------------------------*/
2516/**
2517 * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
2518 * function get_category_parents() but handles any type of taxonomy.
2519 *
2520 * @since 3.7.0
2521 * @param int $parent_id The ID of the first parent.
2522 * @param object|string $taxonomy The taxonomy of the term whose parents we want.
2523 * @return array $trail Array of links to parent terms.
2524 */
2525function woo_breadcrumbs_get_term_parents( $parent_id = '', $taxonomy = '' ) {
2526 /* Set up some default arrays. */
2527 $trail = array();
2528 $parents = array();
2529
2530 /* If no term parent ID or taxonomy is given, return an empty array. */
2531 if ( empty( $parent_id ) || empty( $taxonomy ) )
2532 return $trail;
2533
2534 /* While there is a parent ID, add the parent term link to the $parents array. */
2535 while ( $parent_id ) {
2536
2537 /* Get the parent term. */
2538 $parent = get_term( $parent_id, $taxonomy );
2539
2540 /* Add the formatted term link to the array of parent terms. */
2541 $parents[] = '<a href="' . get_term_link( $parent, $taxonomy ) . '" title="' . esc_attr( $parent->name ) . '">' . $parent->name . '</a>';
2542
2543 /* Set the parent term's parent as the parent ID. */
2544 $parent_id = $parent->parent;
2545 }
2546
2547 /* If we have parent terms, reverse the array to put them in the proper order for the trail. */
2548 if ( !empty( $parents ) )
2549 $trail = array_reverse( $parents );
2550
2551 /* Return the trail of parent terms. */
2552 return $trail;
2553} // End woo_breadcrumbs_get_term_parents()
2554
2555/*-----------------------------------------------------------------------------------*/
2556/* WordPress Admin Bar-related */
2557/*-----------------------------------------------------------------------------------*/
2558
2559/*-----------------------------------------------------------------------------------*/
2560/* Disable WordPress Admin Bar */
2561/*-----------------------------------------------------------------------------------*/
2562
2563$woo_admin_bar_disable = get_option( 'framework_woo_admin_bar_disable' );
2564
2565if ( $woo_admin_bar_disable == 'true' ) {
2566 add_filter( 'show_admin_bar', '__return_false' );
2567
2568 add_action( 'admin_print_scripts-profile.php', 'woo_hide_admin_bar_prefs' );
2569
2570 function woo_hide_admin_bar_prefs () { ?>
2571 <style type="text/css">
2572 .show-admin-bar { display: none; }
2573 </style>
2574 <?php
2575 } // End woo_hide_admin_bar_prefs()
2576}
2577
2578/*-----------------------------------------------------------------------------------*/
2579/* Enhancements to the WordPress Admin Bar */
2580/*-----------------------------------------------------------------------------------*/
2581
2582if ( $woo_admin_bar_disable != 'true' && is_user_logged_in() && current_user_can( 'manage_options' ) ) {
2583 $woo_admin_bar_enhancements = get_option( 'framework_woo_admin_bar_enhancements' );
2584 if ( $woo_admin_bar_enhancements == 'true' ) {
2585 add_action( 'admin_bar_menu', 'woo_admin_bar_menu', 20 );
2586 }
2587} // End IF Statement
2588
2589/*-----------------------------------------------------------------------------------*/
2590/* woo_admin_bar_menu() - Add menu items to the admin bar. */
2591/*-----------------------------------------------------------------------------------*/
2592
2593function woo_admin_bar_menu () {
2594 global $wp_admin_bar, $current_user;
2595 $current_user_id = $current_user->user_login;
2596 $super_user = get_option( 'framework_woo_super_user' );
2597
2598 $theme_data = wooframework_get_theme_version_data();
2599
2600 $menu_label = __( 'WooThemes', 'woothemes' );
2601
2602 // Customise menu label to the child theme's name.
2603 if ( is_array( $theme_data ) && array_key_exists( 'theme_name', $theme_data ) ) {
2604 $menu_label = $theme_data['theme_name'];
2605 }
2606
2607 // Main WooThemes Menu Item
2608 $wp_admin_bar->add_menu( array( 'id' => 'woothemes', 'title' => $menu_label, 'href' => admin_url('admin.php?page=woothemes') ) );
2609
2610 // Theme Options
2611 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes', 'id' => 'woothemes-theme-options', 'title' => __( 'Theme Options', 'woothemes' ), 'href' => admin_url( 'admin.php?page=woothemes' ) ) );
2612
2613 if ( ( $super_user == $current_user_id ) || empty( $super_user ) ) {
2614 $wp_admin_bar->add_group( array( 'parent' => 'woothemes', 'id' => 'woothemes-super-user', 'meta' => array( 'class' => 'ab-sub-secondary' ) ) );
2615
2616 // Framework Settings
2617 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes-super-user', 'id' => 'woothemes-framework-settings', 'title' => __( 'Framework Settings', 'woothemes' ), 'href' => admin_url( 'admin.php?page=woothemes_framework_settings' ) ) );
2618
2619 // Update Framework
2620 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes-super-user', 'id' => 'woothemes-update-framework', 'title' => __( 'Update Framework', 'woothemes' ), 'href' => admin_url( 'admin.php?page=woothemes_framework_update' ) ) );
2621
2622 // Theme Version Data Display
2623 if ( true == $theme_data['is_child'] ) {
2624 $child_theme_name = sprintf( __( 'Child Theme: %s %s', 'woothemes' ), $theme_data['child_theme_name'], $theme_data['child_theme_version'] );
2625 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes-super-user', 'id' => 'woothemes-child-theme-version-data', 'title' => $child_theme_name ) );
2626 }
2627
2628 $theme_name = sprintf( __( 'Theme: %s %s', 'woothemes' ), $theme_data['theme_name'], $theme_data['theme_version'] );
2629 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes-super-user', 'id' => 'woothemes-theme-version-data', 'title' => $theme_name ) );
2630
2631 $framework_version = sprintf( __( 'WooFramework: %s', 'woothemes' ), $theme_data['framework_version'] );
2632 $wp_admin_bar->add_menu( array( 'parent' => 'woothemes-super-user', 'id' => 'woothemes-framework-version-data', 'title' => $framework_version ) );
2633 } // End IF Statement
2634} // End woo_admin_bar_menu()
2635
2636/*-----------------------------------------------------------------------------------*/
2637/* woo_prepare_category_ids_from_option()
2638 *
2639 * Setup an array of category IDs, from a given theme option.
2640 * Attempt to transform category slugs into ID values as well.
2641 *
2642 * Params: String $option
2643 * Return: Array $cats
2644/*-----------------------------------------------------------------------------------*/
2645
2646if ( ! function_exists( 'woo_prepare_category_ids_from_option' ) ) {
2647 function woo_prepare_category_ids_from_option ( $option ) {
2648 $cats = array();
2649
2650 $stored_cats = get_option( $option );
2651
2652 $cats_raw = explode( ',', $stored_cats );
2653
2654 if ( is_array( $cats_raw ) && ( count( $cats_raw ) > 0 ) ) {
2655 foreach ( $cats_raw as $k => $v ) {
2656 $value = trim( $v );
2657
2658 if ( is_numeric( $value ) ) {
2659 $cats_raw[$k] = $value;
2660 } else {
2661 $cat_obj = get_category_by_slug( $value );
2662 if ( isset( $cat_obj->term_id ) ) {
2663 $cats_raw[$k] = $cat_obj->term_id;
2664 }
2665 }
2666
2667 $cats = $cats_raw;
2668 }
2669 }
2670
2671 return $cats;
2672 } // End woo_prepare_category_ids_from_option()
2673}
2674
2675/*-----------------------------------------------------------------------------------*/
2676/* Move tracking code from footer to header */
2677/*-----------------------------------------------------------------------------------*/
2678
2679add_action( 'init', 'woo_move_tracking_code', 20 );
2680
2681function woo_move_tracking_code () {
2682 $move_code = get_option( 'framework_woo_move_tracking_code' );
2683
2684 if ( ! is_admin() && isset( $move_code ) && ( $move_code == 'true' ) ) {
2685 remove_action( 'wp_footer', 'woo_analytics' );
2686 add_action( 'wp_head', 'woo_analytics', 10 );
2687 }
2688} // End woo_move_tracking_code()
2689
2690
2691/*-----------------------------------------------------------------------------------*/
2692/* woo_get_dynamic_value() */
2693/* Replace values in a provided array with theme options, if available. */
2694/*
2695/* $settings array should resemble: $settings = array( 'theme_option_without_woo_' => 'default_value' );
2696/*
2697/* @since 4.4.4 */
2698/*-----------------------------------------------------------------------------------*/
2699
2700function woo_get_dynamic_values ( $settings ) {
2701 global $woo_options;
2702
2703 if ( is_array( $woo_options ) ) {
2704 foreach ( $settings as $k => $v ) {
2705 if ( isset( $woo_options['woo_' . $k] ) && ( $woo_options['woo_' . $k] != '' ) ) { $settings[$k] = $woo_options['woo_' . $k]; }
2706 }
2707 }
2708
2709 return $settings;
2710} // End woo_get_dynamic_values()
2711
2712/*-----------------------------------------------------------------------------------*/
2713/* woo_get_posts_by_taxonomy()
2714/*
2715/* Selects posts based on specified taxonomies.
2716/*
2717/* @since 4.5.0
2718/* @param array $args
2719/* @return array $posts
2720/*-----------------------------------------------------------------------------------*/
2721
2722 function woo_get_posts_by_taxonomy ( $args = null ) {
2723 global $wp_query;
2724
2725 $posts = array();
2726
2727 /* Parse arguments, and declare individual variables for each. */
2728
2729 $defaults = array(
2730 'limit' => 5,
2731 'post_type' => 'any',
2732 'taxonomies' => 'post_tag, category',
2733 'specific_terms' => '',
2734 'relationship' => 'OR',
2735 'order' => 'DESC',
2736 'orderby' => 'date',
2737 'operator' => 'IN',
2738 'exclude' => ''
2739 );
2740
2741 $args = wp_parse_args( $args, $defaults );
2742
2743 extract( $args, EXTR_SKIP );
2744
2745 // Make sure the order value is safe.
2746 if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) ) { $order = $defaults['order']; }
2747
2748 // Make sure the orderby value is safe.
2749 if ( ! in_array( $orderby, array( 'none', 'id', 'author', 'title', 'date', 'modified', 'parent', 'rand', 'comment_count', 'menu_order' ) ) ) { $orderby = $defaults['orderby']; }
2750
2751 // Make sure the operator value is safe.
2752 if ( ! in_array( $operator, array( 'IN', 'NOT IN', 'AND' ) ) ) { $orderby = $defaults['operator']; }
2753
2754 // Convert our post types to an array.
2755 if ( ! is_array( $post_type ) ) { $post_type = explode( ',', $post_type ); }
2756
2757 // Convert our taxonomies to an array.
2758 if ( ! is_array( $taxonomies ) ) { $taxonomies = explode( ',', $taxonomies ); }
2759
2760 // Convert exclude to an array.
2761 if ( ! is_array( $exclude ) && ( $exclude != '' ) ) { $exclude = explode( ',', $exclude ); }
2762
2763 if ( ! count( (array)$taxonomies ) ) { return; }
2764
2765 // Clean up our taxonomies for use in the query.
2766 if ( count( $taxonomies ) ) {
2767 foreach ( $taxonomies as $k => $v ) {
2768 $taxonomies[$k] = trim( $v );
2769 }
2770 }
2771
2772 // Determine which terms we're going to relate to this entry.
2773 $related_terms = array();
2774
2775 foreach ( $taxonomies as $t ) {
2776 $terms = get_terms( $t, 'orderby=id&hide_empty=1' );
2777
2778 if ( ! empty( $terms ) ) {
2779 foreach ( $terms as $k => $v ) {
2780 $related_terms[$t][$v->term_id] = $v->slug;
2781 }
2782 }
2783 }
2784
2785 // If specific terms are available, use those.
2786 if ( ! is_array( $specific_terms ) ) { $specific_terms = explode( ',', $specific_terms ); }
2787
2788 if ( count( $specific_terms ) ) {
2789 foreach ( $specific_terms as $k => $v ) {
2790 $specific_terms[$k] = trim( $v );
2791 }
2792 }
2793
2794 // Look for posts with the same terms.
2795
2796 // Setup query arguments.
2797 $query_args = array();
2798
2799 if ( $post_type ) { $query_args['post_type'] = $post_type; }
2800
2801 if ( $limit ) {
2802 $query_args['posts_per_page'] = $limit;
2803 // $query_args['nopaging'] = true;
2804 }
2805
2806 // Setup specific posts to exclude.
2807 if ( count( $exclude ) > 0 ) {
2808 $query_args['post__not_in'] = $exclude;
2809 }
2810
2811 $query_args['order'] = $order;
2812 $query_args['orderby'] = $orderby;
2813
2814 $query_args['tax_query'] = array();
2815
2816 // Setup for multiple taxonomies.
2817
2818 if ( count( $related_terms ) > 1 ) {
2819 $query_args['tax_query']['relation'] = $args['relationship'];
2820 }
2821
2822 // Add the taxonomies to the query arguments.
2823
2824 foreach ( (array)$related_terms as $k => $v ) {
2825 $terms_for_search = array_values( $v );
2826
2827 if ( count( $specific_terms ) ) {
2828 $specific_terms_by_tax = array();
2829
2830 foreach ( $specific_terms as $i => $j ) {
2831 if ( in_array( $j, array_values( $v ) ) ) {
2832 $specific_terms_by_tax[] = $j;
2833 }
2834 }
2835
2836 if ( count( $specific_terms_by_tax ) ) {
2837 $terms_for_search = $specific_terms_by_tax;
2838 }
2839 }
2840
2841 $query_args['tax_query'][] = array(
2842 'taxonomy' => $k,
2843 'field' => 'slug',
2844 'terms' => $terms_for_search,
2845 'operator' => $operator
2846 );
2847 }
2848
2849 if ( empty( $query_args['tax_query'] ) ) { return; }
2850
2851 $query_saved = $wp_query;
2852
2853 $query = new WP_Query( $query_args );
2854
2855 if ( $query->have_posts() ) {
2856 while( $query->have_posts() ) {
2857 $query->the_post();
2858
2859 $posts[] = $query->post;
2860 }
2861 }
2862
2863 $query = $query_saved;
2864
2865 wp_reset_query();
2866
2867 return $posts;
2868 } // End woo_get_posts_by_taxonomy()
2869
2870/*-----------------------------------------------------------------------------------*/
2871/* If the user has specified a "posts page", load the "Blog" page template there */
2872/*-----------------------------------------------------------------------------------*/
2873
2874add_filter( 'template_include', 'woo_load_posts_page_blog_template', 10 );
2875
2876if ( ! function_exists( 'woo_load_posts_page_blog_template' ) ) {
2877 function woo_load_posts_page_blog_template ( $template ) {
2878 if ( 'page' == get_option( 'show_on_front' ) && ( '' != get_option( 'page_for_posts' ) ) && is_home() ) {
2879 $tpl = locate_template( array( 'template-blog.php' ) );
2880 if ( $tpl != '' ) { $template = $tpl; }
2881 }
2882 return $template;
2883 } // End woo_load_posts_page_blog_template()
2884}
2885
2886/*-----------------------------------------------------------------------------------*/
2887/* PressTrends API Integration */
2888/*-----------------------------------------------------------------------------------*/
2889
2890/**
2891 * woo_presstrends function.
2892 *
2893 * @description Send data to the PressTrends API.
2894 * @access public
2895 * @return void
2896 */
2897
2898if ( defined( 'WOO_PRESSTRENDS_THEMEKEY' ) ) {
2899 if ( get_option( 'framework_woo_presstrends_enable', 'false' ) == 'true' ) {
2900 add_action( 'admin_footer', 'woo_presstrends', 100 );
2901 }
2902}
2903
2904function woo_presstrends () {
2905 if ( ! defined( 'WOO_PRESSTRENDS_THEMEKEY' ) ) { return; }
2906
2907 // Add your PressTrends API Keys
2908 $api_key = 'ypvilflyjb7yyht8as1u2k0no3rxbgl2p4a9';
2909 $auth = WOO_PRESSTRENDS_THEMEKEY;
2910
2911 // Check if we have cached data.
2912 $data = get_transient( 'woo_presstrends_data' );
2913
2914 if ( ! $data || $data == '' ) {
2915 global $wpdb;
2916
2917 // Don't edit below
2918 $api_base = 'http://api.presstrends.io/index.php/api/sites/add/auth/';
2919 $url = $api_base . $auth . '/api/' . $api_key . '/';
2920
2921 $count_posts = wp_count_posts();
2922 $count_pages = wp_count_posts( 'page' );
2923 $comments_count = wp_count_comments();
2924
2925 // Custom WooFramework way of getting theme data.
2926 $theme_data = wooframework_get_theme_version_data();
2927 $theme_name = $theme_data['theme_name'];
2928 $theme_version = $theme_data['theme_version'];
2929
2930 $plugin_name = '&';
2931 foreach ( get_plugins() as $plugin_info ) {
2932 $plugin_name .= $plugin_info['Name'] . '&';
2933 }
2934 $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
2935 $data = array(
2936 'url' => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
2937 'posts' => $count_posts->publish,
2938 'pages' => $count_pages->publish,
2939 'comments' => $comments_count->total_comments,
2940 'approved' => $comments_count->approved,
2941 'spam' => $comments_count->spam,
2942 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
2943 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
2944 'theme_version' => $theme_version,
2945 'theme_name' => $theme_name,
2946 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
2947 'plugins' => count( get_option( 'active_plugins' ) ),
2948 'plugin' => urlencode( $plugin_name ),
2949 'wpversion' => get_bloginfo( 'version' ),
2950 'api_version' => '2.4'
2951 );
2952
2953 foreach ( $data as $k => $v ) {
2954 $url .= $k . '/' . $v . '/';
2955 }
2956
2957 // Perform the remote request.
2958 $response = wp_remote_get( $url );
2959
2960 if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) != 200 ) {
2961 // Silence is golden.
2962 } else {
2963 set_transient( 'woo_presstrends_data', $data, 60*60*24 );
2964 }
2965 }
2966} // End woo_presstrends()
2967
2968/*-----------------------------------------------------------------------------------*/
2969/* THE END */
2970/*-----------------------------------------------------------------------------------*/
2971
2972/*-----------------------------------------------------------------------------------*/
2973/* WooDojo Download Banner */
2974/*-----------------------------------------------------------------------------------*/
2975
2976if ( is_admin() && current_user_can( 'install_plugins' ) && ! class_exists( 'WooDojo' ) ) {
2977 add_action( 'wooframework_container_inside', 'wooframework_add_woodojo_banner' );
2978}
2979
2980if ( defined( 'WOO_PRESSTRENDS_THEMEKEY' ) && is_admin() && current_user_can( 'switch_themes' ) && isset( $_GET['activated'] ) && ( $_GET['activated'] == 'true' ) ) {
2981 add_action( 'wooframework_container_inside', 'wooframework_add_presstrends_banner' );
2982}
2983
2984add_action( 'wp_ajax_wooframework_banner_close', 'wooframework_ajax_banner_close' );
2985
2986/**
2987 * Add a WooDojo banner on the Theme Options screen.
2988 * @since 5.3.4
2989 * @return void
2990 */
2991function wooframework_add_woodojo_banner () {
2992 if ( get_user_setting( 'wooframeworkhidebannerwoodojo', '0' ) == '1' ) { return; }
2993
2994 $close_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=wooframework_banner_close&banner=woodojo' ), 'wooframework_banner_close' );
2995 $html = '';
2996
2997 $html .= '<div id="woodojo-banner" class="wooframework-banner">' . "\n";
2998 $html .= '<span class="main">' . __( 'Enhance your theme with WooDojo.', 'woothemes' ) . '</span>' . "\n";
2999 $html .= '<span>' . __( 'WooDojo is a powerful WooThemes features suite for enhancing your website. Learn more.', 'woothemes' ) . '</span>' . "\n";
3000 $html .= '<a class="button-primary" href="' . esc_url( 'http://woothemes.com/woodojo/' ) . '" title="' . esc_attr__( 'Get WooDojo', 'woothemes' ) . '" target="_blank">' . __( 'Get WooDojo', 'woothemes' ) . '</a>' . "\n";
3001 $html .= '<span class="close-banner"><a href="' . $close_url . '">' . __( 'Close', 'woothemes' ) . '</a></span>' . "\n";
3002 $html .= '</div>' . "\n";
3003
3004 echo $html;
3005} // End wooframework_add_woodojo_banner()
3006
3007/**
3008 * Add a PressTrends banner on the Theme Options screen on first activation.
3009 * @since 5.3.4
3010 * @return void
3011 */
3012function wooframework_add_presstrends_banner () {
3013 if ( get_user_setting( 'wooframeworkhidebannerpresstrends', '0' ) == '1' ) { return; }
3014
3015 $close_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=wooframework_banner_close&banner=presstrends' ), 'wooframework_banner_close' );
3016 $html = '';
3017
3018 $html .= '<div id="presstrends-banner" class="wooframework-banner">' . "\n";
3019 $html .= '<span class="main">' . __( 'Enable PressTrends', 'woothemes' ) . '</span>' . "\n";
3020 $html .= '<span class="info">' . sprintf( __( 'PressTrends is a simple usage tracker that allows us to see how our customers are using WooThemes themes - so that we can help improve them for you. %sNone%s of your personal data is sent to PressTrends.', 'woothemes' ), '<br /><strong>', '</strong>' ) . '</span>' . "\n";
3021 $html .= '<a class="button-primary" href="' . esc_url( admin_url( 'admin.php?page=woothemes_framework_settings' ) ) . '" title="' . esc_attr__( 'Enable PressTrends', 'woothemes' ) . '">' . __( 'Enable PressTrends', 'woothemes' ) . '</a>' . "\n";
3022 $html .= '<span class="close-banner"><a href="' . $close_url . '">' . __( 'Close', 'woothemes' ) . '</a></span>' . "\n";
3023 $html .= '</div>' . "\n";
3024
3025 echo $html;
3026} // End wooframework_add_presstrends_banner()
3027
3028/**
3029 * wooframework_ajax_banner_close function.
3030 *
3031 * @access public
3032 * @since 1.0.0
3033 */
3034function wooframework_ajax_banner_close () {
3035 if( ! current_user_can( 'install_plugins' ) ) wp_die( __( 'You do not have sufficient permissions to access this page.', 'woothemes' ) );
3036
3037 if( ! check_admin_referer( 'wooframework_banner_close' ) ) wp_die( __( 'You have taken too long. Please go back and retry.', 'woothemes' ) );
3038
3039 $banner = ( isset( $_GET['banner'] ) ) ? $_GET['banner'] : '';
3040
3041 if( ! $banner ) die;
3042
3043 // Run the update.
3044 $response = set_user_setting( 'wooframeworkhidebanner' . $banner, '1' );
3045
3046 $sendback = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'ids' ), wp_get_referer() );
3047 wp_safe_redirect( $sendback );
3048 exit;
3049} // End toggle_notifications_status()
3050
3051/*-----------------------------------------------------------------------------------*/
3052/* WooSEO Deprecation Banner */
3053/*-----------------------------------------------------------------------------------*/
3054
3055if ( is_admin() && current_user_can( 'install_plugins' ) && isset( $_GET['page'] ) && ( $_GET['page'] == 'woothemes' || $_GET['page'] == 'woothemes_framework_settings' ) ) {
3056 add_action( 'wooframework_container_inside', 'wooframework_add_wooseosbm_banner' );
3057 add_action( 'wooframework_wooframeworksettings_container_inside', 'wooframework_add_wooseosbm_banner' );
3058}
3059
3060/**
3061 * Add a WooSEO Deprecation banner on the WooSEO Options screen.
3062 * @since 5.4.0
3063 * @return void
3064 */
3065function wooframework_add_wooseosbm_banner () {
3066 if ( get_user_setting( 'wooframeworkhidebannerwooseosbmremoved', '0' ) == '1' ) { return; }
3067
3068 $close_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=wooframework_banner_close&banner=wooseosbmremoved' ), 'wooframework_banner_close' );
3069 $html = '';
3070
3071 $html .= '<div id="woodeprecate-banner" class="wooframework-banner">' . "\n";
3072 $html .= '<span class="main">' . __( 'WooSEO and Sidebar Manager have been removed from version 5.5.0 of the WooFramework.', 'woothemes' ) . '</span>' . "\n";
3073 $html .= '<span>' . sprintf( __( 'For your SEO needs, we encourage you to use the %1$s.', 'woothemes' ), '<a href="' . esc_url( 'http://wordpress.org/extend/plugins/wordpress-seo/' ) . '" title="' . esc_attr__( 'Get WordPress SEO', 'woothemes' ) . '" target="_blank">' . __( 'WordPress SEO Plugin', 'woothemes' ) . '</a>' ) . '</span><span>' . __( 'If you need help moving your existing SEO data, WordPress SEO has a built-in importer to move your data over.', 'woothemes' ) . '</span>' . "\n";
3074 $html .= '<br /><br /><span>' . sprintf( __( 'While the Sidebar Manager has been removed, we encourage you to download %1$s in our free plugin, %2$s. There is also a Sidebar Manager to WooSidebars Converter plugin, available through WooDojo.', 'woothemes' ), '<a href="' . esc_url( 'http://www.woothemes.com/woosidebars/' ) . '" title="' . esc_attr__( 'Get WooSidebars', 'woothemes' ) . '" target="_blank">' . __( 'WooSidebars', 'woothemes' ) . '</a>', '<a href="' . esc_url( 'http://www.woothemes.com/woodojo/' ) . '" title="' . esc_attr__( 'Get WooDojo', 'woothemes' ) . '" target="_blank">' . __( 'WooDojo', 'woothemes' ) . '</a>' ) . '</span>' . "\n";
3075 $html .= '<span class="close-banner"><a href="' . $close_url . '">' . __( 'Close', 'woothemes' ) . '</a></span>' . "\n";
3076 $html .= '</div>' . "\n";
3077
3078 echo $html;
3079} // End wooframework_add_wooseosbm_banner()
3080
3081/*-----------------------------------------------------------------------------------*/
3082/* Timthumb Detection Banner */
3083/*-----------------------------------------------------------------------------------*/
3084
3085if ( is_admin() && current_user_can( 'install_plugins' ) ) {
3086 add_action( 'wooframework_wooframeworksettings_container_inside', 'wooframework_add_wootimthumb_banner' );
3087 add_action( 'wooframework_container_inside', 'wooframework_add_wootimthumb_banner' );
3088}
3089
3090/**
3091 * Add a Timthumb Detection banner on all WooThemes Options screens.
3092 * @since 5.4.0
3093 * @return void
3094 */
3095function wooframework_add_wootimthumb_banner () {
3096 if ( get_user_setting( 'wooframeworkhidebannerwootimthumb', '0' ) == '1' ) { return; }
3097
3098 // Test for old timthumb scripts
3099 $thumb_php_test = file_exists( get_template_directory() . '/thumb.php' );
3100 $timthumb_php_test = file_exists( get_template_directory() . '/timthumb.php' );
3101
3102 if ( $thumb_php_test || $timthumb_php_test ) {
3103 $theme_dir = str_replace( WP_CONTENT_DIR, '', get_template_directory() );
3104 $close_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=wooframework_banner_close&banner=wootimthumb' ), 'wooframework_banner_close' );
3105 $html = '';
3106
3107 $html .= '<div id="woodeprecate-banner" class="wooframework-banner">' . "\n";
3108 $html .= '<span class="main">' . __( 'ATTENTION: Insecure Version of Timthumb Image Resize Script Detected', 'woothemes' ) . '</span>' . "\n";
3109 $html .= '<span>' . __( "A possible old version of the TimThumb script was detected in your theme folder. Please remove the following files from your theme as a security precaution", 'woothemes' ) . ':</span>' . "\n";
3110 if ( $thumb_php_test ) { $html .= '<span><strong>- thumb.php</strong> ( found at ' . $theme_dir . '/thumb.php' . ' )</span>' . "\n"; }
3111 if ( $timthumb_php_test ) { $html .= '<span><strong>- timthumb.php</strong> ( found at ' . $theme_dir . '/timthumb.php' . ' )</span>' . "\n"; }
3112 $html .= '<span class="close-banner"><a href="' . $close_url . '">' . __( 'Close', 'woothemes' ) . '</a></span>' . "\n";
3113 $html .= '</div>' . "\n";
3114
3115 echo $html;
3116 } else {
3117 return;
3118 }
3119
3120} // End wooframework_add_wootimthumb_banner()
3121
3122/*-----------------------------------------------------------------------------------*/
3123/* Static Front Page Detection Banner */
3124/*-----------------------------------------------------------------------------------*/
3125
3126if ( is_admin() && current_user_can( 'manage_options' ) && ( 0 < intval( get_option( 'page_on_front' ) ) ) ) {
3127 add_action( 'wooframework_container_inside', 'wooframework_add_static_front_page_banner' );
3128}
3129
3130/**
3131 * Add a Static Front Page Detection banner on all WooThemes Options screens.
3132 * @since 5.5.2
3133 * @return void
3134 */
3135function wooframework_add_static_front_page_banner () {
3136 if ( get_user_setting( 'wooframeworkhidebannerstaticfrontpage', '0' ) == '1' ) { return; }
3137 $theme_data = wooframework_get_theme_version_data();
3138 $close_url = wp_nonce_url( admin_url( 'admin-ajax.php?action=wooframework_banner_close&banner=staticfrontpage' ), 'wooframework_banner_close' );
3139 $html = '';
3140 $html .= '<div id="staticfrontpage-banner" class="wooframework-banner">' . "\n";
3141 $html .= '<span class="main">' . sprintf( __( 'You have setup a static front page in %1$sSettings > Reading%2$s. Please set it to show "Your latest posts" if you want to display the default homepage in %3$s.', 'woothemes' ), '<strong><a href="' . esc_url( admin_url( 'options-reading.php' ) ) . '">', '</a></strong>', $theme_data['theme_name'], '<strong>', '</strong>' ) . '</span>' . "\n";
3142 $html .= '<span class="close-banner"><a href="' . $close_url . '">' . __( 'Close', 'woothemes' ) . '</a></span>' . "\n";
3143 $html .= '</div>' . "\n";
3144
3145 echo $html;
3146} // End wooframework_add_static_front_page_banner()
3147
3148/** edit adit
3149 * Get the version data for the currently active theme.
3150 * @since 5.4.2
3151 * @return array [theme_version, theme_name, framework_version, is_child, child_theme_version, child_theme_name]
3152 */
3153if ( ! function_exists( 'wooframework_get_theme_version_data' ) ) {
3154function wooframework_get_theme_version_data () {
3155 $response = array(
3156 'theme_version' => '',
3157 'theme_name' => '',
3158 'framework_version' => get_option( 'woo_framework_version' ),
3159 'is_child' => is_child_theme(),
3160 'child_theme_version' => '',
3161 'child_theme_name' => ''
3162 );
3163
3164 if ( function_exists( 'wp_get_theme' ) ) {
3165 $theme_data = wp_get_theme();
3166 if ( true == $response['is_child'] ) {
3167 $response['theme_version'] = $theme_data->parent()->Version;
3168 $response['theme_name'] = $theme_data->parent()->Name;
3169
3170 $response['child_theme_version'] = $theme_data->Version;
3171 $response['child_theme_name'] = $theme_data->Name;
3172 } else {
3173 $response['theme_version'] = $theme_data->Version;
3174 // $response['theme_name'] = $theme_data->Name;
3175 }
3176 } else {
3177 $theme_data = wp_get_theme( get_template_directory() . '/style.css' );
3178 $response['theme_version'] = $theme_data['Version'];
3179 $response['theme_name'] = $theme_data['Name'];
3180
3181 if ( true == $response['is_child'] ) {
3182 $theme_data = wp_get_theme( get_stylesheet_directory() . '/style.css' );
3183 $response['child_theme_version'] = $theme_data['Version'];
3184 $response['child_theme_name'] = $theme_data['Name'];
3185 }
3186 }
3187
3188 return $response;
3189} // End wooframework_get_theme_version_data()
3190}
3191
3192if ( ! function_exists( 'wooframework_display_theme_version_data' ) ) {
3193/**
3194 * Display the version data for the currently active theme.
3195 * @since 5.4.2
3196 * @return void
3197 */
3198function wooframework_display_theme_version_data ( $echo = true ) {
3199 $data = wooframework_get_theme_version_data();
3200 $html = '';
3201
3202 // Theme Version
3203 if ( true == $data['is_child'] ) {
3204 $html .= '<span class="theme">' . esc_html( $data['child_theme_name'] . ' ' . $data['child_theme_version'] ) . '</span>' . "\n";
3205 $html .= '<span class="parent-theme">' . esc_html( $data['theme_name'] . ' ' . $data['theme_version'] ) . '</span>' . "\n";
3206 } else {
3207 $html .= '<span class="theme">' . esc_html( $data['theme_name'] . ' ' . $data['theme_version'] ) . '</span>' . "\n";
3208 }
3209
3210 // Framework Version
3211 $html .= '<span class="framework">' . esc_html( sprintf( __( 'Framework %s', 'woothemes' ), $data['framework_version'] ) ) . '</span>' . "\n";
3212
3213 if ( true == $echo ) { echo $html; } else { return $html; }
3214} // End wooframework_display_theme_version_data()
3215}
3216
3217if ( ! function_exists( 'wooframework_load_google_fonts' ) ) {
3218function wooframework_load_google_fonts() {
3219 global $woo_used_google_fonts;
3220
3221 if( $woo_used_google_fonts && is_array( $woo_used_google_fonts ) ) {
3222 $fonts = '';
3223 $c = 0;
3224 foreach( $woo_used_google_fonts as $font ) {
3225 if( $c > 0 ) {
3226 $fonts .= '|';
3227 } else {
3228 ++$c;
3229 }
3230 $fonts .= $font;
3231 }
3232
3233 if( '' != $fonts ) {
3234 woo_shortcode_typography_loadgooglefonts( $fonts , 'woo-used-google-fonts' );
3235 }
3236 }
3237} // End wooframework_load_google_fonts()
3238}
3239add_action( 'wp_footer' , 'wooframework_load_google_fonts' );
3240