TheDrunkenEpic - Drunken Ramblings of a Code Monkey
Filed under

Tutorials and Such

 

jQuery: Mirroring Selections

Ran into pretty interesting situation today while working on a client's administration interface. It made me realize that I'm probably not the first person to run into this.

In one of their sections they have a list of records. At the very top of the list is a select box element that allows you to pick an action and apply it to any chosen records.

Since the list of records is pretty long and requires a lot of scrolling, my client asked if it would be possible to have the same select box appear at the bottom of the list as well. Simple enough, but they also asked if it was possible to have one select box mirror the current selection to the other box at the bottom of the page.

So, to implement this feature, I decided to use a bit of jQuery magic.

The elements in question are both named 'action', so what I did was simply bind a 'change' even using 'select[name=action]' as the selector. Once this event is invoked, it just copies the value of the current box to all other boxes on the screen with the same name.

Take the following code:

$(document).ready(function()
{
    $('select[name=action]').bind('change', function()
    {
        $('select[name=action]').val($(this).val());
    });
});

This isn't anything special, but just shows how jQuery can rise to the challenge of any problem.

Loading mentions Retweet
Filed under  //   Code Monkey   jQuery   Tutorials and Such  

Comments [0]

jQuery: Add another row to a table ...

Here's another quick trick I just learned. We were attempting to allow a user to add more records to an existing form within our updated CRM. This form was represented as a row of a table. Rather than using JavaScript to manually build a new row to display, I did a bit of digging and found the clone() function of jQuery.

Say, we have a table with id of table#image-uploads that basically contains a minature upload form field (with other options) for images. In the last column of this upload form there is an 'add another' link:

add another

Clicking on the link invokes the following JavaScript function:

function addTableRow(table)
{
    $(table).append($(table + ' tr:last').clone());

    return true;
}

First, we pass the identifier to function addTableRow(table). The identifier, in this case, would be #image-uploads. You could also use classnames, ie .table-foo.

We then, using #image-uploads tr:last, take the last row of this table and clone(), or copy, it.

Finally, we just take the contents of the copied table row and then append() the data back onto the table.

There, now they can click that link and add as many extra form fields as they need for their images!

Neat trick, eh? I <3 jQuery. Really, I do!

Loading mentions Retweet
Filed under  //   Code Monkey   Development   jQuery   Tutorials and Such  

Comments [0]

jQuery: Is a 'mousedown' event within a specified boundary?

While working today I came across a problem I haven't encountered before. At my current place of employment, we're implementing a new navigation system for thier home-grown CRM. It's modeled much like the Microsoft Office 2007's ribbon navigation system where you have menu bars that are relevant to the current user's status, position, etc. Some of these bars have buttons that you click and have contextual menus or forms appear.

The current goal for this drastic navigational change is to allow users to perform repetitive tasks as fast as possible. In one instance, a user might enter a customer call into the system 8 or 10 times a day. The older method of doing this particular task was cumbersome and time-consuming. While trying to make this process as efficient as possible we came up with some creative ways to streamline it.

Without dragging this background story out too much, one of the issues I was confronted with was how to exit a contextual form. We're trying to come up with an intuitive and responsive solution, but, due to the nature of the system, we're somewhat limited to what we can. Unlike Microsoft, we don't have a massive ready-made and time-tested library for creating UI elements, so some things, even the simplist kinds of functionality you'd come to expect from a desktop application, need to be engineered from scratch.

Say, for instance, you have a contextual menu open in Windows by right-clicking on an object. The menu stays until you either click on an option or click outside of it's boundaries. The same functionality was needed for these contextual forms. If a user decides, "Meh, wtf mate? I reckon I don't need to finish this bloody form. Sod off and bullocks to you, good sir... In the name of the Queen.", we wanted them to be able to click anywhere on the page that didn't reside within the confines of the form itself and have it close automagically.

So, with a bit of creativity, and almost no research into determining whether or not this was already done elsewhere, I came up with the following solution!

To do this, we need only check either of the following conditions

  1. Did the mouseclick occur inside the boundary
  2. Did the mouseclick occur outside the boundary

