Tpl: Add stuff to have multiple templates directories with priority

This commit is contained in:
Benjamin Renard 2023-02-13 00:42:20 +01:00
parent 4f47dc056d
commit 317cb30cb3
24 changed files with 800 additions and 548 deletions

View file

@ -13,12 +13,6 @@ upload_tmp_directory: ${tmp_root_directory}/uploading"
# Main pagetitle
main_pagetitle: "Eesyphp"
# Theme CSS file
included_css_files:
#- css/custom.css
included_js_files:
#- js/custom.js
# Debug Ajax request/response
debug_ajax: false
@ -81,12 +75,17 @@ sentry:
traces_sample_rate: 0.2
#
# Smarty template configuration
# Smarty templates configuration
#
template:
templates:
# Smarty directories
directory: "${root_directory_path}/templates"
cache_directory: "${tmp_root_directory}/templates_c"
# Theme CSS file
included_css_files:
#- css/custom.css
included_js_files:
#- js/custom.js
#
# Translations

View file

@ -24,7 +24,7 @@ $root_dir_path = realpath(dirname($script).'/../');
set_include_path($root_dir_path.'/includes' . PATH_SEPARATOR . get_include_path());
// Load composer autoload.php
require("$root_dir_path/../vendor/autoload.php");
require("$root_dir_path/vendor/autoload.php");
// Initialize EesyPHP application
App::init(

View file

@ -22,15 +22,6 @@ Tpl :: enable_security_mode(
array('range', 'implode', 'stripslashes')
);
// Defined some global template variables
Tpl :: assign('public_root_url', App::get('public_root_url', '/', 'string'));
Tpl :: assign('main_pagetitle', App::get('main_pagetitle', null, 'string'));
Tpl :: assign('session_key', $_SESSION['session_key']);
// Handle CSS & JS files included
Tpl :: add_css_file(App::get('included_css_files', array(), 'array'));
Tpl :: add_js_file(App::get('included_js_files', array(), 'array'));
function define_common_template_variables($event) {
global $status_list, $admin;
Tpl :: assign(

View file

@ -10,11 +10,6 @@ use function EesyPHP\vardump;
if (php_sapi_name() == "cli")
return true;
function handle_homepage($request) {
Tpl :: display("homepage.tpl", _("Hello world !"));
}
Url :: add_url_handler('#^$#', 'handle_homepage');
function handle_search($request) {
global $status_list;

View file

@ -0,0 +1,305 @@
#: Cli.php:34
#, php-format
msgid "The CLI command '%s' already exists."
msgstr ""
#: Cli.php:39
#, php-format
msgid "The CLI command '%s' handler is not callable !"
msgstr ""
#: Cli.php:71
#, php-format
msgid "Usage: %s [-h] [-qd] command\n"
msgstr ""
#: Cli.php:72
msgid " -h Show this message\n"
msgstr ""
#: Cli.php:73
msgid " -q / -d Quiet/Debug mode\n"
msgstr ""
#: Cli.php:74
msgid " --trace Trace mode (the most verbose)\n"
msgstr ""
#: Cli.php:75
msgid " command Command to run\n"
msgstr ""
#: Cli.php:77
msgid "Available commands:\n"
msgstr ""
#: Cli.php:125
msgid "Only one command could be executed !"
msgstr ""
#: Cli.php:153
#, php-format
msgid ""
"Invalid parameter \"%s\".\n"
"Note: Command's parameter/argument must be place after the command."
msgstr ""
#: Cli.php:178
#, php-format
msgid "An exception occured running command %s"
msgstr ""
#: Db.php:74
msgid "Unable to connect to the database."
msgstr ""
#: Email.php:141
#, php-format
msgid "</hr><p><small>Mail initialy intended for %s.</small></p>"
msgstr ""
#: Email.php:142
#, php-format
msgid ""
"\n"
"\n"
"\n"
"Mail initialy intended for %s."
msgstr ""
#: Email.php:178
#, php-format
msgid "<p><small>%s: %s</small></p>"
msgstr ""
#: Email.php:179
#, php-format
msgid ""
"\n"
"%s: %s"
msgstr ""
#: Tpl.php:339
msgid "No template specified."
msgstr ""
#: Tpl.php:370
msgid "An error occurred while displaying this page."
msgstr ""
#: Url.php:141
msgid "Bad request"
msgstr ""
#: Url.php:142
msgid "Invalid request."
msgstr ""
#: Url.php:145
msgid "Authentication required"
msgstr ""
#: Url.php:146
msgid "You have to be authenticated to access to this page."
msgstr ""
#: Url.php:149
msgid "Access denied"
msgstr ""
#: Url.php:150
msgid ""
"You do not have access to this application. If you think this is an error, "
"please contact support."
msgstr ""
#: Url.php:153
msgid "Whoops ! Page not found"
msgstr ""
#: Url.php:154
msgid "The requested page can not be found."
msgstr ""
#: Url.php:162
msgid "Error"
msgstr ""
#: Url.php:163
msgid "An unknown error occurred. If problem persist, please contact support."
msgstr ""
#: Url.php:226
msgid ""
"Unable to determine the requested page. If the problem persists, please "
"contact support."
msgstr ""
#: Url.php:376
msgid ""
"Unable to determine the requested page (loop detected). If the problem "
"persists, please contact support."
msgstr ""
#: Url.php:407
msgid "This request cannot be processed."
msgstr ""
#: Url.php:420
msgid ""
"Authentication required but force_authentication function is not defined."
msgstr ""
#: Url.php:429
msgid "This request could not be processed correctly."
msgstr ""
#: I18n.php:114 App.php:120
msgid "Hello world !"
msgstr ""
#: I18n.php:130
msgid "Extract messages that need to be translated"
msgstr ""
#: I18n.php:132
msgid "This command could be used to generate/update lang/messages.pot file."
msgstr ""
#: I18n.php:138
msgid "Update messages in translation PO lang files"
msgstr ""
#: I18n.php:140
msgid ""
"This command could be used to init/update PO files in lang/*/LC_MESSAGES "
"directories."
msgstr ""
#: I18n.php:147
msgid ""
"Compile messages from existing translation PO lang files to corresponding MO "
"files and JSON catalogs"
msgstr ""
#: I18n.php:152
msgid ""
"This command could be used to compile PO files in lang/*/LC_MESSAGES "
"directories to MO files and as JSON catalogs in public_html/translations."
msgstr ""
#: I18n.php:277 I18n.php:307
msgid "Fail to list PHP files."
msgstr ""
#: I18n.php:296 I18n.php:326
msgid "Fail to extract messages from PHP files using xgettext."
msgstr ""
#: I18n.php:338
#, php-format
msgid "Fail to list JS files in '%s' static directory."
msgstr ""
#: I18n.php:358
msgid "Fail to extract messages from JS files using xgettext."
msgstr ""
#: I18n.php:374
msgid ""
"Fail to extract messages from template files using tsmarty2c.php script."
msgstr ""
#: I18n.php:402
msgid "Fail to merge messages using msgcat."
msgstr ""
#: I18n.php:416
#, php-format
msgid "Compendium file %s not found."
msgstr ""
#: I18n.php:423
#, php-format
msgid "POT file not found (%s). Please run extract_messages first."
msgstr ""
#: I18n.php:435 I18n.php:543
#, php-format
msgid "Lang directory '%s' found"
msgstr ""
#: I18n.php:441 I18n.php:549
#, php-format
msgid "LC_MESSAGES directory not found in lang '%s' directory, ignore it."
msgstr ""
#: I18n.php:456
#, php-format
msgid "Fail to init messages in %s PO file using msginit (%s)."
msgstr ""
#: I18n.php:474
#, php-format
msgid "Fail to update messages in %s PO file using msgmerge (%s)."
msgstr ""
#: I18n.php:480 I18n.php:557
#, php-format
msgid "PO file not found in lang '%s' directory, ignore it."
msgstr ""
#: I18n.php:487 I18n.php:597
#, php-format
msgid "Fail to open root lang directory (%s)."
msgstr ""
#: I18n.php:513
#, php-format
msgid "Lang alias symlink found: %s -> %s"
msgstr ""
#: I18n.php:520
#, php-format
msgid "JSON catalog symlink for %s -> %s created (%s)"
msgstr ""
#: I18n.php:524
#, php-format
msgid "Fail to create JSON catalog symlink for %s -> %s (%s)"
msgstr ""
#: I18n.php:530
#, php-format
msgid "JSON catalog symlink for %s -> %s already exist (%s)"
msgstr ""
#: I18n.php:535
#, php-format
msgid ""
"JSON catalog file for %s already exist, but it's not a symlink to %s (%s)"
msgstr ""
#: I18n.php:570
#, php-format
msgid "Fail to compile messages from %s PO file as MO file using msgfmt (%s)."
msgstr ""
#: I18n.php:580
#, php-format
msgid "Fail to open %s JSON catalog file in write mode (%s)."
msgstr ""
#: I18n.php:585
#, php-format
msgid "Fail to write %s JSON catalog in file (%s)."
msgstr ""
#: I18n.php:590
#, php-format
msgid "%s JSON catalog writed (%s)."
msgstr ""
#: App.php:122
msgid "Hello world!"
msgstr ""

View file

@ -1,554 +1,259 @@
#: /home/brenard/dev/eesyphp/includes/url-helpers.php:5
#: includes/cli.php:23
#, php-format
msgid "Item #%s:\n"
msgstr ""
#: includes/cli.php:24
#, php-format
msgid "ID: %s"
msgstr ""
#: includes/cli.php:25
#, php-format
msgid "Name: '%s'"
msgstr ""
#: includes/cli.php:26
#, php-format
msgid "Date: %s"
msgstr ""
#: includes/cli.php:28
#, php-format
msgid "Description: %s"
msgstr ""
#: includes/cli.php:29
msgid "Not set"
msgstr ""
#: includes/cli.php:31
#, php-format
msgid "Status: %s"
msgstr ""
#: includes/cli.php:84
msgid "No item.\n"
msgstr ""
#: includes/cli.php:110
#, php-format
msgid "%d item(s)"
msgstr ""
#: includes/cli.php:116
msgid "List/search items"
msgstr ""
#: includes/cli.php:117
msgid "[patterns]"
msgstr ""
#: includes/cli.php:119
msgid "-o|--orderby Ordering list criterion. Possible values:"
msgstr ""
#: includes/cli.php:121
msgid "-r|--reverse Reverse order"
msgstr ""
#: includes/cli.php:122
msgid "-s|--status Filter on status. Possible values:"
msgstr ""
#: includes/cli.php:129
msgid "You must provide a valid ID."
msgstr ""
#: includes/cli.php:135 includes/cli.php:159
#, php-format
msgid "Item #%s not found."
msgstr ""
#: includes/cli.php:143
msgid "Show item"
msgstr ""
#: includes/cli.php:144
msgid "[ID]"
msgstr ""
#: includes/cli.php:149
msgid "You must provide item ID."
msgstr ""
#: includes/cli.php:153
msgid "Invalid item ID"
msgstr ""
#: includes/cli.php:164
msgid "Are you sure you want to delete this item? Type 'yes' to continue: "
msgstr ""
#: includes/cli.php:168
msgid "User cancel"
msgstr ""
#: includes/cli.php:174
#, php-format
msgid "An error occured deleting item #%d."
msgstr ""
#: includes/cli.php:181
msgid "Delete item"
msgstr ""
#: includes/cli.php:182
msgid "[item ID]"
msgstr ""
#: includes/cli.php:194
msgid "Export items (as CSV)"
msgstr ""
#: includes/cli.php:195
msgid "[output file path]"
msgstr ""
#: includes/cli.php:210
msgid "Restore items (from CSV)"
msgstr ""
#: includes/cli.php:211
msgid "[input file path]"
msgstr ""
#: includes/cli.php:278
msgid "Cron to handle item expiration"
msgstr ""
#: includes/cli.php:281
msgid "-j/--just-try Just-try mode : do not really removed expired item(s)"
msgstr ""
#: includes/cli.php:282
msgid "-m/--max-age Item expiration limit (in days, optional)"
msgstr ""
#: includes/url-helpers.php:9
msgid "Invalid element identifier."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-helpers.php:9
#: /home/brenard/dev/eesyphp/includes/url-public.php:222
#: /home/brenard/dev/eesyphp/includes/url-public.php:246
#: includes/url-helpers.php:13 includes/url-public.php:220
#: includes/url-public.php:242
#, php-format
msgid "Item #% s not found."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/smarty.php:61
msgid "Smarty version not supported."
#: includes/core.php:51
msgid "Pending"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/smarty.php:148
msgid "No template specified."
#: includes/core.php:52
msgid "Validated"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/smarty.php:166
msgid "An error occurred while viewing this page."
#: includes/core.php:53
msgid "Refused"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:7
#: /home/brenard/dev/eesyphp/includes/translation.php:140
msgid "Hello world !"
#: includes/core.php:54
msgid "Archived"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:31
#: includes/url-public.php:33
msgid "Any"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:89
#: includes/url-public.php:91
msgid ""
"An error occurred while listing the items. If the problem persists, please "
"contact support."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:104
#: includes/url-public.php:106
msgid "Search"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:128
#: includes/url-public.php:128
#, php-format
msgid "Element %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:142
#: includes/url-public.php:142
#, php-format
msgid "The element '% s' has been created."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:146
#: includes/url-public.php:146
msgid "An error occurred while saving this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:153
#: includes/url-public.php:153
msgid ""
"There are errors preventing this item from being saved. Please correct them "
"before attempting to add this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:160
#: includes/url-public.php:160
msgid "New"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:170
#: includes/url-public.php:170
msgid "You cannot edit this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:183
#: includes/url-public.php:183
#, php-format
msgid "You have not made any changes to element '% s'."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:187
#: includes/url-public.php:187
#, php-format
msgid "The element '% s' has been updated successfully."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:191
#: includes/url-public.php:191
msgid "An error occurred while updating this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:199
#: includes/url-public.php:199
msgid ""
"There are errors preventing this item from being saved. Please correct them "
"before attempting to save your changes."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:211
#: includes/url-public.php:211
#, php-format
msgid "Element %s: Modification"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:226
#: includes/url-public.php:224
msgid "This item is already archived."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:229
#: includes/url-public.php:227
msgid "You cannot archive this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:232
#: includes/url-public.php:230
#, php-format
msgid "The element '% s' has been archived successfully."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:235
#: includes/url-public.php:233
msgid "An error occurred while archiving this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:249
#: includes/url-public.php:245
msgid "You cannot delete this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:252
#: includes/url-public.php:248
#, php-format
msgid "The element '% s' has been deleted successfully."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url-public.php:255
#: includes/url-public.php:251
msgid "An error occurred while deleting this item."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/db.php:31
msgid "Unable to connect to the database."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/core.php:44
msgid "Pending"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/core.php:45
msgid "Validated"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/core.php:46
msgid "Refused"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/core.php:47
msgid "Archived"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:59
msgid "Fail to list PHP files."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:76
msgid "Fail to extract messages from PHP files using xgettext."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:86
msgid "Fail to list JS files."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:103
msgid "Fail to extract messages from JS files using xgettext."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:116
msgid ""
"Fail to extract messages from template files using tsmarty2c.php script."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:142
msgid "Fail to merge messages using msgcat."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:147
msgid "Extract messages that need to be translated"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:149
msgid "This command could be used to generate/update lang/messages.pot file."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:165
#, php-format
msgid "Compendium file %s not found."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:172
#, php-format
msgid "POT file not found (%s). Please run extract_messages first."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:184
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:301
#, php-format
msgid "Lang directory '%s' found"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:190
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:307
#, php-format
msgid "LC_MESSAGES directory not found in lang '%s' directory, ignore it."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:205
#, php-format
msgid "Fail to init messages in %s PO file using msginit (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:223
#, php-format
msgid "Fail to update messages in %s PO file using msgmerge (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:229
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:315
#, php-format
msgid "PO file not found in lang '%s' directory, ignore it."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:236
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:356
#, php-format
msgid "Fail to open root lang directory (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:241
msgid "Update messages in translation PO lang files"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:243
msgid ""
"This command could be used to init/update PO files in lang/*/LC_MESSAGES "
"directories."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:270
#, php-format
msgid "Lang alias symlink found: %s -> %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:277
#, php-format
msgid "JSON catalog symlink for %s -> %s created (%s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:281
#, php-format
msgid "Fail to create JSON catalog symlink for %s -> %s (%s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:287
#, php-format
msgid "JSON catalog symlink for %s -> %s already exist (%s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:293
#, php-format
msgid ""
"JSON catalog file for %s already exist, but it's not a symlink to %s (%s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:329
#, php-format
msgid "Fail to compile messages from %s PO file as MO file using msgfmt (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:339
#, php-format
msgid "Fail to open %s JSON catalog file in write mode (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:344
#, php-format
msgid "Fail to write %s JSON catalog in file (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:349
#, php-format
msgid "%s JSON catalog writed (%s)."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:362
msgid ""
"Compile messages from existing translation PO lang files to corresponding MO "
"files and JSON catalogs"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/translation-cli.php:367
msgid ""
"This command could be used to compile PO files in lang/*/LC_MESSAGES "
"directories to MO files and as JSON catalogs in public_html/translations."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/mail.php:14
#, php-format
msgid ""
"\n"
"\n"
"\n"
"Mail initialy intended for %s."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:98
msgid "Bad request"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:99
msgid "Invalid request."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:102
msgid "Authentication required"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:103
msgid "You have to be authenticated to access to this page."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:106
msgid "Access denied"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:107
msgid ""
"You do not have access to this application. If you think this is an error, "
"please contact support."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:110
msgid "Whoops ! Page not found"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:111
msgid "The requested page can not be found."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:119
msgid "Error"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:120
msgid "An unknown error occurred. If problem persist, please contact support."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:165
msgid ""
"Unable to determine the requested page. If the problem persists, please "
"contact support."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:318
msgid ""
"Unable to determine the requested page (loop detected). If the problem "
"persists, please contact support."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:347
msgid "This request cannot be processed."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:360
msgid ""
"Authentication required but force_authentication function is not defined."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/url.php:368
msgid "This request could not be processed correctly."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:8
#, php-format
msgid "The CLI command '%s' already exists."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:13
#, php-format
msgid "The CLI command '%s' handler is not callable !"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:54
#, php-format
msgid "Usage: %s [-h] [-qd] command\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:55
msgid " -h Show this message\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:56
msgid " -q / -d Quiet/Debug mode\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:57
msgid " --trace Trace mode (the most verbose)\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:58
msgid " command Command to run\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:60
msgid "Available commands:\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:102
msgid "Only one command could be executed !"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:127
#, php-format
msgid ""
"Invalid parameter \"%s\".\n"
"Note: Command's parameter/argument must be place after the command."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:149
#, php-format
msgid "An exception occured running command %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:155
#, php-format
msgid "Item #%s:\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:156
#, php-format
msgid "ID: %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:157
#, php-format
msgid "Name: '%s'"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:158
#, php-format
msgid "Date: %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:160
#, php-format
msgid "Description: %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:161
msgid "Not set"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:163
#, php-format
msgid "Status: %s"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:216
msgid "No item.\n"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:242
#, php-format
msgid "%d item(s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:248
msgid "List/search items"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:249
msgid "[patterns]"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:251
msgid "-o|--orderby Ordering list criterion. Possible values:"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:253
msgid "-r|--reverse Reverse order"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:254
msgid "-s|--status Filter on status. Possible values:"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:261
msgid "You must provide a valid ID."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:267
#: /home/brenard/dev/eesyphp/includes/cli.php:291
#, php-format
msgid "Item #%s not found."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:275
msgid "Show item"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:276
msgid "[ID]"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:281
msgid "You must provide item ID."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:285
msgid "Invalid item ID"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:296
msgid "Are you sure you want to delete this item? Type 'yes' to continue: "
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:300
msgid "User cancel"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:306
#, php-format
msgid "An error occured deleting item #%d."
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:313
msgid "Delete item"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:314
msgid "[item ID]"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:326
msgid "Export items (as CSV)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:327
msgid "[output file path]"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:342
msgid "Restore items (from CSV)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:343
msgid "[input file path]"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:412
msgid "Cron to handle item expiration"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:415
msgid "-j/--just-try Just-try mode : do not really removed expired item(s)"
msgstr ""
#: /home/brenard/dev/eesyphp/includes/cli.php:416
msgid "-m/--max-age Item expiration limit (in days, optional)"
msgstr ""

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="content"}
<form enctype="multipart/form-data" method="post" class="container" id="item-form">
<input type='hidden' name='session_key' value='{$session_key|escape:'quotes'}' />

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="pagetitle"}{/block}
{block name="content"}
<div class="jumbotron">

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="content"}
<div class="row">
<div class="col-md-auto">

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="content"}
<div class="container">
<div class="form-group row">

