FLBuilder.php
11 years ago
FLBuilderAdmin.php
11 years ago
FLBuilderAdminPosts.php
11 years ago
FLBuilderAdminSettings.php
11 years ago
FLBuilderAutoSuggest.php
11 years ago
FLBuilderColor.php
11 years ago
FLBuilderLoop.php
11 years ago
FLBuilderModel.php
11 years ago
FLBuilderModule.php
11 years ago
FLBuilderPhoto.php
11 years ago
FLBuilderUpdate.php
11 years ago
FLBuilderUtils.php
11 years ago
FLJSMin.php
11 years ago
FLBuilderModule.php
215 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Base class that gets extended by all module classes. |
| 5 | * |
| 6 | * @class FLBuilderModule |
| 7 | */ |
| 8 | class FLBuilderModule { |
| 9 | |
| 10 | /** |
| 11 | * A unique ID for the module. |
| 12 | * |
| 13 | * @property $node |
| 14 | * @type string |
| 15 | */ |
| 16 | public $node; |
| 17 | |
| 18 | /** |
| 19 | * A unique ID for the module's parent. |
| 20 | * |
| 21 | * @property $parent |
| 22 | * @type number |
| 23 | */ |
| 24 | public $parent; |
| 25 | |
| 26 | /** |
| 27 | * The sort order for this module. |
| 28 | * |
| 29 | * @property $position |
| 30 | * @type number |
| 31 | */ |
| 32 | public $position; |
| 33 | |
| 34 | /** |
| 35 | * A display name for the module. |
| 36 | * |
| 37 | * @property $name |
| 38 | * @type string |
| 39 | */ |
| 40 | public $name; |
| 41 | |
| 42 | /** |
| 43 | * A description to display for the module. |
| 44 | * |
| 45 | * @property $description |
| 46 | * @type string |
| 47 | */ |
| 48 | public $description; |
| 49 | |
| 50 | /** |
| 51 | * The category this module belongs to. |
| 52 | * |
| 53 | * @property $category |
| 54 | * @type string |
| 55 | */ |
| 56 | public $category; |
| 57 | |
| 58 | /** |
| 59 | * Must be the module's folder name. |
| 60 | * |
| 61 | * @property $slug |
| 62 | * @type string |
| 63 | */ |
| 64 | public $slug; |
| 65 | |
| 66 | /** |
| 67 | * The module's directory path. |
| 68 | * |
| 69 | * @property $dir |
| 70 | * @type string |
| 71 | */ |
| 72 | public $dir; |
| 73 | |
| 74 | /** |
| 75 | * The module's directory url. |
| 76 | * |
| 77 | * @property $url |
| 78 | * @type string |
| 79 | */ |
| 80 | public $url; |
| 81 | |
| 82 | /** |
| 83 | * An array of form settings. |
| 84 | * |
| 85 | * @property $form |
| 86 | * @type array |
| 87 | */ |
| 88 | public $form = array(); |
| 89 | |
| 90 | /** |
| 91 | * Whether this module is enabled on the |
| 92 | * frontend or not. |
| 93 | * |
| 94 | * @property $enabled |
| 95 | * @type boolean |
| 96 | */ |
| 97 | public $enabled = true; |
| 98 | |
| 99 | /** |
| 100 | * Whether this module's content should |
| 101 | * be exported to the WP editor or not. |
| 102 | * |
| 103 | * @property $editor_export |
| 104 | * @type boolean |
| 105 | */ |
| 106 | public $editor_export = true; |
| 107 | |
| 108 | /** |
| 109 | * The module settings object. |
| 110 | * |
| 111 | * @property $settings |
| 112 | * @type object |
| 113 | */ |
| 114 | public $settings; |
| 115 | |
| 116 | /** |
| 117 | * Additional CSS to enqueue. |
| 118 | * |
| 119 | * @property $css |
| 120 | * @type array |
| 121 | */ |
| 122 | public $css = array(); |
| 123 | |
| 124 | /** |
| 125 | * Additional JS to enqueue. |
| 126 | * |
| 127 | * @property $js |
| 128 | * @type array |
| 129 | */ |
| 130 | public $js = array(); |
| 131 | |
| 132 | /** |
| 133 | * @method __construct |
| 134 | */ |
| 135 | public function __construct($params) |
| 136 | { |
| 137 | $class_info = new ReflectionClass($this); |
| 138 | $class_path = $class_info->getFileName(); |
| 139 | $dir_path = dirname($class_path); |
| 140 | $this->name = $params['name']; |
| 141 | $this->description = $params['description']; |
| 142 | $this->category = $params['category']; |
| 143 | $this->slug = basename($class_path, '.php'); |
| 144 | $this->enabled = isset($params['enabled']) ? $params['enabled'] : true; |
| 145 | $this->editor_export = isset($params['editor_export']) ? $params['editor_export'] : true; |
| 146 | |
| 147 | if(stristr($dir_path, 'wp-content/themes')) { |
| 148 | $parts = explode('/wp-content', str_ireplace($_SERVER['DOCUMENT_ROOT'], '', $dir_path)); |
| 149 | $folder = array_shift($parts); |
| 150 | $this->url = str_ireplace($_SERVER['DOCUMENT_ROOT'] . $folder, home_url(), $dir_path) . '/'; |
| 151 | $this->dir = $dir_path . '/'; |
| 152 | } |
| 153 | else { |
| 154 | $this->url = isset($params['url']) ? $params['url'] : FL_BUILDER_URL . 'modules/' . $this->slug . '/'; |
| 155 | $this->dir = isset($params['dir']) ? $params['dir'] : FL_BUILDER_DIR . 'modules/' . $this->slug . '/'; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Used to enqueue additional frontend styles. Do not enqueue |
| 161 | * frontend.css or frontend.responsive.css as those will be |
| 162 | * enqueued automatically. |
| 163 | * |
| 164 | * @method add_css |
| 165 | */ |
| 166 | public function add_css($handle, $src = null, $deps = null, $ver = null, $media = null) |
| 167 | { |
| 168 | $this->css[$handle] = array($src, $deps, $ver, $media); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Used to enqueue additional frontend scripts. Do not enqueue |
| 173 | * frontend.js as that will be enqueued automatically. |
| 174 | * |
| 175 | * @method add_js |
| 176 | */ |
| 177 | public function add_js($handle, $src = null, $deps = null, $ver = null, $in_footer = null) |
| 178 | { |
| 179 | $this->js[$handle] = array($src, $deps, $ver, $in_footer); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Should be overridden by child classes to enqueue |
| 184 | * additional css/js using the add_css and add_js methods. |
| 185 | * |
| 186 | * @method enqueue_scripts |
| 187 | */ |
| 188 | public function enqueue_scripts() |
| 189 | { |
| 190 | |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Should be overridden by child classes to |
| 195 | * work with settings data before it is saved. |
| 196 | * |
| 197 | * @method update |
| 198 | * @param $settings {object} |
| 199 | */ |
| 200 | public function update($settings) |
| 201 | { |
| 202 | return $settings; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Should be overridden by child classes to |
| 207 | * work with a module before it is deleted. |
| 208 | * |
| 209 | * @method delete |
| 210 | */ |
| 211 | public function delete() |
| 212 | { |
| 213 | |
| 214 | } |
| 215 | } |