function generate_thumb($path, $prefix, $type = THUMB_SMALL) { global $config, $thumbnail_config; $thumb_config = $thumbnail_config[$type]; // For relative paths assume that they are relative to 'plog-content/images/' directory, // otherwise just use the given path if (file_exists($path)) { $source_file_name = $path; if ($type == THUMB_THEME) { $cache_path = 'themes/'; } else { $cache_path = 'uploads/'; } } else { $source_file_name = $config['basedir'] . 'plog-content/images/' . SmartStripSlashes($path); $cache_path = dirname(SmartStripSlashes($path)) . '/' . $thumb_config['type'] . '/'; } // The file might have been deleted and since phpThumb dies in that case // try to do something sensible so that the rest of the images can still be seen // There is a problem in safe mode - if the script and picture file are owned by // different users, then the file cannot be read. if (!is_readable($source_file_name)) { return false; } $imgdata = @getimagesize($source_file_name); if (!$imgdata) { // Unknown image format, bail out // Do we want to have video support in the Plogger core? //return 'plog-graphics/thumb-video.gif'; return false; } // Attributes of original image $orig_width = $imgdata[0]; $orig_height = $imgdata[1]; // XXX: food for thought - maybe we can return URL to some kind of error image // if this function fails? $base_filename = sanitize_filename(basename($path)); if ($thumb_config['disabled']) { return $config['gallery_url'] . 'plog-content/images/' . $path; } $prefix = $prefix . '-'; $thumbpath = $config['basedir'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename; $thumburl = $config['gallery_url'] . 'plog-content/thumbs/' . $cache_path . $prefix . $base_filename; // If thumbnail file already exists and is generated after data for a thumbnail type // has been changed, then we assume that the thumbnail is valid. if (file_exists($thumbpath)) { $thumbnail_timestamp = @filemtime($thumbpath); if ($thumb_config['timestamp'] < $thumbnail_timestamp) { return $thumburl; } } // Create the same directory structure as the image under plog-content/thumbs/ include_once PLOGGER_DIR . 'plog-admin/plog-admin-functions.php'; if (!makeDirs(dirname($thumbpath))) { return sprintf(plog_tr('Error creating path %s'), dirname($thumbpath)); } // If dimensions of source image are smaller than those of the requested // thumbnail, then use the original image as thumbnail unless fullsize images are disabled if ($orig_width <= $thumb_config['size'] && $orig_height <= $thumb_config['size']) { // if fullsize image access is disabled, copy the file to the thumbs folder if ($config['allow_fullpic'] == 0) { copy($source_file_name, $thumbpath); return $thumburl; // otherwise return the original file path } else { return $config['gallery_url'] . 'plog-content/images/' . $path; } } // No existing thumbnail found or thumbnail config has changed, // generate new thumbnail file require_once PLOGGER_DIR . 'plog-includes/lib/phpthumb/phpthumb.class.php'; $phpThumb = new phpThumb(); // Set data $phpThumb->setSourceFileName($source_file_name); switch ($thumb_config['resize_option']) { // Resize to width case 0: $phpThumb->w = $thumb_config['size']; break; // Resize to height // Resize to height case 1: $phpThumb->h = $thumb_config['size']; break; // Use square thumbnails // Use square thumbnails case 3: $phpThumb->zc = 1; $phpThumb->h = $thumb_config['size']; $phpThumb->w = $thumb_config['size']; break; // Resize to longest side // Resize to longest side case 2: default: if ($imgdata[0] > $imgdata[1]) { $phpThumb->w = $thumb_config['size']; } else { $phpThumb->h = $thumb_config['size']; } } $phpThumb->q = $config['compression']; if ($type == THUMB_NAV) { $phpThumb->zc = 1; $phpThumb->h = $thumb_config['size']; $phpThumb->w = $thumb_config['size']; } if ($type == THUMB_THEME) { $phpThumb->w = $thumb_config['size']; } // Set options (see phpThumb.config.php) // here you must preface each option with "config_" // Disable ImageMagick - set to false for localhost testing // ImageMagick seems to cause some issues on localhost using FF or Chrome $phpThumb->config_prefer_imagemagick = false; // We want to use the original image for thumbnail creation, not the EXIF stored thumbnail $phpThumb->config_use_exif_thumbnail_for_speed = false; // Set error handling (optional) $phpThumb->config_error_die_on_error = false; // If safe_mode enabled, open the permissions first if (is_safe_mode()) { $thumb_path = dirname($thumbpath) . '/'; chmod_ftp($thumb_path, 0777); } // Generate & output thumbnail if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($thumbpath); } else { // do something with debug/error messages die('Failed: ' . implode("\n", $phpThumb->debugmessages)); } @chmod($thumbpath, PLOGGER_CHMOD_FILE); // If safe_mode enabled, close the permissions back down to the default if (is_safe_mode()) { chmod_ftp($thumb_path); } return $thumburl; }
// Let's decompress the zip file into the 'plog-content/uploads/' folder and then redirect the user to plog-import.php include PLOGGER_DIR . 'plog-includes/lib/pclzip-2-4/pclzip.lib.php'; // Zip file to extract $archive = new PclZip($_FILES['userfile']['tmp_name']); // Create a temporary folder in 'plog-content/uploads/' based on the .zip file name $zipname = strtolower(sanitize_filename(substr($_FILES['userfile']['name'], 0, -4))); $zipdir = $config['basedir'] . 'plog-content/uploads/' . $zipname; $zipdirkey = md5($zipdir); $zipresult = makeDirs($zipdir); if (is_safe_mode()) { chmod_ftp($zipdir, 0777); } // Extract to 'plog-content/uploads/' folder $results = $archive->extract(PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $zipdir); if (is_safe_mode()) { chmod_ftp($zipdir); } if ($results == 0) { // Failed $output .= "\n\t" . '<p class="errors">' . plog_tr('Error') . ': ' . $archive->errorInfo(true) . '</p>' . "\n"; } else { // Unzip succeeded - doesn't necessarily mean that saving the images succeeded $errors = array(); foreach ($results as $r) { if ($r['status'] != 'ok') { $errors[] = $r; } } if (empty($errors)) { // Let's redirect to the import interface. header('location: plog-import.php?directory=' . $zipdirkey);
function makeDirs_ftp($path) { global $config, $PLOGGER_FTP; $return = false; $ftp_path = str_replace($config['basedir'], '', $path); $ftp_dir = dirname($ftp_path); $ftp_new_dir = str_replace($ftp_dir . '/', '', $ftp_path); if (!isset($PLOGGER_FTP)) { // Check if connection was made $ftp_connection = connect_ftp(); if ($ftp_connection === false) { return $return; } } ftp_chdir($PLOGGER_FTP, $config['ftp_path'] . $ftp_dir); // Go to destination dir $ftp_create_dir = ftp_mkdir($PLOGGER_FTP, $ftp_new_dir); // Create directory if ($ftp_create_dir) { chmod_ftp($path, 0777); configure_blank_index($path); $chmod = decoct(PLOGGER_CHMOD_DIR); $ftp_exec_dir = ftp_site($PLOGGER_FTP, 'CHMOD ' . $chmod . ' ' . $ftp_new_dir . '/'); } if ($ftp_exec_dir) { $return = true; } else { echo 'could not chmod!'; } return $return; }