function _verifyDB() { $state = $this->_getState(); // Uploads the file Citruscart::load('CitruscartFile', 'library.file'); $upload = new CitruscartFile(); // we have to upload the file if ($state->uploaded_file == '') { // handle upload creates upload object properties $success = $upload->handleUpload('file'); if ($success) { if (strtolower($upload->getExtension()) != 'csv') { $this->setError(JText::_('COM_CITRUSCART_THIS_IS_NOT_A_CSV_FILE')); return false; } // Move the file to let us reuse it $upload->setDirectory(JFactory::getConfig()->get('tmp_path', JPATH_SITE . DS . 'tmp')); $success = $upload->upload(); if (!$success) { $this->setError($upload->getError()); return false; } $upload->file_path = $upload->getFullPath(); } else { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_UPLOAD_CSV_FILE' . $upload->getError())); return false; } } else { $upload->full_path = $upload->file_path = $state->uploaded_file; $upload->proper_name = CitruscartFile::getProperName($state->uploaded_file); $success = true; } if ($success) { // Get the file content $upload->fileToText(); $content = $upload->fileastext; // Set the uploaded file as the file to use during the real import $this->_uploaded_file = $upload->getFullPath(); $rows = explode("\n", $content); if (!count($rows)) { $this->setError('No Rows in this file'); return false; } $records = array(); if ($state->skip_first) { $header = array_shift($rows); $header = explode($state->field_separator, $header); } else { $header = $this->_keys; } $records[] = $header; // Get the records foreach ($rows as $row) { // Get the columns $fields = explode($state->field_separator, $row); if ($fields) { // Map them using an associative array $fields = $this->_mapFields($fields); // explore possible multiple subfields // Categories $fields['product_categories'] = explode($state->subfield_separator, $fields['product_categories']); // Images $fields['product_images'] = explode($state->subfield_separator, $fields['product_images']); // Attributes $attributes = explode($state->subfield_separator, $fields['product_attributes']); // Explode the Attribute options! $real_attributes = array(); foreach ($attributes as $attribute) { // size:s|m|l|sx $att = explode(":", $attribute); $att_name = $att[0]; $att_options = array(); if (!empty($att[1])) { $att_options = explode("|", $att[1]); } $real_attributes[$att_name] = $att_options; } // Assign the parsed version! $fields['product_attributes'] = $real_attributes; $records[] = $fields; } } return $records; } else { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_UPLOAD_CSV_FILE' . $upload->getError())); return false; } return false; }
function _verifyDB() { $state = $this->_getState(); // Uploads the file Citruscart::load('CitruscartFile', 'library.file'); $upload = new CitruscartFile(); $zip_images_upload = new CitruscartFile(); $zip_files_upload = new CitruscartFile(); // we have to upload the file if ($state->uploaded_file == '') { // handle upload creates upload object properties $success = $upload->handleUpload('file'); $zip_images_success = $zip_images_upload->handleUpload('images_zip_file'); $zip_files_success = $zip_files_upload->handleUpload('files_zip_file'); if ($success) { if (strtolower($upload->getExtension()) != 'xml') { $this->setError(JText::_('COM_CITRUSCART_THIS_IS_NOT_AN_XML_FILE')); return false; } // Move the file to let us reuse it $upload->setDirectory($this->_temp_dir); $success = $upload->upload(); if (!$success) { $this->setError($upload->getError()); return false; } $upload->file_path = $upload->getFullPath(); // Now for the zips // Check if it's a supported archive if ($zip_images_success) { $allowed_archives = array('zip', 'tar', 'tgz', 'gz', 'gzip', 'tbz2', 'bz2', 'bzip2'); if (!in_array(strtolower($zip_images_upload->getExtension()), $allowed_archives)) { $this->setError(JText::_('COM_CITRUSCART_THIS_IS_NOT_A_SUPPORTED_ARCHIVE_FILE')); return false; } // Move the file to let us reuse it $zip_images_upload->setDirectory($this->_temp_dir); $success = $zip_images_upload->upload(); if (!$success) { $this->setError($zip_images_upload->getError()); return false; } $zip_images_upload->file_path = $zip_images_upload->getFullPath(); } if ($zip_files_success) { $allowed_archives = array('zip', 'tar', 'tgz', 'gz', 'gzip', 'tbz2', 'bz2', 'bzip2'); if (!in_array(strtolower($zip_files_upload->getExtension()), $allowed_archives)) { $this->setError(JText::_('COM_CITRUSCART_THIS_IS_NOT_A_SUPPORTED_ARCHIVE_FILE')); return false; } // Move the file to let us reuse it $zip_files_upload->setDirectory($this->_temp_dir); $success = $zip_files_upload->upload(); if (!$success) { $this->setError($zip_files_upload->getError()); return false; } $zip_files_upload->file_path = $zip_files_upload->getFullPath(); } } else { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_UPLOAD_XML_FILE' . $upload->getError())); return false; } } else { $upload->full_path = $upload->file_path = $state->uploaded_file; $upload->proper_name = CitruscartFile::getProperName($state->uploaded_file); if ($state->uploaded_images_zip_file) { $zip_images_upload->full_path = $zip_images_upload->file_path = $state->uploaded_images_zip_file; $zip_images_upload->proper_name = CitruscartFile::getProperName($state->uploaded_images_zip_file); } if ($state->uploaded_files_zip_file) { $zip_files_upload->full_path = $zip_files_upload->file_path = $state->uploaded_files_zip_file; $zip_files_upload->proper_name = CitruscartFile::getProperName($state->uploaded_files_zip_file); } $success = true; } if ($success) { // Get the file content $upload->fileToText(); $content = $upload->fileastext; // Set the uploaded file as the file to use during the real import $this->_uploaded_file = $upload->getFullPath(); $this->_uploaded_images_zip_file = $zip_images_upload->getFullPath(); $this->_uploaded_files_zip_file = $zip_files_upload->getFullPath(); $xml = simplexml_load_string($content); $products = $xml->children(); if (!count($products)) { $this->setError('No Products in this file'); return false; } return $products; } else { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_UPLOAD_CSV_FILE' . $upload->getError())); return false; } return false; }
/** * * Method to upload and verify file if uploaded * @return boolean */ function _verifyFile() { $state = $this->_getState(); $success = false; // Uploads the file Citruscart::load('CitruscartFile', 'library.file'); $upload = new CitruscartFile(); // we have to upload the file if ($state->uploaded_file == '') { // handle upload creates upload object properties $success = $upload->handleUpload('file'); if ($success) { if (strtolower($upload->getExtension()) != 'sql') { $this->setError(JText::_('COM_CITRUSCART_THIS_IS_NOT_AN_SQL_FILE')); return false; } // Move the file to let us reuse it $upload->setDirectory(JFactory::getConfig()->get('tmp_path', JPATH_SITE . '/tmp')); $success = $upload->upload(); if (!$success) { $this->setError($upload->getError()); return false; } $upload->file_path = $upload->getFullPath(); } else { $this->setError(JText::_('COM_CITRUSCART_COULD_NOT_UPLOAD_SQL_FILE' . $upload->getError())); $success = false; } } else { $upload->full_path = $upload->file_path = $state->uploaded_file; $upload->proper_name = CitruscartFile::getProperName($state->uploaded_file); $success = true; } if ($success) { // Set the uploaded file as the file to use during the real import $this->_uploaded_file = $upload->getFullPath(); $this->_uploaded_filename = str_replace(".sql", "", $upload->physicalname); } return $success; }