codice:
<?php
/* =============================================================================
* Copyright 2005-08
* commenti
*
* comenti
*
* commenti
*
* commenti
*
* commenti
* =============================================================================
*/
define('API_KEY', 'ARgbYoNTCbs');
define('API_URL', 'http://www.youtube.com/');
define('API_REST_CALL', API_URL . 'api2_rest?');
define('API_XMLRPC_CALL', API_URL . 'api2_xmlrpc?');
define('BY_TAG', 'list_by_tag');
class youtube {
public $xml, $config = array(), $api_call, $return, $tag, $errors;
public function __construct($api_key = API_KEY, $page = 1, $per_page = 25) {
youtube::set('api_key', API_KEY);
youtube::set('page', $page);
youtube::set('per_page', $per_page);
youtube::modify_call(API_REST_CALL . 'method=youtube.');
}
function xml_to_array($xml) {
$fils = 0;
$tab = false;
$array = array();
foreach($xml->children() as $key => $value) {
$child = youtube::xml_to_array($value);
//To deal with the attributes
//foreach ($node->attributes() as $ak => $av) {
// $child[$ak] = (string)$av;
//}
//Let see if the new child is not in the array
if ($tab == false && in_array($key, array_keys($array))) {
//If this element is already in the array we will create an indexed array
$tmp = $array[$key];
$array[$key] = NULL;
$array[$key][] = $tmp;
$array[$key][] = $child;
$tab = true;
} elseif($tab == true) {
//Add an element in an existing array
$array[$key][] = $child;
} else {
//Add a simple element
$array[$key] = $child;
}
$fils++;
}
if($fils==0) {
return (string)$xml;
}
return $array;
}
// SET A CONFIG VARIABLE
public function set($item, $value) {
$this->config[$item] = $value;
}
// ACCESS CONFIG
public function config($item) {
return $this->config[$item];
}
// MODIFY THE CALL CLASS PROPERTY
public function modify_call($params) {
$this->api_call .= $params;
}
// ECHO THE CALL FOR DEBUGGING
public function return_call() {
return $this->api_call;
}
// YOUTUBE VIDEO METHODS
public function videos($data = '', $method = BY_TAG) {
//---------------------------------------------//
$this->api_call .= 'videos.'; ///////////////////////
//---------------------------------------------//
switch ($method) {
case BY_TAG:
if (isset($_GET['video'])) {
$_GET['video'] = str_replace(' ', '+', $_GET['video']);
$this->tag = '&tag=' . $_GET['video'];
} else {
$this->tag = '&tag='. $data;
}
youtube::modify_call($method . '&dev_id=' . $this->config['api_key'] . $this->tag);
break;
default:
return 'Tags.';
break;
}
// CALL DISPLAY
return youtube::display();
}
public function tags_for_video($tags) {
$tag_links = '';
// explode
$x = explode(' ', $tags);
if (count($x) > 0) {
foreach ($x as $k => $v) {
$tag_links .= "<a href=\"{$_SERVER['PHP_SELF']}?tag=$v\">$v</a> ";
}
} else {
$tag_links = "<a href=\"{$_SERVER['PHP_SELF']}?tag=mutemath\">mutemath</a>";
}
return $tag_links;
}
// DISPLAY RESULTS
public function display() {
// CHECK FOR A NEW PAGE & PER PAGE
if (isset($_GET['page'])) {
youtube::set('page', $_GET['page']);
}
if (isset($_GET['per_page'])) {
youtube::set('per_page', $_GET['per_page']);
}
// per page, page, prev, next
// total videos, total pages
youtube::modify_call('&page=' . youtube::config('page') . '&per_page=' . youtube::config('per_page'));
// SEND REQUEST
$this->return = file_get_contents(youtube::return_call());
$this->xml = new SimpleXMLElement($this->return);
$this->xml = youtube::xml_to_array($this->xml);
// CHECK IF THEY'RE ASKING FOR A VIDEO ID
if (isset($_GET['video_id'])) {
define('YOUTUBE_VIDEO_ID', $_GET['video_id']);
// loop through videos to get videos index
foreach ($this->xml['video_list']['video'] as $indx => $array) {
if ($array['id'] == $_GET['video_id']) {
$index = $indx;
echo $index;
break;
} else {
$index = '';
}
}
// define index
define('YOUTUBE_VIDEO_INDEX', $index);
} else {
define('YOUTUBE_VIDEO_ID', $this->xml['video_list']['video'][0]['id']);
define('YOUTUBE_VIDEO_INDEX', 0);
}
//////////////////////////////////////////
// CREATE DISPLAY CONSTANTS //
/////////////////////////////////////////
define('YOUTUBE_PAGE', youtube::config('page'));
define('YOUTUBE_PER_PAGE', youtube::config('per_page'));
$prev = (youtube::config('page') - 1 == 0) ? 1 : youtube::config('page') - 1;
define('YOUTUBE_PREV_PAGE', $prev . $this->tag);
define('YOUTUBE_NEXT_PAGE', youtube::config('page') + 1 . $this->tag);
define('YOUTUBE_TOTAL_VIDEOS', $this->xml['video_list']['total']);
define('YOUTUBE_TOTAL_PAGES', ceil($this->xml['video_list']['total'] / youtube::config('per_page')));
// CONVERT FROM SIMPLEXML OBJECT TO ARRAY
return $this->xml;
}
}
class video {
function wyniki($query, $p) {
$api = new youtube();
$api->set('per_page', 16);
$api->set('page', $p);
$res = $api->videos(urlencode($query));
$video_list = $res['video_list']['video'];
require_once('class/functions.class.php');
$f = new functions;
foreach ($video_list as $k => $v) {
$this->wynik[] = array(
'title' => $v['title'],
'id' => $v['id'],
'thumb' => $v['thumbnail_url'],
'desc' => $v['description'],
'author' => $v['author'],
'tags' => $v['tags'],
'rating' => $v['rating_avg'],
'views' => $v['view_count'],
'time' => $v['length_seconds'],
'link' => $f->usun_znaki($v['title']),
);
}
return $this->wynik;
}
function get_link($id) {
if($_SESSION['language'] == "pl") {
$langz = 'pl.';
}
else {
$langz = '';
}
$youtube_video_id = $id;
$open = file_get_contents('http://'.$langz.'youtube.com/watch?v='.$youtube_video_id.'');
preg_match_all('/"video_id": "(.*)", "l": (.*), "sk": "(.*)"/', $open, $id); // get video id
preg_match_all('/"l": (.*), "sk": "(.*)"/', $open, $le); // get "l" var
preg_match_all('/"t": "(.*)", "(.*)": "(.*)", "(.*)": "(.*)"/ismU', $open, $te); // get "t" vars
preg_match_all('#<title>YouTube - (.*)<\/title>#ismU', $open, $this->title);
preg_match_all('#<td>(.*): <span class="watch-stat">(.*)<\/span><\/td>#ismU', $open, $this->stats);
preg_match_all('#<div class="watch-video-desc">\s+<span >(.*)<\/span>\s+<\/div>#ismU', $open, $this->desc);
$this->desc = $this->desc[1][0];
$this->stats = $this->stats[2][0];
$this->title = $this->title[1][0];
$this->t = $te[1][0];
$this->return = array('t' => $this->t, 'title' => $this->title, 'added' => $this->stats, 'desc' => $this->desc, 'id' => $this->id);
return $this->return;
}
function records_count($q) {
$this->q = urlencode($q);
$this->url = 'http://youtube.com/results?search_query='.$this->q;
$this->content = file_get_contents($this->url);
preg_match_all('#of about (.*)#ismU', $this->content, $this->results);
$this->results = $this->results[1][0];
$this->results = str_replace(',', '', $this->results);
return $this->results;
}
}
?>
codice:
<?php
require('app-load.php');
$smarty->debugging = false; // debugging false = off, true = on
$smarty->caching = false; // caching = false = off, true = on
$smarty->assign('lang', $lang);
class configuration {
function cfg() {
$cfg = array(
'img_dir' => 'public/title_images/',
'site_url' => 'http://www.mysite.com/',
);
return $cfg;
}
}
$cfg = new configuration;
$smarty->assign('cfg', $cfg->cfg());
if(empty($_GET['slowo']) && empty($_GET['akcja'])) {
$smarty->assign('title', 'KatalogMP3.eu');
} else {
$smarty->assign('title', $f->dynamic_title($_GET['slowo']));
}
if($_GET['aplikacja'] == "price" || $_GET['aplikacja'] == "auctions" && $_GET['aplikacja'] == "lyrics") {
$smarty->assign('title', 'KatalogMP3.eu'); // default site title
}
if($_GET['akcja'] == "show" && $_GET['aplikacja'] == "mp3") {
$mp3_info = $wrzuta->get_file_info($_GET['mp3_id']);
$title = $mp3_info['title'];
$title .= ' MP3 ' . $lang['listen_and_download'];
$smarty->assign('title', $title);
}
if($_GET['akcja'] == "show" && $_GET['aplikacja'] == "video") {
$info = $youtube->get_link($_GET['video_id']);
$title = $info['title'];
$title .= ' Video ' . $lang['watch_and_download'];
$smarty->assign('title', $title);
}
?>
premetto che di php ci capisco ben poco.. mi daresti qualke atra dritta per favore..?