Version Description
Release Date - 2021-05-20
- IWP-178 Additonal refactoring
- IWP-188 make "FAQ & Docs" tab open in new browser tab
Download this release
Release Info
Developer | IntellyWP |
Plugin | Inline Related Posts |
Version | 3.0.4 |
Comparing to | |
See all releases |
Code changes from version 3.0.2 to 3.0.4
- assets/css/style.css +162 -162
- assets/js/button-mce.js +44 -44
- includes/actions.php +22 -95
- includes/admin/button-mce.php +134 -134
- includes/admin/settings.php +437 -437
- includes/classes/html/HTMLContext.php +563 -563
- includes/classes/ui/Form.php +457 -457
- includes/classes/ui/Tabs.php +243 -234
- includes/core.php +334 -334
- index.php +2 -2
- languages/Lang.txt +201 -201
- readme.txt +12 -0
assets/css/style.css
CHANGED
@@ -1,163 +1,163 @@
|
|
1 |
-
._irp {
|
2 |
-
background-color: #efc439;
|
3 |
-
border-radius: 2px;
|
4 |
-
color: #fff;
|
5 |
-
display: inline-block;
|
6 |
-
font-size: 12px;
|
7 |
-
padding: 0 2px;
|
8 |
-
line-height: 14px;
|
9 |
-
vertical-align: baseline;
|
10 |
-
}
|
11 |
-
|
12 |
-
.irp-tag {
|
13 |
-
display: inline-block;
|
14 |
-
line-height: 13px;
|
15 |
-
padding: 0 3px;
|
16 |
-
color: white;
|
17 |
-
font-size: 10px;
|
18 |
-
font-weight: normal;
|
19 |
-
width:25px;
|
20 |
-
margin-top:3px;
|
21 |
-
margin-right:5px;
|
22 |
-
text-align:center;
|
23 |
-
-webkit-border-radius: 2px;
|
24 |
-
border-radius: 2px;
|
25 |
-
vertical-align: baseline;
|
26 |
-
}
|
27 |
-
.irp-tag-free {
|
28 |
-
/*background-color: #edb802;*/
|
29 |
-
background-color: #16a765;
|
30 |
-
}
|
31 |
-
.irp-tag-premium {
|
32 |
-
/*background-color: #edb802;*/
|
33 |
-
background-color: #4986e7;
|
34 |
-
opacity: 0.7;
|
35 |
-
filter: alpha(opacity=70);
|
36 |
-
}
|
37 |
-
.irp-tag-premium a {
|
38 |
-
color:white;
|
39 |
-
text-decoration:none;
|
40 |
-
}
|
41 |
-
.irp-button {
|
42 |
-
margin-right:5px!important;
|
43 |
-
}
|
44 |
-
|
45 |
-
.irp-textarea {
|
46 |
-
font-family:"Courier New", Courier, mono;
|
47 |
-
font-size:12px;
|
48 |
-
color:#555;
|
49 |
-
background-color:#f8f8f8;
|
50 |
-
width:550px;
|
51 |
-
height:350px;
|
52 |
-
}
|
53 |
-
|
54 |
-
.irp-form {
|
55 |
-
float:left;
|
56 |
-
padding:5px;
|
57 |
-
}
|
58 |
-
.irp-form input, .irp-form label {
|
59 |
-
float:left;
|
60 |
-
}
|
61 |
-
.irp-text {
|
62 |
-
width: 400px;
|
63 |
-
}
|
64 |
-
.irp-label {
|
65 |
-
width: 200px;
|
66 |
-
margin: 0px;
|
67 |
-
background-color: transparent;
|
68 |
-
}
|
69 |
-
.irp-label-disabled {
|
70 |
-
/*color:#A8A8A8;*/
|
71 |
-
opacity: 0.7;
|
72 |
-
filter: alpha(opacity=70);
|
73 |
-
}
|
74 |
-
.irp-checkbox {
|
75 |
-
margin:0px;
|
76 |
-
}
|
77 |
-
.irp-checkbox:disabled {
|
78 |
-
background-color: #f8f8f8;
|
79 |
-
}
|
80 |
-
.irp-select {
|
81 |
-
|
82 |
-
}
|
83 |
-
.irp-form-newline {
|
84 |
-
clear:both;
|
85 |
-
margin-bottom:5px;
|
86 |
-
}
|
87 |
-
|
88 |
-
img.irp-help {
|
89 |
-
cursor: pointer;
|
90 |
-
float: left;
|
91 |
-
margin-right: 10px;
|
92 |
-
}
|
93 |
-
|
94 |
-
.irp-qtip {
|
95 |
-
font-size: 14px !important;
|
96 |
-
line-height: 18px !important;
|
97 |
-
}
|
98 |
-
|
99 |
-
i.mce-i-icon {
|
100 |
-
font: 400 20px/1 dashicons;
|
101 |
-
padding: 0;
|
102 |
-
vertical-align: top;
|
103 |
-
speak: none;
|
104 |
-
-webkit-font-smoothing: antialiased;
|
105 |
-
-moz-osx-font-smoothing: grayscale;
|
106 |
-
margin-left: -2px;
|
107 |
-
padding-right: 2px
|
108 |
-
}
|
109 |
-
|
110 |
-
i.irp-own-icon {
|
111 |
-
background-image: url('../images/repeat.png');
|
112 |
-
}
|
113 |
-
|
114 |
-
.irp-box-error {
|
115 |
-
background: #fff;
|
116 |
-
border-left: 4px solid #dd3d36;
|
117 |
-
margin: 5px 0 15px;
|
118 |
-
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
119 |
-
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
120 |
-
padding: 1px 12px;
|
121 |
-
}
|
122 |
-
.irp-box-warning {
|
123 |
-
background: #fff;
|
124 |
-
border-left: 4px solid #ffba00;
|
125 |
-
margin: 5px 0 15px;
|
126 |
-
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
127 |
-
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
128 |
-
padding: 1px 12px;
|
129 |
-
}
|
130 |
-
.irp-box-success {
|
131 |
-
background: #fff;
|
132 |
-
border-left: 4px solid #7ad03a;
|
133 |
-
margin: 5px 0 15px;
|
134 |
-
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
135 |
-
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
136 |
-
padding: 1px 12px;
|
137 |
-
}
|
138 |
-
.irp-box-info {
|
139 |
-
background: #fff;
|
140 |
-
border-left: 4px solid #00a0d2;
|
141 |
-
margin: 5px 0 15px;
|
142 |
-
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
143 |
-
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
144 |
-
padding: 1px 12px;
|
145 |
-
}
|
146 |
-
|
147 |
-
.select2-chosen .irpColorSelectItem {
|
148 |
-
padding-bottom:0px!important;
|
149 |
-
padding-top:0px!important;
|
150 |
-
}
|
151 |
-
.irpColorSelectItem {
|
152 |
-
padding: 5px;
|
153 |
-
width: 100%;
|
154 |
-
}
|
155 |
-
|
156 |
-
#irp-sidebar li {
|
157 |
-
margin: 0px!important;
|
158 |
-
margin-left: 20px!important;;
|
159 |
-
}
|
160 |
-
.irp-plugin-widget {
|
161 |
-
padding: 10px;
|
162 |
-
border: 2px dashed red;
|
163 |
Â
}
|
1 |
+
._irp {
|
2 |
+
background-color: #efc439;
|
3 |
+
border-radius: 2px;
|
4 |
+
color: #fff;
|
5 |
+
display: inline-block;
|
6 |
+
font-size: 12px;
|
7 |
+
padding: 0 2px;
|
8 |
+
line-height: 14px;
|
9 |
+
vertical-align: baseline;
|
10 |
+
}
|
11 |
+
|
12 |
+
.irp-tag {
|
13 |
+
display: inline-block;
|
14 |
+
line-height: 13px;
|
15 |
+
padding: 0 3px;
|
16 |
+
color: white;
|
17 |
+
font-size: 10px;
|
18 |
+
font-weight: normal;
|
19 |
+
width:25px;
|
20 |
+
margin-top:3px;
|
21 |
+
margin-right:5px;
|
22 |
+
text-align:center;
|
23 |
+
-webkit-border-radius: 2px;
|
24 |
+
border-radius: 2px;
|
25 |
+
vertical-align: baseline;
|
26 |
+
}
|
27 |
+
.irp-tag-free {
|
28 |
+
/*background-color: #edb802;*/
|
29 |
+
background-color: #16a765;
|
30 |
+
}
|
31 |
+
.irp-tag-premium {
|
32 |
+
/*background-color: #edb802;*/
|
33 |
+
background-color: #4986e7;
|
34 |
+
opacity: 0.7;
|
35 |
+
filter: alpha(opacity=70);
|
36 |
+
}
|
37 |
+
.irp-tag-premium a {
|
38 |
+
color:white;
|
39 |
+
text-decoration:none;
|
40 |
+
}
|
41 |
+
.irp-button {
|
42 |
+
margin-right:5px!important;
|
43 |
+
}
|
44 |
+
|
45 |
+
.irp-textarea {
|
46 |
+
font-family:"Courier New", Courier, mono;
|
47 |
+
font-size:12px;
|
48 |
+
color:#555;
|
49 |
+
background-color:#f8f8f8;
|
50 |
+
width:550px;
|
51 |
+
height:350px;
|
52 |
+
}
|
53 |
+
|
54 |
+
.irp-form {
|
55 |
+
float:left;
|
56 |
+
padding:5px;
|
57 |
+
}
|
58 |
+
.irp-form input, .irp-form label {
|
59 |
+
float:left;
|
60 |
+
}
|
61 |
+
.irp-text {
|
62 |
+
width: 400px;
|
63 |
+
}
|
64 |
+
.irp-label {
|
65 |
+
width: 200px;
|
66 |
+
margin: 0px;
|
67 |
+
background-color: transparent;
|
68 |
+
}
|
69 |
+
.irp-label-disabled {
|
70 |
+
/*color:#A8A8A8;*/
|
71 |
+
opacity: 0.7;
|
72 |
+
filter: alpha(opacity=70);
|
73 |
+
}
|
74 |
+
.irp-checkbox {
|
75 |
+
margin:0px;
|
76 |
+
}
|
77 |
+
.irp-checkbox:disabled {
|
78 |
+
background-color: #f8f8f8;
|
79 |
+
}
|
80 |
+
.irp-select {
|
81 |
+
|
82 |
+
}
|
83 |
+
.irp-form-newline {
|
84 |
+
clear:both;
|
85 |
+
margin-bottom:5px;
|
86 |
+
}
|
87 |
+
|
88 |
+
img.irp-help {
|
89 |
+
cursor: pointer;
|
90 |
+
float: left;
|
91 |
+
margin-right: 10px;
|
92 |
+
}
|
93 |
+
|
94 |
+
.irp-qtip {
|
95 |
+
font-size: 14px !important;
|
96 |
+
line-height: 18px !important;
|
97 |
+
}
|
98 |
+
|
99 |
+
i.mce-i-icon {
|
100 |
+
font: 400 20px/1 dashicons;
|
101 |
+
padding: 0;
|
102 |
+
vertical-align: top;
|
103 |
+
speak: none;
|
104 |
+
-webkit-font-smoothing: antialiased;
|
105 |
+
-moz-osx-font-smoothing: grayscale;
|
106 |
+
margin-left: -2px;
|
107 |
+
padding-right: 2px
|
108 |
+
}
|
109 |
+
|
110 |
+
i.irp-own-icon {
|
111 |
+
background-image: url('../images/repeat.png');
|
112 |
+
}
|
113 |
+
|
114 |
+
.irp-box-error {
|
115 |
+
background: #fff;
|
116 |
+
border-left: 4px solid #dd3d36;
|
117 |
+
margin: 5px 0 15px;
|
118 |
+
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
119 |
+
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
120 |
+
padding: 1px 12px;
|
121 |
+
}
|
122 |
+
.irp-box-warning {
|
123 |
+
background: #fff;
|
124 |
+
border-left: 4px solid #ffba00;
|
125 |
+
margin: 5px 0 15px;
|
126 |
+
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
127 |
+
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
128 |
+
padding: 1px 12px;
|
129 |
+
}
|
130 |
+
.irp-box-success {
|
131 |
+
background: #fff;
|
132 |
+
border-left: 4px solid #7ad03a;
|
133 |
+
margin: 5px 0 15px;
|
134 |
+
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
135 |
+
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
136 |
+
padding: 1px 12px;
|
137 |
+
}
|
138 |
+
.irp-box-info {
|
139 |
+
background: #fff;
|
140 |
+
border-left: 4px solid #00a0d2;
|
141 |
+
margin: 5px 0 15px;
|
142 |
+
-webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
143 |
+
box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
|
144 |
+
padding: 1px 12px;
|
145 |
+
}
|
146 |
+
|
147 |
+
.select2-chosen .irpColorSelectItem {
|
148 |
+
padding-bottom:0px!important;
|
149 |
+
padding-top:0px!important;
|
150 |
+
}
|
151 |
+
.irpColorSelectItem {
|
152 |
+
padding: 5px;
|
153 |
+
width: 100%;
|
154 |
+
}
|
155 |
+
|
156 |
+
#irp-sidebar li {
|
157 |
+
margin: 0px!important;
|
158 |
+
margin-left: 20px!important;;
|
159 |
+
}
|
160 |
+
.irp-plugin-widget {
|
161 |
+
padding: 10px;
|
162 |
+
border: 2px dashed red;
|
163 |
Â
}
|
assets/js/button-mce.js
CHANGED
@@ -1,45 +1,45 @@
|
|
1 |
-
(function() {
|
2 |
-
tinymce.PluginManager.add('irp_mce_button', function(editor, url) {
|
3 |
-
editor.addButton('irp_mce_button', {
|
4 |
-
title: 'Inline Related Posts PRO'
|
5 |
-
, type: 'menubutton'
|
6 |
-
, icon: 'icon irp-own-icon'
|
7 |
-
, image : url + '/../images/repeat.png'
|
8 |
-
, menu: [
|
9 |
-
{
|
10 |
-
text: 'Inline Related Post'
|
11 |
-
, onclick: function() {
|
12 |
-
var code='[irp]';
|
13 |
-
editor.insertContent(code);
|
14 |
-
}
|
15 |
-
}
|
16 |
-
, {
|
17 |
-
text: 'Custom Related Post'
|
18 |
-
, onclick: function() {
|
19 |
-
editor.windowManager.open({
|
20 |
-
title: 'Choose a post'
|
21 |
-
, width: 350
|
22 |
-
, height: 250
|
23 |
-
, file: ajaxurl+'?action=do_action&irp_action=ui_button_editor&irp_post_type=post'
|
24 |
-
, inline: 1
|
25 |
-
, resizable: false
|
26 |
-
});
|
27 |
-
}
|
28 |
-
}
|
29 |
-
, {
|
30 |
-
text: 'Custom Related Page'
|
31 |
-
, onclick: function() {
|
32 |
-
editor.windowManager.open({
|
33 |
-
title: 'Choose a page'
|
34 |
-
, width: 350
|
35 |
-
, height: 250
|
36 |
-
, file: ajaxurl+'?action=do_action&irp_action=ui_button_editor&irp_post_type=page'
|
37 |
-
, inline: 1
|
38 |
-
, resizable: false
|
39 |
-
});
|
40 |
-
}
|
41 |
-
}
|
42 |
-
]
|
43 |
-
});
|
44 |
-
});
|
45 |
Â
})();
|
1 |
+
(function() {
|
2 |
+
tinymce.PluginManager.add('irp_mce_button', function(editor, url) {
|
3 |
+
editor.addButton('irp_mce_button', {
|
4 |
+
title: 'Inline Related Posts PRO'
|
5 |
+
, type: 'menubutton'
|
6 |
+
, icon: 'icon irp-own-icon'
|
7 |
+
, image : url + '/../images/repeat.png'
|
8 |
+
, menu: [
|
9 |
+
{
|
10 |
+
text: 'Inline Related Post'
|
11 |
+
, onclick: function() {
|
12 |
+
var code='[irp]';
|
13 |
+
editor.insertContent(code);
|
14 |
+
}
|
15 |
+
}
|
16 |
+
, {
|
17 |
+
text: 'Custom Related Post'
|
18 |
+
, onclick: function() {
|
19 |
+
editor.windowManager.open({
|
20 |
+
title: 'Choose a post'
|
21 |
+
, width: 350
|
22 |
+
, height: 250
|
23 |
+
, file: ajaxurl+'?action=do_action&irp_action=ui_button_editor&irp_post_type=post'
|
24 |
+
, inline: 1
|
25 |
+
, resizable: false
|
26 |
+
});
|
27 |
+
}
|
28 |
+
}
|
29 |
+
, {
|
30 |
+
text: 'Custom Related Page'
|
31 |
+
, onclick: function() {
|
32 |
+
editor.windowManager.open({
|
33 |
+
title: 'Choose a page'
|
34 |
+
, width: 350
|
35 |
+
, height: 250
|
36 |
+
, file: ajaxurl+'?action=do_action&irp_action=ui_button_editor&irp_post_type=page'
|
37 |
+
, inline: 1
|
38 |
+
, resizable: false
|
39 |
+
});
|
40 |
+
}
|
41 |
+
}
|
42 |
+
]
|
43 |
+
});
|
44 |
+
});
|
45 |
Â
})();
|
includes/actions.php
CHANGED
@@ -1,31 +1,14 @@
|
|
1 |
Â
<?php
|
2 |
-
/**
|
3 |
-
* Front-end Actions
|
4 |
-
*
|
5 |
-
* @package EDD
|
6 |
-
* @subpackage Functions
|
7 |
-
* @copyright Copyright (c) 2015, Pippin Williamson
|
8 |
-
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
9 |
-
* @since 1.0.8.1
|
10 |
-
*/
|
11 |
-
|
12 |
Â
// Exit if accessed directly
|
13 |
Â
if ( ! defined( 'ABSPATH' ) ) exit;
|
14 |
Â
|
15 |
-
/**
|
16 |
-
* Hooks EDD actions, when present in the $_GET superglobal. Every edd_action
|
17 |
-
* present in $_GET is called using WordPress's do_action function. These
|
18 |
-
* functions are called on init.
|
19 |
-
*
|
20 |
-
* @since 1.0
|
21 |
-
* @return void
|
22 |
-
*/
|
23 |
Â
add_action('init', 'irp_do_action');
|
24 |
Â
add_action('wp_ajax_do_action', 'irp_do_action');
|
25 |
Â
function irp_do_action() {
|
26 |
Â
global $irp;
|
27 |
Â
|
28 |
Â
$action = $irp->Utils->qs('irp_action');
|
Â
|
|
29 |
Â
switch($action) {
|
30 |
Â
case 'ui_button_editor':
|
31 |
Â
call_irp_ui_button_editor($irp);
|
@@ -47,94 +30,38 @@ function irp_do_action() {
|
|
47 |
Â
}
|
48 |
Â
}
|
49 |
Â
|
50 |
-
function call_irp_ui_button_editor($irp)
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
59 |
Â
}
|
60 |
Â
|
61 |
Â
function call_irp_ui_box_preview($irp)
|
62 |
Â
{
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
//}
|
67 |
-
//else {
|
68 |
-
// Replace this with an actual function call
|
69 |
-
irp_find_and_call_func($irp, 'ui_box_preview');
|
70 |
-
//}
|
71 |
Â
}
|
72 |
Â
|
73 |
Â
function call_irp_manager_trackingOn($irp)
|
74 |
Â
{
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
//}
|
79 |
-
//else {
|
80 |
-
// Replace this with an actual function call
|
81 |
-
irp_find_and_call_func($irp, 'manager_trackingOn');
|
82 |
-
//}
|
83 |
Â
}
|
84 |
Â
|
85 |
Â
function call_irp_manager_trackingOff($irp)
|
86 |
Â
{
|
87 |
-
|
88 |
-
|
89 |
-
// $irp->Log->info('Rejected Non-admin call of irp_do_action().');
|
90 |
-
//}
|
91 |
-
//else {
|
92 |
-
// Replace this with an actual function call
|
93 |
-
irp_find_and_call_func($irp, 'manager_trackingOff');
|
94 |
-
//}
|
95 |
-
}
|
96 |
-
|
97 |
-
// Phase one of removing the irp_do_action
|
98 |
-
function irp_find_and_call_func($irp, $action)
|
99 |
-
{
|
100 |
-
$args=array_merge($_GET, $_POST, $_COOKIE, $_SERVER);
|
101 |
-
$name='irp_'.$action;
|
102 |
-
|
103 |
-
if(has_action($name)) {
|
104 |
-
$irp->Log->debug('EXECUTING ACTION=%s', $name);
|
105 |
-
do_action($name, $args);
|
106 |
-
} elseif(function_exists($name)) {
|
107 |
-
$irp->Log->debug('EXECUTING FUNCTION=%s DATA=%s', $name, $args);
|
108 |
-
call_user_func($name, $args);
|
109 |
-
} elseif(strpos($action, '_')!==FALSE) {
|
110 |
-
$pos=strpos($action, '_');
|
111 |
-
$what=substr($action, 0, $pos);
|
112 |
-
$function=substr($action, $pos+1);
|
113 |
-
|
114 |
-
$class=NULL;
|
115 |
-
switch (strtolower($what)) {
|
116 |
-
case 'cron':
|
117 |
-
$class=$irp->Cron;
|
118 |
-
break;
|
119 |
-
case 'tracking':
|
120 |
-
$class=$irp->Tracking;
|
121 |
-
break;
|
122 |
-
case 'properties':
|
123 |
-
$class=$irp->Options;
|
124 |
-
break;
|
125 |
-
}
|
126 |
-
|
127 |
-
if(!$class) {
|
128 |
-
$irp->Log->fatal('NO CLASS FOR=%s IN ACTION=%s', $what, $action);
|
129 |
-
} elseif(!method_exists ($class, $function)) {
|
130 |
-
$irp->Log->fatal('NO METHOD FOR=%s IN CLASS=%s IN ACTION=%s', $function, $what, $action);
|
131 |
-
} else {
|
132 |
-
$irp->Log->debug('METHOD=%s OF CLASS=%s', $function, $what);
|
133 |
-
call_user_func(array($class, $function), $args);
|
134 |
-
}
|
135 |
-
} else {
|
136 |
-
$irp->Log->fatal('NO FUNCTION FOR==%s', $action);
|
137 |
Â
}
|
138 |
Â
}
|
139 |
-
|
140 |
-
?>
|
1 |
Â
<?php
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
2 |
Â
// Exit if accessed directly
|
3 |
Â
if ( ! defined( 'ABSPATH' ) ) exit;
|
4 |
Â
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
5 |
Â
add_action('init', 'irp_do_action');
|
6 |
Â
add_action('wp_ajax_do_action', 'irp_do_action');
|
7 |
Â
function irp_do_action() {
|
8 |
Â
global $irp;
|
9 |
Â
|
10 |
Â
$action = $irp->Utils->qs('irp_action');
|
11 |
+
$irp->Log->info('[actions::irp_do_action] Action: %s', $action);
|
12 |
Â
switch($action) {
|
13 |
Â
case 'ui_button_editor':
|
14 |
Â
call_irp_ui_button_editor($irp);
|
30 |
Â
}
|
31 |
Â
}
|
32 |
Â
|
33 |
+
function call_irp_ui_button_editor($irp)
|
34 |
+
{
|
35 |
+
if (current_user_can('edit_posts')
|
36 |
+
|| current_user_can('edit_pages')
|
37 |
+
|| current_user_can('edit_published_posts')
|
38 |
+
|| current_user_can('edit_published_pages')
|
39 |
+
|| current_user_can('edit_others_posts')
|
40 |
+
|| current_user_can('edit_others_pages')
|
41 |
+
|| current_user_can('edit_private_posts')
|
42 |
+
|| current_user_can('edit_private_pages')
|
43 |
+
) {
|
44 |
+
irp_ui_button_editor();
|
45 |
+
}
|
46 |
Â
}
|
47 |
Â
|
48 |
Â
function call_irp_ui_box_preview($irp)
|
49 |
Â
{
|
50 |
+
if (current_user_can('activate_plugins')) {
|
51 |
+
irp_ui_box_preview();
|
52 |
+
}
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
53 |
Â
}
|
54 |
Â
|
55 |
Â
function call_irp_manager_trackingOn($irp)
|
56 |
Â
{
|
57 |
+
if (current_user_can('activate_plugins')) {
|
58 |
+
$irp->Tracking->enableTracking();
|
59 |
+
}
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
60 |
Â
}
|
61 |
Â
|
62 |
Â
function call_irp_manager_trackingOff($irp)
|
63 |
Â
{
|
64 |
+
if (current_user_can('activate_plugins')) {
|
65 |
+
$irp->Tracking->disableTracking();
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
Â
|
|
66 |
Â
}
|
67 |
Â
}
|
Â
|
|
Â
|
includes/admin/button-mce.php
CHANGED
@@ -1,134 +1,134 @@
|
|
1 |
-
<?php
|
2 |
-
add_action('admin_head', 'irp_add_mce_button');
|
3 |
-
function irp_add_mce_button() {
|
4 |
-
global $typenow;
|
5 |
-
|
6 |
-
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
|
7 |
-
return;
|
8 |
-
}
|
9 |
-
|
10 |
-
if(!in_array($typenow, array('post', 'page'))) {
|
11 |
-
return;
|
12 |
-
}
|
13 |
-
if (get_user_option('rich_editing') == 'true') {
|
14 |
-
add_filter("mce_external_plugins", "irp_add_mce_plugin");
|
15 |
-
add_filter('mce_buttons', 'irp_register_mce_button');
|
16 |
-
}
|
17 |
-
}
|
18 |
-
|
19 |
-
function irp_add_mce_plugin($plugin_array) {
|
20 |
-
$plugin_array['irp_mce_button']=IRP_PLUGIN_ASSETS.'js/button-mce.js';
|
21 |
-
return $plugin_array;
|
22 |
-
}
|
23 |
-
function irp_register_mce_button($buttons) {
|
24 |
-
array_push($buttons, "irp_mce_button");
|
25 |
-
return $buttons;
|
26 |
-
}
|
27 |
-
|
28 |
-
function irp_ui_button_editor() {
|
29 |
-
global $irp;
|
30 |
-
|
31 |
-
$irp->Utils->printScriptCss();
|
32 |
-
$irp->Form->prefix='Editor';
|
33 |
-
$irp->Form->labels=FALSE;
|
34 |
-
|
35 |
-
$args=array('class'=>'wp-admin wp-core-ui admin-bar'
|
36 |
-
, 'style'=>'padding:10px; margin-left:auto; margin-right:auto;');
|
37 |
-
$irp->Form->formStarts('post', '', $args);
|
38 |
-
{
|
39 |
-
?>
|
40 |
-
<p style="text-align:center;"><?php $irp->Lang->P('EditorSubtitle') ?></p>
|
41 |
-
<?php
|
42 |
-
$args = array('post_type' => 'post', 'all' => FALSE);
|
43 |
-
$options = $irp->Utils->query(IRP_QUERY_POSTS_OF_TYPE, $args);
|
44 |
-
$irp->Form->text('irpPostId', '', FALSE);
|
45 |
-
?>
|
46 |
-
<div style="clear:both;"></div>
|
47 |
-
<p style="text-align:right;">
|
48 |
-
<input type="button" id="btnInsert" class="button button-primary irp-button irp-submit" value="<?php $irp->Lang->P('Insert')?>"/>
|
49 |
-
<input type="button" id="btnClose" class="button irp-button" value="<?php $irp->Lang->P('Cancel')?>"/>
|
50 |
-
</p>
|
51 |
-
|
52 |
-
<script>
|
53 |
-
jQuery(function () {
|
54 |
-
jQuery('#btnInsert').click(function () {
|
55 |
-
var editor = top.tinymce.activeEditor;
|
56 |
-
var postId = parseInt(jQuery('#irpPostId').val());
|
57 |
-
var name=jQuery('#select2-chosen-1').text().replace('"', ' ');
|
58 |
-
if(name) {
|
59 |
-
name='name="'+name+'"';
|
60 |
-
}
|
61 |
-
if (postId > 0) {
|
62 |
-
var code = '[irp posts="' + postId + '" '+name+']';
|
63 |
-
editor.insertContent(code);
|
64 |
-
}
|
65 |
-
editor.windowManager.close();
|
66 |
-
});
|
67 |
-
jQuery('#btnClose').click(function () {
|
68 |
-
var editor = top.tinymce.activeEditor;
|
69 |
-
editor.windowManager.close();
|
70 |
-
});
|
71 |
-
/*
|
72 |
-
jQuery("#irpPostId").select2({
|
73 |
-
placeholder: "Type here..."
|
74 |
-
, theme: "classic"
|
75 |
-
, width: '100%'
|
76 |
-
//, maximumSelectionLength: 3
|
77 |
-
});
|
78 |
-
*/
|
79 |
-
var ajaxurl = 'admin-ajax.php';
|
80 |
-
jQuery('#irpPostId').select2({
|
81 |
-
|
82 |
-
ajax: {
|
83 |
-
|
84 |
-
url: ajaxurl,
|
85 |
-
dataType: 'json',
|
86 |
-
|
87 |
-
delay: 250,
|
88 |
-
|
89 |
-
data: function (term, page) {
|
90 |
-
|
91 |
-
return {
|
92 |
-
action: 'irp_list_posts',
|
93 |
-
irp_post_type: '<?php echo esc_attr($_REQUEST['irp_post_type']);?>',
|
94 |
-
q: term,
|
95 |
-
page: page
|
96 |
-
};
|
97 |
-
|
98 |
-
},
|
99 |
-
|
100 |
-
results: function (data, page) {
|
101 |
-
|
102 |
-
page = page || 1;
|
103 |
-
|
104 |
-
return {
|
105 |
-
results: data.items,
|
106 |
-
more: false,
|
107 |
-
};
|
108 |
-
|
109 |
-
},
|
110 |
-
|
111 |
-
cache: true
|
112 |
-
|
113 |
-
},
|
114 |
-
|
115 |
-
placeholder: "Type here to search an item...",
|
116 |
-
minimumInputLength: 3,
|
117 |
-
width: '100%'
|
118 |
-
|
119 |
-
});
|
120 |
-
});
|
121 |
-
</script>
|
122 |
-
|
123 |
-
<style>
|
124 |
-
.select2-results {
|
125 |
-
max-height: 100px;
|
126 |
-
overflow-y: auto;
|
127 |
-
}
|
128 |
-
</style>
|
129 |
-
<?php
|
130 |
-
}
|
131 |
-
$irp->Form->formEnds();
|
132 |
-
exit;
|
133 |
-
}
|
134 |
-
|
1 |
+
<?php
|
2 |
+
add_action('admin_head', 'irp_add_mce_button');
|
3 |
+
function irp_add_mce_button() {
|
4 |
+
global $typenow;
|
5 |
+
|
6 |
+
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
|
7 |
+
return;
|
8 |
+
}
|
9 |
+
|
10 |
+
if(!in_array($typenow, array('post', 'page'))) {
|
11 |
+
return;
|
12 |
+
}
|
13 |
+
if (get_user_option('rich_editing') == 'true') {
|
14 |
+
add_filter("mce_external_plugins", "irp_add_mce_plugin");
|
15 |
+
add_filter('mce_buttons', 'irp_register_mce_button');
|
16 |
+
}
|
17 |
+
}
|
18 |
+
|
19 |
+
function irp_add_mce_plugin($plugin_array) {
|
20 |
+
$plugin_array['irp_mce_button']=IRP_PLUGIN_ASSETS.'js/button-mce.js';
|
21 |
+
return $plugin_array;
|
22 |
+
}
|
23 |
+
function irp_register_mce_button($buttons) {
|
24 |
+
array_push($buttons, "irp_mce_button");
|
25 |
+
return $buttons;
|
26 |
+
}
|
27 |
+
|
28 |
+
function irp_ui_button_editor() {
|
29 |
+
global $irp;
|
30 |
+
|
31 |
+
$irp->Utils->printScriptCss();
|
32 |
+
$irp->Form->prefix='Editor';
|
33 |
+
$irp->Form->labels=FALSE;
|
34 |
+
|
35 |
+
$args=array('class'=>'wp-admin wp-core-ui admin-bar'
|
36 |
+
, 'style'=>'padding:10px; margin-left:auto; margin-right:auto;');
|
37 |
+
$irp->Form->formStarts('post', '', $args);
|
38 |
+
{
|
39 |
+
?>
|
40 |
+
<p style="text-align:center;"><?php $irp->Lang->P('EditorSubtitle') ?></p>
|
41 |
+
<?php
|
42 |
+
$args = array('post_type' => 'post', 'all' => FALSE);
|
43 |
+
$options = $irp->Utils->query(IRP_QUERY_POSTS_OF_TYPE, $args);
|
44 |
+
$irp->Form->text('irpPostId', '', FALSE);
|
45 |
+
?>
|
46 |
+
<div style="clear:both;"></div>
|
47 |
+
<p style="text-align:right;">
|
48 |
+
<input type="button" id="btnInsert" class="button button-primary irp-button irp-submit" value="<?php $irp->Lang->P('Insert')?>"/>
|
49 |
+
<input type="button" id="btnClose" class="button irp-button" value="<?php $irp->Lang->P('Cancel')?>"/>
|
50 |
+
</p>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
jQuery(function () {
|
54 |
+
jQuery('#btnInsert').click(function () {
|
55 |
+
var editor = top.tinymce.activeEditor;
|
56 |
+
var postId = parseInt(jQuery('#irpPostId').val());
|
57 |
+
var name=jQuery('#select2-chosen-1').text().replace('"', ' ');
|
58 |
+
if(name) {
|
59 |
+
name='name="'+name+'"';
|
60 |
+
}
|
61 |
+
if (postId > 0) {
|
62 |
+
var code = '[irp posts="' + postId + '" '+name+']';
|
63 |
+
editor.insertContent(code);
|
64 |
+
}
|
65 |
+
editor.windowManager.close();
|
66 |
+
});
|
67 |
+
jQuery('#btnClose').click(function () {
|
68 |
+
var editor = top.tinymce.activeEditor;
|
69 |
+
editor.windowManager.close();
|
70 |
+
});
|
71 |
+
/*
|
72 |
+
jQuery("#irpPostId").select2({
|
73 |
+
placeholder: "Type here..."
|
74 |
+
, theme: "classic"
|
75 |
+
, width: '100%'
|
76 |
+
//, maximumSelectionLength: 3
|
77 |
+
});
|
78 |
+
*/
|
79 |
+
var ajaxurl = 'admin-ajax.php';
|
80 |
+
jQuery('#irpPostId').select2({
|
81 |
+
|
82 |
+
ajax: {
|
83 |
+
|
84 |
+
url: ajaxurl,
|
85 |
+
dataType: 'json',
|
86 |
+
|
87 |
+
delay: 250,
|
88 |
+
|
89 |
+
data: function (term, page) {
|
90 |
+
|
91 |
+
return {
|
92 |
+
action: 'irp_list_posts',
|
93 |
+
irp_post_type: '<?php echo esc_attr($_REQUEST['irp_post_type']);?>',
|
94 |
+
q: term,
|
95 |
+
page: page
|
96 |
+
};
|
97 |
+
|
98 |
+
},
|
99 |
+
|
100 |
+
results: function (data, page) {
|
101 |
+
|
102 |
+
page = page || 1;
|
103 |
+
|
104 |
+
return {
|
105 |
+
results: data.items,
|
106 |
+
more: false,
|
107 |
+
};
|
108 |
+
|
109 |
+
},
|
110 |
+
|
111 |
+
cache: true
|
112 |
+
|
113 |
+
},
|
114 |
+
|
115 |
+
placeholder: "Type here to search an item...",
|
116 |
+
minimumInputLength: 3,
|
117 |
+
width: '100%'
|
118 |
+
|
119 |
+
});
|
120 |
+
});
|
121 |
+
</script>
|
122 |
+
|
123 |
+
<style>
|
124 |
+
.select2-results {
|
125 |
+
max-height: 100px;
|
126 |
+
overflow-y: auto;
|
127 |
+
}
|
128 |
+
</style>
|
129 |
+
<?php
|
130 |
+
}
|
131 |
+
$irp->Form->formEnds();
|
132 |
+
exit;
|
133 |
+
}
|
134 |
+
|
includes/admin/settings.php
CHANGED
@@ -1,437 +1,437 @@
|
|
1 |
-
<?php
|
2 |
-
function irp_ui_tracking($override=FALSE) {
|
3 |
-
global $irp;
|
4 |
-
|
5 |
-
$track=$irp->Utils->qs('track', '');
|
6 |
-
if($track!='') {
|
7 |
-
$track=intval($track);
|
8 |
-
$irp->Options->setTrackingEnable($track);
|
9 |
-
$irp->Tracking->sendTracking(TRUE);
|
10 |
-
}
|
11 |
-
|
12 |
-
$uri=IRP_TAB_SETTINGS_URI.'&track=';
|
13 |
-
if($irp->Options->isTrackingEnable()) {
|
14 |
-
if($override) {
|
15 |
-
$uri.='0';
|
16 |
-
$irp->Options->pushSuccessMessage('EnableAllowTrackingNotice', $uri);
|
17 |
-
}
|
18 |
-
} else {
|
19 |
-
$uri.='1';
|
20 |
-
$irp->Options->pushWarningMessage('DisableAllowTrackingNotice', $uri);
|
21 |
-
}
|
22 |
-
$irp->Options->writeMessages();
|
23 |
-
}
|
24 |
-
function irp_io_first_time() {
|
25 |
-
global $irp;
|
26 |
-
if($irp->Options->isShowActivationNotice()) {
|
27 |
-
$irp->Options->pushSuccessMessage('FirstTimeActivation');
|
28 |
-
$irp->Options->writeMessages();
|
29 |
-
$irp->Options->setShowActivationNotice(FALSE);
|
30 |
-
}
|
31 |
-
}
|
32 |
-
function irp_ui_box_preview() {
|
33 |
-
global $irp;
|
34 |
-
|
35 |
-
$count=$irp->Options->getRewritePostsInBoxCount();
|
36 |
-
$count=$irp->Utils->iqs('rewritePostsInBoxCount', $count);
|
37 |
-
$args=array(
|
38 |
-
'orderby'=>'rand'
|
39 |
-
, 'numberposts'=>$count
|
40 |
-
);
|
41 |
-
|
42 |
-
$days=$irp->Options->getRewritePostsDays();
|
43 |
-
$days=$irp->Utils->iqs('rewritePostsDays', $days);
|
44 |
-
if($days>0) {
|
45 |
-
$args['date_query'] = array(
|
46 |
-
'column' => 'post_date'
|
47 |
-
, 'after' => '- '.$days.' days'
|
48 |
-
);
|
49 |
-
}
|
50 |
-
$posts=get_posts($args);
|
51 |
-
$ids=array();
|
52 |
-
foreach($posts as $p) {
|
53 |
-
$ids[]=$p->ID;
|
54 |
-
}
|
55 |
-
if(count($ids)==0) {
|
56 |
-
echo "<b>No posts available. Check settings and try again</b>";
|
57 |
-
die();
|
58 |
-
}
|
59 |
-
|
60 |
-
$defaults=$irp->Options->getTemplateStyle();
|
61 |
-
$args=$irp->Utils->aqs('template-', $defaults);
|
62 |
-
$args['includeCss']=TRUE;
|
63 |
-
$args['preview']=TRUE;
|
64 |
-
$box=irp_ui_get_box($ids, $args);
|
65 |
-
echo $box;
|
66 |
-
die();
|
67 |
-
}
|
68 |
-
function irp_ui_settings() {
|
69 |
-
global $irp;
|
70 |
-
irp_ui_tracking(FALSE);
|
71 |
-
|
72 |
-
?>
|
73 |
-
<script>
|
74 |
-
var IRP_preview=true;
|
75 |
-
var IRP_labelColor='';
|
76 |
-
var IRP_defaults={};
|
77 |
-
<?php
|
78 |
-
$defaults=$irp->HtmlTemplate->getDefaults();
|
79 |
-
foreach($defaults as $k=>$v) {
|
80 |
-
$buffer='';
|
81 |
-
foreach($v as $kk=>$vv) {
|
82 |
-
if($buffer!='') {
|
83 |
-
$buffer.=', ';
|
84 |
-
}
|
85 |
-
|
86 |
-
if(stripos($kk, 'label')!==FALSE) {
|
87 |
-
$vv=$irp->Lang->L('Settings.Color.'.$vv);
|
88 |
-
} elseif(stripos($kk, 'color')!==FALSE) {
|
89 |
-
$vv=$irp->Options->getColor($vv);
|
90 |
-
}
|
91 |
-
|
92 |
-
$buffer.=$kk.': "'.$vv.'"';
|
93 |
-
}
|
94 |
-
?>
|
95 |
-
IRP_defaults["<?php echo $k?>"]={<?php echo $buffer?>};
|
96 |
-
<?php }
|
97 |
-
?>
|
98 |
-
|
99 |
-
function IRP_changeTheme() {
|
100 |
-
IRP_preview=false;
|
101 |
-
t=IRP_val('template-template');
|
102 |
-
t=IRP_defaults[t];
|
103 |
-
isProTheme=false;
|
104 |
-
console.log(t);
|
105 |
-
jQuery.each(t, function(k,v) {
|
106 |
-
if(IRP_stripos(k, 'color')!==false) {
|
107 |
-
var $k=jQuery('[name=template-'+k+']');
|
108 |
-
$k.select2("val", v);
|
109 |
-
} else if(k=='proTheme') {
|
110 |
-
isProTheme=(v+''.toLowerCase()=='true');
|
111 |
-
}
|
112 |
-
});
|
113 |
-
|
114 |
-
jQuery("[name*='Color']").each(function(i,v) {
|
115 |
-
var $cbo=jQuery(this);
|
116 |
-
$cbo.prop("disabled", isProTheme);
|
117 |
-
$cbo.select2("enable", !isProTheme);
|
118 |
-
});
|
119 |
-
jQuery("[id*='ColorLabel']").each(function(i,v) {
|
120 |
-
var $lbl=jQuery(this);
|
121 |
-
if(IRP_labelColor!='') {
|
122 |
-
IRP_labelColor=$lbl.css('color');
|
123 |
-
}
|
124 |
-
if(isProTheme) {
|
125 |
-
$lbl.css('color', '#ccc');
|
126 |
-
} else {
|
127 |
-
$lbl.css('color', IRP_labelColor);
|
128 |
-
}
|
129 |
-
});
|
130 |
-
jQuery('.irp-submit').prop("disabled", isProTheme);
|
131 |
-
IRP_preview=true;
|
132 |
-
}
|
133 |
-
function IRP_changeRelatedBox() {
|
134 |
-
if(!IRP_preview) {
|
135 |
-
return;
|
136 |
-
}
|
137 |
-
|
138 |
-
var t=IRP_val('template-template');
|
139 |
-
t=IRP_defaults[t].borderColorLabel;
|
140 |
-
jQuery('#template-borderColorLabel').text(t);
|
141 |
-
|
142 |
-
data=IRP_aval('template-');
|
143 |
-
data=jQuery.extend({
|
144 |
-
'action': 'do_action'
|
145 |
-
, 'irp_action': 'ui_box_preview'
|
146 |
-
, 'rewritePostsDays': IRP_val('irpRewritePostsDays')
|
147 |
-
}, data);
|
148 |
-
//console.log(data);
|
149 |
-
|
150 |
-
var request=jQuery.ajax({
|
151 |
-
url: ajaxurl
|
152 |
-
, method: "POST"
|
153 |
-
, data: data
|
154 |
-
, dataType: "html"
|
155 |
-
});
|
156 |
-
|
157 |
-
request.done(function(html) {
|
158 |
-
jQuery("#relatedBoxExample").html(html);
|
159 |
-
});
|
160 |
-
}
|
161 |
-
|
162 |
-
jQuery(function() {
|
163 |
-
IRP_preview=false;
|
164 |
-
var array=['irpRewritePostsDays', 'irpRewritePostsInBoxCount', 'irpRewriteBoxesCount'];
|
165 |
-
for(i=0; i<array.length; i++) {
|
166 |
-
if(jQuery('[name='+array[i]+']').length>0) {
|
167 |
-
jQuery('[name='+array[i]+']').change(function() {
|
168 |
-
IRP_changeRelatedBox();
|
169 |
-
});
|
170 |
-
}
|
171 |
-
}
|
172 |
-
jQuery("[name^='template-']").change(function() {
|
173 |
-
if(!IRP_preview) {
|
174 |
-
return;
|
175 |
-
}
|
176 |
-
|
177 |
-
var $self=jQuery(this);
|
178 |
-
var name=$self.attr('name');
|
179 |
-
if(name=='template-template') {
|
180 |
-
IRP_changeTheme();
|
181 |
-
}
|
182 |
-
IRP_changeRelatedBox();
|
183 |
-
});
|
184 |
-
//IRP_changeTheme();
|
185 |
-
IRP_preview=true;
|
186 |
-
IRP_changeRelatedBox();
|
187 |
-
});
|
188 |
-
</script>
|
189 |
-
<?php
|
190 |
-
|
191 |
-
$irp->Form->prefix='Settings';
|
192 |
-
$irp->Form->helps = FALSE;
|
193 |
-
$irp->Form->formStarts();
|
194 |
-
|
195 |
-
if($irp->Check->nonce('irp_settings')) {
|
196 |
-
|
197 |
-
$irp->Options->resetMaxExecutionTime();
|
198 |
-
$irp->Options->setActive($irp->Utils->iqs('irpActive'));
|
199 |
-
|
200 |
-
$defaults=array(
|
201 |
-
'hasShadow'=>0
|
202 |
-
, 'hasPoweredBy'=>0
|
203 |
-
);
|
204 |
-
$template=$irp->Utils->aqs('template-', $defaults);
|
205 |
-
$irp->Options->setTemplateStyle($template);
|
206 |
-
|
207 |
-
$irp->Options->setMarginTop($irp->Utils->qs('marginTop', '0em'));
|
208 |
-
$irp->Options->setMarginBottom($irp->Utils->qs('marginBottom', '1em'));
|
209 |
-
$irp->Options->setRewriteActive($irp->Utils->iqs('irpRewriteActive'));
|
210 |
-
$irp->Options->setRewriteBoxesCount($irp->Utils->iqs('irpRewriteBoxesCount', 1));
|
211 |
-
//$irp->Options->setRewritePostsInBoxCount($irp->Utils->iqs('irpRewritePostsInBoxCount', 1));
|
212 |
-
$irp->Options->setRewritePostsDays($irp->Utils->iqs('irpRewritePostsDays', 0));
|
213 |
-
$irp->Options->setRewriteThreshold($irp->Utils->iqs('irpRewriteThreshold', 300));
|
214 |
-
$irp->Options->setRewriteAtEnd($irp->Utils->iqs('irpRewriteAtEnd'));
|
215 |
-
|
216 |
-
$irp->Options->setEngineSearch($irp->Utils->iqs('irpEngineSearch', IRP_ENGINE_SEARCH_CATEGORIES_TAGS));
|
217 |
-
|
218 |
-
$options = $irp->Options->getRewritePostTypes();
|
219 |
-
foreach ($options as $k => $template) {
|
220 |
-
$template = intval($irp->Utils->qs('irpRewritePostType_' . $k, 0));
|
221 |
-
$options[$k] = $template;
|
222 |
-
}
|
223 |
-
$irp->Options->setRewritePostTypes($options);
|
224 |
-
|
225 |
-
$options = $irp->Options->getMetaboxPostTypes();
|
226 |
-
foreach ($options as $k => $template) {
|
227 |
-
$template = intval($irp->Utils->qs('metabox_' . $k, 0));
|
228 |
-
$options[$k] = $template;
|
229 |
-
}
|
230 |
-
$irp->Options->setMetaboxPostTypes($options);
|
231 |
-
}
|
232 |
-
|
233 |
-
$c=wp_count_posts()->publish;
|
234 |
-
$t=$irp->Options->getMaxExecutionTime();
|
235 |
-
if($t>0) {?>
|
236 |
-
<p style="width:auto; font-style: italic;"><?php $irp->Lang->P('PreviewSectionMaxTime', $t, $c)?></p>
|
237 |
-
<?php }
|
238 |
-
|
239 |
-
$irp->Form->p('GeneralSection');
|
240 |
-
$args=array(
|
241 |
-
'class'=>'irp-hideShow irp-checkbox'
|
242 |
-
, 'irp-hideIfTrue'=>'false'
|
243 |
-
, 'irp-hideShow'=>'irp-active-box'
|
244 |
-
);
|
245 |
-
$irp->Form->checkbox('irpActive', $irp->Options->isActive(), 1, $args);
|
246 |
-
$args=array(
|
247 |
-
'id'=>'irp-active-box'
|
248 |
-
, 'name'=>'irp-active-box'
|
249 |
-
, 'style'=>'margin-top:10px;'
|
250 |
-
);
|
251 |
-
$irp->Form->divStarts($args);
|
252 |
-
{
|
253 |
-
$template=$irp->Options->getTemplateStyle();
|
254 |
-
$prefix='template-';
|
255 |
-
$irp->Form->text($prefix.'ctaText', $irp->Utils->get($template, 'ctaText'));
|
256 |
-
$options=$irp->HtmlTemplate->getTemplatesNames();
|
257 |
-
$irp->Form->select($prefix.'template', $irp->Utils->get($template, 'template'), $options);
|
258 |
-
$irp->Form->number($prefix.'boxOpacity', $irp->Utils->get($template, 'boxOpacity'));
|
259 |
-
$irp->Form->text('marginTop', $irp->Options->getMarginTop());
|
260 |
-
$irp->Form->text('marginBottom', $irp->Options->getMarginBottom());
|
261 |
-
//$options=array('none', 'capitalize', 'uppercase', 'lowercase');
|
262 |
-
//$irp->Form->select($t.'textTransform', $irp->Utils->get($v, 'textTransform'), $options);
|
263 |
-
$array=array('ctaTextColor', 'postTitleColor', 'boxColor', 'borderColor');
|
264 |
-
$blanks=array('(Default)', '(Default)', '(Trasparent)', '(Without)');
|
265 |
-
for($i=0; $i<count($array); $i++) {
|
266 |
-
$k=$array[$i];
|
267 |
-
$v=$blanks[$i];
|
268 |
-
$colors=$irp->Options->getColors($v);
|
269 |
-
|
270 |
-
$v=$irp->Utils->get($template, $k);
|
271 |
-
$v=$irp->Options->getColor($v);
|
272 |
-
$irp->Form->colorSelect($prefix.$k, $v, $colors);
|
273 |
-
}
|
274 |
-
$array=array('hasShadow', 'hasPoweredBy');
|
275 |
-
foreach($array as $k) {
|
276 |
-
$irp->Form->checkbox($prefix.$k, $irp->Utils->iget($template, $k));
|
277 |
-
}
|
278 |
-
?>
|
279 |
-
<div style="padding-left:10px; padding-right:10px; border:1px dashed #444444">
|
280 |
-
<?php $irp->Form->p('PreviewSection'); ?>
|
281 |
-
<p id="relatedBoxExample" style="width:auto;"></p>
|
282 |
-
</div>
|
283 |
-
<?php
|
284 |
-
$irp->Form->p('RewriteSection');
|
285 |
-
$args=array(
|
286 |
-
'class'=>'irp-hideShow irp-checkbox'
|
287 |
-
, 'irp-hideIfTrue'=>'false'
|
288 |
-
, 'irp-hideShow'=>'irp-rewrite-box'
|
289 |
-
);
|
290 |
-
$irp->Form->checkbox('irpRewriteActive', $irp->Options->isRewriteActive(), 1, $args);
|
291 |
-
$args=array('id'=>'irp-rewrite-box', 'name'=>'irp-rewrite-box', 'style'=>'margin-top:10px;');
|
292 |
-
$irp->Form->divStarts($args);
|
293 |
-
{
|
294 |
-
$options=array();
|
295 |
-
$options[]=array('id'=>1, 'name'=>1);
|
296 |
-
$options[]=array('id'=>2, 'name'=>2);
|
297 |
-
$options[]=array('id'=>3, 'name'=>3);
|
298 |
-
$irp->Form->select('irpRewriteBoxesCount', $irp->Options->getRewriteBoxesCount(), $options);
|
299 |
-
$irp->Form->number('irpRewritePostsDays', $irp->Options->getRewritePostsDays());
|
300 |
-
$irp->Form->number('irpRewriteThreshold', $irp->Options->getRewriteThreshold(), $args);
|
301 |
-
$irp->Form->checkbox('irpRewriteAtEnd', $irp->Options->isRewriteAtEnd());
|
302 |
-
$irp->Form->p('');
|
303 |
-
|
304 |
-
$options=$irp->Options->getRewritePostTypes();
|
305 |
-
$types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
|
306 |
-
foreach($types as $v) {
|
307 |
-
$v=$v['name'];
|
308 |
-
$irp->Form->checkbox('irpRewritePostType_'.$v, $options[$v]);
|
309 |
-
}
|
310 |
-
}
|
311 |
-
$irp->Form->divEnds();
|
312 |
-
|
313 |
-
$irp->Form->p('EngineSection');
|
314 |
-
$irp->Form->divStarts();
|
315 |
-
{
|
316 |
-
$options=array(
|
317 |
-
IRP_ENGINE_SEARCH_CATEGORIES_TAGS
|
318 |
-
, IRP_ENGINE_SEARCH_CATEGORIES
|
319 |
-
, IRP_ENGINE_SEARCH_TAGS
|
320 |
-
);
|
321 |
-
$irp->Form->select('irpEngineSearch', $irp->Options->getEngineSearch(), $options);
|
322 |
-
$options=array();
|
323 |
-
$options[]=array('id'=>'nofollow', 'name'=>'nofollow');
|
324 |
-
$options[]=array('id'=>'dofollow', 'name'=>'dofollow');
|
325 |
-
$k='linkRel';
|
326 |
-
|
327 |
-
$irp->Form->select($prefix.$k, $irp->Utils->get($template, $k), $options);
|
328 |
-
$options=array();
|
329 |
-
$options[]=array('id'=>'_blank', 'name'=>'_blank');
|
330 |
-
$options[]=array('id'=>'_self', 'name'=>'_self');
|
331 |
-
$k='linkTarget';
|
332 |
-
$irp->Form->select($prefix.$k, $irp->Utils->get($template, $k), $options);
|
333 |
-
}
|
334 |
-
$irp->Form->divEnds();
|
335 |
-
|
336 |
-
$irp->Form->p('MetaboxSection');
|
337 |
-
$irp->Form->divStarts();
|
338 |
-
{
|
339 |
-
$metaboxes=$irp->Options->getMetaboxPostTypes();
|
340 |
-
$types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
|
341 |
-
foreach($types as $template) {
|
342 |
-
$template=$template['name'];
|
343 |
-
$irp->Form->checkbox('metabox_'.$template, $metaboxes[$template]);
|
344 |
-
}
|
345 |
-
}
|
346 |
-
$irp->Form->divEnds();
|
347 |
-
}
|
348 |
-
$irp->Form->divEnds();
|
349 |
-
|
350 |
-
$irp->Form->nonce('irp_settings');
|
351 |
-
irp_notice_pro_features();
|
352 |
-
$args=array('id'=>'boxDontSave', 'style'=>'display:none;');
|
353 |
-
$irp->Form->divStarts($args);
|
354 |
-
{
|
355 |
-
$irp->Form->p('Notice.DontSave');
|
356 |
-
}
|
357 |
-
$irp->Form->divEnds();
|
358 |
-
$irp->Form->submit('Save');
|
359 |
-
|
360 |
-
$irp->Form->formEnds(false);
|
361 |
-
$irp->Form->helps=FALSE;
|
362 |
-
|
363 |
-
$args=array('id'=>'irp-sidebar', 'style'=>'float:left; max-width: 250px; margin-left:10px');
|
364 |
-
$irp->Form->divStarts($args);
|
365 |
-
|
366 |
-
$count=$irp->Tabs->getPluginsCount();
|
367 |
-
$plugins=array();
|
368 |
-
while(count($plugins)<2) {
|
369 |
-
$id=rand(1, $count);
|
370 |
-
if(!isset($plugins[$id])) {
|
371 |
-
$plugins[$id]=$id;
|
372 |
-
}
|
373 |
-
}
|
374 |
-
|
375 |
-
$count=$irp->Tabs->drawContactUsWidget();
|
376 |
-
foreach($plugins as $id) {
|
377 |
-
$count=$irp->Tabs->drawPluginWidget($id);
|
378 |
-
}
|
379 |
-
|
380 |
-
$irp->Form->divEnds();
|
381 |
-
|
382 |
-
}
|
383 |
-
|
384 |
-
function irp_notice_pro_features() {
|
385 |
-
global $irp;
|
386 |
-
|
387 |
-
?>
|
388 |
-
<br/>
|
389 |
-
<div class="message updated below-h2" style="max-width:600px;">
|
390 |
-
<div style="height:10px;"></div>
|
391 |
-
<?php
|
392 |
-
$i=1;
|
393 |
-
while($irp->Lang->H('Notice.ProHeader'.$i)) {
|
394 |
-
$irp->Lang->P('Notice.ProHeader'.$i);
|
395 |
-
echo '<br/>';
|
396 |
-
++$i;
|
397 |
-
}
|
398 |
-
$i=1;
|
399 |
-
?>
|
400 |
-
<br/>
|
401 |
-
<?php
|
402 |
-
/*
|
403 |
-
$options = array('public' => TRUE, '_builtin' => FALSE);
|
404 |
-
$q=get_post_types($options, 'names');
|
405 |
-
if(is_array($q) && count($q)>0) {
|
406 |
-
sort($q);
|
407 |
-
$q=implode(', ', $q);
|
408 |
-
$q='(<b>'.$q.'</b>)';
|
409 |
-
} else {
|
410 |
-
$q='';
|
411 |
-
}*/
|
412 |
-
|
413 |
-
while($irp->Lang->H('Notice.ProFeature'.$i)) { ?>
|
414 |
-
<div style="clear:both; margin-top: 2px;"></div>
|
415 |
-
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px;">
|
416 |
-
<img src="<?php echo IRP_PLUGIN_IMAGES?>tick.png" />
|
417 |
-
</div>
|
418 |
-
<div style="float:left; vertical-align:middle; height:24px;">
|
419 |
-
<?php $irp->Lang->P('Notice.ProFeature'.$i)?>
|
420 |
-
</div>
|
421 |
-
<?php ++$i;
|
422 |
-
}
|
423 |
-
?>
|
424 |
-
<div style="clear:both;"></div>
|
425 |
-
<div style="height:10px;"></div>
|
426 |
-
<div style="float:right;">
|
427 |
-
<?php
|
428 |
-
$url=IRP_INTELLYWP_SITE.IRP_PLUGIN_SLUG.'/?utm_source=free-users&utm_medium=irp-cta&utm_campaign=IRP';
|
429 |
-
?>
|
430 |
-
<a href="<?php echo $url?>" target="_blank">
|
431 |
-
<b><?php $irp->Lang->P('Notice.ProCTA')?></b>
|
432 |
-
</a>
|
433 |
-
</div>
|
434 |
-
<div style="height:10px; clear:both;"></div>
|
435 |
-
</div>
|
436 |
-
<br/>
|
437 |
-
<?php }
|
1 |
+
<?php
|
2 |
+
function irp_ui_tracking($override=FALSE) {
|
3 |
+
global $irp;
|
4 |
+
|
5 |
+
$track=$irp->Utils->qs('track', '');
|
6 |
+
if($track!='') {
|
7 |
+
$track=intval($track);
|
8 |
+
$irp->Options->setTrackingEnable($track);
|
9 |
+
$irp->Tracking->sendTracking(TRUE);
|
10 |
+
}
|
11 |
+
|
12 |
+
$uri=IRP_TAB_SETTINGS_URI.'&track=';
|
13 |
+
if($irp->Options->isTrackingEnable()) {
|
14 |
+
if($override) {
|
15 |
+
$uri.='0';
|
16 |
+
$irp->Options->pushSuccessMessage('EnableAllowTrackingNotice', $uri);
|
17 |
+
}
|
18 |
+
} else {
|
19 |
+
$uri.='1';
|
20 |
+
$irp->Options->pushWarningMessage('DisableAllowTrackingNotice', $uri);
|
21 |
+
}
|
22 |
+
$irp->Options->writeMessages();
|
23 |
+
}
|
24 |
+
function irp_io_first_time() {
|
25 |
+
global $irp;
|
26 |
+
if($irp->Options->isShowActivationNotice()) {
|
27 |
+
$irp->Options->pushSuccessMessage('FirstTimeActivation');
|
28 |
+
$irp->Options->writeMessages();
|
29 |
+
$irp->Options->setShowActivationNotice(FALSE);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
function irp_ui_box_preview() {
|
33 |
+
global $irp;
|
34 |
+
|
35 |
+
$count=$irp->Options->getRewritePostsInBoxCount();
|
36 |
+
$count=$irp->Utils->iqs('rewritePostsInBoxCount', $count);
|
37 |
+
$args=array(
|
38 |
+
'orderby'=>'rand'
|
39 |
+
, 'numberposts'=>$count
|
40 |
+
);
|
41 |
+
|
42 |
+
$days=$irp->Options->getRewritePostsDays();
|
43 |
+
$days=$irp->Utils->iqs('rewritePostsDays', $days);
|
44 |
+
if($days>0) {
|
45 |
+
$args['date_query'] = array(
|
46 |
+
'column' => 'post_date'
|
47 |
+
, 'after' => '- '.$days.' days'
|
48 |
+
);
|
49 |
+
}
|
50 |
+
$posts=get_posts($args);
|
51 |
+
$ids=array();
|
52 |
+
foreach($posts as $p) {
|
53 |
+
$ids[]=$p->ID;
|
54 |
+
}
|
55 |
+
if(count($ids)==0) {
|
56 |
+
echo "<b>No posts available. Check settings and try again</b>";
|
57 |
+
die();
|
58 |
+
}
|
59 |
+
|
60 |
+
$defaults=$irp->Options->getTemplateStyle();
|
61 |
+
$args=$irp->Utils->aqs('template-', $defaults);
|
62 |
+
$args['includeCss']=TRUE;
|
63 |
+
$args['preview']=TRUE;
|
64 |
+
$box=irp_ui_get_box($ids, $args);
|
65 |
+
echo $box;
|
66 |
+
die();
|
67 |
+
}
|
68 |
+
function irp_ui_settings() {
|
69 |
+
global $irp;
|
70 |
+
irp_ui_tracking(FALSE);
|
71 |
+
|
72 |
+
?>
|
73 |
+
<script>
|
74 |
+
var IRP_preview=true;
|
75 |
+
var IRP_labelColor='';
|
76 |
+
var IRP_defaults={};
|
77 |
+
<?php
|
78 |
+
$defaults=$irp->HtmlTemplate->getDefaults();
|
79 |
+
foreach($defaults as $k=>$v) {
|
80 |
+
$buffer='';
|
81 |
+
foreach($v as $kk=>$vv) {
|
82 |
+
if($buffer!='') {
|
83 |
+
$buffer.=', ';
|
84 |
+
}
|
85 |
+
|
86 |
+
if(stripos($kk, 'label')!==FALSE) {
|
87 |
+
$vv=$irp->Lang->L('Settings.Color.'.$vv);
|
88 |
+
} elseif(stripos($kk, 'color')!==FALSE) {
|
89 |
+
$vv=$irp->Options->getColor($vv);
|
90 |
+
}
|
91 |
+
|
92 |
+
$buffer.=$kk.': "'.$vv.'"';
|
93 |
+
}
|
94 |
+
?>
|
95 |
+
IRP_defaults["<?php echo $k?>"]={<?php echo $buffer?>};
|
96 |
+
<?php }
|
97 |
+
?>
|
98 |
+
|
99 |
+
function IRP_changeTheme() {
|
100 |
+
IRP_preview=false;
|
101 |
+
t=IRP_val('template-template');
|
102 |
+
t=IRP_defaults[t];
|
103 |
+
isProTheme=false;
|
104 |
+
console.log(t);
|
105 |
+
jQuery.each(t, function(k,v) {
|
106 |
+
if(IRP_stripos(k, 'color')!==false) {
|
107 |
+
var $k=jQuery('[name=template-'+k+']');
|
108 |
+
$k.select2("val", v);
|
109 |
+
} else if(k=='proTheme') {
|
110 |
+
isProTheme=(v+''.toLowerCase()=='true');
|
111 |
+
}
|
112 |
+
});
|
113 |
+
|
114 |
+
jQuery("[name*='Color']").each(function(i,v) {
|
115 |
+
var $cbo=jQuery(this);
|
116 |
+
$cbo.prop("disabled", isProTheme);
|
117 |
+
$cbo.select2("enable", !isProTheme);
|
118 |
+
});
|
119 |
+
jQuery("[id*='ColorLabel']").each(function(i,v) {
|
120 |
+
var $lbl=jQuery(this);
|
121 |
+
if(IRP_labelColor!='') {
|
122 |
+
IRP_labelColor=$lbl.css('color');
|
123 |
+
}
|
124 |
+
if(isProTheme) {
|
125 |
+
$lbl.css('color', '#ccc');
|
126 |
+
} else {
|
127 |
+
$lbl.css('color', IRP_labelColor);
|
128 |
+
}
|
129 |
+
});
|
130 |
+
jQuery('.irp-submit').prop("disabled", isProTheme);
|
131 |
+
IRP_preview=true;
|
132 |
+
}
|
133 |
+
function IRP_changeRelatedBox() {
|
134 |
+
if(!IRP_preview) {
|
135 |
+
return;
|
136 |
+
}
|
137 |
+
|
138 |
+
var t=IRP_val('template-template');
|
139 |
+
t=IRP_defaults[t].borderColorLabel;
|
140 |
+
jQuery('#template-borderColorLabel').text(t);
|
141 |
+
|
142 |
+
data=IRP_aval('template-');
|
143 |
+
data=jQuery.extend({
|
144 |
+
'action': 'do_action'
|
145 |
+
, 'irp_action': 'ui_box_preview'
|
146 |
+
, 'rewritePostsDays': IRP_val('irpRewritePostsDays')
|
147 |
+
}, data);
|
148 |
+
//console.log(data);
|
149 |
+
|
150 |
+
var request=jQuery.ajax({
|
151 |
+
url: ajaxurl
|
152 |
+
, method: "POST"
|
153 |
+
, data: data
|
154 |
+
, dataType: "html"
|
155 |
+
});
|
156 |
+
|
157 |
+
request.done(function(html) {
|
158 |
+
jQuery("#relatedBoxExample").html(html);
|
159 |
+
});
|
160 |
+
}
|
161 |
+
|
162 |
+
jQuery(function() {
|
163 |
+
IRP_preview=false;
|
164 |
+
var array=['irpRewritePostsDays', 'irpRewritePostsInBoxCount', 'irpRewriteBoxesCount'];
|
165 |
+
for(i=0; i<array.length; i++) {
|
166 |
+
if(jQuery('[name='+array[i]+']').length>0) {
|
167 |
+
jQuery('[name='+array[i]+']').change(function() {
|
168 |
+
IRP_changeRelatedBox();
|
169 |
+
});
|
170 |
+
}
|
171 |
+
}
|
172 |
+
jQuery("[name^='template-']").change(function() {
|
173 |
+
if(!IRP_preview) {
|
174 |
+
return;
|
175 |
+
}
|
176 |
+
|
177 |
+
var $self=jQuery(this);
|
178 |
+
var name=$self.attr('name');
|
179 |
+
if(name=='template-template') {
|
180 |
+
IRP_changeTheme();
|
181 |
+
}
|
182 |
+
IRP_changeRelatedBox();
|
183 |
+
});
|
184 |
+
//IRP_changeTheme();
|
185 |
+
IRP_preview=true;
|
186 |
+
IRP_changeRelatedBox();
|
187 |
+
});
|
188 |
+
</script>
|
189 |
+
<?php
|
190 |
+
|
191 |
+
$irp->Form->prefix='Settings';
|
192 |
+
$irp->Form->helps = FALSE;
|
193 |
+
$irp->Form->formStarts();
|
194 |
+
|
195 |
+
if($irp->Check->nonce('irp_settings')) {
|
196 |
+
|
197 |
+
$irp->Options->resetMaxExecutionTime();
|
198 |
+
$irp->Options->setActive($irp->Utils->iqs('irpActive'));
|
199 |
+
|
200 |
+
$defaults=array(
|
201 |
+
'hasShadow'=>0
|
202 |
+
, 'hasPoweredBy'=>0
|
203 |
+
);
|
204 |
+
$template=$irp->Utils->aqs('template-', $defaults);
|
205 |
+
$irp->Options->setTemplateStyle($template);
|
206 |
+
|
207 |
+
$irp->Options->setMarginTop($irp->Utils->qs('marginTop', '0em'));
|
208 |
+
$irp->Options->setMarginBottom($irp->Utils->qs('marginBottom', '1em'));
|
209 |
+
$irp->Options->setRewriteActive($irp->Utils->iqs('irpRewriteActive'));
|
210 |
+
$irp->Options->setRewriteBoxesCount($irp->Utils->iqs('irpRewriteBoxesCount', 1));
|
211 |
+
//$irp->Options->setRewritePostsInBoxCount($irp->Utils->iqs('irpRewritePostsInBoxCount', 1));
|
212 |
+
$irp->Options->setRewritePostsDays($irp->Utils->iqs('irpRewritePostsDays', 0));
|
213 |
+
$irp->Options->setRewriteThreshold($irp->Utils->iqs('irpRewriteThreshold', 300));
|
214 |
+
$irp->Options->setRewriteAtEnd($irp->Utils->iqs('irpRewriteAtEnd'));
|
215 |
+
|
216 |
+
$irp->Options->setEngineSearch($irp->Utils->iqs('irpEngineSearch', IRP_ENGINE_SEARCH_CATEGORIES_TAGS));
|
217 |
+
|
218 |
+
$options = $irp->Options->getRewritePostTypes();
|
219 |
+
foreach ($options as $k => $template) {
|
220 |
+
$template = intval($irp->Utils->qs('irpRewritePostType_' . $k, 0));
|
221 |
+
$options[$k] = $template;
|
222 |
+
}
|
223 |
+
$irp->Options->setRewritePostTypes($options);
|
224 |
+
|
225 |
+
$options = $irp->Options->getMetaboxPostTypes();
|
226 |
+
foreach ($options as $k => $template) {
|
227 |
+
$template = intval($irp->Utils->qs('metabox_' . $k, 0));
|
228 |
+
$options[$k] = $template;
|
229 |
+
}
|
230 |
+
$irp->Options->setMetaboxPostTypes($options);
|
231 |
+
}
|
232 |
+
|
233 |
+
$c=wp_count_posts()->publish;
|
234 |
+
$t=$irp->Options->getMaxExecutionTime();
|
235 |
+
if($t>0) {?>
|
236 |
+
<p style="width:auto; font-style: italic;"><?php $irp->Lang->P('PreviewSectionMaxTime', $t, $c)?></p>
|
237 |
+
<?php }
|
238 |
+
|
239 |
+
$irp->Form->p('GeneralSection');
|
240 |
+
$args=array(
|
241 |
+
'class'=>'irp-hideShow irp-checkbox'
|
242 |
+
, 'irp-hideIfTrue'=>'false'
|
243 |
+
, 'irp-hideShow'=>'irp-active-box'
|
244 |
+
);
|
245 |
+
$irp->Form->checkbox('irpActive', $irp->Options->isActive(), 1, $args);
|
246 |
+
$args=array(
|
247 |
+
'id'=>'irp-active-box'
|
248 |
+
, 'name'=>'irp-active-box'
|
249 |
+
, 'style'=>'margin-top:10px;'
|
250 |
+
);
|
251 |
+
$irp->Form->divStarts($args);
|
252 |
+
{
|
253 |
+
$template=$irp->Options->getTemplateStyle();
|
254 |
+
$prefix='template-';
|
255 |
+
$irp->Form->text($prefix.'ctaText', $irp->Utils->get($template, 'ctaText'));
|
256 |
+
$options=$irp->HtmlTemplate->getTemplatesNames();
|
257 |
+
$irp->Form->select($prefix.'template', $irp->Utils->get($template, 'template'), $options);
|
258 |
+
$irp->Form->number($prefix.'boxOpacity', $irp->Utils->get($template, 'boxOpacity'));
|
259 |
+
$irp->Form->text('marginTop', $irp->Options->getMarginTop());
|
260 |
+
$irp->Form->text('marginBottom', $irp->Options->getMarginBottom());
|
261 |
+
//$options=array('none', 'capitalize', 'uppercase', 'lowercase');
|
262 |
+
//$irp->Form->select($t.'textTransform', $irp->Utils->get($v, 'textTransform'), $options);
|
263 |
+
$array=array('ctaTextColor', 'postTitleColor', 'boxColor', 'borderColor');
|
264 |
+
$blanks=array('(Default)', '(Default)', '(Trasparent)', '(Without)');
|
265 |
+
for($i=0; $i<count($array); $i++) {
|
266 |
+
$k=$array[$i];
|
267 |
+
$v=$blanks[$i];
|
268 |
+
$colors=$irp->Options->getColors($v);
|
269 |
+
|
270 |
+
$v=$irp->Utils->get($template, $k);
|
271 |
+
$v=$irp->Options->getColor($v);
|
272 |
+
$irp->Form->colorSelect($prefix.$k, $v, $colors);
|
273 |
+
}
|
274 |
+
$array=array('hasShadow', 'hasPoweredBy');
|
275 |
+
foreach($array as $k) {
|
276 |
+
$irp->Form->checkbox($prefix.$k, $irp->Utils->iget($template, $k));
|
277 |
+
}
|
278 |
+
?>
|
279 |
+
<div style="padding-left:10px; padding-right:10px; border:1px dashed #444444">
|
280 |
+
<?php $irp->Form->p('PreviewSection'); ?>
|
281 |
+
<p id="relatedBoxExample" style="width:auto;"></p>
|
282 |
+
</div>
|
283 |
+
<?php
|
284 |
+
$irp->Form->p('RewriteSection');
|
285 |
+
$args=array(
|
286 |
+
'class'=>'irp-hideShow irp-checkbox'
|
287 |
+
, 'irp-hideIfTrue'=>'false'
|
288 |
+
, 'irp-hideShow'=>'irp-rewrite-box'
|
289 |
+
);
|
290 |
+
$irp->Form->checkbox('irpRewriteActive', $irp->Options->isRewriteActive(), 1, $args);
|
291 |
+
$args=array('id'=>'irp-rewrite-box', 'name'=>'irp-rewrite-box', 'style'=>'margin-top:10px;');
|
292 |
+
$irp->Form->divStarts($args);
|
293 |
+
{
|
294 |
+
$options=array();
|
295 |
+
$options[]=array('id'=>1, 'name'=>1);
|
296 |
+
$options[]=array('id'=>2, 'name'=>2);
|
297 |
+
$options[]=array('id'=>3, 'name'=>3);
|
298 |
+
$irp->Form->select('irpRewriteBoxesCount', $irp->Options->getRewriteBoxesCount(), $options);
|
299 |
+
$irp->Form->number('irpRewritePostsDays', $irp->Options->getRewritePostsDays());
|
300 |
+
$irp->Form->number('irpRewriteThreshold', $irp->Options->getRewriteThreshold(), $args);
|
301 |
+
$irp->Form->checkbox('irpRewriteAtEnd', $irp->Options->isRewriteAtEnd());
|
302 |
+
$irp->Form->p('');
|
303 |
+
|
304 |
+
$options=$irp->Options->getRewritePostTypes();
|
305 |
+
$types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
|
306 |
+
foreach($types as $v) {
|
307 |
+
$v=$v['name'];
|
308 |
+
$irp->Form->checkbox('irpRewritePostType_'.$v, $options[$v]);
|
309 |
+
}
|
310 |
+
}
|
311 |
+
$irp->Form->divEnds();
|
312 |
+
|
313 |
+
$irp->Form->p('EngineSection');
|
314 |
+
$irp->Form->divStarts();
|
315 |
+
{
|
316 |
+
$options=array(
|
317 |
+
IRP_ENGINE_SEARCH_CATEGORIES_TAGS
|
318 |
+
, IRP_ENGINE_SEARCH_CATEGORIES
|
319 |
+
, IRP_ENGINE_SEARCH_TAGS
|
320 |
+
);
|
321 |
+
$irp->Form->select('irpEngineSearch', $irp->Options->getEngineSearch(), $options);
|
322 |
+
$options=array();
|
323 |
+
$options[]=array('id'=>'nofollow', 'name'=>'nofollow');
|
324 |
+
$options[]=array('id'=>'dofollow', 'name'=>'dofollow');
|
325 |
+
$k='linkRel';
|
326 |
+
|
327 |
+
$irp->Form->select($prefix.$k, $irp->Utils->get($template, $k), $options);
|
328 |
+
$options=array();
|
329 |
+
$options[]=array('id'=>'_blank', 'name'=>'_blank');
|
330 |
+
$options[]=array('id'=>'_self', 'name'=>'_self');
|
331 |
+
$k='linkTarget';
|
332 |
+
$irp->Form->select($prefix.$k, $irp->Utils->get($template, $k), $options);
|
333 |
+
}
|
334 |
+
$irp->Form->divEnds();
|
335 |
+
|
336 |
+
$irp->Form->p('MetaboxSection');
|
337 |
+
$irp->Form->divStarts();
|
338 |
+
{
|
339 |
+
$metaboxes=$irp->Options->getMetaboxPostTypes();
|
340 |
+
$types=$irp->Utils->query(IRP_QUERY_POST_TYPES);
|
341 |
+
foreach($types as $template) {
|
342 |
+
$template=$template['name'];
|
343 |
+
$irp->Form->checkbox('metabox_'.$template, $metaboxes[$template]);
|
344 |
+
}
|
345 |
+
}
|
346 |
+
$irp->Form->divEnds();
|
347 |
+
}
|
348 |
+
$irp->Form->divEnds();
|
349 |
+
|
350 |
+
$irp->Form->nonce('irp_settings');
|
351 |
+
irp_notice_pro_features();
|
352 |
+
$args=array('id'=>'boxDontSave', 'style'=>'display:none;');
|
353 |
+
$irp->Form->divStarts($args);
|
354 |
+
{
|
355 |
+
$irp->Form->p('Notice.DontSave');
|
356 |
+
}
|
357 |
+
$irp->Form->divEnds();
|
358 |
+
$irp->Form->submit('Save');
|
359 |
+
|
360 |
+
$irp->Form->formEnds(false);
|
361 |
+
$irp->Form->helps=FALSE;
|
362 |
+
|
363 |
+
$args=array('id'=>'irp-sidebar', 'style'=>'float:left; max-width: 250px; margin-left:10px');
|
364 |
+
$irp->Form->divStarts($args);
|
365 |
+
|
366 |
+
$count=$irp->Tabs->getPluginsCount();
|
367 |
+
$plugins=array();
|
368 |
+
while(count($plugins)<2) {
|
369 |
+
$id=rand(1, $count);
|
370 |
+
if(!isset($plugins[$id])) {
|
371 |
+
$plugins[$id]=$id;
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
$count=$irp->Tabs->drawContactUsWidget();
|
376 |
+
foreach($plugins as $id) {
|
377 |
+
$count=$irp->Tabs->drawPluginWidget($id);
|
378 |
+
}
|
379 |
+
|
380 |
+
$irp->Form->divEnds();
|
381 |
+
|
382 |
+
}
|
383 |
+
|
384 |
+
function irp_notice_pro_features() {
|
385 |
+
global $irp;
|
386 |
+
|
387 |
+
?>
|
388 |
+
<br/>
|
389 |
+
<div class="message updated below-h2" style="max-width:600px;">
|
390 |
+
<div style="height:10px;"></div>
|
391 |
+
<?php
|
392 |
+
$i=1;
|
393 |
+
while($irp->Lang->H('Notice.ProHeader'.$i)) {
|
394 |
+
$irp->Lang->P('Notice.ProHeader'.$i);
|
395 |
+
echo '<br/>';
|
396 |
+
++$i;
|
397 |
+
}
|
398 |
+
$i=1;
|
399 |
+
?>
|
400 |
+
<br/>
|
401 |
+
<?php
|
402 |
+
/*
|
403 |
+
$options = array('public' => TRUE, '_builtin' => FALSE);
|
404 |
+
$q=get_post_types($options, 'names');
|
405 |
+
if(is_array($q) && count($q)>0) {
|
406 |
+
sort($q);
|
407 |
+
$q=implode(', ', $q);
|
408 |
+
$q='(<b>'.$q.'</b>)';
|
409 |
+
} else {
|
410 |
+
$q='';
|
411 |
+
}*/
|
412 |
+
|
413 |
+
while($irp->Lang->H('Notice.ProFeature'.$i)) { ?>
|
414 |
+
<div style="clear:both; margin-top: 2px;"></div>
|
415 |
+
<div style="float:left; vertical-align:middle; height:24px; margin-right:5px;">
|
416 |
+
<img src="<?php echo IRP_PLUGIN_IMAGES?>tick.png" />
|
417 |
+
</div>
|
418 |
+
<div style="float:left; vertical-align:middle; height:24px;">
|
419 |
+
<?php $irp->Lang->P('Notice.ProFeature'.$i)?>
|
420 |
+
</div>
|
421 |
+
<?php ++$i;
|
422 |
+
}
|
423 |
+
?>
|
424 |
+
<div style="clear:both;"></div>
|
425 |
+
<div style="height:10px;"></div>
|
426 |
+
<div style="float:right;">
|
427 |
+
<?php
|
428 |
+
$url=IRP_INTELLYWP_SITE.IRP_PLUGIN_SLUG.'/?utm_source=free-users&utm_medium=irp-cta&utm_campaign=IRP';
|
429 |
+
?>
|
430 |
+
<a href="<?php echo $url?>" target="_blank">
|
431 |
+
<b><?php $irp->Lang->P('Notice.ProCTA')?></b>
|
432 |
+
</a>
|
433 |
+
</div>
|
434 |
+
<div style="height:10px; clear:both;"></div>
|
435 |
+
</div>
|
436 |
+
<br/>
|
437 |
+
<?php }
|
includes/classes/html/HTMLContext.php
CHANGED
@@ -1,564 +1,564 @@
|
|
1 |
-
<?php
|
2 |
-
if (!defined('ABSPATH')) exit;
|
3 |
-
|
4 |
-
class IRP_HTMLContext {
|
5 |
-
var $root; //MainTag
|
6 |
-
var $buffer; //IRP_Stack
|
7 |
-
|
8 |
-
var $uncuttable;
|
9 |
-
var $withoutNextState;
|
10 |
-
var $withoutNextWords;
|
11 |
-
|
12 |
-
var $currentWords;
|
13 |
-
var $lastBoxWords;
|
14 |
-
//last time that the plugin insert the related posts box counter values
|
15 |
-
var $wordsThreshold;
|
16 |
-
var $skipWordsCount=FALSE;
|
17 |
-
|
18 |
-
public function __construct() {
|
19 |
-
$this->clearBuffer();
|
20 |
-
}
|
21 |
-
|
22 |
-
public function setWithoutNextBox() {
|
23 |
-
$this->withoutNextState=TRUE;
|
24 |
-
$this->withoutNextWords=$this->currentWords;
|
25 |
-
}
|
26 |
-
public function isSkipCurrentBox() {
|
27 |
-
$result=FALSE;
|
28 |
-
if($this->withoutNextState) {
|
29 |
-
//if i already had written some words i can unlock the withoutNext lock
|
30 |
-
$result=($this->currentWords<=$this->withoutNextWords);
|
31 |
-
if(!$result) {
|
32 |
-
$this->withoutNextState=FALSE;
|
33 |
-
$this->withoutNextWords=0;
|
34 |
-
}
|
35 |
-
}
|
36 |
-
return $result;
|
37 |
-
}
|
38 |
-
public function clearSkipNext() {
|
39 |
-
$this->withoutNextState=FALSE;
|
40 |
-
$this->withoutNextWords=0;
|
41 |
-
}
|
42 |
-
|
43 |
-
public function setUncuttable($value) {
|
44 |
-
$this->uncuttable=$value;
|
45 |
-
}
|
46 |
-
public function isUncuttable() {
|
47 |
-
return $this->uncuttable;
|
48 |
-
}
|
49 |
-
|
50 |
-
private function clearBuffer() {
|
51 |
-
$this->buffer=new IRP_Stack();
|
52 |
-
$this->uncuttable=FALSE;
|
53 |
-
$this->isParentTable=FALSE;
|
54 |
-
$this->withoutNextState=FALSE;
|
55 |
-
$this->currentWords=0;
|
56 |
-
$this->lastBoxWords=0;
|
57 |
-
$this->withoutNextState=FALSE;
|
58 |
-
$this->withoutNextWords=0;
|
59 |
-
}
|
60 |
-
private function pushTextContent($part, $text, IRP_Stack &$tagsStack) {
|
61 |
-
if(!$part) {
|
62 |
-
$parent=$tagsStack->peek();
|
63 |
-
$part=new IRP_TextContent();
|
64 |
-
$parent->pushTag($part);
|
65 |
-
}
|
66 |
-
$part->append($text);
|
67 |
-
return $part;
|
68 |
-
}
|
69 |
-
|
70 |
-
public function isWriteRelatedBox() {
|
71 |
-
global $irp;
|
72 |
-
if($this->isSkipCurrentBox()) {
|
73 |
-
return FALSE;
|
74 |
-
}
|
75 |
-
if($this->isUncuttable()) {
|
76 |
-
return FALSE;
|
77 |
-
}
|
78 |
-
|
79 |
-
$irp->Log->debug('WriteRelatedBox?');
|
80 |
-
$diff=($this->currentWords-$this->lastBoxWords);
|
81 |
-
$irp->Log->debug('currentWords[%s]-lastBoxWords[%s]=diff[%s]'
|
82 |
-
, $this->currentWords, $this->lastBoxWords, $diff);
|
83 |
-
|
84 |
-
$postLimit=$this->wordsThreshold*($irp->Options->getRewriteBoxesWritten()+1);
|
85 |
-
$irp->Log->debug('wordsThreshold[%s]*(RewriteBoxesWritten[%s]+1)=postLimit[%s]'
|
86 |
-
, $this->wordsThreshold, $irp->Options->getRewriteBoxesWritten(), $postLimit);
|
87 |
-
|
88 |
-
$minLimit=$irp->Options->getRewriteThreshold();
|
89 |
-
$result=($this->currentWords>=$postLimit && $diff>=$minLimit);
|
90 |
-
$irp->Log->debug('(currentWords[%s]>=postLimit[%s]) AND (diff[%s]>=minLimit[%s])=%s'
|
91 |
-
, $this->currentWords, $postLimit
|
92 |
-
, $diff, $minLimit, $result);
|
93 |
-
return $result;
|
94 |
-
}
|
95 |
-
|
96 |
-
function getTagAttribute($fullTag, $name) {
|
97 |
-
$close=strpos($fullTag, '>');
|
98 |
-
$attr=strpos($fullTag, ' '.$name.'=');
|
99 |
-
$result='';
|
100 |
-
if($attr!==FALSE && $close!==FALSE && $attr<$close) {
|
101 |
-
$quote=substr($fullTag, $attr+strlen($name)+2, 1);
|
102 |
-
$text=substr($fullTag, $attr+strlen($name)+3);
|
103 |
-
$end=strpos($text, $quote, 1);
|
104 |
-
if($end!==FALSE) {
|
105 |
-
$result=substr($text, 0, $end);
|
106 |
-
}
|
107 |
-
}
|
108 |
-
return $result;
|
109 |
-
}
|
110 |
-
|
111 |
-
//get the tag name to lower case, could be that is not defined
|
112 |
-
//so this function return '' could also be that
|
113 |
-
function getTagName($fullTag) {
|
114 |
-
global $irp;
|
115 |
-
|
116 |
-
$start=1;
|
117 |
-
$p=strpos($fullTag, ' ');
|
118 |
-
if($p===FALSE) {
|
119 |
-
$p=strpos($fullTag, '/');
|
120 |
-
if($p!==FALSE && $p==1) {
|
121 |
-
$start=2;
|
122 |
-
$p=FALSE;
|
123 |
-
}
|
124 |
-
if($p===FALSE) {
|
125 |
-
$p=strpos($fullTag, '>');
|
126 |
-
if($p===FALSE) {
|
127 |
-
$irp->Log->error('UNABLE TO DECODE TAG %s', $fullTag);
|
128 |
-
return '';
|
129 |
-
}
|
130 |
-
}
|
131 |
-
}
|
132 |
-
$tag=trim(substr($fullTag, $start, $p-$start));
|
133 |
-
$tag=strtolower($tag);
|
134 |
-
return $tag;
|
135 |
-
}
|
136 |
-
function getHtmlTag($fullTag){
|
137 |
-
global $irp;
|
138 |
-
|
139 |
-
$tag=$this->getTagName($fullTag);
|
140 |
-
$tagId=$this->getTagAttribute($fullTag, 'id');
|
141 |
-
$tagClasses=$this->getTagAttribute($fullTag, 'class');
|
142 |
-
if($tagClasses!=='') {
|
143 |
-
$tagClasses=explode(' ', $tagClasses);
|
144 |
-
} else {
|
145 |
-
$tagClasses=array();
|
146 |
-
}
|
147 |
-
|
148 |
-
if($tag=='') {
|
149 |
-
return NULL;
|
150 |
-
}
|
151 |
-
|
152 |
-
$result=new IRP_OtherTag();
|
153 |
-
if(in_array($tag, array('h1','h2','h3','h4','h5','h6'))) {
|
154 |
-
$result=new IRP_BehaviourTag();
|
155 |
-
$result->allowBoxBefore=TRUE;
|
156 |
-
$result->ensureUncuttable=TRUE;
|
157 |
-
$result->ensureWithoutNextBox=TRUE;
|
158 |
-
} elseif(in_array($tag, array('ul', 'ol', 'dl'))) {
|
159 |
-
$result=new IRP_BehaviourTag();
|
160 |
-
$result->ensureWithoutPreviousBox=TRUE;
|
161 |
-
$result->ensureUncuttable=TRUE;
|
162 |
-
$result->allowBoxAfter=TRUE;
|
163 |
-
} elseif(in_array($tag, array('area','base','col','br','command','embed','hr','img','input','link','meta','param','source'))) {
|
164 |
-
$result=new IRP_SingletonTag();
|
165 |
-
} elseif(in_array($tag, array('iframe'))) {
|
166 |
-
$result=new IRP_BehaviourTag();
|
167 |
-
$result->allowBoxBefore=TRUE;
|
168 |
-
$result->ensureUncuttable=TRUE;
|
169 |
-
$result->allowBoxAfter=TRUE;
|
170 |
-
$result->skipWordsCount=TRUE;
|
171 |
-
} elseif(in_array($tag, array('table'))) {
|
172 |
-
$result=new IRP_BehaviourTag();
|
173 |
-
$result->allowBoxBefore=TRUE;
|
174 |
-
$result->ensureUncuttable=TRUE;
|
175 |
-
$result->allowBoxAfter=TRUE;
|
176 |
-
} elseif(in_array($tag, array('span'))) {
|
177 |
-
$result=new IRP_BehaviourTag();
|
178 |
-
$result->ensureWithoutPreviousBox=TRUE;
|
179 |
-
$result->ensureWithoutNextBox=TRUE;
|
180 |
-
} elseif(in_array($tag, array('figure'))) {
|
181 |
-
$result=new IRP_BehaviourTag();
|
182 |
-
$result->ensureWithoutNextBox=TRUE;
|
183 |
-
$result->skipWordsCount=TRUE;
|
184 |
-
$result->ensureUncuttable=TRUE;
|
185 |
-
} elseif(in_array($tag, array('div'))) {
|
186 |
-
$result=new IRP_BehaviourTag();
|
187 |
-
$result->ensureWithoutPreviousBox=TRUE;
|
188 |
-
$result->ensureWithoutNextBox=TRUE;
|
189 |
-
|
190 |
-
$ids=explode('|', 'optinforms-|wpautbox-|wpurp-container-recipe-');
|
191 |
-
if($irp->Utils->startsWith($tagId, $ids)) {
|
192 |
-
$result->skipWordsCount=TRUE;
|
193 |
-
$result->ensureUncuttable=TRUE;
|
194 |
-
}
|
195 |
-
|
196 |
-
$classes=explode('|', 'yuzo_related_post|shareaholic-|wp-caption|wordpress-post-tabs|amp-wp-article-content|title-wrapper|sa-source-wrapper|et_pb_text_inner|wprm-recipe-name|toc_light_blue|ast-oembed-container|depiction|wc-tab|gkblock-3|et_pb_toggle_content|et_pb_module|aawp-product__description|fusion-text|fusion-alert-content|mv-create-instructions|recipe-ingredients-wrap|guide-box|underPostOptin|x-columnize');
|
197 |
-
if($irp->Utils->startsWith($tagClasses, $classes)) {
|
198 |
-
$result->skipWordsCount=TRUE;
|
199 |
-
$result->ensureUncuttable=TRUE;
|
200 |
-
}
|
201 |
-
} elseif(in_array($tag, array('p'))) {
|
202 |
-
$result=new IRP_BehaviourTag();
|
203 |
-
$result->allowBoxBefore=TRUE;
|
204 |
-
$result->allowBoxAfter=TRUE;
|
205 |
-
} elseif(in_array($tag, array('blockquote', 'cite', 'code', 'em', 'pre'))) {
|
206 |
-
$result=new IRP_BehaviourTag();
|
207 |
-
$result->ensureWithoutPreviousBox=TRUE;
|
208 |
-
$result->ensureUncuttable=TRUE;
|
209 |
-
$result->ensureWithoutNextBox=TRUE;
|
210 |
-
} elseif(in_array($tag, array('irp', 'script', 'style'))) {
|
211 |
-
$result=new IRP_BehaviourTag();
|
212 |
-
$result->ensureWithoutPreviousBox=TRUE;
|
213 |
-
$result->ensureUncuttable=TRUE;
|
214 |
-
$result->ensureWithoutNextBox=TRUE;
|
215 |
-
$result->skipWordsCount=TRUE;
|
216 |
-
} elseif(in_array($tag, array('sub', 'sup'))) {
|
217 |
-
$result=new IRP_BehaviourTag();
|
218 |
-
$result->ensureUncuttable=TRUE;
|
219 |
-
}
|
220 |
-
return $result;
|
221 |
-
}
|
222 |
-
|
223 |
-
public function decode($all) {
|
224 |
-
global $irp;
|
225 |
-
|
226 |
-
$this->root=new IRP_MainTag();
|
227 |
-
$this->clearBuffer();
|
228 |
-
|
229 |
-
if(!$all || trim($all)=='') return FALSE;
|
230 |
-
|
231 |
-
//qui sono a ricercare tutti i tag per poi farci delle verifiche
|
232 |
-
$tagsStack=new IRP_Stack();
|
233 |
-
$tagsStack->push($this->root);
|
234 |
-
|
235 |
-
$errors=FALSE;
|
236 |
-
$part=NULL;
|
237 |
-
$previous=0;
|
238 |
-
|
239 |
-
try {
|
240 |
-
do {
|
241 |
-
$less=strpos($all, '<', $previous);
|
242 |
-
if($less===FALSE) {
|
243 |
-
if($previous!=strlen($all)) {
|
244 |
-
$text=$irp->Utils->substrln($all, $previous);
|
245 |
-
$part=$this->pushTextContent($part, $text, $tagsStack);
|
246 |
-
}
|
247 |
-
break;
|
248 |
-
}
|
249 |
-
|
250 |
-
if($previous!=$less) {
|
251 |
-
$text=$irp->Utils->substrln($all, $previous, $less);
|
252 |
-
$part=$this->pushTextContent($part, $text, $tagsStack);
|
253 |
-
}
|
254 |
-
|
255 |
-
$more=strpos($all, '>', $less+1);
|
256 |
-
$another=strpos($all, '<', $less+1);
|
257 |
-
if($more===FALSE) {
|
258 |
-
//only open tag so I considate all as text (in this case is better
|
259 |
-
//to use html code like > or <
|
260 |
-
$text=$irp->Utils->substrln($all, $previous);
|
261 |
-
$part=$this->pushTextContent($part, $text, $tagsStack);
|
262 |
-
break;
|
263 |
-
}
|
264 |
-
|
265 |
-
if($another!==FALSE && $another<$more) {
|
266 |
-
//something like this <bla bla bla <bla bla> so we considerate
|
267 |
-
//from the last < before >
|
268 |
-
$previous=$another;
|
269 |
-
$text=$irp->Utils->substrln($all, $less, $previous);
|
270 |
-
$part=$this->pushTextContent($part, $text, $tagsStack);
|
271 |
-
continue;
|
272 |
-
}
|
273 |
-
|
274 |
-
$previous=$more+1;
|
275 |
-
$text=$irp->Utils->substrln($all, $less, $previous);
|
276 |
-
$parent=$tagsStack->peek();
|
277 |
-
$tag=$this->getOpenTag($text);
|
278 |
-
if($tag) {
|
279 |
-
//detected tag open
|
280 |
-
$part=NULL;
|
281 |
-
$parent->pushTag($tag);
|
282 |
-
if($tag->hasTagContent()) {
|
283 |
-
//this tag contains a content
|
284 |
-
$tagsStack->push($tag);
|
285 |
-
}
|
286 |
-
} else {
|
287 |
-
//detected tag close
|
288 |
-
$tag=$this->getCloseTag($text, $tagsStack);
|
289 |
-
if($tag) {
|
290 |
-
$part=NULL;
|
291 |
-
$compare=$tagsStack->pop();
|
292 |
-
while(!$tagsStack->isEmpty() && $compare!=$tag) {
|
293 |
-
//security check: close each tag until i found my tag
|
294 |
-
$irp->Log->error('WHAT? UNABLE TO FIND OPENED TAG..TRY CLOSING AND RETRYING AGAIN');
|
295 |
-
$compare->closeTag='</'.$compare->tag.'>';
|
296 |
-
$compare=$tagsStack->pop();
|
297 |
-
}
|
298 |
-
if($compare!=$tag) {
|
299 |
-
$irp->Log->error('WHAT? UNABLE TO FIND OPENED TAG');
|
300 |
-
$errors=TRUE;
|
301 |
-
} else {
|
302 |
-
$compare->closeTag=$text;
|
303 |
-
}
|
304 |
-
} else {
|
305 |
-
//simply text
|
306 |
-
$part=$this->pushTextContent($part, $text, $tagsStack);
|
307 |
-
}
|
308 |
-
}
|
309 |
-
}
|
310 |
-
while($previous<strlen($all));
|
311 |
-
} catch(Exception $ex) {
|
312 |
-
$irp->Log->exception($ex);
|
313 |
-
}
|
314 |
-
|
315 |
-
return !$errors;
|
316 |
-
}
|
317 |
-
|
318 |
-
private function getOpenTag($openTag) {
|
319 |
-
global $irp;
|
320 |
-
if($irp->Utils->startsWith($openTag, '</')) {
|
321 |
-
return NULL;
|
322 |
-
}
|
323 |
-
|
324 |
-
$name=$this->getTagName($openTag);
|
325 |
-
$tag=$this->getHtmlTag($openTag);
|
326 |
-
if($tag) {
|
327 |
-
$tag->tag=$name;
|
328 |
-
$tag->openTag=$openTag;
|
329 |
-
}
|
330 |
-
return $tag;
|
331 |
-
}
|
332 |
-
private function getCloseTag($closeTag, IRP_Stack $tagsStack) {
|
333 |
-
global $irp;
|
334 |
-
if(!$irp->Utils->startsWith($closeTag, '</')) {
|
335 |
-
return NULL;
|
336 |
-
}
|
337 |
-
|
338 |
-
$compare=$this->getTagName($closeTag);
|
339 |
-
if($compare=='') return NULL;
|
340 |
-
|
341 |
-
$tos=$tagsStack->peek();
|
342 |
-
if(!$tos || !isset($tos->tag) || strcasecmp($tos->tag, $compare)!=0) {
|
343 |
-
$irp->Log->error('CHECK YOU BODY TAG %s ENDS WITH %s TAG', $tos->tag, $compare);
|
344 |
-
return NULL;
|
345 |
-
}
|
346 |
-
|
347 |
-
$tos->closeTag=$closeTag;
|
348 |
-
return $tos;
|
349 |
-
}
|
350 |
-
|
351 |
-
public function execute($body) {
|
352 |
-
global $irp;
|
353 |
-
if(!$irp->Options->isRewriteActive()) {
|
354 |
-
return $body;
|
355 |
-
}
|
356 |
-
|
357 |
-
$this->decode($body);
|
358 |
-
$this->root->analyseText($this);
|
359 |
-
$t=intval($this->currentWords/($irp->Options->getRewriteBoxesCount()+1));
|
360 |
-
if($t<$irp->Options->getRewriteThreshold()) {
|
361 |
-
$t=$irp->Options->getRewriteThreshold();
|
362 |
-
}
|
363 |
-
/*
|
364 |
-
if($t<$irp->Options->getRewriteThreshold()) {
|
365 |
-
if($irp->Options->isRewriteAtEnd()) {
|
366 |
-
//this avoid to write a box just before the end of the posts
|
367 |
-
//where, due the isRewriteAtEnd flag we will write another box
|
368 |
-
$t=$this->wordsCounter+1;
|
369 |
-
} else {
|
370 |
-
$t=$irp->Options->getRewriteThreshold();
|
371 |
-
}
|
372 |
-
}
|
373 |
-
*/
|
374 |
-
$this->wordsThreshold=$t;
|
375 |
-
|
376 |
-
$this->clearBuffer();
|
377 |
-
$this->root->write($this);
|
378 |
-
|
379 |
-
$result='';
|
380 |
-
foreach($this->buffer->array as $v) {
|
381 |
-
$result.=$v->getText();
|
382 |
-
}
|
383 |
-
return $result;
|
384 |
-
}
|
385 |
-
public function write($text, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
|
386 |
-
global $irp;
|
387 |
-
if(!$text || $text=='') return;
|
388 |
-
$text=$irp->Utils->format($text, $v1, $v2, $v3, $v4, $v5);
|
389 |
-
|
390 |
-
$v=NULL;
|
391 |
-
$new=$this->buffer->isEmpty();
|
392 |
-
if(!$new) {
|
393 |
-
$v=$this->buffer->peek();
|
394 |
-
if(!$v->isBufferText()) {
|
395 |
-
$new=TRUE;
|
396 |
-
}
|
397 |
-
}
|
398 |
-
|
399 |
-
if($new) {
|
400 |
-
$v=new IRP_BufferText();
|
401 |
-
$this->buffer->push($v);
|
402 |
-
}
|
403 |
-
$v->appendText($text);
|
404 |
-
}
|
405 |
-
public function writeRelatedBoxIfNeeded() {
|
406 |
-
$result=FALSE;
|
407 |
-
//write the box at the end of the tag only if this is not an <Hn> tag
|
408 |
-
if($this->isWriteRelatedBox()) {
|
409 |
-
$result=$this->writeRelatedBox();
|
410 |
-
}
|
411 |
-
return $result;
|
412 |
-
}
|
413 |
-
public function writeRelatedBox($forceBox=FALSE) {
|
414 |
-
global $irp;
|
415 |
-
|
416 |
-
$written=$irp->Options->getRewriteBoxesWritten();
|
417 |
-
$max=$irp->Options->getRewriteBoxesCount();
|
418 |
-
if(!$forceBox && $written>=$max) {
|
419 |
-
$irp->Log->error('MAX BOX=%s REACHED', $max);
|
420 |
-
return FALSE;
|
421 |
-
}
|
422 |
-
|
423 |
-
$irp->Log->debug('WRITING BOX=%s/%s', $written+1, $max);
|
424 |
-
$result=FALSE;
|
425 |
-
$count=1;//$irp->Options->getRewritePostsInBoxCount();
|
426 |
-
$ids=$irp->Options->getToShowPostsIds($count, TRUE);
|
427 |
-
|
428 |
-
$comment="INLINE RELATED POSTS %s/%s";
|
429 |
-
$comment=sprintf($comment, $written+1, $max);
|
430 |
-
$options=array(
|
431 |
-
'comment'=>$comment
|
432 |
-
, 'shortcode'=>FALSE
|
433 |
-
);
|
434 |
-
$box=irp_ui_get_box($ids, $options);
|
435 |
-
if($box!='') {
|
436 |
-
$this->pushRelatedBox($box);
|
437 |
-
$result=TRUE;
|
438 |
-
} else {
|
439 |
-
$result=FALSE;
|
440 |
-
$irp->Log->error('NO BOX TO WRITE WITH IDS=%s', $ids);
|
441 |
-
}
|
442 |
-
return $result;
|
443 |
-
}
|
444 |
-
//append related-box element to buffer
|
445 |
-
public function pushRelatedBox($box) {
|
446 |
-
global $irp;
|
447 |
-
|
448 |
-
$v=new IRP_BufferBox();
|
449 |
-
$v->appendText($box);
|
450 |
-
$v->currentBoxWords=$this->currentWords;
|
451 |
-
$v->previousBoxWords=$this->lastBoxWords;
|
452 |
-
$this->buffer->push($v);
|
453 |
-
|
454 |
-
$written=$irp->Options->getRewriteBoxesWritten()+1;
|
455 |
-
$irp->Options->setRewriteBoxesWritten($written);
|
456 |
-
$this->lastBoxWords=$v->currentBoxWords;
|
457 |
-
}
|
458 |
-
//remove related-box elements from buffer starting from the end
|
459 |
-
public function popRelatedBox($args=NULL) {
|
460 |
-
global $irp;
|
461 |
-
if($this->buffer->isEmpty()) {
|
462 |
-
return FALSE;
|
463 |
-
}
|
464 |
-
|
465 |
-
$result=FALSE;
|
466 |
-
$defaults=array('last'=>TRUE, 'all'=>FALSE);
|
467 |
-
$args=$irp->Utils->parseArgs($args, $defaults);
|
468 |
-
if($args['last']) {
|
469 |
-
$v=$this->buffer->peek();
|
470 |
-
if($v->isBufferBox()) {
|
471 |
-
$v=$this->buffer->pop();
|
472 |
-
$this->lastBoxWords=$v->previousBoxWords;
|
473 |
-
$result=TRUE;
|
474 |
-
|
475 |
-
$w=$irp->Options->getRewriteBoxesWritten()-1;
|
476 |
-
$irp->Options->setRewriteBoxesWritten($w);
|
477 |
-
}
|
478 |
-
} elseif($args['all']) {
|
479 |
-
$array=array();
|
480 |
-
for($i=0; $i<count($this->buffer->array); $i++) {
|
481 |
-
$v=$this->buffer->array[$i];
|
482 |
-
if($v->isBufferBox()) {
|
483 |
-
$result=TRUE;
|
484 |
-
} else {
|
485 |
-
$array[]=$v;
|
486 |
-
}
|
487 |
-
}
|
488 |
-
$this->buffer->array=$array;
|
489 |
-
$this->lastBoxWords=0;
|
490 |
-
$irp->Options->setRewriteBoxesWritten(0);
|
491 |
-
}
|
492 |
-
return $result;
|
493 |
-
}
|
494 |
-
public function incCounters($text){
|
495 |
-
global $irp;
|
496 |
-
if($this->skipWordsCount) {
|
497 |
-
return;
|
498 |
-
}
|
499 |
-
|
500 |
-
$text=trim($text);
|
501 |
-
$words=explode(' ', $text);
|
502 |
-
$c=0;
|
503 |
-
foreach($words as $w) {
|
504 |
-
$w=trim($w);
|
505 |
-
if($w!='' && strlen($w)>1) {
|
506 |
-
$c++;
|
507 |
-
}
|
508 |
-
}
|
509 |
-
|
510 |
-
$this->currentWords+=$c;
|
511 |
-
$irp->Log->debug('TEXT=[%s] INCREMENT WORDS words[%s]/currentWords[%s]'
|
512 |
-
, $text, $c, $this->currentWords);
|
513 |
-
}
|
514 |
-
}
|
515 |
-
|
516 |
-
class IRP_BufferElement {
|
517 |
-
var $text;
|
518 |
-
public function __construct() {
|
519 |
-
$this->text='';
|
520 |
-
}
|
521 |
-
|
522 |
-
public function getText() {
|
523 |
-
return $this->text;
|
524 |
-
}
|
525 |
-
public function appendText($text) {
|
526 |
-
$this->text.=$text;
|
527 |
-
}
|
528 |
-
|
529 |
-
public function isBufferBox() {
|
530 |
-
return FALSE;
|
531 |
-
}
|
532 |
-
public function isBufferText() {
|
533 |
-
return FALSE;
|
534 |
-
}
|
535 |
-
}
|
536 |
-
class IRP_BufferText extends IRP_BufferElement {
|
537 |
-
public function __construct() {
|
538 |
-
parent::__construct();
|
539 |
-
}
|
540 |
-
|
541 |
-
public function isBufferBox() {
|
542 |
-
return FALSE;
|
543 |
-
}
|
544 |
-
public function isBufferText() {
|
545 |
-
return TRUE;
|
546 |
-
}
|
547 |
-
}
|
548 |
-
class IRP_BufferBox extends IRP_BufferElement {
|
549 |
-
var $currentBoxWords;
|
550 |
-
var $previousBoxWords;
|
551 |
-
|
552 |
-
public function __construct() {
|
553 |
-
parent::__construct();
|
554 |
-
$this->currentBoxWords=0;
|
555 |
-
$this->previousBoxWords=0;
|
556 |
-
}
|
557 |
-
|
558 |
-
public function isBufferBox() {
|
559 |
-
return TRUE;
|
560 |
-
}
|
561 |
-
public function isBufferText() {
|
562 |
-
return FALSE;
|
563 |
-
}
|
564 |
Â
}
|
1 |
+
<?php
|
2 |
+
if (!defined('ABSPATH')) exit;
|
3 |
+
|
4 |
+
class IRP_HTMLContext {
|
5 |
+
var $root; //MainTag
|
6 |
+
var $buffer; //IRP_Stack
|
7 |
+
|
8 |
+
var $uncuttable;
|
9 |
+
var $withoutNextState;
|
10 |
+
var $withoutNextWords;
|
11 |
+
|
12 |
+
var $currentWords;
|
13 |
+
var $lastBoxWords;
|
14 |
+
//last time that the plugin insert the related posts box counter values
|
15 |
+
var $wordsThreshold;
|
16 |
+
var $skipWordsCount=FALSE;
|
17 |
+
|
18 |
+
public function __construct() {
|
19 |
+
$this->clearBuffer();
|
20 |
+
}
|
21 |
+
|
22 |
+
public function setWithoutNextBox() {
|
23 |
+
$this->withoutNextState=TRUE;
|
24 |
+
$this->withoutNextWords=$this->currentWords;
|
25 |
+
}
|
26 |
+
public function isSkipCurrentBox() {
|
27 |
+
$result=FALSE;
|
28 |
+
if($this->withoutNextState) {
|
29 |
+
//if i already had written some words i can unlock the withoutNext lock
|
30 |
+
$result=($this->currentWords<=$this->withoutNextWords);
|
31 |
+
if(!$result) {
|
32 |
+
$this->withoutNextState=FALSE;
|
33 |
+
$this->withoutNextWords=0;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
return $result;
|
37 |
+
}
|
38 |
+
public function clearSkipNext() {
|
39 |
+
$this->withoutNextState=FALSE;
|
40 |
+
$this->withoutNextWords=0;
|
41 |
+
}
|
42 |
+
|
43 |
+
public function setUncuttable($value) {
|
44 |
+
$this->uncuttable=$value;
|
45 |
+
}
|
46 |
+
public function isUncuttable() {
|
47 |
+
return $this->uncuttable;
|
48 |
+
}
|
49 |
+
|
50 |
+
private function clearBuffer() {
|
51 |
+
$this->buffer=new IRP_Stack();
|
52 |
+
$this->uncuttable=FALSE;
|
53 |
+
$this->isParentTable=FALSE;
|
54 |
+
$this->withoutNextState=FALSE;
|
55 |
+
$this->currentWords=0;
|
56 |
+
$this->lastBoxWords=0;
|
57 |
+
$this->withoutNextState=FALSE;
|
58 |
+
$this->withoutNextWords=0;
|
59 |
+
}
|
60 |
+
private function pushTextContent($part, $text, IRP_Stack &$tagsStack) {
|
61 |
+
if(!$part) {
|
62 |
+
$parent=$tagsStack->peek();
|
63 |
+
$part=new IRP_TextContent();
|
64 |
+
$parent->pushTag($part);
|
65 |
+
}
|
66 |
+
$part->append($text);
|
67 |
+
return $part;
|
68 |
+
}
|
69 |
+
|
70 |
+
public function isWriteRelatedBox() {
|
71 |
+
global $irp;
|
72 |
+
if($this->isSkipCurrentBox()) {
|
73 |
+
return FALSE;
|
74 |
+
}
|
75 |
+
if($this->isUncuttable()) {
|
76 |
+
return FALSE;
|
77 |
+
}
|
78 |
+
|
79 |
+
$irp->Log->debug('WriteRelatedBox?');
|
80 |
+
$diff=($this->currentWords-$this->lastBoxWords);
|
81 |
+
$irp->Log->debug('currentWords[%s]-lastBoxWords[%s]=diff[%s]'
|
82 |
+
, $this->currentWords, $this->lastBoxWords, $diff);
|
83 |
+
|
84 |
+
$postLimit=$this->wordsThreshold*($irp->Options->getRewriteBoxesWritten()+1);
|
85 |
+
$irp->Log->debug('wordsThreshold[%s]*(RewriteBoxesWritten[%s]+1)=postLimit[%s]'
|
86 |
+
, $this->wordsThreshold, $irp->Options->getRewriteBoxesWritten(), $postLimit);
|
87 |
+
|
88 |
+
$minLimit=$irp->Options->getRewriteThreshold();
|
89 |
+
$result=($this->currentWords>=$postLimit && $diff>=$minLimit);
|
90 |
+
$irp->Log->debug('(currentWords[%s]>=postLimit[%s]) AND (diff[%s]>=minLimit[%s])=%s'
|
91 |
+
, $this->currentWords, $postLimit
|
92 |
+
, $diff, $minLimit, $result);
|
93 |
+
return $result;
|
94 |
+
}
|
95 |
+
|
96 |
+
function getTagAttribute($fullTag, $name) {
|
97 |
+
$close=strpos($fullTag, '>');
|
98 |
+
$attr=strpos($fullTag, ' '.$name.'=');
|
99 |
+
$result='';
|
100 |
+
if($attr!==FALSE && $close!==FALSE && $attr<$close) {
|
101 |
+
$quote=substr($fullTag, $attr+strlen($name)+2, 1);
|
102 |
+
$text=substr($fullTag, $attr+strlen($name)+3);
|
103 |
+
$end=strpos($text, $quote, 1);
|
104 |
+
if($end!==FALSE) {
|
105 |
+
$result=substr($text, 0, $end);
|
106 |
+
}
|
107 |
+
}
|
108 |
+
return $result;
|
109 |
+
}
|
110 |
+
|
111 |
+
//get the tag name to lower case, could be that is not defined
|
112 |
+
//so this function return '' could also be that
|
113 |
+
function getTagName($fullTag) {
|
114 |
+
global $irp;
|
115 |
+
|
116 |
+
$start=1;
|
117 |
+
$p=strpos($fullTag, ' ');
|
118 |
+
if($p===FALSE) {
|
119 |
+
$p=strpos($fullTag, '/');
|
120 |
+
if($p!==FALSE && $p==1) {
|
121 |
+
$start=2;
|
122 |
+
$p=FALSE;
|
123 |
+
}
|
124 |
+
if($p===FALSE) {
|
125 |
+
$p=strpos($fullTag, '>');
|
126 |
+
if($p===FALSE) {
|
127 |
+
$irp->Log->error('UNABLE TO DECODE TAG %s', $fullTag);
|
128 |
+
return '';
|
129 |
+
}
|
130 |
+
}
|
131 |
+
}
|
132 |
+
$tag=trim(substr($fullTag, $start, $p-$start));
|
133 |
+
$tag=strtolower($tag);
|
134 |
+
return $tag;
|
135 |
+
}
|
136 |
+
function getHtmlTag($fullTag){
|
137 |
+
global $irp;
|
138 |
+
|
139 |
+
$tag=$this->getTagName($fullTag);
|
140 |
+
$tagId=$this->getTagAttribute($fullTag, 'id');
|
141 |
+
$tagClasses=$this->getTagAttribute($fullTag, 'class');
|
142 |
+
if($tagClasses!=='') {
|
143 |
+
$tagClasses=explode(' ', $tagClasses);
|
144 |
+
} else {
|
145 |
+
$tagClasses=array();
|
146 |
+
}
|
147 |
+
|
148 |
+
if($tag=='') {
|
149 |
+
return NULL;
|
150 |
+
}
|
151 |
+
|
152 |
+
$result=new IRP_OtherTag();
|
153 |
+
if(in_array($tag, array('h1','h2','h3','h4','h5','h6'))) {
|
154 |
+
$result=new IRP_BehaviourTag();
|
155 |
+
$result->allowBoxBefore=TRUE;
|
156 |
+
$result->ensureUncuttable=TRUE;
|
157 |
+
$result->ensureWithoutNextBox=TRUE;
|
158 |
+
} elseif(in_array($tag, array('ul', 'ol', 'dl'))) {
|
159 |
+
$result=new IRP_BehaviourTag();
|
160 |
+
$result->ensureWithoutPreviousBox=TRUE;
|
161 |
+
$result->ensureUncuttable=TRUE;
|
162 |
+
$result->allowBoxAfter=TRUE;
|
163 |
+
} elseif(in_array($tag, array('area','base','col','br','command','embed','hr','img','input','link','meta','param','source'))) {
|
164 |
+
$result=new IRP_SingletonTag();
|
165 |
+
} elseif(in_array($tag, array('iframe'))) {
|
166 |
+
$result=new IRP_BehaviourTag();
|
167 |
+
$result->allowBoxBefore=TRUE;
|
168 |
+
$result->ensureUncuttable=TRUE;
|
169 |
+
$result->allowBoxAfter=TRUE;
|
170 |
+
$result->skipWordsCount=TRUE;
|
171 |
+
} elseif(in_array($tag, array('table'))) {
|
172 |
+
$result=new IRP_BehaviourTag();
|
173 |
+
$result->allowBoxBefore=TRUE;
|
174 |
+
$result->ensureUncuttable=TRUE;
|
175 |
+
$result->allowBoxAfter=TRUE;
|
176 |
+
} elseif(in_array($tag, array('span'))) {
|
177 |
+
$result=new IRP_BehaviourTag();
|
178 |
+
$result->ensureWithoutPreviousBox=TRUE;
|
179 |
+
$result->ensureWithoutNextBox=TRUE;
|
180 |
+
} elseif(in_array($tag, array('figure'))) {
|
181 |
+
$result=new IRP_BehaviourTag();
|
182 |
+
$result->ensureWithoutNextBox=TRUE;
|
183 |
+
$result->skipWordsCount=TRUE;
|
184 |
+
$result->ensureUncuttable=TRUE;
|
185 |
+
} elseif(in_array($tag, array('div'))) {
|
186 |
+
$result=new IRP_BehaviourTag();
|
187 |
+
$result->ensureWithoutPreviousBox=TRUE;
|
188 |
+
$result->ensureWithoutNextBox=TRUE;
|
189 |
+
|
190 |
+
$ids=explode('|', 'optinforms-|wpautbox-|wpurp-container-recipe-');
|
191 |
+
if($irp->Utils->startsWith($tagId, $ids)) {
|
192 |
+
$result->skipWordsCount=TRUE;
|
193 |
+
$result->ensureUncuttable=TRUE;
|
194 |
+
}
|
195 |
+
|
196 |
+
$classes=explode('|', 'yuzo_related_post|shareaholic-|wp-caption|wordpress-post-tabs|amp-wp-article-content|title-wrapper|sa-source-wrapper|et_pb_text_inner|wprm-recipe-name|toc_light_blue|ast-oembed-container|depiction|wc-tab|gkblock-3|et_pb_toggle_content|et_pb_module|aawp-product__description|fusion-text|fusion-alert-content|mv-create-instructions|recipe-ingredients-wrap|guide-box|underPostOptin|x-columnize');
|
197 |
+
if($irp->Utils->startsWith($tagClasses, $classes)) {
|
198 |
+
$result->skipWordsCount=TRUE;
|
199 |
+
$result->ensureUncuttable=TRUE;
|
200 |
+
}
|
201 |
+
} elseif(in_array($tag, array('p'))) {
|
202 |
+
$result=new IRP_BehaviourTag();
|
203 |
+
$result->allowBoxBefore=TRUE;
|
204 |
+
$result->allowBoxAfter=TRUE;
|
205 |
+
} elseif(in_array($tag, array('blockquote', 'cite', 'code', 'em', 'pre'))) {
|
206 |
+
$result=new IRP_BehaviourTag();
|
207 |
+
$result->ensureWithoutPreviousBox=TRUE;
|
208 |
+
$result->ensureUncuttable=TRUE;
|
209 |
+
$result->ensureWithoutNextBox=TRUE;
|
210 |
+
} elseif(in_array($tag, array('irp', 'script', 'style'))) {
|
211 |
+
$result=new IRP_BehaviourTag();
|
212 |
+
$result->ensureWithoutPreviousBox=TRUE;
|
213 |
+
$result->ensureUncuttable=TRUE;
|
214 |
+
$result->ensureWithoutNextBox=TRUE;
|
215 |
+
$result->skipWordsCount=TRUE;
|
216 |
+
} elseif(in_array($tag, array('sub', 'sup'))) {
|
217 |
+
$result=new IRP_BehaviourTag();
|
218 |
+
$result->ensureUncuttable=TRUE;
|
219 |
+
}
|
220 |
+
return $result;
|
221 |
+
}
|
222 |
+
|
223 |
+
public function decode($all) {
|
224 |
+
global $irp;
|
225 |
+
|
226 |
+
$this->root=new IRP_MainTag();
|
227 |
+
$this->clearBuffer();
|
228 |
+
|
229 |
+
if(!$all || trim($all)=='') return FALSE;
|
230 |
+
|
231 |
+
//qui sono a ricercare tutti i tag per poi farci delle verifiche
|
232 |
+
$tagsStack=new IRP_Stack();
|
233 |
+
$tagsStack->push($this->root);
|
234 |
+
|
235 |
+
$errors=FALSE;
|
236 |
+
$part=NULL;
|
237 |
+
$previous=0;
|
238 |
+
|
239 |
+
try {
|
240 |
+
do {
|
241 |
+
$less=strpos($all, '<', $previous);
|
242 |
+
if($less===FALSE) {
|
243 |
+
if($previous!=strlen($all)) {
|
244 |
+
$text=$irp->Utils->substrln($all, $previous);
|
245 |
+
$part=$this->pushTextContent($part, $text, $tagsStack);
|
246 |
+
}
|
247 |
+
break;
|
248 |
+
}
|
249 |
+
|
250 |
+
if($previous!=$less) {
|
251 |
+
$text=$irp->Utils->substrln($all, $previous, $less);
|
252 |
+
$part=$this->pushTextContent($part, $text, $tagsStack);
|
253 |
+
}
|
254 |
+
|
255 |
+
$more=strpos($all, '>', $less+1);
|
256 |
+
$another=strpos($all, '<', $less+1);
|
257 |
+
if($more===FALSE) {
|
258 |
+
//only open tag so I considate all as text (in this case is better
|
259 |
+
//to use html code like > or <
|
260 |
+
$text=$irp->Utils->substrln($all, $previous);
|
261 |
+
$part=$this->pushTextContent($part, $text, $tagsStack);
|
262 |
+
break;
|
263 |
+
}
|
264 |
+
|
265 |
+
if($another!==FALSE && $another<$more) {
|
266 |
+
//something like this <bla bla bla <bla bla> so we considerate
|
267 |
+
//from the last < before >
|
268 |
+
$previous=$another;
|
269 |
+
$text=$irp->Utils->substrln($all, $less, $previous);
|
270 |
+
$part=$this->pushTextContent($part, $text, $tagsStack);
|
271 |
+
continue;
|
272 |
+
}
|
273 |
+
|
274 |
+
$previous=$more+1;
|
275 |
+
$text=$irp->Utils->substrln($all, $less, $previous);
|
276 |
+
$parent=$tagsStack->peek();
|
277 |
+
$tag=$this->getOpenTag($text);
|
278 |
+
if($tag) {
|
279 |
+
//detected tag open
|
280 |
+
$part=NULL;
|
281 |
+
$parent->pushTag($tag);
|
282 |
+
if($tag->hasTagContent()) {
|
283 |
+
//this tag contains a content
|
284 |
+
$tagsStack->push($tag);
|
285 |
+
}
|
286 |
+
} else {
|
287 |
+
//detected tag close
|
288 |
+
$tag=$this->getCloseTag($text, $tagsStack);
|
289 |
+
if($tag) {
|
290 |
+
$part=NULL;
|
291 |
+
$compare=$tagsStack->pop();
|
292 |
+
while(!$tagsStack->isEmpty() && $compare!=$tag) {
|
293 |
+
//security check: close each tag until i found my tag
|
294 |
+
$irp->Log->error('WHAT? UNABLE TO FIND OPENED TAG..TRY CLOSING AND RETRYING AGAIN');
|
295 |
+
$compare->closeTag='</'.$compare->tag.'>';
|
296 |
+
$compare=$tagsStack->pop();
|
297 |
+
}
|
298 |
+
if($compare!=$tag) {
|
299 |
+
$irp->Log->error('WHAT? UNABLE TO FIND OPENED TAG');
|
300 |
+
$errors=TRUE;
|
301 |
+
} else {
|
302 |
+
$compare->closeTag=$text;
|
303 |
+
}
|
304 |
+
} else {
|
305 |
+
//simply text
|
306 |
+
$part=$this->pushTextContent($part, $text, $tagsStack);
|
307 |
+
}
|
308 |
+
}
|
309 |
+
}
|
310 |
+
while($previous<strlen($all));
|
311 |
+
} catch(Exception $ex) {
|
312 |
+
$irp->Log->exception($ex);
|
313 |
+
}
|
314 |
+
|
315 |
+
return !$errors;
|
316 |
+
}
|
317 |
+
|
318 |
+
private function getOpenTag($openTag) {
|
319 |
+
global $irp;
|
320 |
+
if($irp->Utils->startsWith($openTag, '</')) {
|
321 |
+
return NULL;
|
322 |
+
}
|
323 |
+
|
324 |
+
$name=$this->getTagName($openTag);
|
325 |
+
$tag=$this->getHtmlTag($openTag);
|
326 |
+
if($tag) {
|
327 |
+
$tag->tag=$name;
|
328 |
+
$tag->openTag=$openTag;
|
329 |
+
}
|
330 |
+
return $tag;
|
331 |
+
}
|
332 |
+
private function getCloseTag($closeTag, IRP_Stack $tagsStack) {
|
333 |
+
global $irp;
|
334 |
+
if(!$irp->Utils->startsWith($closeTag, '</')) {
|
335 |
+
return NULL;
|
336 |
+
}
|
337 |
+
|
338 |
+
$compare=$this->getTagName($closeTag);
|
339 |
+
if($compare=='') return NULL;
|
340 |
+
|
341 |
+
$tos=$tagsStack->peek();
|
342 |
+
if(!$tos || !isset($tos->tag) || strcasecmp($tos->tag, $compare)!=0) {
|
343 |
+
$irp->Log->error('CHECK YOU BODY TAG %s ENDS WITH %s TAG', $tos->tag, $compare);
|
344 |
+
return NULL;
|
345 |
+
}
|
346 |
+
|
347 |
+
$tos->closeTag=$closeTag;
|
348 |
+
return $tos;
|
349 |
+
}
|
350 |
+
|
351 |
+
public function execute($body) {
|
352 |
+
global $irp;
|
353 |
+
if(!$irp->Options->isRewriteActive()) {
|
354 |
+
return $body;
|
355 |
+
}
|
356 |
+
|
357 |
+
$this->decode($body);
|
358 |
+
$this->root->analyseText($this);
|
359 |
+
$t=intval($this->currentWords/($irp->Options->getRewriteBoxesCount()+1));
|
360 |
+
if($t<$irp->Options->getRewriteThreshold()) {
|
361 |
+
$t=$irp->Options->getRewriteThreshold();
|
362 |
+
}
|
363 |
+
/*
|
364 |
+
if($t<$irp->Options->getRewriteThreshold()) {
|
365 |
+
if($irp->Options->isRewriteAtEnd()) {
|
366 |
+
//this avoid to write a box just before the end of the posts
|
367 |
+
//where, due the isRewriteAtEnd flag we will write another box
|
368 |
+
$t=$this->wordsCounter+1;
|
369 |
+
} else {
|
370 |
+
$t=$irp->Options->getRewriteThreshold();
|
371 |
+
}
|
372 |
+
}
|
373 |
+
*/
|
374 |
+
$this->wordsThreshold=$t;
|
375 |
+
|
376 |
+
$this->clearBuffer();
|
377 |
+
$this->root->write($this);
|
378 |
+
|
379 |
+
$result='';
|
380 |
+
foreach($this->buffer->array as $v) {
|
381 |
+
$result.=$v->getText();
|
382 |
+
}
|
383 |
+
return $result;
|
384 |
+
}
|
385 |
+
public function write($text, $v1=NULL, $v2=NULL, $v3=NULL, $v4=NULL, $v5=NULL) {
|
386 |
+
global $irp;
|
387 |
+
if(!$text || $text=='') return;
|
388 |
+
$text=$irp->Utils->format($text, $v1, $v2, $v3, $v4, $v5);
|
389 |
+
|
390 |
+
$v=NULL;
|
391 |
+
$new=$this->buffer->isEmpty();
|
392 |
+
if(!$new) {
|
393 |
+
$v=$this->buffer->peek();
|
394 |
+
if(!$v->isBufferText()) {
|
395 |
+
$new=TRUE;
|
396 |
+
}
|
397 |
+
}
|
398 |
+
|
399 |
+
if($new) {
|
400 |
+
$v=new IRP_BufferText();
|
401 |
+
$this->buffer->push($v);
|
402 |
+
}
|
403 |
+
$v->appendText($text);
|
404 |
+
}
|
405 |
+
public function writeRelatedBoxIfNeeded() {
|
406 |
+
$result=FALSE;
|
407 |
+
//write the box at the end of the tag only if this is not an <Hn> tag
|
408 |
+
if($this->isWriteRelatedBox()) {
|
409 |
+
$result=$this->writeRelatedBox();
|
410 |
+
}
|
411 |
+
return $result;
|
412 |
+
}
|
413 |
+
public function writeRelatedBox($forceBox=FALSE) {
|
414 |
+
global $irp;
|
415 |
+
|
416 |
+
$written=$irp->Options->getRewriteBoxesWritten();
|
417 |
+
$max=$irp->Options->getRewriteBoxesCount();
|
418 |
+
if(!$forceBox && $written>=$max) {
|
419 |
+
$irp->Log->error('MAX BOX=%s REACHED', $max);
|
420 |
+
return FALSE;
|
421 |
+
}
|
422 |
+
|
423 |
+
$irp->Log->debug('WRITING BOX=%s/%s', $written+1, $max);
|
424 |
+
$result=FALSE;
|
425 |
+
$count=1;//$irp->Options->getRewritePostsInBoxCount();
|
426 |
+
$ids=$irp->Options->getToShowPostsIds($count, TRUE);
|
427 |
+
|
428 |
+
$comment="INLINE RELATED POSTS %s/%s";
|
429 |
+
$comment=sprintf($comment, $written+1, $max);
|
430 |
+
$options=array(
|
431 |
+
'comment'=>$comment
|
432 |
+
, 'shortcode'=>FALSE
|
433 |
+
);
|
434 |
+
$box=irp_ui_get_box($ids, $options);
|
435 |
+
if($box!='') {
|
436 |
+
$this->pushRelatedBox($box);
|
437 |
+
$result=TRUE;
|
438 |
+
} else {
|
439 |
+
$result=FALSE;
|
440 |
+
$irp->Log->error('NO BOX TO WRITE WITH IDS=%s', $ids);
|
441 |
+
}
|
442 |
+
return $result;
|
443 |
+
}
|
444 |
+
//append related-box element to buffer
|
445 |
+
public function pushRelatedBox($box) {
|
446 |
+
global $irp;
|
447 |
+
|
448 |
+
$v=new IRP_BufferBox();
|
449 |
+
$v->appendText($box);
|
450 |
+
$v->currentBoxWords=$this->currentWords;
|
451 |
+
$v->previousBoxWords=$this->lastBoxWords;
|
452 |
+
$this->buffer->push($v);
|
453 |
+
|
454 |
+
$written=$irp->Options->getRewriteBoxesWritten()+1;
|
455 |
+
$irp->Options->setRewriteBoxesWritten($written);
|
456 |
+
$this->lastBoxWords=$v->currentBoxWords;
|
457 |
+
}
|
458 |
+
//remove related-box elements from buffer starting from the end
|
459 |
+
public function popRelatedBox($args=NULL) {
|
460 |
+
global $irp;
|
461 |
+
if($this->buffer->isEmpty()) {
|
462 |
+
return FALSE;
|
463 |
+
}
|
464 |
+
|
465 |
+
$result=FALSE;
|
466 |
+
$defaults=array('last'=>TRUE, 'all'=>FALSE);
|
467 |
+
$args=$irp->Utils->parseArgs($args, $defaults);
|
468 |
+
if($args['last']) {
|
469 |
+
$v=$this->buffer->peek();
|
470 |
+
if($v->isBufferBox()) {
|
471 |
+
$v=$this->buffer->pop();
|
472 |
+
$this->lastBoxWords=$v->previousBoxWords;
|
473 |
+
$result=TRUE;
|
474 |
+
|
475 |
+
$w=$irp->Options->getRewriteBoxesWritten()-1;
|
476 |
+
$irp->Options->setRewriteBoxesWritten($w);
|
477 |
+
}
|
478 |
+
} elseif($args['all']) {
|
479 |
+
$array=array();
|
480 |
+
for($i=0; $i<count($this->buffer->array); $i++) {
|
481 |
+
$v=$this->buffer->array[$i];
|
482 |
+
if($v->isBufferBox()) {
|
483 |
+
$result=TRUE;
|
484 |
+
} else {
|
485 |
+
$array[]=$v;
|
486 |
+
}
|
487 |
+
}
|
488 |
+
$this->buffer->array=$array;
|
489 |
+
$this->lastBoxWords=0;
|
490 |
+
$irp->Options->setRewriteBoxesWritten(0);
|
491 |
+
}
|
492 |
+
return $result;
|
493 |
+
}
|
494 |
+
public function incCounters($text){
|
495 |
+
global $irp;
|
496 |
+
if($this->skipWordsCount) {
|
497 |
+
return;
|
498 |
+
}
|
499 |
+
|