Elgg  Version 4.x
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 
10 elgg_unregister_external_file('css', 'elgg');
11 elgg_require_js('elgg/admin');
12 
13 if (!$plugin) {
14  $error = elgg_echo('admin:plugins:markdown:unknown_plugin');
15  $body = elgg_view_layout('admin', [
16  'content' => $error,
17  'title' => $error,
18  ]);
19  echo elgg_view_page($error, $body, 'admin');
20  return true;
21 }
22 
25  $file_contents = file_get_contents($plugin->getPath() . $filename);
26 }
27 
28 if (!$file_contents) {
29  $error = elgg_echo('admin:plugins:markdown:unknown_file');
30  $body = elgg_view_layout('admin', ['content' => $error, 'title' => $error]);
31  echo elgg_view_page($error, $body, 'admin');
32  return true;
33 }
34 
35 $title = $plugin->getDisplayName() . ": $filename";
36 
37 use \Michelf\MarkdownExtra;
38 $text = MarkdownExtra::defaultTransform($file_contents);
39 
40 $body = elgg_view_layout('admin', [
41  // setting classes here because there's no way to pass classes
42  // to the layout
43  'content' => elgg_format_element('div', ['class' => 'elgg-markdown'], $text),
44  'title' => $title,
45  'filter_id' => 'admin/plugin_text_file',
46  'filter_value' => "{$plugin_id}/{$filename}",
47 ]);
48 
49 echo elgg_view_page($title, $body, 'admin');
elgg_set_context($context)
Elgg context library.
Definition: context.php:29
elgg_get_plugin_from_id(string $plugin_id)
Elgg plugins library Contains functions for managing plugins.
Definition: plugins.php:15
elgg_unregister_external_file(string $type, string $name)
Unregister an external file.
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
elgg_view_page($title, $body, $page_shell= 'default', $vars=[])
Assembles and outputs a full page.
Definition: views.php:288
const ADDITIONAL_TEXT_FILES
Definition: ElggPlugin.php:28
$error
Bad request error.
Definition: 400.php:6
elgg_format_element($tag_name, array $attributes=[], $text= '', array $options=[])
Format an HTML element.
Definition: output.php:134
if(in_array($filename,\ElggPlugin::ADDITIONAL_TEXT_FILES)) if(!$file_contents) $title
elgg_require_js($name)
Request that Elgg load an AMD module onto the page.
$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:686
elgg_view_layout($layout_name, $vars=[])
Displays a layout with optional parameters.
Definition: views.php:406
if(!$plugin) $file_contents
$filename
elgg echo
Translates a string.
Definition: deprecated.js:530
$vars['head']
Definition: html.php:24