, * @copyright Copyright © 2008-2012 Saidmade Srl * */ //mod jrc 070613: my mods (throughout) to ensure plugin admin features (edit, create,delete banners, etc) are ONLY presented to users with (custom) role capability, as configured in (modified) main.h.php (define( 'kWPBannerizeUserCapabilitiy', 'manage_wp_bannerize_banners' )) AND ALSO specified as role capability for user/groups roles via wp admin, roles. 'administrator' role has this new capability added by default. //files changed: wpBannerizeAdmin.php, main.php, main.h.php //my mod mark: 'mod jrc 070613', throughout /** * Outputs the html inline style attribute with display. * * Compares the first two arguments and if not identical marks as display none * * @since 3.0.0 * * @param $display * @param mixed $current (true) The other value to compare if not just true * @param bool $echo Whether to echo or just return the string * * @internal param mixed $checked One of the values to compare * @return string html attribute or empty string */ function hidden( $display, $current = true, $echo = true ) { if ( (string)$display !== (string)$current ) { $result = " style='display:none'"; } else { $result = ''; } if ( $echo ) { echo $result; } return $result; } class WPBannerizeAdmin extends WPBannerizeClass { var $pageMain; var $pageAddBanner; var $pageSettings; var $pageTools; /** * Keep the default CSS sample rules * * @var string */ var $cssRulesSample = ''; function WPBannerizeAdmin( $__file__ ) { $this->__construct( $__file__); } function __construct( $__file__ ) { // super parent::WPBannerizeClass( $__file__ ); // Foo string for PoEdit $foo_publish = __( 'Publish', 'wp-bannerize' ); //$this->init(); add_action( 'plugins_loaded', array( $this, 'init' ), 1 ); } /** * Init the default plugin options and re-load from WP * * @since 2.2.2 */ function init() { // Load localizations if available; @since 2.4.0 load_plugin_textdomain( 'wp-bannerize', false, 'wp-bannerize/localization' ); $this->cssRulesSample = $this->cssRulesSample(); // Add version control in options $this->options = $this->defaultOptions(); add_option( $this->options_key, $this->options ); $this->options = get_option( $this->options_key ); // Add option menu in Wordpress backend add_action( 'admin_init', array ( $this, 'plugin_init' ) ); add_action( 'admin_menu', array ( $this, 'plugin_setup' ) ); add_filter( 'screen_layout_columns', array ( &$this, 'on_screen_layout_columns' ), 10, 2 ); // Update version control in options update_option( $this->options_key, $this->options ); } /** * Comodity: echo saidmade WP Bannerize header * * @return void */ function saidmadeHeader() { ?>
pageSettings ) { $columns[$this->pageSettings] = 1; } else { if ( $screen == $this->pageTools ) { $columns[$this->pageTools] = 2; } } return $columns; } /** * Return css rules sample * * @return string */ function cssRulesSample() { ob_start(); require_once( 'wpBannerizeCssRulesSample.css' ); $result = ob_get_contents(); ob_end_clean(); return $result; } /** * Return and setting default options values * * @return mixed */ function defaultOptions() { $this->options = array ( 'wp_bannerize_version' => $this->version, 'clickCounterEnabled' => '1', 'impressionsEnabled' => '1', 'supportWPBannerize' => '1', 'comboWindowModeFlash' => 'Window', 'linkDescription' => '0', 'wpBannerizeStyleDefault' => 'default', 'wpBannerizeStyle' => kWPBannerizeBannerStyleDefault, 'wpBannerizeStyleCustom' => $this->cssRulesSample, 'wpBannerizeNoBannerHTMLMessage' => '

No Banner to display

' ); return $this->options; } /** * Reset options to default values * * @return void */ function resetOptionsToDefault() { $this->options = $this->defaultOptions(); update_option( $this->options_key, $this->options ); } /** * Register style for plugin * * @since 2.4.9 * @return void */ function plugin_init() { wp_register_style( 'WPBannerizeBannerStyleAdmin', $this->uri . kWPBannerizeBannerStyleAdmin ); wp_register_style( 'wp-bannerize-jqueryui-css', $this->uri . "/css/ui-lightness/jquery-ui.custom.css" ); wp_register_style( 'fancybox-css', $this->uri . kWPBannerizeFancyBoxCSS ); } /** * Execute when plugin is showing on backend * * @since 2.4.9 * @return void */ function plugin_admin_scripts() { wp_enqueue_script( 'common' ); wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'wp-lists' ); // Add wp_enqueue_script for jquery library wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'fancybox_js', $this->uri . kWPBannerizeFancyBoxJavascript, array ( 'jquery' ), kWPBannerizeVersion, true ); wp_enqueue_script( 'WPBannerizeJavascriptAdmin', $this->uri . kWPBannerizeJavascriptAdmin, array ( 'jquery', 'media-upload', 'thickbox' ), kWPBannerizeVersion, true ); wp_enqueue_script( 'wp_bannerize_jquery_dp_js', $this->uri . '/js/jquery-ui.min.js', array ( 'jquery' ), kWPBannerizeVersion, true ); wp_enqueue_script( 'wp_bannerize_timepicker_js', $this->uri . '/js/jquery.timepicker.min.js', array ( 'jquery-ui-core' ), kWPBannerizeVersion, true ); // Add main admin javascript wp_localize_script( 'WPBannerizeJavascriptAdmin', 'wpBannerizeJavascriptLocalization', array ( 'wpBannerizeFormAction' => kWPBannerizeFormAction, 'ajaxURL' => $this->ajaxURL, 'messageConfirm' => __( 'WARINING!! Do you want delete this banner?', 'wp-bannerize' ), 'messageTruncateConfirm' => __( 'WARINING!! Do you have to check `Confirm unreversible action` ', 'wp-bannerize' ), 'messageTruncateConfirmAgain' => __( 'WARINING!! Are you sure to erase all WP Bannerize Database Table? ', 'wp-bannerize' ), 'timeOnlyTitle' => __( 'Choose Time', 'wp-bannerize' ), 'timeText' => __( 'Time', 'wp-bannerize' ), 'hourText' => __( 'Hour', 'wp-bannerize' ), 'minuteText' => __( 'Minute', 'wp-bannerize' ), 'secondText' => __( 'Seconds', 'wp-bannerize' ), 'currentText' => __( 'Now', 'wp-bannerize' ), 'dayNamesMin' => __( 'Su,Mo,Tu,We,Th,Fr,Sa', 'wp-bannerize' ), 'monthNames' => __( 'January,February,March,April,May,June,July,August,September,October,November,December', 'wp-bannerize' ), 'closeText' => __( 'Close', 'wp-bannerize' ), 'dateFormat' => __( 'mm/dd/yy', 'wp-bannerize' ) ) ); } /** * Execute when plugin is showing on backend * * @return void */ function plugin_admin_styles() { wp_enqueue_style( 'fancybox-css' ); wp_enqueue_style( 'thickbox' ); wp_enqueue_style( 'WPBannerizeBannerStyleAdmin' ); wp_enqueue_style( 'wp-bannerize-jqueryui-css' ); } function didToolsLoadPage() { add_meta_box( 'wp_bannerize_tools_editor', __( 'PHP Function and Shortcode Editor', 'wp-bannerize' ), array ( &$this, 'boxTools' ), $this->pageTools, 'normal', 'core' ); add_meta_box( 'wp_bannerize_tools_database', __( 'Database', 'wp-bannerize' ), array ( &$this, 'boxToolsDatabase' ), $this->pageTools, 'side', 'core' ); } function didSettingsLoadPage() { add_meta_box( kWPBannerizeMetaBoxSettingsKey, __( 'Settings', 'wp-bannerize' ), array ( &$this, 'boxSettings' ), $this->pageSettings, 'normal', 'core' ); } function boxSettings() { require_once( 'wpBannerizeSettings.php' ); } function boxTools() { require_once( 'wpBannerizeTools.php' ); } function boxToolsDatabase() { require_once( 'wpBannerizeDatabase.php' ); } /** * Draw Settings Panel */ function settings() { global $screen_layout_columns; /** * Any error flag */ $any_error = ''; $this->error = false; if ( isset( $_POST['command_action'] ) ) { if ( $_POST['command_action'] == "updateSettings" && !isset( $_POST['tools'] ) ) { $this->options['clickCounterEnabled'] = ( isset( $_POST['clickCounterEnabled'] ) ) ? '1' : '0'; $this->options['impressionsEnabled'] = ( isset( $_POST['impressionsEnabled'] ) ) ? '1' : '0'; $this->options['supportWPBannerize'] = ( isset( $_POST['supportWPBannerize'] ) ) ? '1' : '0'; $this->options['comboWindowModeFlash'] = ( isset( $_POST['comboWindowModeFlash'] ) ) ? $_POST['comboWindowModeFlash'] : 'Window'; $this->options['linkDescription'] = ( isset( $_POST['linkDescription'] ) ) ? '1' : '0'; $this->options['wpBannerizeStyleDefault'] = ( isset( $_POST['wpBannerizeStyleDefault'] ) ) ? $_POST['wpBannerizeStyleDefault'] : 'default'; $this->options['wpBannerizeStyleCustom'] = ( isset( $_POST['wpBannerizeStyleCustom'] ) ) ? $_POST['wpBannerizeStyleCustom'] : $this->options['wpBannerizeStyleCustom']; $this->options['wpBannerizeStyle'] = ( isset( $_POST['wpBannerizeStyle'] ) ) ? $_POST['wpBannerizeStyle'] : kWPBannerizeBannerStyleDefault; $this->options['wpBannerizeNoBannerHTMLMessage'] = ( isset( $_POST['wpBannerizeNoBannerHTMLMessage'] ) ) ? $_POST['wpBannerizeNoBannerHTMLMessage'] : ''; update_option( $this->options_key, $this->options ); $any_error = __( 'Settings update succesfully!', 'wp-bannerize' ); } else { if ( $_POST['tools'] == "resetToDefault" ) { $this->resetOptionsToDefault(); $any_error = __( 'Settings Reset to default succesfully!', 'wp-bannerize' ); } } } ?>
saidmadeHeader(); ?>

pageSettings, 'side', "" ); ?>
pageSettings, 'normal', "" ); ?>

