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