Version Description
Download this release
Release Info
Developer | basszje |
Plugin | WordPress Button Plugin MaxButtons |
Version | 7.1.3 |
Comparing to | |
See all releases |
Code changes from version 7.1.2 to 7.1.3
- classes/collection-block.php +0 -217
- classes/collection.php +0 -768
- classes/collections.php +0 -514
- classes/maxbuttons-class.php +7 -49
- collections/basic-block.php +0 -192
- collections/basic-collection.php +0 -14
- collections/layout-block.php +0 -348
- collections/picker-block.php +0 -275
- collections/preview-block.php +0 -50
- collections/social-block.php +0 -728
- collections/social-collection.php +0 -227
- includes/maxbuttons-admin-helper.php +1 -30
- includes/maxbuttons-list.php +1 -20
- js/maxbuttons_media_button.js +4 -1
- js/maxcollections.js +0 -957
- js/maxmodal.js +7 -1
- js/min/maxbuttons_media_button.js +1 -1
- js/min/maxcollections.js +0 -1
- js/min/maxmodal.js +1 -1
- maxbuttons.php +3 -7
- readme.txt +9 -1
classes/collection-block.php
DELETED
@@ -1,217 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace maxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
|
5 |
-
abstract class collectionBlock
|
6 |
-
{
|
7 |
-
protected $data = array();
|
8 |
-
protected $collection = null;
|
9 |
-
protected $fields = array();
|
10 |
-
protected $fielddata = array();
|
11 |
-
protected $blockname;
|
12 |
-
protected $is_preview = false;
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
function setCollection($collection)
|
17 |
-
{
|
18 |
-
$this->collection = $collection;
|
19 |
-
}
|
20 |
-
|
21 |
-
function set($data)
|
22 |
-
{
|
23 |
-
//$blockname = $this->blockname;
|
24 |
-
|
25 |
-
if (! isset($data[$this->blockname]))
|
26 |
-
$blockdata = array();
|
27 |
-
else
|
28 |
-
$blockdata = $data[$this->blockname];
|
29 |
-
|
30 |
-
|
31 |
-
foreach($this->fields as $field => $options)
|
32 |
-
{
|
33 |
-
if ($field == 'multifields') // multifields can't set default since amount is unknown
|
34 |
-
{
|
35 |
-
$mf_id = $options["id"];
|
36 |
-
$mf_fields = $options["fields"];
|
37 |
-
if (isset($blockdata[$mf_id]))
|
38 |
-
{
|
39 |
-
$this->data[$mf_id] = $blockdata[$mf_id]; // why not.
|
40 |
-
}
|
41 |
-
}
|
42 |
-
else
|
43 |
-
{
|
44 |
-
if (isset($blockdata[$field]))
|
45 |
-
$this->data[$field] = $blockdata[$field];
|
46 |
-
elseif (isset($options["default"]))
|
47 |
-
$this->data[$field] = $options["default"];
|
48 |
-
}
|
49 |
-
}
|
50 |
-
|
51 |
-
return true;
|
52 |
-
|
53 |
-
}
|
54 |
-
|
55 |
-
// get the block data
|
56 |
-
function get()
|
57 |
-
{
|
58 |
-
return $this->data;
|
59 |
-
|
60 |
-
}
|
61 |
-
|
62 |
-
function setPreview($preview = true)
|
63 |
-
{
|
64 |
-
$this->is_preview = $preview;
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
-
/* Save fields on a per block data
|
69 |
-
|
70 |
-
Post data is sent unfiltered so sanitization must be done here!
|
71 |
-
*/
|
72 |
-
function save_fields($data, $post)
|
73 |
-
{
|
74 |
-
$blockdata = array();
|
75 |
-
|
76 |
-
//if (isset($this->data[$this->blockname]))
|
77 |
-
$blockdata = $this->data;
|
78 |
-
|
79 |
-
foreach($this->fields as $field => $options)
|
80 |
-
{
|
81 |
-
|
82 |
-
if ($field == "multifields") // standardize multi fields
|
83 |
-
{
|
84 |
-
$mf_id = $options["id"];
|
85 |
-
$mf_fields = $options["fields"];
|
86 |
-
|
87 |
-
$multidata = array();
|
88 |
-
|
89 |
-
if (isset($post[$mf_id])) // the collection with the id's.
|
90 |
-
{
|
91 |
-
$i = 0; // id's might be duplicate i.e. two similar buttons.
|
92 |
-
foreach ($post[$mf_id] as $id) // id is button-id
|
93 |
-
{
|
94 |
-
|
95 |
-
foreach($mf_fields as $mf_field => $options)
|
96 |
-
{
|
97 |
-
$default = (isset($options["default"])) ? $options["default"] : '';
|
98 |
-
// POST[ field_name - $id ]
|
99 |
-
//
|
100 |
-
$multidata[$i][$id][$mf_field] = isset($post[$mf_field . "-" . $id . "-" . $i ]) ? $post[$mf_field . "-" . $id . "-" . $i] : $default;
|
101 |
-
}
|
102 |
-
$i++;
|
103 |
-
}
|
104 |
-
}
|
105 |
-
$blockdata[$mf_id] = $multidata;
|
106 |
-
}
|
107 |
-
else
|
108 |
-
{
|
109 |
-
$default = (isset($options["default"])) ? $options["default"] : '';
|
110 |
-
// stripslashes since the WP post var adds them.
|
111 |
-
$blockdata[$field] = (isset($post[$field])) ? stripslashes(sanitize_text_field($post[$field])) : $default;
|
112 |
-
}
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
-
$data[$this->blockname] = $blockdata;
|
117 |
-
return $data;
|
118 |
-
|
119 |
-
}
|
120 |
-
|
121 |
-
function parse($domObj, $args)
|
122 |
-
{
|
123 |
-
|
124 |
-
return $domObj; // nothing to do by default
|
125 |
-
}
|
126 |
-
|
127 |
-
function parseButtons($buttons)
|
128 |
-
{
|
129 |
-
return $buttons;
|
130 |
-
}
|
131 |
-
|
132 |
-
// Adepted from block class - maxbuttons
|
133 |
-
function parseCSS($css, $args)
|
134 |
-
{
|
135 |
-
$data = $this->data;
|
136 |
-
|
137 |
-
// get all fields from this block
|
138 |
-
foreach($this->fields as $field => $field_data)
|
139 |
-
{
|
140 |
-
// get cssparts, can be comma-seperated value
|
141 |
-
$csspart = (isset($field_data["csspart"])) ? explode(",",$field_data["csspart"]) : array('maxbutton');
|
142 |
-
$csspseudo = (isset($field_data["csspseudo"])) ? explode(",", $field_data["csspseudo"]) : 'normal';
|
143 |
-
|
144 |
-
// if this field has a css property
|
145 |
-
if (isset($field_data["css"]))
|
146 |
-
{
|
147 |
-
// get the property value from the data
|
148 |
-
$value = isset($data[$field]) ? $data[$field] : '';
|
149 |
-
$value = str_replace(array(";"), '', $value); //sanitize
|
150 |
-
|
151 |
-
if ( strpos($field_data["default"],"px") && ! strpos($value,"px"))
|
152 |
-
{
|
153 |
-
if ($value == '') $value = 0; // pixel values, no empty but 0
|
154 |
-
$value .= "px";
|
155 |
-
}
|
156 |
-
if (isset($data[$field]))
|
157 |
-
{
|
158 |
-
foreach($csspart as $part)
|
159 |
-
{
|
160 |
-
if (is_array($csspseudo))
|
161 |
-
{
|
162 |
-
foreach($csspseudo as $pseudo)
|
163 |
-
$css[$part][$pseudo][$field_data["css"]] = $value ;
|
164 |
-
}
|
165 |
-
else
|
166 |
-
$css[$part][$csspseudo][$field_data["css"]] = $value ;
|
167 |
-
}
|
168 |
-
}
|
169 |
-
}
|
170 |
-
|
171 |
-
}
|
172 |
-
|
173 |
-
return $css;
|
174 |
-
}
|
175 |
-
|
176 |
-
// default function
|
177 |
-
function parseJS($js)
|
178 |
-
{
|
179 |
-
return $js;
|
180 |
-
}
|
181 |
-
|
182 |
-
// for the preview
|
183 |
-
public function map_fields($map)
|
184 |
-
{
|
185 |
-
foreach($this->fields as $field => $field_data)
|
186 |
-
{
|
187 |
-
if (isset($field_data["css"]))
|
188 |
-
{
|
189 |
-
$cssdef = $field_data["css"];
|
190 |
-
$multidef = explode('-',$cssdef);
|
191 |
-
if ( count($multidef) > 1)
|
192 |
-
{
|
193 |
-
$cssdef = "";
|
194 |
-
for($i = 0; $i < count($multidef); $i++)
|
195 |
-
{
|
196 |
-
if ($i == 0)
|
197 |
-
$cssdef .= $multidef[$i];
|
198 |
-
else
|
199 |
-
$cssdef .= ucfirst($multidef[$i]);
|
200 |
-
//$multidef[$i] . ucfirst($multidef[1]);
|
201 |
-
}
|
202 |
-
}
|
203 |
-
$map[$field]["css"] = $cssdef;
|
204 |
-
if ( isset($field_data["default"]) && strpos($field_data["default"],"px") != false )
|
205 |
-
$map[$field]["css_unit"] = 'px';
|
206 |
-
|
207 |
-
}
|
208 |
-
if (isset($field_data["csspart"]))
|
209 |
-
$map[$field]["csspart"] = $field_data["csspart"];
|
210 |
-
}
|
211 |
-
return $map;
|
212 |
-
|
213 |
-
}
|
214 |
-
|
215 |
-
abstract function admin_fields();
|
216 |
-
|
217 |
-
} // class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/collection.php
DELETED
@@ -1,768 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
|
5 |
-
use \simple_html_dom as simple_html_dom;
|
6 |
-
|
7 |
-
class maxCollection
|
8 |
-
{
|
9 |
-
protected $collection_type = 'none';
|
10 |
-
protected $uses_blocks = array();
|
11 |
-
protected $blocks = array(); // array of objects
|
12 |
-
|
13 |
-
protected $collection_id = 0;
|
14 |
-
|
15 |
-
// layout functions
|
16 |
-
protected $cssParser;
|
17 |
-
protected $collection_js;
|
18 |
-
|
19 |
-
// derived from button class, prepare for maxcss parser
|
20 |
-
//protected $collection_css = array('normal' => array() ,':hover' => array() ,':visited' => array(), "responsive" => array());
|
21 |
-
protected $buttons = array(); // array of buttons, ready for display - pre parse
|
22 |
-
|
23 |
-
|
24 |
-
/* Constructor
|
25 |
-
Sets the blocks used in this collection. These are mostly derived from subclasses of the specific collection types.
|
26 |
-
*/
|
27 |
-
public function __construct()
|
28 |
-
{
|
29 |
-
maxCollections::checkExpireTrans();
|
30 |
-
|
31 |
-
foreach($this->uses_blocks as $block_name )
|
32 |
-
{
|
33 |
-
$block = maxCollections::getBlock($block_name);
|
34 |
-
if ($block)
|
35 |
-
{
|
36 |
-
$block->setCollection($this);
|
37 |
-
$block->set(array()); // defaults
|
38 |
-
$this->blocks[$block_name] = $block;
|
39 |
-
}
|
40 |
-
}
|
41 |
-
|
42 |
-
|
43 |
-
}
|
44 |
-
/* Get all buttons that are currently loaded */
|
45 |
-
public function getLoadedButtons()
|
46 |
-
{
|
47 |
-
return $this->buttons;
|
48 |
-
}
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
/* Get a certain block class by name */
|
53 |
-
public function getBlock($blockname)
|
54 |
-
{
|
55 |
-
|
56 |
-
if (isset($this->blocks[$blockname]))
|
57 |
-
return $this->blocks[$blockname];
|
58 |
-
else
|
59 |
-
return false;
|
60 |
-
}
|
61 |
-
|
62 |
-
/* Get the type of the collection */
|
63 |
-
public function getType()
|
64 |
-
{
|
65 |
-
return $this->collection_type;
|
66 |
-
}
|
67 |
-
|
68 |
-
/* Get the ID of the collection */
|
69 |
-
public function getID()
|
70 |
-
{
|
71 |
-
return $this->collection_id;
|
72 |
-
}
|
73 |
-
|
74 |
-
/** Get the MaxCSSParser classes which handles SCSS. This function is derived from the one in Button class */
|
75 |
-
public function getCSSParser()
|
76 |
-
{
|
77 |
-
if (! $this->cssParser)
|
78 |
-
$this->cssParser = new maxCSSParser();
|
79 |
-
|
80 |
-
return $this->cssParser;
|
81 |
-
}
|
82 |
-
|
83 |
-
/** Set the collection by ID
|
84 |
-
@param $collection_id ID of the collection stored in database
|
85 |
-
*/
|
86 |
-
public function set($collection_id)
|
87 |
-
{
|
88 |
-
$this->collection_id = $collection_id;
|
89 |
-
|
90 |
-
// make every block set it's stuff.
|
91 |
-
$values = $this->get_meta($collection_id);
|
92 |
-
|
93 |
-
foreach($this->blocks as $block)
|
94 |
-
{
|
95 |
-
|
96 |
-
$block->set($values);
|
97 |
-
// run every blocks setter
|
98 |
-
|
99 |
-
}
|
100 |
-
}
|
101 |
-
|
102 |
-
|
103 |
-
/** Interface for handling AJAX requests to communicate with the seperate blocks.
|
104 |
-
@param $result The initial (default) result to JSON back
|
105 |
-
@param $block_name The name of the block in question
|
106 |
-
@param $action The name of the block function to call
|
107 |
-
@param $data Data specified by JS to use for this function
|
108 |
-
@return $result - Standardized result block including error, body
|
109 |
-
*/
|
110 |
-
public function doBlockAJAX($result, $block_name, $action, $data)
|
111 |
-
{
|
112 |
-
// core class is being called.
|
113 |
-
if ($block_name == 'collection')
|
114 |
-
{
|
115 |
-
$result = $this->$action($result, $data);
|
116 |
-
return $result;
|
117 |
-
}
|
118 |
-
|
119 |
-
if (isset($this->blocks[$block_name]))
|
120 |
-
{
|
121 |
-
$block= $this->blocks[$block_name];
|
122 |
-
$result = $block->$action($result, $data);
|
123 |
-
return $result;
|
124 |
-
|
125 |
-
}
|
126 |
-
|
127 |
-
$result["error"] = true;
|
128 |
-
$result["title"] = __("Error : Block was not there","maxbuttons");
|
129 |
-
return $result;
|
130 |
-
}
|
131 |
-
|
132 |
-
/** Save the collection data to the database. This will invoke the save functions of the blocks itself to gather, verify and manipulate data */
|
133 |
-
public function save($post)
|
134 |
-
{
|
135 |
-
$data = array();
|
136 |
-
|
137 |
-
// Collection id needed to save meta data and others.
|
138 |
-
if ($this->collection_id == 0) // assume new
|
139 |
-
{
|
140 |
-
$collection_id = $this->getNewCollectionID();
|
141 |
-
|
142 |
-
$this->collection_id = $collection_id;
|
143 |
-
}
|
144 |
-
|
145 |
-
// run this by each block and collect data
|
146 |
-
foreach($this->blocks as $block)
|
147 |
-
{
|
148 |
-
$data = $block->save_fields($data, $post);
|
149 |
-
}
|
150 |
-
|
151 |
-
$data = apply_filters("mb_col_save_collection_data", $data, $post);
|
152 |
-
|
153 |
-
// clean what was not set
|
154 |
-
$this->clean_meta($data);
|
155 |
-
|
156 |
-
// write data as a per block per key value into the database
|
157 |
-
foreach($data as $blockname => $blockdata)
|
158 |
-
{
|
159 |
-
// seems dangerous
|
160 |
-
$meta_id = $this->update_meta($this->collection_id, $blockname, $blockdata);
|
161 |
-
|
162 |
-
}
|
163 |
-
|
164 |
-
return $this->collection_id;
|
165 |
-
|
166 |
-
}
|
167 |
-
|
168 |
-
// remove post meta not in data post.
|
169 |
-
public function clean_meta($data)
|
170 |
-
{
|
171 |
-
$data_blocks = array_keys($data);
|
172 |
-
|
173 |
-
|
174 |
-
$meta = $this->get_meta($this->collection_id);
|
175 |
-
|
176 |
-
|
177 |
-
foreach($meta as $meta_key => $values)
|
178 |
-
{
|
179 |
-
if (! in_array($meta_key, $data_blocks))
|
180 |
-
{
|
181 |
-
$this->delete_meta($this->collection_id, $meta_key);
|
182 |
-
}
|
183 |
-
|
184 |
-
}
|
185 |
-
|
186 |
-
}
|
187 |
-
|
188 |
-
protected function update_meta($collection_id, $collection_key, $collection_value)
|
189 |
-
{
|
190 |
-
global $wpdb;
|
191 |
-
$table = maxUtils::get_collection_table_name();
|
192 |
-
|
193 |
-
if ($collection_value == '') return; // no data no database entry
|
194 |
-
if (is_array($collection_value) && count($collection_value) == 0) return; // same for empty arrays
|
195 |
-
|
196 |
-
if (is_array($collection_value))
|
197 |
-
$collection_value = json_encode($collection_value);
|
198 |
-
|
199 |
-
if ($collection_id == 0) // assume new
|
200 |
-
{
|
201 |
-
$collection_id = $this->getNewCollectionID();
|
202 |
-
|
203 |
-
$this->collection_id = $collection_id;
|
204 |
-
}
|
205 |
-
|
206 |
-
$sql = "SELECT meta_id from $table where collection_id = %d and collection_key = %s ";
|
207 |
-
$sql = $wpdb->prepare($sql, $collection_id, $collection_key);
|
208 |
-
|
209 |
-
$results = $wpdb->get_results($sql, ARRAY_A);
|
210 |
-
|
211 |
-
if (count($results) == 1)
|
212 |
-
{
|
213 |
-
$meta_id = $results[0]["meta_id"];
|
214 |
-
$data = array("collection_value" => $collection_value); // what's being updated
|
215 |
-
$where = array("meta_id" => $meta_id);
|
216 |
-
|
217 |
-
$wpdb->update($table, $data, $where);
|
218 |
-
return $meta_id;
|
219 |
-
}
|
220 |
-
if (count($results) == 0)
|
221 |
-
{
|
222 |
-
$data = array("collection_value" => $collection_value,
|
223 |
-
"collection_key" => $collection_key,
|
224 |
-
"collection_id" => $collection_id,
|
225 |
-
);
|
226 |
-
|
227 |
-
$meta_id = $wpdb->insert($table, $data);
|
228 |
-
|
229 |
-
return $meta_id;
|
230 |
-
}
|
231 |
-
else
|
232 |
-
{
|
233 |
-
MB()->add_notice("error", __("Update Collection meta has multiple rows, this should not be possible.","maxbuttons"));
|
234 |
-
|
235 |
-
}
|
236 |
-
}
|
237 |
-
|
238 |
-
|
239 |
-
/** Determine the next ID for collection */
|
240 |
-
protected function getNewCollectionID()
|
241 |
-
{
|
242 |
-
global $wpdb;
|
243 |
-
$table = maxUtils::get_collection_table_name();
|
244 |
-
|
245 |
-
$sql = "SELECT max(collection_id) as max from $table";
|
246 |
-
|
247 |
-
$max = intval($wpdb->get_var($sql));
|
248 |
-
|
249 |
-
$max = $max + 1;
|
250 |
-
return $max;
|
251 |
-
}
|
252 |
-
|
253 |
-
protected function delete_meta($collection_id, $collection_key)
|
254 |
-
{
|
255 |
-
if (intval($collection_id) > 0 && $collection_key != "")
|
256 |
-
{
|
257 |
-
global $wpdb;
|
258 |
-
// delete_post_meta($collection_id, $collection_key);
|
259 |
-
$table = maxUtils::get_collection_table_name();
|
260 |
-
$where = array("collection_id" => $collection_id,
|
261 |
-
"collection_key" => $collection_key
|
262 |
-
);
|
263 |
-
$where_format = array("%d", "%s");
|
264 |
-
$wpdb->delete($table, $where, $format);
|
265 |
-
|
266 |
-
}
|
267 |
-
}
|
268 |
-
|
269 |
-
|
270 |
-
/** Delete the collection. This is done via AJAX request */
|
271 |
-
public function delete($result, $data)
|
272 |
-
{
|
273 |
-
global $wpdb;
|
274 |
-
if(! $this->collection_id > 0)
|
275 |
-
return false;
|
276 |
-
|
277 |
-
$picker = $this->getBlock("picker");
|
278 |
-
$picker_data = $picker->get();
|
279 |
-
$buttons = $picker_data["selection"];
|
280 |
-
$button = MB()->getClass("button");
|
281 |
-
|
282 |
-
$buttons_removed = 0;
|
283 |
-
|
284 |
-
foreach($buttons as $button_id)
|
285 |
-
{
|
286 |
-
$deleted = $this->maybe_delete_button($button_id);
|
287 |
-
if ($deleted)
|
288 |
-
$buttons_removed++;
|
289 |
-
|
290 |
-
}
|
291 |
-
|
292 |
-
$table = maxUtils::get_collection_table_name();
|
293 |
-
$where = array("collection_id" => $this->collection_id);
|
294 |
-
$where_format = array("%d");
|
295 |
-
$wpdb->delete($table, $where, $where_format);
|
296 |
-
|
297 |
-
$result["data"]["body"] = __("The collection is removed","maxbuttons");
|
298 |
-
$result["data"]["title"] = __("Removed","maxbuttons");
|
299 |
-
$result["data"]["buttons_removed"] = $buttons_removed;
|
300 |
-
$result["data"]["collection_id"] = $this->collection_id;
|
301 |
-
return $result;
|
302 |
-
|
303 |
-
|
304 |
-
}
|
305 |
-
|
306 |
-
/** On deletion of a collection check for each button if this is an auto-generated button just made for this collection and if
|
307 |
-
no changes where made to this button. If both conditions are true, remove the button */
|
308 |
-
function maybe_delete_button($button_id)
|
309 |
-
{
|
310 |
-
$button = MB()->getClass("button");
|
311 |
-
|
312 |
-
$button->set($button_id);
|
313 |
-
$button_data = $button->get();
|
314 |
-
|
315 |
-
$collection_id= $this->collection_id;
|
316 |
-
|
317 |
-
// remove unedited buttons created for this collection - use with care.
|
318 |
-
if (isset($button_data["meta"]["user_edited"]))
|
319 |
-
{
|
320 |
-
$created_source = (isset($button_data["meta"]["created_source"])) ? $button_data["meta"]["created_source"] : '';
|
321 |
-
if ($button_data["meta"]["user_edited"] === false && $created_source == 'collection')
|
322 |
-
{
|
323 |
-
$in_collections = $button_data["meta"]["in_collections"];
|
324 |
-
|
325 |
-
$key = array_search($collection_id, $in_collections);
|
326 |
-
|
327 |
-
if ($key !== false)
|
328 |
-
{
|
329 |
-
unset($button_data["meta"]["in_collections"][$key]);
|
330 |
-
|
331 |
-
if (count($button_data["meta"]["in_collections"]) == 0)
|
332 |
-
{ $button->delete($button_id);
|
333 |
-
return true;
|
334 |
-
}
|
335 |
-
else
|
336 |
-
{
|
337 |
-
if ($button_id > 0) // safety.
|
338 |
-
$button->update($button_data);
|
339 |
-
}
|
340 |
-
}
|
341 |
-
}
|
342 |
-
|
343 |
-
|
344 |
-
}
|
345 |
-
return false;
|
346 |
-
}
|
347 |
-
|
348 |
-
function get_meta ($collection_id, $collection_key = '')
|
349 |
-
{
|
350 |
-
global $wpdb;
|
351 |
-
$table = maxUtils::get_collection_table_name();
|
352 |
-
|
353 |
-
$prepare = array($collection_id);
|
354 |
-
|
355 |
-
$sql = "SELECT * from $table where collection_id = %d ";
|
356 |
-
if ($collection_key != '')
|
357 |
-
{
|
358 |
-
$sql .= " and collection_key = %s ";
|
359 |
-
array_push($prepare, $collection_key);
|
360 |
-
|
361 |
-
}
|
362 |
-
|
363 |
-
$sql = $wpdb->prepare($sql, $prepare);
|
364 |
-
|
365 |
-
$results = $wpdb->get_results($sql, ARRAY_A);
|
366 |
-
|
367 |
-
$result_array = array(); // format array by field name = values to feed blocks and others.
|
368 |
-
if (! is_null($results))
|
369 |
-
{
|
370 |
-
$nr = array();
|
371 |
-
foreach($results as $row)
|
372 |
-
{
|
373 |
-
$key = $row["collection_key"];
|
374 |
-
/* A field can be either plain text or JSON */
|
375 |
-
if(json_decode($row["collection_value"]))
|
376 |
-
$value = json_decode($row["collection_value"], true);
|
377 |
-
else
|
378 |
-
$value = $row["collection_value"];
|
379 |
-
$result_array[$key] = $value;
|
380 |
-
|
381 |
-
//$row["collection_value"] = unserialize($row["collection_value"]);
|
382 |
-
}
|
383 |
-
|
384 |
-
return $result_array;
|
385 |
-
}
|
386 |
-
else
|
387 |
-
{
|
388 |
-
return false;
|
389 |
-
}
|
390 |
-
}
|
391 |
-
|
392 |
-
function display($args = array())
|
393 |
-
{
|
394 |
-
maxUtils::startTime('collection-display');
|
395 |
-
$defaults = array(
|
396 |
-
"preview" => false,
|
397 |
-
"echo" => true,
|
398 |
-
"style_tag" => false,
|
399 |
-
"compile" => false,
|
400 |
-
"js_tag" => true,
|
401 |
-
"load_type" => "footer",
|
402 |
-
);
|
403 |
-
|
404 |
-
$args = wp_parse_args($args, $defaults);
|
405 |
-
|
406 |
-
$cache = MaxCollections::checkCachedCollection($this->collection_id);
|
407 |
-
|
408 |
-
if (! $cache)
|
409 |
-
{
|
410 |
-
$cssParser = $this->getCSSParser();
|
411 |
-
$domObj = $this->parse($args);
|
412 |
-
$css = $this->parseCSS($args);
|
413 |
-
|
414 |
-
$js = $this->parseJS($args);
|
415 |
-
|
416 |
-
$output = $domObj->save();
|
417 |
-
unset($domObj);
|
418 |
-
|
419 |
-
|
420 |
-
// CSS & JS output control
|
421 |
-
$output .= $this->displayCSS($css, $args);
|
422 |
-
$output .= $this->displayJS($js, $args);
|
423 |
-
}
|
424 |
-
else
|
425 |
-
$output = $cache;
|
426 |
-
|
427 |
-
MaxCollections::addCachedCollection($this->collection_id, $output);
|
428 |
-
|
429 |
-
maxUtils::endTime('collection-display');
|
430 |
-
|
431 |
-
if ($args["echo"])
|
432 |
-
{
|
433 |
-
echo $output;
|
434 |
-
}
|
435 |
-
else
|
436 |
-
{
|
437 |
-
return $output;
|
438 |
-
}
|
439 |
-
|
440 |
-
}
|
441 |
-
|
442 |
-
public function displayCSS($css, $args = array() ) // $echo = true, $style_tag = true)
|
443 |
-
{
|
444 |
-
|
445 |
-
$default = array(
|
446 |
-
"echo" => true,
|
447 |
-
"style_tag" => true,
|
448 |
-
"load_type" => "footer",
|
449 |
-
);
|
450 |
-
$args = wp_parse_args($args, $default);
|
451 |
-
if ($args['load_type'] == 'inline')
|
452 |
-
$args['style_tag'] =true;
|
453 |
-
|
454 |
-
$output = '';
|
455 |
-
|
456 |
-
if ($args["style_tag"])
|
457 |
-
$output .= "<style type='text/css'>";
|
458 |
-
|
459 |
-
$output .= $css;
|
460 |
-
|
461 |
-
if ($args["style_tag"])
|
462 |
-
$output .= "</style>";
|
463 |
-
|
464 |
-
|
465 |
-
if ($args["load_type"] == 'footer')
|
466 |
-
{
|
467 |
-
|
468 |
-
do_action('mb-footer','collection-' . $this->collection_id, $output);
|
469 |
-
}
|
470 |
-
elseif ($args["load_type"] == 'inline')
|
471 |
-
{
|
472 |
-
if ($args["echo"]) echo $output;
|
473 |
-
else return $output;
|
474 |
-
|
475 |
-
}
|
476 |
-
|
477 |
-
}
|
478 |
-
|
479 |
-
public function displayJS($js, $args = array() ) // $echo = true, $style_tag = true)
|
480 |
-
{
|
481 |
-
$default = array(
|
482 |
-
"echo" => true,
|
483 |
-
"js_tag" => true,
|
484 |
-
"load_type" => "footer",
|
485 |
-
"preview" => false,
|
486 |
-
);
|
487 |
-
|
488 |
-
|
489 |
-
$args = wp_parse_args($args, $default);
|
490 |
-
|
491 |
-
if ($args["preview"])
|
492 |
-
return; // no js on previews.
|
493 |
-
|
494 |
-
$output = '';
|
495 |
-
|
496 |
-
if (count($js) == 0)
|
497 |
-
return; // no output, holiday
|
498 |
-
|
499 |
-
if ($args["js_tag"])
|
500 |
-
{
|
501 |
-
$output .= "<script type='text/javascript'> ";
|
502 |
-
|
503 |
-
}
|
504 |
-
|
505 |
-
foreach($js as $index => $code)
|
506 |
-
{
|
507 |
-
$output .= $code;
|
508 |
-
}
|
509 |
-
|
510 |
-
if ($args["js_tag"])
|
511 |
-
{
|
512 |
-
$output .= " // }
|
513 |
-
// }
|
514 |
-
// window.onload = MBcollection" . $this->collection_id . "();
|
515 |
-
</script> ";
|
516 |
-
}
|
517 |
-
|
518 |
-
|
519 |
-
if ($args["load_type"] == 'footer')
|
520 |
-
{
|
521 |
-
|
522 |
-
do_action('mb-footer','collection-' . $this->collection_id, $output, "js");
|
523 |
-
}
|
524 |
-
elseif ($args["load_type"] == 'inline')
|
525 |
-
{
|
526 |
-
if ($args["echo"]) echo $output;
|
527 |
-
else return $output;
|
528 |
-
|
529 |
-
}
|
530 |
-
}
|
531 |
-
|
532 |
-
public function display_field_map()
|
533 |
-
{
|
534 |
-
$map = array();
|
535 |
-
foreach ($this->blocks as $block)
|
536 |
-
{
|
537 |
-
$map = $block->map_fields($map);
|
538 |
-
}
|
539 |
-
echo "<script language='javascript'>";
|
540 |
-
echo "var collectionFieldMap = '" . json_encode($map) . "';" ;
|
541 |
-
echo "</script>";
|
542 |
-
}
|
543 |
-
|
544 |
-
/* Parses the collection, via the blocks */
|
545 |
-
function parse($args)
|
546 |
-
{
|
547 |
-
$preview = isset($args["preview"]) ? $args["preview"] : false;
|
548 |
-
|
549 |
-
$domObj = new simple_html_dom();
|
550 |
-
$collection_id = $this->collection_id;
|
551 |
-
|
552 |
-
$node = "<div class='maxcollection maxcollection-" . $collection_id . "' data-collection='" . $collection_id . "'>
|
553 |
-
</div>";
|
554 |
-
$node = apply_filters("mb-col-basic-container",$node);
|
555 |
-
$domObj->load($node);
|
556 |
-
|
557 |
-
// use picker to get button classes in array
|
558 |
-
$picker = $this->getBlock("picker");
|
559 |
-
$this->buttons = $picker->getButtons();
|
560 |
-
|
561 |
-
// changes to buttons in this function
|
562 |
-
maxUtils::startTime('collection-parse-parsebuttons');
|
563 |
-
foreach($this->blocks as $block)
|
564 |
-
{
|
565 |
-
$block->setPreview($preview);
|
566 |
-
$this->buttons = $block->parseButtons($this->buttons);
|
567 |
-
|
568 |
-
|
569 |
-
}
|
570 |
-
maxUtils::endTime('collection-parse-parsebuttons');
|
571 |
-
|
572 |
-
maxUtils::startTime('collection-parse-blockparse');
|
573 |
-
// general parsing
|
574 |
-
|
575 |
-
foreach($this->blocks as $block)
|
576 |
-
{
|
577 |
-
$domObj = $block->parse($domObj, $args);
|
578 |
-
}
|
579 |
-
maxUtils::endTime('collection-parse-blockparse');
|
580 |
-
|
581 |
-
$this->buttons = array();
|
582 |
-
|
583 |
-
$cssParser = $this->getCSSParser();
|
584 |
-
$domObj->load($domObj->save() );
|
585 |
-
$cssParser->loadDom($domObj);
|
586 |
-
|
587 |
-
return $domObj;
|
588 |
-
}
|
589 |
-
function parseCSS($args)
|
590 |
-
{
|
591 |
-
$css = array();
|
592 |
-
|
593 |
-
foreach($this->blocks as $block)
|
594 |
-
{
|
595 |
-
$css = $block->parseCSS($css, $args);
|
596 |
-
}
|
597 |
-
|
598 |
-
$css = $this->getCSSParser()->parse($css);
|
599 |
-
|
600 |
-
return $css;
|
601 |
-
}
|
602 |
-
|
603 |
-
function parseJS($args)
|
604 |
-
{
|
605 |
-
$js = array();
|
606 |
-
|
607 |
-
$defaults = array("preview" => false,
|
608 |
-
);
|
609 |
-
|
610 |
-
$args = wp_parse_args($args, $defaults);
|
611 |
-
|
612 |
-
if ($args["preview"])
|
613 |
-
return false; // no js on previews
|
614 |
-
|
615 |
-
foreach($this->blocks as $block)
|
616 |
-
{
|
617 |
-
$js = $block->parseJS($js, $args);
|
618 |
-
|
619 |
-
}
|
620 |
-
|
621 |
-
return $js;
|
622 |
-
}
|
623 |
-
|
624 |
-
|
625 |
-
function shortcode($atts, $content = null)
|
626 |
-
{
|
627 |
-
|
628 |
-
// ugly -need to rework logic here.
|
629 |
-
//$collection = maxCollections::getCollection('social');
|
630 |
-
$display_args = shortcode_atts(array(
|
631 |
-
"echo" => false,
|
632 |
-
"mode" => "normal",
|
633 |
-
"nocache" => false,
|
634 |
-
"style" => 'footer',
|
635 |
-
),
|
636 |
-
|
637 |
-
$atts);
|
638 |
-
|
639 |
-
$collection_id = $this->collection_id;
|
640 |
-
|
641 |
-
//$this->set($collection_id);
|
642 |
-
$display_args["compile"] = $display_args["nocache"];
|
643 |
-
$display_args['load_type'] = $display_args['style'];
|
644 |
-
unset($display_args['style']);
|
645 |
-
unset($display_args["nocache"]);
|
646 |
-
|
647 |
-
$output = $this->display($display_args);
|
648 |
-
|
649 |
-
return $output;
|
650 |
-
}
|
651 |
-
|
652 |
-
|
653 |
-
// Get the pack definition that are present in the system.
|
654 |
-
function editor_getPacks()
|
655 |
-
{
|
656 |
-
//$pack_paths = apply_filters('mb-col-pack-paths', array(MB()->get_plugin_path() . "/") );
|
657 |
-
$packs["maxbuttons"]["func"] = array($this, 'editor_getButtons');
|
658 |
-
$packs["maxbuttons"]["tab"] = __("Your MaxButtons","maxbuttons");
|
659 |
-
return $packs;
|
660 |
-
|
661 |
-
}
|
662 |
-
|
663 |
-
public function ajax_getButtons($result, $data)
|
664 |
-
{
|
665 |
-
$packs = $this->editor_getPacks();
|
666 |
-
$req_pack= $data["pack"];
|
667 |
-
|
668 |
-
foreach($packs as $index => $pack_data)
|
669 |
-
{
|
670 |
-
if ($req_pack == $index)
|
671 |
-
{
|
672 |
-
$buttons = call_user_func($pack_data["func"], $index, $data);
|
673 |
-
|
674 |
-
}
|
675 |
-
}
|
676 |
-
$output = '';
|
677 |
-
|
678 |
-
|
679 |
-
$page_args = array();
|
680 |
-
if (isset($data["paged"]))
|
681 |
-
{
|
682 |
-
$page_args["paged"] = $data["paged"];
|
683 |
-
}
|
684 |
-
|
685 |
-
if ($req_pack == 'maxbuttons')
|
686 |
-
{
|
687 |
-
$page_args["limit"] = 18;
|
688 |
-
ob_start();
|
689 |
-
do_action("mb-display-meta");
|
690 |
-
do_action("mb-display-pagination", $page_args);
|
691 |
-
$pagination = "<div class='tablenav top'>" .ob_get_contents() . "</div>";
|
692 |
-
ob_end_clean();
|
693 |
-
|
694 |
-
$output .= $pagination;
|
695 |
-
}
|
696 |
-
|
697 |
-
foreach($buttons as $button)
|
698 |
-
{
|
699 |
-
$button_data = $button->get();
|
700 |
-
|
701 |
-
$button_id = $button->getID();
|
702 |
-
$name = $button->getName();
|
703 |
-
|
704 |
-
$meta = isset($button_data["meta"]) ? $button_data["meta"] : array();
|
705 |
-
//do_action('mb-data-load',$button_data); // weakness of the bubbling filter model
|
706 |
-
|
707 |
-
$output .= "<div class='item shortcode-container' data-id='$button_id'> ";
|
708 |
-
$output .= $button->display(array("mode" => "preview", 'echo' => false, 'load_css' => 'inline') ); //"mode" => "preview", "compile" => true,
|
709 |
-
$output .= "<span class='button_data'>" . base64_encode(json_encode($button_data)) . "</span>";
|
710 |
-
$output .= "<span class='button_name'>" . $name . "</span>";
|
711 |
-
$output .= "</div>";
|
712 |
-
|
713 |
-
}
|
714 |
-
|
715 |
-
if ($req_pack == 'maxbuttons')
|
716 |
-
{
|
717 |
-
$output .= $pagination;
|
718 |
-
}
|
719 |
-
|
720 |
-
$result["body"] = $output;
|
721 |
-
return $result;
|
722 |
-
|
723 |
-
}
|
724 |
-
|
725 |
-
// show the available buttons
|
726 |
-
function editor_getButtons($pack, $data)
|
727 |
-
{
|
728 |
-
$button_array = array();
|
729 |
-
|
730 |
-
$admin = MB()->getClass("admin");
|
731 |
-
$button = MB()->getClass("button");
|
732 |
-
|
733 |
-
$paged = (isset($data["paged"])) ? $data["paged"] : 1;
|
734 |
-
|
735 |
-
$buttons = $admin->getButtons(array(
|
736 |
-
"orderby" => "id",
|
737 |
-
"order" => "DESC",
|
738 |
-
"paged" => $paged,
|
739 |
-
"limit" => 18,
|
740 |
-
));
|
741 |
-
|
742 |
-
|
743 |
-
foreach($buttons as $btn)
|
744 |
-
{
|
745 |
-
$id = $btn["id"];
|
746 |
-
$b = MB()->getClass('button');
|
747 |
-
$b->clear();
|
748 |
-
$b->set($id);
|
749 |
-
$button_data = $b->get();
|
750 |
-
// exclude auto-generated non-user edited buttons.
|
751 |
-
if ( ! isset($button_data["meta"]["user_edited"]) || ($button_data["meta"]["user_edited"] == true || $button_data["meta"]["created_source"] != "collection"))
|
752 |
-
$button_array[] = $b; // the object
|
753 |
-
}
|
754 |
-
return $button_array;
|
755 |
-
}
|
756 |
-
|
757 |
-
function showBlocks()
|
758 |
-
{
|
759 |
-
|
760 |
-
foreach($this->blocks as $block)
|
761 |
-
{
|
762 |
-
echo $block->admin_fields();
|
763 |
-
|
764 |
-
}
|
765 |
-
|
766 |
-
}
|
767 |
-
} //class
|
768 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/collections.php
DELETED
@@ -1,514 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
|
5 |
-
use \RecursiveDirectoryIterator as RecursiveDirectoryIterator;
|
6 |
-
use \FilesystemIterator as FilesystemIterator;
|
7 |
-
use \RecursiveIteratorIterator as RecursiveIteratorIterator;
|
8 |
-
|
9 |
-
|
10 |
-
class maxCollections
|
11 |
-
{
|
12 |
-
static $init = false;
|
13 |
-
//static $collections = array();
|
14 |
-
static $collectionClass = array();
|
15 |
-
static $collectionBlock = array();
|
16 |
-
|
17 |
-
static $hooks = array();
|
18 |
-
|
19 |
-
static $cached_collections = array();
|
20 |
-
protected static $transientChecked = false;
|
21 |
-
|
22 |
-
static $collectionButtons = null; // all button ID's in a collection.
|
23 |
-
|
24 |
-
static function init()
|
25 |
-
{
|
26 |
-
$collection_paths = apply_filters("mbcollection_paths", array( MB()->get_plugin_path() . '/collections/') );
|
27 |
-
$collectionClass = array();
|
28 |
-
$collectionBlock = array();
|
29 |
-
|
30 |
-
foreach($collection_paths as $cpath)
|
31 |
-
{
|
32 |
-
$dir_iterator = new RecursiveDirectoryIterator($cpath, FilesystemIterator::SKIP_DOTS);
|
33 |
-
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
|
34 |
-
|
35 |
-
foreach ($iterator as $fileinfo)
|
36 |
-
{
|
37 |
-
$collection = $fileinfo->getFilename();
|
38 |
-
|
39 |
-
|
40 |
-
if (file_exists($cpath . $collection))
|
41 |
-
{
|
42 |
-
require_once( $cpath . $collection);
|
43 |
-
}
|
44 |
-
}
|
45 |
-
}
|
46 |
-
self::$collectionClass = $collectionClass;
|
47 |
-
self::$collectionBlock = $collectionBlock;
|
48 |
-
|
49 |
-
self::$init = true;
|
50 |
-
|
51 |
-
}
|
52 |
-
|
53 |
-
/*
|
54 |
-
Check our custom transients for expiration. This should be done only once per run or less.
|
55 |
-
*/
|
56 |
-
static function checkExpireTrans()
|
57 |
-
{
|
58 |
-
if (! self::$transientChecked)
|
59 |
-
{
|
60 |
-
maxUtils::removeExpiredTrans(); // instead of on each button to reduce load.
|
61 |
-
self::$transientChecked = true;
|
62 |
-
}
|
63 |
-
}
|
64 |
-
/*
|
65 |
-
Function to hook into WordPress for automatic display of collections.
|
66 |
-
*/
|
67 |
-
static function setupHooks()
|
68 |
-
{
|
69 |
-
// check for admin side, we need not hooks nor queries for this.
|
70 |
-
if (is_admin())
|
71 |
-
return;
|
72 |
-
|
73 |
-
|
74 |
-
global $pagenow;
|
75 |
-
if ( in_array($pagenow, array('wp-login.php', 'wp-register.php')) )
|
76 |
-
return;
|
77 |
-
|
78 |
-
global $wpdb;
|
79 |
-
$table = maxUtils::get_collection_table_name();
|
80 |
-
$sql = "select collection_id, collection_key, collection_value from $table where
|
81 |
-
collection_key in ('show_homepage','show_page','show_post', 'show_archive')
|
82 |
-
and collection_id IN (select collection_id from $table where collection_key = 'collection_type'
|
83 |
-
and collection_value = 'social' ) ";
|
84 |
-
$results = $wpdb->get_results($sql, ARRAY_A);
|
85 |
-
|
86 |
-
$hook_array = array();
|
87 |
-
|
88 |
-
foreach($results as $result)
|
89 |
-
{
|
90 |
-
$id = $result["collection_id"];
|
91 |
-
$key = $result["collection_key"];
|
92 |
-
$placement = $result["collection_value"];
|
93 |
-
|
94 |
-
// override - if needed you can specify a different placement for each position
|
95 |
-
$placement = apply_filters("mb-collection-$id-$key-placement", $placement);
|
96 |
-
|
97 |
-
switch($placement)
|
98 |
-
{
|
99 |
-
case "after":
|
100 |
-
case "before":
|
101 |
-
case "after-before":
|
102 |
-
$show_type = "post"; // show on the post loop
|
103 |
-
break;
|
104 |
-
case "static-left":
|
105 |
-
case "static-right":
|
106 |
-
case "static-top":
|
107 |
-
case "static-bottom":
|
108 |
-
$show_type = "once"; // show once - otherwise for overviews they will be many static buttons.
|
109 |
-
break;
|
110 |
-
}
|
111 |
-
|
112 |
-
$hook_array[$show_type][$key][] = array("collection_id" => $id, "placement" => $placement);
|
113 |
-
}
|
114 |
-
|
115 |
-
|
116 |
-
self::$hooks = $hook_array;
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
if (isset($hook_array["post"]) && count($hook_array["post"]) > 0)
|
121 |
-
{
|
122 |
-
add_filter("the_content", array(maxUtils::namespaceit('maxCollections'), "doContentHooks"));
|
123 |
-
}
|
124 |
-
if (isset($hook_array["once"]) && count($hook_array["once"]) > 0)
|
125 |
-
{
|
126 |
-
//self::doFooterHooks(); // the stuff that goes once.
|
127 |
-
add_action('wp_head', array(maxUtils::namespaceit('maxCollections'), 'doFooterHooks'));
|
128 |
-
}
|
129 |
-
|
130 |
-
if (count($hook_array) > 0)
|
131 |
-
return true; // yes, bind action and check
|
132 |
-
else
|
133 |
-
return false; // no binds, don't check.
|
134 |
-
}
|
135 |
-
|
136 |
-
/* Try to find the current place we are at in the site ( front / blog / page etc ) .*/
|
137 |
-
protected static function getCurrentHook()
|
138 |
-
{
|
139 |
-
$hook = '';
|
140 |
-
if (is_front_page()) // check if home page ( home page > page )
|
141 |
-
{
|
142 |
-
$hook = "show_homepage";
|
143 |
-
|
144 |
-
}
|
145 |
-
elseif (is_page()) // check if page
|
146 |
-
{
|
147 |
-
$hook = "show_page";
|
148 |
-
}
|
149 |
-
elseif (is_single() || is_home()) // check if post
|
150 |
-
{
|
151 |
-
$hook = "show_post";
|
152 |
-
}
|
153 |
-
elseif (is_archive())
|
154 |
-
{
|
155 |
-
$hook = "show_archive";
|
156 |
-
}
|
157 |
-
|
158 |
-
|
159 |
-
return $hook;
|
160 |
-
}
|
161 |
-
|
162 |
-
static function doContentHooks($content)
|
163 |
-
{
|
164 |
-
$hook_array = self::$hooks["post"];
|
165 |
-
$hook = self::getCurrentHook();
|
166 |
-
|
167 |
-
if ($hook == '')
|
168 |
-
return $content; // nothing
|
169 |
-
|
170 |
-
if (! isset($hook_array[$hook])) // nothing as well
|
171 |
-
return $content;
|
172 |
-
|
173 |
-
$collections = $hook_array[$hook];
|
174 |
-
|
175 |
-
// do all collections on hook -- check for placement as well.
|
176 |
-
foreach($collections as $settings)
|
177 |
-
{
|
178 |
-
$collection_id = $settings["collection_id"];
|
179 |
-
$placement = $settings["placement"];
|
180 |
-
|
181 |
-
$col = self::getCollectionByID($collection_id);
|
182 |
-
$col->set($collection_id);
|
183 |
-
$output = $col->display(array("echo" => false)); // output default, no echo
|
184 |
-
|
185 |
-
|
186 |
-
switch($placement) // where to output, rather limited atm.
|
187 |
-
{
|
188 |
-
case "before":
|
189 |
-
$place = "before";
|
190 |
-
break;
|
191 |
-
case "after-before";
|
192 |
-
$place = "both";
|
193 |
-
break;
|
194 |
-
default:
|
195 |
-
$place = "after";
|
196 |
-
break;
|
197 |
-
|
198 |
-
}
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
if($place == 'before' || $place == 'both')
|
203 |
-
{
|
204 |
-
$content = $output . $content;
|
205 |
-
}
|
206 |
-
if($place == 'after' || $place == 'both')
|
207 |
-
{
|
208 |
-
|
209 |
-
$content = $content . $output;
|
210 |
-
}
|
211 |
-
}
|
212 |
-
|
213 |
-
return $content;
|
214 |
-
|
215 |
-
}
|
216 |
-
|
217 |
-
static function doFooterHooks()
|
218 |
-
{
|
219 |
-
$hook_array = self::$hooks["once"];
|
220 |
-
$hook = self::getCurrentHook();
|
221 |
-
|
222 |
-
if (! isset($hook_array[$hook])) // nothing
|
223 |
-
return;
|
224 |
-
|
225 |
-
$collections = $hook_array[$hook];
|
226 |
-
foreach($collections as $settings)
|
227 |
-
{
|
228 |
-
$collection_id = $settings["collection_id"];
|
229 |
-
$placement = $settings["placement"];
|
230 |
-
|
231 |
-
$col = self::getCollectionByID($collection_id);
|
232 |
-
$col->set($collection_id);
|
233 |
-
|
234 |
-
$output = $col->display(array("echo" => false)); // output default, no echo
|
235 |
-
|
236 |
-
do_action('mb-footer', 'collection-' . $collection_id, $output, 'collection_output');
|
237 |
-
|
238 |
-
}
|
239 |
-
}
|
240 |
-
|
241 |
-
static function checkCachedCollection($collection_id)
|
242 |
-
{
|
243 |
-
/* The cache is pointless since for every collection the shared URL's and fields can change. This means that the same collection
|
244 |
-
can server up multiple situations. Deactivated this when discovered in /blogs/ all have the same share URL on different posts.
|
245 |
-
*/
|
246 |
-
return false;
|
247 |
-
|
248 |
-
// if (isset(self::$cached_collections[$collection_id]))
|
249 |
-
// return self::$cached_collections[$collection_id];
|
250 |
-
|
251 |
-
// return false;
|
252 |
-
}
|
253 |
-
|
254 |
-
static function addCachedCollection($collection_id, $data)
|
255 |
-
{
|
256 |
-
self::$cached_collections[$collection_id] = $data;
|
257 |
-
}
|
258 |
-
|
259 |
-
public static function isButtonInCollection($button_id)
|
260 |
-
{
|
261 |
-
if (is_null(self::$collectionButtons))
|
262 |
-
{
|
263 |
-
global $wpdb;
|
264 |
-
$table = maxUtils::get_collection_table_name();
|
265 |
-
$sql = 'SELECT collection_id, collection_value FROM ' . $table . ' WHERE
|
266 |
-
collection_key = "picker";';
|
267 |
-
$result = $wpdb->get_results($sql, ARRAY_A);
|
268 |
-
|
269 |
-
$buttonarray = array();
|
270 |
-
foreach ($result as $index => $row)
|
271 |
-
{
|
272 |
-
$collection_id = $row['collection_id'];
|
273 |
-
$buttons = json_decode($row['collection_value']);
|
274 |
-
|
275 |
-
if (isset($buttons->selection))
|
276 |
-
$buttons = $buttons->selection;
|
277 |
-
else
|
278 |
-
$buttons = array();
|
279 |
-
|
280 |
-
foreach($buttons as $index => $b_id)
|
281 |
-
{
|
282 |
-
if (isset(static::$collectionButtons[$b_id]))
|
283 |
-
self::$collectionButtons[$b_id][] = $collection_id;
|
284 |
-
else
|
285 |
-
self::$collectionButtons[$b_id] = array($collection_id);
|
286 |
-
}
|
287 |
-
|
288 |
-
}
|
289 |
-
|
290 |
-
}
|
291 |
-
|
292 |
-
if (isset(self::$collectionButtons[$button_id]))
|
293 |
-
return self::$collectionButtons[$button_id];
|
294 |
-
else
|
295 |
-
return false;
|
296 |
-
}
|
297 |
-
|
298 |
-
static function ajax_save()
|
299 |
-
{
|
300 |
-
$nonce = sanitize_text_field($_POST["nonce"]);
|
301 |
-
$action = sanitize_text_field($_POST["action"]);
|
302 |
-
|
303 |
-
|
304 |
-
$collection_id = intval($_POST["collection_id"]);
|
305 |
-
$collection_type = sanitize_text_field($_POST["collection_type"]);
|
306 |
-
|
307 |
-
$admin = MB()->getClass('admin');
|
308 |
-
|
309 |
-
$result_title = array("success" => __("Your collection was saved","maxbuttons"),
|
310 |
-
"error" => __("Error","maxbuttons")
|
311 |
-
);
|
312 |
-
|
313 |
-
$close_text = __('Close', 'maxbuttons');
|
314 |
-
|
315 |
-
$result = array(
|
316 |
-
"error" => false,
|
317 |
-
"body" => '',
|
318 |
-
"result" => true,
|
319 |
-
"data" => array(),
|
320 |
-
"close_text" => $close_text,
|
321 |
-
"new_nonce" => 0,
|
322 |
-
);
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
if (! wp_verify_nonce($nonce, $action . "-" . $collection_id))
|
327 |
-
{
|
328 |
-
$result["error"] = true;
|
329 |
-
$result["body"] = __("Nonce not verified","maxbuttons");
|
330 |
-
$result["result"] = false;
|
331 |
-
$result["title"] = $result_title["error"];
|
332 |
-
$result["data"] = array("id" => $collection_id);
|
333 |
-
|
334 |
-
$admin->endAjaxRequest($result);
|
335 |
-
|
336 |
-
}
|
337 |
-
|
338 |
-
if (! isset($collection_type))
|
339 |
-
{
|
340 |
-
MB()->add_notice("error", __("Collection type not found in save. Aborting","maxbuttons"));
|
341 |
-
$result["error"] = true;
|
342 |
-
$result["body"] = MB()->display_notices(false);
|
343 |
-
$result["result"] = false;
|
344 |
-
$result["title"] = $result_title["error"];
|
345 |
-
|
346 |
-
$admin->endAjaxRequest($result);
|
347 |
-
}
|
348 |
-
|
349 |
-
$collection = self::getCollection($collection_type);
|
350 |
-
$collection->set($collection_id);
|
351 |
-
|
352 |
-
$force_reload = false;
|
353 |
-
if ($collection_id == 0)
|
354 |
-
$force_reload = true;
|
355 |
-
|
356 |
-
// this can be a new id (!)
|
357 |
-
$collection_id = $collection->save($_POST);
|
358 |
-
|
359 |
-
$result["data"]["id"] = $collection_id;
|
360 |
-
$result["data"]["new_nonce"] = wp_create_nonce($action . "-" . $collection_id);
|
361 |
-
$result["data"]["reload"] = apply_filters("collections_ajax_force_reload",$force_reload);
|
362 |
-
|
363 |
-
$result["title"] = $result_title["success"];
|
364 |
-
|
365 |
-
$admin->endAjaxRequest($result);
|
366 |
-
|
367 |
-
//echo json_encode($result);
|
368 |
-
//exit();
|
369 |
-
}
|
370 |
-
|
371 |
-
static function ajax_action_front()
|
372 |
-
{
|
373 |
-
// only for trivial front page actions!
|
374 |
-
self::ajax_action(array("ajax_nopriv" => true));
|
375 |
-
}
|
376 |
-
|
377 |
-
static function ajax_action($args = array())
|
378 |
-
{
|
379 |
-
ob_start();
|
380 |
-
$defaults = array("ajax_nopriv" => false);
|
381 |
-
$args = wp_parse_args($args, $defaults);
|
382 |
-
|
383 |
-
|
384 |
-
$admin = MB()->getClass('admin');
|
385 |
-
|
386 |
-
$nonce = isset($_POST["nonce"]) ? $_POST["nonce"] : false;
|
387 |
-
$block_name = sanitize_text_field($_POST["block_name"]);
|
388 |
-
$block_action = sanitize_text_field($_POST["block_action"]);
|
389 |
-
$block_data = (isset($_POST["block_data"])) ? $_POST["block_data"] : '';
|
390 |
-
$action = sanitize_text_field($_POST["action"]);
|
391 |
-
|
392 |
-
$collection_id = intval($_POST["collection_id"]);
|
393 |
-
$collection_type = sanitize_text_field($_POST["collection_type"]);
|
394 |
-
|
395 |
-
if(! $args["ajax_nopriv"])
|
396 |
-
{
|
397 |
-
if (! wp_verify_nonce($nonce, $action . "-" . $collection_id))
|
398 |
-
{
|
399 |
-
$result["error"] = true;
|
400 |
-
$result["body"] = __("Nonce not verified","maxbuttons");
|
401 |
-
$result["result"] = false;
|
402 |
-
$result["title"] = __("Security error","maxbuttons");
|
403 |
-
$result["data"] = array("id" => $collection_id);
|
404 |
-
|
405 |
-
$admin->endAjaxRequest($result);
|
406 |
-
|
407 |
-
}
|
408 |
-
}
|
409 |
-
|
410 |
-
$result = array(
|
411 |
-
"error" => false,
|
412 |
-
"body" => '',
|
413 |
-
"result" => true,
|
414 |
-
"data" => array(),
|
415 |
-
"new_nonce" => 0,
|
416 |
-
);
|
417 |
-
|
418 |
-
$collection = self::getCollection($collection_type);
|
419 |
-
$collection->set($collection_id);
|
420 |
-
|
421 |
-
$result = $collection->doBlockAjax($result, $block_name, $block_action, $block_data);
|
422 |
-
|
423 |
-
//ob_end_clean(); // prevent PHP errors from breaking JSON response.
|
424 |
-
|
425 |
-
$admin->endAjaxRequest($result);
|
426 |
-
$results = $collection->get_meta($name, 'collection_name');
|
427 |
-
}
|
428 |
-
|
429 |
-
static function getCollections()
|
430 |
-
{
|
431 |
-
if (! self::$init) self::init();
|
432 |
-
|
433 |
-
global $wpdb;
|
434 |
-
|
435 |
-
$table = maxUtils::get_collection_table_name();
|
436 |
-
|
437 |
-
$sql = "SELECT distinct collection_id from $table";
|
438 |
-
|
439 |
-
$results = $wpdb->get_results($sql,ARRAY_A);
|
440 |
-
return $results;
|
441 |
-
}
|
442 |
-
|
443 |
-
/* This will invoke a collection class by name ( i.e. social-collection or basic-collection */
|
444 |
-
static function getCollection($name)
|
445 |
-
{
|
446 |
-
if (! self::$init) self::init();
|
447 |
-
|
448 |
-
if (isset(self::$collectionClass[$name]))
|
449 |
-
{
|
450 |
-
$class = maxUtils::namespaceit(self::$collectionClass[$name]);
|
451 |
-
return new $class;
|
452 |
-
}
|
453 |
-
}
|
454 |
-
|
455 |
-
/* This will find an user defined collection from the database by ID */
|
456 |
-
static function getCollectionByID($id)
|
457 |
-
{
|
458 |
-
$collection = new maxCollection();
|
459 |
-
$results = $collection->get_meta($id, 'collection_type');
|
460 |
-
|
461 |
-
|
462 |
-
if ( count($results) == 1)
|
463 |
-
{
|
464 |
-
|
465 |
-
$type = $results["collection_type"];
|
466 |
-
|
467 |
-
$usecol = self::getCollection($type);
|
468 |
-
if (! $usecol)
|
469 |
-
return false;
|
470 |
-
|
471 |
-
$usecol->set($id);
|
472 |
-
return $usecol;
|
473 |
-
}
|
474 |
-
|
475 |
-
return false;
|
476 |
-
}
|
477 |
-
|
478 |
-
/* Find a collection from the database by name */
|
479 |
-
static function getCollectionbyName($name)
|
480 |
-
{
|
481 |
-
//$collection = new maxCollection();
|
482 |
-
global $wpdb;
|
483 |
-
$sql = "select collection_id from " . maxUtils::get_collection_table_name() . " where collection_key = 'collection_name' and collection_value = %s ";
|
484 |
-
$sql = $wpdb->prepare($sql, $name);
|
485 |
-
$result = $wpdb->get_row($sql, ARRAY_A); // find first
|
486 |
-
|
487 |
-
|
488 |
-
if (count($result) > 0)
|
489 |
-
{
|
490 |
-
if (isset($result["collection_id"]))
|
491 |
-
{
|
492 |
-
|
493 |
-
$usecol = self::getCollectionByID($result["collection_id"]);
|
494 |
-
return $usecol;
|
495 |
-
}
|
496 |
-
|
497 |
-
}
|
498 |
-
return false;
|
499 |
-
}
|
500 |
-
|
501 |
-
static function getBlock($name)
|
502 |
-
{
|
503 |
-
if (! self::$init) self::init();
|
504 |
-
|
505 |
-
if (isset(self::$collectionBlock[$name]))
|
506 |
-
{
|
507 |
-
$class = maxUtils::namespaceit(self::$collectionBlock[$name]);
|
508 |
-
return new $class;
|
509 |
-
}
|
510 |
-
else return false;
|
511 |
-
}
|
512 |
-
|
513 |
-
|
514 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classes/maxbuttons-class.php
CHANGED
@@ -74,16 +74,11 @@ class maxButtonsPlugin
|
|
74 |
add_action('maxbuttons/ajax/save_review_notice_status', array(maxUtils::namespaceit('maxAdmin'), "setReviewNoticeStatus") );
|
75 |
//add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
|
76 |
|
77 |
-
|
78 |
-
//add_action("wp_ajax_collection-edit", array(maxUtils::namespaceit("maxCollections"), "ajax_save"));
|
79 |
-
//add_action('wp_ajax_mbpro_collection_block', array(maxUtils::namespaceit("maxCollections"), "ajax_action")); // all block level ajax stuff - for logged in users - backend
|
80 |
add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
|
81 |
|
82 |
add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
|
83 |
}
|
84 |
-
// FRONT AJAX
|
85 |
-
//add_action('wp_ajax_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front")); // front end for all users
|
86 |
-
//add_action('wp_ajax_nopriv_mbpro_collection_block_front', array(maxUtils::namespaceit("maxCollections"), "ajax_action_front"));
|
87 |
|
88 |
// front scripts
|
89 |
add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
|
@@ -96,8 +91,7 @@ class maxButtonsPlugin
|
|
96 |
|
97 |
// setup page hooks and shortcode
|
98 |
add_shortcode('maxcollection', array($this, 'collection_shortcode'));
|
99 |
-
|
100 |
-
$hook_bool = maxCollections::setupHooks(); // setup the hooks to insert collections
|
101 |
|
102 |
self::$instance = $this;
|
103 |
maxIntegrations::init(); // fire the integrations.
|
@@ -117,8 +111,6 @@ class maxButtonsPlugin
|
|
117 |
"admin" => "maxButtonsAdmin",
|
118 |
"install" => "maxInstall",
|
119 |
"groups" => "maxGroups",
|
120 |
-
"collections" => "maxCollections",
|
121 |
-
"collection" => "maxCollection",
|
122 |
"pack" => "maxPack",
|
123 |
);
|
124 |
|
@@ -414,24 +406,7 @@ class maxButtonsPlugin
|
|
414 |
|
415 |
wp_enqueue_script('maxbuttons-ajax');
|
416 |
|
417 |
-
/* wp_register_script('maxcollections', $js_url . 'maxcollections.js',
|
418 |
-
array('jquery', 'maxbutton-admin', 'jquery-ui-sortable'),$version, true );
|
419 |
-
|
420 |
-
$local = array();
|
421 |
-
$local["ajaxurl"] = admin_url( 'admin-ajax.php' );
|
422 |
-
$local["maxurl"] = $this->plugin_url;
|
423 |
-
wp_localize_script('maxbutton-admin', 'mb_ajax', $local);
|
424 |
-
|
425 |
-
$local = array(
|
426 |
-
"leave_page" => __("You have unsaved data, are you sure you want to leave the page?","maxbuttons"),
|
427 |
-
'picker_title' => __('Select your buttons','maxbuttons'),
|
428 |
-
|
429 |
-
);
|
430 |
-
wp_localize_script('maxcollections', 'maxcol_wp', $local);
|
431 |
-
*/
|
432 |
$this->load_modal_script();
|
433 |
-
|
434 |
-
//wp_enqueue_script('maxcollections');
|
435 |
}
|
436 |
|
437 |
/** Load the Modal Script
|
@@ -567,28 +542,7 @@ class maxButtonsPlugin
|
|
567 |
/** Function for collection shortcode [deprecated] **/
|
568 |
public function collection_shortcode($atts, $content = null)
|
569 |
{
|
570 |
-
return false; // no more.
|
571 |
-
$atts = shortcode_atts(array(
|
572 |
-
"id" => 0,
|
573 |
-
"name" => '',
|
574 |
-
"nocache" => false, // these are button options.
|
575 |
-
"mode" => "normal",
|
576 |
-
"style" => "footer",
|
577 |
-
),
|
578 |
-
|
579 |
-
$atts);
|
580 |
-
|
581 |
-
$id = intval($atts["id"]);
|
582 |
-
$name = sanitize_text_field($atts["name"]);
|
583 |
-
|
584 |
-
if ($id > 0)
|
585 |
-
$collection = maxCollections::getCollectionByID($id);
|
586 |
-
elseif ($atts["name"] != '')
|
587 |
-
$collection = maxCollections::getCollectionByName($name);
|
588 |
-
|
589 |
-
|
590 |
-
if ($collection)
|
591 |
-
return $collection->shortcode($atts,$content);
|
592 |
|
593 |
}
|
594 |
|
@@ -620,6 +574,10 @@ class maxButtonsPlugin
|
|
620 |
}
|
621 |
|
622 |
|
|
|
|
|
|
|
|
|
623 |
function footer()
|
624 |
{
|
625 |
if(count($this->footer) == 0) return; // nothing
|
74 |
add_action('maxbuttons/ajax/save_review_notice_status', array(maxUtils::namespaceit('maxAdmin'), "setReviewNoticeStatus") );
|
75 |
//add_action("wp_ajax_set_review_notice_status", array($this, "setReviewNoticeStatus"));
|
76 |
|
77 |
+
|
|
|
|
|
78 |
add_action('wp_ajax_mb_button_action', array(maxUtils::namespaceit('maxButtons'), "ajax_action"));
|
79 |
|
80 |
add_action('wp_ajax_maxajax', array(maxUtils::namespaceit('maxUtils'), 'ajax_action'));
|
81 |
}
|
|
|
|
|
|
|
82 |
|
83 |
// front scripts
|
84 |
add_action('wp_enqueue_scripts', array($this, 'front_scripts'));
|
91 |
|
92 |
// setup page hooks and shortcode
|
93 |
add_shortcode('maxcollection', array($this, 'collection_shortcode'));
|
94 |
+
|
|
|
95 |
|
96 |
self::$instance = $this;
|
97 |
maxIntegrations::init(); // fire the integrations.
|
111 |
"admin" => "maxButtonsAdmin",
|
112 |
"install" => "maxInstall",
|
113 |
"groups" => "maxGroups",
|
|
|
|
|
114 |
"pack" => "maxPack",
|
115 |
);
|
116 |
|
406 |
|
407 |
wp_enqueue_script('maxbuttons-ajax');
|
408 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
409 |
$this->load_modal_script();
|
|
|
|
|
410 |
}
|
411 |
|
412 |
/** Load the Modal Script
|
542 |
/** Function for collection shortcode [deprecated] **/
|
543 |
public function collection_shortcode($atts, $content = null)
|
544 |
{
|
545 |
+
return false; // no more. silent fail.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
546 |
|
547 |
}
|
548 |
|
574 |
}
|
575 |
|
576 |
|
577 |
+
/** Output footer styles and scripts
|
578 |
+
*
|
579 |
+
* Outputs loaded styles, and scripts to the footer for display. Email_off is to prevent cloudfare from 'obfuscating' the minified CSS
|
580 |
+
*/
|
581 |
function footer()
|
582 |
{
|
583 |
if(count($this->footer) == 0) return; // nothing
|
collections/basic-block.php
DELETED
@@ -1,192 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
$collectionBlock["basic"] = "basicCollectionBlock";
|
5 |
-
|
6 |
-
class basicCollectionBlock extends collectionBlock
|
7 |
-
{
|
8 |
-
protected $blockname = "basic";
|
9 |
-
protected $fields = array("name" => array("default" => ""),
|
10 |
-
"show_homepage" => array("default" => 0),
|
11 |
-
"show_page" => array("default" => 0),
|
12 |
-
"show_post" => array("default" => 0),
|
13 |
-
"show_archive" => array("default" => 0),
|
14 |
-
"placement" => array("default" => "after"),
|
15 |
-
|
16 |
-
);
|
17 |
-
|
18 |
-
function __construct()
|
19 |
-
{
|
20 |
-
$this->fields["name"]["default"] = __("New Collection","maxbuttons");
|
21 |
-
|
22 |
-
}
|
23 |
-
|
24 |
-
function parseCSS($css, $args)
|
25 |
-
{
|
26 |
-
$css["maxcollection"]["normal"]["display"] = "inline-block";
|
27 |
-
$css["maxcollection"]["normal"]["z-index"] = "9999";
|
28 |
-
|
29 |
-
switch($this->data["placement"])
|
30 |
-
{
|
31 |
-
case "static-left":
|
32 |
-
$css["maxcollection"]["normal"]["position"] = "fixed";
|
33 |
-
$css["maxcollection"]["normal"]["left"] = "0"; // these as string otherwise css compiler doens't like it
|
34 |
-
$css["maxcollection"]["normal"]["top"] = "0";
|
35 |
-
break;
|
36 |
-
case "static-right":
|
37 |
-
$css["maxcollection"]["normal"]["position"] = "fixed";
|
38 |
-
$css["maxcollection"]["normal"]["right"] = "0";
|
39 |
-
$css["maxcollection"]["normal"]["top"] = "0";
|
40 |
-
break;
|
41 |
-
case "static-top":
|
42 |
-
$css["maxcollection"]["normal"]["position"] = "fixed";
|
43 |
-
$css["maxcollection"]["normal"]["left"] = "0";
|
44 |
-
$css["maxcollection"]["normal"]["top"] = "0";
|
45 |
-
break;
|
46 |
-
case "static-bottom":
|
47 |
-
$css["maxcollection"]["normal"]["position"] = "fixed";
|
48 |
-
$css["maxcollection"]["normal"]["left"] = "0";
|
49 |
-
$css["maxcollection"]["normal"]["bottom"] = "0";
|
50 |
-
break;
|
51 |
-
}
|
52 |
-
|
53 |
-
if ($args["preview"] == true)
|
54 |
-
{
|
55 |
-
if (isset($css["maxcollection"]["normal"]["position"]) && $css["maxcollection"]["normal"]["position"] == "fixed")
|
56 |
-
{
|
57 |
-
$css["maxcollection"]["normal"]["position"]= "absolute";
|
58 |
-
}
|
59 |
-
|
60 |
-
|
61 |
-
}
|
62 |
-
|
63 |
-
//$css["maxcollection"]["normal"]["background-color"] = "#fff";
|
64 |
-
return $css;
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
-
public function map_fields($map)
|
69 |
-
{
|
70 |
-
$map = parent::map_fields($map);
|
71 |
-
$map["collection_name"]["func"] = "updateCollectionName";
|
72 |
-
$map["placement"]["func"] = "updatePlacement";
|
73 |
-
|
74 |
-
|
75 |
-
return $map;
|
76 |
-
}
|
77 |
-
|
78 |
-
function save_fields($data, $post)
|
79 |
-
{
|
80 |
-
$data = parent::save_fields($data, $post);
|
81 |
-
$data["collection_name"] = $data[$this->blockname]["name"]; // save as a global meta for searching
|
82 |
-
$data["collection_type"] = $this->collection->getType();
|
83 |
-
if ($data[$this->blockname]["show_homepage"] == 1)
|
84 |
-
{
|
85 |
-
$data["show_homepage"] = $data[$this->blockname]["placement"];
|
86 |
-
}
|
87 |
-
if ($data[$this->blockname]["show_page"] == 1)
|
88 |
-
{
|
89 |
-
$data["show_page"] = $data[$this->blockname]["placement"];
|
90 |
-
}
|
91 |
-
|
92 |
-
if ($data[$this->blockname]["show_post"] == 1)
|
93 |
-
{
|
94 |
-
$data["show_post"] = $data[$this->blockname]["placement"];
|
95 |
-
}
|
96 |
-
if ($data[$this->blockname]["show_archive"] == 1)
|
97 |
-
{
|
98 |
-
$data["show_archive"] = $data[$this->blockname]["placement"];
|
99 |
-
}
|
100 |
-
|
101 |
-
return $data;
|
102 |
-
|
103 |
-
}
|
104 |
-
|
105 |
-
function admin_fields()
|
106 |
-
{
|
107 |
-
|
108 |
-
extract($this->data); // admin data
|
109 |
-
|
110 |
-
$placement_options = array(
|
111 |
-
"after" => __("After","maxbuttons"),
|
112 |
-
"before" => __("Before","maxbuttons"),
|
113 |
-
"after-before" => __("Before + After (both)", "maxbuttons"),
|
114 |
-
"static-left" => __("Static left","maxbuttons"),
|
115 |
-
"static-right" => __("Static right","maxbuttons"),
|
116 |
-
"static-top" => __("Static top","maxbuttons"),
|
117 |
-
"static-bottom" => __("Static bottom","maxbuttons"),
|
118 |
-
);
|
119 |
-
?><div class="mb_tab option-container" data-options="settings">
|
120 |
-
<div class="title">
|
121 |
-
<span class="dashicons dashicons-admin-settings"></span>
|
122 |
-
<span class="title"><?php _e("Settings","maxbuttons"); ?></span>
|
123 |
-
<span class='manual-box'><a href='javascript:void(0)' class='manual-toggle' data-target="settings"> <?php _e("Getting Started","maxbuttons-pro"); ?> </a></span>
|
124 |
-
<span class='right'><button name="save" type="submit" data-form='collection_edit' class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
|
125 |
-
</span>
|
126 |
-
</div>
|
127 |
-
|
128 |
-
<div class="inside">
|
129 |
-
|
130 |
-
<div class="option">
|
131 |
-
<label for="collection_name"><?php _e("Name"); ?></label>
|
132 |
-
<input type="text" id='collection_name' name="name" value="<?php echo esc_attr($name) ?>" />
|
133 |
-
<div class="help fa fa-question-circle">
|
134 |
-
<span><?php _e("The name of your collection. It will not be displayed on the site.", "maxbuttons"); ?>
|
135 |
-
</span>
|
136 |
-
</div>
|
137 |
-
|
138 |
-
</div>
|
139 |
-
|
140 |
-
<div class="option">
|
141 |
-
<label for="collection_show"><?php _e("Automatically show on","maxbuttons"); ?></label>
|
142 |
-
|
143 |
-
<div class='option-list'>
|
144 |
-
<div class="help fa fa-question-circle">
|
145 |
-
<span><?php _e("Auto-display your buttons on the site. Checking the options will display the buttons on the corresponding part.", "maxbuttons"); ?>
|
146 |
-
</span>
|
147 |
-
</div>
|
148 |
-
<input type="checkbox" name="show_homepage" value="1" <?php checked(1, $show_homepage) ?> >
|
149 |
-
<?php _e("Homepage","maxbuttons"); ?><br />
|
150 |
-
|
151 |
-
<input type="checkbox" name="show_page" value="1" <?php checked(1, $show_page) ?> > <?php _e("Pages","maxbuttons"); ?><br>
|
152 |
-
<input type="checkbox" name="show_post" value="1" <?php checked(1, $show_post) ?> > <?php _e("Posts","maxbuttons"); ?><br>
|
153 |
-
<input type="checkbox" name="show_archive" value="1" <?php checked(1,$show_archive) ?> >
|
154 |
-
<?php _e("Category / Archives","maxbuttons"); ?> <br>
|
155 |
-
|
156 |
-
|
157 |
-
</div>
|
158 |
-
</div>
|
159 |
-
|
160 |
-
<div class="option">
|
161 |
-
<label for="collection_placement"><?php _e("Placement"); ?></label>
|
162 |
-
<?php echo maxUtils::selectify("placement", $placement_options, $placement); ?>
|
163 |
-
<div class="help fa fa-question-circle">
|
164 |
-
<span><?php _e("Choose where the buttons will show up.", "maxbuttons"); ?>
|
165 |
-
</span>
|
166 |
-
</div>
|
167 |
-
</div>
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
</div>
|
172 |
-
</div> <!-- option container -->
|
173 |
-
|
174 |
-
<div class="manual-entry" data-manual="settings">
|
175 |
-
<h3><?php _e("General settings", "maxbuttons"); ?>
|
176 |
-
<span class="dashicons dashicons-no window close manual-toggle" data-target="settings"></span>
|
177 |
-
</h3>
|
178 |
-
|
179 |
-
<p><?php _e("Give a name to your collection of buttons and select which portions and locations on your site you want the collection to appear. Anytime you want to see how your collection is going to look click the Preview tab to open up the Preview tab. We suggest you do this first. ","maxbuttons"); ?></p>
|
180 |
-
|
181 |
-
|
182 |
-
</div>
|
183 |
-
|
184 |
-
|
185 |
-
<?php
|
186 |
-
|
187 |
-
|
188 |
-
}
|
189 |
-
|
190 |
-
}
|
191 |
-
|
192 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/basic-collection.php
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
|
5 |
-
$collectionClass["basic"] = "basicCollection";
|
6 |
-
|
7 |
-
class basicCollection extends maxCollection
|
8 |
-
{
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
}
|
13 |
-
|
14 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/layout-block.php
DELETED
@@ -1,348 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
$collectionBlock["layout"] = "layoutCollectionBlock";
|
5 |
-
|
6 |
-
class layoutCollectionBlock extends collectionBlock
|
7 |
-
{
|
8 |
-
protected $blockname = "layout";
|
9 |
-
protected $fields = array(
|
10 |
-
"margin_left" => array("default" => "0px",
|
11 |
-
"css" => "margin-left",
|
12 |
-
"csspart" => "maxcollection"),
|
13 |
-
|
14 |
-
"margin_right" => array("default" => "0px",
|
15 |
-
"css" => "margin-right",
|
16 |
-
"csspart" => "maxcollection"),
|
17 |
-
|
18 |
-
"margin_top" => array("default" => "0px",
|
19 |
-
"css" => "margin-top",
|
20 |
-
"csspart" => "maxcollection"),
|
21 |
-
|
22 |
-
"margin_bottom" => array("default" => "0px",
|
23 |
-
"css" => "margin-bottom",
|
24 |
-
"csspart" => "maxcollection"),
|
25 |
-
"orientation" => array("default" => "auto"),
|
26 |
-
|
27 |
-
"item_margin_right" => array("default" => "0px",
|
28 |
-
"css" => "margin-right",
|
29 |
-
"csspart" => "mb-collection-item",
|
30 |
-
),
|
31 |
-
"item_margin_bottom" => array("default" => "0px",
|
32 |
-
"css" => "margin-bottom",
|
33 |
-
"csspart" => "mb-collection-item",
|
34 |
-
),
|
35 |
-
"ignore_container" => array("default" => 1),
|
36 |
-
"static_position_ver" => array("default" => "Auto",
|
37 |
-
),
|
38 |
-
"static_position_hor" => array("default" => "Auto",
|
39 |
-
),
|
40 |
-
|
41 |
-
);
|
42 |
-
public function map_fields($map)
|
43 |
-
{
|
44 |
-
$map = parent::map_fields($map);
|
45 |
-
$map["orientation"]["func"] = "updatePlacement";
|
46 |
-
|
47 |
-
return $map;
|
48 |
-
}
|
49 |
-
|
50 |
-
function parseButtons($buttons)
|
51 |
-
{
|
52 |
-
// searches the cache for the container statement ending with -container or -center and tries to remove then
|
53 |
-
// not very optimal code, but this is a way to maintain cache loading while altering css.
|
54 |
-
|
55 |
-
if ($this->data["ignore_container"] == 0)
|
56 |
-
return $buttons; // ignore container off .
|
57 |
-
|
58 |
-
foreach($buttons as $button)
|
59 |
-
{
|
60 |
-
$cache = $button->getCache();
|
61 |
-
|
62 |
-
// chops all css statements in a different line
|
63 |
-
preg_match_all('/([^{]+)\s*\{\s*([^}]+)\s*}/i',$cache, $matches);
|
64 |
-
foreach($matches[0] as $cssline)
|
65 |
-
{
|
66 |
-
// tries to find the last part of the statement from - to {
|
67 |
-
preg_match_all('/.([^-])*{/i', $cssline, $item);
|
68 |
-
|
69 |
-
$item = trim(str_replace("{","",$item[0][0]));
|
70 |
-
if ($item == '-center' || $item == '-container')
|
71 |
-
{
|
72 |
-
$cache = str_replace($cssline,'',$cache);
|
73 |
-
}
|
74 |
-
|
75 |
-
|
76 |
-
}
|
77 |
-
|
78 |
-
//([^{]+)\s*\{\s*([^}]+)\s*} { split }
|
79 |
-
// match last thing .([^-])*{
|
80 |
-
$button->setCache($cache);
|
81 |
-
|
82 |
-
$data = $button->get();
|
83 |
-
|
84 |
-
$container = isset($data["container"]) ? $data["container"] : array();
|
85 |
-
foreach($container as $key => $value)
|
86 |
-
{
|
87 |
-
if ($key != 'container_enabled' && $key != 'container_center_div_wrap') // causes container to be removed otherwise
|
88 |
-
$container[$key] = '';
|
89 |
-
}
|
90 |
-
|
91 |
-
$button->setdata("container", $container);
|
92 |
-
}
|
93 |
-
return $buttons;
|
94 |
-
|
95 |
-
}
|
96 |
-
|
97 |
-
function parseCSS($css, $args)
|
98 |
-
{
|
99 |
-
$css = parent::parseCSS($css, $args);
|
100 |
-
|
101 |
-
|
102 |
-
$css["mb-collection-item"]["normal"]["float"] = "left";
|
103 |
-
$css["mb-collection-item"]["normal"]["display"] = "inline-block";
|
104 |
-
$css["mb-collection-item a"]["normal"]["cursor"] = "pointer"; // by default social share = call to action.
|
105 |
-
|
106 |
-
//$button_spacing = $this->data["button_spacing"];
|
107 |
-
$orientation = $this->data["orientation"];
|
108 |
-
|
109 |
-
$static_position_ver = $this->data["static_position_ver"];
|
110 |
-
$static_position_hor = $this->data["static_position_hor"];
|
111 |
-
|
112 |
-
$basic = $this->collection->getBlock("basic");
|
113 |
-
$picker_data = $basic->get();
|
114 |
-
$placement = $picker_data["placement"];
|
115 |
-
|
116 |
-
|
117 |
-
if ($orientation == 'auto')
|
118 |
-
{
|
119 |
-
// $basic = $this->collection->getBlock("basic");
|
120 |
-
|
121 |
-
switch($placement) // auto align on basis of placement on screen
|
122 |
-
{
|
123 |
-
case "static-left": // vertical items
|
124 |
-
case "static-right":
|
125 |
-
$orientation = "vertical";
|
126 |
-
break;
|
127 |
-
case "static-top": // horizontal
|
128 |
-
case "static-bottom":
|
129 |
-
default:
|
130 |
-
$orientation = "horizontal";
|
131 |
-
break;
|
132 |
-
}
|
133 |
-
}
|
134 |
-
|
135 |
-
switch($orientation)
|
136 |
-
{
|
137 |
-
case "horizontal":
|
138 |
-
//$css["mb_collection_item"]["normal"]["float"]
|
139 |
-
// todo
|
140 |
-
//$css["mb-collection-item"]["normal"]["margin-right"] = $button_spacing . "px";
|
141 |
-
//$css["mb-collection-item:last-child"]["normal"]["margin-right"] = "0";
|
142 |
-
break;
|
143 |
-
|
144 |
-
case "vertical";
|
145 |
-
$css["mb-collection-item"]["normal"]["clear"] = "both";
|
146 |
-
//if ($button_spacing > 0)
|
147 |
-
//{
|
148 |
-
//unset($css["mb-collection-item"]["normal"]["margin-right"]) ;
|
149 |
-
//$css["mb-collection-item"]["normal"]["clear"] = "left";
|
150 |
-
//$css["mb-collection-item"]["normal"]["margin-bottom"] = $button_spacing . "px";
|
151 |
-
|
152 |
-
//}
|
153 |
-
break;
|
154 |
-
|
155 |
-
}
|
156 |
-
|
157 |
-
if ($args["preview"] == true)
|
158 |
-
return $css; // don't process move than this in preview.
|
159 |
-
|
160 |
-
switch($placement)
|
161 |
-
{
|
162 |
-
case "static-left":
|
163 |
-
case "static-right":
|
164 |
-
switch($static_position_ver)
|
165 |
-
{
|
166 |
-
case "auto":
|
167 |
-
case "center":
|
168 |
-
$css["maxcollection"]["normal"]["top"] = "50%";
|
169 |
-
$css["maxcollection"]["normal"]["transform"] = "translateY(-50%)";
|
170 |
-
break;
|
171 |
-
case "top":
|
172 |
-
// nothing
|
173 |
-
break;
|
174 |
-
case "bottom":
|
175 |
-
unset($css["maxcollection"]["normal"]["top"]);
|
176 |
-
$css["maxcollection"]["normal"]["bottom"] = "0";
|
177 |
-
break;
|
178 |
-
}
|
179 |
-
|
180 |
-
break;
|
181 |
-
|
182 |
-
case "static-top":
|
183 |
-
case "static-bottom":
|
184 |
-
switch($static_position_hor)
|
185 |
-
{
|
186 |
-
case "auto":
|
187 |
-
case "center":
|
188 |
-
$css["maxcollection"]["normal"]["left"] = "50%";
|
189 |
-
$css["maxcollection"]["normal"]["transform"] = "translateX(-50%)";
|
190 |
-
break;
|
191 |
-
case "left":
|
192 |
-
|
193 |
-
break;
|
194 |
-
case "right":
|
195 |
-
unset($css["maxcollection"]["normal"]["left"]);
|
196 |
-
$css["maxcollection"]["normal"]["right"] = "0";
|
197 |
-
break;
|
198 |
-
|
199 |
-
}
|
200 |
-
break;
|
201 |
-
|
202 |
-
}
|
203 |
-
|
204 |
-
return $css;
|
205 |
-
|
206 |
-
}
|
207 |
-
|
208 |
-
function save_fields($data, $post)
|
209 |
-
{
|
210 |
-
$data = parent::save_fields($data, $post);
|
211 |
-
if (! isset($post["ignore_container"]))
|
212 |
-
$data[$this->blockname]["ignore_container"] = 0;
|
213 |
-
|
214 |
-
return $data;
|
215 |
-
|
216 |
-
}
|
217 |
-
|
218 |
-
function admin_fields()
|
219 |
-
{
|
220 |
-
extract($this->data);
|
221 |
-
|
222 |
-
$orientation_array = array(
|
223 |
-
"auto" => __("Auto","maxbuttons"),
|
224 |
-
"horizontal" => __("Horizontal","maxbuttons"),
|
225 |
-
"vertical" => __("Vertical","maxbuttons")
|
226 |
-
);
|
227 |
-
|
228 |
-
$staticposver = array(
|
229 |
-
"auto" => __("Auto","maxbuttons"),
|
230 |
-
"center" => __("Center","maxbuttons"),
|
231 |
-
"top" => __("Top", "maxbuttons"),
|
232 |
-
"bottom" => __("Bottom", "maxbuttons"),
|
233 |
-
);
|
234 |
-
$staticposhor = array(
|
235 |
-
"auto" => __("Auto","maxbuttons"),
|
236 |
-
"center" => __("Center","maxbutton-pro"),
|
237 |
-
"left" => __("Left","maxbuttons"),
|
238 |
-
"right" => __("Right","maxbuttons"),
|
239 |
-
);
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
$px = __("px","maxbuttons");
|
244 |
-
?><div class="mb_tab option-container layout-block" data-options="layout">
|
245 |
-
<div class="title">
|
246 |
-
<span class="dashicons dashicons-admin-appearance"></span>
|
247 |
-
<span class="title"><?php _e("Layout","maxbuttons"); ?></span>
|
248 |
-
<span class='manual-box'><a class='manual-toggle' href='javascript:void(0)' data-target="layout"> <?php _e("Getting Started","maxbuttons-pro"); ?> </a></span>
|
249 |
-
<span class='right'><button name="save" type="submit" data-form='collection_edit' class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
|
250 |
-
</span>
|
251 |
-
</div>
|
252 |
-
|
253 |
-
<div class="inside">
|
254 |
-
<div class="option">
|
255 |
-
<label for="margin-left"><?php _e("Margin left","maxbuttons"); ?></label>
|
256 |
-
<input type="number" class="tiny" id="margin_left" name="margin_left" value="<?php echo intval($margin_left) ?>" class="tiny"> <?php echo $px; ?>
|
257 |
-
</div>
|
258 |
-
|
259 |
-
<div class="option">
|
260 |
-
<label for="margin-right"><?php _e("Margin right","maxbuttons"); ?></label>
|
261 |
-
<input type="number" name="margin_right" id="margin_right" value="<?php echo intval($margin_right) ?>" class="tiny"> <?php echo $px; ?>
|
262 |
-
</div>
|
263 |
-
|
264 |
-
<div class="option">
|
265 |
-
<label for="margin-top"><?php _e("Margin bottom","maxbuttons"); ?></label>
|
266 |
-
<input type="number" name="margin_bottom" id="margin_bottom" value="<?php echo maxUtils::strip_px($margin_top) ?>" class="tiny"> <?php echo $px; ?>
|
267 |
-
</div>
|
268 |
-
|
269 |
-
<div class="option">
|
270 |
-
<label for="margin-bottom"><?php _e("Margin top","maxbuttons"); ?></label>
|
271 |
-
<input type="number" name="margin_top" id="margin_top" value="<?php echo maxUtils::strip_px($margin_bottom) ?>" class="tiny"> <?php echo $px; ?>
|
272 |
-
</div>
|
273 |
-
|
274 |
-
<div class="option">
|
275 |
-
<label for="orientation"><?php _e("Orientation","maxbuttons"); ?></label>
|
276 |
-
<?php echo maxUtils::selectify("orientation", $orientation_array, $orientation); ?>
|
277 |
-
</div>
|
278 |
-
|
279 |
-
<div class="option">
|
280 |
-
<label for="item_margin_right"><?php _e("Item margin right","maxbuttons"); ?></label>
|
281 |
-
<input type="number" class="tiny" name="item_margin_right" id="item_margin_right" value="<?php echo maxUtils::strip_px($item_margin_right) ?>"> <?php echo $px; ?>
|
282 |
-
</div>
|
283 |
-
|
284 |
-
<div class="option">
|
285 |
-
<label for="item_margin_bottom"><?php _e("Item margin bottom","maxbuttons"); ?></label>
|
286 |
-
<input type="number" class="tiny" name="item_margin_bottom" id="item_margin_bottom" value="<?php echo maxUtils::strip_px($item_margin_bottom) ?>">
|
287 |
-
<?php echo $px ?>
|
288 |
-
|
289 |
-
</div>
|
290 |
-
|
291 |
-
<div class="option">
|
292 |
-
<label for="ignore_container"><?php _e("Remove container width and margins","maxbuttons"); ?></label>
|
293 |
-
<input type="checkbox" name="ignore_container" value="1" <?php checked($ignore_container,1) ?>>
|
294 |
-
<div class="help fa fa-question-circle ">
|
295 |
-
<span><?php _e("Removes the margins and widths of the button container.", "maxbuttons"); ?>
|
296 |
-
</span>
|
297 |
-
</div>
|
298 |
-
|
299 |
-
</div>
|
300 |
-
</div>
|
301 |
-
|
302 |
-
<?php
|
303 |
-
$condition = array("target" => "placement", "values" => array("static-left","static-right","static-top", "static-bottom")) ;
|
304 |
-
$static_conditional = htmlentities(json_encode($condition ));
|
305 |
-
?>
|
306 |
-
<br>
|
307 |
-
<div class='conditional-option option-container' data-show="<?php echo $static_conditional ?>">
|
308 |
-
<div class="title"> <?php _e("Static positioning","maxbuttons"); ?></div>
|
309 |
-
<div class="inside">
|
310 |
-
<?php
|
311 |
-
$condition = array("target" => "placement", "values" => array("static-left","static-right")) ;
|
312 |
-
$static_conditional = htmlentities(json_encode($condition ));
|
313 |
-
?>
|
314 |
-
<div class="option conditional-option" data-show="<?php echo $static_conditional ?>">
|
315 |
-
<label for="static_position_ver"><?php _e("Static position vertical","maxbuttons"); ?></label>
|
316 |
-
<?php echo maxUtils::selectify("static_position_ver", $staticposver,$static_position_ver); ?>
|
317 |
-
|
318 |
-
</div>
|
319 |
-
<?php
|
320 |
-
$condition = array("target" => "placement", "values" => array("static-top", "static-bottom")) ;
|
321 |
-
$static_conditional = htmlentities(json_encode($condition ));
|
322 |
-
?>
|
323 |
-
<div class="option conditional-option" data-show="<?php echo $static_conditional ?>">
|
324 |
-
<label for="static_position_hor"><?php _e("Static position horizontal","maxbuttons"); ?></label>
|
325 |
-
<?php echo maxUtils::selectify("static_position_hor", $staticposhor,$static_position_hor); ?>
|
326 |
-
|
327 |
-
</div>
|
328 |
-
</div>
|
329 |
-
</div>
|
330 |
-
<!-- manual entry -->
|
331 |
-
<div class="manual-entry" data-manual="layout">
|
332 |
-
<h3><?php _e("Layout settings", "maxbuttons"); ?>
|
333 |
-
<span class="dashicons dashicons-no window close manual-toggle" data-target="layout"></span>
|
334 |
-
</h3>
|
335 |
-
|
336 |
-
<p><?php _e("The first 4 options - margins left, right, buttom and top - are for positioning the entire collection. Click the Preview tab on so you can see the changes to your collection as you make them. The Orientation options let’s you choose between Auto, Horizontal and Vertical. Image margin allows you to set the spacing between the icons.","maxbuttons"); ?></p>
|
337 |
-
|
338 |
-
</div>
|
339 |
-
</div> <!-- tab -->
|
340 |
-
|
341 |
-
<?php
|
342 |
-
|
343 |
-
|
344 |
-
}
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/picker-block.php
DELETED
@@ -1,275 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
|
5 |
-
$collectionBlock["picker"] = "pickerCollectionBlock";
|
6 |
-
|
7 |
-
class pickerCollectionBlock extends collectionBlock
|
8 |
-
{
|
9 |
-
protected $blockname = "picker";
|
10 |
-
protected $fields = array("selection" => array("default" => array() ),
|
11 |
-
|
12 |
-
);
|
13 |
-
|
14 |
-
// get all buttons in collection, set as proper button object/
|
15 |
-
function getButtons()
|
16 |
-
{ // should maybe but a 'light init' of buttons?
|
17 |
-
$selection = $this->data["selection"];
|
18 |
-
|
19 |
-
$buttonsArray = array();
|
20 |
-
if (count($selection) == 0)
|
21 |
-
return $buttonsArray;
|
22 |
-
|
23 |
-
$table = maxUtils::get_table_name();
|
24 |
-
$status = 'publish';
|
25 |
-
|
26 |
-
$query_selection = $selection;
|
27 |
-
|
28 |
-
$selectmask = implode( ', ', array_fill( 0, count( $query_selection ), '%d' ) );
|
29 |
-
$sql = "SELECT DISTINCT * FROM {$table} WHERE id in (" . $selectmask . ") and status = '%s' ";
|
30 |
-
$prepare_values = $query_selection;
|
31 |
-
|
32 |
-
array_push($prepare_values, $status);
|
33 |
-
|
34 |
-
global $wpdb;
|
35 |
-
$sql = $wpdb->prepare($sql, $prepare_values );
|
36 |
-
$results = $wpdb->get_results($sql, ARRAY_A);
|
37 |
-
|
38 |
-
$data_array = array();
|
39 |
-
|
40 |
-
foreach ($results as $result)
|
41 |
-
{
|
42 |
-
$data_array[$result['id']] = $result;
|
43 |
-
}
|
44 |
-
|
45 |
-
foreach($selection as $button_id)
|
46 |
-
{
|
47 |
-
$button = MB()->getClass("button");
|
48 |
-
|
49 |
-
// performance: bypass the set ( = query ) for every button
|
50 |
-
//$button->set($button_id);
|
51 |
-
|
52 |
-
$data = isset($data_array[$button_id]) ? $data_array[$button_id] : array();
|
53 |
-
if (count($data) > 0)
|
54 |
-
{
|
55 |
-
maxButtons::buttonLoad(array("button_id" => $button_id)); // central registration - from button
|
56 |
-
$button->setupData($data);
|
57 |
-
}
|
58 |
-
else
|
59 |
-
continue; // non-existing buttons should not show.
|
60 |
-
|
61 |
-
maxButtons::forceNextID();
|
62 |
-
|
63 |
-
$buttonsArray[] = $button;
|
64 |
-
}
|
65 |
-
|
66 |
-
|
67 |
-
return $buttonsArray;
|
68 |
-
}
|
69 |
-
|
70 |
-
function parse($domObj, $args)
|
71 |
-
{
|
72 |
-
|
73 |
-
$buttons = $this->collection->getLoadedButtons();
|
74 |
-
|
75 |
-
$output = '';
|
76 |
-
|
77 |
-
$collectionObj = $domObj->find('.maxcollection', 0);
|
78 |
-
|
79 |
-
$btn_display = '';
|
80 |
-
|
81 |
-
foreach($buttons as $button)
|
82 |
-
{
|
83 |
-
|
84 |
-
//$button->reloadData();
|
85 |
-
$button_id = $button->getID();
|
86 |
-
|
87 |
-
$document_id = $button->getDocumentID();
|
88 |
-
|
89 |
-
$default_args = array("mode" => "normal",
|
90 |
-
"compile" => false,
|
91 |
-
"load_type" => "footer",
|
92 |
-
);
|
93 |
-
$button_args = wp_parse_args($args, $default_args);
|
94 |
-
$button_args["load_css"] = $button_args["load_type"];
|
95 |
-
|
96 |
-
$button_args["echo"] = false; // non-optional.
|
97 |
-
|
98 |
-
if (isset($args['preview']) && $args["preview"])
|
99 |
-
$button_args["mode"] = "preview"; // buttons work with mode.
|
100 |
-
|
101 |
-
$btn_display .= "<span class='mb-collection-item item-$button_id ' data-doc-id='" . $document_id . "'>" . $button->display($button_args) . "</span>";
|
102 |
-
|
103 |
-
|
104 |
-
}
|
105 |
-
|
106 |
-
|
107 |
-
$collectionObj->innertext = $btn_display;
|
108 |
-
|
109 |
-
$domObj->load($domObj->save());
|
110 |
-
|
111 |
-
return $domObj;
|
112 |
-
|
113 |
-
}
|
114 |
-
|
115 |
-
function save_fields($data, $post)
|
116 |
-
{
|
117 |
-
$blockdata = $this->data;
|
118 |
-
|
119 |
-
$selection = array();
|
120 |
-
|
121 |
-
$button = MB()->getClass("button");
|
122 |
-
|
123 |
-
if (isset($post["sorted"]))
|
124 |
-
{
|
125 |
-
$sorted = array_filter(explode(",",sanitize_text_field($post["sorted"])));
|
126 |
-
$i = 0;
|
127 |
-
foreach($sorted as $button_id)
|
128 |
-
{
|
129 |
-
|
130 |
-
if (intval($button_id) > 0)
|
131 |
-
{
|
132 |
-
$selection[$i] = $button_id;
|
133 |
-
$i++;
|
134 |
-
|
135 |
-
$set_bool = $button->set($button_id);
|
136 |
-
if (! $set_bool) continue; // buttons that don't exist, like virtuals.
|
137 |
-
|
138 |
-
$button_data = $button->get();
|
139 |
-
$collection_id = $this->collection->getID();
|
140 |
-
$collection_meta = isset($button_data["meta"]["in_collections"]) ?
|
141 |
-
$button_data["meta"]["in_collections"] : array();
|
142 |
-
|
143 |
-
if (! is_array($collection_meta))
|
144 |
-
$collection_meta = maybe_unserialize($collection_meta);
|
145 |
-
|
146 |
-
if (is_array($collection_meta))
|
147 |
-
{
|
148 |
-
$key = array_search($collection_id, $collection_meta);
|
149 |
-
if ($key === false)
|
150 |
-
{
|
151 |
-
$collection_meta[] = $collection_id;
|
152 |
-
$button_data["meta"]["in_collections"] = $collection_meta;
|
153 |
-
$button->update($button_data);
|
154 |
-
}
|
155 |
-
}
|
156 |
-
}
|
157 |
-
}
|
158 |
-
}
|
159 |
-
/* If a button id is in the previous selection, but not in the current, maybe the button should be deleted if the
|
160 |
-
button appears to be auto-generated only for this collection */
|
161 |
-
if (isset($post["previous_selection"]))
|
162 |
-
{
|
163 |
-
$previous = array_filter(explode(",",sanitize_text_field($post["previous_selection"])));
|
164 |
-
foreach($previous as $button_id)
|
165 |
-
{
|
166 |
-
if (! in_array($button_id, $selection) && intval($button_id) > 0)
|
167 |
-
$this->collection->maybe_delete_button($button_id);
|
168 |
-
}
|
169 |
-
|
170 |
-
}
|
171 |
-
$data[$this->blockname]["selection"] = $selection;
|
172 |
-
return $data;
|
173 |
-
}
|
174 |
-
|
175 |
-
function admin_fields()
|
176 |
-
{
|
177 |
-
extract($this->data); // admin data
|
178 |
-
$btns = $this->collection->editor_getPacks();
|
179 |
-
?>
|
180 |
-
|
181 |
-
<?php ob_start(); ?>
|
182 |
-
<div id="picker-modal">
|
183 |
-
<div class='picker-packages'>
|
184 |
-
|
185 |
-
<ul>
|
186 |
-
<?php foreach ($btns as $index => $data)
|
187 |
-
{ ?>
|
188 |
-
<li><a href="#" data-pack="<?php echo $index ?>"><?php echo $data["tab"]; ?></a></li>
|
189 |
-
|
190 |
-
<?php } ?>
|
191 |
-
</ul>
|
192 |
-
</div>
|
193 |
-
<div class='picker-main' >
|
194 |
-
</div>
|
195 |
-
<div class='picker-inselection'>
|
196 |
-
<div class='info'>
|
197 |
-
<span class='count'></span> <?php _e("Selected","maxbuttons"); ?>
|
198 |
-
<button type="button" name="clear" class='button-link clear-selection'><?php _e("Clear","maxbuttons"); ?></button>
|
199 |
-
</div>
|
200 |
-
<div class='items'>
|
201 |
-
</div>
|
202 |
-
<div class='add'>
|
203 |
-
<button type="button" name="add-buttons" class="button button-primary"><?php _e("Add selected buttons","maxbuttons"); ?></button>
|
204 |
-
</div>
|
205 |
-
</div>
|
206 |
-
|
207 |
-
|
208 |
-
</div>
|
209 |
-
|
210 |
-
<?php
|
211 |
-
global $mb_pick_modal;
|
212 |
-
$mb_pick_modal = ob_get_contents();
|
213 |
-
|
214 |
-
// print this outside of the main div since it messes with z-index
|
215 |
-
add_action('mb-interface-end', maxUtils::namespaceit('mb_print_modal') );
|
216 |
-
function mb_print_modal()
|
217 |
-
{
|
218 |
-
global $mb_pick_modal;
|
219 |
-
echo $mb_pick_modal;
|
220 |
-
}
|
221 |
-
ob_end_clean();
|
222 |
-
|
223 |
-
?>
|
224 |
-
<div class="mb_tab option-container">
|
225 |
-
<div class="title">
|
226 |
-
<span class="dashicons dashicons-list-view"></span>
|
227 |
-
<span class='title'><?php _e("Buttons", "maxbuttons"); ?></span>
|
228 |
-
<button name="picker_popup" type="button" class="button-primary"><?php _e("Select Social Share Icons","maxbuttons"); ?></button>
|
229 |
-
<span class='right'><button name="save" type="submit" data-form='collection_edit' class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
|
230 |
-
</span>
|
231 |
-
</div>
|
232 |
-
<div class="inside">
|
233 |
-
|
234 |
-
<div class="option preview_collection">
|
235 |
-
<label> <?php _e("Current Selection","maxbuttons"); ?></label>
|
236 |
-
<p><?php _e("Drag the buttons to change the order of your selection. You can remove the button by clicking on the remove icon.",
|
237 |
-
"maxbuttons"); ?>
|
238 |
-
</p>
|
239 |
-
|
240 |
-
|
241 |
-
<div class="mb_collection_selection">
|
242 |
-
<input type="hidden" name="sorted" value="" />
|
243 |
-
<input type="hidden" name="previous_selection" value="" />
|
244 |
-
|
245 |
-
<div class="sortable buttons">
|
246 |
-
|
247 |
-
<?php
|
248 |
-
|
249 |
-
foreach($selection as $button_id)
|
250 |
-
{
|
251 |
-
echo "<div class='shortcode-container item' data-id='$button_id'>";
|
252 |
-
$button = MB()->getClass("button");
|
253 |
-
$button->set($button_id);
|
254 |
-
echo "<div id='maxbutton-$button_id'>";
|
255 |
-
$button->display(array( "load_css" => "inline", 'mode' => 'preview' ));
|
256 |
-
echo "</div>";
|
257 |
-
echo "<div class='button-remove'><span class='dashicons dashicons-no'></span></div>";
|
258 |
-
echo "</div>";
|
259 |
-
}
|
260 |
-
|
261 |
-
?>
|
262 |
-
|
263 |
-
</div>
|
264 |
-
</div>
|
265 |
-
</div> <!-- option -->
|
266 |
-
</div> <!-- inside -->
|
267 |
-
</div> <!-- tab -->
|
268 |
-
|
269 |
-
<?php
|
270 |
-
|
271 |
-
}
|
272 |
-
|
273 |
-
}
|
274 |
-
|
275 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/preview-block.php
DELETED
@@ -1,50 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
$collectionBlock["preview"] = "previewCollectionBlock";
|
5 |
-
|
6 |
-
class previewCollectionBlock extends collectionBlock
|
7 |
-
{
|
8 |
-
protected $blockname = "preview";
|
9 |
-
|
10 |
-
function ajax_update()
|
11 |
-
{
|
12 |
-
|
13 |
-
|
14 |
-
}
|
15 |
-
|
16 |
-
function admin_fields()
|
17 |
-
{
|
18 |
-
|
19 |
-
|
20 |
-
?><div class="mb_tab option-container">
|
21 |
-
<div class="title">
|
22 |
-
<span class="dashicons dashicons-no"></span>
|
23 |
-
<span class="title"><?php _e("Preview","maxbuttons"); ?></span>
|
24 |
-
</div>
|
25 |
-
</div>
|
26 |
-
|
27 |
-
<div class='mb-preview-window output'>
|
28 |
-
<div class="header"><?php _e("Preview", 'maxbuttons'); ?>
|
29 |
-
<span class="close tb-close-icon"></span>
|
30 |
-
</div>
|
31 |
-
<div class="mb-preview-wrapper shortcode-container">
|
32 |
-
|
33 |
-
<?php
|
34 |
-
$args = array(
|
35 |
-
"preview" => true
|
36 |
-
|
37 |
-
);
|
38 |
-
$this->collection->display($args);
|
39 |
-
?>
|
40 |
-
</div>
|
41 |
-
</div>
|
42 |
-
|
43 |
-
<?php
|
44 |
-
|
45 |
-
|
46 |
-
}
|
47 |
-
|
48 |
-
}
|
49 |
-
|
50 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/social-block.php
DELETED
@@ -1,728 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
$collectionBlock["social"] = "socialCollectionBlock";
|
5 |
-
|
6 |
-
use \simple_html_dom as simple_html_dom;
|
7 |
-
|
8 |
-
class socialCollectionBlock extends collectionBlock
|
9 |
-
{
|
10 |
-
protected $blockname = "social";
|
11 |
-
protected $fields = array(
|
12 |
-
"multifields" => array(
|
13 |
-
"id" => "social-option",
|
14 |
-
"fields" => array(
|
15 |
-
"network" => array("default" => "none"),
|
16 |
-
"display_count" => array("default" => 0 ),
|
17 |
-
"count_threshold" => array("default" => 4),
|
18 |
-
"share_url_setting" => array("default" => "auto"),
|
19 |
-
"share_url_custom" => array("default" => ''),
|
20 |
-
"blog_url" => array("default" => ''),
|
21 |
-
|
22 |
-
),
|
23 |
-
),
|
24 |
-
);
|
25 |
-
|
26 |
-
protected $social_data = array();
|
27 |
-
protected $ajax_remote_count = 0; // failback for hanging remote requests in ajax_get_count.
|
28 |
-
|
29 |
-
|
30 |
-
function __construct()
|
31 |
-
{
|
32 |
-
|
33 |
-
require_once( MB()->get_plugin_path() . "/classes/social-networks.php");
|
34 |
-
|
35 |
-
}
|
36 |
-
function parse($domObj, $args)
|
37 |
-
{
|
38 |
-
|
39 |
-
$popup = isset($this->social_data["popup"]) ? $this->social_data["popup"] : array();
|
40 |
-
$onload = isset($this->social_data["onload"]) ? $this->social_data["onload"] : array();
|
41 |
-
|
42 |
-
$collection_items = $domObj->find('.maxcollection .mb-collection-item');
|
43 |
-
$i = 0;
|
44 |
-
|
45 |
-
foreach($collection_items as $item)
|
46 |
-
{
|
47 |
-
//$this_item = $item->find('.maxbutton');
|
48 |
-
$tag = 'data-doc-id';
|
49 |
-
$doc_id = $item->$tag;
|
50 |
-
if (isset($popup[$doc_id]))
|
51 |
-
{
|
52 |
-
$tag = 'data-popup'; // annoying.
|
53 |
-
$json = htmlentities(json_encode($popup[$doc_id]), ENT_QUOTES, 'UTF-8');
|
54 |
-
$item->$tag = $json;
|
55 |
-
|
56 |
-
}
|
57 |
-
if (isset($onload[$doc_id]))
|
58 |
-
{
|
59 |
-
$tag = 'data-onload';
|
60 |
-
$json = htmlentities(json_encode($onload[$doc_id]), ENT_QUOTES, 'UTF-8');
|
61 |
-
$item->$tag = $json;
|
62 |
-
|
63 |
-
}
|
64 |
-
$i++;
|
65 |
-
|
66 |
-
}
|
67 |
-
|
68 |
-
return $domObj;
|
69 |
-
|
70 |
-
}
|
71 |
-
|
72 |
-
function parseButtons($buttons)
|
73 |
-
{
|
74 |
-
$mf_field_id = $this->fields["multifields"]["id"];
|
75 |
-
|
76 |
-
// set social behavoir on the buttons, overriding things
|
77 |
-
foreach($buttons as $index => $button) // index is order of buttons and should be kept like that
|
78 |
-
{
|
79 |
-
$button_id = $button->getID();
|
80 |
-
|
81 |
-
if (isset($this->data[$mf_field_id][$index][$button_id]))
|
82 |
-
{
|
83 |
-
$button_data = $button->get();
|
84 |
-
|
85 |
-
// can happen if button collection button has been deleted.
|
86 |
-
$document_id = isset($button_data["document_id"]) ? $button_data["document_id"] : -1;
|
87 |
-
|
88 |
-
$field_data = $this->data[$mf_field_id][$index][$button_id];
|
89 |
-
|
90 |
-
$network = $field_data["network"];
|
91 |
-
$maxSN = new maxSN($network);
|
92 |
-
$network_name = $maxSN->getNetworkName();
|
93 |
-
|
94 |
-
$display_count = $field_data["display_count"];
|
95 |
-
$count_threshold = $field_data["count_threshold"];
|
96 |
-
|
97 |
-
// collect all variables here for conversion
|
98 |
-
$share_data = $this->getShareData($field_data);
|
99 |
-
$share_url = $share_data["url"];
|
100 |
-
$share_title = isset($share_data["title"]) ? $share_data["title"] : '';
|
101 |
-
$share_img = isset($share_data["img"]) ? $share_data["img"] : '';
|
102 |
-
|
103 |
-
$share_count = 0;
|
104 |
-
|
105 |
-
$apply_vars = array("url" => $share_url,
|
106 |
-
"count" => $share_count,
|
107 |
-
"title" => $share_title,
|
108 |
-
"network_name" => $network_name,
|
109 |
-
"img" => $share_img,
|
110 |
-
);
|
111 |
-
|
112 |
-
$network_url = $maxSN->getShareURL($network);
|
113 |
-
$network_url = $this->applyVars($network_url, $apply_vars);
|
114 |
-
|
115 |
-
|
116 |
-
if ($network_url)
|
117 |
-
{
|
118 |
-
$buttons[$index]->setData("basic",array("url" => $network_url) );
|
119 |
-
|
120 |
-
}
|
121 |
-
|
122 |
-
$count_to_display = '';
|
123 |
-
$text = isset($button_data["text"]["text"]) ? $button_data["text"]["text"] : '' ;
|
124 |
-
$text2 = isset($button_data["text"]["text2"]) ? $button_data["text"]["text2"] : '';
|
125 |
-
|
126 |
-
if ($display_count == 1 && $this->is_supported('display_count', $network) )
|
127 |
-
{
|
128 |
-
$count = $maxSN->getShareCount(array("url" => $share_url,
|
129 |
-
"preview" => $this->is_preview,
|
130 |
-
));
|
131 |
-
|
132 |
-
if ($count === false) // signal for remote check
|
133 |
-
{
|
134 |
-
$this->social_data["onload"][$document_id] = array("network" => $network, "share_url" => esc_url($share_url), "count_threshold" => $count_threshold, "text" => $text, "text2" => $text2 );
|
135 |
-
|
136 |
-
}
|
137 |
-
|
138 |
-
if($count >= $count_threshold )
|
139 |
-
{
|
140 |
-
$count_to_display = $count;
|
141 |
-
|
142 |
-
}
|
143 |
-
}
|
144 |
-
|
145 |
-
// apply_vars. Always run this to get rid of placeholders ( defaults to emtpy )
|
146 |
-
$apply_vars = array("count" => $count_to_display, "network_name" => $network_name);
|
147 |
-
|
148 |
-
$text = $this->applyVars($text, $apply_vars);
|
149 |
-
$text2 = $this->applyVars($text2, $apply_vars);
|
150 |
-
|
151 |
-
$button->setData("text",array("text" => $text, "text2" => $text2) );
|
152 |
-
|
153 |
-
// arrange JS stuff
|
154 |
-
if ($maxSN->checkPopup() )
|
155 |
-
{
|
156 |
-
|
157 |
-
$dimensions = $maxSN->getPopupDimensions(); // ["popup_dimensions"];
|
158 |
-
$this->social_data["popup"][$document_id] = array("width" => $dimensions[0],
|
159 |
-
"height" => $dimensions[1],
|
160 |
-
);
|
161 |
-
}
|
162 |
-
|
163 |
-
|
164 |
-
} // isset button data
|
165 |
-
|
166 |
-
}
|
167 |
-
|
168 |
-
return $buttons;
|
169 |
-
|
170 |
-
}
|
171 |
-
|
172 |
-
function getShareData($data)
|
173 |
-
{
|
174 |
-
$share_setting = $data["share_url_setting"];
|
175 |
-
$custom = $data["share_url_custom"];
|
176 |
-
|
177 |
-
$url = '';
|
178 |
-
$title = '';
|
179 |
-
$img = '';
|
180 |
-
|
181 |
-
$basic = $this->collection->getBlock("basic");
|
182 |
-
$place_data = $basic->get();
|
183 |
-
$placement = $place_data["placement"];
|
184 |
-
|
185 |
-
switch($share_setting)
|
186 |
-
{
|
187 |
-
case "home":
|
188 |
-
$url = get_home_url();
|
189 |
-
$title = get_bloginfo('name');
|
190 |
-
$img = $this->getImage(null, true);
|
191 |
-
break;
|
192 |
-
case "custom-url";
|
193 |
-
$url = $custom;
|
194 |
-
$img = $this->getImage();
|
195 |
-
break;
|
196 |
-
case "current-post":
|
197 |
-
$url = get_permalink();
|
198 |
-
$title = get_the_title();
|
199 |
-
$img = $this->getImage();
|
200 |
-
break;
|
201 |
-
case "auto":
|
202 |
-
default:
|
203 |
-
|
204 |
-
|
205 |
-
/* After / before being placed on the post data, therefore by default (auto) always use the POST URL
|
206 |
-
Static is being placed once(1) on the page, so get the greated to-share url ( of the whole section ) */
|
207 |
-
|
208 |
-
switch($placement)
|
209 |
-
{
|
210 |
-
case "before":
|
211 |
-
case "after":
|
212 |
-
case "after-before":
|
213 |
-
$url = get_permalink();
|
214 |
-
$title = get_the_title();
|
215 |
-
$img = $this->getImage();
|
216 |
-
break;
|
217 |
-
case "static-left":
|
218 |
-
case "static-right":
|
219 |
-
case "static-top":
|
220 |
-
case "static-bottom":
|
221 |
-
if (is_front_page())
|
222 |
-
{
|
223 |
-
$url = get_home_url();
|
224 |
-
$title = get_bloginfo('name');
|
225 |
-
$img = $this->getImage(null, true);
|
226 |
-
}
|
227 |
-
else // are there any other cases? Page / Archive should give back their main url like this.
|
228 |
-
{
|
229 |
-
$url = get_permalink();
|
230 |
-
$title = get_the_title();
|
231 |
-
$img = $this->getImage();
|
232 |
-
}
|
233 |
-
break;
|
234 |
-
|
235 |
-
|
236 |
-
} // switch
|
237 |
-
|
238 |
-
break;
|
239 |
-
}
|
240 |
-
$data = array("url" => $url,
|
241 |
-
"title" => $title,
|
242 |
-
"img" => $img);
|
243 |
-
return $data;
|
244 |
-
|
245 |
-
}
|
246 |
-
|
247 |
-
function getImage($post_id = null, $home = false)
|
248 |
-
{
|
249 |
-
if (is_admin())
|
250 |
-
return ''; // in admin all this is not set.
|
251 |
-
|
252 |
-
if ($home && get_option('show_on_front') === 'page')
|
253 |
-
{
|
254 |
-
$post_id = get_option('page_on_front');
|
255 |
-
|
256 |
-
}
|
257 |
-
|
258 |
-
$thumb_id = get_post_thumbnail_id($post_id); // First try to find thumbnail on the content
|
259 |
-
|
260 |
-
$image = false;
|
261 |
-
if (is_numeric($thumb_id))
|
262 |
-
{
|
263 |
-
$image = wp_get_attachment_url($thumb_id);
|
264 |
-
}
|
265 |
-
|
266 |
-
if ($image !== false)
|
267 |
-
return $image;
|
268 |
-
|
269 |
-
// In case of no thumbnails, tries to find first image from current content.
|
270 |
-
|
271 |
-
// if (! is_null($post_id))
|
272 |
-
// {
|
273 |
-
$post = get_post($post_id);
|
274 |
-
$content = '';
|
275 |
-
if (! is_null($post))
|
276 |
-
$content = $post->post_content;
|
277 |
-
/* }
|
278 |
-
else
|
279 |
-
{
|
280 |
-
|
281 |
-
$content = get_the_content();
|
282 |
-
} */
|
283 |
-
$domObj = new simple_html_dom();
|
284 |
-
$domObj->load($content);
|
285 |
-
|
286 |
-
$img = $domObj->find('img', 0);
|
287 |
-
if ($img)
|
288 |
-
{
|
289 |
-
$image = $img->src;
|
290 |
-
return $image;
|
291 |
-
}
|
292 |
-
else
|
293 |
-
return '';
|
294 |
-
}
|
295 |
-
|
296 |
-
function applyVars($string, $vars)
|
297 |
-
{
|
298 |
-
|
299 |
-
if (isset($vars["url"]))
|
300 |
-
$string = str_replace("{url}", urlencode(esc_url($vars["url"])), $string);
|
301 |
-
if (isset($vars["count"]))
|
302 |
-
{
|
303 |
-
$count = $this->formatCount($vars["count"]);
|
304 |
-
$string = str_replace("{count}", "<span class='share_count'>" . $count . "</span>", $string);
|
305 |
-
$string = str_replace("{c}", "<span class='share_count'>" . $count . "</span>", $string);
|
306 |
-
}
|
307 |
-
if (isset($vars["title"]))
|
308 |
-
$string = str_replace("{title}", $vars["title"], $string);
|
309 |
-
if (isset($vars["network_name"]))
|
310 |
-
$string = str_replace("{network_name}", $vars["network_name"], $string);
|
311 |
-
|
312 |
-
if (isset($vars["img"]))
|
313 |
-
$string = str_replace("{img}", $vars["img"], $string);
|
314 |
-
|
315 |
-
return $string;
|
316 |
-
}
|
317 |
-
|
318 |
-
protected function formatCount($raw_count)
|
319 |
-
{
|
320 |
-
$count = $raw_count;
|
321 |
-
if ($count > 1000)
|
322 |
-
{
|
323 |
-
$count = round(($count/1000), 1). 'K';
|
324 |
-
}
|
325 |
-
$count = apply_filters("mb-collection-count-format", $count, $raw_count);
|
326 |
-
return $count;
|
327 |
-
}
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
// function to get specifics on network like where to get count / where to sent people etc.
|
332 |
-
|
333 |
-
|
334 |
-
function save_fields($data, $post)
|
335 |
-
{
|
336 |
-
|
337 |
-
$data = parent::save_fields($data, $post);
|
338 |
-
|
339 |
-
|
340 |
-
$picker = $this->collection->getBlock("picker");
|
341 |
-
if ($picker)
|
342 |
-
{
|
343 |
-
|
344 |
-
$picker_data = $picker->get();
|
345 |
-
$selection = $picker_data["selection"];
|
346 |
-
|
347 |
-
}
|
348 |
-
|
349 |
-
$mf_field_id = $this->fields["multifields"]["id"];
|
350 |
-
|
351 |
-
return $data;
|
352 |
-
}
|
353 |
-
|
354 |
-
function ajax_new_button($result, $data)
|
355 |
-
{
|
356 |
-
ob_start();
|
357 |
-
$button_array = json_decode(base64_decode($data["data"]), true);
|
358 |
-
$button_id = $data["button_id"];
|
359 |
-
$index = isset($data["index"]) ? intval($data["index"]) : 0;
|
360 |
-
|
361 |
-
$data = array();
|
362 |
-
$data["index"] = $index;
|
363 |
-
|
364 |
-
$fields = $this->fields["multifields"]["fields"];
|
365 |
-
|
366 |
-
if (isset($button_array["collection"]["social"]))
|
367 |
-
{ $social_data = $button_array["collection"]["social"]; // removed array filter since it removes zero's as well..
|
368 |
-
|
369 |
-
}
|
370 |
-
else
|
371 |
-
$social_data = array();
|
372 |
-
|
373 |
-
|
374 |
-
foreach($fields as $field => $options)
|
375 |
-
{
|
376 |
-
if (isset($social_data[$field]))
|
377 |
-
$data[$field] = $social_data[$field];
|
378 |
-
else
|
379 |
-
$data[$field] = (isset($options["default"])) ? $options["default"] : '';
|
380 |
-
}
|
381 |
-
|
382 |
-
|
383 |
-
$this->init_admin_arrays();
|
384 |
-
$this->do_social_option($button_id, $data, $button_array ) ;
|
385 |
-
|
386 |
-
$output = ob_get_contents();
|
387 |
-
ob_end_clean();
|
388 |
-
|
389 |
-
$result["body"] = $output;
|
390 |
-
return $result;
|
391 |
-
|
392 |
-
}
|
393 |
-
|
394 |
-
function ajax_get_count($result, $data)
|
395 |
-
{
|
396 |
-
|
397 |
-
$network = (isset($data["network"])) ? sanitize_text_field($data["network"]) : '';
|
398 |
-
$share_url = (isset($data["share_url"])) ? sanitize_text_field($data["share_url"]) : '';
|
399 |
-
|
400 |
-
if ($network == '')
|
401 |
-
return $result;
|
402 |
-
|
403 |
-
// init network
|
404 |
-
$maxSN = new maxSN($network);
|
405 |
-
|
406 |
-
// check if share count appeared in the cache. If this is the case it's possible another process put it there.
|
407 |
-
$do_remote = true;
|
408 |
-
$share_count = $maxSN->getShareCount(array("url" => $share_url));
|
409 |
-
if ($share_count !== false)
|
410 |
-
{
|
411 |
-
$count = $share_count;
|
412 |
-
$do_remote = false; // stop annoying other servers
|
413 |
-
}
|
414 |
-
|
415 |
-
if ($do_remote)
|
416 |
-
{
|
417 |
-
// returns false, a number or 'locked' in case of locked.
|
418 |
-
$count = $maxSN->getRemoteShareCount($share_url);
|
419 |
-
|
420 |
-
/* If the request is lock, another request is probably asking for this and shouldn't take long.
|
421 |
-
Try a maximum of 5 times to prevent server process hanging until php times out ( we want to prevent that ) */
|
422 |
-
if ($count == 'locked')
|
423 |
-
{
|
424 |
-
if ($this->ajax_remote_count < 5)
|
425 |
-
{
|
426 |
-
sleep(1); // in seconds please.
|
427 |
-
// after retry result here will at some point have the count data, extract and return at the end.
|
428 |
-
$result = $this->ajax_get_count($result,$data);
|
429 |
-
$count = $result["data"]["count"];
|
430 |
-
}
|
431 |
-
else
|
432 |
-
$count = "TIMEOUT";
|
433 |
-
$this->ajax_remote_count++;
|
434 |
-
}
|
435 |
-
}
|
436 |
-
|
437 |
-
$result["data"] = array('count' => intval($count) );
|
438 |
-
|
439 |
-
return $result;
|
440 |
-
}
|
441 |
-
|
442 |
-
function init_admin_arrays()
|
443 |
-
{
|
444 |
-
|
445 |
-
global $supported_networks, $share_url_settings;
|
446 |
-
|
447 |
-
$supported_networks = maxSN::getSupportedNetworks();
|
448 |
-
|
449 |
-
|
450 |
-
$share_url_settings = array(
|
451 |
-
"auto" => __("Auto","maxbuttons"),
|
452 |
-
"current-post" => __("Current post or page","maxbuttons"),
|
453 |
-
"custom-url" => __("Custom URL","maxbuttons"),
|
454 |
-
"home" => __("Homepage URL","maxbuttons"),
|
455 |
-
);
|
456 |
-
|
457 |
-
}
|
458 |
-
|
459 |
-
/* These two functions to be merged / or do_supports should use this - next rework */
|
460 |
-
function is_supported ($field_type, $network)
|
461 |
-
{
|
462 |
-
switch ($field_type)
|
463 |
-
{
|
464 |
-
case "display_count":
|
465 |
-
case "count_threshold":
|
466 |
-
$networks = array("facebook","google-plus","linkedin","pinterest","reddit","stumbleupon","vkontakte");
|
467 |
-
break;
|
468 |
-
case "share_url_setting":
|
469 |
-
$networks = array_keys($supported_networks);
|
470 |
-
// unset exceptions
|
471 |
-
$networks = array_values(array_diff($networks, array("bloglovin", "none") ));
|
472 |
-
break;
|
473 |
-
case "blog_url":
|
474 |
-
$networks = array('bloglovin');
|
475 |
-
break;
|
476 |
-
}
|
477 |
-
|
478 |
-
if (in_array($network, $networks))
|
479 |
-
{
|
480 |
-
return true;
|
481 |
-
}
|
482 |
-
return false;
|
483 |
-
}
|
484 |
-
|
485 |
-
function do_supports($field, $button_id, $index)
|
486 |
-
{
|
487 |
-
|
488 |
-
global $supported_networks;
|
489 |
-
|
490 |
-
$basic_supports = array("share_url_setting", "share_url_custom"); // conditionals interface
|
491 |
-
$share_supports = array("display_count", "count_threshold");
|
492 |
-
|
493 |
-
$networks = array();
|
494 |
-
|
495 |
-
switch ($field)
|
496 |
-
{
|
497 |
-
case "display_count":
|
498 |
-
case "count_threshold":
|
499 |
-
$networks = array("facebook","google-plus","linkedin","pinterest","reddit","stumbleupon","vkontakte");
|
500 |
-
break;
|
501 |
-
|
502 |
-
case "share_url_setting":
|
503 |
-
//case "share_url_custom":
|
504 |
-
$networks = array_keys($supported_networks);
|
505 |
-
// unset exceptions
|
506 |
-
$networks = array_values(array_diff($networks, array("bloglovin", "none") ));
|
507 |
-
|
508 |
-
break;
|
509 |
-
|
510 |
-
case "blog_url":
|
511 |
-
$networks = array('bloglovin');
|
512 |
-
break;
|
513 |
-
|
514 |
-
}
|
515 |
-
|
516 |
-
$conditional = htmlentities(json_encode(array("target" => "network-$button_id-$index", "values" => $networks)));
|
517 |
-
return $conditional;
|
518 |
-
|
519 |
-
|
520 |
-
}
|
521 |
-
|
522 |
-
public function map_fields($map)
|
523 |
-
{
|
524 |
-
$map = parent::map_fields($map);
|
525 |
-
$map["network"]["func"] = "parseTags";
|
526 |
-
$map["display_count"]["func"] = "parseTags";
|
527 |
-
|
528 |
-
|
529 |
-
return $map;
|
530 |
-
}
|
531 |
-
|
532 |
-
function admin_fields()
|
533 |
-
{
|
534 |
-
|
535 |
-
$picker = $this->collection->getBlock("picker");
|
536 |
-
if ($picker)
|
537 |
-
{
|
538 |
-
|
539 |
-
$picker_data = $picker->get();
|
540 |
-
$selection = $picker_data["selection"];
|
541 |
-
|
542 |
-
}
|
543 |
-
|
544 |
-
$this->init_admin_arrays();
|
545 |
-
|
546 |
-
|
547 |
-
$mf_field_id = $this->fields["multifields"]["id"];
|
548 |
-
$mf_fields = $this->fields["multifields"]["fields"];
|
549 |
-
|
550 |
-
?><div class="mb_tab social_block option-container" data-options="social">
|
551 |
-
<div class="title">
|
552 |
-
<span class='dashicons dashicons-share'> </span>
|
553 |
-
<span class="title"><?php _e("Social options", "maxbuttons"); ?></span>
|
554 |
-
<span class='manual-box'><a class='manual-toggle' href='javascript:void(0)' data-target="social"> <?php _e("Getting Started","maxbuttons-pro"); ?> </a></span>
|
555 |
-
<span class='right'><button name="save" data-form='collection_edit' type="submit" class="button button-primary"><?php _e("Save All","maxbuttons"); ?></button>
|
556 |
-
</span>
|
557 |
-
</div>
|
558 |
-
<div class="inside">
|
559 |
-
<?php
|
560 |
-
|
561 |
-
$defaults = array();
|
562 |
-
foreach($mf_fields as $mf_field => $options)
|
563 |
-
{
|
564 |
-
$defaults[$mf_field] = isset($options["default"]) ? $options["default"] : "";
|
565 |
-
}
|
566 |
-
|
567 |
-
$buttondata = isset($this->data[$mf_field_id]) ? $this->data[$mf_field_id] : array();
|
568 |
-
|
569 |
-
foreach($selection as $index => $button_id)
|
570 |
-
{
|
571 |
-
$mf_data = array();
|
572 |
-
$mf_data = $defaults; // defauls until found
|
573 |
-
|
574 |
-
//foreach($this->data[$mf_field_id] as $b_index => $buttondata)
|
575 |
-
//{
|
576 |
-
|
577 |
-
|
578 |
-
if (isset($buttondata[$index][$button_id]))
|
579 |
-
{
|
580 |
-
|
581 |
-
$mf_data = $buttondata[$index][$button_id];
|
582 |
-
|
583 |
-
|
584 |
-
}
|
585 |
-
|
586 |
-
//}
|
587 |
-
$mf_data["index"] = $index;
|
588 |
-
$this->do_social_option($button_id, $mf_data);
|
589 |
-
|
590 |
-
}
|
591 |
-
|
592 |
-
?>
|
593 |
-
|
594 |
-
<?php if (count($selection) == 0) // no buttons
|
595 |
-
{
|
596 |
-
?>
|
597 |
-
<p class='no-buttons'><?php _e("No buttons selected yet. Please select some buttons first.","maxbuttons"); ?></p>
|
598 |
-
|
599 |
-
<?php
|
600 |
-
|
601 |
-
}
|
602 |
-
?>
|
603 |
-
</div>
|
604 |
-
</div> <!-- option container -->
|
605 |
-
|
606 |
-
|
607 |
-
<!-- manual entry -->
|
608 |
-
<div class="manual-entry" data-manual="social">
|
609 |
-
<h3><?php _e("Social settings", "maxbuttons"); ?>
|
610 |
-
<span class="dashicons dashicons-no window close manual-toggle" data-target="social"></span>
|
611 |
-
</h3>
|
612 |
-
|
613 |
-
<p><?php _e("For each button you have selected pick the Social Media network that corresponds to the icon. For each Social Sharing button you can choose to use the current page, the your homepage URL or a custom URL.","maxbuttons"); ?></p>
|
614 |
-
|
615 |
-
</div>
|
616 |
-
|
617 |
-
<?php
|
618 |
-
}
|
619 |
-
|
620 |
-
function do_social_option($button_id, $data, $button_array = array() )
|
621 |
-
{
|
622 |
-
|
623 |
-
global $supported_networks, $share_url_settings;
|
624 |
-
|
625 |
-
//$data = array_filter($data); // packs from xml can give back empty arrays if value is not set ( attribute of pack handler ).
|
626 |
-
|
627 |
-
$defaults = $this->fields['multifields']['fields']; // array filter removes empty fields, set to defaults.
|
628 |
-
|
629 |
-
// array filter doesn't work since vars need to be set, or be able to have zero. Put to default if array ( xml import )
|
630 |
-
$network = is_array($data['network']) ? $defaults['network']['default'] : $data['network'];
|
631 |
-
$display_count = is_array($data['display_count']) ? $defaults['display_count']['default'] : $data['display_count'];
|
632 |
-
$count_threshold = is_array($data['count_threshold']) ? $defaults['count_threshold']['default'] : $data['count_threshold'];
|
633 |
-
$share_url_setting = is_array($data['share_url_setting']) ? $defaults['share_url_setting']['default'] : $data['share_url_setting'];
|
634 |
-
$share_url_custom = is_array($data['share_url_custom']) ? $defaults['share_url_custom']['default'] : $data['share_url_custom'];
|
635 |
-
$blog_url = is_array($data['blog_url']) ? $defaults['blog_url']['default'] : $data['blog_url'];
|
636 |
-
|
637 |
-
//extract($data);
|
638 |
-
|
639 |
-
$index = isset($data["index"]) ? $data["index"] : 0;
|
640 |
-
|
641 |
-
$button = MB()->getClass("button");
|
642 |
-
|
643 |
-
if ($button_id > 0 && (! isset($button_array["meta"]) || ! $button_array["meta"]["is_virtual"]) )
|
644 |
-
{
|
645 |
-
$button->set($button_id);
|
646 |
-
}
|
647 |
-
elseif (count($button_array) > 0)
|
648 |
-
{
|
649 |
-
$button_array["name"] = $button_array["basic"]["name"];
|
650 |
-
$button_array["status"] = $button_array["basic"]["status"];
|
651 |
-
$button->clear();
|
652 |
-
maxButtons::buttonLoad(array("button_id" => $button_id)); // central registration - from button
|
653 |
-
$button->setupData($button_array);
|
654 |
-
}
|
655 |
-
|
656 |
-
$document_id = $button->getDocumentID();
|
657 |
-
|
658 |
-
|
659 |
-
?>
|
660 |
-
<div class="social-option" data-id="<?php echo $button_id ?>" data-document_id="<?php echo $document_id ?>">
|
661 |
-
<input type="hidden" name="social-option[]" value="<?php echo $button_id ?>" />
|
662 |
-
<div class="option">
|
663 |
-
<div class="shortcode-container">
|
664 |
-
<?php
|
665 |
-
|
666 |
-
|
667 |
-
$button->display(array("mode" => "preview"));
|
668 |
-
|
669 |
-
?>
|
670 |
-
|
671 |
-
</div>
|
672 |
-
<span class="button_name"><?php echo $button->getName(); ?></span>
|
673 |
-
</div>
|
674 |
-
|
675 |
-
|
676 |
-
<div class="option ">
|
677 |
-
<label><?php _e("Sharing network","maxbuttons"); ?></label>
|
678 |
-
<?php echo maxUtils::selectify("network-$button_id-$index",$supported_networks, $network, 'network'); ?>
|
679 |
-
|
680 |
-
</div>
|
681 |
-
|
682 |
-
<div class="option conditional-option" data-show="<?php echo $this->do_supports('display_count', $button_id, $index); ?>">
|
683 |
-
<label><?php _e("Show Share Counts","maxbuttons"); ?></label>
|
684 |
-
<input type="checkbox" name="display_count-<?php echo $button_id ?>-<?php echo $index ?>" value="1" <?php checked($display_count, 1); ?> />
|
685 |
-
</div>
|
686 |
-
|
687 |
-
<div class="option conditional-option" data-show="<?php echo $this->do_supports('count_threshold', $button_id, $index); ?>">
|
688 |
-
<label><?php _e("Minimum share count","maxbuttons"); ?></label>
|
689 |
-
<input type="number" class="tiny" name="count_threshold-<?php echo $button_id ?>-<?php echo $index ?>" min="0"
|
690 |
-
value="<?php echo intval($count_threshold) ?>" />
|
691 |
-
</div>
|
692 |
-
|
693 |
-
<div class="option conditional-option" data-show="<?php echo $this->do_supports('share_url_setting', $button_id, $index); ?>">
|
694 |
-
<label><?php _e("Share URL settings","maxbuttons"); ?></label>
|
695 |
-
<?php echo maxUtils::selectify("share_url_setting-$button_id-$index", $share_url_settings, $share_url_setting); ?>
|
696 |
-
|
697 |
-
|
698 |
-
<div class="help fa fa-question-circle ">
|
699 |
-
<span><?php _e("Which URL (link) is to be shared. Auto will share the current page on pages, and the full site URL on the homepage", "maxbuttons"); ?>
|
700 |
-
</span>
|
701 |
-
</div>
|
702 |
-
|
703 |
-
</div>
|
704 |
-
|
705 |
-
<!-- bloglovin -->
|
706 |
-
<div class="option conditional-option" data-show="<?php echo $this->do_supports('blog_url', $button_id, $index); ?>">
|
707 |
-
<label><?php _e("Bloglovin' Blog URL","maxbuttons"); ?></label>
|
708 |
-
<input type="text" name="blog_url-<?php echo $button_id ?>-<?php echo $index ?>"
|
709 |
-
value="<?php echo esc_attr($blog_url) ?>">
|
710 |
-
</div>
|
711 |
-
|
712 |
-
<?php $condition = array("target" => "share_url_setting-$button_id-$index", "values" => array("custom-url")) ;
|
713 |
-
$custom_conditional = htmlentities(json_encode($condition ));
|
714 |
-
?>
|
715 |
-
|
716 |
-
|
717 |
-
<div class="option conditional-option" data-show="<?php echo $custom_conditional ?>">
|
718 |
-
<label><?php _e("Custom URL","maxbuttons"); ?></label>
|
719 |
-
<input type="text" name="share_url_custom-<?php echo $button_id ?>-<?php echo $index ?>"
|
720 |
-
value="<?php echo esc_attr($share_url_custom) ?>">
|
721 |
-
|
722 |
-
</div>
|
723 |
-
</div> <!-- social option -->
|
724 |
-
<?php
|
725 |
-
}
|
726 |
-
}
|
727 |
-
|
728 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
collections/social-collection.php
DELETED
@@ -1,227 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
namespace MaxButtons;
|
3 |
-
defined('ABSPATH') or die('No direct access permitted');
|
4 |
-
$collectionClass["social"] = "socialCollection";
|
5 |
-
|
6 |
-
class socialCollection extends maxCollection
|
7 |
-
{
|
8 |
-
protected $collection_type = "social";
|
9 |
-
protected $uses_blocks = array("picker", "basic","layout", "social","preview", "export");
|
10 |
-
|
11 |
-
public function __construct()
|
12 |
-
{
|
13 |
-
parent::__construct();
|
14 |
-
add_filter("mb_col_save_collection_data", array($this,"save_collection"), 10, 2 );
|
15 |
-
|
16 |
-
}
|
17 |
-
|
18 |
-
// check if button is real button , or insert if not.
|
19 |
-
public function save_collection($data, $post)
|
20 |
-
{
|
21 |
-
|
22 |
-
$selection = $data["picker"]["selection"];
|
23 |
-
$pack_buttons = false;
|
24 |
-
|
25 |
-
foreach($selection as $index => $button_id)
|
26 |
-
{
|
27 |
-
|
28 |
-
if (isset($post["button-data-$button_id"]))
|
29 |
-
{
|
30 |
-
$post_data = json_decode(base64_decode($post["button-data-$button_id"]), true);
|
31 |
-
|
32 |
-
// check if real = false is set - this is a button from a pack.
|
33 |
-
if (isset($post_data["meta"]["is_virtual"]) && $post_data["meta"]["is_virtual"] == true)
|
34 |
-
{
|
35 |
-
$pack_buttons = true; // after dealing with virtual button id's, reload is needed
|
36 |
-
|
37 |
-
// if so, save button
|
38 |
-
$user = wp_get_current_user();
|
39 |
-
|
40 |
-
$button = MB()->getClass("button");
|
41 |
-
$button->clear();
|
42 |
-
|
43 |
-
$post_data["name"] = $post_data["basic"]["name"];
|
44 |
-
$post_data["status"] = $post_data["basic"]["status"];
|
45 |
-
|
46 |
-
// set the proper meta's and user edited = false;
|
47 |
-
$post_data["meta"]["is_virtual"] = false; // off to the real world
|
48 |
-
$post_data["meta"]["user_edited"] = false;
|
49 |
-
$post_data["meta"]["created"] = time();
|
50 |
-
$post_data["meta"]["user_created"] = $user->user_login;
|
51 |
-
$post_data["meta"]["in_collections"] = array($this->collection_id);
|
52 |
-
$post_data["id"] = 0; // new button
|
53 |
-
|
54 |
-
$button->setupData($post_data);
|
55 |
-
|
56 |
-
$new_button_id = $button->update($post_data);
|
57 |
-
|
58 |
-
// save a reference to collection.
|
59 |
-
$data["picker"]["selection"][$index] = $new_button_id;
|
60 |
-
|
61 |
-
// update social options to new button id
|
62 |
-
$social = $data["social"];
|
63 |
-
|
64 |
-
|
65 |
-
foreach($social as $option => $options) // social-option - data
|
66 |
-
{
|
67 |
-
foreach($options as $index => $option_data) // index (count) - data
|
68 |
-
{
|
69 |
-
foreach($option_data as $option_id => $opt_data) // button_id - data
|
70 |
-
{
|
71 |
-
//echo $option_id . " - $button_id (OPT / BUTT)<BR>";
|
72 |
-
if ($option_id == $button_id)
|
73 |
-
{
|
74 |
-
$social["social-option"][$index][$new_button_id] = $opt_data;
|
75 |
-
unset($social["social-option"][$index][$button_id]);
|
76 |
-
|
77 |
-
|
78 |
-
}
|
79 |
-
}
|
80 |
-
}
|
81 |
-
}
|
82 |
-
|
83 |
-
$data["social"] = $social;
|
84 |
-
}
|
85 |
-
}
|
86 |
-
}
|
87 |
-
|
88 |
-
if ($pack_buttons)
|
89 |
-
{
|
90 |
-
add_filter("collections_ajax_force_reload", function () { return true; });
|
91 |
-
|
92 |
-
}
|
93 |
-
|
94 |
-
return $data;
|
95 |
-
|
96 |
-
// return $this->collection_id;
|
97 |
-
//exit();
|
98 |
-
}
|
99 |
-
|
100 |
-
function editor_getPacks()
|
101 |
-
{
|
102 |
-
$packs = parent::editor_getPacks();
|
103 |
-
|
104 |
-
// Collect packs from dynamic amount of dirs
|
105 |
-
$path = MB()->get_plugin_path() . "assets/packs/" ;
|
106 |
-
$packs = array_merge($this->getSocialPacks($path), $packs );
|
107 |
-
return $packs;
|
108 |
-
|
109 |
-
}
|
110 |
-
|
111 |
-
function getSocialPacks($path)
|
112 |
-
{
|
113 |
-
if (! is_dir($path))
|
114 |
-
{
|
115 |
-
MB()->add_notice("error", "Could not load asset packs");
|
116 |
-
return;
|
117 |
-
}
|
118 |
-
$dirhandle = opendir($path);
|
119 |
-
$found_packs = array();
|
120 |
-
while (false !== ($name = readdir($dirhandle))) {
|
121 |
-
if ($name != '.' && $name != '..')
|
122 |
-
{
|
123 |
-
$found_packs[] = $name;
|
124 |
-
}
|
125 |
-
}
|
126 |
-
|
127 |
-
sort($found_packs);
|
128 |
-
|
129 |
-
foreach($found_packs as $pack)
|
130 |
-
{
|
131 |
-
$packsClass = MB()->getClass("pack");
|
132 |
-
|
133 |
-
$socialpack = array("file" => $path . $pack . "/" . $pack . ".xml",
|
134 |
-
"img" => '',
|
135 |
-
"dir" => '',
|
136 |
-
"is_local" => true,
|
137 |
-
);
|
138 |
-
$result = $packsClass->load_pack($socialpack);
|
139 |
-
if(! $result) // failed.
|
140 |
-
{
|
141 |
-
continue;
|
142 |
-
}
|
143 |
-
$packs[$pack]['tab'] = $packsClass->getName();
|
144 |
-
$packs[$pack]["func"] = array($this, 'editor_getSocialButtons');
|
145 |
-
$packs[$pack]["rel"] = "assets/packs/";
|
146 |
-
$packs[$pack]["path"] = $path . $pack;
|
147 |
-
|
148 |
-
|
149 |
-
}
|
150 |
-
return $packs;
|
151 |
-
}
|
152 |
-
|
153 |
-
/* public function editor_getButtons()
|
154 |
-
{
|
155 |
-
$buttons = parent::editor_getButtons();
|
156 |
-
|
157 |
-
$buttons = $this->editor_getSocialButtons($buttons);
|
158 |
-
|
159 |
-
return $buttons;
|
160 |
-
} */
|
161 |
-
|
162 |
-
protected function editor_getSocialButtons($packname, $data = array() )
|
163 |
-
{
|
164 |
-
$buttons = array();
|
165 |
-
|
166 |
-
$packsClass = MB()->getClass("pack");
|
167 |
-
|
168 |
-
$packs = $this->editor_getPacks();
|
169 |
-
$data = $packs[$packname];
|
170 |
-
|
171 |
-
|
172 |
-
//$packName = isset($data["tab"]) ? $data["tab"] : '';
|
173 |
-
$packpath = $data["path"]; // isset($data["rel"]) ? $data["rel"] : '';
|
174 |
-
$plugin_path = MB()->get_plugin_path(true);
|
175 |
-
$rel = str_replace($plugin_path,'',$packpath);
|
176 |
-
|
177 |
-
|
178 |
-
$socialpath = MB()->get_plugin_path(true) . $rel . "/";
|
179 |
-
$socialurl = MB()->get_plugin_url(true) . $rel . "/";
|
180 |
-
|
181 |
-
$socialpack = array("file" => $socialpath . "$packname.xml",
|
182 |
-
"img" => '',
|
183 |
-
"dir" => $socialurl,
|
184 |
-
"is_local" => true,
|
185 |
-
);
|
186 |
-
|
187 |
-
|
188 |
-
$packsClass->setPackPath($socialurl);
|
189 |
-
$packsClass->load_pack($socialpack);
|
190 |
-
$xml = $packsClass->getPackXML();
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
foreach( $xml->maxbutton as $xmlbutton)
|
195 |
-
{
|
196 |
-
|
197 |
-
$button_array = $packsClass->parse_pack_button($xmlbutton);
|
198 |
-
|
199 |
-
$button = MB()->getClass('button');
|
200 |
-
$button->clear(); // also ensures all fields are loaded
|
201 |
-
|
202 |
-
$meta = array("is_virtual" => true, // not a real button
|
203 |
-
"created_source" => "collection");
|
204 |
-
$button_array["meta"]= json_encode($meta);
|
205 |
-
|
206 |
-
$button->setupData($button_array);
|
207 |
-
|
208 |
-
|
209 |
-
if (isset($button_array["collection"]))
|
210 |
-
{
|
211 |
-
$coldata = $button_array["collection"];
|
212 |
-
|
213 |
-
// overloading the class to retrieve collection data later on social-block at adding time.
|
214 |
-
$button->setData("collection", $coldata);
|
215 |
-
|
216 |
-
}
|
217 |
-
|
218 |
-
$buttons[] = $button;
|
219 |
-
|
220 |
-
}
|
221 |
-
return $buttons;
|
222 |
-
}
|
223 |
-
|
224 |
-
}
|
225 |
-
|
226 |
-
|
227 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
includes/maxbuttons-admin-helper.php
CHANGED
@@ -297,36 +297,7 @@ class maxAdmin
|
|
297 |
}
|
298 |
}
|
299 |
|
300 |
-
|
301 |
-
static function formResponseModals()
|
302 |
-
{
|
303 |
-
return false;
|
304 |
-
?>
|
305 |
-
<div class='form_modal_wrapper'>
|
306 |
-
<a href='#mb-formresponse' rel='leanModal' class='show_response_modal'></a>
|
307 |
-
<div id='mb-formresponse' class='max-modal'>
|
308 |
-
|
309 |
-
<div class="content-area">
|
310 |
-
<div class="modal_header">
|
311 |
-
<h3 class='title'></h3>
|
312 |
-
<div id="modal_close" class="modal_close tb-close-icon"></div>
|
313 |
-
</div>
|
314 |
-
<p class='content'> </p>
|
315 |
-
</div>
|
316 |
-
<div class='controls'>
|
317 |
-
<div class='ok'>
|
318 |
-
<input type="button" name="#" onClick="javascript:document.getElementById('modal_close').click();" class="button-primary" value="<?Php _e("OK", "maxbuttons-pro"); ?>">
|
319 |
-
</div>
|
320 |
-
<div class='yesno'>
|
321 |
-
<input type='button' class="button-primary yes" name='#' value="<?php _e("Yes","maxbuttons-pro"); ?>">
|
322 |
-
<input type="button" class="button-primary no" name='#' value="<?php _e("No","maxbuttons-pro"); ?>" onClick="javascript:document.getElementById('modal_close').click();">
|
323 |
-
</div>
|
324 |
-
</div>
|
325 |
-
</div>
|
326 |
-
</div>
|
327 |
-
<?php
|
328 |
-
|
329 |
-
}
|
330 |
|
331 |
public static function displayCollectionWelcome()
|
332 |
{
|
297 |
}
|
298 |
}
|
299 |
|
300 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
public static function displayCollectionWelcome()
|
303 |
{
|
includes/maxbuttons-list.php
CHANGED
@@ -259,7 +259,7 @@ $mbadmin->get_header(array("title" => $page_title, "title_action" => $action));
|
|
259 |
else
|
260 |
$button->set($id);
|
261 |
|
262 |
-
|
263 |
?>
|
264 |
<div class='button-row'>
|
265 |
<span class="col col_check"><input type="checkbox" name="button-id[]" id="button-id-<?php echo $id ?>" value="<?php echo $id ?>" /></span>
|
@@ -286,26 +286,7 @@ $mbadmin->get_header(array("title" => $page_title, "title_action" => $action));
|
|
286 |
<?php endif; ?>
|
287 |
</div>
|
288 |
|
289 |
-
<?php if ($inCollections):
|
290 |
-
$number = count($inCollections);
|
291 |
|
292 |
-
?>
|
293 |
-
<div class='collection_notice'>
|
294 |
-
<?php echo _n('In collection:', 'In collections:', $number,'maxbuttons') ?>
|
295 |
-
<?php foreach($inCollections as $col_id)
|
296 |
-
{
|
297 |
-
$meta = $collection->get_meta($col_id, 'collection_name');
|
298 |
-
$name = isset($meta['collection_name']) ? $meta['collection_name'] : false;
|
299 |
-
if ($name)
|
300 |
-
echo "<span class='name'>$name</span> ";
|
301 |
-
}
|
302 |
-
|
303 |
-
?>
|
304 |
-
</div>
|
305 |
-
|
306 |
-
<?php
|
307 |
-
endif;
|
308 |
-
?>
|
309 |
</span>
|
310 |
<span class="col col_name"><a class="button-name" href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=button&id=<?php echo $id ?>"><?php echo $button->getName() ?></a>
|
311 |
<br />
|
259 |
else
|
260 |
$button->set($id);
|
261 |
|
262 |
+
//$inCollections = $collections::isButtonInCollection($id);
|
263 |
?>
|
264 |
<div class='button-row'>
|
265 |
<span class="col col_check"><input type="checkbox" name="button-id[]" id="button-id-<?php echo $id ?>" value="<?php echo $id ?>" /></span>
|
286 |
<?php endif; ?>
|
287 |
</div>
|
288 |
|
|
|
|
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
</span>
|
291 |
<span class="col col_name"><a class="button-name" href="<?php admin_url() ?>admin.php?page=maxbuttons-controller&action=button&id=<?php echo $id ?>"><?php echo $button->getName() ?></a>
|
292 |
<br />
|
js/maxbuttons_media_button.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
//var maxMedia;
|
2 |
-
|
|
|
3 |
|
4 |
/* Add button for the post editor screen + integrations */
|
5 |
function maxMedia() {
|
@@ -321,3 +322,5 @@ maxMedia.prototype.getEditor = function ()
|
|
321 |
|
322 |
window.maxMedia = new maxMedia();
|
323 |
window.maxMedia.init();
|
|
|
|
1 |
//var maxMedia;
|
2 |
+
jQuery(document).ready(function(jq) {
|
3 |
+
$ = jq;
|
4 |
|
5 |
/* Add button for the post editor screen + integrations */
|
6 |
function maxMedia() {
|
322 |
|
323 |
window.maxMedia = new maxMedia();
|
324 |
window.maxMedia.init();
|
325 |
+
|
326 |
+
}); // jquery
|
js/maxcollections.js
DELETED
@@ -1,957 +0,0 @@
|
|
1 |
-
// All backend JS for collections
|
2 |
-
|
3 |
-
jQuery(document).ready(function($) {
|
4 |
-
|
5 |
-
maxCollection = function(){};
|
6 |
-
|
7 |
-
maxCollection.prototype = {
|
8 |
-
fields: '',
|
9 |
-
form_updated: false,
|
10 |
-
modalCurrentPage: 0,
|
11 |
-
item_maxwidth: 0,
|
12 |
-
}
|
13 |
-
|
14 |
-
// init
|
15 |
-
maxCollection.prototype.init = function()
|
16 |
-
{
|
17 |
-
// LIST
|
18 |
-
$('.collection_remove').on('click', $.proxy(this.confirmRemoveCollection, this));
|
19 |
-
|
20 |
-
/****** ONLY THE COLLECTION FORM ****/
|
21 |
-
if ($('#collection_edit').length == 0)
|
22 |
-
return;
|
23 |
-
|
24 |
-
$('.mb-preview-window').draggable();
|
25 |
-
$('.button-picker .picker-wrapper').on('click', $.proxy(this.addButtontoCollection, this));
|
26 |
-
|
27 |
-
//$(document).on('mouseenter', '.sortable.buttons .item', $.proxy(this.showTrash, this));
|
28 |
-
//$(document).on('mouseleave', '.sortable.buttons .item', $.proxy(this.hideTrash, this));
|
29 |
-
$(document).on('click', '.sortable.buttons .button-remove', $.proxy(this.removeButton, this));
|
30 |
-
|
31 |
-
if ( typeof collectionFieldMap != 'undefined')
|
32 |
-
this.fields = $.parseJSON(collectionFieldMap);
|
33 |
-
|
34 |
-
|
35 |
-
// Limit this to the collection edit screen */
|
36 |
-
$(document).on('keyup','.mb_ajax_save input[type="text"]', $.proxy(this.update_preview,this));
|
37 |
-
$(document).on('keyup change','.mb_ajax_save input', $.proxy(this.update_preview,this));
|
38 |
-
$(document).on('change','.mb_ajax_save select', $.proxy(this.update_preview, this));
|
39 |
-
|
40 |
-
this.initSortable();
|
41 |
-
|
42 |
-
// popup selection
|
43 |
-
$(document).on('click','button[name="picker_popup"]', $.proxy(this.togglePickerPopup, this));
|
44 |
-
|
45 |
-
$(document).on('updatePreviewWindow', $.proxy(this.updatePlacement, this)); // event from other scripts possible
|
46 |
-
$(document).on('mbFormSaved', $.proxy(function () { this.form_updated = false; this.toggleSaveIndicator(false); },this));
|
47 |
-
$(window).on('beforeunload', $.proxy(function () { if (this.form_updated) return maxcol_wp.leave_page; }, this));
|
48 |
-
|
49 |
-
$(document).on('click', '#exportCollection', $.proxy(this.exportCollection, this));
|
50 |
-
|
51 |
-
this.updatePlacement();
|
52 |
-
this.updatePlacement(); // running this twice yields better results
|
53 |
-
|
54 |
-
// init, if there are not buttons selected, open selector ( i.e. new collection )
|
55 |
-
if ($('input[name="sorted"]').val() == '')
|
56 |
-
this.togglePickerPopup();
|
57 |
-
}
|
58 |
-
|
59 |
-
// add a button to the collection on screen, buttons are passed by param.
|
60 |
-
maxCollection.prototype.addButtontoCollection = function (button)
|
61 |
-
{
|
62 |
-
var $button = $(button).clone();
|
63 |
-
var btn_id = $button.data('id');
|
64 |
-
$button.find('.button_name').remove();
|
65 |
-
|
66 |
-
//$button.css('height','auto');
|
67 |
-
|
68 |
-
var addbtn = $button;
|
69 |
-
|
70 |
-
// find span w/ button data
|
71 |
-
var bdata = addbtn.find('.button_data').text();
|
72 |
-
addbtn.find('.button_data').remove();
|
73 |
-
addbtn.append('<input type="hidden" name="button-data-' + btn_id + '" value="' + bdata + '">');
|
74 |
-
|
75 |
-
this.addButtontoPreview($button.clone());
|
76 |
-
|
77 |
-
// get data from it and add input type hidden to the sortable.
|
78 |
-
$(addbtn).appendTo('.mb_collection_selection .sortable ');
|
79 |
-
|
80 |
-
$('.mb_collection_selection .sortable').sortable('refresh');
|
81 |
-
|
82 |
-
// add new buttons to sort array ( and thus to selection )
|
83 |
-
var order = $(".mb_collection_selection .sortable").sortable('toArray', {attribute: 'data-id'})
|
84 |
-
var count = order.length;
|
85 |
-
order = order.toString();
|
86 |
-
$('input[name="sorted"]').val(order);
|
87 |
-
|
88 |
-
$.proxy( this.updateColPreview({ action: 'new_button', data: bdata, button_id: btn_id, button_count: count }), this);
|
89 |
-
|
90 |
-
}
|
91 |
-
|
92 |
-
/* Update the social options preview */
|
93 |
-
maxCollection.prototype.updateColPreview = function (args)
|
94 |
-
{
|
95 |
-
|
96 |
-
if (typeof args.action !== 'undefined')
|
97 |
-
{
|
98 |
-
var action = args.action;
|
99 |
-
}
|
100 |
-
else
|
101 |
-
action = '';
|
102 |
-
|
103 |
-
var nonce = $('input[name="block_nonce"]').val();
|
104 |
-
var collection_id = $('input[name="collection_id"]').val();
|
105 |
-
var collection_type = $('input[name="collection_type"]').val();
|
106 |
-
var count = args.button_count;
|
107 |
-
var index = (count-1);
|
108 |
-
|
109 |
-
if (action == 'new_button')
|
110 |
-
{
|
111 |
-
var ajax_data = {
|
112 |
-
block_name : 'social',
|
113 |
-
block_action : 'ajax_new_button',
|
114 |
-
action : 'mbpro_collection_block',
|
115 |
-
nonce: nonce,
|
116 |
-
collection_id: collection_id,
|
117 |
-
collection_type: collection_type,
|
118 |
-
block_data : {data : args.data, button_id: args.button_id, index: index },
|
119 |
-
// button_id: args.button_id,
|
120 |
-
}
|
121 |
-
$.proxy(this.ajaxNewButton(ajax_data), this);
|
122 |
-
}
|
123 |
-
|
124 |
-
// update interface, probably via ajax.
|
125 |
-
|
126 |
-
}
|
127 |
-
|
128 |
-
maxCollection.prototype.addButtontoPreview = function($button)
|
129 |
-
{
|
130 |
-
|
131 |
-
$button.find('input').remove();
|
132 |
-
$button.find('.dashicons').remove();
|
133 |
-
var button_id = $button.data('id');
|
134 |
-
var $preview = $("<span class='mb-collection-item' data-id='" + button_id + "'></span>").append($button.children());
|
135 |
-
|
136 |
-
$preview.appendTo('.mb-preview-window .maxcollection');
|
137 |
-
this.updatePlacement();
|
138 |
-
}
|
139 |
-
|
140 |
-
maxCollection.prototype.ajaxNewButton = function(data)
|
141 |
-
{
|
142 |
-
|
143 |
-
var url = mb_ajax.ajaxurl;
|
144 |
-
|
145 |
-
$.ajax({
|
146 |
-
type: "POST",
|
147 |
-
url: url,
|
148 |
-
data: data,
|
149 |
-
|
150 |
-
}).done($.proxy(this.ajaxNewButtonDone, this));
|
151 |
-
|
152 |
-
}
|
153 |
-
|
154 |
-
maxCollection.prototype.ajaxNewButtonDone = function (result)
|
155 |
-
{
|
156 |
-
var json = $.parseJSON(result);
|
157 |
-
$('.mb_tab[data-tab="social-options"]').children('.inside').append(json.body);
|
158 |
-
$('.no-buttons').hide();
|
159 |
-
$(document).trigger('reInitConditionals'); // do again conditionals
|
160 |
-
}
|
161 |
-
|
162 |
-
|
163 |
-
// update the live preview.
|
164 |
-
maxCollection.prototype.update_preview = function(e)
|
165 |
-
{
|
166 |
-
|
167 |
-
e.preventDefault();
|
168 |
-
|
169 |
-
this.toggleSaveIndicator(true);
|
170 |
-
|
171 |
-
var target = $(e.target);
|
172 |
-
var id = $(target).attr('id');
|
173 |
-
|
174 |
-
// for multi-fields the id is not bound to an update function.
|
175 |
-
if (typeof $(target).data('target') !== 'undefined')
|
176 |
-
id = $(target).data('target');
|
177 |
-
|
178 |
-
|
179 |
-
var data = this.fields[id];
|
180 |
-
|
181 |
-
if (typeof data == 'undefined')
|
182 |
-
return; // field doesn't have updates
|
183 |
-
|
184 |
-
if (typeof data.css != 'undefined')
|
185 |
-
{
|
186 |
-
|
187 |
-
value = target.val();
|
188 |
-
if (typeof data.css_unit != 'undefined' && value.indexOf(data.css_unit) == -1)
|
189 |
-
value += data.css_unit;
|
190 |
-
|
191 |
-
//$('.output .result').find('a').css(data.css, value);
|
192 |
-
|
193 |
-
this.putCSS(data, value);
|
194 |
-
}
|
195 |
-
if (typeof data.attr != 'undefined')
|
196 |
-
{
|
197 |
-
$('.output .result').find('a').attr(data.attr, target.val());
|
198 |
-
}
|
199 |
-
if (typeof data.func != 'undefined')
|
200 |
-
{
|
201 |
-
|
202 |
-
eval('this.'+ data.func + '(target)');
|
203 |
-
}
|
204 |
-
|
205 |
-
this.updatePlacement(); // update the window size
|
206 |
-
};
|
207 |
-
|
208 |
-
maxCollection.prototype.putCSS = function(data,value,state)
|
209 |
-
{
|
210 |
-
state = state || 'both';
|
211 |
-
|
212 |
-
|
213 |
-
var element = '.maxcollection';
|
214 |
-
|
215 |
-
if (typeof data.csspart != 'undefined')
|
216 |
-
{
|
217 |
-
var parts = data.csspart.split(",");
|
218 |
-
for(i=0; i < parts.length; i++)
|
219 |
-
{
|
220 |
-
var cpart = parts[i];
|
221 |
-
//var fullpart = element;
|
222 |
-
if (element !== '.' + cpart)
|
223 |
-
var fullpart = element + " ." + cpart;
|
224 |
-
else
|
225 |
-
var fullpart = element; // lot of stuff on .maxcollection main element
|
226 |
-
|
227 |
-
|
228 |
-
$('.mb-preview-wrapper').find(fullpart).css(data.css, value);
|
229 |
-
}
|
230 |
-
}
|
231 |
-
else
|
232 |
-
$('.output .result').find(element).css(data.css, value);
|
233 |
-
|
234 |
-
|
235 |
-
}
|
236 |
-
|
237 |
-
/* Check the position ( horizontal - vertical ) of the buttons and change accordingly. */
|
238 |
-
maxCollection.prototype.updatePlacement = function ()
|
239 |
-
{
|
240 |
-
|
241 |
-
var orientation = $('#orientation').val();
|
242 |
-
|
243 |
-
if (typeof orientation != 'undefined' && orientation !== 'auto')
|
244 |
-
{
|
245 |
-
this.pushPreview(orientation);
|
246 |
-
|
247 |
-
}
|
248 |
-
else if (orientation == 'auto')
|
249 |
-
{
|
250 |
-
var placement = $('#placement').val();
|
251 |
-
if (placement == 'static-left' || placement == 'static-right')
|
252 |
-
orientation = 'vertical';
|
253 |
-
else
|
254 |
-
orientation = 'horizontal';
|
255 |
-
|
256 |
-
this.pushPreview(orientation);
|
257 |
-
}
|
258 |
-
|
259 |
-
}
|
260 |
-
|
261 |
-
maxCollection.prototype.updateCollectionName = function ()
|
262 |
-
{
|
263 |
-
// needs escaping!
|
264 |
-
var name = $('#collection_name').val();
|
265 |
-
|
266 |
-
name = name.MBescapeHTML();
|
267 |
-
|
268 |
-
var line = $('.mb-message.shortcode').html();
|
269 |
-
if (line)
|
270 |
-
{
|
271 |
-
line = line.replace(/\[maxcollection name="(.*)"]/gi, '[maxcollection name="' + name + '"]');
|
272 |
-
$('.mb-message.shortcode').html( line );
|
273 |
-
}
|
274 |
-
|
275 |
-
|
276 |
-
}
|
277 |
-
|
278 |
-
var __entityMap = {
|
279 |
-
"&": "&",
|
280 |
-
"<": "<",
|
281 |
-
">": ">",
|
282 |
-
'"': '"',
|
283 |
-
"'": ''',
|
284 |
-
"/": '/'
|
285 |
-
};
|
286 |
-
|
287 |
-
String.prototype.MBescapeHTML = function() {
|
288 |
-
return String(this).replace(/[&<>"'\/]/g, function (s) {
|
289 |
-
return __entityMap[s];
|
290 |
-
});
|
291 |
-
}
|
292 |
-
|
293 |
-
|
294 |
-
/* Update for social block, make {tags} to be more meaningful in the preview */
|
295 |
-
maxCollection.prototype.parseTags = function (target)
|
296 |
-
{
|
297 |
-
var option = $(target).parents('.social-option');
|
298 |
-
var index = $('.social-option').index(option);
|
299 |
-
var button = $('.mb-preview-window .mb-collection-item').eq(index);
|
300 |
-
var social_button = $(option).find('.maxbutton');
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
var network = $(option).find('[data-target="network"] :selected').text();
|
305 |
-
var count = 0;
|
306 |
-
var replacements = { network_name : network, count: count };
|
307 |
-
|
308 |
-
|
309 |
-
// objects
|
310 |
-
var text = $(button).find('.mb-text');
|
311 |
-
var text2 = $(button).find('.mb-text2');
|
312 |
-
|
313 |
-
|
314 |
-
//strings
|
315 |
-
var social_text = $(social_button).find('.mb-text').text();
|
316 |
-
var social_text2 = $(social_button).find('.mb-text2').text();
|
317 |
-
|
318 |
-
$(text).text(social_text);
|
319 |
-
$(text2).text(social_text2);
|
320 |
-
|
321 |
-
|
322 |
-
this.replaceTags(text, replacements);
|
323 |
-
this.replaceTags(text2, replacements);
|
324 |
-
|
325 |
-
}
|
326 |
-
|
327 |
-
maxCollection.prototype.replaceTags = function (element, replacements)
|
328 |
-
{
|
329 |
-
var text = $(element).text();
|
330 |
-
|
331 |
-
if (typeof $(element).data('original') == 'undefined')
|
332 |
-
{
|
333 |
-
$(element).data('original', text);
|
334 |
-
}
|
335 |
-
else // use original text for this
|
336 |
-
{
|
337 |
-
text = $(element).data('original');
|
338 |
-
}
|
339 |
-
|
340 |
-
$.each(replacements, function (index, el)
|
341 |
-
{
|
342 |
-
|
343 |
-
text = text.replace('{' + index + '}', el);
|
344 |
-
$(element).text(text);
|
345 |
-
});
|
346 |
-
}
|
347 |
-
|
348 |
-
maxCollection.prototype.pushPreview = function(orientation)
|
349 |
-
{
|
350 |
-
|
351 |
-
var $window = $('.mb-preview-window.output');
|
352 |
-
var $items = $('.mb-preview-window .mb-collection-item');
|
353 |
-
var height = $('.mb-preview-window .maxcollection').height() + 75;
|
354 |
-
|
355 |
-
$items.css('float','left');
|
356 |
-
|
357 |
-
if( $window.css('position') == 'relative')
|
358 |
-
return; // don't size on mobile views.
|
359 |
-
|
360 |
-
if (orientation == 'horizontal')
|
361 |
-
{
|
362 |
-
$window.css('width', $('#maxbuttons').css('width') );
|
363 |
-
$window.css('top', 'auto');
|
364 |
-
$window.css('bottom', '10px');
|
365 |
-
$window.css('height', height + 'px');
|
366 |
-
$window.css('right', '10px');
|
367 |
-
$window.css('left', 'auto');
|
368 |
-
$items.css('clear', 'none');
|
369 |
-
|
370 |
-
}
|
371 |
-
if (orientation == 'vertical')
|
372 |
-
{
|
373 |
-
$window.css('width', '30%');
|
374 |
-
$window.css('right', '20px');
|
375 |
-
$window.css('top', '25%');
|
376 |
-
$window.css('height', height + 'px');
|
377 |
-
$window.css('left','auto');
|
378 |
-
$window.css('bottom', 'auto');
|
379 |
-
$items.css('clear','both');
|
380 |
-
}
|
381 |
-
|
382 |
-
|
383 |
-
}
|
384 |
-
|
385 |
-
maxCollection.prototype.exportCollection = function ()
|
386 |
-
{
|
387 |
-
var nonce = $('input[name="block_nonce"]').val();
|
388 |
-
var collection_id = $('input[name="collection_id"]').val();
|
389 |
-
var collection_type = $('input[name="collection_type"]').val();
|
390 |
-
|
391 |
-
var ajax_data = {
|
392 |
-
block_name : 'export',
|
393 |
-
block_action : 'export',
|
394 |
-
action : 'mbpro_collection_block',
|
395 |
-
nonce: nonce,
|
396 |
-
collection_id: collection_id,
|
397 |
-
collection_type: collection_type,
|
398 |
-
block_data : {},
|
399 |
-
}
|
400 |
-
|
401 |
-
var url = mb_ajax.ajaxurl;
|
402 |
-
|
403 |
-
$.ajax({
|
404 |
-
type: "POST",
|
405 |
-
url: url,
|
406 |
-
data: ajax_data,
|
407 |
-
|
408 |
-
}).done(
|
409 |
-
function (result)
|
410 |
-
{
|
411 |
-
var json = $.parseJSON(result);
|
412 |
-
var location = json.data.location;
|
413 |
-
window.location.href = location;
|
414 |
-
}
|
415 |
-
);
|
416 |
-
|
417 |
-
}
|
418 |
-
|
419 |
-
|
420 |
-
maxCollection.prototype.checkPicker = function ()
|
421 |
-
{
|
422 |
-
if ($('.mb_collection_picker').is(':visible'))
|
423 |
-
this.initButtonPicker();
|
424 |
-
}
|
425 |
-
|
426 |
-
/* Init sortable interface */
|
427 |
-
maxCollection.prototype.initSortable = function ()
|
428 |
-
{
|
429 |
-
var mbc = this;
|
430 |
-
|
431 |
-
$('.mb_collection_selection .sortable').sortable({
|
432 |
-
|
433 |
-
placeholder: 'sortable-placeholder',
|
434 |
-
connectWith: '.maxcollection',
|
435 |
-
start: function(event, ui){
|
436 |
-
iBefore = ui.item.index();
|
437 |
-
},
|
438 |
-
create: function(event, ui) {
|
439 |
-
// var order = $(".mb_collection_selection .sortable").sortable('toArray', {attribute: 'data-id'}).toString();
|
440 |
-
var order = $(this).sortable('toArray', {attribute: 'data-id'}).toString();
|
441 |
-
$('input[name="sorted"]').val(order);
|
442 |
-
$('input[name="previous_selection"]').val(order);
|
443 |
-
},
|
444 |
-
update: function(event, ui) {
|
445 |
-
iAfter = ui.item.index();
|
446 |
-
// var order = $(".mb_collection_selection .sortable").sortable('toArray', {attribute: 'data-id'}).toString();
|
447 |
-
var order = $(this).sortable('toArray', {attribute: 'data-id'}).toString();
|
448 |
-
$('input[name="sorted"]').val(order);
|
449 |
-
|
450 |
-
mbc.updateListOrder('.maxcollection .mb-collection-item', iBefore, iAfter);
|
451 |
-
mbc.updateListOrder('.social_block .social-option', iBefore, iAfter);
|
452 |
-
},
|
453 |
-
|
454 |
-
|
455 |
-
});
|
456 |
-
}
|
457 |
-
|
458 |
-
|
459 |
-
// removes button from the current collection.
|
460 |
-
maxCollection.prototype.removeButton = function (e)
|
461 |
-
{
|
462 |
-
e.preventDefault();
|
463 |
-
|
464 |
-
var old_sort = $('input[name="sorted"]').val();
|
465 |
-
var parent = $(e.currentTarget).parents('.item');
|
466 |
-
var items = $('.mb_collection_selection .sortable .item');
|
467 |
-
var index = items.index(parent);
|
468 |
-
|
469 |
-
$(e.currentTarget).parents('.item').remove();
|
470 |
-
$('.maxcollection .mb-collection-item:eq(' + index + ')').remove();
|
471 |
-
$('.social_block .social-option:eq(' + index + ')').remove();
|
472 |
-
|
473 |
-
$('.mb_collection_selection .sortable').sortable('refresh');
|
474 |
-
var order = $(".mb_collection_selection .sortable").sortable('toArray', {attribute: 'data-id'}).toString();
|
475 |
-
$('input[name="sorted"]').val(order);
|
476 |
-
|
477 |
-
this.toggleSaveIndicator(true);
|
478 |
-
|
479 |
-
}
|
480 |
-
|
481 |
-
maxCollection.prototype.updateListOrder = function (el, before, after)
|
482 |
-
{
|
483 |
-
this.toggleSaveIndicator(true);
|
484 |
-
evictee = $(el + ':eq('+after+')');
|
485 |
-
evictor = $(el + ':eq('+before+')');
|
486 |
-
|
487 |
-
|
488 |
-
evictee.replaceWith(evictor);
|
489 |
-
if(iBefore > iAfter)
|
490 |
-
evictor.after(evictee);
|
491 |
-
else
|
492 |
-
evictor.before(evictee);
|
493 |
-
|
494 |
-
// reorder not only the position but also the name of everything (-buttonId-index ) since it's important when saving.
|
495 |
-
if(el == '.social_block .social-option')
|
496 |
-
{
|
497 |
-
var elements = $(el).each(function (index) {
|
498 |
-
var id = $(this).data('id');
|
499 |
-
var html = $(this).html();
|
500 |
-
var pattern = new RegExp( '-' + id + '-\\d', 'gi');
|
501 |
-
html = html.replace(pattern,'-' + id + '-' + index);
|
502 |
-
$(this).html(html);
|
503 |
-
});
|
504 |
-
}
|
505 |
-
|
506 |
-
|
507 |
-
}
|
508 |
-
|
509 |
-
/* Confirmation window to delete the collection */
|
510 |
-
maxCollection.prototype.confirmRemoveCollection = function(e)
|
511 |
-
{
|
512 |
-
|
513 |
-
var collection_id = $(e.target).parents('.collection').data('id');
|
514 |
-
var nonce = $(e.target).parents('.collection').data('blocknonce');
|
515 |
-
var collection_type = $(e.target).parents('.collection').data('type');
|
516 |
-
|
517 |
-
var title = $('.remove_action_title').text();
|
518 |
-
var text = "<p>" + $('.remove_action_text').text() + "</p>";
|
519 |
-
|
520 |
-
var modal = window.maxFoundry.maxmodal;
|
521 |
-
modal.newModal('collection_remove');
|
522 |
-
modal.setTitle(title);
|
523 |
-
modal.setContent(text);
|
524 |
-
|
525 |
-
modal.addControl('yes', {collection_id: collection_id, nonce: nonce, collection_type: collection_type},
|
526 |
-
$.proxy(this.removeCollection, this) );
|
527 |
-
modal.addControl('no', '', $.proxy(modal.close, modal) );
|
528 |
-
modal.setControls();
|
529 |
-
modal.show();
|
530 |
-
|
531 |
-
}
|
532 |
-
|
533 |
-
maxCollection.prototype.removeCollection = function (e)
|
534 |
-
{
|
535 |
-
|
536 |
-
var collection_id = e.data.collection_id;
|
537 |
-
|
538 |
-
// ajax something
|
539 |
-
var nonce = e.data.nonce;
|
540 |
-
|
541 |
-
var collection_type = e.data.collection_type;
|
542 |
-
|
543 |
-
var ajax_data = {
|
544 |
-
block_name : 'collection', // invoke on the main class
|
545 |
-
block_action : 'delete',
|
546 |
-
action : 'mbpro_collection_block',
|
547 |
-
nonce: nonce,
|
548 |
-
collection_id: collection_id,
|
549 |
-
collection_type: collection_type,
|
550 |
-
block_data : {},
|
551 |
-
}
|
552 |
-
|
553 |
-
var url = mb_ajax.ajaxurl;
|
554 |
-
|
555 |
-
$.ajax({
|
556 |
-
type: "POST",
|
557 |
-
url: url,
|
558 |
-
data: ajax_data,
|
559 |
-
|
560 |
-
}).done(
|
561 |
-
function (result)
|
562 |
-
{
|
563 |
-
var json = $.parseJSON(result);
|
564 |
-
var modal = window.maxFoundry.maxmodal;
|
565 |
-
|
566 |
-
var title = json.data.title;
|
567 |
-
var body = json.data.body;
|
568 |
-
var collection_id = json.data.collection_id;
|
569 |
-
|
570 |
-
modal.newModal('collection_removed');
|
571 |
-
modal.setTitle(title);
|
572 |
-
modal.setContent(body);
|
573 |
-
modal.addControl('ok','', $.proxy(modal.close, modal) );
|
574 |
-
modal.setControls();
|
575 |
-
modal.show();
|
576 |
-
|
577 |
-
$('.collection-' + collection_id).hide();
|
578 |
-
|
579 |
-
}
|
580 |
-
);
|
581 |
-
} // removeCollection
|
582 |
-
|
583 |
-
|
584 |
-
maxCollection.prototype.togglePickerPopup = function (e)
|
585 |
-
{
|
586 |
-
var maxmodal = window.maxFoundry.maxmodal;
|
587 |
-
|
588 |
-
var picker = $('#picker-modal').html();
|
589 |
-
maxmodal.newModal('picker-modal');
|
590 |
-
|
591 |
-
maxmodal.setTitle(maxcol_wp.picker_title);
|
592 |
-
maxmodal.setContent(picker);
|
593 |
-
|
594 |
-
maxmodal.show();
|
595 |
-
modal = maxmodal.get();
|
596 |
-
|
597 |
-
// load the events on demand
|
598 |
-
$(modal).off('click change keyup');
|
599 |
-
$(modal).on('click', '.picker-packages a', $.proxy(this.getModalButtons, this));
|
600 |
-
$(modal).on('click', '.picker-main .screen .item', $.proxy(this.toggleInSelection, this));
|
601 |
-
$(modal).on('click', '.modal_close', $.proxy(maxmodal.close, maxmodal) );
|
602 |
-
$(modal).on('click', '.clear-selection', $.proxy(this.modalClearSelection, this));
|
603 |
-
$(modal).on('click', 'button[name="add-buttons"]', $.proxy(this.modalAddButtons,this));
|
604 |
-
$(modal).on('click', '.button-remove', $.proxy(this.modalDeleteButton, this) );
|
605 |
-
|
606 |
-
$(modal).on('click', '.pagination-links a', $.proxy(this.modalLoadPage, this));
|
607 |
-
$(modal).on('change keyup', '.pagination-links input', $.proxy(this.modalLoadPage, this));
|
608 |
-
|
609 |
-
if ($(modal).find('.picker-main .current-screen').length == 0 ) // not loaded, load first.
|
610 |
-
{
|
611 |
-
$(modal).find('.picker-packages ul li a:first').trigger('click');
|
612 |
-
}
|
613 |
-
|
614 |
-
} // initPickerPopup
|
615 |
-
|
616 |
-
maxCollection.prototype.getModalButtons = function (e)
|
617 |
-
{
|
618 |
-
e.preventDefault();
|
619 |
-
|
620 |
-
var modal = window.maxFoundry.maxmodal.get();
|
621 |
-
var target = $(e.target);
|
622 |
-
var pack = $(e.target).data('pack');
|
623 |
-
var loaded = $(e.target).data('pack-loaded');
|
624 |
-
|
625 |
-
if (typeof loaded !== 'undefined' && loaded)
|
626 |
-
{
|
627 |
-
$(modal).find('.picker-main .screen').hide().removeClass('current-screen');
|
628 |
-
$(modal).find('.picker-main .screen-' + pack).show().addClass('current-screen');
|
629 |
-
this.modalEqualHeight();
|
630 |
-
|
631 |
-
// select the package in view
|
632 |
-
$(modal).find('.picker-packages ul li a').removeClass('pack-active');
|
633 |
-
$(e.target).addClass('pack-active');
|
634 |
-
|
635 |
-
return; // loaded, already fine.
|
636 |
-
}
|
637 |
-
|
638 |
-
var collection_id = $('input[name="collection_id"]').val();
|
639 |
-
var collection_type = $('input[name="collection_type"]').val();
|
640 |
-
var nonce = $('input[name="block_nonce"]').val();
|
641 |
-
|
642 |
-
var ajax_data = {
|
643 |
-
block_name : 'collection', // invoke on the main class
|
644 |
-
block_action : 'ajax_getButtons',
|
645 |
-
action : 'mbpro_collection_block',
|
646 |
-
nonce: nonce,
|
647 |
-
collection_id: collection_id,
|
648 |
-
collection_type: collection_type,
|
649 |
-
block_data : { 'pack' : pack },
|
650 |
-
}
|
651 |
-
|
652 |
-
var url = mb_ajax.ajaxurl;
|
653 |
-
var self = this;
|
654 |
-
|
655 |
-
$.ajax({
|
656 |
-
type: "POST",
|
657 |
-
url: url,
|
658 |
-
data: ajax_data,
|
659 |
-
|
660 |
-
}).done(
|
661 |
-
function (result)
|
662 |
-
{
|
663 |
-
self.modalLoadButtons(result, pack, target);
|
664 |
-
|
665 |
-
}
|
666 |
-
);
|
667 |
-
|
668 |
-
} // getModalButtons
|
669 |
-
|
670 |
-
/* Add the AJAX requested buttons to the modal screen */
|
671 |
-
maxCollection.prototype.modalLoadButtons = function (result,pack,target)
|
672 |
-
{
|
673 |
-
var self = this;
|
674 |
-
var modal = window.maxFoundry.maxmodal.get();
|
675 |
-
|
676 |
-
$(modal).find('.picker-main .screen').hide().removeClass('current-screen');
|
677 |
-
|
678 |
-
var json = $.parseJSON(result);
|
679 |
-
|
680 |
-
if ( $(modal).find('.picker-main .screen-' + pack).length == 0 )
|
681 |
-
{
|
682 |
-
var el = $('<div class="screen screen-' + pack + '">');
|
683 |
-
$(modal).find('.picker-main').append(el);
|
684 |
-
}
|
685 |
-
else
|
686 |
-
{
|
687 |
-
var el = $(modal).find(' .picker-main .screen-' + pack);
|
688 |
-
}
|
689 |
-
|
690 |
-
el.html(json.body);
|
691 |
-
|
692 |
-
$(modal).find('.picker-main .screen-' + pack).show().addClass('current-screen');
|
693 |
-
|
694 |
-
setTimeout( $.proxy(function() {
|
695 |
-
|
696 |
-
$(modal).find('.picker-main .current-screen .item').each(function()
|
697 |
-
{
|
698 |
-
self.modalScaleButton(this);
|
699 |
-
|
700 |
-
});
|
701 |
-
}, this), 400);
|
702 |
-
|
703 |
-
this.modalEqualHeight();
|
704 |
-
$(target).data('pack-loaded', true);
|
705 |
-
|
706 |
-
// select the package in view
|
707 |
-
$(modal).find('.picker-packages ul li a').removeClass('pack-active');
|
708 |
-
$(target).addClass('pack-active');
|
709 |
-
|
710 |
-
$(document).trigger('mb-modalLoadButtons');
|
711 |
-
|
712 |
-
}
|
713 |
-
|
714 |
-
maxCollection.prototype.modalLoadPage = function (e)
|
715 |
-
{
|
716 |
-
e.preventDefault();
|
717 |
-
|
718 |
-
var page = $(e.target).data("page");
|
719 |
-
if (typeof page == 'undefined')
|
720 |
-
{
|
721 |
-
// check if input number is event
|
722 |
-
if (e.target.type == 'number')
|
723 |
-
var page = $(e.target).val();
|
724 |
-
else
|
725 |
-
return; // no page load if page link is disabled ( current / or n/a )
|
726 |
-
}
|
727 |
-
var collection_id = $('input[name="collection_id"]').val();
|
728 |
-
var collection_type = $('input[name="collection_type"]').val();
|
729 |
-
var nonce = $('input[name="block_nonce"]').val();
|
730 |
-
|
731 |
-
var pack = $('.picker-packages a.pack-active').data('pack');
|
732 |
-
var target = $('.picker-packages a.pack-active');
|
733 |
-
|
734 |
-
var ajax_data = {
|
735 |
-
block_name : 'collection', // invoke on the main class
|
736 |
-
block_action : 'ajax_getButtons',
|
737 |
-
action : 'mbpro_collection_block',
|
738 |
-
nonce: nonce,
|
739 |
-
collection_id: collection_id,
|
740 |
-
collection_type: collection_type,
|
741 |
-
block_data : { 'pack' : pack, 'paged' : page },
|
742 |
-
}
|
743 |
-
|
744 |
-
var url = mb_ajax.ajaxurl;
|
745 |
-
var self = this;
|
746 |
-
|
747 |
-
$.ajax({
|
748 |
-
type: "POST",
|
749 |
-
url: url,
|
750 |
-
data: ajax_data,
|
751 |
-
|
752 |
-
}).done(
|
753 |
-
function (result)
|
754 |
-
{
|
755 |
-
|
756 |
-
self.modalLoadButtons(result, pack, target);
|
757 |
-
}
|
758 |
-
);
|
759 |
-
|
760 |
-
}
|
761 |
-
|
762 |
-
maxCollection.prototype.toggleInSelection = function (e)
|
763 |
-
{
|
764 |
-
var target = $(e.target);
|
765 |
-
var modal = window.maxFoundry.maxmodal.get();
|
766 |
-
|
767 |
-
if (! target.hasClass('item')) // find the whole thing.
|
768 |
-
{
|
769 |
-
var target = $(e.target).parents('.item');
|
770 |
-
}
|
771 |
-
|
772 |
-
var id = $(target).data('id');
|
773 |
-
var exists = $(modal).find('.picker-inselection .items').children('[data-id="' + id + '"]');
|
774 |
-
if (exists.length > 0)
|
775 |
-
{
|
776 |
-
$(target).find('.button-selected').remove();
|
777 |
-
$(modal).find('.picker-inselection .items').children('[data-id="' + id + '"]').remove();
|
778 |
-
this.modalUpdateCount();
|
779 |
-
return;
|
780 |
-
}
|
781 |
-
|
782 |
-
var clone = $(target).clone();
|
783 |
-
$(clone).find('.dashicons').remove();
|
784 |
-
$(clone).css('height', '100%');
|
785 |
-
$(clone).css('width', '40px'); // projected width from css
|
786 |
-
$(clone).find('a').css('verticalAlign', 'middle');
|
787 |
-
|
788 |
-
if ( $(target).children('.button-selected').length == 0)
|
789 |
-
$(target).append('<div class="button-selected"><span class="dashicons dashicons-yes">');
|
790 |
-
|
791 |
-
clone.append('<div class="button-remove"><span class="dashicons dashicons-no">');
|
792 |
-
|
793 |
-
$(modal).find('.picker-inselection .items').append(clone);
|
794 |
-
|
795 |
-
this.modalScaleButton(clone);
|
796 |
-
this.modalUpdateCount();
|
797 |
-
|
798 |
-
} // toggleInSelection
|
799 |
-
|
800 |
-
maxCollection.prototype.modalEqualHeight = function (e)
|
801 |
-
{
|
802 |
-
|
803 |
-
var maxHeight = 0;
|
804 |
-
$(modal).find('.picker-main .current-screen .item').each(function()
|
805 |
-
{
|
806 |
-
if ( $(this).height() > maxHeight)
|
807 |
-
maxHeight = $(this).height();
|
808 |
-
}
|
809 |
-
);
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
if(maxHeight > 0) // 0 is possible when picker is closed before buttons are done loading.
|
814 |
-
$(modal).find('.picker-main .current-screen .item').height(maxHeight);
|
815 |
-
}
|
816 |
-
|
817 |
-
maxCollection.prototype.modalScaleButton = function(item)
|
818 |
-
{
|
819 |
-
var maxwidth = $(item).width();
|
820 |
-
|
821 |
-
// switch over width like this, not clone due to performance ( about 30 times ) .
|
822 |
-
$(item).css('width', '100%');
|
823 |
-
var button = $(item).find('a');
|
824 |
-
var width = $(button).width();
|
825 |
-
var height = $(button).height();
|
826 |
-
$(item).css('width', maxwidth);
|
827 |
-
|
828 |
-
if (maxwidth >= width)
|
829 |
-
{
|
830 |
-
return; // we don't want to enlarge.
|
831 |
-
}
|
832 |
-
|
833 |
-
// find the scale to resize it.
|
834 |
-
var scale = (maxwidth/width);
|
835 |
-
scale = scale.toFixed(2);
|
836 |
-
|
837 |
-
var $button = $(item).find('a');
|
838 |
-
|
839 |
-
var csstext = 'width: calc(' + width + 'px * ' + scale + ')!important; height: calc(' + height + 'px * ' + scale + ') !important;';
|
840 |
-
$button.css('cssText', csstext);
|
841 |
-
|
842 |
-
$button.children('.mb-text').each(function()
|
843 |
-
{
|
844 |
-
var text = $(this).css('fontSize');
|
845 |
-
|
846 |
-
var textitem = this;
|
847 |
-
var cssitems = [ "font-size", "padding-left","padding-right","padding-top","padding-bottom" ];
|
848 |
-
var item_csstext = '';
|
849 |
-
|
850 |
-
for( i = 0; i < cssitems.length; i++)
|
851 |
-
{
|
852 |
-
|
853 |
-
if ( parseInt ($(this).css(cssitems[i]) ) > 0)
|
854 |
-
{
|
855 |
-
var p = $(this).css(cssitems[i]);
|
856 |
-
|
857 |
-
item_csstext += cssitems[i] + ': calc(' + p + ' * ' + scale + ') !important; ';
|
858 |
-
}
|
859 |
-
|
860 |
-
}
|
861 |
-
$(this).css('cssText', item_csstext);
|
862 |
-
});
|
863 |
-
|
864 |
-
$icon = $button.children('.mb-icon');
|
865 |
-
var iwidth = $icon.width();
|
866 |
-
var iheight = $icon.height();
|
867 |
-
|
868 |
-
var cssText = 'width: calc(' + iwidth + 'px * ' + scale + ') !important; height: calc(' + iheight + 'px * ' + scale + ') !important;';
|
869 |
-
$icon.css('cssText', cssText);
|
870 |
-
|
871 |
-
var $icon_img = $icon.children('img');
|
872 |
-
|
873 |
-
if ($icon_img.length > 0)
|
874 |
-
{
|
875 |
-
var iwidth = $icon_img.width();
|
876 |
-
var iheight = $icon_img.height();
|
877 |
-
var cssText = 'width: calc(' + iwidth + 'px * ' + scale + ') !important; height: calc(' + iheight + 'px * ' + scale + ') !important;';
|
878 |
-
$icon_img.css('cssText', cssText);
|
879 |
-
}
|
880 |
-
|
881 |
-
}
|
882 |
-
// Remove all the scaling.
|
883 |
-
maxCollection.prototype.unScaleButton = function(item)
|
884 |
-
{
|
885 |
-
item.find('a, .mb-text, .mb-icon, img').css('cssText','');
|
886 |
-
item.css('cssText','');
|
887 |
-
|
888 |
-
}
|
889 |
-
|
890 |
-
maxCollection.prototype.modalClearSelection = function (e)
|
891 |
-
{
|
892 |
-
var modal = window.maxFoundry.maxmodal.get();
|
893 |
-
$(modal).find('.picker-inselection .items').html('');
|
894 |
-
$(modal).find('.screen .item .button-selected').remove();
|
895 |
-
this.modalUpdateCount();
|
896 |
-
}
|
897 |
-
|
898 |
-
maxCollection.prototype.modalAddButtons = function (e)
|
899 |
-
{
|
900 |
-
e.preventDefault;
|
901 |
-
var self = this;
|
902 |
-
var maxmodal = window.maxFoundry.maxmodal;
|
903 |
-
var modal = window.maxFoundry.maxmodal.get();
|
904 |
-
|
905 |
-
$(modal).find('.picker-inselection .items .item').each(function ()
|
906 |
-
{
|
907 |
-
|
908 |
-
var button = $(this).clone().wrap('<div>').parent().html();
|
909 |
-
var $button = $(button); // load the dom
|
910 |
-
|
911 |
-
self.unScaleButton($button);
|
912 |
-
self.addButtontoCollection( $button );
|
913 |
-
});
|
914 |
-
|
915 |
-
// close modal
|
916 |
-
// this.togglePickerPopup();
|
917 |
-
maxmodal.close();
|
918 |
-
this.modalClearSelection(); // reset selection
|
919 |
-
|
920 |
-
}
|
921 |
-
|
922 |
-
maxCollection.prototype.modalUpdateCount = function (e)
|
923 |
-
{
|
924 |
-
var modal = window.maxFoundry.maxmodal.get();
|
925 |
-
|
926 |
-
// update count
|
927 |
-
var count = $(modal).find('.picker-inselection .items .item').length;
|
928 |
-
$(modal).find('.picker-inselection .info .count').text(count);
|
929 |
-
|
930 |
-
if (count == 0)
|
931 |
-
$(modal).find('.picker-inselection .info').hide();
|
932 |
-
else
|
933 |
-
$(modal).find('.picker-inselection .info').show();
|
934 |
-
}
|
935 |
-
|
936 |
-
maxCollection.prototype.modalDeleteButton = function (e) {
|
937 |
-
var item = $(e.target).parents('.item');
|
938 |
-
var id = item.data('id');
|
939 |
-
$('.picker-main').find('[data-id="' + id + '"]').children('.button-selected').remove();
|
940 |
-
item.remove();
|
941 |
-
this.modalUpdateCount();
|
942 |
-
}
|
943 |
-
|
944 |
-
maxCollection.prototype.toggleSaveIndicator = function(toggle)
|
945 |
-
{
|
946 |
-
if (toggle)
|
947 |
-
{
|
948 |
-
this.form_updated = true;
|
949 |
-
$('.save-indicator').css('display', 'block').addClass('dashicons-warning').removeClass('dashicons-yes');
|
950 |
-
}
|
951 |
-
else
|
952 |
-
$('.save-indicator').removeClass('dashicons-warning').addClass('dashicons-yes');
|
953 |
-
}
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
}); // jquery
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
js/maxmodal.js
CHANGED
@@ -1,5 +1,9 @@
|
|
|
|
1 |
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
}
|
5 |
|
@@ -302,3 +306,5 @@ ex
|
|
302 |
$('.maxmodal_overlay').on('click', $.proxy(this.close, this));
|
303 |
|
304 |
}
|
|
|
|
1 |
+
var maxModal;
|
2 |
|
3 |
+
jQuery(document).ready(function(jq) {
|
4 |
+
$ = jq;
|
5 |
+
|
6 |
+
maxModal = function maxModal() {
|
7 |
|
8 |
}
|
9 |
|
306 |
$('.maxmodal_overlay').on('click', $.proxy(this.close, this));
|
307 |
|
308 |
}
|
309 |
+
|
310 |
+
}); // jquery
|
js/min/maxbuttons_media_button.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
function maxMedia(){this.callback=null,this.parent="#poststuff",this.window_loaded=null,this.maxm=null,this.closeOnCallback=!0}maxMedia.prototype.init=function(){this.maxm=new maxModal,this.maxm.init(),$(document).on("click",".maxbutton_media_button",$.proxy(this.clickAddButton,this)),this.callback="this.buttonToEditor"},maxMedia.prototype.setCallback=function(callback){if("function"!=typeof callback)if("function"==typeof window[callback])callback=window[callback];else{if("function"!=typeof eval(callback))return!1;callback=eval(callback)}this.callback=callback},maxMedia.prototype.showShortcodeOptions=function(t,a){this.closeOnCallback=!1,$currentModal=this.maxm.currentModal;var o=$('[data-button="'+t+'"]').find(".shortcode-container");options=$('<div class="shortcode_options">'),$("<input>",{type:"hidden",id:"mb_shortcode_id",name:"button_id"}).val(t).appendTo(options),$("<h3>").text("Shortcode Options").appendTo(options),$('<div class="button_example">').append(o).appendTo(options),$("<label>",{for:"mb_shortcode_url"}).text(mbtrans.short_url_label).appendTo(options),$("<input>",{type:"text",id:"mb_shortcode_url",name:"shortcode_url",placeholder:"http://"}).on("change, keyup",function(t){var a=$(t.target).val();$(".button_example").find(".maxbutton").prop("href",a)}).appendTo(options),$("<label>",{for:"mb_shortcode_text"}).text(mbtrans.short_text_label).appendTo(options),$("<input>",{type:"text",name:"shortcode_text",id:"mb_shortcode_text"}).on("change, keyup",function(t){var a=$(t.target).val();$(".button_example").find(".mb-text").text(a)}).appendTo(options),$("<p>").text(mbtrans.short_options_explain).appendTo(options),$("<input>",{type:"button",name:"add_shortcode",class:"button-primary",value:mbtrans.short_add_button}).on("click",$.proxy(this.addShortcodeOptions,this)).appendTo(options),this.maxm.setContent(options),this.maxm.checkResize()},maxMedia.prototype.addShortcodeOptions=function(t){t.preventDefault();var a=$("#mb_shortcode_url").val(),o=$("#mb_shortcode_text").val(),e=$("#mb_shortcode_id").val();this.buttonToEditor(e,a,o)},maxMedia.prototype.clickAddButton=function(t){t.preventDefault(),t.stopPropagation(),$(document).off("click",".pagination span");var a=this,o=$(t.target).data("nonce");void 0!==$(t.target).data("callback")&&this.setCallback($(t.target).data("callback")),void 0!==$(t.target).data("parent")&&(this.parent=$(t.target).data("parent")),$(document).on("click",".button-row",$.proxy(function(t){var a=$(t.target);void 0===$(a).data("button")&&(a=$(a).parents(".button-row"));var o=$(a).data("button");$(".button-row").removeClass("selected"),$(a).addClass("selected"),$(".controls .insert").data("button",o),this.maxm.currentModal.find(".controls .insert").removeClass("disabled")},this)),$(document).on("click",".pagination span, .pagination-links a",function(t){if(t.preventDefault(),$(t.target).hasClass("disabled"))return!1;var e=$(t.target).data("page");e<=1&&(e=1),a.loadPostEditScreen(e,o)}),$(document).on("change",".input-paging",function(t){t.preventDefault();var e=parseInt($(t.target).val());a.loadPostEditScreen(e,o)}),this.loadPostEditScreen(0,o)},maxMedia.prototype.loadPostEditScreen=function(t,a){void 0===t&&(t=0);var o={action:"maxajax",plugin_action:"getAjaxButtons",nonce:a,paged:t},e=mbtrans.ajax_url,n=this;return $(".media-buttons .loading").css("visibility","visible"),$.ajax({url:e,data:o,method:"POST",success:function(t){n.putResults(t)}}),!1},maxMedia.prototype.showPostEditScreen=function(){this.maxm.parent=this.parent,this.maxm.newModal("media-buttons"),this.maxm.setTitle(mbtrans.windowtitle),$(document).trigger("mb_media_buttons_open",this.maxm),this.maxm.show(),this.window_loaded=!0},maxMedia.prototype.putResults=function(t){this.showPostEditScreen(),$(".media-buttons .loading").css("visibility","hidden"),this.maxm.addControl("insert","",$.proxy(this.insertAction,this)),this.maxm.setContent(t),this.maxm.setControls(),this.maxm.checkResize(),this.resize(),$(window).on("resize",$.proxy(this.resize,this)),$(document).on("click",".maxbutton-preview",function(t){t.preventDefault()}),$(document).trigger("mb_media_put_results",[t,this.maxm])},maxMedia.prototype.resize=function(t){null!==this.maxm.currentModal&&(topHeight=this.maxm.currentModal.find(".modal_header").height()+17,controlsHeight=this.maxm.currentModal.find(".controls").height()+21,modalHeight=this.maxm.currentModal.height(),this.maxm.currentModal.find(".modal_content").css("height",modalHeight-topHeight-controlsHeight),this.maxm.currentModal.find(".controls .insert").addClass("disabled"))},maxMedia.prototype.insertAction=function(t){t.preventDefault();var a=$(t.target).data("button");void 0===a||parseInt(a)<=0||("function"==typeof this.callback&&this.callback(a,$(t.target)),this.closeOnCallback&&(this.maxm.close(),$(document).trigger("mb_media_buttons_close")))},maxMedia.prototype.buttonToEditor=function(t,a,o){var e='[maxbutton id="'+t+'"';void 0!==a&&a.length>1&&(e+=' url="'+a+'"'),void 0!==o&&o.length>1&&(e+=' text="'+o+'"'),e+=" ] ",window.send_to_editor(e),this.maxm.close()},maxMedia.prototype.getEditor=function(){var t='line-height: 32px; padding-left: 40px; background: url("'+mbtrans.icon+'") no-repeat',a=$("<div>",{id:"maxbutton-add-button",class:"content"});return a.append($("<h2>",{style:t}).text(mbtrans.insert)).append($("<p>").text(mbtrans.select)).append($("<div>",{id:"mb_media_buttons"}).append('<div class="loading"></div>')),a},window.maxMedia=new maxMedia,window.maxMedia.init();
|
1 |
+
jQuery(document).ready(function(jq){function maxMedia(){this.callback=null,this.parent="#poststuff",this.window_loaded=null,this.maxm=null,this.closeOnCallback=!0}$=jq,maxMedia.prototype.init=function(){this.maxm=new maxModal,this.maxm.init(),$(document).on("click",".maxbutton_media_button",$.proxy(this.clickAddButton,this)),this.callback="this.buttonToEditor"},maxMedia.prototype.setCallback=function(callback){if("function"!=typeof callback)if("function"==typeof window[callback])callback=window[callback];else{if("function"!=typeof eval(callback))return!1;callback=eval(callback)}this.callback=callback},maxMedia.prototype.showShortcodeOptions=function(t,a){this.closeOnCallback=!1,$currentModal=this.maxm.currentModal;var o=$('[data-button="'+t+'"]').find(".shortcode-container");options=$('<div class="shortcode_options">'),$("<input>",{type:"hidden",id:"mb_shortcode_id",name:"button_id"}).val(t).appendTo(options),$("<h3>").text("Shortcode Options").appendTo(options),$('<div class="button_example">').append(o).appendTo(options),$("<label>",{for:"mb_shortcode_url"}).text(mbtrans.short_url_label).appendTo(options),$("<input>",{type:"text",id:"mb_shortcode_url",name:"shortcode_url",placeholder:"http://"}).on("change, keyup",function(t){var a=$(t.target).val();$(".button_example").find(".maxbutton").prop("href",a)}).appendTo(options),$("<label>",{for:"mb_shortcode_text"}).text(mbtrans.short_text_label).appendTo(options),$("<input>",{type:"text",name:"shortcode_text",id:"mb_shortcode_text"}).on("change, keyup",function(t){var a=$(t.target).val();$(".button_example").find(".mb-text").text(a)}).appendTo(options),$("<p>").text(mbtrans.short_options_explain).appendTo(options),$("<input>",{type:"button",name:"add_shortcode",class:"button-primary",value:mbtrans.short_add_button}).on("click",$.proxy(this.addShortcodeOptions,this)).appendTo(options),this.maxm.setContent(options),this.maxm.checkResize()},maxMedia.prototype.addShortcodeOptions=function(t){t.preventDefault();var a=$("#mb_shortcode_url").val(),o=$("#mb_shortcode_text").val(),e=$("#mb_shortcode_id").val();this.buttonToEditor(e,a,o)},maxMedia.prototype.clickAddButton=function(t){t.preventDefault(),t.stopPropagation(),$(document).off("click",".pagination span");var a=this,o=$(t.target).data("nonce");void 0!==$(t.target).data("callback")&&this.setCallback($(t.target).data("callback")),void 0!==$(t.target).data("parent")&&(this.parent=$(t.target).data("parent")),$(document).on("click",".button-row",$.proxy(function(t){var a=$(t.target);void 0===$(a).data("button")&&(a=$(a).parents(".button-row"));var o=$(a).data("button");$(".button-row").removeClass("selected"),$(a).addClass("selected"),$(".controls .insert").data("button",o),this.maxm.currentModal.find(".controls .insert").removeClass("disabled")},this)),$(document).on("click",".pagination span, .pagination-links a",function(t){if(t.preventDefault(),$(t.target).hasClass("disabled"))return!1;var e=$(t.target).data("page");e<=1&&(e=1),a.loadPostEditScreen(e,o)}),$(document).on("change",".input-paging",function(t){t.preventDefault();var e=parseInt($(t.target).val());a.loadPostEditScreen(e,o)}),this.loadPostEditScreen(0,o)},maxMedia.prototype.loadPostEditScreen=function(t,a){void 0===t&&(t=0);var o={action:"maxajax",plugin_action:"getAjaxButtons",nonce:a,paged:t},e=mbtrans.ajax_url,n=this;return $(".media-buttons .loading").css("visibility","visible"),$.ajax({url:e,data:o,method:"POST",success:function(t){n.putResults(t)}}),!1},maxMedia.prototype.showPostEditScreen=function(){this.maxm.parent=this.parent,this.maxm.newModal("media-buttons"),this.maxm.setTitle(mbtrans.windowtitle),$(document).trigger("mb_media_buttons_open",this.maxm),this.maxm.show(),this.window_loaded=!0},maxMedia.prototype.putResults=function(t){this.showPostEditScreen(),$(".media-buttons .loading").css("visibility","hidden"),this.maxm.addControl("insert","",$.proxy(this.insertAction,this)),this.maxm.setContent(t),this.maxm.setControls(),this.maxm.checkResize(),this.resize(),$(window).on("resize",$.proxy(this.resize,this)),$(document).on("click",".maxbutton-preview",function(t){t.preventDefault()}),$(document).trigger("mb_media_put_results",[t,this.maxm])},maxMedia.prototype.resize=function(t){null!==this.maxm.currentModal&&(topHeight=this.maxm.currentModal.find(".modal_header").height()+17,controlsHeight=this.maxm.currentModal.find(".controls").height()+21,modalHeight=this.maxm.currentModal.height(),this.maxm.currentModal.find(".modal_content").css("height",modalHeight-topHeight-controlsHeight),this.maxm.currentModal.find(".controls .insert").addClass("disabled"))},maxMedia.prototype.insertAction=function(t){t.preventDefault();var a=$(t.target).data("button");void 0===a||parseInt(a)<=0||("function"==typeof this.callback&&this.callback(a,$(t.target)),this.closeOnCallback&&(this.maxm.close(),$(document).trigger("mb_media_buttons_close")))},maxMedia.prototype.buttonToEditor=function(t,a,o){var e='[maxbutton id="'+t+'"';void 0!==a&&a.length>1&&(e+=' url="'+a+'"'),void 0!==o&&o.length>1&&(e+=' text="'+o+'"'),e+=" ] ",window.send_to_editor(e),this.maxm.close()},maxMedia.prototype.getEditor=function(){var t='line-height: 32px; padding-left: 40px; background: url("'+mbtrans.icon+'") no-repeat',a=$("<div>",{id:"maxbutton-add-button",class:"content"});return a.append($("<h2>",{style:t}).text(mbtrans.insert)).append($("<p>").text(mbtrans.select)).append($("<div>",{id:"mb_media_buttons"}).append('<div class="loading"></div>')),a},window.maxMedia=new maxMedia,window.maxMedia.init()});
|
js/min/maxcollections.js
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
jQuery(document).ready(function($){maxCollection=function(){},maxCollection.prototype={fields:"",form_updated:!1,modalCurrentPage:0,item_maxwidth:0},maxCollection.prototype.init=function(){$(".collection_remove").on("click",$.proxy(this.confirmRemoveCollection,this)),0!=$("#collection_edit").length&&($(".mb-preview-window").draggable(),$(".button-picker .picker-wrapper").on("click",$.proxy(this.addButtontoCollection,this)),$(document).on("click",".sortable.buttons .button-remove",$.proxy(this.removeButton,this)),"undefined"!=typeof collectionFieldMap&&(this.fields=$.parseJSON(collectionFieldMap)),$(document).on("keyup",'.mb_ajax_save input[type="text"]',$.proxy(this.update_preview,this)),$(document).on("keyup change",".mb_ajax_save input",$.proxy(this.update_preview,this)),$(document).on("change",".mb_ajax_save select",$.proxy(this.update_preview,this)),this.initSortable(),$(document).on("click",'button[name="picker_popup"]',$.proxy(this.togglePickerPopup,this)),$(document).on("updatePreviewWindow",$.proxy(this.updatePlacement,this)),$(document).on("mbFormSaved",$.proxy(function(){this.form_updated=!1,this.toggleSaveIndicator(!1)},this)),$(window).on("beforeunload",$.proxy(function(){if(this.form_updated)return maxcol_wp.leave_page},this)),$(document).on("click","#exportCollection",$.proxy(this.exportCollection,this)),this.updatePlacement(),this.updatePlacement(),""==$('input[name="sorted"]').val()&&this.togglePickerPopup())},maxCollection.prototype.addButtontoCollection=function(t){var e=$(t).clone(),o=e.data("id");e.find(".button_name").remove();var a=e,i=a.find(".button_data").text();a.find(".button_data").remove(),a.append('<input type="hidden" name="button-data-'+o+'" value="'+i+'">'),this.addButtontoPreview(e.clone()),$(a).appendTo(".mb_collection_selection .sortable "),$(".mb_collection_selection .sortable").sortable("refresh");var n=$(".mb_collection_selection .sortable").sortable("toArray",{attribute:"data-id"}),c=n.length;n=n.toString(),$('input[name="sorted"]').val(n),$.proxy(this.updateColPreview({action:"new_button",data:i,button_id:o,button_count:c}),this)},maxCollection.prototype.updateColPreview=function(t){if(void 0!==t.action)var e=t.action;else e="";var o=$('input[name="block_nonce"]').val(),a=$('input[name="collection_id"]').val(),i=$('input[name="collection_type"]').val(),n=t.button_count-1;if("new_button"==e){var c={block_name:"social",block_action:"ajax_new_button",action:"mbpro_collection_block",nonce:o,collection_id:a,collection_type:i,block_data:{data:t.data,button_id:t.button_id,index:n}};$.proxy(this.ajaxNewButton(c),this)}},maxCollection.prototype.addButtontoPreview=function(t){t.find("input").remove(),t.find(".dashicons").remove();var e=t.data("id");$("<span class='mb-collection-item' data-id='"+e+"'></span>").append(t.children()).appendTo(".mb-preview-window .maxcollection"),this.updatePlacement()},maxCollection.prototype.ajaxNewButton=function(t){var e=mb_ajax.ajaxurl;$.ajax({type:"POST",url:e,data:t}).done($.proxy(this.ajaxNewButtonDone,this))},maxCollection.prototype.ajaxNewButtonDone=function(t){var e=$.parseJSON(t);$('.mb_tab[data-tab="social-options"]').children(".inside").append(e.body),$(".no-buttons").hide(),$(document).trigger("reInitConditionals")},maxCollection.prototype.update_preview=function(e){e.preventDefault(),this.toggleSaveIndicator(!0);var target=$(e.target),id=$(target).attr("id");void 0!==$(target).data("target")&&(id=$(target).data("target"));var data=this.fields[id];void 0!==data&&(void 0!==data.css&&(value=target.val(),void 0!==data.css_unit&&-1==value.indexOf(data.css_unit)&&(value+=data.css_unit),this.putCSS(data,value)),void 0!==data.attr&&$(".output .result").find("a").attr(data.attr,target.val()),void 0!==data.func&&eval("this."+data.func+"(target)"),this.updatePlacement())},maxCollection.prototype.putCSS=function(t,e,o){o=o||"both";var a=".maxcollection";if(void 0!==t.csspart){var n=t.csspart.split(",");for(i=0;i<n.length;i++){var c=n[i];if(a!=="."+c)l=a+" ."+c;else var l=a;$(".mb-preview-wrapper").find(l).css(t.css,e)}}else $(".output .result").find(a).css(t.css,e)},maxCollection.prototype.updatePlacement=function(){var t=$("#orientation").val();if(void 0!==t&&"auto"!==t)this.pushPreview(t);else if("auto"==t){var e=$("#placement").val();t="static-left"==e||"static-right"==e?"vertical":"horizontal",this.pushPreview(t)}},maxCollection.prototype.updateCollectionName=function(){var t=$("#collection_name").val();t=t.MBescapeHTML();var e=$(".mb-message.shortcode").html();e&&(e=e.replace(/\[maxcollection name="(.*)"]/gi,'[maxcollection name="'+t+'"]'),$(".mb-message.shortcode").html(e))};var __entityMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"};String.prototype.MBescapeHTML=function(){return String(this).replace(/[&<>"'\/]/g,function(t){return __entityMap[t]})},maxCollection.prototype.parseTags=function(t){var e=$(t).parents(".social-option"),o=$(".social-option").index(e),a=$(".mb-preview-window .mb-collection-item").eq(o),i=$(e).find(".maxbutton"),n={network_name:$(e).find('[data-target="network"] :selected').text(),count:0},c=$(a).find(".mb-text"),l=$(a).find(".mb-text2"),r=$(i).find(".mb-text").text(),d=$(i).find(".mb-text2").text();$(c).text(r),$(l).text(d),this.replaceTags(c,n),this.replaceTags(l,n)},maxCollection.prototype.replaceTags=function(t,e){var o=$(t).text();void 0===$(t).data("original")?$(t).data("original",o):o=$(t).data("original"),$.each(e,function(e,a){o=o.replace("{"+e+"}",a),$(t).text(o)})},maxCollection.prototype.pushPreview=function(t){var e=$(".mb-preview-window.output"),o=$(".mb-preview-window .mb-collection-item"),a=$(".mb-preview-window .maxcollection").height()+75;o.css("float","left"),"relative"!=e.css("position")&&("horizontal"==t&&(e.css("width",$("#maxbuttons").css("width")),e.css("top","auto"),e.css("bottom","10px"),e.css("height",a+"px"),e.css("right","10px"),e.css("left","auto"),o.css("clear","none")),"vertical"==t&&(e.css("width","30%"),e.css("right","20px"),e.css("top","25%"),e.css("height",a+"px"),e.css("left","auto"),e.css("bottom","auto"),o.css("clear","both")))},maxCollection.prototype.exportCollection=function(){var t={block_name:"export",block_action:"export",action:"mbpro_collection_block",nonce:$('input[name="block_nonce"]').val(),collection_id:$('input[name="collection_id"]').val(),collection_type:$('input[name="collection_type"]').val(),block_data:{}},e=mb_ajax.ajaxurl;$.ajax({type:"POST",url:e,data:t}).done(function(t){var e=$.parseJSON(t).data.location;window.location.href=e})},maxCollection.prototype.checkPicker=function(){$(".mb_collection_picker").is(":visible")&&this.initButtonPicker()},maxCollection.prototype.initSortable=function(){var t=this;$(".mb_collection_selection .sortable").sortable({placeholder:"sortable-placeholder",connectWith:".maxcollection",start:function(t,e){iBefore=e.item.index()},create:function(t,e){var o=$(this).sortable("toArray",{attribute:"data-id"}).toString();$('input[name="sorted"]').val(o),$('input[name="previous_selection"]').val(o)},update:function(e,o){iAfter=o.item.index();var a=$(this).sortable("toArray",{attribute:"data-id"}).toString();$('input[name="sorted"]').val(a),t.updateListOrder(".maxcollection .mb-collection-item",iBefore,iAfter),t.updateListOrder(".social_block .social-option",iBefore,iAfter)}})},maxCollection.prototype.removeButton=function(t){t.preventDefault();$('input[name="sorted"]').val();var e=$(t.currentTarget).parents(".item"),o=$(".mb_collection_selection .sortable .item").index(e);$(t.currentTarget).parents(".item").remove(),$(".maxcollection .mb-collection-item:eq("+o+")").remove(),$(".social_block .social-option:eq("+o+")").remove(),$(".mb_collection_selection .sortable").sortable("refresh");var a=$(".mb_collection_selection .sortable").sortable("toArray",{attribute:"data-id"}).toString();$('input[name="sorted"]').val(a),this.toggleSaveIndicator(!0)},maxCollection.prototype.updateListOrder=function(t,e,o){if(this.toggleSaveIndicator(!0),evictee=$(t+":eq("+o+")"),evictor=$(t+":eq("+e+")"),evictee.replaceWith(evictor),iBefore>iAfter?evictor.after(evictee):evictor.before(evictee),".social_block .social-option"==t)$(t).each(function(t){var e=$(this).data("id"),o=$(this).html(),a=new RegExp("-"+e+"-\\d","gi");o=o.replace(a,"-"+e+"-"+t),$(this).html(o)})},maxCollection.prototype.confirmRemoveCollection=function(t){var e=$(t.target).parents(".collection").data("id"),o=$(t.target).parents(".collection").data("blocknonce"),a=$(t.target).parents(".collection").data("type"),i=$(".remove_action_title").text(),n="<p>"+$(".remove_action_text").text()+"</p>",c=window.maxFoundry.maxmodal;c.newModal("collection_remove"),c.setTitle(i),c.setContent(n),c.addControl("yes",{collection_id:e,nonce:o,collection_type:a},$.proxy(this.removeCollection,this)),c.addControl("no","",$.proxy(c.close,c)),c.setControls(),c.show()},maxCollection.prototype.removeCollection=function(t){var e=t.data.collection_id,o={block_name:"collection",block_action:"delete",action:"mbpro_collection_block",nonce:t.data.nonce,collection_id:e,collection_type:t.data.collection_type,block_data:{}},a=mb_ajax.ajaxurl;$.ajax({type:"POST",url:a,data:o}).done(function(t){var e=$.parseJSON(t),o=window.maxFoundry.maxmodal,a=e.data.title,i=e.data.body,n=e.data.collection_id;o.newModal("collection_removed"),o.setTitle(a),o.setContent(i),o.addControl("ok","",$.proxy(o.close,o)),o.setControls(),o.show(),$(".collection-"+n).hide()})},maxCollection.prototype.togglePickerPopup=function(t){var e=window.maxFoundry.maxmodal,o=$("#picker-modal").html();e.newModal("picker-modal"),e.setTitle(maxcol_wp.picker_title),e.setContent(o),e.show(),modal=e.get(),$(modal).off("click change keyup"),$(modal).on("click",".picker-packages a",$.proxy(this.getModalButtons,this)),$(modal).on("click",".picker-main .screen .item",$.proxy(this.toggleInSelection,this)),$(modal).on("click",".modal_close",$.proxy(e.close,e)),$(modal).on("click",".clear-selection",$.proxy(this.modalClearSelection,this)),$(modal).on("click",'button[name="add-buttons"]',$.proxy(this.modalAddButtons,this)),$(modal).on("click",".button-remove",$.proxy(this.modalDeleteButton,this)),$(modal).on("click",".pagination-links a",$.proxy(this.modalLoadPage,this)),$(modal).on("change keyup",".pagination-links input",$.proxy(this.modalLoadPage,this)),0==$(modal).find(".picker-main .current-screen").length&&$(modal).find(".picker-packages ul li a:first").trigger("click")},maxCollection.prototype.getModalButtons=function(t){t.preventDefault();var e=window.maxFoundry.maxmodal.get(),o=$(t.target),a=$(t.target).data("pack"),i=$(t.target).data("pack-loaded");if(void 0!==i&&i)return $(e).find(".picker-main .screen").hide().removeClass("current-screen"),$(e).find(".picker-main .screen-"+a).show().addClass("current-screen"),this.modalEqualHeight(),$(e).find(".picker-packages ul li a").removeClass("pack-active"),void $(t.target).addClass("pack-active");var n=$('input[name="collection_id"]').val(),c=$('input[name="collection_type"]').val(),l={block_name:"collection",block_action:"ajax_getButtons",action:"mbpro_collection_block",nonce:$('input[name="block_nonce"]').val(),collection_id:n,collection_type:c,block_data:{pack:a}},r=mb_ajax.ajaxurl,d=this;$.ajax({type:"POST",url:r,data:l}).done(function(t){d.modalLoadButtons(t,a,o)})},maxCollection.prototype.modalLoadButtons=function(t,e,o){var a=this,i=window.maxFoundry.maxmodal.get();$(i).find(".picker-main .screen").hide().removeClass("current-screen");var n=$.parseJSON(t);if(0==$(i).find(".picker-main .screen-"+e).length){c=$('<div class="screen screen-'+e+'">');$(i).find(".picker-main").append(c)}else var c=$(i).find(" .picker-main .screen-"+e);c.html(n.body),$(i).find(".picker-main .screen-"+e).show().addClass("current-screen"),setTimeout($.proxy(function(){$(i).find(".picker-main .current-screen .item").each(function(){a.modalScaleButton(this)})},this),400),this.modalEqualHeight(),$(o).data("pack-loaded",!0),$(i).find(".picker-packages ul li a").removeClass("pack-active"),$(o).addClass("pack-active"),$(document).trigger("mb-modalLoadButtons")},maxCollection.prototype.modalLoadPage=function(t){t.preventDefault();if(void 0===(e=$(t.target).data("page"))){if("number"!=t.target.type)return;var e=$(t.target).val()}var o=$('input[name="collection_id"]').val(),a=$('input[name="collection_type"]').val(),i=$('input[name="block_nonce"]').val(),n=$(".picker-packages a.pack-active").data("pack"),c=$(".picker-packages a.pack-active"),l={block_name:"collection",block_action:"ajax_getButtons",action:"mbpro_collection_block",nonce:i,collection_id:o,collection_type:a,block_data:{pack:n,paged:e}},r=mb_ajax.ajaxurl,d=this;$.ajax({type:"POST",url:r,data:l}).done(function(t){d.modalLoadButtons(t,n,c)})},maxCollection.prototype.toggleInSelection=function(t){var e=$(t.target),o=window.maxFoundry.maxmodal.get();if(!e.hasClass("item"))e=$(t.target).parents(".item");var a=$(e).data("id");if($(o).find(".picker-inselection .items").children('[data-id="'+a+'"]').length>0)return $(e).find(".button-selected").remove(),$(o).find(".picker-inselection .items").children('[data-id="'+a+'"]').remove(),void this.modalUpdateCount();var i=$(e).clone();$(i).find(".dashicons").remove(),$(i).css("height","100%"),$(i).css("width","40px"),$(i).find("a").css("verticalAlign","middle"),0==$(e).children(".button-selected").length&&$(e).append('<div class="button-selected"><span class="dashicons dashicons-yes">'),i.append('<div class="button-remove"><span class="dashicons dashicons-no">'),$(o).find(".picker-inselection .items").append(i),this.modalScaleButton(i),this.modalUpdateCount()},maxCollection.prototype.modalEqualHeight=function(t){var e=0;$(modal).find(".picker-main .current-screen .item").each(function(){$(this).height()>e&&(e=$(this).height())}),e>0&&$(modal).find(".picker-main .current-screen .item").height(e)},maxCollection.prototype.modalScaleButton=function(t){var e=$(t).width();$(t).css("width","100%");var o=$(t).find("a"),a=$(o).width(),n=$(o).height();if($(t).css("width",e),!(e>=a)){var c=e/a;c=c.toFixed(2);var l=$(t).find("a"),r="width: calc("+a+"px * "+c+")!important; height: calc("+n+"px * "+c+") !important;";l.css("cssText",r),l.children(".mb-text").each(function(){$(this).css("fontSize");var t=["font-size","padding-left","padding-right","padding-top","padding-bottom"],e="";for(i=0;i<t.length;i++)if(parseInt($(this).css(t[i]))>0){var o=$(this).css(t[i]);e+=t[i]+": calc("+o+" * "+c+") !important; "}$(this).css("cssText",e)}),$icon=l.children(".mb-icon");var d=$icon.width(),s=$icon.height(),p="width: calc("+d+"px * "+c+") !important; height: calc("+s+"px * "+c+") !important;";$icon.css("cssText",p);var m=$icon.children("img");if(m.length>0){var d=m.width(),s=m.height(),p="width: calc("+d+"px * "+c+") !important; height: calc("+s+"px * "+c+") !important;";m.css("cssText",p)}}},maxCollection.prototype.unScaleButton=function(t){t.find("a, .mb-text, .mb-icon, img").css("cssText",""),t.css("cssText","")},maxCollection.prototype.modalClearSelection=function(t){var e=window.maxFoundry.maxmodal.get();$(e).find(".picker-inselection .items").html(""),$(e).find(".screen .item .button-selected").remove(),this.modalUpdateCount()},maxCollection.prototype.modalAddButtons=function(t){t.preventDefault;var e=this,o=window.maxFoundry.maxmodal,a=window.maxFoundry.maxmodal.get();$(a).find(".picker-inselection .items .item").each(function(){var t=$(this).clone().wrap("<div>").parent().html(),o=$(t);e.unScaleButton(o),e.addButtontoCollection(o)}),o.close(),this.modalClearSelection()},maxCollection.prototype.modalUpdateCount=function(t){var e=window.maxFoundry.maxmodal.get(),o=$(e).find(".picker-inselection .items .item").length;$(e).find(".picker-inselection .info .count").text(o),0==o?$(e).find(".picker-inselection .info").hide():$(e).find(".picker-inselection .info").show()},maxCollection.prototype.modalDeleteButton=function(t){var e=$(t.target).parents(".item"),o=e.data("id");$(".picker-main").find('[data-id="'+o+'"]').children(".button-selected").remove(),e.remove(),this.modalUpdateCount()},maxCollection.prototype.toggleSaveIndicator=function(t){t?(this.form_updated=!0,$(".save-indicator").css("display","block").addClass("dashicons-warning").removeClass("dashicons-yes")):$(".save-indicator").removeClass("dashicons-warning").addClass("dashicons-yes")}});
|
|
js/min/maxmodal.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
1 |
+
var maxModal;jQuery(document).ready(function(t){$=t,(maxModal=function(){}).prototype={currentModal:null,modals:[],controls:[],parent:"#maxbuttons",multiple:!1,windowHeight:!1,windowWidth:!1,setWidth:!1,setHeight:!1,target:!1},maxModal.prototype.init=function(){this.windowHeight=$(window).height(),this.windowWidth=$(window).width(),$(document).off("click",".maxmodal"),$(document).on("click",".maxmodal",$.proxy(this.buildModal,this)),$(window).on("resize",$.proxy(this.checkResize,this))},maxModal.prototype.focus=function(){this.currentModal.show()},maxModal.prototype.get=function(){return this.currentModal},maxModal.prototype.show=function(){$(".maxmodal_overlay").remove(),$("body").removeClass("max-modal-active"),this.writeOverlay(),this.setWidth&&this.currentModal.width(this.setWidth),this.setHeight&&this.currentModal.height(this.setHeight);var t=this.currentModal.height(),o=this.currentModal.width(),e=(this.windowHeight-t)/2,a=(this.windowWidth-o)/2;e<30&&(e=30),t>this.windowHeight&&this.currentModal.height(this.windowHeight-e-5+"px"),this.currentModal.css("left",a+"px"),this.currentModal.css("top",e+"px"),this.currentModal.css("height",t),this.currentModal.show(),$(".maxmodal_overlay").show(),$("body").addClass("max-modal-active"),$(document).off("keydown",$.proxy(this.keyPressHandler,this)),$(document).on("keydown",$.proxy(this.keyPressHandler,this)),this.currentModal.focus()},maxModal.prototype.keyPressHandler=function(t){27===t.keyCode&&this.close()},maxModal.prototype.checkResize=function(){this.windowHeight=$(window).height(),this.windowWidth=$(window).width(),null!==this.currentModal&&(this.currentModal.removeAttr("style"),this.currentModal.find(".modal_content").removeAttr("style"),this.show())},maxModal.prototype.close=function(){this.currentModal.trigger("modal_close",[this]),this.currentModal.remove(),this.currentModal=null,$(".maxmodal_overlay").remove(),$("body").removeClass("max-modal-active"),$(document).off("keydown",$.proxy(this.keyPressHandler,this))},maxModal.prototype.fadeOut=function(t){void 0==typeof t&&(t=600);var o=this;this.currentModal.fadeOut(t,function(){o.close()})},maxModal.prototype.setTitle=function(t){this.currentModal.find(".modal_title").text(t)},maxModal.prototype.setControls=function(t){var o=this.currentModal.find(".modal_content"),e=$('<div class="controls">');for(i=0;i<this.controls.length;i++)e.append(this.controls[i]);void 0!==t&&e.append(t),o.append(e),$(this.currentModal).find(".modal_close").off("click"),$(this.currentModal).find(".modal_close").on("click",$.proxy(this.close,this))},maxModal.prototype.addControl=function(t,o,e){var a="";switch(t){case"yes":a=modaltext.yes;break;case"ok":a=modaltext.ok;break;case"no":a=modaltext.no;break;case"cancel":a=modaltext.cancel;break;case"insert":a=mbtrans.insert}var i=$('<a class="button-primary '+t+'">'+a+"</a>");i.on("click",o,e),this.controls.push(i)},maxModal.prototype.setContent=function(t){this.currentModal.find(".modal_content").html(t)},maxModal.prototype.buildModal=function(t){t.preventDefault();var o=$(t.target);void 0===o.data("modal")&&(o=o.parents(".maxmodal")),this.target=o;var e=o.data("modal"),a=$("#"+e);void 0!==a.data("width")?this.setWidth=a.data("width"):this.setWidth=!1,void 0!==a.data("height")?this.setHeight=a.data("height"):this.setHeight=!1;var i=$(a).find(".title").text(),d=$(a).find(".controls").html(),s=$(a).find(".content").html();if(this.newModal(e),this.setTitle(i),this.setContent(s),this.setControls(d),void 0!==$(a).data("load")){var n=a.data("load")+"(modal)",l=new Function("modal",n);try{l(this)}catch(t){ex,console.log("MB Modal Callback Error: "+t.message),console.log("MB Mobdal tried calling: "+n)}}this.show()},maxModal.prototype.newModal=function(t){null!==this.currentModal&&this.close();var o=$('<div class="max-modal '+t+'" > \t\t\t\t\t\t <div class="modal_header"> \t\t\t\t\t\t\t <div class="modal_close dashicons dashicons-no"></div><h3 class="modal_title"></h3> \t\t\t\t\t\t </div> \t\t\t\t\t\t <div class="inner modal_content"></div>\t\t\t\t\t </div>');return $(this.parent).length>0?$(this.parent).append(o):$("body").append(o),$(o).draggable({handle:".modal_header"}),this.modals.push(o),this.currentModal=o,this.controls=[],this},maxModal.prototype.writeOverlay=function(){$(this.parent).append('<div class="maxmodal_overlay"></div>'),$(".maxmodal_overlay").on("click",$.proxy(this.close,this))}});
|
maxbuttons.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: MaxButtons
|
4 |
Plugin URI: http://maxbuttons.com
|
5 |
Description: The best WordPress button generator. This is the free version; the Pro version <a href="http://maxbuttons.com/?ref=mbfree">can be found here</a>.
|
6 |
-
Version: 7.1.
|
7 |
Author: Max Foundry
|
8 |
Author URI: http://maxfoundry.com
|
9 |
Text Domain: maxbuttons
|
@@ -16,9 +16,9 @@ namespace MaxButtons;
|
|
16 |
if (! defined('MAXBUTTONS_ROOT_FILE'))
|
17 |
define("MAXBUTTONS_ROOT_FILE", __FILE__);
|
18 |
if (! defined('MAXBUTTONS_VERSION_NUM'))
|
19 |
-
define('MAXBUTTONS_VERSION_NUM', '7.1.
|
20 |
|
21 |
-
define('MAXBUTTONS_RELEASE',"
|
22 |
|
23 |
|
24 |
if (! function_exists('MaxButtons\maxbutton_double_load'))
|
@@ -55,13 +55,9 @@ require_once("classes/block.php");
|
|
55 |
require_once('classes/field.php');
|
56 |
require_once('classes/blocks.php');
|
57 |
|
58 |
-
|
59 |
require_once("classes/maxCSSParser.php");
|
60 |
require_once("classes/admin-class.php");
|
61 |
|
62 |
-
require_once("classes/collections.php");
|
63 |
-
require_once("classes/collection.php");
|
64 |
-
require_once("classes/collection-block.php");
|
65 |
require_once("classes/pack.php");
|
66 |
require_once("classes/integrations.php");
|
67 |
|
3 |
Plugin Name: MaxButtons
|
4 |
Plugin URI: http://maxbuttons.com
|
5 |
Description: The best WordPress button generator. This is the free version; the Pro version <a href="http://maxbuttons.com/?ref=mbfree">can be found here</a>.
|
6 |
+
Version: 7.1.3
|
7 |
Author: Max Foundry
|
8 |
Author URI: http://maxfoundry.com
|
9 |
Text Domain: maxbuttons
|
16 |
if (! defined('MAXBUTTONS_ROOT_FILE'))
|
17 |
define("MAXBUTTONS_ROOT_FILE", __FILE__);
|
18 |
if (! defined('MAXBUTTONS_VERSION_NUM'))
|
19 |
+
define('MAXBUTTONS_VERSION_NUM', '7.1.3');
|
20 |
|
21 |
+
define('MAXBUTTONS_RELEASE',"27 Apr 2018");
|
22 |
|
23 |
|
24 |
if (! function_exists('MaxButtons\maxbutton_double_load'))
|
55 |
require_once('classes/field.php');
|
56 |
require_once('classes/blocks.php');
|
57 |
|
|
|
58 |
require_once("classes/maxCSSParser.php");
|
59 |
require_once("classes/admin-class.php");
|
60 |
|
|
|
|
|
|
|
61 |
require_once("classes/pack.php");
|
62 |
require_once("classes/integrations.php");
|
63 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: wordpress button plugin, share button, wordpress buttons, css3 button gene
|
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 4.9.5
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 7.1.
|
8 |
|
9 |
WordPress button plugin so powerful and easy to use anyone can create beautiful buttons, share buttons and social icons.
|
10 |
|
@@ -251,6 +251,10 @@ Secondly, please use latin only characters for button name ( Basic settings) and
|
|
251 |
|
252 |
== Changelog ==
|
253 |
|
|
|
|
|
|
|
|
|
254 |
= 7.1.1 / 7.1.2 =
|
255 |
|
256 |
* Fixed issue when other sources call jQuery.noConfict()
|
@@ -399,6 +403,10 @@ Secondly, please use latin only characters for button name ( Basic settings) and
|
|
399 |
|
400 |
== Upgrade Notice ==
|
401 |
|
|
|
|
|
|
|
|
|
402 |
= 4.0 =
|
403 |
|
404 |
This major update includes new Social sharing features. If you run into issues please let us know via support. Experiences are also welcome!
|
4 |
Requires at least: 4.8
|
5 |
Tested up to: 4.9.5
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 7.1.3
|
8 |
|
9 |
WordPress button plugin so powerful and easy to use anyone can create beautiful buttons, share buttons and social icons.
|
10 |
|
251 |
|
252 |
== Changelog ==
|
253 |
|
254 |
+
= 7.1.3. =
|
255 |
+
|
256 |
+
* Fixed legacy issue with social share that could crash plugin in certain cases
|
257 |
+
|
258 |
= 7.1.1 / 7.1.2 =
|
259 |
|
260 |
* Fixed issue when other sources call jQuery.noConfict()
|
403 |
|
404 |
== Upgrade Notice ==
|
405 |
|
406 |
+
= 7. 0 =
|
407 |
+
|
408 |
+
Social Share has been split of into it's own plugin. Check your site if you are using this feature.
|
409 |
+
|
410 |
= 4.0 =
|
411 |
|
412 |
This major update includes new Social sharing features. If you run into issues please let us know via support. Experiences are also welcome!
|