[Plugin] StreetViewFun

Post plugins and custom CSS snippets here
psylox
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 31 Mar 2015, 18:47

[Plugin] StreetViewFun

Postby psylox » 31 Mar 2015, 18:51

Hi,

Attach is a plugin to load images from StreetViewFun rss feed.

Enjoy
Psylox
Attachments
streetviewfun.tar.gz
(692 Bytes) Downloaded 162 times

Reader_Refugee
Bear Rating Trainee
Bear Rating Trainee
Posts: 7
Joined: 01 Apr 2013, 19:25

Re: [Plugin] StreetViewFun

Postby Reader_Refugee » 01 Apr 2015, 01:06

Just saw this post pop up in TTRS and thought, "I'll bet this was inspired by that Aussie bird who flashed her mams at the Google car".

Lo and behold, that story is on the front page of StreetViewFun.

Lulz.

psylox
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 31 Mar 2015, 18:47

Re: [Plugin] StreetViewFun

Postby psylox » 01 Apr 2015, 08:50

Ahaha absolutely! Or maybe the "OMG it's an alien" at the end of the home page who inspired me :)

psylox
Bear Rating Trainee
Bear Rating Trainee
Posts: 4
Joined: 31 Mar 2015, 18:47

Re: [Plugin] StreetViewFun

Postby psylox » 16 Jun 2015, 14:34

Hi,

Due to a bug with php-5.6.9 and DOMDocument::loadHTML, the updated script is:

Code: Select all

<?php
class StreetViewFun extends Plugin {

    private $host;

    function about() {
        return array(1.0,
            "Fixes RSS feeds of included images",
            "psylox");
    }

    function init($host) {
        $this->host = $host;

        $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
    }

    function hook_article_filter($article) {
        $owner_uid = $article["owner_uid"];

        if (strpos($article["link"], "Streetviewfun/") !== FALSE) {
                $page = fetch_file_contents($article["link"]);
                $page = str_replace("\x0", ' ', $page);
                $doc = new DOMDocument();
                $doc->loadHTML($page);

                $basenode = false;

                if ($doc) {
                    $xpath = new DOMXPath($doc);
                    $basenode = $xpath->query('(//div[@class="entry_content"])')->item(0);

                    if ($basenode) {
                        foreach($xpath->query('*[not(self::p)]', $basenode) as $node)
                            $basenode->removeChild($node);

                        $article["content"] = $doc->saveXML($basenode);
                    }
                    else
                        $article["content"] = "BaseNode not found<br/><br/>".$doc->saveXML();
                }
                else
                    $article["content"] = "Fetch content or load HTML failed";
        }

        return $article;

    }

    function api_version() {
        return 2;
    }

}
?>



Just to point out changes to those are interested in it:

Code: Select all

      if (strpos($article["link"], "Streetviewfun/") !== FALSE) {
                $page = fetch_file_contents($article["link"]);
                $page = str_replace("\x0", ' ', $page);
                $doc = new DOMDocument();


Cheers


Return to “Themes and plugins”

Who is online

Users browsing this forum: No registered users and 2 guests