PluginProbe
Social Share Buttons / 1.8
Social Share Buttons v1.8
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.8, at classes/class-utils.php

177 lines 4.9 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 $admin->addField($iconurl, '','');
57
58 $iconsize = new maxField('hidden');
59 $iconsize->id = $id . '_size';
60 $iconsize->name = $iconsize->id;
61 $iconsize->value = $icon_size;
62 $admin->addField($iconsize, '','');
63
64 $iconpreview = new maxField('generic');
65 $iconpreview->id = $id . '_option_preview';
66 if ($args['hide'])
67 $iconpreview->main_class = 'option hidden';
68 $iconpreview->label =$args['label'];
69 $iconpreview->name = $iconpreview->id;
70 $iconpreview->start_conditional = $args['conditional'];
71 // $iconpreview->main_class = 'option icon_preview';
72
73 if ($icon_id > 0)
74 {
75 $data = get_post($icon_id);
76
77 if (! is_null($data))
78 {
79 $icon_title = $data->post_title;
80 $icon_alt = get_post_meta( $icon_id, '_wp_attachment_image_alt', true );
81
82 $data = wp_get_attachment_image_src($icon_id, $icon_size);
83
84 $filename = basename($data[0]);
85 $width = $data[1];
86 $height = $data[2];
87 }
88 else {
89 $icon_id = -1; // error state
90 $icon_url = '';
91 }
92 }
93 else {
94 $filename = $icon_alt = $icon_title = '';
95 }
96
97 $content = '';
98 $content .= '<span class="image_' . $id . '_preview the_icon_preview non-fa">';
99 if (isset($icon_url) && $icon_url != '')
100 {
101 $content .= '<img src="' . $icon_url . '">';
102 }
103 $content .= '<span class="remove_icon dashicons dashicons-dismiss" data-key="' . $id . '"></span></span>';
104
105
106 if ($args['show_image_data'])
107 {
108 $content .= "<span class='" . $id . "_data the_icon_data'>";
109 $content .= "<label>" . __("File Name","maxbuttons-pro") . "</label>
110 <span class='filename'>" . $filename . "</span>
111 <label>" . __("Alt","maxbuttons-pro") . "</label>
112 <span class='alt'>" . $icon_alt . "</span>
113 <label>" . __("Title","maxbuttons-pro") . "</label>
114 <span class='atttitle'>" . $icon_title . "</span>
115 </span>";
116 }
117
118 $iconpreview->content = $content;
119 $admin->addField($iconpreview, 'start', 'end');
120
121 $image_button = new maxField('generic');
122 $image_button->label = '&nbsp;';
123 $image_button->id = $id . '_image_button';
124 $image_button->name = $image_button->id;
125 $image_button->start_conditional = $args['conditional'] ;
126
127 if ($args['hide'])
128 $image_button->main_class = 'option hidden';
129
130 $image_button->content = '<input type="button" class="media_upload button" id="image_' . $id . '_button" name="image_' . $id . '_button"
131 data-uploader_title="' . __('Select an Image', 'maxbuttons-pro') . '"
132 data-uploader_button_text="' . __('Use Image', 'maxbuttons-pro') . '"
133 data-upload-id="' . $id . '"
134 value="' . __('Select...', 'maxbuttons-pro') . '" />';
135
136 $end = $args['show_hover_link'] ? '' : 'end';
137 $admin->addField($image_button, 'start', $end);
138
139 if ($args['show_hover_link'])
140 {
141 $hover_link = new maxField('generic');
142 $hover_link->id = $id . '_hover_link';
143 $hover_link->name = $hover_link->id;
144 $hover_link->content = "<p class='add_hover_image'>
145 <a href='javascript:void(0);' id='add_hover_image'>" . __("Add a different Hover Image", 'maxbuttons-pro') . "</a>
146 </p>";
147
148 $admin->addField($hover_link, '', 'end');
149 }
150
151 }
152
153
154 } // class
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 ?>
177