backendtea/fourchanapi

This package is abandoned and no longer maintained. No replacement package was suggested.

A php wrapper for the 4chan api

v1.0.0 2017-10-20 18:41 UTC

This package is not auto-updated.

Last update: 2020-01-24 17:11:54 UTC


README

Build Status Code Climate Code Climate Code Climate

A PHP api wrapper for the 4chan api.

Please see https://github.com/4chan/4chan-API for usage rules.

Instalation

Run composer require backendtea/fourchanapi ^1.0 For information about Composer check out their website

Usage

Get a list off all the Thread #'s of /v/

use FourChan\FourChan;

FourChan::board('v')->getThreads();

Grab all the images of the first thread we find on /v/

use FourChan\FourChan;

$posts = FourChan::board('v')->getThreads()[0]->getPosts();

foreach($posts as $post) {
    if ($post->hasimage() {
        echo $post->getImageUrl();
    }
}

Any function related to getting image information throws a FourChan\Util\NoImageException when there is no image. So another way would be:


$posts = FourChan::board('a')->getThreads()[0]->getPosts();

foreach($posts as $post) {
    try{
        echo $post->getImageUrl();
    } catch(NoImageException $e) {
        //do nothing
    }
}

Get the information of a thread

$thread = FourChan::board('a')->getThreads()[0];

// true or false
$thread->isStick();
//true or false
$thread->isClosed();
//true or false
$thread->isArchived();
//Subject or '' if no subject is set.
$thread->getSubject();
//# of OP
$thread->getID();

Get the information of a post

$post = FourChan::board('a')->getThreads()[0]->getPosts()[0];
//Comment of the post, including escaped html.
$post->getFullComment();
//# of the post
$post->getID();

If you need more functionality, either make it yourself and shoot me a PR, or create an issue on Github and hope me or someone else does it for you.

Contributing

Features, bug fixes etc are welcome, please check the Contributing.md for more info

Note

All of fake responses have been grabbed from live threads on 4chan, they do not necessarily represent my views, or of anyone who has worked on this project.