truncateTable(); $any_error = __( 'WP Bannerize Table was erase succesfully!', 'wp-bannerize' ); } } ?>
saidmadeHeader(); ?>

pageTools, 'side', "" ); ?>
pageTools, 'normal', "" ); ?>

plugin_name, $this->plugin_name, kWPBannerizeUserCapabilitiy, $this->directory . '-mainshow', array ( &$this, 'show_banners' ), $this->uri . "/css/images/wp-bannerize-16x16.png" ); } if ( function_exists( 'add_submenu_page' ) ) { $this->pageMain = add_submenu_page( $this->directory . '-mainshow', __( 'Edit', 'wp-bannerize' ), __( 'Edit', 'wp-bannerize' ), kWPBannerizeUserCapabilitiy, $this->directory . '-mainshow', array ( &$this, 'show_banners' ) ); $this->pageAddBanner = add_submenu_page( $this->directory . '-mainshow', __( 'Add New', 'wp-bannerize' ), __( 'Add New', 'wp-bannerize' ), kWPBannerizeUserCapabilitiy, $this->directory . '-addnew', array ( &$this, 'add_new_banner' ) ); $this->pageSettings = add_submenu_page( $this->directory . '-mainshow', __( 'Settings', 'wp-bannerize' ), __( 'Settings', 'wp-bannerize' ), kWPBannerizeUserCapabilitiy, $this->directory . '-settings', array ( &$this, 'settings' ) ); $this->pageTools = add_submenu_page( $this->directory . '-mainshow', __( 'Tools', 'wp-bannerize' ), __( 'Tools', 'wp-bannerize' ), kWPBannerizeUserCapabilitiy, $this->directory . '-tools', array ( &$this, 'tools' ) ); add_action( 'load-' . $this->pageSettings, array ( &$this, 'didSettingsLoadPage' ) ); add_action( 'load-' . $this->pageTools, array ( &$this, 'didToolsLoadPage' ) ); } add_action( 'admin_print_scripts-' . $plugin_page, array ( $this, 'plugin_admin_scripts' ) ); add_action( 'admin_print_scripts-' . $this->pageAddBanner, array ( $this, 'plugin_admin_scripts' ) ); add_action( 'admin_print_scripts-' . $this->pageSettings, array ( $this, 'plugin_admin_scripts' ) ); add_action( 'admin_print_scripts-' . $this->pageTools, array ( $this, 'plugin_admin_scripts' ) ); add_action( 'admin_print_styles-' . $plugin_page, array ( $this, 'plugin_admin_styles' ) ); add_action( 'admin_print_styles-' . $this->pageAddBanner, array ( $this, 'plugin_admin_styles' ) ); add_action( 'admin_print_styles-' . $this->pageSettings, array ( $this, 'plugin_admin_styles' ) ); add_action( 'admin_print_styles-' . $this->pageTools, array ( $this, 'plugin_admin_styles' ) ); // Add contextual Help if ( function_exists( 'add_contextual_help' ) ) { ob_start(); require_once( 'wpBannerizeHelp.php' ); $help = ob_get_contents(); $help = str_replace( "\t", "", $help ); $help = trim( $help ); ob_end_clean(); add_contextual_help( $plugin_page, $help ); add_contextual_help( $this->pageAddBanner, $help ); add_contextual_help( $this->pageSettings, $help ); add_contextual_help( $this->pageTools, $help ); } } /** * Add new banner Panel * * @return void */ function add_new_banner() { $any_error = ''; if ( isset( $_POST['command_action'] ) && $_POST['command_action'] == "insert" ) { $any_error = $this->insertBanner(); } ?>
saidmadeHeader(); ?>

() : getPHPDateFormat() ) ?>
get_combo_group() ?> ()
get_target_combo() ?>
( )

setBannerToTrash(); break; case "untrash": $any_error = $this->unsetBannerToTrash(); break; case "delete": $any_error = $this->deleteBanner(); break; case "update": $any_error = $this->updateBanner(); break; } } ?>
saidmadeHeader(); ?>

setBannerToTrash( $id ); } break; case "delete-selected": if ( isset( $_POST['image_record'] ) ) { if ( is_array( $_POST['image_record'] ) ) { foreach ( $_POST['image_record'] as $id ) { $any_error = $this->deleteBanner( $id ); } } } break; case "restore-selected": if ( isset( $_POST['image_record'] ) ) { $id = implode( ",", $_POST['image_record'] ); $any_error = $this->unsetBannerToTrash( $id ); } break; } $any_error = ''; $pagenum = isset( $_GET['pagenum'] ) ? ( ( $_GET['pagenum'] == '' ? 1 : $_GET['pagenum'] ) ) : '1'; $limit = isset( $_REQUEST['combo_pagination_filter'] ) ? $_REQUEST['combo_pagination_filter'] : '10'; $where = "1"; $count = array (); // Build where condictions if ( isset( $_GET['trash'] ) && $_GET['trash'] != "" ) { $where = sprintf( "%s AND trash = '%s'", $where, $_GET['trash'] ); } else { $where = "1 AND trash = '0'"; } if ( isset( $_REQUEST['combo_group_filter'] ) && $_REQUEST['combo_group_filter'] != "" ) { $where = sprintf( "%s AND `group` = '%s'", $where, $_REQUEST['combo_group_filter'] ); } // All Total records $sql = sprintf( "SELECT COUNT(*) AS all_record FROM %s", $this->table_bannerize ); $result = $wpdb->get_row( $sql ); $count['All'] = intval( $result->all_record ); // Trash $sql = sprintf( "SELECT COUNT(*) AS trashed FROM %s WHERE trash = '1'", $this->table_bannerize ); $result = $wpdb->get_row( $sql ); $count['Trash'] = intval( $result->trashed ); $count['Publish'] = $count['All'] - $count['Trash']; // Count record with where conditions $sql = sprintf( "SELECT COUNT(*) AS showing FROM %s WHERE %s", $this->table_bannerize, $where ); $result = $wpdb->get_row( $sql ); $count['showing'] = $result->showing; $num_pages = ceil( $count['showing'] / $limit ); // GET query fields $query_search = array ( 'trash' => isset( $_GET['trash'] ) ? $_GET['trash'] : 0, 'combo_group_filter' => isset( $_REQUEST['combo_group_filter'] ) ? $_REQUEST['combo_group_filter'] : '', 'combo_pagination_filter' => $limit ); $arraytolink = array_merge( array ( 'edit' => null, 'pagenum' => '%#%' ), $query_search ); $page_links = paginate_links( array ( 'base' => add_query_arg( $arraytolink ), 'format' => 'page=wp-bannerize-mainshow', 'total' => $num_pages, 'current' => $pagenum ) ); ?>

