PluginProbe
MaxButtons – Create buttons / 6.26
MaxButtons – Create buttons v6.26
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 / blocks.php

blocks.php in MaxButtons – Create buttons 6.26, at classes/blocks.php

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