Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // GET THE URL PARAMETERS
- if (isset($_GET['loc'])) {
- $loc = $_GET['loc'];
- } else {
- echo "You didn't specify a location!";
- die;
- }
- //TEMP SET TO THIS ID
- $loc='5uXiVGhhqoaiqIc6YO8Q60'; /// REMOVE ME
- // GET THE CURRENT VERSION FOR THE ITEM SUPPLIED ABOVE
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_RETURNTRANSFER => 1,
- CURLOPT_URL => 'https://api.contentful.com/spaces/gzx8y8irje6a/entries/'.$loc.'?access_token=XXXX'
- ));
- $resp = curl_exec($curl);
- $resp = json_decode($resp,true);
- //echo '<pre>';
- //var_dump( $resp);
- //echo '</pre>';
- curl_close($curl);
- // SET ALL THE VARIABLE DATA
- $version = $resp['sys']['version'];
- $prevVersion = $resp['sys']['publishedVersion'];
- $id = $resp['fields']['id']['en-US'];
- $name = $resp['fields']['name']['en-US'];
- $komm = $resp['fields']['komm']['en-US'];
- $votes = $resp['fields']['votes']['en-US'];
- //echo 'Old'.$votes;
- // INCREMENT THE VOTE VALUE
- $votes++;
- //echo 'New'.$votes;
- // SET THE VARIABLES TYPES
- settype($id, "integer");
- settype($komm, "integer");
- settype($votes, "integer");
- settype($prevVersion, "integer");
- // UPDATE THE ENTRY
- $service_url = 'https://api.contentful.com/spaces/gzx8y8irje6a/entries/'.$loc.'?access_token=XXXX';
- $ch = curl_init($service_url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/vnd.contentful.management.v1+json'));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Contentful-Version: '.$version.''));
- $data2 = json_encode(array('fields' => array('id'=>array('en-US'=>$id),'name'=>array('en-US'=>$name),'komm'=>array('en-US'=>$komm),'votes'=>array('en-US'=>$votes))));
- curl_setopt($ch, CURLOPT_POSTFIELDS,$data2);
- $response = curl_exec($ch);
- if ($response === false) {
- $info = curl_getinfo($ch);
- curl_close($ch);
- die('error occurred during curl exec. info: ' . var_export($info));
- }
- curl_close($ch);
- $decoded = json_decode($response);
- if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') {
- die('error occurred: ' . $decoded->response->errormessage);
- }
- // Publish the entry
- $puburl = 'https://api.contentful.com/spaces/gzx8y8irje6a/entries/'.$loc.'/published?access_token=XXXX';
- $ch = curl_init($puburl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/vnd.contentful.management.v1+json'));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Contentful-Version: '.$prevVersion.''));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: 0'));
- //var_dump($ch);
- $what = curl_exec($ch);
- echo '<pre>';
- var_dump($what);
- echo '</pre>';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement