Eneko Alonso

un Navarro en California

Projects

¿Eres español y vives fuera de España? ¿Estás pensando en salir una temporada a trabajar o estudiar en el extranjero? Si es así, no dejes de visitar Spaniards.es, la Comunidad de Españoles en el Mundo
spaniards.es

Recent comments

13:15 America/Los_Angeles


drupal

Pensando en migrar este blog a Wordpress

Bueno, allá por el 2005, cuando empecé a escribir este blog (después de haber dejado atrás el blog de EBK que tenía en Serendipity), elegí Drupal como opción porque entonces creía que era el CMS más potente que había (y lo era). Wordpress estaba siendo el motor para blogs más popular, pero aun así Drupal se veía como la mejor opción.

Cinco años después creo que no hay color. Cada vez que tengo que escribir algo en este blog me da mucha pereza, sobre todo porque poner imágenes y demás historias es un poco engorroso. También tener el CMS al día es más complicado, ya que Drupal todavía no dispone de ningún sistema de actualización automático.

No obstante, sigo pensando que Drupal es el mejor CMS para comunidades como spaniards.es. Pero para blogs, creo que Wordpress está hoy día a años luz de los demás. En cuanto tenga un rato, lo cambio. 

Adding 'random jump' functionality to your drupal page/blog

It's been a few years I would say since some blogs implemented this random jumping functionality. It is not very useful, but it's fun and sometimes very handy when one is bored. Wikipedia has it, very popular blogs like Microsiervos have it... It is small, simple and fun.

Still I had never used it on my blogs. This morning, don't ask me why, I decided to implement it, which on Drupal becomes a very simple task. Let's see. In order to implement this functionality we need:

  1. A menu link to the random post page
  2. A new page node, which PHP input format

Both tasks are very easy in Drupal, if you are using Primary Links Menus and Page nodes. Now, let's see what the new page node has to do:

  1. Generate a list of published story nodes ids
  2. Pick a random node from the list
  3. Redirect the browser to the randomly selected node page

The two first tasks can be done on a single query using the MySql function Rand(). Also we can limit the query to return only one node. Next we redirect to the new done. Finally, we abort the execution of the page with an exit() call. This will indicate Drupal it doesn't need to keep generating and formatting the new random page, since the user will never see it actually. Here is the code:

$sql = "select nid from {node} where status=1 and type='story' order by rand() limit 0,1"; $result = db_query($sql); if ($anode = db_fetch_object($result)) { global $base_url; header("Location: $base_url/node/$anode->nid"); exit(); } else { print "Error: no node returned."; }

No more Trackbacks

Few days ago I installed a new Trackback module for this blog (Drupal doesn't support trackbacks by default). But today I just realized how spammed my blog had gotten in just a few days. I have just deleted more than 7000 fake-trackback-spam-entries.

Despite the trackback module has some anti-spam measures, like verifying the original link on the other website, I think it is not worth to have all that overload on the server. So I have removed the module. No more trackbacks!

Drupal Archive

I wanted to have a very simple archive page for my blog, but I didn't want to install any extra modules. So I just wrote this code:

<?php $sql = "select n.title, n.nid, n.created, n.* from node n where n.type = 'story' and n.status = 1 order by n.created desc"; $result = db_query($sql); $output = ''; $anode = db_fetch_object($result); while ($anode) { $current_month = date('F', $anode->created); $output .= "

$current_month " . date('Y', $anode->created) . "

\n"; $output .= "
    \n"; do { $output .= "
  • " . date('d', $anode->created) . " " . l($anode->title, "node/$anode->nid") . "
  • "; } while (($anode = db_fetch_object($result)) && (date('F', $anode->created) == $current_month)); $output .= "
\n"; } print $output; ?>

You can see the result here.

Most readed content on your Drupal website

Sometimes people ask me about some stuff I have done on my Drupal sites, like this blog or Spaniards.es. I was just updating the Popular items page and I thought it would be nice to paste the code here. After all, is very simple, but still it may help newbies :)

<?php $sql = "select n.title, n.nid, nc.totalcount, n.created from node n join node_counter nc on n.nid = nc.nid where n.type = 'story' order by nc.totalcount desc limit 0,100"; $result = db_query($sql); $output = ''; while ($anode = db_fetch_object($result)) { $output .= "" . date('M d, y', $anode->created) . " " . l($anode->title, "node/$anode->nid") . " ($anode->totalcount reads)
"; } print "
$output
"; ?>

PS: This doesn't follow Drupal's standards.