From d71a111fe961c9f15f6122325091bfd7667e75bc Mon Sep 17 00:00:00 2001 From: JoseluCross Date: Sun, 16 Sep 2018 13:04:58 +0200 Subject: [PATCH] Add languages, categorized them, add rechaptcha --- Source/assets/css/main.css | 27 ++++++- Source/assets/html/add.twig | 6 +- Source/assets/html/base.twig | 2 +- Source/assets/html/code.twig | 2 +- Source/assets/html/filter.twig | 28 +++++-- Source/assets/html/loginregister.twig | 4 +- Source/assets/js/functions.js | 3 +- Source/composer.lock | 103 ++++++++++++++++++++------ Source/data/supported.json | 1 + Source/data/supported.kson | 91 +++++++++++++---------- Source/src/DB.php | 4 +- Source/src/app.php | 8 +- Source/src/dbToTable.php | 6 +- Source/src/functions.php | 28 +++++++ 14 files changed, 225 insertions(+), 88 deletions(-) create mode 100644 Source/data/supported.json diff --git a/Source/assets/css/main.css b/Source/assets/css/main.css index cf87cf9..5961fdc 100644 --- a/Source/assets/css/main.css +++ b/Source/assets/css/main.css @@ -76,13 +76,17 @@ p{ margin-bottom: 30px; } -.codeFilterCheckBox, .codeFilterButton{ +.codeFilterCheckBox, .codeFilterButton, .codeFilterTitle{ margin: 0.2em 0; padding: 0; width: 100px; float: left; } +.codeFilterTitle { + font-weight: bold; +} + .codeFilterSearch { margin-top: 1em; } @@ -136,11 +140,16 @@ p{ transform: rotate(180deg); } -#filterBlock{ +.sub-depth{ + border-radius: 5px; + box-shadow: inset 0px 0px 5px rgba(119, 119, 119, 0.205); +} + +#filterBlock, .filterBlock{ align-content: center; width: 90%; - margin-left: 7%; - margin-right: 3%; + margin-left: 5%; + margin-right: 5%; } #user{ @@ -164,6 +173,16 @@ p{ animation: spin 2s linear infinite; } +@media (min-width: 992px) { + .nopadding { + padding: 0%; + } +} + +.nomargin { + margin: 0%; +} + @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } diff --git a/Source/assets/html/add.twig b/Source/assets/html/add.twig index 776d7cd..072d911 100644 --- a/Source/assets/html/add.twig +++ b/Source/assets/html/add.twig @@ -19,7 +19,7 @@ @@ -52,7 +52,9 @@
- +
diff --git a/Source/assets/html/base.twig b/Source/assets/html/base.twig index 9a26c9e..4b9da97 100644 --- a/Source/assets/html/base.twig +++ b/Source/assets/html/base.twig @@ -2,7 +2,6 @@ {{ page.title }} - @@ -16,6 +15,7 @@ + diff --git a/Source/assets/html/code.twig b/Source/assets/html/code.twig index 88a76f5..0b3a49f 100644 --- a/Source/assets/html/code.twig +++ b/Source/assets/html/code.twig @@ -76,7 +76,7 @@ {% for key,value in supported %} {% if key not in page.existedLangs %} - + {% endif %} {% endfor %} diff --git a/Source/assets/html/filter.twig b/Source/assets/html/filter.twig index 98599e0..2196eaf 100644 --- a/Source/assets/html/filter.twig +++ b/Source/assets/html/filter.twig @@ -1,16 +1,28 @@
- +
diff --git a/Source/assets/js/functions.js b/Source/assets/js/functions.js index 0af1baa..7f00889 100644 --- a/Source/assets/js/functions.js +++ b/Source/assets/js/functions.js @@ -26,7 +26,8 @@ function reHightlight(){ function mostrar(div) { obj = document.getElementById(div); - obj.style.display = (obj.style.display == 'none') ? 'block' : 'none'; + $(obj).slideToggle(); + //obj.style.display = (obj.style.display == 'none') ? 'block' : 'none'; } function getAjax() { diff --git a/Source/composer.lock b/Source/composer.lock index e873566..2ca7c56 100644 --- a/Source/composer.lock +++ b/Source/composer.lock @@ -1,23 +1,23 @@ { "_readme": [ "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" ], "content-hash": "c34d26c2711c26f871ff9ca8a4401104", "packages": [ { "name": "jkanetwork/dbwrapper", - "version": "1.5.0", + "version": "1.5.1", "source": { "type": "git", "url": "https://gitlab.com/CodeSolutionsProject/DBWrapper.git", - "reference": "d366ae0f1f25d6a89c8c5a379118bf92aca45bdd" + "reference": "1bc58622f2f520286f5de7058fc5b9a97921003b" }, "dist": { "type": "zip", - "url": "https://gitlab.com/api/v4/projects/CodeSolutionsProject%2FDBWrapper/repository/archive.zip?sha=d366ae0f1f25d6a89c8c5a379118bf92aca45bdd", - "reference": "d366ae0f1f25d6a89c8c5a379118bf92aca45bdd", + "url": "https://gitlab.com/api/v4/projects/CodeSolutionsProject%2FDBWrapper/repository/archive.zip?sha=1bc58622f2f520286f5de7058fc5b9a97921003b", + "reference": "1bc58622f2f520286f5de7058fc5b9a97921003b", "shasum": "" }, "require": { @@ -46,20 +46,78 @@ "sqlite", "wrapper" ], - "time": "2018-05-16T13:37:18+00:00" + "time": "2018-05-16T15:47:31+00:00" }, { - "name": "symfony/polyfill-mbstring", - "version": "v1.8.0", + "name": "symfony/polyfill-ctype", + "version": "v1.9.0", "source": { "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "3296adf6a6454a050679cde90f95350ad604b171" + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/3296adf6a6454a050679cde90f95350ad604b171", - "reference": "3296adf6a6454a050679cde90f95350ad604b171", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/e3d826245268269cd66f8326bd8bc066687b4a19", + "reference": "e3d826245268269cd66f8326bd8bc066687b4a19", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + }, + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "time": "2018-08-06T14:22:27+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.9.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d0cd638f4634c16d8df4508e847f14e9e43168b8", + "reference": "d0cd638f4634c16d8df4508e847f14e9e43168b8", "shasum": "" }, "require": { @@ -71,7 +129,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.8-dev" + "dev-master": "1.9-dev" } }, "autoload": { @@ -105,24 +163,25 @@ "portable", "shim" ], - "time": "2018-04-26T10:06:28+00:00" + "time": "2018-08-06T14:22:27+00:00" }, { "name": "twig/twig", - "version": "v2.4.8", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "7b604c89da162034bdf4bb66310f358d313dd16d" + "reference": "6a5f676b77a90823c2d4eaf76137b771adf31323" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/7b604c89da162034bdf4bb66310f358d313dd16d", - "reference": "7b604c89da162034bdf4bb66310f358d313dd16d", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/6a5f676b77a90823c2d4eaf76137b771adf31323", + "reference": "6a5f676b77a90823c2d4eaf76137b771adf31323", "shasum": "" }, "require": { "php": "^7.0", + "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-mbstring": "~1.0" }, "require-dev": { @@ -133,7 +192,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } }, "autoload": { @@ -162,16 +221,16 @@ }, { "name": "Twig Team", - "homepage": "http://twig.sensiolabs.org/contributors", + "homepage": "https://twig.symfony.com/contributors", "role": "Contributors" } ], "description": "Twig, the flexible, fast, and secure template language for PHP", - "homepage": "http://twig.sensiolabs.org", + "homepage": "https://twig.symfony.com", "keywords": [ "templating" ], - "time": "2018-04-02T09:24:19+00:00" + "time": "2018-07-13T07:18:09+00:00" } ], "packages-dev": [], diff --git a/Source/data/supported.json b/Source/data/supported.json new file mode 100644 index 0000000..d9b061f --- /dev/null +++ b/Source/data/supported.json @@ -0,0 +1 @@ +{"ada": ["Ada", "Programming"], "apache": ["Apache", "Config"], "arduino": ["Arduino", "Programming"], "bash": ["Bash", "Script"], "basic": ["Basic", "Programming"], "bat": ["Batch", "Script"], "clojure": ["Clojure", "Programming"], "cmake": ["CMake", "Config"], "cs": ["C#", "Programming"], "cpp": ["C/C++", "Programming"], "css": ["CSS", "Markup"], "coffescript": ["CoffeScript", "Programming"], "dart": ["Dart", "Programming"], "delphi": ["Delphi", "Programming"], "dockerfile": ["Docker", "Config"], "fortran": ["Fortran", "Programming"], "fsharp": ["F#", "Programming"], "go": ["Go", "Programming"], "groovy": ["Groovy", "Programming"], "haskell": ["Haskell", "Programming"], "xml": ["HTML/XML", "Markup"], "ini": ["Ini", "Config"], "json": ["JSON", "Data"], "java": ["Java", "Programming"], "javascript": ["JavaScript", "Programming"], "kotlin": ["Kotlin", "Programming"], "less": ["Less", "Markup"], "lua": ["Lua", "Programming"], "lisp": ["Lisp", "Programming"], "makefile": ["Makefile", "Config"], "markdown": ["Markdown", "Markup"], "matlab": ["Matlab", "Mathematics"], "maxima": ["Maxima", "Mathematics"], "nginx": ["Nginx", "Config"], "objectivec": ["Objective-C", "Programming"], "php": ["PHP", "Programming"], "perl": ["Perl", "Programming"], "powershell": ["PowerShell", "Script"], "prolog": ["Prolog", "Programming"], "python": ["Python", "Programming"], "r": ["R", "Mathematics"], "ruby": ["Ruby", "Programming"], "rust": ["Rust", "Programming"], "scss": ["Sass", "Markup"], "scala": ["Scala", "Programming"], "smalltalk": ["Samlltalk", "Programming"], "sql": ["SQL", "Data"], "swift": ["Swift", "Programming"], "twig": ["Twig", "Markup"], "typescript": ["TypeScript", "Programming"], "vbnet": ["VB.Net", "Programming"], "yaml": ["YAML", "Data"]} \ No newline at end of file diff --git a/Source/data/supported.kson b/Source/data/supported.kson index 3ec639c..85ba11e 100644 --- a/Source/data/supported.kson +++ b/Source/data/supported.kson @@ -1,39 +1,52 @@ -ada:Ada -arduino:Arduino -bash:Bash -basic:Basic -cs:C# -cpp:C/C++ -css:CSS -coffescript:CoffeScript -dart:Dart -delphi:Delphi -fortran:Fortran -go:Go -groovy:Groovy -haskell:Haskell -xml:HTML/XML -json:JSON -java:Java -javascript:JavaScript -kotlin:Kotlin -less:Less -lua:Lua -markdown:Markdown -objectivec:Objective-C -php:PHP -perl:Perl -powershell:PowerShell -python:Python -r:R -ruby:Ruby -rust:Rust -scss:Sass -scala:Scala -smalltalk:Samlltalk -sql:SQL -swift:Swift -twig:Twig -typescript:TypeScript -vbnet:VB.Net -yaml:YAML \ No newline at end of file +ada:Ada:Programming +apache:Apache:Config +arduino:Arduino:Programming +bash:Bash:Script +basic:Basic:Programming +bat:Batch:Script +clojure:Clojure:Programming +cmake:CMake:Config +cs:C#:Programming +cpp:C/C++:Programming +css:CSS:Markup +coffescript:CoffeScript:Programming +dart:Dart:Programming +delphi:Delphi:Programming +dockerfile:Docker:Config +fortran:Fortran:Programming +fsharp:F#:Programming +go:Go:Programming +groovy:Groovy:Programming +haskell:Haskell:Programming +xml:HTML/XML:Markup +Ini:ini:Config +json:JSON:Data interchange +java:Java:Programming +javascript:JavaScript:Programming +kotlin:Kotlin:Programming +less:Less:Markup +lua:Lua:Programming +lisp:Lisp:Programming +makefile:Makefile:Config +markdown:Markdown:Markup +matlab:Matlab:Mathematics +maxima:Maxima:Mathematics +nginx:Nginx:Config +objectivec:Objective-C:Programming +php:PHP:Programming +perl:Perl:Programming +powershell:PowerShell:Script +prolog:Prolog:Programming +python:Python:Programming +r:R:Mathematics +ruby:Ruby:Programming +rust:Rust:Programming +scss:Sass:Markup +scala:Scala:Programming +smalltalk:Samlltalk:Programming +sql:SQL:Data +swift:Swift:Programming +twig:Twig:Markup +typescript:TypeScript:Programming +vbnet:VB.Net:Programming +yaml:YAML:Data \ No newline at end of file diff --git a/Source/src/DB.php b/Source/src/DB.php index d8d791a..94db56b 100644 --- a/Source/src/DB.php +++ b/Source/src/DB.php @@ -211,15 +211,13 @@ class DB } } } - if(count($array)==1) - $where = $where . "S.Lang<>''"; if (isset($array["o"])) $first = $array["o"] * 10; else $first = 0; if(array_key_exists("search",$array)) - $search = $array("search"); + $search = $this->search($array["search"]); else $search = ""; $queryLast = ") AND Version = (SELECT MAX(Version) FROM Sources WHERE S.Lang = Lang AND S.IDC = IDC)" . $search . " ORDER BY Modification DESC LIMIT $first, 10"; diff --git a/Source/src/app.php b/Source/src/app.php index e9dbc41..1cc4dfa 100644 --- a/Source/src/app.php +++ b/Source/src/app.php @@ -18,7 +18,8 @@ $path = array( "js" => "assets/js/", "img" => "assets/img/", ); -$supported = ksonParse('data/supported.kson'); +$string = file_get_contents(__DIR__."/../data/supported.json"); +$supported = json_decode($string, true); $loader = new Twig_Loader_Filesystem($path['html']); $twig = new Twig_Environment($loader); $user = array(); @@ -143,7 +144,8 @@ function firstPage($filter=false,$globalSearch=false){ "description" => "Sharing your solution with all", "last" => $last, "supported" => $supported, - "page" => "home" + "page" => "home", + "grouped" => groupByCategory($supported) ); if(!$filter) echo $twig->render("firstpage.twig",array("page" => $page, "path" => $path, "user" => $user)); @@ -237,7 +239,7 @@ function codeViewer(){ if($array){ $page = array( "title" => "$array[Name] by $array[nick]", - "description" => "$array[Name] by $array[nick] in ".$supported[$_GET['lang']], + "description" => "$array[Name] by $array[nick] in ".$supported[$_GET['lang']][0], "otherV" => false, "otherI" => false, "existedLangs" => $db->loadLangs($_GET['id']), diff --git a/Source/src/dbToTable.php b/Source/src/dbToTable.php index d8a364a..9f8bf51 100644 --- a/Source/src/dbToTable.php +++ b/Source/src/dbToTable.php @@ -20,7 +20,7 @@ function lastToArray($db,&$query,&$supported){ "version" => $var["Version"], "name" => $var["Name"], "nick" => $var["nick"], - "lLang" => $supported[$var["Lang"]], + "lLang" => $supported[$var["Lang"]][0], "description" => $var["Description"], "code" => html_entity_decode($var["Code"]), ); @@ -37,7 +37,7 @@ function allCodeToArray(&$query,&$supported){ "name" => $query['Name'], "nick" => $query['nick'], "idu" => $query['IDU'], - "lLang" => $supported[$query['Lang']], + "lLang" => $supported[$query['Lang']][0], "description" => $query['Description'], "code" => html_entity_decode($query['Code']), "input" => html_entity_decode($query['Input']), @@ -56,7 +56,7 @@ function otherImplementationToArray($db,&$query,&$supported){ $array = array ( "lang" => $var["Lang"], "version" => $var["Version"], - "lLang" => $supported[$var["Lang"]], + "lLang" => $supported[$var["Lang"]][0], "code" => html_entity_decode($var["Code"]), ); array_push($other,$array); diff --git a/Source/src/functions.php b/Source/src/functions.php index d8310f7..4a6d4cb 100644 --- a/Source/src/functions.php +++ b/Source/src/functions.php @@ -49,4 +49,32 @@ function ksonParse($path){ }else{ die('

Error, kson file not exist

'); } +} + +/** + * Group by $supported + */ +function groupByCategory(&$supported){ + $grouped = Array(); + foreach($supported as $key => $val){ + if(!array_key_exists($val[1],$grouped)){ + switch($val[1]){ + case "Programming": + $num=5; + break; + case "Config": + case "Markup": + $num=2; + break; + case "Script": + case "Data": + case "Mathematics": + $num=1; + break; + } + $grouped[$val[1]] = Array(Array(),$num); + } + array_push($grouped[$val[1]][0],[$key,$val[0]]); + } + return $grouped; } \ No newline at end of file