Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $posts = [
- "GROUP1" => [
- "565167146975015"
- ],
- "GROUP2" => [
- "1727257750831063"
- ],
- "GROUP3" => [
- "494510417393925"
- ]
- ];
- $bumpResults = ['Notify' => 'yes', 'PageResults' => 'No Result', 'Errors' => 'Nothing was processed!'];
- if (!empty($posts)) {
- $accessToken = "1106227486057176|9SnNQUiP09SjWKpN29jYIgG3uyE";
- foreach ($posts as $page => $ids) {
- $bumpResult = BumpPost("bump", $accessToken, $ids);
- if (is_array($bumpResult) && !isset($bumpResult['error'])) {
- $removalResult = BumpPost("removeBump", $accessToken, $bumpResult);
- foreach ($removalResult as $key => $value) {
- switch ($value) {
- case "successRemove":
- @$bumpResults['PageResults'][$page]['success'][$key] = "Post: #".$key." was successfully bumped!";
- if ($bumpResults['Notify'] != "yes") { $bumpResults['Notify'] = "no"; }
- break;
- case "failedBump":
- @$bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!";
- $bumpResults['Notify'] = "yes";
- break;
- case "failedRemove":
- $key = explode(">", $key);
- $bumpResults['PageResults'][$page]['fails'][$key[1]] = "Post: #".$key[1]." was bumped but failed to remove comment: #".$key[0]." !";
- $bumpResults['Notify'] = "yes";
- break;
- case "error":
- default:
- $bumpResults['PageResults'][$page]['error'][] = $key;
- $bumpResults['Notify'] = "yes";
- break;
- }
- }
- } else if (is_array($bumpResult) && isset($bumpResult['error'])) {
- $bumpResults['Errors'][] = $bumpResult['error'];
- $bumpResults['Notify'] = "yes";
- } else {
- $bumpResults['Errors'][] = "An error has occurred!";
- $bumpResults['Notify'] = "yes";
- }
- }
- } else {
- $bumpResults['Errors'][] = "There are no posts to bump.";
- $bumpResults['Notify'] = "yes";
- }
- if ($bumpResults['Notify'] == "yes") {
- echo "<pre>";
- print_r($bumpResults);
- echo "</pre>";
- }
- function BumpPost($action, $accessToken, $ids) {
- $params = ["access_token" => $accessToken];
- $results = [];
- $fixedIDs = [];
- if ($action == "removeBump") {
- foreach ($ids as $id => $result) {
- switch ($result) {
- case "successBump":
- $fixedIDs[] = $id;
- break;
- case "failedBump":
- $results[$id] = $result;
- break;
- }
- }
- }
- else
- $fixedIDs = $ids;
- if (!empty($fixedIDs)) {
- foreach ($fixedIDs as $id) {
- switch ($action) {
- case "bump":
- $id .= "/comments";
- $params['message'] = "Bump!";
- break;
- case "removeBump":
- $id = explode(">", $id);
- $params['method'] = "delete";
- break;
- }
- if (($action === "bump" || $action === "removeBump") && count($params) > 1) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.2/".(($action === "bump") ? $id : $id[0]));
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $comment = curl_exec($ch);
- curl_close($ch);
- $comment = json_decode($comment, true);
- switch ($action) {
- case "bump":
- $results[((isset($comment['id'])) ? $comment['id'].">".rtrim($id, "/comments") : rtrim($id, "/comments"))] = ((count($comment) === 1 && isset($comment['id'])) ? "successBump" : "failedBump");
- break;
- case "removeBump":
- $results[((isset($comment['success'])) ? $id[1] : $id[0].">".$id[1])] = ((count($comment) === 1 && isset($comment['success'])) ? "successRemove" : "failedRemove");
- break;
- }
- } else {
- $results["Post failed to be processed!"] = "error";
- }
- }
- } else if (empty($fixedIDs) && count(array_keys($fixedIDs, "failedBump")) != count($fixedIDs)) {
- $results['No IDs were passed.'] = "error";
- }
- return $results;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement