Skip to content

Commit e513a79

Browse files
committed
Added functionality to get platform's favicon
1 parent 7c67bd3 commit e513a79

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

example/example.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# 3. Define your platform. The key is country - platform name
1212
$parser->setPlatform('ch-nzz');
1313

14-
# 4. Get articles
14+
# 4. Display the platform's favicon
15+
print '<img src="'.$parser->getIconUrl().'">';
16+
17+
# 5. Get articles
1518
var_dump($parser->getRecommendedArticles(5));
1619

1720
# Options: Clear the cache

lib/NewsParser/Parser/Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function getMostCommentedArticles($limit = null)
4646
return $articles;
4747
}
4848

49+
public function getIconUrl()
50+
{
51+
return 'http://www.google.com/s2/favicons?domain=' . $this->getPlatform()->getRootUrl();
52+
}
53+
4954
public function setPlatform($platformKey)
5055
{
5156
$platformNameParts = explode('-', $platformKey);

lib/NewsParser/Parser/Platforms/CH/NzzParser.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
use Sprain\NewsParser\Parser\Interfaces\PlatformParserInterface;
66
use Sprain\NewsParser\Parser\Parser;
7+
use Sprain\NewsParser\Parser\Platforms\PlatformParser;
78
use Sunra\PhpSimple\HtmlDomParser;
89

9-
class NzzParser implements PlatformParserInterface
10+
class NzzParser extends PlatformParser implements PlatformParserInterface
1011
{
1112
protected $rootUrl = 'http://www.nzz.ch';
1213

lib/NewsParser/Parser/Platforms/CH/TagesanzeigerParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Sprain\NewsParser\Parser\Parser;
88
use Sunra\PhpSimple\HtmlDomParser;
99

10-
class TagesanzeigerParser implements PlatformParserInterface
10+
class TagesanzeigerParser extends PlatformParser implements PlatformParserInterface
1111
{
1212
protected $rootUrl = 'http://www.tagesanzeiger.ch';
1313

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Sprain\NewsParser\Parser\Platforms;
4+
5+
abstract class PlatformParser
6+
{
7+
public function getRootUrl()
8+
{
9+
return $this->rootUrl;
10+
}
11+
}

0 commit comments

Comments
 (0)