/[drupal]/contributions/modules/demo/demo.module
ViewVC logotype

Contents of /contributions/modules/demo/demo.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.35 - (show annotations) (download) (as text)
Wed Sep 30 16:56:59 2009 UTC (8 weeks ago) by sun
Branch: MAIN
Changes since 1.34: +8 -3 lines
File MIME type: text/x-php
by sun: Updated for new File API, Database API, Form API, and removed registry.
1 <?php
2 // $Id: demo.module,v 1.34 2009/07/29 14:07:33 sun Exp $
3
4 /**
5 * @file
6 * Demonstration Site module
7 */
8
9 /**
10 * Implementation of hook_perm().
11 */
12 function demo_permission() {
13 return array(
14 'administer demo settings' => array(
15 'title' => t('Administer demonstration site settings'),
16 'description' => t('Administer reset interval, create new dumps and manually reset this site.'),
17 ),
18 );
19 }
20
21 /**
22 * Implementation of hook_menu().
23 */
24 function demo_menu() {
25 $admin_access = array('administer demo settings');
26
27 $items['admin/structure/demo'] = array(
28 'title' => 'Demonstration site',
29 'description' => 'Administer reset interval, create new dumps and manually reset this site.',
30 'page callback' => 'drupal_get_form',
31 'page arguments' => array('demo_admin_settings'),
32 'access arguments' => $admin_access,
33 'file' => 'demo.admin.inc',
34 );
35 $items['admin/structure/demo/maintenance'] = array(
36 'title' => 'Status',
37 'type' => MENU_DEFAULT_LOCAL_TASK,
38 'weight' => 0,
39 );
40 $items['admin/structure/demo/manage'] = array(
41 'title' => 'Manage snapshots',
42 'page callback' => 'drupal_get_form',
43 'page arguments' => array('demo_manage'),
44 'access arguments' => $admin_access,
45 'file' => 'demo.admin.inc',
46 'type' => MENU_LOCAL_TASK,
47 'weight' => 1,
48 );
49 $items['admin/structure/demo/dump'] = array(
50 'title' => 'Create snapshot',
51 'page callback' => 'drupal_get_form',
52 'page arguments' => array('demo_dump'),
53 'access arguments' => $admin_access,
54 'file' => 'demo.admin.inc',
55 'type' => MENU_LOCAL_TASK,
56 'weight' => 2,
57 );
58 $items['admin/structure/demo/reset'] = array(
59 'title' => 'Reset site',
60 'page callback' => 'drupal_get_form',
61 'page arguments' => array('demo_reset_confirm'),
62 'access arguments' => $admin_access,
63 'file' => 'demo.admin.inc',
64 'type' => MENU_LOCAL_TASK,
65 'weight' => 3,
66 );
67 $items['admin/structure/demo/delete/%'] = array(
68 'title' => 'Delete snapshot',
69 'page callback' => 'drupal_get_form',
70 'page arguments' => array('demo_delete_confirm', 4),
71 'access arguments' => $admin_access,
72 'file' => 'demo.admin.inc',
73 'type' => MENU_CALLBACK,
74 );
75 $items['demo/autocomplete'] = array(
76 'page callback' => 'demo_autocomplete',
77 'access arguments' => $admin_access,
78 'file' => 'demo.admin.inc',
79 'type' => MENU_CALLBACK,
80 );
81 $items['demo/download'] = array(
82 'page callback' => 'demo_download',
83 'access arguments' => $admin_access,
84 'file' => 'demo.admin.inc',
85 'type' => MENU_CALLBACK,
86 );
87 return $items;
88 }
89
90 /**
91 * Implementation of hook_block_list().
92 */
93 function demo_block_list() {
94 $blocks[0] = array('info' => t('Demo site reset'),
95 'status' => 1, 'region' => 'right', 'cache' => BLOCK_NO_CACHE,
96 );
97 return $blocks;
98 }
99
100 /**
101 * Implementation of hook_block_view().
102 */
103 function demo_block_view($delta = '') {
104 $block = array(
105 'subject' => t('Reset demo'),
106 'content' => drupal_get_form('demo_reset_now'),
107 );
108 return $block;
109 }
110
111 function demo_reset_now($form, &$form_state) {
112 $form['redirect'] = array(
113 '#type' => 'value',
114 '#value' => $_GET['q'],
115 );
116 $form['filename'] = array(
117 '#type' => 'value',
118 '#value' => variable_get('demo_dump_cron', 'demo_site'),
119 );
120 $form['snapshot'] = array(
121 '#value' => t('Active snapshot: !snapshot', array('!snapshot' => variable_get('demo_dump_cron', 'demo_site'))),
122 );
123 $form['reset-demo'] = array(
124 '#type' => 'submit',
125 '#value' => t('Reset now'),
126 );
127 return $form;
128 }
129
130 function demo_reset_now_submit($form, &$form_state) {
131 module_load_include('inc', 'demo', 'demo.admin');
132 demo_reset_confirm_submit($form, $form_state);
133 }
134
135 /**
136 * Implementation of hook_cron().
137 */
138 function demo_cron() {
139 if ($interval = variable_get('demo_reset_interval', 0)) {
140 // See if it's time for a reset.
141 if ((REQUEST_TIME - $interval) >= variable_get('demo_reset_last', 0)) {
142 module_load_include('inc', 'demo', 'demo.admin');
143 demo_reset(variable_get('demo_dump_cron', 'demo_site'), FALSE);
144 variable_set('demo_reset_last', REQUEST_TIME);
145 }
146 }
147 }
148

  ViewVC Help
Powered by ViewVC 1.1.2