Project

General

Profile

« Previous | Next » 

Revision 543

Added by thorn almost 17 years ago

module menu_link: fixed page-deleteing-bug and some odd behavior, added table mod_menu_link

View differences:

trunk/CHANGELOG
11 11
! = Update/Change
12 12

  
13 13
------------------------------------- 2.7.0 -------------------------------------
14
16-Jan-2008 Thomas Hornik
15
! changed module menu_link: added table mod_menu_link, fixed page-deleting-bug,
16
	fixed odd behavior in case of menu_link as default-page.
17
16-Jan-2008 Thomas Hornik
18
# changing PHP-error-level within website baker does not work - fixed (fixed ticket 532)
14 19
14-Jan-2008 Matthias Gallas
15 20
#	Replaced hardcoded .php with the variable PAGE_EXTENSION for the use in pagenames.
16 21
	(!!Attention!! To get extenions other than .php working additional fixes are necessary!)
trunk/wb/admin/pages/settings2.php
143 143
// Get page trail
144 144
$page_trail = get_page_trail($page_id);
145 145

  
146
// Make sure link is not overwritten if page uses the menu link module
147
$query_sections = $database->query("SELECT section_id FROM ".TABLE_PREFIX."sections WHERE page_id = '$page_id' AND module = 'menu_link'");
148
if($query_sections->numRows() > 0) {
149
	$link = $old_link;
150
} 
151

  
152 146
// Update page settings in the pages table
153 147
$query = "UPDATE ".TABLE_PREFIX."pages SET parent = '$parent', page_title = '$page_title', menu_title = '$menu_title', menu = '$menu', level = '$level', page_trail = '$page_trail', root_parent = '$root_parent', link = '$link', template = '$template', target = '$target', description = '$description', keywords = '$keywords', position = '$position', visibility = '$visibility', searching = '$searching', language = '$language', admin_groups = '$admin_groups', viewing_groups = '$viewing_groups' WHERE page_id = '$page_id'";
154 148
$database->query($query);
......
237 231
// Print admin footer
238 232
$admin->print_footer();
239 233

  
240
?>
234
?>
trunk/wb/modules/menu_link/modify.html
1
<!-- BEGIN main_block -->
2

  
3
<form action="{WB_URL}/modules/menu_link/save.php" method="post">
4

  
5
<input type="hidden" name="page_id" value="{PAGE_ID}" />
6
<input type="hidden" name="section_id" value="{SECTION_ID}" />
7

  
8
<table cellpadding="0" cellspacing="0" border="0" width="100%">
9
<tr>
10
	<td>
11
		{TEXT_LINK}:
12
	</td>
13
	<td>
14
		<input type="text" id="link" name="link" style="width: 100%;" value="{LINK}" />
15
	</td>
16
</tr>
17
<tr>
18
	<td>
19
		{TEXT_TARGET}:
20
	</td>
21
	<td>
22
		<select name="target" style="WIDTH: 100%;" value="{TARGET}" />
23
			<option value="_blank"{BLANK_SELECTED}>{TEXT_NEW_WINDOW}</option>
24
			<option value="_self"{SELF_SELECTED}>{TEXT_SAME_WINDOW}</option>
25
			<option value="_top"{TOP_SELECTED}>{TEXT_TOP_FRAME}</option>
26
		</select>
27
	</td>
28
</tr>
29
</table>
30

  
31
<br />
32

  
33
<table cellpadding="0" cellspacing="0" border="0" width="100%">
34
<tr>
35
	<td align="left">
36
		<input type="submit" value="{TEXT_SAVE}" style="width: 100px; margin-top: 5px;" />
37
	</td>
38
	<td align="right">
39
		</form>
40
		<input type="button" value="{TEXT_CANCEL}" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
41
	</td>
