/[drupal]/contributions/modules/upside_down/upside_down.module
ViewVC logotype

Contents of /contributions/modules/upside_down/upside_down.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Wed Aug 13 21:22:45 2008 UTC (15 months, 1 week ago) by cwgordon7
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
Initial commit.
1 <?php
2 // $Id$
3
4 /**
5 * Implementation of hook_filter_tips().
6 */
7 function upside_down_filter_tips($delta, $format, $long = FALSE) {
8 return t('All text will be flipped and displayed upside down.');
9 }
10
11 /**
12 * Implementation of hook_filter().
13 */
14 function upside_down_filter($op, $delta = 0, $format = -1, $text = '') {
15 switch ($op) {
16 case 'list':
17 return array(
18 0 => t('Upside down filter'),
19 );
20
21 case 'description':
22 return t('Flips text upside down. Currently only works with the simple roman alphabet and basic punctuation.');
23
24 case 'process':
25 $text = upside_down_flip_text($text);
26 return $text;
27
28 default:
29 return $text;
30 }
31 }
32
33 /**
34 * Helper function for upside_down_filter() - flips the text.
35 *
36 * @param $text
37 * The text to flip.
38 * @return
39 * The flipped text.
40 */
41 function upside_down_flip_text($text) {
42 $map = array(
43 'a' => 0x0250,
44 'b' => 'q',
45 'c' => 0x0254,
46 'd' => 'p',
47 'e' => 0x01DD,
48 'f' => 0x025F,
49 'g' => 0x0183,
50 'h' => 0x0265,
51 'i' => 0x0131,
52 'j' => 0x027E,
53 'k' => 0x029E,
54 'l' => 0x0283,
55 'm' => 0x026F,
56 'n' => 'u',
57 'r' => 0x0279,
58 't' => 0x0287,
59 'v' => 0x028C,
60 'w' => 0x028D,
61 'y' => 0x028E,
62 '.' => 0x02D9,
63 '[' => ']',
64 '(' => ')',
65 '{' => '}',
66 '?' => 0x00BF,
67 '!' => 0x00A1,
68 "'" => ',',
69 '<' => '>',
70 '_' => 0x203E,
71 ';' => '!',
72 0x203F => 0x2040,
73 0x2045 => 0x2046,
74 0x2234 => 0x2235,
75 );
76 $map += array_flip($map);
77 $text = strrev($text);
78 $lower = strtolower($text);
79 $new_text = '';
80 for ($i = 0; $i < strlen($text); $i++) {
81 if (isset($map[$lower[$i]])) {
82 $new_text .= is_numeric($map[$lower[$i]]) ? _upside_down_unicode_to_utf8($map[$lower[$i]]) : $map[$lower[$i]];
83 }
84 else {
85 $new_text .= $text[$i];
86 }
87 }
88 return $new_text;
89 }
90
91 /**
92 * Helper function for upside_down_flip_text() - convert unicode entities to
93 * utf8.
94 *
95 * @param $char
96 * The character to convert.
97 * @return
98 * The converted character.
99 */
100 function _upside_down_unicode_to_utf8($char) {
101 $output = '';
102 if ($char < 0x80) {
103 return chr($char);
104 }
105 elseif ($char < 0x800) {
106 return chr(0xc0 | ($char >> 6)) . chr(0x80 | ($char & 0x3f));
107 }
108 elseif ($char < 0x10000) {
109 return chr(0xe0 | ($char >> 12)) . chr(0x80 | (($char >> 6) & 0x3f)) . chr(0x80 | ($char & 0x3f));
110 }
111 elseif ($char < 0x200000) {
112 return chr(0xf0 | ($char >> 18)) . chr(0x80 | (($char >> 12) & 0x3f)) . chr(0x80 | (($char >> 6) & 0x3f)) . chr(0x80 | ($char & 0x3f));
113 }
114 return '';
115 }

  ViewVC Help
Powered by ViewVC 1.1.2