From bc90d9765f01cbe514dc54d6eb8d6d43cf3df175 Mon Sep 17 00:00:00 2001 From: J-P Stacey Date: Sat, 6 Feb 2016 15:56:45 +0000 Subject: [PATCH 1/5] Some templating done --- src/ConfiguredSilex.php | 70 ++++++++-------- src/Controllers/All.php | 110 ++++++++++++++++++++------ views/base.twig | 28 +++++++ views/choose-ar.twig | 58 ++++++++++++++ views/choose-en.twig | 58 ++++++++++++++ views/index.twig | 1 - views/location-ar.twig | 19 +++++ views/location-en.twig | 19 +++++ views/result-ar-postoffice.twig | 6 ++ views/result-en-postoffice.twig | 6 ++ views/start.twig | 16 ++++ web/{microframework.php => index.php} | 0 web/{index.html => old-index.html} | 0 13 files changed, 331 insertions(+), 60 deletions(-) create mode 100644 views/base.twig create mode 100644 views/choose-ar.twig create mode 100644 views/choose-en.twig delete mode 100644 views/index.twig create mode 100644 views/location-ar.twig create mode 100644 views/location-en.twig create mode 100644 views/result-ar-postoffice.twig create mode 100644 views/result-en-postoffice.twig create mode 100644 views/start.twig rename web/{microframework.php => index.php} (100%) rename web/{index.html => old-index.html} (100%) diff --git a/src/ConfiguredSilex.php b/src/ConfiguredSilex.php index debef68..80aaea1 100644 --- a/src/ConfiguredSilex.php +++ b/src/ConfiguredSilex.php @@ -1,33 +1,37 @@ -get('/', 'Sheffugees\\Controllers\\All::index'); - - $this->register(new \Silex\Provider\TwigServiceProvider(), [ - 'twig.path' => __DIR__ . '/../views', - ]); - } -} +get('/', 'Sheffugees\\Controllers\\All::index'); + $this->get('/{lang}', 'Sheffugees\\Controllers\\All::location'); + $this->get('/{lang}/choose', 'Sheffugees\\Controllers\\All::choose'); + $this->get('/{lang}/need/{need}', 'Sheffugees\\Controllers\\All::need'); + $this->get('/{lang}/results/{find}', 'Sheffugees\\Controllers\\All::results'); + + $this->register(new \Silex\Provider\TwigServiceProvider(), [ + 'twig.path' => __DIR__ . '/../views', + ]); + } +} diff --git a/src/Controllers/All.php b/src/Controllers/All.php index f156874..558f535 100644 --- a/src/Controllers/All.php +++ b/src/Controllers/All.php @@ -1,26 +1,84 @@ -render('index.twig'); - } -} +render('start.twig'); + } + + /** + * Page callback: set location. + */ + public function location(Request $request, Application $app, $lang) + { + if (!preg_match("/^[a-z]{2}\$/", $lang)) { + return $app->redirect('/'); + } + + return $app['twig']->render("location-$lang.twig"); + } + + /** + * Page callback: choose a need. + */ + public function choose(Request $request, Application $app, $lang) + { + if (!preg_match("/^[a-z]{2}\$/", $lang)) { + return $app->redirect('/'); + } + + return $app['twig']->render("choose-$lang.twig"); + } + + /** + * Page callback: define a need. + */ + public function need(Request $request, Application $app, $lang, $need) + { + if (!preg_match("/^[a-z]{2}\$/", $lang)) { + return $app->redirect('/'); + } + + if (!preg_match("/^[a-z]+\$/", $need)) { + return $app->redirect('/'); + } + + + return $app['twig']->render("need-$lang-$need.twig"); + } + + /** + * Page callback: return some results. + */ + public function results(Request $request, Application $app, $lang, $find) + { + if (!preg_match("/^[a-z]{2}\$/", $lang)) { + return $app->redirect('/'); + } + + if (!preg_match("/^[a-z]+\$/", $need)) { + return $app->redirect('/'); + } + + return $app['twig']->render("results-$lang-$find.twig"); + } + +} diff --git a/views/base.twig b/views/base.twig new file mode 100644 index 0000000..90aaaa7 --- /dev/null +++ b/views/base.twig @@ -0,0 +1,28 @@ + + + + + + + Foundation for Sites + + + +
+
+

