Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php /** * Disqus Upvote Script * Copyright 2015-2016 YokoLittner, All Rights Reserved * * Requires at least PHP 5.3 and the PHP module cURL * * Website: https://charuru.moe * License: http://creativecommons.org/licenses/by-nc-nd/4.0/ * $ 21.06.2016 00:03 YokoLittner $ **/ $url='https://disqus.com/api/3.0/forums/details?forum=sanctuary-3&attach=forumFeatures&api_key=E8Uh5l5fHZ6gD8U3KycjAIAk46f68Zw7C6eW8WSjZvCLXebZ7p0r1yrYDrLilk2F'; function fetch_remote_file($url, $post_data = array()) { if(!filter_var($url, FILTER_VALIDATE_URL)) { return false; } if(function_exists("curl_init")) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); if(!empty($post_data)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); } $data = curl_exec($ch); if($data === false) { $data = curl_error($ch); } curl_close($ch); return $data; } else { return false; } } if(count($argv) < 2) { die("Not enough parameters (did you pass the username to upvote?)"); } set_time_limit(0); $username = $argv[1]; //Username to Upvote $last_post = array(); $details_url = "https://disqus.com/api/3.0/users/details.json"; $list_url = "https://disqus.com/api/3.0/users/listPosts.json"; $vote_url = "https://disqus.com/api/3.0/posts/vote.json"; //use a different user for each api application $auth = array( array("access_token" => "a1f3156cfd654f8cbc02f0438c882041", "api_key" => "85y4Yz6ucygtqWAb31vsz49UNKQvTleGJCVBbHi9z2bm2hLlLiYNYru9gjWMEUDW", "api_secret" => "tDlgHSj4K49mxk7AxJQbftgsUw7gCoUqHPwZcodQyR7SFgfMzFKG2l5gw857uPhV") ); if(empty($auth) OR (count($auth) > 0 AND empty($auth[0]))) { die("You need to define at least one disqus app."); } function upvote($posts) { global $auth, $last_post, $vote_url; if(!is_array($posts)) { die("Error: ".$posts); } elseif(empty($posts)) { return; } foreach($posts as $post) { $post = (array) $post; $last_post = $post; foreach($auth as $keypair) { $vote = fetch_remote_file($vote_url, array_merge(array("vote" => 1, "post" => $post['id']), $keypair)); echo $post['id'].": voted\n"; } sleep(4); } } $listposts_defaultparams = $list_url."?limit=100&related=forum&user=username:".$username; $default_auth = ""; foreach($auth[0] as $key => $val) { $default_auth .= "&".$key."=".$val; $listposts_defaultparams .= "&".$key."=".$val; } $listposts_params = $listposts_defaultparams; $lookup_user = fetch_remote_file($details_url."?user=username:".$username.$default_auth); $user = json_decode($lookup_user, true); $user = $user['response']; if(is_string($user)) { die("Disqus returned a string: ".print_r($user, true)); } if($user['isPrivate'] == true) { die("The userprofile has to be public."); } $start_listposts = $listposts_params; if(isset($argv[2]) AND !empty($argv[2])) { $start_listposts .= '&since='.$argv[2]; } $initial_scan = fetch_remote_file($start_listposts); $json = json_decode($initial_scan, true); if(!is_array($json['response'])) { die("Disqus returned a string: ".print_r($json['response'], true)); } $first_post = $json['response'][0]; upvote($json['response']); $jsoncursor = $json['cursor']; $invalid_response_count = 0; while($json['cursor']['more'] == true) { if($invalid_response_count >= 5) { die('Got too many invalid responses. Last response: '.print_r($json['response'], true)); } $listposts_params = $listposts_defaultparams."&cursor="+$json['cursor']['next']; $scan = fetch_remote_file($listposts_params); $json = json_decode($scan, true); if(!is_array($json['response'])) { $invalid_response_count++; echo "Got invalid response, get latest posts since last post voted\n"; $listposts_params = $listposts_defaultparams."&since=".$last_post['createdAt']; $scan = fetch_remote_file($listposts_params); $json = json_decode($scan, true); } $invalid_response_count = 0; upvote($json['response']); $jsoncursor = $json['cursor']; } if($json['cursor']['more'] == false) { die("End of program: No more cursors"); } fetch_remote_file($url);
Copy Clear