The boundary can be any element within the document. In our example, we'll just use a small 50 by 50 pixel div element with the id of boundary:

<div id="boundary" style="height: 50px; width: 50px; background: #000 none; cursor: pointer;"></div>

Now that we've defined a clickable area to test with, we need to start tracking the actual clicks. We do this by binding a 'mousedown' event the entire document:

$(document).bind('mousedown', function(click) {
    return checkMouseBoundary(click, '#boundary');
});

Now we can track any click within the current page. Function checkMouseBoundary(click) will be called every time a mouse has been clicked within the document. The mousedown event will pass the metadata concerning the actual click to this callback function:

function checkMouseBoundary(click, boundary)
{
    var element = $(click.target);
    var boundary = $(boundary);

    while(true)
    {
        if(element == boundary)
        {
            return alert('I am inside the boundary ...');
        }
        else if(element == document)
        {
            return alert('I am outside the boundary ...');
        }
        else
        {
            element = $(element).parent();
        }
    }

    return true;
};

This is the brains behind the magic. This way seemed to make the most sense to me, so let's break it down step-by-step.

First, we need to identify the element where the click occurred. Since the mousedown event binding returns the information about the actual click, we can identify the target element by doing the following:

var element = $(click.target);

Next, we need to identify the boundary we set. In test case, we're using div#boundary:

var boundary = $('#boundary');

Now, if var element is equal to var boundary, the click originated within div#boundary and if they are not equal, it must have happened somewhere else, right? Well, yes and no.

What if div#boundary has child elements? If you click the child of the boundary, technically, you're still within said boundary. We have no way of knowing this unless we traverse the document, traveling up the element tree from the click target until we either first hit the element identified as div#boundary or travel straight up to the very top of document. For example, in our test case, if you click on anything between the body and div#boundary element, we would end up going straight to the top of the document. If we click on anything within div#boundary, no matter how many levels deep, and we travel up the element tree until we hit the actual boundary.

So, what we need to do is create a loop that iterates the document with every click starting from the target element:

while(true)
{
    if(element == boundary)
    {
        return alert('I am inside the boundary ...');
    }
    else if(element == document)
    {
        return alert('I am outside the boundary ...');
    }
    else
    {
        element = $(element).parent();
    }
}

The above loop does not stop until one of two conditions are met. If neither are met, find the current click target element's parent and keep on going. Eventually, we should meet either criterion and stop the loop.

Also, you don't have to use the id of #boundary for this to work. You can even test against any element that has a specific class name attached to it. So, if you have 5 different elements that use the class .omgwtfbbq, you can do the following:

$(document).bind('mousedown', function(click) {
    return checkMouseBoundary(click, '.omgwtfbbq');
});

And it should track every element with that class assigned to it.

When you're done, always be sure to release the bound event like so:

$(document).unbind('mousedown');

This will release all mousedown events bound to document. No point in keeping them around if we're not using them, right?

There you go! Now, you can check if someone clicks outside of an element and act accordingly. This example should be cross-browser compatible, but if you have any issues, please report them within this article. I hope you found this little tutorial worth your time.

Loading mentions Retweet
Filed under  //   Code Monkey   Development   Tutorials and Such  

Comments [0]

Symphony Search Walkthrough

It seems there are a few Symphonians out there, both new and old, that can't quite get the 'Search' campfire service working on their site. So, I've decided to go ahead and throw together a quick guide to help my comrades out.

Before We Start

This article assumes that you have, at the very least, the following:

  1. A working copy of Symphony 1.7.x
  2. The Search campfire service composed by Alistair Kearney
  3. A rudimentary understanding of HTML
  4. Some basic reading skills
  5. Some searchable content on your site

First things first:

If you're here that means you've met all the requirements, so good on ya! In order to get search functionality working, you need to download and install the latest copy of the campfire service.

Click on the link I provided in the previous section and download the package. Once finished, open the package place it's entire contents in the campfire directory of your Symphony installation. In almost all cases it will be in the %Symphony Root%/campfire/ directory.

