Back to Opencart

File admin\controller\marketplace\marketplace.php

docs/api/source-admin.controller.marketplace.marketplace.html

4.1.0.363.2 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Marketplace; | | 3: | /** | | 4: | * Class Marketplace | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Marketplace | | 7: | */ | | 8: | class Marketplace extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('marketplace/marketplace'); | | 16: | | | 17: | $this->document->setTitle($this->language->get('heading_title')); | | 18: | | | 19: | if (isset($this->request->get['filter_search'])) { | | 20: | $filter_search = (string)$this->request->get['filter_search']; | | 21: | } else { | | 22: | $filter_search = ''; | | 23: | } | | 24: | | | 25: | if (isset($this->request->get['filter_category'])) { | | 26: | $filter_category = (string)$this->request->get['filter_category']; | | 27: | } else { | | 28: | $filter_category = ''; | | 29: | } | | 30: | | | 31: | if (isset($this->request->get['filter_license'])) { | | 32: | $filter_license = (string)$this->request->get['filter_license']; | | 33: | } else { | | 34: | $filter_license = ''; | | 35: | } | | 36: | | | 37: | if (isset($this->request->get['filter_rating'])) { | | 38: | $filter_rating = (int)$this->request->get['filter_rating']; | | 39: | } else { | | 40: | $filter_rating = ''; | | 41: | } | | 42: | | | 43: | if (isset($this->request->get['filter_member_type'])) { | | 44: | $filter_member_type = (string)$this->request->get['filter_member_type']; | | 45: | } else { | | 46: | $filter_member_type = ''; | | 47: | } | | 48: | | | 49: | if (isset($this->request->get['filter_member'])) { | | 50: | $filter_member = (string)$this->request->get['filter_member']; | | 51: | } else { | | 52: | $filter_member = ''; | | 53: | } | | 54: | | | 55: | if (isset($this->request->get['sort'])) { | | 56: | $sort = (string)$this->request->get['sort']; | | 57: | } else { | | 58: | $sort = 'date_modified'; | | 59: | } | | 60: | | | 61: | if (isset($this->request->get['page'])) { | | 62: | $page = (int)$this->request->get['page']; | | 63: | } else { | | 64: | $page = 1; | | 65: | } | | 66: | | | 67: | $url = ''; | | 68: | | | 69: | if (isset($this->request->get['filter_search'])) { | | 70: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 71: | } | | 72: | | | 73: | if (isset($this->request->get['filter_category'])) { | | 74: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 75: | } | | 76: | | | 77: | if (isset($this->request->get['filter_license'])) { | | 78: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 79: | } | | 80: | | | 81: | if (isset($this->request->get['filter_rating'])) { | | 82: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 83: | } | | 84: | | | 85: | if (isset($this->request->get['filter_member_type'])) { | | 86: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 87: | } | | 88: | | | 89: | if (isset($this->request->get['filter_member'])) { | | 90: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 91: | } | | 92: | | | 93: | if (isset($this->request->get['sort'])) { | | 94: | $url .= '&sort=' . $this->request->get['sort']; | | 95: | } | | 96: | | | 97: | if (isset($this->request->get['page'])) { | | 98: | $url .= '&page=' . $this->request->get['page']; | | 99: | } | | 100: | | | 101: | $data['breadcrumbs'] = []; | | 102: | | | 103: | $data['breadcrumbs'][] = [ | | 104: | 'text' => $this->language->get('text_home'), | | 105: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 106: | ]; | | 107: | | | 108: | $data['breadcrumbs'][] = [ | | 109: | 'text' => $this->language->get('heading_title'), | | 110: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url) | | 111: | ]; | | 112: | | | 113: | $time = time(); | | 114: | | | 115: | // We create a hash from the data in a similar method to how amazon does things. | | 116: | $string = 'api/marketplace/list' . "\n"; | | 117: | $string .= $this->config->get('opencart_username') . "\n"; | | 118: | $string .= $this->request->server['HTTP_HOST'] . "\n"; | | 119: | $string .= VERSION . "\n"; | | 120: | $string .= $time . "\n"; | | 121: | | | 122: | $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), true)); | | 123: | | | 124: | $url = '&username=' . urlencode($this->config->get('opencart_username')); | | 125: | $url .= '&domain=' . $this->request->server['HTTP_HOST']; | | 126: | $url .= '&version=' . VERSION; | | 127: | $url .= '&time=' . $time; | | 128: | $url .= '&signature=' . rawurlencode($signature); | | 129: | | | 130: | if (isset($this->request->get['filter_search'])) { | | 131: | $url .= '&filter_search=' . urlencode($this->request->get['filter_search']); | | 132: | } | | 133: | | | 134: | if (isset($this->request->get['filter_category'])) { | | 135: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 136: | } | | 137: | | | 138: | if (isset($this->request->get['filter_license'])) { | | 139: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 140: | } | | 141: | | | 142: | if (isset($this->request->get['filter_rating'])) { | | 143: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 144: | } | | 145: | | | 146: | if (isset($this->request->get['filter_member_type'])) { | | 147: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 148: | } | | 149: | | | 150: | if (isset($this->request->get['filter_member'])) { | | 151: | $url .= '&filter_member=' . urlencode($this->request->get['filter_member']); | | 152: | } | | 153: | | | 154: | if (isset($this->request->get['sort'])) { | | 155: | $url .= '&sort=' . $this->request->get['sort']; | | 156: | } | | 157: | | | 158: | if (isset($this->request->get['page'])) { | | 159: | $url .= '&page=' . $this->request->get['page']; | | 160: | } | | 161: | | | 162: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace' . $url); | | 163: | | | 164: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 165: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 166: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 167: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 168: | curl_setopt($curl, CURLOPT_POST, 1); | | 169: | | | 170: | $response = curl_exec($curl); | | 171: | | | 172: | $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | | 173: | | | 174: | curl_close($curl); | | 175: | | | 176: | $response_info = json_decode($response, true); | | 177: | | | 178: | if (isset($response_info['extension_total'])) { | | 179: | $extension_total = (int)$response_info['extension_total']; | | 180: | } else { | | 181: | $extension_total = 0; | | 182: | } | | 183: | | | 184: | $url = ''; | | 185: | | | 186: | if (isset($this->request->get['filter_search'])) { | | 187: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 188: | } | | 189: | | | 190: | if (isset($this->request->get['filter_category'])) { | | 191: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 192: | } | | 193: | | | 194: | if (isset($this->request->get['filter_license'])) { | | 195: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 196: | } | | 197: | | | 198: | if (isset($this->request->get['filter_rating'])) { | | 199: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 200: | } | | 201: | | | 202: | if (isset($this->request->get['filter_member_type'])) { | | 203: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 204: | } | | 205: | | | 206: | if (isset($this->request->get['filter_member'])) { | | 207: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 208: | } | | 209: | | | 210: | if (isset($this->request->get['sort'])) { | | 211: | $url .= '&sort=' . $this->request->get['sort']; | | 212: | } | | 213: | | | 214: | if (isset($this->request->get['page'])) { | | 215: | $url .= '&page=' . $this->request->get['page']; | | 216: | } | | 217: | | | 218: | $data['promotions'] = []; | | 219: | | | 220: | if ($page == 1 && isset($response_info['promotions'])) { | | 221: | foreach ($response_info['promotions'] as $result) { | | 222: | $data['promotions'][] = [ | | 223: | 'name' => $result['name'], | | 224: | 'description' => $result['description'], | | 225: | 'image' => $result['image'], | | 226: | 'license' => $result['license'], | | 227: | 'price' => $result['price'], | | 228: | 'rating' => $result['rating'], | | 229: | 'rating_total' => $result['rating_total'], | | 230: | 'href' => $this->url->link('marketplace/marketplace.info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . $url) | | 231: | ]; | | 232: | } | | 233: | } | | 234: | | | 235: | $data['extensions'] = []; | | 236: | | | 237: | if (isset($response_info['extensions'])) { | | 238: | foreach ($response_info['extensions'] as $result) { | | 239: | $data['extensions'][] = [ | | 240: | 'name' => $result['name'], | | 241: | 'description' => $result['description'], | | 242: | 'image' => $result['image'], | | 243: | 'license' => $result['license'], | | 244: | 'price' => $result['price'], | | 245: | 'rating' => $result['rating'], | | 246: | 'rating_total' => $result['rating_total'], | | 247: | 'href' => $this->url->link('marketplace/marketplace.info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . $url) | | 248: | ]; | | 249: | } | | 250: | } | | 251: | | | 252: | $data['signature'] = $this->config->get('opencart_username') && $this->config->get('opencart_secret'); | | 253: | | | 254: | if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { | | 255: | $data['error_warning'] = $this->language->get('error_api'); | | 256: | } elseif (isset($response_info['error'])) { | | 257: | $data['error_warning'] = $response_info['error']; | | 258: | } else { | | 259: | $data['error_warning'] = ''; | | 260: | } | | 261: | | | 262: | // Categories | | 263: | $url = ''; | | 264: | | | 265: | if (isset($this->request->get['filter_search'])) { | | 266: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 267: | } | | 268: | | | 269: | if (isset($this->request->get['filter_license'])) { | | 270: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 271: | } | | 272: | | | 273: | if (isset($this->request->get['filter_rating'])) { | | 274: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 275: | } | | 276: | | | 277: | if (isset($this->request->get['filter_member_type'])) { | | 278: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 279: | } | | 280: | | | 281: | if (isset($this->request->get['filter_member'])) { | | 282: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 283: | } | | 284: | | | 285: | if (isset($this->request->get['sort'])) { | | 286: | $url .= '&sort=' . $this->request->get['sort']; | | 287: | } | | 288: | | | 289: | $data['categories'] = []; | | 290: | | | 291: | $data['categories'][] = [ | | 292: | 'text' => $this->language->get('text_all'), | | 293: | 'value' => '', | | 294: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url) | | 295: | ]; | | 296: | | | 297: | $data['categories'][] = [ | | 298: | 'text' => $this->language->get('text_theme'), | | 299: | 'value' => 'theme', | | 300: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=theme' . $url) | | 301: | ]; | | 302: | | | 303: | $data['categories'][] = [ | | 304: | 'text' => $this->language->get('text_marketplace'), | | 305: | 'value' => 'marketplace', | | 306: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=marketplace' . $url) | | 307: | ]; | | 308: | | | 309: | $data['categories'][] = [ | | 310: | 'text' => $this->language->get('text_language'), | | 311: | 'value' => 'language', | | 312: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=language' . $url) | | 313: | ]; | | 314: | | | 315: | $data['categories'][] = [ | | 316: | 'text' => $this->language->get('text_payment'), | | 317: | 'value' => 'payment', | | 318: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=payment' . $url) | | 319: | ]; | | 320: | | | 321: | $data['categories'][] = [ | | 322: | 'text' => $this->language->get('text_shipping'), | | 323: | 'value' => 'shipping', | | 324: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=shipping' . $url) | | 325: | ]; | | 326: | | | 327: | $data['categories'][] = [ | | 328: | 'text' => $this->language->get('text_module'), | | 329: | 'value' => 'module', | | 330: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=module' . $url) | | 331: | ]; | | 332: | | | 333: | $data['categories'][] = [ | | 334: | 'text' => $this->language->get('text_total'), | | 335: | 'value' => 'total', | | 336: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=total' . $url) | | 337: | ]; | | 338: | | | 339: | $data['categories'][] = [ | | 340: | 'text' => $this->language->get('text_feed'), | | 341: | 'value' => 'feed', | | 342: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=feed' . $url) | | 343: | ]; | | 344: | | | 345: | $data['categories'][] = [ | | 346: | 'text' => $this->language->get('text_report'), | | 347: | 'value' => 'report', | | 348: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=report' . $url) | | 349: | ]; | | 350: | | | 351: | $data['categories'][] = [ | | 352: | 'text' => $this->language->get('text_other'), | | 353: | 'value' => 'other', | | 354: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_category=other' . $url) | | 355: | ]; | | 356: | | | 357: | // Licenses | | 358: | $url = ''; | | 359: | | | 360: | if (isset($this->request->get['filter_search'])) { | | 361: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 362: | } | | 363: | | | 364: | if (isset($this->request->get['filter_category'])) { | | 365: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 366: | } | | 367: | | | 368: | if (isset($this->request->get['filter_rating'])) { | | 369: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 370: | } | | 371: | | | 372: | if (isset($this->request->get['filter_member_type'])) { | | 373: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 374: | } | | 375: | | | 376: | if (isset($this->request->get['filter_member'])) { | | 377: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 378: | } | | 379: | | | 380: | if (isset($this->request->get['sort'])) { | | 381: | $url .= '&sort=' . $this->request->get['sort']; | | 382: | } | | 383: | | | 384: | if (isset($this->request->get['page'])) { | | 385: | $url .= '&page=' . $this->request->get['page']; | | 386: | } | | 387: | | | 388: | $data['licenses'] = []; | | 389: | | | 390: | $data['licenses'][] = [ | | 391: | 'text' => $this->language->get('text_all'), | | 392: | 'value' => '', | | 393: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url) | | 394: | ]; | | 395: | | | 396: | $data['licenses'][] = [ | | 397: | 'text' => $this->language->get('text_recommended'), | | 398: | 'value' => 'recommended', | | 399: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=recommended' . $url) | | 400: | ]; | | 401: | | | 402: | $data['licenses'][] = [ | | 403: | 'text' => $this->language->get('text_free'), | | 404: | 'value' => 'free', | | 405: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=free' . $url) | | 406: | ]; | | 407: | | | 408: | $data['licenses'][] = [ | | 409: | 'text' => $this->language->get('text_paid'), | | 410: | 'value' => 'paid', | | 411: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=paid' . $url) | | 412: | ]; | | 413: | | | 414: | $data['licenses'][] = [ | | 415: | 'text' => $this->language->get('text_purchased'), | | 416: | 'value' => 'purchased', | | 417: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_license=purchased' . $url) | | 418: | ]; | | 419: | | | 420: | // Sort | | 421: | $url = ''; | | 422: | | | 423: | if (isset($this->request->get['filter_search'])) { | | 424: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 425: | } | | 426: | | | 427: | if (isset($this->request->get['filter_category'])) { | | 428: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 429: | } | | 430: | | | 431: | if (isset($this->request->get['filter_license'])) { | | 432: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 433: | } | | 434: | | | 435: | if (isset($this->request->get['filter_rating'])) { | | 436: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 437: | } | | 438: | | | 439: | if (isset($this->request->get['filter_member_type'])) { | | 440: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 441: | } | | 442: | | | 443: | if (isset($this->request->get['filter_member'])) { | | 444: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 445: | } | | 446: | | | 447: | $data['sorts'] = []; | | 448: | | | 449: | $data['sorts'][] = [ | | 450: | 'text' => $this->language->get('text_date_modified'), | | 451: | 'value' => 'date_modified', | | 452: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=date_modified') | | 453: | ]; | | 454: | | | 455: | $data['sorts'][] = [ | | 456: | 'text' => $this->language->get('text_date_added'), | | 457: | 'value' => 'date_added', | | 458: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=date_added') | | 459: | ]; | | 460: | | | 461: | $data['sorts'][] = [ | | 462: | 'text' => $this->language->get('text_rating'), | | 463: | 'value' => 'rating', | | 464: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=rating') | | 465: | ]; | | 466: | | | 467: | $data['sorts'][] = [ | | 468: | 'text' => $this->language->get('text_name'), | | 469: | 'value' => 'name', | | 470: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=name') | | 471: | ]; | | 472: | | | 473: | $data['sorts'][] = [ | | 474: | 'text' => $this->language->get('text_price'), | | 475: | 'value' => 'price', | | 476: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&sort=price') | | 477: | ]; | | 478: | | | 479: | // Pagination | | 480: | $url = ''; | | 481: | | | 482: | if (isset($this->request->get['filter_search'])) { | | 483: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 484: | } | | 485: | | | 486: | if (isset($this->request->get['filter_category'])) { | | 487: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 488: | } | | 489: | | | 490: | if (isset($this->request->get['filter_license'])) { | | 491: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 492: | } | | 493: | | | 494: | if (isset($this->request->get['filter_rating'])) { | | 495: | $url .= '&filter_rating=' . $this->request->get['filter_rating']; | | 496: | } | | 497: | | | 498: | if (isset($this->request->get['filter_member_type'])) { | | 499: | $url .= '&filter_member_type=' . $this->request->get['filter_member_type']; | | 500: | } | | 501: | | | 502: | if (isset($this->request->get['filter_member'])) { | | 503: | $url .= '&filter_member=' . $this->request->get['filter_member']; | | 504: | } | | 505: | | | 506: | if (isset($this->request->get['sort'])) { | | 507: | $url .= '&sort=' . $this->request->get['sort']; | | 508: | } | | 509: | | | 510: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 511: | 'total' => $extension_total, | | 512: | 'page' => $page, | | 513: | 'limit' => 12, | | 514: | 'url' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 515: | ]); | | 516: | | | 517: | $data['filter_search'] = $filter_search; | | 518: | $data['filter_category'] = $filter_category; | | 519: | $data['filter_license'] = $filter_license; | | 520: | $data['filter_member_type'] = $filter_member_type; | | 521: | $data['filter_rating'] = $filter_rating; | | 522: | | | 523: | $data['sort'] = $sort; | | 524: | | | 525: | $data['user_token'] = $this->session->data['user_token']; | | 526: | | | 527: | $data['header'] = $this->load->controller('common/header'); | | 528: | $data['column_left'] = $this->load->controller('common/column_left'); | | 529: | $data['footer'] = $this->load->controller('common/footer'); | | 530: | | | 531: | $this->response->setOutput($this->load->view('marketplace/marketplace_list', $data)); | | 532: | } | | 533: | | | 534: | /** | | 535: | * Info | | 536: | * | | 537: | * @return \Opencart\System\Engine\Action|null | | 538: | */ | | 539: | public function info(): ?\Opencart\System\Engine\Action { | | 540: | if (isset($this->request->get['extension_id'])) { | | 541: | $extension_id = (int)$this->request->get['extension_id']; | | 542: | } else { | | 543: | $extension_id = 0; | | 544: | } | | 545: | | | 546: | $time = time(); | | 547: | | | 548: | // We create a hash from the data in a similar method to how amazon does things. | | 549: | $string = 'api/marketplace/info' . "\n"; | | 550: | $string .= $this->config->get('opencart_username') . "\n"; | | 551: | $string .= $this->request->server['HTTP_HOST'] . "\n"; | | 552: | $string .= VERSION . "\n"; | | 553: | $string .= $extension_id . "\n"; | | 554: | $string .= $time . "\n"; | | 555: | | | 556: | $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), true)); | | 557: | | | 558: | $url = '&username=' . urlencode($this->config->get('opencart_username')); | | 559: | $url .= '&domain=' . $this->request->server['HTTP_HOST']; | | 560: | $url .= '&version=' . VERSION; | | 561: | $url .= '&extension_id=' . $extension_id; | | 562: | $url .= '&time=' . $time; | | 563: | $url .= '&signature=' . rawurlencode($signature); | | 564: | | | 565: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/info' . $url); | | 566: | | | 567: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 568: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 569: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 570: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 571: | curl_setopt($curl, CURLOPT_POST, 1); | | 572: | | | 573: | $response = curl_exec($curl); | | 574: | | | 575: | $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | | 576: | | | 577: | curl_close($curl); | | 578: | | | 579: | $response_info = json_decode($response, true); | | 580: | | | 581: | if ($response_info) { | | 582: | $this->load->language('marketplace/marketplace'); | | 583: | | | 584: | $this->document->setTitle($this->language->get('heading_title')); | | 585: | | | 586: | $data['signature'] = $this->config->get('opencart_username') && $this->config->get('opencart_secret'); | | 587: | | | 588: | if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { | | 589: | $data['error_warning'] = $this->language->get('error_api'); | | 590: | } elseif (isset($response_info['error'])) { | | 591: | $data['error_warning'] = $response_info['error']; | | 592: | } else { | | 593: | $data['error_warning'] = ''; | | 594: | } | | 595: | | | 596: | $url = ''; | | 597: | | | 598: | if (isset($this->request->get['filter_search'])) { | | 599: | $url .= '&filter_search=' . $this->request->get['filter_search']; | | 600: | } | | 601: | | | 602: | if (isset($this->request->get['filter_category'])) { | | 603: | $url .= '&filter_category=' . $this->request->get['filter_category']; | | 604: | } | | 605: | | | 606: | if (isset($this->request->get['filter_license'])) { | | 607: | $url .= '&filter_license=' . $this->request->get['filter_license']; | | 608: | } | | 609: | | | 610: | if (isset($this->request->get['filter_username'])) { | | 611: | $url .= '&filter_username=' . $this->request->get['filter_username']; | | 612: | } | | 613: | | | 614: | if (isset($this->request->get['sort'])) { | | 615: | $url .= '&sort=' . $this->request->get['sort']; | | 616: | } | | 617: | | | 618: | if (isset($this->request->get['page'])) { | | 619: | $url .= '&page=' . $this->request->get['page']; | | 620: | } | | 621: | | | 622: | $data['back'] = $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url); | | 623: | | | 624: | $data['breadcrumbs'] = []; | | 625: | | | 626: | $data['breadcrumbs'][] = [ | | 627: | 'text' => $this->language->get('text_home'), | | 628: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 629: | ]; | | 630: | | | 631: | $data['breadcrumbs'][] = [ | | 632: | 'text' => $this->language->get('heading_title'), | | 633: | 'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . $url) | | 634: | ]; | | 635: | | | 636: | $data['banner'] = $response_info['banner']; | | 637: | | | 638: | $data['extension_id'] = (int)$this->request->get['extension_id']; | | 639: | $data['name'] = $response_info['name']; | | 640: | $data['description'] = $response_info['description']; | | 641: | $data['documentation'] = $response_info['documentation']; | | 642: | $data['price'] = $response_info['price']; | | 643: | $data['license'] = $response_info['license']; | | 644: | $data['license_period'] = $response_info['license_period']; | | 645: | $data['purchased'] = $response_info['purchased']; | | 646: | $data['compatibility'] = $response_info['compatibility']; | | 647: | | | 648: | $data['rating'] = $response_info['rating']; | | 649: | $data['rating_total'] = $response_info['rating_total']; | | 650: | | | 651: | $data['downloaded'] = $response_info['downloaded']; | | 652: | $data['sales'] = $response_info['sales']; | | 653: | | | 654: | $data['date_added'] = date($this->language->get('date_format_short'), strtotime($response_info['date_added'])); | | 655: | $data['date_modified'] = date($this->language->get('date_format_short'), strtotime($response_info['date_modified'])); | | 656: | | | 657: | $data['member_username'] = $response_info['member_username']; | | 658: | $data['member_image'] = $response_info['member_image']; | | 659: | $data['member_date_added'] = $response_info['member_date_added']; | | 660: | $data['filter_member'] = $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token'] . '&filter_member=' . $response_info['member_username']); | | 661: | | | 662: | if (isset($response_info['comment_total'])) { | | 663: | $data['comment_total'] = $response_info['comment_total']; | | 664: | } else { | | 665: | $data['comment_total'] = 0; | | 666: | } | | 667: | | | 668: | $data['images'] = []; | | 669: | | | 670: | foreach ($response_info['images'] as $result) { | | 671: | $data['images'][] = [ | | 672: | 'thumb' => $result['thumb'], | | 673: | 'popup' => $result['popup'] | | 674: | ]; | | 675: | } | | 676: | | | 677: | $this->load->model('setting/extension'); | | 678: | | | 679: | $data['downloads'] = []; | | 680: | | | 681: | if ($response_info['downloads']) { | | 682: | $this->session->data['extension_download'][$extension_id] = $response_info['downloads']; | | 683: | } else { | | 684: | $this->session->data['extension_download'][$extension_id] = []; | | 685: | } | | 686: | | | 687: | $this->document->addStyle('view/javascript/jquery/magnific/magnific-popup.css'); | | 688: | $this->document->addScript('view/javascript/jquery/magnific/jquery.magnific-popup.min.js'); | | 689: | | | 690: | $data['user_token'] = $this->session->data['user_token']; | | 691: | | | 692: | $data['header'] = $this->load->controller('common/header'); | | 693: | $data['column_left'] = $this->load->controller('common/column_left'); | | 694: | $data['footer'] = $this->load->controller('common/footer'); | | 695: | | | 696: | $this->response->setOutput($this->load->view('marketplace/marketplace_info', $data)); | | 697: | | | 698: | return null; | | 699: | } else { | | 700: | return new \Opencart\System\Engine\Action('error/not_found'); | | 701: | } | | 702: | } | | 703: | | | 704: | /** | | 705: | * Extension | | 706: | * | | 707: | * @return void | | 708: | */ | | 709: | public function extension(): void { | | 710: | $this->load->language('marketplace/marketplace'); | | 711: | | | 712: | if (isset($this->request->get['extension_id'])) { | | 713: | $extension_id = (int)$this->request->get['extension_id']; | | 714: | } else { | | 715: | $extension_id = 0; | | 716: | } | | 717: | | | 718: | $this->load->model('setting/extension'); | | 719: | | | 720: | $data['downloads'] = []; | | 721: | | | 722: | if (isset($this->session->data['extension_download'][$extension_id])) { | | 723: | $results = $this->session->data['extension_download'][$extension_id]; | | 724: | | | 725: | foreach ($results as $result) { | | 726: | if (substr($result['filename'], -10) == '.ocmod.zip') { | | 727: | $code = basename($result['filename'], '.ocmod.zip'); | | 728: | | | 729: | $install_info = $this->model_setting_extension->getInstallByCode($code); | | 730: | | | 731: | // Download | | 732: | if (!$install_info) { | | 733: | $download = $this->url->link('marketplace/marketplace.download', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&extension_download_id=' . $result['extension_download_id']); | | 734: | } else { | | 735: | $download = ''; | | 736: | } | | 737: | | | 738: | // Install | | 739: | if ($install_info && !$install_info['status']) { | | 740: | $install = $this->url->link('marketplace/installer.install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $install_info['extension_install_id']); | | 741: | } else { | | 742: | $install = ''; | | 743: | } | | 744: | | | 745: | // Uninstall | | 746: | if ($install_info && $install_info['status']) { | | 747: | $uninstall = $this->url->link('marketplace/installer.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $install_info['extension_install_id']); | | 748: | } else { | | 749: | $uninstall = ''; | | 750: | } | | 751: | | | 752: | // Delete | | 753: | if ($install_info && !$install_info['status']) { | | 754: | $delete = $this->url->link('marketplace/installer.delete', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $install_info['extension_install_id']); | | 755: | } else { | | 756: | $delete = ''; | | 757: | } | | 758: | | | 759: | $data['downloads'][] = [ | | 760: | 'name' => $result['name'], | | 761: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), | | 762: | 'download' => $download, | | 763: | 'install' => $install, | | 764: | 'uninstall' => $uninstall, | | 765: | 'delete' => $delete | | 766: | ]; | | 767: | } | | 768: | } | | 769: | } | | 770: | | | 771: | $this->response->setOutput($this->load->view('marketplace/marketplace_extension', $data)); | | 772: | } | | 773: | | | 774: | /** | | 775: | * Purchase | | 776: | * | | 777: | * @return void | | 778: | */ | | 779: | public function purchase(): void { | | 780: | $this->load->language('marketplace/marketplace'); | | 781: | | | 782: | $json = []; | | 783: | | | 784: | if (isset($this->request->get['extension_id'])) { | | 785: | $extension_id = (int)$this->request->get['extension_id']; | | 786: | } else { | | 787: | $extension_id = 0; | | 788: | } | | 789: | | | 790: | if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { | | 791: | $json['error'] = $this->language->get('error_permission'); | | 792: | } | | 793: | | | 794: | if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { | | 795: | $json['error'] = $this->language->get('error_api'); | | 796: | } | | 797: | | | 798: | if (!$this->request->post['pin']) { | | 799: | $json['error'] = $this->language->get('error_pin'); | | 800: | } | | 801: | | | 802: | if (!$json) { | | 803: | $time = time(); | | 804: | | | 805: | // We create a hash from the data in a similar method to how amazon does things. | | 806: | $string = 'api/marketplace/purchase' . "\n"; | | 807: | $string .= $this->config->get('opencart_username') . "\n"; | | 808: | $string .= $this->request->server['HTTP_HOST'] . "\n"; | | 809: | $string .= VERSION . "\n"; | | 810: | $string .= $extension_id . "\n"; | | 811: | $string .= $this->request->post['pin'] . "\n"; | | 812: | $string .= $time . "\n"; | | 813: | | | 814: | $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), true)); | | 815: | | | 816: | $url = '&username=' . urlencode($this->config->get('opencart_username')); | | 817: | $url .= '&domain=' . $this->request->server['HTTP_HOST']; | | 818: | $url .= '&version=' . urlencode(VERSION); | | 819: | $url .= '&extension_id=' . $extension_id; | | 820: | $url .= '&time=' . $time; | | 821: | $url .= '&signature=' . rawurlencode($signature); | | 822: | | | 823: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/purchase' . $url); | | 824: | | | 825: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 826: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 827: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 828: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 829: | | | 830: | $response = curl_exec($curl); | | 831: | | | 832: | curl_close($curl); | | 833: | | | 834: | $response_info = json_decode($response, true); | | 835: | | | 836: | if (isset($response_info['success'])) { | | 837: | // If purchase complete we update the status for all downloads to be available. | | 838: | if (isset($this->session->data['extension_download'][$extension_id])) { | | 839: | $results = $this->session->data['extension_download'][$extension_id]; | | 840: | | | 841: | foreach (array_keys($results) as $key) { | | 842: | $this->session->data['extension_download'][$extension_id][$key]['status'] = 1; | | 843: | } | | 844: | } | | 845: | | | 846: | $json['success'] = $response_info['success']; | | 847: | } elseif (isset($response_info['error'])) { | | 848: | $json['error'] = $response_info['error']; | | 849: | } else { | | 850: | $json['error'] = $this->language->get('error_purchase'); | | 851: | } | | 852: | } | | 853: | | | 854: | $this->response->addHeader('Content-Type: application/json'); | | 855: | $this->response->setOutput(json_encode($json)); | | 856: | } | | 857: | | | 858: | /** | | 859: | * Download | | 860: | * | | 861: | * @return void | | 862: | */ | | 863: | public function download(): void { | | 864: | $this->load->language('marketplace/marketplace'); | | 865: | | | 866: | $json = []; | | 867: | | | 868: | if (isset($this->request->get['extension_id'])) { | | 869: | $extension_id = (int)$this->request->get['extension_id']; | | 870: | } else { | | 871: | $extension_id = 0; | | 872: | } | | 873: | | | 874: | if (isset($this->request->get['extension_download_id'])) { | | 875: | $extension_download_id = (int)$this->request->get['extension_download_id']; | | 876: | } else { | | 877: | $extension_download_id = 0; | | 878: | } | | 879: | | | 880: | if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { | | 881: | $json['error'] = $this->language->get('error_permission'); | | 882: | } | | 883: | | | 884: | if (!$json) { | | 885: | $time = time(); | | 886: | | | 887: | // We create a hash from the data in a similar method to how amazon does things. | | 888: | $string = 'api/marketplace/download' . "\n"; | | 889: | $string .= $this->config->get('opencart_username') . "\n"; | | 890: | $string .= $this->request->server['HTTP_HOST'] . "\n"; | | 891: | $string .= VERSION . "\n"; | | 892: | $string .= $extension_id . "\n"; | | 893: | $string .= $extension_download_id . "\n"; | | 894: | $string .= $time . "\n"; | | 895: | | | 896: | $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), true)); | | 897: | | | 898: | $url = '&username=' . urlencode($this->config->get('opencart_username')); | | 899: | $url .= '&domain=' . $this->request->server['HTTP_HOST']; | | 900: | $url .= '&version=' . urlencode(VERSION); | | 901: | $url .= '&extension_id=' . $extension_id; | | 902: | $url .= '&extension_download_id=' . $extension_download_id; | | 903: | $url .= '&time=' . $time; | | 904: | $url .= '&signature=' . rawurlencode($signature); | | 905: | | | 906: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/download&extension_download_id=' . $extension_download_id . $url); | | 907: | | | 908: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 909: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 910: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 911: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 912: | | | 913: | $response = curl_exec($curl); | | 914: | | | 915: | $response_info = json_decode($response, true); | | 916: | | | 917: | curl_close($curl); | | 918: | | | 919: | if (isset($response_info['download'])) { | | 920: | if (substr($response_info['filename'], -10) == '.ocmod.zip') { | | 921: | $handle = fopen(DIR_STORAGE . 'marketplace/' . $response_info['filename'], 'w'); | | 922: | | | 923: | $download = file_get_contents($response_info['download']); | | 924: | | | 925: | fwrite($handle, $download); | | 926: | | | 927: | fclose($handle); | | 928: | | | 929: | $extension_data = [ | | 930: | 'extension_id' => $extension_id, | | 931: | 'extension_download_id' => $extension_download_id, | | 932: | 'name' => $response_info['name'], | | 933: | 'description' => $response_info['description'] ?? '', | | 934: | 'code' => basename($response_info['filename'], '.ocmod.zip'), | | 935: | 'author' => $response_info['author'], | | 936: | 'version' => $response_info['version'], | | 937: | 'link' => OPENCART_SERVER . 'index.php?route=marketplace/extension.info&extension_id=' . $extension_id | | 938: | ]; | | 939: | | | 940: | $this->load->model('setting/extension'); | | 941: | | | 942: | $json['extension_install_id'] = $this->model_setting_extension->addInstall($extension_data); | | 943: | | | 944: | $json['success'] = $this->language->get('text_success'); | | 945: | } else { | | 946: | $json['redirect'] = $response_info['download']; | | 947: | } | | 948: | } elseif (isset($response_info['error'])) { | | 949: | $json['error'] = $response_info['error']; | | 950: | } else { | | 951: | $json['error'] = $this->language->get('error_download'); | | 952: | } | | 953: | } | | 954: | | | 955: | $this->response->addHeader('Content-Type: application/json'); | | 956: | $this->response->setOutput(json_encode($json)); | | 957: | } | | 958: | | | 959: | /** | | 960: | * Add Comment | | 961: | * | | 962: | * @return void | | 963: | */ | | 964: | public function addComment(): void { | | 965: | $this->load->language('marketplace/marketplace'); | | 966: | | | 967: | $json = []; | | 968: | | | 969: | if (isset($this->request->get['extension_id'])) { | | 970: | $extension_id = (int)$this->request->get['extension_id']; | | 971: | } else { | | 972: | $extension_id = 0; | | 973: | } | | 974: | | | 975: | if (isset($this->request->get['parent_id'])) { | | 976: | $parent_id = (int)$this->request->get['parent_id']; | | 977: | } else { | | 978: | $parent_id = 0; | | 979: | } | | 980: | | | 981: | if (!$this->user->hasPermission('modify', 'marketplace/marketplace')) { | | 982: | $json['error'] = $this->language->get('error_permission'); | | 983: | } | | 984: | | | 985: | if (!$this->config->get('opencart_username') || !$this->config->get('opencart_secret')) { | | 986: | $json['error'] = $this->language->get('error_opencart'); | | 987: | } | | 988: | | | 989: | if (!$json) { | | 990: | $time = time(); | | 991: | | | 992: | // We create a hash from the data in a similar method to how amazon does things. | | 993: | $string = 'api/marketplace/addcomment' . "\n"; | | 994: | $string .= urlencode($this->config->get('opencart_username')) . "\n"; | | 995: | $string .= $this->request->server['HTTP_HOST'] . "\n"; | | 996: | $string .= urlencode(VERSION) . "\n"; | | 997: | $string .= $extension_id . "\n"; | | 998: | $string .= $parent_id . "\n"; | | 999: | $string .= urlencode(base64_encode($this->request->post['comment'])) . "\n"; | | 1000: | $string .= $time . "\n"; | | 1001: | | | 1002: | $signature = base64_encode(hash_hmac('sha1', $string, $this->config->get('opencart_secret'), true)); | | 1003: | | | 1004: | $url = '&username=' . $this->config->get('opencart_username'); | | 1005: | $url .= '&domain=' . $this->request->server['HTTP_HOST']; | | 1006: | $url .= '&version=' . VERSION; | | 1007: | $url .= '&extension_id=' . $extension_id; | | 1008: | $url .= '&parent_id=' . $parent_id; | | 1009: | $url .= '&time=' . $time; | | 1010: | $url .= '&signature=' . rawurlencode($signature); | | 1011: | | | 1012: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/addcomment&extension_id=' . $extension_id . $url); | | 1013: | | | 1014: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 1015: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 1016: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 1017: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 1018: | curl_setopt($curl, CURLOPT_POST, 1); | | 1019: | curl_setopt($curl, CURLOPT_POSTFIELDS, ['comment' => $this->request->post['comment']]); | | 1020: | | | 1021: | $response = curl_exec($curl); | | 1022: | | | 1023: | curl_close($curl); | | 1024: | | | 1025: | $response_info = json_decode($response, true); | | 1026: | | | 1027: | if (isset($response_info['success'])) { | | 1028: | $json['success'] = $response_info['success']; | | 1029: | } elseif (isset($response_info['error'])) { | | 1030: | $json['error'] = $response_info['error']; | | 1031: | } else { | | 1032: | $json['error'] = $this->language->get('error_comment'); | | 1033: | } | | 1034: | } | | 1035: | | | 1036: | $this->response->addHeader('Content-Type: application/json'); | | 1037: | $this->response->setOutput(json_encode($json)); | | 1038: | } | | 1039: | | | 1040: | /** | | 1041: | * Comment | | 1042: | * | | 1043: | * @return void | | 1044: | */ | | 1045: | public function comment(): void { | | 1046: | $this->load->language('marketplace/marketplace'); | | 1047: | | | 1048: | if (isset($this->request->get['extension_id'])) { | | 1049: | $extension_id = (int)$this->request->get['extension_id']; | | 1050: | } else { | | 1051: | $extension_id = 0; | | 1052: | } | | 1053: | | | 1054: | if (isset($this->request->get['page'])) { | | 1055: | $page = (int)$this->request->get['page']; | | 1056: | } else { | | 1057: | $page = 1; | | 1058: | } | | 1059: | | | 1060: | $data['button_more'] = $this->language->get('button_more'); | | 1061: | $data['button_reply'] = $this->language->get('button_reply'); | | 1062: | | | 1063: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/comment&extension_id=' . $extension_id . '&page=' . $page); | | 1064: | | | 1065: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 1066: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 1067: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 1068: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 1069: | | | 1070: | $response = curl_exec($curl); | | 1071: | | | 1072: | curl_close($curl); | | 1073: | | | 1074: | $json = json_decode($response, true); | | 1075: | | | 1076: | $data['comments'] = []; | | 1077: | | | 1078: | if ($json['comments']) { | | 1079: | $results = $json['comments']; | | 1080: | | | 1081: | foreach ($results as $result) { | | 1082: | if ($result['reply_total'] > 5) { | | 1083: | $next = $this->url->link('marketplace/marketplace.reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id'] . '&page=2'); | | 1084: | } else { | | 1085: | $next = ''; | | 1086: | } | | 1087: | | | 1088: | $data['comments'][] = [ | | 1089: | 'extension_comment_id' => $result['extension_comment_id'], | | 1090: | 'member' => $result['member'], | | 1091: | 'image' => $result['image'], | | 1092: | 'comment' => $result['comment'], | | 1093: | 'date_added' => $result['date_added'], | | 1094: | 'reply' => $result['reply'], | | 1095: | 'add' => $this->url->link('marketplace/marketplace.addcomment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id']), | | 1096: | 'refresh' => $this->url->link('marketplace/marketplace.reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $result['extension_comment_id'] . '&page=1'), | | 1097: | 'next' => $next | | 1098: | ]; | | 1099: | } | | 1100: | } | | 1101: | | | 1102: | $comment_total = $json['comment_total']; | | 1103: | | | 1104: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1105: | 'total' => $comment_total, | | 1106: | 'page' => $page, | | 1107: | 'limit' => 20, | | 1108: | 'url' => $this->url->link('marketplace/marketplace.comment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&page={page}') | | 1109: | ]); | | 1110: | | | 1111: | $data['refresh'] = $this->url->link('marketplace/marketplace.comment', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&page=' . $page); | | 1112: | | | 1113: | $this->response->setOutput($this->load->view('marketplace/marketplace_comment', $data)); | | 1114: | } | | 1115: | | | 1116: | /** | | 1117: | * Reply | | 1118: | * | | 1119: | * @return void | | 1120: | */ | | 1121: | public function reply(): void { | | 1122: | $this->load->language('marketplace/marketplace'); | | 1123: | | | 1124: | if (isset($this->request->get['extension_id'])) { | | 1125: | $extension_id = (int)$this->request->get['extension_id']; | | 1126: | } else { | | 1127: | $extension_id = 0; | | 1128: | } | | 1129: | | | 1130: | if (isset($this->request->get['parent_id'])) { | | 1131: | $parent_id = (int)$this->request->get['parent_id']; | | 1132: | } else { | | 1133: | $parent_id = 0; | | 1134: | } | | 1135: | | | 1136: | if (isset($this->request->get['page'])) { | | 1137: | $page = (int)$this->request->get['page']; | | 1138: | } else { | | 1139: | $page = 1; | | 1140: | } | | 1141: | | | 1142: | $curl = curl_init(OPENCART_SERVER . 'index.php?route=api/marketplace/comment&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . $page); | | 1143: | | | 1144: | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | | 1145: | curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); | | 1146: | curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); | | 1147: | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | | 1148: | | | 1149: | $response = curl_exec($curl); | | 1150: | | | 1151: | $json = json_decode($response, true); | | 1152: | | | 1153: | $data['replies'] = []; | | 1154: | | | 1155: | if (isset($json['reply_total'])) { | | 1156: | $reply_total = $json['reply_total']; | | 1157: | } else { | | 1158: | $reply_total = 0; | | 1159: | } | | 1160: | | | 1161: | if (isset($json['replies'])) { | | 1162: | $results = $json['replies']; | | 1163: | | | 1164: | foreach ($results as $result) { | | 1165: | $data['replies'][] = [ | | 1166: | 'extension_comment_id' => $result['extension_comment_id'], | | 1167: | 'member' => $result['member'], | | 1168: | 'image' => $result['image'], | | 1169: | 'comment' => $result['comment'], | | 1170: | 'date_added' => $result['date_added'] | | 1171: | ]; | | 1172: | } | | 1173: | } | | 1174: | | | 1175: | $data['refresh'] = $this->url->link('marketplace/marketplace.reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . $page); | | 1176: | | | 1177: | if (($page * 5) < $reply_total) { | | 1178: | $data['next'] = $this->url->link('marketplace/marketplace.reply', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $extension_id . '&parent_id=' . $parent_id . '&page=' . ($page + 1)); | | 1179: | } else { | | 1180: | $data['next'] = ''; | | 1181: | } | | 1182: | | | 1183: | $this->response->setOutput($this->load->view('marketplace/marketplace_reply', $data)); | | 1184: | } | | 1185: | } | | 1186: | |

OpenCart API API documentation generated by ApiGen dev-master