Blog News

CMS Blog
Browse in : All > Topics > CMS Blog

Avoiding Duplicate Article Creation

Posted by: St.Ego on June 01, 2008 2:29:52 PM (1092 Reads)
After finding a few duplicate entries in the Semantics section of the site, I decided to implement a feature to help me catch when an article already exists with the same title. What I wanted was a display of potentially matching articles, of the same pubtype, shown on the preview page. Fortunately, the articles module comes equipped with a search hook that we can (ab)use the function for.

The easiest way, in my mind, to add just about anything to a page in Xaraya is through the use of a block or blockgroup. First I created a blockgroup for the search to be included with theĀ  preview. Then I added a "content" block, which allows an inner template (whereas the HTML block does not). I had to call the articles search function directly via the block template (which is why I used the "content" block) using this code. Since the block is meant to display on the preview page, we can collect what we need to send to the search function from the POST variables, as you can see in the linked snippet.

I had to manually break down the search string into words, stripping out words of less than 5 characters in the process. The routine does not exclude punctuation and could probably be written better, but it suites our purposes here.

From there, unfortunately, I ran into issues with the search form displaying instead of just the results. It seems the articles module does not offer use of alternate templates, which is included by default when using the xarTplModule function; it just isn't made use of in articles_user_search.

So, I had to do a quick custom hack to articles/xaruser/search.php, at line 562, so that any template value sent with $extrainfo will be used in xarTplModule:

if(!isset($template)) $template = NULL;
return xarTplModule('articles','user','search',$data, $template);

This ensures that our block template will pass the "block" template value and have it use the appropriate template to return results from articles_user_search in. As you can see from the linked snippet, I have removed all of the actual search form from the template. I want to see matching results, not conduct an additional search.

And that, boys and girls, is an easy way to help keep yourself from submitting duplicate content to your own site... should you have that problem.

There are no comments attached to this item. You must be registered and logged in to post comments!

Options:
View Article Map
View Archives