diff --git a/admin/event-edit.php b/admin/event-edit.php index cbd9393..19e36b7 100644 --- a/admin/event-edit.php +++ b/admin/event-edit.php @@ -1,715 +1,736 @@ . /* * 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 = $_GET['conference_uid'] ?? $_POST['conference_uid'] ?? CURRENT_CONFERENCE_UID; // check if the Conference exists $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['id'] ) ) { // no Event no party $event = ( new QueryEvent() ) ->whereConference( $conference ) ->joinConference() ->joinChapter( 'LEFT' ) ->whereEventID( $_GET['id'] ) ->queryRow(); // no Event no party if( !$event ) { die_with_404(); } // no editable no party if( !$event->isEventEditable() ) { missing_privileges(); } } else { // check if there are permissions to add event if( !has_permission( 'add-event' ) ) { 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::EXTERNAL_URL,$_POST['url'], 's' ); $data[] = new DBCol( Event::ABORTED, $_POST['aborted'], 'd' ); $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->getEventEditURL(), 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 ( new QueryEventUser() ) ->whereEvent( $event ) ->whereUser( $user ) ->delete(); } elseif( isset( $_POST['order'], $_POST['role'] ) ) { // change order ( new QueryEventUser() ) ->whereEvent( $event ) ->whereUser( $user ) ->update( [ new DBCol( EventUser::ORDER, $_POST['order'], 'd' ), new DBCol( EventUser::ROLE, $_POST['role'], 's' ), ] ); } } } // post -> redirect -> get (no: it hide errors) // http_redirect( $_SERVER[ 'REQUEST_URI' ], 303 ); } // Event's Sharable(s) $sharables = []; +$users = []; if( $event ) { // query all the Sharable(s) related to this Event $sharables = ( new QuerySharable() ) ->whereEvent( $event ) ->queryGenerator(); + // users + $users = $event->factoryUserByEvent() + ->select( [ + User::UID, + User::NAME, + User::SURNAME, + EventUser::ORDER, + EventUser::ROLE, + ] ) + ->defaultClass( EventUser::class ) + ->orderBy( EventUser::ORDER ) + ->queryResults(); + 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' ) ) ?>

hasEventPermalink() ): ?>

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

get( Event::TITLE ) ); } ?> />
get( Event::UID ) ); } ?> />
get( Event::SUBTITLE ) ); } ?> />
get( Event::EXTERNAL_URL ) ); } ?> />
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, - EventUser::ROLE, - ] ) - ->defaultClass( EventUser::class ) - ->orderBy( EventUser::ORDER ) - ->queryGenerator(); - ?> - valid() ): ?> +

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

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

+ + + + +

+ + + + . + +// default FFMPEG command pathname +define_default( 'FFMPEG_COMMAND', 'ffmpeg' ); + +/** + * Tool to save video metadata with FFMPEG + * + * @See https://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata + */ +class VideoMetadata { + + /** + * Print an FFMPEG command + * + * To see some available metadatas: + * https://wiki.multimedia.cx/index.php?title=FFmpeg_Metadata + * + * @param array $args Associative array of arguments + * Some available keys: + * 'input' => (string) Input file path + * 'output' => (string) Output file path + * 'metadata' => (array) Associative array of metadata + * Some of them: + * title + * author + * album_artist + * album + * composer + * year + * copyright + * description + * language + * + * @param array $data Arguments + */ + public static function command( $data = [] ) { + + $args = []; + + // print the input file '-i stuff' + if( !empty( $data['input'] ) ) { + $args[] = escapeshellarg( '-i' ); + $args[] = escapeshellarg( $data['input'] ); + } + + // default arguments + $data['metadata'] = $data['metadata'] ?? []; + $event = $data['event'] ?? null; + $conference = $data['conference'] ?? null; + + // inherit some Event parameters + if( $event ) { + + // enrich the Metadata with some Event stuff + $data['metadata'] = array_replace( [ + 'title' => $event->getEventTitle(), + 'language' => $event->getEventLanguage(), + 'date' => $event->getEventStart( 'Y' ), + ], $data['metadata'] ); + } + + // inherit some Conference parameters + if( $conference ) { + $data['metadata'] = array_replace( [ + 'album' => $conference->getConferenceTitle(), + ], $data['metadata'] ); + } + + // eventually generate some credits + if( empty( $data['metadata']['author'] ) && isset( $data['users'] ) ) { + $data['metadata']['author'] = self::generateUserCredits( $data['users'] ); + } + + // loop metadata and build arguments + foreach( $data['metadata'] as $key => $value ) { + + // build pairs of '-metadata stuff=foo' + $args[] = escapeshellarg( '-metadata' ); + $args[] = escapeshellarg( sprintf( + "%s=%s", + $key, + $value + ) ); + } + + // print the output file 'stuff' + // the default is "input.with_metadata" + $output = $data['output'] ?? $data['input'] . '.with_metadata'; + if( !empty( $data['output'] ) ) { + $args[] = escapeshellarg( $data['output'] ); + } + + // merge the arguments + $args_complete = implode( ' ', $args ); + + // return the complete command + return sprintf( + "%s %s", + escapeshellcmd( FFMPEG_COMMAND ), + $args_complete + ); + } + + /** + * Generate some user credits + * + * @param EventUser[] $users + * @return string + */ + public static function generateUserCredits( $users ) { + + // users indexed by role + $grouped = [ + 'speaker' => [], + 'moderator' => [], + ]; + foreach( $users as $user ) { + $role = $user->get( EventUser::ROLE ); + + // eventually create empty and then append + $grouped[ $role ] = $grouped[ $role ] ?? []; + $grouped[ $role ][] = $user->getUserDisplayName(); + } + + $lines = []; + + $speakers = implode( ', ', $grouped['speaker'] ); + $moderators = implode( ', ', $grouped['moderator'] ); + + if( $speakers ) { + $lines[] = sprintf( __( "Relatori: %s" ), $speakers ); + } + + if( $moderators ) { + $lines[] = sprintf( __( "Moderatori: %s" ), $moderators ); + } + + return implode( "\n", $lines ); + } +} +