Project

General

Profile

« Previous | Next » 

Revision 1696

Added by Dietmar about 12 years ago

move extra handling of menu links in index.php to the view.php of module menu links {Tks to NorHei)

View differences:

branches/2.8.x/wb/upgrade-script.php
473 473
	}
474 474
	/**********************************************************
475 475
 *  - Add field "redirect_type" to table "mod_menu_link"
476
 *  has to be moved later to upgrade.php in modul menu_link, because modul can be removed
476 477
 */
477 478
	$table_name = TABLE_PREFIX.'mod_menu_link';
478 479
	$field_name = 'redirect_type';
479
	$description = "INT NOT NULL DEFAULT '302' AFTER `target_page_id`";
480
	$description = "INT NOT NULL DEFAULT '301' AFTER `target_page_id`";
480 481
	if(!$database->field_exists($table_name,$field_name)) {
481 482
		echo "<br />Adding field redirect_type to mod_menu_link table";
482 483
		echo ($database->field_add($table_name, $field_name, $description) ? " $OK<br />" : " $FAIL!<br />");
483 484

  
branches/2.8.x/wb/index.php
4 4
 * @category        frontend
5 5
 * @package         page
6 6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-, Website Baker Org. e.V.
7
 * @copyright       2009-, WebsiteBaker Org. e.V.
8 8
 * @link			http://www.websitebaker2.org/
9 9
 * @license         http://www.gnu.org/licenses/gpl.html
10 10
 * @platform        WebsiteBaker 2.8.x
......
60 60
require(WB_PATH.'/framework/frontend.functions.php');
61 61

  
62 62
// redirect menu-link
63
$this_page_id = PAGE_ID;
63
/**
64
 *
65
 * Removed the extra handling of menu links in index.php
66
 * Moved it to the view.php of module menu links.
67
 * Now the extra functionality of this module is seperated from the
68
 * core and you can uninstall it if you like.
69
 * Freeing the core from unnecessary code.
70
 *
71
 *
72
 */
64 73

  
65
$php43 = version_compare(phpversion(), '4.3', '>=');
66

  
67
$sql  = 'SELECT `module`, `block` FROM `'.TABLE_PREFIX.'sections` ';
68
$sql .= 'WHERE `page_id` = '.(int)$this_page_id.' AND `module` = "menu_link"';
69
$query_this_module = $database->query($sql);
70
if($query_this_module->numRows() == 1)  // This is a menu_link. Get link of target-page and redirect
71
{
72
	// get target_page_id
73
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_menu_link` WHERE `page_id` = '.(int)$this_page_id;
74
	$query_tpid = $database->query($sql);
75
	if($query_tpid->numRows() == 1)
76
	{
77
		$res = $query_tpid->fetchRow();
78
		$target_page_id = $res['target_page_id'];
79
		$redirect_type = $res['redirect_type'];
80
		$anchor = ($res['anchor'] != '0' ? '#'.(string)$res['anchor'] : '');
81
		$extern = $res['extern'];
82
		// set redirect-type
83
		if($redirect_type == 301)
84
		{
85
			if($php43)
86
			{
87
				@header('HTTP/1.1 301 Moved Permanently', TRUE, 301);
88
			}
89
			else
90
			{
91
				@header('HTTP/1.1 301 Moved Permanently');
92
			}
93
		}
94
		if($target_page_id == -1)
95
		{
96
			if($extern != '')
97
			{
98
				$target_url = $extern.$anchor;
99
				header('Location: '.$target_url);
100
				exit;
101
			}
102
		}
103
		else
104
		{
105
			// get link of target-page
106
			$sql  = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$target_page_id;
107
			$target_page_link = $database->get_one($sql);
108
			if($target_page_link != null)
109
			{
110
				$target_url = WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION.$anchor;
111
				header('Location: '.$target_url);
112
				exit;
113
			}
114
		}
115
	}
116
}
117
//Get pagecontent in buffer for Droplets and/or Filter operations
118 74
ob_start();
119 75
require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
120 76
$output = ob_get_contents();
branches/2.8.x/wb/modules/menu_link/view.php
3 3
 *
4 4
 * @category        modules
5 5
 * @package         Menu Link
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
6
 * @author          Ryan Djurovich, WebsiteBaker Project, Norbert Heimsath
7
 * @copyright       2009-2012, Website Baker Org. e.V.
9 8
 * @link			http://www.websitebaker2.org/
10 9
 * @license         http://www.gnu.org/licenses/gpl.html
11 10
 * @platform        WebsiteBaker 2.8.x
12 11
 * @requirements    PHP 5.2.2 and higher
13 12
 * @version         $Id$
14
 * @filesource		$HeadURL: http://svn.websitebaker2.org/branches/2.8.x/wb/modules/wysiwyg/modify.php $
15
 * @lastmodified    $Date: 2011-01-11 20:29:52 +0100 (Di, 11 Jan 2011) $
13
 * @filesource		$HeadURL$
14
 * @lastmodified    $Date$
16 15
 *
17 16
 */
18 17

  
19 18
// Must include code to stop this file being access directly
20
if(defined('WB_PATH') == false) { die("Cannot access this file directly"); }
19
/* -------------------------------------------------------- */
20
if(defined('WB_PATH') == false)
21
{
22
	// Stop this file being access directly
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
24
}
25
/* -------------------------------------------------------- */
21 26

  
22 27
// check if module language file exists for the language set by the user (e.g. DE, EN)
23 28
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
......
28 33
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
29 34
}
30 35

  
36

  
37
// redirect menu-link
38
$this_page_id = PAGE_ID;
39

  
40
$php43 = version_compare(phpversion(), '4.3', '>=');
41

  
42
$sql  = 'SELECT `module`, `block` FROM `'.TABLE_PREFIX.'sections` ';
43
$sql .= 'WHERE `page_id` = '.(int)$this_page_id.' AND `module` = "menu_link"';
44
$query_this_module = $database->query($sql);
45
if($query_this_module->numRows() == 1)  // This is a menu_link. Get link of target-page and redirect
46
{
47
	// get target_page_id
48
	$sql  = 'SELECT * FROM `'.TABLE_PREFIX.'mod_menu_link` WHERE `page_id` = '.(int)$this_page_id;
49
	$query_tpid = $database->query($sql);
50
	if($query_tpid->numRows() == 1)
51
	{
52
		$res = $query_tpid->fetchRow();
53
		$target_page_id = $res['target_page_id'];
54
		$redirect_type = $res['redirect_type'];
55
		$anchor = ($res['anchor'] != '0' ? '#'.(string)$res['anchor'] : '');
56
		$extern = $res['extern'];
57
		// set redirect-type
58
		if($redirect_type == 301)
59
		{
60
			if($php43)
61
			{
62
				@header('HTTP/1.1 301 Moved Permanently', TRUE, 301);
63
			}
64
			else
65
			{
66
				@header('HTTP/1.1 301 Moved Permanently');
67
			}
68
		}
69
		if($target_page_id == -1)
70
		{
71
			if($extern != '')
72
			{
73
				$target_url = $extern.$anchor;
74
				header('Location: '.$target_url);
75
				exit;
76
			}
77
		}
78
		else
79
		{
80
			// get link of target-page
81
			$sql  = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id` = '.$target_page_id;
82
			$target_page_link = $database->get_one($sql);
83
			if($target_page_link != null)
84
			{
85
				$target_url = WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION.$anchor;
86
				header('Location: '.$target_url);
87
				exit;
88
			}
89
		}
90
	}
