forked from wp-plugins/html-social-share-buttons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconsets.php
180 lines (150 loc) · 4.73 KB
/
iconsets.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
class zm_sh_iconset{
public $options;
private $iconsets;
private $iconsetId;
private $curr_iconset;
function __get($var){
if($var == 'curr_iconset')
return $this->get_current_iconset();
if($var == 'private')
return $this->get_current_iconset();
elseif(isset($this->iconsets->$var))
return $this->iconsets->$var;
}
function __construct(){
global $zm_sh, $zm_sh_default_options;
global $zm_sh_iconset_classes;
$this->iconsets = new stdClass;
//var_dump($this->iconsets);
$this->options = get_option("zm_shbt_fld", $zm_sh_default_options);
//print_r($zm_sh_iconset_classes);
foreach($zm_sh_iconset_classes as $iconset)
$this->add_iconset(new $iconset);
do_action( "zm_sh_add_iconset");
add_action( 'wp_ajax_get_iconset', array($this, 'wp_ajax_get_iconset') );
add_action( 'wp_ajax_get_iconset_preview', array($this, 'wp_ajax_get_iconset_preview') );
}
function add_iconset($iconset){
$id = $iconset->id;
if(empty($id)) return;
$this->iconsets->$id = $iconset;
$class = get_class($iconset);
if(isset($zm_sh_iconset_classes[$class]))
unset($zm_sh_iconset_classes[$class]);
return $this->iconsets->$id;
}
function get_current_iconset(){
$this->iconsetId = $this->options['iconset'];
$this->curr_iconset = $this->get_iconset($this->iconsetId);
return $this->curr_iconset;
}
function set_current_iconset($iconset_name){
$this->curr_iconset = $iconset_name;
return true;
}
function get_iconset($iconset = "default", $setAsCurrent = false){
//print_r(debug_backtrace());
//if(empty($iconset)) return false;
//echo '"><pre>';
//print_r(debug_backtrace ());
if($setAsCurrent)
$this->curr_iconset = $this->iconsets->$iconset;
if(isset($this->iconsets->$iconset))
return $this->iconsets->$iconset;
else
return $this->iconsets->default;
}
function get_iconsets(){
return $this->iconsets;
}
function get_iconset_list(){
$iocnsets = array();
foreach($this->iconsets as $iconset){
$id = $iconset->id;
$iocnsets[$id] = $iconset->name;
}
return $iocnsets;
}
public function remove_iconset($id){
unset($this->iconsets->$id);
return $id;
}
function wp_ajax_get_iconset_preview(){
$iconset_id = $_POST['iconsetId'];
$preview = $this->get_iconset($iconset_id)->get_iconset_preview();
echo $preview;
die();
}
function wp_ajax_get_iconset(){
$iconset_id = $_POST['iconsetId'];
$iconset = $this->get_iconset($iconset_id);
echo json_encode($iconset);
die();
}
}
abstract class __iconset_parent_class implements interface_iconset{
public $__FILE__;
public $id;
public $name;
public $types;
public $icons;
public $inTheme = false;
public $stylesheet = "style.css";
public $preview_img = "preview.png";
function __construct(){
$this->set_dir_and_url($this->__FILE__);
}
function set_dir_and_url($__FILE__){
if(isset($this->inTheme) and $this->inTheme){
$this->dir = get_template_directory(). $this->inTheme;
$this->url = get_template_directory_uri(). $this->inTheme;
}
elseif(isset($this->inChildTheme) and $this->inChildTheme){
$this->dir = get_stylesheet_directory(). $this->inChildTheme;
$this->url = get_stylesheet_directory_uri(). $this->inChildTheme;
}
else{
$this->dir = plugin_dir_path( $__FILE__ );
$this->url = plugins_url( "/", $__FILE__ );
}
$this->stylesheet_url = $this->url . $this->stylesheet;
$this->preview_img_url = $this->url . $this->preview_img;
$this->preview_img_dir = $this->dir . $this->preview_img;
}
public function get_icons(){
return $this->icons;
}
public function get_icons_id_name(){
$new = array();
foreach( $this->icons as $id=>$icon)
$new[$id] = $icon['name'];
return $new;
}
public function push_icon($icon){
$this->icons[] = $icon;
}
public function get_iconset_preview(){
return $this->url . $this->preview_img;
}
}
// Searching for iconsets
// This will search for ssb.php if found then includ that.
$dir = scandir($dir_iconset);
foreach ($dir as $subdir) {
if ($subdir === '.' or $subdir === '..') continue;
$iconset_file = $dir_iconset . '/' . $subdir . "/ssb.php";
if (file_exists($iconset_file)) {
require_once $iconset_file;
$class_name = 'zm_sh_iconset_' . $subdir;
if(class_exists($class_name))
$zm_sh_iconset_classes[$class_name] = $class_name;
}
}
add_action( 'wp_ajax_get_iconset_details', 'wp_ajax_get_iconset_details' );
function wp_ajax_get_iconset_details() {
$iconset_class = new zm_sh_iconset;
$iconset = $iconset_class->get_iconset($_POST['iconset']);
echo json_encode($iconset->get_icons_id_name());
die();
}