aboutsummaryrefslogtreecommitdiff
path: root/mod/ecml/ecml_functions.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-07-08 18:51:34 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-07-08 18:51:34 +0000
commitcf3752e80273d93964305e43481fabc370888a47 (patch)
tree273451f549351eacd8b0e2374ffb2470567926e7 /mod/ecml/ecml_functions.php
parent74c3aaeea871e28b2b1785b9044271d040b84396 (diff)
downloadelgg-cf3752e80273d93964305e43481fabc370888a47.tar.gz
elgg-cf3752e80273d93964305e43481fabc370888a47.tar.bz2
Pulled ECML regex into a constant.
Added ecml_get_keywords(), ecml_parse_string(), ecml_extract_keywords(), ecml_get_keyword_info(). Added callback for resolving ECML given an embed code / URL. Removed unused page setup hook. Added web services support. Updated docs. git-svn-id: http://code.elgg.org/elgg/trunk@6664 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/ecml/ecml_functions.php')
-rw-r--r--mod/ecml/ecml_functions.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/mod/ecml/ecml_functions.php b/mod/ecml/ecml_functions.php
index eba8460b2..a4ec8be4f 100644
--- a/mod/ecml/ecml_functions.php
+++ b/mod/ecml/ecml_functions.php
@@ -9,6 +9,39 @@
* @link http://elgg.org/
*/
+/**
+ * Parses a string for ECML.
+ *
+ * @param string $string
+ * @return string $string with ECML replaced by HTML.
+ */
+function ecml_parse_string($string, $view = NULL) {
+ global $CONFIG;
+
+ $CONFIG->ecml_current_view = $view;
+
+ return preg_replace_callback(ECML_KEYWORD_REGEX, 'ecml_parse_view_match', $string);
+}
+
+/**
+ * Returns ECML-style keywords found in $string.
+ * Doesn't validate them.
+ * Returns an array of keyword => arguments
+ *
+ * @param string $string
+ * @return array
+ */
+function ecml_extract_keywords($string) {
+ $return = array();
+
+ if (preg_match_all(ECML_KEYWORD_REGEX, $string, $matches)) {
+ foreach ($matches[1] as $i => $keyword) {
+ $return[] = array('keyword' => $keyword, 'params' => $matches[2][$i]);
+ }
+ }
+
+ return $return;
+}
/**
* Parse ECML keywords
@@ -204,6 +237,11 @@ function ecml_is_valid_keyword($keyword, $view = NULL) {
if (!isset($CONFIG->ecml_keywords[$keyword])) {
return FALSE;
}
+
+ // don't check against views. Already know it's a real one.
+ if (!$view) {
+ return TRUE;
+ }
// this keyword is restricted to certain views
if (isset($CONFIG->ecml_keywords[$keyword]['restricted'])
@@ -222,3 +260,34 @@ function ecml_is_valid_keyword($keyword, $view = NULL) {
return $r;
}
+
+/**
+ * Grab the ECML keywords as saved in $CONFIG or regenerate.
+ */
+function ecml_get_keywords($recache = FALSE) {
+ global $CONFIG;
+
+ if (isset($CONFIG->ecml_keywords) && !$recache) {
+ return $CONFIG->ecml_keywords;
+ }
+
+ $keywords = trigger_plugin_hook('get_keywords', 'ecml', NULL, array());
+ $CONFIG->ecml_keywords = $keywords;
+ return $keywords;
+}
+
+/**
+ * Return basic info about the keyword.
+ *
+ * @param string $keyword
+ * @return array
+ */
+function ecml_get_keyword_info($keyword) {
+ global $CONFIG;
+
+ if (isset($CONFIG->ecml_keywords[$keyword])) {
+ return $CONFIG->ecml_keywords[$keyword];
+ }
+
+ return FALSE;
+} \ No newline at end of file