{% block title %}{% endblock %}

+ + {% block standfirst %}{% endblock %} +
+
+ +
+ {% block content %}{% endblock %} +
+ + + + + + + diff --git a/views/choose-ar.twig b/views/choose-ar.twig new file mode 100644 index 0000000..b9345af --- /dev/null +++ b/views/choose-ar.twig @@ -0,0 +1,58 @@ +{% extends "base.twig" %} + +{% block title %}What do you need? (Arabic){% endblock %} + +{% block content %} +
+ +
+{% endblock %} diff --git a/views/choose-en.twig b/views/choose-en.twig new file mode 100644 index 0000000..f25379f --- /dev/null +++ b/views/choose-en.twig @@ -0,0 +1,58 @@ +{% extends "base.twig" %} + +{% block title %}What do you need?{% endblock %} + +{% block content %} +
+ +
+{% endblock %} diff --git a/views/index.twig b/views/index.twig deleted file mode 100644 index 3a36e53..0000000 --- a/views/index.twig +++ /dev/null @@ -1 +0,0 @@ -

Test

diff --git a/views/location-ar.twig b/views/location-ar.twig new file mode 100644 index 0000000..4727350 --- /dev/null +++ b/views/location-ar.twig @@ -0,0 +1,19 @@ +{% extends "base.twig" %} + +{% block title %}Set your location (in Arabic){% endblock %} + +{% block content %} +
+ + +

I'm at home now: set my location.

+
+
+ +
+ + +

I'm not at home: add my address.

+
+
+{% endblock %} diff --git a/views/location-en.twig b/views/location-en.twig new file mode 100644 index 0000000..00b709c --- /dev/null +++ b/views/location-en.twig @@ -0,0 +1,19 @@ +{% extends "base.twig" %} + +{% block title %}Set your location{% endblock %} + +{% block content %} +
+ + +

I'm at home now: set my location.

+
+
+ +
+ + +

I'm not at home: add my address.