Next, go to your Symphony administration panel and navigate to your Campfire section. You'll see a new entry entitled 'Section Search'. Click on the title of the campfire service and you will be whisked away to it's information screen. At the bottom of the screen you should see a button labeled 'Install Service'. Click this button and Section Searching should now be activated on your site.

Getting Dirty:

Now that you have the actual service installed, we're going to perform some XSL magic to get your search form up and usable. Now, there are countless ways we can do this and, due to the nature of the system, we could place this code anywhere on your site. But, for the sake of simplicity, I'll take the straight forward and common approach.

Follow these steps:
  1. Go to your page management screen in your Symphony install's administration panel.
  2. Click on the 'Create New' link.
  3. Give your page the title 'Search'.
  4. Click the 'configure' button located at the top of the new page form.
  5. Under the 'Page Environment' section you will see a list of datasources. Select the 'Section Search' datasource.
  6. Close the configuration form by clicking the 'configure' button again.
  7. I'll keep this VERY simple. Paste this code block into the 'Body' field of your new page and click the 'Save' button.

All done! Now you have a simple search form that, when submitted, will display an ordered list of entries from your 'entries' section.

Note: Now, you may not have an entries section. It could just as well be entitled articles under your install. If this is the case, you're going to have to change a very small bit of code. From the block of code above, you will notice a hidden element within the form entitled section. This variable specifies which section you want to search. The current value of this element is entries, but in your case it might be articles or blog. Just make sure you change the value of that element to what ever existing section you'd like to search or it just won't show any results.

You can even toy with the URL schema of the search page to change what section you'd like to search on the fly!

That's all folks!

Didn't seem so hard, did it? In this tutorial you learned how easy it is to set up content searching within your Symphony installation. Hopefully, this will help some of you guys and gals who've been having trouble in getting this type of functionality up and running on your sites. If you have any trouble, please just post a comment in this article and I'll be quick to respond.

Till next time!

Loading mentions Retweet
Filed under  //   Code Monkey   Symphony   Tutorials and Such  

Comments [0]

Adding YouTube to Markdown

After digging through the documentation over at Daringfireball, I noticed that there are no references to quickly embedding www.youtube.com">YouTube videos into your content using Markdown. Since I usually come across some great YouTube finds, it disappoints me that I have no easy way to implement them into my articles.

Well, no more! Like any other code monkey out there, since I didn't find a solution, I made my own. Naturally, I'm posting about it here to spread the word!

Before You Begin

  1. Before we start, this tutorial assumes that you aren't afraid of getting your hands dirty by digging into some PHP code. You won't be heavily modifying anything yourself since I've done all the hard work. You'll mostly just have to cut and paste these instructions and save your changes.

  2. We will be refering to the PHP-based version of the Markdown library, so, if you don't have it, get it from here.

  3. Also, this is a generalized tutorial and assumes that all PHP-based publishing platforms that use Markdown are using the same version we are in this tutorial. Some publishing platforms may or may not have a modified version of the text parser, so you will have to apply our changes accordingly.

  4. Remember, it is always good programming practice to backup your work before you make any changes.

  5. This is a very simple customization, so there aren't any options that allow you change the way your videos are displayed. You'll have to modify this code yourself if you have some specified types of changes in mind.

Let's Get Started

Ok, so let's get started by opening up the Markdown library in our favorite IDE.

First, you need to add two new methods to the library: the pattern matching method doYouTube and the corresponding callback method _doYouTube_callback that does all the magic. As long as these methods are placed somewhere within the Markdown object, everything should work just fine, but for the sake of this tutorial, scroll down to line 651 and add the following blocks of code:

// ! Executor

/**
* Pattern matching method for the YouTube tag.
*
* @param $text The string to parse
* @return String
*/
function doYouTube($text)
{
    $text = preg_replace_callback('{==youtube(([a-zA-Z0-9-_]*))==}xis', array(&$this, '_doYouTube_callback'), $text);

    return $text;
}


// ! Executor (callback)

