diff options
author | Kukielka <kukielka58@gmail.com> | 2018-04-16 12:15:00 +0200 |
---|---|---|
committer | Kukielka <kukielka58@gmail.com> | 2018-04-16 12:15:00 +0200 |
commit | b9dfafa3bdf2783d8a790c20473e910bd9217d4d (patch) | |
tree | c7cb1a935c89a8bc11327a07933193fa5862bbbe /hp_assets/lib | |
parent | 05247c761f12d490073534875eae7571c87f6d13 (diff) | |
download | simple-dash-fork-b9dfafa3bdf2783d8a790c20473e910bd9217d4d.zip |
Removed Unsplash
Removed Unsplash in order to keep everything simple. (Also the load times were too god damn high)
Diffstat (limited to 'hp_assets/lib')
-rw-r--r-- | hp_assets/lib/ajax_get_image.php | 66 |
1 files changed, 0 insertions, 66 deletions
diff --git a/hp_assets/lib/ajax_get_image.php b/hp_assets/lib/ajax_get_image.php deleted file mode 100644 index 7910619..0000000 --- a/hp_assets/lib/ajax_get_image.php +++ /dev/null @@ -1,66 +0,0 @@ -<?php - - // AJAX call to fetch a new background image - - // http://stackoverflow.com/a/24707821 => use instead of file_get_contents for external URL's - function curl_get_contents($url, $headers = null) { - $ch = curl_init(); - - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_URL, $url); - - // Include potential headers with request - if (!empty($headers)) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - } - - $data = curl_exec($ch); - curl_close($ch); - - return $data; - } - - // Traverse a JSON object given a string selector - function traverse_json($json, $selector) { - $regex = "\[\'?([{}a-z0-9_]+)\'?\]"; - preg_match_all('/' . $regex . '/i', $selector, $matches); - - // Go through each regex match and traverse the JSON object given the keys - $obj = $json; - foreach ($matches[1] as $i => $match) { - if ($match == '{random}' && is_array($obj)) { - // Let's fetch a random index of the array - $rand = rand(0, count($obj)); - $obj = $obj[$rand]; - } else { - // Keep traversing the object - $obj = $obj[$match]; - } - } - - return $obj; - } - - $config = json_decode(file_get_contents(dirname(__FILE__) . "/../../config.json"), true); - - if (!empty($config['custom_url'])) { - // We're fetching from a custom URL - $json = json_decode(curl_get_contents($config['custom_url'], $config['custom_url_headers']), true); - $image_url = traverse_json($json, $config['custom_url_selector']); - - echo json_encode(array('success' => 1, 'url' => $image_url)); - } else if (!empty($config['unsplash_client_id'])) { - // We're fetching from Unsplash's API - $url = "https://api.unsplash.com/photos/random?per_page=1&client_id=" . $config['unsplash_client_id']; - $json = json_decode(curl_get_contents($url), true); - $image_url = $json['urls']['regular']; - $image_user_name = $json['user']['name']; - $image_user_url = $json['user']['links']['html']; - - echo json_encode(array('success' => 1, 'url' => $image_url, 'image_user_name' => $image_user_name, 'image_user_url' => $image_user_url)); - } - - die(); - -?>
\ No newline at end of file |