/** * Do a GET request against given url and returns the redirect_url header, if exists. * @return redirect_url if exists, $url otherwise; leave $url unmodified if something went wrong. * @param string $url */ function resolveUrl($url) { try { $header = doCurlRequest($url); if (array_key_exists('redirect_url', $header) && !empty($header['redirect_url'])) { $redirect_url = $header['redirect_url']; // utm_* paramters removed $parameters_removed = remove_utm_parameters($redirect_url); return $parameters_removed; } else { return $url; } } catch (Exception $ex) { return $url; } }
<?php $host = 'graph.facebook.com'; $method = 'GET'; $path = '/v2.3/' . $page_id . '/posts'; // api call path $query = array('limit' => $count, 'access_token' => $app_id . '|' . $app_secret, 'fields' => 'id,created_time,updated_time,from,story,message,link,name,description'); include "functions.php"; $facebook_data = doCurlRequest($query, $path); if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $protocol = 'https://'; } else { $protocol = 'http://'; } print '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL; print '<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en" xml:base="' . $_SERVER['SERVER_NAME'] . '">' . PHP_EOL; print '<id>tag:facebook.com,2006:/' . $facebook_data['data'][0]['from']['name'] . '</id>' . PHP_EOL; print '<title>' . $facebook_data['data'][0]['from']['name'] . '\'s Facebook Page</title>' . PHP_EOL; @(print '<updated>' . date('c', strtotime($facebook_data['data'][0]['updated_time'])) . '</updated>' . PHP_EOL); print '<link href="https://facebook.com/' . $facebook_data['data'][0]['from']['id'] . '"/>' . PHP_EOL; print '<link href="' . $protocol . $_SERVER['SERVER_NAME'] . str_replace("&", "&", $_SERVER['REQUEST_URI']) . '" rel="self" type="application/atom+xml" />' . PHP_EOL; include "feed.php";
function dsc_courses_form_callback() { //global $wpdb; // this is how you get access to the database check_ajax_referer('dsc-courses-form', 'dsc_nonce'); // Create Laufstrecken post entry $post_data = array('post_title' => $_REQUEST['dsc-course-blogger-name'], 'post_content' => $_REQUEST['dsc-course-desc'], 'post_status' => 'draft', 'post_author' => 1, 'post_type' => 'laufstrecke'); $post_id = wp_insert_post($post_data); //require the needed files if ($post_id) { require_once ABSPATH . "wp-admin" . '/includes/image.php'; require_once ABSPATH . "wp-admin" . '/includes/file.php'; require_once ABSPATH . "wp-admin" . '/includes/media.php'; //then loop over the files that were sent and store them using media_handle_upload(); $course_file_attach_id = 0; $blogger_pic_attach_id = 0; if ($_FILES) { foreach ($_FILES as $file => $array) { if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) { echo "upload error : " . $_FILES[$file]['error']; die; } $attach_id = media_handle_upload($file, $post_id); if ($file == 'dsc-course-file') { $course_file_attach_id = $attach_id; if (substr($array['name'], -3) == 'kmz') { // Parse KMZ file -> extract ZIP, parse and map onto $_REQUEST $path = extractKmz($attach_id); if ($path) { $data = parseKml($path); if (is_array($data)) { $_REQUEST['dsc-course-start-lat'] = $data['start'][0]; $_REQUEST['dsc-course-start-lon'] = $data['start'][1]; $_REQUEST['dsc-course-end-lat'] = $data['end'][0]; $_REQUEST['dsc-course-end-lon'] = $data['end'][1]; $_REQUEST['dsc-waypoints-lat'] = $data['waypoints-lat']; $_REQUEST['dsc-waypoints-lon'] = $data['waypoints-lon']; } } } } else { if ($file == 'dsc-course-blogger-picture') { $blogger_pic_attach_id = $attach_id; } } } } // Connect upload file with post if ($blogger_pic_attach_id > 0) { update_post_meta($post_id, '_thumbnail_id', $blogger_pic_attach_id); } // Google Geocode API to get Infos of startpoint $url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $_REQUEST['dsc-course-start-lat'] . ',' . $_REQUEST['dsc-course-start-lon']; $googleApiStartReturn = doCurlRequest($url); // Google Geocode API to get infos of endpoint if (isset($_REQUEST['dsc-course-end-lat']) && $_REQUEST['dsc-course-end-lat'] != '') { $url = "https://maps.googleapis.com/maps/api/geocode/json?address=" . $_REQUEST['dsc-course-end-lat'] . ',' . $_REQUEST['dsc-course-end-lon']; $googleApiEndReturn = doCurlRequest($url); update_field('endpunkt_json', $googleApiEndReturn, $post_id); } // Waypoints of route $waypointsArr = array(); if (isset($_REQUEST['dsc-waypoints-lat']) && is_array($_REQUEST['dsc-waypoints-lat']) && isset($_REQUEST['dsc-waypoints-lon']) && is_array($_REQUEST['dsc-waypoints-lon'])) { for ($i = 0; $i < count($_REQUEST['dsc-waypoints-lat']); $i++) { if (trim($_REQUEST['dsc-waypoints-lat'][$i]) != '' && trim($_REQUEST['dsc-waypoints-lon'][$i]) != '') { array_push($waypointsArr, array($_REQUEST['dsc-waypoints-lat'][$i], $_REQUEST['dsc-waypoints-lon'][$i])); } } update_field('wegpunkte', json_encode($waypointsArr), $post_id); } // Google Direction API if (isset($_REQUEST['dsc-course-end-lat']) && $_REQUEST['dsc-course-end-lat'] != '') { // Start -> Ziel $url = "http://maps.googleapis.com/maps/api/directions/json?mode=walking&origin=" . $_REQUEST['dsc-course-start-lat'] . ',' . $_REQUEST['dsc-course-start-lon']; $url .= "&destination=" . $_REQUEST['dsc-course-end-lat'] . ',' . $_REQUEST['dsc-course-end-lon']; if ($waypointsArr) { generateWaypoints($url, $waypointsArr); } $googleApiDirectionReturn = doCurlRequest($url); update_field('route_json', removeFontSizeAttr($googleApiDirectionReturn), $post_id); } else { if ($waypointsArr) { // Start == Ziel $url = "http://maps.googleapis.com/maps/api/directions/json?mode=walking&origin=" . $_REQUEST['dsc-course-start-lat'] . ',' . $_REQUEST['dsc-course-start-lon']; $url .= "&destination=" . $_REQUEST['dsc-course-start-lat'] . ',' . $_REQUEST['dsc-course-start-lon']; if ($waypointsArr) { generateWaypoints($url, $waypointsArr); } $googleApiDirectionReturn = doCurlRequest($url); update_field('route_json', removeFontSizeAttr($googleApiDirectionReturn), $post_id); } } // ACF Fields update_field('startpunkt_-_latitude', trim($_REQUEST['dsc-course-start-lat']), $post_id); update_field('startpunkt_-_longitude', trim($_REQUEST['dsc-course-start-lon']), $post_id); update_field('startpunkt_json', $googleApiStartReturn, $post_id); update_field('endpunkt_-_latitude', trim($_REQUEST['dsc-course-end-lat']), $post_id); update_field('endpunkt_-_longitude', trim($_REQUEST['dsc-course-end-lon']), $post_id); update_field('blogger_name', trim($_REQUEST['dsc-course-blogger-name']), $post_id); update_field('blogger_url', trim($_REQUEST['dsc-course-blogger-url']), $post_id); update_field('blogger_laenge', trim($_REQUEST['dsc-length']), $post_id); if ($course_file_attach_id > 0) { update_field('streckendatei', $course_file_attach_id, $post_id); } } wp_die(); // this is required to terminate immediately and return a proper response }