PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
← All changes | classes/pack.php +68 -77 7.06.28 View file →
@@ -1,5 +1,5 @@
1 -<?php
1 +<?php
2 2 namespace MaxButtons;
3 3 defined('ABSPATH') or die('No direct access permitted');
4 4
5 5 // basic pack reading functionality for social buttons
@@ -4,89 +4,89 @@
4 4
5 5 // basic pack reading functionality for social buttons
6 6 class maxPack
7 7 {
8 - protected $default_img_url = '';
8 + protected $default_img_url = '';
9 9
10 10 protected $pack_path = ''; // path of the pack with trailing slash
11 - protected $pack_dir = ''; // the name of the packs directory without path.
12 - protected $pack_xml = '';
13 - protected $pack_url = '';
11 + protected $pack_dir = ''; // the name of the packs directory without path.
12 + protected $pack_xml = '';
13 + protected $pack_url = '';
14 +
15 +
16 + protected $img = '';
17 + protected $name = '';
18 + protected $author = '';
19 + protected $author_url = '';
20 + protected $description = '';
21 + protected $is_local = true;
14 22
15 23
16 - protected $img = '';
17 - protected $name = '';
18 - protected $author = '';
19 - protected $author_url = '';
20 - protected $description = '';
21 - protected $is_local = true;
22 -
23 -
24 24 public function setPackPath($path)
25 25 {
26 26 $this->pack_path = $path;
27 27 }
28 28
29 - public function getName()
29 + public function getName()
30 30 {
31 31 return $this->name;
32 32 }
33 -
33 +
34 34 public function getAuthor()
35 35 {
36 36 return $this->author;
37 37 }
38 -
38 +
39 39 public function getDescription()
40 40 {
41 41 return $this->description;
42 42 }
43 -
44 -
43 +
44 +
45 45 public function load_pack($packdata)
46 46 {
47 - $pack_file = $packdata["file"];
48 - $pack_img = $packdata["img"];
47 + $pack_file = $packdata["file"];
48 + $pack_img = $packdata["img"];
49 49 $this->pack_dir = $packdata["dir"];
50 50
51 - $xml = simplexml_load_file($pack_file,null, LIBXML_NOCDATA);
52 -
53 - if (! $xml)
51 + $xml = simplexml_load_file($pack_file,null, LIBXML_NOCDATA);
52 +
53 + if (! $xml)
54 54 {
55 55 MB()->add_notice('error', __( sprintf('Pack file could not be loaded', $pack_file), 'maxbuttons'));
56 56 return false;
57 57 }
58 - $this->pack_xml = $xml;
59 -
58 + $this->pack_xml = $xml;
59 +
60 60 $pack = $xml->pack[0];
61 61 $packset = current($pack->attributes());
62 62 $packset["image"] = $pack_img;
63 63 $packset["is_local"] = $packdata["is_local"];
64 64
65 - $this->set_pack($packset);
65 + $this->set_pack($packset);
66 66 return true; // success
67 67 }
68 -
69 - /* Return the full XML of the pack */
68 +
69 + /* Return the full XML of the pack */
70 70 public function getPackXML()
71 71 {
72 72 return $this->pack_xml;
73 - }
73 + }
74 74
75 - /* Set all the pack attributes */
75 + /* Set all the pack attributes */
76 76 function set_pack($pack)
77 77 {
78 - $this->img = (isset($pack["image"])) ? $pack["image"] : '';
79 - $this->name = (isset($pack["name"])) ? $pack["name"] : '';
80 - $this->author = (isset($pack["author"])) ? $pack["author"] : '';
81 - $this->authorurl = (isset($pack["author_url"])) ? $pack["author_url"] : '';
82 - $this->description = (isset($pack["description"])) ? $pack["description"] : '';
78 + $this->img = (isset($pack["image"])) ? $pack["image"] : '';
79 + $this->name = (isset($pack["name"])) ? $pack["name"] : '';
80 + $this->author = (isset($pack["author"])) ? $pack["author"] : '';
81 + $this->authorurl = (isset($pack["author_url"])) ? $pack["author_url"] : '';
82 + $this->description = (isset($pack["description"])) ? $pack["description"] : '';
83 83 $this->is_local = $pack["is_local"];
84 - if (isset($pack["pack_dir"]))
85 - $this->pack_dir = $pack["pack_dir"];
86 - if (isset($pack["pack_url"]))
87 - $this->pack_url = $pack["pack_url"];
88 -
84 + if (isset($pack["pack_dir"]))
85 + $this->pack_dir = $pack["pack_dir"];
86 + if (isset($pack["pack_url"]))
87 + $this->pack_url = $pack["pack_url"];
88 +
89 89 }
90 90
91 91
92 92 /* Parses old format and current format pack XML into a button_array which button setupdata understands */
@@ -91,78 +91,69 @@
91 91
92 92 /* Parses old format and current format pack XML into a button_array which button setupdata understands */
93 93 public function parse_pack_button($xmlbutton)
94 94 {
95 - $button = MB()->getClass("button");
95 + $button = MB()->getClass("button");
96 96 if ( count($xmlbutton->attributes()) > 0) // old button
97 97 {
98 98
99 - $attrs = current($xmlbutton->attributes());
99 + $attrs = current($xmlbutton->attributes());
100 +
101 + $data = MB()->getClass("install")->convertOldFields($attrs);
100 102
101 - $data = MB()->getClass("install")->convertOldFields($attrs);
102 -
103 103 $button_array = array();
104 - $button_array["status"] = $data["status"];
104 + $button_array["status"] = $data["status"];
105 105
106 106 $data = $button->save($data,false); // convert from post var to block struct without dbase save
107 107
108 108
109 - foreach($data as $block => $values)
110 - {
111 - if (is_array($values))
109 + foreach($data as $block => $values)
110 + {
111 + if (is_array($values))
112 112 $button_array[$block] = json_encode($values);
113 113 else
114 - $button_array[$block] = $values;
114 + $button_array[$block] = $values;
115 115 }
116 -
116 +
117 117 }
118 118 else // new button
119 119 {
120 - //$button = MB()->getClass("button");
120 + //$button = MB()->getClass("button");
121 121
122 122 $button_array = json_decode(json_encode( (array)$xmlbutton), TRUE);
123 -
123 +
124 124 // $data = $button->save($button_array, false);
125 125 }
126 126 $temp_id = floor(rand(100000,990000));
127 127 $button_array["id"] = $temp_id; // fingers crossed
128 -
128 +
129 129 // for some reason on json_decode when value is empty it created an empty array instead of string.
130 130 foreach($button_array as $name => $values)
131 131 {
132 - if (is_array($values) && count($values) == 0)
133 - $button_array[$name] = '';
132 + if (is_array($values) && count($values) == 0)
133 + $button_array[$name] = '';
134 134 }
135 135
136 136
137 137 // icons from pack
138 - $icon_array = array();
139 -
140 - if (isset($button_array["icon"]))
141 - {
142 - $icon_array = maybe_unserialize($button_array["icon"]);
138 + $icon_array = array();
139 +
140 + if (isset($button_array["icon"]))
141 + {
142 + $icon_array = maybe_unserialize($button_array["icon"]);
143 143 if (! is_array($icon_array)) // moving to json_encode
144 - $icon_array = json_decode($button_array["icon"], true);
144 + $icon_array = json_decode($button_array["icon"], true);
145 145
146 - if (isset($icon_array["icon_url"]) && $icon_array["icon_url"] != '') {
147 - $path = str_replace(array('http:','https:'), '', $this->pack_path); // allow for SSL / HTTP
148 - $icon_array["icon_url"] = $path . $icon_array["icon_url"]; // pack path to allow for remote images
149 - }
150 - if (isset($icon_array['fa_icon_value']) && strlen($icon_array['fa_icon_value']) > 0)
151 - {
152 - $conversion_path = MB()->get_plugin_path() . '/assets/libraries/font-awesome-5/shims.json';
153 - $conversion_array = json_decode(file_get_contents($conversion_path), ARRAY_A);
154 - $old_value = $icon_array['fa_icon_value'];
155 - $old_value = str_replace('fa-','', $old_value);
156 - $icon_array['fa_icon_value'] = maxInstall::searchNewFA($old_value, $conversion_array);
157 -
158 - }
159 -
160 - $button_array['icon'] = json_encode($icon_array);
161 146 }
147 + if (isset($icon_array["icon_url"]) && $icon_array["icon_url"] != '') {
148 + $path = str_replace(array('http:','https:'), '', $this->pack_path); // allow for SSL / HTTP
149 + $icon_array["icon_url"] = $path . $icon_array["icon_url"]; // pack path to allow for remote images
150 + $button_array["icon"] = json_encode($icon_array);
151 + }
162 152
163 - return $button_array;
153 + return $button_array;
164 154 }
165 155
166 156
167 157
168 158 } // class
159 +