In this first article I give you detailed instructions on how the recently added Community Link Feed function have been build. This includes a introduction to writing a Joomla Module that graps data from a database and presents it nicely in the sidebar (see screenshot below). The solution is based on Chronoforms and the module I describe and provide here is actually needed and requested in the community and not yet provided by chronoengine.com.


ElegantThemes
ThemeForest

Advertisement

You may ask why anyone would add a feature that allows its users to add Links and Descriptions to their own articles? First of all I have experienced that using Community Link Services on popular websites can be a good source to traffic if you add articles that match the main topics of the website. This means that some people will visit websites that have a Community Link Feed function only to add their new posts to the list. If they start generating traffic this pattern will only grow stronger. Community Link Feeds are also a great way to make sure that your website is updated regularly making both Search Engines and visitors more happy.Basically this means that adding a Community Link Feed function over time will you give more traffic and more important a list of relevant links that will updated all by itself. Be aware that you should monitor the links that your users submit to make sure that links you wouldn’t add yourself is removed before anyone gets offended. You may also just put in some kind of moderation before links goes online.

What does a Community Link Feed function consist off? Below I will take you through the details.

1] The Input Form: A Input form that typically consists of the following input fields: Name, Email, Title, URL and Description. The form should provide some basic validation to make sure the information put in is valid (like a valid e-mail address or a valid URL.)

2] A mechanism to write the input data to a database

3] A simple function that allows you to moderate the links provided by your users. I would say that deletion is enough but it depends…)

4] Creating a Joomla Module that presents data from a database. A Module that reads the data and presents the Links as a Community Feed in the fx. in the sidebar.

The Input Form

There are many ways to create forms in Joomla (on extensions.Joomla.org there are 22 extensions available) I have decided to use ChronoForms that is a really feature rich and free extension. There is a copyright link in all the pages it generate but you can legally remove it by purchasing a 25$ license.

Get started:

Download and install Chronoforms V3.1 RC2.zip

This is the main component that you need to download and install. This article assumes that you know how to install Joomla modules, plugins etc.

tutorials

ChronoForms Mambot_V0.9_V3.1RC2.zip

You need this mambot To view the form inside an article using Chronoforms component V3.1. This mambot is not used in this article but you may find it interesting.

Configure the form:

In the following steps you will set up the following form using Chronoformsand simply by uploading the configuration provided below.

the form

  • Download the configuration file SubmitForm.cfbak by rigth clicking the link and choosing save target as.
  • Go into ChronoForms Form Management page
    chrono_menu
  • Click the Restore Form button.
  • Choose the file SubmitForm.cfbak and Click Submit file
    select_file
  • Your form has now been created and it is ready for final configuration. To test the form as it is try clicking the Link. The form will not really work yet as you need to create the database table that it will save its input data to.
    form_created
  • Creating the database table is really easy. Just select your form and click the Create Table button. This will bring up the following screen where you need to select all fields to be created. The name of the table will be suggested but take a note of it as you need it later on. Click Save Table.
    create_table
  • Finally you have to make sure the form is configured to use the database table you just created. Click on the form name and you will be directed to the form details page. Click on the DB Connection tab and select the database table name.
    choose_db
  • Configure your redirect URL that the user should be redirected to once the form has been submitted. Click on the Form URLs tab and type it in as shown below.
    form url
  • Thats it. Your form is ready to be used. You may want to configure more features like receiving e-mails when form is submitted or adding more complex validation rules. This is a tutorial covering basic form configuration and I will not uncover further details here.
  • Basic Moderation is offered through ChronoForms. Clicking on the table name in the column “Tables Connected” will take you to a page where unwanted entries can simply be deleted. It’s not a highly functional feature but it does what you basically need ChronoEngine also provides the component called ChronoConnectivity that can be used if you need more advanced editing features. You may also just use DB admin tools like phpMyAdmin if you have access to that kind of tools. ChronoConnectivity on the other hand can be used for creating pages in Joomla that show the data being put into a database using ChronoForms why you may consider using it.

