Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP mode #210

Closed
CyberShadow opened this issue Mar 4, 2018 · 4 comments
Closed

PHP mode #210

CyberShadow opened this issue Mar 4, 2018 · 4 comments
Labels

Comments

@CyberShadow
Copy link
Contributor

@CyberShadow CyberShadow commented Mar 4, 2018

Hi, and thank you for your work on this project.

I'm trying to get PHP mode to work with the latest version from git, and running into some trouble.

  1. First, currently there is no documentation. The only instructions I found on this subject were in the changelog. This might not be a problem if integrating Hashover in PHP mode would be simple or obvious, but I haven't found such a way.

  2. Following the changelog instructions:

    You implement it like so:
    <?php
    $hashover = new HashOver ('php', 'title', 'URL');
    ?>
    <!DOCTYPE html>
    ...
    <div id="hashover">
    <?php
    echo $hashover->displayComments ();
    ?>
    </div>

    currently seems insufficient. It results in the error:

    <b>Fatal error</b>:  Uncaught TypeError: Argument 2 passed to HashOver\PHPMode::__construct() must be an instance of HashOver\CommentsUI, null given, called in /home/csblog/hashover-next/hashover/backend/classes/hashover.php on line 414 and defined in /home/csblog/hashover-next/hashover/backend/classes/phpmode.php:43
    Stack trace:
    #0 /home/csblog/hashover-next/hashover/backend/classes/hashover.php(414): HashOver\PHPMode-&gt;__construct(Object(HashOver\Setup), NULL, Array)
    #1 /home/csblog/www/hashovertest.php(22): HashOver-&gt;displayComments()
    #2 {main}
      thrown in <b>/home/csblog/hashover-next/hashover/backend/classes/phpmode.php</b> on line <b>43</b><br />
    
  3. From looking at the source code, I inferred that the above code is missing calls to $hashover->initiate() and $hashover->finalize(). Adding those, there are no more errors; however, the output looks like this:

    screen shot 2018-03-04 at 06 33 02

    • It looks like the form has many more fields than necessary.
    • There is a "Name" and "Password" field even though "Allow users to login" is off.
    • There is complete lack of styling. There are no references to style sheets in the generated HTML, either.

Have I missed something?

@techboyg5
Copy link

@techboyg5 techboyg5 commented Oct 21, 2020

You need to load the CSS seperately like this:

<link href="/hashover/comments.css" rel="stylesheet" type="text/css">
@jacobwb jacobwb added the question label Oct 21, 2020
@jacobwb
Copy link
Owner

@jacobwb jacobwb commented Oct 21, 2020

@CyberShadow You're on the right track. There isn't any documentation right now because it is still so not-straightforward to use, I want to make it simpler before documenting it. @techboyg5 is right, you need to declare the CSS file in your website <head> yourself, because HashOver in PHP mode can't do that automatically like JavaScript can.

Now, for a long overdue explanation of using HashOver in PHP mode:

<?php

// Setup HashOver for use in PHP-mode, autoload class files
require ('hashover/backend/php-setup.php');

try {
    // Instantiate HashOver
    $hashover = new HashOver ('php');

    // Set page URL to create a backend thread directory
    $hashover->setup->setPageURL ('https://comments.barkdull.org/test-page.php');

    // Set page title for metadata / use in APIs
    $hashover->setup->setPageTitle ('HashOver 2.0 (development) Test Page');

    // Do some necessary setup work before loading comment files
    $hashover->initiate ();

    // Load and parse primary comment files
    $hashover->parsePrimary ();

    // Decide which comments appear in the popular comments section
    $hashover->parsePopular ();

    // Sort primary comments as configured
    $hashover->sortPrimary ();

    // Do some final setup work before outputting HTML
    $hashover->finalize ();

} catch (Exception $error) {
    // Displays exceptions in HTML paragraph tag
    echo HashOver\Misc::displayError ($error->getMessage ());
}

?>

You should place that kind of code in a PHP file that returns HTML, but place it before any HTML output, as HashOver needs to set a few headers. The key things you're missing is using setPageURL to tell HashOver what page it is on, and using parsePrimary to load normal comments. The other things in the code above are mostly optional, but required to get the same functionality as HashOver in JavaScript mode, also the order of the functions is important.

After that code is in place, you can now output the HashOver HTML wherever you want using the following code...

<?php

try {
    // Generate interface, form, and comment HTML
    echo $hashover->displayComments ();

} catch (Exception $error) {
    // Displays exceptions in HTML paragraph tag
    echo HashOver\Misc::displayError ($error->getMessage ());
}

?>

I am going to close this issue, but feel free to continuing asking more questions here if necessary.

I hope this helps.

@jacobwb jacobwb closed this Oct 21, 2020
@CyberShadow
Copy link
Contributor Author

@CyberShadow CyberShadow commented Oct 21, 2020

Thanks, I had already figured something out two years ago. Sorry for not updating the issue.

@jacobwb
Copy link
Owner

@jacobwb jacobwb commented Oct 21, 2020

No problem, I'm glad you figured it out. I'm just going through and answering some issues right now, some are quite old but I don't know who is still interested in answers so I just answer them all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.