PHP - Get Meta Information by EmbedURL - metadata

How I will get meta information specified by EmbedURL? I have tried get_meta_tags('MY_VIDEO_URL'). But it returns nothing.
MY HTML:
<!--Video 1-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
<!--Video 2-->
<div class="embed-responsive embed-responsive-16by9" onclick="loadYoutubeVideoThroughYTApi(this)" data-src-id="player-1" data-yut-var="YOUTUBE_VIDEO_ID">
<meta itemprop="description" content="META_DESCRIPTION_2">
<meta itemprop="duration" content="PT1M13S">
<meta itemprop="name" content="META_TITLE_2">
<meta itemprop="thumbnailUrl" content="https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg">
<meta itemprop="embedURL" content="https://www.youtube.com/embed/YOUTUBE_VIDEO_ID">
<meta itemprop="uploadDate" content="2019-02-04T11:00:43.000Z">
</div>
<!--Video 3-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL_2">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL_2">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL_2">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
As you can see the html contains three different videos with three different meta properties. So the result array should be look like this
Desired Output:
Array
(
[0] => Array
(
[url] => INTERNAL_VIDEO_URL
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL
[upload_date] => 2021-03-27T04:10:1600Z
)
[1] => Array
(
[url] => https://www.youtube.com/embed/YOUTUBE_VIDEO_ID
[meta_name] => META_TITLE_2
[meta_description] => META_DESCRIPTION_2
[meta_duration] => PT1M13S
[meta_thumbnail] => https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg
[upload_date] => 2021-03-27T04:10:1600Z
)
[2] => Array
(
[url] => INTERNAL_VIDEO_URL_2
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL_2
[upload_date] => 2021-03-27T04:10:1600Z
)
)
How will I get the set of array like this?

After so many research I have come up with a solution that gives my desired output.
<?php
function load_my_custom_attributes_from_meta_tags( $string )
{
$htmlDom = new DOMDocument();
$errorBuffer = libxml_use_internal_errors( true );
$htmlDom->loadHTML($string);
libxml_clear_errors();
libxml_use_internal_errors( $errorBuffer );
$result = Array(
"url" => NULL,
"meta_name" => NULL,
"meta_description" => NULL,
"meta_duration" => NULL,
"meta_thumbnail" => NULL,
"upload_date" => NULL
);
$arrayKeyMap = Array(
"embedURL"=>"url",
"name"=>"meta_name",
"description"=>"meta_description",
"thumbnailURL"=>"meta_thumbnail",
"duration"=>"meta_duration",
"uploadDate"=>"upload_date"
);
$main_array = array();
foreach ($htmlDom->getElementsByTagName("meta") as $tag) {
$temp = Array();
foreach ( $tag->attributes as $attribute ) {
$temp[ $attribute->nodeName ] = $attribute->nodeValue;
}
if ( array_key_exists( "itemprop" , $temp ) && array_key_exists( "content" , $temp ) && array_key_exists( $temp["itemprop"] , $arrayKeyMap ) ) {
$result[ $arrayKeyMap[ $temp["itemprop"] ] ] = $temp["content"] === "" ? NULL : $temp["content"];
}
}
return $result;
}
$file_contents = file_get_contents('PAGE_URL');
preg_match_all('/<div class=\"embed-responsive\">(.*?)<\/div>/s',$file_contents,$matches);
$all_meta_properties = $matches[0];
$meta_array = array();
foreach($all_meta_properties as $video_meta) {
$meta_array[] = load_my_custom_attributes_from_meta_tags($video_meta);
}
print_r($meta_array);
?>

Related

PHP - Get Meta Information by EmbedURL

