Remove the comment about translating block titles
[drupal_ipv6_greeter.git] / ipv6_greeter.module
1 <?php
2
3 /**
4  * @file
5  * Standalone module file to handle ipv6_greeter
6  */
7
8 /**
9  * Implementation of hook_perm().
10  *
11  * @return
12  */
13 function ipv6_greeter_perm() {
14   $perms[] = 'administer IPv6 Greeter';
15   return $perms;
16 }
17
18 /**
19  * Implementation of hook_block().
20  *
21  * @param object $op [optional]
22  * @param object $delta [optional]
23  * @return
24  */
25 function ipv6_greeter_block($op = 'list', $delta = 0) {
26   if ($op == 'list') {
27     $blocks[0]['info'] = 'IPv6 Greeter';
28     return $blocks;
29   }
30   elseif ($op == 'view') {
31     $title = variable_get('ipv6_greeter_blocktitle', 'IPv6 Greeter');
32     if (!empty($title)) {
33       $block['subject'] = t($title);
34     }
35     $block['content'] = _ipv6_greeter_create_content();
36     $block['cache'] = BLOCK_NO_CACHE;
37
38     return $block;
39   }
40 }
41
42 /**
43  * Implementation of hook_menu().
44  */
45 function ipv6_greeter_menu() {
46   $items = array();
47
48   $items['admin/settings/ipv6_greeter'] = array(
49     'title'            => 'IPv6 Greeter',
50     'description'      => 'Setting for IPv6 Greeter',
51     'page callback'    => 'drupal_get_form',
52     'page arguments'   => array('ipv6_greeter_admin_settings'),
53     'access arguments' => array('administer IPv6 Greeter'),
54     'file'             => 'ipv6_greeter.admin.inc',
55   );
56
57   return $items;
58 }
59
60 /**
61  * Internal function to generate code for ipv6_greeter block
62  *
63  * @return
64  *   String containing HTML code for the block
65  */
66 function _ipv6_greeter_create_content() {
67
68   drupal_add_css((drupal_get_path('module', 'ipv6_greeter') .'/ipv6_greeter.css'));
69
70   $client_ip = ip_address();
71
72   $is_client_ipv6 = filter_var($client_ip, FILTER_VALIDATE_IP, array("flags" => FILTER_FLAG_IPV6));
73   if ($is_client_ipv6) {
74     $content = "<div class=\"ipv6_greeter-ipv6-client\"><p>";
75     $content .= t("You've got IPv6!<br />!client_ip",
76       array('!client_ip' => $client_ip));
77     $content .= "</p></div>";
78   }
79   else {
80     if (variable_get('ipv6_greeter_greetIPv4', '1') == '1') {
81       $ipv6 = l('IPv6', 'http://en.wikipedia.org/wiki/IPv6',
82         array( 'attributes' => array('title' => 'Wikipedia - IPv6'))
83       );
84       $content = "<div class=\"ipv6_greeter-ipv4-client\"><p>";
85       $content .= t("You're not on $ipv6, yet!");
86       $content .= "</p></div>";
87     }
88   }
89
90   return $content;
91 }