"/>
    "0", "Trash" => "1" ); foreach ( $status_links as $status => $value ) { if ( $count[$status] > 0 ) { $current = ""; $addurl = ""; if ( ( isset( $_GET['trash'] ) && $_GET['trash'] == $value ) || ( !isset( $_GET['trash'] ) && $value == "0" ) ) { $current = 'class="current"'; } if ( $value != "" ) { $addurl = "&trash=" . $value; } $links[] = sprintf( "
  • %s (%s)", $current, $addurl, __( $status, 'wp-bannerize' ), $count[$status] ); } } $output = implode( '|
  • ', $links ) . ''; echo $output; ?>
0 ) : ?>
combo_group_filter(); $this->combo_pagination_filter() ?>
$limit ? $limit : $count['showing'] ), $count['showing'] ) ?>
" id="wp_bannerize_list" cellspacing="0" class="widefat"> NOW() OR `end_date` = '0000-00-00 00:00:00') AND (`maximpressions` = 0 OR `impressions` < `maximpressions`), 'enabled', 'disabled' ) AS status FROM %s WHERE %s ORDER BY `sorter`, `group` ASC LIMIT %s,%s", $this->table_bannerize, $where, ( ( $pagenum - 1 ) * $limit ), $limit ); $row = $wpdb->get_results( $sql ); foreach ( $row as $item ) : ?> id="item_id ?>"> rowWithItem( $item ) ?>
CTR
CTR
$limit ? $limit : $count['showing'] ), $count['showing'] ) ?>

NOW() OR `end_date` = '0000-00-00 00:00:00') AND (`maximpressions` = 0 OR `impressions` < `maximpressions`), 'enabled', 'disabled' ) AS status FROM `%s` WHERE id = %s", $this->table_bannerize, $id ); $row = $wpdb->get_row( $sql ); $this->rowWithItem( $row ); } /** * Compute HTML for a row * * @param $item * Result set of a query * * @return void */ function rowWithItem( $item ) { ?>
banner_type == kWPBannerizeBannerTypeFromLocal || $item->banner_type == kWPBannerizeBannerTypeByURL ) : ?> mime == "application/x-shockwave-flash" ) : ?> <?php echo $item->description ?> <?php echo $item->description ?> group ?>
start_date != '0000-00-00 00:00:00' || $item->end_date != '0000-00-00 00:00:00' ) : ?>

mysql_date( $item->start_date ) == '0000-00-00 00:00:00' ) ? __( 'Always', 'wp-bannerize' ) : $this->mysql_date( $item->start_date ) ?> mysql_date( $item->end_date ) == '0000-00-00 00:00:00' ) ? __( 'Always', 'wp-bannerize' ) : $this->mysql_date( $item->end_date ) ?>

url != '' ) : ?>

stringCut( $item->url ) ?>

