| | 283 | // Retrieve and set pagination information |
|---|
| | 284 | $s = isset( $_GET['s'] ) ? urldecode( $_GET['s'] ) : ''; // Number of acronyms per page |
|---|
| | 285 | $o = isset( $_GET['o'] ) ? urldecode( $_GET['o'] ) : 'acronym'; // Sort acronyms by initalism or by full text (default is initialism) |
|---|
| | 286 | $p = isset( $_GET['p'] ) && is_numeric( $_GET['p'] ) && 0 < $_GET['p'] ? $_GET['p'] : 1; // Which page to display |
|---|
| | 287 | if ( isset( $_GET['n'] ) ) { // Number of acronyms per page |
|---|
| | 288 | if ( is_numeric( $_GET['n'] ) && 0 < $_GET['n'] ) $n = $_GET['n']; |
|---|
| | 289 | else if ( 'All' == $_GET['n'] ) $n = 0; |
|---|
| | 290 | } |
|---|
| | 291 | else $n = get_option( 'default_num_of_acronyms' ); |
|---|
| | 292 | if ( 0 == $n ) $t = 1; |
|---|
| | 293 | else $t = ceil( Acronyms::count_acronyms( $s ) / $n ); // Total number of pages, rounded up to nearest integer |
|---|
| 274 | | <h2><?php |
|---|
| 275 | | _e('Manage Acronyms'); |
|---|
| 276 | | if( 'edit' != $_GET['action'] ) echo ' (<a href="#addacronym">' . __('add new') . '</a>)' |
|---|
| 277 | | ?></h2> |
|---|
| 278 | | <p id="post-search"> |
|---|
| 279 | | <input type="text" id="post-search-input" name="s" value="<?php echo attribute_escape(stripslashes($_GET['s'])); ?>" /> |
|---|
| 280 | | <input type="submit" value="<?php _e( 'Search acronyms' ); ?>" class="button" /> |
|---|
| 281 | | </p> |
|---|
| 282 | | <br class="clear" /> |
|---|
| 283 | | |
|---|
| 284 | | <div class="tablenav"> |
|---|
| 285 | | <div class="alignleft"> |
|---|
| 286 | | <input type="submit" value="<?php _e('Delete') ?>" name="deleteit" class="button-secondary delete" /> |
|---|
| 287 | | <?php wp_nonce_field('delete-acronym'); ?> |
|---|
| 288 | | </div> |
|---|
| 289 | | <br class="clear" /> |
|---|
| 290 | | </div> |
|---|
| 291 | | <br class="clear" /> |
|---|
| 292 | | <?php Acronyms::show_acronym_list($_GET['s']) ?> |
|---|
| | 298 | <h2><?php |
|---|
| | 299 | _e('Manage Acronyms'); |
|---|
| | 300 | if( 'edit' != $_GET['action'] ) echo ' (<a href="#addacronym">' . __('add new') . '</a>)' |
|---|
| | 301 | ?></h2> |
|---|
| | 302 | <p id="post-search"> |
|---|
| | 303 | <input type="text" id="post-search-input" name="search" value="<?php echo attribute_escape( stripslashes( $_GET['s'] ) ); ?>" /> |
|---|
| | 304 | <input type="submit" value="<?php _e( 'Search acronyms' ); ?>" class="button" /> |
|---|
| | 305 | </p> |
|---|
| | 306 | <br class="clear" /> |
|---|
| | 307 | <?php |
|---|
| | 308 | Acronyms::show_pagination_bar( $n, $p, $t, $o, true); |
|---|
| | 309 | Acronyms::show_acronym_list( $s, $n, $p, $o ); |
|---|
| | 310 | Acronyms::show_pagination_bar( $n, $p, $t, $o); |
|---|
| | 311 | ?> |
|---|
| 325 | | * Displays the list of acronyms, filtered by search term $s and showing page # $page_num based on $num_of_acronyms per page |
|---|
| 326 | | */ |
|---|
| 327 | | function show_acronym_list ( $s ) |
|---|
| 328 | | { |
|---|
| | 344 | * Displays the list of acronyms, filtered by search term $s and showing page # $p based on $n per page |
|---|
| | 345 | */ |
|---|
| | 346 | function show_acronym_list ( $s, $n, $p = '1', $o = 'acronym' ) |
|---|
| | 347 | { |
|---|
| | 348 | // Sort the acronyms appropriately |
|---|
| | 349 | $acronyms = get_option( 'acronym_acronyms' ); |
|---|
| | 350 | if ( 'full' == $o ) |
|---|
| | 351 | natcasesort( $acronyms ); |
|---|
| | 352 | else |
|---|
| | 353 | uksort( $acronyms, "strnatcmp"); |
|---|
| | 354 | |
|---|
| 343 | | if ( ( '' == $s ) || ( ( false !== strpos( strtolower( $acronym ), strtolower( $s ) ) ) || ( false !== strpos( strtolower( $fulltext ), strtolower( $s ) ) ) ) ) { |
|---|
| 344 | | ?> |
|---|
| 345 | | <tr<?php if (0 == $i++ % 2) echo ' class="alternate"' ?>> |
|---|
| 346 | | <th scope="row" class="check-column"> <input type="checkbox" name="delete_acronyms[]" value="<?php echo $acronym ?>" /></th> |
|---|
| 347 | | <td><strong> |
|---|
| 348 | | <a class="row-title" href="edit.php?page=acronyms.php&action=edit&acronym=<?php echo urlencode( $acronym ) ?>&fulltext=<?php echo urlencode( $fulltext ) ?>" title="Edit "<?php echo $acronym ?>""> |
|---|
| 349 | | <?php echo $acronym ?> |
|---|
| 350 | | </a></strong></td> |
|---|
| 351 | | <td><?php echo $fulltext ?></td> |
|---|
| 352 | | </tr> |
|---|
| 353 | | <?php |
|---|
| | 371 | if ( ( '' == $s ) || ( ( false !== strpos( strtolower( $acronym ), strtolower( $s ) ) ) || ( false !== strpos( strtolower( $fulltext ), strtolower( $s ) ) ) ) ) |
|---|
| | 372 | { |
|---|
| | 373 | if ( 0 == $n || ( ++$index >= $index_start && $index <= $index_end ) ) { |
|---|
| | 374 | ?> |
|---|
| | 375 | <tr<?php if (0 == $i++ % 2) echo ' class="alternate"' ?>> |
|---|
| | 376 | <th scope="row" class="check-column"> <input type="checkbox" name="delete_acronyms[]" value="<?php echo $acronym ?>" /></th> |
|---|
| | 377 | <td><strong> |
|---|
| | 378 | <a class="row-title" href="edit.php?page=acronyms.php&action=edit&acronym=<?php echo urlencode( $acronym ) ?>&fulltext=<?php echo urlencode( $fulltext ) ?>" title="Edit "<?php echo $acronym ?>""><?php echo $acronym ?></a></strong></td> |
|---|
| | 379 | <td><?php echo $fulltext ?></td> |
|---|
| | 380 | </tr> |
|---|
| | 381 | <?php |
|---|
| | 382 | } |
|---|
| | 391 | function show_pagination_bar ( $n, $p, $t, $o, $filter = false) |
|---|
| | 392 | { |
|---|
| | 393 | echo '<div class="tablenav">'; |
|---|
| | 394 | // Display pagination links |
|---|
| | 395 | $page_links = paginate_links( array( |
|---|
| | 396 | 'base' => add_query_arg( 'p', '%#%' ), |
|---|
| | 397 | 'format' => '', |
|---|
| | 398 | 'total' => $t, |
|---|
| | 399 | 'current' => $p, |
|---|
| | 400 | 'add_args' => $n |
|---|
| | 401 | ) ); |
|---|
| | 402 | |
|---|
| | 403 | if ( 0 < $n && $page_links ) |
|---|
| | 404 | echo "<div class='tablenav-pages'>$page_links</div>"; |
|---|
| | 405 | ?> |
|---|
| | 406 | |
|---|
| | 407 | <div class="alignleft"> |
|---|
| | 408 | <input type="submit" value="<?php _e('Delete') ?>" name="deleteit" class="button-secondary delete" /> |
|---|
| | 409 | <?php |
|---|
| | 410 | wp_nonce_field('delete-acronym'); |
|---|
| | 411 | if ( $filter ) { |
|---|
| | 412 | echo '<select name="n" id="n">'; |
|---|
| | 413 | $num_options = array ( 5, 15, 25, 50, 'All' ); |
|---|
| | 414 | foreach ( $num_options as $option ) { |
|---|
| | 415 | echo '<option value="' . $option . '"'; |
|---|
| | 416 | if ( $n == $option ) echo ' selected="selected" '; |
|---|
| | 417 | echo '>Show ' . $option . ' acronyms per page</option>'; |
|---|
| | 418 | } |
|---|
| | 419 | ?> |
|---|
| | 420 | </select> |
|---|
| | 421 | <select name="o" id="o"> |
|---|
| | 422 | <option value="acronym"<?php echo 'acronym' == $o ? ' selected="selected"' : '' ?>>Order by acronym</option> |
|---|
| | 423 | <option value="full"<?php echo 'full' == $o ? ' selected="selected"' : '' ?>>Order by full text</option> |
|---|
| | 424 | </select> |
|---|
| | 425 | <input type="submit" value="Filter" class="button-secondary" /> |
|---|
| | 426 | <?php |
|---|
| | 427 | } |
|---|
| | 428 | ?> |
|---|
| | 429 | </div> |
|---|
| | 430 | <br class="clear" /> |
|---|
| | 431 | </div> |
|---|
| | 432 | <br class="clear" /> |
|---|
| | 433 | <?php |
|---|
| | 434 | } |
|---|
| | 435 | |
|---|
| | 500 | return true; |
|---|
| | 501 | } |
|---|
| | 502 | else return false; |
|---|
| | 503 | } |
|---|
| | 504 | |
|---|
| | 505 | /* int count_acronyms ( string $s ) |
|---|
| | 506 | * |
|---|
| | 507 | * Get the number of acronyms based on the search term if provided |
|---|
| | 508 | */ |
|---|
| | 509 | function count_acronyms ( $s = '' ) |
|---|
| | 510 | { |
|---|
| | 511 | $acronyms = get_option( 'acronym_acronyms' ); |
|---|
| | 512 | if ( empty( $s ) ) return count( $acronyms ); |
|---|
| | 513 | else { |
|---|
| | 514 | $index = 0; |
|---|
| | 515 | foreach ( $acronyms as $acronym => $fulltext ) |
|---|
| | 516 | { |
|---|
| | 517 | if ( false !== strpos( strtolower( $acronym ), strtolower( $s ) ) || ( false !== strpos( strtolower( $fulltext ), strtolower( $s ) ) ) ) |
|---|
| | 518 | { |
|---|
| | 519 | $index++; |
|---|
| | 520 | } |
|---|
| | 521 | } |
|---|
| | 522 | return $index; |
|---|