Esempio n. 1
0
/**
* @des Visualiza todas las pantallas existentes
**/
function showScreens()
{
    global $xoopsModule, $xoopsSecurity, $tpl, $functions, $xoopsModule, $xoopsModuleConfig, $xoopsUser, $xoopsConfig;
    define('RMCSUBLOCATION', 'screenshots');
    if ($xoopsConfig['closesite']) {
        showMessage(__('Screenshop uploader does not work when site is closed. Before to start uploding, please change this configuration.', 'rmcommon'), RMMSG_WARN);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $tc = TextCleaner::getInstance();
    $item = rmc_server_var($_REQUEST, 'item', 0);
    if ($item <= 0) {
        redirectMsg('items.php', __('Download item ID not provided!', 'dtransport'), RMMSG_WARN);
    }
    $sw = new DTSoftware($item);
    $sql = "SELECT * FROM " . $db->prefix('dtrans_screens') . " WHERE id_soft={$item}";
    $result = $db->queryF($sql);
    while ($rows = $db->fetchArray($result)) {
        $sc = new DTScreenshot();
        $sc->assignVars($rows);
        $screens[] = array('id' => $sc->id(), 'title' => $sc->title(), 'desc' => substr($tc->clean_disabled_tags($sc->desc()), 0, 80) . "...", 'image' => XOOPS_UPLOAD_URL . '/screenshots/' . date('Y', $sc->date()) . '/' . date('m', $sc->date()) . '/ths/' . $sc->image());
    }
    // CSS Styles
    $tpl->add_style('admin.css', 'dtransport');
    $tpl->add_style('screens.css', 'dtransport');
    $tpl->add_style('uploadify.css', 'rmcommon');
    // Javascripts
    $tpl->add_local_script('swfobject.js', 'rmcommon', 'include');
    $tpl->add_local_script('jquery.uploadify.js', 'rmcommon', 'include');
    $tpl->add_local_script('screens.js', 'dtransport');
    $tc = TextCleaner::getInstance();
    $rmf = RMFunctions::get();
    ob_start();
    include DT_PATH . '/js/screenshots.js';
    $script = ob_get_clean();
    $tpl->add_head_script($script);
    $functions->toolbar();
    xoops_cp_location("<a href='./'>" . $xoopsModule->name() . "</a> &raquo; <a href='items.php'>" . __('Downloads', 'dtransport') . "</a> &raquo; " . __('Screenshots Management', 'dtransport'));
    $tpl->assign('xoops_pagetitle', sprintf(__("%s Screenshots", 'dtransport'), $sw->getVar('name')));
    include DT_PATH . '/include/js_strings.php';
    xoops_cp_header();
    include $tpl->get_template('admin/dtrans_screens.php', 'module', 'dtransport');
    xoops_cp_footer();
}
Esempio n. 2
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'));
    }
}