initial commit
This commit is contained in:
commit
b9521ad7ed
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
config.php
|
||||
logs/*
|
||||
vendor/
|
4
.nova/Configuration.json
Normal file
4
.nova/Configuration.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"com.thorlaksson.phpcs.runOnChange" : "onSave",
|
||||
"com.thorlaksson.phpcs.standard" : "\/Volumes\/Alyx\/Users\/max\/Dev\/Pnut\/Dragonpolls\/phpcs.xml"
|
||||
}
|
28
auth_callback.php
Normal file
28
auth_callback.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*require __DIR__ .'/vendor/autoload.php';
|
||||
|
||||
use APnutI\APnutI;
|
||||
|
||||
session_start();
|
||||
$api = new APnutI(
|
||||
'DKXEf-a9t6_1wWNnQK-bHijxLCIRXFBk',
|
||||
'mmZhbsH4KIoFkqnbIOVMktTSKypZ_QQk',
|
||||
'basic,polls,public_messages,stream,update_profile,write_post',
|
||||
'Playground',
|
||||
'http://localhost/auth_callback.php',
|
||||
'./log.log'
|
||||
);*/
|
||||
|
||||
require_once __DIR__ .'/bootstrap.php';
|
||||
|
||||
if (isset($_GET['code'])) {
|
||||
$success = $api->authenticate($_GET['code']);
|
||||
if ($success) {
|
||||
die('Welcome! <a href="index.php">Back to home</a>');
|
||||
} else {
|
||||
die('Echo error authenticating');
|
||||
}
|
||||
} else {
|
||||
die('error authenticating: ' . $_GET['error_message']);
|
||||
}
|
16
bootstrap.php
Normal file
16
bootstrap.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ .'/vendor/autoload.php';
|
||||
|
||||
use APnutI\APnutI;
|
||||
|
||||
session_start();
|
||||
$config = include(__DIR__.'/config.php');
|
||||
$api = new APnutI(
|
||||
$config['client_id'],
|
||||
$config['client_secret'],
|
||||
$config['permission_scopes'],
|
||||
$config['app_name'],
|
||||
$config['callback_url'],
|
||||
__DIR__.'/'.$config['log_file']
|
||||
);
|
11
composer.json
Normal file
11
composer.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"require": {
|
||||
"hutattedonmyarm/apnuti": "@dev"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type": "path",
|
||||
"url": "../APnutI"
|
||||
}
|
||||
]
|
||||
}
|
202
composer.lock
generated
Normal file
202
composer.lock
generated
Normal file
@ -0,0 +1,202 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "c023d89db0d1884f6caab2753f9f04f6",
|
||||
"packages": [
|
||||
{
|
||||
"name": "hutattedonmyarm/apnuti",
|
||||
"version": "dev-main",
|
||||
"dist": {
|
||||
"type": "path",
|
||||
"url": "../APnutI",
|
||||
"reference": "171b4a0ec6bacc9e53eb3d0f3fdebef8f54533b5"
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-pdo": "*",
|
||||
"monolog/monolog": "^2.0",
|
||||
"php": "^7.4|^8.0",
|
||||
"psr/log": "^1.1"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"APnutI\\": "src"
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "PHP Pnut library",
|
||||
"keywords": [
|
||||
"api",
|
||||
"pnut"
|
||||
],
|
||||
"transport-options": {
|
||||
"relative": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "monolog/monolog",
|
||||
"version": "2.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Seldaek/monolog.git",
|
||||
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Seldaek/monolog/zipball/1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
|
||||
"reference": "1cb1cde8e8dd0f70cc0fe51354a59acad9302084",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"psr/log": "^1.0.1"
|
||||
},
|
||||
"provide": {
|
||||
"psr/log-implementation": "1.0.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
|
||||
"doctrine/couchdb": "~1.0@dev",
|
||||
"elasticsearch/elasticsearch": "^7",
|
||||
"graylog2/gelf-php": "^1.4.2",
|
||||
"mongodb/mongodb": "^1.8",
|
||||
"php-amqplib/php-amqplib": "~2.4",
|
||||
"php-console/php-console": "^3.1.3",
|
||||
"phpspec/prophecy": "^1.6.1",
|
||||
"phpstan/phpstan": "^0.12.59",
|
||||
"phpunit/phpunit": "^8.5",
|
||||
"predis/predis": "^1.1",
|
||||
"rollbar/rollbar": "^1.3",
|
||||
"ruflin/elastica": ">=0.90 <7.0.1",
|
||||
"swiftmailer/swiftmailer": "^5.3|^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
"aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB",
|
||||
"doctrine/couchdb": "Allow sending log messages to a CouchDB server",
|
||||
"elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client",
|
||||
"ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)",
|
||||
"ext-mbstring": "Allow to work properly with unicode symbols",
|
||||
"ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)",
|
||||
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
|
||||
"mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)",
|
||||
"php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib",
|
||||
"php-console/php-console": "Allow sending log messages to Google Chrome",
|
||||
"rollbar/rollbar": "Allow sending log messages to Rollbar",
|
||||
"ruflin/elastica": "Allow sending log messages to an Elastic Search server"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Monolog\\": "src/Monolog"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be",
|
||||
"homepage": "https://seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Sends your logs to files, sockets, inboxes, databases and various web services",
|
||||
"homepage": "https://github.com/Seldaek/monolog",
|
||||
"keywords": [
|
||||
"log",
|
||||
"logging",
|
||||
"psr-3"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Seldaek/monolog/issues",
|
||||
"source": "https://github.com/Seldaek/monolog/tree/2.2.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://github.com/Seldaek",
|
||||
"type": "github"
|
||||
},
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/monolog/monolog",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-12-14T13:15:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/log",
|
||||
"version": "1.1.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/log.git",
|
||||
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/log/zipball/0f73288fd15629204f9d42b7055f72dacbe811fc",
|
||||
"reference": "0f73288fd15629204f9d42b7055f72dacbe811fc",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Log\\": "Psr/Log/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"description": "Common interface for logging libraries",
|
||||
"homepage": "https://github.com/php-fig/log",
|
||||
"keywords": [
|
||||
"log",
|
||||
"psr",
|
||||
"psr-3"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/php-fig/log/tree/1.1.3"
|
||||
},
|
||||
"time": "2020-03-23T09:12:05+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": {
|
||||
"hutattedonmyarm/apnuti": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.0.0"
|
||||
}
|
10
config.php.default
Normal file
10
config.php.default
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'client_id' => '',
|
||||
'client_secret' => '',
|
||||
'log_file' => '../../logs/Dragonpolls.log', // Relative to index.php
|
||||
'app_name' => 'Playground',
|
||||
'callback_url' => 'http://localhost/auth_callback.php',
|
||||
'permission_scopes' => 'basic' //comma seperated string
|
||||
];
|
10
index.php
Normal file
10
index.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ .'/bootstrap.php';
|
||||
|
||||
$is_authenticated = $api->isAuthenticated();
|
||||
if (!$is_authenticated) {
|
||||
echo '<a href="' . $api->getAuthURL() . '">Login with pnut</a>';
|
||||
} else {
|
||||
echo 'Welcome';
|
||||
}
|
28
phpcs.xml
Normal file
28
phpcs.xml
Normal file
@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="Slim PSR2">
|
||||
<!--
|
||||
Include all sniffs in the PEAR standard. Note that the
|
||||
path to the standard does not have to be specified as the
|
||||
PEAR standard exists inside the PHP_CodeSniffer install
|
||||
directory.
|
||||
-->
|
||||
<rule ref="PSR2"/>
|
||||
|
||||
<!--
|
||||
Another useful example of changing sniff settings is
|
||||
to specify the end of line character that your standard
|
||||
should check for.
|
||||
-->
|
||||
<rule ref="Generic.Files.LineEndings">
|
||||
<properties>
|
||||
<property name="eolChar" value="\n"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<arg name="tab-width" value="2"/>
|
||||
<rule ref="Generic.WhiteSpace.ScopeIndent">
|
||||
<properties>
|
||||
<property name="indent" value="2"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
30
view_poll.php
Normal file
30
view_poll.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
require_once __DIR__ .'/bootstrap.php';
|
||||
|
||||
use APnutI\Exceptions\NotFoundException;
|
||||
use APnutI\Exceptions\HttpPnutForbiddenException;
|
||||
use APnutI\Exceptions\NotSupportedPollException;
|
||||
use APnutI\Entities\Poll;
|
||||
|
||||
if (empty($_GET['id']) || !is_numeric($_GET['id']) || $_GET['id'] <= 0) {
|
||||
die('Invalid poll ID');
|
||||
}
|
||||
$poll_id = (int)$_GET['id'];
|
||||
$poll = null;
|
||||
try {
|
||||
$poll = $api->getPoll($poll_id);
|
||||
} catch (NotFoundException $nfe) {
|
||||
die('Poll not found');
|
||||
} catch (HttpPnutForbiddenException $fe) {
|
||||
die('Poll token required!');
|
||||
} catch (NotSupportedPollException $nspe) {
|
||||
die('Sorry, this poll has a not yet supported type: ' . $nspe->getMessage());
|
||||
}
|
||||
|
||||
#echo json_encode($poll);
|
||||
#$user_avatar_url = $api->getAvatarUrl($poll->user->id, 50);
|
||||
$user_avatar_url = $poll->user->getAvatarUrl(50);
|
||||
$prompt = '@' . $poll->user->username . ' asks: ' . $poll->prompt;
|
||||
echo '<img src="'.$user_avatar_url.'"/>';
|
||||
echo $prompt;
|
Loading…
Reference in New Issue
Block a user