Пример #1
0
/**
* @desc Almacena información de las pantallas en la base de datos
**/
function saveScreens($edit = 0)
{
    global $db, $xoopsModuleConfig, $util;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$util->validateToken()) {
        if (!$edit) {
            redirectMsg('./screens.php?op=new&item=' . $item, _AS_DT_SESSINVALID, 1);
            die;
        } else {
            redirectMsg('./screens.php?op=edit&id=' . $id . '&item=' . $item, _AS_DT_SESSINVALID, 1);
            die;
        }
    }
    //Verificamos que el software sea válido
    if ($item <= 0) {
        redirectMsg('./screens.php', _AS_DT_ERR_ITEMVALID, 1);
        die;
    }
    //Verificamos que el software exista
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        redirectMsg('./screens.php', _AS_DT_ERR_ITEMEXIST, 1);
        die;
    }
    //Verificamos el limite de pantallas a almacenar
    if ($xoopsModuleConfig['limit_screen'] <= $sw->screensCount()) {
        redirectMsg('./screens.php?item=' . $item, _AS_DT_ERRCOUNT, 1);
        die;
    }
    if ($edit) {
        //Verificamos si pantalla es válida
        if ($id <= 0) {
            redirectMsg('./screens.php?item=' . $item, _AS_DT_ERR_SCVALID, 1);
            die;
        }
        //Verificamos que la pantalla exista
        $sc = new DTScreenshot($id);
        if ($sc->isNew()) {
            redirectMsg('./screens.php?item=' . $item, _AS_DT_ERR_SCEXIST, 1);
            die;
        }
        //Comprueba que el título de la pantalla no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_screens') . " WHERE title='{$title}' AND id_soft=" . $item . "id_screen<>" . $sc->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirectMsg('./screens.php?item=' . $item, _AS_DT_ERRNAME, 1);
            die;
        }
    } else {
        //Comprueba que el título de la pantalla no exista
        $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_screens') . " WHERE title='{$title}' AND id_soft={$item}";
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirectMsg('./screens.php?item=' . $item, _AS_DT_ERRNAME, 1);
            die;
        }
        $sc = new DTScreenshot();
    }
    $sc->setTitle($title);
    $sc->setDesc(substr($desc, 0, 255));
    $sc->setModified(time());
    $sc->setSoftware($item);
    //Imagen
    include_once XOOPS_ROOT_PATH . '/rmcommon/uploader.class.php';
    $up = new RMUploader(true);
    $folder = XOOPS_UPLOAD_PATH . '/dtransport';
    $folderths = XOOPS_UPLOAD_PATH . '/dtransport/ths';
    if ($edit) {
        $filename = $sc->image();
    } else {
        $filename = '';
    }
    $up->prepareUpload($folder, array($up->getMIME('jpg'), $up->getMIME('png'), $up->getMIME('gif')), $xoopsModuleConfig['image'] * 1024);
    //tamaño
    if ($up->fetchMedia('image')) {
        if (!$up->upload()) {
            if ($sc->isNew()) {
                redirectMsg('./screens.php?op=new&item=' . $item, $up->getErrors(), 1);
                die;
            } else {
                redirectMsg('./screens.php?op=edit&item=' . $item . '&id=' . $id, $up->getErrors(), 1);
                die;
            }
        }
        if ($edit && $sc->image() != '') {
            @unlink(XOOPS_UPLOAD_PATH . '/dtransport/' . $sc->image());
            @unlink(XOOPS_UPLOAD_PATH . '/dtransport/ths/' . $sc->image());
        }
        $filename = $up->getSavedFileName();
        $fullpath = $up->getSavedDestination();
        // Redimensionamos la imagen
        $redim = new RMImageControl($fullpath, $fullpath);
        switch ($xoopsModuleConfig['redim_image']) {
            case 0:
                //Recortar miniatura
                $redim->resizeWidth($xoopsModuleConfig['nscreen']);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($xoopsModuleConfig['thscreen'], $xoopsModuleConfig['thscreen']);
                break;
            case 1:
                //Recortar imagen grande
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($xoopsModuleConfig['thscreen']);
                $redim->setTargetFile($fullpath);
                $redim->resizeAndCrop($xoopsModuleConfig['nscreen'], $xoopsModuleConfig['nscreen']);
                break;
            case 2:
                //Recortar ambas
                $redim->resizeAndCrop($xoopsModuleConfig['nscreen'], $xoopsModuleConfig['nscreen']);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeAndCrop($xoopsModuleConfig['thscreen'], $xoopsModuleConfig['thscreen']);
                break;
            case 3:
                //Redimensionar
                $redim->resizeWidth($xoopsModuleConfig['nscreen']);
                $redim->setTargetFile($folderths . "/{$filename}");
                $redim->resizeWidth($xoopsModuleConfig['thscreen']);
                break;
        }
    }
    $sc->setImage($filename);
    if (!$sc->save()) {
        if ($sc->isNew()) {
            redirectMsg('./screens.php?op=new&item=' . $item, _AS_DT_DBERROR, 1);
            die;
        } else {
            redirectMsg('./screens.php?op=edit&item=' . $item . '&id=' . $id, _AS_DT_DBERROR, 1);
            die;
        }
    } else {
        redirectMsg('./screens.php?item=' . $item, _AS_DT_DBOK, 0);
        die;
    }
}
Пример #2
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;
    }
}