Plugin Directory

Changeset 923545


Ignore:
Timestamp:
05/30/2014 05:51:02 AM (12 years ago)
Author:
shibi
Message:

version 1.1

Location:
wp-spotim/trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • wp-spotim/trunk/admin/wp-spot.im-admin.php

    r922042 r923545  
    5252                <thead>
    5353                    <tr>
    54                         <th class="check-column">
    55                             <input type="checkbox" name="check_all" />
    56                         </th>
    5754                        <th>Spot.IM</th>
    5855                    </tr>
     
    6360                <tfoot>
    6461                    <tr>
    65                         <th class="check-column">
    66                             <input type="checkbox" name="check_all" />
    67                         </th>
    6862                        <th>Spot.IM</th>
    6963                    </tr>
  • wp-spotim/trunk/css/style.css

    r922042 r923545  
    1010
    1111.spotim_table.widefat {
     12    width: 600px;
     13}
     14
     15.spotim_table .spotim-spot-hidden {
     16    display: none;
     17    border-top: solid 1px #dbdbdb;
     18    margin: 15px 0px 0px;
     19    padding: 10px 0px 0px;
     20}
     21
     22.spotim_table .spotim-spot-show .spot-btn {
     23    float: right;
     24    margin-left: 15px;
    1225}
    1326
     
    1528    width: 100%;
    1629    height: 120px;
    17     max-width: 500px;
    1830}
    1931
    2032.spotim_table .spotim_title {
    2133    width: 100%;
    22     max-width: 500px;
    2334}
    2435
     
    3950}
    4051
    41 .spotim_table tbody .last-row td,
    42 .spotim_table tbody .last-row th.check-column {
     52.spotim_table tbody tr:nth-child(odd) {
     53    background: #f9f9f9;
     54}
     55
     56.spotim_table tbody tr:last-child td,
     57.spotim_table tbody tr:last-child th.check-column {
    4358    border-bottom: 0;
    4459}
    4560
    4661.spotim_table .spotim-spot-box {
    47     float: left;
    48     min-width: 25%;
    49     padding: 0px 10px;
     62
    5063}
    5164
    5265.spotim_table .spotim-spot-box.spotim-spot-box1 {
    53     min-width: 50%;
    5466}
    5567
     
    7789}
    7890
     91.spotim_table .spot-rules-box .spot-rules,
     92.spotim_table .spot-rules-box .spot-sub-rules {
     93    width: 200px;
     94    float: left;
     95    margin: 0px 10px 10px 0px;
     96}
     97
     98.spotim_table .spot-rules-box .spot-rules select,
     99.spotim_table .spot-rules-box .spot-sub-rules select {
     100    width: 100%;
     101}
     102
     103.spotim_table .spot-rules-box .spot-rules-equal {
     104    float: left;
     105    margin: 0px 10px 10px 0px;
     106}
     107
     108.spotim_table .spot-rules-box .spot-rules-equal-hidden {
     109    display: none;
     110}
    79111
    80112
     113/* rtl */
     114
     115.rtl .spotim_table .spotim-spot-show .spot-btn {
     116    float: left;
     117    margin-right: 15px;
     118}
     119
     120.rtl .spotim_table .spot-rules-box .spot-rules,
     121.rtl .spotim_table .spot-rules-box .spot-sub-rules {
     122    width: 200px;
     123    float: right;
     124    margin: 0px 0px 10px 10px;
     125}
     126
     127.rtl .spotim_table .spot-rules-box .spot-rules-equal {
     128    float: right;
     129    margin: 0px 0px 10px 10px;
     130}
  • wp-spotim/trunk/inc/wp-spot.im-ajax.php

    r922042 r923545  
    55    private $post_req;
    66    private $spots;
     7    private $rules;
    78   
    89    public function __construct() {
     10        $rules = new wp_spotim_rules();
     11        $this->rules = $rules;
    912        $this->get_action();
    1013        $this->make_action();
     
    3134            case "update":
    3235                if(check_ajax_referer('spotim_update_'.$this->post_req['spotim_id'], 'spotim_update_nonce')) {
    33                     $db->edit_spot($this->post_req['spotim_id'] ,$this->post_req['spotim_title'], $this->post_req['spotim_content']);
     36                    $db->edit_spot($this->post_req['spotim_id'] ,$this->post_req['spotim_title'], $this->post_req['spotim_content'], $this->post_req['spotim_rules']);
    3437                }
    3538                break;
     
    4548                }
    4649                break;
     50            case "rules":
     51                if(check_ajax_referer('spotim_rules_'.$this->post_req['spotim_id'], 'spotim_rules_nonce')) {
     52                    $this->ajax_sub_rules();
     53                }
     54                break;
    4755        }
    4856    }
     
    5563        foreach($spots as $s) {
    5664            $y = ($y > 2) ? 1 : $y;
     65            $delete_nonce = wp_create_nonce('spotim_delete_'.$s->ID);
     66            $update_nonce = wp_create_nonce('spotim_update_'.$s->ID);
    5767            ?>
    58             <tr class="spot-id-<?php echo $s->ID; ?> <?php echo ($y == 1) ? 'alternate' : ''; ?> <?php echo ($x == $total) ? 'last-row' : ''; ?>">
    59                 <th class="check-column">
    60                     <input type="checkbox" name="bulk_option[<?php echo $s->ID; ?>]" />
    61                 </th>
     68            <tr class="spot-id-<?php echo $s->ID; ?>">
    6269                <td class="spotim_spot">
    63                     <div class="spotim-spot-box spotim-spot-box1">
    64                         <div class="inp-box">
    65                             <label>Title</label>
    66                             <input name="spotim_title[<?php echo $s->ID; ?>]" class="spotim_title" value="<?php echo $s->post_title; ?>" />
     70                    <div class="spotim-spot-show">
     71                        <a class="row-title" href="#"><?php echo $s->post_title; ?></a>
     72                        <a class="spot-btn delete-spot" data-value="<?php echo $s->ID; ?>" data-nonce="<?php echo $delete_nonce; ?>" data-action="delete" href="#"><?php _e('Delete'); ?></a>
     73                        <a class="spot-btn edit-spot" data-value="<?php echo $s->ID; ?>" href="#"><?php _e('Edit'); ?></a>
     74                        <a class="spot-btn preview-spot" data-action="preview" data-value="<?php echo $s->ID; ?>" href="#"><?php _e('Preview'); ?></a>
     75                    </div>
     76                    <div class="spotim-spot-hidden">
     77                        <div class="spotim-spot-box spotim-spot-box1">
     78                            <div class="inp-box">
     79                                <label><?php _e('Title'); ?></label>
     80                                <input type="text" name="spotim_title[<?php echo $s->ID; ?>]" class="spotim_title" value="<?php echo $s->post_title; ?>" />
     81                            </div>
     82                            <div class="inp-box">
     83                                <label><?php _e('Code'); ?></label>
     84                                <textarea name="spotim_code[<?php echo $s->ID; ?>]" class="spotim_textarea"><?php echo $this->fix_code($s->post_content); ?></textarea>
     85                            </div>
    6786                        </div>
    68                         <div class="inp-box">
    69                             <label>Code</label>
    70                             <textarea name="spotim_code[<?php echo $s->ID; ?>]" class="spotim_textarea"><?php echo $this->fix_code($s->post_content); ?></textarea>
     87                        <div class="spotim-spot-box">
     88                            <div class="inp-box">
     89                                <label><?php _e('Rules'); ?></label>
     90                                <?php $this->rules->build_rules($s); ?>
     91                            </div>
    7192                        </div>
    72                     </div>
    73                     <div class="spotim-spot-box">
    74                         <div class="inp-box">
    75                             <label>Rules</label>
    76                             <select name="spotim_condition[<?php echo $s->ID; ?>]">
    77                                 <option>All Site</option>
    78                             </select>
    79                         </div>
    80                     </div>
    81                     <div class="spotim-spot-box">
    82                         <div class="inp-box spotim-buttons">
    83                             <label>Publish</label>
    84                             <button type="button" class="button button-secondary" data-action="preview" data-value="<?php echo $s->ID; ?>">Preview</button>
    85                             <button type="button" class="button button-primary" data-action="update" data-value="<?php echo $s->ID; ?>" data-nonce="<?php echo wp_create_nonce('spotim_update_'.$s->ID); ?>">Update</button>
    86                             <button type="button" class="button button-primary" data-action="delete" data-value="<?php echo $s->ID; ?>" data-nonce="<?php echo wp_create_nonce('spotim_delete_'.$s->ID); ?>">Delete</button>
    87                             <div class="ajax-status"></div>
     93                        <div class="spotim-spot-box">
     94                            <div class="inp-box spotim-buttons">
     95                                <label><?php _e('Publish'); ?></label>
     96                                <button type="button" class="button button-secondary" data-action="preview" data-value="<?php echo $s->ID; ?>"><?php _e('Preview'); ?></button>
     97                                <button type="button" class="button button-primary" data-action="update" data-value="<?php echo $s->ID; ?>" data-nonce="<?php echo $update_nonce; ?>"><?php _e('Update'); ?></button>
     98                                <button type="button" class="button button-primary" data-action="delete" data-value="<?php echo $s->ID; ?>" data-nonce="<?php echo $delete_nonce; ?>"><?php _e('Delete'); ?></button>
     99                                <div class="ajax-status"></div>
     100                            </div>
    88101                        </div>
    89102                    </div>
     
    96109    }
    97110   
     111    private function ajax_sub_rules() {
     112        $sub = $this->rules->get_sub_rules($this->post_req['spotim_rules_by']);
     113        if($sub) {
     114        ?>
     115        <select name="sub_rules" class="spotim_sub_rules">
     116            <?php foreach($sub as $sk=>$sv) { ?>
     117            <option value="<?php echo $sk; ?>"><?php echo $sv; ?></option>
     118            <?php } ?> 
     119        </select>
     120        <?php
     121        }
     122    }
     123   
    98124    private function fix_code($code) {
    99125        return stripslashes($code);
  • wp-spotim/trunk/inc/wp-spot.im-db.php

    r922042 r923545  
    3333    }
    3434   
    35     public function edit_spot($spot_id, $spot_title, $spot_content) {
     35    public function edit_spot($spot_id, $spot_title, $spot_content, $rules) {
     36        $rules = serialize($rules);
    3637        $update = $this->wpdb->update(
    3738            $this->wpdb->posts,
     
    3940                'post_title' => $spot_title,
    4041                'post_content' => $spot_content,
     42                'post_excerpt' => $rules,
    4143                'post_modified' => date("Y-m-d H:i:s")
    4244            ),
     
    4547                '%s',
    4648                '%s',
     49                '%s',
    4750                '%s'
    4851            ),
    4952            array( '%d' )
    5053        );
    51        
    5254        echo $update;
    5355    }
     
    6466    public function get_all_spots() {
    6567        $spots = $this->wpdb->get_results(
    66             $this->wpdb->prepare("SELECT ID, post_title, post_content FROM {$this->wpdb->posts} WHERE post_type='%s'", 'spotim')
     68            $this->wpdb->prepare("SELECT ID, post_title, post_content, post_excerpt FROM {$this->wpdb->posts} WHERE post_type='%s'", 'spotim')
    6769        );
    6870        return $spots;
  • wp-spotim/trunk/js/script.js

    r922042 r923545  
    22    $('.spotim-add-new').click(function(e) {
    33        e.preventDefault();
    4         if($('.spotim_table tbody tr').length) {
    5             alert('In our next version you could add more than 1 chat');   
    6         }else{
    7             var data = {
    8                 action: 'spotim',
    9                 spotim_action: 'new',
    10                 spotim_new_nonce: $(this).attr('data-nonce')
    11             };
    12             $.post(ajaxurl, data, function(response) {
    13                 get_spots();
    14             });
    15         }
     4        var data = {
     5            action: 'spotim',
     6            spotim_action: 'new',
     7            spotim_new_nonce: $(this).attr('data-nonce')
     8        };
     9        $.post(ajaxurl, data, function(response) {
     10            get_spots();
     11        });
     12       
    1613    });
    1714   
    18     $('.spotim_table').on('click', '.spotim-buttons button', function() {
    19        
     15    $('.spotim_table').on('click', '.spotim-buttons button, .delete-spot, .preview-spot', function(e) {
     16        e.preventDefault();
    2017        //edit spot
    2118        if($(this).attr('data-action') == 'update') {
     19            var rules = [];
     20            var x = 0;
     21            $.each($(this).parents('td').find('.spot-rules-box'), function() {
     22                rules[x] = {
     23                        spotim_rules: $(this).find('.spotim_rules').val(),
     24                        spotim_rules_equal: $(this).find('.spot-rules-equal input').val(),
     25                        spotim_sub_rules: $(this).find('.spotim_sub_rules').val()
     26                };
     27                x++;
     28            });
    2229            var data = {
    2330                action: 'spotim',
     
    2633                spotim_title: $(this).parents('td').find('input.spotim_title').val(),
    2734                spotim_content: $(this).parents('td').find('textarea.spotim_textarea').val(),
     35                spotim_rules: rules,
    2836                spotim_update_nonce: $(this).attr('data-nonce')
    2937            };
    3038            $.post(ajaxurl, data, function(response) {
    31                 get_spots(data.spotim_id);
     39                var spot_id_status = $('tr.spot-id-'+data.spotim_id).find('.ajax-status');
     40                if(spot_id_status.length) {
     41                    spot_id_status.html('Spot is Update');
     42                    spot_id_status.fadeIn('fast', function() {
     43                        spot_id_status.fadeOut(5000);
     44                    });
     45                }
    3246            });
    3347        }
     
    4155            };
    4256            $.post(ajaxurl, data, function(response) {
    43                 get_spots();
     57                $('tr.spot-id-'+data.spotim_id).remove();
    4458            });
    4559        }
     
    5569    });
    5670   
    57     function get_spots(spotim_id) {
     71    $('.spotim_table').on('change', '.spotim_rules', function() {
     72        var sub_rules = $(this).parents('.spot-rules-box').find('.spot-sub-rules');
     73        var data = {
     74            action: 'spotim',
     75            spotim_action: 'rules',
     76            spotim_id: $(this).attr('data-value'),
     77            spotim_rules_nonce: $(this).attr('data-nonce'),
     78            spotim_rules_by: $(this).val()
     79        };
     80        $.post(ajaxurl, data, function(response) {
     81            sub_rules.html(response);
     82            sub_rules.parents('.spot-rules-box').find('.spot-rules-equal button').eq(0).click();
     83            if(response !== '') {
     84                sub_rules.parents('.spot-rules-box').find('.spot-rules-equal').removeClass('spot-rules-equal-hidden');
     85            }else{
     86                sub_rules.parents('.spot-rules-box').find('.spot-rules-equal').addClass('spot-rules-equal-hidden');
     87            }
     88        });
     89    });
     90   
     91    $('.spotim_table').on('click', '.spot-rules-equal button', function() {
     92        if(!$(this).hasClass('active')) {
     93            $(this).siblings('button').removeClass('active');
     94            $(this).addClass('active');
     95            $(this).siblings('input').val($(this).attr('data-value'));
     96        }
     97    });
     98   
     99    $('.spotim_table').on('click', '.spotim-spot-show .row-title, .spotim-spot-show .edit-spot', function(e) {
     100        e.preventDefault();
     101        $(this).parents('td').find('.spotim-spot-hidden').slideToggle();
     102    });
     103   
     104    function get_spots() {
    58105        var data = {
    59106            action: 'spotim',
     
    63110        $.post(ajaxurl, data, function(response) {
    64111            $('.spotim_table tbody').html(response);
    65             if(spotim_id) {
    66                 var spot_id_status = $('.spot-id-'+spotim_id).find('.ajax-status');
    67                 if(spot_id_status.length) {
    68                     spot_id_status.html('Spot is Update');
    69                     spot_id_status.fadeIn('fast', function() {
    70                         spot_id_status.fadeOut(5000);
    71                     });
    72                 }
    73             }
    74112        });
    75113    }
  • wp-spotim/trunk/readme.txt

    r922054 r923545  
    3636
    3737== Changelog ==
    38 No recent changes
     38
     39= 1.1 =
     40New admin design
     41Add rules for spots
     42Add the option to add more than 1 spot
     43Fix rtl admin design
    3944
    4045== Upgrade Notice ==
  • wp-spotim/trunk/wp-spot.im.php

    r922042 r923545  
    44 * Plugin URI: http://wordpress.org/plugins/wp-spotim/
    55 * Description: WP Spot.IM let you add and manage your chats from Spot.IM.
    6  * Version: 1.0
     6 * Version: 1.1
    77 * Author: shibi
    88 * Author URI: http://profiles.wordpress.org/shibi
     
    1515
    1616require_once('admin/wp-spot.im-admin.php');
     17require_once('inc/wp-spot.im-rules.php');
    1718require_once('inc/wp-spot.im-db.php');
    1819require_once('inc/wp-spot.im-ajax.php');
     
    2021class wp_spotim {
    2122    private $spots;
     23    private $max_priority;
     24    private $max_rules_priority;
    2225   
    2326    public function __construct() {
     
    2831   
    2932    public function print_spot() {
     33        $x = 0;
     34        $spot = array();
    3035        foreach($this->spots as $s) {
    31             if($this->check_spot_rules($s->ID)) {
    32                 echo $this->fix_code($s->post_content);
    33             }
    34         }
    35     }
    36    
    37     private function check_spot_rules($spot_id) {
    38         //later for rules
    39         $spot_rules = 1; // all site
    40         if($spot_rules == 1) {
    41             return true;
    42         }else{
    43             return false;
     36            $rules = $this->check_spot_rules($s->post_excerpt);
     37            if($rules) {
     38                if($rules[1] == $this->max_rules_priority) {
     39                    $spot[$x]['code'] = $this->fix_code($s->post_content);
     40                    $spot[$x]['priority'] = $this->max_rules_priority;
     41                    $this->max_priority = $this->max_rules_priority;
     42                }
     43            }
     44        }
     45       
     46        if($spot) {
     47            foreach($spot as $s) {
     48                if($this->max_priority == $s['priority']) {
     49                    echo $s['code'];
     50                    break;
     51                }
     52            }
     53        }
     54    }
     55   
     56    private function check_spot_rules($rules) {
     57        $rules = unserialize($rules);
     58        $this->max_rules_priority = 0;
     59        $show = 0;
     60        $x = 0;
     61        foreach($rules as $r) {
     62            switch ($r['spotim_rules']) {
     63                case "":
     64                case "all_site":
     65                    $show = 1;
     66                    $priority[$x] = 10;
     67                    $res[$x] = array($show, $priority[$x]);
     68                    break;
     69                case "post_type":
     70                    $show = $this->check_post_type($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     71                    $priority[$x] = 20;
     72                    $res[$x] = array($show, $priority[$x]);
     73                    break;
     74                case "post":
     75                    $show = $this->check_post_id($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     76                    $priority[$x] = 50;
     77                    $res[$x] = array($show, $priority[$x]);
     78                    break;
     79                case "category":
     80                    $show = $this->check_post_category($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     81                    $priority[$x] = 30;
     82                    $res[$x] = array($show, $priority[$x]);
     83                    break;
     84                case "page":
     85                    $show = $this->check_page_id($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     86                    $priority[$x] = 50;
     87                    $res[$x] = array($show, $priority[$x]);
     88                    break;
     89                case "page_parent":
     90                    $show = $this->check_page_parent($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     91                    $priority[$x] = 30;
     92                    $res[$x] = array($show, $priority[$x]);
     93                    break;
     94                case "page_template":
     95                    $show = $this->check_page_template($r['spotim_rules_equal'], $r['spotim_sub_rules']);
     96                    $priority[$x] = 40;
     97                    $res[$x] = array($show, $priority[$x]);
     98                    break; 
     99            }
     100            $x++;
     101        }
     102       
     103        $pri = (count($priority) > 1) ? max($priority) : $priority[0];
     104        if($this->max_rules_priority < $pri) {
     105            $this->max_rules_priority = $pri;
     106        }
     107       
     108        $end_check = 0;
     109        foreach($res as $r) {
     110            if($r[0]) {
     111                return $r;
     112            }else{
     113                return false;
     114            }
     115        }
     116       
     117
     118       
     119    }
     120   
     121    private function check_post_type($equal, $sub) {
     122        if($equal == 1) {
     123            if(get_post_type() == $sub) {
     124                return true;
     125            }else{
     126                return false;
     127            }
     128        }elseif($equal == 2) {
     129            if(get_post_type() !== $sub) {
     130                return true;
     131            }else{
     132                return false;
     133            }
     134        }
     135    }
     136   
     137    private function check_post_id($equal, $sub) {
     138        if($equal == 1) {
     139            if(is_single($sub)) {
     140                return true;
     141            }else{
     142                return false;
     143            }
     144        }elseif($equal == 2) {
     145            if(!is_single($sub)) {
     146                return true;
     147            }else{
     148                return false;
     149            }
     150        }
     151    }
     152   
     153    private function check_post_category($equal, $sub) {
     154        if($equal == 1) {
     155            if(is_category($sub) || (is_single() && in_category($sub))) {
     156                return true;
     157            }else{
     158                return false;
     159            }
     160        }elseif($equal == 2) {
     161            if(!is_category($sub) || (is_single() && !in_category($sub))) {
     162                return true;
     163            }else{
     164                return false;
     165            }
     166        }
     167    }
     168   
     169    private function check_page_id($equal, $sub) {
     170        if($equal == 1) {
     171            if(is_page($sub)) {
     172                return true;
     173            }else{
     174                return false;
     175            }
     176        }elseif($equal == 2) {
     177            if(!is_page($sub)) {
     178                return true;
     179            }else{
     180                return false;
     181            }
     182        }
     183    }
     184   
     185    private function check_page_parent($equal, $sub) {
     186        global $post;
     187        if($equal == 1) {
     188            if($post->post_parent == $sub) {
     189                return true;
     190            }else{
     191                return false;
     192            }
     193        }elseif($equal == 2) {
     194            if($post->post_parent != $sub) {
     195                return true;
     196            }else{
     197                return false;
     198            }
     199        }
     200    }
     201   
     202    private function check_page_template($equal, $sub) {
     203        if($equal == 1) {
     204            if(is_page_template($sub)) {
     205                return true;
     206            }else{
     207                return false;
     208            }
     209        }elseif($equal == 2) {
     210            if(!is_page_template($sub)) {
     211                return true;
     212            }else{
     213                return false;
     214            }
    44215        }
    45216    }
Note: See TracChangeset for help on using the changeset viewer.