P'unk Avenue Window

Archive for September, 2009

sfSyncContentPlugin: moving content without pain

September 29th, 2009 by Tom No Comments

Use the source, Luke!

Lorem Ipsum is fun and all, but there’s nothing quite like real content when you need to duplicate a problem that a client is experiencing with their website.

(Not that our websites ever have problems! That could never, ever happen! But let’s just say it did.)

Frameworks like Symfony include handy features to deploy new code to a staging or production site. Specifically, the project:deploy task, which is a simple wrapper around rsync that gets the job done.

This is a great thing. But what about the other half of the equation- deploying content… or pulling the production site’s content back down to your own box for some seriously realistic testing?

This is where sfSyncContentPlugin comes into the picture. With this handy plugin, you can just type this:

./symfony project:sync-content frontend dev from staging@staging

… And down comes the content from the staging server, beginning with the current state of the database and optionally followed by data folders, such as your uploads folder, search indexes and other data kept in the filesystem rather than the database.

You can also push content in the other direction. For instance, the day you launch the production site, you might do this to push content from staging up to production:

./symfony project:sync-content frontend staging to prod@production

(The seemingly redundant business with the ‘@’ signs is there because Symfony distinguishes environments from servers. In practice ours tend to be the same, but your setup may vary.)

sfSyncContentPlugin isn’t for every Symfony developer… just the 95% of you who use MySQL and, for now at least, only have one database in your project that should be synced. But as I said, that’s the vast majority of Symfony projects. So we suspect this plugin will be as useful to others as it has been to us. We welcome code contributions intended to accommodate other databases, sites with multiple databases and so on.

You can pick up sfSyncContentPlugin here.



A quick aside to hardcore Symfony developers: we’ve been using this plugin internally for quite some time, but it was a bit of a hack until recently. Our code was parsing config/databases.yml manually, struggling to duplicate what Symfony already does. Fortunately I recently discovered the sfDatabaseManager class, which fetches everything you need to know about the database in exactly the same way Symfony does, because it is Symfony. I recommend using it in any similar tasks you might be writing. Take a look at our source to see how it’s put to work, in particular the sfSyncContentTools class.

Developer, Developer, Developer

September 28th, 2009 by Geoff No Comments

developer

We have not yet hired for the project manager/information architect/content strategist position, but we have an immediate need to add another developer to our team…

P’unk Avenue is a web design and development team located in Philadelphia that creates websites and applications for higher education and business clients. We are also the creators of an open source CMS, Apostrophe, built on top of the Symfony framework.

We are five people looking for another Symfony developer to add to the team. Since we are a small team we all get involved in various aspects of each project. We believe that is a good thing and are looking for someone that enjoys being engaged in a project on many levels.

Our ideal candidate has the following experience/interests:

  • At least 3 years working with PHP (including PHP 5 and object oriented programming), or 2 years experience with Ruby and at least one year with PHP 5
  • 1+ year developing in the Symfony framework
  • Using other frameworks such as Zend Framework, CakePHP, jQuery and Ruby on Rails
  • Working knowledge of ORMs such as Doctrine and Propel
  • Building and calling web services (REST & SOAP)
  • Prototyping and releasing on a frequent iteration schedule
  • Using or contributing to open source projects
  • A passion for using Test Driven Development to write tight well tested code
  • A love for collaborating with a small team to solve problems
  • A great sense of humor and an ability to stay cool under pressure

This job does require you to work out of our Philadelphia studio. We have great flexibility in other areas, but we believe that having our team in the same location on a regular basis benefits the websites and products that we create.

Of note, we organize various community events like the Junto and Ignite Philly. We are very interested in engaging in and encouraging deeper conversations about stimulating ideas. The type of person that is also stimulated by thinking and acting on issues they care about would be a good fit on our team. It is not required, but the opportunity to help organize these events is a possibility for any member of our team.

If you feel that you are a good fit, please send resumes and whatever other documentation that you think best represents why we should consider you to: jobs@punkave.com.

A better strip_tags: pkHtml::simplify

September 21st, 2009 by Tom No Comments

Many web sites allow users to edit content via a rich text editor. And we all know what happens if the user pastes a Word document in there: the styles of the page wind up hopelessly munged. PHP coders can use strip_tags() to limit the HTML tags that get pasted in, but that doesn’t clean up the CSS style attributes that can be pasted in. So your page is still a mess. Often it is so broken that the user can’t figure out how to edit again. This is the point where they pick up the phone and plead with you for help.

strip_tags also won’t help if the HTML is invalid. Unclosed tags can create nightmares elsewhere in the page when users are allowed to submit snippets of HTML that leave a bold tag or a header tag unclosed.

A common workaround is to use the FCK (aka CK) rich text editor’s “paste as plaintext” mode, which thwarts attempts to paste rich text from another program. That works, after a fashion, but users are forced to do all of their styling all over again. Bold, italic and bulleted lists must be recreated from scratch.

