public function testRandomFeaturedItems() { $randomFeaturedItems = get_random_featured_items(); $this->assertEquals(5, count($randomFeaturedItems)); $randomFeaturedItemsWithImages = get_random_featured_items('5', true); $this->assertEquals(5, count($randomFeaturedItemsWithImages)); foreach ($randomFeaturedItemsWithImages as $randomItem) { $this->assertTrue(metadata($randomItem, 'has files')); } }
function rhythm_display_random_featured_item_squarethumb() { $featuredItems = get_random_featured_items(1); $featuredItem = $featuredItems[0]; $html = '<h2>Featured <span class="type-featured">Item</span></h2>'; if ($featuredItem) { set_current_record('item', $featuredItem); // Needed for transparent access of item metadata. if (metadata('item', 'has thumbnail')) { $html .= link_to_item(item_square_thumbnail(), array('class' => 'image')); } // Grab the 1st Dublin Core description field (first 150 characters) $itemDescription = metadata('item', array('Dublin Core', 'Description'), array('snippet' => 150)); $html .= '<p><span class="title">' . link_to_item() . '</span> ' . $itemDescription . '</p>'; } else { $html .= '<p>No featured items are available.</p>'; } return $html; }
/** * Get HTML for random featured items. * * @package Omeka\Function\View\Item * @uses get_random_featured_items() * @param int $count Maximum number of items to show. * @param boolean $withImage Whether or not the featured items must have * images associated. If null, as default, all featured items can appear, * whether or not they have files. If true, only items with files will appear, * and if false, only items without files will appear. * @return string */ function random_featured_items($count = 5, $hasImage = null) { $items = get_random_featured_items($count, $hasImage); if ($items) { $html = ''; foreach ($items as $item) { $html .= get_view()->partial('items/single.php', array('item' => $item)); release_object($item); } } else { $html = '<p>' . __('No featured items are available.') . '</p>'; } return $html; }
</div> <?php if ($description) { ?> <p class="item-description"><?php echo $description; ?> </p> <?php } ?> </div> <div style="float:right;clear:both;margin-bottom:-20px;"><p> <?php $featuredItems = get_random_featured_items(5); usort($featuredItems, function ($a, $b) { return $a['id'] - $b['id']; }); $i = 0; $positions = array(); foreach ($featuredItems as $fItem) { $positions[$i] = $fItem['id']; $num = $i + 1; if ($fItem['id'] == $item->id) { echo '<a href="' . url('items/browse/items/browse?search=&advanced[0][element_id]=&advanced[0][type]=&advanced[0][terms]=&range=&collection=&type=&user=&tags=&public=&featured=1&exhibit=&submit_search=Search+for+items') . "\">View all " . count($featuredItems) . ' featured items.</a>'; } $i += 1; } ?>
function mh_display_random_item($num = 1) { echo $num <= 1 ? '<h2>Random ' . mh_item_label() . '</h2>' : '<h2>Random ' . mh_item_label('plural') . '</h2>'; set_loop_records('items', get_random_featured_items($num, true)); if (has_loop_records('items')) { foreach (loop('items') as $item) { echo '<article class="item-result">'; echo '<h3>' . link_to_item(metadata($item, array('Dublin Core', 'Title'))) . '</h3>'; echo '<div class="item-thumb">' . link_to_item(item_image('square_thumbnail')) . '</div>'; if ($desc = metadata($item, array('Dublin Core', 'Description'), array('snippet' => 200))) { echo '<div class="item-description">' . $desc . '</div>'; } else { echo '<div class="item-description">Text preview unavailable.</div>'; } echo '</article>'; } } echo '<p class="view-more-link">' . link_to_items_browse('View all ' . mh_item_label('plural') . '') . '</p>'; }
public function hookPublicHead($args) { $title = ''; $description = ''; $image_url = ''; // Is the curent record an exhibit? Use its metadata. try { $exhibit = get_current_record('exhibit'); $title = metadata($exhibit, 'title', array('no_escape' => false)); $description = metadata($exhibit, 'description', array('no_escape' => false)); $file = $exhibit->getFile(); if ($file) { $image_url = file_display_url($file, 'fullsize'); } } catch (Omeka_View_Exception $ove) { // no exhibit, don't do anything } // Is the curent record an item? Use its metadata. try { $item = get_current_record('item'); $title = metadata('item', array('Dublin Core', 'Title')); $description = metadata('item', array('Dublin Core', 'Description')); if (strlen($title) > 0 && strlen($description) > 0) { foreach (loop('files', $item->Files) as $file) { if ($file->hasThumbnail()) { $image_url = file_display_url($file, 'fullsize'); break; } } } } catch (Omeka_View_Exception $ove) { // no item, don't do anything } // Is the curent record an collection? Use its metadata. try { $collection = get_current_record('collection'); $title = metadata('collection', array('Dublin Core', 'Title')); $description = metadata('collection', array('Dublin Core', 'Description')); $file = $collection->getFile(); if ($file) { $image_url = file_display_url($file, 'fullsize'); } } catch (Omeka_View_Exception $ove) { // no collection, don't do anything } // Default to the site settings if we didn't find anything else to use if (strlen($title) < 1 || strlen($description) < 1) { $title = option('site_title'); $description = option('description'); $items = get_random_featured_items(1, true); if (isset($items[0])) { foreach (loop('files', $items[0]->Files) as $file) { if ($file->hasThumbnail()) { $image_url = file_display_url($file, 'fullsize'); break; } } } } if (strlen($title) > 0 && strlen($description) > 0) { echo '<meta property="twitter:card" content="summary" />'; echo '<meta property="twitter:site" content="' . get_option(TWITTER_CARDS_SITE_HANDLE_OPTION) . '" />'; echo '<meta property="twitter:title" content="' . strip_tags(html_entity_decode($title)) . '" />'; echo '<meta property="twitter:description" content="' . strip_tags(html_entity_decode($description)) . '" />'; echo '<meta property="og:title" content="' . strip_tags(html_entity_decode($title)) . '" />'; echo '<meta property="og:description" content="' . strip_tags(html_entity_decode($description)) . '" />'; if (strlen($image_url) > 0) { echo '<meta property="twitter:image:src" content="' . $image_url . '" />'; echo '<meta property="og:image" content="' . $image_url . '" />'; echo '<link rel="image_src" type="image/jpeg" href="' . $image_url . '" />'; } } }
?> <div id="sort-links"> <span class="sort-label"><?php echo __('Sort by: '); ?> </span><?php echo browse_sort_links($sortLinks); ?> </div> <?php } ?> <?php if (count(get_random_featured_items()) > 0) { ?> <div id="featured-item"> <h2><?php echo __('Featured Item'); ?> </h2> <?php echo random_featured_items(1); ?> </div> <?php } ?> <div class="items-list">