Plugin Directory

Changeset 3053843


Ignore:
Timestamp:
03/18/2024 06:37:13 PM (2 years ago)
Author:
ShopSite
Message:

Fix jQuery error

Location:
shopsite-plugin/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • shopsite-plugin/trunk/editor_plugin.js

    r1079131 r3053843  
    1 
    21(function() {
    32    tinymce.create('tinymce.plugins.shopsite', {
     
    65
    76            ed.addCommand('open_shopsite', function() {
    8         tutorial = "";
    9         if (window.location.href.search("tutorial=1") != -1)
    10           tutorial = "&tutorial=1";
     7                tutorial = '';
     8                if (window.location.href.search('tutorial=1') != -1){tutorial = '&tutorial=1';}
    119                ed.windowManager.open({
    12           url: ss_path +
    13             "/shopsite.php?ss_action=insert" + tutorial,
    14                     width : 830,
     10                    url : ss_path+'/shopsite.php?ss_action=insert'+tutorial,
     11                    width  : 830,
    1512                    height : 600,
    16                     title : "Loading... please wait.",
    17           inline: true
    18           , onClose: function() { if (tutorial != "") continue_tutorial();}
    19                 }, {
    20                     plugin_url : url // Plugin absolute URL
    21                 });
     13                    title : 'Loading... please wait.',
     14                    inline : true,
     15                    onClose : function(){if(tutorial!=''){continue_tutorial();}}
     16                }, {plugin_url : url});
    2217            });
    23 
    24             // Register example button
     18            // Register button
    2519            ed.addButton('shopsite', {
    2620                title : 'Insert a ShopSite product',
    2721                cmd : 'open_shopsite',
    28         id: 'shopsite_button',
    29         image : url+'/ss-20.png'
     22                id : 'shopsite_button',
     23                image : url+'/ss-20.png'
    3024            });
    3125
     
    3327                disabled = co && n.nodeName != 'A';
    3428            });
    35      
    36 
    37 
    3829        },
    3930
     
    4435                authorurl : 'http://shopsite.com',
    4536                infourl : '',
    46                 version : "1.0"
     37                version : '1.0'
    4738            };
    4839        }
    4940    });
    5041
    51 
    5242    tinymce.PluginManager.add('shopsite', tinymce.plugins.shopsite);
    5343})();
  • shopsite-plugin/trunk/jquery.tutorial.js

    r1079131 r3053843  
    11//search for $.tutorial.defaults to see acceptable options
    22(function( $ ) {
    3  
     3    $.tutorial = function( options ) {
     4        if (options.placement == 'right') {
     5            $.extend($.tutorial.defaults.instructionCss, {'text-align':'left', 'height':70} );
     6        }
    47
    5   $.tutorial = function( options ) {
    6    
    7    
     8        if (options.placement == 'left') {
     9            $.extend($.tutorial.defaults.instructionCss, {'text-align':'right', 'height':70, 'width':150} );
     10        }
    811
    9    
    10    
    11    
    12     if (options.placement == 'right') {
    13       $.extend($.tutorial.defaults.instructionCss, {'text-align':'left', 'height':70} );
    14     }
    15    
    16     if (options.placement == 'left') {
    17       $.extend($.tutorial.defaults.instructionCss, {'text-align':'right', 'height':70, 'width':150} );
    18     }
    19    
    20    
    21     $.tutorial.state =
    22     {
    23       obj: this,
    24       oldinlinestyle: this.attr('style'),
    25       settings: $.extend(true, {}, $.tutorial.defaults, options )
    26      
    27     }
    28    
    29    
    30     settings = $.tutorial.state.settings;
    31    
    32     if (settings.overlay != false)
    33       $('body').append("<div id='masking_overlay'></div>");
    34    
    35    
    36     /*$.each(settings.css, function ( key, value ) {
    37       $.tutorial.state.oldcss[key]=value;
    38     });*/
    39    
    40    
    41     this.css(settings.css);
    42     pathway = settings.pathway;
    43     if (this.prop("tagName") == 'A') {
    44       url = this.attr('href');
    45       if (typeof url !== 'undefined') {
    46         if (url.indexOf('?') == -1)
    47           this.attr('href', url + "?tutorial="+pathway);
    48         else
    49           this.attr('href', url + "&tutorial="+pathway);
    50       }
    51     }
    52    
    53     this.find('a').each(function() {
    54       url = $(this).attr('href');
    55       if (typeof url !== 'undefined') {
    56         if (url.indexOf('?') == -1)
    57           $(this).attr('href', url + "?tutorial="+pathway);
    58         else
    59           $(this).attr('href', url + "&tutorial="+pathway);
    60       }
    61     });
    62    
    63     this.after("<input type=hidden name=tutorial id=tutorial_pass value='"+pathway+"'>");
     12        $.tutorial.state = {
     13            obj: this,
     14            oldinlinestyle: this.attr('style'),
     15            settings: $.extend(true, {}, $.tutorial.defaults, options )
     16        };
    6417
    65    
    66    
    67    
    68     if (settings.instruction !== false) {
    69       html = "<div id='tutorial'>"+settings.instruction;
    70       if (settings.removeOnClose !== false)
    71         html += "<div id='tutorial_close'>&nbsp;</div>";
    72       html += "</div>";
    73       object = $(html);
    74       if (settings.placement == 'below') {
    75         ptop = this.offset().top + this.height() + 2 + settings.move.y;
    76         pleft = this.offset().left + this.width()/2 - settings.instructionCss.width/2 + settings.move.x;;
    77         if (pleft < 0) pleft = 0;
    78         if (pleft + settings.instructionCss.width > $( window ).width())
    79           pleft = $( window ).width() - settings.instructionCss.width;
    80         $.extend(settings.instructionCss, {top: ptop, left: pleft} );
    81       }
    82      
    83       if (settings.placement == 'above') {
    84         pbottom = $(window).height() - this.offset().top + 2 + settings.move.y;
    85         pleft = this.offset().left + this.width()/2 - settings.instructionCss.width/2 + settings.move.x;
    86         if (pleft < 0) pleft = 0;
    87         if (pleft + settings.instructionCss.width > $( window ).width())
    88           pleft = $( window ).width() - settings.instructionCss.width;
    89         $.extend(settings.instructionCss, {bottom: pbottom, left: pleft} );
    90       }
    91      
    92       if (settings.placement == 'right') {
    93         ptop = this.offset().top + this.height()/2 - settings.instructionCss.height/2 + settings.move.y;
    94         pleft = this.offset().left + this.width() + 5 + settings.move.x;
    95         if (ptop < 0)
    96           ptop = 0;
    97         $.extend(settings.instructionCss, {top: ptop, left: pleft} );
    98       }
    99      
    100       if (settings.placement == 'left') {
    101         ptop = this.offset().top + this.height()/2 - settings.instructionCss.height/2 + settings.move.y;
    102         pleft = this.offset().left - settings.instructionCss.width - 5 + settings.move.x;
    103         if (ptop < 0)
    104           ptop = 0;
    105         $.extend(settings.instructionCss, {top: ptop, left: pleft} );
    106       }
    107      
    108      
    109       $(object).css(settings.instructionCss);
    110       //$('#nav_buttons').after(object);
    111       $('body').prepend(object);
    112     }
    113    
    114     if (settings.removeOnClick !== false) {
    115       $('#masking_overlay').one('click', function() { $.tutorial.remove();});
    116     }
    117    
    118     if (settings.removeOnClose !== false) {
    119       $('#tutorial_close').bind('click', function() {
    120         if (settings.removeOnClose == 'confirm') {
    121           if (confirm(settings.removeOnCloseConfirmText)) {
    122             $.tutorial.remove({'reload':true});
    123            
    124           }
    125         } else {
    126           $.tutorial.remove({'reload':true});
    127         }
    128       });
    129     }
    130    
    131     return this;
    132   };
    133  
    134   //overwritable options
    135   $.tutorial.defaults = {
    136       instruction: false,
    137       placement: 'below',
    138       css: {'z-index':'10001', 'position':'relative'},
    139       instructionCss: {'text-align': 'center', 'box-sizing':'border-box', 'width':300},
    140       pathway: 1,
    141       overlay:true,
    142       removeOnClick: false,
    143       move: {'x':0,'y':0},
    144       removeOnClose: 'confirm', //allowed values are false, true, and confirm
    145       removeOnCloseConfirmText: "Are you sure you want to stop the tutorial?"
    146       //width: 300
    147     };
    148  
    149  
    150   $.tutorial.remove = function( options ) {
    151     $('#masking_overlay').remove();
    152    
    153     var obj = $.tutorial.state.obj;
    154    
    155     if (typeof $.tutorial.state.oldinlinestyle === 'undefined')
    156       obj.removeAttr('style');
    157     else
    158       obj.attr('style', $.tutorial.state.oldinlinestyle);
    159      
    160      
    161     if (obj.prop("tagName") == 'A') {
    162       url = obj.attr('href');
    163       if (typeof url !== 'undefined') {
    164         if (url.search('tutorial=') != -1)
    165           obj.attr('href', url.substr(0,url.length-("&tutorial="+pathway).length));
    166       }
    167     }
    168    
    169     obj.find('a').each(function() {
    170       url = $(this).attr('href');
    171       if (typeof url !== 'undefined') {
    172         if (url.search('tutorial=') != -1)
    173           $(this).attr('href', url.substr(0,url.length-("&tutorial="+pathway).length));
    174       }
    175     });
    176    
    177     $('#tutorial_pass').remove();
    178    
    179    
    180     if ($.tutorial.state.instruction !== false) {
    181       $('#tutorial').remove();
    182     }
    183    
    184     if (options && options.reload) {
    185       url = window.location.href;
    186       if (url.search('tutorial=') != -1)
    187         window.location.replace(url.substr(0,url.length-("&tutorial="+pathway).length));
    188     }
    189    
    190   };
    191  
    192   $.fn.tutorial = $.tutorial;
     18        settings = $.tutorial.state.settings;
     19
     20        if (settings.overlay != false)
     21            $('body').append('<div id="masking_overlay"></div>');
     22
     23        /*$.each(settings.css, function ( key, value ) {
     24            $.tutorial.state.oldcss[key]=value;
     25        });*/
     26
     27        this.css(settings.css);
     28        pathway = settings.pathway;
     29        if (this.prop('tagName') == 'A') {
     30            url = this.attr('href');
     31            if (typeof url !== 'undefined') {
     32                if (url.indexOf('?') == -1)
     33                    this.attr('href', url + '?tutorial='+pathway);
     34                else
     35                    this.attr('href', url + '&tutorial='+pathway);
     36            }
     37        }
     38
     39        this.find('a').each(function() {
     40            url = $(this).attr('href');
     41            if (typeof url !== 'undefined') {
     42                if (url.indexOf('?') == -1)
     43                    $(this).attr('href', url + '?tutorial='+pathway);
     44                else
     45                    $(this).attr('href', url + '&tutorial='+pathway);
     46            }
     47        });
     48
     49        this.after('<input type="hidden" name="tutorial" id="tutorial_pass" value="'+pathway+'">');
     50
     51        if (settings.instruction !== false) {
     52            html = '<div id="tutorial">'+settings.instruction;
     53            if (settings.removeOnClose !== false)
     54                html += '<div id="tutorial_close">&nbsp;</div>';
     55            html += '</div>';
     56            object = $(html);
     57            if (settings.placement == 'below') {
     58                ptop = this.offset().top + this.height() + 2 + settings.move.y;
     59                pleft = this.offset().left + this.width()/2 - settings.instructionCss.width/2 + settings.move.x;;
     60                if (pleft < 0) pleft = 0;
     61                if (pleft + settings.instructionCss.width > $( window ).width())
     62                    pleft = $( window ).width() - settings.instructionCss.width;
     63                $.extend(settings.instructionCss, {top: ptop, left: pleft} );
     64            }
     65
     66            if (settings.placement == 'above') {
     67                pbottom = $(window).height() - this.offset().top + 2 + settings.move.y;
     68                pleft = this.offset().left + this.width()/2 - settings.instructionCss.width/2 + settings.move.x;
     69                if (pleft < 0) pleft = 0;
     70                if (pleft + settings.instructionCss.width > $( window ).width())
     71                    pleft = $( window ).width() - settings.instructionCss.width;
     72                $.extend(settings.instructionCss, {bottom: pbottom, left: pleft} );
     73            }
     74
     75            if (settings.placement == 'right') {
     76                ptop = this.offset().top + this.height()/2 - settings.instructionCss.height/2 + settings.move.y;
     77                pleft = this.offset().left + this.width() + 5 + settings.move.x;
     78                if (ptop < 0)
     79                    ptop = 0;
     80                $.extend(settings.instructionCss, {top: ptop, left: pleft} );
     81            }
     82
     83            if (settings.placement == 'left') {
     84                ptop = this.offset().top + this.height()/2 - settings.instructionCss.height/2 + settings.move.y;
     85                pleft = this.offset().left - settings.instructionCss.width - 5 + settings.move.x;
     86                if (ptop < 0)
     87                    ptop = 0;
     88                $.extend(settings.instructionCss, {top: ptop, left: pleft} );
     89            }
     90
     91
     92            $(object).css(settings.instructionCss);
     93            //$('#nav_buttons').after(object);
     94            $('body').prepend(object);
     95        }
     96
     97        if (settings.removeOnClick !== false) {
     98            $('#masking_overlay').one('click', function() { $.tutorial.remove();});
     99        }
     100
     101        if (settings.removeOnClose !== false) {
     102            $('#tutorial_close').bind('click', function() {
     103                if (settings.removeOnClose == 'confirm') {
     104                    if (confirm(settings.removeOnCloseConfirmText)) {
     105                        $.tutorial.remove({'reload':true});
     106
     107                    }
     108                } else {
     109                    $.tutorial.remove({'reload':true});
     110                }
     111            });
     112        }
     113
     114        return this;
     115    };
     116
     117    //overwritable options
     118    $.tutorial.defaults = {
     119        instruction: false,
     120        placement: 'below',
     121        css: {'z-index':'10001', 'position':'relative'},
     122        instructionCss: {'text-align': 'center', 'box-sizing':'border-box', 'width':300},
     123        pathway: 1,
     124        overlay:true,
     125        removeOnClick: false,
     126        move: {'x':0,'y':0},
     127        removeOnClose: 'confirm', //allowed values are false, true, and confirm
     128        removeOnCloseConfirmText: 'Are you sure you want to stop the tutorial?'
     129        //width: 300
     130    };
     131
     132
     133    $.tutorial.remove = function( options ) {
     134        $('#masking_overlay').remove();
     135
     136        var obj = $.tutorial.state.obj;
     137
     138        if (typeof $.tutorial.state.oldinlinestyle === 'undefined')
     139            obj.removeAttr('style');
     140        else
     141            obj.attr('style', $.tutorial.state.oldinlinestyle);
     142
     143
     144        if (obj.prop('tagName') == 'A') {
     145            url = obj.attr('href');
     146            if (typeof url !== 'undefined') {
     147                if (url.search('tutorial=') != -1)
     148                    obj.attr('href', url.substr(0,url.length-('&tutorial='+pathway).length));
     149            }
     150        }
     151
     152        obj.find('a').each(function() {
     153            url = $(this).attr('href');
     154            if (typeof url !== 'undefined') {
     155                if (url.search('tutorial=') != -1)
     156                    $(this).attr('href', url.substr(0,url.length-('&tutorial='+pathway).length));
     157            }
     158        });
     159
     160        $('#tutorial_pass').remove();
     161
     162
     163        if ($.tutorial.state.instruction !== false) {
     164            $('#tutorial').remove();
     165        }
     166
     167        if (options && options.reload) {
     168            url = window.location.href;
     169            if (url.search('tutorial=') != -1)
     170                window.location.replace(url.substr(0,url.length-('&tutorial='+pathway).length));
     171        }
     172
     173    };
     174
     175    $.fn.tutorial = $.tutorial;
    193176}( jQuery ));
  • shopsite-plugin/trunk/oauth.php

    r2010190 r3053843  
    4545
    4646  switch ($request_type) {
    47     case DOWNLOAD:
    48       $endpointurl = $json['download_url'];
    49       break;
    50     case UPLOAD:
    51       $endpointurl = $json['upload1_url'];
    52       break;
    53     case PUBLISH:
    54       $endpointurl = $json['publish_url'];
    55       break;
     47  case DOWNLOAD:
     48    $endpointurl = $json['download_url'];
     49    break;
     50  case UPLOAD:
     51    $endpointurl = $json['upload1_url'];
     52    break;
     53  case PUBLISH:
     54    $endpointurl = $json['publish_url'];
     55    break;
    5656  }
    5757  //debug_print("endpoint: ".$endpointurl);
  • shopsite-plugin/trunk/populate_products.js

    r1159065 r3053843  
    1 window.onload = populate_products;
    21
    3 function rfc3986EncodeURIComponent (str) { 
    4     return encodeURIComponent(str).replace(/[!'()*]/g, escape); 
     2function rfc3986EncodeURIComponent (str) {
     3    return encodeURIComponent(str).replace(/[!'()*]/g, escape);
    54}
    65
    76function isNumber(n) {
    8   return !isNaN(parseFloat(n)) && isFinite(n);
     7    return !isNaN(parseFloat(n)) && isFinite(n);
    98}
    109
    1110function populate_products() {
    12   //alert(id_list);
    13   //alert(path + "shopsite.php");
    14   $ = jQuery;
    15   $.ajax({
    16     async: true,
    17     type: 'POST',
    18     data: {ss_action:'get_data', shopsite_url:ss_shopsite_url, id_list: ss_id_list, identifier: ss_identifier},
    19     url: ss_path + "shopsite.php",
    20     success: function(data) {
    21       //alert(data);
    22       if (data.length > 1) {
    23         var products = data.split("\7");
    24         for (i in products) {
    25           if (products[i].length > 0) {
    26             var pair = products[i].split("\6");
    27             var id = rfc3986EncodeURIComponent(pair[0]);
    28             //alert(id);
    29             for (j in ss_product_map[id]) {
    30               if (isNumber(j))
    31                 $('#product_' + ss_product_map[id][j]).html(pair[1]);
    32             }
    33           }
    34         }
    35       }
    36     }
    37   });
    38   /*var wp_id = 1;
    39   while (typeof product_list['wp' + wp_id] != 'undefined') {
    40     //alert(wp_id + " " + product_list['wp' + wp_id]);
    41     wp_id++;
    42   }*/
     11    $ = jQuery;
     12    $.ajax({
     13        async: true,
     14        type: 'POST',
     15        data: {ss_action:'get_data', shopsite_url:ss_shopsite_url, id_list: ss_id_list, identifier: ss_identifier},
     16        url: ss_path + 'shopsite.php',
     17        success: function(data) {
     18            if (data.length > 1) {
     19                var products = data.split('\7');
     20                for (i in products) {
     21                    if (products[i].length > 0) {
     22                        var pair = products[i].split('\6');
     23                        var id = rfc3986EncodeURIComponent(pair[0]);
     24                        for (j in ss_product_map[id]) {
     25                            if (isNumber(j))
     26                                $('#product_' + ss_product_map[id][j]).html(pair[1]);
     27                        }
     28                    }
     29                }
     30            }
     31        }
     32    });
     33    /*
     34    var wp_id = 1;
     35    while (typeof product_list['wp' + wp_id] != 'undefined') {
     36        wp_id++;
     37    }*/
    4338}
     39window.addEventListener('load',populate_products);
  • shopsite-plugin/trunk/search_products.js

    r1159065 r3053843  
    1 window.onload = do_stuff;
     1$ = jQuery;
     2function do_stuff() {
     3    function search_products(string, rems) {
     4        $('#search_results').html('<div id=please_wait>Loading products... please wait</div>');
     5        var data = 'ss_action=search_products&search_string=' + string + '&remember_search=' + rems;
     6        $.ajax({
     7            async: true,
     8            data: data,
     9            url: 'shopsite.php',
     10            success:
     11            function(data) {
     12                $('#search_results').html(data);
     13            }
     14        });
     15    }
    216
    3 $ = jQuery;
     17    var ctrl = false;
     18    var shift = false;
     19    $(document).keydown(function(event){
     20        if(event.which=='17')
     21            ctrl = true;
     22        if(event.which=='16')
     23            shift = true;
    424
    5 function do_stuff() {
    6   /*$('#search_button').click(function() {
    7     search_products(encodeURIComponent($('#search_string').val()), $('#search_on').val(), $('#remember_search').is(':checked'));
    8   });
    9  
    10   $('#search_string').click(function() {
    11     if ($(this).val() == default_search_string)
    12       $(this).val('');
    13   });*/
    14  
    15   function search_products(string, rems) {
    16     $('#search_results').html("<div id=please_wait>Loading products... please wait</div>");
    17     var data = "ss_action=search_products&search_string=" + string + "&remember_search=" + rems;
    18     //alert(data);
    19     $.ajax({
    20       async: true,
    21       data: data,
    22       url: "shopsite.php",
    23       success:
    24       function(data) {
    25         $('#search_results').html(data);
    26       }
    27     });
    28   }
    29  
    30  
    31  
    32  
    33  
    34   var ctrl = false;
    35   var shift = false;
    36   $(document).keydown(function(event){
    37     if(event.which=="17")
    38         ctrl = true;
    39     if(event.which=="16")
    40         shift = true;
    41        
    42     if (event.which=="13" && $('#search_input').length && $('#search_input').is(':focus')) {
    43       $('#search_button').trigger('click');
    44     }
    45   });
     25        if (event.which=='13' && $('#search_input').length && $('#search_input').is(':focus')) {
     26            $('#search_button').trigger('click');
     27        }
     28    });
    4629
    47   $(document).keyup(function(event){
    48     if(event.which=="17")
    49         ctrl = false;
    50     if(event.which=="16")
    51         shift = false;
    52   });
     30    $(document).keyup(function(event){
     31        if(event.which=='17')
     32            ctrl = false;
     33        if(event.which=='16')
     34            shift = false;
     35    });
    5336
    54  
    55   var last_selected = false;
    56   $(document).on('click', '.wp_product', function() {
    57     var count = parseInt($(this).attr('id').substr(11));
    58     if (!ctrl)
    59       $('.selected_product').removeClass('selected_product');
    60    
    61    
    62     if (shift && last_selected) {
    63       if (count > last_selected) {
    64         for (i = last_selected; i <= count; i++) {
    65           $('#wp_product_'+i).addClass('selected_product');
    66         }
    67       } else {
    68         for (i = count; i <= last_selected; i++) {
    69           $('#wp_product_'+i).addClass('selected_product');
    70         }
    71       }
    72     } else {
    73       $(this).toggleClass('selected_product');
    74       last_selected = count;
    75     }
    76   });
    77  
    78   $(document).on('dblclick', '.wp_product', function() {
    79     $('.selected_product').removeClass('selected_product');
    80     $(this).addClass('selected_product');
    81     insert_shortcodes();
    82   });
    83  
    84   $(document).on('click', '#insert_button', function() {insert_shortcodes();});
    85  
    86  
    87  
    88  
    89  
    90   var search_performed = false;
    91  
    92  
    93   $('.tab').click(function() {
    94     if ($(this).hasClass('selected_tab'))
    95       return;
    96      
    97     $('.selected_tab').removeClass('selected_tab');
    98     $(this).addClass('selected_tab');
    99  
    100     if ($(this).attr('id') == 'search') {
    101       $(this).html('<input type=text id=search_input name=search_input value='+last_search_string+'><div id=search_button>Search</div>');
    102       $('#search_input').focus();
    103     } else {
    104       $('#tabs #search').html('Search');
    105       if (search_performed)
    106         search_products('*', 'true');
    107       search_performed = false;
    108     }
    109    
    110   });
    111  
    112  
    113   $(document).on('click', '#search_button', function() {
    114     search_products(encodeURIComponent($('#search_input').val()), 'true');
    115     search_performed = true;
    116     last_search_string = $('#search_input').val();
    117   });
    118  
    119  
    120   var last_search_string = "";
    121   if (ss_remembered_search_string == "*")
    122     search_products('*', 'true');
    123   else {
    124     last_search_string = ss_remembered_search_string;
    125     $('#search').trigger('click');
    126     $('#search_button').trigger('click');
    127   }
     37
     38    var last_selected = false;
     39    $(document).on('click', '.wp_product', function() {
     40        var count = parseInt($(this).attr('id').substr(11));
     41        if (!ctrl)
     42            $('.selected_product').removeClass('selected_product');
     43
     44
     45        if (shift && last_selected) {
     46            if (count > last_selected) {
     47                for (i = last_selected; i <= count; i++) {
     48                    $('#wp_product_'+i).addClass('selected_product');
     49                }
     50            } else {
     51                for (i = count; i <= last_selected; i++) {
     52                    $('#wp_product_'+i).addClass('selected_product');
     53                }
     54            }
     55        } else {
     56            $(this).toggleClass('selected_product');
     57            last_selected = count;
     58        }
     59    });
     60
     61    $(document).on('dblclick', '.wp_product', function() {
     62        $('.selected_product').removeClass('selected_product');
     63        $(this).addClass('selected_product');
     64        insert_shortcodes();
     65    });
     66
     67    $(document).on('click', '#insert_button', function() {insert_shortcodes();});
     68
     69    var search_performed = false;
     70
     71    $('.tab').click(function() {
     72        if ($(this).hasClass('selected_tab'))
     73            return;
     74
     75        $('.selected_tab').removeClass('selected_tab');
     76        $(this).addClass('selected_tab');
     77
     78        if ($(this).attr('id') == 'search') {
     79            $(this).html('<input type=text id=search_input name=search_input value='+last_search_string+'><div id=search_button>Search</div>');
     80            $('#search_input').focus();
     81        } else {
     82            $('#tabs #search').html('Search');
     83            if (search_performed)
     84                search_products('*', 'true');
     85            search_performed = false;
     86        }
     87    });
     88
     89
     90    $(document).on('click', '#search_button', function() {
     91        search_products(encodeURIComponent($('#search_input').val()), 'true');
     92        search_performed = true;
     93        last_search_string = $('#search_input').val();
     94    });
     95
     96
     97    var last_search_string = '';
     98    if (ss_remembered_search_string == '*')
     99        search_products('*', 'true');
     100    else {
     101        last_search_string = ss_remembered_search_string;
     102        $('#search').trigger('click');
     103        $('#search_button').trigger('click');
     104    }
    128105}
    129106
    130107function insert_shortcodes() {
    131   var shortcodes = "";
    132   $('.selected_product').each(function() {
    133     var shortcode = ("[ss_product id='"+$(this).find('.guid_input').val()+"' ");
    134    
    135     var sku = $(this).find('.sku_input').val()
    136     if (sku.length)
    137       shortcode += ("sku='"+sku+"' ");
    138     shortcode += "]"+$(this).find('.name_input').val()+"[/ss_product]";
    139    
    140     shortcodes += "<p>"+shortcode+"</p>";
    141   });
    142  
    143   tinyMCEPopup.execCommand('mceInsertContent', false, shortcodes);
    144   tinyMCEPopup.close();
     108    var shortcodes = '';
     109    $('.selected_product').each(function() {
     110        var shortcode = ('[ss_product id="'+$(this).find('.guid_input').val()+'"');
     111        var sku = $(this).find('.sku_input').val()
     112        if (sku.length)
     113            shortcode += (' sku="'+sku+'"');
     114        shortcode += ']'+$(this).find('.name_input').val()+'[/ss_product]';
     115
     116        shortcodes += '<p>'+shortcode+'</p>';
     117    });
     118
     119    tinyMCEPopup.execCommand('mceInsertContent', false, shortcodes);
     120    tinyMCEPopup.close();
    145121}
     122window.addEventListener('load',do_stuff);
  • shopsite-plugin/trunk/shopsite.css

    r1097525 r3053843  
    1 h1 {
    2   margin-bottom: 10px;
    3 }
    4 
    5 a#get_shopsite {
    6   display: inline-block;
    7 }
    8 
    9 div#masking_overlay {
    10   position:absolute;
    11   top:0;
    12   left:0;
    13   width:100%;
    14   height:100%;
    15   z-index:10000;
    16   opacity: 0.5;
    17   background-color: black;
    18 }
    19 
    20 div#tutorial {
    21   z-index: 10002;
    22   position: absolute;
    23   background-color: white;
    24   padding: 10px;
    25   text-align: center;
    26   border-radius: 4px;
    27 }
    28 
    29 div#tutorial_close {
    30   background-image: url(ui-icons_222222_256x240.png);
    31   background-position: -80px -128px;
    32   opacity: 0.2;
    33   height: 16px;
    34   width: 16px;
    35   position: absolute;
    36   top:0px;
    37   right:0px;
    38   cursor: pointer;
    39 }
    40 
    41 tbody#ss_11_settings {
    42   display: none;
    43 }
    44 
    45 a#ss_11, a#ss_12, a#proceed_tutorial {
    46   text-decoration: underline;
    47   cursor: pointer;
    48 }
    49 
    50 a#ss_11, a#ss_12 {
    51   display: block;
    52 }
    53 
    54 a#ss_11 {
    55   width: 300px;
    56 }
    57 
    58 #test_result {
    59   width: 400px;
    60 }
    61 
    62 #test_good {
    63   font-weight: bold;
    64   color:green;
    65 }
    66 
    67 #test_bad {
    68   font-weight: bold;
    69   color:red;
    70 }
    71 
    72 tr#store_url_instructions td {
    73   height: 30px;
    74   vertical-align: bottom;
    75 }
    76 
    77 
    78 
    79 
    80 
    81 
    82 
    83 
    84 
    85 
    86 
    87 div#please_wait, div#no_products, div#error_head {
    88   display: block;
    89   text-align: center;
    90   font-size: 20pt;
    91   width: 100%;
    92   color: gray;
    93   margin-top: 45px;
    94 }
    95 
    96 div#error_message {
    97   margin-top: 20px;
    98   margin-left: 50px;
    99   color: gray;
    100 }
    101 
    102 div#please_wait {
    103   cursor: wait;
    104   height: 600px;
    105 }
    106 
    107 div#over_limit_warning {
    108   text-align: center;
    109   margin-top: 65px;
    110   margin-bottom: 15px;
    111   font-size: 15px;
    112 }
    113 
    114 div#products {
    115   margin-top: 45px;
    116 }
    117 
    118 div.wp_product {
    119   float: left;
    120   width: 150px;
    121   height: 150px;
    122   padding: 3px;
    123   padding-top: 8px;
    124 
    125   box-sizing:border-box;
    126   border-radius: 4px;
    127   text-align: center;
    128   margin: 4px;
    129   background-color: white;
    130   position: relative;
    131   box-shadow: 1px 1px 3px #DFDFDF; -moz-box-shadow: 1px 1px 3px #DFDFDF; -webkit-box-shadow: 1px 1px 3px #DFDFDF;
    132   cursor: pointer;
    133  
    134  
    135   -webkit-touch-callout: none;
    136   -webkit-user-select: none;
    137   -khtml-user-select: none;
    138   -moz-user-select: none;
    139   -ms-user-select: none;
    140   user-select: none;
    141 }
    142 
    143 div.outdated {
    144   height: 80px;
    145   padding-top: 20px;
    146 }
    147 
    148 div.wp_product img {
    149   max-width:130px;
    150   max-height: 100px;
    151   /*border: 1px solid #dfdfdf;*/
    152   padding: 2px; 
    153 }
    154 
    155 div.outdated_shopsite {
    156   width: 130px;
    157   height: 60px;
    158   color: #CCCCCC;
    159   text-align:center;
    160   margin-left:auto;
    161   margin-right:auto;
    162 }
    163 
    164 a.product_name {
    165   display: block;
    166   overflow: hidden;
    167   max-height: 41px;
    168   color: black;
    169 }
    170 
    171 a.product_name:hover {
    172   color: black;
    173 }
    174 
    175 div.product_sku {
    176   background-color: white;
    177   opacity: 0.7;
    178   position: relative;
    179   margin-top: -20px;
    180   width: 130px;
    181   height: 19px;
    182   text-align: center;
    183   overflow: hidden;
    184   margin-left: auto;
    185   margin-right: auto;
    186 }
    187 
    188 div.selected_product {
    189   border: 3px solid #21759b;
    190 }
    191 
    192 div#bottom_fix {
    193   position: fixed;
    194   width:100%;
    195   bottom:0px;
    196   left:0px;
    197   height:60px;
    198   background-color: white;
    199   box-shadow: 0 0px 5px #CDCDCD; -moz-box-shadow: 0 0px 5px #CDCDCD; -webkit-box-shadow: 0 0px 5px #CDCDCD;
    200 }
    201 
    202 div#extra_message {
    203   margin-top: 5px;
    204   margin-bottom: -10px;
    205   margin-left: auto;
    206   margin-right: auto;
    207   text-align: center;
    208 }
    209 
    210 div#insert_button {
    211   background-color: #2ea2cc;
    212   border: 1px solid #0074a2;
    213   color: white;
    214   width: 300px;
    215   border-radius: 3px;
    216   font-size: 13px;
    217   margin-left: auto;
    218   margin-right: auto;
    219   line-height: 30px;
    220   margin-top: 15px;
    221   cursor: pointer;
    222   text-align: center;
    223 }
    224 
    225 #top_bar {
    226   position: fixed;
    227   width:100%;
    228   top:0px;
    229   left:0px;
    230   height:40px;
    231   background-color: white;
    232   z-index: 10;
    233   /*border-bottom: 3px solid #dfdfdf;*/
    234   box-sizing:border-box;
    235  
    236   box-shadow: 1px 1px 3px #DFDFDF; -moz-box-shadow: 1px 1px 3px #DFDFDF; -webkit-box-shadow: 1px 1px 3px #DFDFDF;
    237 }
    238 
    239 #top_bar #message {
    240   display: inline-block;
    241   margin-left: 10px;
    242   margin-top: 13px;
    243 }
    244 
    245 #top_bar #tabs {
    246   display: inline-block;
    247   position: absolute;
    248   left: 400px;
    249   top: 10px;
    250   padding: 0px;
    251   vertical-align: top;
    252 }
    253 
    254 #tabs .tab {
    255   display: inline-block;
    256   background-color: white;
    257   border-left: 1px solid #dfdfdf;
    258   border-right: 1px solid #dfdfdf;
    259   border-top: 1px solid #dfdfdf;
    260   padding-left: 15px;
    261   padding-right: 15px;
    262   margin-left: 6px;
    263   height: 30px;
    264  
    265   box-sizing:border-box;
    266   vertical-align: top;
    267   position: relative;
    268   border-top-right-radius: 3px;
    269   border-top-left-radius: 3px;
    270  
    271   font-size: 15px;
    272   padding-top: 5px;
    273   cursor: pointer;
    274  
    275 }
    276 
    277 #tabs .selected_tab {
    278   box-shadow: 0px 4px 0px white;
    279   cursor: default;
    280 }
    281 
    282 #search_input {
    283   width: 100px;
    284   height: 20px;
    285   display: inline-block;
    286   box-sizing:border-box;
    287   position: relative;
    288   vertical-align: bottom;
    289 }
    290 
    291 #search_button {
    292   font-size: 13px;
    293   /*background-color: #dfdfdf;*/
    294   padding: 2px;
    295   padding-left: 5px;
    296   padding-right: 5px;
    297   display: inline-block;
    298   box-sizing:border-box;
    299   height: 20px;
    300   position: relative;
    301   vertical-align: bottom;
    302   cursor: pointer;
    303 }
     1h1 {margin-bottom: 10px;}
     2a#get_shopsite {display: inline-block;}
     3div#masking_overlay {position:absolute;top:0;left:0;width:100%;height:100%;z-index:10000;opacity: 0.5; background-color: black;}
     4div#tutorial {z-index: 10002;position: absolute;background-color: white;padding: 10px;text-align: center;border-radius: 4px;}
     5div#tutorial_close {background-image: url(ui-icons_222222_256x240.png);background-position: -80px -128px;opacity: 0.2;height: 16px;width: 16px;position: absolute;top:0px;right:0px;cursor: pointer;}
     6tbody#ss_11_settings {display: none;}
     7a#ss_11, a#ss_12, a#proceed_tutorial {text-decoration: underline;cursor: pointer;}
     8a#ss_11, a#ss_12 {display: block;}
     9a#ss_11 {width: 300px;}
     10#test_result {width: 400px;}
     11#test_good {font-weight: bold;color:green;}
     12#test_bad {font-weight: bold;color:red;}
     13tr#store_url_instructions td {height: 30px;vertical-align: bottom;}
     14div#please_wait, div#no_products, div#error_head {display: block;text-align: center;font-size: 20pt;width: 100%;color: gray;margin-top: 45px;}
     15div#error_message {margin-top: 20px;margin-left: 50px;color: gray;}
     16div#please_wait {cursor: wait;height: 600px;}
     17div#over_limit_warning {text-align: center;margin-top: 65px;margin-bottom: 15px;font-size: 15px;}
     18div#products {margin-top: 45px;}
     19div.wp_product {float: left;width: 150px;height: 150px;padding: 3px;padding-top: 8px;
     20box-sizing:border-box;border-radius: 4px;text-align: center;margin: 4px;background-color: white;position: relative;box-shadow: 1px 1px 3px #DFDFDF; -moz-box-shadow: 1px 1px 3px #DFDFDF; -webkit-box-shadow: 1px 1px 3px #DFDFDF;cursor: pointer;-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;}
     21div.outdated {height: 80px;padding-top: 20px;}
     22div.wp_product img {max-width:130px;max-height: 100px;/*border: 1px solid #dfdfdf;*/padding: 2px;  }
     23div.outdated_shopsite {width: 130px;height: 60px;color: #CCCCCC;text-align:center;margin-left:auto;margin-right:auto;}
     24a.product_name {display: block;overflow: hidden;max-height: 41px;color: black;}
     25a.product_name:hover {color: black;}
     26div.product_sku {background-color: white;opacity: 0.7;position: relative;margin-top: -20px;width: 130px;height: 19px;text-align: center;overflow: hidden;margin-left: auto;margin-right: auto;}
     27div.selected_product {border: 3px solid #21759b;}
     28div#bottom_fix {position: fixed;width:100%;bottom:0px;left:0px;height:60px;background-color: white;box-shadow: 0 0px 5px #CDCDCD; -moz-box-shadow: 0 0px 5px #CDCDCD; -webkit-box-shadow: 0 0px 5px #CDCDCD;}
     29div#extra_message {margin-top: 5px;margin-bottom: -10px;margin-left: auto;margin-right: auto;text-align: center;}
     30div#insert_button {background-color: #2ea2cc;border: 1px solid #0074a2;color: white;width: 300px;border-radius: 3px;font-size: 13px;margin-left: auto;margin-right: auto;line-height: 30px;margin-top: 15px;cursor: pointer;text-align: center;}
     31#top_bar {position: fixed;width:100%;top:0px;left:0px;height:40px;background-color: white;z-index: 10;/*border-bottom: 3px solid #dfdfdf;*/box-sizing:border-box;box-shadow: 1px 1px 3px #DFDFDF; -moz-box-shadow: 1px 1px 3px #DFDFDF; -webkit-box-shadow: 1px 1px 3px #DFDFDF;}
     32#top_bar #message {display: inline-block;margin-left: 10px;margin-top: 13px;}
     33#top_bar #tabs {display: inline-block;position: absolute;left: 400px;top: 10px;padding: 0px;vertical-align: top;}
     34#tabs .tab {display: inline-block;background-color: white;border-left: 1px solid #dfdfdf;border-right: 1px solid #dfdfdf;border-top: 1px solid #dfdfdf;padding-left: 15px;padding-right: 15px;margin-left: 6px;height: 30px;box-sizing:border-box;vertical-align: top;position: relative;border-top-right-radius: 3px;border-top-left-radius: 3px;font-size: 15px;padding-top: 5px;cursor: pointer;}
     35#tabs .selected_tab {box-shadow: 0px 4px 0px white; cursor: default;}
     36#search_input {width: 100px;height: 20px;display: inline-block;box-sizing:border-box;position: relative;vertical-align: bottom;}
     37#search_button {font-size: 13px;/*background-color: #dfdfdf;*/padding: 2px;padding-left: 5px;padding-right: 5px;display: inline-block;box-sizing:border-box;height: 20px;position: relative;vertical-align: bottom;cursor: pointer;}
  • shopsite-plugin/trunk/shopsite.php

    r2034484 r3053843  
    22/**
    33 * @package ShopSite
    4  * @version 1.5.7
     4 * @version 1.5.8
    55 */
    66/*
    7 Plugin Name: ShopSite
    8 Plugin URI: http://shopsite.com/
    9 Description: ShopSite plugin to put products into your WordPress blog
    10 Author: ShopSite
    11 Version: 1.5.7
    12 Author URI: http://shopsite.com/
     7 * Plugin Name: ShopSite
     8 * Plugin URI: http://shopsite.com/
     9 * Description: ShopSite plugin to put products into your WordPress blog
     10 * Author: ShopSite
     11 * Version: 1.5.8
     12 * Author URI: http://shopsite.com/
    1313 */
    1414
    1515if (isset($_REQUEST['ss_action'])) {
    16   //taken from http://plugins.svn.wordpress.org/limelight-networks/trunk/limelight_popup.php
    17   if ( !defined('WP_LOAD_PATH') ) {
    18     $classic_root = dirname( dirname( dirname( dirname(__FILE__) ) ) ) . '/' ;
    19     if (file_exists( $classic_root . 'wp-load.php') )
    20       define( 'WP_LOAD_PATH' , $classic_root );
    21     else
    22       exit( 'Could not find wp-load.php' );
    23   }
    24   require_once(WP_LOAD_PATH.'wp-load.php');
    25 
    26   //debug_print("Called with action ".$_REQUEST['ss_action']);
    27   if ($_REQUEST['ss_action'] == 'insert')
    28     show_search_form();
    29   if ($_REQUEST['ss_action'] == 'search_products')
    30     get_product_list();
    31   if ($_REQUEST['ss_action'] == 'get_data')
    32     get_product_data(($_REQUEST['id_list']));
    33   exit(0);
     16    //taken from http://plugins.svn.wordpress.org/limelight-networks/trunk/limelight_popup.php
     17    if ( !defined('WP_LOAD_PATH') ) {
     18        $classic_root = dirname( dirname( dirname( dirname(__FILE__) ) ) ) . '/' ;
     19        if (file_exists( $classic_root . 'wp-load.php') )
     20            define( 'WP_LOAD_PATH' , $classic_root );
     21        else
     22            exit( 'Could not find wp-load.php' );
     23    }
     24    require_once(WP_LOAD_PATH.'wp-load.php');
     25
     26    //debug_print("Called with action ".$_REQUEST['ss_action']);
     27    if ($_REQUEST['ss_action'] == 'insert')
     28        show_search_form();
     29    if ($_REQUEST['ss_action'] == 'search_products')
     30        get_product_list();
     31    if ($_REQUEST['ss_action'] == 'get_data')
     32        get_product_data(($_REQUEST['id_list']));
     33    exit(0);
    3434}
    3535
     
    4141register_activation_hook( __FILE__, 'on_activate' );
    4242function on_activate() {
    43   add_option('ss_just_activated','yes');
     43    add_option('ss_just_activated','yes');
    4444}
    4545
    4646function on_uninstall() {
    47   $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url', 'version');
    48   foreach ($option_list as $option) {
    49     delete_option('ss_'.$option);
    50   }
     47    $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url', 'version');
     48    foreach ($option_list as $option) {
     49        delete_option('ss_'.$option);
     50    }
    5151}
    5252
    5353function load_plugin() {
    54   $version = "1.5.7";
    55   if ( is_admin() ) { 
    56     $running_version = get_option('ss_version');
    57     if (!$running_version)
    58       $running_version = "1";
    59 
    60     update_option('ss_version', $version);
    61     if ($running_version < "1.5.1") {
    62           //updating, rename to ss_ options to prevent conflicts with other plugins
    63       $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url');
    64       foreach ($option_list as $option) {
    65         $option_val = get_option($option);
    66         if ($option_val) {
    67           update_option('ss_'.$option, $option_val);
    68           delete_option($option);
    69         } else
    70           add_option('ss_'.$option);
    71       }
    72     }
    73 
    74     if (get_option('ss_just_activated')) {
    75       delete_option( 'ss_just_activated' );
    76       $shopsite_url = get_option('ss_shopsite_url');
    77       if ($shopsite_url == false || strlen($shopsite_url) < 10) {
    78         add_action( 'admin_head', 'start_tutorial');
    79       }
    80     }
    81   }
     54    $version = "1.5.7";
     55    if ( is_admin() ) { 
     56        $running_version = get_option('ss_version');
     57        if (!$running_version)
     58            $running_version = "1";
     59
     60        update_option('ss_version', $version);
     61        if ($running_version < "1.5.1") {
     62            //updating, rename to ss_ options to prevent conflicts with other plugins
     63            $option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url');
     64            foreach ($option_list as $option) {
     65                $option_val = get_option($option);
     66                if ($option_val) {
     67                    update_option('ss_'.$option, $option_val);
     68                    delete_option($option);
     69                } else
     70                    add_option('ss_'.$option);
     71            }
     72        }
     73
     74        if (get_option('ss_just_activated')) {
     75            delete_option( 'ss_just_activated' );
     76            $shopsite_url = get_option('ss_shopsite_url');
     77            if ($shopsite_url == false || strlen($shopsite_url) < 10) {
     78                add_action( 'admin_head', 'start_tutorial');
     79            }
     80        }
     81    }
    8282}
    8383
    8484function start_tutorial() {
    85   echo "<script>start_tutorial();</script>"; 
     85    echo "<script>start_tutorial();</script>"; 
    8686}
    8787
    8888function request_output_url() {
    89   echo "<script>request_output_url();</script>"; 
     89    echo "<script>request_output_url();</script>"; 
    9090}
    9191
    9292function link_tutorial() {
    93   echo "<script> $ = jQuery;</script>";
    94   echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."jquery.tutorial.js></script>";
    95   echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."tutorial_driver.js></script>";
    96   echo "<link rel='stylesheet' href=".plugin_dir_url(__FILE__)."shopsite.css type='text/css' />";
     93    echo "<script> $ = jQuery;</script>";
     94    echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."jquery.tutorial.js></script>";
     95    echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."tutorial_driver.js></script>";
     96    echo "<link rel='stylesheet' href=".plugin_dir_url(__FILE__)."shopsite.css type='text/css' />";
    9797}
    9898
    9999function link_ss_path() {
    100   echo "<script>var ss_path='".plugin_dir_url(__FILE__)."';</script>";
     100    echo "<script>var ss_path='".plugin_dir_url(__FILE__)."';</script>";
    101101}
    102102
     
    115115
    116116function add_shopsite_settings_link($links, $file) {
    117   if($file === plugin_basename(__FILE__)) {
    118     $links = (array) $links;
    119     $links[] = '<a href="'.admin_url('options-general.php?page=shopsite_menu').'">Settings</a>';
    120   }
    121   return $links;
     117    if($file === plugin_basename(__FILE__)) {
     118        $links = (array) $links;
     119        $links[] = '<a href="'.admin_url('options-general.php?page=shopsite_menu').'">Settings</a>';
     120    }
     121    return $links;
    122122}
    123123
    124124function add_shopsite_menu() {
    125   add_submenu_page( "options-general.php", "ShopSite", "ShopSite", "manage_options", "shopsite_menu", "show_shopsite_menu" );
     125    add_submenu_page( "options-general.php", "ShopSite", "ShopSite", "manage_options", "shopsite_menu", "show_shopsite_menu" );
    126126}
    127127
    128128function show_shopsite_menu() {
    129   global $wpdb;
    130   include_once "oauth.php";
    131   $testing = false;
    132   $state = 'new_config';
    133 
    134   /*$option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url');
    135   foreach ($option_list as $option) {
    136     echo "<br>$option  |".get_option($option)."| |".get_option('ss_'.$option)."|";
    137   }*/
    138 
    139 
    140   if (isset($_REQUEST['config_type'])) {
    141 
    142     $config_type = trim($_REQUEST['config_type']);
    143     //echo "<script>alert('$config_type');</script>";
    144 
    145     update_option('ss_config_type', $config_type);
    146     $state = 'settings_saved';
    147 
    148     delete_option('ss_media_url');
    149 
    150     if ($config_type == 'ss_12') {
    151       update_option('ss_config_dump', trim($_REQUEST['config_dump']));
    152 
    153 
    154       $decoded = base64_decode(trim($_REQUEST['config_dump']));
    155       $decoded = explode('^',$decoded);
    156 
    157       update_option('ss_clientid', trim($decoded[0]));
    158       update_option('ss_secretkey', trim($decoded[1]));
    159       update_option('ss_code', trim($decoded[2]));
    160       update_option('ss_authorizationurl', trim($decoded[3]));
    161       update_option('ss_shopsite_url', trim($decoded[4]));
    162     } else {
    163 
    164       $clientid = trim($_REQUEST['clientid']); update_option('ss_clientid', $clientid);
    165       $secretkey = trim($_REQUEST['secretkey']); update_option('ss_secretkey', $secretkey);
    166       $code = trim($_REQUEST['code']); update_option('ss_code', $code);
    167       $authorizationurl = trim($_REQUEST['authorizationurl']); update_option('ss_authorizationurl', $authorizationurl);
    168       $shopsite_url = trim($_REQUEST['shopsite_url']); update_option('ss_shopsite_url', $shopsite_url);
    169       $config_dump = base64_encode("$clientid^$secretkey^$code^$authorizationurl^$shopsite_url");
    170       update_option('ss_config_dump', $config_dump);
    171     }
    172   }
    173 
    174   if (isset($_REQUEST['identifier'])) update_option('ss_identifier', trim($_REQUEST['identifier']));
    175   if (isset($_REQUEST['test'])) {
    176     $testing = true;
    177     $test_result = test_connection();
    178     $state = 'testing_completed';
    179   }
    180 
    181   $config_type = get_option('ss_config_type');
    182   if (strlen($config_type) == 0)
    183     $config_type = 'ss_12';
    184   $config_dump = get_option('ss_config_dump');
    185   $shopsite_url = get_option('ss_shopsite_url');
    186   $clientid = get_option('ss_clientid');
    187   $secretkey = get_option('ss_secretkey');
    188   $code = get_option('ss_code');
    189   $authorizationurl = get_option('ss_authorizationurl');
    190 
    191 
    192   $identifier = get_option('ss_identifier');
    193 
    194   $SKU_selected = $GUID_selected = "";
    195   if ($identifier == 'SKU')
    196     $SKU_selected = "checked";
    197   else
    198     $GUID_selected = "checked";
    199 
    200   $ss_12_extra = "";
    201   $ss_11_extra = "";
    202   if ($config_type == 'ss_11') {
    203     $ss_12_extra = " style='display:none;'";
    204     $ss_11_extra = " style='display:table-row-group;'";
    205   }
    206 
    207   //ss_action=plugins.php?page=shopsite_menu
    208   echo
    209     "<script>
    210 
    211     \$('#ss_11').live('click', function() {\$('#config_type').val('ss_11'); \$('#ss_12_settings').css({'display':'none'}); \$('#ss_11_settings').css({'display':'table-row-group'}); });
    212   \$('#ss_12').live('click', function() {\$('#config_type').val('ss_12'); \$('#ss_11_settings').css({'display':'none'}); \$('#ss_12_settings').css({'display':'table-row-group'}); });
    213     </script>";
    214 
    215   echo 
    216     "<h1>ShopSite configuration</h1>
    217     Don't have a ShopSite store? <a id=get_shopsite target=_blank href='https://saas.shopsite.com/express/'>Get a free 10-product Express store</a>.
    218     <form method=post>
    219     <input type=hidden id=config_type name=config_type value=$config_type>
    220     <table>
    221     <thead><tr><th colspan=2>Application settings</th></tr></thead>";
    222 
    223   echo
    224     "<tbody id='ss_12_settings' $ss_12_extra><tr><td>Configuration data (paste from ShopSite)
    225     <br><a id=ss_11>Click here if you have 5 fields to copy and paste in your ShopSite backoffice WordPress config</a></td>
    226     <td><textarea name=config_dump id=config_dump style='height:100px;width:675px;'>$config_dump</textarea></td></tr></tbody>";
    227 
    228 
    229   echo
    230     "<tbody id='ss_11_settings' $ss_11_extra>
    231     <tr><td colspan=2><a id=ss_12>Click here if you only have 1 field to paste in your ShopSite backoffice WordPress config</a></td></tr>
    232     <tr><td>Client ID:</td><td><input type=text name=clientid id=clientid value='$clientid' size=100></td></tr>
    233     <tr><td>Secret Key for Signing:</td><td><input type=text name=secretkey id=secretkey value='$secretkey' size=100></td></tr>
    234     <tr><td>Authorization Code:</td><td><input type=text name=code id=code value='$code' size=100></td></tr>
    235     <tr><td>Authorization URL:</td><td><input type=text name=authorizationurl id=authorizationurl value='$authorizationurl' size=100></td></tr>
    236     <tr><td>ShopSite callback URL:</td><td><input type=text name=shopsite_url value='$shopsite_url' size=100></td></tr>";
    237 
    238   echo
    239     "</tbody>";
    240 
    241   echo "<tbody><tr><th colspan=2>Other settings</th></tr>
    242     <tr><td>Unique product identifier:</td>
    243     <td>
    244     <input type=radio name=identifier value='GUID' $GUID_selected/>Global unique ID<br/>
    245     <input type=radio name=identifier value='SKU' $SKU_selected/>SKU</td></tr>
    246     </tbody></table>
    247     <br/><input type=submit name=test id=test_connection value='Test connection'>";
    248 
    249   if ($testing) {
    250     echo "<div id=test_result>";
    251     if ($test_result['success'] == true)
    252       echo "<p id=\"test_good\">Connection test successful</p>";
    253     if ($test_result['success'] == false) {
    254       echo "<p id=\"test_bad\">Connection test failed, check your settings.<br>Error: ".$test_result["error"]."</p>";
    255     }
    256     echo "</div>";
    257 
    258   }
    259 
    260   echo "<input type=hidden name=state id=state value=$state>";
    261   echo "<br/><input type=submit id=save_settings value='Save settings'></form>";
     129    global $wpdb;
     130    include_once "oauth.php";
     131    $testing = false;
     132    $state = 'new_config';
     133
     134    /*$option_list = array('shopsite_url', 'config_dump', 'config_type', 'clientid', 'secretkey', 'code', 'authorizationurl', 'identifier', 'remember_search', 'remembered_search_string', 'media_url');
     135    foreach ($option_list as $option) {
     136        echo "<br>$option  |".get_option($option)."| |".get_option('ss_'.$option)."|";
     137    }*/
     138
     139
     140    if (isset($_REQUEST['config_type'])) {
     141
     142        $config_type = trim($_REQUEST['config_type']);
     143        //echo "<script>alert('$config_type');</script>";
     144
     145        update_option('ss_config_type', $config_type);
     146        $state = 'settings_saved';
     147
     148        delete_option('ss_media_url');
     149
     150        if ($config_type == 'ss_12') {
     151            update_option('ss_config_dump', trim($_REQUEST['config_dump']));
     152
     153
     154            $decoded = base64_decode(trim($_REQUEST['config_dump']));
     155            $decoded = explode('^',$decoded);
     156
     157            update_option('ss_clientid', trim($decoded[0]));
     158            update_option('ss_secretkey', trim($decoded[1]));
     159            update_option('ss_code', trim($decoded[2]));
     160            update_option('ss_authorizationurl', trim($decoded[3]));
     161            update_option('ss_shopsite_url', trim($decoded[4]));
     162        } else {
     163
     164            $clientid = trim($_REQUEST['clientid']); update_option('ss_clientid', $clientid);
     165            $secretkey = trim($_REQUEST['secretkey']); update_option('ss_secretkey', $secretkey);
     166            $code = trim($_REQUEST['code']); update_option('ss_code', $code);
     167            $authorizationurl = trim($_REQUEST['authorizationurl']); update_option('ss_authorizationurl', $authorizationurl);
     168            $shopsite_url = trim($_REQUEST['shopsite_url']); update_option('ss_shopsite_url', $shopsite_url);
     169            $config_dump = base64_encode("$clientid^$secretkey^$code^$authorizationurl^$shopsite_url");
     170            update_option('ss_config_dump', $config_dump);
     171        }
     172    }
     173
     174    if (isset($_REQUEST['identifier'])) update_option('ss_identifier', trim($_REQUEST['identifier']));
     175    if (isset($_REQUEST['test'])) {
     176        $testing = true;
     177        $test_result = test_connection();
     178        $state = 'testing_completed';
     179    }
     180
     181    $config_type = get_option('ss_config_type');
     182    if (strlen($config_type) == 0)
     183        $config_type = 'ss_12';
     184    $config_dump = get_option('ss_config_dump');
     185    $shopsite_url = get_option('ss_shopsite_url');
     186    $clientid = get_option('ss_clientid');
     187    $secretkey = get_option('ss_secretkey');
     188    $code = get_option('ss_code');
     189    $authorizationurl = get_option('ss_authorizationurl');
     190
     191
     192    $identifier = get_option('ss_identifier');
     193
     194    $SKU_selected = $GUID_selected = "";
     195    if ($identifier == 'SKU')
     196        $SKU_selected = "checked";
     197    else
     198        $GUID_selected = "checked";
     199
     200    $ss_12_extra = "";
     201    $ss_11_extra = "";
     202    if ($config_type == 'ss_11') {
     203        $ss_12_extra = " style='display:none;'";
     204        $ss_11_extra = " style='display:table-row-group;'";
     205    }
     206
     207    //ss_action=plugins.php?page=shopsite_menu
     208    echo
     209        "<script>
     210
     211        \$('#ss_11').live('click', function() {\$('#config_type').val('ss_11'); \$('#ss_12_settings').css({'display':'none'}); \$('#ss_11_settings').css({'display':'table-row-group'}); });
     212    \$('#ss_12').live('click', function() {\$('#config_type').val('ss_12'); \$('#ss_11_settings').css({'display':'none'}); \$('#ss_12_settings').css({'display':'table-row-group'}); });
     213        </script>";
     214
     215    echo   
     216        "<h1>ShopSite configuration</h1>
     217        Don't have a ShopSite store? <a id=get_shopsite target=_blank href='https://saas.shopsite.com/express/'>Get a free 10-product Express store</a>.
     218        <form method=post>
     219        <input type=hidden id=config_type name=config_type value=$config_type>
     220        <table>
     221        <thead><tr><th colspan=2>Application settings</th></tr></thead>";
     222
     223    echo
     224        "<tbody id='ss_12_settings' $ss_12_extra><tr><td>Configuration data (paste from ShopSite)
     225        <br><a id=ss_11>Click here if you have 5 fields to copy and paste in your ShopSite backoffice WordPress config</a></td>
     226        <td><textarea name=config_dump id=config_dump style='height:100px;width:675px;'>$config_dump</textarea></td></tr></tbody>";
     227
     228
     229    echo
     230        "<tbody id='ss_11_settings' $ss_11_extra>
     231        <tr><td colspan=2><a id=ss_12>Click here if you only have 1 field to paste in your ShopSite backoffice WordPress config</a></td></tr>
     232        <tr><td>Client ID:</td><td><input type=text name=clientid id=clientid value='$clientid' size=100></td></tr>
     233        <tr><td>Secret Key for Signing:</td><td><input type=text name=secretkey id=secretkey value='$secretkey' size=100></td></tr>
     234        <tr><td>Authorization Code:</td><td><input type=text name=code id=code value='$code' size=100></td></tr>
     235        <tr><td>Authorization URL:</td><td><input type=text name=authorizationurl id=authorizationurl value='$authorizationurl' size=100></td></tr>
     236        <tr><td>ShopSite callback URL:</td><td><input type=text name=shopsite_url value='$shopsite_url' size=100></td></tr>";
     237
     238    echo
     239        "</tbody>";
     240
     241    echo "<tbody><tr><th colspan=2>Other settings</th></tr>
     242        <tr><td>Unique product identifier:</td>
     243        <td>
     244        <input type=radio name=identifier value='GUID' $GUID_selected/>Global unique ID<br/>
     245        <input type=radio name=identifier value='SKU' $SKU_selected/>SKU</td></tr>
     246        </tbody></table>
     247        <br/><input type=submit name=test id=test_connection value='Test connection'>";
     248
     249    if ($testing) {
     250        echo "<div id=test_result>";
     251        if ($test_result['success'] == true)
     252            echo "<p id=\"test_good\">Connection test successful</p>";
     253        if ($test_result['success'] == false) {
     254            echo "<p id=\"test_bad\">Connection test failed, check your settings.<br>Error: ".$test_result["error"]."</p>";
     255        }
     256        echo "</div>";
     257
     258    }
     259
     260    echo "<input type=hidden name=state id=state value=$state>";
     261    echo "<br/><input type=submit id=save_settings value='Save settings'></form>";
    262262}
    263263
    264264function shopsite_addbuttons() {
    265   // Don't bother doing this stuff if the current user lacks permissions
    266   if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
    267     return;
    268 
    269   // Add only in Rich Editor mode
    270   if ( get_user_option('rich_editing') == 'true') {
    271     add_filter("mce_external_plugins", "add_shopsite_tinymce_plugin");
    272     add_filter('mce_buttons', 'register_shopsite_button');
    273   }
     265    // Don't bother doing this stuff if the current user lacks permissions
     266    if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') )
     267        return;
     268
     269    // Add only in Rich Editor mode
     270    if ( get_user_option('rich_editing') == 'true') {
     271        add_filter("mce_external_plugins", "add_shopsite_tinymce_plugin");
     272        add_filter('mce_buttons', 'register_shopsite_button');
     273    }
    274274}
    275275
    276276function register_shopsite_button($buttons) {
    277   array_push($buttons, "separator", "shopsite");
    278   return $buttons;
     277    array_push($buttons, "separator", "shopsite");
     278    return $buttons;
    279279}
    280280
    281281// Load the TinyMCE plugin : editor_plugin.js (wp2.5)
    282282function add_shopsite_tinymce_plugin($plugin_array) {
    283   $path = plugin_dir_url(__FILE__).'editor_plugin.js';
    284   $plugin_array['shopsite'] = $path;
    285   return $plugin_array;
     283    $path = plugin_dir_url(__FILE__).'editor_plugin.js';
     284    $plugin_array['shopsite'] = $path;
     285    return $plugin_array;
    286286}
    287287
    288288function show_search_form() {
    289289
    290   $tinymce_url = includes_url()."js/tinymce/tiny_mce_popup.js";
    291   $jquery_url = includes_url()."js/jquery/jquery.js";
    292 
    293   $search_string = "*";
    294 
    295   $remember_search = "";
    296   $selected_name = "";
    297   $selected_sku = "";
    298   if (get_option('ss_remember_search') == 'true') {
    299       $remember_search = "checked";
    300 
    301     if (strlen(get_option('ss_remembered_search_string')))
    302       $search_string = get_option('ss_remembered_search_string');
    303   }
    304 
    305   echo "
    306   <html>
    307   <head>
    308   <script type='text/javascript' src='".$jquery_url."'></script>\n";
    309   link_tutorial();
    310   echo"<script type='text/javascript' src='".$tinymce_url."'></script>\n
    311   <script type='text/javascript' src='".plugin_dir_url(__FILE__)."search_products.js?".time()."'></script>
    312   <script type='text/javascript'> var ss_remembered_search_string = '".$search_string."';</script>
    313   </head>
    314   <body>";
    315   echo "<div id=top_bar>";
    316   echo "<div id=message>You can use CTRL and SHIFT keys to select multiple products.</div>"; 
    317   echo "<div id=tabs>";
    318   echo "<div class='tab selected_tab' id=list_all>List all products</div><div class=tab id=search>Search</div>";
    319   echo "</div>";
    320   echo "</div>";
    321   echo "<div id=search_results></div>";
    322 
    323   $extra_space = "";
    324   $message = "";
    325   $media_url = get_media_url();
    326   if (!$media_url)
    327   {
    328     $extra_space = " style='height:80px;'";
    329     $message = "<div id=extra_message>Upgrade your store to ShopSite v12 sp1 or greater to see product images above.</div>";
    330   }
    331 
    332   echo "<div id=\"bottom_fix\"$extra_space>$message<div id=\"insert_button\">Insert selected products into post</div></div>";
    333 
    334   echo "
    335   </body>
    336   </html>";
     290    $tinymce_url = includes_url()."js/tinymce/tiny_mce_popup.js";
     291    $jquery_url = includes_url()."js/jquery/jquery.js";
     292
     293    $search_string = "*";
     294
     295    $remember_search = "";
     296    $selected_name = "";
     297    $selected_sku = "";
     298    if (get_option('ss_remember_search') == 'true') {
     299            $remember_search = "checked";
     300
     301        if (strlen(get_option('ss_remembered_search_string')))
     302            $search_string = get_option('ss_remembered_search_string');
     303    }
     304
     305    echo "
     306    <html>
     307    <head>
     308    <script type='text/javascript' src='".$jquery_url."'></script>\n";
     309    link_tutorial();
     310    echo"<script type='text/javascript' src='".$tinymce_url."'></script>\n
     311    <script type='text/javascript' src='".plugin_dir_url(__FILE__)."search_products.js?".time()."'></script>
     312    <script type='text/javascript'> var ss_remembered_search_string = '".$search_string."';</script>
     313    </head>
     314    <body>";
     315    echo "<div id=top_bar>";
     316    echo "<div id=message>You can use CTRL and SHIFT keys to select multiple products.</div>"; 
     317    echo "<div id=tabs>";
     318    echo "<div class='tab selected_tab' id=list_all>List all products</div><div class=tab id=search>Search</div>";
     319    echo "</div>";
     320    echo "</div>";
     321    echo "<div id=search_results></div>";
     322
     323    $extra_space = "";
     324    $message = "";
     325    $media_url = get_media_url();
     326    if (!$media_url)
     327    {
     328        $extra_space = " style='height:80px;'";
     329        $message = "<div id=extra_message>Upgrade your store to ShopSite v12 sp1 or greater to see product images above.</div>";
     330    }
     331
     332    echo "<div id=\"bottom_fix\"$extra_space>$message<div id=\"insert_button\">Insert selected products into post</div></div>";
     333
     334    echo "
     335    </body>
     336    </html>";
    337337}
    338338
    339339function get_media_url() {
    340   $media_url = get_option('ss_media_url');
    341   if (!$media_url) {
    342     $shopsite_url = get_option('ss_shopsite_url');
    343     $url = $shopsite_url."&operation=get_setting&setting=output_url"; 
    344     $resp = get_url($url);
    345     $outputurl = $resp[0];
    346     if ($outputurl && strlen($outputurl) > 10) {
    347       $media_url = $outputurl."/media/";
    348       update_option('ss_media_url', $media_url);
    349     }
    350   }
    351   return $media_url;
     340    $media_url = get_option('ss_media_url');
     341    if (!$media_url) {
     342        $shopsite_url = get_option('ss_shopsite_url');
     343        $url = $shopsite_url."&operation=get_setting&setting=output_url"; 
     344        $resp = get_url($url);
     345        $outputurl = $resp[0];
     346        if ($outputurl && strlen($outputurl) > 10) {
     347            $media_url = $outputurl."/media/";
     348            update_option('ss_media_url', $media_url);
     349        }
     350    }
     351    return $media_url;
    352352}
    353353
    354354
    355355function get_product_list() {
    356   include_once "oauth.php";
    357   $limit = 1000;
    358   //echo ("in:|".$_REQUEST['search_string']."|<br>");
    359   $search_string = stripslashes(trim($_REQUEST['search_string']));
    360 
    361   $remember_search = $_REQUEST['remember_search'];
    362 
    363   ///debug_print("Updating remember_search to $remember_search");
    364   update_option('ss_remember_search', $remember_search);
    365 
    366   if ($remember_search == 'true') {
    367     update_option('ss_remembered_search_string', $search_string);
    368   }
    369 
    370 
    371   $shopsite_url = get_option('ss_shopsite_url');
    372 
    373 
    374   $media_url = get_media_url();
    375 
    376   $list_all = false;
    377   if ($search_string == '*') {
    378     $search_array = array();
    379     $list_all = true;
    380   }
    381 
    382   if (!$list_all) {
    383     if ($media_url)
    384       $search_array = array('search_on'=>"name,sku", 'search_term'=>$search_string, 'search_filter'=>'contains');
    385     else
    386       $search_array = array('search_on'=>"name", 'search_term'=>$search_string, 'search_filter'=>'contains');
    387   }
    388 
    389   $products_xml = oauth(
    390     get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
    391     DOWNLOAD,
    392     array_merge(array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|Graphic|', 'limit'=>$limit), $search_array)
    393   );
    394 
    395   //debug_print(print_r(html_entity_decode($products_xml['data']),true));
    396 
    397   if (!$products_xml['success']) {
    398     echo "<div id=error_head>Unfortunately, something went wrong.</div>";
    399     echo "<div id=error_message>Detailed error message: <br>".$products_xml['error']."</div>";
    400     exit(1);
    401   }
    402   $products_ar = array();
    403   //html_entity_decode($string, ENT_QUOTES, "utf-8");
    404   //libxml_use_internal_errors(1);
    405   libxml_disable_entity_loader(false);
    406   //$products = simplexml_load_string(html_entity_decode($products_xml['data'], ENT_QUOTES, "ISO-8859-1"));
    407   //$products = simplexml_load_string($products_xml['data']);
    408   $products = simplexml_load_string($products_xml['data'], 'SimpleXMLElement', LIBXML_NOENT);
    409   if (count($products->Products->Product) > 0) {
    410     foreach ($products->Products->Product as $product) {
    411       $products_ar[addslashes($product->Name)] = array($product->ProductGUID, $product->SKU, $product->Graphic);
    412     }
    413   }
    414 
    415   //if media_url is absent, that means shopsite's XML API can't handle searches on multiple fields at once. We'll perform two separate searches then.
    416   if (!$list_all && !$media_url) {
    417     $search_array = array('search_on'=>"sku", 'search_term'=>$search_string, 'search_filter'=>'contains');
    418     $products_xml = oauth(
    419       get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
    420       DOWNLOAD,
    421       array_merge(array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|Graphic|', 'limit'=>$limit), $search_array)
    422     );
    423     $products = /*new SimpleXMLElement*/simplexml_load_string ($products_xml['data'], 'SimpleXMLElement');
    424     if (count($products->Products->Product) > 0) {
    425       foreach ($products->Products->Product as $product) {
    426         if (!array_key_exists(addslashes($product->Name), $products_ar))
    427           $products_ar[addslashes($product->Name)] = array($product->ProductGUID, $product->SKU, $product->Graphic);
    428       }
    429     }
    430   }
    431 
    432   if (count($products_ar) == 0) {
    433     echo "<div id=no_products>No matching products.</div>";
    434     return;
    435   }
    436 
    437 
    438   ksort($products_ar);
    439   $products_ar = array_slice($products_ar,0,$limit);
    440 
    441   echo "<div id=\"products\">";
    442   if (count($products_ar) == $limit) {
    443     echo "<div id=\"over_limit_warning\">Displaying first $limit products only. Please use \"Search\" button to narrow down your results.</div>";
    444   }
    445   $count = 1;
    446   foreach ($products_ar as $name => $data) {
    447     print_product($count, stripslashes($name), $data, $media_url);
    448     $count++;
    449   }
    450   echo "</div>";
     356    include_once "oauth.php";
     357    $limit = 1000;
     358    //echo ("in:|".$_REQUEST['search_string']."|<br>");
     359    $search_string = stripslashes(trim($_REQUEST['search_string']));
     360
     361    $remember_search = $_REQUEST['remember_search'];
     362
     363    ///debug_print("Updating remember_search to $remember_search");
     364    update_option('ss_remember_search', $remember_search);
     365
     366    if ($remember_search == 'true') {
     367        update_option('ss_remembered_search_string', $search_string);
     368    }
     369
     370
     371    $shopsite_url = get_option('ss_shopsite_url');
     372
     373
     374    $media_url = get_media_url();
     375
     376    $list_all = false;
     377    if ($search_string == '*') {
     378        $search_array = array();
     379        $list_all = true;
     380    }
     381
     382    if (!$list_all) {
     383        if ($media_url)
     384            $search_array = array('search_on'=>"name,sku", 'search_term'=>$search_string, 'search_filter'=>'contains');
     385        else
     386            $search_array = array('search_on'=>"name", 'search_term'=>$search_string, 'search_filter'=>'contains');
     387    }
     388
     389    $products_xml = oauth(
     390        get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
     391        DOWNLOAD,
     392        array_merge(array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|Graphic|', 'limit'=>$limit), $search_array)
     393    );
     394
     395    //debug_print(print_r(html_entity_decode($products_xml['data']),true));
     396
     397    if (!$products_xml['success']) {
     398        echo "<div id=error_head>Unfortunately, something went wrong.</div>";
     399        echo "<div id=error_message>Detailed error message: <br>".$products_xml['error']."</div>";
     400        exit(1);
     401    }
     402    $products_ar = array();
     403    //html_entity_decode($string, ENT_QUOTES, "utf-8");
     404    //libxml_use_internal_errors(1);
     405    libxml_disable_entity_loader(false);
     406    //$products = simplexml_load_string(html_entity_decode($products_xml['data'], ENT_QUOTES, "ISO-8859-1"));
     407    //$products = simplexml_load_string($products_xml['data']);
     408    $products = simplexml_load_string($products_xml['data'], 'SimpleXMLElement', LIBXML_NOENT);
     409    if (count($products->Products->Product) > 0) {
     410        foreach ($products->Products->Product as $product) {
     411            $products_ar[addslashes($product->Name)] = array($product->ProductGUID, $product->SKU, $product->Graphic);
     412        }
     413    }
     414
     415    //if media_url is absent, that means shopsite's XML API can't handle searches on multiple fields at once. We'll perform two separate searches then.
     416    if (!$list_all && !$media_url) {
     417        $search_array = array('search_on'=>"sku", 'search_term'=>$search_string, 'search_filter'=>'contains');
     418        $products_xml = oauth(
     419            get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
     420            DOWNLOAD,
     421            array_merge(array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|Graphic|', 'limit'=>$limit), $search_array)
     422        );
     423        $products = /*new SimpleXMLElement*/simplexml_load_string ($products_xml['data'], 'SimpleXMLElement');
     424        if (count($products->Products->Product) > 0) {
     425            foreach ($products->Products->Product as $product) {
     426                if (!array_key_exists(addslashes($product->Name), $products_ar))
     427                    $products_ar[addslashes($product->Name)] = array($product->ProductGUID, $product->SKU, $product->Graphic);
     428            }
     429        }
     430    }
     431
     432    if (count($products_ar) == 0) {
     433        echo "<div id=no_products>No matching products.</div>";
     434        return;
     435    }
     436
     437
     438    ksort($products_ar);
     439    $products_ar = array_slice($products_ar,0,$limit);
     440
     441    echo "<div id=\"products\">";
     442    if (count($products_ar) == $limit) {
     443        echo "<div id=\"over_limit_warning\">Displaying first $limit products only. Please use \"Search\" button to narrow down your results.</div>";
     444    }
     445    $count = 1;
     446    foreach ($products_ar as $name => $data) {
     447        print_product($count, stripslashes($name), $data, $media_url);
     448        $count++;
     449    }
     450    echo "</div>";
    451451
    452452}
     
    454454function print_product ($count, $name, $data, $media_url) {
    455455
    456   $id = $data[0];
    457   $sku = rawurlencode($data[1]);
    458   $image = $data[2];
    459 
    460   if (!strstr($image, "://")) {
    461     if ($image && strstr($image,".") && $image != "no-image.png") {
    462       $image_ar = explode("/", $image,2);
    463       if (count($image_ar) == 2)
    464         $image = $image_ar[0]."/ss_size2/".$image_ar[1];
    465       else
    466         $image = "ss_size2/".$image_ar[0];
    467     } else
    468       $image = false;//"ss_size2/no-image.png";
    469   }
    470 
    471   $outdated = "";
    472   if (!$media_url)
    473     $outdated = " outdated";
    474 
    475   echo "<div class=\"wp_product$outdated\" id=\"wp_product_$count\">";
    476   if ($media_url && $image)
    477     if (strstr($image, "://"))
    478       echo "<img class=\"product_image\" alt=\"\" src=\"".$image."\">";
    479     else
    480       echo "<img class=\"product_image\" alt=\"\" src=\"".$media_url.$image."\">";
    481   if (strlen($sku) > 0)
    482     echo "<div class='product_sku'>".strip_tags($sku)."</div>";
    483   echo "<a class=\"product_name\" title=\"".str_replace("\"","&quot;",$name)."\">".strip_tags($name)."</a>";
    484 
    485   echo '<input type=hidden class="name_input" name="name_input" value="'.str_replace("\"","&quot;",$name).'">';
    486   echo '<input type=hidden class="guid_input" name="guid_input" value="'.$id.'">';
    487   echo '<input type=hidden class="sku_input" name="sku_input" value="'.str_replace("\"","&quot;",$sku).'">';
    488   echo "</div>";
     456    $id = $data[0];
     457    $sku = rawurlencode($data[1]);
     458    $image = $data[2];
     459
     460    if (!strstr($image, "://")) {
     461        if ($image && strstr($image,".") && $image != "no-image.png") {
     462            $image_ar = explode("/", $image,2);
     463            if (count($image_ar) == 2)
     464                $image = $image_ar[0]."/ss_size2/".$image_ar[1];
     465            else
     466                $image = "ss_size2/".$image_ar[0];
     467        } else
     468            $image = false;//"ss_size2/no-image.png";
     469    }
     470
     471    $outdated = "";
     472    if (!$media_url)
     473        $outdated = " outdated";
     474
     475    echo "<div class=\"wp_product$outdated\" id=\"wp_product_$count\">";
     476    if ($media_url && $image)
     477        if (strstr($image, "://"))
     478            echo "<img class=\"product_image\" alt=\"\" src=\"".$image."\">";
     479        else
     480            echo "<img class=\"product_image\" alt=\"\" src=\"".$media_url.$image."\">";
     481    if (strlen($sku) > 0)
     482        echo "<div class='product_sku'>".strip_tags($sku)."</div>";
     483    echo "<a class=\"product_name\" title=\"".str_replace("\"","&quot;",$name)."\">".strip_tags($name)."</a>";
     484
     485    echo '<input type=hidden class="name_input" name="name_input" value="'.str_replace("\"","&quot;",$name).'">';
     486    echo '<input type=hidden class="guid_input" name="guid_input" value="'.$id.'">';
     487    echo '<input type=hidden class="sku_input" name="sku_input" value="'.str_replace("\"","&quot;",$sku).'">';
     488    echo "</div>";
    489489}
    490490
    491491
    492492function product_handler( $atts, $content=null, $code="" ) {
    493   global $product_list, $wp_id;
    494   ///debug_print("product_handler entered");
    495   //return "<iframe src='$content' width='100%' height='300px' ><p>IFRAME FAIL!</p></iframe>";
    496 
    497   extract( shortcode_atts( array(
    498     'id' => '',
    499     'sku'=>''
    500   ), $atts ) );
    501 
    502   if (get_option('ss_identifier') == 'SKU')
    503     $identifier = $sku;
    504   else
    505     $identifier = $id;
    506 
    507 
    508   if ($identifier == '')
    509     return "";
    510 
    511 
    512   /*$shopsite_url = get_option('shopsite_url');   
    513   $handle = fopen($shopsite_url."&operation=get_product&id=$id",'r');
    514   $contents = stream_get_contents($handle);*/
    515 
    516   $wp_id++;
    517 
    518 
    519   if (!isset($product_list[$identifier])) {
    520     ///debug_print("sticking stuff into product_list for $identifier");
    521     $product_list[$identifier] = array();
    522   }
    523   ///debug_print("sticking stuff into product_list 2");
    524   array_push($product_list[$identifier], $wp_id);
    525 
    526 
    527   //$product_list["wp".$wp_id] = $id;
    528   return "<div class=ss_product id=product_".$wp_id."></div>";
    529 
    530   //return $contents;
     493    global $product_list, $wp_id;
     494    ///debug_print("product_handler entered");
     495    //return "<iframe src='$content' width='100%' height='300px' ><p>IFRAME FAIL!</p></iframe>";
     496
     497    extract( shortcode_atts( array(
     498        'id' => '',
     499        'sku'=>''
     500    ), $atts ) );
     501
     502    if (get_option('ss_identifier') == 'SKU')
     503        $identifier = $sku;
     504    else
     505        $identifier = $id;
     506
     507
     508    if ($identifier == '')
     509        return "";
     510
     511
     512    /*$shopsite_url = get_option('shopsite_url');   
     513    $handle = fopen($shopsite_url."&operation=get_product&id=$id",'r');
     514    $contents = stream_get_contents($handle);*/
     515
     516    $wp_id++;
     517
     518
     519    if (!isset($product_list[$identifier])) {
     520        ///debug_print("sticking stuff into product_list for $identifier");
     521        $product_list[$identifier] = array();
     522    }
     523    ///debug_print("sticking stuff into product_list 2");
     524    array_push($product_list[$identifier], $wp_id);
     525
     526
     527    //$product_list["wp".$wp_id] = $id;
     528    return "<div class=ss_product id=product_".$wp_id."></div>";
     529
     530    //return $contents;
    531531}
    532532
    533533function add_scripts() {
    534   //link_tutorial();
    535   wp_enqueue_script("jquery");
    536   //echo "<script>alert('wp_enq');</script>";
     534    //link_tutorial();
     535    wp_enqueue_script("jquery");
     536    //echo "<script>alert('wp_enq');</script>";
    537537}
    538538
    539539function init_product_list() {
    540   global $product_list;
    541 
    542   echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."populate_products.js></script>";
    543   $product_list = array();
    544   $wp_id = 0;
     540    global $product_list;
     541
     542    echo "<script type='text/javascript' src=".plugin_dir_url(__FILE__)."populate_products.js></script>";
     543    $product_list = array();
     544    $wp_id = 0;
    545545}
    546546
    547547function dispatch_product_list() {
    548   global $product_list;
    549   ///debug_print("Xi2");
    550   ///debug_print("product_list:".print_r($product_list, true));
    551   $product_map = json_encode($product_list);
    552   ///debug_print("product_map:".print_r($product_map, true));
    553   $identifier = get_option('ss_identifier');
    554   $id_list = implode(",",array_unique(array_keys($product_list)));
    555 
    556   //debug_print("dispatched:|$id_list|");
    557 
    558 
    559   echo
    560     "<script> var ss_path='".plugin_dir_url(__FILE__)."';
    561   var ss_identifier = \"$identifier\";
    562   var ss_product_map = $product_map;
    563   var ss_id_list = '$id_list';
    564   var ss_shopsite_url='".get_option('ss_shopsite_url')."';</script>";
    565   //echo "<script> var product_mapping = ".json_encode($product_list).";</script>";
     548    global $product_list;
     549    ///debug_print("Xi2");
     550    ///debug_print("product_list:".print_r($product_list, true));
     551    $product_map = json_encode($product_list);
     552    ///debug_print("product_map:".print_r($product_map, true));
     553    $identifier = get_option('ss_identifier');
     554    $id_list = implode(",",array_unique(array_keys($product_list)));
     555
     556    //debug_print("dispatched:|$id_list|");
     557
     558
     559    echo
     560        "<script> var ss_path='".plugin_dir_url(__FILE__)."';
     561    var ss_identifier = \"$identifier\";
     562    var ss_product_map = $product_map;
     563    var ss_id_list = '$id_list';
     564    var ss_shopsite_url='".get_option('ss_shopsite_url')."';</script>";
     565    //echo "<script> var product_mapping = ".json_encode($product_list).";</script>";
    566566}
    567567
    568568
    569569function get_product_data($id_list) {
    570   $id_list = stripslashes($id_list);
    571   //debug_print("GPD |$id_list|");
    572   $clientid = get_option('ss_clientid');
    573   $secretkey = get_option('ss_secretkey');
    574   $ids = explode(",", $id_list);
    575   $decoded_id_list = array();
    576   foreach ($ids as $id) {
    577     array_push($decoded_id_list, urldecode($id));
    578   }
    579   $data = "$clientid:".implode(",",$decoded_id_list);
    580   $hmachash = hash_hmac("sha1", $data, $secretkey, true);
    581   $signature = rawurlencode(base64_encode($hmachash));
    582 
    583   $identifier = get_option('ss_identifier');
    584 
    585   $shopsite_url = get_option('ss_shopsite_url');
    586   $url = $shopsite_url."&operation=get_products&".$identifier."_list=".$id_list."&signature=".$signature;
    587   //debug_print("DATA URL |$url|");
    588   $resp = get_url($url);
    589   $product_data = $resp[0];
    590   if ($product_data)
    591     print($product_data);
    592   else
    593     print($product_data[1]);
     570    $id_list = stripslashes($id_list);
     571    //debug_print("GPD |$id_list|");
     572    $clientid = get_option('ss_clientid');
     573    $secretkey = get_option('ss_secretkey');
     574    $ids = explode(",", $id_list);
     575    $decoded_id_list = array();
     576    foreach ($ids as $id) {
     577        array_push($decoded_id_list, urldecode($id));
     578    }
     579    $data = "$clientid:".implode(",",$decoded_id_list);
     580    $hmachash = hash_hmac("sha1", $data, $secretkey, true);
     581    $signature = rawurlencode(base64_encode($hmachash));
     582
     583    $identifier = get_option('ss_identifier');
     584
     585    $shopsite_url = get_option('ss_shopsite_url');
     586    $url = $shopsite_url."&operation=get_products&".$identifier."_list=".$id_list."&signature=".$signature;
     587    //debug_print("DATA URL |$url|");
     588    $resp = get_url($url);
     589    $product_data = $resp[0];
     590    if ($product_data)
     591        print($product_data);
     592    else
     593        print($product_data[1]);
    594594}
    595595
    596596function test_connection() {
    597   $test_download_xml = oauth(
    598     get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
    599     DOWNLOAD,
    600     array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|', 'search_term'=>"B0gu5", 'search_on'=>'name', 'search_filter'=>'contains', 'limit'=>1)
    601   );
    602   if (!$test_download_xml["success"])
    603     return $test_download_xml;
    604 
    605   $res = get_url(get_option('ss_shopsite_url'));
    606   if ($res[0] == false)
    607     return array("success"=>false, "error"=>$res[1]);
    608 
    609   return array("success"=>true);
     597    $test_download_xml = oauth(
     598        get_option('ss_clientid'), get_option('ss_secretkey'), get_option('ss_code'), get_option('ss_authorizationurl'),
     599        DOWNLOAD,
     600        array('clientApp'=>'1', 'dbname'=>'products', 'version'=>'11.2', 'fields'=>'|Product GUID|Name|SKU|', 'search_term'=>"B0gu5", 'search_on'=>'name', 'search_filter'=>'contains', 'limit'=>1)
     601    );
     602    if (!$test_download_xml["success"])
     603        return $test_download_xml;
     604
     605    $res = get_url(get_option('ss_shopsite_url'));
     606    if ($res[0] == false)
     607        return array("success"=>false, "error"=>$res[1]);
     608
     609    return array("success"=>true);
    610610}
    611611
    612612function debug_print($text) {
    613   //file_put_contents("log.txt", $text."\n", FILE_APPEND);
     613    //file_put_contents("log.txt", $text."\n", FILE_APPEND);
    614614}
    615615
    616616function get_url($url) {
    617   $response = wp_remote_get($url);
    618   if(wp_remote_retrieve_response_code($response) != 200) {
    619     $retval = array(false, wp_remote_retrieve_response_message($response));
    620   } else {
    621     $retval = array(wp_remote_retrieve_body($response));
    622   }
    623 
    624   return $retval;
    625 }
    626 
     617    $response = wp_remote_get($url);
     618    if(wp_remote_retrieve_response_code($response) != 200) {
     619        $retval = array(false, wp_remote_retrieve_response_message($response));
     620    } else {
     621        $retval = array(wp_remote_retrieve_body($response));
     622    }
     623
     624    return $retval;
     625}
     626
  • shopsite-plugin/trunk/tutorial_driver.js

    r1028993 r3053843  
    1 
    2 
    31function start_tutorial() {
    4   $(window).load(function() {
    5     $("#menu-settings").parents().css({'z-index':'auto', 'position':'relative'});
    6     $('#menu-settings').tutorial({'instruction':"Hover over 'Settings' to the left and click on 'ShopSite' from the dropdown menu", 'placement':'right', 'move':{'x':0, 'y':-25}});
    7     //$(".wp-menu-name:contains('Settings')").tutorial({'instruction':"Hover over 'Settings' to the left and click on 'ShopSite' from the dropdown menu", 'placement':'right'});
    8   });
     2    $(window).on('load',function() {
     3        $("#menu-settings").parents().css({'z-index':'auto', 'position':'relative'});
     4        $('#menu-settings').tutorial({'instruction':"Hover over 'Settings' to the left and click on 'ShopSite' from the dropdown menu", 'placement':'right', 'move':{'x':0, 'y':-25}});
     5        //$(".wp-menu-name:contains('Settings')").tutorial({'instruction':"Hover over 'Settings' to the left and click on 'ShopSite' from the dropdown menu", 'placement':'right'});
     6    });
    97}
    10 
    118function continue_tutorial() {
    12   $('#content_ifr').tutorial({'instruction':'You\'ll see something like [ss_product...] in your blog and when you preview or publish that tag will show your Order Button <br> <a href=# class=\'remove_me\'>Finish tutorial</a>',
    13   'instructionCss':{'width':400},'placement':'above', 'removeOnClose':false});
    14   $('.remove_me').one('click', function () {
    15     $.tutorial.remove();
    16   });
    17   /*$('.remove_me').one('click', function () {
    18     $.tutorial.remove();
    19     $('#post-preview').tutorial({'instruction':'Click here', 'placement':'left'});
    20     $('#post-preview').one('click', function () {
    21       $.tutorial.remove();
    22       $('#publish').tutorial({'instruction':'Click here to publish your new post. That\'s the end of the tutorial', 'placement':'left', 'instructionCss':{'width':250}, 'removeOnClick':true});
    23       $('#publish').one('click', function () {
    24         $.tutorial.remove();
    25       });
    26     });
    27   });*/
     9    $('#content_ifr').tutorial({'instruction':'You\'ll see something like [ss_product...] in your blog and when you preview or publish that tag will show your Order Button <br> <a href="#" class="remove_me">Finish tutorial</a>',
     10        'instructionCss':{'width':400},'placement':'above', 'removeOnClose':false});
     11    $('.remove_me').one('click', function () {
     12        $.tutorial.remove();
     13    });
     14    /*$('.remove_me').one('click', function () {
     15        $.tutorial.remove();
     16        $('#post-preview').tutorial({'instruction':'Click here', 'placement':'left'});
     17        $('#post-preview').one('click', function () {
     18            $.tutorial.remove();
     19            $('#publish').tutorial({'instruction':'Click here to publish your new post. That\'s the end of the tutorial', 'placement':'left', 'instructionCss':{'width':250}, 'removeOnClick':true});
     20            $('#publish').one('click', function () {
     21                $.tutorial.remove();
     22            });
     23        });
     24    });*/
    2825}
    29 
    3026function five_fields() {
    31   $('#ss_11_settings').css({'display':'table-row-group'});
    32   $('#ss_12_settings').css({'display':'none'});
    33  
    34   $('#ss_11_settings').parent().tutorial({'instruction':
    35     "Paste 5 fields from your ShopSite WordPress configuration below."+
    36     "<p style='text-align:right;color:#cccccc;font-size:8pt;margin:0px;'><a id=ss_12 style='display:inline;color:#cccccc;'>Go back</a> to 1-field config</p>",
    37     'placement':'above', 'move':{'x':0, 'y':-45}, 'instructionCss':{'width':500, 'text-align':'left', 'padding-left':50},});
    38   $('#ss_12').one('click', function () {
    39     $.tutorial.remove();
    40     one_field();
    41   });
    42  
    43   var paste_count = 0;
    44   $('#ss_11_settings input').one('paste', function () {
    45     paste_count++;
    46     if (paste_count == 5) {
    47       $.tutorial.remove();
    48       $('#test_connection').tutorial({'instruction':'Now click \'Test connection\' to ensure that the Plugin can communicate with your store', 'placement':'right', 'move':{'x':10, 'y':0}});
    49     }
    50   });
     27    $('#ss_11_settings').css({'display':'table-row-group'});
     28    $('#ss_12_settings').css({'display':'none'});
     29    $('#ss_11_settings').parent().tutorial({'instruction':
     30        "Paste 5 fields from your ShopSite WordPress configuration below."+
     31        '<p style="text-align:right;color:#cccccc;font-size:8pt;margin:0px;"><a id="ss_12" style="display:inline;color:#cccccc;">Go back</a> to 1-field config</p>',
     32        'placement':'above', 'move':{'x':0, 'y':-45}, 'instructionCss':{'width':500, 'text-align':'left', 'padding-left':50},});
     33    $('#ss_12').one('click', function () {
     34        $.tutorial.remove();
     35        one_field();
     36    });
     37    var paste_count = 0;
     38    $('#ss_11_settings input').one('paste', function () {
     39        paste_count++;
     40        if (paste_count == 5) {
     41            $.tutorial.remove();
     42            $('#test_connection').tutorial({'instruction':'Now click "Test connection" to ensure that the Plugin can communicate with your store', 'placement':'right', 'move':{'x':10, 'y':0}});
     43        }
     44    });
    5145}
    52 
    5346function one_field() {
    54   $('#ss_12_settings').css({'display':'table-row-group'});
    55   $('#ss_11_settings').css({'display':'none'});
    56  
    57   $('#config_dump').tutorial({'instruction':
    58       "In your ShopSite, go to Merchandizing then Social Media then WordPress.<br>"+
    59       "If there's one field there for you to copy and paste, paste it in the space below.<br>"+
    60       "If there are 5 fields to copy and paste, <a id=ss_11 style='display:inline;'>click here</a>.",         
    61       'instructionCss':{'width':700, 'text-align':'left', 'padding-left':50},'placement':'above'});
    62    
    63   $('#ss_11').one('click', function () {
    64     $.tutorial.remove();
    65     five_fields();
    66   });
    67    
    68   $('#config_dump').one('paste', function() {
    69     $.tutorial.remove();
    70     $('#test_connection').tutorial({'instruction':'Now click \'Test connection\' to ensure that the Plugin can communicate with your store', 'placement':'right', 'move':{'x':10, 'y':0}});
    71   } );
     47    $('#ss_12_settings').css({'display':'table-row-group'});
     48    $('#ss_11_settings').css({'display':'none'});
     49    $('#config_dump').tutorial({'instruction':
     50        'In your ShopSite, go to Merchandizing then Social Media then WordPress.<br>'+
     51        'If there\'s one field there for you to copy and paste, paste it in the space below.<br>'+
     52        'If there are 5 fields to copy and paste, <a id="ss_11" style="display:inline;">click here</a>.',
     53        'instructionCss':{'width':700, 'text-align':'left', 'padding-left':50},'placement':'above'});
     54    $('#ss_11').one('click', function () {
     55        $.tutorial.remove();
     56        five_fields();
     57    });
     58    $('#config_dump').one('paste', function() {
     59        $.tutorial.remove();
     60        $('#test_connection').tutorial({'instruction':'Now click "Test connection" to ensure that the Plugin can communicate with your store', 'placement':'right', 'move':{'x':10, 'y':0}});
     61    } );
    7262}
    73 
    74 $(window).load(function() {
    75  
    76  
    77   var l = window.location.href;
    78   if (l.search("tutorial=1") != -1) {
    79     if (l.search("page=shopsite_menu") != -1) {
    80       var state = $('#state').val();
    81       if (state == 'new_config') {
    82         $('#get_shopsite').tutorial({'instruction':
    83         "This tutorial helps you configure ShopSite plugin. <a id='proceed_tutorial'>Click here</a> to continue, or click the link above if you don't have a ShopSite store.",
    84         'instructionCss':{'width':500},
    85         'css':{'background-color':'white', 'padding':'0px 5px'}, 'placement':'below', 'move':{'x':0, 'y':0}});
    86         $('#proceed_tutorial').one('click', function() {
    87           $.tutorial.remove();
    88           if ($('#config_type').val() == 'ss_12') {
    89             one_field();
    90           } else {
    91             five_fields();
    92           }
    93         });
    94       } else if (state == 'testing_completed') {
    95         if ($('#test_bad').length) {
    96           $('#test_result').tutorial({'instruction':'Connection test failed. Please double-check your settings. If the problem still persists, contact ShopSite.<br><a href=# class=\'remove_me\'>Finish tutorial</a>',
    97             'placement':'above', 'instructionCss':{'width':400}, 'css':{'background-color':'white', 'padding':'0px 5px'}});
    98           $('.remove_me').one('click', function () {
    99             window.location.replace("options-general.php?page=shopsite_menu");
    100           });
    101         } else
    102           $('#save_settings').tutorial({'instruction':'Now Save your Settings', 'instructionCss':{'height':40},'placement':'right', 'move':{'x':10, 'y':0}});
    103       } else if (state == 'settings_saved') {
    104         $("#menu-posts").parents().css({'z-index':'auto', 'position':'relative'});
    105         $('#menu-posts').tutorial({'instruction':"Hover over 'Posts' to the left and click on 'Add New' from the dropdown menu to try out the Plugin", 'instructionCss':{'height':55, 'width':400}, 'move':{'x':0, 'y':-45}, 'placement':'right'});
    106       }
    107     } else if (l.search("post-new.php") != -1) {
    108       //$("#wp-content-editor-tools").css({'z-index':'auto'});
    109       $("#content-tmce").parents().css({'z-index':'auto'});
    110       $("#content-tmce").tutorial({'instruction':'Select Visual Display', 'placement':'above'});
    111       $('#content-tmce').one('click', function() {
    112         $.tutorial.remove();
    113         window.setTimeout(function() {
    114           el = $(".mce-btn[aria-label*='ShopSite']");
    115           el.parents().css({'z-index':'auto'});
    116           el.tutorial({'instruction':'Click this ShopSite Icon to now add a product to your blog', 'placement':'above', 'css':{'background-color':'white'}});
    117           el.one('click', function() {
    118             $.tutorial.remove();
    119           });
    120         }, 500);
    121        
    122       });
    123     }
    124    
    125     else if (l.search("ss_action=insert") != -1) {
    126      
    127    
    128       $('#search_form').tutorial({'instruction':'Enter a product name or "*" and click the Search button', 'placement':'right', 'overlay': false,
    129         'instructionCss':{'background-color':'#DFDFDF'}, 'css':{'padding':'5px'}, 'removeOnClose':false});
    130       $('#search_button').bind('click', function () {
    131         $.tutorial.remove();
    132         $( document ).ajaxComplete(function() {
    133           if ($('#no_products').length) {
    134             $.tutorial.remove();
    135             $('#search_form').tutorial({'instruction':'No matching products found. Try searching for "*"', 'placement':'right', 'overlay': false,
    136             'instructionCss':{'background-color':'#DFDFDF'}, 'css':{'padding':'5px'}, 'removeOnClose':false});
    137           } else {
    138             $.tutorial.remove();
    139             $('#product').tutorial({'instruction':'Select a product from the list', 'placement':'left', 'overlay': 1,
    140               'instructionCss':{'background-color':'#DFDFDF'}, 'removeOnClose':false});
    141            
    142             $('#product').one('change', function() {
    143               $.tutorial.remove();
    144               //$(this).attr('selected', true);
    145               $('#product').val($(this).val());
    146               $('#insert_product').tutorial({'instruction':'This inserts the product into your blog', 'placement':'left', 'overlay': 1,
    147                 'instructionCss':{'background-color':'#DFDFDF', 'height':60, 'width':200}, 'css':{'background-color':'white', 'padding':'2px'}, 'removeOnClose':false});
    148                
    149               $('#insert_product').one('click', function() {
    150                 //tinyMCE.activeEditor.windowManager.onClose = function() {alert('Bye!');};
    151                
    152                 $.tutorial.remove();
    153                 $('#close_popup').tutorial({'instruction':'Click here to close this popup', 'placement':'left', 'overlay': 1,
    154                 'instructionCss':{'background-color':'#DFDFDF', 'height':60}, 'css':{'background-color':'white', 'padding':'2px'}, 'removeOnClose':false});
    155               });
    156              
    157             });
    158           }
    159         });
    160       });
    161     }
    162   }
     63$(window).on('load',function() {
     64    var l = window.location.href;
     65    if (l.search("tutorial=1") != -1) {
     66        if (l.search("page=shopsite_menu") != -1) {
     67            var state = $('#state').val();
     68            if (state == 'new_config') {
     69                $('#get_shopsite').tutorial({'instruction':
     70                    'This tutorial helps you configure ShopSite plugin. <a id="proceed_tutorial">Click here</a> to continue, or click the link above if you don\'t have a ShopSite store.',
     71                    'instructionCss':{'width':500},
     72                    'css':{'background-color':'white', 'padding':'0px 5px'}, 'placement':'below', 'move':{'x':0, 'y':0}});
     73                $('#proceed_tutorial').one('click', function() {
     74                    $.tutorial.remove();
     75                    if ($('#config_type').val() == 'ss_12') {
     76                        one_field();
     77                    } else {
     78                        five_fields();
     79                    }
     80                });
     81            } else if (state == 'testing_completed') {
     82                if ($('#test_bad').length) {
     83                    $('#test_result').tutorial({'instruction':'Connection test failed. Please double-check your settings. If the problem still persists, contact ShopSite.<br><a href="#" class="remove_me">Finish tutorial</a>',
     84                        'placement':'above', 'instructionCss':{'width':400}, 'css':{'background-color':'white', 'padding':'0px 5px'}});
     85                    $('.remove_me').one('click', function () {
     86                        window.location.replace("options-general.php?page=shopsite_menu");
     87                    });
     88                } else
     89                    $('#save_settings').tutorial({'instruction':'Now Save your Settings', 'instructionCss':{'height':40},'placement':'right', 'move':{'x':10, 'y':0}});
     90            } else if (state == 'settings_saved') {
     91                $("#menu-posts").parents().css({'z-index':'auto', 'position':'relative'});
     92                $('#menu-posts').tutorial({'instruction':"Hover over 'Posts' to the left and click on 'Add New' from the dropdown menu to try out the Plugin", 'instructionCss':{'height':55, 'width':400}, 'move':{'x':0, 'y':-45}, 'placement':'right'});
     93            }
     94        } else if (l.search("post-new.php") != -1) {
     95            //$("#wp-content-editor-tools").css({'z-index':'auto'});
     96            $("#content-tmce").parents().css({'z-index':'auto'});
     97            $("#content-tmce").tutorial({'instruction':'Select Visual Display', 'placement':'above'});
     98            $('#content-tmce').one('click', function() {
     99                $.tutorial.remove();
     100                window.setTimeout(function() {
     101                    el = $(".mce-btn[aria-label*='ShopSite']");
     102                    el.parents().css({'z-index':'auto'});
     103                    el.tutorial({'instruction':'Click this ShopSite Icon to now add a product to your blog', 'placement':'above', 'css':{'background-color':'white'}});
     104                    el.one('click', function() {
     105                        $.tutorial.remove();
     106                    });
     107                }, 500);
     108            });
     109        }
     110        else if (l.search("ss_action=insert") != -1) {
     111            $('#search_form').tutorial({'instruction':'Enter a product name or "*" and click the Search button', 'placement':'right', 'overlay': false,
     112                'instructionCss':{'background-color':'#DFDFDF'}, 'css':{'padding':'5px'}, 'removeOnClose':false});
     113            $('#search_button').bind('click', function () {
     114                $.tutorial.remove();
     115                $( document ).ajaxComplete(function() {
     116                    if ($('#no_products').length) {
     117                        $.tutorial.remove();
     118                        $('#search_form').tutorial({'instruction':'No matching products found. Try searching for "*"', 'placement':'right', 'overlay': false,
     119                            'instructionCss':{'background-color':'#DFDFDF'}, 'css':{'padding':'5px'}, 'removeOnClose':false});
     120                    } else {
     121                        $.tutorial.remove();
     122                        $('#product').tutorial({'instruction':'Select a product from the list', 'placement':'left', 'overlay': 1,
     123                            'instructionCss':{'background-color':'#DFDFDF'}, 'removeOnClose':false});
     124                        $('#product').one('change', function() {
     125                            $.tutorial.remove();
     126                            //$(this).attr('selected', true);
     127                            $('#product').val($(this).val());
     128                            $('#insert_product').tutorial({'instruction':'This inserts the product into your blog', 'placement':'left', 'overlay': 1,
     129                                'instructionCss':{'background-color':'#DFDFDF', 'height':60, 'width':200}, 'css':{'background-color':'white', 'padding':'2px'}, 'removeOnClose':false});
     130                            $('#insert_product').one('click', function() {
     131                                //tinyMCE.activeEditor.windowManager.onClose = function() {alert('Bye!');};
     132                                $.tutorial.remove();
     133                                $('#close_popup').tutorial({'instruction':'Click here to close this popup', 'placement':'left', 'overlay': 1,
     134                                    'instructionCss':{'background-color':'#DFDFDF', 'height':60}, 'css':{'background-color':'white', 'padding':'2px'}, 'removeOnClose':false});
     135                            });
     136                        });
     137                    }
     138                });
     139            });
     140        }
     141    }
    163142});
Note: See TracChangeset for help on using the changeset viewer.