And none of the workarounds are sufficient if you can’t at least trust the intentions of your users. This is not a problem when your client logs in to update his site, but it’s a big issue when his customers are creating personal profiles and the like.

HTML Tidy can tackle this sort of filtering for you, but it is often not included in your build of PHP as it is not standard equipment (although some Linux distributions do include it in the box). This is especially important on client sites where you’ve been asked to live with the setup that is available.

HTML Purifier does much the same thing in pure PHP, but since it parses the document directly in PHP it is a bit slow and heavy. Which makes you long for the raw performance of strip_tags.

Enter pkHtml::simplify():

pkHtml::simplify($richTextHTML,
  "<h3><h4><h5><h6><blockquote><p><a><ul><ol><nl><li><b><i>" .
  "<strong><em><strike><code><hr><br><div>" .
  "<table><thead><caption><tbody><tr><th><td>");

If that looks a lot like the arguments to strip_tags(), you’re right. That’s because pkHtml::simplify() uses strip_tags() as a starting point. But pkHtml::simplify() follows up strip_tags() with a DOMDocument-based filter that removes attributes too, except for the attributes that actually make sense to permit for certain tags. That is, if you are permitting the tag at all, you need those attributes for it to be useful.

Currently these tags are:

A tag -> href and name attributes
img tag -> src attribute

If you’re coding for Symfony, you don’t have to call pkHtml::simplify() directly. Instead, you can use the sfValidatorHtml validator, also found in pkToolkit, which allows the above list of tags by default because they are well-suited to user-entered content. For the convenience of Symfony developers we also package Dominic Schierlinck’s sfWidgetFormRichTextarea widget in pkToolkit. It’s meant to be compatible with both MCE and FCK, although we always use FCK.

pkHtml::simplify is short and sweet because it uses the most straightforward tool for each job. For removing disallowed tags, nothing beats the raw speed of strip_tags. But strip_tags doesn’t know anything about attributes, so for that purpose we use DOMDocument. Many PHP developers aren’t yet familiar with this class, which is standard equipment in PHP 5.

DOMDocument has three great features from our perspective: it can clean up HTML automatically, ensuring that tags are closed. And it lets you manipulate attributes painlessly. And since it is built into the core of PHP, it is much faster than parsing HTML “from scratch” in PHP.

DOMDocument does want to give you back a complete HTML document with nifty things like a document type and html, head and body elements that we don’t need when we’re manipulating snippets of user-entered HTML, not truly complete pages. So pkHtml::simplify optionally undoes that for you, leaving you with an HTML container element that’s ready to snick into place in the middle of your page body.

So: how good is the performance of pkHtml::simplify? Very good indeed. On one project we need to separately clean hundreds of untrusted potential HTML containers in a single XML document, in real time, before presenting portions of that information to the user. pkHtml::simplify has no trouble keeping up in this scenario.

Our Apostrophe CMS takes advantage of pkHtml::simplify() to allow rich text editing without the constant “oops I screwed up my site” issues that come up without a robust server-side filter.

pkToolkitPlugin is available from the Symfony repository and is released under the open-source MIT license. Keep in mind that the pkHtml class is useful to all PHP developers, not just Symfony developers. Just download the tarball and copy it from the lib folder.

I recommend picking up the latest version of the code from svn. You can also use the tarball versions, but you may need to remove a few Symfony logging calls to use it in a non-Symfony context.

Be a P’unk

September 18th, 2009 by Geoff 1 Comment

project-manager

We are hiring!

If you would like to join our team and you think you would be a good fit, we want to hear from you…

Information Architect / Content Strategist / Project Manager

P’unk Avenue is a web design and development team located in Philadelphia that creates websites and applications for higher education and business clients. We are also the creators of an open source CMS, Apostrophe, built on top of the Symfony web framework.

We are a 5 person team looking to add a person with a blend of project management, content strategy, and information architect skills to the mix. You do not have to be experienced in all 3 areas, but a good amount of experience in one area is highly desirable.

Since we are a small team, we all get involved in various aspects of each project. We believe that is a good thing. We are looking for someone that enjoys being engaged in a project on many levels.

An ideal candidate would:

  • Love problem-solving
  • Be excellent at communicating
  • Have a documented ability to project manage, do content strategy and/or information architecture
  • Have a great sense of humor and an ability to stay cool under pressure
  • Have a real love for people

This job does require you to work out of our Philadelphia studio. We have great flexibility in other areas, but we believe that having our team in the same location on a regular basis benefits the websites and products that we create.

Of note, we organize various community events like the Junto and Ignite Philly. We are very interested in engaging in and encouraging deeper conversations about stimulating ideas. The type of person that is also stimulated by thinking and acting on issues they care about would be a good fit for us. It is not required, but if you are interested we would welcome your help with these events and others like it.

If you want to join the team, please send whatever documentation that you think best represents why we should consider you to: jobs@punkave.com.