Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <?php
  3.  //error_reporting(E_ERROR | E_PARSE);
  4. $stream_opts = [
  5.     "ssl" => [
  6.         "verify_peer"=>false,
  7.         "verify_peer_name"=>false,
  8.     ]
  9. ];
  10.  
  11. $Authorization = '563492ad6f91700001000001b068633704ba4d62a98ea93083bfd85c';
  12. $context = stream_context_create(array(
  13.     'http' => array(
  14.         'header' => "Authorization:$Authorization",
  15.     ),
  16.     'ssl' => array(
  17.         "verify_peer"=>false,
  18.         "verify_peer_name"=>false,    
  19.     ),
  20. ));
  21. ?>
  22. <!DOCTYPE html>
  23. <html>
  24. <head>
  25.   <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  26.  
  27.   <script type="text/javascript" src="jquery-1.11.0.js"></script>
  28. <style>
  29. div.gallery {
  30.   border: 1px solid #ccc;
  31. }
  32.  
  33. div.gallery:hover {
  34.   border: 1px solid #777;
  35. }
  36.  
  37. div.gallery img {
  38.   width: 100%;
  39.   height: auto;
  40. }
  41.  
  42. div.desc {
  43.   padding: 15px;
  44.   text-align: center;
  45. }
  46.  
  47. * {
  48.   box-sizing: border-box;
  49. }
  50.  
  51. .responsive {
  52.   padding: 0 6px;
  53.   float: left;
  54.   width: 24.99999%;
  55. }
  56.  
  57. @media only screen and (max-width: 700px) {
  58.   .responsive {
  59.     width: 49.99999%;
  60.     margin: 6px 0;
  61.   }
  62. }
  63.  
  64. @media only screen and (max-width: 500px) {
  65.   .responsive {
  66.     width: 100%;
  67.   }
  68. }
  69.  
  70. .clearfix:after {
  71.   content: "";
  72.   display: table;
  73.   clear: both;
  74. }
  75. </style>
  76. </head>
  77. <body>
  78.  
  79. <form method="post" >
  80.  
  81.   <input type="text" name="query">
  82.   <input type="submit" name="submit">
  83.  
  84. </form>
  85.  
  86.  
  87.  
  88.  
  89. <?php
  90.  
  91. if (isset($_POST['submit'])) {
  92.  
  93. ?>
  94.  
  95.   <input type="button" id="mybutton" value="Sort" />
  96. <div id="list">
  97. <?php
  98.  
  99.  
  100.  
  101. $query = $_POST['query'];
  102.   $api_url = 'https://api.pexels.com/v1/search?query='.$query.'&per_page=8&page=1';
  103.  
  104. $result = file_get_contents($api_url, false, $context);
  105.  
  106. $data = json_decode($result);
  107. include 'html.php';
  108. foreach ($data->photos as $key ) {
  109.  
  110. $ur = $key->url;
  111.  
  112. $id = $key->id;
  113.  
  114. $src_img = $key->src->medium;
  115.  
  116.  
  117. $d = array();
  118. $i=0;
  119. $html = file_get_contents('https://www.pexels.com/medium/below-the-fold-photo-stats/'.$id.'/');
  120.  
  121. $html = str_get_html($html);
  122. echo $html;
  123. foreach($html->find('div') as $element) {
  124.     if ($element->class === 'photo-page__info__statistics__view-avatar-container__icons__icon__text') {
  125.         $d[$i] =  $element->innertext;
  126.         $i++;
  127. }
  128. }
  129.  
  130. $d[0] =  substr(trim($d[0]), 0, -1);
  131.  
  132. ?>
  133.  
  134. <div id="categorie5.1-<?php echo $d[0]; ?>" class="responsive">
  135.   <div  class="gallery">
  136.     <a target="_blank" href="<?php echo $ur; ?>">
  137.       <img style="width:300px;height:250px;"  src="<?php echo $src_img; ?>" alt=""  >
  138.     </a>
  139.     <div class="desc">Download : <?php echo " <i>". $d[0] ."K</i>"; ?><br>
  140.      <br>Likes : <?php echo $d[1]; ?><br></div>
  141.   </div>
  142. </div>
  143.  
  144. <?php
  145.  
  146.  
  147.  
  148.  
  149. }
  150. }
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. // foreach ($ids as $key ) {
  159.  
  160.  
  161. // print_r($data);
  162. // }
  163.  
  164. ?>
  165. </div>
  166. </body>
  167.  
  168. <script type="text/javascript">
  169.    
  170. var sortID = function () {
  171.  
  172.     var toSort = document.getElementById('list').children;
  173.     toSort = Array.prototype.slice.call(toSort, 0);
  174.  
  175.     toSort.sort(function (a, b) {
  176.         var aord = +a.id.split('-')[1];
  177.         var bord = +b.id.split('-')[1];
  178.         // two elements never have the same ID hence this is sufficient:
  179.         return (aord < bord) ? 1 : -1;
  180.     });
  181.  
  182.     var parent = document.getElementById('list');
  183.     parent.innerHTML = "";
  184.  
  185.     for (var i = 0, l = toSort.length; i < l; i++) {
  186.         parent.appendChild(toSort[i]);
  187.     }
  188.  
  189. };
  190.  
  191. window.onload = function(){
  192.     document.getElementById("mybutton").onclick = sortID;
  193. }
  194.    
  195. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement