Advertisement
Guest User

facebump

a guest
Dec 5th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.34 KB | None | 0 0
  1. <?php
  2.     $posts = [
  3.         "GROUP1" => [
  4.             "565167146975015"
  5.         ],
  6.         "GROUP2" => [
  7.             "1727257750831063"
  8.         ],
  9.         "GROUP3" => [
  10.             "494510417393925"
  11.         ]
  12.     ];
  13.     $bumpResults = ['Notify' => 'yes', 'PageResults' => 'No Result', 'Errors' => 'Nothing was processed!'];
  14.     if (!empty($posts)) {
  15.         $accessToken = "1106227486057176|9SnNQUiP09SjWKpN29jYIgG3uyE";
  16.         foreach ($posts as $page => $ids) {
  17.             $bumpResult = BumpPost("bump", $accessToken, $ids);
  18.             if (is_array($bumpResult) && !isset($bumpResult['error'])) {
  19.                 $removalResult = BumpPost("removeBump", $accessToken, $bumpResult);
  20.                 foreach ($removalResult as $key => $value) {
  21.                     switch ($value) {
  22.                         case "successRemove":
  23.                             @$bumpResults['PageResults'][$page]['success'][$key] = "Post: #".$key." was successfully bumped!";
  24.                             if ($bumpResults['Notify'] != "yes") { $bumpResults['Notify'] = "no"; }
  25.                         break;
  26.                         case "failedBump":
  27.                             @$bumpResults['PageResults'][$page]['fails'][$key] = "Post: #".$key." failed to bump!";
  28.                             $bumpResults['Notify'] = "yes";
  29.                         break;
  30.                         case "failedRemove":
  31.                             $key = explode(">", $key);
  32.                             $bumpResults['PageResults'][$page]['fails'][$key[1]] = "Post: #".$key[1]." was bumped but failed to remove comment: #".$key[0]." !";
  33.                             $bumpResults['Notify'] = "yes";
  34.                         break;
  35.                         case "error":
  36.                         default:
  37.                             $bumpResults['PageResults'][$page]['error'][] = $key;
  38.                             $bumpResults['Notify'] = "yes";
  39.                         break;
  40.                     }
  41.                 }
  42.             } else if (is_array($bumpResult) && isset($bumpResult['error'])) {
  43.                 $bumpResults['Errors'][] = $bumpResult['error'];
  44.                 $bumpResults['Notify'] = "yes";
  45.             } else {
  46.                 $bumpResults['Errors'][] = "An error has occurred!";
  47.                 $bumpResults['Notify'] = "yes";
  48.             }
  49.         }
  50.     } else {
  51.         $bumpResults['Errors'][] = "There are no posts to bump.";
  52.         $bumpResults['Notify'] = "yes";
  53.     }
  54.     if ($bumpResults['Notify'] == "yes") {
  55.         echo "<pre>";
  56.         print_r($bumpResults);
  57.         echo "</pre>";
  58.     }
  59.     function BumpPost($action, $accessToken, $ids) {
  60.         $params = ["access_token" => $accessToken];
  61.         $results = [];
  62.         $fixedIDs = [];
  63.         if ($action == "removeBump") {
  64.             foreach ($ids as $id => $result) {
  65.                 switch ($result) {
  66.                     case "successBump":
  67.                         $fixedIDs[] = $id;
  68.                     break;
  69.                     case "failedBump":
  70.                         $results[$id] = $result;
  71.                     break;
  72.                 }
  73.             }
  74.         }
  75.         else
  76.             $fixedIDs = $ids;
  77.         if (!empty($fixedIDs)) {
  78.             foreach ($fixedIDs as $id) {
  79.                 switch ($action) {
  80.                     case "bump":
  81.                         $id .= "/comments";
  82.                         $params['message'] = "Bump!";
  83.                     break;
  84.                     case "removeBump":
  85.                         $id = explode(">", $id);
  86.                         $params['method'] = "delete";
  87.                     break;
  88.                 }
  89.                 if (($action === "bump" || $action === "removeBump") && count($params) > 1) {
  90.                     $ch = curl_init();
  91.                     curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/v2.2/".(($action === "bump") ? $id : $id[0]));
  92.                     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  93.                     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  94.                     curl_setopt($ch, CURLOPT_POST, true);
  95.                     curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  96.                     curl_setopt($ch, CURLOPT_HEADER, 0);
  97.                     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  98.                     $comment = curl_exec($ch);
  99.                     curl_close($ch);
  100.                     $comment = json_decode($comment, true);
  101.                     switch ($action) {
  102.                         case "bump":
  103.                             $results[((isset($comment['id'])) ? $comment['id'].">".rtrim($id, "/comments") : rtrim($id, "/comments"))] = ((count($comment) === 1 && isset($comment['id'])) ? "successBump" : "failedBump");
  104.                         break;
  105.                         case "removeBump":
  106.                             $results[((isset($comment['success'])) ? $id[1] : $id[0].">".$id[1])] = ((count($comment) === 1 && isset($comment['success'])) ? "successRemove" : "failedRemove");
  107.                         break;
  108.                     }
  109.                 } else {
  110.                     $results["Post failed to be processed!"] = "error";
  111.                 }
  112.             }
  113.         } else if (empty($fixedIDs) && count(array_keys($fixedIDs, "failedBump")) != count($fixedIDs)) {
  114.             $results['No IDs were passed.'] = "error";
  115.         }
  116.         return $results;
  117.     }
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement