Refactored view/template.
This commit is contained in:
parent
09cee5a5df
commit
597a20deea
34 changed files with 179 additions and 801 deletions
|
|
@ -6,7 +6,6 @@ use b8;
|
|||
use b8\Exception\HttpException;
|
||||
use b8\Http\Response;
|
||||
use b8\Http\Response\RedirectResponse;
|
||||
use b8\View;
|
||||
|
||||
/**
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
|
|
|
|||
|
|
@ -6,22 +6,26 @@ use b8\Config;
|
|||
use b8\Exception\HttpException\ForbiddenException;
|
||||
use b8\Http\Request;
|
||||
use b8\Http\Response;
|
||||
use b8\View;
|
||||
|
||||
class Controller extends \b8\Controller
|
||||
{
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var View
|
||||
*/
|
||||
protected $controllerView;
|
||||
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var View
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
/**
|
||||
* @var \b8\View
|
||||
* @var string
|
||||
*/
|
||||
protected $className;
|
||||
|
||||
/**
|
||||
* @var View
|
||||
*/
|
||||
public $layout;
|
||||
|
||||
|
|
@ -55,7 +59,7 @@ class Controller extends \b8\Controller
|
|||
if (View::exists($this->className)) {
|
||||
$this->controllerView = new View($this->className);
|
||||
} else {
|
||||
$this->controllerView = new View\Template('{@content}');
|
||||
$this->controllerView = new View('{@content}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use PHPCensor\Model\Project;
|
|||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\BuildService;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* Build Controller - Allows users to run and view builds.
|
||||
|
|
@ -189,7 +190,7 @@ class BuildController extends Controller
|
|||
$errorStore = b8\Store\Factory::getStore('BuildError');
|
||||
$errors = $errorStore->getByBuildId($build->getId(), $perPage, $start, $plugin, $severity, $isNew);
|
||||
|
||||
$errorView = new b8\View('Build/errors');
|
||||
$errorView = new View('Build/errors');
|
||||
$errorView->build = $build;
|
||||
$errorView->errors = $errors['items'];
|
||||
|
||||
|
|
@ -213,7 +214,7 @@ class BuildController extends Controller
|
|||
*/
|
||||
protected function getPaginatorHtml($buildId, $plugin, $severity, $isNew, $total, $perPage, $page)
|
||||
{
|
||||
$view = new b8\View('pagination');
|
||||
$view = new View('pagination');
|
||||
|
||||
$urlPattern = APP_URL . 'build/view/' . $buildId;
|
||||
$params = [];
|
||||
|
|
@ -306,7 +307,7 @@ class BuildController extends Controller
|
|||
foreach ($builds['items'] as $build) {
|
||||
$item = $build->toArray(1);
|
||||
|
||||
$header = new b8\View('Build/header-row');
|
||||
$header = new View('Build/header-row');
|
||||
$header->build = $build;
|
||||
|
||||
$item['header_row'] = $header->render();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use PHPCensor\Service\BuildService;
|
|||
use PHPCensor\Service\ProjectService;
|
||||
use PHPCensor\Model\Build;
|
||||
use b8\Http\Response\RedirectResponse;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* Project Controller - Allows users to create, edit and view projects.
|
||||
|
|
@ -141,7 +142,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
*/
|
||||
protected function getPaginatorHtml($projectId, $branch, $environment, $total, $perPage, $page)
|
||||
{
|
||||
$view = new b8\View('pagination');
|
||||
$view = new View('pagination');
|
||||
|
||||
$urlPattern = APP_URL . 'project/view/' . $projectId;
|
||||
$params = [];
|
||||
|
|
@ -178,7 +179,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
if (empty($project) || $project->getArchived()) {
|
||||
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
|
||||
}
|
||||
|
||||
|
||||
$type = $this->getParam('type', 'branch');
|
||||
$id = $this->getParam('id');
|
||||
$debug = (boolean)$this->getParam('debug', false);
|
||||
|
|
@ -273,7 +274,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
|
||||
$order = ['id' => 'DESC'];
|
||||
$builds = $this->buildStore->getWhere($criteria, $perPage, $start, [], $order);
|
||||
$view = new b8\View('Project/ajax-builds');
|
||||
$view = new View('Project/ajax-builds');
|
||||
|
||||
foreach ($builds['items'] as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
|
|
@ -312,7 +313,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$form = $this->projectForm($values);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('Project/edit');
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'add';
|
||||
$view->project = null;
|
||||
$view->form = $form;
|
||||
|
|
@ -381,7 +382,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
$form = $this->projectForm($values, 'edit/' . $projectId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('Project/edit');
|
||||
$view = new View('Project/edit');
|
||||
$view->type = 'edit';
|
||||
$view->project = $project;
|
||||
$view->form = $form;
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@ use PHPCensor\Controller;
|
|||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\User;
|
||||
use PHPCensor\Service\UserService;
|
||||
use PHPCensor\View;
|
||||
|
||||
/**
|
||||
* User Controller - Allows an administrator to view, add, edit and delete users.
|
||||
*
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class UserController extends Controller
|
||||
|
|
@ -61,7 +62,7 @@ class UserController extends Controller
|
|||
$name = $this->getParam('name', null);
|
||||
$email = $this->getParam('email', null);
|
||||
$password = $this->getParam('password', null);
|
||||
|
||||
|
||||
$language = $this->getParam('language', null);
|
||||
if (!$language) {
|
||||
$language = null;
|
||||
|
|
@ -166,7 +167,7 @@ class UserController extends Controller
|
|||
$form = $this->userForm($values);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('User/edit');
|
||||
$view = new View('User/edit');
|
||||
$view->type = 'add';
|
||||
$view->user = null;
|
||||
$view->form = $form;
|
||||
|
|
@ -208,7 +209,7 @@ class UserController extends Controller
|
|||
$form = $this->userForm($values, 'edit/' . $userId);
|
||||
|
||||
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
|
||||
$view = new b8\View('User/edit');
|
||||
$view = new View('User/edit');
|
||||
$view->type = 'edit';
|
||||
$view->user = $user;
|
||||
$view->form = $form;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ namespace PHPCensor\Controller;
|
|||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Model\Project;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
|
|
@ -101,7 +101,7 @@ class WidgetAllProjectsController extends Controller
|
|||
|
||||
/**
|
||||
* Get a summary of the project groups we have, and what projects they have in them.
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGroupInfo()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\Controller;
|
||||
use PHPCensor\Store\BuildStore;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8\Store\Factory;
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use b8\Http\Response;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Controller;
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Helper;
|
||||
|
||||
use b8\Config;
|
||||
|
||||
/**
|
||||
* Login Is Disabled Helper - Checks if login is disabled in the view
|
||||
*
|
||||
* @author Stephen Ball <phpci@stephen.rebelinblue.com>
|
||||
*/
|
||||
class LoginIsDisabled
|
||||
{
|
||||
/**
|
||||
* Checks if
|
||||
*
|
||||
* @param $method
|
||||
* @param array $params
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function __call($method, $params = [])
|
||||
{
|
||||
unset($method, $params);
|
||||
|
||||
$config = Config::getInstance();
|
||||
$disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false);
|
||||
|
||||
return $disableAuth;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace PHPCensor\Plugin;
|
||||
|
||||
use b8\View;
|
||||
use PHPCensor\View;
|
||||
use PHPCensor\Helper\Email as EmailHelper;
|
||||
use Psr\Log\LogLevel;
|
||||
use PHPCensor\Plugin;
|
||||
|
||||
/**
|
||||
* Email Plugin - Provides simple email capability.
|
||||
*
|
||||
*
|
||||
* @author Steve Brazier <meadsteve@gmail.com>
|
||||
*/
|
||||
class Email extends Plugin
|
||||
|
|
|
|||
88
src/PHPCensor/View.php
Normal file
88
src/PHPCensor/View.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor;
|
||||
|
||||
use b8\Config;
|
||||
use PHPCensor\Model\User;
|
||||
|
||||
class View
|
||||
{
|
||||
protected $vars = [];
|
||||
protected $isContent = false;
|
||||
|
||||
protected static $extension = 'phtml';
|
||||
|
||||
public function __construct($file, $path = null)
|
||||
{
|
||||
if ('{@content}' === $file) {
|
||||
$this->isContent = true;
|
||||
} else {
|
||||
if (!self::exists($file, $path)) {
|
||||
throw new \RuntimeException('View file does not exist: ' . $file);
|
||||
}
|
||||
|
||||
$this->viewFile = self::getViewFile($file, $path);
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getViewFile($file, $path = null)
|
||||
{
|
||||
$viewPath = is_null($path) ? Config::getInstance()->get('b8.view.path') : $path;
|
||||
$fullPath = $viewPath . $file . '.' . static::$extension;
|
||||
|
||||
return $fullPath;
|
||||
}
|
||||
|
||||
public static function exists($file, $path = null)
|
||||
{
|
||||
if (!file_exists(self::getViewFile($file, $path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __isset($var)
|
||||
{
|
||||
return isset($this->vars[$var]);
|
||||
}
|
||||
|
||||
public function __get($var)
|
||||
{
|
||||
return $this->vars[$var];
|
||||
}
|
||||
|
||||
public function __set($var, $val)
|
||||
{
|
||||
$this->vars[$var] = $val;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
if ($this->isContent) {
|
||||
return $this->vars['content'];
|
||||
} else {
|
||||
extract($this->vars);
|
||||
|
||||
ob_start();
|
||||
|
||||
require($this->viewFile);
|
||||
|
||||
$html = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
protected function LoginIsDisabled()
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
$disableAuth = (boolean)$config->get('php-censor.security.disable_auth', false);
|
||||
|
||||
return $disableAuth;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,10 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
<a class="btn btn-success pull-right" href="<?php print APP_URL . 'group/edit'; ?>">
|
||||
<?php Lang::out('group_add'); ?>
|
||||
|
|
@ -22,7 +28,7 @@
|
|||
<td>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>group/edit/<?php print $group['id']; ?>"><?php Lang::out('group_edit'); ?></a>
|
||||
<?php if($this->User()->getIsAdmin() && (!count($group['projects']))): ?>
|
||||
<?php if($user->getIsAdmin() && (!count($group['projects']))): ?>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
|
|
@ -45,4 +51,4 @@
|
|||
confirmDelete(e.target.href).onCloseConfirmed = function () {window.location = window.location.href};
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
|
||||
<?php if(empty($builds) || !count($builds)): ?>
|
||||
|
|
@ -92,7 +94,7 @@ $branches = $build->getExtra('branches');
|
|||
<td>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>build/view/<?php print $build->getId(); ?>"><?php Lang::out('view'); ?></a>
|
||||
<?php if($this->User()->getIsAdmin()): ?>
|
||||
<?php if($user->getIsAdmin()): ?>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
<script>
|
||||
var PROJECT_ID = <?= $project->getId(); ?>;
|
||||
|
|
@ -29,7 +31,7 @@ use PHPCensor\Helper\Lang;
|
|||
?>
|
||||
<div class="pull-right btn-group">
|
||||
<?php if (!$project->getArchived()): ?>
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($user->getIsAdmin()): ?>
|
||||
<?php if (!empty($environment)): ?>
|
||||
<a class="btn btn-danger" href="<?= $build_url . '?' . http_build_query(['type' => 'environment', 'id' => $environment, 'debug' => 1]); ?>">
|
||||
<?php Lang::out('build_now_debug'); ?>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
<div class="clearfix" style="margin-bottom: 20px;">
|
||||
<div class="pull-right btn-group">
|
||||
<a class="btn btn-success" href="<?php print APP_URL; ?>user/add"><?php Lang::out('add_user'); ?></a>
|
||||
|
|
@ -39,7 +45,7 @@
|
|||
<td><?php print htmlspecialchars($user->getName()); ?></td>
|
||||
<td><?php print $status; ?></td>
|
||||
<td>
|
||||
<?php if($this->User()->getIsAdmin()): ?>
|
||||
<?php if($user->getIsAdmin()): ?>
|
||||
<div class="btn-group btn-group-right">
|
||||
<a class="btn btn-default btn-sm" href="<?php echo APP_URL ?>user/edit/<?php print $user->getId(); ?>"><?php Lang::out('edit'); ?></a>
|
||||
<button class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown">
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@
|
|||
* @var $exception \Exception
|
||||
*/
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
<div class="panel panel-danger">
|
||||
<div class="box-header">
|
||||
<h2 class="box-title">Sorry, there was a problem</h2>
|
||||
</div>
|
||||
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($user->getIsAdmin()): ?>
|
||||
<div class="box-body">
|
||||
<strong>Message</strong>: <?= $exception->getMessage(); ?><br />
|
||||
<strong>File</strong>: <?= $exception->getFile(); ?><br />
|
||||
|
|
|
|||
|
|
@ -1,4 +1,10 @@
|
|||
<?php use PHPCensor\Helper\Lang; ?>
|
||||
<?php
|
||||
|
||||
use PHPCensor\Helper\Lang;
|
||||
|
||||
$user = $_SESSION['php-censor-user'];
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
|
|
@ -87,19 +93,19 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()->check()): ?>
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- User Account: style can be found in dropdown.less -->
|
||||
<li class="dropdown user user-menu">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
<i class="glyphicon glyphicon-user"></i>
|
||||
<span><?php print $this->User()->getName(); ?> <i class="caret"></i></span>
|
||||
<span><?= $user->getName(); ?> <i class="caret"></i></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<!-- User image -->
|
||||
<li class="user-header">
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($this->User()->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $this->User()->getName(); ?>" />
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($user->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $user->getName(); ?>" />
|
||||
<p>
|
||||
<?php print $this->User()->getName(); ?>
|
||||
<?php print $user->getName(); ?>
|
||||
</p>
|
||||
</li>
|
||||
|
||||
|
|
@ -124,14 +130,14 @@
|
|||
<!-- sidebar: style can be found in sidebar.less -->
|
||||
<section class="sidebar">
|
||||
|
||||
<?php if (!$this->LoginIsDisabled()->check()): ?>
|
||||
<?php if (!$this->LoginIsDisabled()): ?>
|
||||
<!-- Sidebar user panel -->
|
||||
<div class="user-panel">
|
||||
<div class="pull-left image">
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($this->User()->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $this->User()->getName(); ?>" />
|
||||
<img src="https://www.gravatar.com/avatar/<?php print md5($user->getEmail()); ?>?d=mm" class="img-circle" alt="<?php print $user->getName(); ?>" />
|
||||
</div>
|
||||
<div class="pull-left info">
|
||||
<p><?php Lang::out('hello_name', $this->User()->getName()); ?></p>
|
||||
<p><?php Lang::out('hello_name', $user->getName()); ?></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
|
@ -144,7 +150,7 @@
|
|||
</a>
|
||||
</li>
|
||||
|
||||
<?php if ($this->User()->getIsAdmin()): ?>
|
||||
<?php if ($user->getIsAdmin()): ?>
|
||||
<li class="treeview">
|
||||
<a href="#">
|
||||
<i class="fa fa-edit"></i>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue