-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslidewizard.php
1063 lines (839 loc) · 31.4 KB
/
slidewizard.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
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
Plugin Name: SlideWizard
Plugin URI: http://colorlabsproject.com/plugins/slidewizard/
Description: SlideWizard helps you to create beautiful slider from various source.
Version: 1.1.3
Author: ColorLabs & Company
Author URI: http://colorlabsproject.com/
Text Domain: slidewizard
*/
/**
* Copyright (c) 2013 ColorLabs & Company. All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* **********************************************************************
*/
/**
* SlideWizard for WordPress
*
* Create awesome slider on your WordPress platform. Manage slide and
* insert them into posts.
*
* @author colorlabs
*/
class SlideWizard {
public $post_type;
public $namespace = "slidewizard";
static $friendly_name = "SlideWizard";
static $version = '1.1.3';
// Environment, 'development' or 'production'
// Don't forget to change back to production
static $env = 'development';
// WordPress Admin panel menu
var $menu = array( );
// Available Sources
var $sources = array( );
// Available Themes
var $themes = array( );
// SlideWizard Sizes
var $sizes = array(
'small' => array(
'label' => "Small",
'width' => 300,
'height' => 300
),
'medium' => array(
'label' => 'Medium',
'width' => 500,
'height' => 500
),
'large' => array(
'label' => 'Large',
'width' => 960,
'height' => 500
),
'custom' => array(
'label' => 'Custom',
'width' => 500,
'height' => 500
)
);
// JavaScript to be run in the footer of the page
var $footer_scripts = "";
// Styles to override slidewizard themes
var $footer_styles = "";
// Array of themes that need loading on a page
var $themes_included = array();
var $sources_included = array();
var $slidewizard_ids = array();
/**
* Constructor method
*
*/
function __construct() {
SlideWizard::load_constant();
/**
* Make this plugin available for translation.
* Translations can be added to the /languages/ directory.
*/
load_plugin_textdomain( $this->namespace, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// SlideWizard Themes primary class
include_once (SLIDEWIZARD_PLUGIN_DIR . '/classes/slidewizard-themes.php');
$this->Themes = new SlideWizardThemes();
include_once (SLIDEWIZARD_PLUGIN_DIR . '/classes/slidewizard-themes-helper.php');
// Primary Class for SlideWizard Slides
include_once (SLIDEWIZARD_PLUGIN_DIR . '/classes/slidewizard-slides.php');
// Template function helper
include_once( dirname( __FILE__ ) . '/includes/template-functions.php' );
// Get All Available Themes
$themes_files = (array) glob( SLIDEWIZARD_PLUGIN_DIR . '/themes/*/themes.php' );
foreach( $themes_files as $filename ) {
if( is_readable( $filename ) ) {
include_once( $filename );
$slug = basename( dirname( $filename ) );
$classname = slidewizard_get_classname_from_filename( dirname( $filename ) );
$prefix_classname = "SlideWizardThemes_{$classname}";
if( class_exists( $prefix_classname ) ) {
$this->themes[$slug] = new $prefix_classname;
}
}
}
// Get All Available sources
$source_files = (array) glob( SLIDEWIZARD_PLUGIN_DIR . '/sources/*/source.php' );
foreach( (array) $source_files as $filename ) {
if( is_readable( $filename ) ) {
include_once ($filename);
$slug = basename( dirname( $filename ) );
$classname = slidewizard_get_classname_from_filename( dirname( $filename ) );
$prefix_classname = "SlideWizardSource_{$classname}";
if( class_exists( $prefix_classname ) ) {
$this->sources[$slug] = new $prefix_classname;
}
}
}
$this->Slides = new Slides();
$this->add_hooks();
}
/**
* Initialization function to hook into the WordPress init action
*
* Instantiates the class on a global variable and sets the class, actions
* etc. up for use.
*/
static function instance( ) {
global $SlideWizard;
// Only instantiate the Class if it hasn't been already
if( !isset( $SlideWizard ) )
$SlideWizard = new SlideWizard();
}
/**
* Add in various hooks
*
* Place all add_action, add_filter, add_shortcode hook-ins here
*/
function add_hooks( ) {
// Add page custom options page
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
// Register all JavaScript files used by this plugin
add_action( 'init', array( &$this, 'wp_register_scripts' ), 1 );
// Register all Stylesheets used by this plugin
add_action( 'init', array( &$this, 'wp_register_styles' ), 1 );
// Add custom post type
add_action( 'init', array( &$this, 'register_post_types' ) );
// Route requests for form processing
add_action( 'init', array( &$this, 'route' ) );
// Hook into slidewizard source control
add_action( "{$this->namespace}_source_control", array( &$this, 'slidewizard_source_control' ) );
// Enqueue javascripts and stylesheets on specific page
add_action( 'admin_print_scripts-toplevel_page_' . SLIDEWIZARD_PLUGIN_NAME, array( &$this, 'admin_print_scripts' ) );
add_action( 'admin_print_styles-toplevel_page_' . SLIDEWIZARD_PLUGIN_NAME, array( &$this, 'admin_print_styles' ) );
// AJAX Action Hooks
add_action( "wp_ajax_{$this->namespace}_source-modal", array( &$this, 'ajax_source_modal' ) );
add_action( "wp_ajax_{$this->namespace}_delete-slide", array( &$this, 'ajax_delete_slide' ) );
add_action( "wp_ajax_{$this->namespace}_preview-iframe", array( &$this, 'ajax_preview_iframe' ) );
add_action( "wp_ajax_{$this->namespace}_preview-iframe-update", array( &$this, 'ajax_preview_iframe_update' ) );
add_action( "wp_ajax_{$this->namespace}_get_theme_options", array( &$this, 'ajax_get_theme_options' ) );
add_action( "wp_ajax_{$this->namespace}_insert-iframe", array( &$this, 'ajax_insert_iframe' ) );
// Front-end only actions
if( !is_admin() ) {
// Pre-loading for themes use by SlideWizard in post or page
add_action( 'wp', array( &$this, 'wp_hook' ) );
// Print required themes stylesheets
add_action( 'wp_print_styles', array( &$this, 'wp_print_styles' ) );
}
// Append scripts for slidewizard initiation at the footer
add_action( 'wp_print_footer_scripts', array( &$this, 'print_footer_scripts' ) );
// Add required JavaScripts and Stylesheets for displaying SlideWizards in front-end
add_action( 'wp_print_scripts', array( &$this, 'wp_print_scripts' ) );
// Add SlideWizard shortcode
add_shortcode( 'slidewizard', array( &$this, 'shortcode' ) );
add_action( "media_buttons", array( &$this, "media_button" ), 19 );
// Add SlideWizard Documentation
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'slidewizard_action_links' ) );
// Hook when plugin activated
register_activation_hook( __FILE__, array( &$this, 'activate' ) );
}
/**
* Add SlideWizard button editor
*
*/
function media_button() {
global $post;
if( in_array( basename( $_SERVER['PHP_SELF'] ), array( 'post-new.php', 'page-new.php', 'post.php', 'page.php' ) ) ) {
echo '<a href="'. $this->get_insert_iframe_url() .'" class="button thickbox add-slidewizard" id="add-slidewizard" title="' . esc_attr__( 'Insert your SlideWizard', $this->namespace ) . '" onclick="return false;">'. __('Insert SlideWizard', $this->namespace) .'</a>';
}
}
/**
* Register custom post type for slide and custom slide
*
*/
public function register_post_types() {
register_post_type( SLIDEWIZARD_POST_TYPE,
array(
'labels' => array(
'name' => 'slidewizard',
'singular_name' => __( 'SlideWizard', $this->namespace )
),
// 'public' => true,
)
);
register_post_type( SLIDEWIZARD_SLIDE_POST_TYPE,
array(
'labels' => array(
'name' => 'slidewizard_slide',
'singular_name' => __( 'SlideWizard Slide', $this->namespace )
),
// 'public' => true
)
);
}
/**
* Register javascript for enqueueing elsewhere
*
*/
public function wp_register_scripts() {
// Twitter bootstrap javascript plugin
wp_register_script( 'bootstrap', SLIDEWIZARD_PLUGIN_URL . "/js/bootstrap" . (SLIDEWIZARD_ENV == 'development' ? '.dev' : '') . '.js', array('jquery'), '2.2.2', true);
// SlideWizard Admin Script
wp_register_script( 'slidewizard-admin-script', SLIDEWIZARD_PLUGIN_URL . "/js/slidewizard-admin-script.js", array('jquery', 'bootstrap'), SLIDEWIZARD_VERSION);
// SlideWizard Admin Preview Script
wp_register_script( 'slidewizard-admin-preview', SLIDEWIZARD_PLUGIN_URL . "/js/slidewizard-admin-preview.js", array('jquery', 'bootstrap'), SLIDEWIZARD_VERSION);
// SlideWizard Insert Slide
wp_register_script( 'slidewizard-insert-slide', SLIDEWIZARD_PLUGIN_URL . "/js/slidewizard-insert-slide.js", array('jquery'), SLIDEWIZARD_VERSION);
// CarouFredSel Script
wp_register_script( 'slidewizard-caroufredsel', SLIDEWIZARD_PLUGIN_URL . "/js/jquery.carouFredSel-6.1.0.js", array( 'jquery' ), '6.1.0' );
}
/**
* Register stylesheets for enqueueing elsewhere
*
*/
public function wp_register_styles() {
// Twitter bootstrap style
wp_register_style( 'bootstrap', SLIDEWIZARD_PLUGIN_URL . "/css/bootstrap" . (SLIDEWIZARD_ENV == 'development' ? '.dev' : '') . '.css', array(), '2.2.2' );
// SlideWizard Admin Style
wp_register_style( "slidewizard-admin-style", SLIDEWIZARD_PLUGIN_URL . "/css/slidewizard-admin-style.css" , array(), SLIDEWIZARD_VERSION );
// SlideWizard base styles for front-end
wp_register_style( "slidewizard-base", SLIDEWIZARD_PLUGIN_URL . "/css/slidewizard-base.css", array(), SLIDEWIZARD_VERSION );
}
/**
* Determine which slidewizard are being loaded in this page
*
*/
function wp_hook() {
global $posts;
if( isset( $posts ) && !empty( $posts ) ) {
$this->slidewizard_ids = array();
// SlideWizard being loaded with iframe=1
$iframe_slidewizards = array();
// Process through $posts for the existence of SlideWizards
foreach( (array) $posts as $post ) {
$matches = array( );
preg_match_all( '/\[slidewizard( ([a-zA-Z0-9]+)\=\'?\"?([a-zA-Z0-9\%\-_\.]+)\'?\"?)*\]/', $post->post_content, $matches );
if( !empty( $matches[0] ) ) {
foreach( $matches[0] as $match ) {
$str = $match;
$str_pieces = explode( " ", $str );
foreach( $str_pieces as $piece ) {
$attrs = explode( "=", $piece );
if( $attrs[0] == "id" ) {
// Add the ID of this SlideWizard to the ID array for loading
$this->slidewizard_ids[] = intval( str_replace( "\"", '', $attrs[1] ) );
// Check for iframe = 1, yes, true
if( preg_match( "/(iframe)=('|\")?(1|yes|true)('|\")?/", $str, $matches ) ) {
$iframe_slidewizards[] = $attrs[1];
}
}
}
}
}
}
if( !empty( $this->slidewizard_ids ) ) {
// Load SlideWizards used on this URL passing the array of IDs
$slidewizards = $this->Slides->get( $this->slidewizard_ids );
// Loop through SlideWizard used on this page and add their themes
// to the $themes_included array for later use
foreach( (array) $slidewizards as $slidewizard ) {
// Only queue assets to be loaded if the SlideWizard is not being loaded via iframe
if( !in_array( $slidewizard['id'], $iframe_slidewizards ) ) {
$themes_slug = isset( $slidewizard['themes'] ) && !empty( $slidewizard['themes'] ) ? $slidewizard['themes'] : 'default';
$this->themes_included[$themes_slug] = true;
foreach( $slidewizard['source'] as $source ) {
$this->sources_included[$source] = true;
}
}
}
}
}
}
function slidewizard_action_links( $links ) {
$plugin_links = array(
'<a href="http://colorlabsproject.com/documentation/slidewizard/" target="_blank">' . __( 'Documentation' ) . '</a>'
);
return array_merge( $plugin_links, $links );
}
/**
* Load javascripts for slidewizard options page
*
*/
public function admin_print_scripts() {
wp_enqueue_script( 'jquery-ui-slider' );
wp_enqueue_script( 'bootstrap' );
wp_enqueue_script( 'slidewizard-admin-script' );
wp_enqueue_script( 'slidewizard-admin-preview' );
// Create object for text that generated with javascript, so it's
// still translateable
$translate_message = array(
'confirm_delete' => __("Are you sure you want to delete this slide? This can't be undone.", $this->namespace),
'use_slide' => __("Copy & Paste this shortcode into your post or page", $this->namespace)
);
wp_localize_script( 'slidewizard-admin-script', "{$this->namespace}_message", $translate_message );
}
/**
* Load stylesheets for slidewizard options page
*
*/
public function admin_print_styles() {
wp_enqueue_style( 'bootstrap' );
wp_enqueue_style( 'slidewizard-admin-style' );
// Only load this only when on SlideWizard page
if( $this->is_plugin() ) {
if( isset( $_GET['id'] ) ) {
$slidewizard = $this->Slides->get( $_GET['id'] );
$themes = $slidewizard['themes'];
} else {
$themes = SLIDEWIZARD_DEFAULT_THEMES;
}
$this->themes_included = array( $themes => 1 );
}
}
/**
* Load javascripts required by SlideWizard on front-end
*
*/
function wp_print_scripts() {
foreach( (array) $this->themes_included as $themes_slug => $val ) {
wp_enqueue_script( "{$this->namespace}-themes-js-{$themes_slug}" );
}
}
/**
* Load stylesheet required by SlideWizard on front-end
*
*/
function wp_print_styles() {
foreach( (array) $this->themes_included as $themes_slug => $val ) {
wp_enqueue_style( "{$this->namespace}-themes-{$themes_slug}" );
}
}
/**
* Print javascript at the footer
*
*/
function print_footer_scripts() {
echo $this->footer_scripts;
}
/**
* Load Constant
*
* Conveninece function to load the constants files for the
* activation and construct
*/
public function load_constant() {
if( !defined( 'SLIDEWIZARD_PLUGIN_NAME' ) ) define('SLIDEWIZARD_PLUGIN_NAME', trim(dirname(plugin_basename(__FILE__)), '/'));
require_once (dirname( __FILE__ ) . '/includes/constants.php');
}
/**
* Add options page for configuration
*
*/
public function admin_menu() {
$show_menu = true;
if( !current_user_can( 'manage_options' ) ) {
$show_menu = false;
}
// If user role can manage options
if( $show_menu === true ) {
$hook = add_menu_page( 'Manage SlideWizard', 'SlideWizard', 'publish_posts', SLIDEWIZARD_PLUGIN_NAME, array( &$this, 'page_route' ), plugin_dir_url( __FILE__ )."images/menu-icon.png", 40 );
// Hook into admin color scheme
add_action('admin_print_scripts-' . $hook, array( $this, 'add_admin_color_schemes' ));
}
}
/**
* Admin Color Schemes
*/
public function add_admin_color_schemes() {
global $_wp_admin_css_colors;
$current_scheme = get_user_option('admin_color');
$text_color = $_wp_admin_css_colors[ $current_scheme ]->icon_colors['base'];
$text_current = $_wp_admin_css_colors[ $current_scheme ]->icon_colors['current'];
if('light'==$current_scheme){
$base_color = $_wp_admin_css_colors[ $current_scheme ]->colors[0];
$highlight_color = $_wp_admin_css_colors[ $current_scheme ]->colors[1];
$text_color = '#333';
$text_current = '#FFF';
}elseif('blue'==$current_scheme){
$base_color = $_wp_admin_css_colors[ $current_scheme ]->colors[2];
$highlight_color = $_wp_admin_css_colors[ $current_scheme ]->colors[0];
}elseif('midnight'==$current_scheme){
$base_color = $_wp_admin_css_colors[ $current_scheme ]->colors[1];
$highlight_color = $_wp_admin_css_colors[ $current_scheme ]->colors[3];
}else{
$base_color = $_wp_admin_css_colors[ $current_scheme ]->colors[1];
$highlight_color = $_wp_admin_css_colors[ $current_scheme ]->colors[2];
}
if('fresh'==$current_scheme){
$base_color = '#0099CC';
$text_color = '#FFFFFF';
}
echo '<style>';
echo '.slidewizard-topblock, .slidewizard-form-header, .slidewizard-footnote, .slidewizard-modal .modal-header,.save-buttons { background-color: '. $base_color .' }';
echo '.slidewizard-topblock h1 a, .slidewizard-modal .modal-header { color: '. $text_color .'; }';
echo '.source-icon, .slidewizard-source-config .popover-title { background-color: '. $highlight_color .' }';
echo '.slidewizard-source-config.popover .arrow { border-bottom-color: '. $highlight_color .' }';
echo '.ui-tooltip, .arrow::after{ border-top-color: '. $text_color .' }';
if('fresh'==$current_scheme){
echo '.wp-core-ui .button-primary {background-color: #FFB101;border-color: #DA903B;box-shadow:0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 0 rgba(255, 255, 255, 0.6) inset}';
echo '.wp-core-ui .button-primary:hover{background-color: #FFCA00;border-color: #DA903B;box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2), 0 1px 0 0 rgba(255, 255, 255, 0.6) inset;}';
}elseif('light'==$current_scheme){
echo '.slidewizard-topblock h1 a, .slidewizard-modal .modal-header, .slidewizard-topblock .slidewizard-version, .slidewizard-footnote a, .slidewizard-footnote{ color:#333; }';
}
echo '</style>';
}
/**
* SlideWizard Page Router
*
* Check "action" parameter and determine what page will be shown
*
*/
public function page_route() {
$action = array_key_exists( 'action', $_REQUEST ) ? $_REQUEST['action'] : "";
switch( $action ) {
// Create new slide
case "create":
$this->page_create_edit();
break;
// Edit existing slide
case "edit":
$this->page_create_edit();
break;
// SlideWizard Dashboard Page
default:
$this->page_dasboard();
break;
}
}
/**
* SlideWizard Dashboard page
*
*/
public function page_dasboard() {
$slidewizards = $this->Slides->get(null, 'publish');
// Render the Dashboard views
include (SLIDEWIZARD_PLUGIN_DIR . '/views/dashboard.php');
}
/**
* SlideWizard Create and Edit page
*
*/
public function page_create_edit() {
$form_action = "create";
if( isset( $_REQUEST['id'] ) ) {
$form_action = "edit";
}
$sources = $this->get_sources();
$namespace = $this->namespace;
// Redirect to dashboard if invalid source was specified
if( $form_action == "create" ) {
$source = $_REQUEST['source'];
if( !is_array( $source ) )
$source = array( $source );
$source_intersect = array_intersect( $source, array_keys( $sources ) );
if( !isset( $_REQUEST['source'] ) OR empty( $source_intersect ) ) {
echo '<script type="text/javascript">document.location.href="'. $this->action() .'"</script>';
}
}
// If user editing a slide
if( $form_action == 'edit' ) {
$slidewizard = $this->Slides->get( $_REQUEST['id'] );
} else {
$slidewizard = $this->Slides->create( $source );
}
// Options
$options = $this->get_options( $slidewizard );
// Get Size
$sizes = apply_filters( "{$this->namespace}_sizes", $this->sizes, $slidewizard );
$slidewizard_dimensions = $this->get_dimensions( $slidewizard );
// Get Themes
$themes = $this->get_slidewizard_themes( $slidewizard );
// Render views
include (SLIDEWIZARD_PLUGIN_DIR . '/views/slide-form.php');
}
/**
* This function will handling routing of form submissions to the appropriate
* form processor.
*
*/
public function route() {
$uri = $_SERVER['REQUEST_URI'];
$protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';
$hostname = $_SERVER['HTTP_HOST'];
$url = "{$protocol}://{$hostname}{$uri}";
$is_post = (bool)(strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST");
$nonce = isset( $_REQUEST['_wpnonce'] ) ? $_REQUEST['_wpnonce'] : false;
// Check if wp nonce exists
if( $nonce ) {
// Handle Post Request
if( $is_post ) {
// Create or edit slide
if( wp_verify_nonce( $nonce, "{$this->namespace}-create-slidewizard" ) ||
wp_verify_nonce( $nonce, "{$this->namespace}-edit-slidewizard" ) ) {
$this->save();
}
}
}
}
/**
* Form processor for saving Slide
*
*/
public function save() {
if( !isset( $_POST['id'] ) ) {
return false;
}
$slide_id = intval( $_POST['id'] );
$slidewizard = $this->Slides->save( $slide_id, $_POST );
$action = '&action=edit&id=' . $slide_id;
if( $_POST['action'] == "create" ) {
$action .= '&firstsave=1';
}
wp_redirect( $this->action( $action ) );
exit ;
}
/**
* Render Source control at top of the slide creation form
*
* @param obj $slidewizard Slide Object
*
*/
function slidewizard_source_control($slidewizard) {
$namespace = $this->namespace;
$sources = $this->get_sources( $slidewizard['source'] );
$slide_id = $slidewizard['id'];
include( SLIDEWIZARD_PLUGIN_DIR . '/views/partials/_source.php' );
}
/**
* Ajax Source Modal
*
* This modal will be shown when Create Slide button clicked
*/
public function ajax_source_modal() {
$sources = $this->get_sources();
$namespace = $this->namespace;
$title = "Choose a source to create new Slider";
$action = "create";
include (SLIDEWIZARD_PLUGIN_DIR . "/views/partials/_source-modal.php");
exit;
}
/**
* Action for deleting SlideWizard
*
*/
public function ajax_delete_slide() {
$nonce = $_REQUEST['nonce'];
$id = $_REQUEST['id'];
if( wp_verify_nonce( $nonce, "{$this->namespace}_delete_slide" ) ) {
$this->Slides->delete( $id );
}
exit;
}
/**
* Ajax action for preview slide within iframe
*
*/
function ajax_preview_iframe() {
global $wp_scripts, $wp_styles;
$slide_id = $_GET['id'];
if( isset( $_GET['width'] ) && is_numeric( $_GET['width'] ) )
$width = $_GET['width'];
if( isset( $_GET['height'] ) && is_numeric( $_GET['height'] ) )
$height = $_GET['height'];
if( isset( $_GET['outer_width'] ) && is_numeric( $_GET['outer_width'] ) )
$outer_width = $_GET['outer_width'];
if( isset( $_GET['outer_height'] ) && is_numeric( $_GET['outer_height'] ) )
$outer_height = $_GET['outer_height'];
$slidewizard = $this->Slides->get( $slide_id );
$themes = $this->Themes->get( $slidewizard['themes'] );
$namespace = $this->namespace;
$scripts = apply_filters( "{$this->namespace}_iframe_scripts", array( 'jquery', 'slidewizard-caroufredsel' ), $slidewizard );
$content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
$base_url = !site_url( ) ? wp_guess_url( ) : site_url( );
include (SLIDEWIZARD_PLUGIN_DIR . '/views/preview-iframe.php');
exit;
}
/**
* Ajax action for getting a new preview URL in an iframe
*
*/
function ajax_preview_iframe_update() {
$slide_id = intval( $_REQUEST['id'] );
$response = $this->_save_autodraft( $slide_id, $_REQUEST );
header( "Content-Type: application/json" );
die( json_encode( $response ) );
}
/**
* Ajax action for showing list of created SlideWizard
*
*/
function ajax_insert_iframe() {
global $wp_scripts;
$namespace = $this->namespace;
$scripts = array( 'jquery', 'slidewizard-insert-slide' );
$content_url = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
$base_url = !site_url( ) ? wp_guess_url( ) : site_url( );
$slidewizards = $this->Slides->get(null, 'publish');
include ( SLIDEWIZARD_PLUGIN_DIR . '/views/insert-slidewizard.php' );
exit;
}
/**
* Ajax action for receiving options for specific SlideWizard Themes
*/
function ajax_get_theme_options() {
$slide_id = intval( $_REQUEST['id'] );
$slidewizard = $this->Slides->save_preview( $slide_id, $_REQUEST );
$sizes = apply_filters( "{$this->namespace}_sizes", $this->sizes, $slidewizard );
$themes = $this->get_slidewizard_themes( $slidewizard );
$options = $this->get_options( $slidewizard );
include( SLIDEWIZARD_PLUGIN_DIR . "/views/partials/_options.php" );
exit;
}
/**
* Get all available sources
*
*/
public function get_sources( $source_slugs = array() ) {
$sources = $this->sources;
if( !empty( $source_slugs ) ) {
if( !is_array( $source_slugs ) ) {
$source_slugs = array( $source_slugs );
}
$filtered_sources = array( );
foreach( $sources as $source_name => $source_object ) {
if( in_array( $source_name, $source_slugs ) ) {
$filtered_sources[$source_name] = $source_object;
}
}
$sources = $filtered_sources;
}
return $sources;
}
/**
* Get available Themes
*
* @param array $slidewizard SlideWizard data
* @return array
*/
public function get_slidewizard_themes( $slidewizard ) {
$themes = $this->Themes->get();
$filtered = array();
foreach( $themes as $theme ) {
$themes_intersect = array_intersect( (array)$slidewizard['source'], $theme['meta']['sources'] );
if( !empty( $themes_intersect ) ) {
$filtered[] = $theme;
}
}
$themes = $filtered;
return $themes;
}
/**
* Get Options
*
* @param array $slidewizard Array containing information about
* the Slide
*/
public function get_options( $slidewizard ) {
$options = apply_filters("{$this->namespace}_slide_options", $this->Slides->options, $slidewizard );
return $options;
}
/**
* Fired when the plugin is activated.
*
*/
public function activate() {
$this->register_plugin_version();
// Register plugin version
if( SLIDEWIZARD_VERSION != '' ) {
update_option( "{$this->namespace}_version", SLIDEWIZARD_VERSION);
}
}
/**
* Get the URL for the specified plugin action
*
* @param object $str [optional] Expects the handle passed in the menu
* definition
*
* @return The absolute URL to the plugin action specified
*/
function action( $str = "" ) {
$path = admin_url( "admin.php?page=" . SLIDEWIZARD_PLUGIN_NAME );
if( !empty( $str ) ) {
return $path . $str;
} else {
return $path;
}
}
/**
* Function to check if we are viewing SlideWizard plugin page
*
* @return boolean
*/
function is_plugin() {
global $pagenow;
$is_plugin = false;
if( !function_exists( 'get_current_screen' ) )
return false;
$screen_id = get_current_screen( );
if( empty( $screen_id ) )
return false;
if( isset( $screen_id->id ) )
$is_plugin = (boolean) in_array( $screen_id->id, array_values( $this->menu ) );
return $is_plugin;
}
/**
* SlideWizard shortcode
*
* @param array $atts shortcode options
*/
function shortcode( $atts ) {
global $post;
// if( isset( $atts['id'] ) && !empty( $atts['id'] ) )
// Filter shortoce attributes
$atts = apply_filters( "{$this->namespace}_shortcode_atts", $atts );
extract( shortcode_atts( array(
'id' => (boolean) false,
'width' => null,
'height' => null,
// 'iframe' => (boolean) false,
'preview' => (boolean) false,
), $atts ) );
if( $id !== false ) {
return $this->Slides->render( $id, $preview );
} else {
return "";
}
}
/**
* Get SlideWizard dimensions
*
* @return array
*/
function get_dimensions( $slidewizard ) {
$dimensions = array( );
$sizes = apply_filters( "{$this->namespace}_sizes", $this->sizes, $slidewizard );
$dimensions['width'] = $slidewizard['options']['size'] != "custom" ? $sizes[$slidewizard['options']['size']]['width'] : $slidewizard['options']['width'];
$dimensions['height'] = $slidewizard['options']['size'] != "custom" ? $sizes[$slidewizard['options']['size']]['height'] : $slidewizard['options']['height'];
$dimensions['outer_width'] = $dimensions['width'];
$dimensions['outer_height'] = $dimensions['height'];
do_action_ref_array( "{$this->namespace}_dimensions", array( &$dimensions['width'], &$dimensions['height'], &$dimensions['outer_width'], &$dimensions['outer_height'], &$slidewizard ) );
return $dimensions;
}
/**
* Get Iframe URL for inserting SlideWizard to the post or page
*/
function get_insert_iframe_url() {
global $post;
$url = admin_url( "admin-ajax.php?action={$this->namespace}_insert-iframe&post_id={$post->ID}&TB_iframe=1&width=640&height=515" );
return $url;
}
/**
* Get Iframe URL
*
*/
function get_iframe_url( $slide_id, $width, $height, $preview = false ) {
$slidewizard = $this->Slides->get( $slide_id );
if( empty( $slidewizard ) )
return '';
$slidewizard_dimensions = $this->get_dimensions( $slidewizard );
if( !$preview ) $uniqid = strtotime( $slidewizard['updated_at'] );
if( !isset( $width ) )
$width = $slidewizard_dimensions['width'];