Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // $Id$
- /**
- * @file
- * Caching In Drupal 6.
- */
- /**
- * Implementation of hook_menu().
- */
- function cacher_menu()
- {
- $items['cacher'] = array(
- 'title' => 'Caching Drupal 6',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('cacher_settings_page'),
- 'access arguments' => array('access content'),
- 'description' => 'My Form',
- 'type' => MENU_NORMAL_ITEM
- );
- $items['cacher/already_set'] = array(
- 'title' => 'Cache Set',
- 'page callback' => 'cache_user_page',
- 'type' => MENU_CALLBACK,
- 'access arguments' => array('access_content')
- );
- return $items;
- }
- function cacher_settings_page(&$form_state = NULL)
- {
- $form = array();
- $form['#validate'][] = 'cacher_settings_page_validate';
- $form['info'] = array(
- '#type' => 'fieldset',
- '#title' => 'Basic Information',
- );
- $form['info']['username'] = array(
- '#type' => 'textfield',
- '#size' => '30',
- '#title' => 'Username',
- '#description' => 'Enter Your Username'
- );
- $form['info']['password'] = array(
- '#type' => 'password',
- '#size' => '30',
- '#title' => 'Password',
- '#description' => 'Please Enter your password'
- );
- $form['cache_info'] = array(
- '#type' => 'fieldset',
- '#title' => 'Caching Information',
- );
- $form['cache_info']['time'] = array(
- '#type' => 'textfield',
- '#size' => '30',
- '#title' => 'Time',
- '#description' => 'How Long would you like to be logged in for (Seconds)'
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => 'Login'
- );
- return $form;
- }
- function cacher_settings_page_validate(&$form, &$form_state)
- {
- dsm($form_state);
- $ttl = $form_state['values']['time'];
- $username = $form_state['values']['username'];
- $password = $form_state['values']['password'];
- if(!empty($username) && !empty($password))
- {
- $my_data = array(
- 'username' => $username,
- 'password' => $password
- );
- }
- else
- form_set_error($form_state['values']['username'], t('Please enter both your username and password'));
- if(!empty($ttl) && is_numeric($ttl))
- {
- cache_set('cacher_data', $my_data, 'cache', time() + $ttl);
- $form_state['data_set'] = TRUE;
- }
- else
- form_set_error($form_state['values']['time'], t('Please set time you would like to be loged in for(numeric value)'));
- }
- function cache_user_page()
- {
- $output;
- $my_data = cache_get('cacher_data');
- dsm($my_data);
- $expire = time() - $my_data->expire;
- $data = $my_data->data;
- dsm($data);
- if($expire < 0)
- {
- $output .= "<p>Successfully Logged In</p>";
- $t = $expire*(-1);
- $output .= "<p>You will be logged out in {$t} Seconds.</p>";
- $output .= "<p>Your username is: {$data['username']} and your password is: {$data['password']}</p>";
- }
- else
- {
- $output .= "<p>Your Cache has expired $expire Seconds ago</p>";
- $output .= "<p>You have been logged out</p>";
- }
- $output .= "<br /><br /><p>Refresh this page to see your caching disappear</p>";
- return $output;
- }
- function cacher_settings_page_submit($form, &$form_state)
- {
- $form_state['redirect'] = 'cacher/already_set';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement