Changeset 804473
- Timestamp:
- 11/14/2013 06:11:09 PM (12 years ago)
- Location:
- post-sorter/trunk
- Files:
-
- 3 added
- 7 edited
-
. (modified) (1 prop)
-
css/style.css (modified) (1 diff)
-
js/common.js (modified) (1 diff)
-
lang (added)
-
page/about.php (added)
-
page/general.php (modified) (4 diffs)
-
page/permissions.php (added)
-
post_sorter.php (modified) (20 diffs)
-
readme.txt (modified) (2 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
post-sorter/trunk
-
Property
svn:ignore
set to
ftpsync.settings
-
Property
svn:ignore
set to
-
post-sorter/trunk/css/style.css
r730333 r804473 39 39 .post_sorter_form textarea[readonly="readonly"] 40 40 { background-color: #eee; } 41 42 .post_sorter_form .multi-select { margin-bottom: 24px; float: left; } 43 .post_sorter_form .multi-select label { display: block; } 44 .post_sorter_form .multi-select select[multiple] { vertical-align: top; width: 320px; min-height: 160px; } 45 46 .post_sorter_form .multi-select.toggle { margin: 48px; } 47 .post_sorter_form .multi-select.toggle input[type="button"] { display: block; margin: 12px 0; } -
post-sorter/trunk/js/common.js
r730151 r804473 1 1 function post_sorter_saveOnKeyUp(e, obj, pid) { 2 var code = e.which ? e.which : e.keyCode;3 4 switch(code) {5 case 13:6 post_sorter_save(obj, pid);7 return false;8 }2 var code = e.which ? e.which : e.keyCode; 3 4 switch(code) { 5 case 13: 6 post_sorter_save(obj, pid); 7 return false; 8 } 9 9 } 10 10 11 11 function post_sorter_save(obj, pid) { 12 jQuery.ajax({13 type: "post",14 url: ajaxurl,15 data: {16 action: "save_sort_position",17 post_id: pid,18 position: jQuery(obj).val()19 },20 dataType: "json",21 success: post_sorter_onSortSave,22 error: post_sorter_onError23 });12 jQuery.ajax({ 13 type: "post", 14 url: ajaxurl, 15 data: { 16 action: "save_sort_position", 17 post_id: pid, 18 position: jQuery(obj).val() 19 }, 20 dataType: "json", 21 success: post_sorter_onSortSave, 22 error: post_sorter_onError 23 }); 24 24 } 25 25 26 26 function post_sorter_onError(jqXhr, textStatus, errorThrown) { 27 alert(textStatus);27 alert(textStatus); 28 28 } 29 29 30 30 function post_sorter_onSortSave(res) { 31 window.location.href = window.location;31 window.location.href = window.location; 32 32 } 33 33 34 34 function post_sorter_moveUp(pid) { 35 post_sorter_move(pid, 'up');35 post_sorter_move(pid, 'up'); 36 36 } 37 37 38 38 function post_sorter_moveDown(pid) { 39 post_sorter_move(pid, 'down');39 post_sorter_move(pid, 'down'); 40 40 } 41 41 42 42 function post_sorter_move(pid, direction) { 43 jQuery.ajax({44 type: "post",45 url: ajaxurl,46 data: {47 action: "move_sort_post",48 post_id: pid,49 direction: direction.toLowerCase() == 'up' ? 'up' : 'down'50 },51 dataType: "json",52 success: post_sorter_onMove,53 error: post_sorter_onError54 });43 jQuery.ajax({ 44 type: "post", 45 url: ajaxurl, 46 data: { 47 action: "move_sort_post", 48 post_id: pid, 49 direction: direction.toLowerCase() == 'up' ? 'up' : 'down' 50 }, 51 dataType: "json", 52 success: post_sorter_onMove, 53 error: post_sorter_onError 54 }); 55 55 } 56 56 57 57 function post_sorter_onMove(res) { 58 window.location.href = window.location;58 window.location.href = window.location; 59 59 } 60 61 function enable_roles() { 62 console.log(jQuery("#available_roles option:selected")); 63 return !jQuery("#available_roles option:selected").remove().appendTo("#enabled_roles"); 64 } 65 66 function disable_roles() { 67 return !jQuery("#enabled_roles option:selected").remove().appendTo("#available_roles"); 68 } -
post-sorter/trunk/page/general.php
r730389 r804473 1 1 <?php 2 global $post_sorter;2 global $post_sorter; 3 3 4 if( !empty( $_POST ) )5 $post_sorter->save_settings();4 if( !empty( $_POST ) ) 5 $post_sorter->save_settings(); 6 6 ?> 7 7 … … 9 9 10 10 <div class="wrap"> 11 <h2><?php echo 'Post Sorter'?></h2>12 13 <form id="post_sorter_settings" action="" method="post" class="post_sorter_form">11 <h2><?php _e( 'Post Sorter', 'post_sorter' ) ?></h2> 12 13 <form id="post_sorter_settings" action="" method="post" class="post_sorter_form"> 14 14 <h3><?php _e( 'Basic Settings', 'post_sorter' ) ?></h3> 15 15 … … 41 41 </tbody> 42 42 </table> 43 43 44 44 <br class="clear" /> 45 45 <br class="clear" /> … … 120 120 </tbody> 121 121 </table> 122 </form>122 </form> 123 123 </div> 124 124 -
post-sorter/trunk/post_sorter.php
r730389 r804473 4 4 Plugin URI: http://intellisys.org/ 5 5 Description: Plugin for easy sorting of posts and pages by numeric value, both ascending and descending. 6 Version: 1. 3.16 Version: 1.4 7 7 Author: Lyubomir Gardev 8 8 Author URI: http://rolice.intellisys.info/ … … 14 14 15 15 class PostSorter { 16 16 17 /** 17 18 * Whether custom sorting is enabled 18 19 * @var bool 19 20 */ 20 private $_custom = FALSE; 21 private $custom = FALSE; 22 23 private $plugin_data = NULL; 21 24 22 25 public function __construct() { … … 25 28 26 29 public function init() { 27 load_plugin_textdomain( 'post_sorter', FALSE, plugin_dir_path(__FILE__) . ' /lang/' );30 load_plugin_textdomain( 'post_sorter', FALSE, plugin_dir_path(__FILE__) . 'lang/' ); 28 31 29 32 add_filter( 'manage_posts_columns', array( $this, 'add_sorter_column' ) ); … … 66 69 67 70 add_action( 'admin_menu', array( $this, 'add_menu' ) ); 68 add_action( 'admin_init', array( $this, ' register_settings' ) );71 add_action( 'admin_init', array( $this, 'set_up' ) ); 69 72 } 70 73 … … 75 78 update_option( 'post_sorter_enabled', TRUE ); 76 79 update_option( 'post_sorter_direction', 'ASC' ); 80 update_option( 'post_sorter_enabled_roles', array( 'administrator' ) ); 77 81 78 82 $args = array( … … 101 105 } 102 106 107 public function meta( $key ) { 108 return isset( $this->plugin_data[ $key ] ) ? $this->plugin_data[ $key ] : NULL; 109 } 110 103 111 /** 104 112 * Enqueues scripts (JavaScripts) and CSS styles … … 117 125 * @return array The columns to be rendered with added new column inside 118 126 */ 119 public function add_sorter_column( $columns ) { 120 $columns['sort'] = __( 'Sorting', 'post_sorter' ); 127 public function add_sorter_column( $columns ) { 128 if( $this->can_use() ) 129 $columns['sort'] = __( 'Sorting', 'post_sorter' ); 130 121 131 return $columns; 122 132 } … … 127 137 */ 128 138 public function show_sorter_column( $name ) { 129 //global $post;130 131 139 switch ( $name ) { 132 140 case 'sort': … … 144 152 $val = (int) get_post_meta( $post->ID, POST_SORTER_META_KEY, TRUE ); 145 153 146 if( $this-> _custom) {154 if( $this->custom || !$this->can_use() ) { 147 155 echo '<div class="post_sorter">—</div>'; 148 156 return; … … 173 181 */ 174 182 public function add_sorter_sort( $columns ) { 175 $columns['sort'] = 'sort'; 183 if( $this->can_use() ) 184 $columns['sort'] = 'sort'; 185 176 186 return $columns; 177 187 } … … 211 221 // If we have some hooks apply them - other plugins, etc. 212 222 if( 2 <= $this->_count_filter_hooks( 'post_sorter_join' ) ) { 213 $this-> _custom = TRUE;223 $this->custom = TRUE; 214 224 $sql = apply_filters( 'post_sorter_join', $sql ); 215 225 return $sql; … … 235 245 // If we have some hooks apply them - other plugins, etc. 236 246 if( 2 <= $this->_count_filter_hooks( 'post_sorter_order' ) ) { 237 $this-> _custom = TRUE;247 $this->custom = TRUE; 238 248 $sql = apply_filters( 'post_sorter_order', $sql ); 239 249 return $sql; … … 252 262 $post_id = (int) $post_id; 253 263 254 if ( 0 >= $post_id ) 255 return; 256 257 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 258 return; 259 260 if ( !wp_verify_nonce( isset( $_POST['post_sorter'] ) ? $_POST['post_sorter'] : '', plugin_basename(__FILE__) ) ) 261 return; 262 263 if ( !current_user_can( 'edit_post', $post_id ) ) 264 // No actual post to manage 265 if( 0 >= $post_id ) 266 return; 267 268 // Do nothing on autosave 269 if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 270 return; 271 272 // Verify nonce for expected request 273 if( !wp_verify_nonce( isset( $_POST['post_sorter'] ) ? $_POST['post_sorter'] : '', plugin_basename(__FILE__) ) ) 274 return; 275 276 // Check permissions for modifing posts to do that (post edit screen) 277 if( !current_user_can( 'edit_post', $post_id ) ) 278 return; 279 280 // Check if our plugin allows this user to save 281 if( !$this->can_use() ) 264 282 return; 265 283 266 284 $position = $_POST['post_sorter_inline']; 267 285 268 if ( is_array( $position ) && !empty( $position ) )286 if( is_array( $position ) && !empty( $position ) ) 269 287 $position = $position[0]; 270 288 … … 278 296 */ 279 297 public function add_menu() { 280 add_menu_page( 'Post Sorter :: General', 'Post Sorter', 'administrator', 'page-sorter', array( $this, 'render_menu' ) ); 281 } 282 283 /** 284 * Renders (outputs) admin menu - display the page behind the menu 285 */ 286 public function render_menu() { 298 add_menu_page( 299 __( 'Post Sorter :: General', 'post_sorter' ), 300 __( 'Post Sorter', 'post_sorter' ), 301 'administrator', 302 'post-sorter', 303 array( $this, 'render_main_menu' ) 304 ); 305 306 add_submenu_page( 307 'post-sorter', 308 __( 'Post Sorter :: Permissions', 'post_sorter' ), 309 __( 'Permissions', 'post_sorter' ), 310 'administrator', 311 'post-sorter-permissions', 312 array( $this, 'render_permissions_menu' ) 313 ); 314 315 add_submenu_page( 316 'post-sorter', 317 __( 'Post Sorter :: About', 'post_sorter' ), 318 __( 'About', 'post_sorter' ), 319 'read', 320 'post-sorter-about', 321 array( $this, 'render_about_menu' ) 322 ); 323 } 324 325 /** 326 * Renders (outputs) main admin menu - display the page behind the main menu 327 */ 328 public function render_main_menu() { 287 329 include( plugin_dir_path(__FILE__) . 'page/general.php' ); 288 330 } 289 331 290 public function register_settings() { 332 /** 333 * Renders (outputs) admin menu for permissions - display the page behind the permissions menu 334 */ 335 public function render_permissions_menu() { 336 include( plugin_dir_path(__FILE__) . 'page/permissions.php' ); 337 } 338 339 /** 340 * Renders (outputs) about page of the plugin 341 */ 342 public function render_about_menu() { 343 include( plugin_dir_path(__FILE__) . 'page/about.php' ); 344 } 345 346 // Initial plugin safe-initialization (admin initialized), check for correct state (plugin update), etc. 347 public function set_up() { 348 // Keep the proper condition on enabled roles (when wrong or plugin update) 349 $roles = get_option( 'post_sorter_enabled_roles' ); 350 if(!$roles || !is_array( $roles ) || empty( $roles ) ) 351 update_option( 'post_sorter_enabled_roles', array( 'administrator' ) ); 352 353 // Load plugin meta-data for runtime routines 354 $this->plugin_data = get_plugin_data( __FILE__ ); 291 355 } 292 356 … … 318 382 update_option( 'post_sorter_join_clause', $own_risk ? $this->_sanitize_sql( $_POST['post_sorter_join_clause'] ) : '' ); 319 383 update_option( 'post_sorter_order_by_clause', $own_risk ? $this->_sanitize_sql( $_POST['post_sorter_order_by_clause'] ) : '' ); 384 } 385 386 /** 387 * Saves settings for the plugin 388 */ 389 public function save_permissions() { 390 $roles = ( isset( $_POST['enabled_roles'] ) && is_array( $_POST['enabled_roles'] ) ) ? $_POST['enabled_roles'] : array(); 391 392 // Administrator should by put inside always, no matter of selection 393 if(!in_array('administrator', $roles)) 394 $roles[] = 'administrator'; 395 396 // To be sure we remove any possible duplicates 397 $roles = array_unique($roles); 398 399 // Save the role selection 400 update_option( 'post_sorter_enabled_roles', $roles ); 320 401 } 321 402 … … 334 415 */ 335 416 public function add_meta_box() { 336 add_meta_box( 'post_sorter', __( 'Post Sorter', 'post_sorter' ), array( $this, 'render_meta_box' ), NULL, 'side', 'core' ); 417 if( $this->can_use() ) 418 add_meta_box( 'post_sorter', __( 'Post Sorter', 'post_sorter' ), array( $this, 'render_meta_box' ), NULL, 'side', 'core' ); 337 419 } 338 420 … … 346 428 $val = (int) get_post_meta( $post->ID, POST_SORTER_META_KEY, TRUE ); 347 429 348 if( $this-> _custom ) {430 if( $this->custom ) { 349 431 echo '<div class="post_sorter">' . __( 'Custom sorting is enabled. Factor is ignored.', 'post_sorter' ) . '</div>'; 350 432 return; … … 385 467 $post_id = (int) $post_id; 386 468 387 if ( 0 >= $post_id )469 if ( 0 >= $post_id || !$this->can_use() ) 388 470 return FALSE; 389 471 … … 464 546 } 465 547 466 548 /** 549 * Get roles available in the system (WordPress installation) 550 * @param bool $all Whether to return all roles or only those which are not enabled 551 * @return array Array with available roles 552 */ 553 public function get_available_roles( $all = FALSE ) { 554 global $wp_roles; 555 556 $enabled_keys = get_option( 'post_sorter_enabled_roles' ); 557 $all_roles = $wp_roles->roles; 558 $editable_roles = apply_filters( 'editable_roles', $all_roles ); 559 560 if($all) 561 return $editable_roles; 562 563 return array_diff_key( $editable_roles, array_flip( $enabled_keys ) ); 564 } 565 566 /** 567 * Returns the roles that are enabled to access plugin functionality 568 * @return array The roles which are capable of using the plugin 569 */ 570 public function get_enabled_roles() { 571 $enabled_keys = get_option( 'post_sorter_enabled_roles' ); 572 $roles = $this->get_available_roles( TRUE ); 573 574 return array_intersect_key( $roles, array_flip( $enabled_keys ) ); 575 } 576 577 private function can_use() { 578 $user = wp_get_current_user(); 579 $enabled = get_option( 'post_sorter_enabled_roles' ); 580 $enabled = is_array( $enabled ) ? $enabled : array(); 581 582 error_reporting(E_ALL); 583 ini_set('display_errors', 'yes'); 584 585 return 0 < count( array_intersect( $user->roles, $enabled ) ); 586 } 467 587 468 588 /* == = = = = = = = = = INERNAL FILTERS = = = = = = = = = = == */ … … 531 651 532 652 $data = $this->_move( $post_id, $direction ); 533 534 535 653 $result = new stdClass(); 536 537 //die( print_r( $data ) );538 654 539 655 if ( is_array( $data ) ) -
post-sorter/trunk/readme.txt
r730389 r804473 40 40 With the use of the expert settings and knowledge in SQL you could implement custom sorting. With such sorting the arrows will disappear, since they are no longer applicable. 41 41 42 Access management is now available. You can authorize specific roles to use the plugin from its section - submenu **Permissions**. By default, only administrator would be allowed to operate with the plugin. 43 42 44 == Installation == 43 45 … … 64 66 3. The screen of post edition - you could see the **metabox added with caption *Post Sorter***. 65 67 4. A screenshot of updated Post Sorter settings. 68 5. Permissions screen where you can authorize roles to operate with Post Sorter. 66 69 67 70 == Changelog == 71 72 = 1.4 = 73 Access to plugin funcionality is now granted with permissions. These permissions are given to roles from the new settings screen. 68 74 69 75 = 1.3.1 = -
post-sorter/trunk/uninstall.php
r730333 r804473 5 5 delete_option( 'post_sorter_enabled' ); 6 6 delete_option( 'post_sorter_direction' ); 7 delete_option( 'post_sorter_enabled_roles' ); 7 8 delete_option( 'post_sorter_metakey' ); 8 9
Note: See TracChangeset
for help on using the changeset viewer.