| 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 |
$class = 'Extension_E2pdf_' . ucfirst($name); |
| 26 |
if (class_exists($class)) { |
| 27 |
$extension = new $class(); |
| 28 |
|
| 29 |
if (is_array(get_option('e2pdf_extensions'))) { |
| 30 |
$extensions = get_option('e2pdf_extensions'); |
| 31 |
} else { |
| 32 |
$extensions = array(); |
| 33 |
} |
| 34 |
|
| 35 |
if ($extension->active() && in_array($name, $extensions)) { |
| 36 |
$this->extension = $extension; |
| 37 |
return true; |
| 38 |
} |
| 39 |
} |
| 40 |
return false; |
| 41 |
} |
| 42 |
|
| 43 |
public function loaded($extension) { |
| 44 |
if ($this->extension() && method_exists($this->extension(), 'info')) { |
| 45 |
$info = $this->extension()->info(); |
| 46 |
if (isset($info[$extension])) { |
| 47 |
return true; |
| 48 |
} |
| 49 |
} |
| 50 |
return false; |
| 51 |
} |
| 52 |
|
| 53 |
public function exist($name) { |
| 54 |
$class = 'Extension_E2pdf_' . ucfirst($name); |
| 55 |
if (class_exists($class)) { |
| 56 |
return true; |
| 57 |
} |
| 58 |
return false; |
| 59 |
} |
| 60 |
|
| 61 |
public function download($extensions = array()) { |
| 62 |
|
| 63 |
if ($extensions && is_array($extensions) && !empty($extensions)) { |
| 64 |
$model_e2pdf_api = new Model_E2pdf_Api(); |
| 65 |
$model_e2pdf_api->set(array( |
| 66 |
'action' => 'update/extensions', |
| 67 |
'data' => array( |
| 68 |
'version' => $this->helper->get('version'), |
| 69 |
'extensions' => $extensions |
| 70 |
) |
| 71 |
)); |
| 72 |
$request = $model_e2pdf_api->request(); |
| 73 |
|
| 74 |
if (isset($request['extensions']) && is_array($request['extensions'])) { |
| 75 |
$extentions_path = $this->helper->get('plugin_dir') . 'classes/extension/'; |
| 76 |
foreach ($request['extensions'] as $extension) { |
| 77 |
if ($extension['filename'] && $extension['file']) { |
| 78 |
if (!file_exists($extentions_path . $extension['filename'])) { |
| 79 |
file_put_contents($extentions_path . $extension['filename'], base64_decode($extension['file'])); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
return true; |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
return false; |
| 88 |
} |
| 89 |
|
| 90 |
public function extension() { |
| 91 |
return $this->extension; |
| 92 |
} |
| 93 |
|
| 94 |
public function set($attr, $value) { |
| 95 |
if (method_exists($this->extension(), 'set')) { |
| 96 |
return $this->extension()->set($attr, $value); |
| 97 |
} |
| 98 |
return false; |
| 99 |
} |
| 100 |
|
| 101 |
public function get($attr) { |
| 102 |
if (method_exists($this->extension(), 'get')) { |
| 103 |
return $this->extension()->get($attr); |
| 104 |
} |
| 105 |
return false; |
| 106 |
} |
| 107 |
|
| 108 |
public function verify() { |
| 109 |
if (method_exists($this->extension(), 'verify')) { |
| 110 |
return $this->extension()->verify(); |
| 111 |
} |
| 112 |
return false; |
| 113 |
} |
| 114 |
|
| 115 |
public function import() { |
| 116 |
if (method_exists($this->extension(), 'import')) { |
| 117 |
return $this->extension()->import(); |
| 118 |
} |
| 119 |
return false; |
| 120 |
} |
| 121 |
|
| 122 |
public function export() { |
| 123 |
if (method_exists($this->extension(), 'export')) { |
| 124 |
return $this->extension()->export(); |
| 125 |
} |
| 126 |
return false; |
| 127 |
} |
| 128 |
|
| 129 |
public function backup() { |
| 130 |
if (method_exists($this->extension(), 'backup')) { |
| 131 |
return $this->extension()->backup(); |
| 132 |
} |
| 133 |
return false; |
| 134 |
} |
| 135 |
|
| 136 |
public function get_item($item_id = false) { |
| 137 |
if (method_exists($this->extension(), 'get_item')) { |
| 138 |
return $this->extension()->get_item($item_id); |
| 139 |
} |
| 140 |
return false; |
| 141 |
} |
| 142 |
|
| 143 |
public function get_items() { |
| 144 |
if (method_exists($this->extension(), 'get_items')) { |
| 145 |
return $this->extension()->get_items(); |
| 146 |
} |
| 147 |
return false; |
| 148 |
} |
| 149 |
|
| 150 |
public function get_styles() { |
| 151 |
if (method_exists($this->extension(), 'get_styles')) { |
| 152 |
return $this->extension()->get_styles(); |
| 153 |
} |
| 154 |
return false; |
| 155 |
} |
| 156 |
|
| 157 |
public function render($value, $type = false, $field = false, $info = false) { |
| 158 |
if (method_exists($this->extension(), 'render')) { |
| 159 |
return $this->extension()->render($value, $type, $field, $info); |
| 160 |
} |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
public function get_datasets($item = false, $name = false) { |
| 165 |
if (method_exists($this->extension(), 'get_datasets')) { |
| 166 |
return $this->extension()->get_datasets($item, $name); |
| 167 |
} |
| 168 |
return false; |
| 169 |
} |
| 170 |
|
| 171 |
public function get_dataset($dataset_id = false) { |
| 172 |
if (method_exists($this->extension(), 'get_dataset')) { |
| 173 |
return $this->extension()->get_dataset($dataset_id); |
| 174 |
} |
| 175 |
return false; |
| 176 |
} |
| 177 |
|
| 178 |
public function get_extensions_list() { |
| 179 |
$list = array(); |
| 180 |
$extentions_path = $this->helper->get('plugin_dir') . 'classes/extension/*'; |
| 181 |
foreach (array_filter(glob($extentions_path), 'is_file') as $file) { |
| 182 |
$info = pathinfo($file); |
| 183 |
$file_name = basename($file, '.' . $info['extension']); |
| 184 |
$file_name = substr($file_name, 6); |
| 185 |
|
| 186 |
if ($this->load($file_name)) { |
| 187 |
$list = array_merge($list, $this->extension->info()); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
return $list; |
| 192 |
} |
| 193 |
|
| 194 |
public function delete_item($template_id = false, $dataset_id = false) { |
| 195 |
if (method_exists($this->extension(), 'delete_item')) { |
| 196 |
return $this->extension()->delete_item($template_id, $dataset_id); |
| 197 |
} |
| 198 |
return false; |
| 199 |
} |
| 200 |
|
| 201 |
public function delete_items($template_id = false) { |
| 202 |
if (method_exists($this->extension(), 'delete_items')) { |
| 203 |
return $this->extension()->delete_items($template_id); |
| 204 |
} |
| 205 |
return false; |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* Visual Mapper for Mapping field |
| 210 |
* |
| 211 |
* @return bool|string - Prepared form or false |
| 212 |
*/ |
| 213 |
public function visual_mapper() { |
| 214 |
if (method_exists($this->extension(), 'visual_mapper')) { |
| 215 |
return $this->extension()->visual_mapper(); |
| 216 |
} |
| 217 |
return false; |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* Convert Field name to Value |
| 222 |
* @since 0.01.34 |
| 223 |
* |
| 224 |
* @param string $name - Field name |
| 225 |
* |
| 226 |
* @return bool|string - Converted value or false |
| 227 |
*/ |
| 228 |
public function auto_map($name = false) { |
| 229 |
if (method_exists($this->extension(), 'auto_map') && $name) { |
| 230 |
return $this->extension()->auto_map($name); |
| 231 |
} |
| 232 |
return false; |
| 233 |
} |
| 234 |
|
| 235 |
public function auto() { |
| 236 |
if (method_exists($this->extension(), 'auto')) { |
| 237 |
return $this->extension()->auto(); |
| 238 |
} |
| 239 |
return false; |
| 240 |
} |
| 241 |
|
| 242 |
public function load_actions() { |
| 243 |
if (method_exists($this->extension(), 'load_actions')) { |
| 244 |
return $this->extension()->load_actions(); |
| 245 |
} |
| 246 |
return false; |
| 247 |
} |
| 248 |
|
| 249 |
public function load_filters() { |
| 250 |
if (method_exists($this->extension(), 'load_filters')) { |
| 251 |
return $this->extension()->load_filters(); |
| 252 |
} |
| 253 |
return false; |
| 254 |
} |
| 255 |
|
| 256 |
public function load_shortcodes() { |
| 257 |
if (method_exists($this->extension(), 'load_shortcodes')) { |
| 258 |
return $this->extension()->load_shortcodes(); |
| 259 |
} |
| 260 |
return false; |
| 261 |
} |
| 262 |
|
| 263 |
} |
| 264 |
|