jacobwb / hashover

Free and Open Source PHP Comment System

Home Page:http://tildehash.com/?page=hashover

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

On each request to a page a folder is created in /pages/ - even with url parameters

q2apro opened this issue · comments

Calling a page with: domain.com/startpage/ creates a folder startpage in pages, fine.

Calling a page with: domain.com/startpage/?flag=stuff&this=me creates a folder startpage--flag&this-me in pages.

However, the second call should also write into pages/startpage and ignore the url parameters.

Is there an option, has this been implemented already? If not, where can it be changed in the source?

Thank you.

Okay, I think I found it in write_comments.php:

Now using:

$kickback = $this->parse_url['path'] . ((!empty($this->parse_url['query'])) ? '?' . $this->parse_url['query'] : ''); // URL back to comment
$kickback = strtok($kickback, '?'); // added to remove query parameters

Are there any drawbacks?


Just realize now that each query parameter in the URL is preventing the existing comments to show up for this page. Obviously the hashover script treats each URL parameter as a separate page. From my point of view, I would strip the parameters and save the clean URL. Stripping can be done as described above. Of course, there are websites that query their pages like domain.com/?page=test - so this should be a boolean in settings.php

This can be done with the $canon_url variable. You can either set it via JavaScript by adding the canon_url query to the src attribute like so...

<script src="/hashover.php?canon_url=http://domain.com/startpage/"></script>

You may simply strip everything after the first question mark from the URL and place it in the canon_url query using PHP, or if you already use a canonical link element in the <head> section of your webpages (this is common, especially in CMSs) you may use the following...

<script>var canon_url = (document.querySelector('link[rel="canonical"]') != null) ? '?canon_url=' + encodeURIComponent(document.querySelector('link[rel="canonical"]').getAttribute('href')) : ''; document.write('<script src="/hashover.php' + canon_url + '"><\/script>');</script>

The documentation has more information:
http://tildehash.com/?page=hashover

I overlooked that, thanks for pointing out!

For my recent page, I have canonical implemented in the head by default using modx. It should work.

Mhh, I reopen this issue because every newbie to this script will run into the issue.

I would suggest to provide an option in settings.php

Is that feasable?

Furthermore, a folder should only be created when a comment is posted. Why having 200 empty folders?

Definitely a necessary core change.


Plus: I noticed that sometimes the folder created in pages has a trailing hyphen, e.g. `games-`. The canonical would be `` - is this a bug?

The culprit seems to be the trailing slash that is converted to a hyphen. I suggest to remove the hyphen from the end. On most servers example.com/games and example.com/games/ will lead to the same page.

The directories are created immediately so that the script will fail immediately if they can't be created, this means the webmaster is far more likely to see the problem and fix the permissions rather than having the user try to post a comment only to get an error.

This is a carryover from Hashover pre-1.0, PHP pre-5.3, it will be fixed.

I will improve the URL conversion as well.

the script will fail immediately if they can't be created

Well, the verification step should be taken at installation time, or in the case of hashover: at first runtime. Maybe you provide a separate php file that can be called to check for all necessary run settings?

The URL conversion without trailing slash / hyphen would be welcome. When do you push your changes?

Back in the day, before PHP 5.3 and before I was a better programmer, it was very difficult to do such verification, checking whether the directory could be created was the fastest and easiest way. Nowadays, it should be possible to simply check if the "pages" directory exists, if it is writable, and that the page's comment directory doesn't already exist.

As for the trailing slash. It's a bit difficult to do, because "/" indicates the website index, stripping trailing slashes would make "/" into nothing, meaning added code just to check if the page is the index or not.

You could change line 129 in setup.php to this...

$this->dir = '.' . $this->setting['root_dir'] . 'pages/' . trim($this->ref_path, '-');

As after the slashes have been converted to dashes, all you have to do is trim the trailing dashes.

I'll make more improvements than that, for example I sometimes see double or triple dashes in the directory names. On Windows certain characters aren't allowed in file names, and that wasn't taken into account, so improving the directory name conversion was already planned.

When do you push your changes?

Likely the end of this month or the early part of next month.

Added the trim in setup.php change, thank you.

For checking if the pages folder exist, or let's say, I want to disable the creation of new folders each time a page is requested, where would I disable that?

Update: I guess it is in setup.php line:

if (!@mkdir($this->dir, 0755) and !@chmod($this->dir, 0755)) {

Mhh, how to tell hashover to only create the folder if a comment or reply is posted, is there a post event? But I can only find mkdir in setup.php, should be in write_comments.php then.

*_Untested_* You could try wrapping that if statement in something like...

if (isset($_POST['comment'])) {
    // original if statement here
}

However, the dependence on the directories actually existing might run deeper than that. I'm unsure.

All right, so I will better wait for your next release. Thumbs up!

Update: Your code addition works, folders are only created on comment posts.

👍