case 'image/tiff':
//Converts PSD to PNG temporarily on the real file system.
$tempFile = tempnam('/tmp', 'media_convert');
exec("convert -density 100 ".$this->FilesystemPath."[0] -flatten $tempFile.png");
return imagecreatefrompng("$tempFile.png");
case 'application/pdf':
return PDFMedia::getImage($sourceFile);
case 'application/postscript':
return imagecreatefromstring(shell_exec("gs -r150 -dEPSCrop -dNOPAUSE -dBATCH -sDEVICE=png48 -sOutputFile=- -q $this->FilesystemPath"));
default:
if (!$fileData = @file_get_contents($sourceFile)) {
throw new Exception('Could not load media source: '.$sourceFile);
}
$image = imagecreatefromstring($fileData);
if ($this->MIMEType == 'image/jpeg' && ($exifData = @exif_read_data($sourceFile)) && !empty($exifData['Orientation'])) {
switch ($exifData['Orientation']) {
case 1: // nothing
break;
case 2: // horizontal flip
imageflip($image, IMG_FLIP_HORIZONTAL); // TODO: need PHP 5.3 compat method
break;
case 3: // 180 rotate left
$image = imagerotate($image, 180, null);
break;
case 4: // vertical flip
imageflip($image, IMG_FLIP_VERTICAL); // TODO: need PHP 5.3 compat method
break;
case 5: // vertical flip + 90 rotate right
imageflip($image, IMG_FLIP_VERTICAL); // TODO: need PHP 5.3 compat method
$image = imagerotate($image, -90, null);
"Could not load media source: /sites/ontrayv2/site-data/media/original/8795.jpg"
}
if (static::$useFaceDetection && extension_loaded('facedetect')) {
Cache::store($cacheKey, time());
set_time_limit(static::$faceDetectionTimeLimit);
$cropper = new CropFace($this->FilesystemPath);
} else {
$cropper = new stojg\crop\CropEntropy($this->FilesystemPath);
}
$croppedImage = $cropper->resizeAndCrop($thumbWidth, $thumbHeight);
$croppedImage->writeimage($thumbPath);
set_time_limit($originalTimeLimit);
Cache::delete($cacheKey);
} else {
// load source image
$srcImage = $this->getImage();
$srcWidth = imagesx($srcImage);
$srcHeight = imagesy($srcImage);
// calculate
if ($srcWidth && $srcHeight) {
$widthRatio = ($srcWidth > $maxWidth) ? ($maxWidth / $srcWidth) : 1;
$heightRatio = ($srcHeight > $maxHeight) ? ($maxHeight / $srcHeight) : 1;
// crop width/height to scale size if fill disabled
if ($cropped) {
$ratio = max($widthRatio, $heightRatio);
} else {
$ratio = min($widthRatio, $heightRatio);
}
$scaledWidth = round($srcWidth * $ratio);
$scaledHeight = round($srcHeight * $ratio);
} else {
$scaledWidth = $maxWidth;
$scaledHeight = $maxHeight;
if ($fillColor) {
$thumbFormat .= 'x'.strtoupper($fillColor);
}
if ($cropped) {
$thumbFormat .= '.cropped';
}
$thumbPath = Site::$rootPath.'/site-data/media/'.$thumbFormat.'/'.$this->Filename;
// look for cached thumbnail
if (!file_exists($thumbPath)) {
// ensure directory exists
$thumbDir = dirname($thumbPath);
if (!is_dir($thumbDir)) {
mkdir($thumbDir, static::$newDirectoryPermissions, true);
}
// create new thumbnail
$this->createThumbnailImage($thumbPath, $maxWidth, $maxHeight, $fillColor, $cropped);
}
// return path
return $thumbPath;
}
public function createThumbnailImage($thumbPath, $maxWidth, $maxHeight, $fillColor = false, $cropped = false)
{
$thumbWidth = $maxWidth;
$thumbHeight = $maxHeight;
if ($cropped && extension_loaded('imagick') && $this->FilesystemPath) {
$originalTimeLimit = ini_get('max_execution_time');
// check for existing facedetect job
$cacheKey = "facedetect:{$thumbPath}";
$faceDetectTime = Cache::fetch($cacheKey);
// a parallel or dead worker is already working on this thumb
"/sites/ontrayv2/site-data/media/500x500/8795.jpg"
"500"
"500"
false
false
static::shiftPath();
$maxWidth = $matches[1];
$maxHeight = $matches[2];
$fillColor = !empty($matches[4]) ? $matches[4] : false;
} else {
$maxWidth = static::$defaultThumbnailWidth;
$maxHeight = static::$defaultThumbnailHeight;
$fillColor = false;
}
if (static::peekPath() == 'cropped') {
static::shiftPath();
$cropped = true;
} else {
$cropped = false;
}
// fetch thumbnail
$thumbPath = $Media->getThumbnail($maxWidth, $maxHeight, $fillColor, $cropped);
// dump it out
header("ETag: media-$Media->ID-$maxWidth-$maxHeight-$fillColor-$cropped");
header("Content-Type: $Media->ThumbnailMIMEType");
header('Content-Length: '.filesize($thumbPath));
readfile($thumbPath);
exit();
}
public static function handleManageRequest()
{
// access control
$GLOBALS['Session']->requireAccountLevel('Staff');
return static::respond('manage');
}
"500"
"500"
false
false
<?php // invoke request handler MediaRequestHandler::handleThumbnailRequest();
if (!empty($GLOBALS['Session'])) {
newrelic_add_custom_parameter('session.token', $GLOBALS['Session']->Handle);
newrelic_add_custom_parameter('session.person_id', $GLOBALS['Session']->PersonID);
}
newrelic_add_custom_parameter('script_path', $_SCRIPT_NODE->FullPath);
}
if (is_callable(static::$onBeforeScriptExecute)) {
call_user_func(static::$onBeforeScriptExecute, $_SCRIPT_NODE);
}
if (class_exists('Emergence\\EventBus')) {
Emergence\EventBus::fireEvent('beforeScriptExecute', 'Site', array(
'node' => $_SCRIPT_NODE,
'exit' => $_SCRIPT_EXIT
));
}
require($_SCRIPT_NODE->RealPath);
if ($_SCRIPT_EXIT) {
exit();
}
}
public static function resolvePath($path, $checkParent = true, $checkCache = true)
{
// special case: request for root collection
if (is_string($path) && (empty($path) || $path == '/')) {
return new Emergence\DAV\RootCollection();
}
// parse path
if (is_array($path)) {
$path = implode('/', $path);
}
// retrieve from filesystem
$fs = static::getFilesystem();
"/sites/ontrayv2/site/site-root/thumbnail.php"
));
}
// if resolved node is a collection, look for _index.php
if (is_a(static::$resolvedNode, 'SiteCollection')) {
$indexNode = static::resolvePath(array_merge($pathResult['searchPath'], array('_index.php')));
if ($indexNode) {
// switch resolvedNode to the index script
static::$resolvedNode = $indexNode;
} elseif (!static::$listCollections) {
// if listing collections is disabled and no index script was found, treat this as not found
return static::respondNotFound();
}
}
// handle php script
if (static::$resolvedNode->MIMEType == 'application/php') {
// TODO: execute _all.php handlers, cache the list of them for the containing collection
return static::executeScript(static::$resolvedNode);
}
// output response
if (is_callable(array(static::$resolvedNode, 'outputAsResponse'))) {
if (is_callable(static::$onBeforeStaticResponse)) {
call_user_func(static::$onBeforeStaticResponse, static::$resolvedNode);
}
if (class_exists('Emergence\\EventBus')) {
Emergence\EventBus::fireEvent('beforeStaticResponse', 'Site', array(
'node' => static::$resolvedNode
));
}
static::$resolvedNode->outputAsResponse();
}
// fallback on notfound handler
return static::respondNotFound();
}
SiteFile {}
'root' => '/tmp/logs',
],
'storage' => [
// Media: one fleet-wide GCS bucket is mounted read-write at /media
// (Cloud Run gcsfuse volume, see the tofu cloud-run-site module),
// holding per-site prefixes {ARCHIVE_HOST}/{handle}/ — populated only
// for sites with qualifying media (rows not attached to a developer's
// profile photo). If this site's prefix exists, root the framework's
// local storage there so MediaRequestHandler serves real originals
// and thumbnails (and can generate thumbnail variants back into the
// bucket); otherwise fall back to disposable tmpfs scratch — a
// no-media site needs no bucket prefix and costs nothing.
'local_root' => is_dir($mediaDir = '/media/'.(getenv('ARCHIVE_HOST') ?: 'unknown-host')."/{$siteHandle}")
? $mediaDir
: "/tmp/data/{$siteHandle}",
],
]);
Site::handleRequest();
| Key | Value |
| requestPath | "thumbnail/8795/500x500/"
|
| resolvedPath | "thumbnail"
|
| resolvedNode | "site-root/thumbnail.php"
|
| pathStack | "8795/500x500/"
|
| Key | Value |
| User | false
|
| Key | Value |
| MYSQL_PORT | "3306"
|
| SITE_DEBUG | "true"
|
| PHPRC | "/hab/svc/site/config_install"
|
| PHP_EXTENSION_SOURCES | "/hab/pkgs/emergence/php5/5.6.40/20240718014634/lib/php/extensions/no-debug-non-zts-20131226"
|
| K_REVISION | "archive-central-00009-76q"
|
| STUDIO_TYPE | "Dockerfile"
|
| CLOUD_RUN_TIMEOUT_SECONDS | "300"
|
| MEDIA_BUCKET | "emergence-legacy-archive-media"
|
| PWD | "/"
|
| PORT | "80"
|
| DB_PORT | "3306"
|
| MYSQL_PASSWORD | "false"
|
| DB_USER | "archive_app"
|
| MYSQL_USER | "false"
|
| HOME | "/"
|
| PHP_EXTENSION_DIR | "/hab/svc/site/config_install/extensions-20131226"
|
| K_SERVICE | "archive-central"
|
| PHP_FPM | "/hab/pkgs/emergence/php5/5.6.40/20240718014634/sbin/php-fpm"
|
| MYSQL_HOST | "169.254.8.1"
|
| HAB_ORIGIN | "emergence-site"
|
| DB_HOST | "10.66.240.5"
|
| SHLVL | "0"
|
| MYSQL_DATABASE | "emergence-site"
|
| MYSQL_HOME | "/hab/svc/site/config"
|
| PHP_ZEND_API_VERSION | "20131226"
|
| SSL_CERT_FILE | "/hab/pkgs/core/cacerts/2021.10.26/20240105224256/ssl/certs/cacert.pem"
|
| ARCHIVE_HOST | "central.menunet.jarv.us"
|
| HAB_LICENSE | "accept-no-persist"
|
| PHP_API_VERSION | "20131106"
|
| PATH | "/hab/pkgs/emergence-site/site/0.0.0/20241119033114/bin:/hab/pkgs/core/bash/5.1/20240105214248/bin:/hab/pkgs/emergence/php-runtime/1.0/20240718015635/bin:/hab/pkgs/core/git/2.33.1/20240106041223/bin:/hab/pkgs/emergence/php5/5.6.40/20240718014634/bin:/hab/pkgs/emergence/php5/5.6.40/20240718014634/sbin:/hab/pkgs/core/expat/2.4.6/20240105215038/bin:/hab/pkgs/core/gettext/0.21/20240105221309/bin:/hab/pkgs/core/openssh/7.9p1/20240106022237/bin:/hab/pkgs/core/openssh/7.9p1/20240106022237/sbin:/hab/pkgs/core/openssh/7.9p1/20240106022237/libexec:/hab/pkgs/core/sed/4.8/20240105212826/bin:/hab/pkgs/core/curl/7.79.1/20240105235730/bin:/hab/pkgs/core/icu/57.2/20240106202710/bin:/hab/pkgs/core/libfcgi/2.4.2/20240106191152/bin:/hab/pkgs/core/libxml2/2.11.5/20240106023845/bin:/hab/pkgs/core/libzip/1.8.0/20240106184154/bin:/hab/pkgs/core/postgresql11-client/11.14/20240106121410/bin:/hab/pkgs/core/zip/3.0/20240107045354/bin:/hab/pkgs/jarvus/ghostscript/9.50/20240717152622/bin:/hab/pkgs/jarvus/imagemagick/7.1.0-45/20240717154037/bin:/hab/pkgs/core/bzip2-musl/1.0.8/20240105230239/bin:/hab/pkgs/core/musl/1.2.2/20240105225813/bin:/hab/pkgs/core/gawk/5.1.0/20240105214723/bin:/hab/pkgs/core/grep/3.7/20240105214031/bin:/hab/pkgs/core/libossp-uuid/1.6.2/20240106023754/bin:/hab/pkgs/core/openssl/1.0.2zi/20240105224424/bin:/hab/pkgs/core/perl/5.34.0/20240105215658/bin:/hab/pkgs/core/openssl-fips/2.0.16/20240105224315/bin:/hab/pkgs/core/bzip2/1.0.8/20240105212113/bin:/hab/pkgs/core/gdbm/1.22/20240105214936/bin:/hab/pkgs/core/db/5.3.28/20240105215139/bin:/hab/pkgs/core/coreutils/8.32/20240105213308/bin:/hab/pkgs/core/less/590/20240105215612/bin:/hab/pkgs/core/acl/2.3.1/20240105212642/bin:/hab/pkgs/core/libcap/2.60/20240105212737/bin:/hab/pkgs/core/attr/2.5.1/20240105212555/bin:/hab/pkgs/core/pcre/8.45/20240105213900/bin:/hab/pkgs/core/ncurses/6.2/20240105212325/bin:/hab/pkgs/core/libtiff/4.3.0/20240107154014/bin:/hab/pkgs/core/jbigkit/2.1/20240106232737/bin:/hab/pkgs/core/libjpeg-turbo/1.5.3/20240106232628/bin:/hab/pkgs/core/libpng/1.6.37/20240106001834/bin:/hab/pkgs/core/xz/5.2.5/20240105221157/bin:/hab/pkgs/core/glibc/2.35/20240105171810/bin:/hab/pkgs/core/busybox-static/1.34.1/20220311112317/bin:/bin"
|
| DB_PASS | "EVSeiSwF4KDXywM9fnl6SIPG4MZMyqoI"
|
| K_CONFIGURATION | "archive-central"
|
| SITE_PKG_PATH | "/hab/pkgs/emergence-site/site/current"
|
| USER | "hab"
|
| FCGI_ROLE | "RESPONDER"
|
| REQUEST_ID | "8dec40d068b0f244bdd7ddab2bd91fb4"
|
| SCRIPT_FILENAME | "/opt/emergence-archive/web/index.php"
|
| QUERY_STRING | "" |
| REQUEST_METHOD | "GET"
|
| CONTENT_TYPE | "" |
| CONTENT_LENGTH | "" |
| SCRIPT_NAME | "/__emergence_dispatch"
|
| REQUEST_URI | "/thumbnail/8795/500x500/"
|
| DOCUMENT_URI | "/thumbnail/8795/500x500/"
|
| DOCUMENT_ROOT | "/sites/ontrayv2/site/site-root"
|
| SERVER_PROTOCOL | "HTTP/1.1"
|
| GATEWAY_INTERFACE | "CGI/1.1"
|
| SERVER_SOFTWARE | "nginx/1.15.6"
|
| REMOTE_ADDR | "127.0.0.1"
|
| REMOTE_PORT | "38636"
|
| SERVER_ADDR | "127.0.0.1"
|
| SERVER_PORT | "80"
|
| SERVER_NAME | "ontrayv2.central.archive.jarv.us"
|
| REDIRECT_STATUS | "200"
|
| SITE_ROOT | "/sites/ontrayv2"
|
| SITE_DB | "ontrayv2"
|
| SITE_HANDLE | "ontrayv2"
|
| HTTPS | "on"
|
| HTTP_HOST | "127.0.0.1"
|
| HTTP_ACCEPT | "*/*"
|
| PHP_SELF | "/__emergence_dispatch"
|
| REQUEST_TIME_FLOAT | 1793637976.6067
|
| REQUEST_TIME | 1793637976
|
| argv | [] |
| argc | 0
|
| Key | Value |
| MYSQL_PORT | "3306"
|
| SITE_DEBUG | "true"
|
| PHPRC | "/hab/svc/site/config_install"
|
| PHP_EXTENSION_SOURCES | "/hab/pkgs/emergence/php5/5.6.40/20240718014634/lib/php/extensions/no-debug-non-zts-20131226"
|
| K_REVISION | "archive-central-00009-76q"
|
| STUDIO_TYPE | "Dockerfile"
|
| CLOUD_RUN_TIMEOUT_SECONDS | "300"
|
| MEDIA_BUCKET | "emergence-legacy-archive-media"
|
| PWD | "/"
|
| PORT | "80"
|
| DB_PORT | "3306"
|
| MYSQL_PASSWORD | "false"
|
| DB_USER | "archive_app"
|
| MYSQL_USER | "false"
|
| HOME | "/"
|
| PHP_EXTENSION_DIR | "/hab/svc/site/config_install/extensions-20131226"
|
| K_SERVICE | "archive-central"
|
| PHP_FPM | "/hab/pkgs/emergence/php5/5.6.40/20240718014634/sbin/php-fpm"
|
| MYSQL_HOST | "169.254.8.1"
|
| HAB_ORIGIN | "emergence-site"
|
| DB_HOST | "10.66.240.5"
|
| SHLVL | "0"
|
| MYSQL_DATABASE | "emergence-site"
|
| MYSQL_HOME | "/hab/svc/site/config"
|
| PHP_ZEND_API_VERSION | "20131226"
|
| SSL_CERT_FILE | "/hab/pkgs/core/cacerts/2021.10.26/20240105224256/ssl/certs/cacert.pem"
|
| ARCHIVE_HOST | "central.menunet.jarv.us"
|
| HAB_LICENSE | "accept-no-persist"
|
| PHP_API_VERSION | "20131106"
|
| PATH | "/hab/pkgs/emergence-site/site/0.0.0/20241119033114/bin:/hab/pkgs/core/bash/5.1/20240105214248/bin:/hab/pkgs/emergence/php-runtime/1.0/20240718015635/bin:/hab/pkgs/core/git/2.33.1/20240106041223/bin:/hab/pkgs/emergence/php5/5.6.40/20240718014634/bin:/hab/pkgs/emergence/php5/5.6.40/20240718014634/sbin:/hab/pkgs/core/expat/2.4.6/20240105215038/bin:/hab/pkgs/core/gettext/0.21/20240105221309/bin:/hab/pkgs/core/openssh/7.9p1/20240106022237/bin:/hab/pkgs/core/openssh/7.9p1/20240106022237/sbin:/hab/pkgs/core/openssh/7.9p1/20240106022237/libexec:/hab/pkgs/core/sed/4.8/20240105212826/bin:/hab/pkgs/core/curl/7.79.1/20240105235730/bin:/hab/pkgs/core/icu/57.2/20240106202710/bin:/hab/pkgs/core/libfcgi/2.4.2/20240106191152/bin:/hab/pkgs/core/libxml2/2.11.5/20240106023845/bin:/hab/pkgs/core/libzip/1.8.0/20240106184154/bin:/hab/pkgs/core/postgresql11-client/11.14/20240106121410/bin:/hab/pkgs/core/zip/3.0/20240107045354/bin:/hab/pkgs/jarvus/ghostscript/9.50/20240717152622/bin:/hab/pkgs/jarvus/imagemagick/7.1.0-45/20240717154037/bin:/hab/pkgs/core/bzip2-musl/1.0.8/20240105230239/bin:/hab/pkgs/core/musl/1.2.2/20240105225813/bin:/hab/pkgs/core/gawk/5.1.0/20240105214723/bin:/hab/pkgs/core/grep/3.7/20240105214031/bin:/hab/pkgs/core/libossp-uuid/1.6.2/20240106023754/bin:/hab/pkgs/core/openssl/1.0.2zi/20240105224424/bin:/hab/pkgs/core/perl/5.34.0/20240105215658/bin:/hab/pkgs/core/openssl-fips/2.0.16/20240105224315/bin:/hab/pkgs/core/bzip2/1.0.8/20240105212113/bin:/hab/pkgs/core/gdbm/1.22/20240105214936/bin:/hab/pkgs/core/db/5.3.28/20240105215139/bin:/hab/pkgs/core/coreutils/8.32/20240105213308/bin:/hab/pkgs/core/less/590/20240105215612/bin:/hab/pkgs/core/acl/2.3.1/20240105212642/bin:/hab/pkgs/core/libcap/2.60/20240105212737/bin:/hab/pkgs/core/attr/2.5.1/20240105212555/bin:/hab/pkgs/core/pcre/8.45/20240105213900/bin:/hab/pkgs/core/ncurses/6.2/20240105212325/bin:/hab/pkgs/core/libtiff/4.3.0/20240107154014/bin:/hab/pkgs/core/jbigkit/2.1/20240106232737/bin:/hab/pkgs/core/libjpeg-turbo/1.5.3/20240106232628/bin:/hab/pkgs/core/libpng/1.6.37/20240106001834/bin:/hab/pkgs/core/xz/5.2.5/20240105221157/bin:/hab/pkgs/core/glibc/2.35/20240105171810/bin:/hab/pkgs/core/busybox-static/1.34.1/20220311112317/bin:/bin"
|
| DB_PASS | "EVSeiSwF4KDXywM9fnl6SIPG4MZMyqoI"
|
| K_CONFIGURATION | "archive-central"
|
| SITE_PKG_PATH | "/hab/pkgs/emergence-site/site/current"
|
| USER | "hab"
|
| FCGI_ROLE | "RESPONDER"
|
| REQUEST_ID | "8dec40d068b0f244bdd7ddab2bd91fb4"
|
| SCRIPT_FILENAME | "/opt/emergence-archive/web/index.php"
|
| QUERY_STRING | "" |
| REQUEST_METHOD | "GET"
|
| CONTENT_TYPE | "" |
| CONTENT_LENGTH | "" |
| SCRIPT_NAME | "/__emergence_dispatch"
|
| REQUEST_URI | "/thumbnail/8795/500x500/"
|
| DOCUMENT_URI | "/thumbnail/8795/500x500/"
|
| DOCUMENT_ROOT | "/sites/ontrayv2/site/site-root"
|
| SERVER_PROTOCOL | "HTTP/1.1"
|
| GATEWAY_INTERFACE | "CGI/1.1"
|
| SERVER_SOFTWARE | "nginx/1.15.6"
|
| REMOTE_ADDR | "127.0.0.1"
|
| REMOTE_PORT | "38636"
|
| SERVER_ADDR | "127.0.0.1"
|
| SERVER_PORT | "80"
|
| SERVER_NAME | "ontrayv2.central.archive.jarv.us"
|
| REDIRECT_STATUS | "200"
|
| SITE_ROOT | "/sites/ontrayv2"
|
| SITE_DB | "ontrayv2"
|
| SITE_HANDLE | "ontrayv2"
|
| HTTPS | "on"
|
| HTTP_HOST | "127.0.0.1"
|
| HTTP_ACCEPT | "*/*"
|
| PHP_SELF | "/__emergence_dispatch"
|
| REQUEST_TIME_FLOAT | 1793637976.6067
|
| REQUEST_TIME | 1793637976
|
| argv | [] |
| argc | 0
|