Facebook Style Youtube, Vimeo, Metacafe, Dailymotion Videos Url Expander with jQuery & PHP
In this post we will about how to create Facebook Style Youtube, Vimeo, Metacafe, Dailymotion Videos Url Expander.In my previous post i had discussed about Facebook Like Extract URL data Using jQuery PHP and Ajax. You can create this using php and jQuery.I have used autoembed php class to embed Youtube, Vimeo, Metacafe, Dailymotion and other video urls.Many of the developers are facing problems in embedding Videos from Url.
Features
-
Facebook like Fetch Video Urls like Youtube, Vimeo, Metacafe, Dailymotion and many more.
-
Facebook like Fetch Website urls also in which there are no video.(e.g->NOTE : THIS CODE FOR DEVLOPER NOT A BIGENERE
PHP Code
<?php $url = trim($_REQUEST['url']); $url = check_url($url); function check_url($value) { $value = trim($value); if (get_magic_quotes_gpc()) { $value = stripslashes($value); } $value = strtr($value, array_flip
(get_html_translation_table
(HTML_ENTITIES))); $value = strip_tags($value); $value = htmlspecialchars($value); return $value; } function fetch_record($path) { $file = fopen($path, "r"); if (!$file) { exit("Problem occured"); } $data = ''; while (!feof($file)) { $data .= fgets($file, 1024); } return $data; } $string = fetch_record($url); /// fecth title $title_regex = "/<title>(.+)<\/title>/i"; preg_match_all($title_regex, $string, $title,
PREG_PATTERN_ORDER); $url_title = $title[1]; /// fecth decription $tags = get_meta_tags($url); // fetch images $image_regex = '/<img[^>]*'.'
src=[\"|\'](.*)[\"|\']/Ui'; preg_match_all($image_regex, $string, $img,
PREG_PATTERN_ORDER); $images_array = $img[1]; include "AutoEmbed.class.php"; $AE = new AutoEmbed(); $AE->parseUrl($url); $AE->setParam('wmode','transparent'); $AE->setParam('autoplay','false'); $imglink = $AE->getImageURL(); if(empty($imglink)){ $imglink = $images_array[0]; } $rand = rand(0,9999999999)
.rand(0,9999999999).rand(0,9999999999); ?> <div id="<? echo $rand;
?>" class="videos"> <div class="expand-video" style="display: block;"> <img src="<? echo $imglink; ?>" width="100"
height="100" id="imglink"
show="<? if($AE->parseUrl($url)) {?>true<?}?>"
rel="<? echo $rand; ?>
_iframe" style="display: inline;"> <span>Play</span> <div id="<? echo $rand; ?>_iframe" style="display:none;"><?
echo $AE->getEmbedCode();?></div> </div> <div class="details" style="display: block;"> <h6> <?php echo $url_title[0]; ?> </h6> <p class="link"> <?php echo substr($url ,0,35); ?> </p> <p class="desc"> <?php echo $tags['description']; ?> </p> </div></div></div> <div> </div>
Post on Facebook User Wall using PHP
Basically there are three PHP pages and one file in this tutorial.Configuration
Config.php page store variables,such as Facebook Application ID,Secret ID,Return URL,etc.Change these settings with your own. Notice include_once(â€Å“inc/facebook.phpâ€); , inc folder contains Facebook PHP SDK files, which can be downloaded from https://github.com/facebook/php-sdk, but I have already included these files in downloadable zip file.<?php include_once("inc/facebook.php"); //
include facebook SDK $appId = 'xxxxxxxxxxxxxx'; /
/Facebook App ID $appSecret =
'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //
Facebook App Secret $return_url = 'http://yoursite.com/scriptpage
/process.php'; //return url
(url to script) $homeurl = 'http://yoursite.com
/scriptpage/'; //return to home $fbPermissions = 'publish_stream';
//Required facebook permissions Some Codes.... ?>
Index Page
index.php file contains a message form for this demo, user is redirected to facebook authentication page, where she/he is required to authenticate and grant mainly one extended permissions publish_stream.It seems to post on page wall, application requires publish_stream.Once user grants the permission, user is redirected back to index page, where she/he is presented with a form containing a message input box.On form submission the data is sent to process.php.
<? include 'config.php'; if(!$fbuser){ //Show login button for guest users $loginUrl = $facebook->getLoginUrl
(array('redirect_uri'=>$homeurl
,'scope'=>$fbPermissions)); echo '<a href="'.$loginUrl.'"><img
src="img/facebook-login.png" border="0"></a>'; }else{ //Everything looks good, show message form. ?> <html> <head> <meta http-equiv="Content-Type"
content="text/html;
charset=utf-8" /> <title>Post to Facebook
User Wall Demo</title> <script type="text/javascript"
src="http://code.jquery.
com/jquery.min.js"></script> <link href="style.css" rel=
"stylesheet" type="text/css" /> </head> <body> <div class="fbpagewrapper"> <div id="fbpageform" class="pageform"> <form id="form" name="form" method="post"
action="process.php"> <h1>Post to Facebook user Wall</h1> <p>Type Message to post!</p> <label>Message <span class="small">Write something to post!</span> </label> <textarea name="message"></textarea> <button type="submit" class="button"
id="submit_button">Send Message</button> <div class="spacer"></div> </form> </div> </div> </body> </html> <?}?>
Posting to Facebook User Wall
$msg_body = array( 'message' => 'My message for wall' );
$msg_body = array( 'link' => 'http://www.shubhamtipstricks.com', 'message' => 'My message for wall' );
$msg_body = array( 'source' => '@'.realpath('img/myphoto.png'), 'message' => 'My Message for wall' );
<?php include_once("config.php"); if($_POST) { $userMessage = $_POST["message"]; if(strlen($userMessage)<1) { //message is empty echo 'No message was entered!'; exit(); } $post_url = '/me/feed'; /* // posts message on page feed $msg_body = array( 'message' => $userMessage, 'name' => 'Message Posted from
ShubhamTipsTricks.com!', 'caption' => "Nice stuff", 'link' => "http://
shubhamtipstricks.com/?p=2851", 'description' =>
'Demo of php script posting message on the facebook user wall.', 'picture' =>
'http://shubhamtipstricks.
com/wp-content/uploads/2012/11
/Shubham-Tips-Tricks.png' 'actions' => array(
array(
'name' => 'Shubham Tips Tricks',
'link' => 'http://www.shubhamtipstricks.com' ) ) ); */ //posts message on page statues $msg_body = array( 'message' => $userMessage ); Some Codes..... } ?>
0 comments:
Post a Comment