function asignar_cotizacion($id_equipo, $placa_inventario) { App::import('Vendor', 'upload', array('file' => 'class.upload.php')); $this->autoLayout = false; $this->autoRender = false; $datos_json = array('resultado' => false, 'id' => '', 'nombre_archivo' => ''); if (!empty($_FILES) && !empty($id_equipo) && !empty($placa_inventario)) { if (!empty($_FILES['cotizacion']['name'])) { $handle = new Upload($_FILES['cotizacion']); if ($handle->uploaded) { $handle->file_overwrite = true; $handle->file_safe_name = false; $handle->file_auto_rename = false; $handle->file_new_name_body = 'cotizacion(' . $this->Cotizacion->getNextAutoIncrement() . ')_' . $placa_inventario; $handle->Process('equipos/cotizaciones'); if ($handle->processed) { $this->data['Cotizacion']['nombre_archivo'] = $handle->file_dst_name; $this->data['Cotizacion']['id_equipo'] = $id_equipo; $this->data['Cotizacion']['placa_inventario'] = $placa_inventario; if ($this->Cotizacion->save($this->data)) { $datos_json['resultado'] = true; $datos_json['id'] = $this->Cotizacion->id; $datos_json['nombre_archivo'] = $this->data['Cotizacion']['nombre_archivo']; } } $handle->Clean(); } } } return json_encode($datos_json); }
/** * @desc sube una imagen jpg al servidor * @param void * @return void */ private function imgUpload() { $msg = ""; $dir = IMG_LOCAL_PATH . "eventos/" . $this->_event_id; $dirweb = IMG_WEB_PATH . "eventos/" . $this->_event_id; $handle = new Upload($_FILES['urlfoto']); if ($handle->uploaded) { // movemos de temp a dir final $handle->Process($dir); // we check if everything went OK if ($handle->processed) { // everything was fine ! $msg .= '!Carga exitosa!: <a href="' . $dirweb . '/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; } else { // one error occured $msg .= '<fieldset>'; $msg .= ' <legend>No es posible mover la imagen en la ruta indicada</legend>'; $msg .= ' Error: ' . $handle->error . ''; $msg .= '</fieldset>'; } // we delete the temporary files $handle->Clean(); } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file $msg .= '<fieldset>'; $msg .= ' <legend>No es pposible cargar la imagen al servidor.</legend>'; $msg .= ' Error: ' . $handle->error . ''; $msg .= '</fieldset>'; } return $msg; }
public function __construct($feed, $type) { $this->feedArray = $feed; $this->feedType = $type; $this->size = '1000000'; $maxSize = $this->size / 1000000; if ($this->feedType == 'text') { $this->feedText = $feed; } else { if ($this->feedType == 'img') { $this->feedImg = $feed['image']; $this->feedText = $feed['text']; $this->newName = $_SESSION['isv_user_id'] . str_replace(' ', '', microtime()); $this->newName = str_replace('.', '', $this->newName); $path = ISVIPI_UPLOADS_BASE . 'feeds/'; //check file size if ($this->feedImg["size"] > $this->size) { $array['err'] = true; $array['message'] = 'The file is too large. Maximum file size is ' . $maxSize . ' MB.'; echo json_encode($array); exit; } //check file type if ($this->feedImg["type"] != "image/jpg" && $this->feedImg["type"] != "image/png" && $this->feedImg["type"] != "image/jpeg" && $this->feedImg["type"] != "image/gif") { $array['err'] = true; $array['message'] = 'Allowed file types are .jpg .jpeg .png .gif'; echo json_encode($array); exit; } //require file upload class require_once ISVIPI_CLASSES_BASE . 'utilities/class.upload.php'; $newUpload = new Upload($this->feedImg); $newUpload->file_new_name_body = ISVIPI_600 . $this->newName; $newUpload->image_resize = true; $newUpload->image_convert = 'jpg'; $newUpload->image_x = 600; $newUpload->image_ratio_y = true; $newUpload->Process($path); if (!$newUpload->processed) { $array['err'] = true; $array['message'] = 'An error occurred: ' . $newUpload->error . ''; echo json_encode($array); exit; } $newUpload->Clean(); } } /** add our feed to the database **/ $this->addFeed(); /** return success **/ $array['err'] = false; echo json_encode($array); exit; }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $model = $this->getModel('admanager'); $data = $model->getFile($post['id']); if (isset($_FILES['file_upload'])) { $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { $dir = HOTELGUIDE_IMAGES_BANNER . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename'] = $handle->file_dst_name; $post['imagewidth'] = $width; $post['imageheight'] = $height; $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=admanager&cid[]=' . (int) $model->get('id'); break; default: $link = 'index.php?option=com_hotelguide&view=admanagers'; break; } $msg = JText::_('HG_AD_ITEM_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); JError::raiseError(500, $model->getError()); $link = 'index.php?option=com_hotelguide&view=admanager'; } $model->checkin(); $this->setRedirect($link, $msg); }
/** * save a record (and redirect to main page) * @return void */ function save() { JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $post = JRequest::get('post'); $file = JRequest::getVar('file_upload', '', 'files', 'array'); $task = JRequest::getVar('task'); $model =& $this->getModel('facility'); $filename = ''; if (isset($_FILES['file_upload'])) { $filename = $_FILES['file_upload']['name']; $post['pictogram'] = $filename; $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { $dir = HOTELGUIDE_IMAGES_PICTOGRAM . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=facility&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=facility'; break; default: $link = 'index.php?option=com_hotelguide&view=facilities'; break; } $msg = JText::_('HG_FACILITY_SAVED'); } else { $link = 'index.php?option=com_hotelguide&view=facilities'; $msg = JText::_('HG_ERROR_SAVING_FACILITY'); } $this->setRedirect($link, $msg); }
public function upload($curso_id) { $msg = false; $handle = new Upload($_FILES['agenda']); if ($handle->uploaded) { $handle->Process('files'); if ($handle->processed) { rename(FILES_PATH . $handle->file_dst_name, FILES_PATH . $curso_id . ".pdf"); return 1; } else { $msg = $handle->error; } $handle->Clean(); } else { $msg = $handle->error; } return $msg; }
private function img_upload($clinic_id) { if (Login::get_instance()->check_login() == 'valid') { $user_data = Register::get_instance()->get_current_user(); if ($user_data['status'] != 10) { exit; } $foo = new Upload($_FILES['clinic_img']); if ($foo->uploaded) { $this->del($clinic_id); $ds = DIRECTORY_SEPARATOR; $storeFolder = '..' . $ds . 'views' . $ds . 'clinics_img'; $targetPath = dirname(__FILE__) . $ds . $storeFolder . $ds; $targetName = $clinic_id . '_' . md5(rand(1, 5000000000)); while (file_exists($targetName)) { $targetName = $clinic_id . '_' . md5(rand(1, 5000000000)); } $targetFile = $targetPath . $targetName . '.jpeg'; $foo->file_new_name_body = $targetName; $foo->image_resize = true; $foo->image_convert = 'jpeg'; $foo->image_x = 1024; $foo->image_y = 768; $foo->image_ratio_crop = false; //$foo->image_ratio_y = true; $foo->Process($targetPath); if ($foo->processed) { $foo->Clean(); Operations::get_instance()->init(array('img_name' => $targetName . '.jpeg', 'clinic_id' => $clinic_id, 'time_added' => time(), 'date_added' => TimeTools::get_time_id(date('Y-m-d'))), 'clinics_img', 'update'); } } } }
/** * Save an item after it has been translated * This will be called by Josetta when a user clicks * the Save button. The context is passed so * that each plugin knows if it must process the data or not * * if $item->reference_id is empty, this is * a new item, otherwise we are updating the item * * $item->data contains the fields entered by the user * that needs to be saved * *@param context type *@param data in form of array * *return table id if data is inserted * *return false if error occurs * */ public function onJosettaSaveItem($context, $item, &$errors) { if ($context != $this->_context) { return; } // load languages for form and error messages $this->loadLanguages(); // Save jimport('joomla.filesystem.file'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables'); require_once JPATH_ADMINISTRATOR . '/components/com_k2/lib/class.upload.php'; $row = JTable::getInstance('K2Category', 'Table'); $params = JComponentHelper::getParams('com_k2'); if (!$row->bind($item)) { JosettaHelper::enqueueMessages($row->getError()); return false; } $row->parent = (int) $row->parent; //$input = JRequest::get('post'); $filter = JFilterInput::getInstance(); $categoryParams = new JRegistry($row->params); $categoryParams->set('catMetaDesc', $filter->clean($item['metadesc'])); $categoryParams->set('catMetaKey', $filter->clean($item['metakey'])); $row->params = $categoryParams->toString(); $isNew = $row->id ? false : true; //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.category', $row, $isNew)); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } if (!$row->id) { $row->ordering = $row->getNextOrder('parent = ' . $row->parent . ' AND trash=0'); } $savepath = JPATH_ROOT . '/media/k2/categories/'; if ($row->image && JFile::exists($savepath . $image)) { $uniqueName = uniqid() . '.jpg'; JFile::copy($savepath . $row->image, $savepath . $uniqueName); $row->image = $uniqueName; } if (!$row->check()) { JosettaHelper::enqueueMessages($row->getError()); return false; } if (!$row->store()) { JosettaHelper::enqueueMessages($row->getError()); return false; } if (!$params->get('disableCompactOrdering')) { $row->reorder('parent = ' . $row->parent . ' AND trash=0'); } if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } //$files = JRequest::get('files'); $savepath = JPATH_ROOT . '/media/k2/categories/'; // TODO: this will be renamed when used through Josetta //$existingImage = JRequest::getVar('existingImage'); if (!empty($item['files']) && !empty($item['files']['image'])) { if (($item['files']['image']['error'] === 0 || !empty($item['existingImage'])) && empty($item['del_image'])) { if ($item['files']['image']['error'] === 0) { $image = $item['files']['image']; } else { $image = JPATH_SITE . '/' . JPath::clean($item['existingImage']); } $handle = new Upload($image); if ($handle->uploaded) { $handle->file_auto_rename = false; $handle->jpeg_quality = $params->get('imagesQuality', '85'); $handle->file_overwrite = true; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('catImageWidth', '100'); $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { JosettaHelper::enqueueMessages($handle->error); return false; } $row->image = $handle->file_dst_name; } } // TODO: this will be renamed when used through Josetta if (!empty($item['del_image'])) { $currentRow = JTable::getInstance('K2Category', 'Table'); $currentRow->load($row->id); if (JFile::exists(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image)) { JFile::delete(JPATH_ROOT . '/media/k2/categories/' . $currentRow->image); } $row->image = ''; } if (!$row->store()) { JosettaHelper::enqueueMessages($row->getError()); return false; } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.category', $row, $isNew)); $cache = JFactory::getCache('com_k2'); $cache->clean(); return $row->id; }
function processLogo() { if ( !isset($_FILES['original_logo']) ) return FALSE; global $connections; // Uses the upload.class.php to handle file uploading and image manipulation. // GPL PHP upload class from http://www.verot.net/php_class_upload.htm require_once(WP_PLUGIN_DIR . '/connections/includes/php_class_upload/class.upload.php'); $process_logo = new Upload($_FILES['original_logo']); if ($process_logo->uploaded) { $connections->setSuccessMessage('image_uploaded'); // Creates the logo image and saves it to the wp_content/connection_images/ dir. // If needed this will create the upload dir and chmod it. $process_logo->allowed = array('image/jpeg','image/gif','image/png'); $process_logo->auto_create_dir = TRUE; $process_logo->auto_chmod_dir = TRUE; $process_logo->file_safe_name = TRUE; $process_logo->file_auto_rename = TRUE; $process_logo->file_name_body_add= '_logo'; $process_logo->image_convert = 'jpg'; $process_logo->jpeg_quality = $connections->options->getImgLogoQuality(); $process_logo->image_resize = TRUE; $process_logo->image_ratio_crop = (bool) $connections->options->getImgLogoRatioCrop(); $process_logo->image_ratio_fill = (bool) $connections->options->getImgLogoRatioFill(); $process_logo->image_y = $connections->options->getImgLogoY(); $process_logo->image_x = $connections->options->getImgLogoX(); $process_logo->Process(CN_IMAGE_PATH); if ($process_logo->processed) { $connections->setSuccessMessage('image_thumbnail'); $logo['name'] = $process_logo->file_dst_name; } else { $connections->setErrorMessage('image_thumbnail_failed'); return FALSE; } $process_logo->Clean(); } else { $connections->setErrorMessage('image_upload_failed'); return FALSE; } return $logo; }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['rate_details'] = JRequest::getVar('rate_details', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['description'] = JRequest::getVar('description', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['amenities'] = JRequest::getVar('amenities', '', 'POST', 'string', JREQUEST_ALLOWRAW); $model = $this->getModel('roomitem'); $data = $model->getFile($post['id']); $directory = 'hotel_' . $post['hotel']; for ($i = 1; $i <= 6; $i++) { if ($i == 1) { $seq = ""; } else { $seq = $i; } eval("\$filename=\$data->filename" . $seq . ";"); $delete_image = JRequest::getCmd('delete_image' . $seq, false, 'post'); if ($delete_image) { $post['filename' . $seq] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; //Elimina la foto de la carpeta album del hotel if (JFile::exists($dir . $filename)) { JFile::delete($dir . $filename); } //Elimina la foto de la carpeta resize del hotel if (JFile::exists($resize_dir . $filename)) { JFile::delete($resize_dir . $filename); } //Elimina la foto de la carpeta thumb del hotel if (JFile::exists($thumb_dir . $filename)) { JFile::delete($thumb_dir . $filename); } } else { $post['filename' . $seq] = $filename; } if (isset($_FILES['file_upload' . $seq])) { $handle = new Upload($_FILES['file_upload' . $seq]); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } if (JFile::exists($dir . $filename)) { JFile::delete($dir . $filename); } if (JFile::exists($resize_dir . $filename)) { JFile::delete($resize_dir . $filename); } if (JFile::exists($thumb_dir . $filename)) { JFile::delete($thumb_dir . $filename); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename' . $seq] = $handle->file_dst_name; // resized image $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 240; //$imageWidth; } else { $handle->image_ratio_x = true; $handle->image_y = 240; //$imageHeight; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 64; //$imageWidth; } else { $handle->image_ratio_x = true; $handle->image_y = 64; //$imageHeight; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=roomitem&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=roomitem'; break; default: $link = 'index.php?option=com_hotelguide&view=roomitems'; break; } $msg = JText::_('HG_ROOM_ITEM_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); $link = 'index.php?option=com_hotelguide&view=roomitem'; } $model->checkin(); $this->setRedirect($link, $msg); }
$document->image_resize = true; $document->image_ratio_pixels = 200000; $document->image_overlay_color = '#505050'; $document->image_overlay_opacity = 75; $document->image_text = $text; $document->image_text_color = '#ffffff'; $document->image_text_opacity = 100; $document->image_text_background_opacity = 50; $document->image_text_font = 5; $document->image_text_padding = 20; $document->file_new_name_body = 'image'; $document->Process('../img/'); if ($document->processed) { //si edition faite... détection de la date, du path du fichier $date = date("Y-m-d H:i:s"); $name = $document->file_dst_name; //enregistrement dans la base de donnee des infos $req2 = $req->prepare('INSERT INTO images(name, date, ip) VALUES(:name, :date, :ip)'); $req2->execute(array('name' => $name, 'date' => $date, 'ip' => $ip)); $document->Clean(); $alert = '<section id="alert"><p>Mauvais type de fichier, ca fichier... :/</p></section>'; header('Location: ../index.php'); exit; } else { $alert = 'error : ' . $document->error; } } } else { $alert = 'Mauvais type de fichier, ca fichier... :/ '; } }
function imageFrame($filename = false, $framefile = false) { global $IMAGE, $CONFIG; if (array_key_exists('mobile', $CONFIG)) { include APP . LIBS . 'class_image_upload/class.upload.php'; } else { include LIBS . 'class_image_upload/class.upload.php'; } deleteFile($filename, 'imageFramed'); // pr($IMAGE[0]['pathfile'].$filename); $handle = new Upload($IMAGE[0]['pathfile'] . $filename); // pr($handle); if ($handle->uploaded) { $handle->image_resize = true; $handle->image_x = 180; $handle->image_y = 181; $handle->image_ratio_crop = false; $handle->jpeg_quality = 100; $handle->image_watermark = $IMAGE[0]['pathframe'] . $framefile; $handle->Process($IMAGE[0]['imageframed']); if ($handle->processed) { $filename = $handle->file_dst_name; } else { echo 'Error: ' . $handle->error . ''; } $handle->Clean(); return true; } else { echo 'Error: ' . $handle->error . ''; } return false; }
if ($foo->uploaded) { // save uploaded image with no changes // save uploaded image with a new name $foo->file_new_name_body = 'foo'; $foo->Process($_SERVER['DOCUMENT_ROOT'] . '/inventory2/logo/'); if ($foo->processed) { } else { //echo 'error : ' . $foo->error; } $foo->file_new_name_body = $s_id; $foo->image_resize = true; $foo->image_convert = 'jpg'; $foo->image_x = 100; $foo->image_ratio_y = true; $foo->Process($_SERVER['DOCUMENT_ROOT'] . '/inventory2/logo/'); if ($foo->processed) { $foo->Clean(); } else { //echo 'error : ' . $foo->error; } } $file = $_SERVER['DOCUMENT_ROOT'] . '/inventory2/logo/' . $s_id . '.jpg'; //echo $file; if (is_file($file)) { } else { $file = $_SERVER['DOCUMENT_ROOT'] . '/inventory2/logo/' . $s_id . '.png'; if (is_file($file)) { } } header("Location: ?folder=store&file=view"); }
public function uploadFile($idR, $campoFile = "file_", $campoEtichetta = "et_file_", $campoCanc = "canc_") { $nFile = $this->get_nfile(); if ($nFile > 0) { //recupero i file già inseriti $query = sprintf("select * from file where fk_tabella = %d and fk_record = %d order by sorting", $this->idTabella, $idR); $this->conn->query($query); $arrayFile = array(); while ($rowFile = $this->conn->fetch()) { $arrayFile[] = array("idF" => $rowFile["idF"], "file" => $rowFile["file"], "etichetta" => $rowFile["titoloF"]); } $arr_file = array(); $arr_etichette = array(); $dir_dest = "../" . $this->folder_upload . "/" . $this->get_cartella(); for ($i = 1; $i <= $nFile; $i++) { $nomeCampoFile = $this->campo . "_" . $campoFile . $i; $nomeCampoEtichetta = $this->campo . "_" . $campoEtichetta . $i; $nomeCampoCanc = $this->campo . $campoCanc . $i; if (isset($_FILES[$nomeCampoFile]) and $_FILES[$nomeCampoFile]["size"] > 0) { if (!($handle = new Upload($_FILES[$nomeCampoFile]))) { exit('error : ' . $handle->error); } $handle->no_script = false; $handle->file_overwrite = true; $handle->Process($dir_dest); if ($handle->processed) { $destname = $handle->file_dst_name; $filenamemd5 = md5_file($dir_dest . "/" . $destname); //controllo se è una immagine e se devo fare ridimensionamento if ($this->tipo == "img") { if ($handle->file_is_image) { $tipoRid = $this->get_tipo_ridim(); if ($tipoRid == 3) { $handle_img = new Upload($dir_dest . "/" . $destname); $ext = $handle_img->file_src_name_ext; //estensione del file //recupero le dimensioni da fissare $arrayDim = $this->get_dimensioni(); if ($handle_img->image_src_x > $handle_img->image_src_y) { $widthB = $arrayDim[0]; $widthT = $arrayDim[2]; if ($handle_img->image_src_x > $widthB) { $handle_img->image_resize = true; $handle_img->image_ratio_y = true; $handle_img->image_x = $widthB; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); } $handle_img->file_new_name_body = $filenamemd5; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); if ($widthT > 0) { if ($handle_img->image_src_x > $widthT) { $handle_img->image_resize = true; $handle_img->image_ratio_y = true; $handle_img->image_x = $widthT; } $handle_img->file_new_name_body = $filenamemd5 . "_thumb"; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); } } else { $heightB = $arrayDim[1]; $heightT = $arrayDim[3]; if ($handle_img->image_src_y > $heightB) { $handle_img->image_resize = true; $handle_img->image_ratio_x = true; $handle_img->image_y = $heightB; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); } $handle_img->file_new_name_body = $filenamemd5; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); if ($heightT > 0) { if ($handle_img->image_src_y > $heightT) { $handle_img->image_resize = true; $handle_img->image_ratio_x = true; $handle_img->image_y = $heightT; } $handle_img->file_new_name_body = $filenamemd5 . "_thumb"; $handle_img->file_overwrite = true; $handle_img->Process($dir_dest); } } $handle_img->Clean(); } } else { exit("error: il file caricato non è una immagine"); } } else { $ext = $handle->file_src_name_ext; $handle->file_new_name_body = $filenamemd5; $handle->no_script = false; $handle->file_overwrite = true; $handle->Process($dir_dest); } //cancello il file caricato con il nome originale e faccio pulizia @unlink($dir_dest . "/" . $destname); $handle->Clean(); $arr_file[$i] = $_FILES[$nomeCampoFile]["name"] . ":" . $filenamemd5 . "." . $ext; $arr_etichette[$i] = $this->conn->str($_POST[$nomeCampoEtichetta]); //controllo se devo cancellare il file vecchio if (isset($arrayFile[$i - 1]) and $arrayFile[$i - 1]["file"] != "") { $expFile = explode(":", $arrayFile[$i - 1]["file"]); if ($expFile[1] != $filenamemd5 . "." . $ext) { $this->delete_file($expFile[1], $arrayFile[$i - 1]["idF"]); } } /* $etichetta = $_POST[$nomeCampoEtichetta]; $this -> addFile($filenamemd5.".".$ext.":".$_FILES[$nomeCampoFile]["name"], $etichetta, $idR); */ } else { exit('error : ' . $handle->error); } } else { if (isset($_POST[$nomeCampoCanc]) and $_POST[$nomeCampoCanc] == 'si') { if (trim($arrayFile[$i - 1]["file"] != "")) { $expFile = explode(":", $arrayFile[$i - 1]["file"]); $this->delete_file($expFile[1], $arrayFile[$i - 1]["idF"]); } $arr_file[$i] = ""; $arr_etichette[$i] = ""; } else { if (isset($arrayFile[$i - 1])) { $arr_file[$i] = $arrayFile[$i - 1]["file"]; $arr_etichette[$i] = $this->conn->str($_POST[$nomeCampoEtichetta]); } else { $arr_file[$i] = ""; $arr_etichette[$i] = ""; } } } } //inserisco i dati nella tbl file. Prima cancello gli eventuali precedenti $queryDel = sprintf("delete from file where fk_tabella = %d and fk_record = %d", $this->idTabella, $idR); $this->conn->query($queryDel); //var_dump($arr_file); $cont = 1; foreach ($arr_file as $key => $value) { if (trim($value != "")) { //inserisco nel db $queryIns = sprintf("insert into file (file, fk_tabella, fk_record, titoloF, sorting) value('%s', %d, %d, '%s', %d)", $value, $this->idTabella, $idR, $arr_etichette[$key], $cont); $this->conn->query($queryIns); $cont++; } } } }
function save($front = false) { $mainframe =& JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $row =& JTable::getInstance('K2Item', 'Table'); $params =& JComponentHelper::getParams('com_k2'); $nullDate = $db->getNullDate(); if (!$row->bind(JRequest::get('post'))) { $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error'); } if ($front && $row->id == NULL) { if (!$user->authorize('com_k2', 'add', 'category', $row->catid) && !$user->authorize('com_k2', 'add', 'category', 'all')) { $mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component', JText::_('You are not allowed to post to this category. Save failed.'), 'error'); } } $row->id ? $isNew = false : ($isNew = true); if ($params->get('mergeEditors')) { $text = JRequest::getVar('text', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $text = $filter->clean($text); } $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; $tagPos = preg_match($pattern, $text); if ($tagPos == 0) { $row->introtext = $text; $row->fulltext = ''; } else { list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2); } } else { $row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2); $row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->introtext = $filter->clean($row->introtext); $row->fulltext = $filter->clean($row->fulltext); } } if ($row->id) { $datenow =& JFactory::getDate(); $row->modified = $datenow->toMySQL(); $row->modified_by = $user->get('id'); } else { $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0"); if (JRequest::getInt('featured')) { $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering'); } } if ($front) { if (!$row->id) { $row->created_by = $user->get('id'); } } else { $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); } if ($row->created && strlen(trim($row->created)) <= 10) { $row->created .= ' 00:00:00'; } $config =& JFactory::getConfig(); $tzoffset = $config->getValue('config.offset'); $date =& JFactory::getDate($row->created, $tzoffset); $row->created = $date->toMySQL(); if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = $date->toMySQL(); if (trim($row->publish_down) == JText::_('Never') || trim($row->publish_down) == '') { $row->publish_down = $nullDate; } else { if (strlen(trim($row->publish_down)) <= 10) { $row->publish_down .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_down, $tzoffset); $row->publish_down = $date->toMySQL(); } $metadata = JRequest::getVar('meta', null, 'post', 'array'); if (is_array($metadata)) { $txt = array(); foreach ($metadata as $k => $v) { if ($k == 'description') { $row->metadesc = $v; } elseif ($k == 'keywords') { $row->metakey = $v; } else { $txt[] = "{$k}={$v}"; } } $row->metadata = implode("\n", $txt); } $row->featured = JRequest::getInt('featured'); if (!$row->check()) { $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id, $row->getError(), 'error'); } $dispatcher =& JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew)); if (in_array(false, $result, true)) { JError::raiseError(500, $row->getError()); return false; } if (version_compare(phpversion(), '5.0') < 0) { $tmpRow = $row; } else { $tmpRow = clone $row; } if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error'); } $itemID = $row->id; $row = $tmpRow; $row->id = $itemID; if (!$params->get('disableCompactOrdering')) { $row->reorder("catid = {$row->catid} AND trash = 0"); } if (JRequest::getInt('featured') && !$params->get('disableCompactOrdering')) { $row->reorder("featured = 1 AND trash = 0", 'featured_ordering'); } $files = JRequest::get('files'); //Image $existingImage = JRequest::getVar('existingImage'); if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); $handle->allowed = array('image/*'); if ($handle->uploaded) { //Image params $category =& JTable::getInstance('K2Category', 'Table'); $category->load($row->catid); $cparams = new JParameter($category->params); if ($cparams->get('inheritFrom')) { $masterCategoryID = $cparams->get('inheritFrom'); $query = "SELECT * FROM #__k2_categories WHERE id=" . (int) $masterCategoryID; $db->setQuery($query, 0, 1); $masterCategory = $db->loadObject(); $cparams = new JParameter($masterCategory->params); } $params->merge($cparams); //Original image $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src'; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = md5("Image" . $row->id); $handle->Process($savepath); $filename = $handle->file_dst_name_body; $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache'; //XLarge image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XL'; if (JRequest::getInt('itemImageXL')) { $imageWidth = JRequest::getInt('itemImageXL'); } else { $imageWidth = $params->get('itemImageXL', '800'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Large image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_L'; if (JRequest::getInt('itemImageL')) { $imageWidth = JRequest::getInt('itemImageL'); } else { $imageWidth = $params->get('itemImageL', '600'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Medium image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_M'; if (JRequest::getInt('itemImageM')) { $imageWidth = JRequest::getInt('itemImageM'); } else { $imageWidth = $params->get('itemImageM', '400'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Small image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_S'; if (JRequest::getInt('itemImageS')) { $imageWidth = JRequest::getInt('itemImageS'); } else { $imageWidth = $params->get('itemImageS', '200'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //XSmall image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XS'; if (JRequest::getInt('itemImageXS')) { $imageWidth = JRequest::getInt('itemImageXS'); } else { $imageWidth = $params->get('itemImageXS', '100'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Generic image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_Generic'; $imageWidth = $params->get('itemImageGeneric', '300'); $handle->image_x = $imageWidth; $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error'); } } if (JRequest::getBool('del_image')) { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); $filename = md5("Image" . $current->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg'); } $row->image_caption = ''; $row->image_credits = ''; } //Attachments $attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array'); $attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array'); $attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array'); $attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array'); $attachmentFiles = array(); if (count($attachments)) { foreach ($attachments as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $attachmentFiles)) { $attachmentFiles[$i] = array(); } $attachmentFiles[$i][$k] = $v; } } $path = $params->get('attachmentsFolder', NULL); if (is_null($path)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments'; } else { $savepath = $path; } $counter = 0; foreach ($attachmentFiles as $file) { if ($file["tmp_name"]) { $handle = new Upload($file); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->allowed[] = 'application/x-zip'; $handle->Process($savepath); $filename = $handle->file_dst_name; $handle->Clean(); $attachment =& JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $filename; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error'); } } $counter++; } } //Gallery if (isset($files['gallery']) && $files['gallery']['error'] == 0 && !JRequest::getBool('del_gallery')) { $handle = new Upload($files['gallery']); $handle->file_auto_rename = true; $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries'; $handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip"); if ($handle->uploaded) { $handle->Process($savepath); $handle->Clean(); if (JFolder::exists($savepath . DS . $row->id)) { JFolder::delete($savepath . DS . $row->id); } if (!JArchive::extract($savepath . DS . $handle->file_dst_name, $savepath . DS . $row->id)) { $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Gallery upload error: Cannot extract archive!'), 'error'); } else { $row->gallery = '{gallery}' . $row->id . '{/gallery}'; } JFile::delete($savepath . DS . $handle->file_dst_name); $handle->Clean(); } else { $mainframe->redirect('index.php?option=com_k2&view=items', $handle->error, 'error'); } } if (JRequest::getBool('del_gallery')) { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id)) { JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id); } $row->gallery = ''; } //Video if (!JRequest::getBool('del_video')) { if (isset($files['video']) && $files['video']['error'] == 0) { $validExtensions = array('flv', 'swf', 'wmv', 'mov', 'mp4', '3gp', 'avi', 'divx'); $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos'; $filetype = JFile::getExt($files['video']['name']); if (!in_array($filetype, $validExtensions)) { $mainframe->redirect('index.php?option=com_k2&view=items', JText::_('Invalid video file'), 'error'); } $filename = JFile::stripExt($files['video']['name']); JFile::upload($files['video']['tmp_name'], $savepath . DS . $row->id . '.' . $filetype); $filetype = JFile::getExt($files['video']['name']); $row->video = '{' . $filetype . '}' . $row->id . '{/' . $filetype . '}'; } else { if (JRequest::getVar('remoteVideo')) { $fileurl = JRequest::getVar('remoteVideo'); $filetype = JFile::getExt($fileurl); $row->video = '{' . $filetype . 'remote}' . $fileurl . '{/' . $filetype . 'remote}'; } if (JRequest::getVar('videoID')) { $provider = JRequest::getWord('videoProvider'); $videoID = JRequest::getVar('videoID'); $row->video = '{' . $provider . '}' . $videoID . '{/' . $provider . '}'; } if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW)) { $row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW); } } } else { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER); $videotype = $matches[1][0]; $videofile = $matches[2][0]; if ($videotype == 'flv' || $videotype == 'swf' || $videotype == 'wmv' || $videotype == 'mov' || $videotype == 'mp4' || $videotype == '3gp' || $videotype == 'divx') { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype); } } $row->video = ''; $row->video_caption = ''; $row->video_credits = ''; } //Extra fields $objects = array(); $variables = JRequest::get('post', 4); foreach ($variables as $key => $value) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); $object->set('value', $value); unset($object->_errors); $objects[] = $object; } } $csvFiles = JRequest::get('files'); foreach ($csvFiles as $key => $file) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); $csvFile = $file['tmp_name'][0]; if (!empty($csvFile) && JFile::getExt($file['name'][0]) == 'csv') { $handle = @fopen($csvFile, 'r'); $csvData = array(); while (($data = fgetcsv($handle, 1000)) !== FALSE) { $csvData[] = $data; } fclose($handle); $object->set('value', $csvData); } else { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $object->set('value', $json->decode(JRequest::getVar('K2CSV_' . $object->id))); if (JRequest::getBool('K2ResetCSV_' . $object->id)) { $object->set('value', null); } } unset($object->_errors); $objects[] = $object; } } require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $row->extra_fields = $json->encode($objects); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php'; $extraFieldModel = new K2ModelExtraField(); $row->extra_fields_search = ''; foreach ($objects as $object) { $row->extra_fields_search .= $extraFieldModel->getSearchValue($object->id, $object->value); $row->extra_fields_search .= ' '; } //Tags if ($user->gid < 24 && $params->get('lockTags')) { $params->set('taggingSystem', 0); } $db =& JFactory::getDBO(); $query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval({$row->id})}"; $db->setQuery($query); $db->query(); if ($params->get('taggingSystem')) { if ($user->gid < 24 && $params->get('lockTags')) { JError::raiseError(403, JText::_("ALERTNOTAUTH")); } $tags = JRequest::getVar('tags', NULL, 'POST', 'array'); if (count($tags)) { $tags = array_unique($tags); foreach ($tags as $tag) { $tag = str_replace('-', '', $tag); $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($tag); $db->setQuery($query); $tagID = $db->loadResult(); if ($tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } else { $K2Tag =& JTable::getInstance('K2Tag', 'Table'); $K2Tag->name = $tag; $K2Tag->published = 1; $K2Tag->check(); $K2Tag->store(); $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$K2Tag->id})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } } else { $tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array'); if (count($tags)) { foreach ($tags as $tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } if ($front) { if (!K2HelperPermissions::canPublishItem($row->catid) && $row->published == 1) { $row->published = 0; $mainframe->enqueueMessage(JText::_("You don't have the permission to publish items."), 'notice'); } } if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=items', $row->getError(), 'error'); } $row->checkin(); $cache =& JFactory::getCache('com_k2'); $cache->clean(); $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew)); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('Changes to Item saved'); $link = 'index.php?option=com_k2&view=item&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('Item saved'); $link = 'index.php?option=com_k2&view=item'; break; case 'save': default: $msg = JText::_('Item Saved'); if ($front) { $link = 'index.php?option=com_k2&view=item&task=edit&cid=' . $row->id . '&tmpl=component'; } else { $link = 'index.php?option=com_k2&view=items'; } break; } $mainframe->redirect($link, $msg); }
/** * This method is copied from admin/com_k2/models/item.php * Modifications have been made * Changed all $mainframe redirects * Removed the check for extra fields, we don't want to override them */ function save($front = false) { $mainframe =& JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); require_once JPATH_ADMINISTRATOR . '/components/com_k2' . DS . 'lib' . DS . 'class.upload.php'; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $row =& JTable::getInstance('K2Item', 'Table'); $params =& JComponentHelper::getParams('com_k2'); $nullDate = $db->getNullDate(); if (!$row->bind(JRequest::get('post'))) { $this->setError($row->getError()); return false; } if ($front && $row->id == NULL) { JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php'); if (!K2HelperPermissions::canAddItem($row->catid)) { $this->setError(JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED')); return false; } } $row->id ? $isNew = false : ($isNew = true); if ($params->get('mergeEditors')) { $text = JRequest::getVar('text', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $text = $filter->clean($text); } $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; $tagPos = preg_match($pattern, $text); if ($tagPos == 0) { $row->introtext = $text; $row->fulltext = ''; } else { list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2); } } else { $row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2); $row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->introtext = $filter->clean($row->introtext); $row->fulltext = $filter->clean($row->fulltext); } } if ($row->id) { $datenow =& JFactory::getDate(); $row->modified = $datenow->toMySQL(); $row->modified_by = $user->get('id'); } else { $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0"); if ($row->featured) { $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering'); } } $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); if ($front) { $K2Permissions =& K2Permissions::getInstance(); if (!$K2Permissions->permissions->get('editAll')) { $row->created_by = $user->get('id'); } } if ($row->created && strlen(trim($row->created)) <= 10) { $row->created .= ' 00:00:00'; } $config =& JFactory::getConfig(); $tzoffset = $config->getValue('config.offset'); $date =& JFactory::getDate($row->created, $tzoffset); $row->created = $date->toMySQL(); if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = $date->toMySQL(); if (trim($row->publish_down) == JText::_('K2_NEVER') || trim($row->publish_down) == '') { $row->publish_down = $nullDate; } else { if (strlen(trim($row->publish_down)) <= 10) { $row->publish_down .= ' 00:00:00'; } $date =& JFactory::getDate($row->publish_down, $tzoffset); $row->publish_down = $date->toMySQL(); } $metadata = JRequest::getVar('meta', null, 'post', 'array'); if (is_array($metadata)) { $txt = array(); foreach ($metadata as $k => $v) { if ($k == 'description') { $row->metadesc = $v; } elseif ($k == 'keywords') { $row->metakey = $v; } else { $txt[] = "{$k}={$v}"; } } $row->metadata = implode("\n", $txt); } if (!$row->check()) { $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id, $row->getError(), 'error'); } $dispatcher =& JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew)); if (in_array(false, $result, true)) { $this->setError($row->getError()); return false; } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFolder::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements')) { if (version_compare(phpversion(), '5.0') < 0) { $tmpRow = $row; } else { $tmpRow = clone $row; } } if (!$row->store()) { $this->setError($row->getError()); return false; } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFolder::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'contentelements')) { $itemID = $row->id; $row = $tmpRow; $row->id = $itemID; } if (!$params->get('disableCompactOrdering')) { $row->reorder("catid = {$row->catid} AND trash = 0"); } if ($row->featured && !$params->get('disableCompactOrdering')) { $row->reorder("featured = 1 AND trash = 0", 'featured_ordering'); } $files = JRequest::get('files'); //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $existingImage = JRequest::getVar('existingImage'); if ((@$files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); $handle->allowed = array('image/*'); if ($handle->uploaded) { //Image params $category =& JTable::getInstance('K2Category', 'Table'); $category->load($row->catid); $cparams = new JParameter($category->params); if ($cparams->get('inheritFrom')) { $masterCategoryID = $cparams->get('inheritFrom'); $query = "SELECT * FROM #__k2_categories WHERE id=" . (int) $masterCategoryID; $db->setQuery($query, 0, 1); $masterCategory = $db->loadObject(); $cparams = new JParameter($masterCategory->params); } $params->merge($cparams); //Original image $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src'; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = md5("Image" . $row->id); $handle->Process($savepath); $filename = $handle->file_dst_name_body; $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache'; //XLarge image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XL'; if (JRequest::getInt('itemImageXL')) { $imageWidth = JRequest::getInt('itemImageXL'); } else { $imageWidth = $params->get('itemImageXL', '800'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Large image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_L'; if (JRequest::getInt('itemImageL')) { $imageWidth = JRequest::getInt('itemImageL'); } else { $imageWidth = $params->get('itemImageL', '600'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Medium image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_M'; if (JRequest::getInt('itemImageM')) { $imageWidth = JRequest::getInt('itemImageM'); } else { $imageWidth = $params->get('itemImageM', '400'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Small image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_S'; if (JRequest::getInt('itemImageS')) { $imageWidth = JRequest::getInt('itemImageS'); } else { $imageWidth = $params->get('itemImageS', '200'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //XSmall image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XS'; if (JRequest::getInt('itemImageXS')) { $imageWidth = JRequest::getInt('itemImageXS'); } else { $imageWidth = $params->get('itemImageXS', '100'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Generic image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_Generic'; $imageWidth = $params->get('itemImageGeneric', '300'); $handle->image_x = $imageWidth; $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $this->setError($handle->error); return false; } } if (JRequest::getBool('del_image')) { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); $filename = md5("Image" . $current->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg'); } $row->image_caption = ''; $row->image_credits = ''; } //Attachments $attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array'); $attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array'); $attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array'); $attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array'); $attachments_existing_files = JRequest::getVar('attachment_existing_file', '', 'POST', 'array'); $attachmentFiles = array(); if (count($attachments)) { foreach ($attachments as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $attachmentFiles)) { $attachmentFiles[$i] = array(); } $attachmentFiles[$i][$k] = $v; } } $path = $params->get('attachmentsFolder', NULL); if (is_null($path)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments'; } else { $savepath = $path; } $counter = 0; foreach ($attachmentFiles as $key => $file) { if ($file["tmp_name"] || $attachments_existing_files[$key]) { if ($attachments_existing_files[$key]) { $file = JPATH_SITE . DS . JPath::clean($attachments_existing_files[$key]); } $handle = new Upload($file); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->allowed[] = 'application/x-zip'; $handle->allowed[] = 'application/download'; $handle->Process($savepath); $filename = $handle->file_dst_name; $handle->Clean(); $attachment =& JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $filename; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $this->setError($handle->error); return false; } } $counter++; } } //Gallery $flickrGallery = JRequest::getVar('flickrGallery'); if ($flickrGallery) { $row->gallery = '{gallery}' . $flickrGallery . '{/gallery}'; } if (isset($files['gallery']) && $files['gallery']['error'] == 0 && !JRequest::getBool('del_gallery')) { $handle = new Upload($files['gallery']); $handle->file_auto_rename = true; $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries'; $handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip"); if ($handle->uploaded) { $handle->Process($savepath); $handle->Clean(); if (JFolder::exists($savepath . DS . $row->id)) { JFolder::delete($savepath . DS . $row->id); } if (!JArchive::extract($savepath . DS . $handle->file_dst_name, $savepath . DS . $row->id)) { $this->setError(JText::_('K2_GALLERY_UPLOAD_ERROR_CANNOT_EXTRACT_ARCHIVE')); return false; } else { $row->gallery = '{gallery}' . $row->id . '{/gallery}'; } JFile::delete($savepath . DS . $handle->file_dst_name); $handle->Clean(); } else { $this->setError($handle->error); return false; } } if (JRequest::getBool('del_gallery')) { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id)) { JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id); } $row->gallery = ''; } //Video if (!JRequest::getBool('del_video')) { if (isset($files['video']) && $files['video']['error'] == 0) { $videoExtensions = array("flv", "mp4", "ogv", "webm", "f4v", "m4v", "3gp", "3g2", "mov", "mpeg", "mpg", "avi", "wmv", "divx"); $audioExtensions = array("mp3", "aac", "m4a", "ogg", "wma"); $validExtensions = array_merge($videoExtensions, $audioExtensions); $filetype = JFile::getExt($files['video']['name']); if (!in_array($filetype, $validExtensions)) { $this->setError(JText::_('K2_INVALID_VIDEO_FILE')); return false; } if (in_array($filetype, $videoExtensions)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos'; } else { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio'; } $filename = JFile::stripExt($files['video']['name']); JFile::upload($files['video']['tmp_name'], $savepath . DS . $row->id . '.' . $filetype); $filetype = JFile::getExt($files['video']['name']); $row->video = '{' . $filetype . '}' . $row->id . '{/' . $filetype . '}'; } else { if (JRequest::getVar('remoteVideo')) { $fileurl = JRequest::getVar('remoteVideo'); $filetype = JFile::getExt($fileurl); $row->video = '{' . $filetype . 'remote}' . $fileurl . '{/' . $filetype . 'remote}'; } if (JRequest::getVar('videoID')) { $provider = JRequest::getWord('videoProvider'); $videoID = JRequest::getVar('videoID'); $row->video = '{' . $provider . '}' . $videoID . '{/' . $provider . '}'; } if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW)) { $row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW); } } } else { $current =& JTable::getInstance('K2Item', 'Table'); $current->load($row->id); preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER); $videotype = $matches[1][0]; $videofile = $matches[2][0]; if (in_array($videotype, $videoExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype); } } if (in_array($videotype, $audioExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype); } } $row->video = ''; $row->video_caption = ''; $row->video_credits = ''; } //Tags if (@$user->gid < 24 && $params->get('lockTags')) { $params->set('taggingSystem', 0); } $db =& JFactory::getDBO(); $query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval({$row->id})}"; $db->setQuery($query); $db->query(); if ($params->get('taggingSystem')) { if (@$user->gid < 24 && $params->get('lockTags')) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } $tags = JRequest::getVar('tags', NULL, 'POST', 'array'); if (count($tags)) { $tags = array_unique($tags); foreach ($tags as $tag) { $tag = str_replace('-', '', $tag); $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($tag); $db->setQuery($query); $tagID = $db->loadResult(); if ($tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } else { $K2Tag =& JTable::getInstance('K2Tag', 'Table'); $K2Tag->name = $tag; $K2Tag->published = 1; $K2Tag->check(); $K2Tag->store(); $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$K2Tag->id})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } } else { $tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array'); if (count($tags)) { foreach ($tags as $tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } if ($front) { if (!K2HelperPermissions::canPublishItem($row->catid) && $row->published) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } } if (!$row->store()) { $this->setError($row->getError()); return false; } $cache =& JFactory::getCache('com_k2'); $cache->clean(); $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew)); return $row; }
function batchupload() { JRequest::checkToken('request') or jexit('Invalid Token'); global $mainframe; $db =& JFactory::getDBO(); $user =& JFactory::getUser(); if (JFolder::exists(HOTELGUIDE_TEMP)) { $temp_dir = HOTELGUIDE_TEMP; //make temp path writeable if it is not, workaround for servers with wwwrun-problem if (!is_writeable($temp_dir)) { change_chmod($temp_dir, 0777); $permissions_changed = true; } } else { $mainframe->redirect('index.php?option=com_hotelguide&view=filemanager', JText::_('UPLOAD_ERROR_TEMP_MISSING'), 'error'); } $post = JRequest::get('post'); $country = JRequest::getVar('country', 0); $states = JRequest::getVar('states', 0); $city = JRequest::getVar('city', 0); $hotel = JRequest::getVar('hotel', 0); $title = JRequest::getVar('title'); $startno = JRequest::getVar('startnumber'); $description = JRequest::getVar('description'); $this->addModelPath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_hotelguide' . DS . 'models'); $model = $this->getModel('galleryitem', 'hotelguideModel'); $directory = 'hotel_' . $post['hotel']; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; require_once JPATH_ADMINISTRATOR . DS . 'includes' . DS . 'pcl' . DS . 'pclzip.lib.php'; if (isset($_FILES['zippack'])) { $zipfile = $_FILES['zippack']; } else { $mainframe->redirect('index.php?option=com_hotelguide&view=filemanager', JText::_('CANNOT_FIND_FILE'), 'error'); } //check existence of uploaded zip if (!JFile::exists($_FILES['zippack']['tmp_name'])) { $mainframe->redirect('index.php?option=com_hotelguide&view=filemanager', JText::_('ERROR_FILE_NOT_UPLOADED'), 'error'); } $zipfile = new PclZip($_FILES['zippack']['tmp_name']); $ziplist = $zipfile->extract(PCLZIP_OPT_PATH, $temp_dir, PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_BY_PREG, "/^(.*).((jpg)|(JPG)|(jpeg)|(JPEG)|(jpe)|(JPE)|(png)|(PNG)|(gif)|(GIF))\$/"); //check error code of extraction if ($zipfile->error_code != 1) { $ziperror = str_replace("'", "", $zipfile->errorInfo()); $msg = JText::_('ZIPFILE ERROR'); $this->setRedirect('index.php?option=com_hotelguide&view=filemanager', $msg); } $sizeofzip = sizeof($ziplist); $ziplist = array_reverse($ziplist); for ($i = 0; $i < $sizeofzip; $i++) { $filepathinfos = pathinfo($ziplist[$i]['filename']); $origfilename = $filepathinfos["basename"]; $handle = new Upload($temp_dir . DS . $origfilename); if ($handle->uploaded) { $album_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($album_dir)) { mkdir($album_dir, 0777); } if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($album_dir); $post['filename'] = $handle->file_dst_name; $post['imagewidth'] = $width; $post['imageheight'] = $height; $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 240; } else { $handle->image_ratio_x = true; $handle->image_y = 240; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 64; } else { $handle->image_ratio_x = true; $handle->image_y = 64; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); if (!$startno) { $startno = 0; } $no = $startno + $i; // $post['catid'] = $cid[0]; if ($no) { $post['title'] = $title . '-' . $no; } else { $post['title'] = $title; } // $post['created'] = mktime( ); // $post['created_by'] = $user->username; } if ($model->store($post)) { $link = 'index.php?option=com_hotelguide&view=galleryitems'; $msg = JText::_('ZIP FILE SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('ERROR SAVING ZIP FILE'); JError::raiseError(500, $model->getError()); $link = 'index.php?option=com_hotelguide&view=galleryitems'; } $model->checkin(); $this->setRedirect($link, $msg); } }
/** * Logic to save an event * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $model = $this->getModel('event'); if (isset($_FILES['file_upload'])) { $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_EVENT_ALBUM_URL; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['image'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_EVENT_RESIZE_URL; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($post['image_size']) { $handle->image_x = $post['image_size']; } else { $handle->image_x = 240; } } else { $handle->image_ratio_x = true; if ($post['image_size']) { $handle->image_y = $post['image_size']; } else { $handle->image_y = 240; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_EVENT_THUMB_URL; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 74; } else { $handle->image_ratio_x = true; $handle->image_y = 74; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=event&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=event'; break; default: $link = 'index.php?option=com_hotelguide&view=events'; break; } $msg = JText::_('HG_EVENT_SAVED'); //Take care of access levels and state $eventsmodel =& $this->getModel('events'); $eventsmodel->access($model->get('id'), $model->get('access')); $pubid = array(); $pubid[] = $model->get('id'); if ($model->get('published') == 1) { $eventsmodel->publish($pubid, 1); } else { $eventsmodel->publish($pubid, 0); } if (!empty($typeimg)) { } $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_EVENT'); $link = 'index.php?option=com_hotelguide&view=event'; } $model->checkin(); $this->setRedirect($link, $msg); }
function save($front = false) { $mainframe = JFactory::getApplication(); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.archive'); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $db = JFactory::getDBO(); $user = JFactory::getUser(); $row = JTable::getInstance('K2Item', 'Table'); $params = JComponentHelper::getParams('com_k2'); $nullDate = $db->getNullDate(); if (!$row->bind(JRequest::get('post'))) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if ($front && $row->id == NULL) { JLoader::register('K2HelperPermissions', JPATH_SITE . DS . 'components' . DS . 'com_k2' . DS . 'helpers' . DS . 'permissions.php'); if (!K2HelperPermissions::canAddItem($row->catid)) { $mainframe->enqueueMessage(JText::_('K2_YOU_ARE_NOT_ALLOWED_TO_POST_TO_THIS_CATEGORY_SAVE_FAILED'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&task=add&tmpl=component'); } } $isNew = $row->id ? false : true; // If we are in front-end and the item is not new we need to get it's current published state. if (!$isNew && $front) { $id = JRequest::getInt('id'); $currentRow = JTable::getInstance('K2Item', 'Table'); $currentRow->load($id); $isAlreadyPublished = $currentRow->published; $currentFeaturedState = $currentRow->featured; } if ($params->get('mergeEditors')) { $text = JRequest::getVar('text', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $text = $filter->clean($text); } $pattern = '#<hr\\s+id=("|\')system-readmore("|\')\\s*\\/*>#i'; $tagPos = preg_match($pattern, $text); if ($tagPos == 0) { $row->introtext = $text; $row->fulltext = ''; } else { list($row->introtext, $row->fulltext) = preg_split($pattern, $text, 2); } } else { $row->introtext = JRequest::getVar('introtext', '', 'post', 'string', 2); $row->fulltext = JRequest::getVar('fulltext', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->introtext = $filter->clean($row->introtext); $row->fulltext = $filter->clean($row->fulltext); } } if ($row->id) { $datenow = JFactory::getDate(); $row->modified = K2_JVERSION == '15' ? $datenow->toMySQL() : $datenow->toSql(); $row->modified_by = $user->get('id'); } else { $row->ordering = $row->getNextOrder("catid = {$row->catid} AND trash = 0"); if ($row->featured) { $row->featured_ordering = $row->getNextOrder("featured = 1 AND trash = 0", 'featured_ordering'); } } $row->created_by = $row->created_by ? $row->created_by : $user->get('id'); if ($front) { $K2Permissions = K2Permissions::getInstance(); if (!$K2Permissions->permissions->get('editAll')) { $row->created_by = $user->get('id'); } } if ($row->created && strlen(trim($row->created)) <= 10) { $row->created .= ' 00:00:00'; } $config = JFactory::getConfig(); $tzoffset = K2_JVERSION == '30' ? $config->get('offset') : $config->getValue('config.offset'); $date = JFactory::getDate($row->created, $tzoffset); $row->created = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (strlen(trim($row->publish_up)) <= 10) { $row->publish_up .= ' 00:00:00'; } $date = JFactory::getDate($row->publish_up, $tzoffset); $row->publish_up = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); if (trim($row->publish_down) == JText::_('K2_NEVER') || trim($row->publish_down) == '') { $row->publish_down = $nullDate; } else { if (strlen(trim($row->publish_down)) <= 10) { $row->publish_down .= ' 00:00:00'; } $date = JFactory::getDate($row->publish_down, $tzoffset); $row->publish_down = K2_JVERSION == '15' ? $date->toMySQL() : $date->toSql(); } $metadata = JRequest::getVar('meta', null, 'post', 'array'); if (is_array($metadata)) { $txt = array(); foreach ($metadata as $k => $v) { if ($k == 'description') { $row->metadesc = $v; } elseif ($k == 'keywords') { $row->metakey = $v; } else { $txt[] = "{$k}={$v}"; } } $row->metadata = implode("\n", $txt); } if (!$row->check()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=item&cid=' . $row->id); } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('k2'); $result = $dispatcher->trigger('onBeforeK2Save', array(&$row, $isNew)); if (in_array(false, $result, true)) { JError::raiseError(500, $row->getError()); return false; } //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.item', $row, $isNew)); // Try to save the video if there is no need to wait for item ID if (!JRequest::getBool('del_video')) { if (!isset($files['video'])) { if (JRequest::getVar('remoteVideo')) { $fileurl = JRequest::getVar('remoteVideo'); $filetype = JFile::getExt($fileurl); $row->video = '{' . $filetype . 'remote}' . $fileurl . '{/' . $filetype . 'remote}'; } if (JRequest::getVar('videoID')) { $provider = JRequest::getWord('videoProvider'); $videoID = JRequest::getVar('videoID'); $row->video = '{' . $provider . '}' . $videoID . '{/' . $provider . '}'; } if (JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW)) { $row->video = JRequest::getVar('embedVideo', '', 'post', 'string', JREQUEST_ALLOWRAW); } } } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { if (version_compare(phpversion(), '5.0') < 0) { $tmpRow = $row; } else { $tmpRow = clone $row; } } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } // JoomFish! Front-end editing compatibility if ($mainframe->isSite() && JFile::exists(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomfish' . DS . 'joomfish.php')) { $itemID = $row->id; $row = $tmpRow; $row->id = $itemID; } if (!$params->get('disableCompactOrdering')) { $row->reorder("catid = {$row->catid} AND trash = 0"); } if ($row->featured && !$params->get('disableCompactOrdering')) { $row->reorder("featured = 1 AND trash = 0", 'featured_ordering'); } $files = JRequest::get('files'); //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $existingImage = JRequest::getVar('existingImage'); if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); $handle->allowed = array('image/*'); if ($handle->uploaded) { //Image params $category = JTable::getInstance('K2Category', 'Table'); $category->load($row->catid); $cparams = class_exists('JParameter') ? new JParameter($category->params) : new JRegistry($category->params); if ($cparams->get('inheritFrom')) { $masterCategoryID = $cparams->get('inheritFrom'); $query = "SELECT * FROM #__k2_categories WHERE id=" . (int) $masterCategoryID; $db->setQuery($query, 0, 1); $masterCategory = $db->loadObject(); $cparams = class_exists('JParameter') ? new JParameter($masterCategory->params) : new JRegistry($masterCategory->params); } $params->merge($cparams); //Original image $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src'; $handle->image_convert = 'jpg'; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = md5("Image" . $row->id); $handle->Process($savepath); $filename = $handle->file_dst_name_body; $savepath = JPATH_SITE . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache'; //XLarge image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XL'; if (JRequest::getInt('itemImageXL')) { $imageWidth = JRequest::getInt('itemImageXL'); } else { $imageWidth = $params->get('itemImageXL', '800'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Large image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_L'; if (JRequest::getInt('itemImageL')) { $imageWidth = JRequest::getInt('itemImageL'); } else { $imageWidth = $params->get('itemImageL', '600'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Medium image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_M'; if (JRequest::getInt('itemImageM')) { $imageWidth = JRequest::getInt('itemImageM'); } else { $imageWidth = $params->get('itemImageM', '400'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Small image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_S'; if (JRequest::getInt('itemImageS')) { $imageWidth = JRequest::getInt('itemImageS'); } else { $imageWidth = $params->get('itemImageS', '200'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //XSmall image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_XS'; if (JRequest::getInt('itemImageXS')) { $imageWidth = JRequest::getInt('itemImageXS'); } else { $imageWidth = $params->get('itemImageXS', '100'); } $handle->image_x = $imageWidth; $handle->Process($savepath); //Generic image $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_convert = 'jpg'; $handle->jpeg_quality = $params->get('imagesQuality'); $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $filename . '_Generic'; $imageWidth = $params->get('itemImageGeneric', '300'); $handle->image_x = $imageWidth; $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } if (JRequest::getBool('del_image')) { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); $filename = md5("Image" . $current->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'src' . DS . $filename . '.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XS.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_S.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_M.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_L.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_XL.jpg'); } if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg')) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'items' . DS . 'cache' . DS . $filename . '_Generic.jpg'); } $row->image_caption = ''; $row->image_credits = ''; } //Attachments $attachments = JRequest::getVar('attachment_file', NULL, 'FILES', 'array'); $attachments_names = JRequest::getVar('attachment_name', '', 'POST', 'array'); $attachments_titles = JRequest::getVar('attachment_title', '', 'POST', 'array'); $attachments_title_attributes = JRequest::getVar('attachment_title_attribute', '', 'POST', 'array'); $attachments_existing_files = JRequest::getVar('attachment_existing_file', '', 'POST', 'array'); $attachmentFiles = array(); if (count($attachments)) { foreach ($attachments as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $attachmentFiles)) { $attachmentFiles[$i] = array(); } $attachmentFiles[$i][$k] = $v; } } $path = $params->get('attachmentsFolder', NULL); if (is_null($path)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'attachments'; } else { $savepath = $path; } $counter = 0; foreach ($attachmentFiles as $key => $file) { if ($file["tmp_name"] || $attachments_existing_files[$key]) { if ($attachments_existing_files[$key]) { $src = JPATH_SITE . DS . JPath::clean($attachments_existing_files[$key]); $copyName = basename($src); $dest = $savepath . DS . $copyName; if (JFile::exists($dest)) { $existingFileName = JFile::getName($dest); $ext = JFile::getExt($existingFileName); $basename = JFile::stripExt($existingFileName); $newFilename = $basename . '_' . time() . '.' . $ext; $copyName = $newFilename; $dest = $savepath . DS . $newFilename; } JFile::copy($src, $dest); $attachment = JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $copyName; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $handle = new Upload($file); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->allowed[] = 'application/x-zip'; $handle->allowed[] = 'application/download'; $handle->Process($savepath); $filename = $handle->file_dst_name; $handle->Clean(); $attachment = JTable::getInstance('K2Attachment', 'Table'); $attachment->itemID = $row->id; $attachment->filename = $filename; $attachment->title = empty($attachments_titles[$counter]) ? $filename : $attachments_titles[$counter]; $attachment->titleAttribute = empty($attachments_title_attributes[$counter]) ? $filename : $attachments_title_attributes[$counter]; $attachment->store(); } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } } $counter++; } } //Gallery $flickrGallery = JRequest::getVar('flickrGallery'); if ($flickrGallery) { $row->gallery = '{gallery}' . $flickrGallery . '{/gallery}'; } if (isset($files['gallery']) && $files['gallery']['error'] == 0 && !JRequest::getBool('del_gallery')) { $handle = new Upload($files['gallery']); $handle->file_auto_rename = true; $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries'; $handle->allowed = array("application/download", "application/rar", "application/x-rar-compressed", "application/arj", "application/gnutar", "application/x-bzip", "application/x-bzip2", "application/x-compressed", "application/x-gzip", "application/x-zip-compressed", "application/zip", "multipart/x-zip", "multipart/x-gzip", "application/x-unknown", "application/x-zip"); if ($handle->uploaded) { $handle->Process($savepath); $handle->Clean(); if (JFolder::exists($savepath . DS . $row->id)) { JFolder::delete($savepath . DS . $row->id); } if (!JArchive::extract($savepath . DS . $handle->file_dst_name, $savepath . DS . $row->id)) { $mainframe->enqueueMessage(JText::_('K2_GALLERY_UPLOAD_ERROR_CANNOT_EXTRACT_ARCHIVE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } else { $row->gallery = '{gallery}' . $row->id . '{/gallery}'; } JFile::delete($savepath . DS . $handle->file_dst_name); $handle->Clean(); } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } } if (JRequest::getBool('del_gallery')) { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id)) { JFolder::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'galleries' . DS . $current->id); } $row->gallery = ''; } //Video if (!JRequest::getBool('del_video')) { if (isset($files['video']) && $files['video']['error'] == 0) { $videoExtensions = array("flv", "mp4", "ogv", "webm", "f4v", "m4v", "3gp", "3g2", "mov", "mpeg", "mpg", "avi", "wmv", "divx"); $audioExtensions = array("mp3", "aac", "m4a", "ogg", "wma"); $validExtensions = array_merge($videoExtensions, $audioExtensions); $filetype = JFile::getExt($files['video']['name']); if (!in_array($filetype, $validExtensions)) { $mainframe->enqueueMessage(JText::_('K2_INVALID_VIDEO_FILE'), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } if (in_array($filetype, $videoExtensions)) { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos'; } else { $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio'; } $filename = JFile::stripExt($files['video']['name']); JFile::upload($files['video']['tmp_name'], $savepath . DS . $row->id . '.' . $filetype); $filetype = JFile::getExt($files['video']['name']); $row->video = '{' . $filetype . '}' . $row->id . '{/' . $filetype . '}'; } } else { $current = JTable::getInstance('K2Item', 'Table'); $current->load($row->id); preg_match_all("#^{(.*?)}(.*?){#", $current->video, $matches, PREG_PATTERN_ORDER); $videotype = $matches[1][0]; $videofile = $matches[2][0]; if (in_array($videotype, $videoExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'videos' . DS . $videofile . '.' . $videotype); } } if (in_array($videotype, $audioExtensions)) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'audio' . DS . $videofile . '.' . $videotype); } } $row->video = ''; $row->video_caption = ''; $row->video_credits = ''; } //Extra fields $objects = array(); $variables = JRequest::get('post', 2); foreach ($variables as $key => $value) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); if (is_string($value)) { $value = trim($value); } $object->set('value', $value); unset($object->_errors); $objects[] = $object; } } $csvFiles = JRequest::get('files'); foreach ($csvFiles as $key => $file) { if ((bool) JString::stristr($key, 'K2ExtraField_')) { $object = new JObject(); $object->set('id', JString::substr($key, 13)); $csvFile = $file['tmp_name'][0]; if (!empty($csvFile) && JFile::getExt($file['name'][0]) == 'csv') { $handle = @fopen($csvFile, 'r'); $csvData = array(); while (($data = fgetcsv($handle, 1000)) !== FALSE) { $csvData[] = $data; } fclose($handle); $object->set('value', $csvData); } else { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $object->set('value', $json->decode(JRequest::getVar('K2CSV_' . $object->id))); if (JRequest::getBool('K2ResetCSV_' . $object->id)) { $object->set('value', null); } } unset($object->_errors); $objects[] = $object; } } require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'lib' . DS . 'JSON.php'; $json = new Services_JSON(); $row->extra_fields = $json->encode($objects); require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'extrafield.php'; $extraFieldModel = K2Model::getInstance('ExtraField', 'K2Model'); $row->extra_fields_search = ''; foreach ($objects as $object) { $row->extra_fields_search .= $extraFieldModel->getSearchValue($object->id, $object->value); $row->extra_fields_search .= ' '; } //Tags if ($user->gid < 24 && $params->get('lockTags')) { $params->set('taggingSystem', 0); } $db = JFactory::getDBO(); $query = "DELETE FROM #__k2_tags_xref WHERE itemID={intval({$row->id})}"; $db->setQuery($query); $db->query(); if ($params->get('taggingSystem')) { if ($user->gid < 24 && $params->get('lockTags')) { JError::raiseError(403, JText::_('K2_ALERTNOTAUTH')); } $tags = JRequest::getVar('tags', NULL, 'POST', 'array'); if (count($tags)) { $tags = array_unique($tags); foreach ($tags as $tag) { $tag = JString::trim($tag); if ($tag) { $tagID = false; $K2Tag = JTable::getInstance('K2Tag', 'Table'); $K2Tag->name = $tag; // Tag has been filtred and does not exist if ($K2Tag->check()) { $K2Tag->published = 1; if ($K2Tag->store()) { $tagID = $K2Tag->id; } } else { if ($K2Tag->name) { $query = "SELECT id FROM #__k2_tags WHERE name=" . $db->Quote($K2Tag->name); $db->setQuery($query); $tagID = $db->loadResult(); } } if ($tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } } } else { $tags = JRequest::getVar('selectedTags', NULL, 'POST', 'array'); if (count($tags)) { foreach ($tags as $tagID) { $query = "INSERT INTO #__k2_tags_xref (`id`, `tagID`, `itemID`) VALUES (NULL, {intval({$tagID})}, {intval({$row->id})})"; $db->setQuery($query); $db->query(); } } } // If we are in front-end check publishing permissions properly. if ($front) { // New items require the "Publish items" permission. if ($isNew && $row->published && !K2HelperPermissions::canPublishItem($row->catid)) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } // Existing items require either the "Publish items" or the "Allow editing of already published items" permission. if (!$isNew && $row->published) { $canEditPublished = $isAlreadyPublished && K2HelperPermissions::canEditPublished($row->catid); if (!K2HelperPermissions::canPublishItem($row->catid) && !$canEditPublished) { $row->published = 0; $mainframe->enqueueMessage(JText::_('K2_YOU_DONT_HAVE_THE_PERMISSION_TO_PUBLISH_ITEMS'), 'notice'); } } // If user has cannot publish the item then also cannot make it featured if (!K2HelperPermissions::canPublishItem($row->catid)) { if ($isNew) { $row->featured = 0; } else { $row->featured = $currentFeaturedState; } } } $query = "UPDATE #__k2_items SET \n video_caption = " . $db->Quote($row->video_caption) . ", \n video_credits = " . $db->Quote($row->video_credits) . ", "; if (!is_null($row->video)) { $query .= " video = " . $db->Quote($row->video) . ", "; } if (!is_null($row->gallery)) { $query .= " gallery = " . $db->Quote($row->gallery) . ", "; } $query .= " extra_fields = " . $db->Quote($row->extra_fields) . ", \n extra_fields_search = " . $db->Quote($row->extra_fields_search) . " ,\n published = " . $db->Quote($row->published) . " \n WHERE id = " . $row->id; $db->setQuery($query); if (!$db->query()) { $mainframe->enqueueMessage($db->getErrorMsg(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=items'); } $row->checkin(); $cache = JFactory::getCache('com_k2'); $cache->clean(); $dispatcher->trigger('onAfterK2Save', array(&$row, $isNew)); JPluginHelper::importPlugin('content'); if (K2_JVERSION != '15') { $dispatcher->trigger('onContentAfterSave', array('com_k2.item', &$row, $isNew)); } else { $dispatcher->trigger('onAfterContentSave', array(&$row, $isNew)); } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.item', $row, $isNew)); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('K2_ITEM_SAVED'); $link = 'index.php?option=com_k2&view=item'; break; case 'save': default: $msg = JText::_('K2_ITEM_SAVED'); if ($front) { $link = 'index.php?option=com_k2&view=item&task=edit&cid=' . $row->id . '&tmpl=component&Itemid=' . JRequest::getInt('Itemid'); } else { $link = 'index.php?option=com_k2&view=items'; } break; } $mainframe->enqueueMessage($msg); $mainframe->redirect($link); }
public function setProfileImage($file) { $foo = new Upload($file); // get user id $this->_DB->query("SELECT id FROM users WHERE uid = :dev LIMIT 1"); $this->_DB->bind(['dev' => $this->_SESS->getSess('uid_logged')]); $this->_DB->execute(); $user_id = $this->_DB->fetchAll(); $user_id = $user_id[0]['id']; // save uploaded image with a new name $foo->file_new_name_body = 'profile_image'; $foo->file_overwrite = true; $foo->allowed = array('image/*'); $foo->image_resize = true; $foo->image_x = 48; $foo->image_y = 48; $foo->Process('common/libs/dev_data/' . $user_id . '/images/'); // succeded? if ($foo->processed) { $this->_SESS->setSess(['success' => 'Profile image changed.']); $foo->Clean(); } else { $this->_SESS->setSess(['error' => $foo->error]); } }
function save() { $mainframe = JFactory::getApplication(); jimport('joomla.filesystem.file'); require_once JPATH_COMPONENT . DS . 'lib' . DS . 'class.upload.php'; $row = JTable::getInstance('K2Category', 'Table'); $params = JComponentHelper::getParams('com_k2'); if (!$row->bind(JRequest::get('post'))) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } $isNew = $row->id ? false : true; //Trigger the finder before save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderBeforeSave', array('com_k2.category', $row, $isNew)); $row->description = JRequest::getVar('description', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } if (!$row->id) { $row->ordering = $row->getNextOrder('parent = ' . $row->parent . ' AND trash=0'); } if (!$row->check()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=category&cid=' . $row->id); } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } if (!$params->get('disableCompactOrdering')) { $row->reorder('parent = ' . $row->parent . ' AND trash=0'); } if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $files = JRequest::get('files'); $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS; $existingImage = JRequest::getVar('existingImage'); if (($files['image']['error'] === 0 || $existingImage) && !JRequest::getBool('del_image')) { if ($files['image']['error'] === 0) { $image = $files['image']; } else { $image = JPATH_SITE . DS . JPath::clean($existingImage); } $handle = new Upload($image); if ($handle->uploaded) { $handle->file_auto_rename = false; $handle->jpeg_quality = $params->get('imagesQuality', '85'); $handle->file_overwrite = true; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('catImageWidth', '100'); $handle->Process($savepath); if ($files['image']['error'] === 0) { $handle->Clean(); } } else { $mainframe->enqueueMessage($handle->error, 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } $row->image = $handle->file_dst_name; } if (JRequest::getBool('del_image')) { $currentRow = JTable::getInstance('K2Category', 'Table'); $currentRow->load($row->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $currentRow->image)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'categories' . DS . $currentRow->image); } $row->image = ''; } if (!$row->store()) { $mainframe->enqueueMessage($row->getError(), 'error'); $mainframe->redirect('index.php?option=com_k2&view=categories'); } //Trigger the finder after save event $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('finder'); $results = $dispatcher->trigger('onFinderAfterSave', array('com_k2.category', $row, $isNew)); $cache = JFactory::getCache('com_k2'); $cache->clean(); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=category&cid=' . $row->id; break; case 'saveAndNew': $msg = JText::_('K2_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=category'; break; case 'save': default: $msg = JText::_('K2_CATEGORY_SAVED'); $link = 'index.php?option=com_k2&view=categories'; break; } $mainframe->enqueueMessage($msg); $mainframe->redirect($link); }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); global $hgconf; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['description'] = JRequest::getVar('description', '', 'POST', 'string', JREQUEST_ALLOWRAW); $delete_image = JRequest::getCmd('delete_image', false, 'post'); $model = $this->getModel('promotion'); $data = $model->getFile($post['id']); $directory = 'hotel_' . $post['hotel']; if (!$hgconf->medium_size) { $hgconf->medium_size = 240; } if (!$hgconf->thumb_size) { $hgconf->thumb_size = 64; } if ($delete_image) { $post['filename'] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (JFile::exists($dir . $data->filename)) { JFile::delete($dir . $data->filename); } if (JFile::exists($resize_dir . $data->filename)) { JFile::delete($resize_dir . $data->filename); } if (JFile::exists($thumb_dir . $data->filename)) { JFile::delete($thumb_dir . $data->filename); } } if (isset($_FILES['file_upload'])) { $filename = $_FILES['file_upload']['name']; $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['filename'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->thumb_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->thumb_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=promotion&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=promotion'; break; default: $link = 'index.php?option=com_hotelguide&view=promotions'; break; } $msg = JText::_('HG_PROMOTION_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ITEM'); $link = 'index.php?option=com_hotelguide&view=promotion'; } $model->checkin(); $this->setRedirect($link, $msg); }
/** * Logic to save an item * * @access public * @return void * @since 1.0 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; global $hgconf; $task = JRequest::getVar('task'); //Sanitize $post = JRequest::get('post'); $post['service'] = JRequest::getVar('service', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['intro'] = JRequest::getVar('intro', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['location'] = JRequest::getVar('location', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['general'] = JRequest::getVar('general', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['roomgeneral'] = JRequest::getVar('roomgeneral', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['promotion'] = JRequest::getVar('promotion', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['resto'] = JRequest::getVar('resto', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['prices'] = JRequest::getVar('prices', '', 'POST', 'string', JREQUEST_ALLOWRAW); $post['otherinfo'] = JRequest::getVar('otherinfo', '', 'POST', 'string', JREQUEST_ALLOWRAW); $delete_mainimage = JRequest::getCmd('delete_mainimage', false, 'post'); $delete_logoimage = JRequest::getCmd('delete_logoimage', false, 'post'); $delete_serviceimage = JRequest::getCmd('delete_serviceimage', false, 'post'); $delete_roomimage = JRequest::getCmd('delete_roomimage', false, 'post'); $roomimage_size = $post['roomimage_size']; $directory = 'hotel_' . $post['id']; if (!$hgconf->medium_size) { $hgconf->medium_size = 240; } if (!$hgconf->thumb_size) { $hgconf->thumb_size = 64; } if (!$roomimage_size) { $roomimage_size = 240; } $model = $this->getModel('hotelitem'); if ($delete_mainimage || $delete_logoimage || $delete_serviceimage || $delete_roomimage) { $data = $model->getFiles($post['id']); if ($delete_mainimage) { $post['mainimage'] = null; $post['imagewidth'] = ''; $post['imageheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->mainimage)) { JFile::delete($dir . $data->mainimage); } if (JFile::exists($resize_dir . $data->mainimage)) { JFile::delete($resize_dir . $data->mainimage); } if (JFile::exists($thumb_dir . $data->mainimage)) { JFile::delete($thumb_dir . $data->mainimage); } if (JFile::exists($crop_dir . $data->mainimage)) { JFile::delete($crop_dir . $data->mainimage); } if (JFile::exists($smallcrop_dir . $data->mainimage)) { JFile::delete($smallcrop_dir . $data->mainimage); } } if ($delete_serviceimage) { $post['serviceimage'] = null; $post['servicewidth'] = ''; $post['serviceheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->serviceimage)) { JFile::delete($dir . $data->serviceimage); } if (JFile::exists($resize_dir . $data->serviceimage)) { JFile::delete($resize_dir . $data->serviceimage); } if (JFile::exists($thumb_dir . $data->serviceimage)) { JFile::delete($thumb_dir . $data->serviceimage); } } if ($delete_roomimage) { $post['roomimage'] = null; $post['roomwidth'] = ''; $post['roomheight'] = ''; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (JFile::exists($dir . $data->roomimage)) { JFile::delete($dir . $data->roomimage); } if (JFile::exists($resize_dir . $data->roomimage)) { JFile::delete($resize_dir . $data->roomimage); } if (JFile::exists($thumb_dir . $data->roomimage)) { JFile::delete($thumb_dir . $data->roomimage); } } if ($delete_logoimage) { $post['logoimage'] = null; $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS; if (JFile::exists($dir . $data->logoimage)) { JFile::delete($dir . $data->logoimage); } } } $data = $model->getFiles($post['id']); if (isset($_FILES['file_upload'])) { $typeimg = $_FILES['file_upload']['type']; if (!empty($typeimg)) { if ($typeimg == 'image/jpeg') { $ext = '.jpg'; } else { $ext = '.' . substr($typeimg, strlen($typeimg) - 3); } $filename = 'logo_' . $post['id'] . $ext; $post['logoimage'] = $filename; } $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->image_resize = true; $handle->image_ratio_x = true; $handle->image_y = 50; $handle->file_new_name_body = 'logo_' . $post['id']; $handle->Process($dir); $handle->Clean(); } } if (isset($_FILES['upload_file'])) { $imgtype = $_FILES['upload_file']['type']; if (!empty($imgtype)) { if ($imgtype == 'image/jpeg') { $ext = '.jpg'; } else { $ext = '.' . substr($imgtype, strlen($imgtype) - 3); } $mainfilename = 'main_' . $post['id'] . $ext; $post['mainimage'] = $mainfilename; } $handle = new Upload($_FILES['upload_file']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 84; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 84; } } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($thumb_dir); // crop image $crop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'crop' . DS; if (!file_exists($crop_dir)) { mkdir($crop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; if ($hgconf->crop_size) { $handle->image_y = $hgconf->crop_size; $handle->image_x = $hgconf->crop_size; } else { $handle->image_y = 170; $handle->image_x = 170; } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($crop_dir); // small crop image $smallcrop_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'smallcrop' . DS; if (!file_exists($smallcrop_dir)) { mkdir($smallcrop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 20; $handle->image_x = 20; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = 'main_' . $post['id']; $handle->Process($smallcrop_dir); $handle->Clean(); } } if (isset($_FILES['upload_service'])) { $handle = new Upload($_FILES['upload_service']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $post['serviceimage'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $hgconf->medium_size; } else { $handle->image_ratio_x = true; $handle->image_y = $hgconf->medium_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['servicewidth'] = $imagewidth; $post['serviceheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 76; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 76; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if (isset($_FILES['upload_room'])) { $handle = new Upload($_FILES['upload_room']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'album' . DS; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->Process($dir); $post['roomimage'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'resize' . DS; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = $roomimage_size; } else { $handle->image_ratio_x = true; $handle->image_y = $roomimage_size; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['roomwidth'] = $imagewidth; $post['roomheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_GALLERY . DS . $directory . DS . 'thumb' . DS; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($hgconf->thumb_size) { $handle->image_x = $hgconf->thumb_size; } else { $handle->image_x = 76; } } else { $handle->image_ratio_x = true; if ($hgconf->thumb_size) { $handle->image_y = $hgconf->thumb_size; } else { $handle->image_y = 76; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } //Update en las diferentes tablas en las cuales esta el user_id $db =& JFactory::getDBO(); $query = 'UPDATE #__hg_galleryitems SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_roomitems SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_restaurants SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_spas SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); $query = 'UPDATE #__hg_promotions SET user_id=' . $post['details']['created_by'] . ' WHERE hotel=' . $post['id']; $db->setQuery($query); $db->loadObject(); if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=hotelitem&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=hotelitem'; break; default: $link = 'index.php?option=com_hotelguide&view=hotelitems'; break; } $msg = JText::_('HG_ACCOMMODATION_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_ACCOMMODATON'); JError::raiseError(500, $model->getError()); $link = 'index.php?option=com_hotelguide&view=hotelitem'; } $model->checkin(); $this->setRedirect($link, $msg); }
$oImgReg = new Upload($_FILES['imagen' . $i]); if ($oImgReg->uploaded) { $oImgReg->Process('../publicidad/temp/'); if ($oImgReg->processed) { $imagen_temp = $oImgReg->file_dst_name; } //$oImgReg->image_resize = true; $oImgReg->image_ratio_crop = true; $oImgReg->image_x = 540; $oImgReg->image_y = 540; $oImgReg->allowed = array('image/*'); $oImgReg->Process('../publicidad/'); if ($oImgReg->processed) { $imagen = $oImgReg->file_dst_name; } $oImgReg->Clean(); } } $campos = array('id_seccion' => $id_seccion, 'titulo' => $titulo, 'descripcion' => $descripcion, 'target' => $target, 'link' => $link, 'imagen' => $imagen, 'imagen_thumbs' => '', 'imagen_temp' => $imagen_temp, 'url_amigable' => $url_ami, 'fecha' => $fecha, 'orden' => 0, 'estado' => '1', 'tipo' => $portada); $db->update('publicidad', $campos, 'id_seccion="' . $id_seccion . '"'); $bErr = 2; } $aLisReg = $db->select(getRow, 'publicidad', array('where' => 'id_seccion="' . $id_seccion . '"', 'order' => 'id_seccion')); ?> <link href='http://fonts.googleapis.com/css?family=Ubuntu:300,400,700' rel='stylesheet' type='text/css'> <link href="css/styles.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="js/botonera.js"></script> <script type="text/javascript" src="js/validate/jquery.validate.js"></script>
function save() { $mainframe =& JFactory::getApplication(); jimport('joomla.filesystem.file'); require_once JPATH_COMPONENT . DS . 'lib' . DS . 'class.upload.php'; $row =& JTable::getInstance('K2User', 'Table'); $params =& JComponentHelper::getParams('com_k2'); if (!$row->bind(JRequest::get('post'))) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } $row->description = JRequest::getVar('description', '', 'post', 'string', 2); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } $jUser =& JFactory::getUser($row->userID); $row->userName = $jUser->name; if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } //Image if ((int) $params->get('imageMemoryLimit')) { ini_set('memory_limit', (int) $params->get('imageMemoryLimit') . 'M'); } $file = JRequest::get('files'); $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS; if ($file['image']['error'] == 0 && !JRequest::getBool('del_image')) { $handle = new Upload($file['image']); if ($handle->uploaded) { $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('userImageWidth', '100'); $handle->Process($savepath); $handle->Clean(); } else { $mainframe->redirect('index.php?option=com_k2&view=users', $handle->error, 'error'); } $row->image = $handle->file_dst_name; } if (JRequest::getBool('del_image')) { $current =& JTable::getInstance('K2User', 'Table'); $current->load($row->id); if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $current->image)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $current->image); } $row->image = ''; } if (!$row->check()) { $mainframe->redirect('index.php?option=com_k2&view=user&cid=' . $row->id, $row->getError(), 'error'); } if (!$row->store()) { $mainframe->redirect('index.php?option=com_k2&view=users', $row->getError(), 'error'); } $cache =& JFactory::getCache('com_k2'); $cache->clean(); switch (JRequest::getCmd('task')) { case 'apply': $msg = JText::_('K2_CHANGES_TO_USER_SAVED'); $link = 'index.php?option=com_k2&view=user&cid=' . $row->userID; break; case 'save': default: $msg = JText::_('K2_USER_SAVED'); $link = 'index.php?option=com_k2&view=users'; break; } $mainframe->redirect($link, $msg); }
public function cover_photo($pic) { global $isv_db; $from_url = $_SERVER['HTTP_REFERER']; $this->feedImg = $pic; $this->size = '1000000'; $maxSize = $this->size / 1000000; $this->newName = $_SESSION['isv_user_id'] . str_replace(' ', '', microtime()) . 'cover'; $this->newName = str_replace('.', '', $this->newName); $this->path = ISVIPI_UPLOADS_BASE . 'cover/'; //check file size if ($this->feedImg["size"] > $this->size) { $_SESSION['isv_error'] = 'The file is too large. Maximum file size is ' . $maxSize . ' MB.'; header('location:' . $from_url . ''); exit; } //check file type if ($this->feedImg["type"] != "image/jpg" && $this->feedImg["type"] != "image/png" && $this->feedImg["type"] != "image/jpeg" && $this->feedImg["type"] != "image/gif") { $_SESSION['isv_error'] = 'Allowed file types are .jpg .jpeg .png .gif'; header('location:' . $from_url . ''); exit; } //check image dimension $image_info = getimagesize($this->feedImg["tmp_name"]); if ($image_info[0] < 800 || $image_info[1] < 250) { $_SESSION['isv_error'] = 'Image dimension MUST be a minimum of 800px by 250px'; header('location:' . $from_url . ''); exit; } //require file upload class require_once ISVIPI_CLASSES_BASE . 'utilities/class.upload.php'; $newUpload = new Upload($this->feedImg); $newUpload->file_new_name_body = $this->newName; $newUpload->image_resize = true; $newUpload->image_convert = 'jpg'; $newUpload->image_x = 800; $newUpload->image_ratio_y = true; $newUpload->Process($this->path); if (!$newUpload->processed) { $_SESSION['isv_error'] = 'An error occurred: ' . $newUpload->error . ''; header('location:' . $from_url . ''); exit; } $newUpload->Clean(); //update our db $newN = $this->newName . '.jpg'; $stmt = $isv_db->prepare("UPDATE user_profile SET cover_photo=? WHERE user_id=?"); $stmt->bind_param('si', $newN, $this->user_id); $stmt->execute(); $stmt->close(); //return success $_SESSION['isv_success'] = 'Cover photo uploaded.'; header('location:' . $from_url . ''); exit; }
if ($handle->processed) { // everything was fine ! echo '<p class="result">'; echo ' <b>File uploaded with success</b><br />'; echo ' File: <a href="' . $dir_pics . '/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; echo ' (' . round(filesize($handle->file_dst_pathname) / 256) / 4 . 'KB)'; echo '</p>'; } else { // one error occured echo '<p class="result">'; echo ' <b>File not uploaded to the wanted location</b><br />'; echo ' Error: ' . $handle->error . ''; echo '</p>'; } // we delete the temporary files $handle->Clean(); } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file echo '<p class="result">'; echo ' <b>File not uploaded on the server</b><br />'; echo ' Error: ' . $handle->error . ''; echo '</p>'; } } else { if ((isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '')) == 'multiple') { // ---------- MULTIPLE UPLOADS ---------- // as it is multiple uploads, we will parse the $_FILES array to reorganize it into $files $files = array(); foreach ($_FILES['my_field'] as $k => $l) { foreach ($l as $i => $v) {
function onAfterStoreUser($user, $isnew, $success, $msg) { $mainframe = JFactory::getApplication(); $params = JComponentHelper::getParams('com_k2'); jimport('joomla.filesystem.file'); $task = JRequest::getCmd('task'); if ($mainframe->isSite() && ($task == 'activate' || $isnew) && $params->get('stopForumSpam')) { $this->checkSpammer($user); } if ($mainframe->isSite() && $task != 'activate' && JRequest::getInt('K2UserForm')) { JPlugin::loadLanguage('com_k2'); JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'tables'); $row = JTable::getInstance('K2User', 'Table'); $k2id = $this->getK2UserID($user['id']); JRequest::setVar('id', $k2id, 'post'); $row->bind(JRequest::get('post')); $row->set('userID', $user['id']); $row->set('userName', $user['name']); $row->set('ip', $_SERVER['REMOTE_ADDR']); $row->set('hostname', gethostbyaddr($_SERVER['REMOTE_ADDR'])); if (isset($user['notes'])) { $row->set('notes', $user['notes']); } if ($isnew) { $row->set('group', $params->get('K2UserGroup', 1)); } else { $row->set('group', NULL); $row->set('gender', JRequest::getVar('gender')); $row->set('url', JRequest::getVar('url')); } $row->set('description', JRequest::getVar('description', '', 'post', 'string', 2)); if ($params->get('xssFiltering')) { $filter = new JFilterInput(array(), array(), 1, 1, 0); $row->description = $filter->clean($row->description); } $file = JRequest::get('files'); require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_k2' . DS . 'lib' . DS . 'class.upload.php'; $savepath = JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS; if (isset($file['image']) && $file['image']['error'] == 0 && !JRequest::getBool('del_image')) { $handle = new Upload($file['image']); $handle->allowed = array('image/*'); if ($handle->uploaded) { $handle->file_auto_rename = true; $handle->file_overwrite = false; $handle->file_new_name_body = $row->id; $handle->image_resize = true; $handle->image_ratio_y = true; $handle->image_x = $params->get('userImageWidth', '100'); $handle->Process($savepath); $handle->Clean(); } else { $mainframe->enqueueMessage(JText::_('K2_COULD_NOT_UPLOAD_YOUR_IMAGE') . $handle->error, 'notice'); } $row->image = $handle->file_dst_name; } if (JRequest::getBool('del_image')) { if (JFile::exists(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $row->image)) { JFile::delete(JPATH_ROOT . DS . 'media' . DS . 'k2' . DS . 'users' . DS . $row->image); } $row->image = ''; } $row->store(); $itemid = $params->get('redirect'); if (!$isnew && $itemid) { $menu = JSite::getMenu(); $item = $menu->getItem($itemid); $url = JRoute::_($item->link . '&Itemid=' . $itemid, false); if (JURI::isInternal($url)) { $mainframe->redirect($url, JText::_('K2_YOUR_SETTINGS_HAVE_BEEN_SAVED')); } } } }
/** * Logic to save a brand * * @access public * @return void * @since 1.5 */ function save() { // Check for request forgeries JRequest::checkToken() or jexit('Invalid Token'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.archive'); require_once HOTELGUIDE_ADMINISTRATOR . DS . 'lib' . DS . 'class.upload.php'; $task = JRequest::getVar('task'); $post = JRequest::get('post'); $post['description'] = JRequest::getVar('description', '', 'post', 'string', JREQUEST_ALLOWRAW); $model = $this->getModel('city'); if (isset($_FILES['file_upload'])) { $handle = new Upload($_FILES['file_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_CITY_ALBUM_URL; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['image'] = $handle->file_dst_name; // resized image $resize_dir = HOTELGUIDE_IMAGES_CITY_RESIZE_URL; if (!file_exists($resize_dir)) { mkdir($resize_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; if ($post['image_size']) { $handle->image_x = $post['image_size']; } else { $handle->image_x = 240; } } else { $handle->image_ratio_x = true; if ($post['image_size']) { $handle->image_y = $post['image_size']; } else { $handle->image_y = 240; } } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($resize_dir); $imagewidth = $handle->image_dst_x; $imageheight = $handle->image_dst_y; $post['imagewidth'] = $imagewidth; $post['imageheight'] = $imageheight; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_CITY_THUMB_URL; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 74; } else { $handle->image_ratio_x = true; $handle->image_y = 74; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); // thumbnail image $crop_dir = HOTELGUIDE_IMAGES_CITY_CROP_URL; if (!file_exists($crop_dir)) { mkdir($crop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 90; $handle->image_x = 90; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($crop_dir); // thumbnail image $scrop_dir = HOTELGUIDE_IMAGES_CITY_SCROP_URL; if (!file_exists($scrop_dir)) { mkdir($scrop_dir, 0777); } $handle->image_resize = true; $handle->image_ratio_crop = true; $handle->image_y = 20; $handle->image_x = 20; $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($scrop_dir); $handle->Clean(); } } if (isset($_FILES['title_upload'])) { $handle = new Upload($_FILES['title_upload']); if ($handle->uploaded) { // Original image $dir = HOTELGUIDE_IMAGES_CITY_ALBUM_URL; if (!file_exists($dir)) { mkdir($dir, 0777); } $handle->jpeg_quality = 100; $handle->file_auto_rename = false; $handle->file_overwrite = true; $width = $handle->image_src_x; $height = $handle->image_src_y; $handle->file_new_name_body = $file_body; $handle->Process($dir); $post['titleimage'] = $handle->file_dst_name; $post['titleimagewidth'] = $width; $post['titleimageheight'] = $height; // thumbnail image $thumb_dir = HOTELGUIDE_IMAGES_CITY_THUMB_URL; if (!file_exists($thumb_dir)) { mkdir($thumb_dir, 0777); } $handle->image_resize = true; if ($height < $width) { $handle->image_ratio_y = true; $handle->image_x = 74; } else { $handle->image_ratio_x = true; $handle->image_y = 74; } $handle->jpeg_quality = 85; $handle->file_auto_rename = false; $handle->file_overwrite = true; $handle->file_new_name_body = $file_body; $handle->Process($thumb_dir); $handle->Clean(); } } if ($model->store($post)) { switch ($task) { case 'apply': $link = 'index.php?option=com_hotelguide&view=city&cid[]=' . (int) $model->get('id'); break; case 'saveandnew': $link = 'index.php?option=com_hotelguide&view=city'; break; default: $link = 'index.php?option=com_hotelguide&view=cities'; break; } $msg = JText::_('HG_CITY_SAVED'); $cache =& JFactory::getCache('com_hotelguide'); $cache->clean(); } else { $msg = JText::_('HG_ERROR_SAVING_CITY'); //JError::raiseWarning( 500, $model->getError() ); $link = 'index.php?option=com_hotelguide&view=city'; } $model->checkin(); $this->setRedirect($link, $msg); }
/** * @desc adjunta ficheros a comunicado * @param void global * @return void */ private function uploadDoc() { $dir = APP_PATH . DS . "files"; $dirweb = DS . "files"; $data = array(); $files = array(); foreach ($_FILES['archivos'] as $k => $l) { foreach ($l as $i => $v) { if (!array_key_exists($i, $files)) { $files[$i] = array(); } $files[$i][$k] = $v; } } foreach ($files as $file) { $handle = new Upload($file); if ($handle->uploaded) { // movemos de temp a dir final $handle->Process($dir); // we check if everything went OK if ($handle->processed) { // everything was fine ! echo '<fieldset>'; echo ' <legend>file uploaded with success</legend>'; echo ' <p>' . round(filesize($handle->file_dst_pathname) / 256) / 4 . 'KB</p>'; echo ' link to the file just uploaded: <a href="' . $dirweb . '/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>'; echo '</fieldset>'; $data['url'] = $handle->file_dst_name; $data['consecu'] = $this->consecu; $this->_setDoc($data); } else { // one error occured echo '<fieldset>'; echo ' <legend>file not uploaded to the wanted location</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } // we delete the temporary files $handle->Clean(); } else { // if we're here, the upload file failed for some reasons // i.e. the server didn't receive the file echo '<fieldset>'; echo ' <legend>file not uploaded on the server</legend>'; echo ' Error: ' . $handle->error . ''; echo '</fieldset>'; } } }