Elgg  Version 3.0
plugin_text_file.php
Go to the documentation of this file.
1 <?php
2 
3 elgg_set_context('admin');
4 
5 $plugin_id = elgg_extract('plugin_id', $vars);
7 
8 $filename = elgg_extract('filename', $vars);
9 
11 
12 elgg_unregister_css('elgg');
13 elgg_require_js('elgg/admin');
14 
15 $error = false;
16 if (!$plugin) {
17  $error = elgg_echo('admin:plugins:markdown:unknown_plugin');
18  $body = elgg_view_layout('admin', ['content' => $error, 'title' => $error]);
19  echo elgg_view_page($error, $body, 'admin');
20  return true;
21 }
22 
23 $text_files = $plugin->getAvailableTextFiles();
24 
25 if (!array_key_exists($filename, $text_files)) {
26  $error = elgg_echo('admin:plugins:markdown:unknown_file');
27 }
28 
30 $file_contents = file_get_contents($file);
31 
32 if (!$file_contents) {
33  $error = elgg_echo('admin:plugins:markdown:unknown_file');
34 }
35 
36 if ($error) {
37  $title = $error;
38  $body = elgg_view_layout('admin', ['content' => $error, 'title' => $title]);
39  echo elgg_view_page($title, $body, 'admin');
40  return true;
41 }
42 
43 $title = $plugin->getDisplayName() . ": $filename";
44 
45 use \Michelf\MarkdownExtra;
46 $text = MarkdownExtra::defaultTransform($file_contents);
47 
48 $body = elgg_view_layout('admin', [
49  // setting classes here because there's no way to pass classes
50  // to the layout
51  'content' => '<div class="elgg-markdown">' . $text . '</div>',
52  'title' => $title
53 ]);
54 
55 echo elgg_view_page($title, $body, 'admin');
if(!array_key_exists($filename, $text_files)) $file
elgg_echo($message_key, array $args=[], $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_view_page($title, $body, $page_shell= 'default', $vars=[])
Assembles and outputs a full page.
Definition: views.php:360
if(!$plugin) $text_files
elgg_unregister_css($name)
Unregister a CSS file.
Definition: elgglib.php:219
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
Definition: elgglib.php:168
elgg_set_context($context)
Sets the page context.
Definition: pageowner.php:189
elgg echo
Translates a string.
Definition: languages.js:43
$plugin_id
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1131
if(!$file_contents) if($error) $title
$file_contents
elgg_admin_gatekeeper()
Used at the top of a page to mark it as admin only.
elgg_view_layout($layout_name, $vars=[])
Displays a layout with optional parameters.
Definition: views.php:593
$vars['type']
Definition: save.php:11
$filename
elgg_get_plugin_from_id($plugin_id)
Returns an object with the path $path.
Definition: plugins.php:28