PDA

View Full Version : Amendment Needed in Code



bbilal
01-10-2013, 05:40 PM
Hello Friends,

I have a long PHP code which I want to edit but I don't know anything about PHP so I can't do anything with it.

I don't know what to do and how to work with this issue so I came here to get some help from you guys. Most of my problems fixed by one of the members from here and I hope this issue should be solved from here as well :)

I think this is the main file which I want to edit

Let me give you some details about this Code.

It's a function about Facebook Apps what does it do it publish the apps result to the wall

It has 2 options to publish data to wall first is by pressing the Button and second it publish automatically; to publish automatically I have to enable the option from Admin Panel.

The problem is when I enable the automatically option it removes the manually option and publish the result to wall so what I want when I enable the automatically publish option the manual button stay there so if someone want to publish again he/she can do it.

The final issue is when I use the manual option it doesn't publish the result to wall


<?php
if (!isset($hideconfig)) {
include('config.php');
include('functions.php');
}
if (!isset($_GET['id'])) { echo "ID missing"; exit; }
if (!isset($app)) {
$query = mysql_query("SELECT * FROM `apps` WHERE `id` = '".addslashes($_GET['id'])."' LIMIT 1");
if (mysql_affected_rows() > 0) {
$app = mysql_fetch_assoc($query);
}
else
{
include('invalid-app.php');
exit;
}
}
$appdata = unserialize($app['data']);
$facebook = new Facebook(array(
'appId' => $app['app_id'],
'secret' => $app['secret']
));
if (isset($_GET['publish']) || $appdata['publishing'] == "auto") {
$facebook->setFileUploadSupport(true);
}
$cookiepre = "app".$app['id'];
include("fbpages.php");
echo_header();

if (isset($info)) {
if (!isset($info['page']['liked']) || empty($info['page']['liked'])) {
if ($appdata['likeland'] == 1) {
echo get_template("notliked");
echo_footer();
exit;
}
}
}

if (!isset($fb_user)) {
echo get_template("fan-login");
?>
<script>
function loginbtn() {
FB.login(function(response) {
top.location.href = "http://www.facebook.com/pages/facebookfanpage/<?php echo $info['page']['id']; ?>?sk=app_<?php echo $app['app_id']; ?>";
}, {scope: 'publish_stream<?php if ($appdata['userscrape'] == 1) { echo ',email'; } if ($appdata['tagusers'] == 1) { echo ',user_photos'; } ?>'});
}
</script>
<?php
echo_footer();
exit;
}

$user_profile = $facebook->api('/me');

$friends = $facebook->api('/me/friends');
$friends = $friends['data'];

if ($appdata['publishing'] == "auto" || isset($_GET['publish'])) {
echo '<div id="loadingDiv">'.get_template('loading')."</div><br/><br/>\n";
while ( @ob_end_flush() ); // even if there is no nested output buffer
flush();
}

$spinstr = "";

$query = mysql_query("SELECT * FROM `spinners` WHERE `data` LIKE '%".$app['id']."%' LIMIT 1");
if (mysql_affected_rows() > 0) {
while ($row = mysql_fetch_assoc($query)) {
$data = unserialize($row['data']);
if (isset($data[$app['id']])) { $randSpin[$row['id']] = 1; }
}
if (isset($randSpin)) {
$randSpin = array_rand($randSpin,1);
//echo "Random index found: ".$randSpin."<br/>"; print_r($randSpin); exit;
$query = mysql_query("SELECT * FROM `spinners` WHERE `id` = '".$randSpin."' LIMIT 1");
$spin = mysql_fetch_assoc($query);
$query = mysql_query("SELECT * FROM `domains` ORDER BY RAND() LIMIT 1");
$domain = mysql_fetch_assoc($query);
$spinstr = " ".str_replace($base_domain,$domain['domain'],$callbackurl).$spin['id'];
}
}

