diff --git a/2016/event.php b/2016/event.php index a9143d1..d4f69aa 100644 --- a/2016/event.php +++ b/2016/event.php @@ -1,358 +1,354 @@ . require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); if( !$conference ) { die_with_404(); } if( !isset( $_GET['uid'] ) ) { die_with_404(); } $event = FullEvent::factoryByConferenceAndUID( $conference->getConferenceID(), $_GET['uid'] )->queryRow(); if( !$event ) { die_with_404(); } -if( FORCE_PERMALINK ) { - $event->forceEventPermalink(); -} - $args = [ 'title' => sprintf( __("%s: %s"), $event->getChapterName(), $event->getEventTitle() ), 'url' => $event->getEventURL( true ), ]; if( $event->hasEventImage() ) { $args['og'] = [ 'image' => $event->getEventImage( true ), ]; } // Adding subscribers $subscribed = null; if( isset( $_POST['subscription_email'] ) && $event->areEventSubscriptionsAvailable() ) { $email = $_POST['subscription_email']; if( filter_var($email, FILTER_VALIDATE_EMAIL) ) { $event->addSubscription($email); $args['alert'] = __("Grazie per esserti iscritto."); $args['alert.type'] = Messagebox::INFO; $subscribed = true; } else { $args['alert'] = __("E-mail non valida."); $args['alert.type'] = Messagebox::ERROR; $subscribed = false; } } Header::spawn( null, $args ); ?> isEventEditable() ): ?>

getFullEventEditURL(), __("Modifica evento") . icon('edit', 'left') ) ?>

<?= esc_attr( $event->getEventTitle() ) ?>
getTrackName() ?>
getTrackLabel() ?>
getRoomName() ?>
@ getLocationGeoOSM(), $conference->getLocationName(), $conference->getLocationAddress(), null, 'target="_blank"' ) ?>
getLocationAddress() ?>
getEventHumanStart() ?>
getEventStart('d/m/Y'), $event->getEventStart('H:i') ) ?>
getEventCalURL(), __( "Scarica promemoria calendario" ) ) ?>
hasEventAbstract() ): ?>

getEventAbstractHTML( ['p' => 'flow-text'] ) ?>
hasEventDescription() ): ?>

getEventDescriptionHTML( ['p' => 'flow-text'] ) ?>
areEventSubscriptionsAvailable() ): ?>

hasEventNote() ): ?>

getEventNoteHTML( ['p' => 'flow-text'] ) ?>
factorySharebleByEvent() ->queryGenerator(); ?> valid() ): ?>

isSharableDownloadable() ): ?>

getSharablePath(), icon('attachment', 'left') . $sharable->getSharableTitle(['prop' => true]), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

isSharableVideo() ): ?>

getSharablePath(), icon('share', 'left') . $sharable->getSharableTitle( ['prop' => true] ), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

factoryUserByEvent() ->queryGenerator(); ?> valid() ): ?>
getUserURL(), "

" . esc_html( $user->getUserFullname() ) . "

", sprintf( __("Profilo di %s"), $user->getUserFullname() ), 'valign' ) ?>

factoryPreviousFullEvent() ->select('event_uid', 'event_title', 'chapter_uid', 'conference_uid', 'event_start') ->limit(1) ->queryRow(); $next = $event->factoryNextFullEvent() ->select('event_uid', 'event_title', 'chapter_uid', 'conference_uid', 'event_start') ->limit(1) ->queryRow(); ?>

getEventURL(), esc_html( $previous->getEventTitle() ) ) ?>

getEventURL(), esc_html( $next->getEventTitle() ) ) ?>

. class Footer { static function spawn( $args = [] ) { $args = array_replace( [ 'home' => true ], $args ); ?>
. /** * Header of the website */ class Header { /** * Spawn the header * * @param $menu_uid string Menu entry UID (if any) or page title * @param $args array Header arguments */ static function spawn( $menu_uid = null, $args = [] ) { $menu = $menu_uid ? menu_entry( $menu_uid ) : null; $args = array_replace( [ 'show-title' => true, 'nav-title' => SITE_NAME_SHORT, 'head-title' => null, 'title' => $menu ? $menu->name : null, - 'url' => $menu ? $menu->url : null, + 'url' => $menu ? keep_url_in_language( $menu->url ) : null, 'not-found' => false, 'user-navbar' => true, 'container' => true, 'alert' => null, 'alert.type' => null, 'noindex' => NOINDEX ], $args ); if( ! isset( $args['og'] ) ) { $args['og'] = []; } $args['og'] = array_replace( [ 'image' => STATIC_URL . '/ld-2016-logo-purple.png', // It's better an absolute URL here 'type' => 'website', 'url' => $args['url'], 'title' => $args['title'] ], $args['og'] ); if( $args['head-title'] === null ) { $args['head-title'] = sprintf( __("%s - %s"), $args['title'], $args['nav-title'] ); } + // force the permalink to this URL + if( $args['url'] && FORCE_PERMALINK ) { + force_permalink( $args['url'] ); + } + header('Content-Type: text/html; charset=' . CHARSET); if( $args['not-found'] ) { header('HTTP/1.1 404 Not Found'); } enqueue_css('materialize'); enqueue_css('materialize.custom'); enqueue_css('materialize.icons'); enqueue_js('jquery'); enqueue_js('materialize'); // Close header - Start $args['container'] && inject_in_module('footer', function() { ?> getISO(); ?> <?= $args['head-title'] ?> $value): ?>
<?php echo __(">

. require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); if( !$conference ) { die_with_404(); } -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" ) ?>

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/2016/user.php b/2016/user.php index d41b34c..a650bc0 100644 --- a/2016/user.php +++ b/2016/user.php @@ -1,289 +1,285 @@ . require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); $conference or die_with_404(); $user = User::factoryByUID( $_GET['uid'] ) ->select( [ User::ID, User::UID, User::GRAVATAR, User::NAME, User::SURNAME, User::IMAGE, User::WEBSITE, User::LOVED_LICENSE, User::BIO_L10N(), ] ) ->select( User::allSocialFields() ) ->queryRow(); if( !$user ) { die_with_404(); } -if( FORCE_PERMALINK ) { - $user->forceUserPermalink(); -} - Header::spawn( null, [ 'title' => $user->getUserFullname(), 'url' => $user->getUserURL(), 'og' => [ 'image' => $user->hasUserImage() ? $user->getUserImage() : null, 'type' => 'profile', 'profile:first_name' => $user->user_name, 'profile:last_name' => $user->user_surname ] ] ); ?> hasPermissionToEditUser() ): ?>

getUserUID()}", __("Modifica") . icon('edit', 'left') ) ?>

user_site ): ?>

user_site, __("Sito personale") . icon('contact_mail', 'right'), null, 'btn waves-effect purple darken-2', 'target="_blank"' ) ?>

factoryUserSkills() ->queryGenerator(); ?> valid() ): ?>

getSkillCode() ) ?>
hasUserLovelicense() ): ?>
getUserLovelicense() ?>

" . $license->getLink() . "" ) ?>

hasUserBio() ): ?>

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

whereConference( $conference ) ->whereUser( $user ) ->joinTrackChapterRoom() ->queryGenerator(); ?> valid() ): ?>
getEventURL(), sprintf( "%s", esc_html( $title = $event->getEventTitle() ) ), sprintf( __("Vedi %s"), $title ) ) ?> getChapterName() ) ?> getTrackName() ) ?> getLocationName() ) ?>
getRoomName() ) ?>
%s (il %s)"), $event->getEventStart("H:i"), $event->getEventStart("d/m/Y") ) ?>
getEventHumanStart() ?>

joinConference() ->joinLocation() ->joinChapter() ->joinEventUser() ->whereConferenceNot( $conference ) ->whereUser( $user ) ->orderBy( Event::START, 'DESC' ) ->queryGenerator(); ?> valid() ): ?>

hasConferenceEventsURL() ) { // print the Event permalink echo HTML::a( $event->getEventURL(), esc_html( $event->getEventTitle() ) ); } else { // just print the Event title echo esc_html( $event->getEventTitle() ); } ?> getConferenceTitle() ) ?> getLocationName() ) ?>
%s (il %s)"), $event->getEventStart("H:i"), $event->getEventStart("d/m/Y") ) ?>
getEventHumanStart() ?>
isUserSocial() ): ?>

