1<?php 2 3class module_galerie extends Module 4{ 5 function module_galerie() 6 { 7 $this->i18n = True; 8 $this->arguments = array( 9 'imagedirurl' => array( 10 'type' => 'textfield', 11 'label' => lang('URL pointing to the directory where the images are found (no trailing slash)') 12 ), 13 'imagedirpath' => array( 14 'type' => 'textfield', 15 'label' => lang('Filesystem path of the directory where the images are found (no trailing slash)') 16 ), 17 'imagename' => array( 18 'type' => 'textfield', 19 'label' => lang('the images\' common name') 20 ), 21 'imagetype' => array( 22 'type' => 'select', 23 'label' => lang('image type'), 24 'options' => array( 25 'jpeg' => 'jpeg', 26 'gif' => 'gif', 27 'png' => 'png' 28 ) 29 ), 30 ); 31 $this->title = lang('Galerie'); 32 $this->post = array( 33 'prev' => array( 34 'type' => 'submit', 35 'value' => "<---" 36 ), 37 'next' => array( 38 'type' => 'submit', 39 'value' => "--->" 40 ) 41 ); 42 $this->session = array('filenumber'); 43 $this->description = lang('A simple picture galery'); 44 } 45 46 function get_user_interface() 47 { 48 $this->set_subtext_args(); 49 return parent::get_user_interface(); 50 } 51 52 function get_translation_interface($fromblock,$toblock) 53 { 54 $this->set_subtext_args(); 55 return parent::get_translation_interface($fromblock,$toblock); 56 } 57 58 function set_subtext_args() 59 { 60 $defaults = $this->block->arguments; 61 if ($defaults['imagedirpath'] && is_dir($defaults['imagedirpath'])) 62 { 63 $i = 1; 64 $this->arguments['subtext'] = array( 65 'type' => "array", 66 'i18n' => True 67 ); 68 while (file_exists($defaults['imagedirpath'] . SEP . $defaults['imagename'] . $i . '.' . $defaults['imagetype'])) 69 { 70 $this->arguments['subtext'][$i-1] = array( 71 'type' => 'textfield', 72 'label' => 'Subtext for image ' . $i . '<br /><img src="' . 73 $defaults['imagedirurl'] . SEP . $defaults['imagename'] . $i . '.' . $defaults['imagetype'] . '" />', 74 'i18n' => True 75 ); 76 $i++; 77 } 78 } 79 } 80 81 function set_block(&$block,$produce=False) 82 { 83 parent::set_block($block,$produce); 84 85 if ($produce) 86 { 87 if (!$this->block->arguments['filenumber']) 88 { 89 $this->block->arguments['filenumber'] = 1; 90 } 91 else 92 { 93 $this->block->arguments['filenumber'] = (int)$this->block->arguments['filenumber']; 94 } 95 if ($this->block->arguments['next']) 96 { 97 $this->block->arguments['filenumber']++; 98 } 99 elseif ($this->block->arguments['prev']) 100 { 101 $this->block->arguments['filenumber']--; 102 } 103 if ($this->block->arguments['filenumber'] < 1 || !file_exists( 104 $this->block->arguments['imagedirpath'] . SEP . $this->block->arguments['imagename'] . 105 $this->block->arguments['filenumber'] . '.' . $this->block->arguments['imagetype'] 106 )) 107 { 108 $this->block->arguments['filenumber'] = 1; 109 } 110 $prevlink = ($this->block->arguments['filenumber'] > 1) ? $this->build_post_element('prev') : ''; 111 $nextlink = 112 (file_exists( 113 $this->block->arguments['imagedirpath'] . SEP . $this->block->arguments['imagename'] . 114 ($this->block->arguments['filenumber'] + 1) . '.' . $this->block->arguments['imagetype'] 115 )) ? 116 $this->build_post_element('next') : 117 ''; 118 require_once(PHPGW_INCLUDE_ROOT . SEP . 'sitemgr' . SEP . 'inc' . SEP . 'class.browser_transform.inc.php'); 119 $this->add_transformer(new browser_transform($prevlink,$nextlink)); 120 } 121 } 122 123 124 125 function get_content(&$arguments,$properties) 126 { 127 $content .= '<div align="center"><img hspace="20" align="absmiddle" src="'. $arguments['imagedirurl'] . SEP . $arguments['imagename'] . $arguments['filenumber'] . '.' . $arguments['imagetype'] . '" /></div>'; 128 $content .= '<div align="center" style="margin:5mm">' . $arguments['subtext'][$arguments['filenumber']-1] . '</div>'; 129 return $content; 130 } 131} 132