08 Feb 2010

Search on

As always, the Super Bowl is host to many great and memorable commercials. This year was the first to feature a Google commercial (not that Google really needs a commercial) and I was pleased to see how simply perfect it was. It got me to thinking about the philosophies between the two companies who are battling for the ‘best search engine’ – Google and Microsoft.

Microsoft has always been – at least to me – a company who forcefully crams its way into lives. Whether it’s preinstalling Internet Explorer during Windows installations or shoving numerous bing commercials down our throats, Microsoft is just over the top with everything. Bloated operating systems and bloated commercials.

You ever heard the saying, “Jack of all trades, Master of none”? Well, this is Microsoft. They try to be everything to everyone – operating systems, gaming consoles, mp3 players, computer hardware, search engines, and who knows what else. How many of these flop? Nearly all of them. I think maybe the Xbox was their biggest success (at least in my book). And I’ll admit, Windows 7 ain’t bad. It sure took them long enough though.

Google is the best search engine because it’s simply that – a search engine. Now, granted Google does other projects too, but at least they all rally among a common theme – search. Google doesn’t need a “pretty” homepage to extend quality to the user. Google does just fine using the bare minimum (which I admire). Microsoft is the opposite… gradients, shininess, superfluous crap… I don’t need my OS to look pretty, nor do I need my search engine to look pretty. What I do need is for my OS and my search engine to work well and work efficiently.

Take a look at these commercials:

Microsoft Bing
http://www.youtube.com/watch?v=ZSkaTcjDIMk

Google
http://www.youtube.com/watch?v=jH5RRLgqzmI

Google and Bing are both search engines, yet it feels to me that Bing tries too hard. Google’s search engine is to the point. It’s simple. You can only do one thing and that one thing is search. And, you can search for the same stuff that you could search for on Bing (Google is even a calculator) – all from a well-dressed, simple, usable homepage. And how is Bing gonna go on about “search overload” when the entire point of search engines is to search? Lame.

Contrary to popular belief, people don’t really “surf” the web anymore. The web is a tool. We use it to accomplish tasks and goals. If we go to Google (or Bing if you prefer) we’re there to search for something, not sit and stare at (and get distracted by) pretty background images.

And as The Washington Post mentions, “Amid dozens of ads focused on cars, beer, and busty women, the Google spot definitely took a different approach: it tells a love story through a series of search queries.” Beautiful. Perfect. Simple.

Whatever search engine you choose I hope you find what you’re searching for efficiently and quickly. In the end that’s what it’s all about. I, however, will be searching with Google. Because it looks pretty.

Search on.

04 Nov 2009

Request for help with some PHP logic…

I realize this post is atypical, but unfortunately Twitter only allows 140 characters – not nearly enough to even begin asking for help.

I’m working on a web application that searches vendor listings within the users zip code. Nevermind how the zip code class works, but I’m stuck on a looping issue. Basically, it works like this:

  • Users enter a search term (they search services and offerings of vendors)
  • The script searches for all vendors with that search term…
  • then searches a ginormous database of every zip code listing in the US for every zip code within the users zip radius
  • If a vendor’s zip matches that of one of the found zips, it lists the vendor listing

And all this works perfectly. What I’m having trouble with though is exiting the loop if no vendors are found. Currently it just doesn’t show anything, but I want it to say something like “No vendors within you zip code radius,” I just don’t know where to put that condition in the multiple loops.

View the code snippet at Pastebin
http://pastebin.com/f53b44de5

Thanks in advance for any help.

23 Jul 2009

Accessing the Joomla! framework from outside Joomla!

A while back we got a client that wanted their website redesigned in Joomla, a content management system based on components, modules, and plugins. Having never used Joomla before I was a little intimidated but ready for the challenge and eager to learn something new. Coding the templates was pretty straight-forward – write your HTML, drop in a few Joomla tags, and bam, you’re all set. Sorta anyways.

The client wanted a ton of customizations. “Can we have this? And this? Oh and this?” All the while nearing the boundaries of what Joomla is capable of. Don’t get me wrong, Joomla is a really powerful tool. The problem with Joomla is that you have to remain within the Joomla framework to access Joomla’s content and databases, limiting the number of external applications you can make that integrate with the system. That is, until today (for me at least).

I spent three months researching ways to gain access to the Joomla database from outside the Joomla framework. I read through countless forum threads for an iota of advice, only to find the thread dropping off after the tough question was posed. I decided rather than to search specifically for ways on accessing the database, I’d break it down into smaller chunks, such as, “how does joomla access database”. I broke the larger problem into smaller problems that would turn over more results.

Using these answers and my knowledge of PHP, I was able to finally figure out a way in. Since this was such a pain in the arse for me, I figured I’d share my research with anyone else who might be interested, or who might be curious as to how to do this.

In this case, our client wanted a queue for users who’ve submitted registrations for the members area. They wanted an application that would kind of hold registered users in an “in-between” place and choose when to accept or decline their memberships. In addition to this, they wanted specific emails to be sent to the registrants and to administrators with details… basically more stuff than Joomla would include. Plus, I always prefer to do things from scratch because I know exactly what each piece does and I enjoy having that detailed control. It’s cleaner and it keeps me sane. And I don’t have to go sifting through help files or tutorials trying to find out what John Doe did in his custom component.

In jest, here’s what I’ve done: Users arrive at the website and wish to access materials behind the members section. Without login credentials all they can do is register for an account. Said user fills out a fairly detailed form (including more information than Joomla would ask), and submits the form. Rather than storing the details for the user account in Joomlas database (and thereby creating a logged in user) it goes into a queue database and an email is sent to both the administrators and the registrant. The administrators can access a secure page, custom for this application, and see a tabled list of all those registrants in the queue. There, they can approve or decline the registration. Once approved, the application writes the information to Joomlas database tables and establishes a new user account. An email is sent to the new user and all is well.

First, you need to know PHP (obviously). Joomla is tightly knit together with many, many individual files that come together to form what’s called the framework. Take out one file and the whole thing ceases to function properly. Since I didn’t know Joomla that well, I opted not to write a custom component, module, or plugin, rather utilize the skills I do know and write a program from scratch. Regardless of whether you’d prefer to write a component for Joomla or a custom application, this should benefit you.

Secondly, you’ll need to know how Joomla access and stores data in its database. In our case, we’re creating users and, instead of using a single database table to store user information, it uses three. Why, I have no idea. Those three tables are:

jos_users
jos_core_acl_aro
jos_core_acl_groups_aro_map

Furthermore, if you don’t insert the information correctly, it won’t work. I discovered that you have to not only write to the tables in that order, but you must use elements from each to create entries on the next. I made a chart today to prevent a big headache.

Untitled-1
Chart illustrating the three Joomla user tables and how they’re connected.

As you can see, the ID from the new row on `jos_users` becomes the value on `jos_core_acl_aro`. You get the idea for the others. Keep in mind these fields are “auto-increment” so they’ll be generated automatically. Just make sure they match up.

Next up, the password. Joomla does some serious encryption and I’m not talking about standard md5 encryption, this system ensures your password is safe and secure. Check this out…

The function:

$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword("blabla", $salt);
$password = $crypt . ':' . $salt;

What does this mean? Well, in short…
1. User chooses a password of “blabla” (as an example).
2. Joomla generates a random string of 32 characters (asdf84rahsljdhf34jahdfhas97dfjah… or something similiar)…
3. Then proceeds to md5 hash the above string…
4. It then encrypts the user’s password (blabla) with md5 hash…
5. Then combines the two with a color colon in between.

What you get looks something like this:

758asefouahseo57asohefoas76e59aysp9r:984awozisjdfoiasjfdas8fdjw84jq38

How’s that for a password, eh?

Okay, back on topic. Once you get all of the user information collected and the password generated, you’re ready for your insert queries. Lucky you, I’ve written them all, so it’s just a matter of adapting what I’ve got to your code. Those of you familiar with PHP will know that words preceded by a $ are variables collected from the form you wrote which brings in the responses from the user. The PHP function “last_insert_id()” will return the last auto-incremented id from the previous insert. This is very important.


insert into `jos_users` (`id`,`name`,`username`,`email`,`password`,`usertype`,`block`,`sendEmail`,`gid`,`registerDate`,`lastvisitDate`) values (NULL,'$name','$username','$email','$insPassword','Registered','0','0','18','0000-00-00 00:00:00','0000-00-00 00:00:00')"


insert into `jos_core_acl_aro` values (NULL, 'users', last_insert_id(), 0, 'Registered', 0)


insert into `jos_core_acl_groups_aro_map` values (18, '', last_insert_id())

You’ll want to do some research as to what the specific variables are. In this case, I’m inserting normal lowest-level users. They are assigned “Registered” which corresponds with ‘18′ in the user groups table. “$isnPassword” is the salted password we generated above. Once you do all this correctly, you should have your new user appear in the Joomla User Manager tool.