PluginProbe
Social Share Buttons / 1.6
Social Share Buttons v1.6
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / classes / class-utils.php

class-utils.php in Social Share Buttons 1.6, at classes/class-utils.php

173 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php namespace MBSocial;
2 defined('ABSPATH') or die('No direct access permitted');
3
4 use \MaxButtons\maxField as maxField;
5
6
7 class Utils
8 {
9
10 public static function imageUploader($args)
11 {
12
13 /* Standard function for Image Uploader. Standard compatible w/ MaxButtons Icon.php Image Uploader. Should be unified later.
14 */
15 $default_args = array(
16 'id' => 'icon', // id of the field
17 'hide' => false, // hide the image upload button
18 'show_image_data' => true, // show image name / title etc in interface.
19 'show_hover_link' => true, // show a link to include a hover image
20 'conditional' => false, // show this field only on conditional
21 'label' => __('Image', 'maxbuttons-pro'), // the label
22 'data' => array(), // where to find the data of the image
23 'admin' => null, // the admin object to add the fields to
24 );
25
26 $args = wp_parse_args($args, $default_args);
27
28 $admin = $args['admin'];
29
30 if (! is_object($admin))
31 {
32 return false;
33 }
34
35 $id = $args['id'];
36 $data = $args['data'];
37
38 $icon_id = isset($data[$id . '_id']) ? $data[$id . '_id'] : false;
39 $icon_url = isset($data[$id . '_url']) ? $data[$id . '_url'] : false;
40 $icon_alt = isset($data[$id . '_alt']) ? $data[$id . '_alt'] : false;
41 $icon_size = isset($data[$id . '_size']) ? $data[$id . '_size'] : false;
42
43
44 //**Icon section.
45 $iconid = new maxField('hidden');
46 $iconid->id = $id . '_id';
47 $iconid->name = $iconid->id;
48 $iconid->value = $icon_id;
49
50 $admin->addField($iconid, '', '');
51
52 $iconurl = new maxField('hidden');
53 $iconurl->id = $id . '_url';
54 $iconurl->name = $iconurl->id;
55 $iconurl->value = $icon_url;
56
57 $admin->addField($iconurl, '','');
58
59 $iconsize = new maxField('hidden');
60 $iconsize->id = $id . '_size';
61 $iconsize->name = $iconsize->id;
62 $iconsize->value = $icon_size;
63
64 $admin->addField($iconsize, '','');
65
66
67 $iconpreview = new maxField('generic');
68 $iconpreview->id = $id . '_option_preview';
69 if ($args['hide'])
70 $iconpreview->main_class = 'option hidden';
71 $iconpreview->label =$args['label'];
72 $iconpreview->name = $iconpreview->id;
73 $iconpreview->start_conditional = $args['conditional'];
74 // $iconpreview->main_class = 'option icon_preview';
75
76 $content = '';
77 $content .= '<span class="image_' . $id . '_preview the_icon_preview non-fa">';
78 if (isset($icon_url) && $icon_url != '')
79 {
80 $content .= '<img src="' . $icon_url . '">';
81 }
82 $content .= '<span class="remove_icon dashicons dashicons-dismiss" data-key="' . $id . '"></span></span>';
83
84
85
86 if ($icon_id > 0)
87 {
88 $data = get_post($icon_id);
89 $icon_title = $data->post_title;
90 $icon_alt = get_post_meta( $icon_id, '_wp_attachment_image_alt', true );
91
92 $data = wp_get_attachment_image_src($icon_id, $icon_size);
93
94 $filename = basename($data[0]);
95 $width = $data[1];
96 $height = $data[2];
97 }
98 else {
99 $filename = $icon_alt = $icon_title = '';
100 }
101
102 if ($args['show_image_data'])
103 {
104 $content .= "<span class='" . $id . "_data the_icon_data'>";
105 $content .= "<label>" . __("File Name","maxbuttons-pro") . "</label>
106 <span class='filename'>" . $filename . "</span>
107 <label>" . __("Alt","maxbuttons-pro") . "</label>
108 <span class='alt'>" . $icon_alt . "</span>
109 <label>" . __("Title","maxbuttons-pro") . "</label>
110 <span class='atttitle'>" . $icon_title . "</span>
111 </span>";
112 }
113
114 $iconpreview->content = $content;
115 $admin->addField($iconpreview, 'start', 'end');
116
117 $image_button = new maxField('generic');
118 $image_button->label = '&nbsp;';
119 $image_button->id = $id . '_image_button';
120 $image_button->name = $image_button->id;
121 $image_button->start_conditional = $args['conditional'] ;
122
123 if ($args['hide'])
124 $image_button->main_class = 'option hidden';
125
126 $image_button->content = '<input type="button" class="media_upload button" id="image_' . $id . '_button" name="image_' . $id . '_button"
127 data-uploader_title="' . __('Select an Image', 'maxbuttons-pro') . '"
128 data-uploader_button_text="' . __('Use Image', 'maxbuttons-pro') . '"
129 data-upload-id="' . $id . '"
130 value="' . __('Select...', 'maxbuttons-pro') . '" />';
131
132 $end = $args['show_hover_link'] ? '' : 'end';
133 $admin->addField($image_button, 'start', $end);
134
135 if ($args['show_hover_link'])
136 {
137 $hover_link = new maxField('generic');
138 $hover_link->id = $id . '_hover_link';
139 $hover_link->name = $hover_link->id;
140 $hover_link->content = "<p class='add_hover_image'>
141 <a href='javascript:void(0);' id='add_hover_image'>" . __("Add a different Hover Image", 'maxbuttons-pro') . "</a>
142 </p>";
143
144 $admin->addField($hover_link, '', 'end');
145 }
146
147 }
148
149
150 } // class
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172 ?>
173