/** * @desc Mostramos el contenido de un Álbum */ function showSetContent() { global $usr, $db, $xoopsModule, $mc, $xoopsModuleConfig, $xoopsConfig, $xoopsUser, $xoopsOption, $tpl, $page; global $pag, $set; $mc =& $xoopsModuleConfig; $user = new GSUser($usr); if ($user->isNew()) { redirect_header(GSFunctions::get_url(), 0, __('Specified users does not exists!', 'galleries')); die; } $set = new GSSet($set); if ($set->isNew()) { redirect_header(GSFunctions::get_url(), 0, __('Specified album does not exists!', 'galleries')); die; } //Verificamos la privacidad del album if (!$set->ispublic()) { if (!$xoopsUser || $xoopsUser->uid() != $set->owner()) { redirect_header(GSFunctions::get_url(), 1, __('You can not view this private album!', 'galleries')); die; } } else { if (!$xoopsUser && $set->isPublic() == 1 && !$user->isFriend($xoopsUser->uid())) { redirect_header(GSFunctions::get_url(), 1, sprintf(__('You must be a friend of %s in order to see this album!', 'galleries'), $user->uname())); die; } } //Incrementamos el número de hits del album if (!isset($_SESSION['vsets'])) { $set->addHit(); $_SESSION['vsets'] = array($set->id()); } elseif (!in_array($set->id(), $_SESSION['vsets'])) { $set->addHit(); $_SESSION['vsets'][] = $set->id(); } $xoopsOption['template_main'] = $mc['set_format_mode'] ? 'gs_setpics.html' : 'gs_userpics.html'; $xoopsOption['module_subpage'] = 'userset'; include 'header.php'; GSFunctions::makeHeader(); // Información del Usuario $tpl->assign('lang_picsof', sprintf(__('Pictures in %s'), $set->title())); $tpl->assign('user', array('id' => $user->uid(), 'uname' => $user->uname(), 'avatar' => RMEvents::get()->run_event('rmcommon.get.avatar', $user->userVar('email'), 0, $user->userVar('user_avatar')), 'link' => $user->userURL())); $tpl->assign('set', array('title' => $set->title(), 'description' => $set->getVar('description', 's'))); // Lenguaje $tpl->assign('lang_bmark', __('Favorites', 'galleries')); $tpl->assign('lang_pics', __('Pictures', 'galleries')); $tpl->assign('sets_link', GSFunctions::get_url() . ($mc['urlmode'] ? "explore/sets/usr/" . $user->uname() . '/' : "?explore=sets&usr="******"explore/tags/usr/" . $user->uname() . '/' : "?explore=tags&usr="******"cp/bookmarks/" : "?cp=bookmarks")); $tpl->assign('xoops_pagetitle', sprintf(__('Pictures in %s'), $set->title()) . ' » ' . $mc['section_title']); $tpl->assign('lang_numpics', sprintf(__('Pictures: %s', 'galleries'), $set->pics())); $tpl->assign('lang_numviews', sprintf(__('Hits: %s'), $set->hits())); global $xoTheme; if ($set->getVar('description') != '') { $xoTheme->addMeta('meta', 'description', TextCleaner::clean_disabled_tags($set->getVar('description'))); } //Verificamos la privacidad de las imágenes if ($xoopsUser && $xoopsUser->uid() == $user->uid()) { $public = ''; } else { if ($xoopsUser && $user->isFriend($xoopsUser->uid())) { $public = " AND public<>0"; } else { $public = "AND public='2'"; } } $tbl1 = $db->prefix("gs_images"); $tbl2 = $db->prefix("gs_setsimages"); $sql = "SELECT COUNT(*) FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image {$public} AND owner='" . $user->uid() . "'"; $page = $page > 0 ? $page : 1; /** * @desc Formato para el manejo de las imágenes */ if ($mc['set_format_mode']) { $format = $mc['set_format_values']; $crop = $format[0]; // 0 = Redimensionar, 1 = Cortar $width = $format[1]; $height = $format[2]; $limit = $format[3]; $cols = $format[4]; @($showdesc = $format[5]); // Imágenes Grandes $format = $mc['setbig_format_values']; $bcrop = $format[0]; $bwidth = $format[1]; $bheight = $format[2]; $blimit = $format[3]; $bcols = $format[4]; @($bshowdesc = $format[5]); // Medidas $tpl->assign('big_width', $bwidth + 15); } else { $limit = $mc['limit_pics']; $cols = $mc['cols_pics']; $showdesc = 0; } list($num) = $db->fetchRow($db->query($sql)); if ($page > 0) { $page -= 1; } $start = $page * $limit; $tpages = (int) ($num / $limit); if ($num % $limit > 0) { $tpages++; } $pactual = $page + 1; if ($pactual > $tpages) { $pactual = $tpages; $start = ($tpages - 1) * $limit; } $urlnav = ''; if ($tpages > 1) { $urlnav .= $mc['urlmode'] ? 'usr/' . $user->uname() . '/set/' . $set->id() : '?usr='******'&set=' . $set->id(); $nav = new RMPageNav($num, $limit, $pactual, 5); $nav->target_url(GSFunctions::get_url() . $urlnav . ($mc['urlmode'] ? '/pag/{PAGE_NUM}/' : '&pag={PAGE_NUM}')); $tpl->assign('upNavPage', $nav->render(false)); } $showmax = $start + $limit; $showmax = $showmax > $num ? $num : $showmax; $tpl->assign('lang_showing', sprintf(__('Showing pictures %u to %u out of %u.', 'galleries'), $start + 1, $showmax, $num)); $tpl->assign('limit', $limit); $tpl->assign('pag', $pactual); //Fin de barra de navegación $sql = str_replace("COUNT(*)", '*', $sql); $sql .= " ORDER BY a.id_image ASC, a.modified DESC LIMIT {$start}, {$limit}"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $img = new GSImage(); $img->assignVars($row); $imglink = $user->userURL() . ($mc['urlmode'] ? 'img/' . $img->id() . '/set/' . $set->id() . '/' : '&img=' . $img->id() . '&set=' . $set->id()); $imgfile = $user->filesURL() . '/' . ($mc['set_format_mode'] ? 'formats/set_' : 'ths/') . $img->image(); // Conversion de los formatos if (!$img->setFormat() && $mc['set_format_mode']) { GSFunctions::resizeImage($crop, $user->filesPath() . '/' . $img->image(), $user->filesPath() . '/formats/set_' . $img->image(), $width, $height); $img->setSetFormat(1, 1); } $tpl->append('images', array('id' => $img->id(), 'title' => $img->title(), 'thumbnail' => $imgfile, 'link' => $imglink, 'bigimage' => $user->filesURL() . '/' . $img->image())); } // Imagen grande del album $sql = "SELECT * FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image {$public} AND owner='" . $user->uid() . "' \n\t\t\tORDER BY a.id_image DESC LIMIT 0,{$blimit}"; $result = $db->query($sql); $bi = 0; $tf = new RMTimeFormatter(0, __('%m%/%d%/%Y% %h%:%i%', 'galleries')); // cremos la imagen grande para los albumes while ($row = $db->fetchArray($result)) { $img = new GSImage(); $img->assignVars($row); if ($mc['set_format_mode'] && !$img->bigSetFormat()) { GSFunctions::resizeImage($bcrop, $user->filesPath() . '/' . $img->image(), $user->filesPath() . '/formats/bigset_' . $img->image(), $bwidth, $bheight); $img->setBigSetFormat(1, 1); } if ($mc['set_format_mode']) { list($ancho, $altura, $tipo, $atr) = getimagesize($user->filesPath() . '/formats/bigset_' . $img->image()); $tpl->assign('big_width', $ancho); } $imglink = $user->userURL() . 'img/' . $img->id() . '/set/' . $set->id() . '/'; // ASignamos las imagenes grandes para los albumes $imgfile = $user->filesURL() . '/' . ($mc['set_format_mode'] ? 'formats/bigset_' : 'ths/') . $img->image(); if ($bi == 0) { $tpl->assign('lang_updated', sprintf(__('Updated on %s', 'galleries'), $tf->format($img->created()))); } $tpl->append('bigs', array('id' => $img->id(), 'title' => $img->title(), 'image' => $imgfile, 'link' => $imglink)); } RMFunctions::get_comments('galleries', 'set=' . $set->id()); // Comments form RMFunctions::comments_form('galleries', 'set=' . $set->id(), 'module', GS_PATH . '/class/galleriescontroller.php'); // Datos para el formato $tpl->assign('max_cols', $cols); include 'footer.php'; }
/** * @desc Almacena la información del usuario en la base de datos **/ function saveUsers($edit = 0) { global $xoopsSecurity, $mc; foreach ($_POST as $k => $v) { ${$k} = $v; } $ruta = "&pag={$page}&search={$search}"; if (!$xoopsSecurity->check()) { redirectMsg('users.php?' . ($edit ? "op=edit&id={$id}&" : '') . $ruta, __('Session token expired!', 'galleries'), 1); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($edit) { //Verificamos que el usuario sea válido if ($id <= 0) { redirectMsg('./users.php?' . $ruta, __('User id is not valid!', 'galleries'), 1); die; } //Verificamos que el usuario exista $user = new GSUser($id); if ($user->isNew()) { redirectMsg('./users.php?' . $ruta, __('Specified user does not exists!', 'galleries'), 1); die; } //Verificamos que el usuario no se encuentre registrado $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_users') . " WHERE uid={$uid} AND id_user<>{$id}"; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirectMsg('./users.php?' . $ruta, __('This is user has been registered already!', 'galleries'), 1); die; } } else { //Verificamos que el usuario no se encuentre registrado $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_users') . " WHERE uid={$uid}"; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirectMsg('./users.php?' . $ruta, __('This is user has been registered already!', 'galleries'), 1); die; } $user = new GSUser(); } $user->setUid($uid); $xu = new XoopsUser($uid); $user->setUname($xu->uname()); $user->setQuota($quota * 1024 * 1024); $user->isNew() ? $user->setDate(time()) : ''; $user->setBlocked($block); if (!$user->save()) { redirectMsg('./users.php?' . $ruta, __('Errors ocurred while trying to save this user.', 'galleries') . '<br />' . $user->errors(), 1); die; } else { if ($edit) { @mkdir($mc['storedir'] . "/" . $user->uname(), 511); @mkdir($mc['storedir'] . "/" . $user->uname() . "/ths", 511); @mkdir($mc['storedir'] . "/" . $user->uname() . "/formats", 511); } else { mkdir($mc['storedir'] . "/" . $user->uname(), 511); mkdir($mc['storedir'] . "/" . $user->uname() . "/ths", 511); mkdir($mc['storedir'] . "/" . $user->uname() . "/formats", 511); } redirectMsg('./users.php?' . $ruta, __('User saved successfully!', 'galleries'), 0); die; } }
/** * @desc Visualiza todas las imágenes de la etiqueta especificada **/ function imgsTag() { global $tpl, $xoopsOption, $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $db, $page, $tag, $usr, $hits; $xoopsOption['template_main'] = 'gs_imagestag.html'; $xoopsOption['module_subpage'] = 'exploretags'; include 'header.php'; $mc =& $xoopsModuleConfig; GSFunctions::makeHeader(); //Verificamos si la etiqueta existe $tag = new GSTag($tag); if ($tag->isNew()) { redirect_header(GSFunctions::get_url(), 1, __('Specified tag does not exists!', 'galleries')); die; } //Incrementamos el número de hits de la etiqueta if (!isset($_SESSION['vtags'])) { $tag->addHit(); $_SESSION['vtags'] = array($tag->id()); } elseif (!in_array($tag->id(), $_SESSION['vtags'])) { $tag->addHit(); $_SESSION['vtags'][] = $tag->id(); } //Verificamos si el usuario existe if (isset($usr)) { $user = new GSUser($usr); if ($user->isNew()) { redirect_header(GSFunctions::get_url(), 1, __('Specified user does not exists!', 'galleries')); die; } $users[$user->uid()] = $user; } //Barra de Navegación $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_tagsimages') . " a INNER JOIN " . $db->prefix('gs_images'); $sql .= " b ON (a.id_tag=" . $tag->id() . " AND a.id_image=b.id_image AND b.public=2"; $sql .= $usr ? " AND b.owner=" . $user->uid() . ") " : ")"; $limit = $xoopsModuleConfig['num_imgstags']; list($num) = $db->fetchRow($db->query($sql)); if ($page > 0) { $page -= 1; } $start = $page * $limit; $tpages = (int) ($num / $limit); if ($num % $limit > 0) { $tpages++; } $pactual = $page + 1; if ($pactual > $tpages) { $rest = $pactual - $tpages; $pactual = $pactual - $rest + 1; $start = ($pactual - 1) * $limit; } if ($tpages > 1) { if ($mc['urlmode']) { $urlnav = 'explore/tags/tag/' . $tag->getVar('nameid') . '/'; $urlnav .= $usr ? 'usr/' . $user->uname() . '/' : ''; } else { $urlnav = '?xplore=tags&tag=' . $tag->getVar('nameid'); $urlnav .= $usr ? '&usr='******''; } $nav = new RMPageNav($num, $limit, $pactual, 5); $nav->target_url(GSFunctions::get_url() . $urlnav . ($mc['urlmode'] ? 'pag/{PAGE_NUM}/' : '&pag={PAGE_NUM}')); $tpl->assign('tagsNavPage', $nav->render(false)); } $showmax = $start + $limit; $showmax = $showmax > $num ? $num : $showmax; $tpl->assign('lang_showing', sprintf(__('Showing photos %u to %u from %u.', 'galleries'), $start + 1, $showmax, $num)); $tpl->assign('limit', $limit); $tpl->assign('pag', $pactual); //Fin de barra de navegación //Obtenemos las imágenes pertenecientes a la etiqueta $sql = "SELECT b.* FROM " . $db->prefix('gs_tagsimages') . " a INNER JOIN " . $db->prefix('gs_images'); $sql .= " b ON (a.id_tag=" . $tag->id() . " AND a.id_image=b.id_image AND b.public=2"; $sql .= $usr ? " AND b.owner=" . $user->uid() . ") " : ")"; $sql .= " GROUP BY b.id_image"; $sql .= " ORDER BY `created` DESC LIMIT {$start}, {$limit}"; $result = $db->query($sql); $tpl->assign('images', GSFunctions::process_image_data($result)); $tpl->assign('lang_picstag', $usr ? sprintf(__('%s: tagged as %s', 'galleries'), $user->uname(), $tag->tag()) : sprintf(__('Images tagged as "%s"', 'galleries'), $tag->tag())); $tpl->assign('tagname', $tag->tag()); $tpl->assign('usr', $usr); if ($usr) { $tpl->assign('pics_link', GS_URL . '/' . ($mc['urlmode'] ? "usr/" . $user->uname() : "user.php?id=usr/" . $user->uname() . "/")); $tpl->assign('tags_link', GS_URL . '/' . ($mc['urlmode'] ? "explore/tags/usr/" . $user->uname() . "/" : "explore.php?by=explore/tags/usr/" . $user->uname() . "/")); $tpl->assign('sets_link', GS_URL . '/' . ($mc['urlmode'] ? "explore/sets/usr/" . $user->uname() . "/" : "explore.php?by=explore/sets/usr/" . $user->uname() . "/")); $tpl->assign('bmark_link', GS_URL . '/' . ($mc['urlmode'] ? "cpanel/booksmarks/" : "cpanel.php?s=cpanel/bookmarks")); } include 'footer.php'; }
/** * @desc Almacena la información del grupo de imágenes **/ function saveBulkImages() { global $util, $mc, $xoopsUser; XoopsLogger::getInstance()->activated = false; XoopsLogger::getInstance()->renderingEnabled = false; set_time_limit(0); foreach ($_POST as $k => $v) { ${$k} = $v; } $ruta = "page={$page}&search={$search}&owner={$uid}&sort={$sort}&mode={$mode}"; if ($xoopsUser->uid() == $uid) { $xu = $xoopsUser; } else { $xu = new XoopsUser($uid); } //Verificamos si el usuario se encuentra registrado $user = new GSUser($xu->uname()); if ($user->isNew()) { //Insertamos información del usuario $user->setUid($uid); $user->setUname($xu->uname()); $user->setQuota($mc['quota'] * 1024 * 1024); $user->setDate(time()); if (!$user->save()) { send_error(__('User owner could not be created!', 'galleries') . "<br />" . $user->errors()); die; } else { mkdir($mc['storedir'] . "/" . $user->uname()); mkdir($mc['storedir'] . "/" . $user->uname() . "/ths"); mkdir($mc['storedir'] . "/" . $user->uname() . "/formats"); } } else { @mkdir($mc['storedir'] . "/" . $user->uname()); @mkdir($mc['storedir'] . "/" . $user->uname() . "/ths"); @mkdir($mc['storedir'] . "/" . $user->uname() . "/formats"); } // Insertamos las etiquetas $tgs = explode(",", $tags); /** * @desc Almacena los ids de las etiquetas que se asignarán a la imágen */ $ret = array(); foreach ($tgs as $k) { $k = trim($k); if ($k == '') { continue; } // Comprobamos que la palabra tenga la longitud permitida if (strlen($k) < $mc['min_tag'] || strlen($k) > $mc['max_tag']) { continue; } // Creamos la etiqueta $tag = new GSTag($k); if (!$tag->isNew()) { // Si ya existe nos saltamos $ret[] = $tag->id(); continue; } $tag->setTag($k); if ($tag->save()) { $ret[] = $tag->id(); } } $errors = ''; $k = 1; include_once RMCPATH . '/class/uploader.php'; $updir = $mc['storedir'] . "/" . $xu->uname(); $upths = $mc['storedir'] . "/" . $xu->uname() . "/ths"; // Cargamos la imágen if (!file_exists($updir)) { mkdir($updir, 511); } if (!file_exists($upths)) { mkdir($upths, 511); } $uploader = new RMFileUploader($updir, $mc['size_image'] * 1024, array('gif', 'jpg', 'jpeg', 'png')); $err = array(); if (!$uploader->fetchMedia('Filedata')) { send_error($uploader->getErrors()); } if (!$uploader->upload()) { send_error($uploader->getErrors()); } // Insertamos el archivo en la base de datos $img = new GSImage(); $img->setTitle($uploader->savedFileName); $img->setOwner($uid); $img->setPublic(2); $img->setCreated(time()); $img->setImage($uploader->getSavedFileName()); if (!$image->save()) { unlink($uploader->savedDestination); send_error(__('File could not be inserted to database!', 'galleries')); } $ret['message'] = '1'; $ret['id'] = $image->id(); echo json_encode($ret); die; }
/** * Resize images */ function gs_resize_images() { global $xoopsUser, $xoopsLogger, $xoopsSecurity; set_time_limit(0); $mc = RMUtilities::module_config('galleries'); $params = rmc_server_var($_GET, 'data', ''); $id = rmc_server_var($_GET, 'img', 0); if ($params == '') { send_error(__('Unauthorized!', 'galleries')); } if ($id <= 0) { send_error(__('Invalid image!', 'galleries')); } $params = TextCleaner::decrypt($params); $data = explode('|', $params); if ($data[0] != $xoopsUser->uid()) { send_error(__('Unauthorized!', 'galleries')); } if ($data[1] != GS_URL . '/admin/images.php') { send_error(__('Unauthorized!', 'galleries')); } if (!$xoopsSecurity->check(false, $data[2])) { send_error(__('Unauthorized!', 'galleries')); } $image = new GSImage($id); if ($image->isNew()) { send_error(__('Image not found!', 'galleries')); } $thSize = $mc['image_ths']; $imgSize = $mc['image']; if ($thSize[0] <= 0) { $thSize[0] = 100; } if (!isset($thSize[1]) || $thSize[1] <= 0) { $thSize[1] = $thSize[0]; } if ($imgSize[0] <= 0) { $imgSize[0] = 500; } if (!isset($imgSize[1]) || $imgSize[1] <= 0) { $imgSize[1] = $imgSize[0]; } $xu = new GSUser($image->owner(), 1); $updir = rtrim($mc['storedir'], '/') . "/" . $xu->uname(); $upurl = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, $updir); $upths = rtrim($mc['storedir'], '/') . "/" . $xu->uname() . "/ths"; $width = 0; $tfile = ''; // Almacenamos la imágen original if ($mc['saveoriginal']) { copy($updir . '/' . $image->image(), $mc['storedir'] . '/originals/' . $image->image()); } $fd = pathinfo($updir . '/' . $image->image()); $filename = $image->image(); $redim = new RMImageResizer($updir . '/' . $image->image(), $updir . '/' . $image->image()); switch ($mc['redim_image']) { case 0: //Recortar miniatura $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 1: //Recortar imagen grande $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($upths . "/" . $image->image()); $redim->resizeWidth($thSize[0]); break; case 2: //Recortar ambas $redim->resizeWidthOrHeight($imgSize[0], $imgSize[1]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeAndCrop($thSize[0], $thSize[1]); break; case 3: //Redimensionar $redim->resizeWidth($imgSize[0]); $redim->setTargetFile($upths . "/{$filename}"); $redim->resizeWidth($thSize[0]); break; } $tfile = $upurl . '/ths/' . $image->image(); $ret['message'] = sprintf(__('%s done!', 'galleries'), $image->image()); $ret['done'] = 1; $ret['file'] = $tfile; $ret['title'] = $image->image(); echo json_encode($ret); die; }
/** * @desc Almacena la información de la imagen **/ function saveImages($edit = 0) { global $xoopsUser, $xoopsModuleConfig, $xoopsConfig, $db; $mc =& $xoopsModuleConfig; foreach ($_POST as $k => $v) { ${$k} = $v; } if ($edit) { if ($id <= 0) { redirect_header($referer, 1, __('Sepecified images is not valid!', 'galleries')); die; } //Verificamos si la imagen existe $img = new GSImage($id); if ($img->isNew()) { redirect_header($referer, 1, __('Sepecified image does not exists!', 'galleries')); die; } //Verificamos que el usuario se el dueño de la imagen if ($img->owner() != $xoopsUser->uid()) { redirect_header($referer, 1, __('You are not authorized!', 'galleries')); die; } } else { $img = new GSImage(); } $img->setTitle($title); $img->setDesc($desc); $img->isNew() ? $img->setCreated(time()) : $img->setModified(time()); if (!$edit) { $img->setOwner($xoopsUser->uid()); } $img->setPublic($public); //Insertamos las etiquetas $tgs = array(); $tags = explode(",", $tags); foreach ($tags as $k) { $k = trim($k); if (!$k) { continue; } if (strlen($k) < $mc['min_tag'] || strlen($k) > $mc['max_tag']) { continue; } $tag = new GSTag($k); if (!$tag->isNew()) { $tgs[] = $tag->id(); continue; } $tag->setTag(strtolower($k)); if ($tag->save()) { $tgs[] = $tag->id(); } } if (!$edit) { //Verificamos si el usuario se encuentra registrado $user = new GSUser($xoopUser->uname()); if ($user->isNew()) { //Insertamos información del usuario $user->setUid($xoopsUser->uid()); $user->setUname($xoopsUser->uname()); $user->setQuota($mc['quota'] * 1024 * 1024); $user->setDate(time()); if (!$user->save()) { redirect_header('./cpanel.php?op=' . ($edit ? 'edit&id=' . $id : 'new') . '&pag=' . $page, 1, _MS_GS_ERRUSER); die; } else { mkdir($mc['storedir'] . "/" . $user->uname()); mkdir($mc['storedir'] . "/" . $user->uname() . "/ths"); mkdir($mc['storedir'] . "/" . $user->uname() . "/formats"); } } //Imagen include_once XOOPS_ROOT_PATH . '/rmcommon/uploader.class.php'; $up = new RMUploader(true); $folder = $mc['storedir'] . "/" . $user->uname(); $folderths = $mc['storedir'] . "/" . $user->uname() . "/ths"; if ($edit) { $filename = $img->image(); } else { $filename = ''; } $up->prepareUpload($folder, array($up->getMIME('jpg'), $up->getMIME('png'), $up->getMIME('gif')), $mc['size_image'] * 1024); if ($up->fetchMedia('image')) { if (!$up->upload()) { redirect_header('./cpanel.php?op=' . ($edit ? 'edit&id=' . $id : 'new'), 1, $up->getErrors()); die; } if ($edit && $img->image() != '') { @unlink($mc['storedir'] . "/" . $user->uname() . "/" . $img->image()); @unlink($mc['storedir'] . "/" . $user->uname() . "/ths/" . $img->image()); @unlink($mc['storedir'] . "/originals/" . $img->image()); } $filename = $up->getSavedFileName(); $fullpath = $up->getSavedDestination(); $thSize = $mc['image_ths']; $imgSize = $mc['image']; if ($thSize[0] <= 0) { $thSize[0] = 100; } if (!isset($thSize[1]) || $thSize[1] <= 0) { $thSize[1] = $thSize[0]; } if ($imgSize[0] <= 0) { $imgSize[0] = 500; } if (!isset($imgSize[1]) || $imgSize[1] <= 0) { $imgSize[1] = $imgSize[0]; } // Almacenamos la imágen original if ($mc['saveoriginal']) { copy($fullpath, $mc['storedir'] . '/originals/' . $filename); } // Redimensionamos la imagen $redim = new RMImageControl($fullpath, $fullpath); switch ($mc['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; } } //Fin de Imagen $img->setImage($filename); } $new = $img->isNew(); if (!$img->save()) { redirect_header($referer, 1, __('Errores ocurred while trying to update database!', 'galleries') . $img->errors()); die; } else { $new ? $user->addPic() : ''; $img->setTags($tgs); $sets = ''; $db = XoopsDatabaseFactory::getDatabaseConnection(); $tbl1 = $db->prefix("gs_sets"); $tbl2 = $db->prefix("gs_setsimages"); foreach ($albums as $k => $v) { // Si el album existe no incrementamos el numero de imagenes $sets .= $sets == '' ? "{$tbl2}.id_set<>'{$v}'" : " AND {$tbl2}.id_set<>'{$v}'"; if ($img->inSet($v)) { continue; } $album = new GSSet($v); $album->addPic($img->id()); } // Actualizamos los valores de los ignorados $sql = "UPDATE {$tbl1}, {$tbl2} SET {$tbl1}.pics={$tbl1}.pics-1 WHERE ({$tbl2}.id_image='" . $img->id() . "'" . ($sets != '' ? ' AND ' . $sets : '') . ") AND {$tbl1}.id_set={$tbl2}.id_set"; $db->queryF($sql); $sets = str_replace($tbl2 . '.', '', $sets); $sql = "DELETE FROM " . $db->prefix("gs_setsimages") . " WHERE id_image='" . $img->id() . "' " . ($sets != '' ? " AND ({$sets})" : ''); $db->queryF($sql); redirect_header($referer, 1, __('Database updated successfully!', 'galleries')); die; } }
/** * @desc Almacena las imágenes en la base de datos y en el disco duro */ function saveImages() { global $db, $xoopsOption, $xoopsUser, $mc, $tpl, $xmh, $xoopsModuleConfig, $util; $mc =& $xoopsModuleConfig; foreach ($_POST as $k => $v) { ${$k} = $v; } //Verificamos si el usuario se encuentra registrado $user = new GSUser($xoopsUser->uname()); if ($user->isNew()) { //Insertamos información del usuario $user->setUid($xoopsUser->uid()); $user->setUname($xoopsUser->uname()); $user->setQuota($mc['quota'] * 1024 * 1024); $user->setDate(time()); if (!$user->save()) { redirect_header('./submit.php', 1, __('Sorry, an error ocurred while trying to register your permissions on database. Try again later!', 'galleries')); die; } } @mkdir($mc['storedir'] . "/" . $user->uname()); @mkdir($mc['storedir'] . "/" . $user->uname() . "/ths"); @mkdir($mc['storedir'] . "/" . $user->uname() . "/formats"); $mc['saveoriginal'] ? @mkdir($mc['storedir'] . "/originals") : ''; // Insertamos las etiquetas $tgs = explode(" ", $tags); /** * @desc Almacena los ids de las etiquetas que se asignarán a la imagen */ $ret = array(); foreach ($tgs as $k) { $k = trim($k); $kf = TextCleaner::getInstance()->sweetstring($k); if ($kf == '') { continue; } // Comprobamos que la palabra tenga la longitud permitida if (strlen($kf) < $mc['min_tag'] || strlen($kf) > $mc['max_tag']) { continue; } // Creamos la etiqueta $tag = new GSTag($k); if (!$tag->isNew()) { // Si ya existe nos saltamos $ret[] = $tag->id(); continue; } $tag->setTag($k); $tag->setVar('nameid', $kf); if ($tag->save()) { $ret[] = $tag->id(); } } $errors = ''; $k = 1; include_once RMCPATH . '/class/uploader.php'; $up = new RMFileUploader(true); $folder = $mc['storedir'] . "/" . $xoopsUser->uname(); $folderths = $mc['storedir'] . "/" . $xoopsUser->uname() . "/ths"; foreach ($_FILES['images']['name'] as $k => $v) { if ($v == '') { continue; } $img = new GSImage(); $img->setOwner($xoopsUser->uid()); $img->setPublic($privacy); $img->setCreated(time()); //Imagen $filename = ''; $up = new RMFileUploader($folder, $mc['size_image'] * 1024, array('jpg', 'png', 'gif')); if ($up->fetchMedia('images', $k)) { if (!$up->upload()) { $errors .= $up->getErrors(); continue; } $filename = $up->getSavedFileName(); $fullpath = $up->getSavedDestination(); $thSize = $mc['image_ths']; $imgSize = $mc['image']; if ($thSize[0] <= 0) { $thSize[0] = 100; } if (!isset($thSize[1]) || $thSize[1] <= 0) { $thSize[1] = $thSize[0]; } if ($imgSize[0] <= 0) { $imgSize[0] = 500; } if (!isset($imgSize[1]) || $imgSize[1] <= 0) { $imgSize[1] = $imgSize[0]; } // Almacenamos la imágen original if ($mc['saveoriginal']) { copy($fullpath, $mc['storedir'] . '/originals/' . $filename); } // Redimensionamos la imagen $redim = new RMImageResizer($fullpath, $fullpath); switch ($mc['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; } } //Fin de Imagen $img->setImage($filename); if ($up->getErrors() == '') { if (!$img->save()) { $errors .= sprintf(__('Picture %s could not be uploaded!', 'galleries'), $v) . " (" . $img->errors() . ")"; } else { $user->addPic(); if ($ret) { $img->setTags($ret); } } } else { $errors .= $up->getErrors(); } ++$k; } if ($errors != '') { redirect_header(GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/images' : '?cp=images'), 2, __('Errors ocurred while trying to upload images!', 'galleries') . $errors); die; } else { redirect_header(GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/images' : '?cp=images'), 2, __('Pictures stored successfully!', 'galleries')); die; } }