Hello Dolly 2010

Since 2 weeks there’s a voting on Digging into WordPress whether to keep the Hello Dolly plugin in the standard distribution or to chuck it out the house.

One of the most heard reasons for the existence of Hello Dolly that it should be used as a pattern for novice plugin developers. In my mind the problem with this argumentation is that the plugin hasn’t changed essentially since WordPress v1.21 (the version which introduced plugins in May 2004).

Since then the environment for plugins has changed a lot. The main difference is that there are typically ten or more plugins installed on a blog. Therefore it’s mor important than ever that the plugins don’t interfere with each other. This can most easily be achieved by encapsulation and this leads inevitable to object-oriented programming. Here’s my attempt to take Hello Dolly to the next decade:

< ?php
/**
 * @package Hello_Dolly
 * @author Matt Mullenweg
 * @version 1.5.1
 */
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/#
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.5.1
Author URI: http://ma.tt/
*/
 
if (! class_exists('Hello Dolly')) {
	class HelloDolly { 
 
		function hello_dolly_get_lyric() {
			/** These are the lyrics to Hello Dolly */
			$lyrics = "Hello, Dolly
			Well, hello, Dolly
                        [...]
			It's so nice to have you back where you belong
			You're lookin' swell, Dolly
 
			Dolly'll never go away
			Dolly'll never go away again";
 
			// Here we split it into lines
			$lyrics = explode("n", $lyrics);
 
			// And then randomly choose a line
			return wptexturize( $lyrics[ mt_rand(0, count($lyrics) - 1) ] );
		}
 
		// This just echoes the chosen line, we'll position it later
		function hello_dolly() {
			$chosen = $this-&gt;hello_dolly_get_lyric();
			echo "<p>$chosen</p>";
		}
 
 
		// We need some CSS to position the paragraph
		function dolly_css() {
			// This makes sure that the posinioning is also good for right-to-left languages
			$x = ( 'rtl' == get_bloginfo( 'text_direction' ) ) ? 'left' : 'right';
 
			echo "
 
			#dolly {
				position: absolute;
				top: 4.5em;
				margin: 0;
				padding: 0;
				$x: 215px;
				font-size: 11px;
			}
 
			";
		} //dolly_css()
	} //class
}//if class_exists()
 
$HelloDolly = new HelloDolly;
 
if (isset($HelloDolly)) {
	add_action('admin_head', array(&amp;$HelloDolly, 'dolly_css'));
	// Now we set that function up to execute when the admin_footer action is called
	add_action('admin_footer', array(&amp;$HelloDolly, 'hello_dolly'));
}
 
?&gt;

As you can see all the code is encapsuled in the HelloDolly class and the only variable names visible to the rest of the system are class HelloDolly and $HelloDolly. It’s not very likely that there will be another plugin using the variables.
This may not be too important in this small plugin but it gives the user a good and up-to-date prototype for more complex code. Maybe this code will convince the 76% that this new Dolly is a cow that is not only sacred but also meaty.

WordPress: Überschriften mit Untertiteln

In vielen Zeitungen ist es üblich, unter die eigentliche Überschrift noch einen Untertitel zu setzen, um den folgenden Titel näher zu erläutern:

Durch diese Untertitel kann man den eigentlichen Titel etwas kreativer gestalten und anschließend erläutern. Leider bietet WordPress von Haus aus diese Funktion nicht an und so muss sie nachgerüstet werden. Als ersten Reflex würde der geneigte Programmierer eine Lösung per Plugin versuchen, allerdings gibt s auch eine Lösungmit Bordmitteln. Die Zauberworte lauten „Benutzerdefinierte Felder“ (engl. „custom fields“).

[Read more…]

xnation.fm

Nachdem Michael Jackson gestern das Zeitliche gesegnet hat werden uns die etablierten Radiosender wohl Wochen oder vielmehr Monate mit Titel wie „Billie Jean“. „Bad“ oder „Dirty Diana“ zumüllen. Solange man allerdings an einem Rechner mit Internetanschluss und Soundkarte sitzt kann man diesem Terror entkommen.
Mein augenblicklicher Zufluchtsort nennt xnation.fm. Hier die letzten fünf Lieder die gerade gespielt wurden:

Hört sich nach einer guten Alternative an!

Sehr schön ist auch die begleitende Webseite, die sich nicht auf bunte blinkende Bilder beschränkt, sondern eine Liveticker mit den zuletzt gespielten Liedern inklusive Links auf die Bio der Band und die Texte des aktuellen Liedes anbietet. Vorbildlich.

Die Tim und Holgi Show

Tim Pritlove und Holger Klein im vollkommen ungeplanten Podcast: Not Safe for Work 001. Erinnert ein wenig an die alten Spreeblick-Podcasts.

WordPress: Überprüfen, ob ein Beitrag das more-Tag enthält

Manchmal möchte man einen Beitrag abhängig davon gestalten, ob er ein <!–more–>-Tag enthält oder nicht. Leider verfügt WordPress nicht über eine Funktion, um diese Prüfung vorzunehmen. Befindet sich der Beitrag innerhalb des Loops, so kann man aber folgende Funktion benutzen:

