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/blocks.php +67 -66 6.266.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 /** Blocks collection
@@ -7,35 +7,35 @@
7 7 * Class for general block functions - transitional
8 8 */
9 9 use \RecursiveDirectoryIterator as RecursiveDirectoryIterator;
10 10 use \RecursiveIteratorIterator as RecursiveIteratorIterator;
11 -use \FilesystemIterator as FilesystemIterator;
11 +use \FilesystemIterator as FilesystemIterator;
12 12
13 13 class maxBlocks
14 14 {
15 15 protected static $blocks; // collection!
16 - protected static $block_classes;
17 -
16 + protected static $block_classes;
17 +
18 18 protected static $data; // full data array
19 - protected static $fields = array(); // all fields
20 -
21 - public static function init()
19 + protected static $fields = array(); // all fields
20 +
21 + public static function init()
22 22 {
23 23
24 24 }
25 -
26 - /** Find the block classes */
27 - public static function initBlocks()
25 +
26 + /** Find the block classes */
27 + public static function initBlocks()
28 28 {
29 -
29 +
30 30 $block_paths = apply_filters('mb-block-paths', array(MB()->get_plugin_path() . "blocks/") );
31 -
31 +
32 32 //global $blockClass; // load requires only onc
33 33
34 34 $newBlocks = array();
35 - $templates = array();
36 -
37 -
35 + $templates = array();
36 +
37 +
38 38 foreach($block_paths as $block_path)
39 39 {
40 40 $dir_iterator = new RecursiveDirectoryIterator($block_path, FilesystemIterator::SKIP_DOTS);
41 41 $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
@@ -42,23 +42,23 @@
42 42
43 43 foreach ($iterator as $fileinfo)
44 44 {
45 45
46 - $path = $fileinfo->getRealPath();
46 + $path = $fileinfo->getRealPath();
47 47 // THIS IS PHP > 5.3.6
48 - //$extension = $fileinfo->getExtension();
48 + //$extension = $fileinfo->getExtension();
49 49 $extension = pathinfo($path, PATHINFO_EXTENSION);
50 -
50 +
51 51 if ($fileinfo->isFile() )
52 52 {
53 - if ($extension == 'php')
53 + if ($extension == 'php')
54 54 {
55 55 require_once($path);
56 56 }
57 - elseif($extension == 'tpl')
58 - {
57 + elseif($extension == 'tpl')
58 + {
59 59 $filename = $fileinfo->getBasename('.tpl');
60 - $templates[$filename] = array('path' => $path);
60 + $templates[$filename] = array('path' => $path);
61 61 }
62 62 }
63 63 }
64 64
@@ -68,98 +68,99 @@
68 68 {
69 69 foreach($blockArray as $block)
70 70 {
71 71 if (isset($blockClass[$block]))
72 - $newBlocks[$block] = $blockClass[$block];
73 -
72 + $newBlocks[$block] = $blockClass[$block];
73 +
74 74 }
75 75 }
76 76 $blockClass = $newBlocks;
77 77 if (is_admin())
78 78 {
79 - // possible issue with some hosters faking is_admin flag.
79 + // possible issue with some hosters faking is_admin flag.
80 80 if (class_exists( maxUtils::namespaceit('maxBlocks') ) && class_exists( maxUtils::namespaceit('maxBlocks') ) )
81 81 {
82 - maxField::setTemplates($templates);
82 + maxField::setTemplates($templates);
83 83
84 84 }
85 85 else
86 86 {
87 - error_log('[MaxButtons] - MaxField class is not set within admin context. This can cause issues when using button editor');
87 + error_log('[MaxButtons] - MaxField class is not set within admin context. This can cause issues when using button editor');
88 88 }
89 89 }
90 -
91 - //$this->loadBlockClasses($blockClass);
92 -
90 +
91 + //$this->loadBlockClasses($blockClass);
92 +
93 93 static::$block_classes = array_values($blockClass);
94 94 }
95 -
96 - public static function getBlockClasses()
95 +
96 + public static function getBlockClasses()
97 97 {
98 98 if ( is_null(static::$block_classes) )
99 99 self::initBlocks();
100 -
100 +
101 101 return static::$block_classes;
102 102 }
103 -
104 -
105 - public static function setData($data)
103 +
104 +
105 + public static function setData($data)
106 106 {
107 - $new_data = array(); //egalite
108 - if (! is_array($data) || count($data) == 0) // no data
109 - return false;
110 -
111 - foreach($data as $block => $fields)
107 +
108 + $new_data = array(); //egalite
109 + if (! is_array($data) || count($data) == 0) // no data
110 + return false;
111 +
112 + foreach($data as $block => $fields)
112 113 {
113 - if (is_array($fields))
114 - $new_data = array_merge($new_data, $fields);
114 + if (is_array($fields))
115 + $new_data = array_merge($new_data, $fields);
115 116 }
116 -
117 117
118 - self::$data = $new_data;
118 +
119 + self::$data = $new_data;
119 120 }
120 -
121 +
121 122 public static function add($block)
122 123 {
123 - $name = $block->get_name();
124 + $name = $block->get_name();
124 125
125 126 static::$blocks[$name] = $block;
126 - static::$fields = array_merge(self::$fields, $block->get_fields());
127 + static::$fields = array_merge(self::$fields, $block->get_fields());
127 128 }
128 -
129 - public static function getValue($fieldname)
129 +
130 + public static function getValue($fieldname)
130 131 {
131 132
132 - if (isset(self::$data[$fieldname]))
133 - return self::$data[$fieldname];
134 - if (isset(self::$fields[$fieldname]))
133 + if (isset(self::$data[$fieldname]))
134 + return self::$data[$fieldname];
135 + if (isset(self::$fields[$fieldname]))
135 136 return self::$fields[$fieldname]['default'];
136 -
137 - return false; // dunno.
137 +
138 + return false; // dunno.
138 139 }
139 140
140 - public static function getColorValue($fieldname)
141 + public static function getColorValue($fieldname)
141 142 {
142 - $value = self::getValue($fieldname);
143 - if (! $value )
143 + $value = self::getValue($fieldname);
144 + if (! $value )
144 145 return false;
145 -
146 - if (substr($value,0,1) !== '#')
146 +
147 + if (substr($value,0,1) !== '#')
147 148 {
148 149 $value = '#' . $value;
149 150 }
150 -
151 +
151 152 return $value;
152 -
153 +
153 154 }
154 155
155 - public static function getDefault($fieldname)
156 + public static function getDefault($fieldname)
156 157 {
157 - if (isset(self::$fields[$fieldname]['default']))
158 + if (isset(self::$fields[$fieldname]['default']))
158 159 return self::$fields[$fieldname]['default'];
159 -
160 +
160 161 return false; // dunno
161 -
162 +
162 163 }
163 164
164 165
165 166 }