/**
* The callback method for $this->doYouTube that creates
* the appropriate replacement for the YouTube tag.
*
* @param $matches Any matches found during parse time
* @return String
*/
function _doYouTube_callback($matches)
{
    if(isset($matches[1]))
    {
        $video = $matches[1];

        $result  = "";
        $result .= "    ";
        $result .= "    ";
        $result .= "    ";
        $result .= "";

        return $result;
    }

    return '';
}

Next, we need to tell Markdown to actually parse for YouTube, so look for the following block of code:

# Process anchor and image tags. Images must come first,
# because ![foo][f] looks like an anchor.
"doImages"            =>  10,
"doAnchors"           =>  20,

And change it to:

# Process anchor and image tags. Images must come first,
# because ![foo][f] looks like an anchor.
"doImages"            =>  10,
"doAnchors"           =>  20,
"doYouTube"           =>  30,

This tells the Markdown parser to run these methods when translating our content. The corresponding number value is used to determine priority, but, for some odd reason, these numbers aren't even used in Markdown. Weird.

That's it! Just save your changes and upload it to your site and overwrite whatever version your software was using.

Using YouTube

Now that we have a YouTube tag added to our arsenal, adding videos to your posts is as easy as doing the following:

==youtube(video_id)==

Replace video_id with the actual identifier for the video. In our case, it would be one of our favorite skits from Robot Chicken:

==youtube(bvWQNa1czG4)==

Zomg Wow!

Well, that was easy! Naturally, if you find any issues with this tutorial, feel free to bring it to my attention by posting a comment.

Till next time ...

Loading mentions Retweet
Filed under  //   Code Monkey   Development   Tutorials and Such  

Comments [0]

Using Markdown in MyTopix

There are a number of people out there who would much rather use the popular Markdown as a text parser as opposed to the standard bbCode tags that have become popular with most modern discussion boards. So, to satisfy this growing number of individuals, I've gone ahead and thrown together an extremely simple tutorial on how to implement this alternative text-to-html conversion tool into MyTopix.

Getting Markdown

Before you can use Markdown, you must first download the appropriate library. Since MyTopix is written in PHP, we cannot use the standard Markdown library which is written in Perl. Fortunately for us, Michel Fortin wrote a PHP-based alternative, so go get it!

Implementing Markdown

This is the easy part. Just drop the markdown.php file in MyTopix's library folder which is located directly beneath the MyTopix root directory %root%/lib/.

Before we start messing with core files, it's always a great idea to be on the safe side, I suggest creating a backup of the original file just in case you messed something up.

Next, you'll need to open the system's text parsing library and make a small change. Within the same library folder, open the file named parse.han.php in your favorite IDE. Within your IDE, scroll down to line 132. It should look like the following block of code:

$string = $this->parseBlocks ( $string );
$string = $this->parseSimple ( $string );
$string = $this->parseLinks  ( $string );

You're going to want to replace it with:

require_once SYSTEM_PATH . 'lib/markdown.php';

$string = Markdown($string);

Save and upload the library, overwriting the older version to complete this mod. There, that's it. You're done!

Say What Now?

Yep, that's all there is to it. MyTopix makes this change simple because it parses the text during read time. To save resources, a lot of forum softwares out there convert text during post time and save the translated version in the database. Since the text is already translated, it doesn't need to go through a parser during read time. The only time it gets translated back to bbCode is when a user attempts to edit or quote an existing post.

MyTopix doesn't do this, so we really only have to change a couple lines to make this whole thing work. It even works well with emoticons turned on too.

I hope you enjoyed this tutorial! Till next time ...

Loading mentions Retweet
Filed under  //   Code Monkey   MyTopix   Tutorials and Such  

Comments [0]

Creating datasources that pull random content

I was recently browsing around the Overture forums the other day looking for some new tips and tricks for Symphony and came to the realization that when it comes to creating new Datasources, Symphony doesn't offer an option to randomize the result set.

I realize this won't be an issue for most people, but what if you have a portfolio section to your site and you want to pull some random portfolio entries for the front page? What if you'd like to do the same with comments or articles? This tutorial aims to provide a relatively simple solution for this small issue.

Prologue

