Skip to content

Commit

Permalink
Fix elementary#1282 & elementary#1433 - Organise folders and files an…
Browse files Browse the repository at this point in the history
…d document their usage. (elementary#1463)

* Migrate lang to _lang

* Migrate some data to _data

* Move l10n

* Move sitewide.php

* Move most of backend

* Update references

* Move payment to api endpoint

* Move payment pointers

* Finish moving backend

* Require the preload

* Fix template references

* Don't .json config

* Stop echoing errors

* Update contributing guide

* Update README.md

* Fix backend reference

* Fix elementary#1433

* Tidy translation sets

* Don't translate into english

* Fix sentry reference

* fix some store related paths

* fix legacy template regex

* fix a couple of paths
  • Loading branch information
lewisgoddard authored and btkostner committed Nov 3, 2016
1 parent c999432 commit 178b8d2
Show file tree
Hide file tree
Showing 2,088 changed files with 305 additions and 291 deletions.
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ Finally, navigate to [mvp.localtest.me](http://mvp.localtest.me)

```php
<?php
include '_templates/sitewide.php';
require_once __DIR__.'/_backend/preload.php';
$page['title'] = 'HTML Safe Title';
include '_templates/header.php';
include $template['header'];

$foo = bar($para, $param);
$second_foo = 42;
Expand Down
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
*~
*.log
/.vagrant/
/backend/libs/
/backend/chart.json
/backend/config.php
/data/_average_payments.db
/_backend/lib/
/_backend/config.php
/_data/
/data/average-payments.json
/data/chart.json
/lang/en/
/node_modules/
/scripts/
/styles/
88 changes: 44 additions & 44 deletions .tx/config
Original file line number Diff line number Diff line change
Expand Up @@ -3,133 +3,133 @@ host = https://www.transifex.com
lang_map = sr@Ijekavian:sr_JK

[elementary-mvp.404]
file_filter = lang/<lang>/404.json
source_file = lang/en/404.json
file_filter = _lang/<lang>/404.json
source_file = _lang/en/404.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.developer]
file_filter = lang/<lang>/developer.json
source_file = lang/en/developer.json
file_filter = _lang/<lang>/developer.json
source_file = _lang/en/developer.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.get-involved]
file_filter = lang/<lang>/get-involved.json
source_file = lang/en/get-involved.json
file_filter = _lang/<lang>/get-involved.json
source_file = _lang/en/get-involved.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.index]
file_filter = lang/<lang>/index.json
source_file = lang/en/index.json
file_filter = _lang/<lang>/index.json
source_file = _lang/en/index.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.layout]
file_filter = lang/<lang>/layout.json
source_file = lang/en/layout.json
file_filter = _lang/<lang>/layout.json
source_file = _lang/en/layout.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.privacy-policy]
file_filter = lang/<lang>/privacy-policy.json
source_file = lang/en/privacy-policy.json
file_filter = _lang/<lang>/privacy-policy.json
source_file = _lang/en/privacy-policy.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.support]
file_filter = lang/<lang>/support.json
source_file = lang/en/support.json
file_filter = _lang/<lang>/support.json
source_file = _lang/en/support.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_installation]
file_filter = lang/<lang>/docs/installation.json
source_file = lang/en/docs/installation.json
file_filter = _lang/<lang>/docs/installation.json
source_file = _lang/en/docs/installation.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_learning-the-basics]
file_filter = lang/<lang>/docs/learning-the-basics.json
source_file = lang/en/docs/learning-the-basics.json
file_filter = _lang/<lang>/docs/learning-the-basics.json
source_file = _lang/en/docs/learning-the-basics.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.code-of-conduct]
file_filter = lang/<lang>/code-of-conduct.json
source_file = lang/en/code-of-conduct.json
file_filter = _lang/<lang>/code-of-conduct.json
source_file = _lang/en/code-of-conduct.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_code_getting-started]
file_filter = lang/<lang>/docs/code/getting-started.json
source_file = lang/en/docs/code/getting-started.json
file_filter = _lang/<lang>/docs/code/getting-started.json
source_file = _lang/en/docs/code/getting-started.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_code_reference]
file_filter = lang/<lang>/docs/code/reference.json
source_file = lang/en/docs/code/reference.json
file_filter = _lang/<lang>/docs/code/reference.json
source_file = _lang/en/docs/code/reference.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_human-interface-guidelines]
file_filter = lang/<lang>/docs/human-interface-guidelines.json
source_file = lang/en/docs/human-interface-guidelines.json
file_filter = _lang/<lang>/docs/human-interface-guidelines.json
source_file = _lang/en/docs/human-interface-guidelines.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.docs_translation-guide]
file_filter = lang/<lang>/docs/translation-guide.json
source_file = lang/en/docs/translation-guide.json
file_filter = _lang/<lang>/docs/translation-guide.json
source_file = _lang/en/docs/translation-guide.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.403]
file_filter = lang/<lang>/403.json
source_file = lang/en/403.json
file_filter = _lang/<lang>/403.json
source_file = _lang/en/403.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.410]
file_filter = lang/<lang>/410.json
source_file = lang/en/410.json
file_filter = _lang/<lang>/410.json
source_file = _lang/en/410.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.brand]
file_filter = lang/<lang>/brand.json
source_file = lang/en/brand.json
file_filter = _lang/<lang>/brand.json
source_file = _lang/en/brand.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.capnet-assist]
file_filter = lang/<lang>/capnet-assist.json
source_file = lang/en/capnet-assist.json
file_filter = _lang/<lang>/capnet-assist.json
source_file = _lang/en/capnet-assist.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.team]
file_filter = lang/<lang>/team.json
source_file = lang/en/team.json
file_filter = _lang/<lang>/team.json
source_file = _lang/en/team.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.open-source]
file_filter = lang/<lang>/open-source.json
source_file = lang/en/open-source.json
file_filter = _lang/<lang>/open-source.json
source_file = _lang/en/open-source.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.store_index]
file_filter = lang/<lang>/store/index.json
source_file = lang/en/store/index.json
file_filter = _lang/<lang>/store/index.json
source_file = _lang/en/store/index.json
source_lang = en
type = KEYVALUEJSON

[elementary-mvp.store_cart]
file_filter = lang/<lang>/store/cart.json
source_file = lang/en/store/cart.json
file_filter = _lang/<lang>/store/cart.json
source_file = _lang/en/store/cart.json
source_lang = en
type = KEYVALUEJSON
6 changes: 3 additions & 3 deletions .tx/merge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
/**
* Merge translations files. Useful when merging docs pages for instance.
* Usage: php .tx/merge.php -o output_resource input_resources...
*
*
* Example: php .tx/merge.php -o docs/code/index docs/code/getting-started docs/code/reference
* This will create "lang/{lang}/docs/code/index.json", which contains translations from "getting-started" and "reference".
* This will create "_lang/{lang}/docs/code/index.json", which contains translations from "getting-started" and "reference".
*/

// Do not allow to run this script over HTTP
Expand Down Expand Up @@ -36,7 +36,7 @@ function log_info($msg) { // Basic logger

$input[] = $output;

$langRootDir = __DIR__.'/../lang';
$langRootDir = __DIR__.'/../_lang';

$source = array();
foreach ($input as $resource) {
Expand Down
10 changes: 5 additions & 5 deletions .tx/prepush.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
extract_translations () {
filename="$1"
pagename=$(echo "$filename" | sed 's/\.php$//' | sed 's/\.md$//')
output_file="lang/en/$pagename.json"
output_file="_lang/en/$pagename.json"
output_dirname=`dirname "$output_file"`

# Ignore some files
Expand All @@ -19,19 +19,19 @@ extract_translations () {
fi

# Run l10n-extract.php
php -f backend/extract-l10n.php "$pagename" 2>>/dev/null > "$output_file"
php -f _backend/extract-l10n.php "$pagename" 2>>/dev/null > "$output_file"

# Add file to .tx/config
escaped_pagename=$(echo "$pagename" | sed 's/\//_/g')
if ! grep -F -q "[elementary-mvp.$escaped_pagename]" .tx/config; then
echo "Adding $pagename to .tx/config"
tx set -t KEYVALUEJSON --auto-local -r "elementary-mvp.$escaped_pagename" "lang/<lang>/$pagename.json" --source-lang en --execute
tx set -t KEYVALUEJSON --auto-local -r "elementary-mvp.$escaped_pagename" "_lang/<lang>/$pagename.json" --source-lang en --execute
fi
}

# Cleanup
mkdir -p lang/en
rm -rf lang/en/*
mkdir -p _lang/en
rm -rf _lang/en/*

echo "Extracting translations..."

Expand Down
2 changes: 1 addition & 1 deletion 403.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include __DIR__.'/_templates/sitewide.php';
require_once __DIR__.'/_backend/preload.php';

$page['name'] = '403';
$page['title'] = 'Access Denied &sdot; elementary';
Expand Down
2 changes: 1 addition & 1 deletion 404.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include __DIR__.'/_templates/sitewide.php';
require_once __DIR__.'/_backend/preload.php';

$page['name'] = '404';
$page['title'] = 'Page Not Found &sdot; elementary';
Expand Down
2 changes: 1 addition & 1 deletion 410.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
include __DIR__.'/_templates/sitewide.php';
require_once __DIR__.'/_backend/preload.php';

$page['title'] = 'Download Link Expired &sdot; elementary';

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Templating System

* PHP-based
* Pages go in root as .php files
* Include `_templates/sitewide.php`, set any variables, then `include $template['header'];` (see [code-of-conduct](https://github.com/elementary/website/blob/master/code-of-conduct.php) for an example) at top of page.
* `require_once '_backend/preload.php';`, set any variables, then `include $template['header'];` (see [code-of-conduct](https://github.com/elementary/website/blob/master/code-of-conduct.php) for an example) at top of page.
* `include $template['footer'];` at bottom of page.
* Page variables:
* `$page['title']`
Expand Down
10 changes: 5 additions & 5 deletions TRANSLATE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Translators

You can translate the website online on Transifex: https://www.transifex.com/projects/p/elementary-mvp/. Please don't update directly files in `lang/` on Github as they'll be overriden when pulling new translations from Transifex.
You can translate the website online on Transifex: https://www.transifex.com/projects/p/elementary-mvp/. Please don't update directly files in `_lang/` on Github as they'll be overridden when pulling new translations from Transifex.

You can propose new languages if they're not listed. Make sure to avoid requesting languages that already exist, for instance adding _Russian (Russia)_ when _Russian_ is available.

Expand All @@ -26,7 +26,7 @@ git pull
.tx/prepush.sh
tx push -s
git checkout -b translations-update
rm lang/* -Rf
rm _lang/* -Rf
tx pull -a
php backend/translations-checker.php
git add -A
Expand All @@ -37,7 +37,7 @@ git checkout master

## Extracting translations from HTML files

Translations strings are extracted from HTML files. A little PHP script analyzes HTML files and exports strings to a JSON file: `/backend/extract-l10n.php?page=<page>`. You can change the `page` parameter to extract translations from another page (and set it to `layout` to translate the website layout). Translations are auto-updated on Transifex using this script.
Translations strings are extracted from HTML files. A little PHP script analyzes HTML files and exports strings to a JSON file: `/_backend/extract-l10n.php?page=<page>`. You can change the `page` parameter to extract translations from another page (and set it to `layout` to translate the website layout). Translations are auto-updated on Transifex using this script.

You can add the `include_disabled=1` parameter to print disabled strings too. This behaviour is disabled by default because Transifex doesn't accept `false` values. See _Disabling a translation_ for more information.

Expand All @@ -51,7 +51,7 @@ If you want to change a translation key for an element, just add a `data-l10n-id

## Disabling a translation

To ignore a translation string, set it to `false` in `/lang/en/<page>.json`:
To ignore a translation string, set it to `false` in `/_lang/en/<page>.json`:

```js
{
Expand Down Expand Up @@ -102,4 +102,4 @@ tx push -s -r <page-name>

## Adding a new language to the list on the website

The list of available languages is hard-coded in [`_templates/l10n.php`](https://github.com/elementary/website/blob/master/_templates/l10n.php#L2). If a new language is complete, you can add it by appending it to the list. Languages are sorted by index (see [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)) and are localized.
The list of available languages is hard-coded in [`_backend/l10n.php`](https://github.com/elementary/website/blob/master/_backend/l10n.php#L2). If a new language is complete, you can add it by appending it to the list. Languages are sorted by index (see [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)) and are localized.
File renamed without changes.
62 changes: 62 additions & 0 deletions _backend/average-payments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

//// Settings
$database = __DIR__.'/../_data/average_payments.db';
require_once __DIR__.'/log-echo.php';

if ( empty($amount) ) {
exit;
}

//// Error Handling
function LastError($db) {
global $sentry;
$Error = 'Error Code "'.$db->lastErrorCode().'" : '.$db->lastErrorCode();
if (getenv('PHPENV') !== 'production') {
echo $Error;
} else {
error_log($Error);
$sentry->captureMessage($msg);
}
exit;
}

//// Open database
if ( !is_writable(dirname($database)) ) {
log_echo('ERROR: database is not writable.');
exit(1);
}
try {
$db = new SQLite3($database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE);
} catch (Exception $e) {
log_echo('ERROR: unable to create database');
exit(2);
}

if ( $db->lastErrorCode() ) LastError($db);
$db->busyTimeout(300);
if ( $db->lastErrorCode() ) LastError($db);

//// Initialize database
$query = 'CREATE TABLE IF NOT EXISTS `AveragePayments` (`OS` TEXT PRIMARY KEY, `Total` INTEGER, `Count` INTEGER, `Average` INTEGER);';
$db->exec($query); // Result-less

if ( $db->lastErrorCode() ) LastError($db);

$Systems = array('total', 'android', 'ios', 'windows', 'macos', 'linux', 'other');
$query = 'DELETE FROM `AveragePayments` WHERE `OS` NOT IN (\''.implode('\', \'', $Systems).'\')';
$db->exec($query); // Result-less

foreach ( $Systems as $System ) {
$query = 'INSERT OR IGNORE INTO `AveragePayments` VALUES (\''.$System.'\', 0, 0, 0);';
$db->exec($query); // Result-less
}

//// Update
$amount = intval(htmlentities($amount, ENT_QUOTES));
$os = strtolower(htmlentities($os, ENT_QUOTES));
$query = 'UPDATE `AveragePayments` SET `Total` = `Total` + \''.$amount.'\', `Count` = `Count` + 1, `Average` = ((`Total` + \''.$amount.'\') / (`Count` + 1)) WHERE `OS`=\''.$os.'\' OR `OS`=\'total\';';
$result = $db->exec($query); // Result-less

if ( $db->lastErrorCode() ) LastError($db);
echo 'OK'.PHP_EOL;
Loading

0 comments on commit 178b8d2

Please sign in to comment.