public function subir() { self::ajaxCheck(); $jinput = JFactory::getApplication()->input; /** * Esta tarea debe accionarse sólamente cuándo el artículo ha sido previamente guardado, * con el fin de evitar subir archivos huerfanos */ $id = $jinput->get('id', null, null); if ($id == 0) { $data = array(); $data['msg'] = JText::_("COM_CONTENT_ADJUNTOS_MSG_GUARDAR_ARTICULO_PRIMERO"); $data['tipo'] = "warn"; print_r(json_encode($data)); return; } // Obtiene la variable @campo enviada en el request $campo = $jinput->get->get('campo', null, null); // Obtiene la variable @exts (extensiones) enviada en el request $exts = explode(',', $jinput->get->get('exts', null, null)); // Obtiene datos del servidor $maxFileSize = ini_get("upload_max_filesize"); $serverContent = $_SERVER['CONTENT_LENGTH']; // Obtiene los datos del archivo $archivo = $jinput->files->get($campo); // Verifica que el tamaño del request no supere el definido en la configuración PHP if ($maxFileSize > $serverContent && is_null($archivo['size'])) { $data = array(); $data['msg'] = JText::_("COM_CONTENT_ADJUNTOS_MSG_ARCHIVO_SUPERA_TAMANO_PERMITIDO_SERVIDOR"); $data['tipo'] = "error"; print_r(json_encode($data)); return; } if (isset($archivo)) { $mimeArchivo = $archivo['type']; // Valida el tip)o mime del archivo, si no es valido retorna mensaje de error // y detiene la ejecución if (!is_null($mimeArchivo)) { $esValido = self::validarTipoMime($exts, $mimeArchivo); if ($esValido['estado'] === false) { $data = array('msg' => $esValido['msg'], 'tipo' => $esValido['tipo']); print_r(json_encode($data)); return; } } // Sanea el nombre de archivo evitando caracteres no deseados $nombreArchivo = strtolower(JFile::makeSafe($archivo['name'])); // Define el origen y destino del archivo // TODO: Crear directorio propio para los adjuntos del artículo // y usarlo como path destino. $src = $archivo['tmp_name']; $dest = JPATH_ROOT . DS . 'uploads' . DS . sha1(time()) . '-' . $nombreArchivo; if (JFile::upload($src, $dest)) { $archivo = array_merge(self::reformarArchivo($id, $dest), array('mimeType' => $mimeArchivo)); $data = array_merge($archivo, self::guardar($archivo), $esValido); // TODO: es posible registrar logs en la gestión de adjuntos print_r(json_encode($data)); } else { // Muestra el mensaje a partir del código de error generado durante la // subida del archivo $err = $archivo['error']; $data = array(); switch ($err) { case 1: $data["msg"] = "#" . $err . ": " . JText::_('COM_CONTENT_ADJUNTOS_MSG_ARCHIVO_SUPERA_TAMANO_PERMITIDO_CONFIG'); break; case 2: $data["msg"] = "#" . $err . ": " . JTex::_('COM_CONTENT_ADJUNTOS_MSG_ARCHIVO_SUPERA_TAMANO_PERMITIDO_FORM'); case 3: $data["msg"] = "#" . $err . ": " . JText::_("COM_CONTENT_ADJUNTOS_MSG_ARCHIVO_PARCIALMENTE_SUBIDO"); break; case 4: $data["msg"] = "#" . $err . ": " . JText::_("COM_CONTENT_ADJUNTOS_MSG_ARCHIVO_NO_SUBIDO"); break; case 6: $data["msg"] = "#" . $err . ": " . JText::_("COM_CONTENT_ADJUNTOS_MSG_NO_TEMPORAL_DIR"); break; case 7: $data["msg"] = "#" . $err . ": " . JText::_('COM_CONTENT_ADJUNTOS_MSG_FALLO_ESCRIBIR_EN_DISCO'); break; case 8: $data["msg"] = "#" . $err . ": " . JText::_('COM_CONTENT_ADJUNTOS_MSG_NO_EXTENSION_PHP'); break; } $data["tipo"] = "error"; // Retorna un objeto JSON que puede ser utilizado en el cliente print_r(json_encode($data)); } } }
function isValid(&$vat) { $class = hikashop_get('class.zone'); $zone = $class->get(@$vat->address_country); if (empty($zone->zone_code_2) || !in_array($zone->zone_code_2, array('AT', 'BE', 'BG', 'CY', 'CZ', 'DK', 'EE', 'EL', 'DE', 'PT', 'GR', 'ES', 'FI', 'HR', 'HU', 'LU', 'MT', 'SI', 'FR', 'GB', 'IE', 'IT', 'LV', 'LT', 'NL', 'PL', 'SK', 'RO', 'SE'))) { return true; } if ($zone->zone_code_2 == 'ES' && !empty($vat->address_state)) { $statezone = $class->get(@$vat->address_state); if ($statezone->zone_code_3 == 'GC' || $statezone->zone_code_3 == 'TF') { return true; } } static $vat_check = null; if (!isset($vat_check)) { $config = hikashop_config(); $vat_check = (int) $config->get('vat_check', 2); } if ($zone->zone_code_2 == 'GR') { $zone->zone_code_2 = 'EL'; } switch ($vat_check) { case 1: case 2: if (is_object($vat)) { $vat_number =& $vat->address_vat; } else { $vat_number =& $vat; } $regex = $this->getRegex($vat_number); if ($regex === false) { if (is_object($vat) && !empty($vat->address_country)) { if (!empty($zone->zone_code_2)) { $vat_number = $zone->zone_code_2 . $vat_number; $regex = $this->getRegex($vat_number); } } if ($regex === false) { $app = JFactory::getApplication(); $this->message = JText::_('VAT_NOT_FOR_YOUR_COUNTRY'); if (@$_REQUEST['tmpl'] == 'component') { hikashop_display($this->message, 'error'); } else { $app->enqueueMessage($this->message); } return false; } } if (!$this->regexCheck($vat_number, $regex)) { return false; } $vat_number = strtoupper(str_replace(array(' ', '.', '-'), array('', '', ''), $vat_number)); $code = substr($vat_number, 0, 2); if ($code == 'GR') { $code = 'EL'; $vat_number = $code . substr($vat_number, 2); } if ($zone->zone_code_2 != $code) { $app = JFactory::getApplication(); $this->message = JTex::sprintf('WRONG_VAT_NUMBER_COUNTRY_CODE', $code, $zone->zone_code_2); if (@$_REQUEST['tmpl'] == 'component') { hikashop_display($this->message, 'error'); } else { $app->enqueueMessage($this->message); } return false; } if ($vat_check == 2) { return $this->onlineCheck($vat_number); } case 0: default: } return true; }