Is there a way! when click on facebook share button from post the image should be top of post title and description instead of left to on facebook share window.
i have tried this code as a Wordpress plugin
add_image_size('fb-preview', 190, 190, true);
// get image preview
function ST4_get_FB_image($post_ID){
$post_thumbnail_id = get_post_thumbnail_id( $post_ID );
if ($post_thumbnail_id){
$post_thumbnail_img = wp_get_attachment_image_src( $post_thumbnail_id, 'fb-preview');
return $post_thumbnail_img[0];
}
}
// get post description
function ST4_get_FB_description($post){
if ($post->post_excerpt){
return $post->post_excerpt;
} else {
// post excerpt is not set, we'll take first 55 words from post content
$excerpt_length = 55;
// clean post content
$text = str_replace("\r\n"," ", strip_tags(strip_shortcodes($post->post_content)));
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) {
array_pop($words);
$excerpt = implode(' ', $words);
return $excerpt;
}
}
}
function ST4FB_header(){
global $post;
$post_featured_image = ST4_get_FB_image($post->ID);
$post_description = ST4_get_FB_description($post);
if ( (is_single()) AND ($post_featured_image) AND ($post_description) ){
?>
<link rel="image_src" href="<?php echo $post_featured_image; ?>" />
<meta name="title" content="<?php echo $post->post_title; ?>" />
<meta name="description" content="<?php echo $post_description; ?>" />
<?php
}
}
add_action('wp_head','ST4FB_header');
and facebook share button on post page.
ID)); ?>&t=post_title); ?>">Share on Facebook
i would suggest reading the facebook api docs and taking the mindset that they don't want you to mess with their stuff.
https://developers.facebook.com/docs/reference/dialogs/feed/
even without that mindset everything here suggests that you get no control over this, and if you do it is an undiscovered bug that fb would want to fix (and hence break whatever you find).
Related
I am using graph API to get access tokken using a reference "pagename?fields=picture" for my facebook page to be used on my website.
This is the function that I am using;
function get_facebook_post_pic_full_url($feed_id)
{
echo "<script>console.log( 'Debug Objects: " . $feed_id . "' );</script>";
$ursls = 'https://graph.facebook.com/'.$feed_id.'/?fields=full_picture,picture&access_token="Access Tokken"';
$fb_act = json_decode(file_get_contents($ursls));
return $fb_act;
}
function get_facebook_page_feed($fts_limiter='')
{
if(!$fts_limiter)
{
$fts_limiter = 1;
}
$pageid = get_field('facebook_page_id','option');
//If there's no Access Token then use a default
$access_token_array = array(
'sampleaccess tokken'
'sampleaccess tokken'
'sampleaccess tokken'
);
$access_token = $access_token_array[rand(0, 11)];
$graph_data = 'https://graph.facebook.com/'.$pageid.'/posts?fields=id,from,message,story,story_tags,link,source,name,caption,description,type,status_type,object_id,attachments,created_time&access_token='.$access_token.'&limit=1&locale=en_US';
$fb_activity = json_decode(file_get_contents($graph_data));
return $fb_activity;
}
And this is used to fetch and display image and caption and date;
<div class="col-xs-12 col-sm-6 col-md-4 no-padding">
<div class="facebook_img">
<?php
$fb_feeds = get_facebook_page_feed();
if(!empty($fb_feeds)):
$feeds = $fb_feeds->data[0];
$created_time = $feeds->created_time;
$link = $feeds->link;
$feed_id = $feeds->id;
$full_arr = get_facebook_post_pic_full_url($feed_id);
$full_picture = $full_arr->full_picture;
$message = $feeds->message;
$submessage = substr($message,0,75);
?>
<!--<?php var_dump($full_arr);?> -->
<img style="width:405px;height:341px" src="<?php echo $full_picture; ?>" alt="facebook"/>
<div class="fb_content"> <a target="_blank" href="<?php echo $link; ?>"><?php echo $submessage; ?></a>
<dt><?php echo date('d/m/Y', strtotime($created_time)); ?></dt>
</div>
<?php endif; ?>
</div>
The issue is that I am getting this error when I run; $ursls = 'https://graph.facebook.com/'.$feed_id.'/?fields=full_picture,picture&access_token="Access Tokken"';
{
"error": {
"message": "(#100) Tried accessing nonexisting field (full_picture) on node type (Page)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "traceid"
}
}
The code and everything was working fine and it has stopped 2 months ago. Can anyone please tell me why full_picture is nonexisting field? Does that mean that we can not use full_picture parameter for page anymore? Any help is appreciated! :)
The code and everything is working fine and facebook has not changed any parameters that are used in the above post. My access tokken was having some issues, I generated a new one and it started to work now. Thank you!
I have a function in Wordpress that checks if the user of the post haves a Facebook id then add the specific meta tag with this Facebook id else if is empty then it's adding the preset Facebook id. The problem is that if the user of the post haves an Facebook id in the facebookurl area the function is only adding the default Facebook id.
function facebook_author_tag() {
if ( is_single() ) {
global $post;
$author = (int) $post->post_author;
$facebook_url = the_author_meta('facebook_url');
if ( !empty( $facebook_url ) )
{
echo '<meta property="article:author" content="'. $facebook_url .'" />';
} else{
echo '<meta property="article:author" content="https://www.facebook.com/test" />';
}
}
}
add_action( 'wp_head', 'facebook_author_tag', 8 );
And this code I used to insert the socials fields in the user's page.
function my_new_contactmethods( $contactmethods ) {
// Add Twitter
$contactmethods['twitter'] = 'Twitter';
//add Facebook
$contactmethods['facebook'] = 'Facebook';
return $contactmethods;
}
add_filter('user_contactmethods','my_new_contactmethods',10,1);
Thanks if anyone can help me.
In case anyone have this issue this was the working code:
function facebook_author_tag() {
if ( is_single() ) {
global $post;
$author = (int) $post->post_author;
$facebook_url = get_the_author_meta( 'facebook_url', $author );
if (empty( $facebook_url ) ) {
echo '<meta property="article:author" content="https://www.facebook.com/test/"/><meta property="article:publisher" content="https://www.facebook.com/test/" />';
}
else{
echo '<meta property="article:author" content="'. $facebook_url .'" /><meta property="article:publisher" content="https://www.facebook.com/test/" />';
}
}
}
So im getting a blank page when loading this page within an iFrame on Internet explorer, every other browser works fine..
I have also tried using p3p headers as other people have suggested, but to no avail.
<?php
require ("connect.php");
require ("config.php");
require ("fb_config.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Login handler</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="css/login.css" type="text/css">
</head>
<body>
<?//=$user?>
<?php
if($user == 0) {
echo "You are not logged into facebook. Nice try.";
}else{
$query = "SELECT id,fb_id,login_ip,login_count,activated,sitestate FROM login WHERE fb_id='".mysql_real_escape_string($user)."'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
if (mysql_num_rows($result) == 0) {
$sql = "INSERT INTO login SET id = '', fb_id ='" .mysql_real_escape_string($user). "', name = '" .rand(10000000000000000,99999999999999999999). "', signup =NOW() , password = '" .mysql_real_escape_string($pass). "', state = '0', mail = '" .mysql_real_escape_string($_POST['mail']). "',location='".mysql_real_escape_string($randomlocation)."',location_start='".mysql_real_escape_string($randomlocation)."', signup_ip='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',ref='".mysql_real_escape_string($_POST['ref'])."', activation_id = '" .mysql_real_escape_string($activation_link). "',activated='2', killprotection = '$twodayprot',gender='" .mysql_real_escape_string($_POST["gender"]). "'";
$res = mysql_query($sql);
}
//if($row['fb_id'] != $user){
//echo "Your facebook ID: $user is NOT in the MW DB.";
//exit();
//}else{
if(empty($row['login_ip'])){
$row['login_ip'] = $_SERVER['REMOTE_ADDR'];
}else{
$ip_information = explode("-", $row['login_ip']);
if (in_array($_SERVER['REMOTE_ADDR'], $ip_information)) {
$row['login_ip'] = $row['login_ip'];
}else{
$row['login_ip'] = $row['login_ip']."-".$_SERVER['REMOTE_ADDR'];
}
}
$update_login = mysql_query("UPDATE login SET login_count=login_count+'1' WHERE name='".mysql_real_escape_string($_POST['username'])."'")
or die(mysql_error());
$_SESSION['user_id'] = $row['id'];
$result = mysql_query("UPDATE login SET userip='".mysql_real_escape_string($_SERVER['REMOTE_ADDR'])."',login_ip='".mysql_real_escape_string($row['login_ip'])."',login_count='0' WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'")
or die(mysql_error());
if ($row['sitestate'] == 0){
header("location: home.php");
} elseif ($row['sitestate'] == 2) {
header("location: killed.php?id={$row['id']}&encrypted={$row['password']}");
} else {
header("location: banned.php?id={$row['id']}&encrypted={$row['password']}");
}
}// id check.
?>
</body>
</html>
You're probably missing p3p headers causing your browser not to accept cookies from Facebook on your site.
See http://www.hanselman.com/blog/TheImportanceOfP3PAndACompactPrivacyPolicy.aspx
or http://www.admon.org/how-to-implement-p3p-http-headers-for-cross-site-cookies/ for more information.
Try removing the line that references your external css file and see if your page loads?
I just solved a similar problem I had. I had the correct p3p headers set up and I narrowed the problem down to css.
The problematic css style was a position:relative; on the html,body element - removing this fixed the problem of Facebook showing my iframe as a blank page.
If removing all the CSS displays something on your page, then you may need to add your CSS step-by-step to find out the culprit as some other kind of css sytle may break the page.
I've been trying to use the JsPush Zend progress bar in a Zend MVC application, but have not been successful. I've used the JsPush.php example found on github to create a standalone progress bar test application, but this does not use the Zend MVC framework. When I apply the CSS, HTML, JavaScript, and PHP code from the JsPush example program, I see my progress bar appear (the CSS works) but I don't get any results during my socket write process. I've used the JsPush CSS code verbatim in a css file that is linked to my application so I won't repeat that here. Below are exerpts from my MVC application, the controller code:
protected function _sendFile($job)
{
$fp = fopen($job->source_file, "rb");
if($fp == null || $fileData['size'] == 0) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
$this->totalXmitSize = $fileSize;
$this->currentXmitSize = 0;
$progressMessage = '';
$adapter = new Zend_ProgressBar_Adapter_JsPush(array
('updateMethodName' => 'Zend_ProgressBar_Update',
'finishMethodName' => 'Zend_ProgressBar_Finish'));
$progressBar = new Zend_ProgressBar($adapter, 0, $this->totalXmitSize);
while(!feof($fp)) {
$blkSize = ($fileSize > 1024) ? 1024 : $fileSize;
$xmitBuf = fread($fp, $blkSize);
if($xmitBuf === false || !strlen($xmitBuf)) {
$this->view->errorMessage = 'Error - file open failed for ' . $job->source_file;
return false;
}
if($this->_writeData($xmitBuf, $blkSize) == false) {
return false;
}
$fileSize -= $blkSize;
$this->currentXmitSize += $blkSize;
$progress = $this->_calculateXmitProgress();
if($progress < 25) {
$progressMessage = 'Just beginning';
} elseif($progress < 50) {
$progressMessage = 'less than half done';
} elseif($progress < 75) {
$progressMessage = 'more than half done';
} else {
$progressMessage = 'almost done';
}
$progressBar->update($this->currentXmitSize, $progressMessage);
if($fileSize <= 0) {
break;
}
}
fclose($fp);
$xmitBuf = '';
$bufLen = 0;
if($this->_readData($xmitBuf, $bufLen) === false) {
return false;
}
$progressBar->finish();
if(strncmp($xmitBuf, MSG_STATUS_OK, strlen(MSG_STATUS_OK)) != 0) {
$this->view->errorMessage = 'Error - invalid response after file transfer complete';
return false;
}
return true;
}
The view code:
<?php
$this->title = "My Title";
$this->headTitle($this->title);
$this->layout()->bodyScripts = 'onload="startProgress();"';
?>
<p class="errors"> <?php echo $this->errorMessage ?> </p >
<?php echo $this->form->setAction($this->url());
?>
<div id="progressbar">
<div class="pg-progressbar">
<div class="pg-progress" id="pg-percent">
<div class="pg-progressstyle"></div>
<div class="pg-invertedtext" id="pg-text-1"></div>
</div>
<div class="pg-text" id="pg-text-2"></div>
</div>
</div>
<div id="progressBar"><div id="progressDone"></div></div>
The layout.phtml code:
function startProgress()
{
var iFrame = document.createElement('iframe');
document.getElementsByTagName('body')[0].appendChild(iFrame);
iFrame.src = 'MyController.php';
}
function Zend_ProgressBar_Update(data)
{
document.getElementById('pg-percent').style.width = data.percent + '%';
document.getElementById('pg-text-1').innerHTML = data.text;
document.getElementById('pg-text-2').innerHTML = data.text;
}
function Zend_ProgressBar_Finish()
{
document.getElementById('pg-percent').style.width = '100%';
document.getElementById('pg-text-1').innerHTML = 'done';
document.getElementById('pg-text-2').innerHTML = 'done';
}
</script>
</head>
<body <?php echo $this->layout()->bodyScripts ?>>
<div>
<h1><?php echo $this->escape($this->title); ?></h1>
<?php echo $this->layout()->content; ?>
</div>
When this runs I get a ton of JavaScript in the page source, but no progress results:
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":0,"max":3397,"percent":0,"timeTaken":0,"timeRemaining":null,"text":null});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":1024,"max":3397,"percent":30.14424492199,"timeTaken":0,"timeRemaining":0,"text":"less than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":2048,"max":3397,"percent":60.28848984398,"timeTaken":0,"timeRemaining":0,"text":"more than half done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3072,"max":3397,"percent":90.43273476597,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Update({"current":3397,"max":3397,"percent":100,"timeTaken":0,"timeRemaining":0,"text":"almost done"});</script><br />
<script type="text/javascript">parent.Zend_ProgressBar_Finish();</script><br />
All of this JavaScript pushes my form out of view. I have spent days on the Zend documentation site and scouring the web to find examples of someone successfully using Zend ProgressBar in a MVC framework application, but can not find any working examples. Thanks in advance for any help.
Well I have been successful in getting a JsPush progress bar to work to some degree, but not 100% correct for my application.
The progressbar works, but the form results end up in the hidden iframe. There is no way to get to the submit buttons on that iframe, so my user has to use the back button to get out of the form.
The only way to get the progress bar to work is to use the target attribute in the form and assign it to the name attribute of the iframe. If I don't use the target attribute, the form scrolls for every call to progressBar->update;. So my form results end up on the parent page several hundred lines scrolled down and the scroll bar never works.
I've tried using the example from the Zend documentation, but it doesn't work. This is my first venture into the Zend framework and it has been very frustrating and disappointing. Not a single response to my original question from 28 days ago.
I had same problem. For me it worked since I did the following steps.
Go to the php.ini and check if the following Data is set in your php.ini.
output_buffering = Off
;output_handler =
zlib.output_compression = Off
;zlib.output_handler =
Then go to class Zend_ProgressBar_Adapter_JsPush and find the Method - which is at the bottom - _outputData. Delete everything in this Method and input
// 1024 padding is required for Safari, while 256 padding is required
// for Internet Explorer. The <br /> is required so Safari actually
// executes the <script />
echo str_pad($data . '', 1024, ' ', STR_PAD_RIGHT) . "\n";
echo(str_repeat(' ',256));
if (ob_get_length()){
#ob_flush();
#flush();
#ob_end_flush();
}
#ob_start();
in Zend FW when I add description meta tag in loop using helper:
$this->headMeta()->appendName('DESCRIPTION', $des);
i got multi meta tags in my html head.
<meta name="DESCRIPTION" content="des1" />
<meta name="DESCRIPTION" content="des2" />
how can i prevent it and have something like below in my html head:
<meta name="DESCRIPTION" content="des1 des2" />
Insted of
echo $this->headMeta ();
have in your layout
$u = '';
foreach ($this->headMeta ()->getContainer () as $y)
{
if ($y->name == 'description')
{
$u .= $y->content;
}
}
$this->headMeta ()->setName ('description', $u);
echo $this->headMeta ();
Extend you own head view helper callable like this.
$this->headDescription($stringToAttach);
and offer a method to push the values to headMeta
$this->headDescription()->pushToHeadMeta();
// internal call like this
$this->view->headMeta('description', $this->getConcatedDescription());
Other option is to use placeholders.
//in view index.phtml
$this->placeholder('description')
->append($desc1);
//in view other.phtml
$this->placeholder('description')
->append($desc2);
// in layout
echo $this->headMeta('description', $this->placeholder('description'));
You can use this function to get your metas as an array (I put it in /application/plugins/common.php you can put it where you want) :
public function getMetasArray(Zend_View $view){
$metas = array();
foreach ($view->headMeta()->getContainer() as $y)
{
if($y->name!=''){
$metas[$y->name] = $y->content;
}
}
return $metas;
}
and to call it when you want and as you want :
$metas = Application_Plugin_Common::getMetasArray($this);
echo $metas['description'];