Skip to content
Permalink
Browse files

Moved to new server

  • Loading branch information
Thoulah committed Nov 6, 2019
1 parent cd6c1f3 commit 3e4fead45cca453ffde9e8fe005f47e0a0e4ce37
@@ -4,7 +4,7 @@
/mister42/controllers/TestController.php
/mister42/models/test/
/mister42/views/test/
/nbproject/
/vendor/
/webroot/php.ini
/.buildpath
/composer.lock
@@ -11,10 +11,10 @@ public function __construct(bool $debug = false, bool $unitTest = false)
define('YII_ENABLE_ERROR_HANDLER', !$unitTest);
}
$loader = require __DIR__ . '/../vendor/autoload.php';
$loader = require __DIR__ . '/vendor/autoload.php';
$loader->setPsr4('mr42\\', __DIR__ . '/mr42/');
$loader->setPsr4('mister42\\', __DIR__ . '/mister42/');
require __DIR__ . '/../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/vendor/yiisoft/yii2/Yii.php';
if ($unitTest) {
return new yii\web\Application($this->loadConfig(['mister42'], 'Web'));
@@ -29,7 +29,8 @@ public function __construct(bool $debug = false, bool $unitTest = false)
private function getConfig(): array
{
switch (yii\helpers\ArrayHelper::getValue($_SERVER, 'SERVER_NAME')) :
$srv = yii\helpers\ArrayHelper::getValue($_SERVER, 'SERVER_NAME');
switch (substr($srv, 0, 4) === 'www.' ? substr($srv, 4) : $srv) :
case 'mister42.me':
return $this->loadConfig(['mister42'], 'Web');
default:
@@ -1,26 +1,26 @@
ExpiresActive On

<FilesMatch "^(day-.*)\.(jpe?g|png|gif)$">
ExpiresDefault "modification plus 5 minutes"
Header set Cache-Control "max-age=300, must-revalidate"
ExpiresDefault "modification plus 5 minutes"
Header set Cache-Control "max-age=300, must-revalidate"
</FilesMatch>

<FilesMatch "^(week-.*)\.(jpe?g|png|gif)$">
ExpiresDefault "modification plus 30 minutes"
Header set Cache-Control "max-age=1800, must-revalidate"
ExpiresDefault "modification plus 30 minutes"
Header set Cache-Control "max-age=1800, must-revalidate"
</FilesMatch>

<FilesMatch "^(month-.*)\.(jpe?g|png|gif)$">
ExpiresDefault "modification plus 1 hour"
Header set Cache-Control "max-age=3600, must-revalidate"
ExpiresDefault "modification plus 1 hour"
Header set Cache-Control "max-age=3600, must-revalidate"
</FilesMatch>

<FilesMatch "^(year-.*)\.(jpe?g|png|gif)$">
ExpiresDefault "modification plus 6 hours"
Header set Cache-Control "max-age=21600, must-revalidate"
ExpiresDefault "modification plus 6 hours"
Header set Cache-Control "max-age=21600, must-revalidate"
</FilesMatch>

<FilesMatch "^(lustrum-.*)\.(jpe?g|png|gif)$">
ExpiresDefault "modification plus 1 day"
Header set Cache-Control "max-age=86400, must-revalidate"
ExpiresDefault "modification plus 1 day"
Header set Cache-Control "max-age=86400, must-revalidate"
</FilesMatch>
@@ -27,7 +27,7 @@ public function getValues(): array
'language' => 'en',
'name' => 'Mr.42',
'params' => $this->params,
'runtimePath' => __DIR__ . '/../../../.cache/yii/mister42',
'runtimePath' => __DIR__ . '/../.cache',
'timeZone' => 'Europe/Berlin',
'vendorPath' => __DIR__ . '/../vendor',
];
@@ -101,13 +101,6 @@ private function getComponents(): array
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => $this->secrets['email']['host'],
'username' => $this->secrets['email']['username'],
'password' => $this->secrets['email']['password'],
'encryption' => 'tls',
],
],
'urlManager' => [
'class' => 'codemix\localeurls\UrlManager',
@@ -2,6 +2,7 @@
namespace app\models;
use Imagick;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
@@ -24,16 +25,15 @@ public static function getAverageImageColor(string $image): string
public static function resize(string $image, int $size): string
{
$process = proc_open("convert -resize {$size} -strip -quality 85% -interlace Plane - jpg:-", [['pipe', 'r'], ['pipe', 'w']], $pipes);
if (is_resource($process)) {
fwrite($pipes[0], $image);
fclose($pipes[0]);
$image = stream_get_contents($pipes[1]);
fclose($pipes[1]);
proc_close($process);
}
$imagick = new Imagick();
$imagick->readImageBlob($image);
$imagick->resizeImage($size, $size, Imagick::FILTER_LANCZOS, 1);
$imagick->stripImage();
$imagick->setImageCompressionQuality(85);
$imagick->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$imagick->setImageFormat('jpg');
$image = (string) $imagick;
$imagick->destroy();
return $image;
}
@@ -3,6 +3,7 @@
namespace app\models\tools;
use app\models\Mailer;
use Imagick;
use Yii;
use yii\helpers\FileHelper;
@@ -28,11 +29,27 @@ public function convertImage(): bool
return false;
}
[$width, $height] = getimagesize($this->sourceImage->tempName);
$tmpSize = min($width, $height);
FileHelper::createDirectory(Yii::getAlias('@assetsroot/temp'));
$cacheFile = Yii::getAlias('@assetsroot/temp/' . uniqid('favicon') . '.ico');
exec("convert {$this->sourceImage->tempName} -gravity center -crop {$tmpSize}x{$tmpSize}+0+0 +repage -resize 256x256 -define icon:auto-resize=" . implode(',', $this->dimensions) . " {$cacheFile}");
$srcImg = new Imagick($this->sourceImage->tempName);
$tmpSize = min($srcImg->getImageGeometry());
$srcImg->setGravity(imagick::GRAVITY_CENTER);
$srcImg->cropImage($tmpSize, $tmpSize, 0, 0);
$srcImg->resizeImage(256, 256, Imagick::FILTER_LANCZOS, 1);
$icon = new Imagick();
$icon->setFormat("ico");
foreach ($this->dimensions as $dim) {
$clone = clone $srcImg;
$clone->scaleImage($dim, 0);
$icon->addImage($clone);
$clone->destroy();
}
$icon->writeImages($cacheFile, true);
$icon->destroy();
$srcImg->destroy();
FileHelper::unlink($this->sourceImage->tempName);
if ($this->recipient) {
@@ -79,6 +79,6 @@
echo Accordion::widget([
'encodeLabels' => false,
'items' => $items,
'itemToggleOptions' => ['class' => 'stretched-link text-left notranslate'],
'itemToggleOptions' => ['class' => 'text-left notranslate'],
]);
echo Html::endTag('div');
@@ -13,17 +13,17 @@ class DownloadController extends \yii\web\Controller
public function actionPhp($version): void
{
FileHelper::createDirectory(Yii::getAlias('@assetsroot/temp'));
$phpFile = Yii::getAlias("@webroot/../../../bin/php{$version}-cli");
$phpFile = Yii::getAlias("@webroot/../../bin/php{$version}-cli");
$archiveFile = Yii::getAlias('@assetsroot/temp/') . uniqid("php{$version}-") . '.tar';
$compressedFile = $archiveFile . '.bz2';
if (!is_readable($phpFile)) {
throw new HttpException(404, 'The requested file could not be found.');
}
$a = new PharData($archiveFile);
$a->addFile(Yii::getAlias("@webroot/../../../bin/php{$version}-cli"), "bin/php{$version}-cli");
$a->addFile(Yii::getAlias("@webroot/../../bin/php{$version}-cli"), "bin/php{$version}-cli");
foreach (['libonig.so.2'] as $file) {
$a->addFile(Yii::getAlias("@webroot/../../../bin/lib/{$file}"), "bin/lib/{$file}");
$a->addFile(Yii::getAlias("@webroot/../../bin/lib/{$file}"), "bin/lib/{$file}");
}
$a->convertToData(Phar::TAR, Phar::BZ2);
FileHelper::unlink($archiveFile);
@@ -1,7 +1,6 @@
Options -Indexes -MultiViews +FollowSymlinks
AddDefaultCharset UTF-8
SetEnv TZ Europe/Berlin
Header always set Strict-Transport-Security "max-age=10886400; includeSubDomains; preload" env=HTTPS
Header set Connection keep-alive

<IfModule mod_rewrite.c>
@@ -35,14 +34,12 @@ Header set Connection keep-alive
# Caching
FileETag All

<IfModule mod_headers.c>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=900, private, must-revalidate"
</FilesMatch>
<FilesMatch "\.(ico)$">
Header set Cache-Control "max-age=900, private, must-revalidate"
</FilesMatch>

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

# Compression
SetOutputFilter DEFLATE

0 comments on commit 3e4fead

Please sign in to comment.
You can’t perform that action at this time.