/[cvs]/nfo/php/libs/org.netfrag.glib/utils/links.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.glib/utils/links.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Tue Apr 8 22:38:43 2003 UTC (21 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.2: +39 -21 lines
NEW: 'class url' as code container for some shortcut functions

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed