1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Controller; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use WBW\Bundle\BootstrapBundle\Model\WikiPage; |
17
|
|
|
use WBW\Bundle\SyntaxHighlighterBundle\API\SyntaxHighlighterConfig; |
18
|
|
|
use WBW\Bundle\SyntaxHighlighterBundle\API\SyntaxHighlighterDefaults; |
19
|
|
|
use WBW\Bundle\SyntaxHighlighterBundle\Provider\SyntaxHighlighterStringsProvider; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Wiki controller. |
23
|
|
|
* |
24
|
|
|
* @author webeweb <https://github.com/webeweb/> |
25
|
|
|
* @package WBW\Bundle\BootstrapBundle\Controller |
26
|
|
|
*/ |
27
|
|
|
class WikiController extends AbstractBootstrapController { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the Syntax Highlighter config. |
31
|
|
|
* |
32
|
|
|
* @return SyntaxHighlighterConfig Returns the SyntaxHighlighter config. |
33
|
|
|
*/ |
34
|
|
|
protected function getSyntaxHighlighterConfig() { |
35
|
|
|
|
36
|
|
|
// Get the SyntaxHighlighter strings provider. |
37
|
|
|
$provider = $this->get(SyntaxHighlighterStringsProvider::SERVICE_NAME); |
38
|
|
|
|
39
|
|
|
// Initialize the SyntaxHighlighter config. |
40
|
|
|
$config = new SyntaxHighlighterConfig(); |
41
|
|
|
$config->setStrings($provider->getSyntaxHighlighterStrings()); |
42
|
|
|
|
43
|
|
|
// Return the SyntaxHighlighter config. |
44
|
|
|
return $config; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the Syntax Highlighter defaults. |
49
|
|
|
* |
50
|
|
|
* @return SyntaxHighlighterDefaults Returns the SyntaxHighlighter defaults. |
51
|
|
|
*/ |
52
|
|
|
protected function getSyntaxHighlighterDefaults() { |
53
|
|
|
|
54
|
|
|
// Initialize the SyntaxHighlighter defaults. |
55
|
|
|
$defaults = new SyntaxHighlighterDefaults(); |
56
|
|
|
|
57
|
|
|
// Return the SyntaxHighlighter defaults. |
58
|
|
|
return $defaults; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get the wiki pages. |
63
|
|
|
* |
64
|
|
|
* @return WikiPage[] Returns the wiki pages. |
65
|
|
|
*/ |
66
|
|
|
public static function getWikiPages() { |
67
|
|
|
|
68
|
|
|
// Initialize the table of contents. |
69
|
|
|
$tableContents = []; |
70
|
|
|
|
71
|
|
|
// Twig extensions > Code |
72
|
|
|
$tableContents[] = new WikiPage("twig-extension", "code", "basic-block", "Basic block"); |
73
|
|
|
$tableContents[] = new WikiPage("twig-extension", "code", "inline", "Inline"); |
74
|
|
|
$tableContents[] = new WikiPage("twig-extension", "code", "sample-output", "Sample output"); |
75
|
|
|
$tableContents[] = new WikiPage("twig-extension", "code", "user-input", "User input"); |
76
|
|
|
$tableContents[] = new WikiPage("twig-extension", "code", "variable", "Variable"); |
77
|
|
|
|
78
|
|
|
// Twig extensions > Component |
79
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "alert", "Alert"); |
80
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "badge", "Badge"); |
81
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "button", "Button"); |
82
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "glyphicon", "Glyphicon"); |
83
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "label", "Label"); |
84
|
|
|
$tableContents[] = new WikiPage("twig-extension", "component", "progress-bar", "Progress bar"); |
85
|
|
|
|
86
|
|
|
// Twig extensions > Form |
87
|
|
|
$tableContents[] = new WikiPage("twig-extension", "form", "button", "Button"); |
88
|
|
|
|
89
|
|
|
// Twig extensions > Grid |
90
|
|
|
$tableContents[] = new WikiPage("twig-extension", "grid", "grid", "Grid"); |
91
|
|
|
|
92
|
|
|
// Twig extensions > Image |
93
|
|
|
$tableContents[] = new WikiPage("twig-extension", "image", "base64", "Base 64"); |
94
|
|
|
|
95
|
|
|
// Twig extensions > Plugin |
96
|
|
|
$tableContents[] = new WikiPage("twig-extension", "plugin", "font-awesome", "Font Awesome"); |
97
|
|
|
$tableContents[] = new WikiPage("twig-extension", "plugin", "jquery-inputmask", "jQuery InputMask"); |
98
|
|
|
$tableContents[] = new WikiPage("twig-extension", "plugin", "material-design-iconic-font", "Material Design Iconic Font"); |
99
|
|
|
|
100
|
|
|
// Twig extensions > Table |
101
|
|
|
$tableContents[] = new WikiPage("twig-extension", "table", "button", "Button"); |
102
|
|
|
|
103
|
|
|
// Twig extensions > Typography |
104
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "bold", "Bold"); |
105
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "deleted", "Deleted"); |
106
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "heading", "Heading"); |
107
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "inserted", "Inserted"); |
108
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "italic", "Italic"); |
109
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "marked", "Marked"); |
110
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "small", "Small"); |
111
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "strikethrough", "Strikethrough"); |
112
|
|
|
$tableContents[] = new WikiPage("twig-extension", "typography", "underlined", "Underlined"); |
113
|
|
|
|
114
|
|
|
// Twig extensions > Utility |
115
|
|
|
$tableContents[] = new WikiPage("twig-extension", "utility", "role-label", "Role label"); |
116
|
|
|
|
117
|
|
|
// Return the table of contents. |
118
|
|
|
return $tableContents; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Displays a wiki page. |
123
|
|
|
* |
124
|
|
|
* @param Request $request The request. |
125
|
|
|
* @param string $category The category. |
126
|
|
|
* @param string $package The parent. |
127
|
|
|
* @param string $page The page. |
128
|
|
|
* @return Response Returns the response. |
129
|
|
|
*/ |
130
|
|
|
public function indexAction(Request $request, $category, $package, $page) { |
|
|
|
|
131
|
|
|
|
132
|
|
|
// Initialize. |
133
|
|
|
$wikiPages = self::getWikiPages(); |
134
|
|
|
$wikiPage = null; |
135
|
|
|
|
136
|
|
|
// Find the wiki page. |
137
|
|
|
foreach ($wikiPages as $current) { |
138
|
|
|
if ($category === $current->getCategory() && $package === $current->getPackage() && $page === $current->getPage()) { |
139
|
|
|
$wikiPage = $current; |
140
|
|
|
break; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
// Check if the wiki page exists. |
145
|
|
|
if (null === $wikiPage) { |
146
|
|
|
|
147
|
|
|
// Set the default wiki page. |
148
|
|
|
$wikiPage = $wikiPages[0]; |
149
|
|
|
|
150
|
|
|
// Notify the user. |
151
|
|
|
$this->notifyDanger("The requested page was not found"); |
152
|
|
|
$this->notifyInfo("You have been redirected to homepage"); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// Set the template. |
156
|
|
|
$template = [ |
157
|
|
|
"@", |
158
|
|
|
$wikiPage->getBundle(), |
159
|
|
|
"/Wiki/", |
160
|
|
|
$wikiPage->getCategory(), |
161
|
|
|
"/", |
162
|
|
|
$wikiPage->getPackage(), |
163
|
|
|
"/", |
164
|
|
|
$wikiPage->getPage(), |
165
|
|
|
".html.twig", |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
// Returns the response. |
169
|
|
|
return $this->render(implode("", $template), [ |
170
|
|
|
"syntaxHighlighterConfig" => $this->getSyntaxHighlighterConfig(), |
171
|
|
|
"syntaxHighlighterDefaults" => $this->getSyntaxHighlighterDefaults(), |
172
|
|
|
"wikiPage" => $wikiPage, |
173
|
|
|
"wikiPages" => $wikiPages, |
174
|
|
|
]); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
} |
178
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.