Files
.github
admin
install
pages_template
qrcode
system
autoload
cache
controllers
accounts.php
admin.php
autoload.php
autoload_user.php
bandwidth.php
callback.php
codecanyon.php
community.php
customers.php
dashboard.php
default.php
export.php
home.php
index.html
login.php
logout.php
logs.php
order.php
page.php
pages.php
paymentgateway.php
plugin.php
pluginmanager.php
pool.php
prepaid.php
radius.php
register.php
reports.php
routers.php
services.php
settings.php
voucher.php
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
LICENSE
README.md
composer.json
config.sample.php
favicon.ico
index.php
init.php
update.php
version.json
mitrobill/system/controllers/codecanyon.php

127 lines
4.8 KiB
PHP
Raw Normal View History

2024-01-18 15:41:24 +07:00
<?php
2024-02-26 14:38:04 +07:00
2024-01-18 15:41:24 +07:00
/**
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
_admin();
2024-01-18 17:24:21 +07:00
$ui->assign('_title', 'CodeCanyon.net');
2024-01-18 15:41:24 +07:00
$ui->assign('_system_menu', 'settings');
$plugin_repository = 'https://hotspotbilling.github.io/Plugin-Repository/repository.json';
$action = $routes['1'];
$ui->assign('_admin', $admin);
2024-02-26 14:38:04 +07:00
$cache = File::pathFixer($CACHE_PATH . '/codecanyon.json');
2024-01-18 15:41:24 +07:00
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) {
2024-02-26 14:38:04 +07:00
_alert(Lang::T('You do not have permission to access this page'), 'danger', "dashboard");
2024-01-18 15:41:24 +07:00
}
if (empty($config['envato_token'])) {
r2(U . 'settings/app', 'w', '<a href="' . U . 'settings/app#envato' . '">Envato Personal Access Token</a> is not set');
}
switch ($action) {
case 'install':
2024-02-26 14:38:04 +07:00
if (!is_writeable(File::pathFixer($CACHE_PATH . '/'))) {
2024-01-18 15:41:24 +07:00
r2(U . "codecanyon", 'e', 'Folder system/cache/ is not writable');
}
2024-02-26 14:38:04 +07:00
if (!is_writeable($PLUGIN_PATH)) {
r2(U . "codecanyon", 'e', 'Folder plugin/ is not writable');
2024-01-18 15:41:24 +07:00
}
2024-02-26 14:38:04 +07:00
if (!is_writeable($PAYMENTGATEWAY_PATH)) {
r2(U . "codecanyon", 'e', 'Folder paymentgateway/ is not writable');
2024-01-18 15:41:24 +07:00
}
set_time_limit(-1);
$item_id = $routes['2'];
$tipe = $routes['3'];
$result = Http::getData('https://api.envato.com/v3/market/buyer/download?item_id=' . $item_id, ['Authorization: Bearer ' . $config['envato_token']]);
$json = json_decode($result, true);
if (!isset($json['download_url'])) {
r2(U . 'codecanyon', 'e', 'Failed to get download url. ' . $json['description']);
}
2024-02-26 14:38:04 +07:00
$file = File::pathFixer($CACHE_PATH . '/codecanyon/');
2024-01-18 17:24:21 +07:00
if (!file_exists($file)) {
2024-01-18 15:41:24 +07:00
mkdir($file);
}
$file .= $item_id . '.zip';
if (file_exists($file))
unlink($file);
2024-01-18 17:24:21 +07:00
//download
2024-01-18 15:41:24 +07:00
$fp = fopen($file, 'w+');
$ch = curl_init($json['download_url']);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
2024-01-18 17:24:21 +07:00
//extract
2024-02-26 14:38:04 +07:00
$target = File::pathFixer($CACHE_PATH . '/codecanyon/' . $item_id . '/');
2024-01-18 15:41:24 +07:00
$zip = new ZipArchive();
$zip->open($file);
2024-01-18 17:24:21 +07:00
$zip->extractTo($target);
2024-01-18 15:41:24 +07:00
$zip->close();
2024-01-18 17:24:21 +07:00
//moving
if (file_exists($target . 'plugin')) {
2024-02-26 14:38:04 +07:00
File::copyFolder($target . 'plugin', $PLUGIN_PATH . DIRECTORY_SEPARATOR);
2024-01-18 17:24:21 +07:00
} else if (file_exists($target . 'paymentgateway')) {
2024-02-26 14:38:04 +07:00
File::copyFolder($target . 'paymentgateway', $PAYMENTGATEWAY_PATH . DIRECTORY_SEPARATOR);
2024-01-19 09:08:49 +07:00
} else if (file_exists($target . 'theme')) {
File::copyFolder($target . 'theme', File::pathFixer('ui/themes/'));
2024-01-18 17:24:21 +07:00
}
//Cleaning
File::deleteFolder($target);
unlink($file);
r2(U . "codecanyon", 's', 'Installation success');
2024-01-18 15:41:24 +07:00
case 'reload':
2024-01-18 17:24:21 +07:00
if (file_exists($cache))
unlink($cache);
2024-01-18 15:41:24 +07:00
default:
if (class_exists('ZipArchive')) {
$zipExt = true;
} else {
$zipExt = false;
}
$ui->assign('zipExt', $zipExt);
if (file_exists($cache) && time() - filemtime($cache) < (24 * 60 * 60)) {
$txt = file_get_contents($cache);
$plugins = json_decode($txt, true);
2024-01-18 17:24:21 +07:00
$ui->assign('chached_until', date($config['date_format'] . ' H:i', filemtime($cache) + (24 * 60 * 60)));
2024-01-18 15:41:24 +07:00
if (count($plugins) == 0) {
unlink($cache);
r2(U . 'codecanyon');
}
} else {
$plugins = [];
$page = _get('page', 1);
back:
$result = Http::getData('https://api.envato.com/v3/market/buyer/list-purchases?&page=' . $page, ['Authorization: Bearer ' . $config['envato_token']]);
$items = json_decode($result, true);
if ($items && count($items['results']) > 0) {
foreach ($items['results'] as $item) {
$name = strtolower($item['item']['name']);
2024-01-18 17:24:21 +07:00
if (strpos($name, 'phpnuxbill') !== false) {
$plugins[] = $item;
2024-01-18 15:41:24 +07:00
}
}
$page++;
goto back;
}
2024-01-18 17:24:21 +07:00
if (count($plugins) > 0) {
file_put_contents($cache, json_encode($plugins));
if (file_exists($cache)) {
$ui->assign('chached_until', date($config['date_format'] . ' H:i', filemtime($cache) + (24 * 60 * 60)));
}
2024-01-18 15:41:24 +07:00
}
}
$ui->assign('plugins', $plugins);
$ui->display('codecanyon.tpl');
}