if ($appdata['publishing'] == "auto") {
include('genimage.php');
// Auto Publishing
if ($appdata['caption'] != "" || $spinstr != "") { $args['message'] = spinmsg($appdata['caption']).$spinstr; }
$args['image'] = '@'.realpath("cache/".$app['id']."_".$fb_user.".jpg");
$data = $facebook->api('/me/photos', 'post', $args);
if ($appdata['tagusers'] == 1 && isset($randKeys_used)) {
foreach ($randKeys_used as $uid => $val) {
$uid = $friends[$uid]['id'];
$tagdata = array("to" => $uid);
try {
//echo "Tagging ".$uid."<br/>";
$facebook->api('/'.$data['id'].'/tags/'.$uid,'post',$tagdata);
} catch (Exception $e) { }
}
}
update_stats($app['id']);
if (isset($appdata['redirect']) && strlen($appdata['redirect']) > strlen("http://")) { echo '<script>top.location.href = "'.$appdata['redirect'].'"</script>'; exit; }
}
else
{
if (isset($_GET['publish'])) {
if ($appdata['caption'] != "" || $spinstr != "") { $args['message'] = spinmsg($appdata['caption']).$spinstr; }
$args['image'] = '@'.realpath("cache/".$app['id']."_".$fb_user.".jpg");
$data = $facebook->api('/me/photos', 'post', $args);
if ($appdata['tagusers'] == 1 && isset($_GET['tags'])) {
$_GET['tags'] = unserialize($_GET['tags']);
foreach ($_GET['tags'] as $uid => $val) {
$uid = $friends[$uid]['id'];
$tagdata = array("to" => $uid);
try {
//echo "Tagging ".$uid."<br/>";
$facebook->api('/'.$data['id'].'/tags/'.$uid,'post',$tagdata);
} catch (Exception $e) { }
}
}
update_stats($app['id']);
if (isset($appdata['redirect']) && strlen($appdata['redirect']) > strlen("http://")) { echo '<script>top.location.href = "'.$appdata['redirect'].'"</script>'; exit; }
}
else
{
include('genimage.php');
echo '<a href="?id='.$app['id'].'&publish=true';
if ($appdata['tagusers'] == 1 && isset($randKeys_used)) { echo '&tags='.serialize($randKeys_used); }
echo '"><img src="images/publish.png" /></a><br/><br/>';
}
}

if ($appdata['publishing'] == "auto" || isset($_GET['publish'])) {
echo '<script>document.getElementById(\'loadingDiv\').style.display = \'none\';</script>';
ob_flush();
flush();
}
?>
<img src="cache/<?php echo $app['id']."_".$fb_user.".jpg"; ?>">
<?php
echo_footer();
?>

bbilal
01-11-2013, 04:51 PM
Sorry for bump anyone?

It's urgent :(

traq
01-12-2013, 01:50 AM
honestly, that code is a mess. I'll take a look when I get a chance, but a quick glance isn't encouraging: there seems to be a lot of interdependent stuff. Changing one thing might easily break others.

If it's urgent, you might consider posting in the paid help forum (http://www.dynamicdrive.com/forums/forumdisplay.php?30-General-Paid-Work-Requests).

bernie1227
01-12-2013, 08:48 AM
The problem is when I enable the automatically option it removes the manually option and publish the result to wall so what I want when I enable the automatically publish option the manual button stay there so if someone want to publish again he/she can do it.


Wait, when the option is automatic, you want the manual option to show up as well? If so, you could just try and add the code for the manual, to the auto section of the if statement. I am doubtful this will work however, but it's worth a try.



<?php
if (!isset($hideconfig)) {
include('config.php');
include('functions.php');
}
if (!isset($_GET['id'])) { echo "ID missing"; exit; }
if (!isset($app)) {
$query = mysql_query("SELECT * FROM `apps` WHERE `id` = '".addslashes($_GET['id'])."' LIMIT 1");
if (mysql_affected_rows() > 0) {
$app = mysql_fetch_assoc($query);
}
else
{
include('invalid-app.php');
exit;
}
}
$appdata = unserialize($app['data']);
$facebook = new Facebook(array(
'appId' => $app['app_id'],
'secret' => $app['secret']
));
if (isset($_GET['publish']) || $appdata['publishing'] == "auto") {
$facebook->setFileUploadSupport(true);
}
$cookiepre = "app".$app['id'];
include("fbpages.php");
echo_header();

