lwazi 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ namespace Lwazi\Core\Console;
|
|
|
4
4
|
|
|
5
5
|
use Illuminate\Console\Command;
|
|
6
6
|
use Lwazi\Core\Installer\NavigationCrawler;
|
|
7
|
+
use Lwazi\Core\Services\GraphVisualizer;
|
|
7
8
|
use Illuminate\Support\Facades\Storage;
|
|
8
9
|
|
|
9
10
|
class AnalyzeProjectCommand extends Command
|
|
@@ -36,6 +37,17 @@ class AnalyzeProjectCommand extends Command
|
|
|
36
37
|
$this->info("Analysis complete. Manifest stored at: {$manifestFile}");
|
|
37
38
|
$this->info("Pages discovered: " . count($manifest['nodes']));
|
|
38
39
|
|
|
40
|
+
$this->info("\n" . str_repeat('=', 50));
|
|
41
|
+
$this->info('SITE NAVIGATION GRAPH');
|
|
42
|
+
$this->info(str_repeat('=', 50));
|
|
43
|
+
|
|
44
|
+
$visualizer = new GraphVisualizer();
|
|
45
|
+
$graphOutput = $visualizer->generateAsciiGraph($manifest);
|
|
46
|
+
$this->line($graphOutput);
|
|
47
|
+
|
|
48
|
+
$summaryOutput = $visualizer->generateSummary($manifest);
|
|
49
|
+
$this->line($summaryOutput);
|
|
50
|
+
|
|
39
51
|
return 0;
|
|
40
52
|
}
|
|
41
53
|
}
|
|
@@ -6,6 +6,7 @@ use Illuminate\Console\Command;
|
|
|
6
6
|
use Illuminate\Support\Facades\Artisan;
|
|
7
7
|
use Lwazi\Core\Installer\ProjectAnalyzer;
|
|
8
8
|
use Lwazi\Core\Installer\NavigationCrawler;
|
|
9
|
+
use Lwazi\Core\Services\GraphVisualizer;
|
|
9
10
|
|
|
10
11
|
class SetupCommand extends Command
|
|
11
12
|
{
|
|
@@ -111,7 +112,19 @@ class SetupCommand extends Command
|
|
|
111
112
|
$crawler = new NavigationCrawler($url, true);
|
|
112
113
|
$manifest = $crawler->crawl();
|
|
113
114
|
$crawler->saveManifest();
|
|
115
|
+
|
|
114
116
|
$this->info("Crawled " . count($manifest['nodes']) . " pages.");
|
|
117
|
+
|
|
118
|
+
$this->info("\n" . str_repeat('=', 50));
|
|
119
|
+
$this->info('SITE NAVIGATION GRAPH');
|
|
120
|
+
$this->info(str_repeat('=', 50));
|
|
121
|
+
|
|
122
|
+
$visualizer = new GraphVisualizer();
|
|
123
|
+
$graphOutput = $visualizer->generateAsciiGraph($manifest);
|
|
124
|
+
$this->line($graphOutput);
|
|
125
|
+
|
|
126
|
+
$summaryOutput = $visualizer->generateSummary($manifest);
|
|
127
|
+
$this->line($summaryOutput);
|
|
115
128
|
} catch (\Throwable $e) {
|
|
116
129
|
$this->warn('Website crawling failed: ' . $e->getMessage());
|
|
117
130
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Lwazi\Core\Services;
|
|
4
|
+
|
|
5
|
+
class GraphVisualizer
|
|
6
|
+
{
|
|
7
|
+
public function generateAsciiGraph(array $manifest, int $maxDepth = 3, int $maxChildren = 8): string
|
|
8
|
+
{
|
|
9
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
10
|
+
$nodes = $manifest['nodes'] ?? [];
|
|
11
|
+
$rootUrl = $manifest['root_url'] ?? '';
|
|
12
|
+
|
|
13
|
+
if (empty($adjacency)) {
|
|
14
|
+
return "No graph data available.\n";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$root = $this->normalizeRoot($rootUrl);
|
|
18
|
+
$visited = [];
|
|
19
|
+
$output = "SITE NAVIGATION GRAPH\n";
|
|
20
|
+
$output .= str_repeat('=', 50) . "\n\n";
|
|
21
|
+
$output .= "Root: {$root}\n";
|
|
22
|
+
$output .= "Total pages: " . count($nodes) . "\n";
|
|
23
|
+
$output .= "Total links: " . array_sum(array_map('count', $adjacency)) . "\n";
|
|
24
|
+
$output .= "\n" . str_repeat('-', 50) . "\n\n";
|
|
25
|
+
|
|
26
|
+
$output .= $this->buildTreeAscii($adjacency, $root, 0, $maxDepth, $maxChildren, $visited);
|
|
27
|
+
|
|
28
|
+
return $output;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected function normalizeRoot(string $url): string
|
|
32
|
+
{
|
|
33
|
+
$parts = parse_url($url);
|
|
34
|
+
return ($parts['scheme'] ?? 'http') . '://' . ($parts['host'] ?? $url);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected function buildTreeAscii(
|
|
38
|
+
array $adjacency,
|
|
39
|
+
string $current,
|
|
40
|
+
int $depth,
|
|
41
|
+
int $maxDepth,
|
|
42
|
+
int $maxChildren,
|
|
43
|
+
array &$visited
|
|
44
|
+
): string {
|
|
45
|
+
if ($depth > $maxDepth) {
|
|
46
|
+
return '';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (isset($visited[$current])) {
|
|
50
|
+
return " [loop back]\n";
|
|
51
|
+
}
|
|
52
|
+
$visited[$current] = true;
|
|
53
|
+
|
|
54
|
+
$label = $this->getPageLabel($current);
|
|
55
|
+
$indent = str_repeat(' ', $depth);
|
|
56
|
+
$prefix = $depth === 0 ? '●' : '├';
|
|
57
|
+
$output = "{$indent}{$prefix} {$label}\n";
|
|
58
|
+
|
|
59
|
+
$children = $adjacency[$current] ?? [];
|
|
60
|
+
$childCount = count($children);
|
|
61
|
+
|
|
62
|
+
if ($childCount === 0) {
|
|
63
|
+
return $output;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$displayChildren = array_slice($children, 0, $maxChildren);
|
|
67
|
+
$hasMore = $childCount > $maxChildren;
|
|
68
|
+
|
|
69
|
+
foreach ($displayChildren as $i => $child) {
|
|
70
|
+
$isLast = ($i === count($displayChildren) - 1) && !$hasMore;
|
|
71
|
+
$childIndent = str_repeat(' ', $depth + 1);
|
|
72
|
+
$childPrefix = $isLast ? '└' : '├';
|
|
73
|
+
|
|
74
|
+
$childLabel = $this->getPageLabel($child);
|
|
75
|
+
$output .= "{$childIndent}{$childPrefix}─ {$childLabel}\n";
|
|
76
|
+
|
|
77
|
+
if ($depth < $maxDepth) {
|
|
78
|
+
$output .= $this->buildTreeAscii(
|
|
79
|
+
$adjacency,
|
|
80
|
+
$child,
|
|
81
|
+
$depth + 1,
|
|
82
|
+
$maxDepth,
|
|
83
|
+
$maxChildren,
|
|
84
|
+
$visited
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ($hasMore) {
|
|
90
|
+
$moreIndent = str_repeat(' ', $depth + 1);
|
|
91
|
+
$output .= "{$moreIndent}└─ ... (+" . ($childCount - $maxChildren) . " more)\n";
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return $output;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected function getPageLabel(string $url): string
|
|
98
|
+
{
|
|
99
|
+
$path = parse_url($url, PHP_URL_PATH) ?? '/';
|
|
100
|
+
$path = rtrim($path, '/');
|
|
101
|
+
|
|
102
|
+
if ($path === '' || $path === '/') {
|
|
103
|
+
return '/ (home)';
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
$segments = explode('/', trim($path, '/'));
|
|
107
|
+
$last = end($segments) ?: basename($path);
|
|
108
|
+
|
|
109
|
+
if (strlen($last) > 25) {
|
|
110
|
+
$last = substr($last, 0, 22) . '...';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return '/' . $last;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public function generateSummary(array $manifest): string
|
|
117
|
+
{
|
|
118
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
119
|
+
$nodes = $manifest['nodes'] ?? [];
|
|
120
|
+
|
|
121
|
+
$totalPages = count($nodes);
|
|
122
|
+
$totalLinks = array_sum(array_map('count', $adjacency));
|
|
123
|
+
|
|
124
|
+
$depths = [];
|
|
125
|
+
$this->calculateDepths($adjacency, $this->normalizeRoot($manifest['root_url'] ?? ''), 0, $depths);
|
|
126
|
+
$maxDepth = empty($depths) ? 0 : max($depths);
|
|
127
|
+
|
|
128
|
+
$outdegree = array_map('count', $adjacency);
|
|
129
|
+
$avgLinks = $totalPages > 0 ? round($totalLinks / $totalPages, 1) : 0;
|
|
130
|
+
$maxLinks = empty($outdegree) ? 0 : max($outdegree);
|
|
131
|
+
|
|
132
|
+
$output = "GRAPH SUMMARY\n";
|
|
133
|
+
$output .= str_repeat('=', 40) . "\n";
|
|
134
|
+
$output .= "Pages: {$totalPages}\n";
|
|
135
|
+
$output .= "Links: {$totalLinks}\n";
|
|
136
|
+
$output .= "Avg links: {$avgLinks} per page\n";
|
|
137
|
+
$output .= "Max depth: {$maxDepth}\n";
|
|
138
|
+
$output .= "Max links: {$maxLinks} from one page\n";
|
|
139
|
+
|
|
140
|
+
return $output;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protected function calculateDepths(array $adjacency, string $current, int $depth, array &$depths): void
|
|
144
|
+
{
|
|
145
|
+
$depths[] = $depth;
|
|
146
|
+
|
|
147
|
+
foreach ($adjacency[$current] ?? [] as $child) {
|
|
148
|
+
$this->calculateDepths($adjacency, $child, $depth + 1, $depths);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public function generateLinkList(array $manifest, int $limit = 20): string
|
|
153
|
+
{
|
|
154
|
+
$adjacency = $manifest['adjacency'] ?? [];
|
|
155
|
+
|
|
156
|
+
$output = "TOP LINK CONNECTIONS\n";
|
|
157
|
+
$output .= str_repeat('=', 40) . "\n";
|
|
158
|
+
|
|
159
|
+
$outdegree = [];
|
|
160
|
+
foreach ($adjacency as $from => $links) {
|
|
161
|
+
$outdegree[$from] = count($links);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
arsort($outdegree);
|
|
165
|
+
$top = array_slice($outdegree, 0, $limit, true);
|
|
166
|
+
|
|
167
|
+
foreach ($top as $url => $count) {
|
|
168
|
+
$label = $this->getPageLabel($url);
|
|
169
|
+
$output .= sprintf(" %-30s → %d links\n", $label, $count);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return $output;
|
|
173
|
+
}
|
|
174
|
+
}
|