1
example/vendor Symbolic link
View file

@ -0,0 +1 @@
../vendor

View file

@ -2,7 +2,8 @@ parameters:
level: 5
paths:
- src
- example
- example/includes
- example/public_html
excludePaths:
- example/includes/config.local.php
- example/data/tmp/templates_c

View file

@ -58,10 +58,12 @@ class App {
Log::init();
if (self :: get('session.enabled', true, 'bool'))
Session::init();
if (self :: get('template.enabled', true, 'bool'))
if (self :: get('templates.enabled', true, 'bool'))
Tpl :: init();
if (self :: get('url.enabled', true, 'bool'))
if (self :: get('url.enabled', true, 'bool')) {
Url::init();
Url :: add_url_handler('#^$#', array('EesyPHP\\App', 'handle_homepage'));
}
if (self :: get('mail.enabled', true, 'bool'))
Email :: init();
if (self :: get('i18n.enabled', true, 'bool'))
@ -108,4 +110,16 @@ class App {
return self :: $root_directory_path?self :: $root_directory_path:'.';
}
/**
* Default homepage handler
* @param UrlRequest $request
* @return void
*/
public static function handle_homepage($request) {
if (Tpl::initialized())
Tpl :: display("homepage.tpl", _("Hello world !"));
else
echo "<h1>"._("Hello world!")."</h1>";
}
}