42
</tr>
43
</table>
44

  
45
</form>
46

  
47
<!-- END main_block -->
48 0

  
trunk/wb/modules/menu_link/uninstall.php
1
<?php
2

  
3
// $Id$
4

  
5
/*
6

  
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2008, Ryan Djurovich
9

  
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

  
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

  
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

  
24
*/
25

  
26
// prevent this file from being accesses directly
27
if(defined('WB_PATH') == false) {
28
	exit("Cannot access this file directly"); 
29
}
30

  
31
$table = TABLE_PREFIX ."mod_menu_link";
32
$database->query("DROP TABLE `$table`");
33

  
34
?>
trunk/wb/modules/menu_link/view.php
31 31
?>
32 32
<a href="<?php echo WB_URL; ?>">
33 33
Click HERE to go to the main page
34
</a>
34
</a>
trunk/wb/modules/menu_link/info.php
23 23

  
24 24
*/
25 25

  
26
/* History:
27

  
28
2.6.1.0 - 16. Jan. 2008 - thorn
29
- added table mod_menu_link
30
- added install.php, delete.php, add.php
31
- changed wb/index.php: redirect if page is menu_link
32
- removed special-handling of menu_link in: admin/pages/settings2.php
33

  
34
*/
35

  
26 36
$module_directory = 'menu_link';
27 37
$module_name = 'Menu Link';
28 38
$module_function = 'page';
29
$module_version = '2.6';
39
$module_version = '2.6.1.0';
30 40
$module_platform = '2.6.x';
31
$module_author = 'Ryan Djurovich';
41
$module_author = 'Ryan Djurovich, thorn';
32 42
$module_license = 'GNU General Public License';
33 43
$module_description = 'This module allows you to insert a link into the menu.';
34 44

  
35
?>
45
?>
trunk/wb/modules/menu_link/save.php
29 29
$update_when_modified = true; // Tells script to update when this page was last updated
30 30
require(WB_PATH.'/modules/admin.php');
31 31

  
32
$database = new database();
33

  
34 32
// Update the mod_menu_links table with the link
35
if(isset($_POST['link'])) {
36
	// Update link and target
37
	$link = $admin->add_slashes($_POST['link']);
38
	$target = $_POST['target'];
39
	$query = "UPDATE ".TABLE_PREFIX."pages SET link = '$link', target = '$target' WHERE page_id = '$page_id'";
40
	$database->query($query);
33
if(isset($_POST['link']) && isset($_POST['target'])) {
34
	// Update id and target
35
	$foreign_page_id = $_POST['link']; // foreign-page_id
36
	$url_target = $_POST['target'];
37
	$table_pages = TABLE_PREFIX.'pages';
38
	$table_mod = TABLE_PREFIX.'mod_menu_link';
39
	$database->query("UPDATE $table_pages SET target = '$url_target' WHERE page_id = '$page_id'");
40
	$database->query("UPDATE $table_mod SET target_page_id = '$foreign_page_id' WHERE page_id = '$page_id'");
41 41
} else {
42
	$admin->print_error('Error in wb/modules/menu_link/save.php at line 35', $js_back);
42
	$admin->print_error('Error in wb/modules/menu_link/save.php at line 35', true);
43 43
}
44 44

  
45 45
// Check if there is a database error, otherwise say successful
......
52 52
// Print admin footer
53 53
$admin->print_footer();
54 54

  
55
?>
55
?>
trunk/wb/modules/menu_link/delete.php
23 23

  
24 24
*/
25 25

  
26
// Nothing special has to be deleted
26
// prevent this file from being accesses directly
27
if(defined('WB_PATH') == false) {
28
	exit("Cannot access this file directly"); 
29
}
27 30

  
31
$table = TABLE_PREFIX ."mod_menu_link";
32
$database->query("DELETE FROM `$table` WHERE section_id = '$section_id'");
33

  
28 34
?>
trunk/wb/modules/menu_link/install.php
23 23

  
24 24
*/
25 25

  
26
// No table is needed for this module
26
// prevent this file from being accesses directly
27
if(defined('WB_PATH') == false) {
28
	exit("Cannot access this file directly"); 
29
}
27 30

  
31
$table = TABLE_PREFIX ."mod_menu_link";
32
$database->query("DROP TABLE IF EXISTS `$table`");
33

  
34
$database->query("
35
	CREATE TABLE `$table` (
36
		`section_id` INT(11) NOT NULL DEFAULT '0',
37
		`page_id` INT(11) NOT NULL DEFAULT '0',
38
		`target_page_id` INT(11) NOT NULL DEFAULT '0',
39
		PRIMARY KEY (`section_id`)
40
	)
41
");
42

  
28 43
?>
trunk/wb/modules/menu_link/modify.php
23 23

  
24 24
*/
25 25

  
26
// Setup template object
27
$template = new Template(WB_PATH.'/modules/menu_link');
28
$template->set_file('page', 'modify.html');
29
$template->set_block('page', 'main_block', 'main');
26
// Must include code to stop this file being access directly
27
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
30 28

  
31
// Get page link and target
32
$query_info = "SELECT link,target FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'";
33
$get_info = $database->query($query_info);
34
$fetch_info = $get_info->fetchRow();
35
$link = ($fetch_info['link']);
36
$target = $fetch_info['target'];
29
// get target page_id
30
$table = TABLE_PREFIX.'mod_menu_link';
31
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
32
$sql_row = $sql_result->fetchRow();
33
$target_page_id = $sql_row['target_page_id'];
37 34

  
38
// Insert vars
39
$template->set_var(array(
40
								'PAGE_ID' => $page_id,
41
								'WB_URL' => WB_URL,
42
								'LINK' => $link,
43
								'TEXT_LINK' => $TEXT['LINK'],
44
								'TEXT_TARGET' => $TEXT['TARGET'],
45
								'TEXT_NEW_WINDOW' => $TEXT['NEW_WINDOW'],
46
								'TEXT_SAME_WINDOW' => $TEXT['SAME_WINDOW'],
47
								'TEXT_TOP_FRAME' => $TEXT['TOP_FRAME'],
48
								'TEXT_SAVE' => $TEXT['SAVE'],
49
								'TEXT_CANCEL' => $TEXT['CANCEL'],
50
								'TEXT_PLEASE_SELECT' => $TEXT['PLEASE_SELECT']
51
								)
52
						);
53

  
54
// Select what the page target is
55
switch ($target) {
56
	case '_top':
57
		$template->set_var('TOP_SELECTED', ' selected');
58
		break;
59
	case '_self':
60
		$template->set_var('SELF_SELECTED', ' selected');
61
		break;
62
	case '_blank':
63
		$template->set_var('BLANK_SELECTED', ' selected');
64
		break;
35
// Get list of all visible page-links, except menu_links and actual page
36
$table_p = TABLE_PREFIX."pages";
37
$table_s = TABLE_PREFIX."sections";
38
$query_page = $database->query("SELECT DISTINCT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module != 'menu_link' AND p.page_id != '$page_id' AND parent = '0' ORDER BY position");
39
if($query_page->numRows() > 0) {
40
	while($page = $query_page->fetchRow()) {
41
		if($admin->page_is_visible($page)) {
42
			$links[$page['page_id']]='/'.$page['menu_title'];
43
			$query_subpage = $database->query("SELECT DISTINCT p.* FROM $table_p AS p, $table_s AS s WHERE p.page_id=s.page_id AND s.module != 'menu_link' AND p.page_id != '$page_id' AND root_parent = '{$page['page_id']}' ORDER BY level");
44
			if($query_subpage->numRows() > 0) {
45
				while($sub = $query_subpage->fetchRow()) {
46
					if($admin->page_is_visible($sub)) {
47
						$links[$sub['page_id']]=$links[$sub['parent']].'/'.$sub['menu_title'];
48
					}
49
				}
50
			}
51
		}
52
	}
65 53
}
66 54

  
67
// Parse template object
68
$template->parse('main', 'main_block', false);
69
$template->pparse('output', 'page');
55
// get URL-target for actual page
56
$table = TABLE_PREFIX."pages";
57
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
58
$page = $query_page->fetchRow();
59
$target = $page['target'];
70 60

  
71
?>
61
?>
62
<form action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
63
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
64
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
65
<table cellpadding="0" cellspacing="0" border="0" width="100%">
66
<tr>
67
	<td>
68
		<?php echo $TEXT['LINK'].':' ?>
69
	</td>
70
	<td>
71
		<select name="link" style="WIDTH: 100%;" value="<?php echo "" ?>" />
72
		<?php
73
		foreach($links as $id=>$l) { ?>
74
			<option value="<?php echo $id ?>"<?php if($id==$target_page_id) echo ' selected'; ?>><?php echo $l ?></option>
75
		<?php } ?>
76
	</td>
77
</tr>
78
<tr>
79
	<td>
80
		<?php echo $TEXT['TARGET'].':' ?>
81
	</td>
82
	<td>
83
		<select name="target" style="WIDTH: 100%;" value="<?php echo "" ?>" />
84
			<option value="_blank"<?php if($target=='_blank') echo ' selected'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
85
			<option value="_self"<?php if($target=='_self') echo ' selected'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
86
			<option value="_top"<?php if($target=='_top') echo ' selected'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
87
		</select>
88
	</td>
89
</tr>
90
</table>
91

  
92
<br />
93

  
94
<table cellpadding="0" cellspacing="0" border="0" width="100%">
95
<tr>
96
	<td align="left">
97
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
98
	</td>
99
	<td align="right">
100
		</form>
101
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
102
	</td>
103
</tr>
104
</table>
105

  
106
</form>
107

  
trunk/wb/modules/menu_link/add.php
23 23

  
24 24
*/
25 25

  
26
// Nothing needs to be inserted anywhere special
26
// prevent this file from being accesses directly
27
if(defined('WB_PATH') == false) {
28
	exit("Cannot access this file directly"); 
29
}
27 30

  
31
$table = TABLE_PREFIX ."mod_menu_link";
32
$database->query("INSERT INTO `$table` (`page_id`, `section_id`, target_page_id) VALUES ('$page_id', '$section_id', '0')");
33

  
28 34
?>
trunk/wb/framework/class.wb.php
45 45
	// performed when frontend or backend is loaded.
46 46
	function wb() {
47 47
	}
48
	
49
	// Check whether a page is visible or not.
50
	// This will check page-visibility and user- and group-rights.
51
	/* page_is_visible() returns
52
		false: if page-visibility is 'none' or 'deleted', or page-vis. is 'registered' or 'private' and user isn't allowed to see the page.
53
		true: if page-visibility is 'public' or 'hidden', or page-vis. is 'registered' or 'private' and user _is_ allowed to see the page.
54
	*/
55
	function page_is_visible($page) {
56
		$show_it = false; // shall we show the page?
57
		$page_id = $page['page_id'];
58
		$visibility = $page['visibility'];
59
		$viewing_groups = $page['viewing_groups'];
60
		$viewing_users = $page['viewing_users'];
61
		// First check if visibility is 'none', 'deleted'
62
		if($visibility == 'none') {
63
			return(false);
64
		} elseif($visibility == 'deleted') {
65
			return(false);
66
		}
67
		// Now check if visibility is 'hidden', 'private' or 'registered'
68
		if($visibility == 'hidden') { // hidden: hide the menu-link, but show the page
69
			$show_it = true;
70
		} elseif($visibility == 'private' || $visibility == 'registered') {
71
			// Check if the user is logged in
72
			if($this->is_authenticated() == true) {
73
				// Now check if the user has perms to view the page
74
				if(in_array($this->get_group_id(), explode(',', $viewing_groups)) || in_array($this->get_user_id(), explode(',', $viewing_users))) {
75
					$show_it = true;
76
				} else {
77
					$show_it = false;
78
				}
79
			} else {
80
				$show_it = false;
81
			}
82
		} elseif($visibility == 'public') {
83
			$show_it = true;
84
		} else {
85
			$show_it = false;
86
		}
87
		return($show_it);
88
	}
48 89

  
49 90
	// Check whether we should show a page or not (for front-end)
50 91
	function show_page($page) {
......
276 317
	}
277 318

  
278 319
}
279
?>
320
?>
trunk/wb/framework/functions.php
1195 1195
	$directory = WB_PATH.PAGES_DIRECTORY.$link;
1196 1196
	$filename = $directory.PAGE_EXTENSION;
1197 1197
	$directory .= '/';
1198
	if(file_exists($filename) && substr($filename,0,1<>'.')) {
1198
	if(file_exists($filename)) {
1199 1199
		if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/')) {
1200 1200
			$admin->print_error($MESSAGE['PAGES']['CANNOT_DELETE_ACCESS_FILE']);
1201 1201
		} else {
1202 1202
			unlink($filename);
1203
			if(file_exists($directory)) {
1203
			if(file_exists($directory) && rtrim($directory,'/')!=WB_PATH.PAGES_DIRECTORY) {
1204 1204
				rm_full_dir($directory);
1205 1205
			}
1206 1206
		}
......
1316 1316
	}
1317 1317
}
1318 1318

  
1319
?>
1319
?>
trunk/wb/index.php
53 53
// also, set some aliases for backward compatibility
54 54
require(WB_PATH.'/framework/frontend.functions.php');
55 55

  
56
// redirect menu-link
57
$this_page_id = PAGE_ID;
58
$query_this_module = $database->query("SELECT module, block FROM ".TABLE_PREFIX."sections WHERE page_id = '$this_page_id' AND module = 'menu_link'");
59
if($query_this_module->numRows() == 1) { // This is a menu_link. Get link of target-page and redirect
60
	// get target_page_id
61
	$table = TABLE_PREFIX.'mod_menu_link';
62
	$query_tpid = $database->query("SELECT target_page_id FROM $table WHERE page_id = '$this_page_id'");
63
	if($query_tpid->numRows() == 1) {
64
		$res=$query_tpid->fetchRow();
65
		$target_page_id = $res['target_page_id'];
66
		// get link of target-page
67
		$table = TABLE_PREFIX.'pages';
68
		$query_link = $database->query("SELECT link FROM $table WHERE page_id = '$target_page_id'");
69
		if($query_link->numRows() == 1) {
70
			$res=$query_link->fetchRow();
71
			$target_page_link = $res['link'];
72
			// redirect
73
			header('Location: '.WB_URL.PAGES_DIRECTORY.$target_page_link.PAGE_EXTENSION);
74
			exit;
75
		}
76
	}
77
}
78

  
56 79
// Display the template
57 80
require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
58 81

  

Also available in: Unified diff