-
Notifications
You must be signed in to change notification settings - Fork 2
/
ProcessAdminHelp.module
192 lines (154 loc) · 5.3 KB
/
ProcessAdminHelp.module
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
/**
*
* Copyright 2016 Macrura
*
*
* ProcessWire 2.x
* Copyright (C) 2012 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://processwire.com
*
*/
class ProcessAdminHelp extends Process {
/**
* Return information about this module (required)
*
*/
public static function getModuleInfo() {
return array(
'title' => 'Admin Help Page',
'summary' => 'Shows documentation pages in a single accordion view.',
'version' => 108,
'author' => 'Marc W. | @Macrura(community), @outflux3 (Github), http://nibiri.com',
'href' => 'http://modules.processwire.com/',
'permission' => 'page-edit',
'requires' => 'AdminHelp',
'icon' => 'life-ring'
);
}
/**
* The name that will be used for the page this module creates
*
* It should be unique and the same (or similar) to the module name, but all lowercase.
* It should not be the same as any other ProcessWire admin page name.
*
*/
const pageName = 'admin-help';
/**
* This is an optional initialization function called before any execute functions.
*
*/
public function init() {
parent::init(); // required
}
/**
* This function is executed when a page with your Process assigned is accessed.
*
* This can be seen as your main or index function. You'll probably want to replace
* everything in this function.
*
*/
public function ___execute() {
$mainClass = 'AdminHelp';
$user = wire('user');
$config = wire('config');
$editButtonLabel = $this->_('Edit');
$addNewDoc = $this->_('Add New Doc');
$data = wire('modules')->getModuleConfigData($mainClass);
$docsRootID = (int) $data['helpRoot'];
$docsRoot = wire('pages')->get($docsRootID);
$this->config->styles->add($this->config->urls->siteModules . $mainClass . '/' . __CLASS__ . '.css?v=' . time());
$this->config->styles->add($this->config->urls->siteModules . $mainClass . '/' . $mainClass . '.css?v=' . time());
$this->config->scripts->add($this->config->urls->siteModules . $mainClass . '/jquery.cbpNTAccordion.min.js');
$out ="<div id='help-container'><ul id='cbp-ntaccordion' class='cbp-ntaccordion'>";
foreach($docsRoot->children as $doc) {
$cls = ' cbp-ntcontent';
// only output the requested docs and show accordion content instantly
$docs = wire('input')->get('docs');
if($docs AND $docs != $doc->name) continue;
elseif($docs AND $docs == $doc->name) $cls = '';
$out .= "<li name='{$this->sanitizer->pageName($doc->title, true)}'>
<h3 class='cbp-nttrigger'><i class='fa fa-file-text-o'></i> {$doc->title}</h3>
<div class='help-doc".$cls."'>
{$doc->body}";
if($user->hasRole('superuser')) {
$out .=
"<div class='doc-edit'>
<a href='{$config->urls->admin}page/edit/?id={$doc->id}'><i class='fa fa-pencil'></i> {$editButtonLabel}: {$doc->title}</a>
</div>";
}
// Children
if($doc->children->count()) {
$out .= "<ul class='cbp-ntsubaccordion'>";
foreach($doc->children as $child) {
$out .= "<li>
<h4 class='cbp-nttrigger'>{$child->title}</h4>
<div class='cbp-ntcontent'>
{$child->body}";
if($user->hasRole('superuser')) {
$out .=
"<div class='doc-edit'>
<a href='{$config->urls->admin}page/edit/?id={$child->id}'><i class='fa fa-pencil'></i> {$editButtonLabel}: {$child->title}</a>
</div>";
}
$out .= "</div></li>";
}
$out .= "</ul>";
}
$out .= "</div></li>";
}
$out .= '</ul>';
// New Doc button
if($user->hasRole('superuser')) {
$out .= "<div style='float:right;font-size:13px;'>
<a href='{$config->urls->admin}page/add/?parent_id={$docsRootID}'>
<button class='ui-button ui-widget ui-corner-all head_button_clone ui-state-default' name='button' value='Add New' type='button'>
<span class='ui-button-text'><i class='fa fa-plus-circle'></i> {$addNewDoc}</span></button>
</a>
</div>";
}
$out .= '</div><!-- /docs -->';
return $out;
}
/**
* Called only when your module is installed
*
* This version creates a new page with this Process module assigned.
*
*/
public function ___install() {
// create the page our module will be assigned to
$page = new Page();
$page->template = 'admin';
$page->name = self::pageName;
// installs to the admin "Setup" menu ... change as you see fit
$page->parent = $this->pages->get($this->config->adminRootPageID)->child('name=setup');
$page->process = $this;
// we will make the page title the same as our module title
//$page->title = 'Admin Help';
$page->title = $this->_('Admin Help');
// save the page
$page->save();
// tell the user we created this page
$this->message("Created Page: {$page->path}");
}
/**
* Called only when your module is uninstalled
*
* This should return the site to the same state it was in before the module was installed.
*
*/
public function ___uninstall() {
// find the page we installed, locating it by the process field (which has the module ID)
// it would probably be sufficient just to locate by name, but this is just to be extra sure.
$moduleID = $this->modules->getModuleID($this);
$page = $this->pages->get("template=admin, process=$moduleID, name=" . self::pageName);
if($page->id) {
// if we found the page, let the user know and delete it
$this->message("Deleting Page: {$page->path}");
$page->delete();
}
}
}