if (isset($info)) {
if (!isset($info['page']['liked']) || empty($info['page']['liked'])) {
if ($appdata['likeland'] == 1) {
echo get_template("notliked");
echo_footer();
exit;
}
}
}

if (!isset($fb_user)) {
echo get_template("fan-login");
?>
<script>
function loginbtn() {
FB.login(function(response) {
top.location.href = "http://www.facebook.com/pages/facebookfanpage/<?php echo $info['page']['id']; ?>?sk=app_<?php echo $app['app_id']; ?>";
}, {scope: 'publish_stream<?php if ($appdata['userscrape'] == 1) { echo ',email'; } if ($appdata['tagusers'] == 1) { echo ',user_photos'; } ?>'});
}
</script>
<?php
echo_footer();
exit;
}

$user_profile = $facebook->api('/me');

$friends = $facebook->api('/me/friends');
$friends = $friends['data'];

if ($appdata['publishing'] == "auto" || isset($_GET['publish'])) {
echo '<div id="loadingDiv">'.get_template('loading')."</div><br/><br/>\n";
while ( @ob_end_flush() ); // even if there is no nested output buffer
flush();
}

$spinstr = "";

$query = mysql_query("SELECT * FROM `spinners` WHERE `data` LIKE '%".$app['id']."%' LIMIT 1");
if (mysql_affected_rows() > 0) {
while ($row = mysql_fetch_assoc($query)) {
$data = unserialize($row['data']);
if (isset($data[$app['id']])) { $randSpin[$row['id']] = 1; }
}
if (isset($randSpin)) {
$randSpin = array_rand($randSpin,1);
//echo "Random index found: ".$randSpin."<br/>"; print_r($randSpin); exit;
$query = mysql_query("SELECT * FROM `spinners` WHERE `id` = '".$randSpin."' LIMIT 1");
$spin = mysql_fetch_assoc($query);
$query = mysql_query("SELECT * FROM `domains` ORDER BY RAND() LIMIT 1");
$domain = mysql_fetch_assoc($query);
$spinstr = " ".str_replace($base_domain,$domain['domain'],$callbackurl).$spin['id'];
}
}