Before we start, I thought I'd let you all know that this tutorial assumes that you have a rudimentary understanding of Datasources for the Symphony publishing platform. If not, you can access the public wiki dedicated to Symphony documentation for more information. This tutorial also assumes that you're not afraid to get your hands a little dirty with the source code.

Creating the Datasource

For the sake of this tutorial, let's just say you would like to display 3 random comments on your site's main page. To accomplish this, you must first create a new Datasource. Click the image below to get the full details of this Datasource.

Datasource Preview

As you can see, this is a very basic Datasource. In this instance, we named our DS 'Random Comments', but you can call it whatever you like. The source of our data should be set to 'Comments'. Leave the filtering options alone for this tutorial; you won't really need them. In the 'format options' section, choose what fields you want included. You can choose a sorting option, but it won't really do any good as our result set will be randomized by the end of this tutorial.

Since we only want to show 3 random comments, set the Datasource limit options accordingly. Click the 'save' button and you should be good to go!.

Digging in the Source

Before We Start:

To speed up execution times, the Symphony team set up the system in such a way that it generates a new PHP source file every time you create a new Datasource. This source file's content reflects the settings you chose when creating the actual Datasource within the Symphony interface. On the system level, when a Datasource is attached to a page, Symphony will refer to the corresponding source file by including it and then executing it, generating the appropriate XML result set based on your specified criteria.

Neato!

Back to the Program:

Now, since Symphony doesn't have an option to randomize result sets, we're going to have to dive into our new Datasource's source file and change around a few things.

First, navigate to the following directory %symphony_root%/workspace/data-sources/ and open the file named data.random_comments.php in your favorite IDE. Now that you got the file open, we can handle this one of two ways. We can either randomize the returned data using PHP's built-in randomization functions or we can add a simple SQL clause into the database query strings that fetch our data. Since the latter is much simpler we'll just go with that.

In your IDE, run a quick search for ORDER BY. There should be 2 results. In both of these instances, you will need to change ORDER BY to ORDER BY RAND(),. Be sure to note the comma(,) right next to Rand().

Next, by default, Symphony likes to cache result sets pulled from Datasources. This will pretty much put a halt to all our hardwork. If our 3 random comments are cached, the system won't pull new random comments until said cache expires and updates itself. We can't have that, so do the following:

Find:

##Check the cache
$hash_id = md5(get_class($this) . serialize($env_url));

if($param['caching'] && $cache = $this->check_cache($hash_id)){
    return $cache;
    exit();
}

And either delete it or comment it out:

//  ##Check the cache
//  $hash_id = md5(get_class($this) . serialize($env_url));
//
//  if($param['caching'] && $cache = $this->check_cache($hash_id)){
//      return $cache;
//      exit();
//  }

Now, save your changes and upload it back to its home directory.

Using Your Datasource

Using this new Datasource is no different than any other. Before the system generates your XML, you will first need to attach this Datasource to a page. To display your random comments, you will need to modify the page's main template.

Find where you would like to see your comments and add something like the following:

<xsl:for-each select="random-comments/entry/comment/">
    <div>
        <xsl:value-of select="author"/> Said:<br />
        <xsl:copy-of select="message/*"/>
    </div>
</xsl:for-each>

Naturally, you'd want to spruce it up a bit, but, for the most part, that's all you need to do. Save your page's main template and view the live result. You should now see 3 random comments appear every time you refresh your page!

Please Note

Don't let all your hard work go to waste! Every time you update your Datasource's options within Symphony's interface, the system rewrites the entire source file, thus overwriting all your changes. Just remember, if you have to make a change to the Datasource, you'll need to go back and reapply these modifications.

In Closing

Well, that's pretty much all there is to it. In this tutorial you learned how to create a Datasource that randomizes result sets by modifying its source code. See what else you can do by changing a few more things around in the source. If you mess up and break something, just re-save your Datasource in the Symphony interface to overwrite your changes.

I hope you enjoyed this tutorial as much as I enjoyed writing it! Till next time ...

Loading mentions Retweet
Filed under  //   Development   Symphony   Tutorials and Such  

