Code: Alles auswählen
<script type="text/javascript">
var a = 0;
hintergrund = new Array();
hintergrund[a]="http://localhost/phpbb3/ext/chris1278/bgchange/img/bild1.jpg"; a++;
hintergrund[a]="http://localhost/phpbb3/ext/chris1278/bgchange/img/bild2.jpg"; a++;
hintergrund[a]="http://localhost/phpbb3/ext/chris1278/bgchange/img/bild3.jpg"; a++;
hintergrund[a]="http://localhost/phpbb3/ext/chris1278/bgchange/img/bild4.jpg"; a++;
var x = Math.floor(Math.random() * a);
document.write('<body style="background:url('+ hintergrund[x] +') no-repeat center center fixed;height:100%;">')
</script>
Code: Alles auswählen
public function add_imagerandom_theme($event)
{
$ordner =dirname(__dir__).'/img/';
$verz = opendir($ordner);
$filesFound = 0;
$linkl = array();
while($file = readdir($verz))
{
if($file != "." && $file != "..")
{
$filesFound++;
array_push ($linkl, $file);
}
}
$index = array_rand($linkl, 1);
closedir($verz);
$zufall = dirname(__dir__).'/img/'.$linkl[$index];
$this->template->assign_vars(array(
'TEST_RANDOM' => $zufall,
));
}
}
$zufall
aus den gessammelten bildern die mittels oprndir eingelesen werden so in diese Variable übernommen werde:
und zwar müsste das diese zeichenfolge haben:
Code: Alles auswählen
hintergrund[a]="http://localhost/phpbb3/ext/chris1278/bgchange/img/bild1.jpg"; a++;
Die listener liest mit der opendir variante die dateien aus die dort sind und erstellt für jede datei einen string für das javscript im template.
ähnlich wie der andere kollege von mir das gelöst hat in der listener:
Code: Alles auswählen
public function add_imagerandom_theme($event)
{
define ('ROOT', dirname(dirname(__FILE__)));
$pic_data = '';
$directory = opendir(ROOT.'/img/');
while ($file = readdir($directory))
{
if ($file != "." && $file != "..")
{
$pic_data .= " <img src='" . generate_board_url() . "/ext/chris1278/bgchange/img/$file'>\n";
}
}
$this->template->assign_vars(array(
'DEMO_ALEX' => $pic_data,
));
closedir($directory);
}
Code: Alles auswählen
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_13.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_5.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_16.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_20.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_19.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_15.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_11.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_9.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_3.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_18.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_17.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_8.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_4.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_7.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_14.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_6.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_1.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_12.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_2.jpg'>
<img src='https://forenurl/ext/chris1278/bgchange/img/DK_Image_10.jpg'>
Wenn du das so anwendest das anstelle dieser code die bilder eingelesen werden in diesem format:
Code: Alles auswählen
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_1.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_2.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_3.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_4.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_5.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_6.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_7.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_8.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_9.jpg"; a++;
hintergrund[a]="https://forenurl/ext/chris1278/bgchange/img/DK_Image_10.jpg"; a++;
Code: Alles auswählen
<script type="text/javascript">
var a = 0;
hintergrund = new Array();
{DEMO_ALEX}
var x = Math.floor(Math.random() * a);
document.write('<body style="background:url('+ hintergrund[x] +') no-repeat center center fixed;height:100%;">')
</script>
Falls das für dich ein ansatz ist.