giza: Giza White Mage (Default)
Earlier today, I performed a major Drupal upgrade on another site that I run. Part of the upgrade involved me installing the Advanced Forum module to bring the forums a little more up to date with other sites that are out there.

Along the way, I learned something interesting: the Author Pane module does NOT display on blog posts.

It looked rather odd when comments on the blog posts had detailed user info, but the post itself did not. So I set out to fix that. I ended up commenting out the line print $picture; in node.tpl.php and instead adding in these lines:

$account = user_load($node->uid);
$template = "advf-author-pane";
$author_pane = theme('author_pane', $account,
        advanced_forum_path_to_images(), $template);
print $author_pane;


The code is fairly straightforward. It loads user info on the author of the post, and the theme() function loads the author_pane template, passing in the user data.
Enjoy!
giza: Giza White Mage (Default)
Wow, it's been awhile since I've written here. Real life has had me very busy lately. I've done some neat things though, and I hope to post more about them soon.

The first neat thing I did recently was to roll out some badly needed updates for the user pages on anthrocon.org.

Before, I merely used the default pages that Drupal provided. The problem was that the pages looked a little... bland. Among other things, there were no icons for the various social networking services, and that just wouldn't do. So I read up on how to customize the user profile layout in Drupal and spent a couple of evenings writing some PHP code and making use of Drupal's theming functions.

Here are the old and the new pages side by side. Click on either to get a full page in a separate window.

Old and busted:New hotness:

Old default Anthrocon user page

New Anthrocon user page, with theming


The upside of this effort is that when I'm ready to upgrade the Save Ardmore Coalition site to Drupal 6, I can pretty much just copy over my user templates on a wholesale basis, and save myself from having to redo all that work. :-)

How has everyone else been here in LJ-land?
giza: Giza White Mage (Default)
It's been a busy week or so since I posted here last.

Over the weekend, I deployed some Drupal modules on a few sites that I manage. So now the Save Ardmore Coalition site has a tag cloud, and registered users may tag existing content with custom tags. I did the same thing on the Anthrocon website, their tag cloud is over here. I also played around with the "views" module and created some pages for all-time popular posts, highest rated posts, posts with the most comments, and posts with the most votes.

I heard from an old client of mine, who asked if I could debug some ancient PHP code. Something about PHP 3 code not working right under PHP 5. :-)

I got involved with another random programming project. This one is a volunteer gig, and more of a long-term project. I have some exciting ideas for things I'd like to do, and hope they'll save us all some time and effort, as well as increase code quality.

I played around with the Simpletest module for Drupal. The version for Drupal 5 seems to be a bit round around the edges, but useful for what I have in mind, since it will be a start.

I took a look at the docs for the Yii PHP Framework. It doesn't look so bad, and the documentation is fairly detailed. I have concerns about some of the naming conventions on their classes, and the fact that a lot of the classes are invoked via static calls. (Makes unit testing and dependency injection a little difficult...), but at least there was some thought put into the way things were done. (Are you listening, PHP team?)

I am getting ready for Furry Connection North next month. Last year's convention went really well for being a first year con, and I've been impressed at how well the preparations are proceeding for this year's con. It should be fun, or at least interesting. :-)
giza: Giza White Mage (Default)
Been setting up a new machine for the migration of Anthrocon's webserver. This should address some of the speed issues we've been having as well as allowing us to use SSL on the site. Plus, since I now have root access and things like crontab available, I can start doing nightly rsyncs of the data.

Fun fact: Nginx lets you chain SSL certificates merely by appending the extra certificates on the end of your site's certificate. No extra webserver configuration requried!

Been building the pre-registration system for 2009, too. I expect that to be finished in the next few weeks. Also, I will be releasing the final product under the GNU Public License. I figure I can at least entertain others by letting them laugh at my code.

I slept poorly a few nights ago and must have done something to the muscles in my neck. This has resulted in me having headaches the last few days. Advil helps the symptoms, though.

Heading up north tomorrow to visit the family for a party. We're celebrating my kid sister's Masters Degree. Let her be the highest educated person in my family for a change. :-P

