forked from wp-plugins/html-social-share-buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.php
64 lines (53 loc) · 1.76 KB
/
filters.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
<?php
new zm_sh_filters;
class zm_sh_filters{
function __construct(){
add_filter("zm_sh_placeholder", array($this, "zm_sh_placeholder"));
add_filter("zm_sh_ico_link", array($this, "ico_link"));
}
function zm_sh_placeholder($item){
$parmalink = zm_sh_curentPageURL();
$title = $this->make_title($parmalink);
$description = get_bloginfo ( 'description' );
$image_url = $this->image_url($parmalink);
$item = str_replace( "%%permalink%%", urlencode($parmalink), $item);
$item = str_replace( "%%title%%", urlencode($title), $item);
$item = str_replace( "%%description%%", urlencode($description), $item);
$item = str_replace( "%%imageurl%%", urlencode($image_url), $item);
return $item;
}
function ico_link($ico_link){
return $ico_link;
}
function make_title($url){
$home = get_home_url();
if($home == $url or $home . "/" == $url){
$title = get_bloginfo ( 'name' );
}
elseif($postid = url_to_postid( $url )){
$title = get_the_title( $postid );
}
else{
$title = get_the_title( );
}
return apply_filters('zm_sh_title', $title);
}
function image_url($url) {
global $post;
if(empty($post->ID)) return;
$thumb_id = get_post_thumbnail_id($post->ID);
$attachmetn_url = wp_get_attachment_url( $thumb_id);
$imageurl = urlencode( $attachmetn_url );
if(!$imageurl){
$postid = url_to_postid( $url );
$post = get_post( $postid, "OBJECT" );
$content = $post->post_content;
$content = str_replace('zm_sh_btn', '', $content);
$content = do_shortcode($content);
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $content, $matches);
if(isset($matches[1][0]))
$imageurl = $matches[1][0];
}
return $imageurl;
}
}