Plugin Directory

Changeset 2492145


Ignore:
Timestamp:
03/10/2021 01:30:16 PM (5 years ago)
Author:
freetobook
Message:

Security fixes and switch to semantic versioning

Location:
freetobook-review-widget/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • freetobook-review-widget/trunk/freetobook-review-widget.php

    r1817328 r2492145  
    11<?php
    2 /*
    3 Plugin Name: Freetobook review widget
    4 Plugin URI: https://www.freetobook.com/diary/bookings/reviews/wordpress_instructions.php
    5 Description: Freetobook review Widget for wordpress
    6 Version:  1.0
    7 Author: freetobook.com
    8 Author URI: http://www.freetobook.com
    9 License: GPL v2
    10 */
     2
     3/**
     4 * Plugin Name:     Freetobook review widget
     5 * Plugin URI:      https://en.freetobook.com/developers/wordpress.php
     6 * Description:     Freetobook Review Widget for wordpress
     7 * Version:         1.1
     8 * Author:          freetobook.com
     9 * Author URI:      https://en.freetobook.com
     10 * License:         GPL v2
     11 */
    1112
    1213 
     
    6465         function admin_page()
    6566         {
    66          
    67              $update=false;
    6867             //must check that the user has the required capability
    69             if (!current_user_can('manage_options'))
    70             {
     68            if (!current_user_can('manage_options')) {
    7169              wp_die( __('You do not have sufficient permissions to access this page.') );
    7270            }
    73            
    74              
    75              //update widget settings
    76             if (!empty($_POST['ftb-review-widget-key']))
    77             {
    78                 check_admin_referer('freetobook_review_update','ftb_nonce' );
    79                 update_option('ftb_review_widget_key',$_POST['ftb-review-widget-key']);
    80                 $update=true;
    81             }       
     71
     72             $updated = $this->update_widget_settings($updateErrors);
     73
    8274               
    8375            $this->widget_key=get_option('ftb_review_widget_key');
     
    8880           
    8981            $html.='<div id="icon-options-general" class="icon32"><br /></div><h2>Freetobook Review Widget Settings</h2>';
    90             if ($update) $html.='<h3>Changes saved</h3>';
     82
     83            if ($updated === true) {
     84                $html.='<h3>Changes saved</h3>';
     85            }
     86
     87            if (!empty($updateErrors)) {
     88                $html.='<h3>Error: ' . implode(', ', $updateErrors) . '</h3>';
     89            }
     90
    9191            $html.='
    9292            <br />
     
    127127       }
    128128
     129       function update_widget_settings(&$updateErrors = array())
     130       {
     131           $update = false;
     132           $updateErrors = array();
     133
     134           if (!empty($_POST['ftb-review-widget-key'])) {
     135               $reviewWidgetKey = trim($_POST['ftb-review-widget-key']);
     136               if (preg_match('/^[a-z0-9]+$/i', $reviewWidgetKey) === 1) {
     137                   check_admin_referer('freetobook_review_update', 'ftb_nonce');
     138                   update_option('ftb_review_widget_key', $reviewWidgetKey);
     139                   $update = true;
     140               } else {
     141                   $updateErrors[] = "Invalid review widget key.";
     142               }
     143           }
     144
     145           return $update;
     146       }
     147
    129148       
    130         function add_widget_scripts()
    131         {
    132             if ( !is_admin() )
    133             {
    134                     // instruction to only load if it is not the admin area
    135                     // register your script location, dependencies and version
    136                    wp_register_script('freetobook-reviews-js',
    137                                     'https://static.freetobook.com/widgets/js/'. $this->widget_key .'.js' ,
    138                                
    139                                     array(),
    140                                    '1.0' );
    141                // enqueue the script
    142                wp_enqueue_script('freetobook-reviews-js');
    143             }
    144             else
    145             {
    146                wp_enqueue_script(array('jquery', 'jquery-ui-core','jquery-ui-slider'));         
    147 
    148                wp_register_script('freetobook-reviews-js',
    149                                 plugins_url().'/freetobook-review-widget/ftb_admin.js',
    150                                 array(),
    151                                '1.0' );
    152                                
    153                wp_enqueue_script('freetobook-reviews-js');         
    154                $params=array('base_url'=>plugins_url().'/freetobook-review-widget/');
    155                wp_localize_script('freetobook-reviews-js','freetobook_reviews_params',$params);
    156 
    157                
    158             }
    159         }
    160 
    161        function add_admin_widget_stylesheet()
    162         {
    163             wp_enqueue_style('jquery-ui-slider', plugins_url() . '/freetobook-review-widget/css/ui-lightness/jquery-ui-slider.min.css');   
    164         }       
    165          
    166          
    167          function load_widgets()
    168          {
    169                 register_widget( 'FreetobookReviewWidget' );
    170          }
    171          
     149    function add_widget_scripts()
     150    {
     151        if (!is_admin()) {
     152            // instruction to only load if it is not the admin area
     153            // register your script location, dependencies and version
     154            wp_register_script(
     155                'freetobook-reviews-js',
     156                'https://static.freetobook.com/widgets/js/'. $this->widget_key .'.js' ,
     157                array(),
     158                '1.0'
     159            );
     160
     161           // enqueue the script
     162           wp_enqueue_script('freetobook-reviews-js');
     163        } else {
     164           wp_enqueue_script(array('jquery', 'jquery-ui-core','jquery-ui-slider'));
     165
     166           wp_register_script(
     167               'freetobook-reviews-js',
     168               plugins_url('/ftb_admin.js', __FILE__),
     169               array(),
     170               '1.0'
     171           );
     172
     173           wp_enqueue_script('freetobook-reviews-js');
     174           $params = array('base_url' => plugin_dir_url(__FILE__));
     175           wp_localize_script('freetobook-reviews-js','freetobook_reviews_params',$params);
     176        }
     177    }
     178
     179    function add_admin_widget_stylesheet()
     180    {
     181        wp_enqueue_style('jquery-ui-slider', plugins_url('/css/ui-lightness/jquery-ui-slider.min.css', __FILE__));
     182    }
     183
     184    function load_widgets()
     185    {
     186        register_widget( 'FreetobookReviewWidget' );
     187    }
     188
    172189         function get_widget_html($instance)
    173190         {
     
    222239            width:170px;height:120px;
    223240            background-position:center center;
    224             background-image:url(<?php echo plugins_url().'/freetobook-review-widget/images/previews/' . $style .'.png' ?>)"></div>
     241            background-image:url(<?php echo plugins_url('/images/previews/' . $style .'.png', __FILE__) ?>)"></div>
    225242            <strong>Style</strong><br>
    226243            <br>
     
    236253            <br>
    237254            <div style="text-align:center;width:220px;margin:0 auto;">
    238             Width:<input readonly type="text" size="3" 
     255            Width:<input readonly type="text" size="3"
    239256                    id="ftb_review_width_<?php echo $this->number?>"
    240257                    name="<?php echo $this->get_field_name( 'width' ) ?>"
     
    283300    add_action('init', array(&$ftb_review_widget,'add_widget_scripts'));
    284301}
    285 
    286 ?>
  • freetobook-review-widget/trunk/ftb_admin.js

    r1817295 r2492145  
    4242        ftb_reviews_update_slider_range(id[1],jQuery(this).val());
    4343    });
    44        
    45    
     44
     45
    4646    jQuery('.ftb_slider').each(function(){
    4747
     
    5353
    5454        if (!range) range=[150,400];
    55        
     55
    5656        jQuery(this).slider({
    5757            min:range[0],
     
    7171
    7272    ftb_reviews_add_handlers();
     73    console.log("argh");
    7374    /* hook into save handler */
    7475    jQuery(document).ajaxSuccess(function(e, xhr, settings) {
    75         var widget_id_base = 'freetobook_reviews'; 
     76        var widget_id_base = 'freetobook_reviews';
    7677
    7778        if(settings.data.search('action=save-widget') != -1 &&
  • freetobook-review-widget/trunk/readme.txt

    r2489583 r2492145  
    33Tags: freetobook, booking system, online booking,pms, web booking, booking engine,booking button
    44Requires at least: 3.0
    5 Tested up to: 5.6.2
    6 Stable tag: trunk
     5Tested up to: 5.7
     6Stable tag: 1.1
    77
    88Add the freetobook booking button to your wordpress blog.
     
    2727== Changelog ==
    2828
     29= 1.1 =
     30* Tidy up and review
     31
    2932= 1.0 =
    3033* Initial release
Note: See TracChangeset for help on using the changeset viewer.