private function __construct() { $si = ServerInfo::GetCached(); $this->mencoder = $si->binaries[ServerInfo::BIN_MENCODER]; $this->mplayer = $si->binaries[ServerInfo::BIN_MPLAYER]; $this->ffmpeg = $si->binaries[ServerInfo::BIN_FFMPEG]; $this->mp4box = $si->binaries[ServerInfo::BIN_MP4BOX]; $this->yamdi = $si->binaries[ServerInfo::BIN_YAMDI]; $this->convert = $si->binaries[ServerInfo::BIN_CONVERT]; $this->nice = $si->binaries[ServerInfo::BIN_NICE]; }
public static function ExtractEntries($archive, $type) { $si = ServerInfo::GetCached(); if (!$si->php_extensions[ServerInfo::EXT_ZIP]) { throw new BaseException('Sorry, the ZIP extension for PHP is not available on this server'); } $entries = array(); $zip = zip_open($archive); if (!is_resource($zip)) { throw new BaseException('Invalid zip file; zip error #' . $zip . ' generated'); } while (($entry = zip_read($zip)) !== false) { if (!is_resource($entry)) { throw new BaseException('Invalid zip entry; zip error #' . $zip . ' generated'); } $name = zip_entry_name($entry); if (File::Type($name) == $type) { $entries[basename($name)] = self::ExtractEntry($zip, $entry); } } zip_close($zip); return $entries; }
public static function IsRunning() { // Check for empty pid $pid = Cache_MySQL::Get(self::$CACHE_PID); if (empty($pid)) { return false; } // Try to use ps to determine if the process is running $si = ServerInfo::GetCached(); if (!empty($si->binaries[ServerInfo::BIN_PS])) { return preg_match('~' . $pid . '~', shell_exec($si->binaries[ServerInfo::BIN_PS] . " {$pid}")) > 0; } // Try to determine based on last ping $stats = self::LoadStats(); if ($stats[self::STAT_RUNNING]) { if ($stats[self::STAT_LAST_PING] < time() - self::MAX_PING_INTERVAL) { self::MarkStopped(); return false; } return true; } // Last resort, assume not running return false; }
public static function ExecScript($cmd, $background = true) { $si = ServerInfo::GetCached(); $cmd = ($si->php_binary_is_cli ? $si->binaries[ServerInfo::BIN_PHP_CLI] . ' ' . $cmd : $si->binaries[ServerInfo::BIN_PHP_CGI] . ' -q ' . $cmd) . ($background ? ' >/dev/null 2>&1 &' : ''); return shell_exec($cmd); }
<?php $si = ServerInfo::GetCached(); $defaults = array('date_added' => Database_MySQL::Now(), 'status' => STATUS_ACTIVE, 'allow_comments' => 'Yes - Add Immediately', 'allow_ratings' => 1, 'allow_embedding' => 1, 'is_private' => 0); $_REQUEST = array_merge($defaults, $_REQUEST); $DB = GetDB(); $categories = $DB->FetchAll('SELECT `category_id`,`name` FROM `tbx_category` ORDER BY `name`'); $clips = $DB->FetchAll('SELECT * FROM `tbx_video_clip` WHERE `video_id`=?', array(Request::Get('video_id'))); ?> <div id="dialog-header" class="ui-widget-header ui-corner-all"> <div id="dialog-close"></div> <?php echo isset($editing) ? 'Update a Video' : 'Add a Video'; ?> </div> <form method="post" action="ajax.php" enctype="multipart/form-data"> <div id="dialog-panel"> <div style="padding: 8px;"> <?php if (empty($categories)) { ?> <div class="message-error"> You will need to create at least one category before you can begin adding videos </div> <?php } else { ?> <?php if (!isset($editing)) {
public static function CanExtract() { $si = ServerInfo::GetCached(); return !$si->shell_exec_disabled && $si->binaries[ServerInfo::BIN_MENCODER]; }
function tbxDatabaseRestore() { Privileges::Check(Privileges::DATABASE); $filename = BASE_DIR . '/data/' . File::Sanitize(Request::Get('filename')); if (!is_file($filename)) { return JSON::Failure('The file you have selected no longer exists on the server.'); } $si = ServerInfo::GetCached(); if (!$si->shell_exec_disabled && $si->binaries[ServerInfo::BIN_PHP]) { Shell::ExecScript('cron.php --restore --file=' . escapeshellarg($filename)); JSON::Success('Database restore has been started. Allow a few minutes to complete, then continue with the next step of the restore process.'); } else { $DB = GetDB(); $DB->RestoreTables($filename); JSON::Success('Database restore has been completed'); } }
public static function Resize($image, $size, $quality, $directory, $coords = null) { $si = ServerInfo::GetCached(); $directory = Dir::StripTrailingSlash($directory); $letterbox = Config::Get('flag_letterbox'); $resized = $directory . '/' . basename($image); list($dst_width, $dst_height) = explode('x', $size); // See if image is already the correct size $imgsize = @getimagesize($image); if ($imgsize === false) { return null; } else { if (empty($coords) && $imgsize[0] <= $dst_width && $imgsize[1] <= $dst_height) { copy($image, $resized); return $resized; } } $src_width = $imgsize[0]; $src_height = $imgsize[1]; $src_aspect = $src_width / $src_height; $dst_aspect = $dst_width / $dst_height; // Get crop information if $coords was supplied // Generally only occurs when image is extracted from a HTML image map $crop = $crop_x = $crop_y = $crop_width = $crop_height = null; if (!empty($coords)) { $crop = explode(',', str_replace(' ', '', $coords)); // Currently only supporting rect if (count($crop) == 4) { $crop_x = $crop[0]; $crop_y = $crop[1]; $crop_width = $crop[2] - $crop_x; $crop_height = $crop[3] - $crop_y; $src_aspect = $crop_width / $crop_height; } } // Resize with ImageMagick (preferred) if (!$si->shell_exec_disabled && $si->binaries[ServerInfo::BIN_CONVERT]) { if ($letterbox) { shell_exec($si->binaries[ServerInfo::BIN_CONVERT] . ' ' . escapeshellarg($image) . ' ' . (!empty($crop) ? '-crop ' . escapeshellarg($crop_width . 'x' . $crop_height . '!+' . $crop_x . '+' . $crop_y) . ' ' : '') . '-resize ' . $size . ' ' . '-modulate 110,102,100 ' . '-unsharp 1.5x1.2+1.0+0.10 ' . '-enhance ' . '-size ' . $size . ' ' . 'xc:black ' . '+swap ' . '-gravity center ' . '-quality ' . $quality . ' ' . '-format jpeg ' . '-composite ' . escapeshellarg($resized)); } else { $recrop = null; if ($src_aspect > $dst_aspect) { $recrop = '-gravity center -crop ' . escapeshellarg(round($src_height * $dst_aspect) . 'x' . $src_height . '+0+0') . ' '; } else { if ($src_aspect < $dst_aspect) { $recrop = '-gravity center -crop ' . escapeshellarg($src_width . 'x' . round($src_width / $dst_aspect) . '+0+0') . ' '; } } shell_exec($si->binaries[ServerInfo::BIN_CONVERT] . ' ' . escapeshellarg($image) . ' ' . (!empty($crop) ? '-crop ' . escapeshellarg($crop_width . 'x' . $crop_height . '!+' . $crop_x . '+' . $crop_y) . ' ' : '') . (!empty($recrop) ? $recrop : '') . '-resize ' . $size . ' ' . '-modulate 110,102,100 ' . '-unsharp 1.5x1.2+1.0+0.10 ' . '-enhance ' . '-quality ' . $quality . ' ' . '-format jpeg ' . escapeshellarg($resized)); } return $resized; } else { if ($si->php_extensions[ServerInfo::EXT_GD]) { if ($crop) { $temp_src = imagecreatefromjpeg($image); $src = imagecreatetruecolor($crop_width, $crop_height); imagecopy($src, $temp_src, 0, 0, $crop_x, $crop_y, $crop_width, $crop_height); imagedestroy($temp_src); } else { $src = imagecreatefromjpeg($image); } $new_width = $dst_width; $new_height = $dst_height; $dst_x = 0; $dst_y = 0; if ($src_aspect > $dst_aspect) { $new_height = round($dst_width * $src_height / $src_width); $dst_y = ($dst_height - $new_height) / 2; } else { if ($src_aspect < $dst_aspect) { $new_width = round($dst_height * $src_width / $src_height); $dst_x = ($dst_width - $new_width) / 2; } } $dst = imagecreatetruecolor($dst_width, $dst_height); $black = imagecolorallocate($dst, 0, 0, 0); imagefill($dst, 0, 0, 0); imagecopyresampled($dst, $src, $dst_x, $dst_y, 0, 0, $new_width, $new_height, $src_width, $src_height); imagejpeg($dst, $resized, $quality); imagedestroy($src); imagedestroy($dst); return $resized; } } return $image; }
public static function CanGrab() { $si = ServerInfo::GetCached(); return !$si->shell_exec_disabled && $si->binaries[ServerInfo::BIN_MPLAYER]; }