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