How I will get meta information specified by EmbedURL? I have tried get_meta_tags('raw_html'). But it returns nothing.
MY HTML:
<!--Video 1-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
<!--Video 2-->
<div class="embed-responsive embed-responsive-16by9" onclick="loadYoutubeVideoThroughYTApi(this)" data-src-id="player-1" data-yut-var="YOUTUBE_VIDEO_ID">
<meta itemprop="description" content="META_DESCRIPTION_2">
<meta itemprop="duration" content="PT1M13S">
<meta itemprop="name" content="META_TITLE_2">
<meta itemprop="thumbnailUrl" content="https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg">
<meta itemprop="embedURL" content="https://www.youtube.com/embed/YOUTUBE_VIDEO_ID">
<meta itemprop="uploadDate" content="2019-02-04T11:00:43.000Z">
</div>
<!--Video 3-->
<div class="embed-responsive-item" itemprop="video" itemscope="" itemtype="http://schema.org/VideoObject">
<video class="embed-responsive-item" controls="" loop="">
<source src="INTERNAL_VIDEO_URL_2">
</video>
<meta itemprop="name" content="">
<meta itemprop="duration" content="">
<meta itemprop="thumbnailUrl" content="THUMBNAIL_URL_2">
<meta itemprop="embedURL" content="INTERNAL_VIDEO_URL_2">
<meta itemprop="uploadDate" content="2021-03-27T04:10:1600Z">
</div>
As you can see the html contains three different videos with three different meta properties. So the result array should be look like this
Desired Output:
Array
(
[0] => Array
(
[url] => INTERNAL_VIDEO_URL
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL
[upload_date] => 2021-03-27T04:10:1600Z
)
[1] => Array
(
[url] => https://www.youtube.com/embed/YOUTUBE_VIDEO_ID
[meta_name] => META_TITLE_2
[meta_description] => META_DESCRIPTION_2
[meta_duration] => PT1M13S
[meta_thumbnail] => https://i.ytimg.com/vi/YOUTUBE_VIDEO_ID/maxresdefault.jpg
[upload_date] => 2021-03-27T04:10:1600Z
)
[2] => Array
(
[url] => INTERNAL_VIDEO_URL_2
[meta_name] => NULL
[meta_description] => NULL // as you can see no meta tags for description
[meta_duration] => NULL
[meta_thumbnail] => THUMBNAIL_IMAGE_URL_2
[upload_date] => 2021-03-27T04:10:1600Z
)
)
How will I get the set of array like this?

Facebook deleting gaming applications

many game apps I have on Facebook are being deleted, and when I ask the facebook support, the answer is always the same:
"We've disabled your app for creating a negative experience on Facebook in Violation of our policies (https://developers.facebook.com/policy). Common violations include Sending Out excessive requests or notifications, auto-posting without consent, and pre-filling content.
We regret That We will not be able to restore your app. This is the final decision. "
I suspect it is something related to "activity log" because whenever the user enters the application, the message in the activity log: "The user playing game ...", or the user "the user is playing"
The code in facebook I am using is this:
<?php
// appsource
require_once 'facebook.php';
require_once 'appinclude.php';
if (isset($_GET['code'])){
header("Location: " . $canvasPage);
exit;
}
$fb = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => true
));
$me = null;
$user = $fb->getUser();
if($user) {
try {
$me = $fb->api('/me');
} catch(FacebookApiException $e) {
error_log($e);
}
}
if($me) {}
else {
$loginUrl = $fb->getLoginUrl(array(
'scope' => ''
));
echo "
<script type='text/javascript'>
window.top.location.href = '$loginUrl';
</script>
";
exit;
}
if(isset($_GET['signed_request'])) {
$fb_args = "signed_request=" . $_REQUEST['signed_request'];
}
include 'spinc.php';
function ae_detect_ie(){
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;}
?>
<html xmlns:fb="//ogp.me/ns/fb#">
<head>
<meta charset="utf-8">
<meta content='IE=edge' http-equiv='X-UA-Compatible' />
<link rel="stylesheet" type="text/css" href="/style.css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="imagetoolbar" content="no">
<title>TITLE APP</title>
</script>
</head>
<body><div id="all">
<h1>NAME APP</h1>
<!--Resize Iframe-->
<div id="fb-root"></div>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '<?=$appid?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true // enable OAuth 2.0
});
FB.Canvas.setAutoGrow();
</script>
<!-- End Resize Iframe-->
<div id="likebutton"><iframe src="//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fapps.facebook.com%2FXXXAPPNAMEXXX%2F&send=false&layout=standard&width=450&show_faces=false&action=like&colorscheme=light&font&height=35&appId=XXXAPPIDXXX" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe> </div>
<center><object width="750" height="500">
<param value="XXXXXXX.swf" name="movie">
<param name="allownetworking" value="internal" />
<param name="bgcolor" value="#336699" />
<param NAME="wmode" value="opaque">
<param NAME="quality" value="high">
<param name="salign" value="c">
<param name="scale" value="exactfit">
<embed salign="c" scale="exactfit" width="750" height="550" src="XXXXXXXXXXX.swf" bgcolor="#336699" allownetworking="internal" wmode="opaque" allowfullscreen="true" quality="high">
</embed>
</object>
</center>
</div>
</body></html>
Is there something wrong with my code?

