/** * Generates an image element. * * @param string $src The path to the image. * @param string $alt * @param int $width * @param int $height * @param string $class * @param array $attributes,... OPTIONAL Any number of associative arrays containing html attributes as the keys. */ public function img($src) { if (!is_string($src)) { throw new Exception('First parameter expected to be a path string.'); } $args = func_get_args(); array_shift($args); $attributes = array(); if (count($args) > 0) { $allowed = he_img::acceptedAttributes(); // alt, width, height, class, attributes //string, int, int, string, array $argPos = 0; while (count($args) > 0) { $arg = array_shift($args); if (is_string($arg)) { if ($argPos < 1) { $attributes['alt'] = $arg; $argPos = 1; continue; } if ($argPos > 1) { $attributes['class'] = $arg; $argPos = 4; continue; } } if (is_int($arg)) { if ($argPos < 2) { $attributes['width'] = $arg; $argPos = 2; continue; } if ($argPos == 2) { $attributes['height'] = $arg; $argPos = 3; continue; } } if (is_array($arg)) { if ($this->hasHtmlAttributes($arg, $allowed)) { foreach ($arg as $n => $v) { $n = strtolower($n); if (!array_key_exists($n, $attributes)) { if (array_key_exists($n, htmlElement::$enumAttributes) && !in_array($v, htmlElement::$enumAttributes[$n]) && array_key_exists($v, htmlElement::$enumAttributes[$n])) { $v = htmlElement::$enumAttributes[$n][$v]; } elseif (in_array($n, htmlElement::$boolAttributes)) { if (is_bool($v) && !$v || !is_bool($v) && $v !== 'true') { continue; } $v = $n; } $attributes[$n] = $v; } } } } } } //get url $attributes['src'] = get::file_url($src); $e = new he_img($attributes); if (!$this->echoOff) { echo $e; } return $e; }