]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blame - Classes/class-plugin-git.php
Fix plugins
[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">
84 <?php
1815dd1e
VP
85 $counter = 0;
86
87
4074d0d1 88 foreach($this->data->list as $p)
1815dd1e 89 {
74eb7196
VP
90 $tok = split(WEBPANEL_VERSION,"-");
91 $upgradeRequired = false;
92 $wpversion = $tok[0];
93 if ($p->minver > $wpversion)
94 $upgradeRequired = true;
fae5cd15 95 $installed = in_array($p->name, $config['plugins']) ? true : false;
1815dd1e
VP
96 if (is_string($p))
97 continue;
e47cb29f 98
1815dd1e
VP
99 // use a default image if there was none
100 $p->icon = $p->icon ?? get_config("base_url")."img/no-image-available.jpg";
101 ?>
fae5cd15
VP
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">
a3599fda 110 <div style="position:relative;float:inline-end"><?php echo $this->ifInstalledLabel($p->name); $this->ifCompatible($p) ?></div>
fae5cd15 111 <h4 class="mb-0 mt-0"><?php echo $p->title ?></h4>
f2e770d4 112 <small>By <a href="<?php echo "mailto:$p->contact" ?>" target="_blank"><?php echo $p->author ?></a></small>
fae5cd15
VP
113 </div>
114 </div>
1815dd1e 115 </div>
fae5cd15
VP
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>
f2e770d4 120 <p class="card-text"><?php echo $p->description ?><br><br> </p>
1815dd1e 121 </div>
fae5cd15
VP
122
123 <!-- Card footer -->
de0b7a09
VP
124 <div class="card-footer d-flex justify-content-between">
125 <div id="justALonelyEmptyDivCryEmoji"></div>
fae5cd15
VP
126 <div>
127 <div id="<?php echo $p->name ?>" class="more-info btn btn-info">More Info</div>
74eb7196
VP
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>
fae5cd15
VP
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++;
1815dd1e
VP
151
152
fae5cd15
VP
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>
1815dd1e
VP
157 <?php
158 }
e47cb29f 159}
1815dd1e
VP
160
161?>