PluginProbe
MaxButtons – Create buttons / 6.3
MaxButtons – Create buttons v6.3
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
maxbuttons / classes / pack.php

pack.php in MaxButtons – Create buttons 6.3, at classes/pack.php

159 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') or die('No direct access permitted');
3
4 // basic pack reading functionality for social buttons
5 class maxPack
6 {
7 protected $default_img_url = '';
8
9 protected $pack_path = ''; // path of the pack with trailing slash
10 protected $pack_dir = ''; // the name of the packs directory without path.
11 protected $pack_xml = '';
12 protected $pack_url = '';
13
14
15 protected $img = '';
16 protected $name = '';
17 protected $author = '';
18 protected $author_url = '';
19 protected $description = '';
20 protected $is_local = true;
21
22
23 public function setPackPath($path)
24 {
25 $this->pack_path = $path;
26 }
27
28 public function getName()
29 {
30 return $this->name;
31 }
32
33 public function getAuthor()
34 {
35 return $this->author;
36 }
37
38 public function getDescription()
39 {
40 return $this->description;
41 }
42
43
44 public function load_pack($packdata)
45 {
46 $pack_file = $packdata["file"];
47 $pack_img = $packdata["img"];
48 $this->pack_dir = $packdata["dir"];
49
50 $xml = simplexml_load_file($pack_file,null, LIBXML_NOCDATA);
51
52 if (! $xml)
53 {
54 MB()->add_notice('error', __( sprintf('Pack file could not be loaded', $pack_file), 'maxbuttons'));
55 return false;
56 }
57 $this->pack_xml = $xml;
58
59 $pack = $xml->pack[0];
60 $packset = current($pack->attributes());
61 $packset["image"] = $pack_img;
62 $packset["is_local"] = $packdata["is_local"];
63
64 $this->set_pack($packset);
65 return true; // success
66 }
67
68 /* Return the full XML of the pack */
69 public function getPackXML()
70 {
71 return $this->pack_xml;
72 }
73
74 /* Set all the pack attributes */
75 function set_pack($pack)
76 {
77 $this->img = (isset($pack["image"])) ? $pack["image"] : '';
78 $this->name = (isset($pack["name"])) ? $pack["name"] : '';
79 $this->author = (isset($pack["author"])) ? $pack["author"] : '';
80 $this->authorurl = (isset($pack["author_url"])) ? $pack["author_url"] : '';
81 $this->description = (isset($pack["description"])) ? $pack["description"] : '';
82 $this->is_local = $pack["is_local"];
83 if (isset($pack["pack_dir"]))
84 $this->pack_dir = $pack["pack_dir"];
85 if (isset($pack["pack_url"]))
86 $this->pack_url = $pack["pack_url"];
87
88 }
89
90
91 /* Parses old format and current format pack XML into a button_array which button setupdata understands */
92 public function parse_pack_button($xmlbutton)
93 {
94 $button = MB()->getClass("button");
95 if ( count($xmlbutton->attributes()) > 0) // old button
96 {
97
98 $attrs = current($xmlbutton->attributes());
99
100 $data = MB()->getClass("install")->convertOldFields($attrs);
101
102 $button_array = array();
103 $button_array["status"] = $data["status"];
104
105 $data = $button->save($data,false); // convert from post var to block struct without dbase save
106
107
108 foreach($data as $block => $values)
109 {
110 if (is_array($values))
111 $button_array[$block] = json_encode($values);
112 else
113 $button_array[$block] = $values;
114 }
115
116 }
117 else // new button
118 {
119 //$button = MB()->getClass("button");
120
121 $button_array = json_decode(json_encode( (array)$xmlbutton), TRUE);
122
123 // $data = $button->save($button_array, false);
124 }
125 $temp_id = floor(rand(100000,990000));
126 $button_array["id"] = $temp_id; // fingers crossed
127
128 // for some reason on json_decode when value is empty it created an empty array instead of string.
129 foreach($button_array as $name => $values)
130 {
131 if (is_array($values) && count($values) == 0)
132 $button_array[$name] = '';
133 }
134
135
136 // icons from pack
137 $icon_array = array();
138
139 if (isset($button_array["icon"]))
140 {
141 $icon_array = maybe_unserialize($button_array["icon"]);
142 if (! is_array($icon_array)) // moving to json_encode
143 $icon_array = json_decode($button_array["icon"], true);
144
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 $button_array["icon"] = json_encode($icon_array);
150 }
151
152 return $button_array;
153 }
154
155
156
157 } // class
158
159