danpros / htmly

Simple and fast databaseless PHP blogging platform, and Flat-File CMS
https://www.htmly.com
GNU General Public License v2.0
1.07k stars 263 forks source link

Commentics #747

Closed philips300-code closed 4 months ago

philips300-code commented 4 months ago

https://commentics.com/integration

Hello, when you add integration code

post.html.php

<?php session_start(); ?>
<!DOCTYPE html>
<?php
**$cmtx_identifier = '1';
$cmtx_reference  = 'Page One';
$cmtx_folder     = '/comments/';
require($_SERVER['DOCUMENT_ROOT'] . $cmtx_folder . 'frontend/index.php');
?>**

I have an error in the console. _PHP Notice: session_start(): Ignoring session_start() because a session is already active in /home/...../publichtml/themes/doks/post.html.php on line 1

danpros commented 4 months ago

Hello,

You just need to remove this one <?php session_start(); ?> because we already called it.

philips300-code commented 4 months ago

Hello, When I remove when <?php session_start(); ?> When there is a new comment, it is not visible on the new device.

When cleared from here, a comment is displayed /admin/clear-cache

danpros commented 4 months ago

For users who are not logged in, each visit will be given a cache page if the cache feature enabled. So if you are using PHP integration (the comments included directly to the page) with cache enable, ideally you need to delete the post cache every time new comment added and this requires a custom code.

The simplest way, of course, uses iframes like in their WordPress plugins.

philips300-code commented 4 months ago

thank you for the information

philips300-code commented 4 months ago

Hello, From here I need to take the code and link to the cache. But I don't understand where the file is located.

Link: https://commentics.com/events

<?php
/* Event for when a new comment is added */
if ($event == 'comment_added') {
  // add your own code here
}
danpros commented 4 months ago

The cache is in cache/page folder.

Try in post.html.php

<?php
$cmtx_identifier = strtok($_SERVER["REQUEST_URI"],'?');
$cmtx_reference  = $p->title;
$cmtx_folder     = '/comments/';
require($_SERVER['DOCUMENT_ROOT'] . $cmtx_folder . 'frontend/index.php');
?>

And all.php example:

<?php
/* Event for when a new comment is added */
if ($event == 'comment_added') {
    $c = str_replace('/', '#', rawurldecode($page_identifier));
    $cachefile = dirname(CMTX_DIR_ROOT) . '/cache/page/' . $c . '.cache';
    if (file_exists($cachefile)) {
        unlink($cachefile);
    }
}
philips300-code commented 4 months ago

Hello i can't figure out where i should create the folder all.php

danpros commented 4 months ago

Well already written here: https://commentics.com/events

To listen for an event, create a file called all.php inside the folder below: /comments/system/events/

philips300-code commented 4 months ago

Thank you for your help.

danpros commented 4 months ago

Added the code to the docs.