__('Wordpress', 'e2pdf') ); } /** * Check if needed plugin active * * @return bool - Activated/Not Activated plugin */ public function active() { return true; } /** * Check if export item function available * * @return bool - Item export available/not available */ public function export() { return false; } /** * Set option * * @param string $attr - Key of option * @param string $value - Value of option * * @return bool - Status of setting option */ public function set($key, $value) { if (!isset($this->options)) { $this->options = new stdClass(); } $this->options->$key = $value; } /** * Get option by key * * @param string $key - Key to get assigned option value * * @return mixed */ public function get($key) { if (isset($this->options->$key)) { $value = $this->options->$key; return $value; } else { return false; } } /** * Get items to work with * * @return array() - List of available items */ public function get_items() { $content = array(); $content[] = array( 'key' => 'post', 'value' => __('Wordpress Posts', 'e2pdf'), ); $content[] = array( 'key' => 'page', 'value' => __('Wordpress Pages', 'e2pdf'), ); return $content; } /** * Get entries for export * * @param string $item - Item * @param string $name - Entries names * * @return array() - Entries list */ public function get_datasets($item = false, $name = false) { $datasets = array(); if ($item) { if ($item == 'page') { $datasets_tmp = get_pages(); } elseif ($item == 'post') { $datasets_tmp = get_posts(); } if ($datasets_tmp) { foreach ($datasets_tmp as $key => $dataset) { $this->set('item', $item); $this->set('dataset', $dataset->ID); $dataset_title = $this->render($name); if (!$dataset_title) { $dataset_title = $dataset->post_title; } $datasets[] = array( 'key' => $dataset->ID, 'value' => $dataset_title ); } } } return $datasets; } /** * Get dataset * * @param int $dataset - Dataset ID * * @return object - Dataset */ public function get_dataset($dataset = false) { $dataset = (int) $dataset; if (!$dataset) { return; } $data = new stdClass(); $data->url = $this->helper->get_url(array('post' => $dataset, 'action' => 'edit'), 'post.php?'); return $data; } /** * Get item * * @param string $item - Item * * @return object - Item */ public function get_item($item = false) { $form = new stdClass(); if ($item == 'post') { $form->name = __('Wordpress Posts', 'e2pdf'); $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?'); } elseif ($item == 'page') { $form->name = __('Wordpress Pages', 'e2pdf'); $form->url = $this->helper->get_url(array('post_type' => $item), 'edit.php?'); } else { $form->name = ''; $form->url = 'javascript:void(0);'; } return $form; } public function load_filters() { add_filter('the_content', array($this, 'filter_content'), 10, 2); } /** * Render value according to content * * @param string $value - Content * @param string $type - Type of rendering value * @param array $field - Field details * * @return string - Fully rendered value */ public function render($value, $type = false, $field = array()) { $value = $this->render_shortcodes($value, $type, $field); $value = $this->strip_shortcodes($value); if ($type === 'value' && isset($field['type']) && $field['type'] === 'e2pdf-checkbox' && isset($field['properties']['option'])) { $option = $this->render($field['properties']['option']); $options = explode(', ', $value); $option_options = explode(', ', $option); if (is_array($options) && is_array($option_options) && !array_diff($option_options, $options)) { return $option; } else { return ""; } } if ($type === 'value') { $value = str_replace("[", "[", $value); } return $value; } /** * Render shortcodes which available in this extension * * @param string $value - Content * @param string $type - Type of rendering value * @param array $field - Field details * * @return string - Value with rendered shortcodes */ public function render_shortcodes($value, $type = false, $field = array()) { $dataset_id = $this->get('dataset'); $item_id = $this->get('item'); $post = get_post($dataset_id); $ext_shortcodes = array( "[id]" => $post->ID, "[post_author]" => get_userdata($post->post_author)->user_nicename, "[post_date]" => $post->post_date, "[post_date_gmt]" => $post->post_date_gmt, "[post_content]" => $post->post_content, "[post_title]" => $post->post_title, "[post_excerpt]" => $post->post_excerpt, "[post_status]" => $post->post_status, "[comment_status]" => $post->comment_status, "[ping_status]" => $post->ping_status, "[post_password]" => $post->post_password, "[post_name]" => $post->post_name, "[to_ping]" => $post->to_ping, "[pinged]" => $post->pinged, "[post_modified]" => $post->post_modified, "[post_modified_gmt]" => $post->post_modified_gmt, "[post_content_filtered]" => $post->post_content_filtered, "[post_parent]" => $post->post_parent, "[guid]" => $post->guid, "[menu_order]" => $post->menu_order, "[post_type]" => $post->post_type, "[post_mime_type]" => $post->post_mime_type, "[comment_count]" => $post->comment_count, "[filter]" => $post->filter ); $post_content = false; if (false !== strpos($value, '[')) { $shortcode_tags = array( 'meta', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { $pattern = get_shortcode_regex($tagnames); preg_match_all("/$pattern/", $value, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = array(); $shortcode[1] = $shortcodes[1][$key]; $shortcode[2] = $shortcodes[2][$key]; $shortcode[3] = $shortcodes[3][$key]; $shortcode[4] = $shortcodes[4][$key]; $shortcode[5] = $shortcodes[5][$key]; $shortcode[6] = $shortcodes[6][$key]; $atts = shortcode_parse_atts($shortcode[3]); if (array_key_exists('key', $atts)) { $value = str_replace($shortcode_value, get_post_meta($post->ID, $atts['key'], true), $value); } } } $shortcode_tags = array( 'e2pdf-format-number', 'e2pdf-format-date', 'e2pdf-format-output', ); preg_match_all('@\[([^<>&/\[\]\x00-\x20=]++)@', $value, $matches); $tagnames = array_intersect($shortcode_tags, $matches[1]); if (!empty($tagnames)) { $pattern = get_shortcode_regex($tagnames); preg_match_all("/$pattern/", $value, $shortcodes); foreach ($shortcodes[0] as $key => $shortcode_value) { $shortcode = array(); $shortcode[1] = $shortcodes[1][$key]; $shortcode[2] = $shortcodes[2][$key]; $shortcode[3] = $shortcodes[3][$key]; $shortcode[4] = $shortcodes[4][$key]; $shortcode[5] = $shortcodes[5][$key]; $shortcode[6] = $shortcodes[6][$key]; if (isset($shortcode['5'])) { if (strpos($shortcode['5'], "[post_content]") !== FALSE && !$this->get('no_filter') && !$post_content) { $ext_shortcodes['[post_content]'] = $this->before_render_post_content($ext_shortcodes['[post_content]']); $ext_shortcodes['[post_content]'] = apply_filters('the_content', $ext_shortcodes['[post_content]']); $ext_shortcodes['[post_content]'] = str_replace("
", " \r\n", $ext_shortcodes['[post_content]']); $post_content = true; } $sub_value = str_replace(array_keys($ext_shortcodes), $ext_shortcodes, $shortcode['5']); $value = str_replace($shortcode_value, "[" . $shortcode['2'] . $shortcode['3'] . "]" . $sub_value . "[/" . $shortcode['2'] . "]", $value); } } } } $value = do_shortcode($value); if (isset($field['type']) && ($field['type'] === 'e2pdf-image' || $field['type'] === 'e2pdf-signature')) { $esig = isset($field['properties']['esig']) && $field['properties']['esig'] ? true : false; if ($esig) { //process e-signature $value = ""; } else { if (!$this->helper->load('image')->get_image($value)) { $value = $this->strip_shortcodes($value); if ( $value && trim($value) != "" && extension_loaded('gd') && function_exists('imagettftext') ) { if (isset($field['properties']['text_color']) && $field['properties']['text_color']) { $penColour = $this->helper->load('convert')->to_hex_color($field['properties']['text_color']); } else { $penColour = array(0x14, 0x53, 0x94); } $default_options = array( 'imageSize' => array(isset($field['width']) ? $field['width'] : '400', isset($field['height']) ? $field['height'] : '150'), 'bgColour' => 'transparent', 'penColour' => $penColour ); $options = array(); $options = array_merge($default_options, $options); $model_e2pdf_font = new Model_E2pdf_Font(); $font = false; if (isset($field['properties']['text_font']) && $field['properties']['text_font']) { $font = $model_e2pdf_font->get_font_path($field['properties']['text_font']); } if (!$font) { $font = $model_e2pdf_font->get_font_path('Noto Sans'); } $size = 150; if (isset($field['properties']['text_font_size']) && $field['properties']['text_font_size']) { $size = $field['properties']['text_font_size']; } $model_e2pdf_signature = new Model_E2pdf_Signature(); $value = $model_e2pdf_signature->ttf_signature($value, $size, $font, $options); } else { $value = ""; } } } } else { if (strpos($value, "[post_content]") !== FALSE && !$this->get('no_filter') && !$post_content) { $ext_shortcodes['[post_content]'] = $this->before_render_post_content($ext_shortcodes['[post_content]']); $ext_shortcodes['[post_content]'] = apply_filters('the_content', $ext_shortcodes['[post_content]']); $ext_shortcodes['[post_content]'] = str_replace("", " \r\n", $ext_shortcodes['[post_content]']); $post_content = true; } $value = str_replace(array_keys($ext_shortcodes), $ext_shortcodes, $value); $value = str_replace("[", '[', $value); } return $value; } public function filter_custom_shortcodes() { } /** * Strip unused shortcodes * * @param string $value - Content * * @return string - Value with removed unused shortcodes */ public function strip_shortcodes($value) { $value = preg_replace('~(?:\[/?)[^/\]]+/?\]~s', "", $value); return $value; } public function auto() { $response = array(); $elements = array(); $post = $this->get('item'); $elements[] = array( 'type' => 'e2pdf-html', 'top' => '20', 'left' => '20', 'right' => '20', 'block' => true, 'properties' => array( 'value' => "