Return to Snippet

Revision: 61600
at December 25, 2012 05:19 by ArsonDPI


Initial Code
<?php if (!defined('SITE')) exit('No direct script access allowed');

/*
Format Name: Random Image
Format URI: http://www.indexhibit.org/format/random-image/
Description: Returns a random image from the exhibit.
Version: 1.0
Author: Indexhibit
Author URI: http://indexhibit.org/
Params: format,images
Source: exhibit
Objects: exhibits
*/

class Exhibit
{
	function Exhibit()
	{

	}
	
	
	function createExhibit()
	{
		$OBJ =& get_instance();
		global $default;
		$OBJ->page->exhibit['dyn_css'][] = $this->dynamicCSS();
		
		// exhibit only source
		$this->source = $default['filesource'][0];
	
		// get images
		$OBJ->vars->images = $OBJ->page->get_imgs();

		// if no images return our text only
		if (!$OBJ->vars->images[0]) { $OBJ->page->exhibit['exhibit'] = $OBJ->vars->exhibit['content']; return; }
		
		$total = count($OBJ->vars->images[0]);
		$rand = rand(0, ($total - 1));
		
		$s = "\n<div id='img-container' style='margin-bottom: 3px;'>\n";
		
		// if image
		if (in_array($OBJ->vars->images[0][$rand]['media_mime'], $default['images']))
		{
			$s .= "<img src='" . $OBJ->vars->images[0][$rand]['media_path'] . "' alt='" . $OBJ->vars->images[0][$rand]['media_title'] . "'/><p class='random_img_title'>" . $OBJ->vars->images[0][$rand]['media_title'] . "</p><p class='random_img_caption'>" . $OBJ->vars->images[0][$rand]['media_caption'] . "</p>";
		}
		else
		{
			$mime = $OBJ->vars->images[0][$rand]['media_mime'];

			$s .= $mime($OBJ->vars->images[0][$rand]['media_file'], 
				$OBJ->vars->images[0][$rand]['media_x'], 
				$OBJ->vars->images[0][$rand]['media_y'], 
				$OBJ->vars->images[0][$rand]['media_thumb']);
		}
		
		$s .= "</div>\n";
		
		$OBJ->page->exhibit['exhibit'] = ($OBJ->vars->exhibit['placement'] == 1) ? 
			$s . $OBJ->vars->exhibit['content'] : 
			$OBJ->vars->exhibit['content'] . $s;

		return $OBJ->page->exhibit['exhibit'];
	}

	function dynamicCSS()
	{
		return "#img-container img {
		display: table;
		margin: 0 auto;
		}";
	}
}

Initial URL


Initial Description
a customized random image plugin for ndxz v2

Initial Title
format.random_centered_image.php for ndxz v.2

Initial Tags


Initial Language
PHP