<?php

namespace Modules;

class Pictures extends \Prefab {
    static function render_an_image($args) {
        $f3 = \Base::instance();
        $attr = $args['@attrib'];
        //var_dump($attr);
        $a=array(
            'img'=>'',
            'hover'=>'',
            'link'=>''
        );
        
        $img = array_key_exists('img', $attr) ? $attr['img'] : false;
        $alt = array_key_exists('hover', $attr) ? $attr['hover'] : false;
        $url = array_key_exists('link', $attr) ? $attr['link'] : false;
        
        echo $img."sss"."<br>";
        var_dump($a);
        
        if($img /*&& is_file($img)*/) {
            $a['img'] = $img;
        } else {
            $a['img'] = $f3->get('RESOURCES')."img/default.png";
        }
        if($alt && is_file($alt)) {
            $a['hover'] = $alt;
        } else {
            $a['hover'] = $a['img'];
        }
        if($url) {
            $a['link'] = $url;
        } else {
            $a['link'] = '/';
        }
        
        //var_dump($a);
        //var_dump($args);
        //$out = sprintf("<code>%s</code>",);
        return self::hover_pic_with_link($a['img'],$a['hover'],$a['link']);
    }
    
    static function hover_pic_with_link($pic1,$pic2,$link) {
    return sprintf('<a href="%s"><img src="%s" alt="%s" /></a>',$link,$pic1,$pic2);
    }
    
    static function makeImageLink($url,$href=false) {
        if($href) {
          return sprintf("<a href=\"%s\"><img class=\"post-image\" src=\"%s\" /></a>",$href, $url);
        }
        return sprintf("<img class=\"post-image\" src=\"%s\" />", $url);
    }
}