(franken)log

dev site for hy(de)blog

2023-03-05 Sunday

Caught an error that was causing pages that end in 'd' to not function properly. The issue was on line96 of managepages.php:

$pagename = rtrim(explode('/',$file)[5], '.md');

Replaced that line with the following code to check and account for page names like 'download' and 'legend':

$parts = explode('/', $file);
$filename = $parts[5];
if (substr($filename, -1) === 'd') {
    $pagename = substr($filename, 0, -3);
} else {
    $pagename = rtrim($filename, '.md');
}

Update:

I also had to account for this in sidebar.php when displaying and linking to the pages. Same code to replace/use.

Update #2

I also needed to update 404.php and page.php with the following code, in each case replaying the existing foreach sections:

page.php

// foreach(glob($root.'/pages/*.md') as $file) {
//  $pagename = rtrim(explode('/',$file)[5], '.md');

//  if ($pagename == $page) {
//      $match = true;
//  }
// }

foreach(glob($root.'/pages/*.md') as $file) {
    $filename = basename($file);
    if (substr($filename, -1) === 'd') {
        $pagename = substr($filename, 0, -3);
    } else {
        $pagename = rtrim($filename, '.md');
    }

    if ($pagename == $page) {
        $match = true;
    }
}

404.php

// foreach(glob($root.'/pages/'.'*.md') as $i=>$file) {
//  $pagenames[$i] = rtrim(explode('/',$file)[5], '.md');
// }

foreach(glob($root.'/pages/'.'*.md') as $i => $file) {
    $filename = basename($file);
    if (substr($filename, -1) === 'd') {
        $pagename = substr($filename, 0, -3);
    } else {
        $pagename = rtrim($filename, '.md');
    }
    $pagenames[$i] = $pagename;
}

Update #3

And, admin.php for the NOWNS section:

                    foreach(glob($pages.'*.md') as $i=>$file) {
                //      $pagename = rtrim(explode('/',$file)[5], '.md');
                        $parts = explode('/', $file);
                        $filename = $parts[5];
                        if (substr($filename, -1) === 'd') {
                            $pagename = substr($filename, 0, -3);
                        } else {
                            $pagename = rtrim($filename, '.md');
                        }

Comments

Have something you'd like to respond with? 📣

Send me a note via email and let's start a conversation on this very topic.

Prior to using hyblog I had not heard of .webp files. Great idea and a step forward in image formats and their delivery.

But, I couldn't get them to work consistently in hyblog.

I realized that the issue was in the uploader.php file.

The following code was missing from the elseif to address jpg files:

$name = str_replace(' ', '_', $explode[0]);

This code existed for png files but not jp(e)g. All fixed:

    if ($imageFileType == 'png') {
        $img = imagecreatefrompng($target_file);
        $explode = explode('.', basename($_FILES["fileToUpload"]["name"]));
        $name = $explode[0];
        $name = str_replace(' ', '_', $explode[0]);
        $webp = $target_dir . $name . '.webp';
        imagewebp($img, $webp ,80);
    } elseif ($imageFileType <mark class='filterMark'> 'jpg' || $imageFileType </mark> 'jpeg') {
        $img = imagecreatefromjpeg($target_file);
        $explode = explode('.', basename($_FILES["fileToUpload"]["name"]));
        $name = $explode[0];
        $name = str_replace(' ', '_', $explode[0]);
        $webp = $target_dir . $name . '.webp';
        imagewebp($img, $webp ,80);
    }

Comments

Have something you'd like to respond with? 📣

Send me a note via email and let's start a conversation on this very topic.