Ejemplo n.º 1
0
function image_tag($file, $options = array())
{
    if (empty($file)) {
        return;
    }
    $out = "<img src=\"" . media_path($file) . "\"";
    if (is_string($options)) {
        $options = array('alt' => $options);
    }
    if ($options === false) {
        $options = array('alt' => false);
    }
    if (!is_array($options)) {
        $options = array();
    }
    if (array_key_exists("alt", $options) && $options['alt'] === false) {
        $pi = pathinfo($file);
        $options['alt'] = human_name(str_replace('.' . $pi['extension'], '', $pi['basename']));
    }
    if (!array_key_exists("alt", $options)) {
        $out .= ' alt=""';
    }
    foreach ($options as $k => $v) {
        if ($k == 'size') {
            $v = explode('x', $v);
            $out .= ' width="' . $v[0] . '" height="' . $v[1] . '" ';
        } else {
            $out .= " {$k}=\"{$v}\" ";
        }
    }
    $out .= " />\n";
    return $out;
}
Ejemplo n.º 2
0
 protected function test_image_of($prop, $msg)
 {
     if (!array_key_exists($prop, $this->data)) {
         return true;
     }
     if ($this->data[$prop] instanceof UploadedFile) {
         if ($this->data[$prop]->is_image()) {
             return true;
         } else {
             $this->add_error(human_name($prop), $msg, VALIDATION_IMAGE);
             return false;
         }
     } else {
         // Allow null
         return true;
     }
 }