-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework.php
74 lines (74 loc) · 1.96 KB
/
framework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
class vc{
public static function cache($k,$time="+1 hour",$v=NULL){
if($v===NULL){
$time_c=get_option("cache_".$k."_time",1);
if(strtotime($time,$time_c)<strtotime("now")){
return false;
}
$res = get_option("cache_".$k,1);
if(unserialize($v)===NULL){$res=unserialize($res);}
return $res;
}else{
$ov=$v;
if(is_array($v)){$v=serialize($v);}
update_option("cache_".$k,$v);
update_option("cache_".$k."_time",strtotime("now"));
return $ov;
}
}
public static function img($image="",$size="full"){
if(is_array($image)){
if($size=="full"){
return $image['url'];
}elseif(array_key_exists($size, $image['sizes'])){
return $image['sizes'][$size];
}else{
return $image['url'];
}
}else{
$res=wp_get_attachment_image_src($image,$size);
return $res[0];
}
}
public static function video($video){
global $wp_embed;
return $wp_embed->run_shortcode('[embed]'.$video.'[/embed]');
}
public static function base64_image($file){
if(!function_exists('mime_content_type')) {
function mime_content_type($filename) {
$mime_types = array(
'png' => 'image/png',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'bmp' => 'image/bmp',
'ico' => 'image/vnd.microsoft.icon',
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
);
$ext = strtolower(array_pop(explode('.',$filename)));
if (array_key_exists($ext, $mime_types)) {
return $mime_types[$ext];
}
elseif (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME);
$mimetype = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mimetype;
}
else {
return 'application/octet-stream';
}
}
}
$data = file_get_contents($file);
$type=mime_content_type($file);
$base64 = 'data:' . $type . ';base64,' . base64_encode($data);
return $base64;
}
}