Example #1
0
/**
* Save file
*/
function dt_save_file($edit)
{
    global $item, $file, $tpl, $xoopsTpl, $mc, $dtfunc;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if ($edit) {
        //Verificamos que la característica exista
        $fl = new DTFile($file);
        if ($fl->isNew()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('Specified file does not exists!', 'dtransport'));
        }
    } else {
        $fl = new DTFile();
    }
    $tc = TextCleaner::getInstance();
    //Comprueba que el título de la característica no exista
    $sql = "SELECT COUNT(*) FROM " . $db->prefix('dtrans_files') . " WHERE title='{$title}' AND id_file!=" . $fl->id() . " AND id_soft=" . $item->id();
    list($num) = $db->fetchRow($db->queryF($sql));
    if ($num > 0) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('Another log with same title already exists!', 'dtransport'));
    }
    // Check if a file has been provided
    if ($_FILES['thefile']['name'] == '') {
        // Comprobamos si se ha proporcionado un archivo
        if (!$edit && !$remote) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file to upload!', 'dtransport'));
        } elseif ($remote && $url == '') {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('You must provide a file URL when remote type is activated!', 'dtransport'));
        }
    } else {
        if ($edit && !$fl->remote()) {
            $path = $item->getVar('secure') ? rtrim($mc['directory_secure'], '/') . '/' . $fl->file() : rtrim($mc['directory_insecure']) . '/' . $fl->file();
            unlink($path);
        }
        if ($item->getVar('secure')) {
            $dir = $mc['directory_secure'];
        } else {
            $dir = $mc['directory_insecure'];
        }
        include RMCPATH . '/class/uploader.php';
        $uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']);
        if (!$uploader->fetchMedia('thefile')) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors());
        }
        if (!$uploader->upload()) {
            redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/edit/' . $fl->id() : '/?p=cpanel&action=files&id=' . $item->id() . '&op=edit&file=' . $fl->id()), 1, __('File could not be uploaded!, Please try again.', 'dtransport') . $uploader->getErrors());
        }
    }
    $fl->setSoftware($item->id());
    $fl->setTitle($title);
    $fname = !$uploader && $edit ? $remote ? $url : $fl->file() : $uploader->getSavedFileName();
    $fl->setFile($fname);
    $fl->setRemote($remote);
    $fl->setGroup($group);
    $fl->setDefault($default);
    $fl->setDate(time());
    $fl->setSize($remote ? '' : (isset($uploader) ? $uploader->getMediaSize() : $fl->size()));
    $fl->setMime($remote ? '' : (isset($uploader) ? $uploader->getMediaType() : $fl->mime()));
    if (!$fl->save()) {
        redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' . ($edit ? 'edit/' . $fl->id() : '') : '/?p=cpanel&action=files&id=' . $item->id() . ($edit ? '&op=edit&file=' . $fl->id() : '')), 1, __('File could not be saved! Please try again.', 'dtransport'));
    }
    if ($fl->isDefault()) {
        $db->queryF("UPDATE " . $db->prefix("dtrans_files") . " SET `default`=0 WHERE id_soft=" . $item->id() . " AND id_file !=" . $fl->id());
    }
    redirect_header(DT_URL . ($mc['permalinks'] ? '/cp/files/' . $item->id() . '/' : '/?p=cpanel&action=files&id=' . $item->id()), 1, __('File saved successfully!', 'dtransport'));
}
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;
}
Example #3
0
     $folder = $xoopsModuleConfig['attachdir'];
     $exts = array();
     include_once RMCPATH . '/class/uploader.php';
     $up = new RMFileUploader($folder, $xoopsModuleConfig['maxfilesize'] * 1024, $forum->extensions());
     $errors = '';
     $filename = '';
     if ($up->fetchMedia('attach')) {
         if (!$up->upload()) {
             $errors .= $up->getErrors();
         } else {
             $filename = $up->getSavedFileName();
             $fullpath = $up->getSavedDestination();
             $attach = new bXAttachment();
             $attach->setPost($post->id());
             $attach->setFile($filename);
             $attach->setMime($up->getMediaType());
             $attach->setDate(time());
             $attach->downloads(0);
             $attach->setName($up->getMediaName());
             if (!$attach->save()) {
                 $errors .= $attach->getErrors();
             }
         }
     }
 }
 $topic->setLastPost($post->id());
 if (!$create) {
     $topic->addReply();
 }
 $topic->save();
 $forum->setPostId($post->id());
Example #4
0
$sw = new DTSoftware($item);
if ($sw->isNew()) {
    error(__('Specified download item does not exists!', 'dtransport'));
}
if ($sw->getVar('secure')) {
    $dir = $mc['directory_secure'];
    if (!is_dir($dir)) {
        if (!mkdir($dir, 511)) {
            error(__('Directory for protected downloads does not exists!', 'dtransport'));
        }
    }
} else {
    $dir = $mc['directory_insecure'];
    if (!is_dir($dir)) {
        if (!mkdir($dir, 511)) {
            error(__('Directory for downloads does not exists!', 'dtransport'));
        }
    }
}
include RMCPATH . '/class/uploader.php';
$uploader = new RMFileUploader($dir, $mc['size_file'] * 1024 * 1024, $mc['type_file']);
$err = array();
if (!$uploader->fetchMedia('Filedata')) {
    error($uploader->getErrors());
}
if (!$uploader->upload()) {
    error($uploader->getErrors());
}
$ret = array('file' => $uploader->getSavedFileName(), 'dir' => $uploader->getSavedDestination(), 'token' => $data[4], 'size' => $rmu->formatBytesSize($uploader->getMediaSize()), 'fullsize' => $uploader->getMediaSize(), 'type' => $uploader->getMediaType(), 'secure' => $sw->getVar('secure') ? __('Protected Download', 'dtransport') : __('Normal Download', 'dtransport'), 'error' => 0);
echo json_encode($ret);
die;