Skip to content

Commit 241ead3

Browse files
committed
Initial commit
1 parent 9f30039 commit 241ead3

File tree

13 files changed

+201
-2
lines changed

13 files changed

+201
-2
lines changed

.htaccess

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FallbackResource index.php
2+
3+
RewriteEngine On
4+
5+
# Rewrites everything to root index.php
6+
RewriteRule ^(.*)$ "index.php"

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,61 @@
1-
# php-framework
2-
A PHP framework for easy and efficient creation of multi-lingual websites
1+
# PHP Framework (Work in progress)
2+
A PHP framework for easy creation of high-performance, multi-lingual websites.
3+
4+
This framework does not contain pre-defined HTML code or something like that,
5+
the purpose of it is to organize your code and eliminate code duplication while
6+
providing maximum performance.
7+
8+
## How to use
9+
In the following is described how to build a website with this framework:
10+
11+
### Structure
12+
#### `views`
13+
Inside of the `views` folder you put your PHP or HTML files that define the layout of each page view of your website.
14+
The structure inside the `views` folder is important because it also defines how the URLs, that the user calls, will look like later on.
15+
For example if you place a file the following `views/login/index.php` then the resulting URL to request the file
16+
will be `https://<yourDomain>/<languageCode>/login/`.
17+
18+
#### `translations`
19+
The `translations` directory contains JSON files that contain the actual text in different languages.
20+
Inside the `translations/globals.json` you can define text variables that should be available in every language
21+
e.g. all the native names
22+
23+
#### `css-components`
24+
You can put CSS files into the `css-components` directory, however they can not directly be called from an URL!
25+
Instead you can define in the `css-components/routes.json` file names that should be generated as keys
26+
and as values an array of files names you've created inside `css-components`. Calling a file name defined as key will
27+
automatically generate the appropriate file consisting of the contents of the file names defined in the value array.
28+
Those generated files will be put in the `css` folder that is publicly accessible over the URL `https://<yourDomain>/css/`.
29+
If a file inside the `css-components` folder gets changed the generated files inside the `css` folder will be automatically updated.
30+
31+
#### `css`
32+
Files automatically generated out of the `css-components` will be placed here.
33+
However you can also directly place static CSS files inside of here if you don't want to use the CSS components system.
34+
All files of the `css` folder are publicly accessible over the URL `https://<yourDomain>/css/`.
35+
36+
#### `js-components`
37+
TODO
38+
39+
#### `js`
40+
TODO
41+
42+
#### `scripts`
43+
TODO
44+
45+
#### `images`
46+
The `images` folder contains all the images. You can create subdirectories in it as you like.
47+
Referencing images inside your code looks like the following `<?php echo IMAGES.'<pathInsideImagesDir>'; ?>`
48+
where the keyword `IMAGES` will get replaced with the relative path to the `images/` directory. So you need just to
49+
append your path as if you were inside the `images/` directory.
50+
For example `<?php echo IMAGES.'backgrounds/start-background.jpg'; ?>`
51+
52+
### Global Variables
53+
* `CSS` TODO
54+
* `JS` TODO
55+
* `IMAGES` TODO
56+
* `SCRIPTS` TODO
57+
* `BASE` Relative path to root index file but still with the language prefix e.g. `https://<yourDomain>/en/`
58+
* `ROOT` Relative path to absolute root index file without the language prefix e.g. `https://<yourDomain>/`
59+
* `LANGUAGE_CODE` TODO
60+
* `REQUEST` TODO
61+
* `FULL_REQUEST` TODO

css-components/default.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
:root {
2+
--color-main: '#333';
3+
4+
--background-main: '#fff';
5+
}
6+
7+
.noselect {
8+
-webkit-user-select: none;
9+
-khtml-user-select: none;
10+
-moz-user-select: none;
11+
-o-user-select: none;
12+
user-select: none;
13+
}
14+
.nodrag {
15+
-webkit-user-drag: none;
16+
-khtml-user-drag: none;
17+
-moz-user-drag: none;
18+
-o-user-drag: none;
19+
user-drag: none;
20+
}

css-components/header.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
header {
2+
display: block;
3+
width: 100%;
4+
}

css-components/routes.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"home": ["default", "header", "home", "footer"],
3+
"contact": ["default", "header", "about", "footer"],
4+
}

