Пример #1
0
 private static function process(&$jobData)
 {
     $data = json_decode($jobData->getData());
     if (!is_object($data) || !property_exists($data, 'class')) {
         echo "Found bad job:\n";
         print_r($data);
         echo "\n";
         bs()->delete($jobData);
         return;
     }
     echo "===============================================\n";
     echo "# Beginning job: " . $data->class . '::' . $data->method . "\n";
     call_user_func_array(array($data->class, $data->method), $data->args);
     echo "\n# Job Complete\n-----------------------------------------------\n\n";
     bs()->delete($jobData);
 }
Пример #2
0
function bs($a, $val, $first, $last)
{
    echo "{$first}<br>";
    echo "{$last}..<br>";
    if ($last - $first < 2) {
        if ($a[$last] == $val) {
            echo "found at {$last}";
            return;
        } elseif ($a[$first] == $val) {
            echo "found at {$first}";
            return;
        }
    }
    $midpoint = floor(($last + $first) / 2);
    if ($a[$midpoint] == $val) {
        echo "found at a midpoint {$midpoint} gotta go to vegas<br>";
        return;
    }
    if ($val > $midpoint) {
        bs($a, $val, $midpoint + 1, $last);
    } else {
        bs($a, $val, $first, $midpoint - 1);
    }
}
Пример #3
0
function process_job(&$jobData)
{
    $data = json_decode($jobData->getData());
    if (!is_array($data)) {
        echo "Found bad job:\n";
        print_r($data);
        echo "\n";
        bs()->delete($jobData);
        continue;
    }
    echo "===============================================\n";
    echo "# Beginning job\n";
    print_r($data);
    foreach ($data as $job) {
        // Get the instagram access token for this user ID
        $user = ORM::for_table('users')->where('instagram_user_id', $job->object_id)->find_one();
        if ($user) {
            if ($user->micropub_success) {
                // Retrieve recent photos for the user after the time specified in the post
                // https://api.instagram.com/v1/users/self/media/recent?min_timestamp=1394295266
                $timestamp = $job->time;
                $media_id = $job->data->media_id;
                if ($photo = IG\get_photo($user, $media_id)) {
                    $entry = h_entry_from_photo($user, $photo);
                    $photo_url = $photo->images->standard_resolution->url;
                    // Download the photo to a temp folder
                    echo "Downloading photo...\n";
                    $filename = download_file($photo_url);
                    if (property_exists($photo, 'videos')) {
                        $video_url = $photo->videos->standard_resolution->url;
                        echo "Downloading video...\n";
                        $video_filename = download_file($video_url, 'mp4');
                    } else {
                        $video_filename = false;
                    }
                    // Send the photo to the micropub endpoint
                    echo "Sending photo" . ($video_filename ? " and video" : "") . " to micropub endpoint: " . $user->micropub_endpoint . "\n";
                    // Collapse category to a comma-separated list if they haven't upgraded yet
                    if ($user->send_category_as_array != 1) {
                        if ($entry['category'] && is_array($entry['category']) && count($entry['category'])) {
                            $entry['category'] = implode(',', $entry['category']);
                        }
                    }
                    print_r($entry);
                    echo "\n";
                    $response = micropub_post($user->micropub_endpoint, $user->micropub_access_token, $entry, $filename, $video_filename);
                    print_r($response);
                    echo "\n";
                    unlink($filename);
                    if ($video_filename) {
                        unlink($video_filename);
                    }
                    // Store the request and response from the micropub endpoint in the DB so it can be displayed to the user
                    $user->last_micropub_response = json_encode($response);
                    $user->last_instagram_photo = $photo->id;
                    $user->last_photo_date = date('Y-m-d H:i:s');
                    $user->save();
                    /*
                    // Add the link to the photo caption
                    
                    $comment_text = '';
                    
                    if($photo->caption && $photo->caption->id) {
                      $comment_id = $photo->caption->id;
                      $comment_text = $photo->caption->text;
                    
                      // Now delete the comment (caption) if there is one
                      $result = IG\delete_comment($user, $media_id, $comment_id);
                      print_r($result);
                    }
                    
                    // Re-add the caption with the citation 
                    $canonical = 'http://aaron.pk/xxxxx';
                    $comment_text .= ' ('.$canonical.')';
                    $result = IG\add_comment($user, $media_id, $comment_text);
                    print_r($result);
                    */
                }
            } else {
                echo "This user has not successfully completed a test micropub post yet\n";
            }
        } else {
            echo "No user account found for Instagram user " . $job->object_id . "\n";
        }
    }
    echo "# Job Complete\n-----------------------------------------------\n\n";
    bs()->delete($jobData);
}
Пример #4
0
    [
      {
          "subscription_id": "1",
          "object": "user",
          "object_id": "1234",
          "changed_aspect": "media",
          "time": 1297286541
      },
      {
          "subscription_id": "2",
          "object": "tag",
          "object_id": "nofilter",
          "changed_aspect": "media",
          "time": 1297286541
      },
      ...
    ]
    */
    // Queue a job to process this request
    bs()->putInTube(Config::$hostname . '-worker', $app->request()->getBody());
});
// Respond to the callback challenge from Instagram
// http://instagram.com/developer/realtime/
$app->get('/instagram/callback', function () use($app) {
    $params = $app->request()->params();
    if (array_key_exists('hub_challenge', $params)) {
        $app->response()->body($params['hub_challenge']);
    } else {
        $app->response()->body('error');
    }
});
Пример #5
0
	$rr= new RemoteRequest( 'http://test.habariproject.org/post', 'POST' );
	$rr->__set_processor( $processor );
	$rr->set_body( 'If you can read this, the test was successful.' );
	$res_post= $rr->execute();
	if ( $res_post === TRUE ) {
	 	$results[]= array( get_class( $processor ), $rr->get_response_headers(), substr( $rr->get_response_body(), 0 ) );
	}
	else {
		$results[]= array( get_class( $processor ), $res_post, );
	}

	foreach ( $tests as $name => $group ) {
		print( "<h2>{$name}</h2>\n" );
		foreach ( $group as $test ) {
			$result= eval( 'return (' . $test . ');' );
			printf( "<p><strong>%s</strong> == ( %s )</p>\n", bs( $result ), var_export( $test, TRUE ) );

			Utils::debug( array_shift( $results ) );
			if ( ! $result ) {
				$tests_failed[$name][]= $test;
			}
		}
	}
}

