View source
<?php
function geshinode_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/settings/geshifilter/geshinode',
'title' => t('GeSHi node'),
'description' => t('Settings of the GeSHi source code node type.'),
'callback' => 'drupal_get_form',
'callback arguments' => array(
'geshinode_settings',
),
'type' => MENU_LOCAL_TASK,
);
}
return $items;
}
function geshinode_help($section) {
if ($section == 'admin/settings/geshifilter/geshinode') {
return '<p>' . t('Settings of the GeSHi source code node type.') . '</p>';
}
}
function geshinode_node_info() {
return array(
'geshinode' => array(
'name' => t('Source code node'),
'module' => 'geshinode',
'description' => t('Source code with GeSHi syntax highlighting.'),
),
);
}
function geshinode_perm() {
return array(
'create source code node',
'edit source code node',
'edit own source code node',
);
}
function geshinode_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create source code node');
}
if ($op == 'update' || $op == 'delete') {
return user_access('edit source code node') || user_access('edit own source code node') && $user->uid == $node->uid;
}
}
function geshinode_form(&$node, &$param) {
require_once './' . drupal_get_path('module', 'geshifilter') . '/geshifilter.inc';
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
$form['body'] = array(
'#type' => 'textarea',
'#title' => t('Source code'),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => TRUE,
);
$form['language'] = array(
'#type' => 'select',
'#title' => t('Syntax highlighting mode'),
'#default_value' => $node->language ? $node->language : variable_get('geshinode_default_language', 'php'),
'#options' => _geshifilter_get_enabled_languages(),
'#description' => t('Select the syntax highlighting mode to use.'),
);
return $form;
}
function geshinode_validate($node) {
}
function geshinode_insert($node) {
db_query("INSERT INTO {geshinode} (nid, vid, language) VALUES (%d, %d, '%s')", $node->nid, $node->vid, $node->language);
}
function geshinode_update($node) {
if ($node->revision) {
geshinode_insert($node);
}
else {
db_query("UPDATE {geshinode} SET language = '%s' WHERE vid=%d", $node->language, $node->vid);
}
}
function geshinode_delete(&$node) {
db_query("DELETE FROM {geshinode} WHERE nid = '%d'", $node->nid);
}
function geshinode_load($node) {
return db_fetch_object(db_query('SELECT language FROM {geshinode} WHERE vid = %d', $node->vid));
}
function geshinode_view($node, $teaser = FALSE, $page = FALSE) {
require_once './' . drupal_get_path('module', 'geshifilter') . '/geshifilter.pages.inc';
$node->readmore = strlen($node->teaser) < strlen($node->body);
$line_numbering = variable_get('geshinode_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE);
$source_code = $teaser ? $node->teaser : $node->body;
$node->content['body'] = array(
'#value' => geshifilter_process($source_code, $node->language, $line_numbering),
'#weight' => 0,
);
return $node;
}
function geshinode_settings() {
require_once './' . drupal_get_path('module', 'geshifilter') . '/geshifilter.inc';
$form = array();
$form['geshinode_line_numbering'] = array(
'#type' => 'select',
'#title' => t('Line numbering'),
'#default_value' => variable_get('geshinode_line_numbering', GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE),
'#options' => array(
GESHIFILTER_LINE_NUMBERS_DEFAULT_NONE => t('no line numbers'),
GESHIFILTER_LINE_NUMBERS_DEFAULT_NORMAL => t('normal line numbers'),
GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY5 => t('fancy line numbers (every @n lines)', array(
'@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY5,
)),
GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY10 => t('fancy line numbers (every @n lines)', array(
'@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY10,
)),
GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY20 => t('fancy line numbers (every @n lines)', array(
'@n' => GESHIFILTER_LINE_NUMBERS_DEFAULT_FANCY20,
)),
),
);
$form['geshinode_default_language'] = array(
'#type' => 'select',
'#title' => t('Default language'),
'#options' => _geshifilter_get_enabled_languages(),
'#default_value' => variable_get('geshinode_default_language', 'php'),
);
return system_settings_form($form);
}