]>
Commit | Line | Data |
---|---|---|
1 | <?php | |
2 | define('DEFAULT_PLUGINS_DIR', 'https://api.valware.uk/plugins.list'); | |
3 | ||
4 | class PluginRepo | |
5 | { | |
6 | public $plugins ; | |
7 | public $data; | |
8 | public $err; | |
9 | function __construct($url = DEFAULT_PLUGINS_DIR) | |
10 | { | |
11 | global $config; | |
12 | if (!isset($config['third-party-plugins'])) | |
13 | { | |
14 | $config['third-party-plugins'] = []; | |
15 | } | |
16 | if (empty($config['third-party-plugins'])) | |
17 | { | |
18 | $config['third-party-plugins']['data'] = NULL; | |
19 | $config['third-party-plugins']['timestamp'] = 0; | |
20 | } | |
21 | if (time() - $config['third-party-plugins']['timestamp'] > 200) // Cache for 3.333 minutes lol | |
22 | { | |
23 | // come simba it is taem | |
24 | $curl = curl_init($url); | |
25 | ||
26 | // Set the options | |
27 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return the response instead of printing it | |
28 | curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); // Set the content type to JSON | |
29 | curl_setopt($curl, CURLOPT_USERAGENT, "UnrealIRCd Admin Panel"); // This is Secret Agent UnrealIRCd Admin Panel reporting for doody | |
30 | // Execute the request | |
31 | $response = curl_exec($curl); | |
32 | ||
33 | // Check for errors | |
34 | if ($response === false) | |
35 | $this->err = curl_error($curl); | |
36 | else | |
37 | { | |
38 | $this->data = json_decode($response, false); | |
39 | $config['third-party-plugins']['data'] = $this->data; | |
40 | $config['third-party-plugins']['timestamp'] = time(); | |
41 | write_config('third-party-plugins'); | |
42 | } | |
43 | } | |
44 | else | |
45 | $this->data = $config['third-party-plugins']['data']; | |
46 | ||
47 | } | |
48 | ||
49 | ||
50 | ||
51 | public function ifInstalledLabel($name, $installed = false) | |
52 | { | |
53 | if ($installed) | |
54 | { ?> | |
55 | <div style="margin-left:40px;" class="badge rounded-pill badge-success">✔ Installed</div> | |
56 | <?php } | |
57 | else if (Plugins::plugin_exists($name)) | |
58 | { | |
59 | ?> | |
60 | <div style="margin-left:40px;" class="badge rounded-pill badge-success">✔ Installed</div> | |
61 | <?php | |
62 | } | |
63 | } | |
64 | public function ifCompatible($plugin) | |
65 | { | |
66 | $tok = split(WEBPANEL_VERSION,"-"); | |
67 | $wpversion = $tok[0]; | |
68 | if ($plugin->minver <= $wpversion) | |
69 | { ?> | |
70 | <div style="margin-left:40px;" class="badge rounded-pill badge-info">Compatible</div> | |
71 | <?php } | |
72 | else | |
73 | { ?> | |
74 | <div style="margin-left:40px;" class="badge rounded-pill badge-danger">Incompatible</div> | |
75 | <?php } | |
76 | } | |
77 | ||
78 | ||
79 | ||
80 | public function do_list() | |
81 | { | |
82 | global $config; | |
83 | if ($this->err) | |
84 | die("Could not fetch list.\n"); | |
85 | ||
86 | ?> | |
87 | <div class="row"> | |
88 | <?php | |
89 | foreach($this->data->list as $p) | |
90 | { | |
91 | $tok = split(WEBPANEL_VERSION,"-"); | |
92 | $upgradeRequired = false; | |
93 | $wpversion = $tok[0]; | |
94 | if ($p->minver > $wpversion) | |
95 | $upgradeRequired = true; | |
96 | $installed = in_array($p->name, $config['plugins']) ? true : false; | |
97 | if (is_string($p)) | |
98 | continue; | |
99 | ||
100 | // use a default image if there was none | |
101 | $p->icon = $p->icon ?? get_config("base_url")."img/no-image-available.jpg"; | |
102 | ?> | |
103 | <!-- Widget for plugins --> | |
104 | <div id="<?php echo $p->name ?>" class="<?php if ($installed) echo "installed" ?> plugin-card card text-dark bg-light ml-4 mb-3 w-25" style="min-width:300px"> | |
105 | ||
106 | <!-- Card header --> | |
107 | <div class="card-header"> | |
108 | <div class="media"> | |
109 | <img class="align-self-start mr-3" src="<?php echo $p->icon ?>" height="50" width="55"> | |
110 | <div class="media-body"> | |
111 | <div style="position:relative;float:inline-end"><?php echo $this->ifInstalledLabel($p->name); $this->ifCompatible($p) ?></div> | |
112 | <h4 class="mb-0 mt-0"><?php echo $p->title ?></h4> | |
113 | <small>By <a href="<?php echo "mailto:$p->contact" ?>" target="_blank"><?php echo $p->author ?></a></small> | |
114 | </div> | |
115 | </div> | |
116 | </div> | |
117 | ||
118 | <!-- Card body --> | |
119 | <div class="card-body"> | |
120 | <h6 class="card-title"><?php echo $p->title ?> <small><code>v<?php echo $p->version ?></code></small></h6> | |
121 | <p class="card-text"><?php echo $p->description ?><br><br> </p> | |
122 | </div> | |
123 | ||
124 | <!-- Card footer --> | |
125 | <div class="card-footer d-flex justify-content-between"> | |
126 | <div id="justALonelyEmptyDivCryEmoji"></div> | |
127 | <div> | |
128 | <div id="<?php echo $p->name ?>" class="more-info btn btn-info">More Info</div> | |
129 | <?php if ($upgradeRequired){ | |
130 | ?> | |
131 | <div id="<?php echo $p->name ?>coming-soon" class="btn-coming-soon btn btn-dark disabled">Panel Upgrade Required</div> | |
132 | <?php | |
133 | } | |
134 | ?> | |
135 | <div id="<?php echo $p->name ?>install" <?php if ($upgradeRequired) echo 'style="display:none" '; ?> class="btn-install-plugin btn btn-primary">Install</div> | |
136 | </div> | |
137 | </div> | |
138 | </div> | |
139 | <?php | |
140 | ||
141 | ||
142 | } | |
143 | ?> | |
144 | </div> | |
145 | <i>Want to see your plugin listed here? <a href="https://github.com/unrealircd/unrealircd-webpanel-plugins" target="__blank">Make a pull request to our GitHub Repository</a>!</i> | |
146 | <?php | |
147 | } | |
148 | } | |
149 | ||
150 | ?> |