description != '' ) : ?>
description ?>
trash == "0" ) : ?> | | |
clickcount ?>
impressions ?>
impressions > 0 ) { echo intval( ( $item->clickcount / $item->impressions ) * 100 ) . '%'; } else { echo '0%'; } ?>
table_bannerize, $id ); $row = $wpdb->get_row( $sql ); ob_start(); ?> ' . ''; $q = "SELECT `group` FROM `" . $this->table_bannerize . "` GROUP BY `group` ORDER BY `group` "; $rows = $wpdb->get_results( $q ); foreach ( $rows as $row ) { if ( isset( $_REQUEST['combo_group_filter'] ) && $_REQUEST['combo_group_filter'] == $row->group ) { $sel = 'selected="selected"'; } else { $sel = ""; } $o .= ''; } $o .= ''; echo $o; } function groupMenu( $name = "wpBannerizeGroupMenu", $selected = "", $firstItem = "" ) { global $wpdb; ob_start(); ?> ' . ''; $q = "SELECT `group` FROM `" . $this->table_bannerize . "` GROUP BY `group` ORDER BY `group` "; $rows = $wpdb->get_results( $q ); foreach ( $rows as $row ) { $o .= ''; } $o .= ''; return $o; } /** * Get Select Checked Categories * * @param null $cats * * @return string */ function get_categories_checkboxes( $cats = null ) { if ( !is_null( $cats ) ) { $cat_array = explode( ",", $cats ); } $res = get_categories(); $o = ""; foreach ( $res as $cat ) { $checked = ""; if ( !is_null( $cats ) ) { if ( in_array( $cat->cat_ID, $cat_array ) ) { $checked = 'checked="checked"'; } } $o .= ' '; } return $o; } /** * Build combo menu for target * * @param string $sel * * @return string */ function get_target_combo( $sel = "_blank" ) { $o = ''; return $o; } /** * Insert banner into the database table * * @return bool|string|void */ function insertBanner() { $wpBannerizeBannerType = intval( $_POST['wpBannerizeBannerType'] ); switch ( $wpBannerizeBannerType ) { case 1: return $this->addBannerFromLocal(); break; case 2: return $this->addBannerFromURL(); break; case 3: return $this->addBannerWithFreeHTML(); break; default: break; } return false; } function addBannerWithFreeHTML() { global $wpdb; $group = $_POST['group']; $description = $_POST['description']; $use_description = isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0; $url = $_POST['url']; $target = $_POST['target']; $nofollow = isset( $_POST['nofollow'] ) ? $_POST['nofollow'] : 0; $start_date = $this->mysql_date( $_POST['start_date'] ); $end_date = $this->mysql_date( $_POST['end_date'] ); $wpdb->show_errors(); $rows = $wpdb->insert( $this->table_bannerize, array ( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $group, 'description' => $description, 'use_description' => $use_description, 'url' => $url, 'target' => $target, 'nofollow' => $nofollow, 'start_date' => $start_date, 'end_date' => $end_date, 'maximpressions' => $_POST['maxImpressions'], 'free_html' => $_POST['freeHTML'] ) ); if ( $rows !== false ) { $this->error = false; return __( 'Banner added succesfully!', 'wp-bannerize' ); } else { $this->error = true; return __( 'Error on insert Free HTML banner type', 'wp-bannerize' ); } } function addBannerFromURL() { global $wpdb; $dimensions = array ( $_POST['width'], $_POST['height'] ); $mime = ""; if ( function_exists( 'getimagesize' ) ) { $dimensions = @getimagesize( $_POST['filenameFromURL'] ); if ( !isset( $dimensions ) ) { $dimensions = array ( '0', '0' ); } else { $mime = $dimensions['mime']; } } $group = $_POST['group']; $description = $_POST['description']; $use_description = isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0; $url = $_POST['url']; $target = $_POST['target']; $nofollow = isset( $_POST['nofollow'] ) ? $_POST['nofollow'] : 0; $start_date = $this->mysql_date( $_POST['start_date'] ); $end_date = $this->mysql_date( $_POST['end_date'] ); $wpdb->show_errors(); $rows = $wpdb->insert( $this->table_bannerize, array( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $group, 'description' => $description, 'use_description' => $use_description, 'url' => $url, 'filename' => $_POST['filenameFromURL'], 'target' => $target, 'nofollow' => $nofollow, 'start_date' => $start_date, 'end_date' => $end_date, 'maximpressions' => $_POST['maxImpressions'], 'mime' => $mime, 'width' => $dimensions[0], 'height' => $dimensions[1], 'free_html' => '' ) ); if ( $rows !== false ) { $this->error = false; return __( 'Banner added succesfully!', 'wp-bannerize' ); } else { $this->error = false; return __( 'Error on insert URL banner type', 'wp-bannerize' ); } } function addBannerFromLocal() { global $wpdb; // check post error if ( is_uploaded_file( $_FILES['filename']['tmp_name'] ) ) { //$size = floor($_FILES['filename']['size'] / (1024 * 1024)); $mime = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $temp = $_FILES['filename']['tmp_name']; $group = $_POST['group']; $description = $_POST['description']; $use_description = isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0; $url = $_POST['url']; $target = $_POST['target']; $nofollow = isset( $_POST['nofollow'] ) ? $_POST['nofollow'] : 0; $dimensions = array ( '0', '0' ); $start_date = $this->mysql_date( $_POST['start_date'] ); $end_date = $this->mysql_date( $_POST['end_date'] ); $uploads = wp_upload_bits( strtolower( $name ), null, '' ); if ( move_uploaded_file( $temp, $uploads['file'] ) ) { if ( function_exists( 'getimagesize' ) ) { $dimensions = @getimagesize( $uploads['file'] ); if ( !isset( $dimensions ) ) { $dimensions = array ( '0', '0' ); } } $wpdb->show_errors(); $rows = $wpdb->insert( $this->table_bannerize, array( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $group, 'description' => $description, 'use_description' => $use_description, 'url' => $url, 'filename' => $uploads['url'], 'target' => $target, 'nofollow' => $nofollow, 'mime' => $mime, 'realpath' => $uploads['file'], 'width' => $dimensions[0], 'height' => $dimensions[1], 'start_date' => $start_date, 'end_date' => $end_date, 'maximpressions' => $_POST['maxImpressions'], 'free_html' => '' ) ); if ( $rows !== false ) { $this->error = false; return __( 'Banner added succesfully!', 'wp-bannerize' ); } else { $this->error = true; return __( 'Error on insert local banner type', 'wp-bannerize' ); } } else { $this->error = true; $error = sprintf( __( 'Error while copying [%s] [%s bytes] - [%s]', 'wp-bannerize' ), $_FILES['filename']['name'], $_FILES['filename']['size'], $_FILES['filename']['error'] ); return $error; } } else { $this->error = true; $error = sprintf( __( 'No file to upload! - [%s]', 'wp-bannerize' ), $_FILES['filename']['error'] ); return $error; } } /** * Set one or more banner in trash mode: trash = "1" * * @param $id string|array * * @return string|void */ function setBannerToTrash( $id = null ) { global $wpdb; $id = ( is_null( $id ) ) ? $_POST['id'] : $id; $sql = sprintf( "UPDATE `%s` SET trash = '1' WHERE id IN(%s)", $this->table_bannerize, $id ); $wpdb->query( $sql ); $this->error = false; return __( 'Banner sent to trash succesfully!', 'wp-bannerize' ); } /** * Set one or more banner in publish mode: trash = "0" * * @param $id string|array * * @return void */ function unsetBannerToTrash( $id = null ) { global $wpdb; $id = ( is_null( $id ) ) ? $_POST['id'] : $id; $sql = sprintf( "UPDATE `%s` SET trash = '0' WHERE id IN(%s)", $this->table_bannerize, $id ); $wpdb->query( $sql ); $this->error = false; return __( 'Banner restore from trash succesfully!', 'wp-bannerize' ); } /** * Delete (permanently) a banner from Database and filesystem. Because a banner is delete from disk, this method * is call from loop for delete more banner * * @param null $id * * @return string|void */ function deleteBanner( $id = null ) { global $wpdb; $id = ( is_null( $id ) ) ? $_POST['id'] : $id; // Delete from disk only local banner. $wpBannerizeBannerType = $wpdb->get_var( "SELECT `banner_type` FROM `" . $this->table_bannerize . "` WHERE `id` = " . $id ); if ( $wpBannerizeBannerType == '1' ) { $filename = $wpdb->get_var( "SELECT `realpath` FROM `" . $this->table_bannerize . "` WHERE `id` = " . $id ); @unlink( $filename ); } $q = "DELETE FROM `" . $this->table_bannerize . "` WHERE `id` = " . $id; $wpdb->query( $q ); $this->error = false; return __( 'Banner delete succesfully!', 'wp-bannerize' ); } /** * Update a banner data and image * * @return bool|string|void Information message */ function updateBanner() { $wpBannerizeBannerType = intval( $_POST['wpBannerizeBannerType'] ); switch ( $wpBannerizeBannerType ) { case 1: return $this->updateBannerFromLocal(); break; case 2: return $this->updateBannerFromURL(); break; case 3: return $this->updateBannerWithFreeHTML(); break; default: break; } return false; } function updateBannerWithFreeHTML() { global $wpdb; $dimensions = array ( $_POST['width'], $_POST['height'] ); $mime = ""; $values = array ( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $_POST['group'], 'start_date' => $this->mysql_date( $_POST['start_date'] ), 'end_date' => $this->mysql_date( $_POST['end_date'] ), 'maximpressions' => $_POST['maxImpressions'], 'impressions' => $_POST['impressions'], 'description' => $_POST['description'], 'url' => $_POST['url'], 'target' => $_POST['target'], 'use_description' => isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0, 'nofollow' => $_POST['nofollow'], 'clickcount' => $_POST['clickcount'], 'width' => $dimensions[0], 'height' => $dimensions[1], 'filename' => $_POST['filenameFromURL'], 'mime' => $mime, 'free_html' => $_POST['freeHTML'] ); $where = array ( 'id' => $_POST['id'] ); $wpdb->show_errors(); $result = $wpdb->update( $this->table_bannerize, $values, $where ); if ( $result !== false ) { $this->error = false; return __( 'Banner update succesfully!', 'wp-bannerize' ); } else { $this->error = true; return __( 'Error while update free HTML Banner!', 'wp-bannerize' ); } } function updateBannerFromLocal() { global $wpdb; // Retrive image info $sql = sprintf( "SELECT * FROM `%s` WHERE id = %s", $this->table_bannerize, $_POST['id'] ); $row = $wpdb->get_row( $sql ); $filename = $row->filename; $mime = $row->mime; $realpath = $row->realpath; $dimensions = array ( $_POST['width'], $_POST['height'] ); if ( is_uploaded_file( $_FILES['filename']['tmp_name'] ) ) { //$size = floor($_FILES['filename']['size'] / (1024 * 1024)); $mime = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $temp = $_FILES['filename']['tmp_name']; $dimensions = array ( '0', '0' ); $uploads = wp_upload_bits( strtolower( $name ), null, '' ); if ( move_uploaded_file( $temp, $uploads['file'] ) ) { if ( function_exists( 'getimagesize' ) ) { $dimensions = @getimagesize( $uploads['file'] ); if ( !isset( $dimensions ) ) { $dimensions = array ( '0', '0' ); } } // Delete old image @unlink( $realpath ); $filename = $uploads['url']; $realpath = $uploads['file']; } } $values = array ( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $_POST['group'], 'start_date' => $this->mysql_date( $_POST['start_date'] ), 'end_date' => $this->mysql_date( $_POST['end_date'] ), 'maximpressions' => $_POST['maxImpressions'], 'impressions' => $_POST['impressions'], 'description' => $_POST['description'], 'url' => $_POST['url'], 'target' => $_POST['target'], 'use_description' => isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0, 'nofollow' => $_POST['nofollow'], 'clickcount' => $_POST['clickcount'], 'width' => $dimensions[0], 'height' => $dimensions[1], 'filename' => $filename, 'realpath' => $realpath, 'mime' => $mime ); $where = array ( 'id' => $_POST['id'] ); $wpdb->show_errors(); $result = $wpdb->update( $this->table_bannerize, $values, $where ); if ( $result !== false ) { $this->error = false; return __( 'Banner update succesfully!', 'wp-bannerize' ); } else { $this->error = true; return __( 'Error while update local Banner!', 'wp-bannerize' ); } } function updateBannerFromURL() { global $wpdb; $dimensions = array ( $_POST['width'], $_POST['height'] ); $mime = ""; if ( function_exists( 'getimagesize' ) ) { $dimensions = @getimagesize( $_POST['filenameFromURL'] ); if ( !isset( $dimensions ) ) { $dimensions = array ( '0', '0' ); } else { $mime = $dimensions['mime']; } if ( !( $_POST['width'] == '0' || $_POST['height'] == '0' || $_POST['width'] == '' || $_POST['height'] == '' ) ) { $dimensions[0] = $_POST['width']; $dimensions[1] = $_POST['height']; } } $values = array ( 'banner_type' => $_POST['wpBannerizeBannerType'], 'group' => $_POST['group'], 'start_date' => $this->mysql_date( $_POST['start_date'] ), 'end_date' => $this->mysql_date( $_POST['end_date'] ), 'maximpressions' => $_POST['maxImpressions'], 'impressions' => $_POST['impressions'], 'description' => $_POST['description'], 'url' => $_POST['url'], 'target' => $_POST['target'], 'use_description' => isset( $_POST['use_description'] ) ? $_POST['use_description'] : 0, 'nofollow' => $_POST['nofollow'], 'clickcount' => $_POST['clickcount'], 'width' => $dimensions[0], 'height' => $dimensions[1], 'filename' => $_POST['filenameFromURL'], 'mime' => $mime ); $where = array ( 'id' => $_POST['id'] ); $wpdb->show_errors(); $result = $wpdb->update( $this->table_bannerize, $values, $where ); if ( $result !== false ) { $this->error = false; return __( 'Banner update succesfully!', 'wp-bannerize' ); } else { $this->error = true; return __( 'Error while update local Banner!', 'wp-bannerize' ); } } /** * Attach settings in Wordpress Plugins list * * @param $pluginfile */ function register_plugin_settings( $pluginfile ) { $this->plugin_file = $pluginfile; add_action( 'plugin_action_links_' . basename( dirname( $pluginfile ) ) . '/' . basename( $pluginfile ), array ( &$this, 'plugin_settings' ), 10, 4 ); add_filter( 'plugin_row_meta', array ( &$this, 'add_plugin_links' ), 10, 2 ); } /** * Add link to Plugin list page * * @param $links * * @return string */ function plugin_settings( $links ) { $settings_link = '' . __( 'Settings' ) . ''; array_unshift( $links, $settings_link ); return $links; } /** * Add links on installed plugin list * * @param $links * @param $file * * @return array */ function add_plugin_links( $links, $file ) { if ( $file == plugin_basename( $this->plugin_file ) ) { $links[] = '' . __( 'For more info visit', 'wp-bannerize' ) . ' wpXtreme Blog'; } return $links; } /** * Call on Plugin Activation * * @since 2.5.0 * * @return void */ function pluginDidActive() { // Table doesn't exists: create it $this->createTable(); // Rename tabel if needed $this->renameTable(); //mod jrc 170613: add admin role to default admin if not alreay exist global $wp_roles; if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } $wp_roles->use_db = true; $administrator = $wp_roles->get_role('administrator'); if (!$administrator->has_cap(kWPBannerizeUserCapabilitiy)) { $wp_roles->add_cap('administrator', kWPBannerizeUserCapabilitiy); //ensure we can unset role cap it safely later add_option( 'scl_wp_bannerize_has_set_role_cap', kWPBannerizeUserCapabilitiy ); } //end mod jrc 070613: } function pluginDidDeactive() { //mod jrc 170613: add admin role to default admin if not alreay exist global $wp_roles; if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } $wp_roles->use_db = true; $administrator = $wp_roles->get_role('administrator'); //attempt to unset role cap safely only iff we have previously set it (ie. it is not a standard wp role cap, or something reqd/added by another plugin) //warning: if you choose a role cap related to another plugin (loaded later) then this is not 100% reliable - it is possble to accidentaly remove admin capability to other chosen plugin //hence: try and use the custom role cap 'manage_wp_bannerize_banners' - set in main.h.php via - define( 'kWPBannerizeUserCapabilitiy', 'manage_wp_bannerize_banners' ); $has_set_role = get_option('scl_wp_bannerize_has_set_role_cap'); if (!empty($has_set_role) && $has_set_role == kWPBannerizeUserCapabilitiy && $administrator->has_cap(kWPBannerizeUserCapabilitiy)) { $wp_roles->remove_cap('administrator', kWPBannerizeUserCapabilitiy); delete_option('scl_wp_bannerize_has_set_role_cap'); } //end mod jrc 070613: } /** * Check if previous database table name exists. * * @return void */ function previousDatabaseTableNameExists() { global $wpdb; $sql = sprintf( "SHOW TABLES LIKE '%s'", $this->prev_table_bannerize ); if ( $wpdb->get_var( $sql ) != $this->prev_table_bannerize ) { // table does not exist! return false; } return true; } /** * Create the WP Bannerize table. This method use Wordpress dbDelta() function for check if table exists and update * table if needed. * * @since 2.1.0 * * @return void */ function createTable() { if(!function_exists('dbDelta')) { require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); } ob_start(); require_once( 'wpBannerizeTable.sql' ); $sql = sprintf( ob_get_contents(), ( $this->previousDatabaseTableNameExists() ) ? $this->prev_table_bannerize : $this->table_bannerize ); @dbDelta( $sql ); ob_end_clean(); } /** * Rename previous databsse table name if needed * * @return void */ function renameTable() { global $wpdb; if ( $this->previousDatabaseTableNameExists() ) { $sql = sprintf( "RENAME TABLE `%s` TO `%s`", $this->prev_table_bannerize, $this->table_bannerize ); $wpdb->query( $sql ); } } /** * Truncate WP bannerize Database Table * * @return void */ function truncateTable() { global $wpdb; $sql = sprintf( "TRUNCATE TABLE `%s`", $this->table_bannerize ); $wpdb->query( $sql ); } /** * Get WP Bannerize table information. Display number of row and table size. * * @param bool $echo * True (default) display output, else return an Object with table status information * * @return Object with table status information if $echo param is true */ function tableInformation( $echo = true ) { global $wpdb; $sql = sprintf( "SHOW TABLE STATUS LIKE '%s'", $this->table_bannerize ); $result = $wpdb->get_row( $sql ); $data = intval( $result->Data_length ); $index = intval( $result->Index_length ); $size = round( ( $data + $index ) / 1024, 3 ); $gain = round( floatval( $result->Data_free ) / 1024, 2 ); if ( $echo ) : ?>

: Rows ?>

: Kb 0 ) : ?> ( Kb)

