This commit is contained in:
JoseluCross
2018-09-30 12:13:14 +02:00
parent a465ac6199
commit 94d28dc292
8 changed files with 228 additions and 91 deletions

3
Source/.env.dist Normal file
View File

@@ -0,0 +1,3 @@
# This file is a "template" of which env vars need to be defined for your application
# Copy this file to .env file for development, create environment variables when deploying to production
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration

View File

@@ -1,4 +1,4 @@
{% extends "base.twig" %} {% extends app.fronthtml~"/base.twig" %}
{% block content %} {% block content %}
<form class="form-horizontal" method="post"> <form class="form-horizontal" method="post">
<div class="form-group"> <div class="form-group">

View File

@@ -69,7 +69,7 @@
<div class="form-group"> <div class="form-group">
<label class="control-label col-sm-2" for="name">Nickname:</label> <label class="control-label col-sm-2" for="name">Nickname:</label>
<div class="col-sm-10"> <div class="col-sm-10">
<input type="text" class="form-control" required="required" name="name" id="pwdre-re" placeholder="Enter your nickname for public identification"> <input type="text" class="form-control" required="required" name="nick" id="nick" placeholder="Enter your nickname for public identification">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -14,7 +14,7 @@
<a href="{{ path('home') }}">Home</a> <a href="{{ path('home') }}">Home</a>
</li> </li>
<li {% if page.page == "add" %}class="active"{% endif %}> <li {% if page.page == "add" %}class="active"{% endif %}>
<a href="?page=add">Submit code</a> <a href="{{ path('add') }}">Submit code</a>
</li> </li>
<li {% if page.page == "doc" %}class="active"{% endif %}> <li {% if page.page == "doc" %}class="active"{% endif %}>
<a href="{{ path('doc') }}">Documentation</a> <a href="{{ path('doc') }}">Documentation</a>

56
Source/composer.lock generated
View File

