Habari: Hints #1

Geschrieben von am 27. Juni 2008 um 04:36 Uhr 4 Kommentare

Some hints + snippets for Habari (0.5alpha), part 1: Theme editing.

1. Sometimes a given plugin is not called correctly (eg. method instead object call). To get all the stuff displayed thats available via $theme, you just place a $lt;?php echo '<pre>' . print_r($theme, true) . '&lt/pre>' ?> at a good position inside your theme code, eg. right before the footer-DIV.

2. Custom highlighting your search should work out with the following quick’n'dirty hack:

if(strpos($post->content_excerpt, ' ') !== false) { // multiple keywords
	$keywords = explode(' ', $criteria);
	foreach($keywords as $single_keyword) {
		$replacer[] = '<span class="search-hilite">' . $single_keyword . '</span>';
	}
} else {
	$keywords = $criteria;
	$replacer = '<span class="search-hilite">' . $criteria . '</span>';
}
echo str_replace($keywords, $replacer, $post->content_excerpt);

Autoreninfo: Fabian Wolf

Der "andere" Autor dieses Weblogs. Schreibt vorrangig fachspezifische Artikel zu Webdesign und -programmierung, beispielsweise über WordPress, Habari, jQuery oder OpenStreetMap, um nur ein paar Themen zu nennen.

4 Antworten zu “Habari: Hints #1”

  1. _Sven sagt:

    ich bastel grad an einer eigene blogumsetzung mit habari. gibts es plugins oder code snippet um kategorien zu aktivieren? gibt es deutsche habari seiten?

  2. Owen sagt:

    Documenting features is an easy and much appreciated way to contribute! Even if you don’t actually write the page, even reporting a “documentation bug” to the issue tracker is helpful and can inform others that such a thing needs written.

    Here’s a link to the brand new Utils::debug() page:
    http://wiki.habariproject.org/en/Debugging_Tips

    Thanks for the input!

  3. fwolf sagt:

    @ Owen: About #2: I already thought of this, but for a simple, quick’n'dirty hack, this should be enough.

    And #1: This is yet another undocumented feature. At least, the Wiki page for this is not yet created! :-(

    Thanks a lot, esp. for #1 ;)

    cu, w0lf.

  4. Owen sagt:

    Re #1: Habari’s built-in Utils::debug() method would work better than all that. Just call Utils::debug($theme); and it’ll format it nicely, complete with a call trace, type names, and even the parameters passed to the call.

    Re #2: It’s possible to write a plugin or an extension to the Theme class itself that uses a formatter (see the Format class) to implement search highlighting when echoing $post->content_out or $post->content_excerpt. This code might work, but using a formatter would be reusable and perhaps a bit cleaner.

Schreibe einen Kommentar: