· 6 years ago · Jun 28, 2019, 04:20 PM
1<?php
2/*
3 *
4 * @ This file is created by http://DeZender.Net
5 * @ deZender (PHP5 Decoder for ionCube Encoder)
6 *
7 * @ Version : 3.5.0.0
8 * @ Author : DeZender
9 * @ Release on : 22.06.2018
10 * @ Official site : http://DeZender.Net
11 *
12 */
13
14if (!defined('MODULE_NAME')) {
15 define('MODULE_NAME', 'export_to_instagram');
16}
17
18define('AUTHOR_LINK', '');
19set_time_limit(0);
20date_default_timezone_set('UTC');
21
22if (!class_exists('str_lib')) {
23 class str_lib
24 {
25 public function str_lib_conv()
26 {
27 $str_lib = 'nazarspece';
28 echo 'licensed to ' . $str_lib;
29 }
30 }
31}
32
33if (!function_exists('icdk')) {
34 function icdk($a)
35 {
36 return md5(md5($a) . 'HGF+_)(()HG*^&^gghfddhkU&*H');
37 }
38}
39
40class ModelExtensionModuleAwExportToInstagram extends Model
41{
42 public $server = false;
43 public $_files = array();
44 public $_handles = array();
45 private $use_proxy = false;
46 private $proxy_list = false;
47 private static $pro = false;
48 private static $actived = false;
49 private static $cookies = '';
50 private static $server_connect = false;
51 private $username = null;
52 private $password = null;
53 private $uuid = null;
54 private $adid = null;
55 private $phone_id = null;
56 private $max_size = 1080;
57 private $ig_url = 'https://i.instagram.com/api/v1/';
58 private $ig_headers = array();
59 private $headers_add = array();
60 private $sig_key_version = 4;
61 private $ig_sig_key = 'ac5f26ee05af3e40a81b94b78d762dc8287bcdd8254fe86d0971b2aded8884a4';
62 private $ig_version = '64.0.0.14.96';
63 private $ig_version_code = '125398467';
64 private $user_agent_format = 'Instagram %s Android (%s/%s; %s; %s; %s; %s; %s; %s; %s; %s)';
65 private $content_type = 'application/x-www-form-urlencoded; charset=UTF-8';
66 private $boundary_chars = '-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
67 private $device_id = null;
68 private $device_string = null;
69 private $device = array();
70 private $devices = array('18/4.3; 320dpi; 720x1280; Xiaomi; HM 1SW; armani; qcom', '24/7.0; 380dpi; 1080x1920; OnePlus; ONEPLUS A3010; OnePlus3T; qcom', '23/6.0.1; 640dpi; 1440x2392; LGE/lge; RS988; h1; h1', '24/7.0; 640dpi; 1440x2560; HUAWEI; LON-L29; HWLON; hi3660', '23/6.0.1; 640dpi; 1440x2560; ZTE; ZTE A2017U; ailsa_ii; qcom', '23/6.0.1; 640dpi; 1440x2560; samsung; SM-G935F; hero2lte; samsungexynos8890', '17/4.2.2; 240dpi; 1080x1920; samsung; SM-G350; cs02; hawaii_ss_cs02', '23/6.0.1; 640dpi; 1440x2560; samsung; SM-G930F; herolte; samsungexynos8890');
71
72 public function createTables()
73 {
74 $sql = 'CREATE TABLE IF NOT EXISTS `aw_export_to_instagram` (`id` INT(11) NOT NULL, PRIMARY KEY (`id`)) CHARSET=utf8 COLLATE utf8_general_ci';
75 $this->db->query($sql);
76 $sql = 'CREATE TABLE IF NOT EXISTS `aw_export_to_instagram_cronlist` (`id` int(11) NOT NULL, PRIMARY KEY (`id`)) CHARSET=utf8 COLLATE utf8_general_ci';
77 $this->db->query($sql);
78 $sql = 'CREATE TABLE IF NOT EXISTS `aw_export_to_instagram_profiles` (`id` int(11) NOT NULL, PRIMARY KEY (`id`)) CHARSET=utf8 COLLATE utf8_general_ci';
79 $this->db->query($sql);
80 $sql = 'CREATE TABLE IF NOT EXISTS `aw_export_to_instagram_settings` (`id` int(11) NOT NULL, PRIMARY KEY (`id`)) CHARSET=utf8 COLLATE utf8_general_ci';
81 $this->db->query($sql);
82 $sql = 'CREATE TABLE IF NOT EXISTS `aw_export_to_instagram_templates` (`id` int(11) NOT NULL, PRIMARY KEY (`id`)) CHARSET=utf8 COLLATE utf8_general_ci';
83 $this->db->query($sql);
84 $tablesInfo = $this->alterTables();
85
86 foreach ($tablesInfo as $tablename => $tableInfo) {
87 if (empty($tableInfo)) {
88 continue;
89 }
90
91 $tablename = 'aw_export_to_instagram' . $tablename;
92 $sql = 'ALTER TABLE `' . $tablename . '`';
93 $this->db->query($sql . ' CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT');
94
95 foreach ($tableInfo as $fieldname => $field) {
96 $alterinfo = $sql . sprintf($field, $fieldname);
97 $notexists = "SELECT '" . $fieldname . "' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = '" . $tablename . "' AND COLUMN_NAME = '" . $fieldname . "'";
98 $isexists = $this->db->query($notexists);
99
100 if (!$isexists->num_rows) {
101 $this->db->query($alterinfo);
102 }
103 }
104 }
105 }
106
107 protected function alterTables()
108 {
109 return array('' => array('profile_id' => ' ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'shortcode' => ' ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'media_id' => ' ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'product_id' => ' ADD `%s` int(11) NOT NULL', 'date' => ' ADD `%s` int(64) NOT NULL', 'group' => ' ADD `%s` int(11) NOT NULL', 'status_id' => ' ADD `%s` int(1) NOT NULL'), '_cronlist' => array('cron_token' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'name' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'product_quantity' => 'ADD `%s` int(3) NOT NULL', 'group_product_quantity' => 'ADD `%s` int(3) NOT NULL', 'product_sort' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'is_nostock' => 'ADD `%s` int(1) NOT NULL', 'is_noprice' => 'ADD `%s` int(1) NOT NULL', 'is_disabled' => 'ADD `%s` int(1) NOT NULL', 'categories_id' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'manufacturers_id' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'products_id' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'stores_id' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'profiles_id' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'export_action' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'send_notifications' => 'ADD `%s` int(1) NOT NULL', 'task' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'status_id' => 'ADD `%s` int(1) NOT NULL'), '_profiles' => array('profile_id' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'status_id' => 'ADD `%s` int(1) NOT NULL', 'stores_id' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'login' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'password' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'pk' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'cookies' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'settings' => 'ADD `%s` text CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'time_logon' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL'), '_settings' => array('store_id' => 'ADD `%s` int(11) NOT NULL', 'is_album' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'is_resize' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'is_crop' => 'ADD `%s` int(1) NOT NULL DEFAULT 2', 'is_crop_ratio' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'is_watermark' => 'ADD `%s` int(1) NOT NULL', 'use_is_all_stores' => 'ADD `%s` int(1) NOT NULL', 'compression_quality' => 'ADD `%s` int(3) NOT NULL', 'background' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'watermark' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'watermark_size' => 'ADD `%s` int(3) NOT NULL DEFAULT 100', 'watermark_quality' => 'ADD `%s` int(3) NOT NULL DEFAULT 80', 'watermark_position' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'cover' => 'ADD `%s` int(1) NOT NULL', 'cover_gap' => 'ADD `%s` int(3) NOT NULL DEFAULT 50', 'cover_custom' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'group_caption' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'use_template' => 'ADD `%s` int(1) NOT NULL', 'is_seo_url' => 'ADD `%s` int(1) NOT NULL', 'template_id' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'category_template_id' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'language_id' => 'ADD `%s` int(11) NOT NULL', 'currency' => 'ADD `%s` varchar(5) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'is_crop_description' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'is_remove_spaces' => 'ADD `%s` int(1) NOT NULL DEFAULT 1', 'use_shortlinks' => 'ADD `%s` int(1) NOT NULL', 'location' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'location_id' => 'ADD `%s` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'use_ds_all_stores' => 'ADD `%s` int(1) NOT NULL', 'store_tags' => 'ADD `%s` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'tags_random' => 'ADD `%s` int(3) NOT NULL'), '_templates' => array('template_id' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'name' => 'ADD `%s` varchar(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL', 'template' => 'ADD `%s` text CHARACTER SET utf8mb4 NOT NULL', 'is_option_price' => 'ADD `%s` int(1) NOT NULL', 'status_id' => 'ADD `%s` int(1) NOT NULL'));
110 }
111
112 public function getProfiles($filter = array())
113 {
114 $profiles = array();
115 $sql = 'SELECT * FROM `aw_' . MODULE_NAME . '_profiles`';
116
117 if (isset($filter['filter_profile_id'])) {
118 $sql .= " WHERE profile_id = '" . $this->db->escape($filter['filter_profile_id']) . "'";
119 }
120
121 if (!$this->pro) {
122 $sql .= ' LIMIT 1';
123 }
124
125 $query = $this->db->query($sql);
126
127 foreach ($query->rows as $profile) {
128 $profile['stores_id'] = json_decode($profile['stores_id'], true);
129
130 if (!$this->user->hasPermission('modify', 'extension/module/aw_' . MODULE_NAME)) {
131 $profile['password'] = '';
132 }
133
134 $profiles[] = $profile;
135 }
136
137 if (isset($filter['filter_profile_id'])) {
138 return current($profiles);
139 }
140
141 return $profiles;
142 }
143
144 public function getStores($filter = array())
145 {
146 $stores = array();
147 $stores[0] = array('store_id' => 0, 'name' => $this->language->get('text_main_store_name'));
148
149 if (!$this->pro) {
150 return $stores;
151 }
152
153 $sql = 'SELECT * FROM `' . DB_PREFIX . 'store`';
154 $query = $this->db->query($sql);
155
156 foreach ($query->rows as $store) {
157 if (100 <= count($stores)) {
158 break;
159 }
160
161 $stores[$store['store_id']] = array('store_id' => $store['store_id'], 'name' => $store['name']);
162 }
163
164 return $stores;
165 }
166
167 public function getStoreByIdSettings($store_id = 0, $filter = array())
168 {
169 $sql = 'SELECT * FROM `' . DB_PREFIX . "setting` WHERE store_id = '" . (int) $store_id . "'";
170
171 if (!empty($filter['filter_code'])) {
172 $sql .= " AND `code` = '" . $this->db->escape($filter['filter_code']) . "'";
173 }
174
175 if (!empty($filter['filter_key'])) {
176 $sql .= " AND `key` = '" . $this->db->escape($filter['filter_key']) . "'";
177 }
178
179 $query = $this->db->query($sql);
180
181 return $query->rows;
182 }
183
184 public function getLanguageIdByCode($code)
185 {
186 $sql = 'SELECT * FROM `' . DB_PREFIX . "language` WHERE code = '" . $this->db->escape($code) . "'";
187 $query = $this->db->query($sql);
188
189 return $query->row['language_id'];
190 }
191
192 public function getSettings($filter = array())
193 {
194 $sql = 'SELECT * FROM `aw_' . MODULE_NAME . '_settings`';
195
196 if (isset($filter['filter_store_id'])) {
197 $sql .= " WHERE store_id = '" . $this->db->escape($filter['filter_store_id']) . "'";
198 }
199
200 if (!$this->pro) {
201 $sql .= ' LIMIT 1';
202 }
203
204 $query = $this->db->query($sql);
205
206 if (isset($filter['filter_store_id'])) {
207 return $query->row;
208 }
209
210 return $query->rows;
211 }
212
213 public function getTemplates($filter = array())
214 {
215 $sql = 'SELECT * FROM `aw_' . MODULE_NAME . '_templates`';
216
217 if (isset($filter['filter_template_id'])) {
218 $sql .= " WHERE template_id = '" . $this->db->escape($filter['filter_template_id']) . "'";
219 }
220
221 if (!$this->pro) {
222 $sql .= ' LIMIT 1';
223 }
224
225 $query = $this->db->query($sql);
226
227 if (isset($filter['filter_template_id'])) {
228 return $query->row;
229 }
230
231 return $query->rows;
232 }
233
234 public function getCronlist($filter = array())
235 {
236 $cronlist = array();
237 $sql = 'SELECT * FROM `aw_' . MODULE_NAME . '_cronlist`';
238
239 if (isset($filter['filter_task_token'])) {
240 $sql .= " WHERE task = '" . $this->db->escape($filter['filter_task_token']) . "'";
241 }
242
243 if (!$this->pro) {
244 $sql .= ' LIMIT 0';
245 }
246
247 $query = $this->db->query($sql);
248
249 foreach ($query->rows as $cronvalues) {
250 $cronvalues['categories'] = array();
251 $cronvalues['categories_id'] = json_decode($cronvalues['categories_id'], true);
252
253 if (0 < count($cronvalues['categories_id'])) {
254 $cronvalues['categories'] = $this->getCategories(array('filter_category_id' => $cronvalues['categories_id']));
255 }
256
257 $cronvalues['manufacturers'] = array();
258 $cronvalues['manufacturers_id'] = json_decode($cronvalues['manufacturers_id'], true);
259
260 if (0 < count($cronvalues['manufacturers_id'])) {
261 $cronvalues['manufacturers'] = $this->getManufacturers(array('filter_manufacturer_id' => $cronvalues['manufacturers_id']));
262 }
263
264 $cronvalues['products'] = array();
265 $cronvalues['products_id'] = json_decode($cronvalues['products_id'], true);
266
267 if (0 < count($cronvalues['products_id'])) {
268 $cronvalues['products'] = $this->getProducts(array('limit' => count($cronvalues['products_id']), 'filter_product_id' => $cronvalues['products_id']));
269 }
270
271 $cronvalues['stores_id'] = json_decode($cronvalues['stores_id'], true);
272 $cronvalues['profiles_id'] = json_decode($cronvalues['profiles_id'], true);
273 $cronlist[] = $cronvalues;
274 }
275
276 if (isset($filter['filter_task_token'])) {
277 return current($cronlist);
278 }
279
280 return $cronlist;
281 }
282
283 public function getCategories($filter, $select = '')
284 {
285 $sql = 'SELECT cp.category_id' . $select . ", GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR ' > ') AS name FROM " . DB_PREFIX . 'category_path cp LEFT JOIN ' . DB_PREFIX . 'category c1 ON (cp.category_id = c1.category_id) LEFT JOIN ' . DB_PREFIX . 'category c2 ON (cp.path_id = c2.category_id) LEFT JOIN ' . DB_PREFIX . 'category_description cd1 ON (cp.path_id = cd1.category_id) LEFT JOIN ' . DB_PREFIX . 'category_description cd2 ON (cp.category_id = cd2.category_id)';
286
287 if (!empty($filter['filter_product_id'])) {
288 $sql .= ' LEFT JOIN ' . DB_PREFIX . 'product_to_category p2c ON (p2c.category_id = cp.category_id)';
289 }
290
291 $sql .= ' WHERE';
292
293 if (isset($filter['filter_language_id'])) {
294 $sql .= " cd1.language_id = '" . (int) $filter['filter_language_id'] . "' AND cd2.language_id = '" . (int) $filter['filter_language_id'] . "'";
295 } else {
296 $sql .= " cd1.language_id = '" . (int) $this->config->get('config_language_id') . "' AND cd2.language_id = '" . (int) $this->config->get('config_language_id') . "'";
297 }
298
299 if (!empty($filter['filter_product_id'])) {
300 $sql .= ' AND p2c.main_category = 1 AND p2c.product_id = ' . (int) $filter['filter_product_id'];
301 }
302
303 if (!empty($filter['filter_name'])) {
304 $sql .= " AND cd2.name LIKE '%" . $this->db->escape($filter['filter_name']) . "%'";
305 }
306
307 if (!empty($filter['filter_category_id'])) {
308 $sql .= ' AND';
309
310 if (is_array($filter['filter_category_id'])) {
311 $sql .= ' (';
312
313 foreach ($filter['filter_category_id'] as $category_id) {
314 $sql .= " cd2.category_id = '" . (int) $category_id . "' OR";
315 }
316 $sql = trim($sql, ' OR') . ')';
317 } else {
318 $sql .= " cd2.category_id = '" . (int) $filter['filter_category_id'] . "'";
319 }
320 }
321
322 $sql .= ' GROUP BY cp.category_id LIMIT 0,10';
323 $query = $this->db->query($sql);
324
325 return $query->rows;
326 }
327
328 public function getCategoriesIdByProductId($product_id)
329 {
330 $sql = 'SELECT cp.path_id as category_id FROM `' . DB_PREFIX . 'product_to_category` p2c LEFT JOIN `' . DB_PREFIX . "category_path` cp ON (p2c.category_id = cp.category_id) WHERE p2c.product_id = '" . (int) $product_id . "' ORDER BY cp.level ASC";
331 $query = $this->db->query($sql);
332 $categories_id = array();
333
334 foreach ($query->rows as $row) {
335 $categories_id[] = $row['category_id'];
336 }
337
338 return $categories_id;
339 }
340
341 public function getManufacturers($filter = array())
342 {
343 $sql = 'SELECT m.manufacturer_id, m.name FROM ' . DB_PREFIX . 'manufacturer m WHERE';
344
345 if (isset($filter['filter_name'])) {
346 $sql .= " m.name LIKE '" . $this->db->escape($filter['filter_name']) . "%'";
347 }
348
349 if (isset($filter['filter_manufacturer_id'])) {
350 $sql .= (isset($filter['filter_name']) ? ' AND' : '');
351
352 if (is_array($filter['filter_manufacturer_id'])) {
353 $sql .= ' (';
354
355 foreach ($filter['filter_manufacturer_id'] as $manufacturer_id) {
356 $sql .= " m.manufacturer_id = '" . (int) $manufacturer_id . "' OR";
357 }
358 $sql = trim($sql, ' OR') . ')';
359 } else {
360 $sql .= " m.manufacturer_id = '" . (int) $filter['filter_manufacturer_id'] . "'";
361 }
362 }
363
364 $sql .= ' LIMIT 0,10';
365 $query = $this->db->query($sql);
366
367 if (isset($filter['filter_manufacturer_id']) && !is_array($filter['filter_manufacturer_id'])) {
368 return $query->row;
369 }
370
371 return $query->rows;
372 }
373
374 public function getProducts($filter, $select = '')
375 {
376 $sql = 'SELECT p.product_id, p.status, p.sku, pd.name' . ((0 < strlen($select) ? ', ' . $select : '')) . ' FROM ' . DB_PREFIX . 'product p LEFT JOIN ' . DB_PREFIX . 'product_description pd ON (p.product_id = pd.product_id)';
377
378 if (!empty($filter['filter_category_id'])) {
379.....................................................................
380....................................
381..........