Index: hypergraph.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/hypergraph/hypergraph.module,v retrieving revision 1.17 diff -u -p -r1.17 hypergraph.module --- hypergraph.module 26 Oct 2007 19:04:09 -0000 1.17 +++ hypergraph.module 17 Jul 2008 03:45:51 -0000 @@ -1,438 +1,187 @@ '. t("Integration of Java hyperbolic tree geometry visualization developed at http://hypergraph.sourceforge.net/"). '

'; - break; - } - - return $output; -} // function hypergraph_help + switch ($section) { + case "admin/help#hypergraph": + $output = '

'. t("Integration of Java hyperbolic tree geometry visualization developed at http://hypergraph.sourceforge.net/"). '

'; + break; + } + return $output; +} +/** + * Implementation of hook_perm(). + */ function hypergraph_perm() { + return array('access hypergraph'); +} -return array('access hypergraph'); #, 'administer hypergraph' - -} // function hypergraph_perm - - -function hypergraph_block($op='list', $delta=0) { - // listing of blocks, such as on the admin/block page - if ($op == "list") { - $block[0]["info"] = t("Hypergraph"); - return $block; - } else if ($op == 'view') { - // our block content - // content variable that will be returned for display - $block_content = ''; - - #$block_content .= l($links->title, 'node/'.$links->nid) . '
'; - #$block_content .= l('vacilando', 'http://www.vacilando.org') . '
'; - - $block_content .= render_hypergraph(); - - // set up the block - $block['subject'] = 'Hypergraph'; - $block['content'] = $block_content; - return $block; - } -} // end hypergraph_block - - -function hypergraph_all() { - // content variable that will be returned for display - $page_content = ''; - - $page_content .= render_hypergraph(); - - return $page_content; +/** + * Implementation of hook_block(). + */ +function hypergraph_block($op = 'list', $delta = 0) { + if ($op == 'list') { + $block[0]["info"] = t("Hypergraph"); + return $block; + } + elseif ($op == 'view') { + // Set up the block. + $block['subject'] = 'Hypergraph'; + $block['content'] = render_hypergraph(); + return $block; + } } +/** + * Admin settings form. + */ +function hypergraph_admin() { + $form = array(); + + $form['hypergraph_width'] = array( + '#type' => 'textfield', + '#title' => t('Default width of the hyper graph'), + '#default_value' => variable_get('hypergraph_width', '720'), + '#size' => 4, + '#maxlength' => 4, + '#description' => t("Default width of the hyper graph.") + ); + + $form['hypergraph_height'] = array( + '#type' => 'textfield', + '#title' => t('Default height of the hyper graph'), + '#default_value' => variable_get('hypergraph_height', '540'), + '#size' => 4, + '#maxlength' => 4, + '#description' => t("Default height of the hyper graph.") + ); -function hypergraph_admin() { -/* - $form['hypergraph_centre'] = array( - '#type' => 'textfield', - '#title' => t('Parent menu of the hyper graph'), - '#default_value' => variable_get('hypergraph_parent', variable_get('menu_primary_menu', 0)), - '#size' => 10, - '#maxlength' => 50, - '#description' => t("Drupal menu id ( $mid ) that you wish to use as the \"beginning\" for your graph.") # Exclude trailing trailing slashes. Example: node/1 - ); -*/ - $form['hypergraph_width'] = array( - '#type' => 'textfield', - '#title' => t('Default width of the hyper graph'), - '#default_value' => variable_get('hypergraph_width', '720'), - '#size' => 4, - '#maxlength' => 4, - '#description' => t("Default width of the hyper graph.") - ); - $form['hypergraph_height'] = array( - '#type' => 'textfield', - '#title' => t('Default height of the hyper graph'), - '#default_value' => variable_get('hypergraph_height', '540'), - '#size' => 4, - '#maxlength' => 4, - '#description' => t("Default height of the hyper graph.") - ); $form['hypergraph_cache'] = array( '#type' => 'radios', '#title' => t('Database or file system caching of the hypergraph source data'), '#default_value' => variable_get('hypergraph_cache', 'd'), - '#options' => array('d' => t('Use the cache table of Drupal.'), - 'f' => t('Use the temporary directory you have set in /admin/settings/file-system. Faster than database caching!')), - #'#description' => t("") + '#options' => array( + 'd' => t('Use the cache table of Drupal.'), + 'f' => t('Use the temporary directory you have set in /admin/settings/file-system. Faster than database caching!'), + ), ); - return system_settings_form($form); -} -# Probably not the right way of doing it but it works... - function hypergraph_perms() { - header("HTTP/1.1 301 Moved Permanently"); - header("Location: " . base_path() . "admin/user/access#module-hypergraph"); - exit(); - } + return system_settings_form($form); +} function hypergraph_menu() { + $items = array(); - $items = array(); + $items[] = array( + 'path' => 'admin/settings/hypergraph', + 'title' => t('Hypergraph'), + 'description' => t('Hypergraph module settings'), + 'callback' => 'drupal_get_form', + 'callback arguments' => 'hypergraph_admin', + 'access' => user_access('access administration pages'), + 'type' => MENU_NORMAL_ITEM, + ); + + $items[] = array( + 'path' => 'hypergraph', + 'title' => t('Hypergraph'), + 'callback' => 'render_hypergraph', + 'access' => user_access('access hypergraph'), + 'type' => MENU_CALLBACK, + ); - $items[] = array( - 'path' => 'admin/settings/hypergraph', - 'title' => t('Hypergraph'), - 'description' => t('Hypergraph module settings'), - 'callback' => 'drupal_get_form', - 'callback arguments' => 'hypergraph_admin', - 'access' => user_access('access administration pages'), - 'type' => MENU_NORMAL_ITEM, - ); - - # Probably not the right way of doing it but it works... - $items[] = array( - 'path' => 'admin/settings/hypergraph/hypergraph_perms', - #'path' => 'admin/user/access#module-hypergraph', - 'title' => t('Configure permissions'), - 'description' => t('Configure access permissions for the Hypergraph module'), - 'callback' => 'hypergraph_perms', - #'callback arguments' => 'hypergraph_perms', - 'access' => user_access('access administration pages'), - 'type' => MENU_NORMAL_ITEM, - ); - - $items[] = array( - 'path' => 'hypergraph', - 'title' => t('Hypergraph'), - 'callback' => 'hypergraph_all', - 'access' => user_access('access hypergraph'), - 'type' => MENU_CALLBACK - ); # 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. - - return $items; + return $items; } -function request_uri2() { - if (isset($_SERVER['REQUEST_URI'])) { - $uri = $_SERVER['REQUEST_URI']; +function render_hypergraph($hgparentoverride = '', $hgwidthoverride = '', $hgheightoverride = '', $hgcenteroverride = '') { + $result = ''; + if ($hgparentoverride == '') { + $hypergraph_parent = variable_get('hypergraph_parent', variable_get('menu_primary_menu', 0)); + } + else { + $hypergraph_parent = $hgparentoverride; + } + if ($hgwidthoverride == '') { + $hypergraph_width = variable_get('hypergraph_width', '720'); + } + else { + $hypergraph_width = $hgwidthoverride; + } + if ($hgheightoverride == '') { + $hypergraph_height = variable_get('hypergraph_height', '540'); + } + else { + $hypergraph_height = $hgheightoverride; + } + if ($hgcenteroverride == '') { + // No center override defined in the HG tag, so center around the current + // node (if it is present in the graph!) + $amitem = _menu_get_active_trail(); + $amitemkey = (sizeof($amitem)-2); + $hypergraph_center = $amitem[$amitemkey]; + } + else { + $hypergraph_center = $hgcenteroverride; + } + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + $result .= ''; + return $result; } -function render_hypergraph( $hgparentoverride = '', $hgwidthoverride = '', $hgheightoverride = '', $hgcenteroverride = '' ) { - # Get ready the cache id where we will store the data. - global $user; - $userId = $user->uid; - $result = ''; - if ( $hgparentoverride == '' ) { - $hypergraph_parent = variable_get('hypergraph_parent', variable_get('menu_primary_menu', 0)); - } else { - $hypergraph_parent = $hgparentoverride; - } - if ( $hgwidthoverride == '' ) { - $hypergraph_width = variable_get('hypergraph_width', '720'); - } else { - $hypergraph_width = $hgwidthoverride; - } - if ( $hgheightoverride == '' ) { - $hypergraph_height = variable_get('hypergraph_height', '540'); - } else { - $hypergraph_height = $hgheightoverride; - } - if ( $hgcenteroverride == '' ) { - # No center override defined in the HG tag, so center around the current node (if it is present in the graph!) - $amitem = _menu_get_active_trail(); - $amitemkey = (sizeof($amitem)-2); # Dunno why but had to do this.. - #echo $amitem[$amitemkey]; - #$hypergraph_center = '322'; - $hypergraph_center = $amitem[$amitemkey]; - } else { - $hypergraph_center = $hgcenteroverride; - } - #$hgmenucacheid = 'hg_menu_' . $userId . '_' . microtime_float() . '_' . mt_rand(0,1000000); - # If menu, m, if taxonomy, t, .. something like that will go here. - $hgsource = 'm'; - # file_directory_path() - #$result .= file_directory_temp(); - # $absolpath = realpath( $path ); - # base_path() . drupal_get_path('module', 'brilliant_gallery') .'/image.php?im - #if ( $hgcenteroverride == '' ) { $result .= '

'; } # In case of display at /hypergraph - #$modulepath = url(drupal_get_path('module', 'hypergraph'), NULL, NULL, TRUE); - $result .= ''; - $result .= ''; - $result .= ''; - $result .= ''; # I don't know if you've solved your problem now, but in the HTML tags, if you add as a parameter to your applet (inside the , or tags), the applet will not be cached. More info here: http://java.sun.com/products/plugin/1.3/docs/appletcaching.html - $result .= '';# . $_SERVER['PHP_SELF']; -/* - $result .= '

'; - # Get possible Drupal path we may be on.. from request_uri but without the last part. - $lastslash = explode( '/', request_uri2() ); - unset($lastslash[(sizeof($lastslash)-1)]); - $lastslash = implode( '/', $lastslash ); - $result .= $lastslash; -*/ -/* - ob_start(); - echo ''; -*/ -/* - $result .= ''; - $result .= ''; - $result .= ''; -*/ - # To debug... temp. line: - #$result .= '.'; - #$result .= '

' . file_directory_temp(); - #$result .= '

' . realpath(file_directory_temp()); - #$result .= '

' . sys_get_temp_dir_compat(); - #$result .= '

'; print_r( $_ENV ); - #if ( $hgcenteroverride == '' ) { $result .= ''; } # In case of display at /hypergraph - - #$o = "<<>>"; - #$o .= "

\n"; - #$x = footermap_get_menu(variable_get('top_menu',variable_get('menu_primary_menu', 0)),1,0,$o,variable_get('recurse_limit',0)); - #$x = hypergraph_get_menu(124,1,0,$o,0); - - #$result .= caching_wrapper_hgm($hgmenucacheid); - #caching_wrapper_hgm2($hgmenucacheid); - #caching_wrapper_hgm( $hgmenucacheid ); +/** + * Implementation of hook_filter(). + */ +function hypergraph_filter($op, $delta = 0, $format = -1, $text = '') { + switch ($op) { + case 'no cache': + return FALSE; - return $result; - } + case 'list': + return array(0 => t('Hypergraph Tag')); + case 'description': + return t('Substitutes a special Hypergraph Tag with the actual visualization.'); -# Implementation of hook_filter(). -function hypergraph_filter($op, $delta = 0, $format = -1, $text = '') { - switch ($op) { - case 'no cache': - return FALSE; - - case 'list': - return array(0 => t('Hypergraph Tag')); - - case 'description': - return t('Substitutes a special Hypergraph Tag with the actual visualization.'); - - case 'prepare': - return $text; - - case 'process': - # process it here........ - $text = replace_hypergraph_tags( $text ); - return $text; - } -} - - -function replace_hypergraph_tags( $str ) { - # [hg|parentnode|width|height|centeroverride] - # no slashes around this path! - $matchlink = ''; - $orig_match = ''; - preg_match_all( "/(\[)hg(\|).*(\])/", $str, $matches); - foreach ( $matches[0] as $match ) { - $orig_match[] = $match; - $match = substr( $match, 1, ( strlen( $match ) - 2 ) ); - $match = explode( "|", $match ); - $matchlink[] = render_hypergraph( $match[1], $match[2], $match[3], $match[4] ); - } - $str = str_replace( $orig_match, $matchlink, $str ); - return $str; - } + case 'process': + return replace_hypergraph_tags($text); -/** - * Implementation of hook_filter_tips(). - * - * This hook allows filters to provide help text to users during the content - * editing process. Short tips are provided on the content editing screen, while - * long tips are provided on a separate linked page. Short tips are optional, - * but long tips are highly recommended. - */ -/* -function hypergraph_filter_tips($delta, $format, $long = FALSE) { - switch ($delta) { - case 0: - if ($long) { - return t('Every instance of "foo" in the input text will be replaced with "%replacement".', array('%replacement' => variable_get('filter_example_foo_'. $format, 'bar'))); - } - break; - - case 1: - if ($long) { - return t('Every instance of the special <time /> tag will be replaced with the current date and time in the user\'s specified time zone.'); - } - else { - return t('Use <time /> to display the current date/time.'); - } - break; - } + default: + return $text; + } } -*/ -?> + +function replace_hypergraph_tags($str) { + $matchlink = ''; + $orig_match = ''; + preg_match_all( "/(\[)hg(\|).*(\])/", $str, $matches); + foreach ($matches[0] as $match) { + $orig_match[] = $match; + $match = substr($match, 1, (strlen($match) - 2)); + $match = explode('|', $match); + $matchlink[] = render_hypergraph($match[1], $match[2], $match[3], $match[4]); + } + returnstr_replace($orig_match, $matchlink, $str); +} Index: graphs/hg.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/hypergraph/graphs/hg.php,v retrieving revision 1.15 diff -u -p -r1.15 hg.php --- graphs/hg.php 31 Mar 2008 18:57:03 -0000 1.15 +++ graphs/hg.php 17 Jul 2008 03:52:42 -0000 @@ -1,211 +1,164 @@ '' ) { - $hgmodulepath = str_replace( '/' . $langcode . '/', '/', $hgmodulepath ); - } - # Non-clean URLs need removing ?q= - $hgmodulepath = str_replace( "?q=", "", $hgmodulepath ); - -if ( $_GET['dtd'] == 1 ) { # Just supply the dtd. - #ob_start(); - #echo 'http://quidne.vacilando.org' . $hgmodulepath . '/graphs/GraphXML.dtd'; - #echo $hgmodulepath; - include $hgmodulepath . 'GraphXML.dtd'; - #include 'http://quidne.vacilando.org/sites/all/modules/hypergraph/graphs/GraphXML.dtd'; - #$dtdfile = ob_get_clean(); - #echo $dtdfile; - exit(); - } + while (!@stat('./includes/bootstrap.inc')) { + chdir ('..'); + } + require_once './includes/bootstrap.inc'; + drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); +} +// Suppress devel module output, if installed and enabled. +$GLOBALS['devel_shutdown'] = FALSE; +$hgmodulepath = drupal_get_path('module', 'hypergraph'); header("Content-type: text/xml"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); -$hgcachexpire = 3600; # Cache expiration time. -#global $user; - $userId = $user->uid; -$hgmenucacheid = 'hg_menu_' . $userId . '_' . $_GET['par']; -/* -$begxml = ''; -*/ -$begxml = ''; +$hgcachexpire = 3600; // Cache expiration time. +$user_id = $user->uid; +$hgmenucacheid = 'hg_menu_' . $user_id . '_' . $_GET['par']; + +$begxml = ''; $endxml = ''; -/* -$fullxml = ''; - ' -echo $fullxml; exit(); -*/ - -#if ( $_SERVER['SERVER_ADDR'] == '64.13.192.90' ) { -if ( variable_get('hypergraph_cache', 'd') == 'f' ) { - #echo '.....................' . $_SERVER['SERVER_ADDR']; - $temp = filecaching_wrapper_hgm(); - } else { - $temp = caching_wrapper_hgm(); - } - -#echo $hgmenucacheid; -/* -$tstart = time(); -do { - sleep(1); # Give MySQL the time to write the data to the cache (if unfinished) - $r = db_query( "SELECT * FROM cache WHERE `cid` = '" . $hgmenucacheid . "'" ) or die(mysql_error()); - $appletdata = ''; - while( $h = db_fetch_object($r) ) { - $temp = $h->data; - $appletdata = unserialize( $temp ); - } - } while ( ( ( time() - $tstart ) < 10 ) and $temp == '' ); # Search for the expected cache (there can be delay) but no longer than 60 seconds. -*/ -if ( $temp <> '' ) { - echo $temp; - } else { - echo $begxml; - echo ' - - - - - - - - '; - echo $endxml; - } -exit(); # IMPORTANT - otherwise any process after Hypergraph adds strings and breaks the XML! +if (variable_get('hypergraph_cache', 'd') == 'f') { + $temp = filecaching_wrapper_hgm(); +} +else { + $temp = caching_wrapper_hgm(); +} + +if (!empty($temp)) { + echo $temp; +} +else { + echo $begxml; + echo ' + + + + + + + + '; + echo $endxml; +} +exit; function filecaching_wrapper_hgm( $reset = FALSE ) { global $hgcachexpire; global $hgmenucacheid; global $begxml; global $endxml; - #echo $hgmenucacheid; $cachedfile = file_directory_temp() . '/' . $hgmenucacheid; $lastchanged = filectime( $cachedfile ); - if ( $lastchanged === false or ( time() - $lastchanged > ( $hgcachexpire ) ) ) { - #echo '. 1.... '; - # Cache file does not exist or is too old. - $my_data = $begxml . hypergraph_get_menu( NULL ) . $endxml; - # Now put $my_data to cache! - $fh = fopen( $cachedfile, "w+" ); - fwrite( $fh, $my_data ); - fclose( $fh ); - } else { - #echo '. 2.... '; - # Cache file exists. - $my_data = file_get_contents( $cachedfile ); - } + if ($lastchanged === FALSE || (time() - $lastchanged > $hgcachexpire)) { + $my_data = $begxml . hypergraph_get_menu(NULL) . $endxml; + $fh = fopen( $cachedfile, "w+" ); + fwrite( $fh, $my_data ); + fclose( $fh ); + } + else { + $my_data = file_get_contents( $cachedfile ); + } return $my_data; } -function caching_wrapper_hgm( $reset = FALSE ) { + +function caching_wrapper_hgm($reset = FALSE) { global $hgcachexpire; global $hgmenucacheid; global $begxml; global $endxml; - #echo $hgmenucacheid; static $my_data; - #echo '0.... '; - if ( !isset($my_data) || $reset ) { - if (!$reset && ($cache = cache_get($hgmenucacheid)) && !empty($cache->data)) { - $my_data = $cache->data; - #echo '1.... ';# . $my_data; - } else { - // Do your expensive calculations here, and populate $my_data - // with the correct stuff.. - $my_data = $begxml . hypergraph_get_menu( NULL ) . $endxml; - cache_set($hgmenucacheid, 'cache', $my_data, time() + $hgcachexpire); - } + if (!isset($my_data) || $reset) { + if (!$reset && ($cache = cache_get($hgmenucacheid)) && !empty($cache->data)) { + $my_data = $cache->data; + } + else { + // Do your expensive calculations here, and populate $my_data + // with the correct stuff.. + $my_data = $begxml . hypergraph_get_menu(NULL) . $endxml; + #cache_set($hgmenucacheid, 'cache', $my_data, time() + $hgcachexpire); + } } return $my_data; } -function array_searchRecursive( $needle, $haystack, $strict=false, $path=array() ) { - # http://be2.php.net/manual/en/function.array-search.php - # Searches haystack for needle and returns an array of the key path if it is found in the (multidimensional) array, FALSE otherwise. - # mixed array_searchRecursive ( mixed needle, array haystack [, bool strict[, array path]] ) - if( !is_array($haystack) ) { - return false; - } - foreach( $haystack as $key => $val ) { - if( is_array($val) && $subPath = array_searchRecursive($needle, $val, $strict, $path) ) { - $path = array_merge($path, array($key), $subPath); - return $path; - } elseif( (!$strict && $val == $needle) || ($strict && $val === $needle) ) { - $path[] = $key; - return $path; - } +function array_search_recursive($needle, $haystack, $strict = FALSE, $path = array()) { + if(!is_array($haystack)) { + return FALSE; + } + foreach($haystack as $key => $val) { + if(is_array($val) && $sub_path = array_search_recursive($needle, $val, $strict, $path)) { + $path = array_merge($path, array($key), $sub_path); + return $path; + } + elseif((!$strict && $val == $needle) || ($strict && $val === $needle)) { + $path[] = $key; + return $path; } - return false; + } + return FALSE; } function findepth( $needle, $haystack ) { - $foundepth = 0; - $foundparent = NULL; - $searchparent = false; - do { - $searchparent = array_searchRecursive( $needle, $haystack ); - if ( $searchparent !== false ) { - $foundepth ++; - unset($tempar[$searchparent]); - $needle = $searchparent[0]; - } - #echo '... ' . $foundepth . "\n"; - } while ( $searchparent !== false ); - return $foundepth; - } + $foundepth = 0; + $foundparent = NULL; + $searchparent = FALSE; + do { + $searchparent = array_search_recursive($needle, $haystack); + if ($searchparent !== FALSE) { + $foundepth ++; + unset($tempar[$searchparent]); + $needle = $searchparent[0]; + } + } + while ($searchparent !== FALSE); + return $foundepth; +} function hypergraph_get_menu( $beginfrom ) { - ob_start(); - #print_r( menu_get_menu() ); - $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. - $temparx = $menu['visible']; - $tempar = NULL; - foreach( $temparx as $key=>$value ) { - foreach( $value['children'] as $key2=>$value2 ) { - $tempar[$key][$key2] = $value2; - } - } - #print_r( $tempar ) ; - foreach( $menu['visible'] as $key=>$value ) { - if ( $value['title'] == '' ) { $value['title'] = 'root'; } - echo ''; - if ( $value['path'] <> '' ) { - echo ''; - } - echo '';# . "\n"; - foreach( $value['children'] as $key2=>$value2 ) { - echo '';#\n'; - } - } - #print_r( menu_tree() ); - #print_r( menu_secondary_links() ); - $temp = ob_get_clean(); - return $temp; - } - -# Some people don't have PHP5 yet... - function microtime_float() - { - list($usec, $sec) = explode(" ", microtime()); - return ((float)$usec + (float)$sec); - } - -?> \ No newline at end of file + ob_start(); + $menu = menu_get_menu(); + $temparx = $menu['visible']; + $tempar = NULL; + foreach($temparx as $key => $value) { + foreach($value['children'] as $key2 => $value2) { + $tempar[$key][$key2] = $value2; + } + } + foreach($menu['visible'] as $key => $value) { + if ($value['title'] == '') { + $value['title'] = 'root'; + } + echo ''; + if ($value['path'] != '') { + echo ''; + } + echo ''; + foreach( $value['children'] as $key2=>$value2 ) { + echo '';#\n'; + } + } + $temp = ob_get_clean(); + return $temp; +} + +/** + * PHP 4 compatibility function. + */ +function microtime_float() { + list($usec, $sec) = explode(" ", microtime()); + return ((float)$usec + (float)$sec); +} \ No newline at end of file