Howtos Archives - Page 5 of 5 - Stay N Alive

Collaborate With Smaller Groups of Digg Users Using Pligg

Yesterday, I announced the release of a new feature of Came2Pass.com, allowing users to specify a Digg User ID in their profile, and have all their Digg-submitted and voted-for articles automatically appear under 2 new categories with other Digg users on their Pligg-based website. Today, I’m happy to announce the release of the code for that feature of Pligg.

Using the link below, you can install a module into your Pligg installation which will take the Digg User IDs of members of your Pligg-run site that also use Digg.com. Once they have entered their Digg User ID in their profile, feeds will begin to import into 2 pre-specified categories (be sure to edit your digg_users_settings.php beforehand to specify these categories!), of which will show all the Digg submitted stories, and Digg voted stories of your Pligg site’s members.

What’s the big deal, you ask? Well, the big deal is you can now bring smaller groups of Digg users into one location, encouraging them to use your site, while being able to congregate, collaborate, and continue in the great community that Digg.com provides. Consider it a grouping tool! This is only the beginning, too – in the future, I hope to add search features to look for particular digg user ids on your Pligg website. You’ll also soon, when adding users of your Pligg website as friends, also add them as friends in Digg if they have specified a Digg ID. The possibilities are endless! Also expect future similar grouping tools for other social bookmarking websites as well (delicous? flickr?).

So, to install, just download the link below into your modules subdirectory in Pligg. Untar and un-gzip it in that directory. Now, under your God/Admin user in Pligg, go to Admin, Module Management, and click on install next to the Digg.com User Feeds module. You’ll also need the “Profile Extra Fields” module by AshDigg for it to work. Good luck, and let me know if you have any comments or suggestions!

http://forums.pligg.com/downloads.php?do=file&id=37&act=down

How to Create Modules in Pligg

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.

How to Find Inventory of Any Item at Target

I discovered a new site recently. I have to admit, among others, I have been one of the ones obsessed with finding the well-sought after Nintendo Wii. Well, there’s a new site out there called iTrackr.com. You pay them $2 for various products (per alert), and they go out and search various stores and send alerts to your cellphone and e-mail when they come available.

I have been obsessed with finding out how they do this, and I have noticed in several forums that others have as well. Well, I present to you the answer. I want you to look at the list of stores they offer notices for: CompUSA, Target, EB Games, GameSpot, and Circuit City. Now, go to those stores’ websites. Search for something on their site. Notice the little “check store availability” link? Bingo. Figure out how to get that link and you can check for store availability yourself on any item in their store.

So I spent some time tonight fishing around Target.com. If you notice, for most of the stores that list store availability, they cleverly don’t offer that option for the Nintendo Wii. You can, however figure out how to read that number by looking at the link for other items that offer the option. I was able to come up with the following URL that will tell you in the source code which stores in your area have the Nintendo Wii in their inventory:

http://www.target.com/gp/store-info/search-results.html/602-9935177-2156646?ie=UTF8&asin=B0009VXBAQ&zipcode=84118&fresh=1

All you need to do now is replace the 84118 with your zipcode, and the asin code with any asin code on the site, and you can get store availability for any item in the store. The above asin code just happens to be for the Nintendo Wii.

To find the availabilities, view the source, and look for the following:


tempData["storeName"] = trim("Sandy South Towne");
tempData["itemAvailability"] = trim("Out Of Stock");

There should be several of them – with any luck, one will say “Available”! As a side-note, you can also do this in the stores by entering the Wii sku for that target on the little red scanners. The above trick, and the scanners are usually right – even if it says they’re in stock and the employees say they aren’t, keep checking back and you will most likely see them on the shelves soon.

Now, I’ve helped you. This means it’s going to be harder for me to find a Wii. I ask in return if you happen to find one using this method that perhaps you could hold one for me so I can buy it for retail price! Donations of found Nintendo Wiis are also graciously accepted (hint, hint).

Stay tuned – I think I’m going to find the URLs for the other stores listed…