Hopeless Geek

Tagline

The problem with most political jokes is that they get elected.

Home » Blogs » Adam Knight's blog

My Drupal Code Changes


  • Blogging
  • Tips
February 6, 2005 - 10:53am

As promised, the parts of Drupal that I changed to get CP working the way I like it.

In mt2drupal I changed:

line 279: my $file = $blog->archive_url . sprintf("%06d", $entry->id) . ".html";

This part just mimics the old MT archive paths of /archives/000102.html and doesn’t handle the newer format, or custom formats. Thankfully, MT 3 has a method of getting the calculated archive path. So we change this line to say:

line 279: my $file = $entry->archive_url("Individual");

That gets us whatever the permalink is to the entry. Now when things are imported, all the paths will be the same and Drupal will answer to them as if it were MT. Sneaky.

What about TrackBacks? Install the trackback.module file and tables first, and then look at:

line 273: db_query($dbh,"REPLACE INTO ${db_prefix}trackback_pingme (nid, cid) VALUES (%d, %d)", ($preserve_id ? $entry->id : $count), $cid) if ($mode == 0);

This line of code is for Drupal4Bloggers, a custom version of Drupal. Something similar works for the stock TrackBack module, so right below it add the following:

line 274: db_query($dbh,"REPLACE INTO ${db_prefix}trackback_received (nid, cid, url) VALUES (%d, %d, %s)", ($preserve_id ? $entry->id : $count), $cid, $dbh->quote($tb->source_url)) if ($mode == 2);

Now if you’ve set the mode of the script to 2, for Drupal HEAD (aka 4.5, at the time), then it will insert TrackBacks into that table and you’ll get a nice list of TrackBacks on their own tab, like you should.

In autopath.module (a contributed module) I had to change several things. As-is all the module does is make URLs for entries be a modified title at the root of the URL. That’s nice, but not nearly as informative as what I had. That, and I wanted some consistency in my URLs for future’s sake. So I opened it up and made the following changes:

line 24: $alias = str_replace("'", "", $alias);

MT also drops non-alphanumeric characters, so I removed this line and its comment and changed this line:

line 25[1]: $alias = preg_replace("/[\W]+/ ", "_", $alias);

to read

$alias = preg_replace("/[\s]+/ ", '_', $alias);
$alias = preg_replace("/[\W]+/ ", '', $alias);

Now there’s the issue of the dates. I added the following code right before the bit where it checks for existing aliases:

$date = date("Y/m/d/", $node->created);
$alias = "archives/".$date.$alias.".php";

The modified versions of both files are attached.

You will need to rename the files to autopath.module and mt-to-drupal.cgi to get them to work properly. Please download the whole mt2drupal package from the Drupal CVS site before trying to use it. This way you get the README, which you must read.

Q&A

Q: I tried to run the script…

I will not answer your questions on how to use it. There’s a nice post from the author that talks about it and runs over some basics. For everything else, get the original package from him and read the documentation. If you’re still lost, well, I’m sorry.

Q: Will you post the changes to the Drupal CVS?

The moment I figure out how to get an account, yes. At the moment, that’s not high on my list of to-dos.

Q: Can I add the changes to CVS in your name?

No, but I lay no claim to the two lines of code. Post it as yourself, I don’t care.

1 New line number after removing the noted lines.

AttachmentSize
autopath.module.txt1.52 KB
mt-to-drupal.txt13.18 KB
  • Adam Knight's blog
  • Printer-friendly version
February 6, 2005 - 4:17pm
jerakeen.org (trackback) said

Notes to myself – useful resources for working with Drupal:

  • Releases, including modules
  • wp2drupa
  • reply
February 6, 2005 - 7:25pm
Tom Insam said

for people wanting to use the autopath hack and apply it to past entries that you didn't manage to keep historic urls for (like me, basically), there's another fix for the autopath module at this drupal node.

  • reply
February 6, 2005 - 9:42pm
James Seng said

Nice change. Just one comment about your autopath.module…

it is better to alias it to .html instead of .php for a couple of reasons – technically, the alias isn’t php – proxies cache it better

  • reply
February 7, 2005 - 12:52am
Adam Knight said

Agreed, generally, but the old pages were .php pages, so for the sake for forward-compatibility I’m using .php here, as well.

  • reply

Post new comment

The content of this field is kept private and will not be shown publicly.
 
Input format
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You can use Textile markup to format text.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Textual smileys will be replaced with graphical ones.
  • You may insert videos with [video:URL]

More information about formatting options

Syndicate content Syndicate content

Site Navigation

  • Home
  • Recent
  • Popular
    • Today
  • Top rated
    • Recent votes
  • Elsewhere
    • FriendFeed
    • Friends
    • Software
    • Unsane
View Adam Knight's profile on LinkedIn

Navigation

  • My votes

Recent comments

  • Do you have any idea as to
    4 days 8 hours ago
  • Absolutely amazing when you
    5 days 21 hours ago
  • I am pro-choice, but not for
    2 weeks 1 day ago
  • My apologies. It is your
    2 weeks 2 days ago
  • Well, first, get your own
    2 weeks 2 days ago
  • There is nothing mythical
    2 weeks 2 days ago
  • Well, the number of square
    2 weeks 6 days ago
  • I think you’re wrong by a
    2 weeks 6 days ago
  • I couldn’t agree more! I am
    2 weeks 6 days ago
  • I think those numbers are
    3 weeks 21 hours ago

Today's popular content

  • Careful, America... (159)
  • Do-It-Yourself Smart Radio Station (10)
  • Krispy Kreme bacon cheddar cheeseburgers (8)
  • Panther's Major Text Services Upgrade (6)
  • The Obama Movie (6)
more

Hopeless Geek Feeds

  • Hopeless Geek
  • Hopeless Geek - Comments

Quotes

“Nobody can understand the greatness of the 13th century, who does not realise that it was a great growth of new things produced by a living thing. In that sense it was really bolder and freer than what we call the Renaissance, which was a resurrection of old things discovered in a dead thing.” — Saint Thomas Aquinas, Garden City, NY: Doubleday Image, 1933, 41 – G. K. Chesterton

Footer Links

  • Badges
  • Contact
Powered by Drupal, an open source content management system
© Adam Knight, All Rights Reserved except where otherwise noted.