Creating a Joomla Module that presents data from a database

As a developer you are probably lazy – right? I am and that is why I wouldn’t want to start from scratch when it is not necessary. The objective I had was to create a simple module that could easily be configured to select data from a database and present them on a page in a module place holder. Let’s try the module first and them go through how it is implemented afterwards.

Setup the Community Link Feed Module

  • Download the module file here and install it in Joomla. mod_communitylinks.zip
  • Perform basic configuration of the module (make sure it is enabled, title is shown if needed, that it is placed on the page in the right spot etc.)
  • The module is very simple and basically takes a SQL string to select the data you need (in this case the data being put in but the form)
    SQL used in this Tutorial is: SELECT a.cf_id, a.name, a.email, a.webtitle, a.weburl, a.webdesc FROM jos_chronoforms_SubmitForm AS a ORDER BY a.cf_id DESC LIMIT 0,8
    NB if you changed the table name earlier change jos_chronoforms_SubmitForm to your table name! The SQL pasted in here only returns the latest 8 records.
    module_config2
  • The template provided (gonna explain this in more detail below) allows you to put in a Submit link that points to your ChronoForms page and a link to a page where all your submitted links are listed (ex. if you are using ChronoConnectivity).
  • Thats it – the module has been configured and should look like this depending ofcause on your look and feel (CSS).
    sidebar_link_feed

How is the Module implemented

Creating modules for Joomla is not that hard if you what you want to acheive is fairly simple. As a rule of thumb you should look at what is already there that may kick start you new development. I found that the Related Items Module (mod_related_items) was doing most of the things needed and just started modifying it. What does it consist of:

  • helper.php (basically contains function getList($params) that selects articles from the Joomla database and returns an array of articles)
  • index.html (just an emply file to avoid file not found errors.)
  • mod_related_items.php (the mail module file that calls the getList and applies the template file)
  • mod_related_items.xml (module information file)
  • tmpl/default.php (php template file that builds up the HTML)
  • tmpl/index.html (just an emply file to avoid file not found errors.)

I started out by renaming the following files.

  • mod_related_items.php –> mod_communitylinks.php
  • mod_related_items.xml –> mod_communitylinks.xml

I them updated the following very little files as explained below.

  • helper.php
    I changed the class name to fit the current module name. I then stripped out all the code that was related to Joomla article handling and externalized the SQL statement. The code $query = trim($params->get(‘select_sql’)); basically taked the SQL statement that you specified above when configuring the module and loads it into a variable called $query. This is then used as input to performing a query against the database.
    helper_code
  • mod_communitylinks.php
    Changes in this file are minimal. Just has to use the right class name as it was changed in helper.php. $list = modcommunitylinksHelper::getList($params);
    Finally the module name had to be changed here to “mod_communitylinks”: require(JModuleHelper::getLayoutPath(‘mod_communitylinks’));
    mod_communitylinks_php
  • mod_communitylinks.xml
    In the module configuration file I just had to update the meta information like author, etc. I also added the files in the module to make sure the zip installed correctly (may be not included as related items module is just installed with Joomla…nut it is needed. I then added a few param definitions to make sure that the module configuration page will provide some text fields to insert fx. SQL statemend and Link to Form.
    mod_communitylinks_xml
  • tmpl/default.php
    I admit it…the template file is not perfect….But it generates a list as needed and inserts two links to the Submit Link form and a page that shows the full list of links submitted. The code loops through all the items (rows) returned from the database. As you can see the $item–>property is used to insert data pulled out from the database. Againg $params->get is used to insert data from the configuration of the module.
    tmpl

I hope you enjoyed reading this tutorial. Please post nay question you may have as comments and I will do my best to answer as quickly as possible.

Pin It on Pinterest

Shares
Share This

Share This

Share this post with your friends!

Shares