Publish embed video in Facebook Wall

I'm trying to publish a video using the PHP SDK. Use the method 'feed' and and then I show the code you i'm using. I using a flv video.
$response = $this->facebook->api('/me/feed/', 'POST', array(
'message' => 'My custom message',
'name' => 'Whatever name',
'description' => 'Whatever description',
'link' => 'http://localhost/my_proyect/',
'picture' => 'http://localhost/my_proyect/my_image.png',
'source' => 'http://localhost/my_proyect/videos/my_video.flv',
'actions' => array(
array(
'name' => 'Some Actions',
'link' => 'http://localhost/my_proyect/'
)
),
'caption' => 'Cool Video'
));
echo json_encode($response);
In my HTML i put the FB meta tags.
<!-- FB Meta Tags -->
<meta property="fb:app_id" content="xxxxxxxxxxxxx" />
<meta property="og:url" content="http://localhost/my_proyect/" />
<meta property="og:video" content="http://localhost/my_proyect/videos/my_video.flv" />
<meta property="og:video:height" content="640" />
<meta property="og:video:width" content="385" />
<meta property="og:video:type" content="application/x-shockwave-flash" />
<!-- FB Meta Tags END -->
When I see the response. Return a array with the ID of post.
When I see the user's wall, just see the post with the text but not the embedded video or image.
What is it I'm doing wrong in my code? Do I need to pass a player or the player that plays my video is by default? Or do not work because I'm on my localhost?
Thanks in advance.

any ideas why facebook like button do not display non-English letters on a wordpress blog?

