aboutsummaryrefslogtreecommitdiff
path: root/mod/ecml
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-14 22:25:37 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-14 22:25:37 +0000
commit436ecaf476e5052434d0841aeeb7c0ccf8dd76f1 (patch)
tree73cfe69b7ee9aca03dcf1c62dc4437a99e27cab5 /mod/ecml
parent9b1f2384134da90edc116790babaa37ce7991151 (diff)
downloadelgg-436ecaf476e5052434d0841aeeb7c0ccf8dd76f1.tar.gz
elgg-436ecaf476e5052434d0841aeeb7c0ccf8dd76f1.tar.bz2
Changed tokenizer for ECML to support attribute quotes.
Added core youtube and slideshare keywords. Passing the full keyword and attribute string to views. git-svn-id: http://code.elgg.org/elgg/trunk@5735 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/ecml')
-rw-r--r--mod/ecml/ecml_functions.php101
-rw-r--r--mod/ecml/start.php29
-rw-r--r--mod/ecml/views/default/ecml/keywords/slideshare.php34
-rw-r--r--mod/ecml/views/default/ecml/keywords/youtube.php43
4 files changed, 175 insertions, 32 deletions
diff --git a/mod/ecml/ecml_functions.php b/mod/ecml/ecml_functions.php
index dca4e03f9..f0dcafa24 100644
--- a/mod/ecml/ecml_functions.php
+++ b/mod/ecml/ecml_functions.php
@@ -52,6 +52,8 @@ function ecml_parse_view_match($matches) {
// match against custom keywords with optional args
$keyword_info = $CONFIG->ecml_keywords[$keyword];
$vars = ecml_keywords_tokenize_params($params_string);
+ $vars['ecml_keyword'] = $keyword;
+ $vars['ecml_params_string'] = $params_string;
$content = elgg_view($keyword_info['view'], $vars);
break;
}
@@ -65,35 +67,102 @@ function ecml_parse_view_match($matches) {
}
/**
- * Creates an array from a "name=value, name2=value2" string.
+ * Creates an array from a name=value name2='value2' name3="value3" string.
*
* @param $string
* @return array
*/
function ecml_keywords_tokenize_params($string) {
- $pairs = array_map('trim', explode(',', $string));
- $params = array();
-
- foreach ($pairs as $pair) {
- list($name, $value) = explode('=', $pair);
- $name = trim($name);
- $value = trim($value);
+ if (empty($string)) {
+ return array();
+ }
- // normalize BOOL values
- if ($value === 'true') {
- $value = TRUE;
- } elseif ($value === 'false') {
- $value = FALSE;
+ $params = array();
+ $pos = 0;
+ $char = substr($string, $pos, 1);
+
+ // working var for assembling name and values
+ $operand = $name = '';
+
+ while ($char !== FALSE) {
+ switch ($char) {
+ // handle quoted names/values
+ case '"':
+ case "'":
+ $quote = $char;
+
+ $next_char = substr($string, ++$pos, 1);
+ while ($next_char != $quote) {
+ if ($next_char === FALSE) {
+ // no matching quote. bail.
+ return array();
+ }
+ $operand .= $next_char;
+ $next_char = substr($string, ++$pos, 1);
+ }
+ break;
+
+ case ECML_ATTR_SEPARATOR:
+ // normalize true and false
+ if ($operand == 'true'){
+ $operand = TRUE;
+ } elseif ($operand == 'false') {
+ $operand = FALSE;
+ }
+ $params[$name] = $operand;
+ $operand = $name = '';
+ break;
+
+ case ECML_ATTR_OPERATOR:
+ // save name, switch to value
+ $name = $operand;
+ $operand = '';
+ break;
+
+ default:
+ $operand .= $char;
}
- // don't check against value since a falsy/empty value is valid.
- if ($name) {
- $params[$name] = $value;
+ $char = substr($string, ++$pos, 1);
+ }
+
+ // need to get the last attr
+ if ($name && $operand) {
+ if ($operand == 'true'){
+ $operand = TRUE;
+ } elseif ($operand == 'false') {
+ $operand = FALSE;
}
+ $params[$name] = $operand;
}
return $params;
+
+ // this is much faster, but doesn't allow quoting.
+// $pairs = array_map('trim', explode(',', $string));
+// $params = array();
+//
+// foreach ($pairs as $pair) {
+// list($name, $value) = explode('=', $pair);
+//
+// $name = trim($name);
+// $value = trim($value);
+//
+// // normalize BOOL values
+// if ($value === 'true') {
+// $value = TRUE;
+// } elseif ($value === 'false') {
+// $value = FALSE;
+// }
+//
+// // don't check against value since a falsy/empty value is valid.
+// if ($name) {
+// $params[$name] = $value;
+// }
+// }
+//
+// return $params;
}
/**
diff --git a/mod/ecml/start.php b/mod/ecml/start.php
index a0fd3c929..6bf1a565d 100644
--- a/mod/ecml/start.php
+++ b/mod/ecml/start.php
@@ -13,7 +13,6 @@
* Update docs / help
* Check for SQL injection problems.
* Check entity keyword views against fullview. Force to FALSE?
- *
*/
/**
@@ -23,6 +22,9 @@ function ecml_init() {
require_once(dirname(__FILE__) . '/ecml_functions.php');
global $CONFIG;
+ define('ECML_ATTR_SEPARATOR', ' ');
+ define('ECML_ATTR_OPERATOR', '=');
+
// help page
register_page_handler('ecml', 'ecml_help_page_handler');
@@ -107,7 +109,8 @@ 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_]+):?([^\]]+)?\]\]/';
+ //$keyword_regex = '/\[\[([a-z0-9_]+):?([^\]]+)?\]\]/';
+ $keyword_regex = '/\[\[([a-z0-9_]+)([^\]]+)?\]\]/';
$CONFIG->ecml_current_view = $params['view'];
$return_value = preg_replace_callback($keyword_regex, 'ecml_parse_view_match', $return_value);
@@ -116,7 +119,7 @@ function ecml_parse_view($hook, $entity_type, $return_value, $params) {
/**
- * Register some default keywords.
+ * Register default keywords.
*
* @param unknown_type $hook
* @param unknown_type $entity_type
@@ -125,20 +128,14 @@ function ecml_parse_view($hook, $entity_type, $return_value, $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')
- );
+ $keywords = array('youtube', 'slideshare');
- $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')
- );
+ foreach ($keywords as $keyword) {
+ $return_value[$keyword] = array(
+ 'view' => "ecml/keywords/$keyword",
+ 'description' => elgg_echo("ecml:keywords:$keyword")
+ );
+ }
return $return_value;
}
diff --git a/mod/ecml/views/default/ecml/keywords/slideshare.php b/mod/ecml/views/default/ecml/keywords/slideshare.php
new file mode 100644
index 000000000..1881a1a89
--- /dev/null
+++ b/mod/ecml/views/default/ecml/keywords/slideshare.php
@@ -0,0 +1,34 @@
+<?php
+/**
+ * ECML Slideshare support
+ *
+ * @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/
+ */
+
+// this wants the "wordpress.com" embed code.
+// to make life easier on users, don't require them to add the "s
+// and just chop out the id= bit here from the full attr list
+
+$id = str_replace('id=', '', $vars['ecml_params_string']);
+$width = (isset($vars['width'])) ? $vars['width'] : 450;
+$height = (isset($vars['height'])) ? $vars['height'] : 369;
+
+if ($id) {
+ // @todo need to check if the & should be encoded.
+
+ $slide_url = "http://static.slideshare.net/swf/ssplayer2.swf?id=$id";
+
+ echo "
+<object type=\"application/x-shockwave-flash\" wmode=\"opaque\" data=\"$slide_url\" width=\"$width\" height=\"$height\">
+ <param name=\"movie\" value=\"$slide_url\" />
+ <param name=\"allowFullScreen\" value=\"true\" />
+ <param name=\"allowScriptAccess\" value=\"always\" />
+
+ <embed src=\"$slide_url\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"$width\" height=\"$height\"></embed>
+</object>
+";
+} \ No newline at end of file
diff --git a/mod/ecml/views/default/ecml/keywords/youtube.php b/mod/ecml/views/default/ecml/keywords/youtube.php
new file mode 100644
index 000000000..87fb669d2
--- /dev/null
+++ b/mod/ecml/views/default/ecml/keywords/youtube.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * ECML Youtube support
+ *
+ * @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/
+ */
+
+$src = (isset($vars['src'])) ? $vars['src'] : FALSE;
+$width = (isset($vars['width'])) ? $vars['width'] : 480;
+$height = (isset($vars['height'])) ? $vars['height'] : 385;
+
+// need to extract the video id.
+// the src arg can take a full url or an id.
+// assume if no youtube.com that it's an id.
+if (strpos($src, 'youtube.com') === FALSE) {
+ $vid = $src;
+} else {
+ // grab the v param
+ if ($parts = parse_url($src)) {
+ if (isset($parts['query'])) {
+ parse_str($parts['query'], $query_arr);
+ $vid = (isset($query_arr['v'])) ? $query_arr['v'] : FALSE;
+ }
+ }
+}
+
+if ($vid) {
+ $movie_url = "http://www.youtube.com/v/$vid";
+
+ echo "
+<object width=\"$width\" height=\"$height\">
+ <param name=\"movie\" value=\"$movie_url\"></param>
+ <param name=\"allowFullScreen\" value=\"true\"></param>
+ <param name=\"allowscriptaccess\" value=\"always\"></param>
+
+ <embed src=\"$movie_url\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"$width\" height=\"$height\"></embed>
+</object>
+ ";
+} \ No newline at end of file