PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.03.07
E2Pdf – Export Pdf Tool for WordPress v1.03.07
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 / helper / e2pdf-helper.php

e2pdf-helper.php in E2Pdf – Export Pdf Tool for WordPress 1.03.07, at classes/helper/e2pdf-helper.php

197 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Helper
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 Helper_E2pdf_Helper {
17
18 protected static $instance = NULL;
19 private $helper;
20
21 const CHMOD_DIR = 0755;
22 const CHMOD_FILE = 0644;
23
24 public static function instance() {
25 if (!isset(self::$instance)) {
26 self::$instance = new self();
27 }
28 return self::$instance;
29 }
30
31 /**
32 * Set option by Key
33 *
34 * @param string $key - Key of option
35 * @param mixed $value - Value of option
36 */
37 public function set($key, $value) {
38 if (!$this->helper) {
39 $this->helper = new stdClass();
40 }
41 $this->helper->$key = $value;
42 }
43
44 /**
45 * Add value to option by Key
46 *
47 * @param string $key - Key of option
48 * @param mixed $value - Value of option
49 */
50 public function add($key, $value) {
51 if (!$this->helper) {
52 $this->helper = new stdClass();
53 }
54
55 if (isset($this->helper->$key)) {
56 if (is_array($this->helper->$key)) {
57 array_push($this->helper->$key, $value);
58 }
59 } else {
60 $this->helper->$key = array();
61 array_push($this->helper->$key, $value);
62 }
63 }
64
65 /**
66 * Unset option
67 *
68 * @param string $key - Key of option
69 */
70 public function deset($key) {
71 if (isset($this->helper->$key)) {
72 unset($this->helper->$key);
73 }
74 }
75
76 /**
77 * Set option
78 *
79 * @param string $key - Key of option
80 *
81 * @return mixed - Get value of option by Key
82 */
83 public function get($key) {
84 if (isset($this->helper->$key)) {
85 return $this->helper->$key;
86 } else {
87 return '';
88 }
89 }
90
91 /**
92 * Get url path
93 *
94 * @param string $url - Url path
95 *
96 * @return string - Url path
97 */
98 public function get_url_path($url) {
99 return plugins_url($url, $this->get('plugin_file_path'));
100 }
101
102 /**
103 * Get url
104 *
105 * @param array $data - Array list of url params
106 * @param string $prefix - Prefix of url
107 *
108 * @return string Url
109 */
110 public function get_url($data = array(), $prefix = 'admin.php?') {
111 $url = $prefix . http_build_query($data);
112 return admin_url($url);
113 }
114
115 /**
116 * Get Ip address
117 *
118 * @return mixed - IP address or FALSE
119 */
120 public function get_ip() {
121
122 if (isset($_SERVER['REMOTE_ADDR'])) {
123 $ip = $_SERVER['REMOTE_ADDR'];
124 } else {
125 $ip = false;
126 }
127
128 return $ip;
129 }
130
131 /**
132 * Remove dir and its content
133 *
134 * @param string $dir - Path of directory to remove
135 */
136 public function delete_dir($dir) {
137 if (!is_dir($dir)) {
138 return;
139 }
140 if (substr($dir, strlen($dir) - 1, 1) != '/') {
141 $dir .= '/';
142 }
143 $files = glob($dir . '*', GLOB_MARK);
144 foreach ($files as $file) {
145 if (is_dir($file)) {
146 $this->delete_dir($file);
147 } else {
148 unlink($file);
149 }
150 }
151 rmdir($dir);
152 }
153
154 public function create_dir($dir = false) {
155 if ($dir && !file_exists($dir)) {
156 if (mkdir($dir, self::CHMOD_DIR)) {
157 $index = $dir . 'index.php';
158 $this->create_file($index, "<?php\n// Silence is golden.\n?>");
159 }
160 }
161 return is_dir($dir);
162 }
163
164 public function create_file($file = false, $content = '') {
165 if ($file && !file_exists($file)) {
166 if (file_put_contents($file, $content)) {
167 chmod($file, self::CHMOD_FILE);
168 }
169 }
170 return is_file($file);
171 }
172
173 public function get_upload_url($path = false) {
174
175 $wp_upload_dir = wp_upload_dir();
176
177 if ($path) {
178 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir'))) . "/" . $path;
179 } else {
180 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir')));
181 }
182 }
183
184 public function load($helper) {
185 $model = null;
186 $class = "Helper_E2pdf_" . ucfirst($helper);
187 if (class_exists($class)) {
188 if (!$this->get($class)) {
189 $this->set($class, new $class());
190 }
191 $model = $this->get($class);
192 }
193 return $model;
194 }
195
196 }
197