Tag: textpattern

Jump to:

Article

How to: Linkblog via iPhone on Textpattern

Jun 24 09

With the power of Safari, the iPhone is more than capable of loading just about any administrative blog interface. It is not the optimal solution for banging out long posts. It is, however, more than capable of running a linkblog. While there are dedicated iPhone applications for several popular blog types—including some real bang up Tumblr apps—there is no such app for my platform of choice: Textpattern.

Thing is, if you’re just interested in posting interesting links like right now you hardly need a dedicated app. With a little bit of forethought and a handy bookmarklet you too can share interesting links with the world via your Textpattern site. Let’s go!

Step 1: Lay the foundation

Textpattern ships with a special link function. I don’t ever use it. This is partially because I’ve been running Textpattern since the release candidate days and the feature was poorly explained nor as robust as it is now. I keep my links in Textpattern articles.

When I had decided to add a link section I had several features I wanted from it. When posting a link I wanted the section to:

  1. Allow me to use Textile in the description.
  2. Show up in my feed—both mixed and section specific.
  3. Accommodate extra links should I so choose, which is arguably the same as reason number 1.
  4. Be friendly with Textpattern forms.

The only way I could check off all of these requirements was to post these links as articles. So that’s just how I set up the section. I made a new section named “link” and set it to be on the front page—it will appear on the front page when I call <txp:article/>—and to be included in site search. As I’m not using the default Textpattern feeds I didn’t much care if it’s syndicated. You might want to look into rolling your own feed if you set up a link section in this way. More on that in a bit. If you don’t want to segregate your linked list as a separate section you can easily post everything in the default article section.

Create a new section for your links.

Textpattern uses a cookie store the device with which you last logged into the admin. This can cause a bit of a snag if you’re trying to use the same login credentials on both desktop and iPhone. Instead of posting a link you’ll end up looking at the login screen and that info you were trying to pass on just gets lost in the ether. The solution is simple: make a new author.

Add a new author so you don't have to sign in repeatedly.

I made a new author that I only use on my phone. I set him up with the same name and email address as my primary author because that info is transmitted via meta tags. It’s not terribly important, though you do need to use a real email address because the password is sent that way. I gave my iPhone account the privileges of “Staff Writer” but you can set him up to have any account type as long as it is allowed to create articles.

The final preparatory step is setting up a place to store the link’s URI. Textpattern allows you to assign up to 10 different “Custom Fields” to articles. Pick one of them. It doesn’t really matter which one, but keep track of it. Make sure to give that field a dedicated name under Admin > Preferences > Advanced because only named fields show up in the Write tab. If they’re not already in use, the default “Custom_1” and “Custom_2” will work just fine.

Name a custom field in the Admin section.

Let’s recap. In order to prepare to post links to external sites as articles I:

  • Created a new section. This could have been skipped had I been okay with links appear in the same section as articles. But it wasn’t and I did.
  • Set up a new author so I don’t need to sign in repeatedly.
  • Chose a custom field to store the linked site’s URI.

Got that? The next step is where the real heavy lifting takes place.

Step 2: One word: bookmarklets

Bookmarklets—tiny bits of Javascript launched from a browser’s bookmarks—are the key to sending information from one website to another. When tapped, this bookmarklet will look at the current site in Safari and copy the address and the title1 to Textpatten’s article tab. Sure, now that the iPhone supports cut-copy-paste you could do this manually, but why would you? Installing a bookmarklet turns a mildly fussy procedure with several taps and holds into a two tap operation.

So, you’ve told your iPhone to sync your Safari bookmarks, right? Good. It’s going to be a whole lot easier if you do.

The first thing is to build a bookmarklet for your site. Thankfully, this has all been spelled out on the Textpattern forums. The code is replicated below. Copy this into your text editor of choice.

javascript:
var d=document,
w=window,
e=w.getSelection,
k=d.getSelection,
x=d.selection,
s=(e?e():(k)?k():(x?x.createRange().text:0)),
f='http://PathToYourTXPFolder/index.php',
l=d.location,
e=encodeURIComponent,
p='?bm=1&Section=SectionName&from_view=1&Category1=CategoryName&Title='+e(d.title)+'&Body='+e(s),
u=f+p;
a=function(){
  if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=800,height=800'))
    l.href=u;
  }
  ;
if(/Firefox/.test(navigator.userAgent))
  setTimeout(a,0);
else
  a();
void(0)

In order to work the following lines need to be changed:

  • Change f='http://PathToYourTXPFolder/index.php', to the address of your Textpattern’s administrative page. This is usually http://yoursiteaddress.tld/textpattern/index.php
  • Change Section=SectionName to whatever section these linked sites should be posted under. In my cast that would be Section=link.
  • Change Category1=CategoryName to whatever Textpattern Category the links should have. The second category can be specified by adding Category2=CategoryName but make sure that it is separated by &. I’m not using Categories in this way so I deleted this bit.
  • Add the following to this line: '&custom_1='+e(l.href). This is what copies the site’s address to the custom field selected to hold the link’s URI. In my case that is Custom 1.

This line—the one that stats with p=—is the important one. It controls what gets transferred and where. Here’s what mine ended up looking like:

p='?bm=1&Section=link&from_view=1&Title='+e(d.title)+'&Body='+e(s)+'&custom_1='+e(l.href),

Translated from the original Javascript this line says that I’ll be posting into my link section. The document’s title will be the new article’s title. Whatever text I’ve selected will be passed into the article’s body. The document’s URI will be be passed into custom 12.

So you’ve got your nascent bookmarklet all set up. You’ve told it where your admin page is. You’ve set a Section. You’ve chosen your Categories (or deleted them altogether). You’ve told it to copy the URI to a Custom Field. It’s almost ready.

