Previously my this code worked well but now it do nothing
I want to show an dialog then the user will be able to select some friends and invite them to use this application.
Now this code shows blank page.
<?php
include_once "fbmain.php";
if (isset($_REQUEST['ids'])){
echo "Invitation Sent";
$string = "<script type='text/javascript'>top.location.href='{$fbconfig['appBaseUrl']}';</script>";
echo $string;
}
else {
?>
<fb:serverFbml style="width: 500px;">
<script type="text/fbml">
<fb:fbml>
<fb:request-form
action="<?=$fbconfig['baseUrl']?>/invite.php"
target="_top"
method="POST"
invite="true"
type= <?php echo $fbconfig['appname']; ?>
content="I tried this and love this, what about you ? <fb:req-choice url='<?php echo $fbconfig['appBaseUrl']; ?>' label='Accept' />"
>
<fb:multi-friend-selector
showborder="false"
actiontext=<?php echo $fbconfig['appname' ]; ?>>
</fb:request-form>
</fb:fbml>
</script>
Facebook has deprecated this legacy FBML plugin. While it may still work for a while, you will want to upgrade to their new Requests Dialog, which will be easier to get support for. Also, I've noticed some other deprecated features stop working lately (yet they haven't officially been killed), so this may be the case. But check the javascript console for any errors and post them.
Now to invite friends the only way is to use FB JS
the code
function showInvite()
{
<?php
if (strlen($fbconfig['appname' ])>50)
{
$title = substr($fbconfig['appname' ],0,45);
$title = $title . ' ...';
}
else
$title = $fbconfig['appname' ];
if (strlen($fbconfig['appBaseUrl'])>200)
{
$message = substr($fbconfig['appBaseUrl'],0,200);
$message = 'I just love this App, now it\'s your turn to try it # '.$message;
}
else
$message ='I just love this App, now it"s your turn to try it # '.$fbconfig['appBaseUrl'];
?>
var r = FB.ui({
method : 'apprequests',
message: '<?php echo $message; ?>',
title: '<?php echo $title; ?>',
});
}
Try out code on this page, it would certainly help
https://developers.facebook.com/docs/reference/dialogs/requests/
Seems like this is what you are looking for
<script>
FB.init({
appId : 'APPID',
});
FB.ui({method: 'apprequests', message: 'My Great Request'});
</script>
Have you tried checking the pages source/html? Maybe there are some errors reporting.
You can also in PHP call error_reporting(E_ALL); which will enable all errors to be printed instead of being hidden.
Also, perhaps you could check your browsers JavaScript logs for errors.
In Internet Explorer 9 press F12
In Firefox download firebug.
In Chrome press CTRL + SHIFT + J
function showInvite() {
<?php
if (strlen($fbconfig['appname']) > 50) {
$title = substr($fbconfig['appname'], 0, 45);
$title = $title . ' ...';
} else $title = $fbconfig['appname'];
if (strlen($fbconfig['appBaseUrl']) > 200) {
$message = substr($fbconfig['appBaseUrl'], 0, 200);
$message = 'I just love this App, now it\'s your turn to try it # ' . $message;
} else $message = 'I just love this App, now it"s your turn to try it # ' . $fbconfig['appBaseUrl']; ?>
var r = FB.ui({
method: 'apprequests',
message: '<?php echo $message; ?>',
title: '<?php echo $title; ?>',
});
}
Related
I am tryaing to to make this echo work, but i cant get the grip of it
echo '<script>
function replaceWithImgLinks(txt) {
var linkRegex = /([-a-zA-Z0-9#:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9#:%_\+.~#?&//=]*)?(?:jpg|jpeg|gif|png))/gi;
return txt.replace(linkRegex, "<img class="sml" src="$1" /><br />");
}
var newHTML = replaceWithImgLinks($(".ms").html());
$(".ms").html(newHTML);';
echo "</script>";
What am i doing wrong? i think i got something wrong with my " ' .
There was a couple of issues. I started by just running it in JavaScript until I got it to work, then moved it into PHP (for the sake of sanity).
<?php
print '
<script>
function replaceWithImgLinks(txt) {
var linkRegex = /([-a-zA-Z0-9#:%_\+.~#?&\/\/=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9#:%_\+.~#?&\/\/=]*)?(?:jpg|jpeg|gif|png))/gi;
return txt.replace(linkRegex, "<img class=\"sml\" src=\"$1\" /><br />");
}
var newHTML = replaceWithImgLinks($(".ms").html());
$(".ms").html(newHTML);
</script>';
?>
Shouldn't the regex be something like:
(^|\b)((https?:)?\/\/[^\s]*?\.(jpe?g|png|gif))(\b|$)
Debuggex Demo
You shouldn't be echo'ing scripts, especially scripts in script tags. I would seriously look into just using your back end to fetch, then use an asynchronous technology that fetches data parsed JSON. That way you can call your scripts normally.
I'm trying to update a DIV with the ongoing output from an rsync command. The idea being I can see how the download is progressing.
This is the code I've got, but I'm getting errors relating 'Uncaught SyntaxError: Unexpected token ILLEGAL'
<?php
$down = popen('rsyncd -Pav http://ipv4.download.thinkbroadband.com/1GB.zip 1GB.zip', 'r');
while($progress = fgets($down, 124)) {
ob_flush();flush();
?>
<script type="text/javascript">
$(document).ready(function() {
var update = "<?php echo $progress; ?>";
$("#status").html(update);
});
</script>
<?php
ob_flush();
ob_flush();flush();
}
pclose($down);
}
?>
<div id="status"></div>
In the console I can see that it relates to :
var update = " 33390592 46% 4.62MB/s 0:00:08
34701312 48% 4.63MB/s 0:00:07
35979264 50% 4.63MB/s 0:00:07
";
How can I get each line of update and show it in a DIV without getting errors ?
Thanks
UPDATE
I'm now using this. The php echo for $update shows the output live in the web page, but the DIV is not updated until the page completes and then I only get the last line of output.
Why does the php echo work, but the jquery update to the div now work as expected ?
<?php
$down = popen('rsyncd -Pav http://ipv4.download.thinkbroadband.com/1GB.zip 1GB.zip', 'r');
$order = array("\r\n", "\n", "\r");
while($progress = fgets($down, 32)) {
ob_flush();flush();
$update = str_replace($order,'<br />', $progress);
echo $update; // <-- this outputs fine.
?>
<script type="text/javascript">
$(document).ready(function() {
var update = "<?php echo $update; ?>";
$("#status").html(update);
});
</script>
<?php
ob_flush();flush();
}
pclose($down);
}
?>
Is this due to the jquery not running until the page is fully loaded, so the div is only updated with the last entry of $update ?
If so is there any way to have the jquery run as the page is loading so the DIV is updated ?
Thanks :)
Thanks
UPDATE
<script type="text/javascript">
$(document).ready(function() {
$.ajaxSetup({ cache: false });
$("#test").click(function () { $("#log").load("go.php"); });
});
</script>
Just tried the above, it works and calls go.php and I get the output but only when go.php has finished the rsync download. any way to show the ongoing output whilst the download happens ?
use str_replace() php function
<?php
$order = array("\r\n", "\n", "\r");
$replace = '<br />';
?>
<script type="text/javascript">
$(document).ready(function() {
var update = "<?php echo str_replace($order, $replace, $progress); ?>";
$("#status").html(update);
});
</script>
I have my PHP code on controller and I have one popup and after
finishing the functionality on popup I wan to close my popup and wan
to redirect to respective page. How can I achieve this using PHP. I
tried using following code but its not working
$strRedirectUrl = $this->m_strSecureBaseName . 'Apartments/module/application_application_list/action/view_application_list/'; echo '<script type="text/javascript">
window.opener.location.replace(' . $strRedirectUrl . ');
window.close; <script>';
Please help me.
thanks
Call this JS in popup page:
window.opener.location.href = "http://some/new/location";
window.close();
PHP Code
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
Demo :
Page 1
file : page_1.php
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// Popup window code
function newPopup(url) {
popupWindow = window.open(
url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
</head>
<body>
Open a popup window
</body>
</html>
Page 2:
file : page_2.php
<?php
$strRedirectUrl = "page_1.php";
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
?>
New Edited Code
PHP Code
if (success condtion) {
$strRedirectUrl = "page_1.php";
echo"<script language='javascript'>";
echo("window.opener.location.href = '" . $strRedirectUrl . "';");
echo("window.close();");
echo "</script>";
}
else
{
echo json_encode(array(
'status' => 'error',
'message'=> 'error message'
));
}
Jquery Code
$.ajax({
type: "post",
url: "postride.php",
dataType:"json",
success: function (response) {
if(response.status === "error") {
// do something with response.message or whatever other data on error
} else {
return false;
}
}
});
I just recently started learning jQuery. To help me learn, I started redesigning this website. The problems I have at the moment are:
Once a thumb image is clicked and the main post loads; after closing the main post and when hovering over the thumbs again, the title and post information no longer fade in above and beside the thumbs.
When hovering over a thumb image for the first time, you should notice that it hides everything (including itself) and then shows itself again, this gives the illusion that it flickers. How can I stop this?
Here is the .js file containing the jQuery code:
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(".post").stop().fadeTo(0,0.2);
$(this).fadeTo(300,1);
},
function () {
$(this).parent().find(".post_title, .post_info").stop(true).hide();
$(this).parent().find(".link-to-post").stop().hide();
$(".post").stop().fadeTo(300,1);
});
$(".cover-img").click(function(){
$("#main-post").fadeIn(1000);
$.post("inc/fullpost.php", {postid: $(this).data('postid')},
function(output){
$("#gotpostid").html(output).show();
}).fail(function(x,y,z){
$("#gotpostid").html(x + "<br />" + y + "<br />" + z)
});
$('.post').fadeTo(0,0);
});
$('input[name=close]').click(function(){
$(this).closest('#main-post').hide();
Each thumbnail is within its own class:
// Retrieve all active posts order by lastest first
$resultarray = retrieve_active_posts();
echo '<div id="content-wrap">';
foreach($resultarray AS $value){
$filename = substr($value['img_file_name'],9);
$cat_id = $value['cat_id'];
echo '<article class="post">';
echo '<div class="post_title">' . stripslashes(stripslashes($value['post_title'])) . '</div>';
echo '<div class="post_info">' .
'Category: ' . $cat_name = get_cat_name($cat_id) .'<br />'.
'Year: ' . $value['post_year'] .'<br />'.
stripslashes($value['post_desc']) .'<br />'.
'</div>';
echo '<div class="link-to-post">Click to view</div>';
echo '<img class="post-thumb" src="img/thumb_/'.$filename.'" alt="MJbox Michael Jackson memorabilia thumbnail" data-postid="'.$value['post_id'].'"/>';
echo '<img class="cover-img" src="img/post-bg-1.png" alt="test" data-postid="'.$value['post_id'].'"/>';
echo '</article>';
}
echo '</div>';
I'll have another go :-)
I've looked on the Google Developer Tools and it looks like this is the problem...
$('.post').fadeTo(0,0);
It is leaving the opacity attribute as 0. When I override this in developer tools, the popups show again. Try changing it to:
$('.post').fadeOut;
or even
$('.post').hide();
Should do the trick.
I'm pretty sure I have the answer to the other problem:
You have two animations. You are fading all of the .post items out and then fading $(this) back in again. You need this solution:
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(this).siblings.().stop().fadeTo(0,0.2);
},
This will fade out only the other ones so you don't have to fade $(this) back in again!
Fingers crossed!
I have tested this. It fixes both problems and also stops the browser going to the top of the page when you click one of the thumbs.
Here is the complete jQuery code
$(document).ready(function(){
$(".fancybox").fancybox();
$("#login").click(function(){
$("#searchform").hide();
$("#loginform").fadeIn('3000','swing');
});
$("#search").click(function(){
$("#loginform").hide();
$("#searchform").fadeIn('3000','swing');
});
$(".post").hover(
function () {
$(this).children(".post_title, .post_info").stop(true).fadeIn();
$(this).children(".link-to-post").stop().show();
$(this).siblings().stop().fadeTo(0,0.2);
},
function () {
$(this).parent().find(".post_title, .post_info").stop(true).hide();
$(this).parent().find(".link-to-post").stop().hide();
$(".post").stop().fadeTo(300,1);
});
$(".cover-img").click(function(e){
e.preventDefault();
$("#main-post").fadeIn(1000);
$.post("inc/fullpost.php", {postid: $(this).data('postid')},
function(output){
$("#gotpostid").html(output).show();
}).fail(function(x,y,z){
$("#gotpostid").html(x + "<br />" + y + "<br />" + z)
});
$('.post').fadeOut();
});
$('input[name=close]').click(function(){
$(this).closest('#main-post').hide();
});
});
Just cut and paste this in place of your code.
Chris
This is for your first problem.
Try doing ...
$(".cover-img").click(function(e){
e.preventDefault();
.... rest of your code
This prevents the default behaviour of the browser to follow the link. This may solve your first problem but should be in there anyway with click events.
I seem to have a syntax error and can't see it myself, could someone run over it for me please?
Thanks.
<script>
var acurl_<?php echo $request_data['friendship_id']; ?> = "sn-include/create_bond_accept.php?friendship_id=<?php echo $request_data['friendship_id']; ?>&friend_id=<?php echo $fromuser['id']; ?>";
</script>
Because you got some answers that intended to show you how to improve your code, but actually don't do so (IMO), here is my attempt:
<?php
$acurl = array();
$acurl[$request_data['friendship_id']] = sprintf('sn-include/create_bond_accept.php?friendship_id=%s&friend_id=%s', $request_data['friendship_id'], $fromuser['id']);
?>
<script>
var acurl = <?php echo json_encode($acurl); ?>
</script>
I would not create dynamic variable names. This code would create a JS object, where the properties are the friendship IDs, something like:
{
'42': 'sn-include/create_bond_accept...'
}
You can access these URLs more easily from JavaScript than if you have dynamic variable names.
David, on the bright side, you don't have a syntax error.
If you're developing PHP, I would recommend two things:
Get a better IDE. Dreamweaver is TERRIBLE for working with PHP. I recommend NetBeans (it's awesome and free).
Start breaking up your code into chunks. The big ball of html and PHP is hard to debug.
Check this out:
<?php
// prepare output
$segment = '?friendship_id=' . $request_data['friendship_id'];
$segment .= '&friend_id=' . $fromuser['id'] . '";' . "\n";
$acurl = 'var acurl_' . $request_data['friendship_id'];
$acurl .= ' = "sn-include/create_bond_accept.php';
$acurl .= $segment;
$dnurl = 'var dnurl_' . $request_data['friendship_id'];
$dnurl .= ' = "sn-include/create_bond_deny.php';
$dnurl .= $segment;
?>
<script type="text/javascript">
<?php
echo $acurl;
echo $dnurl;
?>
</script>
Use here doc instead:
<?php
echo <<<JS
<script>
var acurl_{$request_data['friendship_id']} = "sn-include/create_bond_accept.php?friendship_id={$request_data['friendship_id']}&friend_id={$fromuser['id']}";
</script>
<script>
var dnurl_{$request_data['friendship_id']} = "sn-include/create_bond_deny.php?friendship_id={$request_data['friendship_id']}&friend_id={$fromuser['id']}";
</script>
JS;
?>
See http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc