You are on page 1of 11

<?

php
2
3 /**
4 * Implementation of hook_help
5 */
6 function indic_script_help($path, $arg) {
7 switch ($path) {
8 case 'admin/help#indic_script':
9 $output = '<p>'. t('This Module enables Indic Language Scripts typing in Drupa
l Text Fields and Text Area Fields So that users can create their content in the
ir Language like Google providing native language typing in Orkut.
10 Older name of this module was tamil_type, now it supports Tamil, Tamil 99, Hi
ndi, Malayalam, Bengali, Gujarathi, Kannada, Oriya, Punjab and Telugu Type writt
ing as well as peonitic typing (so the name is indic_script).
11 What it does exactly?') .'</p>';
12
13 $output .= '<p>'. t('If the user type "ammaa" in English it will convert this
to the Tamil word ? (means mother). The Keystroke F9 is set as Hot key for swi
languages.') .'</p>';
14
15 $output .= '<p>'. t('* <b>You should enable/add the block "indic_script" to m
ake this module work.</b>
16 This module is created mainly for indian people to enjoy their Own Language i
n www.') .'</p>';
17 $output .= '<p>'. t('
18 <h3>Features in this release.</h3>
19 <ul>
20 <li>Configuration Page for admin</li>
21 <li>Field/page wise enabling or disabling feature</li>
22 <li>Inline Help Display</li>
23 </ul>
24 <h3>Whats make us Busy?</h3>
25 <ul>
26 <li>Integration with WYSIWYG Editors</li>
27 </ul>
28
29 <h3>Installation/Configuration</h3>
30 <ul>
31 <li>Install the module as usual. </li>
32 <li>Goto admin indic script configuration page and enable the languages.</li>
33 <li>Add the indic_script block to all the pages.</li>
34 <li>goto permissions page and give permissions for users to access indic scri
pt typing.</li>
35 <li>type type type...</li>
36 </ul>
37
38 If characters doesn??t show properly in your browser you can find some helpful
hints in <a target="_blank" href="http://en.wikipedia.org/wiki/Wikipedia:Enabli
ng_complex_text_support_for_Indic_scripts">this Wikipedia page( ??Multilingual su
pport (Indic)? )</a>
39
40 Thanks to all co-operation of the Tamil Friends. Please send us your suggesti
ons.
41 Vinoth <vinoth.3v@gmail.com>
42 <a target="_blank" href="http://Tamil2Friends.com">http://Tamil2Friends.com</
a>') .'</p>';
43 return $output;
44 }
45 }
46

47
48
49 /**
50 * Implementation of hook_perm
51 * Administer -> User management -> Permissions
52 */
53 function indic_script_perm() {
54 return array('administer indic_script', 'access indic_script');
55 }
56
57
58 /**
59 * Implementation of hook_menu
60 */
61 function indic_script_menu() {
62
63 $items = array();
64
65 $items['admin/settings/indic_script'] = array(
66 'page callback' => 'drupal_get_form',
67 'page arguments' => array('indic_script_admin_settings_form'),
68 'title' => 'Indic Script',
69 'access arguments' => array('administer site configuration'),
70 'description' => 'Configure the main indic_script module.',
71 'file' => 'indic_script.admin.inc',
72 );
73
74 //ajax call
75 $items['indic_script/userlang/set'] = array(
76 'page callback' => 'indic_script_set_user_lang',
77 'access callback' => 'user_access',
78 'access arguments' => array('access indic_script'),
79 'type' => MENU_CALLBACK,
80 );
81
82 $items['tamil'] = array(
83 'title' => t('Tamil Typing'),
84 'access arguments' => array('access content'),
85 'page callback' => 'indic_script_tamil_type_page_demo',
86 );
87 return $items;
88 }
89
90 /**
91 * Implementation of hook_elements
92 * Replace textarea with indic_script using callback function (indic_script_pr
ocess_textarea)
93 */
94 function indic_script_elements() {
95 $type = array();
96
97 if (user_access('access indic_script')) {
98 $type['textfield'] = array(
99 '#process' => array( 'indic_script_process_input' ),
100 );
101 $type['textarea'] = array(
102 '#process' => array( 'indic_script_process_textarea' ),
103 );
104 }
105 return $type;

106 }
107
108 /**
109 * process the input
110 *
111 */
112 function indic_script_process_input($element) {
113 if (isset($element['#attributes']['disabled']) && $element['#attributes']['d
isabled'] == 'disabled') {
114 return $element;
115 }
116 if($element['#id']=='edit-pass' ||
117 $element['#id']=='edit-name' ||
118 $element['#id']=='edit-openid-identifier' ||
119 $element['#id']=='edit-mail' ||
120 $element['#id']=='edit-captcha' ){
121 return $element;
122 }
123
124 if(!_indic_script_element_check($element['#id'])){
125 return $element;
126 }
127
128 $onkeypress ="javascript:indic_script_lang(event);" ;
129 $onkeydown ="javascript:toggleKBMode(event);" ;
130 $onfocus ="javascript:indic_script_show_typing_method();" ;
131 $onblur ="javascript:indic_script_hide_typing_method();" ;
132
133
134 _indic_script_attach_element_event($element, 'onkeypress', $onkeypress);
135 _indic_script_attach_element_event($element, 'onkeydown', $onkeydown);
136 _indic_script_attach_element_event($element, 'onfocus', $onfocus);
137 _indic_script_attach_element_event($element, 'onblur', $onblur);
138
139 return $element;
140 }
141
142
143
144
145 /**
146 * This function create the HTML objects required for the indic_script
147 *
148 * @param $element
149 * A fully populated form elment to add the editor to
150 * @return
151 * The same $element with extra indic_script markup and initialization
152 */
153 function indic_script_process_textarea($element) {
154 global $user, $indic_script_simple_toolbar_ids;
155
156 //skip this one, surely nobody wants WYSIWYG here
157
158 switch ($element['#id']) {
159 case 'edit-excl-list':
160 case 'edit-simple-incl-list':
161 case 'edit-simple-incl-paths':
162 case 'edit-simple-incl-fields':
163 case 'edit-excl-fields':
164 case 'edit-excl-paths':

165 case 'edit-js-conf':


166 case 'indic_script_excl_fields':
167 return $element;
168 break;
169 }
170
171
172 if (isset($element['#attributes']['disabled']) && $element['#attributes']['d
isabled'] == 'disabled') {
173 return $element;
174 }
175
176 if(!_indic_script_element_check($element['#id'])){
177 return $element;
178 }
179
180 $onkeypress ="javascript:indic_script_lang(event);" ;
181 $onkeydown ="javascript:toggleKBMode(event);" ;
182 $onfocus ="javascript:indic_script_show_typing_method();" ;
183 $onblur ="javascript:indic_script_hide_typing_method();" ;
184
185
186 _indic_script_attach_element_event($element, 'onkeypress', $onkeypress);
187 _indic_script_attach_element_event($element, 'onkeydown', $onkeydown);
188 _indic_script_attach_element_event($element, 'onfocus', $onfocus);
189 _indic_script_attach_element_event($element, 'onblur', $onblur);
190
191
192 return $element;
193 }
194
195
196 /**
197 * Implementation of hook_init
198 */
199 function indic_script_init() {
200
201 drupal_add_js(drupal_get_path('module', 'indic_script') .'/js/common.js');
202 drupal_add_css(drupal_get_path('module', 'indic_script') .'/css/indic_script
.css');
203 $langs = _indic_script_languages();
204 $enabled_langs = variable_get('indic_script_langs', Array());
205 //print_r($enabled_langs);
206 foreach ($langs as $lang) {
207 if ($enabled_langs[$lang['key']]){
208 //print($lang['key']);
209 drupal_add_js($lang['js']);
210 }
211 }
212
213 }
214
215
216 /**
217 * Implementation of hook_block
218 */
219 function indic_script_block($op='list', $delta=0) {
220
221 if ($op == "list") {
222 $block[0]["info"] = t("indic_script");

223 return $block;


224 }
225 else if ($op == 'view') {
226 if (user_access('access indic_script')) {
227 $block['subject'] = t('indic_script');
228 $block['content'] = indic_script_block_selector();
229 return $block;
230 }
231 }
232 }
233
234 /**
235 * This function helper function
236 *
237 * @return
238 * the block of state indicator of tamil typing
239 */
240 function indic_script_block_selector(){
241
242 //$output = '<div class="indic_script"><a href="'.url('tamil').'">
243 $output = drupal_get_form('indic_script_type_method_form');
244 return $output;
245
246 }
247
248 /**
249 * indic_script_select_form
250 *
251 * @return
252 * elect_form
253 */
254 function indic_script_type_method_form(){
255 static $options;
256 global $user;
257 if (!$options){
258 $langs = _indic_script_languages();
259 $enabled_langs = variable_get('indic_script_langs', Array());
260 $options['en'] = t('English');
261 foreach ($langs as $lang) {
262 if ($enabled_langs[$lang['key']]){
263 $options[$lang['key']] = $lang['title'];
264 }
265 }
266 }
267 $form['destination'] = array(
268 '#type' => 'hidden',
269 '#value' => url('indic_script/userlang/set'),
270 '#id' => 'is_dest_url',
271 );
272 $form['indic_script_typein'] = array(
273 '#type' => 'select',
274 '#title' => t('Type in (F9)'),
275 '#options' => $options,
276 '#default_value' => variable_get('indic_default_lang_'.$user->uid, variable_
get('indic_default_lang','en')),
277 '#weight' => 0,
278 '#attributes' => array(
279 'onchange' => 'indic_script_change_lang(this);'
280 ),
281 );

282 $form['indic_script_show_tips'] = array(


283 '#type' => 'checkbox',
284 '#title' => t('Show Tips?'),
285 '#default_value' => TRUE,
286 );
287 return $form;
288 }
289
290
291 function indic_script_set_user_lang() {
292
293 global $user;
294 if ($user->uid == 0) return;
295
296 variable_set('indic_default_lang_'.$user->uid, arg(3));
297
298 $output = '';
299 $output .= '<?xml version="1.0" encoding="UTF-8"?>';
300 $output .= '<xml><result>OK';
301 $output .= '</result>';
302 $output .= '</xml>';
303
304 drupal_set_header("Content-Type: text/xml");
305 exit($output);
306 }
307
308 /**
309 * This function helper function
310 *
311 */
312 function _indic_script_element_check($element_id) {
313
314 static $excl_mode, $excl_fields, $excl_paths;
315
316 if(!isset($excl_mode)){
317 $excl_mode = variable_get('indic_script_excl_mode', 0);
318 }
319 if(!isset($excl_fields)){
320 $excl_fields = variable_get('indic_script_excl_fields', '');
321 }
322 if(!isset($excl_fields)){
323 $excl_fields = variable_get('indic_script_excl_paths', '');
324 }
325
326 $get_q = $_GET['q'];
327
328 $arr_excl_fields = preg_split("/[\s,]+/", strip_tags($excl_fields));
329 $field_found = _indic_script_element_id_check($element_id, $arr_excl_fields)
;
330
331 $path = drupal_get_path_alias($get_q);
332 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\
<front\\\\>($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_front
page', 'node'), '/') .'\2'), preg_quote($excl_paths, '/')) .')$/';
333 $path_found = preg_match($regexp, $path);
334
335 $found = $field_found || $path_found;
336
337 $result = ($excl_mode == 1) ? $found : !$found;
338 return $result;

339
340 }
341
342 /**
343 * This function helper function
344 *
345 */
346 function _indic_script_element_id_check($search, $array) {
347 foreach ($array as $key => $value) {
348 if (!empty($value) && preg_match('/^'. str_replace('*', '.*', addslashes($va
lue)) .'$/i', $search)) {
349 return true;
350 }
351 }
352 return false;
353 }
354
355
356 function _indic_script_languages() {
357 static $langs;
358 if (!isset($langs)){
359 $langs = module_invoke_all('indic_script_api', 'lang');
360 }
361 return $langs;
362 }
363
364 /**
365 * Implementation of indic_script_api
366 *
367 */
368 function indic_script_indic_script_api($op) {
369
370 $path = drupal_get_path('module', 'indic_script');
371
372 switch($op){
373 case 'lang':
374 $lang[] = array(
375 'lang' => 'ta',
376 'key' => 'ta_en',
377 'title' => t('Tamil Thanglish'),
378 'js' => $path . '/js/' . 'ta.js',
379 );
380 $lang[] = array(
381 'lang' => 'ta',
382 'key' => 'ta_99',
383 'title' => t('Tamil 99'),
384 'js' => $path . '/js/' . 'ta.js',
385 );
386 $lang[] = array(
387 'lang' => 'ta',
388 'key' => 'ta_tw',
389 'title' => t('Tamil TypeWriter'),
390 'js' => $path . '/js/' . 'ta.js',
391 );
392 $lang[] = array(
393 'lang' => 'ma',
394 'key' => 'ma_en',
395 'title' => t('Malayalam Phonetic'),
396 'js' => $path . '/js/' . 'ma.js',
397 );

398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457

$lang[] = array(
'lang' => 'ma',
'key' => 'ma_tw',
'title' => t('Malayalam TypeWriter'),
'js' => $path . '/js/' . 'ma.js',
);
$lang[] = array(
'lang' => 'hi',
'key' => 'hi_en',
'title' => t('Hindi Phonetic'),
'js' => $path . '/js/' . 'hi.js',
);
$lang[] = array(
'lang' => 'hi',
'key' => 'hi_tw',
'title' => t('Hindi TypeWriter'),
'js' => $path . '/js/' . 'hi.js',
);
$lang[] = array(
'lang' => 'be',
'key' => 'be_en',
'title' => t('Bengali Phonetic'),
'js' => $path . '/js/' . 'be.js',
);
$lang[] = array(
'lang' => 'be',
'key' => 'be_tw',
'title' => t('Bengali TypeWriter'),
'js' => $path . '/js/' . 'be.js',
);
$lang[] = array(
'lang' => 'gu',
'key' => 'gu_en',
'title' => t('Gujarathi Phonetic'),
'js' => $path . '/js/' . 'gu.js',
);
$lang[] = array(
'lang' => 'gu',
'key' => 'gu_tw',
'title' => t('Gujarathi TypeWriter'),
'js' => $path . '/js/' . 'gu.js',
);
$lang[] = array(
'lang' => 'ka',
'key' => 'ka_en',
'title' => t('Kannada Phonetic'),
'js' => $path . '/js/' . 'ka.js',
);
$lang[] = array(
'lang' => 'ka',
'key' => 'ka_tw',
'title' => t('Kannada TypeWriter'),
'js' => $path . '/js/' . 'ka.js',
);
$lang[] = array(
'lang' => 'or',
'key' => 'or_en',
'title' => t('Oriya Phonetic'),
'js' => $path . '/js/' . 'or.js',
);

458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

$lang[] = array(
'lang' => 'or',
'key' => 'or_tw',
'title' => t('Oriya TypeWriter'),
'js' => $path . '/js/' . 'or.js',
);
$lang[] = array(
'lang' => 'pu',
'key' => 'pu_en',
'title' => t('Punjab Phonetic'),
'js' => $path . '/js/' . 'pu.js',
);
$lang[] = array(
'lang' => 'pu',
'key' => 'pu_tw',
'title' => t('Punjab TypeWriter'),
'js' => $path . '/js/' . 'pu.js',
);
$lang[] = array(
'lang' => 'te',
'key' => 'te_en',
'title' => t('Telugu Phonetic'),
'js' => $path . '/js/' . 'te.js',
);
$lang[] = array(
'lang' => 'te',
'key' => 'te_tw',
'title' => t('Telugu TypeWriter'),
'js' => $path . '/js/' . 'te.js',
);
return $lang;
}
}
/**
* This is just a page thats allows users can type tamil.
*
* @return
* The page of one text area and help info
*/
function indic_script_tamil_type_page_demo() {
$ourput = drupal_get_form('indic_script_tamil_type_page');
return $ourput;
}
/**
* This is just a page thats allows users can type tamil.
*
* @return
* The page of one text area and help info
*/
function indic_script_tamil_type_page(){
$form = array();
$form['body'] = array(
'#type' => 'textarea',
'#title' => t('Type here'),
'#description' => t(''),
'#rows' => 7,

518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577

'#weight' => 0,
);
$form['body_filter'] = array(
'#type' => 'item',
'#value' => _indic_script_tamil_page_help(),
'#weight' => 1,
);
return $form;
}
/**
* This is just a page thats allows users can type tamil.
*
* @return
* The page of one text area and help info
*/
function _indic_script_tamil_page_help(){

$output .= '
<div><strong> ? ? ? ?
<table>
<tbody>
<tr>
<td><strong>?? ? ? </strong></td>
<td><strong>? ? ? ? </strong></td>
<td><strong>? ? ? ? </strong></td>
</tr>
<tr>
<td valign="top">? - a<br />
? - aa, A<br />
? - i<br />
? - ii, I<br />
? - u<br />
? - uu, U<br />
? - e<br />
- ee, E<br />
- ai<br />
? - o<br />
? - oo, O<br />
? - au<br />
<strong>? ? </strong><br />
? - q<br />
&nbsp;</td>
<td valign="top">? - k, g<br />
? - ng<br />
? - c, s<br />
? - nj, X<br />
? - t, d<br />
- N<br />
- th, dh, T<br />
- w, n-<br />
- p, b<br />
- m<br />
- y<br />
- r<br />
- l<br />
- v<br />
- z<br />
- L<br />
- R<br />

578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604

- n<br />
&nbsp;</td>
<td valign="top">? - j<br />
- sh, ch, Z<br />
- S<br />
- h<br />
? - ksh, kch, kZ<br />
? - sr</td>
</tr>
</tbody>
</table>
</div>';
return $output;
}
/**
* helper function
*
*/
function _indic_script_attach_element_event(&$element, $event, $js) {
if (isset($element['#attributes'][$event])){
$element['#attributes'][$event] = $js + $element['#attributes'][$event] ;
}else{
$element['#attributes'][$event] = $js;
}
}