91
} else {
92

  
31 93
?>
94

  
32 95
<a href="<?php echo WB_URL; ?>">
33 96
<?php echo $MOD_MENU_LINK['TEXT']; ?>
34 97
</a>
98
<?php }
35 99

  
branches/2.8.x/wb/modules/menu_link/install.php
3 3
 *
4 4
 * @category        modules
5 5
 * @package         menu_link
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2012, Website Baker Org. e.V.
9 8
 * @link			http://www.websitebaker2.org/
10 9
 * @license         http://www.gnu.org/licenses/gpl.html
11 10
 * @platform        WebsiteBaker 2.8.x
......
21 20
if(defined('WB_PATH') == false)
22 21
{
23 22
	// Stop this file being access directly
24
		die('<head><title>Access denied</title></head><body><h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2></body></html>');
23
		die('<h2 style="color:red;margin:3em auto;text-align:center;">Cannot access this file directly</h2>');
25 24
}
26 25
/* -------------------------------------------------------- */
27 26

  
......
33 32
		`section_id` INT(11) NOT NULL DEFAULT '0',
34 33
		`page_id` INT(11) NOT NULL DEFAULT '0',
35 34
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
36
		`redirect_type` INT NOT NULL DEFAULT '302',
35
		`redirect_type` INT NOT NULL DEFAULT '301',
37 36
		`anchor` VARCHAR(255) NOT NULL DEFAULT '0' ,
38 37
		`extern` VARCHAR(255) NOT NULL DEFAULT '' ,
39 38
		PRIMARY KEY (`section_id`)
40 39

  

Also available in: Unified diff