×
Kunena 5.1.6.1 Released - Security Release (09 Nov 2018)

The Kunena team has announce the arrival of Kunena 5.1.6 [K 5.1.6] which is now available for download as a native Joomla extension for J! 3.9.x. This version addresses most of the issues that were discovered in K 5.1 and issues discovered during the development stages of K 5.1. This is a Security release.

K5.1.6.1 is a install update.

× Please note: The Kunena project team takes NO responsibility for maintaining nor supporting anything in this category.

Solved Customize categories WHERE clause

More
5 years 13 hours ago - 5 years 12 hours ago #1 by jcsoft
Hello!

I'm using Kunena 3.0.3 with Joomla 2.5

I would like to customize the categories query to display only some categories depending on languages (i'll use specific aliases for this)

Where to find the WHERE clause to edit?
Which .php file to look for?

Thanx!
Last edit: 5 years 12 hours ago by jcsoft.

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago #2 by Matias
Unfortunately there isn't just one query which you can change, this would affect many different places. Kunena doesn't currently have full language support.

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago - 4 years 11 months ago #3 by jcsoft
Thank you very much for your answer, Matias!

Meanwhile i put some printf() and print_r() around to try to understand how it works, and finally achieved it by myself, well, kunena is a very clean code! :)

!!!This hack works for Kunena 3.0.3 and Joomla 2.5!
Other versions not tested!!!


All data i need is in the class KunenaViewCategory.
i just needed to modify this file:

/components/com_kunena/views/category/view.html.php

The function i hacked is displayList() to remove some categories from the list.

I manage the category aliases by placing the lang-code before the name to be able to distinguish them, as i didn't find any lang field for categories.
So, for example, website alias became both en-website, fr-website, it-website etc.
This way i just need to hide the categories that doesn't begin with the current lang-code.

Here's the code:
function displayList($tpl = null) {
		$this->Itemid = $this->get ( 'Itemid' );
		$this->category = $this->get ( 'Category' );
		if ($this->category->id && ! $this->category->authorise('read')) {
			$this->setError($this->category->getError());
		}
		$this->message_ordering = $this->me->getMessageOrdering();
		$this->categories = $this->get ( 'Categories' );
		$this->pending = $this->get ( 'UnapprovedCount' );
		$this->moderators = $this->get ( 'Moderators' );
		$this->sections = isset($this->categories[0]) ? $this->categories[0] : array();
 
		if ($this->category->isSection()) {
// TODO: turn this on:
/*			if ($this->me->isAdmin($this->category)) {
				$url = "index.php?option=com_kunena&view=category&layout=manage&catid={$this->category->id}";
				$this->category_manage = $this->getButton($url, 'manage', 'category', 'moderation');
			}*/
		}
		if ($this->me->exists()) {
			$this->markAllReadURL = KunenaRoute::_();
		}
 
		$errors = $this->getErrors();
		if ($errors) {
			$this->displayNoAccess($errors);
			return;
		}
/*******************************************************************************************/
// here i add some code to hack category list, i need to display current language categories only!
// i manage categories by placing the lang-code [en, fr, ...] before the category name itself (like en-website-category, fr-website-category, ...)
 
	//retrieve lang code
	$jcsoft_language = &JFactory::getLanguage();
	$jcsoft_lang_code_array = explode('-',$jcsoft_language->getTag());
	$jcsoft_lang_code = $jcsoft_lang_code_array[0];
 
	//check if there are categories in other languages and unset them
	foreach ($this->categories as $jc_idx => $jc_main_cat) {
		foreach($jc_main_cat as $jc_inner_idx => $jc_cat) {
			$jc_cat_explo = explode("-", $jc_cat->alias);
			$jc_cat_lang = $jc_cat_explo[0];
			if($jcsoft_lang_code==$jc_cat_lang) {
				// this is what i need! -do nothing-
			} else {
				// don't want these categories, remove from array
				unset($this->categories[$jc_idx][$jc_inner_idx]);
			}
		}
	}
 
	// finally check if there are some empty main categories (the parents of the removed ones) and unset them
	foreach($this->categories as $jc_idx => $jc_main_cat) {
		if(empty($jc_main_cat)) {
			unset($this->categories[$jc_idx]);
			unset($this->sections[$jc_idx]);
		}
	}
 
// that's it, now it can be displayed
/*******************************************************************************************/
 
		$this->_prepareDocument('list');
 
		$this->display ($tpl);
	}

-EDIT-
A similar hack could be extended to the other objects and functions (category/views.html.php#displayDefault(), topic/..., search/...) to make language categories indipendent, but this way if, for exampe, a -fr- user searches for an item, he will not see the results from non-fr- categories.

Hope it helps.

... i love php!
Last edit: 4 years 11 months ago by jcsoft.
The following user(s) said Thank You: Matias, Jiminimonka

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago #4 by Matias
Didn't think of that. :)

Thanks for saying that Kunena is easy to modify -- Kunena 3.1 will be even easier and you can do much more inside the template.

Please Log in or Create an account to join the conversation.

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to add attachements.
  • Not Allowed: to edit your message.
Time to create page: 0.130 seconds