Tuesday, October 20, 2009

Content Component

The main content creation needs enhancing.
What i need is for a user to create an article, entering all the usual fields (description, title etc) as well being able to select an image.

Upon submission, the JOS_CONTENT item is created and the image is uploaded and saved to the users directory.

Why a new component? At the moment when you add an image its put into a general pool; not segregated by user, which i want to be able to do.

Components like JoomGallery use new tables which i don't want also i need to post-process adding watermark and creating resized versions.

So, to do this i'll need to create component to add/update content entry and processing to do the above.

Update
What i've done first is to create a new plugin that, on the event onAfterStoreUser uses the user's username and creates a new folder under the Media Managers Image Path.

All images will then be held under this folder.

Thursday, October 15, 2009

Search Plugin

Ok,
having finished a first pass at the component so search for 'Author' type users, i now want to search for that authors content when the user selects one of those Authors.

Best way seems to be a search plugin.

So, starting point is here. More to follow as i develop it.

Update #1 - Implementation
All we need to do is create an XML descriptor (authorcontent.xml) and a Php file to perform the search (authorcontent.php).

Update #2 - Using It
Ok, creating the search plugin is simple as detailed here.

Having developed the plugin we need to trigger it and use the results.

A sample of using it can be found in the standard search component (com_search/models/search.php).

Using it will be something like:


