Skip to content

Commit

Permalink
Use event scripts instead of a custom plugin class
Browse files Browse the repository at this point in the history
  • Loading branch information
jDanek committed Sep 2, 2023
1 parent 5c098c1 commit debb7af
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 90 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Jirka Daněk
Copyright (c) 2023 Jirka Daněk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
78 changes: 0 additions & 78 deletions plugins/extend/gallerycomments/class/GalleryCommentsPlugin.php

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

use Sunlight\Database\Database as DB;
use Sunlight\Page\Page;
use Sunlight\Post\Post;

return function (array $args) {
global $id, $continue, $query;
if ($continue && $query['type'] == Page::GALLERY) {
DB::delete('post', 'home=' . $query['id'] . ' AND type=' . Post::PLUGIN . ' AND flag=' . $this->getOptions()['extra']['gallery_comments_flag']);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Sunlight\Router;

return function (array $args) {
if ($args['post']['flag'] == $this->getOptions()['extra']['gallery_comments_flag']) {
$args['backlink'] = Router::page($args['post']['id']) . '#posts';
}
};
20 changes: 20 additions & 0 deletions plugins/extend/gallerycomments/event/page_gallery_after.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Sunlight\Post\PostService;
use Sunlight\Settings;

return function (array $args) {
$args['output'] .= PostService::renderList(
PostService::RENDER_PLUGIN_POSTS,
$args['page']['id'],
[
Settings::get('commentsperpage'), // comments per page
true, // can post
false, // locked
$this->getOptions()['extra']['gallery_comments_flag'], // plugin flag
true, // desc
_lang('posts.comments'), // title
null // page vars
]
);
};
9 changes: 9 additions & 0 deletions plugins/extend/gallerycomments/event/posts_1000_link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Sunlight\Router;

return function (array $args) {
if ($args['post']['flag'] == $this->getOptions()['extra']['gallery_comments_flag']) {
$args['url'] = Router::page($args['post']['id']);
}
};
11 changes: 11 additions & 0 deletions plugins/extend/gallerycomments/event/posts_1000_validate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use Sunlight\Database\Database as DB;
use Sunlight\Page\Page;

return function (array $args) {
// check the existence of the gallery
if (DB::count('page', 'id=' . $args['home'] . ' AND type=' . Page::GALLERY) !== 0) {
$args['valid'] = true;
}
};
24 changes: 13 additions & 11 deletions plugins/extend/gallerycomments/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
"$schema": "../../../system/schema/extend.json",
"name": "Gallery Comments",
"description": "Adds comments to galleries",
"version": "0.9.2",
"environment": {
"system": "^8.0"
},
"authors": [
{"name": "Friends of Sunlight CMS", "url": "https://github.com/friends-of-sunlight-cms/"}
],
"class": "GalleryCommentsPlugin",
"version": "1.0.0",
"environment": {
"system": "^8.0"
},
"events": [
{"event": "page.gallery.after", "method": "onCommentsShow"},
{"event": "posts.1000.validate", "method": "onCommentsValidate"},
{"event": "posts.1000.link", "method": "onCommentsLink"},
{"event": "mod.editpost.backlink", "method": "onCommentsEditBacklink"}
{"event": "page.gallery.after", "script": "event/page_gallery_after.php"},
{"event": "posts.1000.validate", "script": "event/posts_1000_validate.php"},
{"event": "posts.1000.link", "script": "event/posts_1000_link.php"},
{"event": "mod.editpost.backlink", "script": "event/mod_editpost_backlink.php"}
],
"events.admin": [
{"event": "admin.mod.content-delete.after", "method": "onCommentsClean"}
]
{"event": "admin.mod.content-delete.after", "script": "event/admin_mod_content_delete_after.php"}
],
"extra": {
"gallery_comments_flag": 1000
}
}

0 comments on commit debb7af

Please sign in to comment.