예제 #1
0
	public function __construct ()
	{
		parent::__construct();
		$this->SetName(GetLang($this->id . '_name'));

		Interspire_Event::bind('Interspire_EmailIntegration_MailChimp/error', array($this, 'onApiError'));
	}
예제 #2
0
		public function CommitSettings(&$messages=array())
		{
			// If the shop path has changed normalize it and set the app path too
			if (isset($GLOBALS['ISC_NEW_CFG']['ShopPath']) && $GLOBALS['ISC_NEW_CFG']['ShopPath'] != GetConfig('ShopPath')) {
				$parsedPath = ParseShopPath($GLOBALS['ISC_NEW_CFG']['ShopPath']);
				$GLOBALS['ISC_NEW_CFG']['ShopPath'] = $parsedPath['shopPath'];

				// add an event to resubscribe to ebay notifications since the notification url will now be different
				if (ISC_ADMIN_EBAY::checkEbayConfig()) {
					Interspire_Event::bind('settings_updated', array('ISC_ADMIN_EBAY', 'resubscribeNotifications'));
				}
			}

			// normalize our shared ssl path
			if (isset($GLOBALS['ISC_NEW_CFG']['SharedSSLPath']) && trim($GLOBALS['ISC_NEW_CFG']['SharedSSLPath'])) {
				$ssl_path_parts = parse_url($GLOBALS['ISC_NEW_CFG']['SharedSSLPath']);

				if (!isset($ssl_path_parts['path'])) {
					$ssl_path_parts['path'] = '';
				}
				$ssl_path_parts['path'] = rtrim($ssl_path_parts['path'], '/');

				// Workout the Shop Path
				$GLOBALS['ISC_NEW_CFG']['SharedSSLPath'] = 'https://' . $ssl_path_parts['host'];
				if (isset($ssl_path_parts['port']) && $ssl_path_parts['port'] != '443') {
					$GLOBALS['ISC_NEW_CFG']['SharedSSLPath'] .= ':'.$ssl_path_parts['port'];
				}
				$GLOBALS['ISC_NEW_CFG']['SharedSSLPath'] .= $ssl_path_parts['path'];
			}

			// normalize our subdomain ssl path
			if (isset($GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath']) && trim($GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath'])) {
				$ssl_path_parts = parse_url($GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath']);

				if (!isset($ssl_path_parts['path'])) {
					$ssl_path_parts['path'] = '';
				}
				$ssl_path_parts['path'] = rtrim($ssl_path_parts['path'], '/');

				// Workout the Shop Path
				$GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath'] = 'https://' . $ssl_path_parts['host'];
				if (isset($ssl_path_parts['port']) && $ssl_path_parts['port'] != '443') {
					$GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath'] .= ':'.$ssl_path_parts['port'];
				}
				$GLOBALS['ISC_NEW_CFG']['SubdomainSSLPath'] .= $ssl_path_parts['path'];
			}

			if (!isset($GLOBALS['ISC_NEW_CFG'])) {
				$GLOBALS['ISC_NEW_CFG'] = array();
			}

			$directories = array(
				'ImageDirectory' => 'product_images',
				'DownloadDirectory' => 'product_downloads'
			);
			foreach($directories as $directory => $default) {
				if(isset($GLOBALS['ISC_NEW_CFG'][$directory])) {
					$newDirectory = ISC_BASE_PATH.'/'.$GLOBALS['ISC_NEW_CFG'][$directory];
					if(!$GLOBALS['ISC_NEW_CFG'][$directory] || !is_dir($newDirectory)) {
						$GLOBALS['ISC_NEW_CFG'][$directory] = $default;
					}
				}
			}

			// Wht we're doing here is we copy the current configuration in to another variable and
			// then load the store configuration file again. We do this to prevent any settings
			// that may have temporarily been modified in memory from propagating to the configuration
			// file. We then revert back to the in memory settings
			$memoryConfig = $GLOBALS['ISC_CFG'];
			unset($GLOBALS['ISC_CFG']);
			require ISC_CONFIG_FILE;
			$originalConfig = $GLOBALS['ISC_CFG'];
			$GLOBALS['ISC_CFG'] = $memoryConfig;
			$GLOBALS['ISC_SAVE_CFG'] = array_merge($originalConfig, $GLOBALS['ISC_NEW_CFG']);
			// Save the var_exported vars in the globals array temporarily for saving
			foreach ($this->all_vars as $var) {
				if (!array_key_exists($var, $GLOBALS['ISC_SAVE_CFG'])) {
					if(array_key_exists($var, $memoryConfig)) {
						$GLOBALS[$var] = var_export($memoryConfig[$var], true);
					} else {
						$GLOBALS[$var] = "null";
					}
				} else {
					$GLOBALS[$var] = var_export($GLOBALS['ISC_SAVE_CFG'][$var], true);
				}
			}

			$config_data = $this->template->render('config.file.tpl');

			$setting_string = "<" . "?php\n\n";
			$setting_string .= "\t// Last Updated: ".isc_date("jS M Y @ g:i A") . "\n";
			$setting_string .= $config_data;

			if (!defined("ISC_CONFIG_FILE") || !defined("ISC_CONFIG_BACKUP_FILE")) {
				die("Config sanity check failed");
			}

			// Try to copy the current config file to a backup file
			if (!@copy(ISC_CONFIG_FILE, ISC_CONFIG_BACKUP_FILE)) {
				isc_chmod(ISC_CONFIG_BACKUP_FILE, ISC_WRITEABLE_FILE_PERM);
				$messages = array(GetLang('CouldntBackupConfig') => MSG_INFO);
			}

			// Try to write to the config file
			if (!is_writable(ISC_CONFIG_FILE)) {
				$this->error = GetLang('CouldntSaveConfig');
				return false;
			}

			if (!($fp = @fopen(ISC_CONFIG_FILE, "wb+"))) {
				$this->error = GetLang('CouldntSaveConfig');
				return false;
			}

			if (@fwrite($fp, $setting_string)) {
				fclose($fp);
				$prevCatListDepth = GetConfig('CategoryListDepth');
				// Include the config file again to initialize the new values
				include(ISC_CONFIG_FILE);

				if (isset($GLOBALS['ISC_NEW_CFG']['CategoryListDepth']) && $GLOBALS['ISC_NEW_CFG']['CategoryListDepth'] != $prevCatListDepth) {
					$GLOBALS['ISC_CLASS_DATA_STORE']->UpdateRootCategories();
				}

				// trigger any events that should run after the settings have been saved
				Interspire_Event::trigger('settings_updated');

				return true;
			}

			fclose($fp);
			$this->error = GetLang('CouldntSaveConfig');
			return false;
		}
예제 #3
0
	/**
	* Actually connect to the server and call the requested methods, parsing the result
	* You should never have to call this public function manually
	*
	* This is an override of the MCAPI callServer method to use ISC's network code. Since it's now using ISC, the error codes produced may not match MCAPI documents.
	*
	* @param string $method
	* @param array $params
	* @param int $timeout
	* @return string|bool resulting response body on success, or false on failure
	*/
	public function callServer($method, $params, $timeout = self::MCAPI_TIMEOUT)
	{
		$dc = "us1";
		if (strstr($this->api_key,"-")){
			list($key, $dc) = explode("-",$this->api_key,2);
			if (!$dc) $dc = "us1";
		}
		$host = $dc.".".$this->apiUrl["host"];
		$params["apikey"] = $this->api_key;

		$this->errorMessage = "";
		$this->errorCode = "";

		$url = 'http';
		if ($this->secure) {
			$url .= 's';
		}
		$url .= '://' . $host . $this->apiUrl['path'] . '?' . $this->apiUrl['query'] . '&method=' . $method;

		$requestOptions = new Interspire_Http_RequestOptions;
		$requestOptions->userAgent = 'MCAPI/' . $this->version . ' (BigCommerce)';

		$response = PostToRemoteFileAndGetResponse($url, http_build_query($params), $timeout, $errno, $requestOptions);

		if (!$response) {
			$this->errorMessage = "Could not connect (" . $errno . ": " . GetLang('ISC_REMOTEFILE_ERROR_' . $errno) . ")";
			$this->errorCode = $errno;
			Interspire_Event::trigger('Interspire_EmailIntegration_MailChimp/error', array(
				'method' => $method,
				'params' => $params,
				'api' => $this,
			));
			return false;
		}

		if (ini_get("magic_quotes_runtime")) {
			$response = stripslashes($response);
		}

		$serial = unserialize($response);
		if($response && $serial === false) {
			$response = array("error" => "Bad Response.  Got This: " . $response, "code" => "-99");
		} else {
			$response = $serial;
		}
		if(is_array($response) && isset($response["error"])) {
			$this->errorMessage = $response["error"];
			$this->errorCode = $response["code"];
			Interspire_Event::trigger('Interspire_EmailIntegration_MailChimp/error', array(
				'method' => $method,
				'params' => $params,
				'api' => $this,
			));
			return false;
		}

		return $response;
	}