Content Views – Post Grid & List for WordPress - Version 1.3.1.9

Version Description

  • Update: Add some new hook for customizing options
Download this release

Release Info

Developer PT Guy
Plugin Icon 128x128 Content Views – Post Grid & List for WordPress
Version 1.3.1.9
Comparing to
See all releases

Code changes from version 1.3.1.8 to 1.3.1.9

README.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: post, posts, page, pages, query, queries, search, display, show, grid, layout, author, blog, categories, category, comment, content, custom, editor, filter, Formatting, image, list, meta, plugin, responsive, shortcode, excerpt, title, tag, term, Taxonomy, thumbnail, pagination, date, scrollable, slider, collapsible
5
  Requires at least: 3.3
6
  Tested up to: 4.0
7
- Stable tag: 1.3.1.8
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -142,6 +142,9 @@ You can create Unlimited Views, in Unlimited websites
142
 
143
  == Changelog ==
144
 
 
 
 
145
  = 1.3.1.8 =
146
  * Bug fixed: Fix row style bug
147
 
@@ -261,6 +264,9 @@ You can create Unlimited Views, in Unlimited websites
261
 
262
  == Upgrade Notice ==
263
 
 
 
 
264
  = 1.3.1.8 =
265
  Bug fixed: Fix row style bug
266
 
4
  Tags: post, posts, page, pages, query, queries, search, display, show, grid, layout, author, blog, categories, category, comment, content, custom, editor, filter, Formatting, image, list, meta, plugin, responsive, shortcode, excerpt, title, tag, term, Taxonomy, thumbnail, pagination, date, scrollable, slider, collapsible
5
  Requires at least: 3.3
6
  Tested up to: 4.0
7
+ Stable tag: 1.3.1.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
142
 
143
  == Changelog ==
144
 
145
+ = 1.3.1.9 =
146
+ * Update: Add some new hook for customizing options
147
+
148
  = 1.3.1.8 =
149
  * Bug fixed: Fix row style bug
150
 
264
 
265
  == Upgrade Notice ==
266
 
267
+ = 1.3.1.9 =
268
+ Update: Add some new hook for customizing options
269
+
270
  = 1.3.1.8 =
271
  Bug fixed: Fix row style bug
272
 
admin/assets/css/admin.css CHANGED
@@ -1,201 +1,201 @@
1
- /**
2
- * Common styles for WP admin
3
- *
4
- * @package PT_Content_Views_Admin
5
- * @author PT Guy <palaceofthemes@gmail.com>
6
- * @license GPL-2.0+
7
- * @link http://www.contentviewspro.com/
8
- * @copyright 2014 PT Guy
9
- */
10
-
11
- /* Overwrite WP */
12
- .update-nag {
13
- display: none;
14
- }
15
-
16
- /* Fix Bootstrap box-sizing "border-box" problem */
17
- .pt-wrap *,
18
- .pt-wrap *:before,
19
- .pt-wrap *:after {
20
- -webkit-box-sizing: border-box;
21
- -moz-box-sizing: border-box;
22
- box-sizing: border-box;
23
- }
24
-
25
- /* Fix small error when use Bootstrap */
26
- html {
27
- background: none;
28
- }
29
-
30
- .pt-wrap select {
31
- height: 34px !important;
32
- }
33
-
34
- .pt-wrap .text-muted {
35
- clear: both;
36
- margin: 2px 0;
37
- float: left;
38
- }
39
-
40
- /* Overwrite Bootstrap */
41
- .form-control:focus {
42
- border-color: #66afe9 !important;
43
- outline: 0;
44
- -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) !important;
45
- box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) !important;
46
- }
47
-
48
- .form-horizontal .control-label {
49
- text-align: left !important;
50
- }
51
-
52
- .nav-tabs a {
53
- font-weight: 600;
54
- font-size: 1.3em;
55
- }
56
-
57
- /* Other settings */
58
- .hide {
59
- display: none;
60
- }
61
-
62
- #pt-cv-form-view .nav .glyphicon {
63
- margin-right: 6px;
64
- }
65
-
66
- #pt-cv-form-view *, .preview-wrapper label {
67
- font-size: 14px;
68
- }
69
-
70
- .preview-wrapper .text-muted {
71
- margin-top: 8px;
72
- }
73
-
74
- .pt-wrap h2 {
75
- margin-bottom: 20px;
76
- }
77
-
78
- .pt-wrap .tab-content {
79
- margin-top: 20px;
80
- }
81
-
82
- .pt-wrap .form-group.pt-form-group {
83
- margin-bottom: 8px;
84
- }
85
-
86
- .pt-cv-color {
87
- width: 100px !important;
88
- }
89
-
90
- /* Group type */
91
- .panel-group .pt-cv-group {
92
- margin-top: 10px;
93
- }
94
-
95
- .pt-cv-group .form-group {
96
- margin-bottom: 6px;
97
- }
98
-
99
- .pt-cv-group .panel-body {
100
- padding: 10px 15px;
101
- }
102
-
103
- .pt-cv-group .control-label, .pt-form-group .pt-form-group .control-label {
104
- font-weight: 400;
105
- }
106
-
107
- .pt-cv-group .checkbox,
108
- .pt-cv-w50 .pt-form-group {
109
- width: 50%;
110
- float: left;
111
- }
112
-
113
- .pt-cv-group .radio {
114
- /* width: 33%;
115
- float: left;
116
- margin-bottom: 10px !important;*/
117
- }
118
-
119
- .pt-cv-group .radio img {
120
- height: 100px;
121
- }
122
-
123
- .pt-cv-group .checkbox {
124
- background: none;
125
- }
126
-
127
- .pt-cv-no-panel {
128
- margin-top: 0px;
129
- }
130
-
131
- .pt-cv-text {
132
- margin-top: 7px;
133
- }
134
-
135
- .pt-wrap .input-group {
136
- width: 200px;
137
- }
138
-
139
- /* Accordion */
140
- .pt-cv-group .pt-accordion .panel-heading {
141
- cursor: pointer;
142
- padding-left: 30px;
143
- }
144
-
145
- .pt-cv-group .clickable {
146
- cursor: pointer;
147
- }
148
-
149
- .pt-cv-group .panel-heading span {
150
- margin-top: -20px;
151
- font-size: 15px;
152
- }
153
-
154
- .pt-cv-group-activate .panel-body {
155
- background: #FFCFCF;
156
- }
157
-
158
- /* Preview */
159
- #pt-cv-preview-box {
160
- margin-bottom: 5px;
161
- height: 300px;
162
- padding: 20px;
163
- position: relative;
164
- overflow-y: scroll;
165
- overflow-x: hidden;
166
- }
167
-
168
- #pt-cv-preview-box + .text-muted {
169
- margin-top: 8px;
170
- }
171
-
172
- #pt-cv-show-preview {
173
- position: fixed;
174
- right: 20px;
175
- bottom: 140px;
176
- z-index: 1001;
177
- }
178
-
179
- /* Field dislay */
180
- .pt-cv-bg-none {
181
- background: #fff;
182
- }
183
-
184
- /* Sortable */
185
- .pt-wrap .ui-sortable {
186
- background: #FFF9D7;
187
- }
188
-
189
- /* Custom css for Settings Group/Option */
190
- #pt-cv-group-excerpt-settings {
191
- margin-bottom: 20px;
192
- }
193
-
194
- /* View shortcode text */
195
- #view-shortcode {
196
- background: #ADFFAD;
197
- margin-bottom: 20px;
198
- float: left;
199
- position: relative;
200
- width: 50%;
201
  }
1
+ /**
2
+ * Common styles for WP admin
3
+ *
4
+ * @package PT_Content_Views_Admin
5
+ * @author PT Guy <palaceofthemes@gmail.com>
6
+ * @license GPL-2.0+
7
+ * @link http://www.contentviewspro.com/
8
+ * @copyright 2014 PT Guy
9
+ */
10
+
11
+ /* Overwrite WP */
12
+ .update-nag {
13
+ display: none;
14
+ }
15
+
16
+ /* Fix Bootstrap box-sizing "border-box" problem */
17
+ .pt-wrap *,
18
+ .pt-wrap *:before,
19
+ .pt-wrap *:after {
20
+ -webkit-box-sizing: border-box;
21
+ -moz-box-sizing: border-box;
22
+ box-sizing: border-box;
23
+ }
24
+
25
+ /* Fix small error when use Bootstrap */
26
+ html {
27
+ background: none;
28
+ }
29
+
30
+ .pt-wrap select {
31
+ height: 34px !important;
32
+ }
33
+
34
+ .pt-wrap .text-muted {
35
+ clear: both;
36
+ margin: 2px 0;
37
+ float: left;
38
+ }
39
+
40
+ /* Overwrite Bootstrap */
41
+ .form-control:focus {
42
+ border-color: #66afe9 !important;
43
+ outline: 0;
44
+ -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) !important;
45
+ box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) !important;
46
+ }
47
+
48
+ .form-horizontal .control-label {
49
+ text-align: left !important;
50
+ }
51
+
52
+ .nav-tabs a {
53
+ font-weight: 600;
54
+ font-size: 1.3em;
55
+ }
56
+
57
+ /* Other settings */
58
+ .hide {
59
+ display: none;
60
+ }
61
+
62
+ #pt-cv-form-view .nav .glyphicon {
63
+ margin-right: 6px;
64
+ }
65
+
66
+ #pt-cv-form-view *, .preview-wrapper label {
67
+ font-size: 14px;
68
+ }
69
+
70
+ .preview-wrapper .text-muted {
71
+ margin-top: 8px;
72
+ }
73
+
74
+ .pt-wrap h2 {
75
+ margin-bottom: 20px;
76
+ }
77
+
78
+ .pt-wrap .tab-content {
79
+ margin-top: 20px;
80
+ }
81
+
82
+ .pt-wrap .form-group.pt-form-group {
83
+ margin-bottom: 8px;
84
+ }
85
+
86
+ .pt-cv-color {
87
+ width: 100px !important;
88
+ }
89
+
90
+ /* Group type */
91
+ .panel-group .pt-cv-group {
92
+ margin-top: 10px;
93
+ }
94
+
95
+ .pt-cv-group .form-group {
96
+ margin-bottom: 6px;
97
+ }
98
+
99
+ .pt-cv-group .panel-body {
100
+ padding: 10px 15px;
101
+ }
102
+
103
+ .pt-cv-group .control-label, .pt-form-group .pt-form-group .control-label {
104
+ font-weight: 400;
105
+ }
106
+
107
+ .pt-cv-group .checkbox,
108
+ .pt-cv-w50 .pt-form-group {
109
+ width: 50%;
110
+ float: left;
111
+ }
112
+
113
+ .pt-cv-group .radio {
114
+ /* width: 33%;
115
+ float: left;
116
+ margin-bottom: 10px !important;*/
117
+ }
118
+
119
+ .pt-cv-group .radio img {
120
+ height: 100px;
121
+ }
122
+
123
+ .pt-cv-group .checkbox {
124
+ background: none;
125
+ }
126
+
127
+ .pt-cv-no-panel {
128
+ margin-top: 0px;
129
+ }
130
+
131
+ .pt-cv-text {
132
+ margin-top: 7px;
133
+ }
134
+
135
+ .pt-wrap .input-group {
136
+ width: 200px;
137
+ }
138
+
139
+ /* Accordion */
140
+ .pt-cv-group .pt-accordion .panel-heading {
141
+ cursor: pointer;
142
+ padding-left: 30px;
143
+ }
144
+
145
+ .pt-cv-group .clickable {
146
+ cursor: pointer;
147
+ }
148
+
149
+ .pt-cv-group .panel-heading span {
150
+ margin-top: -20px;
151
+ font-size: 15px;
152
+ }
153
+
154
+ .pt-cv-group-activate .panel-body {
155
+ background: #FFCFCF;
156
+ }
157
+
158
+ /* Preview */
159
+ #pt-cv-preview-box {
160
+ margin-bottom: 5px;
161
+ height: 300px;
162
+ padding: 20px;
163
+ position: relative;
164
+ overflow-y: scroll;
165
+ overflow-x: hidden;
166
+ }
167
+
168
+ #pt-cv-preview-box + .text-muted {
169
+ margin-top: 8px;
170
+ }
171
+
172
+ #pt-cv-show-preview {
173
+ position: fixed;
174
+ right: 20px;
175
+ bottom: 140px;
176
+ z-index: 1001;
177
+ }
178
+
179
+ /* Field dislay */
180
+ .pt-cv-bg-none {
181
+ background: #fff;
182
+ }
183
+
184
+ /* Sortable */
185
+ .pt-wrap .ui-sortable {
186
+ background: #FFF9D7;
187
+ }
188
+
189
+ /* Custom css for Settings Group/Option */
190
+ #pt-cv-group-excerpt-settings {
191
+ margin-bottom: 20px;
192
+ }
193
+
194
+ /* View shortcode text */
195
+ #view-shortcode {
196
+ background: #ADFFAD;
197
+ margin-bottom: 20px;
198
+ float: left;
199
+ position: relative;
200
+ width: 50%;
201
  }
admin/assets/css/menu.css CHANGED
@@ -1,14 +1,14 @@
1
- /**
2
- * Overwrite WP style : make the icon look clear on WP admin menu
3
- *
4
- * @package PT_Content_Views_Admin
5
- * @author PT Guy <palaceofthemes@gmail.com>
6
- * @license GPL-2.0+
7
- * @link http://www.contentviewspro.com/
8
- * @copyright 2014 PT Guy
9
- */
10
-
11
- #adminmenu #toplevel_page_content-views .menu-icon-generic div.wp-menu-image:before {
12
- background: url(../images/icon.png) no-repeat 0 7px;
13
- content: '' !important;
14
  }
1
+ /**
2
+ * Overwrite WP style : make the icon look clear on WP admin menu
3
+ *
4
+ * @package PT_Content_Views_Admin
5
+ * @author PT Guy <palaceofthemes@gmail.com>
6
+ * @license GPL-2.0+
7
+ * @link http://www.contentviewspro.com/
8
+ * @copyright 2014 PT Guy
9
+ */
10
+
11
+ #adminmenu #toplevel_page_content-views .menu-icon-generic div.wp-menu-image:before {
12
+ background: url(../images/icon.png) no-repeat 0 7px;
13
+ content: '' !important;
14
  }
admin/assets/css/wp.css CHANGED
@@ -1,18 +1,18 @@
1
- /**
2
- * Fix css error for Wordpress <= 3.7
3
- *
4
- * @package PT_Content_Views_Admin
5
- * @author PT Guy <palaceofthemes@gmail.com>
6
- * @license GPL-2.0+
7
- * @link http://www.contentviewspro.com/
8
- * @copyright 2014 PT Guy
9
- */
10
-
11
- .pt-wrap label input[type=radio],
12
- .pt-wrap label input[type=checkbox] {
13
- margin-top: 4px !important;
14
- }
15
-
16
- /* Screen Resolutions */
17
- @media screen and (max-width: 782px) {
18
  }
1
+ /**
2
+ * Fix css error for Wordpress <= 3.7
3
+ *
4
+ * @package PT_Content_Views_Admin
5
+ * @author PT Guy <palaceofthemes@gmail.com>
6
+ * @license GPL-2.0+
7
+ * @link http://www.contentviewspro.com/
8
+ * @copyright 2014 PT Guy
9
+ */
10
+
11
+ .pt-wrap label input[type=radio],
12
+ .pt-wrap label input[type=checkbox] {
13
+ margin-top: 4px !important;
14
+ }
15
+
16
+ /* Screen Resolutions */
17
+ @media screen and (max-width: 782px) {
18
  }
admin/assets/css/wp38.css CHANGED
@@ -1,25 +1,25 @@
1
- /**
2
- * Fix css error for Wordpress 3.8
3
- *
4
- * @package PT_Content_Views_Admin
5
- * @author PT Guy <palaceofthemes@gmail.com>
6
- * @license GPL-2.0+
7
- * @link http://www.contentviewspro.com/
8
- * @copyright 2014 PT Guy
9
- */
10
-
11
- .pt-wrap input[type=radio], input[type=checkbox] {
12
- margin-top: 2px !important;
13
- }
14
-
15
- /* Screen Resolutions */
16
- @media screen and (max-width: 782px) {
17
- .pt-wrap label {
18
- margin-left: 6px;
19
- }
20
-
21
- .pt-wrap label input[type=radio],
22
- .pt-wrap label input[type=checkbox] {
23
- margin-top: -2px !important;
24
- }
25
  }
1
+ /**
2
+ * Fix css error for Wordpress 3.8
3
+ *
4
+ * @package PT_Content_Views_Admin
5
+ * @author PT Guy <palaceofthemes@gmail.com>
6
+ * @license GPL-2.0+
7
+ * @link http://www.contentviewspro.com/
8
+ * @copyright 2014 PT Guy
9
+ */
10
+
11
+ .pt-wrap input[type=radio], input[type=checkbox] {
12
+ margin-top: 2px !important;
13
+ }
14
+
15
+ /* Screen Resolutions */
16
+ @media screen and (max-width: 782px) {
17
+ .pt-wrap label {
18
+ margin-left: 6px;
19
+ }
20
+
21
+ .pt-wrap label input[type=radio],
22
+ .pt-wrap label input[type=checkbox] {
23
+ margin-top: -2px !important;
24
+ }
25
  }
admin/includes/options.php CHANGED
@@ -1,391 +1,391 @@
1
- <?php
2
- /**
3
- * Options framework
4
- *
5
- * Contain all functions to display setting options on page
6
- *
7
- * @package PT_Options_Framework
8
- * @author PT Guy <palaceofthemes@gmail.com>
9
- * @license GPL-2.0+
10
- * @link http://www.contentviewspro.com/
11
- * @copyright 2014 PT Guy
12
- */
13
-
14
- if ( ! class_exists( 'PT_Options_Framework' ) ) {
15
-
16
- class PT_Options_Framework {
17
-
18
- private static $dependence_info; // Store dependency information of options
19
-
20
- public function __construct() {
21
- }
22
-
23
- /**
24
- * Check dependence information & generate random id for dependency elements
25
- *
26
- * @param array $param Array of parameters of a setting option
27
- * @param array $dependence_ Global dependence array
28
- *
29
- * @return string|null
30
- */
31
- public static function _dependence_check( $param, &$dependence_ ) {
32
- if ( isset( $param['dependence'] ) ) {
33
- // Depend array: 3 params in order : name (of param this param depends), value (of param this param depends), operator
34
- $dependence = (array) $param['dependence'];
35
- $random_id = PT_CV_PREFIX . 'dependence_' . PT_CV_Functions::string_random();
36
-
37
- // Single dependency relationship
38
- if ( ! is_array( $dependence[0] ) ) {
39
- self::_dependence_assign( $dependence, $random_id, $dependence_ );
40
- } else {
41
- // Multiple dependency relationships
42
- foreach ( $dependence as $dp ) {
43
- self::_dependence_assign( $dp, $random_id, $dependence_ );
44
- }
45
- }
46
-
47
- return $random_id;
48
- }
49
-
50
- return NULL;
51
- }
52
-
53
- /**
54
- * Assign dependency relationship
55
- *
56
- * @param array $dependence Array of dependence attributes
57
- * @param string $random_id Random string
58
- * @param array $dependence_ Global dependence array
59
- */
60
- public static function _dependence_assign( $dependence, $random_id, &$dependence_ ) {
61
- $dependence_[$dependence[0]][] = array( $random_id, $dependence[1], isset( $dependence[2] ) ? $dependence[2] : '=' );
62
- }
63
-
64
- /**
65
- * Settings for group of options
66
- *
67
- * @param array $options List of setting options
68
- * @param array $data Stored data of settings
69
- *
70
- * @return string
71
- */
72
- public static function do_settings( $options, $data = array() ) {
73
- $result = $dependence_ = array();
74
- if ( ! $options ) {
75
- return '';
76
- }
77
-
78
- foreach ( $options as $group ) {
79
- $result[] = self::group( $group, $data, $dependence_ );
80
- }
81
- if ( $dependence_ ) {
82
- self::$dependence_info[] = $dependence_;
83
- }
84
-
85
- return implode( '', $result );
86
- }
87
-
88
- /**
89
- * Group of options
90
- *
91
- * @param array $group
92
- * @param array $data Stored data of settings
93
- * @param array $dependence_ Global dependence array
94
- *
95
- * @return string
96
- */
97
- public static function group( $group, $data, &$dependence_ ) {
98
- if ( empty( $group['label'] ) && empty( $group['params'] ) ) {
99
- return '';
100
- }
101
-
102
- $extra_setting = isset( $group['extra_setting'] ) ? $group['extra_setting'] : array();
103
- $label = self::label( $group['label'], $extra_setting );
104
- $params = self::params( $group['params'], $data, $extra_setting );
105
- $random_id = self::_dependence_check( $group, $dependence_ );
106
- $id = $class = '';
107
- if ( $random_id ) {
108
- $id = "id='$random_id'";
109
- $class = 'hidden';
110
- }
111
-
112
- return "<div class='form-group pt-form-group $class' $id>$label $params</div>";
113
- }
114
-
115
- /**
116
- * Label
117
- *
118
- * @param string $label Text for label
119
- */
120
- public static function label( $label = array(), $extra_setting = array() ) {
121
- $for = isset( $label['for'] ) ? "for='{$label['for']}'" : '';
122
- $width = 12 - ( isset( $extra_setting['params']['width'] ) ? intval( $extra_setting['params']['width'] ) : 10 );
123
- if ( $width ) {
124
- $html = "<label $for class='col-md-$width control-label'>" . __( $label['text'], PT_CV_DOMAIN ) . '</label>';
125
- } else {
126
- $html = '';
127
- }
128
-
129
- return $html;
130
- }
131
-
132
- /**
133
- * Print params next to label
134
- *
135
- * @param string $params Array of setting options in a group
136
- */
137
- public static function params( $params, $data, $extra_setting ) {
138
- $params_html = array();
139
- foreach ( (array) $params as $param ) {
140
- $params_html[] = self::field_type( (array) $param, $data ) . "\n";
141
- }
142
- $html = implode( '', $params_html );
143
- $param_wrap_class = isset( $extra_setting['params']['wrap-class'] ) ? esc_attr( $extra_setting['params']['wrap-class'] ) : '';
144
- $param_wrap_id = isset( $extra_setting['params']['wrap-id'] ) ? "id='" . esc_attr( $extra_setting['params']['wrap-id'] ) . "'" : '';
145
- $width = isset( $extra_setting['params']['width'] ) ? intval( $extra_setting['params']['width'] ) : 10;
146
-
147
- return "<div class='col-md-$width pt-params $param_wrap_class' $param_wrap_id>$html</div>";
148
- }
149
-
150
- /**
151
- * Get value of field
152
- *
153
- * @param array $data Stored data of settings
154
- * @param array $param Array of parameters of a setting option
155
- *
156
- * @return string
157
- */
158
- public static function field_value( $data, $param, $name ) {
159
- // Get name without []
160
- $single_name = rtrim( $name, '[]' );
161
-
162
- // Get value of field
163
- if ( $data ) {
164
- $value = isset( $data[$single_name] ) ? $data[$single_name] : '';
165
- } else {
166
- $value = isset( $param['std'] ) ? $param['std'] : '';
167
- }
168
-
169
- return $value;
170
- }
171
-
172
- /**
173
- * Print HTML code of field type: input, select, textarea...
174
- *
175
- * @param array $param Array of parameters of a setting option
176
- *
177
- * @return string
178
- */
179
- public static function field_type( $param, $data ) {
180
- if ( ! $param || ! isset( $param['type'] ) ) {
181
- return '';
182
- }
183
- $html = $extend = '';
184
- $class = 'form-control ' . ( isset( $param['class'] ) ? ' ' . PT_CV_PREFIX . $param['class'] : '' );
185
-
186
- $type = esc_attr( $param['type'] );
187
- $name = ! empty( $param['name'] ) ? PT_CV_PREFIX . esc_attr( $param['name'] ) : '';
188
- $id = ! empty( $param['id'] ) ? "id='" . PT_CV_PREFIX . esc_attr( $param['id'] ) . "'" : '';
189
- $value = self::field_value( $data, $param, $name );
190
- $description = isset( $param['desc'] ) ? balanceTags( $param['desc'] ) : '';
191
-
192
- // Add extra information of option type
193
- switch ( $type ) {
194
- case 'number':
195
- $min = ! empty( $param['min'] ) ? intval( $param['min'] ) : 0;
196
- $extend = 'min="' . $min . '"';
197
- break;
198
- case 'color':
199
- $class .= ' ' . PT_CV_PREFIX . 'color';
200
- break;
201
- case 'checkbox':
202
- case 'radio':
203
- // Remove form-control class in checkbox, radio
204
- $class = str_replace( 'form-control', '', $class );
205
- break;
206
- }
207
-
208
- $class = esc_attr( $class );
209
-
210
- // Show HTML of option type
211
- switch ( $type ) {
212
- case 'group':
213
- $html .= self::do_settings( $param['params'], $data );
214
- break;
215
- case 'text':
216
- case 'email':
217
- case 'password':
218
- case 'number':
219
- case 'url':
220
- $placeholder = ! empty( $param['placeholder'] ) ? $param['placeholder'] : '';
221
- $append_text = ! empty( $param['append_text'] ) ? $param['append_text'] : '';
222
-
223
- $input = "<input type='$type' name='$name' value='$value' class='$class' $id $extend placeholder='$placeholder'>";
224
- if ( empty( $append_text ) ) {
225
- $html .= $input;
226
- } else {
227
- $html .= "<div class='input-group'>$input<span class='input-group-addon'>$append_text</span></div>";
228
- }
229
- break;
230
- case 'color':
231
- $html .= "<input type='text' name='$name' value='$value' class='$class' $id $extend style='background-color:$value;'>";
232
- $html .= "<div class='" . PT_CV_PREFIX . "colorpicker' style='z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;'></div><br>";
233
- break;
234
- case 'textarea':
235
- $html .= "<textarea name='$name' class='$class' $id $extend>$value</textarea>";
236
- break;
237
- case 'checkbox':
238
- case 'radio':
239
- if ( ! isset( $param['options'] ) ) {
240
- break;
241
- }
242
-
243
- $settings = isset( $param['settings'] ) ? $param['settings'] : array();
244
- foreach ( $param['options'] as $key => $text ) {
245
- // Append Html to $text, such as image...
246
- if ( $settings ) {
247
- $append = isset( $settings['text-append'] ) ? $settings['text-append'] : '';
248
- if ( $append == 'image' ) {
249
- $path = isset( $settings['path'] ) ? $settings['path'] : '';
250
- if ( $path ) {
251
- $text .= "<br> <img src='" . plugins_url( $path . "/$key.png", PT_CV_FILE ) . "' />";
252
- }
253
- }
254
- }
255
-
256
- $checked = ( in_array( $key, (array) $value ) || ( $value == 'all' ) ) ? 'checked' : '';
257
- $html .= "<div class='$type'><label><input type='$type' name='$name' value='$key' class='$class' $checked $id $extend>$text</label></div>";
258
- }
259
-
260
- break;
261
- case 'select':
262
- if ( ! isset( $param['options'] ) ) {
263
- break;
264
- }
265
-
266
- $options = '';
267
- foreach ( $param['options'] as $key => $text ) {
268
- $selected = ( in_array( $key, (array) $value ) || ( $value == 'all' ) ) ? 'selected' : '';
269
- $option_class = isset( $param['option_class_prefix'] ) ? sprintf( "class='%s'", $param['option_class_prefix'] . esc_attr( sanitize_title( $key ) ) ) : '';
270
- $options .= "<option value='$key' $selected $option_class>$text</option>";
271
- }
272
- if ( empty( $options ) ) {
273
- $html .= "<div class='" . PT_CV_PREFIX . "text'>" . __( 'There is no option', PT_CV_DOMAIN ) . '</div>';
274
- } else {
275
- $multiple = '';
276
- if ( ( isset( $param['multiple'] ) && $param['multiple'] == '1' ) || $value == 'all' ) {
277
- $multiple = 'multiple';
278
- // Auto add [] to name of select
279
- $name .= substr( $name, - 2 ) == '[]' ? '' : '[]';
280
- }
281
- $html .= "<select name='$name' class='$class' $multiple $id $extend>$options</select>";
282
- }
283
- break;
284
- case 'color_picker':
285
- $html .= self::field_type( $param['options'], $data );
286
- break;
287
- case 'html':
288
- if ( isset( $param['content'] ) ) {
289
- $html .= $param['content'];
290
- }
291
- break;
292
- case 'panel_group':
293
- // In format: key => array of params
294
- $parent_id = PT_CV_Functions::string_random( true );
295
- $settings = isset( $param['settings'] ) ? $param['settings'] : array();
296
- foreach ( $param['params'] as $key => $param_group ) {
297
- $html .= self::sub_panel_group( $key, $param_group, $data, $parent_id, $settings );
298
- }
299
- break;
300
- default:
301
- break;
302
- }
303
-
304
- $description = apply_filters( PT_CV_PREFIX_ . 'options_description', $description, $param );
305
-
306
- if ( ! empty( $description ) ) {
307
- $html .= "<p class='text-muted'>$description</p>";
308
- }
309
-
310
- return $html;
311
- }
312
-
313
- /**
314
- * HTML for group of params inside Panel group
315
- *
316
- * @param string $key
317
- * @param array $param_group Array of setting options in a group
318
- * @param array $data Stored data of settings
319
- * @param string $parent_id
320
- * @param bool $settings : array of custom settings
321
- *
322
- * @return string
323
- */
324
- static function sub_panel_group( $key, $param_group, $data, $parent_id, $settings = array() ) {
325
-
326
- // Content for body
327
- $content = self::do_settings( $param_group, $data );
328
- // Class for wrapper
329
- $class = PT_CV_Html::html_group_class();
330
- $class .= ( isset( $settings['show_all'] ) ? '' : ' hidden' );
331
- $class .= ( isset( $settings['show_only_one'] ) ? ' ' . PT_CV_PREFIX . 'only-one' : '' );
332
- $class .= ( isset( $settings['no_panel'] ) ? ' ' . PT_CV_PREFIX . 'no-panel' : '' );
333
- $class .= ( isset( $settings['no_animation'] ) ? ' ' . PT_CV_PREFIX . 'no-animation' : '' );
334
- // Id for wrapper
335
- $id = PT_CV_Html::html_group_id( $key );
336
-
337
- if ( ! isset( $settings['no_panel'] ) ) {
338
- // Heading text
339
- $heading = ( isset( $settings['nice_name'] ) && isset( $settings['nice_name'][$key] ) ) ? $settings['nice_name'][$key] : PT_CV_Functions::string_slug_to_text( $key );
340
- $heading = __( $heading, PT_CV_DOMAIN ) . ' ' . __( 'Settings', PT_CV_DOMAIN );
341
- $html = PT_CV_Html::html_collapse_one( $parent_id, $id . '-child', $heading, $content, true );
342
- } else {
343
- $html = $content;
344
- }
345
-
346
- return "<div class='$class' id='$id'>$html</div>";
347
- }
348
-
349
- /**
350
- * Print inline js
351
- */
352
- public static function print_js() {
353
- $toggle_data_js = json_encode( self::$dependence_info );
354
- ?>
355
- <script>
356
- (function ($) {
357
- "use strict";
358
-
359
- $(function () {
360
- var _prefix = '<?php echo esc_js( PT_CV_PREFIX ); ?>';
361
- var $pt_cv_admin_js = new $.PT_CV_Admin({_prefix: _prefix});
362
- var group_prefix = '<?php echo esc_js( PT_CV_Html::html_group_class() ); ?>' + '-';
363
-
364
- // Preview actions
365
- $pt_cv_admin_js.preview('<?php echo balanceTags( wp_create_nonce( PT_CV_PREFIX_ . 'ajax_nonce' ) );?>');
366
-
367
- // Custom js
368
- $pt_cv_admin_js.custom();
369
-
370
- // Toggle Panel group of 'Advance Settings'
371
- $pt_cv_admin_js.toggle_group('.' + _prefix + 'advanced-settings-item', group_prefix);
372
- // Toggle Panel group of 'Terms' (in "Taxonomy Settings")
373
- $pt_cv_admin_js.toggle_group('.' + _prefix + 'taxonomy-item', group_prefix);
374
- // Toggle Panel group of 'Advanced Order by'
375
- $pt_cv_admin_js.toggle_group('[name="' + _prefix + 'content-type' + '"]', group_prefix);
376
- // Toggle Panel group of 'View type settings'
377
- $pt_cv_admin_js.toggle_group('[name="' + _prefix + 'view-type' + '"]', group_prefix);
378
-
379
- // Toggle dependence
380
- $pt_cv_admin_js.dependence_do_all('<?php echo balanceTags( $toggle_data_js ); ?>');
381
-
382
- $pt_cv_admin_js.multi_level_toggle();
383
- });
384
- }(jQuery));
385
- </script>
386
- <?php
387
- }
388
-
389
- }
390
-
391
- }
1
+ <?php
2
+ /**
3
+ * Options framework
4
+ *
5
+ * Contain all functions to display setting options on page
6
+ *
7
+ * @package PT_Options_Framework
8
+ * @author PT Guy <palaceofthemes@gmail.com>
9
+ * @license GPL-2.0+
10
+ * @link http://www.contentviewspro.com/
11
+ * @copyright 2014 PT Guy
12
+ */
13
+
14
+ if ( ! class_exists( 'PT_Options_Framework' ) ) {
15
+
16
+ class PT_Options_Framework {
17
+
18
+ private static $dependence_info; // Store dependency information of options
19
+
20
+ public function __construct() {
21
+ }
22
+
23
+ /**
24
+ * Check dependence information & generate random id for dependency elements
25
+ *
26
+ * @param array $param Array of parameters of a setting option
27
+ * @param array $dependence_ Global dependence array
28
+ *
29
+ * @return string|null
30
+ */
31
+ public static function _dependence_check( $param, &$dependence_ ) {
32
+ if ( isset( $param['dependence'] ) ) {
33
+ // Depend array: 3 params in order : name (of param this param depends), value (of param this param depends), operator
34
+ $dependence = (array) $param['dependence'];
35
+ $random_id = PT_CV_PREFIX . 'dependence_' . PT_CV_Functions::string_random();
36
+
37
+ // Single dependency relationship
38
+ if ( ! is_array( $dependence[0] ) ) {
39
+ self::_dependence_assign( $dependence, $random_id, $dependence_ );
40
+ } else {
41
+ // Multiple dependency relationships
42
+ foreach ( $dependence as $dp ) {
43
+ self::_dependence_assign( $dp, $random_id, $dependence_ );
44
+ }
45
+ }
46
+
47
+ return $random_id;
48
+ }
49
+
50
+ return NULL;
51
+ }
52
+
53
+ /**
54
+ * Assign dependency relationship
55
+ *
56
+ * @param array $dependence Array of dependence attributes
57
+ * @param string $random_id Random string
58
+ * @param array $dependence_ Global dependence array
59
+ */
60
+ public static function _dependence_assign( $dependence, $random_id, &$dependence_ ) {
61
+ $dependence_[$dependence[0]][] = array( $random_id, $dependence[1], isset( $dependence[2] ) ? $dependence[2] : '=' );
62
+ }
63
+
64
+ /**
65
+ * Settings for group of options
66
+ *
67
+ * @param array $options List of setting options
68
+ * @param array $data Stored data of settings
69
+ *
70
+ * @return string
71
+ */
72
+ public static function do_settings( $options, $data = array() ) {
73
+ $result = $dependence_ = array();
74
+ if ( ! $options ) {
75
+ return '';
76
+ }
77
+
78
+ foreach ( $options as $group ) {
79
+ $result[] = self::group( $group, $data, $dependence_ );
80
+ }
81
+ if ( $dependence_ ) {
82
+ self::$dependence_info[] = $dependence_;
83
+ }
84
+
85
+ return implode( '', $result );
86
+ }
87
+
88
+ /**
89
+ * Group of options
90
+ *
91
+ * @param array $group
92
+ * @param array $data Stored data of settings
93
+ * @param array $dependence_ Global dependence array
94
+ *
95
+ * @return string
96
+ */
97
+ public static function group( $group, $data, &$dependence_ ) {
98
+ if ( empty( $group['label'] ) && empty( $group['params'] ) ) {
99
+ return '';
100
+ }
101
+
102
+ $extra_setting = isset( $group['extra_setting'] ) ? $group['extra_setting'] : array();
103
+ $label = self::label( $group['label'], $extra_setting );
104
+ $params = self::params( $group['params'], $data, $extra_setting );
105
+ $random_id = self::_dependence_check( $group, $dependence_ );
106
+ $id = $class = '';
107
+ if ( $random_id ) {
108
+ $id = "id='$random_id'";
109
+ $class = 'hidden';
110
+ }
111
+
112
+ return "<div class='form-group pt-form-group $class' $id>$label $params</div>";
113
+ }
114
+
115
+ /**
116
+ * Label
117
+ *
118
+ * @param string $label Text for label
119
+ */
120
+ public static function label( $label = array(), $extra_setting = array() ) {
121
+ $for = isset( $label['for'] ) ? "for='{$label['for']}'" : '';
122
+ $width = 12 - ( isset( $extra_setting['params']['width'] ) ? intval( $extra_setting['params']['width'] ) : 10 );
123
+ if ( $width ) {
124
+ $html = "<label $for class='col-md-$width control-label'>" . __( $label['text'], PT_CV_DOMAIN ) . '</label>';
125
+ } else {
126
+ $html = '';
127
+ }
128
+
129
+ return $html;
130
+ }
131
+
132
+ /**
133
+ * Print params next to label
134
+ *
135
+ * @param string $params Array of setting options in a group
136
+ */
137
+ public static function params( $params, $data, $extra_setting ) {
138
+ $params_html = array();
139
+ foreach ( (array) $params as $param ) {
140
+ $params_html[] = self::field_type( (array) $param, $data ) . "\n";
141
+ }
142
+ $html = implode( '', $params_html );
143
+ $param_wrap_class = isset( $extra_setting['params']['wrap-class'] ) ? esc_attr( $extra_setting['params']['wrap-class'] ) : '';
144
+ $param_wrap_id = isset( $extra_setting['params']['wrap-id'] ) ? "id='" . esc_attr( $extra_setting['params']['wrap-id'] ) . "'" : '';
145
+ $width = isset( $extra_setting['params']['width'] ) ? intval( $extra_setting['params']['width'] ) : 10;
146
+
147
+ return "<div class='col-md-$width pt-params $param_wrap_class' $param_wrap_id>$html</div>";
148
+ }
149
+
150
+ /**
151
+ * Get value of field
152
+ *
153
+ * @param array $data Stored data of settings
154
+ * @param array $param Array of parameters of a setting option
155
+ *
156
+ * @return string
157
+ */
158
+ public static function field_value( $data, $param, $name ) {
159
+ // Get name without []
160
+ $single_name = rtrim( $name, '[]' );
161
+
162
+ // Get value of field
163
+ if ( $data ) {
164
+ $value = isset( $data[$single_name] ) ? $data[$single_name] : '';
165
+ } else {
166
+ $value = isset( $param['std'] ) ? $param['std'] : '';
167
+ }
168
+
169
+ return $value;
170
+ }
171
+
172
+ /**
173
+ * Print HTML code of field type: input, select, textarea...
174
+ *
175
+ * @param array $param Array of parameters of a setting option
176
+ *
177
+ * @return string
178
+ */
179
+ public static function field_type( $param, $data ) {
180
+ if ( ! $param || ! isset( $param['type'] ) ) {
181
+ return '';
182
+ }
183
+ $html = $extend = '';
184
+ $class = 'form-control ' . ( isset( $param['class'] ) ? ' ' . PT_CV_PREFIX . $param['class'] : '' );
185
+
186
+ $type = esc_attr( $param['type'] );
187
+ $name = ! empty( $param['name'] ) ? PT_CV_PREFIX . esc_attr( $param['name'] ) : '';
188
+ $id = ! empty( $param['id'] ) ? "id='" . PT_CV_PREFIX . esc_attr( $param['id'] ) . "'" : '';
189
+ $value = self::field_value( $data, $param, $name );
190
+ $description = isset( $param['desc'] ) ? balanceTags( $param['desc'] ) : '';
191
+
192
+ // Add extra information of option type
193
+ switch ( $type ) {
194
+ case 'number':
195
+ $min = ! empty( $param['min'] ) ? intval( $param['min'] ) : 0;
196
+ $extend = 'min="' . $min . '"';
197
+ break;
198
+ case 'color':
199
+ $class .= ' ' . PT_CV_PREFIX . 'color';
200
+ break;
201
+ case 'checkbox':
202
+ case 'radio':
203
+ // Remove form-control class in checkbox, radio
204
+ $class = str_replace( 'form-control', '', $class );
205
+ break;
206
+ }
207
+
208
+ $class = esc_attr( $class );
209
+
210
+ // Show HTML of option type
211
+ switch ( $type ) {
212
+ case 'group':
213
+ $html .= self::do_settings( $param['params'], $data );
214
+ break;
215
+ case 'text':
216
+ case 'email':
217
+ case 'password':
218
+ case 'number':
219
+ case 'url':
220
+ $placeholder = ! empty( $param['placeholder'] ) ? $param['placeholder'] : '';
221
+ $append_text = ! empty( $param['append_text'] ) ? $param['append_text'] : '';
222
+
223
+ $input = "<input type='$type' name='$name' value='$value' class='$class' $id $extend placeholder='$placeholder'>";
224
+ if ( empty( $append_text ) ) {
225
+ $html .= $input;
226
+ } else {
227
+ $html .= "<div class='input-group'>$input<span class='input-group-addon'>$append_text</span></div>";
228
+ }
229
+ break;
230
+ case 'color':
231
+ $html .= "<input type='text' name='$name' value='$value' class='$class' $id $extend style='background-color:$value;'>";
232
+ $html .= "<div class='" . PT_CV_PREFIX . "colorpicker' style='z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;'></div><br>";
233
+ break;
234
+ case 'textarea':
235
+ $html .= "<textarea name='$name' class='$class' $id $extend>$value</textarea>";
236
+ break;
237
+ case 'checkbox':
238
+ case 'radio':
239
+ if ( ! isset( $param['options'] ) ) {
240
+ break;
241
+ }
242
+
243
+ $settings = isset( $param['settings'] ) ? $param['settings'] : array();
244
+ foreach ( $param['options'] as $key => $text ) {
245
+ // Append Html to $text, such as image...
246
+ if ( $settings ) {
247
+ $append = isset( $settings['text-append'] ) ? $settings['text-append'] : '';
248
+ if ( $append == 'image' ) {
249
+ $path = isset( $settings['path'] ) ? $settings['path'] : '';
250
+ if ( $path ) {
251
+ $text .= "<br> <img src='" . plugins_url( $path . "/$key.png", PT_CV_FILE ) . "' />";
252
+ }
253
+ }
254
+ }
255
+
256
+ $checked = ( in_array( $key, (array) $value ) || ( $value == 'all' ) ) ? 'checked' : '';
257
+ $html .= "<div class='$type'><label><input type='$type' name='$name' value='$key' class='$class' $checked $id $extend>$text</label></div>";
258
+ }
259
+
260
+ break;
261
+ case 'select':
262
+ if ( ! isset( $param['options'] ) ) {
263
+ break;
264
+ }
265
+
266
+ $options = '';
267
+ foreach ( $param['options'] as $key => $text ) {
268
+ $selected = ( in_array( $key, (array) $value ) || ( $value == 'all' ) ) ? 'selected' : '';
269
+ $option_class = isset( $param['option_class_prefix'] ) ? sprintf( "class='%s'", $param['option_class_prefix'] . esc_attr( sanitize_title( $key ) ) ) : '';
270
+ $options .= "<option value='$key' $selected $option_class>$text</option>";
271
+ }
272
+ if ( empty( $options ) ) {
273
+ $html .= "<div class='" . PT_CV_PREFIX . "text'>" . __( 'There is no option', PT_CV_DOMAIN ) . '</div>';
274
+ } else {
275
+ $multiple = '';
276
+ if ( ( isset( $param['multiple'] ) && $param['multiple'] == '1' ) || $value == 'all' ) {
277
+ $multiple = 'multiple';
278
+ // Auto add [] to name of select
279
+ $name .= substr( $name, - 2 ) == '[]' ? '' : '[]';
280
+ }
281
+ $html .= "<select name='$name' class='$class' $multiple $id $extend>$options</select>";
282
+ }
283
+ break;
284
+ case 'color_picker':
285
+ $html .= self::field_type( $param['options'], $data );
286
+ break;
287
+ case 'html':
288
+ if ( isset( $param['content'] ) ) {
289
+ $html .= $param['content'];
290
+ }
291
+ break;
292
+ case 'panel_group':
293
+ // In format: key => array of params
294
+ $parent_id = PT_CV_Functions::string_random( true );
295
+ $settings = isset( $param['settings'] ) ? $param['settings'] : array();
296
+ foreach ( $param['params'] as $key => $param_group ) {
297
+ $html .= self::sub_panel_group( $key, $param_group, $data, $parent_id, $settings );
298
+ }
299
+ break;
300
+ default:
301
+ break;
302
+ }
303
+
304
+ $description = apply_filters( PT_CV_PREFIX_ . 'options_description', $description, $param );
305
+
306
+ if ( ! empty( $description ) ) {
307
+ $html .= "<p class='text-muted'>$description</p>";
308
+ }
309
+
310
+ return $html;
311
+ }
312
+
313
+ /**
314
+ * HTML for group of params inside Panel group
315
+ *
316
+ * @param string $key
317
+ * @param array $param_group Array of setting options in a group
318
+ * @param array $data Stored data of settings
319
+ * @param string $parent_id
320
+ * @param bool $settings : array of custom settings
321
+ *
322
+ * @return string
323
+ */
324
+ static function sub_panel_group( $key, $param_group, $data, $parent_id, $settings = array() ) {
325
+
326
+ // Content for body
327
+ $content = self::do_settings( $param_group, $data );
328
+ // Class for wrapper
329
+ $class = PT_CV_Html::html_group_class();
330
+ $class .= ( isset( $settings['show_all'] ) ? '' : ' hidden' );
331
+ $class .= ( isset( $settings['show_only_one'] ) ? ' ' . PT_CV_PREFIX . 'only-one' : '' );
332
+ $class .= ( isset( $settings['no_panel'] ) ? ' ' . PT_CV_PREFIX . 'no-panel' : '' );
333
+ $class .= ( isset( $settings['no_animation'] ) ? ' ' . PT_CV_PREFIX . 'no-animation' : '' );
334
+ // Id for wrapper
335
+ $id = PT_CV_Html::html_group_id( $key );
336
+
337
+ if ( ! isset( $settings['no_panel'] ) ) {
338
+ // Heading text
339
+ $heading = ( isset( $settings['nice_name'] ) && isset( $settings['nice_name'][$key] ) ) ? $settings['nice_name'][$key] : PT_CV_Functions::string_slug_to_text( $key );
340
+ $heading = __( $heading, PT_CV_DOMAIN ) . ' ' . __( 'Settings', PT_CV_DOMAIN );
341
+ $html = PT_CV_Html::html_collapse_one( $parent_id, $id . '-child', $heading, $content, true );
342
+ } else {
343
+ $html = $content;
344
+ }
345
+
346
+ return "<div class='$class' id='$id'>$html</div>";
347
+ }
348
+
349
+ /**
350
+ * Print inline js
351
+ */
352
+ public static function print_js() {
353
+ $toggle_data_js = json_encode( self::$dependence_info );
354
+ ?>
355
+ <script>
356
+ (function ($) {
357
+ "use strict";
358
+
359
+ $(function () {
360
+ var _prefix = '<?php echo esc_js( PT_CV_PREFIX ); ?>';
361
+ var $pt_cv_admin_js = new $.PT_CV_Admin({_prefix: _prefix});
362
+ var group_prefix = '<?php echo esc_js( PT_CV_Html::html_group_class() ); ?>' + '-';
363
+
364
+ // Preview actions
365
+ $pt_cv_admin_js.preview('<?php echo balanceTags( wp_create_nonce( PT_CV_PREFIX_ . 'ajax_nonce' ) );?>');
366
+
367
+ // Custom js
368
+ $pt_cv_admin_js.custom();
369
+
370
+ // Toggle Panel group of 'Advance Settings'
371
+ $pt_cv_admin_js.toggle_group('.' + _prefix + 'advanced-settings-item', group_prefix);
372
+ // Toggle Panel group of 'Terms' (in "Taxonomy Settings")
373
+ $pt_cv_admin_js.toggle_group('.' + _prefix + 'taxonomy-item', group_prefix);
374
+ // Toggle Panel group of 'Advanced Order by'
375
+ $pt_cv_admin_js.toggle_group('[name="' + _prefix + 'content-type' + '"]', group_prefix);
376
+ // Toggle Panel group of 'View type settings'
377
+ $pt_cv_admin_js.toggle_group('[name="' + _prefix + 'view-type' + '"]', group_prefix);
378
+
379
+ // Toggle dependence
380
+ $pt_cv_admin_js.dependence_do_all('<?php echo balanceTags( $toggle_data_js ); ?>');
381
+
382
+ $pt_cv_admin_js.multi_level_toggle();
383
+ });
384
+ }(jQuery));
385
+ </script>
386
+ <?php
387
+ }
388
+
389
+ }
390
+
391
+ }
admin/includes/plugin.php CHANGED
@@ -1,222 +1,222 @@
1
- <?php
2
- /**
3
- * Form, option group, option name, option fields
4
- *
5
- * @package PT_Content_Views_Admin
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! class_exists( 'PT_CV_Plugin' ) ) {
13
-
14
- /**
15
- * @name PT_CV_Plugin
16
- */
17
- class PT_CV_Plugin {
18
-
19
- /**
20
- * Holds the values to be used in the fields callbacks
21
- */
22
- static $options;
23
-
24
- /**
25
- * Add custom filters/actions
26
- */
27
- static function init() {
28
-
29
- // Action
30
- add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
31
- }
32
-
33
- /**
34
- * Content Views Settings page : section 1
35
- */
36
- public static function settings_page_section_one() {
37
-
38
- $file_path = plugin_dir_path( PT_CV_FILE ) . 'admin/includes/templates/settings-section-one.php';
39
-
40
- $text = PT_CV_Functions::file_include_content( $file_path );
41
-
42
- $text = apply_filters( PT_CV_PREFIX_ . 'settings_page_section_one', $text );
43
-
44
- echo balanceTags( $text );
45
- }
46
-
47
- /**
48
- * Content Views Settings page : section 2
49
- */
50
- public static function settings_page_section_two() {
51
-
52
- $file_path = plugin_dir_path( PT_CV_FILE ) . 'admin/includes/templates/settings-section-two.php';
53
-
54
- $text = PT_CV_Functions::file_include_content( $file_path );
55
-
56
- $text = apply_filters( PT_CV_PREFIX_ . 'settings_page_section_two', $text );
57
-
58
- echo balanceTags( $text );
59
- }
60
-
61
- /**
62
- * Form in Settings page
63
- */
64
- public static function settings_page_form() {
65
- ob_start();
66
-
67
- self::$options = get_option( PT_CV_OPTION_NAME );
68
- ?>
69
- <form method="post" action="options.php">
70
- <?php
71
- // This prints out all hidden setting fields
72
- settings_fields( PT_CV_OPTION_NAME . '_group' );
73
- do_settings_sections( PT_CV_DOMAIN );
74
- submit_button();
75
- ?>
76
- </form>
77
- <?php
78
- $text = ob_get_clean();
79
-
80
- echo balanceTags( $text );
81
- }
82
-
83
- /**
84
- * Register option group, option name, option fields
85
- */
86
- public static function register_settings() {
87
-
88
- register_setting(
89
- PT_CV_OPTION_NAME . '_group', // Option group
90
- PT_CV_OPTION_NAME, // Option name
91
- array( __CLASS__, 'field_sanitize' ) // Sanitize
92
- );
93
-
94
- // Common setting Section
95
- $this_section = 'setting_frontend_assets';
96
- add_settings_section(
97
- $this_section, // ID
98
- __( '', PT_CV_DOMAIN ), // Title
99
- array( __CLASS__, 'section_callback_setting_frontend_assets' ), // Callback
100
- PT_CV_DOMAIN // Page
101
- );
102
-
103
- // Define Common setting fields
104
- $frontend_assets_fields = array(
105
- array(
106
- 'id' => 'unload_bootstrap',
107
- 'title' => '<strong>' . __( 'Frontend assets', PT_CV_DOMAIN ) . '</strong>',
108
- ),
109
- );
110
-
111
- // Filter Frontend assets option
112
- $frontend_assets_fields = apply_filters( PT_CV_PREFIX_ . 'frontend_assets_fields', $frontend_assets_fields );
113
-
114
- // Add classes to find callback function for extra options
115
- $defined_in_class = (array) apply_filters( PT_CV_PREFIX_ . 'defined_in_class', array() );
116
-
117
- // Register Common setting fields
118
- foreach ( $frontend_assets_fields as $field ) {
119
- $class = ( array_key_exists( $field['id'], $defined_in_class ) ) ? $defined_in_class[$field['id']] : __CLASS__;
120
- self::field_register( $field, $this_section, $class );
121
- }
122
-
123
- do_action( PT_CV_PREFIX_ . 'settings_page' );
124
- }
125
-
126
- /**
127
- * Sanitize each setting field as needed
128
- *
129
- * @param array $input Contains all settings fields as array keys
130
- */
131
- public static function field_sanitize( $input ) {
132
- $new_input = array();
133
-
134
- foreach ( $input as $key => $value ) {
135
- $new_input[$key] = sanitize_text_field( $value );
136
- }
137
-
138
- return $new_input;
139
- }
140
-
141
- /**
142
- * Add settings field
143
- *
144
- * @param array $field_info Field information
145
- * @param string $section Id of setting section
146
- * @param string $class Class name to find the callback function
147
- */
148
- public static function field_register( $field_info, $section, $class = __CLASS__ ) {
149
- if ( ! $field_info ) {
150
- return false;
151
- }
152
-
153
- add_settings_field(
154
- $field_info['id'], // ID
155
- $field_info['title'], // Title
156
- array( $class, 'field_callback_' . $field_info['id'] ), // Callback
157
- PT_CV_DOMAIN, // Page
158
- $section // Section
159
- );
160
- }
161
-
162
- /**
163
- * License key field
164
- */
165
- public static function field_callback_unload_bootstrap() {
166
- $field_name = 'unload_bootstrap';
167
-
168
- self::_field_print(
169
- $field_name,
170
- 'checkbox',
171
- __( "Don't load <b>Bootstrap</b> style & script (in frontend of website)", PT_CV_DOMAIN ),
172
- __( 'Only check this option if Bootstrap has been loaded by active theme or other plugin', PT_CV_DOMAIN )
173
- );
174
- }
175
-
176
- /**
177
- * Print text/password field
178
- *
179
- * @param string $field_name The ID of field
180
- * @param string $field_type The type of field
181
- * @param string $text The label of field
182
- * @param string $desc Description text
183
- */
184
- static function _field_print( $field_name, $field_type = 'text', $text = '', $desc = '' ) {
185
-
186
- // Get Saved value
187
- $field_value = isset( self::$options[$field_name] ) ? esc_attr( self::$options[$field_name] ) : '';
188
- $checked = '';
189
-
190
- if ( in_array( $field_type, array( 'checkbox', 'radio' ) ) ) {
191
- $checked = checked( 1, $field_value, false );
192
- // Reassign value for this option
193
- $field_value = 1;
194
- }
195
-
196
- $field_id = esc_attr( $field_name );
197
-
198
- printf(
199
- '<input type="%1$s" id="%2$s" name="%3$s[%2$s]" value="%4$s" %5$s /> ',
200
- esc_attr( $field_type ), $field_id, PT_CV_OPTION_NAME, $field_value, $checked
201
- );
202
-
203
- // For radio, checkbox field
204
- if ( ! empty( $text ) ) {
205
- printf( '<label for="%s" class="label-for-option">%s</label>', $field_id, $text );
206
- }
207
-
208
- // Show description
209
- if ( ! empty( $desc ) ) {
210
- printf( '<p class="description">%s</p>', $desc );
211
- }
212
- }
213
-
214
- /**
215
- * Print the text for Common setting Section
216
- */
217
- public static function section_callback_setting_frontend_assets() {
218
-
219
- }
220
- }
221
-
222
  }
1
+ <?php
2
+ /**
3
+ * Form, option group, option name, option fields
4
+ *
5
+ * @package PT_Content_Views_Admin
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! class_exists( 'PT_CV_Plugin' ) ) {
13
+
14
+ /**
15
+ * @name PT_CV_Plugin
16
+ */
17
+ class PT_CV_Plugin {
18
+
19
+ /**
20
+ * Holds the values to be used in the fields callbacks
21
+ */
22
+ static $options;
23
+
24
+ /**
25
+ * Add custom filters/actions
26
+ */
27
+ static function init() {
28
+
29
+ // Action
30
+ add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
31
+ }
32
+
33
+ /**
34
+ * Content Views Settings page : section 1
35
+ */
36
+ public static function settings_page_section_one() {
37
+
38
+ $file_path = plugin_dir_path( PT_CV_FILE ) . 'admin/includes/templates/settings-section-one.php';
39
+
40
+ $text = PT_CV_Functions::file_include_content( $file_path );
41
+
42
+ $text = apply_filters( PT_CV_PREFIX_ . 'settings_page_section_one', $text );
43
+
44
+ echo balanceTags( $text );
45
+ }
46
+
47
+ /**
48
+ * Content Views Settings page : section 2
49
+ */
50
+ public static function settings_page_section_two() {
51
+
52
+ $file_path = plugin_dir_path( PT_CV_FILE ) . 'admin/includes/templates/settings-section-two.php';
53
+
54
+ $text = PT_CV_Functions::file_include_content( $file_path );
55
+
56
+ $text = apply_filters( PT_CV_PREFIX_ . 'settings_page_section_two', $text );
57
+
58
+ echo balanceTags( $text );
59
+ }
60
+
61
+ /**
62
+ * Form in Settings page
63
+ */
64
+ public static function settings_page_form() {
65
+ ob_start();
66
+
67
+ self::$options = get_option( PT_CV_OPTION_NAME );
68
+ ?>
69
+ <form method="post" action="options.php">
70
+ <?php
71
+ // This prints out all hidden setting fields
72
+ settings_fields( PT_CV_OPTION_NAME . '_group' );
73
+ do_settings_sections( PT_CV_DOMAIN );
74
+ submit_button();
75
+ ?>
76
+ </form>
77
+ <?php
78
+ $text = ob_get_clean();
79
+
80
+ echo balanceTags( $text );
81
+ }
82
+
83
+ /**
84
+ * Register option group, option name, option fields
85
+ */
86
+ public static function register_settings() {
87
+
88
+ register_setting(
89
+ PT_CV_OPTION_NAME . '_group', // Option group
90
+ PT_CV_OPTION_NAME, // Option name
91
+ array( __CLASS__, 'field_sanitize' ) // Sanitize
92
+ );
93
+
94
+ // Common setting Section
95
+ $this_section = 'setting_frontend_assets';
96
+ add_settings_section(
97
+ $this_section, // ID
98
+ __( '', PT_CV_DOMAIN ), // Title
99
+ array( __CLASS__, 'section_callback_setting_frontend_assets' ), // Callback
100
+ PT_CV_DOMAIN // Page
101
+ );
102
+
103
+ // Define Common setting fields
104
+ $frontend_assets_fields = array(
105
+ array(
106
+ 'id' => 'unload_bootstrap',
107
+ 'title' => '<strong>' . __( 'Frontend assets', PT_CV_DOMAIN ) . '</strong>',
108
+ ),
109
+ );
110
+
111
+ // Filter Frontend assets option
112
+ $frontend_assets_fields = apply_filters( PT_CV_PREFIX_ . 'frontend_assets_fields', $frontend_assets_fields );
113
+
114
+ // Add classes to find callback function for extra options
115
+ $defined_in_class = (array) apply_filters( PT_CV_PREFIX_ . 'defined_in_class', array() );
116
+
117
+ // Register Common setting fields
118
+ foreach ( $frontend_assets_fields as $field ) {
119
+ $class = ( array_key_exists( $field['id'], $defined_in_class ) ) ? $defined_in_class[$field['id']] : __CLASS__;
120
+ self::field_register( $field, $this_section, $class );
121
+ }
122
+
123
+ do_action( PT_CV_PREFIX_ . 'settings_page' );
124
+ }
125
+
126
+ /**
127
+ * Sanitize each setting field as needed
128
+ *
129
+ * @param array $input Contains all settings fields as array keys
130
+ */
131
+ public static function field_sanitize( $input ) {
132
+ $new_input = array();
133
+
134
+ foreach ( $input as $key => $value ) {
135
+ $new_input[$key] = sanitize_text_field( $value );
136
+ }
137
+
138
+ return $new_input;
139
+ }
140
+
141
+ /**
142
+ * Add settings field
143
+ *
144
+ * @param array $field_info Field information
145
+ * @param string $section Id of setting section
146
+ * @param string $class Class name to find the callback function
147
+ */
148
+ public static function field_register( $field_info, $section, $class = __CLASS__ ) {
149
+ if ( ! $field_info ) {
150
+ return false;
151
+ }
152
+
153
+ add_settings_field(
154
+ $field_info['id'], // ID
155
+ $field_info['title'], // Title
156
+ array( $class, 'field_callback_' . $field_info['id'] ), // Callback
157
+ PT_CV_DOMAIN, // Page
158
+ $section // Section
159
+ );
160
+ }
161
+
162
+ /**
163
+ * License key field
164
+ */
165
+ public static function field_callback_unload_bootstrap() {
166
+ $field_name = 'unload_bootstrap';
167
+
168
+ self::_field_print(
169
+ $field_name,
170
+ 'checkbox',
171
+ __( "Don't load <b>Bootstrap</b> style & script (in frontend of website)", PT_CV_DOMAIN ),
172
+ __( 'Only check this option if Bootstrap has been loaded by active theme or other plugin', PT_CV_DOMAIN )
173
+ );
174
+ }
175
+
176
+ /**
177
+ * Print text/password field
178
+ *
179
+ * @param string $field_name The ID of field
180
+ * @param string $field_type The type of field
181
+ * @param string $text The label of field
182
+ * @param string $desc Description text
183
+ */
184
+ static function _field_print( $field_name, $field_type = 'text', $text = '', $desc = '' ) {
185
+
186
+ // Get Saved value
187
+ $field_value = isset( self::$options[$field_name] ) ? esc_attr( self::$options[$field_name] ) : '';
188
+ $checked = '';
189
+
190
+ if ( in_array( $field_type, array( 'checkbox', 'radio' ) ) ) {
191
+ $checked = checked( 1, $field_value, false );
192
+ // Reassign value for this option
193
+ $field_value = 1;
194
+ }
195
+
196
+ $field_id = esc_attr( $field_name );
197
+
198
+ printf(
199
+ '<input type="%1$s" id="%2$s" name="%3$s[%2$s]" value="%4$s" %5$s /> ',
200
+ esc_attr( $field_type ), $field_id, PT_CV_OPTION_NAME, $field_value, $checked
201
+ );
202
+
203
+ // For radio, checkbox field
204
+ if ( ! empty( $text ) ) {
205
+ printf( '<label for="%s" class="label-for-option">%s</label>', $field_id, $text );
206
+ }
207
+
208
+ // Show description
209
+ if ( ! empty( $desc ) ) {
210
+ printf( '<p class="description">%s</p>', $desc );
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Print the text for Common setting Section
216
+ */
217
+ public static function section_callback_setting_frontend_assets() {
218
+
219
+ }
220
+ }
221
+
222
  }
admin/includes/templates/settings-section-one.php CHANGED
@@ -1,3 +1,3 @@
1
- <p><br>Thank you for using Content Views!</p>
2
- <p>You are using
3
  <strong>Free</strong> version: <?php echo esc_html( PT_CV_Functions::plugin_info( PT_CV_FILE, 'Version' ) ); ?></p>
1
+ <p><br>Thank you for using Content Views!</p>
2
+ <p>You are using
3
  <strong>Free</strong> version: <?php echo esc_html( PT_CV_Functions::plugin_info( PT_CV_FILE, 'Version' ) ); ?></p>
admin/includes/templates/settings-section-two.php CHANGED
@@ -1,135 +1,135 @@
1
- <hr>
2
- <p>Here is list of some of awesome features which are available at
3
- <a href="http://www.contentviewspro.com/?utm_source=settings_page&utm_medium=link&utm_campaign=content-views" target="_blank">Content Views PRO</a>
4
- </p>
5
-
6
- <p>
7
- <a href="http://www.contentviewspro.com/pricing/?utm_source=settings_page&utm_medium=link&utm_campaign=content-views" target="_blank" class="btn btn-success">Upgrade now</a>
8
- or <a href="http://sample.contentviewspro.com/?utm_source=client&utm_medium=view" target="_blank" class="btn btn-info">Check demo site</a>
9
- </p>
10
-
11
- <div class="row">
12
- <div class="col-md-6">
13
- <h3>
14
- Query custom post types
15
- </h3>
16
-
17
- <div>
18
- <p>You can get any posts of any custom post types (<strong>WooCommerce</strong> product, FAQ, Book...)</p>
19
-
20
- <p>Especially, with <strong>WooCommerce</strong>, there are quick filters to pick up</p>
21
- <ul style="list-style: circle; margin-left: 20px;">
22
- <li>Recent products</li>
23
- <li>Best selling products</li>
24
- <li>Features products</li>
25
- <li>Top rated products</li>
26
- </ul>
27
- easily
28
- </div>
29
- </div>
30
- <div class="col-md-6">
31
- <div>
32
- <img src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/woocommerce.png', PT_CV_FILE ) ); ?>" />
33
- </div>
34
- </div>
35
- </div>
36
-
37
- <hr>
38
-
39
- <div class="row">
40
- <div class="col-md-12">
41
- <h3>
42
- More beautiful & awesome layouts
43
- </h3>
44
-
45
- <div>
46
- <div class="row">
47
- <div class="col-md-6">
48
- <h6>Scrollable list</h6>
49
-
50
- <div>
51
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/scrollable.png', PT_CV_FILE ) ); ?>" />
52
- </div>
53
- </div>
54
- <div class="col-md-6">
55
- <h6>Collapsible list</h6>
56
-
57
- <div>
58
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/collapsible.png', PT_CV_FILE ) ); ?>" />
59
- </div>
60
- </div>
61
- </div>
62
- <div class="row">
63
- <div class="col-md-6">
64
- <h6>Pinterest</h6>
65
-
66
- <div>
67
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/pinterest.png', PT_CV_FILE ) ); ?>" />
68
- </div>
69
- </div>
70
- <div class="col-md-6">
71
- <h6>Timeline</h6>
72
-
73
- <div>
74
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/timeline.png', PT_CV_FILE ) ); ?>" />
75
- </div>
76
- </div>
77
- </div>
78
- </div>
79
- </div>
80
- </div>
81
-
82
- <hr>
83
-
84
- <div class="row">
85
- <div class="col-md-6">
86
- <h3>
87
- Drag & drop to change display order of fields
88
- </h3>
89
-
90
- <div>
91
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/drag_drop.png', PT_CV_FILE ) ); ?>" />
92
- </div>
93
- </div>
94
- <div class="col-md-6">
95
- <h3>
96
- Read more settings
97
- </h3>
98
-
99
- <div>
100
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/readmore.png', PT_CV_FILE ) ); ?>" />
101
- </div>
102
- </div>
103
- </div>
104
-
105
- <hr>
106
-
107
- <div class="row">
108
- <div class="col-md-6">
109
- <h3>
110
- Custom font settings
111
- </h3>
112
-
113
- <div>
114
- <p>You can customize Font family (from top 50 most popular Google fonts), font style, font size for Title, Content, Meta fields easily</p>
115
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/font-settings.png', PT_CV_FILE ) ); ?>" style="height: 210px;" />
116
- </div>
117
- </div>
118
- <div class="col-md-6">
119
- <h3>
120
- And more powerful options
121
- </h3>
122
-
123
- <div>
124
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/pagination.png', PT_CV_FILE ) ); ?>" />
125
- <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/openin.png', PT_CV_FILE ) ); ?>" />
126
- <br> <span style="font-size: 30px;">...</span>
127
- </div>
128
- </div>
129
- </div>
130
-
131
- <hr>
132
-
133
- <p>I hope you enjoy with Content Views!</p>
134
- <p>Plugin developed by PT Guy (support@contentviewspro.com)</p>
135
  <p>Copyright &COPY; 2014</p>
1
+ <hr>
2
+ <p>Here is list of some of awesome features which are available at
3
+ <a href="http://www.contentviewspro.com/?utm_source=settings_page&utm_medium=link&utm_campaign=content-views" target="_blank">Content Views PRO</a>
4
+ </p>
5
+
6
+ <p>
7
+ <a href="http://www.contentviewspro.com/pricing/?utm_source=settings_page&utm_medium=link&utm_campaign=content-views" target="_blank" class="btn btn-success">Upgrade now</a>
8
+ or <a href="http://sample.contentviewspro.com/?utm_source=client&utm_medium=view" target="_blank" class="btn btn-info">Check demo site</a>
9
+ </p>
10
+
11
+ <div class="row">
12
+ <div class="col-md-6">
13
+ <h3>
14
+ Query custom post types
15
+ </h3>
16
+
17
+ <div>
18
+ <p>You can get any posts of any custom post types (<strong>WooCommerce</strong> product, FAQ, Book...)</p>
19
+
20
+ <p>Especially, with <strong>WooCommerce</strong>, there are quick filters to pick up</p>
21
+ <ul style="list-style: circle; margin-left: 20px;">
22
+ <li>Recent products</li>
23
+ <li>Best selling products</li>
24
+ <li>Features products</li>
25
+ <li>Top rated products</li>
26
+ </ul>
27
+ easily
28
+ </div>
29
+ </div>
30
+ <div class="col-md-6">
31
+ <div>
32
+ <img src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/woocommerce.png', PT_CV_FILE ) ); ?>" />
33
+ </div>
34
+ </div>
35
+ </div>
36
+
37
+ <hr>
38
+
39
+ <div class="row">
40
+ <div class="col-md-12">
41
+ <h3>
42
+ More beautiful & awesome layouts
43
+ </h3>
44
+
45
+ <div>
46
+ <div class="row">
47
+ <div class="col-md-6">
48
+ <h6>Scrollable list</h6>
49
+
50
+ <div>
51
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/scrollable.png', PT_CV_FILE ) ); ?>" />
52
+ </div>
53
+ </div>
54
+ <div class="col-md-6">
55
+ <h6>Collapsible list</h6>
56
+
57
+ <div>
58
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/collapsible.png', PT_CV_FILE ) ); ?>" />
59
+ </div>
60
+ </div>
61
+ </div>
62
+ <div class="row">
63
+ <div class="col-md-6">
64
+ <h6>Pinterest</h6>
65
+
66
+ <div>
67
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/pinterest.png', PT_CV_FILE ) ); ?>" />
68
+ </div>
69
+ </div>
70
+ <div class="col-md-6">
71
+ <h6>Timeline</h6>
72
+
73
+ <div>
74
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/timeline.png', PT_CV_FILE ) ); ?>" />
75
+ </div>
76
+ </div>
77
+ </div>
78
+ </div>
79
+ </div>
80
+ </div>
81
+
82
+ <hr>
83
+
84
+ <div class="row">
85
+ <div class="col-md-6">
86
+ <h3>
87
+ Drag & drop to change display order of fields
88
+ </h3>
89
+
90
+ <div>
91
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/drag_drop.png', PT_CV_FILE ) ); ?>" />
92
+ </div>
93
+ </div>
94
+ <div class="col-md-6">
95
+ <h3>
96
+ Read more settings
97
+ </h3>
98
+
99
+ <div>
100
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/readmore.png', PT_CV_FILE ) ); ?>" />
101
+ </div>
102
+ </div>
103
+ </div>
104
+
105
+ <hr>
106
+
107
+ <div class="row">
108
+ <div class="col-md-6">
109
+ <h3>
110
+ Custom font settings
111
+ </h3>
112
+
113
+ <div>
114
+ <p>You can customize Font family (from top 50 most popular Google fonts), font style, font size for Title, Content, Meta fields easily</p>
115
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/font-settings.png', PT_CV_FILE ) ); ?>" style="height: 210px;" />
116
+ </div>
117
+ </div>
118
+ <div class="col-md-6">
119
+ <h3>
120
+ And more powerful options
121
+ </h3>
122
+
123
+ <div>
124
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/pagination.png', PT_CV_FILE ) ); ?>" />
125
+ <img class="thumbnail" src="<?php echo esc_url( plugins_url( 'admin/assets/images/features/openin.png', PT_CV_FILE ) ); ?>" />
126
+ <br> <span style="font-size: 30px;">...</span>
127
+ </div>
128
+ </div>
129
+ </div>
130
+
131
+ <hr>
132
+
133
+ <p>I hope you enjoy with Content Views!</p>
134
+ <p>Plugin developed by PT Guy (support@contentviewspro.com)</p>
135
  <p>Copyright &COPY; 2014</p>
admin/views/view.php CHANGED
@@ -285,162 +285,164 @@ $options = array(
285
  'params' => array(
286
  array(
287
  'type' => 'panel_group',
288
- 'params' => array(
 
289
 
290
- // Taxonomies Settings
291
- 'taxonomy' => array(
292
 
293
- // Taxonomies list
294
- array(
295
- 'label' => array(
296
- 'text' => __( 'Taxonomies', PT_CV_DOMAIN ),
297
- ),
298
- 'params' => array(
299
- array(
300
- 'type' => 'checkbox',
301
- 'name' => 'taxonomy[]',
302
- 'options' => PT_CV_Values::taxonomy_list(),
303
- 'std' => '',
304
- 'class' => 'taxonomy-item',
305
- 'desc' => __( 'Select checkbox of taxonomies to filter posts by their terms', PT_CV_DOMAIN ),
306
  ),
307
- ),
308
- ),
309
-
310
- // Terms list
311
- array(
312
- 'label' => array(
313
- 'text' => __( 'Terms', PT_CV_DOMAIN ),
314
- ),
315
- 'extra_setting' => array(
316
  'params' => array(
317
- 'wrap-class' => PT_CV_Html::html_panel_group_class() . ' terms',
318
- 'wrap-id' => PT_CV_Html::html_panel_group_id( PT_CV_Functions::string_random() ),
319
- ),
320
- ),
321
- 'params' => array(
322
- array(
323
- 'type' => 'panel_group',
324
- 'settings' => array(
325
- 'nice_name' => PT_CV_Values::taxonomy_list(),
326
  ),
327
- 'params' => PT_CV_Settings::terms_of_taxonomies(),
328
  ),
329
  ),
330
- ),
331
 
332
- // Relation of taxonomies
333
- array(
334
- 'label' => array(
335
- 'text' => __( 'Relation', PT_CV_DOMAIN ),
336
- ),
337
- 'params' => array(
338
- array(
339
- 'type' => 'select',
340
- 'name' => 'taxonomy-relation',
341
- 'options' => PT_CV_Values::taxonomy_relation(),
342
- 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::taxonomy_relation() ),
343
- 'class' => 'taxonomy-relation',
344
- 'desc' => __( 'Select AND to show posts which match ALL settings of selected taxonomies<br>Select OR to show posts which match settings of at least one selected taxonomy', PT_CV_DOMAIN ),
 
 
 
 
 
 
345
  ),
346
  ),
347
- ),
348
- ), // End Taxonomies Settings
349
 
350
- // Order by Settings
351
- 'order' => array(
352
- array(
353
- 'label' => array(
354
- 'text' => __( 'Order by', PT_CV_DOMAIN ),
355
- ),
356
- 'extra_setting' => array(
357
- 'params' => array(
358
- 'width' => 12,
359
  ),
360
- ),
361
- 'params' => array(
362
- array(
363
- 'type' => 'panel_group',
364
- 'settings' => array(
365
- 'show_all' => 1,
 
 
366
  ),
367
- 'params' => PT_CV_Settings::orderby(),
368
  ),
369
  ),
370
- ),
371
- ), // End Order by Settings
372
 
373
- // Author Settings
374
- 'author' => array(
375
- array(
376
- 'label' => array(
377
- 'text' => __( 'Written by', PT_CV_DOMAIN ),
378
- ),
379
- 'params' => array(
380
- array(
381
- 'type' => 'select',
382
- 'name' => 'author__in[]',
383
- 'options' => PT_CV_Values::user_list(),
384
- 'std' => '',
385
- 'class' => 'select2',
386
- 'multiple' => $version_gt_37 ? '1' : '0',
 
 
 
 
 
387
  ),
388
  ),
389
- ),
390
- $version_gt_37 ?
 
 
391
  array(
392
  'label' => array(
393
- 'text' => __( 'Not written by', PT_CV_DOMAIN ),
394
  ),
395
  'params' => array(
396
  array(
397
  'type' => 'select',
398
- 'name' => 'author__not_in[]',
399
  'options' => PT_CV_Values::user_list(),
400
  'std' => '',
401
  'class' => 'select2',
402
  'multiple' => $version_gt_37 ? '1' : '0',
403
  ),
404
  ),
405
- ) : array(),
406
- ), // End Author Settings
407
-
408
- // Status Settings
409
- 'status' => array(
410
- array(
411
- 'label' => array(
412
- 'text' => __( 'Status', PT_CV_DOMAIN ),
413
  ),
414
- 'params' => array(
415
  array(
416
- 'type' => 'select',
417
- 'name' => 'post_status',
418
- 'options' => PT_CV_Values::post_statuses(),
419
- 'std' => 'publish',
420
- 'class' => 'select2',
421
- 'multiple' => '1',
422
- 'desc' => __( 'Select status of posts', PT_CV_DOMAIN ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
  ),
424
  ),
425
- ),
426
- ), // End Status Settings
427
 
428
- // Keyword Settings
429
- 'search' => array(
430
- array(
431
- 'label' => array(
432
- 'text' => __( 'Keyword', PT_CV_DOMAIN ),
433
- ),
434
- 'params' => array(
435
- array(
436
- 'type' => 'text',
437
- 'name' => 's',
438
- 'std' => '',
439
- 'desc' => __( 'Enter the keyword to searching for posts', PT_CV_DOMAIN ),
 
440
  ),
441
  ),
442
- ),
443
- ), // End Keyword Settings
444
  ),
445
  ),
446
  ),
285
  'params' => array(
286
  array(
287
  'type' => 'panel_group',
288
+ 'params' => apply_filters( PT_CV_PREFIX_ . 'advanced_settings_panel',
289
+ array(
290
 
291
+ // Taxonomies Settings
292
+ 'taxonomy' => array(
293
 
294
+ // Taxonomies list
295
+ array(
296
+ 'label' => array(
297
+ 'text' => __( 'Taxonomies', PT_CV_DOMAIN ),
 
 
 
 
 
 
 
 
 
298
  ),
 
 
 
 
 
 
 
 
 
299
  'params' => array(
300
+ array(
301
+ 'type' => 'checkbox',
302
+ 'name' => 'taxonomy[]',
303
+ 'options' => PT_CV_Values::taxonomy_list(),
304
+ 'std' => '',
305
+ 'class' => 'taxonomy-item',
306
+ 'desc' => __( 'Select checkbox of taxonomies to filter posts by their terms', PT_CV_DOMAIN ),
 
 
307
  ),
 
308
  ),
309
  ),
 
310
 
311
+ // Terms list
312
+ array(
313
+ 'label' => array(
314
+ 'text' => __( 'Terms', PT_CV_DOMAIN ),
315
+ ),
316
+ 'extra_setting' => array(
317
+ 'params' => array(
318
+ 'wrap-class' => PT_CV_Html::html_panel_group_class() . ' terms',
319
+ 'wrap-id' => PT_CV_Html::html_panel_group_id( PT_CV_Functions::string_random() ),
320
+ ),
321
+ ),
322
+ 'params' => array(
323
+ array(
324
+ 'type' => 'panel_group',
325
+ 'settings' => array(
326
+ 'nice_name' => PT_CV_Values::taxonomy_list(),
327
+ ),
328
+ 'params' => PT_CV_Settings::terms_of_taxonomies(),
329
+ ),
330
  ),
331
  ),
 
 
332
 
333
+ // Relation of taxonomies
334
+ array(
335
+ 'label' => array(
336
+ 'text' => __( 'Relation', PT_CV_DOMAIN ),
 
 
 
 
 
337
  ),
338
+ 'params' => array(
339
+ array(
340
+ 'type' => 'select',
341
+ 'name' => 'taxonomy-relation',
342
+ 'options' => PT_CV_Values::taxonomy_relation(),
343
+ 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::taxonomy_relation() ),
344
+ 'class' => 'taxonomy-relation',
345
+ 'desc' => __( 'Select AND to show posts which match ALL settings of selected taxonomies<br>Select OR to show posts which match settings of at least one selected taxonomy', PT_CV_DOMAIN ),
346
  ),
 
347
  ),
348
  ),
349
+ ), // End Taxonomies Settings
 
350
 
351
+ // Order by Settings
352
+ 'order' => array(
353
+ array(
354
+ 'label' => array(
355
+ 'text' => __( 'Order by', PT_CV_DOMAIN ),
356
+ ),
357
+ 'extra_setting' => array(
358
+ 'params' => array(
359
+ 'width' => 12,
360
+ ),
361
+ ),
362
+ 'params' => array(
363
+ array(
364
+ 'type' => 'panel_group',
365
+ 'settings' => array(
366
+ 'show_all' => 1,
367
+ ),
368
+ 'params' => PT_CV_Settings::orderby(),
369
+ ),
370
  ),
371
  ),
372
+ ), // End Order by Settings
373
+
374
+ // Author Settings
375
+ 'author' => array(
376
  array(
377
  'label' => array(
378
+ 'text' => __( 'Written by', PT_CV_DOMAIN ),
379
  ),
380
  'params' => array(
381
  array(
382
  'type' => 'select',
383
+ 'name' => 'author__in[]',
384
  'options' => PT_CV_Values::user_list(),
385
  'std' => '',
386
  'class' => 'select2',
387
  'multiple' => $version_gt_37 ? '1' : '0',
388
  ),
389
  ),
 
 
 
 
 
 
 
 
390
  ),
391
+ $version_gt_37 ?
392
  array(
393
+ 'label' => array(
394
+ 'text' => __( 'Not written by', PT_CV_DOMAIN ),
395
+ ),
396
+ 'params' => array(
397
+ array(
398
+ 'type' => 'select',
399
+ 'name' => 'author__not_in[]',
400
+ 'options' => PT_CV_Values::user_list(),
401
+ 'std' => '',
402
+ 'class' => 'select2',
403
+ 'multiple' => $version_gt_37 ? '1' : '0',
404
+ ),
405
+ ),
406
+ ) : array(),
407
+ ), // End Author Settings
408
+
409
+ // Status Settings
410
+ 'status' => array(
411
+ array(
412
+ 'label' => array(
413
+ 'text' => __( 'Status', PT_CV_DOMAIN ),
414
+ ),
415
+ 'params' => array(
416
+ array(
417
+ 'type' => 'select',
418
+ 'name' => 'post_status',
419
+ 'options' => PT_CV_Values::post_statuses(),
420
+ 'std' => 'publish',
421
+ 'class' => 'select2',
422
+ 'multiple' => '1',
423
+ 'desc' => __( 'Select status of posts', PT_CV_DOMAIN ),
424
+ ),
425
  ),
426
  ),
427
+ ), // End Status Settings
 
428
 
429
+ // Keyword Settings
430
+ 'search' => array(
431
+ array(
432
+ 'label' => array(
433
+ 'text' => __( 'Keyword', PT_CV_DOMAIN ),
434
+ ),
435
+ 'params' => array(
436
+ array(
437
+ 'type' => 'text',
438
+ 'name' => 's',
439
+ 'std' => '',
440
+ 'desc' => __( 'Enter the keyword to searching for posts', PT_CV_DOMAIN ),
441
+ ),
442
  ),
443
  ),
444
+ ), // End Keyword Settings
445
+ )
446
  ),
447
  ),
448
  ),
content-views.php CHANGED
@@ -10,7 +10,7 @@
10
  * Plugin Name: Content Views
11
  * Plugin URI: http://wordpress.org/plugins/content-views-query-and-display-post-page/
12
  * Description: Query and display <strong>posts, pages</strong> in awesome layouts (<strong>grid, scrollable list, collapsible list</strong>) easier than ever, without coding!
13
- * Version: 1.3.1.8
14
  * Author: PT Guy
15
  * Author URI: http://profiles.wordpress.org/pt-guy
16
  * Text Domain: content-views
@@ -27,7 +27,7 @@ if ( ! defined( 'WPINC' ) ) {
27
  /*
28
  * Define Constant
29
  */
30
- define( 'PT_CV_VERSION', '1.3.1.8' );
31
  define( 'PT_CV_FILE', __FILE__ );
32
  $pt_cv_path = plugin_dir_path( __FILE__ );
33
  include_once( $pt_cv_path . 'includes/defines.php' );
10
  * Plugin Name: Content Views
11
  * Plugin URI: http://wordpress.org/plugins/content-views-query-and-display-post-page/
12
  * Description: Query and display <strong>posts, pages</strong> in awesome layouts (<strong>grid, scrollable list, collapsible list</strong>) easier than ever, without coding!
13
+ * Version: 1.3.1.9
14
  * Author: PT Guy
15
  * Author URI: http://profiles.wordpress.org/pt-guy
16
  * Text Domain: content-views
27
  /*
28
  * Define Constant
29
  */
30
+ define( 'PT_CV_VERSION', '1.3.1.9' );
31
  define( 'PT_CV_FILE', __FILE__ );
32
  $pt_cv_path = plugin_dir_path( __FILE__ );
33
  include_once( $pt_cv_path . 'includes/defines.php' );
includes/assets.php CHANGED
@@ -1,197 +1,197 @@
1
- <?php
2
- /**
3
- * Asset management
4
- *
5
- * Register, enqueue, localize asset functions
6
- *
7
- * @package PT_Content_Views
8
- * @author PT Guy <palaceofthemes@gmail.com>
9
- * @license GPL-2.0+
10
- * @link http://www.contentviewspro.com/
11
- * @copyright 2014 PT Guy
12
- */
13
-
14
- if ( ! class_exists( 'PT_CV_Asset' ) ) {
15
-
16
- /**
17
- * @name PT_CV_Asset
18
- * @todo Register, enqueue, localize asset functions
19
- */
20
- class PT_CV_Asset {
21
-
22
- // Prefix for handle of all assets
23
- static $prefix = PT_CV_PREFIX;
24
- // Array of style & script
25
- static $assets = array();
26
- /**
27
- * version of assets
28
- * if an asset doesn't have configed version, it will get plugin version as asset version
29
- */
30
- static $version = array(
31
- 'bootstrap' => '3.1.1',
32
- 'bootstrap-paginator' => '0.5',
33
- 'select2' => '3.4.5',
34
- 'select2-bootstrap' => '3.4.5',
35
- );
36
-
37
- /**
38
- * Register assets to enqueue later
39
- */
40
- static function register() {
41
- self::$assets['style'] = self::style();
42
- self::$assets['script'] = self::script();
43
- }
44
-
45
- /**
46
- * Enqueue registered assets
47
- *
48
- * @param string $name Asset slug name
49
- * @param string $type Asset type (css/js)
50
- * @param array $data Asset data (url, depends, version...)
51
- * @param string $prefix Prefix string for asset
52
- */
53
- static function enqueue( $name, $type = 'script', $data = '', $prefix = '' ) {
54
-
55
- // If asset is registered, get handle information $data
56
- if ( array_key_exists( $name, self::$assets[$type] ) ) {
57
- $data = self::$assets[$type][$name];
58
- }
59
-
60
- // Do action
61
- self::action( $name, (array) $data, $type, 'enqueue', $prefix );
62
- }
63
-
64
- /**
65
- * Styles list
66
- *
67
- * @return array
68
- */
69
- static function style() {
70
- return array(
71
- 'bootstrap' => array(
72
- 'src' => plugins_url( 'assets/bootstrap/css/bootstrap.min.css', PT_CV_FILE ),
73
- ),
74
- 'select2' => array(
75
- 'src' => plugins_url( 'assets/select2/select2.min.css', PT_CV_FILE ),
76
- ),
77
- 'select2-bootstrap' => array(
78
- 'src' => plugins_url( 'assets/select2/select2-bootstrap.min.css', PT_CV_FILE ),
79
- ),
80
- );
81
- }
82
-
83
- /**
84
- * Scripts list
85
- *
86
- * @return array
87
- */
88
- static function script() {
89
- return array(
90
- 'bootstrap' => array(
91
- 'src' => plugins_url( 'assets/bootstrap/js/bootstrap.min.js', PT_CV_FILE ),
92
- 'deps' => array( 'jquery' ),
93
- ),
94
- 'bootstrap-paginator' => array(
95
- 'src' => plugins_url( 'assets/bootstrap-paginator/bootstrap-paginator.min.js', PT_CV_FILE ),
96
- // 'deps' => array( PT_CV_PREFIX . 'bootstrap' . '-' . 'script' ),
97
- ),
98
- 'select2' => array(
99
- 'src' => plugins_url( 'assets/select2/select2.min.js', PT_CV_FILE ),
100
- 'deps' => array( 'jquery' ),
101
- ),
102
- );
103
- }
104
-
105
- /**
106
- * Get version of handle
107
- *
108
- * @param string $name Asset slug name
109
- * @param array $data Asset data (url, depends, version...)
110
- *
111
- * @return string
112
- */
113
- static function get_version( $name, $data ) {
114
-
115
- if ( isset( $data['ver'] ) ) {
116
- return $data['ver'];
117
- }
118
-
119
- if ( array_key_exists( $name, self::$version ) ) {
120
- return self::$version[$name];
121
- }
122
-
123
- return PT_CV_Functions::plugin_info( PT_CV_FILE, 'Version' );
124
- }
125
-
126
- /**
127
- * Register / Enqueue a style / script
128
- *
129
- * @param string $name Asset slug name
130
- * @param string $data Asset information
131
- * @param string $type Asset type (css/js)
132
- * @param string $action Action to executing: enqueue / register
133
- * @param string $prefix Prefix string for asset
134
- */
135
- static function action( $name, $data, $type, $action, $prefix ) {
136
- $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
137
- $handle = $prefix_ . $name . '-' . $type;
138
- $src = isset( $data['src'] ) ? $data['src'] : '';
139
- $deps = isset( $data['deps'] ) ? $data['deps'] : '';
140
- $ver = self::get_version( $name, $data );
141
-
142
- if ( $type == 'style' ) {
143
- $last_param = isset( $data['media'] ) ? $data['media'] : 'all';
144
- } else {
145
- // Auto enqueue script in footer
146
- $last_param = isset( $data['in_footer'] ) ? $data['in_footer'] : true;
147
- }
148
- $function = "wp_{$action}_{$type}";
149
- if ( function_exists( $function ) ) {
150
- $function( $handle, $src, $deps, $ver, $last_param );
151
- }
152
- }
153
-
154
- /**
155
- * Localize script
156
- *
157
- * @param string $name Asset slug name
158
- * @param string $object_name The name of the variable which will contain the data
159
- * @param string $translation_array Array of translation strings
160
- * @param string $prefix Prefix string for asset
161
- */
162
- static function localize_script( $name, $object_name, $translation_array, $prefix = '' ) {
163
- $type = 'script';
164
- $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
165
- $handle = $prefix_ . $name . '-' . $type;
166
-
167
- wp_localize_script( $handle, $object_name, $translation_array );
168
- }
169
-
170
- /**
171
- * Include asset files directly in page
172
- *
173
- * @param string $name Asset slug name
174
- * @param string $scr The link to asset file
175
- * @param string $type Asset type (css/js)
176
- * @param string $prefix Prefix string for asset
177
- */
178
- static function include_inline( $name, $src, $type, $prefix = '' ) {
179
- $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
180
- $handle = $prefix_ . $name . '-' . $type;
181
-
182
- switch ( $type ) {
183
- case 'js':
184
- printf( "<script type='text/javascript' src='%s'></script>", $src );
185
- break;
186
-
187
- case 'css':
188
- printf( "<link rel='stylesheet' id='%s' href='%s' type='text/css' media='all' />", esc_attr( $handle ), esc_url( $src ) );
189
- break;
190
- }
191
- }
192
-
193
- }
194
- }
195
-
196
- // Call to run
197
  PT_CV_Asset::register();
1
+ <?php
2
+ /**
3
+ * Asset management
4
+ *
5
+ * Register, enqueue, localize asset functions
6
+ *
7
+ * @package PT_Content_Views
8
+ * @author PT Guy <palaceofthemes@gmail.com>
9
+ * @license GPL-2.0+
10
+ * @link http://www.contentviewspro.com/
11
+ * @copyright 2014 PT Guy
12
+ */
13
+
14
+ if ( ! class_exists( 'PT_CV_Asset' ) ) {
15
+
16
+ /**
17
+ * @name PT_CV_Asset
18
+ * @todo Register, enqueue, localize asset functions
19
+ */
20
+ class PT_CV_Asset {
21
+
22
+ // Prefix for handle of all assets
23
+ static $prefix = PT_CV_PREFIX;
24
+ // Array of style & script
25
+ static $assets = array();
26
+ /**
27
+ * version of assets
28
+ * if an asset doesn't have configed version, it will get plugin version as asset version
29
+ */
30
+ static $version = array(
31
+ 'bootstrap' => '3.1.1',
32
+ 'bootstrap-paginator' => '0.5',
33
+ 'select2' => '3.4.5',
34
+ 'select2-bootstrap' => '3.4.5',
35
+ );
36
+
37
+ /**
38
+ * Register assets to enqueue later
39
+ */
40
+ static function register() {
41
+ self::$assets['style'] = self::style();
42
+ self::$assets['script'] = self::script();
43
+ }
44
+
45
+ /**
46
+ * Enqueue registered assets
47
+ *
48
+ * @param string $name Asset slug name
49
+ * @param string $type Asset type (css/js)
50
+ * @param array $data Asset data (url, depends, version...)
51
+ * @param string $prefix Prefix string for asset
52
+ */
53
+ static function enqueue( $name, $type = 'script', $data = '', $prefix = '' ) {
54
+
55
+ // If asset is registered, get handle information $data
56
+ if ( array_key_exists( $name, self::$assets[$type] ) ) {
57
+ $data = self::$assets[$type][$name];
58
+ }
59
+
60
+ // Do action
61
+ self::action( $name, (array) $data, $type, 'enqueue', $prefix );
62
+ }
63
+
64
+ /**
65
+ * Styles list
66
+ *
67
+ * @return array
68
+ */
69
+ static function style() {
70
+ return array(
71
+ 'bootstrap' => array(
72
+ 'src' => plugins_url( 'assets/bootstrap/css/bootstrap.min.css', PT_CV_FILE ),
73
+ ),
74
+ 'select2' => array(
75
+ 'src' => plugins_url( 'assets/select2/select2.min.css', PT_CV_FILE ),
76
+ ),
77
+ 'select2-bootstrap' => array(
78
+ 'src' => plugins_url( 'assets/select2/select2-bootstrap.min.css', PT_CV_FILE ),
79
+ ),
80
+ );
81
+ }
82
+
83
+ /**
84
+ * Scripts list
85
+ *
86
+ * @return array
87
+ */
88
+ static function script() {
89
+ return array(
90
+ 'bootstrap' => array(
91
+ 'src' => plugins_url( 'assets/bootstrap/js/bootstrap.min.js', PT_CV_FILE ),
92
+ 'deps' => array( 'jquery' ),
93
+ ),
94
+ 'bootstrap-paginator' => array(
95
+ 'src' => plugins_url( 'assets/bootstrap-paginator/bootstrap-paginator.min.js', PT_CV_FILE ),
96
+ // 'deps' => array( PT_CV_PREFIX . 'bootstrap' . '-' . 'script' ),
97
+ ),
98
+ 'select2' => array(
99
+ 'src' => plugins_url( 'assets/select2/select2.min.js', PT_CV_FILE ),
100
+ 'deps' => array( 'jquery' ),
101
+ ),
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Get version of handle
107
+ *
108
+ * @param string $name Asset slug name
109
+ * @param array $data Asset data (url, depends, version...)
110
+ *
111
+ * @return string
112
+ */
113
+ static function get_version( $name, $data ) {
114
+
115
+ if ( isset( $data['ver'] ) ) {
116
+ return $data['ver'];
117
+ }
118
+
119
+ if ( array_key_exists( $name, self::$version ) ) {
120
+ return self::$version[$name];
121
+ }
122
+
123
+ return PT_CV_Functions::plugin_info( PT_CV_FILE, 'Version' );
124
+ }
125
+
126
+ /**
127
+ * Register / Enqueue a style / script
128
+ *
129
+ * @param string $name Asset slug name
130
+ * @param string $data Asset information
131
+ * @param string $type Asset type (css/js)
132
+ * @param string $action Action to executing: enqueue / register
133
+ * @param string $prefix Prefix string for asset
134
+ */
135
+ static function action( $name, $data, $type, $action, $prefix ) {
136
+ $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
137
+ $handle = $prefix_ . $name . '-' . $type;
138
+ $src = isset( $data['src'] ) ? $data['src'] : '';
139
+ $deps = isset( $data['deps'] ) ? $data['deps'] : '';
140
+ $ver = self::get_version( $name, $data );
141
+
142
+ if ( $type == 'style' ) {
143
+ $last_param = isset( $data['media'] ) ? $data['media'] : 'all';
144
+ } else {
145
+ // Auto enqueue script in footer
146
+ $last_param = isset( $data['in_footer'] ) ? $data['in_footer'] : true;
147
+ }
148
+ $function = "wp_{$action}_{$type}";
149
+ if ( function_exists( $function ) ) {
150
+ $function( $handle, $src, $deps, $ver, $last_param );
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Localize script
156
+ *
157
+ * @param string $name Asset slug name
158
+ * @param string $object_name The name of the variable which will contain the data
159
+ * @param string $translation_array Array of translation strings
160
+ * @param string $prefix Prefix string for asset
161
+ */
162
+ static function localize_script( $name, $object_name, $translation_array, $prefix = '' ) {
163
+ $type = 'script';
164
+ $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
165
+ $handle = $prefix_ . $name . '-' . $type;
166
+
167
+ wp_localize_script( $handle, $object_name, $translation_array );
168
+ }
169
+
170
+ /**
171
+ * Include asset files directly in page
172
+ *
173
+ * @param string $name Asset slug name
174
+ * @param string $scr The link to asset file
175
+ * @param string $type Asset type (css/js)
176
+ * @param string $prefix Prefix string for asset
177
+ */
178
+ static function include_inline( $name, $src, $type, $prefix = '' ) {
179
+ $prefix_ = ! empty( $prefix ) ? $prefix : self::$prefix;
180
+ $handle = $prefix_ . $name . '-' . $type;
181
+
182
+ switch ( $type ) {
183
+ case 'js':
184
+ printf( "<script type='text/javascript' src='%s'></script>", $src );
185
+ break;
186
+
187
+ case 'css':
188
+ printf( "<link rel='stylesheet' id='%s' href='%s' type='text/css' media='all' />", esc_attr( $handle ), esc_url( $src ) );
189
+ break;
190
+ }
191
+ }
192
+
193
+ }
194
+ }
195
+
196
+ // Call to run
197
  PT_CV_Asset::register();
includes/defines.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
- /**
3
- * Defines common constant
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- define( 'PT_CV_DOMAIN', 'content-views' );
13
- define( 'PT_CV_PREFIX', 'pt-cv-' );
14
- define( 'PT_CV_PREFIX_', 'pt_cv_' );
15
- define( 'PT_CV_PREFIX_UPPER', 'PT_CV_' );
16
-
17
- // Custom post type
18
- define( 'PT_CV_POST_TYPE', 'pt_view' );
19
-
20
- // Options
21
- define( 'PT_CV_OPTION_VERSION', PT_CV_PREFIX_ . 'version' );
22
- define( 'PT_CV_OPTION_NAME', PT_CV_PREFIX_ . 'options' );
23
-
24
- // Custom fields
25
- define( 'PT_CV_META_ID', '_' . PT_CV_PREFIX_ . 'id' );
26
- define( 'PT_CV_META_SETTINGS', '_' . PT_CV_PREFIX_ . 'settings' );
27
- define( 'PT_CV_META_VIEW_COUNT', '_' . PT_CV_PREFIX_ . 'view_count' );
28
-
29
- // Public assets directory
30
- define( 'PT_CV_PUBLIC_ASSETS', plugin_dir_path( PT_CV_FILE ) . 'public/assets/' );
31
-
32
- // Public assets uri
33
- define( 'PT_CV_PUBLIC_ASSETS_URI', plugins_url( 'public/assets/', PT_CV_FILE ) );
34
-
35
- // View type directory (HTML + CSS + JS)
36
  define( 'PT_CV_VIEW_TYPE_OUTPUT', plugin_dir_path( PT_CV_FILE ) . 'public/templates/' );
1
+ <?php
2
+ /**
3
+ * Defines common constant
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ define( 'PT_CV_DOMAIN', 'content-views' );
13
+ define( 'PT_CV_PREFIX', 'pt-cv-' );
14
+ define( 'PT_CV_PREFIX_', 'pt_cv_' );
15
+ define( 'PT_CV_PREFIX_UPPER', 'PT_CV_' );
16
+
17
+ // Custom post type
18
+ define( 'PT_CV_POST_TYPE', 'pt_view' );
19
+
20
+ // Options
21
+ define( 'PT_CV_OPTION_VERSION', PT_CV_PREFIX_ . 'version' );
22
+ define( 'PT_CV_OPTION_NAME', PT_CV_PREFIX_ . 'options' );
23
+
24
+ // Custom fields
25
+ define( 'PT_CV_META_ID', '_' . PT_CV_PREFIX_ . 'id' );
26
+ define( 'PT_CV_META_SETTINGS', '_' . PT_CV_PREFIX_ . 'settings' );
27
+ define( 'PT_CV_META_VIEW_COUNT', '_' . PT_CV_PREFIX_ . 'view_count' );
28
+
29
+ // Public assets directory
30
+ define( 'PT_CV_PUBLIC_ASSETS', plugin_dir_path( PT_CV_FILE ) . 'public/assets/' );
31
+
32
+ // Public assets uri
33
+ define( 'PT_CV_PUBLIC_ASSETS_URI', plugins_url( 'public/assets/', PT_CV_FILE ) );
34
+
35
+ // View type directory (HTML + CSS + JS)
36
  define( 'PT_CV_VIEW_TYPE_OUTPUT', plugin_dir_path( PT_CV_FILE ) . 'public/templates/' );
includes/functions.php CHANGED
@@ -1,1144 +1,1144 @@
1
- <?php
2
- /**
3
- * Contain main functions to work with plugin, post, custom fields...
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! function_exists( 'get_plugin_data' ) ) {
13
- require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
14
- }
15
- if ( ! class_exists( 'PT_CV_Functions' ) ) {
16
-
17
- /**
18
- * @name PT_CV_Functions
19
- * @todo Utility functions
20
- */
21
- class PT_CV_Functions {
22
-
23
- static $prev_random_string = '';
24
-
25
- /**
26
- * Compare current Wordpress version with a version
27
- *
28
- * @global string $wp_version
29
- *
30
- * @param string $version_to_compare
31
- * @param string $operator
32
- *
33
- * @return boolean
34
- */
35
- static function wp_version_compare( $version_to_compare, $operator = '>=' ) {
36
- if ( empty( $version_to_compare ) ) {
37
- return true;
38
- }
39
-
40
- global $wp_version;
41
-
42
- // Check if using Wordpress version 3.7 or higher
43
- return version_compare( $wp_version, $version_to_compare, $operator );
44
- }
45
-
46
- /**
47
- * Get current language of site
48
- */
49
- static function get_language() {
50
- $language = '';
51
-
52
- // WPML
53
- global $sitepress;
54
- if ( $sitepress && method_exists( $sitepress, 'get_current_language' ) ) {
55
- $language = $sitepress->get_current_language();
56
- }
57
-
58
- return $language;
59
- }
60
-
61
- /**
62
- * Get plugin info
63
- *
64
- * @param string $file Absolute path to the plugin file
65
- * @param string $data Field of plugin data want to get
66
- *
67
- * @return array | null
68
- */
69
- static function plugin_info( $file, $data = '' ) {
70
- $plugin_data = get_plugin_data( $file );
71
-
72
- return isset( $plugin_data[$data] ) ? $plugin_data[$data] : NULL;
73
- }
74
-
75
- /**
76
- * Add sub menu page
77
- *
78
- * @param string $parent_slug Slug of parent menu
79
- * @param string $page_title Title of page
80
- * @param string $menu_title Title of menu
81
- * @param string $sub_page Slug of sub menu
82
- * @param string $class Class name which contains function to output content of page created by this menu
83
- */
84
- static function menu_add_sub( $parent_slug, $page_title, $menu_title, $sub_page, $class ) {
85
- // Get user role settings option
86
- $options = get_option( PT_CV_OPTION_NAME );
87
- $user_role = current_user_can( 'administrator' ) ? 'administrator' : ( isset( $options['access_role'] ) ? $options['access_role'] : 'edit_posts' );
88
-
89
- return add_submenu_page(
90
- $parent_slug, $page_title, $menu_title, $user_role, $parent_slug . '-' . $sub_page, array( $class, 'display_sub_page_' . $sub_page )
91
- );
92
- }
93
-
94
- /**
95
- * Get current post type in Admin
96
- *
97
- * @global type $post
98
- * @global type $typenow
99
- * @global type $current_screen
100
- * @return type
101
- */
102
- static function admin_current_post_type() {
103
- global $post, $typenow, $current_screen;
104
-
105
- //we have a post so we can just get the post type from that
106
- if ( $post && $post->post_type ) {
107
- return $post->post_type;
108
- } //check the global $typenow - set in admin.php
109
- elseif ( $typenow ) {
110
- return $typenow;
111
- } //check the global $current_screen object - set in sceen.php
112
- elseif ( $current_screen && isset( $current_screen->post_type ) ) {
113
- return $current_screen->post_type;
114
- }
115
- }
116
-
117
- /**
118
- * Include content of file
119
- *
120
- * @param string $file_path Absolute path of file
121
- *
122
- * @return NULL | string Content of file
123
- */
124
- static function file_include_content( $file_path ) {
125
- $content = NULL;
126
-
127
- if ( file_exists( $file_path ) ) {
128
- ob_start();
129
- include_once $file_path;
130
- $content = ob_get_clean();
131
- }
132
-
133
- return $content;
134
- }
135
-
136
- /**
137
- * Generate random string
138
- *
139
- * @param bool $prev_return Return previous generated string
140
- *
141
- * @return string
142
- */
143
- static function string_random( $prev_return = false ) {
144
- if ( $prev_return ) {
145
- return PT_CV_Functions::$prev_random_string;
146
- }
147
- PT_CV_Functions::$prev_random_string = substr( md5( rand() ), 0, 10 );
148
-
149
- return PT_CV_Functions::$prev_random_string;
150
- }
151
-
152
- /**
153
- * Create array from string, use explode function
154
- *
155
- * @param string $string String to explode
156
- * @param string $delimiter Delimiter to explode string
157
- *
158
- * @return array
159
- */
160
- static function string_to_array( $string, $delimiter = ',' ) {
161
- return is_array( $string ) ? $string : (array) explode( $delimiter, (string) str_replace( ' ', '', $string ) );
162
- }
163
-
164
- /**
165
- * Slug to nice String
166
- *
167
- * @param string $slug Slug string
168
- *
169
- * @return string
170
- */
171
- static function string_slug_to_text( $slug ) {
172
- $slug = preg_replace( '/[^a-z]+/', ' ', $slug );
173
-
174
- return ucwords( $slug );
175
- }
176
-
177
- /**
178
- * Get thumbnail dimensions
179
- *
180
- * @param array $fargs The settings of thumbnail
181
- *
182
- * @return array
183
- */
184
- static function field_thumbnail_dimensions( $fargs ) {
185
- $size = $fargs['size'];
186
-
187
- return (array) explode( '&times;', str_replace( ' ', '', $size ) );
188
- }
189
-
190
- /**
191
- * Get value of a setting from global settings array
192
- *
193
- * @param string $field The full name of setting to get value
194
- * @param array $array_to_get Array to get values of wanted setting
195
- * @param mixed|null $assign The value to assign if setting is not found
196
- */
197
- static function setting_value( $field, $array_to_get, $assign = NULL ) {
198
- return isset( $array_to_get[$field] ) ? $array_to_get[$field] : $assign;
199
- }
200
-
201
- /**
202
- * Get values of settings from global settings array
203
- *
204
- * @param array $fields Array of setting fields to get value
205
- * @param array $array_to_save Array to save values of wanted setting fields
206
- * @param array $array_to_get Array to get values of wanted setting fields
207
- * @param string $prefix Prefix string to looking for fields in $array_to_get
208
- */
209
- static function settings_values( $fields, &$array_to_save, $array_to_get, $prefix ) {
210
- foreach ( $fields as $tsetting ) {
211
- $array_to_save[$tsetting] = PT_CV_Functions::setting_value( $prefix . $tsetting, $array_to_get );
212
- }
213
- }
214
-
215
- /**
216
- * Get names of options for a setting group (setting name started by a prefix)
217
- *
218
- * @param string $prefix The prefix in name of settings
219
- * @param array $options The options array (contain full paramaters of settings)
220
- */
221
- static function settings_keys( $prefix, $options ) {
222
- $result = array();
223
- foreach ( $options as $option ) {
224
- if ( isset( $option['params'] ) ) {
225
- foreach ( $option['params'] as $params ) {
226
- // If name of setting match with prefix string, got it name
227
- if ( isset( $params['name'] ) && substr( $params['name'], 0, strlen( $prefix ) ) === $prefix ) {
228
- $result[] = substr( $params['name'], strlen( $prefix ) );
229
- }
230
- }
231
- }
232
- }
233
-
234
- return $result;
235
- }
236
-
237
- /**
238
- * Get value of some setting options by prefix
239
- *
240
- * @param string $prefix The prefix in name of setting options
241
- */
242
- static function settings_values_by_prefix( $prefix ) {
243
- global $pt_view_settings;
244
-
245
- $result = array();
246
-
247
- foreach ( $pt_view_settings as $name => $value ) {
248
- // If name of setting match with prefix string, got it name
249
- if ( substr( $name, 0, strlen( $prefix ) ) === $prefix ) {
250
- $result[substr( $name, strlen( $prefix ) )] = $value;
251
- }
252
- }
253
-
254
- return $result;
255
- }
256
-
257
- /**
258
- * Get terms list of a post
259
- *
260
- * @param object $post The post object
261
- *
262
- * @return string
263
- */
264
- static function post_terms( $post ) {
265
- global $pt_post_terms;
266
-
267
-
268
- // List of HTML link to terms
269
- $links = array();
270
-
271
- // Get list of taxonomies
272
- $taxonomies = get_taxonomies( '', 'names' );
273
-
274
- $taxonomies = apply_filters( PT_CV_PREFIX_ . 'taxonomies_list', $taxonomies );
275
-
276
- // Get post ID
277
- $post_id = is_object( $post ) ? $post->ID : $post;
278
-
279
- // Get lists of terms of this post
280
- $terms = wp_get_object_terms( $post_id, $taxonomies );
281
-
282
- foreach ( $terms as $term ) {
283
- $links[] = sprintf(
284
- '<a href="%1$s" title="%2$s %3$s">%3$s</a>',
285
- esc_url( get_term_link( $term, $term->taxonomy ) ),
286
- __( 'View all posts in', PT_CV_DOMAIN ),
287
- $term->name
288
- );
289
-
290
- if ( ! isset( $pt_post_terms[$post_id] ) ) {
291
- $pt_post_terms[$post_id] = array();
292
- }
293
- $pt_post_terms[$post_id][$term->slug] = $term->name;
294
- }
295
-
296
- return implode( ', ', $links );
297
- }
298
-
299
- /**
300
- * Update post view count
301
- *
302
- * @param string $post_id ID of post
303
- */
304
- static function post_update_view_count( $post_id ) {
305
- $meta_key = PT_CV_META_VIEW_COUNT;
306
- $count = get_post_meta( $post_id, $meta_key, true );
307
- if ( ! $count ) {
308
- $count = 0;
309
- }
310
- $count ++;
311
- update_post_meta( $post_id, $meta_key, $count );
312
- }
313
-
314
- /**
315
- * Get post view count
316
- *
317
- * @param string $post_id ID of post
318
- */
319
- static function post_get_view_count( $post_id ) {
320
- $meta_key = PT_CV_META_VIEW_COUNT;
321
- $count = get_post_meta( $post_id, $meta_key, true );
322
- if ( ! $count ) {
323
- $count = 1;
324
- }
325
-
326
- return _n( 'view', 'views', $count, PT_CV_DOMAIN );
327
- }
328
-
329
- /**
330
- * Insert/Update post
331
- *
332
- * @param string $arr Array of post data
333
- */
334
- static function post_insert( $arr ) {
335
- if ( ! $arr ) {
336
- return;
337
- }
338
- // Create post object
339
- $my_post = array(
340
- 'ID' => (int) $arr['ID'],
341
- 'post_type' => PT_CV_POST_TYPE,
342
- 'post_content' => '',
343
- 'post_title' => ! empty( $arr['title'] ) ? $arr['title'] : __( '(no title)', PT_CV_DOMAIN ),
344
- 'post_status' => 'publish',
345
- );
346
-
347
- // Insert the post into the database
348
- return wp_insert_post( $my_post );
349
- }
350
-
351
- /**
352
- * Get View id in post table, from "id" meta key value
353
- *
354
- * @param string $meta_id ID of custom field
355
- *
356
- * @return int Return Post ID of this view
357
- */
358
- static function post_id_from_meta_id( $meta_id ) {
359
-
360
- $post_id = 0;
361
- if ( ! $meta_id ) {
362
- return $post_id;
363
- }
364
-
365
- // Query view which has view id = $meta_id
366
- $pt_query = new WP_Query(
367
- array(
368
- 'post_type' => PT_CV_POST_TYPE,
369
- 'post_status' => 'publish',
370
- 'meta_key' => PT_CV_META_ID,
371
- 'meta_value' => esc_sql( $meta_id ),
372
- )
373
- );
374
- if ( $pt_query->have_posts() ) :
375
- while ( $pt_query->have_posts() ):
376
- $pt_query->the_post();
377
- $post_id = get_the_ID();
378
- endwhile;
379
- endif;
380
-
381
- return $post_id;
382
- }
383
-
384
- /**
385
- * Get first key of array
386
- *
387
- * @param array $args Array data
388
- *
389
- * @return string
390
- */
391
- static function array_get_first_key( $args ) {
392
- return current( array_keys( $args ) );
393
- }
394
-
395
- /**
396
- * Check valid request
397
- *
398
- * @param string $nonce_name Name of nonce field
399
- * @param string $action_name name of action relates to nonce field
400
- */
401
- static function _nonce_check( $nonce_name, $action_name ) {
402
- $nonce_name = PT_CV_PREFIX_ . $nonce_name;
403
- if ( ! isset( $_POST[$nonce_name] ) || ! wp_verify_nonce( $_POST[$nonce_name], PT_CV_PREFIX_ . $action_name ) ) {
404
- print esc_html( __( 'Sorry, your nonce did not verify.', PT_CV_DOMAIN ) );
405
- exit;
406
- }
407
- }
408
-
409
- /**
410
- * Get view data
411
- *
412
- * @param string $meta_id ID of custom field
413
- *
414
- * @return array
415
- */
416
- static function view_get_settings( $meta_id ) {
417
- if ( ! $meta_id ) {
418
- return;
419
- }
420
-
421
- $post_id = PT_CV_Functions::post_id_from_meta_id( $meta_id );
422
-
423
- // Get view settings
424
- if ( $post_id ) {
425
- $view_settings = get_post_meta( $post_id, PT_CV_META_SETTINGS, true );
426
-
427
- /* Backward compatibility
428
- * since 1.3.2
429
- */
430
- self::view_backward_comp( $view_settings );
431
-
432
- return is_array( $view_settings ) ? $view_settings : array();
433
- }
434
-
435
- return array();
436
- }
437
-
438
- /**
439
- * Update values for some new options in new version (from options in old version)
440
- *
441
- * @param type $view_settings
442
- */
443
- static function view_backward_comp( &$view_settings ) {
444
- if ( ! $view_settings )
445
- return $view_settings;
446
-
447
- $taxonomies = isset( $view_settings[ PT_CV_PREFIX . 'taxonomy'] ) ? $view_settings[ PT_CV_PREFIX . 'taxonomy'] : array();
448
- if ( $taxonomies ) {
449
- $list = array( '__in', '__not_in' );
450
- foreach ( $taxonomies as $taxonomy ) {
451
- // Check if IN/NOT IN list has values. NOT IN list will overwite IN list
452
- foreach ( $list as $ltype ) {
453
- if ( isset( $view_settings[PT_CV_PREFIX . $taxonomy . $ltype] ) ) {
454
- $view_settings[PT_CV_PREFIX . $taxonomy . '-terms'] = $view_settings[PT_CV_PREFIX . $taxonomy . $ltype];
455
- $view_settings[PT_CV_PREFIX . $taxonomy . '-operator'] = ( $ltype == '__in' ) ? 'IN' : 'NOT IN';
456
- }
457
- }
458
- }
459
- }
460
- }
461
-
462
- /**
463
- * Process view $settings array, return HTML output
464
- *
465
- * @param string $id The current view id
466
- * @param array $settings The settings array
467
- * @param array $pargs The pagination settings array
468
- *
469
- * @return string HTML output of Content View
470
- */
471
- static function view_process_settings( $id, $settings, $pargs = array() ) {
472
- if ( empty( $settings ) ) {
473
- return __( 'Empty settings', PT_CV_DOMAIN );
474
- }
475
-
476
- // Escaped value appropriate for use in a SQL query
477
- global $pt_view_settings;
478
-
479
- $pt_view_settings = array();
480
- foreach ( $settings as $key => $value ) {
481
- $pt_view_settings[$key] = esc_sql( $value );
482
- }
483
-
484
- // Get content type
485
- global $pt_content_type;
486
- $pt_content_type = $content_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'content-type', $pt_view_settings );
487
-
488
- // Get view type
489
- $view_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'view-type', $pt_view_settings );
490
-
491
- // Store display settings
492
- global $dargs, $pt_query_args;
493
-
494
- $session_id = ( $pargs && isset( $pargs['session_id'] ) ) ? $pargs['session_id'] : 0;
495
-
496
- if ( $session_id ) {
497
- $session_data = array_merge(
498
- array( '$args' => '', '$dargs' => '' ),
499
- ( false === ( $saved_settings = get_transient( PT_CV_PREFIX . 'view-data-' . $session_id ) ) ) ? array() : $saved_settings
500
- );
501
-
502
- $args = $session_data['$args'];
503
- $dargs = $session_data['$dargs'];
504
- } else {
505
- // Generate session key for pagination
506
- global $pt_view_sid;
507
- $pt_view_sid = $session_id = PT_CV_Functions::string_random();
508
-
509
- // Store settings
510
- set_transient( PT_CV_PREFIX . 'view-settings-' . $session_id, $settings, 30 * MINUTE_IN_SECONDS );
511
- }
512
-
513
- if ( empty( $args ) || empty( $dargs ) ) {
514
- $args = PT_CV_Functions::view_filter_settings( $content_type, $pt_view_settings );
515
- $dargs = PT_CV_Functions::view_display_settings( $view_type );
516
-
517
- // Filter
518
- $dargs = apply_filters( PT_CV_PREFIX_ . 'all_display_settings', $dargs );
519
- $args = apply_filters( PT_CV_PREFIX_ . 'query_parameters', $args );
520
-
521
- // Store view data
522
- set_transient(
523
- PT_CV_PREFIX . 'view-data-' . $session_id,
524
- array(
525
- '$args' => $args,
526
- '$dargs' => $dargs,
527
- ), 30 * MINUTE_IN_SECONDS
528
- );
529
- }
530
-
531
- // Pagination settings
532
- PT_CV_Functions::view_get_pagination_settings( $dargs, $args, $pargs );
533
-
534
- // Validate settings, if some required parameters are missing, show error and exit
535
- $error = apply_filters( PT_CV_PREFIX_ . 'validate_settings', array(), $args );
536
-
537
- // Return error message
538
- if ( $error ) {
539
- return ( implode( '</p><p>', $error ) );
540
- }
541
-
542
- // Update global query parameters variable
543
- $pt_query_args = $args;
544
-
545
- do_action( PT_CV_PREFIX_ . 'add_global_variables' );
546
-
547
- /**
548
- * Output Items
549
- */
550
-
551
- // Store HTML output of each item
552
- $content_items = array();
553
-
554
- // The Query
555
- do_action( PT_CV_PREFIX_ . 'before_query' );
556
-
557
- $pt_query = new WP_Query( $args );
558
-
559
- do_action( PT_CV_PREFIX_ . 'after_query' );
560
-
561
- // The Loop
562
- if ( $pt_query->have_posts() ) {
563
- while ( $pt_query->have_posts() ) {
564
- $pt_query->the_post();
565
- global $post;
566
-
567
- // Output HTML for this item
568
- $content_items[$post->ID] = PT_CV_Html::view_type_output( $view_type, $post );
569
- }
570
- } else {
571
- // Get no post found class
572
- $_class = apply_filters( PT_CV_PREFIX_ . 'content_no_post_found_class', 'alert alert-warning' );
573
-
574
- // Get no post found text
575
- $_text = apply_filters( PT_CV_PREFIX_ . 'content_no_post_found_text', __( 'No post found', PT_CV_DOMAIN ) );
576
-
577
- // Output HTML
578
- $content_items[] = sprintf( '<div class="%1$s">%2$s</div>', esc_attr( $_class ), balanceTags( $_text ) );
579
- }
580
-
581
- // Restore original Post Data
582
- wp_reset_postdata();
583
-
584
- // Filter array of items
585
- $content_items = apply_filters( PT_CV_PREFIX_ . 'content_items', $content_items );
586
-
587
- /**
588
- * Output Pagination
589
- */
590
- $current_page = ( isset( $pargs['page'] ) && $pargs['page'] > 1 ) ? $pargs['page'] : 1;
591
- $html = PT_CV_Html::content_items_wrap( $content_items, $current_page, $args['posts_per_page'], $id );
592
-
593
- // Append Pagination HTML if this is first page, or not Ajax calling
594
- if ( $args['posts_per_page'] > 0 && $current_page === 1 ) {
595
- // Total post founds
596
- $found_posts = apply_filters( PT_CV_PREFIX_ . 'found_posts', $pt_query->found_posts );
597
-
598
- // Total number of items
599
- $total_items = ( $args['limit'] > 0 && $found_posts > $args['limit'] ) ? $args['limit'] : $found_posts;
600
-
601
- // Total number of pages
602
- $max_num_pages = ceil( $total_items / $args['posts_per_page'] );
603
-
604
- // Output pagination
605
- $html .= "\n" . PT_CV_Html::pagination_output( $max_num_pages, $session_id );
606
- }
607
-
608
- return $html;
609
- }
610
-
611
- /**
612
- * Get query parameters of View
613
- *
614
- * @param string $content_type The current content type
615
- * @param array $pt_view_settings The settings of View
616
- * @return array
617
- */
618
- static function view_filter_settings( $content_type, $pt_view_settings ) {
619
- /**
620
- * Get Query parameters
621
- * Set default values
622
- */
623
- $args = array(
624
- 'post_type' => $content_type,
625
- 'post_status' => 'publish',
626
- 'ignore_sticky_posts' => 1,
627
- );
628
-
629
- // Post in
630
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__in', $pt_view_settings ) ) {
631
- $post_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__in', $pt_view_settings ) );
632
- $args['post__in'] = array_map( 'intval', array_filter( $post_in ) );
633
- }
634
-
635
- // Post not in
636
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__not_in', $pt_view_settings ) ) {
637
- $post_not_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__not_in', $pt_view_settings ) );
638
- $args['post__not_in'] = array_map( 'intval', array_filter( $post_not_in ) );
639
- }
640
-
641
- $args['post__not_in'] = apply_filters( PT_CV_PREFIX_ . 'post__not_in', isset( $args['post__not_in'] ) ? $args['post__not_in'] : array(), $pt_view_settings );
642
-
643
- // Parent page
644
- if ( $content_type == 'page' ) {
645
- $post_parent = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_parent', $pt_view_settings );
646
- if ( ! empty( $post_parent ) ) {
647
- $args['post_parent'] = (int) $post_parent;
648
- }
649
- }
650
-
651
- // Advance settings
652
- PT_CV_Functions::view_get_advanced_settings( $args, $content_type );
653
-
654
- return $args;
655
- }
656
-
657
- /**
658
- * Get display parameters of View
659
- *
660
- * @param string $view_type The view type of View
661
- * @return array
662
- */
663
- static function view_display_settings( $view_type ) {
664
- /**
665
- * Get Display parameters
666
- */
667
- $dargs = array();
668
-
669
- $dargs['view-type'] = $view_type;
670
-
671
- // Field settings of a item
672
- PT_CV_Functions::view_get_display_settings( $dargs );
673
-
674
- // Other settings
675
- PT_CV_Functions::view_get_other_settings( $dargs );
676
-
677
- // View type settings
678
- $dargs['view-type-settings'] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . $view_type . '-' );
679
-
680
- return $dargs;
681
- }
682
-
683
- /**
684
- * Get Advance settings
685
- *
686
- * @param array $args The parameters array
687
- * @param string $content_type The content type
688
- */
689
- static function view_get_advanced_settings( &$args, $content_type ) {
690
- global $pt_view_settings;
691
-
692
- $advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings', $pt_view_settings );
693
- if ( $advanced_settings ) {
694
- foreach ( $advanced_settings as $setting ) {
695
- switch ( $setting ) {
696
-
697
- // Author
698
- case 'author':
699
- $author_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'author__in', $pt_view_settings ) );
700
-
701
- // Check if using Wordpress version 3.7 or higher
702
- $version_gt_37 = PT_CV_Functions::wp_version_compare( '3.7' );
703
-
704
- if ( $version_gt_37 ) {
705
- $author_not_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'author__not_in', $pt_view_settings ) );
706
-
707
- // Author in
708
- if ( ! empty( $author_in[0] ) ) {
709
- $args = array_merge(
710
- $args, array(
711
- 'author__in' => array_map( 'intval', $author_in ),
712
- )
713
- );
714
- }
715
-
716
- // Author not in
717
- if ( ! empty( $author_not_in[0] ) ) {
718
- $args = array_merge(
719
- $args, array(
720
- 'author__not_in' => array_map( 'intval', $author_not_in ),
721
- )
722
- );
723
- }
724
- } else {
725
- // Author = ID
726
- if ( ! empty( $author_in[0] ) ) {
727
- $args = array_merge(
728
- $args, array(
729
- 'author' => intval( $author_in[0] ),
730
- )
731
- );
732
- }
733
- }
734
-
735
- break;
736
-
737
- // Status
738
- case 'status':
739
- $args = array_merge(
740
- $args, array(
741
- 'post_status' => PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_status', $pt_view_settings, 'publish' ) ),
742
- )
743
- );
744
- break;
745
-
746
- // Search
747
- case 'search':
748
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 's', $pt_view_settings ) ) {
749
- $args = array_merge(
750
- $args, array(
751
- 's' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 's', $pt_view_settings ),
752
- )
753
- );
754
- }
755
- break;
756
-
757
- // Taxonomy
758
- case 'taxonomy':
759
- // No taxonomy found
760
- if ( ! PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy', $pt_view_settings ) ) {
761
- break;
762
- }
763
-
764
- // All settings of taxonomies
765
- $taxonomy_setting = array();
766
-
767
- // Selected taxonomies
768
- $taxonomies = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy', $pt_view_settings );
769
-
770
- // Get Terms & criterias (In, Not in)
771
- foreach ( $taxonomies as $taxonomy ) {
772
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-terms', $pt_view_settings ) ) {
773
- // Get operator
774
- $operator = PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-operator', $pt_view_settings, 'IN' );
775
-
776
- $taxonomy_setting[] = array(
777
- 'taxonomy' => $taxonomy,
778
- 'field' => 'slug',
779
- 'terms' => (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-terms', $pt_view_settings ),
780
- 'operator' => $operator,
781
- );
782
- }
783
- }
784
-
785
- // Get Taxonomy relation if there are more than 1 selected taxonomies | set In & Not in of a taxonomy
786
- if ( count( $taxonomies ) > 1 || count( $taxonomy_setting ) > 1 ) {
787
- $taxonomy_setting['relation'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-relation', $pt_view_settings, 'AND' );
788
- }
789
-
790
- // Filter taxonomy with Custom post types
791
- $taxonomy_setting_ = apply_filters( PT_CV_PREFIX_ . 'taxonomy_setting', $taxonomy_setting );
792
-
793
- $args = array_merge( $args, array( 'tax_query' => $taxonomy_setting_ ) );
794
- break;
795
-
796
- // Order
797
- case 'order':
798
-
799
- $order_settings = array();
800
-
801
- // Advanced order by
802
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . $content_type . '-orderby', $pt_view_settings ) ) {
803
-
804
- // Get meta key to order by
805
- $meta_key = PT_CV_Functions::setting_value( PT_CV_PREFIX . $content_type . '-orderby', $pt_view_settings );
806
-
807
- // Use 'meta_value_num' for numeric values
808
- global $pt_content_type;
809
- $all_meta_numeric_values = apply_filters( PT_CV_PREFIX_ . 'meta_numeric_values', array() );
810
-
811
- // Get numeric values of selected content type
812
- $meta_numeric_values = isset( $all_meta_numeric_values[$pt_content_type] ) ? $all_meta_numeric_values[$pt_content_type] : array();
813
- $meta_orderby = array_key_exists( $meta_key, (array) $meta_numeric_values ) ? 'meta_value_num' : 'meta_value';
814
- $order_settings = array(
815
- 'meta_key' => isset( $meta_numeric_values[$meta_key] ) ? $meta_numeric_values[$meta_key] : $meta_key,
816
- 'orderby' => $meta_orderby,
817
- 'order' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-order', $pt_view_settings ),
818
- );
819
-
820
- } else {
821
- // Common order by
822
- $orderby = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'orderby', $pt_view_settings );
823
- $order_by_options = array_keys( PT_CV_Values::post_regular_orderby() );
824
-
825
- if ( in_array( $orderby, $order_by_options ) ) {
826
- $order_settings = array(
827
- 'orderby' => $orderby,
828
- 'order' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'order', $pt_view_settings )
829
- );
830
- }
831
- }
832
-
833
- $args = array_merge( $args, $order_settings );
834
- break;
835
-
836
- default:
837
- break;
838
- }
839
- }
840
- }
841
- }
842
-
843
- /**
844
- * Get Fields settings
845
- *
846
- * @param array $dargs The settings array of Fields
847
- */
848
- static function view_get_display_settings( &$dargs ) {
849
- global $pt_view_settings;
850
-
851
- $view_type = $dargs['view-type'];
852
-
853
- /**
854
- * Layout format
855
- */
856
- $dargs['layout-format'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'layout-format', $pt_view_settings );
857
-
858
- /**
859
- * Columns count & Rows count
860
- */
861
- $dargs['number-columns'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-' . 'number-columns', $pt_view_settings, 1 );
862
- $dargs['number-rows'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-' . 'number-rows', $pt_view_settings, 1 );
863
-
864
- /**
865
- * Fields settings
866
- */
867
- $cfields_settings = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'show-field-' );
868
- $cfields = (array) array_keys( (array) $cfields_settings );
869
- foreach ( $cfields as $field ) {
870
- // If show this field
871
- if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'show-field-' . $field, $pt_view_settings ) ) {
872
- // Add this field to display fields list
873
- $dargs['fields'][] = $field;
874
-
875
- // Get field settings
876
- switch ( $field ) {
877
-
878
- // Get thumbnail settings
879
- case 'thumbnail':
880
- $prefix = PT_CV_PREFIX . 'field-thumbnail-';
881
- $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
882
-
883
- $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_setting_values', $field_setting, $prefix );
884
-
885
- break;
886
-
887
- // Get meta fields settings
888
- case 'meta-fields':
889
- $prefix = PT_CV_PREFIX . 'meta-fields-';
890
- $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
891
-
892
- $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_setting_values', $field_setting, $prefix );
893
-
894
- break;
895
-
896
- // Get content settings
897
- case 'content':
898
- $prefix = PT_CV_PREFIX . 'field-content-';
899
- $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
900
-
901
- if ( $field_setting['show'] == 'excerpt' ) {
902
- $field_setting = array_merge( $field_setting, PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'field-excerpt-' ) );
903
- }
904
-
905
- $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_content_setting_values', $field_setting, $prefix );
906
-
907
- break;
908
-
909
- default:
910
- break;
911
- }
912
- }
913
- }
914
- }
915
-
916
- /**
917
- * Get Pagination settings
918
- *
919
- * @param array $dargs The settings array of Fields
920
- * @param array $args The parameters array
921
- * @param array $pargs The pagination settings array
922
- */
923
- static function view_get_pagination_settings( &$dargs, &$args, $pargs ) {
924
- global $pt_view_settings;
925
-
926
- // Get Limit value
927
- $limit = trim( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'limit', $pt_view_settings ) );
928
- $limit = ( empty( $limit ) || $limit === '-1' ) ? 10000000 : (int) $limit;
929
- $args['limit'] = $args['posts_per_page'] = $limit;
930
- $offset = 0;
931
-
932
- // Get pagination enable/disable
933
- $pagination = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination', $pt_view_settings );
934
- if ( $pagination ) {
935
- $prefix = PT_CV_PREFIX . 'pagination-';
936
- $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
937
-
938
- $dargs['pagination-settings'] = apply_filters( PT_CV_PREFIX_ . 'pagination_settings', $field_setting, $prefix );
939
-
940
- // If Items per page is set, get its value
941
- $posts_per_page = isset( $dargs['pagination-settings']['items-per-page'] ) ? (int) $dargs['pagination-settings']['items-per-page'] : $limit;
942
-
943
- if ( $posts_per_page > $limit ) {
944
- $posts_per_page = $limit;
945
- }
946
-
947
- // Set 'posts_per_page' parameter
948
- $args['posts_per_page'] = $posts_per_page;
949
-
950
- // Get offset
951
- if ( isset( $pargs['page'] ) ) {
952
- $offset = $posts_per_page * ( (int) $pargs['page'] - 1 );
953
- }
954
- }
955
-
956
- $offset = apply_filters( PT_CV_PREFIX_ . 'settings_args_offset', $offset );
957
-
958
- // Set 'offset' parameter
959
- $args['offset'] = $offset;
960
- }
961
-
962
- /**
963
- * Get Other settings
964
- *
965
- * @param array $dargs The settings array of Fields
966
- */
967
- static function view_get_other_settings( &$dargs ) {
968
- $prefix = PT_CV_PREFIX . 'other-';
969
- $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
970
-
971
- $dargs['other-settings'] = apply_filters( PT_CV_PREFIX_ . 'other_settings', $field_setting );
972
- }
973
-
974
- /**
975
- * Process data when submit form add/edit view
976
- *
977
- * @return void
978
- */
979
- static function view_submit() {
980
- if ( empty( $_POST ) ) {
981
- return;
982
- }
983
-
984
- PT_CV_Functions::_nonce_check( 'form_nonce', 'view_submit' );
985
-
986
- /**
987
- * INSERT VIEW
988
- */
989
- // View title
990
- $title = esc_sql( $_POST[PT_CV_PREFIX . 'view-title'] );
991
-
992
- // Current post id ( 0 if new view )
993
- $cur_post_id = esc_sql( $_POST[PT_CV_PREFIX . 'post-id'] );
994
-
995
- // Insert post
996
- if ( ! $cur_post_id ) {
997
- $post_id = PT_CV_Functions::post_insert( array( 'ID' => $cur_post_id, 'title' => $title ) );
998
- } else {
999
- $post_id = $cur_post_id;
1000
- }
1001
-
1002
- /**
1003
- * ADD/UPDATE CUSTOM FIELDS
1004
- */
1005
- // Get current view id, = 0 if it is new view
1006
- $cur_view_id = esc_sql( $_POST[PT_CV_PREFIX . 'view-id'] );
1007
- $view_id = empty( $cur_view_id ) ? PT_CV_Functions::string_random() : $cur_view_id;
1008
- update_post_meta( $post_id, PT_CV_META_ID, $view_id );
1009
- update_post_meta( $post_id, PT_CV_META_SETTINGS, (array) $_POST );
1010
-
1011
- // Update post title
1012
- if ( strpos( $title, '[ID:' ) === false ) {
1013
- PT_CV_Functions::post_insert( array( 'ID' => $post_id, 'title' => sprintf( '%s [ID: %s]', $title, $view_id ) ) );
1014
- }
1015
-
1016
- /**
1017
- * redirect to edit page
1018
- */
1019
- $edit_link = PT_CV_Functions::view_link( $view_id );
1020
- wp_redirect( $edit_link );
1021
- exit;
1022
- }
1023
-
1024
- /**
1025
- * Add shortcode
1026
- *
1027
- * @param array $atts Array of setting parameters for shortcode
1028
- * @param string $content Content of shortcode
1029
- */
1030
- static function view_output( $atts, $content = '' ) {
1031
- $atts = shortcode_atts(
1032
- apply_filters(
1033
- PT_CV_PREFIX_ . 'shortcode_params',
1034
- array(
1035
- 'id' => 0,
1036
- )
1037
- ),
1038
- $atts
1039
- );
1040
-
1041
- global $pt_cv_shortcode_params;
1042
- $pt_cv_shortcode_params = $atts;
1043
-
1044
- // View meta id
1045
- $id = esc_sql( $atts['id'] );
1046
-
1047
- // Get View settings
1048
- $settings = PT_CV_Functions::view_get_settings( $id );
1049
-
1050
- // Show View output
1051
- return balanceTags( PT_CV_Functions::view_process_settings( $id, $settings ) );
1052
- }
1053
-
1054
- /**
1055
- * Generate link to View page: Add view/ Edit view
1056
- *
1057
- * @param string $view_id The view id
1058
- * @param array $action Custom parameters
1059
- *
1060
- * @return string
1061
- */
1062
- public static function view_link( $view_id, $action = array() ) {
1063
-
1064
- $edit_link = admin_url( 'admin.php?page=' . PT_CV_DOMAIN . '-add' );
1065
- if ( ! empty( $view_id ) ) {
1066
- $query_args = array( 'id' => $view_id ) + $action;
1067
- $edit_link = add_query_arg( $query_args, $edit_link );
1068
- }
1069
-
1070
- return $edit_link;
1071
- }
1072
-
1073
- /**
1074
- * Callback function for ajax Preview action 'preview_request'
1075
- */
1076
- static function ajax_callback_preview_request() {
1077
-
1078
- // Validate request
1079
- check_ajax_referer( PT_CV_PREFIX_ . 'ajax_nonce', 'ajax_nonce' );
1080
-
1081
- do_action( PT_CV_PREFIX_ . 'preview_header' );
1082
-
1083
- // Request handle
1084
- $settings = array();
1085
- parse_str( $_POST['data'], $settings );
1086
-
1087
- // Show View output
1088
- echo balanceTags( PT_CV_Functions::view_process_settings( null, $settings ) );
1089
-
1090
- do_action( PT_CV_PREFIX_ . 'preview_footer' );
1091
- // Must exit
1092
- die;
1093
- }
1094
-
1095
- /**
1096
- * Callback function for ajax Pagination action 'pagination_request'
1097
- */
1098
- static function ajax_callback_pagination_request() {
1099
-
1100
- // Validate request
1101
- check_ajax_referer( PT_CV_PREFIX_ . 'ajax_nonce', 'ajax_nonce' );
1102
-
1103
- // Session id
1104
- $session_id = empty( $_POST['sid'] ) ? '' : esc_sql( $_POST['sid'] );
1105
-
1106
- // Get saved $settings
1107
- $settings = get_transient( PT_CV_PREFIX . 'view-settings-' . $session_id );
1108
-
1109
- // Pagination settings
1110
- $pargs = array( 'session_id' => $session_id, 'page' => (int) esc_sql( $_POST['page'] ) );
1111
-
1112
- // Language
1113
- $language = empty( $_POST['lang'] ) ? '' : esc_sql( $_POST['lang'] );
1114
- // WPML
1115
- global $sitepress;
1116
- if ( $sitepress && $language ) {
1117
- $sitepress->switch_lang( $language, true );
1118
- }
1119
-
1120
- // Show View output
1121
- echo balanceTags( PT_CV_Functions::view_process_settings( '', $settings, $pargs ) );
1122
-
1123
- // Must exit
1124
- die;
1125
- }
1126
-
1127
- /**
1128
- * Show promotion text in View page
1129
- */
1130
- static function util_show_promo_view() {
1131
- $pro_installed = get_option( 'pt_cv_version_pro' );
1132
- if ( ! $pro_installed ) {
1133
- ?>
1134
- <div class="pull-right" style="margin-top: -54px;">
1135
- <a class="btn btn-success" target="_blank" href="http://www.contentviewspro.com/pricing/?utm_source=client&utm_medium=view">&#187; Get Pro version</a>
1136
- or <a class="btn btn-info" target="_blank" href="http://sample.contentviewspro.com/?utm_source=client&utm_medium=view">Check demo site</a>
1137
- </div>
1138
- <?php
1139
- }
1140
- }
1141
-
1142
- }
1143
-
1144
  }
1
+ <?php
2
+ /**
3
+ * Contain main functions to work with plugin, post, custom fields...
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! function_exists( 'get_plugin_data' ) ) {
13
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
14
+ }
15
+ if ( ! class_exists( 'PT_CV_Functions' ) ) {
16
+
17
+ /**
18
+ * @name PT_CV_Functions
19
+ * @todo Utility functions
20
+ */
21
+ class PT_CV_Functions {
22
+
23
+ static $prev_random_string = '';
24
+
25
+ /**
26
+ * Compare current Wordpress version with a version
27
+ *
28
+ * @global string $wp_version
29
+ *
30
+ * @param string $version_to_compare
31
+ * @param string $operator
32
+ *
33
+ * @return boolean
34
+ */
35
+ static function wp_version_compare( $version_to_compare, $operator = '>=' ) {
36
+ if ( empty( $version_to_compare ) ) {
37
+ return true;
38
+ }
39
+
40
+ global $wp_version;
41
+
42
+ // Check if using Wordpress version 3.7 or higher
43
+ return version_compare( $wp_version, $version_to_compare, $operator );
44
+ }
45
+
46
+ /**
47
+ * Get current language of site
48
+ */
49
+ static function get_language() {
50
+ $language = '';
51
+
52
+ // WPML
53
+ global $sitepress;
54
+ if ( $sitepress && method_exists( $sitepress, 'get_current_language' ) ) {
55
+ $language = $sitepress->get_current_language();
56
+ }
57
+
58
+ return $language;
59
+ }
60
+
61
+ /**
62
+ * Get plugin info
63
+ *
64
+ * @param string $file Absolute path to the plugin file
65
+ * @param string $data Field of plugin data want to get
66
+ *
67
+ * @return array | null
68
+ */
69
+ static function plugin_info( $file, $data = '' ) {
70
+ $plugin_data = get_plugin_data( $file );
71
+
72
+ return isset( $plugin_data[$data] ) ? $plugin_data[$data] : NULL;
73
+ }
74
+
75
+ /**
76
+ * Add sub menu page
77
+ *
78
+ * @param string $parent_slug Slug of parent menu
79
+ * @param string $page_title Title of page
80
+ * @param string $menu_title Title of menu
81
+ * @param string $sub_page Slug of sub menu
82
+ * @param string $class Class name which contains function to output content of page created by this menu
83
+ */
84
+ static function menu_add_sub( $parent_slug, $page_title, $menu_title, $sub_page, $class ) {
85
+ // Get user role settings option
86
+ $options = get_option( PT_CV_OPTION_NAME );
87
+ $user_role = current_user_can( 'administrator' ) ? 'administrator' : ( isset( $options['access_role'] ) ? $options['access_role'] : 'edit_posts' );
88
+
89
+ return add_submenu_page(
90
+ $parent_slug, $page_title, $menu_title, $user_role, $parent_slug . '-' . $sub_page, array( $class, 'display_sub_page_' . $sub_page )
91
+ );
92
+ }
93
+
94
+ /**
95
+ * Get current post type in Admin
96
+ *
97
+ * @global type $post
98
+ * @global type $typenow
99
+ * @global type $current_screen
100
+ * @return type
101
+ */
102
+ static function admin_current_post_type() {
103
+ global $post, $typenow, $current_screen;
104
+
105
+ //we have a post so we can just get the post type from that
106
+ if ( $post && $post->post_type ) {
107
+ return $post->post_type;
108
+ } //check the global $typenow - set in admin.php
109
+ elseif ( $typenow ) {
110
+ return $typenow;
111
+ } //check the global $current_screen object - set in sceen.php
112
+ elseif ( $current_screen && isset( $current_screen->post_type ) ) {
113
+ return $current_screen->post_type;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Include content of file
119
+ *
120
+ * @param string $file_path Absolute path of file
121
+ *
122
+ * @return NULL | string Content of file
123
+ */
124
+ static function file_include_content( $file_path ) {
125
+ $content = NULL;
126
+
127
+ if ( file_exists( $file_path ) ) {
128
+ ob_start();
129
+ include_once $file_path;
130
+ $content = ob_get_clean();
131
+ }
132
+
133
+ return $content;
134
+ }
135
+
136
+ /**
137
+ * Generate random string
138
+ *
139
+ * @param bool $prev_return Return previous generated string
140
+ *
141
+ * @return string
142
+ */
143
+ static function string_random( $prev_return = false ) {
144
+ if ( $prev_return ) {
145
+ return PT_CV_Functions::$prev_random_string;
146
+ }
147
+ PT_CV_Functions::$prev_random_string = substr( md5( rand() ), 0, 10 );
148
+
149
+ return PT_CV_Functions::$prev_random_string;
150
+ }
151
+
152
+ /**
153
+ * Create array from string, use explode function
154
+ *
155
+ * @param string $string String to explode
156
+ * @param string $delimiter Delimiter to explode string
157
+ *
158
+ * @return array
159
+ */
160
+ static function string_to_array( $string, $delimiter = ',' ) {
161
+ return is_array( $string ) ? $string : (array) explode( $delimiter, (string) str_replace( ' ', '', $string ) );
162
+ }
163
+
164
+ /**
165
+ * Slug to nice String
166
+ *
167
+ * @param string $slug Slug string
168
+ *
169
+ * @return string
170
+ */
171
+ static function string_slug_to_text( $slug ) {
172
+ $slug = preg_replace( '/[^a-z]+/', ' ', $slug );
173
+
174
+ return ucwords( $slug );
175
+ }
176
+
177
+ /**
178
+ * Get thumbnail dimensions
179
+ *
180
+ * @param array $fargs The settings of thumbnail
181
+ *
182
+ * @return array
183
+ */
184
+ static function field_thumbnail_dimensions( $fargs ) {
185
+ $size = $fargs['size'];
186
+
187
+ return (array) explode( '&times;', str_replace( ' ', '', $size ) );
188
+ }
189
+
190
+ /**
191
+ * Get value of a setting from global settings array
192
+ *
193
+ * @param string $field The full name of setting to get value
194
+ * @param array $array_to_get Array to get values of wanted setting
195
+ * @param mixed|null $assign The value to assign if setting is not found
196
+ */
197
+ static function setting_value( $field, $array_to_get, $assign = NULL ) {
198
+ return isset( $array_to_get[$field] ) ? $array_to_get[$field] : $assign;
199
+ }
200
+
201
+ /**
202
+ * Get values of settings from global settings array
203
+ *
204
+ * @param array $fields Array of setting fields to get value
205
+ * @param array $array_to_save Array to save values of wanted setting fields
206
+ * @param array $array_to_get Array to get values of wanted setting fields
207
+ * @param string $prefix Prefix string to looking for fields in $array_to_get
208
+ */
209
+ static function settings_values( $fields, &$array_to_save, $array_to_get, $prefix ) {
210
+ foreach ( $fields as $tsetting ) {
211
+ $array_to_save[$tsetting] = PT_CV_Functions::setting_value( $prefix . $tsetting, $array_to_get );
212
+ }
213
+ }
214
+
215
+ /**
216
+ * Get names of options for a setting group (setting name started by a prefix)
217
+ *
218
+ * @param string $prefix The prefix in name of settings
219
+ * @param array $options The options array (contain full paramaters of settings)
220
+ */
221
+ static function settings_keys( $prefix, $options ) {
222
+ $result = array();
223
+ foreach ( $options as $option ) {
224
+ if ( isset( $option['params'] ) ) {
225
+ foreach ( $option['params'] as $params ) {
226
+ // If name of setting match with prefix string, got it name
227
+ if ( isset( $params['name'] ) && substr( $params['name'], 0, strlen( $prefix ) ) === $prefix ) {
228
+ $result[] = substr( $params['name'], strlen( $prefix ) );
229
+ }
230
+ }
231
+ }
232
+ }
233
+
234
+ return $result;
235
+ }
236
+
237
+ /**
238
+ * Get value of some setting options by prefix
239
+ *
240
+ * @param string $prefix The prefix in name of setting options
241
+ */
242
+ static function settings_values_by_prefix( $prefix ) {
243
+ global $pt_view_settings;
244
+
245
+ $result = array();
246
+
247
+ foreach ( $pt_view_settings as $name => $value ) {
248
+ // If name of setting match with prefix string, got it name
249
+ if ( substr( $name, 0, strlen( $prefix ) ) === $prefix ) {
250
+ $result[substr( $name, strlen( $prefix ) )] = $value;
251
+ }
252
+ }
253
+
254
+ return $result;
255
+ }
256
+
257
+ /**
258
+ * Get terms list of a post
259
+ *
260
+ * @param object $post The post object
261
+ *
262
+ * @return string
263
+ */
264
+ static function post_terms( $post ) {
265
+ global $pt_post_terms;
266
+
267
+
268
+ // List of HTML link to terms
269
+ $links = array();
270
+
271
+ // Get list of taxonomies
272
+ $taxonomies = get_taxonomies( '', 'names' );
273
+
274
+ $taxonomies = apply_filters( PT_CV_PREFIX_ . 'taxonomies_list', $taxonomies );
275
+
276
+ // Get post ID
277
+ $post_id = is_object( $post ) ? $post->ID : $post;
278
+
279
+ // Get lists of terms of this post
280
+ $terms = wp_get_object_terms( $post_id, $taxonomies );
281
+
282
+ foreach ( $terms as $term ) {
283
+ $links[] = sprintf(
284
+ '<a href="%1$s" title="%2$s %3$s">%3$s</a>',
285
+ esc_url( get_term_link( $term, $term->taxonomy ) ),
286
+ __( 'View all posts in', PT_CV_DOMAIN ),
287
+ $term->name
288
+ );
289
+
290
+ if ( ! isset( $pt_post_terms[$post_id] ) ) {
291
+ $pt_post_terms[$post_id] = array();
292
+ }
293
+ $pt_post_terms[$post_id][$term->slug] = $term->name;
294
+ }
295
+
296
+ return implode( ', ', $links );
297
+ }
298
+
299
+ /**
300
+ * Update post view count
301
+ *
302
+ * @param string $post_id ID of post
303
+ */
304
+ static function post_update_view_count( $post_id ) {
305
+ $meta_key = PT_CV_META_VIEW_COUNT;
306
+ $count = get_post_meta( $post_id, $meta_key, true );
307
+ if ( ! $count ) {
308
+ $count = 0;
309
+ }
310
+ $count ++;
311
+ update_post_meta( $post_id, $meta_key, $count );
312
+ }
313
+
314
+ /**
315
+ * Get post view count
316
+ *
317
+ * @param string $post_id ID of post
318
+ */
319
+ static function post_get_view_count( $post_id ) {
320
+ $meta_key = PT_CV_META_VIEW_COUNT;
321
+ $count = get_post_meta( $post_id, $meta_key, true );
322
+ if ( ! $count ) {
323
+ $count = 1;
324
+ }
325
+
326
+ return _n( 'view', 'views', $count, PT_CV_DOMAIN );
327
+ }
328
+
329
+ /**
330
+ * Insert/Update post
331
+ *
332
+ * @param string $arr Array of post data
333
+ */
334
+ static function post_insert( $arr ) {
335
+ if ( ! $arr ) {
336
+ return;
337
+ }
338
+ // Create post object
339
+ $my_post = array(
340
+ 'ID' => (int) $arr['ID'],
341
+ 'post_type' => PT_CV_POST_TYPE,
342
+ 'post_content' => '',
343
+ 'post_title' => ! empty( $arr['title'] ) ? $arr['title'] : __( '(no title)', PT_CV_DOMAIN ),
344
+ 'post_status' => 'publish',
345
+ );
346
+
347
+ // Insert the post into the database
348
+ return wp_insert_post( $my_post );
349
+ }
350
+
351
+ /**
352
+ * Get View id in post table, from "id" meta key value
353
+ *
354
+ * @param string $meta_id ID of custom field
355
+ *
356
+ * @return int Return Post ID of this view
357
+ */
358
+ static function post_id_from_meta_id( $meta_id ) {
359
+
360
+ $post_id = 0;
361
+ if ( ! $meta_id ) {
362
+ return $post_id;
363
+ }
364
+
365
+ // Query view which has view id = $meta_id
366
+ $pt_query = new WP_Query(
367
+ array(
368
+ 'post_type' => PT_CV_POST_TYPE,
369
+ 'post_status' => 'publish',
370
+ 'meta_key' => PT_CV_META_ID,
371
+ 'meta_value' => esc_sql( $meta_id ),
372
+ )
373
+ );
374
+ if ( $pt_query->have_posts() ) :
375
+ while ( $pt_query->have_posts() ):
376
+ $pt_query->the_post();
377
+ $post_id = get_the_ID();
378
+ endwhile;
379
+ endif;
380
+
381
+ return $post_id;
382
+ }
383
+
384
+ /**
385
+ * Get first key of array
386
+ *
387
+ * @param array $args Array data
388
+ *
389
+ * @return string
390
+ */
391
+ static function array_get_first_key( $args ) {
392
+ return current( array_keys( $args ) );
393
+ }
394
+
395
+ /**
396
+ * Check valid request
397
+ *
398
+ * @param string $nonce_name Name of nonce field
399
+ * @param string $action_name name of action relates to nonce field
400
+ */
401
+ static function _nonce_check( $nonce_name, $action_name ) {
402
+ $nonce_name = PT_CV_PREFIX_ . $nonce_name;
403
+ if ( ! isset( $_POST[$nonce_name] ) || ! wp_verify_nonce( $_POST[$nonce_name], PT_CV_PREFIX_ . $action_name ) ) {
404
+ print esc_html( __( 'Sorry, your nonce did not verify.', PT_CV_DOMAIN ) );
405
+ exit;
406
+ }
407
+ }
408
+
409
+ /**
410
+ * Get view data
411
+ *
412
+ * @param string $meta_id ID of custom field
413
+ *
414
+ * @return array
415
+ */
416
+ static function view_get_settings( $meta_id ) {
417
+ if ( ! $meta_id ) {
418
+ return;
419
+ }
420
+
421
+ $post_id = PT_CV_Functions::post_id_from_meta_id( $meta_id );
422
+
423
+ // Get view settings
424
+ if ( $post_id ) {
425
+ $view_settings = get_post_meta( $post_id, PT_CV_META_SETTINGS, true );
426
+
427
+ /* Backward compatibility
428
+ * since 1.3.2
429
+ */
430
+ self::view_backward_comp( $view_settings );
431
+
432
+ return is_array( $view_settings ) ? $view_settings : array();
433
+ }
434
+
435
+ return array();
436
+ }
437
+
438
+ /**
439
+ * Update values for some new options in new version (from options in old version)
440
+ *
441
+ * @param type $view_settings
442
+ */
443
+ static function view_backward_comp( &$view_settings ) {
444
+ if ( ! $view_settings )
445
+ return $view_settings;
446
+
447
+ $taxonomies = isset( $view_settings[ PT_CV_PREFIX . 'taxonomy'] ) ? $view_settings[ PT_CV_PREFIX . 'taxonomy'] : array();
448
+ if ( $taxonomies ) {
449
+ $list = array( '__in', '__not_in' );
450
+ foreach ( $taxonomies as $taxonomy ) {
451
+ // Check if IN/NOT IN list has values. NOT IN list will overwite IN list
452
+ foreach ( $list as $ltype ) {
453
+ if ( isset( $view_settings[PT_CV_PREFIX . $taxonomy . $ltype] ) ) {
454
+ $view_settings[PT_CV_PREFIX . $taxonomy . '-terms'] = $view_settings[PT_CV_PREFIX . $taxonomy . $ltype];
455
+ $view_settings[PT_CV_PREFIX . $taxonomy . '-operator'] = ( $ltype == '__in' ) ? 'IN' : 'NOT IN';
456
+ }
457
+ }
458
+ }
459
+ }
460
+ }
461
+
462
+ /**
463
+ * Process view $settings array, return HTML output
464
+ *
465
+ * @param string $id The current view id
466
+ * @param array $settings The settings array
467
+ * @param array $pargs The pagination settings array
468
+ *
469
+ * @return string HTML output of Content View
470
+ */
471
+ static function view_process_settings( $id, $settings, $pargs = array() ) {
472
+ if ( empty( $settings ) ) {
473
+ return __( 'Empty settings', PT_CV_DOMAIN );
474
+ }
475
+
476
+ // Escaped value appropriate for use in a SQL query
477
+ global $pt_view_settings;
478
+
479
+ $pt_view_settings = array();
480
+ foreach ( $settings as $key => $value ) {
481
+ $pt_view_settings[$key] = esc_sql( $value );
482
+ }
483
+
484
+ // Get content type
485
+ global $pt_content_type;
486
+ $pt_content_type = $content_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'content-type', $pt_view_settings );
487
+
488
+ // Get view type
489
+ $view_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'view-type', $pt_view_settings );
490
+
491
+ // Store display settings
492
+ global $dargs, $pt_query_args;
493
+
494
+ $session_id = ( $pargs && isset( $pargs['session_id'] ) ) ? $pargs['session_id'] : 0;
495
+
496
+ if ( $session_id ) {
497
+ $session_data = array_merge(
498
+ array( '$args' => '', '$dargs' => '' ),
499
+ ( false === ( $saved_settings = get_transient( PT_CV_PREFIX . 'view-data-' . $session_id ) ) ) ? array() : $saved_settings
500
+ );
501
+
502
+ $args = $session_data['$args'];
503
+ $dargs = $session_data['$dargs'];
504
+ } else {
505
+ // Generate session key for pagination
506
+ global $pt_view_sid;
507
+ $pt_view_sid = $session_id = PT_CV_Functions::string_random();
508
+
509
+ // Store settings
510
+ set_transient( PT_CV_PREFIX . 'view-settings-' . $session_id, $settings, 30 * MINUTE_IN_SECONDS );
511
+ }
512
+
513
+ if ( empty( $args ) || empty( $dargs ) ) {
514
+ $args = PT_CV_Functions::view_filter_settings( $content_type, $pt_view_settings );
515
+ $dargs = PT_CV_Functions::view_display_settings( $view_type );
516
+
517
+ // Filter
518
+ $dargs = apply_filters( PT_CV_PREFIX_ . 'all_display_settings', $dargs );
519
+ $args = apply_filters( PT_CV_PREFIX_ . 'query_parameters', $args );
520
+
521
+ // Store view data
522
+ set_transient(
523
+ PT_CV_PREFIX . 'view-data-' . $session_id,
524
+ array(
525
+ '$args' => $args,
526
+ '$dargs' => $dargs,
527
+ ), 30 * MINUTE_IN_SECONDS
528
+ );
529
+ }
530
+
531
+ // Pagination settings
532
+ PT_CV_Functions::view_get_pagination_settings( $dargs, $args, $pargs );
533
+
534
+ // Validate settings, if some required parameters are missing, show error and exit
535
+ $error = apply_filters( PT_CV_PREFIX_ . 'validate_settings', array(), $args );
536
+
537
+ // Return error message
538
+ if ( $error ) {
539
+ return ( implode( '</p><p>', $error ) );
540
+ }
541
+
542
+ // Update global query parameters variable
543
+ $pt_query_args = $args;
544
+
545
+ do_action( PT_CV_PREFIX_ . 'add_global_variables' );
546
+
547
+ /**
548
+ * Output Items
549
+ */
550
+
551
+ // Store HTML output of each item
552
+ $content_items = array();
553
+
554
+ // The Query
555
+ do_action( PT_CV_PREFIX_ . 'before_query' );
556
+
557
+ $pt_query = new WP_Query( $args );
558
+
559
+ do_action( PT_CV_PREFIX_ . 'after_query' );
560
+
561
+ // The Loop
562
+ if ( $pt_query->have_posts() ) {
563
+ while ( $pt_query->have_posts() ) {
564
+ $pt_query->the_post();
565
+ global $post;
566
+
567
+ // Output HTML for this item
568
+ $content_items[$post->ID] = PT_CV_Html::view_type_output( $view_type, $post );
569
+ }
570
+ } else {
571
+ // Get no post found class
572
+ $_class = apply_filters( PT_CV_PREFIX_ . 'content_no_post_found_class', 'alert alert-warning' );
573
+
574
+ // Get no post found text
575
+ $_text = apply_filters( PT_CV_PREFIX_ . 'content_no_post_found_text', __( 'No post found', PT_CV_DOMAIN ) );
576
+
577
+ // Output HTML
578
+ $content_items[] = sprintf( '<div class="%1$s">%2$s</div>', esc_attr( $_class ), balanceTags( $_text ) );
579
+ }
580
+
581
+ // Restore original Post Data
582
+ wp_reset_postdata();
583
+
584
+ // Filter array of items
585
+ $content_items = apply_filters( PT_CV_PREFIX_ . 'content_items', $content_items );
586
+
587
+ /**
588
+ * Output Pagination
589
+ */
590
+ $current_page = ( isset( $pargs['page'] ) && $pargs['page'] > 1 ) ? $pargs['page'] : 1;
591
+ $html = PT_CV_Html::content_items_wrap( $content_items, $current_page, $args['posts_per_page'], $id );
592
+
593
+ // Append Pagination HTML if this is first page, or not Ajax calling
594
+ if ( $args['posts_per_page'] > 0 && $current_page === 1 ) {
595
+ // Total post founds
596
+ $found_posts = apply_filters( PT_CV_PREFIX_ . 'found_posts', $pt_query->found_posts );
597
+
598
+ // Total number of items
599
+ $total_items = ( $args['limit'] > 0 && $found_posts > $args['limit'] ) ? $args['limit'] : $found_posts;
600
+
601
+ // Total number of pages
602
+ $max_num_pages = ceil( $total_items / $args['posts_per_page'] );
603
+
604
+ // Output pagination
605
+ $html .= "\n" . PT_CV_Html::pagination_output( $max_num_pages, $session_id );
606
+ }
607
+
608
+ return $html;
609
+ }
610
+
611
+ /**
612
+ * Get query parameters of View
613
+ *
614
+ * @param string $content_type The current content type
615
+ * @param array $pt_view_settings The settings of View
616
+ * @return array
617
+ */
618
+ static function view_filter_settings( $content_type, $pt_view_settings ) {
619
+ /**
620
+ * Get Query parameters
621
+ * Set default values
622
+ */
623
+ $args = array(
624
+ 'post_type' => $content_type,
625
+ 'post_status' => 'publish',
626
+ 'ignore_sticky_posts' => 1,
627
+ );
628
+
629
+ // Post in
630
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__in', $pt_view_settings ) ) {
631
+ $post_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__in', $pt_view_settings ) );
632
+ $args['post__in'] = array_map( 'intval', array_filter( $post_in ) );
633
+ }
634
+
635
+ // Post not in
636
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__not_in', $pt_view_settings ) ) {
637
+ $post_not_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__not_in', $pt_view_settings ) );
638
+ $args['post__not_in'] = array_map( 'intval', array_filter( $post_not_in ) );
639
+ }
640
+
641
+ $args['post__not_in'] = apply_filters( PT_CV_PREFIX_ . 'post__not_in', isset( $args['post__not_in'] ) ? $args['post__not_in'] : array(), $pt_view_settings );
642
+
643
+ // Parent page
644
+ if ( $content_type == 'page' ) {
645
+ $post_parent = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_parent', $pt_view_settings );
646
+ if ( ! empty( $post_parent ) ) {
647
+ $args['post_parent'] = (int) $post_parent;
648
+ }
649
+ }
650
+
651
+ // Advance settings
652
+ PT_CV_Functions::view_get_advanced_settings( $args, $content_type );
653
+
654
+ return $args;
655
+ }
656
+
657
+ /**
658
+ * Get display parameters of View
659
+ *
660
+ * @param string $view_type The view type of View
661
+ * @return array
662
+ */
663
+ static function view_display_settings( $view_type ) {
664
+ /**
665
+ * Get Display parameters
666
+ */
667
+ $dargs = array();
668
+
669
+ $dargs['view-type'] = $view_type;
670
+
671
+ // Field settings of a item
672
+ PT_CV_Functions::view_get_display_settings( $dargs );
673
+
674
+ // Other settings
675
+ PT_CV_Functions::view_get_other_settings( $dargs );
676
+
677
+ // View type settings
678
+ $dargs['view-type-settings'] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . $view_type . '-' );
679
+
680
+ return $dargs;
681
+ }
682
+
683
+ /**
684
+ * Get Advance settings
685
+ *
686
+ * @param array $args The parameters array
687
+ * @param string $content_type The content type
688
+ */
689
+ static function view_get_advanced_settings( &$args, $content_type ) {
690
+ global $pt_view_settings;
691
+
692
+ $advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings', $pt_view_settings );
693
+ if ( $advanced_settings ) {
694
+ foreach ( $advanced_settings as $setting ) {
695
+ switch ( $setting ) {
696
+
697
+ // Author
698
+ case 'author':
699
+ $author_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'author__in', $pt_view_settings ) );
700
+
701
+ // Check if using Wordpress version 3.7 or higher
702
+ $version_gt_37 = PT_CV_Functions::wp_version_compare( '3.7' );
703
+
704
+ if ( $version_gt_37 ) {
705
+ $author_not_in = PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'author__not_in', $pt_view_settings ) );
706
+
707
+ // Author in
708
+ if ( ! empty( $author_in[0] ) ) {
709
+ $args = array_merge(
710
+ $args, array(
711
+ 'author__in' => array_map( 'intval', $author_in ),
712
+ )
713
+ );
714
+ }
715
+
716
+ // Author not in
717
+ if ( ! empty( $author_not_in[0] ) ) {
718
+ $args = array_merge(
719
+ $args, array(
720
+ 'author__not_in' => array_map( 'intval', $author_not_in ),
721
+ )
722
+ );
723
+ }
724
+ } else {
725
+ // Author = ID
726
+ if ( ! empty( $author_in[0] ) ) {
727
+ $args = array_merge(
728
+ $args, array(
729
+ 'author' => intval( $author_in[0] ),
730
+ )
731
+ );
732
+ }
733
+ }
734
+
735
+ break;
736
+
737
+ // Status
738
+ case 'status':
739
+ $args = array_merge(
740
+ $args, array(
741
+ 'post_status' => PT_CV_Functions::string_to_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_status', $pt_view_settings, 'publish' ) ),
742
+ )
743
+ );
744
+ break;
745
+
746
+ // Search
747
+ case 'search':
748
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 's', $pt_view_settings ) ) {
749
+ $args = array_merge(
750
+ $args, array(
751
+ 's' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 's', $pt_view_settings ),
752
+ )
753
+ );
754
+ }
755
+ break;
756
+
757
+ // Taxonomy
758
+ case 'taxonomy':
759
+ // No taxonomy found
760
+ if ( ! PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy', $pt_view_settings ) ) {
761
+ break;
762
+ }
763
+
764
+ // All settings of taxonomies
765
+ $taxonomy_setting = array();
766
+
767
+ // Selected taxonomies
768
+ $taxonomies = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy', $pt_view_settings );
769
+
770
+ // Get Terms & criterias (In, Not in)
771
+ foreach ( $taxonomies as $taxonomy ) {
772
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-terms', $pt_view_settings ) ) {
773
+ // Get operator
774
+ $operator = PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-operator', $pt_view_settings, 'IN' );
775
+
776
+ $taxonomy_setting[] = array(
777
+ 'taxonomy' => $taxonomy,
778
+ 'field' => 'slug',
779
+ 'terms' => (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . $taxonomy . '-terms', $pt_view_settings ),
780
+ 'operator' => $operator,
781
+ );
782
+ }
783
+ }
784
+
785
+ // Get Taxonomy relation if there are more than 1 selected taxonomies | set In & Not in of a taxonomy
786
+ if ( count( $taxonomies ) > 1 || count( $taxonomy_setting ) > 1 ) {
787
+ $taxonomy_setting['relation'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-relation', $pt_view_settings, 'AND' );
788
+ }
789
+
790
+ // Filter taxonomy with Custom post types
791
+ $taxonomy_setting_ = apply_filters( PT_CV_PREFIX_ . 'taxonomy_setting', $taxonomy_setting );
792
+
793
+ $args = array_merge( $args, array( 'tax_query' => $taxonomy_setting_ ) );
794
+ break;
795
+
796
+ // Order
797
+ case 'order':
798
+
799
+ $order_settings = array();
800
+
801
+ // Advanced order by
802
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . $content_type . '-orderby', $pt_view_settings ) ) {
803
+
804
+ // Get meta key to order by
805
+ $meta_key = PT_CV_Functions::setting_value( PT_CV_PREFIX . $content_type . '-orderby', $pt_view_settings );
806
+
807
+ // Use 'meta_value_num' for numeric values
808
+ global $pt_content_type;
809
+ $all_meta_numeric_values = apply_filters( PT_CV_PREFIX_ . 'meta_numeric_values', array() );
810
+
811
+ // Get numeric values of selected content type
812
+ $meta_numeric_values = isset( $all_meta_numeric_values[$pt_content_type] ) ? $all_meta_numeric_values[$pt_content_type] : array();
813
+ $meta_orderby = array_key_exists( $meta_key, (array) $meta_numeric_values ) ? 'meta_value_num' : 'meta_value';
814
+ $order_settings = array(
815
+ 'meta_key' => isset( $meta_numeric_values[$meta_key] ) ? $meta_numeric_values[$meta_key] : $meta_key,
816
+ 'orderby' => $meta_orderby,
817
+ 'order' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-order', $pt_view_settings ),
818
+ );
819
+
820
+ } else {
821
+ // Common order by
822
+ $orderby = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'orderby', $pt_view_settings );
823
+ $order_by_options = array_keys( PT_CV_Values::post_regular_orderby() );
824
+
825
+ if ( in_array( $orderby, $order_by_options ) ) {
826
+ $order_settings = array(
827
+ 'orderby' => $orderby,
828
+ 'order' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'order', $pt_view_settings )
829
+ );
830
+ }
831
+ }
832
+
833
+ $args = array_merge( $args, $order_settings );
834
+ break;
835
+
836
+ default:
837
+ break;
838
+ }
839
+ }
840
+ }
841
+ }
842
+
843
+ /**
844
+ * Get Fields settings
845
+ *
846
+ * @param array $dargs The settings array of Fields
847
+ */
848
+ static function view_get_display_settings( &$dargs ) {
849
+ global $pt_view_settings;
850
+
851
+ $view_type = $dargs['view-type'];
852
+
853
+ /**
854
+ * Layout format
855
+ */
856
+ $dargs['layout-format'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'layout-format', $pt_view_settings );
857
+
858
+ /**
859
+ * Columns count & Rows count
860
+ */
861
+ $dargs['number-columns'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-' . 'number-columns', $pt_view_settings, 1 );
862
+ $dargs['number-rows'] = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-' . 'number-rows', $pt_view_settings, 1 );
863
+
864
+ /**
865
+ * Fields settings
866
+ */
867
+ $cfields_settings = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'show-field-' );
868
+ $cfields = (array) array_keys( (array) $cfields_settings );
869
+ foreach ( $cfields as $field ) {
870
+ // If show this field
871
+ if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'show-field-' . $field, $pt_view_settings ) ) {
872
+ // Add this field to display fields list
873
+ $dargs['fields'][] = $field;
874
+
875
+ // Get field settings
876
+ switch ( $field ) {
877
+
878
+ // Get thumbnail settings
879
+ case 'thumbnail':
880
+ $prefix = PT_CV_PREFIX . 'field-thumbnail-';
881
+ $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
882
+
883
+ $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_setting_values', $field_setting, $prefix );
884
+
885
+ break;
886
+
887
+ // Get meta fields settings
888
+ case 'meta-fields':
889
+ $prefix = PT_CV_PREFIX . 'meta-fields-';
890
+ $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
891
+
892
+ $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_setting_values', $field_setting, $prefix );
893
+
894
+ break;
895
+
896
+ // Get content settings
897
+ case 'content':
898
+ $prefix = PT_CV_PREFIX . 'field-content-';
899
+ $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
900
+
901
+ if ( $field_setting['show'] == 'excerpt' ) {
902
+ $field_setting = array_merge( $field_setting, PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'field-excerpt-' ) );
903
+ }
904
+
905
+ $dargs['field-settings'][$field] = apply_filters( PT_CV_PREFIX_ . 'field_content_setting_values', $field_setting, $prefix );
906
+
907
+ break;
908
+
909
+ default:
910
+ break;
911
+ }
912
+ }
913
+ }
914
+ }
915
+
916
+ /**
917
+ * Get Pagination settings
918
+ *
919
+ * @param array $dargs The settings array of Fields
920
+ * @param array $args The parameters array
921
+ * @param array $pargs The pagination settings array
922
+ */
923
+ static function view_get_pagination_settings( &$dargs, &$args, $pargs ) {
924
+ global $pt_view_settings;
925
+
926
+ // Get Limit value
927
+ $limit = trim( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'limit', $pt_view_settings ) );
928
+ $limit = ( empty( $limit ) || $limit === '-1' ) ? 10000000 : (int) $limit;
929
+ $args['limit'] = $args['posts_per_page'] = $limit;
930
+ $offset = 0;
931
+
932
+ // Get pagination enable/disable
933
+ $pagination = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination', $pt_view_settings );
934
+ if ( $pagination ) {
935
+ $prefix = PT_CV_PREFIX . 'pagination-';
936
+ $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
937
+
938
+ $dargs['pagination-settings'] = apply_filters( PT_CV_PREFIX_ . 'pagination_settings', $field_setting, $prefix );
939
+
940
+ // If Items per page is set, get its value
941
+ $posts_per_page = isset( $dargs['pagination-settings']['items-per-page'] ) ? (int) $dargs['pagination-settings']['items-per-page'] : $limit;
942
+
943
+ if ( $posts_per_page > $limit ) {
944
+ $posts_per_page = $limit;
945
+ }
946
+
947
+ // Set 'posts_per_page' parameter
948
+ $args['posts_per_page'] = $posts_per_page;
949
+
950
+ // Get offset
951
+ if ( isset( $pargs['page'] ) ) {
952
+ $offset = $posts_per_page * ( (int) $pargs['page'] - 1 );
953
+ }
954
+ }
955
+
956
+ $offset = apply_filters( PT_CV_PREFIX_ . 'settings_args_offset', $offset );
957
+
958
+ // Set 'offset' parameter
959
+ $args['offset'] = $offset;
960
+ }
961
+
962
+ /**
963
+ * Get Other settings
964
+ *
965
+ * @param array $dargs The settings array of Fields
966
+ */
967
+ static function view_get_other_settings( &$dargs ) {
968
+ $prefix = PT_CV_PREFIX . 'other-';
969
+ $field_setting = PT_CV_Functions::settings_values_by_prefix( $prefix );
970
+
971
+ $dargs['other-settings'] = apply_filters( PT_CV_PREFIX_ . 'other_settings', $field_setting );
972
+ }
973
+
974
+ /**
975
+ * Process data when submit form add/edit view
976
+ *
977
+ * @return void
978
+ */
979
+ static function view_submit() {
980
+ if ( empty( $_POST ) ) {
981
+ return;
982
+ }
983
+
984
+ PT_CV_Functions::_nonce_check( 'form_nonce', 'view_submit' );
985
+
986
+ /**
987
+ * INSERT VIEW
988
+ */
989
+ // View title
990
+ $title = esc_sql( $_POST[PT_CV_PREFIX . 'view-title'] );
991
+
992
+ // Current post id ( 0 if new view )
993
+ $cur_post_id = esc_sql( $_POST[PT_CV_PREFIX . 'post-id'] );
994
+
995
+ // Insert post
996
+ if ( ! $cur_post_id ) {
997
+ $post_id = PT_CV_Functions::post_insert( array( 'ID' => $cur_post_id, 'title' => $title ) );
998
+ } else {
999
+ $post_id = $cur_post_id;
1000
+ }
1001
+
1002
+ /**
1003
+ * ADD/UPDATE CUSTOM FIELDS
1004
+ */
1005
+ // Get current view id, = 0 if it is new view
1006
+ $cur_view_id = esc_sql( $_POST[PT_CV_PREFIX . 'view-id'] );
1007
+ $view_id = empty( $cur_view_id ) ? PT_CV_Functions::string_random() : $cur_view_id;
1008
+ update_post_meta( $post_id, PT_CV_META_ID, $view_id );
1009
+ update_post_meta( $post_id, PT_CV_META_SETTINGS, (array) $_POST );
1010
+
1011
+ // Update post title
1012
+ if ( strpos( $title, '[ID:' ) === false ) {
1013
+ PT_CV_Functions::post_insert( array( 'ID' => $post_id, 'title' => sprintf( '%s [ID: %s]', $title, $view_id ) ) );
1014
+ }
1015
+
1016
+ /**
1017
+ * redirect to edit page
1018
+ */
1019
+ $edit_link = PT_CV_Functions::view_link( $view_id );
1020
+ wp_redirect( $edit_link );
1021
+ exit;
1022
+ }
1023
+
1024
+ /**
1025
+ * Add shortcode
1026
+ *
1027
+ * @param array $atts Array of setting parameters for shortcode
1028
+ * @param string $content Content of shortcode
1029
+ */
1030
+ static function view_output( $atts, $content = '' ) {
1031
+ $atts = shortcode_atts(
1032
+ apply_filters(
1033
+ PT_CV_PREFIX_ . 'shortcode_params',
1034
+ array(
1035
+ 'id' => 0,
1036
+ )
1037
+ ),
1038
+ $atts
1039
+ );
1040
+
1041
+ global $pt_cv_shortcode_params;
1042
+ $pt_cv_shortcode_params = $atts;
1043
+
1044
+ // View meta id
1045
+ $id = esc_sql( $atts['id'] );
1046
+
1047
+ // Get View settings
1048
+ $settings = PT_CV_Functions::view_get_settings( $id );
1049
+
1050
+ // Show View output
1051
+ return balanceTags( PT_CV_Functions::view_process_settings( $id, $settings ) );
1052
+ }
1053
+
1054
+ /**
1055
+ * Generate link to View page: Add view/ Edit view
1056
+ *
1057
+ * @param string $view_id The view id
1058
+ * @param array $action Custom parameters
1059
+ *
1060
+ * @return string
1061
+ */
1062
+ public static function view_link( $view_id, $action = array() ) {
1063
+
1064
+ $edit_link = admin_url( 'admin.php?page=' . PT_CV_DOMAIN . '-add' );
1065
+ if ( ! empty( $view_id ) ) {
1066
+ $query_args = array( 'id' => $view_id ) + $action;
1067
+ $edit_link = add_query_arg( $query_args, $edit_link );
1068
+ }
1069
+
1070
+ return $edit_link;
1071
+ }
1072
+
1073
+ /**
1074
+ * Callback function for ajax Preview action 'preview_request'
1075
+ */
1076
+ static function ajax_callback_preview_request() {
1077
+
1078
+ // Validate request
1079
+ check_ajax_referer( PT_CV_PREFIX_ . 'ajax_nonce', 'ajax_nonce' );
1080
+
1081
+ do_action( PT_CV_PREFIX_ . 'preview_header' );
1082
+
1083
+ // Request handle
1084
+ $settings = array();
1085
+ parse_str( $_POST['data'], $settings );
1086
+
1087
+ // Show View output
1088
+ echo balanceTags( PT_CV_Functions::view_process_settings( null, $settings ) );
1089
+
1090
+ do_action( PT_CV_PREFIX_ . 'preview_footer' );
1091
+ // Must exit
1092
+ die;
1093
+ }
1094
+
1095
+ /**
1096
+ * Callback function for ajax Pagination action 'pagination_request'
1097
+ */
1098
+ static function ajax_callback_pagination_request() {
1099
+
1100
+ // Validate request
1101
+ check_ajax_referer( PT_CV_PREFIX_ . 'ajax_nonce', 'ajax_nonce' );
1102
+
1103
+ // Session id
1104
+ $session_id = empty( $_POST['sid'] ) ? '' : esc_sql( $_POST['sid'] );
1105
+
1106
+ // Get saved $settings
1107
+ $settings = get_transient( PT_CV_PREFIX . 'view-settings-' . $session_id );
1108
+
1109
+ // Pagination settings
1110
+ $pargs = array( 'session_id' => $session_id, 'page' => (int) esc_sql( $_POST['page'] ) );
1111
+
1112
+ // Language
1113
+ $language = empty( $_POST['lang'] ) ? '' : esc_sql( $_POST['lang'] );
1114
+ // WPML
1115
+ global $sitepress;
1116
+ if ( $sitepress && $language ) {
1117
+ $sitepress->switch_lang( $language, true );
1118
+ }
1119
+
1120
+ // Show View output
1121
+ echo balanceTags( PT_CV_Functions::view_process_settings( '', $settings, $pargs ) );
1122
+
1123
+ // Must exit
1124
+ die;
1125
+ }
1126
+
1127
+ /**
1128
+ * Show promotion text in View page
1129
+ */
1130
+ static function util_show_promo_view() {
1131
+ $pro_installed = get_option( 'pt_cv_version_pro' );
1132
+ if ( ! $pro_installed ) {
1133
+ ?>
1134
+ <div class="pull-right" style="margin-top: -54px;">
1135
+ <a class="btn btn-success" target="_blank" href="http://www.contentviewspro.com/pricing/?utm_source=client&utm_medium=view">&#187; Get Pro version</a>
1136
+ or <a class="btn btn-info" target="_blank" href="http://sample.contentviewspro.com/?utm_source=client&utm_medium=view">Check demo site</a>
1137
+ </div>
1138
+ <?php
1139
+ }
1140
+ }
1141
+
1142
+ }
1143
+
1144
  }
includes/hooks.php CHANGED
@@ -1,119 +1,119 @@
1
- <?php
2
- /**
3
- * Custom filters/actions
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! class_exists( 'PT_CV_Hooks' ) ) {
13
-
14
- /**
15
- * @name PT_CV_Hooks
16
- */
17
- class PT_CV_Hooks {
18
-
19
- /**
20
- * Add custom filters/actions
21
- */
22
- static function init() {
23
- // Filter Output
24
- add_filter( PT_CV_PREFIX_ . 'validate_settings', array( __CLASS__, 'filter_validate_settings' ), 10, 2 );
25
-
26
- // Do action
27
- }
28
-
29
- /**
30
- * Validate settings filter
31
- *
32
- * @param string $error The error message
33
- * @param array $args The Query parameters array
34
- */
35
- public static function filter_validate_settings( $errors, $args ) {
36
- global $dargs;
37
-
38
- // echo "<pre>";
39
- // var_dump( 'query args', $args );
40
- // echo "</pre>";
41
-
42
- // echo "<pre>";
43
- // var_dump( 'display args', $dargs );
44
- // echo "</pre>";
45
-
46
- // Prefix string for error message
47
- $messages = array(
48
- 'field' => array(
49
- 'select' => __( 'Please select an option in : ', PT_CV_DOMAIN ),
50
- 'text' => __( 'Please set value in : ', PT_CV_DOMAIN ),
51
- ),
52
- 'tab' => array(
53
- 'filter' => __( 'Filter Settings', PT_CV_DOMAIN ),
54
- 'display' => __( 'Display Settings', PT_CV_DOMAIN ),
55
- ),
56
- );
57
-
58
- /**
59
- * Validate Query parameters
60
- */
61
-
62
- // Post type
63
- if ( empty( $args['post_type'] ) ) {
64
- $errors[] = $messages['field']['select'] . $messages['tab']['filter'] . ' > ' . __( 'Content type', PT_CV_DOMAIN );
65
- }
66
-
67
- /**
68
- * Validate common Display parameters
69
- */
70
-
71
- // View type
72
- if ( empty( $dargs['view-type'] ) ) {
73
- $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'View type', PT_CV_DOMAIN );
74
- }
75
-
76
- // Layout format
77
- if ( empty( $dargs['layout-format'] ) ) {
78
- $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'Layout format', PT_CV_DOMAIN );
79
- }
80
-
81
- // Field settings
82
- if ( ! isset( $dargs['fields'] ) ) {
83
- $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'Fields settings', PT_CV_DOMAIN ) . ' > ' . __( 'Fields display', PT_CV_DOMAIN );
84
- }
85
-
86
- // Excerpt length
87
- $fargs = isset( $dargs['field-settings'] ) ? $dargs['field-settings'] : array();
88
- if ( isset( $fargs['content'] ) && $fargs['content']['show'] === 'excerpt' ) {
89
- if ( empty( $fargs['content']['length'] ) ) {
90
- $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'Fields settings', PT_CV_DOMAIN ) . ' > ' . __( 'Content settings', PT_CV_DOMAIN ) . __( 'Excerpt length', PT_CV_DOMAIN );
91
- }
92
- }
93
-
94
- // Item per page
95
- if ( isset( $dargs['pagination-settings'] ) ) {
96
- if ( empty( $dargs['pagination-settings']['items-per-page'] ) ) {
97
- $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'Pagination settings', PT_CV_DOMAIN ) . ' > ' . __( 'Items per page', PT_CV_DOMAIN );
98
- }
99
- }
100
-
101
- /**
102
- * Validate Display parameters of view types
103
- */
104
- if ( ! empty( $dargs['view-type'] ) ) {
105
- switch ( $dargs['view-type'] ) {
106
- case 'grid':
107
- if ( empty( $dargs['number-columns'] ) ) {
108
- $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'View type settings', PT_CV_DOMAIN ) . ' > ' . __( 'Items per row', PT_CV_DOMAIN );
109
- }
110
- break;
111
- }
112
- }
113
-
114
- return array_filter( $errors );
115
- }
116
-
117
- }
118
-
119
- }
1
+ <?php
2
+ /**
3
+ * Custom filters/actions
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! class_exists( 'PT_CV_Hooks' ) ) {
13
+
14
+ /**
15
+ * @name PT_CV_Hooks
16
+ */
17
+ class PT_CV_Hooks {
18
+
19
+ /**
20
+ * Add custom filters/actions
21
+ */
22
+ static function init() {
23
+ // Filter Output
24
+ add_filter( PT_CV_PREFIX_ . 'validate_settings', array( __CLASS__, 'filter_validate_settings' ), 10, 2 );
25
+
26
+ // Do action
27
+ }
28
+
29
+ /**
30
+ * Validate settings filter
31
+ *
32
+ * @param string $error The error message
33
+ * @param array $args The Query parameters array
34
+ */
35
+ public static function filter_validate_settings( $errors, $args ) {
36
+ global $dargs;
37
+
38
+ // echo "<pre>";
39
+ // var_dump( 'query args', $args );
40
+ // echo "</pre>";
41
+
42
+ // echo "<pre>";
43
+ // var_dump( 'display args', $dargs );
44
+ // echo "</pre>";
45
+
46
+ // Prefix string for error message
47
+ $messages = array(
48
+ 'field' => array(
49
+ 'select' => __( 'Please select an option in : ', PT_CV_DOMAIN ),
50
+ 'text' => __( 'Please set value in : ', PT_CV_DOMAIN ),
51
+ ),
52
+ 'tab' => array(
53
+ 'filter' => __( 'Filter Settings', PT_CV_DOMAIN ),
54
+ 'display' => __( 'Display Settings', PT_CV_DOMAIN ),
55
+ ),
56
+ );
57
+
58
+ /**
59
+ * Validate Query parameters
60
+ */
61
+
62
+ // Post type
63
+ if ( empty( $args['post_type'] ) ) {
64
+ $errors[] = $messages['field']['select'] . $messages['tab']['filter'] . ' > ' . __( 'Content type', PT_CV_DOMAIN );
65
+ }
66
+
67
+ /**
68
+ * Validate common Display parameters
69
+ */
70
+
71
+ // View type
72
+ if ( empty( $dargs['view-type'] ) ) {
73
+ $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'View type', PT_CV_DOMAIN );
74
+ }
75
+
76
+ // Layout format
77
+ if ( empty( $dargs['layout-format'] ) ) {
78
+ $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'Layout format', PT_CV_DOMAIN );
79
+ }
80
+
81
+ // Field settings
82
+ if ( ! isset( $dargs['fields'] ) ) {
83
+ $errors[] = $messages['field']['select'] . $messages['tab']['display'] . ' > ' . __( 'Fields settings', PT_CV_DOMAIN ) . ' > ' . __( 'Fields display', PT_CV_DOMAIN );
84
+ }
85
+
86
+ // Excerpt length
87
+ $fargs = isset( $dargs['field-settings'] ) ? $dargs['field-settings'] : array();
88
+ if ( isset( $fargs['content'] ) && $fargs['content']['show'] === 'excerpt' ) {
89
+ if ( empty( $fargs['content']['length'] ) ) {
90
+ $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'Fields settings', PT_CV_DOMAIN ) . ' > ' . __( 'Content settings', PT_CV_DOMAIN ) . __( 'Excerpt length', PT_CV_DOMAIN );
91
+ }
92
+ }
93
+
94
+ // Item per page
95
+ if ( isset( $dargs['pagination-settings'] ) ) {
96
+ if ( empty( $dargs['pagination-settings']['items-per-page'] ) ) {
97
+ $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'Pagination settings', PT_CV_DOMAIN ) . ' > ' . __( 'Items per page', PT_CV_DOMAIN );
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Validate Display parameters of view types
103
+ */
104
+ if ( ! empty( $dargs['view-type'] ) ) {
105
+ switch ( $dargs['view-type'] ) {
106
+ case 'grid':
107
+ if ( empty( $dargs['number-columns'] ) ) {
108
+ $errors[] = $messages['field']['text'] . $messages['tab']['display'] . ' > ' . __( 'View type settings', PT_CV_DOMAIN ) . ' > ' . __( 'Items per row', PT_CV_DOMAIN );
109
+ }
110
+ break;
111
+ }
112
+ }
113
+
114
+ return array_filter( $errors );
115
+ }
116
+
117
+ }
118
+
119
+ }
includes/html-viewtype.php CHANGED
@@ -1,290 +1,290 @@
1
- <?php
2
- /**
3
- * HTML output for specific View types
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! class_exists( 'PT_CV_Html_ViewType' ) ) {
13
-
14
- /**
15
- * @name PT_CV_Html_ViewType
16
- * @todo List of functions relates to View type output
17
- */
18
- class PT_CV_Html_ViewType {
19
-
20
- /**
21
- * Generate class for columns
22
- *
23
- * @global array $dargs
24
- * @param array $content_items
25
- * @return array
26
- */
27
- static function process_column_width( $content_items ) {
28
- global $dargs;
29
-
30
- // -- Get column span
31
- $columns = ( (int) $dargs['number-columns'] < count( $content_items ) ) ? (int) $dargs['number-columns'] : count( $content_items );
32
-
33
- if ( ! $columns ) {
34
- $columns = 1;
35
- }
36
-
37
- $span_width_last = $span_width = (int) ( 12 / $columns );
38
-
39
- // Get span for the last column on row
40
- if ( 12 % $columns ) {
41
- $span_width_last = $span_width + ( 12 % $columns );
42
- }
43
-
44
- // Get span class
45
- $span_class = apply_filters( PT_CV_PREFIX_ . 'span_class', 'col-md-' );
46
-
47
- // -- Row output
48
-
49
- // Get wrapper class of a row
50
- $row_classes = apply_filters( PT_CV_PREFIX_ . 'row_class', array( 'row', PT_CV_PREFIX . 'row' ) );
51
- $row_class = implode( ' ', array_filter( $row_classes ) );
52
-
53
- return array( $columns, $span_width_last, $span_width, $span_class, $row_class );
54
- }
55
-
56
- /**
57
- * Wrap content of Grid type
58
- *
59
- * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
60
- * @param array $content The output array
61
- *
62
- * @return array Array of rows, each row contains columns
63
- */
64
- static function grid_wrapper( $content_items, &$content ) {
65
- global $pt_cv_enable_filter;
66
-
67
- list( $columns, $span_width_last, $span_width, $span_class, $row_class ) = self::process_column_width( $content_items );
68
-
69
- // Split items to rows
70
- $columns_item = array_chunk( $content_items, $columns, true );
71
-
72
- // Get HTML of each row
73
- foreach ( $columns_item as $items_per_row ) {
74
- $row_html = array();
75
-
76
- $idx = 0;
77
- foreach ( $items_per_row as $post_id => $content_item ) {
78
- $_span_width = ( $idx == count( $items_per_row ) - 1 ) ? $span_width_last : $span_width;
79
-
80
- // Wrap content of item
81
- $item_classes = apply_filters( PT_CV_PREFIX_ . 'item_col_class', array( $span_class . $_span_width ), $_span_width );
82
- $item_class = implode( ' ', array_filter( $item_classes ) );
83
- $row_html[] = PT_CV_Html::content_item_wrap( $content_item, $item_class, $post_id );
84
-
85
- $idx ++;
86
- }
87
-
88
- $list_item = implode( "\n", $row_html );
89
-
90
- if ( $pt_cv_enable_filter != 'yes' ) {
91
- $list_item = sprintf( '<div class="%s">%s</div>', esc_attr( $row_class ), $list_item );
92
- } else {
93
- // Add the extra clearfix
94
- $list_item .= '<div class="clearfix visible-xs-block"></div>';
95
- }
96
-
97
- $content[] = balanceTags( $list_item );
98
- }
99
- }
100
-
101
- /**
102
- * Wrap content of Collapsible List type
103
- *
104
- * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
105
- * @param array $content The output array
106
- *
107
- * @return string Collapsible list, wrapped in a "panel-group" div
108
- */
109
- static function collapsible_wrapper( $content_items, &$content ) {
110
- // Generate random id for the wrapper of Collapsible list
111
- $random_id = PT_CV_Functions::string_random();
112
-
113
- $collapsible_list = array();
114
- foreach ( $content_items as $idx => $content_item ) {
115
- // Replace class in body of collapsible item, to show one (now is the first item)
116
- $class = ( $idx == 0 ) ? 'in' : '';
117
- $content_item = str_replace( PT_CV_PREFIX_UPPER . 'CLASS', $class, $content_item );
118
-
119
- // Replace id in {data-parent="#ID"} of each item by generated id
120
- $collapsible_list[] = str_replace( PT_CV_PREFIX_UPPER . 'ID', $random_id, $content_item );
121
- }
122
-
123
- // Data attribute
124
- $data_attr = apply_filters( PT_CV_PREFIX_ . 'collapsible_data_attr', '' );
125
-
126
- // Collapsible wrapper class
127
- $wrapper_class = apply_filters( PT_CV_PREFIX_ . 'wrapper_collapsible_class', 'panel-group' );
128
-
129
- $output = sprintf( '<div class="%s" id="%s" %s>%s</div>', esc_attr( $wrapper_class ), esc_attr( $random_id ), $data_attr, balanceTags( implode( "\n", $collapsible_list ) ) );
130
-
131
- $content[] = $output;
132
- }
133
-
134
- /**
135
- * Wrap content of Scrollable list
136
- *
137
- * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
138
- * @param array $content The output array
139
- *
140
- * @return array Array of rows, each row contains columns
141
- */
142
- static function scrollable_wrapper( $content_items, &$content ) {
143
- global $dargs;
144
-
145
- // ID for the wrapper of scrollable list
146
- $wrapper_id = PT_CV_Functions::string_random();
147
-
148
- // Store all output of Scrollale list (indicators, content, controls)
149
- $scrollable_html = array();
150
-
151
- $scrollable_content_data = self::scrollable_content( $content_items );
152
- $count_slides = $scrollable_content_data['count_slides'];
153
- $scrollable_content = $scrollable_content_data['scrollable_content'];
154
-
155
- // Js code
156
- $interval = apply_filters( PT_CV_PREFIX_ . 'scrollable_interval', 'false' );
157
- $js = "$('#$wrapper_id').carousel({ interval : $interval })";
158
-
159
- $scrollable_html[] = PT_CV_Html::inline_script( $js );
160
-
161
- // Indicator html
162
- $show_indicator = isset( $dargs['view-type-settings']['indicator'] ) ? $dargs['view-type-settings']['indicator'] : 'yes';
163
- $scrollable_html[] = self::scrollable_indicator( ( $show_indicator == 'yes' ) ? 1 : 0, $wrapper_id, $count_slides );
164
-
165
- // Content html
166
- $scrollable_html[] = $scrollable_content;
167
-
168
- // Control html
169
- $show_navigation = isset( $dargs['view-type-settings']['navigation'] ) ? $dargs['view-type-settings']['navigation'] : 'yes';
170
- $scrollable_html[] = self::scrollable_control( ( $show_navigation == 'yes' ) ? 1 : 0, $wrapper_id, $count_slides );
171
-
172
- // Get wrapper class scrollable
173
- $scrollable_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_class', 'carousel slide' );
174
- $content[] = sprintf( '<div id="%s" class="%s" data-ride="carousel">%s</div>', esc_attr( $wrapper_id ), esc_attr( $scrollable_class ), implode( "\n", $scrollable_html ) );
175
- }
176
-
177
- /**
178
- * HTML output of item in Scrollable List
179
- *
180
- * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
181
- *
182
- * @return array
183
- */
184
- static function scrollable_content( $content_items ) {
185
- global $dargs;
186
-
187
- // Store content of a Scrollable list
188
- $scrollable_content = array();
189
-
190
- $rows = ( $dargs['number-rows'] ) ? (int) $dargs['number-rows'] : 1;
191
-
192
- list( $columns, $span_width_last, $span_width, $span_class, $row_class ) = self::process_column_width( $content_items );
193
-
194
- // Get wrapper class of a scrollable slide
195
- $slide_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_slide_class', 'item' );
196
-
197
- // Split items to slide
198
- $slides_item = array_chunk( $content_items, $columns * $rows );
199
-
200
- foreach ( $slides_item as $s_idx => $slide ) {
201
- // Store content of a slide
202
- $slide_html = array();
203
-
204
- // Split items to rows
205
- $columns_item = array_chunk( $slide, $columns );
206
-
207
- // Get HTML of each row
208
- foreach ( $columns_item as $items_per_row ) {
209
- $row_html = array();
210
-
211
- foreach ( $items_per_row as $idx => $content_item ) {
212
- $_span_width = ( $idx == count( $items_per_row ) - 1 ) ? $span_width_last : $span_width;
213
-
214
- // Wrap content of item
215
- $row_html[] = PT_CV_Html::content_item_wrap( $content_item, $span_class . $_span_width );
216
- }
217
-
218
- $slide_html[] = sprintf( '<div class="%1$s">%2$s</div>', esc_attr( $row_class ), implode( "\n", $row_html ) );
219
- }
220
-
221
- // Show first slide
222
- $this_class = $slide_class . ( ( $s_idx == 0 ) ? ' active' : '' );
223
- $scrollable_content[] = sprintf( '<div class="%s">%s</div>', esc_attr( $this_class ), implode( "\n", $slide_html ) );
224
- }
225
-
226
- // Get class of wrapper of content of scrollable list
227
- $content_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_content_class', 'carousel-inner' );
228
- $content = sprintf( '<div class="%s">%s</div>', esc_attr( $content_class ), implode( "\n", $scrollable_content ) );
229
-
230
- return array(
231
- 'scrollable_content' => $content,
232
- 'count_slides' => count( $slides_item ),
233
- );
234
- }
235
-
236
- /**
237
- * HTML output of Indicators in Scrollable
238
- *
239
- * @param bool $show Whether or not to show this element
240
- * @param string $wrapper_id The ID of wrapper of scrollable list
241
- * @param int $count_slides The amount of items
242
- */
243
- static function scrollable_indicator( $show, $wrapper_id, $count_slides ) {
244
- if ( ! $show ) {
245
- return '';
246
- }
247
-
248
- $output = '';
249
- if ( $count_slides > 1 ) {
250
- $li = array();
251
- for ( $index = 0; $index < $count_slides; $index ++ ) {
252
- $class = ( $index == 0 ) ? 'active' : '';
253
- $li[] = sprintf( '<li data-target="#%s" data-slide-to="%s" class="%s"></li>', esc_attr( $wrapper_id ), esc_attr( $index ), $class );
254
- }
255
-
256
- $output = '<ol class="carousel-indicators">' . implode( "\n", $li ) . '</ol>';
257
- }
258
-
259
- return $output;
260
- }
261
-
262
- /**
263
- * HTML output of Controls in Scrollable
264
- *
265
- * @param bool $show Whether or not to show this element
266
- * @param string $wrapper_id The ID of wrapper of scrollable list
267
- * @param int $count_slides The amount of items
268
- */
269
- static function scrollable_control( $show, $wrapper_id, $count_slides ) {
270
- if ( ! $show ) {
271
- return '';
272
- }
273
- $output = '';
274
- if ( $count_slides > 1 ) {
275
- $output = sprintf(
276
- '<a class="left carousel-control" href="#%1$s" data-slide="prev">
277
- <span class="glyphicon glyphicon-chevron-left"></span>
278
- </a>
279
- <a class="right carousel-control" href="#%1$s" data-slide="next">
280
- <span class="glyphicon glyphicon-chevron-right"></span>
281
- </a>',
282
- esc_attr( $wrapper_id )
283
- );
284
- }
285
-
286
- return $output;
287
- }
288
- }
289
-
290
  }
1
+ <?php
2
+ /**
3
+ * HTML output for specific View types
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! class_exists( 'PT_CV_Html_ViewType' ) ) {
13
+
14
+ /**
15
+ * @name PT_CV_Html_ViewType
16
+ * @todo List of functions relates to View type output
17
+ */
18
+ class PT_CV_Html_ViewType {
19
+
20
+ /**
21
+ * Generate class for columns
22
+ *
23
+ * @global array $dargs
24
+ * @param array $content_items
25
+ * @return array
26
+ */
27
+ static function process_column_width( $content_items ) {
28
+ global $dargs;
29
+
30
+ // -- Get column span
31
+ $columns = ( (int) $dargs['number-columns'] < count( $content_items ) ) ? (int) $dargs['number-columns'] : count( $content_items );
32
+
33
+ if ( ! $columns ) {
34
+ $columns = 1;
35
+ }
36
+
37
+ $span_width_last = $span_width = (int) ( 12 / $columns );
38
+
39
+ // Get span for the last column on row
40
+ if ( 12 % $columns ) {
41
+ $span_width_last = $span_width + ( 12 % $columns );
42
+ }
43
+
44
+ // Get span class
45
+ $span_class = apply_filters( PT_CV_PREFIX_ . 'span_class', 'col-md-' );
46
+
47
+ // -- Row output
48
+
49
+ // Get wrapper class of a row
50
+ $row_classes = apply_filters( PT_CV_PREFIX_ . 'row_class', array( 'row', PT_CV_PREFIX . 'row' ) );
51
+ $row_class = implode( ' ', array_filter( $row_classes ) );
52
+
53
+ return array( $columns, $span_width_last, $span_width, $span_class, $row_class );
54
+ }
55
+
56
+ /**
57
+ * Wrap content of Grid type
58
+ *
59
+ * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
60
+ * @param array $content The output array
61
+ *
62
+ * @return array Array of rows, each row contains columns
63
+ */
64
+ static function grid_wrapper( $content_items, &$content ) {
65
+ global $pt_cv_enable_filter;
66
+
67
+ list( $columns, $span_width_last, $span_width, $span_class, $row_class ) = self::process_column_width( $content_items );
68
+
69
+ // Split items to rows
70
+ $columns_item = array_chunk( $content_items, $columns, true );
71
+
72
+ // Get HTML of each row
73
+ foreach ( $columns_item as $items_per_row ) {
74
+ $row_html = array();
75
+
76
+ $idx = 0;
77
+ foreach ( $items_per_row as $post_id => $content_item ) {
78
+ $_span_width = ( $idx == count( $items_per_row ) - 1 ) ? $span_width_last : $span_width;
79
+
80
+ // Wrap content of item
81
+ $item_classes = apply_filters( PT_CV_PREFIX_ . 'item_col_class', array( $span_class . $_span_width ), $_span_width );
82
+ $item_class = implode( ' ', array_filter( $item_classes ) );
83
+ $row_html[] = PT_CV_Html::content_item_wrap( $content_item, $item_class, $post_id );
84
+
85
+ $idx ++;
86
+ }
87
+
88
+ $list_item = implode( "\n", $row_html );
89
+
90
+ if ( $pt_cv_enable_filter != 'yes' ) {
91
+ $list_item = sprintf( '<div class="%s">%s</div>', esc_attr( $row_class ), $list_item );
92
+ } else {
93
+ // Add the extra clearfix
94
+ $list_item .= '<div class="clearfix visible-xs-block"></div>';
95
+ }
96
+
97
+ $content[] = balanceTags( $list_item );
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Wrap content of Collapsible List type
103
+ *
104
+ * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
105
+ * @param array $content The output array
106
+ *
107
+ * @return string Collapsible list, wrapped in a "panel-group" div
108
+ */
109
+ static function collapsible_wrapper( $content_items, &$content ) {
110
+ // Generate random id for the wrapper of Collapsible list
111
+ $random_id = PT_CV_Functions::string_random();
112
+
113
+ $collapsible_list = array();
114
+ foreach ( $content_items as $idx => $content_item ) {
115
+ // Replace class in body of collapsible item, to show one (now is the first item)
116
+ $class = ( $idx == 0 ) ? 'in' : '';
117
+ $content_item = str_replace( PT_CV_PREFIX_UPPER . 'CLASS', $class, $content_item );
118
+
119
+ // Replace id in {data-parent="#ID"} of each item by generated id
120
+ $collapsible_list[] = str_replace( PT_CV_PREFIX_UPPER . 'ID', $random_id, $content_item );
121
+ }
122
+
123
+ // Data attribute
124
+ $data_attr = apply_filters( PT_CV_PREFIX_ . 'collapsible_data_attr', '' );
125
+
126
+ // Collapsible wrapper class
127
+ $wrapper_class = apply_filters( PT_CV_PREFIX_ . 'wrapper_collapsible_class', 'panel-group' );
128
+
129
+ $output = sprintf( '<div class="%s" id="%s" %s>%s</div>', esc_attr( $wrapper_class ), esc_attr( $random_id ), $data_attr, balanceTags( implode( "\n", $collapsible_list ) ) );
130
+
131
+ $content[] = $output;
132
+ }
133
+
134
+ /**
135
+ * Wrap content of Scrollable list
136
+ *
137
+ * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
138
+ * @param array $content The output array
139
+ *
140
+ * @return array Array of rows, each row contains columns
141
+ */
142
+ static function scrollable_wrapper( $content_items, &$content ) {
143
+ global $dargs;
144
+
145
+ // ID for the wrapper of scrollable list
146
+ $wrapper_id = PT_CV_Functions::string_random();
147
+
148
+ // Store all output of Scrollale list (indicators, content, controls)
149
+ $scrollable_html = array();
150
+
151
+ $scrollable_content_data = self::scrollable_content( $content_items );
152
+ $count_slides = $scrollable_content_data['count_slides'];
153
+ $scrollable_content = $scrollable_content_data['scrollable_content'];
154
+
155
+ // Js code
156
+ $interval = apply_filters( PT_CV_PREFIX_ . 'scrollable_interval', 'false' );
157
+ $js = "$('#$wrapper_id').carousel({ interval : $interval })";
158
+
159
+ $scrollable_html[] = PT_CV_Html::inline_script( $js );
160
+
161
+ // Indicator html
162
+ $show_indicator = isset( $dargs['view-type-settings']['indicator'] ) ? $dargs['view-type-settings']['indicator'] : 'yes';
163
+ $scrollable_html[] = self::scrollable_indicator( ( $show_indicator == 'yes' ) ? 1 : 0, $wrapper_id, $count_slides );
164
+
165
+ // Content html
166
+ $scrollable_html[] = $scrollable_content;
167
+
168
+ // Control html
169
+ $show_navigation = isset( $dargs['view-type-settings']['navigation'] ) ? $dargs['view-type-settings']['navigation'] : 'yes';
170
+ $scrollable_html[] = self::scrollable_control( ( $show_navigation == 'yes' ) ? 1 : 0, $wrapper_id, $count_slides );
171
+
172
+ // Get wrapper class scrollable
173
+ $scrollable_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_class', 'carousel slide' );
174
+ $content[] = sprintf( '<div id="%s" class="%s" data-ride="carousel">%s</div>', esc_attr( $wrapper_id ), esc_attr( $scrollable_class ), implode( "\n", $scrollable_html ) );
175
+ }
176
+
177
+ /**
178
+ * HTML output of item in Scrollable List
179
+ *
180
+ * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
181
+ *
182
+ * @return array
183
+ */
184
+ static function scrollable_content( $content_items ) {
185
+ global $dargs;
186
+
187
+ // Store content of a Scrollable list
188
+ $scrollable_content = array();
189
+
190
+ $rows = ( $dargs['number-rows'] ) ? (int) $dargs['number-rows'] : 1;
191
+
192
+ list( $columns, $span_width_last, $span_width, $span_class, $row_class ) = self::process_column_width( $content_items );
193
+
194
+ // Get wrapper class of a scrollable slide
195
+ $slide_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_slide_class', 'item' );
196
+
197
+ // Split items to slide
198
+ $slides_item = array_chunk( $content_items, $columns * $rows );
199
+
200
+ foreach ( $slides_item as $s_idx => $slide ) {
201
+ // Store content of a slide
202
+ $slide_html = array();
203
+
204
+ // Split items to rows
205
+ $columns_item = array_chunk( $slide, $columns );
206
+
207
+ // Get HTML of each row
208
+ foreach ( $columns_item as $items_per_row ) {
209
+ $row_html = array();
210
+
211
+ foreach ( $items_per_row as $idx => $content_item ) {
212
+ $_span_width = ( $idx == count( $items_per_row ) - 1 ) ? $span_width_last : $span_width;
213
+
214
+ // Wrap content of item
215
+ $row_html[] = PT_CV_Html::content_item_wrap( $content_item, $span_class . $_span_width );
216
+ }
217
+
218
+ $slide_html[] = sprintf( '<div class="%1$s">%2$s</div>', esc_attr( $row_class ), implode( "\n", $row_html ) );
219
+ }
220
+
221
+ // Show first slide
222
+ $this_class = $slide_class . ( ( $s_idx == 0 ) ? ' active' : '' );
223
+ $scrollable_content[] = sprintf( '<div class="%s">%s</div>', esc_attr( $this_class ), implode( "\n", $slide_html ) );
224
+ }
225
+
226
+ // Get class of wrapper of content of scrollable list
227
+ $content_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_content_class', 'carousel-inner' );
228
+ $content = sprintf( '<div class="%s">%s</div>', esc_attr( $content_class ), implode( "\n", $scrollable_content ) );
229
+
230
+ return array(
231
+ 'scrollable_content' => $content,
232
+ 'count_slides' => count( $slides_item ),
233
+ );
234
+ }
235
+
236
+ /**
237
+ * HTML output of Indicators in Scrollable
238
+ *
239
+ * @param bool $show Whether or not to show this element
240
+ * @param string $wrapper_id The ID of wrapper of scrollable list
241
+ * @param int $count_slides The amount of items
242
+ */
243
+ static function scrollable_indicator( $show, $wrapper_id, $count_slides ) {
244
+ if ( ! $show ) {
245
+ return '';
246
+ }
247
+
248
+ $output = '';
249
+ if ( $count_slides > 1 ) {
250
+ $li = array();
251
+ for ( $index = 0; $index < $count_slides; $index ++ ) {
252
+ $class = ( $index == 0 ) ? 'active' : '';
253
+ $li[] = sprintf( '<li data-target="#%s" data-slide-to="%s" class="%s"></li>', esc_attr( $wrapper_id ), esc_attr( $index ), $class );
254
+ }
255
+
256
+ $output = '<ol class="carousel-indicators">' . implode( "\n", $li ) . '</ol>';
257
+ }
258
+
259
+ return $output;
260
+ }
261
+
262
+ /**
263
+ * HTML output of Controls in Scrollable
264
+ *
265
+ * @param bool $show Whether or not to show this element
266
+ * @param string $wrapper_id The ID of wrapper of scrollable list
267
+ * @param int $count_slides The amount of items
268
+ */
269
+ static function scrollable_control( $show, $wrapper_id, $count_slides ) {
270
+ if ( ! $show ) {
271
+ return '';
272
+ }
273
+ $output = '';
274
+ if ( $count_slides > 1 ) {
275
+ $output = sprintf(
276
+ '<a class="left carousel-control" href="#%1$s" data-slide="prev">
277
+ <span class="glyphicon glyphicon-chevron-left"></span>
278
+ </a>
279
+ <a class="right carousel-control" href="#%1$s" data-slide="next">
280
+ <span class="glyphicon glyphicon-chevron-right"></span>
281
+ </a>',
282
+ esc_attr( $wrapper_id )
283
+ );
284
+ }
285
+
286
+ return $output;
287
+ }
288
+ }
289
+
290
  }
includes/html.php CHANGED
@@ -1,897 +1,897 @@
1
- <?php
2
- /**
3
- * HTML output, class, id generating
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! class_exists( 'PT_CV_Html' ) ) {
13
-
14
- /**
15
- * @name PT_CV_Html
16
- * @todo related HTML functions: Define HTML layout, Set class name...
17
- */
18
- class PT_CV_Html {
19
-
20
- // Store directory of selected view_types
21
- static $view_type_dir = array();
22
- // Store all selected styles
23
- static $style = array();
24
-
25
- /**
26
- * return class for Panel (Group of) group of params
27
- *
28
- * @return string
29
- */
30
- static function html_panel_group_class() {
31
- return 'panel-group';
32
- }
33
-
34
- /**
35
- * Return ID for Panel (Group of) group of params
36
- *
37
- * @param string $id Unique id of element
38
- *
39
- * @return string
40
- */
41
- static function html_panel_group_id( $id ) {
42
- return 'panel-group-' . $id;
43
- }
44
-
45
- /**
46
- * Return class for no animation elements
47
- *
48
- * @return string
49
- */
50
- static function html_no_animation_class() {
51
- return PT_CV_PREFIX . 'no-animation';
52
- }
53
-
54
- /**
55
- * Return class for group of params
56
- *
57
- * @return string
58
- */
59
- static function html_group_class() {
60
- return PT_CV_PREFIX . 'group';
61
- }
62
-
63
- /**
64
- * Return ID for group of params
65
- *
66
- * @param string $id Unique id of element
67
- *
68
- * @return string
69
- */
70
- static function html_group_id( $id ) {
71
- return self::html_group_class() . '-' . $id;
72
- }
73
-
74
- /**
75
- * Collapse HTML
76
- *
77
- * @param string $parent_id Id of parent element
78
- * @param string $id Unique id of element
79
- * @param string $heading Heading text
80
- * @param string $content Content
81
- * @param bool $show Show/hide the content
82
- */
83
- static function html_collapse_one( $parent_id, $id, $heading, $content = '', $show = true ) {
84
- $class = $show ? 'in' : '';
85
- ob_start();
86
- ?>
87
- <div class="panel panel-primary pt-accordion">
88
- <div class="panel-heading">
89
- <h4 class="panel-title" title="<?php _e( 'Click to toggle', PT_CV_DOMAIN ); ?>">
90
- <a class="pt-accordion-a" data-parent="#<?php echo esc_attr( $parent_id ); ?>" href="#<?php echo esc_attr( $id ); ?>">
91
- <?php echo balanceTags( $heading ); ?>
92
- </a>
93
- </h4>
94
- <span class="pull-right clickable"><i class="glyphicon glyphicon-minus"></i></span>
95
- </div>
96
- <div id="<?php echo esc_attr( $id ); ?>" class="panel-body <?php echo esc_attr( $class ); ?>">
97
- <div class="panel-body">
98
- <?php echo balanceTags( $content ); ?>
99
- </div>
100
- </div>
101
- </div>
102
- <?php
103
- return ob_get_clean();
104
- }
105
-
106
- /**
107
- * HTML content of Preview box
108
- */
109
- static function html_preview_box() {
110
- ob_start();
111
- ?>
112
- <div class="panel panel-default collapse" id="<?php echo esc_attr( PT_CV_PREFIX ); ?>preview-box"></div>
113
- <div class="text-center hidden" style="position: absolute; left: 50%; top: 160px;">
114
- <?php echo balanceTags( self::html_loading_img() ); ?>
115
- </div>
116
- <?php
117
- return ob_get_clean();
118
- }
119
-
120
- /**
121
- * Show loading image
122
- *
123
- * @param type $dimension
124
- *
125
- * @return type
126
- */
127
- static function html_loading_img( $dimension = 16, $class = '' ) {
128
- $img = sprintf( '<img width="%1$s" height="%1$s" class="%2$s" alt="%3$s" src="%4$s" /><div class="clear %5$s"></div>', esc_attr( $dimension ), esc_attr( $class ), __( 'loading', PT_CV_DOMAIN ), 'data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==', PT_CV_PREFIX . 'clear-pagination' );
129
-
130
- return apply_filters( PT_CV_PREFIX_ . 'loading_image', $img );
131
- }
132
-
133
- /**
134
- * Html output for button
135
- *
136
- * @param string $style Bootstrap type of button
137
- * @param string $text Text of button
138
- * @param string $class Class of button
139
- * @param string $size Size of button
140
- *
141
- * @return string
142
- */
143
- static function html_button( $style, $text = 'Button', $class = '', $size = '' ) {
144
- return sprintf( '<button type="button" class="btn btn-%s %s %s">%s</button>', $style, $class, $size, $text );
145
- }
146
-
147
- /**
148
- * Html output for a link, but style as button
149
- *
150
- * @param string $link Value for href attribute of link
151
- * @param string $style Bootstrap type of button
152
- * @param string $text Text of button
153
- * @param string $class Class of button
154
- * @param string $size Size of button
155
- *
156
- * @return string
157
- */
158
- static function link_button( $link, $style, $text = 'Button', $class = '', $size = '' ) {
159
- return sprintf( '<a href="%s" class="btn btn-%s %s %s">%s</a>', $link, $style, $class, $size, $text );
160
- }
161
-
162
- /**
163
- * Get Output HTML of a View type
164
- *
165
- * @param string $view_type The view type (grid, collapse...)
166
- * @param object $post The post object
167
- * @param string $style The style of view type (main, style2...)
168
- */
169
- static function view_type_output( $view_type, $post, $style = 'main' ) {
170
- global $dargs;
171
- $content = NULL;
172
-
173
- if ( empty( $view_type ) ) {
174
- return $content;
175
- }
176
-
177
- // Get view type directory
178
- $view_type_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_dir', PT_CV_VIEW_TYPE_OUTPUT, $view_type ) . $view_type;
179
-
180
- // Get asset directory
181
- $view_type_assets_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_asset', $view_type_dir, $view_type );
182
-
183
- if ( is_dir( $view_type_dir ) ) {
184
- // Store view type & asset information
185
- self::$view_type_dir[] = $view_type_assets_dir;
186
- self::$style[] = $style;
187
-
188
- // Generate HTML output of all content fields
189
- $fields_html = array();
190
- foreach ( $dargs['fields'] as $field_name ) {
191
- // Get settings of fields
192
- $fargs = isset( $dargs['field-settings'] ) ? $dargs['field-settings'] : array();
193
-
194
- $fargs['layout-format'] = $dargs['layout-format'];
195
-
196
- // Get HTML output of field
197
- $fields_html[$field_name] = self::field_item_html( $field_name, $post, $fargs );
198
- }
199
-
200
- // Get HTML content of view type, with specific style
201
- $file_path = $view_type_dir . '/' . 'html' . '/' . $style . '.' . 'php';
202
-
203
- if ( file_exists( $file_path ) ) {
204
- ob_start();
205
- // Include, not include_once
206
- include $file_path;
207
- $content = ob_get_clean();
208
- }
209
- }
210
-
211
- return $content;
212
- }
213
-
214
- /**
215
- * Wrap content of a item
216
- *
217
- * @param array $html_item The HTML output of a item
218
- * @param string $class The extra wrapper class of a item, such as col span
219
- * @param array $post_id The post ID
220
- *
221
- * @return string Full HTML output of a item
222
- */
223
- static function content_item_wrap( $html_item, $class = '', $post_id = 0 ) {
224
- global $dargs;
225
-
226
- if ( empty( $html_item ) ) {
227
- return '';
228
- }
229
-
230
- if ( is_array( $dargs ) ) {
231
- // If only show Title
232
- if ( isset( $dargs['fields'] ) && count( (array) $dargs['fields'] ) == 1 && $dargs['fields'][0] === 'title' ) {
233
- $class .= ' ' . PT_CV_PREFIX . 'only-title';
234
- }
235
- }
236
-
237
- // Get wrapper class of a item
238
- $layout = $dargs['layout-format'];
239
- $item_class = apply_filters( PT_CV_PREFIX_ . 'content_item_class', array( $class, PT_CV_PREFIX . 'content-item', PT_CV_PREFIX . $layout ) );
240
-
241
- $item_filter = apply_filters( PT_CV_PREFIX_ . 'content_item_filter_value', '', $post_id );
242
-
243
- $result = sprintf( '<div class="%s" %s>%s</div>', esc_attr( implode( ' ', $item_class ) ), $item_filter, balanceTags( $html_item ) );
244
-
245
- return $result;
246
- }
247
-
248
- /**
249
- * Wrap content of all items
250
- *
251
- * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
252
- * @param int $current_page The current page
253
- * @param int $post_per_page The number of posts per page
254
- * @param int $id ID of View
255
- *
256
- * @return string Full HTML output for Content View
257
- */
258
- static function content_items_wrap( $content_items, $current_page, $post_per_page, $id ) {
259
- global $dargs;
260
-
261
- if ( empty( $content_items ) ) {
262
- return '';
263
- }
264
-
265
- $content = array();
266
-
267
- $view_type = $dargs['view-type'];
268
-
269
- // Separate items by row, column
270
- switch ( $view_type ) {
271
-
272
- // Grid
273
- case 'grid':
274
-
275
- PT_CV_Html_ViewType::grid_wrapper( $content_items, $content );
276
-
277
- break;
278
-
279
- // Collapsible List
280
- case 'collapsible':
281
-
282
- PT_CV_Html_ViewType::collapsible_wrapper( $content_items, $content );
283
-
284
- break;
285
-
286
- // Scrollable List
287
- case 'scrollable':
288
-
289
- PT_CV_Html_ViewType::scrollable_wrapper( $content_items, $content );
290
-
291
- break;
292
-
293
- default :
294
- foreach ( $content_items as $post_id => $content_item ) {
295
- // Wrap content of item
296
- $content[] = PT_CV_Html::content_item_wrap( $content_item, '', $post_id );
297
- }
298
-
299
- $content = apply_filters( PT_CV_PREFIX_ . 'content_items_wrap', $content, $content_items, $current_page, $post_per_page );
300
-
301
- break;
302
- }
303
-
304
- // Join content
305
- $content_list = balanceTags( implode( "\n", $content ) );
306
-
307
- // Custom attribute of a page
308
- $page_attr_ = apply_filters( PT_CV_PREFIX_ . 'page_attr', '', $view_type, $content_items );
309
- $page_attr = strip_tags( $page_attr_ );
310
-
311
- // Wrap items in 'page' wrapper
312
- $wrap_in_page = apply_filters( PT_CV_PREFIX_ . 'wrap_in_page', true );
313
- if ( $wrap_in_page ) {
314
- // Wrap in page wrapper
315
- $html = sprintf( '<div id="%s" class="%s" %s>%s</div>', esc_attr( PT_CV_PREFIX . 'page' . '-' . $current_page ), esc_attr( PT_CV_PREFIX . 'page' ), $page_attr, $content_list );
316
- // Remove page attribute value
317
- $page_attr = '';
318
- } else {
319
- $html = $content_list;
320
- }
321
-
322
- // If is first page, wrap content in 'view' wrapper
323
- if ( $current_page === 1 ) {
324
- // Get wrapper class of a view
325
- $view_class = apply_filters( PT_CV_PREFIX_ . 'view_class', array( PT_CV_PREFIX . 'view', PT_CV_PREFIX . $view_type ) );
326
-
327
- // ID for the wrapper
328
- $view_id = PT_CV_PREFIX . 'view-' . $id;
329
-
330
- $output = sprintf( '<div class="%s" id="%s" %s>%s</div>', esc_attr( implode( ' ', array_filter( $view_class ) ) ), esc_attr( $view_id ), $page_attr, $html );
331
-
332
- do_action( PT_CV_PREFIX_ . 'store_view_data', $view_id );
333
- } else {
334
- $output = $html;
335
- }
336
-
337
- $before_output = ( $current_page === 1 ) ? apply_filters( PT_CV_PREFIX_ . 'before_output_html', '' ) : '';
338
-
339
- return balanceTags( $before_output ) . balanceTags( $output );
340
- }
341
-
342
- /**
343
- * HTML output of a field (thumbnail, title, content, meta fields...)
344
- *
345
- * @param string $field_name The name of field
346
- * @param object $post The post object
347
- * @param array $fargs The array of Field settings
348
- *
349
- * @return string
350
- */
351
- static function field_item_html( $field_name, $post, $fargs ) {
352
- global $dargs;
353
-
354
- if ( empty( $field_name ) ) {
355
- return '';
356
- }
357
-
358
- $html = '';
359
-
360
- // Get other settings
361
- $oargs = isset( $dargs['other-settings'] ) ? $dargs['other-settings'] : array();
362
-
363
- switch ( $field_name ) {
364
-
365
- // Thumbnail
366
- case 'thumbnail':
367
-
368
- if ( empty( $fargs['thumbnail'] ) ) {
369
- break;
370
- }
371
-
372
- $html = self::_field_thumbnail( $post, $fargs );
373
-
374
- break;
375
-
376
- // Title
377
- case 'title':
378
-
379
- // Get title class
380
- $title_class = apply_filters( PT_CV_PREFIX_ . 'field_title_class', PT_CV_PREFIX . 'title' );
381
-
382
- // Get title tag
383
- $tag = apply_filters( PT_CV_PREFIX_ . 'field_title_tag', 'h4' );
384
-
385
- // Get post title
386
- $title = get_the_title( $post );
387
- if ( empty( $title ) ) {
388
- $title = __( '(no title)', PT_CV_DOMAIN );
389
- }
390
-
391
- $html = sprintf(
392
- '<%1$s class="%2$s">%3$s</%1$s>',
393
- $tag, esc_attr( $title_class ), self::_field_href( $oargs, $post, $title )
394
- );
395
-
396
- break;
397
-
398
- // Content
399
- case 'content':
400
-
401
- if ( empty( $fargs['content'] ) ) {
402
- break;
403
- }
404
-
405
- // Sets up global post data
406
- setup_postdata( $post );
407
-
408
- // Handle the more tag inside content
409
- do_action( PT_CV_PREFIX_ . 'handle_teaser' );
410
-
411
- // Get content class
412
- $content_class = apply_filters( PT_CV_PREFIX_ . 'field_content_class', PT_CV_PREFIX . 'content' );
413
-
414
- // Get content tag (div/p/span...)
415
- $tag = apply_filters( PT_CV_PREFIX_ . 'field_content_tag', 'div' );
416
-
417
- // Get full content/exceprt
418
- $content = '';
419
- switch ( $fargs['content']['show'] ) {
420
- case 'excerpt':
421
- $length = (int) $fargs['content']['length'];
422
- $readmore = '<br />' . PT_CV_Html::link_button( get_permalink(), 'success', __( 'Read More', PT_CV_DOMAIN ), PT_CV_PREFIX . 'readmore', 'btn-sm' );
423
- $readmore_btn = ' ...' . apply_filters( PT_CV_PREFIX_ . 'field_content_readmore', $readmore, $fargs['content'], get_permalink() );
424
- $content = apply_filters( PT_CV_PREFIX_ . 'field_content_result', '', $fargs, $post );
425
-
426
- if ( empty( $content ) ) {
427
- $content = wp_trim_words( strip_shortcodes( get_the_content() ), $length, $readmore_btn );
428
- }
429
- // Force balance tags
430
- $content = force_balance_tags( $content );
431
-
432
- break;
433
-
434
- case 'full':
435
- ob_start();
436
- the_content();
437
- $content = ob_get_clean();
438
-
439
- break;
440
- }
441
-
442
- $html = sprintf(
443
- '<%1$s class="%2$s">%3$s</%1$s>',
444
- $tag, esc_attr( $content_class ), balanceTags( $content )
445
- );
446
-
447
- break;
448
-
449
- // Meta fields
450
- case 'meta-fields':
451
-
452
- if ( empty( $fargs['meta-fields'] ) ) {
453
- break;
454
- }
455
-
456
- $html = self::_field_meta( $post, $fargs['meta-fields'] );
457
-
458
- break;
459
-
460
- default :
461
- $html = apply_filters( PT_CV_PREFIX_ . 'field_item_html', $html, $field_name, $post );
462
- break;
463
- }
464
-
465
- return $html;
466
- }
467
-
468
- /**
469
- * Output link to item
470
- *
471
- * @param array $oargs The other settings
472
- * @param object $post The post object
473
- * @param string $content The HTML of <a> tag
474
- */
475
- static function _field_href( $oargs, $post, $content ) {
476
-
477
- // Open in
478
- $open_in = isset( $oargs['open-in'] ) ? $oargs['open-in'] : '_blank';
479
-
480
- // Class of href
481
- $href_class = apply_filters( PT_CV_PREFIX_ . 'field_href_class', array( $open_in ), $oargs );
482
-
483
- // Custom data
484
- $custom_attr = apply_filters( PT_CV_PREFIX_ . 'field_href_attrs', array(), $open_in, $oargs );
485
-
486
- // Don't wrap link
487
- $no_link = apply_filters( PT_CV_PREFIX_ . 'field_href_no_link', 0, $open_in );
488
-
489
- if ( $no_link ) {
490
- $html = $content;
491
- } else {
492
- $html = sprintf(
493
- '<a href="%s" class="%s" target="%s" %s>%s</a>',
494
- get_permalink( $post->ID ), implode( ' ', array_filter( $href_class ) ), $open_in, implode( ' ', array_filter( $custom_attr ) ), balanceTags( $content )
495
- );
496
- }
497
-
498
- return $html;
499
- }
500
-
501
- /**
502
- * HTML output of thumbnail field
503
- *
504
- * @param object $post The post object
505
- * @param array $fargs The settings of this field
506
- *
507
- * @return string
508
- */
509
- static function _field_thumbnail( $post, $fargs ) {
510
- global $dargs;
511
-
512
- // Get layout format
513
- $layout_format = $fargs['layout-format'];
514
-
515
- // Get thumbnail settings
516
- $fargs = $fargs['thumbnail'];
517
-
518
- $html = '';
519
-
520
- // Get post ID
521
- $post_id = $post->ID;
522
-
523
- // Custom args for get_the_post_thumbnail function
524
- $thumbnail_class = array();
525
- $thumbnail_class[] = PT_CV_PREFIX . 'thumbnail';
526
- $thumbnail_class[] = isset( $fargs['style'] ) ? $fargs['style'] : '';
527
- if ( $layout_format === '2-col' ) {
528
- $thumbnail_class[] = isset( $fargs['position'] ) ? 'pull-' . $fargs['position'] : 'pull-left';
529
- }
530
- $gargs = array(
531
- 'class' => apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_class', implode( ' ', array_filter( $thumbnail_class ) ) ),
532
- );
533
-
534
- // Get thumbnail dimensions
535
- $dimensions = PT_CV_Functions::field_thumbnail_dimensions( $fargs );
536
- $dimensions = (array) apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_dimension_output', $dimensions, $fargs );
537
-
538
- // Check if has thumbnail ( has_post_thumbnail doesn't works )
539
- $has_thumbnail = get_the_post_thumbnail( $post_id );
540
- if ( ! empty( $has_thumbnail ) ) {
541
- $thumbnail_size = count( $dimensions ) > 1 ? $dimensions : $dimensions[0];
542
- $html = get_the_post_thumbnail( $post_id, $thumbnail_size, $gargs );
543
- } else {
544
- $html = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_not_found', $html, $post, $dimensions, $gargs );
545
- }
546
-
547
- // Add link to thumbnail
548
- $oargs = isset( $dargs['other-settings'] ) ? $dargs['other-settings'] : array();
549
- $html = self::_field_href( $oargs, $post, $html );
550
-
551
- return $html;
552
- }
553
-
554
- /**
555
- * HTML output of meta fields group
556
- *
557
- * @param object $post The post object
558
- * @param array $fargs The settings of this field
559
- *
560
- * @return string
561
- */
562
- static function _field_meta( $post, $fargs ) {
563
-
564
- $html = array();
565
-
566
- // Sets up global post data
567
- setup_postdata( $post );
568
-
569
- foreach ( $fargs as $meta => $val ) {
570
- if ( ! $val ) {
571
- continue;
572
- }
573
-
574
- switch ( $meta ) {
575
- case 'date':
576
- // Get date wrapper class
577
- $date_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'entry-date', 'date' );
578
- $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', '', 'date' );
579
-
580
- $html['date'] = sprintf( '<span class="%s">%s <time datetime="%s">%s</time></span>', esc_html( $date_class ), balanceTags( $prefix_text ), esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) );
581
- break;
582
-
583
- case 'taxonomy':
584
-
585
- // Get terms wrapper class
586
- $term_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'terms', 'terms' );
587
- $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', __( 'in', PT_CV_DOMAIN ), 'terms' );
588
-
589
- $terms = PT_CV_Functions::post_terms( $post );
590
- if ( ! empty( $terms ) ) {
591
- $html['taxonomy'] = sprintf( '<span class="%s">%s %s</span>', esc_attr( $term_class ), balanceTags( $prefix_text ), balanceTags( $terms ) );
592
- }
593
- break;
594
-
595
- case 'comment':
596
- if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) :
597
- // Get comment wrapper class
598
- $comment_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'comments-link', 'comment' );
599
- $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', '', 'comment' );
600
-
601
- ob_start();
602
- comments_popup_link( __( 'Leave a comment', PT_CV_DOMAIN ), __( '1 Comment', PT_CV_DOMAIN ), __( '% Comments', PT_CV_DOMAIN ) );
603
- $comment_content = ob_get_clean();
604
- $html['comment'] = sprintf( '<span class="%s">%s %s</span>', esc_attr( $comment_class ), balanceTags( $prefix_text ), $comment_content );
605
- endif;
606
- break;
607
-
608
- case 'author':
609
-
610
- // Get author wrapper class
611
- $author_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'author', 'author' );
612
- $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', __( 'by', PT_CV_DOMAIN ), 'author' );
613
-
614
- $author_html = sprintf( '<span class="%s">%s <a href="%s" rel="author">%s</a></span>', esc_attr( $author_class ), balanceTags( $prefix_text ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() );
615
- $html['author'] = apply_filters( PT_CV_PREFIX_ . 'field_meta_author_html', $author_html, $post );
616
- break;
617
-
618
- default:
619
- break;
620
- }
621
- }
622
-
623
- // Merge fields, or let them as seperate items in array
624
- $merge_fields = apply_filters( PT_CV_PREFIX_ . 'field_meta_merge_fields', true );
625
-
626
- if ( $merge_fields ) {
627
- $result = PT_CV_Html::_field_meta_wrap( $html );
628
- } else {
629
- $result = $html;
630
- }
631
-
632
- return $result;
633
- }
634
-
635
- /**
636
- * Wrap meta fields in a wrapper
637
- *
638
- * @param array $meta_html Array of meta fields to wrapping
639
- * @param string $seperator Seperator string when join meta fields
640
- *
641
- * @return string
642
- */
643
- static function _field_meta_wrap( $meta_html, $seperator = NULL ) {
644
-
645
- $seperator = isset( $seperator ) ? $seperator : apply_filters( PT_CV_PREFIX_ . 'field_meta_seperator', ' / ' );
646
-
647
- // Get meta fields class
648
- $meta_fields_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_class', PT_CV_PREFIX . 'meta-fields' );
649
-
650
- // Get meta fields tag
651
- $tag = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_tag', 'div' );
652
-
653
- // Define wrapper
654
- $wrapper = sprintf(
655
- '<%1$s class="%2$s">%3$s</%1$s>',
656
- $tag, esc_attr( $meta_fields_class ), '%s'
657
- );
658
-
659
- // Join fields
660
- $meta_html = implode( $seperator, (array) $meta_html );
661
-
662
- // Wrap
663
- $html = sprintf( $wrapper, balanceTags( $meta_html ) );
664
-
665
- return $html;
666
- }
667
-
668
- /**
669
- * Output pagination
670
- *
671
- * @param type $max_num_pages The total of pages
672
- * @param string $session_id The session ID of current view
673
- *
674
- * @return type
675
- */
676
- static function pagination_output( $max_num_pages, $session_id ) {
677
- global $dargs;
678
-
679
- if ( ! $max_num_pages || (int) $max_num_pages === 1 ) {
680
- return '';
681
- }
682
-
683
- $pagination_btn = '';
684
-
685
- $style = isset( $dargs['pagination-settings']['style'] ) ? $dargs['pagination-settings']['style'] : 'regular';
686
- if ( $style == 'regular' ) {
687
- $pagination_btn = sprintf( '<ul class="%s" data-totalpages="%s" data-sid="%s"></ul>', PT_CV_PREFIX . 'pagination', esc_attr( $max_num_pages ), esc_attr( $session_id ) );
688
- } else {
689
- $pagination_btn = apply_filters( PT_CV_PREFIX_ . 'btn_more_html', $pagination_btn, $max_num_pages, $session_id );
690
- }
691
- // Add loading icon
692
- $pagination_btn .= self::html_loading_img( 12, PT_CV_PREFIX . 'spinner' );
693
-
694
- $output = apply_filters( PT_CV_PREFIX_ . 'pagination_output', $pagination_btn );
695
-
696
- return $output;
697
- }
698
-
699
- /**
700
- * Get assets content of all selected view types in a page
701
- * by merging css files to public/assets/css/public.css, js files to public/assets/js/public.js
702
- */
703
- static function assets_of_view_types() {
704
- $assets = array( 'css', 'js' );
705
- $assets_output = $assets_files = array();
706
-
707
- // Get content of asset files in directory of view type
708
- foreach ( self::$view_type_dir as $idx => $view_type_dir ) {
709
- // Get selected style of current view type
710
- $style = self::$style[$idx];
711
-
712
- // With each type of asset (css, js), looking for suit file of selected style
713
- foreach ( $assets as $type ) {
714
- $file_path = $view_type_dir . '/' . $type . '/' . $style . '.' . $type;
715
- $content = PT_CV_Functions::file_include_content( $file_path );
716
- if ( $content ) {
717
- $assets_output[$type][] = $content;
718
- }
719
- }
720
- }
721
-
722
- // Echo script, style inline
723
- if ( $assets_output ) {
724
-
725
- foreach ( $assets_output as $type => $contents ) {
726
- $content = implode( "\n", $contents );
727
-
728
- if ( $type == 'js' ) {
729
- echo balanceTags( self::inline_script( $content, false ) );
730
- } else {
731
- echo balanceTags( self::inline_style( $content ) );
732
- }
733
- }
734
- }
735
-
736
- // Link to external files
737
- $assets_files = apply_filters( PT_CV_PREFIX_ . 'assets_files', array() );
738
-
739
- if ( is_admin() ) {
740
- // Include assets file in Preview
741
- foreach ( $assets_files as $type => $srcs ) {
742
- foreach ( $srcs as $src ) {
743
- PT_CV_Asset::include_inline( 'preview', $src, $type );
744
- }
745
- }
746
- } else {
747
- // Enqueue merged asset contents
748
- foreach ( $assets_files as $type => $srcs ) {
749
- foreach ( $srcs as $src ) {
750
- $type = ( $type == 'js' ) ? 'script' : 'style';
751
- $function = "wp_enqueue_{$type}";
752
-
753
- if ( function_exists( $function ) ) {
754
- $function( PT_CV_PREFIX . $type, $src );
755
- }
756
- }
757
- }
758
- }
759
-
760
- // Output font style for views
761
- do_action( PT_CV_PREFIX_ . 'print_view_style' );
762
- }
763
-
764
- /**
765
- * Scripts for Preview & WP frontend
766
- *
767
- * @param bool $is_admin Whether or not in WP Admin
768
- */
769
- static function frontend_scripts( $is_admin = false ) {
770
-
771
- // Get settings option
772
- $options = get_option( PT_CV_OPTION_NAME );
773
-
774
- if ( $is_admin || ! isset( $options['unload_bootstrap'] ) ) {
775
- // Load bootstrap js
776
- PT_CV_Asset::enqueue( 'bootstrap' );
777
- }
778
-
779
- // Load bootstrap paginator
780
- PT_CV_Asset::enqueue( 'bootstrap-paginator' );
781
-
782
- // Public script
783
- PT_CV_Asset::enqueue(
784
- 'public', 'script', array(
785
- 'src' => plugins_url( 'public/assets/js/public.js', PT_CV_FILE ),
786
- 'deps' => array( 'jquery' ),
787
- )
788
- );
789
-
790
- // Localize for Public script
791
- PT_CV_Asset::localize_script(
792
- 'public', PT_CV_PREFIX_UPPER . 'PUBLIC', array(
793
- 'is_admin' => is_admin() ? 1 : 0,
794
- '_prefix' => PT_CV_PREFIX,
795
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
796
- 'lang' => PT_CV_Functions::get_language(),
797
- '_nonce' => wp_create_nonce( PT_CV_PREFIX_ . 'ajax_nonce' ),
798
- )
799
- );
800
- }
801
-
802
- /**
803
- * Styles for Preview & WP frontend
804
- *
805
- * @global bool $is_IE
806
- *
807
- * @param bool $is_admin Whether or not in WP Admin
808
- */
809
- static function frontend_styles( $is_admin = false ) {
810
-
811
- // Get settings option
812
- $options = get_option( PT_CV_OPTION_NAME );
813
-
814
- if ( $is_admin || ! isset( $options['unload_bootstrap'] ) ) {
815
- $data = apply_filters(
816
- PT_CV_PREFIX_ . 'assets_data',
817
- array(
818
- 'name' => 'bootstrap',
819
- 'type' => 'style',
820
- 'data' => '',
821
- 'prefix' => '',
822
- ), $is_admin, $options
823
- );
824
-
825
- PT_CV_Asset::enqueue( $data['name'], $data['type'], $data['data'], $data['prefix'] );
826
- }
827
-
828
- PT_CV_Asset::enqueue(
829
- 'public', 'style', array(
830
- 'src' => plugins_url( 'public/assets/css/public.css', PT_CV_FILE ),
831
- )
832
- );
833
-
834
- // Fix bootstrap error in IE
835
- global $is_IE;
836
- if ( $is_IE ) {
837
- PT_CV_Asset::enqueue(
838
- 'html5shiv', 'script', array(
839
- 'src' => plugins_url( 'assets/ie-fix/html5shiv.min.js', PT_CV_FILE ),
840
- 'ver' => '3.7.0',
841
- )
842
- );
843
- PT_CV_Asset::enqueue(
844
- 'respond', 'script', array(
845
- 'src' => plugins_url( 'assets/ie-fix/respond.js', PT_CV_FILE ),
846
- 'ver' => '1.4.2',
847
- )
848
- );
849
- }
850
- }
851
-
852
- /**
853
- * Print inline js code
854
- *
855
- * @param string $js The js code
856
- *
857
- * @return string
858
- */
859
- static function inline_script( $js, $wrap = true ) {
860
- // Generate random id for script tag
861
- $random_id = PT_CV_Functions::string_random();
862
-
863
- ob_start();
864
- ?>
865
- <script type="text/javascript" id="<?php echo esc_attr( PT_CV_PREFIX . 'inline-script-' . $random_id ); ?>">
866
- <?php
867
- $format = $wrap ? "(function ($) {\n $(function () { %s }); \n}(jQuery));" : '%s';
868
- $content = balanceTags( $js );
869
- printf( $format, $content );
870
- ?>
871
- </script>
872
- <?php
873
- return ob_get_clean();
874
- }
875
-
876
- /**
877
- * Print inline css code
878
- *
879
- * @param string $css The css code
880
- *
881
- * @return string
882
- */
883
- static function inline_style( $css ) {
884
- // Generate random id for style tag
885
- $random_id = PT_CV_Functions::string_random();
886
-
887
- ob_start();
888
- ?>
889
- <style type="text/css" id="<?php echo esc_attr( PT_CV_PREFIX . 'inline-style-' . $random_id ); ?>">
890
- <?php echo balanceTags( $css ); ?>
891
- </style>
892
- <?php
893
- return ob_get_clean();
894
- }
895
- }
896
-
897
  }
1
+ <?php
2
+ /**
3
+ * HTML output, class, id generating
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! class_exists( 'PT_CV_Html' ) ) {
13
+
14
+ /**
15
+ * @name PT_CV_Html
16
+ * @todo related HTML functions: Define HTML layout, Set class name...
17
+ */
18
+ class PT_CV_Html {
19
+
20
+ // Store directory of selected view_types
21
+ static $view_type_dir = array();
22
+ // Store all selected styles
23
+ static $style = array();
24
+
25
+ /**
26
+ * return class for Panel (Group of) group of params
27
+ *
28
+ * @return string
29
+ */
30
+ static function html_panel_group_class() {
31
+ return 'panel-group';
32
+ }
33
+
34
+ /**
35
+ * Return ID for Panel (Group of) group of params
36
+ *
37
+ * @param string $id Unique id of element
38
+ *
39
+ * @return string
40
+ */
41
+ static function html_panel_group_id( $id ) {
42
+ return 'panel-group-' . $id;
43
+ }
44
+
45
+ /**
46
+ * Return class for no animation elements
47
+ *
48
+ * @return string
49
+ */
50
+ static function html_no_animation_class() {
51
+ return PT_CV_PREFIX . 'no-animation';
52
+ }
53
+
54
+ /**
55
+ * Return class for group of params
56
+ *
57
+ * @return string
58
+ */
59
+ static function html_group_class() {
60
+ return PT_CV_PREFIX . 'group';
61
+ }
62
+
63
+ /**
64
+ * Return ID for group of params
65
+ *
66
+ * @param string $id Unique id of element
67
+ *
68
+ * @return string
69
+ */
70
+ static function html_group_id( $id ) {
71
+ return self::html_group_class() . '-' . $id;
72
+ }
73
+
74
+ /**
75
+ * Collapse HTML
76
+ *
77
+ * @param string $parent_id Id of parent element
78
+ * @param string $id Unique id of element
79
+ * @param string $heading Heading text
80
+ * @param string $content Content
81
+ * @param bool $show Show/hide the content
82
+ */
83
+ static function html_collapse_one( $parent_id, $id, $heading, $content = '', $show = true ) {
84
+ $class = $show ? 'in' : '';
85
+ ob_start();
86
+ ?>
87
+ <div class="panel panel-primary pt-accordion">
88
+ <div class="panel-heading">
89
+ <h4 class="panel-title" title="<?php _e( 'Click to toggle', PT_CV_DOMAIN ); ?>">
90
+ <a class="pt-accordion-a" data-parent="#<?php echo esc_attr( $parent_id ); ?>" href="#<?php echo esc_attr( $id ); ?>">
91
+ <?php echo balanceTags( $heading ); ?>
92
+ </a>
93
+ </h4>
94
+ <span class="pull-right clickable"><i class="glyphicon glyphicon-minus"></i></span>
95
+ </div>
96
+ <div id="<?php echo esc_attr( $id ); ?>" class="panel-body <?php echo esc_attr( $class ); ?>">
97
+ <div class="panel-body">
98
+ <?php echo balanceTags( $content ); ?>
99
+ </div>
100
+ </div>
101
+ </div>
102
+ <?php
103
+ return ob_get_clean();
104
+ }
105
+
106
+ /**
107
+ * HTML content of Preview box
108
+ */
109
+ static function html_preview_box() {
110
+ ob_start();
111
+ ?>
112
+ <div class="panel panel-default collapse" id="<?php echo esc_attr( PT_CV_PREFIX ); ?>preview-box"></div>
113
+ <div class="text-center hidden" style="position: absolute; left: 50%; top: 160px;">
114
+ <?php echo balanceTags( self::html_loading_img() ); ?>
115
+ </div>
116
+ <?php
117
+ return ob_get_clean();
118
+ }
119
+
120
+ /**
121
+ * Show loading image
122
+ *
123
+ * @param type $dimension
124
+ *
125
+ * @return type
126
+ */
127
+ static function html_loading_img( $dimension = 16, $class = '' ) {
128
+ $img = sprintf( '<img width="%1$s" height="%1$s" class="%2$s" alt="%3$s" src="%4$s" /><div class="clear %5$s"></div>', esc_attr( $dimension ), esc_attr( $class ), __( 'loading', PT_CV_DOMAIN ), 'data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==', PT_CV_PREFIX . 'clear-pagination' );
129
+
130
+ return apply_filters( PT_CV_PREFIX_ . 'loading_image', $img );
131
+ }
132
+
133
+ /**
134
+ * Html output for button
135
+ *
136
+ * @param string $style Bootstrap type of button
137
+ * @param string $text Text of button
138
+ * @param string $class Class of button
139
+ * @param string $size Size of button
140
+ *
141
+ * @return string
142
+ */
143
+ static function html_button( $style, $text = 'Button', $class = '', $size = '' ) {
144
+ return sprintf( '<button type="button" class="btn btn-%s %s %s">%s</button>', $style, $class, $size, $text );
145
+ }
146
+
147
+ /**
148
+ * Html output for a link, but style as button
149
+ *
150
+ * @param string $link Value for href attribute of link
151
+ * @param string $style Bootstrap type of button
152
+ * @param string $text Text of button
153
+ * @param string $class Class of button
154
+ * @param string $size Size of button
155
+ *
156
+ * @return string
157
+ */
158
+ static function link_button( $link, $style, $text = 'Button', $class = '', $size = '' ) {
159
+ return sprintf( '<a href="%s" class="btn btn-%s %s %s">%s</a>', $link, $style, $class, $size, $text );
160
+ }
161
+
162
+ /**
163
+ * Get Output HTML of a View type
164
+ *
165
+ * @param string $view_type The view type (grid, collapse...)
166
+ * @param object $post The post object
167
+ * @param string $style The style of view type (main, style2...)
168
+ */
169
+ static function view_type_output( $view_type, $post, $style = 'main' ) {
170
+ global $dargs;
171
+ $content = NULL;
172
+
173
+ if ( empty( $view_type ) ) {
174
+ return $content;
175
+ }
176
+
177
+ // Get view type directory
178
+ $view_type_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_dir', PT_CV_VIEW_TYPE_OUTPUT, $view_type ) . $view_type;
179
+
180
+ // Get asset directory
181
+ $view_type_assets_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_asset', $view_type_dir, $view_type );
182
+
183
+ if ( is_dir( $view_type_dir ) ) {
184
+ // Store view type & asset information
185
+ self::$view_type_dir[] = $view_type_assets_dir;
186
+ self::$style[] = $style;
187
+
188
+ // Generate HTML output of all content fields
189
+ $fields_html = array();
190
+ foreach ( $dargs['fields'] as $field_name ) {
191
+ // Get settings of fields
192
+ $fargs = isset( $dargs['field-settings'] ) ? $dargs['field-settings'] : array();
193
+
194
+ $fargs['layout-format'] = $dargs['layout-format'];
195
+
196
+ // Get HTML output of field
197
+ $fields_html[$field_name] = self::field_item_html( $field_name, $post, $fargs );
198
+ }
199
+
200
+ // Get HTML content of view type, with specific style
201
+ $file_path = $view_type_dir . '/' . 'html' . '/' . $style . '.' . 'php';
202
+
203
+ if ( file_exists( $file_path ) ) {
204
+ ob_start();
205
+ // Include, not include_once
206
+ include $file_path;
207
+ $content = ob_get_clean();
208
+ }
209
+ }
210
+
211
+ return $content;
212
+ }
213
+
214
+ /**
215
+ * Wrap content of a item
216
+ *
217
+ * @param array $html_item The HTML output of a item
218
+ * @param string $class The extra wrapper class of a item, such as col span
219
+ * @param array $post_id The post ID
220
+ *
221
+ * @return string Full HTML output of a item
222
+ */
223
+ static function content_item_wrap( $html_item, $class = '', $post_id = 0 ) {
224
+ global $dargs;
225
+
226
+ if ( empty( $html_item ) ) {
227
+ return '';
228
+ }
229
+
230
+ if ( is_array( $dargs ) ) {
231
+ // If only show Title
232
+ if ( isset( $dargs['fields'] ) && count( (array) $dargs['fields'] ) == 1 && $dargs['fields'][0] === 'title' ) {
233
+ $class .= ' ' . PT_CV_PREFIX . 'only-title';
234
+ }
235
+ }
236
+
237
+ // Get wrapper class of a item
238
+ $layout = $dargs['layout-format'];
239
+ $item_class = apply_filters( PT_CV_PREFIX_ . 'content_item_class', array( $class, PT_CV_PREFIX . 'content-item', PT_CV_PREFIX . $layout ) );
240
+
241
+ $item_filter = apply_filters( PT_CV_PREFIX_ . 'content_item_filter_value', '', $post_id );
242
+
243
+ $result = sprintf( '<div class="%s" %s>%s</div>', esc_attr( implode( ' ', $item_class ) ), $item_filter, balanceTags( $html_item ) );
244
+
245
+ return $result;
246
+ }
247
+
248
+ /**
249
+ * Wrap content of all items
250
+ *
251
+ * @param array $content_items The array of Raw HTML output (is not wrapped) of each item
252
+ * @param int $current_page The current page
253
+ * @param int $post_per_page The number of posts per page
254
+ * @param int $id ID of View
255
+ *
256
+ * @return string Full HTML output for Content View
257
+ */
258
+ static function content_items_wrap( $content_items, $current_page, $post_per_page, $id ) {
259
+ global $dargs;
260
+
261
+ if ( empty( $content_items ) ) {
262
+ return '';
263
+ }
264
+
265
+ $content = array();
266
+
267
+ $view_type = $dargs['view-type'];
268
+
269
+ // Separate items by row, column
270
+ switch ( $view_type ) {
271
+
272
+ // Grid
273
+ case 'grid':
274
+
275
+ PT_CV_Html_ViewType::grid_wrapper( $content_items, $content );
276
+
277
+ break;
278
+
279
+ // Collapsible List
280
+ case 'collapsible':
281
+
282
+ PT_CV_Html_ViewType::collapsible_wrapper( $content_items, $content );
283
+
284
+ break;
285
+
286
+ // Scrollable List
287
+ case 'scrollable':
288
+
289
+ PT_CV_Html_ViewType::scrollable_wrapper( $content_items, $content );
290
+
291
+ break;
292
+
293
+ default :
294
+ foreach ( $content_items as $post_id => $content_item ) {
295
+ // Wrap content of item
296
+ $content[] = PT_CV_Html::content_item_wrap( $content_item, '', $post_id );
297
+ }
298
+
299
+ $content = apply_filters( PT_CV_PREFIX_ . 'content_items_wrap', $content, $content_items, $current_page, $post_per_page );
300
+
301
+ break;
302
+ }
303
+
304
+ // Join content
305
+ $content_list = balanceTags( implode( "\n", $content ) );
306
+
307
+ // Custom attribute of a page
308
+ $page_attr_ = apply_filters( PT_CV_PREFIX_ . 'page_attr', '', $view_type, $content_items );
309
+ $page_attr = strip_tags( $page_attr_ );
310
+
311
+ // Wrap items in 'page' wrapper
312
+ $wrap_in_page = apply_filters( PT_CV_PREFIX_ . 'wrap_in_page', true );
313
+ if ( $wrap_in_page ) {
314
+ // Wrap in page wrapper
315
+ $html = sprintf( '<div id="%s" class="%s" %s>%s</div>', esc_attr( PT_CV_PREFIX . 'page' . '-' . $current_page ), esc_attr( PT_CV_PREFIX . 'page' ), $page_attr, $content_list );
316
+ // Remove page attribute value
317
+ $page_attr = '';
318
+ } else {
319
+ $html = $content_list;
320
+ }
321
+
322
+ // If is first page, wrap content in 'view' wrapper
323
+ if ( $current_page === 1 ) {
324
+ // Get wrapper class of a view
325
+ $view_class = apply_filters( PT_CV_PREFIX_ . 'view_class', array( PT_CV_PREFIX . 'view', PT_CV_PREFIX . $view_type ) );
326
+
327
+ // ID for the wrapper
328
+ $view_id = PT_CV_PREFIX . 'view-' . $id;
329
+
330
+ $output = sprintf( '<div class="%s" id="%s" %s>%s</div>', esc_attr( implode( ' ', array_filter( $view_class ) ) ), esc_attr( $view_id ), $page_attr, $html );
331
+
332
+ do_action( PT_CV_PREFIX_ . 'store_view_data', $view_id );
333
+ } else {
334
+ $output = $html;
335
+ }
336
+
337
+ $before_output = ( $current_page === 1 ) ? apply_filters( PT_CV_PREFIX_ . 'before_output_html', '' ) : '';
338
+
339
+ return balanceTags( $before_output ) . balanceTags( $output );
340
+ }
341
+
342
+ /**
343
+ * HTML output of a field (thumbnail, title, content, meta fields...)
344
+ *
345
+ * @param string $field_name The name of field
346
+ * @param object $post The post object
347
+ * @param array $fargs The array of Field settings
348
+ *
349
+ * @return string
350
+ */
351
+ static function field_item_html( $field_name, $post, $fargs ) {
352
+ global $dargs;
353
+
354
+ if ( empty( $field_name ) ) {
355
+ return '';
356
+ }
357
+
358
+ $html = '';
359
+
360
+ // Get other settings
361
+ $oargs = isset( $dargs['other-settings'] ) ? $dargs['other-settings'] : array();
362
+
363
+ switch ( $field_name ) {
364
+
365
+ // Thumbnail
366
+ case 'thumbnail':
367
+
368
+ if ( empty( $fargs['thumbnail'] ) ) {
369
+ break;
370
+ }
371
+
372
+ $html = self::_field_thumbnail( $post, $fargs );
373
+
374
+ break;
375
+
376
+ // Title
377
+ case 'title':
378
+
379
+ // Get title class
380
+ $title_class = apply_filters( PT_CV_PREFIX_ . 'field_title_class', PT_CV_PREFIX . 'title' );
381
+
382
+ // Get title tag
383
+ $tag = apply_filters( PT_CV_PREFIX_ . 'field_title_tag', 'h4' );
384
+
385
+ // Get post title
386
+ $title = get_the_title( $post );
387
+ if ( empty( $title ) ) {
388
+ $title = __( '(no title)', PT_CV_DOMAIN );
389
+ }
390
+
391
+ $html = sprintf(
392
+ '<%1$s class="%2$s">%3$s</%1$s>',
393
+ $tag, esc_attr( $title_class ), self::_field_href( $oargs, $post, $title )
394
+ );
395
+
396
+ break;
397
+
398
+ // Content
399
+ case 'content':
400
+
401
+ if ( empty( $fargs['content'] ) ) {
402
+ break;
403
+ }
404
+
405
+ // Sets up global post data
406
+ setup_postdata( $post );
407
+
408
+ // Handle the more tag inside content
409
+ do_action( PT_CV_PREFIX_ . 'handle_teaser' );
410
+
411
+ // Get content class
412
+ $content_class = apply_filters( PT_CV_PREFIX_ . 'field_content_class', PT_CV_PREFIX . 'content' );
413
+
414
+ // Get content tag (div/p/span...)
415
+ $tag = apply_filters( PT_CV_PREFIX_ . 'field_content_tag', 'div' );
416
+
417
+ // Get full content/exceprt
418
+ $content = '';
419
+ switch ( $fargs['content']['show'] ) {
420
+ case 'excerpt':
421
+ $length = (int) $fargs['content']['length'];
422
+ $readmore = '<br />' . PT_CV_Html::link_button( get_permalink(), 'success', __( 'Read More', PT_CV_DOMAIN ), PT_CV_PREFIX . 'readmore', 'btn-sm' );
423
+ $readmore_btn = ' ...' . apply_filters( PT_CV_PREFIX_ . 'field_content_readmore', $readmore, $fargs['content'], get_permalink() );
424
+ $content = apply_filters( PT_CV_PREFIX_ . 'field_content_result', '', $fargs, $post );
425
+
426
+ if ( empty( $content ) ) {
427
+ $content = wp_trim_words( strip_shortcodes( get_the_content() ), $length, $readmore_btn );
428
+ }
429
+ // Force balance tags
430
+ $content = force_balance_tags( $content );
431
+
432
+ break;
433
+
434
+ case 'full':
435
+ ob_start();
436
+ the_content();
437
+ $content = ob_get_clean();
438
+
439
+ break;
440
+ }
441
+
442
+ $html = sprintf(
443
+ '<%1$s class="%2$s">%3$s</%1$s>',
444
+ $tag, esc_attr( $content_class ), balanceTags( $content )
445
+ );
446
+
447
+ break;
448
+
449
+ // Meta fields
450
+ case 'meta-fields':
451
+
452
+ if ( empty( $fargs['meta-fields'] ) ) {
453
+ break;
454
+ }
455
+
456
+ $html = self::_field_meta( $post, $fargs['meta-fields'] );
457
+
458
+ break;
459
+
460
+ default :
461
+ $html = apply_filters( PT_CV_PREFIX_ . 'field_item_html', $html, $field_name, $post );
462
+ break;
463
+ }
464
+
465
+ return $html;
466
+ }
467
+
468
+ /**
469
+ * Output link to item
470
+ *
471
+ * @param array $oargs The other settings
472
+ * @param object $post The post object
473
+ * @param string $content The HTML of <a> tag
474
+ */
475
+ static function _field_href( $oargs, $post, $content ) {
476
+
477
+ // Open in
478
+ $open_in = isset( $oargs['open-in'] ) ? $oargs['open-in'] : '_blank';
479
+
480
+ // Class of href
481
+ $href_class = apply_filters( PT_CV_PREFIX_ . 'field_href_class', array( $open_in ), $oargs );
482
+
483
+ // Custom data
484
+ $custom_attr = apply_filters( PT_CV_PREFIX_ . 'field_href_attrs', array(), $open_in, $oargs );
485
+
486
+ // Don't wrap link
487
+ $no_link = apply_filters( PT_CV_PREFIX_ . 'field_href_no_link', 0, $open_in );
488
+
489
+ if ( $no_link ) {
490
+ $html = $content;
491
+ } else {
492
+ $html = sprintf(
493
+ '<a href="%s" class="%s" target="%s" %s>%s</a>',
494
+ get_permalink( $post->ID ), implode( ' ', array_filter( $href_class ) ), $open_in, implode( ' ', array_filter( $custom_attr ) ), balanceTags( $content )
495
+ );
496
+ }
497
+
498
+ return $html;
499
+ }
500
+
501
+ /**
502
+ * HTML output of thumbnail field
503
+ *
504
+ * @param object $post The post object
505
+ * @param array $fargs The settings of this field
506
+ *
507
+ * @return string
508
+ */
509
+ static function _field_thumbnail( $post, $fargs ) {
510
+ global $dargs;
511
+
512
+ // Get layout format
513
+ $layout_format = $fargs['layout-format'];
514
+
515
+ // Get thumbnail settings
516
+ $fargs = $fargs['thumbnail'];
517
+
518
+ $html = '';
519
+
520
+ // Get post ID
521
+ $post_id = $post->ID;
522
+
523
+ // Custom args for get_the_post_thumbnail function
524
+ $thumbnail_class = array();
525
+ $thumbnail_class[] = PT_CV_PREFIX . 'thumbnail';
526
+ $thumbnail_class[] = isset( $fargs['style'] ) ? $fargs['style'] : '';
527
+ if ( $layout_format === '2-col' ) {
528
+ $thumbnail_class[] = isset( $fargs['position'] ) ? 'pull-' . $fargs['position'] : 'pull-left';
529
+ }
530
+ $gargs = array(
531
+ 'class' => apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_class', implode( ' ', array_filter( $thumbnail_class ) ) ),
532
+ );
533
+
534
+ // Get thumbnail dimensions
535
+ $dimensions = PT_CV_Functions::field_thumbnail_dimensions( $fargs );
536
+ $dimensions = (array) apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_dimension_output', $dimensions, $fargs );
537
+
538
+ // Check if has thumbnail ( has_post_thumbnail doesn't works )
539
+ $has_thumbnail = get_the_post_thumbnail( $post_id );
540
+ if ( ! empty( $has_thumbnail ) ) {
541
+ $thumbnail_size = count( $dimensions ) > 1 ? $dimensions : $dimensions[0];
542
+ $html = get_the_post_thumbnail( $post_id, $thumbnail_size, $gargs );
543
+ } else {
544
+ $html = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_not_found', $html, $post, $dimensions, $gargs );
545
+ }
546
+
547
+ // Add link to thumbnail
548
+ $oargs = isset( $dargs['other-settings'] ) ? $dargs['other-settings'] : array();
549
+ $html = self::_field_href( $oargs, $post, $html );
550
+
551
+ return $html;
552
+ }
553
+
554
+ /**
555
+ * HTML output of meta fields group
556
+ *
557
+ * @param object $post The post object
558
+ * @param array $fargs The settings of this field
559
+ *
560
+ * @return string
561
+ */
562
+ static function _field_meta( $post, $fargs ) {
563
+
564
+ $html = array();
565
+
566
+ // Sets up global post data
567
+ setup_postdata( $post );
568
+
569
+ foreach ( $fargs as $meta => $val ) {
570
+ if ( ! $val ) {
571
+ continue;
572
+ }
573
+
574
+ switch ( $meta ) {
575
+ case 'date':
576
+ // Get date wrapper class
577
+ $date_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'entry-date', 'date' );
578
+ $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', '', 'date' );
579
+
580
+ $html['date'] = sprintf( '<span class="%s">%s <time datetime="%s">%s</time></span>', esc_html( $date_class ), balanceTags( $prefix_text ), esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() ) );
581
+ break;
582
+
583
+ case 'taxonomy':
584
+
585
+ // Get terms wrapper class
586
+ $term_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'terms', 'terms' );
587
+ $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', __( 'in', PT_CV_DOMAIN ), 'terms' );
588
+
589
+ $terms = PT_CV_Functions::post_terms( $post );
590
+ if ( ! empty( $terms ) ) {
591
+ $html['taxonomy'] = sprintf( '<span class="%s">%s %s</span>', esc_attr( $term_class ), balanceTags( $prefix_text ), balanceTags( $terms ) );
592
+ }
593
+ break;
594
+
595
+ case 'comment':
596
+ if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) :
597
+ // Get comment wrapper class
598
+ $comment_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'comments-link', 'comment' );
599
+ $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', '', 'comment' );
600
+
601
+ ob_start();
602
+ comments_popup_link( __( 'Leave a comment', PT_CV_DOMAIN ), __( '1 Comment', PT_CV_DOMAIN ), __( '% Comments', PT_CV_DOMAIN ) );
603
+ $comment_content = ob_get_clean();
604
+ $html['comment'] = sprintf( '<span class="%s">%s %s</span>', esc_attr( $comment_class ), balanceTags( $prefix_text ), $comment_content );
605
+ endif;
606
+ break;
607
+
608
+ case 'author':
609
+
610
+ // Get author wrapper class
611
+ $author_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_class', 'author', 'author' );
612
+ $prefix_text = apply_filters( PT_CV_PREFIX_ . 'field_meta_prefix_text', __( 'by', PT_CV_DOMAIN ), 'author' );
613
+
614
+ $author_html = sprintf( '<span class="%s">%s <a href="%s" rel="author">%s</a></span>', esc_attr( $author_class ), balanceTags( $prefix_text ), esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), get_the_author() );
615
+ $html['author'] = apply_filters( PT_CV_PREFIX_ . 'field_meta_author_html', $author_html, $post );
616
+ break;
617
+
618
+ default:
619
+ break;
620
+ }
621
+ }
622
+
623
+ // Merge fields, or let them as seperate items in array
624
+ $merge_fields = apply_filters( PT_CV_PREFIX_ . 'field_meta_merge_fields', true );
625
+
626
+ if ( $merge_fields ) {
627
+ $result = PT_CV_Html::_field_meta_wrap( $html );
628
+ } else {
629
+ $result = $html;
630
+ }
631
+
632
+ return $result;
633
+ }
634
+
635
+ /**
636
+ * Wrap meta fields in a wrapper
637
+ *
638
+ * @param array $meta_html Array of meta fields to wrapping
639
+ * @param string $seperator Seperator string when join meta fields
640
+ *
641
+ * @return string
642
+ */
643
+ static function _field_meta_wrap( $meta_html, $seperator = NULL ) {
644
+
645
+ $seperator = isset( $seperator ) ? $seperator : apply_filters( PT_CV_PREFIX_ . 'field_meta_seperator', ' / ' );
646
+
647
+ // Get meta fields class
648
+ $meta_fields_class = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_class', PT_CV_PREFIX . 'meta-fields' );
649
+
650
+ // Get meta fields tag
651
+ $tag = apply_filters( PT_CV_PREFIX_ . 'field_meta_fields_tag', 'div' );
652
+
653
+ // Define wrapper
654
+ $wrapper = sprintf(
655
+ '<%1$s class="%2$s">%3$s</%1$s>',
656
+ $tag, esc_attr( $meta_fields_class ), '%s'
657
+ );
658
+
659
+ // Join fields
660
+ $meta_html = implode( $seperator, (array) $meta_html );
661
+
662
+ // Wrap
663
+ $html = sprintf( $wrapper, balanceTags( $meta_html ) );
664
+
665
+ return $html;
666
+ }
667
+
668
+ /**
669
+ * Output pagination
670
+ *
671
+ * @param type $max_num_pages The total of pages
672
+ * @param string $session_id The session ID of current view
673
+ *
674
+ * @return type
675
+ */
676
+ static function pagination_output( $max_num_pages, $session_id ) {
677
+ global $dargs;
678
+
679
+ if ( ! $max_num_pages || (int) $max_num_pages === 1 ) {
680
+ return '';
681
+ }
682
+
683
+ $pagination_btn = '';
684
+
685
+ $style = isset( $dargs['pagination-settings']['style'] ) ? $dargs['pagination-settings']['style'] : 'regular';
686
+ if ( $style == 'regular' ) {
687
+ $pagination_btn = sprintf( '<ul class="%s" data-totalpages="%s" data-sid="%s"></ul>', PT_CV_PREFIX . 'pagination', esc_attr( $max_num_pages ), esc_attr( $session_id ) );
688
+ } else {
689
+ $pagination_btn = apply_filters( PT_CV_PREFIX_ . 'btn_more_html', $pagination_btn, $max_num_pages, $session_id );
690
+ }
691
+ // Add loading icon
692
+ $pagination_btn .= self::html_loading_img( 12, PT_CV_PREFIX . 'spinner' );
693
+
694
+ $output = apply_filters( PT_CV_PREFIX_ . 'pagination_output', $pagination_btn );
695
+
696
+ return $output;
697
+ }
698
+
699
+ /**
700
+ * Get assets content of all selected view types in a page
701
+ * by merging css files to public/assets/css/public.css, js files to public/assets/js/public.js
702
+ */
703
+ static function assets_of_view_types() {
704
+ $assets = array( 'css', 'js' );
705
+ $assets_output = $assets_files = array();
706
+
707
+ // Get content of asset files in directory of view type
708
+ foreach ( self::$view_type_dir as $idx => $view_type_dir ) {
709
+ // Get selected style of current view type
710
+ $style = self::$style[$idx];
711
+
712
+ // With each type of asset (css, js), looking for suit file of selected style
713
+ foreach ( $assets as $type ) {
714
+ $file_path = $view_type_dir . '/' . $type . '/' . $style . '.' . $type;
715
+ $content = PT_CV_Functions::file_include_content( $file_path );
716
+ if ( $content ) {
717
+ $assets_output[$type][] = $content;
718
+ }
719
+ }
720
+ }
721
+
722
+ // Echo script, style inline
723
+ if ( $assets_output ) {
724
+
725
+ foreach ( $assets_output as $type => $contents ) {
726
+ $content = implode( "\n", $contents );
727
+
728
+ if ( $type == 'js' ) {
729
+ echo balanceTags( self::inline_script( $content, false ) );
730
+ } else {
731
+ echo balanceTags( self::inline_style( $content ) );
732
+ }
733
+ }
734
+ }
735
+
736
+ // Link to external files
737
+ $assets_files = apply_filters( PT_CV_PREFIX_ . 'assets_files', array() );
738
+
739
+ if ( is_admin() ) {
740
+ // Include assets file in Preview
741
+ foreach ( $assets_files as $type => $srcs ) {
742
+ foreach ( $srcs as $src ) {
743
+ PT_CV_Asset::include_inline( 'preview', $src, $type );
744
+ }
745
+ }
746
+ } else {
747
+ // Enqueue merged asset contents
748
+ foreach ( $assets_files as $type => $srcs ) {
749
+ foreach ( $srcs as $src ) {
750
+ $type = ( $type == 'js' ) ? 'script' : 'style';
751
+ $function = "wp_enqueue_{$type}";
752
+
753
+ if ( function_exists( $function ) ) {
754
+ $function( PT_CV_PREFIX . $type, $src );
755
+ }
756
+ }
757
+ }
758
+ }
759
+
760
+ // Output font style for views
761
+ do_action( PT_CV_PREFIX_ . 'print_view_style' );
762
+ }
763
+
764
+ /**
765
+ * Scripts for Preview & WP frontend
766
+ *
767
+ * @param bool $is_admin Whether or not in WP Admin
768
+ */
769
+ static function frontend_scripts( $is_admin = false ) {
770
+
771
+ // Get settings option
772
+ $options = get_option( PT_CV_OPTION_NAME );
773
+
774
+ if ( $is_admin || ! isset( $options['unload_bootstrap'] ) ) {
775
+ // Load bootstrap js
776
+ PT_CV_Asset::enqueue( 'bootstrap' );
777
+ }
778
+
779
+ // Load bootstrap paginator
780
+ PT_CV_Asset::enqueue( 'bootstrap-paginator' );
781
+
782
+ // Public script
783
+ PT_CV_Asset::enqueue(
784
+ 'public', 'script', array(
785
+ 'src' => plugins_url( 'public/assets/js/public.js', PT_CV_FILE ),
786
+ 'deps' => array( 'jquery' ),
787
+ )
788
+ );
789
+
790
+ // Localize for Public script
791
+ PT_CV_Asset::localize_script(
792
+ 'public', PT_CV_PREFIX_UPPER . 'PUBLIC', array(
793
+ 'is_admin' => is_admin() ? 1 : 0,
794
+ '_prefix' => PT_CV_PREFIX,
795
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
796
+ 'lang' => PT_CV_Functions::get_language(),
797
+ '_nonce' => wp_create_nonce( PT_CV_PREFIX_ . 'ajax_nonce' ),
798
+ )
799
+ );
800
+ }
801
+
802
+ /**
803
+ * Styles for Preview & WP frontend
804
+ *
805
+ * @global bool $is_IE
806
+ *
807
+ * @param bool $is_admin Whether or not in WP Admin
808
+ */
809
+ static function frontend_styles( $is_admin = false ) {
810
+
811
+ // Get settings option
812
+ $options = get_option( PT_CV_OPTION_NAME );
813
+
814
+ if ( $is_admin || ! isset( $options['unload_bootstrap'] ) ) {
815
+ $data = apply_filters(
816
+ PT_CV_PREFIX_ . 'assets_data',
817
+ array(
818
+ 'name' => 'bootstrap',
819
+ 'type' => 'style',
820
+ 'data' => '',
821
+ 'prefix' => '',
822
+ ), $is_admin, $options
823
+ );
824
+
825
+ PT_CV_Asset::enqueue( $data['name'], $data['type'], $data['data'], $data['prefix'] );
826
+ }
827
+
828
+ PT_CV_Asset::enqueue(
829
+ 'public', 'style', array(
830
+ 'src' => plugins_url( 'public/assets/css/public.css', PT_CV_FILE ),
831
+ )
832
+ );
833
+
834
+ // Fix bootstrap error in IE
835
+ global $is_IE;
836
+ if ( $is_IE ) {
837
+ PT_CV_Asset::enqueue(
838
+ 'html5shiv', 'script', array(
839
+ 'src' => plugins_url( 'assets/ie-fix/html5shiv.min.js', PT_CV_FILE ),
840
+ 'ver' => '3.7.0',
841
+ )
842
+ );
843
+ PT_CV_Asset::enqueue(
844
+ 'respond', 'script', array(
845
+ 'src' => plugins_url( 'assets/ie-fix/respond.js', PT_CV_FILE ),
846
+ 'ver' => '1.4.2',
847
+ )
848
+ );
849
+ }
850
+ }
851
+
852
+ /**
853
+ * Print inline js code
854
+ *
855
+ * @param string $js The js code
856
+ *
857
+ * @return string
858
+ */
859
+ static function inline_script( $js, $wrap = true ) {
860
+ // Generate random id for script tag
861
+ $random_id = PT_CV_Functions::string_random();
862
+
863
+ ob_start();
864
+ ?>
865
+ <script type="text/javascript" id="<?php echo esc_attr( PT_CV_PREFIX . 'inline-script-' . $random_id ); ?>">
866
+ <?php
867
+ $format = $wrap ? "(function ($) {\n $(function () { %s }); \n}(jQuery));" : '%s';
868
+ $content = balanceTags( $js );
869
+ printf( $format, $content );
870
+ ?>
871
+ </script>
872
+ <?php
873
+ return ob_get_clean();
874
+ }
875
+
876
+ /**
877
+ * Print inline css code
878
+ *
879
+ * @param string $css The css code
880
+ *
881
+ * @return string
882
+ */
883
+ static function inline_style( $css ) {
884
+ // Generate random id for style tag
885
+ $random_id = PT_CV_Functions::string_random();
886
+
887
+ ob_start();
888
+ ?>
889
+ <style type="text/css" id="<?php echo esc_attr( PT_CV_PREFIX . 'inline-style-' . $random_id ); ?>">
890
+ <?php echo balanceTags( $css ); ?>
891
+ </style>
892
+ <?php
893
+ return ob_get_clean();
894
+ }
895
+ }
896
+
897
  }
includes/settings.php CHANGED
@@ -1,741 +1,741 @@
1
- <?php
2
- /**
3
- * Define settings for options
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- if ( ! class_exists( 'PT_CV_Settings' ) ) {
13
-
14
- /**
15
- * @name PT_CV_Settings
16
- * @todo Define settings for options
17
- */
18
- class PT_CV_Settings {
19
-
20
- /**
21
- * Get collection : Taxonomies => Terms
22
- *
23
- * @param string $taxonomies Array of taxonomies
24
- * @param array $args Array of query parameters
25
- */
26
- static function terms_of_taxonomies( $taxonomies = array(), $args = array() ) {
27
- $terms_of_taxonomies = $result = array();
28
- // Get taxonomies
29
- $taxonomies = PT_CV_Values::taxonomy_list();
30
- // Get slug list of taxonomies
31
- $taxonomies_slug = array_keys( $taxonomies );
32
-
33
- foreach ( $taxonomies_slug as $taxonomy_slug ) {
34
- PT_CV_Values::term_of_taxonomy( $taxonomy_slug, $terms_of_taxonomies, $args );
35
- }
36
-
37
- foreach ( $terms_of_taxonomies as $taxonomy_slug => $terms ) {
38
-
39
- $result[$taxonomy_slug] = array(
40
-
41
- // Select term to filter
42
- array(
43
- 'label' => array(
44
- 'text' => __( 'Select terms', PT_CV_DOMAIN ),
45
- ),
46
- 'params' => array(
47
- array(
48
- 'type' => 'select',
49
- 'name' => $taxonomy_slug . '-terms[]',
50
- 'options' => $terms,
51
- 'std' => '',
52
- 'class' => 'select2',
53
- 'multiple' => '1',
54
- ),
55
- ),
56
- ),
57
-
58
- // Quick filter
59
- apply_filters( PT_CV_PREFIX_ . 'term_quick_filter', array() ),
60
-
61
- //Operator
62
- array(
63
- 'label' => array(
64
- 'text' => __( 'Operator', PT_CV_DOMAIN ),
65
- ),
66
- 'params' => array(
67
- array(
68
- 'type' => 'radio',
69
- 'name' => $taxonomy_slug . '-operator',
70
- 'options' => PT_CV_Values::taxonomy_operators(),
71
- 'std' => 'IN',
72
- ),
73
- ),
74
- ),
75
- );
76
- }
77
-
78
- return $result;
79
- }
80
-
81
- /**
82
- * Order by options
83
- *
84
- * @return array
85
- */
86
- static function orderby() {
87
- $result = array();
88
-
89
- $result['common'] = array(
90
- // Order By
91
- array(
92
- 'label' => array(
93
- 'text' => __( 'Order by', PT_CV_DOMAIN ),
94
- ),
95
- 'params' => array(
96
- array(
97
- 'type' => 'select',
98
- 'name' => 'orderby',
99
- 'options' => PT_CV_Values::post_regular_orderby(),
100
- 'std' => '',
101
- ),
102
- ),
103
- ),
104
- // Order
105
- array(
106
- 'label' => array(
107
- 'text' => __( 'Order', PT_CV_DOMAIN ),
108
- ),
109
- 'params' => array(
110
- array(
111
- 'type' => 'radio',
112
- 'name' => 'order',
113
- 'options' => PT_CV_Values::orders(),
114
- 'std' => 'asc',
115
- ),
116
- ),
117
- ),
118
- );
119
-
120
- $result = apply_filters( PT_CV_PREFIX_ . 'orderby', $result );
121
-
122
- return $result;
123
- }
124
-
125
- /**
126
- * Pagination settings
127
- *
128
- * @return array
129
- */
130
- static function settings_pagination() {
131
-
132
- $prefix = 'pagination-';
133
-
134
- $result = array(
135
-
136
- // Pagination
137
- array(
138
- 'label' => array(
139
- 'text' => __( 'Pagination', PT_CV_DOMAIN ),
140
- ),
141
- 'params' => array(
142
- array(
143
- 'type' => 'checkbox',
144
- 'name' => 'enable-pagination',
145
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Enable', PT_CV_DOMAIN ) ),
146
- 'std' => '',
147
- ),
148
- ),
149
- ),
150
-
151
- // Items per page
152
- array(
153
- 'label' => array(
154
- 'text' => __( 'Items per page', PT_CV_DOMAIN ),
155
- ),
156
- 'params' => array(
157
- array(
158
- 'type' => 'number',
159
- 'name' => $prefix . 'items-per-page',
160
- 'std' => '5',
161
- 'placeholder' => 'e.g. 5',
162
- 'append_text' => '1 &rarr; 100',
163
- 'desc' => __( 'The number of items per page.<br>If value of Limit option is not blank (empty), this value should be smaller than Limit value', PT_CV_DOMAIN ),
164
- ),
165
- ),
166
- 'dependence' => array( 'enable-pagination', 'yes' ),
167
- ),
168
-
169
- // Pagination Style
170
- array(
171
- 'label' => array(
172
- 'text' => __( 'Pagination style', PT_CV_DOMAIN ),
173
- ),
174
- 'params' => array(
175
- array(
176
- 'type' => 'radio',
177
- 'name' => $prefix . 'style',
178
- 'options' => PT_CV_Values::pagination_styles(),
179
- 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::pagination_styles() ),
180
- ),
181
- ),
182
- 'dependence' => array( 'enable-pagination', 'yes' ),
183
- ),
184
- );
185
-
186
- $result = apply_filters( PT_CV_PREFIX_ . 'settings_pagination', $result, $prefix );
187
-
188
- return $result;
189
- }
190
-
191
- /**
192
- * Other settings for All View Type
193
- */
194
- static function settings_other() {
195
-
196
- $prefix = 'other-';
197
-
198
- $result = array(
199
- // Open an item in
200
- array(
201
- 'label' => array(
202
- 'text' => __( 'Open item in', PT_CV_DOMAIN ),
203
- ),
204
- 'params' => array(
205
- array(
206
- 'type' => 'radio',
207
- 'name' => $prefix . 'open-in',
208
- 'options' => PT_CV_Values::open_in(),
209
- 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::open_in() ),
210
- 'desc' => __( 'How to open an item when click on Title or Thumbnail', PT_CV_DOMAIN ),
211
- ),
212
- ),
213
- ),
214
- );
215
-
216
- $result = apply_filters( PT_CV_PREFIX_ . 'settings_other', $result, $prefix );
217
-
218
- return $result;
219
- }
220
-
221
- /**
222
- * Fields settings
223
- */
224
- static function field_settings() {
225
-
226
- $prefix = 'field-';
227
- $prefix2 = 'show-' . $prefix;
228
-
229
- $result = array(
230
-
231
- // Fields display
232
- array(
233
- 'label' => array(
234
- 'text' => __( 'Fields display', PT_CV_DOMAIN ),
235
- ),
236
- 'extra_setting' => array(
237
- 'params' => array(
238
- 'wrap-class' => PT_CV_Html::html_group_class(),
239
- ),
240
- ),
241
- 'params' => array(
242
- array(
243
- 'type' => 'group',
244
- 'params' => PT_CV_Settings::field_display_settings(),
245
- ),
246
- ),
247
- ),
248
-
249
- // Thumbnail settings
250
- array(
251
- 'label' => array(
252
- 'text' => __( 'Thumbnail settings', PT_CV_DOMAIN ),
253
- ),
254
- 'extra_setting' => array(
255
- 'params' => array(
256
- 'wrap-class' => PT_CV_Html::html_group_class() . ' ' . PT_CV_PREFIX . 'thumbnail-setting',
257
- ),
258
- ),
259
- 'params' => array(
260
- array(
261
- 'type' => 'group',
262
- 'params' => PT_CV_Settings::field_thumbnail_settings( $prefix ),
263
- ),
264
- ),
265
- 'dependence' => array( $prefix2 . 'thumbnail', 'yes' ),
266
- ),
267
-
268
- // Meta fields settings
269
- array(
270
- 'label' => array(
271
- 'text' => __( 'Meta fields settings', PT_CV_DOMAIN ),
272
- ),
273
- 'extra_setting' => array(
274
- 'params' => array(
275
- 'wrap-class' => PT_CV_Html::html_group_class() . ' ' . PT_CV_PREFIX . 'meta-fields-settings',
276
- ),
277
- ),
278
- 'params' => array(
279
- array(
280
- 'type' => 'group',
281
- 'params' => PT_CV_Settings::field_meta_fields( 'meta-fields-' ),
282
- 'desc' => apply_filters( PT_CV_PREFIX_ . 'settings_sort_text', '' ),
283
- ),
284
- ),
285
- 'dependence' => array( $prefix2 . 'meta-fields', 'yes' ),
286
- ),
287
-
288
- // Taxonomies settings
289
- apply_filters( PT_CV_PREFIX_ . 'settings_taxonomies_display', array() ),
290
-
291
- // Content settings
292
- array(
293
- 'label' => array(
294
- 'text' => __( 'Content settings', PT_CV_DOMAIN ),
295
- ),
296
- 'params' => array(
297
- array(
298
- 'type' => 'radio',
299
- 'name' => $prefix . 'content-show',
300
- 'options' => array(
301
- 'full' => __( 'Show Full Content', PT_CV_DOMAIN ),
302
- 'excerpt' => __( 'Show Excerpt', PT_CV_DOMAIN ),
303
- ),
304
- 'std' => 'excerpt',
305
- ),
306
- ),
307
- 'dependence' => array( $prefix2 . 'content', 'yes' ),
308
- ),
309
-
310
- // Excerpt settings
311
- array(
312
- 'label' => array(
313
- 'text' => __( '', PT_CV_DOMAIN ),
314
- ),
315
- 'extra_setting' => array(
316
- 'params' => array(
317
- 'wrap-id' => PT_CV_Html::html_group_id( 'excerpt-settings' ),
318
- ),
319
- ),
320
- 'params' => array(
321
- array(
322
- 'type' => 'group',
323
- 'params' => apply_filters(
324
- PT_CV_PREFIX_ . 'excerpt_settings',
325
- array(
326
- // Excerpt length
327
- array(
328
- 'label' => array(
329
- 'text' => __( 'Excerpt length', PT_CV_DOMAIN ),
330
- ),
331
- 'extra_setting' => array(
332
- 'params' => array(
333
- 'width' => 9,
334
- ),
335
- ),
336
- 'params' => array(
337
- array(
338
- 'type' => 'number',
339
- 'name' => $prefix . 'excerpt-length',
340
- 'std' => '20',
341
- 'placeholder' => 'e.g. 20',
342
- 'append_text' => '1 &rarr; 100',
343
- 'desc' => __( 'Generating excerpt by selecting the first X words of the content', PT_CV_DOMAIN ),
344
- ),
345
- ),
346
- ),
347
- ),
348
- $prefix . 'excerpt-'
349
- ),
350
- ),
351
- ),
352
- 'dependence' => array( array( $prefix . 'content-show', 'excerpt' ) ),
353
- ),
354
- );
355
-
356
- $result = apply_filters( PT_CV_PREFIX_ . 'field_settings', $result, $prefix2 );
357
-
358
- return $result;
359
- }
360
-
361
- /**
362
- * Fields display
363
- *
364
- * @return array
365
- */
366
- static function field_display_settings() {
367
-
368
- $field_display_settings = array(
369
- array(
370
- 'label' => array(
371
- 'text' => __( '', PT_CV_DOMAIN ),
372
- ),
373
- 'extra_setting' => array(
374
- 'params' => array(
375
- 'width' => 12,
376
- 'wrap-class' => PT_CV_PREFIX . 'field-display',
377
- ),
378
- ),
379
- 'params' => array(
380
- array(
381
- 'type' => 'group',
382
- 'params' => PT_CV_Settings::field_display(),
383
- 'desc' => apply_filters( PT_CV_PREFIX_ . 'settings_sort_text', '' ),
384
- ),
385
- ),
386
- ),
387
- );
388
-
389
- $result = apply_filters( PT_CV_PREFIX_ . 'field_display_settings', $field_display_settings );
390
-
391
- return $result;
392
- }
393
-
394
- /**
395
- * Options to check/uncheck to display fields
396
- *
397
- * @return array
398
- */
399
- static function field_display() {
400
-
401
- $prefix = 'show-field-';
402
-
403
- $result = array(
404
-
405
- // Thumbnail position
406
- array(
407
- 'label' => array(
408
- 'text' => __( 'Thumbnail position', PT_CV_DOMAIN ),
409
- ),
410
- 'extra_setting' => array(
411
- 'params' => array(
412
- 'width' => 9,
413
- 'wrap-class' => PT_CV_PREFIX . 'bg-none',
414
- ),
415
- ),
416
- 'params' => array(
417
- array(
418
- 'type' => 'select',
419
- 'name' => 'field-' . 'thumbnail-position',
420
- 'options' => PT_CV_Values::thumbnail_position(),
421
- 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::thumbnail_position() ),
422
- ),
423
- ),
424
- 'dependence' => array( 'layout-format', '2-col' ),
425
- ),
426
-
427
- // Show Thumbnail
428
- array(
429
- 'label' => array(
430
- 'text' => __( '', PT_CV_DOMAIN ),
431
- ),
432
- 'extra_setting' => array(
433
- 'params' => array(
434
- 'width' => 12,
435
- ),
436
- ),
437
- 'params' => array(
438
- array(
439
- 'type' => 'checkbox',
440
- 'name' => $prefix . 'thumbnail',
441
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Thumbnail', PT_CV_DOMAIN ) ),
442
- 'std' => 'yes',
443
- ),
444
- ),
445
- 'dependence' => array( 'layout-format', '1-col' ),
446
- ),
447
-
448
- // Show Title
449
- array(
450
- 'label' => array(
451
- 'text' => __( '', PT_CV_DOMAIN ),
452
- ),
453
- 'extra_setting' => array(
454
- 'params' => array(
455
- 'width' => 12,
456
- ),
457
- ),
458
- 'params' => array(
459
- array(
460
- 'type' => 'checkbox',
461
- 'name' => $prefix . 'title',
462
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Title', PT_CV_DOMAIN ) ),
463
- 'std' => 'yes',
464
- ),
465
- ),
466
- ),
467
-
468
- // Show Content
469
- array(
470
- 'label' => array(
471
- 'text' => __( '', PT_CV_DOMAIN ),
472
- ),
473
- 'extra_setting' => array(
474
- 'params' => array(
475
- 'width' => 12,
476
- ),
477
- ),
478
- 'params' => array(
479
- array(
480
- 'type' => 'checkbox',
481
- 'name' => $prefix . 'content',
482
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Content', PT_CV_DOMAIN ) ),
483
- 'std' => 'yes',
484
- ),
485
- ),
486
- ),
487
-
488
- // Show Meta fields
489
- array(
490
- 'label' => array(
491
- 'text' => __( '', PT_CV_DOMAIN ),
492
- ),
493
- 'extra_setting' => array(
494
- 'params' => array(
495
- 'width' => 12,
496
- ),
497
- ),
498
- 'params' => array(
499
- array(
500
- 'type' => 'checkbox',
501
- 'name' => $prefix . 'meta-fields',
502
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Meta Fields: Author, Date, Comment...', PT_CV_DOMAIN ) ),
503
- 'std' => '',
504
- ),
505
- ),
506
- ),
507
- );
508
-
509
- // Add/remove params
510
- $result = apply_filters( PT_CV_PREFIX_ . 'field_display', $result, $prefix );
511
-
512
- // Sort array of params by saved order
513
- $result = apply_filters( PT_CV_PREFIX_ . 'settings_sort', $result, PT_CV_PREFIX . $prefix );
514
-
515
- return $result;
516
- }
517
-
518
- /**
519
- * Setting options for Field = Thumbnail
520
- */
521
- static function field_thumbnail_settings( $prefix ) {
522
-
523
- $result = array(
524
- // Size
525
- array(
526
- 'label' => array(
527
- 'text' => __( 'Thumbnail size', PT_CV_DOMAIN ),
528
- ),
529
- 'extra_setting' => array(
530
- 'params' => array(
531
- 'width' => 9,
532
- ),
533
- ),
534
- 'params' => array(
535
- array(
536
- 'type' => 'select',
537
- 'name' => $prefix . 'thumbnail-size',
538
- 'options' => PT_CV_Values::field_thumbnail_sizes(),
539
- 'std' => 'medium',
540
- ),
541
- ),
542
- ),
543
- );
544
-
545
- $result = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_settings', $result, $prefix );
546
-
547
- return $result;
548
- }
549
-
550
- /**
551
- * Show settings of other fields
552
- */
553
- static function field_meta_fields( $prefix ) {
554
-
555
- $result = array(
556
-
557
- // Date
558
- array(
559
- 'label' => array(
560
- 'text' => '',
561
- ),
562
- 'extra_setting' => array(
563
- 'params' => array(
564
- 'width' => 12,
565
- ),
566
- ),
567
- 'params' => array(
568
- array(
569
- 'type' => 'checkbox',
570
- 'name' => $prefix . 'date',
571
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Date', PT_CV_DOMAIN ) ),
572
- 'std' => 'yes',
573
- ),
574
- ),
575
- ),
576
-
577
- // Author
578
- array(
579
- 'label' => array(
580
- 'text' => '',
581
- ),
582
- 'extra_setting' => array(
583
- 'params' => array(
584
- 'width' => 12,
585
- ),
586
- ),
587
- 'params' => array(
588
- array(
589
- 'type' => 'checkbox',
590
- 'name' => $prefix . 'author',
591
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Author', PT_CV_DOMAIN ) ),
592
- 'std' => 'yes',
593
- ),
594
- ),
595
- ),
596
-
597
- // Taxonomy
598
- array(
599
- 'label' => array(
600
- 'text' => '',
601
- ),
602
- 'extra_setting' => array(
603
- 'params' => array(
604
- 'width' => 12,
605
- ),
606
- ),
607
- 'params' => array(
608
- array(
609
- 'type' => 'checkbox',
610
- 'name' => $prefix . 'taxonomy',
611
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Taxonomies (categories, tags...)', PT_CV_DOMAIN ) ),
612
- 'std' => 'yes',
613
- ),
614
- ),
615
- 'dependence' => array( 'content-type', 'page', '!=' ),
616
- ),
617
-
618
- // Comment
619
- array(
620
- 'label' => array(
621
- 'text' => '',
622
- ),
623
- 'extra_setting' => array(
624
- 'params' => array(
625
- 'width' => 12,
626
- ),
627
- ),
628
- 'params' => array(
629
- array(
630
- 'type' => 'checkbox',
631
- 'name' => $prefix . 'comment',
632
- 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Comment Count', PT_CV_DOMAIN ) ),
633
- 'std' => 'yes',
634
- ),
635
- ),
636
- ),
637
-
638
- );
639
-
640
- // Sort array of params by saved order
641
- $result = apply_filters( PT_CV_PREFIX_ . 'settings_sort', $result, PT_CV_PREFIX . $prefix );
642
-
643
- return $result;
644
- }
645
-
646
- /**
647
- * Settings of View Type = Grid
648
- *
649
- * @return array
650
- */
651
- static function view_type_settings_grid() {
652
-
653
- $prefix = 'grid-';
654
-
655
- $result = array(
656
- // Number of columns
657
- array(
658
- 'label' => array(
659
- 'text' => __( 'Items per row', PT_CV_DOMAIN ),
660
- ),
661
- 'params' => array(
662
- array(
663
- 'type' => 'number',
664
- 'name' => $prefix . 'number-columns',
665
- 'std' => '2',
666
- 'append_text' => '1 &rarr; 4',
667
- 'desc' => __( 'The number of items on each row of grid', PT_CV_DOMAIN ),
668
- ),
669
- ),
670
- 'dependence' => array( 'view-type', 'grid' ),
671
- ),
672
- );
673
-
674
- $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_grid', $result );
675
-
676
- return $result;
677
- }
678
-
679
- /**
680
- * Settings of View Type = Collapsible
681
- *
682
- * @return array
683
- */
684
- static function view_type_settings_collapsible() {
685
-
686
- $prefix = 'collapsible-';
687
-
688
- $result = array(
689
- PT_CV_Settings::setting_no_option(),
690
- );
691
-
692
- $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_collapsible', $result );
693
-
694
- return $result;
695
- }
696
-
697
- /**
698
- * Settings of View Type = Scrollable
699
- *
700
- * @return array
701
- */
702
- static function view_type_settings_scrollable() {
703
-
704
- $prefix = 'scrollable-';
705
-
706
- $result = array(
707
- PT_CV_Settings::setting_no_option(),
708
- );
709
-
710
- $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_scrollable', $result );
711
-
712
- return $result;
713
- }
714
-
715
- /**
716
- * Setting with no option
717
- *
718
- * @return array
719
- */
720
- static function setting_no_option() {
721
-
722
- return array(
723
- 'label' => array(
724
- 'text' => __( '', PT_CV_DOMAIN ),
725
- ),
726
- 'extra_setting' => array(
727
- 'params' => array(
728
- 'width' => 12,
729
- ),
730
- ),
731
- 'params' => array(
732
- array(
733
- 'type' => 'html',
734
- 'content' => "<div class='" . PT_CV_PREFIX . "text'>" . __( 'There is no option', PT_CV_DOMAIN ) . '</div>',
735
- ),
736
- ),
737
- );
738
- }
739
- }
740
-
741
  }
1
+ <?php
2
+ /**
3
+ * Define settings for options
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ if ( ! class_exists( 'PT_CV_Settings' ) ) {
13
+
14
+ /**
15
+ * @name PT_CV_Settings
16
+ * @todo Define settings for options
17
+ */
18
+ class PT_CV_Settings {
19
+
20
+ /**
21
+ * Get collection : Taxonomies => Terms
22
+ *
23
+ * @param string $taxonomies Array of taxonomies
24
+ * @param array $args Array of query parameters
25
+ */
26
+ static function terms_of_taxonomies( $taxonomies = array(), $args = array() ) {
27
+ $terms_of_taxonomies = $result = array();
28
+ // Get taxonomies
29
+ $taxonomies = PT_CV_Values::taxonomy_list();
30
+ // Get slug list of taxonomies
31
+ $taxonomies_slug = array_keys( $taxonomies );
32
+
33
+ foreach ( $taxonomies_slug as $taxonomy_slug ) {
34
+ PT_CV_Values::term_of_taxonomy( $taxonomy_slug, $terms_of_taxonomies, $args );
35
+ }
36
+
37
+ foreach ( $terms_of_taxonomies as $taxonomy_slug => $terms ) {
38
+
39
+ $result[$taxonomy_slug] = array(
40
+
41
+ // Select term to filter
42
+ array(
43
+ 'label' => array(
44
+ 'text' => __( 'Select terms', PT_CV_DOMAIN ),
45
+ ),
46
+ 'params' => array(
47
+ array(
48
+ 'type' => 'select',
49
+ 'name' => $taxonomy_slug . '-terms[]',
50
+ 'options' => $terms,
51
+ 'std' => '',
52
+ 'class' => 'select2',
53
+ 'multiple' => '1',
54
+ ),
55
+ ),
56
+ ),
57
+
58
+ // Quick filter
59
+ apply_filters( PT_CV_PREFIX_ . 'term_quick_filter', array() ),
60
+
61
+ //Operator
62
+ array(
63
+ 'label' => array(
64
+ 'text' => __( 'Operator', PT_CV_DOMAIN ),
65
+ ),
66
+ 'params' => array(
67
+ array(
68
+ 'type' => 'radio',
69
+ 'name' => $taxonomy_slug . '-operator',
70
+ 'options' => PT_CV_Values::taxonomy_operators(),
71
+ 'std' => 'IN',
72
+ ),
73
+ ),
74
+ ),
75
+ );
76
+ }
77
+
78
+ return $result;
79
+ }
80
+
81
+ /**
82
+ * Order by options
83
+ *
84
+ * @return array
85
+ */
86
+ static function orderby() {
87
+ $result = array();
88
+
89
+ $result['common'] = array(
90
+ // Order By
91
+ array(
92
+ 'label' => array(
93
+ 'text' => __( 'Order by', PT_CV_DOMAIN ),
94
+ ),
95
+ 'params' => array(
96
+ array(
97
+ 'type' => 'select',
98
+ 'name' => 'orderby',
99
+ 'options' => PT_CV_Values::post_regular_orderby(),
100
+ 'std' => '',
101
+ ),
102
+ ),
103
+ ),
104
+ // Order
105
+ array(
106
+ 'label' => array(
107
+ 'text' => __( 'Order', PT_CV_DOMAIN ),
108
+ ),
109
+ 'params' => array(
110
+ array(
111
+ 'type' => 'radio',
112
+ 'name' => 'order',
113
+ 'options' => PT_CV_Values::orders(),
114
+ 'std' => 'asc',
115
+ ),
116
+ ),
117
+ ),
118
+ );
119
+
120
+ $result = apply_filters( PT_CV_PREFIX_ . 'orderby', $result );
121
+
122
+ return $result;
123
+ }
124
+
125
+ /**
126
+ * Pagination settings
127
+ *
128
+ * @return array
129
+ */
130
+ static function settings_pagination() {
131
+
132
+ $prefix = 'pagination-';
133
+
134
+ $result = array(
135
+
136
+ // Pagination
137
+ array(
138
+ 'label' => array(
139
+ 'text' => __( 'Pagination', PT_CV_DOMAIN ),
140
+ ),
141
+ 'params' => array(
142
+ array(
143
+ 'type' => 'checkbox',
144
+ 'name' => 'enable-pagination',
145
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Enable', PT_CV_DOMAIN ) ),
146
+ 'std' => '',
147
+ ),
148
+ ),
149
+ ),
150
+
151
+ // Items per page
152
+ array(
153
+ 'label' => array(
154
+ 'text' => __( 'Items per page', PT_CV_DOMAIN ),
155
+ ),
156
+ 'params' => array(
157
+ array(
158
+ 'type' => 'number',
159
+ 'name' => $prefix . 'items-per-page',
160
+ 'std' => '5',
161
+ 'placeholder' => 'e.g. 5',
162
+ 'append_text' => '1 &rarr; 100',
163
+ 'desc' => __( 'The number of items per page.<br>If value of Limit option is not blank (empty), this value should be smaller than Limit value', PT_CV_DOMAIN ),
164
+ ),
165
+ ),
166
+ 'dependence' => array( 'enable-pagination', 'yes' ),
167
+ ),
168
+
169
+ // Pagination Style
170
+ array(
171
+ 'label' => array(
172
+ 'text' => __( 'Pagination style', PT_CV_DOMAIN ),
173
+ ),
174
+ 'params' => array(
175
+ array(
176
+ 'type' => 'radio',
177
+ 'name' => $prefix . 'style',
178
+ 'options' => PT_CV_Values::pagination_styles(),
179
+ 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::pagination_styles() ),
180
+ ),
181
+ ),
182
+ 'dependence' => array( 'enable-pagination', 'yes' ),
183
+ ),
184
+ );
185
+
186
+ $result = apply_filters( PT_CV_PREFIX_ . 'settings_pagination', $result, $prefix );
187
+
188
+ return $result;
189
+ }
190
+
191
+ /**
192
+ * Other settings for All View Type
193
+ */
194
+ static function settings_other() {
195
+
196
+ $prefix = 'other-';
197
+
198
+ $result = array(
199
+ // Open an item in
200
+ array(
201
+ 'label' => array(
202
+ 'text' => __( 'Open item in', PT_CV_DOMAIN ),
203
+ ),
204
+ 'params' => array(
205
+ array(
206
+ 'type' => 'radio',
207
+ 'name' => $prefix . 'open-in',
208
+ 'options' => PT_CV_Values::open_in(),
209
+ 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::open_in() ),
210
+ 'desc' => __( 'How to open an item when click on Title or Thumbnail', PT_CV_DOMAIN ),
211
+ ),
212
+ ),
213
+ ),
214
+ );
215
+
216
+ $result = apply_filters( PT_CV_PREFIX_ . 'settings_other', $result, $prefix );
217
+
218
+ return $result;
219
+ }
220
+
221
+ /**
222
+ * Fields settings
223
+ */
224
+ static function field_settings() {
225
+
226
+ $prefix = 'field-';
227
+ $prefix2 = 'show-' . $prefix;
228
+
229
+ $result = array(
230
+
231
+ // Fields display
232
+ array(
233
+ 'label' => array(
234
+ 'text' => __( 'Fields display', PT_CV_DOMAIN ),
235
+ ),
236
+ 'extra_setting' => array(
237
+ 'params' => array(
238
+ 'wrap-class' => PT_CV_Html::html_group_class(),
239
+ ),
240
+ ),
241
+ 'params' => array(
242
+ array(
243
+ 'type' => 'group',
244
+ 'params' => PT_CV_Settings::field_display_settings(),
245
+ ),
246
+ ),
247
+ ),
248
+
249
+ // Thumbnail settings
250
+ array(
251
+ 'label' => array(
252
+ 'text' => __( 'Thumbnail settings', PT_CV_DOMAIN ),
253
+ ),
254
+ 'extra_setting' => array(
255
+ 'params' => array(
256
+ 'wrap-class' => PT_CV_Html::html_group_class() . ' ' . PT_CV_PREFIX . 'thumbnail-setting',
257
+ ),
258
+ ),
259
+ 'params' => array(
260
+ array(
261
+ 'type' => 'group',
262
+ 'params' => PT_CV_Settings::field_thumbnail_settings( $prefix ),
263
+ ),
264
+ ),
265
+ 'dependence' => array( $prefix2 . 'thumbnail', 'yes' ),
266
+ ),
267
+
268
+ // Meta fields settings
269
+ array(
270
+ 'label' => array(
271
+ 'text' => __( 'Meta fields settings', PT_CV_DOMAIN ),
272
+ ),
273
+ 'extra_setting' => array(
274
+ 'params' => array(
275
+ 'wrap-class' => PT_CV_Html::html_group_class() . ' ' . PT_CV_PREFIX . 'meta-fields-settings',
276
+ ),
277
+ ),
278
+ 'params' => array(
279
+ array(
280
+ 'type' => 'group',
281
+ 'params' => PT_CV_Settings::field_meta_fields( 'meta-fields-' ),
282
+ 'desc' => apply_filters( PT_CV_PREFIX_ . 'settings_sort_text', '' ),
283
+ ),
284
+ ),
285
+ 'dependence' => array( $prefix2 . 'meta-fields', 'yes' ),
286
+ ),
287
+
288
+ // Taxonomies settings
289
+ apply_filters( PT_CV_PREFIX_ . 'settings_taxonomies_display', array() ),
290
+
291
+ // Content settings
292
+ array(
293
+ 'label' => array(
294
+ 'text' => __( 'Content settings', PT_CV_DOMAIN ),
295
+ ),
296
+ 'params' => array(
297
+ array(
298
+ 'type' => 'radio',
299
+ 'name' => $prefix . 'content-show',
300
+ 'options' => array(
301
+ 'full' => __( 'Show Full Content', PT_CV_DOMAIN ),
302
+ 'excerpt' => __( 'Show Excerpt', PT_CV_DOMAIN ),
303
+ ),
304
+ 'std' => 'excerpt',
305
+ ),
306
+ ),
307
+ 'dependence' => array( $prefix2 . 'content', 'yes' ),
308
+ ),
309
+
310
+ // Excerpt settings
311
+ array(
312
+ 'label' => array(
313
+ 'text' => __( '', PT_CV_DOMAIN ),
314
+ ),
315
+ 'extra_setting' => array(
316
+ 'params' => array(
317
+ 'wrap-id' => PT_CV_Html::html_group_id( 'excerpt-settings' ),
318
+ ),
319
+ ),
320
+ 'params' => array(
321
+ array(
322
+ 'type' => 'group',
323
+ 'params' => apply_filters(
324
+ PT_CV_PREFIX_ . 'excerpt_settings',
325
+ array(
326
+ // Excerpt length
327
+ array(
328
+ 'label' => array(
329
+ 'text' => __( 'Excerpt length', PT_CV_DOMAIN ),
330
+ ),
331
+ 'extra_setting' => array(
332
+ 'params' => array(
333
+ 'width' => 9,
334
+ ),
335
+ ),
336
+ 'params' => array(
337
+ array(
338
+ 'type' => 'number',
339
+ 'name' => $prefix . 'excerpt-length',
340
+ 'std' => '20',
341
+ 'placeholder' => 'e.g. 20',
342
+ 'append_text' => '1 &rarr; 100',
343
+ 'desc' => __( 'Generating excerpt by selecting the first X words of the content', PT_CV_DOMAIN ),
344
+ ),
345
+ ),
346
+ ),
347
+ ),
348
+ $prefix . 'excerpt-'
349
+ ),
350
+ ),
351
+ ),
352
+ 'dependence' => array( array( $prefix . 'content-show', 'excerpt' ) ),
353
+ ),
354
+ );
355
+
356
+ $result = apply_filters( PT_CV_PREFIX_ . 'field_settings', $result, $prefix2 );
357
+
358
+ return $result;
359
+ }
360
+
361
+ /**
362
+ * Fields display
363
+ *
364
+ * @return array
365
+ */
366
+ static function field_display_settings() {
367
+
368
+ $field_display_settings = array(
369
+ array(
370
+ 'label' => array(
371
+ 'text' => __( '', PT_CV_DOMAIN ),
372
+ ),
373
+ 'extra_setting' => array(
374
+ 'params' => array(
375
+ 'width' => 12,
376
+ 'wrap-class' => PT_CV_PREFIX . 'field-display',
377
+ ),
378
+ ),
379
+ 'params' => array(
380
+ array(
381
+ 'type' => 'group',
382
+ 'params' => PT_CV_Settings::field_display(),
383
+ 'desc' => apply_filters( PT_CV_PREFIX_ . 'settings_sort_text', '' ),
384
+ ),
385
+ ),
386
+ ),
387
+ );
388
+
389
+ $result = apply_filters( PT_CV_PREFIX_ . 'field_display_settings', $field_display_settings );
390
+
391
+ return $result;
392
+ }
393
+
394
+ /**
395
+ * Options to check/uncheck to display fields
396
+ *
397
+ * @return array
398
+ */
399
+ static function field_display() {
400
+
401
+ $prefix = 'show-field-';
402
+
403
+ $result = array(
404
+
405
+ // Thumbnail position
406
+ array(
407
+ 'label' => array(
408
+ 'text' => __( 'Thumbnail position', PT_CV_DOMAIN ),
409
+ ),
410
+ 'extra_setting' => array(
411
+ 'params' => array(
412
+ 'width' => 9,
413
+ 'wrap-class' => PT_CV_PREFIX . 'bg-none',
414
+ ),
415
+ ),
416
+ 'params' => array(
417
+ array(
418
+ 'type' => 'select',
419
+ 'name' => 'field-' . 'thumbnail-position',
420
+ 'options' => PT_CV_Values::thumbnail_position(),
421
+ 'std' => PT_CV_Functions::array_get_first_key( PT_CV_Values::thumbnail_position() ),
422
+ ),
423
+ ),
424
+ 'dependence' => array( 'layout-format', '2-col' ),
425
+ ),
426
+
427
+ // Show Thumbnail
428
+ array(
429
+ 'label' => array(
430
+ 'text' => __( '', PT_CV_DOMAIN ),
431
+ ),
432
+ 'extra_setting' => array(
433
+ 'params' => array(
434
+ 'width' => 12,
435
+ ),
436
+ ),
437
+ 'params' => array(
438
+ array(
439
+ 'type' => 'checkbox',
440
+ 'name' => $prefix . 'thumbnail',
441
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Thumbnail', PT_CV_DOMAIN ) ),
442
+ 'std' => 'yes',
443
+ ),
444
+ ),
445
+ 'dependence' => array( 'layout-format', '1-col' ),
446
+ ),
447
+
448
+ // Show Title
449
+ array(
450
+ 'label' => array(
451
+ 'text' => __( '', PT_CV_DOMAIN ),
452
+ ),
453
+ 'extra_setting' => array(
454
+ 'params' => array(
455
+ 'width' => 12,
456
+ ),
457
+ ),
458
+ 'params' => array(
459
+ array(
460
+ 'type' => 'checkbox',
461
+ 'name' => $prefix . 'title',
462
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Title', PT_CV_DOMAIN ) ),
463
+ 'std' => 'yes',
464
+ ),
465
+ ),
466
+ ),
467
+
468
+ // Show Content
469
+ array(
470
+ 'label' => array(
471
+ 'text' => __( '', PT_CV_DOMAIN ),
472
+ ),
473
+ 'extra_setting' => array(
474
+ 'params' => array(
475
+ 'width' => 12,
476
+ ),
477
+ ),
478
+ 'params' => array(
479
+ array(
480
+ 'type' => 'checkbox',
481
+ 'name' => $prefix . 'content',
482
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Content', PT_CV_DOMAIN ) ),
483
+ 'std' => 'yes',
484
+ ),
485
+ ),
486
+ ),
487
+
488
+ // Show Meta fields
489
+ array(
490
+ 'label' => array(
491
+ 'text' => __( '', PT_CV_DOMAIN ),
492
+ ),
493
+ 'extra_setting' => array(
494
+ 'params' => array(
495
+ 'width' => 12,
496
+ ),
497
+ ),
498
+ 'params' => array(
499
+ array(
500
+ 'type' => 'checkbox',
501
+ 'name' => $prefix . 'meta-fields',
502
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Meta Fields: Author, Date, Comment...', PT_CV_DOMAIN ) ),
503
+ 'std' => '',
504
+ ),
505
+ ),
506
+ ),
507
+ );
508
+
509
+ // Add/remove params
510
+ $result = apply_filters( PT_CV_PREFIX_ . 'field_display', $result, $prefix );
511
+
512
+ // Sort array of params by saved order
513
+ $result = apply_filters( PT_CV_PREFIX_ . 'settings_sort', $result, PT_CV_PREFIX . $prefix );
514
+
515
+ return $result;
516
+ }
517
+
518
+ /**
519
+ * Setting options for Field = Thumbnail
520
+ */
521
+ static function field_thumbnail_settings( $prefix ) {
522
+
523
+ $result = array(
524
+ // Size
525
+ array(
526
+ 'label' => array(
527
+ 'text' => __( 'Thumbnail size', PT_CV_DOMAIN ),
528
+ ),
529
+ 'extra_setting' => array(
530
+ 'params' => array(
531
+ 'width' => 9,
532
+ ),
533
+ ),
534
+ 'params' => array(
535
+ array(
536
+ 'type' => 'select',
537
+ 'name' => $prefix . 'thumbnail-size',
538
+ 'options' => PT_CV_Values::field_thumbnail_sizes(),
539
+ 'std' => 'medium',
540
+ ),
541
+ ),
542
+ ),
543
+ );
544
+
545
+ $result = apply_filters( PT_CV_PREFIX_ . 'field_thumbnail_settings', $result, $prefix );
546
+
547
+ return $result;
548
+ }
549
+
550
+ /**
551
+ * Show settings of other fields
552
+ */
553
+ static function field_meta_fields( $prefix ) {
554
+
555
+ $result = array(
556
+
557
+ // Date
558
+ array(
559
+ 'label' => array(
560
+ 'text' => '',
561
+ ),
562
+ 'extra_setting' => array(
563
+ 'params' => array(
564
+ 'width' => 12,
565
+ ),
566
+ ),
567
+ 'params' => array(
568
+ array(
569
+ 'type' => 'checkbox',
570
+ 'name' => $prefix . 'date',
571
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Date', PT_CV_DOMAIN ) ),
572
+ 'std' => 'yes',
573
+ ),
574
+ ),
575
+ ),
576
+
577
+ // Author
578
+ array(
579
+ 'label' => array(
580
+ 'text' => '',
581
+ ),
582
+ 'extra_setting' => array(
583
+ 'params' => array(
584
+ 'width' => 12,
585
+ ),
586
+ ),
587
+ 'params' => array(
588
+ array(
589
+ 'type' => 'checkbox',
590
+ 'name' => $prefix . 'author',
591
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Author', PT_CV_DOMAIN ) ),
592
+ 'std' => 'yes',
593
+ ),
594
+ ),
595
+ ),
596
+
597
+ // Taxonomy
598
+ array(
599
+ 'label' => array(
600
+ 'text' => '',
601
+ ),
602
+ 'extra_setting' => array(
603
+ 'params' => array(
604
+ 'width' => 12,
605
+ ),
606
+ ),
607
+ 'params' => array(
608
+ array(
609
+ 'type' => 'checkbox',
610
+ 'name' => $prefix . 'taxonomy',
611
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Taxonomies (categories, tags...)', PT_CV_DOMAIN ) ),
612
+ 'std' => 'yes',
613
+ ),
614
+ ),
615
+ 'dependence' => array( 'content-type', 'page', '!=' ),
616
+ ),
617
+
618
+ // Comment
619
+ array(
620
+ 'label' => array(
621
+ 'text' => '',
622
+ ),
623
+ 'extra_setting' => array(
624
+ 'params' => array(
625
+ 'width' => 12,
626
+ ),
627
+ ),
628
+ 'params' => array(
629
+ array(
630
+ 'type' => 'checkbox',
631
+ 'name' => $prefix . 'comment',
632
+ 'options' => PT_CV_Values::yes_no( 'yes', __( 'Show Comment Count', PT_CV_DOMAIN ) ),
633
+ 'std' => 'yes',
634
+ ),
635
+ ),
636
+ ),
637
+
638
+ );
639
+
640
+ // Sort array of params by saved order
641
+ $result = apply_filters( PT_CV_PREFIX_ . 'settings_sort', $result, PT_CV_PREFIX . $prefix );
642
+
643
+ return $result;
644
+ }
645
+
646
+ /**
647
+ * Settings of View Type = Grid
648
+ *
649
+ * @return array
650
+ */
651
+ static function view_type_settings_grid() {
652
+
653
+ $prefix = 'grid-';
654
+
655
+ $result = array(
656
+ // Number of columns
657
+ array(
658
+ 'label' => array(
659
+ 'text' => __( 'Items per row', PT_CV_DOMAIN ),
660
+ ),
661
+ 'params' => array(
662
+ array(
663
+ 'type' => 'number',
664
+ 'name' => $prefix . 'number-columns',
665
+ 'std' => '2',
666
+ 'append_text' => '1 &rarr; 4',
667
+ 'desc' => __( 'The number of items on each row of grid', PT_CV_DOMAIN ),
668
+ ),
669
+ ),
670
+ 'dependence' => array( 'view-type', 'grid' ),
671
+ ),
672
+ );
673
+
674
+ $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_grid', $result );
675
+
676
+ return $result;
677
+ }
678
+
679
+ /**
680
+ * Settings of View Type = Collapsible
681
+ *
682
+ * @return array
683
+ */
684
+ static function view_type_settings_collapsible() {
685
+
686
+ $prefix = 'collapsible-';
687
+
688
+ $result = array(
689
+ PT_CV_Settings::setting_no_option(),
690
+ );
691
+
692
+ $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_collapsible', $result );
693
+
694
+ return $result;
695
+ }
696
+
697
+ /**
698
+ * Settings of View Type = Scrollable
699
+ *
700
+ * @return array
701
+ */
702
+ static function view_type_settings_scrollable() {
703
+
704
+ $prefix = 'scrollable-';
705
+
706
+ $result = array(
707
+ PT_CV_Settings::setting_no_option(),
708
+ );
709
+
710
+ $result = apply_filters( PT_CV_PREFIX_ . 'view_type_settings_scrollable', $result );
711
+
712
+ return $result;
713
+ }
714
+
715
+ /**
716
+ * Setting with no option
717
+ *
718
+ * @return array
719
+ */
720
+ static function setting_no_option() {
721
+
722
+ return array(
723
+ 'label' => array(
724
+ 'text' => __( '', PT_CV_DOMAIN ),
725
+ ),
726
+ 'extra_setting' => array(
727
+ 'params' => array(
728
+ 'width' => 12,
729
+ ),
730
+ ),
731
+ 'params' => array(
732
+ array(
733
+ 'type' => 'html',
734
+ 'content' => "<div class='" . PT_CV_PREFIX . "text'>" . __( 'There is no option', PT_CV_DOMAIN ) . '</div>',
735
+ ),
736
+ ),
737
+ );
738
+ }
739
+ }
740
+
741
  }
includes/update.php CHANGED
@@ -1,19 +1,19 @@
1
- <?php
2
- /**
3
- * Check update, do update
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- // Compare stored version and current version
13
- $stored_version = get_option( PT_CV_OPTION_VERSION );
14
- if ( $stored_version && version_compare( $stored_version, PT_CV_VERSION, '<' ) ) {
15
- // Do update
16
-
17
- // Update version
18
- update_option( PT_CV_OPTION_VERSION, PT_CV_VERSION );
19
  }
1
+ <?php
2
+ /**
3
+ * Check update, do update
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ // Compare stored version and current version
13
+ $stored_version = get_option( PT_CV_OPTION_VERSION );
14
+ if ( $stored_version && version_compare( $stored_version, PT_CV_VERSION, '<' ) ) {
15
+ // Do update
16
+
17
+ // Update version
18
+ update_option( PT_CV_OPTION_VERSION, PT_CV_VERSION );
19
  }
includes/values.php CHANGED
@@ -245,12 +245,15 @@ if ( ! class_exists( 'PT_CV_Values' ) ) {
245
  * @return array
246
  */
247
  static function advanced_settings() {
248
- return array(
249
- 'taxonomy' => __( 'Taxonomy (Categories, Tags...)', PT_CV_DOMAIN ),
250
- 'status' => __( 'Status', PT_CV_DOMAIN ),
251
- 'order' => __( 'Order & Orderby', PT_CV_DOMAIN ),
252
- 'search' => __( 'Search', PT_CV_DOMAIN ),
253
- 'author' => __( 'Author', PT_CV_DOMAIN ),
 
 
 
254
  );
255
  }
256
 
245
  * @return array
246
  */
247
  static function advanced_settings() {
248
+ return apply_filters(
249
+ PT_CV_PREFIX_ . 'advanced_settings',
250
+ array(
251
+ 'taxonomy' => __( 'Taxonomy (Categories, Tags...)', PT_CV_DOMAIN ),
252
+ 'status' => __( 'Status', PT_CV_DOMAIN ),
253
+ 'order' => __( 'Order & Orderby', PT_CV_DOMAIN ),
254
+ 'search' => __( 'Search', PT_CV_DOMAIN ),
255
+ 'author' => __( 'Author', PT_CV_DOMAIN ),
256
+ )
257
  );
258
  }
259
 
public/assets/css/public.css CHANGED
@@ -1,231 +1,231 @@
1
- /**
2
- * Common styles for Front-end
3
- *
4
- * @package PT_Content_Views
5
- * @author PT Guy <palaceofthemes@gmail.com>
6
- * @license GPL-2.0+
7
- * @link http://www.contentviewspro.com/
8
- * @copyright 2014 PT Guy
9
- */
10
-
11
- /* Fix Bootstrap box-sizing "border-box" problem */
12
- .pt-cv-row *,
13
- .pt-cv-row *:before,
14
- .pt-cv-row *:after,
15
- .pt-cv-view *,
16
- .pt-cv-view *:before,
17
- .pt-cv-view *:after {
18
- -webkit-box-sizing: border-box;
19
- -moz-box-sizing: border-box;
20
- box-sizing: border-box;
21
- }
22
-
23
- /* Common */
24
- .pt-cv-view {
25
- position: relative;
26
- margin-bottom: 30px;
27
- clear: both;
28
- }
29
-
30
- .pt-cv-page {
31
- position: relative;
32
- }
33
-
34
- .pt-cv-row {
35
- clear: left;
36
- }
37
-
38
- /* Link */
39
- .pt-cv-view a {
40
- /*color: #000;*/
41
- text-decoration: none !important;
42
- }
43
-
44
- .pt-cv-view a:hover, .pt-cv-view .panel-heading:hover a {
45
- /*color: #ff3c1f;*/
46
- }
47
-
48
- /* Read more */
49
- .pt-cv-readmore {
50
- color: #fff;
51
- margin: 10px 0;
52
- }
53
-
54
- /* An Item */
55
- .pt-cv-content-item {
56
- padding-bottom: 1.875em;
57
- position: relative;
58
- overflow: hidden;
59
- }
60
-
61
- /* For the output which shows only Title */
62
- .pt-cv-only-title {
63
- padding-bottom: 0;
64
- }
65
-
66
- /* Title */
67
- .pt-cv-title {
68
- margin-top: 0;
69
- font-size: 20px;
70
- }
71
-
72
- .pt-cv-title a {
73
- font-weight: 600;
74
- }
75
-
76
- /* Thumbnail */
77
- .pt-cv-thumbnail {
78
- max-width: 100% !important;
79
- margin-bottom: 15px;
80
- }
81
-
82
- .pt-cv-thumbnail.pull-left {
83
- margin-right: 10px;
84
- }
85
-
86
- .pt-cv-thumbnail.pull-right {
87
- margin-left: 10px;
88
- }
89
-
90
- .pt-cv-no-image {
91
- min-width: 80px;
92
- min-height: 80px;
93
- }
94
-
95
- /* Content */
96
- .pt-cv-content, .pt-cv-content * {
97
- font-size: 14px;
98
- zoom: 1;
99
- line-height: 1.6em;
100
- }
101
-
102
- /* Meta fields */
103
- .pt-cv-meta-fields {
104
- font-size: 13px;
105
- margin-top: 15px;
106
- padding-bottom: 15px;
107
- }
108
-
109
- .pt-cv-meta-fields a {
110
- color: #41b7d8;
111
- }
112
-
113
- /* Pagination */
114
- .pt-cv-view + .pagination {
115
- float: left;
116
- margin: 0 auto !important;
117
- }
118
-
119
- .pagination > li > a {
120
- cursor: pointer;
121
- }
122
-
123
- .pt-cv-spinner {
124
- display: inline-block;
125
- opacity: 0;
126
- filter: alpha(opacity=0);
127
- color: #0470ec;
128
-
129
- margin-top: 12px;
130
- margin-left: 10px;
131
-
132
- -webkit-transition: opacity 0.25s, width 0.25s;
133
- -moz-transition: opacity 0.25s, width 0.25s;
134
- -o-transition: opacity 0.25s, width 0.25s;
135
- transition: opacity 0.25s, width 0.25s;
136
- }
137
-
138
- .pt-cv-spinner.active {
139
- opacity: 1;
140
- filter: alpha(opacity=100);
141
- }
142
-
143
- .pt-cv-clear-pagination {
144
- margin-bottom: 50px;
145
- }
146
-
147
- /* View type : Collapsible List */
148
- .pt-cv-collapsible .panel-heading {
149
- padding: 0;
150
- }
151
-
152
- .pt-cv-collapsible .panel-heading a {
153
- display: block;
154
- padding: 10px 15px;
155
- }
156
-
157
- /* View type : Scrollable List */
158
-
159
- /* Caption */
160
- .pt-cv-view .carousel-caption {
161
- text-align: left;
162
- left: 0;
163
- right: 15px;
164
- bottom: 14px;
165
- }
166
-
167
- .pt-cv-view .carousel-caption * {
168
- text-shadow: none;
169
- }
170
-
171
- /* Caption with image */
172
- .pt-cv-cap-w-img {
173
- background: rgba(0, 0, 0, 0.6);
174
- text-shadow: 0px 1px 1px #000;
175
- left: 15px !important;
176
- padding-left: 10px;
177
- padding-bottom: 0;
178
- padding-top: 10px;
179
- }
180
-
181
- .pt-cv-cap-w-img * {
182
- color: #fff;
183
- }
184
-
185
- .pt-cv-cap-w-img .pt-cv-title a {
186
- color: #fff !important;
187
- }
188
-
189
- /* Caption without image */
190
- .pt-cv-cap-wo-img {
191
- position: relative;
192
- }
193
-
194
- .pt-cv-cap-wo-img * {
195
- color: #000;
196
- }
197
-
198
- .pt-cv-cap-wo-img .pt-cv-readmore {
199
- color: #fff;
200
- }
201
-
202
- /* Control */
203
- .pt-cv-view .carousel-control {
204
- background-image: none !important;
205
- z-index: 1000;
206
- height: 30px;
207
- width: 40px;
208
- bottom: 0;
209
- top: auto;
210
- }
211
-
212
- /* Indicator */
213
- .pt-cv-view .carousel-indicators {
214
- bottom: 0;
215
- margin-bottom: 4px;
216
- }
217
-
218
- .pt-cv-view .carousel-indicators li {
219
- background: #cecece;
220
- border: 1px solid #cecece;
221
- }
222
-
223
- .pt-cv-view .carousel-indicators li.active {
224
- background: #428bca;
225
- border: 1px solid #428bca;
226
- }
227
-
228
- /* Layout */
229
- .pt-cv-2-col .pt-cv-title {
230
- clear: none !important;
231
  }
1
+ /**
2
+ * Common styles for Front-end
3
+ *
4
+ * @package PT_Content_Views
5
+ * @author PT Guy <palaceofthemes@gmail.com>
6
+ * @license GPL-2.0+
7
+ * @link http://www.contentviewspro.com/
8
+ * @copyright 2014 PT Guy
9
+ */
10
+
11
+ /* Fix Bootstrap box-sizing "border-box" problem */
12
+ .pt-cv-row *,
13
+ .pt-cv-row *:before,
14
+ .pt-cv-row *:after,
15
+ .pt-cv-view *,
16
+ .pt-cv-view *:before,
17
+ .pt-cv-view *:after {
18
+ -webkit-box-sizing: border-box;
19
+ -moz-box-sizing: border-box;
20
+ box-sizing: border-box;
21
+ }
22
+
23
+ /* Common */
24
+ .pt-cv-view {
25
+ position: relative;
26
+ margin-bottom: 30px;
27
+ clear: both;
28
+ }
29
+
30
+ .pt-cv-page {
31
+ position: relative;
32
+ }
33
+
34
+ .pt-cv-row {
35
+ clear: left;
36
+ }
37
+
38
+ /* Link */
39
+ .pt-cv-view a {
40
+ /*color: #000;*/
41
+ text-decoration: none !important;
42
+ }
43
+
44
+ .pt-cv-view a:hover, .pt-cv-view .panel-heading:hover a {
45
+ /*color: #ff3c1f;*/
46
+ }
47
+
48
+ /* Read more */
49
+ .pt-cv-readmore {
50
+ color: #fff;
51
+ margin: 10px 0;
52
+ }
53
+
54
+ /* An Item */
55
+ .pt-cv-content-item {
56
+ padding-bottom: 1.875em;
57
+ position: relative;
58
+ overflow: hidden;
59
+ }
60
+
61
+ /* For the output which shows only Title */
62
+ .pt-cv-only-title {
63
+ padding-bottom: 0;
64
+ }
65
+
66
+ /* Title */
67
+ .pt-cv-title {
68
+ margin-top: 0;
69
+ font-size: 20px;
70
+ }
71
+
72
+ .pt-cv-title a {
73
+ font-weight: 600;
74
+ }
75
+
76
+ /* Thumbnail */
77
+ .pt-cv-thumbnail {
78
+ max-width: 100% !important;
79
+ margin-bottom: 15px;
80
+ }
81
+
82
+ .pt-cv-thumbnail.pull-left {
83
+ margin-right: 10px;
84
+ }
85
+
86
+ .pt-cv-thumbnail.pull-right {
87
+ margin-left: 10px;
88
+ }
89
+
90
+ .pt-cv-no-image {
91
+ min-width: 80px;
92
+ min-height: 80px;
93
+ }
94
+
95
+ /* Content */
96
+ .pt-cv-content, .pt-cv-content * {
97
+ font-size: 14px;
98
+ zoom: 1;
99
+ line-height: 1.6em;
100
+ }
101
+
102
+ /* Meta fields */
103
+ .pt-cv-meta-fields {
104
+ font-size: 13px;
105
+ margin-top: 15px;
106
+ padding-bottom: 15px;
107
+ }
108
+
109
+ .pt-cv-meta-fields a {
110
+ color: #41b7d8;
111
+ }
112
+
113
+ /* Pagination */
114
+ .pt-cv-view + .pagination {
115
+ float: left;
116
+ margin: 0 auto !important;
117
+ }
118
+
119
+ .pagination > li > a {
120
+ cursor: pointer;
121
+ }
122
+
123
+ .pt-cv-spinner {
124
+ display: inline-block;
125
+ opacity: 0;
126
+ filter: alpha(opacity=0);
127
+ color: #0470ec;
128
+
129
+ margin-top: 12px;
130
+ margin-left: 10px;
131
+
132
+ -webkit-transition: opacity 0.25s, width 0.25s;
133
+ -moz-transition: opacity 0.25s, width 0.25s;
134
+ -o-transition: opacity 0.25s, width 0.25s;
135
+ transition: opacity 0.25s, width 0.25s;
136
+ }
137
+
138
+ .pt-cv-spinner.active {
139
+ opacity: 1;
140
+ filter: alpha(opacity=100);
141
+ }
142
+
143
+ .pt-cv-clear-pagination {
144
+ margin-bottom: 50px;
145
+ }
146
+
147
+ /* View type : Collapsible List */
148
+ .pt-cv-collapsible .panel-heading {
149
+ padding: 0;
150
+ }
151
+
152
+ .pt-cv-collapsible .panel-heading a {
153
+ display: block;
154
+ padding: 10px 15px;
155
+ }
156
+
157
+ /* View type : Scrollable List */
158
+
159
+ /* Caption */
160
+ .pt-cv-view .carousel-caption {
161
+ text-align: left;
162
+ left: 0;
163
+ right: 15px;
164
+ bottom: 14px;
165
+ }
166
+
167
+ .pt-cv-view .carousel-caption * {
168
+ text-shadow: none;
169
+ }
170
+
171
+ /* Caption with image */
172
+ .pt-cv-cap-w-img {
173
+ background: rgba(0, 0, 0, 0.6);
174
+ text-shadow: 0px 1px 1px #000;
175
+ left: 15px !important;
176
+ padding-left: 10px;
177
+ padding-bottom: 0;
178
+ padding-top: 10px;
179
+ }
180
+
181
+ .pt-cv-cap-w-img * {
182
+ color: #fff;
183
+ }
184
+
185
+ .pt-cv-cap-w-img .pt-cv-title a {
186
+ color: #fff !important;
187
+ }
188
+
189
+ /* Caption without image */
190
+ .pt-cv-cap-wo-img {
191
+ position: relative;
192
+ }
193
+
194
+ .pt-cv-cap-wo-img * {
195
+ color: #000;
196
+ }
197
+
198
+ .pt-cv-cap-wo-img .pt-cv-readmore {
199
+ color: #fff;
200
+ }
201
+
202
+ /* Control */
203
+ .pt-cv-view .carousel-control {
204
+ background-image: none !important;
205
+ z-index: 1000;
206
+ height: 30px;
207
+ width: 40px;
208
+ bottom: 0;
209
+ top: auto;
210
+ }
211
+
212
+ /* Indicator */
213
+ .pt-cv-view .carousel-indicators {
214
+ bottom: 0;
215
+ margin-bottom: 4px;
216
+ }
217
+
218
+ .pt-cv-view .carousel-indicators li {
219
+ background: #cecece;
220
+ border: 1px solid #cecece;
221
+ }
222
+
223
+ .pt-cv-view .carousel-indicators li.active {
224
+ background: #428bca;
225
+ border: 1px solid #428bca;
226
+ }
227
+
228
+ /* Layout */
229
+ .pt-cv-2-col .pt-cv-title {
230
+ clear: none !important;
231
  }
public/templates/_view_type_/html/main.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Layout Name: View type
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- $html = array();
13
-
14
- $layout = $dargs['layout-format'];
15
-
16
- // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
- if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
- $layout = '1-col';
19
- }
20
-
21
- switch ( $layout ) {
22
- case '1-col':
23
- foreach ( $fields_html as $field_html ) {
24
- $html[] = $field_html;
25
- }
26
- break;
27
- case '2-col':
28
-
29
- // Thumbnail html
30
- $thumbnail_html = $fields_html['thumbnail'];
31
-
32
- // Other fields html
33
- unset( $fields_html['thumbnail'] );
34
- $others_html = implode( "\n", $fields_html );
35
-
36
- $html[] = $thumbnail_html;
37
- $html[] = $others_html;
38
-
39
- break;
40
- }
41
-
42
  echo balanceTags( implode( "\n", $html ) );
1
+ <?php
2
+ /**
3
+ * Layout Name: View type
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ $html = array();
13
+
14
+ $layout = $dargs['layout-format'];
15
+
16
+ // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
+ if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
+ $layout = '1-col';
19
+ }
20
+
21
+ switch ( $layout ) {
22
+ case '1-col':
23
+ foreach ( $fields_html as $field_html ) {
24
+ $html[] = $field_html;
25
+ }
26
+ break;
27
+ case '2-col':
28
+
29
+ // Thumbnail html
30
+ $thumbnail_html = $fields_html['thumbnail'];
31
+
32
+ // Other fields html
33
+ unset( $fields_html['thumbnail'] );
34
+ $others_html = implode( "\n", $fields_html );
35
+
36
+ $html[] = $thumbnail_html;
37
+ $html[] = $others_html;
38
+
39
+ break;
40
+ }
41
+
42
  echo balanceTags( implode( "\n", $html ) );
public/templates/collapsible/html/main.php CHANGED
@@ -1,66 +1,66 @@
1
- <?php
2
- /**
3
- * Layout Name: Collapsible List
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- $html = array();
13
-
14
- $layout = $dargs['layout-format'];
15
-
16
- // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
- if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
- $layout = '1-col';
19
- }
20
-
21
- // Get title
22
- $heading = isset( $fields_html['title'] ) ? $fields_html['title'] : '';
23
- unset( $fields_html['title'] );
24
-
25
- switch ( $layout ) {
26
- case '1-col':
27
- foreach ( $fields_html as $field_html ) {
28
- $html[] = $field_html;
29
- }
30
- break;
31
- case '2-col':
32
-
33
- // Thumbnail html
34
- $thumbnail_html = $fields_html['thumbnail'];
35
-
36
- // Other fields html
37
- unset( $fields_html['thumbnail'] );
38
- $others_html = implode( "\n", $fields_html );
39
-
40
- $html[] = $thumbnail_html;
41
- $html[] = $others_html;
42
-
43
- break;
44
- }
45
-
46
- $random_id = PT_CV_Functions::string_random();
47
- ?>
48
- <div class="panel panel-default">
49
- <div class="panel-heading">
50
- <a class="panel-title" data-toggle="collapse" data-parent="#<?php echo esc_attr( PT_CV_PREFIX_UPPER . 'ID' ); ?>" href="#<?php echo esc_attr( $random_id ); ?>">
51
- <?php echo balanceTags( strip_tags( $heading ) ); ?>
52
- </a>
53
- <?php
54
- // Custom toggle icon
55
- $toggle_icon = apply_filters( PT_CV_PREFIX_ . 'scrollable_toggle_icon', '' );
56
- echo balanceTags( $toggle_icon );
57
- ?>
58
- </div>
59
- <div id="<?php echo esc_attr( $random_id ); ?>" class="panel-collapse collapse <?php echo esc_attr( PT_CV_PREFIX_UPPER . 'CLASS' ); ?>">
60
- <div class="panel-body">
61
- <?php
62
- echo balanceTags( implode( "\n", $html ) );
63
- ?>
64
- </div>
65
- </div>
66
  </div>
1
+ <?php
2
+ /**
3
+ * Layout Name: Collapsible List
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ $html = array();
13
+
14
+ $layout = $dargs['layout-format'];
15
+
16
+ // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
+ if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
+ $layout = '1-col';
19
+ }
20
+
21
+ // Get title
22
+ $heading = isset( $fields_html['title'] ) ? $fields_html['title'] : '';
23
+ unset( $fields_html['title'] );
24
+
25
+ switch ( $layout ) {
26
+ case '1-col':
27
+ foreach ( $fields_html as $field_html ) {
28
+ $html[] = $field_html;
29
+ }
30
+ break;
31
+ case '2-col':
32
+
33
+ // Thumbnail html
34
+ $thumbnail_html = $fields_html['thumbnail'];
35
+
36
+ // Other fields html
37
+ unset( $fields_html['thumbnail'] );
38
+ $others_html = implode( "\n", $fields_html );
39
+
40
+ $html[] = $thumbnail_html;
41
+ $html[] = $others_html;
42
+
43
+ break;
44
+ }
45
+
46
+ $random_id = PT_CV_Functions::string_random();
47
+ ?>
48
+ <div class="panel panel-default">
49
+ <div class="panel-heading">
50
+ <a class="panel-title" data-toggle="collapse" data-parent="#<?php echo esc_attr( PT_CV_PREFIX_UPPER . 'ID' ); ?>" href="#<?php echo esc_attr( $random_id ); ?>">
51
+ <?php echo balanceTags( strip_tags( $heading ) ); ?>
52
+ </a>
53
+ <?php
54
+ // Custom toggle icon
55
+ $toggle_icon = apply_filters( PT_CV_PREFIX_ . 'scrollable_toggle_icon', '' );
56
+ echo balanceTags( $toggle_icon );
57
+ ?>
58
+ </div>
59
+ <div id="<?php echo esc_attr( $random_id ); ?>" class="panel-collapse collapse <?php echo esc_attr( PT_CV_PREFIX_UPPER . 'CLASS' ); ?>">
60
+ <div class="panel-body">
61
+ <?php
62
+ echo balanceTags( implode( "\n", $html ) );
63
+ ?>
64
+ </div>
65
+ </div>
66
  </div>
public/templates/grid/html/main.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
- /**
3
- * Layout Name: Grid
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- $html = array();
13
-
14
- $layout = $dargs['layout-format'];
15
-
16
- // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
- if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
- $layout = '1-col';
19
- }
20
-
21
- switch ( $layout ) {
22
- case '1-col':
23
- foreach ( $fields_html as $field_html ) {
24
- $html[] = $field_html;
25
- }
26
- break;
27
- case '2-col':
28
-
29
- // Thumbnail html
30
- $html[] = $fields_html['thumbnail'];
31
-
32
- // Other fields html
33
- unset( $fields_html['thumbnail'] );
34
- $others_html = implode( "\n", $fields_html );
35
- $html[] = $others_html;
36
-
37
- break;
38
- }
39
-
40
  echo balanceTags( implode( "\n", $html ) );
1
+ <?php
2
+ /**
3
+ * Layout Name: Grid
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ $html = array();
13
+
14
+ $layout = $dargs['layout-format'];
15
+
16
+ // Prevent the case: there are 2 columns but have not setting for thumbnail position
17
+ if ( $layout == '2-col' && ! isset( $dargs['field-settings']['thumbnail'] ) ) {
18
+ $layout = '1-col';
19
+ }
20
+
21
+ switch ( $layout ) {
22
+ case '1-col':
23
+ foreach ( $fields_html as $field_html ) {
24
+ $html[] = $field_html;
25
+ }
26
+ break;
27
+ case '2-col':
28
+
29
+ // Thumbnail html
30
+ $html[] = $fields_html['thumbnail'];
31
+
32
+ // Other fields html
33
+ unset( $fields_html['thumbnail'] );
34
+ $others_html = implode( "\n", $fields_html );
35
+ $html[] = $others_html;
36
+
37
+ break;
38
+ }
39
+
40
  echo balanceTags( implode( "\n", $html ) );
public/templates/scrollable/html/main.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
- /**
3
- * Layout Name: Scrollable List
4
- *
5
- * @package PT_Content_Views
6
- * @author PT Guy <palaceofthemes@gmail.com>
7
- * @license GPL-2.0+
8
- * @link http://www.contentviewspro.com/
9
- * @copyright 2014 PT Guy
10
- */
11
-
12
- $html = array();
13
-
14
- $ex_cap_cls = PT_CV_PREFIX . 'cap-w-img';;
15
-
16
- $img = strip_tags( isset( $fields_html['thumbnail'] ) ? $fields_html['thumbnail'] : '', '<img>' );
17
- if ( ! empty( $img ) ) {
18
- // Thumbnail html
19
- $html[] = $fields_html['thumbnail'];
20
- unset( $fields_html['thumbnail'] );
21
- } else {
22
- $ex_cap_cls = PT_CV_PREFIX . 'cap-wo-img';
23
- }
24
-
25
- // Other fields html
26
- $others_html = implode( "\n", $fields_html );
27
-
28
- // Get wrapper class of caption
29
- $caption_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_caption_class', array( 'carousel-caption', $ex_cap_cls ) );
30
- $html[] = sprintf( '<div class="%s">%s</div>', esc_attr( implode( ' ', array_filter( $caption_class ) ) ), balanceTags( $others_html ) );
31
-
32
  echo balanceTags( implode( "\n", $html ) );
1
+ <?php
2
+ /**
3
+ * Layout Name: Scrollable List
4
+ *
5
+ * @package PT_Content_Views
6
+ * @author PT Guy <palaceofthemes@gmail.com>
7
+ * @license GPL-2.0+
8
+ * @link http://www.contentviewspro.com/
9
+ * @copyright 2014 PT Guy
10
+ */
11
+
12
+ $html = array();
13
+
14
+ $ex_cap_cls = PT_CV_PREFIX . 'cap-w-img';;
15
+
16
+ $img = strip_tags( isset( $fields_html['thumbnail'] ) ? $fields_html['thumbnail'] : '', '<img>' );
17
+ if ( ! empty( $img ) ) {
18
+ // Thumbnail html
19
+ $html[] = $fields_html['thumbnail'];
20
+ unset( $fields_html['thumbnail'] );
21
+ } else {
22
+ $ex_cap_cls = PT_CV_PREFIX . 'cap-wo-img';
23
+ }
24
+
25
+ // Other fields html
26
+ $others_html = implode( "\n", $fields_html );
27
+
28
+ // Get wrapper class of caption
29
+ $caption_class = apply_filters( PT_CV_PREFIX_ . 'scrollable_caption_class', array( 'carousel-caption', $ex_cap_cls ) );
30
+ $html[] = sprintf( '<div class="%s">%s</div>', esc_attr( implode( ' ', array_filter( $caption_class ) ) ), balanceTags( $others_html ) );
31
+
32
  echo balanceTags( implode( "\n", $html ) );