-
Notifications
You must be signed in to change notification settings - Fork 0
/
vojo.module
720 lines (650 loc) · 24.4 KB
/
vojo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
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
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
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
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
<?php
// Optimization: maintain a single-query-duration cache of published story counts per group
$_vojo_group_published_story_counts = array();
/**
* Load up helpers
*/
function vojo_init(){
// load custom blocks
module_load_include('inc', 'vojo', 'includes/vojo.blocks');
// load costom voip-drupal scripts
module_load_include('inc', 'vojo', 'vojo.script');
drupal_add_css(drupal_get_path('module', 'vojo') .'/css/vojo-site-header.css');
}
/**
* Implementation of hook_menu.
*/
function vojo_menu() {
$items = array();
$items['nolink'] = array(
'page callback' => 'vojo_nolink',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['story'] = array(
'title' => 'Create story',
'page callback' => 'vojo_create_story',
'access arguments' => array('access content'),
);
$items['story/%ctools_js/go'] = array(
'page callback' => 'vojo_create_story_ajax_callback',
'page arguments' => array(1),
'access arguments' => array('access content'),
);
return $items;
}
function vojo_create_story() {
// Load the modal library and add the modal javascript.
ctools_include('modal');
ctools_modal_add_js();
$output = l('Load modal content', 'story/nojs/go', array(
'attributes' => array('class' => 'ctools-use-modal')));
return $output;
}
function vojo_create_story_ajax_callback($js = FALSE) {
global $user;
$links = array();
foreach ($user->og_groups as $group) {
$group_nid = $group['nid'];
$links[] = l($group['title'], 'node/add/blog', array('attributes' => array('title' => t('Add a new story in this group.')),'query' => "gids[]=$group_nid"));
}
$title = t('Create story');
$intro = "<p>".t("Select the group you'd like to post your story to:")."</p>";
$output = $intro.theme('item_list', $links);
if ($js) {
ctools_include('ajax');
ctools_include('modal');
ctools_modal_render($title, $output);
// above command will exit().
}
else {
drupal_set_title($title);
return $output;
}
}
/**
* Implementation of hook_menu_alter.
*/
function vojo_menu_alter(&$items) {
// Unset default blog module's blog path (we want to use views instead).
unset($items['blog/%user_uid_optional']);
$items['blog/%user_uid_optional']['page callback'] = FALSE;
}
/**
* Page callback
*/
function vojo_nolink() {
$output = 'This is a dummy page used for nolink menu items. You should not be able to see this page';
return t($output);
}
/**
* Implementation of hook_link_alter.
*/
function vojo_link_alter(&$links, $node) {
// Change user's blog link to so it points to custom view (instead of core blog module's path)
if ($links['blog_usernames_blog']) {
$links['blog_usernames_blog']['href'] = 'blogs/'. $node->name;
}
}
/**
* Implementation of hook_profile_alter.
*/
function vojo_profile_alter(&$account) {
// Override path to user's blog, /blogs points to a view instead.
$account->content['summary']['blog']['#value'] = l(t('View recent blog entries'), 'blogs/'. $account->name, array('attributes' => array('title' => 'Read latest blog entries.')));
// Unset groups since we want to add them in a separate block/pane.
unset($account->content['summary']['groups']);
}
/**
* Helper function to find out how many stories are published within a group. This is written
* to be called by themes and custom panels/blocks if they need to embed the count somewhere. This
* manages a qingle-query-duration cache for you.
*/
function vojo_group_published_story_count($group_id) {
global $_vojo_group_published_story_counts;
$story_count = 0;
if(array_key_exists($group_id,$_vojo_group_published_story_counts)){
$story_count = $_vojo_group_published_story_counts[$group_id];
} else {
$results = db_query("SELECT count(n.nid) as story_count
FROM {og_ancestry} as oga, {node} as n
WHERE oga.nid=n.nid AND oga.group_nid=$group_id AND n.status=1", $group_id);
while ($object = db_fetch_object($results)) {
$story_count = $object->story_count;
}
$_vojo_group_published_story_counts[$group_id] = $story_count;
}
return $story_count;
}
/**
* Use this to get the path to an image inside the "img" dir of this module
*/
function _vojo_image_path($imgfile){
return theme_image(drupal_get_path('module','vojo')."/img/".$imgfile);
}
/**
* Return the VoipVoice id (name) for a ISO standard language code. All calls to change
* the language during a voice call should query this function to return the VoipVoice
* for a language.
*/
function vojo_voice_id_for_language( $language=null ) {
$voice = 'vojo-en'; // default to english
switch($language) {
case 'en':
case 'en-us':
$voice = 'vojo-en';
break;
case 'es':
$voice = 'vojo-es';
break;
case 'pt':
case 'pt-br':
$voice = 'vojo-pt';
break;
}
return $voice;
}
/**
* Implementation of hook_voipscript_load_script().
*/
function vojo_voipscript_load_script($script_name, $params = NULL) {
if ($script_name == 'vojo_group') {
module_load_include('inc', 'vojo', 'vojo.script');
$node = node_load($params['nid']);
return _vojo_group_script($node);
}
elseif ($script_name == 'vojo_simple_group') {
module_load_include('inc', 'vojo', 'vojo.script');
$node = node_load($params['nid']);
return _vojo_simple_group_script($node);
}
elseif ($script_name == 'vojo_record_blog') {
module_load_include('inc', 'vojo', 'vojo.script');
$node = node_load($params['nid']);
return _vojo_record_blog_script($node, $params['simple']);
}
elseif ($script_name == 'vojo_save_blog') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_save_blog_script($params['nid'], $params['fid'], $params['uid']);
}
elseif ($script_name == 'vojo_login') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_login_script($params['number']);
}
elseif ($script_name == 'vojo_welcome') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_welcome_script($params['number']);
}
elseif ($script_name == 'vojo_redirect_to_group') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_redirect_to_group_script($params['number']);
}
elseif ($script_name == 'vojo_pick_create_or_anon') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_pick_create_or_anon_script($params['number'], $params['nid']);
}
elseif ($script_name == 'vojo_create_user') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_create_user_script($params['number'], $params['nid'], $params['simple']);
}
elseif ($script_name == 'vojo_pick_language') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_pick_language_script();
}
elseif ($script_name == 'vojo_change_language') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_change_language_script($params['language']);
}
elseif ($script_name == 'vojo_play_extension') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_get_play_extension_script($params['eid']);
}
elseif ($script_name == 'vojo_default_incoming_text') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_default_incoming_text();
}
elseif ($script_name == 'vojo_update_username') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_update_username($params['number'], $params['text']);
}
elseif ($script_name == 'vojo_hear_group_stories') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_hear_group_stories_script($params['nid']);
}
elseif ($script_name == 'vojo_route_inboud_text') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_route_inbound_text($params['number'], $params['text']);
}
elseif ($script_name == 'vojo_post_sms_story') {
module_load_include('inc', 'vojo', 'vojo.script');
return _vojo_post_sms_story($params['number'], $params['text'], $params['nid'], $params['anon']);
}
}
/**
* Implementation of hook_voipscript_get_script_names().
*/
function vojo_voipscript_get_script_names() {
return array(
'vojo_group',
'vojo_simple_group',
'vojo_record_blog',
'vojo_save_blog',
'vojo_login',
'vojo_welcome',
'vojo_redirect_to_group',
'vojo_pick_create_or_anon',
'vojo_create_user',
'vojo_pick_language',
'vojo_change_language',
'vojo_play_extension',
'vojo_default_incoming_text',
'vojo_update_username',
'vojo_hear_group_stories',
'vojo_route_inboud_text',
'vojo_post_sms_story'
);
}
/**
* Implementation of hook_ctools_plugin_dierctory() to let the system know
* we implement task and task_handler plugins.
*/
function vojo_ctools_plugin_directory($module, $plugin) {
return 'plugins/' . $plugin;
}
/** --------- OPENLAYERS ------------------------------------------------------ **/
/**
* Define custom styles for rendering the markers on a map.
* Implements hook_openlayers_styles().
* http://drupal.org/node/620602
*/
function vojo_openlayers_styles() {
$styles = array();
$style = new stdClass();
$style->api_version = 1;
$style->name = 'vojo_default';
$style->title = t('Vojo Default style');
$style->description = t('Basic default style for the vojo website.');
$style->data = array(
'pointRadius' => 6,
'fillColor' => '#ffffff',
'strokeColor' => '#890053',
'strokeWidth' => 4,
'fillOpacity' => 0.9,
'strokeOpacity' => 1
);
$styles[ $style->name ] = $style;
$style = new stdClass();
$style->api_version = 1;
$style->name = 'vojo_selected';
$style->title = t('Vojo Selected style');
$style->description = t('Basic selected style for the vojo website.');
$style->data = array(
'pointRadius' => 10,
'fillColor' => '#ffffff',
'strokeColor' => '#890053',
'strokeWidth' => 8,
'fillOpacity' => 1.0,
'strokeOpacity' => 1.0
);
$styles[ $style->name ] = $style;
$style = new stdClass();
$style->api_version = 1;
$style->name = 'vojo_temporary';
$style->title = t('Vojo Temporary style');
$style->description = t('Basic temporary style for the vojo website.');
$style->data = array(
'pointRadius' => 8,
'fillColor' => '#ffffff',
'strokeColor' => '#890053',
'strokeWidth' => 6,
'fillOpacity' => 0.5,
'strokeOpacity' => 0.5
);
$styles[ $style->name ] = $style;
return $styles;
}
/**
* Tell ctools that we have custom marker styles.
* Implements hook_ctools_plugin_api().
* http://drupal.org/node/620602
*/
function vojo_ctools_plugin_api($module, $api) {
if ($module == "openlayers") {
switch ($api) {
case 'openlayers_styles':
return array('version' => 1);
}
}
}
/**
* Get the url to an audio file stored with this model.
*/
function _vojo_get_audio_url($filename){
global $base_url;
return $base_url."/".drupal_get_path('module','vojo')."/audio/".$filename;
}
/**
* Tweak the blog edit form and setup some callbacks for later customizations
*/
function vojo_form_blog_node_form_alter($form, &$form_state) {
// Hide location field to prevent users from editing it directly.
$form['field_location_string']['#theme'] = FALSE;
$form['#after_build'][] = 'vojo_form_blog_node_form_after_build';
// Add submit handler.
$form['#submit'][] = 'vojo_form_blog_node_form_submit';
// Adjust weight of submit button
$form['buttons']['#type'] = 'markup';
$form['buttons']['#weight'] = 15;
// Hide preview button
unset($form['buttons']['preview']);
// Hide sticky check box
unset($form['options']['sticky']);
}
/* After build function for blog node form */
function vojo_form_blog_node_form_after_build($form, &$form_state) {
global $user;
// Move attachments outside vertical tabs
$form['attachments']['#group'] = '';
// Make attachments fieldset expanded and not collapsible.
$form['attachments']['#collapsed '] = 0;
$form['attachments']['#collapsible'] = 0;
// Hide fields from regular users (authenticaged and bloggers).
if (user_access('administer nodes') == FALSE) {
$form['path']['#access'] = FALSE; // only admins can set custom paths for blog posts
$form['comment_settings']['#access'] = FALSE; // turn off blog post comments
// Hide field_image from everyone except admins, since all image uploading
// should normally be done through file attachments (to be handled by media mover).
$form['field_image']['#access'] = FALSE;
// Hide the audience select area if we are creating a new node.
if (!empty($_GET['gids'][0]) && empty($form['nid']['#value'])) {
// For some reason using '#access' => false causes any values to be ereased on save.
$form['og_nodeapi']['visible']['og_groups']['#prefix'] = '<div style="display: none">';
$form['og_nodeapi']['visible']['og_groups']['#suffix'] = '</div>';
// Unset read only version of audience field.
unset($form['og_nodeapi']['visible']['og_groups_visible']);
}
}
// Make publishing options always expanded
$form['options']['#collapsible'] = FALSE;
$form['options']['#collapsed'] = FALSE;
$form['options']['promote']['#title'] = t("Yes, feature this story!");
// Change title from Publishing options to Promote story if not admin
if (user_access('administer nodes') == FALSE && user_access('override blog published option') == FALSE) {
$form['options']['#title'] = t("Promote story");
}
// pre-fill the WKT search address with the existing location string
$form['field_map']['openlayers_geocoder_query']['#value'] = $form['#node']->field_location_string[0]['value'];
// force hiding of voipnode extension settings (see http://drupal.org/node/1549288)
unset($form['group_voipnode_settings']);
return $form;
}
/* Submit handler for blog node form */
function vojo_form_blog_node_form_submit($form, &$form_state) {
// Grab user entered value from openlayers_geocoder field and save to $form['field_location_string']
$form_state['values']['field_location_string'][0]['value'] = $form['field_map']['openlayers_geocoder_query']['#value'];
}
/**
* Find the node matching the specified phone number, checking in all voipnumber fields.
* Returns false if no match is found. If multiple matches are found, this return the first
* one it finds.
*/
function _vojo_voipnumber_api_nid_from_number($number) {
// look in all the voipnumber fields
foreach( content_fields() as $field){
if($field['type']=='voipnumberfield'){
// determine what table to search in
$table_name= "content_type_".$field['type_name'];
$col_name = $field['field_name']."_vnid";
$sql = "
SELECT num.nid
FROM {".$table_name."} AS g
LEFT JOIN {voipnumber} AS num
ON g.".$col_name."=num.vnid
LEFT JOIN {voipnumber_dialing_codes} AS code
ON num.country_name = code.country
WHERE CONCAT('+', code.code, num.phone_number) = %s";
$result = db_query($sql, $number);
while ($noderow = db_fetch_object($result)) {
return $noderow->nid;
}
}
}
return false;
}
/**
* Find the extension number for a specific node id.
*/
function _vojo_voipextension_api_extension_for_node($nid) {
return db_result(db_query('SELECT eid FROM {voipextension} WHERE module_id = %d', $nid));
}
/**
* Helper function to format phone numbers.
*/
function vojo_format_phone_number($number) {
$parts = array();
if ($number{0} == '+') {
$number = substr($number, 1);
if (is_numeric($number)) {
if (strlen($number) == 19) {
$formatted_number = '+'. substr($number, 0, 2) .' '. substr($number, 2, 2) .' '. substr($number, 4, 3) .'-'. substr($number, 7);
}
// If 12 digits format as Mexican number: +xx xx xxx-xxxxx.
else if (strlen($number) == 11 && substr($number, 0, 1) == '1') {
// 10 digit with US country code: +1 (xxx) xxx-xxxx.
$formatted_number = '+1 ('. substr($number, 1, 3) .') '. substr($number, 4, 3) .'-'. substr($number, 7);
}
else if ((strlen($number) == 12 || strlen($number) == 13) && substr($number, 0, 2) == '55') {
// Brazillian +55 aa nnnn nnnn or +55 aa nnnn nnnnn
$parts[] = '+55';
$parts[] = substr($number, 2, 2);
$parts[] = substr($number, 4, 4);
$parts[] = substr($number, 8);
$formatted_number = implode(' ', $parts);
}
// If 10 digits format as US number: (xxx) xxx-xxxx.
else if (strlen($number) == 10) {
$formatted_number = '('. substr($number, 0, 3) .') '. substr($number, 3, 3) .'-'. substr($number, 6);
} else {
watchdog('vojo', "Unrecognized phone number format: $number");
}
}
else {
$formatted_number = $number;
}
} else {
// Local number
$formatted_number = $number;
}
return $formatted_number;
}
/** THEME FUNCTIONS **/
function vojo_theme() {
$items['vojo_site_header'] = array(
'arguments' => array('items' => NULL),
'template' => 'templates/vojo-site-header',
);
$items['dropdown_links'] = array(
'arguments' => array('links' => NULL, 'attributes' => NULL),
);
return $items;
}
function vojo_preprocess_vojo_site_header(&$vars) {
global $user;
$vars['base_path'] = base_path();
// Generate user links menu
$menu_tree = menu_tree_page_data('secondary-links');
$vars['user_links'] = '<div id="vojo-user-menu" class="vojo-header-menu">';
if ($vars['logged_in'] == 1) {
// The parent menu item showing the user name is hard coded for easier
// rendering of the user name. Couldn't get it to work as a menu callback.
$vars['user_links'] .= '<ul id="vojo-user-links" class="vojo-header-links"><li class="menu-parent">';
$vars['user_links'] .= '<span>'. $user->name .'</span>';
$vars['user_links'] .= theme('dropdown_links', $menu_tree, array('class' => 'submenu'));
$vars['user_links'] .= '</li></ul>';
}
else {
$vars['user_links'] .= l(t('Login'), 'user/login', array('attributes' => array('id' => 'vojo-login-link'))) .' ';
if (variable_get('user_register', '0')) {
// Include signup link if users are allowed to register online
$vars['user_links'] .= ' | '. l(t('Signup'), 'user/register', array('attributes' => array('id' => 'vojo-login-link')));
}
}
$vars['user_links'] .= '</div>';
$vars['primary_links'] = theme_get_setting('toggle_primary_links') ? menu_primary_links() : array();
// Generate language links menu
$q = $_GET['q'];
$translations = translation_path_get_translations($q);
$languages = language_list('enabled');
$output = '<div id="vojo-language-menu" class="vojo-header-menu">';
$output .= '<ul id="vojo-language-links" class="vojo-header-links"><li class="menu-parent">';
$output .= '<span>'.t('Languages').'</span>';
$output .= '<ul class="submenu">';
// figure out the paths (copied from the switcher block view in locale.module)
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$links = array();
foreach ($languages[1] as $language) {
$links[$language->language] = array(
'href' => $path,
'title' => $language->native,
'language' => $language,
'attributes' => array('class' => 'language-link'),
);
}
drupal_alter('translation_link', $links, $path);
$output .= theme('links', $links, array());
$output .= '</li></ul>';
$output .= '</div>';
$vars['language_links'] = $output;
// Get voip call in number, set at admin/voip/call/settings
$vars['vojo_callin_number'] = vojo_format_phone_number(variable_get('voipcall_cid_number',''));
// Load language swicher block
$lang_block = module_invoke('locale', 'block', 'view', 0);
$vars['language_switcher'] = '<div class="block-locale">'. $lang_block['content'] .'</div>';
}
function vojo_preprocess_page(&$vars) {
// Provide persistant vojo site-wide header (for global operations like login)
$vars['vojo_site_header'] = theme('vojo_site_header');
}
/**
* Provides our own version of theme_links() with markup for a dropdown menu.
*/
function theme_dropdown_links($links, $attributes = array('class' => 'links')) {
global $language;
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $menu_item) {
$link = $menu_item['link'];
// Do not show disabled menu items and submenu
if ($link['hidden'] != 1) {
$class = 'menu-' . $menu_item['link']['mlid'];
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($menu_item['below']) {
$class .= ' menu-parent';
}
if ($i == $num_links) {
$class .= ' last';
}
$class .= ' menu-item-' . $i;
if ($link['in_active_trail'] == TRUE) {
$class .= ' active-trail';
}
// Add classes based on path name
$path_alias = drupal_get_path_alias($link['href']);
$class_from_path = str_replace(array('/', ' '), '-', $path_alias);
$class .= ' menu-' . $class_from_path;
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language->language)) {
$class .= ' active';
}
$output .= '<li'. drupal_attributes(array('class' => $class)) .'>';
if (isset($link['href']) && $link['href'] != 'nolink' && $link['href'] != 'vojo_user_name') {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['localized_options']['attributes'])) {
$span_attributes = drupal_attributes($link['localized_options']['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
// Display expanded submenu items, so we can style it as a dropdown menu
if (!empty($menu_item['below']) && $menu_item['link']['expanded'] != 0) {
// reset counter
$i_sub = 0;
$sublinks_count = count($menu_item['below']);
$output .= '<ul class="submenu' . $submenu_class . '">';
foreach ($menu_item['below'] as $child_item) {
$child_link = $child_item['link'];
$class = 'menu-' . $child_item['link']['mlid'];
$options = array();
if ($child_item['link']['localized_options']['fragment']) {
$options = array(
'fragment' => $child_item['link']['localized_options']['fragment'],
);
}
// Only show menu items not set to hidden in UI
if ($child_link['hidden'] != 1) {
$output .= '<li'. drupal_attributes(array ('class' => $class)) .'>';
$output .= l($child_link['title'], $child_link['href'], $options);
$output .= '</li>';
}
$i_sub++;
}
$output .= '</ul>';
// End submenu
}
}
$output .= '</li>';
}
$output .= '</ul>';
}
return $output;
}
/**
* Return true if the node has audio attached
*/
function vojo_node_has_audio($node){
return vojo_node_has_file_with_extension($node,'mp3');
}
/**
* Return true if the node has images attached
*/
function vojo_node_has_image($node){
return $node->field_image[0]!=null;
}
/**
* Return true if the node has video attached
*/
function vojo_node_has_video($node){
return vojo_node_has_file_with_extension($node,'m4v');
}
/**
* Return true if the node has a mediamover completed file with this extension
*/
function vojo_node_has_file_with_extension($node,$ext){
if( property_exists($node, 'media_mover') ) {
foreach($node->media_mover as $mm_config){
foreach($mm_config as $mm_item){
$pathinfo = pathinfo($mm_item['complete_file']);
if(array_key_exists('extension',$pathinfo)){
if($pathinfo['extension']==$ext){
return true;
}
}
}
}
}
return false;
}