Zikkio - Version 1.0.5

Version Notes

First stable release.

Download this release

Release Info

Developer Zikkio
Extension Zikkio
Version 1.0.5
Comparing to
See all releases


Code changes from version 1.0.4 to 1.0.5

app/code/community/Zikkio/Zikkio/Model/Observer.php CHANGED
@@ -1,24 +1,23 @@
1
  <?php
2
  class Zikkio_Zikkio_Model_Observer {
3
-
4
  public function saveApiKey() {
5
-
6
- $zikkio_api_key = Mage::getStoreConfig('catalog/zikkio/zikkio_api', Mage::app()->getStore());
7
- $content_file = '';
8
  $root_magento = Mage::getBaseDir();
9
-
10
- $file = $root_magento."/bridge2cart/bridge.php";
11
- $fh = fopen($file, 'r');
 
 
12
 
13
- while (($row_file = fgets($fh)) !== false) {
14
-
15
- if(preg_match('/M1_TOKEN/i', $row_file)) {
16
- $content_file = $content_file . "\n".'define("M1_TOKEN", "'.$zikkio_api_key.'");'."\n";
17
- }else{
18
- $content_file = $content_file . $row_file;
19
- }
20
- }
21
  file_put_contents($file, $content_file);
22
- fclose($fh);
 
 
 
 
23
  }
24
- }
 
1
  <?php
2
  class Zikkio_Zikkio_Model_Observer {
3
+
4
  public function saveApiKey() {
5
+
6
+ $zikkio_api_key = Mage::getStoreConfig('catalog/zikkio/zikkio_api', Mage::app()->getStore());
7
+
8
  $root_magento = Mage::getBaseDir();
9
+ $zikkio_bridge_directory = $root_magento."/bridge2cart";
10
+
11
+ $file = $root_magento."/bridge2cart/config.php";
12
+
13
+ $content_file = '<?php define("M1_TOKEN", "'.$zikkio_api_key.'");';
14
 
 
 
 
 
 
 
 
 
15
  file_put_contents($file, $content_file);
16
+
17
+ if( chmod($zikkio_bridge_directory, 0777) ) {
18
+ // more code
19
+ chmod($zikkio_bridge_directory, 0755);
20
+ }
21
  }
22
+
23
+ }
bridge2cart/bridge.php CHANGED
@@ -42,9 +42,7 @@
42
 
43
  class M1_Bridge_Action_Getconfig