css/static.css

Whitespace-only changes.

index.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
4+
// ---------------------------------------------------------------------------------------
5+
// CONFIG
6+
// ---------------------------------------------------------------------------------------
7+
8+
define('DEFAULT_LANGUAGE_CODE', 'en');
9+
10+
define('_CSS', 'css/'); // internal use only
11+
define('_IMAGES', 'images/'); // internal use only
12+
define('_JS', 'js/'); // internal use only
13+
define('_VIEWS', 'views/'); // internal use only
14+
define('_SCRIPTS', 'scripts/'); // internal use only
15+
define('_TRANSLATIONS', 'translations/'); // internal use only
16+
17+
18+
19+
20+
21+
// ---------------------------------------------------------------------------------------
22+
// DEFINING DEFAULT FUNCTIONS
23+
// ---------------------------------------------------------------------------------------
24+
25+
function isSupportedLanguage($langCode){
26+
return is_string($langCode) && file_exists(_TRANSLATIONS.strtolower($langCode).'.php');
27+
}
28+
29+
// ---------------------------------------------------------------------------------------
30+
// PROCESSING REQUEST URI
31+
// ---------------------------------------------------------------------------------------
32+
33+
$base = substr($_SERVER['SCRIPT_NAME'], 0, -strlen(basename($_SERVER['SCRIPT_NAME'])));
34+
35+
define('FULL_REQUEST', substr($_SERVER['REQUEST_URI'], strlen($base)));
36+
$fullRequestLen = strlen(FULL_REQUEST);
37+
38+
// ---------------------------------------------------------------------------------------
39+
// DETECTING LANGUAGE
40+
// ---------------------------------------------------------------------------------------
41+
42+
$lang = false;
43+
// TODO check if language codes exist as /translations/<lang>.php
44+
45+
// TODO based on URI
46+
47+
// TODO based cookie
48+
49+
// TODO default language
50+
51+
if(!isSupportedLanguage($lang)) $lang = DEFAULT_LANGUAGE_CODE;
52+
53+
define('LANGUAGE_CODE', $lang);
54+
55+
$langLen = strlen(LANGUAGE_CODE);
56+
57+
define('REQUEST', ($fullRequestLen < $langLen || strtolower(substr(FULL_REQUEST, 0, $langLen)) != $lang) ? FULL_REQUEST : substr(FULL_REQUEST, $langLen+1));
58+
59+
// ---------------------------------------------------------------------------------------
60+
// ---------------------------------------------------------------------------------------
61+
62+
63+
// TODO HANDLE _CSS
64+
// TODO HANDLE _IMAGES
65+
// TODO HANDLE _JS
66+
67+
// TODO HANDLE sitemap.
68+
69+
?>

js-components/routes.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"home": {
3+
"instant": ["storage.js"],
4+
"onload": ["home-onload"]
5+
},
6+
"about": {
7+
"onload": ["about"]
8+
}
9+
}

js/static.js

Whitespace-only changes.

translations/de.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"descriptionAbout": "Weitere Informationen über dieses Framework und LupCode",
3+
"descriptionStart": "Startseite dieses Frameworks, welches von LupCode entwickelt wurde",
4+
5+
"languageName": "Deutsch"
6+
}

translations/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"descriptionAbout": "More information about this framework and LupCode",
3+
"descriptionStart": "Start page of this framework developed by LupCode",
4+
5+
"languageName": "English"
6+
}

translations/globals.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"languageNameDE": "Deutsch",
3+
"languageNameEN": "English",
4+
"languageNameES": "Español",
5+
"languageNameFR": "Français",
6+
"languageNameIT": "Italiano",
7+
"languageNameNL": "Nederlands",
8+
"languageNamePO": "Polskie",
9+
"languageNameRU": "русский",
10+
11+
"keywordsStartEN": "Start,Framework,PHP,LupCode",
12+
"keywordsStartDE": "Start,Framework,PHP,LupCode",
13+
14+
"keywordsAboutEN": "About,Welcome,LupCode",
15+
"keywordsAboutDE": "Über,Willkommen,LupCode"
16+
}

views/index.php

Whitespace-only changes.

0 commit comments

Comments
 (0)