JPluginHelper::importPlugin( 'search');
$dispatcher =& JDispatcher::getInstance();
$results = $dispatcher->trigger( 'onSearch', array(
$rows = array();
foreach($results AS $result) {
$rows = array_merge( (array) $rows, (array) $result);
}

Wednesday, October 14, 2009

Custom Search Component #2

Following on from before, i've completed part one of this component. I'll not go into too much detail, but if you want a copy, email me.

What i will do is outline what it does (functionally) and then outline how it's been put together in terms of files and configuration.

Functionality
There are 2 screens; the first presents a search input box in which the user enters some text; the second screen presents the results, if there are any.

The search uses the above text to search JOS_USERS using the above string comparing against the NAME column.

Implementation

Using the MVC pattern, Joomla separates the functionality into several pieces.

Entry Point
The entry point file simply creates an instance of the controller and tells it to run the method pointed to by the requests var parameter (or defaults to display).

Controller
Has methods to pull together the model, views etc. In this case we have two methods:

  • display - default method

  • exec_search - called from the search parameter form; gets the view, assigns model to the view and calls the views display method



Views
The views pull together data and present the template. There are two; one default one does nothing and shows the default template (search input screen); a second which executes the search using the inputted screen data and puts the results into the JView class.

Models
There are 2 models; the default one which simply invokes the default template; a second which uses the search term, executes a search and returns the rows.

Monday, October 12, 2009

Custom Search Component

Ok, next step.

I need to search my user-base for Authors (based on title, first, middle and surname) and then present a list of them. Then, when selected i need to show their list of content.

Seemingly, there's nothing to do that, so i'll have to do it myself. i'll document as i go. I'm starting with this tutorial.

Update #1
Right, its quite straightforward create your own component; at least so far it has been. The first step, for me, was to get a simple component installed and running; i can then get it to do fancy stuff after that.

The link above was right on the money (as it should be i suppose!), the only difference being that the guide above put everything in a site folder for some reason. I didn't; i looked at the other standard components to see how they did it and there was no sub directory.

So, the order to creating my new search was


  • create a new development directory say, and within that create a directory called com_xyz where xyz is the name of your component.

  • Under that the entry point Php file xyz.php

  • Add a controller.php as well; this contains the controller sub-class, e.g. XYZController

  • Create a view class to pull together the data you'll need in the scrren(s). This file is views/xyz/view.html.php

  • Create a default template called views/xyz/tmpl/default.php for presenting the information

  • Add an XML descriptor holding metadata about the component.



So, thats the first pass; i'll add more once it becomes more functional

Thursday, October 08, 2009

Usertype, GID and Article Creation

One wrinkle with Joomla's security system is this; to create an Article, the user me be at least an Author (default is Registered).

Now, this info is held both in JOS_USERS.USERTYPE and JOS_USERS.GID where the GID column references JOS_CORE_ACL_ARO_GROUPS.

Now, in the customisation work id did to the components/com_user/controller.php i was setting the user's usertype based on the value of the drop down, but the assignment of gid was based on another variable so usertype was out of step with gid so an Author couldn't create an Article. So; ensure GID is set as well

Wednesday, October 07, 2009

Allow User to Create Article

At the moment, the users (well, Author or above) still cant create content as the article creation link is only available in the Admin Control Panel.

However, thats eaily fixed.

In the Control Panel, select "Menus>Main Menu". That will bring up the "Menu Item Manager".

Select the "New" icon, select "Articles" under the "Internal Link" option. The select "Article Submission Layout" and fill out the next page as required.

Easy.

Then, once you log in as an "Author" or above, lo, the option will appear.

User Login Custom Processing

Having aded some fields previously, i now need to perform some custom actions.

What i need to do is manage the usertype column population.

To do that, we modify the com_user controller. (components/com_user/controller.php).

We modify the 'register_save' function.


(line 237)
$post = JRequest::get('post');
$user->set( 'name' , $post['title']." ".$post['firstname']." ".$post['middlenames']." ".$post['surname'] );
$usertype2 = $post['usertype2'];

...

(line 269)
if ($usertype2 == 'photographer')
{
$user->set('usertype', 'Author');
}
elseif ($usertype2 == 'consumer')
{
$user->set('usertype', 'Registered');
}
else
{
$user->set('usertype', $newUsertype);
}


Also, i want to stop checking of the 'name' field as i am using other fields to populate this. To do that amend libraries/joomla/database/table/user.php
, commenting out this section (line 152):

if (trim( $this->name ) == '') {
$this->setError( JText::_( 'Please enter your name.' ) );
return false;
}



Next
Next step is to amend the form so that depending upon which user type i pick, hide some of the fields.

Update
Ok, can now hide a field on the registration form based on the value of a a drop down.

Added this javascript:

function hideFields()
{
var x=document.getElementById("usertype2");
if (x.value == 'consumer')
{
document.getElementById("biographyrow").style.display='none';
}
else
{
document.getElementById("biographyrow").style.display='block';
}
}


So, when the user amends a drop-down called 'usertype2' (onchange event), the above is called.

You need to make sure that the row which holds the field has the id 'biographyrow' (in this case).

Monday, October 05, 2009

User Registration Form Extension

Next stage.

For the site I need to extend the standard User Registration.

Details of how to do this can be found here (steps 1 & 2), here (video) and here.

Simply, do the following:

1. Add new fields to the JOS_USERS table. The new fields are added like this:


alter table jos_users add (firstname varchar(100))
alter table jos_users add (middlenames varchar(100))
alter table jos_users add (surname varchar(100))
alter table jos_users add (title varchar(20))
alter table jos_users add (biography text)
alter table jos_users add (contactnumber varchar(50))
alter table jos_users add (mobilenumber varchar(50))
alter table jos_users add (camerainfo varchar(100))
alter table jos_users add (termsandconditions tinyint(4) NOT NULL default '0')


2. Edit libraries/joomla/database/table/user.php (around line 118):


var $firstname = null;
var $middlenames = null;
var $surname = null;
var $title = null;
var $biography = null;
var $contactnumber = null;
var $mobilenumber = null;
var $camerainfo = null;
var $termsandconditions = null;


3. Edit libraries/joomla/user/user.php (around line 138):


var $firstname = null;
var $middlenames = null;
var $surname = null;
var $title = null;
var $biography = null;
var $contactnumber = null;
var $mobilenumber = null;
var $camerainfo = null;
var $termsandconditions = null;


4. Edit com_user/views/user/tmpl/form.php (around line 29).
Add the new fields (and in this case i commented out the 'name' field).

5. Edit com_user/views/register/tmpl/default.php (around line 24).

Login Module
To use this, we need to add a login module. So, in admin, go to Module Manager and add a Login module.

Friday, October 02, 2009

Component Installation Issue

So, setting up Joomla on the web host. All's going well until i tried to install the Export Content module.

I got an error


JFolder::create: Path not in open_basedir paths
Could not create folder ...


So, after muchh digging, i found this post and it worked.

Thanks goodness!

Thursday, October 01, 2009

Random Content #2

Ok,

given the links from the previous post, i've gone with Global News.

Configuration
Easy, this one. Somply download the module, then in Joomla administration, use "Extensions>Install/Unininstall".

Then, go to the "Module Manager" and "Global News" is listed. Click on the link and there are all manner of options!.

I set:

  • "Show Title" to "No"

  • "Count Articles" to "1"

  • "Show Section ID(s)" to "1" (the ID of my "Photographs" section

  • "Article Ordering" to "Random"