This patch introduces a new module well under one kilobyte which lets you define pages in a very, very simple way: save something.inc into modules/pages and define something_page inside it. This will work under pages/something. Because it's a module, not eval'd code, it'll be faster. Because there is no node_load, it'll be faster again. The burden on menu system is minimal, one path is defined, 'pages'.

Also I modified hook_block that it can work without switching on 'op' -- just return a string and block.module will do what's right, For example, I tested with the following module:

function test_block() {
  return 'foo';
}

and it worked.

Do not let the size of the patch intimidate you, it's very simple, the changes are very small, just I reindented some lines. It does not break any current functionality.

With this change in place, we could remove PHP filter frorm the defaults because now it will be awfully simple to define a page or a block. In other words: some may blog about removing that filter -- that's the silver. Here is the gold.

Because of nothing what exists is effected, I'd like to see this in 4.7. I know pages could use some help. I leave that for others.

Comments

chx’s picture

StatusFileSize
new7.17 KB

http://www.webschuur.com/node/409 Ber's blog entry and a small fix.

chx’s picture

StatusFileSize
new7.23 KB

This is an an even better way to simplify pages: just pour the raw PHP into something inc.

chx’s picture

StatusFileSize
new7.23 KB

Ops, we use return now, of course, I spend too much with non-4.7 code.

chx’s picture

Status: Needs review » Needs work

Instead hacking block.module, I am creating a blocks.module which will also use .inc -- simpler is the key.

chx’s picture

Status: Needs work » Needs review
StatusFileSize
new1.58 KB

So here we are. Just save the necessary snippet into the relevant directory and you are set.

If this goes in, my hand is up to write an update function which saves the relevant nodes and blocks to .inc files and if succeeded then disables PHP filter.

chx’s picture

StatusFileSize
new1.6 KB

Proper output buffer end.

chx’s picture

StatusFileSize
new1.62 KB
chx’s picture

StatusFileSize
new1.57 KB

I made blocks.module itself more complicated than I should. BTW if this goes in, the

    ob_start();
    include_once("./$file");
    $output = ob_get_contents();
    ob_end_clean();

blurb will be repeated three times (these modules + phptemplate.engine), so I am inclined to move it to common.inc , named drupal_include. Just another thought to keep the added code smaller.

chx’s picture

StatusFileSize
new3 KB

Hell I can't let this patch rest. Moved code from phptemplate to common.inc and reused in the new modules.

chx’s picture

StatusFileSize
new20 bytes

As an example, I am testing with the attached include. It is not to be committed. I go to 'pages/foo' and watch out. I have this as a block, too.

morbus iff’s picture

I'm against this patch - the workflow is *anything* but simple. Don't force me to load an FTP client. I thought Drupal was a content management system - if I'm forced to a) write my content in a text editor (and PHP code that tweaks existing data or otherwise generates data *is* content), b) upload it through an FTP program, c) THEN manage it in the CMS, Drupal just isn't useful to me anymore. That's too many steps, too many additional resources, and too much headache. Updates will be uber annoying (open up FTP, find the file, grab the file, modify the file, reupload the file), and so will bugfixing (the whole process over and over again).

Hey, I'm all for security. But this is security that is becoming a pain in the ass - it's as bad an idea as "whee, let's move a bunch of crap into non-public directories!". I, as an administrator, should be able to decide who I trust with uploading PHP, and if that means Just Me, or All of This User Role, then so be it. Don't force me, or my administrators (who may not have an FTP client or, more importantly, whom I DON'T WANT TO HAVE FTP ACCESS ON MY DAMN BOX), to go through this insanity.

killes@www.drop.org’s picture

I agree with Morbus. While I don't like php snippets particulary and agree with Ber that you should rather write a module, people who have chosen to ignore my opinion should be free to use this feature without too much interference.

Tobias Maier’s picture

And I agree with killes
if you really want to commit this to core then there should be a front end in the admin area which makes it easy to upload and edit such *.inc files