has( User::RSS ) and SocialBox::spawn( $user, "RSS", $user->get( User::RSS ), 'home.png' ); $user->has( User::FACEBOOK ) and SocialBox::spawn( $user, "Facebook", $user->getUserFacebruck(), 'facebook_logo.png' ); $user->has( User::GOOGLE_PLUS ) and SocialBox::spawn( $user, "Google+", $user->getUserGuggolpluz(), 'google.png' ); $user->has( User::TWITTER ) and SocialBox::spawn( $user, "Twitter", $user->getUserTuitt(), 'twitter.png' ); $user->has( User::LINKEDIN ) and SocialBox::spawn( $user, "Linkedin", $user->getUserLinkeddon(), 'linkedin.png' ); $user->has( User::GITHUB ) and SocialBox::spawn( $user, "Github", $user->getUserGithubbo(), 'github.png' ); ?>
. require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); if( !$conference ) { die_with_404(); } $event = FullEvent::factoryByConferenceAndUID( $conference->getConferenceID(), @ $_GET['uid'] )->queryRow(); if( !$event ) { die_with_404(); } -if( FORCE_PERMALINK ) { - $event->forceEventPermalink(); -} - $args = [ 'conference' => $conference, 'title' => sprintf( __("%s: %s"), $event->getChapterName(), $event->getEventTitle() ), - 'url' => $event->getEventURL() + 'canonical' => $event->getEventURL( true ), ]; if( $event->hasEventImage() ) { $args['og'] = [ 'image' => $event->getEventImage( true ), ]; } template( 'header', $args ); ?>

getEventTitle() ) ?>

isEventEditable() ): ?>

getFullEventEditURL(), __("Modifica") . icon('edit', 'left') ) ?>

<?= esc_attr( $event->getEventTitle() ) ?>
getTrackName() ?>
getTrackLabel() ?>
getRoomName() ?>
@ getLocationGeoOSM(), esc_html( $conference->getLocationName() ), $conference->getLocationAddress(), null, 'target="_blank"' ) ?>
getLocationAddress() ) ?>
getEventHumanStart() ?>
getEventStart('d/m/Y'), $event->getEventStart('H:i') ) ?>
getEventCalURL(), __( "Scarica promemoria calendario" ) ) ?>
hasEventAbstract() ): ?>

getEventAbstractHTML( ['p' => 'flow-text'] ) ?>
hasEventDescription() ): ?>

getEventDescriptionHTML( ['p' => 'flow-text'] ) ?>
hasEventNote() ): ?>

getEventNoteHTML( ['p' => 'flow-text'] ) ?>
factorySharebleByEvent() ->queryGenerator(); ?> valid() ): ?>

isSharableDownloadable() ): ?>

getSharablePath(), icon('attachment', 'left') . $sharable->getSharableTitle(['prop' => true]), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

isSharableVideo() ): ?>

getSharablePath(), icon('share', 'left') . $sharable->getSharableTitle( ['prop' => true] ), null, null, 'target="_blank"' ), $sharable->getSharableLicense()->getLink() ) ?>

factoryUserByEvent() ->queryGenerator(); ?> valid() ): ?>
-
+
- getUserURL(), "

" . esc_html( $user->getUserFullname() ) . "

", sprintf( __("Profilo di %s"), $user->getUserFullname() - ), - 'valign' - ) ?> + ) + ) ?>

factoryPreviousFullEvent() ->limit( 1 ) ->queryRow(); $next = $event->factoryNextFullEvent() ->limit( 1 ) ->queryRow(); ?>

getEventURL(), esc_html( $previous->getEventTitle() ) ) ?>

getEventURL(), esc_html( $next->getEventTitle() ) ) ?>

