PluginProbe
WP Ultimate Post Grid / 2.6.0
WP Ultimate Post Grid v2.6.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / vafpress / classes / util / res.php

res.php in WP Ultimate Post Grid 2.6.0, at vendor/vafpress/classes/util/res.php

91 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class VP_Util_Res
4 {
5
6 public static function is_font_awesome($icon)
7 {
8 if (strpos($icon, 'font-awesome:') === 0)
9 {
10 return trim(str_replace('font-awesome:', '', $icon));
11 }
12 return false;
13 }
14
15 public static function get_preview_from_url($url)
16 {
17 $preview = '';
18 $images = array('jpg', 'JPG', 'jpeg', 'bmp', 'gif', 'png', 'ico');
19
20 if(filter_var($url, FILTER_VALIDATE_URL) !== FALSE)
21 {
22 // check for extension, if it has extension then use it
23 $info = pathinfo($url);
24 if(isset($info['extension']))
25 {
26 if(in_array($info['extension'], $images))
27 {
28 $preview = $url;
29 }
30 else
31 {
32 $type = wp_ext2type( $info['extension'] );
33 if(is_null($type))
34 $type = 'default';
35 $preview = includes_url() . 'images/crystal/' . $type . '.png';
36 }
37 }
38 else
39 {
40 // if no extension, try to discover from mime
41 $mime = wp_remote_head( $url );
42 if(!is_wp_error( $mime ))
43 {
44 $mime = $mime['headers']['content-type'];
45 if(strpos($mime, 'image') === 0)
46 $preview = $url;
47 else
48 $preview = wp_mime_type_icon( $mime );
49 }
50 else
51 {
52 $preview = includes_url() . 'images/crystal/' . 'default' . '.png';
53 }
54 }
55 }
56
57 return $preview;
58 }
59
60 public static function img($url)
61 {
62 // empty parameter
63 if (empty($url)) {
64 return '';
65 }
66
67 // if already absolute, then just return
68 if (parse_url($url, PHP_URL_SCHEME))
69 {
70 return $url;
71 }
72 else
73 {
74 // check if got beginning slash
75 if ($url[0] == '/' or $url[0] == '\\')
76 {
77 return VP_IMAGE_URL . $url;
78 }
79 return VP_IMAGE_URL . '/' . $url;
80 }
81 }
82
83 public static function img_out($img, $default)
84 {
85 if (empty($img))
86 echo self::img($default);
87 else
88 echo self::img($img);
89 }
90
91 }