WTTGG #3

I almost forgot for this week, but found some stuff today, so here goes….

And a small disclaimer, or explanation first. Instead of just making this a list of cool stuff out there, I’m going to try to tie it into the field of history or academia. That will get me to think a bit more and hopefully stay true to my desires to have this blog about history and new media.

So… First off we have a couple of gadgets, of the software kind:

paintbrush
Gadget #1: Paintbrush. [Mac only] Have you ever wanted to just make a quick drawing or picture in Mac. It’s not that easy without Paintbrush. It gives Mac users a semblance of Microsoft Paint. Now, what’s the application to history, et al.? Ummm… I don’t know either. I’ll get a strike for this one…

skitch
Gadget #2: Skitch.com This is a new service that allows you to quickly take an image and annotate, draw, and share. You can grab photos from your iPhoto library, take screen shots, or import images. When you’re done drawing and such, you can upload it to your own account on skitch.com and share your photos. Check out my test photo at http://skitch.com/mossiso/ This might come in handy as another way for historians to share photos and their ideas. A teacher could upload some images and draw specific things… yeah, it’s a stretch too.

Tip #1: US National Archives Research Online and the US Holocaust Memorial Museum. OK, OK, here’s a real tip for the historians. I’ve been looking for some information on the “Quarz” project started by the Nazis in late 1944. There is supposedly some photos at the National Archives, but I haven’t found them yet. I was tipped off to this topic by a friend and co-PhD student at GMU who works at USHMM. She knew of some nice had drawn maps that relate to project Quarz. So I took some digital copies of these maps, and want to use them in a project this semester. The above linked resources help in searching for documents, images, etc.

Well, the tips, tricks, gadgets and goodies were a bit lacking this week. Enjoy what you can of it.

Weekly Tips, Tricks, Gadgets and Goodies #2

So, here it is. The second week of TTGG. I found a bunch of things this week. Enjoy!

Goodies #1: There’s a lot of hype lately about Twitter. Don’t understand it? Here’s a video that explains it in plain English. [Google Video] It still seems a little tooooo much for me. I don’t want to know what someone is doing every minute of the day, and I don’t want to have to update my info all of the time too. I’m an old fashioned tech-noob.

WiredScience
Goodies #2: We’ve got no T.V. at home. It’s a conscious and wise decision. It means more time to spend with each other, reading books etc. But we get the hankerin’ for some media entertainment every once in a while. I looked on pbs.org last night and found a cool show with good quality video feeds: Wired Science. The best were the “What’s Inside” segments featuring Chris Hardwick. He’s a pretty funny guy.

Scribd
Gadgets #1: http://www.scribd.com/ This is a cool project for getting your documents in a viewable format without having to worry about programs. It will take a pdf, word document, power point, and anything from OpenOffice or the OpenDocument format, and display it in your web browser (using Flash and JavaScript). I’m thinking this will be ideal for letting people view research papers and such on a digital historians site. It would be cool to see this in JStor as well. Their current interface is a little clunky (one page at a time, slow loads, no text copy, etc). It would probably be even easier for them to get content on their site. Come to think of it, this would be great for any online journal.

iPaper
They call it iPaper (everybody’s on this “i” bandwagon), and have a platform version available for you to embed the service on your own website. Look for it here one of these days.

newDock2
Tip #1: Change your Leopard Dock even more using the LeopardDocks App from LeopardDocks.com I like the jet black look.

Trick #1: (not really sure what the difference between a tip and a trick is, but it allowed alliteration and acronyms to work) Take a quick snapshot of your screen in Mac OS X. Hit the Command-Shift-4 keys at the same time, and your mouse becomes a cross hair. Click some where, drag the box, and bing-o! a picture on your desktop appears. Quick and easy!

TipTrick #2: Get different languages in your Mac OSX dictionary. It makes looking up words in other languages easy. And, for the second part of this tiptrick, some people use QuickSilver for fast application launching and fancy program work. I haven’t had the time to figure it out, but stumbled upon an easy built in tool that works similar: SpotLight. Hit Command-SpaceBar and start typing. Type “Firef” and Firefox is your first result, hit enter and it opens the application right up! You can change the preferences as to what shows up first, and what shows at all. Type in a word, and SpotLight will give you a definition. Nice! Now the fingers seldom leave the keyboard!

Weekly Tips, Tricks, Gadgets, and Goodies #1

I think I’ll try and start a weekly tips, tricks, gadgets and goodies post. It will cover the neat-o things in the tech world that I come across during the week that don’t have a whole lot to do with history, but are fun nay-the-less.

dock
Tip #1: Custom Leopard stacks and drawer images
Tutorial for customizing your stacks icons.

make a new folder, name it “0000” for sorting by name, or “touch -mt 2020010101 foldername” for sorting by date added.
copy the image from Get Info, paste int onto the Get Info for the new folder.

Add your own image to your drawer using the steps shown here at usingmac.com.

And you get something like above.

Goody #1: Geotag your photos
Check out the Geotag application which is helpful for spatially locating your great photographs when your camera has no GPS built in.

THAT podcast

Check out THAT podcast (THAT = The Humanities And Technology). It’s a new video pod cast put on by a couple of co-workers at CHNM. They interview someone in the technical field about software that helps those of us in the humanities.

The first episode includes an interview with Matt Mullenweg, creator of WordPress (the software running this site!) and shows you how to install and configure ScholarPress (a plug-in to WordPress written by Jeremy Boggs).

It’s great stuff, check it out!

Converting WordPress to static html

UPDATE: Check out the new post on a better way to do this here: Convert WP to Static HTML Part 2. Or see the page devoted to the script here: Make WordPress Static.

Usually people are wanting to convert their static html pages to some dynamic content management system. I’ve run into the issue of needing to go the other way.

A few professors at GMU love to use WordPress for their classes. It’s a really great way to get more student participation and involve some of those who aren’t so talkative in class.

But these blogs are usually only needed for one semester, and then just sit there. This can be a security risk if they are not kept up to date, and is cumbersome when trying to update many of them (one professor had over 30 blogs!).

Sometimes the content should still be viewable, but the need for a whole cms type back-end no longer exists. Sometimes the professor would just like a copy of the pages for their own future research or whatever.

So, I figured out a way to convert a dynamic WordPress site into static html pages.