true, ] ); diff --git a/2019/index.php b/2019/index.php index 3c5a6d4..4befca4 100644 --- a/2019/index.php +++ b/2019/index.php @@ -1,390 +1,387 @@ . 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(); if( !$conference ) { die_with_404(); } -if( FORCE_PERMALINK ) { - $conference->forceConferencePermalink(); -} - template( 'header', [ 'conference' => $conference, 'intro' => true, + 'canonical' => $conference->getConferenceURL( 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() ?>

. /* * This is the header of the website */ /* * Args that should be passed: * * $conference (object) Current conference * $intro (true|undefined) If true, you want that damn splash screen + * $og (array) OG meta tags + * $canonical (string) Canonical link tag */ // do not visit directly defined( 'ABSPATH' ) or exit; +// canonical URL +$canonical = isset( $canonical ) ? $canonical : null; + +// if the canonical is specified, and we have to force the permalink, force that damn permalink +if( $canonical && FORCE_PERMALINK ) { + force_permalink( $canonical ); +} + // as default declare empty OG Meta tags if( ! isset( $args['og'] ) ) { $args['og'] = []; } // set default OG Meta tags $args['og'] = array_replace( [ + 'url' => $canonical, 'image' => CURRENT_CONFERENCE_URL . '/images/linux-day-2019.png', // It's better an absolute URL here 'type' => 'website', 'title' => $conference->getConferenceTitle(), ], $args['og'] ); // TODO: move the define somewhere else (per-year, not a global parameter for every site across all years) define('DEFAULT_LANGUAGE_ISO', 'it'); // I assume that latest_language()->getISO() does not return different codes for the same language: // e.g. it should return ONLY it_IT OR it, not "it_IT" some times and "it" some others // this does not appear to be the case and it breaks everything completely. // l is either given in the request or implicit $l = $_GET['l'] ?? latest_language()->getISO(); // From the manual: "This function may not give correct results for relative URLs." // Then build a full URL! $parsed = parse_url("https://${_SERVER['HTTP_HOST']}${_SERVER['REQUEST_URI']}"); if(isset($parsed["query"])) { parse_str($parsed["query"], $query); } else { $query = []; } if($l === DEFAULT_LANGUAGE_ISO) { // Remove the ugly l if(isset($_GET['l'])) { unset($query["l"]); } // are there any remaining query parameters? if(count($query) > 0) { $query = '?' . http_build_query($query); } else { $query = ''; } // l was there: redirect to page without l (or remove this "if" to get a canonical URL without l) if(isset($_GET['l'])) { // TODO: change to 301 when we're sure header("Location: ${parsed['path']}$query", true, 302); exit(0); } } else { // Other languages need the l for the canonical URL $query["l"] = $l; $query = '?' . http_build_query($query); } $canonical = "https://${_SERVER['HTTP_HOST']}${parsed['path']}$query"; ?> <?= esc_html( $conference->getConferenceTitle() ) ?> "> + + + + $value ): ?> $conference, 'top_nav_collapse' => !isset( $intro ), ] ); if( isset( $intro ) ) { template( 'intro' ); } diff --git a/2019/template/navbar-home.php b/2019/template/navbar-home.php index 9e001e2..dd755d5 100644 --- a/2019/template/navbar-home.php +++ b/2019/template/navbar-home.php @@ -1,60 +1,75 @@ . /* * This is the navbar of the website */ /* * Args that should be passed: * * $conference (object) Current conference */ // do not visit directly defined( 'ABSPATH' ) or exit; $home = keep_url_in_language( CURRENT_CONFERENCE_ROOT . _ ); +// get the current URL but without the query string (without the language) +$current_url = $_SERVER['REQUEST_URI']; +$current_url = strtok( $current_url, '?' ); + $classes = $top_nav_collapse ? 'top-nav-collapse' : 'navbar-fixed-top'; ?> diff --git a/2019/user.php b/2019/user.php index 33e16f7..d03a796 100644 --- a/2019/user.php +++ b/2019/user.php @@ -1,316 +1,312 @@ . require 'load.php'; $conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) ->queryRow(); if( !$conference ) { die_with_404(); } $user = User::factoryByUID( $_GET['uid'] ) ->select( [ User::ID, User::UID, User::GRAVATAR, User::NAME, User::SURNAME, User::IMAGE, User::WEBSITE, User::LOVED_LICENSE, User::BIO_L10N(), ] ) ->select( User::allSocialFields() ) ->queryRow(); if( !$user ) { die_with_404(); } -if( FORCE_PERMALINK ) { - $user->forceUserPermalink(); -} - enqueue_js('jquery'); template( 'header', [ 'conference' => $conference, 'title' => $user->getUserFullname(), + 'canonical' => $user->getUserURL( true ), 'og' => [ 'image' => $user->getUserImage( true ), - 'url' => $user->getUserURL( true ), 'type' => 'profile', 'profile:first_name' => $user->get( 'user_name' ), 'profile:last_name' => $user->get( 'user_surname' ), ] ] ); ?>

getUserFullName() ) ?>

hasPermissionToEditUser() ): ?>

getUserUID()}", __("Modifica") . icon('edit', 'left') ) ?>