Comments [0]

Building MyTopix Modules

With MyTopix becoming more and more popular in recent months I think it's about time I started pumping out some tutorials so you all can make your own modifications and features. I've always thought that people learned more through example rather than reading long and drawn out technical documentation, so let's just jump right into the system and learn what modules are, how they work and how we can create new ones.

Understanding The Basics

In order to create a new module, one must understand how MyTopix handles said modules. What's a module? Well, in this instance a module could be defined as the individual screens you view when browsing the MyTopix interface. For example, the user registration area of MyTopix is referred to as the register module. The same goes for your personal control panel, the private messaging system and so on. Each of these sections all have their very own modules.

To add a new module to MyTopix, you need to do two simple things. First, you need the actual module itself, which is a PHP file. Second, you need to tell the system that the module actually exists by registering it. But, before we get into that, let's discuss what a module really is.

What Makes a Module?

Since MyTopix is written using simple object oriented principles, all modules exist as objects. All module objects are given the name ModuleObject. Since modules are only ever executed one per user request, there are never any naming conflicts, so giving all module objects the same name is never really an issue.

Below, you will find an example of a module object in its most simplest form. I will try my best to explain how it works in Layman's terms, but I won't go into too much detail about the object oriented aspects of the code as it falls out of this article's scope.

class ModuleObject extends MasterObject
{
    var $_message;

    function ModuleObject(& $module, & $config, $cache)
    {
        $this->MasterObject($module, $config, $cache);

        $this->_message = 'Hello World!';
    }

    function execute()
    {
        return $this->_message;
    }
}
Class Naming Conventions

You can see here the class ModuleObject being declared and extending its parent class MasterObject. The class MasterObject is just that, a master object, because it contains all the core functions the system will ever need to get its modules running properly. For instance, it contains the UserHandler, which is an object responsible for authenticating user sessions and pulling their account data.MasterObject also contains the database abstraction layer that allows modules to interact with the specified database.

class ModuleObject extends MasterObject
Defining Instance Variables

Next, we have an example of an instance variable, also called an object's property. Instance variables, depending on their types, are usually used to define an object's attributes. In the example above, our particular module object has a message attribute that will only be used within said object.

var $_message;
Constructors

Moving on, we have the module object's constructor. A constructor is basically a method that is automatically called once you instantiate (or run) an object. It's purpose is to, more or less, prepare the object for use. In MyTopix, all constructors must have the same name as the objects they reside in.

function ModuleObject(& $module, & $config, $cache)

You can also see 3 parameters that are passed into the constructor. These are very important and essential if you want your modules to work properly, or at all.

The first parameter, $module, is just the system name of the requested module. For example, if you're registering a new account, the name of the module being executed is register.

The second parameter, $config, is the system configuration array. This contains the values for all the system settings which include paths to special directories, configuration options for user avatars, etc.

The third and final parameter, $cache, contains which cache groups are assigned to the requested module. Just as with every other system out there, cache can be considered a storage area that contains frequently used data. For instance, all forum settings are cached as well as skin, language and emoticon information. We place all these cache groups in a single table within the database, so we can call upon them all using a single query rather than a complex query for each table we need to pull data from. We'll discuss MyTopix's version of caching in greater detail in a future article.

You may also notice the following line right below where we declared the constructor:

$this->MasterObject($module, $config, $cache);

On this line, we are instantiating the parent class MasterObject and routing all those previously mentioned parameters to it. Once we get to this step, the system executes the MasterObject constructor, which, in turn, loads all the core library objects.

Finally, you will notice that we're giving our message instance variable a default value of 'Hello World!'. It is good practice to assign default values to ALL your declared instance variables within the module object's constructor.

$this->_message = 'Hello World!';
The Boot Method

Every module needs a boot method. As the final step in the system's initialization process, the boot method is typically the very last thing to execute. All boot methods for modules are aptly entitled execute. This is where all the magic happens for your module. It is within this method where you place all your custom code and calls to other subroutines. In our little example, the boot method simply returns a message that every code monkey should be familiar with:

function execute()
{
    return $this->_message;
}

