summaryrefslogtreecommitdiffstats
path: root/main.php
diff options
context:
space:
mode:
authorsijanec <sijanecantonluka@gmail.com>2020-10-18 02:25:07 +0200
committersijanec <sijanecantonluka@gmail.com>2020-10-18 02:25:07 +0200
commit3ee87bc75472706f24a90c208b384deef1a89cea (patch)
treecbfe88e549a870602c0575c8d8de993c6a34788b /main.php
parentmodflair dodan (diff)
downloadoldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.gz
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.bz2
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.lz
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.xz
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.tar.zst
oldredditclient-3ee87bc75472706f24a90c208b384deef1a89cea.zip
Diffstat (limited to '')
-rw-r--r--main.php65
1 files changed, 64 insertions, 1 deletions
diff --git a/main.php b/main.php
index 0b869e6..31dee80 100644
--- a/main.php
+++ b/main.php
@@ -59,7 +59,7 @@ Errors:
-2 you are not logged in (aj blin trms of srvis bi neseseri)
-3 bad username and/or password (diplomatski odgovor ;-)
-4 not written yet (suka bljet)
- -5
+ -5 value from argument not supported
-6 error in fetched data
0 bad
1 good
@@ -69,8 +69,10 @@ Errors:
private $password;
public $version = array(0, 0, 1);
private $programname = "oldredditclient";
+ private $adminemail = "a"."n"."t"."o"."n"."@"."s"."i"."j"."a"."n"."ec.eu";
private $programdomain = 'oldredditclient.sijanec.eu';
private $cookiedir; // set at runtime, ker je get_curerent_user, v login()
+ private $redditurl = "https://old.reddit.com/";
private $loginurl = "https://old.reddit.com/api/login/";
private $setflairurl = "https://old.reddit.com/api/selectflair";
private $modflairurl = "https://old.reddit.com/api/flair";
@@ -199,5 +201,66 @@ Errors:
}
return true;
}
+ public function fetch($what = "mentions", $value = "jd2fm5", $limit = 100) {
+ if(!curl_getinfo($this->ch)) {
+ if (!$this->login()) {
+ return -2;
+ }
+ }
+ if ($limit>100) {
+ echo "\n[oldredditclient] WARN get(): multipage not implemented (limit>100)!\n";
+ }
+ $ch = $this->ch;
+ switch($what) {
+ case "mentions":
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl."message/mentions.json?limit=".$limit);
+ curl_setopt($ch, CURLOPT_POST, 0);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'X-Modhash: '.$this->modhash,
+ 'X-ContactBotDeveloper: '.$this->adminemail
+ ));
+ $response = curl_exec($ch);
+ if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+ return false;
+ }
+ $arr = json_decode($response, true, 512);
+ return $arr;
+ break;
+ case "post":
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl.$value.".json");
+ curl_setopt($ch, CURLOPT_POST, 0);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'X-Modhash: '.$this->modhash,
+ 'X-ContactBotDeveloper: '.$this->adminemail
+ ));
+ $response = curl_exec($ch);
+ if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200) {
+ return false;
+ }
+ $arr = json_decode($response, true, 512);
+ return $arr;
+ default:
+ return -5;
+ }
+ }
+ public function comment($text = "oldredditClient", $in_reply_to = "jd2fm5") {
+ if (!curl_getinfo($this->ch)) {
+ if (!$this->login()) {
+ return -2;
+ }
+ }
+ $ch = $this->ch;
+ curl_setopt($ch, CURLOPT_URL, $this->redditurl."api/comment");
+ curl_setopt($ch, CURLOPT_POST, 1);
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+ 'X-Modhash: '.$this->modhash,
+ 'X-ContactBotDeveloper: '.$this->adminemail
+ ));
+ curl_setopt($ch, CURLOPT_POSTFIELDS, "thing_id=$in_reply_to&text=".urlencode($text));
+ $response = curl_exec($ch);
+ if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) != 200)
+ return false;
+ return true;
+ }
}
?>