| 1 |
<?php
|
| 2 |
|
| 3 |
function wwsgd_block ($op = 'list', $delta = 0, $edit = array()) {
|
| 4 |
$wwsgd_block_text_default = "Is this your first time visiting? Consider subscribing to <a href=\"rss.xml\">thissite's RSS feed</a> to get updates.";
|
| 5 |
switch($op) {
|
| 6 |
case 'list':
|
| 7 |
$blocks = array();
|
| 8 |
$blocks[0] = array(
|
| 9 |
'info' => 'What Would Seth Godin Do?',
|
| 10 |
'status' => '',
|
| 11 |
'weight' => 0,
|
| 12 |
'visibility' => 1
|
| 13 |
);
|
| 14 |
return $blocks;
|
| 15 |
break;
|
| 16 |
case 'configure':
|
| 17 |
$form = array();
|
| 18 |
$form['wwsgd_block_text'] = array(
|
| 19 |
'#type' => 'textarea',
|
| 20 |
'#size' => 150,
|
| 21 |
'#description' => 'This text will display in the sidebar block for first-time visitors',
|
| 22 |
'#default_value' => variable_get('wwsgd_block_text', $wwsgd_block_text_default)
|
| 23 |
);
|
| 24 |
$form['wwsgd_max_visits'] = array(
|
| 25 |
'#type' => 'select',
|
| 26 |
'#options' => drupal_map_assoc(array(1,2,3,4,5,6,7,8,9,10)),
|
| 27 |
'#default_value' => variable_get('wwsgd_max_visits', 5),
|
| 28 |
'#description' => 'Number of visits before the block turns off for a user.'
|
| 29 |
);
|
| 30 |
return $form;
|
| 31 |
break;
|
| 32 |
case 'save':
|
| 33 |
variable_set('wwsgd_max_visits', $edit['wwsgd_max_visits']);
|
| 34 |
variable_set('wwsgd_block_text', $edit['wwsgd_block_text']);
|
| 35 |
break;
|
| 36 |
case 'view':
|
| 37 |
$wwsgd_visits = $_COOKIE['wwsgd_visits'];
|
| 38 |
if ($_COOKIE['wwsgd_visits'] < variable_get('wwsgd_max_visits', 5)) {
|
| 39 |
$block['content'] = variable_get('wwsgd_block_text', $wwsgd_block_text_default);
|
| 40 |
$wwsgd_visits = $_COOKIE['wwsgd_visits'] + 1;
|
| 41 |
}
|
| 42 |
global $base_url;
|
| 43 |
$wwsgd_url = parse_url($base_url);
|
| 44 |
setcookie('wwsgd_visits', $wwsgd_visits, time()+60*60*24*365, '/', $wwsgd_url['host']);
|
| 45 |
return $block;
|
| 46 |
break;
|
| 47 |
}
|
| 48 |
}
|