Example #1
0
function MG_approveSubmission($media_id)
{
    global $_CONF, $_TABLES, $LANG_MG01;
    $mid = addslashes($media_id);
    $owner_uid = DB_getItem($_TABLES['mg_mediaqueue'], 'media_user_id', "media_id='" . $mid . "'");
    DB_delete($_TABLES['mg_mediaqueue'], 'media_id', $mid);
    $album_id = DB_getItem($_TABLES['mg_media_album_queue'], 'album_id', "media_id='" . $mid . "'");
    DB_save($_TABLES['mg_media_albums'], 'album_id, media_id, media_order', "{$album_id}, '{$mid}', 0");
    require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
    MG_SortMedia($album_id);
    DB_delete($_TABLES['mg_media_album_queue'], 'media_id', $mid);
    $sql = "SELECT media_filename, media_type " . "FROM {$_TABLES['mg_media']} WHERE media_id='" . $mid . "'";
    $result = DB_query($sql);
    list($media_filename, $media_type) = DB_fetchArray($result);
    $media_count = DB_getItem($_TABLES['mg_albums'], 'media_count', 'album_id=' . $album_id);
    $media_count++;
    DB_change($_TABLES['mg_albums'], 'media_count', $media_count, 'album_id', $album_id);
    MG_updateAlbumLastUpdate($album_id);
    $album_cover = DB_getItem($_TABLES['mg_albums'], 'album_cover', 'album_id=' . $album_id);
    if ($album_cover == -1 && $media_type == 0) {
        DB_change($_TABLES['mg_albums'], 'album_cover_filename', $media_filename, 'album_id', $album_id);
    }
    // email the owner / uploader that the item has been approved.
    COM_clearSpeedlimit(600, 'mgapprove');
    $last = COM_checkSpeedlimit('mgapprove');
    if ($last == 0) {
        $result2 = DB_query("SELECT username, fullname, email FROM {$_TABLES['users']} WHERE uid='" . $owner_uid . "'");
        list($username, $fullname, $email) = DB_fetchArray($result2);
        if ($email != '') {
            $subject = $LANG_MG01['upload_approved'];
            $body = $LANG_MG01['upload_approved'];
            $body .= '<br' . XHTML . '><br' . XHTML . '>';
            $body .= $LANG_MG01['thanks_submit'];
            $body .= '<br' . XHTML . '><br' . XHTML . '>';
            $body .= $_CONF['site_name'] . '<br' . XHTML . '>';
            $body .= $_CONF['site_url'] . '<br' . XHTML . '>';
            $to = array();
            $from = array();
            $to = COM_formatEmailAddress($username, $email);
            $from = COM_formatEmailAddress($_CONF['site_name'], $_CONF['site_mail']);
            if (!COM_mail($to, $subject, $body, $from, true)) {
                COM_errorLog("Media Gallery Error - Unable to send queue notification email");
            }
            COM_updateSpeedlimit('mgapprove');
        }
    }
    // PLG_itemSaved($media_id, 'mediagallery');
    // COM_rdfUpToDateCheck();
    // COM_olderStuff();
    return;
}
Example #2
0
function mg_batch_session_ftpimport($row)
{
    global $_CONF, $_TABLES, $LANG_MG02;
    require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
    require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
    $srcFile = $row['data'];
    // full path
    $album_id = $row['aid'];
    $purgefiles = intval($row['data2']);
    $baseSrcFile = $row['data3'];
    // basefilename
    $directory = $row['mid'];
    $album_data = MG_getAlbumData($album_id, array('max_filesize'));
    $session_id = $row['session_id'];
    if ($directory == 1) {
        require_once $_CONF['path'] . 'plugins/mediagallery/include/albumedit.php';
        $new_aid = MG_quickCreate($album_id, $baseSrcFile);
        $dir = $srcFile;
        // COM_stripslashes($srcFile);
        if (!($dh = @opendir($dir))) {
            COM_errorLog("Media Gallery: Error - unable process FTP import directory " . $dir);
        } else {
            while (($file = readdir($dh)) != false) {
                if ($file == '..' || $file == '.') {
                    continue;
                }
                if ($file == 'Thumbs.db' || $file == 'thumbs.db') {
                    continue;
                }
                $filetmp = $dir . '/' . $file;
                $mid = is_dir($filetmp) ? 1 : 0;
                $filename = basename($file);
                MG_registerSession(array('session_id' => $session_id, 'mid' => $mid, 'aid' => $new_aid, 'data' => $filetmp, 'data2' => $purgefiles, 'data3' => $filename));
                if (DB_error()) {
                    COM_errorLog("Media Gallery: Error - SQL error on inserting record into session_items table");
                }
            }
        }
    } else {
        if ($album_data['max_filesize'] != 0 && filesize($srcFile) > $album_data['max_filesize']) {
            COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
            $statusMsg = addslashes(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
            MG_setSessionLog($session_id, $statusMsg);
            continue;
        }
        $filetype = "application/force-download";
        $opt = array('upload' => 0, 'purgefiles' => $purgefiles, 'filetype' => $filetype);
        list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $opt);
        $statusMsg = addslashes($baseSrcFile . " " . $msg);
        MG_setSessionLog($session_id, $statusMsg);
        MG_SortMedia($album_id);
        @set_time_limit($time_limit + 20);
    }
    return;
}
Example #3
0
/**
* 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;
}
Example #4
0
/**
* 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;
}
Example #5
0
function MG_batchMoveMedia($album_id, $actionURL = '')
{
    global $_USER, $_CONF, $_TABLES, $_MG_CONF, $LANG_MG00, $LANG_MG01, $LANG_MG03, $_POST;
    // check permissions...
    $sql = "SELECT * FROM " . $_TABLES['mg_albums'] . " WHERE album_id=" . $album_id;
    $result = DB_query($sql);
    $A = DB_fetchArray($result);
    if (DB_error() != 0) {
        echo COM_errorLog("Media Gallery - Error retrieving album cover.");
    }
    $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']);
    if ($access != 3 && !SEC_hasRights('mediagallery.admin')) {
        COM_errorLog("Someone has tried to illegally delete items from album in Media Gallery.  User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$REMOTE_ADDR}", 1);
        return MG_genericError($LANG_MG00['access_denied_msg']);
    }
    $destination = intval(COM_applyFilter($_POST['album'], true));
    // check permissions...
    $sql = "SELECT * FROM " . $_TABLES['mg_albums'] . " WHERE album_id=" . $destination;
    $result = DB_query($sql);
    $D = DB_fetchArray($result);
    if (DB_error() != 0) {
        echo COM_errorLog("Media Gallery - Error retrieving destination album.");
    }
    $access = SEC_hasAccess($D['owner_id'], $D['group_id'], $D['perm_owner'], $D['perm_group'], $D['perm_members'], $D['perm_anon']);
    if ($access != 3 && !SEC_hasRights('mediagallery.admin')) {
        COM_errorLog("Someone has tried to illegally move items from album in Media Gallery.  User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$REMOTE_ADDR}", 1);
        return MG_genericError($LANG_MG00['access_denied_msg']);
    }
    // make sure they are not the same...
    if ($album_id == $destination || $destination == 0) {
        echo COM_refresh($actionURL);
        exit;
    }
    $numItems = count($_POST['sel']);
    // get max order for destination album....
    $sql = "SELECT MAX(media_order) + 10 AS media_seq FROM " . $_TABLES['mg_media_albums'] . " WHERE album_id = " . $destination;
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $media_seq = $row['media_seq'];
    if ($media_seq < 10) {
        $media_seq = 10;
    }
    // ok to move media objects, we will need a destination album.
    // we will also need to get the max order value so we can put all of these at the top
    // of the new album.
    $dMediaCount = $D['media_count'];
    $aMediaCount = $A['media_count'];
    for ($i = 0; $i < $numItems; $i++) {
        $sql = "UPDATE {$_TABLES['mg_media_albums']} SET album_id=" . $destination . ", media_order=" . $media_seq . " WHERE album_id=" . $album_id . " AND media_id='" . DB_escapeString($_POST['sel'][$i]) . "'";
        DB_query($sql);
        if (DB_error()) {
            COM_errorLog("Media Gallery - Error moving " . $_POST['sel'][$i] . " to new destination album " . $album_id);
        }
        $media_seq += 10;
        // update the media count in both albums...
        $last_update = time();
        $dMediaCount++;
        $aMediaCount--;
        DB_query("UPDATE {$_TABLES['mg_albums']} set media_count=" . $dMediaCount . ", last_update=" . $last_update . " WHERE album_id=" . $D['album_id']);
        DB_query("UPDATE {$_TABLES['mg_albums']} set media_count=" . $aMediaCount . " WHERE album_id=" . $A['album_id']);
        // get the media_filename for the image / item we are moving...
        $mediaFilename = DB_getItem($_TABLES['mg_media'], 'media_filename', "media_id='" . DB_escapeString($_POST['sel'][$i]) . "'");
        //
        // check to see if cover of old album...
        if ($_POST['sel'][$i] == $A['album_cover']) {
            $sql = "SELECT m.media_filename FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE ma.album_id=" . $A['album_id'] . " AND m.media_type=0 ORDER BY m.media_upload_time DESC LIMIT 1";
            $result = DB_query($sql);
            $nRows = DB_numRows($result);
            if ($nRows > 0) {
                $row = DB_fetchArray($result);
                DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover=-1,album_cover_filename='" . $row['media_filename'] . "' WHERE album_id=" . $A['album_id']);
                if (DB_error()) {
                    COM_errorLog("Media Gallery - Error setting new album cover after media move");
                }
            } else {
                // album must be empty now or it only has video / audio files
                DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover=-1,album_cover_filename='' WHERE album_id=" . $A['album_id']);
            }
        }
        // check if we moved the cover file
        if ($mediaFilename == $A['album_cover_filename']) {
            $sql = "SELECT m.media_filename FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE ma.album_id=" . $A['album_id'] . " AND m.media_type=0 ORDER BY m.media_upload_time DESC LIMIT 1";
            $result = DB_query($sql);
            $nRows = DB_numRows($result);
            if ($nRows > 0) {
                $row = DB_fetchArray($result);
                DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover_filename='" . $row['media_filename'] . "' WHERE album_id=" . $A['album_id']);
            } else {
                // album must be empty now or it only has video / audio files
                DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover=-1,album_cover_filename='' WHERE album_id=" . $A['album_id']);
            }
        }
    }
    // now check for the latest media item if no cover set...
    if ($D['album_cover'] == -1) {
        $sql = "SELECT m.media_filename FROM {$_TABLES['mg_media']} AS m LEFT JOIN {$_TABLES['mg_media_albums']} AS ma ON m.media_id=ma.media_id WHERE ma.album_id=" . $D['album_id'] . " AND m.media_type=0 ORDER BY m.media_upload_time DESC LIMIT 1";
        $result = DB_query($sql);
        $nRows = DB_numRows($result);
        if ($nRows > 0) {
            $row = DB_fetchArray($result);
            DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover_filename='" . $row['media_filename'] . "' WHERE album_id=" . $D['album_id']);
        } else {
            DB_query("UPDATE {$_TABLES['mg_albums']} set album_cover_filename='' WHERE album_id=" . $D['album_id']);
        }
    }
    // reset the last_update field...
    $sql = "SELECT media_upload_time FROM {$_TABLES['mg_media_albums']} as ma INNER JOIN " . $_TABLES['mg_media'] . " as m " . " ON ma.media_id=m.media_id WHERE ma.album_id=" . $album_id . " ORDER BY media_upload_time DESC LIMIT 1";
    $result = DB_query($sql);
    $nRows = DB_numRows($result);
    if ($nRows > 0) {
        $row = DB_fetchArray($result);
        DB_query("UPDATE {$_TABLES['mg_albums']} set last_update='" . $row['media_upload_time'] . "' WHERE album_id=" . $album_id);
    }
    MG_SortMedia($album_id);
    MG_SortMedia($destination);
    require_once $_CONF['path'] . 'plugins/mediagallery/include/rssfeed.php';
    MG_buildFullRSS();
    MG_buildAlbumRSS($album_id);
    MG_buildAlbumRSS($destination);
    CACHE_remove_instance('whatsnew');
    echo COM_refresh($actionURL);
    exit;
}
Example #6
0
/**
 * Continues a session - handles timeout, looping, etc.
 *
 * @parm    char    session id to continue
 * @parm    int     number of items to process per run
 *                  0 indicates initial run
 * @return  char    HTML of status screen
 */
