コード例 #1
0
ファイル: newmedia.php プロジェクト: mistgrass/geeklog-ivywe
/**
* Save flash upload(s)
*
* @param    int     album_id    album_id save uploaded media
* @return   string              HTML
*
*/
function MG_saveFileUpload($album_id)
{
    global $_TABLES, $_MG_CONF, $LANG_MG01, $LANG_MG02, $new_media_id;
    $statusMsg = '';
    $file = array();
    $album = new mgAlbum($album_id);
    if ($_MG_CONF['verbose']) {
        COM_errorLog('*** Inside MG_saveFileUpload()***');
        COM_errorLog('uploading to album_id=' . $album_id);
        COM_errorLog('album owner_id=' . $album->owner_id);
    }
    if (!isset($album->id) || $album_id == 0) {
        COM_errorLog('MediaGallery: FileUpload was unable to determine album id');
        return $LANG_MG01['swfupload_err_album_id'];
    }
    $successfull_upload = 0;
    $upload = isset($_FILES['files']) ? $_FILES['files'] : null;
    if ($upload && is_array($upload['tmp_name'])) {
        // param_name is an array identifier like "files[]",
        // $_FILES is a multi-dimensional array:
        foreach ($upload['tmp_name'] as $index => $value) {
            $file[$index] = array('name' => $upload['name'][$index], 'type' => $upload['type'][$index], 'size' => $upload['size'][$index], 'tmp_name' => $upload['tmp_name'][$index], 'error' => $upload['error'][$index]);
        }
    } else {
        // param_name is a single object identifier like "file",
        // $_FILES is a one-dimensional array:
        $file[0]['name'] = $upload['name'];
        $file[0]['type'] = $upload['type'];
        $file[0]['size'] = $upload['size'];
        $file[0]['tmp_name'] = $upload['tmp_name'];
        $file[0]['error'] = $upload['error'];
    }
    $info = array();
    foreach ($file as $tagname => $object) {
        $filename = $object['name'];
        $filetype = $object['type'];
        $filesize = $object['size'];
        $filetmp = $object['tmp_name'];
        $error = $object['error'];
        $caption = '';
        $description = 'No Description';
        $attachtn = '';
        $thumbnail = '';
        if ($_MG_CONF['verbose']) {
            COM_errorLog('filename=' . $filename, 1);
            COM_errorLog('filesize=' . $filesize, 1);
            COM_errorLog('filetype=' . $filetype, 1);
            COM_errorLog('filetmp=' . $filetmp, 1);
            COM_errorLog('error=' . $error, 1);
        }
        // we need to move the max filesize stuff to the flash uploader
        if ($album->max_filesize != 0 && $filesize > $album->max_filesize) {
            COM_errorLog('MediaGallery: File ' . $filename . ' exceeds maximum allowed filesize for this album');
            COM_errorLog('MediaGallery: Max filesize for this album=' . $album->max_filesize);
            $tmpmsg = sprintf($LANG_MG02['upload_exceeds_max_filesize'], $filename);
            return $tmpmsg;
        }
        $attach_tn = 0;
        // process the uploaded file(s)
        $opt = array('caption' => $caption, 'description' => $description, 'filetype' => $filetype, 'atttn' => $attach_tn, 'thumbnail' => $thumbnail);
        list($rc, $msg) = MG_getFile($filetmp, $filename, $album_id, $opt);
        if ($rc == true) {
            $successfull_upload++;
            $temp = new stdClass();
            $temp->name = $filename;
            $temp->size = $filesize;
            $temp->type = $filetype;
            $temp->mid = $new_media_id;
            $temp->caption = $caption;
            $temp->description = $description;
            $info[] = $temp;
        } else {
            COM_errorLog('MG_saveFileUpload error: ' . $msg, 1);
            return $msg;
        }
    }
    if ($successfull_upload) {
        MG_notifyModerators($album_id);
    }
    // failsafe check - after all the uploading is done, double check that the database counts
    // equal the actual count of items shown in the database, if not, fix the counts and log
    // the error
    $dbCount = DB_count($_TABLES['mg_media_albums'], 'album_id', intval($album_id));
    $aCount = DB_getItem($_TABLES['mg_albums'], 'media_count', "album_id=" . intval($album_id));
    if ($dbCount != $aCount) {
        DB_change($_TABLES['mg_albums'], 'media_count', $dbCount, 'album_id', intval($album_id));
        COM_errorLog("MediaGallery: Upload processing - Counts don't match - dbCount = " . $dbCount . " aCount = " . $aCount);
    }
    MG_SortMedia($album_id);
    //    return 'FILEID:' . $new_media_id;
    $json = json_encode($info);
    return $json;
}
コード例 #2
0
ファイル: newmedia.php プロジェクト: spacequad/glfusion
/**
* Save browser upload(s)
*
* @param    int     album_id    album_id save uploaded media
* @return   string              HTML
*
*/
function MG_saveUserUpload($album_id)
{
    global $MG_albums, $_USER, $_CONF, $_TABLES, $_MG_CONF, $LANG_MG00, $LANG_MG01, $LANG_MG02, $LANG_MG03, $new_media_id;
    $retval = '';
    $retval .= COM_startBlock($LANG_MG03['upload_results'], '', COM_getBlockTemplate('_admin_block', 'header'));
    $T = new Template(MG_getTemplatePath($album_id));
    $T->set_file('mupload', 'useruploadstatus.thtml');
    $statusMsg = '';
    $file = array();
    $file = $_FILES['newmedia'];
    $thumbs = $_FILES['thumbnail'];
    $albums = $album_id;
    $successfull_upload = 0;
    $upload = 1;
    $purge = 0;
    foreach ($file['name'] as $key => $name) {
        $filename = $file['name'][$key];
        $filetype = $file['type'][$key];
        $filesize = $file['size'][$key];
        $filetmp = $file['tmp_name'][$key];
        $upload = isset($file['_data_dir']) ? 0 : 1;
        $purge = isset($file['_data_dir']) ? 1 : 0;
        $error = $file['error'][$key];
        $caption = $_POST['caption'][$key];
        $description = $_POST['description'][$key];
        $keywords = $_POST['keywords'][$key];
        $category = 0;
        if (isset($_POST['cat_id'])) {
            $category = COM_applyFilter($_POST['cat_id'][$key], true);
        }
        $attachtn = isset($_POST['attachtn'][$key]) ? $_POST['attachtn'][$key] : '';
        $thumbnail = isset($thumbs['tmp_name'][$key]) ? $thumbs['tmp_name'][$key] : '';
        if (isset($_POST['dnc'][$key]) && $_POST['dnc'][$key] == 'on') {
            $dnc = 1;
        } else {
            $dnc = 0;
        }
        if ($filename == '') {
            continue;
        }
        if ($MG_albums[$album_id]->max_filesize != 0 && $filesize > $MG_albums[$album_id]->max_filesize) {
            COM_errorLog("MG Upload: File " . $filename . " exceeds maximum allowed filesize for this album");
            $tmpmsg = sprintf($LANG_MG02['upload_exceeds_max_filesize'], $filename);
            $statusMsg .= $tmpmsg . '<br/>';
            continue;
        }
        if ($attachtn == "on") {
            $attach_tn = 1;
        } else {
            $attach_tn = 0;
        }
        if ($error != UPLOAD_ERR_OK) {
            switch ($error) {
                case 1:
                    $tmpmsg = sprintf($LANG_MG02['upload_too_big'], $filename);
                    $statusMsg .= $tmpmsg . '<br/>';
                    COM_errorLog('MediaGallery:  Error - ' . $tmpmsg);
                    break;
                case 2:
                    $tmpmsg = sprintf($LANG_MG02['upload_too_big_html'], $filename);
                    $statusMsg .= $tmpmsg . '<br/>';
                    COM_errorLog('MediaGallery: Error - ' . $tmpmsg);
                    break;
                case 3:
                    $tmpmsg = sprintf($LANG_MG02['partial_upload'], $filename);
                    $statusMsg .= $tmpmsg . '<br/>';
                    COM_errorLog('MediaGallery: Error - ' . $tmpmsg);
                    break;
                case 4:
                    break;
                case 6:
                    $statusMsg .= $LANG_MG02['missing_tmp'] . '<br/>';
                    break;
                case 7:
                    $statusMsg .= $LANG_MG02['disk_fail'] . '<br/>';
                    break;
                default:
                    $statusMsg .= $LANG_MG02['unknown_err'] . '<br/>';
                    break;
            }
            continue;
        }
        // check user quota -- do we have one?
        $user_quota = MG_getUserQuota($_USER['uid']);
        if ($user_quota > 0) {
            $disk_used = MG_quotaUsage($_USER['uid']);
            if ($disk_used + $filesize > $user_quota) {
                COM_errorLog("MG Upload: File " . $filename . " would exceeds the users quota");
                $tmpmsg = sprintf($LANG_MG02['upload_exceeds_quota'], $filename);
                $statusMsg .= $tmpmsg . '<br/>';
                continue;
            }
        }
        // override the determination for some filetypes
        $filetype = MG_getFileTypeFromExt($filename, $filetype);
        // process the uploaded files
        list($rc, $msg) = MG_getFile($filetmp, $filename, $albums, $caption, $description, $upload, $purge, $filetype, $attach_tn, $thumbnail, $keywords, $category, $dnc, 0);
        $statusMsg .= $filename . " " . $msg . '<br/>';
        if ($rc == true) {
            $successfull_upload++;
        }
    }
    if ($successfull_upload) {
        MG_notifyModerators($albums);
        PLG_sendSubscriptionNotification('mediagallery', '', $albums, $new_media_id, $_USER['uid']);
    }
    // failsafe check - after all the uploading is done, double check that the database counts
    // equal the actual count of items shown in the database, if not, fix the counts and log
    // the error
    $dbCount = DB_count($_TABLES['mg_media_albums'], 'album_id', (int) $album_id);
    $aCount = DB_getItem($_TABLES['mg_albums'], 'media_count', "album_id=" . (int) $album_id);
    if ($dbCount != $aCount) {
        DB_query("UPDATE " . $_TABLES['mg_albums'] . " SET media_count=" . $dbCount . " WHERE album_id=" . (int) $album_id);
        COM_errorLog("MediaGallery: Upload processing - Counts don't match - dbCount = " . $dbCount . " aCount = " . $aCount);
    }
    MG_SortMedia($album_id);
    $T->set_var('status_message', $statusMsg);
    $tmp = $_MG_CONF['site_url'] . '/album.php?aid=' . $album_id . '&amp;page=1';
    $redirect = sprintf($LANG_MG03['album_redirect'], $tmp);
    $T->set_var('redirect', $redirect);
    $T->parse('output', 'mupload');
    $retval .= $T->finish($T->get_var('output'));
    $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
    return $retval;
}
コード例 #3
0
ファイル: remote.php プロジェクト: NewRoute/glfusion
/**
* Save user uploads
*
* @param    int     album_id    album_id save uploaded media
* @return   string              HTML
*
*/
function MG_saveRemoteUpload($albumId)
{
    global $MG_albums, $_FILES, $_CONF, $_TABLES, $_MG_CONF, $LANG_MG01, $LANG_MG02, $LANG_MG03, $_POST;
    $retval = '';
    $retval .= COM_startBlock($LANG_MG03['upload_results'], '', COM_getBlockTemplate('_admin_block', 'header'));
    $T = new Template(MG_getTemplatePath($albumId));
    $T->set_file('mupload', 'useruploadstatus.thtml');
    $T->set_var('site_url', $_CONF['site_url']);
    $statusMsg = '';
    $file = array();
    $file = $_FILES['thumbnail'];
    $successfull_upload = 0;
    $remoteURL = array();
    $remoteURL = $_POST['remoteurl'];
    $totalUploads = count($remoteURL);
    for ($i = 0; $i < $totalUploads; $i++) {
        $errorFound = 0;
        if ($remoteURL[$i] == '') {
            continue;
        }
        $URL = $remoteURL[$i];
        $uploadType = COM_applyFilter($_POST['type'][$i]);
        $caption = $_POST['caption'][$i];
        $description = $_POST['description'][$i];
        $keywords = $_POST['keywords'][$i];
        $category = COM_applyFilter($_POST['cat_id'][$i], true);
        $thumbnail = $file['tmp_name'][$i];
        $resolution_x = isset($_POST['width'][$i]) ? COM_applyFilter($_POST['width'][$i], true) : 0;
        $resolution_y = isset($_POST['height'][$i]) ? COM_applyFilter($_POST['height'][$i], true) : 0;
        if ($thumbnail != '') {
            $attachedThumbnail = 1;
        } else {
            //Jon Deliz:THUMBNAIL: custom code to check and see if uploadType is 4 (JPG) or 6 (GIF).
            // If you add other options for photos and want the thumbnail generation to work, you must
            // add them to this list!!!
            if (in_array($uploadType, array(4, 6, 7, 8)) && $_MG_CONF['enable_remote_images'] == 1) {
                $attachedThumbnail = 1;
                $thumbnail = $URL;
            } else {
                $attachedThumbnail = 0;
            }
        }
        // set the mime type here
        switch ($uploadType) {
            case 0:
                // streaming FLV
                $mimeType = 'video/x-flv';
                $urlParts = array();
                $urlParts = parse_url($URL);
                $pathParts = array();
                $pathParts = explode('/', $urlParts['path']);
                $ppCount = count($pathParts);
                $pPath = '';
                for ($x = 1; $x < $ppCount - 1; $x++) {
                    $pPath .= '/' . $pathParts[$x];
                }
                $videoFile = $pathParts[$ppCount - 1];
                if ($urlParts['scheme'] != 'rtmp' && $urlParts['scheme'] != 'rtsp') {
                    $statusMsg .= sprintf($LANG_MG02['invalid_remote_url'] . '<br>', $i);
                    $errorFound++;
                    $retval = MG_errorHandler($statusMsg);
                    return $retval;
                }
                break;
            case 1:
                $mimeType = 'video/quicktime';
                break;
            case 2:
                $mimeType = 'video/x-ms-asf';
                break;
            case 3:
                $mimeType = 'audio/mpeg';
                break;
            case 4:
                $mimeType = 'image/jpg';
                break;
            case 5:
                $mimeType = 'embed';
                $videoFile = 'Embedded Video';
                if (!preg_match("/embed/i", $URL) && !preg_match("/movie/i", $URL)) {
                    $statusMsg .= sprintf($LANG_MG02['invalid_embed_url'] . '<br>', $i);
                    $errorFound++;
                    $retval = MG_errorHandler($statusMsg);
                    return $retval;
                    exit;
                }
                break;
            case 6:
                $mimeType = 'image/gif';
                break;
            case 7:
                $mimeType = 'image/png';
                break;
            case 8:
                //new case item added to handle GIF images. Approx. line 209
                $mimeType = 'image/bmp';
                break;
            default:
                $fileNumber = $i + 1;
                $retval = MG_errorHandler($LANG_MG01['file_number'] . ' ' . $fileNumber . ' - ' . $LANG_MG02['no_format']);
                return $retval;
                exit;
        }
        if ($errorFound) {
            continue;
        }
        list($rc, $msg) = MG_getRemote($URL, $mimeType, $albumId, $caption, $description, $keywords, $category, $attachedThumbnail, $thumbnail, $resolution_x, $resolution_y);
        $statusMsg .= $msg . "<br />";
        if ($rc == true) {
            $successfull_upload++;
        }
    }
    if ($successfull_upload) {
        MG_notifyModerators($albumId);
    }
    // failsafe check - after all the uploading is done, double check that the database counts
    // equal the actual count of items shown in the database, if not, fix the counts and log
    // the error
    $dbCount = DB_count($_TABLES['mg_media_albums'], 'album_id', intval($albumId));
    $aCount = DB_getItem($_TABLES['mg_albums'], 'media_count', "album_id=" . intval($albumId));
    if ($dbCount != $aCount) {
        DB_query("UPDATE " . $_TABLES['mg_albums'] . " SET media_count=" . $dbCount . " WHERE album_id=" . intval($albumId));
        COM_errorLog("MediaGallery: Upload processing - Counts don't match - dbCount = " . $dbCount . " aCount = " . $aCount);
    }
    $T->set_var('status_message', $statusMsg);
    $tmp = $_MG_CONF['site_url'] . '/album.php?aid=' . $albumId . '&page=1';
    $redirect = sprintf($LANG_MG03['album_redirect'], $tmp);
    $T->set_var('redirect', $redirect);
    $T->parse('output', 'mupload');
    $retval .= $T->finish($T->get_var('output'));
    $retval .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
    return $retval;
}