-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwysiwyg_imageupload.filter.inc
67 lines (57 loc) · 1.78 KB
/
wysiwyg_imageupload.filter.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// $Id$
// Copyright (c) 2010 KontextWork GbR
// Author: Eugen Mayer
/**
* Implementation of hook_filter().
*/
function wysiwyg_imageupload_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(0 => t('Drupal Wiki inline-images'));
case 'description':
return t('Converts Drupal Wiki inline images to HTML.');
case 'process':
return _wysiwyg_imageupload_filter_process($text);
case 'no cache':
return FALSE;
case 'settings':
$form = array();
return $form;
default:
return $text;
}
}
function _wysiwyg_imageupload_filter_pattern() {
return '/\[\[wysiwyg_imageupload:(\d+):([^\]]*?)\]\]/e';
}
/**
* Finds all the occurences of a inline image tag
*/
function _wysiwyg_imageupload_filter_process(&$body) {
// Syntax: [[inlineimage:<iid>:<inlineargs>]]
$body = preg_replace(array(_wysiwyg_imageupload_filter_pattern()), array("_wysiwyg_imageupload_render_nodeview($1,'$2');"), $body);
return $body;
}
/**
* returns a rendered(html) image for the tag
*/
function _wysiwyg_imageupload_render_nodeview($iid, $arguments) {
$arguments = _wysiwyg_imageupload_unserialize_arguments(urldecode($arguments));
$image_obj = _wysiwyg_imageupload_load_inline_entity($iid);
return theme('wysiwyg_imageupload_render_image_entity', $image_obj, $arguments);
}
/**
* Loads the comma seperated argument list into an array
*/
function _wysiwyg_imageupload_unserialize_arguments($arguments) {
// Argument syntax: key=value,key=value,key=value
$result = array();
// TODO: What about values with commas?
$arguments = explode(',', $arguments);
foreach ($arguments as $value) {
$pair = explode('=', $value);
$result[ $pair[0] ] = $pair[1];
}
return $result;
}