+
+
+{% endblock %} diff --git a/views/result-ar-postoffice.twig b/views/result-ar-postoffice.twig new file mode 100644 index 0000000..9614022 --- /dev/null +++ b/views/result-ar-postoffice.twig @@ -0,0 +1,6 @@ +{% extends "base.twig" %} + +{% block title %}{% endblock %} + +{% block content %} +{% endblock %} diff --git a/views/result-en-postoffice.twig b/views/result-en-postoffice.twig new file mode 100644 index 0000000..9614022 --- /dev/null +++ b/views/result-en-postoffice.twig @@ -0,0 +1,6 @@ +{% extends "base.twig" %} + +{% block title %}{% endblock %} + +{% block content %} +{% endblock %} diff --git a/views/start.twig b/views/start.twig new file mode 100644 index 0000000..539ced8 --- /dev/null +++ b/views/start.twig @@ -0,0 +1,16 @@ +{% extends "base.twig" %} + +{% block title %}Welcome to Sheffield!{% endblock %} + +{% block content %} +
+
+
+ English +
+ +
+
+{% endblock %} diff --git a/web/microframework.php b/web/index.php similarity index 100% rename from web/microframework.php rename to web/index.php diff --git a/web/index.html b/web/old-index.html similarity index 100% rename from web/index.html rename to web/old-index.html From bee2bed2edf7568c6f31b722f288a44c48f1078e Mon Sep 17 00:00:00 2001 From: J-P Stacey Date: Sat, 6 Feb 2016 16:07:16 +0000 Subject: [PATCH 2/5] Final templates --- src/Controllers/All.php | 2 +- views/base.twig | 8 ++++++ views/location-ar.twig | 4 +-- views/need-ar-money.twig | 33 ++++++++++++++++++++++ views/need-en-money.twig | 33 ++++++++++++++++++++++ views/result-ar-postoffice.twig | 6 ---- views/result-en-postoffice.twig | 6 ---- views/results-ar-postoffice.twig | 47 ++++++++++++++++++++++++++++++++ views/results-en-postoffice.twig | 47 ++++++++++++++++++++++++++++++++ views/start.twig | 34 ++++++++++++----------- 10 files changed, 189 insertions(+), 31 deletions(-) create mode 100644 views/need-ar-money.twig create mode 100644 views/need-en-money.twig delete mode 100644 views/result-ar-postoffice.twig delete mode 100644 views/result-en-postoffice.twig create mode 100644 views/results-ar-postoffice.twig create mode 100644 views/results-en-postoffice.twig diff --git a/src/Controllers/All.php b/src/Controllers/All.php index 558f535..cb74fe4 100644 --- a/src/Controllers/All.php +++ b/src/Controllers/All.php @@ -74,7 +74,7 @@ public function results(Request $request, Application $app, $lang, $find) return $app->redirect('/'); } - if (!preg_match("/^[a-z]+\$/", $need)) { + if (!preg_match("/^[a-z]+\$/", $find)) { return $app->redirect('/'); } diff --git a/views/base.twig b/views/base.twig index 90aaaa7..39bc727 100644 --- a/views/base.twig +++ b/views/base.twig @@ -8,6 +8,14 @@ +
+
+ {% block languages %} + English|العربية + {% endblock %} +
+
+

{% block title %}{% endblock %}

diff --git a/views/location-ar.twig b/views/location-ar.twig index 4727350..dafea13 100644 --- a/views/location-ar.twig +++ b/views/location-ar.twig @@ -4,14 +4,14 @@ {% block content %}
- +

I'm not at home: add my address.

diff --git a/views/need-ar-money.twig b/views/need-ar-money.twig new file mode 100644 index 0000000..81666e3 --- /dev/null +++ b/views/need-ar-money.twig @@ -0,0 +1,33 @@ +{% extends "base.twig" %} + +{% block title %}Money (in Arabic){% endblock %} + +{% block standfirst %} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum maximus tincidunt sagittis. Pellentesque justo neque, tincidunt non viverra nec, auctor eget nisl.

+{% endblock %} + +{% block content %} +
+
+ +

Post office

+

If you have your identification card you can get money form the Post Office.

+ + +

Find a Post Office

+
+
+
+ +
+
+ +

Western Union

+

You can receive money from your family using Western Union

+ + +

Find Western Union

+
+
+
+{% endblock %} diff --git a/views/need-en-money.twig b/views/need-en-money.twig new file mode 100644 index 0000000..299d073 --- /dev/null +++ b/views/need-en-money.twig @@ -0,0 +1,33 @@ +{% extends "base.twig" %} + +{% block title %}Money{% endblock %} + +{% block standfirst %} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum maximus tincidunt sagittis. Pellentesque justo neque, tincidunt non viverra nec, auctor eget nisl.

+{% endblock %} + +{% block content %} +
+
+ +

Post office

+

If you have your identification card you can get money form the Post Office.

+ + +

Find a Post Office

+
+
+
+ +
+
+ +

Western Union

+

You can receive money from your family using Western Union

+ + +

Find Western Union

+
+
+
+{% endblock %} diff --git a/views/result-ar-postoffice.twig b/views/result-ar-postoffice.twig deleted file mode 100644 index 9614022..0000000 --- a/views/result-ar-postoffice.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "base.twig" %} - -{% block title %}{% endblock %} - -{% block content %} -{% endblock %} diff --git a/views/result-en-postoffice.twig b/views/result-en-postoffice.twig deleted file mode 100644 index 9614022..0000000 --- a/views/result-en-postoffice.twig +++ /dev/null @@ -1,6 +0,0 @@ -{% extends "base.twig" %} - -{% block title %}{% endblock %} - -{% block content %} -{% endblock %} diff --git a/views/results-ar-postoffice.twig b/views/results-ar-postoffice.twig new file mode 100644 index 0000000..267e1ac --- /dev/null +++ b/views/results-ar-postoffice.twig @@ -0,0 +1,47 @@ +{% extends "base.twig" %} + +{% block title %}Post offices near you (in Arabic){% endblock %} + +{% block content %} +
+
+ +

