PluginProbe ʕ •ᴥ•ʔ
Tracking Code Manager / 1.4
Tracking Code Manager v1.4
trunk 1.11.8 1.11.9 1.12.0 1.12.1 1.12.2 1.12.3 1.4 1.5 2.0.0 2.0.1 2.0.13 2.0.14 2.0.15 2.0.16 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.6.0
tracking-code-manager / includes / class-TCM-options.php
tracking-code-manager / includes Last commit date
admin 11 years ago actions.php 11 years ago class-TCM-check.php 11 years ago class-TCM-cron.php 11 years ago class-TCM-form.php 11 years ago class-TCM-language.php 11 years ago class-TCM-logger.php 11 years ago class-TCM-manager.php 11 years ago class-TCM-options.php 11 years ago class-TCM-tracking.php 11 years ago class-TCM-utils.php 11 years ago core.php 11 years ago install.php 11 years ago uninstall.php 11 years ago
class-TCM-options.php
266 lines
1 <?php
2 /**
3 * Created by PhpStorm.
4 * User: alessio
5 * Date: 24/03/2015
6 * Time: 08:45
7 */
8 // Exit if accessed directly
9 if ( ! defined( 'ABSPATH' ) ) exit;
10
11 class TCM_Options {
12 public function __construct() {
13
14 }
15
16 //always add a prefix to avoid conflicts with other plugins
17 private function getKey($key) {
18 return 'TCM_'.$key;
19 }
20 //option
21 private function removeOption($key) {
22 $key=$this->getKey($key);
23 delete_option($key);
24 }
25 private function getOption($key, $default=FALSE) {
26 $key=$this->getKey($key);
27 $result=get_option($key, $default);
28 if(is_string($result)) {
29 $result=trim($result);
30 }
31 return $result;
32 }
33 private function setOption($key, $value) {
34 $key=$this->getKey($key);
35 if(is_bool($value)) {
36 $value=($value ? 1 : 0);
37 }
38 update_option($key, $value);
39 }
40
41 //$_SESSION
42 private function removeSession($key) {
43 global $wp_session;
44
45 $key=$this->getKey($key);
46 if(isset($wp_session[$key])) {
47 unset($wp_session[$key]);
48 }
49 }
50 private function getSession($key, $default=FALSE) {
51 global $wp_session;
52
53 $key=$this->getKey($key);
54 $result=$default;
55 if(isset($wp_session[$key])) {
56 $result=$wp_session[$key];
57 }
58 if(is_string($result)) {
59 $result=trim($result);
60 }
61 return $result;
62 }
63 private function setSession($key, $value) {
64 global $wp_session;
65
66 $key=$this->getKey($key);
67 $wp_session[$key]=$value;
68 }
69
70 //$_REQUEST
71 //However WP enforces its own logic - during load process wp_magic_quotes() processes variables to emulate magic quotes setting and enforces $_REQUEST to contain combination of $_GET and $_POST, no matter what PHP configuration says.
72 private function removeRequest($key) {
73 $key=$this->getKey($key);
74 if(isset($_POST[$key])) {
75 unset($_POST[$key]);
76 }
77 }
78 private function getRequest($key, $default=FALSE) {
79 $key=$this->getKey($key);
80 $result=$default;
81 if(isset($_POST[$key])) {
82 $result=$_POST[$key];
83 }
84 return $result;
85 }
86 private function setRequest($key, $value) {
87 $key=$this->getKey($key);
88 $_POST[$key]=$value;
89 }
90
91 //TrackingEnable
92 public function isTrackingEnable() {
93 return $this->getOption('TrackingEnable', 0);
94 }
95 public function setTrackingEnable($value) {
96 $this->setOption('TrackingEnable', $value);
97 }
98 //TrackingNotice
99 public function isTrackingNotice() {
100 return $this->getOption('TrackingNotice', 1);
101 }
102 public function setTrackingNotice($value) {
103 $this->setOption('TrackingNotice', $value);
104 }
105 //TrackingLastSendPro
106 public function getTrackingLastSend() {
107 return $this->getOption('TrackingLastSend', 0);
108 }
109 public function setTrackingLastSend($value) {
110 $this->setOption('TrackingLastSend', $value);
111 }
112
113 //LoggerEnable
114 public function isLoggerEnable() {
115 return ($this->getOption('LoggerEnable', FALSE) || (defined('TCM_LOGGER') && TCM_LOGGER));
116 }
117 public function setLoggerEnable($value) {
118 $this->setOption('LoggerEnable', $value);
119 }
120
121 //Snippet
122 public function getSnippet($id) {
123 return $this->getOption('Snippet_'.$id, NULL);
124 }
125 public function setSnippet($id, $value) {
126 $this->setOption('Snippet_'.$id, $value);
127 }
128 public function removeSnippet($id) {
129 $this->removeOption('Snippet_'.$id);
130 }
131 //SnippetList
132 public function getSnippetList() {
133 return $this->getOption('SnippetList', array());
134 }
135 public function setSnippetList($value) {
136 $this->setOption('SnippetList', $value);
137 }
138 public function removeSnippetList() {
139 $this->removeOption('SnippetList');
140 }
141
142 public function hasSnippetWritten($snippet) {
143 //check also the md5 of code so if the user create 2 different snippets with
144 //the same tracking code we will not insert into 2 times inside the html
145 $id=$snippet['id'];
146 $md5=md5($snippet['code']);
147
148 $listIds=$this->getRequest('SnippetsWrittenIds', array());
149 $listMd5=$this->getRequest('SnippetsWrittenMd5', array());
150
151 $result=(in_array($id, $listIds) || in_array($md5, $listMd5));
152 return $result;
153 }
154 public function pushSnippetWritten($snippet) {
155 $md5=md5($snippet['code']);
156 $id=$snippet['id'];
157 $listIds=$this->getRequest('SnippetsWrittenIds', array());
158 $listMd5=$this->getRequest('SnippetsWrittenMd5', array());
159
160 $listIds[$id]=$snippet;
161 $listMd5[$md5]=$id;
162 $this->setRequest('SnippetsWrittenIds', $listIds);
163 $this->setRequest('SnippetsWrittenMd5', $listMd5);
164 }
165 public function getSnippetsWritten() {
166 return $this->getRequest('SnippetsWrittenIds', array());
167 }
168 public function clearSnippetsWritten() {
169 $this->setRequest('SnippetsWrittenIds', array());
170 $this->setRequest('SnippetsWrittenMd5', array());
171 }
172
173 //PostShown
174 public function getPostShown() {
175 return $this->getRequest('PostShown');
176 }
177 public function setPostShown($post) {
178 $this->setRequest('PostShown', $post);
179 }
180 //Cache
181 public function getCache($name, $id) {
182 return $this->getRequest('Cache_'.$name.'_'.$id);
183 }
184 public function setCache($name, $id, $value) {
185 $this->setRequest('Cache_'.$name.'_'.$id, $value);
186 }
187
188 //ErrorMessages
189 public function hasErrorMessages() {
190 $result=$this->getRequest('ErrorMessages', NULL);
191 return (is_array($result) && count($result)>0);
192 }
193 public function pushErrorMessage($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
194 global $tcm;
195 $array=$this->getRequest('ErrorMessages', array());
196 $array[]=$tcm->Lang->L($message, $v1, $v2, $v3, $v4, $v5);
197 $this->setRequest('ErrorMessages', $array);
198 }
199 public function writeErrorMessages($clean=TRUE) {
200 global $tcm;
201 $array=$this->getRequest('ErrorMessages', array());
202 if(is_array($array) && count($array)>0) { ?>
203 <div class="message error"><?php echo wpautop(implode("\n", $array)); ?></div>
204 <?php }
205 if($clean) {
206 $this->removeRequest('ErrorMessages');
207 }
208 }
209 //SuccessMessages
210 public function hasSuccessMessages() {
211 $result=$this->getRequest('SuccessMessages', NULL);
212 return (is_array($result) && count($result)>0);
213 }
214 public function pushSuccessMessage($message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
215 global $tcm;
216 $array=$this->getRequest('SuccessMessages', array());
217 $array[]=$tcm->Lang->L($message, $v1, $v2, $v3, $v4, $v5);
218 $this->setRequest('SuccessMessages', $array);
219 }
220 public function writeSuccessMessages($clean=TRUE) {
221 $array=$this->getRequest('SuccessMessages', array());
222 if(is_array($array) && count($array)>0) { ?>
223 <div class="message updated"><?php echo wpautop(implode("\n", $array)); ?></div>
224 <?php }
225 if($clean) {
226 $this->removeRequest('SuccessMessages');
227 }
228 }
229 public function writeMessages($clean=TRUE) {
230 $this->writeErrorMessages($clean);
231 $this->writeSuccessMessages($clean);
232 }
233 public function pushMessage($success, $message, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
234 if($success) {
235 $this->pushSuccessMessage($message.'Success', $v1, $v2, $v3, $v4, $v5);
236 } else {
237 $this->pushErrorMessage($message.'Error', $v1, $v2, $v3, $v4, $v5);
238 }
239 }
240
241 public function getFeedbackEmail() {
242 return $this->getOption('FeedbackEmail', get_bloginfo('admin_email'));
243 }
244 public function setFeedbackEmail($value) {
245 $this->setOption('FeedbackEmail', $value);
246 }
247
248 //MetaboxPostTypes
249 public function getMetaboxPostTypes($create=TRUE) {
250 global $tcm;
251 $result=$this->getOption('MetaboxPostTypes', array());
252 if($create) {
253 $types=$tcm->Utils->query(TCM_QUERY_POST_TYPES);
254 foreach($types as $v) {
255 $v=$v['id'];
256 if(!isset($result[$v])) {
257 $result[$v]=1;
258 }
259 }
260 }
261 return $result;
262 }
263 public function setMetaboxPostTypes($values) {
264 $this->setOption('MetaboxPostTypes', $values);
265 }
266 }