-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimagefilter.module
57 lines (51 loc) · 1.95 KB
/
imagefilter.module
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
<?php
/**
* Implementation of hook_filter_info().
*/
function imagefilter_filter_info() {
return array('imagefilter' => array(
'title' => t('Insert Image'),
'description' => t('Inserts images nicely.'),
'process callback' => '_imagefilter_process',
'tips callback' => '_imagefilter_filter_tips',
));
}
/**
* Filter tips callback for imagefilter filter.
*/
function _imagefilter_filter_tips($filter, $format, $long) {
if ($long) {
$output = t('You can use the following syntax .');
} else {
$output = t('');
}
return $output;
}
/**
* Implementation of hook_init().
*/
function imagefilter_init() {
drupal_add_css(drupal_get_path('module', 'imagefilter') . '/imagefilter.css');
}
/**
* Processing function to apply the imagefilter filters
*
* @param string $text
* The text to apply the filter on.
* @param integer $format
* ID if the input format whose settings to use when applying the filters.
* @return string
* The filtered text.
*/
function _imagefilter_process($text, $filter, $format, $langcode, $cache, $cache_id) {
$image_with_float = '/\!\[(.*)\]\((.*)\)\s*({(.*)})*/';
$replacement_with_float= '<a href="?q=sites/default/files/styles/large/public/images/\2" class="colorbox" title="\1" rel="list"><img src="?q=sites/default/files/styles/medium/public/images/\2" class="\4"/></a>';
$image = '/\!\[(.*)\]\((.*)\)/';
$replacement = '<a href="?q=sites/default/files/styles/large/public/images/\2" class="colorbox" title="\1" rel="list"><img src="?q=sites/default/files/styles/medium/public/images/\2"/></a>';
$text = preg_replace($image_with_float, $replacement_with_float, $text);
return preg_replace($image, $replacement, $text);
}
function imagefilter_help($path, $arg) {
if ($path == 'admin/help#imagefilter')
return t('<p>For more information look at <a href="https://github.com/fmms/drupal-imagefilter">https://github.com/fmms/drupal-imagefilter</a>.</p>');
}