PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.00.00
E2Pdf – Export Pdf Tool for WordPress v1.00.00
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.00.00, 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 * Convert from bytes to Human View
133 *
134 * @param int $size - Size in Bytes
135 *
136 * @return string - Converted size
137 */
138 public function convert($size) {
139 $unit = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
140 return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . '' . $unit[$i];
141 }
142
143 /**
144 * Remove dir and its content
145 *
146 * @param string $dir - Path of directory to remove
147 */
148 public function delete_dir($dir) {
149 if (!is_dir($dir)) {
150 return;
151 }
152 if (substr($dir, strlen($dir) - 1, 1) != '/') {
153 $dir .= '/';
154 }
155 $files = glob($dir . '*', GLOB_MARK);
156 foreach ($files as $file) {
157 if (is_dir($file)) {
158 $this->delete_dir($file);
159 } else {
160 unlink($file);
161 }
162 }
163 rmdir($dir);
164 }
165
166 public function create_dir($dir = false) {
167 if ($dir && !file_exists($dir)) {
168 if (mkdir($dir, self::CHMOD_DIR)) {
169 $index = $dir . 'index.php';
170 $this->create_file($index, "<?php\n// Silence is golden.\n?>");
171 }
172 }
173 return is_dir($dir);
174 }
175
176 public function create_file($file = false, $content = '') {
177 if ($file && !file_exists($file)) {
178 if (file_put_contents($file, $content)) {
179 chmod($file, self::CHMOD_FILE);
180 }
181 }
182 return is_file($file);
183 }
184
185 public function get_upload_url($path = false) {
186
187 $wp_upload_dir = wp_upload_dir();
188
189 if ($path) {
190 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir'))) . "/" . $path;
191 } else {
192 return $wp_upload_dir['baseurl'] . "/" . basename(untrailingslashit($this->get('upload_dir')));
193 }
194 }
195
196 }
197