1 |
<? |
2 |
/* |
3 |
## ------------------------------------------------------------------------- |
4 |
## $Id: links.php,v 1.1 2003/04/06 04:30:10 joko Exp $ |
5 |
## ------------------------------------------------------------------------- |
6 |
## $Log: links.php,v $ |
7 |
## Revision 1.1 2003/04/06 04:30:10 joko |
8 |
## initial commit |
9 |
## |
10 |
## Revision 1.8 2003/04/04 02:00:54 joko |
11 |
## modified rTopic |
12 |
## new: jsAnchor |
13 |
## |
14 |
## Revision 1.7 2003/03/28 03:09:49 joko |
15 |
## + function pageLink |
16 |
## |
17 |
## Revision 1.6 2003/02/28 04:30:45 joko |
18 |
## + new shortcuts to build links/urls directly to topics etc. |
19 |
## |
20 |
## Revision 1.5 2003/02/27 18:07:49 joko |
21 |
## + new functions: rPage, rLink |
22 |
## |
23 |
## Revision 1.4 2003/02/22 17:38:17 cvsmax |
24 |
## + added array_merge of GET and POST vars |
25 |
## |
26 |
## Revision 1.3 2003/02/22 16:41:58 joko |
27 |
## renamed core functions |
28 |
## |
29 |
## Revision 1.2 2003/02/20 22:42:10 joko |
30 |
## + functions rAnchor and rLink |
31 |
## |
32 |
## Revision 1.1 2003/02/17 01:12:17 joko |
33 |
## + initial commit |
34 |
## |
35 |
## ------------------------------------------------------------------------- |
36 |
*/ |
37 |
|
38 |
|
39 |
require_once("LinkBuilder.php"); |
40 |
|
41 |
class link { |
42 |
|
43 |
// shortcut to 'LinkBuilder' |
44 |
function store($link_vars = array()) { |
45 |
$linkbuilder = new LinkBuilder(); |
46 |
$link_guid = $linkbuilder->save($link_vars); |
47 |
return $link_guid; |
48 |
} |
49 |
|
50 |
// shortcut to 'LinkBuilder' |
51 |
function restore($guid) { |
52 |
$linkbuilder = new LinkBuilder(); |
53 |
return $linkbuilder->load($guid); |
54 |
} |
55 |
|
56 |
// shortcut to render a html-link triggering a function |
57 |
// in the global javascript scope of the user agent |
58 |
function js_function($js_function, $js_args = array(), $caption) { |
59 |
$bufarr = array(); |
60 |
foreach ($js_args as $arg) { |
61 |
array_push($bufarr, "'$arg'"); |
62 |
} |
63 |
$bufstr = join(', ', $bufarr); |
64 |
return html_a("javascript:$js_function($bufstr);", $caption); |
65 |
} |
66 |
|
67 |
function topic($topic_name, $args = array()) { |
68 |
$css_class = $args[_css_class]; |
69 |
unset($args[_css_class]); |
70 |
$query_string = linkargs::topic($topic_name, $args); |
71 |
return html_a($query_string, $topic_name, $css_class); |
72 |
} |
73 |
|
74 |
function page($caption = null, $args = array(), $identifier = null) { |
75 |
// manipulate args, merge in non-existent, but required attributes (e.g. 'ap') |
76 |
// FIXME: do this more generic! use array_merge for this purpose? |
77 |
$opts = array_merge($_GET, $_POST); |
78 |
if (!$args[ap]) { $args[ap] = $opts[ap]; } |
79 |
$query_string = httpQuery($args); |
80 |
return html_a($query_string, $caption); |
81 |
} |
82 |
|
83 |
function action($action_name, $args = array()) { |
84 |
$query_string = linkargs::action($action_name, $args); |
85 |
return html_a($query_string, "[$action_name]"); |
86 |
} |
87 |
|
88 |
} |
89 |
|
90 |
class ref { |
91 |
|
92 |
function action($action, $args = array()) { |
93 |
$args[action] = $action; |
94 |
return rAnchor($action, $args); |
95 |
} |
96 |
|
97 |
function page($page_ident, $args = array()) { |
98 |
$args[ap] = $page_ident; |
99 |
return rAnchor($action, $args); |
100 |
} |
101 |
|
102 |
function link($caption, $page_ident) { |
103 |
$args[ap] = $page_ident; |
104 |
return rAnchor($caption, $args); |
105 |
} |
106 |
|
107 |
} |
108 |
|
109 |
|
110 |
|
111 |
class linkargs { |
112 |
|
113 |
function page($page_name, $args = array()) { |
114 |
$args[ap] = $page_name; |
115 |
//unset($args[ap]); |
116 |
return httpQuery($args); |
117 |
} |
118 |
|
119 |
function topic($topic_name, $args = array()) { |
120 |
$args[t] = $topic_name; |
121 |
//unset($args[ap]); |
122 |
return httpQuery($args); |
123 |
} |
124 |
|
125 |
function action($action_name, $args = array()) { |
126 |
$args[ga] = $action_name; |
127 |
return httpQuery($args); |
128 |
} |
129 |
|
130 |
} |
131 |
|
132 |
|
133 |
function httpQuery($args = array()) { |
134 |
$query_list = array(); |
135 |
foreach ($args as $key => $val) { |
136 |
array_push($query_list, "$key=$val"); |
137 |
} |
138 |
$query_string = join('&', $query_list); |
139 |
if ($query_string) { $query_string = '?' . $query_string; } |
140 |
return $query_string; |
141 |
} |
142 |
|
143 |
|
144 |
function yesno($bool) { |
145 |
return $bool ? 'yes' : 'no'; |
146 |
} |
147 |
|
148 |
function qLink_old($args = array()) { |
149 |
return httpQuery($args); |
150 |
} |
151 |
|
152 |
|
153 |
?> |