diff options
author | Steven Wittens <steven@10.no-reply.drupal.org> | 2004-08-10 18:34:29 +0000 |
---|---|---|
committer | Steven Wittens <steven@10.no-reply.drupal.org> | 2004-08-10 18:34:29 +0000 |
commit | 660f99287d032c8fdc3cf09fb52f46512b68ede0 (patch) | |
tree | 678e03930c462e4ecd538f21add7a704cfbc9017 /modules/book.module | |
parent | 09fc61c0652c8603689c2bf02a6e3de8fc1b699a (diff) | |
download | brdo-660f99287d032c8fdc3cf09fb52f46512b68ede0.tar.gz brdo-660f99287d032c8fdc3cf09fb52f46512b68ede0.tar.bz2 |
The Input formats - filter patch has landed. I still need to make update instructions for modules and update the hook docs.
Here's an overview of the changes:
1) Multiple Input formats: they are complete filter configurations (what filters to use, in what order and with which settings). Input formats are admin-definable, and usage of them is role-dependant. For example, you can set it up so that regular users can only use limited HTML, while admins can free HTML without any tag limitations.
The input format can be chosen per content item (nodes, comments, blocks, ...) when you add/edit them. If only a single format is available, there is no choice, and nothing changes with before.
The default install (and the upgrade) contains a basic set of formats which should satisfy the average user's needs.
2) Filters have toggles
Because now you might want to enable a filter only on some input formats, an explicit toggle is provided by the filter system. Modules do not need to worry about it and filters that still have their own on/off switch should get rid of it.
3) Multiple filters per module
This was necessary to accomodate the next change, and it's also a logical extension of the filter system.
4) Embedded PHP is now a filter
Thanks to the multiple input formats, I was able to move the 'embedded PHP' feature from block.module, page.module and book.module into a simple filter which executes PHP code. This filter is part of filter.module, and by default there is an input format 'PHP', restricted to the administrator only, which contains this filter.
This change means that block.module now passes custom block contents through the filter system.
As well as from reducing code duplication and avoiding two type selectors for page/book nodes, you can now combine PHP code with other filters.
5) User-supplied PHP code now requires <?php ?> tags.
This is required for teasers to work with PHP code. Because PHP evaluation is now just another step in the filter process, we can't do this. Also, because teasers are generated before filtering, this would result in errors when the teaser generation would cut off a piece of PHP code.
Also, regular PHP syntax explicitly includes the <?php ?> tags for PHP files, so it makes sense to use the same convention for embedded PHP in Drupal.
6) Filter caching was added.
Benchmarking shows that even for a simple setup (basic html filtering + legacy URL rewriting), filtercache can offer speedups. Unlike the old filtercache, this uses the normal cache table.
7) Filtertips were moved from help into a hook_filter_tips(). This was required to accomodate the fact that there are multiple filters per module, and that filter settings are format dependant. Shoehorning filter tips into _help was ugly and silly. The display of the filter tips is done through the input format selector, so filter_tips_short() no longer exists.
8) A more intelligent linebreak convertor was added, which doesn't stop working if you use block-level tags and which adds <p> tags.
Diffstat (limited to 'modules/book.module')
-rw-r--r-- | modules/book.module | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/modules/book.module b/modules/book.module index a56d2bc8b..a2111a00f 100644 --- a/modules/book.module +++ b/modules/book.module @@ -39,10 +39,11 @@ function book_access($op, $node) { // Only registered users can update book pages. Given the nature // of the book module this is considered to be a good/safe idea. // One can only update a book page if there are no suggested updates - // of that page waiting for approval, it is not a PHP page, and - // the "create new revision" bit is set. That is, only updates that - // don't overwrite the current or pending information are allowed. - return user_access('maintain books') && !$node->moderate && !$node->format && $node->revision; + // of that page waiting for approval and as long as the "create new + // revision"-bit is set. That is, only updates that don't overwrite + // the current or pending information are allowed. + + return user_access('maintain books') && !$node->moderate && $node->revision; } } @@ -139,7 +140,7 @@ function book_block($op = 'list', $delta = 0) { function book_load($node) { global $user; - $book = db_fetch_object(db_query('SELECT format, parent, weight, log FROM {book} WHERE nid = %d', $node->nid)); + $book = db_fetch_object(db_query('SELECT parent, weight, log FROM {book} WHERE nid = %d', $node->nid)); if (arg(1) == 'edit' && !user_access('administer nodes')) { // If a user is about to update a book page, we overload some @@ -166,14 +167,14 @@ function book_load($node) { * Implementation of hook_insert(). */ function book_insert($node) { - db_query("INSERT INTO {book} (nid, format, parent, weight, log) VALUES (%d, %d, %d, %d, '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log); + db_query("INSERT INTO {book} (nid, parent, weight, log) VALUES (%d, %d, %d, '%s')", $node->nid, $node->parent, $node->weight, $node->log); } /** * Implementation of hook_update(). */ function book_update($node) { - db_query("UPDATE {book} SET format = %d, parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->format, $node->parent, $node->weight, $node->log, $node->nid); + db_query("UPDATE {book} SET parent = %d, weight = %d, log = '%s' WHERE nid = %d", $node->parent, $node->weight, $node->log, $node->nid); } /** @@ -187,17 +188,8 @@ function book_delete(&$node) { * Implementation of hook_validate(). */ function book_validate(&$node) { - if ($node->format && user_access('create php content')) { - // Do not filter PHP code. Do not auto-extract a teaser. - $node->teaser = $node->body; - } - else { - $node->format = 0; - } - // Set default values for non-administrators. if (!user_access('administer nodes')) { - $node->format = 0; $node->weight = 0; $node->revision = 1; } @@ -216,14 +208,11 @@ function book_form(&$node) { $output .= implode('', taxonomy_node_form('book', $node)); } - $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, filter_tips_short(), NULL, TRUE); + $output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE); $output .= form_textarea(t('Log message'), 'log', $node->log, 60, 5, t('An explanation of the additions or updates being made to help the group understand your motivations.')); if (user_access('administer nodes')) { $output .= form_weight(t('Weight'), 'weight', $node->weight, 15, t('The heavier pages will sink and the lighter pages will be positioned nearer the top.')); - if (user_access('create php content')) { - $output .= form_radios(t('Type'), 'format', $node->format, array(0 => 'HTML / text', 1 => 'PHP')); - } } else { // If a regular user updates a book page, we create a new revision @@ -401,24 +390,8 @@ function book_content($node, $teaser = FALSE) { } } - // Extract the page body. If body is dynamic (using PHP code), the body - // will be generated. - if ($node->format == 1) { - // Make sure only authorized users can preview PHP pages. - if ($op == t('Preview') && !user_access('create php content')) { - return; - } - - ob_start(); - eval($node->body); - $node->body = ob_get_contents(); - ob_end_clean(); - $node->teaser = node_teaser($node->body); - $node->readmore = (strlen($node->teaser) < strlen($node->body)); - } - else { - $node = node_prepare($node, $teaser); - } + // Extract the page body. + $node = node_prepare($node, $teaser); return $node; } |