/[drupal]/contributions/modules/custom_pagers/custom_pagers.admin.inc
ViewVC logotype

Contents of /contributions/modules/custom_pagers/custom_pagers.admin.inc

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Jun 17 20:47:05 2008 UTC (17 months, 1 week ago) by eaton
Branch: MAIN
CVS Tags: DRUPAL-6--1-10-BETA1, HEAD
Branch point for: DRUPAL-6--1, DRUPAL-6--2
File MIME type: text/x-php
Initial port to Drupal 6. Views handling code will need to be made more efficient, but it works for now.
1 <?php
2 // $Id$
3
4 // Lists all current custom pagers, and provides a link to the edit page.
5 function custom_pagers_page() {
6 $pagers = _custom_pagers_load_all_pagers(TRUE);
7
8 $header = array(t('Title'), t('Node list'), t('Visibility'), '');
9
10 $rows = array();
11 foreach ($pagers as $pager) {
12 $row = array();
13 $row[] = $pager->title;
14 $row[] = !empty($pager->list_php) ? t('PHP snippet') : $pager->view . t(' view');
15 $row[] = !empty($pager->visibility_php) ? t('PHP snippet') : $pager->node_type . t(' nodes');
16 $row[] = l(t('edit'), 'admin/build/custom_pagers/edit/' . $pager->pid);
17 $rows[] = $row;
18 }
19 if (count($rows) == 0) {
20 $rows[] = array(array('data' => t('No custom pagers have been defined.'), 'colspan' => 3));
21 }
22
23 $rows[] = array(array('data' => l(t('Add a new custom pager'), 'admin/build/custom_pagers/add'), 'colspan' => 2));
24
25
26 return theme('table', $header, $rows);
27 }
28
29
30 // Displays an edit form for a custom pager record.
31 function custom_pagers_form(&$form_state, $pid = NULL) {
32 if (isset($pid) && $pager = _custom_pagers_load_pager($pid)) {
33 $form['pid'] = array(
34 '#type' => 'hidden',
35 '#value' => $pid,
36 );
37 }
38
39 $form['title'] = array(
40 '#type' => 'textfield',
41 '#title' => t('Title'),
42 '#required' => TRUE,
43 '#default_value' => $pid ? $pager->title : '',
44 );
45
46
47 $form['position'] = array(
48 '#type' => 'select',
49 '#title' => t('Pager position'),
50 '#required' => TRUE,
51 '#options' => array(
52 'top' => t("Above the node's body"),
53 'bottom' => t("Below the node's body"),
54 'both' => t("Both above and below the node's body"),
55 'block' => t("In a sidebar block"),
56 ),
57 '#description' => t('The node type(s) this custom pager will apply to.'),
58 '#default_value' => $pid ? $pager->position : NULL,
59 );
60
61 $form['visibility'] = array(
62 '#type' => 'fieldset',
63 '#collapsible' => FALSE,
64 '#collapsed' => FALSE,
65 '#title' => t('Pager visibility'),
66 '#description' => t('Determine what nodes this pager should be displayed on.'),
67 );
68
69 // Warn the user they're about to override custom code.
70 if ((!empty($pager->visibility_php)) && !user_access('use php in custom pagers')){
71 $form['visibility']['php'] = array(
72 '#type' => 'item',
73 '#title' => t('Note'),
74 '#value' => t('This pager uses custom PHP snippets to control visibility. You do not have permission to use PHP snippets, and the changes you make to this field will be ignored.'),
75 );
76 }
77 $form['visibility']['node_type'] = array(
78 '#type' => 'select',
79 '#title' => t('By node type'),
80 '#required' => TRUE,
81 '#multiple' => TRUE,
82 '#options' => node_get_types('names'),
83 '#description' => t('If the PHP field is filled in, this field will be ignored.'),
84 '#default_value' => $pid ? explode(',', $pager->node_type) : NULL,
85 );
86
87 $form['visibility']['visibility_php'] = array(
88 '#type' => 'textarea',
89 '#title' => t('By PHP snippet'),
90 '#access' => user_access('use php in custom pagers'),
91 '#description' => t('Use a snippet of PHP to return TRUE or FALSE. Note that this code has access to the $node variable, and can check its type or any other property. If this field is filled out, the <em>By node type</em> field will be ignored.'),
92 '#default_value' => $pid ? $pager->visibility_php : '',
93 );
94
95 $form['node_list'] = array(
96 '#type' => 'fieldset',
97 '#collapsible' => FALSE,
98 '#collapsed' => FALSE,
99 '#title' => t('Pager node list'),
100 '#description' => t('Determine how the list of nodes for this pager should be generated.'),
101 );
102
103 // Warn the user they're about to override custom code, or if Views
104 // is missing and PHP permissions haven't been granted.
105 if (!user_access('use php in custom pagers')) {
106 if (!empty($pager->list_php)) {
107 $form['node_list']['note'] = array(
108 '#type' => 'item',
109 '#title' => t('Note'),
110 '#value' => t('This pager uses custom PHP snippets to generate a list of nodes. You do not have permission to use PHP snippets, and the changes you make to this field will be ignored.'),
111 );
112 }
113 elseif (!module_exists('views')){
114 $form['node_list']['warning'] = array(
115 '#type' => 'item',
116 '#title' => t('Warning'),
117 '#value' => t('The Views module is not installed, and you do not have permission to use PHP snippets to configure the node. You can save this custom pager, but it will not appear until the node list is properly configured.'),
118 );
119 }
120 }
121
122 $form['node_list']['list_php'] = array(
123 '#type' => 'textarea',
124 '#title' => t('Use PHP snippet'),
125 '#access' => user_access('use php in custom pagers'),
126 '#default_value' => $pid ? $pager->list_php : '',
127 '#description' => t('Use a snippet of PHP to populate the pager. The snippet should return an array of node ids in the order they should be browsed. If this field is filled out, the <em>Use a view</em> and <em>View arguments</em> fields will be ignored.'),
128 );
129
130 if (module_exists('views')) {
131 $options = array();
132
133 $all_views = views_get_all_views();
134 foreach ($all_views as $view) {
135 // Only views that have fields will work for our purpose.
136 if (!empty($view->display['default']->display_options['fields']) && $view->base_table == 'node') {
137 $options[$view->name] = $view->name;
138 }
139 }
140
141 $form['node_list']['view'] = array(
142 '#type' => 'select',
143 '#title' => t('Use a view'),
144 '#required' => TRUE,
145 '#options' => $options,
146 '#description' => t('A view used to populate the pager. The nodes will appear in the pager in the same order they are displayed in the view. If the PHP field is populated, this will be ignored.'),
147 '#default_value' => $pid ? $pager->view : NULL
148 );
149
150 $form['node_list']['args'] = array(
151 '#type' => 'textarea',
152 '#title' => t('View arguments'),
153 '#required' => FALSE,
154 '#description' => t('A return-delimited list of arguments to pass into the selected view. If Token.module is enabled, placeholder tokens like [type] and [author] can be used.'),
155 '#default_value' => $pid ? $pager->args : NULL
156 );
157
158 $form['help'] = array(
159 '#type' => 'fieldset',
160 '#collapsible' => TRUE,
161 '#collapsed' => TRUE,
162 '#title' => t('Placeholder tokens'),
163 '#description' => t("The following placeholder tokens can be used when passing arguments into the view. Each will be replaced with the correct values at runtime."),
164 );
165
166 if (module_exists('token')) {
167 $form['help']['tokens'] = array(
168 '#value' => theme('token_help', 'node'),
169 );
170 }
171 else {
172 $form['help']['#description'] = t("To use dynamic placeholder tokens in your pager arguments (the ID of the current node or currently logged in user, for example), download and install the <a href='@token'>Token module</a> from Drupal.org.", array('@token' => 'http://www.drupal.org/project/token'));
173 $form['help']['#collapsible'] = FALSE;
174 $form['help']['#collapsed'] = FALSE;
175 }
176 }
177
178 $form['node_list']['reverse_list'] = array(
179 '#type' => 'checkbox',
180 '#title' => t('Reverse the list of nodes'),
181 '#return_value' => 1,
182 '#description' => t("The natural list view ordering for an archive is the opposite of the natural 'previous/next' order for a pager. As such, reversing the pager list is useful when using a single view for paging and other sorted lists (pages, blocks, etc)."),
183 '#default_value' => $pid ? $pager->reverse_list : NULL
184 );
185
186 $form['node_list']['cache_list'] = array(
187 '#type' => 'checkbox',
188 '#title' => t('Cache the list of nodes'),
189 '#return_value' => 1,
190 '#default_value' => $pid ? $pager->cache_list : NULL
191 );
192
193 $form['buttons']['submit'] = array(
194 '#type' => 'submit',
195 '#value' => t('Submit'),
196 );
197 if ($pid) {
198 $form['buttons']['delete'] = array(
199 '#type' => 'submit',
200 '#value' => t('Delete'),
201 );
202 }
203
204 return $form;
205 }
206
207 function custom_pagers_form_submit(&$form, &$form_state) {
208 if ($form_state['values']['op'] == t('Delete')) {
209 _custom_pagers_delete_pager($form_state['values']['pid']);
210 }
211 else {
212 $pager = (object)$form_state['values'];
213 $pager->node_type = implode(',', $pager->node_type);
214 _custom_pagers_save_pager($pager);
215 }
216 $form_state['redirect'] = 'admin/build/custom_pagers';
217 }

  ViewVC Help
Powered by ViewVC 1.1.2