Joomla! TIP: come riconoscere la homepage in una estensione

Joomla! & Extensions

In una qualsiasi estensione per Joomla 1.5.x (componente, plugin, modulo o template) potreste trovarvi nella necessità di essere certi di trovarvi nella homepage.

Qui riportiamo una funzione che da come risultato un booleano che indica se siamo nella home del sito o meno.

Snippet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
 *
 * (c)2011 SFS.it, All rights reserved
 * License: http://www.sfs.it/licenza-bsd44.html
 * Use and modify all you want just keep this comment. Thanks
 *
 **/
 
// This function return a boolean 
//   true: the page is the homesite default page
//   false: the page isnt the homesite default page
function is_homepage() {
	$menuitem = & JSite::getMenu();
	$is_homepage = ($menuitem->_active == $menuitem->_default);
	if ($is_homepage && !empty($_SERVER['QUERY_STRING'])) {
		$page_gets=split('&',$_SERVER['QUERY_STRING']);
		$homepage_link=$menuitem->_items[$menuitem->_default]->link;
		if (substr($homepage_link,0,9) == 'index.php' && substr($homepage_link,9,1) == '?') {
			$query_string='';
			asort($page_gets);
			foreach ($page_gets as $gets) {
				$get=split('=',$gets);
				if (in_array($get[0],array('option','view','id','layout','Itemid'))) {
					if ($get[0] == 'layout')
						$had_layout=true;
					$query_string.=$gets.'&';
				}
			}
			$homepage_link = substr($homepage_link,10);
			$homepage_gets=split('&',$homepage_link.'&Itemid='.$menuitem->_default);
			asort($homepage_gets);
			$homepage_link='';
			foreach ($homepage_gets as $gets) {
				$get=split('=',$gets);
				if (in_array($get[0],array('option','view','id','layout','Itemid')))
					if ($get[0] == 'layout' && !$had_layout)
						continue;
					$homepage_link.=$gets.'&';
			}
			if ($query_string != $homepage_link)
				$is_homepage = false;
		} else
			$is_homepage = false;
	}
	return $is_homepage;
}
$is_homepage = is_homepage();

 


 

Ultimo aggiornamento (Domenica 01 Maggio 2011 23:46)

 

Aggiungi commento


Codice di sicurezza
Aggiorna