function hasMoreLink() {
	global $post;
	return strpos($post-&gt;post_content, '<!--nore-->');
}

(Bitte „nore“ mit „more“ ersetzen, konnte ich aber nicht eingeben, weil sonst WordPress das Tag auswertet.)
Danke an MichaelH aus dem englischen WordPress Forum

WordPress Plugins übersetzen

Viele WordPress-Nutzer bevorzugen eine deutsche Oberfläche, weil sie der englischen Sprache nicht mächtig sind oder es einfach als angenehmer empfinden, sich mit ihrem Blogsystem in ihrer eigenen Muttersprache zu verständigen.
Für das Basissystem von WordPress wird mit großem Enthusiasmus vom wordpress-deutschland.org-Team eine Übersetzung bereitgestellt. Viele Plugins allerdings nicht nur in englischer Sprache verfügbar, was nicht nur den Nutzer verwirrt, wenn plötzlich Meldungen in einer anderen Sprache erscheinen, sondern auch ein uneinheitlichen und unprofessionelles Bild ergibt.

Zum Glück ist es in WordPress aber relativ einfach, Plugins in eine andere Sprache zu übersetzen. Sofern das Plugin es vorsieht und die Funktion __() (Doppelunterstrich) oder _e() für die Textausgaben benutzt. Diese Funktionen benutzen die gettext Bibliotheken und Werkzeuge.
[Read more…]

Electric-Trick

electric-trick
My first try at macro photography.

Tabelle zeilenweise ausblenden mit jQuery

Möchte man mit jQuery einige Zeilen aus einer Tabelle ausblenden, so könnte man auf folgende einfache Lösung verfallen:

Ursprüngliche Tabelle:

<table>
  <tr><td>Zeile 1</td></tr>
  <tr><td>Zeile 2</td></tr>
  <tr><td>Zeile 3</td></tr>
</table>

Tabelle mit <div> und checkbox:

<table>
  <tr><td>Zeile 1</td></tr>
  <div>
    <tr><td>Zeile 2</td></tr>
  </div>
    <tr><td>Zeile 3</td></tr>
</table>
Zeile 2 verstecken

jQuery-Code zum Ausblenden der Zeile 2:

function hideshow() {
  if ($("#cb_test").attr("checked"))
    $("#test").hide();
  else 
    $("#test").show();
}

Dieser Ansatz funktioniert leider nicht, da es nicht möglich ist, Tabellen- und Textstrukturierungelemente zu mischen. Seit HTML 4 gibt es allerdings das <tbody>-Element, das man für diesen Zweck verwenden kann:

<table>
  <tr><td>Zeile 1</td></tr>
  <tbody>
    <tr><td>Zeile 2</td></tr>
  </tbody>
    <tr><td>Zeile 3</td></tr>
</table>
Zeile 2 verstecken

Laut HTML-Validator des W3C ist diese Lösung „HTML 4.01 Transitional“-valide.

Invite Data to your birthday party… almost!

Nice Tweet from Brent Spiner, the actor who impersonated Data in the Startrek Next Generation series:

I am available for birthday parties and weddings (straight or gay). I won’t come as any character and I won’t do anything but eat cake.

(Link)

7 reasons that make me NOT listen to your web radio

I like to listen to web radios of all kind and like to discover new ones. But if you want to keep me from listening to your station on a long term try to avoid the following:

  1. Bad stream quality
    FM was invented in 1925 by Abraham Esau and we can listen to good sound quality radio for over 75 years. Why should I listen to your 64 kbps or even 24 kbps radio? If you can’t afford the bandwidth then try at least to spice up the stream with AAC.
  2. Ever changing IP address
    If I like your radio i will put it in my bookmarks. It’s quite anoying if I try to listen to your stream the next day and the player can not find it. More often than not I‘m too lazy to look for the new address and simply delete the bookmark. Get a domain name, it’s cheap.
  3. No ID3 tags
    I like to know to what song I am listening right now and my media player will tell it to me if… if you put the ID3 tags into your stream.
  4. Repeating always the same songs
    Classic Rock, New Wave or 80’s collections should contain more than your 20 favourite songs. Such small collections will keep me one hour with your stream and off you go.
  5. Force me to install any plugins
    If you want me to install any plugins because you‘re using some esoteric codec you‘ve lost a new potential listener this very minute.
  6. Not following any conventions
    There are some unwritten conventions which will make the life of your listeners easier. You should for example put the station’s name and any other additional information in round brackets behind the ID3 informationen. This will enable the lyrics plugin my to distinguish between them and to display the correct lyrics.
  7. No MP3/OGG stream
    Some people want me to use their almost unusable Flash players to listen to their stream. Despite the poor sound quality most of these players offer I don’t want to have an open browser tab or an extra browser window on my screen. I like my media player and it’s the only application use for music (OK, the last.fm player is an exception).

Most web radios are aware of the bad habits above and try to avoid them and if not, many will change their streaming after a small hint.