Permalink
Browse files

add backlink

  • Loading branch information...
1 parent 5a12176 commit c4f66a3a129fe604adc7001fa78016eaa0f34166 @tekezo committed Oct 18, 2011
Showing with 36 additions and 1 deletion.
  1. +17 −1 Tests/ImageLnkTest.php
  2. +11 −0 lib/Engine/itmedia.php
  3. +8 −0 lib/Response.php
View
@@ -9,7 +9,7 @@ function __construct() {
ImageLnkConfig::set('cache_expire_minutes', 30);
}
- private function check_response($url, $title, $imageurls, $referer = NULL) {
+ private function check_response($url, $title, $imageurls, $referer = NULL, $backlink = NULL) {
$response = ImageLnk::getImageInfo($url);
$expect = $title;
@@ -26,6 +26,12 @@ private function check_response($url, $title, $imageurls, $referer = NULL) {
$expect = $referer;
$actual = $response->getReferer();
$this->assertSame($expect, $actual);
+
+ if ($backlink !== NULL) {
+ $expect = $backlink;
+ $actual = $response->getBackLink();
+ $this->assertSame($expect, $actual);
+ }
}
// ======================================================================
@@ -195,6 +201,16 @@ function test_itmedia2() {
$this->check_response($url, $title, $imageurls);
}
+ function test_itmedia3() {
+ $url = 'http://image.itmedia.co.jp/l/im/mobile/articles/1110/14/l_os_appsomm03.jpg';
+ $title = '“普通の女性”目線で厳選したスマートフォンアプリ紹介サイト「アプリソムリエ」';
+ $imageurls = array(
+ 'http://image.itmedia.co.jp/mobile/articles/1110/14/l_os_appsomm03.jpg',
+ );
+ $backlink = 'http://plusd.itmedia.co.jp/mobile/articles/1110/14/news142.html#l_os_appsomm03.jpg';
+ $this->check_response($url, $title, $imageurls, NULL, $backlink);
+ }
+
// ======================================================================
function test_nicovideo1() {
$url = 'http://www.nicovideo.jp/watch/sm12589060';
View
@@ -28,6 +28,17 @@ public static function handle($url) {
}
}
+ if (preg_match_all('%<a (.+?)>%', $html, $matches)) {
+ foreach ($matches[1] as $a) {
+ if (preg_match('%onclick="designCnt\(\'largeImgMain\'\);"%', $a)) {
+ if (preg_match('%href="(.+?)"%', $a, $m)) {
+ $response->setBackLink($m[1]);
+ break;
+ }
+ }
+ }
+ }
+
return $response;
}
}
View
@@ -4,6 +4,7 @@ class ImageLnkResponse {
private $title_ = '';
private $referer_ = '';
private $imageurls_ = array();
+ private $backlink_ = '';
private static function normalize($string) {
return @iconv("UTF-8", "UTF-8//IGNORE", $string);
@@ -35,4 +36,11 @@ public function setReferer($newvalue) {
public function getReferer() {
return $this->referer_;
}
+
+ public function setBackLink($newvalue) {
+ $this->backlink_ = self::normalize($newvalue);
+ }
+ public function getBackLink() {
+ return $this->backlink_;
+ }
}

0 comments on commit c4f66a3

Please sign in to comment.