Changeset 513959
- Timestamp:
- 03/03/2012 03:55:11 PM (14 years ago)
- Location:
- database-peek/trunk
- Files:
-
- 2 added
- 4 edited
-
database-peek.php (modified) (20 diffs)
-
integrate.php (added)
-
readme.txt (modified) (3 diffs)
-
screenshot-1.png (modified) (previous)
-
screenshot-2.png (modified) (previous)
-
settings.php (added)
Legend:
- Unmodified
- Added
- Removed
-
database-peek/trunk/database-peek.php
r504375 r513959 27 27 */ 28 28 29 require_once( dirname( __FILE__) . '/integrate.php'); 30 require_once( dirname( __FILE__) . '/settings.php'); 31 32 29 33 if (!class_exists("ABDatabasePeek")) { 30 34 class ABDatabasePeek { 31 35 32 p rivate $footer_msg = 'Database Peek version 1.0Developed by Albert Bertilsson in 2012';33 p rivate$no_access_msg = 'You do not have sufficient permissions to access this page.';36 public static $footer_msg = 'Database Peek version 1.1 Developed by Albert Bertilsson in 2012'; 37 public static $no_access_msg = 'You do not have sufficient permissions to access this page.'; 34 38 35 39 private $wp_ms_tables = array('blogs', 'blog_versions', 'registration_log', 'signups', … … 79 83 add_management_page('Database Peek', 'Database Peek', 'manage_options', 'ab-database-peek', 80 84 array($this,'main_page')); 81 add_options_page('Database Peek', 'Database Peek', 'manage_options', 'ab-database-peek',82 array($this,'settings_page'));83 }84 85 86 function register_mysettings() { // whitelist options87 register_setting( $this->option_group, 'ABDatabasePeek-pagesize' );88 85 } 89 86 … … 161 158 162 159 163 function show_table_link($table, $row = -1) {160 public static function show_table_link($table, $row = -1) { 164 161 $url = admin_url('admin.php?page=ab-database-peek'); 165 162 … … 167 164 168 165 if ($row == -1) 169 remove_query_arg('row');166 $url = remove_query_arg('row', $url); 170 167 else 171 add_query_arg('row', $row);168 $url = add_query_arg('row', $row, $url); 172 169 173 170 return $url; … … 226 223 227 224 225 function check_table_parameter() { 226 if (!isset($_GET['table'])) return false; 227 228 global $wpdb; 229 230 $rows = $wpdb->get_results( "show tables" ); 231 $col = $wpdb->get_col_info('name', 0); 232 foreach ($rows as $row) { 233 if ($_GET['table'] == $row->$col) return true; 234 } 235 236 return false; 237 } 238 239 240 function check_column_parameter($param) { 241 if (!isset($_GET['table'])) return false; 242 if (!isset($_GET[$param])) return false; 243 244 global $wpdb; 245 246 $table = $_GET['table']; 247 $rows = $wpdb->get_results( "select * from $table where 1 = 0" ); 248 $col_names = $wpdb->get_col_info('name'); 249 foreach ($col_names as $n) { 250 if ($_GET[$param] == $n) return true; 251 } 252 253 return false; 254 } 255 256 228 257 function main_page() { 229 258 230 259 //must check that the user has the required capability 231 260 if (!current_user_can('manage_options')) { 232 wp_die( __($this->no_access_msg) ); 233 } 261 wp_die( __(ABDatabasePeek::$no_access_msg) ); 262 } 263 264 $table = false; 265 if ($this->check_table_parameter()) $table = true; 234 266 235 267 global $wpdb; … … 240 272 <br> 241 273 <?php 242 if ( isset($_GET['table'])&& isset($_GET['row'])) {274 if ($table && isset($_GET['row'])) { 243 275 $this->show_row($_GET['table'], $_GET['row']); 244 276 } 245 277 else { 246 if ( isset($_GET['table'])) {278 if ($table) { 247 279 $this->display_table($_GET['table']); 248 280 } … … 254 286 <br> 255 287 <div class="info"> 256 <?php _e( $this->footer_msg); ?>288 <?php _e(ABDatabasePeek::$footer_msg); ?> 257 289 </div> 258 290 … … 260 292 <?php 261 293 } 262 263 264 265 function settings_page() { 266 267 //must check that the user has the required capability 268 if (!current_user_can('manage_options')) { 269 wp_die( __($this->no_access_msg) ); 270 } 271 272 if (isset($_GET['settings-updated'])) { 273 ?> 274 <div class="updated"><p><strong> 275 <?php _e('Settings saved.' ); ?> 276 </strong></p></div><?php 277 } 278 279 ?> 280 <div class="wrap"> 281 <div id="icon-options-general" class="icon32"></div> 282 <h2>Database Peek Settings</h2> 283 <form method="POST" action="options.php"> 284 <?php 285 settings_fields( $this->option_group ); 286 do_settings_sections( $this->option_group ); 287 ?> 288 <table class="form-table"><tbody> 289 <tr valign="top"> 290 <th scope="row"> 291 <label for="pagesize">Rows per page</label> 292 </th> 293 <td> 294 <input type="text" id="ABDatabasePeek-pagesize" maxlength="5" size="10" name="ABDatabasePeek-pagesize" 295 value="<?php echo $this->get_numeric_option('ABDatabasePeek-pagesize', 1, 100); ?>" class="regular-text" /> 296 <span class="description">For table display (default = 100)</span> 297 </td> 298 </tr> 299 </tbody></table> 300 <p class="submit"> 301 <input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"> 302 </p> 303 </form> 304 <div class="info"> 305 <?php _e($this->footer_msg); ?> 306 </div> 307 </div> 308 <?php 309 } 310 294 311 295 312 296 … … 472 456 473 457 474 function get_numeric_option($name, $min, $default) {475 $value = get_option($name);476 if (empty($value)) $value = $default;477 478 if (is_numeric($value))479 $value = (int)$value;480 481 if ($value < $min) $value = $min;482 483 return $value;484 }485 486 487 458 function display_table($table) { 488 459 … … 493 464 $pagenum = isset( $_GET['pagenum'] ) ? absint( $_GET['pagenum'] ) : 1; 494 465 495 $limit = $this->get_numeric_option('ABDatabasePeek-pagesize', 1, 100);466 $limit = ABDatabasePeekSettings::option_pagesize(); 496 467 497 468 $offset = ( $pagenum - 1 ) * $limit; … … 504 475 </h3> 505 476 506 <?php 507 $total = $wpdb->get_var( $wpdb->prepare( "select count(*) from $table" ) ); 477 <form method="get" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> 478 <?php 479 foreach ($_GET as $k => $v) { 480 if ($k != 'filter' && $k != 'match') 481 echo "<input type=\"hidden\" name=\"$k\" value=\"$v\">"; 482 } 483 ?> 484 485 <select name="filter"> 486 <?php 487 $rows = $wpdb->get_results( "select * from $table where 1 = 0" ); 488 $col_names = $wpdb->get_col_info('name'); 489 foreach ($col_names as $n) { 490 $selected = ''; 491 if (isset($_GET['filter']) && $_GET['filter'] == $n) $selected = 'selected'; 492 echo "<option value=\"$n\" $selected>$n</option>"; 493 } 494 ?> 495 </select> 496 <input type="text" name="match" maxlength="20" size="10" class="regular-text" value="<?php if( isset($_GET['match']) ) echo $_GET['match']; ?>"> 497 <input type="submit" class="button-primary" value="Filter"> 498 </form> 499 500 <?php 501 $filter = ''; 502 $match = ''; 503 if (isset($_GET['filter']) && $this->check_column_parameter('filter') && isset($_GET['match'])) { 504 //$filter = 'where ' . $_GET['filter'] . ' like "%%' . $_GET['match'] . '%%"'; 505 $filter = 'where ' . $_GET['filter'] . ' like %s'; 506 $match = '%' . $_GET['match'] . '%'; 507 } 508 509 $total = $wpdb->get_var( $wpdb->prepare( "select count(*) from $table $filter", $match ) ); 510 $tabletotal = $wpdb->get_var( "select count(*) from $table" ); 508 511 $num_of_pages = ceil( $total / $limit ); 509 512 $page_links = paginate_links( array( … … 517 520 518 521 if ( $page_links ) { 519 echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>'; 520 } 521 522 $rows = $wpdb->get_results( "select * from $table limit $offset, $limit" ); 522 echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . ' ' . $total . ' / ' . $tabletotal . '</div></div>'; 523 } else { 524 echo '<br>'; 525 } 526 527 $orderby = ''; 528 if (isset( $_GET['sort'] ) && $this->check_column_parameter('sort')) $orderby = 'order by ' . $_GET['sort']; 529 if (isset( $_GET['desc'] ) ) $orderby .= ' desc'; 530 531 $rows = $wpdb->get_results( $wpdb->prepare( "select * from $table $filter $orderby limit $offset, $limit", $match ) ); 523 532 524 533 ?> … … 531 540 foreach ($col_names as $n) { 532 541 echo '<th>'; 533 542 543 $sort = add_query_arg('sort', $n, $_SERVER["REQUEST_URI"]); 544 if (isset( $_GET['sort'] ) && $_GET['sort'] == $n) { 545 if (isset($_GET['desc'])) 546 $sort = remove_query_arg('desc', $sort); 547 else 548 $sort = add_query_arg('desc', '', $sort); 549 } 550 else 551 $sort = remove_query_arg('desc', $sort); 552 553 echo "<a href=\"$sort\">"; 554 if (isset( $_GET['sort'] ) && $_GET['sort'] == $n) echo '<strong>'; 534 555 if (count($col_names) > 5) 535 556 for ($i = 0 ; $i < strlen($n) ; $i++) … … 538 559 echo $n; 539 560 561 if (isset( $_GET['sort'] ) && $_GET['sort'] == $n) echo '</strong>'; 562 echo '</a>'; 540 563 echo '</th>'; 541 564 } … … 566 589 567 590 if ( $page_links ) { 568 echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . '</div></div>'; 569 } 570 571 } 572 573 574 591 echo '<div class="tablenav"><div class="tablenav-pages" style="margin: 1em 0">' . $page_links . ' ' . $total . ' / ' . $tabletotal . '</div></div>'; 592 } 593 594 } 595 596 575 597 function list_tables() { 576 598 global $wpdb; … … 578 600 $rows = $wpdb->get_results( "show tables" ); 579 601 $col = $wpdb->get_col_info('name', 0); 602 $trow = 0; 580 603 581 604 ?> … … 611 634 612 635 $count++; 636 $trow += $rowcount; 613 637 } 614 638 } … … 635 659 636 660 $count++; 661 $trow += $rowcount; 637 662 } 638 663 } … … 657 682 658 683 $count++; 684 $trow += $rowcount; 659 685 } 660 686 } 661 687 } 662 688 ?> 663 </tbody></table> 689 </tbody> 690 <tfoot><tr> 691 <th><?php echo $count; ?></th><th></th><th><?php echo $trow; ?></th> 692 </tr></tfoot> 693 </table> 664 694 <?php 665 695 } … … 669 699 670 700 701 671 702 $ab_database_peek = new ABDatabasePeek(); 672 703 673 704 if (isset($ab_database_peek)) { 674 // create the menu675 705 if (is_admin()) { 676 706 add_action('admin_menu', array($ab_database_peek,'create_menus')); 677 678 add_action( 'admin_init', array($ab_database_peek,'register_mysettings') );679 707 } 680 708 } 681 ?> 709 710 711 712 $ab_database_peek_settings = new ABDatabasePeekSettings(); 713 714 if (isset($ab_database_peek_settings)) { 715 if (is_admin()) { 716 add_action('admin_menu', array($ab_database_peek_settings,'create_menus')); 717 add_action( 'admin_init', array($ab_database_peek_settings,'register_mysettings') ); 718 } 719 } 720 721 722 723 $ab_database_peek_integrate = new ABDatabasePeekIntegrate(); 724 725 if (isset($ab_database_peek_integrate)) { 726 if (is_admin()) { 727 $ab_database_peek_integrate->integrate(); 728 } 729 } -
database-peek/trunk/readme.txt
r504351 r513959 4 4 Requires at least: 3.0.1 5 5 Tested up to: 3.3.1 6 Stable tag: 1. 06 Stable tag: 1.1 7 7 8 8 Database Peek allows admins to view the database content in a user friendly and safe way. … … 10 10 == Description == 11 11 12 For those with a need to look at the pure contents of the WordPress database. The plugin gives admins a user friendly and safe way to display the tables of the database as well as show the detailed information of the tables and view each row of data including rows in other tables referring to the displayed row. 12 For those with a need to look at the pure contents of the WordPress database. The plugin gives admins a user friendly and safe way to display the tables of the database as well as show the detailed information of the tables and view each row of data including rows in other tables referring to the displayed row. Functionallity for filtering and sorting makes it very easy to get a good overview and find specific data. Integration with other parts of the administration tool makes it quick and easy to examine various entities in the database. 13 13 14 14 This is not a replacement to having access to the WordPress database but it provides several benefits: … … 32 32 == Changelog == 33 33 34 = 1.1 = 35 * Fixed bug in the function that created links between tables. 36 * Code clean up, separate file for options. 37 * Added settings option to add shortcut links on edit page for pages and posts. 38 * Added shortcut links on listing pages for pages, posts, tags, comments and links. 39 * Added sums of total number of tables and rows in the footer of the table list. 40 * Added clickable column names to sort the display order. 41 * Added option to filter results by matching a value in a selected column. 42 34 43 = 1.0 = 35 44 * Initial Release
Note: See TracChangeset
for help on using the changeset viewer.