Saturday, 31 December 2011
New year's eve excitement
Friday, 30 December 2011
Various
This morning I worked on a testcase for a Google Chrome bug where images aren't shown in ATOM feeds where the content is xhtml. I submitted the bug report, then played on Rayman Origins on the xbox with Mauser for a bit before lunch.
In the afternoon I received my latest credit card statement in the post. I noticed that I was charged £1 interest, and the same on my previous statement. I have a direct debit set up to pay off the full amount each month, so I wondered what this £1 interest charge was. I looked on the MBNA website, but couldn't see anything there, so phoned them.
After being on hold for a while I spoke to someone, and they explained that any cash transactions accrue interest on them from the date they are made until they are paid off, with a minimum charge of £1 per month. So as well as charging a cash advance fee on any cash transactions, there is also this monthly cash transaction charge. I just need to make sure that I don't use my credit card to pay for anything that can be considered cash.
I uploaded some photos to my photo website.
For the rest of the afternoon and most of the evening I did some sculpey as McRad wanted me to do sculpey at the holiday at home thing. I decided that the standard coloured sculpey would be too tough for most of the people, but the soft sculpey should be OK. Since we only had 1 pack green Studio sculpey and about 1/3 pack yellow Studio sculpey, I bought a 6 pack of coloured soft fimo from ebay. I also bought 2 packs of super sculpey since we've run out (and it is also soft enough for most people to use), and a pack of sculpey firm for our own use and to see what it's like.
I hope 6 packs of soft fimo will be enough as the packs are only small (56g each). I thought I could probably photocopy some pages from L's polymer clay book for ideas of things for people to do. We'll also need knifes for being able to cut the clay as well. I made a caterpillar from the book today with the Studio sculpey, and it came out okay.
Tuesday, 27 December 2011
Camera system comparison
This morning I was doing some more work on my photo website. I noticed that the contact form for the website was throwing up a lot of errors. But when I looked into it, the problem was actually with the PEAR Mail class I was using. I was using the class correctly, but the class seems to be written for PHP4 rather than PHP5, and is missing the keyword 'static' in front of methods that are meant to be called statically.
I downloaded the latest version of the class, but this still had the same problem. To be honest, I think I might just leave these errors. Correcting the errors in PEAR seems a bit much to me.
I spent most of the day trying to get Mailpress set up, however it didn't seem to work properly. When you subscribed, it would add you to the database as a 'subscriber', but not actually subscribe you to the Newsletter. So I posted to the support group for Mailpress to see if I could get any help.
Here is the camera comparison I was doing yesterday, trying to decide what camera to get next:
Since for some options I listed two or more lenses that could fulfil the same job, I used an orange colour in the spreadsheet to indicate the rows that were added to get the total costs below each option. Lenses priced at £0 are ones I already own, so there would be no cost for me.
The comparison is done looking for the things I want in a camera system. All the cameras have good image quality, so I didn't compare that. I want to be able to shoot from wide angle (sometimes known as super-wide angle) up to low-end telephoto (100-200mm). I also want a full frame fisheye for decent resolution panos in 6 +2 shots, and a wider fisheye for 3-4 shot lower resolution panos, which are better for those with lots of people / moving objects.
The reason I want a new camera / lenses is that my Nikon 18-70mm lens seems to be a bit soft on one side, and I am not convinced that my Nikon D200 camera is autofocusing correctly. I did try adjusting the autofocus, but it is quite difficult, and despite looking to autofocus correctly when doing the adjustment tests, it seems to backfocus in actual use.
My Canon 450D is even worse when it comes to autofocus, and I don't know how to adjust that. It has been to Canon, who certified it within expected tolerances. The Canon does AF correctly in contrast detect (Live view) mode, which is how I used it in Scotland, but I found this too slow and missed some shots.
So with both my current cameras the problem is autofocus. I have tried manual focusing with them, but for anything other than macro, I can't get the focus correct manually. Manual focusing in liveview with the 450D is possible, but it doesn't feature picture-in-picture magnification. So you have to magnify where you want to focus, focus, then unmagnify and make sure the composition is correct. This is nearly impossible if the subject you want to focus on is moving.
I have included manual lenses for the NEX and Canon 5D Mk II in my options to purchase though. The NEX features focus peaking, and the 5D Mk II has a split prism viewfinder available (at extra cost) to aid in manual focus, as well as the larger viewfinder naturally making manual focus easier.
I didn't include the 17-40mm L lens for the Canon 5D Mk II as the wide-angle option, but instead looked at some prime lenses. From what I've read in forums the 17-40 L lens isn't sharp in the corners until f/8 - f/11. A good selection of primes offers the best quality and light gathering ability, but is more expensive, heavy, and large. The 5D Mk II also doesn't have an adjustable LCD screen.
Although I've never used a camera with an adjustable LCD, I imagine they are useful for more discreet street shooting, to enable better shooting from the hip. It should also be good for low angle (e.g. macro), high angle, and any other strange angle shots.
Exposure Bracketing is also important to me, with my D200 I often find the camera doesn't have enough dynamic range to capture a scene in one shot. New cameras are probably better, but I still think there would be situations where exposure blending or HDR would be needed.
The NEX fails in this regard, with no exposure bracketing available. It also doesn't have a viewfinder, though I understand one can be purchased at an extra cost.
The Canon and Nikon options are both pretty similar, however I prefer the Nikon as I already have more Nikon lenses and accessories than Canon. I will also want to be taking my Fuji IS-Pro with me, which is Nikon mount, so the Nikon option allows sharing lenses etc. with the Fuji cam.
The Micro four thirds option is lacking in that I couldn't find any wide fisheyes available for m4/3, only full frame fishes. Also, both the Nex and micro four thirds cameras don't seem to have any macros available. You can use old manual lenses on both, but this would entail either shooting with the lens stopped down (bad in low-light), or having to manually stop the lens down as you come to take the shot (bad for keeping focus when hand holding).
My current preference would probably be either for the m4/3 option (due to low weight and size) or the Nikon option (due to my existing Nikon gear). I don't intend on purchasing anything right now anyway, so will be interested to see what stuff is released over the coming year (but before I go on holiday again and need some new photo gear). I think I should be okay with my current gear until I go on holiday.
Monday, 26 December 2011
Websiting and playing boulder dash
Checking my emails this morning I had two very similar emails promoting SEO services:
Hi,
My name is Monica and I'm the webmaster of SerpSynergy.com
I work on many projects for my partners websites and by doing so
I came across website-name.com and I immediately wanted to contact you.
As you might aware, getting links from good quality sites would definitely
help you in terms of Page Rank, traffic and higher ranking in major search
engines like Google, Yahoo! and Bing.
If you're interested in more details, please get back to me
and I will suggest you all my tips, tricks & knowledge I've gained
with years of experience in the SEO field.
Hope to hear from you soon and have a great day :)
Thanks,
Monica Banyard
monica@serpsynergy.com
Serpsynergy.com
http://www.linkedin.com/in/monicabanyard
and:
Hi,
I would like to introduce myself my name is Marian, webmaster of SocialSEOMaster.com
among other sites that I personally maintain.
While working on a project for my partners website I've found website-name.com
and I decided to contact you to tell you little bit more about what I do.
I'm a SEO expert with vast experience over the years in the SEO field
placing my partner's websites on Google's 1st results page for the
keywords they're after.
I would like to elaborate more and send you more information, to share
my thoughts, tips & tricks.
Please let me know if you're interested and we'll take it from there.
Thanks a lot,
Marian Dolan
marian@socialseomaster.com
SocialSEOMaster.com
http://www.linkedin.com/in/mariansdolan
I checked their websites, and while the design is very different, the concept is quite similar - a single page with a bit of text, lots of graphics, and only one link, to the contact page.
My guess is that they're either both the same person, or maybe two people who have bought into a 'become an SEO expert course' or something similar, which gives a general template of the email to send and website to create.
This morning I did some more work on my website. First I looked into if the addThis wordpress plugin could be modified to just link to a new page with a list of all the different social networks / bookmark sites supported by AddThis. This is what the plugin already does in Google Chrome for me, just it doesn't work in IE.
But the code didn't seem that simple to change, and this functionality is not actually that great anyway - the list of sites on the AddThis page is so long it takes a while to find the correct button. Also, it involves two clicks - one click on the AddThis button to bring up the list of supported sites, then a second click on the site you want to bookmark / share the link on.
So I decided to look at other social bookmarking plugins again. One I already had installed was WP Socializer. This plugin spews up a lot of PHP errors, all seemed to be to do with undefined variables. I thought it would be worth at least attempting to fix the plugin, so did this. Most of the errors were due to concatenating to a variable that had not been set, or accessing the value of an array key that did not exist.
After getting rid of the errors on the client facing side (the plugin still had lots of similar errors on the admin side I didn't bother fixing), I looked to integrating the plugin's js and css with my combined js and css files. Strangely, the plugin didn't seem to be including its js file. I checked the file and it had a addBookmark function, which just alerted a message to press Ctrl + D to bookmark the page.
In my combined js file I already had an add to favourites function from sociable (which I had been using previously), so I modified this instead of using the WP Socializer javascript. But when I tested it in Google Chrome, it wasn't working. After doing some googling it seemed like some browsers don't support adding a bookmark via javascript, and instead it is recommended to just tell the user how to bookmark the site. This is exactly what the WP Socializer js function does, so I just copied that across and deleted my modified sociable js addBookmark function.
After getting that sorted I installed the Mailpress plugin for my photo website. I wanted to use the same email template that I use for my photography tips website, however I spent quite a long time trying to find the template, and couldn't find it anyway. When I checked the Mailpress theme settings on my photo tips website it said there was a problem with the selected theme, and was using the default theme instead.
I think that I must have upgraded the Mailpress plugin and this resulted in my customized theme being deleted or overwritten. Doh! So now I'll have to spend quite a while again testing to try and get a reasonable looking template again.
Sarah and Mark came to stay for a couple of days in the afternoon. We all had Christmas dinner together in the evening (Pheasant and Guinea fowl), then played boulderdash afterwards.
I also looked at different camera upgrade options for me, maybe I will post my thoughts tomorrow as I am sleepy and going to bed now. Bye!
Sunday, 25 December 2011
Christmas
Today I went to church in the morning and then updated my pog website. In the afternoon I helped Ben make some cookies and did the washing up.
In the evening I watched a Laurel & Hardy film with the family and tried debugging the AddThis plugin for wordpress. Unfortunately I think the plugin (actually it's the AddThis javascript, not the plugin itself) is broken in too many places for me to fix.
The problem is only appearing in IE9 for me. I think that probably the js is doing some browser sniffing and doing things differently for IE than the other browsers, and because I serve the site as XHTML (XML) this is breaking the js. So I am going to have and try another different social bookmarking plugin.
I was thinking of giving the sparrows "Lil' Maniac" badges for a Christmas present, but
- I don't think they'd let me get close enough to give them the badges
- If I pinned badges on them it would likely hurt or even kill them
So the sparrows didn't get any Christmas presents, but probably had their best Christmas ever anyway as it was relatively warm today.
Thursday, 22 December 2011
Websiting
This morning I thought about how my wordpress blog feed sent a 304 Not modified header if there hadn't been any new posts since the feed was last requested. For my photo website feed I hadn't implemented this, but it seemed like it would be a good idea. Otherwise a feed reader would have to download the whole feed each time it wanted to check for new items.
However, when I looked for tutorials about creating a feed using PHP, none of them seemed to mention this. However, I did find a tutorial on dealing with sending Last-Modified headers here: Using HTTP IF MODIFIED SINCE with PHP.
I read the W3C info on the Last-Modified header, which states that HTTP/1.1 servers SHOULD send Last-Modified whenever feasible.
I haven't been doing this on any of my dynamic pages, however I can't see how I'd be able to implement it, other than on pages where the images are sorted by date.
If I have 20 pages sorted by rating, and a new image is added today that gets inserted to page 10, pages 1-9 would still be the same, while pages 10-20 would be last updated today. The only solution I can think of would be to create a new database table with a record for every single page that could exist. Then whenever a new image is added, calculate the pages that would be changed and update the pages table with the new last modified date.
The work required to write this logic, the size of the new db table, and the extra processing work required for the server means it is not worth implementing a Last-Modified date for me. It is okay for the feed though, since there the images are sorted in date order, so you can just get the date of the most recently added image.
I did what I was hoping to be my final run with the IIS Site Analyser, but then still found some more things that needed to be corrected. I found that as well as the RSS feed, Wordpress also had an ATOM feed. I realised that you could have ATOM and RSS feeds in wordpress, but I didn't think that both of them were linked to from the blog. I thought wrong obviously.
So I did the same for the ATOM feed as I did the other day for the RSS feed. But then I found some more problems. The ATOM feed had an id specified like so:
<id><?php bloginfo('atom_url'); ?></id>
This seems to be quite incorrect, since it means that all feeds for the blog would have the same id. In a similar way, the alternate link (link to the HTML page that the feed is for) was the same for all feeds:
<link rel="self" type="application/atom+xml" href="<?php self_link(); ?>" />
For fixing the id issue, you can just use self_link()
, which gives the URL of the current feed. For fixing the alternate link, I took Wordpress' self_link()
function and modified it slightly to remove '/feed' or '/feed/atom'. This gives the url of the page the feed is for. I put this function in my theme's functions.php file:
/**
* Display the link for the currently displayed feed in a XSS safe way.
*
* Generate a correct link for the rss link or atom alternate link element.
*
* @package WordPress
* @subpackage Feed
* @since 2.5
*/
function get_self_alt_link() {
$host = @parse_url(home_url());
$host = $host['host'];
return esc_url(
'http'
. ( (isset($_SERVER['https']) && $_SERVER['https'] == 'on') ? 's' : '' ) . '://'
. $host
. preg_replace('/blog(\/)?(.*)?\/feed(\/atom)?(\?.*)?/', 'blog/$2$4', $_SERVER['REQUEST_URI'])
);
}
The alternate link issue is relevant for RSS feeds as well as ATOM feeds, just I missed the issue before when I was modifying the RSS feed template.
I spent most of the rest of the day trying to fix some issues with my google maps page. I was sure I had it working okay before!
Wednesday, 21 December 2011
Various
This morning I wrote up yesterday's blog post and also put the Goodwill Season song on youtube:
I was also thinking about adding the Christmas Orphan Boy song onto youtube. I thought it sounded like it was by the guy who did the Austin Ambassador Y-reg song, and sure enough I was right - his name is John Shuttleworth. What I didn't know is that John Shuttleworth is actually just a character played by comedian Graham Fellows. When I saw him many years ago playing Austin Ambassador Y-reg on the Tonight show on Yorkshire TV, I thought he was a genuine guy with a sense of humour about his music. When actually he's an ungenuine guy with a sense of humour about his music.
Anyway, the song in question was already on youtube, albeit as part of a Vic and Bob sketch with about 3 minutes of useless babbling from Vic & Bob before the actual song. Since the song is available on itunes, lastfm, and on CD from Amazon etc. I didn't bother adding it to youtube.
I ran the IIS Site Analyzer a couple more times on my site, each time finding some things I'd missed that needed correcting. It takes quite a long time to run each time, and also quite a long time to delete old reports. While I was waiting I read dpreview's Mirrorless Roundup 2011
Later in the afternoon and for part of the evening I made a Lemon and Coconut cake with L. Only problem was, we didn't have any coconut.
For birthday presents I got an A3 laminator from McRad, Chocolate from L, and an Olympus LS-5 sound recorder from Clare and Mauser. I went on eBay and bought a wind muffler for the sound recorder as from the reviews I have previously read it seems like this is quite important.
I also bought a North Korean calendar that has nice photos of North Korea. Hopefully it will arrive before 2012, but it is being shipped from Russia I think, and post is quite slow at this time of year, especially with all the bank holidays coming up.
Tuesday, 20 December 2011
Fixing wordpress
Today I was still clearing up errors on my photo website discovered by the IIS Site Analyzer. Mostly I was trying to fix wordpress errors.
The problem is that the url of my blog is /blog/, but wordpress doesn't let you specify that the url ends in a trailing slash. So often when wordpress generates a link back to the blog homepage, it will use a url of /blog, which then creates an unneeded redirect to the correct address of /blog/.
The urls of tags and categories are /blog/tag/tag-name or /blog/category/category-name and again, there is no way to change this (that I know of) to force them to end in a trailing slash. The problem here is the opposite, that often when wordpress generates a link to the tag or category, it will end with a trailing slash e.g. /blog/tag/tag-name/. So this then creates an unneeded redirect to the correct address of /blog/tag/tag-name.
After trying various things and much research I ended up with the following in my theme's functions.php file:
//Wordpess won't save the site/blog URL with the needed trailing slash, so we have to add it manually here
add_filter( 'index_rel_link', 'fix_index_rel_link' );
function fix_index_rel_link(){
return '<link rel="index" title="David Kennard Photography" href="'.get_bloginfo('url').'/" />';
}
//In the opposite way, Wordpress adds trailing slashes to URLs that don't need them, so we have to remove it manually here
add_filter('get_pagenum_link', 'fix_get_pagenum_link');
function fix_get_pagenum_link($w){
//match an ending slash or slash followed by query string, so long as the slash isn't immediately preceded by /blog
return preg_replace('/(?<!blog)(\/$|\/(\?))/', '$2', $w);
}
Next I found that the feed had similar problems, and also was using the same description for every category and tag. However I couldn't find a way to filter the info used in the feed. The feed uses bloginfo_rss()
to get the various info. While it is possible to filter this, it didn't seem possible to get the type of info that had been requested. So if I created a filter, the same filter would be run on bloginfo_rss('url')
, bloginfo_rss("description")
, and bloginfo_rss('name')
, and there is no way to tell in the filter function whether you are filtering a url, description, or name.
So, what I had to do instead is to add a custom feed template to my theme. I copied the default feed-rss2.php file into my theme directory. In functions.php I added:
//Default wordpress feed doesn't give correct title on tag pages etc. so use a custom feed
remove_all_actions( 'do_feed_rss2' );
add_action( 'do_feed_rss2', 'dkphoto_feed_rss2', 10, 1 );
function dkphoto_feed_rss2( $for_comments ) {
$rss_template = get_template_directory() . '/feed-rss2.php';
load_template( $rss_template );
}
For the custom feed I wanted to use the same titles, descriptions etc. that I used for the non feed page equivalents. So I removed the logic that pulled these from my theme's header.php file and put it into a separate file, which I named header_pageTypeDetect.php. Googling to find how to include the new file, I found the function get_template_part()
. However, this didn't work as the variables created in header_pageTypeDetect.php were scoped within the get_template_part()
call. Since the variables created in header_pageTypeDetect.php needed to be accessed by header.php and feed-rss2.php, this was no good.
The solution is instead to use a standard include with get_template_directory()
to get the correct path. e.g. include(get_template_directory().'/header_pageTypeDetect.php');
.
After getting this set up, I found that while the feed was working for most pages, it wasn't working for /blog/feed. The reason was that I was using is_home() to detect the front page of the blog, but this doesn't work for the feed of the blog home. Unfortunately, there doesn't seem to be any functions available to detect if you are at the feed of the blog homepage.
So what I did instead was to do my standard checks, setting the title and description etc. appropriately, then at the bottom I added
//If this is the main feed page /blog/feed
elseif(is_feed() && !is_archive()){
//set the title, description etc. here
}
Since I had already done a check for single posts and pages, I knew that if the check got this far, and it was a feed and not an archive (tags, categories etc.), then it must be the feed for the home page.
While working on this I found that some of my blog pages had extremely long meta keywords tags. This is because I was including all the keywords for all posts on a page. Doing some googling, it seemed to be generally recommended to stick to only about 10 keywords: Google Webmaster Central: Max length of Meta Tags ?. So it looked like I should only include the 10 most common keywords from the posts on the page rather than all the keywords.
For figuring out the keyword popularity, I thought that the keyword cloud widget must already do something along these lines. However, I couldn't see any code easily borrowable from the keyword cloud widget, so I just wrote my own logic:
if(have_posts()){
$metaKeywords = array();
//var_dump($wp_query); exit();
//get all the tags for posts on this page
while (have_posts()){
the_post();
$tags = get_the_tags($post->ID);
if($tags){
foreach($tags as $tag){
if(isset($metaKeywords[$tag->name])){
$metaKeywords[$tag->name]+= 1;
}
else{
$metaKeywords[$tag->name] = 1;
}
}
unset($tags, $tag);
}
}
//Sort the keywords by most used and select only the top 10
if(count($metaKeywords)>10){
arsort($metaKeywords);
$metaKeywords = array_slice($metaKeywords,0,10,true);
}
$metaKeywords = array_keys($metaKeywords);
}
Another thing that the IIS Site Analyzer brought to my attention today is that I was serving some pages with text/xml
, while others were being served with application/xml
. I read What's the difference between text/xml vs application/xml for webservice response, and it seems that it doesn't make much difference what one you use (text/xml means easily readable by humans, application/xml means not easily readable by humans).
Along other lines today, DPS had a special offer of all 35 ebooks from Craft & Vision for $99 (40% off). After looking at some of the book pages and customer comments on the Craft and Vision site, it did look like a great deal. However, in the end I decided against it. I already have tons of stuff I've bought and not had time to read or use yet. If I bought the e-books they'd probably just be added to that 'pile'. Better to save the money for spending on a new camera or lens.
I also had a message from Red Bubble that they were offering 20% off gift vouchers. I thought this sounded quite good as you could buy the voucher then use it to buy a T-shirt for yourself. Most of the T-shirts on the site seemed quite expensive, so I wondered how much it costs to make you own shirt. Checking their prices, it costs £12.40 for a White Unisex S-XL Tee. This is excluding VAT at 20%. Since the voucher is 20% discount, £12.40 would essentially be the price you pay (I couldn't see anything about there being additional shipping charges). I checked Zazzle, and they were charging about £15.50 for the same, so seems quite a good deal to me.
Monday, 19 December 2011
Websiting
Today I did some more KML / Google Earth debugging. I found that my KML was working correctly on my live website, but not my local dev website. So I performed the same actions on both the local and live KML, using Fiddler to record the HTTP requests. Then I used Beyond Compare to compare each request between the Live and dev versions. There were a few differences, but the main one was that the Live website used target="_blank"
on the links, which worked, while the dev site didn't use target, and the links didn't work.
So I added target="_blank"
to the dev site, and now that works as well. Phew!
Later, I checked the Google KML Reference, and it does actually say:
Targets are ignored when included in HTML written directly into the KML; all such links are opened as if the target is set to _blank. Any specified targets are ignored.
HTML that is contained in an iFrame, however, or dynamically generated with JavaScript or DHTML, will use target="_self" as the default. Other targets can be specified and are supported.
However, what it does not say is that target
must be set to _blank
for links to KML to work. Still, if I had read that earlier it probably would have given me enough of a prompt to discover that the target
property was the problem, which would have saved me hours of work discovering that myself.
After sorting that out, I ran the IIS Site Analysis on my dev site. One of the errors it came up with was that the wordpress author link went to a 404 not found error page. I did some googling and found a few posts on the wordpress forums where people were having the same problem, but no solutions were given. Then I found this page: WordPress Authors Page 404 Page Not Found Error.
I did what the author suggested (altering the value of wp_users.user_nicename in the database to have no spaces), and it worked nicely. Now the author link works and no more 404. Interestingly, I noted that all the other users (subscribers) already had user_nicename so that it contained dashes instead of spaces, my author nicename was the only one with spaces.
Another thing I found from the Site Analysis, was that it had a 404 error for the cite attribute of a blockquote. I had just put the name of the person who the quote came from as the cite, it wasn't a URL, so no wonder it 404'd. Looking it up (Quotations: The BLOCKQUOTE and Q elements), I found that what I'd done is incorrect, and it should be a URI.
I had quite a few links on my blog where I had just used the link text 'here', e.g.
This is tenth post in my series on how to be a boring blogger, you can read the first post <a href="/link/to/post" title="How to be a boring blogger part 1 - blah blah blah">here</a>
However, the IIS Site analysis report flagged these for having non-relevant link text. I had always thought that so long as you used the title text to explain what the link was, then it didn't matter that you used non-relevant anchor text. But investigating this, I found that the purpose of the title attribute is to convey extra information about the link: W3C - The title attribute, and is not really given much relevance by search engines: SEOmoz - Link Title Attribute and its SEO Benefit. Another useful link I found on link titles was this one, linked to from the SEOMoz article: RNIB Web Access Centre - TITLE attributes.
So I started to change my link text to be more like:
This is tenth post in my series on how to be a boring blogger, you can read the first post here: <a href="/link/to/post">How to be a boring blogger part 1 - blah blah blah</a>
I only left the title attribute in if it gave more info than the anchor text.
When doing this, I noticed that some posts seemed to be duplicated. I thought I had turned off post revision in Wordpress, but when I checked, I couldn't even find a setting for it. I think that probably I used to have a posts revision plugin installed, and turned it off in the plugin. But then subsequently I must have uninstalled the plugin.
So I found some info on how to turn the posts revision off - add define('WP_POST_REVISIONS', false);
to wp-config.php. And I also found a plugin that removes all post revisions from the database: Better Delete Revision. So I installed and ran that, then deactivated it. It removed a load of post revisions, reducing the database size by quite a bit. Nice!
With that done, I finished off my job of replacing all the links with the anchor text 'here'. I did this by exporting the wp_posts table using phpMyAdmin, then opening the saved sql file in gedit text editor. Then I just did a find '>here<' to find any links that needed changing.
I still have a lot more things brought up by the IIS Site Analyzer that I need to fix, but they will have to wait until tomorrow now.
In other news, it was revealed today that North Korean dictator Kim Jong-il died a couple of days ago. I checked the Juche Songun blog, and they have a post where you can leave your condolences: Сообщение о кончине товарища Ким Чен Ира. It seems strange that people would leave messages of condolence to Kim Jong-il, but when you consider people leaving messages there have an image of Stalin for an avatar, I guess it's not so weird.
On the news they had someone saying that the North Koreans are much smaller and weigh much less than South Koreans due to malnutrition. I wonder how they got this information? Did they go into North Korea and measure lots of Koreans? If they had done this government consent, I certainly doubt they would have got an accurate sample. If they did it without government consent I certainly doubt their sample was of a reasonable size and spread over a reasonable area.
I wonder if they also considered whether South Koreans were taller and heavier due to eating foods full of growth hormones and artificial additives. It would also be interesting to know how Chinese Koreans compared in weight and height to those living in North and South Korea.
For the moment I hope that the North, South, and America don't try provoking each other, as they seem prone to do. Just leave North Korea alone while it settles down with Kim Jong-eun as leader, and hopefully he will be a better (for the people) leader than his father. I'm not sure if he will ever live up to titles of his father though, such as World’s Best Ideal Leader with Versatile Talents
, Humankind’s Greatest Musical Genius
, and Master of the Computer Who Surprised the World
(list of titles used to refer to Kim Jong-il by North Korean state television).
Sunday, 18 December 2011
Google earth debugging
Today I updated my pog website and went to Church. I did more work on my test case for a couple of Google Earth bugs, and then posted them to the Google Earth bug tracker. Unfortunately one of the bugs is very serious for my KML, and given that my previous bug reports posted over a year ago are still 'New', it is unlikely the new bugs will be fixed anytime soon. So I will just have to put up with my KML that I spent probably hundreds of hours working on being broken.
In the evening I also watched 'Gunfight at the O.K. Corral' with Mauser and Bo.
Friday, 16 December 2011
Debugging kml & js in google earth
Today I was mainly trying to create a test case of a jquery AJAX request failing from a Google Earth info window bubble. I found that actually the problem didn't seem to be with jquery, but Google Earth. The status of the XMLHttpRequest object was returning 0 on the server's response, when the actual HTTP status code returned by the server was 200. Since jquery checks the status, and sees that it isn't 200, it thinks the request failed and fires the error handler.
I also tried using jsonp in case it was a cross domain issue (I'm not sure whether contacting your server from a Google Earth info window bubble counts as cross domain or not). Anyway, this didn't make any difference, and I still got a status of 0, causing jquery to fire the error handler and not the success handler.
Here's a funny email I got from DXO today, it seems they are having a special offer throughout December where they have increased the price of DXO Optics Pro from £89 to £135:
Link to the email here, though they might correct the image on the link. I'm guessing that it is meant to be the other way round (normally £135, special offer £89).
And here's another weird thing, searching for help on the jquery forum told me there were lots of results, but wouldn't let me see any of them:
Eventually I worked out how to get AJAX working properly in Google Earth Info Window bubbles - add an error handler that checks everything okay, and the error is just GE being buggy, then parses the JSON response and fires the success handler, e.g.
$.ajax({ "url": dk.WWW+'/AJAXandDBFuncs.xhtml?getImgData='+img_id+'&format=json',
"dataType": "json",
"success": dk.ge.createImgInfoWindow,
//hack to get around GE intermittently reporting status as 0 when is actually 200 OK
"error" : function(jqXHR, textStatus, errorThrown){
if(!errorThrown && jqXHR.status === 0 && jqXHR.responseText){
dk.ge.createImgInfoWindow($.parseJSON(jqXHR.responseText));
}
}
}
);
The other alternative would be to use the "complete" property of the object you pass to jquery's ajax method. complete fires when the request has completed, regardless of whether the result was an error or success.
After getting that working though, I found that image links weren't working (they are meant to zoom into where the image is and load its info bubble). I saw that the request was returning kml, that looked okay. I tried to validate the KML, but didn't get very far with that.
I downloaded the feedvalidator software from feedvalidator.org, but when I ran it, it just seemed to get stuck in the background.
So next I tried to find something for Komodo Edit. After some googling and testing I found the following command to validate an xml file against an xsd schema. (The KML schema is here). In Komodo Edit I went to Tools > Run Command...
and ran
xmllint %F --noout --schema /home/djeyewater/Desktop/kml21.xsd
That gave me
/home/djeyewater/Desktop/Text-1.txt:3: element kml: Schemas validity error : Element '{http://earth.google.com/kml/2.0}kml': No matching global declaration available for the validation root.
Hmm... no idea what that means.
Then, when I was writing the above, I realised that the reason the feedvalidator program probably went into the background and didn't work was because it works on a specified URL, and the URL I input had an & in it. So I retried with the URL quoted, which gave me the error
line 25, column 49: Invalid altitudeMode
I checked it up, and I had clampedToGround
, when it should be clampToGround
. I don't think that will be the problem causing my links not to work, but at least I can correct it. the feedvalidator program is also better than using the xmllint command in Komodo Edit as it works on URLs rather than files. So I can point the feedvalidator program to my KML generating script rather than having to run the KML generating script manually and saving the results in a file.
Rather annoyingly, the image links work on a static KML file, even though they are exactly the same as the ones that don't work on the dynamic file. Also, the links do work on the dynamic file on my live website (which is the same as my testing website)! So I am going to have leave debugging this problem until tomorrow I think.
Thursday, 15 December 2011
article photo finding
This morning and some of the afternoon I was mostly checking my emails and finding relevant CC licensed photos on Flickr to illustrate a couple of photo tips articles. You'd think that using article directories to source articles for your website would make the process of getting a new article up extremely quick.
But actually you have to wade through loads of rubbish articles before you find a good one. Then you have to find relevant CC licensed photos of flickr to illustrate the article, which can also take quite a long time. Still, I find it quite a bit faster than writing an article myself. I would say it takes me about one day to write an article myself.
Also this afternoon, I finished off my Christmas video for this year. This one is just done on the computer, no photo taking for animation.
Credits:
- MacCutcheon Whisky from screenshot by Lostpedia
- Santa in sleigh cc licensed ( BY ) flickr photo by Ben Sutherland
- Background by Stock flash on istockphoto
- Lost clips copyright Bad Robot / ABC
In the evening I watched Wing Chun and read camera websites while waiting for stuff to copy / move / delete on Mauser's hard drives.
Tuesday, 13 December 2011
Traumatic experience with Hostgator support
Wow, I just have spent a week trying to get favicons working on my wordpress multisite installation! Getting them working in my dev environment was quite easy (after getting apache set up okay), just had to read up about rewrite maps in apache and nginx. The problem was with my webhost, Hostgator.
First problem was after I had got favicons working correctly in dev site, I messaged Hostgator and asked them to set up a rewrite map. I had read here: Question regarding rewritemaps and shared hosting (I can modrewrite) that Hostgator said they did support rewrite maps. However, when I sent my request to them, they said they didn't support rewrite maps.
Not too much of a problem, I just re-wrote the map using SetEnvIf. A bit more work for the server on every request though. This worked, but I found that requests for favicon.ico were being replied to with no content. After doing some debugging, I could only conclude that this was a problem with Hostgator's server setup.
So I contacted them again, they said there was no problem or configuration issue with their server, the problem must be with my .htaccess. They don't offer a service of customising .htaccess files, so I'd have to find out what the problem was myself.
So I made a test case and sent the info to them. The rewrite rule I was using was
RewriteRule ^/files/ wp-content/favicon.ico [L]
They replied to say
I believe you'll need to rework the rule to direct files to wp-content and not a full path.
So, according to Hostgator it is only possible to rewrite to a directory, not a file?!?
I rewrote the rule as follows:
RewriteRule ^files/(.*) wp-content/$1 [L]
It's still a full path, but this time they seemed to see sense and actually investigated the issue. It turns out that they have a rewrite rule that rewrites any request for a non-existent favicon.ico file to an empty one. Since their rewrite rule is evaluated before mine, it sees that /files/favicon.ico does not exist, and rewrites it to the blank file.
Hostgator then said that they could solve this using symlinks. I replied that I didn't think that was possible due to the way the site was structured (and gave them the details). They said they could do it anyway, so I asked them to go ahead. Then, of course, they replied to say actually they can't do it due to the structure of the site.
Eventually I managed to get from them the directive they are using to rewrite the favicon.ico requests. It took me two requests though. It seems that the Hostgator support team is full of Linux sysadmins rather than anyone who's ever used apache before. With the details of the directive they were using it was immediately obvious what a simple work-around would be.
However, I first tried to add their favicon rewriting directive to my own apache config. I spent quite a bit of this morning trying to get it work, but just couldn't. It seems that either I am doing something wrong, or my apache is buggy / misconfigured so that rewrites are always relative to the document root, even when using an absolute path. So I posted on the Ubuntu forums to try and get some help with that.
Despite not getting Hostgator's favicon rewrite rule working on my dev site, I made the quick fix on the live server, and the favicons are now working properly there. The simple fix was just to create files/favicon.ico. Hostgator's rule will see the file exists, and so not rewrite it. Then my rewrite rule will see that the url matches ^/files/ and rewrite it to the correct location for that blog - the actual files/favicon.ico is never served.
Also today I made a cake, played with making custom apertures, and wrote a bit of a photo tips article.
Wednesday, 7 December 2011
Setting up wordpress mu under apache
This morning I was still trying to get my wordpress multisite setup in my local dev environment on apache. The first problem I had was that I am using two variations of each domain - domain.con for nginx and domain.can for acessing the same site through apache. Because wordpress gets the domain name from the db (and wp_config) and checks it against the request, this meant I needed to have a separate db for .can and .con and also make some modifications to wp_config.
Otherwise if the db was for .con domains and I requested domain.can, wordpress would redirect me to .con. After getting this setup, I tried logging into the wp-admin area via the .con (nginx served) domain, but just got a couple of error messages about missing indexes in arrays etc. from some plugins. Doing some debugging I eventually tracked the problem down to wp_redirect
. The function sends a redirect header, but this header wasn't being received according to the Web Developer toolbar in Firefox.
I scratched my head for a while, then tried turning off WP_DEBUG
in wp_config. (I needed it switched on yesterday as otherwise wordpress just displayed a blank page instead of giving an error message about the mysql extension being missing). With WP_DEBUG
set to false, the admin area now loaded successfully. Of course, now I thought about it, it was obvious why the header
wasn't working - PHP had already sent output in the form of the error messages to do with the badly written plugins, and so couldn't send any headers.
It's a shame that PHP didn't also give the standard error message of 'Headers already sent' as that would have made debugging the issue much easier and quicker. Maybe that error message needs a stricter error reporting setting than wordpress uses with WP_DEBUG
switched on.
The next job was to figure out why w3totalcache was correctly serving images from a static subdomain for the .con nginx site but not the .can apache site. I found the problem was that it loads the configuration settings from a file (rather than, or maybe as well as the database). After some debugging, I found the configuration file is stored as '/wp-content/w3-total-cache-config-domain.con.php' (I spent quite a while looking in the plugin directory as I thought it would save its files in there). So I just copied that file, renamed it to '/wp-content/w3-total-cache-config-domain.can.php and replaced the references in it to domain.con with domain.can.
Tuesday, 6 December 2011
websiting
This morning I wrote a blog post for my web development blog about using .htaccess to make a browser download an image from a link instead of just opening the image in the browser.
I noticed that the favicon for the blog was the same as the one for my photo tips website, so I thought I'd better change that. Looking into that, I found that I didn't have a full copy of my wordpress multisite in my dev (virtual) machine. So I downloaded the files that looked to be missing from the server, and updated the local database with a copy from the server.
Then I found that my recipes website wasn't working properly on my local machine. I checked up what the problem was, and I was missing a rewrite rule. The webserver my wordpress multisite is on uses apache, while my local dev environment uses nginx, so I had to have a few tries before I got the rule working properly. Then I thought about what the rule was doing, and it was sending requests for static images to a PHP page that would then serve the image file. Not good!
To do some testing on getting it working properly I really needed to get apache working in my local setup, so I spent quite a bit of time working on this.
Most of the evening I was trying to work out why PHP wasn't loading any extensions. In the end I worked out the problem was that my php.ini file has [HOST] and [PATH] sections in it. After loading my php.ini file PHP would then go onto load other configuration .ini files that loaded mysql and the other extensions. But because they were below a [HOST] section, the directives in the other .ini files were only being applied for that host, and not globally. The fix was at the bottom of my php.ini file to put [PHP]. That switched it back to the global section, so directives in the other .ini files to load the extensions were treated globally (or at least not ignored).
I still have quite a bit of work to do to get PHP and apache working properly together and my wordpress multisite running it looks like though.
Monday, 5 December 2011
Various
This morning I was going through some old emails that I hadn't had time to check properly, and one was from 7dayshop for an interesting gadget - Capture Camera Clip Strap/Belt System by Peak Design (affiliate link). It's basically a quick release system that you can attach to your belt or bag strap. Initially I thought this wouldn't be that great since if you wanted to mount the camera on a tripod or monopod, you'd have to remove the proprietary quick release plate and then attach a QR plate compatible with your tripod / monopod head. This would be a hassle and take too long.
But actually, according to their video, the proprietary QR plate they use is arca-swiss compatible. Since I use arca-swiss compatible QR clamps on all my tripod heads, this would mean the camera could be used on a tripod or monopod with no hassle at all. However, £50 seems extremely expensive to me, I might consider one if they were £20, and would probably buy one if it was £10. Having my camera on a strap as I do now is not much inconvenience compared to putting it on a belt clip, so not worth the price for me.
Most of the afternoon and some of the evening I worked on an article for my photo tips website. Also in the evening I played on Kirby Wii with L and Mauser, and did some work trying to make a file download prompt in .htaccess
Sunday, 4 December 2011
Various
Saturday, 3 December 2011
Walking
I forgot to post a pic of these Intel sweets Mauser got from work a few weeks ago:
After copying those pics across to my comp, and writing yesterday's blog post, I went out for walk as it was nice weather. I stopped to take some test shots not too far from the house, and then realised that I needed another adapter ring to be able to some of my srew-in filters with my Cokin P filters as well.
So I went back home, then as it was only about 1½ hrs until lunch, I decided to make some cake. But I remembered that actually I needed to leave the fruit soaking overnight, so I couldn't make the cake now. So I made some cheese straws instead.
After lunch I went out for another walk, this time making sure I brought the other adapter ring I needed. Part of the walk was a bit scary as I had to walk through a field of bulls. The bulls ran up behind me, and when the lead one tried to stop he just carried on skidding forwards across the muddy field towards me. But luckily he stopped before he got me.
The main annoying thing about the walk was that the footpath ended up at a road, and then there wasn't any way to get back to the town except walking back along the side of the road, or going all the way back down the footpath I'd walked across. Also, the path wasn't very well sign posted when it got into Northamptonshire.
When I got back home I geo-coded and sorted the photos, then had dinner.
After dinner I played on Kirby Wii with Belly and Mauser, then we all went to see KK in animal crossing. After that I went to bed about 9pm as I felt really sleepy and had a headache.
Friday, 2 December 2011
Various stuff
This morning I helped someone with their wireless printer / internet not working properly. I spent quite a while trying to figure out why their laptop couldn't connect to the printer. Then when I tried to go on the internet to google for info, I found that actually the problem was that the laptop wasn't connected to the router. Doh! The problem actually seemed to be with the BT wireless connection software they had installed.
The BT software said that it was connected OK, but the internet and printer wouldn't work. If you went into Windows Wireless settings and selected something like 'Use Windows to configure my wirless settings', then the wireless would work OK. But upon restarting the computer, the BT software would take over again, and it would stop working. So I went into msconfig and disabled a couple of startup programs that looked like they might be the BT software. After restarting, it worked okay, and could now connect to the printer. Yay!
I spent most of the afternoon writing an article for my photo tips website.
In the evening I played on Kirby Wii with Mauser and Bo for a bit, and then photoshopped some Boglins of them:
Thursday, 1 December 2011
Site Analysing
Someone had replied to my question on the jquery forums about debugging why an AJAX request failed, and they asked me to post exactly what is in the responseText
. I did try printing out responseText as part of my debugging yesterday, but as it contained HTML, it was being converted to HTML rather than printed as plain text. I remembered this morning about textNodes, and decided to try printing the responseText as a textNode. I used jquery's text() method, and this worked fine.
The only difference between the responseText printed by jquery and the content body of the server's response was that text() collapsed multiple whitespace to a single space. I posted the responseText to the thread as had been requested, though haven't received any reply yet. I am actually quite surprised I got a reply at all, I don't seem to have much luck getting replies (particularly helpful replies) on forums.
I would say sitepoint is probably the best forum, out of the 24 threads I've started there, I got helpful replies on 12 of them. Usually I get replies from people trying to be helpful as well, I only have a few threads there with no replies. For this jquery issue I get the feeling I'm going to have to spend many hours whittling my code down and constant testing until it either starts working or I have a test case suitable for filing a bug report.
I also processed a pano today, and ran the ISS Site Analyser a couple of times on my site. It did find lots of stuff wrong with my site, so still lots to fix.
Wednesday, 30 November 2011
Just Buggin'
Yesterday evening I thought that I had finished making the needed changes to my photo website and could run it through the Microsoft Site Analyser tool just to make sure everything was okay this morning. But then, even before I did that, I found a problem, and then some more problems.
One thing I did do was to add <link>
s to my pages for self, next, prev, last, first, and up. I hadn't heard about rel="up"
before, but found out about it on this page: The WHATWG Blog — The Road to HTML 5: Link Relations - rel=first, last, prev, next, and up. Up means the category page the current page is a direct descendant of.
I spent most of the afternoon trying to debug why the javascript in my KML wasn't working properly in Google Earth. Unfortunately the lack of any debugger in Google Earth makes debugging very difficult. What I had to do was to delete the KML from the 'Temporary Places' folder in Google earth, then clear the memory and disk cache. I would make a small change in the javascript, then reload the KML file and see what difference it made. Then repeat.
Any debugging messages had to be output to the HTML of the infoBubble window, you can't do Alert
s in Google Earth. Despite spending all afternoon on it, I still couldn't work out why my javascript wasn't working properly. The problem was with an AJAX request made by jquery, when it got the response it would fire the error handler rather than the success handler. But I couldn't get any info on what the error was, so I posted to the jquery forums in hope that someone there can help me.
One thing I came across while trying to solve this problem was that my server was sending a Content-Type header of text/html for the JSON response. This is because the JSON is generated by PHP, and I wasn't setting an explicit Content-Type header with PHP. So I did some research and found the correct Content-Type header for JSON is application/json
. I wondered if I should also put charset=utf-8
, however according to this article: Setting the HTTP charset parameter, you only need to do that for Mime types of text/x, not application/x.
In the evening I moved all the stuff (except my bed) out of my bedroom and into L's bedroom as we are currently having all the bedrooms re-carpeted, and mine is next.
Tuesday, 29 November 2011
URL encoding
Today I was doing more work on my photo website.
I wanted to try and find the regex that wordpress uses for converting page / post titles into permalinks (also known as 'slugs'). However despite much googling and searching through the source code (wordpress codebase is too large to search properly), I didn't find anything.
So instead I made my own:
/**
*Replace ' with nothing e.g. don't becomes dont, other punctuation replaced with a - with max one dash between words
*@param $str The string to be encoded
*@return $str The encoded string
*/
function myurlencode($url){
return preg_replace('/[!"#$%&\'()*+,\/:;<=>\-?@\\\[\]^`{|}\s]+/', '-', str_replace("'", '', $url));
}
Unless I've made a mistake (quite possible), this should replace any punctuation or space with a dash, with multiples being collapsed to a single dash, e.g. 'hel!o - there' should become 'hel-o-there'. I also elected to change words like don't to dont rather than don-t or don%27t. So this should allow me to use RFC3987 compatible IRIs/URLs without using any percent encoding at all (since all characters that need percent encoding are removed or converted to dashes).
Because &, <, >, ", and ' are removed / converted to dashes this also means that the url doesn't need to be run through htmlspecialchars before printing as part of a webpage / xml doc either. The function doesn't deal with all characters not allowed in URLs per RFC3987, but these are control characters or reserved blocks that there is virtually 0% chance will be in any string I run through the function.
After some help on the sitepoint forums, I managed to get a regex that should work to encode a URL per RFC3987 correctly. I tested it against a more simplistic str_replace function and another regex that don't bother trying to encode later blocks (which tend to be reserved / not used). So these functions all encode control chars and should be good enough (I think) to make a url comply with RFC3987, similar to how rawurlencode works for RFC3986.
function iriencode($url){
$notiunreserved = array("\x25","\x0","\x1","\x2","\x3","\x4","\x5","\x6","\x7","\x8","\x9","\x0a","\x0b","\x0c","\x0d","\x0e","\x0f","\x10","\x11","\x12","\x13","\x14","\x15","\x16","\x17","\x18","\x19","\x1a","\x1b","\x1c","\x1d","\x1e","\x1f","\x20","\x21","\x22","\x23","\x24","\x26","\x27","\x28","\x29","\x2a","\x2b","\x2c","\x2f","\x3a","\x3b","\x3c","\x3d","\x3e","\x3f","\x40","\x5b","\x5c","\x5d","\x5e","\x60","\x7b","\x7c","\x7d","\x7f","\xc2\x80","\xc2\x81","\xc2\x82","\xc2\x83","\xc2\x84","\xc2\x85","\xc2\x86","\xc2\x87","\xc2\x88","\xc2\x89","\xc2\x8a","\xc2\x8b","\xc2\x8c","\xc2\x8d","\xc2\x8e","\xc2\x8f","\xc2\x90","\xc2\x91","\xc2\x92","\xc2\x93","\xc2\x94","\xc2\x95","\xc2\x96","\xc2\x97","\xc2\x98","\xc2\x99","\xc2\x9a","\xc2\x9b","\xc2\x9c","\xc2\x9d","\xc2\x9e","\xc2\x9f","\xef\xbf\xb0","\xef\xbf\xb1","\xef\xbf\xb2","\xef\xbf\xb3","\xef\xbf\xb4","\xef\xbf\xb5","\xef\xbf\xb6","\xef\xbf\xb7","\xef\xbf\xb8","\xef\xbf\xb9","\xef\xbf\xba","\xef\xbf\xbb","\xef\xbf\xbc","\xef\xbf\xbd");
$notiunreservedEncoded = array('%25','','%01','%02','%03','%04','%05','%06','%07','%08','%09','%0A','%0B','%0C','%0D','%0E','%0F','%10','%11','%12','%13','%14','%15','%16','%17','%18','%19','%1A','%1B','%1C','%1D','%1E','%1F','%20','%21','%22','%23','%24','%26','%27','%28','%29','%2A','%2B','%2C','%2F','%3A','%3B','%3C','%3D','%3E','%3F','%40','%5B','%5C','%5D','%5E','%60','%7B','%7C','%7D','%7F','%C2%80','%C2%81','%C2%82','%C2%83','%C2%84','%C2%85','%C2%86','%C2%87','%C2%88','%C2%89','%C2%8A','%C2%8B','%C2%8C','%C2%8D','%C2%8E','%C2%8F','%C2%90','%C2%91','%C2%92','%C2%93','%C2%94','%C2%95','%C2%96','%C2%97','%C2%98','%C2%99','%C2%9A','%C2%9B','%C2%9C','%C2%9D','%C2%9E','%C2%9F','%EF%BF%B0','%EF%BF%B1','%EF%BF%B2','%EF%BF%B3','%EF%BF%B4','%EF%BF%B5','%EF%BF%B6','%EF%BF%B7','%EF%BF%B8','%EF%BF%B9','%EF%BF%BA','%EF%BF%BB','%EF%BF%BC','%EF%BF%BD');
return str_replace($notiunreserved, $notiunreservedEncoded, $url);
}
function preg_iriencode($url){
return preg_replace('/[^0-9a-zA-Z\-._~\x{00A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}]+/eu', 'rawurlencode("$0")', $url);
}
function preg_iriencode_basic($url){
return preg_replace('/[\x{0000}-\x{009F}]+/eu', 'rawurlencode("$0")', $url);
}
$i=0;
$url = 'Exclamation!Question?NBSP Newline
Atsign@Tab Hyphen-Plus+Tilde~好';
$iriencode = 0;
$preg_iriencode = 0;
$preg_iriencode_basic = 0;
$methods = array('iriencode','preg_iriencode','preg_iriencode_basic');
while($i<500){
shuffle($methods);
foreach($methods as $method){
$start = microtime(true);
$method($url);
$end=microtime(true);
$$method+=($end-$start);
}
$i++;
}
foreach($methods as $method){
echo $method.number_format($$method/500, 30);
}
Example results:
- preg_iriencode 0.000042529106140136717665797828
- preg_iriencode_basic 0.000018751144409179686578428153
- iriencode 0.000083773136138916016709202172
I did try a 50,000 run loop but the str_replace function decreased in performance a lot. At 500 loop performance is similar to a single loop. I will be sticking to my myurlencode function though, at least until I find some problem with it.
Monday, 28 November 2011
RFC3987
This morning I was doing some work on my photo website, and then did a bit of work on my christmas list. While I was searching for things to put on my christmas list, I came across this page where someone has made a DIY CNC miller! I wouldn't have thought many people would build something like that, though it seems quite popular: http://www.instructables.com/id/Easy-to-Build-Desk-Top-3-Axis-CNC-Milling-Machine/.
Most of the afternoon and evening I spent looking into RFC3987 and how to implement it. It is similar to RFC3986 for encoding urls, but allows many unicode characters like Chinese etc. Sadly it doesn't allow many characters like '(' and ',', which are reserved under both schemes. So I will still get messed up looking URLs with it, but I can't complain too much.
Saturday, 26 November 2011
Debugging errors that don't exist
This morning I was still trying to debug my problematic google maps page. In Firefox on Ubuntu, I was getting tons of errors, so I tried cutting the page down bit by bit, making it more and more basic. The idea being that when I remove a bit and then the page starts working properly, I know that it must have been something in the bit of code I just removed that was causing the errors.
However, I cut the page down to almost as basic as you can get, and was still getting the same errors. Then I tried the Google Maps tutorial map, and found that had the same issue. I thought I should post on the Google Groups maps API v3 about the issue, but first should check if the issue only occurs in Firefox on Ubuntu.
After opening the page in IE6, I found that all the layout of the images in the info bubble was all messed up. I used the Web Developer Tools to check the properties of the <span> that was meant to make the images display correctly in IE6, and it looked like it didn't have any style set by stylesheets.
So I Ctrl-clicked on a link on the page to open in a new window the main photos area of my website. This uses the same html and stylesheets for displaying images as I have inside the info bubble in Google maps, so I wanted to see if the image display was messed up there as well. But rather than opening the page in a new window, it opened it in the same window. So I clicked the back button to get back to the map, and opened up the info window again, but this time the images were all displayed correctly. I checked the <span> using Web Developer Tools, and now it had the correct styles applied to it. It makes it very difficult to debug real problems when browsers change their behaviour on each page load.
When testing in Google Chrome, I had erratic behaviour with that as well. For example, one time the map loaded up blank so I checked the developer tools, and the first part of the page was shown to be:
<script>
$.ajaxSetup(("async" : true});
i.e. the first 21 lines of the html were blank, and the 22nd line is missing it's type="text/javascript" attribute. I refreshed the page, and still got a blank screen, but now the HTML code was showing correctly in the Developer tools.
After this I had a problem with the text inside a noscript tag not being styled correctly. I found this forum thread: NoScript - css background? and if you scroll about half way down the page, you can find a post by penders that lists the way different browsers deal with styling content inside noscript tags. Some browsers ignore rules applied to a noscript element in css, but will honour rules if you instead apply them to a containing element, such as a div, within the noscript tag. Seems very strange behaviour to me.
After finishing testing on the different browsers, I wrote a post to put on the Google Maps API v3 group:
I am having the same issue as detailed in this thread: http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/9fce9c1a493b3413?pli=1
But, only on Firefox in Ubuntu. The other browsers I have tested (Chrome Win7, IE6 Win XP, IE7 Win XP, IE8 Win XP, IE9 Win7, Firefox Win7, Safari Win7, Opera Win7, K-Meleon Win7) do not have this problem.
The errors happen on any google map, including the example tutorial map: http://code.google.com/apis/maps/documentation/javascript/examples/map-simple.html
Both when the map is loading and when the cursor is moved over the map, thousands of errors will occur, e.g.
Warning: reference to undefined property a[oo] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 68 Warning: reference to undefined property this[a] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 26 Warning: reference to undefined property this[a] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 26 Warning: reference to undefined property a[pc] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 53 Warning: reference to undefined property a[oo] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 68 Warning: reference to undefined property this[a] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 26 Warning: reference to undefined property this[a] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 26 Warning: reference to undefined property a[pc] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 53 Warning: reference to undefined property a[oo] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 68 Warning: reference to undefined property this[a] Source File: http://maps.gstatic.com/intl/en_gb/mapfiles/api-3/7/2/main.js Line: 26The version number of Firefox for Ubuntu is 3.6.24. I have disabled all extensions and add-ons and still have the same problem.
However, after writing this, but thankfully before I posted it, I found out what the problem was. I had javascript strict error checking set to true in Firefox on Ubuntu, but not on any of the other browsers. Sure enough, I turned strict error checking off (type about:config into the address bar to get to the settings), and now didn't get any errors other than one mismatched mime type error. Likewise, I set strict error checking to true on Firefox in Win7, and started to get the stream of near constant errors.
I am unsure if I originally turned strict error checking on, whether Ubuntu Firefox comes with it turned on by default, or if one the extensions e.g. firebug turned it on. But at least with it turned off I now won't get a constant stream of error messages and can hopefully debug why my page isn't working correctly in Ubuntu Firefox.
I also tried to see if I could turn strict error checking on in Chrome. I found this post Re: [chromium-dev] Re: enabling javascript strict warnings and errors?, which suggested using --strict when starting chrome to turn on strict error checking. Unfortunately that didn't seem to make any difference.
Interestingly, after turning off strict error checking in Firefox, I found that my Google Maps page now worked correctly. So all of my work yesterday and today has been mostly debugging errors that don't exist.
The rest of the afternoon and first part of the evening I made a lemon & coconut cake with Belly. Then most of the evening I spent listing my communist santa hats on ebay. I also went to see KK on Animal Crossing as well.
Friday, 25 November 2011
Trying to debug problems with google maps page
I spent quite a while trying to debug why a page on my site wasn't working properly in FF on Ubuntu. However, when I opened firebug I found that it was too slow to do anything. Checking the CPU usage for my VM, I found that the VM was using between 20-50% CPU (40-100% of one core), usually it is 0-3%. So I tried to figure what it was on my webpage that was causing CPU usage to spike so high.
Eventually, after a few hours and much trial and error, I discovered the problem was actually a different site I had open in a different tab: http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/
It gave a constant stream of the following error message:
Warning: reference to undefined property window.Dialog
Source File: http://static.ak.fbcdn.net/rsrc.php/v1/y6/r/naNy-PS2iP8.js
Line: 54
I had always thought that when you opened firebug, it would attach itself to the current tab, and only report errors etc. from that tab. It seems I was wrong.
Now I finally have that sorted, I can get down to the job of figuring out why my site isn't working properly!
I'm having a lot of trouble debugging the problem with my site, specifically the problem is with a Google Maps page. At first the info window would open when you clicked on a marker (correct behaviour), but then immediately close (incorrect behaviour). Then when trying to debug that, it happened that the marker window wouldn't open at all. Trying to debug that, the markers stopped showing up. And trying to debug that, now the map doesn't even load and I just get a grey page.
And annoyingly, the original problem is only showing in Firefox on Ubuntu (well at least it's not showing in Chrome and Firefox on Win 7), so I can't try debugging the problem in a different browser.
It also seems like Firebug might be having trouble, as later doing some debugging I got error messages like
A script on this page may be busy, or it may have stopped responding. You can stop the script now, or you can continue to see if the script will complete.
Script: file:///home/djeyewater/.mozilla/firefox/f8kz0h7v.default/extensions/firebug@software.joehewitt.com/modules/firebug-service.js:266
and the VM started using 50% of CPU (100% of one core).
I noticed that whenever I ran the mouse cursor over the map, the error console would fill up with errors like
reference to undefined property a[pc]
(53 out of range 43)
main.js (line 53)
reference to undefined property a[oo]
(68 out of range 43)
main.js (line 68)
reference to undefined property this[a]
var tf=sf(-fa,-fa,fa,fa),uf=sf(0,0,0,0...his.set(b,c)}};I.setOptions=V[C][Eb];
main.js (line 26)
reference to undefined property this[a]
var tf=sf(-fa,-fa,fa,fa),uf=sf(0,0,0,0...his.set(b,c)}};I.setOptions=V[C][Eb];
main.js (line 26)
In the end, I still haven't worked out what the problem is yet. Maybe tomorrow...
Wednesday, 23 November 2011
How to update multiple rows in mysql and rant against rfc3986
Today I was doing some work on my photo website and needed to update all the records in a table, but each row needed to be updated to a different value. So I looked for ways to do this, and it seems there are a few:
- Do a separate query for each row
- Use a prepared statement to do a separate query for each row
- Do an INSERT ON DUPLICATE KEY UPDATE
- Use CASE (same as switch in php I think - I'm not convinced that it would efficient)
- Insert the new values and old keys into a temporary table, then use that in a JOIN to do the update
If I get a minute (unlikely) I will test the different methods to see which is most efficient.
I was working on creating a feed for my site, and reading this tutorial on ATOM feeds, I liked the source of the comment they use to get around browser's not applying XSL stylesheets:
I employ an excerpt in Esperanto translation from the first chapter of a Polish novel about ancient Egypt.
As part of my work on creating a feed for the site, I have had to change the url structure to be encoded as per rfc3986. I don't agree with the restrictive ASCII only nature of rfc3986, in my opinion we should have moved beyond that by now and chinese characters etc. should be valid in URLs. rfc3986 to me comes across like so long as we don't have to encode characters in english it's okay, the rest of the world will just have to put up with encoding their characters as we don't care about them
. That's probably not actually the case, but just the way it seems to me.
As well as this, some web browsers display unencoded urls correctly in the address bar, but display encoded urls in their encoded form e.g.
If I link to a page as http://zh-yue.wikipedia.org/wiki/ä¸æ–‡ it will display as http://zh-yue.wikipedia.org/wiki/ä¸æ–‡ in the address bar.
However, if I link to the url encoded as per rfc3986 http://zh-yue.wikipedia.org/wiki/%E4%B8%AD%E6%96%87, it will display in the address bar as http://zh-yue.wikipedia.org/wiki/%E4%B8%AD%E6%96%87
Now I know which looks much nicer to me as a url, especially if my native language was Chinese. It should be noted that for the unencoded url, the browser will encode the url itself when it makes the page request, but will display the unencoded url in the address bar. So by using unencoded urls, you do not avoid rfc3986, but rather the encoding responsibility for requests is put on the browser's shoulders.
I believe Google Chrome is much better in this aspect than IE (what a surprise!) and displays the unencoded url in the address bar even if the page was loaded from an encoded link. Unfortunately IE is the most popular browser, so it is important how things appear in it.
There is also an issue of filesize - an encoded url will take up more space than an unencoded url. Not a big issue, but another reason against encoding urls. (For the above example the encoded url is 51 bytes while the unencoded url is 39 bytes when both are saved as UTF-8, and that's with only two of the 35 characters being encoded).
Anyway, despite my disagreement with rfc3986 I still need to implement it to make the feed valid. Plus my not using it has probably made some pages on my site not discoverable by Google or accessible by some strange web browsers / bots.
So while I was looking at converting my urls to be compliant with rfc3986, I wondered about how I was structuring my URLs with regard to pagination and SEO. I found quite a bit of info on this subject: http://www.google.com/support/forum/p/Webmasters/thread?tid=344378292ff91e8d&hl=en&start=40#fid_344378292ff91e8d0004af9f4a5efbe7.
I have still got quite a bit of reading to do, but what I gather so far is:
- Use rel=next and prev links in the <head> for paginated pages
Use query string parameters for the page (and other parameters) rather than including them as part of the URL (which I am doing at the moment - oops):
@katty22: One thing I’d like to mention is that for interchangeable/filterable options, it’s more search engine friendly to keep the options as parameters, not as subdirectories. For example, we’d prefer this URL:
http://www.example.com/item?story=abc&price=up&page=1
rather than:
http://www.example.com/story=abc/price=up/page=1Unlike some articles suggest, if you have four pages that are the same, except for a url parameter, and each 'page' has a single link to it, this will not be any worse SEO-wise than having one page with four links to it. Google will automatically identify the pages as being the same as group them into a cluster:
When Google detects duplicate content, such as variations caused by URL parameters, we group the duplicate URLs into one cluster and select what we think is the "best" URL to represent the cluster in search results. We then consolidate properties of the URLs in the cluster, such as link popularity, to the representative URL. Consolidating properties from duplicates into one representative URL often provides users with more accurate search results.
source: http://www.google.com/support/webmasters/bin/answer.py?answer=1235687- I was interested about this suggestion on pagination. The article suggests that you shouldn't have more than 100 links on a page, and that comment suggests only linking certain pages using logarithmic pagination.
I haven't read any guidance from Google on this yet. At the moment I have all pages linked and then use js to reduce this for the user, e.g. for page 45 js would reduce the links to look like
1, 2, [...] 43, 44, 45, 46, 47, [...], 120, 121
And the user can expand back to showing all linked pages by clicking on the [...]So this is something I need to look at more closely.
I hope to do some more research and reading on this aspect of SEO tomorrow.
Tuesday, 22 November 2011
Blah de blah blah blah blah
Yesterday I was checking the dpreview forums and came across this thread about slit scan photography. Investigating a bit more I found this long list of Slit scan photography. The list is so long that I only finished reading it today. One of the photographers listed on there I think I have seen the work of before, and he has a couple of other nice projects as well: Adam Magyar.
After doing quite a bit of reading on the subject, it seems that digital slit scanning requires a video camera, then taking a slit from each frame and blending the slits together on the computer. Streak photography on the other hand is used with a static subject. So you can use a still camera and move the subject or camera a very small amount between each frame. Then, just as with the video you need to extract a slit from each image and blend them into a single image.
Also today and yesterday I was working on a couple of articles for my photo tips website. In the evening both days I have gone on Civ IV. Today I won a domination victory on it, so for the rest of the evening I checked Google Webmaster Tools and Bing webmaster tools stats for my websites.
On Bing I noticed that a Google gadgets page had lots of links (in different languages) to a KML file on my photo website. So I checked it and it was one of my static KML files that I must have submitted quite a while ago. I couldn't see any way to submit KML files from the KML gallery, but found the submit page by googling for it. So I submitted my dynamic kml file for my photo website.
I also checked out the KML from a guy who spent 30 months touring Asia, lots of nice places and photos.
Friday, 18 November 2011
Reading emails
So I spent a while fixing that and trying to work out what had gone wrong.
Then I had an email about Google+ pages, so I set one up for my photography tips website. It seems you can't get a 'vanity' url, so I followed the recommendation here: HOW TO: Get Your Own Google+ Vanity URL. It's not a hack to actually get a custom url, rather just using a service similar to bit.ly so you can give people an easy to read url that will then redirect to the Google+ page.
I also followed the procedure here: Add Google+ Profile Buttons On Your Blog to add a button on my site that links to my google plus page.
A link I forgot to post yesterday was Alternatives to illegal
or
within
li:before{This inserted an inline element as the bullet, but since this was followed by a block element (
content 'some unicode code point';
}
) in my page, this meant there would be a line break between the bullet and the paragraph e.g.
>To fix this I changed:
Some text in a paragraph here
li:before{and this seemed to fix it.
content 'some unicode code point';
display: block;
float: left;
}
Most of the afternoon today I was checking my email. I also tried out an RSS feed submitter called Traffic Launchpad.
In the evening I watched The Woman In The Window with Mauser and Bo, then watched Autumn watch with Belly & McRad.
Thursday, 17 November 2011
Walking and photoing
In the evening I sorted some of the photos from the afternoon's walk and also went out to take some star photos. Unfortunately there seems to be too much light pollution here, even out in the a field. This isn't a densely populated area, there is the town in one direction, then various villages dotted around in other directions. I guess you have to be really far from civilization to get good night sky photos.