PageRenderTime 83ms CodeModel.GetById 35ms RepoModel.GetById 1ms app.codeStats 1ms

/wp-content/themes/artificer/functions/admin-functions.php

https://bitbucket.org/nathancorbier/wastark.com
PHP | 3186 lines | 1944 code | 541 blank | 701 comment | 547 complexity | d69f1f7171626c6b72363513bcc3511a MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // File Security Check
  3. if ( ! defined( 'ABSPATH' ) ) exit;
  4. ?>
  5. <?php
  6. /*-----------------------------------------------------------------------------------
  7. TABLE OF CONTENTS
  8. - woo_image - Get Image from custom field
  9. - vt_resize - Resize post thumbnail
  10. - woo_get_youtube_video_image - Get thumbnail from YouTube
  11. - Add default filters to woo_embed()
  12. - woo_get_embed - Get Video
  13. - Woo Show Page Menu
  14. - Get the style path currently selected
  15. - Get page ID
  16. - Tidy up the image source url
  17. - Show image in RSS feed
  18. - Show analytics code footer
  19. - Browser detection body_class() output
  20. - Twitter's Blogger.js output for Twitter widgets
  21. - Template Detector
  22. - Framework Updater
  23. - WooFramework Update Page
  24. - WooFramework Update Head
  25. - WooFramework Version Getter
  26. - Woo URL shortener
  27. - SEO - woo_title()
  28. - SEO - Strip slashes from the display of the website/page title
  29. - SEO - woo_meta()
  30. - Woo Text Trimmer
  31. - Google Webfonts array
  32. - Google Fonts Stylesheet Generator
  33. - Enable Home link in WP Menus
  34. - Buy Themes page
  35. - Detects the Charset of String and Converts it to UTF-8
  36. - WP Login logo
  37. - WP Login logo URL
  38. - WP Login logo title
  39. - woo_pagination()
  40. - woo_breadcrumbs()
  41. -- woo_breadcrumbs_get_parents()
  42. -- woo_breadcrumbs_get_term_parents()
  43. - WordPress Admin Bar-related
  44. -- Disable WordPress Admin Bar
  45. -- Enhancements to the WordPress Admin Bar
  46. - woo_prepare_category_ids_from_option()
  47. - Move tracking code from footer to header.
  48. - woo_get_dynamic_values()
  49. - woo_get_posts_by_taxonomy()
  50. - If the user has specified a "posts page", load the "Blog" page template there
  51. - PressTrends API Integration
  52. - WooDojo Download Banner
  53. - wooframework_add_woodojo_banner()
  54. - wooframework_ajax_banner_close()
  55. - WooSEO Deprecation Banner
  56. - wooframework_add_wooseo_banner()
  57. - WooSidebars Deprecation Banner
  58. - wooframework_add_woosbm_banner()
  59. - Static Front Page Detection Banner
  60. - wooframework_get_theme_version_data()
  61. - wooframework_display_theme_version_data()
  62. -----------------------------------------------------------------------------------*/
  63. /*-----------------------------------------------------------------------------------*/
  64. /* woo_image - Get Image from custom field */
  65. /*-----------------------------------------------------------------------------------*/
  66. /*
  67. This function retrieves/resizes the image to be used with the post in this order:
  68. 1. Image passed through parameter 'src'
  69. 2. WP Post Thumbnail (if option activated)
  70. 3. Custom field
  71. 4. First attached image in post (if option activated)
  72. 5. First inline image in post (if option activated)
  73. Resize options (enabled in options panel):
  74. - vt_resize() is used to natively resize #2 and #4
  75. - Thumb.php is used to resize #1, #3, #4 (only if vt_resize is disabled) and #5
  76. Parameters:
  77. $key = Custom field key eg. "image"
  78. $width = Set width manually without using $type
  79. $height = Set height manually without using $type
  80. $class = CSS class to use on the img tag eg. "alignleft". Default is "thumbnail"
  81. $quality = Enter a quality between 80-100. Default is 90
  82. $id = Assign a custom ID, if alternative is required.
  83. $link = Echo with anchor ( 'src'), without anchor ( 'img') or original image URL ( 'url').
  84. $repeat = Auto Img Function. Adjust amount of images to return for the post attachments.
  85. $offset = Auto Img Function. Offset the $repeat with assigned amount of objects.
  86. $before = Auto Img Function. Add Syntax before image output.
  87. $after = Auto Img Function. Add Syntax after image output.
  88. $single = (true/false) Force thumbnail to link to the post instead of the image.
  89. $force = Force smaller images to not be effected with image width and height dimensions (proportions fix)
  90. $return = Return results instead of echoing out.
  91. $src = A parameter that accepts a img url for resizing. (No anchor)
  92. $meta = Add a custom meta text to the image and anchor of the image.
  93. $alignment = Crop alignment for thumb.php (l, r, t, b)
  94. $size = Custom pre-defined size for WP Thumbnail (string)
  95. $noheight = Don't output the height on img tag (for responsive designs)
  96. */
  97. if ( !function_exists('woo_image') ) {
  98. function woo_image($args) {
  99. /* ------------------------------------------------------------------------- */
  100. /* SET VARIABLES */
  101. /* ------------------------------------------------------------------------- */
  102. global $post;
  103. global $woo_options;
  104. //Defaults
  105. $key = 'image';
  106. $width = null;
  107. $height = null;
  108. $class = '';
  109. $quality = 90;
  110. $id = null;
  111. $link = 'src';
  112. $repeat = 1;
  113. $offset = 0;
  114. $before = '';
  115. $after = '';
  116. $single = false;
  117. $force = false;
  118. $return = false;
  119. $is_auto_image = false;
  120. $src = '';
  121. $meta = '';
  122. $alignment = '';
  123. $size = '';
  124. $noheight = '';
  125. $alt = '';
  126. $img_link = '';
  127. $attachment_id = array();
  128. $attachment_src = array();
  129. if ( ! is_array( $args ) )
  130. parse_str( $args, $args );
  131. extract( $args );
  132. // Set post ID
  133. if ( empty( $id ) ) {
  134. $id = $post->ID;
  135. }
  136. $thumb_id = esc_html( get_post_meta( $id, '_thumbnail_id', true ) );
  137. // Set alignment
  138. if ( $alignment == '' )
  139. $alignment = esc_html( get_post_meta( $id, '_image_alignment', true ) );
  140. // Get standard sizes
  141. if ( ! $width && ! $height ) {
  142. $width = '100';
  143. $height = '100';
  144. }
  145. // Cast $width and $height to integer
  146. $width = intval( $width );
  147. $height = intval( $height );
  148. /* ------------------------------------------------------------------------- */
  149. /* FIND IMAGE TO USE */
  150. /* ------------------------------------------------------------------------- */
  151. // When a custom image is sent through
  152. if ( $src != '' ) {
  153. $custom_field = esc_url( $src );
  154. $link = 'img';
  155. // WP 2.9 Post Thumbnail support
  156. } elseif ( get_option( 'woo_post_image_support' ) == 'true' && ! empty( $thumb_id ) ) {
  157. if ( get_option( 'woo_pis_resize' ) == 'true' ) {
  158. if ( 0 == $height ) {
  159. $img_data = wp_get_attachment_image_src( $thumb_id, array( intval( $width ), 9999 ) );
  160. $height = $img_data[2];
  161. }
  162. // Dynamically resize the post thumbnail
  163. $vt_crop = get_option( 'woo_pis_hard_crop' );
  164. if ($vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
  165. $vt_image = vt_resize( $thumb_id, '', $width, $height, $vt_crop );
  166. // Set fields for output
  167. $custom_field = esc_url( $vt_image['url'] );
  168. $width = $vt_image['width'];
  169. $height = $vt_image['height'];
  170. } else {
  171. // Use predefined size string
  172. if ( $size )
  173. $thumb_size = $size;
  174. else
  175. $thumb_size = array( $width, $height );
  176. $img_link = get_the_post_thumbnail( $id, $thumb_size, array( 'class' => 'woo-image ' . esc_attr( $class ) ) );
  177. }
  178. // Grab the image from custom field
  179. } else {
  180. $custom_field = esc_url( get_post_meta( $id, $key, true ) );
  181. }
  182. // Automatic Image Thumbs - get first image from post attachment
  183. if ( empty( $custom_field ) && get_option( 'woo_auto_img' ) == 'true' && empty( $img_link ) && ! ( is_singular() && in_the_loop() && $link == 'src' ) ) {
  184. if( $offset >= 1 )
  185. $repeat = $repeat + $offset;
  186. $attachments = get_children( array( 'post_parent' => $id,
  187. 'numberposts' => $repeat,
  188. 'post_type' => 'attachment',
  189. 'post_mime_type' => 'image',
  190. 'order' => 'DESC',
  191. 'orderby' => 'menu_order date')
  192. );
  193. // Search for and get the post attachment
  194. if ( ! empty( $attachments ) ) {
  195. $counter = -1;
  196. foreach ( $attachments as $att_id => $attachment ) {
  197. $counter++;
  198. if ( $counter < $offset )
  199. continue;
  200. if ( get_option( 'woo_post_image_support' ) == 'true' && get_option( 'woo_pis_resize' ) == 'true' ) {
  201. // Dynamically resize the post thumbnail
  202. $vt_crop = get_option( 'woo_pis_hard_crop' );
  203. if ( $vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
  204. $vt_image = vt_resize( $att_id, '', $width, $height, $vt_crop );
  205. // Set fields for output
  206. $custom_field = esc_url( $vt_image['url'] );
  207. $width = $vt_image['width'];
  208. $height = $vt_image['height'];
  209. } else {
  210. $src = wp_get_attachment_image_src( $att_id, 'large', true );
  211. $custom_field = esc_url( $src[0] );
  212. $attachment_id[] = $att_id;
  213. $src_arr[] = $custom_field;
  214. }
  215. $thumb_id = $att_id;
  216. $is_auto_image = true;
  217. }
  218. // Get the first img tag from content
  219. } else {
  220. $first_img = '';
  221. $post = get_post( $id );
  222. ob_start();
  223. ob_end_clean();
  224. $output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
  225. if ( !empty($matches[1][0]) ) {
  226. // Save Image URL
  227. $custom_field = esc_url( $matches[1][0] );
  228. // Search for ALT tag
  229. $output = preg_match_all( '/<img.+alt=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );
  230. if ( !empty($matches[1][0]) ) {
  231. $alt = esc_attr( $matches[1][0] );
  232. }
  233. }
  234. }
  235. }
  236. // Check if there is YouTube embed
  237. if ( empty( $custom_field ) && empty( $img_link ) ) {
  238. $embed = esc_html( get_post_meta( $id, 'embed', true ) );
  239. if ( $embed )
  240. $custom_field = esc_url( woo_get_video_image( $embed ) );
  241. }
  242. // Return if there is no attachment or custom field set
  243. if ( empty( $custom_field ) && empty( $img_link ) ) {
  244. // Check if default placeholder image is uploaded
  245. $placeholder = get_option( 'framework_woo_default_image' );
  246. if ( $placeholder && !(is_singular() && in_the_loop()) ) {
  247. $custom_field = esc_url( $placeholder );
  248. // Resize the placeholder if
  249. if ( get_option( 'woo_post_image_support' ) == 'true' && get_option( 'woo_pis_resize' ) == 'true' ) {
  250. // Dynamically resize the post thumbnail
  251. $vt_crop = get_option( 'woo_pis_hard_crop' );
  252. if ($vt_crop == 'true' ) $vt_crop = true; else $vt_crop = false;
  253. $vt_image = vt_resize( '', $placeholder, $width, $height, $vt_crop );
  254. // Set fields for output
  255. $custom_field = esc_url( $vt_image['url'] );
  256. $width = $vt_image['width'];
  257. $height = $vt_image['height'];
  258. }
  259. } else {
  260. return;
  261. }
  262. }
  263. if(empty( $src_arr ) && empty( $img_link ) ) { $src_arr[] = $custom_field; }
  264. /* ------------------------------------------------------------------------- */
  265. /* BEGIN OUTPUT */
  266. /* ------------------------------------------------------------------------- */
  267. $output = '';
  268. // Set output height and width
  269. $set_width = ' width="' . esc_attr( $width ) . '" ';
  270. $set_height = '';
  271. if ( ! $noheight && 0 < $height )
  272. $set_height = ' height="' . esc_attr( $height ) . '" ';
  273. // Set standard class
  274. if ( $class ) $class = 'woo-image ' . esc_attr( $class ); else $class = 'woo-image';
  275. // Do check to verify if images are smaller then specified.
  276. if($force == true){ $set_width = ''; $set_height = ''; }
  277. // WP Post Thumbnail
  278. if( ! empty( $img_link ) ) {
  279. if( $link == 'img' ) { // Output the image without anchors
  280. $output .= wp_kses_post( $before );
  281. $output .= $img_link;
  282. $output .= wp_kses_post( $after );
  283. } elseif( $link == 'url' ) { // Output the large image
  284. $src = wp_get_attachment_image_src( $thumb_id, 'large', true );
  285. $custom_field = esc_url( $src[0] );
  286. $output .= $custom_field;
  287. } else { // Default - output with link
  288. if ( ( is_single() || is_page() ) && $single == false ) {
  289. $rel = 'rel="lightbox"';
  290. $href = false;
  291. } else {
  292. $href = get_permalink( $id );
  293. $rel = '';
  294. }
  295. $title = 'title="' . esc_attr( get_the_title( $id ) ) .'"';
  296. $output .= wp_kses_post( $before );
  297. if($href == false){
  298. $output .= $img_link;
  299. } else {
  300. $output .= '<a ' . $title . ' href="' . esc_url( $href ) . '" '. $rel .'>' . $img_link . '</a>';
  301. }
  302. $output .= wp_kses_post( $after );
  303. }
  304. }
  305. // Use thumb.php to resize. Skip if image has been natively resized with vt_resize.
  306. elseif ( get_option( 'woo_resize') == 'true' && empty( $vt_image['url'] ) ) {
  307. foreach( $src_arr as $key => $custom_field ) {
  308. // Clean the image URL
  309. $href = esc_url( $custom_field );
  310. $custom_field = cleanSource( $custom_field );
  311. // Check if WPMU and set correct path AND that image isn't external
  312. if ( function_exists( 'get_current_site') ) {
  313. get_current_site();
  314. //global $blog_id; Breaks with WP3 MS
  315. if ( !$blog_id ) {
  316. global $current_blog;
  317. $blog_id = $current_blog->blog_id;
  318. }
  319. if ( isset($blog_id) && $blog_id > 0 ) {
  320. $imageParts = explode( 'files/', $custom_field );
  321. if ( isset( $imageParts[1] ) )
  322. $custom_field = '/blogs.dir/' . $blog_id . '/files/' . $imageParts[1];
  323. }
  324. }
  325. //Set the ID to the Attachment's ID if it is an attachment
  326. if($is_auto_image == true){
  327. $quick_id = $attachment_id[$key];
  328. } else {
  329. $quick_id = $id;
  330. }
  331. //Set custom meta
  332. if ($meta) {
  333. $alt = $meta;
  334. $title = 'title="' . esc_attr( $meta ) . '"';
  335. } else {
  336. if ( ( $alt != '' ) || ! ( $alt = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) ) ) {
  337. $alt = esc_attr( get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) );
  338. } else {
  339. $alt = esc_attr( get_the_title( $quick_id ) );
  340. }
  341. $title = 'title="'. esc_attr( get_the_title( $quick_id ) ) .'"';
  342. }
  343. // Set alignment parameter
  344. if ( $alignment != '' )
  345. $alignment = '&amp;a=' . urlencode( $alignment );
  346. $img_url = esc_url( get_template_directory_uri() . '/functions/thumb.php?src=' . $custom_field . '&amp;w=' . $width . '&amp;h=' . $height . '&amp;zc=1&amp;q=' . $quality . $alignment );
  347. $img_link = '<img src="' . $img_url . '" alt="' . esc_attr( $alt ) . '" class="' . esc_attr( stripslashes( $class ) ) . '" ' . $set_width . $set_height . ' />';
  348. if( $link == 'img' ) { // Just output the image
  349. $output .= wp_kses_post( $before );
  350. $output .= $img_link;
  351. $output .= wp_kses_post( $after );
  352. } elseif( $link == 'url' ) { // Output the image without anchors
  353. if($is_auto_image == true){
  354. $src = wp_get_attachment_image_src($thumb_id, 'large', true);
  355. $custom_field = esc_url( $src[0] );
  356. }
  357. $output .= $href;
  358. } else { // Default - output with link
  359. if ( ( is_single() || is_page() ) && $single == false ) {
  360. $rel = 'rel="lightbox"';
  361. } else {
  362. $href = get_permalink( $id );
  363. $rel = '';
  364. }
  365. $output .= wp_kses_post( $before );
  366. $output .= '<a ' . $title . ' href="' . esc_url( $href ) . '" ' . $rel . '>' . $img_link . '</a>';
  367. $output .= wp_kses_post( $after );
  368. }
  369. }
  370. // No dynamic resizing
  371. } else {
  372. foreach( $src_arr as $key => $custom_field ) {
  373. //Set the ID to the Attachment's ID if it is an attachment
  374. if( $is_auto_image == true && isset( $attachment_id[$key] ) ){
  375. $quick_id = $attachment_id[$key];
  376. } else {
  377. $quick_id = $id;
  378. }
  379. //Set custom meta
  380. if ($meta) {
  381. $alt = esc_attr( $meta );
  382. $title = 'title="'. esc_attr( $meta ) .'"';
  383. } else {
  384. if ($alt == '') $alt = esc_attr( get_post_meta( $thumb_id, '_wp_attachment_image_alt', true ) );
  385. $title = 'title="'. esc_attr( get_the_title( $quick_id ) ) .'"';
  386. }
  387. $img_link = '<img src="'. esc_url( $custom_field ) . '" alt="' . esc_attr( $alt ) . '" ' . $set_width . $set_height . ' class="' . esc_attr( stripslashes( $class ) ) . '" />';
  388. if ( $link == 'img' ) { // Just output the image
  389. $output .= wp_kses_post( $before );
  390. $output .= $img_link;
  391. $output .= wp_kses_post( $after );
  392. } elseif( $link == 'url' ) { // Output the URL to original image
  393. if ( $vt_image['url'] || $is_auto_image ) {
  394. $src = wp_get_attachment_image_src( $thumb_id, 'full', true );
  395. $custom_field = esc_url( $src[0] );
  396. }
  397. $output .= $custom_field;
  398. } else { // Default - output with link
  399. if ( ( is_single() || is_page() ) && $single == false ) {
  400. // Link to the large image if single post
  401. if ( $vt_image['url'] || $is_auto_image ) {
  402. $src = wp_get_attachment_image_src( $thumb_id, 'full', true );
  403. $custom_field = esc_url( $src[0] );
  404. }
  405. $href = $custom_field;
  406. $rel = 'rel="lightbox"';
  407. } else {
  408. $href = get_permalink( $id );
  409. $rel = '';
  410. }
  411. $output .= wp_kses_post( $before );
  412. $output .= '<a href="' . esc_url( $href ) . '" ' . $rel . ' ' . $title . '>' . $img_link . '</a>';
  413. $output .= wp_kses_post( $after );
  414. }
  415. }
  416. }
  417. // Remove no height attribute - IE fix when no height is set
  418. $output = str_replace( 'height=""', '', $output );
  419. $output = str_replace( 'height="0"', '', $output );
  420. // Return or echo the output
  421. if ( $return == TRUE )
  422. return $output;
  423. else
  424. echo $output; // Done
  425. }
  426. }
  427. /* Get thumbnail from Video Embed code */
  428. if ( ! function_exists( 'woo_get_video_image' ) ) {
  429. function woo_get_video_image( $embed ) {
  430. $video_thumb = '';
  431. // YouTube - get the video code if this is an embed code (old embed)
  432. preg_match( '/youtube\.com\/v\/([\w\-]+)/', $embed, $match );
  433. // YouTube - if old embed returned an empty ID, try capuring the ID from the new iframe embed
  434. if( ! isset( $match[1] ) )
  435. preg_match( '/youtube\.com\/embed\/([\w\-]+)/', $embed, $match );
  436. // YouTube - if it is not an embed code, get the video code from the youtube URL
  437. if( ! isset( $match[1] ) )
  438. preg_match( '/v\=(.+)&/', $embed, $match );
  439. // YouTube - get the corresponding thumbnail images
  440. if( isset( $match[1] ) )
  441. $video_thumb = "http://img.youtube.com/vi/" . urlencode( $match[1] ) . "/0.jpg";
  442. // return whichever thumbnail image you would like to retrieve
  443. return $video_thumb;
  444. } // End woo_get_video_image()
  445. }
  446. /*-----------------------------------------------------------------------------------*/
  447. /* vt_resize - Resize images dynamically using wp built in functions
  448. /*-----------------------------------------------------------------------------------*/
  449. /*
  450. * Resize images dynamically using wp built in functions
  451. * Victor Teixeira
  452. *
  453. * php 5.2+
  454. *
  455. * Exemplo de uso:
  456. *
  457. * <?php
  458. * $thumb = get_post_thumbnail_id();
  459. * $image = vt_resize( $thumb, '', 140, 110, true );
  460. * ?>
  461. * <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
  462. *
  463. * @param int $attach_id
  464. * @param string $img_url
  465. * @param int $width
  466. * @param int $height
  467. * @param bool $crop
  468. * @return array
  469. */
  470. if ( ! function_exists( 'vt_resize' ) ) {
  471. function vt_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
  472. // Cast $width and $height to integer
  473. $width = intval( $width );
  474. $height = intval( $height );
  475. // this is an attachment, so we have the ID
  476. if ( $attach_id ) {
  477. $image_src = wp_get_attachment_image_src( $attach_id, 'full' );
  478. $file_path = get_attached_file( $attach_id );
  479. // this is not an attachment, let's use the image url
  480. } else if ( $img_url ) {
  481. $file_path = parse_url( esc_url( $img_url ) );
  482. $file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
  483. //$file_path = ltrim( $file_path['path'], '/' );
  484. //$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
  485. $orig_size = getimagesize( $file_path );
  486. $image_src[0] = $img_url;
  487. $image_src[1] = $orig_size[0];
  488. $image_src[2] = $orig_size[1];
  489. }
  490. $file_info = pathinfo( $file_path );
  491. // check if file exists
  492. if ( !isset( $file_info['dirname'] ) && !isset( $file_info['filename'] ) && !isset( $file_info['extension'] ) )
  493. return;
  494. $base_file = $file_info['dirname'].'/'.$file_info['filename'].'.'.$file_info['extension'];
  495. if ( !file_exists($base_file) )
  496. return;
  497. $extension = '.'. $file_info['extension'];
  498. // the image path without the extension
  499. $no_ext_path = $file_info['dirname'].'/'.$file_info['filename'];
  500. $cropped_img_path = $no_ext_path.'-'.$width.'x'.$height.$extension;
  501. // checking if the file size is larger than the target size
  502. // if it is smaller or the same size, stop right here and return
  503. if ( $image_src[1] > $width ) {
  504. // 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)
  505. if ( file_exists( $cropped_img_path ) ) {
  506. $cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
  507. $vt_image = array (
  508. 'url' => $cropped_img_url,
  509. 'width' => $width,
  510. 'height' => $height
  511. );
  512. return $vt_image;
  513. }
  514. // $crop = false or no height set
  515. if ( $crop == false OR !$height ) {
  516. // calculate the size proportionaly
  517. $proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
  518. $resized_img_path = $no_ext_path.'-'.$proportional_size[0].'x'.$proportional_size[1].$extension;
  519. // checking if the file already exists
  520. if ( file_exists( $resized_img_path ) ) {
  521. $resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
  522. $vt_image = array (
  523. 'url' => $resized_img_url,
  524. 'width' => $proportional_size[0],
  525. 'height' => $proportional_size[1]
  526. );
  527. return $vt_image;
  528. }
  529. }
  530. // check if image width is smaller than set width
  531. $img_size = getimagesize( $file_path );
  532. if ( $img_size[0] <= $width ) $width = $img_size[0];
  533. // Check if GD Library installed
  534. if ( ! function_exists ( 'imagecreatetruecolor' ) ) {
  535. echo 'GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library';
  536. return;
  537. }
  538. // no cache files - let's finally resize it
  539. if ( function_exists( 'wp_get_image_editor' ) ) {
  540. $image = wp_get_image_editor( $file_path );
  541. if ( ! is_wp_error( $image ) ) {
  542. $image->resize( $width, $height, $crop );
  543. $save_data = $image->save();
  544. if ( isset( $save_data['path'] ) ) $new_img_path = $save_data['path'];
  545. }
  546. } else {
  547. $new_img_path = image_resize( $file_path, $width, $height, $crop );
  548. }
  549. $new_img_size = getimagesize( $new_img_path );
  550. $new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
  551. // resized output
  552. $vt_image = array (
  553. 'url' => $new_img,
  554. 'width' => $new_img_size[0],
  555. 'height' => $new_img_size[1]
  556. );
  557. return $vt_image;
  558. }
  559. // default output - without resizing
  560. $vt_image = array (
  561. 'url' => $image_src[0],
  562. 'width' => $width,
  563. 'height' => $height
  564. );
  565. return $vt_image;
  566. }
  567. }
  568. /*-----------------------------------------------------------------------------------*/
  569. /* Depreciated - woo_get_image - Get Image from custom field */
  570. /*-----------------------------------------------------------------------------------*/
  571. // Depreciated
  572. function 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) {
  573. // Run new function
  574. 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 );
  575. return;
  576. } // End woo_get_image()
  577. /*-----------------------------------------------------------------------------------*/
  578. /* woo_embed - Get Video embed code from custom field */
  579. /*-----------------------------------------------------------------------------------*/
  580. /*
  581. Get Video
  582. This function gets the embed code from the custom field
  583. Parameters:
  584. $key = Custom field key eg. "embed"
  585. $width = Set width manually without using $type
  586. $height = Set height manually without using $type
  587. $class = Custom class to apply to wrapping div
  588. $id = ID from post to pull custom field from
  589. */
  590. if ( ! function_exists( 'woo_embed' ) ) {
  591. function woo_embed($args) {
  592. //Defaults
  593. $key = 'embed';
  594. $width = null;
  595. $height = null;
  596. $class = 'video';
  597. $id = null;
  598. if ( ! is_array( $args ) )
  599. parse_str( $args, $args );
  600. extract( $args );
  601. if( empty( $id ) ) {
  602. global $post;
  603. $id = $post->ID;
  604. }
  605. // Cast $width and $height to integer
  606. $width = intval( $width );
  607. $height = intval( $height );
  608. $custom_field = esc_textarea( get_post_meta( $id, $key, true ) );
  609. if ($custom_field) :
  610. $custom_field = html_entity_decode( $custom_field ); // Decode HTML entities.
  611. $org_width = $width;
  612. $org_height = $height;
  613. $calculated_height = '';
  614. $embed_width = '';
  615. $embed_height = '';
  616. // Get custom width and height
  617. $custom_width = esc_html( get_post_meta( $id, 'width', true ) );
  618. $custom_height = esc_html( get_post_meta( $id, 'height', true ) );
  619. //Dynamic Height Calculation
  620. if ($org_height == '' && $org_width != '') {
  621. $raw_values = explode( ' ', $custom_field);
  622. foreach ( $raw_values as $raw ) {
  623. $embed_params = explode( '=', $raw );
  624. if ( $embed_params[0] == 'width' ) {
  625. $embed_width = preg_replace( '/[^0-9]/', '', $embed_params[1]);
  626. }
  627. elseif ( $embed_params[0] == 'height' ) {
  628. $embed_height = preg_replace( '/[^0-9]/', '', $embed_params[1]);
  629. }
  630. }
  631. $float_width = floatval( $embed_width );
  632. $float_height = floatval( $embed_height );
  633. @$float_ratio = $float_height / $float_width;
  634. $calculated_height = intval( $float_ratio * $width );
  635. }
  636. // Set values: width="XXX", height="XXX"
  637. if ( ! $custom_width ) $width = 'width="' . esc_attr( $width ) . '"'; else $width = 'width="' . esc_attr( $custom_width ) . '"';
  638. if ( $height == '' ) { $height = 'height="' . esc_attr( $calculated_height ) . '"'; } else { if ( ! $custom_height ) { $height = 'height="' . esc_attr( $height ) . '"'; } else { $height = 'height="' . esc_attr( $custom_height ) . '"'; } }
  639. $custom_field = stripslashes($custom_field);
  640. $custom_field = preg_replace( '/width="([0-9]*)"/' , $width , $custom_field );
  641. $custom_field = preg_replace( '/height="([0-9]*)"/' , $height, $custom_field );
  642. // Set values: width:XXXpx, height:XXXpx
  643. if ( ! $custom_width ) $width = 'width:' . esc_attr( $org_width ) . 'px'; else $width = 'width:' . esc_attr( $custom_width ) . 'px';
  644. 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'; } }
  645. $custom_field = stripslashes($custom_field);
  646. $custom_field = preg_replace( '/width:([0-9]*)px/' , $width , $custom_field );
  647. $custom_field = preg_replace( '/height:([0-9]*)px/' , $height, $custom_field );
  648. // Suckerfish menu hack
  649. $custom_field = str_replace( '<embed ', '<param name="wmode" value="transparent"></param><embed wmode="transparent" ', $custom_field );
  650. $custom_field = str_replace( '<iframe ', '<iframe wmode="transparent" ', $custom_field );
  651. $custom_field = str_replace( '" frameborder="', '?wmode=transparent" frameborder="', $custom_field );
  652. // Find and sanitize video URL. Add "wmode=transparent" to URL.
  653. $video_url = preg_match( '/src=["\']?([^"\' ]*)["\' ]/is', $custom_field, $matches );
  654. if ( isset( $matches[1] ) ) {
  655. $custom_field = str_replace( $matches[0], 'src="' . esc_url( add_query_arg( 'wmode', 'transparent', $matches[1] ) ) . '"', $custom_field );
  656. }
  657. $output = '';
  658. $output .= '<div class="'. esc_attr( $class ) .'">' . $custom_field . '</div>';
  659. return apply_filters( 'woo_embed', $output );
  660. else :
  661. return false;
  662. endif;
  663. }
  664. }
  665. /*-----------------------------------------------------------------------------------*/
  666. /* Add default filters to woo_embed() */
  667. /*-----------------------------------------------------------------------------------*/
  668. add_filter( 'woo_embed', 'do_shortcode' );
  669. /*-----------------------------------------------------------------------------------*/
  670. /* Depreciated - woo_get_embed - Get Video embed code from custom field */
  671. /*-----------------------------------------------------------------------------------*/
  672. // Depreciated
  673. function woo_get_embed($key = 'embed', $width, $height, $class = 'video', $id = null) {
  674. // Run new function
  675. return woo_embed( 'key='.$key.'&width='.$width.'&height='.$height.'&class='.$class.'&id='.$id );
  676. }
  677. /*-----------------------------------------------------------------------------------*/
  678. /* Woo Show Page Menu */
  679. /*-----------------------------------------------------------------------------------*/
  680. // Show menu in header.php
  681. // Exlude the pages from the slider
  682. function woo_show_pagemenu( $exclude = '' ) {
  683. // Split the featured pages from the options, and put in an array
  684. if ( get_option( 'woo_ex_featpages') ) {
  685. $menupages = get_option( 'woo_featpages' );
  686. $exclude = $menupages . ',' . $exclude;
  687. }
  688. $pages = wp_list_pages( 'sort_column=menu_order&title_li=&echo=0&depth=1&exclude=' . $exclude );
  689. $pages = preg_replace( '%<a ([^>]+)>%U','<a $1><span>', $pages );
  690. $pages = str_replace( '</a>','</span></a>', $pages );
  691. echo $pages;
  692. } // End woo_show_pagemenu()
  693. /*-----------------------------------------------------------------------------------*/
  694. /* Get the style path currently selected */
  695. /*-----------------------------------------------------------------------------------*/
  696. function woo_style_path() {
  697. $return = '';
  698. $style = $_REQUEST['style'];
  699. // Sanitize request input.
  700. $style = esc_attr( strtolower( trim( strip_tags( $style ) ) ) );
  701. if ( $style != '' ) {
  702. $style_path = $style;
  703. } else {
  704. $stylesheet = esc_attr( get_option( 'woo_alt_stylesheet' ) );
  705. // Prevent against an empty return to $stylesheet.
  706. if ( $stylesheet == '' ) {
  707. $stylesheet = 'default.css';
  708. }
  709. $style_path = str_replace( '.css', '', $stylesheet );
  710. }
  711. if ( $style_path == 'default' ) {
  712. $return = 'images';
  713. } else {
  714. $return = 'styles/' . $style_path;
  715. }
  716. echo esc_html( $return );
  717. } // End woo_style_path()
  718. /*-----------------------------------------------------------------------------------*/
  719. /* Get page ID */
  720. /*-----------------------------------------------------------------------------------*/
  721. function get_page_id( $page_slug ) {
  722. $page_id = get_page_by_path( $page_slug );
  723. if ($page_id) {
  724. return $page_id->ID;
  725. } else {
  726. return null;
  727. }
  728. } // End get_page_id()
  729. /*-----------------------------------------------------------------------------------*/
  730. /* Tidy up the image source url */
  731. /*-----------------------------------------------------------------------------------*/
  732. function cleanSource( $src ) {
  733. // remove slash from start of string
  734. if(strpos($src, "/") == 0) {
  735. $src = substr($src, -(strlen($src) - 1));
  736. }
  737. // Check if same domain so it doesn't strip external sites
  738. $host = str_replace( 'www.', '', $_SERVER['HTTP_HOST'] );
  739. if ( ! strpos( $src, $host ) )
  740. return $src;
  741. $regex = "/^((ht|f)tp(s|):\/\/)(www\.|)" . $host . "/i";
  742. $src = preg_replace ( $regex, '', $src );
  743. $src = htmlentities ( $src );
  744. // remove slash from start of string
  745. if ( strpos( $src, '/' ) === 0 ) {
  746. $src = substr ( $src, -( strlen( $src ) - 1 ) );
  747. }
  748. return $src;
  749. } // End cleanSource()
  750. /*-----------------------------------------------------------------------------------*/
  751. /* Show image in RSS feed */
  752. /* Original code by Justin Tadlock http://justintadlock.com */
  753. /*-----------------------------------------------------------------------------------*/
  754. if ( get_option( 'woo_rss_thumb' ) == 'true' ) {
  755. if ( get_option( 'rss_use_excerpt' ) )
  756. add_filter( 'the_excerpt_rss', 'add_image_RSS' );
  757. else
  758. add_filter( 'the_content', 'add_image_RSS' );
  759. }
  760. function add_image_RSS( $content ) {
  761. global $post, $id;
  762. $blog_key = substr( md5( home_url( '/' ) ), 0, 16 );
  763. if ( ! is_feed() ) return $content;
  764. // Get the "image" from custom field
  765. //$image = get_post_meta($post->ID, 'image', $single = true);
  766. $image = woo_image( 'return=true&link=url' );
  767. $image_width = '240';
  768. // If there's an image, display the image with the content
  769. if( $image != '' ) {
  770. $content = '<p style="float:right; margin:0 0 10px 15px; width:' . esc_attr( $image_width ) . 'px;">
  771. <img src="' . esc_url( $image ) . '" width="' . esc_attr( $image_width ) . '" />
  772. </p>' . $content;
  773. return $content;
  774. } else {
  775. // If there's not an image, just display the content
  776. $content = $content;
  777. return $content;
  778. }
  779. } // End add_image_RSS()
  780. /*-----------------------------------------------------------------------------------*/
  781. /* Show analytics code in footer */
  782. /*-----------------------------------------------------------------------------------*/
  783. function woo_analytics(){
  784. $output = get_option( 'woo_google_analytics' );
  785. if ( $output != '' )
  786. echo stripslashes( $output ) . "\n";
  787. } // End woo_analytics()
  788. add_action( 'wp_footer','woo_analytics' );
  789. /*-----------------------------------------------------------------------------------*/
  790. /* Browser detection body_class() output */
  791. /*-----------------------------------------------------------------------------------*/
  792. add_filter( 'body_class','browser_body_class' );
  793. function browser_body_class( $classes ) {
  794. global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
  795. if($is_lynx) $classes[] = 'lynx';
  796. elseif($is_gecko) $classes[] = 'gecko';
  797. elseif($is_opera) $classes[] = 'opera';
  798. elseif($is_NS4) $classes[] = 'ns4';
  799. elseif($is_safari) $classes[] = 'safari';
  800. elseif($is_chrome) $classes[] = 'chrome';
  801. elseif($is_IE) {
  802. $browser = $_SERVER['HTTP_USER_AGENT'];
  803. $browser = substr( "$browser", 25, 8);
  804. if ($browser == "MSIE 7.0" ) {
  805. $classes[] = 'ie7';
  806. $classes[] = 'ie';
  807. } elseif ($browser == "MSIE 6.0" ) {
  808. $classes[] = 'ie6';
  809. $classes[] = 'ie';
  810. } elseif ($browser == "MSIE 8.0" ) {
  811. $classes[] = 'ie8';
  812. $classes[] = 'ie';
  813. } elseif ($browser == "MSIE 9.0" ) {
  814. $classes[] = 'ie9';
  815. $classes[] = 'ie';
  816. } else {
  817. $classes[] = 'ie';
  818. }
  819. }
  820. else $classes[] = 'unknown';
  821. if( $is_iphone ) $classes[] = 'iphone';
  822. // Alternative style body class.
  823. $style = get_option( 'woo_alt_stylesheet', 'default' );
  824. $style = str_replace( '.css', '', $style );
  825. if ( '' != $style ) {
  826. $classes[] = 'alt-style-' . esc_attr( $style );
  827. }
  828. return $classes;
  829. } // End browser_body_class()
  830. /*-----------------------------------------------------------------------------------*/
  831. /* Twitter's Blogger.js output for Twitter widgets */
  832. /*-----------------------------------------------------------------------------------*/
  833. if ( ! function_exists( 'woo_twitter_script' ) ) {
  834. function woo_twitter_script($unique_id,$username,$limit) {
  835. ?>
  836. <script type="text/javascript">
  837. <!--//--><![CDATA[//><!--
  838. function twitterCallback2(twitters) {
  839. var statusHTML = [];
  840. for (var i=0; i<twitters.length; i++){
  841. var username = twitters[i].user.screen_name;
  842. var status = twitters[i].text.replace(/((https?|s?ftp|ssh)\:\/\/[^"\s\<\>]*[^.,;'">\:\s\<\>\)\]\!])/g, function(url) {
  843. return '<a href="'+url+'">'+url+'</a>';
  844. }).replace(/\B@([_a-z0-9]+)/ig, function(reply) {
  845. return reply.charAt(0)+'<a href="http://twitter.com/'+reply.substring(1)+'">'+reply.substring(1)+'</a>';
  846. });
  847. 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>' );
  848. }
  849. document.getElementById( 'twitter_update_list_<?php echo esc_attr( $unique_id ); ?>').innerHTML = statusHTML.join( '' );
  850. }
  851. function relative_time(time_value) {
  852. var values = time_value.split( " " );
  853. time_value = values[1] + " " + values[2] + ", " + values[5] + " " + values[3];
  854. var parsed_date = Date.parse(time_value);
  855. var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
  856. var delta = parseInt((relative_to.getTime() - parsed_date) / 1000);
  857. delta = delta + (relative_to.getTimezoneOffset() * 60);
  858. if (delta < 60) {
  859. return '<?php esc_attr_e( 'less than a minute ago', 'woothemes' ); ?>';
  860. } else if(delta < 120) {
  861. return '<?php esc_attr_e( 'about a minute ago', 'woothemes' ); ?>';
  862. } else if(delta < (60*60)) {
  863. return (parseInt(delta / 60)).toString() + ' <?php esc_attr_e( 'minutes ago', 'woothemes' ); ?>';
  864. } else if(delta < (120*60)) {
  865. return 'about an hour ago';
  866. } else if(delta < (24*60*60)) {
  867. return 'about ' + (parseInt(delta / 3600)).toString() + ' <?php esc_attr_e( 'hours ago', 'woothemes' ); ?>';
  868. } else if(delta < (48*60*60)) {
  869. return '1 day ago';
  870. } else {
  871. return (parseInt(delta / 86400)).toString() + ' <?php esc_attr_e( 'days ago', 'woothemes' ); ?>';
  872. }
  873. }
  874. //-->!]]>
  875. </script>
  876. <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&amp;count=<?php echo esc_attr( $limit ); ?>&amp;include_rts=t"></script>
  877. <?php
  878. } // End woo_twitter_script()
  879. }
  880. /*-----------------------------------------------------------------------------------*/
  881. /* Deprecated: Template Detector */
  882. /*-----------------------------------------------------------------------------------*/
  883. function woo_active_template( $filename = null ) {
  884. 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' ) );
  885. return false; // No $filename argument was set
  886. } // End woo_active_template()
  887. /*-----------------------------------------------------------------------------------*/
  888. /* WooFramework Update Page */
  889. /*-----------------------------------------------------------------------------------*/
  890. function woothemes_framework_update_page() {
  891. // Clear transients.
  892. delete_transient( 'woo_framework_critical_update' );
  893. delete_transient( 'woo_framework_critical_update_data' );
  894. delete_transient( 'wooframework_version_data' );
  895. $method = get_filesystem_method();
  896. $to = ABSPATH . 'wp-content/themes/' . get_option( 'template' ) . '/functions/';
  897. if(isset($_POST['password'])){
  898. $cred = $_POST;
  899. $filesystem = WP_Filesystem($cred);
  900. }
  901. elseif(isset($_POST['woo_ftp_cred'])){
  902. $cred = unserialize(base64_decode($_POST['woo_ftp_cred']));
  903. $filesystem = WP_Filesystem($cred);
  904. } else {
  905. $filesystem = WP_Filesystem();
  906. };
  907. $url = admin_url( 'admin.php?page=woothemes_framework_update' );
  908. ?>
  909. <div class="wrap themes-page">
  910. <?php
  911. if($filesystem == false){
  912. request_filesystem_credentials ( $url );
  913. } else {
  914. // Clear the transient to force a fresh update.
  915. delete_transient( 'wooframework_version_data' );
  916. $localversion = esc_html( get_option( 'woo_framework_version' ) );
  917. $remoteversion = woo_get_fw_version();
  918. // Test if new version
  919. $upd = false;
  920. $loc = explode( '.',$localversion);
  921. $rem = explode( '.',$remoteversion['version']);
  922. if( $loc[0] < $rem[0] )
  923. $upd = true;
  924. elseif ( $loc[1] < $rem[1] )
  925. $upd = true;
  926. elseif( $loc[2] < $rem[2] )
  927. $upd = true;
  928. ?>
  929. <?php screen_icon( 'tools' ); ?>
  930. <h2>Framework Update</h2>
  931. <span style="display:none"><?php echo $method; ?></span>
  932. <form method="post" enctype="multipart/form-data" id="wooform" action="<?php /* echo $url; */ ?>">
  933. <?php if( $upd ) { ?>
  934. <?php wp_nonce_field( 'update-options' ); ?>
  935. <h3>A new version of WooFramework is available.</h3>
  936. <p>This updater will download and extract the latest WooFramework files to your current theme's functions folder. </p>
  937. <p>We recommend backing up your theme files and updating WordPress to latest version before proceeding.</p>
  938. <p>&rarr; <strong>Your version:</strong> <?php echo $localversion; ?></p>
  939. <p>&rarr; <strong>Current Version:</strong> <?php echo $remoteversion['version']; ?></p>
  940. <input type="submit" class="button" value="Update Framework" />
  941. <?php } else { ?>
  942. <h3>You have the latest version of WooFramework</h3>
  943. <p>&rarr; <strong>Your version:</strong> <?php echo $localversion; ?></p>
  944. <?php } ?>
  945. <input type="hidden" name="woo_update_save" value="save" />
  946. <input type="hidden" name="woo_ftp_cred" value="<?php echo esc_attr( base64_encode(serialize($_POST))); ?>" />
  947. </form>
  948. <?php } ?>
  949. </div>
  950. <?php
  951. };
  952. /*-----------------------------------------------------------------------------------*/
  953. /* WooFramework Update Head */
  954. /*-----------------------------------------------------------------------------------*/
  955. function woothemes_framework_update_head() {
  956. if( isset( $_REQUEST['page'] ) ) {
  957. // Sanitize page being requested.
  958. $_page = esc_attr( $_REQUEST['page'] );
  959. if( $_page == 'woothemes_framework_update' ) {
  960. //Setup Filesystem
  961. $method = get_filesystem_method();
  962. if( isset( $_POST['woo_ftp_cred'] ) ) {
  963. $cred = unserialize( base64_decode( $_POST['woo_ftp_cred'] ) );
  964. $filesystem = WP_Filesystem($cred);
  965. } else {
  966. $filesystem = WP_Filesystem();
  967. }
  968. if( $filesystem == false && $_POST['upgrade'] != 'Proceed' ) {
  969. function woothemes_framework_update_filesystem_warning() {
  970. $method = get_filesystem_method();
  971. echo "<div id='filesystem-warning' class='updated fade'><p>Failed: Filesystem preventing downloads. ( ". $method .")</p></div>";
  972. }
  973. add_action( 'admin_notices', 'woothemes_framework_update_filesystem_warning' );
  974. return;
  975. }
  976. if(isset($_REQUEST['woo_update_save'])){
  977. // Sanitize action being requested.
  978. $_action = esc_attr( $_REQUEST['woo_update_save'] );
  979. if( $_action == 'save' ) {
  980. $temp_file_addr = download_url( esc_url( 'http://www.woothemes.com/updates/framework.zip' ) );
  981. if ( is_wp_error($temp_file_addr) ) {
  982. $error = esc_html( $temp_file_addr->get_error_code() );
  983. if( $error == 'http_no_url' ) {
  984. //The source file was not found or is invalid
  985. function woothemes_framework_update_missing_source_warning() {
  986. echo "<div id='source-warning' class='updated fade'><p>Failed: Invalid URL Provided</p></div>";
  987. }
  988. add_action( 'admin_notices', 'woothemes_framework_update_missing_source_warning' );
  989. } else {
  990. function woothemes_framework_update_other_upload_warning() {
  991. echo "<div id='source-warning' class='updated fade'><p>Failed: Upload - $error</p></div>";
  992. }
  993. add_action( 'admin_notices', 'woothemes_framework_update_other_upload_warning' );
  994. }
  995. return;
  996. }
  997. //Unzip it
  998. global $wp_filesystem;
  999. $to = $wp_filesystem->wp_content_dir() . "/themes/" . get_option( 'template' ) . "/functions/";
  1000. $dounzip = unzip_file($temp_file_addr, $to);
  1001. unlink($temp_file_addr); // Delete Temp File
  1002. if ( is_wp_error($dounzip) ) {
  1003. //DEBUG
  1004. $error = esc_html( $dounzip->get_error_code() );
  1005. $data = $dounzip->get_error_data($error);
  1006. //echo $error. ' - ';
  1007. //print_r($data);
  1008. if($error == 'incompatible_archive') {
  1009. //The source file was not found or is invalid
  1010. function woothemes_framework_update_no_archive_warning() {
  1011. echo "<div id='woo-no-archive-warning' class='updated fade'><p>Failed: Incompatible archive</p></div>";
  1012. }
  1013. add_action( 'admin_notices', 'woothemes_framework_update_no_archive_warning' );
  1014. }
  1015. if($error == 'empty_archive') {
  1016. function woothemes_framework_update_empty_archive_warning() {
  1017. echo "<div id='woo-empty-archive-warning' class='updated fade'><p>Failed: Empty Archive</p></div>";
  1018. }
  1019. add_action( 'admin_notices', 'woothemes_framework_update_empty_archive_warning' );
  1020. }
  1021. if($error == 'mkdir_failed') {
  1022. function woothemes_framework_update_mkdir_warning() {
  1023. echo "<div id='woo-mkdir-warning' class='updated fade'><p>Failed: mkdir Failure</p></div>";
  1024. }
  1025. add_action( 'admin_notices', 'woothemes_framework_update_mkdir_warning' );
  1026. }
  1027. if($error == 'copy_failed') {
  1028. function woothemes_framework_update_copy_fail_warning() {
  1029. echo "<div id='woo-copy-fail-warning' class='updated fade'><p>Failed: Copy Failed</p></div>";
  1030. }
  1031. add_action( 'admin_notices', 'woothemes_framework_update_copy_fail_warning' );
  1032. }
  1033. return;
  1034. }
  1035. function woothemes_framework_updated_success() {
  1036. echo "<div id='framework-upgraded' class='updated fade'><p>New framework successfully downloaded, extracted and updated.</p></div>";
  1037. }
  1038. add_action( 'admin_notices', 'woothemes_framework_updated_success' );
  1039. }
  1040. }
  1041. } //End user input save part of the update
  1042. }
  1043. }
  1044. add_action( 'admin_head', 'woothemes_framework_update_head' );
  1045. /*-----------------------------------------------------------------------------------*/
  1046. /* WooFramework Version Getter */
  1047. /*-----------------------------------------------------------------------------------*/
  1048. function woo_get_fw_version( $url = '', $check_if_critical = false ) {
  1049. if( ! empty( $url ) ) {
  1050. $fw_url = $url;
  1051. } else {
  1052. $fw_url = 'http://www.woothemes.com/updates/functions-changelog.txt';
  1053. }
  1054. $output = array( 'version' => '', 'is_critical' => false );
  1055. $version_data = get_transient( 'wooframework_version_data' );
  1056. if ( $version_data != '' && $check_if_critical == false ) { return $version_data; }
  1057. $temp_file_addr = download_url( $fw_url );
  1058. if( ! is_wp_error( $temp_file_addr ) && $file_contents = file( $temp_file_addr ) ) {
  1059. foreach ( $file_contents as $line_num => $line ) {
  1060. $current_line = $line;
  1061. if( $line_num > 1 ) { // Not the first or second... dodgy :P
  1062. if ( preg_match( '/^[0-9]/', $line ) ) {
  1063. // Do critical update check.
  1064. if ( $check_if_critical && ( strtolower( trim( substr( $line, -10 ) ) ) == 'critical' ) ) {
  1065. $output['is_critical'] = true;
  1066. }
  1067. $current_line = stristr( $current_line, 'version' );
  1068. $current_line = preg_replace( '~[^0-9,.]~','',$current_line );
  1069. $output['version'] = $current_line;
  1070. break;
  1071. }
  1072. }
  1073. }
  1074. unlink( $temp_file_addr );
  1075. } else {
  1076. $output['version'] = get_option( 'woo_framework_version' );
  1077. }
  1078. // Set the transient containing the latest version number.
  1079. set_transient( 'wooframework_version_data', $output , 60*60*24 );
  1080. return $output;
  1081. } // End woo_get_fw_version()
  1082. /*-----------------------------------------------------------------------------------*/
  1083. /* WooFramework Version Checker */
  1084. /*-----------------------------------------------------------------------------------*/
  1085. function woo_framework_version_checker( $local_version, $check_if_critical = false ) {
  1086. $data = array( 'is_update' => false, 'version' => '1.0.0', 'status' => 'none' );
  1087. if ( ! $local_version ) { return $data; }
  1088. $version_data = woo_get_fw_version( '', $check_if_critical );
  1089. $check = version_compare( $version_data['version'], $local_version ); // Returns 1 if there is an update available.
  1090. if ( $check == 1 ) {
  1091. $data['is_update'] = true;
  1092. $data['version'] = $version_data['version'];
  1093. $data['is_critical'] = $version_data['is_critical'];
  1094. }
  1095. return $data;
  1096. } // End woo_framework_version_checker()
  1097. /*-----------------------------------------------------------------------------------*/
  1098. /* Woo URL shortener */
  1099. /*-----------------------------------------------------------------------------------*/
  1100. function woo_short_url($url) {
  1101. $service = get_option( 'woo_url_shorten' );
  1102. $bitlyapilogin = get_option( 'woo_bitly_api_login' );;
  1103. $bitlyapikey = get_option( 'woo_bitly_api_key' );;
  1104. if (isset($service)) {
  1105. switch ($service)
  1106. {
  1107. case 'TinyURL':
  1108. $shorturl = getTinyUrl($url);
  1109. break;
  1110. case 'Bit.ly':
  1111. if (isset($bitlyapilogin) && isset($bitlyapikey) && ($bitlyapilogin != '') && ($bitlyapikey != '')) {
  1112. $shorturl = make_bitly_url($url,$bitlyapilogin,$bitlyapikey,'json' );
  1113. }
  1114. else {
  1115. $shorturl = getTinyUrl($url);
  1116. }
  1117. break;
  1118. case 'Off':
  1119. $shorturl = $url;
  1120. break;
  1121. default:
  1122. $shorturl = $url;
  1123. break;
  1124. }
  1125. }
  1126. else {
  1127. $shorturl = $url;
  1128. }
  1129. return $shorturl;
  1130. }
  1131. //TinyURL
  1132. function getTinyUrl($url) {
  1133. $tinyurl = file_get_contents_curl( "http…

Large files files are truncated, but you can click here to view the full file