$l ) { return substr( $s, 0, ( $l - strlen( $f ) ) / 2 ) . $f . substr( $s, -( $l - strlen( $f ) ) / 2, ( $l - strlen( $f ) ) / 2 ); } else { return $s; } } /** * Reformatting a date * * @param $s * String date * * @return string * Format date or "0000-00-00 00:00:00" for default */ function mysql_date( $s ) { $result = "0000-00-00 00:00:00"; $f = __( 'mm/dd/yy', 'wp-bannerize' ) . ' H:i'; if ( $s != "" && $s != $result ) { if ( substr( $s, 4, 1 ) == '-' ) { if ( substr( $f, 0, 1 ) == "m" ) { $fa = "m/d/Y H:i"; } else { $fa = "d/m/Y H:i"; } $date = date_create( $s ); $result = date_format( $date, $fa ); } else { $a = explode( ' ', $s ); $d = explode( '/', $a[0] ); if ( substr( $f, 0, 1 ) == 'm' ) { // mm/dd/yyyy hh:mm $result = sprintf( '%s-%s-%s %s:00', $d[2], $d[0], $d[1], $a[1] ); } else { if ( substr( $f, 0, 1 ) == 'd' ) { // dd/mm/yyyy hh:mm $result = sprintf( '%s-%s-%s %s:00', $d[2], $d[1], $d[0], $a[1] ); } } } } return $result; } /** * Return the localized date format in accordance with the language selected * * @return string * Localized date format in accordance with the language selected */ function getPHPDateFormat() { $f = __( 'mm/dd/yy', 'wp-bannerize' ); if ( substr( $f, 0, 1 ) == "m" ) { $result = "m/d/Y H:i"; } else { $result = "d/m/Y H:i"; } return $result; } /** * Return HTML code (ul/li) with all Wordpress categories * * @param array $selected * * @return string */ function categoriesTree( $selected = null ) { $allCategories = get_categories(); $o = ''; } /** * Internal "iterate" recursive function. For build a tree of category * Parent/Child * * @param object $cat_object * @param array $selected * * @return string */ function _iterateCategory( $cat_object, $selected = null ) { $checked = ""; if ( !is_null( $selected ) && is_array( $selected ) ) { $checked = ( in_array( $cat_object->cat_ID, $selected ) ) ? 'checked="checked"' : ""; } $ou = '
  • '; $childs = get_categories( 'parent=' . $cat_object->cat_ID ); foreach ( $childs as $cat ) { $ou .= ''; } $ou .= '
  • '; return $ou; } } // end of class