/**
  * Action
  *
  * @return void
  */
 public function action()
 {
     // Create custom nonce
     $this->create_nonce('general_settings');
     // Load views if action is empty
     if (empty($this->action)) {
         $this->content($this->view());
     }
     // Load views if action is not empty (handle postdata)
     if (!empty($this->action) && check_admin_referer($this->nonce, '_nonce')) {
         $this->process_postdata($_POST);
         if ($this->is_ajax === false) {
             wp_redirect($this->referrer);
             exit;
         } else {
             GW_GoPricing_AdminNotices::show();
         }
     }
 }
 /**
  * Action
  *
  * @return void
  */
 public function action()
 {
     // Create custom nonce
     $this->create_nonce('main');
     // Load views if action is empty
     if (empty($this->action)) {
         $action = isset($_GET['action']) ? $_GET['action'] : '';
         switch ($action) {
             case 'create':
                 // Load table editor view
                 $this->content($this->view('table_editor'));
                 break;
             case 'edit':
                 $result = GW_GoPricing_Data::get_table((int) $_GET['id']);
                 if (empty($result)) {
                     // Load table manager view
                     $this->content($this->view());
                 } else {
                     // Load table editor view
                     $this->content($this->view('table_editor'));
                 }
                 break;
             default:
                 // Load table manager view
                 $this->content($this->view());
         }
     }
     // Load views if action is not empty (handle postdata)
     if (!empty($this->action) && check_admin_referer($this->nonce, '_nonce')) {
         switch ($this->action) {
             // Table manager page (action)
             case 'table_manager':
                 if (!empty($this->action_type)) {
                     switch ($this->action_type) {
                         // Create (action type)
                         case 'create':
                             // Redirect / Load view
                             if ($this->is_ajax === false) {
                                 wp_redirect(add_query_arg('action', 'create', 'admin.php?page=go-pricing'));
                                 exit;
                             } else {
                                 echo $this->view('table_editor');
                             }
                             break;
                             // Edit (action type)
                         // Edit (action type)
                         case 'edit':
                             $result = $this->validate_edit((int) $_POST['postid']);
                             // Check whether table id is valid/invalid
                             if ($result === false) {
                                 // Redirect / Load view
                                 if ($this->is_ajax === false) {
                                     wp_redirect(admin_url('admin.php?page=go-pricing'));
                                     exit;
                                 } else {
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 // Redirect / Load view
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg(array('action' => 'edit', 'id' => $_POST['postid']), admin_url('admin.php?page=go-pricing')));
                                     exit;
                                 } else {
                                     echo $this->view('table_editor');
                                 }
                             }
                             break;
                             // Copy	(action type)
                         // Copy	(action type)
                         case 'copy':
                             $result = $this->copy_table($_POST['postid']);
                             // Redirect / Load view
                             if ($this->is_ajax === false) {
                                 wp_redirect(admin_url('admin.php?page=go-pricing'));
                                 exit;
                             } else {
                                 echo $this->view();
                                 GW_GoPricing_AdminNotices::show();
                             }
                             break;
                             // Delete (action type)
                         // Delete (action type)
                         case 'delete':
                             $result = $this->delete_table($_POST['postid']);
                             // Redirect / Load view
                             if ($this->is_ajax === false) {
                                 wp_redirect(admin_url('admin.php?page=go-pricing'));
                                 exit;
                             } else {
                                 echo $this->view();
                                 GW_GoPricing_AdminNotices::show();
                             }
                             break;
                             // Order (action type)
                         // Order (action type)
                         case 'order':
                             $user_id = get_current_user_id();
                             if (!empty($_POST['_order']) && !empty($_POST['_orderby'])) {
                                 switch ($_POST['_order']) {
                                     case 'ASC':
                                     case 'DESC':
                                         setcookie("go_pricing[settings][tm][order][{$user_id}]", $_POST['_order']);
                                         break;
                                 }
                                 switch ($_POST['_orderby']) {
                                     case 'ID':
                                     case 'title':
                                     case 'date':
                                     case 'modified':
                                         setcookie("go_pricing[settings][tm][orderby][{$user_id}]", $_POST['_orderby']);
                                         break;
                                 }
                             }
                             // Redirect / Load view
                             if ($this->is_ajax === false) {
                                 wp_redirect(admin_url('admin.php?page=go-pricing'));
                                 exit;
                             } else {
                                 echo $this->view();
                                 GW_GoPricing_AdminNotices::show();
                             }
                             break;
                             // Export (action type)
                         // Export (action type)
                         case 'export':
                             if (empty($_POST['postid'])) {
                                 return;
                             }
                             $table_ids = explode(',', $_POST['postid']);
                             $result = $this->validate_export_data($table_ids);
                             if ($result === false) {
                                 if ($this->is_ajax === false) {
                                     wp_redirect($this->referrer);
                                     exit;
                                 } else {
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 $this->set_temp_postdata($table_ids);
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg(array('action' => 'export'), admin_url('admin.php?page=go-pricing-import-export')));
                                     exit;
                                 } else {
                                     echo '<div id="download_url">' . add_query_arg(array('action' => 'export'), admin_url('admin.php?page=go-pricing-import-export')) . '</div>';
                                 }
                             }
                             break;
                     }
                 }
                 break;
                 // Import page (action)
             // Import page (action)
             case 'table_editor':
                 $result = $this->save_table($_POST);
                 if ($result === false) {
                     if ($this->is_ajax === false) {
                         wp_redirect(add_query_arg('action', 'create', $this->referrer));
                         exit;
                     } else {
                         GW_GoPricing_AdminNotices::show();
                     }
                 } else {
                     if ($this->is_ajax === false) {
                         wp_redirect(add_query_arg(array('action' => 'edit', 'id' => $result), admin_url('admin.php?page=go-pricing')));
                         exit;
                     } else {
                         echo '<div id="postid">' . $result . '</div>';
                         GW_GoPricing_AdminNotices::show();
                     }
                 }
                 break;
                 // Add new column (ajax action type)
             // Add new column (ajax action type)
             case 'table_column':
                 $body_row_count = isset($_POST['body_row_count']) ? (int) $_POST['body_row_count'] : 0;
                 $footer_row_count = isset($_POST['footer_row_count']) ? (int) $_POST['footer_row_count'] : 0;
                 echo $this->get_column(null, $body_row_count, $footer_row_count);
                 break;
                 // Add new body row (ajax action type)
             // Add new body row (ajax action type)
             case 'table_row':
                 echo $this->get_column_body(null, null, 1);
                 break;
                 // Add new footer row (ajax action type)
             // Add new footer row (ajax action type)
             case 'table_button':
                 echo $this->get_column_footer(null, null, 1);
                 break;
                 // Load popup (ajax action type)
             // Load popup (ajax action type)
             case 'popup':
                 echo $this->load_popup();
                 break;
                 // Load editor popup (ajax action type)
             // Load editor popup (ajax action type)
             case 'editor_popup':
                 echo $this->editor_popup();
                 break;
                 // (Re)load editor (ajax action type)
             // (Re)load editor (ajax action type)
             case 'editor_columns':
                 echo $this->get_editor_columns();
                 break;
         }
     }
 }
