BaseHandler.php
11 years ago
EmptyTrashHandler.php
11 years ago
GetTaxonomiesHandler.php
11 years ago
ListingSortHandler.php
11 years ago
NestToggleHandler.php
11 years ago
NewChildHandler.php
11 years ago
NewLinkHandler.php
11 years ago
QuickEditHandler.php
11 years ago
QuickEditLinkHandler.php
11 years ago
SearchHandler.php
11 years ago
SortHandler.php
11 years ago
SyncMenuHandler.php
11 years ago
ListingSortHandler.php
74 lines
| 1 | <?php namespace NestedPages\Form\Handlers; |
| 2 | /** |
| 3 | * Redirect to Listing with Specified Sorting Options Applied |
| 4 | */ |
| 5 | class ListingSortHandler { |
| 6 | |
| 7 | /** |
| 8 | * URL to redirect to |
| 9 | * @var string |
| 10 | */ |
| 11 | private $url; |
| 12 | |
| 13 | |
| 14 | public function __construct() |
| 15 | { |
| 16 | $this->setURL(); |
| 17 | $this->redirect(); |
| 18 | } |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Build the URL to Redirect to |
| 23 | */ |
| 24 | private function setURL() |
| 25 | { |
| 26 | $this->url = sanitize_text_field($_POST['page']); |
| 27 | $this->setOrderBy(); |
| 28 | $this->setOrder(); |
| 29 | $this->setAuthor(); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | /** |
| 34 | * Set Order by parameters |
| 35 | */ |
| 36 | private function setOrderBy() |
| 37 | { |
| 38 | $allowed = array('menu_order', 'date', 'title'); // prevent tomfoolery |
| 39 | if ( ($_POST['np_orderby'] !== "") && (!in_array($_POST['np_orderby'], $allowed)) ) $this->url .= '&orderby=menu_order'; |
| 40 | $this->url .= '&orderby=' . sanitize_text_field($_POST['np_orderby']); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | /** |
| 45 | * Set Order parameters |
| 46 | */ |
| 47 | private function setOrder() |
| 48 | { |
| 49 | $allowed = array('ASC', 'DESC'); // prevent tomfoolery |
| 50 | if ( !in_array($_POST['np_order'], $allowed) ) $this->url .= '&order=DESC'; |
| 51 | $this->url .= '&order=' . sanitize_text_field($_POST['np_order']); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Set Author parameters |
| 57 | */ |
| 58 | private function setAuthor() |
| 59 | { |
| 60 | if ( (isset($_POST['np_author'])) && ($_POST['np_author'] !== "") ){ |
| 61 | $this->url .= '&author=' . sanitize_text_field($_POST['np_author']); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | |
| 66 | /** |
| 67 | * Redirect to new URL |
| 68 | */ |
| 69 | private function redirect() |
| 70 | { |
| 71 | header('Location:' . $this->url); |
| 72 | } |
| 73 | |
| 74 | } |