When does a web developer not care about what browser you use?

January 19th, 2010

When shit that I want to create doesn’t work on your browser, that’s when.

I’m learning about the Document Object Model so that I can build killer web applications. Unfortunately, different browsers will read my code differently, and in many cases, throw massive coronary errors and refuse to work.

If you use Netscape Navigator, Internet Explorer <= 6, or any other browser that does not support the traditional event registration model, you’re shit out of luck. This allows me to at least get my web app off the ground before I start worrying about everyone and their mom that uses IE6 going to the site and having it not work. I’ll get it off the ground, then pay someone else to make it work in other crap. In the mean time, when someone goes to the site, they’ll see a blank page with links to browsers that work.

Just learning how to manipulate the Document Object Model with Javascript.

January 19th, 2010

Event Listeners own me.

I’ve been DEATHLY scared of these damn things my entire professional career. Finally, last night, in an attempt to create my first full-on javascript / php / mysql / ajax / blablabla some other web technology, I started to come to terms with the fact that yes, I need to learn it if I want to create some truly awesome web apps.

I’ve “used” them before. Usually, this entails going to someone else’s site that had what I needed to accomplish already completed and there for the download / copy / paste. However, with this new project that’s consuming my mind, I need to learn them. I need to make 100% unique javascript functions in order to accomplish my goals. I think that as I learn this stuff I’ll post here, but most likely I’ll just post some strings of code with a post titled “EUREKA!”

Migrating to Wordpress for a blog

January 19th, 2010

I’ve decided that since CMS Made Simple doesn’t have any of the automatic pinging capabilities that Wordpress does that I should migrate over and continue blogging from it instead. I’ve transferred most of my posts over, but not all because those that actually could be wanted by someone are ~10, and the rest is just crap. I feel that part of my professional growth is going to be creating a journal of successes(what few I have), failures(what many I have), trials(shitloads of them), and tribulations(whatever these are).

Moving forward with a good platform is key; I’m going to continue to develop sites with CMSMS but I’m not going to be using it myself on this site. Wordpress development is something I’ve been meaning to get in to for a while as well though, so maybe actually having a site to do it on will spur action on my part.

Removing spaces from text in Excel

January 19th, 2010

I’ve been meaning to come up with a way to create an Excel library for tasks I do very often; I suppose this will be a good place to start it and update it.

The TRIM function removes spaces from the right and left sides of whatever text you’re processing, like so:

Formula:

=TRIM(A1)

” Hello ” will process to: “Hello”

However, if you want to remove spaces from within a text cell, leaving all other characters / numbers / etc., you need to use the SUBSTITUTE function for simple cases.

Formula

=SUBSTITUTE(A1," ","")

” Hello Thar ” will process to “HelloThar”

First in what will probably be a lot of posts about Excel stuff. I use it WAY too often for text processing.

Use Excel to generate a whole crapload of SQL queries

January 19th, 2010

I had to update a whole lot of rows, and instead of sitting down and doing some ridiculous export and re-update, I figured I’d just write an SQL query in an Excel Concatenate statement and use the ids in the spreadsheet. WAH LA

First 2 columns are A : the id and B : the value I want to replace.

In column C, I put:

=CONCATENATE("UPDATE tablename SET fieldname='",B1,"' WHERE idfield=",A1,";")

Then, just copy and paste that cell all the way down, copy the queries, and paste them into a phpMyAdmin SQL text box and run.

Integrating Calendar and Google Maps in CMSMS

January 19th, 2010

I recently had to do a website for a family friend who’s getting married. They were having a destination wedding, and one of the things they wanted to do on the site was have calendar items below a Google Map, with the addresses associated with the events reflected on the map.

I could have had it be a little redundant, but this is the sort of puzzle I like figuring out, so I set to work.

I use CMS Made Simple for most of the sites I do for folks nowadays, because it’s open source and excellently put together.

I installed Calguy’s Calendar and Google Maps modules, and set to work. I created an upcoming list template to display all the events; pretty easy.

One of the field definitions on the Calendar module was “Address” so that they could put in the event’s location. This would come in handy for my map points!

Next was getting the map set up. After setting up the module with the API key for Google Maps, I created an new map and added a central map point. (the map won’t display without one, something I didn’t realize at first)

The Google Maps module includes a plugin for creating dynamic map points on the fly. I created another upcoming list template in the calendar module to automatically create these map points dynamically. Sample code below. I had to use the smarty “assign” function to get them to work correctly; don’t ask me why.


{foreach from=$events key=key item=event}
{assign var=event_title value=$event.event_title}
{assign var=event_date value=$event.event_date_start|date_format:"%e"}
{assign var=event_summary value=$event.event_summary}
{assign var=event_address value=$event.fields.Address}

{cggm_add_dynpoint map=1 name="$event_title" address="$event_address" description="$event_summary"}
{/foreach}

This way, any new calendar item they created would be created on the map!

Note: when you add any code or dynamic points, make sure to add them below wherever you create the map! Otherwise they don’t show up!

Creating a Document Management System with CMS Made Simple and some modules

January 19th, 2010

So I had to create a system where users could register, login, and upload files. The system would need to show each user his/her files and no one else’s, and get in touch with the administrator to let them know a new file was uploaded.

