This repository has been archived by the owner on Jan 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapi.php
58 lines (56 loc) · 2.08 KB
/
api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
Template Name: _pinkoob_api
*/
function pincAPI($id = 0 , string $size = "large-size-dl"):string {
if($id == "rnd"){
$argss = array(
'orderby' => 'rand',
'posts_per_page' => '1'
);
$loop = new WP_Query( $argss );
while ( $loop->have_posts() ) : $loop->the_post();
$rndId = get_the_ID();
endwhile;
$url_image = wp_get_attachment_image_src(get_post_thumbnail_id($rndId), $size)[0];
}else{
$url_image = wp_get_attachment_image_src(get_post_thumbnail_id($id), $size)[0];
}
return $url_image;
}
if (isset($_GET["pin"]) && !empty($_GET) && is_user_logged_in()) {
switch ($_GET["size"]) {
case "small":
$getAPI = ["url" => pincAPI($_GET["pin"], 'small-size-dl'), "size" => "Small"];
break;
case "medium":
$getAPI = ["url" => pincAPI($_GET["pin"], 'medium-size-dl'), "size" => "Medium"];
break;
case "large":
$getAPI = ["url" => pincAPI($_GET["pin"], "large-size-dl"), "size" => "Large"];
break;
case "raw":
$getAPI = ["url" => pincAPI($_GET["pin"]), "size" => "Raw"];
break;
default:
$getAPI = ["url" => pincAPI($_GET["pin"]), "size" => "Raw"];
}
echo json_encode($getAPI);
} else {
get_header();
?>
<div calss="container-fluid">
<h3>The most powerful photo engine in the world.</h3>
<p>Welcome to the Official Pinkoob API. Create with the largest open collection of high-quality photos. For free.</p>
<h4>Try it</h4>
<a href="<?php echo home_url( '/api/?pin=rnd&size=small' ); ?>"><?php echo home_url( '/api/?pin=rnd&size=small' ); ?></a>
<p>in the exapmle above "pin" is the post ID and "size" can be "small", "medium", "large" and "raw".<br>
"size" is Optinal and its default value is "raw" if it's not set.
</p>
<?php if (!is_user_logged_in()){ ?>
<span class="alert alert-info">You need to login or create Account to use API!</span>
</div>
<?php
}
get_footer();
}