@@ -1,7 +1,7 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "80eef0db968dff798db6ae8ac2157e65", "content-hash": "80eef0db968dff798db6ae8ac2157e65",
@@ -283,16 +283,16 @@
}, },
{ {
"name": "symfony/debug", "name": "symfony/debug",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/debug.git", "url": "https://github.com/symfony/debug.git",
"reference": "47ead688f1f2877f3f14219670f52e4722ee7052" "reference": "b4a0b67dee59e2cae4449a8f8eabc508d622fd33"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/debug/zipball/47ead688f1f2877f3f14219670f52e4722ee7052", "url": "https://api.github.com/repos/symfony/debug/zipball/b4a0b67dee59e2cae4449a8f8eabc508d622fd33",
"reference": "47ead688f1f2877f3f14219670f52e4722ee7052", "reference": "b4a0b67dee59e2cae4449a8f8eabc508d622fd33",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -335,11 +335,11 @@
], ],
"description": "Symfony Debug Component", "description": "Symfony Debug Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-08-03T11:13:38+00:00" "time": "2018-09-22T19:04:12+00:00"
}, },
{ {
"name": "symfony/event-dispatcher", "name": "symfony/event-dispatcher",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/event-dispatcher.git", "url": "https://github.com/symfony/event-dispatcher.git",
@@ -449,16 +449,16 @@
}, },
{ {
"name": "symfony/http-foundation", "name": "symfony/http-foundation",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-foundation.git", "url": "https://github.com/symfony/http-foundation.git",
"reference": "3a5c91e133b220bb882b3cd773ba91bf39989345" "reference": "2ce66353d0a6ea96bc54bc9ecf8bcea4eaf5896c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/3a5c91e133b220bb882b3cd773ba91bf39989345", "url": "https://api.github.com/repos/symfony/http-foundation/zipball/2ce66353d0a6ea96bc54bc9ecf8bcea4eaf5896c",
"reference": "3a5c91e133b220bb882b3cd773ba91bf39989345", "reference": "2ce66353d0a6ea96bc54bc9ecf8bcea4eaf5896c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -499,20 +499,20 @@
], ],
"description": "Symfony HttpFoundation Component", "description": "Symfony HttpFoundation Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-08-27T17:47:02+00:00" "time": "2018-09-30T03:47:35+00:00"
}, },
{ {
"name": "symfony/http-kernel", "name": "symfony/http-kernel",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/http-kernel.git", "url": "https://github.com/symfony/http-kernel.git",
"reference": "33de0a1ff2e1720096189e3ced682d7a4e8f5e35" "reference": "74b1d37bf9a1cddc38093530c0a931a310994ea5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/http-kernel/zipball/33de0a1ff2e1720096189e3ced682d7a4e8f5e35", "url": "https://api.github.com/repos/symfony/http-kernel/zipball/74b1d37bf9a1cddc38093530c0a931a310994ea5",
"reference": "33de0a1ff2e1720096189e3ced682d7a4e8f5e35", "reference": "74b1d37bf9a1cddc38093530c0a931a310994ea5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -586,7 +586,7 @@
], ],
"description": "Symfony HttpKernel Component", "description": "Symfony HttpKernel Component",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-08-28T06:17:42+00:00" "time": "2018-09-30T05:05:39+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
@@ -707,16 +707,16 @@
}, },
{ {
"name": "symfony/routing", "name": "symfony/routing",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/routing.git", "url": "https://github.com/symfony/routing.git",
"reference": "a5784c2ec4168018c87b38f0e4f39d2278499f51" "reference": "d998113cf6db1e8262fdd8d5db9774c9a7be33b0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/routing/zipball/a5784c2ec4168018c87b38f0e4f39d2278499f51", "url": "https://api.github.com/repos/symfony/routing/zipball/d998113cf6db1e8262fdd8d5db9774c9a7be33b0",
"reference": "a5784c2ec4168018c87b38f0e4f39d2278499f51", "reference": "d998113cf6db1e8262fdd8d5db9774c9a7be33b0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -780,20 +780,20 @@
"uri", "uri",
"url" "url"
], ],
"time": "2018-08-03T07:58:40+00:00" "time": "2018-09-08T13:24:10+00:00"
}, },
{ {
"name": "symfony/twig-bridge", "name": "symfony/twig-bridge",
"version": "v4.1.4", "version": "v4.1.5",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/twig-bridge.git", "url": "https://github.com/symfony/twig-bridge.git",
"reference": "550cd9cd3a106a3426bdb2bd9d2914a4937656d1" "reference": "4a8426ab5e00c34ac8a7bf1a2bfd5a75165edadb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/twig-bridge/zipball/550cd9cd3a106a3426bdb2bd9d2914a4937656d1", "url": "https://api.github.com/repos/symfony/twig-bridge/zipball/4a8426ab5e00c34ac8a7bf1a2bfd5a75165edadb",
"reference": "550cd9cd3a106a3426bdb2bd9d2914a4937656d1", "reference": "4a8426ab5e00c34ac8a7bf1a2bfd5a75165edadb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -810,7 +810,7 @@
"symfony/dependency-injection": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0",
"symfony/expression-language": "~3.4|~4.0", "symfony/expression-language": "~3.4|~4.0",
"symfony/finder": "~3.4|~4.0", "symfony/finder": "~3.4|~4.0",
"symfony/form": "^4.1.2", "symfony/form": "^4.1.5",
"symfony/http-foundation": "~3.4|~4.0", "symfony/http-foundation": "~3.4|~4.0",
"symfony/http-kernel": "~3.4|~4.0", "symfony/http-kernel": "~3.4|~4.0",
"symfony/polyfill-intl-icu": "~1.0", "symfony/polyfill-intl-icu": "~1.0",
@@ -870,7 +870,7 @@
], ],
"description": "Symfony Twig Bridge", "description": "Symfony Twig Bridge",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"time": "2018-08-14T15:48:59+00:00" "time": "2018-09-18T16:38:01+00:00"
}, },
{ {
"name": "twig/twig", "name": "twig/twig",

View File

@@ -173,9 +173,9 @@ class DB
* *
* @return int the last code identifier * @return int the last code identifier
*/ */
public function getLastIDC() public function getLastIDC($name)
{ {
$query = "SELECT MAX(IDC) FROM Codes"; $query = "SELECT MAX(IDC) FROM Codes WHERE name='$name'";
return $this->getQuery($query)[0]; return $this->getQuery($query)[0];
} }
@@ -308,7 +308,7 @@ class DB
* @param $IDU user identifier * @param $IDU user identifier
* @param null $extlib external library * @param null $extlib external library
* @param null $extlibver external library version * @param null $extlibver external library version
* @return int the snippet's version * @return int the snippet's version or IDC
*/ */
public function addOrModifyCodes($IDC, $name, $description, $input, $output, $lang, $code, $IDU, $extlib = null, $extlibver = null) public function addOrModifyCodes($IDC, $name, $description, $input, $output, $lang, $code, $IDU, $extlib = null, $extlibver = null)
{ {
@@ -319,9 +319,10 @@ class DB
$query = "INSERT INTO Codes (`UserCreator`,`Name`,`Description`,`Input`,`Output`) VALUES ('$IDU','$name','$description','$in','$out') "; $query = "INSERT INTO Codes (`UserCreator`,`Name`,`Description`,`Input`,`Output`) VALUES ('$IDU','$name','$description','$in','$out') ";
//echo $query.';'; //echo $query.';';
//die(); //die();
dbw_query($this->conn, $query); dbw_query($this->conn, $query);
$this->addSource($this->getLastIDC(), $lang, $_code, $IDU, $extlib, $extlibver); $myID = $this->getLastIDC($name);
$this->addSource($myID, $lang, $_code, $IDU, $extlib, $extlibver);
return $myID;
} else { } else {
$arr = $this->loadAll($IDC, $lang, $this->getLastVersion($IDC, $lang)); $arr = $this->loadAll($IDC, $lang, $this->getLastVersion($IDC, $lang));
$codewrite = $arr["Code"]; $codewrite = $arr["Code"];

View File

@@ -94,61 +94,6 @@ $app->get('/about', function (Request $request) use($app){
return $app['twig']->render($app['fronthtml'].'/about.twig', array("page" => $page,'user'=>$user)); return $app['twig']->render($app['fronthtml'].'/about.twig', array("page" => $page,'user'=>$user));
})->bind('about'); })->bind('about');
/* Codes */
$app->get('/code/{lang}-{idc}-{version}', function (Request $request, $lang, $idc, $version) use($app){
connectDB();
$user = getUser($app);
$array = $app['db']->loadAll($idc,$lang,$version);
if(!$array){
$app->abort('404');
}
$page = array(
"page" => 'code',
"title" => "$array[Name] by $array[nick]",
"description" => "$array[Name] by $array[nick] in ".$app['supported'][$lang][0],
"otherV" => false,
"otherI" => false,
"existedLangs" => $app['db']->loadLangs($idc),
"original" => $app['db']->loadOriginalAuthor($idc),
);
$code = allCodeToArray($array,$app['supported']);
if($array['Version']!=1)
$page['otherV'] = true;
$diff = $app['db']->loadDiff($idc,$lang);
if(dbw_fetch_array($app['db']->conn,$diff)){
$page['otherI'] = true;
}
dbw_query_goto($app['db']->conn,$diff);
$otherImplementation = otherImplementationToArray($app['db'],$diff,$app['supported']);
return $app['twig']->render($app['fronthtml'].'/code.twig', array(
"page" => $page,
"code" => $code,
"otherImplementation" => $otherImplementation,
"supported" => $app['supported'],
"user" => $user
));
})->bind('code');
$app->get('/code/{lang}-{idc}', function(Request $request, $lang, $idc) use($app){
connectDB();
$user = getUser($app);
$array = $app['db']->loadOtherVersion($idc,$lang);
$other = otherVersionToArray($app['db'],$array,$app['supported']);
$name = $other[0]['name'];
$page = array(
"title" => "Other versions of $name",
"description" => "All differents version of $name uploaded in CodeShare",
"last" => $other,
"page" => ""
);
return $app['twig']->render($app['fronthtml'].'/otherVersion.twig', array(
"page" => $page, "user" => $user
));
})->bind('codeVer');
/* User */ /* User */
$app->get('/tos',function(Request $request) use($app){ $app->get('/tos',function(Request $request) use($app){
connectDB(); connectDB();
@@ -264,6 +209,9 @@ $app->get('/user', function(Request $request) use ($app){
/* Error Codes */ /* Error Codes */
function HTTPError($code){ function HTTPError($code){
switch($code){ switch($code){
case 400:
$text = "Bad Request";
break;
case 401: case 401:
$text = "Unauthorized user"; $text = "Unauthorized user";
break; break;
@@ -309,3 +257,141 @@ $app->error(function (\Exception $e,$request, $code) use ($app) {
}); });
/* Codes */
$app->get('/code/{lang}-{idc}-{version}', function (Request $request, $lang, $idc, $version) use($app){
connectDB();
$user = getUser($app);
$array = $app['db']->loadAll($idc,$lang,$version);
if(!$array){
$app->abort('404');
}
if($request->getMethod()=='POST'){
return updateCode($request,$idc,$lang,$version,$user);
}
$page = array(
"page" => 'code',
"title" => "$array[Name] by $array[nick]",
"description" => "$array[Name] by $array[nick] in ".$app['supported'][$lang][0],
"otherV" => false,
"otherI" => false,
"existedLangs" => $app['db']->loadLangs($idc),
"original" => $app['db']->loadOriginalAuthor($idc),
);
$code = allCodeToArray($array,$app['supported']);
if($array['Version']!=1)
$page['otherV'] = true;
$diff = $app['db']->loadDiff($idc,$lang);
if(dbw_fetch_array($app['db']->conn,$diff)){
$page['otherI'] = true;
}
dbw_query_goto($app['db']->conn,$diff);
$otherImplementation = otherImplementationToArray($app['db'],$diff,$app['supported']);
return $app['twig']->render($app['fronthtml'].'/code.twig', array(
"page" => $page,
"code" => $code,
"otherImplementation" => $otherImplementation,
"supported" => $app['supported'],
"user" => $user
));
})->bind('code')->method('GET|POST');
function updateCode($request,$idc,$lang,$version,$user){
global $app;
$lang2 = $request->request->all()['lang'];
$extlib = $request->get('extlib');
$extlibver = $request->get('extlibver');
if($extlibver == null and $extlib != null)
$app->abort(400);
$code = htmlentities($request->get('code'));
if ($code == null or $lang == null)
$app->abort(400);
if($lang2 != null){
$app['db']->addSource($idc,$lang2,$code,$user['IDU'],$extlib,$extlibver);
$app['db']->close();
return $app->redirect($app['url_generator']->generate('code',array("idc"=>$idc,"version"=>1,"lang"=>$lang2)));
}else{
$name = $request->get("name");
$description = $request->get("description");
$input = htmlentities($request->get("input"));
$output = htmlentities($request->get("output"));
if($name == null || $description == null || $input == null ||$output == null)
$app->abort(400);
$version2 = $app['db']->addOrModifyCodes($idc,$name,$description,$input,$output,$lang,$code,$user['IDU'],$extlibver,$extlibver);
$app['db']->close();
if($version2!=0)
return $app->redirect($app['url_generator']->generate('code',array("idc"=>$idc,"version"=>$version2,"lang"=>$lang)));
else
return $app->redirect($app['url_generator']->generate('code',array("idc"=>$idc,"version"=>$version,"lang"=>$lang)));
}
}
$app->get('/code/{lang}-{idc}', function(Request $request, $lang, $idc) use($app){
connectDB();
$user = getUser($app);
$array = $app['db']->loadOtherVersion($idc,$lang);
$other = otherVersionToArray($app['db'],$array,$app['supported']);
$name = $other[0]['name'];
$page = array(
"title" => "Other versions of $name",
"description" => "All differents version of $name uploaded in CodeShare",
"last" => $other,
"page" => ""
);
return $app['twig']->render($app['fronthtml'].'/otherVersion.twig', array(
"page" => $page, "user" => $user
));
})->bind('codeVer');
$app->get('/add', function(Request $request) use($app){
connectDB();
$user = getUser($app);
if ($user == null)
return $app->redirect($app['url_generator']->generate('login'));
if($request->getMethod()=="POST"){
$extlib = $request->get('extlib');
$extlibver = $request->get('extlibver');
if($extlib == null or $extlibver != null){
$name = $request->get('name');
$description = $request->get('description');
$input = htmlentities($request->get('input'));
$output = htmlentities($request->get('output'));
$lang = $request->get('lang');
$code = htmlentities($request->get('code'));
if($name == null || $description == null || $input == null ||
$output == null || $lang == null || $code == null){
$app->abort(400);
}
else{
$idc = $app['db']->addOrModifyCodes(
0,
$name,
$description,
$input,
$output,
$lang,
$code,
$user['IDU'],
$extlib,
$extlibver
);
return $app->redirect($app['url_generator']->generate('code',array(
"lang"=>$lang,"idc"=>$idc, "version"=>1
)));
}
}else{
$app->abort(400);
}
}else{
$page=array(
"title" => "Add your own solution",
"description" => "Share now your snippet",
"page" => "add",
);
return $app['twig']->render($app['fronthtml']."/add.twig", array("page" => $page, "user"=>$user, "supported" => $app["supported"]));
}
})->bind('add')->method('GET|POST');

47
Source/symfony.lock Normal file
View File

@@ -0,0 +1,47 @@
{
"pimple/pimple": {
"version": "v3.2.3"
},
"psr/container": {
"version": "1.0.0"
},
"psr/log": {
"version": "1.0.2"
},
"silex/silex": {
"version": "v2.3.0"
},
"symfony/debug": {
"version": "v4.1.5"
},
"symfony/event-dispatcher": {
"version": "v4.1.5"
},
"symfony/flex": {
"version": "1.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "1.0",
"ref": "e921bdbfe20cdefa3b82f379d1cd36df1bc8d115"
}
},
"symfony/http-foundation": {
"version": "v4.1.5"
},
"symfony/http-kernel": {
"version": "v4.1.5"
},
"symfony/routing": {
"version": "4.0",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "master",
"version": "4.0",
"ref": "5f514d9d3b8a8aac3d62ae6a86b18b90ed0c7826"
}
},
"symfony/twig-bridge": {
"version": "v4.1.5"
}
}