/[drupal]/contributions/sandbox/alaa/zkatib.module
ViewVC logotype

Contents of /contributions/sandbox/alaa/zkatib.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Oct 20 17:14:10 2006 UTC (3 years, 1 month ago) by alaa
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-php
initial commit
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * TODO: Enter file description here.
7 */
8
9
10 /**
11 * Implementation of hook_form_alter().
12 */
13 function zkatib_form_alter($form_id, &$form) {
14 global $user;
15 //if ($user->uid == 1) return;
16
17 //modify all node forms
18 if (strpos($form_id, "_node_form") !== false) {
19 //remove moderate and revisions
20 unset($form['options']['moderate']);
21 unset($form['options']['revision']);
22
23 //author field not needed in single author blogs
24 $form['author']['name']['#type']='hidden';
25
26
27 //convert published to draft radio buttons
28 $form['options']['#collapsed'] = false;
29 $form['options']['status']['#type'] = 'radios';
30 $form['options']['status']['#options'] = array(1 => t('published'), 0 => t('draft'));
31 $form['options']['status']['#title'] = '';
32
33 //only static pages get to be in menus
34 if ($form_id != "page_node_form") {
35 unset($form['menu']);
36 }
37
38 //implement multilingual comma
39 $form['#submit'] = array('zkatib_node_presubmit' => array())+$form['#submit'];
40 }
41
42
43 switch ($form_id) {
44 case "story_node_form":
45 //disable default taxonomy
46 //should be a look
47 $path = drupal_get_path_alias($_GET['q']);
48 if ($path == 'node/add/story') {
49 unset($form['taxonomy'][4]["#default_value"]);
50 }
51 break;
52
53 case "page_node_form":
54 //static pages don't appear on frant page, and don't have comments
55 unset($form['comment_settings']);
56 unset($form['options']['promote']);
57 unset($form['options']['sticky']);
58 break;
59
60 case "event_node_form":
61 //body field too small by default
62 // maybe it should be done by css?
63 $form['body_filter']['body']['#rows']=15;
64 break;
65
66 case "system_themes":
67 // special function to make sure only a single block config exists
68 // potential race condition
69 $form['#submit']['zkatib_system_themes_presubmit'] = array();
70
71 // only default theme is ever enabled
72 $form['status']['#default_value']=array();
73
74 // theme path as description is not useful remove it
75 $themes = element_children($form);
76 foreach ($themes as $theme) {
77 $form[$theme]['operations']=array();
78 unset($form[$theme]['description']['#value']);
79 }
80 break;
81 case "block_admin_configure":
82 $form['user_vis_settings']['#type']='hidden';
83 break;
84 default:
85 //echo "\n\n\n$form_id\n\n\n";
86 //var_dump($form);
87 }
88 }
89
90
91 /**
92 * Implementation of hook_help().
93 */
94 function zkatib_help($section) {
95 switch ($section) {
96 case 'admin/modules#description':
97 return t('altered forms and overrides for katib.org');
98 // OPTIONAL: Add additional cases for other paths that should display help text.
99 }
100 }
101
102
103
104 //add support to arabic comma (does not recognise quotes)
105 function zkatib_node_presubmit($form_id, $form_values) {
106 if ($form_values['taxonomy']['tags']) {
107 foreach ($form_values['taxonomy']['tags'] as $vid => $tags) {
108 $form_values['taxonomy']['tags'][$vid] = preg_replace('/\x{060C}/u',',',$tags);
109 }
110 }
111 }
112
113 //cleans up blocks table on theme change to make sure only one block
114 //configuration exists at any time
115 function zkatib_system_themes_presubmit($form_id, $form_data) {
116 $default_theme = variable_get('theme_default', 'box_grey-rtl');
117 if (db_result(db_query("SELECT COUNT(status) from {blocks} where theme = '%s'", $default_theme))) {
118 db_query("DELETE FROM {blocks} WHERE theme != '%s'", $default_theme);
119 }
120 }
121
122 //a simpler admin/theme design
123 // replace with something that doesn't use radio buttons at all
124 function phptemplate_system_themes($form) {
125 foreach (element_children($form) as $key) {
126 $row = array();
127 if (is_array($form[$key]['description'])) {
128 $row[] = form_render($form[$key]['description']).form_render($form[$key]['screenshot']);
129
130 form_render($form['status'][$key]);
131 if ($form['theme_default']) {
132 $row[] = array('data' => form_render($form['theme_default'][$key]), 'align' => 'center');
133 form_render($form[$key]['operations']);
134 }
135 }
136 $rows[] = $row;
137 }
138
139 form_render($form['buttons']['reset']);
140
141 $header = array(t('Screenshot'), t('Active'));
142 $output = theme('table', $header, $rows);
143 $output .= form_render($form);
144 return $output;
145 }
146
147 //adds an add image to gallery link
148 //maybe add a manage galleries link too?
149 function phptemplate_image_gallery($galleries, $images) {
150 drupal_set_html_head(theme('stylesheet_import', base_path() . drupal_get_path('module', 'image_gallery') .'/image_gallery.css'));
151 $size = _image_get_dimensions('thumbnail');
152 $width = $size['width'];
153 $height = $size['height'];
154 $content = '';
155 if (count($galleries)) {
156 global $user;
157 $content.= '<ul class="galleries">';
158 foreach ($galleries as $gallery) {
159 $content .= '<li>';
160 $content .= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
161 $content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
162 $content.= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
163 $content.= '<p class="count">' . format_plural($gallery->count, 'There is %count image in this gallery', 'There are %count images in this gallery') . "</p>\n";
164 if ($gallery->latest->changed) {
165 $content.= '<p class="last">'. t('Last updated: %date', array('%date' => format_date($gallery->latest->changed))) . "</p>\n";
166 }
167 if ($user->uid) {
168 $content.='<p class="add-image">'.l(t('add image to gallery'), 'node/add/image',array(),"edit[taxonomy][2]=$gallery->tid").'</p>';
169 }
170 $content.= "</li>\n";
171 }
172 $content.= "</ul>\n";
173 }
174 if (count($images)) {
175 $height += 5;
176 $content= '<ul class="images">';
177 foreach ($images as $image) {
178 $content .= '<li';
179 if ($image->sticky) {
180 $content .= ' class="sticky"';
181 }
182 $content .= ">\n";
183 $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
184 $content .= "</li>\n";
185 }
186 $content.= "</ul>\n";
187 }
188
189 if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
190 $content.= $pager;
191 }
192 If (count($images) + count($galleries) == 0) {
193 $content.= '<p class="count">' . format_plural(0, 'There is %count image in this gallery', 'There are %count images in this gallery') . "</p>\n";
194 }
195 return $content;
196 }
197
198
199 function zkatib_menu($may_cache) {
200 $items = array();
201 if ($may_cache) {
202 $items[] = array('path' => 'admin/zkatib/settings',
203 'title' => t('blog settings'),
204 'callback' => 'zkatib_blog_settings_page',
205 'access' => user_access('access administration pages'),
206 'type' => MENU_NORMAL_ITEM);
207 $items[] = array('path' => 'admin/zkatib/node',
208 'title' => t('posts'),
209 'callback' => 'zkatib_posts_settings_page',
210 'access' => user_access('access administration pages'),
211 'type' => MENU_NORMAL_ITEM);
212 }
213 return $items;
214 }
215
216
217 //content list (fron page, taxonomy page, rss feeds) rendering settings
218 function zkatib_posts_settings_page() {
219
220 $form['default_nodes_main'] = array(
221 '#type' => 'select', '#title' => t('Number of posts on main page'), '#default_value' => variable_get('default_nodes_main', 10),
222 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
223 '#description' => t('The default maximum number of posts to display per page on overview pages such as the main page.')
224 );
225
226 $form['teaser_length'] = array(
227 '#type' => 'select', '#title' => t('Length of trimmed posts'), '#default_value' => variable_get('teaser_length', 600),
228 '#options' => array(0 => t('Unlimited'), 200 => t('200 characters'), 400 => t('400 characters'), 600 => t('600 characters'),
229 800 => t('800 characters'), 1000 => t('1000 characters'), 1200 => t('1200 characters'), 1400 => t('1400 characters'),
230 1600 => t('1600 characters'), 1800 => t('1800 characters'), 2000 => t('2000 characters')),
231 '#description' => t("The maximum number of characters used in the trimmed version of a post. Drupal will use this setting to determine at which offset long posts should be trimmed. The trimmed version of a post is typically used as a teaser when displaying the post on the main page, in XML feeds, etc. To disable teasers, set to 'Unlimited'. Note that this setting will only affect new or updated content and will not affect existing teasers.")
232 );
233
234 // Feed settings
235 $form['feed'] = array('#type' => 'fieldset', '#title' => t('RSS feed settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
236 $form['feed']['feed_default_items'] = array(
237 '#type' => 'select', '#title' => t('Number of items per feed'), '#default_value' => variable_get('feed_default_items', 10),
238 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
239 '#description' => t('The default number of items to include in a feed.')
240 );
241 $form['feed']['feed_item_length'] = array(
242 '#type' => 'select', '#title' => t('Display of XML feed items'), '#default_value' => variable_get('feed_item_length','teaser'),
243 '#options' => array('title' => t('Titles only'), 'teaser' => t('Titles plus teaser'), 'fulltext' => t('Full text')),
244 '#description' => t('Global setting for the length of XML feed items that are output by default.')
245 );
246
247 $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
248 $form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') );
249
250 if (!empty($_POST) && form_get_errors()) {
251 drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
252 }
253
254 return drupal_get_form('zkatib_posts_settings', $form, 'system_settings_form');
255 }
256
257 //blogger doesn't have access to settings pages, this allows changing
258 //site name, slogan , footer, mission and that kind of stuff without
259 //messing with core configs
260 function zkatib_blog_settings_page() {
261 // General settings:
262 $form['general'] = array(
263 '#type' => 'fieldset', '#title' => t('General settings'),
264 '#collapsible' => TRUE, '#collapsed' => FALSE
265 );
266 $form['general']['site_name'] = array(
267 '#type' => 'textfield', '#title' => t('Name'), '#default_value' => variable_get('site_name', 'drupal'),
268 '#description' => t('The name of this web site.'), '#required' => TRUE
269 );
270 $form['general']['site_mail'] = array(
271 '#type' => 'textfield', '#title' => t('E-mail address'), '#default_value' => variable_get('site_mail', ini_get('sendmail_from')),
272 '#description' => t('A valid e-mail address for this website, used by the auto-mailer during registration, new password requests, notifications, etc.')
273 );
274 $form['general']['site_slogan'] = array(
275 '#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => variable_get('site_slogan', ''),
276 '#description' => t('The slogan of this website. Some themes display a slogan when available.')
277 );
278
279 $form['general']['site_mission'] = array(
280 '#type' => 'textarea', '#title' => t('Mission'), '#default_value' => variable_get('site_mission', ''),
281 '#description' => t('Your site\'s mission statement or focus.')
282 );
283 $form['general']['site_footer'] = array(
284 '#type' => 'textarea', '#title' => t('Footer message'), '#default_value' => variable_get('site_footer', ''),
285 '#description' => t('This text will be displayed at the bottom of each page. Useful for adding a copyright notice to your pages.')
286 );
287
288 // Date settings:
289 $zones = _system_zonelist();
290 $form['dates'] = array('#type' => 'fieldset', '#title' => t('Date settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
291 $form['dates']['date_default_timezone'] = array(
292 '#type' => 'select', '#title' => t('Default time zone'), '#default_value' => variable_get('date_default_timezone', 0),
293 '#options' => $zones, '#description' => t('Select the default site time zone.')
294 );
295
296 $form['dates']['date_first_day'] = array(
297 '#type' => 'select', '#title' => t('First day of week'), '#default_value' => variable_get('date_first_day', 0),
298 '#options' => array(0 => t('Sunday'), 1 => t('Monday'), 2 => t('Tuesday'), 3 => t('Wednesday'), 4 => t('Thursday'), 5 => t('Friday'), 6 => t('Saturday')),
299 '#description' => t('The first day of the week for calendar views.')
300 );
301
302 $form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') );
303
304 if (!empty($_POST) && form_get_errors()) {
305 drupal_set_message(t('The settings have not been saved because of the errors.'), 'error');
306 }
307
308 return drupal_get_form('zkatib_blog_settings', $form, 'system_settings_form');
309
310 }
311
312 /**
313 * Implementation of hook_block().
314 *
315 * Generates blocks for the latest news items in each category and feed.
316 */
317 function zkatib_block($op, $delta = 0, $edit = array()) {
318 if (user_access('access news feeds')) {
319 switch ($op) {
320 case 'list':
321 $block['zkatib-aggregator']['info'] = t('latest items from all feeds');
322 break;
323
324 case 'configure':
325 $value = variable_get('zkatib_aggregator_block', 5);
326 $form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
327 return $form;
328 case 'save':
329 variable_set('zkatib_aggregator_block', $edit['block']);
330 break;
331 case 'view':
332 $result = db_query_range('SELECT i.* from {aggregator_item} i ORDER BY i.timestamp DESC, i.iid DESC', 0 , variable_get('zkatib_aggregator_block',5));
333 $block['subject'] = t("latest feed items");
334 $items = array();
335 while ($item = db_fetch_object($result)) {
336 $items[] = theme('aggregator_block_item', $item);
337 }
338 $block['content'] = theme('item_list', $items);
339 $block['content'] .= '<div class="more-link">'.l(t('more'), 'aggregator', array('title' => t("View aggregator's recent news"))) .'</div>';
340 break;
341 }
342 }
343 return $block;
344 }

  ViewVC Help
Powered by ViewVC 1.1.2