PluginProbe
Tracking Code Manager / 2.3.0
Tracking Code Manager v2.3.0
2.8.0 2.7.0 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 All 29 releases
tracking-code-manager / includes / classes / utils / AppOptions.php
AppOptions.php
562 lines 20.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class IRP_AppOptions extends IRP_Options {
4 public function __construct() {
5 }
6
7 public function getMarginTop() {
8 $mt = $this->getOption('MarginTop', '0em');
9 return wp_kses_post($mt);
10 }
11 public function setMarginTop($value) {
12 $this->setOption('MarginTop', $value);
13 }
14 public function getMarginBottom() {
15 $mb = $this->getOption('MarginBottom', '1em');
16 return wp_kses_post($mb);
17 }
18 public function setMarginBottom($value) {
19 $this->setOption('MarginBottom', $value);
20 }
21
22 public function hasRelatedPostsIds() {
23 $array=$this->getRequest('RelatedPostsIds', array());
24 return (is_array($array) && count($array)>0);
25 }
26
27 public function initRelatedPostsIds($ids, $postId = -1)
28 {
29 $staticLinks = $this->isRewriteStaticLinks();
30 if ($postId > 0 && $staticLinks) {
31 $ids = $this->getStaticLinks($postId, $ids);
32 }
33 $this->setRequest('RelatedPostsIds', $ids);
34 if ($ids && !$staticLinks) {
35 shuffle($ids);
36 }
37 $this->setRequest('ToShowPostsIds', $ids);
38 $this->setRequest('ShownPostsIdsSequence', array());
39 $this->setRewriteBoxesWritten(0);
40 }
41
42 private function getStaticLinks($postId, $ids)
43 {
44 $key = 'POST_' . $postId;
45 $staticIds = $this->getOption($key, array());
46 $checkedDate = get_the_modified_date('', $postId) . ' ' . get_the_modified_time('', $postId);
47 if (empty($staticIds)) {
48 $data = array (
49 'date' => $checkedDate,
50 'ids' => $ids
51 );
52 $this->setOption($key, $data);
53 } else {
54 $savedDate = $staticIds['date'];
55 $savedIds = $staticIds['ids'];
56 $valid = $this->validatePostIds($savedIds);
57 if (!$valid || $savedDate != $checkedDate) {
58 $data = array (
59 'date' => $checkedDate,
60 'ids' => $ids
61 );
62 $this->setOption($key, $data);
63 } else {
64 $ids = $savedIds;
65 }
66 }
67 return $ids;
68 }
69
70 private function validatePostIds($ids)
71 {
72 foreach ($ids as $id) {
73 $status = get_post_status($id);
74 if ($status === false) {
75 return false;
76 }
77 }
78 return true;
79 }
80
81 public function refreshRelatedPostsIds() {
82 $ids=$this->getRequest('RelatedPostsIds', array());
83 $this->initRelatedPostsIds($ids);
84 }
85 //if you pass maxIds as a number this function take next [maxIds] posts to show as related
86 //if you pass maxIds as an array of postsIds will return this array as posts to show as related
87 public function getToShowPostsIds($maxIds, $repeat=FALSE) {
88 $result=array();
89 $maxIds=intval($maxIds);
90 if(!$this->hasRelatedPostsIds()) {
91 return $result;
92 }
93
94 $toShow=$this->getRequest('ToShowPostsIds', array());
95 if(is_numeric($maxIds)) {
96 if(!is_array($toShow) || (count($toShow)==0 && !$repeat)) {
97 return $result;
98 }
99 while($maxIds>0) {
100 if(count($toShow)==0) {
101 if($repeat) {
102 //i can use again the posts shown
103 $toShow=$this->getRequest('RelatedPostsIds');
104 shuffle($toShow);
105 } else {
106 break;
107 }
108 }
109
110 $postId=array_pop($toShow);
111 $result[]=$postId;
112 --$maxIds;
113 }
114 } elseif(is_array($maxIds)) {
115 $toShow=array_diff($toShow, $maxIds);
116 $result=$maxIds;
117 }
118 $this->setRequest('ToShowPostsIds', $toShow);
119
120 //update the sequence shown
121 $array=$this->getRequest('ShownPostsIdsSequence', array());
122 $array[]=$result;
123 $this->setRequest('ShownPostsIdsSequence', $array);
124
125 return $result;
126 }
127 public function getShownPostsIdsSequence() {
128 return $this->getRequest('ShownPostsIdsSequence', array());
129 }
130
131 public function getPostShown() {
132 return $this->getRequest('PostShown', NULL);
133 }
134 public function setPostShown($value) {
135 $this->setRequest('PostShown', $value);
136 }
137 public function isPostShownExcluded() {
138 global $irp;
139 $array=$this->getExcludedPostsIds();
140 $post=$this->getPostShown();
141
142 $result=FALSE;
143 if(!$post || !isset($post->ID)) {
144 $result=TRUE;
145 } elseif(in_array($post->ID, $array)) {
146 $irp->Log->info('POST ID=%s IN RELATED POSTS EXCLUDE LIST', $post->ID);
147 $result=TRUE;
148 } else {
149 $result=FALSE;
150 }
151 return $result;
152 }
153 public function isShortcodeUsed() {
154 return $this->getRequest('ShortcodeUsed', 0);
155 }
156 public function setShortcodeUsed($value) {
157 $this->setRequest('ShortcodeUsed', $value);
158 }
159
160 public function getTemplateStyle() {
161 global $irp;
162
163 $defaults=array(
164 'template'=>''
165 , 'linkRel'=>$this->getOption('LinkRel', IRP_DEFAULT_LINK_REL_ATTRIBUTE)
166 , 'linkTarget'=>$this->getOption('LinkTarget', '_blank')
167 , 'ctaText'=>$this->getOption('RelatedText', 'READ')
168 , 'ctaTextColor'=>$this->getOption('TemplateRelatedTextColor', '')
169 , 'postTitleColor'=>$this->getOption('TemplateRelatedTextColor', '')
170 , 'boxColor'=>$this->getOption('TemplateBackgroundColor', '')
171 , 'borderColor'=>$this->getOption('TemplateBorderColor', '')
172 , 'hasShadow'=>$this->getOption('TemplateShadow', FALSE)
173 , 'hasPoweredBy'=>$this->getOption('ShowPoweredBy', FALSE)
174 , 'boxOpacity'=>100
175 );
176 $result=$this->getOption('TemplateStyle', $defaults);
177 $names=$irp->HtmlTemplate->getTemplatesNames();
178 if($result['template']=='' || !in_array($result['template'], $names)) {
179 if(count($names)>0) {
180 $n = 'Minimalist';
181 $dt = $irp->HtmlTemplate->getDefaults();
182
183 $result['template'] = $n;
184 $result['ctaTextColor'] = $this->getColor( $dt[$n]['ctaTextColor'] );
185 $result['postTitleColor'] = $this->getColor( $dt[$n]['postTitleColor'] );
186 $result['boxColor'] = $this->getColor( $dt[$n]['boxColor'] );
187 $result['borderColor'] = $this->getColor( $dt[$n]['borderColor'] );
188 }
189 }
190 if (isset($result['linkTarget']) && !empty($result['linkTarget']))
191 {
192 if ($result['linkTarget'] !== '_blank')
193 {
194 if ($result['linkTarget'] !== '_self')
195 {
196 $result['linkTarget'] = '_blank';
197 }
198 }
199 }
200 if (isset($result['linkRel']) && !empty($result['linkRel']))
201 {
202 if ($result['linkRel'] !== 'dofollow')
203 {
204 if ($result['linkRel'] !== 'nofollow')
205 {
206 $result['linkRel'] = 'nofollow';
207 }
208 }
209 }
210 return $result;
211 }
212 public function setTemplateStyle($value) {
213 if (isset($value['linkTarget']) && !empty($value['linkTarget']))
214 {
215 if ($value['linkTarget'] !== '_blank')
216 {
217 if ($value['linkTarget'] !== '_self')
218 {
219 $value['linkTarget'] = '_blank';
220 }
221 }
222 }
223 if (isset($value['linkRel']) && !empty($value['linkRel']))
224 {
225 if ($value['linkRel'] !== 'dofollow')
226 {
227 if ($value['linkRel'] !== 'nofollow')
228 {
229 $value['linkRel'] = 'nofollow';
230 }
231 }
232 }
233 $this->setOption('TemplateStyle', $value);
234 }
235
236 //is related posts active in posts without any [irl] shortcodes defined
237 public function isRewriteActive() {
238 return $this->getOption('RewriteActive', 1);
239 }
240 public function setRewriteActive($value) {
241 $this->setOption('RewriteActive', $value);
242 }
243
244 public function isPlaceInsideSpanElements() {
245 return $this->getOption('PlaceInsideSpanElements', 1);
246 }
247
248 public function setPlaceInsideSpanElements($value) {
249 $this->setOption('PlaceInsideSpanElements', $value);
250 }
251
252 public function isDoNotIncludeCssInBox() {
253 // 0 = include css with the link box, 1 = put css at end of body
254 return $this->getOption('DoNotIncludeCssInBox', 0);
255 }
256
257 public function setDoNotIncludeCssInBox($value) {
258 $this->setOption('DoNotIncludeCssInBox', $value);
259 }
260
261 public function isRewriteStaticLinks()
262 {
263 return $this->getOption('RewriteStaticLinks', false);
264 }
265
266 public function setRewriteStaticLinks($value)
267 {
268 if (!$value && $this->isRewriteStaticLinks()) {
269 // remove all saved links
270 global $wpdb;
271 $wpdb->query( $wpdb->prepare( "DELETE FROM `wp_options` where option_name like %s", array('IRP_POST_%') ) );
272 }
273 $this->setOption('RewriteStaticLinks', $value);
274 }
275
276 public function getExcludedPostsIds() {
277 return $this->getOption('ExcludedPostsIds', array());
278 }
279 public function setExcludedPostsIds($value) {
280 $value=array_unique($value);
281 $this->setOption('ExcludedPostsIds', $value);
282 }
283 public function getMetaboxPostTypes($create=TRUE) {
284 global $irp;
285 $result=$this->getOption('MetaboxPostTypes', array());
286 if($create) {
287 $types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
288 foreach($types as $v) {
289 $v=$v['id'];
290 if(!isset($result[$v])) {
291 $result[$v]=($v=='post' ? 1 : 0);
292 }
293 }
294 }
295 // We used to try to apply the automatic IRP to pages even though it never really worked.
296 // The unset is here to expunge the value from the database. The unset needs to stay
297 // here because a $create will put it back into the database and if it's returned from
298 // here, the IRP checkbox will be placed in the page editor.
299 unset($result['page']);
300 return $result;
301 }
302 public function setMetaboxPostTypes($values) {
303 $this->setOption('MetaboxPostTypes', $values);
304 }
305 //is integrated with which post types?
306 public function getRewritePostTypes($create=TRUE) {
307 global $irp;
308 $result=$this->getOption('RewritePostTypes', array());
309 if($create) {
310 $types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
311 foreach($types as $v) {
312 $v=$v['id'];
313 if(!isset($result[$v])) {
314 $result[$v]=($v=='post' ? 1 : 0);
315 }
316 }
317 }
318 return $result;
319 }
320 public function setRewritePostTypes($values) {
321 $this->setOption('RewritePostTypes', $values);
322 }
323 //how many related posts boxes we have to include?
324 public function getRewriteBoxesCount() {
325 return intval($this->getOption('RewriteBoxesCount', 3));
326 }
327 public function setRewriteBoxesCount($value) {
328 $this->setOption('RewriteBoxesCount', $value);
329 }
330 //how many related posts we see in each box?
331 public function getRewritePostsInBoxCount() {
332 //return $this->getOption('RewritePostsInBoxCount', 1);
333 return 1;
334 }
335 public function setRewritePostsInBoxCount($value) {
336 $this->setOption('RewritePostsInBoxCount', $value);
337 }
338 public function getRewritePostsDays() {
339 return intval($this->getOption('RewritePostsDays', 0));
340 }
341 public function setRewritePostsDays($value) {
342 $this->setOption('RewritePostsDays', intval($value));
343 }
344 //how many words we have to "wait" before inserting a related box
345 public function getRewriteThreshold() {
346 return $this->getOption('RewriteThreshold', 250);
347 }
348 public function setRewriteThreshold($value) {
349 $this->setOption('RewriteThreshold', $value);
350 }
351 //hook priority
352 public function getHookPriority() {
353 return intval($this->getOption('HookPriority', 99999));
354 }
355 public function setHookPriority($value) {
356 $this->setOption('HookPriority', $value);
357 }
358 //include also a related box in the end?
359 public function isRewriteAtEnd() {
360 return $this->getOption('RewriteAtEnd', TRUE);
361 }
362 public function setRewriteAtEnd($value) {
363 $this->setOption('RewriteAtEnd', $value);
364 }
365 //how many boxes are already been written?
366 public function getRewriteBoxesWritten() {
367 return $this->getRequest('RewriteBoxesWritten', 0);
368 }
369 public function setRewriteBoxesWritten($value) {
370 $this->setRequest('RewriteBoxesWritten', $value);
371 }
372
373 public function getEngineSearch() {
374 return $this->getOption('EngineSearch', IRP_ENGINE_SEARCH_CATEGORIES_TAGS);
375 }
376 public function setEngineSearch($value) {
377 $this->setOption('EngineSearch', $value);
378 }
379
380 public function getMaxExecutionTime(){
381 return $this->getOption('MaxExecutionTime', -1);
382 }
383 public function resetMaxExecutionTime(){
384 $this->setOption('MaxExecutionTime', -1);
385 }
386 public function updateMaxExecutionTime($value){
387 $now=$this->getMaxExecutionTime();
388 if($value>$now) {
389 $this->setOption('MaxExecutionTime', $value);
390 }
391 }
392
393 public function pushCssStyle($code) {
394 global $irp;
395 if(is_array($code)) {
396 $code=implode("\n", $code);
397 }
398 $code=str_replace('<style>', '', $code);
399 $code=str_replace('</style>', '', $code);
400 $code=$irp->Utils->trimCode($code);
401
402 $array=$this->getCssStyles();
403 $exists=FALSE;
404 if(count($array)>0) {
405 foreach($array as $v) {
406 if(trim($v)==trim($code)) {
407 $exists=TRUE;
408 break;
409 }
410 }
411 }
412 if(!$exists) {
413 $array[]=$code;
414 $this->setRequest('CssStyles', $array);
415 }
416 }
417 public function getCssStyles() {
418 return $this->getRequest('CssStyles', array());
419 }
420
421 public function getColor($color) {
422 global $irp;
423 $result=$color;
424 if(!$irp->Utils->startsWith($color, '#')) {
425 $colors=$this->getLegacyColors();
426 $v=$irp->Utils->geti($colors, $color, FALSE);
427 if($v!==FALSE) {
428 $result=$v['color'];
429 } else {
430 $colors=$this->getColors();
431 $v=$irp->Utils->geti($colors, $color, FALSE);
432 if($v!==FALSE) {
433 $result=$v['color'];
434 }
435 }
436 }
437 return $result;
438 }
439 public function getHoverColor($color) {
440 $color=$this->getColor($color);
441 $colors=$this->getLightDarkColors();
442 $result='';
443 foreach($colors as $k=>$v) {
444 if($v['light']==$color) {
445 $result=$v['dark'];
446 break;
447 } elseif($v['dark']==$color) {
448 $result=$v['light'];
449 break;
450 }
451 }
452 return $result;
453 }
454 public function getColors($blank='') {
455 $array=$this->getLightDarkColors();
456 $result=array();
457 if($blank!='') {
458 $result[$blank]=array('color'=>'', 'fontColor'=>'#464646');
459 }
460 foreach($array as $k=>$v) {
461 if(isset($v['color'])) {
462 $a=array();
463 $a['color']=$v['color'];
464 if(isset($v['fontColor'])) {
465 $a['fontColor']=$v['fontColor'];
466 }
467 $result[$k]=$a;
468 }
469 if(isset($v['light'])) {
470 $a=array();
471 $a['color']=$v['light'];
472 if(isset($v['fontLight'])) {
473 $a['fontColor']=$v['fontLight'];
474 }
475 $result[$k.' Light']=$a;
476 }
477 if(isset($v['dark'])) {
478 $a=array();
479 $a['color']=$v['dark'];
480 if(isset($v['fontDark'])) {
481 $a['fontColor']=$v['fontDark'];
482 }
483 $result[$k.' Dark']=$a;
484 }
485 }
486
487 ksort($result);
488 return $result;
489 }
490 //$colors['(Default)']=array('color'=>'', 'fontColor'=>'#464646');
491 public function getLightDarkColors() {
492 $colors['WHITE']=array(
493 'light'=>'#FFFFFF', 'fontLight'=>'#464646'
494 , 'dark'=>'#eaeaea', 'fontDark'=>'#464646'
495 );
496 $colors['AQUA']=array('light'=>'#1ABC9C', 'dark'=>'#16A085');
497 $colors['GREEN']=array('light'=>'#2ECC71', 'dark'=>'#27AE60');
498 $colors['VIOLET']=array('light'=>'#9B59B6', 'dark'=>'#8E44AD');
499 $colors['BLUE #1']=array('light'=>'#3498DB', 'dark'=>'#2980B9');
500 $colors['BLUE #2']=array('light'=>'#34495E', 'dark'=>'#2C3E50');
501 $colors['YELLOW']=array('light'=>'#F1C40F', 'dark'=>'#F39C12');
502 $colors['ORANGE']=array('light'=>'#E67E22', 'dark'=>'#D35400');
503 $colors['RED']=array('light'=>'#E74C3C', 'dark'=>'#C0392B');
504 $colors['GREY #1']=array(
505 'light'=>'#ECF0F1', 'fontLight'=>'#464646'
506 , 'dark'=>'#e6e6e6', 'fontDark'=>'#464646'
507 );
508 $colors['GREY #2']=array('light'=>'#95A5A6', 'dark'=>'#7F8C8D');
509 $colors['BLACK']=array('light'=>'#141414', 'dark'=>'#000000');
510 ksort($colors);
511 return $colors;
512 }
513 public function getLegacyColors() {
514 $colors=array();
515 $colors['(Default)']=array('color'=>'', 'fontColor'=>'#464646');
516 $colors['WHITE']=array('color'=>'#FFFFFF', 'fontColor'=>'#464646');
517 $colors['LIGHT GREY']=array('color'=>'#ECF0F1', 'fontColor'=>'#464646');
518 $colors['DARK GREY']=array('color'=>'#555555');
519 $colors['BLACK']=array('color'=>'#000000');
520
521 $colors['(Transparent)']=array('color'=>'', 'fontColor'=>'#464646');
522 $colors['WHITE']=array('color'=>'#FFFFFF', 'fontColor'=>'#464646');
523 $colors['LIGHT GREY']=array('color'=>'#ECF0F1', 'fontColor'=>'#464646');
524 $colors['DARK GREY']=array('color'=>'#555555');
525 $colors['BLACK']=array('color'=>'#000000'); //black
526
527 $colors['(Transparent)']=array('color'=>'', 'fontColor'=>'#464646');
528 $colors['TURQUOISE']=array('color'=>'#1ABC9C'); //Aqua
529 $colors['EMERALD']=array('color'=>'#2ECC71'); //green
530 $colors['AMETHYST']=array('color'=>'#9B59B6');//violet
531 $colors['PETER RIVER']=array('color'=>'#3498DB');//blue
532 $colors['WET ASPHALT']=array('color'=>'#34495E');//blue
533 $colors['SUN FLOWER']=array('color'=>'#F1C40F');//yellow
534 $colors['CARROT']=array('color'=>'#E67E22');//orange
535 $colors['ALIZARIN']=array('color'=>'#E74C3C');//red
536 $colors['CLOUDS']=array('color'=>'#ECF0F1', 'fontColor'=>'#464646');//grey
537 $colors['CONCRETE']=array('color'=>'#95A5A6');//grey (+grey)
538
539 $colors['(Transparent)']=array('color'=>'', 'fontColor'=>'#464646');
540 $colors['GREEN SEA']=array('color'=>'#16A085');
541 $colors['NEPHRITIS']=array('color'=>'#27AE60');
542 $colors['WISTERIA']=array('color'=>'#8E44AD');
543 $colors['BELIZE HOLE']=array('color'=>'#2980B9');
544 $colors['MIDNIGHT BLUE']=array('color'=>'#2C3E50');
545 $colors['ORANGE']=array('color'=>'#F39C12');
546 $colors['PUMPKIN']=array('color'=>'#D35400');
547 $colors['POMEGRANATE']=array('color'=>'#C0392B');
548 $colors['SILVER']=array('color'=>'#BDC3C7');
549 $colors['ASBESTOS']=array('color'=>'#7F8C8D');
550 ksort($colors);
551 return $colors;
552 }
553
554 public function getTemplateUUID($template) {
555 $uuid=$this->getRequest("Template>".$template);
556 if(!$uuid) {
557 $uuid="s".md5($template."-".gmdate("Ymd"));
558 $this->setRequest("Template>".$template, $uuid);
559 }
560 return $uuid;
561 }
562 }