/** * @desc Almacena las imágenes en la base de datos **/ function saveImages($edit = 0) { global $xoopsModuleConfig, $xoopsSecurity; foreach ($_POST as $k => $v) { ${$k} = $v; } $ruta = "&page={$page}"; //Verificamos que el trabajo sea válido if ($work <= 0) { redirectMsg('./works.php', __('You must specify a work ID!', 'works'), 1); die; } //Verificamos que el trabajo exista $work = new PWWork($work); if ($work->isNew()) { redirectMsg('./works.php', __('Specified work does not exists!', 'works'), 1); die; } if (!$xoopsSecurity->check()) { redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Session token expired!', 'works'), 1); die; } if ($edit) { //Verificamos que la imagen sea válida if ($id <= 0) { redirectMsg('./images.php?work=' . $work->id() . $ruta, __('You must specify an image ID!', 'works'), 1); die; } //Verificamos que la imagen exista $img = new PWImage($id); if ($img->isNew()) { redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Specified image does not exists!', 'works'), 1); die; } } else { $img = new PWImage(); } $img->setTitle($title); $img->setDesc(substr($desc, 0, 100)); $img->setWork($work->id()); //Imagen include_once RMCPATH . '/class/uploader.php'; $folder = XOOPS_UPLOAD_PATH . '/works'; $folderths = XOOPS_UPLOAD_PATH . '/works/ths'; if ($edit) { $image = $img->image(); $filename = $img->image(); } else { $filename = ''; } //Obtenemos el tamaño de la imagen $thSize = $xoopsModuleConfig['image_ths']; $imgSize = $xoopsModuleConfig['image']; $up = new RMFileUploader($folder, $xoopsModuleConfig['size_image'] * 1024, array('jpg', 'png', 'gif')); if ($up->fetchMedia('image')) { if (!$up->upload()) { redirectMsg('./images.php?op=' . ($edit ? 'edit' : 'new') . '&work=' . $work->id() . $ruta, $up->getErrors(), 1); die; } if ($edit && $img->image() != '') { @unlink(XOOPS_UPLOAD_PATH . '/works/' . $img->image()); @unlink(XOOPS_UPLOAD_PATH . '/works/ths/' . $img->image()); } $filename = $up->getSavedFileName(); $fullpath = $up->getSavedDestination(); // Redimensionamos la imagen $redim = new RMImageResizer($fullpath, $fullpath); switch ($xoopsModuleConfig['redim_image']) { case 0: //Recortar miniatura $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($folderths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 1: //Recortar imagen grande $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($folderths . "/{$filename}"); $redim->resizeWidth($thSize[0]); break; case 2: //Recortar ambas $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($folderths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 3: //Redimensionar $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($folderths . "/{$filename}"); $redim->resizeWidth($thSize[0]); break; } } $img->setImage($filename); RMEvents::get()->run_event('works.save.image', $img); if (!$img->save()) { redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Errors ocurred while trying to save the image', 'works') . '<br />' . $img->errors(), 1); die; } else { redirectMsg('./images.php?work=' . $work->id() . $ruta, __('Database updated successfully!', 'works'), 0); die; } }
if (!$work->isPublic()) { $xoopsTpl->assign('lang_preview', __('You are in preview mode! This work is hidden for all other users.', 'works')); } $cat = new PWCategory($work->category()); $client = new PWClient($work->client()); $work_data = array('id' => $work->id(), 'title' => $work->title(), 'desc' => $work->desc(), 'intro' => $work->descShort(), 'category' => array('name' => $cat->name(), 'description' => $cat->desc(), 'id' => $cat->id(), 'nameid' => $cat->nameId(), 'link' => $cat->link()), 'client' => $client->businessName(), 'site' => $work->nameSite(), 'url' => formatURL($work->url()), 'created' => formatTimeStamp($work->created(), 's'), 'start' => formatTimeStamp($work->start(), 's'), 'period' => $work->period(), 'cost' => $mc['cost'] ? sprintf($mc['format_currency'], number_format($work->cost(), 2)) : '', 'mark' => $work->mark(), 'image' => XOOPS_UPLOAD_URL . '/works/' . $work->image(), 'thumb' => XOOPS_UPLOAD_URL . '/works/ths/' . $work->image(), 'comment' => $work->comment(), 'rating' => PWFunctions::rating($work->rating()), 'views' => $work->views(), 'metas' => $work->get_metas(), 'public' => $work->isPublic(), 'link' => $work->link()); $work_data = RMEvents::get()->run_event('works.work.data<{$work.l}', $work_data, $work); $xoopsTpl->assign('work', $work_data); $work->addView(); //Obtenemos todas las imágenes del trabajo $sql = "SELECT * FROM " . $db->prefix('pw_images') . " WHERE work=" . $work->id(); $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $img = new PWImage(); $img->assignVars($row); $tpl->append('images', array('id' => $img->id(), 'image' => XOOPS_UPLOAD_URL . '/works/ths/' . $img->image(), 'title' => $img->title(), 'desc' => $img->desc(), 'link_image' => XOOPS_UPLOAD_URL . '/works/' . $img->image())); } RMEvents::get()->run_event('works.load.work.images', $work); $tpl->assign('xoops_pagetitle', $work->title() . ' » ' . $mc['title']); /** * Otros trabajos **/ if ($mc['other_works'] > 0) { if ($mc['other_works'] == 2) { //Trabajos destacados $sql = "SELECT * FROM " . $db->prefix('pw_works') . " WHERE public=1 AND mark=1 AND id_work<>'" . $work->id() . "' ORDER BY RAND() LIMIT 0," . $mc['num_otherworks']; } elseif ($mc['other_works'] == 1) { //Misma categoría $sql = "SELECT * FROM " . $db->prefix('pw_works') . " WHERE public=1 AND catego=" . $work->category() . " AND id_work<>'" . $work->id() . "' ORDER BY RAND() LIMIT 0," . $mc['num_otherworks']; } $result = $db->query($sql);