first commit

This commit is contained in:
Konstantin
2026-05-30 09:27:58 +03:00
commit de0344d218
2371 changed files with 661486 additions and 0 deletions
@@ -0,0 +1,39 @@
<?php
class ControllerMarketplaceApi extends Controller {
public function index() {
$this->load->language('marketplace/api');
$data['user_token'] = $this->session->data['user_token'];
$this->response->setOutput($this->load->view('marketplace/api', $data));
}
public function save() {
$this->load->language('marketplace/api');
$json = array();
if (!$this->user->hasPermission('modify', 'marketplace/api')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if (!$this->request->post['opencart_username']) {
$json['error']['username'] = $this->language->get('error_username');
}
if (!$this->request->post['opencart_secret']) {
$json['error']['secret'] = $this->language->get('error_secret');
}
if (!$json) {
$this->load->model('setting/setting');
$this->model_setting_setting->editSetting('opencart', $this->request->post);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,260 @@
<?php
class ControllerMarketplaceEvent extends Controller {
private $error = array();
public function index() {
$this->load->language('marketplace/event');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/event');
$this->getList();
}
public function enable() {
$this->load->language('marketplace/event');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/event');
if (isset($this->request->get['event_id']) && $this->validate()) {
$this->model_setting_event->enableEvent($this->request->get['event_id']);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true));
}
$this->getList();
}
public function disable() {
$this->load->language('marketplace/event');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/event');
if (isset($this->request->get['event_id']) && $this->validate()) {
$this->model_setting_event->disableEvent($this->request->get['event_id']);
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true));
}
$this->getList();
}
public function delete() {
$this->load->language('marketplace/event');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('setting/event');
if (isset($this->request->post['selected']) && $this->validate()) {
foreach ($this->request->post['selected'] as $event_id) {
$this->model_setting_event->deleteEvent($event_id);
}
$this->session->data['success'] = $this->language->get('text_success');
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->response->redirect($this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true));
}
$this->getList();
}
public function getList() {
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'code';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url, true)
);
$data['delete'] = $this->url->link('marketplace/event/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
$data['events'] = array();
$filter_data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
'limit' => $this->config->get('config_limit_admin')
);
$event_total = $this->model_setting_event->getTotalEvents();
$results = $this->model_setting_event->getEvents($filter_data);
foreach ($results as $result) {
$data['events'][] = array(
'event_id' => $result['event_id'],
'code' => $result['code'],
'trigger' => $result['trigger'],
'action' => $result['action'],
'sort_order' => $result['sort_order'],
'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
'enable' => $this->url->link('marketplace/event/enable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id'] . $url, true),
'disable' => $this->url->link('marketplace/event/disable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id'] . $url, true),
'enabled' => $result['status']
);
}
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
} else {
$data['error_warning'] = '';
}
if (isset($this->session->data['success'])) {
$data['success'] = $this->session->data['success'];
unset($this->session->data['success']);
} else {
$data['success'] = '';
}
if (isset($this->request->post['selected'])) {
$data['selected'] = (array)$this->request->post['selected'];
} else {
$data['selected'] = array();
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['sort_code'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url, true);
$data['sort_sort_order'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true);
$data['sort_status'] = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, true);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$pagination = new Pagination();
$pagination->total = $event_total;
$pagination->page = $page;
$pagination->limit = $this->config->get('config_limit_admin');
$pagination->url = $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($event_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($event_total - $this->config->get('config_limit_admin'))) ? $event_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $event_total, ceil($event_total / $this->config->get('config_limit_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketplace/event', $data));
}
protected function validate() {
if (!$this->user->hasPermission('modify', 'marketplace/event')) {
$this->error['warning'] = $this->language->get('error_permission');
}
return !$this->error;
}
}
@@ -0,0 +1,57 @@
<?php
class ControllerMarketplaceExtension extends Controller {
private $error = array();
public function index() {
$this->load->language('marketplace/extension');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)
);
$data['user_token'] = $this->session->data['user_token'];
if (isset($this->request->get['type'])) {
$data['type'] = $this->request->get['type'];
} else {
$data['type'] = '';
}
$data['categories'] = array();
$files = glob(DIR_APPLICATION . 'controller/extension/extension/*.php', GLOB_BRACE);
foreach ($files as $file) {
$extension = basename($file, '.php');
// Compatibility code for old extension folders
$this->load->language('extension/extension/' . $extension, 'extension');
if ($this->user->hasPermission('access', 'extension/extension/' . $extension)) {
$files = glob(DIR_APPLICATION . 'controller/extension/' . $extension . '/*.php', GLOB_BRACE);
$data['categories'][] = array(
'code' => $extension,
'text' => $this->language->get('extension')->get('heading_title') . ' (' . count($files) .')',
'href' => $this->url->link('extension/extension/' . $extension, 'user_token=' . $this->session->data['user_token'], true)
);
}
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketplace/extension', $data));
}
}
@@ -0,0 +1,520 @@
<?php
class ControllerMarketplaceInstall extends Controller {
public function install() {
$this->load->language('marketplace/install');
$json = array();
if (isset($this->request->get['extension_install_id'])) {
$extension_install_id = $this->request->get['extension_install_id'];
} else {
$extension_install_id = 0;
}
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
// Make sure the file name is stored in the session.
if (!isset($this->session->data['install'])) {
$json['error'] = $this->language->get('error_file');
} elseif (!is_file(DIR_UPLOAD . $this->session->data['install'] . '.tmp')) {
$json['error'] = $this->language->get('error_file');
}
if (!$json) {
$json['text'] = $this->language->get('text_unzip');
$json['next'] = str_replace('&amp;', '&', $this->url->link('marketplace/install/unzip', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function unzip() {
$this->load->language('marketplace/install');
$json = array();
if (isset($this->request->get['extension_install_id'])) {
$extension_install_id = $this->request->get['extension_install_id'];
} else {
$extension_install_id = 0;
}
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
if (!isset($this->session->data['install'])) {
$json['error'] = $this->language->get('error_file');
} elseif (!is_file(DIR_UPLOAD . $this->session->data['install'] . '.tmp')) {
$json['error'] = $this->language->get('error_file');
}
// Sanitize the filename
if (!$json) {
$file = DIR_UPLOAD . $this->session->data['install'] . '.tmp';
// Unzip the files
$zip = new ZipArchive();
if ($zip->open($file)) {
$zip->extractTo(DIR_UPLOAD . 'tmp-' . $this->session->data['install']);
$zip->close();
} else {
$json['error'] = $this->language->get('error_unzip');
}
// Remove Zip
unlink($file);
$json['text'] = $this->language->get('text_move');
$json['next'] = str_replace('&amp;', '&', $this->url->link('marketplace/install/move', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function move() {
$this->load->language('marketplace/install');
$json = array();
if (isset($this->request->get['extension_install_id'])) {
$extension_install_id = $this->request->get['extension_install_id'];
} else {
$extension_install_id = 0;
}
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
if (!isset($this->session->data['install'])) {
$json['error'] = $this->language->get('error_directory');
} elseif (!is_dir(DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/')) {
$json['error'] = $this->language->get('error_directory');
}
if (!$json) {
$directory = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/';
if (is_dir($directory . 'upload/')) {
$files = array();
// Get a list of files ready to upload
$path = array($directory . 'upload/*');
while (count($path) != 0) {
$next = array_shift($path);
foreach ((array)glob($next) as $file) {
if (is_dir($file)) {
$path[] = $file . '/*';
}
$files[] = $file;
}
}
// A list of allowed directories to be written to
$allowed = array(
'admin/controller/extension/',
'admin/language/',
'admin/model/extension/',
'admin/view/image/',
'admin/view/javascript/',
'admin/view/stylesheet/',
'admin/view/template/extension/',
'catalog/controller/extension/',
'catalog/language/',
'catalog/model/extension/',
'store/view/javascript/',
'store/view/theme/',
'system/config/',
'system/library/',
'image/catalog/'
);
// First we need to do some checks
foreach ($files as $file) {
$destination = str_replace('\\', '/', substr($file, strlen($directory . 'upload/')));
$safe = false;
foreach ($allowed as $value) {
if (strlen($destination) < strlen($value) && substr($value, 0, strlen($destination)) == $destination) {
$safe = true;
break;
}
if (strlen($destination) > strlen($value) && substr($destination, 0, strlen($value)) == $value) {
$safe = true;
break;
}
}
if ($safe) {
// Check if the copy location exists or not
if (substr($destination, 0, 5) == 'admin') {
$destination = DIR_APPLICATION . substr($destination, 6);
}
if (substr($destination, 0, 7) == 'catalog') {
$destination = DIR_CATALOG . substr($destination, 8);
}
if (substr($destination, 0, 5) == 'image') {
$destination = DIR_IMAGE . substr($destination, 6);
}
if (substr($destination, 0, 6) == 'system') {
$destination = DIR_SYSTEM . substr($destination, 7);
}
} else {
$json['error'] = sprintf($this->language->get('error_allowed'), $destination);
break;
}
}
if (!$json) {
$this->load->model('setting/extension');
foreach ($files as $file) {
$destination = str_replace('\\', '/', substr($file, strlen($directory . 'upload/')));
$path = '';
if (substr($destination, 0, 5) == 'admin') {
$path = DIR_APPLICATION . substr($destination, 6);
}
if (substr($destination, 0, 7) == 'catalog') {
$path = DIR_CATALOG . substr($destination, 8);
}
if (substr($destination, 0, 5) == 'image') {
$path = DIR_IMAGE . substr($destination, 6);
}
if (substr($destination, 0, 6) == 'system') {
$path = DIR_SYSTEM . substr($destination, 7);
}
if (is_dir($file) && !is_dir($path)) {
if (mkdir($path, 0777)) {
$this->model_setting_extension->addExtensionPath($extension_install_id, $destination);
}
}
if (is_file($file)) {
if (rename($file, $path)) {
$this->model_setting_extension->addExtensionPath($extension_install_id, $destination);
}
}
}
}
}
}
if (!$json) {
$json['text'] = $this->language->get('text_xml');
$json['next'] = str_replace('&amp;', '&', $this->url->link('marketplace/install/xml', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function xml() {
$this->load->language('marketplace/install');
$json = array();
if (isset($this->request->get['extension_install_id'])) {
$extension_install_id = $this->request->get['extension_install_id'];
} else {
$extension_install_id = 0;
}
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
if (!isset($this->session->data['install'])) {
$json['error'] = $this->language->get('error_directory');
} elseif (!is_dir(DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/')) {
$json['error'] = $this->language->get('error_directory');
}
if (!$json) {
$file = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/install.xml';
if (is_file($file)) {
$this->load->model('setting/modification');
// If xml file just put it straight into the DB
$xml = file_get_contents($file);
if ($xml) {
try {
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXml($xml);
$name = $dom->getElementsByTagName('name')->item(0);
if ($name) {
$name = $name->nodeValue;
} else {
$name = '';
}
$code = $dom->getElementsByTagName('code')->item(0);
if ($code) {
$code = $code->nodeValue;
// Check to see if the modification is already installed or not.
$modification_info = $this->model_setting_modification->getModificationByCode($code);
if ($modification_info) {
$this->model_setting_modification->deleteModification($modification_info['modification_id']);
}
} else {
$json['error'] = $this->language->get('error_code');
}
$author = $dom->getElementsByTagName('author')->item(0);
if ($author) {
$author = $author->nodeValue;
} else {
$author = '';
}
$version = $dom->getElementsByTagName('version')->item(0);
if ($version) {
$version = $version->nodeValue;
} else {
$version = '';
}
$link = $dom->getElementsByTagName('link')->item(0);
if ($link) {
$link = $link->nodeValue;
} else {
$link = '';
}
if (!$json) {
$modification_data = array(
'extension_install_id' => $extension_install_id,
'name' => $name,
'code' => $code,
'author' => $author,
'version' => $version,
'link' => $link,
'xml' => $xml,
'status' => 1
);
$this->model_setting_modification->addModification($modification_data);
}
} catch(Exception $exception) {
$json['error'] = sprintf($this->language->get('error_exception'), $exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine());
}
}
}
}
if (!$json) {
$json['text'] = $this->language->get('text_remove');
$json['next'] = str_replace('&amp;', '&', $this->url->link('marketplace/install/remove', 'user_token=' . $this->session->data['user_token'], true));
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function remove() {
$this->load->language('marketplace/install');
$json = array();
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
if (!isset($this->session->data['install'])) {
$json['error'] = $this->language->get('error_directory');
}
if (!$json) {
$directory = DIR_UPLOAD . 'tmp-' . $this->session->data['install'] . '/';
if (is_dir($directory)) {
// Get a list of files ready to upload
$files = array();
$path = array($directory);
while (count($path) != 0) {
$next = array_shift($path);
// We have to use scandir function because glob will not pick up dot files.
foreach (array_diff(scandir($next), array('.', '..')) as $file) {
$file = $next . '/' . $file;
if (is_dir($file)) {
$path[] = $file;
}
$files[] = $file;
}
}
rsort($files);
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
rmdir($file);
}
}
if (is_dir($directory)) {
rmdir($directory);
}
}
$file = DIR_UPLOAD . $this->session->data['install'] . '.tmp';
if (is_file($file)) {
unlink($file);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
public function uninstall() {
$this->load->language('marketplace/install');
$json = array();
if (isset($this->request->get['extension_install_id'])) {
$extension_install_id = $this->request->get['extension_install_id'];
} else {
$extension_install_id = 0;
}
if (!$this->user->hasPermission('modify', 'marketplace/install')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('setting/extension');
$results = $this->model_setting_extension->getExtensionPathsByExtensionInstallId($extension_install_id);
rsort($results);
foreach ($results as $result) {
$source = '';
// Check if the copy location exists or not
if (substr($result['path'], 0, 5) == 'admin') {
$source = DIR_APPLICATION . substr($result['path'], 6);
}
if (substr($result['path'], 0, 7) == 'catalog') {
$source = DIR_CATALOG . substr($result['path'], 8);
}
if (substr($result['path'], 0, 5) == 'image') {
$source = DIR_IMAGE . substr($result['path'], 6);
}
if (substr($result['path'], 0, 14) == 'system/library') {
$source = DIR_SYSTEM . 'library/' . substr($result['path'], 15);
}
if (is_file($source)) {
unlink($source);
}
if (is_dir($source)) {
// Get a list of files ready to upload
$files = array();
$path = array($source);
while (count($path) != 0) {
$next = array_shift($path);
// We have to use scandir function because glob will not pick up dot files.
foreach (array_diff(scandir($next), array('.', '..')) as $file) {
$file = $next . '/' . $file;
if (is_dir($file)) {
$path[] = $file;
}
$files[] = $file;
}
}
rsort($files);
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
rmdir($file);
}
}
if (is_file($source)) {
unlink($source);
}
if (is_dir($source)) {
rmdir($source);
}
}
$this->model_setting_extension->deleteExtensionPath($result['extension_path_id']);
}
// Remove the install
$this->model_setting_extension->deleteExtensionInstall($extension_install_id);
// Remove any xml modifications
$this->load->model('setting/modification');
$this->model_setting_modification->deleteModificationsByExtensionInstallId($extension_install_id);
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -0,0 +1,172 @@
<?php
class ControllerMarketplaceInstaller extends Controller {
public function index() {
$this->load->language('marketplace/installer');
$this->document->setTitle($this->language->get('heading_title'));
$data['breadcrumbs'] = array();
$data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
);
$data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token'], true)
);
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketplace/installer', $data));
}
public function history() {
$this->load->language('marketplace/installer');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$data['histories'] = array();
$this->load->model('setting/extension');
$results = $this->model_setting_extension->getExtensionInstalls(($page - 1) * 10, 10);
foreach ($results as $result) {
$data['histories'][] = array(
'extension_install_id' => $result['extension_install_id'],
'filename' => $result['filename'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
);
}
$history_total = $this->model_setting_extension->getTotalExtensionInstalls();
$pagination = new Pagination();
$pagination->total = $history_total;
$pagination->page = $page;
$pagination->limit = 10;
$pagination->url = $this->url->link('marketplace/installer/history', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true);
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10));
$this->response->setOutput($this->load->view('marketplace/installer_history', $data));
}
public function upload() {
$this->load->language('marketplace/installer');
$json = array();
// Check user has permission
if (!$this->user->hasPermission('modify', 'marketplace/installer')) {
$json['error'] = $this->language->get('error_permission');
}
// Check if there is a install zip already there
$files = glob(DIR_UPLOAD . '*.tmp');
foreach ($files as $file) {
if (is_file($file) && (filectime($file) < (time() - 5))) {
unlink($file);
}
if (is_file($file)) {
$json['error'] = $this->language->get('error_install');
break;
}
}
// Check for any install directories
$directories = glob(DIR_UPLOAD . 'tmp-*');
foreach ($directories as $directory) {
if (is_dir($directory) && (filectime($directory) < (time() - 5))) {
// Get a list of files ready to upload
$files = array();
$path = array($directory);
while (count($path) != 0) {
$next = array_shift($path);
// We have to use scandir function because glob will not pick up dot files.
foreach (array_diff(scandir($next), array('.', '..')) as $file) {
$file = $next . '/' . $file;
if (is_dir($file)) {
$path[] = $file;
}
$files[] = $file;
}
}
rsort($files);
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
} elseif (is_dir($file)) {
rmdir($file);
}
}
rmdir($directory);
}
if (is_dir($directory)) {
$json['error'] = $this->language->get('error_install');
break;
}
}
if (isset($this->request->files['file']['name'])) {
if (substr($this->request->files['file']['name'], -10) != '.ocmod.zip') {
$json['error'] = $this->language->get('error_filetype');
}
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
}
} else {
$json['error'] = $this->language->get('error_upload');
}
if (!$json) {
$this->session->data['install'] = token(10);
$file = DIR_UPLOAD . $this->session->data['install'] . '.tmp';
move_uploaded_file($this->request->files['file']['tmp_name'], $file);
if (is_file($file)) {
$this->load->model('setting/extension');
$extension_install_id = $this->model_setting_extension->addExtensionInstall($this->request->files['file']['name']);
$json['text'] = $this->language->get('text_install');
$json['next'] = str_replace('&amp;', '&', $this->url->link('marketplace/install/install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_id, true));
} else {
$json['error'] = $this->language->get('error_file');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
<?php
class ControllerMarketplacePromotion extends Controller {
public function index() {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, OPENCARTFORUM_SERVER . 'marketplace/api/promotion?type=' . substr($this->request->get['route'], strrpos($this->request->get['route'], '/') + 1));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$response = curl_exec($curl);
curl_close($curl);
$this->load->helper('HTMLPurifier/Bootstrap');
HTMLPurifier_Bootstrap::registerAutoload();
$config = HTMLPurifier_Config::createDefault();
$response = $this->strip($response, $config);
if ($response) {
return $response;
} else {
return '';
}
}
private function strip($string, $config) {
$purifier = new HTMLPurifier($config);
if (is_array($string)) {
foreach ($string as $k => $v) {
$string[$k] = $this->strip($v, $config); } return $string;
}
return $purifier->purify($string);
}
}