Here are the basic steps I used:

  1. Change the permalink structure in the WordPress admin section. Alternatively, directly in the database change wp_options.permalink_structure.option_value to “/%postname%.html”.
    [code lang=”SQL”]
    UPDATE `database`.`prefix_options` SET `option_value` = ‘/%year%/%monthnum%/%day%/%postname%/’ WHERE `prefix_options`.`option_name` = ‘permalink_structure’ LIMIT 1 ;
    [/code] 

    UPDATE (2.12.08): Reading a post from Christopher Price (who linked to this post) about WP permalinks, I’m thinking using this structure (/archives/%post_id%.html) might afford the best results. I often found a page that displayed the raw HTML instead of being rendered. This just might fix that issue.

    UPDATE (3.11.08): I did some more dynamic to static conversions today, and found out the best permalink structure to use is just the post name. No extra categories and such. So the best structure to use would be this (/%postname%.html). The benefit is that the every page is unique with a descriptive name for the url (albeit sometime very long), and there are not as many subdirectory issues that arise.

    UPDATE (7.17.09): This time around, I have found that the following seems to work best for permalink: /%year%/%monthnum%/%day%/%postname%/ And cleaned up the SQL statement.

  2. Add the .htaccess to /path/to/wp/ if not already there (where /path/to/wp/ is from http://somedomain.com/path/to/wp/ ). If there already is a .htaccess file and it is set to have permalinks, then you can probably leave it as it is.
    RewriteEngine On
    RewriteBase /path/to/wp/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /path/to/wp/index.php [L]
  3. Use wget to copy all of the files as static html files.
    [code lang=”bash”]wget –mirror –wait=2 -P blogname-static -nH -np -p -k -E –cut-dirs=3 http://sitename.com/path/to/blog/[/code]
    *** Change –cut-dirs to the appropriate number associated with how many directories are after the domain name. The trailing slash plays a part too. ****
    UPDATE (03.11.08): I found that the –cut-dirs doesn’t really do anything this time around.
    UPDATE (7.17.09): This time around, I find the following to work best, even the –cut-dirs. 

    wget --mirror -P wpsite-static --cut-dirs=3 -nH -p -k -E https://site.com/path/to/wp/

    This has the bonus of making the directory for you, thus negating the make directory step. Make sure to use two dashes and not an em dash.

  4. Copy the contents of wp-content to save uploaded files, themes, etc. This way copies a lot of unnecessary php files, which could be potentially dangerous, but is really easy if you’re just converting to archive. To remove the security threat, just pick and choose the files you need.
    [code lang=”bash”]cp -r /path/to/wp/wp-content/* /path/to/static/wp-content/[/code]
  5. Sometimes the files are created with folders in the archives folder. To fix this run the following three commands in the archive folder to fix that up. To get rid of the feed file in all of the directories:
    [code]rm -f */feed [/code]
    To delete all of the now empty direcotries:
    [code]find . -type d -exec rmdir ‘{}’ \;[/code]
    To rename the files ###.1 to ###
    [code]rename .1 ” `find . -type f -name “*.1″`[/code] That’s two single quotes after the first ‘.1’
  6. UPDATE (03.11.08): I have found that the old ‘rename‘ command [rename .1 ” *.1]only works on the current directory. If you want to do a recursive renaming you have to use the ‘find‘ command. The above code has changed to reflect this.
    UPDATE (7.14.09): When the rename with find doesn’t work, it’s probably because the post has comments, so there is a folder with the same name as the post’s filename. In this case, just move the file (with the .1 extension) into the folder of the same name, but change the name of the file to index.html

  7. move to wp folder. make a backup of database: [code lang=”bash”]mysqldump -u [userfromwp-config.php] -p –opt databasename > databasename.sql[/code]
    UPDATE (03.11.08): I found I needed to backup just a few tables from a database that contained many copies of wordpress. To do this more easily, I used a little script I wrote earlier to dump tables with a common prefix. This could also work if you just put in the full name of only the tables you wanted to backup.
  8. move one directory above wp install. make tar backup of old wordpress folder: [code lang=”bash”]tar -cf wordpress.tar wordpress/[/code]
  9. rename the old wordpress folder [code]mv wordpress wordpress-old[/code]
  10. move the static copy into place [code]mv static/wordpress/ wordpress/[/code]
  11. test out the site. If it’s totally broke, just delete the wordpress directory and restore the original from the tar file.
  12. remove the tar file and wordpress-old directory as needed.

WordPress updater

What’s with these multiple posts in a day…

Today marks the completion of my Multiple WordPress Updater Script. I’ve already posted a bunch about school stuff, might as well post about work stuff too.

We host over 55 blogs at CHNM. It’s up to me to update them when security patches or new versions come out. Doing them each by hand is a pain. I did a bit of searching but didn’t find anything that would help me update so many sites automatically. So I wrote a bash script that will do it for me. It reads a file that lists all of the wordpress install paths or prompts you for the path to one, prompts for the version to switch to, and a mysql user/pass that has permissions for all databases.

Then the script creates a copy of the database, makes a copy of the wp-content folder, updates the wordpress install using subversion, fixes some permissions, and saves the subversion output to a file in your home directory (which I’ll probably change to somewhere’s else).

I run this via sudo as root for easy updating. What I’m really pleased with is that I figured out how to get the script to pull the database name from the wp-config.php file, and grab the owner and group for later fixing of the permissions.

I hope it can be useful to someone. If you have any comments or suggestions, let me know.

Latest Version: 1.2.3 – 04/29/08
Download file

UPDATE 24.4.08: WordPress Updater has been updated. I also updated this post, took out the code in the post, and put up a link to the file for you to download instead.

How does the yahoo/flash map work…

There’s a lot of tutorials out there, but here’s how I got it to work.

The Plan

Got what? Oh, well, basically it’s being able to use yahoo maps, flash, xml, php, mysql, and data to display a bunch of markers on a map. Each marker contains data pulled from the database, and has a link to a page that displays the full information. For now, I just made a display page. But sometime latter, it will be implemented into the fine Omeka install that the 1989 project will use.

The Steps

Here’s an outline of what I did.

  1. Create a flash file using the yahoo flash map api component. Available at Yahoo.
  2. Add some ActionScript to the first frame that will import data from an xml file.
  3. Create a php page that pulls in data from a MySQL database and displays as an xml file.

Create the swf

In order to make Yahoo and flash play nicely, you need to install the component linked above. Follow directions there. This will add a new component to your Flash program, available in your components window (Window->Components->Yahoo->com.yahoo.maps.api.flash.YahooMap).

Once that’s installed, create a new empty fla. Make a keframe in the first frame on layer one. Drag the yahooMap component onto your stage.

Next, add another layer for your actionscript.

the ActionScript

Here’s the tricky part. Here’s the code I used, heavily commented:

[code lang=”Actionscript”]
/*********************************
* File: yahoomap.as
* Author: Ammon Shepherd
* based off of many tutorials and code snippets, mostly from Yahoo! documentation.
********************************/
//Set the URL where the xml file is.
var xmlURL = “http://chnm.gmu.edu/1989/maps/xml.php”;

//Import Yahoo map tools
import com.yahoo.maps.LatLon;
import com.yahoo.maps.markers.CustomPOIMarker;
import com.yahoo.maps.tools.PanTool;
import com.yahoo.maps.widgets.*;

//Create a listener associated with the instance of the Yahoo map component.
// Set the map to pull down the yahoo map and get the setting/changes from
// the onMap function.
euroMap.addEventListener(com.yahoo.maps.api.flash.YahooMap.EVENT_INITIALIZE, onMap);

//This will add a zoom tool and set it as closed by default
var zoomer:NavigatorWidget = new NavigatorWidget(“closed”);

//The onMap function adds the tools, settings, and markers to the map.
function onMap(eventData) {
//create a new PanTool and name it pantool
var pantool:PanTool = new PanTool();

//tell the instance of the map to use the new PanTool called pantool
euroMap.addTool(pantool, true);

//Add the Navigator widget
euroMap.addWidget(zoomer);

//Create a variable called xmlData of the type XML
var locations_xml:XML = new XML();

//igore white space
locations_xml.ignoreWhite = true;

//when the xml file is loaded, do the fuction within
locations_xml.onLoad = function(success){
//if the xml file loaded successfully run the function addMarkers
if (success) addMarkers(this);
};

//then actually load the xml file.
locations_xml.load(xmlURL);

/*******************************************
* Used this for testing, you don’t really need it. I was thinking of using
* this in the future to display the lat and long to the user.
//Get the center of the map and store them in the variable called points.
var points = euroMap.getCenter();
//trace(“before convert” + points);
//swap the points, so long->long and lat->lat
convert(points);
//trace(points);
******************************************/

}

//This is the function that adds the markers to the map.
function addMarkers(xml:XML):Void {
//the addresses variable holds the path to the right xml element.
//firstChild is the and childNodes is an array of the tags
var addresses = xml.firstChild.childNodes;

for(var i=0; i then the second and so on for all of them.
address = addresses[i];

/***************************************************************
* MarkerData is the object that holds the info for each marker.
* index: is the text that shows up on the marker (usually just A or
* what have you. you could use the variable i to show an
* incremented number (each marker has it’s own number).
* title: sets the title of the marker and corresponds to the title
* parameter in the location tags in the xml file.
* description: is the larger text. It corresponds with the description
* parameter in the location tag in the xml field.
* markerColor: sets the color of the marker, duh 🙂 It’s the border
* color, and the color when not expanded.
* strokeColor: is the background.
***************************************************************/
var MarkerData:Object = {index: ‘\’89’, title:address.attributes.info, description:address.attributes.description, markerColor:0xcc0000, strokeColor:0xceccc7};

/****************************************************************
* This actually adds the address to the map using the custom point of
* interest style of marker (you can use your own style if you like.
* the address.attributes.loc grabs the latitude and longitude from
* the loc=”” part of the location tag in the xml file. MarkerData
* is the stuff we just set above.
****************************************************************/
euroMap.addMarkerByAddress(CustomPOIMarker, address.attributes.loc, MarkerData);
}
}
[/code]
Download yahoomap.as

(Special thanks to CodeSnippet for providing a way to show code. This was the 5th one I tried that finally worked.)

The PHP/XML

Next we need an xml file. I need to pull the data from a database, so I used a php script which pretends to be an xml file. The basics of that is to put this in the php file:
[code lang=”php”]
// Date in the past
header(“Expires: Mon, 26 Jul 1997 05:00:00 GMT”);
// always modified
header(“Last-Modified: ” . gmdate(“D, d M Y H:i:s”) . ” GMT”);
// HTTP/1.1
header(“Cache-Control: no-store, no-cache, must-revalidate”);
header(“Cache-Control: post-check=0, pre-check=0”, false);
// HTTP/1.0
header(“Pragma: no-cache”);
//XML Header
header(“content-type:text/xml”);
[/code]

Then, because our database doesn’t store the geocodes by default yet, nor do the items have any type of specific address or what not associated with them, I created an array with specific places and their lat, long. Each of the items in the database have tags associated with them. The array corresponds to tags that have countries names on them. This poses a problem if the tag name is changed, but for now it works OK.

[code lang=”php”]
$countries = array(
array(“Poland”, “52.1874047455997”, “19.072265625”),
array(“East Germany”, “52.517474393230245”, “13.41156005859375”),
array(“Czechoslovakia”, “49.210420445650286”, “17.490234375”),
array(“Hungary”, “47.45780853075031”, “19.05029296875”),
array(“romania”, “45.98169518512228”, “25.07080078125”),
array(“Yugoslavia”, “44.26093725039923”, “18.96240234375”),
array(“Bulgaria”, “42.601619944327965”, “25.24658203125”),
array(“Soviet Union”, “55.70235509327093”, “37.79296875”)
);
[/code]

The problem I ran into next was that there were over 15 markers that would share the same lat an long. This makes it hard to click on a marker when it’s buried under 20 other markers. So at first I tried just adding a couple of digits to the lat and long as it looped through the array. This led to a long line of markers, and didn’t look very good. Random numbers to the rescue! To create a clustering affect I generated two random numbers, one for the lat and one for the long. This number was added giving the markers a clustered appearance. Here’s that part of the code:

[code lang=”php”]
echo “< ?xml version='1.0' ?>

“;

for($g=0; $g‘;

}
}

