diff --git a/2016/index.php b/2016/index.php index 3c328db..93ec704 100644 --- a/2016/index.php +++ b/2016/index.php @@ -1,396 +1,399 @@ . require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); -$conference or die_with_404(); +if( !$conference ) { + die_with_404(); +} -FORCE_PERMALINK - and $conference->forceConferencePermalink(); +if( FORCE_PERMALINK ) { + $conference->forceConferencePermalink(); +} enqueue_js('leaflet'); enqueue_js('leaflet.init'); enqueue_js('scrollfire'); enqueue_css('leaflet'); enqueue_css('home'); // Support for non-JavaScript inject_in_module('header', function() { echo "\n\t"; } ); Header::spawn( null, [ 'show-title' => false, 'head-title' => $s = $conference->getConferenceTitle(), 'title' => $s, 'url' => $conference->getConferenceURL() ] ); ?> getConferenceEnd('Y-m-d H:i:s'); $other_events = $conference->factoryFullEventByConference() ->select( [ Event::UID, Event::TITLE, Event::START, Event::END, Chapter::UID, Chapter::NAME, Room::NAME, ] ) ->where( sprintf( "%s > '%s'", Event::END, esc_sql( $from ) ) ) ->orderBy( Event::START ) ->queryGenerator(); ?> valid() ): ?>

getConferenceTitle() ) ?>

isEventPassed() ) { $classes .= ' grey lighten-3'; } ?>
getConferenceUID(), $event->getEventUID(), $event->getChapterUID() ), $event->getEventTitle() ) ?>
(getChapterName() ?>)

(getEventStart( __( "d/m/Y" ) ), $event->getEventStart( 'H:i' ) ) ?>)
getRoomName() ?>

getConferenceURL(), strtoupper( SITE_NAME ), null, TEXT ) ?>

<?= esc_attr( $conference->getConferenceTitle() ) ?>

%s (%s) presso il Dipartimento di Informatica dell'Università degli studi di Torino." ), HTML::a( __('https://it.wikipedia.org/wiki/GNU'), 'GNU', null, 'black-text hoverable' ), HTML::a( __('https://it.wikipedia.org/wiki/Linux_%28kernel%29'), 'Linux', null, 'black-text hoverable' ), $conference->getConferenceStart('d/m/Y'), $conference->getConferenceHumanStart() ) ?>

// How to write good code
$software: function(play, freedom, friends) { /* RTFM */ }

coding!") ?>

queryRow() ?>

getChapterName() ) ?>

{$eventsTable->countEvents()}", "{$eventsTable->getHours()}" ) ?>

{$eventsTable->countTracks()}" ) ?>

printTable(); ?>

<?= __(" />

LDTO Companion" ) ?>

F-Droid

getLocationName() ?>

getLocationNoteHTML(['p' => 'flow-text']) ?>
printLocationLeaflet() ?>

getLocationAddress() ?>

getLocationGeoOSM(), icon('place', 'right'), sprintf( __("Vedi %s su OpenStreetMap"), esc_html( $conference->getConferenceTitle() ) ), 'btn-floating btn-large purple darken-3 waves-effect', 'target="_blank"' ) ?>

<?php
 								__(" />

". "Non dimenticare di portarti a casa una maglietta o ". "qualche dozzina di adesivi e spille! ". "È il nostro modo per promuovere ulteriormente il software libero, ". "per far sì che altri Linux Day rimangano sempre indipendenti, liberi e gratuiti.
". "Ci vediamo il %s!" ), __("22 ottobre") ) ?>

false] ); diff --git a/2019/index.php b/2019/index.php index 9d2784d..0660111 100644 --- a/2019/index.php +++ b/2019/index.php @@ -1,387 +1,390 @@ . require 'load.php'; enqueue_js('jquery'); enqueue_js('typed'); enqueue_js('leaflet'); enqueue_js('leaflet.init'); enqueue_css('leaflet'); $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); -$conference or die_with_404(); +if( !$conference ) { + die_with_404(); +} -FORCE_PERMALINK - and $conference->forceConferencePermalink(); +if( FORCE_PERMALINK ) { + $conference->forceConferencePermalink(); +} template( 'header', [ 'conference' => $conference, 'intro' => true, ] ); ?>

aula base, l'aula per sistemisti o programmatori e divertiti!" ) ?>

getConferenceStart(); // query all the events that belongs to this conference // and that belongs to this chapter // order by date $events = FullEvent::factoryByConference( $conference->getConferenceID() ) ->whereStr( Track::UID, $track ) ->orderBy( Event::START, 'ASC' ) ->queryResults(); ?> get( Event::START ) ?>

getEventTitle() ) ?>

hasEventSubtitle() ): ?>

getEventSubtitle() ) ?>

 getEventStart( 'H:i' ) ?> (getHumanEventDuration( [ 'long' => false ] ) ?>)
 

hasEventAbstract() ): ?>

getEventAbstractHTML() ?>

 info

 

isEventEditable() ): ?> getFullEventEditURL(), __( "Modifica" ) ) ?>
add( $one_hour ); $last_event_end = clone $last_event_start; $last_event_end->add( $one_hour ); ?>

printLocationLeaflet() ?>

. trait ConferenceTrait { /** * Get conference ID * * @return int */ public function getConferenceID() { return $this->nonnull( Conference::ID ); } /** * Get conference UID * * @return string */ function getConferenceUID() { return $this->get( Conference::UID ); } /** * Get localized conference title * * @return string */ public function getConferenceTitle() { return __( $this->get( Conference::TITLE ) ); } - function getConferenceURL( $base = URL ) { - return $base . sprintf( PERMALINK_CONFERENCE, $this->getConferenceUID() ); + /** + * Get the Conference URL + * + * @param boolean $absolute Set to true to force an absolute URL + * @return string + */ + public function getConferenceURL( $absolute = false ) { + $url = sprintf( PERMALINK_CONFERENCE, $this->getConferenceUID() ); + return site_page( $url, $absolute ); } /** * Check if the Conference has URLs for every Event * * @return boolean */ public function hasConferenceEventsURL() { return $this->has( 'conference_events_url' ); } - function forceConferencePermalink() { - $url = $this->getConferenceURL( ROOT ); - if( $url !== $_SERVER['REQUEST_URI'] ) { - http_redirect( $url ); + /** + * Force this request to the correct Conference permalink + */ + public function forceConferencePermalink() { + $from = BASE_URL . $_SERVER['REQUEST_URI']; + $to = $this->getConferenceURL( true ); + if( $from !== $to ) { + http_redirect( $to, 303 ); } } function getConferenceHumanStart() { return HumanTime::diff( $this->getConferenceStart() ); } function getConferenceHumanEnd() { return HumanTime::diff( $this->getConferenceEnd() ); } /** * Get the Conference date start * * @param string $format If specified, return the formatted date * @return DateTime|string */ public function getConferenceStart( $format = null ) { $date = $this->get( 'conference_start' ); if( $format ) { return $date->format( $format ); } return $date; } /** * Get the Conference date end * * @param string $format If specified, return the formatted date */ public function getConferenceEnd( $format = null ) { $date = $this->get( 'conference_end' ); if( $format ) { return $date->format( $format ); } return $date; } /** * Get URL to trop-iCal API for this conference * * @param boolean $absolute Set to true for an absolute URL * @return string */ function getConferenceCalURL( $absolute = false ) { $conf = urlencode( $this->getConferenceUID() ); return site_page( "api/tropical.php?conference=$conf", $absolute ); } /** * Get localized conference description * * @return string */ public function getConferenceDescription() { return nl2br( __( $this->get( Conference::DESCRIPTION ) ) ); } /** * Get localized conference quote * * @return string */ public function getConferenceQuote() { return nl2br( __( $this->get( 'conference_quote' ) ) ); } /** * Get localized conference subtitle * * @return string */ public function getConferenceSubtitle() { return __( $this->get( Conference::SUBTITLE ) ); } /** * Factory a FullEvent by this conference * * @return Query */ public function factoryFullEventByConference() { return FullEvent::factoryByConference( $this->getConferenceID() ); } /** * Get the URL to create an Event in this Conference * * @param boolean $absolute Flag to have an absolute URL * @return string */ public function getURLToCreateEventInConference( $args = [], $absolute = false ) { $args['conference'] = $this->getConferenceUID(); return FullEvent::editURL( $args, $absolute ); } /** * Normalize a Conference object */ protected function normalizeConference() { $this->integers( Conference::ID, Conference::DAYS, Location::ID ); $this->datetimes( Conference::START, Conference::END ); } } /** * A Conference is an event in a certain Location */ class Conference extends Queried { use ConferenceTrait; /** * Database table name */ const T = 'conference'; /** * Conference ID column */ const ID = 'conference_ID'; /** * Conference UID column */ const UID = 'conference_uid'; /** * Conference title column */ const TITLE = 'conference_title'; /** * Subtitle column name */ const SUBTITLE = 'conference_subtitle'; /** * Description column name */ const DESCRIPTION = 'conference_description'; /** * Start column name */ const START = 'conference_start'; /** * End column name */ const END = 'conference_end'; /** * Acronym column name */ const ACRONYM = 'conference_acronym'; /** * Persons URL column name */ const PERSONS_URL = 'conference_persons_url'; /** * Events URL column name */ const EVENTS_URL = 'conference_events_url'; /** * Days column name */ const DAYS = 'conference_days'; /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Complete Location ID column name */ const LOCATION_ = self::T . DOT . Location::ID; /** * Maximum UID length * * @override */ const MAXLEN_UID = 32; /** * Constructor */ public function __construct() { $this->normalizeConference(); } } diff --git a/includes/class-FullEvent.php b/includes/class-FullEvent.php index c989aad..cbf48c9 100644 --- a/includes/class-FullEvent.php +++ b/includes/class-FullEvent.php @@ -1,213 +1,220 @@ . class_exists('Event'); class_exists('Conference'); class_exists('Location'); class_exists('Room'); class_exists('Chapter'); class_exists('Track'); trait FullEventTrait { /** * Check if the Event has a permalink * * @return bool */ public function hasEventPermalink() { return $this->has( Conference::UID ) && $this->has( Event ::UID ) && $this->has( Chapter ::UID ); } /** * Get the Event URL + * + * @param boolean $absolute Set to true to force an absolute URL + * @return string */ public function getEventURL( $absolute = false ) { return FullEvent::permalink( $this->getConferenceUID(), $this->getEventUID(), $this->getChapterUID(), $absolute ); } - function forceEventPermalink() { - $url = $this->getEventURL( ROOT ); - if( $url !== $_SERVER['REQUEST_URI'] ) { - http_redirect( $url ); + /** + * Force the current request to the correct Event permalink + */ + public function forceEventPermalink() { + $from = BASE_URL . $_SERVER['REQUEST_URI']; + $to = $this->getEventURL( true ); + if( $from !== $to ) { + http_redirect( $to, 303 ); } } /** * Create a Query to find the next Event in the same Room * * @return Query */ public function factoryNextFullEvent() { $date = $this->getEventEnd( 'Y-m-d H:i:s' ); return $this->factoryFullEventInSameContext() ->whereStr( 'event_start', $date, '>=' ) ->orderBy( 'event_start', 'ASC' ); } /** * Create a Query to find the previous Event in the same Room * * @return Query */ public function factoryPreviousFullEvent( $compare = '<=' ) { $date = $this->getEventStart( 'Y-m-d H:i:s' ); return $this->factoryFullEventInSameContext() ->whereStr( 'event_end', $date, '<=' ) ->orderBy( 'event_end', 'DESC' ); } /** * Get the edit URL for this FullEvent * * @param boolean $absolute Flag to require an absolute URL * @return string */ public function getFullEventEditURL( $absolute = false ) { return FullEvent::editURL( [ 'uid' => $this->getEventUID(), 'conference' => $this->getConferenceUID() ], $absolute ); } private function factoryFullEventInSameContext() { return FullEvent::factory() ->whereInt( 'event.conference_ID', $this->getConferenceID() ) ->whereInt( 'event.room_ID', $this->getRoomID() ); } } /** * An Event with all the bells and whistles */ class FullEvent extends Queried { use FullEventTrait; use EventTrait; use ConferenceTrait; use LocationTrait; use ChapterTrait; use RoomTrait; use TrackTrait; public function __construct() { $this->normalizeEvent(); $this->normalizeConference(); $this->normalizeChapter(); $this->normalizeRoom(); $this->normalizeTrack(); } /** * Query constructor * * @return Query */ public static function factory() { return Query::factory( __CLASS__ ) ->from( [ Event ::T, Conference::T, Room ::T, Track ::T, Chapter ::T, ] ) ->equals( Event::CONFERENCE_, Conference::ID_ ) ->equals( Event::ROOM_, Room ::ID_ ) ->equals( Event::TRACK_, Track ::ID_ ) ->equals( Event::CHAPTER_, Chapter ::ID_ ); } static function factoryByConference( $conference_ID ) { return self::factory() ->whereInt( Event::CONFERENCE_, $conference_ID ); } /** * @deprecate Use self::factoryFromConferenceAndUID() instead */ static function factoryByConferenceAndUID( $conference_ID, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } /** * Factory from a Conference object and the Event UID * * @param object $conference * @param string $event_uid * @return Query */ public static function factoryFromConferenceAndEventUID( $conference, $event_uid ) { $event_uid = Event::sanitizeUID( $event_uid ); $conference_ID = $conference->getConferenceID(); return self::factoryByConference( $conference_ID ) ->whereStr( Event::UID, $event_uid ); } static function queryByConferenceAndUID( $conference_ID, $event_uid ) { return self::factoryByConferenceAndUID( $conference_ID, $event_uid ) ->queryRow(); } static function factoryByUser( $user_ID ) { return self::factory() ->from( EventUser::T ) ->equals( EventUser::EVENT_, Event::ID_ ) ->whereInt( EventUser::USER_, $user_ID ) ->orderBy( EventUser::ORDER ); } static function factoryByConferenceChapter( $conference_ID, $chapter_ID ) { return self::factoryByConference( $conference_ID ) ->whereInt( Event::CHAPTER_, $chapter_ID ); } /** * Get an absolute FullEvent permalink * * @param $conference_uid string Conference UID * @param $event_uid string Event UID * @param $chapter_uid string Chapter UID * @param string $absolute Force an absolute URL * @return string */ public static function permalink( $conference_uid, $event_uid, $chapter_uid, $absolute = false ) { $url = sprintf( PERMALINK_EVENT, $conference_uid, $event_uid, $chapter_uid ) ; return site_page( $url, $absolute ); } /** * Get the edit URL to a FullEvent * * @param array $args Arguments for the edit page * @param boolean $absolute Flag to require an absolute URL * @return string */ public static function editURL( $args, $absolute = false ) { $url = http_build_get_query( '/2016/event-edit.php', $args ); return site_page( $url, $absolute ); } } diff --git a/includes/class-User.php b/includes/class-User.php index 5323c86..320b6cc 100644 --- a/includes/class-User.php +++ b/includes/class-User.php @@ -1,424 +1,437 @@ . trait UserTrait { /** * Get the user ID * * @return int */ public function getUserID() { return $this->nonnull( User::ID ); } /** * Get the user UID * * @return string */ public function getUserUID() { return $this->get( User::UID ); } /** * Get the user e-mail * * @return string */ public function getUserEmail() { return $this->get( User::EMAIL ); } /** * Check if the user is public * * @return bool */ public function isUserPublic() { return $this->get( User::IS_PUBLIC ); } /** * Check if I can see this user * * @return bool */ public function isUserVisible() { return $this->isUserPublic() || $this->isUserMyself(); } /** * Get the user full name * * @return string */ public function getUserFullname() { return sprintf( __("%s %s"), $this->get( User::NAME ), $this->get( User::SURNAME ) ); } - function getUserURL( $base = ROOT ) { - return $base . sprintf( PERMALINK_USER, + /** + * Get the User URL + * + * The User URL is based on the CURRENT_CONFERENCE_UID. + * + * @param boolean $absolute Set to true to force an absolute URL + * @return string + */ + public function getUserURL( $absolute = false ) { + $url = sprintf( PERMALINK_USER, CURRENT_CONFERENCE_UID, $this->getUserUID() ); + return site_page( $url, $absolute ); } - function forceUserPermalink() { - $url = $this->getUserURL( ROOT ); - if( $url !== $_SERVER['REQUEST_URI'] ) { - http_redirect( $url ); + /** + * Force this request to the correct User permalink + */ + public function forceUserPermalink() { + $from = BASE_URL . $_SERVER['REQUEST_URI']; + $to = $this->getUserURL( true ); + if( $from !== $to ) { + http_redirect( $to, 303 ); } } function getUserLink( $base = null, $html_class = null) { $name = $this->getUserFullname(); return HTML::a( $this->getUserURL( $base ), - $name, + esc_html( $name ), sprintf( __("Profilo utente di %s"), $name ), $html_class ); } /** * Check if the User has a Gravatar image * * @return int */ public function hasUserGravatar() { return $this->has( User::GRAVATAR ) || $this->has( User::EMAIL ); } /** * Get the md5 of the E-mail * * @return string|null */ public function getUserGravatarUID() { $gravatar = $this->get( User::GRAVATAR ); return $gravatar ? $gravatar : md5( $this->getUserEmail() ); } /** * Check if the User has an image * * @return boolean */ public function hasUserImage() { return $this->has( User::IMAGE ) || $this->has( User::GRAVATAR ); } /** * Get the URL of the user image * * @param int $size Suggested width * @param boolean $absolute Set true to force an absolute URL * @return string */ public function getUserImage( $size = 256, $absolute = false ) { $image = $this->get( User::IMAGE ); if( ! $image ) { $image = 'https://www.gravatar.com/avatar/' . $this->getUserGravatarUID() . '?s=' . $size; } return site_page( $image, $absolute ); } /** * It has an user bio? * * @return bool */ public function hasUserBio() { return null !== $this->get('user_bio'); } function getUserBio() { return $this->get('user_bio'); } function getUserBioHTML($args = []) { return Markdown::parse( __( $this->getUserBIO() ), $args); } /** * Check if the user is somehow social * * @return bool */ public function isUserSocial() { foreach( User::allSocialFields() as $field ) { if( $this->has( $field ) ) { return true; } } return false; } /** * Get the user Facebook profile URL * * @return string URL */ public function getUserFacebruck() { return 'https://facebook.com/' . $this->get( User::FACEBOOK ); } /** * Get the user Google+ profile URL * * @return string URL */ public function getUserGuggolpluz() { return 'https://plus.google.com/' . $this->get( User::GOOGLE_PLUS ); } /** * Get the user Twitter profile URL * * @return string URL */ public function getUserTuitt() { return 'https://twitter.com/' . $this->get( User::TWITTER ); } /** * Get the user Linkedin profile URL * * @return string URL */ public function getUserLinkeddon() { return 'https://www.linkedin.com/in/' . $this->get( User::LINKEDIN ); } /** * Get the user GitHub profile URL * * @return string URL */ public function getUserGithubbo() { return 'https://github.com/' . $this->get( User::GITHUB ); } /** * Get the edit URL to this user * * @return string */ public function getUserEditURL() { $url = http_build_get_query( '2016/user-edit.php', [ 'uid' => $this->getUserUID(), ] ); return site_page( $url ); } /** * Can you edit this user? * * @return bool */ public function hasPermissionToEditUser() { if( has_permission('edit-users') ) { return true; } if( has_permission('edit-account') && $this->isUserMyself() ) { return true; } return false; } /** * Is this user myself? * * @return bool */ public function isUserMyself() { return is_logged() && get_user()->getUserID() === $this->getUserID(); } /** * Check if the User has a loved license * * @return */ public function hasUserLovelicense() { return $this->has( User::LOVED_LICENSE ); } /** * Get the User loved license * * @return License */ public function getUserLovelicense() { return license( $this->get( User::LOVED_LICENSE ) ); } function factoryUserSkills() { return UserSkill::factorySkillByUser( $this->getUserID() ); } function factoryUserEvents() { return FullEvent::factoryByUser( $this->getUserID() ); } /** * Normalize a User object */ protected function normalizeUser() { $this->integers( User::ID ); $this->booleans( User::IS_PUBLIC, User::IS_ACTIVE ); } } class User extends Sessionuser { use UserTrait; /** * Name column */ const NAME = 'user_name'; /** * Aristocratic title column */ const ARISTOCRATIC_TITLE = 'user_title'; /** * ID column */ const SURNAME = 'user_surname'; /** * He/she public column */ const IS_PUBLIC = 'user_public'; /** * Image column */ const IMAGE = 'user_image'; /** * E-mail */ const EMAIL = 'user_email'; /** * Gravatar column */ const GRAVATAR = 'user_gravatar'; /** * RSS column */ const RSS = 'user_rss'; /** * Facebook username column */ const FACEBOOK = 'user_fb'; /** * Linkedin username column */ const LINKEDIN = 'user_lnkd'; /** * Google+ username column */ const GOOGLE_PLUS = 'user_googl'; /** * Twitter username */ const TWITTER = 'user_twtr'; /** * GitHub username */ const GITHUB = 'user_github'; /** * Personal website column */ const WEBSITE = 'user_site'; /** * Loved license column */ const LOVED_LICENSE = 'user_lovelicense'; /** * Biography column */ const BIO = 'user_bio'; /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Maximum UID length */ const MAXLEN_UID = 20; /** * Constructor */ public function __construct() { $this->normalizeUser(); } /** * Get all the user social fields * * @return array */ public static function allSocialFields() { return [ User::RSS, User::FACEBOOK, User::LINKEDIN, User::GOOGLE_PLUS, User::TWITTER, User::GITHUB, ]; } /** * Factory users by an event * * @param $event_ID int * @return Query */ public static function factoryByEvent( $event_ID ) { return self::factory() ->from('event_user') ->equals('event_user.user_ID', 'user.user_ID') ->whereInt('event_user.event_ID', $event_ID ); } } diff --git a/includes/load-post.php b/includes/load-post.php index cc6bae9..847b686 100644 --- a/includes/load-post.php +++ b/includes/load-post.php @@ -1,110 +1,110 @@ . // 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/' ); +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( '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_default_language( 'it_IT' ); // apply the global timezone date_default_timezone_set( DEFAULT_TIMEZONE ); // apply a language if( isset( $_GET[ 'l' ] ) ) { // for this request only apply_language( $_GET[ 'l' ] ); } elseif( isset( $_POST[ 'l' ] ) ) { if( false !== apply_language( $_POST[ 'l' ] ) ) { // also for future requests setcookie( 'l', latest_language()->getCode() ); } } else { // when the cookie is empty is taken from browser language apply_language( @ $_COOKIE[ 'l' ] ); }