aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/classes/ElggPlugin.php29
-rw-r--r--engine/classes/ElggPluginPackage.php19
-rw-r--r--engine/lib/admin.php70
-rw-r--r--engine/lib/plugins.php2
4 files changed, 107 insertions, 13 deletions
diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php
index f8a6d9b5c..20a8673de 100644
--- a/engine/classes/ElggPlugin.php
+++ b/engine/classes/ElggPlugin.php
@@ -30,7 +30,6 @@ class ElggPlugin extends ElggObject {
$this->access_id = ACCESS_PUBLIC;
}
-
/**
* Loads the plugin by GUID or path.
*
@@ -91,7 +90,6 @@ class ElggPlugin extends ElggObject {
}
}
-
/**
* Save the plugin object. Make sure required values exist.
*
@@ -138,7 +136,6 @@ class ElggPlugin extends ElggObject {
return sanitise_filepath($this->path);
}
-
/**
* Sets the location of this plugin.
*
@@ -149,6 +146,23 @@ class ElggPlugin extends ElggObject {
return $this->attributes['title'] = $id;
}
+ /**
+ * Returns an array of available markdown files for this plugin
+ *
+ * @return array
+ */
+ public function getAvailableTextFiles() {
+ $filenames = $this->package->getTextFilenames();
+
+ $files = array();
+ foreach ($filenames as $filename) {
+ if ($this->canReadFile($filename)) {
+ $files[$filename] = "$this->path/$filename";
+ }
+ }
+
+ return $files;
+ }
// Load Priority
@@ -162,7 +176,6 @@ class ElggPlugin extends ElggObject {
return $this->$name;
}
-
/**
* Sets the priority of the plugin
*
@@ -324,7 +337,6 @@ class ElggPlugin extends ElggObject {
return $this->set($name, $value);
}
-
/**
* Removes a plugin setting name and value.
*
@@ -336,7 +348,6 @@ class ElggPlugin extends ElggObject {
return remove_private_setting($this->guid, $name);
}
-
/**
* Removes all settings for this plugin.
*
@@ -496,7 +507,6 @@ class ElggPlugin extends ElggObject {
return remove_private_setting($user->guid, $name);
}
-
/**
* Removes all User Settings for this plugin
*
@@ -517,7 +527,6 @@ class ElggPlugin extends ElggObject {
return delete_data($q);
}
-
/**
* Removes this plugin's user settings for all users.
*
@@ -566,7 +575,6 @@ class ElggPlugin extends ElggObject {
return true;
}
-
/**
* Is this plugin active?
*
@@ -591,7 +599,6 @@ class ElggPlugin extends ElggObject {
return check_entity_relationship($this->guid, 'active_plugin', $site->guid);
}
-
/**
* Checks if this plugin can be activated on the current
* Elgg installation.
@@ -660,7 +667,6 @@ class ElggPlugin extends ElggObject {
return false;
}
-
/**
* Deactivates the plugin.
*
@@ -694,7 +700,6 @@ class ElggPlugin extends ElggObject {
}
}
-
/**
* Start the plugin.
*
diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php
index b2ec20549..4daab381e 100644
--- a/engine/classes/ElggPluginPackage.php
+++ b/engine/classes/ElggPluginPackage.php
@@ -28,6 +28,15 @@ class ElggPluginPackage {
);
/**
+ * The optional files that can be read and served through the markdown page handler
+ * @var array
+ */
+ private $textFiles = array(
+ 'README.txt', 'CHANGES.txt',
+ 'INSTALL.txt', 'COPYRIGHT.txt', 'LICENSE.txt'
+ );
+
+ /**
* Valid types for provides.
*
* @var array
@@ -286,6 +295,16 @@ class ElggPluginPackage {
return false;
}
+ /****************
+ * Readme Files *
+ ***************/
+
+ /**
+ * Returns an array of present and readable text files
+ */
+ public function getTextFilenames() {
+ return $this->textFiles;
+ }
/***********************
* Dependencies system *
diff --git a/engine/lib/admin.php b/engine/lib/admin.php
index a9a0382cc..06418c44f 100644
--- a/engine/lib/admin.php
+++ b/engine/lib/admin.php
@@ -303,6 +303,7 @@ function admin_init() {
elgg_register_page_handler('admin', 'admin_settings_page_handler');
elgg_register_page_handler('admin_plugin_screenshot', 'admin_plugin_screenshot_page_handler');
+ elgg_register_page_handler('admin_plugin_text_file', 'admin_markdown_page_handler');
}
/**
@@ -446,7 +447,8 @@ function admin_settings_page_handler($page) {
* @return true
*/
function admin_plugin_screenshot_page_handler($pages) {
- admin_gatekeeper(); // only admins can use this - security feature
+ // only admins can use this for security
+ admin_gatekeeper();
$plugin_id = elgg_extract(0, $pages);
// only thumbnail or full.
@@ -485,6 +487,72 @@ function admin_plugin_screenshot_page_handler($pages) {
}
/**
+ * Formats and serves out markdown files from plugins.
+ *
+ * URLs in format like admin_plugin_text_file/<plugin_id>/filename.ext
+ *
+ * The only valid files are:
+ * * README.txt
+ * * CHANGES.txt
+ * * INSTALL.txt
+ * * COPYRIGHT.txt
+ * * LICENSE.txt
+ *
+ * @param type $page
+ */
+function admin_markdown_page_handler($pages) {
+ admin_gatekeeper();
+
+ elgg_set_context('admin');
+
+ elgg_unregister_css('elgg');
+ $url = elgg_get_simplecache_url('js', 'admin');
+ elgg_register_js('elgg.admin', $url);
+ elgg_load_js('elgg.admin');
+ elgg_load_library('elgg:markdown');
+
+ $plugin_id = elgg_extract(0, $pages);
+ $plugin = elgg_get_plugin_from_id($plugin_id);
+ $filename = elgg_extract(1, $pages);
+
+ $error = false;
+
+ if (!$plugin) {
+ $error = elgg_echo('admin:plugins:markdown:unknown_plugin');
+ }
+
+ $text_files = $plugin->getAvailableTextFiles();
+
+ if (!array_key_exists($filename, $text_files)) {
+ $error = elgg_echo('admin:plugins:markdown:unknown_file');
+ }
+
+ $file = $text_files[$filename];
+ $file_contents = file_get_contents($file);
+
+ if (!$file_contents) {
+ $error = elgg_echo('admin:plugins:markdown:unknown_file');
+ }
+
+ if ($error) {
+ $title = $error;
+ $body = elgg_view_layout('admin', array('content' => $error, 'title' => $title));
+ echo elgg_view_page($title, $body, 'admin');
+ return true;
+ }
+
+ $title = $plugin->manifest->getName() . ": $filename";
+ $text = Markdown($file_contents);
+
+ $body = elgg_view_layout('admin', array(
+ 'content' => $text,
+ 'title' => $title
+ ));
+
+ echo elgg_view_page($title, $body, 'admin');
+}
+
+/**
* Adds default admin widgets to the admin dashboard.
*
* @return void
diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php
index 3a144abc5..0947b7a8e 100644
--- a/engine/lib/plugins.php
+++ b/engine/lib/plugins.php
@@ -1088,6 +1088,8 @@ function plugin_init() {
elgg_register_action('admin/plugins/deactivate_all', '', 'admin');
elgg_register_action('admin/plugins/set_priority', '', 'admin');
+
+ elgg_register_library('elgg:markdown', elgg_get_root_path() . 'vendors/markdown/markdown.php');
}
elgg_register_event_handler('init', 'system', 'plugin_init');