228 Shoreham St, Sheffield, England

+ +
+
+ +
+
+ +

43 Charles St, Sheffield, England

+ +
+
+{% endblock %} diff --git a/views/results-en-postoffice.twig b/views/results-en-postoffice.twig new file mode 100644 index 0000000..8e39a92 --- /dev/null +++ b/views/results-en-postoffice.twig @@ -0,0 +1,47 @@ +{% extends "base.twig" %} + +{% block title %}Post offices near you{% endblock %} + +{% block content %} +
+
+ +

228 Shoreham St, Sheffield, England

+ +
+
+ +
+
+ +

43 Charles St, Sheffield, England

+ +
+
+{% endblock %} diff --git a/views/start.twig b/views/start.twig index 539ced8..b0a7031 100644 --- a/views/start.twig +++ b/views/start.twig @@ -1,16 +1,18 @@ -{% extends "base.twig" %} - -{% block title %}Welcome to Sheffield!{% endblock %} - -{% block content %} -
-
-
- English -
- -
-
-{% endblock %} +{% extends "base.twig" %} + +{% block languages %}{% endblock %} + +{% block title %}Welcome to Sheffield!{% endblock %} + +{% block content %} +
+
+
+ English +
+ +
+
+{% endblock %} From cdd6aca22359259d3da014574c0a08815b69f958 Mon Sep 17 00:00:00 2001 From: Ian Rufus Date: Sat, 6 Feb 2016 15:19:20 +0000 Subject: [PATCH 3/5] API Key Text file containing API key for Yandex Translate --- yandex-api-key | 1 + 1 file changed, 1 insertion(+) create mode 100644 yandex-api-key diff --git a/yandex-api-key b/yandex-api-key new file mode 100644 index 0000000..7d74803 --- /dev/null +++ b/yandex-api-key @@ -0,0 +1 @@ +trnsl.1.1.20160206T123230Z.37bca81167793559.4914b0cdb53f30907bf278a6726aee775e04cfb1 \ No newline at end of file From 82372bdaad8903f51a498953e86cedfa3cf99316 Mon Sep 17 00:00:00 2001 From: Ian Rufus Date: Sat, 6 Feb 2016 15:20:07 +0000 Subject: [PATCH 4/5] Translation Demo Demo of Yandex translate api. --- translation-demo | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 translation-demo diff --git a/translation-demo b/translation-demo new file mode 100644 index 0000000..5286921 --- /dev/null +++ b/translation-demo @@ -0,0 +1,64 @@ + + + + + + + + + + + + +
+
+
+ Hello! Welcome to our new website +
+ + + \ No newline at end of file From 6b9de2fb4e08aaeac8b14cb527422f693da3bd0d Mon Sep 17 00:00:00 2001 From: Ian Rufus Date: Sat, 6 Feb 2016 16:14:03 +0000 Subject: [PATCH 5/5] Moved to subfolder Moved translate demo to sub folder so it can be easily removed --- translation-demo => translate-demo/translation-demo | 0 yandex-api-key => translate-demo/yandex-api-key | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename translation-demo => translate-demo/translation-demo (100%) rename yandex-api-key => translate-demo/yandex-api-key (100%) diff --git a/translation-demo b/translate-demo/translation-demo similarity index 100% rename from translation-demo rename to translate-demo/translation-demo diff --git a/yandex-api-key b/translate-demo/yandex-api-key similarity index 100% rename from yandex-api-key rename to translate-demo/yandex-api-key