Ejemplo n.º 1
0
function dt_upload_screenshots()
{
    global $xoopsSecurity;
    $item = rmc_server_var($_REQUEST, 'item', 0);
    $data = rmc_server_var($_REQUEST, 'data', '');
    $rmu = RMUtilities::get();
    $mc = $rmu->module_config('dtransport');
    $tc = TextCleaner::getInstance();
    $data = explode("|", $tc->decrypt($data));
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $ses = new XoopsSessionHandler($db);
    session_decode($ses->read($data[1]));
    $_SERVER['HTTP_USER_AGENT'] = trim($data[0]);
    if (!$xoopsSecurity->check(false)) {
        error(__('Session token not valid!', 'dtransport'));
    }
    if ($item <= 0) {
        error(__('Download item ID not provided!', 'dtransport'));
    }
    require_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtsoftware.class.php';
    $sw = new DTSoftware($item);
    if ($sw->isNew()) {
        error(__('Specified download item does not exists!', 'dtransport'));
    }
    if ($sw->getVar('screens') >= $mc['limit_screen']) {
        error(__('You have reached the limit screens number for this download item!', 'dtransport'));
    }
    // Directorio de almacenamiento
    $dir = XOOPS_UPLOAD_PATH . '/screenshots';
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    $dir .= '/' . date('Y', time());
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    $dir .= '/' . date('m', time());
    if (!is_dir($dir)) {
        mkdir($dir, 511);
    }
    if (!is_dir($dir . '/ths')) {
        mkdir($dir . '/ths', 511);
    }
    if (!is_dir($dir)) {
        error(__('Directory for store screenshots does not exists!', 'dtransport'));
    }
    include RMCPATH . '/class/uploader.php';
    $uploader = new RMFileUploader($dir, $mc['image'] * 1024, array('jpg', 'gif', 'png'));
    $err = array();
    if (!$uploader->fetchMedia('Filedata')) {
        error($uploader->getErrors());
    }
    if (!$uploader->upload()) {
        error($uploader->getErrors());
    }
    // Saving image
    require_once XOOPS_ROOT_PATH . '/modules/dtransport/class/dtscreenshot.class.php';
    $img = new DTScreenshot();
    $img->setDesc('');
    $img->setTitle($uploader->getSavedFileName());
    $img->setImage($uploader->getSavedFileName());
    $img->setDate(time());
    $img->setSoftware($item);
    if (!$img->save()) {
        unlink($dir . '/' . $img->image());
        error(__('Screenshot could not be saved!', 'dtransport'));
    }
    // Resize image
    $thumb = explode(":", $mc['size_ths']);
    $big = explode(":", $mc['size_image']);
    $sizer = new RMImageResizer($dir . '/' . $img->getVar('image'), $dir . '/ths/' . $img->getVar('image'));
    // Thumbnail
    if (!isset($thumb[2]) || $thumb[2] == 'crop') {
        $sizer->resizeAndCrop($thumb[0], $thumb[1]);
    } else {
        $sizer->resizeWidthOrHeight($thumb[0], $thumb[1]);
    }
    // Full size image
    $sizer->setTargetFile($dir . '/' . $img->image());
    if (!isset($big[2]) || $big[2] == 'crop') {
        $sizer->resizeAndCrop($big[0], $big[1]);
    } else {
        $sizer->resizeWidthOrHeight($big[0], $big[1]);
    }
    $ret = array('image' => $uploader->getSavedFileName(), 'dir' => str_replace(XOOPS_UPLOAD_PATH, XOOPS_UPLOAD_URL, $dir), 'token' => $xoopsSecurity->createToken(), 'type' => $uploader->getMediaType(), 'error' => 0, 'id' => $img->id());
    echo json_encode($ret);
    die;
}
Ejemplo n.º 2
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;
    }
}
Ejemplo n.º 3
0
/**
* @desc almacena la informacion de la pantalla en la base de datos
**/
function dt_save_screens($edit = 0)
{
    global $item, $xoopsModuleConfig, $screen, $mc;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verificamos que la pantalla exista
        $sc = new DTScreenshot($screen);
        if ($sc->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Specified screenshot is not valid!', 'dtransport'));
        }
        //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() . " AND id_screen!=" . $sc->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/edit/' . $sc->id() : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id() . '&amp;op=edit&amp;screen' . $sc->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
    } 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->id();
        list($num) = $db->fetchRow($db->queryF($sql));
        if ($num > 0) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
        $sc = new DTScreenshot();
    }
    $sc->setTitle($title);
    $sc->setDesc($desc);
    $sc->setDate(time());
    $sc->setSoftware($item->id());
    //Cargamos la imagen
    // Directorio de almacenamiento
    if (isset($_FILES['image']) && $_FILES['image']['name'] != '') {
        $dir = XOOPS_UPLOAD_PATH . '/screenshots';
        // Eliminamos la imagen existente
        if ($edit) {
            $dir .= '/' . date('Y', $sc->date()) . '/' . date('m', $sc->date());
            unlink($dir . '/' . $sc->image());
            unlink($dir . '/ths/' . $sc->image());
            $dir = XOOPS_UPLOAD_PATH . '/screenshots';
        }
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        $dir .= '/' . date('Y', time());
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        $dir .= '/' . date('m', time());
        if (!is_dir($dir)) {
            mkdir($dir, 511);
        }
        if (!is_dir($dir . '/ths')) {
            mkdir($dir . '/ths', 511);
        }
        if (!is_dir($dir)) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        include RMCPATH . '/class/uploader.php';
        $uploader = new RMFileUploader($dir, $mc['image'] * 1024, array('jpg', 'gif', 'png'));
        $err = array();
        if (!$uploader->fetchMedia('image')) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        if (!$uploader->upload()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Image could not be upload due to an internal error!', 'dtransport'));
        }
        $sc->setImage($uploader->getSavedFileName());
        // Resize image
        $thumb = explode(":", $mc['size_ths']);
        $big = explode(":", $mc['size_image']);
        $sizer = new RMImageResizer($dir . '/' . $sc->getVar('image'), $dir . '/ths/' . $sc->getVar('image'));
        // Thumbnail
        if (!isset($thumb[2]) || $thumb[2] == 'crop') {
            $sizer->resizeAndCrop($thumb[0], $thumb[1]);
        } else {
            $sizer->resizeWidthOrHeight($thumb[0], $thumb[1]);
        }
        // Full size image
        $sizer->setTargetFile($dir . '/' . $sc->image());
        if (!isset($big[2]) || $big[2] == 'crop') {
            $sizer->resizeAndCrop($big[0], $big[1]);
        } else {
            $sizer->resizeWidthOrHeight($big[0], $big[1]);
        }
    }
    if (!$sc->save()) {
        if ($sc->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        } else {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/edit/' . $sc->id() : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id() . '&amp;op=edit&amp;screen' . $sc->id()), 1, __('Already exist another screenshot with the same name!', 'dtransport'));
        }
    } else {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/screens/' . $item->id() . '/' : '/?p=cpanel&amp;action=screens&amp;id=' . $item->id()), 1, __('Screenshot saved successfully!', 'dtransport'));
    }
}