Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Template Name: Youtube Search Page
- *
- * A blank custom page template.
- *
- * Author - Lapan
- *
- * The "Template Name:" bit above allows this to be selectable
- * from a dropdown menu on the edit page screen.
- *
- */
- get_header(); ?>
- <div id="primary" class="content-area">
- <main id="main" class="site-main" >
- <?php
- while (have_posts()):
- the_post(); ?>
- <?php
- define("MAX_RESULTS", 15);
- if (isset($_POST['submit']))
- {
- $keyword = $_POST['keyword'];
- if (empty($keyword))
- {
- $response = array(
- "type" => "error",
- "message" => "Please enter the keyword."
- );
- }
- }
- ?>
- <style>
- body {}
- .search-form-container {
- background: #F0F0F0;
- border: #e0dfdf 1px solid;
- padding: 20px;
- border-radius: 2px;
- }
- .input-row {
- margin-bottom: 20px;
- }
- .input-field {
- width: 100%;
- border-radius: 2px;
- padding: 10px;
- border: #e0dfdf 1px solid;
- }
- .btn-submit {
- padding: 10px 20px;
- background: #333;
- border: #1d1d1d 1px solid;
- color: #f0f0f0;
- font-size: 0.9em;
- width: 100px;
- border-radius: 2px;
- cursor: pointer;
- }
- .videos-data-container {
- background: #F0F0F0;
- border: #e0dfdf 1px solid;
- padding: 20px;
- border-radius: 2px;
- }
- .response {
- padding: 10px;
- margin-top: 10px;
- border-radius: 2px;
- }
- .error {
- background: #fdcdcd;
- border: #ecc0c1 1px solid;
- }
- .success {
- background: #c5f3c3;
- border: #bbe6ba 1px solid;
- }
- .result-heading {
- margin: 20px 0px;
- padding: 20px 10px 5px 0px;
- border-bottom: #e0dfdf 1px solid;
- }
- iframe {
- border: 0px;
- }
- .video-tile {
- display: inline-block;
- margin: 1%;
- float: left;
- width: 31.3%;
- }
- .videoDiv {
- width: 100%;
- height: auto;
- display: inline-block;
- }
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 12px;
- width: 100%;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 10px;
- width: 100%;
- }
- .videoInfo {
- width: 100%;
- }
- .videos-data-container {
- background: #F0F0F0;
- border: #e0dfdf 1px solid;
- padding: 20px;
- border-radius: 2px;
- float: left;
- width: 100%;
- }
- .video-tile:nth-child(3n+1) {
- clear: both;
- }
- @media only screen and (min-width: 1920px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 14px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 12px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 155px !important;
- }
- }
- @media only screen and (max-width: 1919px) and (min-width: 1200px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 14px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 12px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 100px !important;
- }
- }
- @media only screen and (max-width: 1119px) and (min-width: 960px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 8px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 6px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 61px !important;
- }
- }
- @media only screen and (max-width: 959px) and (min-width: 768px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 8px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 6px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 117px !important;
- }
- }
- @media only screen and (max-width: 767px) and (min-width: 480px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 8px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 6px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 66px !important;
- }
- }
- @media only screen and (max-width: 479px) {
- .videoTitle {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 5px;
- width: 100%;
- line-height: 2;
- }
- .videoDesc {
- text-overflow: ellipsis;
- white-space: nowrap;
- overflow: hidden;
- font-size: 4px;
- width: 100%;
- line-height: 2;
- }
- .wpuf-submit input {
- height: 38px !important;
- }
- }
- </style>
- <h2>Search Videos by keyword using YouTube Data API V3</h2>
- <div class="search-form-container">
- <form id="keywordForm" method="post" action="">
- <div class="input-row">
- Search Keyword : <input class="input-field" type="search" id="keyword" name="keyword" placeholder="Enter Search Keyword">
- </div>
- <input class="btn-submit" type="submit" name="submit" value="Search">
- </form>
- </div>
- <?php if (!empty($response))
- { ?>
- <div class="response <?php echo $response["type"]; ?>"> <?php echo $response["message"]; ?> </div>
- <?php
- } ?>
- <?php
- if (isset($_POST['submit']))
- {
- if (!empty($keyword))
- {
- $apikey = 'APIKEY';
- $googleApiUrl = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' . rawurlencode($keyword) . '&maxResults=' . MAX_RESULTS . '&key=' . $apikey;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $googleApiUrl);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $response = curl_exec($ch);
- curl_close($ch);
- $data = json_decode($response);
- $value = json_decode(json_encode($data) , true);
- ?>
- <div class="result-heading">About <?php echo MAX_RESULTS; ?> Results</div>
- <div class="videos-data-container" id="SearchResultsDiv">
- <?php
- for ($i = 0;$i < MAX_RESULTS;$i++)
- {
- $videoId = $value['items'][$i]['id']['videoId'];
- $title = $value['items'][$i]['snippet']['title'];
- $description = $value['items'][$i]['snippet']['description'];
- ?>
- <div class="video-tile">
- <div class="videoDiv">
- <form class="wpuf-form-add wpuf-form-layout1 wpuf-theme-style" action="" method="post">
- <ul class="wpuf-form form-label-left">
- <script type="text/javascript">
- if ( typeof wpuf_conditional_items === 'undefined' ) {
- wpuf_conditional_items = [];
- }
- if ( typeof wpuf_plupload_items === 'undefined' ) {
- wpuf_plupload_items = [];
- }
- if ( typeof wpuf_map_items === 'undefined' ) {
- wpuf_map_items = [];
- }
- </script>
- <li class="wpuf-el post_title" data-label="Naslov"> <div class="wpuf-label">
- <label for="post_title">Naslov <span class="required">*</span></label>
- </div>
- <div class="wpuf-fields">
- <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">
- <span class="wpuf-wordlimit-message wpuf-help"></span>
- <span class="wpuf-help"> Upišite naslov.</span>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push();
- </script>
- </li><li class="wpuf-el video_play" data-label="Embed Link"> <div class="wpuf-label">
- <label for="video_play">Embed Link</label>
- </div>
- <div class="wpuf-fields">
- <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">
- <span class="wpuf-wordlimit-message wpuf-help"></span>
- <span class="wpuf-help">Iframe kod sa video zapisa ili jednostavno upišite YouTube Link.</span>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push();
- </script>
- </li><li class="wpuf-el fifu_image_url" data-label="Slika"> <div class="wpuf-label">
- <label for="fifu_image_url">Slika <span class="required">*</span></label>
- </div>
- <div class="wpuf-fields">
- <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">
- <span class="wpuf-wordlimit-message wpuf-help"></span>
- <span class="wpuf-help">Slika o vašem postu. Link na sliku, treba biti direktan.</span>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push();
- </script>
- </li><li class="wpuf-el category field-size-small" data-label="Kategorija"> <div class="wpuf-label">
- <label for="category">Kategorija <span class="required">*</span></label>
- </div>
- <div class="wpuf-fields wpuf_category_select_2413_1372">
- <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
- <option value="4">Video</option>
- <option class="level-0" value="2">Text</option>
- <option class="level-0" value="4">Video</option>
- </select>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2413"});
- </script>
- </li><li class="wpuf-el category field-size-small" data-label="Text Kategorije"> <div class="wpuf-label">
- <label for="category">Text Kategorije</label>
- </div>
- <div class="wpuf-fields wpuf_category_select_2895_1372">
- <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
- <option value="-1">– select –</option>
- <option class="level-0" value="15">Fimovi</option>
- <option class="level-0" value="16">Internet</option>
- <option class="level-0" value="17">Islam</option>
- <option class="level-0" value="18">Kuhanje</option>
- <option class="level-0" value="7">Muzička Teorija</option>
- <option class="level-0" value="11">Pravopis</option>
- <option class="level-0" value="13">Život</option>
- </select>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2895"});
- </script>
- </li><li class="wpuf-el category field-size-small" data-label="Video Kategorije"> <div class="wpuf-label">
- <label for="category">Video Kategorije</label>
- </div>
- <div class="wpuf-fields wpuf_category_select_2507_1372">
- <select data-required="no" data-type="select" name="category[]" id="category[]" class="category wpuf_category_1372">
- <option value="-1">– select –</option>
- <option class="level-0" value="104">Filmovi Video</option>
- <option class="level-0" value="103">Igre Video</option>
- <option class="level-0" value="8">Muzika Video</option>
- <option class="level-0" value="105">Sport Video</option>
- <option class="level-0" value="106">Zabava Video</option>
- </select>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push({"condition_status":"no","cond_field":[],"cond_operator":["="],"cond_option":["- select -"],"cond_logic":"all","name":"category_select_2507"});
- </script>
- </li><li class="wpuf-el post_content" data-label="Opis"> <div class="wpuf-label">
- <label for="post_content">Opis <span class="required">*</span></label>
- </div>
- <div class="wpuf-fields">
- <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>
- <span class="wpuf-wordlimit-message wpuf-help"></span>
- <span class="wpuf-help">Napišite opis.</span>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push();
- </script>
- </li><li class="wpuf-el tags" data-label="Oznake"> <div class="wpuf-label">
- <label for="tags">Oznake</label>
- </div>
- <div class="wpuf-fields">
- <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">
- <span class="wpuf-wordlimit-message wpuf-help"></span>
- <span class="wpuf-help">Odvojite zarezom.</span>
- <script type="text/javascript">
- ;(function($) {
- $(document).ready( function(){
- $('li.tags input[name=tags]').suggest( wpuf_frontend.ajaxurl + '?action=wpuf-ajax-tag-search&tax=post_tag', { delay: 500, minchars: 2, multiple: true, multipleSep: ', ' } );
- });
- })(jQuery);
- </script>
- </div>
- <script type="text/javascript">
- wpuf_conditional_items.push();
- </script>
- </li> <li class="wpuf-submit">
- <div class="wpuf-label">
-
- </div>
- <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">
- <input type="hidden" name="page_id" value="102">
- <input type="hidden" id="del_attach" name="delete_attachments[]">
- <input type="hidden" name="action" value="wpuf_submit_post">
- <input style="background-image:url(https://i.ytimg.com/vi/<?php echo $videoId; ?>/hqdefault.jpg);
- height: auto;
- max-width: 100%;
- background-size: cover;
- background-clip: border-box;
- width: 100%;
- height: auto;
- display: inline-block;" type="image" class="wpuf-submit-button" name="submit" value="Poslji" src="https://i.ytimg.com/vi/<?php echo $videoId; ?>/hqdefault.jpg">
- </input>
- </li>
- </ul>
- </form>
- <style>
- ul.wpuf-form .wpuf-el {
- position: relative;
- display: none;
- }
- ul.wpuf-form li .wpuf-label {
- float: left;
- width: 31%;
- min-height: 1px;
- font-weight: bold;
- display: none;
- }
- ul.wpuf-form li {
- margin-left: 0;
- margin-bottom: 0px !important;
- width: 100%;
- height: auto;
- padding: 0;
- }
- .wpuf-loading {
- float: left;
- width: 31%;
- min-height: 1px;
- font-weight: bold;
- display: none;
- }
- </style>
- </div>
- <div class="videoInfo">
- <div class="videoTitle"><b><?php echo $title; ?></b></div>
- <div class="videoDesc"><?php echo $description; ?></div>
- </div>
- </div>
- <?php
- }
- }
- }
- ?>
- <?php
- endwhile; // End of the loop.
- ?>
- </main><!-- #main -->
- </div><!-- #primary -->
- <?php
- get_sidebar();
- get_footer();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement