Jelajahi Sumber

felt quirky, might commit later

lolcat 3 tahun lalu
induk
melakukan
16ee0b368f
7 mengubah file dengan 771 tambahan dan 265 penghapusan
  1. 2 19
      images.php
  2. 16 1
      lib/frontend.php
  3. 1 1
      scraper/ddg.php
  4. 740 224
      scraper/google.php
  5. 0 1
      static/client.js
  6. 2 0
      static/style.css
  7. 10 19
      web.php

+ 2 - 19
images.php

@@ -58,32 +58,15 @@ if(count($results["image"]) === 0){
 	
 foreach($results["image"] as $image){
 	
-	$domain = htmlspecialchars(parse_url($image["url"], PHP_URL_HOST));
-	
-	$c = count($image["source"]) - 1;
-	
-	if(
-		preg_match(
-			'/^data:/',
-			$image["source"][$c]["url"]
-		)
-	){
-		
-		$src = htmlspecialchars($image["source"][$c]["url"]);
-	}else{
-		
-		$src = "/proxy?i=" . urlencode($image["source"][$c]["url"]) . "&s=thumb";
-	}
-	
 	$payload["images"] .=
 		'<div class="image-wrapper" title="' . htmlspecialchars($image["title"]) .'" data-json="' . htmlspecialchars(json_encode($image["source"])) . '">' .
 			'<div class="image">' .
 				'<a href="' . htmlspecialchars($image["source"][0]["url"]) . '" rel="noreferrer nofollow" class="thumb">' .
-					'<img src="' . $src . '" alt="thumbnail">' .
+					'<img src="' . $frontend->htmlimage($image["source"][count($image["source"]) - 1]["url"], "thumb") . '" alt="thumbnail">' .
 					'<div class="duration">' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '</div>' .
 				'</a>' .
 				'<a href="' . htmlspecialchars($image["url"]) . '" rel="noreferrer nofollow">' .
-					'<div class="title">' . htmlspecialchars($domain) . '</div>' .
+					'<div class="title">' . htmlspecialchars(parse_url($image["url"], PHP_URL_HOST)) . '</div>' .
 					'<div class="description">' . $frontend->highlighttext($get["s"], $image["title"]) . '</div>' .
 				'</a>' .
 			'</div>' .

+ 16 - 1
lib/frontend.php

@@ -143,7 +143,7 @@ class frontend{
 				
 				$payload .=
 					'">' .
-						'<img class="thumb" src="/proxy?i=' . urlencode($site["thumb"]["url"]) . '&s=' . $size . '" alt="thumb">';
+						'<img class="thumb" src="' . $this->htmlimage($site["thumb"]["url"], $size) . '" alt="thumb">';
 				
 				if($duration !== null){
 					
@@ -1273,6 +1273,21 @@ class frontend{
 		return http_build_query($out);
 	}
 	
+	public function htmlimage($image, $format){
+		
+		if(
+			preg_match(
+				'/^data:/',
+				$image
+			)
+		){
+			
+			return htmlspecialchars($image);
+		}
+		
+		return "/proxy.php?i=" . urlencode($image) . "&s=" . $format;
+	}
+	
 	public function htmlnextpage($gets, $npt, $page){
 		
 		$query = $this->buildquery($gets);

+ 1 - 1
scraper/ddg.php

@@ -679,7 +679,7 @@ class ddg{
 				Check for worknik results
 			*/
 			preg_match(
-				'/nrj\(\'\/js\/spice\/dictionary\/definition\/([^\']+)\'\)/',
+				'/nrj\(\'\/js\/spice\/dictionary\/definition\/([^\'\)]+)/',
 				$js,
 				$wordnik
 			);

File diff ditekan karena terlalu besar
+ 740 - 224
scraper/google.php


+ 0 - 1
static/client.js

@@ -577,7 +577,6 @@ function getproxylink(url){
 		return htmlspecialchars(url);
 	}else{
 		
-		console.log(url);
 		return '/proxy?i=' + encodeURIComponent(url);
 	}
 }

+ 2 - 0
static/style.css

@@ -50,6 +50,8 @@
 
 audio{
 	max-width:100%;
+	display:block;
+	margin-bottom:17px;
 }
 
 body,html{

+ 10 - 19
web.php

@@ -65,7 +65,13 @@ if($results["spelling"]["type"] != "no_correction"){
 	$payload["left"] .=
 		'<div class="infobox">' .
 			$type . ' <b>' . htmlspecialchars($results["spelling"]["using"]) . '</b>.<br>' .
-			'Did you mean <a href="?s=' . urlencode($results["spelling"]["correction"]) . '">' . $results["spelling"]["correction"] . '</a>?' .
+			'Did you mean <a href="?s=' .
+			urlencode($results["spelling"]["correction"]) .
+			'&' .
+			$frontend->buildquery($get, true) .
+			'">' .
+			$results["spelling"]["correction"] .
+			'</a>?' .
 		'</div>';
 }
 
@@ -120,24 +126,9 @@ if(count($results["image"]) !== 0){
 	
 	foreach($results["image"] as $image){
 		
-		$c = count($image["source"]) - 1;
-		
-		if(
-			preg_match(
-				'/^data:/',
-				$image["source"][$c]["url"]
-			)
-		){
-			
-			$src = htmlspecialchars($image["source"][$c]["url"]);
-		}else{
-			
-			$src = "/proxy?i=" . urlencode($image["source"][$c]["url"]) . "&s=square";
-		}
-		
 		$right["image"] .=
 			'<a class="image" href="' . htmlspecialchars($image["url"]) . '" rel="noreferrer nofollow" title="' . htmlspecialchars($image["title"]) . '" data-json="' . htmlspecialchars(json_encode($image["source"])) . '" tabindex="-1">' .
-				'<img src="' . $src . '" alt="thumb">' .
+				'<img src="' . $frontend->htmlimage($image["source"][count($image["source"]) - 1]["url"], "square") . '" alt="thumb">' .
 				'<div class="duration">' . $image["source"][0]["width"] . 'x' . $image["source"][0]["height"] . '</div>' .
 			'</a>';
 	}
@@ -283,7 +274,7 @@ if(count($results["answer"]) !== 0){
 			
 			$right["answer"] .=
 				'<a href="' . htmlspecialchars($answer["thumb"]) . '" rel="noreferrer nofollow" class="photo">' .
-					'<img src="/proxy?i=' . urlencode($answer["thumb"]) . '&s=cover" alt="thumb" class="openimg">' .
+					'<img src="' . $frontend->htmlimage($answer["thumb"], "cover") . '" alt="thumb" class="openimg">' .
 				'</a>';
 		}
 		
@@ -337,7 +328,7 @@ if(count($results["answer"]) !== 0){
 				
 				case "image":
 					$right["answer"] .=
-						'<a href="' . htmlspecialchars($description["url"]) . '" rel="noreferrer nofollow" tabindex="-1"><img src="/proxy?i=' . urlencode($description["url"]) . '&s=thumb" alt="image" class="fullimg openimg"></a>';
+						'<a href="' . htmlspecialchars($description["url"]) . '" rel="noreferrer nofollow" tabindex="-1"><img src="' . $frontend->htmlimage($description["url"], "thumb") . '" alt="image" class="fullimg openimg"></a>';
 					break;
 				
 				case "audio":

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini