Elgg  Version master
plugin_text_file.php
Go to the documentation of this file.
1 <?php
2 
4 
5 elgg_set_context('admin');
6 
7 $plugin_id = (string) elgg_extract('plugin_id', $vars);
9 
10 $filename = elgg_extract('filename', $vars);
11 
12 elgg_unregister_external_file('css', 'elgg');
13 
14 if (!$plugin instanceof \ElggPlugin) {
15  $error = elgg_echo('admin:plugins:markdown:unknown_plugin');
16  $body = elgg_view_layout('admin', [
17  'content' => $error,
18  'title' => $error,
19  ]);
20  echo elgg_view_page($error, $body, 'admin');
21  return;
22 }
23 
26  $file_contents = file_get_contents($plugin->getPath() . $filename);
27 }
28 
29 if (!$file_contents) {
30  $error = elgg_echo('admin:plugins:markdown:unknown_file');
31  $body = elgg_view_layout('admin', ['content' => $error, 'title' => $error]);
32  echo elgg_view_page($error, $body, 'admin');
33  return;
34 }
35 
36 $title = $plugin->getDisplayName() . ": $filename";
37 
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_view_layout(string $layout_name, array $vars=[])
Displays a layout with optional parameters.
Definition: views.php:352
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
Definition: ElggPlugin.php:17
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(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
const ADDITIONAL_TEXT_FILES
Definition: ElggPlugin.php:30
$error
Bad request error.
Definition: 400.php:6
elgg_view_page(string $title, string|array $body, string $page_shell= 'default', array $vars=[])
Assembles and outputs a full page.
Definition: views.php:235
elgg_set_context(string $context)
Elgg context library.
Definition: context.php:29
if(in_array($filename,\ElggPlugin::ADDITIONAL_TEXT_FILES)) if(!$file_contents) $title
$plugin_id
$vars
Definition: theme.php:5
elgg_format_element(string $tag_name, array $attributes=[], string $text= '', array $options=[])
Format an HTML element.
Definition: output.php:145
if(!$plugin instanceof\ElggPlugin) $file_contents