PHP code example of sgkirby / commentions

1. Go to this page and download the library: Download sgkirby/commentions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sgkirby / commentions example snippets


'sgkirby.commentions.templatesWithComments' => ['note', 'article'],
'sgkirby.commentions.templatesWithWebmentions' => ['note'],


  // in a page template or snippet
  commentions();


  // within the <head> tags of a template or snippet
  commentions('css');


  // in a page template or snippet
  commentions('feedback');
  commentions('form');
  commentions('list');


  // within the <head> tags of a template or snippet
  commentions('endpoints');

// in config.php
return [
  'sgkirby.commentions.secret' => '<YOUR-SECRET>'
];


  commentions('feedback');
  commentions('form');
  commentions('list');

'hooks' => [
  'commentions.add:before' => function ($page, $data) {
    if($data['name'] == 'John Doe') {
      throw new Exception("John Doe is not allowed to comment.");
    }
  }
],

'hooks' => [
  'commentions.add:after' => function ($page, $data) {
    try {
      kirby()->email([
        'from' => '[email protected]',
        'to' => '[email protected]',
        'subject' => 'New comment/webmention on ' . $page->title(),
        'body'=> print_r($data, true),
      ]);
    } catch (Exception $error) {
      echo $error;
    }
  }
],

'hooks' => [
  'commentions.update:after' => function ($page, $data, $olddata) {
    if ($data['status'] === 'approved' && $olddata['status'] === 'pending') {
      someCustomFunction();
    }
  }
],

'sgkirby.commentions.templatesWithComments' => ['note', 'article'],
'sgkirby.commentions.templatesWithWebmentions' => ['note'],

'sgkirby.commentions.templatesWithComments' => ['note'],
'sgkirby.commentions.templatesWithWebmentions' => [],

'sgkirby.commentions.defaultstatus' => 'approved',

'sgkirby.commentions.defaultstatus' => [
  'comment'   => 'pending',
  'like'      => 'approved',
],

'sgkirby.commentions.endpoint' => 'webmention-endpoint',

'sgkirby.commentions.secret' => '<YOUR-SECRET>',

'sgkirby.commentions.keepfailed' => false,

// empty array = no data beyond the  => [],

'sgkirby.commentions.commentfields' => [
  'name',          // / 

'sgkirby.commentions.commentfields' => [
  'name' => true,  // include name field and mark as website field
],

'sgkirby.commentions.commentfields' => function($targetPage){
  // comment forms on event pages 
      'email' => true,
    ];
  }
  // on all other pages, only show optional name field
  return [
    'name',
  ];
},

// empty array = no data beyond the ds' => [],

'sgkirby.commentions.webmentionfields' => [
  'text',     // store source HTML
  'name',     // store author's realname
  'avatar',   // store author's avatar URL
  'website',  // store author's homepage URL
],

'sgkirby.commentions.hideforms' => true,

'sgkirby.commentions.spamprotection' => [
  'honeypot', /* filter comments where a hidden field contains data */
  'timemin',  /* filter comments submitted too fast */
  'timemax',  /* filter comments submitted after very long time */
],

'sgkirby.commentions.spamtimemin' => 5,     /* valid n seconds after page load; default 5s */
'sgkirby.commentions.spamtimemax' => 86400, /* no longer valid after n seconds; default 24h */

'sgkirby.commentions.grouped', [
  'read'            => 'Read by',
  'like'            => 'Likes',
  'repost'          => 'Reposts',
  'bookmark'        => 'Bookmarks',
  'rsvp:yes'        => 'RSVP: yes',
  'rsvp:maybe'      => 'RSVP: maybe',
  'rsvp:interested' => 'RSVP: interested',
  'rsvp:no'         => 'RSVP: no',
],

 Kirby\Toolkit\I18n::$locale = 'de'; 

'sgkirby.commentions.t.en.snippet.list.comments' => 'Comments',

'sgkirby.commentions.allowlinks' => true, /* Allow links in comments, if true */
'sgkirby.commentions.autolinks' => true,  /* Automatically recognize URLs in comments and turn them into links. Has no effect, if allowlinks is false. */

foreach ($testpage->commentions('all') as $item) {
  print_r($item->content());
}
 commentions('endpoints') 
 commentions() 
 commentions('feedback') 
 commentions('form') 
 commentions('list') 
 commentions('grouped'); 
 commentions('endpoints'); 
 commentions('css');