help.php
13 years ago
home.php
13 years ago
import.php
13 years ago
manage.php
13 years ago
settings.php
13 years ago
manage.php
108 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Manage Imports |
| 4 | * |
| 5 | * @author Pavel Kulbakin <p.kulbakin@gmail.com> |
| 6 | */ |
| 7 | class PMXI_Admin_Manage extends PMXI_Controller_Admin { |
| 8 | |
| 9 | public function init() { |
| 10 | parent::init(); |
| 11 | |
| 12 | if ('update' == PMXI_Plugin::getInstance()->getAdminCurrentScreen()->action) { |
| 13 | $this->isInline = true; |
| 14 | if ( ! session_id()) session_start(); // prevent session initialization throw a notification in inline mode of delegated plugin |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * Previous Imports list |
| 20 | */ |
| 21 | public function index() { |
| 22 | |
| 23 | $get = $this->input->get(array( |
| 24 | 's' => '', |
| 25 | 'order_by' => 'name', |
| 26 | 'order' => 'ASC', |
| 27 | 'pagenum' => 1, |
| 28 | 'perPage' => 10, |
| 29 | )); |
| 30 | $get['pagenum'] = absint($get['pagenum']); |
| 31 | extract($get); |
| 32 | $this->data += $get; |
| 33 | |
| 34 | $list = new PMXI_Import_List(); |
| 35 | $post = new PMXI_Post_Record(); |
| 36 | $by = NULL; |
| 37 | if ('' != $s) { |
| 38 | $like = '%' . preg_replace('%\s+%', '%', preg_replace('/[%?]/', '\\\\$0', $s)) . '%'; |
| 39 | $by[] = array(array('name LIKE' => $like, 'type LIKE' => $like, 'path LIKE' => $like), 'OR'); |
| 40 | } |
| 41 | |
| 42 | $this->data['list'] = $list->join($post->getTable(), $list->getTable() . '.id = ' . $post->getTable() . '.import_id', 'LEFT') |
| 43 | ->setColumns( |
| 44 | $list->getTable() . '.*', |
| 45 | 'COUNT(' . $post->getTable() . '.post_id' . ') AS post_count' |
| 46 | ) |
| 47 | ->getBy($by, "$order_by $order", $pagenum, $perPage, $list->getTable() . '.id'); |
| 48 | |
| 49 | $this->data['page_links'] = paginate_links(array( |
| 50 | 'base' => add_query_arg('pagenum', '%#%', $this->baseUrl), |
| 51 | 'format' => '', |
| 52 | 'prev_text' => __('«', 'pmxi_plugin'), |
| 53 | 'next_text' => __('»', 'pmxi_plugin'), |
| 54 | 'total' => ceil($list->total() / $perPage), |
| 55 | 'current' => $pagenum, |
| 56 | )); |
| 57 | |
| 58 | $this->render(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Delete an import |
| 63 | */ |
| 64 | public function delete() { |
| 65 | $id = $this->input->get('id'); |
| 66 | $this->data['item'] = $item = new PMXI_Import_Record(); |
| 67 | if ( ! $id or $item->getById($id)->isEmpty()) { |
| 68 | wp_redirect($this->baseUrl); die(); |
| 69 | } |
| 70 | |
| 71 | if ($this->input->post('is_confirmed')) { |
| 72 | check_admin_referer('delete-import', '_wpnonce_delete-import'); |
| 73 | |
| 74 | $item->delete( ! $this->input->post('is_delete_posts')); |
| 75 | wp_redirect(add_query_arg('pmxi_nt', urlencode(__('Import deleted', 'pmxi_plugin')), $this->baseUrl)); die(); |
| 76 | } |
| 77 | |
| 78 | $this->render(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Bulk actions |
| 83 | */ |
| 84 | public function bulk() { |
| 85 | check_admin_referer('bulk-imports', '_wpnonce_bulk-imports'); |
| 86 | if ($this->input->post('doaction2')) { |
| 87 | $this->data['action'] = $action = $this->input->post('bulk-action2'); |
| 88 | } else { |
| 89 | $this->data['action'] = $action = $this->input->post('bulk-action'); |
| 90 | } |
| 91 | $this->data['ids'] = $ids = $this->input->post('items'); |
| 92 | $this->data['items'] = $items = new PMXI_Import_List(); |
| 93 | if (empty($action) or ! in_array($action, array('delete')) or empty($ids) or $items->getBy('id', $ids)->isEmpty()) { |
| 94 | wp_redirect($this->baseUrl); die(); |
| 95 | } |
| 96 | |
| 97 | if ($this->input->post('is_confirmed')) { |
| 98 | $is_delete_posts = $this->input->post('is_delete_posts'); |
| 99 | foreach($items->convertRecords() as $item) { |
| 100 | $item->delete( ! $is_delete_posts); |
| 101 | } |
| 102 | |
| 103 | wp_redirect(add_query_arg('pmxi_nt', urlencode(sprintf(__('<strong>%d</strong> %s deleted', 'pmxi_plugin'), $items->count(), _n('import', 'imports', $items->count(), 'pmxi_plugin'))), $this->baseUrl)); die(); |
| 104 | } |
| 105 | |
| 106 | $this->render(); |
| 107 | } |
| 108 | } |