From bc45a203ade8777c552fb8b8e9e71669f521fc12 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 30 Jun 2012 21:24:06 +0000
Subject: [PATCH] Poprawki w module lang: - przeniesienie klasy msapi z osobnego pliku do hander.php - poprawienie URL do metody Translate w API

---
 /dev/null                   |   44 ----------------------
 modules/80_lang/handler.php |   45 +++++++++++++++++++++-
 2 files changed, 43 insertions(+), 46 deletions(-)

diff --git a/modules/80_lang/handler.php b/modules/80_lang/handler.php
index 15bd3b0..1e4a4f3 100644
--- a/modules/80_lang/handler.php
+++ b/modules/80_lang/handler.php
@@ -1,5 +1,46 @@
 <?php
-require_once(dirname(__FILE__).'/msapi.php');
+require_once(dirname(__FILE__).'/msapi_config.php');
+
+class msapi extends msapi_config {
+	public $url;
+	
+	function __construct($url) {
+		$this->url = $url;
+	}
+	
+	function execute($params) {
+		if(!is_array($params)) {
+			throw new Exception('Przekazany parametr nie jest tablicą');
+		}
+		
+		foreach($params as $name => &$param) {
+			if(substr($name, 0, 1)!='$' && is_string($param)) {
+				$param = '\''.$param.'\'';
+			}
+		}
+		unset($param);
+		$params['$format'] = 'json';
+		
+		$context = stream_context_create(array(
+			'http' => array(
+				'request_fulluri' => TRUE,
+				'header' => 'Authorization: Basic '.base64_encode(':'.$this->accountKey)
+			),
+		));
+		
+		$content = file_get_contents($this->url.'?'.http_build_query($params, '', '&'), FALSE, $context);
+		if(!$content) {
+			return FALSE;
+		}
+		
+		$content = json_decode($content, TRUE);
+		if(!$content) {
+			return FALSE;
+		}
+		
+		return $content;
+	}
+}
 
 class bot_lang_module implements BotModule {
 	function handle($msg, $params) {
@@ -23,7 +64,7 @@
 		$data = jsarray::parse($data);
 		
 		if(!$data OR count($data)==0 OR count($data[1])==0) {
-			$api = new msapi('https://api.datamarket.azure.com/Bing/MicrosoftTranslator/');
+			$api = new msapi('https://api.datamarket.azure.com/Bing/MicrosoftTranslator/Translate');
 			$data = $api->execute(array(
 				'From' => $params[0],
 				'To' => $params[1],
diff --git a/modules/80_lang/msapi.php b/modules/80_lang/msapi.php
deleted file mode 100644
index 4f4fc16..0000000
--- a/modules/80_lang/msapi.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-require_once(dirname(__FILE__).'/msapi_config.php');
-
-class msapi extends msapi_config {
-	public $url;
-	
-	function __construct($url) {
-		$this->url = $url;
-	}
-	
-	function execute($params) {
-		if(!is_array($params)) {
-			throw new Exception('Przekazany parametr nie jest tablicą');
-		}
-		
-		foreach($params as $name => &$param) {
-			if(substr($name, 0, 1)!='$' && is_string($param)) {
-				$param = '\''.$param.'\'';
-			}
-		}
-		unset($param);
-		$params['$format'] = 'json';
-		
-		$context = stream_context_create(array(
-			'http' => array(
-				'request_fulluri' => TRUE,
-				'header' => 'Authorization: Basic '.base64_encode(':'.$this->accountKey)
-			),
-		));
-		
-		$content = file_get_contents($this->url.'?'.http_build_query($params, '', '&'), FALSE, $context);
-		if(!$content) {
-			return FALSE;
-		}
-		
-		$content = json_decode($content, TRUE);
-		if(!$content) {
-			return FALSE;
-		}
-		
-		return $content;
-	}
-}
-?>

--
Gitblit v1.9.1