has( User::WEBSITE ) ): ?> <?= esc_html(
 								$user->getUserFullname()
 							) ?> has( User::WEBSITE ) ): ?>
user_site ): ?>

user_site, __("Sito personale") . icon('inbox', 'right'), null, 'btn waves-effect purple darken-2', 'target="_blank"' ) ?>

factoryUserSkills() ->queryGenerator(); ?> valid() ): ?>

getSkillCode() ) ?>
hasUserLovelicense() ): ?>
getUserLovelicense() ?>

%s."), $license->getLink() ) ?>

hasUserBio() ): ?>

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

whereConference( $conference ) ->whereUser( $user ) ->joinTrackChapterRoom() ->queryGenerator(); ?> valid() ): ?>
getEventURL(), sprintf( "%s", esc_html( $title = $event->getEventTitle() ) ), sprintf( __("Vedi %s"), $title ) ) ?> getChapterName() ) ?> getTrackName() ) ?> getLocationName() ) ?>
getRoomName() ) ?>
%s (il %s)"), $event->getEventStart("H:i"), $event->getEventStart("d/m/Y") ) ?>
getEventHumanStart() ?>

joinConference() ->joinLocation() ->joinChapter() ->whereUser( $user ) ->whereConferenceNot( $conference ) ->orderBy( Event::START, 'DESC' ) ->queryGenerator(); ?> valid() ): ?>

- +
hasConferenceEventsURL() ) { // print the Event permalink echo HTML::a( $event->getEventURL(), esc_html( $event->getEventTitle() ) ); } else { // just print the Event title echo esc_html( $event->getEventTitle() ); } ?>getConferenceTitle() ) ?>getConferenceURL(), + esc_html( $event->getConferenceTitle() ) + ) ?> getLocationName() ) ?>
- %s (il %s)"), - $event->getEventStart("H:i"), - $event->getEventStart("d/m/Y") - ) ?>
+ getEventStart( __( "d/m/Y" ) ) ) ?> +
getEventHumanStart() ?>
isUserSocial() ): ?>