Example #3
0
 /**
  * Ajax action router (handle callbacks)
  *
  * @return void
  */
 public static function ajax_action_router()
 {
     if (empty($_POST['action']) || empty($_POST['_action'])) {
         GW_GoPricing_AdminNotices::add('ajax', 'error', __('No AJAX action has been found!', 'go_pricing_textdomain'));
         GW_GoPricing_AdminNotices::show();
         exit;
     }
     $actions = get_option(self::$plugin_prefix . '_ajax_actions');
     if (empty($actions['data']) || empty($actions['token']) || sha1(@serialize($actions['data'])) != $actions['token']) {
         GW_GoPricing_AdminNotices::add('ajax', 'error', __('Invalid AJAX callback has been detected! Please, refresh the page!', 'go_pricing_textdomain'));
         GW_GoPricing_AdminNotices::show();
         exit;
     }
     if (!empty($actions['data'][$_POST['_action']])) {
         call_user_func($actions['data'][$_POST['_action']]);
     } else {
         GW_GoPricing_AdminNotices::add('ajax', 'error', __('No AJAX callback has been registered for this action! Please, refresh the page!', 'go_pricing_textdomain'));
         GW_GoPricing_AdminNotices::show();
         exit;
     }
     exit;
 }
 /**
  * Action
  *
  * @return void
  */
 public function action()
 {
     // Create custom nonce
     $this->create_nonce('impex');
     // Load views if action is empty
     if (empty($this->action)) {
         $action = isset($_GET['action']) ? $_GET['action'] : '';
         switch ($action) {
             case 'import':
                 $tmp_postdata = $this->get_temp_postdata();
                 if (empty($tmp_postdata)) {
                     // Load default view
                     $this->content($this->view());
                 } else {
                     // Load import view
                     $this->content($this->view('import'));
                 }
                 break;
             case 'export':
                 $tmp_postdata = $this->get_temp_postdata();
                 if (empty($tmp_postdata)) {
                     // Load default view
                     $this->content($this->view());
                 } else {
                     // Load export view
                     $this->content($this->view('export'));
                 }
                 break;
             default:
                 // Load default view
                 $this->content($this->view());
         }
     }
     // Load views if action is not empty (handle postdata)
     if (!empty($this->action) && check_admin_referer($this->nonce, '_nonce')) {
         switch ($this->action) {
             // Default
             case 'impex':
                 if (!empty($this->action_type)) {
                     switch ($this->action_type) {
                         // Import
                         case 'import':
                             $result = $this->validate_import_data(stripslashes($_POST['import-data']));
                             if ($result === false) {
                                 if ($this->is_ajax === false) {
                                     wp_redirect($this->referrer);
                                     exit;
                                 } else {
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 $this->set_temp_postdata(array('result' => $result, 'data' => stripslashes($_POST['import-data'])));
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg('action', 'import', $this->referrer));
                                     exit;
                                 } else {
                                     echo $this->view('import');
                                 }
                             }
                             break;
                             // Export
                         // Export
                         case 'export':
                             $result = $this->validate_export_data($_POST['export']);
                             if ($result === false) {
                                 if ($this->is_ajax === false) {
                                     wp_redirect($this->referrer);
                                     exit;
                                 } else {
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 $this->set_temp_postdata($result);
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg('action', 'export', $this->referrer));
                                     exit;
                                 } else {
                                     echo $this->view('export');
                                 }
                             }
                             break;
                     }
                 }
                 break;
                 // Import page
             // Import page
             case 'import':
                 $result = $this->validate_import_data($_POST['import-data']);
                 if ($result !== false) {
                     if (!empty($_POST['import'])) {
                         $this->import($_POST['import-data'], isset($_POST['replace']) ? $_POST['replace'] : false, $_POST['import']);
                         if ($this->is_ajax === false) {
                             wp_redirect($this->referrer);
                             exit;
                         } else {
                             echo $this->view();
                             GW_GoPricing_AdminNotices::show();
                         }
                     } else {
                         GW_GoPricing_AdminNotices::add('impex', 'error', __('Please select tables to import!', 'go_pricing_textdomain'));
                         if ($this->is_ajax === false) {
                             $this->set_temp_postdata($_POST['import-data']);
                             wp_redirect(add_query_arg('action', 'import', $this->referrer));
                             exit;
                         } else {
                             GW_GoPricing_AdminNotices::show();
                         }
                     }
                 }
         }
     }
 }
 /**
  * Action
  *
  * @return void
  */
 public function action()
 {
     // Create custom nonce
     $this->create_nonce('impex');
     // Load views if action is empty
     if (empty($this->action)) {
         $action = isset($_GET['action']) ? $_GET['action'] : '';
         switch ($action) {
             case 'import':
                 $tmp_postdata = $this->get_temp_postdata();
                 if (empty($tmp_postdata)) {
                     // Load default view
                     $this->content($this->view());
                 } else {
                     // Load import view
                     $this->content($this->view('import'));
                 }
                 break;
             case 'export':
                 $tmp_postdata = $this->get_temp_postdata();
                 if (empty($tmp_postdata) || !isset($tmp_postdata[0])) {
                     // Load default view
                     $this->content($this->view());
                 } else {
                     // Force download data
                     $this->export($tmp_postdata);
                 }
                 break;
             default:
                 // Load default view
                 $this->content($this->view());
         }
     }
     // Load views if action is not empty (handle postdata)
     if (!empty($this->action) && check_admin_referer($this->nonce, '_nonce')) {
         switch ($this->action) {
             // Default
             case 'impex':
                 if (!empty($this->action_type)) {
                     switch ($this->action_type) {
                         // Import
                         case 'import':
                             add_filter('upload_mimes', array($this, 'restrict_upload_mimes'));
                             add_filter('upload_dir', array($this, 'set_upload_dir'));
                             $result = $this->validate_import_data($_FILES);
                             if ($result === false) {
                                 if ($this->is_ajax === false) {
                                     wp_redirect($this->referrer);
                                     exit;
                                 } else {
                                     echo $this->view();
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 $this->set_temp_postdata($result);
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg('action', 'import', $this->referrer));
                                     exit;
                                 } else {
                                     echo $this->view('import');
                                 }
                             }
                             break;
                             // Export
                         // Export
                         case 'export':
                             $result = $this->validate_export_data($_POST['export']);
                             if ($result === false) {
                                 if ($this->is_ajax === false) {
                                     wp_redirect($this->referrer);
                                     exit;
                                 } else {
                                     GW_GoPricing_AdminNotices::show();
                                 }
                             } else {
                                 $this->set_temp_postdata($_POST['export']);
                                 if ($this->is_ajax === false) {
                                     wp_redirect(add_query_arg('action', 'export', $this->referrer));
                                     exit;
                                 } else {
                                     echo '<div id="download_url">' . add_query_arg(array('action' => 'export'), admin_url('admin.php?page=go-pricing-import-export')) . '</div>';
                                 }
                             }
                             break;
                     }
                 }
                 break;
                 // Import page
             // Import page
             case 'import':
                 if (!empty($_POST['import'])) {
                     $this->import($_POST['import-data'], isset($_POST['replace']) ? $_POST['replace'] : false, $_POST['import']);
                     if ($this->is_ajax === false) {
                         wp_redirect($this->referrer);
                         exit;
                     } else {
                         echo $this->view();
                         GW_GoPricing_AdminNotices::show();
                     }
                 } else {
                     GW_GoPricing_AdminNotices::add('impex', 'error', __('Please select tables to import!', 'go_pricing_textdomain'));
                     if ($this->is_ajax === false) {
                         $this->set_temp_postdata($_POST['import-data']);
                         wp_redirect(add_query_arg('action', 'import', $this->referrer));
                         exit;
                     } else {
                         GW_GoPricing_AdminNotices::show();
                     }
                 }
         }
     }
 }