User:Mikelietz
From Habari Project
Cabal member, plugin developer, (occasionally) troublesome user, likes lurking in the IRC channel. Theme porter. Wrestler of bears.
Twitter: twitter.com/mikelietz
Website: mikelietz.org
Amazon wishlist: mikelietz
sandbox:
@TODO
-extras cleanup:
- Remove defined THEME_CLASSes from -extras themes.
- Remove save buttons from -extras plugins with blocks.
- text domains for l10n.
Themes to port:
- http://files.priteshgupta.com/elegant_press/index.html
- http://www.elmastudio.de/wordpress-themes/yoko/
- http://www.elmastudio.de/wordpress-themes/ari/
There's no reason Habari couldn't...
If I had my druthers, there would be purpose-specific downloads of Habari to mimic the functionality of the following:
- reader-submitted content (i.e. the Cheezeburger network)
- webcomic (i.e. ComicPress)
- Microblog/blog about this/mobile content creation (i.e. Posterous)
- Band website
- Realtor listings
- NYTimes ICE info
Wanted Pages
- What makes Habari so secure?
- ASL2 Apache License, v2.0
- How do I know which license to use? .. link to ASL compatibility
- Dev:Using a Token that you created when Dev:Creating A Plugin ... a more practical Core:ACL_Class
- Dev:Naming Tokens ... would come in handy on Dev:Adding an Admin Page
- Dev:Core Tokens ... same.
- Dev:Creating a Dropbutton ... or just Dropbutton.
- Dev:Adding a Search Filter ... how to add, say, search=category:whatever
- Dev:Working With URLs - rewrite rule stuff. Dev:Adding Rewrite Rules should redirect there.
- Dev:Creating a Custom Content Type, including how to add it to the feed, and even better, how to modify what goes in the feed.
- Dev:Adding to the Header as seen in the typekit and geotags plugins.
- Guidelines like Dev:Adding Content to Themes for blocks and whatnot.
- Dev:Dynamic FormUI ... $form->append(new FormControlText(... syntax and what you can do (better) with it.
- Dev:Text Domains for Plugins and Themes
- Dev:Using FormStorage
Using the author imageurl
Outside of the loop (this is from a header.php):
<?php if( $request->display_entries_by_author && isset( $posts ) ) { ?> <img src="<?php echo $posts[0]->author->info->imageurl; ?>" alt="Posts by <?php echo $posts[0]->author->displayname; ?>"> <?php } else { ?> <img src="header.png" alt="regular header image"> <?php } ?>
I suppose I should point out that display_entries_by_author up there is from a custom version of 0.5.2, not a core feature (yet).
Textarea rows and cols on the publish page
(for /dev/plugin)
Textareas don't always need to be massive. This works for both tabcontrol_textarea and admincontrol_textarea templates.
$instructions = $myform->append('textarea','plugin_version_instructions', 'null:null', Instructions'); $instructions->value = $plugin_versions->info->instructions; $instructions->rows = '3'; $instructions->cols = '75'; $instructions->class[] = 'resizable'; $instructions->template = 'tabcontrol_textarea';
$Request display content
These are the possible display methods(? attributes?) for a $request object (plus any added through rewrite rules):
- display_home
- display_entries
- display_entries_by_date
- display_entries_by_tag
- display_entry
- display_page
- display_search
- display_404
In the example below I only want to display the search form when I am not displaying the search results page(s).
<?php if( !($request->display_search ) ) { ?> <li id="search"> <?php include 'searchform.php'; ?> </li> <?php } ?>
Friendlier ordinal comments links
"Friendlier" only in English, that is.
<?php // pointless and dirty hack. $ordinals = array(_t( "no" ), _t( "one" ), _t( "three" )); ?> <div class="feedback"> <a href="<?php echo $post->permalink; ?>" title="Comments on this post"><?php echo ($post->comments->approved->count >= count($ordinals) ? $post->comments->approved->count : $ordinals[$post->comments->approved->count ] ); echo _n( ' comment', ' comments', $post->comments->approved->count ); ?></a>
Counting words in a post
Not counting the title, though:
<?php echo count( explode( " ", strip_tags( $post->content_out ) ) ); ?> words.
This is the basis of my word count plugins.
XHTML to HTML
Wow. Amazingly easy way to fix all of the horizontal rules:
UPDATE habari__posts SET content=REPLACE(content,'hr /','hr');
Pulling out the most recent entry outside of Habari
$conn = mysql_connect($host,$user,$password) or die ('Connection failed'); mysql_select_db( $db ); $query = "SELECT * FROM habari__posts where id = (SELECT max(id) FROM habari__posts WHERE content_type = '1' and status = '2')"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $date = date("j F Y",strtotime($row['pubdate'])); $title = $row['title']; $content = wpautop($row['content']); } mysql_close( $conn );
Rolling your own translation without Launchpad
Copy the file from system/locale/habari.pot to user/locale/habari.po.
Make sure msgid is always a single line. Sometimes the POT generator adds newlines for strings that have "\n" in them.
Fill in msgstr for each msgid you wish to translate. Make sure that msgid ending in "\n" have corresponding msgstr ending in "\n".
Compile with msgfmt
msgfmt -o dirname/LC_MESSAGES/habari.mo habari.po
Free webhosts that don't support Habari
x10Hosting - Installs fine, but Flickr silo does not work. Inactivity policy somewhat aggressive.
110mb.com - PHP5.1.6 and, as of 10/2009, no plans to upgrade to 5.2.anything.
UnlimitedMB - missing many extensions.
Host.sk - missing PDO.
T35 - forced ads on all pages, including admin. Unacceptable, and breaks admin.
iLive - Streams disabled and no Curl.
Installer testing (on hold for now)
I think I'll make a spreadsheet for this.
| case | db type | / writable | /user writable | results |
|---|---|---|---|---|
| sqlite | no | no | yes | big red box |
random musings, not ticket worthy until thought through
- Would there be any merit to having a $comment->permalink? Instead of hardcoding {$comment-post->url}#comment-{$comment->id} in both the admin and the theme (as well as anywhere else) wouldn't it be more flexible to have a permalink function (as well as a configurable option) to do it?
Changing 'tag' in the URL to 'blah'
Quick and dirty way to customize the stock rewriterule URLs.
public function filter_rewrite_rules( $rules ) { foreach ( $rules as $rule ) { if ( $rule->name == 'display_entries_by_tag' ) { $rule->parse_regex = '#^blah/(?P<tag>[^/]*)(?:/page/(?P<page>\d+))?/?$#i'; $rule->build_str = 'blah/{$tag}(/page/{$page})'; $rule->update(); } } return $rules; }
Monthly Archives link list
(thanks Rick)
public function theme_monthly_archives_links_list( $theme, $full_names = TRUE, $show_counts = TRUE, $type = 'entry', $status = 'published' ) { $results = Posts::get( array( 'content_type' => $type, 'status' => $status, 'month_cts' => 1 ) ); $archives[] = '<ul class="archives">'; foreach ( $results as $result ) { // what format do we want to show the month in? if( $full_names ) { $display_month = HabariDateTime::date_create()->set_date( $result->year, $result->month, 1)->get( 'F' ); } else { $display_month = HabariDateTime::date_create()->set_date( $result->year, $result->month, 1)->get( 'M' ); } // do we want to show the count of posts? if ( $show_counts ) { $count = ' (' . $result->ct . ')'; } else { $count = ''; } $result->month= str_pad( $result->month, 2, 0, STR_PAD_LEFT ); $archives[] = '<li>'; $archives[] = '<a href="' . URL::get( 'display_entries_by_date', array( 'year' => $result->year, 'month' => $result->month ) ) . '" title="View entries in ' . $display_month . '/' . $result->year . '">' . $display_month . ' ' . $result->year . ' ' . $count . '</a>'; $archives[] = '</li>'; } $archives[] = '</ul>'; return implode( "\n", $archives ); }
Threaded comments for K2
Using the threaded_comment plugin in habari-extras. Complete with fallback code.
<!-- comments -->
<hr>
<div class="comments">
<h4><span id="comments"><?php echo $post->comments->moderated->count; ?> <?php _e('Responses to'); ?> <?php echo $post->title; ?></span></h4>
<div class="metalinks">
<span class="commentsrsslink"><a href="<?php echo $post->comment_feed_link; ?>"><?php _e('Feed for this Entry'); ?></a></span>
</div>
<ol id="commentlist">
<?php
if ( $post->comments->moderated->count ) {
/* this is the new stuff here */
if ( $post->threadedComments ) {
foreach ( $post->threadedComments as $comment ) {
$theme->output_comment($post, $comment, 1, $theme->commentThreadMaxDepth);
}
/* the rest is basically stock plus enough brackets to make it all work */
}
else {
foreach ( $post->comments->moderated as $comment ) {
if ( $comment->url_out == '' ) {
$comment_url = $comment->name_out;
}
else {
$comment_url = '<a href="' . $comment->url_out . '" rel="external">' . $comment->name_out . '</a>';
}
?>
<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>
<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>
<div class="comment-content">
<?php echo $comment->content_out; ?>
</div>
</li>
<?php }
}
}
else { ?>
<li><?php _e('There are currently no comments.'); ?></li>
<?php } ?>
</ol>
<?php if ( ! $post->info->comments_disabled ) { ?>
<div class="comments">
<h4 id="respond" class="reply"><?php _e('Leave a Reply'); ?></h4>
<?php if ( Session::has_messages() ) {
Session::messages_out();
}
$post->comment_form()->out();
} ?>
</div>
<hr>
</div>
<!-- /comments -->