/** * Get image data */ public function process_image_data($result) { $mc = RMUtilities::module_config('galleries'); $users = array(); $ret = array(); $tf = new RMTimeFormatter(0, "%M%/%d%/%Y%"); $db = Database::getInstance(); $i = 0; while ($row = $db->fetchArray($result)) { $img = new GSImage(); $img->assignVars($row); if (!isset($users[$img->owner()])) { $users[$img->owner()] = new GSUser($img->owner(), 1); } $imglink = $users[$img->owner()]->userURL() . ($mc['urlmode'] ? 'img/' . $img->id() . '/' : '&img=' . $img->id()); $ret[$i] = array('id' => $img->id(), 'title' => $img->title(), 'thumbnail' => $users[$img->owner()]->filesURL() . '/ths/' . $img->image(), 'thumbuser' => $users[$img->owner()]->filesURL() . '/' . ($mc['user_format_mode'] ? 'formats/user_' : 'ths/') . $img->image(), 'thumbsrh' => $users[$img->owner()]->filesURL() . '/' . ($mc['search_format_mode'] ? 'formats/srh_' : 'ths/') . $img->image(), 'image' => $users[$img->owner()]->filesURL() . '/' . $img->image(), 'by' => sprintf(__('by %s', 'galleries'), '<a href="' . $users[$img->owner()]->userUrl() . '">' . $users[$img->owner()]->uname() . '</a>'), 'link' => $imglink, 'created' => $tf->format($img->created()), 'public' => $img->isPublic(), 'desc' => $img->desc()); // Format resize if (!$img->userFormat() && $mc['user_format_mode']) { $format = $mc['user_format_values']; GSFunctions::resizeImage($format[0], $users[$img->owner()]->filesPath() . '/' . $img->image(), $users[$img->owner()]->filesPath() . '/formats/user_' . $img->image(), $format[1], $format[2]); $img->setUserFormat(1, 1); } if (!$img->searchFormat() && $mc['search_format_mode']) { $format = $mc['search_format_values']; GSFunctions::resizeImage($format[0], $users[$img->owner()]->filesPath() . '/' . $img->image(), $users[$img->owner()]->filesPath() . '/formats/srh_' . $img->image(), $format[1], $format[2]); $img->setSearchFormat(1, 1); } if ($mc['search_format_mode']) { $ret[$i]['viewmore'] = sprintf(__('Ver <a href="%s">más fotos</a>.', 'galleries'), $users[$img->owner()]->userURL()); $ret[$i]['avatar'] = RMEvents::get()->run_event('rmcommon.get.avatar', $users[$img->owner()]->userVar('email'), 0, $users[$img->owner()]->userVar('user_avatar')); $tags = $img->tags(true); $tagurl = self::get_url() . ($mc['urlmode'] ? 'explore/tags/tag/' : '?explore=tags&tag='); $strtag = ''; foreach ($tags as $tag) { $strtag .= $strtag == '' ? "<a href=\"{$tagurl}" . $tag->getVar('nameid') . "\">" . $tag->tag() . "</a>" : ", <a href=\"{$tagurl}" . $tag->getVar('nameid') . "\">" . $tag->tag() . "</a>"; } $ret[$i]['tags'] = $strtag; } $i++; } RMTemplate::get()->add_local_script('photos.js', 'galleries'); if (!$mc['quickview']) { return $ret; } if (RMFunctions::plugin_installed('lightbox')) { RMLightbox::get()->add_element('.pic_qview a'); RMLightbox::get()->render(); } return $ret; }
/** * @desc Mostramos los detalles de una imágen */ function showImageDetails() { global $usr, $set, $img, $db, $xoopsModule, $mc, $xoopsModuleConfig, $xoopsConfig, $xoopsUser, $xoopsOption, $tpl; $user = new GSUser($usr); if ($user->isNew()) { redirect_header(GSFunctions::get_url(), 0, __('Specified user does not exists!', 'galleries')); die; } $image = new GSImage($img); if ($image->isNew()) { redirect_header(GSFunctions::get_url(), 0, __('Specified image does not exists!', 'galleries')); die; } $user = new GSUser($image->owner(), 1); //Verificamos la privacidad de la imagen if (!$image->isPublic()) { //Privada, Verificamos si el usuario es el dueño de la imagen if (!$xoopsUser || $xoopsUser->uid() != $image->owner()) { redirect_header(GSFunctions::get_url(), 1, __('You can not view this image!', 'galleries')); die; } } else { if ($image->isPublic() == 1) { //Privada y amigos if (!$xoopsUser || $xoopsUser->uid() != $image->owner()) { //Verificamos si es un amigo if (!$xoopsUser || !$user->isFriend($xoopsUser->uid())) { redirect_header(GSFunctions::get_url(), 1, __('You are not authorized to view this image!', 'galleries')); die; } } } } //Incrementamos las vistas de la imagen $image->addViews(); if (isset($set)) { $set = new GSSet($set); if ($set->isNew()) { redirect_header(GSFunctions::get_url(), 0, __('Specified album does not exists!', 'galleries')); die; } } if ($image->desc() != '') { global $xoTheme; $xoTheme->addMeta('meta', 'description', $image->desc()); } $xoopsOption['template_main'] = 'gs_imgdetails.html'; $xoopsOption['module_subpage'] = 'picsdetails'; include 'header.php'; GSFunctions::makeHeader(); $tpl->assign('user', array('id' => $user->id(), 'uname' => $user->uname(), 'link' => $user->userURL(), 'avatar' => $user->userVar('user_avatar') != '' ? XOOPS_URL . '/uploads/avatars/' . $user->userVar('user_avatar') : GS_URL . '/images/avatar.png')); $tpl->assign('user_link', $user->userURL()); $tpl->assign('lang_alsobelong', __('Also belongs to:', 'galleries')); $tpl->assign('lang_postcards', __('Send postcard', 'galleries')); $tpl->assign('lang_bookmark', __('+ Bookmark', 'galleries')); $tpl->assign('lang_photos', __('Pictures', 'galleries')); $tpl->assign('lang_toset', __('+ to Album', 'galleries')); $tpl->assign('lang_lastpic', __('This is the last picture', 'galleries')); $tpl->assign('lang_firstpic', __('This is the first picture', 'galleries')); $tpl->assign('toset_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/toset/ids/' . $image->id() . '/referer/' . base64_encode(RMFunctions::current_url()) . '/' : '?cp=toset&ids=' . $image->id() . '&referer=' . base64_encode(RMFunctions::current_url()))); $tpl->assign('edit_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/edit/id/' . $image->id() . '/referer/' . base64_encode(RMFunctions::current_url()) . '/' : '?cp=edit&id=' . $image->id() . '&referer=' . base64_encode(RMFunctions::current_url()))); $tpl->assign('bookmark_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/bookmarks/add/' . $image->id() . '/referer/' . base64_encode($_SERVER['REQUEST_URI']) : '?cpanel=bookmarks&add=' . $image->id() . '&referer=' . base64_encode($_SERVER['REQUEST_URI']))); $tpl->assign('postcard_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'postcard/new/img/' . $image->id() . '/' : '?postcard=new&img=' . $image->id())); $tpl->assign('delete_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/delete/referer/' . base64_encode(RMFunctions::current_url()) . '/ids/' : '?cpanel=delete&referer=' . base64_encode(RMFunctions::current_url()) . '&ids=')); $tpl->assign('lang_confirmdel', sprintf(__('Dow you really want to delete this picture?\\n(%s)', 'galleries'), $image->title())); if ($xoopsUser && $xoopsUser->uid() == $image->owner()) { $tpl->assign('lang_edit', __('Edit', 'galleries')); $tpl->assign('lang_delete', __('Delete', 'galleries')); $tpl->assign('isowner', 1); } $tpl->assign('postcards', $mc['postcards']); $data = getimagesize($user->filesURL() . '/' . $image->image()); $tpl->assign('image', array('title' => $image->title(), 'id' => $image->id(), 'file' => $user->filesURL() . '/' . $image->image(), 'desc' => $image->desc(), 'width' => $data[0] + 2, 'height' => $data[1] + 2)); unset($data); //Verificamos si el usuario es dueño o amigo if ($xoopsUser && $xoopsUser->uid() == $user->uid()) { $public = ''; } else { if ($xoopsUser && $user->isFriend($xoopsUser->uid())) { $public = " AND public<>'0'"; } else { $public = " AND public='2'"; } } // Imágenes anterior y siguiente if (!isset($set)) { // Navigation as images if ($xoopsModuleConfig['navimages']) { $limit_n = $xoopsModuleConfig['navimages_num']; $limit_p = $xoopsModuleConfig['navimages_num']; // Count images $sql = "SELECT * FROM " . $db->prefix("gs_images") . " WHERE id_image>'" . $image->id() . "' AND owner='" . $user->uid() . "' {$public} ORDER BY id_image ASC LIMIT 0," . $xoopsModuleConfig['navimages_num']; $resultn = $db->query($sql); if ($db->getRowsNum($resultn) < $xoopsModuleConfig['navimages_num']) { $limit_p = $limit_p + ($xoopsModuleConfig['navimages_num'] - $db->getRowsNum($resultn)); } $sql = "SELECT * FROM " . $db->prefix("gs_images") . " WHERE id_image<'" . $image->id() . "' AND owner='" . $user->uid() . "' {$public} ORDER BY id_image DESC, created DESC LIMIT 0," . $limit_p; $resultp = $db->query($sql); if ($db->getRowsNum($resultp) < $xoopsModuleConfig['navimages_num']) { $limit_n = $limit_n + ($xoopsModuleConfig['navimages_num'] - $db->getRowsNum($resultp)); } if ($limit_n > $db->getRowsNum($resultn) && $limit_p == $xoopsModuleConfig['navimages_num']) { $sql = "SELECT * FROM " . $db->prefix("gs_images") . " WHERE id_image>'" . $image->id() . "' AND owner='" . $user->uid() . "' {$public} ORDER BY id_image ASC LIMIT 0," . $limit_n; $resultn = $db->query($sql); } // Previous Images while ($row = $db->fetchArray($resultp)) { $pn = new GSImage(); $pn->assignVars($row); $previous_images[] = array('link' => $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'img/' . $pn->id() . '/' : '&img=' . $pn->id()), 'id' => $pn->id(), 'title' => $pn->title(), 'file' => $user->filesURL() . '/ths/' . $pn->image()); } // Next Images while ($row = $db->fetchArray($resultn)) { $pn = new GSImage(); $pn->assignVars($row); $next_images[] = array('link' => $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'img/' . $pn->id() . '/' : '&img=' . $pn->id()), 'id' => $pn->id(), 'title' => $pn->title(), 'file' => $user->filesURL() . '/ths/' . $pn->image()); } } $tpl->assign('prevnext_title', sprintf(__('Pictures of %s'), $user->uname())); $tpl->assign('xoops_pagetitle', $image->title() . ' » ' . sprintf(__('Pictures of %s'), $user->uname()) . ' » ' . $xoopsModuleConfig['section_title']); $tpl->assign('title_link', $user->userURL()); $result = $db->query("SELECT COUNT(*) FROM " . $db->prefix("gs_images") . " WHERE owner='" . $user->uid() . "' {$public}"); list($num) = $db->fetchRow($result); $tpl->assign('pics_count', $num); // Tambien pertenece $tbl1 = $db->prefix("gs_sets"); $tbl2 = $db->prefix("gs_setsimages"); $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_image='" . $image->id() . "' AND a.id_set=b.id_set"; $result = $db->query($sql); while ($row = $db->fetchArray($result)) { $oset = new GSSet(); $oset->assignVars($row); //Verificamos la privacidad del album if (!$oset->ispublic()) { if (!$xoopsUser) { continue; } if ($xoopsUser->uid() != $oset->owner()) { continue; } } else { if (!$xoopsUser && $oset->isPublic() == 1 && !$user->isFriend($xoopsUser->uid())) { continue; } } $tpl->append('sets', array('id' => $oset->id(), 'title' => $oset->title(), 'link' => $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'set/' . $oset->id() . '/' : '&set=' . $oset->id()))); } } else { // Imágen Siguiente $tbl1 = $db->prefix("gs_images"); $tbl2 = $db->prefix("gs_setsimages"); // Navigation as images if ($xoopsModuleConfig['navimages']) { $limit_n = $xoopsModuleConfig['navimages_num']; $limit_p = $xoopsModuleConfig['navimages_num']; // Count images $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image AND a.id_image>'" . $image->id() . "' AND a.owner='" . $user->uid() . "' {$public} ORDER BY a.id_image ASC LIMIT 0," . $xoopsModuleConfig['navimages_num']; $resultn = $db->query($sql); if ($db->getRowsNum($resultn) < $xoopsModuleConfig['navimages_num']) { $limit_p = $limit_p + ($xoopsModuleConfig['navimages_num'] - $db->getRowsNum($resultn)); } $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image AND a.id_image<'" . $image->id() . "' AND a.owner='" . $user->uid() . "' {$public} ORDER BY a.id_image DESC LIMIT 0,{$limit_p}"; $resultp = $db->query($sql); if ($db->getRowsNum($resultp) < $xoopsModuleConfig['navimages_num']) { $limit_n = $limit_n + ($xoopsModuleConfig['navimages_num'] - $db->getRowsNum($resultp)); } if ($limit_n > $db->getRowsNum($resultn) && $limit_p == $xoopsModuleConfig['navimages_num']) { $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image AND a.id_image>'" . $image->id() . "' AND a.owner='" . $user->uid() . "' {$public} ORDER BY a.id_image ASC LIMIT 0," . $limit_n; $resultn = $db->query($sql); } // Previous Images while ($row = $db->fetchArray($resultp)) { $pn = new GSImage(); $pn->assignVars($row); $previous_images[] = array('link' => $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'img/' . $pn->id() . '/set/' . $set->id() . '/' : '&img=' . $pn->id() . '&set=' . $set->id()), 'id' => $pn->id(), 'title' => $pn->title(), 'file' => $user->filesURL() . '/ths/' . $pn->image()); } // Next Images while ($row = $db->fetchArray($resultn)) { $pn = new GSImage(); $pn->assignVars($row); $next_images[] = array('link' => $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'img/' . $pn->id() . '/set/' . $set->id() . '/' : '&img=' . $pn->id() . '&set=' . $set->id()), 'id' => $pn->id(), 'title' => $pn->title(), 'file' => $user->filesURL() . '/ths/' . $pn->image()); } } $tpl->assign('prevnext_title', sprintf(__('Pictures in %s', 'galleries'), $set->title())); $tpl->assign('xoops_pagetitle', $image->title() . ' » ' . sprintf(__('Pictures in %s'), $set->title()) . ' » ' . $xoopsModuleConfig['section_title']); $tpl->assign('title_link', $user->userURL() . ($xoopsModuleConfig['urlmode'] ? 'set/' . $set->id() . '/' : '&set=' . $set->id())); $result = $db->query("SELECT COUNT(*) FROM {$tbl1} a, {$tbl2} b WHERE b.id_set='" . $set->id() . "' AND a.id_image=b.id_image AND a.owner='" . $user->uid() . "' {$public}"); list($num) = $db->fetchRow($result); $tpl->assign('pics_count', $num); // Tambien pertenece $tbl1 = $db->prefix("gs_sets"); $sql = "SELECT a.* FROM {$tbl1} a, {$tbl2} b WHERE b.id_set<>'" . $set->id() . "' AND b.id_image='" . $image->id() . "' AND a.id_set=b.id_set"; $result = $db->query($sql); $tpl->append('sets', array('id' => 0, 'title' => sprintf(__('Galleries of %s', 'galleries'), $user->uname()), 'link' => $user->userURL())); while ($row = $db->fetchArray($result)) { $oset = new GSSet(); $oset->assignVars($row); //Verificamos la privacidad del album if (!$oset->ispublic()) { if (!$xoopsUser) { continue; } if ($xoopsUser->uid() != $oset->owner()) { continue; } } else { if (!$xoopsUser && $oset->isPublic() == 1 && !$user->isFriend($xoopsUser->uid())) { continue; } } $tpl->append('sets', array('id' => $oset->id(), 'title' => $oset->title(), 'link' => $user->userURL() . 'set/' . $oset->id(), '/')); } } if (!empty($previous_images)) { $tpl->assign('prev', $previous_images[0]); $tpl->assign('previous_images', array_reverse($previous_images)); } else { $tpl->assign('is_first', 1); } if (!empty($next_images)) { $tpl->assign('next', $next_images[0]); $tpl->assign('next_images', $next_images); } else { $tpl->assign('is_last', 1); } $tpl->assign('current_image', array('title' => $image->title(), 'file' => $user->filesURL() . '/ths/' . $image->image())); // Etiquetas $tags = $image->tags(true, '*'); $link = GSFunctions::get_url() . ($mc['urlmode'] ? 'explore/tags/tag/' : "?explore=tags&tag="); foreach ($tags as $tag) { $tpl->append('tags', array('id' => $tag->id(), 'tag' => $tag->tag(), 'link' => $link . $tag->getVar('nameid'))); } // Comentarios $tpl->assign('users_link', GSFunctions::get_url() . ($mc['urlmode'] ? 'usr/' : '?usr='******'galleries', 'image=' . $image->id()); // Comments form RMFunctions::comments_form('galleries', 'image=' . $image->id(), 'module', GS_PATH . '/class/galleriescontroller.php'); include 'footer.php'; }
/** * @desc Marca Imagen como favorita **/ function addBookMarks() { global $xoopsUser, $add, $xoopsModuleConfig, $referer; $mc =& $xoopsModuleConfig; $referer = base64_decode($referer); if (!$referer) { $referer = GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/bookmarks/' : '?cp=bookmarks'); } //Verificamos que la imagen sea válida if ($add <= 0) { redirect_header($referer, 1, __('Image id is not valid!', 'galleries')); die; } //Verificamos que la imagen exista $img = new GSImage($add); if ($img->isNew()) { redirect_header($referer, 1, __('Specified image does not exists!', 'galleries')); die; } //Verificamos que la imagen sea pública o de amigos if ($img->isPublic() == 0) { redirect_header($referer, 1, __('You don\'t have authorization to view this picture!', 'galleries')); die; } $user = new GSUser($img->owner(), 1); //Verificamos si el usuario es amigo del dueño de la imagen if ($img->isPublic() == 1) { if (!$user->isFriend($xoopsUser->uid())) { redirect_header($referer, 1, __('You must be a friend of this user in order to view this picture!', 'galleries')); die; } } $db = Database::getInstance(); //Verificamos si la imagen se encuentra ya registrada en favoritos $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_favourites') . " WHERE uid='" . $xoopsUser->uid() . "' AND id_image='" . $img->id() . "'"; list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirect_header($referer, 1, __('This picture already is in your favorites', 'galleries')); die; } //Agregamos la imagen a favoritos $sql = "INSERT INTO " . $db->prefix('gs_favourites') . " (`uid`,`id_image`) VALUES ('" . $xoopsUser->uid() . "','" . $img->id() . "')"; $result = $db->queryF($sql); if (!$result) { redirect_header($referer, 1, __('Picture could not be added to your favorites!', 'galleries')); die; } else { redirect_header($referer, 1, __('Picture added to your favorites successfully!', 'galleries')); die; } }
// Álbumes Recientes $result = $db->query("SELECT * FROM " . $db->prefix("gs_sets") . " WHERE public='2' ORDER BY date DESC LIMIT 0," . ($mc['sets_num'] > 0 ? $mc['sets_num'] : 5)); while ($row = $db->fetchArray($result)) { $set = new GSSet(); $set->assignVars($row); $pics = $set->getPics('RAND()'); $imgs = @array_slice($pics, 0, $xoopsModuleConfig['sets_num_images']); if (!isset($users[$set->owner()])) { $users[$set->owner()] = new GSUser($set->owner(), 1); } $images = array(); if (!empty($imgs)) { // Obtenemos las primeras 4 imágenes foreach ($imgs as $k) { $img = new GSImage($k); if ($img->isPublic() != 2) { continue; } if (!isset($users[$img->owner()])) { $users[$img->owner()] = new GSUser($img->owner(), 1); } $imglink = $users[$img->owner()]->userURL() . 'img/' . $img->id() . '/'; $images[] = array('id' => $img->id(), 'title' => $img->title(), 'thumbnail' => $users[$img->owner()]->filesURL() . '/ths/' . $img->image(), 'image' => $users[$img->owner()]->filesURL() . '/' . $img->image(), 'by' => sprintf(__('by %s', 'galleries'), '<a href="' . $users[$img->owner()]->userUrl() . '">' . $users[$img->owner()]->uname() . '</a>'), 'link' => $imglink); } } $tpl->append('sets', array('id' => $set->id(), 'title' => $set->title(), 'images' => $images, 'link' => $users[$set->owner()]->userUrl() . ($mc['urlmode'] ? 'set/' . $set->id() : '&set=' . $set->id()), 'date' => formatTimestamp($set->date(), 'c'), 'by' => '<a href="' . $users[$set->owner()]->userUrl() . '">' . $users[$set->owner()]->uname() . '</a>', 'picsnum' => count($pics))); } $result = $db->query("SELECT * FROM " . $db->prefix("gs_sets") . " WHERE public='2' ORDER BY date DESC LIMIT {$mc['sets_num']}," . ($mc['sets_num'] > 0 ? $mc['sets_num'] : 5)); while ($row = $db->fetchArray($result)) { $set = new GSSet(); $set->assignVars($row);
/** * @desc Formulario de creación/edición de imágenes **/ function formImages($edit = 0) { global $xoopsModule, $mc, $xoopsUser, $db; $id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1; $limit = isset($_REQUEST['limit']) ? intval($_REQUEST['limit']) : 10; $search = isset($_REQUEST['search']) ? $_REQUEST['search'] : ''; $owner = isset($_REQUEST['owner']) ? $_REQUEST['owner'] : ''; $uid = isset($_REQUEST['uid']) ? intval($_REQUEST['uid']) : 0; $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}"; if ($edit) { //Verificamos si la imagen es válida if ($id <= 0) { redirectMsg('./images.php?' . $ruta, __('Image ID not valid!', 'galleries'), 1); die; } //Verificamos si la imagen existe $img = new GSImage($id); if ($img->isNew()) { redirectMsg('./images.php?' . $ruta, __('Specified image does not exists!', 'galleries'), 1); die; } } GSFunctions::toolbar(); xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> » <a href='./images.php'>" . __('Images', 'galleries') . "</a> » " . ($edit ? __('Edit image', 'galleries') : __('Add image', 'galleries'))); xoops_cp_header(); $form = new RMForm($edit ? __('Editing image', 'galleries') : __('Add image', 'galleries'), 'frmimg', 'images.php'); $form->setExtra("enctype='multipart/form-data'"); if (!$edit) { $ele = new RMFormUser(__('User', 'galleries'), 'uid', 0, $uid ? array($uid) : ($edit ? array($img->owner()) : array($xoopsUser->uid())), 50); $ele->onChange("\$('op').value='" . ($edit ? 'edit' : 'new') . "'; \$('frmimg').submit();"); $form->addElement($ele); } else { $xu = new XoopsUser($img->owner()); $form->addElement(new RMFormLabel(__('User', 'galleries'), $xu->uname())); $form->addElement(new RMFormHidden('uid', $img->owner())); } $form->addElement(new RMFormText(__('Title', 'galleries'), 'title', 50, 100, $edit ? $img->title() : '')); $form->addElement(new RMFormFile(__('Image file', 'galleries'), 'image', 45, $mc['size_image'] * 1024)); if ($edit) { $user = new GSUser($img->owner(), 1); $url = $user->filesURL(); $form->addElement(new RMFormLabel(__('Current image', 'galleries'), "<img src='" . $url . "/ths/" . $img->image() . "' />")); } $form->addElement(new RMFormTextArea(__('Description', 'galleries'), 'desc', 4, 50, $edit ? $img->desc() : '')); $ele = new RMFormSelect(__('Privacy', 'galleries'), 'public'); $ele->addOption(0, __('Private', 'galleries'), $edit ? $img->isPublic() == 0 ? 1 : 0 : 0); $ele->addOption(1, __('Visible for friends', 'galleries'), $edit ? $img->isPublic() == 1 ? 1 : 0 : 0); $ele->addOption(2, __('Visible for all', 'galleries'), $edit ? $img->isPublic() == 2 ? 1 : 0 : 1); $form->addElement($ele, true); $db = Database::getInstance(); //Albumes if ($edit) { $albums = $img->sets(false); foreach ($albums as $k => $v) { $sets[] = $v['id_set']; } } $ele = new RMFormSelect(__('Albums', 'galleries'), 'albums[]', 1, $edit ? $sets : ''); $sql = "SELECT * FROM " . $db->prefix('gs_sets') . " WHERE owner='" . ($uid ? $uid : ($edit ? $img->owner() : $xoopsUser->uid())) . "'"; $result = $db->query($sql); while ($rows = $db->fetchArray($result)) { $ele->addOption($rows['id_set'], $rows['title']); } $form->addElement($ele); $ele = new RMFormText(__('Tags', 'galleries'), 'tags', 50, 100, $edit ? implode(", ", $img->tags(false, 'tag')) : ''); $ele->setDescription(__('Separate each tag with a comma (,)', 'galleries')); $form->addElement($ele, true); $form->addElement(new RMFormHidden('op', $edit ? 'saveedit' : 'save')); if ($edit) { $form->addElement(new RMFormHidden('id', $id)); } $form->addElement(new RMFormHidden('page', $page)); $form->addElement(new RMFormHidden('limit', $limit)); $form->addElement(new RMFormHidden('search', $search)); $form->addElement(new RMFormHidden('owner', $owner)); $form->addElement(new RMFormHidden('sort', $sort)); $form->addElement(new RMFormHidden('mode', $mode)); $buttons = new RMFormButtonGroup(); $buttons->addButton('sbt', $edit ? __('Save changes', 'galleries') : __('Add image', 'galleries'), 'submit'); $buttons->addButton('cancel', __('Cancel', 'galleries'), 'button', 'onclick="window.location=\'images.php?' . $ruta . '\'"'); $form->addElement($buttons); $form->display(); xoops_cp_footer(); }
/** * @desc Formulario de imágenes **/ function formImages($edit = 0) { global $xoopsOption, $tpl, $db, $xoopsUser, $xoopsModuleConfig, $xoopsUser, $xoopsConfig, $id, $referer, $page; $mc =& $xoopsModuleConfig; if (!$referer) { $referer = GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/images/pag/' . $page . '/' : '?cp=images&pag=' . $page); } else { $referer = base64_decode($referer); } if ($edit) { //Verificamos si la imagen es válida 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; } } $xoopsOption['template_main'] = 'gs_formpics.html'; include 'header.php'; GSFunctions::makeHeader(); $form = new RMForm($edit ? __('Edit Image', 'galleries') : __('New Image', 'galleries'), 'frmimg', GSFunctions::get_url() . ($mc['urlmode'] ? 'cp/saveedit/' : '?cp=saveedit')); $form->setExtra("enctype='multipart/form-data'"); $form->addElement(new RMFormText(__('Image title', 'galleries'), 'title', 50, 100, $edit ? $img->title(false) : '')); if ($edit) { $user = new GSUser($img->owner(), 1); $url = $user->filesURL(); $form->addElement(new RMFormLabel(__('Current picture', 'galleries'), "<img src='" . $url . "/ths/" . $img->image() . "' />")); } else { $form->addElement(new RMFormFile(__('Image file', 'galleries'), 'image', 45, $mc['size_image'] * 1024)); } $form->addElement(new RMFormTextArea(__('Description', 'galleries'), 'desc', 4, 50, $edit ? $img->desc() : '')); $ele = new RMFormSelect(__('Access level', 'galleries'), 'public'); $ele->addOption(0, __('Private', 'galleries'), $edit ? $img->isPublic() == 0 ? 1 : 0 : 0); $ele->addOption(1, __('Public for friends', 'galleries'), $edit ? $img->isPublic() == 1 ? 1 : 0 : 0); $ele->addOption(2, __('Public for all', 'galleries'), $edit ? $img->isPublic() == 2 ? 1 : 0 : 0); $form->addElement($ele, true); //Albumes if ($edit) { $albums = $img->sets(false); foreach ($albums as $k => $v) { $sets[] = $v['id_set']; } } $ele = new RMFormSelect(__('Albums', 'galleries'), 'albums[]', 1, $edit ? $sets : ''); $sql = "SELECT * FROM " . $db->prefix('gs_sets') . " WHERE owner='" . $xoopsUser->uid() . "'"; $result = $db->query($sql); while ($rows = $db->fetchArray($result)) { $ele->addOption($rows['id_set'], $rows['title']); } $form->addElement($ele); $ele = new RMFormText(__('Tags', 'galleries'), 'tags', 50, 255, $edit ? implode(", ", $img->tags(false, 'tag')) : ''); $ele->setDescription(__('Separe each tag with commas.', 'galleries')); $form->addElement($ele, true); $form->addElement(new RMFormHidden('op', $edit ? 'saveedit' : 'save')); $form->addElement(new RMFormHidden('id', $id)); $form->addElement(new RMFormHidden('page', $page)); $form->addElement(new RMFormHidden('referer', $referer)); $buttons = new RMFormButtonGroup(); $buttons->addButton('sbt', $edit ? __('Save Changes', 'galleries') : __('Create Image', 'galleries'), 'submit'); $buttons->addButton('cancel', __('Cancel', 'galleries'), 'button', 'onclick="window.location=\'' . $referer . '\'"'); $form->addElement($buttons); $tpl->assign('form_pics', $form->render()); createLinks(); RMTemplate::get()->add_style('panel.css', 'galleries'); include 'footer.php'; }