File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
1518var_dump ($ parser ->getRecommendedArticles (5 ));
1619
1720# Options: Clear the cache
Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change 44
55use Sprain \NewsParser \Parser \Interfaces \PlatformParserInterface ;
66use Sprain \NewsParser \Parser \Parser ;
7+ use Sprain \NewsParser \Parser \Platforms \PlatformParser ;
78use 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
Original file line number Diff line number Diff line change 77use Sprain \NewsParser \Parser \Parser ;
88use 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments