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

Diff of /contributions/modules/freemind/freemind.module

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

revision 1.2, Sun May 21 12:22:42 2006 UTC revision 1.3, Sat Dec 1 22:00:35 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: freemind.module,v 1.1 2005/12/12 21:32:09 joelguesclin Exp $  // $Id: freemind.module,v 1.51.2.7 2004/12/14 02:00:18 guesclin Exp $
3  /*  /*
4   * Acknowledgments: this module could not have been produced without   * Acknowledgments: this module could not have been produced without
5   * liberal hacking from the taxonomy_dhtml module: thanks to weitzman   * liberal hacking from the taxonomy_dhtml and xml_import modules
6   */   */
7    
8  /*  /*
  * this has been hacked to work with drupal v4.7.0  
  */  
   
 /*  
9   * Module to render vocabularies in freemind node format   * Module to render vocabularies in freemind node format
10   */   */
11  function freemind_format($fr_overview_vocab, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers) {  function freemind_format($fr_overview_vocab, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers) {
# Line 19  function freemind_format($fr_overview_vo Line 15  function freemind_format($fr_overview_vo
15    
16      $tree = taxonomy_get_tree($vocabulary->vid);      $tree = taxonomy_get_tree($vocabulary->vid);
17    
18    // get rid of $type here?
19      $tree_nodes = freemind_inject_nodes($tree, $type);      $tree_nodes = freemind_inject_nodes($tree, $type);
20    
21      $freenodes[$n]["content"] = freemind_render_nodes($tree_nodes, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers);      $freenodes[$n]["content"] = freemind_render_nodes($tree_nodes, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers);
# Line 46  function freemind_get_vocabularies($fr_o Line 43  function freemind_get_vocabularies($fr_o
43  }  }
44    
45  function freemind_menu($may_cache) {  function freemind_menu($may_cache) {
46    global $base_url;
47       $output = "<script type=\"text/javascript\" src=\"".$base_url."/modules/freemind/flashobject.js\"></script>\n";
48       drupal_set_html_head($output);
49    
50    if ($may_cache) {    if ($may_cache) {
51      $items[] = array('path' => 'freemind_map', 'title' => t("create freemind map"),      $items[] = array('path' => 'freemind_map', 'title' => t("create freemind map"),
52      'callback' => 'freemind_page',      'callback' => 'freemind_page',
53      'access' => user_access('download map'),      'access' => user_access('download map'),
54      'weight' => 5,      'weight' => 5,
55      'type' => MENU_NORMAL_ITEM);      'type' => MENU_NORMAL_ITEM);
56        $items[] = array('path' => 'admin/taxonomy/freemind',
57          'title' => t('freemind'),
58          'access' => user_access('administer taxonomy'),
59          'callback' => 'freemind_xml_import_form',
60          'type' => MENU_LOCAL_TASK);
61      $items[] = array('path' => variable_get("freemind_flash",''), 'title' => t("flash map"),      $items[] = array('path' => variable_get("freemind_flash",''), 'title' => t("flash map"),
62      'access' => user_access('access flash map'),      'access' => user_access('access flash map'),
63      'weight' => 5,      'weight' => 5,
# Line 62  function freemind_menu($may_cache) { Line 68  function freemind_menu($may_cache) {
68      'type' => MENU_NORMAL_ITEM);      'type' => MENU_NORMAL_ITEM);
69      return $items;      return $items;
70    }    }
71     else {
72       }
73  }  }
74    
75  /*  /*
# Line 72  function freemind_inject_nodes($tree, $t Line 80  function freemind_inject_nodes($tree, $t
80    // iterate over the tree backwards, so I don't trip on the new items    // iterate over the tree backwards, so I don't trip on the new items
81    for ($i=count($tree)-1; $i>=0 ; $i--) {    for ($i=count($tree)-1; $i>=0 ; $i--) {
82      $term = $tree[$i];      $term = $tree[$i];
83      /* restrict to a single type if given */      /* restrict to a single type if given - should get rid of this since we don't use it*/
84      $type_q = ($type ? " AND n.type = '$type'" : "");      $type_q = ($type ? " AND n.type = '$type'" : "");
85      $result = db_query_range("SELECT n.nid, n.title, n.type, u.uid, u.name FROM {term_node} r LEFT JOIN {node} n ON r.nid = n.nid LEFT JOIN {users} u ON n.uid = u.uid WHERE n.status = '1' $type_q AND r.tid = '$term->tid' ORDER BY n.changed DESC", 0, variable_get("freemind_overview_count", 50));  // Revised the query to get the teaser from the revisions table and remove unnecessary user info
86        $result = db_query_range("SELECT n.nid, n.title, n.type, r.teaser FROM {term_node} t LEFT JOIN {node} n ON t.nid = n.nid LEFT JOIN {node_revisions} r on r.vid = n.vid WHERE n.status = '1'  AND t.tid = '$term->tid' ORDER BY n.changed DESC", 0, variable_get("freemind_overview_count", 50));
87      while ($node = db_fetch_object($result)) {      while ($node = db_fetch_object($result)) {
88        $link = l($node->title, "node/$node->nid", array ("title" => $detail, "class" => "dhtml_node"));        $link = l($node->title, "node/$node->nid", array ("title" => $detail, "class" => "dhtml_node"));
89  // this line modified to include title  // this line modified to include title and teaser
90    // and again to remove the link - this stuff needs tidying up
91        $term_node = (object) array ("nid" => $node->nid, "depth" => $term->depth+1, "link" => $link, "title" => $node->title, "teaser" => $node->teaser);        $term_node = (object) array ("nid" => $node->nid, "depth" => $term->depth+1, "link" => $link, "title" => $node->title, "teaser" => $node->teaser);
92    
93        $part1 = array_slice($tree_node, 0, $i+1);        $part1 = array_slice($tree_node, 0, $i+1);
94        $part2 = array_slice($tree_node, $i+1, count($tree_node));        $part2 = array_slice($tree_node, $i+1, count($tree_node));
95        $part1[] = $term_node;        $part1[] = $term_node;
# Line 97  function freemind_render_desc($desc_var, Line 108  function freemind_render_desc($desc_var,
108    $desc = '';    $desc = '';
109    if ($description != '') {    if ($description != '') {
110      $desc = '<node COLOR="#999999" TEXT="desc" '.($desc_var == 'folded' ? 'FOLDED="true"' : 'FOLDED="false"' ).'><font NAME="Default" SIZE="10"/>';      $desc = '<node COLOR="#999999" TEXT="desc" '.($desc_var == 'folded' ? 'FOLDED="true"' : 'FOLDED="false"' ).'><font NAME="Default" SIZE="10"/>';
111      $desc .= "\r\n";      $output .= "\r\n";
112      $desc .= '<node COLOR="#339900" TEXT="'.freemind_strings($description).'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';      $desc .= '<node COLOR="#339900" TEXT="'.freemind_strings($description).'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';
113      $desc .= "\r\n";      $output .= "\r\n";
114      $desc .= "</node>";      $desc .= "</node>\r\n</node>\r\n";
115      $desc .= "\r\n";      $output .= "\r\n";
     $desc .= "</node>";  
     $desc .= "\r\n";  
116      }      }
117    return $desc;    return $desc;
118    
# Line 115  function freemind_render_desc($desc_var, Line 124  function freemind_render_desc($desc_var,
124  function freemind_spec2hex($str) {  function freemind_spec2hex($str) {
125     $result = '';     $result = '';
126     for($i = 0; $i < strlen($str); $i++) {     for($i = 0; $i < strlen($str); $i++) {
127             if(ord(substr($str, $i, 1)) > 127 || ord(substr($str, $i, 1)) == 10 || ord(substr($str, $i, 1)) == 38){             if(ord(substr($str, $i, 1)) > 127 || ord(substr($str, $i, 1)) == 10){
128                 $result .= '&#x'.bin2hex(substr($str, $i, 1)).';';                 $result .= '&#x'.bin2hex(substr($str, $i, 1)).';';
129             }             }
130             else{             else{
# Line 128  function freemind_spec2hex($str) { Line 137  function freemind_spec2hex($str) {
137  /*  /*
138   * Kill the dubious quotes and double-quotes + desperate efforts to render   * Kill the dubious quotes and double-quotes + desperate efforts to render
139   * even the teasers viewable by stripping all html tags from them + converting   * even the teasers viewable by stripping all html tags from them + converting
140   * all specials characters first out of UTF-8 and then into hex representation!   * all special characters first out of UTF-8 and then into hex representation!
  * NOTE - this requires extension=php_mbstring.dll to be activated in php.ini  
  * This rather roundabout way of doing things is to get around the problem that  
  * PHP "cannot yet handle MBCS (ie UTF-8 in our case) in html_entity_decode"  
141   */   */
142  function freemind_strings($text, $strip_tags = FALSE) {  function freemind_strings($text, $strip_tags = FALSE) {
143         $badwordchars=array(         $badwordchars=array(
# Line 144  function freemind_strings($text, $strip_ Line 150  function freemind_strings($text, $strip_
150                             "&#146;",                             "&#146;",
151                             "&#145;",                             "&#145;",
152                             "&ndash;",                             "&ndash;",
153                               " & "
154                             );                             );
155         $fixedwordchars=array(         $fixedwordchars=array(
156                             "'",                             "'",
# Line 155  function freemind_strings($text, $strip_ Line 162  function freemind_strings($text, $strip_
162                             "'",                             "'",
163                             "'",                             "'",
164                             "-",                             "-",
165                               " &amp; "
166                             );                             );
167         $txt = trim($text);         $txt = trim($text);
168  // All Drupal content is in UTF-8, so convert it to ISO8859-1         $txt = htmlentities($txt,ENT_QUOTES,'UTF-8');
        $txt = mb_convert_encoding($txt, "ISO-8859-1", "UTF-8");  
 // Next, convert any HTML entities that might have slipped through back into ISO-8859-1  
        $txt = html_entity_decode($txt, ENT_QUOTES, 'ISO8859-1');  
 // Then convert the resulting clean ISO string into HTML entities  
        $txt = htmlentities($txt,ENT_QUOTES,'ISO8859-1');  
 // Get rid of all the possible double-quotes and single-quotes  
169         $txt = str_replace($badwordchars,$fixedwordchars,$txt);         $txt = str_replace($badwordchars,$fixedwordchars,$txt);
170  // Now convert all the HTML entities back into ISO8859 'cos Freemind don't like them         $txt = html_entity_decode($txt, ENT_NOQUOTES, 'ISO8859-1');
        $txt = html_entity_decode($txt, ENT_QUOTES, 'ISO8859-1');  
 // Get rid of any HTML or PHP tags that might be hanging about  
171         if ($strip_tags) {$txt = strip_tags($txt);}         if ($strip_tags) {$txt = strip_tags($txt);}
 // And convert all special chars to HEX representation  
172         $txt = freemind_spec2hex($txt);         $txt = freemind_spec2hex($txt);
173         return $txt;         return $txt;
174     }     }
# Line 181  function freemind_render_nodes($tree, $f Line 180  function freemind_render_nodes($tree, $f
180    $desc_var = $fr_description;    $desc_var = $fr_description;
181    $taxlinks = ($fr_taxlinks == 1);    $taxlinks = ($fr_taxlinks == 1);
182    $nodes = ($fr_nodes == 1);    $nodes = ($fr_nodes == 1);
183    $teasers = 0;    $teasers = ($fr_teasers == 1);
184    $old_depth = -1;    $old_depth = -1;
185    $output = "";    $output = "";
186    for ($m = 0; $m < count($tree); $m++) {    for ($m = 0; $m < count($tree); $m++) {
# Line 190  function freemind_render_nodes($tree, $f Line 189  function freemind_render_nodes($tree, $f
189      if ($term->tid) {      if ($term->tid) {
190        $output .= '<node ID="tid_'.$term->tid.($taxlinks ? '" LINK="'.$base_url.'/taxonomy/term/'.$term->tid.'" ': '"' ).' TEXT="'.freemind_strings($term->name).'">';        $output .= '<node ID="tid_'.$term->tid.($taxlinks ? '" LINK="'.$base_url.'/taxonomy/term/'.$term->tid.'" ': '"' ).' TEXT="'.freemind_strings($term->name).'">';
191        $output .= "\r\n";        $output .= "\r\n";
192    // This is where we put the Description indicator for level 3 terms (ie terms with no parents)
193          if ($fr_maptype == 'full') {
194            if ($term->parents[0] == 0) {
195              $output .= '<attribute NAME="Description" VALUE="No"/>';
196              $output .= "\r\n";
197              }
198            }
199        if ($desc_var != 'none') {$output .= freemind_render_desc($desc_var,trim(freemind_strings($term->description)));}        if ($desc_var != 'none') {$output .= freemind_render_desc($desc_var,trim(freemind_strings($term->description)));}
200        $current_tid_depth = $term->depth;        $current_tid_depth = $term->depth;
201        }        }
202      if ($term->nid) {      if ($term->nid) {
203        if ($nodes) {        if ($nodes) {
204  // Stick the node teaser stuff in here  // Stick the node teaser stuff in here - needs checking to see if it works
205          $output .= '<node TEXT="'.freemind_strings($term->title).'" LINK="'.$base_url.'/'.node.'/'.$term->nid.(!$teasers ? '" />' : '" FOLDED="true">');          $output .= '<node ID="nid_'.$term->nid.'" TEXT="'.freemind_strings($term->title).'" LINK="'.$base_url.'/'.node.'/'.$term->nid.(!$teasers ? '" />' : '" FOLDED="true">');
206          if ($teasers) {          if ($teasers) {
207            $output .= '<node COLOR="#339900" TEXT="'.freemind_strings($term->teaser, TRUE).'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/></node>';            $output .= '<node COLOR="#339900" TEXT="'.freemind_strings($term->teaser, TRUE).'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/></node>';
208            $output .= '</node>';            $output .= '</node>';
# Line 222  function freemind_perm() { Line 228  function freemind_perm() {
228    }    }
229    
230  /*  /*
231   * Freemind cron (instantiates hook_cron)   * Freemind cron (instantiates hook_cron) - needs checking to see if it works
232   */   */
233  function freemind_cron() {  function freemind_cron() {
234    if (variable_get("freemind_cron", 0 ) == 1) {    if (variable_get("freemind_cron", 0 ) == 1) {
# Line 390  function freemind_get_map_settings($grou Line 396  function freemind_get_map_settings($grou
396    return $form;    return $form;
397  }  }
398    
399    /*
400     * Create the attributes registry at the beginning of the map
401     */
402    function freemind_attributes_registry() {
403      $att_reg = '<attribute_registry FONT_SIZE="10" SHOW_ATTRIBUTES="selected">';
404      $att_reg .= '<attribute_name NAME="hierarchy" RESTRICTED="true" VISIBLE="true">';
405      $att_reg .= '<attribute_value VALUE="Disabled"/>';
406      $att_reg .= '<attribute_value VALUE="Single"/>';
407      $att_reg .= '<attribute_value VALUE="Multiple"/>';
408      $att_reg .= '</attribute_name>';
409      $att_reg .= '<attribute_name NAME="multiple" RESTRICTED="true" VISIBLE="true">';
410      $att_reg .= '<attribute_value VALUE="Yes"/>';
411      $att_reg .= '<attribute_value VALUE="No"/>';
412      $att_reg .= '</attribute_name>';
413      $att_reg .= '<attribute_name NAME="related" RESTRICTED="true" VISIBLE="true">';
414      $att_reg .= '<attribute_value VALUE="Yes"/>';
415      $att_reg .= '<attribute_value VALUE="No"/>';
416      $att_reg .= '</attribute_name>';
417      $att_reg .= '<attribute_name NAME="Description" RESTRICTED="true">';
418      $att_reg .= '<attribute_value VALUE="Yes"/>';
419      $att_reg .= '<attribute_value VALUE="No"/>';
420      $att_reg .= '</attribute_name>';
421      $att_reg .= '<attribute_name NAME="nodes" RESTRICTED="true" VISIBLE="true">';
422      foreach (node_get_types() as $key => $name) {
423        $att_reg .= '<attribute_value VALUE="'.$key.'"/>';
424        }
425      $att_reg .= '</attribute_name>';
426      $att_reg .= "</attribute_registry>";
427    
428      return $att_reg;
429    }
430    
431  // Format an attribute node  // Format an attribute node
432  function freemind_format_attribute($vid,$attribute,$attribute_val) {  function freemind_format_attribute($vid,$attribute,$attribute_val) {
433  $attr_label = $attribute;  $attr_label = $attribute;
434    $attr = '';
435  switch ($attribute) {  switch ($attribute) {
436    case 'Hierarchy':    case 'hierarchy':
437      switch ($attribute_val) {      switch ($attribute_val) {
438        case 0:        case 0:
439          $attribute .= '-Disabled';          $attribute = 'Disabled';
440          break 2;          break;
441        case 1:        case 1:
442          $attribute .= '-Single';          $attribute = 'Single';
443          break 2;          break;
444        case 2:        case 2:
445          $attribute .= '-Multiple';          $attribute = 'Multiple';
446          break 2;          break;
447        default:        default:
448          $attribute .= '-Unknown';          break;
         break 2;  
449        }        }
450          $attr = '<attribute NAME="'.$attr_label.'" VALUE="'.$attribute.'"/>';
451        break;        break;
452    case 'Multiple':    case 'multiple':
453      switch ($attribute_val) {      switch ($attribute_val) {
454        case 0:        case 0:
455          $attribute .= '-No';          $attribute = 'No';
456          break 2;          break;
457        case 1:        case 1:
458          $attribute .= '-Yes';          $attribute = 'Yes';
459          break 2;          break;
460        default:        default:
461          $attribute .= '-Unknown';          break;
         break 2;  
462       }       }
463         $attr = '<attribute NAME="'.$attr_label.'" VALUE="'.$attribute.'"/>';
464       break;       break;
465    case 'Related':    case 'related':
466      switch ($attribute_val) {      switch ($attribute_val) {
467        case 0:        case 0:
468          $attribute .= '-No';          $attribute = 'No';
469          break 2;          break;
470        case 1:        case 1:
471          $attribute .= '-Yes';          $attribute = 'Yes';
472          break 2;          break;
473        default:        default:
474          $attribute .= '-Unknown';          break;
         break 2;  
475        }        }
476          $attr = '<attribute NAME="'.$attr_label.'" VALUE="'.$attribute.'"/>';
477        break;        break;
478      case 'nodes':
479    //    $attribute = implode(',',$attribute_val);
480        foreach ($attribute_val as $node_type) {
481          $attr .= '<attribute NAME="nodes" VALUE="'.$node_type.'"/>';
482          }
483        break;
484      case 'Description':
485        $attr .= '<node COLOR="#339900" TEXT="'.freemind_strings($attribute_val).'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';
486        $attr .= '<attribute NAME="Description" VALUE="Yes"/>';
487        $attr .= '</node>';
488        break;
489    default:    default:
490      break;      break;
491    }    }
   if ($attribute == 'Description') {  
     $attr  = '<node COLOR="#339900" ID="vid_'.$vid.'_'.$attr_label.'" TEXT="Description" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';  
     $attr .= '<node COLOR="#339900" TEXT="'.$attribute_val.'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';  
     $attr .= '</node>';  
     }  
   else {  
     $attr  = '<node COLOR="#339900" ID="vid_'.$vid.'_'.$attr_label.'" TEXT="'.$attribute.'" STYLE="bubble"><edge COLOR="#999999" WIDTH="thin" STYLE="bezier"/><font NAME="Default" SIZE="10"/>';  
     }  
   $attr .= '</node>';  
492    return $attr;    return $attr;
493    
494  }  }
495  // Format the attributes of a vocabulary for Freemind  // Format the attributes of a vocabulary for Freemind
496  function freemind_format_node_attributes($vid,$hierarchy,$multiple,$related,$desc) {  function freemind_format_node_attributes($vid,$hierarchy,$multiple,$related,$nodes, $desc) {
497    $attribs  = '<node ID="vid_'.$vid.'_attributes" COLOR="#999999" TEXT="attributes" FOLDED="true"><font NAME="Default" SIZE="10"/>';    $attribs = "";
498    $attribs .= freemind_format_attribute($vid,'Hierarchy',$hierarchy);    $attribs .= freemind_format_attribute($vid,'hierarchy',$hierarchy);
499    $attribs .= freemind_format_attribute($vid,'Multiple',$multiple);    $attribs .= freemind_format_attribute($vid,'multiple',$multiple);
500    $attribs .= freemind_format_attribute($vid,'Related',$related);    $attribs .= freemind_format_attribute($vid,'related',$related);
501      $attribs .= freemind_format_attribute($vid,'nodes',$nodes);
502    if (trim($desc) != "") {$attribs .= freemind_format_attribute($vid,'Description',$desc);}    if (trim($desc) != "") {$attribs .= freemind_format_attribute($vid,'Description',$desc);}
   $attribs .= '</node>';  
503    return $attribs;    return $attribs;
504    
505  }  }
# Line 523  function freemind_page() { Line 564  function freemind_page() {
564      $output = drupal_get_form('freemind_map_settings', $form);      $output = drupal_get_form('freemind_map_settings', $form);
565      }      }
566    else {    else {
 //  print "edit<br>";  
 //  print_r($edit);  
 //  print "op<br>";  
 //  print($op);  
 //  print "<br>".FILE_DIRECTORY_TEMP;  
567    $output = variable_get("file_directory_path",'').'/'.variable_get('freemind_path', 'freemind').'/'.$edit['freemind_server_file'];    $output = variable_get("file_directory_path",'').'/'.variable_get('freemind_path', 'freemind').'/'.$edit['freemind_server_file'];
568      if ($edit['freemind_where'] == 'download') {      if ($edit['freemind_where'] == 'download') {
569  // Need to give a non-conflicting temp file name  // Need to give a non-conflicting temp file name
# Line 554  function freemind_build($fr_overview_voc Line 590  function freemind_build($fr_overview_voc
590    $freenodes = freemind_format($fr_overview_vocab, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers);    $freenodes = freemind_format($fr_overview_vocab, $fr_description, $fr_taxlinks, $fr_nodes, $fr_teasers);
591  // write out the Freemind structure  // write out the Freemind structure
592    $mmfile = fopen($file_name, 'w');    $mmfile = fopen($file_name, 'w');
593    fwrite($mmfile, '<map version="0.7.1">');    fwrite($mmfile, '<map version="0.8.1">');
594      if ($fr_maptype == 'full') {
595        fwrite($mmfile, freemind_attributes_registry());
596        }
597    fwrite($mmfile, '<node ID="Drupal_Sitemap" '.($fr_logo == 1 ? 'TEXT="&lt;html&gt;&lt;img src=&quot;'.$base_url.'/modules/freemind/logo.gif&quot;&gt;"' : 'TEXT="'.$fr_server_title.'"').' >');    fwrite($mmfile, '<node ID="Drupal_Sitemap" '.($fr_logo == 1 ? 'TEXT="&lt;html&gt;&lt;img src=&quot;'.$base_url.'/modules/freemind/logo.gif&quot;&gt;"' : 'TEXT="'.$fr_server_title.'"').' >');
598    $vidi = 0;    $vidi = 0;
599    foreach ($freenodes as $freenode) {    foreach ($freenodes as $freenode) {
600      $vidi++;      $vidi++;
601      $vid_pos = ($vidi % 2 != 0) ? 'right' : 'left';      $vid_pos = ($vidi % 2 != 0) ? 'right' : 'left';
602      fwrite($mmfile,'<node ID="vid_'.$freenode['subject-id'].'" TEXT="'.$freenode['subject']. '" POSITION="'.$vid_pos.'">');      fwrite($mmfile,'<node ID="vid_'.$freenode['subject-id'].'" TEXT="'.freemind_strings($freenode['subject']). '" POSITION="'.$vid_pos.'">');
603  // This bit does the attributes for the vocabulary  // This bit does the attributes for the vocabulary
604      if ($fr_maptype == 'full') {      if ($fr_maptype == 'full') {
605         fwrite($mmfile,freemind_format_node_attributes($freenode['subject-id'],$freenode['subject-hierarchy'],$freenode['subject-multiple'],$freenode['subject-related'],$freenode['subject-description']));         fwrite($mmfile,freemind_format_node_attributes($freenode['subject-id'],$freenode['subject-hierarchy'],$freenode['subject-multiple'],$freenode['subject-related'],$freenode['subject-nodes'],$freenode['subject-description']));
606         }         }
607  // get the vocabulary content and put it here  // get the vocabulary content and put it here
608      fwrite($mmfile,$freenode['content']);      fwrite($mmfile,$freenode['content']);
# Line 577  function freemind_build($fr_overview_voc Line 616  function freemind_build($fr_overview_voc
616    fclose($mmfile);    fclose($mmfile);
617    
618  }  }
619    // FROM HERE ON IT IS THE IMPORTING BIT ++++++++++++++++++++++++++++
620    //
621    
622  function freemind_help($section) {  function freemind_load_map_form_submit($form_id, $form_values) {
623    $output ="";    $edit = $_POST['edit'];
624      if ($file = file_check_upload("xml")) {
625        $fd = fopen($file->filepath, "rb");
626        if (!$fd) {
627          $output = '<p>' . t('Vocabulary import failed: file %filename cannot be read.', array('%filename' => "<em>$file->filename</em>")) . "</p>\n";
628        } else {
629          $info = fstat($fd);
630          $len = $info["size"];
631          $text = fread($fd, $len);
632          fclose($fd);
633              $output = '<p>' . t('Loaded file %filename.', array('%filename' => "<i>$file->filename</i>")) . "</p>\n";
634            $test = '';
635          $output .= '<p>The file is '.$len.' bytes : START <br />';
636          $output .= freemind_xml_parse($file->filepath);
637          $output .= 'END';
638        }
639      } else {
640        $output = '<p>' . t('Vocabulary import failed: file was not uploaded.') . "</p>\n";
641      }
642      drupal_set_message("The taxonomy was loaded");
643      print theme("page",$output);
644    }
645    
646    switch ($section) {  /**
647      case 'admin/modules#description':   * freemind_xml_import_form
648        $output = t("Builds a dynamic site map to display using Freemind");   */
649        break;  function freemind_xml_import_form() {
650      case 'admin/help#freemind':  $form["xml"] = array(
651      case 'admin/settings/freemind':    '#type' => 'file',
652        $output = t("This module generates a Freemind representation of this site's taxonomy (a site map). The map can be created on the server or downloaded to the workstation.<br>");    '#title' => "From file",
653        $output .= t("The map can be displayed on the web site using either the Freemind Java applet or a Flash browser. Note that the maps are known to be compatible with Freemind up to 0.8.0 RC4");    '#size' => 50,
654      '#description' => t("Click \"Browse...\" to select a modified Freemind sitemap to upload."),
655      );
656    $form[] = array(
657      '#type' => 'submit',
658      '#value' => t("Load"),
659      );
660    $form['#attributes'] = array('enctype' => 'multipart/form-data');
661    $output = drupal_get_form('freemind_load_map_form', $form);
662    return $output;
663    }
664    /**
665     * Save a term
666     */
667    function freemind_save_tid($term_details) {
668      global $term, $element, $tag, $mkterms, $mkdepth, $freemind_vocab_attributes, $freemind_vocab_desc, $freemind_term, $freemind_term_desc, $freemind_vocab, $freemind_parents, $freemind_last_tid_depth;
669      if (!is_array($term_details)) {
670        $freemind_term = array();
671        $freemind_term['name'] = $term_details;
672        $freemind_term['vid'] = $freemind_vocab['vid'];
673        $mkterms[] = 'In - '.$mkdepth .' Tid - '.$freemind_term['name'].'<br />';
674    // Here we work out whether the Term has a parent
675        if ($mkdepth > 3) {
676    //      if ($freemind_last_tid_depth > $mkdepth) {
677            $freemind_term['parent'] = $freemind_parents[$mkdepth - 1];
678          }
679        if (taxonomy_save_term($freemind_term) == SAVED_NEW) {
680          drupal_set_message(t('Created term %term in vocabulary %vocab.', array('%term' => theme('placeholder', $freemind_term['name']), '%vocab' => theme('placeholder', $freemind_vocab['name']))));
681          $freemind_parents[$mkdepth] = $freemind_term['tid'];
682    //      $freemind_term = array();
683          $freemind_last_tid_depth = $mkdepth;
684          }
685        }
686      else {
687    print("In principle this should not happen!<br/>");
688        }
689    
690    }
691    
692    /**
693     * Associate a node with a term
694     */
695    function freemind_save_nid($nid) {
696      global $term, $element, $tag, $mkterms, $mkdepth, $freemind_vocab_attributes, $freemind_vocab_desc, $freemind_term, $freemind_term_desc, $freemind_vocab, $freemind_parents;
697    
698      taxonomy_node_save($nid, array($freemind_parents[$mkdepth - 1]));
699    
700    }
701    
702    /**
703     * Call-back for the XML parser.
704     */
705    function freemind_xml_element_start($parser, $name, $attributes) {
706      global $term, $element, $tag, $mkterms, $mkdepth, $freemind_vocab_attributes, $freemind_vocab_desc, $freemind_term, $freemind_term_desc, $freemind_vocab, $freemind_parents, $freemind_node_attributes;
707      switch ($name)  {
708       case 'node':
709        $freemind_node_attributes = $attributes;
710        $mkdepth += 1;
711        $mkterms[] = 'SE - '.$mkdepth .' '.$name.' ID - '.$attributes['ID'].' TEXT - '.$attributes['TEXT'].' '.$freemind_global_test.' '.$freemind_term_desc.'<br />';
712        switch ($mkdepth) {
713          case 0:
714            break;
715          case 1:
716          $freemind_global_test = "Global test";
717          $freemind_term_desc = FALSE;
718            break;
719          case 2:
720    // Level 2 is necessarily a new or existing vocabulary
721            if (substr($attributes['ID'],0,4) == 'vid_') {
722              if (taxonomy_del_vocabulary(substr($attributes['ID'],4))) {
723                drupal_set_message(t('Deleted vocabulary %name.', array('%name' => theme('placeholder', $attributes['TEXT']))));
724                }
725              }
726            $freemind_vocab = array();
727            $freemind_vocab['name'] = $attributes['TEXT'];
728    // hierarchy by default - needs adapting - probably could get rid of this line
729            $freemind_vocab['hierarchy'] = 1;
730            if (taxonomy_save_vocabulary($freemind_vocab)) {
731              drupal_set_message(t('Created vocabulary %name.', array('%name' => theme('placeholder', $freemind_vocab['name']))));
732              }
733            else {
734              drupal_set_message(t('Failed to create vocabulary %name.', array('%name' => theme('placeholder', $freemind_vocab['name']))));
735              }
736            break;
737          case 3:
738    // It's a term or a vocabulary description
739              $freemind_vocab['description'] = $attributes['TEXT'];
740              $freemind_term['title'] = $attributes['TEXT'];
741            break;
742           default:  // All values above 3 handled the same
743             if ($freemind_term_desc) {
744    // It's a term description
745               $freemind_term_desc = FALSE;
746               $freemind_term['description'] = $attributes['TEXT'];
747               taxonomy_save_term($freemind_term);
748               }
749    //       elseif (substr($attributes['ID'],0,4) == 'nid_') {
750             elseif (array_key_exists('LINK', $attributes)) {
751    // It's a node
752               freemind_save_nid(end(explode("/", $attributes['LINK'])));
753               }
754             elseif ($attributes['TEXT'] == 'desc') {
755    //It's a term description flag
756               $freemind_term_desc = TRUE;
757               }
758             else {
759    // It's a term
760               freemind_save_tid($attributes['TEXT']);
761               }
762          }
763         break;
764    // The tag is an 'attribute'
765       case 'attribute':
766        $mkterms[] = 'SE - '.$mkdepth .' '.$name.' NAME - '.$attributes['NAME'].' VALUE - '.$attributes['VALUE'].' '.$freemind_global_test.' '.$freemind_term_desc.'<br />';
767        switch ($mkdepth) {
768          case 0:
769            break;
770          case 1:
771            break;
772          case 2:
773    // This is a vocabulary attribute
774            if ($attributes['NAME'] == 'hierarchy') {
775               switch ($attributes['VALUE']) {
776                 case 'disabled':
777                   $freemind_vocab['hierarchy'] = 0;
778                   break;
779                 case 'single':
780                   $freemind_vocab['hierarchy'] = 1;
781                   break;
782                 case 'multiple':
783                   $freemind_vocab['hierarchy'] = 2;
784                   break;
785                 default:
786                   break;
787               }
788              }
789            elseif ($attributes['NAME'] == 'nodes') {
790              $freemind_vocab['nodes'][$attributes['VALUE']] = 1;
791    //        $node_types = explode(",", $attributes['VALUE']);
792    // PHP5 only
793    //        $freemind_vocab['nodes'] = array_combine($node_types, array_fill(0, count($node_types), 1));
794    //        foreach ($node_types as $type) {$nodes[$type] = 1;}
795              }
796            else {
797              $freemind_vocab[$attributes['NAME']] = $attributes['VALUE'] == 'Yes' ? 1 : 0;
798              }
799            taxonomy_save_vocabulary($freemind_vocab);
800            print_r($freemind_vocab);
801            print("<br />");
802            break;
803          case 3:
804    //        If Description is "Yes" then this is a vocabulary description
805            if ($attributes['NAME'] == 'Description' && $attributes['VALUE'] == 'Yes') {
806              $freemind_vocab_desc = TRUE;
807              }
808    //        If Description is "No" then this is a term
809            if ($attributes['NAME'] == 'Description' && $attributes['VALUE'] == 'No') {
810              freemind_save_tid($freemind_term['title']);
811              }
812            break;
813          default:
814            break;
815          }
816        default:
817        break;        break;
818        }
819      $tag = $name;
820    }
821    
822    /**
823     * Call-back for the XML parser.
824     */
825    function freemind_xml_element_end($parser, $name) {
826      global $term, $element, $tag, $mkterms, $mkdepth, $freemind_vocab_attributes, $freemind_vocab_desc, $freemind_term, $freemind_term_desc, $freemind_vocab, $freemind_parents, $freemind_node_attributes;
827      if ($name == 'node') {
828    //    $mkdepth -= 1;
829        $mkterms[] = 'EE - '.$mkdepth .' '.$name.' ID - '.$freemind_node_attributes['ID'].' TEXT - '.$freemind_node_attributes['TEXT'].' '.$freemind_global_test.' '.$freemind_term_desc.'<br />';
830        switch ($mkdepth) {
831          case 1:
832            break;
833          case 2:
834    /*        if (taxonomy_save_vocabulary($freemind_vocab)) {
835              drupal_set_message(t('Created vocabulary %name.', array('%name' => theme('placeholder', $freemind_vocab['name']))));
836              }
837            else {
838              drupal_set_message(t('Failed to create vocabulary %name.', array('%name' => theme('placeholder', $freemind_vocab['name']))));
839              }*/
840            break;
841          case 3:
842            if ($freemind_vocab_desc) {
843              taxonomy_save_vocabulary($freemind_vocab);
844              $freemind_vocab_desc = FALSE;
845              }
846    /*        else {
847              freemind_save_tid($freemind_node_attributes['TEXT']);
848              }*/
849          default:
850        }
851        $mkdepth -= 1;
852    }    }
853    
854    return $output;  }
855    
856    /**
857     * Call-back for the XML parser. This is currently a dummy function
858     */
859    function freemind_xml_element_data($parser, $data) {
860    
861    }
862    
863    //function freemind_xml_parse(&$data, $vid) {
864    function freemind_xml_parse($filedetail) {
865      global $terms, $vocabulary, $mkterms, $mkdepth;
866    
867      // Unset the global variables before we use them:
868      unset($GLOBALS['element'], $GLOBALS['term'], $GLOBALS['tag']);
869      $terms = array();
870      $mkterms = array();
871      $mkdepth = 0;
872      $vocabulary = array();
873            $document = file($filedetail);
874    //  not sure why i didn't use drupal_xml_parser_create here: must be a good reason
875      $xml_parser = xml_parser_create();
876      xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false); //
877      xml_set_element_handler($xml_parser, 'freemind_xml_element_start', 'freemind_xml_element_end');
878      xml_set_character_data_handler($xml_parser, 'freemind_xml_element_data');
879    
880      foreach ($document as $line) {
881        xml_parse($xml_parser, $line);
882      }
883    
884      xml_parser_free($xml_parser);
885      $test = implode(' ', $mkterms);
886      return $test;
887    }
888    
889    /**
890     * Implementation of hook_help().
891     */
892    function freemind_help($section) {
893      switch ($section) {
894        case 'admin/modules#description':
895          return t('Creates Freemind site maps');
896    /*    case 'admin/checkout':
897          return t("Users automatically check-out a document when they load it for modification.  Documents are checked back in once that user migrates to a different page in the system.  Administrators can also check documents back in via content administration.");
898        case 'admin/help#checkout':
899          return t("
900    <h3>Document management</h3>
901    
902    ");*/
903    
904      }
905  }  }
906    
907  ?>  ?>

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

  ViewVC Help
Powered by ViewVC 1.1.2