All non-English (Lithuanian) elements like š,ė,ž,č and more are displayed as code which doesnt look nice. I added a facebook like button to my wordpress blog, which looks like this:
<iframe src="http://www.facebook.com/plugins/like.php?locale=lt_LT&href=<?php echo urlencode(get_permalink($post->ID)); ?>&layout=standard&show_faces=false&width=450&action=like&colorscheme=light" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; position: relative; top: -150px; padding: 0 0 20px 0; overflow:hidden; width:450px; height:60px"></iframe>
You can see that I added locale=lt_LT (I'm from Lithuania)
DOCTYPE:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Im using this:
<?php
$thumb = get_post_meta($post->ID,'_thumbnail_id',false);
$thumb = wp_get_attachment_image_src($thumb[0], false);
$thumb = $thumb[0];
$default_img = get_bloginfo('stylesheet_directory').'/images/default_icon.jpg';
?>
<?php if(is_single() || is_page()) { ?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php single_post_title(''); ?>" />
<meta property="og:description" content="<?php
while(have_posts()):the_post();
$out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", get_the_excerpt());
echo apply_filters('the_excerpt_rss', $out_excerpt);
endwhile; ?>" />
<meta property="og:url" content="<?php the_permalink(); ?>"/>
<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php } else { ?>
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php bloginfo('name'); ?>" />
<meta property="og:url" content="<?php bloginfo('url'); ?>"/>
<meta property="og:description" content="<?php bloginfo('description'); ?>" />
<meta property="og:image" content="<?php if ( $thumb[0] == null ) { echo $default_img; } else { echo $thumb; } ?>" />
<?php } ?>
Can it be a problem with DOCTYPE or something else?
The language of the button sets when you order a button from http://developers.facebook.com/docs/reference/plugins/like/
the button should have the language according to the user. example
js.src = "/ / connect.facebook.net / es_LA / all.js # xfbml = 1 & appId = 250867014982684";
that line where it says you can modify for your code es_LA language. This is html 5.
ok, for like button, try using fb developer page and get the code for htlm5; instead of iframe. i made like button in spanish some time ago, let me check my code. i'll get baack to you.

Display a tree dijit using zend framework

I am trying to display a tree of categories and subcategories by using dijits with zend framework. Haven't been able to find a good example. This is what I've got:
Basically I got the following code as my action:
class SubcategoriesController extends Zend_Controller_Action{
.....
public function loadtreeAction()
{
Zend_Dojo::enableView($this->view);
Zend_Layout::getMvcInstance()->disableLayout();
//Creating a sample tree of categories and subcategories
$a["cat1"]["id"] = "id1";
$a["cat1"]["name"] = "Category1";
$a["cat1"]["type"] = "category";
$subcat1 = array("id" => "Subcat1","name" => "Subcategory1" , "type" => "subcategory");
$subcat2 = array("id" => "Subcat12","name" => "Subcategory12" , "type" => "subcategory");
$a["cat1"]["children"] = array($subcat1,$subcat2);
$treeObj = new Zend_Dojo_Data('id', $a);
$treeObj->setLabel('name');
$this->view->tree = $treeObj->toJson();
}
....
}
And on my view:
<?php
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
$this->dojo()->requireModule('dijit.Tree');
$this->dojo()->requireModule('dojo.parser');
?>
<div dojoType="dojo.data.ItemFileReadStore" url="/Subcategories/loadtree" jsId="store"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="treeModel" store="store" rootId="root" rootLabel="List of Categories" childrenAttrs="children" query="{type:'category'}"></div>
<div dojoType="dijit.Tree" model="treeModel" labelAttrs="ListOfCategories"></div>
It doesn't even seem to try to load the tree at all.
Any help is appreciated
First you must create separate action. One for display, other to load:
public function indexAction()
{
Zend_Dojo::enableView($this->view);
$this->view->dojo()->setDjConfigOption('parseOnLoad', true);
}
public function loadtreeAction()
{
//Creating a sample tree of categories and subcategories
$a["cat1"]["id"] = "id1";
$a["cat1"]["name"] = "Category1";
$a["cat1"]["type"] = "category";
$subcat1 = array("id" => "Subcat1","name" => "Subcategory1" , "type" => "subcategory");
$subcat2 = array("id" => "Subcat12","name" => "Subcategory12" , "type" => "subcategory");
$a["cat1"]["children"] = array($subcat1,$subcat2);
$treeObj = new Zend_Dojo_Data('id', $a);
$treeObj->setLabel('ListOfCategories');
$this->view->tree = $treeObj->toJson();
}
And you dont must forget the
setDjConfigOption('parseOnLoad', true)
In your views/scripts/index.phtml (if you use layout, some parts must be placed in, i let you do that) :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<?php
$this->dojo()->enable();
$this->dojo()->requireModule('dojo.data.ItemFileReadStore');
$this->dojo()->requireModule('dijit.Tree');
$this->dojo()->requireModule('dojo.parser');
echo $this->dojo();
echo $this->dojo()->addStylesheetModule('dijit.themes.tundra');
?>
</head>
<body class="tundra">
<div id="content">
<div dojoType="dojo.data.ItemFileReadStore" url="http://194.79.142.38:1080/rbplm/public/home/index/loadtree" jsId="store"></div>
<div dojoType="dijit.tree.ForestStoreModel" jsId="treeModel" store="store" rootId="root" rootLabel="List of Categories" childrenAttrs="children" query="{type:'category'}"></div>
<div dojoType="dijit.Tree" model="treeModel" labelAttrs="ListOfCategories"></div>
</div>
</body>
</html>
And in loadtree.phtmln just:
<?php echo $this->tree ?>