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