forked from pauloamgomes/CockpitCMS-Moderation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
72 lines (59 loc) · 2.48 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
// Module ACL definitions.
$this("acl")->addResource('moderation', [
'manage',
'publish',
'unpublish',
'schedule',
]);
/**
* Add moderation markup to collections sidebar.
*/
$this->on('collections.entry.aside', function($name) use ($app) {
$canSchedule = $app->module('cockpit')->hasaccess('moderation', ['manage', 'schedule']);
$settings = $this->retrieve('config/moderation', ['schedule' => []]);
$scheduleEnabled = $canSchedule && isset($settings['schedule']) && ($settings['schedule'] === '*' || in_array($name, $settings['schedule']));
$this->renderView("moderation:views/partials/collections.entry.aside.php", ['enabled' => $scheduleEnabled]);
});
/**
* Add moderation markup to singleton sidebar.
*/
$this->on('singletons.form.aside', function($name) use ($app) {
$canSchedule = $app->module('cockpit')->hasaccess('moderation', ['manage', 'schedule']);
$settings = $this->retrieve('config/moderation', ['schedule' => []]);
$scheduleEnabled = $canSchedule && isset($settings['schedule']) && ($settings['schedule'] === '*' || in_array($name, $settings['schedule']));
$this->renderView("moderation:views/partials/singletons.form.aside.php", ['enabled' => $scheduleEnabled]);
});
/**
* Initialize addon for admin pages.
*/
$app->on('admin.init', function () use ($app) {
// Check moderation capabilities for the user.
$canPublish = $app->module('cockpit')->hasaccess('moderation', ['manage', 'publish']);
$canUnpublish = $app->module('cockpit')->hasaccess('moderation', ['manage', 'unpublish']);
$this('admin')->data["extract/moderation"] = [
'canPublish' => $canPublish,
'canUnpublish' => $canUnpublish,
];
// Add field tag.
$this->helper('admin')->addAssets('moderation:assets/field-moderation.tag');
$this->helper('admin')->addAssets('moderation:assets/moderation.css');
$this->helper('admin')->addAssets('moderation:assets/moderation.js');
// Bind admin routes.
$this->bindClass('Moderation\\Controller\\Admin', 'settings/moderation');
});
/*
* Add menu entry if the user has access to group stuff.
*/
$this->on('cockpit.view.settings.item', function () use ($app) {
if ($app->module('cockpit')->hasaccess('moderation', 'manage')) {
$this->renderView("moderation:views/partials/settings.php");
}
});
/**
* Provide modifications on the preview url (Helpers addon).
*/
$this->on('helpers.preview.url', function(&$preview) use ($app) {
$keys = $app->module('cockpit')->loadApiKeys();
$preview['token'] = $keys['moderation'] ?? '';
});