Anyone know how to use PHP to send X-Headers with cURL? Anyone? No? Never hurts to ask.
Tag archives for PHP
Wednesday, May 30, 2007
Thursday, November 30, 2006
Damn him all to hell
So apparently Michael Douglas almost killed himself.
Douglas briefly lost his footing while standing in a cherry-picker basket 25 feet in the air to christen a new art museum in Bermuda. Douglas, a benefactor of the Masterworks Museum of Bermuda Art, was pouring rum on the roof in a traditional regional "roof-wetting" ceremony Monday but managed to steady himself.
Fucking Michael Douglas. When presented with the opportunity, the guy adamantly refuses to fall on his head.
And on a completely different note, I've been considering making a dramatic overhaul to my sidebar. A few of the ideas I'm kicking around might not be compatible with my older blog skins. Does anyone use the Eat at The Fish's, Tossed My Salad, or Just For Charred skins? I'm thinking about getting rid of them to free my template for more radical designs, but I don't want to feel like I'm yanking the rug out from under too many people.
Speaking of design changes, I've changed the way this blog uses CSS. The "standard" methods for serving CSS are to have styles embedded in the HTML or to use static external files. I'm using a different method now. I'm serving CSS through PHP, which (among other benefits) allows some server-side trickery.
Anyway, you probably don't care about the behind-the-scenes voodoo. I bring it up only because I'm wondering about compatibility. I'd hate to go blazing forward with something that doesn't work for everyone. So if none of these new stylesheets are available to you, I'd really appreciate hearing about it.
Thursday, August 31, 2006
I warned you
As threatened, I've posted instructions for setting up your own random quotes. The instructions apply to any blogging system: Blogger, WordPress, ExpressionEngine, whatever.
Since random quotes is one of the things I'm asked about most often, I decided to make that post a static page so it won't be quickly pushed into the archives and forgotten. So you can find it here or click the new entry in the list of quicklinks near the top of the sidebar.
Wednesday, July 26, 2006
A whatsis?
I've been following with great interest Andy Skelton and Scott Allen Wallick's posts on semantic CSS. At first I was really thrown by their use of "semantic." "The meaning of words?" I thought. "What does that have to do with CSS?"
It turns out that semantics is all about meaning and changes in meaning, usually (but not always) as it applies to language. Yeah, ok, that does make a little more sense. Anyway! They're trying to flesh out a new model for WordPress templates that would provide a much higher level of customizability than most designs currently floating around out there.
Although the entire idea has tremendous potential, the one aspect of this that interests me most is the possibility of distinct styles for individual posts based on that post's category. I've had this particular feature implemented on this blog for over a week. So far all I've done with it is specify subtle background images for the "geekery" category, and only on the red "Eat at The Fish's" skin.
Interested in seeing how it's done? No? Tough luck, I'm writing about it anyway.
Implementation requires three fairly minor changes. First, you need to add a custom function to your theme's functions.php (if you don't have a functions.php, you'll need to create one):
function post_category_class() {
foreach ( ( get_the_category() ) as $cat ) {
echo ' ' . $cat->category_nicename;
}
}
This function will generate the category slug names as output suitable for CSS classes.
Next you need to call the function in the WordPress loop. Your theme will probably have a line of code similar to this:
<div class="post" id="post-<?php the_ID(); ?>">
Which would generate output like this:
<div class="post" id="post-514">
After you've inserted the new function call into your template like this:
<div class="post<?php post_category_class(); ?>" id="post-<?php the_ID(); ?>">
Simply and elegantly, every post will now automatically have a category-related class attached. Like this:
<div class="post geekery" id="post-514">
Finally, you'll need to add style rules to make certain categories stand out. Here are mine:
.geekery {
background:url('/images/styles/eatatthefishs/geekery.gif') top right no-repeat;
}
.geekery .entry {
background:url('/images/styles/eatatthefishs/geekery2.gif') bottom right no-repeat;
}
And huzzah! New styles just for "geekery" posts. If you intend to implement this type of setup on your WordPress blog, note that you'll probably want to insert that new function call into every template page that contains the WP loop (e.g., Search Results, Archives, Single Post, etc.) Not all themes have all template files, so your results will vary.
As I said, the only thing I've done with this so far is to specify those two subtle background images. Because this method will apply the category slug as a class for every category to which a post is assigned, there's the very real possibility of overstyling a post. For example, if I specify a border for the News category and a larger font for the A/V category, a post filed in both categories would have both a border and the larger font. Since a few of my catch-all posts are filed into many categories, too many styles would easily make for cluttered eyesores.
I like the clean simplicity of my template now, so I'm only implementing modest styles as they occur to me. Since the blue "Tossed My Salad" skin is available mostly as a retro throwback, that skin probably won't see any new styles at all.
Wednesday, June 7, 2006
Notes on hosting your own blog, part 10
So, last week an update to WordPress was released. The new version, 2.0.3, includes a few minor performance enhancements and bug fixes and one big new feature: nonces. Nonces are some moderately complex technobabble that Owen at Asymptomatic does a pretty good job translating into something resembling layman's terms here. The short version is that nonces are a system for verifying that administrative commands come from the right place.
I read the release notes and was very interested in the new version. So I got all of my little ducks lined up in a row and prepared to upgrade. I downloaded the new installation, made an up-to-the minute backup of my database, and FTP'd a copy of my current install to my hard drive.
I've modified the WP core files a bit, so let's just say that I was using WordPress "2.0.2.fish." I took the new 2.0.3 files and added my mods before uploading them to save me the difficulty of doing it after the files were in place.
I activated the Maintenance Mode plugin to take my blog offline and overwrote my current installation with the new version. After the upload, I ran the one-click database upgrade. All finished, I viewed my blog… and found that for some unfathomable reason all of my content was crammed into the sidebar. The content that should have composed the main column was inexplicably displaying with a width of about half a character.
It was completely unusable.
I wondered, "Why would the theme fail in the new WP? Did the Maintenance Mode plugin mess with the install?" So I deleted my WP install and database, restored my backups, disabled Maintenance Mode and tried again.
No luck. Same problem.
I played around with the templates and found that it was only my custom theme that had a problem. The two themes included with WP worked just fine.
I wondered, "So is it a plugin problem?" I disabled all my plugins and tried the whole thing all over again, only to learn that nothing in my custom theme worked without the plugins the theme used.
Eventually, I mucked around with the blog output enough to learn that there was nothing wrong with my theme, or my plugins, or with the WP update.
The problem is that I'm a dumbass.
It was all in those mods I made to the WP core files. See, it turns out that if a file has two modifications, I better damn well make sure I update both of them, not just one. Some of the code I changed involves how the sidebar displays. I was sloppy when I inserted my changes. Garbage in, garbage out.
So in addition to being reminded yet again of how important it is to pay attention and do things right the first time, I also learned a lesson about using plugin template tags.
Trying to troubleshoot plugins without being able to disable the plugins was a colossal pain in the ass. So I took the time to sort out my template and wrap all plugin calls with function checks. I'm now at a point where I can disable all my plugins and everything will still work. Which is exactly what I need for troubleshooting in the future.
Confused about that function check business? It's simple, yet kind of important, so I'll explain.
The install instructions for a plugin with template features may tell you to insert a line of code like this:
<?php plugin_function('do_something_cool'); ?>
I would strongly recommend you wrap that in a function check, like this:
<?php if (function_exists('plugin_function')) { plugin_function('do_something_cool'); } ?>
The first line of code basically says "do this or else." The second line of code is more like "if you can do this, then do. Otherwise don't worry about it." And that's exactly what one needs to disable a plugin without also removing any matching template tags.
It's a good thing that I finally got around to adding those function check wrappers, but it turns out that the whole thing was kind of an exercise in foolishness. Although the new nonce system is cool, WordPress 2.0.3 is no kind of improvement at all. Those nonces don't really work right.
For some reason or another, every edit or delete operation I perform generates an extra warning prompt. And everything I edit suddenly has all single and double quotes escaped. (Like this: \"Let\'s go to John\'s house.\") What a pain in the ass.
Apparently these problems are not unique to me. There's a support thread on the WordPress site where people are talking about it. Mark Jaquith has even developed a plugin to fix it.
But that's a little messed up. Install the new update and then install a third party plugin to get the update to work? That blows. I'd recommend skipping WP 2.0.3 altogether and just waiting for the next revision.
Thursday, February 16, 2006
Notes on hosting your own blog, part 5
So I'm planning on getting off the Blogger tit for good and migrating to Wordpress. (Not as big a deal as you might think. More details on that later.)
Wordpress is amazingly powerful. I've got a test installation up and running to fiddle with before I "go live." There's quite a learning curve on some of this stuff. For example, a standard Blogger template is XHTML with special markup stored in one file. The default Wordpress template is a mix of XHTML and PHP with special markup stored in seventeen files.
Installing Wordpress is fast and is a task of "intermediate difficulty." The basic options are as simple to use as the Blogger Dashboard. But when it comes to advanced customization, only ubergeeks need apply.