There’s just one problem: too much white space. You can’t use a bookmarklet with all these lines and spaces. You could strip it out yourself, but it’s a far sight easier to just copy this whole mess and paste it into the Bookmarklet Builder. Just paste the whole mess into the textarea, give it a snappy name, and then click “Format” and “Compress.” Bookmarklet Builder will give you a nice handy link suitable for dragging and dropping into the Safari’s bookmarks. I would recommend that you install a copy in your Bookmarks Bar and in your top-level Bookmarks. The former will be useful in the desktop Safari. The latter will be a bit easier on iPhone. Of course, the bookmarklet works in every browser, but only Safari will sync to iPhone.

Add the bookmarklet to Safari Bookmarks. Plug in iPhone. Sync.

A recap of step 2. In this step I’ve:

  • Configured a bookmarklet to post the desired information to my Textpattern installation.
  • Added said bookmarklet to Safari.
  • Synced it to iPhone.

Now it’s time to put it to use.

Linkblogging on the go

iPhone in hand, visit a site you’d like to share with your lovely, intelligent readers. You’ll need to visit it in Safari, so if you’ve a ken to share a page found via Twitter or feed reader you’ll need to hit the “View in Safari” button.

View a page in Safari.

Provided you’ve upgraded to iPhone OS 3.0 (and I doubt you’d be reading this if you haven’t) you can copy and paste text from linked sites into your own—as a blockquote say. You might want to go ahead and copy that text now unless you really enjoy swapping tabs/windows. Not that there’s anything wrong with that.

Tap your bookmarklet.

Now it’s time to put that bookmarklet to use. With the page loaded in Safari tap the bookmarks icon at the bottom of the screen—you know, the one that looks like a little book. Scroll down to wherever you saved it and tap the bookmarklet. This is why I recommend saving a copy in the top-level of the bookmarks.

The write panel will appear.

The URI will be filled into the custom field, and the page's title attribute appears as the article title.

Safari will open a new window with your Textpattern write tab—provided, of course, that you’ve logged in with the special new phone account. You’ll see the page title from the site you just visited will already be in the article’s title field and the address will be in the custom field chosen to hold the URI. Great!

The link section is automatically selected. I like to turn off comments on these posts.

Scrolling over—the administrative interface isn’t really built for a screen that tops out at 480px—you’ll see that the section for this article has automagically been set to link instead of the default. I also like to turn off comments for my links. I’ve ensured that the comment form doesn’t appear on this section through the presentation, but I still like it off thank you very much. There doesn’t seem to be a way to do this via the bookmarklet.

Type (or paste) the link's description in the article body area.

Type a description for this link in the body. Here’s where you can make use of that fancy new cut-copy-paste you’ve been wanting for so long. Use the excerpt field below too if that’s your thing.

Tap publish and you're done.

Tap submit and…

Your article has been posted!

Your link has been posted. Good for you!

Oh balls! I very nearly forgot!

I’d be remiss if I didn’t mention just how the hell you’re going to display all of this. Those of you with even a passing familiarity with Textpattern have probably figured out that our little article is going to be of little use if the link doesn’t go anywhere offsite.

With my links I like to have the title of the link go to the page and not to the permanent link on my site3. That’s how Gruber does it and it’s just flat out the right way to do it. You don’t have to do it that way, but you’d be wrong.

No matter where you choose to put the link’s URI, call it up in your forms using the <txp:custom_field/> tag. Here’s how I set mine up:

<a href="<txp:custom_field name="linkURI" />" title="<txp:title />">
  <txp:title/>
</a>

Set the custom field name to whatever you set it to earlier. You could wrap this link around whatever you want, such as a spot of text that says “go away!” or some such thing. That’s not very helpful link text, but nobody is stopping you from doing it.

And finally…

To sum up a rather overlong, excessively wordy, and painstakingly specific tutorial, here’s what just happened. In order to post links via iPhone to my Textpattern based site I:

  • Added a section in which to store these articles.
  • Created a new author to circumvent Textpattern’s security cookie
  • Named a custom field to store the linked site’s URI.
  • Configured a bookmarklet, compressed it, and synced it to my iPhone.
  • Posted a link to my site on the train home from work.
  • Oh, and I also made sure my Textpattern forms were in order.

It occurs to me that this entire tutorial could be boiled down to a few succinct sentences. It also occurs to me that I can write whatever I want, however long I want. So, I guess it’s a wash.


1 In desktop browsers the bookmarklet will copy whatever text is selected into the article body field. iPhone 3.0’s select doesn’t seem to work in the same way. No matter what is selected, the article body section is going to be blank on iPhone. Remember to tap copy first!

2 If instead of posting these links as articles you’d prefer to use the Link functions of Textpattern you might want to consider this bookmarklet from the Textpattern forums. I can’t speak for it personally, but I thought I should mention that it is possible.

3 The little ∞ links to the permanent link to this, ahh, link here on the site.

Tags

Comments, now significantly less broken

Dec 27 06

Happy fucking holidays! My gift to you is a not broken comment function!

Apparently it’s been broken since I upgraded to TextPattern v4.04. Some folks have told me that they were denied due to IP blacklisting but I mistakenly assumed it was caused by the handful of comment spam messages I had specifically blacklisted. As it turns out, it wasn’t. Everyone was blacklisted, including yours truly.

At issue was a single period. Buried deep within Advanced section of the Admin Preferences in TextPattern is a field marked “Spam blacklists (comma-separated).” Up until this morning mine said sbl.spamhaus.org when it should have said sbl.spamhaus.org. and that little period made the difference between wholesale IP blocking and everything working as intended. This is why I should really read the FAQs when upgrading.

Tags