| 1 |
<?php
|
| 2 |
// $Id: mobile_codes.filter.inc,v 1.1.2.1 2008/06/03 07:35:48 deciphered Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Mobile Codes filter integration
|
| 7 |
*
|
| 8 |
* Mobile Codes filter integration adds the ability to render a mobile code via
|
| 9 |
* a text filter.
|
| 10 |
*/
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_filter_tips().
|
| 14 |
*/
|
| 15 |
function mobile_codes_filter_tips($delta, $format, $long = FALSE) {
|
| 16 |
if ($long) {
|
| 17 |
return t('
|
| 18 |
Create a Mobile Code using the following format:<br />
|
| 19 |
[mobilecode type="<em>type</em>" data="<em>data</em>" size="<em>size</em>" name="<em>name</em>" tinyurl="<em>tinyurl</em>"]<em>content</em>[/mobilecode]
|
| 20 |
<p>
|
| 21 |
<strong>type</strong>: \'dm\' (Data Matrix), \'qr\' (QR Code) or leave blank for default.<br />
|
| 22 |
<strong>data type</strong>: \'link\', \'text\', \'phone\' or leave blank for default.<br />
|
| 23 |
<strong>size</strong>: \'small\', \'medium\', \'large\' or leave blank for default.<br />
|
| 24 |
<strong>name</strong>: user defined (optional)<br />
|
| 25 |
<strong>tinyurl</strong>: \'0\', \'1\' or leave blank for default.<br />
|
| 26 |
<strong>content</strong>: user defined.
|
| 27 |
</p>
|
| 28 |
');
|
| 29 |
}
|
| 30 |
|
| 31 |
else {
|
| 32 |
return t('
|
| 33 |
Create a Mobile Code using the following format:<br />
|
| 34 |
[mobilecode type="<em>type</em>" data="<em>data type</em>" size="<em>size</em>" name="<em>name</em>" tinyurl="<em>tinyurl</em>"]<em>content</em>[/mobilecode]
|
| 35 |
');
|
| 36 |
}
|
| 37 |
}
|
| 38 |
|
| 39 |
/**
|
| 40 |
* Implementation of hook_filter().
|
| 41 |
*/
|
| 42 |
function mobile_codes_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 43 |
switch ($op) {
|
| 44 |
case 'list':
|
| 45 |
return array(0 => t('Mobile codes filter'));
|
| 46 |
|
| 47 |
case 'description':
|
| 48 |
return t('
|
| 49 |
Create a Mobile Code using the following format:<br />
|
| 50 |
[mobilecode type="<em>type</em>" data="<em>data type</em>" size="<em>size</em>" name="<em>name</em>" tinyurl="<em>tinyurl</em>"]<em>content</em>[/mobilecode]
|
| 51 |
');
|
| 52 |
|
| 53 |
case 'prepare':
|
| 54 |
return $text;
|
| 55 |
|
| 56 |
case 'process':
|
| 57 |
return mobile_codes_filter_process($text, $format);
|
| 58 |
|
| 59 |
case 'settings':
|
| 60 |
return mobile_codes_filter_settings($format);
|
| 61 |
|
| 62 |
default:
|
| 63 |
return $text;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
|
| 67 |
function mobile_codes_filter_process($text, $format) {
|
| 68 |
$attr = '';
|
| 69 |
|
| 70 |
if (preg_match_all('/\[mobilecode([^]]*)\]([^[]*)\[\/mobilecode\]/', $text, $codes, PREG_SET_ORDER)) {
|
| 71 |
foreach ($codes as $match) {
|
| 72 |
if (preg_match_all('/\s(\w+)="([^"]*)"/', $match[1], $attributes, PREG_SET_ORDER)) {
|
| 73 |
foreach ($attributes as $attribute) {
|
| 74 |
$attr[$attribute[1]] = $attribute[2];
|
| 75 |
}
|
| 76 |
}
|
| 77 |
$text = str_replace($match[0], mobile_codes_generate($match[2], $attr, $format), $text);
|
| 78 |
unset($attr);
|
| 79 |
}
|
| 80 |
}
|
| 81 |
|
| 82 |
return $text;
|
| 83 |
}
|
| 84 |
|
| 85 |
function mobile_codes_filter_settings($format) {
|
| 86 |
$form['mobile_codes_filter'] = array(
|
| 87 |
'#type' => 'fieldset',
|
| 88 |
'#title' => t('Mobile Codes filter'),
|
| 89 |
'#collapsible' => TRUE,
|
| 90 |
);
|
| 91 |
$form['mobile_codes_filter'][] = mobile_codes_settings($format);
|
| 92 |
|
| 93 |
return $form;
|
| 94 |
}
|