| 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() );
}
?> |
= HTML::a(
$event->getConferenceURL(),
esc_html( $event->getConferenceTitle() )
) ?> |
= esc_html( $event->getLocationName() ) ?>
|
= esc_html( $event->getEventStart( __( "d/m/Y" ) ) ) ?>
= $event->getEventHumanStart() ?>
|
isUserSocial() ): ?>
= __("Social") ?>
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/api/tagliatella.php b/api/tagliatella.php
index fba0d42..df61c17 100755
--- a/api/tagliatella.php
+++ b/api/tagliatella.php
@@ -1,232 +1,216 @@
.
require __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'load.php';
// In case something goes wrong...
http_response_code( 500 );
$uid = isset( $_GET[ 'conference' ] )
? $_GET[ 'conference' ]
: CURRENT_CONFERENCE_UID;
$conference_row = FullConference::factoryFromUID( $uid )
->queryRow();
if( ! $conference_row ) {
throw new LogicException( sprintf(
"Conference with uid '%s' does not exists!",
esc_html( $uid )
) );
}
$xml = new DOMDocument( '1.0', 'UTF-8' );
$schedule = $xml->createElement( 'schedule' );
$schedule = $xml->appendChild( $schedule );
$conference = $xml->createElement( 'conference' );
$conference = $schedule->appendChild( $conference );
$conference_fields = [
'title' => $conference_row->getConferenceTitle(),
'subtitle' => $conference_row->getConferenceSubtitle(),
'acronym' => $conference_row->get( Conference::ACRONYM ),
'days' => $conference_row->get( Conference::DAYS ),
'persons_url' => $conference_row->get( Conference::PERSONS_URL ),
'events_url' => $conference_row->get( Conference::EVENTS_URL ),
];
foreach( $conference_fields as $xml_field => $db_field ) {
add_child( $xml, $conference, $xml_field, $db_field );
}
add_child( $xml, $conference, 'start', $conference_row->getConferenceStart( 'Y-m-d H:i:s' ) );
add_child( $xml, $conference, 'end', $conference_row->getConferenceEnd( 'Y-m-d H:i:s' ) );
add_child( $xml, $conference, 'city', $conference_row->getLocationAddress() );
add_child( $xml, $conference, 'venue', $conference_row->getLocationNoteHTML() );
// Yes, these are hardcoded. asd
add_child( $xml, $conference, 'day_change', '09:00:00' );
add_child( $xml, $conference, 'timeslot_duration', '00:30:00' );
$events = FullEvent::factoryByConference( $conference_row->getConferenceID() )
- ->select( [
- Event::ID_,
- Event::UID,
- Event::TITLE,
- Event::SUBTITLE,
- Event::ABSTRACT,
- Event::DESCRIPTION,
- Event::LANGUAGE,
- Event::START,
- Event::END,
- Room ::ID_,
- Room::NAME,
- Chapter::NAME,
- Track::ID_,
- Track::NAME
- ] )
->orderBy( Event::START )
->orderBy( Room::ID_ )
->queryGenerator();
// Room names indexed by room_ID
$room_names = [];
$events_by_date_then_room = [];
foreach( $events as $event ) {
$day = $event->getEventStart( 'Y-m-d' );
// Add various levels to the array, if they don't already exists
if( ! isset( $events_by_date_then_room[ $day ] ) ) {
$events_by_date_then_room[ $day ] = [];
}
$room = $event->getRoomID();
if( ! isset( $events_by_date_then_room[ $day ][ $room ] ) ) {
$events_by_date_then_room[ $day ][ $room ] = [];
}
$room_names[ $room ] = $event->getRoomName();
// And finally, add the event itself
$events_by_date_then_room[ $day ][$room ][] = $event;
}
// These are database event fields whose content can be taken straight from the database.
// Others need a little more work to convert to the correct format.
$keys = [
'subtitle' => Event::SUBTITLE,
'language' => Event::LANGUAGE,
];
$day_index = 1;
$events_by_id = [];
foreach( $events_by_date_then_room as $day_date => $rooms ) {
$dayxml = add_child( $xml, $schedule, 'day', NULL );
$dayxml->setAttribute( 'index', $day_index );
$dayxml->setAttribute( 'date', $day_date );
foreach( $rooms as $room_ID => $events ) {
$roomxml = add_child( $xml, $dayxml, 'room', NULL );
// 9 agosto 2016 22:30 Ludovico says that this does not exist. OK.
// 9 agosto 2016 22:31 Ludovico says that this exists. OK.
$roomxml->setAttribute( 'name', $room_names[ $room_ID ] );
foreach( $events as $event ) {
$event_ID = $event->getEventID();
$eventxml = add_child( $xml, $roomxml, 'event', NULL );
$eventxml->setAttribute( 'id', $event_ID );
$events_by_id[ $event_ID ] = $eventxml;
// this stops PHPStorm from complaining, but most of these elements are really just strings...
/** @var $event DateTime[] */
// Same exact format, two different parameters since 'start' is a DateTime and 'duration' a DateInterval. Why, PHP, WHY?
add_child( $xml, $eventxml, 'title', $event->getEventTitle() );
add_child( $xml, $eventxml, 'slug', $event->getEventUID() );
add_child( $xml, $eventxml, 'start', $event->getEventStart( 'H:i' ) );
add_child( $xml, $eventxml, 'duration', $event->getEventDuration( '%H:%I' ) );
add_child( $xml, $eventxml, 'room', $event->getRoomName() );
add_child( $xml, $eventxml, 'track', $event->getTrackName() );
add_child( $xml, $eventxml, 'type', $event->getChapterName() );
$description = null;
if( $event->hasEventDescription() ) {
$description = $event->getEventDescriptionHTML();
}
add_child( $xml, $eventxml, 'description', $description );
$abstract = null;
if( $event->hasEventAbstract() ) {
$abstract = $event->getEventAbstractHTML();
}
add_child( $xml, $eventxml, 'abstract', $abstract );
// Add event fields that don't need any further processing
foreach( $keys as $xml_key => $db_key ) {
add_child( $xml, $eventxml, $xml_key, $event->get( $db_key ) );
}
}
}
$day_index++;
}
$people = EventUser::factory()
->select( [
Event::ID_,
User::ID_,
User::UID,
User::NAME,
User::SURNAME
] )
->from( [
Event::T,
User::T,
] )
->whereInt( Conference::ID , $conference_row->getConferenceID() )
->equals( EventUser::EVENT_, Event::ID_ )
->equals( EventUser::USER_, User ::ID_ )
->orderBy( Event::ID )
->queryGenerator();
$lastid = NULL;
$lastpersons = NULL;
foreach( $people as $row ) {
// This works only because rows are sorted by events
$event_ID = $row->getEventID();
if( $lastid !== $event_ID ) {
$event = $event_ID;
$lastid = $event;
$personsxml = $xml->createElement( 'persons' );
$personsxml = $events_by_id[ $event ]->appendChild( $personsxml );
$lastpersons = $personsxml;
}
$personxml = add_child( $xml, $lastpersons, 'person', $row->getUserFullname() );
$personxml->setAttribute( 'id', $row->getUserID() );
$personxml->setAttribute( 'slug', $row->getUserUID() );
}
http_response_code( 200 );
header( 'Content-type: text/xml; charset=' . CHARSET );
echo $xml->saveXML();
// ----------------------------------------------------------------------------
/**
* Add child to an element and return it
*
* @param $xml DOMDocument
* @param $parent DOMNode
* @param $tagname string
* @param $content string
* @return DOMElement
*/
function add_child( & $xml, $parent, $tagname, $content ) {
$child = $xml->createElement( $tagname );
if( null !== $content && '' !== $content ) {
$child->nodeValue = $content;
}
return $parent->appendChild( $child );
}
diff --git a/documentation/database/patches/patch-1.sql b/documentation/database/patches/patch-1.sql
new file mode 100644
index 0000000..e22b846
--- /dev/null
+++ b/documentation/database/patches/patch-1.sql
@@ -0,0 +1,6 @@
+ALTER TABLE `{$prefix}event` CHANGE `event_description` `event_description_it` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;
+ALTER TABLE `{$prefix}event` ADD `event_description_en` TEXT NULL AFTER `event_description_it`;
+ALTER TABLE `{$prefix}event` CHANGE `event_abstract` `event_abstract_it` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;
+ALTER TABLE `{$prefix}event` ADD `event_abstract_en` TEXT NULL AFTER `event_abstract_it`;
+ALTER TABLE `{$prefix}event` CHANGE `event_note` `event_note_it` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL;
+ALTER TABLE `{$prefix}event` ADD `event_note_en` TEXT NULL AFTER `event_note_it`;
diff --git a/includes/class-Chapter.php b/includes/class-Chapter.php
index c22d253..d215270 100644
--- a/includes/class-Chapter.php
+++ b/includes/class-Chapter.php
@@ -1,93 +1,105 @@
.
trait ChapterTrait {
/**
* Get chapter ID
*
* @return int
*/
public function getChapterID() {
return $this->nonnull( Chapter::ID );
}
/**
* Get chapter UID
*
* @return string
*/
public function getChapterUID() {
return $this->get( Chapter::UID );
}
/**
* Get localized chapter name
*
* @return string
*/
function getChapterName() {
return __( $this->get( Chapter::NAME ) );
}
/**
* Normalize a Chapter object
*/
protected function normalizeChapter() {
$this->integers( Chapter::ID );
}
}
class Chapter extends Queried {
use ChapterTrait;
/**
* Database table name
*/
const T = 'chapter';
/**
* Chapter ID column
*/
const ID = 'chapter_ID';
/**
* Chapter UID column
*/
const UID = 'chapter_uid';
/**
* Chapter NAME column
*/
const NAME = 'chapter_name';
/**
* Complete Chapter ID column
*/
const ID_ = self::T . DOT . self::ID;
/**
* Maximum UID length
*
* @override
*/
const MAXLEN_UID = 32;
- function __construct() {
+ /**
+ * Constructor
+ */
+ public function __construct() {
$this->normalizeChapter();
}
+
+ /**
+ * All the public Chapter fields
+ *
+ * @return string
+ */
+ public static function fields() {
+ return self::T . DOT . STAR;
+ }
}
diff --git a/includes/class-Conference.php b/includes/class-Conference.php
index 9f59834..9c698ee 100644
--- a/includes/class-Conference.php
+++ b/includes/class-Conference.php
@@ -1,278 +1,301 @@
.
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;
}
/**
* 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 );
}
/**
* 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
+ * Description column name
*/
- const SUBTITLE = 'conference_subtitle';
+ const DESCRIPTION = 'conference_description';
/**
- * Description column name
+ * Subtitle column name
*/
- const DESCRIPTION = 'conference_description';
+ 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();
}
+
+ /**
+ * 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 46758b0..eb2b0cc 100644
--- a/includes/class-Event.php
+++ b/includes/class-Event.php
@@ -1,411 +1,459 @@
.
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 );
}
function getEventDescriptionHTML( $args = [] ) {
return Markdown::parse( __( $this->getEventDescription() ), $args );
}
function getEventAbstractHTML( $args = [] ) {
return Markdown::parse( __( $this->getEventAbstract() ), $args );
}
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');
}
/**
* 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;
}
/**
* 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';
/**
- * Abstract column name
+ * 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, 'event_abstract_%s' );
+ }
+
+ /**
+ * Generate the appropriate SELECT for the User Description
+ *
+ * @return string
+ */
+ public static function DESCRIPTION_L10N() {
+ return i18n_coalesce( self::DESCRIPTION, 'event_description_%s' );
+ }
+
+ /**
+ * Generate the appropriate SELECT for the User Description
+ *
+ * @return string
+ */
+ public static function NOTE_L10N() {
+ return i18n_coalesce( self::NOTE, 'event_description_%s' );
+ }
+
+ /**
+ * 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,
+ ];
+ }
}
diff --git a/includes/class-FullConference.php b/includes/class-FullConference.php
index c0071f4..099c714 100644
--- a/includes/class-FullConference.php
+++ b/includes/class-FullConference.php
@@ -1,64 +1,58 @@
.
class_exists( 'Conference' );
class_exists( 'Location' );
/**
* A conference with all the bells and whistles
*/
class FullConference extends Queried {
use ConferenceTrait;
use LocationTrait;
/**
* Constructor
*/
public function __construct() {
$this->normalizeConference();
$this->normalizeLocation();
}
/**
* Query constructor
*
* @return Query
*/
public static function factory() {
- return Query::factory( __CLASS__ )
- ->from( [
- Conference::T,
- Location ::T,
- ] )
- ->equals(
- Conference::T . DOT . Location::ID,
- Location ::T . DOT . Location::ID
- );
+ return ( new QueryConference() )
+ ->joinLocation()
+ ->defaultClass( __CLASS__ );
}
/**
* Query constructor from a certain Conference UID
*
* @param $conference_uid string Conference UID
* @return Query
*/
public static function factoryFromUID( $conference_uid ) {
$conference_uid = Conference::sanitizeUID( $conference_uid );
return self::factory()
->whereStr( Conference::UID, $conference_uid );
}
}
diff --git a/includes/class-FullEvent.php b/includes/class-FullEvent.php
index 6baf41b..be0cc1c 100644
--- a/includes/class-FullEvent.php
+++ b/includes/class-FullEvent.php
@@ -1,210 +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 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_ );
+ 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 = http_build_get_query( '/2016/event-edit.php', $args );
return site_page( $url, $absolute );
}
}
diff --git a/includes/class-Location.php b/includes/class-Location.php
index 6c2f02d..b181aaa 100644
--- a/includes/class-Location.php
+++ b/includes/class-Location.php
@@ -1,189 +1,202 @@
.
trait LocationTrait {
/**
* Get the Location ID
*
* @return int
*/
public function getLocationID() {
return $this->get( Location::ID );
}
/**
* Get localized location name
*
* @return string
*/
public function getLocationName() {
return __( $this->get( Location::NAME ) );
}
/**
* Get localized location address
*
* @return string
*/
public function getLocationAddress() {
return __( $this->get( Location::ADDRESS ) );
}
/**
* Get the Location latitude
*
* @return float|null
*/
public function getLocationGeoLat() {
return $this->get( 'location_lat' );
}
/**
* Get the Location longitude
*
* @return float|null
*/
public function getLocationGeoLng() {
return $this->get( 'location_lng' );
}
/**
* Get localized location note
*
* @return string
*/
public function getLocationNote() {
return __( $this->get( Location::NOTE ) );
}
function getLocationNoteHTML($args = []) {
return Markdown::parse( __( $this->getLocationNote() ), $args );
}
function getLocationGeothumb() {
$g = DEFAULT_IMAGE;
$geothumb = $this->get('location_geothumb');
if( $geothumb ) {
$g = site_page( $geothumb, CURRENT_CONFERENCE_PATH );
}
return $g;
}
/**
* Check if the location has geographical informations
*
* @return boolean
*/
public function locationHasGeo() {
return $this->has('location_lat') &&
$this->has('location_lng');
}
function getLocationZoom() {
$z = $this->get('location_zoom');
return isset( $z ) ? $z : Location::DEFAULT_ZOOM;
}
/**
* Get the URL to this location on OpenStreetMap
*
* @return string
*/
public function getLocationGeoOSM() {
return sprintf(
'https://www.openstreetmap.org/?mlat=%1$s&mlon=%2$s#map=%3$s/%1$s/%2$s',
$this->getLocationGeoLat(),
$this->getLocationGeoLng(),
$this->getLocationZoom()
);
}
/**
* PrintGet a
that can be used to plot a Leaflet map
*
*/
public function printLocationLeaflet() {
printf(
'
',
$this->getLocationGeoLat(),
$this->getLocationGeoLng(),
$this->getLocationZoom()
);
}
function normalizeLocation() {
$this->integers(
'location_ID',
'location_zoom'
);
$this->floats(
'location_lat',
'location_lng'
);
}
}
/**
* A Location is a place that can host Conferences
*/
class Location extends Queried {
use LocationTrait;
/**
* Database table name
*/
const T = 'location';
/**
* ID column name
*/
const ID = 'location_ID';
/**
* Name column name
*/
const NAME = 'location_name';
/**
* Address column name
*/
const ADDRESS = 'location_address';
/**
* Note column name
*/
const NOTE = 'location_note';
/**
* ID complete column name
*/
const ID_ = self::T . DOT . self::ID;
/**
* Maximum UID length
*
* @override Queried::MAXLEN_UID
*/
const MAXLEN_UID = 64;
const DEFAULT_ZOOM = 17;
- function __construct() {
+ /**
+ * Constructor
+ */
+ public function __construct() {
$this->normalizeLocation($this);
}
+
+ /**
+ * All the public Location fields
+ *
+ * @return string
+ */
+ public static function fields() {
+ return self::T . DOT . STAR;
+ }
+
}
diff --git a/includes/class-QueryConference.php b/includes/class-QueryConference.php
new file mode 100644
index 0000000..53717eb
--- /dev/null
+++ b/includes/class-QueryConference.php
@@ -0,0 +1,124 @@
+.
+
+/**
+ * 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->whereInt( $this->CONFERENCE_ID, $conference->getConferenceID() );
+ }
+
+ /**
+ * 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.
+ *
+ * @return self
+ */
+ public function joinLocation() {
+ if( empty( $this->joinedLocation ) ) {
+ $this->joinOn( 'INNER', Location::T, $this->LOCATION_ID, 'location.location_ID' );
+ $this->joinedLocation = true;
+ }
+ return $this;
+ }
+
+}
+
+/**
+ * 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 2417bec..7d18096 100644
--- a/includes/class-QueryEvent.php
+++ b/includes/class-QueryEvent.php
@@ -1,184 +1,181 @@
.
+// load dependent traits
+class_exists( QueryConference::class, true );
+
/**
* Class able to query a FullEvent.
*/
class QueryEvent extends Query {
+ use QueryConferenceTrait;
+
/**
* 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 location ID column name (useful with conference joins)
+ * Univoque Track ID column name
+ *
+ * @var
*/
- protected $LOCATION_ID = 'conference.location_ID';
+ 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 );
}
/**
* Where the Event is...
*
* @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 );
}
/**
* Limit to a certain User
*
* @param $user User
* @return self
*/
public function whereUser( $user ) {
return $this->joinEventUser()
->whereInt( EventUser::USER_, $user->getUserID() );
}
/**
- * Limit to a specific Conference
- *
- * @param $conference Conference
- * @return self
- */
- public function whereConference( $conference ) {
- return $this->joinConference()
- ->whereInt( Event::CONFERENCE_, $conference->getConferenceID() );
- }
-
- /**
- * Exclude a specific Conference
+ * Where the Event UID is this one
*
- * @param $conference Conference
+ * @param string $uid Event UID
* @return self
*/
- public function whereConferenceNot( $conference ) {
- $id = $conference->getConferenceID();
- return $this->joinConference()
- ->whereInt( Event::CONFERENCE_, $id, '<>' );
+ public function whereEventUID( $uid ) {
+ return $this->whereStr( Event::UID, $uid );
}
/**
- * Join Events to their Conference
- *
- * You can call it multiple time safely.
+ * Join a table with the Chapter table
*
* @return self
*/
- public function joinConference() {
- if( empty( $this->joinedConference ) ) {
- $this->from( Conference::T );
- $this->equals( Conference::ID_, Event::CONFERENCE_ );
- $this->joinedConference = true;
- }
- return $this;
+ public function joinChapter() {
+ return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID );
}
/**
- * Join a table with the Chapter table
+ * Join a table with the Track table
*
* @return self
*/
- public function joinChapter() {
- return $this->joinOn( 'INNER', 'chapter', 'chapter.chapter_ID' , $this->CHAPTER_ID );
+ public function joinTrack() {
+ return $this->joinOn( 'INNER', Track::T, Track::ID_, $this->TRACK_ID );
}
/**
- * Join Events to their Location (and Conference. asd)
+ * Join a table with the Room table
*
- * You can call it multiple time safely.
- *
- * @TODO: move this method into QueryConference, and extends QueryEvent
* @return self
*/
- public function joinLocation() {
- if( empty( $this->joinedLocation ) ) {
- $this->joinOn( 'INNER', Location::T, $this->LOCATION_ID, 'location.location_ID' );
- }
- return $this;
+ 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/class-Room.php b/includes/class-Room.php
index f896041..619f9e1 100644
--- a/includes/class-Room.php
+++ b/includes/class-Room.php
@@ -1,99 +1,108 @@
.
trait RoomTrait {
/**
* Get room ID
*
* @return int
*/
public function getRoomID() {
return $this->get( Room::ID );
}
/**
* Get room UID
*
* @return string
*/
public function getRoomUID() {
return $this->get( Room::UID );
}
/**
* Get localized room name
*
* @return string
*/
public function getRoomName() {
return __( $this->get( ROOM::NAME ) );
}
/**
* Normalize a Room object
*/
protected function normalizeRoom() {
$this->integers( Room::ID );
}
}
/**
* A Room host Talks and it's in a Location
*/
class Room extends Queried {
use RoomTrait;
/**
* Database table name
*/
const T = 'room';
/**
* Maximum UID length
*
* @override Queried::MAXLEN_UID
*/
const MAXLEN_UID = 64;
/**
* Room ID column
*/
const ID = 'room_ID';
/**
* Room UID column
*/
const UID = 'room_uid';
/**
* Room name column
*/
const NAME = 'room_name';
/**
* Complete ID column name
*/
const ID_ = self::T . DOT . self::ID;
/**
* Constructor
*/
public function __construct() {
$this->normalizeRoom();
}
+
+ /**
+ * All the public room fields
+ *
+ * @return string
+ */
+ public static function fields() {
+ return Room::T . DOT . STAR;
+ }
}
diff --git a/includes/class-Track.php b/includes/class-Track.php
index e0e0518..f7ba153 100644
--- a/includes/class-Track.php
+++ b/includes/class-Track.php
@@ -1,119 +1,128 @@
.
trait TrackTrait {
/**
* Get the track ID
*
* @return int
*/
public function getTrackID() {
return $this->nonnull( Track::ID );
}
/**
* Get the track UID
*
* @return string
*/
public function getTrackUID() {
return $this->get( Track::UID );
}
/**
* Get the localized track name
*
* @return string
*/
function getTrackName() {
return __( $this->get( Track::NAME ) );
}
/**
* Get the localized track label
*
* @return string
*/
function getTrackLabel() {
return __( $this->get( Track::LABEL ) );
}
/**
* Normalize a Track object
*/
protected function normalizeTrack() {
$this->integers(
Track::ID,
Track::ORDER
);
}
}
/**
* A Track is the theme of a Talk
*/
class Track extends Queried {
use TrackTrait;
/**
* Database table name
*/
const T = 'track';
/**
* ID column name
*/
const ID = 'track_ID';
/**
* UID column name
*/
const UID = 'track_uid';
/**
* Name column name
*/
const NAME = 'track_name';
/**
* Label column name
*/
const LABEL = 'track_label';
/**
* Order column name
*/
const ORDER = 'track_order';
/**
* Complete ID column name
*/
const ID_ = self::T . DOT . self::ID;
/**
* Maximum UID length
*/
const MAXLEN_UID = 64;
/**
* Constructor
*/
public function __construct() {
$this->normalizeTrack();
}
+
+ /**
+ * All the public Track fields
+ *
+ * @return string
+ */
+ public static function fields() {
+ return self::T . DOT . STAR;
+ }
}
diff --git a/includes/class-User.php b/includes/class-User.php
index 9573bf1..017719e 100644
--- a/includes/class-User.php
+++ b/includes/class-User.php
@@ -1,435 +1,455 @@
.
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 );
}
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' );
}
+
+ /**
+ * Get all the public User fields
+ *
+ * @return array
+ */
+ public static function fields() {
+ return [
+ self::ID,
+ self::UID,
+ self::GRAVATAR,
+ self::NAME,
+ self::SURNAME,
+ self::IMAGE,
+ self::WEBSITE,
+ self::LOVED_LICENSE,
+ self::BIO_L10N(),
+ ];
+ }
+
}
diff --git a/includes/functions.php b/includes/functions.php
index 1983448..f1ce59f 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -1,132 +1,134 @@
.
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
: 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 );
}