Patch MetaSEO in Habari

(MetaSEO) adds search engine optimizations to the page head.

Habari’s plug-in doesn’t provide an option to configure web-robot caching. I created the following patch to address this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--- metaseo.plugin.php 2011-10-06 18:54:14.326378049 +0800
+++ metaseo.plugin.php-nocache 2011-10-06 18:53:37.566385150 +0800
@@ -69,10 +69,13 @@
'home_keywords' => $home_keys,
'home_index' => true,
'home_follow' => true,
+ 'home_cache' => false,
'posts_index' => true,
'posts_follow' => true,
+ 'posts_cache' => true,
'archives_index' => false,
'archives_follow' => true,
+ 'archives_cache' => false,
);
}
@@ -133,10 +136,13 @@
$ui->append( 'fieldset', 'Robots', _t( 'Robots', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'home_index', 'option:MetaSEO__home_index', _t( 'Index Home Page', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'home_follow', 'option:MetaSEO__home_follow', _t( 'Follow Home Page Links', 'metaseo' ) );
+ $ui->Robots->append( 'checkbox', 'home_cache', 'option:MetaSEO__home_cache', _t( 'Cache Home Page', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'posts_index', 'option:MetaSEO__posts_index', _t( 'Index Posts', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'posts_follow', 'option:MetaSEO__posts_follow', _t( 'Follow Post Links', 'metaseo' ) );
+ $ui->Robots->append( 'checkbox', 'posts_cache', 'option:MetaSEO__posts_cache', _t( 'Cache Posts', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'archives_index', 'option:MetaSEO__archives_index', _t( 'Index Archives', 'metaseo' ) );
$ui->Robots->append( 'checkbox', 'archives_follow', 'option:MetaSEO__archives_follow', _t( 'Follow Archive Links', 'metaseo' ) );
+ $ui->Robots->append( 'checkbox', 'archives_cache', 'option:MetaSEO__archives_cache', _t( 'Cache Archives', 'metaseo' ) );
$ui->append( 'submit', 'save', _t( 'Save', 'metaseo' ) );
$ui->out();
@@ -381,6 +387,12 @@
else {
$robots .= ', nofollow';
}
+ if ( !Options::get( 'MetaSEO__posts_cache' ) ) {
+ $robots .= ', noarchive';
+ }
break;
case 'display_home':
if ( Options::get( 'MetaSEO__home_index' ) ) {
@@ -395,6 +407,12 @@
else {
$robots .= ', nofollow';
}
+ if ( !Options::get( 'MetaSEO__home_cache' ) ) {
+ $robots .= ', noarchive';
+ }
break;
case 'display_entries_by_tag':
case 'display_entries_by_date':
@@ -411,6 +429,12 @@
else {
$robots .= ', nofollow';
}
+ if ( !Options::get( 'MetaSEO__archives_cache' ) ) {
+ $robots .= ', noarchive';
+ }
break;
default:
$robots = 'noindex, follow';

Gist Extras in Habari

Gist Extras embeds gists in post content, and allows for the use of custom CSS.

Unfortunately, the author has not updated the plug-in for Habari 0.7 - where plug-in information now resides in a separate XML file. To address this, make the following changes to gistextras.plugin.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
*** user/plugins/gistextras/gistextras.plugin.php.orig 2010-06-26 22:11:59.777117173 +0800
--- user/plugins/gistextras/gistextras.plugin.php 2010-06-26 22:11:32.328366681 +0800
***************
*** 2,20 ****
class GistExtras extends Plugin
{
- public function info()
- {
- return array(
- 'url' => 'http://andrewhutchings.com',
- 'name' => 'Gist Extras',
- 'description' => 'Embeds gists in post content, and allows for the use of custom CSS.',
- 'license' => 'Apache License 2.0',
- 'author' => 'Andrew Hutchings',
- 'authorurl' => 'http://andrewhutchings.com',
- 'version' => '0.0.2'
- );
- }
-
public function action_update_check()
{
Update::add( 'GistExtras', 'A6A9D42C-2F4F-11DE-BB63-026155D89593', $this->info->version );
--- 2,7 ----

You’ll also need to create gistextras.plugin.xml:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="plugin">
<name>Gist Extras</name>
<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
<url>http://andrewhutchings.com</url>
<author url="http://andrewhutchings.com">Andrew Hutchings</author>
<version>0.0.2</version>
<description><![CDATA[Embeds gists in post content, and allows for the use of custom CSS.]]></description>
<copyright>2009</copyright>
</pluggable>

Extending the Habari Sidebar

Habari’s sidebar (in K2) is very minimal. The following plug-ins provide much needed site-navigation:

Fluffytag shows a fluffy cloud of tags.
monthly_archives shows archives grouped by month.

To display output from both plug-ins, make the following changes to sidebar.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
*** system/themes/k2/sidebar.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/sidebar.php 2010-06-26 14:52:35.928366633 +0800
***************
*** 13,18 ****
--- 13,28 ----
<?php $theme->area( 'sidebar' ); ?>
+ <div class="sb-archives">
+ <h2><?php _e('Archives'); ?></h2>
+ <?php $theme->monthly_archives ( '0','N' ); ?>
+ </div>
+
+ <div class="sb-tags">
+ <h2><?php _e('Tags'); ?></h2>
+ <?php $theme->fluffytag(); ?>
+ </div>
+
<div class="sb-user">
<h2><?php _e('User'); ?></h2>
<?php $theme->display ( 'loginform' ); ?>

Fluffytag’s appearance was slightly modified with the following changes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Index: fluffytag.css
===================================================================
--- fluffytag.css (revision 3226)
+++ fluffytag.css (working copy)
@@ -7,11 +7,10 @@
#fluffytag li a {
margin: 0px;
line-height: 34px;
- color: #000;
+ color: #CCCCCC;
}
#fluffytag li a:hover {
- background: #000;
- color: #fff;
+ color: #444444;
}
#fluffytag .step-1 a {
font-size: 1.0em;
@@ -42,4 +41,4 @@
}
#fluffytag .step-10 a {
font-size: 2.8em;
-}
\ No newline at end of file
+}

Code in Habari

Using <code>, I can post short code snippets without relying on Github. e.g,

// my first program in C++
#include 
using namespace std;
int main ()
{
  cout << "Hello World!";
  return 0;
}

Habari has two plug-ins that cater especially to code snippets:

google-code-prettify allows syntax highlighting of source code snippets.

code_escape runs htmlspecialchars() on any code blocks in your post.

Whilst in user/plugins, fetch both plug-ins from their subversion repositories:

$ svn checkout http://svn.habariproject.org/habari-extras/plugins/google-code-prettify/trunk google-code-prettify $ svn checkout http://svn.habariproject.org/habari-extras/plugins/code_escape/trunk code_escape

Make the following changes to plugins/code_escape/code_escape.plugin.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Index: code_escape.plugin.php
===================================================================
--- code_escape.plugin.php (revision 3226)
+++ code_escape.plugin.php (working copy)
@@ -4,7 +4,7 @@
public function filter_post_content_out ( $content, $post ) {
- $content = preg_replace_callback('/<code>(.*?)<\/code>/s', array( 'self', 'escape_code' ), $content);
+ $content = preg_replace_callback('/<code class="prettyprint">(.*?)&lt;\/code&gt;/s', array( 'self', 'escape_code' ), $content);
return $content;
@@ -16,7 +16,7 @@
$string = htmlspecialchars( $string );
- $string = '&lt;code&gt;' . $string . '</code>';
+ $string = '<code class="prettyprint">' . $string . '</code>';
return $string;
@@ -30,4 +30,4 @@
}
-?>
\ No newline at end of file
+?>

Filter Habari Pages by Tags

Habari’s pages, while taggable, aren’t filtered; Habari’s content filters only apply to entries. This can be easily addressed by modifying the theme - for example, with K2, make the following changes to themes/k2/theme.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
*** system/themes/k2/theme.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/theme.php 2010-06-23 20:00:35.488368879 +0800
***************
*** 46,51 ****
--- 46,70 ----
* template. So the values here, unless checked, will overwrite any existing
* values.
*/
+
+ /**
+ * Filter the parameters being passed to Posts::get()
+ *
+ * @param array $filters The parameters to be passed to Posts::get()
+ *
+ * @return array The updated parameters
+ */
+ public function filter_template_where_filters( $filters )
+ {
+
+ if( isset( $filters['content_type'] ) ) {
+ $types = Utils::single_array( $filters->offsetGet( 'content_type' ) );
+ $types[] = Post::type( 'page' );
+ $filters->offsetSet( 'content_type', $types );
+ }
+ return $filters;
+ }
+
public function add_template_vars()
{
//Theme Options

Upgrade to Habari Trunk

To upgrade Habari to the latest development snapshot, read this. Be mindful of the format changes mentioned in Upgrade Notes here.

Move your existing set of plug-ins (at user/plugins/) to user/plugins_prev/ for safe-keeping.

Issue the following command from a MySQL shell to deactivate all active plug-ins:

mysql> DELETE from habari__options WHERE name = "active_plugins";

To update the plug-ins, you will need to search Habari’s plug-ins index for replacement versions 0.7.x.y or trunk.

Gravatar in Habari

Gravatar adds a comment author’s Gravatar by adding <img src="gravatar ?>"> to the relevant file(s) in your theme.

For the K2 theme, make the following changes to themes/k2/comments.php:

1
2
3
4
5
6
7
8
9
10
11
*** system/themes/k2/comments.php 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/comments.php 2010-06-21 23:20:23.068368014 +0800
***************
*** 22,27 ****
--- 22,28 ----
?>
<li id="comment-<?php echo $comment->id; ?>" <?php echo $theme->k2_comment_class( $comment, $post ); ?>>
<a href="#comment-<?php echo $comment->id; ?>" class="counter" title="<?php _e('Permanent Link to this Comment'); ?>"><?php echo $comment->id; ?></a>
+ <img src="<? echo $comment->gravatar ?>">
<span class="commentauthor"><?php echo $comment_url; ?></span>
<small class="comment-meta"><a href="#comment-<?php echo $comment->id; ?>" title="<?php _e('Time of this Comment'); ?>"><?php $comment->date->out(); ?></a><?php if ( $comment->status == Comment::STATUS_UNAPPROVED ) : ?> <em><?php _e('In moderation'); ?></em><?php endif; ?></small>

Github Gists in Habari

To avoid having wasted space in embedded gists, make the following changes to user/themes/k2/style.css:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
*** system/themes/k2/style.css 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/style.css 2010-06-27 21:22:38.248366535 +0800
***************
*** 891,895 ****
--- 891,902 ----
border: 1px solid #999;
}
+ /*-
+ Github Gists
+ */
+
+ .gist { text-indent:0 !important; }
+ .gist-highlight { line-height: 1.2em !important;}
+
/* Peace and forgiveness */
/* Learn more about the other K2: http://en.wikipedia.org/wiki/K2 */

Themes in Habari

The default themes in Habari are placed in system/themes/. To make any customizations to a theme, it is often better to create a duplicate copy in user/themes/, and to work from there.

To be able to distinguish between the two versions of a theme in Habari’s theme selector, you need to modify the tag in theme.xml, e.g. with the following changes to themes/k2/theme.xml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
*** system/themes/k2/theme.xml 2010-06-21 22:15:10.587118909 +0800
--- user/themes/k2/theme.xml 2010-06-21 23:06:11.018366092 +0800
***************
*** 1,6 ****
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="theme">
! <name>K2</name>
<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
<author url="http://getk2.com/">K2 Team</author>
--- 1,6 ----
<?xml version="1.0" encoding="utf-8" ?>
<pluggable type="theme">
! <name>K2_custom</name>
<license url="http://www.apache.org/licenses/LICENSE-2.0.html">Apache Software License 2.0</license>
<author url="http://getk2.com/">K2 Team</author>

Thoughts on Habari

With Chyrp development dead in the water, I had to find a worthwhile alternative. Wordpress, while no doubt a popular and proven platform, seemed a bit too complex for my needs. Still, as my experience with blogging platforms was virtually nil, I had no choice but to make it a major consideration.

Upon searching for Wordpress themes, I chanced upon some Habari themes, oddly enough. After browsing Habari’s wiki pages, I soon realized that it was not so different from Chyrp - besides a much more active Habari community. A trial run of Habari on this host showed that it was probably the closest thing to Chyrp that I could ever find, and it has remained on this host since.

Habari is different

While there are a number of technical reasons that highlight the differences and advantages Habari has over other blogging packages, a major component of what makes Habari different is its community participation model. Users who demonstrate a level of quality contributions to the project are granted more privileges within the project. Habari’s intro page