/**
  * Process postdata
  *
  * @return void
  */
 public function process_postdata($postdata)
 {
     // Clean postdata
     $postdata = GW_GoPricing_Helper::clean_input($postdata, 'filtered', '', array('thousand-sep'));
     $postdata = GW_GoPricing_Helper::remove_input($postdata, 'action');
     $settings = get_option(self::$plugin_prefix . '_table_settings', $postdata);
     // Veriify and save data
     if (!empty($postdata)) {
         if (empty($settings) || !empty($settings) && $settings != $postdata) {
             $result = update_option(self::$plugin_prefix . '_table_settings', $postdata);
             if ($result === false) {
                 GW_GoPricing_AdminNotices::add('general_settings', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
             } else {
                 GW_GoPricing_AdminNotices::add('general_settings', 'success', __('General Settings has been successfully updated!', 'go_pricing_textdomain'));
             }
         } else {
             GW_GoPricing_AdminNotices::add('general_settings', 'success', __('General Settings has been successfully updated!', 'go_pricing_textdomain'));
         }
     } else {
         GW_GoPricing_AdminNotices::add('general_settings', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
     }
 }
Ejemplo n.º 2
0
 /**
  * Do import
  *
  * @return bool
  */
 public function save_table($data)
 {
     if (empty($data['name'])) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table Name" is empty!', 'go_pricing_textdomain'), false);
     }
     if (empty($data['id'])) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table ID" is empty!', 'go_pricing_textdomain'), false);
     } elseif (strlen($data['id']) >= 1 && preg_match('/([^a-z0-9\\-_])+/', $data['id']) == 1) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table ID" can contain only lowercase letters, numbers, hyphens and underscores!', 'go_pricing_textdomain'), false);
     } else {
         $tables = GW_GoPricing_Data::get_tables();
         foreach ((array) $tables as $table_key => $table) {
             $table_ids[$table_key] = $table['id'];
         }
         if (!empty($data['postid']) && !empty($table_ids[$data['postid']])) {
             unset($table_ids[$data['postid']]);
         }
         if (in_array($data['id'], $table_ids)) {
             GW_GoPricing_AdminNotices::add('main', 'error', sprintf(__('Pricing table with an ID of "%s" already exists! It must be uniqe.', 'go_pricing_textdomain'), $data['id']), false);
         }
     }
     $notices = GW_GoPricing_AdminNotices::get('main', 'error');
     if (isset($data['col-data'])) {
         $col_data = GW_GoPricing_Helper::clean_input($data['col-data'], 'html');
     }
     $data = GW_GoPricing_Helper::clean_input($data);
     if (isset($col_data)) {
         $data['col-data'] = $col_data;
     }
     if (empty($notices)) {
         $data = GW_GoPricing_Helper::remove_input($data, array($_POST['action']));
         $postid = GW_GoPricing_Data::update_table($data);
         if ($postid !== false) {
             // Create table message
             if (empty($data['postid'])) {
                 GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('Pricing table has been successfully created!<br>Shortcode: </strong>[go_pricing id="%s"]<strong>', 'go_pricing_textdomain'), $data['id']));
             } else {
                 GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('Pricing table has been successfully updated!<br>Shortcode: </strong>[go_pricing id="%s"]<strong>', 'go_pricing_textdomain'), $data['id']));
             }
             return $postid;
         } else {
             GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
         }
     } else {
         $this->set_temp_postdata($data);
     }
     return false;
 }
 /**
  * Import
  *
  * @return bool
  */
 public function import($data, $override, $ids)
 {
     if (empty($data)) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Import data is missing!', 'go_pricing_textdomain'));
         return;
     }
     $ids = isset($ids[0]) && $ids[0] == 'all' ? array() : $ids;
     $data = GW_GoPricing_Helper::clean_input($data);
     $result = GW_GoPricing_Data::import($data, (bool) $override, $ids);
     if ($result === false) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
     } else {
         GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('%1$s pricing table(s) has been successfully imported.', 'go_pricing_textdomain'), $result));
     }
 }
 /**
  * Import
  *
  * @return bool
  */
 public function import($file, $override, $ids)
 {
     $file_content = @file_get_contents($file);
     if ($file_content === false) {
         GW_GoPricing_AdminNotices::add('impex', 'error', __('Invalid import data!', 'go_pricing_textdomain'));
         return false;
     }
     $data = @unserialize(base64_decode($file_content));
     if ($data === false) {
         GW_GoPricing_AdminNotices::add('impex', 'error', __('Invalid import data!', 'go_pricing_textdomain'));
         unlink($file['file']);
         return false;
     }
     if (empty($data['_info']['db_version']) || version_compare($data['_info']['db_version'], self::$db_version, "<")) {
         GW_GoPricing_AdminNotices::add('impex', 'error', __('Import data is not compatible with the current version!', 'go_pricing_textdomain'));
         unlink($file['file']);
         return false;
     }
     $data = $file_content;
     $ids = isset($ids[0]) && $ids[0] == 'all' ? array() : $ids;
     $data = GW_GoPricing_Helper::clean_input($data);
     $result = GW_GoPricing_Data::import($data, (bool) $override, $ids);
     if ($result === false) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
         unlink($file['file']);
         return false;
     } else {
         GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('%1$s pricing table(s) has been successfully imported.', 'go_pricing_textdomain'), $result));
     }
     delete_transient(self::$plugin_prefix . '_uploads');
     return true;
 }