aboutsummaryrefslogtreecommitdiff
path: root/mod/ecml/start.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-13 19:13:36 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-13 19:13:36 +0000
commit444fb4e8a3e5189868b8b12c5fdccc4bef6868fc (patch)
tree2df668e1e079d354006938b2f6a0528b2b22d09b /mod/ecml/start.php
parentece80595836be086201629824bceeae05892cd55 (diff)
downloadelgg-444fb4e8a3e5189868b8b12c5fdccc4bef6868fc.tar.gz
elgg-444fb4e8a3e5189868b8b12c5fdccc4bef6868fc.tar.bz2
First version of ecml.
git-svn-id: http://code.elgg.org/elgg/trunk@5722 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/ecml/start.php')
-rw-r--r--mod/ecml/start.php149
1 files changed, 149 insertions, 0 deletions
diff --git a/mod/ecml/start.php b/mod/ecml/start.php
new file mode 100644
index 000000000..0e89b4bbc
--- /dev/null
+++ b/mod/ecml/start.php
@@ -0,0 +1,149 @@
+<?php
+/**
+ * Provides the ECML service to plugins.
+ *
+ * @package ECML
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
+ * @author Curverider Ltd
+ * @copyright Curverider Ltd 2008-2010
+ * @link http://elgg.org/
+ *
+ * @todo
+ * Granular access to keywords based upon view.
+ * Updated docs
+ * Check for SQL injection problems.
+ * Check entity keyword views against fullview. Force to FALSE?
+ *
+ */
+
+/**
+ * Init ECML
+ */
+function ecml_init() {
+ require_once(dirname(__FILE__) . '/ecml_functions.php');
+ global $CONFIG;
+
+ // help page
+ register_page_handler('ecml', 'ecml_help_page_handler');
+
+ // admin access page
+ register_page_handler('ecml_admin', 'ecml_admin_page_handler');
+ register_elgg_event_handler('pagesetup', 'system', 'ecml_pagesetup');
+
+ // parse views for keywords
+ register_plugin_hook('display', 'view', 'ecml_parse_view');
+
+ // show ECML-enabled icon on free-text input areas
+ elgg_extend_view('input/longtext', 'ecml/input_ext');
+ elgg_extend_view('input/plaintext', 'ecml/input_ext');
+ //elgg_extend_view('input/text', 'ecml/input_ext');
+
+ // get register the views we want to parse for ecml
+ // @todo will need to do profiling to see if it would be faster
+ // to foreach through this list and register to specific views or
+ // do the check in a single plugin hook.
+ // Wants array('view_name' => 'Short Description')
+ $CONFIG->ecml_parse_views = trigger_plugin_hook('get_views', 'ecml', NULL, array());
+
+ // provide a few built-in ecml keywords.
+ // @todo could pull this out into an array here to save an API call.
+ register_plugin_hook('get_keywords', 'ecml', 'ecml_keyword_hook');
+
+ // grab the list of keywords and their views from plugins
+ $CONFIG->ecml_keywords = trigger_plugin_hook('get_keywords', 'ecml', NULL, array());
+
+ // grab permissions for specific views/contexts
+ // this is a black list.
+ // it's more efficient to use this as a blacklist
+ // but probably makes more sense from a UI perspective as a whitelist.
+ // uses [views][view_name] = array(keywords, not, allowed)
+ $CONFIG->ecml_permissions = array(
+ 'views' => array()
+ );
+}
+
+/**
+ * Page setup. Adds admin controls to the admin panel for granular permission
+ */
+function ecml_pagesetup(){
+ if (get_context() == 'admin' && isadminloggedin()) {
+ global $CONFIG;
+ add_submenu_item(elgg_echo('ecml'), $CONFIG->wwwroot . 'pg/ecml_admin');
+ }
+}
+
+/**
+ * Display a help page for valid ECML keywords on this page.
+ *
+ * @param array $page
+ */
+function ecml_help_page_handler($page) {
+
+ $content = elgg_view('ecml/help');
+ echo page_draw(elgg_echo('ecml:help'), $content);
+}
+
+/**
+ * Display a help page for valid ECML keywords on this page.
+ *
+ * @param array $page
+ */
+function ecml_admin_page_handler($page) {
+ $content = elgg_view('ecml/admin');
+ echo page_draw(elgg_echo('ecml:admin'), $content);
+}
+
+/**
+ * Parses a registered view / context for supported keywords.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $return_value
+ * @param unknown_type $params
+ * @return string
+ */
+function ecml_parse_view($hook, $entity_type, $return_value, $params) {
+ global $CONFIG;
+
+ // give me everything that is not a ], possibly followed by a :, and surrounded by [[ ]]s
+ $keyword_regex = '/\[\[([a-z0-9_]+):?([^\]]+)?\]\]/';
+
+ if (array_key_exists($params['view'], $CONFIG->ecml_parse_views)) {
+ $CONFIG->ecml_current_view = $params['view'];
+
+ $return_value = preg_replace_callback($keyword_regex, 'ecml_parse_view_match', $return_value);
+ }
+
+ return $return_value;
+}
+
+
+/**
+ * Register some default keywords.
+ *
+ * @param unknown_type $hook
+ * @param unknown_type $entity_type
+ * @param unknown_type $return_value
+ * @param unknown_type $params
+ * @return unknown_type
+ */
+function ecml_keyword_hook($hook, $entity_type, $return_value, $params) {
+ $return_value['login_box'] = array(
+ 'view' => 'account/forms/login',
+ 'description' => elgg_echo('ecml:keywords:login_box')
+ );
+
+ $return_value['user_list'] = array(
+ 'view' => 'ecml/keywords/user_list',
+ 'description' => elgg_echo('ecml:keywords:user_list')
+ );
+
+ $return_value['site_stats'] = array(
+ 'view' => 'ecml/keywords/site_stats',
+ 'description' => elgg_echo('ecml:keywords:site_stats')
+ );
+
+ return $return_value;
+}
+
+register_elgg_event_handler('init', 'system', 'ecml_init'); \ No newline at end of file