Merge branch 'feature-fixe-archived'
This commit is contained in:
commit
c93e838627
|
@ -7,9 +7,10 @@ cache:
|
|||
- $HOME/.composer/cache
|
||||
|
||||
php:
|
||||
- 5.6.30
|
||||
- 7.0.21
|
||||
- 7.1.7
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
|
||||
matrix:
|
||||
fast_finish: true
|
||||
|
|
|
@ -1,148 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace b8;
|
||||
|
||||
class Image
|
||||
{
|
||||
public static $cachePath = '/tmp/';
|
||||
public static $sourcePath = './';
|
||||
|
||||
/**
|
||||
* @var \Imagick
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function __construct($imagePath)
|
||||
{
|
||||
$this->setSource(new \Imagick(self::$sourcePath . $imagePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Imagick
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return $this->source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Imagick $image
|
||||
*/
|
||||
public function setSource(\Imagick $image)
|
||||
{
|
||||
$this->source = $image;
|
||||
}
|
||||
|
||||
public function render($media, $width, $height, $format = 'jpeg')
|
||||
{
|
||||
$cachePath = self::$cachePath . $media['fileId'] . '.' . $width . 'x' . $height . '.' . $format;
|
||||
|
||||
if(file_exists($cachePath) && 0)
|
||||
{
|
||||
$output = file_get_contents($cachePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output = $this->doRender($media, $width, $height, $format);
|
||||
file_put_contents($cachePath, $output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function doRender($media, $width, $height, $format = 'jpeg')
|
||||
{
|
||||
$focal = !empty($media['focal_point']) ? $media['focal_point'] : [0, 0];
|
||||
$focalX = (int)$focal[0];
|
||||
$focalY = (int)$focal[1];
|
||||
|
||||
$width = (int)$width;
|
||||
$height = (int)$height;
|
||||
|
||||
$source = $this->getSource();
|
||||
$sourceWidth = $source->getImageWidth();
|
||||
$sourceHeight = $source->getImageHeight();
|
||||
$sourceRatio = $sourceWidth / $sourceHeight;
|
||||
$targetRatio = $height != 'auto' ? $width / $height : $sourceRatio;
|
||||
|
||||
$quads = $this->getQuadrants($sourceWidth, $sourceHeight);
|
||||
|
||||
foreach($quads as $name => $l)
|
||||
{
|
||||
if($focalX >= $l[0] && $focalX <= $l[1] && $focalY >= $l[2] && $focalY <= $l[3])
|
||||
{
|
||||
$useQuad = $name;
|
||||
}
|
||||
}
|
||||
|
||||
if($sourceRatio <= $targetRatio)
|
||||
{
|
||||
$scale = $sourceWidth / $width;
|
||||
}
|
||||
else
|
||||
{
|
||||
$scale = $sourceHeight / $height;
|
||||
}
|
||||
|
||||
$resizeWidth = (int)($sourceWidth / $scale);
|
||||
$resizeHeight = (int)($sourceHeight / $scale);
|
||||
|
||||
if($height == 'auto')
|
||||
{
|
||||
$height = $resizeHeight;
|
||||
}
|
||||
|
||||
$source->scaleImage($resizeWidth, $resizeHeight);
|
||||
|
||||
switch($useQuad)
|
||||
{
|
||||
case 'top_left':
|
||||
$cropX = 0;
|
||||
$cropY = 0;
|
||||
break;
|
||||
|
||||
case 'top_right':
|
||||
$cropX = ($resizeWidth - $width);
|
||||
$cropY = 0;
|
||||
break;
|
||||
|
||||
case 'middle_left':
|
||||
$cropX = 0;
|
||||
$cropY = ($resizeHeight - $height) / 2;
|
||||
break;
|
||||
|
||||
case 'middle-right':
|
||||
$cropX = ($resizeWidth - $width);
|
||||
$cropY = ($resizeHeight - $height) / 2;
|
||||
break;
|
||||
|
||||
case 'bottom_left':
|
||||
$cropX = 0;
|
||||
$cropY = ($resizeHeight - $height);
|
||||
break;
|
||||
|
||||
case 'bottom_right':
|
||||
$cropX = ($resizeWidth - $width);
|
||||
$cropY = ($resizeHeight - $height);
|
||||
break;
|
||||
}
|
||||
|
||||
$source->cropImage($width, $height, $cropX, $cropY);
|
||||
$source->setImageFormat($format);
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
protected function getQuadrants($x, $y)
|
||||
{
|
||||
$rtn = [];
|
||||
$rtn['top_left'] = [0, $x / 2, 0, $y / 3];
|
||||
$rtn['top_right'] = [($x / 2) + 1, $x, 0, $y / 3];
|
||||
$rtn['middle_left'] = [0, $y / 2, ($y / 3)+1, (($y / 3) * 2)];
|
||||
$rtn['middle_right'] = [($x / 2) + 1, $x, ($y / 3)+1, (($y / 3) * 2)];
|
||||
$rtn['bottom_left'] = [0, $y / 2, (($y / 3) * 2)+1, $y];
|
||||
$rtn['bottom_right'] = [($x / 2) + 1, $x, (($y / 3) * 2)+1, $y];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ use PHPCensor\Controller;
|
|||
|
||||
/**
|
||||
* Build Status Controller - Allows external access to build status information / images.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildStatusController extends Controller
|
||||
|
@ -30,26 +30,34 @@ class BuildStatusController extends Controller
|
|||
public function init()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
$this->buildStore = Store\Factory::getStore('Build');
|
||||
$this->projectStore = Store\Factory::getStore('Project');
|
||||
|
||||
$this->buildStore = Store\Factory::getStore('Build');
|
||||
$this->projectStore = Store\Factory::getStore('Project');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns status of the last build
|
||||
*
|
||||
* @param $projectId
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStatus($projectId)
|
||||
{
|
||||
$status = null;
|
||||
$branch = $this->getParam('branch', 'master');
|
||||
|
||||
try {
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
$status = 'passing';
|
||||
|
||||
if (isset($project) && $project instanceof Project) {
|
||||
$build = $project->getLatestBuild($branch, [2,3]);
|
||||
$build = $project->getLatestBuild($branch, [
|
||||
Build::STATUS_SUCCESS,
|
||||
Build::STATUS_FAILED,
|
||||
]);
|
||||
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() != 2) {
|
||||
if (isset($build) && $build instanceof Build && $build->getStatus() !== Build::STATUS_SUCCESS) {
|
||||
$status = 'failed';
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +72,9 @@ class BuildStatusController extends Controller
|
|||
* Displays projects information in ccmenu format
|
||||
*
|
||||
* @param $projectId
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws b8\Exception\HttpException
|
||||
*/
|
||||
|
@ -103,7 +113,8 @@ class BuildStatusController extends Controller
|
|||
|
||||
/**
|
||||
* @param \SimpleXMLElement $xml
|
||||
* @return bool
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function renderXml(\SimpleXMLElement $xml = null)
|
||||
{
|
||||
|
@ -140,6 +151,7 @@ class BuildStatusController extends Controller
|
|||
if (is_null($status)) {
|
||||
$response = new b8\Http\Response\RedirectResponse();
|
||||
$response->setHeader('Location', '/');
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -151,7 +163,7 @@ class BuildStatusController extends Controller
|
|||
$color,
|
||||
$style
|
||||
);
|
||||
|
||||
|
||||
foreach ($optionalParams as $paramName => $param) {
|
||||
if ($param) {
|
||||
$imageUrl .= '&' . $paramName . '=' . $param;
|
||||
|
@ -186,7 +198,7 @@ class BuildStatusController extends Controller
|
|||
{
|
||||
$project = $this->projectStore->getById($projectId);
|
||||
|
||||
if (empty($project) || !$project->getAllowPublicStatus() || $project->getArchived()) {
|
||||
if (empty($project) || !$project->getAllowPublicStatus()) {
|
||||
throw new NotFoundException('Project with id: ' . $projectId . ' not found');
|
||||
}
|
||||
|
||||
|
@ -196,7 +208,7 @@ class BuildStatusController extends Controller
|
|||
$this->view->latest = $builds[0];
|
||||
}
|
||||
|
||||
$this->view->builds = $builds;
|
||||
$this->view->builds = $builds;
|
||||
$this->view->project = $project;
|
||||
|
||||
return $this->view->render();
|
||||
|
@ -204,12 +216,16 @@ class BuildStatusController extends Controller
|
|||
|
||||
/**
|
||||
* Render latest builds for project as HTML table.
|
||||
*
|
||||
* @param integer $projectId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getLatestBuilds($projectId)
|
||||
{
|
||||
$criteria = ['project_id' => $projectId];
|
||||
$order = ['id' => 'DESC'];
|
||||
$builds = $this->buildStore->getWhere($criteria, 10, 0, [], $order);
|
||||
$criteria = ['project_id' => $projectId];
|
||||
$order = ['id' => 'DESC'];
|
||||
$builds = $this->buildStore->getWhere($criteria, 10, 0, [], $order);
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
|
|
Loading…
Reference in a new issue