Project

General

Profile

« Previous | Next » 

Revision 872

Added by thorn about 16 years ago

updated menulink and search to use configureable section-anchor

View differences:

modify.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
// Must include code to stop this file being accessed directly
27
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
1
<?php
28 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
// Must include code to stop this file being accessed directly
27
if(defined('WB_PATH') == false) { exit("Cannot access this file directly"); }
28

  
29 29
// check if module language file exists for the language set by the user (e.g. DE, EN)
30 30
if(!file_exists(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php')) {
31 31
	// no module language file exists for the language set by the user, include default module language file EN.php
......
34 34
	// a module language file exists for the language defined by the user, load it
35 35
	require_once(WB_PATH .'/modules/menu_link/languages/'.LANGUAGE .'.php');
36 36
}
37

  
38
// get target page_id

39
$table = TABLE_PREFIX.'mod_menu_link';

40
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");

41
$sql_row = $sql_result->fetchRow();

37

  
38
// get target page_id
39
$table = TABLE_PREFIX.'mod_menu_link';
40
$sql_result = $database->query("SELECT * FROM $table WHERE section_id = '$section_id'");
41
$sql_row = $sql_result->fetchRow();
42 42
$target_page_id = $sql_row['target_page_id'];
43
$extern = $sql_row['extern'];

44
$anchor = $sql_row['anchor'];

45
$sel = ' selected';

46

  
47
// Get list of all visible pages, except actual one

48
$links = array();

49
$table_p = TABLE_PREFIX."pages";

50
if($query_page = $database->query("SELECT * FROM $table_p WHERE parent = '0' ORDER BY position")) {

43
$extern = $sql_row['extern'];
44
$anchor = $sql_row['anchor'];
45
$sel = ' selected';
46

  
47
// Get list of all visible pages, except actual one
48
$links = array();
49
$table_p = TABLE_PREFIX."pages";
50
if($query_page = $database->query("SELECT * FROM $table_p WHERE parent = '0' ORDER BY position")) {
51 51
	while($page = $query_page->fetchRow()) {
52 52
		$all_links[$page['page_id']]='/'.$page['menu_title'];
53
		if($admin->page_is_visible($page) && $page['page_id']!=$page_id) {

53
		if($admin->page_is_visible($page) && $page['page_id']!=$page_id) {
54 54
			$links[$page['page_id']]='/'.$page['menu_title'];
55
		}

56
		if($query_subpage = $database->query("SELECT * FROM $table_p WHERE page_id != '$page_id' AND root_parent = '{$page['page_id']}' ORDER BY level")) {

57
			while($sub = $query_subpage->fetchRow()) {

58
				if($admin->page_is_visible($sub)) {

59
					$parent_link = (array_key_exists($sub['parent'],$all_links))?$all_links[$sub['parent']]:"";

60
					$links[$sub['page_id']]=$parent_link.'/'.$sub['menu_title'];

61
				}

62
			}

63
		}

64
	}

65
}

66
// Get list of targets (id=... or <a name ...>) from pages in $links

67
$targets = array();

68
$table_mw = TABLE_PREFIX."mod_wysiwyg";

69
$table_s = TABLE_PREFIX."sections";

70
foreach($links as $pid=>$l) {

71
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {

55
		}
56
		if($query_subpage = $database->query("SELECT * FROM $table_p WHERE page_id != '$page_id' AND root_parent = '{$page['page_id']}' ORDER BY level")) {
57
			while($sub = $query_subpage->fetchRow()) {
58
				if($admin->page_is_visible($sub)) {
59
					$parent_link = (array_key_exists($sub['parent'],$all_links))?$all_links[$sub['parent']]:"";
60
					$links[$sub['page_id']]=$parent_link.'/'.$sub['menu_title'];
61
				}
62
			}
63
		}
64
	}
65
}
66
// Get list of targets (id=... or <a name ...>) from pages in $links
67
$targets = array();
68
$table_mw = TABLE_PREFIX."mod_wysiwyg";
69
$table_s = TABLE_PREFIX."sections";
70
foreach($links as $pid=>$l) {
71
	if($query_section = $database->query("SELECT section_id, module FROM $table_s WHERE page_id = '$pid' ORDER BY position")) {
72 72
		while($section = $query_section->fetchRow()) {
73
			// get section-anchor
74
			$targets[$pid][] = "wb_section_{$section['section_id']}";
75
			if($section['module'] == 'wysiwyg') {
76
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
77
					$page = $query_page->fetchRow();
78
					if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iuU',$page['content'], $match)) {
79
						foreach($match[1] AS $t) {
80
							$targets[$pid][] = $t;
81
						}
82
					}
83
				}
84
			}
85
		}
86
	}
87
}
88
// get target-window for actual page
89
$table = TABLE_PREFIX."pages";
90
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
91
$page = $query_page->fetchRow();
92
$target = $page['target'];
93

  
94

  
95
// script for target-select-box
96
?>
97
<script type="text/javascript">
73
			// get section-anchor
74
			if(defined('SEC_ANCHOR') && SEC_ANCHOR!='') {
75
				$targets[$pid][] = SEC_ANCHOR.$section['section_id'];
76
			} else {
77
				$targets[$pid] = array();
78
			}
79
			if($section['module'] == 'wysiwyg') {
80
				if($query_page = $database->query("SELECT content FROM $table_mw WHERE section_id = '{$section['section_id']}' LIMIT 1")) {
81
					$page = $query_page->fetchRow();
82
					if(preg_match_all('/<(?:[^>]+id|\s*a[^>]+name)\s*=\s*"(.*)"/iuU',$page['content'], $match)) {
83
						foreach($match[1] AS $t) {
84
							$targets[$pid][] = $t;
85
						}
86
					}
87
				}
88
			}
89
		}
90
	}
91
}
92
// get target-window for actual page
93
$table = TABLE_PREFIX."pages";
94
$query_page = $database->query("SELECT target FROM $table WHERE page_id = '$page_id'");
95
$page = $query_page->fetchRow();
96
$target = $page['target'];
97

  
98

  
99
// script for target-select-box
100
?>
101
<script type="text/javascript">
98 102
	function populate() {
99
		o=document.getElementById('page_link');

103
		o=document.getElementById('page_link');
100 104
		d=document.getElementById('page_target');
101 105
		e=document.getElementById('extern');
102
		if(!d){return;}			
103
		var mitems=new Array();
104
		mitems['0']=[' ','0'];
105
		mitems['-1']=[' ','0'];
106
		<?php
107
		foreach($links AS $pid=>$link) {
108
			$str="mitems['$pid']=[";
109
			$str.="' ',";
110
			$str.="'0',";
111
			if(is_array($targets) && is_array($targets[$pid])) {
112
				foreach($targets[$pid] AS $value) {
113
					$str.="'#$value',";
114
					$str.="'$value',";
115
				}
116
				$str=rtrim($str, ',');
117
				$str.="];\n";
118
			}
119
			echo $str;
120
		}
121
		?>
122
		d.options.length=0;
123
		cur=mitems[o.options[o.selectedIndex].value];
124
		if(!cur){return;}
125
		d.options.length=cur.length/2;
126
		j=0;
127
		for(var i=0;i<cur.length;i=i+2)
128
		{
129
			d.options[j].text=cur[i];
130
			d.options[j++].value=cur[i+1];
106
		if(!d){return;}			
107
		var mitems=new Array();
108
		mitems['0']=[' ','0'];
109
		mitems['-1']=[' ','0'];
110
		<?php
111
		foreach($links AS $pid=>$link) {
112
			$str="mitems['$pid']=[";
113
			$str.="' ',";
114
			$str.="'0',";
115
			if(is_array($targets) && is_array($targets[$pid])) {
116
				foreach($targets[$pid] AS $value) {
117
					$str.="'#$value',";
118
					$str.="'$value',";
119
				}
120
				$str=rtrim($str, ',');
121
				$str.="];\n";
122
			}
123
			echo $str;
131 124
		}
125
		?>
126
		d.options.length=0;
127
		cur=mitems[o.options[o.selectedIndex].value];
128
		if(!cur){return;}
129
		d.options.length=cur.length/2;
130
		j=0;
131
		for(var i=0;i<cur.length;i=i+2)
132
		{
133
			d.options[j].text=cur[i];
134
			d.options[j++].value=cur[i+1];
135
		}
132 136
		
133 137
		if(o.value=='-1') {
134 138
			e.disabled = false;
......
136 140
			e.disabled = true;
137 141
		}
138 142
	}
139
</script>

140

  
141
<form name="menulink" action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">

142
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />

143
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />

144
<table cellpadding="0" cellspacing="0" border="0" width="100%">

145
<tr>

146
	<td>

147
		<?php echo $TEXT['LINK'].':' ?>

148
	</td>

149
	<td>

150
		<select name="page_link" id="page_link" onchange="populate()" style="width:250px;" />

143
</script>
144

  
145
<form name="menulink" action="<?php echo WB_URL ?>/modules/menu_link/save.php" method="post">
146
<input type="hidden" name="page_id" value="<?php echo $page_id ?>" />
147
<input type="hidden" name="section_id" value="<?php echo $section_id ?>" />
148
<table cellpadding="0" cellspacing="0" border="0" width="100%">
149
<tr>
150
	<td>
151
		<?php echo $TEXT['LINK'].':' ?>
152
	</td>
153
	<td>
154
		<select name="page_link" id="page_link" onchange="populate()" style="width:250px;" />
151 155
			<option value="0"<?php echo $target_page_id=='0'?$sel:''?>><?php echo $TEXT['PLEASE_SELECT']; ?></option>
152
			<option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>

153
			<?php foreach($links AS $pid=>$link) {

154
				echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>";

155
			} ?>

156
			<option value="-1"<?php echo $target_page_id=='-1'?$sel:''?>><?php echo $MOD_MENU_LINK['EXTERNAL_LINK']; ?></option>
157
			<?php foreach($links AS $pid=>$link) {
158
				echo "<option value=\"$pid\" ".($target_page_id==$pid?$sel:'').">$link</option>";
159
			} ?>
156 160
		</select>
157 161
		&nbsp;
158
		<input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
159
	</td>
160
</tr>
161
<tr>
162
	<td>
163
		<?php echo $TEXT['ANCHOR'].':' ?>
164
	</td>
165
	<td>
166
		<select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" />
167
			<option value="<?php echo $anchor ?>" selected><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
168
		</select>
169
	</td>
170
</tr>
171
<tr>
172
	<td>
173
		<?php echo $TEXT['TARGET'].':' ?>
174
	</td>
175
	<td>
176
		<select name="target" style="width:250px;" />
177
			<option value="_blank"<?php if($target=='_blank') echo ' selected'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
178
			<option value="_self"<?php if($target=='_self') echo ' selected'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
179
			<option value="_top"<?php if($target=='_top') echo ' selected'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
180
		</select>
181
	</td>
182
</tr>
183
</table>
184

  
185
<br />
186

  
187
<table cellpadding="0" cellspacing="0" border="0" width="100%">
188
<tr>
189
	<td align="left">
190
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
191
	</td>
192
	<td align="right">
193
		</form>
194
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
195
	</td>
196
</tr>
197
</table>
198

  
199
</form>
200

  
162
		<input type="text" name="extern" id="extern" value="<?php echo $extern; ?>" style="width:250px;" <?php if($target_page_id!='-1') echo 'disabled="disabled"'; ?> />
163
	</td>
164
</tr>
165
<tr>
166
	<td>
167
		<?php echo $TEXT['ANCHOR'].':' ?>
168
	</td>
169
	<td>
170
		<select name="page_target" id="page_target" onfocus="populate()" style="width:250px;" />
171
			<option value="<?php echo $anchor ?>" selected><?php echo $anchor=='0'?' ':'#'.$anchor ?></option>
172
		</select>
173
	</td>
174
</tr>
175
<tr>
176
	<td>
177
		<?php echo $TEXT['TARGET'].':' ?>
178
	</td>
179
	<td>
180
		<select name="target" style="width:250px;" />
181
			<option value="_blank"<?php if($target=='_blank') echo ' selected'; ?>><?php echo $TEXT['NEW_WINDOW'] ?></option>
182
			<option value="_self"<?php if($target=='_self') echo ' selected'; ?>><?php echo $TEXT['SAME_WINDOW'] ?></option>
183
			<option value="_top"<?php if($target=='_top') echo ' selected'; ?>><?php echo $TEXT['TOP_FRAME'] ?></option>
184
		</select>
185
	</td>
186
</tr>
187
</table>
188

  
189
<br />
190

  
191
<table cellpadding="0" cellspacing="0" border="0" width="100%">
192
<tr>
193
	<td align="left">
194
		<input type="submit" value="<?php echo $TEXT['SAVE'] ?>" style="width: 100px; margin-top: 5px;" />
195
	</td>
196
	<td align="right">
197
		</form>
198
		<input type="button" value="<?php echo $TEXT['CANCEL'] ?>" onclick="javascript: window.location = 'index.php';" style="width: 100px; margin-top: 5px;" />
199
	</td>
200
</tr>
201
</table>
202

  
203
</form>
204

  

Also available in: Unified diff