echo ‘
‘;
[/code]

You may notice my call to the description function (which, in turn, calls a function called truncate, but you wouldn’t know that yet). This simply turns all HTML characters into their HTML entity characters. HTML in an XML file will break the XML file… more specifically the < and " ' characters. The truncate function I grabbed from php.net's comments for substr_replace. The truncate function shortens long text to a set number of words, and adds an ellipse at the end to signify more text. Here are those two functions:

[code lang=”php”]
function description($id,$text){
$description = wordwrap(htmlentities(truncate($text,200), ENT_QUOTES),30);

$fulltext = $description.”\n<a target=’_blank’ href=’http://chnm.gmu.edu/1989/maps/results.php?id=$id’>Show item</a>”;

return $fulltext;
}

function truncate($text,$numb) {
// source: www.kigoobe.com, please keep this if you are using the function
//$text = html_entity_decode($text, ENT_QUOTES);
if (strlen($text) > $numb) {
$text = substr($text, 0, $numb);
$text = substr($text,0,strrpos($text,” “));
$etc = ” …”;
$text = $text.$etc;
}
//$text = htmlentities($text, ENT_QUOTES);
return $text;
}
[/code]

Here’s the whole php file.
That basically does it.

xml, and lots of time.

Back again. Only two weeks left of school.