just one new concern
I know that this system makes it easy to write small code snippets, but i think it brings more inconsistency in drupal
because with this we have two different ways to write and provide some kind of modules....

chx’s picture

Morbus, PHP is not content.

Tobias, I see no problems here -- while you had PHP nodes and blocks where were your inconsistency concerns? This is just the same.

All points are moot. PHP filter is way too insecure to be there by default.

adrian’s picture

I much prefer the solution here: http://drupal.org/node/46941

means you could remove the php filter module from the modules directory, and only allow certain sites to use it.

morbus iff’s picture

chx: bullshit. There is no semantic difference in content between:

 <p>this</p>
 <p>is</p>
 <p>a</p>
 <p>series</p>

and

<?php
 $terms = array('this', 'is', 'a', 'series');
 foreach($terms as $term) {
   print "<p>$term</p>";
 }
?>

They both produce the same content in differing ways, just using different languages and logic. Obviously, it's a really really really simple example, but I balk at the suggestions that a) I should use an FTP program each and every time I change a term or the surrounding data, or b) "well, that's a pisspoor example, and you shouldn't use PHP for that anyways", or c) "well, you should write a module for those four lines of code. Oh, and if you REALLY want to remove the FTP part, hook it into taxonomy, and ooh, ooh, hook_settings, and generally take 3 minutes of a regular node/PHP filter and turn it into an hour of work".

I can't stand this patch or the thinking behind it. Absolute idiocy.

morbus iff’s picture

"All points are moot" - ahahah. Man, that's some funny shit. "I am chx, the security genius. I will make your life more difficult, and you must accept it, because I am the security genius. Don't even bother trying to argue: I am the security genius. You are not. alt.morbus.die.die.die."

nevets’s picture

Ok, so Drupal provides a functionality that allows people to extend it's functionality with small snippets of PHP code inserted in a node or block. This catches on and drupal.org now includes snippets for both nodes and blocks. While there is alot to be said for writing a module it can be over kill for a lot of the tasks the snippets provide.

From the start though it has been know that PHP can lead to security problems and that there is potential risk to using them. Now some seem to be saying that the risk is too high and people must do it our way or tough luck, a really good approach in my opion to alienating people who have embraced drupal.

Personally I have no problem with a module that requires I turn something on (enable a module, set a global setting) but this talk of disallowing PHP in nodes and blocks is off putting. In doing so you would be either disallowing or making harder a feature that makes it easier for people to customize drupal to their liking. And that is one of Drupal's strenghts, the flexiablity to allow users of Drupal to build the web site they what, not the one some CMS constrains them to.

chx’s picture

Title: Simplify defining pages and blocks -- pave the road to get rid of PHP filter by default » Simpler pages and blocks
Category: task » feature
Priority: Critical » Normal

Interesting the fact is that while I said that "pave the road to get rid of PHP filter by default" -- noone cares. I thought something like http://drupal.org/node/46941 as a second, future step after this little patch.

So. Now I am turning this into a feature and not critical. Ber's issue is the critical one.

killes@www.drop.org’s picture

Version: 4.7.0-beta4 » x.y.z

moving

drumm’s picture

Status: Needs review » Needs work

-1.

We certainly can't have page, pages, blocks, and block in core.

I like this approach because it is more convenient to do some editing in a real editor rather than a textarea. But Morbus's point in #11 is valid (except for the ranting); editing via textarea is useful.

I think the best way to move this forward is
- Make it a single module in contrib, with 'php' somewhere in the module title
- Find someone who wants to code the textarea end
- Put some permissions on the textarea end so it can be locked out when necessary
- Bonus points: make the node type CCKable

LAsan’s picture

Version: x.y.z » 7.x-dev

moving

casey’s picture

Version: 7.x-dev » 8.x-dev

D7 is in alpha fase already.

I agree with drumm on a contrib module and making this a won't fix.

valthebald’s picture

So, should this go to won't fix?

chx’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)