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 / helper / e2pdf-helper.php

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

231 lines 5.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 if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
122 $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
123 } elseif (isset($_SERVER['REMOTE_ADDR'])) {
124 $ip = $_SERVER['REMOTE_ADDR'];
125 } else {
126 $ip = false;
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 $wp_upload_dir = wp_upload_dir();
175 if ($path) {
176 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir'))) . "/" . $path;
177 } else {
178 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir')));
179 }
180 }
181
182 /**
183 * Get Capabilities
184 *
185 * @return array()
186 */
187 public function get_caps() {
188 $caps = array(
189 'e2pdf' => array(
190 'name' => __('Export', 'e2pdf'),
191 'cap' => 'e2pdf',
192 ),
193 'e2pdf_templates' => array(
194 'name' => __('Templates', 'e2pdf'),
195 'cap' => 'e2pdf_templates'
196 ),
197 'e2pdf_settings' => array(
198 'name' => __('Settings', 'e2pdf'),
199 'cap' => 'e2pdf_settings'
200 ),
201 'e2pdf_license' => array(
202 'name' => __('License', 'e2pdf'),
203 'cap' => 'e2pdf_license'
204 ),
205 'e2pdf_debug' => array(
206 'name' => __('Debug', 'e2pdf'),
207 'cap' => 'e2pdf_debug'
208 )
209 );
210 return $caps;
211 }
212
213 /**
214 * Load sub-helper
215 *
216 * @return object
217 */
218 public function load($helper) {
219 $model = null;
220 $class = "Helper_E2pdf_" . ucfirst($helper);
221 if (class_exists($class)) {
222 if (!$this->get($class)) {
223 $this->set($class, new $class());
224 }
225 $model = $this->get($class);
226 }
227 return $model;
228 }
229
230 }
231