PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.06
E2Pdf – Export Pdf Tool for WordPress v1.08.06
1.32.49 1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 All 72 releases
e2pdf / classes / model / e2pdf-convert.php

e2pdf-convert.php in E2Pdf – Export Pdf Tool for WordPress 1.08.06, at classes/model/e2pdf-convert.php

91 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2Pdf Convert Model
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Convert extends Model_E2pdf_Model {
17
18 protected $convert = NULL;
19
20 /**
21 * Initialize functions
22 */
23 function __construct() {
24 parent::__construct();
25 }
26
27 /**
28 * Convert Template to PHP Output
29 *
30 * @param array $data - Template
31 *
32 * @return string - Converted template
33 */
34 public function toPHP($data = array()) {
35 $content = "";
36 foreach ($data as $key => $value) {
37 if (is_array($value)) {
38 $content .= "'" . $key . "' => [";
39 $content .= $this->toPHP($value);
40 $content .= "],\n";
41 } else {
42 $content .= "'" . $key . "' => '" . str_replace("'", "\'", $value) . "',\n";
43 }
44 }
45 return $content;
46 }
47
48 /**
49 * Set options for API Request
50 *
51 * @param string $key - Key
52 * @param mixed $value - Value
53 */
54 public function set($key, $value = false) {
55 if (!$this->convert) {
56 $this->convert = new stdClass();
57 }
58 if (is_array($key)) {
59 foreach ($key as $attr => $value) {
60 $this->convert->$attr = $value;
61 }
62 } else {
63 $this->convert->$key = $value;
64 }
65 }
66
67 /**
68 * Convert Template
69 */
70 public function convert() {
71
72 $data = !empty($this->convert->data) ? $this->convert->data : array();
73
74 $file = '<?php' . PHP_EOL;
75 $file .= 'function e2pdf_template() {' . PHP_EOL;
76 $file .= '$template = [' . PHP_EOL;
77 $file .= $this->toPHP($data);
78 $file .= '];' . PHP_EOL;
79 $file .= 'return $template;' . PHP_EOL;
80 $file .= '}';
81
82 if ($file) {
83 $response['file'] = base64_encode($file);
84 } else {
85 $response['error'] = __("Something went wrong!", "e2pdf");
86 }
87 return $response;
88 }
89
90 }
91