Sueta

ArticlesPHPAPI

1.0

An additional PHP API for Articles

·Plugin

Description
This PHP file is an addon for our premium plugin Articles. It (yet) requires a bit knowledge of PHP.

Usage

Usage

To get started upload the PHP file to your webserver and add following code at the top of your page:

<?php
include "ArticlesAPI.php";

Below that code you set up the connection with the database:

<?php
include "ArticlesAPI.php";

/*
 * Init API
 */

$articlesAPI = new ArticlesAPI();
$articlesAPI->connect("DatabaseHost", "DatabasePort", "TableName", "AccessUsername", "AccessPassword");
?>

The API provides two main functions:

$articlesAPI->getArticle(ID)
- Returns an instance of Article by the given ID; throws ArticleNotFoundException

$articlesAPI->getArticles()
- Returns an array of articles

Article Class:

$articlesAPI->getArticle(0)->getID()
- Returns the article's ID

$articlesAPI->getArticle(0)->getCreator()
- Returns the article's creator

$articlesAPI->getArticle(0)->getTitle()
- Returns the article's title

$articlesAPI->getArticle(0)->getComments()
- Returns an array of an article's comments

$articlesAPI->getArticle(0)->getUps()
- Returns the amount of positive ratings the article has recieved

$articlesAPI->getArticle(0)->getDowns()
- Returns the amount of negative ratings the article has recieved

$articlesAPI->getArticle(0)->getAllowed()
- Returns an array with the the players' uuid which are allowed to access the article

$articlesAPI->getArticle(0)->getLines()
- Returns an array with the article's lines

Comment Class:

Comment->getConent()
- Returns the comment's text

Comment->getCreator()
- Returns the comment's creator

ArticleNotFoundException Class:

Inherits all methods of a standart PHP Exception and:

Exception->getID()
- Returns the ID of the article that caused the exception
Demo Website
<?php
include "ArticlesAPI.php";

/*
 * Init API
 */

$articlesAPI = new ArticlesAPI();
$articlesAPI->connect("localhost", "3306", "articles_data", "root", "");
?>
<html>
    <body>
        <?php
            foreach($articlesAPI->getArticles() as $article){
                echo "Article #".$article->getID()."<ul><li>Name: ".$article->getCreator()."</li><li>Title: ".$article->getTitle()."</li> <li>Thumbs up: ".$article->getUps()."</li><li>Thumbs down: ".$article->getDowns()."</li></ul>";
            }
        ?>
    </body>
</html>

Similar projects

Plugin →