Files
MagicSetEditor2/tools/website/drupal/fromfile.module
T
twanvl fe0de4893f Custom php scripts used for the documentation on the website
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@566 0fc631ac-6414-0410-93d0-97cfa31319b6
2007-07-13 18:08:02 +00:00

121 lines
2.7 KiB
Plaintext

<?php
require_once('./modules/mse-drupal-modules/autoformat.inc');
global $nice_ff_names;
$nice_ff_names = array(
'function' => 'Functions',
'type' => 'Types'
);
define('FROMFILE_DIR', 'doc');
/**
* @file
* Read pages from the filesystem
*/
/**
* Implementation of hook_help().
*/
function fromfile_help($section) {
switch ($section) {
case 'admin/modules#description':
return t('Read pages from the filesystem.');
case 'admin/settings/search':
return t('From file path settings');
}
}
/**
* Implementation of hook_menu().
*/
function fromfile_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => FROMFILE_DIR,
'title' => t('fromfile'),
'callback' => 'fromfile_page',
'access' => user_access('access content'),
'type' => MENU_SUGGESTED_ITEM);
}
return $items;
}
/**
* Menu callback: show file
*/
function fromfile_page() {
global $nice_ff_names;
$path = variable_get('fromfile_path', '');
if ($path=='') return drupal_not_found();
$args = func_get_args();
$file = implode('/', $args);
// open file
$file = str_replace('.','',$file);
$file1 = "$path/$file.txt";
$file2 = "$path/$file/index.txt";
$file1 = str_replace('//','/',$file1);
$file2 = str_replace('//','/',$file2);
if (file_exists($file1)) {
$full_path = $file1;
} elseif (file_exists($file2)) {
$full_path = $file2;
} else {
return drupal_not_found();
}
$raw = file($full_path);
foreach($raw as $k=>$l) $raw[$k] = preg_replace("/\r?\n/","",$l);
// format the file
$title = array_shift($raw);
$content = autoformat($raw);
// breadcrumbs
$breadcrumbs = array(l(t('Home'), NULL));
$path = FROMFILE_DIR;
for ($i = -1 ; $i < count($args) ; ++$i) {
$path .= '/' . $args[$i];
if ($i == count($args) - 1) {
$name = $title;
$name = preg_replace("/.*: ?/","",$name);
} elseif ($i == -1) {
$name = 'Documentation';
} else {
$name = ucfirst($args[$i]);
if (isset($nice_ff_names[$name])) $name = $nice_ff_names[$name];
}
$breadcrumbs[] = l(t($name), $path);
}
// done
drupal_set_title($title);
drupal_set_breadcrumb($breadcrumbs);
return $content;
}
/**
* Menu callback; displays a module's settings page.
*/
function fromfile_settings() {
// From file settings:
$form['fromfile'] = array(
'#type' => 'fieldset', '#title' => t('From file settings'),
'#collapsible' => TRUE, '#collapsed' => FALSE
);
$form['fromfile']['fromfile_path'] = array(
'#type' => 'textfield', '#title' => t('Path'), '#default_value' => variable_get('fromfile_path', ''),
'#description' => t('Path for the fromfile module.'), '#required' => FALSE
);
return $form;
}