44
  {
45
-
46
- function parseMemoryLimit($val)
47
- {
48
  $last = strtolower($val[strlen($val)-1]);
49
  switch($last) {
50
  case 'g':
@@ -58,51 +56,49 @@ class M1_Bridge_Action_Getconfig
58
  return $val;
59
  }
60
 
61
- function getMemoryLimit()
62
- {
63
  $memoryLimit = trim(@ini_get('memory_limit'));
64
- if (strlen($memoryLimit) === 0) {
65
  $memoryLimit = "0";
66
  }
67
  $memoryLimit = $this->parseMemoryLimit($memoryLimit);
68
 
69
  $maxPostSize = trim(@ini_get('post_max_size'));
70
- if (strlen($maxPostSize) === 0) {
71
  $maxPostSize = "0";
72
  }
73
  $maxPostSize = $this->parseMemoryLimit($maxPostSize);
74
 
75
  $suhosinMaxPostSize = trim(@ini_get('suhosin.post.max_value_length'));
76
- if (strlen($suhosinMaxPostSize) === 0) {
77
  $suhosinMaxPostSize = "0";
78
  }
79
  $suhosinMaxPostSize = $this->parseMemoryLimit($suhosinMaxPostSize);
80
 
81
- if ($suhosinMaxPostSize == 0) {
82
  $suhosinMaxPostSize = $maxPostSize;
83
  }
84
 
85
- if ($maxPostSize == 0) {
86
  $suhosinMaxPostSize = $maxPostSize = $memoryLimit;
87
  }
88
 
89
- return min($suhosinMaxPostSize, $maxPostSize, $memoryLimit);
90
  }
91
-
92
  function isZlibSupported()
93
  {
94
  return function_exists('gzdecode');
95
  }
96
 
97
- function perform($bridge)
98
- {
99
- if (!defined("DEFAULT_LANGUAGE_ISO2")) {
100
- define("DEFAULT_LANGUAGE_ISO2", ""); //variable for Interspire cart
101
  }
102
 
103
  $result = array(
104
  "images" => array(
105
- "imagesPath" => $bridge->config->imagesDir, // path to images folder - relative to store root
106
  "categoriesImagesPath" => $bridge->config->categoriesImagesDir,
107
  "categoriesImagesPaths" => $bridge->config->categoriesImagesDirs,
108
  "productsImagesPath" => $bridge->config->productsImagesDir,
@@ -134,7 +130,7 @@ class M1_Bridge_Action_Cubecart
134
  $languages = array();
135
 
136
  while ($dirEntry = readdir($dirHandle)) {
137
- if (!is_dir(M1_STORE_BASE_DIR . 'language/' . $dirEntry) || $dirEntry == '.' || $dirEntry == '..' || strpos($dirEntry, "_") !== false) {
138
  continue;
139
  }
140
 
@@ -147,14 +143,14 @@ class M1_Bridge_Action_Cubecart
147
  $cnfile = "config.php";
148
  }
149
 
150
- if (!file_exists( M1_STORE_BASE_DIR . 'language/' . $dirEntry . '/'. $cnfile)) {
151
  continue;
152
  }
153
 
154
  $str = file_get_contents(M1_STORE_BASE_DIR . 'language/' . $dirEntry . '/'.$cnfile);
155
  preg_match("/".preg_quote('$langName')."[\s]*=[\s]*[\"\'](.*)[\"\'];/", $str, $match);
156
 
157
- if (isset($match[1])) {
158
  $lang['name'] = $match[1];
159
  $languages[] = $lang;
160
  }
@@ -222,43 +218,42 @@ class M1_Bridge_Action_Clearcache
222
  * @var $fileExclude - name file in format pregmatch
223
  */
224
 
225
- function _removeGarbage($dirs = array(), $fileExclude = '')
226
  {
227
  $result = true;
228
 
229
- foreach ($dirs as $dir) {
230
 
231
- if (!file_exists($dir)) {
232
  continue;
233
  }
234
 
235
  $dirHandle = opendir($dir);
236
 
237
  while (false !== ($file = readdir($dirHandle))) {
238
- if ($file == "." || $file == "..") {
239
  continue;
240
  }
241
 
242
- if ((trim($fileExclude) != '') && preg_match("/^" .$fileExclude . "?$/", $file)) {
243
  continue;
244
  }
245
 
246
- if (is_dir($dir . $file)) {
247
  continue;
248
  }
249
 
250
  if (!unlink($dir . $file)) {
251
- $result = false;
252
  }
253
  }
254
-
255
  closedir($dirHandle);
256
  }
257
 
258
  if ($result) {
259
- echo 'OK';
260
  } else {
261
- echo 'ERROR';
262
  }
263
 
264
  return $result;
@@ -285,19 +280,19 @@ class M1_Bridge_Action_Clearcache
285
  foreach ($indexes as $index) {
286
  exec($phpExecutable . " shell/indexer.php --reindex $index", $out);
287
  }
288
- echo 'OK';
289
  } else {
290
  echo 'Error: can not find PHP executable file.';
291
  }
292
 
293
- echo 'OK';
294
  }
295
-
296
  function _InterspireClearCache()
297
  {
298
  $res = true;
299
  $file = M1_STORE_BASE_DIR . 'cache' . DIRECTORY_SEPARATOR . 'datastore' . DIRECTORY_SEPARATOR . 'RootCategories.php';
300
- if (file_exists($file)) {
301
  if (!unlink($file)) {
302
  $res = false;
303
  }
@@ -312,16 +307,14 @@ class M1_Bridge_Action_Clearcache
312
  function _CubecartClearCache()
313
  {
314
  $ok = true;
315
-
316
- if (file_exists(M1_STORE_BASE_DIR . 'cache')) {
317
  $dirHandle = opendir(M1_STORE_BASE_DIR . 'cache/');
318
 
319
  while (false !== ($file = readdir($dirHandle))) {
320
- if ($file != "." && $file != ".." && !preg_match("/^index\.html?$/", $file) && !preg_match("/^\.htaccess?$/", $file)) {
321
- if (is_file( M1_STORE_BASE_DIR . 'cache/' . $file)) {
322
- if (!unlink(M1_STORE_BASE_DIR . 'cache/' . $file)) {
323
- $ok = false;
324
- }
325
  }
326
  }
327
  }
@@ -333,11 +326,8 @@ class M1_Bridge_Action_Clearcache
333
  unlink(M1_STORE_BASE_DIR.'includes/extra/admin_cat_cache.txt');
334
  }
335
 
336
- if ($ok) {
337
- echo 'OK';
338
- } else {
339
- echo 'ERROR';
340
- }
341
  }
342
 
343
  function _PrestashopClearCache()
@@ -398,9 +388,9 @@ class M1_Bridge_Action_Clearcache
398
  {
399
  $pathToImages = 'components/com_virtuemart/shop_image';
400
 
401
- $dirParts = explode("/", $pathToImages);
402
  $path = M1_STORE_BASE_DIR;
403
- foreach ($dirParts as $item) {
404
  if ($item == '') {
405
  continue;
406
  }
@@ -445,19 +435,22 @@ class M1_Bridge_Action_Clearcache
445
 
446
  $this->_removeGarbage($dirs, '\.htaccess');
447
  }
448
-
449
  function _CscartClearCache()
450
  {
 
 
451
  $dir = M1_STORE_BASE_DIR . 'var/cache/';
452
  $res = $this->removeDirRec($dir);
453
 
454
- if ($res) {
455
- echo 'OK';
456
  } else {
457
- echo 'ERROR';
458
  }
459
  }
460
 
 
461
  function _Prestashop15ClearCache()
462
  {
463
  $dirs = array(
@@ -472,25 +465,23 @@ class M1_Bridge_Action_Clearcache
472
  function removeDirRec($dir)
473
  {
474
  $result = true;
475
-
476
  if ($objs = glob($dir."/*")) {
477
- foreach ($objs as $obj) {
478
- if (is_dir($obj)) {
479
  //print "IS DIR! START RECURSIVE FUNCTION.\n";
480
  $this->removeDirRec($obj);
481
  } else {
482
- if (!unlink($obj)) {
483
  //print "!UNLINK FILE: ".$obj."\n";
484
  $result = false;
485
  }
486
  }
487
  }
488
  }
489
- if (!rmdir($dir)) {
490
  //print "ERROR REMOVE DIR: ".$dir."\n";
491
  $result = false;
492
  }
493
-
494
  return $result;
495
  }
496
  }
@@ -510,15 +501,8 @@ class M1_Bridge_Action_Batchsavefile extends M1_Bridge_Action_Savefile
510
  {
511
  function perform($bridge) {
512
  $result = array();
513
-
514
  foreach ($_POST['files'] as $fileInfo) {
515
- $result[$fileInfo['id']] = $this->_saveFile(
516
- $fileInfo['source'],
517
- $fileInfo['target'],
518
- (int)$fileInfo['width'],
519
- (int)$fileInfo['height'],
520
- $fileInfo['local_source']
521
- );
522
  }
523
 
524
  echo serialize($result);
@@ -807,41 +791,41 @@ class M1_Bridge_Action_Savefile
807
 
808
  function _saveFile($source, $destination, $width, $height, $local = '')
809
  {
810
- if (trim($local) != '') {
811
 
812
- if ($this->_copyLocal($local, $destination, $width, $height)) {
813
  return "OK";
814
  }
815
 
816
  }
817
 
818
- if (!preg_match('/^https?:\/\//i', $source)) {
819
  $result = $this->_createFile($source, $destination);
820
- } elseif ($this->_isSameHost($source)) {
821
  $result = $this->_saveFileLocal($source, $destination);
822
  } else {
823
  $result = $this->_saveFileCurl($source, $destination);
824
  }
825
 
826
- if ($result != "OK") {
827
  return $result;
828
  }
829
 
830
  $destination = M1_STORE_BASE_DIR . $destination;
831
 
832
- if ($width != 0 && $height != 0) {
833
  $this->_scaled2( $destination, $width, $height );
834
  }
835
-
836
- if ($this->cartType == "Prestashop11") {
837
  // convert destination.gif(png) to destination.jpg
838
  $imageGd = $this->_loadImage($destination);
839
 
840
- if ($imageGd === false) {
841
  return $result;
842
  }
843
 
844
- if (!$this->_convert($imageGd, $destination, IMAGETYPE_JPEG, 'jpg')) {
845
  return "CONVERT FAILED";
846
  }
847
  }
@@ -858,69 +842,69 @@ class M1_Bridge_Action_Savefile
858
  return false;
859
  }
860
 
861
- if ($width != 0 && $height != 0) {
862
- $this->_scaled2($destination, $width, $height);
863
  }
864
 
865
  return true;
866
  }
867
 
868
- function _loadImage($filename, $skipJpg = true)
869
  {
870
- $imageInfo = @getimagesize($filename);
871
- if ($imageInfo === false) {
872
  return false;
873
  }
874
 
875
- $this->_imageType = $imageInfo[2];
876
 
877
- switch ($this->_imageType) {
878
- case IMAGETYPE_JPEG:
879
  $image = imagecreatefromjpeg($filename);
880
  break;
881
- case IMAGETYPE_GIF:
882
  $image = imagecreatefromgif($filename);
883
  break;
884
- case IMAGETYPE_PNG:
885
  $image = imagecreatefrompng($filename);
886
  break;
887
  default:
888
  return false;
889
  }
890
 
891
- if ($skipJpg && ($this->_imageType == IMAGETYPE_JPEG)) {
892
  return false;
893
  }
894
 
895
  return $image;
896
  }
897
 
898
- function _saveImage($image, $filename, $imageType = IMAGETYPE_JPEG, $compression = 85, $permissions = null)
899
- {
900
  $result = true;
901
- if ($imageType == IMAGETYPE_JPEG) {
902
- $result = imagejpeg($image, $filename, $compression);
903
- } elseif ($imageType == IMAGETYPE_GIF) {
904
- $result = imagegif($image, $filename);
905
- } elseif ($imageType == IMAGETYPE_PNG) {
906
- $result = imagepng($image, $filename);
907
  }
908
 
909
- if ($permissions != null) {
910
- chmod($filename, $permissions);
911
  }
912
 
913
- imagedestroy($image);
914
 
915
  return $result;
916
  }
917
 
918
  function _createFile($source, $destination)
919
  {
920
- if ($this->_create_dir(dirname($destination)) !== false) {
921
  $destination = M1_STORE_BASE_DIR . $destination;
922
  $body = base64_decode($source);
923
- if ($body === false || file_put_contents($destination, $body) === false) {
924
  return '[BRIDGE ERROR] File save failed!';
925
  }
926
 
@@ -935,10 +919,10 @@ class M1_Bridge_Action_Savefile
935
  $srcInfo = parse_url($source);
936
  $src = rtrim($_SERVER['DOCUMENT_ROOT'], "/") . $srcInfo['path'];
937
 
938
- if ($this->_create_dir(dirname($destination)) !== false) {
939
  $dst = M1_STORE_BASE_DIR . $destination;
940
 
941
- if (!@copy($src, $dst)) {
942
  return $this->_saveFileCurl($source, $destination);
943
  }
944
 
@@ -952,7 +936,7 @@ class M1_Bridge_Action_Savefile
952
  function _saveFileCurl($source, $destination)
953
  {
954
  $source = $this->_escapeSource($source);
955
- if ($this->_create_dir(dirname($destination)) !== false) {
956
  $destination = M1_STORE_BASE_DIR . $destination;
957
 
958
  $ch = curl_init();
@@ -964,25 +948,25 @@ class M1_Bridge_Action_Savefile
964
  curl_exec($ch);
965
  $httpResponseCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
966
 
967
- if ($httpResponseCode != 200) {
968
  curl_close($ch);
969
  return "[BRIDGE ERROR] Bad response received from source, HTTP code $httpResponseCode!";
970
  }
971
 
972
  $dst = @fopen($destination, "wb");
973
- if ($dst === false) {
974
  return "[BRIDGE ERROR] Can't create $destination!";
975
  }
976
  curl_setopt($ch, CURLOPT_NOBODY, false);
977
  curl_setopt($ch, CURLOPT_FILE, $dst);
978
  curl_setopt($ch, CURLOPT_HTTPGET, true);
979
  curl_exec($ch);
980
- if (($error_no = curl_errno($ch)) != CURLE_OK) {
981
  return "[BRIDGE ERROR] $error_no: " . curl_error($ch);
982
  }
983
  curl_close($ch);
984
  @chmod($destination, 0777);
985
-
986
  return "OK";
987
 
988
  } else {
@@ -996,16 +980,16 @@ class M1_Bridge_Action_Savefile
996
  }
997
 
998
  function _create_dir($dir) {
999
- $dirParts = explode("/", $dir);
1000
  $path = M1_STORE_BASE_DIR;
1001
- foreach ($dirParts as $item) {
1002
  if ($item == '') {
1003
  continue;
1004
  }
1005
  $path .= $item . DIRECTORY_SEPARATOR;
1006
- if (!is_dir($path)) {
1007
  $res = @mkdir($path);
1008
- if (!$res) {
1009
  return false;
1010
  }
1011
  }
@@ -1018,12 +1002,12 @@ class M1_Bridge_Action_Savefile
1018
  {
1019
  $srcInfo = parse_url($source);
1020
 
1021
- if (preg_match('/\.php$/', $srcInfo['path'])) {
1022
  return false;
1023
  }
1024
 
1025
  $hostInfo = parse_url("http://" . $_SERVER['HTTP_HOST']);
1026
- if (@$srcInfo['host'] == $hostInfo['host']) {
1027
  return true;
1028
  }
1029
 
@@ -1038,15 +1022,15 @@ class M1_Bridge_Action_Savefile
1038
  *
1039
  * @return true if success or false if no
1040
  */
1041
- function _convert($image, $filename, $type = IMAGETYPE_JPEG, $extension = '')
1042
  {
1043
  $end = pathinfo($filename, PATHINFO_EXTENSION);
1044
 
1045
- if ($extension == '') {
1046
  $extension = image_type_to_extension($type, false);
1047
  }
1048
 
1049
- if ($end == $extension) {
1050
  return true;
1051
  }
1052
 
@@ -1068,33 +1052,33 @@ class M1_Bridge_Action_Savefile
1068
  return $this->_saveImage($newImage, $pathSave, $type);
1069
  }
1070
 
1071
- function _scaled($destination, $width, $height)
1072
  {
1073
  $image = $this->_loadImage($destination, false);
1074
 
1075
- if ($image === false) {
1076
  return;
1077
  }
1078
 
1079
  $originWidth = imagesx( $image );
1080
  $originHeight = imagesy( $image );
1081
-
1082
  $rw = (int)$height * (int)$originWidth / (int)$originHeight;
1083
  $useHeight = ($rw <= $width);
1084
 
1085
- if ($useHeight) {
1086
  $width = (int)$rw;
1087
  } else {
1088
  $height = (int)((int)($width) * (int)($originHeight) / (int)($originWidth));
1089
  }
1090
 
1091
- $newImage = imagecreatetruecolor($width, $height);
1092
- $white = imagecolorallocate($newImage, 255, 255, 255);
1093
- imagefill($newImage, 0, 0, $white);
1094
- imagecopyresampled($newImage, $image, 0, 0, 0, 0, $width, $height, $originWidth, $originHeight);
1095
- imagecolortransparent($newImage, $white);
1096
-
1097
- return $this->_saveImage($newImage, $destination, $this->_imageType, 100) ? "OK" : "CAN'T SCALE IMAGE";
1098
  }
1099
 
1100
  //scaled2 method optimizet for prestashop
@@ -1104,24 +1088,25 @@ class M1_Bridge_Action_Savefile
1104
 
1105
  $sourceImage = $this->_loadImage($destination, false);
1106
 
1107
- if ($sourceImage === false) {
1108
  return "IMAGE NOT SUPPORTED";
1109
  }
1110
 
1111
- $sourceWidth = imagesx($sourceImage);
1112
- $sourceHeight = imagesy($sourceImage);
1113
 
1114
  $widthDiff = $destWidth / $sourceWidth;
1115
  $heightDiff = $destHeight / $sourceHeight;
1116
 
1117
- if ($widthDiff > 1 && $heightDiff > 1) {
 
1118
  $nextWidth = $sourceWidth;
1119
  $nextHeight = $sourceHeight;
1120
  } else {
1121
  if (intval($method) == 2 || (intval($method) == 0 AND $widthDiff > $heightDiff)) {
1122
  $nextHeight = $destHeight;
1123
  $nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight);
1124
- $destWidth = ((intval($method) == 0 ) ? $destWidth : $nextWidth);
1125
  } else {
1126
  $nextWidth = $destWidth;
1127
  $nextHeight = intval($sourceHeight * $destWidth / $sourceWidth);
@@ -1139,8 +1124,8 @@ class M1_Bridge_Action_Savefile
1139
 
1140
  imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight);
1141
  imagecolortransparent($destImage, $white);
1142
-
1143
- return $this->_saveImage($destImage, $destination, $this->_imageType, 100) ? "OK" : "CAN'T SCALE IMAGE";
1144
  }
1145
  }
1146
 
@@ -1148,20 +1133,22 @@ class M1_Bridge_Action_Query
1148
  {
1149
  function perform($bridge)
1150
  {
1151
- if (isset($_POST['query']) && isset($_POST['fetchMode'])) {
1152
- $query = base64_decode($_POST['query']);
 
1153
 
1154
  $res = $bridge->query($query, (int)$_POST['fetchMode']);
1155
 
1156
- if (is_array($res['result']) || is_bool($res['result'])) {
1157
- $result = serialize(array(
1158
  'res' => $res['result'],
1159
  'fetchedFields' => @$res['fetchedFields'],
1160
- 'insertId' => $bridge->getLink()->getLastInsertId(),
1161
- 'affectedRows' => $bridge->getLink()->getAffectedRows(),
1162
  ));
1163
 
1164
  echo base64_encode($result);
 
1165
  } else {
1166
  echo base64_encode($res['message']);
1167
  }
@@ -1174,21 +1161,21 @@ class M1_Bridge_Action_Query
1174
 
1175
  class M1_Config_Adapter
1176
  {
1177
- var $Host = 'localhost';
1178
  var $Port = null;//"3306";
1179
- var $Username = 'root';
1180
- var $Password = '';
1181
- var $Dbname = '';
1182
- var $TblPrefix = '';
1183
-
1184
- var $cartType = 'Oscommerce22ms2';
1185
- var $imagesDir = '';
1186
- var $categoriesImagesDir = '';
1187
- var $productsImagesDir = '';
1188
- var $manufacturersImagesDir = '';
1189
- var $categoriesImagesDirs = '';
1190
- var $productsImagesDirs = '';
1191
- var $manufacturersImagesDirs = '';
1192
 
1193
  var $languages = array();
1194
  var $cartVars = array();
@@ -1199,56 +1186,59 @@ class M1_Config_Adapter
1199
  return null;
1200
  }
1201
 
1202
- $cartType = $this->_detectCartType();
1203
- $className = "M1_Config_Adapter_" . $cartType;
1204
-
1205
  $obj = new $className();
1206
  $obj->cartType = $cartType;
1207
-
1208
  return $obj;
1209
  }
1210
 
1211
- function _detectCartType()
1212
  {
1213
  // Zencart137
1214
- if (file_exists(M1_STORE_BASE_DIR . "includes" . DIRECTORY_SEPARATOR . "configure.php")
1215
- && file_exists(M1_STORE_BASE_DIR . "ipn_main_handler.php")
1216
- ) {
 
 
1217
  return "Zencart137";
1218
  }
1219
 
1220
  //osCommerce
1221
- /* is if not tomatocart */
1222
- if (file_exists(M1_STORE_BASE_DIR . "includes" . DIRECTORY_SEPARATOR . "configure.php")
1223
- && !file_exists(M1_STORE_BASE_DIR . "includes" . DIRECTORY_SEPARATOR . "toc_constants.php")
1224
- ) {
 
 
 
1225
  return "Oscommerce22ms2";
1226
  }
1227
 
1228
- if (file_exists(M1_STORE_BASE_DIR . "/includes/configure.php")) {
1229
  return "Gambio";
1230
  }
1231
 
1232
  //JooCart
1233
- if (file_exists(M1_STORE_BASE_DIR . '/components/com_opencart/opencart.php')) {
1234
  return 'JooCart';
1235
  }
1236
 
1237
  //ACEShop
1238
- if (file_exists(M1_STORE_BASE_DIR . '/components/com_aceshop/aceshop.php')) {
1239
  return 'AceShop';
1240
  }
1241
 
1242
  //Litecommerce
1243
- if ((file_exists(M1_STORE_BASE_DIR .'/etc/config.php'))
1244
- || (file_exists(M1_STORE_BASE_DIR .'/modules/lc_connector/litecommerce/etc/config.php'))
1245
- ) {
1246
  return "Litecommerce";
1247
  }
1248
 
1249
  //Prestashop11
1250
  if (file_exists(M1_STORE_BASE_DIR . "config/config.inc.php")) {
1251
- if (file_exists(M1_STORE_BASE_DIR . "cache/class_index.php")) {
 
1252
  return "Prestashop15";
1253
  }
1254
  return "Prestashop11";
@@ -1279,16 +1269,13 @@ class M1_Config_Adapter
1279
  }
1280
 
1281
  //Cscart203 - 3
1282
- if (file_exists(M1_STORE_BASE_DIR . "config.local.php") || file_exists(M1_STORE_BASE_DIR . "partner.php")) {
 
1283
  return "Cscart203";
1284
  }
1285
 
1286
  //Opencart14
1287
- if ((file_exists(M1_STORE_BASE_DIR . "system/startup.php")
1288
- || (file_exists(M1_STORE_BASE_DIR . "common.php"))
1289
- || (file_exists(M1_STORE_BASE_DIR . "library/locator.php"))
1290
- ) && file_exists(M1_STORE_BASE_DIR . "config.php")
1291
- ) {
1292
  return "Opencart14";
1293
  }
1294
 
@@ -1298,25 +1285,25 @@ class M1_Config_Adapter
1298
  }
1299
 
1300
  //XCart
1301
- if (file_exists(M1_STORE_BASE_DIR . "config.php")) {
1302
  return "XCart";
1303
  }
1304
 
1305
  //LemonStand
1306
- if (file_exists(M1_STORE_BASE_DIR . "boot.php")) {
1307
  return "LemonStand";
1308
  }
1309
-
1310
  //Interspire
1311
  if (file_exists(M1_STORE_BASE_DIR . "config/config.php")) {
1312
  return "Interspire";
1313
- }
1314
-
1315
  //Squirrelcart242
1316
  if (file_exists(M1_STORE_BASE_DIR . 'squirrelcart/config.php')) {
1317
  return "Squirrelcart242";
1318
  }
1319
-
1320
  //Shopscript WebAsyst
1321
  if (file_exists(M1_STORE_BASE_DIR . 'kernel/wbs.xml')) {
1322
  return "WebAsyst";
@@ -1338,41 +1325,37 @@ class M1_Config_Adapter
1338
  }
1339
 
1340
  //Summercart3
1341
- if (file_exists(M1_STORE_BASE_DIR . 'sclic.lic') && file_exists(M1_STORE_BASE_DIR . 'include/miphpf/Config.php')) {
1342
  return "Summercart3";
1343
  }
1344
 
1345
  //XtcommerceVeyton
1346
- if (file_exists(M1_STORE_BASE_DIR . 'conf/config.php')) {
1347
  return "XtcommerceVeyton";
1348
  }
1349
 
1350
  //Ubercart
1351
- if (file_exists(M1_STORE_BASE_DIR . 'sites/default/settings.php' )) {
1352
- if (file_exists( M1_STORE_BASE_DIR . '/modules/ubercart/uc_store/includes/coder_review_uc3x.inc')) {
1353
- return "Ubercart3";
1354
- } elseif (file_exists(M1_STORE_BASE_DIR . 'sites/all/modules/commerce/includes/commerce.controller.inc')) {
1355
- return "DrupalCommerce";
1356
- }
1357
-
1358
  return "Ubercart";
1359
  }
1360
 
1361
  //Woocommerce
1362
- if (file_exists(M1_STORE_BASE_DIR . 'wp-config.php')
1363
- && file_exists(M1_STORE_BASE_DIR . 'wp-content/plugins/woocommerce/woocommerce.php')
1364
- ) {
1365
  return 'Woocommerce';
1366
  }
1367
 
1368
- if (file_exists(dirname(M1_STORE_BASE_DIR) . '/wp-config.php')
1369
- && file_exists(M1_STORE_BASE_DIR . 'wp-content/plugins/woocommerce/woocommerce.php')
1370
- ) {
1371
  return 'Woocommerce';
1372
  }
1373
 
1374
  //WPecommerce
1375
- if (file_exists(M1_STORE_BASE_DIR . 'wp-config.php')) {
1376
  return 'WPecommerce';
1377
  }
1378
 
@@ -1382,21 +1365,22 @@ class M1_Config_Adapter
1382
  }
1383
 
1384
  //HHGMultistore
1385
- if (file_exists(M1_STORE_BASE_DIR . 'core/config/configure.php')) {
1386
  return 'Hhgmultistore';
1387
  }
1388
 
1389
  //SunShop
1390
- if (file_exists(M1_STORE_BASE_DIR . "include" . DIRECTORY_SEPARATOR . "config.php")
1391
- || file_exists(M1_STORE_BASE_DIR . "include" . DIRECTORY_SEPARATOR . "db_mysql.php")
1392
- ) {
1393
  return "Sunshop4";
1394
  }
1395
 
1396
  //Tomatocart
1397
- if (file_exists(M1_STORE_BASE_DIR . "includes" . DIRECTORY_SEPARATOR . "configure.php")
1398
- && file_exists(M1_STORE_BASE_DIR. "includes" . DIRECTORY_SEPARATOR . "toc_constants.php")
1399
- ) {
 
 
 
1400
  return 'Tomatocart';
1401
  }
1402
 
@@ -1405,294 +1389,87 @@ class M1_Config_Adapter
1405
 
1406
  function getAdapterPath($cartType)
1407
  {
1408
- return M1_STORE_BASE_DIR . M1_BRIDGE_DIRECTORY_NAME . DIRECTORY_SEPARATOR
1409
- . "app" . DIRECTORY_SEPARATOR
1410
- . "class" . DIRECTORY_SEPARATOR
1411
- . "config_adapter" . DIRECTORY_SEPARATOR . $cartType . ".php";
 
1412
  }
1413
 
1414
  function setHostPort($source)
1415
  {
1416
  $source = trim($source);
1417
 
1418
- if ($source == '') {
1419
- $this->Host = 'localhost';
1420
  return;
1421
  }
1422
 
1423
  $conf = explode(":", $source);
 
1424
 
1425
- if (isset($conf[0]) && isset($conf[1])) {
1426
  $this->Host = $conf[0];
1427
- $this->Port = $conf[1];
1428
- } elseif ($source[0] == '/') {
1429
- $this->Host = 'localhost';
1430
- $this->Port = $source;
1431
- } else {
1432
- $this->Host = $source;
1433
- }
1434
- }
1435
 
1436
- function connect()
1437
- {
1438
- if (function_exists('mysql_connect')) {
1439
- $link = new M1_Mysql($this);
1440
- } elseif (function_exists('mysqli_connect')) {
1441
- $link = new M1_Mysqli($this);
1442
- } elseif (extension_loaded('pdo_mysql')) {
1443
- $link = new M1_Pdo($this);
1444
- } else {
1445
- $link = false;
1446
- }
1447
 
1448
- return $link;
1449
- }
1450
-
1451
- function getCartVersionFromDb($field, $tableName, $where)
1452
- {
1453
- $version = '';
1454
-
1455
- $link = $this->connect();
1456
- if (!$link) {
1457
- return '[ERROR] MySQL Query Error: Can not connect to DB';
1458
- }
1459
-
1460
- $result = $link->localQuery("
1461
- SELECT " . $field . " AS version
1462
- FROM " . $this->TblPrefix . $tableName . "
1463
- WHERE " . $where
1464
- );
1465
 
1466
- if (is_array($result) && isset($result[0]['version'])) {
1467
- $version = $result[0]['version'];
1468
- }
1469
-
1470
- return $version;
1471
- }
1472
- }
1473
-
1474
- /**
1475
- * @package api2cart
1476
- * @author Vasul Babiy (v.babyi@magneticone.com)
1477
- * @license Not public license
1478
- * @link https://www.api2cart.com
1479
- */
1480
-
1481
- class M1_Mysqli
1482
- {
1483
- var $config = null; // config adapter
1484
- var $result = array();
1485
- var $dataBaseHandle = null;
1486
-
1487
- /**
1488
- * mysql constructor
1489
- *
1490
- * @param M1_Config_Adapter $config
1491
- * @return M1_Mysql
1492
- */
1493
- function M1_Mysqli($config)
1494
- {
1495
- $this->config = $config;
1496
- }
1497
-
1498
- /**
1499
- * @return bool|null|resource
1500
- */
1501
- function getDataBaseHandle()
1502
- {
1503
- if ($this->dataBaseHandle) {
1504
- return $this->dataBaseHandle;
1505
- }
1506
 
1507
- $this->dataBaseHandle = $this->connect();
1508
 
1509
- if (!$this->dataBaseHandle) {
1510
- exit('[ERROR] MySQLi Query Error: Can not connect to DB');
1511
  }
1512
-
1513
- return $this->dataBaseHandle;
1514
  }
1515
 
1516
- /**
1517
- * @return bool|null|resource
1518
- */
1519
  function connect()
1520
  {
1521
  $triesCount = 10;
1522
  $link = null;
1523
- $host = $this->config->Host . ($this->config->Port ? ':' . $this->config->Port : '');
1524
- $password = stripslashes($this->config->Password);
1525
 
 
1526
  while (!$link) {
1527
  if (!$triesCount--) {
1528
  break;
1529
  }
1530
-
1531
- $link = @mysqli_connect($host, $this->config->Username, $password);
1532
- if (!$link) {
1533
  sleep(5);
1534
  }
1535
  }
1536
 
1537
- if ($link) {
1538
- mysqli_select_db($link, $this->config->Dbname);
1539
- } else {
1540
- return false;
1541
  }
1542
 
1543
  return $link;
1544
  }
1545
 
1546
- /**
1547
- * @param $sql
1548
- *
1549
- * @return array|bool|mysqli_result
1550
- */
1551
- function localQuery($sql)
1552
- {
1553
- $result = array();
1554
- $dataBaseHandle = $this->getDataBaseHandle();
1555
-
1556
- $sth = mysqli_query($dataBaseHandle, $sql);
1557
-
1558
- if (is_bool($sth)) {
1559
- return $sth;
1560
- }
1561
-
1562
- while (($row = mysqli_fetch_assoc($sth))) {
1563
- $result[] = $row;
1564
- }
1565
-
1566
- return $result;
1567
- }
1568
-
1569
- /**
1570
- * @param $sql
1571
- * @param $fetchType
1572
- *
1573
- * @return array
1574
- */
1575
- function query($sql, $fetchType)
1576
  {
1577
- $result = array(
1578
- 'result' => null,
1579
- 'message' => ''
1580
- );
1581
-
1582
- $dataBaseHandle = $this->getDataBaseHandle();
1583
-
1584
- if (!$dataBaseHandle) {
1585
- $result['message'] = '[ERROR] MySQLi Query Error: Can not connect to DB';
1586
- return $result;
1587
- }
1588
-
1589
- if (isset($_GET['disable_checks'])) {
1590
- $this->localQuery('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0');
1591
- $this->localQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
1592
- }
1593
-
1594
- if (isset($_REQUEST['set_names'])) {
1595
- @mysqli_query($dataBaseHandle, "SET NAMES " . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1596
- @mysqli_query($dataBaseHandle, "SET CHARACTER SET " . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1597
- @mysqli_query($dataBaseHandle, "SET CHARACTER_SET_CONNECTION=" . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1598
- }
1599
-
1600
- $fetchMode = MYSQLI_ASSOC;
1601
- switch ($fetchType) {
1602
- case 3:
1603
- $fetchMode = MYSQLI_BOTH;
1604
- break;
1605
- case 2:
1606
- $fetchMode = MYSQLI_NUM;
1607
- break;
1608
- case 1:
1609
- $fetchMode = MYSQLI_ASSOC;
1610
- break;
1611
- default:
1612
- break;
1613
- }
1614
-
1615
- $res = mysqli_query($dataBaseHandle, $sql);
1616
-
1617
- $triesCount = 10;
1618
- while (mysqli_errno($dataBaseHandle) == 2013) {
1619
- if (!$triesCount--) {
1620
- break;
1621
- }
1622
- // reconnect
1623
- $dataBaseHandle = $this->getDataBaseHandle();
1624
- if ($dataBaseHandle) {
1625
-
1626
- if (isset($_REQUEST['set_names'])) {
1627
- @mysqli_query($dataBaseHandle, "SET NAMES " . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1628
- @mysqli_query($dataBaseHandle, "SET CHARACTER SET " . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1629
- @mysqli_query($dataBaseHandle, "SET CHARACTER_SET_CONNECTION=" . @mysqli_real_escape_string($dataBaseHandle, $_REQUEST['set_names']));
1630
- }
1631
-
1632
- // execute query once again
1633
- $res = mysqli_query($dataBaseHandle, $sql);
1634
- }
1635
- }
1636
-
1637
- if (($errno = mysqli_errno($dataBaseHandle)) != 0) {
1638
- $result['message'] = '[ERROR] MySQLi Query Error: ' . $errno . ', ' . mysqli_error($dataBaseHandle);
1639
- return $result;
1640
- }
1641
-
1642
- $fetchedFields = array();
1643
- while ($field = mysqli_fetch_field($res)) {
1644
- $fetchedFields[] = $field;
1645
- }
1646
-
1647
- $rows = array();
1648
- while ($row = mysqli_fetch_array($res, $fetchMode)) {
1649
- $rows[] = $row;
1650
- }
1651
 
1652
- if (isset($_GET['disable_checks'])) {
1653
- $this->localQuery("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
1654
- $this->localQuery("SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS,0)");
1655
  }
1656
 
1657
- $result['result'] = $rows;
1658
- $result['fetchedFields'] = $fetchedFields;
1659
 
1660
- mysqli_free_result($res);
1661
-
1662
- return $result;
1663
- }
1664
-
1665
- /**
1666
- * @return int
1667
- */
1668
- function getLastInsertId()
1669
- {
1670
- return mysqli_insert_id($this->dataBaseHandle);
1671
- }
1672
 
1673
- /**
1674
- * @return int
1675
- */
1676
- function getAffectedRows()
1677
- {
1678
- return mysqli_affected_rows($this->dataBaseHandle);
1679
- }
1680
 
1681
- /**
1682
- * @return void
1683
- */
1684
- function __destruct()
1685
- {
1686
- if ($this->dataBaseHandle) {
1687
- mysqli_close($this->dataBaseHandle);
1688
  }
1689
 
1690
- $this->dataBaseHandle = null;
1691
- }
1692
-
1693
  }
1694
 
1695
-
1696
  class M1_Config_Adapter_Cscart203 extends M1_Config_Adapter
1697
  {
1698
  function M1_Config_Adapter_Cscart203()
@@ -3208,494 +2985,168 @@ class M1_Config_Adapter_JooCart extends M1_Config_Adapter
3208
  }
3209
 
3210
 
3211
- /**
3212
- * @package api2cart
3213
- * @author Vasul Babiy (v.babyi@magneticone.com)
3214
- * @license Not public license
3215
- * @link https://www.api2cart.com
3216
- */
3217
-
3218
- class M1_Pdo
3219
- {
3220
- var $config = null; // config adapter
3221
- var $noResult = array('delete', 'update', 'move', 'truncate', 'insert', 'set', 'create', 'drop');
3222
- var $dataBaseHandle = null;
3223
-
3224
- var $insertedId = 0;
3225
- var $affectedRows = 0;
3226
-
3227
- /**
3228
- * pdo constructor
3229
- *
3230
- * @param M1_Config_Adapter $config configuration
3231
- * @return M1_Pdo
3232
- */
3233
- function M1_Pdo($config)
3234
- {
3235
- $this->config = $config;
3236
- }
3237
-
3238
- /**
3239
- * @return bool|null|PDO
3240
- */
3241
- function getDataBaseHandle()
3242
- {
3243
- if ($this->dataBaseHandle) {
3244
- return $this->dataBaseHandle;
3245
- }
3246
-
3247
- $this->dataBaseHandle = $this->connect();
3248
-
3249
- if (!$this->dataBaseHandle) {
3250
- exit('[ERROR] MySQL Query Error: Can not connect to DB');
3251
- }
3252
-
3253
- return $this->dataBaseHandle;
3254
- }
3255
-
3256
- /**
3257
- * @return bool|PDO
3258
- */
3259
- function connect()
3260
- {
3261
- $triesCount = 3;
3262
- $host = $this->config->Host . ($this->config->Port ? ':' . $this->config->Port : '');
3263
- $password = stripslashes($this->config->Password);
3264
- $dbName = $this->config->Dbname;
3265
-
3266
- while ($triesCount) {
3267
- try {
3268
- $link = new PDO("mysql:host=$host; dbname=$dbName", $this->config->Username, $password);
3269
- $link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
3270
-
3271
- return $link;
3272
 
3273
- } catch (PDOException $e) {
3274
- $triesCount--;
3275
-
3276
- // fix invalid port
3277
- $host = $this->config->Host;
3278
- }
3279
- }
3280
- return false;
3281
- }
3282
-
3283
- /**
3284
- * @param string $sql sql query
3285
- *
3286
- * @return array|bool
3287
- */
3288
- function localQuery($sql)
3289
- {
3290
- $result = array();
3291
- $dataBaseHandle = $this->getDataBaseHandle();
3292
-
3293
- $sth = $dataBaseHandle->query($sql);
3294
-
3295
- foreach ($this->noResult as $statement) {
3296
- if (!$sth || strpos(strtolower(trim($sql)), $statement) === 0) {
3297
- return true;
3298
- }
3299
- }
3300
-
3301
- while (($row = $sth->fetch(PDO::FETCH_ASSOC)) != false) {
3302
- $result[] = $row;
3303
- }
3304
-
3305
- return $result;
3306
- }
3307
-
3308
- /**
3309
- * @param string $sql sql query
3310
- * @param int $fetchType fetch Type
3311
- *
3312
- * @return array
3313
- */
3314
- function query($sql, $fetchType)
3315
- {
3316
- $result = array(
3317
- 'result' => null,
3318
- 'message' => '',
3319
- 'fetchedFields' => array()
3320
- );
3321
- $dataBaseHandle = $this->getDataBaseHandle();
3322
-
3323
- if (isset($_GET['disable_checks'])) {
3324
- $dataBaseHandle->exec('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0');
3325
- $dataBaseHandle->exec("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
3326
- }
3327
-
3328
- if (isset($_REQUEST['set_names'])) {
3329
- $dataBaseHandle->exec("SET NAMES '" . ($_REQUEST['set_names']) . "'");
3330
- $dataBaseHandle->exec("SET CHARACTER SET '" . ($_REQUEST['set_names']) . "'");
3331
- $dataBaseHandle->exec("SET CHARACTER_SET_CONNECTION = '" . ($_REQUEST['set_names']) . "'");
3332
- }
3333
-
3334
- switch ($fetchType) {
3335
- case 3:
3336
- $dataBaseHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_BOTH);
3337
- break;
3338
- case 2:
3339
- $dataBaseHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_NUM);
3340
- break;
3341
- case 1:
3342
- default:
3343
- $dataBaseHandle->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
3344
- break;
3345
- }
3346
-
3347
- try {
3348
- $res = $dataBaseHandle->query($sql);
3349
- $this->affectedRows = $res->rowCount();
3350
- $this->insertedId = $dataBaseHandle->lastInsertId();
3351
- } catch (PDOException $e) {
3352
- $result['message'] = '[ERROR] Mysql Query Error: ' . $e->getCode() . ', ' . $e->getMessage();
3353
- return $result;
3354
- }
3355
-
3356
- foreach ($this->noResult as $statement) {
3357
- if (!$res || strpos(strtolower(trim($sql)), $statement) === 0) {
3358
- $result['result'] = true;
3359
- return $result;
3360
- }
3361
- }
3362
-
3363
- $rows = array();
3364
- while (($row = $res->fetch()) !== false) {
3365
- $rows[] = $row;
3366
- }
3367
-
3368
- if (isset($_GET['disable_checks'])) {
3369
- $this->localQuery("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
3370
- $this->localQuery("SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS,0)");
3371
- }
3372
-
3373
- $result['result'] = $rows;
3374
-
3375
- unset($res);
3376
- return $result;
3377
- }
3378
-
3379
- /**
3380
- * @return string|int
3381
- */
3382
- function getLastInsertId()
3383
- {
3384
- return $this->insertedId;
3385
- }
3386
-
3387
- /**
3388
- * @return int
3389
- */
3390
- function getAffectedRows()
3391
- {
3392
- return $this->affectedRows;
3393
- }
3394
-
3395
- /**
3396
- * @return void
3397
- */
3398
- function __destruct()
3399
- {
3400
- $this->dataBaseHandle = null;
3401
- }
3402
- }
3403
-
3404
- /**
3405
- * @package api2cart
3406
- * @author Vasul Babiy (v.babyi@magneticone.com)
3407
- * @license Not public license
3408
- * @link https://www.api2cart.com
3409
- */
3410
-
3411
- class M1_Mysql
3412
  {
 
 
 
3413
  var $config = null; // config adapter
3414
- var $result = array();
3415
- var $dataBaseHandle = null;
3416
 
3417
  /**
3418
- * mysql constructor
3419
  *
3420
  * @param M1_Config_Adapter $config
3421
- * @return M1_Mysql
3422
  */
3423
- function M1_Mysql($config)
3424
  {
3425
  $this->config = $config;
3426
- }
3427
-
3428
- /**
3429
- * @return bool|null|resource
3430
- */
3431
- function getDataBaseHandle()
3432
- {
3433
- if ($this->dataBaseHandle) {
3434
- return $this->dataBaseHandle;
3435
- }
3436
 
3437
- $this->dataBaseHandle = $this->connect();
3438
-
3439
- if (!$this->dataBaseHandle) {
3440
- exit('[ERROR] MySQL Query Error: Can not connect to DB');
3441
  }
3442
-
3443
- return $this->dataBaseHandle;
3444
  }
3445
 
3446
- /**
3447
- * @return bool|null|resource
3448
- */
3449
- function connect()
3450
  {
3451
- $triesCount = 10;
3452
- $link = null;
3453
- $host = $this->config->Host . ($this->config->Port ? ':' . $this->config->Port : '');
3454
- $password = stripslashes($this->config->Password);
3455
-
3456
- while (!$link) {
3457
- if (!$triesCount--) {
3458
- break;
3459
- }
3460
-
3461
- $link = @mysql_connect($host, $this->config->Username, $password);
3462
- if (!$link) {
3463
- sleep(5);
3464
- }
3465
- }
3466
-
3467
- if ($link) {
3468
- mysql_select_db($this->config->Dbname, $link);
3469
- } else {
3470
- return false;
3471
- }
3472
-
3473
- return $link;
3474
  }
3475
 
3476
- /**
3477
- * @param string $sql sql query
3478
- *
3479
- * @return array
3480
- */
3481
- function localQuery($sql)
3482
  {
3483
- $result = array();
3484
- $dataBaseHandle = $this->getDataBaseHandle();
3485
-
3486
- $sth = mysql_query($sql, $dataBaseHandle);
3487
-
3488
- if (is_bool($sth)) {
3489
- return $sth;
3490
- }
3491
-
3492
- while (($row = mysql_fetch_assoc($sth)) != false) {
3493
- $result[] = $row;
3494
- }
3495
-
3496
- return $result;
3497
  }
3498
 
3499
- /**
3500
- * @param string $sql sql query
3501
- * @param int $fetchType fetch Type
3502
- *
3503
- * @return array
3504
- */
3505
- function query($sql, $fetchType)
3506
  {
3507
  $result = array(
3508
  'result' => null,
3509
  'message' => '',
3510
  );
3511
- $dataBaseHandle = $this->getDataBaseHandle();
3512
 
3513
- if (!$dataBaseHandle) {
3514
  $result['message'] = '[ERROR] MySQL Query Error: Can not connect to DB';
3515
  return $result;
3516
  }
3517
 
 
3518
  if (isset($_GET['disable_checks'])) {
3519
- $this->localQuery('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0');
3520
- $this->localQuery("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'");
3521
  }
3522
 
3523
- if (isset($_REQUEST['set_names'])) {
3524
- @mysql_query("SET NAMES " . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3525
- @mysql_query("SET CHARACTER SET " . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3526
- @mysql_query("SET CHARACTER_SET_CONNECTION=" . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3527
  }
3528
 
3529
- $fetchMode = MYSQL_ASSOC;
3530
- switch ($fetchType) {
3531
  case 3:
3532
- $fetchMode = MYSQL_BOTH;
3533
- break;
 
3534
  case 2:
3535
- $fetchMode = MYSQL_NUM;
3536
- break;
 
3537
  case 1:
3538
- $fetchMode = MYSQL_ASSOC;
3539
- break;
3540
  default:
3541
- break;
3542
  }
3543
 
3544
- $res = mysql_query($sql, $dataBaseHandle);
3545
 
3546
  $triesCount = 10;
3547
- while (mysql_errno($dataBaseHandle) == 2013) {
3548
  if (!$triesCount--) {
3549
  break;
3550
  }
3551
  // reconnect
3552
- $dataBaseHandle = $this->getDataBaseHandle();
3553
- if ($dataBaseHandle) {
3554
 
3555
- if (isset($_REQUEST['set_names'])) {
3556
- @mysql_query("SET NAMES " . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3557
- @mysql_query("SET CHARACTER SET " . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3558
- @mysql_query("SET CHARACTER_SET_CONNECTION=" . @mysql_real_escape_string($_REQUEST['set_names']), $dataBaseHandle);
3559
- }
3560
 
3561
- // execute query once again
3562
- $res = mysql_query($sql, $dataBaseHandle);
3563
  }
3564
  }
3565
 
3566
- if (($errno = mysql_errno($dataBaseHandle)) != 0) {
3567
- $result['message'] = '[ERROR] Mysql Query Error: ' . $errno . ', ' . mysql_error($dataBaseHandle);
3568
  return $result;
3569
  }
3570
 
3571
- if (!is_resource($res)) {
3572
- $result['result'] = $res;
3573
  return $result;
3574
  }
3575
 
3576
  $fetchedFields = array();
3577
- while (($field = mysql_fetch_field($res)) !== false) {
3578
  $fetchedFields[] = $field;
3579
  }
3580
 
3581
  $rows = array();
3582
- while (($row = mysql_fetch_array($res, $fetchMode)) !== false) {
3583
  $rows[] = $row;
3584
  }
3585
 
 
 
3586
  if (isset($_GET['disable_checks'])) {
3587
- $this->localQuery("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')");
3588
- $this->localQuery("SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS,0)");
3589
  }
3590
 
3591
  $result['result'] = $rows;
3592
  $result['fetchedFields'] = $fetchedFields;
3593
 
3594
- mysql_free_result($res);
3595
  return $result;
3596
  }
3597
 
3598
- /**
3599
- * @return int
3600
- */
3601
- function getLastInsertId()
3602
- {
3603
- return mysql_insert_id($this->dataBaseHandle);
3604
- }
3605
-
3606
- /**
3607
- * @return int
3608
- */
3609
- function getAffectedRows()
3610
- {
3611
- return mysql_affected_rows($this->dataBaseHandle);
3612
- }
3613
-
3614
- /**
3615
- * @return void
3616
- */
3617
- function __destruct()
3618
- {
3619
- if ($this->dataBaseHandle) {
3620
- mysql_close($this->dataBaseHandle);
3621
- }
3622
-
3623
- $this->dataBaseHandle = null;
3624
- }
3625
- }
3626
-
3627
-
3628
-
3629
- class M1_Bridge
3630
- {
3631
- var $_link = null; //mysql connection link
3632
- var $config = null; //config adapter
3633
-
3634
- /**
3635
- * Bridge constructor
3636
- *
3637
- * @param M1_Config_Adapter $config
3638
- * @return M1_Bridge
3639
- */
3640
- function M1_Bridge($config)
3641
- {
3642
- $this->config = $config;
3643
-
3644
- if ($this->getAction() != "savefile" && $this->getAction() != "update") {
3645
- $this->_link = $this->config->connect();
3646
- }
3647
- }
3648
-
3649
- function getTablesPrefix()
3650
- {
3651
- return $this->config->TblPrefix;
3652
- }
3653
-
3654
- function getLink()
3655
- {
3656
- return $this->_link;
3657
- }
3658
-
3659
- function query($sql, $fetchMode)
3660
- {
3661
- return $this->_link->query($sql, $fetchMode);
3662
- }
3663
-
3664
  function getAction()
3665
  {
3666
- if (isset($_GET['action'])) {
3667
- return str_replace('.', '', $_GET['action']);
 
 
3668
  }
3669
-
3670
- return '';
3671
  }
3672
 
3673
  function run()
3674
  {
3675
  $action = $this->getAction();
3676
 
3677
- if ($action != "update") {
3678
  $this->_selfTest();
3679
  }
3680
 
3681
- if ($action == "checkbridge") {
3682
  echo "BRIDGE_OK";
3683
  return;
3684
  }
3685
 
3686
- if ($action == "update") {
3687
  $this->_checkPossibilityUpdate();
3688
  }
3689
 
3690
- $className = "M1_Bridge_Action_" . ucfirst($action);
3691
- if (!class_exists($className)) {
3692
- echo 'ACTION_DO_NOT EXIST' . PHP_EOL;
3693
  die;
3694
  }
3695
-
3696
- $actionObj = new $className();
3697
- @$actionObj->cartType = @$this->config->cartType;
3698
- $actionObj->perform($this);
3699
  $this->_destroy();
3700
  }
3701
 
@@ -3707,16 +3158,16 @@ class M1_Bridge
3707
 
3708
  $dh = @opendir($dir);
3709
 
3710
- if ($dh === false) {
3711
  return false;
3712
  }
3713
 
3714
- while (($entry = readdir($dh)) !== false) {
3715
- if ($entry == "." || $entry == ".." || !@is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
3716
  continue;
3717
  }
3718
 
3719
- if (!$this->isWritable($dir . DIRECTORY_SEPARATOR . $entry)) {
3720
  return false;
3721
  }
3722
  }
@@ -3730,13 +3181,15 @@ class M1_Bridge
3730
 
3731
  function _destroy()
3732
  {
3733
- $this->_link = null;
 
 
3734
  }
3735
 
3736
  function _checkPossibilityUpdate()
3737
  {
3738
  if (!is_writable(M1_STORE_BASE_DIR . "/" . M1_BRIDGE_DIRECTORY_NAME . "/")) {
3739
- die("ERROR_TRIED_TO_PERMISSION" . M1_STORE_BASE_DIR . "/" . M1_BRIDGE_DIRECTORY_NAME . "/");
3740
  }
3741
 
3742
  if (!is_writable(M1_STORE_BASE_DIR . "/". M1_BRIDGE_DIRECTORY_NAME . "/bridge.php")) {
@@ -3746,32 +3199,19 @@ class M1_Bridge
3746
 
3747
  function _selfTest()
3748
  {
3749
- if (!isset($_GET['ver']) || $_GET['ver'] != M1_BRIDGE_VERSION) {
3750
  die ('ERROR_BRIDGE_VERSION_NOT_SUPPORTED');
3751
  }
3752
 
3753
-
3754
-
3755
-
3756
-
3757
-
3758
-
3759
-
3760
-
3761
-
3762
-
3763
-
3764
-
3765
-
3766
- define("M1_TOKEN", "sadsadsadsadsadsa");
3767
  // good :)
3768
  } else {
3769
  die('ERROR_INVALID_TOKEN');
3770
  }
3771
 
3772
- if ((!isset($_GET['storetype']) || $_GET['storetype'] == 'target') && $this->getAction() == 'checkbridge') {
3773
 
3774
- if (trim($this->config->imagesDir) != "") {
3775
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->imagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3776
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->imagesDir, 0777, true)) {
3777
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->imagesDir);
@@ -3783,7 +3223,7 @@ define("M1_TOKEN", "sadsadsadsadsadsa");
3783
  }
3784
  }
3785
 
3786
- if (trim($this->config->categoriesImagesDir) != "") {
3787
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->categoriesImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3788
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->categoriesImagesDir, 0777, true)) {
3789
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->categoriesImagesDir);
@@ -3795,7 +3235,7 @@ define("M1_TOKEN", "sadsadsadsadsadsa");
3795
  }
3796
  }
3797
 
3798
- if (trim($this->config->productsImagesDir) != "") {
3799
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->productsImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3800
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->productsImagesDir, 0777, true)) {
3801
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->productsImagesDir);
@@ -3807,7 +3247,7 @@ define("M1_TOKEN", "sadsadsadsadsadsa");
3807
  }
3808
  }
3809
 
3810
- if (trim($this->config->manufacturersImagesDir) != "") {
3811
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3812
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir, 0777, true)) {
3813
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir);
@@ -3829,26 +3269,13 @@ define('M1_BRIDGE_VERSION', '21');
3829
  define('M1_BRIDGE_DIRECTORY_NAME', basename(getcwd()));
3830
 
3831
  ini_set('display_errors', 1);
3832
- if (substr(phpversion(), 0, 1) == 5) {
3833
  error_reporting(E_ALL & ~E_STRICT);
3834
  } else {
3835
  error_reporting(E_ALL);
3836
  }
3837
 
3838
-
3839
-
3840
-
3841
-
3842
-
3843
-
3844
-
3845
-
3846
-
3847
-
3848
-
3849
-
3850
-
3851
- define("M1_TOKEN", "sadsadsadsadsadsa");
3852
 
3853
  function stripslashes_array($array) {
3854
  return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
@@ -3861,14 +3288,15 @@ function getPHPExecutable() {
3861
  // we need this for XAMPP (Windows)
3862
  if (isset($_SERVER["WINDIR"]) && strstr($path, 'php.exe') && file_exists($path) && is_file($path)) {
3863
  return $path;
3864
- } else {
 
3865
  $phpExecutable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : "");
3866
  if (file_exists($phpExecutable) && is_file($phpExecutable)) {
3867
  return $phpExecutable;
3868
  }
3869
  }
3870
  }
3871
- return false;
3872
  }
3873
 
3874
  if (!isset($_SERVER))
@@ -3881,7 +3309,8 @@ if (!isset($_SERVER))
3881
  $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
3882
  }
3883
 
3884
- if (get_magic_quotes_gpc()) {
 
3885
  $_COOKIE = stripslashes_array($_COOKIE);
3886
  $_FILES = stripslashes_array($_FILES);
3887
  $_GET = stripslashes_array($_GET);
@@ -3899,10 +3328,10 @@ if (isset($_SERVER['SCRIPT_FILENAME'])) {
3899
  //Windows IIS
3900
  define("M1_STORE_BASE_DIR", preg_replace('/[^\/\\\]*[\/\\\][^\/\\\]*$/', '', realpath(dirname(__FILE__) . "/../")));
3901
  }
3902
- $adapter = new M1_Config_Adapter();
3903
- $bridge = new M1_Bridge($adapter->create());
3904
 
3905
- if (!$bridge->getLink()) {
 
 
3906
  die ('ERROR_BRIDGE_CANT_CONNECT_DB');
3907
  }
3908
 
42
 
43
  class M1_Bridge_Action_Getconfig
44
  {
45
+ function parseMemoryLimit($val) {
 
 
46
  $last = strtolower($val[strlen($val)-1]);
47
  switch($last) {
48
  case 'g':
56
  return $val;
57
  }
58
 
59
+ function getMemoryLimit() {
 
60
  $memoryLimit = trim(@ini_get('memory_limit'));
61
+ if( strlen($memoryLimit) === 0 ) {
62
  $memoryLimit = "0";
63
  }
64
  $memoryLimit = $this->parseMemoryLimit($memoryLimit);
65
 
66
  $maxPostSize = trim(@ini_get('post_max_size'));
67
+ if( strlen($maxPostSize) === 0 ) {
68
  $maxPostSize = "0";
69
  }
70
  $maxPostSize = $this->parseMemoryLimit($maxPostSize);
71
 
72
  $suhosinMaxPostSize = trim(@ini_get('suhosin.post.max_value_length'));
73
+ if( strlen($suhosinMaxPostSize) === 0 ) {
74
  $suhosinMaxPostSize = "0";
75
  }
76
  $suhosinMaxPostSize = $this->parseMemoryLimit($suhosinMaxPostSize);
77
 
78
+ if ( $suhosinMaxPostSize == 0 ) {
79
  $suhosinMaxPostSize = $maxPostSize;
80
  }
81
 
82
+ if ( $maxPostSize == 0 ){
83
  $suhosinMaxPostSize = $maxPostSize = $memoryLimit;
84
  }
85
 
86
+ return min ( $suhosinMaxPostSize, $maxPostSize, $memoryLimit );
87
  }
88
+
89
  function isZlibSupported()
90
  {
91
  return function_exists('gzdecode');
92
  }
93
 
94
+ function perform($bridge) {
95
+ if(!defined("DEFAULT_LANGUAGE_ISO2")) {
96
+ define("DEFAULT_LANGUAGE_ISO2",""); //variable for Interspire cart
 
97
  }
98
 
99
  $result = array(
100
  "images" => array(
101
+ "imagesPath" => $bridge->config->imagesDir, // path to images folder - relative to store root
102
  "categoriesImagesPath" => $bridge->config->categoriesImagesDir,
103
  "categoriesImagesPaths" => $bridge->config->categoriesImagesDirs,
104
  "productsImagesPath" => $bridge->config->productsImagesDir,
130
  $languages = array();
131
 
132
  while ($dirEntry = readdir($dirHandle)) {
133
+ if (!is_dir(M1_STORE_BASE_DIR . 'language/' . $dirEntry) || $dirEntry == '.' || $dirEntry == '..' || strpos($dirEntry, "_") !== false ) {
134
  continue;
135
  }
136
 
143
  $cnfile = "config.php";
144
  }
145
 
146
+ if( !file_exists( M1_STORE_BASE_DIR . 'language/' . $dirEntry . '/'. $cnfile ) ) {
147
  continue;
148
  }
149
 
150
  $str = file_get_contents(M1_STORE_BASE_DIR . 'language/' . $dirEntry . '/'.$cnfile);
151
  preg_match("/".preg_quote('$langName')."[\s]*=[\s]*[\"\'](.*)[\"\'];/", $str, $match);
152
 
153
+ if( isset($match[1]) ) {
154
  $lang['name'] = $match[1];
155
  $languages[] = $lang;
156
  }
218
  * @var $fileExclude - name file in format pregmatch
219
  */
220
 
221
+ function _removeGarbage( $dirs = array(), $fileExclude = '' )
222
  {
223
  $result = true;
224
 
225
+ foreach($dirs as $dir) {
226
 
227
+ if( !file_exists( $dir ) ){
228
  continue;
229
  }
230
 
231
  $dirHandle = opendir($dir);
232
 
233
  while (false !== ($file = readdir($dirHandle))) {
234
+ if ( $file == "." || $file == ".." ) {
235
  continue;
236
  }
237
 
238
+ if( (trim($fileExclude) != '') && preg_match("/^" .$fileExclude . "?$/",$file) ) {
239
  continue;
240
  }
241
 
242
+ if( is_dir( $dir . $file ) ) {
243
  continue;
244
  }
245
 
246
  if (!unlink($dir . $file)) {
247
+ $result=false;
248
  }
249
  }
 
250
  closedir($dirHandle);
251
  }
252
 
253
  if ($result) {
254
+ print "OK";
255
  } else {
256
+ print "ERROR";
257
  }
258
 
259
  return $result;
280
  foreach ($indexes as $index) {
281
  exec($phpExecutable . " shell/indexer.php --reindex $index", $out);
282
  }
283
+ print "OK";
284
  } else {
285
  echo 'Error: can not find PHP executable file.';
286
  }
287
 
288
+ print "OK";
289
  }
290
+
291
  function _InterspireClearCache()
292
  {
293
  $res = true;
294
  $file = M1_STORE_BASE_DIR . 'cache' . DIRECTORY_SEPARATOR . 'datastore' . DIRECTORY_SEPARATOR . 'RootCategories.php';
295
+ if( file_exists( $file ) ) {
296
  if (!unlink($file)) {
297
  $res = false;
298
  }
307
  function _CubecartClearCache()
308
  {
309
  $ok = true;
310
+
311
+ if( file_exists(M1_STORE_BASE_DIR . 'cache') ) {
312
  $dirHandle = opendir(M1_STORE_BASE_DIR . 'cache/');
313
 
314
  while (false !== ($file = readdir($dirHandle))) {
315
+ if ($file != "." && $file != ".." && !preg_match("/^index\.html?$/",$file) && !preg_match("/^\.htaccess?$/",$file) ) {
316
+ if( is_file( M1_STORE_BASE_DIR . 'cache/' . $file ) ) {
317
+ if (!unlink(M1_STORE_BASE_DIR . 'cache/' . $file)) $ok=false;
 
 
318
  }
319
  }
320
  }
326
  unlink(M1_STORE_BASE_DIR.'includes/extra/admin_cat_cache.txt');
327
  }
328
 
329
+ if ($ok) print "OK";
330
+ else print "ERROR";
 
 
 
331
  }
332
 
333
  function _PrestashopClearCache()
388
  {
389
  $pathToImages = 'components/com_virtuemart/shop_image';
390
 
391
+ $dir_parts = explode("/", $pathToImages);
392
  $path = M1_STORE_BASE_DIR;
393
+ foreach ($dir_parts as $item) {
394
  if ($item == '') {
395
  continue;
396
  }
435
 
436
  $this->_removeGarbage($dirs, '\.htaccess');
437
  }
438
+
439
  function _CscartClearCache()
440
  {
441
+ $res = true;
442
+
443
  $dir = M1_STORE_BASE_DIR . 'var/cache/';
444
  $res = $this->removeDirRec($dir);
445
 
446
+ if($res){
447
+ print "OK\n";
448
  } else {
449
+ print "ERROR!!!\n";
450
  }
451
  }
452
 
453
+
454
  function _Prestashop15ClearCache()
455
  {
456
  $dirs = array(
465
  function removeDirRec($dir)
466
  {
467
  $result = true;
 
468
  if ($objs = glob($dir."/*")) {
469
+ foreach($objs as $obj) {
470
+ if(is_dir($obj)){
471
  //print "IS DIR! START RECURSIVE FUNCTION.\n";
472
  $this->removeDirRec($obj);
473
  } else {
474
+ if(!unlink($obj)){
475
  //print "!UNLINK FILE: ".$obj."\n";
476
  $result = false;
477
  }
478
  }
479
  }
480
  }
481
+ if(!rmdir($dir)){
482
  //print "ERROR REMOVE DIR: ".$dir."\n";
483
  $result = false;
484
  }
 
485
  return $result;
486
  }
487
  }
501
  {
502
  function perform($bridge) {
503
  $result = array();
 
504
  foreach ($_POST['files'] as $fileInfo) {
505
+ $result[$fileInfo['id']] = $this->_saveFile($fileInfo['source'], $fileInfo['target'], (int)$fileInfo['width'], (int)$fileInfo['height'], $fileInfo['local_source']);
 
 
 
 
 
 
506
  }
507
 
508
  echo serialize($result);
791
 
792
  function _saveFile($source, $destination, $width, $height, $local = '')
793
  {
794
+ if ( trim($local) != '' ) {
795
 
796
+ if( $this->_copyLocal($local, $destination, $width, $height) ) {
797
  return "OK";
798
  }
799
 
800
  }
801
 
802
+ if( !preg_match('/^https?:\/\//i', $source) ) {
803
  $result = $this->_createFile($source, $destination);
804
+ } elseif( $this->_isSameHost($source) ) {
805
  $result = $this->_saveFileLocal($source, $destination);
806
  } else {
807
  $result = $this->_saveFileCurl($source, $destination);
808
  }
809
 
810
+ if ( $result != "OK" ) {
811
  return $result;
812
  }
813
 
814
  $destination = M1_STORE_BASE_DIR . $destination;
815
 
816
+ if( $width != 0 && $height != 0 ) {
817
  $this->_scaled2( $destination, $width, $height );
818
  }
819
+
820
+ if ( $this->cartType == "Prestashop11" ) {
821
  // convert destination.gif(png) to destination.jpg
822
  $imageGd = $this->_loadImage($destination);
823
 
824
+ if( $imageGd === false ) {
825
  return $result;
826
  }
827
 
828
+ if( !$this->_convert($imageGd, $destination, IMAGETYPE_JPEG, 'jpg') ){
829
  return "CONVERT FAILED";
830
  }
831
  }
842
  return false;
843
  }
844
 
845
+ if( $width != 0 && $height != 0 ) {
846
+ $this->_scaled2( $destination, $width, $height );
847
  }
848
 
849
  return true;
850
  }
851
 
852
+ function _loadImage( $filename, $skipJpg = true )
853
  {
854
+ $image_info = @getimagesize($filename);
855
+ if( $image_info === false ) {
856
  return false;
857
  }
858
 
859
+ $this->_imageType = $image_info[2];
860
 
861
+ switch ( $this->_imageType ) {
862
+ case IMAGETYPE_JPEG :
863
  $image = imagecreatefromjpeg($filename);
864
  break;
865
+ case IMAGETYPE_GIF :
866
  $image = imagecreatefromgif($filename);
867
  break;
868
+ case IMAGETYPE_PNG :
869
  $image = imagecreatefrompng($filename);
870
  break;
871
  default:
872
  return false;
873
  }
874
 
875
+ if( $skipJpg && ($this->_imageType == IMAGETYPE_JPEG) ) {
876
  return false;
877
  }
878
 
879
  return $image;
880
  }
881
 
882
+ function _saveImage( $image, $filename, $image_type=IMAGETYPE_JPEG, $compression=85, $permissions=null )
883
+ {
884
  $result = true;
885
+ if( $image_type == IMAGETYPE_JPEG ) {
886
+ $result = imagejpeg($image,$filename,$compression);
887
+ } elseif( $image_type == IMAGETYPE_GIF ) {
888
+ $result = imagegif($image,$filename);
889
+ } elseif( $image_type == IMAGETYPE_PNG ) {
890
+ $result = imagepng($image,$filename);
891
  }
892
 
893
+ if( $permissions != null) {
894
+ chmod($filename,$permissions);
895
  }
896
 
897
+ imagedestroy( $image );
898
 
899
  return $result;
900
  }
901
 
902
  function _createFile($source, $destination)
903
  {
904
+ if( $this->_create_dir(dirname($destination)) !== false ) {
905
  $destination = M1_STORE_BASE_DIR . $destination;
906
  $body = base64_decode($source);
907
+ if( $body === false || file_put_contents($destination, $body) === false ) {
908
  return '[BRIDGE ERROR] File save failed!';
909
  }
910
 
919
  $srcInfo = parse_url($source);
920
  $src = rtrim($_SERVER['DOCUMENT_ROOT'], "/") . $srcInfo['path'];
921
 
922
+ if( $this->_create_dir(dirname($destination)) !== false ) {
923
  $dst = M1_STORE_BASE_DIR . $destination;
924
 
925
+ if ( !@copy($src, $dst) ) {
926
  return $this->_saveFileCurl($source, $destination);
927
  }
928
 
936
  function _saveFileCurl($source, $destination)
937
  {
938
  $source = $this->_escapeSource($source);
939
+ if( $this->_create_dir(dirname($destination)) !== false ) {
940
  $destination = M1_STORE_BASE_DIR . $destination;
941
 
942
  $ch = curl_init();
948
  curl_exec($ch);
949
  $httpResponseCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
950
 
951
+ if($httpResponseCode != 200) {
952
  curl_close($ch);
953
  return "[BRIDGE ERROR] Bad response received from source, HTTP code $httpResponseCode!";
954
  }
955
 
956
  $dst = @fopen($destination, "wb");
957
+ if( $dst === false ) {
958
  return "[BRIDGE ERROR] Can't create $destination!";
959
  }
960
  curl_setopt($ch, CURLOPT_NOBODY, false);
961
  curl_setopt($ch, CURLOPT_FILE, $dst);
962
  curl_setopt($ch, CURLOPT_HTTPGET, true);
963
  curl_exec($ch);
964
+ if( ($error_no = curl_errno($ch)) != CURLE_OK ) {
965
  return "[BRIDGE ERROR] $error_no: " . curl_error($ch);
966
  }
967
  curl_close($ch);
968
  @chmod($destination, 0777);
969
+
970
  return "OK";
971
 
972
  } else {
980
  }
981
 
982
  function _create_dir($dir) {
983
+ $dir_parts = explode("/", $dir);
984
  $path = M1_STORE_BASE_DIR;
985
+ foreach ($dir_parts as $item) {
986
  if ($item == '') {
987
  continue;
988
  }
989
  $path .= $item . DIRECTORY_SEPARATOR;
990
+ if(!is_dir($path)) {
991
  $res = @mkdir($path);
992
+ if(!$res) {
993
  return false;
994
  }
995
  }
1002
  {
1003
  $srcInfo = parse_url($source);
1004
 
1005
+ if ( preg_match('/\.php$/', $srcInfo['path'] ) ) {
1006
  return false;
1007
  }
1008
 
1009
  $hostInfo = parse_url("http://" . $_SERVER['HTTP_HOST']);
1010
+ if( @$srcInfo['host'] == $hostInfo['host'] ) {
1011
  return true;
1012
  }
1013
 
1022
  *
1023
  * @return true if success or false if no
1024
  */
1025
+ function _convert( $image, $filename, $type = IMAGETYPE_JPEG, $extension = '' )
1026
  {
1027
  $end = pathinfo($filename, PATHINFO_EXTENSION);
1028
 
1029
+ if( $extension == '' ) {
1030
  $extension = image_type_to_extension($type, false);
1031
  }
1032
 
1033
+ if( $end == $extension ) {
1034
  return true;
1035
  }
1036
 
1052
  return $this->_saveImage($newImage, $pathSave, $type);
1053
  }
1054
 
1055
+ function _scaled( $destination, $width, $height )
1056
  {
1057
  $image = $this->_loadImage($destination, false);
1058
 
1059
+ if( $image === false ) {
1060
  return;
1061
  }
1062
 
1063
  $originWidth = imagesx( $image );
1064
  $originHeight = imagesy( $image );
1065
+
1066
  $rw = (int)$height * (int)$originWidth / (int)$originHeight;
1067
  $useHeight = ($rw <= $width);
1068
 
1069
+ if ( $useHeight ) {
1070
  $width = (int)$rw;
1071
  } else {
1072
  $height = (int)((int)($width) * (int)($originHeight) / (int)($originWidth));
1073
  }
1074
 
1075
+ $new_image = imagecreatetruecolor($width, $height);
1076
+ $white = imagecolorallocate($new_image, 255, 255, 255);
1077
+ imagefill($new_image, 0, 0, $white);
1078
+ imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $originWidth, $originHeight);
1079
+ imagecolortransparent($new_image, $white);
1080
+
1081
+ return $this->_saveImage($new_image, $destination, $this->_imageType, 100)? "OK" : "CAN'T SCALE IMAGE";
1082
  }
1083
 
1084
  //scaled2 method optimizet for prestashop
1088
 
1089
  $sourceImage = $this->_loadImage($destination, false);
1090
 
1091
+ if( $sourceImage === false ) {
1092
  return "IMAGE NOT SUPPORTED";
1093
  }
1094
 
1095
+ $sourceWidth = imagesx( $sourceImage );
1096
+ $sourceHeight = imagesy( $sourceImage );
1097
 
1098
  $widthDiff = $destWidth / $sourceWidth;
1099
  $heightDiff = $destHeight / $sourceHeight;
1100
 
1101
+ if ( $widthDiff > 1 && $heightDiff > 1 )
1102
+ {
1103
  $nextWidth = $sourceWidth;
1104
  $nextHeight = $sourceHeight;
1105
  } else {
1106
  if (intval($method) == 2 || (intval($method) == 0 AND $widthDiff > $heightDiff)) {
1107
  $nextHeight = $destHeight;
1108
  $nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight);
1109
+ $destWidth = ((intval($method) == 0 )? $destWidth : $nextWidth);
1110
  } else {
1111
  $nextWidth = $destWidth;
1112
  $nextHeight = intval($sourceHeight * $destWidth / $sourceWidth);
1124
 
1125
  imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight);
1126
  imagecolortransparent($destImage, $white);
1127
+
1128
+ return $this->_saveImage($destImage, $destination, $this->_imageType, 100)? "OK" : "CAN'T SCALE IMAGE";
1129
  }
1130
  }
1131
 
1133
  {
1134
  function perform($bridge)
1135
  {
1136
+ if(isset($_POST['query']) && isset($_POST['fetchMode'])) {
1137
+
1138
+ $query = base64_decode( $_POST['query'] );
1139
 
1140
  $res = $bridge->query($query, (int)$_POST['fetchMode']);
1141
 
1142
+ if(is_array($res['result']) || is_bool($res['result'])) {
1143
+ $result = serialize(array(
1144
  'res' => $res['result'],
1145
  'fetchedFields' => @$res['fetchedFields'],
1146
+ 'insertId' => mysql_insert_id($bridge->getLink()),
1147
+ 'affectedRows' => mysql_affected_rows($bridge->getLink()),
1148
  ));
1149
 
1150
  echo base64_encode($result);
1151
+
1152
  } else {
1153
  echo base64_encode($res['message']);
1154
  }
1161
 
1162
  class M1_Config_Adapter
1163
  {
1164
+ var $Host = "localhost";
1165
  var $Port = null;//"3306";
1166
+ var $Username = "root";
1167
+ var $Password = "";
1168
+ var $Dbname = "";
1169
+ var $TblPrefix = "";
1170
+
1171
+ var $cartType = "Oscommerce22ms2";
1172
+ var $imagesDir = "";
1173
+ var $categoriesImagesDir = "";
1174
+ var $productsImagesDir = "";
1175
+ var $manufacturersImagesDir = "";
1176
+ var $categoriesImagesDirs = "";
1177
+ var $productsImagesDirs = "";
1178
+ var $manufacturersImagesDirs= "";
1179
 
1180
  var $languages = array();
1181
  var $cartVars = array();
1186
  return null;
1187
  }
1188
 
1189
+ $cartType = M1_Config_Adapter::detectCartType();
1190
+ $className = "M1_Config_Adapter_" . $cartType;
 
1191
  $obj = new $className();
1192
  $obj->cartType = $cartType;
 
1193
  return $obj;
1194
  }
1195
 
1196
+ function detectCartType()
1197
  {
1198
  // Zencart137
1199
+ if(file_exists(M1_STORE_BASE_DIR
1200
+ . "includes" . DIRECTORY_SEPARATOR
1201
+ . "configure.php")
1202
+ && file_exists(M1_STORE_BASE_DIR
1203
+ . "ipn_main_handler.php") ) {
1204
  return "Zencart137";
1205
  }
1206
 
1207
  //osCommerce
1208
+ if(file_exists(M1_STORE_BASE_DIR
1209
+ . "includes" . DIRECTORY_SEPARATOR
1210
+ . "configure.php")
1211
+ && !file_exists(M1_STORE_BASE_DIR
1212
+ . "includes" . DIRECTORY_SEPARATOR
1213
+ . "toc_constants.php")/* is if not tomatocart */ ) {
1214
+
1215
  return "Oscommerce22ms2";
1216
  }
1217
 
1218
+ if(file_exists(M1_STORE_BASE_DIR . "/includes/configure.php")) {
1219
  return "Gambio";
1220
  }
1221
 
1222
  //JooCart
1223
+ if(file_exists(M1_STORE_BASE_DIR . '/components/com_opencart/opencart.php')) {
1224
  return 'JooCart';
1225
  }
1226
 
1227
  //ACEShop
1228
+ if(file_exists(M1_STORE_BASE_DIR . '/components/com_aceshop/aceshop.php')) {
1229
  return 'AceShop';
1230
  }
1231
 
1232
  //Litecommerce
1233
+ if ((file_exists(M1_STORE_BASE_DIR .'/etc/config.php')) ||
1234
+ (file_exists(M1_STORE_BASE_DIR .'/modules/lc_connector/litecommerce/etc/config.php')) ) {
 
1235
  return "Litecommerce";
1236
  }
1237
 
1238
  //Prestashop11
1239
  if (file_exists(M1_STORE_BASE_DIR . "config/config.inc.php")) {
1240
+ if (file_exists(M1_STORE_BASE_DIR . "cache/class_index.php"))
1241
+ {
1242
  return "Prestashop15";
1243
  }
1244
  return "Prestashop11";
1269
  }
1270
 
1271
  //Cscart203 - 3
1272
+ if ( file_exists(M1_STORE_BASE_DIR . "config.local.php") || file_exists(M1_STORE_BASE_DIR . "partner.php") ) {
1273
+ //return "Cscart203";
1274
  return "Cscart203";
1275
  }
1276
 
1277
  //Opencart14
1278
+ if ( (file_exists(M1_STORE_BASE_DIR . "system/startup.php") || (file_exists(M1_STORE_BASE_DIR . "common.php") ) || (file_exists(M1_STORE_BASE_DIR . "library/locator.php"))) && file_exists(M1_STORE_BASE_DIR . "config.php") ) {
 
 
 
 
1279
  return "Opencart14";
1280
  }
1281
 
1285
  }
1286
 
1287
  //XCart
1288
+ if(file_exists(M1_STORE_BASE_DIR . "config.php")) {
1289
  return "XCart";
1290
  }
1291
 
1292
  //LemonStand
1293
+ if(file_exists(M1_STORE_BASE_DIR . "boot.php")) {
1294
  return "LemonStand";
1295
  }
1296
+
1297
  //Interspire
1298
  if (file_exists(M1_STORE_BASE_DIR . "config/config.php")) {
1299
  return "Interspire";
1300
+ }
1301
+
1302
  //Squirrelcart242
1303
  if (file_exists(M1_STORE_BASE_DIR . 'squirrelcart/config.php')) {
1304
  return "Squirrelcart242";
1305
  }
1306
+
1307
  //Shopscript WebAsyst
1308
  if (file_exists(M1_STORE_BASE_DIR . 'kernel/wbs.xml')) {
1309
  return "WebAsyst";
1325
  }
1326
 
1327
  //Summercart3
1328
+ if (file_exists(M1_STORE_BASE_DIR . 'sclic.lic') && file_exists(M1_STORE_BASE_DIR . 'include/miphpf/Config.php') ) {
1329
  return "Summercart3";
1330
  }
1331
 
1332
  //XtcommerceVeyton
1333
+ if (file_exists(M1_STORE_BASE_DIR . 'conf/config.php') ) {
1334
  return "XtcommerceVeyton";
1335
  }
1336
 
1337
  //Ubercart
1338
+ if( file_exists( M1_STORE_BASE_DIR . 'sites/default/settings.php' ) ) {
1339
+ if( file_exists( M1_STORE_BASE_DIR . '/modules/ubercart/uc_store/includes/coder_review_uc3x.inc' ) )
1340
+ return "Ubercart3";
1341
+ elseif ( file_exists(M1_STORE_BASE_DIR . 'sites/all/modules/commerce/includes/commerce.controller.inc') )
1342
+ return "DrupalCommerce";
 
 
1343
  return "Ubercart";
1344
  }
1345
 
1346
  //Woocommerce
1347
+ if (file_exists(M1_STORE_BASE_DIR . 'wp-config.php') &&
1348
+ file_exists(M1_STORE_BASE_DIR . 'wp-content/plugins/woocommerce/woocommerce.php')) {
 
1349
  return 'Woocommerce';
1350
  }
1351
 
1352
+ if (file_exists(dirname(M1_STORE_BASE_DIR) . '/wp-config.php') &&
1353
+ file_exists(M1_STORE_BASE_DIR . 'wp-content/plugins/woocommerce/woocommerce.php')) {
 
1354
  return 'Woocommerce';
1355
  }
1356
 
1357
  //WPecommerce
1358
+ if( file_exists( M1_STORE_BASE_DIR . 'wp-config.php' ) ) {
1359
  return 'WPecommerce';
1360
  }
1361
 
1365
  }
1366
 
1367
  //HHGMultistore
1368
+ if( file_exists( M1_STORE_BASE_DIR . 'core/config/configure.php' ) ) {
1369
  return 'Hhgmultistore';
1370
  }
1371
 
1372
  //SunShop
1373
+ if( file_exists(M1_STORE_BASE_DIR . "include" . DIRECTORY_SEPARATOR . "config.php") || file_exists(M1_STORE_BASE_DIR . "include" . DIRECTORY_SEPARATOR . "db_mysql.php") ) {
 
 
1374
  return "Sunshop4";
1375
  }
1376
 
1377
  //Tomatocart
1378
+ if(file_exists(M1_STORE_BASE_DIR
1379
+ . "includes" . DIRECTORY_SEPARATOR
1380
+ . "configure.php")
1381
+ && file_exists(M1_STORE_BASE_DIR
1382
+ . "includes" . DIRECTORY_SEPARATOR
1383
+ . "toc_constants.php")) {
1384
  return 'Tomatocart';
1385
  }
1386
 
1389
 
1390
  function getAdapterPath($cartType)
1391
  {
1392
+ return M1_STORE_BASE_DIR .
1393
+ M1_BRIDGE_DIRECTORY_NAME . DIRECTORY_SEPARATOR .
1394
+ "app" . DIRECTORY_SEPARATOR .
1395
+ "class" . DIRECTORY_SEPARATOR .
1396
+ "config_adapter" . DIRECTORY_SEPARATOR . $cartType . ".php";
1397
  }
1398
 
1399
  function setHostPort($source)
1400
  {
1401
  $source = trim($source);
1402
 
1403
+ if( $source == '' ) {
1404
+ $this->Host = "localhost";
1405
  return;
1406
  }
1407
 
1408
  $conf = explode(":", $source);
1409
+ if( isset($conf[0]) && isset($conf[1]) ) {
1410
 
 
1411
  $this->Host = $conf[0];
1412
+ $this->Port = $conf[1];
 
 
 
 
 
 
 
1413
 
1414
+ } elseif( $source[0] == '/' ) {
 
 
 
 
 
 
 
 
 
 
1415
 
1416
+ $this->Host = "localhost";
1417
+ $this->Port = $source;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1418
 
1419
+ } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1420
 
1421
+ $this->Host = $source;
1422
 
 
 
1423
  }
 
 
1424
  }
1425
 
 
 
 
1426
  function connect()
1427
  {
1428
  $triesCount = 10;
1429
  $link = null;
 
 
1430
 
1431
+ $host = $this->Host.($this->Port? ':'.$this->Port : '');
1432
  while (!$link) {
1433
  if (!$triesCount--) {
1434
  break;
1435
  }
1436
+ $link = @mysql_connect($host, $this->Username, $this->Password);
1437
+ if (!$link) {
 
1438
  sleep(5);
1439
  }
1440
  }
1441
 
1442
+ if( $link ) {
1443
+ mysql_select_db($this->Dbname, $link);
 
 
1444
  }
1445
 
1446
  return $link;
1447
  }
1448
 
1449
+ function getCartVersionFromDb($field, $tableName, $where)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1450
  {
1451
+ $_link = null;
1452
+ $version = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1453
 
1454
+ $_link = $this->connect();
1455
+ if( !$_link ) {
1456
+ return '[ERROR] MySQL Query Error: Can not connect to DB';
1457
  }
1458
 
1459
+ $sql = "SELECT " . $field . " AS version FROM " . $this->TblPrefix . $tableName . " WHERE " . $where;
 
1460
 
1461
+ $query = mysql_query($sql, $_link);
 
 
 
 
 
 
 
 
 
 
 
1462
 
1463
+ if ( $query !== false ) {
1464
+ $row = mysql_fetch_assoc($query);
 
 
 
 
 
1465
 
1466
+ $version = $row['version'];
 
 
 
 
 
 
1467
  }
1468
 
1469
+ return $version;
1470
+ }
 
1471
  }
1472
 
 
1473
  class M1_Config_Adapter_Cscart203 extends M1_Config_Adapter
1474
  {
1475
  function M1_Config_Adapter_Cscart203()
2985
  }
2986
 
2987
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2988
 
2989
+ class M1_Bridge
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2990
  {
2991
+ var $_link = null; //mysql connection link
2992
+ var $_res = null; // mysql query result
2993
+ var $_tblPrefix = ""; // table prefix
2994
  var $config = null; // config adapter
 
 
2995
 
2996
  /**
2997
+ * Bridge constructor
2998
  *
2999
  * @param M1_Config_Adapter $config
3000
+ * @return M1_Bridge
3001
  */
3002
+ function M1_Bridge($config)
3003
  {
3004
  $this->config = $config;
 
 
 
 
 
 
 
 
 
 
3005
 
3006
+ if($this->getAction() != "savefile" && $this->getAction() != "update" ) {
3007
+ $this->_link = $this->config->connect();
 
 
3008
  }
 
 
3009
  }
3010
 
3011
+ function getTablesPrefix()
 
 
 
3012
  {
3013
+ return $this->_tblPrefix;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3014
  }
3015
 
3016
+ function getLink()
 
 
 
 
 
3017
  {
3018
+ return $this->_link;
 
 
 
 
 
 
 
 
 
 
 
 
 
3019
  }
3020
 
3021
+ function query($sql, $fetchMode)
 
 
 
 
 
 
3022
  {
3023
  $result = array(
3024
  'result' => null,
3025
  'message' => '',
3026
  );
 
3027
 
3028
+ if (!$this->_link) {
3029
  $result['message'] = '[ERROR] MySQL Query Error: Can not connect to DB';
3030
  return $result;
3031
  }
3032
 
3033
+
3034
  if (isset($_GET['disable_checks'])) {
3035
+ mysql_query('SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0', $this->_link);
3036
+ mysql_query("SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'", $this->_link);
3037
  }
3038
 
3039
+ if(isset($_REQUEST['set_names'])) {
3040
+ @mysql_query("SET NAMES " . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link);
3041
+ @mysql_query("SET CHARACTER SET " . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link );
3042
+ @mysql_query("SET CHARACTER_SET_CONNECTION=" . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link );
3043
  }
3044
 
3045
+ $fetch_mode = MYSQL_ASSOC;
3046
+ switch ($fetchMode) {
3047
  case 3:
3048
+ $fetch_mode = MYSQL_BOTH;
3049
+ break;
3050
+
3051
  case 2:
3052
+ $fetch_mode = MYSQL_NUM;
3053
+ break;
3054
+
3055
  case 1:
3056
+ $fetch_mode = MYSQL_ASSOC;
 
3057
  default:
3058
+ break;
3059
  }
3060
 
3061
+ $this->_res = mysql_query($sql, $this->_link);
3062
 
3063
  $triesCount = 10;
3064
+ while (mysql_errno($this->_link) == 2013) {
3065
  if (!$triesCount--) {
3066
  break;
3067
  }
3068
  // reconnect
3069
+ $this->_link = $this->config->connect();
3070
+ if ($this->_link) {
3071
 
3072
+ if(isset($_REQUEST['set_names'])) {
3073
+ @mysql_query("SET NAMES " . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link);
3074
+ @mysql_query("SET CHARACTER SET " . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link );
3075
+ @mysql_query("SET CHARACTER_SET_CONNECTION=" . @mysql_real_escape_string($_REQUEST['set_names']), $this->_link );
3076
+ }
3077
 
3078
+ // execute query once again
3079
+ $this->_res = mysql_query($sql, $this->_link);
3080
  }
3081
  }
3082
 
3083
+ if( ($errno = mysql_errno($this->_link)) != 0 ) {
3084
+ $result['message'] = '[ERROR] Mysql Query Error: '.$errno.', ' . mysql_error($this->_link);
3085
  return $result;
3086
  }
3087
 
3088
+ if(!is_resource($this->_res)) {
3089
+ $result['result'] = $this->_res;
3090
  return $result;
3091
  }
3092
 
3093
  $fetchedFields = array();
3094
+ while ( ($field = mysql_fetch_field($this->_res)) !== false ) {
3095
  $fetchedFields[] = $field;
3096
  }
3097
 
3098
  $rows = array();
3099
+ while( ($row = mysql_fetch_array($this->_res, $fetch_mode)) !== false) {
3100
  $rows[] = $row;
3101
  }
3102
 
3103
+ mysql_free_result($this->_res);
3104
+
3105
  if (isset($_GET['disable_checks'])) {
3106
+ mysql_query("SET SQL_MODE=IFNULL(@OLD_SQL_MODE,'')", $this->_link);
3107
+ mysql_query("SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS,0)", $this->_link);
3108
  }
3109
 
3110
  $result['result'] = $rows;
3111
  $result['fetchedFields'] = $fetchedFields;
3112
 
 
3113
  return $result;
3114
  }
3115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3116
  function getAction()
3117
  {
3118
+ if(isset($_GET['action'])) {
3119
+ return str_replace(".", "", $_GET['action']);
3120
+ } else {
3121
+ return "";
3122
  }
 
 
3123
  }
3124
 
3125
  function run()
3126
  {
3127
  $action = $this->getAction();
3128
 
3129
+ if ( $action != "update") {
3130
  $this->_selfTest();
3131
  }
3132
 
3133
+ if($action == "checkbridge") {
3134
  echo "BRIDGE_OK";
3135
  return;
3136
  }
3137
 
3138
+ if ( $action == "update") {
3139
  $this->_checkPossibilityUpdate();
3140
  }
3141
 
3142
+ $class_name = "M1_Bridge_Action_" . ucfirst($action);
3143
+ if (!class_exists($class_name)) {
3144
+ echo "ACTION_DO_NOT EXIST" . PHP_EOL;
3145
  die;
3146
  }
3147
+ $action_obj = new $class_name();
3148
+ @$action_obj->cartType = @$this->config->cartType;
3149
+ $action_obj->perform($this);
 
3150
  $this->_destroy();
3151
  }
3152
 
3158
 
3159
  $dh = @opendir($dir);
3160
 
3161
+ if($dh === false) {
3162
  return false;
3163
  }
3164
 
3165
+ while( ($entry = readdir($dh)) !== false ) {
3166
+ if($entry == "." || $entry == ".." || !@is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
3167
  continue;
3168
  }
3169
 
3170
+ if( !$this->isWritable($dir . DIRECTORY_SEPARATOR . $entry) ) {
3171
  return false;
3172
  }
3173
  }
3181
 
3182
  function _destroy()
3183
  {
3184
+ if($this->getAction() != "savefile") {
3185
+ mysql_close($this->_link);
3186
+ }
3187
  }
3188
 
3189
  function _checkPossibilityUpdate()
3190
  {
3191
  if (!is_writable(M1_STORE_BASE_DIR . "/" . M1_BRIDGE_DIRECTORY_NAME . "/")) {
3192
+ die("ERROR_TRIED_TO_PERMISSION" . M1_STORE_BASE_DIR . "/". M1_BRIDGE_DIRECTORY_NAME . "/");
3193
  }
3194
 
3195
  if (!is_writable(M1_STORE_BASE_DIR . "/". M1_BRIDGE_DIRECTORY_NAME . "/bridge.php")) {
3199
 
3200
  function _selfTest()
3201
  {
3202
+ if( !isset($_GET['ver']) || $_GET['ver'] != M1_BRIDGE_VERSION ) {
3203
  die ('ERROR_BRIDGE_VERSION_NOT_SUPPORTED');
3204
  }
3205
 
3206
+ if (isset($_GET['token']) && $_GET['token'] == M1_TOKEN) {
 
 
 
 
 
 
 
 
 
 
 
 
 
3207
  // good :)
3208
  } else {
3209
  die('ERROR_INVALID_TOKEN');
3210
  }
3211
 
3212
+ if( (!isset($_GET['storetype']) || $_GET['storetype'] == 'target') && $this->getAction() == 'checkbridge' ) {
3213
 
3214
+ if( trim($this->config->imagesDir) != "" ) {
3215
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->imagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3216
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->imagesDir, 0777, true)) {
3217
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->imagesDir);
3223
  }
3224
  }
3225
 
3226
+ if( trim($this->config->categoriesImagesDir) != "" ) {
3227
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->categoriesImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3228
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->categoriesImagesDir, 0777, true)) {
3229
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->categoriesImagesDir);
3235
  }
3236
  }
3237
 
3238
+ if( trim($this->config->productsImagesDir) != "" ) {
3239
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->productsImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3240
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->productsImagesDir, 0777, true)) {
3241
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->productsImagesDir);
3247
  }
3248
  }
3249
 
3250
+ if( trim($this->config->manufacturersImagesDir) != "" ) {
3251
  if (!file_exists(M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir) && is_writable(M1_STORE_BASE_DIR)) {
3252
  if (!@mkdir(M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir, 0777, true)) {
3253
  die('ERROR_TRIED_TO_CREATE_IMAGE_DIR' . M1_STORE_BASE_DIR . $this->config->manufacturersImagesDir);
3269
  define('M1_BRIDGE_DIRECTORY_NAME', basename(getcwd()));
3270
 
3271
  ini_set('display_errors', 1);
3272
+ if(substr(phpversion(), 0, 1) == 5) {
3273
  error_reporting(E_ALL & ~E_STRICT);
3274
  } else {
3275
  error_reporting(E_ALL);
3276
  }
3277
 
3278
+ require_once 'config.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
3279
 
3280
  function stripslashes_array($array) {
3281
  return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
3288
  // we need this for XAMPP (Windows)
3289
  if (isset($_SERVER["WINDIR"]) && strstr($path, 'php.exe') && file_exists($path) && is_file($path)) {
3290
  return $path;
3291
+ }
3292
+ else {
3293
  $phpExecutable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : "");
3294
  if (file_exists($phpExecutable) && is_file($phpExecutable)) {
3295
  return $phpExecutable;
3296
  }
3297
  }
3298
  }
3299
+ return FALSE;
3300
  }
3301
 
3302
  if (!isset($_SERVER))
3309
  $_REQUEST = array_merge($_GET, $_POST, $_COOKIE);
3310
  }
3311
 
3312
+ if ( get_magic_quotes_gpc() ) {
3313
+
3314
  $_COOKIE = stripslashes_array($_COOKIE);
3315
  $_FILES = stripslashes_array($_FILES);
3316
  $_GET = stripslashes_array($_GET);
3328
  //Windows IIS
3329
  define("M1_STORE_BASE_DIR", preg_replace('/[^\/\\\]*[\/\\\][^\/\\\]*$/', '', realpath(dirname(__FILE__) . "/../")));
3330
  }
 
 
3331
 
3332
+ $bridge = new M1_Bridge(M1_Config_Adapter::create());
3333
+
3334
+ if( !$bridge->getLink() ) {
3335
  die ('ERROR_BRIDGE_CANT_CONNECT_DB');
3336
  }
3337
 
bridge2cart/config.php ADDED
@@ -0,0 +1 @@
 
1
+ <?php define("M1_TOKEN", "7704da1581ddebce0eeb358f69421ceb");
bridge2cart/index.html DELETED
File without changes
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Zikkio</name>
4
- <version>1.0.4</version>
5
  <stability>stable</stability>
6
- <license uri="https://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Import millions of products with a click and start trading with the power of drop-shipping.</summary>
10
- <description>Zikkio module is the connector between your Magento and Zikkio service. With Zikkio module active you can import/export orders and products to Zikkio</description>
11
- <notes>Import millions of products with a click and start trading with the power of drop-shipping</notes>
12
- <authors><author><name>Zikkio</name><user>zikkio</user><email>account@zikkio.com</email></author></authors>
13
- <date>2016-05-25</date>
14
- <time>14:24:09</time>
15
- <contents><target name="magecommunity"><dir name="Zikkio"><dir name="Zikkio"><dir name="Helper"><file name="Data.php" hash="bf754598a4fe65877c12cafd769ad149"/></dir><dir name="Model"><file name="Observer.php" hash="8f194df93259aff846cd1da968207be8"/></dir><dir name="etc"><file name="config.xml" hash="d2952e6cc5ae41d6d0ac5051e2ef66d5"/><file name="system.xml" hash="256c0d51bb6fb236fbf9b314d0be6389"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Zikkio_Zikkio.xml" hash="155aee552d731fb3cb73678fcb8704c0"/></dir></target><target name="mage"><dir name="bridge2cart"><file name="bridge.php" hash="69aa3dc57467c42bc1660ed1d1202d98"/><file name="index.html" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Zikkio</name>
4
+ <version>1.0.5</version>
5
  <stability>stable</stability>
6
+ <license>Open Software License (OSL)</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Import millions of products with a click and start trading with the power of drop-shipping.</summary>
10
+ <description>Zikkio module is the connector between your Magento and Zikkio service. With Zikkio module active you can import/export orders and products to Zikkio.</description>
11
+ <notes>First stable release.</notes>
12
+ <authors><author><name>Zikkio</name><user>Zikkio</user><email>account@zikkio.com</email></author></authors>
13
+ <date>2016-07-04</date>
14
+ <time>11:39:32</time>
15
+ <contents><target name="magecommunity"><dir name="Zikkio"><dir name="Zikkio"><dir name="Helper"><file name="Data.php" hash="bf754598a4fe65877c12cafd769ad149"/></dir><dir name="Model"><file name="Observer.php" hash="b3a44d2041d37a603604f6ac3e5f3c16"/></dir><dir name="etc"><file name="config.xml" hash="d2952e6cc5ae41d6d0ac5051e2ef66d5"/><file name="system.xml" hash="256c0d51bb6fb236fbf9b314d0be6389"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Zikkio_Zikkio.xml" hash="155aee552d731fb3cb73678fcb8704c0"/></dir></target><target name="mage"><dir name="bridge2cart"><file name="bridge.php" hash="84b71a49ce41efa85a2872f824c6b171"/><file name="config.php" hash="e7d47925538152d91fb207daa9d4f57f"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>