2015-08-19 20:22:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A formatter for the notification flyout popup
|
|
|
|
*
|
|
|
|
* Ideally we wouldn't need this and we'd just pass the
|
|
|
|
* presentation model to the client, but we need to continue
|
|
|
|
* sending HTML for backwards compatibility.
|
|
|
|
*/
|
|
|
|
class EchoFlyoutFormatter extends EchoEventFormatter {
|
2015-10-29 21:13:10 +00:00
|
|
|
protected function formatModel( EchoEventPresentationModel $model ) {
|
2015-08-19 20:22:45 +00:00
|
|
|
$icon = Html::element(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'class' => 'mw-echo-icon',
|
|
|
|
'src' => $this->getIconURL( $model ),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$html = Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-title' ),
|
|
|
|
$model->getHeaderMessage()->parse()
|
|
|
|
) . "\n";
|
|
|
|
|
2015-11-04 20:41:29 +00:00
|
|
|
$body = $model->getBodyMessage();
|
|
|
|
if ( $body ) {
|
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
2015-11-19 04:10:40 +00:00
|
|
|
array( 'class' => 'mw-echo-payload' ),
|
2015-11-04 20:41:29 +00:00
|
|
|
$body->parse()
|
|
|
|
) . "\n";
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
$ts = $this->language->getHumanTimestamp(
|
2015-10-29 21:13:10 +00:00
|
|
|
new MWTimestamp( $model->getTimestamp() ),
|
2015-08-19 20:22:45 +00:00
|
|
|
null,
|
|
|
|
$this->user
|
|
|
|
);
|
|
|
|
|
|
|
|
$footerItems = array( $ts );
|
2015-11-19 15:41:18 +00:00
|
|
|
$secondaryLinks = $this->normalizeSecondaryLinks( $model->getSecondaryLinks() );
|
|
|
|
foreach ( $secondaryLinks as $link ) {
|
|
|
|
$footerItems[] = Html::element( 'a', array( 'href' => $link['url'] ), $link['label'] );
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|
|
|
|
$html .= Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-notification-footer' ),
|
|
|
|
$this->language->pipeList( $footerItems )
|
|
|
|
) . "\n";
|
|
|
|
|
2015-11-02 23:55:17 +00:00
|
|
|
// Add the primary link afterwards, if it has one
|
|
|
|
$primaryLink = $model->getPrimaryLink();
|
|
|
|
if ( $primaryLink !== false ) {
|
2015-11-19 15:41:18 +00:00
|
|
|
$primaryLink = $this->normalizePrimaryLink( $primaryLink );
|
2015-11-02 23:55:17 +00:00
|
|
|
$html .= Html::element(
|
|
|
|
'a',
|
2015-11-19 15:41:18 +00:00
|
|
|
array( 'class' => 'mw-echo-notification-primary-link', 'href' => $primaryLink['url'] ),
|
|
|
|
$primaryLink['label']
|
2015-11-02 23:55:17 +00:00
|
|
|
) . "\n";
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
|
|
|
|
// Wrap everything in mw-echo-content class
|
|
|
|
$html = Xml::tags( 'div', array( 'class' => 'mw-echo-content' ), $html );
|
|
|
|
|
|
|
|
// And then add the icon in front and wrap with mw-echo-state class.
|
|
|
|
$html = Xml::tags( 'div', array( 'class' => 'mw-echo-state' ), $icon . $html );
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getIconURL( EchoEventPresentationModel $model ) {
|
|
|
|
return EchoNotificationFormatter::getIconUrl(
|
|
|
|
$model->getIconType(),
|
|
|
|
$this->language->getDir()
|
|
|
|
);
|
|
|
|
}
|
2015-11-19 15:41:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility method to ensure B/C compat with previous getPrimaryLink return
|
|
|
|
* types, until all of them have been fixed.
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* @param string|array|bool $link
|
|
|
|
* @return string|bool
|
|
|
|
*/
|
|
|
|
protected function normalizePrimaryLink( $link ) {
|
|
|
|
// B/C for old format: [url, label]
|
|
|
|
if ( !isset( $link['url'] ) ) {
|
|
|
|
return array(
|
|
|
|
'url' => $link[0],
|
|
|
|
'label' => $link[1],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// current primary link format: ['url' => ..., 'label' => ...]
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility method to ensure B/C compat with previous getSecondaryLinks
|
|
|
|
* return types, until all of them have been fixed.
|
|
|
|
*
|
|
|
|
* @deprecated
|
|
|
|
* @param array $link
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function normalizeSecondaryLinks( array $link ) {
|
|
|
|
// B/C for old secondary links format: [url => label, ...]
|
|
|
|
if ( !isset( $link[0] ) || !isset( $link[0]['url'] ) ) {
|
|
|
|
$links = array();
|
|
|
|
foreach ( $link as $url => $text ) {
|
|
|
|
$links[] = array(
|
|
|
|
'url' => $url,
|
|
|
|
'label' => $text,
|
|
|
|
'description' => '',
|
|
|
|
'icon' => false,
|
|
|
|
'prioritized' => false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $links;
|
|
|
|
}
|
|
|
|
|
|
|
|
// current secondary links format: [['url' => ..., 'label' => ..., ...], ...]
|
|
|
|
return $link;
|
|
|
|
}
|
2015-08-19 20:22:45 +00:00
|
|
|
}
|