Once again, for this year’s edition of Soul of Athens we decided to use Drupal as our
CMS. Drupal gave a level of flexibility and ease of use that matched our knowledge of
both programming and CMSs.
While using Drupal, we ran into a few unique problems that required some interesting
solutions.
Let me prerequisite this by saying I do not claim to be some know-all Drupal or PHP
guru; these are just some solutions that happened to work for us in our situation.
As you may know, this year’s site was built around the idea of having multiple editions,
five to be precise, each with a unique template. While one approach to that would have
been to load specific CSS files for each page template on each page and piece of
content, we decided to do it a bit more dynamically with PHP. The idea behind the code
was to inject part of the current URL path into the body tag so that we could specify
each CSS rule more specifically with each edition’s links and divs:
<body id="<?php $edition = explode("/", $node->path); print $edition[0];?>">
There it is. Simple, but it does exactly what I need it to do. What the PHP is doing is
taking the path of the node (expression/ink, for example) and exploding the string into
an array that is being delimitated by the “/” character. Then I use the first element in
the array as the id of the body.
Alright phew.
While we were building the node templates for the pieces of content, it became quite
obvious that the way in which we were entering the contributors was slightly
problematic. When we would go into the devel module and inspect the node contents,
the only content available for the contributors was their “number.” The reason why that
was happening is still a bit of a mystery. Nevertheless, I was presented with a large list
of numbers that I was going to have to somehow correlate to an author. Instead of
going and spending an hour or so constructing a keyed array of values in PHP off a list
formated like this,
0|Matthew Anderson
1|Jonathan Adams
2|Josh Birnbaum
3|Victor Blue
4|Kiersten Bonifant …..
… I wrote a quick and dirty script in C++ to process the text into the format that I
needed, which took all of .0025 seconds to run:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
ifstream ins;
ofstream ous;
ins.open("parse.txt");
string tmp,tmp2,tmp3;
while (!ins.fail())
{
int i;
getline(ins,tmp);
for (i =0;tmp[i] != '|';++i)
std::cout<<tmp[i];
++i;
std::cout<<"=> \" ";
std::cout<<tmp.substr (i,tmp.size());
std::cout<<"\",";
}
}
… which ended up spitting out something that looked like this:
0=> ” Matthew Anderson”,1=> ” Jonathan Adams “,2=> ” Josh Birnbaum”,3=>
” Victor Blue”,4=> ” Kiersten Bonifant”
While that solved one problem, we also had to figure out a way to correlate all the users’
roles with their names and then display that in an organized fashion. The first thing we
tackled was how to grab the roles that people held:
That is what the input format looked like in Drupal. We were using a single select dropdowns
and then a multi-select field for their roles because one person could do multiple
things in any given piece.
So let’s take a look at the code … and then we can talk about it:
for ( $ii = 0; $ii <= 5; $ii++)
{
print("<li><a class='mouse_over' href='#' title='<strong>Roles:</strong>< br/> ");
for ( $i = 0; $i < count($node->field_content_role_1); $i++){
if ($ii == 0&&$arr2[$node->field_content_role_1[$i]['value']])
{
print $arr2[$node->field_content_role_1[$i]['value']];
}
if ($ii == 1&&$arr2[$node->field_content_role_2[$i]['value']])
{
print $arr2[$node->field_content_role_2[$i]['value']];
print(” “);
}
if ($ii == 2&&$arr2[$node->field_content_role_3[$i]['value']])
{
print $arr2[$node->field_content_role_3[$i]['value']];
print(” “);
}
if ($ii == 3&&$arr2[$node->field_content_role_4[$i]['value']])
{
print $arr2[$node->field_content_role_4[$i]['value']];
print(” “);
}
if ($ii == 4&&$arr2[$node->field_content_role_5[$i]['value']])
{
print $arr2[$node->field_content_role_5[$i]['value']];
print(” “);
}
}
print("'>");
if ($ii == 0)
print $arr[$node->field_content_contributors[0]['value']];
if ($ii == 1)
print $arr[$node->field_content_contributor_2[0]['value']];
if ($ii == 2)
print $arr[$node->field_content_contributor_3[0]['value']];
if ($ii == 3)
print $arr[$node->field_content_contributor_4[0]['value']];
if ($ii == 4)
print $arr[$node->field_content_contributor_5[0]['value']];
print("</a></li>");
}
?>
Basically, what I did was set up a variable called $arr that holds all of the
contributors and another array, $arr2, that contains the roles that someone
could hold (and, yes, it is also a keyed array).
Then it gets a bit more complicated. I set a nesting looping structure that goes through all five possible contributors (variable $ii) and within that goes through their possible roles. If the role field is not NULL and $i is at the corresponding contributor it prints the role(s) within the title field of a link.
The reason for all of this code is that we really wanted to refine how peoples roles were displayed. Instead of listing the contribtors roles below or beside them we decided to do something a but more dynamic and throw some jquery into the mix, with something called Qtip.
So all that work for something so simple? Yes, but that is what makes this years site so great, it’s the little things that seem almost expected that work so intuitively that really make this years site shine.
I hope this explanation helps and pulls back the curtain that all to often falls on those glued to their monitors coding away.
Good luck and Thanks for reading.
Sam Saccone









