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

Contents of /contributions/modules/wp_comments/wp_comments.module

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


Revision 1.2 - (show annotations) (download) (as text)
Tue May 6 06:57:05 2008 UTC (18 months, 3 weeks ago) by eaton
Branch: MAIN
CVS Tags: DRUPAL-6--1-0, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +2 -2 lines
File MIME type: text/x-php
Adding a screenshot, and fixing capitalization errors.
1 <?php
2 // $Id: wp_comments.module,v 1.1 2008/05/06 06:37:53 eaton Exp $
3
4 /**
5 * An implementation of hook_theme_registry_alter()
6 * Substitute our own custom version of the standard 'theme_form_element' function.
7 * If the theme has overridden it, we'll be bypassed, but in most cases this will
8 * work nicely..
9 *
10 * @return void
11 **/
12 function wp_comments_theme_registry_alter(&$theme_registry) {
13 if (!empty($theme_registry['form_element'])) {
14 $theme_registry['form_element']['function'] = 'wp_comments_form_element';
15 }
16 }
17
18
19
20 /**
21 * An implementation of hook_form_alter()
22 * Tweak the comment form, and add the #wp_comments_element flag to any textareas
23 * so our custom theme function can intercept and shuffle the labels around.
24 *
25 * @return void
26 **/
27 function wp_comments_form_alter(&$form, &$form_state, $form_id) {
28 if ($form_id == 'comment_form') {
29 foreach (element_children($form) as $key) {
30 if (isset($form[$key]) && isset($form[$key]['#type']) && $form[$key]['#type'] == 'textfield') {
31 $form[$key]['#wp_comments_element'] = TRUE;
32 $form[$key]['#size'] = 40;
33 }
34 }
35
36 if (isset($form['_author'])) {
37 $form['_author']['#type'] = 'markup';
38 $form['_author']['#value'] = t('Logged in as !user.', array('!user' => $form['_author']['#value']));
39 }
40
41 $form['comment_filter']['comment']['#rows'] = 10;
42 unset($form['comment_filter']['comment']['#title']);
43 }
44 }
45
46
47 /**
48 * A hacked version of theme_form_element()
49 * This version adds a custom CSS class, makes elements inline, and (most
50 * importantly) puts the labels on the right side of the element rather than the
51 * left. This allows the module to simulate WordPress style comment forms. Yes.
52 * All that hacking just for this. Wrong, isn't it?
53 *
54 * @return A formatted HTML form element with wrapper divs.
55 **/
56 function wp_comments_form_element($element, $value) {
57 if (empty($element['#wp_comments_element'])) {
58 return theme_form_element($element, $value);
59 }
60 else {
61 $t = get_t();
62
63 $output = '<div class="form-item container-inline wp-comments-element"';
64 if (!empty($element['#id'])) {
65 $output .= ' id="'. $element['#id'] .'-wrapper"';
66 }
67 $output .= ">\n";
68 $output .= " $value\n";
69
70 $required = !empty($element['#required']) ? '<span class="form-required" title="'. $t('This field is required.') .'">('. $t('required') .')</span>' : '';
71
72 if (!empty($element['#title'])) {
73 $title = $element['#title'];
74 if (!empty($element['#id'])) {
75 $output .= ' <label for="'. $element['#id'] .'">'. $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
76 }
77 else {
78 $output .= ' <label>'. $t('!title !required', array('!title' => filter_xss_admin($title), '!required' => $required)) ."</label>\n";
79 }
80 }
81
82 $output .= "</div>\n";
83
84 return $output;
85 }
86 }

  ViewVC Help
Powered by ViewVC 1.1.2