Dec 12

Code Colorer

I used WP-SyntaxHighlighter, I tried some others, but the simplest and most expedient plugin I found for highlighting code in my blogs comes from Dmytro Shteflyuk’s Code Colorer.
Like most of them it’s based on the Geshi Generic Syntax Highlighter … much easier syntax.

I recommend this one for bloggers who wish to include code in their posts.

  • Facebook
  • Share/Bookmark
Tagged with:
Dec 11

I’m learning how to write wordpress plugins, I’ve said that before here in my blog.  One of the ways I’m doing it is by downloading/installing existing plugins I see out there which may be interesting to me – they provide actions and capabilities to do things I want my plugin(s) to do … on a more general scale.

One thing I have noticed – almost all of these plugin authors do NOT use classes in their design.  Their .php files are full of functions, most of the time written without the

if (!function_exists('my_function')) {
  function my_function() {
    // and so on
  }
}

or

if (!function_exists('my_function')) :
  function my_function() {
    // and so on
  }
}
endif;

How do they expect to avoid naming collisions?  If they have to have a function by a certain name which probably exist in some other plugin developer’s file somewhere, then even if they use this !function_exists business they’ll end up getting the other author’s behavior for that function.

Why don’t these people just use classes! I know I’m coming at this from the java world where you have to use classes for everything, and there’s packaging to avoid naming collisions, but still – this seems like an obvious question to me. Do the modern php programmers have no experience with a real class-oriented language?

Here’s a silly example I’m doing. I have a plugin I’m developing to allow Zlatina’s web administrators to deal with their database of students and contacts. It’s called Bcc DBManager.
I created a subdirectory wp-content/plugins/bcc-dbmanager, with a file named bcc-dbmanager.php … duh. I want to hook into the activate_${plugin} (see this link for an explanation of that). Here’s a partial …

<?php
/*
Plugin Name: Bcc DBManager
Description: Blah blah
*/

$bccDBManager = new BCC_DBmanager();
add_action('activate_bcc-dbmanager/bcc-dbmanager.php',                  
         array(&$bccDBManager,'_activate'));

class BCC_DBmanager {  
  function _activate()  {    
    // do stuff    
    $this->very_common_function_name();
    // or this way
    BCC_DBmanager::very_common_function_name();
  }
  ## function with a very common name
 function very_common_function_name() {
    // do stuff
  }
}
?>

How hard is that? I certainly don’t know much about plugin development at this point. But I would have to describe the use of functions rather than class instances and methods as Code Smell.

[Edit] Since I wrote this post I found this link on Nerdaphernalia: Use Classes in your WordPress plugins to increase code portability and reduce name conflicts

  • Facebook
  • Share/Bookmark
Tagged with:
Dec 04

After you’ve installed apach2, php5, mysql, etc, you test it with http://localhost and all you get is this “It Works!” crap.  You can actually create an index.php page that looks like:

<?php
  phpinfo();
?>

and you can actually type in http://localhost/index.php and get your phpinfo page coming out.  But it seems nowhere in the docs can you find out how to get apache2 to recognize index.php as the first page to deliver.

So, I found out where, finally.  In your WAMP environment there’s only the http.conf file, you look for the DirectoryIndex, and move index.php or insert “index.php” to the front of the line.  In this ubuntu 9.10 LAMP setup, where the hell is the file?

/etc/apache2/mods-available/dir.conf

That’s where it is.  open the file, it looks like this after your normal lamp setup in this environment

<ifmodule mod_dir.c>
 DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</ifmodule>

Notice the “index.php” somewhere in the DirectoryIndex list … move that to the front of the list as in

<ifmodule mod_dir.c>
 DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</ifmodule>
  • Facebook
  • Share/Bookmark
Tagged with:
Nov 26

So I've cranked up the linux box for sandbox development of wordpress themes and plugins.  Sounds interesting, doesn't it? Well, for a hard-core java programmer moving back into PHP doesn't immediately seem like a step up, but here we are, eh dear reader?  And this may be where the business is in Bulgaria these days …. WordPress is a perfectly good Content Management System (CMS), and It's likely that skills in this CMS will prove useful in this country at this time. I installed NetBeans, the latest version.  Installed apache2, php, all that good stuff with apt-get and aptitutude.  And finally I went to http://netbeans.org/kb/docs/php/wordpress-screencast.html for a quick tutorial on how to setup a wordpress plugin project. Good stuff, eh?  Let's see where this goes. If you're interested, I can write a post on the setup procedures which got me here.  Just try and get XDebug and all this running on windows, pee-yew.

  • Facebook
  • Share/Bookmark
Tagged with:
Nov 07

I discovered this interesting idea today, see the website at www.gravatar.com
Play the video on the front page, it explains it quite well.

Basically here’s what’s going on with it:  You sign up for a free account, you attach your favorite avatar – image of you or a cartoon character or a symbol or whatever, just so it’s an image – to that email account.  Now any website that supports gravatar (such as any wordpress blog out there) where you register with your email address will show your avatar next to your comments.

Here’s a better explanation, though a bit technical for those not so tech-oriented.

Here’s what my gravatar looks like.  I picked an old image from last winter (2008-2009) of me walking down State street in Madison Wisconsin.  All dressed up for winter aren’t I?  You can upload any picture, it can be cropped or zoomed or edited on the website itself.

Any place which supports gravatars, such as here on my own wordpress blog, any comment I make on the posts will show my gravatar image.  Sign up if you want to see your gravatar on comments in this blog, or any other wordpress blog you visit.

I’ve added a sample comment to this blog entry to show you.

  • Facebook
  • Share/Bookmark
Tagged with:
preload preload preload