Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.41 KB | None | 0 0
  1. <?php
  2. require_once 'users/init.php';
  3. require_once $abs_us_root.$us_url_root.'usersc/includes/header.php';
  4. require_once $abs_us_root.$us_url_root.'usersc/includes/n2.php';
  5.  
  6. error_reporting(E_ALL);
  7. ini_set('display_errors', 1);
  8. $videos = '';
  9. $errors = [];
  10. $successes = [];
  11.  
  12. if(isset($user) && $user->isLoggedIn()){
  13. }
  14. if (!securePage($_SERVER['PHP_SELF'])){die();}
  15.  
  16.  
  17.  if(!empty($_POST))
  18.     {
  19.           $token = $_POST['csrf'];
  20.         if(!Token::check($token)){
  21.           die('Token doesn\'t match! <a href="ytadd.php">Try Again</a>');
  22.         }
  23.        
  24.        
  25.        
  26. if (isset($_POST['vnr']))
  27.     {
  28.         $fileid = trim($_POST['vnr']);
  29.         $fileti = trim($_POST['vna']);
  30.        
  31.           try {
  32.                 // echo "Trying to create item";
  33.                 $time = time();
  34.                 $fields=array(
  35.                   'v_files_userid' => $user->data()->id,
  36.                   'v_files_title' => ucfirst(Input::get('vna')),
  37.                   'v_files_filename' => $fileid,
  38.                   'v_files_explain' => ucfirst(Input::get('explain')),
  39.                   'v_files_timestamp' => $time,
  40.                   'v_files_cachecode' => 2
  41.                 );
  42.                 $db->insert('uc_venus_files',$fields);
  43.                 $theNewId=$db->lastId();
  44.                 // bold($theNewId);
  45.                 $successes[] = 'Database Row Created: '.$theNewId;
  46.                 $successes[] = '<a href="/details.php?f='.$theNewId.'"><img src="/uploads/'.$fileti.'" class="img-responsive thumbnail" /></a>';           
  47.                
  48.                 logger($user->data()->id,"Item Manager","Added item $theNewId.");
  49.                 //Redirect::to($us_url_root.'users/admin_user.php?id='.$theNewId);
  50.               } catch (Exception $e) {
  51.                 die($e->getMessage());
  52.               }
  53.        
  54.     }
  55.        
  56. if (isset($_POST['q']))
  57.     {
  58.     $qq = $_POST['q'];
  59.         set_include_path(get_include_path() . PATH_SEPARATOR . '/var/www/vhosts/cw2/lib/');
  60.         require_once("Google/autoload.php");
  61.         require_once 'Google/Client.php';
  62.         require_once 'Google/Service/YouTube.php';
  63.           /*
  64.            * Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
  65.            * {{ Google Cloud Console }} <{{ https://cloud.google.com/console }}>
  66.            * Please ensure that you have enabled the YouTube Data API for your project.
  67.            */
  68.           $DEVELOPER_KEY = 'xyz';
  69.           $client = new Google_Client();
  70.           $client->setDeveloperKey($DEVELOPER_KEY);
  71.           // Define an object that will be used to make all API requests.
  72.           $youtube = new Google_Service_YouTube($client);
  73.           try {
  74.             // Call the search.list method to retrieve results matching the specified
  75.             // query term.
  76.             $searchResponse = $youtube->search->listSearch('id,snippet', array(
  77.               'q' => $qq,
  78.               'maxResults' => 24,
  79.               'videoEmbeddable' => 'true',
  80.               'type' => 'video'
  81.             ));
  82.             $videos = '';
  83.             // Add each result to the appropriate list, and then display the lists of
  84.             // matching videos, channels, and playlists.
  85.             foreach ($searchResponse['items'] as $searchResult) {
  86.               switch ($searchResult['id']['kind']) {
  87.                 case 'youtube#video':
  88.                 $title = urlencode($searchResult['snippet']['title']);
  89.                 $videos .= '
  90.                
  91.                     <div class="col-xs-6 col-sm-4">
  92.                         <div class="embed-responsive embed-responsive-16by9">
  93.                                   <iframe class="embed-responsive-item" src="//www.youtube.com/embed/'.$searchResult['id']['videoId'].'?autoplay=0"></iframe>
  94.                         </div>
  95.                             <h4>'.$title.'</h4>
  96.                        
  97.                             <input type="hidden" name="vid" value="'.$searchResult['id']['videoId'].'" />
  98.                             <input type="hidden" name="vna" value="'.substr($searchResult['snippet']['title'],0,24).'" />
  99.                            
  100.                            
  101.                             <input type="radio" name="vnr" value="'.$searchResult['id']['videoId'].'" />
  102.                    
  103.                    
  104.                        
  105.                         </div>
  106.                 ';
  107.                 break;
  108.                }
  109.             }
  110.  
  111.           } catch (Google_Service_Exception $e) {
  112.             $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
  113.               htmlspecialchars($e->getMessage()));
  114.           } catch (Google_Exception $e) {
  115.             $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
  116.               htmlspecialchars($e->getMessage()));
  117.           }
  118.         }
  119.  
  120.        
  121.  
  122.     }
  123. $tok = Token::generate();  
  124.  ?>
  125.  
  126.  
  127.  
  128.  
  129. <div id="page-wrapper" style="display: none;">
  130. <div class="container">
  131. <?php require_once $abs_us_root.$us_url_root.'usersc/includes/m2.php'; ?>
  132. <?php echo resultBlock($errors,$successes); ?>
  133.  
  134.  
  135.  
  136.  
  137.     <div id="imagestrip">      
  138.  
  139.  
  140.         <div class="row">
  141.             <div class="col-md-12">
  142.  
  143.                 <form method="POST">
  144.                     <div class="form-group">
  145.                         <label for="q">Search YouTube:</label>
  146.                         <input type="search" id="q" name="q" class="form-control input-lg"  placeholder="Enter Title or Video ID">
  147.                     </div> 
  148.                     <button type="submit" class="btn btn-default btn-lg">Search</button><a class="btn btn-danger btn-lg" href="upload.php">Cancel</a>
  149.                         <input type="hidden" value="<?=$tok;?>" name="csrf">
  150.                 </form>
  151.             </div>
  152.         </div>
  153.        
  154.         <div class="row">
  155.             <div class="col-xs-12">
  156.            
  157.                 <form method="post">
  158.                         <div class="row">
  159.        
  160.                 <?php echo $videos;?>
  161.                 </div>
  162.                 <input type="hidden" value="<?=$tok;?>" name="csrf">
  163.                
  164.                 <?php //print_r($_SESSION);?>
  165.                         <input type="submit" value="Add this" />
  166.                 </form>
  167.            
  168.        
  169.  
  170.             </div>
  171.         </div>
  172.        
  173.     </div>
  174.  
  175. </div> <!-- /container -->
  176. </div> <!-- /#page-wrapper -->
  177.  
  178. <!-- footers -->
  179. <?php require_once $abs_us_root.$us_url_root.'usersc/includes/page_footer.php'; // the final html footer copyright row + the external js calls ?>
  180.  
  181. <script>
  182. $(document).ready(function() {
  183.     $('#page-wrapper').fadeIn();
  184. });
  185. </script>
  186.  
  187. <?php require_once $abs_us_root.$us_url_root.'users/includes/html_footer.php'; // currently just the closing /body and /html ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement