diff --git a/admin/conference.php b/admin/conference.php new file mode 100644 index 0000000..3b2a57a --- /dev/null +++ b/admin/conference.php @@ -0,0 +1,211 @@ +. + +require 'load.php'; + +// check if you can see the backend +require_permission( 'backend' ); + +// current Conference infos +$conference = null; +$conference_ID = null; + +// known text fields +$TEXT_FIELDS = [ + Conference::TITLE => __( "Titolo" ), + Conference::ACRONYM => __( "Titolo breve" ), + Conference::SUBTITLE => __( "Sottotitolo" ), + Conference::UID => __( "Codice" ), + Conference::EVENTS_URL => __( "URL Eventi" ), + Conference::PERSONS_URL => __( "URL Utenti" ), + Conference::START => __( "Inizio" ) . ' YYYY-MM-DD HH:ii:ss', + Conference::END => __( "Fine" ) . ' YYYY-MM-DD HH:ii:ss', +]; + +// check if we should create a new Conference +if( isset( $_GET['create'] ) || isset( $_POST['create'] ) ) { + + // check if you can create a new Conference + require_permission( 'add-conference' ); + +// check if we are editing an already existing Conference +} else { + + // check the current Conference + $conference_ID = $_GET['id'] ?? $_POST['id'] ?? 0; + + // check if the ID has sense + if( !$conference_ID ) { + error_die( "missing conference id" ); + } + + // query the Conference + $conference = ( new QueryConference() ) + ->whereConferenceID( $conference_ID ) + ->queryRow(); + + // no Conference no party + if( !$conference ) { + + // I do not want to spend so much time for this + http_response_code( 404 ); + echo "Missing Conference"; + exit; + + } + + // check if I'm allowed to edit this conference + if( !$conference->isConferenceEditable() ) { + + // no way + missing_privileges(); + } +} + +// check if you want to save the Conference +if( is_action( 'save-conference' ) ) { + + // receive data to be saved + $data = []; + foreach( $TEXT_FIELDS as $field => $label ) { + + // something can be missing + $value = $_POST[ $field ] ?? ''; + + // cast everything to string + // note that it will be escaped later by the Query class + $data[ $field ] = (string) $value; + } + + // prepare to query + $query = new QueryConference(); + + // here the user pressed the 'Save' button + if( $conference ) { + + // save existing + $query->whereConference( $conference ) + ->update( $data ); + } else { + + // create a new one + $query->insertRow( $data ); + + // gotcha! + $conference_ID = last_inserted_ID(); + } + + // POST -> redirect -> GET + http_redirect( Conference::editURL( [ + 'id' => $conference_ID, + ] ) ); +} + +// events list +$events = []; +if( $conference ) { + + // query all the visible Events related to this Conference + $events = ( new QueryEvent() ) + ->whereConference( $conference ) + ->queryGenerator(); +} + +Header::spawn( null, [ + 'title' => __( "Conferenza" ), +] ); +?> + +
+ + + +
+ + $label ): ?> + +
+ +

+
+ + { $field }; + + // for DateTime(s), show raw date + if( $value instanceof DateTime ) { + $value = $value->format( 'Y-m-d H:i:s' ); + } + + echo value( $value ); + } + + ?> /> + +

+
+ + + +
+ + +
+ + + +
+ +

+ + + + + + + + +. - -require 'load.php'; - -inject_in_module('header', function() { - echo "\n\t"; -} ); - -Header::spawn('credits'); -?> -
-

software libero e open source.") ?>

-
- -
-
- -
-
- -
-

getLink() - ) ?>

-
-
-
git clone
-
-
- -
-
-

