Example #1
0
function scale_image($url, $width, $extension = null)
{
    if ($extension == null) {
        $extension = parse_extension($url);
    }
    $lsp_image = is_lsp_image($url);
    if ($lsp_image !== false) {
        global $DATA_DIR;
        include_once 'lsp/dbo.php';
        $url = "{$DATA_DIR}{$lsp_image}";
    }
    ini_set('user_agent', 'gd/2.x (linux)');
    $image = NULL;
    try {
        switch ($extension) {
            case '.jpg':
            case '.jpeg':
                $image = @imagecreatefromjpeg($url);
                break;
            case '.gif':
                $image = @imagecreatefromgif($url);
                break;
            case '.bmp':
                $image = @imagecreatefromwbmp($url);
                break;
            case '.png':
            default:
                $image = @imagecreatefrompng($url);
                break;
        }
    } catch (Exception $e) {
        return $url;
    }
    if ($image === false) {
        return $url;
    }
    $orig_width = imagesx($image);
    $orig_height = imagesy($image);
    if ($orig_width < $width) {
        return $url;
    }
    // Calc the new height
    $height = $orig_height * $width / $orig_width;
    // Create new image to display
    $new_image = imagecreatetruecolor($width, $height);
    imagealphablending($new_image, false);
    imagesavealpha($new_image, true);
    // Create new image with changed dimensions
    imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
    // Capture object to memory
    ob_start();
    //header( "Content-type: image/jpeg" );
    imagepng($new_image);
    imagedestroy($new_image);
    $i = ob_get_clean();
    return 'data:image/png;base64,' . base64_encode($i) . '"';
}
Example #2
0
                $file_path = $_FILES["filename"]["name"];
            } else {
                $file_path = POST('fn');
            }
            if (POST_EMPTY('fsize')) {
                $file_size = $_FILES["filename"]["size"];
            } else {
                $file_size = POST('fsize');
            }
            $no_copyright = POST('nocopyright');
            if (POST('ok') == 'OK') {
                if (POST_EMPTY('nocopyright')) {
                    display_error("Copyrighted content is forbidden", array('<a href="">Add File</a>', 'Error'), $LSP_URL . '?content=add');
                    return;
                }
                $file_extension = parse_extension($file_path);
                $categories = get_categories_for_ext($file_extension);
                if ($categories != false) {
                    if (isset($_FILES["filename"]["tmp_name"])) {
                        echo '<div class="col-md-9">';
                        create_title(array('<a href="">Add File</a>', $file_path));
                        $tmp_path = $_FILES["filename"]["tmp_name"];
                        $tmp_ext = trim(pathinfo($tmp_path, PATHINFO_EXTENSION));
                        $tmp_name_only = pathinfo($tmp_path, PATHINFO_FILENAME) . ($tmp_ext == "" ? '' : '.' . $tmp_ext);
                        move_uploaded_file($tmp_path, $TMP_DIR . $tmp_name_only);
                        //echo "<code>moving $tmp_path to $TMP_DIR$tmp_name_only</code>";
                        ?>
					<?php 
                        $form = new form($LSP_URL . '?content=add', 'File Details', 'fa-upload');
                        ?>
					<div class="form-group">
Example #3
0
function read_project($file_id)
{
    global $DATA_DIR;
    $extension = parse_extension(get_file_name($file_id));
    switch ($extension) {
        case '.mmp':
            // Treat as plain XML
            return simplexml_load_file($DATA_DIR . $file_id);
        case '.mmpz':
            // Open binary file for reading
            $handle = fopen($DATA_DIR . $file_id, "rb");
            // Skip the first 4 bytes for compressed mmpz files
            fseek($handle, 4);
            $data = fread($handle, filesize($DATA_DIR . $file_id) - 4);
            return simplexml_load_string(zlib_decode($data));
        default:
            return null;
    }
}
Example #4
0
function show_file($file_id, $user, $success = null)
{
    global $LSP_URL, $DATA_DIR;
    $dbh =& get_db();
    $stmt = $dbh->prepare('SELECT licenses.name AS license, size, realname, filename, users.login, ' . 'categories.name AS category, subcategories.name AS subcategory,' . 'insert_date, update_date, description, downloads, files.id FROM files ' . 'INNER JOIN categories ON categories.id=files.category ' . 'INNER JOIN subcategories ON subcategories.id=files.subcategory ' . 'INNER JOIN users ON users.id=files.user_id ' . 'INNER JOIN licenses ON licenses.id=files.license_id ' . 'WHERE files.id=:file_id');
    $stmt->bindParam(':file_id', $file_id);
    $found = false;
    if ($stmt->execute()) {
        while ($object = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $title = array($object['category'], $object['subcategory'], get_file_url($file_id));
            if ($success == null) {
                echo '<div class="col-md-9">';
                create_title($title);
            } else {
                if ($success === true) {
                    display_success("Updated successfully", $title);
                    echo '<div class="col-md-9">';
                } else {
                    if ($success === false) {
                        display_error("Update failed.", $title);
                        echo '<div class="col-md-9">';
                    } else {
                        display_success("{$success}", $title);
                    }
                }
            }
            echo '<table class="table table-striped">';
            show_basic_file_info($object, false);
            // Bump the download button under details block
            $url = htmlentities('download_file.php?file=' . $object['id'] . '&name=' . $object['filename']);
            echo '<tr><td><strong>Name:</strong>&nbsp;' . $object['filename'];
            if (is_image($url)) {
                echo '<br><br><a href="' . $url . '"><img class="thumbnail" src="' . scale_image($DATA_DIR . $file_id, 300, parse_extension($url)) . '" alt=""></a>';
            }
            echo '</td><td class="lsp-file-info">';
            echo '<a href="' . $url . '" id="downloadbtn" class="lsp-dl-btn btn btn-primary">';
            echo '<span class="fa fa-download lsp-download"></span>&nbsp;Download</a>';
            echo '</td></tr>';
            echo '<tr><td colspan="2"><div class="well"><strong>Description:</strong><p>';
            echo $object['description'] != '' ? parse_links(newline_to_br($object['description'], true)) : 'No description available.';
            echo '</p></div></td></tr>';
            echo '<tr><td colspan="2">';
            echo '<nav id="lspnav" class="navbar navbar-default"><ul class="nav navbar-nav">';
            $can_edit = $object['login'] == $user || is_admin(get_user_id($user));
            $can_rate = !SESSION_EMPTY();
            $rate_self = $object['login'] == $user;
            global $LSP_URL;
            create_toolbar_item('Comment', "{$LSP_URL}?comment=add&file={$file_id}", 'fa-comment', $can_rate);
            create_toolbar_item('Edit', "{$LSP_URL}?content=update&file={$file_id}", 'fa-pencil', $can_edit);
            create_toolbar_item('Delete', "{$LSP_URL}?content=delete&file={$file_id}", 'fa-trash', $can_edit);
            $star_url = $LSP_URL . '?' . file_show_query_string() . '&rate=';
            create_toolbar_item(get_stars($file_id, $star_url, $rate_self ? false : $can_rate), '', null, $can_rate, $rate_self);
            echo '</ul></nav>';
            echo '<strong>Comments:</strong>';
            echo '</td></tr>';
            get_comments($file_id);
            echo '</table></div>';
            $found = true;
            break;
        }
    }
    if (!$found) {
        display_error('Invalid file: "' . sanitize($file_id) . '"');
    }
    $stmt = null;
    $dbh = null;
}
Example #5
0
<?php

require_once 'utils.php';
require_once 'dbo.php';
require_once 'xhtml.php';
global $LSP_URL;
if (get_user_id(SESSION()) == get_object_by_id("files", GET('file'), 'user_id') || is_admin(get_user_id(SESSION()))) {
    if (!POST('updateok', false)) {
        $file_name = get_file_name(GET('file'));
        $file_extension = parse_extension($file_name);
        $categories = get_categories_for_ext($file_extension, get_file_category(GET('file')) . ' - ' . get_file_subcategory(GET('file')));
        echo '<div class="col-md-9">';
        create_title(array('Edit', get_file_url()));
        $form = new form($LSP_URL . '?content=update&file=' . GET('file'), $title = 'Edit File', 'fa-pencil');
        ?>
		<div class="form-group">
			<label for="category">Category</label>
			<select name="category" class="form-control">
			<?php 
        echo $categories;
        ?>
	
			</select>
		</div>
		<div class="form-group">
			<label for="license">License</label>
			<select name="license" class="form-control">
			<?php 
        echo get_licenses(get_license_name(get_file_license(GET('file'))));
        ?>
			</select>