Skip to content

Commit

Permalink
Added a link to display the resource in public view from the admin pa…
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Dec 16, 2018
1 parent 23bc95c commit ed793b1
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This is an equivalent for the [shortcode as a page] in Omeka classic too.

Display direct links to the current resource in the public user bar in order to
simplify edition and management of resources (fix [#1283]).
The revert links are available too. They display the resource in the default
site, or in the first one (fix [#1259]).

#### Random order of resources

Expand Down Expand Up @@ -148,6 +150,7 @@ Copyright
[shortcode as a page]: https://github.com/omeka/plugin-SimplePages/pull/24
[#1156]: https://github.com/omeka/omeka-s/issues/1156
[#1258]: https://github.com/omeka/omeka-s/issues/1258
[#1259]: https://github.com/omeka/omeka-s/issues/1259
[#1274]: https://github.com/omeka/omeka-s/issues/1274
[#1276]: https://github.com/omeka/omeka-s/issues/1276
[#1281]: https://github.com/omeka/omeka-s/issues/1281
Expand Down
1 change: 1 addition & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'factories' => [
'defaultSiteSlug' => Service\ViewHelper\DefaultSiteSlugFactory::class,
'logger' => Service\ViewHelper\LoggerFactory::class,
'publicResourceUrl' => Service\ViewHelper\PublicResourceUrlFactory::class,
],
],
'block_layouts' => [
Expand Down
25 changes: 25 additions & 0 deletions src/Service/ViewHelper/PublicResourceUrlFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace Next\Service\ViewHelper;

use Interop\Container\ContainerInterface;
use Next\View\Helper\PublicResourceUrl;
use Zend\ServiceManager\Factory\FactoryInterface;

/**
* Service factory for the PublicResourceUrlFactory view helper.
*
* @todo Set a setting for the default site of the user.
*/
class PublicResourceUrlFactory implements FactoryInterface
{
/**
* Create and return the PublicResourceUrl view helper
*
* @return PublicResourceUrl
*/
public function __invoke(ContainerInterface $services, $requestedName, array $options = null)
{
$defaultSiteSlug = $services->get('ViewHelperManager')->get('defaultSiteSlug');
return new PublicResourceUrl($defaultSiteSlug());
}
}
43 changes: 43 additions & 0 deletions src/View/Helper/PublicResourceUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Next\View\Helper;

use Omeka\Api\Representation\AbstractResourceRepresentation;
use Zend\View\Helper\AbstractHelper;

/**
* View helper to return the url to the public default site page of a resource.
*/
class PublicResourceUrl extends AbstractHelper
{
/**
* @var string
*/
protected $defaultSiteSlug;

/**
* Construct the helper.
*
* @param string|null $defaultSiteSlug
*/
public function __construct($defaultSiteSlug)
{
$this->defaultSiteSlug = $defaultSiteSlug;
}

/**
* Return the url to the public default site page or a resource.
*
* @uses AbstractResourceRepresentation::siteUrl()
*
* @param AbstractResourceRepresentation $resource
* @param bool $canonical Whether to return an absolute URL
* @return string
*/
public function __invoke(AbstractResourceRepresentation $resource, $canonical = false)
{
// Manage the case where there is no site.
return $this->defaultSiteSlug
? $resource->siteUrl($this->defaultSiteSlug, $canonical)
: '';
}
}
86 changes: 86 additions & 0 deletions view/omeka/admin/item-set/show.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'item-sets show');
$viewItemsLink = $this->url(
'admin/default',
['controller' => 'item', 'action' => 'browse'],
[
'query' => [
'item_set_id' => $itemSet->id()
]
]
);
if ($owner = $itemSet->owner()) {
$ownerText = $escape($itemSet->owner()->name());
} else {
$ownerText = $translate('[no owner]');
}

$sectionNavs = [
'item-set-metadata' => $translate('Metadata'),
'item-set-linked' => $translate('Linked resources'),
];
?>

<?php echo $this->pageTitle($itemSet->displayTitle(), 1, $translate('Item sets')); ?>

<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($itemSet), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($itemSet->userIsAllowed('update')): ?>
<?php echo $itemSet->link($translate('Edit item set'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
<a href="<?php echo $viewItemsLink; ?>" class="button"><?php echo $translate('View items'); ?></a>
</div>

<?php echo $this->sectionNav($sectionNavs, 'view.show.section_nav', $itemSet); ?>

<div id="item-set-metadata" class="active section">
<?php if ( $itemSet->resourceClass()): ?>
<div class="meta-group">
<h4><?php echo $translate('Class'); ?></h4>
<div class="value"><?php echo $escape($itemSet->resourceClass()->label()); ?></div>
</div>
<?php endif; ?>
<?php echo $itemSet->displayValues(); ?>
</div>

<div id="item-set-linked" class="section">
<?php
$page = $this->params()->fromQuery('page', 1);
$property = $this->params()->fromQuery('property');
$subjectValues = $itemSet->displaySubjectValues($page, 25);
?>
<?php if ($subjectValues): ?>
<p><?php echo $translate('The following resources link to this item set:'); ?></p>
<?php echo $subjectValues; ?>
<?php else: ?>
<div class="no-resources">
<p><?php echo $translate('No resources link to this item set.'); ?></p>
</div>
<?php endif; ?>
</div>


<div class="active sidebar">
<div class="meta-group">
<h4><?php echo $translate('Created'); ?></h4>
<div class="value"><?php echo $escape($this->i18n()->dateFormat($itemSet->created())); ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Owner'); ?></h4>
<div class="value"><?php echo $ownerText; ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Visibility'); ?></h4>
<div class="value"><?php echo ($itemSet->isPublic()) ? $escape($translate('Public')) : $escape($translate('Private')); ?></div>
<div class="value"><?php echo ($itemSet->isOpen()) ? $escape($translate('Open to additions')) : $escape($translate('Closed to additions')); ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Items'); ?></h4>
<div class="value"><?php echo $this->hyperlink($itemSet->itemCount(), $this->url('admin/default', ['controller' => 'item', 'action' => 'browse'], ['query' => ['item_set_id' => $itemSet->id()]])); ?></div>
</div>
<?php $this->trigger('view.show.sidebar'); ?>
</div>

<?php $this->trigger('view.show.after'); ?>
88 changes: 88 additions & 0 deletions view/omeka/admin/item/show.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'items show');
if ($owner = $item->owner()) {
$ownerText = $escape($item->owner()->name());
} else {
$ownerText = $translate('[no owner]');
}

$sectionNavs = [
'item-metadata' => $translate('Metadata'),
'item-linked' => $translate('Linked resources'),
];
?>
<?php echo $this->pageTitle($item->displayTitle(), 1, $translate('Items')); ?>
<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($item), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($item->userIsAllowed('update')): ?>
<?php echo $item->link($translate('Edit item'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
</div>

<?php echo $this->sectionNav($sectionNavs, 'view.show.section_nav', $item); ?>

<div id="item-metadata" class="active section">
<?php if ( $item->resourceClass()): ?>
<div class="meta-group">
<h4><?php echo $translate('Class'); ?></h4>
<div class="value"><?php echo $escape($translate($item->resourceClass()->label())); ?></div>
</div>
<?php endif; ?>
<?php echo $item->displayValues(); ?>
</div>

<div id="item-linked" class="section">
<?php
$page = $this->params()->fromQuery('page', 1);
$property = $this->params()->fromQuery('property');
$subjectValues = $item->displaySubjectValues($page, 25, $property);
?>
<?php if ($subjectValues): ?>
<p><?php echo $translate('The following resources link to this item:'); ?></p>
<?php echo $subjectValues; ?>
<?php else: ?>
<div class="no-resources">
<p><?php echo $translate('No resources link to this item.'); ?></p>
</div>
<?php endif; ?>
</div>


<div class="sidebar active">
<?php echo $this->thumbnail($item, 'square'); ?>
<div class="meta-group">
<h4><?php echo $translate('Visibility'); ?></h4>
<div class="value"><?php echo ($item->isPublic()) ? $escape($translate('Public')) : $escape($translate('Private')); ?></div>
</div>
<?php $itemsets = $item->itemSets(); ?>
<?php if (count($itemsets) > 0): ?>
<div class="meta-group">
<h4><?php echo $translate('Item sets'); ?></h4>
<?php foreach ($itemsets as $itemset): ?>
<div class="value item-sets"><?php echo $itemset->link($itemset->displayTitle()); ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="meta-group">
<h4><?php echo $translate('Created'); ?></h4>
<div class="value"><?php echo $escape($this->i18n()->dateFormat($item->created())); ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Owner'); ?></h4>
<div class="value"><?php echo $ownerText; ?></div>
</div>
<?php if ($item->media()): ?>
<div class="meta-group">
<h4><?php echo $translate('Media'); ?></h4>
<?php foreach ($item->media() as $media): ?>
<div class="value">
<?php echo $media->linkPretty(); ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php $this->trigger('view.show.sidebar'); ?>
</div>
<?php $this->trigger('view.show.after'); ?>
85 changes: 85 additions & 0 deletions view/omeka/admin/media/show.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
$translate = $this->plugin('translate');
$escape = $this->plugin('escapeHtml');
$this->htmlElement('body')->appendAttribute('class', 'media show');

$sectionNavs = [
'media-metadata' => $translate('Metadata'),
];
?>

<?php echo $this->pageTitle($media->displayTitle(), 1, $translate('Media')); ?>

<div id="page-actions">
<?php echo $this->hyperlink($translate('Public view'), $this->publicResourceUrl($media), ['class' => 'button', 'target' => '_blank']); ?>
<?php if ($media->userIsAllowed('update')): ?>
<?php echo $media->link($translate('Edit media'), 'edit', ['class' => 'button']); ?>
<?php endif; ?>
</div>

<?php echo $this->sectionNav($sectionNavs, 'view.show.section_nav', $media); ?>

<div id="media-metadata" class="active section">
<?php echo $media->render(); ?>
<?php if ( $media->resourceClass()): ?>
<div class="meta-group">
<h4><?php echo $translate('Class'); ?></h4>
<div class="value"><?php echo $media->resourceClass()->label(); ?></div>
</div>
<?php endif; ?>
<?php echo $media->displayValues(); ?>
</div>

<div class="sidebar active">
<div class="meta-group">
<h4><?php echo $translate('Visibility'); ?></h4>
<div class="value"><?php echo ($media->isPublic()) ? $translate('Public') : $translate('Private'); ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Part of item'); ?></h4>
<?php $mediaItem = $media->item(); ?>
<div class="value"><?php echo $mediaItem->link($mediaItem->displayTitle()); ?></div>
</div>
<div class="meta-group">
<h4><?php echo $translate('Created'); ?></h4>
<div class="value"><?php echo $escape($this->i18n()->dateFormat($media->created())); ?></div>
</div>
<?php if ($media->mediaType()): ?>
<div class="meta-group">
<h4><?php echo $translate('MIME type'); ?></h4>
<div class="value"><?php echo $escape($media->mediaType()); ?></div>
</div>
<?php endif; ?>
<?php if (is_numeric($resource->size())): ?>
<div class="meta-group">
<h4><?php echo $translate('Size'); ?></h4>
<div class="value"><?php echo sprintf($translate('%s bytes'), number_format($resource->size())); ?></div>
</div>
<?php endif; ?>
<div class="meta-group">
<h4><?php echo $translate('Ingester'); ?></h4>
<div class="value"><?php echo $escape($translate($media->ingesterLabel())); ?></div>
</div>
<?php if ($media->source()): ?>
<div class="meta-group">
<h4><?php echo $translate('Source'); ?></h4>
<div class="value"><?php echo $escape($media->source()); ?></div>
</div>
<?php endif; ?>
<?php if ($media->hasThumbnails() || $media->hasOriginal()): ?>
<div class="meta-group">
<h4><?php echo $translate('File Derivatives'); ?></h4>
<?php if ($media->hasOriginal()): ?>
<div class="value"><a href="<?php echo $escape($media->originalUrl()); ?>"><?php echo $translate('original'); ?></a></div>
<?php endif; ?>
<?php if ($media->hasThumbnails()): ?>
<div class="value"><a href="<?php echo $escape($media->thumbnailUrl('large')); ?>"><?php echo $translate('large'); ?></a></div>
<div class="value"><a href="<?php echo $escape($media->thumbnailUrl('medium')); ?>"><?php echo $translate('medium'); ?></a></div>
<div class="value"><a href="<?php echo $escape($media->thumbnailUrl('square')); ?>"><?php echo $translate('square'); ?></a></div>
<?php endif; ?>
</div>
<?php endif; ?>
<?php $this->trigger('view.show.sidebar'); ?>
</div>

<?php $this->trigger('view.show.after'); ?>

0 comments on commit ed793b1

Please sign in to comment.