Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:grapher-php [2020/10/06 07:32] babdev:grapher-php [2020/11/01 15:59] (current) bab
Line 30: Line 30:
             "graph with graphviz. The 'gexf' format is a more complex XML-based format which contains more info ".             "graph with graphviz. The 'gexf' format is a more complex XML-based format which contains more info ".
             "about the found nodes and can be loaded in Gephi. Default: dot",             "about the found nodes and can be loaded in Gephi. Default: dot",
-            'f', 'dot|gexf');+            'f', 'dot|gexf|json');
         $options->registerOption(         $options->registerOption(
             'output',             'output',
Line 58: Line 58:
         }         }
         $format = $options->getOpt('format', 'dot');         $format = $options->getOpt('format', 'dot');
-        if(!in_array($format, array('dot', 'gexf'))) {+        if(!in_array($format, array('dot', 'gexf','json'))) {
             $this->fatal('Bad format option: ' . $format);             $this->fatal('Bad format option: ' . $format);
         }         }
Line 75: Line 75:
         } elseif($format == 'gexf') {         } elseif($format == 'gexf') {
             $this->create_gexf($data, $fh);             $this->create_gexf($data, $fh);
-        } +        } elseif($format == 'json') { 
 +            $this->create_json($data, $fh); 
 + }
         fclose($fh);         fclose($fh);
     }     }
Line 238: Line 239:
             $pages[$pid]['media'] = array_unique($pages[$pid]['media']);             $pages[$pid]['media'] = array_unique($pages[$pid]['media']);
         }         }
-        //var_dump($pages); 
  
         return array('pages' => $pages, 'media' => $media);         return array('pages' => $pages, 'media' => $media);
Line 256: Line 256:
  
         fwrite($fh, "digraph G {\n");         fwrite($fh, "digraph G {\n");
-        fwrite($fh, "concentrate=true; +        fwrite($fh, "labelloc=\"b\";\nlabel=\"Actors of a Persecution - https:\/\/challengepower.info - #FreeAssange\";")   
-//compound=true; +        fwrite($fh, "bgcolor=\"white\";
-//baranksep=1.25; +
-splines=ortho; +
-splines=spline; +
-labelURL=\"https://challengepower.info\"; +
-//fontsize=36; +
-//clusterMode=local; +
-//size=\"12.93,7.28\"; +
-size=\"10,12!\"+
-ratio=compress; +
-rankype=same; +
-rankdir=TB; +
-fixedsize=true; +
-dpi=100; +
-bgcolor=\"white\";+
 node [shape = \"circle\", fontsize=16, color=black, bgcolor=aquamarine]; node [shape = \"circle\", fontsize=16, color=black, bgcolor=aquamarine];
 edge [arrowsize=2, color=black]; edge [arrowsize=2, color=black];
 +root=\"page-the_actors:assange\";
 +
 +subgraph corporations {
 +    \"page-the_actors:corporations:darktrace\"
 + \"page-the_actors:corporations:thales\"
 + \"page-the_actors:corporations:sc_strategy_limited\", 
 + \"page-the_actors:corporations:startfor\",
 + \"page-the_actors:corporations:uc_global_s.l\"
 +}
 +
 +subgraph leaks {
 + \"page-the_actors:leaks:global_intelligences_files\"
 + \"page-the_actors:leaks:spy_files\", 
 + \"page-the_actors:leaks:vault7\"
 +}
 +
 +subgraph countries {
 + \"page-the_actors:ukgov:start\",
 + \"page-the_actors:usgov:start\",
 + \"page-the_actors:sweden:start\",
 + \"page-the_actors:ecuador:start\"
 +
 +}
 \n"); \n");
  
Line 308: Line 317:
         // now create all the links         // now create all the links
         foreach($pages as $id => $page) {         foreach($pages as $id => $page) {
-            foreach($page['links'] as $link) { + for($n=0;$n<count($page['links']);$n++) 
- foreach($page['linklabel'as $label) { +
- fwrite($fh, "    \"page-$id\" -> \"page-$link\" [color=navy;label=\"".$label."\"];\n"); + fwrite($fh, "    \"page-"$id ."\" -> \"page-"$page['links'][$n] ."\" [color=navy;label=\"". $page['linklabel'][$n] ."\"];\n");
- }+
  }  }
-            /* 
-            foreach($page['media'] as $link) { 
-                fwrite($fh, "    \"page-$id\" -> \"media-$link\" [color=firebrick];\n"); 
-            } 
-            */ 
         }         }
         fwrite($fh, "}\n");         fwrite($fh, "}\n");
Line 407: Line 410:
         fwrite($fh, "    </graph>\n");         fwrite($fh, "    </graph>\n");
         fwrite($fh, "</gexf>\n");         fwrite($fh, "</gexf>\n");
 +    
 +   }
 +   
 +    /* Create a JSON representation
 +     */
 +    protected function create_json(&$data, $fh) {
 +        
 +        $pages =& $data['pages'];
 +        $media =& $data['media'];
 + $root_name = array_values($pages)[0]["ns"];  
 +
 +        $output = '{
 +   "root": "'. $root_name .'",
 +   "nodes": ['."\n" ;
 + $i=0;
 +        // create all nodes first
 +        foreach($pages as $id => $item){
 + $i++;
 +            $title = htmlspecialchars($item['title']);
 +            $lang  = htmlspecialchars($item['lang']);
 +            $output .= "{\n";
 +            $output .= '"id" : "'. $id .'",'."\n";
 +            $output .= '"name" : "'. $title .'",'."\n";
 +            $output .= '"value" : "'. $item['size'] .'",'."\n";
 +            $output .= '"type" : "'. substr($item['ns'],4) .'"'."\n";
 +            if (!empty( $item['media'][0]))
 +            {
 + $path = explode (":", $item['media'][0]);
 + $file = count($path );
 + $folder="";
 + for($n=0 ; $n < $file-1 ; $n++)
 + {
 + $folder = $folder . $path[$n] . "/";
 + }
 + $output .= ',"img" : "'. DOKU_INC. "data/media/" . $folder . "300x300-" . $path[$file-1] .'"'."\n";
 + }
 +           // $output .= '"has_conflict" : "'.$id.'"'."\n";
 +           // $output .= '"description" : "'.$id.'"'."\n";
 +            $output .= "}\n";
 +            if ($i <= count($pages)-1) $output .= ',';
 +        
 +        }
 + 
 +        // now create all the edges
 +         $output .= '],
 + "links": ['."\n";
 +
 +        $cnt = 0;
 +        foreach($pages as $id => $page){
 +
 +            foreach($page['links'] as $link){
 + if ($cnt > 0) $output .= ',';
 +
 + $output .= '{
 +   "source": "'. $id . '",
 +   "target": "'. $link . '",
 +   "value": "'. $page["linklabel"][$cnt] .'"
 + }';
 +                $cnt++;
 +            }
 +
 +        }
 +       
 +        
 +        $output .= " ] }";
 +    
 +        fwrite($fh,  $output);
     }     }
  
Line 413: Line 483:
 $grapher = new Grapher(); $grapher = new Grapher();
 $grapher->run(); $grapher->run();
 +
 +
  
  
 </file> </file>
  • dev/grapher-php.1601969533.txt.gz
  • Last modified: 2020/10/06 07:32
  • by bab