Plugin Directory

Changeset 1264133


Ignore:
Timestamp:
10/12/2015 02:53:39 PM (10 years ago)
Author:
s_ruben
Message:
  • The image banners can be displayed without "width" and "height" attributes, so they can be made responsive.
  • Polish translation is added.
Location:
useful-banner-manager/trunk
Files:
16 added
4 deleted
18 edited

Legend:

Unmodified
Added
Removed
  • useful-banner-manager/trunk/readme.txt

    r946808 r1264133  
    44Tags: banner manager, ads manager, banner, banners, ads, advertisement, buddypress
    55Requires at least: 3.0
    6 Tested up to: 3.9.1
     6Tested up to: 4.3.1
    77
    88This banner manager plugin helps to manage the banners easily over the WordPress blog. It works with BuddyPress too.
     
    1919* Español - Thanks to Maria Ramos from [Webhostinghub.com](http://webhostinghub.com/)
    2020* Français - Thanks to Therese Lachance
     21* Polski - Thanks to Michał Rybak [mrybak.pl](http://mrybak.pl/)
    2122
    2223[Plugin Homepage](http://rubensargsyan.com/wordpress-plugin-useful-banner-manager)
     
    5051== Changelog ==
    5152
     53= 1.6 =
     54* The image banners can be displayed without "width" and "height" attributes, so they can be made responsive.
     55* Polish translation is added.
     56
    5257= 1.5 =
    5358* The conflict with qTranslate plugin is solved.
  • useful-banner-manager/trunk/scripts.js

    r946808 r1264133  
    11jQuery( document ).ready( function( $ ) {
    2     $.each( $( '.useful_banner_manager_banners_rotation' ), function() {
    3         if ( $( this ).find( '.useful_banner_manager_rotating_banner' ).length > 1 ) {
     2    $.each( $( '.ubm_banners_rotation' ), function() {
     3        if ( $( this ).find( '.ubm_rotating_banner' ).length > 1 ) {
    44            var banners_rotation_block = $( this );
    55            var interval = 1000 + $( this ).data( 'interval' );
    66
    7             setTimeout( function() { useful_banner_manager_rotate_banners( banners_rotation_block, interval ) }, interval );
     7            setTimeout( function() { ubm_rotate_banners( banners_rotation_block, interval ) }, interval );
    88        }
    99    } );
     
    1111} );
    1212
    13 function useful_banner_manager_rotate_banners( banners_rotation_block, interval ) {
     13function ubm_rotate_banners( banners_rotation_block, interval ) {
    1414    jQuery ( function( $ ) {
    15         $.each( $( banners_rotation_block ).find( '.useful_banner_manager_rotating_banner' ), function() {
     15        $.each( $( banners_rotation_block ).find( '.ubm_rotating_banner' ), function() {
    1616            if ( $( this ).css( 'display' ) != 'none' ) {
    1717                if ( $( this ).next().html() != null ) {
     
    2222                    } );
    2323                } else {
    24                     $( banners_rotation_block ).find( '.useful_banner_manager_rotating_banner:last' ).fadeOut( 1000, function() {
    25                         var next_banner_id = $( banners_rotation_block ).find( '.useful_banner_manager_rotating_banner:first' ).data( 'banner-id' );
     24                    $( banners_rotation_block ).find( '.ubm_rotating_banner:last' ).fadeOut( 1000, function() {
     25                        var next_banner_id = $( banners_rotation_block ).find( '.ubm_rotating_banner:first' ).data( 'banner-id' );
    2626
    27                         $( banners_rotation_block ).find( '.useful_banner_manager_rotating_banner:first' ).fadeIn( 1000 );
     27                        $( banners_rotation_block ).find( '.ubm_rotating_banner:first' ).fadeIn( 1000 );
    2828                    } );
    2929                }
     
    3232    } );
    3333
    34     setTimeout( function() { useful_banner_manager_rotate_banners( banners_rotation_block, interval ) }, interval );
     34    setTimeout( function() { ubm_rotate_banners( banners_rotation_block, interval ) }, interval );
    3535}
  • useful-banner-manager/trunk/tinymce/window.php

    r868786 r1264133  
    44}
    55
    6 global $wpdb, $useful_banner_manager_plugin_url, $useful_banner_manager_table_name;
     6global $wpdb, $ubm_plugin_url;
    77
    8 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     8@ header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
    99
    10 $banners = $wpdb->get_results( "SELECT id, banner_name, banner_type, banner_title FROM " . $useful_banner_manager_table_name . " WHERE is_visible='yes' ORDER BY id;" );
     10$banners = $wpdb->get_results( "SELECT id, banner_name, banner_type, banner_title FROM " . $wpdb->ubm_banners . " WHERE is_visible='yes' ORDER BY id;" );
    1111?>
    1212<html>
     
    1515    <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php echo( get_option( 'blog_charset' ) ); ?>" />
    1616    <script language="javascript" type="text/javascript" src="<?php echo( site_url() ); ?>/wp-includes/js/tinymce/tiny_mce_popup.js"></script>
    17     <script language="javascript" type="text/javascript" src="<?php echo(  $useful_banner_manager_plugin_url ); ?>tinymce/tinymce.js"></script>
     17    <script language="javascript" type="text/javascript" src="<?php echo(  $ubm_plugin_url ); ?>tinymce/tinymce.js"></script>
    1818</head>
    1919<body class="useful_banner_manager_tinymce_window" id="link" onload="tinyMCEPopup.executeOnLoad('init();');document.body.style.display='';" style="display: none">
     
    2121    if ( empty( $banners ) ) {
    2222        ?>
    23         <p><?php _e( 'There is no visible banner.', 'useful-banner-manager' ); ?> <a href="admin.php?page=useful-banner-manager/useful-banner-manager-banners.php"><?php _e( 'Add Banners', 'useful-banner-manager' ); ?></a></p>
     23        <p><?php _e( 'There is no visible banner.', 'useful-banner-manager' ); ?> <a href="admin.php?page=useful-banner-manager/banners.php"><?php _e( 'Add Banners', 'useful-banner-manager' ); ?></a></p>
    2424        <?php
    2525    } else {
  • useful-banner-manager/trunk/useful-banner-manager.php

    r946808 r1264133  
    33Plugin Name: Useful Banner Manager
    44Plugin URI: http://rubensargsyan.com/wordpress-plugin-useful-banner-manager/
    5 Description: This banner manager plugin helps to manage the banners easily over the WordPress blog. It works with BuddyPress too. <a href="admin.php?page=useful-banner-manager/useful-banner-manager-banners.php">Banner Manager</a>
    6 Version: 1.5
     5Description: This banner manager plugin helps to manage the banners easily over the WordPress blog. It works with BuddyPress too. <a href="admin.php?page=useful-banner-manager/banners.php">Banner Manager</a>
     6Version: 1.6
    77Author: Ruben Sargsyan
    88Author URI: http://rubensargsyan.com/
    99*/
    1010
    11 /*  Copyright 2014 Ruben Sargsyan (email: [email protected])
     11/*  Copyright 2015 Ruben Sargsyan (email: [email protected])
    1212
    1313    This program is free software; you can redistribute it and/or modify
     
    2525*/
    2626
    27 $useful_banner_manager_plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) );
    28 $useful_banner_manager_plugin_title = 'Useful Banner Manager';
    29 $useful_banner_manager_plugin_prefix = 'useful_banner_manager_';
    30 $useful_banner_manager_table_name = $wpdb->prefix . 'useful_banner_manager_banners';
     27$ubm_plugin_url = WP_PLUGIN_URL . '/' . str_replace( basename( __FILE__ ), '', plugin_basename( __FILE__ ) );
     28$ubm_plugin_prefix = 'ubm_';
    3129
    32 add_action( 'init', 'useful_banner_manager_init' );
     30require_once dirname( __FILE__ ) . '/classes/classes.php';
     31require_once dirname( __FILE__ ) . '/includes/hooks.php';
     32require_once dirname( __FILE__ ) . '/includes/widgets.php';
    3333
    34 function useful_banner_manager_init() {
    35    if ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) {
    36        if ( get_user_option( 'rich_editing' ) == 'true' ) {
    37           add_filter( 'mce_external_plugins', 'useful_banner_manager_add_plugin' );
    38           add_filter( 'mce_buttons', 'useful_banner_manager_register_button' );
    39        }
    40    }
     34function ubm_add_banner( $data ) {
     35    global $ubm_banners;
     36
     37    $id = $ubm_banners->add_banner( $data );
     38
     39    return $id;
    4140}
    4241
    43 add_action( 'plugins_loaded', 'useful_banner_manager_load' );
     42function ubm_update_banner( $id, $data ) {
     43    global $ubm_banners;
    4444
    45 function useful_banner_manager_load() {
    46     global $wpdb;
    47 
    48     $useful_banner_manager_table_name = $wpdb->prefix . 'useful_banner_manager_banners';
    49     $useful_banner_manager_plugin_prefix = 'useful_banner_manager_';
    50     $useful_banner_manager_version = '1.5';
    51 
    52     $charset_collate = '';
    53 
    54     if ( $wpdb->has_cap( 'collation' ) ) {
    55         if ( ! empty( $wpdb->charset ) ) {
    56             $charset_collate = "DEFAULT CHARACTER SET " . $wpdb->charset;
    57         }
    58 
    59         if ( ! empty( $wpdb->collate ) ) {
    60             $charset_collate .= " COLLATE " . $wpdb->collate;
    61         }
    62     }
    63 
    64     require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    65 
    66     if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $useful_banner_manager_table_name . "'") != $useful_banner_manager_table_name ) {
    67         $create_useful_banner_manager_table = "CREATE TABLE " . $useful_banner_manager_table_name . "(" .
    68             "id INT(11) NOT NULL auto_increment," .
    69             "banner_name VARCHAR(255) NOT NULL," .
    70             "banner_type VARCHAR(4) NOT NULL," .
    71             "banner_title VARCHAR(255) NOT NULL," .
    72             "banner_alt TEXT NOT NULL," .
    73             "banner_link VARCHAR(255) NOT NULL," .
    74             "link_target VARCHAR(7) NOT NULL," .
    75             "link_rel VARCHAR(8) NOT NULL," .
    76             "banner_width INT(11) NOT NULL," .
    77             "banner_height INT(11) NOT NULL," .
    78             "added_date VARCHAR(10) NOT NULL," .
    79             "active_until VARCHAR(10) NOT NULL," .
    80             "banner_order INT(11) NOT NULL DEFAULT 0," .
    81             "is_visible VARCHAR(3) NOT NULL," .
    82             "banner_added_by VARCHAR(50) NOT NULL," .
    83             "banner_edited_by TEXT NOT NULL," .
    84             "last_edited_date VARCHAR(10) NOT NULL," .
    85             "PRIMARY KEY (id)) $charset_collate;";
    86 
    87         dbDelta( $create_useful_banner_manager_table );
    88     }
    89 
    90     $current_version = get_option( 'useful_banner_manager_version');
    91 
    92     if ( $current_version < '1.3' ) {
    93         $create_useful_banner_manager_not_exists_fields = "ALTER TABLE " . $useful_banner_manager_table_name . " ADD wrapper_id VARCHAR(255) NOT NULL AFTER banner_order, ADD wrapper_class VARCHAR(255) NOT NULL AFTER wrapper_id";
    94 
    95         $wpdb->query( $create_useful_banner_manager_not_exists_fields );
    96     }
    97 
    98     if ( $current_version == '1.0' ) {
    99         $create_useful_banner_manager_not_exists_fields = "ALTER TABLE " . $useful_banner_manager_table_name . " ADD banner_alt TEXT NOT NULL AFTER banner_title, ADD link_rel VARCHAR(8) NOT NULL AFTER link_target";
    100 
    101         $wpdb->query( $create_useful_banner_manager_not_exists_fields );
    102 
    103         update_option( 'useful_banner_manager_version', $useful_banner_manager_version );
    104     } elseif ( $current_version < $useful_banner_manager_version ) {
    105         update_option( 'useful_banner_manager_version', $useful_banner_manager_version );
    106     } elseif ( $current_version === false ) {
    107         add_option( 'useful_banner_manager_version', $useful_banner_manager_version );
    108     }
    109 
    110     $upload_dir = wp_upload_dir();
    111 
    112     if ( ! file_exists( $upload_dir['basedir'] . '/useful_banner_manager_banners' ) ) {
    113         @ mkdir( $upload_dir['basedir'] . '/useful_banner_manager_banners' );
    114     }
    115 
    116     load_plugin_textdomain( 'useful-banner-manager', false, 'useful-banner-manager/languages' );
     45    $ubm_banners->update_banner( $id, $data );
    11746}
    11847
    119 add_action( 'admin_menu', 'useful_banner_manager_menu' );
     48function ubm_delete_banner( $id ){
     49    global $ubm_banners;
    12050
    121 function useful_banner_manager_menu() {
    122     if ( function_exists ( 'add_menu_page' ) ) {
    123         add_menu_page( __( 'Banners', 'useful-banner-manager' ), __( 'Banner Manager', 'useful-banner-manager' ), 'manage_options', 'useful-banner-manager/useful-banner-manager-banners.php' );
    124     }
     51    $ubm_banners->delete_banner( $id );
    12552}
    12653
    127 function useful_banner_manager_add_banner( $banner_data ) {
    128     global $wpdb, $useful_banner_manager_table_name;
     54function ubm_get_banners(){
     55    global $ubm_banners;
    12956
    130     $data = array(
    131         'banner_name'       => $banner_data['banner_name'],
    132         'banner_type'       => $banner_data['banner_type'],
    133         'banner_title'      => $banner_data['banner_title'],
    134         'banner_alt'        => $banner_data['banner_alt'],
    135         'banner_link'       => $banner_data['banner_link'],
    136         'link_target'       => $banner_data['link_target'],
    137         'link_rel'          => $banner_data['link_rel'],
    138         'banner_width'      => $banner_data['banner_width'],
    139         'banner_height'     => $banner_data['banner_height'],
    140         'added_date'        => $banner_data['added_date'],
    141         'active_until'      => $banner_data['active_until'],
    142         'banner_order'      => $banner_data['banner_order'],
    143         'wrapper_id'        => $banner_data['wrapper_id'],
    144         'wrapper_class'     => $banner_data['wrapper_class'],
    145         'is_visible'        => $banner_data['is_visible'],
    146         'banner_added_by'   => $banner_data['banner_added_by']
    147     );
    148 
    149     $wpdb->insert( $useful_banner_manager_table_name, $data );
    150 
    151     $banner_id = $wpdb->insert_id;
    152 
    153     return $banner_id;
    154 }
    155 
    156 function useful_banner_manager_update_banner( $banner_id, $banner_data ) {
    157     global $wpdb, $useful_banner_manager_table_name;
    158 
    159     $data = array(
    160         'banner_name'       => $banner_data['banner_name'],
    161         'banner_type'       => $banner_data['banner_type'],
    162         'banner_title'      => $banner_data['banner_title'],
    163         'banner_alt'        => $banner_data['banner_alt'],
    164         'banner_link'       => $banner_data['banner_link'],
    165         'link_target'       => $banner_data['link_target'],
    166         'link_rel'          => $banner_data['link_rel'],
    167         'banner_width'      => $banner_data['banner_width'],
    168         'banner_height'     => $banner_data['banner_height'],
    169         'active_until'      => $banner_data['active_until'],
    170         'banner_order'      => $banner_data['banner_order'],
    171         'wrapper_id'        => $banner_data['wrapper_id'],
    172         'wrapper_class'     => $banner_data['wrapper_class'],
    173         'is_visible'        => $banner_data['is_visible'],
    174         'banner_edited_by'  => $banner_data['banner_edited_by'],
    175         'last_edited_date'  => $banner_data['last_edited_date']
    176     );
    177 
    178     $where = array(
    179         'id'  => $banner_id
    180     );
    181 
    182     $wpdb->update( $useful_banner_manager_table_name, $data, $where );
    183 }
    184 
    185 function useful_banner_manager_delete_banner( $banner_id ){
    186     global $wpdb, $useful_banner_manager_table_name;
    187 
    188     $banner = $wpdb->get_row( "SELECT banner_name,banner_type FROM " . $useful_banner_manager_table_name . " WHERE id=" . $banner_id . ";" );
    189 
    190     $wpdb->query( "DELETE FROM " . $useful_banner_manager_table_name . " WHERE id=" . $banner_id . ";" );
    191 
    192     $upload_dir = wp_upload_dir();
    193 
    194     if ( file_exists( $upload_dir['basedir'] . '/useful_banner_manager_banners/' . $banner_id . '-' . $banner->banner_name . '.' . $banner->banner_type ) ) {
    195         unlink( $upload_dir['basedir'] . '/useful_banner_manager_banners/' . $banner_id . '-' . $banner->banner_name . '.' . $banner->banner_type );
    196     }
    197 }
    198 
    199 function useful_banner_manager_get_banners(){
    200     global $wpdb, $useful_banner_manager_table_name;
    201 
    202     $banners = $wpdb->get_results( "SELECT * FROM " . $useful_banner_manager_table_name . " ORDER BY id;" );
     57    $banners = $ubm_banners->get_banners();
    20358
    20459    return $banners;
    20560}
    20661
    207 function useful_banner_manager_get_banner( $banner_id ) {
    208     global $wpdb, $useful_banner_manager_table_name;
     62function ubm_get_banner( $id ) {
     63    global $ubm_banners;
    20964
    210     $banner = $wpdb->get_row( "SELECT * FROM " . $useful_banner_manager_table_name . " WHERE id='" . $banner_id . "';" );
     65    $banner = $ubm_banners->get_banner( $id );
    21166
    21267    return $banner;
    21368}
    21469
    215 function useful_banner_manager_get_available_years(){
    216     global $wpdb, $useful_banner_manager_table_name;
     70function ubm_display_banner( $banner ) {
     71    global $ubm_banners;
    21772
    218     $available_years = array();
    219 
    220     $earliest_date = $wpdb->get_var( "SELECT MIN(added_date) as earliest_date FROM " . $useful_banner_manager_table_name . ";" );
    221 
    222     if ( ! is_null( $earliest_date ) ){
    223         $earliest_date = substr( $earliest_date, 0, 4 );
    224 
    225         for ( $i = date( 'Y' ); $i >= $earliest_date; $i-- ) {
    226             $available_years[] = $i;
    227         }
    228     }
    229 
    230 
    231     return $available_years;
     73    $ubm_banners->display_banner( $banner );
    23274}
    23375
    234 function useful_banner_manager_display_banner( $banner ) {
    235     global $useful_banner_manager_plugin_url;
     76function ubm_set_rotation_number( $number ) {
     77    global $ubm_banners;
    23678
    237     $upload_dir = wp_upload_dir();
    238     ?>
    239     <div<?php if ( ! empty( $banner->wrapper_id ) ) { echo( ' id="' . $banner->wrapper_id . '"' ); } ?> class="useful_banner_manager_banner<?php if ( ! empty( $banner->wrapper_class ) ) { echo( ' ' . $banner->wrapper_class ); } ?>">
    240     <?php
    241     if ( $banner->banner_type == 'swf' ) {
    242         ?>
    243         <object width="<?php echo( $banner->banner_width ); ?>" height="<?php echo( $banner->banner_height ); ?>">
    244             <param name="movie" value="<?php echo( $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type ); ?>" />
    245             <param name="wmode" value="transparent">
    246             <embed src="<?php echo( $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type ); ?>" width="<?php echo( $banner->banner_width ); ?>" height="<?php echo( $banner->banner_height ); ?>" wmode="transparent"></embed>
    247         </object>
    248         <?php
    249     } else {
    250         if ( $banner->banner_link != '' ) {
    251         ?>
    252             <a href="<?php echo( $banner->banner_link ); ?>" target="<?php echo( $banner->link_target ); ?>" rel="<?php echo( $banner->link_rel ); ?>">
    253         <?php
    254         }
    255     ?>
    256         <img src="<?php echo( $upload_dir['baseurl'] ); ?>/useful_banner_manager_banners/<?php echo( $banner->id . '-' . $banner->banner_name ); ?>.<?php echo( $banner->banner_type ); ?>" width="<?php echo( $banner->banner_width ); ?>" height="<?php echo( $banner->banner_height ); ?>" alt="<?php echo( $banner->banner_alt ); ?>" />
    257         <?php
    258         if ( $banner->banner_link != '' ) {
    259         ?>
    260             </a>
    261         <?php
    262         }
    263     }
    264     ?>
    265     </div>
    266     <?php
     79    $ubm_banners->set_rotation_number( $number );
    26780}
    26881
    269 class Useful_Banner_Manager_Widget extends WP_Widget {
    270      function Useful_Banner_Manager_Widget() {
    271         $widget_opions = array(
    272             'classname'     => 'useful_banner_manager_widget',
    273             'description'   => 'UBM banners'
    274         );
     82function ubm_get_rotation_number() {
     83    global $ubm_banners;
    27584
    276         $this->WP_Widget( 'useful-banner-manager-banners', 'UBM banners', $widget_opions );
    277      }
     85    $rotation_number = $ubm_banners->get_rotation_number();
    27886
    279      function widget( $args, $instance ) {
    280         global $wpdb, $useful_banner_manager_table_name;
    281 
    282         extract( $args );
    283 
    284         $title = $instance['title'];
    285         $banners_ids = $instance['banners_ids'];
    286         $count = $instance['count'];
    287 
    288         echo( $before_widget );
    289 
    290         if ( ! empty( $title ) ) {
    291             echo( $before_title . $title . $after_title );
    292         }
    293 
    294         if ( ! empty( $banners_ids ) ) {
    295             $banners = $wpdb->get_results( "SELECT * FROM (SELECT * FROM " . $useful_banner_manager_table_name . " WHERE id IN (" .implode( ',', $banners_ids ) . ") AND (active_until=-1 OR active_until>='" . date( 'Y-m-d' ) . "') AND is_visible='yes' ORDER BY RAND() LIMIT " . $count . ") as banners ORDER BY banner_order DESC;" );
    296 
    297             foreach ( $banners as $banner ) {
    298                 useful_banner_manager_display_banner( $banner );
    299             }
    300         }
    301 
    302         echo( $after_widget );
    303      }
    304 
    305      function update( $new_instance, $old_instance ) {
    306         $instance = $old_instance;
    307         $instance['title'] = esc_attr( $new_instance['title'] );
    308         $instance['banners_ids'] = isset( $new_instance['banners_ids'] ) ? $new_instance['banners_ids'] : '';
    309 
    310         if ( is_numeric( $new_instance['count'] ) && $new_instance['count'] > 0 ) {
    311             $instance['count'] = $new_instance['count'];
    312         } elseif( is_numeric( $old_instance['count'] ) && $old_instance['count'] > 0 ) {
    313             $instance['count'] = $old_instance['count'];
    314         }else{
    315             $instance['count'] = 1;
    316         }
    317 
    318         return $instance;
    319      }
    320 
    321      function form( $instance ) {
    322         global $wpdb, $useful_banner_manager_table_name;
    323 
    324         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'banners_ids' => '', 'count' => 1 ) );
    325         $title = esc_attr( $instance['title'] );
    326         $banners_ids = $instance['banners_ids'];
    327 
    328         if ( $instance['count'] ) {
    329             $count = intval( $instance['count'] );
    330         }else{
    331             $count = 1;
    332         }
    333 
    334         $banners = $wpdb->get_results( "SELECT id, banner_name, banner_type, banner_title FROM " . $useful_banner_manager_table_name . " WHERE is_visible='yes' ORDER BY id;" );
    335 
    336         if ( empty( $banners ) ) {
    337             ?>
    338             <p><?php _e( 'There is no visible banner.', 'useful-banner-manager' ); ?> <a href="admin.php?page=useful-banner-manager/useful-banner-manager-banners.php"><?php _e( 'Add Banners', 'useful-banner-manager' ); ?></a></p>
    339             <?php
    340         } else {
    341             ?>
    342             <p><label><?php _e( 'Title:', 'useful-banner-manager' ); ?> <input class="widefat" name="<?php echo( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo( esc_attr( $title ) ); ?>" /></label></p>
    343             <table width="100%" style="border-collapse: collapse">
    344                 <caption><?php _e( 'Banners', 'useful-banner-manager' ); ?></caption>
    345                 <?php
    346                 foreach ( $banners as $banner ) {
    347                 ?>
    348                     <tr><td width="90%" style="border: 1px solid #f1f1f1; text-align: left; padding: 2px 5px"><label for="<?php echo( $this->get_field_id( 'banners_ids' ) ); ?>_<?php echo( $banner->id ); ?>"><?php echo( $banner->banner_title ); ?></label></td><td width="10%" style="border: 1px solid #f1f1f1; text-align: center; padding: 2px 0"><input class="checkbox" id="<?php echo( $this->get_field_id( 'banners_ids' ) ); ?>_<?php echo( $banner->id ); ?>" name="<?php echo( $this->get_field_name( 'banners_ids' ) ); ?>[]" type="checkbox" value="<?php echo( $banner->id ); ?>" <?php if ( is_array( $banners_ids ) ){ if( in_array( $banner->id, $banners_ids ) ) { echo( 'checked="checked"' ); } } ?> /></td></tr>
    349                 <?php
    350                 }
    351                 ?>
    352             </table><br />
    353             <p><label><?php _e( 'Number of banners to show:', 'useful-banner-manager' ); ?> <input name="<?php echo( $this->get_field_name( 'count' ) ); ?>" type="text" value="<?php echo( esc_attr( $count ) ); ?>" size="2" /></label></p>
    354         <?php
    355         }
    356     }
     87    return $rotation_number;
    35788}
    35889
    359 class Useful_Banner_Manager_Rotation_Widget extends WP_Widget {
    360      function Useful_Banner_Manager_Rotation_Widget() {
    361         $widget_opions = array(
    362             'classname'     => 'useful_banner_manager_rotation_widget',
    363             'description'   => 'UBM banners rotation'
    364         );
    365 
    366         $this->WP_Widget( 'useful-banner-manager-banners-rotation', 'UBM banners rotation', $widget_opions );
    367      }
    368 
    369      function widget( $args, $instance ) {
    370         global $wpdb, $useful_banner_manager_table_name, $useful_banner_manager_plugin_url;
    371 
    372         extract( $args );
    373 
    374         $title = $instance['title'];
    375         $banners_ids = $instance['banners_ids'];
    376         $interval = $instance['interval'];
    377         $width = $instance['width'];
    378         $height = $instance['height'];
    379 
    380         if ( $instance['orderby'] == 'rand' ) {
    381             $orderby = 'RAND()';
    382         } else {
    383             $orderby = 'banner_order, id DESC';
    384         }
    385 
    386         echo( $before_widget );
    387 
    388         if ( ! empty( $title ) ) {
    389             echo( $before_title . $title . $after_title );
    390         }
    391 
    392         if ( ! empty( $banners_ids ) ) {
    393             $upload_dir = wp_upload_dir();
    394 
    395             $banners = $wpdb->get_results( "SELECT * FROM " . $useful_banner_manager_table_name . " WHERE id IN (" . implode( ',', $banners_ids ) . ") AND (active_until=-1 OR active_until>='" . date( 'Y-m-d' ) . "') AND is_visible='yes' ORDER BY " . $orderby . ";" );
    396             ?>
    397             <div id="<?php echo( $args['widget_id'] ); ?>" data-interval="<?php echo( ( $interval * 1000 ) ); ?>" class="useful_banner_manager_banners_rotation" style="overflow: hidden; width: <?php echo( $width ); ?>px; height: <?php echo( $height ); ?>px;">
    398             <?php
    399             $first_banner = true;
    400 
    401             foreach ( $banners as $banner ) {
    402                 ?>
    403                 <div id="<?php echo( $banner->id ); ?>_useful_banner_manager_banner" class="useful_banner_manager_rotating_banner"<?php if ( $first_banner ) { $first_banner = false; } else { echo( ' style="display: none"' ); } ?>>
    404                     <?php
    405                     if ( $banner->banner_link != '' ) {
    406                     ?>
    407                         <a href="<?php echo( $banner->banner_link ); ?>" target="<?php echo( $banner->link_target ); ?>" rel="<?php echo( $banner->link_rel ); ?>">
    408                     <?php
    409                     }
    410                     ?>
    411                     <img src="<?php echo( $upload_dir['baseurl'] ); ?>/useful_banner_manager_banners/<?php echo( $banner->id . '-' . $banner->banner_name ); ?>.<?php echo( $banner->banner_type ); ?>" width="<?php echo( $width ); ?>" height="<?php echo( $height ); ?>" alt="<?php echo( $banner->banner_alt ); ?>" />
    412                     <?php
    413                     if ( $banner->banner_link != '' ) {
    414                     ?>
    415                         </a>
    416                     <?php
    417                     }
    418                     ?>
    419                 </div>
    420                 <?php
    421             }
    422             ?>
    423             </div>
    424             <?php
    425         }
    426 
    427         echo( $after_widget );
    428      }
    429 
    430      function update( $new_instance, $old_instance ) {
    431         $instance = $old_instance;
    432         $instance['title'] = esc_attr( $new_instance['title'] );
    433         $instance['banners_ids'] = isset( $new_instance['banners_ids'] ) ? $new_instance['banners_ids'] : '';
    434 
    435         if ( is_numeric( $new_instance['interval'] ) && $new_instance['interval'] > 0 ) {
    436             $instance['interval'] = $new_instance['interval'];
    437         } elseif ( is_numeric( $old_instance['interval'] ) && $old_instance['interval'] > 0 ) {
    438             $instance['interval'] = $old_instance['interval'];
    439         }else{
    440             $instance['interval'] = 10;
    441         }
    442 
    443         if ( is_numeric( $new_instance['width'] ) && $new_instance['width'] > 0 ) {
    444             $instance['width'] = $new_instance['width'];
    445         } elseif ( is_numeric( $old_instance['width'] ) && $old_instance['width'] > 0 ) {
    446             $instance['width'] = $old_instance['width'];
    447         }else{
    448             $instance['width'] = 180;
    449         }
    450 
    451         if ( is_numeric( $new_instance['height'] ) && $new_instance['height'] > 0 ) {
    452             $instance['height'] = $new_instance['height'];
    453         } elseif ( is_numeric( $old_instance['height'] ) && $old_instance['height'] > 0 ) {
    454             $instance['height'] = $old_instance['height'];
    455         }else{
    456             $instance['height'] = 180;
    457         }
    458 
    459         if ( isset( $new_instance['orderby'] ) && $new_instance['orderby'] == 'rand' ) {
    460             $instance['orderby'] = 'rand';
    461         }else{
    462             $instance['orderby'] = 'banner_order, id';
    463         }
    464 
    465         return $instance;
    466      }
    467 
    468      function form( $instance ) {
    469         global $wpdb, $useful_banner_manager_table_name;
    470 
    471         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'banners_ids' => '', 'orderby' => 'banner_order, id' ) );
    472         $title = esc_attr( $instance['title'] );
    473         $banners_ids = $instance['banners_ids'];
    474 
    475         if ( empty( $instance['interval'] ) ) {
    476             $interval =  10;
    477         }else{
    478             $interval =  intval( $instance['interval'] );
    479         }
    480 
    481         if ( empty( $instance['width'] ) ) {
    482             $width =  180;
    483         }else{
    484             $width =  intval( $instance['width'] );
    485         }
    486 
    487         if ( empty( $instance['height'] ) ) {
    488             $height =  180;
    489         }else{
    490             $height =  intval( $instance['height'] );
    491         }
    492 
    493         $banners = $wpdb->get_results( "SELECT id, banner_title FROM " . $useful_banner_manager_table_name . " WHERE is_visible='yes' AND banner_type!='swf' ORDER BY id;" );
    494 
    495         if ( empty( $banners ) ) {
    496         ?>
    497             <p><?php _e( 'There is no visible banner.', 'useful-banner-manager' ); ?> <a href="admin.php?page=useful-banner-manager/useful-banner-manager-banners.php"><?php _e( 'Add Banners', 'useful-banner-manager' ); ?></a></p>
    498         <?php
    499         } else {
    500             ?>
    501             <p><label><?php _e( 'Title:', 'useful-banner-manager' ); ?> <input class="widefat" id="<?php echo( $this->get_field_id( 'title' ) ); ?>" name="<?php echo( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo( esc_attr( $title ) ); ?>" /></label></p>
    502             <table width="100%" style="border-collapse: collapse">
    503                 <caption><?php _e( 'Banners', 'useful-banner-manager' ); ?></caption>
    504                 <?php
    505                 foreach ( $banners as $banner ) {
    506                     ?>
    507                     <tr><td width="90%" style="border: 1px solid #f1f1f1; text-align: left; padding: 2px 5px"><label for="<?php echo( $this->get_field_id( 'banners_ids' ) ); ?>_<?php echo( $banner->id ); ?>"><?php echo( $banner->banner_title ); ?></label></td><td width="10%" style="border: 1px solid #f1f1f1; text-align: center; padding: 2px 0"><input class="checkbox" id="<?php echo( $this->get_field_id( 'banners_ids' ) ); ?>_<?php echo( $banner->id ); ?>" name="<?php echo( $this->get_field_name( 'banners_ids' ) ); ?>[]" type="checkbox" value="<?php echo( $banner->id ); ?>" <?php if ( is_array( $banners_ids ) ) { if ( in_array( $banner->id, $banners_ids ) ) { echo( 'checked="checked"' ); } } ?> /></td></tr>
    508                 <?php
    509                 }
    510                 ?>
    511             </table>
    512             <br />
    513             <p><label><?php _e( 'Interval:', 'useful-banner-manager' ); ?> <input name="<?php echo( $this->get_field_name( 'interval' ) ); ?>" type="text" value="<?php echo( esc_attr( $interval ) ); ?>" size="2" /></label> <?php _e( 'seconds', 'useful-banner-manager' ); ?></p>
    514             <p><label><?php _e( 'Width of rotating banners:', 'useful-banner-manager' ); ?> <input name="<?php echo( $this->get_field_name( 'width' ) ); ?>" type="text" value="<?php echo( esc_attr( $width ) ); ?>" size="2" /></label><?php _e( 'px', 'useful-banner-manager' ); ?></p>
    515             <p><label><?php _e( 'Height of rotating banners:', 'useful-banner-manager' ); ?> <input name="<?php echo( $this->get_field_name( 'height' ) ); ?>" type="text" value="<?php echo( esc_attr( $height ) ); ?>" size="2" /></label><?php _e( 'px', 'useful-banner-manager' ); ?></p>
    516             <p><label><?php _e( 'Order by rand:', 'useful-banner-manager' ); ?> <input class="checkbox" name="<?php echo( $this->get_field_name( 'orderby' ) ); ?>" type="checkbox" value="rand" <?php if ( $instance['orderby'] == 'rand' ) { echo( 'checked="checked"' ); } ?> /></label></p>
    517             <?php
    518         }
    519      }
    520 }
    521 
    522 add_action( 'widgets_init', 'useful_banner_manager_widget_init' );
    523 
    524 function useful_banner_manager_widget_init() {
    525     if ( ! is_blog_installed() ) {
    526         return;
    527     }
    528 
    529     register_widget( 'Useful_Banner_Manager_Widget' );
    530     register_widget( 'Useful_Banner_Manager_Rotation_Widget' );
    531 }
    532 
    533 $banners_rotation_id = 1;
    534 
    535 add_shortcode( 'useful_banner_manager', 'add_useful_banner_manager_banners' );
    536 
    537 function add_useful_banner_manager_banners( $atts ) {
    538     global $wpdb, $useful_banner_manager_table_name, $useful_banner_manager_plugin_url;
    539 
    540     if ( empty( $atts['banners'] ) ) {
    541         $banners_ids_where = '';
    542     } else {
    543         $banners_ids = explode( ',', $atts['banners'] );
    544 
    545         $banners_ids_where = "id IN (" . implode( ',', $banners_ids ) . ") AND ";
    546     }
    547 
    548     if ( empty( $atts['count'] ) ) {
    549         $count = 1;
    550     } else {
    551         $count = $atts['count'];
    552     }
    553 
    554     $banners = $wpdb->get_results( "SELECT * FROM (SELECT * FROM ".$useful_banner_manager_table_name." WHERE " . $banners_ids_where . "(active_until=-1 OR active_until>='" . date( 'Y-m-d' ) . "') AND is_visible='yes' ORDER BY RAND() LIMIT " . $count . ") as banners ORDER BY banner_order DESC;" );
    555 
    556     $banners_html = '';
    557 
    558     if( ! empty( $banners ) ) {
    559         $upload_dir = wp_upload_dir();
    560 
    561         foreach ( $banners as $banner ) {
    562             $banners_html .= '<div' . ( ( empty( $banner->wrapper_id ) ) ? '' : ' id="' . $banner->wrapper_id . '"' ) . ' class="useful_banner_manager_banner' . ( ( empty( $banner->wrapper_class ) ) ? '' : ' ' . $banner->wrapper_class ) . '">';
    563 
    564             if ( $banner->banner_type == 'swf' ) {
    565                 $banners_html .= '<object width="' . $banner->banner_width . '" height="' . $banner->banner_height . '">
    566                     <param name="movie" value="' . $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type . '" />
    567                     <param name="wmode" value="transparent">
    568                     <embed src="' . $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type . '" width="' . $banner->banner_width . '" height="' . $banner->banner_height . '" wmode="transparent"></embed>
    569                 </object>';
    570             } else {
    571                 if ( $banner->banner_link != '' ) {
    572                     $banners_html .= '<a href="' . $banner->banner_link . '" target="' . $banner->link_target . '" rel="' . $banner->link_rel . '">';
    573                 }
    574 
    575                 $banners_html .= '<img src="' . $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type . '" width="' . $banner->banner_width . '" height="' . $banner->banner_height . '" alt="' . $banner->banner_alt . '" />';
    576 
    577                 if ( $banner->banner_link != '' ) {
    578                     $banners_html .= '</a>';
    579                 }
    580             }
    581 
    582             $banners_html .= '</div>';
    583         }
    584     }
    585 
    586     return $banners_html;
    587 }
    588 
    589 add_shortcode( 'useful_banner_manager_banner_rotation', 'add_useful_banner_manager_banners_rotation' );
    590 
    591 function add_useful_banner_manager_banners_rotation( $atts ) {
    592     global $wpdb, $useful_banner_manager_table_name, $useful_banner_manager_plugin_url, $banners_rotation_id;
    593 
    594     if ( empty( $atts['banners'] ) ) {
    595         $banners_ids_where = '';
    596     } else {
    597         $banners_ids = explode( ',', $atts['banners'] );
    598 
    599         $banners_ids_where = "id IN (" . implode( ',', $banners_ids ) . ") AND ";
    600     }
    601 
    602     if ( empty( $atts['interval'] ) ) {
    603         $interval = 10;
    604     } else {
    605         $interval = $atts['interval'];
    606     }
    607 
    608     if ( empty( $atts['width'] ) ) {
    609         $width = 180;
    610     } else {
    611         $width = $atts['width'];
    612     }
    613 
    614     if ( empty( $atts['height'] ) ) {
    615         $height = 180;
    616     } else {
    617         $height = $atts['height'];
    618     }
    619 
    620     if ( ! empty( $atts['orderby'] ) && $atts['orderby'] == 'rand' ) {
    621         $orderby = 'RAND()';
    622     }else{
    623         $orderby = 'banner_order, id DESC';
    624     }
    625 
    626     $banners = $wpdb->get_results( "SELECT * FROM (SELECT * FROM ".$useful_banner_manager_table_name." WHERE " . $banners_ids_where . "(active_until=-1 OR active_until>='" . date( 'Y-m-d' ) . "') AND banner_type!='swf' AND is_visible='yes' ORDER BY " . $orderby . ") as banners ORDER BY banner_order DESC;" );
    627 
    628     $banners_rotation_html = '';
    629 
    630     if( ! empty( $banners ) ){
    631         $upload_dir = wp_upload_dir();
    632 
    633         $banners_rotation_html = '<div id="useful-banner-manager-banners-rotation-n' . $banners_rotation_id . '" data-interval="' . ( $interval * 1000 ) . '" class="useful_banner_manager_banners_rotation" style="overflow: hidden; width: ' . $width . 'px; height: ' . $height . 'px;">';
    634 
    635         $first_banner = true;
    636 
    637         foreach ( $banners as $banner ) {
    638             $banners_rotation_html .= '<div id="' . $banner->id . '_useful_banner_manager_banner" class="useful_banner_manager_rotating_banner"';
    639 
    640             if ( $first_banner ) {
    641                 $first_banner = false;
    642             } else {
    643                 $banners_rotation_html .= ' style="display: none"';
    644             }
    645 
    646             $banners_rotation_html .= '>';
    647 
    648             if ( $banner->banner_link != '' ) {
    649                 $banners_rotation_html .= '<a href="' . $banner->banner_link . '" target="' . $banner->link_target . '" rel="' . $banner->link_rel . '">';
    650             }
    651 
    652             $banners_rotation_html .= '<img src="' . $upload_dir['baseurl'] . '/useful_banner_manager_banners/' . $banner->id . '-' . $banner->banner_name . '.' . $banner->banner_type . '" width="' . $width . '" height="' . $height . '" alt="' . $banner->banner_alt . '" />';
    653 
    654             if ( $banner->banner_link != '' ) {
    655                 $banners_rotation_html .= '</a>';
    656             }
    657 
    658             $banners_rotation_html .= '</div>';
    659         }
    660 
    661         $banners_rotation_html .= '</div>';
    662 
    663         $banners_rotation_id++;
    664     }
    665 
    666     return $banners_rotation_html;
    667 }
    668 
    669 function useful_banner_manager_banners( $banners = '', $count = '' ) {
    670     echo( do_shortcode( '[useful_banner_manager' . ( ( empty( $banners ) ) ? '' : ' banners=' . $banners ) . ( ( empty( $count ) ) ? '' : ' count=' . $count ) . ']' ) );
    671 }
    672 
    673 function useful_banner_manager_banners_rotation( $banners = '', $interval = '', $width = '', $height = '', $orderby = '' ){
    674     echo( do_shortcode( '[useful_banner_manager_banner_rotation' . ( ( empty( $banners ) ) ? '' : ' banners=' . $banners ) . ( ( empty( $interval ) ) ? '' : ' interval=' . $interval ) . ( ( empty( $width ) ) ? '' : ' width=' . $width ) . ( ( empty( $height ) ) ? '' : ' height=' . $height ) . ( ( empty( $orderby ) ) ? '' : ' orderby=' . $orderby ) . ']' ) );
    675 }
    676 
    677 function useful_banner_manager_register_button( $buttons ) {
     90function ubm_register_button( $buttons ) {
    67891    array_push( $buttons, 'usefulbannermanager' );
    67992
     
    68194}
    68295
    683 function useful_banner_manager_add_plugin( $plugin_array ) {
    684     global $useful_banner_manager_plugin_url;
     96function ubm_add_plugin( $plugin_array ) {
     97    global $ubm_plugin_url;
    68598
    686     $plugin_array['usefulbannermanager'] = $useful_banner_manager_plugin_url . 'tinymce/useful-banner-manager.js';
     99    $plugin_array['usefulbannermanager'] = $ubm_plugin_url . 'tinymce/useful-banner-manager.js';
    687100
    688101    return $plugin_array;
    689102}
    690103
    691 add_action( 'wp_ajax_useful_banner_manager', 'useful_banner_manager_ajax_tinymce' );
    692 
    693 function useful_banner_manager_ajax_tinymce() {
    694     if ( ! current_user_can( 'edit_pages' ) && ! current_user_can( 'edit_posts' ) ){
    695         return;
    696     }
    697 
    698     include_once( dirname(__FILE__) . '/tinymce/window.php' );
    699 
    700     die();
     104function useful_banner_manager_banners( $banners = '', $count = '' ) {
     105    echo( do_shortcode( '[useful_banner_manager' . ( empty( $banners ) ? '' : ' banners=' . $banners ) . ( empty( $count ) ? '' : ' count=' . $count ) . ']' ) );
    701106}
    702107
    703 add_action( 'wp_enqueue_scripts', 'useful_banner_manager_load_scripts' );
    704 
    705 function useful_banner_manager_load_scripts() {
    706     global $useful_banner_manager_plugin_url;
    707 
    708     wp_enqueue_script( 'jquery' );
    709     wp_enqueue_script( 'useful_banner_manager_scripts', $useful_banner_manager_plugin_url . 'scripts.js', array( 'jquery' ) );
    710 }
    711 
    712 add_action( 'admin_enqueue_scripts', 'useful_banner_manager_load_admin_scripts' );
    713 
    714 function useful_banner_manager_load_admin_scripts( $hook ) {
    715     if ( $hook != 'useful-banner-manager/useful-banner-manager-banners.php' ) {
    716         return;
    717     }
    718 
    719     global $useful_banner_manager_plugin_url;
    720 
    721     wp_enqueue_style( 'jquery-ui', $useful_banner_manager_plugin_url . '/css/jquery-ui.custom.min.css' );
    722 
    723     wp_enqueue_script( 'jquery-ui', $useful_banner_manager_plugin_url . '/javascript/jquery-ui.custom.min.js', array('jquery' ) );
     108function useful_banner_manager_banners_rotation( $banners = '', $interval = '', $width = '', $height = '', $orderby = '' ) {
     109    echo( do_shortcode( '[useful_banner_manager_banner_rotation' . ( empty( $banners ) ? '' : ' banners=' . $banners ) . ( empty( $interval ) ? '' : ' interval=' . $interval ) . ( empty( $width ) ? '' : ' width=' . $width ) . ( empty( $height ) ? '' : ' height=' . $height ) . ( ( empty( $orderby ) ) ? '' : ' orderby=' . $orderby ) . ']' ) );
    724110}
    725111?>
Note: See TracChangeset for help on using the changeset viewer.