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

Contents of /contributions/modules/fcf/fcf.module

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


Revision 1.3 - (show annotations) (download) (as text)
Sat Aug 18 13:00:56 2007 UTC (2 years, 3 months ago) by flevour
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -1 lines
File MIME type: text/x-php
#168435 by ica: PHP4 compatibility issue: parse_url() call with 2 args is available after PHP 5.1.2
1 <?php
2
3 // implementation of hook_menu
4 function fcf_menu($may_cache) {
5 $items = array();
6
7 if ($may_cache) {
8 $items[] = array(
9 'path' => 'admin/settings/fcf',
10 'title' => t('First Click Free'),
11 'description' => t('Configure First Click Free role.'),
12 'callback' => 'drupal_get_form',
13 'callback arguments' => array('fcf_settings'));
14 }
15 return $items;
16 }
17
18
19 // implementation of hook_init
20 function fcf_init() {
21 global $user;
22 /* if user is anonymous and we are coming from Google, add to $user a special role
23 to let him see the article.
24 Parse referrer to check if click comes from Google.
25 As per http://tinyurl.com/2jtwoc, check http://*.google.*
26 */
27 $components = parse_url($_SERVER['HTTP_REFERER']); // subdomain.google.com
28 $host = $components['host'];
29 list($tld, $domain, $subdomain) = array_reverse(explode('.', $host)); // (com, google, subdomain)
30
31 if(variable_get('fcf_debug', 0) || $user->uid == 0 && $domain == "google" ) {
32 // fetch special role using rid from settings. default to 1 = anonymous user rid
33 $role = db_fetch_object(db_query('SELECT * FROM {role} WHERE rid = %s', variable_get('fcf_rid', 1)));
34 if($role) { // should be always true, but we check nevertheless to avoid errors
35 $user->roles[$role->rid] = $role->name;
36 // if we are in debug mode, show an informative message
37 if(variable_get('fcf_debug', 0)) {
38 $message = t("First Click Free debug mode activated. You may toggle debug mode on !link.", array("!link" => l(t("First Click Free settings"), "admin/settings/fcf")));
39 }
40 else {
41 $message = t("Customize the message displayed to users when referred by Google. It's useful for helping or instructing them to register if they wish.");
42 }
43 drupal_set_message($message, "fcf");
44 }
45 }
46 }
47
48 // settings form (called from _menu)
49 function fcf_settings() {
50 $roles = user_roles(TRUE); // first argument TRUE excludes anonymous role from listing
51 $form['fcf_rid'] = array(
52 '#type' => 'select',
53 '#title' => t('Extra for First Click Free users'),
54 '#default_value' => variable_get('fcf_rid', 1),
55 '#options' => $roles,
56 );
57 $form['fcf_debug'] = array(
58 '#type' => 'checkbox',
59 '#title' => t('Enable debug mode.'),
60 '#default_value' => variable_get('fcf_debug', 0),
61 );
62 return system_settings_form($form);
63 }
64

  ViewVC Help
Powered by ViewVC 1.1.2