Archive for March 9th, 2007

How to Create Modules in Pligg

Hi - you seem to be new here. If you like what you see, please give back by subscribing to my RSS feed!

You can check me out on Twitter, Facebook, or FriendFeed to see what I'm up to. Thanks for visiting!

As I mentioned earlier, for came2pass.com I had promised any changes to the site would be submitted back to the community for other Pligg administrators to use. I have had several ideas of new functionality for Pligg, of which I am developing. You can expect those in the coming months. Pligg actually makes it really easy to add new functionality with a very little documented plugin architecture called Modules. I have decided to document it here for others to use. It is my hope this can expand the Pligg community even faster than before. I’d like to start this with a disclaimer that I am not a PHP developer as my first trade - my experience roots in Perl, but I do a little PHP as well for my job. So if my terminology is incorrect, please forgive me - it is my intention to have this out there as a service to the community. I am also an outsider - I did not write the Pligg code, and I have not until recently gotten involved with the Pligg community. I have only recently begun to read the Pligg internals, and I try to note my lack of knowledge in the areas I still don’t fully understand. I’ll update this blog entry if I stand corrected in anything, and if anything needs to be added.

While I’d like to delve in immediately on Modules, I should probably preface that there are actually 2 extendible architecture types in Pligg. The first is Pligg’s Module system, a pluggable architecture to extend Pligg functionality. The second are Pligg templates. These allow you to customize your own look and feel, and perhaps even add a few extra functional elements to Pligg as well. Because there is already a vast amount of documentation on the web for templates, I’ll save that for later. Today I’ll focus on Pligg Modules.

Module Hierarchy

To understand how modules work, you have to understand the filesystem hierarchy for each module. All Pligg modules exist as individual directories (listed by module name) in pliggroot/modules. I will refer to pliggroot throughout this document as the path to your pligg web application.

Within pliggroot is also a file called module.php. This is mostly just a file for use by each Module later. It’s a pretty bare-bones file that calls a few of the essential libraries needed to write pligg pages.

Within pliggroot/modules, there are also 3 php files, modules\_init.php, modules\_libs.php, and modules\_manage.php. My understanding is that these files are called when each module hook is called, and tell pligg how to load the modules. I haven’t read deep into them though, so I’ll let the Pligg maintainers explain that later if they want.

Underneath each module directory you will always have a series of files. I will explain those below:

modulename_init.php

Throughout this document, the term “modulename” is the main identifier of the module being written. It just has to be consistent, and unique - I don’t think it really matters what you name it.

modulename\_init.php is your main controller for your module. Most module\_init’s start out with a call to:

include_once(’modulename_settings.php’);

I’ll explain what that does in a minute. To summarize, it essentially loads all the variables to be used throughout your module.

Following that block, you’ll see in most modules a:

$include_in_pages = array(’all’);
$do_not_include_in_pages = array();

As the comments in this module says:

// tell pligg what pages this modules should be included in
// pages are minus .php
// index.php becomes ‘index’ and upcoming.php becomes ‘upcoming’

This is essentially a good way to speed up your application. By not selecting “all” and only selecting the pages you want your module to load in, your module will only be called from the pages you select. This keeps unneeded code from loading on the other pages. So, to only load your page in index.php, replace the first line above with:

$include_in_pages = array(’index’);

$do\_not\_include\_in\_pages() works the same as above, but you are to include in that any pages you absolutely do not want your module to load in. I’m assuming that works best with ‘all’ in $include\_in\_pages.

Next, in each modulename\_init.php you’ll see a section that looks like this:

if( do_we_load_module() ) {

module_add_action(’module_page’, ‘modulename_function’, ”);
module_add_action_tpl(’tpl_sidebar_top’, modulename_tpl_path . ‘module_tpl.tpl’);

include_once(mnmmodules . ‘modulename/modulename_main.php’);
}

In the first part, it’s just checking the arrays we talked about above to see if we should go further.

The next module\_add\_actions are essentially setting callbacks for various sections already in the code. module\_add\_action() runs the function listed as parameter 2 at the location of the callback name listed as parameter 1. That function is located in modulename\_main.php. The 3rd parameter I believe is just any parameters you want to send to the function you just called - I haven’t gotten this to work yet though.

module\_add\_action\_tpl() works similarly. The first parameter is a callback name within a template in your templates directory. The second parameter is the name of the customized template you want to place at the location of that callback. module\_add\_action\_tpl() is a great way to insert custom html code into an already existing template.

