/** * Upload new photo, delete old photo * * @param string $delete_photo 'on': delete old photo * @return string filename of new photo (empty = no new photo) * */ function USER_handlePhotoUpload($uid, $delete_photo = '') { global $_CONF, $_TABLES, $LANG24; USES_class_upload(); $upload = new upload(); if (!empty($_CONF['image_lib'])) { $upload->setAutomaticResize(true); if (isset($_CONF['debug_image_upload']) && $_CONF['debug_image_upload']) { $upload->setLogFile($_CONF['path'] . 'logs/error.log'); $upload->setDebug(true); } } $upload->setAllowedMimeTypes(array('image/gif' => '.gif', 'image/jpeg' => '.jpg,.jpeg', 'image/pjpeg' => '.jpg,.jpeg', 'image/x-png' => '.png', 'image/png' => '.png')); if (!$upload->setPath($_CONF['path_images'] . 'userphotos')) { return ''; } $filename = ''; if (!empty($delete_photo) && $delete_photo == 1) { $delete_photo = true; } else { $delete_photo = false; } $curphoto = DB_getItem($_TABLES['users'], 'photo', "uid = " . (int) $uid); if (empty($curphoto)) { $delete_photo = false; } // see if user wants to upload a (new) photo $newphoto = $_FILES['photo']; if (!empty($newphoto['name'])) { $pos = strrpos($newphoto['name'], '.') + 1; $fextension = substr($newphoto['name'], $pos); $filename = $uid . '.' . $fextension; if (!empty($curphoto) && $filename != $curphoto) { $delete_photo = true; } else { $delete_photo = false; } } // delete old photo first if ($delete_photo) { USER_deletePhoto($curphoto); } // now do the upload if (!empty($filename)) { $upload->setFileNames($filename); $upload->setFieldName('photo'); $upload->setPerms('0644'); $upload->setMaxDimensions(1024000, 1024000); $upload->uploadFiles(); if ($upload->areErrors()) { return ''; } IMG_resizeImage($_CONF['path_images'] . 'userphotos/' . $filename, $_CONF['path_images'] . 'userphotos/' . $filename, $_CONF['max_photo_height'], $_CONF['max_photo_width']); } else { if (!$delete_photo && !empty($curphoto)) { $filename = $curphoto; } } return $filename; }
protected function _DBupdate_users($uid, $users) { global $_TABLES, $_CONF; $sql = "UPDATE {$_TABLES['users']} SET remoteusername = '******'remoteusername']) . "', remoteservice = '" . DB_escapeString($users['remoteservice']) . "' "; if (!empty($users['remotephoto'])) { $save_img = $_CONF['path_images'] . 'userphotos/' . $uid; $imgsize = $this->_saveUserPhoto($users['remotephoto'], $save_img); if ($imgsize > 0) { $ext = $this->_getImageExt($save_img); $image = $save_img . $ext; if (file_exists($image)) { unlink($image); } rename($save_img, $image); if ($_CONF['max_photo_width'] > 0 && $_CONF['max_photo_height'] > 0) { $upWidth = $_CONF['max_photo_width']; $upHeight = $_CONF['max_photo_height']; } else { $upWidth = $_CONF['max_image_width']; $upHeight = $_CONF['max_image_height']; } IMG_resizeImage($image, $image, $upHeight, $upWidth); $imgname = $uid . $ext; $sql .= ", photo = '" . DB_escapeString($imgname) . "'"; } } $sql .= " WHERE uid = " . (int) $uid; DB_query($sql); }
/** * This function actually completes the upload of a file * * @access private * @return boolean true if copy succeeds otherwise false * */ function _copyFile() { if (!is_writable($this->_fileUploadDirectory)) { // Developer didn't check return value of setPath() method which would // have told them the upload directory was not writable. Error out now $this->_addError('Specified upload directory, ' . $this->_fileUploadDirectory . ' exists but is not writable'); return false; } $sizeOK = true; if (!$this->_imageSizeOK(false) and $this->_autoResize) { $imageInfo = $this->_getImageDimensions($this->_currentFile['tmp_name']); if ($imageInfo['width'] > $this->_maxImageWidth) { $sizeOK = false; } if ($imageInfo['height'] > $this->_maxImageHeight) { $sizeOK = false; } } if (isset($this->_currentFile['_data_dir']) && $this->_currentFile['_data_dir']) { $returnMove = @copy($this->_currentFile['tmp_name'], $this->_fileUploadDirectory . '/' . $this->_getDestinationName()); @unlink($this->_currentFile['tmp_name']); } else { $returnMove = move_uploaded_file($this->_currentFile['tmp_name'], $this->_fileUploadDirectory . '/' . $this->_getDestinationName()); } if (!$sizeOK) { // OK, resize $sizefactor = $this->_calcSizefactor($imageInfo['width'], $imageInfo['height']); $newwidth = (int) ($imageInfo['width'] * $sizefactor); $newheight = (int) ($imageInfo['height'] * $sizefactor); $newsize = $newwidth . 'x' . $newheight; if (!$this->_keepOriginalFile($this->_fileUploadDirectory . '/' . $this->_getDestinationName())) { exit; } list($retval, $msg) = IMG_resizeImage($this->_fileUploadDirectory . '/' . $this->_getDestinationName(), $this->_fileUploadDirectory . '/' . $this->_getDestinationName(), $newheight, $newwidth, $this->_currentFile['type'], 0); if ($retval !== true) { $this->_addError('Image, ' . $this->_currentFile['name'] . ' ' . $msg); $this->printErrors(); exit; } else { $this->_addDebugMsg('Image, ' . $this->_currentFile['name'] . ' was resized from ' . $imageInfo['width'] . 'x' . $imageInfo['height'] . ' to ' . $newsize); } } $returnChmod = true; $perms = $this->_getPermissions(); if (!empty($perms)) { $returnChmod = @chmod($this->_fileUploadDirectory . '/' . $this->_getDestinationName(), octdec($perms)); } if ($returnMove and $returnChmod) { return true; } else { if (!$returnMove) { $this->_addError('Upload of ' . $this->_currentFile['name'] . ' failed.'); } if (!$returnChmod) { $this->_addError('Chmod of ' . $this->_currentFile['name'] . ' to ' . $perms . ' failed'); } return false; } }
/** * 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&sid=' . $session_id . '&refresh=' . $refresh_rate . '&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; }
/** * Save the current values to the database. * * @param array $A Optional array of values from $_POST * @return boolean True if no errors, False otherwise */ public function Save($A = array()) { global $_TABLES, $_PP_CONF; if (is_array($A)) { $this->SetVars($A); } // Handle image uploads. // We don't want to delete the existing image if one isn't // uploaded, we should leave it unchanged. So we'll first // retrieve the existing image filename, if any. if (!$this->isNew) { $img_filename = DB_getItem($_TABLES['paypal.categories'], 'image', "cat_id='" . $this->cat_id . "'"); } else { // New entry, assume no image $img_filename = ''; } if (is_uploaded_file($_FILES['imagefile']['tmp_name'])) { $img_filename = rand(100, 999) . "_" . COM_sanitizeFilename($_FILES['imagefile']['name'], true); $status = IMG_resizeImage($_FILES['imagefile']['tmp_name'], $_PP_CONF['catimgpath'] . "/{$img_filename}", $_PP_CONF['max_thumb_size'], $_PP_CONF['max_thumb_size'], '', true); if ($status[0] == false) { $this->AddError('Error Moving Image'); } else { // If a new image was uploaded, and this is an existing // category, then delete the old image file, if any. // The DB still has the old filename at this point. if (!$this->isNew) { $this->DeleteImage(false); } } } $this->image = $img_filename; // Insert or update the record, as appropriate, as long as a // previous error didn't occur. if (empty($this->Errors)) { if ($this->isNew) { $sql1 = "INSERT INTO {$_TABLES['paypal.categories']} SET "; $sql3 = ''; } else { $sql1 = "UPDATE {$_TABLES['paypal.categories']} SET "; $sql3 = " WHERE cat_id='{$this->cat_id}'"; } $sql2 = "parent_id='" . $this->parent_id . "',\n cat_name='" . DB_escapeString($this->cat_name) . "',\n description='" . DB_escapeString($this->description) . "',\n enabled='{$this->enabled}',\n grp_access ='{$this->grp_access}',\n image='" . DB_escapeString($this->image) . "'"; $sql = $sql1 . $sql2 . $sql3; DB_query($sql); if (!DB_error()) { if ($this->isNew) { $this->cat_id = DB_insertID(); } } else { $this->AddError('Failed to insert or update record'); } } if (empty($this->Errors)) { return true; } else { return false; } }
function MG_attachThumbnail($aid, $thumbnail, $mediaFilename) { global $_CONF, $_MG_CONF, $MG_albums; $makeSquare = 0; if ($_MG_CONF['verbose']) { COM_errorLog("MG Upload: Processing attached thumbnail: " . $thumbnail); } 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; } } $tn_mime_type = IMG_getMediaMetaData($thumbnail); if (!isset($tn_mime_type['mime_type'])) { $tn_mime_type['mime_type'] = ''; } switch ($tn_mime_type['mime_type']) { case 'image/gif': $tnExt = '.gif'; break; case 'image/jpeg': case 'image/jpg': $tnExt = '.jpg'; break; case 'image/png': $tnExt = '.png'; break; case 'image/bmp': $tnExt = '.bmp'; break; default: COM_errorLog("MG_attachThumbnail: Invalid graphics type for attached thumbnail."); return false; } $attach_tn = $mediaFilename . $tnExt; if ($makeSquare) { list($rc, $msg) = IMG_squareThumbnail($thumbnail, $attach_tn, $tnWidth, $tn_mime_type['mime_type'], 1); } else { list($rc, $msg) = IMG_resizeImage($thumbnail, $attach_tn, $tnHeight, $tnWidth, $tn_mime_type['mime_type'], 1); } return true; }
/** * Resize an image to the specified dimensions, placing the resulting * image in the specified location. At least one of $newWidth or * @deprecated 1.0.8 * $newHeight must be specified. * @return string Blank if successful, error message otherwise. */ public function MakeThumbs() { global $_CONF_ADVT, $LANG_PHOTO; if (!is_array($this->_fileNames)) { return; } $thumbsize = (int) $_CONF_ADVT['thumb_max_size']; foreach ($this->_fileNames as $filename) { $src = "{$this->pathImage}/{$filename}"; $dst = "{$this->pathThumb}/{$filename}"; // If parent::upload() dropped the file due to some restriction, // then the source won't be there even though the file info is. if (!file_exists($src)) { continue; } USES_lglib_class_image(); // Calculate the new dimensions list($dWidth, $dHeight) = lgImage::reDim($src, $thumbsize, $thumbsize); //$this->reDim($src, $thumbsize, $thumbsize); if ($dWidth == 0 || $dHeight == 0) { $this->_addError("MakeThumbs() {$filename} could not get dimensions"); return; } // Returns an array, with [0] either true/false and [1] // containing a message. For older versions of glFusion, // we call Media Gallery's _mg_resizeImage() as a backup. This // won't work if MG isn't enabled. list($retval, $msg) = IMG_resizeImage($src, $dst, $dHeight, $dWidth, $this->mime_type); if ($retval != true) { $this->_addError("MakeThumbs() : {$filename} - {$msg}"); } else { $this->goodfiles[] = $filename; } } }
function MG_bpResizeDisplay($aid, $media_id) { global $MG_albums, $_CONF, $_TABLES, $_MG_CONF, $LANG_MG01; if ($_MG_CONF['discard_original'] == 1) { return true; } if ($MG_albums[$aid]->access != 3) { return true; } require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php'; $sql = "SELECT * FROM {$_TABLES['mg_media']} WHERE media_id='" . DB_escapeString($media_id) . "'"; $result = DB_query($sql); if (DB_numRows($result) > 0) { $row = DB_fetchArray($result); @set_time_limit(30); $imageDisplay = ''; $srcImage = ''; if ($_MG_CONF['discard_original'] == 1) { foreach ($_MG_CONF['validExtensions'] as $ext) { if (file_exists($_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext)) { $imageDisplay = $_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext; $srcImage = $_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext; break; } } } else { $srcImage = $_MG_CONF['path_mediaobjects'] . 'orig/' . $row['media_filename'][0] . '/' . $row['media_filename'] . '.' . $row['media_mime_ext']; foreach ($_MG_CONF['validExtensions'] as $ext) { if (file_exists($_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext)) { $imageDisplay = $_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext; break; } } if ($imageDisplay == '') { switch ($row['mime_type']) { case 'image/jpeg': case 'image/jpg': $ext = '.jpg'; break; case 'image/png': $ext = '.png'; break; case 'image/gif': $ext = '.gif'; break; case 'image/bmp': $ext = '.bmp'; break; default: $ext = '.jpg'; break; } $imageDisplay = $_MG_CONF['path_mediaobjects'] . 'disp/' . $row['media_filename'][0] . '/' . $row['media_filename'] . $ext; } } $mimeExt = $row['media_mime_ext']; // actually do the resize here $mimeType = $row['mime_type']; $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."); return true; } } 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); } } return true; }
function _ff_check4files($id, $tempfile = false) { global $_FILES, $_CONF, $_TABLES, $_USER, $_FF_CONF, $LANG_GF00, $_FF_CONF, $filemgmt_FileStore; $retval = ''; for ($z = 1; $z <= $_FF_CONF['maxattachments']; $z++) { $filelinks = ''; $varName = 'file_forum' . $z; $chk_usefilemgmt = 'chk_usefilemgmt' . $z; $filemgmtcat = 'filemgmtcat' . $z; $filemgmt_desc = 'filemgmt_desc' . $z; if (isset($_FILES[$varName]) && is_array($_FILES[$varName])) { $uploadfile = $_FILES[$varName]; } else { $uploadfile['name'] = ''; } if ($uploadfile['name'] != '') { if (isset($_POST[$chk_usefilemgmt]) && $_POST[$chk_usefilemgmt] == 1) { $filename = $uploadfile['name']; $pos = strrpos($uploadfile['name'], '.') + 1; $ext = strtolower(substr($uploadfile['name'], $pos)); } else { $uploadfilename = glfRandomFilename(); $pos = strrpos($uploadfile['name'], '.') + 1; $ext = strtolower(substr($uploadfile['name'], $pos)); $filename = "{$uploadfilename}.{$ext}"; } $set_chk_usefilemgmt = isset($_POST[$chk_usefilemgmt]) ? (int) $_POST[$chk_usefilemgmt] : 0; if (_ff_uploadfile($filename, $uploadfile, $_FF_CONF['allowablefiletypes'], $set_chk_usefilemgmt)) { if (array_key_exists($uploadfile['type'], $_FF_CONF['inlineimageypes'])) { if (isset($_POST[$chk_usefilemgmt]) && $_POST[$chk_usefilemgmt] == 1) { $srcImage = "{$filemgmt_FileStore}{$filename}"; $destImage = "{$_FF_CONF['uploadpath']}/tn/{$filename}"; } else { $srcImage = "{$_FF_CONF['uploadpath']}/{$filename}"; $destImage = "{$_FF_CONF['uploadpath']}/tn/{$uploadfilename}.{$ext}"; } $ret = IMG_resizeImage($srcImage, $destImage, $_FF_CONF['inlineimage_height'], $_FF_CONF['inlineimage_width']); } // Store both the created filename and the real file source filename $realfilename = $filename; $filename = "{$filename}:{$uploadfile['name']}"; if ($tempfile) { $temp = 1; } else { $temp = 0; } if (isset($_POST[$chk_usefilemgmt]) && $_POST[$chk_usefilemgmt] == 1) { $cid = COM_applyFilter($_POST[$filemgmtcat], true); $sql = "INSERT INTO {$_TABLES['filemgmt_filedetail']} (cid, title, url, size, submitter, status,date ) "; $sql .= "VALUES ('" . DB_escapeString($cid) . "', '" . DB_escapeString($realfilename) . "', '" . DB_escapeString($realfilename) . "', '" . DB_escapeString($uploadfile['size']) . "', '{$_USER['uid']}', 1, UNIX_TIMESTAMP())"; DB_query($sql); $newid = DB_insertID(); DB_query("INSERT INTO {$_TABLES['ff_attachments']} (topic_id,repository_id,filename,tempfile)\n VALUES ('" . DB_escapeString($id) . "',{$newid},'" . DB_escapeString($filename) . "',{$temp})"); $description = glfPrepareForDB($_POST[$filemgmt_desc]); DB_query("INSERT INTO {$_TABLES['filemgmt_filedesc']} (lid, description) VALUES ({$newid}, '{$description}')"); } else { DB_query("INSERT INTO {$_TABLES['ff_attachments']} (topic_id,filename,tempfile)\n VALUES ('" . DB_escapeString($id) . "','" . DB_escapeString($filename) . "',{$temp})"); } } else { COM_errorlog("upload error:" . $GLOBALS['ff_errmsg']); $retval .= $GLOBALS['ff_errmsg']; $filelinks = -1; } } } if (!$tempfile and isset($_POST['uniqueid']) and COM_applyFilter($_POST['uniqueid'], true) > 0 and DB_COUNT($_TABLES['ff_topic'], 'id', (int) $id)) { $tid = COM_applyFilter($_POST['uniqueid']); DB_query("UPDATE {$_TABLES['ff_attachments']} SET topic_id=" . (int) $id . ", tempfile=0 WHERE topic_id=" . (int) $tid); } return $retval; }