Posted By

ArsonDPI on 12/25/12


Tagged


Versions (?)

format.random_centered_image.php for ndxz v.2


 / Published in: PHP
 

a customized random image plugin for ndxz v2

  1. <?php if (!defined('SITE')) exit('No direct script access allowed');
  2.  
  3. /*
  4. Format Name: Random Image
  5. Format URI: http://www.indexhibit.org/format/random-image/
  6. Description: Returns a random image from the exhibit.
  7. Version: 1.0
  8. Author: Indexhibit
  9. Author URI: http://indexhibit.org/
  10. Params: format,images
  11. Source: exhibit
  12. Objects: exhibits
  13. */
  14.  
  15. class Exhibit
  16. {
  17. function Exhibit()
  18. {
  19.  
  20. }
  21.  
  22.  
  23. function createExhibit()
  24. {
  25. $OBJ =& get_instance();
  26. global $default;
  27. $OBJ->page->exhibit['dyn_css'][] = $this->dynamicCSS();
  28.  
  29. // exhibit only source
  30. $this->source = $default['filesource'][0];
  31.  
  32. // get images
  33. $OBJ->vars->images = $OBJ->page->get_imgs();
  34.  
  35. // if no images return our text only
  36. if (!$OBJ->vars->images[0]) { $OBJ->page->exhibit['exhibit'] = $OBJ->vars->exhibit['content']; return; }
  37.  
  38. $total = count($OBJ->vars->images[0]);
  39. $rand = rand(0, ($total - 1));
  40.  
  41. $s = "\n<div id='img-container' style='margin-bottom: 3px;'>\n";
  42.  
  43. // if image
  44. if (in_array($OBJ->vars->images[0][$rand]['media_mime'], $default['images']))
  45. {
  46. $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>";
  47. }
  48. else
  49. {
  50. $mime = $OBJ->vars->images[0][$rand]['media_mime'];
  51.  
  52. $s .= $mime($OBJ->vars->images[0][$rand]['media_file'],
  53. $OBJ->vars->images[0][$rand]['media_x'],
  54. $OBJ->vars->images[0][$rand]['media_y'],
  55. $OBJ->vars->images[0][$rand]['media_thumb']);
  56. }
  57.  
  58. $s .= "</div>\n";
  59.  
  60. $OBJ->page->exhibit['exhibit'] = ($OBJ->vars->exhibit['placement'] == 1) ?
  61. $s . $OBJ->vars->exhibit['content'] :
  62. $OBJ->vars->exhibit['content'] . $s;
  63.  
  64. return $OBJ->page->exhibit['exhibit'];
  65. }
  66.  
  67. function dynamicCSS()
  68. {
  69. return "#img-container img {
  70. display: table;
  71. margin: 0 auto;
  72. }";
  73. }
  74. }

Report this snippet  

You need to login to post a comment.