| @@ -1,717 +1,1766 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * E2pdf Wordpress Extension | |
| 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 | |
| 4 | + * File: /extension/e2pdf-wordpress.php | |
| 5 | + * | |
| 6 | + * @package E2Pdf | |
| 7 | + * @license GPLv3 | |
| 8 | + * @link https://e2pdf.com | |
| 11 | 9 | */ |
| 12 | 10 | if (!defined('ABSPATH')) { |
| 13 | 11 | die('Access denied.'); |
| 14 | 12 | } |
| 15 | 13 | |
| 14 | +// phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName | |
| 16 | 15 | class Extension_E2pdf_Wordpress extends Model_E2pdf_Model { |
| 17 | 16 | |
| 18 | 17 | private $options; |
| 19 | - private $info = array( | |
| 18 | + private $info = [ | |
| 20 | 19 | 'key' => 'wordpress', |
| 21 | - 'title' => 'WordPress' | |
| 22 | - ); | |
| 20 | + 'title' => 'WordPress', | |
| 21 | + ]; | |
| 23 | 22 | |
| 24 | - function __construct() { | |
| 25 | - parent::__construct(); | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Get info about extension | |
| 30 | - * | |
| 31 | - * @param string $key - Key to get assigned extension info value | |
| 32 | - * | |
| 33 | - * @return array|string - Extension Key and Title or Assigned extension info value | |
| 34 | - */ | |
| 23 | + // info | |
| 35 | 24 | public function info($key = false) { |
| 36 | 25 | if ($key && isset($this->info[$key])) { |
| 37 | 26 | return $this->info[$key]; |
| 38 | 27 | } else { |
| 39 | - return array( | |
| 40 | - $this->info['key'] => $this->info['title'] | |
| 41 | - ); | |
| 28 | + return [ | |
| 29 | + $this->info['key'] => $this->info['title'], | |
| 30 | + ]; | |
| 42 | 31 | } |
| 43 | 32 | } |
| 44 | 33 | |
| 45 | - /** | |
| 46 | - * Check if needed plugin active | |
| 47 | - * | |
| 48 | - * @return bool - Activated/Not Activated plugin | |
| 49 | - */ | |
| 34 | + // active | |
| 50 | 35 | public function active() { |
| 51 | 36 | return true; |
| 52 | 37 | } |
| 53 | 38 | |
| 54 | - /** | |
| 55 | - * Set option | |
| 56 | - * | |
| 57 | - * @param string $attr - Key of option | |
| 58 | - * @param string $value - Value of option | |
| 59 | - * | |
| 60 | - * @return bool - Status of setting option | |
| 61 | - */ | |
| 39 | + // set | |
| 62 | 40 | public function set($key, $value) { |
| 63 | 41 | if (!isset($this->options)) { |
| 64 | 42 | $this->options = new stdClass(); |
| 65 | 43 | } |
| 66 | - | |
| 67 | 44 | $this->options->$key = $value; |
| 45 | + switch ($key) { | |
| 46 | + case 'dataset': | |
| 47 | + $this->set('cached_post', false); | |
| 48 | + if ($this->get('dataset')) { | |
| 49 | + if ($this->get('item') == '-3') { | |
| 50 | + $this->set('cached_post', get_user_by('id', $this->get('dataset'))); | |
| 51 | + } else { | |
| 52 | + $pll = $this->helper->load('translator')->isPolylang(); | |
| 53 | + if ($pll) { | |
| 54 | + $lang = pll_get_post_language($this->get('dataset')); | |
| 55 | + if ($lang) { | |
| 56 | + PLL()->curlang = PLL()->model->get_language($lang); | |
| 57 | + } | |
| 58 | + } | |
| 59 | + $this->set('cached_post', get_post($this->get('dataset'))); | |
| 60 | + } | |
| 61 | + } | |
| 62 | + break; | |
| 63 | + default: | |
| 64 | + break; | |
| 65 | + } | |
| 68 | 66 | } |
| 69 | 67 | |
| 70 | - /** | |
| 71 | - * Get option by key | |
| 72 | - * | |
| 73 | - * @param string $key - Key to get assigned option value | |
| 74 | - * | |
| 75 | - * @return mixed | |
| 76 | - */ | |
| 68 | + // get | |
| 77 | 69 | public function get($key) { |
| 70 | + if ($key == 'user_id' && $this->get('item') == '-3') { | |
| 71 | + $key = 'dataset'; | |
| 72 | + } | |
| 78 | 73 | if (isset($this->options->$key)) { |
| 79 | 74 | $value = $this->options->$key; |
| 80 | - return $value; | |
| 81 | 75 | } else { |
| 82 | - return false; | |
| 76 | + switch ($key) { | |
| 77 | + case 'args': | |
| 78 | + $value = []; | |
| 79 | + break; | |
| 80 | + default: | |
| 81 | + $value = false; | |
| 82 | + break; | |
| 83 | + } | |
| 83 | 84 | } |
| 85 | + return $value; | |
| 84 | 86 | } |
| 85 | 87 | |
| 86 | - /** | |
| 87 | - * Get items to work with | |
| 88 | - * | |
| 89 | - * @return array() - List of available items | |
| 90 | - */ | |
| 88 | + // items | |
| 91 | 89 | public function items() { |
| 92 | - $content = array(); | |
| 93 | - | |
| 94 | - $content[] = $this->item('post'); | |
| 95 | - $content[] = $this->item('page'); | |
| 96 | - | |
| 97 | - return $content; | |
| 90 | + $items = []; | |
| 91 | + $forms = get_post_types([], 'names'); | |
| 92 | + foreach ($forms as $form) { | |
| 93 | + if ($form != 'attachment') { | |
| 94 | + $items[] = $this->item($form); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + $items[] = $this->item('-3'); | |
| 98 | + return $items; | |
| 98 | 99 | } |
| 99 | 100 | |
| 100 | - /** | |
| 101 | - * Get entries for export | |
| 102 | - * | |
| 103 | - * @param string $item - Item | |
| 104 | - * @param string $name - Entries names | |
| 105 | - * | |
| 106 | - * @return array() - Entries list | |
| 107 | - */ | |
| 108 | - public function datasets($item = false, $name = false) { | |
| 101 | + // datasets | |
| 102 | + public function datasets($item_id = false, $name = false) { | |
| 103 | + $datasets = []; | |
| 104 | + if ($item_id) { | |
| 105 | + if ($item_id == '-3') { | |
| 106 | + $entries = get_users( | |
| 107 | + [ | |
| 108 | + 'fields' => [ | |
| 109 | + 'ID', 'user_login', | |
| 110 | + ], | |
| 111 | + ] | |
| 112 | + ); | |
| 109 | 113 | |
| 110 | - $datasets = array(); | |
| 111 | - | |
| 112 | - if ($item) { | |
| 113 | - if ($item == 'page') { | |
| 114 | - $datasets_tmp = get_pages(); | |
| 115 | - } elseif ($item == 'post') { | |
| 116 | - $datasets_tmp = get_posts(); | |
| 117 | - } | |
| 118 | - | |
| 119 | - if ($datasets_tmp) { | |
| 120 | - foreach ($datasets_tmp as $key => $dataset) { | |
| 121 | - $this->set('item', $item); | |
| 122 | - $this->set('dataset', $dataset->ID); | |
| 123 | - $dataset_title = $this->render($name); | |
| 124 | - if (!$dataset_title) { | |
| 125 | - $dataset_title = $dataset->post_title; | |
| 114 | + if ($entries) { | |
| 115 | + $this->set('item', $item_id); | |
| 116 | + foreach ($entries as $key => $entry) { | |
| 117 | + $this->set('dataset', $entry->ID); | |
| 118 | + $entry_title = $this->render($name); | |
| 119 | + if (!$entry_title) { | |
| 120 | + $entry_title = isset($entry->user_login) && $entry->user_login ? $entry->user_login : $entry->ID; | |
| 121 | + } | |
| 122 | + $datasets[] = [ | |
| 123 | + 'key' => $entry->ID, | |
| 124 | + 'value' => $entry_title, | |
| 125 | + ]; | |
| 126 | 126 | } |
| 127 | - $datasets[] = array( | |
| 128 | - 'key' => $dataset->ID, | |
| 129 | - 'value' => $dataset_title | |
| 127 | + } | |
| 128 | + } else { | |
| 129 | + $wpml = $this->helper->load('translator')->isWPML(); | |
| 130 | + if ($wpml) { | |
| 131 | + $lang = apply_filters('wpml_current_language', null); | |
| 132 | + $entries = get_posts( | |
| 133 | + [ | |
| 134 | + 'post_type' => $item_id, | |
| 135 | + 'numberposts' => -1, | |
| 136 | + 'post_status' => 'any', | |
| 137 | + 'lang' => $lang, | |
| 138 | + 'suppress_filters' => false, | |
| 139 | + ] | |
| 130 | 140 | ); |
| 141 | + } else { | |
| 142 | + $entries = get_posts( | |
| 143 | + [ | |
| 144 | + 'post_type' => $item_id, | |
| 145 | + 'numberposts' => -1, | |
| 146 | + 'post_status' => 'any', | |
| 147 | + ] | |
| 148 | + ); | |
| 131 | 149 | } |
| 150 | + if ($entries) { | |
| 151 | + $this->set('item', $item_id); | |
| 152 | + foreach ($entries as $key => $entry) { | |
| 153 | + $this->set('dataset', $entry->ID); | |
| 154 | + $entry_title = $this->render($name); | |
| 155 | + if (!$entry_title) { | |
| 156 | + $entry_title = isset($entry->post_title) && $entry->post_title ? $entry->post_title : $entry->ID; | |
| 157 | + } | |
| 158 | + $datasets[] = [ | |
| 159 | + 'key' => $entry->ID, | |
| 160 | + 'value' => $entry_title, | |
| 161 | + ]; | |
| 162 | + } | |
| 163 | + } | |
| 132 | 164 | } |
| 133 | 165 | } |
| 134 | - | |
| 135 | 166 | return $datasets; |
| 136 | 167 | } |
| 137 | 168 | |
| 138 | - /** | |
| 139 | - * Get dataset | |
| 140 | - * | |
| 141 | - * @param int $dataset - Dataset ID | |
| 142 | - * | |
| 143 | - * @return object - Dataset | |
| 144 | - */ | |
| 145 | - public function dataset($dataset = false) { | |
| 169 | + // get dataset actions | |
| 170 | + public function get_dataset_actions($dataset_id = false) { | |
| 171 | + $dataset_id = (int) $dataset_id; | |
| 172 | + if (!$dataset_id) { | |
| 173 | + return false; | |
| 174 | + } | |
| 175 | + $actions = new stdClass(); | |
| 176 | + if ($this->get('item') == '-3') { | |
| 177 | + $actions->view = $this->helper->get_url( | |
| 178 | + [ | |
| 179 | + 'user_id' => $dataset_id, | |
| 180 | + ], 'user-edit.php?' | |
| 181 | + ); | |
| 182 | + } else { | |
| 183 | + $actions->view = $this->helper->get_url( | |
| 184 | + [ | |
| 185 | + 'post' => $dataset_id, | |
| 186 | + 'action' => 'edit', | |
| 187 | + ], 'post.php?' | |
| 188 | + ); | |
| 189 | + } | |
| 190 | + $actions->delete = false; | |
| 191 | + return $actions; | |
| 192 | + } | |
| 146 | 193 | |
| 147 | - $dataset = (int) $dataset; | |
| 148 | - | |
| 149 | - if (!$dataset) { | |
| 194 | + // get template actions | |
| 195 | + public function get_template_actions($template = false) { | |
| 196 | + $template = (int) $template; | |
| 197 | + if (!$template) { | |
| 150 | 198 | return; |
| 151 | 199 | } |
| 152 | - | |
| 153 | - $data = new stdClass(); | |
| 154 | - $data->url = $this->helper->get_url(array('post' => $dataset, 'action' => 'edit'), 'post.php?'); | |
| 155 | - | |
| 156 | - return $data; | |
| 200 | + $actions = new stdClass(); | |
| 201 | + $actions->delete = false; | |
| 202 | + return $actions; | |
| 157 | 203 | } |
| 158 | 204 | |
| 159 | - /** | |
| 160 | - * Get item | |
| 161 | - * | |
| 162 | - * @param string $item - Item | |
| 163 | - * | |
| 164 | - * @return object - Item | |
| 165 | - */ | |
| 166 | - public function item($item = false) { | |
| 167 | - | |
| 168 | - if (!$item && $this->get('item')) { | |
| 169 | - $item = $this->get('item'); | |
| 205 | + // item | |
| 206 | + public function item($item_id = false) { | |
| 207 | + if (!$item_id && $this->get('item')) { | |
| 208 | + $item_id = $this->get('item'); | |
| 170 | 209 | } |
| 171 | - | |
| 172 | - $form = new stdClass(); | |
| 173 | - if ($item == 'post') { | |
| 174 | - $form->id = 'post'; | |
| 175 | - $form->name = __('WordPress Post', 'e2pdf'); | |
| 176 | - $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?'); | |
| 177 | - } elseif ($item == 'page') { | |
| 178 | - $form->id = 'page'; | |
| 179 | - $form->name = __('WordPress Page', 'e2pdf'); | |
| 180 | - $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?'); | |
| 210 | + $item = new stdClass(); | |
| 211 | + if ($item_id == '-3') { | |
| 212 | + $item->id = $item_id; | |
| 213 | + $item->name = __('Users'); | |
| 214 | + $item->url = $this->helper->get_url([], 'users.php'); | |
| 181 | 215 | } else { |
| 182 | - $form->id = ''; | |
| 183 | - $form->name = ''; | |
| 184 | - $form->url = 'javascript:void(0);'; | |
| 216 | + $form = get_post_type_object($item_id); | |
| 217 | + if ($form) { | |
| 218 | + $item->id = $item_id; | |
| 219 | + $item->name = $form->label ? $form->label : $item_id; | |
| 220 | + $item->url = $this->helper->get_url(['post_type' => $item_id], 'edit.php?'); | |
| 221 | + } else { | |
| 222 | + $item->id = ''; | |
| 223 | + $item->name = ''; | |
| 224 | + $item->url = ''; | |
| 225 | + } | |
| 185 | 226 | } |
| 186 | - | |
| 187 | - return $form; | |
| 227 | + return $item; | |
| 188 | 228 | } |
| 189 | 229 | |
| 230 | + // load filters | |
| 190 | 231 | public function load_filters() { |
| 191 | - add_filter('the_content', array($this, 'filter_content'), 10, 2); | |
| 192 | - } | |
| 232 | + add_filter('the_content', [$this, 'filter_the_content'], 10, 2); | |
| 233 | + add_filter('widget_text', [$this, 'filter_content_custom']); | |
| 234 | + add_filter('widget_block_content', [$this, 'filter_content_custom']); | |
| 193 | 235 | |
| 194 | - /** | |
| 195 | - * Render value according to content | |
| 196 | - * | |
| 197 | - * @param string $value - Content | |
| 198 | - * @param string $type - Type of rendering value | |
| 199 | - * @param array $field - Field details | |
| 200 | - * | |
| 201 | - * @return string - Fully rendered value | |
| 202 | - */ | |
| 203 | - public function render($value, $type = false, $field = array()) { | |
| 236 | + /** | |
| 237 | + * Popup Maker – Popup for opt-ins, lead gen, & more | |
| 238 | + * https://wordpress.org/plugins/popup-maker/ | |
| 239 | + */ | |
| 240 | + add_filter('pum_popup_content', [$this, 'filter_the_content'], 10, 2); | |
| 204 | 241 | |
| 205 | - $value = $this->render_shortcodes($value, $type, $field); | |
| 206 | - $value = $this->strip_shortcodes($value); | |
| 242 | + /** | |
| 243 | + * Events Manager | |
| 244 | + * https://wordpress.org/plugins/events-manager/ | |
| 245 | + */ | |
| 246 | + add_filter('em_event_output_placeholder', [$this, 'filter_content_custom'], 0); | |
| 247 | + add_filter('em_event_output', [$this, 'filter_content_custom']); | |
| 248 | + add_filter('em_booking_output_placeholder', [$this, 'filter_content_custom'], 0); | |
| 249 | + add_filter('em_booking_output', [$this, 'filter_content_custom']); | |
| 250 | + add_filter('em_location_output_placeholder', [$this, 'filter_content_custom'], 0); | |
| 251 | + add_filter('em_location_output', [$this, 'filter_content_custom']); | |
| 252 | + add_filter('em_category_output_placeholder', [$this, 'filter_content_custom'], 0); | |
| 207 | 253 | |
| 208 | - if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) { | |
| 209 | - $option = $this->render($field['properties']['option']); | |
| 210 | - $options = explode(', ', $value); | |
| 211 | - $option_options = explode(', ', $option); | |
| 212 | - if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) { | |
| 213 | - return $option; | |
| 214 | - } else { | |
| 215 | - return ""; | |
| 216 | - } | |
| 217 | - } | |
| 254 | + /** | |
| 255 | + * Beaver Builder – WordPress Page Builder | |
| 256 | + * https://wordpress.org/plugins/beaver-builder-lite-version/ | |
| 257 | + */ | |
| 258 | + add_filter('fl_builder_before_render_shortcodes', [$this, 'filter_content_loop']); | |
| 218 | 259 | |
| 219 | - if ($type === 'value') { | |
| 220 | - $value = $this->convert_shortcodes($value, true); | |
| 221 | - } | |
| 260 | + /** | |
| 261 | + * WPBakery Page Builder Image Object Link | |
| 262 | + */ | |
| 263 | + add_filter('vc_map_get_attributes', [$this, 'filter_vc_map_get_attributes'], 10, 2); | |
| 222 | 264 | |
| 223 | - return $value; | |
| 224 | - } | |
| 265 | + /** | |
| 266 | + * Flatsome theme global tab content | |
| 267 | + */ | |
| 268 | + add_filter('theme_mod_tab_content', [$this, 'filter_content_custom']); | |
| 225 | 269 | |
| 226 | - /** | |
| 227 | - * Render shortcodes which available in this extension | |
| 228 | - * | |
| 229 | - * @param string $value - Content | |
| 230 | - * @param string $type - Type of rendering value | |
| 231 | - * @param array $field - Field details | |
| 232 | - * | |
| 233 | - * @return string - Value with rendered shortcodes | |
| 234 | - */ | |
| 235 | - public function render_shortcodes($value, $type = false, $field = array()) { | |
| 270 | + /** | |
| 271 | + * MemberPress Mail attachments | |
| 272 | + * https://memberpress.com/ | |
| 273 | + */ | |
| 274 | + add_filter('mepr_email_send_attachments', [$this, 'filter_mepr_email_send_attachments'], 10, 4); | |
| 275 | + add_filter('the_content', [$this, 'filter_mepr_the_content'], 99); | |
| 276 | + add_filter('mepr_custom_thankyou_message', [$this, 'filter_mepr_custom_thankyou_message']); | |
| 236 | 277 | |
| 237 | - $dataset_id = $this->get('dataset'); | |
| 238 | - $item_id = $this->get('item'); | |
| 239 | - $post = get_post($dataset_id); | |
| 278 | + /** | |
| 279 | + * Thrive Theme Builder dynamic shortcode support | |
| 280 | + */ | |
| 281 | + add_filter('thrive_theme_template_content', [$this, 'filter_thrive_theme_template_content']); | |
| 240 | 282 | |
| 241 | - $ext_shortcodes = array( | |
| 242 | - "[id]" => $post->ID, | |
| 243 | - "[post_author]" => get_userdata($post->post_author)->user_nicename, | |
| 244 | - "[post_date]" => $post->post_date, | |
| 245 | - "[post_date_gmt]" => $post->post_date_gmt, | |
| 246 | - "[post_content]" => $post->post_content, | |
| 247 | - "[post_title]" => $post->post_title, | |
| 248 | - "[post_excerpt]" => $post->post_excerpt, | |
| 249 | - "[post_status]" => $post->post_status, | |
| 250 | - "[comment_status]" => $post->comment_status, | |
| 251 | - "[ping_status]" => $post->ping_status, | |
| 252 | - "[post_password]" => $post->post_password, | |
| 253 | - "[post_name]" => $post->post_name, | |
| 254 | - "[to_ping]" => $post->to_ping, | |
| 255 | - "[pinged]" => $post->pinged, | |
| 256 | - "[post_modified]" => $post->post_modified, | |
| 257 | - "[post_modified_gmt]" => $post->post_modified_gmt, | |
| 258 | - "[post_content_filtered]" => $post->post_content_filtered, | |
| 259 | - "[post_parent]" => $post->post_parent, | |
| 260 | - "[guid]" => $post->guid, | |
| 261 | - "[menu_order]" => $post->menu_order, | |
| 262 | - "[post_type]" => $post->post_type, | |
| 263 | - "[post_mime_type]" => $post->post_mime_type, | |
| 264 | - "[comment_count]" => $post->comment_count, | |
| 265 | - "[filter]" => $post->filter | |
| 266 | - ); | |
| 283 | + /** | |
| 284 | + * WPBakery Page Builder Grid Item | |
| 285 | + * [e2pdf-download id="1" dataset="{{ post_data:ID }}"] | |
| 286 | + */ | |
| 287 | + add_filter('vc_basic_grid_items_list', [$this, 'filter_vc_basic_grid_items_list']); | |
| 267 | 288 | |
| 289 | + /** | |
| 290 | + * Themify Builder dynamic shortcode support | |
| 291 | + * https://wordpress.org/plugins/themify-builder/ | |
| 292 | + */ | |
| 293 | + add_filter('themify_builder_module_content', [$this, 'filter_themify_builder_module_content']); | |
| 268 | 294 | |
| 269 | - $post_content = false; | |
| 295 | + /** | |
| 296 | + * Impreza theme by Up Solutions | |
| 297 | + * https://themeforest.net/item/impreza-retina-responsive-wordpress-theme/6434280 | |
| 298 | + */ | |
| 299 | + add_filter('us_content_template_the_content', [$this, 'filter_content_custom']); | |
| 270 | 300 | |
| 271 | - if (false !== strpos($value, '[')) { | |
| 301 | + /** | |
| 302 | + * Cornerstone Builder | |
| 303 | + * https://theme.co/cornerstone/ | |
| 304 | + */ | |
| 305 | + add_filter('cs_element_pre_render', [$this, 'filter_cs_element_pre_render']); | |
| 272 | 306 | |
| 273 | - $shortcode_tags = array( | |
| 274 | - 'meta', | |
| 275 | - ); | |
| 276 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); | |
| 277 | - $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 307 | + /** | |
| 308 | + * Divi Theme Builder | |
| 309 | + * https://www.elegantthemes.com/ | |
| 310 | + */ | |
| 311 | + add_filter('et_pb_module_content', [$this, 'filter_et_pb_module_content'], 30, 6); | |
| 278 | 312 | |
| 279 | - if (!empty($tagnames)) { | |
| 280 | - $pattern = get_shortcode_regex($tagnames); | |
| 313 | + /** | |
| 314 | + * User Registration & Membership – Custom Registration Form, Login Form, and User Profile | |
| 315 | + * https://wordpress.org/plugins/user-registration/ | |
| 316 | + */ | |
| 317 | + add_filter('user_registration_smart_tag_values', [$this, 'filter_user_registration_smart_tag_values'], 0); | |
| 281 | 318 | |
| 282 | - preg_match_all("/$pattern/", $value, $shortcodes); | |
| 319 | + /** | |
| 320 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 321 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 322 | + */ | |
| 323 | + add_filter('um_email_send_message_content', [$this, 'filter_um_email_send_message_content']); | |
| 283 | 324 | |
| 284 | - foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 285 | - $shortcode = array(); | |
| 286 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 287 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 288 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 289 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 290 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 291 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 325 | + /** | |
| 326 | + * Shortcodes do not render when the Toolset template is used | |
| 327 | + * https://toolset.com/ | |
| 328 | + */ | |
| 329 | + add_filter('wpv_filter_content_template_output', [$this, 'filter_wpv_filter_content_template_output']); | |
| 292 | 330 | |
| 293 | - $atts = shortcode_parse_atts($shortcode[3]); | |
| 331 | + /* Hooks */ | |
| 332 | + add_filter('post_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2); | |
| 333 | + add_filter('page_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2); | |
| 334 | + add_filter('user_row_actions', [$this, 'hook_wordpress_row_actions'], 10, 2); | |
| 335 | + } | |
| 294 | 336 | |
| 295 | - if (array_key_exists('key', $atts)) { | |
| 296 | - $value = str_replace($shortcode_value, get_post_meta($post->ID, $atts['key'], true), $value); | |
| 297 | - } | |
| 298 | - } | |
| 299 | - } | |
| 337 | + // load actions | |
| 338 | + public function load_actions() { | |
| 339 | + /** | |
| 340 | + * Elementor Website Builder – More than Just a Page Builder | |
| 341 | + * https://wordpress.org/plugins/elementor/ | |
| 342 | + */ | |
| 343 | + add_action('elementor/widget/before_render_content', [$this, 'action_elementor_widget_before_render_content']); | |
| 344 | + add_action('elementor/frontend/widget/before_render', [$this, 'action_elementor_widget_before_render_content'], 5); | |
| 300 | 345 | |
| 301 | - $shortcode_tags = array( | |
| 302 | - 'e2pdf-format-number', | |
| 303 | - 'e2pdf-format-date', | |
| 304 | - 'e2pdf-format-output', | |
| 305 | - ); | |
| 306 | - preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); | |
| 307 | - $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 346 | + /** | |
| 347 | + * JetEngine: WordPress Plugin for Elementor | |
| 348 | + * https://crocoblock.com | |
| 349 | + */ | |
| 350 | + add_action('jet-engine/listing/grid/before-render', [$this, 'action_jet_engine_listing_grid_before_render']); | |
| 351 | + add_action('jet-engine/listing/grid/after-render', [$this, 'action_jet_engine_listing_grid_after_render']); | |
| 308 | 352 | |
| 309 | - if (!empty($tagnames)) { | |
| 353 | + /** | |
| 354 | + * Happy Addons for Elementor | |
| 355 | + * https://wordpress.org/plugins/happy-elementor-addons/ compatibility fix | |
| 356 | + */ | |
| 357 | + add_action('elementor/frontend/before_render', [$this, 'action_elementor_widget_before_render_content'], 0); | |
| 310 | 358 | |
| 311 | - $pattern = get_shortcode_regex($tagnames); | |
| 312 | - preg_match_all("/$pattern/", $value, $shortcodes); | |
| 313 | - foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 314 | - $shortcode = array(); | |
| 315 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 316 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 317 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 318 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 319 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 320 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 359 | + /** | |
| 360 | + * MemberPress Mail attachments remove | |
| 361 | + * https://memberpress.com/ | |
| 362 | + */ | |
| 363 | + add_action('mepr_email_sent', [$this, 'action_mepr_email_sent']); | |
| 321 | 364 | |
| 322 | - if (isset($shortcode['5'])) { | |
| 323 | - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { | |
| 324 | - $sub_value = $this->render($shortcode['5'], $type); | |
| 325 | - } else { | |
| 326 | - $sub_value = $this->render($shortcode['5'], $type, $field); | |
| 327 | - } | |
| 328 | - $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value); | |
| 329 | - } | |
| 330 | - } | |
| 331 | - } | |
| 332 | - } | |
| 365 | + /** | |
| 366 | + * User Registration & Membership – Custom Registration Form, Login Form, and User Profile | |
| 367 | + * https://wordpress.org/plugins/user-registration/ | |
| 368 | + */ | |
| 369 | + add_action('user_registration_email_send_before', [$this, 'action_user_registration_email_send_before']); | |
| 370 | + add_action('user_registration_email_send_after', [$this, 'action_user_registration_email_send_after']); | |
| 333 | 371 | |
| 334 | - $value = do_shortcode($value); | |
| 372 | + /** | |
| 373 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 374 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 375 | + */ | |
| 376 | + add_action('um_before_email_notification_sending', [$this, 'action_um_before_email_notification_sending']); | |
| 377 | + add_action('um_after_email_notification_sending', [$this, 'action_um_after_email_notification_sending']); | |
| 335 | 378 | |
| 336 | - if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { | |
| 337 | - $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false; | |
| 338 | - if ($esig) { | |
| 339 | - //process e-signature | |
| 340 | - $value = ""; | |
| 341 | - } else { | |
| 342 | - if (!$this->helper->load('image')->get_image($value)) { | |
| 343 | - $value = $this->strip_shortcodes($value); | |
| 344 | - if ( | |
| 345 | - $value && | |
| 346 | - trim($value) != "" && | |
| 347 | - extension_loaded('gd') && | |
| 348 | - function_exists('imagettftext') | |
| 349 | - ) { | |
| 350 | - if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { | |
| 351 | - $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']); | |
| 352 | - } else { | |
| 353 | - $penColour = array(0x14, 0x53, 0x94); | |
| 354 | - } | |
| 379 | + /* Hooks */ | |
| 380 | + add_action('add_meta_boxes', [$this, 'hook_wordpress_page_edit']); | |
| 381 | + } | |
| 355 | 382 | |
| 356 | - $default_options = array( | |
| 357 | - 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), | |
| 358 | - 'bgColour' => 'transparent', | |
| 359 | - 'penColour' => $penColour | |
| 360 | - ); | |
| 383 | + // render | |
| 384 | + public function render($value, $field = [], $convert_shortcodes = true, $raw = false) { | |
| 385 | + $value = $this->render_shortcodes($value, $field); | |
| 386 | + if (!$raw) { | |
| 387 | + $value = $this->strip_shortcodes($value); | |
| 388 | + $value = $this->convert_shortcodes($value, $convert_shortcodes, isset($field['type']) && $field['type'] == 'e2pdf-html' ? true : false); | |
| 389 | + $value = $this->helper->load('field')->render_checkbox($value, $this, $field); | |
| 390 | + } | |
| 391 | + return $value; | |
| 392 | + } | |
| 361 | 393 | |
| 362 | - $options = array(); | |
| 363 | - $options = array_merge($default_options, $options); | |
| 394 | + // render shortcodes | |
| 395 | + public function render_shortcodes($value, $field = []) { | |
| 364 | 396 | |
| 365 | - $model_e2pdf_font = new Model_E2pdf_Font(); | |
| 397 | + $element_id = isset($field['element_id']) ? $field['element_id'] : false; | |
| 366 | 398 | |
| 367 | - $font = false; | |
| 368 | - if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { | |
| 369 | - $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); | |
| 370 | - } | |
| 371 | - if (!$font) { | |
| 372 | - $font = $model_e2pdf_font->get_font_path('Noto Sans'); | |
| 373 | - } | |
| 399 | + if ($this->verify()) { | |
| 400 | + /** | |
| 401 | + * Set current Post for Toolset Views | |
| 402 | + * https://toolset.com/ | |
| 403 | + */ | |
| 404 | + do_action('wpv_action_wpv_set_top_current_post', $this->get('cached_post')); | |
| 374 | 405 | |
| 375 | - $size = 150; | |
| 376 | - if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { | |
| 377 | - $size = $field['properties']['text_font_size']; | |
| 406 | + $wordpress_shortcodes = [ | |
| 407 | + 'id', | |
| 408 | + 'post_author', | |
| 409 | + 'post_date', | |
| 410 | + 'post_date_gmt', | |
| 411 | + 'post_content', | |
| 412 | + 'post_title', | |
| 413 | + 'post_excerpt', | |
| 414 | + 'post_status', | |
| 415 | + 'comment_status', | |
| 416 | + 'ping_status', | |
| 417 | + 'post_password', | |
| 418 | + 'post_name', | |
| 419 | + 'to_ping', | |
| 420 | + 'pinged', | |
| 421 | + 'post_modified', | |
| 422 | + 'post_modified_gmt', | |
| 423 | + 'post_content_filtered', | |
| 424 | + 'post_parent', | |
| 425 | + 'guid', | |
| 426 | + 'menu_order', | |
| 427 | + 'post_type', | |
| 428 | + 'post_mime_type', | |
| 429 | + 'comment_count', | |
| 430 | + 'filter', | |
| 431 | + 'post_thumbnail', | |
| 432 | + 'get_the_post_thumbnail', | |
| 433 | + 'get_the_post_thumbnail_url', | |
| 434 | + 'get_permalink', | |
| 435 | + 'get_post_permalink', | |
| 436 | + ]; | |
| 437 | + | |
| 438 | + if (false !== strpos($value, '[')) { | |
| 439 | + $value = $this->helper->load('field')->pre_shortcodes($value, $this, $field); | |
| 440 | + $value = $this->helper->load('field')->inner_shortcodes($value, $this, $field); | |
| 441 | + if ($this->get('item') == '-3') { | |
| 442 | + $shortcode_tags = [ | |
| 443 | + 'acf', | |
| 444 | + ]; | |
| 445 | + } else { | |
| 446 | + $shortcode_tags = [ | |
| 447 | + 'meta', | |
| 448 | + 'terms', | |
| 449 | + 'e2pdf-wp', | |
| 450 | + 'e2pdf-wp-term', | |
| 451 | + 'e2pdf-content', | |
| 452 | + 'acf', | |
| 453 | + ]; | |
| 454 | + $shortcode_tags = array_merge($shortcode_tags, $wordpress_shortcodes); | |
| 455 | + } | |
| 456 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); | |
| 457 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 458 | + if (!empty($tagnames)) { | |
| 459 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $value, $shortcodes); | |
| 460 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 461 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 462 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 463 | + if ($shortcode[2] === 'e2pdf-content') { | |
| 464 | + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) { | |
| 465 | + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . ''; | |
| 466 | + $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value); | |
| 467 | + } | |
| 468 | + } elseif ($shortcode[2] === 'meta' || $shortcode[2] === 'terms' || $shortcode[2] == 'e2pdf-wp') { | |
| 469 | + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) { | |
| 470 | + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . ''; | |
| 471 | + } | |
| 472 | + if ($shortcode[2] === 'meta') { | |
| 473 | + $shortcode[3] .= ' meta=true'; | |
| 474 | + } | |
| 475 | + if ($shortcode[2] === 'terms') { | |
| 476 | + $shortcode[3] .= ' terms=true'; | |
| 477 | + } | |
| 478 | + if (substr($shortcode_value, -11) === '[/e2pdf-wp]' || substr($shortcode_value, -8) === '[/terms]' || substr($shortcode_value, -7) === '[/meta]') { | |
| 479 | + if ($shortcode[5]) { | |
| 480 | + $shortcode[5] = $this->render($shortcode[5], [], false); | |
| 481 | + } | |
| 482 | + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp]', $value); | |
| 483 | + } else { | |
| 484 | + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value); | |
| 485 | + } | |
| 486 | + } elseif ($shortcode[2] === 'e2pdf-wp-term') { | |
| 487 | + if (substr($shortcode_value, -16) === '[/e2pdf-wp-term]') { | |
| 488 | + if ($shortcode[5]) { | |
| 489 | + $shortcode[5] = $this->render($shortcode[5], [], false); | |
| 490 | + } | |
| 491 | + $value = str_replace($shortcode_value, '[e2pdf-wp-term' . $shortcode[3] . ']' . $shortcode[5] . '[/e2pdf-wp-term]', $value); | |
| 492 | + } | |
| 493 | + } elseif (in_array($shortcode[2], $wordpress_shortcodes, false)) { | |
| 494 | + if (!isset($atts['id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) { | |
| 495 | + $shortcode[3] .= ' id=' . $this->get('cached_post')->ID . ''; | |
| 496 | + } | |
| 497 | + $shortcode[3] .= ' key=' . $shortcode[2] . ''; | |
| 498 | + $value = str_replace($shortcode_value, '[e2pdf-wp' . $shortcode[3] . ']', $value); | |
| 499 | + } elseif ($shortcode[2] === 'acf') { | |
| 500 | + if (!isset($atts['post_id']) && isset($this->get('cached_post')->ID) && $this->get('cached_post')->ID) { | |
| 501 | + if ($this->get('item') == '-3') { | |
| 502 | + $shortcode[3] .= ' post_id=user_' . $this->get('cached_post')->ID . ''; | |
| 503 | + } else { | |
| 504 | + $shortcode[3] .= ' post_id=' . $this->get('cached_post')->ID . ''; | |
| 505 | + } | |
| 506 | + $value = str_replace($shortcode_value, '[' . $shortcode[2] . $shortcode[3] . ']', $value); | |
| 507 | + } | |
| 378 | 508 | } |
| 379 | - | |
| 380 | - $model_e2pdf_signature = new Model_E2pdf_Signature(); | |
| 381 | - $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); | |
| 382 | - } else { | |
| 383 | - $value = ""; | |
| 384 | 509 | } |
| 385 | 510 | } |
| 511 | + $value = $this->helper->load('field')->wrapper_shortcodes($value, $this, $field); | |
| 386 | 512 | } |
| 387 | - } else { | |
| 388 | - if (strpos($value, "[post_content]") !== FALSE && !$this->get('no_filter') && !$post_content) { | |
| 389 | - $ext_shortcodes['[post_content]'] = $this->before_render_post_content($ext_shortcodes['[post_content]']); | |
| 390 | - $ext_shortcodes['[post_content]'] = apply_filters('the_content', $ext_shortcodes['[post_content]']); | |
| 391 | - $ext_shortcodes['[post_content]'] = str_replace("</p>", "</p> \r\n", $ext_shortcodes['[post_content]']); | |
| 392 | - $post_content = true; | |
| 393 | - } | |
| 394 | - $value = str_replace(array_keys($ext_shortcodes), $ext_shortcodes, $value); | |
| 395 | - $value = $this->convert_shortcodes($value); | |
| 513 | + | |
| 514 | + add_filter('frm_filter_view', [$this, 'filter_frm_filter_view']); | |
| 515 | + $value = $this->helper->load('field')->do_shortcodes($value, $this, $field); | |
| 516 | + $value = $this->helper->load('field')->render( | |
| 517 | + apply_filters('e2pdf_extension_render_shortcodes_pre_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false), | |
| 518 | + $this, | |
| 519 | + $field | |
| 520 | + ); | |
| 521 | + remove_filter('frm_filter_view', [$this, 'filter_frm_filter_view']); | |
| 396 | 522 | } |
| 397 | - return $value; | |
| 523 | + return apply_filters( | |
| 524 | + 'e2pdf_extension_render_shortcodes_value', $value, $element_id, $this->get('template_id'), $this->get('item'), $this->get('dataset'), false, false | |
| 525 | + ); | |
| 398 | 526 | } |
| 399 | 527 | |
| 400 | - public function filter_custom_shortcodes() { | |
| 401 | - | |
| 402 | - } | |
| 403 | - | |
| 404 | - /** | |
| 405 | - * Strip unused shortcodes | |
| 406 | - * | |
| 407 | - * @param string $value - Content | |
| 408 | - * | |
| 409 | - * @return string - Value with removed unused shortcodes | |
| 410 | - */ | |
| 528 | + // strip shortcodes | |
| 411 | 529 | public function strip_shortcodes($value) { |
| 412 | - $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); | |
| 530 | + $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', '', $value); | |
| 413 | 531 | return $value; |
| 414 | 532 | } |
| 415 | 533 | |
| 416 | - public function convert_shortcodes($value, $to = false) { | |
| 534 | + // convert shortcodes | |
| 535 | + public function convert_shortcodes($value, $to = false, $html = false) { | |
| 417 | 536 | if ($value) { |
| 418 | 537 | if ($to) { |
| 419 | - $value = str_replace("[", "[", $value); | |
| 538 | + $value = str_replace('[', '[', $value); | |
| 539 | + if (!$html) { | |
| 540 | + $value = wp_specialchars_decode($value, ENT_QUOTES); | |
| 541 | + } | |
| 420 | 542 | } else { |
| 421 | - $value = str_replace("[", "[", $value); | |
| 543 | + $value = str_replace('[', '[', $value); | |
| 422 | 544 | } |
| 423 | 545 | } |
| 424 | 546 | return $value; |
| 425 | 547 | } |
| 426 | 548 | |
| 549 | + // auto | |
| 427 | 550 | public function auto() { |
| 428 | - $response = array(); | |
| 429 | - $elements = array(); | |
| 430 | 551 | |
| 431 | - $post = $this->get('item'); | |
| 552 | + $response = []; | |
| 553 | + $elements = []; | |
| 432 | 554 | |
| 433 | - $elements[] = array( | |
| 434 | - 'type' => 'e2pdf-html', | |
| 435 | - 'block' => true, | |
| 436 | - 'properties' => array( | |
| 437 | - 'top' => '20', | |
| 438 | - 'left' => '20', | |
| 439 | - 'right' => '20', | |
| 440 | - 'width' => '100%', | |
| 441 | - 'height' => 'auto', | |
| 442 | - 'value' => "<h1>[post_title]</h1>", | |
| 443 | - ) | |
| 444 | - ); | |
| 555 | + if ($this->get('item') == '-3') { | |
| 556 | + $elements[] = [ | |
| 557 | + 'type' => 'e2pdf-html', | |
| 558 | + 'block' => true, | |
| 559 | + 'properties' => [ | |
| 560 | + 'top' => '20', | |
| 561 | + 'left' => '20', | |
| 562 | + 'right' => '20', | |
| 563 | + 'width' => '100%', | |
| 564 | + 'height' => 'auto', | |
| 565 | + 'value' => '<h1>[e2pdf-user key="user_login"]</h1>', | |
| 566 | + ], | |
| 567 | + ]; | |
| 568 | + $elements[] = [ | |
| 569 | + 'type' => 'e2pdf-image', | |
| 570 | + 'block' => true, | |
| 571 | + 'properties' => [ | |
| 572 | + 'top' => '20', | |
| 573 | + 'left' => '20', | |
| 574 | + 'right' => '20', | |
| 575 | + 'width' => '100%', | |
| 576 | + 'height' => '100', | |
| 577 | + 'vertical' => 'top', | |
| 578 | + 'value' => '[e2pdf-user key="get_avatar_url"]', | |
| 579 | + ], | |
| 580 | + ]; | |
| 581 | + $elements[] = [ | |
| 582 | + 'type' => 'e2pdf-html', | |
| 583 | + 'block' => true, | |
| 584 | + 'properties' => [ | |
| 585 | + 'top' => '20', | |
| 586 | + 'left' => '20', | |
| 587 | + 'right' => '20', | |
| 588 | + 'width' => '100%', | |
| 589 | + 'height' => 'auto', | |
| 590 | + 'value' => 'ID: [e2pdf-user key="ID"]', | |
| 591 | + ], | |
| 592 | + ]; | |
| 593 | + $elements[] = [ | |
| 594 | + 'type' => 'e2pdf-html', | |
| 595 | + 'block' => true, | |
| 596 | + 'properties' => [ | |
| 597 | + 'top' => '20', | |
| 598 | + 'left' => '20', | |
| 599 | + 'right' => '20', | |
| 600 | + 'width' => '100%', | |
| 601 | + 'height' => 'auto', | |
| 602 | + 'value' => 'First Name: [e2pdf-user key="user_firstname"]', | |
| 603 | + ], | |
| 604 | + ]; | |
| 605 | + $elements[] = [ | |
| 606 | + 'type' => 'e2pdf-html', | |
| 607 | + 'block' => true, | |
| 608 | + 'properties' => [ | |
| 609 | + 'top' => '20', | |
| 610 | + 'left' => '20', | |
| 611 | + 'right' => '20', | |
| 612 | + 'width' => '100%', | |
| 613 | + 'height' => 'auto', | |
| 614 | + 'value' => 'Last Name: [e2pdf-user key="user_lastname"]', | |
| 615 | + ], | |
| 616 | + ]; | |
| 617 | + $elements[] = [ | |
| 618 | + 'type' => 'e2pdf-html', | |
| 619 | + 'block' => true, | |
| 620 | + 'properties' => [ | |
| 621 | + 'top' => '20', | |
| 622 | + 'left' => '20', | |
| 623 | + 'right' => '20', | |
| 624 | + 'width' => '100%', | |
| 625 | + 'height' => 'auto', | |
| 626 | + 'value' => 'Email: [e2pdf-user key="user_email"]', | |
| 627 | + ], | |
| 628 | + ]; | |
| 629 | + $elements[] = [ | |
| 630 | + 'type' => 'e2pdf-html', | |
| 631 | + 'block' => true, | |
| 632 | + 'properties' => [ | |
| 633 | + 'top' => '20', | |
| 634 | + 'left' => '20', | |
| 635 | + 'right' => '20', | |
| 636 | + 'width' => '100%', | |
| 637 | + 'height' => 'auto', | |
| 638 | + 'value' => 'Registered: [e2pdf-user key="user_registered"]', | |
| 639 | + ], | |
| 640 | + ]; | |
| 641 | + } else { | |
| 642 | + $elements[] = [ | |
| 643 | + 'type' => 'e2pdf-html', | |
| 644 | + 'block' => true, | |
| 645 | + 'properties' => [ | |
| 646 | + 'top' => '20', | |
| 647 | + 'left' => '20', | |
| 648 | + 'right' => '20', | |
| 649 | + 'width' => '100%', | |
| 650 | + 'height' => 'auto', | |
| 651 | + 'value' => '<h1>[e2pdf-wp key="post_title"]</h1>', | |
| 652 | + ], | |
| 653 | + ]; | |
| 654 | + $elements[] = [ | |
| 655 | + 'type' => 'e2pdf-html', | |
| 656 | + 'block' => true, | |
| 657 | + 'properties' => [ | |
| 658 | + 'top' => '20', | |
| 659 | + 'left' => '20', | |
| 660 | + 'right' => '20', | |
| 661 | + 'width' => '100%', | |
| 662 | + 'height' => 'auto', | |
| 663 | + 'value' => 'Post name: [e2pdf-wp key="post_name"]', | |
| 664 | + ], | |
| 665 | + ]; | |
| 666 | + $elements[] = [ | |
| 667 | + 'type' => 'e2pdf-html', | |
| 668 | + 'block' => true, | |
| 669 | + 'properties' => [ | |
| 670 | + 'top' => '20', | |
| 671 | + 'left' => '20', | |
| 672 | + 'right' => '20', | |
| 673 | + 'width' => '100%', | |
| 674 | + 'height' => 'auto', | |
| 675 | + 'value' => 'Post type: [e2pdf-wp key="post_type"]', | |
| 676 | + ], | |
| 677 | + ]; | |
| 678 | + $elements[] = [ | |
| 679 | + 'type' => 'e2pdf-html', | |
| 680 | + 'block' => true, | |
| 681 | + 'properties' => [ | |
| 682 | + 'top' => '20', | |
| 683 | + 'left' => '20', | |
| 684 | + 'right' => '20', | |
| 685 | + 'width' => '100%', | |
| 686 | + 'height' => 'auto', | |
| 687 | + 'value' => 'ID: [e2pdf-wp key="id"]', | |
| 688 | + ], | |
| 689 | + ]; | |
| 690 | + $elements[] = [ | |
| 691 | + 'type' => 'e2pdf-html', | |
| 692 | + 'block' => true, | |
| 693 | + 'properties' => [ | |
| 694 | + 'top' => '20', | |
| 695 | + 'left' => '20', | |
| 696 | + 'right' => '20', | |
| 697 | + 'width' => '100%', | |
| 698 | + 'height' => 'auto', | |
| 699 | + 'value' => 'Author: [e2pdf-wp key="post_author"]', | |
| 700 | + ], | |
| 701 | + ]; | |
| 702 | + $elements[] = [ | |
| 703 | + 'type' => 'e2pdf-html', | |
| 704 | + 'block' => true, | |
| 705 | + 'properties' => [ | |
| 706 | + 'top' => '20', | |
| 707 | + 'left' => '20', | |
| 708 | + 'right' => '20', | |
| 709 | + 'width' => '100%', | |
| 710 | + 'height' => '300', | |
| 711 | + 'value' => '[e2pdf-wp key="post_content"]', | |
| 712 | + ], | |
| 713 | + ]; | |
| 714 | + $elements[] = [ | |
| 715 | + 'type' => 'e2pdf-html', | |
| 716 | + 'block' => true, | |
| 717 | + 'properties' => [ | |
| 718 | + 'top' => '20', | |
| 719 | + 'left' => '20', | |
| 720 | + 'right' => '20', | |
| 721 | + 'width' => '100%', | |
| 722 | + 'height' => 'auto', | |
| 723 | + 'value' => 'Created: [e2pdf-wp key="post_date"]', | |
| 724 | + ], | |
| 725 | + ]; | |
| 726 | + $elements[] = [ | |
| 727 | + 'type' => 'e2pdf-html', | |
| 728 | + 'block' => true, | |
| 729 | + 'properties' => [ | |
| 730 | + 'top' => '20', | |
| 731 | + 'left' => '20', | |
| 732 | + 'right' => '20', | |
| 733 | + 'width' => '100%', | |
| 734 | + 'height' => 'auto', | |
| 735 | + 'value' => 'Modified: [e2pdf-wp key="post_modified"]', | |
| 736 | + ], | |
| 737 | + ]; | |
| 738 | + } | |
| 739 | + $response['page'] = [ | |
| 740 | + 'bottom' => '20', | |
| 741 | + 'top' => '20', | |
| 742 | + 'left' => '20', | |
| 743 | + 'right' => '20', | |
| 744 | + ]; | |
| 445 | 745 | |
| 446 | - $elements[] = array( | |
| 447 | - 'type' => 'e2pdf-html', | |
| 448 | - 'block' => true, | |
| 449 | - 'properties' => array( | |
| 450 | - 'top' => '20', | |
| 451 | - 'left' => '20', | |
| 452 | - 'right' => '20', | |
| 453 | - 'width' => '100%', | |
| 454 | - 'height' => 'auto', | |
| 455 | - 'value' => __("Post name", 'e2pdf') . ": [post_name]", | |
| 456 | - ) | |
| 457 | - ); | |
| 746 | + $response['elements'] = $elements; | |
| 747 | + return $response; | |
| 748 | + } | |
| 458 | 749 | |
| 459 | - $elements[] = array( | |
| 460 | - 'type' => 'e2pdf-html', | |
| 461 | - 'block' => true, | |
| 462 | - 'properties' => array( | |
| 463 | - 'top' => '20', | |
| 464 | - 'left' => '20', | |
| 465 | - 'right' => '20', | |
| 466 | - 'width' => '100%', | |
| 467 | - 'height' => 'auto', | |
| 468 | - 'value' => __("Post type", 'e2pdf') . ": [post_type]", | |
| 469 | - ) | |
| 470 | - ); | |
| 750 | + // before render content widget action | |
| 751 | + public function action_elementor_widget_before_render_content($widget) { | |
| 752 | + if ($widget && ($widget->get_name() == 'shortcode' || $widget->get_name() == 'text-editor')) { | |
| 753 | + $content = $widget->get_name() == 'shortcode' ? $widget->get_settings('shortcode') : $widget->get_settings('editor'); | |
| 754 | + if ($content && false !== strpos($content, '[e2pdf-')) { | |
| 755 | + $wp_reset_postdata = true; | |
| 756 | + if (class_exists('\ElementorPro\Plugin') && class_exists('\ElementorPro\Modules\LoopBuilder\Documents\Loop')) { | |
| 757 | + $document = \ElementorPro\Plugin::elementor()->documents->get_current(); | |
| 758 | + if ($document && $document instanceof \ElementorPro\Modules\LoopBuilder\Documents\Loop) { | |
| 759 | + $wp_reset_postdata = false; | |
| 760 | + } | |
| 761 | + } | |
| 762 | + if ($widget->get_name() == 'shortcode') { | |
| 763 | + $widget->set_settings('shortcode', $this->filter_content($content, false, $wp_reset_postdata)); | |
| 764 | + } elseif ($widget->get_name() == 'text-editor' && !$wp_reset_postdata) { | |
| 765 | + $widget->set_settings('editor', $this->filter_content($content, false, $wp_reset_postdata)); | |
| 766 | + } | |
| 767 | + } | |
| 768 | + } | |
| 769 | + } | |
| 471 | 770 | |
| 771 | + // jet engine listing grid before render action | |
| 772 | + public function action_jet_engine_listing_grid_before_render($listing_grid) { | |
| 773 | + $this->set('queried_object', true); | |
| 774 | + } | |
| 472 | 775 | |
| 473 | - $elements[] = array( | |
| 474 | - 'type' => 'e2pdf-html', | |
| 475 | - 'block' => true, | |
| 476 | - 'properties' => array( | |
| 477 | - 'top' => '20', | |
| 478 | - 'left' => '20', | |
| 479 | - 'right' => '20', | |
| 480 | - 'width' => '100%', | |
| 481 | - 'height' => 'auto', | |
| 482 | - 'value' => __("ID", 'e2pdf') . ": [id]", | |
| 483 | - ) | |
| 484 | - ); | |
| 776 | + // jet engine listing grid after render action | |
| 777 | + public function action_jet_engine_listing_grid_after_render($listing_grid) { | |
| 778 | + $this->set('queried_object', false); | |
| 779 | + } | |
| 485 | 780 | |
| 486 | - $elements[] = array( | |
| 487 | - 'type' => 'e2pdf-html', | |
| 488 | - 'block' => true, | |
| 489 | - 'properties' => array( | |
| 490 | - 'top' => '20', | |
| 491 | - 'left' => '20', | |
| 492 | - 'right' => '20', | |
| 493 | - 'width' => '100%', | |
| 494 | - 'height' => 'auto', | |
| 495 | - 'value' => __("Author", 'e2pdf') . ": [post_author]", | |
| 496 | - ) | |
| 497 | - ); | |
| 781 | + /** | |
| 782 | + * Delete attachments that were sent by MemberPress email | |
| 783 | + * https://memberpress.com/ | |
| 784 | + */ | |
| 785 | + public function action_mepr_email_sent() { | |
| 786 | + $files = $this->helper->get('wordpress_attachments_mepr'); | |
| 787 | + if (is_array($files) && !empty($files)) { | |
| 788 | + foreach ($files as $key => $file) { | |
| 789 | + $this->helper->delete_dir(dirname($file) . '/'); | |
| 790 | + } | |
| 791 | + $this->helper->deset('wordpress_attachments_mepr'); | |
| 792 | + } | |
| 793 | + } | |
| 498 | 794 | |
| 499 | - $elements[] = array( | |
| 500 | - 'type' => 'e2pdf-html', | |
| 501 | - 'block' => true, | |
| 502 | - 'properties' => array( | |
| 503 | - 'top' => '20', | |
| 504 | - 'left' => '20', | |
| 505 | - 'right' => '20', | |
| 506 | - 'width' => '100%', | |
| 507 | - 'height' => '300', | |
| 508 | - 'value' => "[post_content]", | |
| 509 | - 'dynamic_height' => '1', | |
| 510 | - ) | |
| 511 | - ); | |
| 795 | + // registration email send before action | |
| 796 | + public function action_user_registration_email_send_before() { | |
| 797 | + add_filter('wp_mail', [$this, 'filter_wp_mail'], 11); | |
| 798 | + } | |
| 512 | 799 | |
| 513 | - $elements[] = array( | |
| 514 | - 'type' => 'e2pdf-html', | |
| 515 | - 'block' => true, | |
| 516 | - 'properties' => array( | |
| 517 | - 'top' => '20', | |
| 518 | - 'left' => '20', | |
| 519 | - 'right' => '20', | |
| 520 | - 'width' => '100%', | |
| 521 | - 'height' => 'auto', | |
| 522 | - 'value' => __("Created", 'e2pdf') . ": [post_date]", | |
| 523 | - ) | |
| 524 | - ); | |
| 800 | + // registration email send after action | |
| 801 | + public function action_user_registration_email_send_after() { | |
| 802 | + remove_filter('wp_mail', [$this, 'filter_wp_mail'], 11); | |
| 803 | + $files = $this->helper->get('wordpress_attachments'); | |
| 804 | + if (is_array($files) && !empty($files)) { | |
| 805 | + foreach ($files as $key => $file) { | |
| 806 | + $this->helper->delete_dir(dirname($file) . '/'); | |
| 807 | + } | |
| 808 | + $this->helper->deset('wordpress_attachments'); | |
| 809 | + } | |
| 810 | + } | |
| 525 | 811 | |
| 526 | - $elements[] = array( | |
| 527 | - 'type' => 'e2pdf-html', | |
| 528 | - 'block' => true, | |
| 529 | - 'properties' => array( | |
| 530 | - 'top' => '20', | |
| 531 | - 'left' => '20', | |
| 532 | - 'right' => '20', | |
| 533 | - 'width' => '100%', | |
| 534 | - 'height' => 'auto', | |
| 535 | - 'value' => __("Modified", 'e2pdf') . ": [post_modified]", | |
| 536 | - ) | |
| 537 | - ); | |
| 812 | + /** | |
| 813 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 814 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 815 | + */ | |
| 816 | + public function action_um_before_email_notification_sending() { | |
| 817 | + add_filter('wp_mail', [$this, 'filter_wp_mail_um'], 11); | |
| 818 | + } | |
| 538 | 819 | |
| 539 | - $response['page'] = array( | |
| 540 | - 'bottom' => '20', | |
| 541 | - 'top' => '20', | |
| 542 | - 'left' => '20', | |
| 543 | - 'right' => '20' | |
| 544 | - ); | |
| 820 | + /** | |
| 821 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 822 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 823 | + */ | |
| 824 | + public function action_um_after_email_notification_sending() { | |
| 825 | + remove_filter('wp_mail', [$this, 'filter_wp_mail_um'], 11); | |
| 826 | + $files = $this->helper->get('wordpress_attachments_um_del'); | |
| 827 | + if (is_array($files) && !empty($files)) { | |
| 828 | + foreach ($files as $key => $file) { | |
| 829 | + $this->helper->delete_dir(dirname($file) . '/'); | |
| 830 | + } | |
| 831 | + $this->helper->deset('wordpress_attachments_um'); | |
| 832 | + $this->helper->deset('wordpress_attachments_um_del'); | |
| 833 | + } | |
| 834 | + } | |
| 545 | 835 | |
| 546 | - $response['elements'] = $elements; | |
| 547 | - return $response; | |
| 836 | + /** | |
| 837 | + * Enable / Disable pre-rendering of E2Pdf shortcodes in the Toolset template. | |
| 838 | + * https://toolset.com/ | |
| 839 | + */ | |
| 840 | + public function filter_wpv_filter_content_template_output($content) { | |
| 841 | + add_filter('render_block', [$this, 'filter_render_block_toolset_disable'], 9, 2); | |
| 842 | + add_filter('render_block', [$this, 'filter_render_block_toolset_enable'], 11, 2); | |
| 843 | + return $content; | |
| 548 | 844 | } |
| 549 | 845 | |
| 550 | 846 | /** |
| 551 | - * Action before wordpress post/page render | |
| 552 | - * Force to apply e2pdf shortcodes | |
| 553 | - * | |
| 554 | - * @param string $content - Content | |
| 555 | - * | |
| 556 | - * @return string - Content with update shortcodes | |
| 847 | + * Disable pre-rendering of E2Pdf shortcodes in the Toolset template. | |
| 848 | + * https://toolset.com/ | |
| 557 | 849 | */ |
| 558 | - public function before_render_post_content($content) { | |
| 850 | + public function filter_render_block_toolset_disable($block_content, $block) { | |
| 851 | + if ( | |
| 852 | + !empty($block['blockName']) && strpos($block['blockName'], 'toolset-blocks/') === 0 && false !== strpos($block_content, '[e2pdf-') | |
| 853 | + ) { | |
| 854 | + remove_shortcode('e2pdf-download'); | |
| 855 | + remove_shortcode('e2pdf-view'); | |
| 856 | + remove_shortcode('e2pdf-save'); | |
| 857 | + remove_shortcode('e2pdf-zapier'); | |
| 858 | + remove_shortcode('e2pdf-adobesign'); | |
| 859 | + } | |
| 860 | + return $block_content; | |
| 861 | + } | |
| 559 | 862 | |
| 560 | - if (false === strpos($content, '[')) { | |
| 863 | + /** | |
| 864 | + * Enable rendering of E2Pdf shortcodes in the Toolset template. | |
| 865 | + * https://toolset.com/ | |
| 866 | + */ | |
| 867 | + public function filter_render_block_toolset_enable($block_content, $block) { | |
| 868 | + if ( | |
| 869 | + !empty($block['blockName']) && strpos($block['blockName'], 'toolset-blocks/') === 0 && false !== strpos($block_content, '[e2pdf-') | |
| 870 | + ) { | |
| 871 | + add_shortcode('e2pdf-download', [new Model_E2pdf_Shortcode(), 'e2pdf_download']); | |
| 872 | + add_shortcode('e2pdf-view', [new Model_E2pdf_Shortcode(), 'e2pdf_view']); | |
| 873 | + add_shortcode('e2pdf-save', [new Model_E2pdf_Shortcode(), 'e2pdf_save']); | |
| 874 | + add_shortcode('e2pdf-zapier', [new Model_E2pdf_Shortcode(), 'e2pdf_zapier']); | |
| 875 | + add_shortcode('e2pdf-adobesign', [new Model_E2pdf_Shortcode(), 'e2pdf_adobesign']); | |
| 876 | + } | |
| 877 | + return $block_content; | |
| 878 | + } | |
| 879 | + | |
| 880 | + // filter content | |
| 881 | + public function filter_content($content, $post_id = false, $wp_reset_postdata = true) { | |
| 882 | + global $post; | |
| 883 | + if (!is_string($content) || false === strpos($content, '[')) { | |
| 561 | 884 | return $content; |
| 562 | 885 | } |
| 563 | - | |
| 564 | - $shortcode_tags = array( | |
| 565 | - 'e2pdf-exclude', | |
| 566 | - ); | |
| 567 | - | |
| 886 | + $shortcode_tags = [ | |
| 887 | + 'e2pdf-download', | |
| 888 | + 'e2pdf-save', | |
| 889 | + 'e2pdf-view', | |
| 890 | + 'e2pdf-adobesign', | |
| 891 | + 'e2pdf-zapier', | |
| 892 | + ]; | |
| 568 | 893 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 569 | 894 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 570 | - | |
| 571 | 895 | if (!empty($tagnames)) { |
| 572 | - $pattern = get_shortcode_regex($tagnames); | |
| 896 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 897 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 898 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 899 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 900 | + if (isset($atts['wp_reset_postdata'])) { | |
| 901 | + if ($atts['wp_reset_postdata'] == 'true') { | |
| 902 | + $wp_reset_postdata = true; | |
| 903 | + } else { | |
| 904 | + $wp_reset_postdata = false; | |
| 905 | + } | |
| 906 | + } | |
| 907 | + if ($wp_reset_postdata) { | |
| 908 | + wp_reset_postdata(); | |
| 909 | + } | |
| 910 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf | |
| 911 | + } else { | |
| 912 | + if (isset($atts['id'])) { | |
| 913 | + $template = new Model_E2pdf_Template(); | |
| 914 | + $template->load($atts['id']); | |
| 915 | + if ($template->get('extension') === 'woocommerce' || $template->get('extension') === 'jetformbuilder') { | |
| 916 | + continue; | |
| 917 | + } elseif ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 918 | + if (!isset($atts['dataset'])) { | |
| 919 | + if ($template->get('item') == '-3') { | |
| 920 | + $dataset = get_current_user_id(); | |
| 921 | + $atts['dataset'] = $dataset; | |
| 922 | + $shortcode[3] .= ' dataset="' . $dataset . '"'; | |
| 923 | + } else { | |
| 924 | + if ($this->get('queried_object') && !$post_id) { | |
| 925 | + $queried_object = get_queried_object(); | |
| 926 | + $post_id = $queried_object && isset($queried_object->ID) ? $queried_object->ID : false; | |
| 927 | + } | |
| 928 | + if ($post_id || isset($post->ID)) { | |
| 929 | + $dataset = $post_id ? $post_id : $post->ID; | |
| 930 | + $atts['dataset'] = $dataset; | |
| 931 | + $shortcode[3] .= ' dataset="' . $dataset . '"'; | |
| 932 | + } | |
| 933 | + } | |
| 934 | + } | |
| 935 | + } | |
| 936 | + } | |
| 937 | + if (!isset($atts['apply'])) { | |
| 938 | + $shortcode[3] .= ' apply="true"'; | |
| 939 | + } | |
| 940 | + if (!isset($atts['filter'])) { | |
| 941 | + $shortcode[3] .= ' filter="true"'; | |
| 942 | + } | |
| 943 | + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); | |
| 944 | + } | |
| 945 | + } | |
| 946 | + } | |
| 947 | + return $content; | |
| 948 | + } | |
| 573 | 949 | |
| 574 | - preg_match_all("/$pattern/", $content, $shortcodes); | |
| 950 | + // [e2pdf-exclude] support inside Formidable Forms View beforeContent and afterContent | |
| 951 | + public function filter_frm_filter_view($view) { | |
| 952 | + if (isset($view->frm_before_content) && $view->frm_before_content) { | |
| 953 | + $view->frm_before_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_before_content); | |
| 954 | + } | |
| 955 | + if (isset($view->post_content) && $view->post_content) { | |
| 956 | + $view->post_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->post_content); | |
| 957 | + } | |
| 958 | + if (isset($view->frm_after_content) && $view->frm_after_content) { | |
| 959 | + $view->frm_after_content = str_replace('[e2pdf-exclude]', '[e2pdf-exclude apply="true"]', $view->frm_after_content); | |
| 960 | + } | |
| 961 | + return $view; | |
| 962 | + } | |
| 575 | 963 | |
| 576 | - foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 964 | + // vc map get attributes filter | |
| 965 | + public function filter_vc_map_get_attributes($atts, $tag) { | |
| 966 | + if ($tag == 'vc_single_image' && ((isset($atts['onclick']) && $atts['onclick'] == 'custom_link') || (empty($atts['onclick']) && (!isset($atts['img_link_large']) || 'yes' !== $atts['img_link_large']))) && (!empty($atts['link']) || !empty($atts['img_link']))) { | |
| 577 | 967 | |
| 578 | - $shortcode = array(); | |
| 579 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 580 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 581 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 582 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 583 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 584 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 968 | + if (!empty($atts['link'])) { | |
| 969 | + $atts['link'] = $this->filter_content($atts['link']); | |
| 970 | + } | |
| 585 | 971 | |
| 586 | - $shortcode[3] .= " apply=\"true\""; | |
| 587 | - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); | |
| 972 | + if (!empty($atts['img_link'])) { | |
| 973 | + $atts['img_link'] = $this->filter_content($atts['img_link']); | |
| 588 | 974 | } |
| 589 | 975 | } |
| 976 | + return $atts; | |
| 977 | + } | |
| 590 | 978 | |
| 979 | + // filter cs element pre prender | |
| 980 | + public function filter_cs_element_pre_render($data) { | |
| 981 | + if (!empty($data['_type']) && $data['_type'] == 'raw-content' && !empty($data['raw_content']) && !empty($data['_p'])) { | |
| 982 | + $data['raw_content'] = $this->filter_content($data['raw_content'], $data['_p']); | |
| 983 | + } | |
| 984 | + return $data; | |
| 985 | + } | |
| 986 | + | |
| 987 | + // filter themify builder module content | |
| 988 | + public function filter_themify_builder_module_content($content) { | |
| 989 | + if ($content) { | |
| 990 | + $content = $this->filter_content($content); | |
| 991 | + } | |
| 591 | 992 | return $content; |
| 592 | 993 | } |
| 593 | 994 | |
| 995 | + // filter vs basic grid items list | |
| 996 | + public function filter_vc_basic_grid_items_list($items) { | |
| 997 | + if ($items) { | |
| 998 | + $items = $this->filter_content($items); | |
| 999 | + } | |
| 1000 | + return $items; | |
| 1001 | + } | |
| 1002 | + | |
| 1003 | + // filter the content | |
| 1004 | + public function filter_the_content($content, $post_id = false) { | |
| 1005 | + $content = $this->filter_content($content, $post_id); | |
| 1006 | + return $content; | |
| 1007 | + } | |
| 1008 | + | |
| 1009 | + // filter content custom | |
| 1010 | + public function filter_content_custom($content) { | |
| 1011 | + $content = $this->filter_content($content); | |
| 1012 | + return $content; | |
| 1013 | + } | |
| 1014 | + | |
| 1015 | + // filter content loop | |
| 1016 | + public function filter_content_loop($content) { | |
| 1017 | + $content = $this->filter_content($content, false, false); | |
| 1018 | + return $content; | |
| 1019 | + } | |
| 1020 | + | |
| 594 | 1021 | /** |
| 595 | - * Search and update shortcodes for this extension inside content | |
| 596 | - * Auto set of dataset id | |
| 597 | - * | |
| 598 | - * @param string $content - Content | |
| 599 | - * | |
| 600 | - * @return string - Content with updated shortcodes | |
| 1022 | + * Memberpress Mail attachments filter | |
| 1023 | + * https://memberpress.com/ | |
| 601 | 1024 | */ |
| 602 | - public function filter_content($content) { | |
| 603 | - global $post; | |
| 1025 | + public function filter_mepr_email_send_attachments($attachments, $mail, $body, $values) { | |
| 1026 | + $message = $body ? $body : $mail->body(); | |
| 1027 | + if ($message && false !== strpos($message, '[')) { | |
| 1028 | + $message = $mail->replace_variables($message, $values); | |
| 1029 | + $shortcode_tags = [ | |
| 1030 | + 'e2pdf-attachment', | |
| 1031 | + 'e2pdf-save', | |
| 1032 | + ]; | |
| 1033 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $message, $matches); | |
| 1034 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1035 | + if (!empty($tagnames)) { | |
| 1036 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $message, $shortcodes); | |
| 1037 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1038 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1039 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1040 | + $file = false; | |
| 1041 | + if (isset($atts['id']) && isset($atts['dataset'])) { | |
| 1042 | + if (!isset($atts['apply'])) { | |
| 1043 | + $shortcode[3] .= ' apply="true"'; | |
| 1044 | + } | |
| 1045 | + if (!isset($atts['filter'])) { | |
| 1046 | + $shortcode[3] .= ' filter="true"'; | |
| 1047 | + } | |
| 1048 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { | |
| 1049 | + $file = do_shortcode_tag($shortcode); | |
| 1050 | + if ($file) { | |
| 1051 | + $tmp = false; | |
| 1052 | + if (substr($file, 0, 4) === 'tmp:') { | |
| 1053 | + $file = substr($file, 4); | |
| 1054 | + $tmp = true; | |
| 1055 | + } | |
| 1056 | + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { | |
| 1057 | + if ($tmp) { | |
| 1058 | + $this->helper->add('wordpress_attachments_mepr', $file); | |
| 1059 | + } | |
| 1060 | + } else { | |
| 1061 | + $this->helper->add('wordpress_attachments_mepr', $file); | |
| 1062 | + } | |
| 1063 | + $attachments[] = $file; | |
| 1064 | + } | |
| 1065 | + } | |
| 1066 | + } | |
| 1067 | + } | |
| 1068 | + } | |
| 1069 | + } | |
| 1070 | + return $attachments; | |
| 1071 | + } | |
| 604 | 1072 | |
| 605 | - if (false === strpos($content, '[')) { | |
| 1073 | + // mepr the content filter | |
| 1074 | + public function filter_mepr_the_content($content) { | |
| 1075 | + if ( | |
| 1076 | + class_exists('MeprUtils') && method_exists('MeprUtils', 'get_current_post') && | |
| 1077 | + class_exists('MeprOptions') && method_exists('MeprOptions', 'fetch') | |
| 1078 | + ) { | |
| 1079 | + $current_post = MeprUtils::get_current_post(); | |
| 1080 | + if ($current_post !== false) { | |
| 1081 | + $mepr_options = MeprOptions::fetch(); | |
| 1082 | + if ($current_post->ID == $mepr_options->thankyou_page_id) { | |
| 1083 | + remove_shortcode('e2pdf-download'); | |
| 1084 | + remove_shortcode('e2pdf-view'); | |
| 1085 | + remove_shortcode('e2pdf-save'); | |
| 1086 | + remove_shortcode('e2pdf-zapier'); | |
| 1087 | + remove_shortcode('e2pdf-adobesign'); | |
| 1088 | + } | |
| 1089 | + } | |
| 1090 | + } | |
| 1091 | + return $content; | |
| 1092 | + } | |
| 1093 | + | |
| 1094 | + // mepr custom thank you message filter | |
| 1095 | + public function filter_mepr_custom_thankyou_message($content) { | |
| 1096 | + add_shortcode('e2pdf-download', [new Model_E2pdf_Shortcode(), 'e2pdf_download']); | |
| 1097 | + add_shortcode('e2pdf-view', [new Model_E2pdf_Shortcode(), 'e2pdf_view']); | |
| 1098 | + add_shortcode('e2pdf-save', [new Model_E2pdf_Shortcode(), 'e2pdf_save']); | |
| 1099 | + add_shortcode('e2pdf-zapier', [new Model_E2pdf_Shortcode(), 'e2pdf_zapier']); | |
| 1100 | + add_shortcode('e2pdf-adobesign', [new Model_E2pdf_Shortcode(), 'e2pdf_adobesign']); | |
| 1101 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 1102 | + if (isset($_REQUEST['trans_num']) && class_exists('MeprTransaction') && method_exists('MeprTransaction', 'get_one_by_trans_num')) { | |
| 1103 | + $txn = new MeprTransaction(); | |
| 1104 | + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 1105 | + $data = MeprTransaction::get_one_by_trans_num($_REQUEST['trans_num']); | |
| 1106 | + if (method_exists($txn, 'load_data')) { | |
| 1107 | + $txn->load_data($data); | |
| 1108 | + if (false !== strpos($content, '[')) { | |
| 1109 | + $shortcode_tags = [ | |
| 1110 | + 'e2pdf-download', | |
| 1111 | + 'e2pdf-view', | |
| 1112 | + 'e2pdf-save', | |
| 1113 | + 'e2pdf-zapier', | |
| 1114 | + 'e2pdf-adobesign', | |
| 1115 | + ]; | |
| 1116 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); | |
| 1117 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1118 | + if (!empty($tagnames)) { | |
| 1119 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 1120 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1121 | + wp_reset_postdata(); | |
| 1122 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1123 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1124 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf | |
| 1125 | + } elseif (isset($atts['id'])) { | |
| 1126 | + $user_id = !empty($txn->user_id) ? $txn->user_id : get_current_user_id(); | |
| 1127 | + $template = new Model_E2pdf_Template(); | |
| 1128 | + $template->load($atts['id']); | |
| 1129 | + if ($template->get('extension') === 'wordpress' && $template->get('item') == '-3') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1130 | + if (!isset($atts['dataset'])) { | |
| 1131 | + $atts['dataset'] = $user_id; | |
| 1132 | + $shortcode[3] .= ' dataset="' . $user_id . '"'; | |
| 1133 | + } | |
| 1134 | + } else { | |
| 1135 | + if (!isset($atts['user_id'])) { | |
| 1136 | + $atts['user_id'] = $user_id; | |
| 1137 | + $shortcode[3] .= ' user_id="' . $user_id . '"'; | |
| 1138 | + } | |
| 1139 | + } | |
| 1140 | + } | |
| 1141 | + if (!isset($atts['apply'])) { | |
| 1142 | + $shortcode[3] .= ' apply="true"'; | |
| 1143 | + } | |
| 1144 | + if (!isset($atts['filter'])) { | |
| 1145 | + $shortcode[3] .= ' filter="true"'; | |
| 1146 | + } | |
| 1147 | + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); | |
| 1148 | + } | |
| 1149 | + } | |
| 1150 | + } | |
| 1151 | + } | |
| 1152 | + } | |
| 1153 | + return $content; | |
| 1154 | + } | |
| 1155 | + | |
| 1156 | + // user registration smart tag values filter | |
| 1157 | + public function filter_user_registration_smart_tag_values($values) { | |
| 1158 | + foreach ($values as $key => $value) { | |
| 1159 | + if (is_string($value) && false !== strpos($value, '[e2pdf-')) { | |
| 1160 | + $values[$key] = str_replace('[e2pdf-', '[e2pdf-', $value); | |
| 1161 | + } | |
| 1162 | + } | |
| 1163 | + return $values; | |
| 1164 | + } | |
| 1165 | + | |
| 1166 | + /** | |
| 1167 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 1168 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 1169 | + */ | |
| 1170 | + public function filter_um_email_send_message_content($content) { | |
| 1171 | + if (!is_string($content) || false === strpos($content, '[')) { | |
| 606 | 1172 | return $content; |
| 607 | 1173 | } |
| 608 | - | |
| 609 | - $shortcode_tags = array( | |
| 1174 | + $shortcode_tags = [ | |
| 610 | 1175 | 'e2pdf-download', |
| 611 | - 'e2pdf-view' | |
| 612 | - ); | |
| 613 | - | |
| 1176 | + 'e2pdf-save', | |
| 1177 | + 'e2pdf-attachment', | |
| 1178 | + 'e2pdf-view', | |
| 1179 | + 'e2pdf-adobesign', | |
| 1180 | + 'e2pdf-zapier', | |
| 1181 | + ]; | |
| 614 | 1182 | preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); |
| 615 | 1183 | $tagnames = array_intersect($shortcode_tags, $matches[1]); |
| 616 | - | |
| 617 | 1184 | if (!empty($tagnames)) { |
| 618 | - $pattern = get_shortcode_regex($tagnames); | |
| 619 | - | |
| 620 | - preg_match_all("/$pattern/", $content, $shortcodes); | |
| 621 | - | |
| 1185 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 622 | 1186 | foreach ($shortcodes[0] as $key => $shortcode_value) { |
| 1187 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1188 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1189 | + if (!isset($atts['apply'])) { | |
| 1190 | + $shortcode[3] .= ' apply="true"'; | |
| 1191 | + } | |
| 1192 | + if (!isset($atts['filter'])) { | |
| 1193 | + $shortcode[3] .= ' filter="true"'; | |
| 1194 | + } | |
| 1195 | + if (isset($atts['id'])) { | |
| 1196 | + $template = new Model_E2pdf_Template(); | |
| 1197 | + $template->load($atts['id']); | |
| 1198 | + if ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1199 | + if (!isset($atts['dataset'])) { | |
| 1200 | + if ($template->get('item') == '-3' && function_exists('um_user')) { | |
| 1201 | + $dataset = um_user('ID'); | |
| 1202 | + $atts['dataset'] = $dataset; | |
| 1203 | + $shortcode[3] .= ' dataset="' . $dataset . '"'; | |
| 1204 | + } | |
| 1205 | + } | |
| 1206 | + } | |
| 1207 | + } | |
| 1208 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { | |
| 1209 | + $file = do_shortcode_tag($shortcode); | |
| 1210 | + if ($file) { | |
| 1211 | + $tmp = false; | |
| 1212 | + if (substr($file, 0, 4) === 'tmp:') { | |
| 1213 | + $file = substr($file, 4); | |
| 1214 | + $tmp = true; | |
| 1215 | + } | |
| 1216 | + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { | |
| 1217 | + if ($tmp) { | |
| 1218 | + $this->helper->add('wordpress_attachments_um_del', $file); | |
| 1219 | + } | |
| 1220 | + } else { | |
| 1221 | + $this->helper->add('wordpress_attachments_um_del', $file); | |
| 1222 | + } | |
| 1223 | + $this->helper->add('wordpress_attachments_um', $file); | |
| 1224 | + } | |
| 1225 | + $content = str_replace($shortcode_value, '', $content); | |
| 1226 | + } else { | |
| 1227 | + $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); | |
| 1228 | + } | |
| 1229 | + } | |
| 1230 | + } | |
| 1231 | + return $content; | |
| 1232 | + } | |
| 623 | 1233 | |
| 624 | - wp_reset_postdata(); | |
| 1234 | + /** | |
| 1235 | + * Ultimate Member – User Profile, Registration, Login, Member Directory, Content Restriction & Membership Plugin | |
| 1236 | + * https://wordpress.org/plugins/ultimate-member/ | |
| 1237 | + */ | |
| 1238 | + public function filter_wp_mail_um($args) { | |
| 1239 | + $files = $this->helper->get('wordpress_attachments_um'); | |
| 1240 | + if (is_array($files) && !empty($files)) { | |
| 1241 | + if (empty($args['attachments'])) { | |
| 1242 | + $args['attachments'] = []; | |
| 1243 | + } elseif (!is_array($args['attachments'])) { | |
| 1244 | + $args['attachments'] = [$args['attachments']]; | |
| 1245 | + } | |
| 1246 | + foreach ($files as $key => $file) { | |
| 1247 | + $args['attachments'][] = $file; | |
| 1248 | + } | |
| 1249 | + } | |
| 1250 | + return $args; | |
| 1251 | + } | |
| 625 | 1252 | |
| 626 | - $shortcode = array(); | |
| 627 | - $shortcode[1] = $shortcodes[1][$key]; | |
| 628 | - $shortcode[2] = $shortcodes[2][$key]; | |
| 629 | - $shortcode[3] = $shortcodes[3][$key]; | |
| 630 | - $shortcode[4] = $shortcodes[4][$key]; | |
| 631 | - $shortcode[5] = $shortcodes[5][$key]; | |
| 632 | - $shortcode[6] = $shortcodes[6][$key]; | |
| 1253 | + // wp mail filter | |
| 1254 | + public function filter_wp_mail($args) { | |
| 1255 | + if (isset($args['message'])) { | |
| 1256 | + if (false !== strpos($args['message'], '[')) { | |
| 1257 | + $shortcode_tags = [ | |
| 1258 | + 'e2pdf-download', | |
| 1259 | + 'e2pdf-save', | |
| 1260 | + 'e2pdf-attachment', | |
| 1261 | + 'e2pdf-adobesign', | |
| 1262 | + 'e2pdf-zapier', | |
| 1263 | + ]; | |
| 1264 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $args['message'], $matches); | |
| 1265 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1266 | + if (!empty($tagnames)) { | |
| 1267 | + $args['attachments'] = $this->helper->load('convert')->is_string_array($args['attachments']); | |
| 1268 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $args['message'], $shortcodes); | |
| 1269 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1270 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1271 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1272 | + if (!isset($atts['apply'])) { | |
| 1273 | + $shortcode[3] .= ' apply="true"'; | |
| 1274 | + } | |
| 1275 | + if (!isset($atts['filter'])) { | |
| 1276 | + $shortcode[3] .= ' filter="true"'; | |
| 1277 | + } | |
| 1278 | + $file = false; | |
| 1279 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { | |
| 1280 | + $file = do_shortcode_tag($shortcode); | |
| 1281 | + if ($file) { | |
| 1282 | + $tmp = false; | |
| 1283 | + if (substr($file, 0, 4) === 'tmp:') { | |
| 1284 | + $file = substr($file, 4); | |
| 1285 | + $tmp = true; | |
| 1286 | + } | |
| 1287 | + if ($shortcode[2] === 'e2pdf-save' || isset($atts['pdf'])) { | |
| 1288 | + if ($tmp) { | |
| 1289 | + $this->helper->add('wordpress_attachments', $file); | |
| 1290 | + } | |
| 1291 | + } else { | |
| 1292 | + $this->helper->add('wordpress_attachments', $file); | |
| 1293 | + } | |
| 1294 | + $args['attachments'][] = $file; | |
| 1295 | + } | |
| 1296 | + $args['message'] = str_replace($shortcode_value, '', $args['message']); | |
| 1297 | + } else { | |
| 1298 | + $args['message'] = str_replace($shortcode_value, do_shortcode_tag($shortcode), $args['message']); | |
| 1299 | + } | |
| 1300 | + } | |
| 1301 | + } | |
| 1302 | + } | |
| 1303 | + } | |
| 1304 | + return [ | |
| 1305 | + 'to' => $args['to'], | |
| 1306 | + 'subject' => $args['subject'], | |
| 1307 | + 'message' => $args['message'], | |
| 1308 | + 'headers' => $args['headers'], | |
| 1309 | + 'attachments' => $args['attachments'], | |
| 1310 | + ]; | |
| 1311 | + } | |
| 633 | 1312 | |
| 634 | - $atts = shortcode_parse_atts($shortcode[3]); | |
| 1313 | + // Thrive Theme Builder dynamic shortcode support | |
| 1314 | + public function filter_thrive_theme_template_content($html) { | |
| 1315 | + add_filter('e2pdf_model_shortcode_e2pdf_download_atts', [$this, 'filter_global_post_id']); | |
| 1316 | + add_filter('e2pdf_model_shortcode_e2pdf_view_atts', [$this, 'filter_global_post_id']); | |
| 1317 | + add_filter('e2pdf_model_shortcode_e2pdf_save_atts', [$this, 'filter_global_post_id']); | |
| 1318 | + add_filter('e2pdf_model_shortcode_e2pdf_zapier_atts', [$this, 'filter_global_post_id']); | |
| 1319 | + return $html; | |
| 1320 | + } | |
| 635 | 1321 | |
| 636 | - if (!array_key_exists('dataset', $atts) && array_key_exists('id', $atts)) { | |
| 637 | - $template = new Model_E2pdf_Template(); | |
| 638 | - $template->load($atts['id']); | |
| 639 | - if ($template->get('extension') === 'wordpress') { | |
| 640 | - if (isset($post->ID)) { | |
| 641 | - $dataset_id = $post->ID; | |
| 642 | - $atts['dataset'] = $dataset_id; | |
| 643 | - $shortcode[3] .= " dataset=\"{$dataset_id}\""; | |
| 1322 | + // dynamic post id support filter | |
| 1323 | + public function filter_global_post_id($atts) { | |
| 1324 | + if (!isset($atts['dataset']) && isset($atts['id'])) { | |
| 1325 | + $template_id = isset($atts['id']) ? (int) $atts['id'] : 0; | |
| 1326 | + $template = new Model_E2pdf_Template(); | |
| 1327 | + if ($template->load($template_id, false)) { | |
| 1328 | + if ($template->get('extension') === 'wordpress') { // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1329 | + global $post; | |
| 1330 | + if (isset($post->ID)) { | |
| 1331 | + $atts['dataset'] = (string) $post->ID; | |
| 1332 | + if (!isset($atts['apply'])) { | |
| 1333 | + $atts['apply'] = 'true'; | |
| 644 | 1334 | } |
| 1335 | + if (!isset($atts['filter'])) { | |
| 1336 | + $atts['filter'] = 'true'; | |
| 1337 | + } | |
| 645 | 1338 | } |
| 646 | 1339 | } |
| 647 | - $content = str_replace($shortcode_value, do_shortcode_tag($shortcode), $content); | |
| 648 | 1340 | } |
| 649 | 1341 | } |
| 1342 | + return $atts; | |
| 1343 | + } | |
| 650 | 1344 | |
| 1345 | + // et pb module content filter | |
| 1346 | + public function filter_et_pb_module_content($content, $props, $attrs, $render_slug, $_address, $global_content) { | |
| 1347 | + if (($render_slug == 'et_pb_code' || $render_slug == 'et_pb_text') && | |
| 1348 | + false !== strpos($content, '[') && | |
| 1349 | + function_exists('et_core_is_builder_used_on_current_request') && | |
| 1350 | + !et_core_is_builder_used_on_current_request() | |
| 1351 | + ) { | |
| 1352 | + global $post; | |
| 1353 | + $shortcode_tags = [ | |
| 1354 | + 'e2pdf-download', | |
| 1355 | + 'e2pdf-save', | |
| 1356 | + 'e2pdf-view', | |
| 1357 | + 'e2pdf-adobesign', | |
| 1358 | + 'e2pdf-zapier', | |
| 1359 | + ]; | |
| 1360 | + preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches); | |
| 1361 | + $tagnames = array_intersect($shortcode_tags, $matches[1]); | |
| 1362 | + if (!empty($tagnames)) { | |
| 1363 | + preg_match_all('/' . $this->helper->load('shortcode')->get_shortcode_regex($tagnames) . '/', $content, $shortcodes); | |
| 1364 | + foreach ($shortcodes[0] as $key => $shortcode_value) { | |
| 1365 | + wp_reset_postdata(); | |
| 1366 | + $shortcode = $this->helper->load('shortcode')->get_shortcode($shortcodes, $key); | |
| 1367 | + $atts = shortcode_parse_atts($shortcode[3]); | |
| 1368 | + if ($this->helper->load('shortcode')->is_attachment($shortcode, $atts)) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedIf | |
| 1369 | + } else { | |
| 1370 | + if (!isset($atts['dataset']) && isset($atts['id']) && (isset($post->ID))) { | |
| 1371 | + $dataset = $post->ID; | |
| 1372 | + $atts['dataset'] = $dataset; | |
| 1373 | + $shortcode[3] .= ' dataset="' . $dataset . '"'; | |
| 1374 | + } | |
| 1375 | + } | |
| 1376 | + if (!isset($atts['apply'])) { | |
| 1377 | + $shortcode[3] .= ' apply="true"'; | |
| 1378 | + } | |
| 1379 | + | |
| 1380 | + if (!isset($atts['filter'])) { | |
| 1381 | + $shortcode[3] .= ' filter="true"'; | |
| 1382 | + } | |
| 1383 | + $new_shortcode = '[' . $shortcode[2] . $shortcode[3] . ']'; | |
| 1384 | + $content = str_replace($shortcode_value, $new_shortcode, $content); | |
| 1385 | + } | |
| 1386 | + } | |
| 1387 | + } | |
| 651 | 1388 | return $content; |
| 652 | 1389 | } |
| 653 | 1390 | |
| 1391 | + // verify | |
| 654 | 1392 | public function verify() { |
| 655 | - $item_id = $this->get('item'); | |
| 656 | - $dataset_id = $this->get('dataset'); | |
| 657 | - | |
| 658 | - if ($item_id && $dataset_id && $item_id == get_post_type($dataset_id)) { | |
| 1393 | + if ($this->get('item') && $this->get('cached_post') && (($this->get('item') == get_post_type($this->get('cached_post'))) || ($this->get('item') == '-3' && $this->get('cached_post')))) { | |
| 659 | 1394 | return true; |
| 660 | 1395 | } |
| 661 | - | |
| 662 | 1396 | return false; |
| 663 | 1397 | } |
| 664 | 1398 | |
| 1399 | + // visual mapper | |
| 665 | 1400 | public function visual_mapper() { |
| 666 | 1401 | |
| 667 | - $vc = "<h3>Wordpress</h3>"; | |
| 1402 | + $vc = ''; | |
| 1403 | + | |
| 1404 | + if ($this->get('item') != '-3') { | |
| 1405 | + $vc .= '<h3 class="e2pdf-plr5">Common</h3>'; | |
| 1406 | + $vc .= '<div class="e2pdf-grid">'; | |
| 1407 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-wp key="id"') . '</div>'; | |
| 1408 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author', 'e2pdf-wp key="post_author"') . '</div>'; | |
| 1409 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Author ID', 'e2pdf-wp key="post_author_id"') . '</div>'; | |
| 1410 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date', 'e2pdf-wp key="post_date"') . '</div>'; | |
| 1411 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Date (GMT)', 'e2pdf-wp key="post_date_gmt"') . '</div>'; | |
| 1412 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Content', 'e2pdf-wp key="post_content"') . '</div>'; | |
| 1413 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Title', 'e2pdf-wp key="post_title"') . '</div>'; | |
| 1414 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Excerpt', 'e2pdf-wp key="post_excerpt"') . '</div>'; | |
| 1415 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Status', 'e2pdf-wp key="post_status"') . '</div>'; | |
| 1416 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comment Status', 'e2pdf-wp key="comment_status"') . '</div>'; | |
| 1417 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping Status', 'e2pdf-wp key="ping_status"') . '</div>'; | |
| 1418 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Password', 'e2pdf-wp key="post_password"') . '</div>'; | |
| 1419 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Name', 'e2pdf-wp key="post_name"') . '</div>'; | |
| 1420 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('To Ping', 'e2pdf-wp key="to_ping"') . '</div>'; | |
| 1421 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Ping', 'e2pdf-wp key="pinged"') . '</div>'; | |
| 1422 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date', 'e2pdf-wp key="post_modified"') . '</div>'; | |
| 1423 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Modified Date (GMT)', 'e2pdf-wp key="post_modified_gmt"') . '</div>'; | |
| 1424 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filtered Content', 'e2pdf-wp key="post_content_filtered"') . '</div>'; | |
| 1425 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Parent ID', 'e2pdf-wp key="post_parent"') . '</div>'; | |
| 1426 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('GUID', 'e2pdf-wp key="guid"') . '</div>'; | |
| 1427 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Menu Order', 'e2pdf-wp key="menu_order"') . '</div>'; | |
| 1428 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Type', 'e2pdf-wp key="post_type"') . '</div>'; | |
| 1429 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Mime Type', 'e2pdf-wp key="post_mime_type"') . '</div>'; | |
| 1430 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Comments Count', 'e2pdf-wp key="comment_count"') . '</div>'; | |
| 1431 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Filter', 'e2pdf-wp key="filter"') . '</div>'; | |
| 1432 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail', 'e2pdf-wp key="get_the_post_thumbnail"') . '</div>'; | |
| 1433 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Thumbnail URL', 'e2pdf-wp key="get_the_post_thumbnail_url"') . '</div>'; | |
| 1434 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Permalink', 'e2pdf-wp key="get_permalink"') . '</div>'; | |
| 1435 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Post Permalink', 'e2pdf-wp key="get_post_permalink"') . '</div>'; | |
| 1436 | + $vc .= '</div>'; | |
| 1437 | + | |
| 1438 | + $meta_keys = $this->get_post_meta_keys(); | |
| 1439 | + if (!empty($meta_keys)) { | |
| 1440 | + $vc .= '<h3 class="e2pdf-plr5">Meta Keys</h3>'; | |
| 1441 | + $vc .= "<div class='e2pdf-grid'>"; | |
| 1442 | + foreach ($meta_keys as $meta_key) { | |
| 1443 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" meta="true"') . '</div>'; | |
| 1444 | + } | |
| 1445 | + $vc .= '</div>'; | |
| 1446 | + } | |
| 1447 | + | |
| 1448 | + $meta_keys = $this->get_post_taxonomy_keys(); | |
| 1449 | + if (!empty($meta_keys)) { | |
| 1450 | + $vc .= '<h3 class="e2pdf-plr5">Taxonomy</h3>'; | |
| 1451 | + $vc .= "<div class='e2pdf-grid'>"; | |
| 1452 | + foreach ($meta_keys as $meta_key) { | |
| 1453 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-wp key="' . $meta_key . '" terms="true" names="true"') . '</div>'; | |
| 1454 | + } | |
| 1455 | + $vc .= '</div>'; | |
| 1456 | + } | |
| 1457 | + } | |
| 1458 | + | |
| 1459 | + $vc .= '<h3 class="e2pdf-plr5">User</h3>'; | |
| 668 | 1460 | $vc .= "<div class='e2pdf-grid'>"; |
| 669 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("ID", "e2pdf"), 'id')}</div>"; | |
| 670 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Author", "e2pdf"), 'post_author')}</div>"; | |
| 671 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Date", "e2pdf"), 'post_date')}</div>"; | |
| 672 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Date (GMT)", "e2pdf"), 'post_date_gmt')}</div>"; | |
| 673 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Content", "e2pdf"), 'post_content')}</div>"; | |
| 674 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Title", "e2pdf"), 'post_title')}</div>"; | |
| 675 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Excerpt", "e2pdf"), 'post_excerpt')}</div>"; | |
| 676 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Status", "e2pdf"), 'post_status')}</div>"; | |
| 677 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comment Status", "e2pdf"), 'comment_status')}</div>"; | |
| 678 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping Status", "e2pdf"), 'ping_status')}</div>"; | |
| 679 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Post Password", "e2pdf"), 'post_password')}</div>"; | |
| 680 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Post Name", "e2pdf"), 'post_name')}</div>"; | |
| 681 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("To Ping", "e2pdf"), 'to_ping')}</div>"; | |
| 682 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Ping", "e2pdf"), 'pinged')}</div>"; | |
| 683 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Modified Date", "e2pdf"), 'post_modified')}</div>"; | |
| 684 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Modified Date (GMT)", "e2pdf"), 'post_modified_gmt')}</div>"; | |
| 685 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Filtered Content", "e2pdf"), 'post_content_filtered')}</div>"; | |
| 686 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Parent ID", "e2pdf"), 'post_parent')}</div>"; | |
| 687 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("GUID", "e2pdf"), 'guid')}</div>"; | |
| 688 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Menu Order", "e2pdf"), 'menu_order')}</div>"; | |
| 689 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Type", "e2pdf"), 'post_type')}</div>"; | |
| 690 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Mime Type", "e2pdf"), 'post_mime_type')}</div>"; | |
| 691 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pr10'>{$this->get_vm_element(__("Comments Count", "e2pdf"), 'comment_count')}</div>"; | |
| 692 | - $vc .= "<div class='e2pdf-ib e2pdf-w50 e2pdf-pl10'>{$this->get_vm_element(__("Filter", "e2pdf"), 'filter')}</div>"; | |
| 693 | - $vc .= "</div>"; | |
| 1461 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('ID', 'e2pdf-user key="ID"') . '</div>'; | |
| 1462 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Description', 'e2pdf-user key="user_description"') . '</div>'; | |
| 1463 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('First Name', 'e2pdf-user key="user_firstname"') . '</div>'; | |
| 1464 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Last Name', 'e2pdf-user key="user_lastname"') . '</div>'; | |
| 1465 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Login', 'e2pdf-user key="user_login"') . '</div>'; | |
| 1466 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Nicename', 'e2pdf-user key="user_nicename"') . '</div>'; | |
| 1467 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('E-mail', 'e2pdf-user key="user_email"') . '</div>'; | |
| 1468 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Url', 'e2pdf-user key="user_url"') . '</div>'; | |
| 1469 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Registered', 'e2pdf-user key="user_registered"') . '</div>'; | |
| 1470 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Status', 'e2pdf-user key="user_status"') . '</div>'; | |
| 1471 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('User Level', 'e2pdf-user key="user_level"') . '</div>'; | |
| 1472 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Display Name', 'e2pdf-user key="display_name"') . '</div>'; | |
| 1473 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Spam', 'e2pdf-user key="spam"') . '</div>'; | |
| 1474 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Deleted', 'e2pdf-user key="deleted"') . '</div>'; | |
| 1475 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Locale', 'e2pdf-user key="locale"') . '</div>'; | |
| 1476 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Rich Editing', 'e2pdf-user key="rich_editing"') . '</div>'; | |
| 1477 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Syntax Highlighting', 'e2pdf-user key="syntax_highlighting"') . '</div>'; | |
| 1478 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Use SSL', 'e2pdf-user key="use_ssl"') . '</div>'; | |
| 1479 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Roles', 'e2pdf-user key="roles"') . '</div>'; | |
| 1480 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar', 'e2pdf-user key="get_avatar"') . '</div>'; | |
| 1481 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element('Avatar Url', 'e2pdf-user key="get_avatar_url"') . '</div>'; | |
| 1482 | + $vc .= '</div>'; | |
| 1483 | + | |
| 1484 | + $meta_keys = $this->get_user_meta_keys(); | |
| 1485 | + if (!empty($meta_keys)) { | |
| 1486 | + $vc .= '<h3 class="e2pdf-plr5">User Meta Keys</h3>'; | |
| 1487 | + $vc .= "<div class='e2pdf-grid'>"; | |
| 1488 | + foreach ($meta_keys as $meta_key) { | |
| 1489 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($meta_key, 'e2pdf-user key="' . $meta_key . '" meta="true"') . '</div>'; | |
| 1490 | + } | |
| 1491 | + $vc .= '</div>'; | |
| 1492 | + } | |
| 1493 | + | |
| 1494 | + if (class_exists('ACF') && function_exists('acf_get_field_groups')) { | |
| 1495 | + $user_groups = acf_get_field_groups( | |
| 1496 | + [ | |
| 1497 | + 'user_id' => 'new', | |
| 1498 | + 'user_form' => 'all', | |
| 1499 | + ] | |
| 1500 | + ); | |
| 1501 | + if (!empty($user_groups)) { | |
| 1502 | + $user_groups = array_column($user_groups, 'key'); | |
| 1503 | + } | |
| 1504 | + if ($this->get('item') == '-3') { | |
| 1505 | + $groups = acf_get_field_groups( | |
| 1506 | + [ | |
| 1507 | + 'user_id' => 'new', | |
| 1508 | + 'user_form' => 'all', | |
| 1509 | + ] | |
| 1510 | + ); | |
| 1511 | + } else { | |
| 1512 | + $groups = acf_get_field_groups(['post_type' => $this->get('item')]); | |
| 1513 | + } | |
| 1514 | + if (!empty($groups)) { | |
| 1515 | + $vc .= "<h3 class='e2pdf-plr5'>ACF</h3>"; | |
| 1516 | + foreach ($groups as $group_key => $group) { | |
| 1517 | + $post_id = ''; | |
| 1518 | + if (!empty($user_groups)) { | |
| 1519 | + if (in_array($group['key'], $user_groups, false)) { | |
| 1520 | + if ($this->get('item') == '-3') { | |
| 1521 | + $post_id = ' post_id="user_[e2pdf-dataset]"'; | |
| 1522 | + } else { | |
| 1523 | + $post_id = ' post_id="user_[e2pdf-userid]"'; | |
| 1524 | + } | |
| 1525 | + } | |
| 1526 | + } | |
| 1527 | + $vc .= '<h3 class="e2pdf-plr5">' . $group['title'] . '</h3>'; | |
| 1528 | + $vc .= "<div class='e2pdf-grid'>"; | |
| 1529 | + foreach (acf_get_fields($group['key']) as $field_key => $field) { | |
| 1530 | + $vc = $this->get_acf_field($vc, $field, $post_id); | |
| 1531 | + } | |
| 1532 | + $vc .= '</div>'; | |
| 1533 | + } | |
| 1534 | + } | |
| 1535 | + } | |
| 694 | 1536 | return $vc; |
| 695 | 1537 | } |
| 696 | 1538 | |
| 697 | - private function get_vm_element($name, $id) { | |
| 698 | - $element = "<div>"; | |
| 699 | - $element .= "<label>{$name}:</label>"; | |
| 700 | - $element .= "<input type='text' name='[{$id}]' value='[{$id}]'>"; | |
| 701 | - $element .= "</div>"; | |
| 1539 | + // get acf field | |
| 1540 | + public function get_acf_field($vc, $field, $post_id) { | |
| 1541 | + if ($field['type'] == 'repeater' && !empty($field['sub_fields'])) { | |
| 1542 | + $sub_fields = []; | |
| 1543 | + foreach ($field['sub_fields'] as $sub_field_key => $sub_field) { | |
| 1544 | + $sub_fields[] = '[acf field="' . $sub_field['name'] . '"' . $post_id . ']'; | |
| 1545 | + $sub_field['label'] = $field['label'] . ' ' . $sub_field['label']; | |
| 1546 | + $sub_field['name'] = $field['name'] . '_0_' . $sub_field['name']; | |
| 1547 | + $vc = $this->get_acf_field($vc, $sub_field, $post_id); | |
| 1548 | + } | |
| 1549 | + if (!empty($sub_fields)) { | |
| 1550 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'] . ' Iteration', 'e2pdf-acf-repeater field="' . $field['name'] . '"' . $post_id . ']' . implode(' ', $sub_fields) . "\r\n" . '[/e2pdf-acf-repeater') . '</div>'; | |
| 1551 | + } | |
| 1552 | + } elseif ($field['type'] == 'group' && !empty($field['sub_fields'])) { | |
| 1553 | + $sub_fields = []; | |
| 1554 | + foreach ($field['sub_fields'] as $sub_field_key => $sub_field) { | |
| 1555 | + $sub_field['label'] = $field['label'] . ' ' . $sub_field['label']; | |
| 1556 | + $sub_field['name'] = $field['name'] . '_' . $sub_field['name']; | |
| 1557 | + $vc = $this->get_acf_field($vc, $sub_field, $post_id); | |
| 1558 | + } | |
| 1559 | + } else { | |
| 1560 | + if ($field['name']) { | |
| 1561 | + $vc .= '<div class="e2pdf-ib e2pdf-w50 e2pdf-vm-item">' . $this->get_vm_element($field['label'], 'acf field="' . $field['name'] . '"' . $post_id) . '</div>'; | |
| 1562 | + } | |
| 1563 | + } | |
| 1564 | + return $vc; | |
| 1565 | + } | |
| 1566 | + | |
| 1567 | + // get post meta keys | |
| 1568 | + public function get_post_meta_keys() { | |
| 1569 | + global $wpdb; | |
| 1570 | + $meta_keys = []; | |
| 1571 | + if ($this->get('item')) { | |
| 1572 | + $condition = [ | |
| 1573 | + 'p.post_type' => [ | |
| 1574 | + 'condition' => '=', | |
| 1575 | + 'value' => $this->get('item'), | |
| 1576 | + 'type' => '%s', | |
| 1577 | + ], | |
| 1578 | + ]; | |
| 1579 | + $order_condition = [ | |
| 1580 | + 'orderby' => 'meta_key', | |
| 1581 | + 'order' => 'desc', | |
| 1582 | + ]; | |
| 1583 | + $where = $this->helper->load('db')->prepare_where($condition); | |
| 1584 | + $orderby = $this->helper->load('db')->prepare_orderby($order_condition); | |
| 1585 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 1586 | + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->postmeta . '` `pm` LEFT JOIN ' . $wpdb->posts . ' `p` ON (`p`.`ID` = `pm`.`post_ID`) ' . $where['sql'] . $orderby . '', $where['filter'])); | |
| 1587 | + } | |
| 1588 | + return $meta_keys; | |
| 1589 | + } | |
| 1590 | + | |
| 1591 | + // get user meta keys | |
| 1592 | + public function get_user_meta_keys() { | |
| 1593 | + global $wpdb; | |
| 1594 | + $meta_keys = []; | |
| 1595 | + if ($this->get('item')) { | |
| 1596 | + $order_condition = [ | |
| 1597 | + 'orderby' => 'meta_key', | |
| 1598 | + 'order' => 'desc', | |
| 1599 | + ]; | |
| 1600 | + $orderby = $this->helper->load('db')->prepare_orderby($order_condition); | |
| 1601 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 1602 | + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `meta_key` FROM `' . $wpdb->usermeta . '` ' . $orderby . '')); | |
| 1603 | + } | |
| 1604 | + return $meta_keys; | |
| 1605 | + } | |
| 1606 | + | |
| 1607 | + // get post taxonomy keys | |
| 1608 | + public function get_post_taxonomy_keys() { | |
| 1609 | + global $wpdb; | |
| 1610 | + $meta_keys = []; | |
| 1611 | + if ($this->get('item')) { | |
| 1612 | + $order_condition = [ | |
| 1613 | + 'orderby' => 'taxonomy', | |
| 1614 | + 'order' => 'desc', | |
| 1615 | + ]; | |
| 1616 | + $orderby = $this->helper->load('db')->prepare_orderby($order_condition); | |
| 1617 | + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare | |
| 1618 | + $meta_keys = $wpdb->get_col($wpdb->prepare('SELECT DISTINCT `taxonomy` FROM `' . $wpdb->term_taxonomy . '` `t` ' . $orderby . '')); | |
| 1619 | + } | |
| 1620 | + return $meta_keys; | |
| 1621 | + } | |
| 1622 | + | |
| 1623 | + // get wm element | |
| 1624 | + public function get_vm_element($name, $id) { | |
| 1625 | + $element = '<div>'; | |
| 1626 | + $element .= '<label>' . $name . ':</label>'; | |
| 1627 | + $element .= '<input type="text" name=\'[' . $id . ']\' value=\'[' . $id . ']\' class="e2pdf-w100">'; | |
| 1628 | + $element .= '</div>'; | |
| 702 | 1629 | return $element; |
| 703 | 1630 | } |
| 704 | 1631 | |
| 705 | - public function load_shortcodes() { | |
| 706 | - add_shortcode('e2pdf-exclude', array($this, 'shortcode_e2pdf_exclude')); | |
| 1632 | + // page edit hook | |
| 1633 | + public function hook_wordpress_page_edit() { | |
| 1634 | + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1635 | + $items = $this->helper->load('hooks')->get_items('wordpress', 'hook_wordpress_page_edit'); | |
| 1636 | + if (!empty($items)) { | |
| 1637 | + add_meta_box( | |
| 1638 | + 'e2pdf', | |
| 1639 | + apply_filters('e2pdf_hook_section_title', __('E2Pdf Actions', 'e2pdf'), 'hook_wordpress_page_edit'), | |
| 1640 | + [$this, 'hook_wordpress_page_edit_callback'], | |
| 1641 | + $items, | |
| 1642 | + 'side', | |
| 1643 | + 'default' | |
| 1644 | + ); | |
| 1645 | + } | |
| 707 | 1646 | } |
| 708 | 1647 | |
| 709 | - function shortcode_e2pdf_exclude($atts = array(), $content = null) { | |
| 710 | - if (is_array($atts) && array_key_exists('apply', $atts)) { | |
| 711 | - return ''; | |
| 1648 | + // page edit callback hook | |
| 1649 | + public function hook_wordpress_page_edit_callback($post) { | |
| 1650 | + if (!empty($post->post_type)) { | |
| 1651 | + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1652 | + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_page_edit', $post->post_type); | |
| 1653 | + if (!empty($hooks)) { | |
| 1654 | + foreach ($hooks as $hook) { | |
| 1655 | + if ($this->helper->load('hooks')->process_hook( | |
| 1656 | + $hook, | |
| 1657 | + [ | |
| 1658 | + 'dataset' => $post->ID, | |
| 1659 | + ], | |
| 1660 | + 'hook_wordpress_page_edit' | |
| 1661 | + ) | |
| 1662 | + ) { | |
| 1663 | + $action = apply_filters( | |
| 1664 | + 'e2pdf_hook_action_button', | |
| 1665 | + [ | |
| 1666 | + 'html' => '<p><a class="e2pdf-download-hook" target="_blank" title="%2$s" href="%1$s"><span class="dashicons dashicons-pdf"></span> %2$s</a></p>', | |
| 1667 | + 'url' => $this->helper->get_url( | |
| 1668 | + [ | |
| 1669 | + 'page' => 'e2pdf', | |
| 1670 | + 'action' => 'export', | |
| 1671 | + 'id' => $hook, | |
| 1672 | + 'dataset' => $post->ID, | |
| 1673 | + ], 'admin.php?' | |
| 1674 | + ), | |
| 1675 | + 'title' => 'PDF #' . $hook, | |
| 1676 | + ], 'hook_wordpress_page_edit', $hook, $post->ID | |
| 1677 | + ); | |
| 1678 | + if (!empty($action)) { | |
| 1679 | + echo sprintf( | |
| 1680 | + $action['html'], $action['url'], $action['title'] | |
| 1681 | + ); | |
| 1682 | + } | |
| 1683 | + } | |
| 1684 | + } | |
| 1685 | + } | |
| 1686 | + } | |
| 1687 | + } | |
| 1688 | + | |
| 1689 | + // row actions hook | |
| 1690 | + public function hook_wordpress_row_actions($actions, $post) { | |
| 1691 | + if ($post && is_a($post, 'WP_User')) { | |
| 1692 | + if (!empty($post->ID)) { | |
| 1693 | + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1694 | + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', '-3'); | |
| 1695 | + foreach ($hooks as $hook) { | |
| 1696 | + if ($this->helper->load('hooks')->process_hook( | |
| 1697 | + $hook, | |
| 1698 | + [ | |
| 1699 | + 'dataset' => $post->ID, | |
| 1700 | + ], | |
| 1701 | + 'hook_wordpress_row_actions' | |
| 1702 | + ) | |
| 1703 | + ) { | |
| 1704 | + $action = apply_filters( | |
| 1705 | + 'e2pdf_hook_action_button', | |
| 1706 | + [ | |
| 1707 | + 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>', | |
| 1708 | + 'url' => $this->helper->get_url( | |
| 1709 | + [ | |
| 1710 | + 'page' => 'e2pdf', | |
| 1711 | + 'action' => 'export', | |
| 1712 | + 'id' => $hook, | |
| 1713 | + 'dataset' => $post->ID, | |
| 1714 | + ], 'admin.php?' | |
| 1715 | + ), | |
| 1716 | + 'title' => 'PDF #' . $hook, | |
| 1717 | + ], 'hook_wordpress_row_actions', $hook, $post->ID | |
| 1718 | + ); | |
| 1719 | + if (!empty($action)) { | |
| 1720 | + $actions['e2pdf_' . $hook] = sprintf( | |
| 1721 | + $action['html'], $action['url'], $action['title'] | |
| 1722 | + ); | |
| 1723 | + } | |
| 1724 | + } | |
| 1725 | + } | |
| 1726 | + } | |
| 712 | 1727 | } else { |
| 713 | - return $content; | |
| 1728 | + if (!empty($post->post_type) && !empty($post->ID)) { | |
| 1729 | + // phpcs:ignore WordPress.WP.CapitalPDangit.Misspelled | |
| 1730 | + $hooks = $this->helper->load('hooks')->get('wordpress', 'hook_wordpress_row_actions', $post->post_type); | |
| 1731 | + foreach ($hooks as $hook) { | |
| 1732 | + if ($this->helper->load('hooks')->process_hook( | |
| 1733 | + $hook, | |
| 1734 | + [ | |
| 1735 | + 'dataset' => $post->ID, | |
| 1736 | + ], | |
| 1737 | + 'hook_wordpress_row_actions' | |
| 1738 | + ) | |
| 1739 | + ) { | |
| 1740 | + $action = apply_filters( | |
| 1741 | + 'e2pdf_hook_action_button', | |
| 1742 | + [ | |
| 1743 | + 'html' => '<a class="e2pdf-download-hook" target="_blank" href="%s">%s</a>', | |
| 1744 | + 'url' => $this->helper->get_url( | |
| 1745 | + [ | |
| 1746 | + 'page' => 'e2pdf', | |
| 1747 | + 'action' => 'export', | |
| 1748 | + 'id' => $hook, | |
| 1749 | + 'dataset' => $post->ID, | |
| 1750 | + ], 'admin.php?' | |
| 1751 | + ), | |
| 1752 | + 'title' => 'PDF #' . $hook, | |
| 1753 | + ], 'hook_wordpress_row_actions', $hook, $post->ID | |
| 1754 | + ); | |
| 1755 | + if (!empty($action)) { | |
| 1756 | + $actions['e2pdf_' . $hook] = sprintf( | |
| 1757 | + $action['html'], $action['url'], $action['title'] | |
| 1758 | + ); | |
| 1759 | + } | |
| 1760 | + } | |
| 1761 | + } | |
| 1762 | + } | |
| 714 | 1763 | } |
| 1764 | + return $actions; | |
| 715 | 1765 | } |
| 716 | - | |
| 717 | 1766 | } |