if ($appdata['publishing'] == "auto") {
include('genimage.php');
// Auto Publishing
if ($appdata['caption'] != "" || $spinstr != "") { $args['message'] = spinmsg($appdata['caption']).$spinstr; }
$args['image'] = '@'.realpath("cache/".$app['id']."_".$fb_user.".jpg");
$data = $facebook->api('/me/photos', 'post', $args);
if ($appdata['tagusers'] == 1 && isset($randKeys_used)) {
foreach ($randKeys_used as $uid => $val) {
$uid = $friends[$uid]['id'];
$tagdata = array("to" => $uid);
try {
//echo "Tagging ".$uid."<br/>";
$facebook->api('/'.$data['id'].'/tags/'.$uid,'post',$tagdata);
} catch (Exception $e) { }
}
if (isset($_GET['publish'])) {
if ($appdata['caption'] != "" || $spinstr != "") { $args['message'] = spinmsg($appdata['caption']).$spinstr; }
$args['image'] = '@'.realpath("cache/".$app['id']."_".$fb_user.".jpg");
$data = $facebook->api('/me/photos', 'post', $args);
if ($appdata['tagusers'] == 1 && isset($_GET['tags'])) {
$_GET['tags'] = unserialize($_GET['tags']);
foreach ($_GET['tags'] as $uid => $val) {
$uid = $friends[$uid]['id'];
$tagdata = array("to" => $uid);
try {
//echo "Tagging ".$uid."<br/>";
$facebook->api('/'.$data['id'].'/tags/'.$uid,'post',$tagdata);
} catch (Exception $e) { }
}
}
update_stats($app['id']);
if (isset($appdata['redirect']) && strlen($appdata['redirect']) > strlen("http://")) { echo '<script>top.location.href = "'.$appdata['redirect'].'"</script>'; exit; }
}
else
{
include('genimage.php');
echo '<a href="?id='.$app['id'].'&publish=true';
if ($appdata['tagusers'] == 1 && isset($randKeys_used)) { echo '&tags='.serialize($randKeys_used); }
echo '"><img src="images/publish.png" /></a><br/><br/>';
}
}
update_stats($app['id']);
if (isset($appdata['redirect']) && strlen($appdata['redirect']) > strlen("http://")) { echo '<script>top.location.href = "'.$appdata['redirect'].'"</script>'; exit; }
}
else
{
if (isset($_GET['publish'])) {
if ($appdata['caption'] != "" || $spinstr != "") { $args['message'] = spinmsg($appdata['caption']).$spinstr; }
$args['image'] = '@'.realpath("cache/".$app['id']."_".$fb_user.".jpg");
$data = $facebook->api('/me/photos', 'post', $args);
if ($appdata['tagusers'] == 1 && isset($_GET['tags'])) {
$_GET['tags'] = unserialize($_GET['tags']);
foreach ($_GET['tags'] as $uid => $val) {
$uid = $friends[$uid]['id'];
$tagdata = array("to" => $uid);
try {
//echo "Tagging ".$uid."<br/>";
$facebook->api('/'.$data['id'].'/tags/'.$uid,'post',$tagdata);
} catch (Exception $e) { }
}
}
update_stats($app['id']);
if (isset($appdata['redirect']) && strlen($appdata['redirect']) > strlen("http://")) { echo '<script>top.location.href = "'.$appdata['redirect'].'"</script>'; exit; }
}
else
{
include('genimage.php');
echo '<a href="?id='.$app['id'].'&publish=true';
if ($appdata['tagusers'] == 1 && isset($randKeys_used)) { echo '&tags='.serialize($randKeys_used); }
echo '"><img src="images/publish.png" /></a><br/><br/>';
}
}

if ($appdata['publishing'] == "auto" || isset($_GET['publish'])) {
echo '<script>document.getElementById(\'loadingDiv\').style.display = \'none\';</script>';
ob_flush();
flush();
}
?>
<img src="cache/<?php echo $app['id']."_".$fb_user.".jpg"; ?>">
<?php
echo_footer();
?>


As to the fact that the manual isn't posting, does it do anything? I don't see why it shouldn't post, it appears to be using exactly the ame code as the auto in that regard.

bbilal
01-26-2013, 06:16 PM
Hello

First of all thank you for giving a try.

I paste the code but nothing happening. :(

Can we do some instant messaging if you have time?

traq
01-27-2013, 06:51 AM
Can we do some instant messaging if you have time?
bbilal,

Part of the benefit of the forums here on Dynamic Drive is that they are public:

...Every DD member can read about your issue, and how you approached and (hopefully!) solved it. This helps everyone, even years later.

...Conversely, any of those members also have the opportunity to help you, should they have something to contribute.

While moving a conversation to IM/PM can sometimes be appropriate, it also defeats both of the above goals. (Also consider that, unless someone publicly advertises their IM contact info [and AFAIK, Bernie does not], it may not be welcome to solicit it - this is private information.) In general, it is better to keep the conversation in the public eye. To get the most from this, you need to be involved in solving your own issue.

What do you want to accomplish? What have you already tried? What problems did you encounter?
Be as specific as possible. "I paste the code but nothing happening" is not only vague and unhelpful, it's probably not accurate, either. If literally nothing happened, my response would be to make sure your server is running - but I doubt that's really what the problem is. It didn't do what you want - fine - what did happen? What was the result of running that code, and how did it not meet your goals?

Of course, if "nothing" really did happen, please confirm this.
Check that you have error reporting enabled, and share any error messages you receive.



To reiterate,

If you are interested in learning how to solve your problem, and getting help doing so, then DD forums is the right place.
Participate!

If you only want someone to fix it for you, you should really be looking for someone to hire instead.
This is the very reason we have a paid help forum (http://www.dynamicdrive.com/forums/forumdisplay.php?30-General-Paid-Work-Requests) here on DD.



Thanks for your attention,