| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Extension Model |
| 5 |
* |
| 6 |
* @copyright Copyright 2017 https://e2pdf.com |
| 7 |
* @license GPL v2 |
| 8 |
* @version 1 |
| 9 |
* @link https://e2pdf.com |
| 10 |
* @since 0.00.01 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Model_E2pdf_Extension extends Model_E2pdf_Model { |
| 17 |
|
| 18 |
private $extension; |
| 19 |
|
| 20 |
function __construct() { |
| 21 |
parent::__construct(); |
| 22 |
} |
| 23 |
|
| 24 |
public function load($name) { |
| 25 |
if (is_array(get_option('e2pdf_disabled_extensions')) && |
| 26 |
in_array($name, get_option('e2pdf_disabled_extensions'))) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
$class = 'Extension_E2pdf_' . ucfirst($name); |
| 30 |
if (class_exists($class)) { |
| 31 |
$extension = new $class(); |
| 32 |
if ($extension->active()) { |
| 33 |
$this->extension = $extension; |
| 34 |
return true; |
| 35 |
} |
| 36 |
} |
| 37 |
return false; |
| 38 |
} |
| 39 |
|
| 40 |
public function loaded($extension) { |
| 41 |
if ($this->extension() && method_exists($this->extension(), 'info')) { |
| 42 |
$info = $this->extension()->info(); |
| 43 |
if (isset($info[$extension])) { |
| 44 |
return true; |
| 45 |
} |
| 46 |
} |
| 47 |
return false; |
| 48 |
} |
| 49 |
|
| 50 |
public function info($attr = false) { |
| 51 |
if (method_exists($this->extension(), 'info')) { |
| 52 |
return $this->extension()->info($attr); |
| 53 |
} |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
public function extension() { |
| 58 |
return $this->extension; |
| 59 |
} |
| 60 |
|
| 61 |
public function set($attr, $value) { |
| 62 |
if (method_exists($this->extension(), 'set')) { |
| 63 |
return $this->extension()->set($attr, $value); |
| 64 |
} |
| 65 |
return false; |
| 66 |
} |
| 67 |
|
| 68 |
public function get($attr) { |
| 69 |
if (method_exists($this->extension(), 'get')) { |
| 70 |
return $this->extension()->get($attr); |
| 71 |
} |
| 72 |
return false; |
| 73 |
} |
| 74 |
|
| 75 |
public function verify() { |
| 76 |
if (method_exists($this->extension(), 'verify')) { |
| 77 |
return $this->extension()->verify(); |
| 78 |
} |
| 79 |
return false; |
| 80 |
} |
| 81 |
|
| 82 |
public function import($xml, $item, $options = array()) { |
| 83 |
if (method_exists($this->extension(), 'import')) { |
| 84 |
return $this->extension()->import($xml, $item, $options); |
| 85 |
} |
| 86 |
return false; |
| 87 |
} |
| 88 |
|
| 89 |
public function after_import($old_template_id, $new_template_id) { |
| 90 |
if (method_exists($this->extension(), 'after_import')) { |
| 91 |
return $this->extension()->after_import($old_template_id, $new_template_id); |
| 92 |
} |
| 93 |
return false; |
| 94 |
} |
| 95 |
|
| 96 |
public function backup($xml = false) { |
| 97 |
if (method_exists($this->extension(), 'backup')) { |
| 98 |
return $this->extension()->backup($xml); |
| 99 |
} |
| 100 |
return false; |
| 101 |
} |
| 102 |
|
| 103 |
public function item($item_id = false) { |
| 104 |
if (method_exists($this->extension(), 'item')) { |
| 105 |
return $this->extension()->item($item_id); |
| 106 |
} |
| 107 |
return false; |
| 108 |
} |
| 109 |
|
| 110 |
public function items() { |
| 111 |
if (method_exists($this->extension(), 'items')) { |
| 112 |
return $this->extension()->items(); |
| 113 |
} |
| 114 |
return false; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Load styles from extension |
| 119 |
*/ |
| 120 |
public function styles() { |
| 121 |
if (method_exists($this->extension(), 'styles')) { |
| 122 |
return $this->extension()->styles(); |
| 123 |
} |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Render Value via extension |
| 129 |
*/ |
| 130 |
public function render($value, $type = false, $field = array()) { |
| 131 |
if (method_exists($this->extension(), 'render')) { |
| 132 |
return $this->extension()->render($value, $type, $field); |
| 133 |
} |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* Get available datasets |
| 139 |
*/ |
| 140 |
public function datasets($item = false, $name = false) { |
| 141 |
if (method_exists($this->extension(), 'datasets')) { |
| 142 |
return $this->extension()->datasets($item, $name); |
| 143 |
} |
| 144 |
return false; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Get current extension dataset |
| 149 |
*/ |
| 150 |
public function dataset($dataset_id = false) { |
| 151 |
if (method_exists($this->extension(), 'dataset')) { |
| 152 |
return $this->extension()->dataset($dataset_id); |
| 153 |
} |
| 154 |
return false; |
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* List of available extensions |
| 159 |
*/ |
| 160 |
public function extensions($load = true) { |
| 161 |
$list = array(); |
| 162 |
$extentions_path = $this->helper->get('plugin_dir') . 'classes/extension/*'; |
| 163 |
foreach (array_filter(glob($extentions_path), 'is_file') as $file) { |
| 164 |
$info = pathinfo($file); |
| 165 |
$file_name = basename($file, '.' . $info['extension']); |
| 166 |
$file_name = substr($file_name, 6); |
| 167 |
|
| 168 |
if ($load) { |
| 169 |
if ($this->load($file_name)) { |
| 170 |
$list = array_merge($list, $this->extension->info()); |
| 171 |
} |
| 172 |
} else { |
| 173 |
$list[] = $file_name; |
| 174 |
} |
| 175 |
} |
| 176 |
return $list; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Delete item |
| 181 |
*/ |
| 182 |
public function delete_item($template_id = false, $dataset_id = false) { |
| 183 |
if (method_exists($this->extension(), 'delete_item')) { |
| 184 |
return $this->extension()->delete_item($template_id, $dataset_id); |
| 185 |
} |
| 186 |
return false; |
| 187 |
} |
| 188 |
|
| 189 |
/** |
| 190 |
* Delete all items |
| 191 |
*/ |
| 192 |
public function delete_items($template_id = false) { |
| 193 |
if (method_exists($this->extension(), 'delete_items')) { |
| 194 |
return $this->extension()->delete_items($template_id); |
| 195 |
} |
| 196 |
return false; |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Visual Mapper for Mapping field |
| 201 |
* |
| 202 |
* @return bool|string - Prepared form or false |
| 203 |
*/ |
| 204 |
public function visual_mapper() { |
| 205 |
|
| 206 |
if (method_exists($this->extension(), 'visual_mapper')) { |
| 207 |
if (!extension_loaded('libxml')) { |
| 208 |
return __('libxml is required', 'e2pdf'); |
| 209 |
} |
| 210 |
if (!extension_loaded('Dom')) { |
| 211 |
return __('DOM is required', 'e2pdf'); |
| 212 |
} |
| 213 |
return $this->extension()->visual_mapper(); |
| 214 |
} |
| 215 |
return false; |
| 216 |
} |
| 217 |
|
| 218 |
public function auto_form($template, $data = array()) { |
| 219 |
if (method_exists($this->extension(), 'auto_form')) { |
| 220 |
return $this->extension()->auto_form($template, $data); |
| 221 |
} |
| 222 |
return $template; |
| 223 |
} |
| 224 |
|
| 225 |
/** |
| 226 |
* Convert Field name to Value |
| 227 |
* @since 0.01.34 |
| 228 |
* |
| 229 |
* @param string $name - Field name |
| 230 |
* |
| 231 |
* @return bool|string - Converted value or false |
| 232 |
*/ |
| 233 |
public function auto_map($name = false) { |
| 234 |
if (method_exists($this->extension(), 'auto_map') && $name) { |
| 235 |
return $this->extension()->auto_map($name); |
| 236 |
} |
| 237 |
return false; |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Auto PDF generation |
| 242 |
*/ |
| 243 |
public function auto() { |
| 244 |
if (method_exists($this->extension(), 'auto')) { |
| 245 |
return $this->extension()->auto(); |
| 246 |
} |
| 247 |
return false; |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* Check if function exists inside extension |
| 252 |
*/ |
| 253 |
public function method($attr = false) { |
| 254 |
if ($attr && method_exists($this->extension(), $attr)) { |
| 255 |
return true; |
| 256 |
} |
| 257 |
return false; |
| 258 |
} |
| 259 |
|
| 260 |
/** |
| 261 |
* Load actions from extension |
| 262 |
*/ |
| 263 |
public function load_actions() { |
| 264 |
if (method_exists($this->extension(), 'load_actions')) { |
| 265 |
return $this->extension()->load_actions(); |
| 266 |
} |
| 267 |
return false; |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Load filters from extension |
| 272 |
*/ |
| 273 |
public function load_filters() { |
| 274 |
if (method_exists($this->extension(), 'load_filters')) { |
| 275 |
return $this->extension()->load_filters(); |
| 276 |
} |
| 277 |
return false; |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Load shortcodes from extension |
| 282 |
*/ |
| 283 |
public function load_shortcodes() { |
| 284 |
if (method_exists($this->extension(), 'load_shortcodes')) { |
| 285 |
return $this->extension()->load_shortcodes(); |
| 286 |
} |
| 287 |
return false; |
| 288 |
} |
| 289 |
|
| 290 |
} |
| 291 |
|