-
Notifications
You must be signed in to change notification settings - Fork 13
/
qa-social-share-admin.php
501 lines (453 loc) · 20.1 KB
/
qa-social-share-admin.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<?php
if ( !defined( 'QA_VERSION' ) ) { // don't allow this page to be requested directly from browser
exit;
}
class qa_social_share_admin
{
function allow_template( $template )
{
return ( $template != 'admin' );
}
function option_default( $option )
{
switch ( $option ) {
case qa_sss_opt::SHARE_TEXT:
case qa_sss_opt::SHARE_TEXT_HOME:
case qa_sss_opt::SHARE_TEXT_BLOG_POST:
return;
break;
case qa_sss_opt::FB_BUTTON:
case qa_sss_opt::GP_BUTTON:
case qa_sss_opt::TW_BUTTON:
case qa_sss_opt::WA_BUTTON:
case qa_sss_opt::BUTTON_STATUS:
return true;
break;
case qa_sss_opt::LI_BUTTON:
case qa_sss_opt::RE_BUTTON:
case qa_sss_opt::VK_BUTTON:
case qa_sss_opt::EM_BUTTON:
case qa_sss_opt::ST_BUTTON:
case qa_sss_opt::TG_BUTTON:
return false;
break;
case qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION:
case qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION:
case qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION:
return qa_sss_opt::SHARE_TYPE_COLORED_BTNS_WITH_ICON;
break;
case qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION:
return qa_sss_opt::SHARE_TYPE_FI_SEMI_ROUNDED;
break;
}
}
function admin_form()
{
//require_once QA_INCLUDE_DIR.'qa-util-sort.php';
$saved = false;
if ( qa_clicked( qa_sss_opt::ADMIN_SAVE_BTN ) ) {
$trimchars = "=;\"\' \t\r\n"; // prevent common errors by copying and pasting from Javascript
qa_opt( qa_sss_opt::SHARE_TEXT, trim( qa_post_text( qa_sss_opt::SHARE_TEXT ), $trimchars ) );
qa_opt( qa_sss_opt::SHARE_TEXT_HOME, trim( qa_post_text( qa_sss_opt::SHARE_TEXT_HOME ), $trimchars ) );
qa_opt( qa_sss_opt::SHARE_TEXT_BLOG_POST, trim( qa_post_text( qa_sss_opt::SHARE_TEXT_BLOG_POST ), $trimchars ) );
qa_opt( qa_sss_opt::FB_BUTTON, (bool) qa_post_text( qa_sss_opt::FB_BUTTON ) );
qa_opt( qa_sss_opt::GP_BUTTON, (bool) qa_post_text( qa_sss_opt::GP_BUTTON ) );
qa_opt( qa_sss_opt::TW_BUTTON, (bool) qa_post_text( qa_sss_opt::TW_BUTTON ) );
qa_opt( qa_sss_opt::LI_BUTTON, (bool) qa_post_text( qa_sss_opt::LI_BUTTON ) );
qa_opt( qa_sss_opt::RE_BUTTON, (bool) qa_post_text( qa_sss_opt::RE_BUTTON ) );
qa_opt( qa_sss_opt::VK_BUTTON, (bool) qa_post_text( qa_sss_opt::VK_BUTTON ) );
qa_opt( qa_sss_opt::EM_BUTTON, (bool) qa_post_text( qa_sss_opt::EM_BUTTON ) );
qa_opt( qa_sss_opt::WA_BUTTON, (bool) qa_post_text( qa_sss_opt::WA_BUTTON ) );
qa_opt( qa_sss_opt::ST_BUTTON, (bool) qa_post_text( qa_sss_opt::ST_BUTTON ) );
qa_opt( qa_sss_opt::TG_BUTTON, (bool) qa_post_text( qa_sss_opt::TG_BUTTON ) );
qa_opt( qa_sss_opt::BUTTON_STATUS, (bool) qa_post_text( qa_sss_opt::BUTTON_STATUS ) );
qa_opt( qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT, (bool) qa_post_text( qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT ) );
qa_opt( qa_sss_opt::FACEBOOK_APP_ID, qa_post_text( qa_sss_opt::FACEBOOK_APP_ID ) );
qa_opt( qa_sss_opt::TWITTER_HANDLE, qa_post_text( qa_sss_opt::TWITTER_HANDLE ) );
qa_opt( qa_sss_opt::WEBSITE_DESCRIPTION, qa_post_text( qa_sss_opt::WEBSITE_DESCRIPTION ) );
qa_opt( qa_sss_opt::DEFAULT_SHARE_IMAGE, qa_post_text( qa_sss_opt::DEFAULT_SHARE_IMAGE ) );
qa_opt( qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION, qa_post_text( qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION ) );
qa_opt( qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION, qa_post_text( qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION ) );
qa_opt( qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION, qa_post_text( qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION ) );
qa_opt( qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION, qa_post_text( qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION ) );
qa_opt( qa_sss_opt::CUSTOM_CSS, qa_post_text( qa_sss_opt::CUSTOM_CSS ) );
$saved = true;
}
$social_share_types = array(
qa_sss_opt::SHARE_TYPE_IMAGE => 'Image',
qa_sss_opt::SHARE_TYPE_TEXT => 'Textual sharing',
qa_sss_opt::SHARE_TYPE_COLORED_BTNS => 'Colored buttons',
qa_sss_opt::SHARE_TYPE_COLORED_BTNS_WITH_ICON => 'Colored buttons with icon',
qa_sss_opt::SHARE_TYPE_FI_SQ => 'Squared icons',
qa_sss_opt::SHARE_TYPE_FI_SEMI_ROUNDED => 'Semi-rounded buttons with icon',
qa_sss_opt::SHARE_TYPE_FI_ROUNDED => 'Rounded buttons with icon',
qa_sss_opt::SHARE_TYPE_ANIMATED_FI => 'Animated buttons with icon',
);
$form = array(
'ok' => $saved ? qa_lang( 'sss_lang/sss_settings_saved' ) : null,
'fields' => array(
qa_sss_opt::SHARE_TEXT_HOME => $this->get_share_text_home_field(),
qa_sss_opt::SHARE_TEXT => $this->get_share_text_field(),
qa_sss_opt::SHARE_TEXT_BLOG_POST => $this->get_share_text_blog_post_field(),
qa_sss_opt::FB_BUTTON => $this->get_fb_button_field(),
qa_sss_opt::GP_BUTTON => $this->get_gp_button_field(),
qa_sss_opt::TW_BUTTON => $this->get_tw_button_field(),
qa_sss_opt::LI_BUTTON => $this->get_li_button_field(),
qa_sss_opt::RE_BUTTON => $this->get_re_button_field(),
qa_sss_opt::VK_BUTTON => $this->get_vk_button_field(),
qa_sss_opt::ST_BUTTON => $this->get_st_button_field(),
qa_sss_opt::EM_BUTTON => $this->get_em_button_field(),
qa_sss_opt::WA_BUTTON => $this->get_wa_button_field(),
qa_sss_opt::TG_BUTTON => $this->get_tg_button_field(),
qa_sss_opt::BUTTON_STATUS => $this->get_button_status_field(),
qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION => $this->get_share_type_q_desktop_button( $social_share_types ),
qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION => $this->get_share_type_q_mobile_button( $social_share_types ),
qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION => $this->get_share_type_w_desktop_button( $social_share_types ),
qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION => $this->get_share_type_w_mobile_button( $social_share_types ),
qa_sss_opt::CUSTOM_CSS => $this->get_custom_css_field(),
qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT => $this->get_enable_opengraph_support_field(),
qa_sss_opt::DEFAULT_SHARE_IMAGE => $this->get_default_image_field(),
qa_sss_opt::FACEBOOK_APP_ID => $this->get_facebook_app_id_field(),
qa_sss_opt::TWITTER_HANDLE => $this->get_twitter_handle_field(),
qa_sss_opt::WEBSITE_DESCRIPTION => $this->get_site_description_field(),
),
'buttons' => array(
array(
'label' => qa_lang( 'sss_lang/save_changes' ),
'tags' => 'name="' . qa_sss_opt::ADMIN_SAVE_BTN . '"',
),
),
);
return $form;
}
/**
* @return array
*/
public function get_share_text_home_field()
{
return array(
'id' => qa_sss_opt::SHARE_TEXT_HOME,
'label' => qa_lang( 'sss_lang/enter_share_text_for_home' ),
'value' => qa_html( qa_opt( qa_sss_opt::SHARE_TEXT_HOME ) ),
'tags' => 'name="' . qa_sss_opt::SHARE_TEXT_HOME . '"',
);
}
/**
* @return array
*/
public function get_share_text_field()
{
return array(
'id' => qa_sss_opt::SHARE_TEXT,
'label' => qa_lang( 'sss_lang/enter_share_text' ),
'value' => qa_html( qa_opt( qa_sss_opt::SHARE_TEXT ) ),
'tags' => 'name="' . qa_sss_opt::SHARE_TEXT . '"',
'note' => qa_lang( 'sss_lang/choose_buttons_from_below' ),
);
}
/**
* @return array
*/
public function get_share_text_blog_post_field()
{
return array(
'id' => qa_sss_opt::SHARE_TEXT_BLOG_POST,
'label' => qa_lang( 'sss_lang/enter_share_text_for_blog_post' ),
'value' => qa_html( qa_opt( qa_sss_opt::SHARE_TEXT_BLOG_POST ) ),
'tags' => 'name="' . qa_sss_opt::SHARE_TEXT_BLOG_POST . '"',
'note' => qa_lang( 'sss_lang/choose_buttons_from_below' ),
);
}
/**
* @return array
*/
public function get_fb_button_field()
{
return array(
'id' => qa_sss_opt::FB_BUTTON,
'label' => qa_lang( 'sss_lang/fb' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::FB_BUTTON ),
'tags' => 'name="' . qa_sss_opt::FB_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_gp_button_field()
{
return array(
'id' => qa_sss_opt::GP_BUTTON,
'label' => qa_lang( 'sss_lang/gp' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::GP_BUTTON ),
'tags' => 'name="' . qa_sss_opt::GP_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_tw_button_field()
{
return array(
'id' => qa_sss_opt::TW_BUTTON,
'label' => qa_lang( 'sss_lang/tw' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::TW_BUTTON ),
'tags' => 'name="' . qa_sss_opt::TW_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_li_button_field()
{
return array(
'id' => qa_sss_opt::LI_BUTTON,
'label' => qa_lang( 'sss_lang/li' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::LI_BUTTON ),
'tags' => 'name="' . qa_sss_opt::LI_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_re_button_field()
{
return array(
'id' => qa_sss_opt::RE_BUTTON,
'label' => qa_lang( 'sss_lang/reddit' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::RE_BUTTON ),
'tags' => 'name="' . qa_sss_opt::RE_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_vk_button_field()
{
return array(
'id' => qa_sss_opt::VK_BUTTON,
'label' => qa_lang( 'sss_lang/vk' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::VK_BUTTON ),
'tags' => 'name="' . qa_sss_opt::VK_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_st_button_field()
{
return array(
'id' => qa_sss_opt::ST_BUTTON,
'label' => qa_lang( 'sss_lang/st' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::ST_BUTTON ),
'tags' => 'name="' . qa_sss_opt::ST_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_em_button_field()
{
return array(
'id' => qa_sss_opt::EM_BUTTON,
'label' => qa_lang( 'sss_lang/email' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::EM_BUTTON ),
'tags' => 'name="' . qa_sss_opt::EM_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_wa_button_field()
{
return array(
'id' => qa_sss_opt::WA_BUTTON,
'label' => qa_lang( 'sss_lang/whatsapp' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::WA_BUTTON ),
'tags' => 'name="' . qa_sss_opt::WA_BUTTON . '"',
);
}
/**
* @return array
*/
public function get_tg_button_field()
{
return array(
'id' => qa_sss_opt::TG_BUTTON,
'label' => qa_lang( 'sss_lang/telegram' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::TG_BUTTON ),
'tags' => 'name="' . qa_sss_opt::TG_BUTTON . '"',
'note' => qa_lang( 'sss_lang/sharing_btn_enable_note' ),
);
}
/**
* @return array
*/
public function get_button_status_field()
{
return array(
'id' => qa_sss_opt::BUTTON_STATUS,
'label' => (int) qa_opt( qa_sss_opt::BUTTON_STATUS ) ? qa_lang( 'sss_lang/currently_enabled' ) : qa_lang( 'sss_lang/currently_disabled' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::BUTTON_STATUS ),
'tags' => 'name="' . qa_sss_opt::BUTTON_STATUS . '"',
);
}
/**
* @param $social_share_types
*
* @return array
*/
public function get_share_type_q_desktop_button( $social_share_types )
{
return array(
'id' => qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION,
'label' => qa_lang( 'sss_lang/choose_share_type_for_q_desktop' ),
'type' => 'select',
'value' => qa_opt( qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION ),
'tags' => 'name="' . qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION . '"',
'options' => $social_share_types,
'match_by' => 'key',
);
}
/**
* @param $social_share_types
*
* @return array
*/
public function get_share_type_q_mobile_button( $social_share_types )
{
return array(
'id' => qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION,
'label' => qa_lang( 'sss_lang/choose_share_type_for_q_mobile' ),
'type' => 'select',
'value' => qa_opt( qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION ),
'tags' => 'name="' . qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION . '"',
'options' => $social_share_types,
'match_by' => 'key',
);
}
/**
* @param $social_share_types
*
* @return array
*/
public function get_share_type_w_desktop_button( $social_share_types )
{
return array(
'id' => qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION,
'label' => qa_lang( 'sss_lang/choose_share_type_for_w_desktop' ),
'type' => 'select',
'value' => qa_opt( qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION ),
'tags' => 'name="' . qa_sss_opt::SHARE_TYPE_WIDGET_DESKTOP_OPTION . '"',
'options' => $social_share_types,
'match_by' => 'key',
);
}
/**
* @param $social_share_types
*
* @return array
*/
public function get_share_type_w_mobile_button( $social_share_types )
{
return array(
'id' => qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION,
'label' => qa_lang( 'sss_lang/choose_share_type_for_w_mobile' ),
'type' => 'select',
'value' => qa_opt( qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION ),
'tags' => 'name="' . qa_sss_opt::SHARE_TYPE_WIDGET_MOBILE_OPTION . '"',
'options' => $social_share_types,
'match_by' => 'key',
);
}
/**
* @return array
*/
public function get_custom_css_field()
{
return array(
'id' => qa_sss_opt::CUSTOM_CSS,
'label' => qa_lang( 'sss_lang/custom_css' ),
'type' => 'textarea',
'rows' => 6,
'value' => qa_opt( qa_sss_opt::CUSTOM_CSS ),
'tags' => 'name="' . qa_sss_opt::CUSTOM_CSS . '"',
);
}
/**
* @return array
*/
public function get_enable_opengraph_support_field()
{
return array(
'id' => qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT,
'label' => ami_social_share_lang( 'enable_opengraph_support' ),
'type' => 'checkbox',
'value' => (int) qa_opt( qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT ),
'tags' => 'name="' . qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT . '"',
);
}
/**
* @return array
*/
public function get_facebook_app_id_field()
{
return array(
'id' => qa_sss_opt::FACEBOOK_APP_ID,
'label' => ami_social_share_lang( 'facebook_app_id' ),
'value' => qa_html( qa_opt( qa_sss_opt::FACEBOOK_APP_ID ) ),
'tags' => 'name="' . qa_sss_opt::FACEBOOK_APP_ID . '"',
);
}
/**
* @return array
*/
public function get_twitter_handle_field()
{
return array(
'id' => qa_sss_opt::TWITTER_HANDLE,
'label' => ami_social_share_lang( 'twitter_handle' ),
'value' => qa_html( qa_opt( qa_sss_opt::TWITTER_HANDLE ) ),
'tags' => 'name="' . qa_sss_opt::TWITTER_HANDLE . '"',
);
}
/**
* @return array
*/
public function get_default_image_field()
{
return array(
'id' => qa_sss_opt::DEFAULT_SHARE_IMAGE,
'label' => ami_social_share_lang( 'default_share_image' ),
'value' => qa_html( qa_opt( qa_sss_opt::DEFAULT_SHARE_IMAGE ) ),
'tags' => 'name="' . qa_sss_opt::DEFAULT_SHARE_IMAGE . '"',
);
}
/**
* @return array
*/
public function get_site_description_field()
{
return array(
'id' => qa_sss_opt::WEBSITE_DESCRIPTION,
'label' => ami_social_share_lang( 'website_desc' ),
'type' => 'textarea',
'rows' => 6,
'value' => qa_opt( qa_sss_opt::WEBSITE_DESCRIPTION ),
'tags' => 'name="' . qa_sss_opt::WEBSITE_DESCRIPTION . '"',
);
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/