/[drupal]/contributions/modules/geshifilter/geshinode.module
ViewVC logotype

Contents of /contributions/modules/geshifilter/geshinode.module

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


Revision 1.9 - (show annotations) (download) (as text)
Mon Jul 21 17:44:23 2008 UTC (16 months ago) by soxofaan
Branch: MAIN
CVS Tags: DRUPAL-6--1-2, HEAD
Changes since 1.8: +6 -1 lines
File MIME type: text/x-php
fixed some issues reported by the coder module
1 <?php
2 // $Id: geshinode.module,v 1.8 2008/07/21 14:24:16 soxofaan Exp $
3
4 /**
5 * @file
6 * Implementation of a GeSHi node.
7 */
8
9 /**
10 * Implementation of hook_menu()
11 */
12 function geshinode_menu() {
13 $items = array();
14 $items['admin/settings/geshifilter/geshinode'] = array(
15 'title' => 'GeSHi node',
16 'description' => 'Settings of the GeSHi source code node type.',
17 'page callback' => 'drupal_get_form',
18 'page arguments' => array('geshinode_settings'),
19 'access arguments' => array('administer site configuration'),
20 'type' => MENU_LOCAL_TASK,
21 );
22 return $items;
23 }
24
25 /**
26 * Implementation of hook_help().
27 */
28 function geshinode_help($path, $arg) {
29 if ($path == 'admin/settings/geshifilter/geshinode') {
30 return '<p>'. t('Settings of the GeSHi source code node type.') .'</p>';
31 }
32 }
33
34 /**
35 * Implementation of hook_node_info().
36 */
37 function geshinode_node_info() {
38 return array(
39 'geshinode' => array(
40 'name' => t('Source code node'),
41 'module' => 'geshinode',
42 'description' => t('Source code with GeSHi syntax highlighting.'),
43 'has_title' => TRUE,
44 'title_label' => t('Title'),
45 'has_body' => TRUE,
46 'body_label' => t('Source code'),
47 )
48 );
49 }
50
51 /**
52 * Implementation of hook_perm().
53 */
54 function geshinode_perm() {
55 return array('create source code node', 'edit source code node', 'edit own source code node');
56 }
57
58 /**
59 * Implementation of hook_access().
60 */
61 function geshinode_access($op, $node) {
62 global $user;
63 if ($op == 'create') {
64 return user_access('create source code node');
65 }
66 if ($op == 'update' || $op == 'delete') {
67 return user_access('edit source code node') ||
68 user_access('edit own source code node') && ($user->uid == $node->uid);
69 }
70 }
71
72 /**
73 * Implementation of hook_form().
74 */
75 function geshinode_form(&$node, $form_state) {
76 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
77
78 $type = node_get_types('type', $node);
79
80 // set the title field
81 $form['title'] = array(
82 '#type' => 'textfield',
83 '#title' => check_plain($type->title_label),
84 '#required' => TRUE,
85 '#default_value' => $node->title,
86 '#weight' => -5,
87 );
88
89 // the body field
90 $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count);
91 unset($form['body_field']['format']);
92
93 // the source code language field
94 $form['source_code_language'] = array(
95 '#type' => 'select',
96 '#title' => t('Syntax highlighting mode'),
97 '#default_value' => isset($node->source_code_language) ? $node->source_code_language: variable_get('geshinode_default_language', 'php'),
98 '#options' => _geshifilter_get_enabled_languages(),
99 '#description' => t('Select the syntax highlighting mode to use.')
100 );
101 return $form;
102 }
103
104 /**
105 * Implementation of hook_validate().
106 */
107 function geshinode_validate($node) {
108 ///TODO
109 }
110
111 /**
112 * Implementation of hook_insert().
113 */
114 function geshinode_insert($node) {
115 db_query("INSERT INTO {geshinode} (nid, vid, language) VALUES (%d, %d, '%s')",
116 $node->nid, $node->vid, $node->source_code_language);
117 }
118
119 /**
120 * Implementation of hook_update().
121 */
122 function geshinode_update($node) {
123 if ($node->revision) {
124 geshinode_insert($node);
125 }
126 else {
127 db_query("UPDATE {geshinode} SET language = '%s' WHERE vid=%d", $node->source_code_language, $node->vid);
128 }
129 }
130
131 /**
132 * Implementation of hook_delete().
133 */
134 function geshinode_delete(&$node) {
135 db_query("DELETE FROM {geshinode} WHERE nid = '%d'", $node->nid);
136 }
137
138 /**
139 * Implementation of hook_load().
140 */
141 function geshinode_load($node) {
142 return db_fetch_object(db_query('SELECT language AS source_code_language FROM {geshinode} WHERE vid = %d', $node->vid));
143 }
144
145 /**
146 * Implementation of hook_view()
147 */
148 function geshinode_view($node, $teaser = FALSE, $page = FALSE) {
149 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.pages.inc';
150 $node->readmore = (strlen($node->teaser) < strlen($node->body));
151 $line_numbering = variable_get('geshinode_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE);
152 $source_code = $teaser ? $node->teaser : $node->body;
153 $node->content['body'] = array(
154 '#value' => geshifilter_process($source_code, $node->source_code_language, $line_numbering),
155 '#weight' => 0,
156 );
157 return $node;
158 }
159
160 /**
161 * Callback for geshinode settings form
162 */
163 function geshinode_settings() {
164 require_once drupal_get_path('module', 'geshifilter') .'/geshifilter.inc';
165 $form = array();
166 $form['geshinode_line_numbering'] = array(
167 '#type' => 'select',
168 '#title' => t('Line numbering'),
169 '#default_value' => variable_get('geshinode_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE),
170 '#options' => array(
171 GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE => t('no line numbers'),
172 GESHIFILTER_LINE_NUMBERS_DEFAULT_NORMAL => t('normal line numbers'),
173 GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY5 => t('fancy line numbers (every @n lines)', array('@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY5)),
174 GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY10 => t('fancy line numbers (every @n lines)', array('@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY10)),
175 GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY20 => t('fancy line numbers (every @n lines)', array('@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY20)),
176 ),
177 );
178 $form['geshinode_default_language'] = array(
179 '#type' => 'select',
180 '#title' => t('Default language'),
181 '#options' => _geshifilter_get_enabled_languages(),
182 '#default_value' => variable_get('geshinode_default_language', 'php'),
183 );
184 return system_settings_form($form);
185 }

  ViewVC Help
Powered by ViewVC 1.1.2