public function get_item_url($params, $com) { static $cimgs; static $csets; $params = urldecode($params); parse_str($params); include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsfunctions.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsimage.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gstag.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsset.class.php'; if (isset($set) && $set > 0) { if (isset($csets[$set])) { $ret = $csets[$set]->url() . '#comment-' . $com->id(); return $ret; } $sobj = new GSSet($set); if ($sobj->isNew()) { return ''; } $ret = $sobj->url() . '#comment-' . $com->id(); $csets[$set] = $sobj; return $ret; } elseif (isset($image) && $image > 0) { if (isset($cimgs[$image])) { $ret = $cimgs[$image]->permalink() . '#comment-' . $com->id(); return $ret; } $img = new GSImage($image); if ($img->isNew()) { return ''; } $ret = $img->permalink() . '#comment-' . $com->id(); $cimgs[$image] = $img; return $ret; } }
public function get_item($params, $com, $url = false) { static $cimgs; static $csets; $params = urldecode($params); parse_str($params); include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsfunctions.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsimage.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gstag.class.php'; include_once XOOPS_ROOT_PATH . '/modules/galleries/class/gsset.class.php'; if (isset($set) && $set > 0) { if (isset($csets[$set])) { $ret = '<a href="' . $csets[$set]->url() . '#comment-' . $com->id() . '">' . $csets[$set]->title() . '</a>'; return $ret; } $sobj = new GSSet($set); if ($sobj->isNew()) { return __('Unknow element', 'galleries'); } $ret = '<a href="' . $sobj->url() . '#comment-' . $com->id() . '">' . $sobj->title() . '</a>'; $csets[$set] = $sobj; return $ret; } elseif (isset($image) && $image > 0) { if (isset($cimgs[$image])) { $ret = '<a href="' . $cimgs[$image]->permalink() . '#comment-' . $com->id() . '">' . $cresources[$res]->getVar('title') . '</a>'; return $ret; } $img = new GSImage($image); if ($img->isNew()) { return __('Unknow element', 'docs'); } $ret = '<a href="' . $img->permalink() . '#comment-' . $com->id() . '">' . $img->title(true) . '</a>'; $cimgs[$image] = $img; return $ret; } }
/** * @desc Determina la página para la imágen especificada */ public function pageFromPic(GSImage &$pic, GSUser &$user, $set = 0) { global $xoopsModuleConfig; $db =& Database::getInstance(); $mc =& $xoopsModuleConfig; if ($pic->isNew()) { return; } if ($set > 0) { } else { // Determinar en que págona se ubica la imágen $result = $db->query("SELECT id_image FROM " . $db->prefix('gs_images') . " WHERE owner='" . $user->uid() . "' AND public='1' ORDER BY created DESC, modified DESC"); $num = $db->getRowsNum($result); for ($i = 0; $i < $num; ++$i) { list($cur_id) = $db->fetchRow($result); // echo $cur_id."<br />"; if ($cur_id == $pic->id()) { break; } } ++$i; // we started at 0 $limit = $mc['user_format_mode'] ? $mc['user_format_values'][3] : $mc['limit_pics']; return ceil($i / $limit); } }
function send_sets() { global $xoopsLogger, $xoopsModuleConfig; $xoopsLogger->renderingEnabled = false; error_reporting(0); $xoopsLogger->activated = false; $mc =& $xoopsModuleConfig; $db = Database::getInstance(); $limit = rmc_server_var($_GET, 'limit', 5); // recent pictures $sql = "SELECT * FROM " . $db->prefix("gs_sets") . " ORDER BY `date` DESC LIMIT 0,{$limit}"; $result = $db->query($sql); $sets = array(); $users = array(); while ($row = $db->fetchArray($result)) { $set = new GSSet(); $set->assignVars($row); $pics = $set->getPics('RAND()'); $img = new GSImage($pics[0]); if (!isset($users[$img->owner()])) { $users[$img->owner()] = new GSUser($img->owner(), 1); } if ($img->isNew()) { $image = array('title' => __('Empty album', 'galleries'), 'link' => '', 'thumbnail' => GS_URL . '/images/empty.jpg'); } else { $image = array('title' => $img->title(), 'link' => $users[$img->owner()]->userURL() . ($mc['urlmode'] ? 'img/' . $img->id() . '/' : '&img=' . $img->id()), 'thumbnail' => $users[$img->owner()]->filesURL() . '/ths/' . $img->image()); } $sets[] = array('title' => $set->title(), 'link' => $set->url(), 'image' => $image); } ob_start(); ?> <?php foreach ($sets as $set) { ?> <a href="<?php echo $set['link']; ?> " target="_blank" title="<?php echo $set['title']; ?> "><img src="<?php echo $set['image']['thumbnail']; ?> " alt="<?php echo $set['title']; ?> " /></a> <?php } ?> <?php $recents = ob_get_clean(); echo $recents; die; }
/** * @desc Busca la posición exacta de una etiqueta */ function browsePic() { global $usr, $mc, $xoopsModuleConfig, $xoopsConfig, $xoopsUser, $pag, $set, $browse; $mc =& $xoopsModuleConfig; $user = new GSUser($usr); if ($user->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries', 0, _MS_GS_ERRUSR); die; } $image = new GSImage($browse); if ($image->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries', 0, _MS_GS_ERRIMG); die; } if (isset($set)) { $set = new GSSet($set); if ($set->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries', 0, _MS_GS_ERRSET); die; } } $page = GSFunctions::pageFromPic($image, $user, $set > 0 ? $set : 0); header('location: ' . $user->userURL() . 'pag/' . $page); }
/** * @desc Visualiza la postal **/ function viewPostcard() { global $tpl, $xoopsModule, $xoopsModuleConfig, $xoopsModuleConfig, $mc, $xoopsUser, $id; include_once XOOPS_ROOT_PATH . '/class/template.php'; $tpl = new XoopsTpl(); $mc =& $xoopsModuleConfig; if (!$xoopsUser) { redirect_header(XOOPS_URL . '/user.php#register', 1, _MS_GS_ERRUSR); die; } //Verificamos si la postal existe $post = new GSPostcard($id); if ($post->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries/', 1, _MS_GS_ERRPOSTEXIST); die; } $img = new GSImage($post->image()); if ($img->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries/', 1, _MS_GS_ERRIMG); die; } $user = new GSUser($img->owner(), 1); $file = $user->filesPath() . '/' . $img->image(); list($ancho, $alto) = getimagesize($file); $tpl->assign('gs_url', XOOPS_URL . '/modules/galleries'); $tpl->assign('img', array('id' => $img->id(), 'width' => $ancho, 'height' => $alto, 'url' => $user->filesURL() . '/' . $img->image(), 'link' => $user->userURL() . 'img/' . $img->id() . '/')); $tpl->assign('title', $post->title()); $tpl->assign('message', $post->message()); $tpl->assign('lang_says', sprintf(_MS_GS_SAYS, $post->name())); $tpl->assign('xoops_pagetitle', sprintf(_MS_GS_PTITLE, $post->title()) . ' » ' . $mc['section_title']); $tpl->assign('lang_see', _MS_GS_SEE); $tpl->assign('user_link', $user->userURL() . 'browse/' . $img->id() . '/'); $tpl->assign('lang_seeuser', _MS_GS_SEEUSER); $tpl->assign('preview', 0); RMTemplate::get()->add_xoops_style('postcard.css', 'galleries'); //Actualizar datos de postal $post->setViewed(1); $post->save(); echo $tpl->fetch("db:gs_postcard.html"); }
/** * @desc Visualiza la postal **/ function viewPostcard() { global $tpl, $xoopsModule, $xoopsModuleConfig, $xoopsModuleConfig, $mc, $xoopsUser, $id; include_once XOOPS_ROOT_PATH . '/class/template.php'; $tpl = new XoopsTpl(); $mc =& $xoopsModuleConfig; //Verificamos si la postal existe $post = new GSPostcard($id); if ($post->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries/', 1, __('Specified E_Card does not exists!', 'galleries')); die; } $img = new GSImage($post->image()); if ($img->isNew()) { redirect_header(XOOPS_URL . '/modules/galleries/', 1, __('Sorry, there are some problems with this e-card!', 'galleries')); die; } $user = new GSUser($img->owner(), 1); $file = $user->filesPath() . '/' . $img->image(); list($ancho, $alto) = getimagesize($file); $tpl->assign('gs_url', XOOPS_URL . '/modules/galleries'); $tpl->assign('img', array('id' => $img->id(), 'width' => $ancho, 'height' => $alto, 'url' => $user->filesURL() . '/' . $img->image(), 'link' => $user->userURL() . 'img/' . $img->id() . '/')); $tpl->assign('title', $post->title()); $tpl->assign('message', $post->message()); $tpl->assign('lang_says', sprintf(__('%s says:'), $post->name())); $tpl->assign('xoops_pagetitle', sprintf(__('%s, E-Card', 'galleries'), $post->title()) . ' » ' . $mc['section_title']); $tpl->assign('lang_see', __('View Picture', 'galleries')); $tpl->assign('user_link', $user->userURL() . 'browse/' . $img->id() . '/'); $tpl->assign('lang_seeuser', __('View User Pictures', 'galleries')); $tpl->assign('preview', 0); RMTemplate::get()->add_xoops_style('postcard.css', 'galleries'); //Actualizar datos de postal $post->setViewed(1); $post->save(); echo $tpl->fetch("db:gs_postcard.html"); }
/** * @desc Elimina una imagen de favoritos **/ function deleteBookMarks() { global $xoopsUser, $xoopsModuleConfig; $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $page = isset($_REQUEST['pag']) ? $_REQUEST['pag'] : ''; $mc =& $xoopsModuleConfig; $link = GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/bookmarks/pag/' . $page . '/' : '?cp=bookmarks&pag=' . $page); //Verificamos si nos proporcionaron al menos un imagen para eliminar if (!is_array($ids)) { redirect_header($link, 2, __('You must select one picture at least!', 'galleries')); die; } if (!is_array($ids)) { $ids = array($ids); } $db = Database::getInstance(); $errors = ''; foreach ($ids as $k) { //Verificamos si la imagen sea válida if ($k <= 0) { $errors .= sprintf(__('ID %u is not valid!', 'galleries'), $k); continue; } //Verificamos si la imagen existe $img = new GSImage($k); if ($img->isNew()) { $errors .= sprintf(__('Image with id %u is not valid!', 'galleries'), $k); continue; } $sql = "DELETE FROM " . $db->prefix('gs_favourites') . " WHERE id_image='" . $k . "' AND uid='" . $xoopsUser->uid() . "'"; $result = $db->queryF($sql); if (!$result) { $errors .= sprintf(__('Favorite picture "%s" could not be deleted!', 'galleries'), $img->title()); } } if ($errors != '') { redirect_header($link, 2, __('Errors ocurred while trying to delete favorites!', 'galleries') . $errors); die; } else { redirect_header($link, 1, __('Favorites deleted successfully!', 'galleries')); die; } }
/** * @desc Publica o no publica las imágenes especificadas **/ function publicImages($pub = 0) { $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0; $ok = isset($_POST['ok']) ? $_POST['ok'] : 0; $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1; $limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 15; $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : ''; $owner = isset($_REQUEST['owner']) ? intval($_REQUEST['owner']) : ''; $sort = isset($_REQUEST['sort']) ? $_REQUEST['sort'] : 'created'; $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : 0; $ruta = "page={$page}&limit={$limit}&search={$search}&owner={$owner}&sort={$sort}&mode={$mode}"; //Verificamos si nos proporcionaron al menos una imagen if (!is_array($ids)) { redirectMsg('./images.php?' . $ruta, __('No images has been selected!', 'galleries'), 1); die; } $errors = ''; foreach ($ids as $k) { //Verificamos si la imagen es válida if ($k <= 0) { $errors .= sprintf(__('Image ID "%s" is not valid', 'galleries'), $k); continue; } //Verificamos si la imagen existe $img = new GSImage($k); if ($img->isNew()) { $errors .= sprintf(__('Image "%s" does not exists!', 'galleries'), $k); continue; } $img->setPublic($pub); if (!$img->save()) { $errors .= sprintf(__('Image could not be updated!', 'galleries'), $k); } } if ($erros != '') { redirectMsg('./images.php?' . $ruta, __('Errors ocurred while trying to update images!') . $errors, 1); die; } else { redirectMsg('./images.php?' . $ruta, __('Images updated successfully!', 'galleries'), 0); 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 asignación de albumes a las imágenes **/ function saveSets() { global $db, $xoopsUser, $xoopsConfig; foreach ($_POST as $k => $v) { ${$k} = $v; } $errors = ''; foreach ($ids as $k) { //Verificamos si la imagen es válida if ($k <= 0) { $errors .= sprintf(__('Picture with id %u is not valid!', 'galleries'), $k); continue; } //Verificamos si la imagen existe $img = new GSImage($k); if ($img->isNew()) { $errors .= sprintf(__('Picture with id %u does not exists!', 'galleries'), $k); continue; } if ($img->owner() != $xoopsUser->uid()) { $errors = sprintf(__('You don\'t have authorization!', 'galleries'), $k); continue; } $db = XoopsDatabaseFactory::getDatabaseConnection(); $sets = ''; $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 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); } if (!$referer) { $referer = GSFunctions::get_url(); } if ($errors != '') { redirect_header($referer, 2, __('Errors ocurred while trying to update picture!', 'galleries') . $errors); die; } else { redirect_header($referer, 2, __('Pictures updated successfully!', 'galleries')); die; } }