/
HookApp.php
97 lines (85 loc) · 2.93 KB
/
HookApp.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace SoosyzeCore\Node\Services;
class HookApp
{
/**
* @var \Soosyze\App
*/
protected $core;
public function __construct($core)
{
$this->core = $core;
}
public function hookResponseAfter($request, &$response)
{
if (!($response instanceof \SoosyzeCore\Template\Services\Templating)) {
return;
}
$vendor = $this->core->getPath('modules', 'modules/core', false) . '/Node/Assets/script.js';
$script = $response->getBlock('this')->getVar('scripts');
$script .= '<script src="' . $vendor . '"></script>';
$response->view('this', [ 'scripts' => $script ]);
}
public function hookNodeShowResponseAfter($response, $node)
{
$robots = '';
if ($node[ 'meta_noindex' ]) {
$robots .= 'noindex,';
}
if ($node[ 'meta_nofollow' ]) {
$robots .= 'nofollow,';
}
if ($node[ 'meta_noarchive' ]) {
$robots .= 'noarchive,';
}
if ($robots) {
$response->view('this', [
'meta' => '<meta name="robots" content="' . substr($robots, 0, -1) . '">' . PHP_EOL
]);
}
if ($node[ 'node_status_id' ] != 1) {
$response->view('page.messages', [
'infos' => [ t('This content is not published') ]
]);
}
}
public function hookNodeEditResponseAfter($request, &$response)
{
if (!($response instanceof \SoosyzeCore\Template\Services\Templating)) {
return;
}
$script = $response->getBlock('this')->getVar('scripts');
$script .= '<script>
$().ready(function () {
var nestedSortables = [].slice.call($(\'.nested-sortable\'));
for (var i = 0; i < nestedSortables.length; i++) {
new Sortable(nestedSortables[i], {
group: "nested",
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.1,
ghostClass: "placeholder",
dragoverBubble: true,
onEnd: function (evt) {
render(".nested-sortable");
}
});
}
function render(idMenu) {
var weight = 1;
var id = $(idMenu).find(\'input[name*="id"]\').val();
if (id === undefined) {
id = -1;
}
$(idMenu).children(".sort_weight").each(function () {
$(this).children(\'input[name*="weight"]\').val(weight);
weight++;
});
}
});
</script>';
$response->view('this', [
'scripts' => $script
]);
}
}