* @param string | null $id - id for the image, if $url is not null used for the anchor tag else for the image tag
* @param array | null $class - array of classes for the image
*/
- public function img(string $src, string $alt, string | null $title, string | null $url, string | null $id, array | null $class): string
+ public function img(string $src, string | null $alt, string | null $title, string | null $url, string | null $id, array | null $class): string
{
$html = "";
- if (!is_null($url)) {
+ if (!empty($url)) {
$html .= "<a href='$url' id='$id'>";
}
$html .= "<img";
- if (!is_null($class)) {
+ if (!empty($class)) {
$html .= ' class="' . implode(' ', $class) . '"';
print_r($class);
}
- $html .= " src='$src' alt='$alt'";
+ $html .= " src='$src'";
- if (!is_null($title)) {
+ if (!empty($alt)) {
+ $html .= " alt='$alt'";
+ }
+
+ if (!empty($title)) {
$html .= " title='$title'";
}
- if (is_null($url) && !is_null($id)) {
+ if (empty($url) && !empty($id)) {
$html .= " id='$id'";
}
$html .= "/>";
- if (!is_null($url)) {
+ if (!empty($url)) {
$html .= "</a>";
}
$url = $this->str_val_or_empty($line, 'url');
$title = $this->str_val_or_empty($line, 'title');
$class = array_map('trim', explode(",", $this->str_val_or_empty($line, 'class')));
+ $image = null;
+
+ if (!empty($line['image'])) {
+ $image = $line['image'];
+ }
// if new-col close p and ul and open div with col class
if (in_array("new-col", $class)) {
$is_div_closed = false;
}
+ // if image is set add image and skipt switch
+ if (!is_null($image)) {
+ $html .= $this->img($image['path'], $image['description'], $image['title'], $image['url'], $image['id'], $image['class']);
+ continue;
+ }
+
switch ($class) {
case in_array("list", $class):
// if previous iteration was diferent section close li
$page_data = $data['pages'][$page['path']];
+ // put image object in page_data
+ foreach ($page_data as $dKey => $line) {
+ if (!empty($line['image'])) {
+ foreach ($data['images'] as $image) {
+ if ($image['id'] == $line['image']) {
+ $page_data[$dKey]['image'] = $image;
+ break;
+ }
+ }
+ }
+ }
+
// generate page
$generator->writeToFile($page_path, $generator->form_html($page_data, "en"));
$generator->writeToFile($page_path, '</section>');