- - -
- false] ); diff --git a/admin/event-edit.php b/admin/event-edit.php index b3f670f..89db424 100644 --- a/admin/event-edit.php +++ b/admin/event-edit.php @@ -1,628 +1,635 @@ . /* * Event edit * * From this page you can create/edit an User and assign some skills/interests etc. */ // load configurations and framework require 'load.php'; // inherit the Conference or specify one -$conference_uid = CURRENT_CONFERENCE_UID; -if( isset( $_REQUEST['conference'] ) ) { - $conference_uid = $_REQUEST['conference']; -} +$conference_uid = $_GET['conference_uid'] ?? $_POST['conference_uid'] ?? CURRENT_CONFERENCE_UID; // check if the Conference exists -$conference = FullConference::factoryFromUID( $conference_uid ) +$conference = ( new QueryConference() ) + ->whereConferenceUID( $conference_uid ) ->queryRow(); +// no Conference no party if( !$conference ) { + error( "missing conference with UID $conferene_uid" ); die_with_404(); } // retrieve the Event (if existing) $event = null; -if( isset( $_GET['uid'] ) ) { +if( isset( $_GET['id'] ) ) { + + // no Event no party $event = ( new QueryEvent() ) ->whereConference( $conference ) ->joinConference() ->joinChapter() - ->whereEventUID( $_GET['uid'] ) + ->whereEventID( $_GET['id'] ) ->queryRow(); + // no Event no party if( !$event ) { die_with_404(); } + // no editable no party if( !$event->isEventEditable() ) { - error_die("Can't edit event"); + missing_privileges(); } } else { // check if there are permissions to add event if( !has_permission( 'add-event' ) ) { - die( 'missing permissions' ); + missing_privileges(); } } $warning = null; +// check if the user submitted a form +// check which one if( $_POST ) { + // the user is submitting the save form if( is_action( 'save-event' ) ) { $conference_ID = $conference->getConferenceID(); $data = []; $data[] = new DBCol( Event::TITLE, $_POST['title'], 's' ); $data[] = new DBCol( Event::UID, $_POST['uid'], 's' ); $data[] = new DBCol( Event::LANGUAGE, $_POST['language'], 's' ); $data[] = new DBCol( Event::SUBTITLE, $_POST['subtitle'], 's' ); $data[] = new DBCol( Event::START, $_POST['start'], 's' ); $data[] = new DBCol( Event::END, $_POST['end'], 's' ); $data[] = new DBCol( Event::IMAGE, $_POST['image'], 'snull' ); $data[] = new DBCol( Chapter::ID, $_POST['chapter'], 'd' ); $data[] = new DBCol( Room::ID, $_POST['room'], 'd' ); $data[] = new DBCol( Track::ID, $_POST['track'], 'd' ); $data[] = new DBCol( Conference::ID, $conference_ID, 'd' ); // for each language save the fields foreach( all_languages() as $lang ) { foreach( Event::fields_i18n() as $i18n_column => $label ) { // generic column name in this language $field = $i18n_column . '_' . $lang->getISO(); // sent column value $value = $_POST[ $field ] ?? null; // prepare to be saved $data[] = new DBCol( $field, $value, 'snull' ); } } // convert empty strings to NULL, if possible foreach( $data as $row ) { $row->promoteNULL(); } if( $event ) { // update the existing Event ( new QueryEvent() ) ->whereEvent( $event ) ->update( $data ); } else { // insert a new Event Event::factory() ->insertRow( $data ); } $id = $event ? $event->getEventID() : last_inserted_ID(); // get the updated Event $event = FullEvent::factory() ->whereInt( Event::ID, $id ) ->queryRow(); // POST-redirect-GET http_redirect( $event->getFullEventEditURL(), 303 ); } /** * Change the Image */ if( $event && is_action( 'change-image' ) ) { // prepare the image uploader $image = new FileUploader( 'image', [ 'category' => 'image', 'override-filename' => "event-" . $event->getEventUID(), ] ); // prepare the image pathnames $img_url = $event->getConferenceUID() . _ . 'images'; $img_path = ABSPATH . __ . $event->getConferenceUID() . __ . 'images'; // really upload that shitty image somewhere if( $image->fileChoosed() ) { $ok = $image->uploadTo( $img_path, $status, $filename, $ext ); if( $ok ) { // now update ( new QueryEvent() ) ->whereEvent( $event ) ->update( [ 'event_img' => $img_url . "/$filename.$ext", ] ); // POST-redirect-GET http_redirect( $event->getFullEventEditURL(), 303 ); } else { $warning = $image->getErrorMessage(); } } } /* * Add the user */ if( $event && is_action( 'add-user' ) && isset( $_POST['user'] ) ) { // Add user $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { ( new QueryEventUser() ) ->whereEvent( $event ) ->whereUser( $user ) ->delete(); ( new QueryEventUser() )->insertRow( [ new DBCol( Event::ID, $event->getEventID(), 'd' ), new DBCol( User ::ID, $user->getUserID(), 'd' ), new DBCol( EventUser::ORDER, 0, 'd' ), ] ); } } /** * Update an user order */ if( $event && is_action( 'update-user' ) && isset( $_POST['user'] ) ) { $user = User::factoryFromUID( $_POST['user'] ) ->select( User::ID ) ->queryRow(); if( $user ) { if ( !empty( $_POST['delete'] ) ) { // Delete user EventUser::delete( $event->getEventID(), $user->getUserID() ); } elseif( isset( $_POST['order'] ) ) { // change order EventUser::factory() ->whereInt( Event::ID, $event->getEventID() ) ->whereInt( User ::ID, $user->getUserID() ) ->update( [ new DBCol( EventUser::ORDER, $_POST['order'], 'd') ] ); } } } // post -> redirect -> get (no: it hide errors) // http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 ); } if( $event ) { Header::spawn( null, [ 'title' => sprintf( __("Modifica %s: %s"), $event->getChapterName(), $event->getEventTitle() ), ] ); } else { Header::spawn( null, [ 'title' => sprintf( __( "Aggiungi %s" ), __( "Evento" ) ), ] ); } ?>

getConferenceURL(), esc_html( $conference->getConferenceTitle() ) . icon( 'home', 'left' ) ) ?>

getEventURL(), // text __( "Vedi" ) . icon( 'account_box', 'left' ) ) ?>

get( Event::TITLE ) ); } ?> />
get( Event::UID ) ); } ?> />
get( Event::SUBTITLE ) ); } ?> />
get( Event::LANGUAGE ) ); } ?> />
getEventStart()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['start'] ) ) { echo value( $_GET['start'] ); } ?> />
getEventEnd()->format( 'Y-m-d H:i:s' ) ); } elseif( isset( $_GET['end'] ) ) { echo value( $_GET['end'] ); } ?> />
$label ): ?>

getISO() ?>
get( Event::IMAGE ) ); } ?>/ > hasEventImage() ): ?> <?= esc_attr( $event->getEventTitle() ) ?>

factoryUserByEvent() ->select( [ User::UID, EventUser::ORDER, ] ) ->defaultClass( EventUser::class ) ->orderBy( EventUser::ORDER ) ->queryGenerator(); ?> valid() ): ?>

$user ): ?>
getUserUID() ) ?> />
getEventUserOrder() ) ?>" />
-
+

getUserEditURL(), sprintf( __( "Modifica %s" ), __( "Utente" ) ) ) ?>

. - -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(); -} - -$args = [ - 'title' => sprintf( - __("%s: %s"), - $event->getChapterName(), - $event->getEventTitle() - ), - 'url' => $event->getEventURL( true ), -]; - -if( $event->hasEventImage() ) { - $args['og'] = [ - 'image' => $event->getEventImage( true ), - ]; -} - -Header::spawn( null, $args ); -?> - - isEventEditable() ): ?> -

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

- isEventTranslatable() ): ?> -