has( User::RSS ) and UserSocialBox::spawn( $user, "RSS", $user->get( User::RSS ), 'home.png' ); $user->has( User::FACEBOOK ) and UserSocialBox::spawn( $user, "Facebook", $user->getUserFacebruck(), 'facebook_logo.png' ); $user->has( User::GOOGLE_PLUS ) and UserSocialBox::spawn( $user, "Google+", $user->getUserGuggolpluz(), 'google.png' ); $user->has( User::TWITTER ) and UserSocialBox::spawn( $user, "Twitter", $user->getUserTuitt(), 'twitter.png' ); $user->has( User::LINKEDIN ) and UserSocialBox::spawn( $user, "Linkedin", $user->getUserLinkeddon(), 'linkedin.png' ); $user->has( User::GITHUB ) and UserSocialBox::spawn( $user, "Github", $user->getUserGithubbo(), 'github.png' ); ?>
true, ] ); diff --git a/documentation/apache/htaccess.conf b/documentation/apache/htaccess.conf index a47bfee..27eca10 100644 --- a/documentation/apache/htaccess.conf +++ b/documentation/apache/htaccess.conf @@ -1,38 +1,39 @@ RewriteBase / RewriteEngine on # I'm pretty sure that I could use the [OR]... but it does not work a fuck! RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] #RewriteCond %{REQUEST_FILENAME} -d #RewriteRule ^ - [L] RewriteCond %{REQUEST_FILENAME} -l RewriteRule ^ - [L] # Skip Apache aliases # javascript is from the `libjs-jquery` package # icons is from Apache RewriteRule ^javascript - [L] RewriteRule ^icons - [L] # Skip DirectoryIndex (add other files if you have it) RewriteRule index.php$ - [L] # xml API to current year schedule RewriteRule ^xml/?$ /api/tagliatella.php [L,PT] # The user page RewriteRule ^([0-9]{4})/user/([\w.-]+)/?$ /$1/user.php?conference=$1&uid=$2 [L,QSA] -# \ / -# °-------> user_uid <-------------° +# \ \ / / +# \ °-------> user_uid <------------- /------° +# °----------------------> conference_uid <-------° # The chapter uid is only for SEO RewriteRule ^([0-9]{4})/([\w.-]+)/([\w.-]+)/?$ /$1/event.php?conference=$1&chapter=$2&uid=$3 [L,QSA] # \ \ \ / / / # \ \ °--> event_uid <------------------/----------/-------° # \ °-----------> chapter_uid <---------------/----------° # °---------------------> conference_uid <-----------° diff --git a/includes/class-Conference.php b/includes/class-Conference.php index 1ecdea7..9f59834 100644 --- a/includes/class-Conference.php +++ b/includes/class-Conference.php @@ -1,273 +1,278 @@ . 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 ) ); } /** * 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() ); $url = site_page( $url, $absolute ); - return keep_url_in_language( $url ); + if( $this->hasConferenceI18nSupport() ) { + $url = keep_url_in_language( $url ); + } + return $url; } /** * Check if the Conference has URLs for every Event * * @return boolean */ public function hasConferenceEventsURL() { return $this->has( 'conference_events_url' ); } - /** - * Force this request to the correct Conference permalink - */ - public function forceConferencePermalink() { - force_permalink( $this->getConferenceURL( true ) ); - } - 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; } + /** + * Check if this Conference has the internationalization support + * + * @return boolean + */ + public function hasConferenceI18nSupport() { + return $this->hasConferenceEventsURL(); + } + /** * 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 e1add95..6baf41b 100644 --- a/includes/class-FullEvent.php +++ b/includes/class-FullEvent.php @@ -1,217 +1,210 @@ . 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 ); } - /** - * Force the current request to the correct Event permalink - */ - public function forceEventPermalink() { - force_permalink( $this->getEventURL( true ) ); - } - /** * 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 ) ; $url = site_page( $url, $absolute ); return keep_url_in_language( $url ); } /** * 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 33ca10c..9573bf1 100644 --- a/includes/class-User.php +++ b/includes/class-User.php @@ -1,442 +1,435 @@ . 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 ) ); } /** * 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() ); $url = site_page( $url, $absolute ); return keep_url_in_language( $url ); } - /** - * Force this request to the correct User permalink - */ - public function forceUserPermalink() { - force_permalink( $this->getUserURL( true ) ); - } - function getUserLink( $base = null, $html_class = null) { $name = $this->getUserFullname(); return HTML::a( $this->getUserURL( $base ), 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() { return $this->get( User::GRAVATAR ); } /** * 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 = 64; /** * 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 ); } /** * Generate the appropriate SELECT for the User Bio * * @return string */ public static function BIO_L10N() { return i18n_coalesce( 'user_bio', 'user_bio_%s' ); } } diff --git a/includes/functions.php b/includes/functions.php index 44e3a88..055f436 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,101 +1,105 @@ . 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' * @return string */ function i18n_coalesce( $name, $i18n ) { // current language (e.g. 'en') $lang = latest_language()->getISO(); // default language of the website $default = 'it'; // 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 + : 300; // 300 Multiple Choices + // redirect to the correct location - http_redirect( $permalink, 303 ); + 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 = false ) { +function keep_url_in_language( $url ) { - if( isset( $_GET['l'] ) || $force ) { - $url = http_build_get_query( $url, [ - 'l' => latest_language()->getCode(), - ] ); - } + $code = latest_language()->getCode(); + $url = http_build_get_query( $url, [ + 'l' => latest_language()->getISO(), + ] ); return $url; } diff --git a/index.php b/index.php index 3b7ac7e..ccd6f82 100644 --- a/index.php +++ b/index.php @@ -1,21 +1,21 @@ . require 'load.php'; -// redirect to latest conference with a temporary redirect -http_redirect( _ . LATEST_CONFERENCE_UID, 307 ); +// redirect to latest conference with a 300 Multiple Choices redirect +http_redirect( _ . LATEST_CONFERENCE_UID, 300 );