function MG_continueSession($session_id, $item_limit, $refresh_rate)
{
    global $MG_albums, $_CONF, $_MG_CONF, $_TABLES, $_USER, $LANG_MG00, $LANG_MG01, $LANG_MG02, $HTTP_SERVER_VARS;
    global $new_media_id, $_GKCONST;
    $retval = '';
    $cycle_start_time = time();
    $temp_time = array();
    $timer_expired = false;
    $num_rows = 0;
    $session_id = COM_applyFilter($session_id);
    // Pull the session status info
    $sql = "SELECT * FROM {$_TABLES['mg_sessions']} WHERE session_id='" . DB_escapeString($session_id) . "'";
    $result = DB_query($sql, 1);
    if (DB_error()) {
        COM_errorLog("MediaGallery:  Error - Unable to retrieve batch session data");
        return '';
    }
    $nRows = DB_numRows($result);
    if ($nRows > 0) {
        $session = DB_fetchArray($result);
    } else {
        COM_errorLog("MediaGallery: Error - Unable to find batch session id");
        return '';
        // no session found
    }
    // security check - make sure we are continuing a session that we own...
    if ($session['session_uid'] != $_USER['uid'] && !$MG_albums[0]->owner_id) {
        $display .= COM_startBlock('', '', COM_getBlockTemplate('_admin_block', 'header'));
        $T = new Template(MG_getTemplatePath(0));
        $T->set_file('admin', 'error.thtml');
        $T->set_var('site_url', $_CONF['site_url']);
        $T->set_var('site_admin_url', $_CONF['site_admin_url']);
        $T->set_var('errormessage', $LANG_MG00['access_denied_msg']);
        $T->parse('output', 'admin');
        $display .= $T->finish($T->get_var('output'));
        $display .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
        $display .= MG_siteFooter();
        return $display;
    }
    // Setup timer information
    $time_limit = $_MG_CONF['def_time_limit'];
    @set_time_limit($time_limit + 20);
    // get execution time
    $max_execution_time = ini_get('max_execution_time');
    if ($time_limit > $max_execution_time) {
        $time_limit = $max_execution_time;
    }
    $label = $session['session_description'];
    // Pull the detail data from the sessions_items table...
    $sql = "SELECT * FROM {$_TABLES['mg_session_items']} WHERE session_id='" . DB_escapeString($session_id) . "' AND status=0 LIMIT " . $item_limit;
    $result = DB_query($sql);
    while (($row = DB_fetchArray($result)) && $timer_expired == false) {
        // used for calculating loop duration and changing the timer condition
        $start_temp_time = time();
        switch ($session['session_action']) {
            case 'watermark':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-watermark.php';
                MG_watermarkBatchProcess($row['aid'], $row['mid']);
                break;
            case 'rebuildthumb':
                $makeSquare = 0;
                $aid = $row['aid'];
                $srcImage = $row['data'];
                $imageThumb = $row['data2'];
                $mimeExt = $row['data3'];
                $mimeType = $row['mid'];
                if ($MG_albums[$aid]->tn_size == 3 || $MG_albums[$aid]->tn_size == 4) {
                    $tnHeight = $MG_albums[$aid]->tnHeight;
                    $tnWidth = $MG_albums[$aid]->tnWidth;
                    if ($MG_albums[$aid]->tn_size == 4) {
                        $makeSquare = 1;
                    }
                } else {
                    if ($_MG_CONF['thumbnail_actual_size'] == 1) {
                        switch ($MG_albums[$aid]->tn_size) {
                            case 0:
                                $tnHeight = 100;
                                $tnWidth = 100;
                                break;
                            case 1:
                                $tnHeight = 150;
                                $tnWidth = 150;
                                break;
                            default:
                                $tnHeight = 200;
                                $tnWidth = 200;
                                break;
                        }
                    } else {
                        $tnHeight = 200;
                        $tnWidth = 200;
                    }
                }
                $tmpImage = '';
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd') {
                    $tmpImage = $_MG_CONF['tmp_path'] . '/wip' . rand() . '.jpg';
                    $rc = IMG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
                    if ($rc == false) {
                        COM_errorLog("MG_convertImage: Error converting uploaded image to jpeg format.");
                        @unlink($srcImage);
                        return false;
                    }
                    if ($makeSquare == 1) {
                        $rc = IMG_squareThumbnail($tmpImage, $imageThumb, $tnWidth, $mimeType, 0);
                    } else {
                        $rc = IMG_resizeImage($tmpImage, $imageThumb, $tnHeight, $tnWidth, $mimeType, 0);
                    }
                } else {
                    if ($makeSquare == 1) {
                        $rc = IMG_squareThumbnail($srcImage, $imageThumb, $tnWidth, $mimeType, 0);
                    } else {
                        $rc = IMG_resizeImage($srcImage, $imageThumb, $tnHeight, $tnWidth, $mimeType, 0);
                    }
                }
                if ($rc == false) {
                    COM_errorLog("MG_convertImage: Error resizing uploaded image to thumbnail size.");
                    @unlink($srcImage);
                }
                break;
            case 'rebuilddisplay':
                $srcImage = $row['data'];
                $imageDisplay = $row['data2'];
                $mimeExt = $row['data3'];
                $mimeType = $row['mid'];
                $aid = $row['aid'];
                $imgsize = @getimagesize("{$srcImage}");
                $imgwidth = $imgsize[0];
                $imgheight = $imgsize[1];
                $tmpImage = '';
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd' || $mimeType == 'image/tiff') {
                    $tmpImage = $_MG_CONF['tmp_path'] . '/wip' . rand() . '.jpg';
                    list($rc, $msg) = IMG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
                    if ($rc == false) {
                        COM_errorLog("MG_libBatch: Error converting uploaded image to jpeg format.");
                    }
                }
                switch ($MG_albums[$aid]->display_image_size) {
                    case 0:
                        $dImageWidth = 500;
                        $dImageHeight = 375;
                        break;
                    case 1:
                        $dImageWidth = 600;
                        $dImageHeight = 450;
                        break;
                    case 2:
                        $dImageWidth = 620;
                        $dImageHeight = 465;
                        break;
                    case 3:
                        $dImageWidth = 720;
                        $dImageHeight = 540;
                        break;
                    case 4:
                        $dImageWidth = 800;
                        $dImageHeight = 600;
                        break;
                    case 5:
                        $dImageWidth = 912;
                        $dImageHeight = 684;
                        break;
                    case 6:
                        $dImageWidth = 1024;
                        $dImageHeight = 768;
                        break;
                    case 7:
                        $dImageWidth = 1152;
                        $dImageHeight = 804;
                        break;
                    case 8:
                        $dImageWidth = 1280;
                        $dImageHeight = 1024;
                        break;
                    case 9:
                        $dImageWidth = $_MG_CONF['custom_image_width'];
                        $dImageHeight = $_MG_CONF['custom_image_height'];
                        break;
                    default:
                        $dImageWidth = 620;
                        $dImageHeight = 465;
                        break;
                }
                if ($imgsize == false || $imgwidth == 0 || $imgheight == 0) {
                    $imgwidth = $dImageWidth;
                    $imgheight = $dImageHeight;
                }
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga') {
                    $fp = @fopen($srcImage, 'rb');
                    if ($fp == false) {
                        $imgwidth = 0;
                        $imgheight = 0;
                    } else {
                        $data = fread($fp, filesize($srcImage));
                        fclose($fp);
                        $imgwidth = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
                        $imgheight = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
                    }
                }
                if ($tmpImage != '') {
                    list($rc, $msg) = IMG_resizeImage($tmpImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0);
                } else {
                    list($rc, $msg) = IMG_resizeImage($srcImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0);
                }
                if ($tmpImage != '') {
                    @unlink($tmpImage);
                }
                break;
            case 'droporiginal':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                if ($_MG_CONF['jhead_enabled'] == 1) {
                    UTL_execWrapper('"' . $_MG_CONF['jhead_path'] . "/jhead" . '"' . " -te " . $row['data'] . " " . $row['data2']);
                }
                @unlink($row['data']);
                break;
            case 'rotate':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/rotate.php';
                MG_rotateMedia($row['aid'], $row['mid'], $row['data'], -1);
                break;
            case 'delete':
                break;
            case 'upgrade':
                break;
            case 'import':
                break;
            case 'ftpimport2':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = intval($row['data2']);
                $baseSrcFile = $row['data3'];
                // basefilename
                $directory = $row['mid'];
                if ($directory == 1) {
                    require_once $_CONF['path'] . 'plugins/mediagallery/include/albumedit.php';
                    $new_aid = MG_quickCreate($album_id, $baseSrcFile);
                    $dir = $srcFile;
                    if (!($dh = @opendir($dir))) {
                        COM_errorLog("Media Gallery: Error - unable process FTP import directory " . $dir);
                    } else {
                        while (($file = readdir($dh)) != false) {
                            if ($file == '..' || $file == '.') {
                                continue;
                            }
                            if ($file == 'Thumbs.db' || $file == 'thumbs.db') {
                                continue;
                            }
                            $filetmp = $dir . '/' . $file;
                            if (is_dir($filetmp)) {
                                $mid = 1;
                            } else {
                                $mid = 0;
                            }
                            $filename = basename($file);
                            $file_extension = strtolower(substr(strrchr($filename, "."), 1));
                            DB_query("INSERT INTO {$_TABLES['mg_session_items']} (session_id,mid,aid,data,data2,data3,status)\n                                      VALUES('" . DB_escapeString($session_id) . "','" . DB_escapeString($mid) . "',{$new_aid},'" . DB_escapeString($filetmp) . "','" . DB_escapeString($purgefiles) . "','" . DB_escapeString($filename) . "',0)");
                            if (DB_error()) {
                                COM_errorLog("Media Gallery: Error - SQL error on inserting record into session_items table");
                            }
                        }
                    }
                } else {
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, '', '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                }
                break;
            case 'galleryimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $baseSrcFile = $row['data2'];
                // basefilename
                $views = (int) $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . ",media_user_id='" . $MG_albums[$album_id]->owner_id . "' WHERE media_id='" . $new_media_id . "'");
                $sql = "SELECT * FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id'];
                $gcmtResult2 = DB_query($sql);
                $cRows = DB_numRows($gcmtResult2);
                for ($z = 0; $z < $cRows; $z++) {
                    $row2 = DB_fetchArray($gcmtResult2);
                    $row2['sid'] = $new_media_id;
                    $row2['type'] = 'mediagallery';
                    $cmtTitle = 'Gallery Comment';
                    $cmtText = $row2['data3'];
                    $cmtDate = (int) $row2['data4'];
                    $cmtIP = $row2['data5'];
                    $cmtUid = 1;
                    if ($row2['data1'] != '' && $row2['data1'] != 'everyone') {
                        $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'data1'])) . "'";
                        $uResult = DB_query($sql);
                        $uRows = DB_numRows($uResult);
                        if ($uRows > 0) {
                            $uRow = DB_fetchArray($uResult);
                            $cmtUid = $uRow['uid'];
                        }
                    }
                    $cmtDate = gmdate("Y-m-d H:i:s", $row2['data4']);
                    MG_saveComment($cmtTitle, $cmtText, $row2['sid'], 0, $row2['type'], 'plain', $cmtUid, $cmtDate, $cmtIP);
                }
                $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                DB_query("DELETE FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id']);
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'coppermineimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $sdata = unserialize($row['mid']);
                $views = (int) $sdata[0];
                $uid = (int) $sdata[1];
                $purgefiles = 0;
                $file = basename($row['data']);
                $baseSrcFile = $file;
                $baseSrcFile = MG_replace_accents($baseSrcFile);
                $baseSrcFile = preg_replace("#[ ]#", "_", $baseSrcFile);
                // change spaces to underscore
                $baseSrcFile = preg_replace('#[^()\\.\\-,\\w]#', '_', $baseSrcFile);
                //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore
                $baseSrcFile = preg_replace('#(_)+#', '_', $baseSrcFile);
                //eliminate duplicate underscore
                $caption = $row['data3'];
                $description = $row['data2'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('{$session_id}','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, $description, 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                if ($rc == true) {
                    $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'";
                    $userResult = DB_query($sql);
                    $userRows = DB_numRows($userResult);
                    if ($userRows > 0) {
                        $userRow = DB_fetchArray($userResult);
                        $glUid = $userRow['uid'];
                    } else {
                        $glUid = 1;
                    }
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . ",media_user_id='" . $glUid . "' WHERE media_id='" . $new_media_id . "'");
                    $sql = "SELECT * FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id'];
                    $gcmtResult2 = DB_query($sql);
                    $cRows = DB_numRows($gcmtResult2);
                    for ($z = 0; $z < $cRows; $z++) {
                        $row2 = DB_fetchArray($gcmtResult2);
                        $row2['sid'] = $new_media_id;
                        $row2['type'] = 'mediagallery';
                        $cmtTitle = 'Coppermine Comment';
                        $cmtText = $row2['data3'];
                        $cmtDate = (int) $row2['data4'];
                        $cmtIP = $row2['data5'];
                        $cmtUid = 1;
                        if ($row2['data1'] != '' && $row2['data1'] != 'everyone') {
                            $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'data1']))) . "'";
                            $uResult = DB_query($sql);
                            $uRows = DB_numRows($uResult);
                            if ($uRows > 0) {
                                $uRow = DB_fetchArray($uResult);
                                $cmtUid = $uRow['uid'];
                            }
                        }
                        $cmtDate = $row2['data4'];
                        // gmdate("Y-m-d H:i:s", $row2['data4']);
                        MG_saveComment($cmtTitle, $cmtText, $row2['sid'], 0, $row2['type'], 'plain', $cmtUid, $cmtDate, $cmtIP);
                    }
                    $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                    DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                }
                DB_query("DELETE FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id']);
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'gallery2import':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $baseSrcFile = $row['data2'];
                // basefilename
                $views = 0;
                // $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('{$session_id}','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . $new_media_id . "'");
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case '4imagesimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $title = $row['data2'];
                $baseSrcFile = basename($row['data']);
                $views = (int) $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'inmemoriamimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                global $INM_TABLES;
                $album_id = $row['aid'];
                $inm_mid = $row['mid'];
                $album_path = $row['data'];
                $inmResult = DB_query("SELECT * FROM {$INM_TABLES['media']} WHERE mid='" . DB_escapeString($inm_mid) . "'");
                $inmNumRows = DB_numRows($inmResult);
                if ($inmNumRows > 0) {
                    $M = DB_fetchArray($inmResult);
                    $srcFile = $album_path . $M['filename'];
                    $baseSrcFile = $M['filename'];
                    $views = (int) $M['hits'];
                    $caption = $M['caption'];
                    $keywords = $M['keywords'];
                    $date = $M['date'];
                    $title = $M['title'];
                    $purgefiles = 0;
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', $keywords, 0, 0, 0);
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                    $sql = "SELECT * FROM {$_TABLES['comments']} WHERE sid='" . $row['mid'] . "' AND type='inmemoriam'";
                    $inmResult2 = DB_query($sql);
                    $cRows = DB_numRows($inmResult2);
                    for ($z = 0; $z < $cRows; $z++) {
                        $row2 = DB_fetchArray($inmResult2);
                        $row2['sid'] = $new_media_id;
                        $row2['type'] = 'mediagallery';
                        MG_saveComment($row2['title'], $row2['comment'], $row2['sid'], 0, $row2['type'], 'plain', $row2['uid'], $row2['date']);
                        $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                        DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                    }
                    // now do the rating...
                    if ($row['totalrating'] > 0) {
                        $rating = $row['totalrating'] / $row['numvotes'];
                        $new_rating = sprintf("%.2f", $rating);
                        $votes = $row['numvotes'];
                        $sql = "UPDATE {$_TABLES['mg_media']} SET media_votes = {$votes}, media_rating = '{$rating}'\n                                        WHERE media_id='" . DB_escapeString($new_media_id) . "'";
                        DB_query($sql);
                    }
                }
                break;
            case 'geekaryimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $album_id = $row['aid'];
                $inm_mid = $row['mid'];
                $gk_album_id = $row['data2'];
                $album_path = $_GKCONST['full_geekage'];
                $inmResult = DB_query("SELECT * FROM {$_TABLES['geekary_images']} WHERE id='" . DB_escapeString($inm_mid) . "'");
                $inmNumRows = DB_numRows($inmResult);
                if ($inmNumRows > 0) {
                    $M = DB_fetchArray($inmResult);
                    $srcFile = $album_path . '/' . $gk_album_id . '/' . $M['file_name'];
                    $baseSrcFile = $M['file_name'];
                    $views = (int) $M['hits'];
                    $caption = $M['description'];
                    $title = $M['name'];
                    $purgefiles = 0;
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', $keywords, 0, 0, 0);
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                }
                break;
            case 'gl_storyimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                require_once $_CONF['path_system'] . 'lib-story.php';
                require_once $_CONF['path_system'] . 'classes/story.class.php';
                $album_id = $row['aid'];
                $srcFile = $row['data'];
                $baseSrcFile = basename($row['data']);
                $sid = $row['data3'];
                $purgefiles = 0;
                $caption = '';
                $imageNumber = $row['data2'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', $mid, 0, 0, 0);
                $mid = $new_media_id;
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                // now update the tag in the article...
                $sResult = DB_query("SELECT * FROM {$_TABLES['stories']} WHERE sid='" . DB_escapeString($sid) . "'");
                $howmany = DB_numRows($sResult);
                $S = DB_fetchArray($sResult);
                $story = new Story();
                $story->loadFromArray($S);
                $intro = $story->replaceImages($S['introtext']);
                $body = $story->replaceImages($S['bodytext']);
                $atag = $session['session_var0'];
                $align = $session['session_var1'];
                $delete = $session['session_var2'];
                $norm = '[image' . $imageNumber . ']';
                $left = '[image' . $imageNumber . '_left]';
                $right = '[image' . $imageNumber . '_right]';
                $mg_norm = '[' . $atag . ':' . $mid . ' align:' . $align . ']';
                $mg_left = '[' . $atag . ':' . $mid . ' align:left]';
                $mg_right = '[' . $atag . ':' . $mid . ' align:right]';
                $intro = str_replace($norm, $mg_norm, $intro);
                $body = str_replace($norm, $mg_norm, $body);
                $intro = str_replace($left, $mg_left, $intro);
                $body = str_replace($left, $mg_left, $body);
                $intro = str_replace($right, $mg_right, $intro);
                $body = str_replace($right, $mg_right, $body);
                $norm = '[unscaled' . $imageNumber . ']';
                $left = '[unscaled' . $imageNumber . '_left]';
                $right = '[unscaled' . $imageNumber . '_right]';
                $mg_norm = '[oimage:' . $mid . ' align:' . $align . ']';
                $mg_left = '[oimage:' . $mid . ' align:left]';
                $mg_right = '[oimage:' . $mid . ' align:right]';
                $intro = str_replace($norm, $mg_norm, $intro);
                $body = str_replace($norm, $mg_norm, $body);
                $intro = str_replace($left, $mg_left, $intro);
                $body = str_replace($left, $mg_left, $body);
                $intro = str_replace($right, $mg_right, $intro);
                $body = str_replace($right, $mg_right, $body);
                DB_query("UPDATE {$_TABLES['stories']} SET introtext='" . DB_escapeString($intro) . "', bodytext='" . DB_escapeString($body) . "' WHERE sid='" . $sid . "'");
                if ($delete == 1) {
                    $sql = "DELETE FROM {$_TABLES['article_images']} WHERE ai_sid='" . DB_escapeString($sid) . "'";
                    DB_query($sql);
                }
                @set_time_limit($time_limit + 20);
                break;
            default:
                // no valid action defined...
                break;
        }
        DB_query("UPDATE {$_TABLES['mg_session_items']} SET status=1 WHERE id=" . $row['id']);
        // calculate time for each loop iteration
        $temp_time[$num_rows] = time() - $start_temp_time;
        // get the max
        $timer_time = max($temp_time);
        $num_rows++;
        // check if timer is about to expire
        if (time() - $cycle_start_time >= $time_limit - $timer_time) {
            $timer_expired_secs = time() - $cycle_start_time;
            $timer_expired = true;
        }
    }
    // end the timer
    $cycle_end_time = time();
    // find how much time the last cycle took
    $last_cycle_time = $cycle_end_time - $cycle_start_time;
    $T = new Template(MG_getTemplatePath(0));
    $T->set_file('batch', 'batch_progress.thtml');
    $processing_messages = '<span style="font-weight:bold;">';
    $processing_messages .= $timer_expired ? sprintf($LANG_MG01['timer_expired'], $timer_expired_secs) : '';
    $processing_messages .= '</span>';
    $sql = "SELECT COUNT(*) as processed FROM {$_TABLES['mg_session_items']} WHERE session_id='" . $session_id . "' AND status=1";
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $session_items_processed = $row['processed'];
    $sql = "SELECT COUNT(*) as processing FROM {$_TABLES['mg_session_items']} WHERE session_id='" . $session_id . "'";
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $session_items_processing = $row['processing'];
    $items_remaining = $session_items_processing - $session_items_processed;
    if ($items_remaining > 0) {
        if ($item_limit == 0) {
            $processing_messages .= '<b>' . $LANG_MG01['begin_processing'] . '</b>';
            $item_limit = $_MG_CONF['def_item_limit'];
        } else {
            $processing_messages .= sprintf('<b>' . $LANG_MG01['processing_next_items'] . '</b>', $item_limit);
        }
        $form_action = $_MG_CONF['site_url'] . '/batch.php?mode=continue&amp;sid=' . $session_id . '&amp;refresh=' . $refresh_rate . '&amp;limit=' . $item_limit;
        $next_button = $LANG_MG01['next'];
        // create the meta tag for refresh
        $T->set_var(array("META" => '<meta http-equiv="refresh" content="' . $refresh_rate . ';url=' . $form_action . '"/>'));
    } else {
        if ($item_limit == 0) {
            echo COM_refresh($session['session_origin']);
            exit;
        }
        $next_button = $LANG_MG01['finished'];
        $processing_messages .= '<b>' . $LANG_MG01['all_done'] . '</b><br /><br />';
        $T->set_var(array("META" => ''));
        $refresh_rate = -1;
        $form_action = $session['session_origin'];
        $result = DB_query("SELECT * FROM {$_TABLES['mg_session_log']} WHERE session_id='" . $session_id . "'");
        $nRows = DB_numRows($result);
        for ($i = 0; $i < $nRows; $i++) {
            $row = DB_fetchArray($result);
            $processing_messages .= $row['session_log'] . '<br />';
        }
        MG_endSession($session_id);
    }
    $session_percent = $session_items_processed / $session_items_processing * 100;
    $session_time = $cycle_end_time - $session['session_start_time'];
    // create the percent boxes
    $pct_box = _mg_create_percent_box('session', _mg_create_percent_color($session_percent), $session_percent);
    $T->set_var(array('L_BATCH_PROCESS' => $label, 'L_BATCH' => $LANG_MG01['batch_processor'], 'L_NEXT' => $next_button, 'L_PROCESSING' => $LANG_MG01['processing'], 'L_CANCEL' => $LANG_MG01['cancel'], 'L_PROCESSING_DETAILS' => $LANG_MG01['processing_details'], 'L_STATUS' => $LANG_MG01['status'], 'L_TOTAL_ITEMS' => $LANG_MG01['total_items'], 'L_ITEMS_PROCESSED' => $LANG_MG01['processed_items'], 'L_ITEMS_REMAINING' => $LANG_MG01['items_remaining'], 'L_POSTS_LAST_CYCLE' => $LANG_MG01['items_last_cycle'], 'L_TIME_LIMIT' => $LANG_MG01['time_limit'], 'L_REFRESH_RATE' => $LANG_MG01['refresh_rate'], 'L_ITEM_RATE' => $LANG_MG01['item_rate'], 'L_ACTIVE_PARAMETERS' => $LANG_MG01['batch_parameters'], 'L_ITEMS_PER_CYCLE' => $LANG_MG01['items_per_cycle'], 'TOTAL_ITEMS' => $session_items_processing, 'ITEMS_PROCESSED' => $session_items_processed, 'ITEMS_REMAINING' => $session_items_processing - $session_items_processed, 'ITEM_RATE' => sprintf($LANG_MG01['seconds_per_item'], round(@($last_cycle_time / $num_rows))), 'PROCESSING_MESSAGES' => $processing_messages, 'SESSION_PERCENT_BOX' => $pct_box, 'SESSION_PERCENT' => sprintf($LANG_MG01['percent_completed'], round($session_percent, 2)), 'POST_LIMIT' => $num_rows, 'ITEM_LIMIT' => $item_limit, 'TIME_LIMIT' => $time_limit, 'REFRESH_RATE' => $refresh_rate, 'PERCENT_COMPLETE' => $session_percent, 'S_BATCH_ACTION' => $form_action));
    $T->parse('output', 'batch');
    $retval .= $T->finish($T->get_var('output'));
    return $retval;
}
Example #7
0
function _processDirectory($target_id, $directory, $parse_sub, $delete, $userid)
{
    global $_CONF, $_MG_CONF, $_TABLES, $LANG_MG02;
    $retmsg = '';
    if ($directory[strlen($directory) - 1] != '/') {
        $directory = $directory . '/';
    }
    if (!@is_dir($directory)) {
        die($directory . ' not a valid directory');
    }
    if (!($dh = @opendir($directory))) {
        die('unable to open directory');
    }
    while (($file = readdir($dh)) != false) {
        if ($file == '..' || $file == '.' || $file == 'desktop.ini' || $file == 'Thumbs.db' || $file == 'thumbs.db') {
            continue;
        }
        $filename = $file;
        $filetmp = $directory . $file;
        $filename = basename($file);
        $file_extension = strtolower(substr(strrchr($filename, "."), 1));
        if (is_dir($filetmp)) {
            if ($parse_sub) {
                require_once $_CONF['path'] . 'plugins/mediagallery/include/albumedit.php';
                $new_aid = MG_quickCreate($target_id, $filename);
                $retmsg .= _processDirectory($target_id, $filetmp, $parse_sub, $delete, $userid) . LB;
            }
        } else {
            $srcFile = $filetmp;
            $album_id = $target_id;
            $purgefiles = $delete;
            $baseSrcFile = $filename;
            $directory = $directory;
            $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
            if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                $retmsg .= $statusMsg . LB;
                continue;
            }
            //This will set the Content-Type to the appropriate setting for the file
            switch ($file_extension) {
                case "exe":
                    $filetype = "application/octet-stream";
                    break;
                case "zip":
                    $filetype = "application/zip";
                    break;
                case "mp3":
                    $filetype = "audio/mpeg";
                    break;
                case "mpg":
                    $filetype = "video/mpeg";
                    break;
                case "avi":
                    $filetype = "video/x-msvideo";
                    break;
                default:
                    $filetype = "application/force-download";
            }
            list($rc, $msg) = _MG_getFile($srcFile, $baseSrcFile, $album_id, '', '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0, $userid);
            $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
            print $statusMsg . LB;
            $retmsg .= $statusMsg . LB;
            MG_SortMedia($album_id);
            @set_time_limit($time_limit + 20);
        }
    }
}
Example #8
0
function MG_batchMoveMedia($album_id, $destination, $media_id_array, $actionURL = '')
{
    global $_USER, $_CONF, $_TABLES, $LANG_MG00;
    // check permissions...
    $sql = "SELECT * FROM {$_TABLES['mg_albums']} WHERE album_id=" . intval($album_id);
    $result = DB_query($sql);
    $A = DB_fetchArray($result);
    $access = SEC_hasAccess($A['owner_id'], $A['group_id'], $A['perm_owner'], $A['perm_group'], $A['perm_members'], $A['perm_anon']);
    if ($access != 3 && !SEC_hasRights('mediagallery.admin')) {
        COM_errorLog("Someone has tried to illegally delete items from album in Media Gallery. " . "User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$REMOTE_ADDR}", 1);
        return COM_showMessageText($LANG_MG00['access_denied_msg']);
    }
    // make sure they are not the same...
    if ($album_id == $destination) {
        echo COM_refresh($actionURL);
        exit;
    }
    // check permissions...
    $sql = "SELECT * FROM {$_TABLES['mg_albums']} WHERE album_id=" . intval($destination);
    $result = DB_query($sql);
    $D = DB_fetchArray($result);
    $access = SEC_hasAccess($D['owner_id'], $D['group_id'], $D['perm_owner'], $D['perm_group'], $D['perm_members'], $D['perm_anon']);
    if ($access != 3 && !SEC_hasRights('mediagallery.admin')) {
        COM_errorLog("Someone has tried to illegally move items from album in Media Gallery. " . "User id: {$_USER['uid']}, Username: {$_USER['username']}, IP: {$REMOTE_ADDR}", 1);
        return COM_showMessageText($LANG_MG00['access_denied_msg']);
    }
    // get max order for destination album....
    $sql = "SELECT MAX(media_order) + 10 AS media_seq " . "FROM {$_TABLES['mg_media_albums']} WHERE album_id = " . intval($destination);
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $media_seq = $row['media_seq'];
    if ($media_seq < 10) {
        $media_seq = 10;
    }
    // ok to move media objects, we will need a destination album.
    // we will also need to get the max order value so we can put all of these at the top
    // of the new album.
    $aMediaCount = $A['media_count'];
    $dMediaCount = $D['media_count'];
    $numItems = count($media_id_array);
    for ($i = 0; $i < $numItems; $i++) {
        $media_id = $media_id_array[$i];
        $sql = "UPDATE {$_TABLES['mg_media_albums']} " . "SET album_id=" . intval($destination) . ", media_order=" . intval($media_seq) . " WHERE album_id=" . intval($album_id) . " AND media_id='" . addslashes($media_id) . "'";
        DB_query($sql);
        $media_seq += 10;
        // update the media count in both albums...
        $aMediaCount--;
        $dMediaCount++;
    }
    DB_change($_TABLES['mg_albums'], 'media_count', $aMediaCount, 'album_id', intval($album_id));
    DB_change($_TABLES['mg_albums'], 'media_count', $dMediaCount, 'album_id', intval($destination));
    MG_resetAlbumCover($album_id);
    MG_resetAlbumCover($destination);
    // reset the last_update field...
    MG_updateAlbumLastUpdate($album_id);
    MG_updateAlbumLastUpdate($destination);
    MG_SortMedia($album_id);
    MG_SortMedia($destination);
    require_once $_CONF['path'] . 'plugins/mediagallery/include/rssfeed.php';
    MG_buildFullRSS();
    MG_buildAlbumRSS($album_id);
    MG_buildAlbumRSS($destination);
    echo COM_refresh($actionURL);
    exit;
}