<?php

include 'php/functions/func_images.php';
include 'php/functions/func_filesystem.php';

# path to picture folders
$pictures_path = $this->absPath.'site/pictures/';
# get a list of those folders
$folders = filesys_get_wanted_children($pictures_path,'files');
# make each folder a full path
foreach($folders as $key => $value)
{
    $folders[$key] = $pictures_path.$value;
}
$image = images_get_random($folders,1,"/thumb_/");
$image = str_replace($this->absPath,'',$image[0]);
$children = filesys_get_wanted_children($this->templates,'folders',"/ourfamilies_/");
$text = '';

foreach($children as $child)
{
    $name = preg_replace('/ourfamilies_(\w+)\.php/','$1',$child);
    if(strstr($image,$name))
    {
        $text = file_get_contents($this->templates.$child);
        $first_p = strpos($text,'<p>') + 3;
        # we want the second paragraph
        $open_p = strpos($text,'<p>',$first_p) + 3;
        $num_chars = strpos($text,'</p>',$open_p) - $open_p;
        $text = preg_replace('/<img.*\/>/','',substr($text,$open_p,$num_chars));
        $text = substr(strip_tags($text),0,170).'...';
        break;
    }
}

?>

<div id='family-div'>
    <div>
        <img src='<?php echo $image ?>' />
        <p>
            <?php echo $text ?>
            <br />
            <a title='<?php echo $name ?>' href='ourfamilies.php?who=<?php echo $name ?>'>mehr lesen</a>
        </p>
    </div>
</div>
<h1 class='de'>
	<a title='Internationale Jairus Verein' href='index.php?lang='>Internationale Jairus Verein</a>
</h1>
