:: Archive for the 'PHP' Category ::

Scriptaculous Lists with PHP

Posted on August 16th, 2005 in PHP, Web Development by Greg

Scriptaculous is one of many great new JavaScript libraries created to answer the call for well written ‘Web 2.0’ JavaScript libraries. Written by Thomas Fuchs, scriptaculous has many features that can be used in AJAX-ified applications, drag-and-drop effects, and a whole slew of visual effects. The drag-and-drop effects, most notably the sortables, caught my eye because the look great, they are so easy to implement, and they’re just so much nicer than the standard listbox with up/down arrows that we see in most of today’s applications and administration tools.

SLLists – a PHP wrapper around scriptaculous sortables

So scriptaculous lists are really easy to use and implement…so why put together a PHP script to wrap around it all? I did this for a couple reasons (no the following list isn’t sortable!):

  • It isn’t very obvious from scriptaculous (or other similar drag-and-drop sorting libraries) how sortables can actually be used in a real application
    to perform a useful function.
  • I wanted a simple way to serialize the result of all this snazzy ordering into a simple PHP array with which I could update a database
  • Many people are just plain scared of JavaScript and don’t know what to do with it – I’m one of these folks too!
  • PHP is fun.

The resulting PHP class is a very simple class that makes it easy – with a couple lines of code to get a sortable list (or sortable just about anything) onto a page and to translate the result into a PHP array. I’ll be the first to admit that there’s no real innovation here – just trying to make an already easy to use JavaScript library easier to use for the JavaScript-scared people out there. I’ve got no documentation except for a sample page…so here’s a brief rundown of the class functions:

  • SLLists – constructor that basically sets the path to the JavaScript files
  • addList – adds a list or other element as a new sortable entity
  • printTopJS – prints the JavaScript into the head of a PHP file
  • printForm – prints an HTML form that contains the hidden inputs needed. Alternatively users can create their own forms or use the printHiddenInputs functions to put these hidden inputs in existing forms
  • printBottomJS – prints the JavaScript that should go right before the closing body tag
  • getOrderArray – returns an array with items and their order after being passed an input with the serialzed scriptaculous list

Download Version 0.01 of the class (and a sample page) to get started – no JavaScript needed!

For the full info, head to the SLLists page. The page has examples and shows what scriptaculous can do. And leave some comments here if you like it or have any comments…


gCards 1.44 Released…And the Abbreviated History of Greg and PHP

Posted on April 16th, 2005 in gCards, PHP by Greg

I just posted up a new release of gCards, the PHP ecard script I wrote about a year and a half ago. I haven’t done a good job at all of fixing bugs over the last year and I have all but stopped reading the forums, but the application – aside from the major news bug (which was actually a small fix) – is very stable now.

I started gCards as a project to learn how to write a PHP app. I wanted to have some background in programming – I work at an enterprise software company as a product manager. In this job I spend about half of my time working directly with engineers. I thought it would be useful to get a better understanding of the issues of design and implementation of software. I bought a PHP book and started reading it, but I quickly got bored running through the chapters and decided it would be better to make a little project for myself that would give me exposure to a wide variety of aspects of PHP programming. I decided on an ecard application because:

  • I like photography and I had a very lame ecard page up on my site – I forget now which script I was using
  • An ecard script would need to involve the following technologies
    • Database to store the card information and the sent cards
    • Image resizing to create thumbnails
    • Security to prevent public access to the admin interface
    • Dynamic front-end pulling information from the database
    • Creating and sending dynamic emails
  • It was more fun the reading through the book

So I started working on it and quickly had something up quickly. I had used a couple scripts which I had found on hotscripts so I figured it would only be fair to post my completed effort on the site for others to use. I never really expected people to download it and use it. In the first couple days, several hundred people downloaded the application. It was very rough around the edges and many people reported bugs which I dutifly fixed, all the while learning how to write a PHP app.

In addition to bugs, people were asking about features. My goal had been to create a simple and dynamic PHP script for my website, so I tried to stick with that goal – I only wanted to implement features that made sense for me and that would keep the script simple. So I added things like WYSWIG (first HTMLArea then FCKeditor) editors for writing. A couple other things I didn’t need for my site I decided to add – one example was internationalization – gCards has been translated into more than 20 languages.

Since I first created gCards, I have created several other applications:

  • A enhancement database, customer database, and several other internal applications for Selectica, the enterprise software company I work for
  • The backed for both the intranet and website of Selectica
  • A website for my friend Michael’s band, Boys on Trial
  • A website for Kiesandahl and Calhoun, a fine art gallery in New York
  • A document / file management application
  • A blog for my brother, that I used at his site
  • Mailing list management for my mom’s company, Redstone Studios

Over the course of this work, my skillz have increased quite a bit, and now I find it difficult to wade through the hackish code that gCards is comprised of. It works, but it isn’t a very nice application from the code perspective. PHP, HTML, and SQL are intermixed with no separation between data and logic. If I wrote the same application now it would be OOP and it customization of the user interface would be a much cleaner thing. I don’t have enough time to rewrite it…between work, travel, and entertaining my girlfriend…I don’t have much time for gCards.

I think that the most important reason for the (relative) success of gCards was it’s ease of use. Too much open source software is difficult to install, use, or understand. It’s not the most beautiful application, but it’s much better than most of the competition. As a product manager at my company it is my job to design usable software that accomplishes its goals. That’s what I tried to do with gCards. So despite it’s hackish origins and it’s moderately ugly looking code, I think gCards was redeemed by it’s ‘keeping it simple’ approach. I hope people like using it, and I plan to continue to fix bugs whenever I have the time…but that time is few and far between.

The beauty of open source software, of course, is that the source is out there for everyone to see. So if there’s something you want to add, or a fix that you think needs fixing…..fix away!

Thanks for reading this completely incomprehensible post!

WordPress – the great and the not so great

Posted on April 14th, 2005 in PHP, WordPress by Greg

When I first stumbled across WordPress (which I’m using to power my website), I was very pleasantly surprised by the excellent administration environment, and just how easy it was to setup and use. Before I even decided what tool I was going to use for my website, I had come up with a basic design and color scheme that I was going to use. I managed to stay pretty close to what I wanted, but there were several things that made it a bit trickier than expected.

In order to get my custom ‘skin’ for WordPress I needed to create a theme – this is pretty easy as a theme is really only composed of a few pages. The template tags used to create a theme are relatively straightforward and I was able to get something up and running very quickly. The difficulty is that the template tags are aimed at very novice users, which means that they hide a lot of complexity. And while hiding complexity is often great, it also means added complexity when you try to do something that is a little outside of the feature set.

For example, WordPress has a feature called ‘Pages’ where you can create regular posts that act more like static pages and aren’t blog-like. In addition to not sitting within the standard blog flow, pages can have child pages so you can build a hierarchy of pages. An example of ‘Pages’ on my site is the ‘About‘ page you can see linked on the left. If I wanted to I could write a sub-page called About Me with sub-pages for My Education, My Resume, and My Hobbies. Now I don’t really have anything on this page, so I guess I’m giving a bad example – but you’re smart, you can imagine it.

While it was possible to create a hierarchy of pages, the only place to show it was really in the navigation bar on the left. Obviously this isn’t acceptable if you have several levels of nesting – the left column isn’t big enough. You can limit the ‘depth’ of the tree, but then the lower levels aren’t shown anywhere, and a page that no one can get to just isn’t too useful. I wanted two additional things:

  1. To show a breadcrumb under the page name which would have links to all of the parent pages
  2. To show a list of child pages

I understand that Pages were only introduced in the current release of WordPress, but these seem like two very obvious requests. The unfortunate thing with doing these is that the API provided by WordPress is so targetted at its own templating that it requires a developer to talk directly to the database to get data. Most of the template tags return data with HTML embedded, so if you want to use the data for another purpose they become useless. Using the WordPress plugin functionality I was able to write a class which augmented the standard Pages feature set with some useful functions.

I understand that the template functions return HTML to simplify things for the user, but it would be great if there were some lower-level functions which returned information as data (i.e. returning an array of child pages) so that the user can choose what to do with them. So while it might be easier to write:

1
get_child_pages($id)

I would personally rather write:

1
2
3
4
$children = $page->getChildren();
foreach ($children as $child) {
      //  do something
}

I think that this actually ends up being more readable because it’s not as spooky – you can see exactly how the data is being rendered on the page, and if you need to make a change to it you can do it write on the template instead of changing the source code of the API.

But….overall I’m very happy with using WordPress and how flexible the system is. I wish the team continued success with the project!

New Site Design

Posted on April 12th, 2005 in Site Updates, WordPress by Greg

After a couple years with the same front page for my website I got a little bored with it…so I decided to switch it up a little bit and change around the format of my site. I thought it might be fun to do a bit of writing on the site, so I did some quick searching for a ‘blog’ or ‘content management’ solution and my final choice was WordPress.

I threw together a quick WordPress theme, augmented the “pages” feature with some missing functionality via a plugin, and ftp’d the thing up. Pretty easy. More details later on my thoughts about WordPress, it’s themes, and ease of use.

I’m hoping to put a wide variety of writing up here…as an outlet for my tech dorkiness, musical thoughts, ramblings, photography, and other things that no one will read. If a real person is actually reading this – add a comment and say hi.

Hope to write soon.

– Greg