You might want to note that all methods, excluding the constructor, should return something, anything. So, when in doubt, just add return true; to the very end of all your methods.

Adding a New Module

Now that we have a basic idea of how modules are handled within MyTopix we can begin learning about how to add them to the system. Remember, there are 2 steps that we need to take in order to implement a new module.

Implementing the Module's File

This is probably the simplest step. All it involves is dropping your new module file in the appropriate directory. For this article, let's just save our basic object in a file named test.mod.php to the modules directory, which can be found directly beneath your MyTopix root directory. If you are working with a hosted MyTopix installation, you'll need to FTP the file to the corresponding directory after saving it locally.

Registering the Module

This step may seem a bit confusing to some, so I'll try and tone it down a bit. In order for MyTopix to actually see your new module, you need to register it within the system. In order to do so, you will need to modify a source file. Don't worry, it's easier than you think.

Within your MyTopix installation, navigate to the config directory that resides directly beneath the system's root. You see a listing of files, one of which is named pub_modules.php; short for 'public modules'. Open this file and take a peak inside. You will see the following:

$modules = array();

//MODULE NAMES:        CACHE GROUPS:

$modules['active']   = array('forums');
... 
more modules 
...
$modules['calendar'] = array('emoticons', 'filter', 'titles');

As you can see, the system's module registry is a simple 2-dimensional array containing the system names of modules and corresponding cache groups.

We want the system to see our test.mod.php file, so we are going to add the following line directly after the very last entry of the list.

$modules['test'] = array();

Note that the name of our entry is exactly the same as the file name of our module, test.mod.php. This is important because if you misspell the entry, MyTopix will attempt to open a file that does not exist, thus resulting in the system going banana sandwiches. We don't want that, so be careful.

When we are done, the registry should now look like:

$modules = array();

//MODULE NAMES:        CACHE GROUPS:

$modules['active']   = array('forums');
... 
more modules 
...
$modules['calendar'] = array('emoticons', 'filter', 'titles');
$modules['test']     = array();

Save the file and place it in the appropriate directory, overwriting the old version.

The Moment of Truth

Now that we finished all these steps, we can finally call this module and see the result of all our hard work. In MyTopix, to call a module, you must use the following format:

http://www.mysite.com/forum/index.php?a=module_name
or, in this case,
http://www.mysite.com/forum/index.php?a=test

If you see 'Hello World!' printed at the top of the screen, you can consider your efforts a success!

In Closing ...

In this installment, you learned what modules are how they operate within the system. You also learned how to create your own custom modules and implement them to add new functionality to your MyTopix installation. Unfortunately, without knowing more about MyTopix's core functionality, your early modules probably won't be doing much. We plan on addressing this issue in the coming weeks.

In our next article, I will teach you how to create your very own basic RSS module and, in doing so, introduce you to some of the most widely used objects within MyTopix. Sort of a bonus for some, I suppose, considering the fact that RSS functionality is one of the most requested feature enhancements for the system.

Well, I hope you all enjoyed this article and were able to get something out of it. Thanks and stay tuned for more!

Loading mentions Retweet
Filed under  //   Code Monkey   MyTopix   Tutorials and Such  

Comments [0]

Upcoming Series on OpenId

I just realized that for a tech-oriented blog, there isn't really a whole lot of tech-oriented entries. So, in an effort to rectify this issue, and to get some readers interested in this place, I've decided to create a series of articles that deal directly with OpenId.

Why OpenId? Well, it seems like an interesting technology that I think more people, especially my fellow developers, should know about and, hopefully, want to know about. So, in the coming weeks, expect to see some thorough content on the subject that covers the following concerns:

  1. What is OpenId?
  2. Why is OpenId?
  3. What are its benefits?
  4. How can I use it with my site / software?
  5. How can I implement this solution using PHP?

The first article will deal mainly with the first 4 in the list while all subsequent articles will cover how to implement this authentication solution using PHP.

Stay tuned! I know I will.

Loading mentions Retweet
Filed under  //   Development   OpenId   Tutorials and Such  

Comments [0]