materio_user.module 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. <?php
  2. /**
  3. * Implements hook_init().
  4. */
  5. function materio_user_init() {
  6. drupal_add_js(drupal_get_path('module', 'materio_user').'/js/materio_user.min.js');
  7. }
  8. /**
  9. * Implements hook_permission().
  10. */
  11. function materio_user_permission() {
  12. $perms = array(
  13. 'view own user profile' => array(
  14. 'title' => t('view own user profile'),
  15. 'description' => t('view own user profile'),
  16. ),
  17. 'access to online payment' => array(
  18. 'title' => t('access to online payment'),
  19. 'description' => t('Access to online payment'),
  20. ),
  21. );
  22. $simplenews_cats = simplenews_category_list();
  23. // dsm($simplenews_cats);
  24. foreach ($simplenews_cats as $tid => $name) {
  25. $perms["subscribe to simplenews category $tid"] = array(
  26. 'title' => t("subscribe to simplenews category $name"),
  27. // 'description' => t('Access to online payment'),
  28. );
  29. }
  30. return $perms;
  31. }
  32. function materio_user_menu(){
  33. $items = array();
  34. $base = array(
  35. 'type' => MENU_CALLBACK,
  36. 'file' => 'materio_user.pages.inc',
  37. );
  38. $items['materio_user/registerblock'] = $base+array(
  39. 'title' => 'Materio base user ajax',
  40. 'page callback' => 'materio_user_registerblock',
  41. // 'page arguments' => array(),
  42. 'access callback' => TRUE,
  43. );
  44. $items['materio_user/loginandregisterblock'] = $base+array(
  45. 'title' => 'Materio base user ajax',
  46. 'page callback' => 'materio_user_loginandregisterblock',
  47. // 'page arguments' => array(),
  48. 'access callback' => TRUE,
  49. );
  50. $items['materio_user/register/submit'] = $base+array(
  51. 'title' => 'Materio base user ajax',
  52. 'page callback' => 'materio_user_register_submit',
  53. // 'page arguments' => array(),
  54. 'access callback' => TRUE,
  55. );
  56. $items['materio_user/login/submit'] = $base+array(
  57. 'title' => 'Materio base user ajax',
  58. 'page callback' => 'materio_user_login_submit',
  59. // 'page arguments' => array(),
  60. 'access callback' => TRUE,
  61. );
  62. return $items;
  63. }
  64. /**
  65. * Implements hook_menu_alter().
  66. */
  67. function materio_user_menu_alter(&$items) {
  68. $items['user/%user']['access callback'] = 'user_access';
  69. $items['user/%user']['access arguments'] = array('view own user profile');
  70. }
  71. /**
  72. * Implements hook_block_info().
  73. */
  74. function materio_user_block_info() {
  75. $blocks['user_createaccount'] = array(
  76. 'info' => t('Create an account block'),
  77. 'cache' => DRUPAL_NO_CACHE
  78. );
  79. $blocks['user_register'] = array(
  80. 'info' => t('Register block'),
  81. 'cache' => DRUPAL_NO_CACHE
  82. );
  83. $blocks['old_database_link'] = array(
  84. 'info' => t('Old data base link'),
  85. 'cache' => DRUPAL_NO_CACHE
  86. );
  87. $blocks['front_link'] = array(
  88. 'info' => t('Front page link'),
  89. 'cache' => DRUPAL_NO_CACHE
  90. );
  91. return $blocks;
  92. }
  93. /**
  94. * Implements hook_block_view().
  95. */
  96. function materio_user_block_view($delta = '') {
  97. global $user, $language;
  98. $block = array();
  99. switch ($delta) {
  100. case 'user_createaccount':
  101. if(isset($user->roles[1])){
  102. $block['subject'] = '';
  103. if (drupal_is_front_page()) {
  104. $block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
  105. $block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
  106. }else{
  107. $block['content'] .= '<h3>'. t('Create your materiO\' account') . '</h3>';
  108. $block['content'] .= drupal_render(drupal_get_form('user_register_form'));
  109. }
  110. }
  111. break;
  112. case 'user_register':
  113. if(isset($user->roles[1])){
  114. $block['subject'] = '';//drupal_is_front_page() ? t('Your projects will born from here') : t('Create your materiO\' account');
  115. $block['content'] = '<h3>'. t('Login') . '</h3>';
  116. $ulog_form = drupal_get_form('user_login');
  117. $block['content'] .= drupal_render($ulog_form);
  118. if (drupal_is_front_page()) {
  119. $block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
  120. $block['content'] .= l(t('Join us'), 'node/11187', array("attributes"=>array("class"=>array("join"))));
  121. }else{
  122. $block['content'] .= '<h3>'. t('<span>or </span>create your materiO\' account') . '</h3>';
  123. $block['content'] .= drupal_render(drupal_get_form('user_register_form'));
  124. }
  125. // $block['content'] .= l(t('Pricing'), 'node/11187', array('attributes' => array('class' => 'pricing'),));
  126. }
  127. break;
  128. case 'old_database_link':
  129. if( (isset($user->roles[6]) || isset($user->roles[8])) && $user->created < strtotime('01-12-2012') ){
  130. // dsm($user, 'user');
  131. $block['subject'] = '';
  132. $path = 'http://base.materio.com';
  133. if($language->language == 'fr')
  134. $path .= '/index_fr.html';
  135. $block['content'] = l(t('Old database'), $path);
  136. }
  137. break;
  138. case 'front_link':
  139. $block['subject'] = '';
  140. $block['content'] = l('<i class="fi-home"></i><span class="text">'.t('home').'</span>', '<front>', array('html'=>true));
  141. break;
  142. }
  143. return $block;
  144. }
  145. /**
  146. * Implements hook_form_alter().
  147. */
  148. function materio_user_form_alter(&$form, &$form_state, $form_id) {
  149. // dsm($form_id);
  150. if( $form_id == "user_register_form" && !user_access('administer users') ){
  151. // dsm($form);
  152. $form['account']['pass']['#type'] = 'password';
  153. $form['account']['pass']['#title'] = t('Password');
  154. $form['actions']['#type'] = "container";
  155. $form['actions']['submit']['#value'] = t('Join');
  156. // $form['termsofservices'] = array(
  157. // '#type' => 'checkbox',
  158. // '#title' => t('I accept') .' '. l(t('the materiO terms of services'), 'node/11183'),
  159. // '#required' => true,
  160. // );
  161. // $form['#submit'][] = "materio_user_user_register_form_submit";
  162. }
  163. if($form_id == "user_login" ){
  164. // dsm($form);
  165. $form['actions']['#type'] = "container";
  166. // $form['actions']['submit']['#value'] = t('Join');
  167. // if( $_GET['q'] == 'node/11187' ){
  168. // $form['#submit'][] = "materio_user_user_login_form_submit";
  169. // }
  170. }
  171. # https://drupal.org/comment/6293810#comment-6293810
  172. if( $form_id == "webform_client_form_11186" ){
  173. // dsm($form, '$form');
  174. materio_user_webform_client_11186_form_alter($form, $form_state, $form_id);
  175. }
  176. if( $form_id == "uc_cart_checkout_form" ){
  177. materio_user_uc_cart_checkout_form_alter($form, $form_state, $form_id);
  178. }
  179. // if( $form_id == "user_profile_form" ){
  180. // //dsm($form, '$form');
  181. // $form['account']['pass']['#type'] = "new_password_confirm";
  182. // }
  183. if ( $form_id == "simplenews_subscriptions_multi_block_form"){
  184. // dsm($form);
  185. $options = array();
  186. foreach ($form['newsletters']['#options'] as $tid => $name) {
  187. if(user_access("subscribe to simplenews category $tid")){
  188. $options[$tid] = $name;
  189. }
  190. }
  191. $form['newsletters']['#options'] = $options;
  192. }
  193. }
  194. // function materio_user_user_register_form_submit($form, &$form_state){
  195. // dsm($form, 'form');
  196. // dsm($form_state, 'form_state');
  197. // dsm($_REQUEST, '$_REQUEST');
  198. // dsm($_GET, '$_GET');
  199. // unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
  200. // $form_state['redirect'] = array(
  201. // 'node/11187',
  202. // array(
  203. // 'fragment' => $_GET['q'] == 'node/11187' ? 'content-bottom' : '', // if we register from the membership page, then go directly to the form
  204. // )
  205. // );
  206. // $frontlink = l('continue with basic', '<front>');
  207. // // drupal_get_messages('status');
  208. // drupal_set_message(t('Welcome, you just join materiO\'! now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink)));
  209. // }
  210. // function materio_user_user_login_form_submit($form, &$form_state){
  211. // unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
  212. // $form_state['redirect'] = array(
  213. // 'node/11187',
  214. // array(
  215. // 'fragment' => 'content-bottom', // if we login from the membership page, then go directly to the form
  216. // )
  217. // );
  218. // }
  219. /*
  220. _ _ _ _
  221. ___ _ _| |_ ___ ___ ___|_|___| |_|_|___ ___
  222. |_ -| | | . |_ -| _| _| | . | _| | . | |
  223. |___|___|___|___|___|_| |_| _|_| |_|___|_|_|
  224. |_|
  225. //(nid : 11186)
  226. */
  227. # prefill the webform form with user profil values
  228. # add validate and submit functions
  229. function materio_user_webform_client_11186_form_alter(&$form, &$form_state, $form_id){
  230. // dsm($form_id, 'form_id');
  231. // dsm($form, "form");
  232. // dsm($form_state, "form_state");
  233. $form['#validate'][] = "materio_user_webform_client_11186_validate";
  234. $form['#submit'][] = "materio_user_webform_client_11186_submit";
  235. # dont fill default values if form is been rebuilded (by address module)
  236. if($form_state["rebuild"])
  237. return;
  238. global $user;
  239. // dsm($user, 'user');
  240. $member_profile = profile2_load_by_user($user, 'adherent');
  241. // dsm($member_profile, "member_profile");
  242. $columnright = &$form['submitted']['column_right'];
  243. $columnright['me']['firstname']['#default_value'] = $member_profile->field_first_name['und'][0]['value'];
  244. $columnright['me']['name']['#default_value'] = $member_profile->field_name['und'][0]['value'];
  245. $columnright['company']['administrative_e_mail']['#default_value'] = $member_profile->field_administrative_email['und'][0]['value'];
  246. $columnright['company']['s']['company']['#default_value'] = $member_profile->field_organization['und'][0]['value'];
  247. $columnright['company']['s']['activity_sector']['#default_value'] = $member_profile->field_activity_sector['und'][0]['value'];
  248. $columnright['company']['d']['vat_number_intra_ce']['#default_value'] = $member_profile->field_vat_number_intra_ce['und'][0]['value'];
  249. $columnright['company']['d']['website']['#default_value'] = $member_profile->field_user_website['und'][0]['url'];
  250. if( isset($member_profile->field_adresse['und'][0]) ){
  251. $address = $member_profile->field_adresse['und'][0];
  252. $formaddress = &$columnright['company']['location']['#address'];
  253. $formaddress['country'] = $address['country'];
  254. $formaddress['thoroughfare'] = $address['thoroughfare'];
  255. $formaddress['premise'] = $address['premise'];
  256. $formaddress['postal_code'] = $address['postal_code'];
  257. $formaddress['locality'] = $address['locality'];
  258. }
  259. $columnright['company']['phone_number']['#default_value'] = $member_profile->field_private_phone['und'][0]["number"];
  260. }
  261. function materio_user_webform_client_11186_validate($form, &$form_state){
  262. // dsm($form, 'form');
  263. // dsm($form_state, 'form_state');
  264. # test if collaborators are filled in case of membership option is 3
  265. $values = $form_state['values']['submitted'];
  266. if ($values['column_left']['membership_options'] == 3) {
  267. foreach ($values['column_right']['collaborators'] as $collab_key => $coll) {
  268. foreach ($coll as $field_key => $field_value) {
  269. $form_field = $form['submitted']['column_right']['collaborators'][$collab_key][$field_key];
  270. if($field_value == ''){
  271. $collab_label = $form['submitted']['column_right']['collaborators'][$collab_key]['#title'];
  272. $field_label = $form_field['#title'];
  273. $human_field_name = $collab_label. " : " .$field_label;
  274. form_error($form_field, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
  275. }
  276. # validate the emails
  277. # see https://api.drupal.org/api/drupal/modules!user!user.module/function/user_account_form_validate/7
  278. if($form_field['#type'] == 'webform_email'){
  279. // dsm($form_field, 'form_field');
  280. $u = db_select('users')
  281. ->fields('users', array('uid'))
  282. // ->condition('uid', $account->uid, '<>')
  283. ->condition('mail', db_like($field_value), 'LIKE')
  284. ->range(0, 1)
  285. ->execute()->fetchField();
  286. if ((bool) $u ) {
  287. form_error($form_field, t('The e-mail address %email is already taken.', array('%email' => $field_value)));
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. #retreive from the web form info, record them into user profil
  295. function materio_user_webform_client_11186_submit(&$form, &$form_state){
  296. // dsm($form, 'form');
  297. // dsm($form_state, 'form_state');
  298. $node = &$form['#node'];
  299. // dsm($node, '$node');
  300. $values = $form_state['values']['submitted_tree'];
  301. // dsm($values, '$values');
  302. $flat_values = array();
  303. materio_user_flatenize_form_values($values, $flat_values);
  304. // dsm($flat_values, 'flat_values');
  305. # records values in member profile
  306. materio_user_record_member_profile($flat_values);
  307. # redirect membership form to checkout with good option selected
  308. if(user_access('access to online payment')){
  309. // forcer le vidage du panier
  310. uc_cart_empty(uc_cart_get_id());
  311. // fill the cart and redirect to checkout
  312. // cf : http://www.ubercart.org/node/1427
  313. $subscription_level = $flat_values['membership_options'];
  314. $form_state['redirect'] = array(
  315. 'cart/add/e-p11849_q1_a1o'.$subscription_level.'-membershipform',
  316. array(
  317. 'query' => array(
  318. 'destination' => 'cart/checkout',
  319. ),
  320. // 'fragment' => 'baz',
  321. ),
  322. );
  323. // TODO effacer le message de soumissions du formulaire -> pas moyen de overwriter le message de webform depuis ici, dommage
  324. // $node->webform['confirmation'] = '';
  325. # create collaborators users account incase of membership option is 3
  326. # NO wait for checkout for that
  327. //materio_user_create_collaborators_users();
  328. // enregistrer le type d'adonnement chez les user
  329. }
  330. }
  331. function materio_user_record_member_profile($values) {
  332. // dsm($values, 'values');
  333. global $user;
  334. // dsm($user, 'user');
  335. $member_profile = profile2_load_by_user($user, 'adherent');
  336. if (empty($member_profile)) {
  337. $member_profile = profile2_create(array("type" => 'adherent', "uid" => $user->uid));
  338. }
  339. // dsm($member_profile, '$member_profile');
  340. $correspondances = array(
  341. "firstname"=>"field_first_name",
  342. "name"=>"field_name",
  343. "company"=>"field_organization",
  344. "activity_sector"=>"field_activity_sector",
  345. "website"=>"field_user_website",
  346. "administrative_e_mail"=>"field_administrative_email",
  347. "vat_number_intra_ce"=>"field_vat_number_intra_ce",
  348. "location"=>"field_adresse",
  349. "phone_number"=>"field_private_phone",
  350. );
  351. foreach ($correspondances as $form_field => $field_name) {
  352. switch($form_field){
  353. case "website":
  354. $value = array("url" => $values[$form_field]);
  355. break;
  356. case "administrative_e_mail":
  357. $value = array("email" => $values[$form_field]);
  358. break;
  359. case "location":
  360. $value = unserialize($values[$form_field]);
  361. // dsm($value, 'location value');
  362. break;
  363. case "phone_number":
  364. $pn = $values[$form_field];
  365. if(module_exists('cck_phone')){
  366. preg_match('/^(\+[0-9]+)\s([0-9]+)$/', $pn, $matches);
  367. // dsm($matches, "matches");
  368. $ccs = cck_phone_countrycodes();
  369. foreach ($ccs as $c => $vs) {
  370. if($vs['code'] == $matches[1]){
  371. $pn = "0".$matches[2];
  372. $cc = $c;
  373. break;
  374. }
  375. }
  376. $value = array(
  377. "number"=>$pn,
  378. "country_codes"=>$cc,
  379. "extension"=>"",
  380. );
  381. }else{
  382. $value = array(
  383. "number"=>$pn,
  384. "country_codes"=>"",
  385. "extension"=>"",
  386. );
  387. }
  388. break;
  389. default:
  390. $value = array("value" => $values[$form_field]);
  391. break;
  392. }
  393. $member_profile->{$field_name} = array(
  394. "und"=>array( 0 => $value,)
  395. );
  396. }
  397. // save the profile2 new contents
  398. profile2_save($member_profile);
  399. // Indicate success to the user.
  400. // drupal_set_message(t('Your member profile has been created.'));
  401. }
  402. function materio_user_flatenize_form_values($ar_src, &$flat_ar){
  403. foreach ($ar_src as $key => $value) {
  404. if(is_array($value)){
  405. materio_user_flatenize_form_values($value, $flat_ar);
  406. }else{
  407. $flat_ar[$key] = $value;
  408. }
  409. }
  410. }
  411. /**
  412. * Implements hook_form_alter().
  413. */
  414. function materio_user_uc_cart_checkout_form_alter(&$form, &$form_state, $form_id) {
  415. // dsm($form_id, 'form_id');
  416. // dsm($form, "form");
  417. // dsm($form_state, "form_state");
  418. // Load an order from the session, if available.
  419. if (isset($_SESSION['cart_order'])) {
  420. $order = uc_order_load($_SESSION['cart_order']);
  421. if ($order) {
  422. // dsm($order, 'order');
  423. global $user;
  424. // dsm($user, 'user');
  425. $member_profile = profile2_load_by_user($user, 'adherent');
  426. // dsm($member_profile, "member_profile");
  427. $location = (object) $member_profile->field_adresse['und'][0];
  428. # convert country code to UC country ID (pfff)
  429. $countries = db_query("SELECT country_id, country_iso_code_2 FROM {uc_countries} WHERE version > :version", array(':version' => 0))->fetchAllKeyed();
  430. foreach ($countries as $country_id => $country_code) {
  431. if($location->country == $country_code){
  432. $location->uc_country_id = $country_id;
  433. break;
  434. }
  435. }
  436. // dsm($location, "location");
  437. // $phone_field = field_get_items('profile2', $member_profile, 'field_private_phone');
  438. // $phone = $phone_field ? field_view_value('profile2', $member_profile, 'field_private_phone', $phone_field[0]) : "";
  439. // dsm($phone, 'phone');
  440. $phone_field = $member_profile->field_private_phone['und'][0];
  441. if(module_exists('cck_phone')){
  442. $cc = cck_phone_countrycodes($phone_field['country_codes']);
  443. $phone = $cc['code'] .' '. $phone_field['number'];
  444. }
  445. $correspondances = array(
  446. "billing_first_name" => $member_profile->field_first_name['und'][0]['value'],
  447. "billing_last_name" => $member_profile->field_name['und'][0]['value'],
  448. "billing_phone" => $phone,
  449. "billing_company" => $member_profile->field_organization['und'][0]['value'],
  450. "billing_street1" => $location->thoroughfare,
  451. "billing_street2" => $location->premise,
  452. "billing_city" => $location->locality,
  453. // "billing_zone" => ,
  454. "billing_postal_code" => $location->postal_code,
  455. "billing_country" => $location->uc_country_id,
  456. );
  457. foreach ($correspondances as $order_field => $value) {
  458. $order->{$order_field} = $value;
  459. }
  460. $form['panes']['billing']['address']['#default_value'] = $order;
  461. }
  462. }
  463. }
  464. /**
  465. * Implements hook_uc_order();
  466. */
  467. function materio_user_order($op, $order, $arg2) {
  468. // dsm($op, "matyerio_user_uc_order | op");
  469. // dsm($order, "order");
  470. // dsm($arg2, "arg2");
  471. switch ($op) {
  472. case 'save':
  473. // Do something to save payment info!
  474. break;
  475. }
  476. }
  477. # not used yet
  478. function materio_user_create_collaborators_users(){
  479. /*
  480. if ($values['membership_options'] == 3) {
  481. $i = 1;
  482. foreach ($values['collaborators'] as $collab_key => $coll) {
  483. // foreach ($coll as $field_key => $field_value) {
  484. // if($field_value == ''){
  485. // $human_field_name = $form['submitted']['collaborators'][$coll_key]['#title'] . " : " . $form['submitted']['collaborators'][$coll_key][$field_key]['#title'];
  486. // $field_name = 'submitted][collaborators]['.$coll_key.']['.$field_key;
  487. // // dsm($field_name, 'field_name');
  488. // form_set_error($field_name, t('You must provide a value for the !name field.', array('!name'=>$human_field_name)));
  489. // }
  490. // }
  491. $userinfo = array(
  492. 'mail' => $coll['e_mail_collab_'.$i],
  493. 'name' => user_password(),
  494. 'pass' => user_password(), // Generate password
  495. // 'init' => $data['components']['username']['value'],
  496. 'status' => 0,
  497. 'access' => REQUEST_TIME,
  498. 'memo' => 'from webform',
  499. );
  500. $account = drupal_anonymous_user();
  501. $account->is_new = TRUE;
  502. user_save($account, $userinfo);
  503. // module_invoke_all('user_insert', $edit, $account);
  504. $i++;
  505. }
  506. }
  507. */
  508. }
  509. /**
  510. * Implements hook_help().
  511. */
  512. function materio_user_help($path, $arg) {
  513. // dsm($path, 'path');
  514. // dsm($arg, 'arg');
  515. switch ($path) {
  516. case 'node/%':
  517. if($arg[1] == 11187 ){
  518. global $user;
  519. // dsm($user, 'user');
  520. if(isset($user->roles[1])){ // anonyme
  521. $message = t('Please create first a free account and join materio or log in with your existing account,<br />then we\'ll provide you our membership form.', array());
  522. $content = '<p>' . $message . '</p>';
  523. return $content;
  524. }else if(isset($user->roles[2])){ // authentificated user (not utilisateur)
  525. $content = '<h2>' . t('Welcome, you just joined materiO\' !') . '</h2>';
  526. $frontlink = l(t('continue with basic'), '<front>');
  527. $message = t('Now you can choose the membership that\'s right for you, or !link', array('!link'=>$frontlink));
  528. $content .= '<p>' . $message . '</p>';
  529. return $content;
  530. }
  531. }
  532. }
  533. }
  534. /**
  535. * Implements hook_block_view_alter().
  536. */
  537. function materio_user_block_view_alter(&$data, $block) {
  538. if( $block->module == "user" && $block->delta == 'login' && isset($data['subject']) ){
  539. // dsm($block, 'block');
  540. // dsm($data, 'data');
  541. $data['subject'] = '<i class="icon-user"></i>' . '<span class="login">' . $data['subject'] . '</span>';
  542. }
  543. }
  544. /**
  545. * Define constants
  546. */
  547. define('MATERIO_USER_CONFIRMED_USER_ROLE', 'Utilisateur'); // add role name here
  548. /**
  549. * Implement hook_user
  550. */
  551. function _materio_user_user_update(&$edit, $account, $category){
  552. // dsm($edit, 'edit');
  553. // dsm($account, 'account');
  554. // dsm($category, 'category');
  555. // This is only fired when a user confirms their email address, logintoboggan style
  556. if (isset($account->logintoboggan_email_validated) && $account->logintoboggan_email_validated == TRUE) {
  557. $confirmed_rid = materio_user_get_role_by_name(MATERIO_USER_CONFIRMED_USER_ROLE);
  558. $roles = $account->roles + array($confirmed_rid => MATERIO_USER_CONFIRMED_USER_ROLE);
  559. // we have to do this to stop an infinite loop, and also to allow lower weighted modules to possibly do something here
  560. $user = $account;
  561. unset($user->logintoboggan_email_validated);
  562. user_save($user, array('roles' => $roles));
  563. drupal_go_to('user/'.$user->uid.'/edit');
  564. }
  565. }
  566. /**
  567. * Returns a role ID based on role name
  568. *
  569. * @param $name
  570. * name of role to return
  571. * @return
  572. * (int) Role ID
  573. */
  574. function materio_user_get_role_by_name($name) {
  575. return array_search($name, user_roles());
  576. }
  577. /**
  578. * Catch rejected email by mandrill, and remove them from simplenews lists
  579. *
  580. * @param array $result
  581. * Associative array containing the send result, including the status.
  582. */
  583. function materio_user_mandrill_mailsend_result($result) {
  584. $status = $result['status'];
  585. if ( in_array($status, array('rejected', 'invalid', 'error')) ) {
  586. $email = $result['email'];
  587. // remove email from pool
  588. module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
  589. simplenews_delete_spool(array('mail'=>$email));
  590. watchdog("materio_user", "@mail rejected by mandrill, removed from simplenews spool", array("@mail"=>$email));
  591. if ( in_array($status, array('invalid')) ) {
  592. // unsubscribe user if mail does not exists
  593. $subscriber = simplenews_subscriber_load_by_mail($email);
  594. if ($subscriber) {
  595. simplenews_subscriber_delete($subscriber);
  596. }
  597. // disable user
  598. $user = user_load_by_mail($email);
  599. // $user->status = 0;
  600. user_save($user, array('status'=>0));
  601. watchdog("materio_user", "@mail rejected as invalid by mandrill, removed from simplenews subscribers liste and user blocked", array("@mail"=>$email), WATCHDOG_WARNING, "/user/".$user->uid."/edit");
  602. }
  603. }
  604. }