1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* @package Pods\Components |
4
|
|
|
* @subpackage Builder |
5
|
|
|
*/ |
6
|
|
|
if ( !class_exists( 'LayoutModule' ) ) |
7
|
|
|
return; |
8
|
|
|
|
9
|
|
|
if ( !class_exists( 'PodsBuilderModuleList' ) ) { |
10
|
|
|
class PodsBuilderModuleList extends LayoutModule { |
11
|
|
|
|
12
|
|
|
var $_name = ''; |
|
|
|
|
13
|
|
|
var $_var = 'pods-builder-list'; |
|
|
|
|
14
|
|
|
var $_description = ''; |
|
|
|
|
15
|
|
|
var $_editor_width = 500; |
|
|
|
|
16
|
|
|
var $_can_remove_wrappers = true; |
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Register the Module |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function __construct () { |
|
|
|
|
22
|
|
|
$this->_name = __( 'Pods - List Items', 'pods' ); |
23
|
|
|
$this->_description = __( 'Display multiple Pod items', 'pods' ); |
24
|
|
|
$this->module_path = dirname( __FILE__ ); |
25
|
|
|
|
26
|
|
|
$this->LayoutModule(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Set default variables |
31
|
|
|
* |
32
|
|
|
* @param $defaults |
33
|
|
|
* |
34
|
|
|
* @return mixed |
35
|
|
|
*/ |
36
|
|
|
function _get_defaults ( $defaults ) { |
|
|
|
|
37
|
|
|
$new_defaults = array( |
38
|
|
|
'pod_type' => '', |
39
|
|
|
'template' => '', |
40
|
|
|
'template_custom' => '', |
41
|
|
|
'limit' => 15, |
42
|
|
|
'orderby' => '', |
43
|
|
|
'where' => '', |
44
|
|
|
'expires' => ( 60 * 5 ), |
45
|
|
|
'cache_mode' => 'transient', |
46
|
|
|
'sidebar' => 'none' |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
return ITUtility::merge_defaults( $new_defaults, $defaults ); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Output something before the table form |
54
|
|
|
* |
55
|
|
|
* @param object $form Form class |
56
|
|
|
* @param bool $results |
57
|
|
|
*/ |
58
|
|
|
function _before_table_edit ( $form, $results = true ) { |
|
|
|
|
59
|
|
|
?> |
60
|
|
|
<p><?php echo $this->_description; ?></p> |
61
|
|
|
<?php |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Output something at the start of the table form |
66
|
|
|
* |
67
|
|
|
* @param object $form Form class |
68
|
|
|
* @param bool $results |
69
|
|
|
*/ |
70
|
|
|
function _start_table_edit ( $form, $results = true ) { |
|
|
|
|
71
|
|
|
$api = pods_api(); |
72
|
|
|
$all_pods = $api->load_pods( array( 'names' => true ) ); |
73
|
|
|
|
74
|
|
|
$pod_types = array(); |
75
|
|
|
|
76
|
|
|
foreach ( $all_pods as $pod_name => $pod_label ) { |
|
|
|
|
77
|
|
|
$pod_types[ $pod_name ] = $pod_label . ' (' . $pod_name . ')'; |
78
|
|
|
} |
79
|
|
|
?> |
80
|
|
|
<tr> |
81
|
|
|
<td valign="top"> |
82
|
|
|
<label for="pod_type"><?php _e( 'Pod', 'pods' ); ?></label> |
83
|
|
|
</td> |
84
|
|
|
<td> |
85
|
|
|
<?php |
86
|
|
View Code Duplication |
if ( 0 < count( $all_pods ) ) |
87
|
|
|
$form->add_drop_down( 'pod_type', $pod_types ); |
88
|
|
|
else |
89
|
|
|
echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; |
90
|
|
|
?> |
91
|
|
|
</td> |
92
|
|
|
</tr> |
93
|
|
|
|
94
|
|
|
<?php |
95
|
|
View Code Duplication |
if ( class_exists( 'Pods_Templates' ) ) { |
96
|
|
|
$all_templates = (array) $api->load_templates( array() ); |
97
|
|
|
|
98
|
|
|
$templates = array( |
99
|
|
|
'' => '- ' . __( 'Custom Template', 'pods' ) . ' -' |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
foreach ( $all_templates as $template ) { |
103
|
|
|
$templates[ $template[ 'name' ] ] = $template[ 'name' ]; |
104
|
|
|
} |
105
|
|
|
?> |
106
|
|
|
<tr> |
107
|
|
|
<td valign="top"> |
108
|
|
|
<label for="template"><?php _e( 'Template', 'pods' ); ?></label> |
109
|
|
|
</td> |
110
|
|
|
<td> |
111
|
|
|
<?php |
112
|
|
|
if ( 0 < count( $all_templates ) ) |
113
|
|
|
$form->add_drop_down( 'template', $templates ); |
114
|
|
|
else |
115
|
|
|
echo '<strong class="red">' . __( 'None Found', 'pods' ) . '</strong>'; |
116
|
|
|
?> |
117
|
|
|
</td> |
118
|
|
|
</tr> |
119
|
|
|
<?php |
120
|
|
|
} |
121
|
|
|
else { |
122
|
|
|
?> |
123
|
|
|
<tr> |
124
|
|
|
<td valign="top"> |
125
|
|
|
<label for="template"><?php _e( 'Template', 'pods' ); ?></label> |
126
|
|
|
</td> |
127
|
|
|
<td> |
128
|
|
|
<?php $form->add_text_box( 'template' ); ?> |
129
|
|
|
</td> |
130
|
|
|
</tr> |
131
|
|
|
<?php |
132
|
|
|
} |
133
|
|
|
?> |
134
|
|
|
|
135
|
|
|
<tr> |
136
|
|
|
<td valign="top"> |
137
|
|
|
<label for="template_custom"><?php _e( 'Custom Template', 'pods' ); ?></label> |
138
|
|
|
</td> |
139
|
|
|
<td> |
140
|
|
|
<?php $form->add_text_area( 'template_custom', array( 'style' => 'width:90%; max-width:100%; min-height:100px;', 'rows' => '8' ) ); ?> |
141
|
|
|
</td> |
142
|
|
|
</tr> |
143
|
|
|
<tr> |
144
|
|
|
<td valign="top"> |
145
|
|
|
<label for="limit"><?php _e( 'Limit', 'pods' ); ?></label> |
146
|
|
|
</td> |
147
|
|
|
<td> |
148
|
|
|
<?php $form->add_text_box( 'limit' ); ?> |
149
|
|
|
</td> |
150
|
|
|
</tr> |
151
|
|
|
<tr> |
152
|
|
|
<td valign="top"> |
153
|
|
|
<label for="orderby"><?php _e( 'Order By', 'pods' ); ?></label> |
154
|
|
|
</td> |
155
|
|
|
<td> |
156
|
|
|
<?php $form->add_text_box( 'orderby' ); ?> |
157
|
|
|
</td> |
158
|
|
|
</tr> |
159
|
|
|
<tr> |
160
|
|
|
<td valign="top"> |
161
|
|
|
<label for="where"><?php _e( 'Where', 'pods' ); ?></label> |
162
|
|
|
</td> |
163
|
|
|
<td> |
164
|
|
|
<?php $form->add_text_box( 'where' ); ?> |
165
|
|
|
</td> |
166
|
|
|
</tr> |
167
|
|
|
<tr> |
168
|
|
|
<td valign="top"> |
169
|
|
|
<label for="cache_mode"><?php _e( 'Cache Type', 'pods' ); ?></label> |
170
|
|
|
</td> |
171
|
|
|
<td> |
172
|
|
|
<?php |
173
|
|
|
$cache_modes = array( |
174
|
|
|
'none' => __( 'Disable Caching', 'pods' ), |
175
|
|
|
'cache' => __( 'Object Cache', 'pods' ), |
176
|
|
|
'transient' => __( 'Transient', 'pods' ), |
177
|
|
|
'site-transient' => __( 'Site Transient', 'pods' ) |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
$form->add_drop_down( 'cache_mode', $cache_modes ); |
181
|
|
|
?> |
182
|
|
|
</td> |
183
|
|
|
</tr> |
184
|
|
|
<tr> |
185
|
|
|
<td valign="top"> |
186
|
|
|
<label for="expires"><?php _e( 'Cache Expiration (in seconds)', 'pods' ); ?></label> |
187
|
|
|
</td> |
188
|
|
|
<td> |
189
|
|
|
<?php $form->add_text_box( 'expires' ); ?> |
190
|
|
|
</td> |
191
|
|
|
</tr> |
192
|
|
|
<?php |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Module Output |
197
|
|
|
*/ |
198
|
|
|
function _render ( $fields ) { |
|
|
|
|
199
|
|
|
$args = array( |
200
|
|
|
'name' => trim( pods_var_raw( 'pod_type', $fields[ 'data' ], '' ) ), |
201
|
|
|
'template' => trim( pods_var_raw( 'template', $fields[ 'data' ], '' ) ), |
202
|
|
|
'limit' => (int) pods_var_raw( 'limit', $fields[ 'data' ], 15, null, true ), |
203
|
|
|
'orderby' => trim( pods_var_raw( 'orderby', $fields[ 'data' ], '' ) ), |
204
|
|
|
'where' => trim( pods_var_raw( 'where', $fields[ 'data' ], '' ) ), |
205
|
|
|
'expires' => (int) trim( pods_var_raw( 'expires', $fields[ 'data' ], ( 60 * 5 ) ) ), |
206
|
|
|
'cache_mode' => trim( pods_var_raw( 'cache_mode', $fields[ 'data' ], 'transient', null, true ) ) |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
$content = trim( pods_var_raw( 'template_custom', $fields[ 'data' ], '' ) ); |
210
|
|
|
|
211
|
|
View Code Duplication |
if ( 0 < strlen( $args[ 'name' ] ) && ( 0 < strlen( $args[ 'template' ] ) || 0 < strlen( $content ) ) ) |
212
|
|
|
echo pods_shortcode( $args, ( isset( $content ) ? $content : null ) ); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
new PodsBuilderModuleList(); |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.