Monthly Archives: January 2009

How to make WordPress display Full Text in RSS Feeds

... and why WordPress Moderators are obviously idiots

Today I got an email asking me to enable full text RSS feeds - so far so good, only when I activated the "Full Text" option nothing changed - neither in FireFox, nor in Google Reader, nor anywhere else. Only in Feed Proxy I saw a <content:encoded> tag appear that contained the full text (including html tags), but the description still only contained the excerpt (without html tags).

Before I link you to the thread that made me conclude the statement in the post title, let me quote from the RSS 2.0 specs:

A channel may contain any number of <item>s. An item may represent a "story" -- much like a story in a newspaper or magazine; if so its description is a synopsis of the story, and the link points to the full story. An item may also be complete in itself, if so, the description contains the text (entity-encoded HTML is allowed; see examples), and the link and title may be omitted. All elements of an item are optional, however at least one of title or description must be present.

That said take a look at http://wordpress.org/support/topic/190901 - having the problem described above and reading the replies, it just left me with one question:

If Otto42 is a moderator, where does WordPress get its trolls from?

The RSS Specs are pretty unspecific and blurry when it comes to the issue, one can at most point to http://www.feedvalidator.org/docs/warning/DuplicateDescriptionSemantics.html, but the main issue I have is that the rants of this "moderator" don't help me fix my problem, because Google Reader and FireFox still don't display the full entries.

A fix for it

If you want to fix it, you can do the following (in WP 2.7):

Open up wp-includes/feed-rss2.php and change

<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php if ( strlen( $post->post_content ) > 0 ) : ?>
<content:encoded><![CDATA[<?php the_content() ?>]]></content:encoded>
<?php else : ?>
<content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
<?php endif; ?>
<?php endif; ?>

to

<?php if (get_option('rss_use_excerpt')) : ?>
<description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
<?php else : ?>
<description><![CDATA[<?php the_content() ?>]]></description>
<?php endif; ?>

Similarly, if you want to fix your comments, too, open wp-includes/feed-rss2-comments.php and change

<?php if ( post_password_required($comment_post) ) : ?>
<description><?php echo ent2ncr(__('Protected Comments: Please enter your password to view comments.')); ?></description>
<content:encoded><![CDATA[<?php echo get_the_password_form() ?>]]></content:encoded>
<?php else : // post pass ?>
<description><?php comment_text_rss() ?></description>
<content:encoded><![CDATA[<?php comment_text() ?>]]></content:encoded>
<?php endif; // post pass

to

<?php if ( post_password_required($comment_post) ) : ?>
<description><![CDATA[<?php echo get_the_password_form() ?>]]></description>
<?php else : // post pass ?>
<description><![CDATA[<?php comment_text() ?>]]></description>
<?php endif; // post pass

Cheers,
Andreas

Seminar about Motion Retargeting

creatureanimationwbTwo weeks ago I had to give a presentation about Motion Retargeting, which I want to share with you now.
I created it due to me attending a seminar about the latest developments in Computer Graphics at university and my presentation was about the Siggraph '08 paper "Real-time Motion Retargeting to Highly Varied User-Created Morphologies" from Chris Hecker et al.
You can check it out on Chris Hecker's homepage - his website also contains a bunch of other really cool articles and presentations from various conferences, so it certainly is worth taking a look at it.

I've also sifted through quite a lot of IK papers and lectures for my presentation to understand the later part about the IK solver in Spore and I've found a few links that are a nice read:

Ive created a huge PowerPoint presentation for my seminar  :-) It includes a few videos (thanks again to Chris Hecker for uploading them and replying to my emails incredibly fast ´) and two awesome IK solvers that I've implemented with VBA macros´ to show how CCD and Particle IK solvers work.

You can find a zip with all the videos and high resolution images here (includes both a PPT 2003 file and a 2007 file). I've also uploaded a small version without videos, macros as PPT 2003 file here, if you don't feel like downloading the 23 MB .zip file.

Here's a YouTube video of the two IK solvers:

I've exported the code into an additional IK Playground presentation which contains just one slide and the two IK solvers with the setup you see in the video above. You can find the PPT 2003 version of it here and the 2007 one here.

I've zipped up the macros here if you want to use them in your own slides. I've also written a handy VBA form that allows one to edit everything more easily (the macros are hardly documented though, but if anyone really wants to use them and runs into problems - you can always drop me a line or two in a comment :) )

The IK Solver Tool Form

The IK Solver Tool Form

BTW I'm not sure you know about it´, but Blender contains an awesome video editor - the UI needs some time to get used to, but the online documentation has improved a lot and with it, it works like a charm. Blender also supports some pretty professional filters, so it's going to be my video editing tool of choice from now on.

Cheers,
Andreas

Logical Equivalence

It has taken me 3 months to finally solve this problem´.

Anyway - I proudly present:

(b \Rightarrow B_0) \land (\lnot b \Rightarrow B_1) \equiv \\ \equiv (\lnot b \lor B_0) \land (b \lor B_1) \equiv \\ \equiv (b \land B_0) \lor (\lnot b \land B_1) \lor (B_0 \land B_1) \equiv\\\equiv (b \land B_0) \lor (\lnot b \land B_1) \lor ((b \lor \lnot b) \land B_0 \land B_1)\equiv\\\equiv 
(b \land B_0) \lor (\lnot b \land B_1) \lor (b \land B_0 \land B_1) \lor (\lnot b \land B_0 \land B_1) \equiv \\ \equiv (b \land B_0) \lor (b \land B_0 \land B_1) \lor (\lnot b \land B_1) \lor (\lnot b \land B_0 \land B_1) \equiv\\ \equiv 
(b \land (B_0 \lor (B_0 \land B_1)) \lor (\lnot b \land (B_1 \lor (B_0 \land B_1)) \equiv \\ \equiv (b \land B_0) \lor (\lnot b \land B_1)

\o/,
Andreas

VGA Project for Technical Computer Science

Today I'm going to write´ about a project that I've worked on for university together with other students for technical computer science.

Some Introductory Words

Some background information first maybe: everybody has to participate in a small project for technical computer science during the course of their studies at my university. Usually it's just a small project done by a team of three students.
I was lucky though and had good marks in the final exams TCS in the first term and was offered with maybe 50 other students to participate in bigger projects that actually work with hardware and have bigger team sizes too (about 10 people usually).

The project started in my second term and due to us being quite lazy students and being not pressured from the faculty itself, only started really working on the project in our summer vacation which explains why we only finished it two weeks ago (mid/end of the third term).

The aim of the project was roughly to display stuff on a monitor by programming an AVR microcontroller as well as an FPGA . We further had a working networking interface (using an old 10 MBit Ethernet card) to retrieve the stuff we should display.
We had to write everything (from the Clients to access/connect to our hardware to the VGA signal output code) on our own (except for a uip network stack to use on the AVR microcontroller).

The hardware (which we didn't have to put together´) looks like this:

We actually started working on and off during the second term, but getting everything setup and running (the FPGA people could probably fill books with horrible stories about Xilinx...) took quite some time and we were incredibly happy when we could connect via network to the AVR for first time and make the little LEDs on the FPGA flash in a pattern.

More than half a year later we were quite happy to produce images like these on the screen though:

The Features

As you can read above the whole project didn't really have a specific outline, it was more like throwing hardware at us and telling us to get creative (and get something done, too, obviously :-) ).

We settled on some features when we really started to implement things and had a better intuition about what is possible and what we cannot do:

  • Java Client to communicate with the hardware
  • AVR server code only to communicate with the client and network card and transmit/pass through data to the FPGA
  • FPGA displays the data on the screen (as 80x40 ASCII output on a resolution of 640x480 at 60 Hz)
  • Fixed color and font tables (ASCII charset and the usual DOS terminal colors)
  • Custom font and color tables can be sent, too
  • AVR has a built-in web interface and can be accessed like a website and offers a small Web Client to send and display text messages on the screen (using the default colors and the usual ASCII charset)
  • Java Client has editors for all three content types (font, color, screen) and can show a preview
  • Java Client has an Image Converter that can take arbitrary images and create custom font, color and screen data to show them in the best way possible
  • AVR can also output log/debug messages as html in the web interface´. Click here and here or here for examples :-)

Moreover there is some unfinished stuff like a hardware emulator to test the Java client with (that was never properly finished) or a batch testsuite to send messages without having to use the Java Client´ or the prototype Java Client and the first version of it (different codebase from what I've heard) etc. etc.

You can download the code for the AVR and its subprojects (testsuite, emulator) here.

The Final "Product"

First, let's take a look at what you see after you power everything up:

ETI is the abbreviation for Introduction to Technical Computer Science and GP4 stands for our project (including its number).

Next we have photo of the old terminal we were using to display debug information from the AVR (I spent hours reading it while coding the AVR):

Let's take a look at the web client now:

The Web ClientThe Java Client is more awesome though.

I'll just drop a few pictures showing and the results on the real screen:

For the rest I've prepared a litttle slideshow:

The Development

We were a team of ten students, which is quite huge (at least for my taste - and it also turned out to be quite difficult to manage). Three of us volunteered to be the official project leads, ie. the people responsible for keeping an eye on everything, organizing meetings and being the contact persons for Dr. Acher from the TCS chair.

We initially divided us up into 3 teams: an FPGA team, an AVR team and a Java Client team. The Java Client team and the FPGA one were the biggest ones, because we thought most of the work had to be done there (that turned out to be true), while the AVR team only consisted of me (doing all the C programming for the project) and Andreas Hubel who wrote the HTML/JavaScript code for the web client amongst other things. In retrospect the AVR was a lot of work, too, and, of course, underestimated by me, because I thought passing along information from A (the Java Client) to B (the FPGA) could be done in a day, which was not true.

A big chunk of the project was done in 3 days during our summer vacation when we all met and locked ourselves up in the lab and worked on the project from 9 am to 9 pm´. The rest was coded during various afternoons and sometimes weekends in our third term.

Read more »

Learn Java Interfaces in 10 Minutes

I've written a small Eclipse project´ that tries to explain interfaces and their use through commented code examples. It also shows how to make for-each loops support iterating over your classes and how to use the iterator interface to create data to iterate over just in time.

You can find the project here.

Cheers,
Andreas

WordPress Hacking II

privatepagesfixI have a few private pages that I use to store random stuff and ideas and private pages (for a reason I don't understand) don't show up in the pages widget.

It turns out that WordPress's get_pages function always filters them out, while get_posts doesn't (it actually has some logic to figure out whether to show private pages or not).

I've decided to fix this. A real fix would probably be merging get_pages and get_posts because both seem to do pretty much the same except that get_posts is a tad bit more advanced, but I'm all for quick fixes at the moment, because I don't have much time and I don't want to end up considering myself a PHP developer ;-)

To make get_pages return private pages, too, you have to open the file wp-includes/post.php and change the following lines near the bottom of the get_pages function:

	$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND post_status = 'publish') $where ";
	$query .= $author_query;
	$query .= " ORDER BY " . $sort_column . " " . $sort_order ;

to:

	$private_pages_inclusion_where = "";
	if ( is_user_logged_in() ) {
		$private_pages_inclusion_where  = current_user_can( "read_private_pages" ) ? " OR post_status = 'private'" : " OR post_author = $user_ID AND post_status = 'private'";
	}

	$query = "SELECT * FROM $wpdb->posts $join WHERE (post_type = 'page' AND (post_status = 'publish' $private_pages_inclusion_where)) $where ";
	$query .= $author_query;
	$query .= " ORDER BY " . $sort_column . " " . $sort_order ;

If you also want to make it easier to distinguish private pages from normal ones, you can also change the following bits in wp-includes/classes.php in the method Walker_Page::start_el:

$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) .
	'" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' .
	$link_before . apply_filters('the_title', $page->post_title) . $link_after . '</a>';

to:

$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_page_link($page->ID) .
	'" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' .
	$link_before . apply_filters('the_title', $page->post_title) . ($page->post_status == 'private' ? " (Private)" : "") . $link_after . '</a>';

Cheers,
Andreas

Partial Integration and the Substitution Rule

I only want to write this down to have a place to look it up:

If we want to integrate \displaystyle{ \int_{a}^{b}{f'\left(x \right) g\left( x\right)} } , we can use:


  \displaystyle { (f \cdot g)'\left( x \right) & = f'\left(x \right)g\left(x \right) +  f\left(x \right)g'\left(x \right) } \\
 \displaystyle { \Leftrightarrow f\left(x \right)g\left(x \right) \big |_{a=x}^b } & = \displaystyle { \int_{a}^{b}{ f'\left(x \right)g\left(x \right) +  f\left(x \right)g' \left(x \right) } \, dx  } \\
\displaystyle { \Leftrightarrow \int_{a}^{b}{ f'\left(x \right)g\left(x \right) }\, dx } & \displaystyle { = f\left(x \right)g\left(x \right) |_{a=x}^b - \int_{a}^{b}{ f\left(x \right)g' \left(x \right) } \, dx }

And if we want to substitute a function in an integral:

 
{  \int_{g\left(a \right)}^{g\left(b \right)}{ f\left( x  \right) } \, dx = F \left ( g \left ( b \right ) \right ) - F \left ( g \left ( a \right ) \right ) = \left (F \circ g \right ) \left ( b \right ) - \left (F \circ g \right ) \left ( a \right ) = } \\ 
= \int_{a}^{b}{ \left (F \circ g \right ) ' \left ( x \right )  } \, dx = \int_{a}^{b}{ f \left ( g  \left ( x \right ) \right )  } \, g' \left ( x \right ) \, dx

(with  F \left ( x \right ) = \int^{x}{ f \left ( x \right )} \, dx)
or using a trick:

\int_{a}^{b}{f \left ( g \left ( x \right ) \right ) } \, dx = F \left ( b \right ) - F \left ( a \right ) = \left ( F \circ g \circ g^{-1} \right ) \left ( b \right ) - \left ( F \circ g \circ g^{-1} \right ) \left ( a \right ) = \\
= \left ( F \circ g^{-1} \right ) \left( g \left ( b \right ) \right ) - \left ( F \circ g^{-1} \right ) \left( g \left ( a \right ) \right ) =
\int_{g \left ( a \right )}^{g \left ( b \right )}{ \left ( F \circ g^{-1} \right ) ' \left ( x \right ) } \, dx = \\
= \int_{g \left ( a \right )}^{g \left ( b \right )}{ F' \left ( g^{-1} \left ( x \right ) \right ) \, g^{-1} ' \left ( x \right ) } \, dx =
 \int_{g \left ( a \right )}^{g \left ( b \right )}{ f \left ( g \left ( g^{-1} \left ( x \right ) \right ) \right ) \, g^{-1} ' \left ( x \right ) } \, dx = \\
= \int_{g \left ( a \right )}^{g \left ( b \right )}{ f \left ( x \right ) \, \frac{1}{g' \left ( g^{-1} \left ( x \right ) \right} } \, dx

(with  F \left ( x \right ) = \int^{x}{ f \left ( g \left ( x \right ) \right )} \, dx)