/[drupal]/contributions/modules/hypergraph/hypergraph.module
ViewVC logotype

Contents of /contributions/modules/hypergraph/hypergraph.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.18 - (show annotations) (download) (as text)
Wed Jan 7 19:00:03 2009 UTC (10 months, 2 weeks ago) by tjfulopp
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.17: +264 -252 lines
File MIME type: text/x-php
*** empty log message ***
1 <?php
2 /* $Id: hypergraph.module,v 1.17 2007/10/26 19:04:09 tjfulopp Exp $ */
3 function hypergraph_help($section = '') {
4
5 $output = '';
6
7 switch ($section) {
8 case "admin/help#hypergraph":
9 $output = '<p>'. t("Integration of Java hyperbolic tree geometry visualization developed at http://hypergraph.sourceforge.net/") .'</p>';
10 break;
11 }
12
13 return $output;
14 }
15 // function hypergraph_help
16 function hypergraph_perm() {
17
18 #, 'administer hypergraph'
19 return array('access hypergraph');
20 }
21 // function hypergraph_perm
22 function hypergraph_block($op = 'list', $delta = 0) {
23 // listing of blocks, such as on the admin/block page
24 if ($op == "list") {
25 $block[0]["info"] = t("Hypergraph");
26 return $block;
27 }
28 else if ($op == 'view') {
29 // our block content
30 // content variable that will be returned for display
31 $block_content = '';
32
33 #$block_content .= l($links->title, 'node/'.$links->nid) . '<br />';
34 #$block_content .= l('vacilando', 'http://www.vacilando.org') . '<br />';
35
36 $block_content .= render_hypergraph();
37
38 // set up the block
39 $block['subject'] = 'Hypergraph';
40 $block['content'] = $block_content;
41 return $block;
42 }
43 }
44 // end hypergraph_block
45 function hypergraph_all() {
46 // content variable that will be returned for display
47 $page_content = '';
48
49 $page_content .= render_hypergraph();
50
51 return $page_content;
52 }
53
54 function hypergraph_admin() {
55 /*
56 $form['hypergraph_centre'] = array(
57 '#type' => 'textfield',
58 '#title' => t('Parent menu of the hyper graph'),
59 '#default_value' => variable_get('hypergraph_parent', variable_get('menu_primary_menu', 0)),
60 '#size' => 10,
61 '#maxlength' => 50,
62 '#description' => t("Drupal menu id ( $mid ) that you wish to use as the \"beginning\" for your graph.") # Exclude trailing trailing slashes. Example: <i>node/1</i>
63 );
64 */
65
66 $form['hypergraph_width'] = array(
67 '#type' => 'textfield',
68 '#title' => t('Default width of the hyper graph'),
69 '#default_value' => variable_get('hypergraph_width', '720'),
70 '#size' => 4,
71 '#maxlength' => 4,
72 '#description' => t("Default width of the hyper graph."),
73 );
74 $form['hypergraph_height'] = array(
75 '#type' => 'textfield',
76 '#title' => t('Default height of the hyper graph'),
77 '#default_value' => variable_get('hypergraph_height', '540'),
78 '#size' => 4,
79 '#maxlength' => 4,
80 '#description' => t("Default height of the hyper graph."),
81 );
82 $form['hypergraph_cache'] = array(
83 '#type' => 'radios',
84 '#title' => t('Database or file system caching of the hypergraph source data'),
85 '#default_value' => variable_get('hypergraph_cache', 'd'),
86 '#options' => array('d' => t('Use the <i>cache</i> table of Drupal.'),
87 'f' => t('Use the temporary directory you have set in <i>/admin/settings/file-system</i>. Faster than database caching!'),
88 ),
89 #'#description' => t("")
90 );
91 return system_settings_form($form);
92 }
93
94 # Probably not the right way of doing it but it works...
95 function hypergraph_perms() {
96 header("HTTP/1.1 301 Moved Permanently");
97 header("Location: ". base_path() ."admin/user/access#module-hypergraph");
98 exit();
99 }
100
101 function hypergraph_menu() {
102
103 $items = array();
104
105 $items[] = array(
106 'path' => 'admin/settings/hypergraph',
107 'title' => t('Hypergraph'),
108 'description' => t('Hypergraph module settings'),
109 'callback' => 'drupal_get_form',
110 'callback arguments' => 'hypergraph_admin',
111 'access' => user_access('access administration pages'),
112 'type' => MENU_NORMAL_ITEM,
113 );
114
115 # Probably not the right way of doing it but it works...
116 $items[] = array(
117 'path' => 'admin/settings/hypergraph/hypergraph_perms',
118 #'path' => 'admin/user/access#module-hypergraph',
119 'title' => t('Configure permissions'),
120 'description' => t('Configure access permissions for the Hypergraph module'),
121 'callback' => 'hypergraph_perms',
122 #'callback arguments' => 'hypergraph_perms',
123 'access' => user_access('access administration pages'),
124 'type' => MENU_NORMAL_ITEM,
125 );
126
127 $items[] = array(
128 'path' => 'hypergraph',
129 'title' => t('Hypergraph'),
130 'callback' => 'hypergraph_all',
131 'access' => user_access('access hypergraph'),
132 'type' => MENU_CALLBACK,
133 # The type MENU_CALLBACK tells Drupal to not display the link in the user's menu, just use this function when the URL is accessed. Use MENU_NORMAL_ITEM if you want the user to see the link in the side navigation block.
134 );
135 return $items;
136 }
137
138 function request_uri2() {
139 if (isset($_SERVER['REQUEST_URI'])) {
140 $uri = $_SERVER['REQUEST_URI'];
141 }
142 else {
143 if (isset($_SERVER['argv'])) {
144 $uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['argv'][0];
145 }
146 else {
147 $uri = $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
148 }
149 }
150 return $uri;
151 }
152
153 function render_hypergraph($hgparentoverride = '', $hgwidthoverride = '', $hgheightoverride = '', $hgcenteroverride = '') {
154 # Get ready the cache id where we will store the data.
155 global $user;
156 $userId = $user->uid;
157 $result = '';
158 if ($hgparentoverride == '') {
159 $hypergraph_parent = variable_get('hypergraph_parent', variable_get('menu_primary_menu', 0));
160 }
161 else {
162 $hypergraph_parent = $hgparentoverride;
163 }
164 if ($hgwidthoverride == '') {
165 $hypergraph_width = variable_get('hypergraph_width', '720');
166 }
167 else {
168 $hypergraph_width = $hgwidthoverride;
169 }
170 if ($hgheightoverride == '') {
171 $hypergraph_height = variable_get('hypergraph_height', '540');
172 }
173 else {
174 $hypergraph_height = $hgheightoverride;
175 }
176 if ($hgcenteroverride == '') {
177 # No center override defined in the HG tag, so center around the current node (if it is present in the graph!)
178 $amitem = _menu_get_active_trail();
179 # Dunno why but had to do this..
180 $amitemkey = (sizeof($amitem) - 2);
181 #echo $amitem[$amitemkey];
182 #$hypergraph_center = '322';
183 $hypergraph_center = $amitem[$amitemkey];
184 }
185 else {
186 $hypergraph_center = $hgcenteroverride;
187 }
188 #$hgmenucacheid = 'hg_menu_' . $userId . '_' . microtime_float() . '_' . mt_rand(0,1000000);
189 # If menu, m, if taxonomy, t, .. something like that will go here.
190 $hgsource = 'm';
191 # file_directory_path()
192 #$result .= file_directory_temp();
193 # $absolpath = realpath( $path );
194 # base_path() . drupal_get_path('module', 'brilliant_gallery') .'/image.php?im
195 #if ( $hgcenteroverride == '' ) { $result .= '<p><center>'; } # In case of display at /hypergraph
196 #$modulepath = url(drupal_get_path('module', 'hypergraph'), NULL, NULL, TRUE);
197 $result .= '<!-- Hypergraph Beginning --><applet code="hypergraph.applications.hexplorer.HExplorerApplet" align="baseline" archive="';
198
199 # Get proper module path.
200 $hgmodulepath = url(drupal_get_path('module', 'hypergraph'), NULL, NULL, TRUE);
201 # url() ads i18n codes to the URL ... we need to remove them here...
202 if ($langcode <> '') {
203 $hgmodulepath = str_replace('/'. $langcode .'/', '/', $hgmodulepath);
204 }
205 # Non-clean URLs need removing ?q=
206 $hgmodulepath = str_replace("?q=", "", $hgmodulepath);
207 /*
208 # Get possible RELATIVE Drupal path we may be on..
209 $levels = count( explode( '/', request_uri2() ) ) - 1;
210 $relprefix = '';
211 for( $x=1;$x<$levels;$x++ ) {
212 $relprefix .= '..';
213 if ( $x < ($levels-1) ) { # Omit closing slash.
214 $relprefix .= '/';
215 }
216 }
217 */
218
219 # ????????Crucial: Java applet paths MUST be relative.
220 $result .= $relprefix . base_path() . drupal_get_path('module', 'hypergraph') .'/hyperapplet.jar" width="'. $hypergraph_width .'" height="'. $hypergraph_height .'"><param name="file" value="';
221 #$result .= $hgmodulepath . '/hyperapplet.jar" width="' . $hypergraph_width . '" height="' . $hypergraph_height . '"><param name="file" value="';
222 #$result .= 'http://www.vacilando.org/_misc/hypergraph/hyperapplet.jar" width="' . $hypergraph_width . '" height="' . $hypergraph_height . '"><param name="file" value="';
223 $result .= $relprefix . base_path() . drupal_get_path('module', 'hypergraph') .'/graphs/hg.php?par='. $hypergraph_parent .'&ctr='. $hypergraph_center .'&src='. $hgsource .'&dummy=.xml';
224 #$result .= $hgmodulepath . '/graphs/hg.php?par=' . $hypergraph_parent . '&ctr=' . $hypergraph_center . '&src=' . $hgsource . '&dummy=.xml';
225 #$result .= 'http://www.vacilando.org/_misc/hypergraph/graphs/hg.php?dummy=.xml';
226 #$result .= $relprefix . base_path() . drupal_get_path('module', 'hypergraph') . '/graphs/hg.php?loc=1&dummy=.xml'; # Test from a local file.
227
228 #$result .= 'http://www.vacilando.org/quidne/_temp/test_vacil.xml'; # ----------
229 #$result .= 'http://www.vacilando.org/quidne/_temp/test_hg_menu_0_124.xml'; # ---------- ALE OK s http://www.vacilando.org/_misc/hypergraph/graphs/GraphXML.dtd
230 #$result .= 'http://www.vacilando.org/temp/_temp/test_vacil.xml'; # OK !!!
231 #$result .= 'http://www.vacilando.org/temp/_temp/test_hg_menu_0_124.xml'; # OK !!!
232 #$result .= 'http://quidne.vacilando.org/_temp/test_vacil.xml'; #
233 #$result .= 'http://quidne.vacilando.org/_temp/test_hg_menu_0_124.xml'; # OK s http://www.vacilando.org/_misc/hypergraph/graphs/GraphXML.dtd
234 ##$result .= $relprefix . base_path() . drupal_get_path('module', 'hypergraph') . '/graphs/test_hg_menu_0_124.xml'; # OK s http://www.vacilando.org/_misc/hypergraph/graphs/GraphXML.dtd or http://quidne.vacilando.org/sites/all/modules/hypergraph/graphs/GraphXML.dtd
235
236 #$result .= 'http://quidne.vacilando.org/sites/quidne.vacilando.org/files/tst/test_hg_menu_0_124.xml';
237 $result .= '">';
238 $result .= '<param name="properties" value="';
239 $result .= $relprefix . base_path() . drupal_get_path('module', 'hypergraph') .'/graphs/';
240 #$result .= $hgmodulepath . '/graphs/';
241 if ($hypergraph_width <= 200) {
242 # Use smaller text if the applet is small.
243 $result .= 'hg_small.prop';
244 }
245 else {
246 $result .= 'hg.prop';
247 }
248 #$result .= 'http://www.vacilando.org/_misc/hypergraph/graphs/hg.prop';
249 $result .= '">';
250 $result .= '<param name="center" value="'. $hypergraph_center .'">';
251 # I don't know if you've solved your problem now, but in the HTML tags, if you add <PARAM="cache_option" VALUE="No"> as a parameter to your applet (inside the <embed>, <object> or <applet> tags), the applet will not be cached. More info here: http://java.sun.com/products/plugin/1.3/docs/appletcaching.html
252 $result .= '<PARAM="cache_option" VALUE="No">';
253 # . $_SERVER['PHP_SELF'];
254 $result .= '</applet>';
255 /*
256 $result .= '<p>';
257 # Get possible Drupal path we may be on.. from request_uri but without the last part.
258 $lastslash = explode( '/', request_uri2() );
259 unset($lastslash[(sizeof($lastslash)-1)]);
260 $lastslash = implode( '/', $lastslash );
261 $result .= $lastslash;
262 */
263
264 /*
265 ob_start();
266 echo '<!--';
267 echo "\n";
268 #$amitem = menu_get_active_item();
269 $amitem = _menu_get_active_trail();
270 $amitemkey = (sizeof($amitem)-2); # Dunno why but had to do this..
271 echo $amitem[$amitemkey];
272 echo "\n";
273 print_r(_menu_get_active_trail());
274 $result .= ob_get_clean();
275 $result .= '-->';
276 */
277
278 /*
279 $result .= '<font color=white>';
280 $result .= '<!--';
281 function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() ) {
282 # http://be2.php.net/manual/en/function.array-search.php
283 # Searches haystack for needle and returns an array of the key path if it is found in the (multidimensional) array, FALSE otherwise.
284 # mixed array_searchRecursive ( mixed needle, array haystack [, bool strict[, array path]] )
285 if( !is_array($haystack) ) {
286 return false;
287 }
288
289 foreach( $haystack as $key => $val ) {
290 if( is_array($val) && $subPath = array_searchRecursive($needle, $val, $strict, $path) ) {
291 $path = array_merge($path, array($key), $subPath);
292 return $path;
293 } elseif( (!$strict && $val == $needle) || ($strict && $val === $needle) ) {
294 $path[] = $key;
295 return $path;
296 }
297 }
298 return false;
299 }
300
301 function findepth( $needle, $haystack ) {
302 $foundepth = 0;
303 $foundparent = NULL;
304 $searchparent = false;
305 do {
306 $searchparent = array_searchRecursive( $needle, $haystack );
307 if ( $searchparent !== false ) {
308 $foundepth ++;
309 unset($tempar[$searchparent]);
310 $needle = $searchparent[0];
311 }
312 #echo '... ' . $foundepth . "\n";
313 } while ( $searchparent !== false );
314 return $foundepth;
315 }
316
317 ob_start();
318 #print_r( menu_get_menu() );
319 $menu = menu_get_menu(); #print_r( $menu['visible'] ); # The returned structure contains much information that is useful only internally in the menu system. External modules are likely to need only the ['visible'] element of the returned array. All menu items that are accessible to the current user and not hidden will be present here, so modules and themes can use this structure to build their own representations of the menu.
320 echo '\n1---------------------------\n ';
321 #echo print_r( multiArraySearch( '326', $menu['visible']) );
322 $temparx = $menu['visible'];
323 $tempar = NULL;
324 foreach( $temparx as $key=>$value ) {
325 foreach( $value['children'] as $key2=>$value2 ) {
326 $tempar[$key][$key2] = $value2;
327 }
328 }
329 print_r( $tempar ) ;
330 echo '\n2---------------------------\n ';
331 print_r( array_searchRecursive('326',$tempar ) );
332 print_r( array_searchRecursive('125',$tempar ) );
333 print_r( array_searchRecursive('320',$tempar ) );
334 print_r( array_searchRecursive('124',$tempar ) );
335 print_r( array_searchRecursive('0',$tempar ) ); # FALSE!!
336 echo '\n3---------------------------\n ';
337 echo '... ' . findepth( '326', $tempar ) . "\n";
338 echo '... ' . findepth( '125', $tempar ) . "\n";
339 echo '... ' . findepth( '320', $tempar ) . "\n";
340 echo '... ' . findepth( '124', $tempar ) . "\n";
341 echo '... ' . findepth( '0', $tempar ) . "\n";
342 echo '\n4---------------------------\n ';
343
344 $depth = 0;
345 foreach( $menu['visible'] as $key=>$value ) {
346 echo ' <node class="hpg' . findepth( $key, $tempar ) . '" name="' . $key . '"><label>' . $value['title'] . '</label><dataref><ref xlink:href="' . $value['path'] . '"/></dataref></node>' . "\n";
347 if ( !empty( $value['children'] ) ) {
348 foreach( $value['children'] as $key2=>$value2 ) {
349 echo ' <edge source="' . $key . '" target="' . $value2 . '" />\n';
350 }
351 }
352 }
353 #print_r( menu_tree() );
354 #print_r( menu_secondary_links() );
355 $result .= ob_get_clean();
356 $result .= '-->';
357 $result .= '</font>';
358 */
359
360 # To debug... temp. line:
361 #$result .= '<a href="' . base_path() . drupal_get_path('module', 'hypergraph') . '/graphs/hg.php?ctr=' . $hypergraph_centre . '&hmc=' . $hgmenucacheid . '&dummy=.xml"><font color=white>.</font></a>';
362 #$result .= '<p>' . file_directory_temp();
363 #$result .= '<p>' . realpath(file_directory_temp());
364 #$result .= '<p>' . sys_get_temp_dir_compat();
365 #$result .= '<p>'; print_r( $_ENV );
366 #if ( $hgcenteroverride == '' ) { $result .= '</center>'; } # In case of display at /hypergraph
367
368 #$o = "<<<hgdivider>>>";
369 #$o .= "<div class=\"footermap\">\n";
370 #$x = footermap_get_menu(variable_get('top_menu',variable_get('menu_primary_menu', 0)),1,0,$o,variable_get('recurse_limit',0));
371 #$x = hypergraph_get_menu(124,1,0,$o,0);
372
373 #$result .= caching_wrapper_hgm($hgmenucacheid);
374 #caching_wrapper_hgm2($hgmenucacheid);
375 #caching_wrapper_hgm( $hgmenucacheid );
376
377 return $result;
378 }
379
380
381 # Implementation of hook_filter().
382 function hypergraph_filter($op, $delta = 0, $format = -1, $text = '') {
383 switch ($op) {
384 case 'no cache':
385 return FALSE;
386
387 case 'list':
388 return array(0 => t('Hypergraph Tag'));
389
390 case 'description':
391 return t('Substitutes a special Hypergraph Tag with the actual visualization.');
392
393 case 'prepare':
394 return $text;
395
396 case 'process':
397 # process it here........
398 $text = replace_hypergraph_tags($text);
399 return $text;
400 }
401 }
402
403 function replace_hypergraph_tags($str) {
404 # [hg|parentnode|width|height|centeroverride]
405 # no slashes around this path!
406 $matchlink = '';
407 $orig_match = '';
408 preg_match_all("/(\[)hg(\|).*(\])/", $str, $matches);
409 foreach ($matches[0] as $match) {
410 $orig_match[] = $match;
411 $match = substr($match, 1, (strlen($match) - 2));
412 $match = explode("|", $match);
413 $matchlink[] = render_hypergraph($match[1], $match[2], $match[3], $match[4]);
414 }
415 $str = str_replace($orig_match, $matchlink, $str);
416 return $str;
417 }
418
419 /**
420 * Implementation of hook_filter_tips().
421 *
422 * This hook allows filters to provide help text to users during the content
423 * editing process. Short tips are provided on the content editing screen, while
424 * long tips are provided on a separate linked page. Short tips are optional,
425 * but long tips are highly recommended.
426 */
427 /*
428 function hypergraph_filter_tips($delta, $format, $long = FALSE) {
429 switch ($delta) {
430 case 0:
431 if ($long) {
432 return t('Every instance of "foo" in the input text will be replaced with "%replacement".', array('%replacement' => variable_get('filter_example_foo_'. $format, 'bar')));
433 }
434 break;
435
436 case 1:
437 if ($long) {
438 return t('Every instance of the special &lt;time /&gt; tag will be replaced with the current date and time in the user\'s specified time zone.');
439 }
440 else {
441 return t('Use &lt;time /&gt; to display the current date/time.');
442 }
443 break;
444 }
445 }
446 */
447
448
449
450

  ViewVC Help
Powered by ViewVC 1.1.2