Posts Tagged ‘php’

Printer friendly Fudzilla RSS

Wednesday, September 29th, 2010

Fudzilla is a nice site for catching up with daily tech news. I prefer to set up my email client Thunderbird to aggregate the RSS, but when you have a 1920×1200 monitor and Fudzilla still puts so much crap at the top of the article that it ends up looking like this and you have to scroll down before you can even read a few lines of text, its becomes a terrible user experience.

Wouldn’t it be better to get the text at a reasonable size, taking 100% of the width available, with no crap at the top that you have to scroll past?

Well, you can. The printer friendly view does all of this, and all you have to do is change the link in the RSS to use the printer friendly URL instead of the standard one. Here is some php do do just that! Just put this on a server somewhere and subscribe to that URL instead of the normal fudzilla feed.

<?php
header("Content-Type: application/rss+xml; charset=utf-8");
 
$url = "http://www.fudzilla.com/?format=feed";
 
$rss = fopen($url, "rb");
$contents = stream_get_contents($rss);
fclose($rss);
 
$contents = str_replace("?</guid>", "%3f</guid>", $contents);
$contents = str_replace("</guid>", "?tmpl=component&amp;print=1</guid>", $contents);
echo($contents);
?>

You may be able to just view the description in your RSS aggregator, but it tends not to show the whole article. In the past, fudzilla has put just the subtitle in there, for example.


Update: This has been broken by fudzilla using a HTTP 302 redirect and a cookie but anything that will take the cookie from the first request and use it for the second request should be able to handle this easily. Here’s a function for it that uses cURL.

function download_string_curl($url)
{
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_AUTOREFERER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
  curl_setopt($ch, CURLOPT_COOKIEFILE, "THIS_FILE_DOES_NOT_EXIST");
  $contents = curl_exec($ch);
  curl_close($ch);
  return $contents;
}

As a note to Fudzilla: This is only necessary because of the sheer amount of crap you put at the top of your page. You shouldn’t have to scroll down an entire screen height before you can even see the content of that page. That’s just poor design. If adding cookies and a redirect was an attempt to stop screen scraping, it didn’t work. You can disable that now and save yourself some bandwidth.

Remote recursive sha1sum with php

Wednesday, June 2nd, 2010

To calculate the SHA-1 sums, display them and make them available for download in a sums.gz file:

<?php echo(`find ./some_directory/ -type f | grep -v sums.gz | xargs sha1sum | gzip -c | tee sums.gz | zcat`); ?>

To check the sums:

<?php echo(`zcat sums.gz | sha1sum -c -`); ?>

wp-syntax to look like Visual Studio

Tuesday, March 23rd, 2010

wp-syntax is a nice plugin for WordPress using GeSHi to produce syntax highlighted blocks of code.

The default colours aren’t very nice though, and there is no way to easily change them. wp-syntax-colorizer (horrible name) makes it easier to set the colours, but defaults to even worse colours.

Most of us want readable colours that we are used to from IDEs, and most of us will be using either Visual Studio or Eclipse. I mainly use the former. To get it to use the visual studio colours I edit wp-syntax-colorizer as follows:

function my_custom_geshi_styles(&$geshi)
{
  $overall = "black";
  $keyword = "blue";
  $literal = "maroon";
  $comment = "green";
 
  $geshi->set_overall_style("color: $overall;", true);
 
  $geshi->set_keyword_group_style(1, "color: $keyword;", true);
  $geshi->set_keyword_group_style(2, "color: $keyword;", true);
  $geshi->set_keyword_group_style(3, "color: $keyword;", true);
  $geshi->set_keyword_group_style(4, "color: $keyword;", true);
 
  $geshi->set_symbols_style("color: $overall;", true);
  $geshi->set_methods_style(1, "color: $overall;", true);
  $geshi->set_regexps_style(1, "color: $overall;", true);
 
  $geshi->set_strings_style("color: $literal;", true);
  $geshi->set_numbers_style("color: $literal;", true);
 
  $geshi->set_comments_style(1, "color: $comment;", true);
  $geshi->set_comments_style('MULTI',"color: $comment;", true);
}

WordPress theme: Kubrick (wide)

Tuesday, February 17th, 2009

The default WordPress 2.7 theme is Kubrick. It’s nice but it is optimised for 800×600 and most people use more than that, so I decided to modify it slightly to optimise for 1024×768 or a similar width. Because of things like window borders and scrollbars, we do not want the width to be exactly 1024 pixels wide so all we do is use the existing widths and add the difference between 1024 and 800 to them. This is a 224 pixel increase in width so if something was 760 it would become 984, if it was 740 it would become 964, etc.

Several files need to be changed for this (make backups beforehand):

The 3 jpeg files are quite straightforward. I just opened them in Microsoft Paint, increased the width by 224 (image -> attributes) making them 984 wide, then dragged the right side of the old image to the right side of the new image and stretched out the middle section to fill the space.

The php file is a bit more complicated. This file reads kubrickheader.jpg, modifies it with your chosen colours and adds the white rounded corners. Again, the only changes here are adding 224 to some of the numbers in this file. We don’t even need to work these out, we can just append “+224″ to the existing numbers where appropriate. First we change the $corners array from
0 => array ( 25, 734 ),
to
0 => array ( 25, 734+224 ),
and do this for every entry in the array.

Slightly lower down in the “Blank out the blue thing” for loop, we change
$x2 = 740;
to
$x2 = 740+224;

and again in the “Draw a new color thing” for loop, we do the same thing, changing
$x2 = 739;
to
$x2 = 739+224;

Lastly, we change the style.css. This is the most complicated part, just because the widths to change are spread out everywhere and missing one will mess the whole page up. This is a bit long to explain, so here’s the diff (modified slightly for reading clarity – don’t try to patch with it). Remember that you want to change the lines with the – in front of them into the lines with the + in front. We can’t just use +224 any more so we actually have to work them out.

As an example, in the first one (#headerimg) you just change 740px to 964px.

@@ -41,9 +41,9 @@

 #headerimg     {
        margin: 7px 9px 0;
        height: 192px;
-       width: 740px;
+       width: 964px;
        }

@@ -236,18 +236,18 @@
 #page {
        background-color: white;
        margin: 20px auto;
        padding: 0;
-       width: 760px;
+       width: 984px;
        border: 1px solid #959596;
        }

 #header {
        background-color: #73a0c5;
        margin: 0 0 0 1px;
        padding: 0;
        height: 200px;
-       width: 758px;
+       width: 982px;
        }

@@ -258,15 +258,15 @@
 .narrowcolumn {
        float: left;
        padding: 0 0 20px 45px;
        margin: 0px 0 0;
-       width: 450px;
+       width: 674px;
        }

 .widecolumn {
        padding: 10px 0 20px 0;
        margin: 5px 0 0 150px;
-       width: 450px;
+       width: 674px;
        }

@@ -311,9 +311,9 @@

 #footer {
        padding: 0;
        margin: 0 auto;
-       width: 760px;
+       width: 984px;
        clear: both;
        }

@@ -570,9 +570,9 @@
 /* Begin Sidebar */
 #sidebar
 {
        padding: 20px 0 10px 0;
-       margin-left: 545px;
+       margin-left: 769px;
        width: 190px;
        }

If you get lost here, you can use my style.css but if you use a different base version to me (I am on the one that comes with WordPress 2.7), my modified style.css may not work for you.

Update 2009-06-13:
With WordPress 2.8′s release, this theme has changed slightly. The right-hand navigation bar is now a different colour from the rest of the page. This is done with the kubrickbg-ltr.jpg image. I have widened mine but I am still using the old images for the rest of the site (header, footer, etc) so it does not fit in perfectly, as you can see from the top and bottom of the page.