/** * private constructor to prevent direct creation * * @Constructor * @access private * @param array $request_data */ private function __construct($request_data = array()) { $this->_req_data = $request_data; $this->today = date("Y-m-d", time()); require_once EE_CLASSES . 'EE_CSV.class.php'; $this->EE_CSV = EE_CSV::instance(); }
/** * Shortcut for preparing a database result for display * @param EEM_Base $model * @param string $field_name * @param string $raw_db_value * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to NOT display pretty * @return string */ protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) { $field_obj = $model->field_settings_for($field_name); $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); if ($field_obj instanceof EE_Datetime_Field) { $field_obj->set_date_format(EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), $pretty_schema); $field_obj->set_time_format(EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), $pretty_schema); } if ($pretty_schema === true) { return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); } elseif (is_string($pretty_schema)) { return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); } else { return $field_obj->prepare_for_get($value_on_model_obj); } }
/** * @Import Event Espresso data - some code "borrowed" from event espresso csv_import.php * @access public * @return boolean success */ public function import() { require_once EE_CLASSES . 'EE_CSV.class.php'; $this->EE_CSV = EE_CSV::instance(); if (isset($_REQUEST['import'])) { if (isset($_POST['csv_submitted'])) { switch ($_FILES['file']['error'][0]) { case UPLOAD_ERR_OK: $error_msg = FALSE; break; case UPLOAD_ERR_INI_SIZE: $error_msg = __("'The uploaded file exceeds the upload_max_filesize directive in php.ini.'", "event_espresso"); break; case UPLOAD_ERR_FORM_SIZE: $error_msg = __('The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.', "event_espresso"); break; case UPLOAD_ERR_PARTIAL: $error_msg = __('The uploaded file was only partially uploaded.', "event_espresso"); break; case UPLOAD_ERR_NO_FILE: $error_msg = __('No file was uploaded.', "event_espresso"); break; case UPLOAD_ERR_NO_TMP_DIR: $error_msg = __('Missing a temporary folder.', "event_espresso"); break; case UPLOAD_ERR_CANT_WRITE: $error_msg = __('Failed to write file to disk.', "event_espresso"); break; case UPLOAD_ERR_EXTENSION: $error_msg = __('File upload stopped by extension.', "event_espresso"); break; default: $error_msg = __('An unknown error occurred and the file could not be uploaded', "event_espresso"); break; } if (!$error_msg) { $filename = $_FILES['file']['name'][0]; $file_ext = substr(strrchr($filename, '.'), 1); $file_type = $_FILES['file']['type'][0]; $temp_file = $_FILES['file']['tmp_name'][0]; $filesize = $_FILES['file']['size'][0] / 1024; //convert from bytes to KB if ($file_ext == 'csv') { $max_upload = $this->EE_CSV->get_max_upload_size(); //max upload size in KB if ($filesize < $max_upload || true) { $wp_upload_dir = str_replace(array('\\', '/'), DS, wp_upload_dir()); $path_to_file = $wp_upload_dir['basedir'] . DS . 'espresso' . DS . $filename; if (move_uploaded_file($temp_file, $path_to_file)) { // convert csv to array $this->csv_array = $this->EE_CSV->import_csv_to_model_data_array($path_to_file); // was data successfully stored in an array? if (is_array($this->csv_array)) { $import_what = str_replace('csv_import_', '', $_REQUEST['action']); $import_what = str_replace('_', ' ', ucwords($import_what)); $processed_data = $this->csv_array; $this->columns_to_save = FALSE; // if any imports require funcky processing, we'll catch them in the switch switch ($_REQUEST['action']) { case "import_events": case "event_list": $import_what = 'Event Details'; break; case 'groupon_import_csv': $import_what = 'Groupon Codes'; $processed_data = $this->process_groupon_codes(); break; } // save processed codes to db if ($this->EE_CSV->save_csv_to_db($processed_data, $this->columns_to_save)) { return TRUE; } } else { // no array? must be an error EE_Error::add_error(sprintf(__("No file seems to have been uploaded", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); return FALSE; } } else { EE_Error::add_error(sprintf(__("%s was not successfully uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); return FALSE; } } else { EE_Error::add_error(sprintf(__("%s was too large of a file and could not be uploaded. The max filesize is %s' KB.", "event_espresso"), $filename, $max_upload), __FILE__, __FUNCTION__, __LINE__); return FALSE; } } else { EE_Error::add_error(sprintf(__("%s had an invalid file extension, not uploaded", "event_espresso"), $filename), __FILE__, __FUNCTION__, __LINE__); return FALSE; } } else { EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); return FALSE; } } } return; }