Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. <?php
  2.  
  3. // $Id$
  4. /**
  5. * @file
  6. * Caching In Drupal 6.
  7. */
  8.  
  9. /**
  10. * Implementation of hook_menu().
  11. */
  12. function cacher_menu()
  13. {
  14. $items['cacher'] = array(
  15. 'title' => 'Caching Drupal 6',
  16. 'page callback' => 'drupal_get_form',
  17. 'page arguments' => array('cacher_settings_page'),
  18. 'access arguments' => array('access content'),
  19. 'description' => 'My Form',
  20. 'type' => MENU_NORMAL_ITEM
  21. );
  22. $items['cacher/already_set'] = array(
  23. 'title' => 'Cache Set',
  24. 'page callback' => 'cache_user_page',
  25. 'type' => MENU_CALLBACK,
  26. 'access arguments' => array('access_content')
  27. );
  28. return $items;
  29. }
  30. function cacher_settings_page(&$form_state = NULL)
  31. {
  32. $form = array();
  33. $form['#validate'][] = 'cacher_settings_page_validate';
  34. $form['info'] = array(
  35. '#type' => 'fieldset',
  36. '#title' => 'Basic Information',
  37. );
  38. $form['info']['username'] = array(
  39. '#type' => 'textfield',
  40. '#size' => '30',
  41. '#title' => 'Username',
  42. '#description' => 'Enter Your Username'
  43. );
  44. $form['info']['password'] = array(
  45. '#type' => 'password',
  46. '#size' => '30',
  47. '#title' => 'Password',
  48. '#description' => 'Please Enter your password'
  49. );
  50. $form['cache_info'] = array(
  51. '#type' => 'fieldset',
  52. '#title' => 'Caching Information',
  53. );
  54. $form['cache_info']['time'] = array(
  55. '#type' => 'textfield',
  56. '#size' => '30',
  57. '#title' => 'Time',
  58. '#description' => 'How Long would you like to be logged in for (Seconds)'
  59. );
  60. $form['submit'] = array(
  61. '#type' => 'submit',
  62. '#value' => 'Login'
  63. );
  64.  
  65. return $form;
  66. }
  67. function cacher_settings_page_validate(&$form, &$form_state)
  68. {
  69. dsm($form_state);
  70. $ttl = $form_state['values']['time'];
  71. $username = $form_state['values']['username'];
  72. $password = $form_state['values']['password'];
  73. if(!empty($username) && !empty($password))
  74. {
  75. $my_data = array(
  76. 'username' => $username,
  77. 'password' => $password
  78. );
  79. }
  80. else
  81. form_set_error($form_state['values']['username'], t('Please enter both your username and password'));
  82. if(!empty($ttl) && is_numeric($ttl))
  83. {
  84. cache_set('cacher_data', $my_data, 'cache', time() + $ttl);
  85. $form_state['data_set'] = TRUE;
  86. }
  87. else
  88. form_set_error($form_state['values']['time'], t('Please set time you would like to be loged in for(numeric value)'));
  89.  
  90. }
  91. function cache_user_page()
  92. {
  93. $output;
  94. $my_data = cache_get('cacher_data');
  95. dsm($my_data);
  96. $expire = time() - $my_data->expire;
  97. $data = $my_data->data;
  98. dsm($data);
  99. if($expire < 0)
  100. {
  101. $output .= "<p>Successfully Logged In</p>";
  102. $t = $expire*(-1);
  103. $output .= "<p>You will be logged out in {$t} Seconds.</p>";
  104. $output .= "<p>Your username is: {$data['username']} and your password is: {$data['password']}</p>";
  105. }
  106. else
  107. {
  108. $output .= "<p>Your Cache has expired $expire Seconds ago</p>";
  109. $output .= "<p>You have been logged out</p>";
  110. }
  111.  
  112. $output .= "<br /><br /><p>Refresh this page to see your caching disappear</p>";
  113. return $output;
  114. }
  115. function cacher_settings_page_submit($form, &$form_state)
  116. {
  117. $form_state['redirect'] = 'cacher/already_set';
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement