]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - Classes/class-plugin-git.php
Fix plugins view (they're flex anyway, what was I thinking)
[irc/unrealircd/unrealircd-webpanel.git] / Classes / class-plugin-git.php
CommitLineData
e47cb29f 1<?php
1ce9548d 2 define('DEFAULT_PLUGINS_DIR', 'https://api.valware.uk/plugins.list');
e47cb29f 3
a3599fda
VP
4class 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
fae5cd15 33 {
a3599fda
VP
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');
fae5cd15 38 }
a3599fda
VP
39 }
40 else
41 $this->data = $config['third-party-plugins']['data'];
fae5cd15 42
a3599fda 43 }
1815dd1e
VP
44
45
46
a3599fda
VP
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))
e47cb29f 54 {
a3599fda 55 ?>
fae5cd15 56 <div style="margin-left:40px;" class="badge rounded-pill badge-success">✔ Installed</div>
a3599fda 57 <?php
e47cb29f 58 }
a3599fda
VP
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 { ?>
74eb7196 70 <div style="margin-left:40px;" class="badge rounded-pill badge-danger">Incompatible</div>
a3599fda
VP
71<?php }
72 }
1815dd1e
VP
73
74
75
76 public function do_list()
77 {
fae5cd15
VP
78 global $config;
79 if ($this->err)
80 die("Could not fetch list.\n");
a3599fda 81
fae5cd15
VP
82 ?>
83 <div class="row">
54ee471f 84 <?php
4074d0d1 85 foreach($this->data->list as $p)
1815dd1e 86 {
74eb7196
VP
87 $tok = split(WEBPANEL_VERSION,"-");
88 $upgradeRequired = false;
89 $wpversion = $tok[0];
90 if ($p->minver > $wpversion)
91 $upgradeRequired = true;
fae5cd15 92 $installed = in_array($p->name, $config['plugins']) ? true : false;
1815dd1e
VP
93 if (is_string($p))
94 continue;
e47cb29f 95
1815dd1e
VP
96 // use a default image if there was none
97 $p->icon = $p->icon ?? get_config("base_url")."img/no-image-available.jpg";
98 ?>
fae5cd15
VP
99 <!-- Widget for plugins -->
100 <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">
101
102 <!-- Card header -->
103 <div class="card-header">
104 <div class="media">
105 <img class="align-self-start mr-3" src="<?php echo $p->icon ?>" height="50" width="55">
106 <div class="media-body">
a3599fda 107 <div style="position:relative;float:inline-end"><?php echo $this->ifInstalledLabel($p->name); $this->ifCompatible($p) ?></div>
fae5cd15 108 <h4 class="mb-0 mt-0"><?php echo $p->title ?></h4>
f2e770d4 109 <small>By <a href="<?php echo "mailto:$p->contact" ?>" target="_blank"><?php echo $p->author ?></a></small>
fae5cd15
VP
110 </div>
111 </div>
1815dd1e 112 </div>
fae5cd15
VP
113
114 <!-- Card body -->
115 <div class="card-body">
116 <h6 class="card-title"><?php echo $p->title ?> <small><code>v<?php echo $p->version ?></code></small></h6>
f2e770d4 117 <p class="card-text"><?php echo $p->description ?><br><br> </p>
1815dd1e 118 </div>
fae5cd15
VP
119
120 <!-- Card footer -->
de0b7a09
VP
121 <div class="card-footer d-flex justify-content-between">
122 <div id="justALonelyEmptyDivCryEmoji"></div>
fae5cd15
VP
123 <div>
124 <div id="<?php echo $p->name ?>" class="more-info btn btn-info">More Info</div>
74eb7196
VP
125 <?php if ($upgradeRequired){
126 ?>
127 <div id="<?php echo $p->name ?>coming-soon" class="btn-coming-soon btn btn-dark disabled">Panel Upgrade Required</div>
128 <?php
129 }
130 ?>
131 <div id="<?php echo $p->name ?>install" <?php if ($upgradeRequired) echo 'style="display:none" '; ?> class="btn-install-plugin btn btn-primary">Install</div>
fae5cd15
VP
132 </div>
133 </div>
134 </div>
135 <?php
1815dd1e
VP
136
137
fae5cd15
VP
138 }
139 ?>
140 </div>
141 <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>
1815dd1e
VP
142 <?php
143 }
e47cb29f 144}
1815dd1e
VP
145
146?>