Posts from — October 2007

CodeIgniter and SimplePie

CodeIgniter - SimplePie

I have been trying to get our rss feed into the administration area of 68kb for a few days now and after trying countless ways I just could not get it to work. Finally after reading loads of forum threads I was able to successfully integrate SimplePie. For anyone else having trouble I will go through all the steps I took to get it working.

Step 1.

Download SimplePie. I used v1.0.1

Step 2.

Rename simplepie.inc to Simplepie.php and save it to system/application/libraries folder.

Step 3.

Open your controller file and add this code:


$this->load->library('simplepie');
$link = 'http://68kb.com/category/news/feed';
$data['feed'] = new SimplePie();
$data['feed']->set_feed_url($link);
$data['feed']->enable_cache(false);
$data['feed']->init();
$data['feed']->handle_content_type();

Of course make sure you pass “$data” to the view file.

Step 4.

Open your view file and add this:

<?php if ($feed->data): ?>
	<?php $items = $feed->get_items(); ?>
		<?php  foreach ($items as $item): ?>
			<strong><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></strong> - <?php echo $item->get_date('j M Y'); ?>

			<p><?php echo $item->get_description(); ?></p>
		<?php endforeach; ?>
<?php endif; ?>

I know this seems pretty basic but it took me ages to get it running. I would like to thank CI user MASS MASS for this forum thread which helped me tremendously.

  1. SimplePie’s Wiki

October 31, 2007   7 Comments

Multi Lingual

Another top feature I wanted to add is the ability for the script to be completely multi lingual. Lucky for me CodeIgniter makes this super easy with their language library. All I had to do was create a new language file (kb_lang.php) and place it in the system/language/english/ folder. Next open the autoload file and add:

$autoload['language'] = array(’kb’);

Now my language file is auto loaded and anywhere I need a string of text I use:

 echo $this->lang->line('kb_hello');

The only downside is it is a lot more coding than just writing “Hello” but in the end it is worth the extra time to add features like this and it keeps you from having to edit the template files just to change the wording.

October 30, 2007   No Comments

Module System Finialized

Happy Pair

One of the things that is high on my feature list is the ability for outside people to extend the system without touching any of the core files. I am jumping for joy to say that this portion of the script was finished up today. In the rest of this post I will try and shed some light on the advantages of a system like this and some insight in how we accomplished it.

Less Bloat

By keeping the core lean and mean it makes bug tracking easy and keeps the administration trimmed down to what you actually use. What good is a product with millions of options if you only use a couple?

Easier Upgrades

If you do not have to touch the core script to add a feature then upgrading should be painless. No need to worry about every little change you made and document it. Of course if you think it is easier to not use the module the system and hack your site anyway then this will not be the case but that is why we are spending so much time building it this way.

No Waiting

With a module system you do not have to wait on a feature to be released. You have the power to add it in any time you want.

How it works

The module system was fairly complex to setup and I had to create a custom library to interact with the “module hooks” and a custom view file that loads a file from the module directory. The hooks are called through out the script like this:

$this->kb_hooks->call_hook('article_edit', $arr);

Which in turn call a module with the function “modulename_article_edit”.

Wrap Up

I am sure you can probably tell from the benefits listed above that I am excited about this module system and I think you will to once you get a chance to give a test drive. At a later date I will be writing a tutorial on how to code a module and be more in depth on how the backend works.

October 29, 2007   No Comments

Templating With CodeIgniter

I started working on the template system today and thought I would share some of things I am doing. One of the features I wanted was to have an easy template system and it must be flexible enough to not choke if a certain template body file couldn’t be found. Another thing I like to do is have one global layout file and include the body portion where needed. This way you do not have to worry about a header, footer, etc.
[Read more →]

October 28, 2007   3 Comments

bbPress Plugin - 68-gravatars

Gravatar

While building this site I decided to use Wordpress as the CMS and bbPress as our forums. This way the user registration will remain constant throughout.

Wordpress already has a gravatar plugin but I could not find one for bbPress so I created a simple version that displays a user’s gravatar on the post page.

Installation

  1. Upload `68-gravatar.php` to the `/my-plugins/` directory
  2. Activate the plugin through the ‘Site Management’ menu in bbPress
  3. Place `<img src=”<?php sixtyeight_gravatar(); ?>” />` in your post template.

Parameters

This plugin has the following syntax:

<?php sixtyeight_gravatar({rating{, size{, default{, border}}}}) ?>

All of the parameters are optional. For example, the following will create a gravatar URL that allows all rating levels, is 80×80 pixels, uses no default image, and has no border:

<?php sixtyeight_gravatar(); ?>

If you wish to restrict your gravatars to R rated and below, you’d do this:

<?php sixtyeight_gravatar("R"); ?>

If you want the size of the image changed as well, supply the pixel dimension as the second argument (defaults to 80):

<?php sixtyeight_gravatar("R", 40); ?>

If you want to use your own “Heat Vision and Jack” image as a default graphic (shows up when either no gravatar exists for a given user, or the given user’s gravatar exceeds the specified rating), you’d do this:

<?php sixtyeight_gravatar("R", 40, "http://www.somewhere.com/heatvision.jpg"); ?>

You can also add a 1px border of any color you choose with the fourth parameter:

<?php sixtyeight_gravatar("R", 40, "http://www.somewhere.com/heatvision.jpg", "FF0000"); ?>

If you wish to leave a parameter at its default while supplying other parameters, simply pass an empty string as the argument.

Remember that this only generates the URL, so you have to place the gravatar tag inside the src attribute of an img tag like so:

<img src="<?php sixtyeight_gravatar() ?>" alt="" />

Download

Download 68-gravatar v1.0

Credits

Special thanks to Tom Werner for the wordpress code.

October 25, 2007   No Comments