forked from idno/known
-
Notifications
You must be signed in to change notification settings - Fork 0
/
known.php
executable file
·145 lines (125 loc) · 5.41 KB
/
known.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/php -q
<?php
define('KNOWN_CONSOLE', 'true');
// Load external libraries
if (file_exists(dirname(__FILE__) . '/vendor/autoload.php')) {
require_once(dirname(__FILE__) . '/vendor/autoload.php');
} else {
die('Could not find autoload.php, did you run "composer install" ..?');
}
// Load Symfony
global $known_loader;
$known_loader = new \Symfony\Component\ClassLoader\UniversalClassLoader();
$known_loader->register();
/**
* Retrieve the loader
* @return \Symfony\Component\ClassLoader\UniversalClassLoader
*/
function &loader()
{
global $known_loader;
return $known_loader;
}
// Register console namespace
use Symfony\Component\Console\Application;
// Known core namespaces
$known_loader->registerNamespace('Idno', dirname(__FILE__));
$known_loader->registerNamespace('ConsolePlugins', dirname(__FILE__));
// Create new console application
global $console;
$console = new Application('Known Console', \Idno\Core\Version::version());
function &application()
{
global $console;
return $console;
}
// Boot known
try {
$idno = new Idno\Core\Idno();
$account = new Idno\Core\Account();
$admin = new Idno\Core\Admin();
$webfinger = new Idno\Core\Webfinger();
$webmention = new Idno\Core\Webmention();
$pubsubhubbub = new Idno\Core\PubSubHubbub();
} catch (\Exception $e) {
error_log($e->getMessage());
}
// Load any plugin functions
$directory = dirname(__FILE__) . '/ConsolePlugins/';
if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) {
foreach ($scanned_directory as $file) {
if (is_dir($directory . $file)) {
$class = "ConsolePlugins\\$file\\Main";
if (class_exists($class)) {
$c = new $class();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
} else {
$stubclass = "ConsolePlugins\\$file";
$stubclass = str_replace('.php', '', $stubclass);
if (class_exists($stubclass)) {
$c = new $stubclass();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
}
}
}
// Allow regular plugins to contain a ConsoleMain.php
$directory = dirname(__FILE__) . '/IdnoPlugins/';
if ($scanned_directory = array_diff(scandir($directory), array('..', '.'))) {
foreach ($scanned_directory as $file) {
if (is_dir($directory . $file)) {
$class = "IdnoPlugins\\$file\\ConsoleMain";
if (class_exists($class)) {
$c = new $class();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
// See if there's a console subdir, for multiple sub commands
$scanned = @scandir($directory . $file . '/Console/');
if (!empty($scanned) && $scanned_sub_directory = array_diff($scanned, array('..', '.'))) {
foreach ($scanned_sub_directory as $file2) {
$class2 = "IdnoPlugins\\$file\\Console\\$file2";
$class2 = str_replace('.php', '', $class2);
if (class_exists($class2)) {
$c = new $class2();
if ($c instanceof \Idno\Common\ConsolePlugin) {
$console->register($c->getCommand())
->setDescription($c->getDescription())
->setDefinition($c->getParameters())
->setCode([$c, 'execute']);
}
}
}
}
}
}
}
$console
->register('version')
->setDescription(\Idno\Core\Idno::site()->language()->_('Returns the current Known version as defined in version.known'))
->setDefinition([])
->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
$output->writeln(file_get_contents(dirname(__FILE__) . '/version.known'));
$remoteVersion = \Idno\Core\RemoteVersion::build();
if (\Idno\Core\Version::build() < $remoteVersion) {
$version = \Idno\Core\RemoteVersion::version();
$output->writeln(\Idno\Core\Idno::site()->language()->_("WARNING: Your build of Known is behind the latest version from Github (%s - %s). If you're having problems, you may want to try updating to the latest version.\nUpdate now: https://github.com/idno/Known\n", [$version, $remoteVersion]));
}
});
// Run the application
$console->run();