I have also seen module\_add\_action\_js and module\_add\_action\_css - I’m pretty sure these work similar to module\_add\_action\_tpl, but for css and js files in your templates architecture.

The next line is:

include_once(mnmmodules . ‘modulename/modulename_main.php’);

This just tells modulename_init.php to include the modulename_main.php file for use with the above callbacks. I’ll explain the various callbacks in the main pligg architecture and templates later.

modulename_main.php

modulename\_main.php is simple. It’s just a list of functions you can use elsewhere in your module, such as we just mentioned in modulename\_init.php. You can use all the already included globals that have been called from module.php, including $db, $smarty, $user, and others.

modulename_settings.php

This is where you initialize and set all your variables. To define a variable that can be called from $smartyvariables in your custom templates, do something like this:

define(’modulename_path’, my_pligg_base . ‘/modules/modulename/’);
$main_smarty->assign(’modulename_path’, modulename_path);

You can really put anything you want in here that you want called before everything else gets called (see where it’s called above).

modulename_install.php

I can see this module being underused to it’s capacity. This module gets included/called when you click “install” or “enable” under modules as God mode under Pligg’s admin section. Most modules just use it to set some critical variables which I will explain in a second, but you could also use it to do things such as add database tables, add your own patches to Pligg, etc. if you really put it to use. I’ll stick to what most people are doing here though, and that’s set critical variables that determine if the module can be installed or not. Most modules have this code in it:

$module_info['name'] = ‘My Module Name’;
$module_info['desc'] = ‘This is my sample module description’;
$module_info['version'] = 0.1;
$module_info['requires'][] = array(’PHP’, 5);

“name” is just your module name listed with all the other modules. “desc” is the description listed with all the other modules. “version” is the version. “requires” is an array of all required elements. I need to research “requires” further though, as I don’t know how it actually works.

modulename_readme.htm

This is just a readme file that gets linked from the list of modules page in admin mode, of which you can put anything about your module for others to see. I recommend listing notes about any special instructions you have for your users, that you know will get asked on the Pligg forums later.

lang.conf

This is exactly the same as your main lang.conf used in the main Pligg architecture. It is a file to specify global variables that you want to access later. I’m not sure if this shows up under language in your Admin or not. You can then call this lang.conf in your custom templates for your module. Just be sure to reload the main lang.conf after your template is finished, or it will overwrite the current lang.conf!

templates

This is your view. Any user interaction with your module should go here. You can add any template, css, or js file in here, so long as you call them from your callbacks listed in modulename\_init.php. I suggest researching template creation for this, and armed with everything listed above you should be able to create something pretty powerful.

Callbacks

Callbacks are what initiate the entire module process. In each main Pligg architecture php and template file are one or more “callbacks”. In the Pligg php files look for the function “check_actions()”. This function has a string in it - that is the name of your callback. When “check_actions” is called, it reads through all the modules and first looks to see if the current “SCRIPT\_NAME” environment variable (minus .php and the leading “/”) is one of those listed in the $include\_in\_pages array. If this is the case and you specified this callback name in your module_add_action call in your modulename_init.php file, it will run the function associated with that call.

For templates, in your main template architecture, look for something like:

{checkActionsTpl location=”tpl_sidebar_top”}