[Edit: Forgot to mention co-worker J. He wants to tag along with me to the next furry convention I attend, which would be FurFright. He has NO idea what he's in for! :-)]
giza: Giza White Mage (Default)
While using the nginx webserver with a Drupal installation I noticed something odd. Whenever I submitted a form (with the GET method) or clicked on a link that had a space in it, it would be converted to a plus sign in the URL. Actually, that's not the odd path--the web browser is doing proper URL encoding since spaces are not allowed in URLs.

The weird part is that after the request got to the webserver, and the server processed it and passed it to PHP, and PHP loaded Drupal and executed the PHP code, the plus sign failed to be turned back into a space when using the nginx webserver. Works fine in Apache, but not in nginx.

The symptom is that if I tried to perform a search or edit my user profile, or anything else that involved a plus sign in the GET data, when that data was processed by PHP, the plus sign was still there. i.e., I would see "term1+term2" in the search box, instead of "term1 term2".

So, how to fix this? I could have spent some time reading RFCs, and looking through the source from PHP and nginx, or I could have my site working again. I opted for the latter, and found that this line of code at the very beginning of Drupal's index.php seems to do the trick:

$_GET["q"] = strtr($_GET["q"], "+", " ");


It's silly, and may even be a bit stupid, but it sure does the trick.
giza: Giza White Mage (Default)
Making form variables into arrays in PHP easy. One only needs to add "[]" to the name of the variable to make this happen. Example:
<input type="text" name="search[name]" id="search[name]" />
<input type="text" name="search[age]" id="search[age]" />
<input type="text" name="search[city]" id="search[city]" />
<input type="text" name="search[state]" id="search[state]" />
<input type="text" name="search[country]" id="search[country]" />
When the form is submitted and the PHP code on the processing page is run, there will be a handy little array called $search. This variable can then be passed into additional functions, looped through, etc. It's way easier than working with 5 separate variables.

Lately, I've been using jQuery in some of my web development. It lets me "do more with less", as they say. One very easy way to access specific HTML entities in a document is with pound-notation. Examples:
$("#foo").addClass("required");
$("#bar").hide();
$("#username").css("background-color", "blue");
If you just groaned, then you know what's coming. Sure enough, jQuery has issues with using square brackets in pound-notation. It seems that square brackets are used by jQuery itself as attribute selectors.

It took me some time, but I finally found a workaround, which was the real reason behind writing this journal entry -- so as to save myself and other folks time from having to find this solution again in the future. Examples:
$("[id='search[name]']").hide();
$("[id='search[address]']").show();
$("[id='search[country]']").css("color", "green");
That's about it. Happy jQuerying!
giza: Giza White Mage (Default)
So, I still need to release my backup module for Drupal 5. But I haven't had a chance to sit down and actually read the documentation.

But, awhile back, I developed my own command-line utility for backing up my own Drupal websites. Since it was quicker to clean that up and release it instead of waiting for me to Finish the Drupal 5 version of the module, I figured I would do that.

The program can be downloaded from here.

It needs to be run from the root directory of DOCUMENT_ROOT from the command line. It will automatically read in your default settings.php file to get the database credentials and create its own backup of the database. Then it will backup the webserver's filesystem and store both database backup and filesystem into a nice little tarball, ready for download via your web browser.

For those of you who are worried because the file is essentially world-readable, there is a random number appended to the database dump and the final backup to prevent an attacker from guessing the name of the file. (your webserver would fall over from the 404s before someone successfully guessed a filename)

Enjoy!
giza: Giza White Mage (Default)
I just learned the hard way that if you call the gettext() on an installation that does not have it compiled in, PHP just exits. No errors, no warnings, nothing. The script just stops. And yes, error_reporting(E_ALL) is enabled.

What an annoyance.
giza: Giza White Mage (Default)
Awhile back, I was working on a private Drupal website for members only. Now, Drupal has a module called Secure Site which can be used for this. However, Secure Site throws up an HTTP 401 error to request authentication from the user. If you've ever seen a "enter username and password" box pop up in your browser, that's an HTTP 401 error. That's okay, but I don't think it's the best UI out there. I wanted something a little user-friendlier.

So, I came up with the code below. Put it in your index.php file (or better yet, in a file included by index.php) right after the call to drupal_bootstrap(). It will redirect all but a certain subset of pages to the login page, and prompt users to log in.

$path = getenv("SCRIPT_URL");

//
// If a user is not logged in, they can only access certain unrestricted pages.
//
if ($user->uid == 0) {
   if (
      // 
      // strstr() is called for efficiency.  Keep in mind that ANY path that matches
      // these strings will be allowed to anonymous users.  So if you have something
      // like "/userlist", an anonymous user can view that.  I warned ya!
      // 
      !strstr($path, "user")
      && !strstr($path, "how-to-join")
      && !strstr($path, "contact")
      ) {
         form_set_error("", "You must be logged in first.");
         drupal_goto("user");
      }

}


Enjoy!

[Edit: Added blurb about security. Thanks for pointing that out [livejournal.com profile] taral.]

Profile

giza: Giza White Mage (Default)
Douglas Muth

April 2012

S M T W T F S
1234567
891011121314
15161718192021
22232425262728
2930     

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags