1
0
Fork 0
forked from deblan/gist

Compare commits

...

33 commits

Author SHA1 Message Date
Sebastian Żmijewski 75297b565b
Polish translation 2018-04-10 16:45:51 +02:00
Simon Vieille d73e4df326
Fix issue #12: make error in Debian 9 Stretch 2018-03-28 12:06:25 +02:00
Simon Vieille b74960ecd3 Fix download issue 2017-10-16 13:32:01 +02:00
Simon Vieille ebc0ea2bf8 Fix empty file validation 2017-10-15 13:28:49 +02:00
Simon Vieille 3a78e500df Mobile view optimised 2017-10-15 13:19:45 +02:00
Simon Vieille db8b512670 Mobile view optimised 2017-10-15 13:18:06 +02:00
Simon Vieille 411447ae3e Merge branch 'feature/highlighter' into dev-master 2017-10-15 12:42:25 +02:00
Simon Vieille d56c33c29f Fix highlighting for ASP and ActionScript 2017-10-15 12:40:52 +02:00
Simon Vieille 37751f51a6 Embed block: highlighting 2017-10-15 03:06:04 +02:00
Simon Vieille b83e1655b5 Embed block: highlighting 2017-10-15 03:01:42 +02:00
Simon Vieille 1a79e4520f Embed block moved 2017-10-15 02:58:10 +02:00
Simon Vieille 21a85c0db4 Embed view css 2017-10-15 02:18:59 +02:00
Simon Vieille 88ce6d66db Geshi removed - Prismjs added 2017-10-15 02:07:41 +02:00
Simon Vieille 43fd509d69 Documentation 2017-09-21 18:45:45 +02:00
Simon Vieille d441d7e834 API list: limit of 15 results 2017-09-21 18:23:30 +02:00
Simon Vieille 9fe6510fc9 Merge branch 'feature/api' into dev-master 2017-09-21 17:56:44 +02:00
Simon Vieille 4d2cf30de1 API: UI and command 'list' renamed with 'gists' 2017-09-21 17:56:37 +02:00
Simon Vieille ab58bdb82d Implementation of Api action "delete" 2017-09-18 09:30:39 +02:00
Simon Vieille 87348c8335 Implementation of Api action "delete" 2017-08-23 19:32:56 +02:00
Simon Vieille f6e4837776 Implementation of Api action "list" 2017-08-23 17:20:23 +02:00
Simon Vieille a478fb3de5 Fix issue with locale cookie 2017-08-11 10:57:57 +02:00
Simon Vieille 91cdb2341c Favicon 2017-06-25 23:09:34 +02:00
Simon Vieille ffe3540565 API key 2017-06-25 23:06:24 +02:00
Simon Vieille 80b3c0bbdb Merge stash 2017-06-25 19:13:27 +02:00
Simon Vieille a9435906fe API refactoring 2017-06-25 18:52:27 +02:00
Simon Vieille 7a3ea9d060 Merge tag 'login' into dev-master
v1.6.2
2017-06-20 16:46:49 +02:00
Simon Vieille 99635e8e3c Merge branch 'hotfix/login' 2017-06-20 16:46:22 +02:00
Simon Vieille 50025705d1 Fix login issue 2017-06-20 16:46:10 +02:00
Simon Vieille c46cf0fdb7 Fix form validation 2017-06-20 10:03:40 +02:00
Simon Vieille 79ba41a983 Apply hotfix 2017-06-20 09:47:51 +02:00
Simon Vieille 8a7de8a107 Apply hotfix 2017-06-20 09:46:40 +02:00
Simon Vieille bc67a2ce1c Fix form validation 2017-06-19 23:55:50 +02:00
Simon Vieille 0f127a0920 feature/3: upload a file 2017-06-19 20:36:51 +02:00
55 changed files with 1921 additions and 946 deletions

View file

@ -31,7 +31,6 @@ update:
@echo "-----------------------------------"
@echo
sh -c 'test -d app && $(GIT) add app && $(GIT) commit -m "Configuration"'
$(GIT) pull origin master
${MKDIR} -p data/git
$(COMPOSER) update

130
README.md
View file

@ -137,10 +137,12 @@ If your version is less than v1.4.2, run: `test -d app && git add app && git com
$ make update
$ make propel
If you upgrade to v1.4.1, run: `app/console migrate:to:v1.4.1`.
If you upgrade to v1.4.1 or more: `app/console migrate:to:v1.4.1`.
If you upgrade to v1.4.4 or more, the configuration is moved to a `app/config/config.yml`: `$ cp app/config/config.yml.dist app/config/config.yml` and see the [configuration section](#configuration) for more information.
If you upgrade to v1.7.0 or more, see the [configuration section](#configurationh) for more information about new options.
Configuration
-------------
@ -173,6 +175,12 @@ Edit `app/config/config.yml`.
* `git.path`: The path of `git`.
* `theme.name`: the name of the theme (`dark` or `light`)
### Version >= v1.7.0
* `api.enabled`: defines if the API is enabled (`true` or `false`)
* `api.api_key_required`: defines if the API key is required to access the API (`true` or `false`)
* `api.client.api_key`: defines the client API key (`string`)
Makefile
--------
@ -187,7 +195,9 @@ A Makefile is provided to automate some tasks.
API
---
### Create a new gist
### Version < v1.7.0
#### Create a new gist
**POST** /{locale}/api/create
Params:
@ -218,7 +228,7 @@ Params:
}
```
### Update an existing gist
#### Update an existing gist
**POST** /{locale}/api/update/{id}
Params:
@ -247,6 +257,115 @@ Params:
}
```
### Version >= v1.7.0
Invalid response codes:
* Code `401`: Unauthorized
* Code `403`: API not enabled
* Code `405`: Method Not Allowed
* Code `400`: Bad Request
#### List gists
**GET** /{locale}/api/list/{apiToken}
Response example:
```javascript
[
{
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:30:15Z"
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
},
{
"id": 67,
"title": "test prod 2",
"cipher": false,
"type": "javascript",
"file": "xyzbcfa7771e0",
"createdAt": "2015-08-19T16:26:15Z",
"updatedAt": "2015-08-19T16:30:15Z"
"url": "https:\/\/gist.deblan.org\/en\/view\/5byzbcfa7771e0\/def72967dd95e346koq0dcaa310d728d6artu",
},
...
]
```
#### Create a new gist
**POST** /{locale}/api/create/{apiToken}
Params:
* `form[title]`: String (required, can be empty)
* `form[type]`: String (required)
Values: html, css, javascript, php, sql, xml, yaml, perl, c, asp, python, bash, actionscript3, text
* `form[content]`: String (required)
Response example:
```javascript
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/f4afbf72967dd95e3461490dcaa310d728d6a97d",
"gist": {
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:26:15Z"
}
}
```
#### Update an existing gist
**POST** /{locale}/api/update/{id}/{apiToken}
Params:
* `{id}`: Gist Id (required)
* `form[content]`: String (required)
Response example:
```javascript
{
"url": "https:\/\/gist.deblan.org\/en\/view\/55abcfa7771e0\/abcgi72967dd95e3461490dcaa310d728d6adef",
"gist": {
"id": 66,
"title": "test prod",
"cipher": false,
"type": "javascript",
"file": "55abcfa7771e0",
"createdAt": "2015-07-19T16:26:15Z",
"updatedAt": "2015-07-19T16:30:15Z"
}
}
```
#### Delete an existing gist
**POST** /{locale}/api/delete/{id}/{apiToken}
Response code `200`:
```javascript
{"error":false}
```
Response code `400`:
```javascript
{"message":"Invalid Gist", "error":true}
```
Console
-------
@ -255,6 +374,11 @@ Console
* **Create user**: `app/console --help user:create`
* **Show stats**: `$ app/console --help stats`
### Version >= v1.7.0
* **List your gists**: `$ app/console --help gists`
* **Delete a gist**: `$ app/console --help delete`
Deployment
----------

View file

@ -12,11 +12,3 @@ $app->extend('twig', function ($twig, $app) {
return $twig;
});
$app['geshi'] = $app->share(function ($app) {
$geshi = new GeSHi();
$geshi->enable_classes();
$geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS);
return $geshi;
});

View file

@ -50,7 +50,7 @@ $app->get('/', function (Request $request) use ($app) {
$foundLocale = $app['translator']->getLocale();
foreach ($app['locales'] as $locale) {
if ($cookie === $locale || $accept->has($locale)) {
if ($cookieValue === $locale || $accept->has($locale)) {
$foundLocale = $locale;
break;
}

View file

@ -20,5 +20,5 @@ $app['git_working_copy'] = $app->share(function ($app) {
});
$app['gist'] = $app->share(function ($app) {
return new Gist($app['gist_path'], $app['git_wrapper'], $app['git_working_copy'], $app['geshi']);
return new Gist($app['gist_path'], $app['git_wrapper'], $app['git_working_copy']);
});

View file

@ -3,5 +3,11 @@
use Gist\Api\Client;
$app['api_client'] = $app->share(function ($app) {
return new Client(['base_uri' => rtrim($app['settings']['api']['base_url'], '/')]);
$client = new Client(['base_uri' => rtrim($app['settings']['api']['base_url'], '/')]);
if (!empty($app['settings']['api']['client']['api_key'])) {
$client->setApiKey($app['settings']['api']['client']['api_key']);
}
return $client;
});

View file

@ -6,7 +6,11 @@ security:
login_required_to_view_gist: false
login_required_to_view_embeded_gist: false
api:
enabled: true
api_key_required: false
base_url: 'https://gist.deblan.org/'
client:
api_key:
data:
path: data/git
git:

View file

@ -57,10 +57,18 @@ revisions:
path: /revs/{gist}
defaults: {_controller: Gist\Controller\ViewController::revisionsAction, _locale: en}
api_list:
path: /api/list/{apiKey}
defaults: {_controller: Gist\Controller\ApiController::listAction, _locale: en, apiKey: null}
api_create:
path: /api/create
defaults: {_controller: Gist\Controller\ApiController::createAction, _locale: en}
path: /api/create/{apiKey}
defaults: {_controller: Gist\Controller\ApiController::createAction, _locale: en, apiKey: null}
api_update:
path: /api/update/{gist}
defaults: {_controller: Gist\Controller\ApiController::updateAction, _locale: en}
path: /api/update/{gist}/{apiKey}
defaults: {_controller: Gist\Controller\ApiController::updateAction, _locale: en, apiKey: null}
api_delete:
path: /api/delete/{gist}/{apiKey}
defaults: {_controller: Gist\Controller\ApiController::deleteAction, _locale: en, apiKey: null}

View file

@ -2,15 +2,19 @@
<?php
use Gist\Command\CreateCommand;
use Gist\Command\ListCommand;
use Gist\Command\UpdateCommand;
use Gist\Command\StatsCommand;
use Gist\Command\DeleteCommand;
use Gist\Command\UserCreateCommand;
use Gist\Command\Migration\UpgradeTo1p4p1Command;
$app = require __DIR__.'/bootstrap.php';
$app['console']->add(new CreateCommand());
$app['console']->add(new ListCommand());
$app['console']->add(new UpdateCommand());
$app['console']->add(new DeleteCommand());
$app['console']->add(new StatsCommand());
$app['console']->add(new UserCreateCommand());
$app['console']->add(new UpgradeTo1p4p1Command());

View file

@ -20,6 +20,11 @@ app:
my:
title: '我的 Gist'
nothing: '这家伙很懒,暂时没有内容'
api:
title: 'API'
warning: 'Keep it <strong>secret!</strong>'
form:
generate: 'Regenerate'
gist:
untitled: '未命名'
@ -32,7 +37,7 @@ gist:
raw: '源文件'
download: '下载'
clone: '克隆'
embed: '引用:'
embed: '引用'
add: '新建'
date:

View file

@ -20,6 +20,11 @@ app:
my:
title: 'Meine Gists'
nothing: 'Nichts zu finden (momentan)!'
api:
title: 'API'
warning: 'Keep it <strong>secret!</strong>'
form:
generate: 'Regenerate'
gist:
untitled: 'Ohne Titel'
@ -32,7 +37,7 @@ gist:
raw: 'RAW'
download: 'Herunterladen'
clone: 'Klonen'
embed: 'Einfügen:'
embed: 'Einfügen'
add: 'Hinzufügen'
date:

View file

@ -20,6 +20,12 @@ app:
my:
title: 'My gists'
nothing: 'Nothing yet!'
api:
title: 'API'
warning: 'Keep it <strong>secret!</strong>'
form:
generate: 'Regenerate'
gist:
untitled: 'Untitled'
@ -32,7 +38,7 @@ gist:
raw: 'RAW'
download: 'Download'
clone: 'Clone'
embed: 'Embed:'
embed: 'Embed'
add: 'New'
date:

View file

@ -20,6 +20,11 @@ app:
my:
title: 'Mis Gists'
nothing: 'Nada por ahora.'
api:
title: 'API'
warning: 'Keep it <strong>secret!</strong>'
form:
generate: 'Regenerate'
gist:
untitled: 'Sin título'
@ -32,7 +37,7 @@ gist:
raw: 'RAW'
download: 'Descargar'
clone: 'Clonar'
embed: 'Insertar : '
embed: 'Insertar'
add: 'Añadir'
date:

View file

@ -20,6 +20,11 @@ app:
my:
title: 'Mes Gists'
nothing: 'Rien pour le moment !'
api:
title: 'API'
warning: 'Gardez-la <strong>secrète !</strong>'
form:
generate: 'Regénérer'
gist:
untitled: 'Sans titre'
@ -32,7 +37,7 @@ gist:
raw: 'RAW'
download: 'Télécharger'
clone: 'Clôner'
embed: 'Insérer : '
embed: 'Insérer'
add: 'Ajouter'
date:

108
app/locales/pl.yml Normal file
View file

@ -0,0 +1,108 @@
app:
title: '#!GIST'
title_prefix: '#!GIST - '
menu:
home:
title: 'Home'
about:
title: 'O projekcie'
my:
login:
title: 'Logowanie'
logout:
title: 'Wylogowanie'
register:
title: 'Rejestracja'
my:
title: 'Konta'
my:
title: 'Moje wklejki'
nothing: 'Nie ma jeszcze nic!'
api:
title: 'API'
warning: 'Trzymaj to w <strong>sekrecie!</strong>'
form:
generate: 'Wygeneruj nowy'
gist:
untitled: 'Bez tytułu'
404:
title: 'Oops!'
message: 'Wklejka nie została znaleziona...'
action:
view: 'Podgląd'
history: 'Commit(s)'
raw: 'RAW'
download: 'Pobierz'
clone: 'Sklonuj'
embed: 'Embed'
add: 'Nowa'
date:
format: 'Y-m-d h:i:s'
footer:
text: '<p>Napędzane przez <a href="https://gitnet.fr/deblan/gist">GIST</a>, to jest open source :) - <a href="https://gitnet.fr/deblan/gist#api">API</a></p>'
login:
login:
title: 'Logowanie'
invalid: 'Nie prawidłowy login lub hasło.'
form:
username:
placeholder: 'Login'
password:
placeholder: 'Hasło'
remember_me:
label: 'Pamiętaj'
register:
title: 'Nowe konto'
already_exists: 'Ta nazwa użytkownika jest już zarejestrowana!'
registred: 'Gratulacje, twoje konto zostało utworzone!'
form:
username:
placeholder: 'Login'
current_password:
placeholder: 'Obecne hasło'
password:
placeholder: 'Hasło'
form:
error:
password: 'Nie prawidłowe hasło.'
not_blank: 'To pole nie powinno być puste!'
title:
placeholder: 'Tytuł'
cipher:
label: 'Szyfrowanie: %value%'
choice:
anyway: 'Tak czy inaczej'
yes: 'Tak'
no: 'Nie'
submit: 'Wyślij'
filter: 'Filtr'
confirm: 'Potwierdzasz?'
success:
password: 'Hasło zostało zaktualizowane.'
gist: 'Wklejka została usunięta.'
type:
label: 'Język: %value%'
choice:
all: 'All'
html: 'HTML'
xml: 'XML'
css: 'CSS'
javascript: 'JAVASCRIPT'
php: 'PHP'
sql: 'SQL'
yaml: 'YAML'
perl: 'PERL'
c: 'C/C++'
asp: 'ASP'
python: 'PYTHON'
bash: 'BASH'
actionscript3: 'ACTION SCRIPT'
text: 'TEXT'

View file

@ -15,8 +15,8 @@
"dependencies": {
"bootstrap": "3.3.4",
"flag-icon-css": "0.7.1",
"SyntaxHighlighter": "3.0.83",
"iframe-resizer": "2.8.6",
"jsdiff": "~2.2.2"
"jsdiff": "~2.2.2",
"Prism": "~1.8.1"
}
}

View file

@ -1,6 +1,5 @@
{
"require": {
"geshi/geshi": "dev-master",
"silex/silex": "1.3.x-dev",
"symfony/yaml": "~2.6",
"symfony/twig-bridge": "~2.6",

View file

@ -12,31 +12,53 @@ use GuzzleHttp\Client as BaseClient;
class Client extends BaseClient
{
/**
* URI of creation
*
* URI of creation.
*
* @const string
*/
const CREATE = '/en/api/create';
/**
* URI of updating
* URI of update.
*
* @const string
*/
const UPDATE = '/en/api/update/{gist}';
/**
* Creates a gist
* URI of delete.
*
* @param string $title The title
* @param string $type The type
* @const string
*/
const DELETE = '/en/api/delete/{gist}';
/**
* URI of list.
*
* @const string
*/
const LIST = '/en/api/list';
/**
* The API key.
*
* @var string|null
*/
protected $apiKey;
/**
* Creates a gist.
*
* @param string $title The title
* @param string $type The type
* @param string $content The content
*
* @return array
*/
public function create($title, $type, $content)
{
$response = $this->post(
self::CREATE,
$this->mergeApiKey(self::CREATE),
array(
'form_params' => array(
'form' => array(
@ -56,9 +78,9 @@ class Client extends BaseClient
}
/**
* Clones and update a gist
* Clones and update a gist.
*
* @param string $gist Gist's ID
* @param string $gist Gist's ID
* @param string $content The content
*
* @return array
@ -66,7 +88,7 @@ class Client extends BaseClient
public function update($gist, $content)
{
$response = $this->post(
str_replace('{gist}', $gist, self::UPDATE),
str_replace('{gist}', $gist, $this->mergeApiKey(self::LIST)),
array(
'form_params' => array(
'form' => array(
@ -82,4 +104,81 @@ class Client extends BaseClient
return [];
}
/**
* Deletes a gist.
*
* @param string $gist Gist's ID
*
* @return array
*/
public function delete($gist)
{
$response = $this->post(str_replace('{gist}', $gist, $this->mergeApiKey(self::DELETE)));
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody()->getContents(), true);
}
return [];
}
/**
* Lists the user's gists.
*
* @param string $gist Gist's ID
* @param string $content The content
*
* @return array
*/
public function list()
{
$response = $this->get($this->mergeApiKey(self::LIST));
if ($response->getStatusCode() === 200) {
return json_decode($response->getBody()->getContents(), true);
}
return [];
}
/*
* Merges the API key with the given url.
*
* @param string $url
*
* @return string
*/
public function mergeApiKey($url)
{
if (empty($this->apiKey)) {
return $url;
}
return rtrim($url, '/').'/'.$this->apiKey;
}
/*
* Set the value of "apiKey".
*
* @param string|null $apiKey
*
* @return Client
*/
public function setApiKey($apiKey)
{
$this->apiKey = $apiKey;
return $this;
}
/*
* Get the value of "apiKey".
*
* @return string|null
*/
public function getApiKey()
{
return $this->apiKey;
}
}

View file

@ -7,6 +7,8 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Propel\Runtime\Parser\YamlParser;
use Symfony\Component\Yaml\Yaml;
/**
* class CreateCommand.
@ -27,8 +29,9 @@ class CreateCommand extends Command
->addArgument('input', InputArgument::REQUIRED, 'Input')
->addArgument('type', InputArgument::OPTIONAL, 'Type', 'text')
->addOption('title', 't', InputOption::VALUE_REQUIRED, 'Title of the gist')
->addOption('show-url', 'u', InputOption::VALUE_NONE, 'Display only the gist url')
->addOption('show-id', 'i', InputOption::VALUE_NONE, 'Display only the gist Id')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Display all the response')
->addOption('id', 'i', InputOption::VALUE_NONE, 'Display only the id of the gist')
->addOption('json', 'j', InputOption::VALUE_NONE, 'Format the response to json')
->setHelp(<<<EOF
Provides a client to create a gist using the API.
@ -43,12 +46,15 @@ Arguments:
Options:
<info>--title</info>, <info>-t</info>
Defines a title
<info>--show-id</info>, <info>-i</info>
Display only the Id of the gist
<info>--show-url</info>, <info>-u</info>
Display only the url of the gist
<info>--id</info>, <info>-i</info>
Display only the id of the gist
<info>--all</info>, <info>-a</info>
Display all the response
<info>--json</info>, <info>-j</info>
Format the response to json
EOF
);
}
@ -58,11 +64,10 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
$file = $input->getArgument('input');
$type = $input->getArgument('type');
$title = $input->getOption('title');
$json = $input->getOption('json');
if ($file === '-') {
$content = file_get_contents('php://stdin');
@ -94,19 +99,17 @@ EOF
$gist = $this->getSilexApplication()['api_client']->create($title, $type, $content);
if ($input->getOption('show-url')) {
$output->writeln($gist['url']);
return true;
if ($input->getOption('id')) {
$id = isset($gist['gist']['id']) ? $gist['gist']['id'] : $gist['gist']['Id'];
$result = $json ? json_encode(array('id' => $id)) : $id;
} elseif ($input->getOption('all')) {
$result = $json ? json_encode($gist) : Yaml::dump($gist);
} else {
$url = $gist['url'];
$result = $json ? json_encode(array('url' => $url)) : $url;
}
if ($input->getOption('show-id')) {
$output->writeln($gist['gist']['Id']);
return true;
}
$output->writeln(json_encode($gist));
$output->writeln($result);
}
/**

View file

@ -0,0 +1,48 @@
<?php
namespace Gist\Command;
use Knp\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
/**
* class DeleteCommand.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class DeleteCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('delete')
->setDescription('Delete a gist using the API')
->addOption('gist', null, InputOption::VALUE_REQUIRED, 'Id or File of the gist')
->setHelp(<<<'EOF'
Provides a client to delete a gist using the API.
Arguments:
none.
Options:
<info>--gist</info>
Defines the Gist to delete by using its Id or its File
EOF
);
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$result = $this->getSilexApplication()['api_client']->delete($input->getOption('gist'));
$output->writeln(empty($result['error']) ? 'OK' : '<error>An error occured.</error>');
}
}

View file

@ -0,0 +1,59 @@
<?php
namespace Gist\Command;
use Knp\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Propel\Runtime\Parser\YamlParser;
use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Console\Helper\Table;
use DateTime;
/**
* class ListCommand.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class ListCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('gists')
->setDescription('List gists using the API');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$gists = $this->getSilexApplication()['api_client']->list();
$rows = [];
foreach ($gists as $gist) {
$rows[] = array(
$gist['id'],
$gist['title'],
$gist['cipher'] ? 'y' : 'n',
$gist['type'],
(new DateTime($gist['createdAt']))->format('Y-m-d H:i:s'),
(new DateTime($gist['updatedAt']))->format('Y-m-d H:i:s'),
$gist['url'],
);
}
$table = new Table($output);
$table
->setHeaders(array('ID', 'Title', 'Cipher', 'Type', 'Created At', 'Updated At', 'url'))
->setRows($rows);
$table->render();
}
}

View file

@ -7,6 +7,7 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Yaml\Yaml;
/**
* class UpdateCommand.
@ -26,8 +27,9 @@ class UpdateCommand extends Command
->setDescription('Update a gist using the API')
->addArgument('input', InputArgument::REQUIRED, 'Input')
->addOption('gist', null, InputOption::VALUE_REQUIRED, 'Id or File of the gist')
->addOption('show-url', 'u', InputOption::VALUE_NONE, 'Display only the gist url')
->addOption('show-id', 'i', InputOption::VALUE_NONE, 'Display only the gist Id')
->addOption('all', 'a', InputOption::VALUE_NONE, 'Display all the response')
->addOption('id', 'i', InputOption::VALUE_NONE, 'Display only the id of the gist')
->addOption('json', 'j', InputOption::VALUE_NONE, 'Format the response to json')
->setHelp(<<<EOF
Provides a client to create a gist using the API.
@ -43,11 +45,14 @@ Options:
<info>--gist</info>
Defines the Gist to update by using its Id or its File
<info>--show-id</info>, <info>-i</info>
Display only the Id of the gist
<info>--id</info>, <info>-i</info>
Display only the id of the gist
<info>--show-url</info>, <info>-u</info>
Display only the url of the gist
<info>--all</info>, <info>-a</info>
Display all the response
<info>--json</info>, <info>-j</info>
Format the response to json
EOF
);
}
@ -57,10 +62,9 @@ EOF
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
//$output->writeln(sprintf('<comment>%s</comment> bar.', 'test'));
$file = $input->getArgument('input');
$gist = $input->getOption('gist');
$json = $input->getOption('json');
if ($file === '-') {
$content = file_get_contents('php://stdin');
@ -86,19 +90,17 @@ EOF
$gist = $this->getSilexApplication()['api_client']->update($gist, $content);
if ($input->getOption('show-url')) {
$output->writeln($gist['url']);
return true;
if ($input->getOption('id')) {
$id = isset($gist['gist']['id']) ? $gist['gist']['id'] : $gist['gist']['Id'];
$result = $json ? json_encode(array('id' => $id)) : $id;
} elseif ($input->getOption('all')) {
$result = $json ? json_encode($gist) : Yaml::dump($gist);
} else {
$url = $gist['url'];
$result = $json ? json_encode(array('url' => $url)) : $url;
}
if ($input->getOption('show-id')) {
$output->writeln($gist['gist']['Id']);
return true;
}
$output->writeln(json_encode($gist));
$output->writeln($result);
}
/**

View file

@ -8,6 +8,9 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Gist\Form\ApiCreateGistForm;
use Gist\Model\GistQuery;
use Gist\Form\ApiUpdateGistForm;
use GitWrapper\GitException;
use Gist\Model\UserQuery;
use Propel\Runtime\ActiveQuery\Criteria;
/**
* Class ApiController.
@ -16,10 +19,80 @@ use Gist\Form\ApiUpdateGistForm;
*/
class ApiController extends Controller
{
public function createAction(Request $request)
/**
* Lists gists.
*
* @param Request $request
* @param string $apiKey
*
* @return JsonResponse
*/
public function listAction(Request $request, $apiKey)
{
$app = $this->getApp();
if (false === $app['settings']['api']['enabled']) {
return new Response('', 403);
}
if (false === $this->isValidApiKey($apiKey, true)) {
return $this->invalidApiKeyResponse();
}
if (false === $request->isMethod('get')) {
return $this->invalidMethodResponse('GET method is required.');
}
$user = $app['user.provider']->loadUserByApiKey($apiKey);
$criteria = GistQuery::create()
->limit(15)
->orderById(Criteria::DESC);
$gists = $user->getGists($criteria);
$data = array();
foreach ($gists as $gist) {
try {
$history = $app['gist']->getHistory($gist);
$value = $gist->toArray();
$value['url'] = $request->getSchemeAndHttpHost().$app['url_generator']->generate(
'view',
array(
'gist' => $gist->getFile(),
'commit' => array_pop($history)['commit'],
)
);
$data[] = $value;
} catch (GitException $e) {
}
}
return new JsonResponse($data);
}
/**
* Creates a gist.
*
* @param Request $request
* @param string $apiKey
*
* @return JsonResponse
*/
public function createAction(Request $request, $apiKey)
{
$app = $this->getApp();
if (false === $app['settings']['api']['enabled']) {
return new Response('', 403);
}
if (false === $this->isValidApiKey($apiKey, (bool) $app['settings']['api']['api_key_required'])) {
return $this->invalidApiKeyResponse();
}
if (false === $request->isMethod('post')) {
return $this->invalidMethodResponse('POST method is required.');
}
@ -36,30 +109,51 @@ class ApiController extends Controller
$form->submit($request);
if ($form->isValid()) {
$user = !empty($apiKey) ? $app['user.provider']->loadUserByApiKey($apiKey) : null;
$gist = $app['gist']->create(new Gist(), $form->getData());
$gist->setCipher(false)->save();
$gist
->setCipher(false)
->setUser($user)
->save();
$history = $app['gist']->getHistory($gist);
return new JsonResponse(array(
'url' => $request->getSchemeAndHttpHost().$app['url_generator']->generate(
'view',
array(
'gist' => $gist->getFile(),
'commit' => array_pop($history)['commit'],
)
),
'gist' => $gist->toArray(),
));
$data = $gist->toArray();
$data['url'] = $request->getSchemeAndHttpHost().$app['url_generator']->generate(
'view',
array(
'gist' => $gist->getFile(),
'commit' => array_pop($history)['commit'],
)
);
return new JsonResponse($data);
}
return $this->invalidRequestResponse('Invalid field(s)');
}
public function updateAction(Request $request, $gist)
/**
* Updates a gist.
*
* @param Request $request
* @param string $gist
* @param string $apiKey
*
* @return JsonResponse
*/
public function updateAction(Request $request, $gist, $apiKey)
{
$app = $this->getApp();
if (false === $app['settings']['api']['enabled']) {
return new Response('', 403);
}
if (false === $this->isValidApiKey($apiKey, (bool) $app['settings']['api']['api_key_required'])) {
return $this->invalidApiKeyResponse();
}
if (false === $request->isMethod('post')) {
return $this->invalidMethodResponse('POST method is required.');
}
@ -91,21 +185,88 @@ class ApiController extends Controller
$history = $app['gist']->getHistory($gist);
return new JsonResponse(array(
'url' => $request->getSchemeAndHttpHost().$app['url_generator']->generate(
'view',
array(
'gist' => $gist->getFile(),
'commit' => array_pop($history)['commit'],
)
),
'gist' => $gist->toArray(),
));
$data = $gist->toArray();
$data['url'] = $request->getSchemeAndHttpHost().$app['url_generator']->generate(
'view',
array(
'gist' => $gist->getFile(),
'commit' => array_pop($history)['commit'],
)
);
return new JsonResponse($data);
}
return $this->invalidRequestResponse('Invalid field(s)');
}
/**
* Deletes a gist.
*
* @param Request $request
* @param string $gist
* @param string $apiKey
*
* @return JsonResponse
*/
public function deleteAction(Request $request, $gist, $apiKey)
{
$app = $this->getApp();
if (false === $app['settings']['api']['enabled']) {
return new Response('', 403);
}
if (false === $this->isValidApiKey($apiKey, true)) {
return $this->invalidApiKeyResponse();
}
if (false === $request->isMethod('post')) {
return $this->invalidMethodResponse('POST method is required.');
}
$user = $app['user.provider']->loadUserByApiKey($apiKey);
$gist = GistQuery::create()
->filterById((int) $gist)
->_or()
->filterByFile($gist)
->filterByUser($user)
->findOne();
if (!$gist) {
return $this->invalidRequestResponse('Invalid Gist');
}
$gist->delete();
return new JsonResponse(['error' => false]);
}
/**
* Builds an invalid api key response.
*
* @param mixed $message
*
* @return JsonResponse
*/
protected function invalidApiKeyResponse()
{
$data = [
'error' => ' Unauthorized',
'message' => 'Invalid API KEY',
];
return new JsonResponse($data, 401);
}
/**
* Builds an invalid method response.
*
* @param mixed $message
*
* @return JsonResponse
*/
protected function invalidMethodResponse($message = null)
{
$data = [
@ -116,6 +277,13 @@ class ApiController extends Controller
return new JsonResponse($data, 405);
}
/**
* Builds an invalid request response.
*
* @param mixed $message
*
* @return JsonResponse
*/
protected function invalidRequestResponse($message = null)
{
$data = [
@ -125,4 +293,24 @@ class ApiController extends Controller
return new JsonResponse($data, 400);
}
/**
* Checks if the given api key is valid
* depending of the requirement.
*
* @param mixed $apiKey
* @param mixed $required
*
* @return bool
*/
protected function isValidApiKey($apiKey, $required = false)
{
if (empty($apiKey)) {
return !$required;
}
return UserQuery::create()
->filterByApiKey($apiKey)
->count() === 1;
}
}

View file

@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
*
* @author Simon Vieille <simon@deblan.fr>
*/
class Controller
abstract class Controller
{
/**
* @var Application
@ -91,7 +91,6 @@ class Controller
'history' => $history,
'commit' => $commit,
'raw_content' => $content,
'content' => $app['gist']->highlight($gist->getGeshiType(), $content),
);
}
@ -128,12 +127,18 @@ class Controller
/**
* Returns the connected user.
*
* @param Request $request An API request
*
* @return mixed
*/
public function getUser()
public function getUser(Request $request = null)
{
$app = $this->getApp();
if (!empty($request)) {
}
$securityContext = $app['security.token_storage'];
$securityToken = $securityContext->getToken();

View file

@ -8,6 +8,7 @@ use Gist\Form\CloneGistForm;
use Gist\Model\Gist;
use GitWrapper\GitException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Form\FormError;
/**
* Class EditController.
@ -37,9 +38,19 @@ class EditController extends Controller
if ($request->isMethod('post')) {
$form->submit($request);
$data = $form->getData();
if (empty($form->getData()['content']) && $form->get('file')->getData()) {
$data['content'] = file_get_contents($form->get('file')->getData()->getPathName());
unset($data['file']);
}
if (empty($data['content'])) {
$form->get('content')->addError(new FormError($app['translator']->trans('form.error.not_blank')));
}
if ($form->isValid()) {
$gist = $app['gist']->create(new Gist(), $form->getData(), $this->getUser());
$gist = $app['gist']->create(new Gist(), $data, $this->getUser());
}
}

View file

@ -26,7 +26,7 @@ class LoginController extends Controller
{
$app = $this->getApp();
if (false === $app['settings']['enable_registration']) {
if (false === $app['settings']['security']['enable_registration']) {
return new Response('', 403);
}
@ -78,7 +78,7 @@ class LoginController extends Controller
{
$app = $this->getApp();
if (false === $app['settings']['enable_login']) {
if (false === $app['settings']['security']['enable_login']) {
return new Response('', 403);
}

View file

@ -58,6 +58,26 @@ class MyController extends Controller
$gists = $this->getUser()->getGistsPager($page, $options);
$apiKey = $this->getUser()->getApiKey();
if (empty($apiKey)) {
$regenerateApiKey = true;
}
// FIXME: CSRF issue!
elseif ($request->request->get('apiKey') === $apiKey && $request->request->has('generateApiKey')) {
$regenerateApiKey = true;
} else {
$regenerateApiKey = false;
}
if ($regenerateApiKey) {
$apiKey = $app['salt_generator']->generate(32, true);
$this->getUser()
->setApiKey($apiKey)
->save();
}
if ($request->isMethod('post')) {
$deleteForm->handleRequest($request);
$passwordForm->handleRequest($request);
@ -104,6 +124,7 @@ class MyController extends Controller
array(
'gists' => $gists,
'page' => $page,
'apiKey' => $apiKey,
'deleteForm' => $deleteForm->createView(),
'filterForm' => $filterForm->createView(),
'passwordForm' => $passwordForm->createView(),

View file

@ -131,7 +131,7 @@ class ViewController extends Controller
200,
array(
'Content-Disposition' => sprintf('filename=%s.%s', $gist->getFile(), $gist->getTypeAsExtension()),
'Content-Length' => filesize($file),
'Content-Length' => mb_strlen($viewOptions['raw_content']),
'Content-Type' => 'application/force-download',
)
);

View file

@ -16,7 +16,9 @@ class ApiCreateGistForm extends CreateGistForm
{
parent::build($options);
$this->builder->remove('cipher');
$this->builder
->remove('cipher')
->remove('file');
return $this->builder;
}

View file

@ -18,6 +18,7 @@ class ApiUpdateGistForm extends ApiCreateGistForm
$this->builder
->remove('title')
->remove('file')
->remove('type');
return $this->builder;

View file

@ -32,16 +32,25 @@ class CreateGistForm extends AbstractForm
'content',
'textarea',
array(
'required' => true,
'required' => false,
'attr' => array(
'class' => 'form-control',
'rows' => 10,
),
'trim' => false,
'constraints' => array(
new NotBlank(array(
'message' => $this->translator->trans('form.error.not_blank'),
)),
),
)
);
$this->builder->add(
'file',
'file',
array(
'required' => false,
'attr' => array(
),
'constraints' => array(
),
)
);

View file

@ -3,6 +3,7 @@
namespace Gist\Model;
use Gist\Model\Base\Gist as BaseGist;
use Propel\Runtime\Map\TableMap;
/**
* Class Gist.
@ -44,14 +45,16 @@ class Gist extends BaseGist
}
/**
* Returns the type for Geshi.
* Returns the type for highlighting.
*
* @return string
*/
public function getGeshiType()
public function getHighlightType()
{
$data = array(
'html' => 'xml',
'asp' => 'aspnet',
'actionscript3' => 'actionscript',
);
return str_replace(array_keys($data), array_values($data), $this->getType());
@ -86,4 +89,25 @@ class Gist extends BaseGist
return $this;
}
/**
* {@inheritdoc}
*/
public function toArray($keyType = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
{
$data = parent::toArray(
$keyType,
$includeLazyLoadColumns,
$alreadyDumpedObjects,
$includeForeignObjects
);
foreach ($data as $key => $value) {
$newKey = lcfirst($key);
unset($data[$key]);
$data[$newKey] = $value;
}
return $data;
}
}

View file

@ -54,7 +54,7 @@ class User extends BaseUser implements UserInterface
*
* @return Propel\Runtime\Util\PropelModelPager
*/
public function getGistsPager($page, $options = array(), $maxPerPage = 10)
public function getGistsPager($page, $options = array(), $maxPerPage = 10)
{
$query = GistQuery::create()
->filterByUser($this)
@ -63,11 +63,11 @@ class User extends BaseUser implements UserInterface
if (!empty($options['type']) && $options['type'] !== 'all') {
$query->filterByType($options['type']);
}
if (!empty($options['title'])) {
$query->filterByTitle('%'.$options['title'].'%', Criteria::LIKE);
}
if (!empty($options['cipher']) && $options['cipher'] !== 'anyway') {
$bools = array(
'yes' => true,

View file

@ -22,6 +22,7 @@
<column name="password" type="VARCHAR" size="255" required="true" />
<column name="roles" type="VARCHAR" size="255" required="true" />
<column name="salt" type="VARCHAR" size="64" required="true" />
<column name="api_key" type="VARCHAR" size="32" required="true" />
<behavior name="timestampable"/>
</table>

View file

@ -4,7 +4,7 @@
{% block body %}
<div class="row">
<form action="{{ path('home') }}" method="post" id="main-form">
<form action="{{ path('home') }}" method="post" id="main-form" enctype="multipart/form-data">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
@ -71,6 +71,10 @@
{{ form_errors(form.content) }}
{{ form_widget(form.content) }}
</p>
<p>
{{ form_errors(form.file) }}
{{ form_widget(form.file) }}
</p>
<p>
<input type="submit" class="btn btn-primary" value="{{ 'form.submit'|trans }}">
</p>

View file

@ -205,30 +205,61 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{ 'login.login.form.password.placeholder'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
<form action="{{ path('my', params) }}" method="post">
<p>
{{ form_errors(passwordForm.currentPassword) }}
{{ form_widget(passwordForm.currentPassword) }}
</p>
{% set apiEnabled = app.settings.api.enabled %}
<p>
{{ form_errors(passwordForm.newPassword) }}
{{ form_widget(passwordForm.newPassword) }}
</p>
<div class="row">
<div class="col-md-{{ apiEnabled ? 6 : 12 }}">
<div class="panel panel-default">
<div class="panel-heading">
{{ 'login.login.form.password.placeholder'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
<form action="{{ path('my', params) }}" method="post">
<p>
{{ form_errors(passwordForm.currentPassword) }}
{{ form_widget(passwordForm.currentPassword) }}
</p>
<p>
{{ form_rest(passwordForm) }}
<input type="submit" class="btn btn-primary" value="{{ 'form.submit'|trans }}">
</p>
</form>
<p>
{{ form_errors(passwordForm.newPassword) }}
{{ form_widget(passwordForm.newPassword) }}
</p>
<p>
{{ form_rest(passwordForm) }}
<input type="submit" class="btn btn-primary" value="{{ 'form.submit'|trans }}">
</p>
</form>
</div>
</div>
</div>
</div>
{% if apiEnabled %}
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
{{ 'my.api.title'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
<p>{{ 'my.api.warning'|trans|raw }}</p>
<form action="{{ path('my', params) }}" method="post">
<div class="row">
<p class="col-md-12">
<input type="text" name="apiKey" id="form-api-key" class="form-control" value="{{ apiKey }}" data-key="{{ apiKey }}">
</p>
<p class="col-md-12">
<input type="submit" name="generateApiKey" value="{{ 'my.api.form.generate'|trans }}" class="btn btn-primary">
</p>
</div>
</form>
</div>
</div>
</div>
</div>
{% endif %}
</div>
</div>
</div>

View file

@ -1,31 +1,17 @@
{% extends 'base.html.twig' %}
{% block css %}
{% if gist.cipher %}
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shCoreRDark.css" />
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shThemeRDark.css" />
{{ parent() }}
<link rel="stylesheet" href="{{ web_path }}components/Prism/themes/prism.css">
{% if theme_settings.name == 'dark' %}
<link rel="stylesheet" href="{{ web_path }}app/css/prism-okaidia.css">
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/prism-solarizedlight.css">
{% endif %}
{{ parent() }}
<style type="text/css">
#embed {
padding: 0;
}
#viewer {
background: #222;
}
pre {
font-size: 14px;
padding: 5px;
margin-bottom: 0;
background: #333;
}
.panel-body {
padding: 0;
}
@ -34,9 +20,8 @@
margin-bottom: 0;
}
pre ol {
padding-left: 0 !important;
list-style: none;
.container-fluid {
padding: 0;
}
</style>
{% endblock %}
@ -50,41 +35,73 @@
<div class="col-md-12" id="embed">
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right actions">
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm cipher-link">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
</a>
<div class="row">
<div class="col-md-6 col-xs-9">
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
</div>
<div class="col-md-6 col-xs-3">
<div class="visible-sm visible-xs pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-menu-hamburger"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
</a>
</li>
{% if not gist.cipher %}
<li>
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}">
{{ 'gist.action.raw'|trans }}
</a>
</li>
<li>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}">
{{ 'gist.action.download'|trans }}
</a>
</li>
{% endif %}
<li>
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="cipher-link">
{{ 'gist.action.clone'|trans }}
</a>
</li>
</ul>
</div>
</div>
<div class="visible-md visible-lg">
<div class="text-right actions">
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link"><span class="btn btn-warning btn-xs">{{ commit|slice(0, 10) }}</span></a>
{% if not gist.cipher %}
<a target="_blank" href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a target="_blank" href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}
{% if not gist.cipher %}
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}
<a target="_blank" href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>
</div>
</div>
</div>
</div>
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
<div id="view" class="tab-pane active in">
<div id="viewer">
{% if gist.cipher %}
<pre class="brush: {{ gist.type }}; syntaxhighlighter">{{ raw_content|raw }}</pre>
{% else %}
{{ content|raw }}
{% endif %}
<pre><code {% if gist.cipher %}data-cipher{% endif %} class="language-{{ gist.highlightType }}">{{ raw_content }}</code></pre>
</div>
</div>
</div>
@ -100,37 +117,5 @@
{{ parent() }}
<script type="text/javascript" src="{{ web_path }}components/iframe-resizer/js/iframeResizer.contentWindow.min.js"></script>
{% if gist.cipher %}
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/XRegExp.js"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="{{ web_path }}components/SyntaxHighlighter/scripts/shAutoloader.js"></script>
<script type="text/javascript">
SyntaxHighlighter.autoloader(
['applescript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAppleScript.js' ],
['actionscript3', 'as3', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushAS3.js' ],
['bash', 'shell', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushBash.js' ],
['coldfusion', 'cf', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushColdFusion.js' ],
['cpp', 'c', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCpp.js' ],
['c#', 'c-sharp', 'csharp', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCSharp.js' ],
['css', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushCss.js' ],
['delphi', 'pascal', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDelphi.js' ],
['diff', 'patch', 'pas', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushDiff.js' ],
['erl', 'erlang', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushErlang.js' ],
['groovy', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushGroovy.js' ],
['java', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJava.js' ],
['jfx', 'javafx', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJavaFX.js' ],
['js', 'jscript', 'javascript', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushJScript.js' ],
['perl', 'pl', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPerl.js' ],
['php', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPhp.js' ],
['text', 'plain', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPlain.js' ],
['py', 'python', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushPython.js' ],
['ruby', 'rails', 'ror', 'rb', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushRuby.js' ],
['scala', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushScala.js' ],
['sql', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushSql.js' ],
['vb', 'vbnet', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushVb.js' ],
['xml', 'xhtml', 'xslt', 'html', '{{ web_path }}components/SyntaxHighlighter/scripts/shBrushXml.js' ]
);
</script>
{% endif %}
<script src="{{ web_path }}app/js/prism.js" {% if gist.cipher %}data-manual{% endif %}></script>
{% endblock %}

View file

@ -1,9 +1,15 @@
{% extends 'base.html.twig' %}
{% block css %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{{ parent() }}
<link rel="stylesheet" href="{{ web_path }}app/css/prism.css">
{% if theme_settings.name == 'dark' %}
<link rel="stylesheet" href="{{ web_path }}app/css/prism-okaidia.css">
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/prism-solarizedlight.css">
{% endif %}
{% endblock %}
{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ 'gist.action.history'|trans }}{% endblock %}
@ -23,7 +29,7 @@
<span class="badge">{{ history|length }}</span>
</a>
</li>
</ul>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
@ -40,7 +46,7 @@
</a>
{% if loop.first %}<span class="btn btn-info btn-sm">init</span>{% endif %}
{% if not loop.first %}
<a href="#diff-{{ loop.index }}" data-target="#diff-{{ loop.index }}" class="btn btn-default btn-sm show-diff">
diff
@ -52,17 +58,14 @@
</p>
<div>
{% if not loop.first %}
<div class="diff" id="diff-{{ loop.index }}">
{% if not gist.cipher %}
{{ commit.diff|raw }}
{% endif %}
</div>
<pre><code class="diff language-diff" id="diff-{{ loop.index }}">{% if not gist.cipher %}{{ commit.diff }}{% endif %}</code></pre>
{% endif %}
</div>
</div>
{% if not loop.last %}
<hr />
<hr />
{% endif %}
{% endfor %}
</div>
@ -76,9 +79,9 @@
{% block js %}
{{ parent() }}
{% if gist.cipher %}
{{ include('View/cipherJs.html.twig') }}
<script src="{{ web_path }}app/js/prism.js" {% if gist.cipher %}data-manual{% endif %}></script>
{% if gist.cipher %}
<script src="{{ web_path }}components/jsdiff/diff.min.js"></script>
<script>
@ -115,21 +118,19 @@
var lines = value.split("\n");
for (var i = 0, l = lines.length; i < l; i++) {
diffContent.push(sign + lines[i]);
if (lines[i] != '\ No newline at end of file') {
diffContent.push(sign + lines[i]);
}
}
}
diffContent = diffContent.join("\n");
var $pre = $('<pre>')
.attr('class', 'brush: diff; syntaxhighlighter')
.text(diffContent);
$('#diff-' + (u + 1).toString()).append($pre);
$('#diff-' + (u + 1).toString()).text(diffContent);
}
}
SyntaxHighlighter.all();
Prism.highlightAll();
</script>
{% endif %}
{% endblock %}

View file

@ -1,14 +1,15 @@
{% extends 'base.html.twig' %}
{% block css %}
{% if gist.cipher %}
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shCoreRDark.css" />
<link type="text/css" rel="Stylesheet" href="{{ web_path }}components/SyntaxHighlighter/styles/shThemeRDark.css" />
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/geshi/vibrant-ink.css" />
{% endif %}
{{ parent() }}
<link rel="stylesheet" href="{{ web_path }}app/css/prism.css">
{% if theme_settings.name == 'dark' %}
<link rel="stylesheet" href="{{ web_path }}app/css/prism-okaidia.css">
{% else %}
<link rel="stylesheet" href="{{ web_path }}app/css/prism-solarizedlight.css">
{% endif %}
{% endblock %}
{% block title %}{{ gist.title ? gist.title : 'gist.untitled'|trans }} - {{ commit|slice(0, 10) }}{% endblock %}
@ -32,46 +33,89 @@
<div class="panel panel-default">
<div class="panel-heading">
<div class="pull-right actions">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
<div class="row">
<div class="col-md-6 col-xs-9">
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
</div>
<div class="col-md-6 col-xs-3">
<div class="visible-sm visible-xs pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-menu-hamburger"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li>
<a target="_blank" href="{{ path('view', app.request.attributes.get('_route_params')) }}" class="cipher-link">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
</a>
</li>
{% if not gist.cipher %}
<li>
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}">
{{ 'gist.action.raw'|trans }}
</a>
</li>
<li>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}">
{{ 'gist.action.download'|trans }}
</a>
</li>
{% endif %}
<li>
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="cipher-link">
{{ 'gist.action.clone'|trans }}
</a>
</li>
</ul>
</div>
</div>
<div class="visible-md visible-lg">
<div class="text-right actions">
<span class="btn btn-warning btn-xs">
{{ commit|slice(0, 10) }}
</span>
{% if not gist.cipher %}
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}
{% if not gist.cipher %}
<a href="{{ path('raw', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-eye-open"></span>
{{ 'gist.action.raw'|trans }}
</a>
<a href="{{ path('download', app.request.attributes.get('_route_params')) }}" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-save-file"></span>
{{ 'gist.action.download'|trans }}
</a>
{% endif %}
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>
<a href="{{ path('clone', app.request.attributes.get('_route_params')) }}" class="btn btn-success btn-sm cipher-link">
<span class="glyphicon glyphicon-copy"></span>
{{ 'gist.action.clone'|trans }}
</a>
</div>
</div>
</div>
</div>
{{ gist.title ? gist.title : 'gist.untitled'|trans }}
</div>
<div class="panel-body">
<div class="tab-content">
<div id="view" class="tab-pane active in">
<div id="viewer">
{% if gist.cipher %}
<pre class="brush: {{ gist.type }}; syntaxhighlighter">{{ raw_content|raw }}</pre>
{% else %}
{{ content|raw }}
{% endif %}
<pre><code {% if gist.cipher %}data-cipher{% endif %} class="language-{{ gist.highlightType }}">{{ raw_content }}</code></pre>
</div>
<p id="embed" class="pull-right">
{{ 'gist.action.embed'|trans }}
<input type="text" class="form-control" id="embed-input" value="{{ '<div%key%id="gist-' ~ gist.file ~ '-' ~ commit ~ '" class="gist-container"></div><script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', app.request.attributes.get('_route_params')) ~ '" async></script>' }}" />
</p>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
{{ 'gist.action.embed'|trans }}
</div>
<div class="panel-body" id="embed">
<div class="tab-content">
<div class="tab-pane active in">
<pre><code class="language-html">{{ '<div%key%id="gist-' ~ gist.file ~ '-' ~ commit ~ '" class="gist-container"></div>
<script src="' ~ app.request.getSchemeAndHttpHost() ~ path('embedjs', app.request.attributes.get('_route_params')) ~ '" async></script>' }}</code></pre>
</div>
</div>
</div>
@ -82,8 +126,6 @@
{% block js %}
{{ parent() }}
{% if gist.cipher %}
{{ include('View/cipherJs.html.twig') }}
{% endif %}
<script src="{{ web_path }}app/js/prism.js" {% if gist.cipher %}data-manual{% endif %}></script>
{% endblock %}

View file

@ -1,26 +1,28 @@
<!DOCTYPE html>
{% set theme_settings = app.settings.theme %}
{% set security_dettings = app.settings.security %}
{% set security_settings = app.settings.security %}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% block css %}
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css" />
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ web_path }}components/flag-icon-css/css/flag-icon.min.css">
{% if theme_settings.name == 'dark' %}
<link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/bootstrap/bootstrap.min.css">
{% else %}
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap-theme.min.css" />
<link rel="stylesheet" href="{{ web_path }}components/bootstrap/dist/css/bootstrap-theme.min.css">
{% endif %}
<link rel="stylesheet" href="{{ web_path }}app/css/themes/{{ theme_settings.name }}.css" />
<link rel="stylesheet" href="{{ web_path }}app/css/themes/{{ theme_settings.name }}.css">
{% endblock %}
{% block metas %}
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
{% endblock %}
<link rel="shortcut icon" href="{{ web_path }}favicon.png">
<title>{{ 'app.title_prefix'|trans }}{% block title %}{% endblock %}</title>
</head>
<body>
@ -56,14 +58,14 @@
{{ 'app.menu.my.logout.title'|trans }}
</a>
</li>
{% elseif security_dettings.enable_login %}
{% elseif security_settings.enable_login %}
<li>
<a href="{{ path('login') }}">
{{ 'app.menu.my.login.title'|trans }}
</a>
</li>
{% if security_dettings.enable_registration %}
{% if security_settings.enable_registration %}
<li>
<a href="{{ path('register') }}">
{{ 'app.menu.my.register.title'|trans }}

View file

@ -32,25 +32,18 @@ class Gist
*/
protected $gitWorkingCopy;
/**
* @var GeSHi
*/
protected $geshi;
/**
* __construct.
*
* @param mixed $gistPath
* @param GitWrapper $gitWrapper
* @param GitWorkingCopy $gitWorkingCopy
* @param GeSHi $geshi
*/
public function __construct($gistPath, GitWrapper $gitWrapper, GitWorkingCopy $gitWorkingCopy, GeSHi $geshi)
public function __construct($gistPath, GitWrapper $gitWrapper, GitWorkingCopy $gitWorkingCopy)
{
$this->gistPath = $gistPath;
$this->gitWrapper = $gitWrapper;
$this->gitWorkingCopy = $gitWorkingCopy;
$this->geshi = $geshi;
}
/**
@ -95,7 +88,7 @@ class Gist
$data = array(
'commit' => trim($commits[$i][1]),
'date' => new \DateTime(trim($dates[$i][1])),
'diff' => $this->highlight('diff', $diff),
'diff' => str_replace('\ No newline at end of file', '', $diff),
);
if ($gist->isCipher()) {
@ -193,20 +186,4 @@ class Gist
return count(explode("\n", $content));
}
/**
* Highlight the content.
*
* @param string $type
* @param string $content
*
* @return string
*/
public function highlight($type, $content)
{
$this->geshi->set_source($content);
$this->geshi->set_language($type);
return $this->geshi->parse_code();
}
}

View file

@ -18,18 +18,30 @@ class SaltGenerator
*
* @return string
*/
public function generate($length = 32)
public function generate($length = 32, $isApiKey = false)
{
if (!is_numeric($length)) {
throw new InvalidArgumentException('Paramter length must be a valid integer.');
}
if (function_exists('openssl_random_pseudo_bytes')) {
return substr(base64_encode(openssl_random_pseudo_bytes($length)), 0, $length);
$string = base64_encode(openssl_random_pseudo_bytes(256));
}
if (function_exists('mcrypt_create_iv')) {
return substr(base64_encode(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)), 0, $length);
$string = base64_encode(mcrypt_create_iv(256, MCRYPT_DEV_URANDOM));
}
if (!empty($string)) {
if (true === $isApiKey) {
$string = str_replace(
array('+', '%', '/', '#', '&'),
'',
$string
);
}
return substr($string, 0, $length);
}
throw new RuntimeException('You must enable openssl or mcrypt modules.');

View file

@ -126,6 +126,7 @@ class UserProvider implements UserProviderInterface
$user
->setRoles('ROLE_USER')
->setPassword($this->encoder->encodePassword($password, $user->getSalt()))
->setApiKey($this->saltGenerator->generate(32, true))
->save();
return $user;
@ -166,6 +167,20 @@ class UserProvider implements UserProviderInterface
return $user;
}
/**
* Loads a user by his api key.
*
* @param string $apiKey
*
* @return User
*/
public function loadUserByApiKey($apiKey)
{
$user = UserQuery::create()->findOneByApiKey($apiKey);
return $user;
}
/*
* Checks if the given password is the current user password.
*

View file

@ -1,146 +0,0 @@
/* @override http://localhost/mark_story2/site/css/geshi.css */
/**
* GeSHi CSS Inspired by
* TextMate Theme Dawn
*
* Copyright 2008 Mark Story
*
* This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* @copyright Copyright 2008, Mark Story.
* @link http://mark-story.com
* @license http://creativecommons.org/licenses/by-sa/2.5/ca/
*/
/*
* Global geshi styles
**********************/
#main pre {
line-height: 1.5em;
font-size: 10px;
white-space: normal;
padding: 0;
background: #E8EDF4;
border: 1px solid #222;
}
pre ol {
list-style: decimal;
list-style-position: outside;
padding: 0;
margin: 0;
}
#main pre ol li {
margin: 0 0 0 35px;
padding: 0;
color: #333;
clear: none;
}
pre ol li div {
color:#000;
}
/* Line highlights */
.li1 {
background: #E4E8EF;
}
/* comments */
.co1,
.coMULTI {
color:#5A526E;
}
/* methods */
.me1{
color:#000;
}
.me0 {
}
.me2 {
color:#000;
}
/* brackets */
.br0 {
color:#000;
}
/* strings */
.st0 {
color:#0B6125;
}
/* keywords */
.kw1 {
color: #794938;
}
.kw2 {
color:#A71D5D;
font-style: italic;
}
.kw3 {
color:#693A17;
}
/* numbers */
.nu0 {
color:#811F24;
}
/* vars */
.re0 {
color:#434A97;
}
/*
* CSS selectors
*****************/
/* classnames */
[lang=css] .kw2,
.css .kw2 {
color:#C24F24;
}
[lang=css] .kw1,
.css .kw1 {
color:#691C97;
}
[lang=css] .re0,
.css .re0 {
color: #C24F24;
}
.re1 {
color: #C24F24;
}
/* px values */
[lang=css] .re3,
.css .re3 {
color:#84252A;
}
/*
* Python
****************/
[lang=python] ol li div,
.python ol li div {
color: #000;
}
[lang=python] .kw2,
.python .kw2 {
font-style: normal;
}
[lang=python] .kw1 {
color: #A91D5D;
}
/*
* Javascript
****************/
[lang=javascript] .me1,
.javascript .me1 {
color: #794938;
}

View file

@ -1,131 +0,0 @@
/**
* GeSHi CSS Inspired by TextMate
* Theme Mac Classic
*
* Copyright 2008 Mark Story
*
* This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* @copyright Copyright 2008, Mark Story.
* @link http://mark-story.com
* @license http://creativecommons.org/licenses/by-sa/2.5/ca/
*/
/*
* Global geshi styles
**********************/
#main pre {
line-height: 1.5em;
font-size: 10px;
white-space: normal;
padding: 0;
background: #eae9e5;
border: 1px solid #c0c0c0;
}
pre ol {
list-style: decimal;
list-style-position: outside;
padding: 0;
margin: 0;
}
#main pre ol li {
margin: 0 0 0 35px;
padding: 0;
color: #000;
clear: none;
}
pre ol li div {
color:#000;
}
/* php */
pre[lang=php] ol div,
pre.php ol div {
color:#fd1435;
}
/* Line highlights */
.li1 {
background: #f2f2f2;
}
/* Line highlights */
.li1 {
background: #f2f2f2;
}
/* comments */
.co1,
.coMULTI {
color:#5c9dff;
}
/* methods */
.me1{
color:#000;
}
.me0 {
}
.me2 {
color:#000;
}
/* brackets */
.br0 {
color:#222;
}
/* strings */
.st0 {
color:#b701bb;
}
/* keywords */
.kw1 {
color: #fd1435;
}
.kw2 {
color:#6266f5;
}
.kw3 {
color:#505e80;
}
/* numbers */
.nu0 {
color:#0a0aa5;
}
/* vars */
.re0 {
color:#059532;
}
/*
* CSS selectors
*****************/
/* classnames */
[lang=css] .kw2,
.css .kw2 {
color:#0a0aa5;
}
.re1 {
color: #b701bb;
}
/* px values */
[lang=css] .re3,
.css .re3 {
color:#059532;
}
/*
* Javascript
****************/
[lang=javascript] .me1,
.javascript .me1 {
color:#505e80;
}

View file

@ -1,123 +0,0 @@
/* @override http://localhost/mark_story2/site/css/geshi.css */
/**
* GeSHi CSS Inspired by TextMate
* Theme Twilight
*
* Copyright 2008 Mark Story
*
* This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* @filesource
* @copyright Copyright 2008, Mark Story.
* @link http://mark-story.com
* @license http://creativecommons.org/licenses/by-sa/2.5/ca/
*/
/*
* Global geshi styles
**********************/
#main pre {
line-height: 1.5em;
font-size: 10px;
white-space: normal;
padding: 0;
background: #222223;
border: 1px solid #222;
}
pre ol {
list-style: decimal;
list-style-position: outside;
padding: 0;
margin: 0;
}
#main pre ol li {
margin: 0 0 0 35px;
padding: 0;
color: #000;
clear: none;
}
pre ol li div {
color:#f8f8f8;
}
/* Line highlights */
.li1 {
background: #202021;
}
/* comments */
.co1,
.coMULTI {
color:#5F5A60;
}
/* methods */
.me1{
color:#fff;
}
.me0 {
}
.me2 {
color:#000;
}
/* brackets */
.br0 {
color:#fff;
}
/* strings */
.st0 {
color:#8F9657;
}
/* keywords */
.kw1 {
color: #CDA869;
}
.kw2 {
color:#F9EE98;
}
.kw3 {
color:#505e80;
}
/* numbers */
.nu0 {
color:#CF6745;
}
/* vars */
.re0 {
color:#7587A6;
}
/*
* CSS selectors
*****************/
/* classnames */
[lang=css] .kw2,
.css .kw2 {
color:#F9EE7E;
}
.re1 {
color: #96703D;
}
/* px values */
[lang=css] .re3,
.css .re3 {
color:#CA7840;
}
/*
* Javascript
****************/
[lang=javascript] .me1,
.javascript .me1 {
color:#505e80;
}

View file

@ -1,148 +0,0 @@
/* @override http://localhost/mark_story2/site/css/geshi.css */
/**
* GeSHi CSS Inspired by TextMate
* Theme Vibrant Ink
*
* Copyright 2008 Mark Story
*
* This work is licensed under the Creative Commons Attribution-Share Alike 2.5 Canada License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ca/
* or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
*
* @copyright Copyright 2008, Mark Story.
* @link http://mark-story.com
* @license http://creativecommons.org/licenses/by-sa/2.5/ca/
*/
/*
* Global geshi styles
**********************/
#main pre {
line-height: 1.5em;
font-size: 10px;
white-space: normal;
padding: 0;
background: #000;
border: 1px solid #222;
}
pre ol {
list-style: decimal;
list-style-position: outside;
padding: 0;
margin: 0;
}
#main pre ol li {
margin: 0 0 0 35px;
padding: 0;
color: #fff;
clear: none;
}
pre ol li div {
/*color: #F26100;*/
color: #D2C0B4;
}
/* Line highlights */
.li1 {
background: #030303;
}
/* comments */
.co1,
.coMULTI {
color:#7830CC;
}
/* methods */
.me1{
color:#fff;
}
.me0 {
}
.me2 {
color:#000;
}
/* brackets */
.br0 {
color:#fff;
}
/* strings */
.st0 {
color:#52F700;
}
/* keywords */
.kw1 {
color: #C6C765;
}
.kw2 {
color:#FFC500;
}
.kw3 {
color:#505e80;
}
/* numbers */
.nu0 {
color:#319994;
}
/* vars */
.re0 {
color:#fff;
}
/*
* CSS selectors
*****************/
/* classnames */
[lang=css] .kw2,
.css .kw2 {
color:#fff;
}
[lang=css] .kw1,
.css .kw1 {
color:#999966;
}
[lang=css] .re0,
.css .re0 {
color: #F26100;
}
.re1 {
color: #96703D;
}
/* px values */
[lang=css] .re3,
.css .re3 {
color:#fff;
}
/*
* Python
****************/
[lang=python] ol li div,
.python ol li div {
color: #fff;
}
[lang=python] .kw1,
.python .kw1 {
color:#F26100;
}
/*
* Javascript
****************/
[lang=javascript] .me1,
.javascript .me1 {
color:#fff;
}
pre[lang=javascript] ol li div,
.javascript ol li div {
color: #fff;
}

View file

@ -0,0 +1,121 @@
/**
* okaidia theme for JavaScript, CSS and HTML
* Loosely based on Monokai textmate theme by http://www.monokai.nl/
* @author ocodia
*/
code[class*="language-"],
pre[class*="language-"] {
color: #f8f8f2;
background: none;
text-shadow: 0 1px rgba(0, 0, 0, 0.3);
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
border-radius: 0.3em;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #272822;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #f8f8f2;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.constant,
.token.symbol,
.token.deleted {
color: #f92672;
}
.token.boolean,
.token.number {
color: #ae81ff;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #a6e22e;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string,
.token.variable {
color: #f8f8f2;
}
.token.atrule,
.token.attr-value,
.token.function {
color: #e6db74;
}
.token.keyword {
color: #66d9ef;
}
.token.regex,
.token.important {
color: #fd971f;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}

View file

@ -0,0 +1,148 @@
/*
Solarized Color Schemes originally by Ethan Schoonover
http://ethanschoonover.com/solarized
Ported for PrismJS by Hector Matos
Website: https://krakendev.io
Twitter Handle: https://twitter.com/allonsykraken)
*/
/*
SOLARIZED HEX
--------- -------
base03 #002b36
base02 #073642
base01 #586e75
base00 #657b83
base0 #839496
base1 #93a1a1
base2 #eee8d5
base3 #fdf6e3
yellow #b58900
orange #cb4b16
red #dc322f
magenta #d33682
violet #6c71c4
blue #268bd2
cyan #2aa198
green #859900
*/
code[class*="language-"],
pre[class*="language-"] {
color: #657b83; /* base00 */
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
background: #073642; /* base02 */
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
background: #073642; /* base02 */
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
border-radius: 0.3em;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background-color: #fdf6e3; /* base3 */
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: #93a1a1; /* base1 */
}
.token.punctuation {
color: #586e75; /* base01 */
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #268bd2; /* blue */
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.url,
.token.inserted {
color: #2aa198; /* cyan */
}
.token.entity {
color: #657b83; /* base00 */
background: #eee8d5; /* base2 */
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #859900; /* green */
}
.token.function {
color: #b58900; /* yellow */
}
.token.regex,
.token.important,
.token.variable {
color: #cb4b16; /* orange */
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}

467
web/app/css/prism.css Normal file
View file

@ -0,0 +1,467 @@
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+actionscript+c+aspnet+bash+cpp+csharp+css-extras+diff+perl+php+php-extras+python+sql+yaml&plugins=line-highlight+line-numbers+autolinker+previewer-base+previewer-color+previewer-gradient+previewer-easing+previewer-time+previewer-angle */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/
code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;
-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}
pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}
pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}
@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}
/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}
:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}
/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}
.token.punctuation {
color: #999;
}
.namespace {
opacity: .7;
}
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}
.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}
.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}
.token.function {
color: #DD4A68;
}
.token.regex,
.token.important,
.token.variable {
color: #e90;
}
.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}
.token.entity {
cursor: help;
}
pre[data-line] {
position: relative;
padding: 1em 0 1em 3em;
}
.line-highlight {
position: absolute;
left: 0;
right: 0;
padding: inherit 0;
margin-top: 1em; /* Same as .prisms padding-top */
background: hsla(24, 20%, 50%,.08);
background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
pointer-events: none;
line-height: inherit;
white-space: pre;
}
.line-highlight:before,
.line-highlight[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(24, 20%, 50%,.4);
color: hsl(24, 20%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: .3em;
border-radius: 999px;
text-shadow: none;
box-shadow: 0 1px white;
}
.line-highlight[data-end]:after {
content: attr(data-end);
top: auto;
bottom: .4em;
}
pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}
pre.line-numbers > code {
position: relative;
white-space: inherit;
}
.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}
.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
.token a {
color: inherit;
}
.prism-previewer,
.prism-previewer:before,
.prism-previewer:after {
position: absolute;
pointer-events: none;
}
.prism-previewer,
.prism-previewer:after {
left: 50%;
}
.prism-previewer {
margin-top: -48px;
width: 32px;
height: 32px;
margin-left: -16px;
opacity: 0;
-webkit-transition: opacity .25s;
-o-transition: opacity .25s;
transition: opacity .25s;
}
.prism-previewer.flipped {
margin-top: 0;
margin-bottom: -48px;
}
.prism-previewer:before,
.prism-previewer:after {
content: '';
position: absolute;
pointer-events: none;
}
.prism-previewer:before {
top: -5px;
right: -5px;
left: -5px;
bottom: -5px;
border-radius: 10px;
border: 5px solid #fff;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75);
}
.prism-previewer:after {
top: 100%;
width: 0;
height: 0;
margin: 5px 0 0 -7px;
border: 7px solid transparent;
border-color: rgba(255, 0, 0, 0);
border-top-color: #fff;
}
.prism-previewer.flipped:after {
top: auto;
bottom: 100%;
margin-top: 0;
margin-bottom: 5px;
border-top-color: rgba(255, 0, 0, 0);
border-bottom-color: #fff;
}
.prism-previewer.active {
opacity: 1;
}
.prism-previewer-color {
background-image: linear-gradient(45deg, #bbb 25%, transparent 25%, transparent 75%, #bbb 75%, #bbb), linear-gradient(45deg, #bbb 25%, #eee 25%, #eee 75%, #bbb 75%, #bbb);
background-size: 10px 10px;
background-position: 0 0, 5px 5px;
}
.prism-previewer-color:before {
background-color: inherit;
background-clip: padding-box;
}
.prism-previewer-gradient {
background-image: linear-gradient(45deg, #bbb 25%, transparent 25%, transparent 75%, #bbb 75%, #bbb), linear-gradient(45deg, #bbb 25%, #eee 25%, #eee 75%, #bbb 75%, #bbb);
background-size: 10px 10px;
background-position: 0 0, 5px 5px;
width: 64px;
margin-left: -32px;
}
.prism-previewer-gradient:before {
content: none;
}
.prism-previewer-gradient div {
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
border-radius: 10px;
border: 5px solid #fff;
box-shadow: 0 0 3px rgba(0, 0, 0, 0.5) inset, 0 0 10px rgba(0, 0, 0, 0.75);
}
.prism-previewer-easing {
margin-top: -76px;
margin-left: -30px;
width: 60px;
height: 60px;
background: #333;
}
.prism-previewer-easing.flipped {
margin-bottom: -116px;
}
.prism-previewer-easing svg {
width: 60px;
height: 60px;
}
.prism-previewer-easing circle {
fill: hsl(200, 10%, 20%);
stroke: white;
}
.prism-previewer-easing path {
fill: none;
stroke: white;
stroke-linecap: round;
stroke-width: 4;
}
.prism-previewer-easing line {
stroke: white;
stroke-opacity: 0.5;
stroke-width: 2;
}
@-webkit-keyframes prism-previewer-time {
0% {
stroke-dasharray: 0, 500;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100, 500;
stroke-dashoffset: 0;
}
100% {
stroke-dasharray: 0, 500;
stroke-dashoffset: -100;
}
}
@-o-keyframes prism-previewer-time {
0% {
stroke-dasharray: 0, 500;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100, 500;
stroke-dashoffset: 0;
}
100% {
stroke-dasharray: 0, 500;
stroke-dashoffset: -100;
}
}
@-moz-keyframes prism-previewer-time {
0% {
stroke-dasharray: 0, 500;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100, 500;
stroke-dashoffset: 0;
}
100% {
stroke-dasharray: 0, 500;
stroke-dashoffset: -100;
}
}
@keyframes prism-previewer-time {
0% {
stroke-dasharray: 0, 500;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100, 500;
stroke-dashoffset: 0;
}
100% {
stroke-dasharray: 0, 500;
stroke-dashoffset: -100;
}
}
.prism-previewer-time:before {
border-radius: 50%;
background: #fff;
}
.prism-previewer-time:after {
margin-top: 4px;
}
.prism-previewer-time svg {
width: 32px;
height: 32px;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.prism-previewer-time circle {
fill: transparent;
stroke: hsl(200, 10%, 20%);
stroke-opacity: 0.9;
stroke-width: 32;
stroke-dasharray: 0, 500;
stroke-dashoffset: 0;
-webkit-animation: prism-previewer-time linear infinite 3s;
-moz-animation: prism-previewer-time linear infinite 3s;
-o-animation: prism-previewer-time linear infinite 3s;
animation: prism-previewer-time linear infinite 3s;
}
.prism-previewer-angle:before {
border-radius: 50%;
background: #fff;
}
.prism-previewer-angle:after {
margin-top: 4px;
}
.prism-previewer-angle svg {
width: 32px;
height: 32px;
-webkit-transform: rotate(-90deg);
-moz-transform: rotate(-90deg);
-ms-transform: rotate(-90deg);
-o-transform: rotate(-90deg);
transform: rotate(-90deg);
}
.prism-previewer-angle[data-negative] svg {
-webkit-transform: scaleX(-1) rotate(-90deg);
-moz-transform: scaleX(-1) rotate(-90deg);
-ms-transform: scaleX(-1) rotate(-90deg);
-o-transform: scaleX(-1) rotate(-90deg);
transform: scaleX(-1) rotate(-90deg);
}
.prism-previewer-angle circle {
fill: transparent;
stroke: hsl(200, 10%, 20%);
stroke-opacity: 0.9;
stroke-width: 32;
stroke-dasharray: 0, 500;
}

View file

@ -26,54 +26,24 @@ body {
margin-right: 4px;
}
pre {
background: #222;
border: #222;
color: #ddd;
#viewer pre, #viewer code, #revisions pre, #revisions code, #embed pre, #embed code {
background: none !important;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}
pre ol {
padding-left: 50px !important;
}
pre li:hover {
background: #444;
border: 0;
}
.panel-heading .actions {
margin-top: -5px;
}
div.diff {
.diff {
display: none;
}
.de1 {
padding-left: 5px;
padding-right: 5px;
}
.li1 {
background: #333;
}
.re8 {
color: #52F700;
}
.kw3 {
color: #C6C765;
}
#viewer .syntaxhighlighter td {
vertical-align: top !important;
}
#options {
margin-bottom: 17px;
}

View file

@ -16,54 +16,24 @@
margin-right: 4px;
}
pre {
background: #222;
border: #222;
color: #ddd;
white-space: pre-wrap;
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;
}
pre ol {
padding-left: 50px !important;
}
pre li:hover {
background: #444;
pre, code {
background: none !important;
white-space: pre-wrap !important;
white-space: -moz-pre-wrap !important;
white-space: -pre-wrap !important;
white-space: -o-pre-wrap !important;
word-wrap: break-word !important;
border: 0;
}
.panel-heading .actions {
margin-top: -5px;
}
div.diff {
.diff {
display: none;
}
.de1 {
padding-left: 5px;
padding-right: 5px;
}
.li1 {
background: #333;
}
.re8 {
color: #52F700;
}
.kw3 {
color: #C6C765;
}
#viewer .syntaxhighlighter td {
vertical-align: top !important;
}
#options {
margin-bottom: 17px;
}

View file

@ -98,6 +98,10 @@ var myEvents = function() {
$('#form-deletion form').submit();
}
});
$(document).on('change keyup keydown', '#form-api-key', function() {
$(this).val($(this).data('key'));
});
}
var mainEditorEvents = function() {
@ -134,13 +138,13 @@ var getKey = function() {
}
var viewerEvents = function() {
var $render = $('.syntaxhighlighter');
var $render = $('#viewer code[data-cipher]');
$(document).ready(function() {
var key = getKey();
var $cipherEditor = $('.cipher-editor');
var $embedInput = $('#embed-input');
var $embedCode = $('#embed code');
var to = ' ';
@ -159,7 +163,8 @@ var viewerEvents = function() {
});
$render.text(decrypted.toString(CryptoJS.enc.Utf8));
SyntaxHighlighter.all();
$render.attr('class', $render.data('class'));
Prism.highlightAll();
to = ' data-key="#key=' + key + '" ';
} else {
@ -172,8 +177,9 @@ var viewerEvents = function() {
}
}
if ($embedInput.length) {
$embedInput.val($embedInput.val().replace('%key%', to));
if ($embedCode.length) {
$embedCode.html($embedCode.html().replace('%key%', to));
Prism.highlightAll();
}
});
}

29
web/app/js/prism.js Normal file

File diff suppressed because one or more lines are too long

BIN
web/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 B