]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-plugin-git.php
Update with plugins page
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-plugin-git.php
1 <?php
2 define('DEFAULT_PLUGINS_DIR', 'https://api.dalek.services/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
12
13 // Initialize curl
14 $curl = curl_init($url);
15
16 // Set the options
17 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Return the response instead of printing it
18 curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); // Set the content type to JSON
19 curl_setopt($curl, CURLOPT_USERAGENT, "UnrealIRCd Admin Panel");
20 // Execute the request
21 $response = curl_exec($curl);
22
23 // Check for errors
24 if ($response === false)
25 $this->err = curl_error($curl);
26 else
27 $this->data = json_decode($response, false);
28 }
29 public function ifInstalledLabel($name)
30 {
31 if (Plugins::plugin_exists($name))
32 {
33 ?>
34 <div class="badge rounded-pill badge-success">Installed ✅</div>
35 <?php
36 }
37 }
38 public function do_list()
39 {
40 ?>
41 <div class="row">
42 <?php
43 $counter = 0;
44 foreach($this->data as $p)
45 {
46 if (is_string($p))
47 continue;
48
49 ?>
50 <!-- Widget for plugins -->
51 <div class="card text-dark bg-light ml-4 mb-3 w-25">
52 <div class="card-header">
53 <div class="font-weight-bold">
54 <div><img class="mr-3" src="<?php echo $p->icon?>" height="50" width="55">
55 <?php echo $p->title; $this->ifInstalledLabel($p->name); ?></div>
56 </div>
57 </div>
58 <div class="card-body">
59 <h5 class="card-title"><?php echo $p->title ?></h5>
60 <p class="card-text"><?php echo $p->description ?> </p>
61 </div>
62 <div class="card-footer">
63 Author: <a href="<?php echo "mailto:".$p->contact ?? "#" ?>">
64 <i><?php echo $p->author ?></i></a>
65 <div class="text-right">
66 <div class="btn btn-secondary">More Info</div>
67 <div class="btn btn-primary">Install</div>
68 </div>
69 </div>
70 </div>
71 <?php
72 $counter++;
73 if ($counter >= 3) // only do three per row. WARNING: untested due to not having more than 2 plugins atm...
74 {
75 ?>
76 </div>
77 <div class="row"><?php
78 $counter = 0;
79 }
80 }
81 ?></div>
82 <?php
83 }
84 }