Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.79 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template Name: Youtube Search Page
  4. *
  5. * A blank custom page template.
  6. *
  7. * Author - Lapan
  8. *
  9. * The "Template Name:" bit above allows this to be selectable
  10. * from a dropdown menu on the edit page screen.
  11. *
  12. */
  13.  
  14. get_header(); ?>
  15.  
  16.  
  17. <div id="primary" class="content-area">
  18. <main id="main" class="site-main" >
  19.  
  20. <?php
  21. while (have_posts()):
  22. the_post(); ?>
  23.  
  24. <?php
  25. define("MAX_RESULTS", 15);
  26.  
  27. if (isset($_POST['submit']))
  28. {
  29. $keyword = $_POST['keyword'];
  30.  
  31. if (empty($keyword))
  32. {
  33. $response = array(
  34. "type" => "error",
  35. "message" => "Please enter the keyword."
  36. );
  37. }
  38. }
  39.  
  40. ?>
  41.  
  42. <style>
  43. body {}
  44.  
  45. .search-form-container {
  46. background: #F0F0F0;
  47. border: #e0dfdf 1px solid;
  48. padding: 20px;
  49. border-radius: 2px;
  50. }
  51.  
  52. .input-row {
  53. margin-bottom: 20px;
  54. }
  55.  
  56. .input-field {
  57. width: 100%;
  58. border-radius: 2px;
  59. padding: 10px;
  60. border: #e0dfdf 1px solid;
  61. }
  62.  
  63. .btn-submit {
  64. padding: 10px 20px;
  65. background: #333;
  66. border: #1d1d1d 1px solid;
  67. color: #f0f0f0;
  68. font-size: 0.9em;
  69. width: 100px;
  70. border-radius: 2px;
  71. cursor: pointer;
  72. }
  73.  
  74. .videos-data-container {
  75. background: #F0F0F0;
  76. border: #e0dfdf 1px solid;
  77. padding: 20px;
  78. border-radius: 2px;
  79. }
  80.  
  81. .response {
  82. padding: 10px;
  83. margin-top: 10px;
  84. border-radius: 2px;
  85. }
  86.  
  87. .error {
  88. background: #fdcdcd;
  89. border: #ecc0c1 1px solid;
  90. }
  91.  
  92. .success {
  93. background: #c5f3c3;
  94. border: #bbe6ba 1px solid;
  95. }
  96.  
  97. .result-heading {
  98. margin: 20px 0px;
  99. padding: 20px 10px 5px 0px;
  100. border-bottom: #e0dfdf 1px solid;
  101. }
  102.  
  103. iframe {
  104. border: 0px;
  105. }
  106.  
  107. .video-tile {
  108. display: inline-block;
  109. margin: 1%;
  110. float: left;
  111. width: 31.3%;
  112. }
  113.  
  114. .videoDiv {
  115. width: 100%;
  116. height: auto;
  117. display: inline-block;
  118. }
  119.  
  120. .videoTitle {
  121. text-overflow: ellipsis;
  122. white-space: nowrap;
  123. overflow: hidden;
  124. font-size: 12px;
  125. width: 100%;
  126. }
  127.  
  128. .videoDesc {
  129. text-overflow: ellipsis;
  130. white-space: nowrap;
  131. overflow: hidden;
  132. font-size: 10px;
  133. width: 100%;
  134. }
  135.  
  136. .videoInfo {
  137. width: 100%;
  138. }
  139.  
  140. .videos-data-container {
  141. background: #F0F0F0;
  142. border: #e0dfdf 1px solid;
  143. padding: 20px;
  144. border-radius: 2px;
  145. float: left;
  146. width: 100%;
  147. }
  148.  
  149. .video-tile:nth-child(3n+1) {
  150. clear: both;
  151. }
  152.  
  153. @media only screen and (min-width: 1920px) {
  154. .videoTitle {
  155. text-overflow: ellipsis;
  156. white-space: nowrap;
  157. overflow: hidden;
  158. font-size: 14px;
  159. width: 100%;
  160. line-height: 2;
  161. }
  162. .videoDesc {
  163. text-overflow: ellipsis;
  164. white-space: nowrap;
  165. overflow: hidden;
  166. font-size: 12px;
  167. width: 100%;
  168. line-height: 2;
  169. }
  170.  
  171. .wpuf-submit input {
  172. height: 155px !important;
  173. }
  174. }
  175.  
  176. @media only screen and (max-width: 1919px) and (min-width: 1200px) {
  177. .videoTitle {
  178. text-overflow: ellipsis;
  179. white-space: nowrap;
  180. overflow: hidden;
  181. font-size: 14px;
  182. width: 100%;
  183. line-height: 2;
  184. }
  185. .videoDesc {
  186. text-overflow: ellipsis;
  187. white-space: nowrap;
  188. overflow: hidden;
  189. font-size: 12px;
  190. width: 100%;
  191. line-height: 2;
  192. }
  193.  
  194. .wpuf-submit input {
  195. height: 100px !important;
  196. }
  197. }
  198.  
  199. @media only screen and (max-width: 1119px) and (min-width: 960px) {
  200. .videoTitle {
  201. text-overflow: ellipsis;
  202. white-space: nowrap;
  203. overflow: hidden;
  204. font-size: 8px;
  205. width: 100%;
  206. line-height: 2;
  207. }
  208. .videoDesc {
  209. text-overflow: ellipsis;
  210. white-space: nowrap;
  211. overflow: hidden;
  212. font-size: 6px;
  213. width: 100%;
  214. line-height: 2;
  215. }
  216.  
  217. .wpuf-submit input {
  218. height: 61px !important;
  219. }
  220. }
  221.  
  222. @media only screen and (max-width: 959px) and (min-width: 768px) {
  223. .videoTitle {
  224. text-overflow: ellipsis;
  225. white-space: nowrap;
  226. overflow: hidden;
  227. font-size: 8px;
  228. width: 100%;
  229. line-height: 2;
  230. }
  231. .videoDesc {
  232. text-overflow: ellipsis;
  233. white-space: nowrap;
  234. overflow: hidden;
  235. font-size: 6px;
  236. width: 100%;
  237. line-height: 2;
  238. }
  239.  
  240. .wpuf-submit input {
  241. height: 117px !important;
  242. }
  243. }
  244.  
  245. @media only screen and (max-width: 767px) and (min-width: 480px) {
  246. .videoTitle {
  247. text-overflow: ellipsis;
  248. white-space: nowrap;
  249. overflow: hidden;
  250. font-size: 8px;
  251. width: 100%;
  252. line-height: 2;
  253. }
  254. .videoDesc {
  255. text-overflow: ellipsis;
  256. white-space: nowrap;
  257. overflow: hidden;
  258. font-size: 6px;
  259. width: 100%;
  260. line-height: 2;
  261. }
  262.  
  263. .wpuf-submit input {
  264. height: 66px !important;
  265. }
  266. }
  267.  
  268. @media only screen and (max-width: 479px) {
  269. .videoTitle {
  270. text-overflow: ellipsis;
  271. white-space: nowrap;
  272. overflow: hidden;
  273. font-size: 5px;
  274. width: 100%;
  275. line-height: 2;
  276. }
  277. .videoDesc {
  278. text-overflow: ellipsis;
  279. white-space: nowrap;
  280. overflow: hidden;
  281. font-size: 4px;
  282. width: 100%;
  283. line-height: 2;
  284. }
  285.  
  286. .wpuf-submit input {
  287. height: 38px !important;
  288. }
  289. }
  290.  
  291. </style>
  292.  
  293.  
  294.  
  295. <h2>Search Videos by keyword using YouTube Data API V3</h2>
  296. <div class="search-form-container">
  297. <form id="keywordForm" method="post" action="">
  298. <div class="input-row">
  299. Search Keyword : <input class="input-field" type="search" id="keyword" name="keyword" placeholder="Enter Search Keyword">
  300. </div>
  301.  
  302. <input class="btn-submit" type="submit" name="submit" value="Search">
  303. </form>
  304. </div>
  305.  
  306. <?php if (!empty($response))
  307. { ?>
  308. <div class="response <?php echo $response["type"]; ?>"> <?php echo $response["message"]; ?> </div>
  309. <?php
  310. } ?>
  311. <?php
  312. if (isset($_POST['submit']))
  313. {
  314.  
  315. if (!empty($keyword))
  316. {
  317. $apikey = 'APIKEY';
  318. $googleApiUrl = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' . rawurlencode($keyword) . '&maxResults=' . MAX_RESULTS . '&key=' . $apikey;
  319.  
  320. $ch = curl_init();
  321.  
  322. curl_setopt($ch, CURLOPT_HEADER, 0);
  323. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  324. curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
  325. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  326. curl_setopt($ch, CURLOPT_VERBOSE, 0);
  327. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  328. $response = curl_exec($ch);
  329.  
  330. curl_close($ch);
  331. $data = json_decode($response);
  332. $value = json_decode(json_encode($data) , true);
  333. ?>
  334.  
  335. <div class="result-heading">About <?php echo MAX_RESULTS; ?> Results</div>
  336. <div class="videos-data-container" id="SearchResultsDiv">
  337.  
  338. <?php
  339. for ($i = 0;$i < MAX_RESULTS;$i++)
  340. {
  341. $videoId = $value['items'][$i]['id']['videoId'];
  342. $title = $value['items'][$i]['snippet']['title'];
  343. $description = $value['items'][$i]['snippet']['description'];
  344. ?>
  345.  
  346. <div class="video-tile">
  347. <div class="videoDiv">
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. <form class="wpuf-form-add wpuf-form-layout1 wpuf-theme-style" action="" method="post">
  369.  
  370. <ul class="wpuf-form form-label-left">
  371.  
  372. <script type="text/javascript">
  373. if ( typeof wpuf_conditional_items === 'undefined' ) {
  374. wpuf_conditional_items = [];
  375. }
  376.  
  377. if ( typeof wpuf_plupload_items === 'undefined' ) {
  378. wpuf_plupload_items = [];
  379. }
  380.  
  381. if ( typeof wpuf_map_items === 'undefined' ) {
  382. wpuf_map_items = [];
  383. }
  384. </script>
  385. <li class="wpuf-el post_title" data-label="Naslov"> <div class="wpuf-label">
  386. <label for="post_title">Naslov <span class="required">*</span></label>
  387. </div>
  388.  
  389. <div class="wpuf-fields">
  390. <input class="textfield wpuf_post_title_1372" id="post_title_1372" type="text" data-required="yes" data-type="text" name="post_title" placeholder="" value="<?php echo $title; ?>" size="40">
  391. <span class="wpuf-wordlimit-message wpuf-help"></span>
  392. <span class="wpuf-help"> Upišite naslov.</span>
  393.  
  394. </div>
  395.  
  396. <script type="text/javascript">
  397. wpuf_conditional_items.push();
  398. </script>
  399. </li><li class="wpuf-el video_play" data-label="Embed Link"> <div class="wpuf-label">
  400. <label for="video_play">Embed Link</label>
  401. </div>
  402.  
  403. <div class="wpuf-fields">
  404. <input class="textfield wpuf_video_play_1372" id="video_play_1372" type="text" data-required="no" data-type="text" name="video_play" placeholder="" value="https://www.youtube.com/watch?v=<?php echo $videoId; ?>" size="40">
  405. <span class="wpuf-wordlimit-message wpuf-help"></span>
  406. <span class="wpuf-help">Iframe kod sa video zapisa ili jednostavno upišite YouTube Link.</span>
  407.  
  408. </div>
  409.  
  410. <script type="text/javascript">
  411. wpuf_conditional_items.push();
  412. </script>
  413. </li><li class="wpuf-el fifu_image_url" data-label="Slika"> <div class="wpuf-label">
  414. <label for="fifu_image_url">Slika <span class="required">*</span></label>
  415. </div>
  416.  
  417. <div class="wpuf-fields">
  418. <input class="textfield wpuf_fifu_image_url_1372" id="fifu_image_url_1372" type="text" data-required="yes" data-type="text" name="fifu_image_url" placeholder="" value="https://i.ytimg.com/vi/<?php echo $videoId; ?>/hqdefault.jpg" size="40">
  419. <span class="wpuf-wordlimit-message wpuf-help"></span>
  420. <span class="wpuf-help">Slika o vašem postu. Link na sliku, treba biti direktan.</span>
  421.  
  422. </div>
  423.  
  424. <script type="text/javascript">
  425. wpuf_conditional_items.push();
  426. </script>
  427. </li><li class="wpuf-el category field-size-small" data-label="Kategorija"> <div class="wpuf-label">
  428. <label for="category">Kategorija <span class="required">*</span></label>
  429. </div>
  430.  
  431.  
  432. <div class="wpuf-fields wpuf_category_select_2413_1372">
  433.  
  434. <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
  435. <option value="4">Video</option>
  436. <option class="level-0" value="2">Text</option>
  437. <option class="level-0" value="4">Video</option>
  438. </select>
  439. </div>
  440.  
  441.  
  442. <script type="text/javascript">
  443. wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2413"});
  444. </script>
  445. </li><li class="wpuf-el category field-size-small" data-label="Text Kategorije"> <div class="wpuf-label">
  446. <label for="category">Text Kategorije</label>
  447. </div>
  448.  
  449.  
  450. <div class="wpuf-fields wpuf_category_select_2895_1372">
  451.  
  452. <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
  453. <option value="-1">– select –</option>
  454. <option class="level-0" value="15">Fimovi</option>
  455. <option class="level-0" value="16">Internet</option>
  456. <option class="level-0" value="17">Islam</option>
  457. <option class="level-0" value="18">Kuhanje</option>
  458. <option class="level-0" value="7">Muzička Teorija</option>
  459. <option class="level-0" value="11">Pravopis</option>
  460. <option class="level-0" value="13">Život</option>
  461. </select>
  462. </div>
  463.  
  464.  
  465. <script type="text/javascript">
  466. wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2895"});
  467. </script>
  468. </li><li class="wpuf-el category field-size-small" data-label="Video Kategorije"> <div class="wpuf-label">
  469. <label for="category">Video Kategorije</label>
  470. </div>
  471.  
  472.  
  473. <div class="wpuf-fields wpuf_category_select_2507_1372">
  474.  
  475. <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
  476. <option value="-1">– select –</option>
  477. <option class="level-0" value="104">Filmovi Video</option>
  478. <option class="level-0" value="103">Igre Video</option>
  479. <option class="level-0" value="8">Muzika Video</option>
  480. <option class="level-0" value="105">Sport Video</option>
  481. <option class="level-0" value="106">Zabava Video</option>
  482. </select>
  483. </div>
  484.  
  485.  
  486. <script type="text/javascript">
  487. wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2507"});
  488. </script>
  489. </li><li class="wpuf-el post_content" data-label="Opis"> <div class="wpuf-label">
  490. <label for="post_content">Opis <span class="required">*</span></label>
  491. </div>
  492.  
  493. <div class="wpuf-fields">
  494.  
  495.  
  496. <textarea class="textareafield wpuf_post_content_1372" id="post_content_1372" name="post_content" data-required="yes" data-type="textarea" placeholder="" rows="5" cols="25"><?php echo $description; ?></textarea>
  497. <span class="wpuf-wordlimit-message wpuf-help"></span>
  498. <span class="wpuf-help">Napišite opis.</span>
  499. </div>
  500. <script type="text/javascript">
  501. wpuf_conditional_items.push();
  502. </script>
  503. </li><li class="wpuf-el tags" data-label="Oznake"> <div class="wpuf-label">
  504. <label for="tags">Oznake</label>
  505. </div>
  506.  
  507. <div class="wpuf-fields">
  508. <input class="textfield wpuf_tags_1372" id="tags_1372" type="text" data-required="no" data-type="text" name="tags" placeholder="" value="" size="40" autocomplete="off">
  509. <span class="wpuf-wordlimit-message wpuf-help"></span>
  510. <span class="wpuf-help">Odvojite zarezom.</span>
  511.  
  512. <script type="text/javascript">
  513. ;(function($) {
  514. $(document).ready( function(){
  515. $('li.tags input[name=tags]').suggest( wpuf_frontend.ajaxurl + '?action=wpuf-ajax-tag-search&tax=post_tag', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } );
  516. });
  517. })(jQuery);
  518. </script>
  519. </div>
  520.  
  521. <script type="text/javascript">
  522. wpuf_conditional_items.push();
  523. </script>
  524. </li> <li class="wpuf-submit">
  525. <div class="wpuf-label">
  526. &nbsp;
  527. </div>
  528.  
  529. <input type="hidden" id="_wpnonce" name="_wpnonce" value="92aca3f438"><input type="hidden" name="_wp_http_referer" value="/dodaj/"> <input type="hidden" name="form_id" value="1372">
  530. <input type="hidden" name="page_id" value="102">
  531. <input type="hidden" id="del_attach" name="delete_attachments[]">
  532. <input type="hidden" name="action" value="wpuf_submit_post">
  533.  
  534. <input style="background-image:url(https://i.ytimg.com/vi/<?php echo $videoId; ?>/hqdefault.jpg);
  535. height: auto;
  536. max-width: 100%;
  537. background-size: cover;
  538. background-clip: border-box;
  539. width: 100%;
  540. height: auto;
  541. display: inline-block;" type="image" class="wpuf-submit-button" name="submit" value="Poslji" src="https://i.ytimg.com/vi/<?php echo $videoId; ?>/hqdefault.jpg">
  542.  
  543.  
  544. </input>
  545.  
  546. </li>
  547.  
  548. </ul>
  549.  
  550. </form>
  551.  
  552. <style>
  553. ul.wpuf-form .wpuf-el {
  554. position: relative;
  555. display: none;
  556. }
  557.  
  558. ul.wpuf-form li .wpuf-label {
  559. float: left;
  560. width: 31%;
  561. min-height: 1px;
  562. font-weight: bold;
  563. display: none;
  564. }
  565.  
  566. ul.wpuf-form li {
  567. margin-left: 0;
  568. margin-bottom: 0px !important;
  569. width: 100%;
  570. height: auto;
  571. padding: 0;
  572. }
  573. .wpuf-loading {
  574. float: left;
  575. width: 31%;
  576. min-height: 1px;
  577. font-weight: bold;
  578. display: none;
  579. }
  580.  
  581. </style>
  582.  
  583. </div>
  584. <div class="videoInfo">
  585. <div class="videoTitle"><b><?php echo $title; ?></b></div>
  586. <div class="videoDesc"><?php echo $description; ?></div>
  587. </div>
  588. </div>
  589. <?php
  590. }
  591. }
  592.  
  593. }
  594. ?>
  595.  
  596.  
  597.  
  598.  
  599.  
  600.  
  601.  
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608.  
  609.  
  610.  
  611.  
  612.  
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637. <?php
  638. endwhile; // End of the loop.
  639.  
  640. ?>
  641.  
  642. </main><!-- #main -->
  643. </div><!-- #primary -->
  644.  
  645. <?php
  646. get_sidebar();
  647. get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement