forked from deblan/gist
git + form
This commit is contained in:
parent
eea3b1e427
commit
843cf43b54
|
@ -5,3 +5,4 @@ use Gist\Application;
|
|||
$app = Application::getInstance();
|
||||
|
||||
$app['root_path'] = __DIR__ . '/../..';
|
||||
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
$app['config.locator.path'] = $app['root_path'].'/app/config';
|
||||
$app['config.locator.path'] = $app['root_path'].'/app/config/';
|
||||
|
||||
$app['config.locator'] = function ($app) {
|
||||
return new FileLocator($app['config.locator.path']);
|
||||
};
|
||||
|
||||
$app['env'] = 'dev';
|
||||
|
|
|
@ -10,3 +10,4 @@ $app->error(function (Exception $e, $code) use ($app) {
|
|||
)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -12,3 +12,4 @@ $app['routes'] = $app->extend('routes', function ($routes, $app) {
|
|||
$routes->addCollection($app['routing.loader']->load($app['routing.file']));
|
||||
return $routes;
|
||||
});
|
||||
|
||||
|
|
|
@ -11,3 +11,4 @@ $app->extend('twig', function ($twig, $app) {
|
|||
|
||||
return $twig;
|
||||
});
|
||||
|
||||
|
|
7
app/bootstrap.php.d/40-form.php
Normal file
7
app/bootstrap.php.d/40-form.php
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Silex\Provider\FormServiceProvider;
|
||||
use Silex\Provider\ValidatorServiceProvider;
|
||||
|
||||
$app->register(new FormServiceProvider());
|
||||
$app->register(new ValidatorServiceProvider());
|
9
app/bootstrap.php.d/50-git.php
Normal file
9
app/bootstrap.php.d/50-git.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
use GitWrapper\GitWrapper;
|
||||
|
||||
$app['git'] = function ($app) {
|
||||
echo "ok";
|
||||
return new GitWrapper();
|
||||
};
|
||||
|
|
@ -3,12 +3,12 @@
|
|||
cd "$(dirname "$0")/.."
|
||||
|
||||
deploy_preprod() {
|
||||
rsync -avzoK --delete -e ssh * weblinuxtest@deblan.fr:/services/web/www/linux-test.deblan.org/project/
|
||||
rsync -avzoK --delete -e ssh * webgist@deblan.fr:/services/web/www/gist.deblan.org/
|
||||
}
|
||||
|
||||
|
||||
deploy_preprod_lan() {
|
||||
rsync -avzoK --delete -e ssh * weblinuxtest@hinata:/services/web/www/linux-test.deblan.org/project/
|
||||
rsync -avzoK --delete -e ssh * webgist@hinata:/services/web/www/gist.deblan.org/
|
||||
}
|
||||
|
||||
([ -n "$1" ] && deploy_$1) || deploy_preprod
|
||||
|
|
|
@ -6,3 +6,26 @@ app:
|
|||
title: 'Home'
|
||||
about:
|
||||
title: 'About'
|
||||
|
||||
form:
|
||||
title:
|
||||
placeholder: 'Title'
|
||||
cipher:
|
||||
choice:
|
||||
yes: 'Yes'
|
||||
no: 'No'
|
||||
type:
|
||||
choice:
|
||||
xml: 'HTML/XML'
|
||||
css: 'CSS'
|
||||
js: 'JAVASCRIPT'
|
||||
php: 'PHP'
|
||||
sql: 'SQL'
|
||||
yaml: 'YAML'
|
||||
perl: 'PERL'
|
||||
c: 'C/C++'
|
||||
asp: 'ASP'
|
||||
python: 'PYTHON'
|
||||
bash: 'BASH'
|
||||
as: 'ACTION SCRIPT'
|
||||
text: 'TEXT'
|
||||
|
|
|
@ -3,9 +3,13 @@
|
|||
"geshi/geshi": "dev-master",
|
||||
"silex/silex": "dev-master",
|
||||
"symfony/yaml": "~2.6",
|
||||
"symfony/twig-bridge": "dev-master",
|
||||
"symfony/twig-bridge": "~2.6",
|
||||
"symfony/translation": "dev-master",
|
||||
"symfony/config": "2.8.x-dev"
|
||||
"symfony/config": "2.8.x-dev",
|
||||
"cpliakas/git-wrapper": "~1.4",
|
||||
"symfony/form": "~2.6",
|
||||
"symfony/security-csrf": "~2.6",
|
||||
"symfony/validator": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
|
|
|
@ -4,15 +4,24 @@ namespace Gist\Controller;
|
|||
|
||||
use Silex\Application;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Gist\Form\CreateGistForm;
|
||||
|
||||
/**
|
||||
* Class HomeController
|
||||
* @author Simon Vieille
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class HomeController
|
||||
{
|
||||
public function indexAction(Request $request, Application $app)
|
||||
{
|
||||
return $app['twig']->render('Home/index.html.twig');
|
||||
$form = new CreateGistForm($app['form.factory'], $app['translator']);
|
||||
$form = $form->build();
|
||||
|
||||
return $app['twig']->render(
|
||||
'Home/index.html.twig',
|
||||
array(
|
||||
'form' => $form->createView(),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
26
src/Gist/Form/AbstractForm.php
Normal file
26
src/Gist/Form/AbstractForm.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Gist\Form;
|
||||
|
||||
use Symfony\Component\Form\FormFactory;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Class AbstractForm
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
abstract class AbstractForm
|
||||
{
|
||||
protected $builder;
|
||||
|
||||
protected $translator;
|
||||
|
||||
public function __construct(FormFactory $formFactory, Translator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
|
||||
$this->builder = $formFactory->createBuilder('form');
|
||||
}
|
||||
|
||||
abstract public function build(array $options = array());
|
||||
}
|
93
src/Gist/Form/CreateGistForm.php
Normal file
93
src/Gist/Form/CreateGistForm.php
Normal file
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace Gist\Form;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
/**
|
||||
* Class CreateGistForm
|
||||
* @author Simon Vieille <simon@deblan.fr>
|
||||
*/
|
||||
class CreateGistForm extends AbstractForm
|
||||
{
|
||||
public function build(array $options = array())
|
||||
{
|
||||
$this->builder->add(
|
||||
'title',
|
||||
'text',
|
||||
array(
|
||||
'required' => false,
|
||||
'attr' => array(
|
||||
'class' => 'form-control',
|
||||
'placeholder' => $this->translator->trans('form.title.placeholder'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->builder->add(
|
||||
'content',
|
||||
'textarea',
|
||||
array(
|
||||
'required' => true,
|
||||
'attr' => array(
|
||||
'class' => 'form-control',
|
||||
'rows' => 10,
|
||||
),
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->builder->add(
|
||||
'type',
|
||||
'choice',
|
||||
array(
|
||||
'required' => true,
|
||||
'choices' => $this->getTypes(),
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$this->builder->add(
|
||||
'cipher',
|
||||
'choice',
|
||||
array(
|
||||
'required' => true,
|
||||
'choices' => array(
|
||||
0 => $this->translator->trans('form.cipher.choice.no'),
|
||||
1 => $this->translator->trans('form.cipher.choice.yes'),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
return $this->builder->getForm();
|
||||
}
|
||||
|
||||
protected function getTypes()
|
||||
{
|
||||
$types = array(
|
||||
'xml' => '',
|
||||
'css' => '',
|
||||
'js' => '',
|
||||
'php' => '',
|
||||
'sql' => '',
|
||||
'yaml'=> '',
|
||||
'perl' => '',
|
||||
'c' => '',
|
||||
'asp' => '',
|
||||
'python' => '',
|
||||
'bash' => '',
|
||||
'as' => '',
|
||||
'text' => '',
|
||||
);
|
||||
|
||||
foreach ($types as $k => $v) {
|
||||
$types[$k] = $this->translator->trans('form.type.choice.'.$k);
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
}
|
|
@ -1 +1,91 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block body %}
|
||||
<div class="row">
|
||||
{{ form(form) }}
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<input type="text" class="form-control" id="name" placeholder="Title">
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p class="text-primary">
|
||||
<span class="glyphicon glyphicon-info-sign"></span>
|
||||
En activant le chiffrement, le code déposé ne pourra pas être forké.
|
||||
</p>
|
||||
<div class="btn-toolbar">
|
||||
<div class="btn-group" id="languages">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Language XML
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li>
|
||||
<a href="html">HTML/XML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">CSS</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript">JAVASCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="php">PHP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="sql">SQL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="yaml">YAML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="perl">PERL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="c">C/C++</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="asp">ASP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="python">PYTHON</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="bash">BASH</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="actionscript">ACTION SCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="texte">TEXT</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Chiffrement : non
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li>
|
||||
<a href="html">oui</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">non</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<textarea rows="10" id="code" class="form-control"></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" class="btn btn-primary" value="Envoyer">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -42,92 +42,7 @@
|
|||
</div>
|
||||
</nav>
|
||||
<div class="container-fluid" id="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<input type="text" class="form-control" id="name" placeholder="Title">
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p class="text-primary">
|
||||
<span class="glyphicon glyphicon-info-sign"></span>
|
||||
En activant le chiffrement, le code déposé ne pourra pas être forké.
|
||||
</p>
|
||||
<div class="btn-toolbar">
|
||||
<div class="btn-group" id="languages">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Language XML
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li>
|
||||
<a href="html">HTML/XML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">CSS</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="javascript">JAVASCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="php">PHP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="sql">SQL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="yaml">YAML</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="perl">PERL</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="c">C/C++</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="asp">ASP</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="python">PYTHON</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="bash">BASH</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="actionscript">ACTION SCRIPT</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="texte">TEXT</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
|
||||
Chiffrement : non
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li>
|
||||
<a href="html">oui</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="css">non</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>
|
||||
<textarea rows="10" id="code" class="form-control"></textarea>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" class="btn btn-primary" value="Envoyer">
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% block body %}{% endblock %}
|
||||
{% block js %}
|
||||
<script src="{{ web_path }}components/jquery/dist/jquery.min.js"></script>
|
||||
<script src="{{ web_path }}components/bootstrap/dist/js/bootstrap.min.js"></script>
|
||||
|
|
|
@ -5,11 +5,23 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>{{ name }}</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
Error: {{ name }}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{% if app.env == 'dev' %}
|
||||
<p><em>In file "{{ exception.file }}" at line {{ exception.line }}</em></p>
|
||||
<p>{{ exception.message }}</p>
|
||||
|
||||
<h2>Stacktrace</h2>
|
||||
<pre>{{ exception.traceAsString }}</pre>
|
||||
{% else %}
|
||||
<p>{{ exception.message }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
49
web/.htaccess
Normal file
49
web/.htaccess
Normal file
|
@ -0,0 +1,49 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
|
||||
RewriteCond %{HTTPS} !on
|
||||
RewriteCond %{SERVER_NAME} =gist.deblan.org
|
||||
RewriteRule .* https://gist.deblan.org%{REQUEST_URI} [R,L]
|
||||
|
||||
# Determine the RewriteBase automatically and set it as environment variable.
|
||||
# If you are using Apache aliases to do mass virtual hosting or installed the
|
||||
# project in a subdirectory, the base path will be prepended to allow proper
|
||||
# resolution of the app.php file and to redirect to the correct URI. It will
|
||||
# work in environments without path prefix as well, providing a safe, one-size
|
||||
# fits all solution. But as you do not need it in this case, you can comment
|
||||
# the following 2 lines to eliminate the overhead.
|
||||
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
|
||||
RewriteRule ^(.*) - [E=BASE:%1]
|
||||
|
||||
# Redirect to URI without front controller to prevent duplicate content
|
||||
# (with and without `/app.php`). Only do this redirect on the initial
|
||||
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
|
||||
# endless redirect loop (request -> rewrite to front controller ->
|
||||
# redirect -> request -> ...).
|
||||
# So in case you get a "too many redirects" error or you always get redirected
|
||||
# to the start page because your Apache does not expose the REDIRECT_STATUS
|
||||
# environment variable, you have 2 choices:
|
||||
# - disable this feature by commenting the following 2 lines or
|
||||
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
|
||||
# following RewriteCond (best solution)
|
||||
RewriteCond %{ENV:REDIRECT_STATUS} ^$
|
||||
RewriteRule ^index\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
|
||||
|
||||
# If the requested filename exists, simply serve it.
|
||||
# We only want to let Apache serve files and not directories.
|
||||
RewriteCond %{REQUEST_FILENAME} -f
|
||||
RewriteRule .? - [L]
|
||||
|
||||
# Rewrite all other queries to the front controller.
|
||||
RewriteRule .? %{ENV:BASE}/index.php [L]
|
||||
</IfModule>
|
||||
|
||||
<IfModule !mod_rewrite.c>
|
||||
<IfModule mod_alias.c>
|
||||
# When mod_rewrite is not available, we instruct a temporary redirect of
|
||||
# the start page to the front controller explicitly so that the website
|
||||
# and the generated links can still be used.
|
||||
RedirectMatch 302 ^/$ /index.php/
|
||||
# RedirectTemp cannot be used instead
|
||||
</IfModule>
|
||||
</IfModule>
|
Loading…
Reference in a new issue