Browse Source

Switch back to unix line breaks after PR

spaghetti 8 years ago
parent
commit
b570edac1f
1 changed files with 99 additions and 99 deletions
  1. 99
    99
      sections/ajax/doujin.php

+ 99
- 99
sections/ajax/doujin.php View File

@@ -1,99 +1,99 @@
1
-<?
2
-
3
-if (empty($_GET['url'])) {
4
-  json_die();
5
-}
6
-
7
-$url = $_GET['url'];
8
-
9
-$matches = array();
10
-preg_match('/^https?:\/\/g?\.?e.hentai\.org\/g\/(\d+)\/([\w\d]+)\/?$/', $url, $matches);
11
-
12
-$gid = $matches[1] ?? '';
13
-$token = $matches[2] ?? '';
14
-
15
-if (empty($gid) || empty($token)) {
16
-  json_die("failure", "Invalid URL");
17
-}
18
-
19
-if ($Cache->get_value('doujin_json_'.$gid)) {
20
-  json_die("success", $Cache->get_value('doujin_json_'.$gid));
21
-} else {
22
-
23
-  $data = json_encode(["method" => "gdata", "gidlist" => [[$gid, $token]], "namespace" => 1]);
24
-  $curl = curl_init('http://g.e-hentai.org/api.php');
25
-  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
26
-  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
27
-  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
28
-  curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: '.strlen($data)]);
29
-
30
-  $json = curl_exec($curl);
31
-
32
-  if (empty($json)) {
33
-    json_die("failure", "Could not get page");
34
-  }
35
-
36
-  $json = json_decode($json, true)["gmetadata"][0];
37
-
38
-  $artists = array();
39
-  $tags = array();
40
-  $lang = NULL;
41
-  $circle = NULL;
42
-  $censored = true;
43
-  foreach ($json["tags"] as $tag) {
44
-    if (strpos($tag, ':') !== false) {
45
-      list($namespace, $tag) = explode(':', $tag);
46
-    } else { $namespace = ''; }
47
-
48
-    if ($namespace == "artist") {
49
-      array_push($artists, ucwords($tag));
50
-    } else if ($namespace == "language") {
51
-      $lang = empty($lang) ? ucfirst($tag) : $lang;
52
-    } else if ($namespace == "group") {
53
-      $circle = empty($circle) ? ucfirst($tag) : $circle;
54
-    } else if ($tag == "uncensored") {
55
-      $censored = false;
56
-    } else {
57
-      if ($namespace) { $tag = $tag.':'.$namespace; }
58
-      array_push($tags, str_replace(' ', '.', $tag));
59
-    }
60
-  }
61
-  
62
-  // get the cover for ants
63
-  $cover = $json['thumb'];
64
-  // and let's see if we can replace it with something better
65
-  $gallery_page = file_get_contents($url);
66
-  $re = '/'.preg_quote('-0px 0 no-repeat"><a href="').'(.*)'.preg_quote('"><img alt="01"').'/';
67
-  preg_match($re, $gallery_page, $galmatch);
68
-  // were we able to find the first page of the gallery?
69
-  if ($galmatch[1]) {
70
-	  $image_page = file_get_contents($galmatch[1]);
71
-	  $re = '/'.preg_quote('"><img id="img" src="').'(.*)'.preg_quote('" style=').'/';
72
-	  preg_match($re, $image_page, $imgmatch);
73
-	  // were we able to find the image url?
74
-	  if ($imgmatch[1]) {
75
-	    $cover = $imgmatch[1];
76
-	  }
77
-  }
78
-
79
-  $json_str = array(
80
-    'id' => $gid,
81
-    'title' => html_entity_decode($json['title'], ENT_QUOTES),
82
-    'title_jp' => html_entity_decode($json['title_jpn'], ENT_QUOTES),
83
-    'artists' => $artists,
84
-    'circle' => $circle,
85
-    'censored' => $censored,
86
-    'year' => NULL,
87
-    'tags' => $tags,
88
-    'lang' => $lang,
89
-    'pages' => $json['filecount'],
90
-    'description' => '',
91
-    'cover' => $cover
92
-  );
93
-
94
-  $Cache->cache_value('doujin_json_'.$gid, $json_str, 86400);
95
-
96
-  json_die("success", $json_str);
97
-}
98
-
99
-?>
1
+<?
2
+
3
+if (empty($_GET['url'])) {
4
+  json_die();
5
+}
6
+
7
+$url = $_GET['url'];
8
+
9
+$matches = array();
10
+preg_match('/^https?:\/\/g?\.?e.hentai\.org\/g\/(\d+)\/([\w\d]+)\/?$/', $url, $matches);
11
+
12
+$gid = $matches[1] ?? '';
13
+$token = $matches[2] ?? '';
14
+
15
+if (empty($gid) || empty($token)) {
16
+  json_die("failure", "Invalid URL");
17
+}
18
+
19
+if ($Cache->get_value('doujin_json_'.$gid)) {
20
+  json_die("success", $Cache->get_value('doujin_json_'.$gid));
21
+} else {
22
+
23
+  $data = json_encode(["method" => "gdata", "gidlist" => [[$gid, $token]], "namespace" => 1]);
24
+  $curl = curl_init('http://g.e-hentai.org/api.php');
25
+  curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
26
+  curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
27
+  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
28
+  curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'Content-Length: '.strlen($data)]);
29
+
30
+  $json = curl_exec($curl);
31
+
32
+  if (empty($json)) {
33
+    json_die("failure", "Could not get page");
34
+  }
35
+
36
+  $json = json_decode($json, true)["gmetadata"][0];
37
+
38
+  $artists = array();
39
+  $tags = array();
40
+  $lang = NULL;
41
+  $circle = NULL;
42
+  $censored = true;
43
+  foreach ($json["tags"] as $tag) {
44
+    if (strpos($tag, ':') !== false) {
45
+      list($namespace, $tag) = explode(':', $tag);
46
+    } else { $namespace = ''; }
47
+
48
+    if ($namespace == "artist") {
49
+      array_push($artists, ucwords($tag));
50
+    } else if ($namespace == "language") {
51
+      $lang = empty($lang) ? ucfirst($tag) : $lang;
52
+    } else if ($namespace == "group") {
53
+      $circle = empty($circle) ? ucfirst($tag) : $circle;
54
+    } else if ($tag == "uncensored") {
55
+      $censored = false;
56
+    } else {
57
+      if ($namespace) { $tag = $tag.':'.$namespace; }
58
+      array_push($tags, str_replace(' ', '.', $tag));
59
+    }
60
+  }
61
+
62
+  // get the cover for ants
63
+  $cover = $json['thumb'];
64
+  // and let's see if we can replace it with something better
65
+  $gallery_page = file_get_contents($url);
66
+  $re = '/'.preg_quote('-0px 0 no-repeat"><a href="').'(.*)'.preg_quote('"><img alt="01"').'/';
67
+  preg_match($re, $gallery_page, $galmatch);
68
+  // were we able to find the first page of the gallery?
69
+  if ($galmatch[1]) {
70
+	  $image_page = file_get_contents($galmatch[1]);
71
+	  $re = '/'.preg_quote('"><img id="img" src="').'(.*)'.preg_quote('" style=').'/';
72
+	  preg_match($re, $image_page, $imgmatch);
73
+	  // were we able to find the image url?
74
+	  if ($imgmatch[1]) {
75
+	    $cover = $imgmatch[1];
76
+	  }
77
+  }
78
+
79
+  $json_str = array(
80
+    'id' => $gid,
81
+    'title' => html_entity_decode($json['title'], ENT_QUOTES),
82
+    'title_jp' => html_entity_decode($json['title_jpn'], ENT_QUOTES),
83
+    'artists' => $artists,
84
+    'circle' => $circle,
85
+    'censored' => $censored,
86
+    'year' => NULL,
87
+    'tags' => $tags,
88
+    'lang' => $lang,
89
+    'pages' => $json['filecount'],
90
+    'description' => '',
91
+    'cover' => $cover
92
+  );
93
+
94
+  $Cache->cache_value('doujin_json_'.$gid, $json_str, 86400);
95
+
96
+  json_die("success", $json_str);
97
+}
98
+
99
+?>

Loading…
Cancel
Save