diff options
author | sijanec <sijanecantonluka@gmail.com> | 2020-10-18 02:25:07 +0200 |
---|---|---|
committer | sijanec <sijanecantonluka@gmail.com> | 2020-10-18 02:25:07 +0200 |
commit | 3ee87bc75472706f24a90c208b384deef1a89cea (patch) | |
tree | cbfe88e549a870602c0575c8d8de993c6a34788b /main.php | |
parent | modflair dodan (diff) | |
download | oldredditclient-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 'main.php')
-rw-r--r-- | main.php | 65 |
1 files changed, 64 insertions, 1 deletions
@@ -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; + } } ?> |