/[drupal]/contributions/modules/sna/common.php
ViewVC logotype

Diff of /contributions/modules/sna/common.php

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

revision 1.2, Thu Aug 17 14:53:04 2006 UTC revision 1.3, Tue Aug 22 11:50:18 2006 UTC
# Line 12  Line 12 
12  /**  /**
13   * The path of data files. This path can be modify trough drupal settings.   * The path of data files. This path can be modify trough drupal settings.
14   */   */
15  define('FILES_PATH', './');  define('FILES_PATH', '/path/to/a/secure/path/');
16  /**  /**
17   * The path to the visualization applet   * The path to the visualization applet
18   */   */
19  define('APPLET_PATH', 'sites/sna.drupaler.net/applet_tryout/');  define('APPLET_PATH', '/modules/sna/applet/');
20  /**  /**
21   * Set the dba_handler   * Set the dba_handler
22   */   */
23  define('DBA_HANDLER', 'gdbm');  define('DBA_HANDLER', 'gdbm');
24    
25    // Set some starting value
26  if (function_exists('variable_get')) {  if (function_exists('variable_get')) {
27    $files_path = variable_get('sna_data_path', FILES_PATH);    $files_path = variable_get('sna_data_path', FILES_PATH);
28    $pic_size = variable_get('sna_pic_size', 300);    $pic_size = variable_get('sna_pic_size', 300);
# Line 47  define('NET_PATH', $files_path . 'my.net Line 49  define('NET_PATH', $files_path . 'my.net
49   * The minimal tree of shortest route - cache   * The minimal tree of shortest route - cache
50   */   */
51  define('CACHE_PATH', $files_path . 'min_trees');  define('CACHE_PATH', $files_path . 'min_trees');
52    /**
53     * It's a very bad idea to rewrite this to FALSE.
54     * If you do not have any dba_handler available in PHP
55     * and you want to try out this module it's a possible
56     * solution to turn this off.
57     */
58    define('SNA_CACHE_ENABLED', TRUE);
59    
60  /**  /**
61   * Possible options: nodes, buddy, stats   * Possible options: nodes, buddy, stats
# Line 166  function vertex_degree($edges, $vertex) Line 175  function vertex_degree($edges, $vertex)
175   * @return boolean In cache or not   * @return boolean In cache or not
176   */   */
177  function is_in_cache($vertex) {  function is_in_cache($vertex) {
178    if (!$db = dba_open(CACHE_PATH, "c", DBA_HANDLER)) {    if (SNA_CACHE_ENABLED) {
179      die("Cannot open database\n");      if (!$db = dba_open(CACHE_PATH, "c", DBA_HANDLER)) {
180          die("Cannot open database\n");
181        }
182        $data = dba_fetch($vertex, $db);
183        dba_close($db);
184        return $data === FALSE ? FALSE : unserialize($data);
185      } else {
186        return FALSE;
187    }    }
   $data = dba_fetch($vertex, $db);  
   dba_close($db);  
   return $data === FALSE ? FALSE : unserialize($data);  
188  }  }
189    
190  /**  /**
# Line 182  function is_in_cache($vertex) { Line 195  function is_in_cache($vertex) {
195   * @return boolean Success or not   * @return boolean Success or not
196  */  */
197  function put_in_cache($vertex, $data) {  function put_in_cache($vertex, $data) {
198    if (!$db = dba_open(CACHE_PATH, "c", DBA_HANDLER)) {    if (SNA_CACHE_ENABLED) {
199      return FALSE;      if (!$db = dba_open(CACHE_PATH, "c", DBA_HANDLER)) {
200    }        return FALSE;
201        }
202    if (!dba_insert($vertex, serialize($data), $db)) {  
203        if (!dba_insert($vertex, serialize($data), $db)) {
204          dba_close($db);
205          return FALSE;
206        }
207      dba_close($db);      dba_close($db);
208      return FALSE;      return TRUE;
209      }
210      else {  // If the caching is off, we imitate that everything works fine.
211        return TRUE;
212    }    }
   dba_close($db);  
   return TRUE;  
213  }  }
214    
215  /**  /**
# Line 347  function compare($a, $b) { Line 365  function compare($a, $b) {
365   *   *
366   */   */
367  function clear_cache() {  function clear_cache() {
368    $db = dba_open(CACHE_PATH, "n", DBA_HANDLER);    if (SNA_CACHE_ENABLED) {
369    dba_close($db);      $db = dba_open(CACHE_PATH, "n", DBA_HANDLER);
370        dba_close($db);
371      }
372  }  }
373    
374  ?>  ?>

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2