예제 #1
0
	/**
	* Sets up a picnik editing session along with template variables for use with control panel pages
	*
	* @param string $imageTypeString Image type in string form, so as to match with an ISC_PICNIK_TYPE_? constant (e.g., 'productimage')
	* @param mixed $imageId Image identifier (could be numeric for product images, filename for image manager, etc.)
	* @param bool $https True to return an HTTPS url, false to return an HTTP url, otherwise leave as null to autodetect based on the current request
	* @return array|bool False if any error occurred
	*/
	public function setupPicnikSession($imageTypeString, $imageId, $https = null)
	{
		$imageTypeConstant = 'ISC_PICNIK_TYPE_' . strtoupper($imageTypeString);
		if (!defined($imageTypeConstant)) {
			$this->log->LogSystemWarning('general', 'Unhandled picnik image type specified: ' . $imageTypeString);
			return false;
		}

		$imageType = constant($imageTypeConstant);

		$token = $this->generatePicnikToken($imageType, $imageId);
		if (!$token) {
			$this->log->LogSystemError('general', 'Failed to generate and save picnik token to database');
			return false;
		}

		if ($https === null) {
			// to account for security warnings, determine based on current request, not store settings - why?
			// 1. could potentially be used on front end design mode
			// 2. the cp request will already be forced to ssl if the store is configured as such
			if (Interspire_Request::server('HTTPS') == 'on') {
				$https = true;
			} else {
				$https = false;
			}
		} else {
			$https = (bool)$https;
		}

		$protocol = 'http';
		if ($https) {
			$protocol .= 's';
		}

		$this->template->assign('PicnikServiceUrl', $protocol . '://' . ISC_PICNIK_SERVICEURL);
		$this->template->assign('PicnikApiKey', ISC_PICNIK_APIKEY);
		$this->template->assign('PicnikImageUrl', $token['url']);
		$this->template->assign('PicnikSaveHandler', GetConfig('ShopPathSSL') . '/admin/index.php?ToDo=receivePicnik&token=' . rawurlencode($token['token']));
		$this->template->assign('PicnikCloseHandler', GetConfig('ShopPathSSL') . '/admin/index.php?ToDo=cancelPicnik&token=' . rawurlencode($token['token']));

		$this->template->assign('PicnikSaveTitle', GetLang('PicnikSaveTitle', array('storename' => GetConfig('StoreName'))));

		return $token;
	}