Plugin Directory

Changeset 1914965


Ignore:
Timestamp:
07/25/2018 07:20:52 PM (8 years ago)
Author:
2kblater.com
Message:

v1.1.0

Location:
2kb-amazon-dropship-manager/trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • 2kb-amazon-dropship-manager/trunk/KbAmazonDropShipManagerController.php

    r1261871 r1914965  
    139139        return $view;
    140140    }
    141 
     141   
     142    public function downloadImagesAction()
     143    {
     144        $view = new KbView(array());
     145        $view->setTemplate($this->getTemplatePath('downloadImages'));
     146        return $view;
     147    }
     148   
     149    public function downloadContentAction()
     150    {
     151        $data = array();
     152        if (isset($_POST['asin'])) {
     153            $importer = new KbAmazonImporter;
     154            $item = $importer->find($_POST['asin']);
     155            $item = $item->getItem();
     156            $data['item'] = $item;
     157        }
     158       
     159        $view = new KbView($data);
     160        $view->setTemplate($this->getTemplatePath('downloadContent'));
     161        return $view;
     162    }
     163   
    142164    public function reportsAction()
    143165    {
     
    166188                'icon' => 'glyphicon-import',
    167189                'label' => __('Import Item'),
     190            ),
     191            array(
     192                'action' => 'tools',
     193                'icon' => 'glyphicon-cog',
     194                'label' => __('Tools'),
     195                'pages' => array(
     196                    array('action' => 'downloadImages', 'label' => __('Download Images by ASIN')),
     197                    array('action' => 'downloadContent', 'label' => __('Download Content ASIN')),
     198                )
    168199            ),
    169200            array(
     
    199230    return $KbAmazonDropShipManagerContoller;
    200231}
     232
     233
     234if (isset($_POST['2kbDownloadImagesASIN'])) {
     235    $importer = new KbAmazonImporter;
     236    $item = $importer->find($_POST['asin']);
     237    $item = $item->getItem();
     238    $url = $item['DetailPageURL'];
     239    $response = wp_remote_get($url);
     240    $html = $response['body'];
     241
     242    $lines = explode("\n", $html);
     243
     244    $images = [];
     245    foreach ($lines as $line) {
     246        if (strpos($line, 'data["colorImages"]') !== false) {
     247            $pair = explode('data["colorImages"] =', $line);
     248            $json = json_decode(substr(trim($pair[1]), 0, -1), true);
     249            if (is_array($json)) {
     250                foreach ($json as $group => $groupImages) {
     251                    foreach ($groupImages as $pair) {
     252                        $images[$group][] = !isset($pair['hiRes']) || empty($pair['hiRes']) ? $pair['large'] : $pair['hiRes'];
     253                    }
     254                }
     255                break;
     256            }
     257        }
     258    }
     259
     260    if (empty($images)) {
     261        foreach ($lines as $line) {
     262            if (strpos($line, "'colorImages':") !== false) {
     263                $pair = explode("'colorImages':", $line);
     264                $jsonStr = str_replace("'initial'", '"initial"', trim(trim(substr($pair[1], 0, -1))));
     265                $result = json_decode($jsonStr, true);
     266                if (is_array($result)) {
     267                    foreach ($result['initial'] as $data) {
     268                        $images['large'][] = !isset($data['hiRes']) || empty($data['hiRes']) ? $data['large'] : $data['hiRes'];
     269                    }
     270                    break;
     271                }
     272            }
     273        }
     274    }
     275
     276    $dir = sys_get_temp_dir();
     277    $zip = new \ZipArchive;
     278    $zipFile = $dir . '/' . $_POST['asin'] . '.zip';
     279    $zip->open($zipFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
     280    $filesToRemove = [];
     281    $filesToRemove[] = $zipFile;
     282
     283    foreach ($images as $group => $groupImages) {
     284        foreach ($groupImages as $key => $src) {
     285            $tmp = $dir . '/' . uniqid($key) . '.jpg';
     286            file_put_contents($tmp, file_get_contents($src));
     287
     288            $img = imagecreatefromjpeg($tmp);
     289            imagejpeg($img, $tmp, 100);
     290
     291            $zip->addFile($tmp, $group . '/' . $key . '.jpg');
     292            $filesToRemove[] = $tmp;
     293        }
     294    }
     295    $zip->close();
     296
     297    header("Content-Type: application/force-download");
     298    header("Content-Type: application/octet-stream");
     299    header("Content-Type: application/download");
     300    header("Content-Disposition: attachment; filename=\"{$_POST['asin']}.zip\"");
     301    header("Pragma: public");
     302    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     303    header('Content-Length: ' . filesize($zipFile));
     304
     305    readfile($zipFile);
     306
     307    foreach ($filesToRemove as $file) {
     308        @unlink($file);
     309    }
     310    exit; 
     311}
  • 2kb-amazon-dropship-manager/trunk/plugin.php

    r1261871 r1914965  
    44 * Plugin URI: http://www.2kblater.com/
    55 * Description: Amazon DropShip Manager helps drop ship sellers to manage their products more easily. This plugin will help you keep track of quantity and price. It will send you reports for product changes by email.
    6  * Version: 1.0.0
     6 * Version: 1.1.0
    77 * Author: 2kblater.com
    88 * Author URI: http://www.2kblater.com
     
    1212!defined('ABSPATH') and exit;
    1313
    14 define('KbAmazonDropShipManagerVersion', '1.0.0');
    15 define('KbAmazonDropShipManagerNumber', 100);
     14define('KbAmazonDropShipManagerVersion', '1.1.0');
     15define('KbAmazonDropShipManagerNumber', 110);
    1616define('KbAmazonDropShipManagerFolderName',  pathinfo(dirname(__FILE__), PATHINFO_FILENAME));
    1717define('KbAmazonDropShipManagerPluginPath',  dirname(__FILE__) . '/');
  • 2kb-amazon-dropship-manager/trunk/readme.txt

    r1810789 r1914965  
    33Requires at least: 4.0
    44Tested up to: 4.1
    5 Stable tag: 1.0.1
     5Stable tag: 1.1.0
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3030
    3131== Changelog ==
     32= 1.1.0 =
     33new tools added
    3234= 1.0.1 =
    3335modal removed
Note: See TracChangeset for help on using the changeset viewer.