if ( count( $tests_failed ) ) {
	print( "<h1>Failed tests</h1>\n" );
	foreach ( $tests_failed as $name => $tests ) {
		print( "<h2>{$name}</h2>\n" );
		foreach ( $tests as $test ) {
			print( "<p>{$test}</p>\n" );
Пример #6
0
 function do_stupid_things_in_global_scope()
 {
     /**
      * Test for the RemoteRequest class.
      */
     include '../htdocs/system/classes/remoterequest.php';
     include '../htdocs/system/classes/curlrequestprocessor.php';
     include '../htdocs/system/classes/socketrequestprocessor.php';
     include '../htdocs/system/classes/utils.php';
     include '../htdocs/system/classes/error.php';
     error_reporting(E_ALL | E_STRICT);
     function bs($v)
     {
         return $v ? 'TRUE' : 'FALSE';
     }
     $tests_failed = array();
     $tests = array('GET http://test.habariproject.org/' => array("\$res"), 'GET http://test.habariproject.org/get' => array("\$res_get"), 'POST http://test.habariproject.org/post' => array("\$res_post"));
     print "<h1>Running tests</h1>\n";
     $processors = array(new CURLRequestProcessor(), new SocketRequestProcessor());
     foreach ($processors as $processor) {
         $rr = new RemoteRequest('http://test.habariproject.org/');
         $rr->__set_processor($processor);
         $res = $rr->execute();
         if ($res === TRUE) {
             $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0));
         } else {
             $results[] = array(get_class($processor), $res);
         }
         $rr = new RemoteRequest('http://test.habariproject.org/get');
         $rr->__set_processor($processor);
         $rr->set_params(array('query' => 'var', 'another' => 'variable'));
         $res_get = $rr->execute();
         if ($res_get === TRUE) {
             $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0));
         } else {
             $results[] = array(get_class($processor), $res_get);
         }
         $rr = new RemoteRequest('http://test.habariproject.org/post', 'POST');
         $rr->__set_processor($processor);
         $rr->set_body('If you can read this, the test was successful.');
         $res_post = $rr->execute();
         if ($res_post === TRUE) {
             $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0));
         } else {
             $results[] = array(get_class($processor), $res_post);
         }
         foreach ($tests as $name => $group) {
             print "<h2>{$name}</h2>\n";
             foreach ($group as $test) {
                 $result = eval('return (' . $test . ');');
                 printf("<p><strong>%s</strong> == ( %s )</p>\n", bs($result), var_export($test, TRUE));
                 Utils::debug(array_shift($results));
                 if (!$result) {
                     $tests_failed[$name][] = $test;
                 }
             }
         }
     }
     if (count($tests_failed)) {
         print "<h1>Failed tests</h1>\n";
         foreach ($tests_failed as $name => $tests) {
             print "<h2>{$name}</h2>\n";
             foreach ($tests as $test) {
                 print "<p>{$test}</p>\n";
             }
         }
     } else {
         print "<h1>All tests successful</h1>\n";
     }
 }