Changeset 923545
- Timestamp:
- 05/30/2014 05:51:02 AM (12 years ago)
- Location:
- wp-spotim/trunk
- Files:
-
- 1 added
- 7 edited
-
admin/wp-spot.im-admin.php (modified) (2 diffs)
-
css/style.css (modified) (4 diffs)
-
inc/wp-spot.im-ajax.php (modified) (5 diffs)
-
inc/wp-spot.im-db.php (modified) (4 diffs)
-
inc/wp-spot.im-rules.php (added)
-
js/script.js (modified) (5 diffs)
-
readme.txt (modified) (1 diff)
-
wp-spot.im.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-spotim/trunk/admin/wp-spot.im-admin.php
r922042 r923545 52 52 <thead> 53 53 <tr> 54 <th class="check-column">55 <input type="checkbox" name="check_all" />56 </th>57 54 <th>Spot.IM</th> 58 55 </tr> … … 63 60 <tfoot> 64 61 <tr> 65 <th class="check-column">66 <input type="checkbox" name="check_all" />67 </th>68 62 <th>Spot.IM</th> 69 63 </tr> -
wp-spotim/trunk/css/style.css
r922042 r923545 10 10 11 11 .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; 12 25 } 13 26 … … 15 28 width: 100%; 16 29 height: 120px; 17 max-width: 500px;18 30 } 19 31 20 32 .spotim_table .spotim_title { 21 33 width: 100%; 22 max-width: 500px;23 34 } 24 35 … … 39 50 } 40 51 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 { 43 58 border-bottom: 0; 44 59 } 45 60 46 61 .spotim_table .spotim-spot-box { 47 float: left; 48 min-width: 25%; 49 padding: 0px 10px; 62 50 63 } 51 64 52 65 .spotim_table .spotim-spot-box.spotim-spot-box1 { 53 min-width: 50%;54 66 } 55 67 … … 77 89 } 78 90 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 } 79 111 80 112 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 5 5 private $post_req; 6 6 private $spots; 7 private $rules; 7 8 8 9 public function __construct() { 10 $rules = new wp_spotim_rules(); 11 $this->rules = $rules; 9 12 $this->get_action(); 10 13 $this->make_action(); … … 31 34 case "update": 32 35 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']); 34 37 } 35 38 break; … … 45 48 } 46 49 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; 47 55 } 48 56 } … … 55 63 foreach($spots as $s) { 56 64 $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); 57 67 ?> 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; ?>"> 62 69 <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> 67 86 </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> 71 92 </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> 88 101 </div> 89 102 </div> … … 96 109 } 97 110 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 98 124 private function fix_code($code) { 99 125 return stripslashes($code); -
wp-spotim/trunk/inc/wp-spot.im-db.php
r922042 r923545 33 33 } 34 34 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); 36 37 $update = $this->wpdb->update( 37 38 $this->wpdb->posts, … … 39 40 'post_title' => $spot_title, 40 41 'post_content' => $spot_content, 42 'post_excerpt' => $rules, 41 43 'post_modified' => date("Y-m-d H:i:s") 42 44 ), … … 45 47 '%s', 46 48 '%s', 49 '%s', 47 50 '%s' 48 51 ), 49 52 array( '%d' ) 50 53 ); 51 52 54 echo $update; 53 55 } … … 64 66 public function get_all_spots() { 65 67 $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') 67 69 ); 68 70 return $spots; -
wp-spotim/trunk/js/script.js
r922042 r923545 2 2 $('.spotim-add-new').click(function(e) { 3 3 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 16 13 }); 17 14 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(); 20 17 //edit spot 21 18 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 }); 22 29 var data = { 23 30 action: 'spotim', … … 26 33 spotim_title: $(this).parents('td').find('input.spotim_title').val(), 27 34 spotim_content: $(this).parents('td').find('textarea.spotim_textarea').val(), 35 spotim_rules: rules, 28 36 spotim_update_nonce: $(this).attr('data-nonce') 29 37 }; 30 38 $.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 } 32 46 }); 33 47 } … … 41 55 }; 42 56 $.post(ajaxurl, data, function(response) { 43 get_spots();57 $('tr.spot-id-'+data.spotim_id).remove(); 44 58 }); 45 59 } … … 55 69 }); 56 70 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() { 58 105 var data = { 59 106 action: 'spotim', … … 63 110 $.post(ajaxurl, data, function(response) { 64 111 $('.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 }74 112 }); 75 113 } -
wp-spotim/trunk/readme.txt
r922054 r923545 36 36 37 37 == Changelog == 38 No recent changes 38 39 = 1.1 = 40 New admin design 41 Add rules for spots 42 Add the option to add more than 1 spot 43 Fix rtl admin design 39 44 40 45 == Upgrade Notice == -
wp-spotim/trunk/wp-spot.im.php
r922042 r923545 4 4 * Plugin URI: http://wordpress.org/plugins/wp-spotim/ 5 5 * Description: WP Spot.IM let you add and manage your chats from Spot.IM. 6 * Version: 1. 06 * Version: 1.1 7 7 * Author: shibi 8 8 * Author URI: http://profiles.wordpress.org/shibi … … 15 15 16 16 require_once('admin/wp-spot.im-admin.php'); 17 require_once('inc/wp-spot.im-rules.php'); 17 18 require_once('inc/wp-spot.im-db.php'); 18 19 require_once('inc/wp-spot.im-ajax.php'); … … 20 21 class wp_spotim { 21 22 private $spots; 23 private $max_priority; 24 private $max_rules_priority; 22 25 23 26 public function __construct() { … … 28 31 29 32 public function print_spot() { 33 $x = 0; 34 $spot = array(); 30 35 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 } 44 215 } 45 216 }
Note: See TracChangeset
for help on using the changeset viewer.