I spent the past two days trying to work XML into the picture for the time line aspect. The thought was, if all of the data for the ‘flash point’ or points of the events of 1989 were kept in an xml file, the the flash could dynamically add them in at the right place and time.  I can bring in the xml data, but I can’t get it to display the correct information for each event. It always shows the last events data. I have a for loop to grab all of the data from the xml file, then it attaches the ‘flash point’ movie clip in the correct place. Then I assign an onRollOver and onRollOut to that movie clip (dynamically named). But the onRollOver just holds the data from the last element in the xml instead of each attached movie clip holding the data for it’s respective event.

This would be really cool to do, because then to add or remove events from the timeline, just edit the xml file.  The xml filed could even theoretically pull the data in from the database, making so that each person can have their own specific timeline.  That would be way cool. But it unfortunately seems a bit beyond me. The other obstacle is about the time aspect. How can I get the flash point to show up at the right time. I’d have to come up with a bunch of mathematical voodo on where the timeline bar is (the _x position on the stage) and the percentage left and compare that with the date of the event somehow. Aargh! Way too confusing for my feeble brain.

I’ll just have to do the easy hard code the events into the timeline. Anyhow, here’s what I have so far on the intro/timeline (which, I’m realizing, I’ll need to have a front page where you select which one you want to view, or have them separate instead of one after the other). Version 0.0.2.3.9.5 (or something like that)

Getting it to work.

I’m finally getting somewhere with the Yahoo/Flash map. The latest is always viewable at http://chnm.gmu.edu/1989/maps/yahoo.html. Tonight I worked on getting the title and description to show up nice. The description is usually really long, so I found a php function that truncates it (without cutting of mid-word), and adds an elipse to show more text. I also figured out how to add html links to the xml data. There’s apparently a couple of different ways. I opted to have the first < in the a tag be written in as &lt ; (the HTML entity). That did the trick. Now the marker has a link to see the whole of the data. This should be a link back to the page that’s part of the real site (in Omeka).

Another idea: Add the ability in the admin side of things, to select an item, and then enter the geocodes for that item by clicking on the map in the appropriate spot. Flickr does something like that. It would make it really easy for admins to enter the geocodes.