There’s nothing inherent in CMS Made Simple to accomplish this, but I used a couple of modules (FrontEndUsers, SelfRegistration, CustomContent, and Uploads) to take care of the job. It’s easy enough that I know the developer meant it to be used this way if someone needed it. I’m not going to explain SelfRegistration here, that’s for another post. However, here’s the instructions for the Document Manager:

  1. Install FrontEndUsers, SelfRegistration, CustomContent, and Uploads (Front End File Management)
  2. Add 2 pages to the site. Call one “Document Manager” and the other “Send a File”
  3. In FrontEndUsers, create the User Properties you’ll need for your registered users.
  4. Create the User’s Group.
  5. Put the “Document Manager” and “Send a File” pages behind a login using FEU
  6. In Uploads, create the Category “Client Uploads.”
  7. In the Page “Document Manager,” insert the code below:

    {assign var=email value=$ccuser->username()}
    {cms_module module="Uploads" category="Client Uploads" mode="summary" key=$email}

    For some reason, I always have better luck assigning any Smarty object variable to a regular variable before using it in another tag. Might be me, I dunno.

  8. In the Page “Send a File,” insert the code below:

    {assign var=email value=$ccuser->username()}
    {cms_module module="Uploads" category="Client Uploads" mode="upload" noauthor="1" key=$email}

    Using the Key attribute for the Uploads module tag in both places inserts whatever file into the database with the key equal to the user’s username, and then allows me to pull it out by the same.

  9. Pretty much done; make it look pretty with some CSS and you should be all set.

Users can register, login, and upload files. They only see their files, and the administrator can log into the backend and manage them there. Mission accomplished.

Front End User Photo Galleries

January 19th, 2010

This was somewhat quick and dirty. However, it works very well for what I need and if anyone else would like to use it, go for it.

I had a need for a way to enable an administrator to manage photo galleries on a per-user basis. I figured that the best thing to do would be to make some sort of connector between Photo Album and FrontEndUsers, but I wasn’t quite sure that was possible, and also whether or not I could pull it off regardless. So, instead I edited FrontEndUsers, and Copied and created a new Module from Photo Albums and called it FEUAlbum. Neither of these modules will be supported by me, (unless there’s money involved) and I don’t expect to extend them beyond what I’ve done. Obviously the original authors of the modules are not going to support an edited version of their module.

Those disclaimers aside, here we go.

Vanilla installation of CustomContent is used.

In FrontEndUsers, I created a new “field type” in the User Properties called “Album.” Adding this to a group will make a link appear when you edit a user. Clicking the link, if the user has no photo album at the moment, will create the photo album using the user’s FEU id as the album id, and the user’s username as the album name. If the user has a current album created already, this link will take the administrator to it to manage it.

Copying Album to a new module was easy. Installing FEUAlbum will NOT overwrite anything from the original module (Album) and both can run side-by-side. New database tables were created throughout and the links to files are correct. All other functionality, including templates, works as expected.

Insert the module tag in the template or page like so:

{cms_module module="FEUAlbum" albums=$ccuser->LoggedIn()}

Calls the module and uses the user’s ID as the album number, which pulls in the relevant album. Obviously the user should be required to log in before access to the album is allowed.

The goal was to do the least amount of work and get the greatest functionality out of it. One caveat is that each user can only have 1 album assigned to them.

I hope this helps someone out; I’ve attached zip files for the edited modules.

If the mysql server hangs with the State “Copying to tmp table”

January 19th, 2010

This one took me a WHILE to figure out. The damn server would start hanging, and websites would not be displayed when using a particular table.

I started by restarting the mysql service once a day. Finally, obviously, I got sick of having to do that (even on the beach one weekend) so I buckled down and got to figuring out what the hell was wrong with my server. I started by shelling in to the server, and running SHOW PROCESSLIST time after time, every 5 seconds. This got old fast. I found and installed Navicat for MySQL, a great monitoring program.

I found that a custom search done on a products table was giving me the MySQL State “Copying to tmp table” and not releasing the process. This would hang that table, allowing some things to be served, but nothing having to do with this table.

The MySQL dev forum had a thread a mile long regarding the topic, I dredged it for days, trying all the suggestions. I tried tweaking the server, I tried screwing around with the mysql user’s ulimits, etc. Nothing worked.

Finally, a solution presented itself. The tables involved in the query were “over-indexed.” It was the simplest thing to remove a few columns from the index and all of a sudden I was done. I am now 48 hours and the server is running flawlessly. Also, since I did some serious tweaking, it’s running even leaner than I originally had it.

Amazing something so simple caused such a big problem, but there you have it.

The challenges with “social news”

January 13th, 2010

I’m a fan of social media, but one thing that aggravates me sometimes is the idiocy of the content out there.

  • A poor lost cow was found; won’t you adopt him?
  • Barack Obama Barack Obama Barack Obama
  • Drinking out of cups

The same affliction absolutely affects social news sites as well, and is one of the reasons I took up reading the Wall Street Journal.

Digg’s site title is the following: “The Latest News Headlines, Videos and Images.” Unfortunately, the “News Headlines” portion of that title does not explain the fact that the “News Headlines” on the site are driven socially and therefore subject to the whims of the mob. When the mob votes on what it deems popular, the result is no longer “News.” News, as defined at Wikipedia, is “the communication of information on current events” using various broadcasting avenues. What happens at Digg is very different. Funny images, celebrity gossip, duplicate stories, and severely leaned (one way or another) political rants abound. These are not news stories. They are fun, and can be a nice distraction during a lunch break or in the evening, but it’s not news.

News is thoroughly investigated, expertly and concisely written, and presented with no propaganda goals.

At least Reddit doesn’t make any pretenses at being a news site; their site title is “what’s new online!” which describes exactly what you can find on their site.

Letting the mob at your content is tough; you could be praised one day, and thrown down the next. Journalists (reporters and investigators of real News) need to have thick skins; they could write a story that is 100% fact and still get hate mail from people that disagree with the truth. For having the sort of integrity to do that gets my total respect, and I think it’s a sad thing that newspapers are shutting their doors because of the free (and more fun) alternative of finding a new picture of a cat “hazing” a “cheezburger.”