getEventTranslateURL(), - __("Traduci") . 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'] ) ?> -
- - - - - 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 = [] ) { + public static function spawn( $args = [] ) { + + // merge default arguments $args = array_replace( [ 'home' => true ], $args ); ?>
-
+
-
-
-
#LDTO2016
-

contenuto culturale libero %s. ". - "Sei libero di distribuire e/o modificare i contenuti ". - "anche per scopi commerciali, fintanto che si cita la provenienza e ". - "si ricondivide sotto la medesima licenza." - ), - license('cc-by-sa-4.0')->getLink('yellow-text') - ) ?>

-

-

- "> - Facebook - - - "> - Twitter - - -

-
+
-
-
    - -
  • - 2006; $year--) { - $ld($year, __("Cascina Roccafranca") ); - } - ?> -
-
+

. /** * 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 */ public 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 ? 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'] ); } + // sent the proper content type and charset header('Content-Type: text/html; charset=' . CHARSET); + // declare that this page was not found if( $args['not-found'] ) { - header('HTTP/1.1 404 Not Found'); + http_response_code( 404 ); } - enqueue_css('materialize'); - enqueue_css('materialize.custom'); - enqueue_css('materialize.icons'); - enqueue_js('jquery'); - enqueue_js('materialize'); +// 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(); ?> <?= esc_html( $args['head-title'] ) ?> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + $value): ?> -
-
<?php echo __(">
-

. /** * A recursive function to generate a menu tree. * * @param string $uid The menu identifier * @param int $level Level of the menu, used internally. Default 0. * @param array $args Arguments */ function print_menu($uid = null, $level = 0, $args = [] ) { $args = array_replace( [ 'max-level' => 99, 'main-ul-intag' => 'class="collection"' ], $args ); if( $level > $args['max-level'] ) { return; } $menuEntries = get_children_menu_entries($uid); if( ! $menuEntries ) { return; } ?> >
  • url ), $menuEntry->name, $menuEntry->get('title') ) ?> uid, $level + 1, $args ) ?>
  • $icon"; } function die_with_404() { new Header('404', [ 'title' => __("È un 404! Pagina non trovata :("), 'not-found' => true ] ); - error( __("Nott foond! A.k.a. erroro quattrociantoquatto (N.B. eseguire coi permessi di root non risolve la situazione!)") ); + printf( + '

    %s

    ', + __("Nott foond! A.k.a. erroro quattrociantoquatto (N.B. eseguire coi permessi di root non risolve la situazione!)") + ); new Footer(); exit; } /** * Require a certain page from the template directory * * @param $name string page name (to be sanitized) * @param $args mixed arguments to be passed to the page scope */ function template( $template, $template_args = [] ) { extract( $template_args, EXTR_SKIP ); require CURRENT_CONFERENCE_ABSPATH . __ . 'template' . __ . $template . '.php'; } diff --git a/admin/index.php b/admin/index.php index 9404d3a..28b0055 100644 --- a/admin/index.php +++ b/admin/index.php @@ -1,395 +1,70 @@ . -require 'load.php'; - -$conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) - ->queryRow(); +/* + * Administration homepage + * + * Here you can see all the conferences + */ -if( !$conference ) { - die_with_404(); -} +// load configurations and framework +require 'load.php'; -enqueue_js('leaflet'); -enqueue_js('leaflet.init'); -enqueue_js('scrollfire'); -enqueue_css('leaflet'); -enqueue_css('home'); +// do not allow to visit this page if you cannot see the backend +require_permission( 'backend' ); -// Support for non-JavaScript -inject_in_module('header', function() { - echo "\n\t"; -} ); +// query all the conferences (they should not be so much) +$conferences = ( new QueryConference() ) + ->queryGenerator(); +// print header Header::spawn( null, [ - 'show-title' => false, - 'head-title' => $s = $conference->getConferenceTitle(), - 'title' => $s, - 'url' => $conference->getConferenceURL() + 'title' => __("Conferenze" ), ] ); ?> - 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() ?> +
    • getConferenceEditURL(), + esc_html( $conference->getConferenceTitle() ), + ) ?>
    • -

      getChapterName() ) ?>

      + + - -

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

      -

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

      - printTable(); ?> -
      + + -
      -
      -
      -
      -

      -

      -
      -
      -
      -
      -

      <?= __(" />

      -
      -
      -
      -
      -
      +
    • 1 ] ), + __( "Aggiungi" ) + ) ?>
    • -
      -
      -

      -

      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, +] ); -Footer::spawn( ['home' => false] ); diff --git a/admin/load-example.php b/admin/load-example.php new file mode 100644 index 0000000..bdfff66 --- /dev/null +++ b/admin/load-example.php @@ -0,0 +1,23 @@ +. - -// Boz-PHP: start -require '../load.php'; - -define('CURRENT_CONFERENCE_UID', '2016'); -define('CURRENT_CONFERENCE_PATH', ROOT . _ . CURRENT_CONFERENCE_UID); -define('CURRENT_CONFERENCE_URL', URL . _ . CURRENT_CONFERENCE_UID); -define('CURRENT_CONFERENCE_ABSPATH', ABSPATH . __ . ROOT . __ . CURRENT_CONFERENCE_UID); - -// Autoload classes -spl_autoload_register( function($c) { - $path = CURRENT_CONFERENCE_ABSPATH . __ . INCLUDES . __ . "class-$c.php"; - if( is_file( $path ) ) { - require $path; - } -} ); - -require 'includes/functions.php'; - -/////////////////////////////////////////////////////////////////// -define('STITIC', 'static'); - -define_default( 'PANEL_NAME', __( "Conference Panel" ) ); - -/////////////////////////////////////////////////////////////////// -// Boz-PHP: CSS and JS (some aliases from `libjs-jquery` package) -register_js('leaflet.init', STATIC_PATH . '/leaflet-init.js'); -register_js('materialize', STATIC_PATH . '/materialize/js/materialize.min.js'); -register_css('materialize', STATIC_PATH . '/materialize/css/materialize.min.css'); -register_css('materialize.custom', STATIC_PATH . '/materialize-custom.css'); -register_css('materialize.icons', STATIC_PATH . '/material-design-icons/material-icons.css'); -register_css('home', STATIC_PATH . '/home.css'); -register_js('scrollfire', STATIC_PATH . '/scrollfire.js'); diff --git a/admin/login.php b/admin/login.php index 0806d89..a7adea2 100644 --- a/admin/login.php +++ b/admin/login.php @@ -1,83 +1,82 @@ . require 'load.php'; $status = null; if( is_action( 'logout' ) ) { logout(); } -if( is_action( 'login' ) && isset( $_POST['user_uid'], $_POST['user_password'] ) ) { +if( is_action( 'login' ) ) { login( $status ); } switch( $status ) { case Session::LOGIN_FAILED: - error_die("Wrong e-mail or password"); - break; + die("Wrong e-mail or password"); case Session::USER_DISABLED: - error_die("User disabled"); - break; + die("User disabled"); } Header::spawn( null, [ 'title' => __( "Login" ), + 'home' => false, ] ); if( is_logged() ): ?>

    />

    . - -require 'load.php'; - -Header::spawn('partner'); -?> -

    - - ', - STATIC_PATH . "/partner/$logo", - sprintf( - __("Logo di %s"), - $name - ), - $max_size - ), - $name, - null, - 'target="_blank"' - ); - } ?> - -
    -
    -

    -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    -

    -
    -
    - -
    -
    -
    - -
    -
    -

    -
    -
    - -
    -
    - -
    -
    -
    - -
    -
    -

    - - - -
    -
    - -
    - -
    - - -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - false] ); diff --git a/admin/photos.php b/admin/photos.php deleted file mode 100644 index 316d7e1..0000000 --- a/admin/photos.php +++ /dev/null @@ -1,47 +0,0 @@ -. - -require 'load.php'; - -$alt = esc_attr( sprintf( - __("foto %s"), - SITE_NAME -) ); - -Header::spawn('photos'); -?> -
    -

    -
    - - - - -
    - " alt="" /> -
    - - - - - -
    -
    - - false ] ); diff --git a/admin/user.php b/admin/user.php deleted file mode 100644 index 3c28181..0000000 --- a/admin/user.php +++ /dev/null @@ -1,277 +0,0 @@ -. - -require 'load.php'; - -$conference = FullConference::factoryFromUID( CURRENT_CONFERENCE_UID ) - ->queryRow(); - -$conference or die_with_404(); - -$user = User::factoryByUID( $_GET['uid'] ) - ->select( User::fields() ) - ->select( User::allSocialFields() ) - ->queryRow(); - -if( !$user ) { - die_with_404(); -} - -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 ) - ->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() ); - } - ?>getConferenceURL(), - esc_html( $event->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' ); - ?> -
    -
    - - -. // allowed only from command line interface -if( ! isset( $argv[ 0 ] ) ) { +if( empty( $argv[ 0 ] ) ) { exit( 1 ); } -// autoload the framework -require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'load.php'; - // command line arguments $opts = getopt( 'h', [ + 'load:', 'uid:', 'role:', 'pwd:', 'force::', 'help', ] ); +// load the configuration file +require $opts['load'] ?? '../load.php'; + // show help if( ! isset( $opts[ 'uid' ], $opts[ 'pwd' ], $opts[ 'role' ] ) || isset( $opts[ 'help' ] ) || isset( $opts[ 'h' ] ) ) { $roles = _roles(); $roles_list = implode( '|', $roles ); printf( "Usage: %s [OPTIONS]\n", $argv[ 0 ] ); echo "OPTIONS:\n"; echo " --uid=UID user UID\n"; echo " --role=ROLE user role ($roles_list)\n"; echo " --pwd=PASSWORD password\n"; echo " --force update the user password if exists\n"; echo " -h --help show this help and exit\n"; exit( 0 ); } // validate role if( !Permissions::instance()->roleExists( $opts['role'] ) ) { printf( "The role '%s' does not exist\n", $opts['role'] ); exit( 1 ); } // look for existing user $user = User::factoryFromUID( $opts[ 'uid' ] ) ->select( User::ID ) ->queryRow(); if( $user && ! isset( $opts[ 'force' ] ) ) { printf( "User %s already exist\n", $opts[ 'uid' ] ); exit( 1 ); } $pwd = User::encryptPassword( $opts[ 'pwd' ] ); if( $user ) { - query_update( User::T, [ - new DBCol( User::PASSWORD, $pwd, 's' ), - ], sprintf( - '%s = %d', - User::ID, - $user->getUserID() - ) ); + + ( new QueryUser() ) + ->whereUser( $user ) + ->update( [ + User::PASSWORD => $pwd, + ] ); + } else { - insert_row( User::T, [ - new DBCol( User::UID, $opts[ 'uid' ], 's' ), - new DBCol( User::ROLE, $opts[ 'role' ], 's' ), - new DBCol( User::PASSWORD, $pwd, 's' ), - new DBCol( User::IS_ACTIVE, 1, 'd' ), - ] ); + + ( new QueryUser() ) + ->insertRow( [ + User::UID => $opts[ 'uid' ], + User::ROLE => $opts[ 'role' ], + User::NAME => $opts[ 'uid' ], + User::SURNAME => '', + User::PASSWORD => $pwd, + User::IS_ACTIVE => 1, + ] ); } /** * Get a list of available roles * * Well, it just remove the DEFAULT_USER_ROLE from the roles. * * @return array */ function _roles() { $good_roles = []; // get the existing roles foreach( Permissions::instance()->getRoles() as $role ) { if( $role !== DEFAULT_USER_ROLE ) { $good_roles[] = $role; } } return $good_roles; } diff --git a/cli/upgrade.php b/cli/upgrade.php index f0015e2..8901be5 100755 --- a/cli/upgrade.php +++ b/cli/upgrade.php @@ -1,75 +1,80 @@ #!/usr/bin/php . // allowed only from command line interface isset( $argv[ 0 ] ) or exit( 1 ); -// autoload the framework -require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'load.php'; +// command line arguments +$opts = getopt( 'h', [ + 'load:', +] ); + +// load the configuration file +require $opts['load'] ?? '../load.php'; // check if the aristocratic title is created safe_alter_table_add_column_after( User::T, User::ARISTOCRATIC_TITLE, 'VARCHAR(16)', User::UID ); // allow some event columns to be NULL $event_columns_allowed_to_be_null = [ Room::ID, Track::ID, Chapter::ID ]; foreach( $event_columns_allowed_to_be_null as $event_column_allowed_to_be_null ) { query( sprintf( "ALTER TABLE %s MODIFY COLUMN %s int(10) unsigned", T( Event::T ), $event_column_allowed_to_be_null ) ); } /** * Check if a table field does not exist * * @param $table string Table name * @param $wanted_field string */ function is_table_field_missing( $table, $wanted_field ) { $fields = query_results( sprintf( 'DESCRIBE %s', T( $table ) ) ); foreach( $fields as $field ) { if( $field->Field === $wanted_field ) { return false; } } return true; } /** * Alter table and add a column * * @param $title string Table name * @param $what string Column name * @param $definition string Column definition * @param $after string Column name */ function safe_alter_table_add_column_after( $table, $what, $definition, $after ) { if( is_table_field_missing( $table, $what ) ) { query( sprintf( 'ALTER TABLE %s ADD COLUMN %s %s AFTER %s', T( $table ), $what, $definition, $after ) ); } } diff --git a/documentation/database/patches/patch-7.sql b/documentation/database/patches/patch-7.sql new file mode 100644 index 0000000..8514493 --- /dev/null +++ b/documentation/database/patches/patch-7.sql @@ -0,0 +1 @@ +ALTER TABLE `{$prefix}user` MODIFY COLUMN `user_role` ENUM('admin','user','translator','superadmin') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'user'; diff --git a/documentation/database/patches/patch-8.sql b/documentation/database/patches/patch-8.sql new file mode 100644 index 0000000..c10944b --- /dev/null +++ b/documentation/database/patches/patch-8.sql @@ -0,0 +1,2 @@ +-- allow NULL +ALTER TABLE `{$prefix}conference` MODIFY COLUMN `conference_days` int(11); diff --git a/includes/class-Conference.php b/includes/class-Conference.php index e8ea92c..15d2a9c 100644 --- a/includes/class-Conference.php +++ b/includes/class-Conference.php @@ -1,341 +1,340 @@ . 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 ); if( $this->hasConferenceI18nSupport() ) { $url = keep_url_in_language( $url ); } return $url; } /** - * * Get the Conference edit URL * * @param boolean $absolute Set to true to prefere an absolute URL * @return string */ public function getConferenceEditURL() { // query string $args = [ - 'uid' => $conference->getConferenceUID(), + 'id' => $this->getConferenceID(), ]; return Conference::editURL( $args, $absolute ); } /** * Check if the Conference has URLs for every Event * * @return boolean */ public function hasConferenceEventsURL() { return $this->has( 'conference_events_url' ); } 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 ); } /** * Check if this Conference is editable by me */ public function isConferenceEditable() { return has_permission( 'edit-conferences' ); } /** * 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'; /** * Description column name */ const DESCRIPTION = 'conference_description'; /** * Subtitle column name */ const SUBTITLE = 'conference_subtitle'; /** * 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(); } /** * Build the conference edit URL * * @param array $args Query string arguments * @param boolean $absolute Flag to prefere an absolute URL * @return string */ public static function editURL( $args = [], $absolute = false ) { // build the base URL - $url = site_page( ADMIN_URL . '/conference.php', $absolute ); + $url = site_page( ADMIN_BASE_URL . '/conference.php', $absolute ); // append the query string return http_build_get_query( $url, $args ); } /** * All the public fields of a Conference * * @return array */ public static function fields() { return [ self::ID_, self::TITLE, self::UID, self::TITLE, self::SUBTITLE, self::DESCRIPTION, self::START, self::END, self::ACRONYM, self::PERSONS_URL, self::EVENTS_URL, self::DAYS, ]; } } diff --git a/includes/class-Event.php b/includes/class-Event.php index 60a09e0..d27d9fc 100644 --- a/includes/class-Event.php +++ b/includes/class-Event.php @@ -1,510 +1,534 @@ . trait EventTrait { /** * Get event ID * * @return int */ public function getEventID() { return $this->nonnull( Event::ID ); } /** * Get event UID * * @return string */ public function getEventUID() { return $this->get( Event::UID ); } /** * Get localized event title * * @return string */ public function getEventTitle() { return __( $this->get( Event::TITLE ) ); } /** * Check if the Event has a subtitle * * @return boolean */ public function hasEventSubtitle() { $title = $this->get( Event::SUBTITLE ); return !empty( $title ); } /** * Get localized event subtitle * * @return string */ public function getEventSubtitle() { return __( $this->get( Event::SUBTITLE ) ); } /** * Get an human event start date * * @return string */ public function getEventHumanStart() { return HumanTime::diff( $this->getEventStart() ); } /** * Get an human event end date * * @return string */ public function getEventHumanEnd() { return HumanTime::diff( $this->getEventEnd() ); } /** * Get event start date * * @param string If present, format of the date * @return DateTime|string */ public function getEventStart( $format = null ) { $date = $this->get( Event::START ); if( $format ) { return $date->format( $format ); } return $date; } /** * When event end date * * @param string If present, format of the date * @return DateTime|string */ public function getEventEnd( $format = null ) { $date = $this->get( Event::END ); if( $format ) { return $date->format( $format ); } return $date; } /** * Get the event duration * * @return DateInterval */ public function getEventDuration( $format ) { $start = $this->get( Event::START ); $end = $this->get( Event::END ); return $start->diff( $end )->format( $format ); } /** * Get the Event duration in a human-readable format * * @return string */ public function getHumanEventDuration( $args = [] ) { if( !isset( $args['adverb'] ) ) { $args['adverb'] = false; } return HumanTime::diff( $this->get( Event::START ), $this->get( Event::END ), $args ); } /** * It has an Event image? * * @return bool */ public function hasEventImage() { return $this->has( Event::IMAGE ); } /** * Get the path to the Event image * * @param boolean $absolute Try to force an absolute URL * @return string */ public function getEventImage( $absolute = false ) { return site_page( $this->get( Event::IMAGE ), $absolute ); } /** * It has event description? * * @return bool */ public function hasEventDescription() { return null !== $this->get( Event::DESCRIPTION ); } /** * It has an event abstract? * * @return bool */ public function hasEventAbstract() { return null !== $this->get( Event::ABSTRACT ); } /** * It has an event note? * * @return bool */ function hasEventNote() { return null !== $this->get( Event::NOTE ); } /** * Get the event description * * @return string */ public function getEventDescription() { return $this->get( Event::DESCRIPTION ); } /** * Get the event abstract * * @return string */ public function getEventAbstract() { return $this->get( Event::ABSTRACT ); } /** * Get the event note * * @return string */ public function getEventNote() { return $this->get( Event::NOTE ); } /** * Get the Event description rendered in HTML * * @return string */ public function getEventDescriptionHTML( $args = [] ) { return Markdown::parse( $this->getEventDescription(), $args ); } /** * Get the Event abstract rendered in HTML * * @return string */ public function getEventAbstractHTML( $args = [] ) { return Markdown::parse( $this->getEventAbstract(), $args ); } /** * Get the Event notes rendered in HTML * * @return string */ public function getEventNoteHTML( $args = [] ) { return Markdown::parse( $this->getEventNote(), $args ); } /** * Factory Users by this event * * @return Query */ public function factoryUserByEvent() { return User::factoryByEvent( $this->getEventID() ); } /** * Factory Sharables by this event * * @return Query */ public function factorySharebleByEvent() { return Sharable::factoryByEvent( $this->getEventID() ); } /** * You can edit this event? * * @return bool */ public function isEventEditable() { return has_permission('edit-events'); } + /** + * Get the edit URL for this Event + * + * @param boolean $absolute Flag to require an absolute URL + * @return string + */ + public function getEventEditURL( $absolute = false ) { + return Event::editURL( [ + 'id' => $this->getEventID(), + ], $absolute ); + } + /** * Check if I can translate this Event * * @return boolean */ public function isEventTranslatable() { return $this->isEventEditable() || has_permission( 'translate' ); } /** * Insert subscription if not exists */ function addSubscription($email) { $exists = Subscription::getStandardQuery( $email, $this->getEventID() )->getRow('Subscription'); $exists || Subscription::insert( $email, $this->getEventID() ); return $exists; } /** * Get URL to trop-iCal API for this event * * @param boolean $absolute Set to true for an absolute URL * @return string */ public function getEventCalURL( $absolute = false ) { $event = urlencode( $this->getEventUID() ); $conf = urlencode( $this->getConferenceUID() ); return site_page( "api/tropical.php?conference=$conf&event=$event", $absolute ); } /** * Are event subscriptions available? * * @return bool */ public function areEventSubscriptionsAvailable() { return $this->get( 'event_subscriptions' ) && ! $this->isEventPassed(); } /** * Is event passed? * * @return bool */ public function isEventPassed() { $now = new DateTime('now'); return $now->diff( $this->get('event_end') )->invert === 1; } /** * Get the URL to the page that allow to translate this Event * * @return string */ public function getEventTranslateURL() { // well, actually the translate page it's in the 2016 directory :^) $page = ROOT . '/2016/event-translate.php'; return http_build_get_query( $page, [ 'id' => $this->getEventID(), ] ); } /** * Normalize an Event object */ protected function normalizeEvent() { $this->integers( Event::ID ); $this->datetimes( Event::START, Event::END ); $this->booleans('event_subscriptions'); } } /** * An Event can be a talk or a lesson etc. */ class Event extends Queried { use EventTrait; /** * Database table name */ const T = 'event'; /** * ID column name */ const ID = 'event_ID'; /** * UID column name */ const UID = 'event_uid'; /** * Title column name */ const TITLE = 'event_title'; /** * Subtitle column name */ const SUBTITLE = 'event_subtitle'; /** * Image column name */ const IMAGE = 'event_img'; /** * Start column name */ const START = 'event_start'; /** * End column name */ const END = 'event_end'; /** * Description column name */ const DESCRIPTION = 'event_description'; /** * Description column name */ const ABSTRACT = 'event_abstract'; /** * Note column name */ const NOTE = 'event_note'; /** * Language column name */ const LANGUAGE = 'event_language'; /** * Complete ID column name */ const ID_ = self::T . DOT . self::ID; /** * Complete conference ID column name */ const CONFERENCE_ = self::T . DOT . Conference::ID; /** * Complete room ID column name */ const ROOM_ = self::T . DOT . Room::ID; /** * Complete track ID column name */ const TRACK_ = self::T . DOT . Track::ID; /** * Complete chapter ID column name */ const CHAPTER_ = self::T . DOT . Chapter::ID; /** * Maximum UID length * * @override */ const MAXLEN_UID = 100; /** * Constructor */ public function __construct() { $this->normalizeEvent(); } /** * Generate the appropriate SELECT for the User Abstract * * @return string */ public static function ABSTRACT_L10N() { return i18n_coalesce( self::ABSTRACT ); } /** * Generate the appropriate SELECT for the User Description * * @return string */ public static function DESCRIPTION_L10N() { return i18n_coalesce( self::DESCRIPTION ); } /** * Generate the appropriate SELECT for the User Description * * @return string */ public static function NOTE_L10N() { return i18n_coalesce( self::NOTE ); } /** * All the public Event fields * * @return array */ public static function fields() { return [ self::ID_, self::UID, self::TITLE, self::DESCRIPTION_L10N(), self::ABSTRACT_L10N(), self::NOTE_L10n(), self::SUBTITLE, self::IMAGE, self::START, self::END, self::LANGUAGE, ]; } /** * Get all the fields that support internationalization * * @return array */ public static function fields_i18n() { return [ self::ABSTRACT => __( "Abstract" ), self::DESCRIPTION => __( "Descrizione" ), self::NOTE => __( "Note" ), ]; } + + /** + * Get the edit URL to an Event + * + * @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 = site_page( ADMIN_BASE_URL . '/event-edit.php', $absolute ); + return http_build_get_query( $url, $args ); + } } diff --git a/includes/class-FullEvent.php b/includes/class-FullEvent.php index aa7bbda..6ea776f 100644 --- a/includes/class-FullEvent.php +++ b/includes/class-FullEvent.php @@ -1,207 +1,207 @@ . 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 ); } /** * 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 ( new QueryEvent() ) ->select( Conference::fields() ) ->select( Event ::fields() ) ->select( Track ::fields() ) ->select( Chapter ::fields() ) ->select( Room ::fields() ) ->joinConference() ->joinTrackChapterRoom() ->defaultClass( __CLASS__ ); } 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 = site_page( ADMIN_URL . '/edit.php', $absolute ); + $url = site_page( ADMIN_BASE_URL . '/edit.php', $absolute ); return http_build_get_query( $url, $args ); } } diff --git a/includes/class-QueryConference.php b/includes/class-QueryConference.php index 7465cec..48fd951 100644 --- a/includes/class-QueryConference.php +++ b/includes/class-QueryConference.php @@ -1,143 +1,144 @@ . /** * Class able to query a Conference */ trait QueryConferenceTrait { /* * Univoque Location ID column name * * Used from ConferenceTrait. * * @var */ protected $LOCATION_ID = 'conference.location_ID'; /** * Limit to a specific Conference * * @param $conference Conference * @return self */ public function whereConference( $conference ) { return $this->whereConferenceID( $conference->getConferenceID() ); } /** * Limit to a specific Conference ID * * @param $id Conference ID * @return self */ public function whereConferenceID( $id ) { return $this->whereInt( $this->CONFERENCE_ID, $id ); } /** * Exclude a specific Conference * * @param $conference Conference * @return self */ public function whereConferenceNot( $conference ) { $id = $conference->getConferenceID(); return $this->joinConference() ->whereInt( Event::CONFERENCE_, $id, '<>' ); } /** * Where the Conference UID is... * * @param string $uid Conference UID * @return self */ public function whereConferenceUID( $uid ) { return $this->whereStr( Conference::UID, $uid ); } /** * Join a table to the Conference table * * You can call it multiple time safely. * * @return self */ public function joinConference() { if( empty( $this->joinedConference ) ) { $this->joinOn( 'INNER', Conference::T, Conference::ID_, $this->CONFERENCE_ID ); $this->joinedConference = true; } return $this; } /** * Join Events to their Location (and Conference. asd) * * You can call it multiple time safely. * + * @param string $join_type Join type * @return self */ - public function joinLocation() { + public function joinLocation( $join_type = 'INNER' ) { if( empty( $this->joinedLocation ) ) { - $this->joinOn( 'INNER', Location::T, $this->LOCATION_ID, 'location.location_ID' ); + $this->joinOn( $join_type, Location::T, $this->LOCATION_ID, 'location.location_ID' ); $this->joinedLocation = true; } return $this; } /** * Check if the Conference has support for internationalization * * @return self */ public function whereConferenceHasI18nSupport() { return $this->compare( 'conference_events_url', 'IS NOT', 'NULL' ); } } /** * Conference */ class QueryConference extends Query { use QueryConferenceTrait; /* * Univoque Conference ID column name * * Used from ConferenceTrait. * * @var */ protected $CONFERENCE_ID = 'conference.conference_ID'; /** * Constructor */ public function __construct( $db = null ) { // set database connection and default result class parent::__construct( $db, Conference::class ); // set the default table $this->from( Conference::T ); } } diff --git a/includes/class-QueryEvent.php b/includes/class-QueryEvent.php index 0ed1f47..261ee6d 100644 --- a/includes/class-QueryEvent.php +++ b/includes/class-QueryEvent.php @@ -1,193 +1,199 @@ . // load dependent traits class_exists( QueryConference::class, true ); /** * Methods for a QueryEvent class */ trait QueryEventTrait { use QueryConferenceTrait; /** * Where the Event is... * * @param object $event Event * @return self */ public function whereEvent( $event ) { return $this->whereEventID( $event->getEventID() ); } /** * Where the Event ID is... * * @param int $id Event ID * @return self */ public function whereEventID( $id ) { return $this->whereInt( $this->EVENT_ID, $id ); } /** * Where the Event UID is this one * * @param string $uid Event UID * @return self */ public function whereEventUID( $uid ) { return $this->whereStr( Event::UID, $uid ); } + /** + * Where the Event is editable by me + */ + public function whereEventIsEditable() { + throw new Exception( "to be implemented" ); + } } /** * Class able to query a FullEvent. */ class QueryEvent extends Query { use QueryEventTrait; /** * Univoque Event ID column name * * @var */ protected $EVENT_ID = 'event.event_ID'; /** * Univoque Chapter ID column name * * @var */ protected $CHAPTER_ID = 'event.chapter_ID'; /* * Univoque Conference ID column name * * Used from ConferenceTrait#joinConference() * * @var */ protected $CONFERENCE_ID = 'event.conference_ID'; /** * Univoque Track ID column name * * @var */ protected $TRACK_ID = 'event.track_ID'; /** * Univoque Room ID column name * * @var */ protected $ROOM_ID = 'event.room_ID'; /** * Constructor */ public function __construct() { parent::__construct(); $this->from( Event::T ); $this->defaultClass( FullEvent::class ); } /** * Limit to a certain User * * @deprecated * * @param $user User * @return self */ public function whereUser( $user ) { return $this->joinEventUser() ->whereInt( EventUser::USER_, $user->getUserID() ); } /** * Join a table with the Chapter table * * @return self */ public function joinChapter() { return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID ); } /** * Join a table with the Track table * * @return self */ public function joinTrack() { return $this->joinOn( 'INNER', Track::T, Track::ID_, $this->TRACK_ID ); } /** * Join a table with the Room table * * @return self */ public function joinRoom() { return $this->joinOn( 'INNER', Room::T, Room::ID_, $this->ROOM_ID ); } /** * Join Events to User IDs * * You can call it multiple time safely. * * @return self */ public function joinEventUser() { if( empty( $this->joinedEventUser ) ) { $this->from( EventUser::T ); $this->equals( EventUser::EVENT_, Event::ID_ ); $this->joinedEventUser = true; } return $this; } /** * Join Events and their Track, Chapter and Room (can be NULL). * * You can call it multiple time safely. * * @return self */ public function joinTrackChapterRoom() { if( empty( $this->joinedTrackChapterRoom ) ) { $this->from( Room::T ) ->equals( Room::ID_, Event::ROOM_ ); $this->from( Track::T ) ->equals( Track::ID_, Event::TRACK_ ); $this->from( Chapter::T ) ->equals( Chapter::ID_, Event::CHAPTER_ ); $this->joinedTrackChapterRoom = true; } return $this; } } diff --git a/includes/functions.php b/includes/functions.php index 1270130..1661327 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1,200 +1,200 @@ . 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(); // 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 ); } /** * Eventually ask for more privileges * * This redirects to the login page or throws a 403 page */ function missing_privileges() { if( is_logged() ) { // I do not want to spend too much time in this. Just die. http_response_code( 403 ); echo "You are not in the sudoers file. This incident will be reported. XKCD 838."; exit; } else { // the user needs to login // login page URL - $login_url = site_page( ADMIN_URL . '/login.php' ); + $login_url = site_page( ADMIN_BASE_URL . '/login.php' ); // current page URL $current_url = $_SERVER['REQUEST_URI'] ?? null; // build the login page URL with redirect to the current page $login_url = http_build_get_query( $login_url, [ 'redirect' => $current_url, ] ); // temporary redirect to the login page http_redirect( $login_url ); } } /** * Shortcut to require a specific permission * * @param string $permission */ function require_permission( $permission ) { $problem = false; // if the argument is a string is something like 'create-conference' if( is_string( $permission ) ) { if( !has_permission( $permission ) ) { $problem = true; } // the argument is a boolean just check it } elseif( !$permission ) { $problem = true; } // eventually raise a problem if( $problem ) { missing_privileges(); } } diff --git a/includes/load-post.php b/includes/load-post.php deleted file mode 100644 index 9917bda..0000000 --- a/includes/load-post.php +++ /dev/null @@ -1,110 +0,0 @@ -. - -// 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', [] ); - -// translator permissions -inherit_permissions( 'translator', 'user', [ - 'translate', -] ); - -// admin permissions -inherit_permissions( 'admin', 'translator', [ - '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( 'it_IT', ['it', 'it-it'], null, null, 'Italiano' ); -register_language( 'en_US', ['en', 'en-us', 'en-en'], null, null, 'English' ); -register_language( 'pms', [ 'pms' ], null, null, 'Piemontèis' ); -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/load.php b/load.php index 327b50b..954591a 100644 --- a/load.php +++ b/load.php @@ -1,150 +1,150 @@ . /** * This file loads the 'suckless-conference' framework. * * Note: you must call the 'suckless-php/load.php' before this. */ // refuse to load directly if( !defined( 'ABSPATH' ) ) { throw new Exception( 'Bad usage' ); } // autoload any requested conference-related class spl_autoload_register( function( $c ) { // this should be: // suckless-conference/includes/class-Test.php $path = __DIR__ . "/includes/class-$c.php"; if( is_file( $path ) ) { require $path; } } ); /******************* * DEFAULT CONSTANTS ******************* * * You can override these constants declaring a: * * define( 'SOMETHING', 'foo' ); * * Just before loading this page. */ // default jQuery URL // as default it uses the jQuery installed in your distribution // apt install libjs-jquery define_default( 'JQUERY_URL', '/javascript/jquery/jquery.min.js' ); // default Leaflet URL // as default it uses the one installed in your distribution // apt install libjs-leaflet define_default( 'LEAFLET_BASE_URL', '/javascript/leaflet' ); // the markdown library // as default it uses the one installed in your distribution // apt install php-markdown define_default( 'LIBMARKDOWN_PATH', '/usr/share/php/markdown.php' ); // default admin URL // this can be a complete URL or whatever but without slash at the end -define_default( 'ADMIN_URL', 'admin' ); +define_default( 'ADMIN_BASE_URL', 'admin' ); // timezone of database dates define_default( 'DEFAULT_TIMEZONE', 'Europe/Rome' ); /******************** * SCRIPTS AND STYLES ******************** * * Scripts and styles that are often used in your CMSs. */ // register the jQuery library register_js( 'jquery', JQUERY_URL ); // register the Leaflet library register_js( 'leaflet', LEAFLET_BASE_URL . '/leaflet.js' ); register_css( 'leaflet', LEAFLET_BASE_URL . '/leaflet.css' ); /********************** * ROLES AND PRIVILEGES ********************** * * Basic roles and privileges for your Conferences. */ // user permissions register_permissions( 'user', [ // an user is allowed to visit the backend 'backend', ] ); // translator permissions inherit_permissions( 'translator', 'user', [ // a translator can translate events 'translate', ] ); // admin permissions inherit_permissions( 'admin', 'translator', [ // an admin can add an event 'add-event', // ad admin can edit an event even if not owned 'edit-events', // an admin can edit all standard users 'edit-users', ] ); // superadmin permissions inherit_permissions( 'superadmin', 'admin', [ // can create a Conference 'add-conference', // edit all Conferences 'edit-conferences', ] ); /*************** * PHP UTILITIES *************** * * Some things that you should always setup. */ // apply the global timezone // above you will notice the constant definition date_default_timezone_set( DEFAULT_TIMEZONE ); // that's all! // load some dummy conference-related shortcuts // this should be: // suckless-conference/includes/functions.php require __DIR__ . '/includes/functions.php';