/
shortcode.php
259 lines (238 loc) · 7.56 KB
/
shortcode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
include_once 'utils.php';
include 'presentation.php';
include 'presentation_full.php';
/*
Function random_faces_count_handler
param $atts (attributes)
max: Number of faces to show (if higher than count, will display count)
per_row: Number of units to be shown per row.
order: attribute determining the order in which units are to be displayed.
By Name:
name-asc
name-desc
By Title:
title-asc
title-desc
None specified: random
Connects to the pavlov_faces shortcode (lists 4 members by default)
*/
function random_faces_count_handler($atts)
{
$a = shortcode_atts(array(
'max' => 4,
'per_row' => 4,
'order' => 'random',
'hoverface'=> '1',
'hovername' => '',
'presentation' => '',
'link' => '#'
), $atts);
ob_start();
presentation($a, get_data($a));
return ob_get_clean();
}
/*
Function listed_faces_handler
param $atts (attributes)
max: Number of faces to show at one time (defaults to total)
per_row: Number of units to be shown per row.
order: attribute determining the order in which units are to be displayed.
By Name:
name-asc
name-desc
By Title:
title-asc
title-desc
None specified: random
Connects to the pavlov_faces_full shortcode (lists all members by default)
*/
function listed_faces_handler($atts)
{
global $wpdb;
global $table_full_name;
$max = $wpdb->get_var("SELECT COUNT(*) FROM $table_full_name");
$a = shortcode_atts(array(
'max' => $max,
'order' => 'name_asc',
'hoverface' => '1',
'hovername' => '',
'presentation' => '1',
), $atts);
ob_start();
presentation_full_list($a, get_data($a));
return ob_get_clean();
}
/*
Get Data Function
param $atts: tags given in the box
Calls the SQL table and returns the array provided.
*/
function get_data($atts)
{
global $wpdb;
global $table_full_name;
//code for list. Here we will eventually check for the type (somehow) then save a lot of size
//$offset = $atts['offset'];
if(!is_numeric($atts['max']))
$limit = 4;
else $limit = $atts['max'];
switch($atts['order'])
{
case 'name-asc':
$order = 'membername';
break;
case 'name-desc':
$order = 'membername DESC';
break;
case 'title-asc':
$order = 'title';
break;
case 'title-desc':
$order = 'title DESC';
break;
default:
$order = 'RAND()';
break;
}
//test query
$faces = $wpdb->get_results("SELECT * FROM $table_full_name ORDER BY $order LIMIT $limit");
return $faces;
}
/*Turns shortcode into element.*/
function make_element()
{
global $wpdb;
$table_name = $wpdb->prefix . 'pavlov_faces';
$max = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
$pages = get_pages();
$list = array('no link' => '');
foreach($pages as $page)
{
$list[$page->post_title] = home_url().get_page_link($page->ID);
}
vc_map( array(
"name" => __("Four Familiar Faces"),
"base" => "pavlov_faces",
"category" => __('Content'),
"params" => array(
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Max"),
"param_name" => "max",
"value" => __($max),
"description" => __("Maximum faces to show (blank = no maximum)", 'my-text-domain')
),
array(
"type" => "dropdown",
"holder" => "div",
"class" => "",
"heading" => __("Row Size"),
"param_name" => "per_row",
"value" => array(1, 2, 3, 4, 5, 6),
"description" => __("Faces to show per row", 'my-text-domain')
),
array(
"type" => "dropdown",
"holder" => "div",
"class" => "",
"heading" => __("Display Order"),
"param_name" => "order",
"value" => array(
'Random' => "random",
'Name (Ascending)' => "name-asc",
'Name (Descending)' => "name-desc",
'Title (Ascending)' => "title-asc",
'Title (Descending)' => "title-desc"
),
"description" => __("Listing order for faces", 'my-text-domain')
),
array(
"type" => "checkbox",
"holder" => "span",
"class" => "",
"heading" => __("Hover Face"),
"param_name" => "hoverface",
"value" => array('' => 'true'), //wants an associative array for checkboxes
"description" => __("Change face on hover?", 'my-text-domain')
),
array(
"type" => "checkbox",
"holder" => "span",
"class" => "",
"heading" => __("Hover Name"),
"param_name" => "hovername",
"value" =>array('' => 'true'),
"description" => __("Change name on hover?", 'my-text-domain')
),
array(
"type" => "dropdown",
"holder" => "div",
"class" => "",
"heading" => __("URL link:"),
"param_name" => "link",
"value" => $list,
"description" => __("URL of webpage containing full member list to link", 'my-text-domain')
),
)
) );
}
/*Turns full list shortcode into element*/
function make_full_element()
{
global $wpdb;
$table_name = $wpdb->prefix . 'pavlov_faces';
$max = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
vc_map( array(
"name" => __("Four Familiar Faces (Full List)"),
"base" => "pavlov_faces_full",
"category" => __('Content'),
"params" => array(
array(
"type" => "textfield",
"holder" => "div",
"class" => "",
"heading" => __("Max"),
"param_name" => "max",
"value" => __($max, 'my-text-domain'),
"description" => __("Maximum faces to show (blank = no maximum)", 'my-text-domain')
),
array(
"type" => "dropdown",
"holder" => "div",
"class" => "",
"heading" => __("Display Order"),
"param_name" => "order",
"value" => array(
'Random' => "random",
'Name (Ascending)' => "name-asc",
'Name (Descending)' => "name-desc",
'Title (Ascending)' => "title-asc",
'Title (Descending)' => "title-desc"
),
"description" => __("Listing order for faces", 'my-text-domain')
),
array(
"type" => "checkbox",
"holder" => "span",
"class" => "",
"heading" => __("Hover Face"),
"param_name" => "hoverface",
"value" => array('Name' => 'true'), //wants an associative array for checkboxes
"description" => __("Change face on hover?", 'my-text-domain')
),
array(
"type" => "checkbox",
"holder" => "span",
"class" => "",
"heading" => __("Hover Name"),
"param_name" => "hovername",
"value" =>array('Face' => 'true'),
"description" => __("Change name on hover?")
),
)
) );
}
?>