| 33 |
* Implementation of hook_perm(). |
* Implementation of hook_perm(). |
| 34 |
*/ |
*/ |
| 35 |
function tellafriend_perm() { |
function tellafriend_perm() { |
| 36 |
return array('access tellafriend form'); |
return array('access tellafriend form', 'administer tellafriend form'); |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
/** |
/** |
| 57 |
'access arguments' => array('access tellafriend form'), |
'access arguments' => array('access tellafriend form'), |
| 58 |
'type' => MENU_CALLBACK, |
'type' => MENU_CALLBACK, |
| 59 |
); |
); |
| 60 |
|
$items['tellafriend_block_form'] = array( |
| 61 |
|
'title' => variable_get('tellafriend_blocktitle', 'Tell a friend'), |
| 62 |
|
'page callback' => 'tellafriend_block_form', |
| 63 |
|
'page arguments' => array('tellafriend_block_form'), |
| 64 |
|
'access arguments' => array('access tellafriend block'), |
| 65 |
|
'type' => MENU_CALLBACK, |
| 66 |
|
); |
| 67 |
|
|
| 68 |
return $items; |
return $items; |
| 69 |
} |
} |
| 128 |
'#description' => t('This is the maximum number of email addresses that can be included per tell-a-friend request.'), |
'#description' => t('This is the maximum number of email addresses that can be included per tell-a-friend request.'), |
| 129 |
); |
); |
| 130 |
|
|
| 131 |
$form['tellafriend_block'] = array( |
$form['tellafriend_block_options'] = array( |
| 132 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 133 |
'#title' => t('Block settings'), |
'#title' => t('Block settings'), |
| 134 |
'#collapsible' => TRUE, |
'#collapsible' => TRUE, |
| 135 |
'#collapsed' => FALSE, |
'#collapsed' => FALSE, |
| 136 |
); |
); |
| 137 |
$form['tellafriend_block']['tellafriend_block_title'] = array( |
$form['tellafriend_block_options']['tellafriend_block_title'] = array( |
| 138 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 139 |
'#title' => t('Block Title'), |
'#title' => t('Block Title'), |
| 140 |
'#default_value' => variable_get('tellafriend_block_title', t("Spread the world...")), |
'#default_value' => variable_get('tellafriend_block_title', t("Spread the world...")), |
| 142 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 143 |
'#description' => t('This will be the title for the tellafriend block (if activated : go to admin/build/block to activate or not the block).'), |
'#description' => t('This will be the title for the tellafriend block (if activated : go to admin/build/block to activate or not the block).'), |
| 144 |
); |
); |
| 145 |
$form['tellafriend_block']['tellafriend_block_linklabel'] = array( |
$form['tellafriend_block_options']['tellafriend_block_style'] = array( |
| 146 |
|
'#type' => 'radios', |
| 147 |
|
'#title' => t('Block style'), |
| 148 |
|
'#default_value' => variable_get('tellafriend_block_style', 0), |
| 149 |
|
'#options' => array(0 => t('Link (Default)'), 1 => t('TextField(s)')), |
| 150 |
|
'#description' => t('Select the visual style of the Block. "Link" will display a link to a page to be used by the user to send invitations, "TextField(s)" will display textfields boxes which user can fill with email(s) directly'), |
| 151 |
|
); |
| 152 |
|
$form['tellafriend_block_options']['tellafriend_block_linklabel'] = array( |
| 153 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 154 |
'#title' => t('Link label'), |
'#title' => t('Link label'), |
| 155 |
'#default_value' => variable_get('tellafriend_block_linklabel', t("Tell a friend...")), |
'#default_value' => variable_get('tellafriend_block_linklabel', t("Tell a friend...")), |
| 156 |
'#size' => 70, |
'#size' => 70, |
| 157 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 158 |
'#description' => t('This will be the link which will appear in the tellafriend block.'), |
'#description' => t('This will be the link which will appear in the tellafriend block, if "Link" display option is choosed.'), |
| 159 |
); |
); |
| 160 |
|
$form['tellafriend_block_options']['how_many_email_textfields']= array( |
| 161 |
|
'#title' => t("How many e-mail textfields?"), |
| 162 |
|
'#type' => 'textfield', |
| 163 |
|
'#required' => TRUE, |
| 164 |
|
'#default_value' => variable_get('how_many_email_textfields', 2), |
| 165 |
|
'#description' => t('This is the number of e-mail fields which will be generated on the tellafriend block, if TextField(s) display option is choosed.'), |
| 166 |
|
'#size' => 2, |
| 167 |
|
'#maxlength' => '2', |
| 168 |
|
); |
| 169 |
$form['tellafriend_mail'] = array( |
$form['tellafriend_mail'] = array( |
| 170 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 171 |
'#title' => t('E-mail template'), |
'#title' => t('E-mail template'), |
| 234 |
switch ($delta) { |
switch ($delta) { |
| 235 |
case 0: |
case 0: |
| 236 |
$block = array(); |
$block = array(); |
| 237 |
if (user_access('access tellafriend form')) { |
if (user_access('access tellafriend form')) { |
| 238 |
$blockContent .= '<ul><li class="leaf">' . l(t(variable_get('tellafriend_block_linklabel', t("Tell a friend..."))), 'tellafriend') . '</li></ul>'; |
//drupal_set_message('option = ' . variable_get('tellafriend_block_style'), 'error'); |
| 239 |
$block['content'] = $blockContent; |
|
| 240 |
$block['subject'] = variable_get('tellafriend_block_title', t("Spread the world...")); |
$block['subject'] = variable_get('tellafriend_block_title', t("Spread the world...")); |
| 241 |
|
if (variable_get('tellafriend_block_style', 0) == '0') { //Link |
| 242 |
|
$blockContent .= '<ul><li class="leaf">' . l(t(variable_get('tellafriend_block_linklabel', t("Tell a friend..."))), 'tellafriend') . '</li></ul>'; |
| 243 |
|
$block['content'] = $blockContent; |
| 244 |
|
} |
| 245 |
|
else { //email TextField(s) |
| 246 |
|
$block['content'] = drupal_get_form('tellafriend_block_form'); |
| 247 |
|
} |
| 248 |
} |
} |
| 249 |
} |
} |
| 250 |
return $block; |
return $block; |
| 251 |
} |
} |
| 252 |
} |
} |
| 253 |
|
|
| 254 |
|
|
| 255 |
|
/** |
| 256 |
|
* Generate the tellafriend block form with email TextFields |
| 257 |
|
* |
| 258 |
|
* @return |
| 259 |
|
* A form definition. |
| 260 |
|
*/ |
| 261 |
|
function tellafriend_block_form() { |
| 262 |
|
global $user; |
| 263 |
|
|
| 264 |
|
$form['tellafriend'] = array( |
| 265 |
|
'#value' => t('Recommend @site-name to:', array('@site-name' => variable_get('site_name', t('Drupal')))), |
| 266 |
|
); |
| 267 |
|
|
| 268 |
|
for ($i = 0; $i < variable_get('how_many_email_textfields', 2); $i++) { |
| 269 |
|
$form['tellafriend_addresses'][] = array( |
| 270 |
|
'#type' => 'textfield', |
| 271 |
|
'#size' => 20, |
| 272 |
|
'#name' => 'to[]', |
| 273 |
|
); |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
$form['submit'] = array( |
| 277 |
|
'#type' => 'submit', |
| 278 |
|
'#value' => t('Tell now'), |
| 279 |
|
); |
| 280 |
|
|
| 281 |
|
return $form; |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
|
| 285 |
/** |
/** |
| 286 |
* Generates the form for the page |
* Generates the form for the page |
| 287 |
*/ |
*/ |
| 312 |
); |
); |
| 313 |
$form['tellafriend_addresses'] = array( |
$form['tellafriend_addresses'] = array( |
| 314 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 315 |
'#title' => t("Your friend's e-mail address"), |
'#title' => t("Your friend's e-mail address(es)"), |
| 316 |
'#size' => 70, |
'#size' => 70, |
| 317 |
'#maxlength' => 255, |
'#maxlength' => 255, |
| 318 |
'#required' => TRUE, |
'#required' => TRUE, |
| 438 |
drupal_goto(variable_get('tellafriend_success', variable_get('site_frontpage', 'node'))); |
drupal_goto(variable_get('tellafriend_success', variable_get('site_frontpage', 'node'))); |
| 439 |
} |
} |
| 440 |
|
|
| 441 |
|
//To be done : separate the send action from the function tellafriend_page_submit |
| 442 |
|
function tellafriend_send_mail() { |
| 443 |
|
|
| 444 |
|
} |
| 445 |
|
|
| 446 |
|
/** |
| 447 |
|
* Implementation of hook_mail(). |
| 448 |
|
*/ |
| 449 |
|
function tellafriend_mail($key, &$message, $params) { |
| 450 |
|
$message['from'] .= $params['from']; |
| 451 |
|
$message['subject'] = $params['subject']; |
| 452 |
|
$message['body'] = $params['body']; |
| 453 |
|
$message['headers'] = array_merge($message['headers'], $params['headers']); |
| 454 |
|
$message['headers']['MIME-Version'] = '1.0'; |
| 455 |
|
$message['headers']['Content-Type'] = 'text/html; charset=utf-8'; |
| 456 |
|
} |
| 457 |
|
|
|
|
|