]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - Classes/class-plugin-git.php
Do something about no icons
[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
30
31
32 public function ifInstalledLabel($name, $installed = false)
33 {
34 if ($installed)
35 { ?>
36 <div class="badge rounded-pill badge-success">Installed ✅</div>
37 <?php }
38 else if (Plugins::plugin_exists($name))
39 {
40 ?>
41 <div class="badge rounded-pill badge-success">Installed ✅</div>
42 <?php
43 }
44 }
45
46
47
48 public function do_list()
49 {
50 ?>
51 <div class="row">
52 <?php
53 $counter = 0;
54
55
56 foreach($this->data as $p)
57 {
58 $installed = Plugins::plugin_exists($p->name) ? true : false;
59
60 if (is_string($p))
61 continue;
62
63 // use a default image if there was none
64 $p->icon = $p->icon ?? get_config("base_url")."img/no-image-available.jpg";
65 ?>
66 <!-- Widget for plugins -->
67 <div id="<?php echo $p->name ?>" class="<?php if ($installed) echo "installed " ?>card text-dark bg-light ml-4 mb-3 w-25">
68 <div class="card-header">
69 <div class="font-weight-bold">
70 <div><h5><img class="mr-3" src="<?php echo $p->icon ?>" height="50" width="55">
71 <?php echo $p->title; $this->ifInstalledLabel($p->name); ?></h5></div>
72 </div>
73 </div>
74 <div class="card-body">
75 <h5 class="card-title"><?php echo $p->title ?> <small><code>v<?php echo $p->version ?></code></small></h5>
76 <p class="card-text"><?php echo $p->description ?> </p>
77 </div>
78 <div class="card-footer d-flex justify-content-between align-items-center">
79 <ul class="list-unstyled">
80 <li class="list-item">Author: <a href="<?php echo "mailto:".$p->contact ?? "#" ?>"></li><i><?php echo $p->author ?></i></a>
81 </ul>
82 <div class="btn-group">
83 <div class="btn btn-secondary">More Info</div>
84 <div id="<?php echo $p->name ?>install" class="btn btn-primary">Install</div>
85 </div></div>
86
87 </div>
88 <?php
89 $counter++;
90 if ($counter >= 3) // only do three per row. WARNING: untested due to not having more than 2 plugins atm...
91 {
92 ?>
93 </div>
94 <div class="row"><?php
95 $counter = 0;
96 }
97
98
99 }
100 ?></div>
101 <?php
102 }
103 }
104
105 ?>