Plugin Directory

source: left-right-image-slideshow-gallery/trunk/left-right-image-slideshow-gallery.php @ 2827127

Last change on this file since 2827127 was 2651617, checked in by gopiplus, 3 years ago

Tested up to 5.9

File size: 12.3 KB
Line 
1<?php
2/*
3Plugin Name: Left right image slideshow gallery
4Plugin URI: http://www.gopiplus.com/work/2011/04/25/wordpress-plugin-left-right-image-slideshow-gallery/
5Description: Left right image slideshow gallery lets showcase images in a horizontal move style. Single image at a time and pull one by one continually. This slideshow will pause on mouse over. The speed of the plugin gallery is customizable. Persistence of last viewed image supported, so when the user reloads the page, the slideshow continues from the last image.
6Author: Gopi Ramasamy
7Version: 12.0
8Author URI: http://www.gopiplus.com/work/2011/04/25/wordpress-plugin-left-right-image-slideshow-gallery/
9Donate link: http://www.gopiplus.com/work/2011/04/25/wordpress-plugin-left-right-image-slideshow-gallery/
10Tags: image, slideshow, gallery
11License: GPLv2 or later
12License URI: http://www.gnu.org/licenses/gpl-2.0.html
13Text Domain: left-right-image-slideshow-gallery
14Domain Path: /languages
15*/
16
17if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])) { die('You are not allowed to call this page directly.'); }
18
19global $wpdb, $wp_version;
20define("WP_LRISG_TABLE", $wpdb->prefix . "lrisg_plugin");
21define('WP_LRISG_FAV', 'http://www.gopiplus.com/work/2011/04/25/wordpress-plugin-left-right-image-slideshow-gallery/');
22
23if ( ! defined( 'WP_LRISG_BASENAME' ) )
24        define( 'WP_LRISG_BASENAME', plugin_basename( __FILE__ ) );
25       
26if ( ! defined( 'WP_LRISG_PLUGIN_NAME' ) )
27        define( 'WP_LRISG_PLUGIN_NAME', trim( dirname( WP_LRISG_BASENAME ), '/' ) );
28       
29if ( ! defined( 'WP_LRISG_PLUGIN_URL' ) )
30        define( 'WP_LRISG_PLUGIN_URL', WP_PLUGIN_URL . '/' . WP_LRISG_PLUGIN_NAME );
31       
32if ( ! defined( 'WP_LRISG_ADMIN_URL' ) )
33        define( 'WP_LRISG_ADMIN_URL', get_option('siteurl') . '/wp-admin/options-general.php?page=left-right-image-slideshow-gallery' );
34
35function Lrisg() 
36{
37        global $wpdb;
38        $Lrisg_package = "";
39        $Lrisg_title = get_option('Lrisg_title');
40        $Lrisg_width = get_option('Lrisg_width');
41        $Lrisg_height = get_option('Lrisg_height');
42        $Lrisg_pause = get_option('Lrisg_pause');
43        $Lrisg_cycles = get_option('Lrisg_cycles');
44        $Lrisg_persist = get_option('Lrisg_persist');
45        $Lrisg_slideduration = get_option('Lrisg_slideduration');
46        $Lrisg_random = get_option('Lrisg_random');
47        $Lrisg_type = get_option('Lrisg_type');
48       
49        if(!is_numeric($Lrisg_width)) { $Lrisg_width = 250;}
50        if(!is_numeric($Lrisg_height)) { $Lrisg_height = 200; }
51        if(!is_numeric($Lrisg_pause)) { $Lrisg_pause = 2000; }
52        if(!is_numeric($Lrisg_cycles)) { $Lrisg_cycles = 5; }
53        if(!is_numeric($Lrisg_slideduration)) { $Lrisg_slideduration = 300; }
54       
55        $sSql = "select Lrisg_path,Lrisg_link,Lrisg_target,Lrisg_title from ".WP_LRISG_TABLE." where 1=1";
56        if($Lrisg_type <> ""){ $sSql = $sSql . " and Lrisg_type='".$Lrisg_type."'"; }
57        if($Lrisg_random == "YES"){ $sSql = $sSql . " ORDER BY RAND()"; }else{ $sSql = $sSql . " ORDER BY Lrisg_order"; }
58       
59        $data = $wpdb->get_results($sSql);
60       
61        if ( ! empty($data) ) 
62        {
63                foreach ( $data as $data ) 
64                {
65                        $Lrisg_package = $Lrisg_package .'["'.$data->Lrisg_path.'", "'.$data->Lrisg_link.'", "'.$data->Lrisg_target.'"],';
66                }
67                $Lrisg_package = substr($Lrisg_package,0,(strlen($Lrisg_package)-1));
68                ?>
69                <script type="text/javascript">
70                var Lrisg_SlideShow=new Lrisg_Show({
71                        Lrisg_Wrapperid: "Lrisg_widgetss",
72                        Lrisg_WidthHeight: [<?php echo $Lrisg_width; ?>, <?php echo $Lrisg_height; ?>],
73                        Lrisg_ImageArray: [ <?php echo $Lrisg_package; ?> ],
74                        Lrisg_Displaymode: {type:'auto', pause:<?php echo $Lrisg_pause; ?>, cycles:<?php echo $Lrisg_cycles; ?>, pauseonmouseover:true},
75                        Lrisg_Orientation: "h",
76                        Lrisg_Persist: <?php echo $Lrisg_persist; ?>,
77                        Lrisg_Slideduration: <?php echo $Lrisg_slideduration; ?> 
78                })
79                </script>
80                <div id="Lrisg_widgetss" style="max-width:100%"></div>
81                <?php
82        }       
83        else
84        {
85                _e('Please check the widget setting gallery group', 'left-right-image-slideshow-gallery');
86        }
87}
88
89function Lrisg_install() 
90{
91        global $wpdb;
92        if($wpdb->get_var("show tables like '". WP_LRISG_TABLE . "'") != WP_LRISG_TABLE) 
93        {
94                $sSql = "CREATE TABLE IF NOT EXISTS ". WP_LRISG_TABLE . " (";
95                $sSql = $sSql . "Lrisg_id INT NOT NULL AUTO_INCREMENT ,";
96                $sSql = $sSql . "Lrisg_path TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,";
97                $sSql = $sSql . "Lrisg_link TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL ,";
98                $sSql = $sSql . "Lrisg_target VARCHAR( 50 ) NOT NULL ,";
99                $sSql = $sSql . "Lrisg_title VARCHAR( 500 ) NOT NULL ,";
100                $sSql = $sSql . "Lrisg_order INT NOT NULL ,";
101                $sSql = $sSql . "Lrisg_status VARCHAR( 10 ) NOT NULL ,";
102                $sSql = $sSql . "Lrisg_type VARCHAR( 100 ) NOT NULL ,";
103                $sSql = $sSql . "Lrisg_extra1 VARCHAR( 100 ) NOT NULL ,";
104                $sSql = $sSql . "Lrisg_extra2 VARCHAR( 100 ) NOT NULL ,";
105                $sSql = $sSql . "Lrisg_date datetime NOT NULL default '0000-00-00 00:00:00' ,";
106                $sSql = $sSql . "PRIMARY KEY ( Lrisg_id )";
107                $sSql = $sSql . ") ENGINE=MyISAM  DEFAULT CHARSET=utf8;";
108                $wpdb->query($sSql);
109               
110                $IsSql = "INSERT INTO `". WP_LRISG_TABLE . "` (Lrisg_path, Lrisg_link, Lrisg_target, Lrisg_title, Lrisg_order, Lrisg_status, Lrisg_type, Lrisg_date)"; 
111                $sSql = $IsSql . " VALUES ('".WP_LRISG_PLUGIN_URL."/images/250x167_1.jpg', '#', '_blank', 'Image title 1', '1', 'YES', 'Widget', '0000-00-00 00:00:00');";
112                $wpdb->query($sSql);
113                $sSql = $IsSql . " VALUES ('".WP_LRISG_PLUGIN_URL."/images/250x167_2.jpg' ,'#', '_blank', 'Image title 2', '2', 'YES', 'Widget', '0000-00-00 00:00:00');";
114                $wpdb->query($sSql);   
115                $sSql = $IsSql . " VALUES ('".WP_LRISG_PLUGIN_URL."/images/250x167_3.jpg', '#', '_blank', 'Image title 3', '1', 'YES', 'Sample', '0000-00-00 00:00:00');";
116                $wpdb->query($sSql);   
117                $sSql = $IsSql . " VALUES ('".WP_LRISG_PLUGIN_URL."/images/250x167_4.jpg', '#', '_blank', 'Image title 4', '2', 'YES', 'Sample', '0000-00-00 00:00:00');";
118                $wpdb->query($sSql);
119        }
120        add_option('Lrisg_title', "Left right slideshow");
121        add_option('Lrisg_width', "260");
122        add_option('Lrisg_height', "200");
123        add_option('Lrisg_pause', "2000");
124        add_option('Lrisg_cycles', "15");
125        add_option('Lrisg_persist', "true");
126        add_option('Lrisg_slideduration', "300");
127        add_option('Lrisg_random', "NO");
128        add_option('Lrisg_type', "Widget");
129}
130
131function Lrisg_control() 
132{
133        echo '<p><b>';
134         _e('Left right slideshow', 'left-right-image-slideshow-gallery');
135        echo '.</b> ';
136        _e('Check official website for more information', 'left-right-image-slideshow-gallery');
137        ?> <a target="_blank" href="<?php echo WP_LRISG_FAV; ?>"><?php _e('click here', 'left-right-image-slideshow-gallery'); ?></a></p><?php
138}
139
140function Lrisg_widget($args) 
141{
142        extract($args);
143        echo $before_widget . $before_title;
144        echo get_option('Lrisg_Title');
145        echo $after_title;
146        Lrisg();
147        echo $after_widget;
148}
149
150function Lrisg_admin_options() 
151{
152        global $wpdb;
153        $current_page = isset($_GET['ac']) ? $_GET['ac'] : '';
154        switch($current_page)
155        {
156                case 'edit':
157                        include('pages/image-management-edit.php');
158                        break;
159                case 'add':
160                        include('pages/image-management-add.php');
161                        break;
162                case 'set':
163                        include('pages/image-setting.php');
164                        break;
165                default:
166                        include('pages/image-management-show.php');
167                        break;
168        }
169}
170
171add_shortcode( 'lr-slideshow', 'Lrisg_shortcode' );
172
173function Lrisg_shortcode( $atts ) 
174{
175        global $wpdb;
176       
177        $Lrisg_package = "";
178        $Lr = "";
179       
180        //[lr-slideshow type="sample" width="250" height="170" pause="3000" random="YES"]
181        if ( ! is_array( $atts ) ) { return ''; }
182        $Lrisg_type = $atts['type'];
183        $Lrisg_width = $atts['width'];
184        $Lrisg_height = $atts['height'];
185        $Lrisg_pause = $atts['pause'];
186        $Lrisg_random = $atts['random'];
187       
188        $Lrisg_persist = get_option('Lrisg_persist');
189       
190        if($Lrisg_persist == "true")
191        {
192                $Lrisg_persist = "true";
193        }
194        else
195        {
196                $Lrisg_persist = "false";
197        }
198       
199        $Lrisg_cycles = get_option('Lrisg_cycles');
200        $Lrisg_slideduration = get_option('Lrisg_slideduration');
201        if(!is_numeric($Lrisg_width)) { $Lrisg_width = 250 ;}
202        if(!is_numeric($Lrisg_height)) { $Lrisg_height = 200; }
203        if(!is_numeric($Lrisg_cycles)) { $Lrisg_cycles = 5; }
204        if(!is_numeric($Lrisg_slideduration)) { $Lrisg_slideduration = 300; }
205        if(!is_numeric($Lrisg_pause)) { $Lrisg_pause = 2000; }
206       
207        $sSql = "select Lrisg_path,Lrisg_link,Lrisg_target,Lrisg_title from ".WP_LRISG_TABLE." where 1=1";
208        if($Lrisg_type <> ""){ $sSql = $sSql . " and Lrisg_type='".$Lrisg_type."'"; }
209        if($Lrisg_random == "YES"){ $sSql = $sSql . " ORDER BY RAND()"; }else{ $sSql = $sSql . " ORDER BY Lrisg_order"; }
210       
211        $data = $wpdb->get_results($sSql);
212       
213        if ( ! empty($data) ) 
214        {
215                foreach ( $data as $data ) 
216                {
217                        $Lrisg_package = $Lrisg_package .'["'.$data->Lrisg_path.'", "'.$data->Lrisg_link.'", "'.$data->Lrisg_target.'"],';
218                }       
219               
220                $Lrisg_package = substr($Lrisg_package,0,(strlen($Lrisg_package)-1));
221                $type = "auto";
222                $wrapperid = "left" . $Lrisg_type;
223                $Lr = $Lr .'<script type="text/javascript">';
224                $Lr = $Lr .'var Lrisg_SlideShow=new Lrisg_Show({Lrisg_Wrapperid: "'.$wrapperid.'",Lrisg_WidthHeight: ['.$Lrisg_width.', '.$Lrisg_height.'], Lrisg_ImageArray: [ '.$Lrisg_package.' ],Lrisg_Displaymode: {type:"'.$type.'", pause:'.$Lrisg_pause.', cycles:'.$Lrisg_cycles.', pauseonmouseover:true},Lrisg_Orientation: "h",Lrisg_Persist: '.$Lrisg_persist.',Lrisg_Slideduration: '.$Lrisg_slideduration.' })';
225                $Lr = $Lr .'</script>';
226                $Lr = $Lr .'<div id="'.$wrapperid.'"></div>';
227        }       
228        else
229        {
230                $Lr = __('Please check the short code', 'left-right-image-slideshow-gallery');
231        }
232        return $Lr;
233}
234
235function Lrisg_add_to_menu() 
236{
237        if (is_admin()) 
238        {
239                add_options_page(__('Left right image slideshow gallery', 'left-right-image-slideshow-gallery'), 
240                                                        __('Left right slideshow', 'left-right-image-slideshow-gallery'), 'manage_options', 
241                                                                'left-right-image-slideshow-gallery', 'Lrisg_admin_options' );
242        }
243}
244
245function Lrisg_init()
246{
247        if(function_exists('wp_register_sidebar_widget')) 
248        {
249                wp_register_sidebar_widget('left-right-image-slideshow-gallery', __('Left right image slideshow gallery', 'left-right-image-slideshow-gallery'), 'Lrisg_widget');
250        }
251       
252        if(function_exists('wp_register_widget_control')) 
253        {
254                wp_register_widget_control('left-right-image-slideshow-gallery', array(__('Left right image slideshow gallery', 'left-right-image-slideshow-gallery'), 'widgets'), 'Lrisg_control');
255        } 
256}
257
258function Lrisg_deactivation() 
259{
260        // No action required.
261}
262
263function Lrisg_add_javascript_files() 
264{
265        if (!is_admin())
266        {
267                wp_enqueue_script('jquery');
268                wp_enqueue_script( 'left-right-image-slideshow-gallery', WP_LRISG_PLUGIN_URL.'/inc/left-right-image-slideshow-gallery.js');
269        }
270}
271
272function Lrisg_textdomain() 
273{
274          load_plugin_textdomain( 'left-right-image-slideshow-gallery', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
275}
276
277function Lrisg_adminscripts() 
278{
279        if( !empty( $_GET['page'] ) ) 
280        {
281                switch ( $_GET['page'] ) 
282                {
283                        case 'left-right-image-slideshow-gallery':
284                                wp_register_script( 'Lrisg-adminscripts', plugins_url( 'pages/setting.js', __FILE__ ), '', '', true );
285                                wp_enqueue_script( 'Lrisg-adminscripts' );
286                                $Lrisg_select_params = array(
287                                        'Lrisg_path'    => __( 'Please enter the image path.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
288                                        'Lrisg_link'    => __( 'Please enter the target link.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
289                                        'Lrisg_target'  => __( 'Please enter the target option.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
290                                        'Lrisg_order'   => __( 'Please enter the display order, only number.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
291                                        'Lrisg_status'  => __( 'Please select the display status.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
292                                        'Lrisg_type'    => __( 'Please enter the gallery type.', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
293                                        'Lrisg_delete'  => __( 'Do you want to delete this record?', 'Lrisg-select', 'left-right-image-slideshow-gallery' ),
294                                );
295                                wp_localize_script( 'Lrisg-adminscripts', 'Lrisg_adminscripts', $Lrisg_select_params );
296                                break;
297                }
298        }
299}
300
301add_action('plugins_loaded', 'Lrisg_textdomain');
302add_action('wp_enqueue_scripts', 'Lrisg_add_javascript_files');
303add_action("plugins_loaded", "Lrisg_init");
304register_activation_hook(__FILE__, 'Lrisg_install');
305register_deactivation_hook(__FILE__, 'Lrisg_deactivation');
306add_action('admin_menu', 'Lrisg_add_to_menu');
307add_action( 'admin_enqueue_scripts', 'Lrisg_adminscripts' );
308?>
Note: See TracBrowser for help on using the repository browser.