Block visibility in Drupal

Posted by Quinn at August 17th, 2006 11:38am under web 0 Comments Permalink

If you wonder how to control visibiliy of the blocks in Drupal, and especially at the front page of the website, you might want to continue reading this. Otherwise, it's probably boring.

I am using Drupal for the project I am developing at this moment. I wanted the front page to be unique as the most websites out there, I suppose. I thought built-in features in Drupal would give me easy to configure a block to be shown at only the front page. But it didn't. at least, not the way I planned.

Environment: Drupal 4.7.3 with MySQL and Apache

Drupal has admin -> block section to configure blocks individually. At the page to configure a sigle block, there is a section under “Page specific visibility settings”. I thought I just have to put

<front>

in there and everything would be fine.

Well, this surely makes the block to be shown at the front page but also paged front page too. This is not something I had in mind. This kind of configuration might work in many cases but not every time though.

Then, I chose to use “Show if the following PHP code returns TRUE” and PHP code to control the block visibility. What I came to at the first is like below.

<?php
$thisisthefrontpage = FALSE;
if(($_SERVER["REQUEST_URI"] == '/')
 ){
	$thisisthefrontpage = TRUE;
}
return $thisisthefrontpage;
?>

Then, I found another little thing that pager link will give the first page to be this url.

http://mywebsite/node

This page shows only the list of nodes and not the block I want to show in the front page. I first thought this is not the big deal, but then I figured this probably confuse many people who are using this website. I think the url in the above should show the page exactly the same as the front page. So, I changed the block configurations again like below.

<?php
$thisisthefrontpage = FALSE;
if(($_SERVER["REQUEST_URI"] == '/')
  || ($_SERVER["REQUEST_URI"] == '/node')
){
	$thisisthefrontpage = TRUE;
}
return $thisisthefrontpage;
?>

I think this is not really good coding. I wanted to do like

  || ($is_font && !is_numeric($_REQUEST["page"]))

or something like that. But none of them actually worked. I don't know why. Anyway, this is what I came to as the solution at this moment. It may work for you too when you come to similar situations. It would be nice to hear suggestions if you have something in mind. Thanks for reading.

References:

Simple Math

Posted by Quinn at August 16th, 2006 9:33am under web 0 Comments Permalink

simple math question I had to add a tweak in my blog since I was still getting spammed after the previous modifications. This is sad because it's forcing good people to do an additional task for posting. A simple math question is required to answer for posting a comment now. The question says like "Please add 7 and 8. Then, put the number here » [textbox]. I am not sure this sounds right. It's somehow harder to say simple sentences, especially when it comes to math. I went to college in the USA but I don't remember much of the math classes. So whoever come to see this as funny English in some way, please let me know it. Thanks.

Getting Spammed

Posted by Quinn at August 11th, 2006 12:53pm under web 0 Comments Permalink

Well, as the title says, my blog is getting spammed. My blog is not run by the world famous blog tool like WordPress or Movable Type. This is only a hand made version of it, which is built by me. I thought nobody would really bother to send spamming POST requests just to spam this blog. I was wrong. Someone out there has invested time to do such a thing. Oh, WTF, wasting time of life.. Doesn't this person have something better things do?

I made a few changes lately. So, it no longer accept just POST requests. You have to actually visit the page, sending a GET request and establish the session with COOKIE enabled, then this blog accepts a POST request for a comment. I also blocked some string patterns that they use, which are obviousely not very common to usual comment posts.

I suppose this is not enough yet. I am stiil getting some spamming going through the filter. But it seems successfully eliminating some of them.

What I don't understand is that I am getting spammed only for a single post page Teacher Me? from a verious IP addresses. I don't know what kind of method is used to do such a task. It looks like human inputs but not totally. I probably should have been more careful in the first place. But this is just making me a better web developer, so thanks whoever this person is..

Don't Make Me THINK

Posted by Quinn at August 1st, 2006 9:38am under web 0 Comments Permalink

Don't Make Me THINK Yes, I am so slow at writing posts for this blog. Despite of my laziness, I am so far doing pretty good as a freelance web developer this year. And I even finished a book, which I barely do.

Well, this is a thin book, easy to read, and particulary in my interest! This book showed me how to make good decisions for designing websites, especially in the view from users. I think it is well described in the book's title. It talks about web usability. Things are mostly I knew from experiences, but I was amazed how stuff are articlated in words. I never can do that. It was fun reading this book. After all, I am looking forward myself doing better jobs for coming projects!