示例#1
0
/**
* @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;
}
示例#2
0
/**
* @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;
    }
}
示例#3
0
/**
* @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;
    }
}
示例#4
0
/**
* @desc Almacena la información de la etiqueta en la base de datos
**/
function saveTags($edit = 0)
{
    global $xoopsModuleConfig, $xoopsSecurity;
    $mc =& $xoopsModuleConfig;
    $db = Database::getInstance();
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $ruta = "&pag={$page}&search={$search}";
    if (!$xoopsSecurity->check()) {
        redirectMsg('./tags.php?' . $ruta, __('Session token expired!', 'galleries'), 1);
        die;
    }
    if ($edit) {
        $errors = '';
        foreach ($tags as $k => $v) {
            $v = trim($v);
            if (!$v) {
                continue;
            }
            //Verificamos el tamaño máximo y mínimo de la etiqueta
            if (strlen($v) < $mc['min_tag'] || strlen($v) > $mc['max_tag']) {
                $errors .= sprintf(__('Tag "%s" does not have the correct length!', 'galleries'), $v);
                continue;
            }
            //Verificamos que la etiqueta no exista
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_tags') . " WHERE tag='{$v}' AND id_tag<>{$k}";
            list($num) = $db->fetchRow($db->query($sql));
            if ($num > 0) {
                $errors .= sprintf(__('There are another tag with name "%s" already registered!', 'galleries'), $v);
                continue;
            }
            //Verificamos si la etiqueta es válida
            if ($k <= 0) {
                $errors .= sprintf(__('ID "%s" is not valid', 'galleries'), $k);
                continue;
            }
            //Verificamos si la etiqueta existe
            $tag = new GSTag($k);
            if ($tag->isNew()) {
                $errors .= sprintf('Tag "%s" does not exists', $v);
                continue;
            }
            $tag->setTag(strtolower($v));
            if (!$tag->save()) {
                $errors .= sprintf(__('Errors while trying to save tag "%s"', 'galleries'), $v);
            }
        }
    } else {
        $errors = '';
        foreach ($tags as $k => $v) {
            $v = trim($v);
            if (!$v) {
                continue;
            }
            //Verificamos el tamaño máximo y mínimo de la etiqueta
            if (strlen($v) < $mc['min_tag'] || strlen($v) > $mc['max_tag']) {
                $errors .= sprintf(__('Tag "%s" does not have the correct length!', 'galleries'), $v);
                continue;
            }
            //Verificamos que la etiqueta no exista
            $sql = "SELECT COUNT(*) FROM " . $db->prefix('gs_tags') . " WHERE tag='{$v}'";
            list($num) = $db->fetchRow($db->query($sql));
            if ($num > 0) {
                $errors .= sprintf(__('There are another tag with name "%s" already registered!', 'galleries'), $v);
                continue;
            }
            $tag = new GSTag();
            $tag->setTag(strtolower($v));
            if (!$tag->save()) {
                $errors .= sprintf(__('Errors while trying to save tag "%s"', 'galleries'), $v);
            }
        }
    }
    if ($errors != '') {
        redirectMsg('./tags.php?' . $ruta, __('Errors ocurred while trying to save tags.', 'galleries') . '<br />' . $errors, 1);
        die;
    } else {
        redirectMsg('./tags.php?' . $ruta, __('Tags saved successfully!', 'galleries'), 0);
        die;
    }
}