The {checkActionsTpl call works very similar to above. It also triggers a search for all modules looking for the callback name listed in “location=”, and inserts the template specified by that callback name into the location of the checkActionsTpl call. Again, see above to see how the callbacks are called in your module.

Contextual Scripture “Link Ads”

I was pondering today and had an interesting idea and I’m wondering if it has already been done. If not, maybe I’ll figure out a way to develop something that does it. I have recently been researching “contextual link ads”. These are ads that are basically random links of words within your blog entries that link back to an advertiser that has paid for that placement. It’s a great idea - people are naturally curious, and want to know what the links within blog posts are. I personally do not think they are annoying, as they do not distract from the content being presented.

That concept got me thinking. What if I were to create a service that does this for scriptural quotes and words of the prophets? You place a piece of javascript on your site, and a central database somewhere references particular words and phrases with scriptures and words of inspiration. It would be very interesting to see the links that appear on your site from that, and what your writing actually references to in the scriptures! What are your thoughts? If I were to do something like this, what would you like to see?

Marketing and Sales - a Bad Thing?

I have been criticized for “Profiting from my Religion” on Came2Pass.com. All this stems from ads that I place on the site to keep a steady stream of income (if you count $.50 a day as income) to help support the site. The ads are usually from other LDS businesses, some times non-LDS businesses that are pertinent to the content that is currently on the page. We do not make money off our users. It also stems from a marketing campaign I am doing to quickly attract new users from all stereotypes, in which we are giving money and prizes to our users.

As many who know me know, I am a huge proponent of “Donating One’s Time and Talents to the Building of the Kingdom of God”. IMO, if you truly believe in something, all your life should be spent building upon those principles. I believe so much that I’ve helped start a group called LDSOSS, which focuses on this principle in regards to software development.

So I got thinking - if one can spend one’s time and talents developing software towards the building of the Kingdom of God, can one spend one’s time in Marketing or Sales doing the same? Is marketing and sales truly a tool of the Devil? I know about 6 marketers or sales people that would digress, but then again - they’re sales and marketing people. Who wants to listen to those people anyway? They don’t have time and talents to give, do they? Or do they?

I’ve thought about starting an LDS news site without ads, donating my time and talents in software development to help accomplish such. If I were to do so, a few people would join and bond together, some would even invite others, but how long would it take until I had a large enough community to fend off anti-Mormon attacks and spam on the site? I have a day job to support my family - would I have enough time to pay attention to the site every waking hour? Something this important should not just be a side-job.

I want Came2Pass.com to become the internet’s largest LDS news portal. There is strength in numbers. If I can use my talents to market and sell to bring in masses of people to one location for one purpose that helps build the Kingdom of God and at the same time drive away any anti-Mormon propaganda that is out there, is there anything wrong with that?

100 for $100, 500 for $50 on Came2Pass.com

For those of you who are members of the Church of Jesus Christ of Latter-Day Saints, I have a proposal for you. As I mentioned before, I’ve started a new little venture called Came2Pass.com. Its slogan is “News for Mormons, by Mormons”, and it will soon become your one-stop shop for all LDS-related news, information, and stories. It is a place where you, your mom, your grandpa, or even your best friend can get together and know what each other are looking at on the web. It’s cutting edge for Mormon News!

Well, I’d like to make being part of the Came2Pass.com community a little sweeter. As of today, I am initiating a contest. From the time Came2Pass went live until now the first 100 users that sign up and submit a unique, appropriate LDS-standards related story get entered into a random drawing for $100. Yes, you have to sign up, and yes, you have to actually submit an appropriate, unique LDS-standards related story to be eligible.

Is that not enough? How about I make the deal even better? The first 500 users that submit at least 1 vote on stories will be eligible for a random, $50 drawing at the end of the 500 votes. Each user only gets entered once per contest, and no, you can’t win both contests, but you should try on both, as you may win one or the other! Please ensure you sign up with a valid e-mail address, as

So I encourage everyone to hurry up and subscribe and start voting on articles! It could mean $100 in your pocket.

Here are some questions some of you may ask:

Is Nephi included in the drawing?

No. In case you haven’t noticed, Nephi is just a bot, and is built to agreggate several LDS-related feeds from off the web to ensure you always have plenty of original content.

So, how can I get original content if Nephi is already gathering it for me?

Nephi is set to only gather a few specific websites’ content. There is plenty more out there. Also, if you beat Nephi to the punch, you get credit for the content for purposes of the contest (JesseStay will even vote for your article!).

Do all my votes count towards the contest?

Unfortunately, we can only enter one vote per user into the contest. You can get double the chances by submitting an original story however!

How do I register?

Registering is easy! In the top bar of the page, you’ll see a “register” link. Click on it and it will ask for a username of your choice, password of your choice, and an e-mail address. Enter your information, and click “Create User”. Congratulations! You’re now a member of the Came2Pass community! Make sure your e-mail address is correct so we can contact you if you win the contest.

Also, you might enjoy after that point adding additional information about yourself for your friends to see. Click “Top Users” on the left and see if any of your friends are on there. Add them as friends if they are (more features surrounding that to come!).

How do I submit a story?

Submitting a story is easy! Simply login, click “Submit a New Story” on the left-hand page, and enter the url of the story you are linking to. If you would like to submit your own content, leave that page blank. Click “Continue”, and enter the information on the following page about your story (or your own original content). Then click “Preview and Submit”, review it, and be sure to submit it again, and you’re finished! See? Wasn’t that easy?

Please, if you have any more questions feel free to post them below, or click on the contact link at the bottom of Came2Pass.com. Again, the link to Came2Pass.com is:

http://www.came2pass.com

Good luck, and I’ll see you on Came2Pass.com!

UPDATE: Now instead of one vote per person being entered in the contest, each vote you make gets entered. Therefore the more votes you make, the better your chances of winning the $50! Good luck, and tell your friends!

Microsoft - the “real” Innovator?

My Linux and Mac Buddies are going to have my hide for this one. First of all, I love Macs. I love Linux. I think they both have their place, and have both done an excellent job putting a huge challenge to a very large Monopoly named Microsoft. Linux, in fact, is my livelihood.

That said, it irks me when I hear stories that Microsoft is not an Innovator and that Vista has no new or innovative features. It bothers me that people think Microsoft is copying Apple in everything. Now, before you come after me with your shovels and torches, let me explain.

Microsoft has been secretly doing something behind the scenes. They haven’t advertised it much, they haven’t even talked about it much. It started back in Windows XP days with a new release of XP called Windows Media Center Edition. It mostly came as an OEM release, meaning that it could only be purchased pre-installed with a manufactured PC such as Dell or HP. You may have seen it at your local Computer Retailer.

Media Center was essentially an add-on to Windows XP that allowed you to do media-related activities with the touch of a remote, no mouse needed. You could watch TV through it, pause, rewind, fast-forward TV like Tivo. You could schedule recordings to your hard drive and watch them later. You also had access to your entire video and/or mp3 collection via one of the best interfaces around.

Not long after Windows XP Media Center Edition was released, Microsoft started releasing hardware clients called Windows Media Center Extenders. These extenders attached to any TV in your home, and basically allowed you to stream TV over your home network for each TV Tuner card you had in your computer. Not just that but you had all the features you had on your main Windows Media Center PC.

Soon after that, Microsoft released software that allowed your Xbox to communicate with the Windows Media Center PC, making the Xbox its own Media Center Extender. Now not only was the Windows PC the central Media Hub for your home, but now worked with the gaming in the home all in one box.

Later they released the Xbox 360, this time with the Media Center extender bundled in for free. Along with this came built-in audio and video streaming from a Windows PC (doesn’t even need to be Media Center!). You got this, networked gaming, some of the best graphics around, all in HD format, all in one device that communicates with a Windows PC!

Now, we see the launch of Windows Vista. Vista Ultimate comes bundled with Media Center. Microsoft has released the Zune, while it may be a rip-off of the iPod, integrates better with Microsoft’s Media Center than any other portable device out there. Not just that, but it syncs with the Xbox directly! It came with features iPods only dreamed of having.

Microsoft has now announced IPTV that will integrate with the Xbox 360. I hear of no other manufacturer announcing such a product.

Now, out of nowhere, Apple has released their Apple TV product. It streams video, music, pictures, connects to the internet. It is meant to stream from a local Mac hub in the home. Gee - sound familiar?

Now there are already talks of Apple hiring game console developers and the possibility of an Apple gaming console that integrates with Apple TV. Apple is releasing faster and faster network speeds between Apple devices.

I ask, who’s copying who? Who’s the innovator? I think Microsoft is about to start marketing one of the largest innovations in their history - they just haven’t made it officially known yet. The thing is, it’s already here, right in front of our noses!

Apple is playing catch up - they know it. The great thing about Apple however is while they may copy, they at least copy better than Microsoft does. You be the judge - who’s the copycat?

Came2Pass.com

I have started a new venture that I hope can be of service to members of the Church of Jesus Christ of Latter-Day Saints. It’s called came2pass.com (http://www.came2pass.com) and it is intended to be a “Digg” for members of the Mormon Church. So, other Mormons can now share links and content they find with each other. Other registered members can vote for the content they like on the site, and the top voted content gets rated to the front page. They just need to register, submit an article (it supports editorials and user content as well), and then they can register friends as well, and then view what their friends are submitting and voting for. All pages have rss links so you can keep track of it all in your favorite rss reader.

I see this as a great tool for the average BYU student or alumni, where they can track the latest news on campus, rumors about candidates for student body President, their favorite professors, news on campus, etc. It would also be an excellent tool for the 40+ year old scrapbooking Mom. I keep getting chain letters from them - I think this is a great way to share the stuff in those chain letters with your friends and family that want to read it, and not worry about spamming those that don’t.

Because content can be submitted as well, I use it as a way to blog about the site. You just view my submissions page, and all new submissions count as blog entries.

Doh!

I’m about ready to shoot myself. I decided to try a Typo upgrade, and just realized it deleted the db! Fortunately, I had an old backup, but I’m missing about 4-5 articles from since then, including my one from today! I’ll have to decide if I need to reload the previous from some of the agreggators reading this site.