diff --git a/includes/functions.php b/includes/functions.php index a7f348e..d77d424 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,138 +1,143 @@ . function license($code) { return Licenses::instance()->get($code); } function request_uri() { return URL_protocol() . URL_domain() . ROOT . $_SERVER['REQUEST_URI']; } /** * Generate a stupid MySQL COALESCE() clause to select the most appropriate i18n database column * * @param string $name Base virtual name of the column * @param mixed $i18n Associative array of languages and column names, or a generic column name like 'column_%s', or nothing to be the "$name_%s" * @return string */ function i18n_coalesce( $name, $i18n = null ) { // current language (e.g. 'en') $lang = latest_language()->getISO(); + // TODO: add database fields for Piemontese + if( $lang === 'pms' ) { + $lang = 'it'; + } + // default language of the website $default = 'it'; if( !$i18n ) { $i18n = $name . '_%s'; } // allow a generic string if( is_string( $i18n ) ) { $generic = $i18n; $i18n = []; $i18n[ $lang ] = sprintf( $generic, $lang ); $i18n[ $default ] = sprintf( $generic, $default ); } // base priority column name $base_priority = $i18n[ $default ]; // try to catch the more specific column, then the default if( $lang !== $default && isset( $i18n[ $lang ] ) ) { $more_priority = $i18n[ $lang ]; return "COALESCE( `$more_priority`, `$base_priority` ) AS $name"; } // just pick the default return "`$base_priority` AS $name"; } /** * Eventually redirect the request to this permalink * * It's allowed the 'lang' parameter to be present or not. * * @param string $permalink URL of the incoming request (absolute or relative) * @return string */ function force_permalink( $permalink ) { // incoming URL $from = BASE_URL . $_SERVER['REQUEST_URI']; // force absolute $permalink = site_page( $permalink, true ); // if it's the same request, do nothing if( $from === $permalink ) { return; } // do not send a 301 Moved Permanently if the language was missing (maybe the user was just redirected to his language) $status = isset( $_GET['l'] ) ? 301 // 301 Moved Permanently : 303; // 303 See Other // redirect to the correct location http_redirect( $permalink, $status ); } /** * Force an URL to have the language argument it it requested the page with it * * @return string */ function keep_url_in_language( $url ) { // force an absolute URL $url = site_page( $url, true ); // current language ISO code $lang = latest_language()->getISO(); // force this argument return replace_url_args( $url, [ 'l' => $lang, ] ); } /** * Override parameters in GET query string * * @param string $url The entire URL (no relative URLs they confuse parse_url) * @param array $parameters Associative array, with key = paramter, value = value or null to remove it * @return string the new query part of the URL with "?" already placed in front, or an empty string * @author Ludovico Pavesi * @since 2019-09-30 */ function replace_url_args( $url, $parameters ) { $parsed = parse_url( $url ); if( isset( $parsed['query'] ) ) { parse_str( $parsed['query'], $query ); } else { $query = []; } foreach( $parameters as $k => $v ) { if( $v === null ) { unset( $query[ $k ] ); } else { $query[ $k ] = $v; } } return http_build_get_query( $url, $parameters ); } diff --git a/includes/load-post.php b/includes/load-post.php index b30545a..6fd8a90 100644 --- a/includes/load-post.php +++ b/includes/load-post.php @@ -1,104 +1,105 @@ . // Die if called directly defined('BOZ_PHP') or exit; // Custom Sessionuser class define('SESSIONUSER_CLASS', 'User'); define('INCLUDES', 'includes'); // Autoload classes spl_autoload_register( function($c) { $path = ABSPATH . __ . INCLUDES . __ . "class-$c.php"; if( is_file( $path ) ) { require $path; } } ); // One day I will push these 2 functions in Boz-PHP require ABSPATH . '/includes/functions.php'; // user permissions register_permissions( 'user', [] ); // admin permissions inherit_permissions( 'admin', 'user', [ 'add-event', 'edit-users', 'edit-events', ] ); define_default( 'LATEST_CONFERENCE_UID', '2019' ); define_default( 'CURRENT_CONFERENCE_UID', LATEST_CONFERENCE_UID ); define_default( 'CONTACT_PHONE_PREFIX', '+39' ); define_default( 'REPO', 'https://github.com/LinuxDayTorino/LinuxDay-Torino-website' ); define_default( 'LIBMARKDOWN_PATH', '/usr/share/php/markdown.php' ); define_default( 'JQUERY', '/javascript/jquery/jquery.min.js' ); define_default( 'LEAFLET_DIR', '/javascript/leaflet' ); define_default( 'NOINDEX', false ); // /{conference_uid}/ define_default( 'PERMALINK_CONFERENCE', '%s/' ); // /{conference_uid}/{$chapter_uid}/{event_uid} define_default( 'PERMALINK_EVENT', '%1$s/%3$s/%2$s' ); // /2016/{user_uid} define_default( 'PERMALINK_USER', '%1$s/user/%2$s' ); define_default( 'FORCE_PERMALINK', 1 ); // timezone of database dates define_default( 'DEFAULT_TIMEZONE', 'Europe/Rome' ); register_js( 'jquery', JQUERY ); register_js( 'leaflet', LEAFLET_DIR . '/leaflet.js' ); register_css( 'leaflet', LEAFLET_DIR . '/leaflet.css' ); register_js('typed', ROOT . '/2017/static/typed/typed.min.js'); // GNU Gettext configuration define( 'GETTEXT_DOMAIN', 'linuxday' ); define( 'GETTEXT_DIRECTORY', ABSPATH . __ . 'l10n' ); define( 'GETTEXT_DEFAULT_ENCODE', 'utf8' ); // register languages -register_language( 'en_US', ['en', 'en-us', 'en-en'], null, null, 'English' ); -register_language( 'it_IT', ['it', 'it-it'], null, null, 'Italiano' ); +register_language( 'en_US', ['en', 'en-us', 'en-en'], null, null, 'English' ); +register_language( 'it_IT', ['it', 'it-it'], null, null, 'Italiano' ); +register_language( 'pms', [ 'pms' ], null, null, 'Piemontese' ); register_default_language( 'it_IT' ); // apply the global timezone date_default_timezone_set( DEFAULT_TIMEZONE ); // apply a language for this request only if( isset( $_GET['l'] ) ) { apply_language( $_GET['l'] ); } else { // as last resource, take from browser language apply_language(); } diff --git a/l10n/pms_PMS.utf8/LC_MESSAGES/linuxday.po b/l10n/pms.utf8/LC_MESSAGES/linuxday.po similarity index 100% rename from l10n/pms_PMS.utf8/LC_MESSAGES/linuxday.po rename to l10n/pms.utf8/LC_MESSAGES/linuxday.po