View file

@ -266,11 +266,42 @@ class I18n {
// Store list of generated POT files
$pot_files = array();
// List EesyPHP PHP files to parse
$eesyphp_php_files = run_external_command(
array('find', '-name', "'*.php'"),
null, // no STDIN data
false, // do not escape command args (already done)
__DIR__ // Run from EesyPHP src directory
);
if (!is_array($eesyphp_php_files) || $eesyphp_php_files[0] != 0) {
Log :: fatal(_("Fail to list PHP files."));
}
// Extract messages from EesyPHP PHP files using xgettext
$result = run_external_command(
array(
"xgettext",
"--from-code utf-8",
"--language=PHP",
"-o", self :: $root_path."/eesyphp-messages.pot", // Output
"--omit-header", // No POT header
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$eesyphp_php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
__DIR__ // Run from EesyPHP src directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from PHP files using xgettext."));
$pot_files[] = self :: $root_path."/eesyphp-messages.pot";
// List PHP files to parse
$php_files = run_external_command(
array('find', escapeshellarg(App :: root_directory_path()), '-name', "'*.php'"),
null, // no STDIN data
false // do not escape command args (already done)
array('find', '-name', "'*.php'"),
null, // no STDIN data
false, // do not escape command args (already done)
App :: root_directory_path() // Run from Application root directory
);
if (!is_array($php_files) || $php_files[0] != 0) {
Log :: fatal(_("Fail to list PHP files."));
@ -287,20 +318,27 @@ class I18n {
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$php_files[1] // Pass PHP files list via STDIN
$php_files[1], // Pass PHP files list via STDIN
true, // Escape parameters
App :: root_directory_path() // Run from EesyPHP src directory
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from PHP files using xgettext."));
$pot_files[] = self :: $root_path."/php-messages.pot";
// List JS files to parse
$js_files = run_external_command(
array('find', escapeshellarg(App :: root_directory_path()."/public_html/js"), '-name', "'*.js'"),
null, // no STDIN data
false // do not escape command args (already done)
);
if (!is_array($js_files) || $js_files[0] != 0) {
Log :: fatal(_("Fail to list JS files."));
$js_files = array();
foreach(Tpl::static_directories() as $static_directory) {
$result = run_external_command(
array('find', escapeshellarg($static_directory), '-name', "'*.js'"),
null, // no STDIN data
false // do not escape command args (already done)
);
if (!is_array($result) || $result[0] != 0) {
Log :: fatal(_("Fail to list JS files in '%s' static directory."), $static_directory);
return;
}
$js_files[] = $result[1];
}
// Extract messages from JS files using xgettext
@ -314,7 +352,7 @@ class I18n {
"--keyword=___", // Handle custom ___() translation function
"--files=-" // Read files to parse from STDIN
),
$js_files[1] // Pass JS files list via STDIN
implode("\n", $js_files) // Pass JS files list via STDIN
);
if (!is_array($result) || $result[0] != 0)
Log :: fatal(_("Fail to extract messages from JS files using xgettext."));
@ -323,10 +361,12 @@ class I18n {
if (Tpl :: initialized()) {
// Extract messages from templates files using tsmarty2c.php
$result = run_external_command(
array (
App :: root_directory_path()."/vendor/bin/tsmarty2c.php",
"-o", self :: $root_path."/templates-messages.pot",
Tpl :: templates_directory(),
array_merge(
array(
App :: root_directory_path()."/vendor/bin/tsmarty2c.php",
"-o", self :: $root_path."/templates-messages.pot",
),
Tpl :: templates_directories(),
)
);
if (!is_array($result) || $result[0] != 0)

View file

@ -22,10 +22,10 @@ class Tpl {
public static $smarty_security_policy = null;
/**
* Smarty templates directory path
* @var string
* Smarty templates directories path with their priority
* @var array<string,int>
*/
public static string $templates_dir;
public static array $templates_directories = array();
/**
* Smarty cache templates directory path
@ -40,8 +40,8 @@ class Tpl {
public static bool $_debug_ajax;
/**
* Static directories
* @var array
* Static directories path with their priority
* @var array<string,array>
*/
private static array $static_directories = array();
@ -72,46 +72,82 @@ class Tpl {
/**
* Initialization
* @param string $templates_dir Smarty templates directory path
* (optional, default: from template.directory config key)
* (optional, default: from templates.directory config key)
* @param string $templates_c_dir Smarty cache templates directory path
* (optional, default: from template.cache_directory config key)
* (optional, default: from templates.cache_directory config key)
* @param bool $debug_ajax Enable/disable AJAX returned data debugging in logs
* (optional, default: from template.debug_ajax or debug_ajax config keys if set,
* (optional, default: from templates.debug_ajax or debug_ajax config keys if set,
* false otherwise)
* @param bool $static_root_url Configure custom root URL path for static files
* (optional, default: from template.static_root_url config key if set,
* (optional, default: from templates.static_root_url config key if set,
* '/static' otherwise. Set to False to disable)
* @return void
*/
public static function init($templates_dir=null, $templates_c_dir=null, $debug_ajax=null,
$static_root_url=null) {
// Check templates/templates_c directories
// Handle templates directories
$default_templates_directory = realpath(__DIR__."/../templates");
self :: register_templates_directory($default_templates_directory);
if (is_null($templates_dir))
$templates_dir = App::get('template.directory', null, 'string');
if (is_null($templates_c_dir))
$templates_c_dir = App::get('template.cache_directory', null, 'string');
if (!$templates_dir || !is_dir($templates_dir)) {
Log :: fatal(
"Template directory not found (%s)",
$templates_dir?$templates_dir:'not set');
return;
$templates_dir = App::get('templates.directory', null, 'string');
if ($templates_dir) {
if (!is_dir($templates_dir))
Log :: fatal("Template directory not found (%s)", $templates_dir);
self :: register_templates_directory($templates_dir);
}
if (!$templates_c_dir || !is_dir($templates_c_dir) || !is_writable($templates_c_dir)) {
Log :: fatal(
"Template cache directory not found or not writable (%s)",
$templates_c_dir?$templates_c_dir:'not set');
return;
// Handle and check templates_c directories
if (is_null($templates_c_dir))
$templates_c_dir = App::get('templates.cache_directory', null, 'string');
if ($templates_c_dir) {
if (!is_dir($templates_c_dir) || !is_writable($templates_c_dir)) {
Log :: fatal(
"Template cache directory not found or not writable (%s)",
$templates_c_dir);
return;
}
}
else {
$public_root_url = Url :: public_root_url();
if ($public_root_url != '/') {
$unique_name = preg_replace('#^https?://#', '', $public_root_url);
}
else {
$root_directory_path = App::root_directory_path();
if ($root_directory_path == '.') {
Log :: fatal(
'Fail to compute a unique templates cache directory for this application. An public '.
'root URL or an application root directory must be set if you do not provide it at '.
'initialization (or via config parameter).');
return;
}
$unique_name = $root_directory_path;
if (substr($unique_name, 0, 1) == '/')
$unique_name = substr($unique_name, 1);
if (substr($unique_name, -1) == '/')
$unique_name = substr($unique_name, 0, -1);
}
$templates_c_dir = sys_get_temp_dir().str_replace(
'/', '_', "eesyphp_templates_cache_$unique_name"
);
if (!is_dir($templates_c_dir) && !mkdir($templates_c_dir)) {
Log :: fatal(
'Fail to create application templates cache directory (%s)',
$templates_c_dir);
return;
}
}
self :: $smarty = new Smarty();
self :: $smarty->setTemplateDir($templates_dir);
self :: $smarty->setTemplateDir($default_templates_directory);
self :: $smarty->setCompileDir($templates_c_dir);
self :: $smarty->registerResource('Tpl', new TplSmartyResource());
if (is_null($debug_ajax))
$debug_ajax = App::get('template.debug_ajax', App::get('debug_ajax'));
$debug_ajax = App::get('templates.debug_ajax', App::get('debug_ajax'));
self :: $_debug_ajax = boolval($debug_ajax);
Log :: register_fatal_error_handler(array('\\EesyPHP\\Tpl', 'fatal_error'));
if (is_null($static_root_url))
$static_root_url = App::get('template.static_root_url', 'static/', 'string');
$static_root_url = App::get('templates.static_root_url', 'static/', 'string');
if ($static_root_url) {
if (substr($static_root_url, 0, 1) == '/')
$static_root_url = substr($static_root_url, 1);
@ -269,7 +305,14 @@ class Tpl {
*/
protected static function define_common_variables($pagetitle=null) {
global $auth_user;
self :: assign('public_root_url', Url :: public_root_url());
self :: assign('pagetitle', $pagetitle);
self :: assign('main_pagetitle', App::get('main_pagetitle', null, 'string'));
self :: assign('session_key', isset($_SESSION['session_key'])?$_SESSION['session_key']:null);
// Handle CSS & JS files included
self :: add_css_file(App::get('templates.included_css_files', array(), 'array'));
self :: add_js_file(App::get('templates.included_js_files', array(), 'array'));
// Messages
self :: assign('errors', (isset($_SESSION['errors'])?$_SESSION['errors']:array()));
@ -319,7 +362,7 @@ class Tpl {
try {
Hook :: trigger('before_displaying_template');
self :: define_common_variables($pagetitle);
self :: $smarty->display($template);
self :: $smarty->display("Tpl:$template");
}
catch (Exception $e) {
Log :: exception($e, "Smarty - An exception occured displaying template '$template'");
@ -413,11 +456,93 @@ class Tpl {
}
/**
* Get the templates directory path
* @return string|null
* Get the templates directories path
* @return array<string>
*/
public static function templates_directory() {
return isset(self :: $templates_directory)?self :: $templates_directory:null;
public static function templates_directories() {
return array_keys(self :: $templates_directories);
}
/**
* Register a templates directory
* @param string $path The templates directory path
* @param int|null $priority The priority of this templates directory
* (optional, default: prior than all other registered directories)
* @return void
*/
public static function register_templates_directory($path, $priority=null) {
if (!is_dir($path)) {
Log :: fatal(
'register_templates_directory(%s): this templates directory does not exists',
$path);
return;
}
if (substr($path, -1) == '/')
$path = substr($path, 0, -1);
if (is_null($priority)) {
$priority = (
!empty(self :: $templates_directories)?
max(self :: $templates_directories) + 1:
100
);
}
Log :: trace(
'Register templates directory "%s" with priority %d',
$path, $priority);
self :: $templates_directories[$path] = $priority;
arsort(self :: $templates_directories);
}
/**
* Resolve templates path against registered templates directories
* @param string $path
* @return string|false
*/
public static function resolve_templates_path($path) {
foreach(array_keys(self :: $templates_directories) as $dir) {
$fullpath = "$dir/$path";
if (file_exists($fullpath)) {
Log::trace('Templates file "%s" resolved as "%s"', $path, $fullpath);
return $fullpath;
}
}
Log::trace('Templates file "%s" not found', $path);
return false;
}
/**
* Return the content of a Smarty template file.
*
* @param string $template The template name (eg: base.tpl)
*
* @return string The content of the Smarty template file
**/
public static function get_template_source($template) {
$path = self :: resolve_templates_path($template);
if (!is_readable($path)) {
// No error return with Smarty3 and highter because it's call
// template name in lower first systematically
return '';
}
return file_get_contents($path);
}
/**
* Return the timestamp of the last change of a Smarty
* template file.
*
* @param string $template The template name (eg: empty.tpl)
*
* @return int|null The timestamp of the last change of the Smarty template file
**/
public static function get_template_timestamp($template) {
$path = self :: resolve_templates_path($template);
if (is_file($path)) {
$time = filemtime($path);
if ($time)
return $time;
}
return null;
}
/**
@ -433,6 +558,19 @@ class Tpl {
return $value;
}
/**
* Get the static directories path
* @return array<string>
*/
public static function static_directories() {
$result = array();
foreach(self :: $static_directories as $root_url => $dirs)
foreach(array_keys($dirs) as $dir)
if (!in_array($dir, $result))
$result[] = $dir;
return $result;
}
/**
* Register a static directory
* @param string $path The static directory path
@ -477,7 +615,7 @@ class Tpl {
$path, $root_url, $priority);
}
if (substr($path, -1) == PATH_SEPARATOR)
if (substr($path, -1) == '/')
$path = substr($path, 0, -1);
self :: $static_directories[$root_url][$path] = $priority;
arsort(self :: $static_directories[$root_url]);

44
src/TplSmartyResource.php Normal file
View file

@ -0,0 +1,44 @@
<?php
namespace EesyPHP;
use Smarty_Resource_Custom;
/**
* Smarty ressource for EesyPHP templates
*
* @author Benjamin Renard <brenard@zionetrix.net>
*/
class TplSmartyResource extends Smarty_Resource_Custom {
// prepared fetch() statement
protected $fetch;
// prepared fetchTimestamp() statement
protected $mtime;
/**
* Fetch a template and its modification time
*
* @param string $name template name
* @param string $source template source
* @param integer $mtime template modification timestamp (epoch)
* @return void
*/
protected function fetch($name, &$source, &$mtime) {
$source = Tpl :: get_template_source($name);
$mtime = Tpl :: get_template_timestamp($name);
}
/**
* Fetch a template's modification time
*
* Note: implementing this method is optional. Only implement it if modification times can be
* accessed faster than loading the comple template source.
*
* @param string $name template name
* @return integer timestamp (epoch) the template was modified
*/
protected function fetchTimestamp($name) {
return Tpl :: get_template_timestamp($name);
}
}

View file

@ -515,6 +515,14 @@ class Url {
if (is_bool($value)) self :: $_api_mode = $value;
return self :: $_api_mode;
}
/**
* Get public root URL
* @return string
*/
public static function public_root_url() {
return (self :: $public_root_url?self :: $public_root_url:'/');
}
}
# vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab

View file

@ -202,11 +202,14 @@ function delete_directory($dir, $recursive=true) {
* @param $data_stdin string|null The command arguments (optional, default: null)
* @param $escape_command_args boolean If true, the command will be escaped
* (optional, default: true)
* @param string|null $cwd The initial working dir for the command
* (optional, default: null = use current PHP process working
* directory)
*
* @return false|array An array of return code, stdout and stderr result or False in case of fatal
* error
**/
function run_external_command($command, $data_stdin=null, $escape_command_args=true) {
function run_external_command($command, $data_stdin=null, $escape_command_args=true, $cwd=null) {
if (is_array($command))
$command = implode(' ', $command);
if ($escape_command_args)
@ -217,7 +220,7 @@ function run_external_command($command, $data_stdin=null, $escape_command_args=t
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w"), // stderr
);
$process = proc_open($command, $descriptorspec, $pipes);
$process = proc_open($command, $descriptorspec, $pipes, $cwd);
if (!is_resource($process)) {
Log :: error("Fail to run external command: '$command'");

View file

@ -71,8 +71,8 @@
<main role="main">
<div class="container-fluid" id="content_container">
{block name="pagetitle"}{if $pagetitle}<h1>{$pagetitle}</h1>{/if}{/block}
{include file='errors.tpl'}
{include file='messages.tpl'}
{include file='Tpl:errors.tpl'}
{include file='Tpl:messages.tpl'}
{block name="content"}{/block}
</div>
</main>

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="content"}
<p class="center">{$message}</p>
{/block}

View file

@ -1,4 +1,4 @@
{extends file='empty.tpl'}
{extends file='Tpl:empty.tpl'}
{block name="content"}
<h1 class="center">Oops ...</h1>

8
templates/homepage.tpl Normal file
View file

@ -0,0 +1,8 @@
{extends file='Tpl:empty.tpl'}
{block name="pagetitle"}{/block}
{block name="content"}
<div class="jumbotron">
<h1 class="display-4">{t}Hello, world!{/t}</h1>
<p class="lead">{t escape=off}This is the default page of a new app using EesyPHP framework. Register your own templates directory and create a <em>homepage.tpl</em> file to overwrite it. You could also overwrite the URL handler for the root of the web application.{/t}</p>
</div>
{/block}