News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Help with a code?

Started by ballin, August 13, 2013, 07:35:23 AM

Previous topic - Next topic

ballin

I'm trying to make a postbit background mod which allows the admin to specify a certain image to be the postbit background according to each usergroup. I've made everything work, however when it comes to loading the image, it's not showing. I think it might be perhaps with the code being used to load the image which is:

<div id="postbitbg" style="background:"' . $message['member']['postbitbg_image'] . ' background-size: 100% 100%;">

Can anyone maybe lend me a hand?

emanuele

It's rather difficult to guess what you are doing and what is wrong with your code looking at just one line of (mostly) html...


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

ballin

Quote from: emanuele on August 13, 2013, 09:21:58 AM
It's rather difficult to guess what you are doing and what is wrong with your code looking at just one line of (mostly) html...

Alright here's more of the code from my package:

<file name="$sourcedir/Load.php">
<operation>
<search position="before"><![CDATA[ SELECT mem.*, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type]]></search>
<add><![CDATA[, memg.postbitbg]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ LEFT JOIN {db_prefix}attachments AS a ON (a.id_member = {int:id_member})]]></search>
<add><![CDATA[ LEFT JOIN {db_prefix}membergroups AS memg ON (memg.id_group = mem.id_group)]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)]]></search>
<add><![CDATA[ LEFT JOIN {db_prefix}membergroups AS memg ON (memg.id_group = mem.id_post_group)]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ 'permissions' => array(),
]]></search>
<add><![CDATA[ 'postbitbg_image' => !empty($user_settings['id_group']) && !empty($user_settings['postbitbg']) ? $user_settings['postbitbg'] : (!empty($user_settings['id_post_group']) && !empty($user_settings['postbitbg']) ?  $user_settings['postbitbg'] : ''),
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.is_activated, mem.warning,]]></search>
<add><![CDATA[ memg.postbitbg,]]></add>
</operation>
<operation>
<search position="before"><![CDATA[pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.ignore_boards, mem.warning,]]></search>
<add><![CDATA[ memg.postbitbg,]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ SELECT group_name AS member_group, online_color AS member_group_color, stars]]></search>
<add><![CDATA[, postbitbg]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ if (!empty($row['stars']))
$user_profile[$id]['stars'] = $row['stars'];]]></search>
<add><![CDATA[ if(!empty($row['postbitbg']))
$user_profile[$id]['postbitbg'] = $row['postbitbg'];]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ 'group_color' => $profile['member_group_color'],
]]></search>
<add><![CDATA[ 'postbitbg_image' => !empty($profile['id_group']) && !empty($profile['postbitbg']) ? '<img src="' . $settings['images_url'] . '/postbit_bg/' . $profile['postbitbg'] . '" alt="" />' : (!empty($profile['id_post_group']) && !empty($profile['postbitbg']) ? '<img src="' . $settings['images_url'] . '/postbit_bg/' . $profile['postbitbg'] . '" alt="" />' : ''),
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[ $context['user']['name'] = $user_info['name'];]]></search>
<add><![CDATA[ $context['user']['postbitbg_image'] = $user_info['postbitbg_image'];]]></add>
</operation>
</file>


I'm sure the reason it's not working is because of a problem in the Load.php file. So, i've pasted all the code from there onto here.

emanuele

mmm...okay, well, maybe the code you posted the first time was a bit wrong anyway:
http://www.w3schools.com/cssref/css3_pr_background.asp

<div id="postbitbg" style="background: url("' . $message['member']['postbitbg_image'] . '); background-size: 100% 100%;">


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

ballin

Quote from: emanuele on August 13, 2013, 09:55:14 AM
mmm...okay, well, maybe the code you posted the first time was a bit wrong anyway:
http://www.w3schools.com/cssref/css3_pr_background.asp

<div id="postbitbg" style="background: url("' . $message['member']['postbitbg_image'] . '); background-size: 100% 100%;">

I can't believe i missed that, but it still didn't work :/ Any other ideas? Is the PHP syntax correct for the Load.php file? I can't think of a reason for why it's not displaying the background image.

MrPhil

So what is the final HTML and CSS that you end up with on your browser? Not the PHP code.

emanuele

Debug it...
Put echo or print_r around and check where and when your variable is lost (or not set).


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

ballin

Quote from: MrPhil on August 13, 2013, 12:03:52 PM
So what is the final HTML and CSS that you end up with on your browser? Not the PHP code.

I don't exactly understand what you mean by that. Do you mean what I get as a result from my code? Well, I get a big empty space of where the image is at but i dont get the image to load itself.

http://smfdigital.yzi.me/forums/index.php?topic=2.msg3#new

@emanuele i don't know what you mean exactly by debug it.

EDIT: I also know that the image is loading properly is because in the admin CP in the membergroups area the image i'm testing with shows up:

http://i.imgur.com/vj5GjZj.png

but of course does not load in the post itself which is the whole objective.

MrPhil

I see a number of problems when I display the page HTML:
<div class="post_wrapper">
<div class="poster" style="background: url("" alt="*">
<h4>

1. You've got nothing showing up for the URL
2. You can't use " quotation marks inside a style attribute which itself uses " (change the url() to use ')
3. Your url( property is missing the closing );
4. Your style attribute is missing the closing "
5. You can't use alt= with a background image (remove it)

That ought to keep you busy for a while.

ballin

Quote from: MrPhil on August 13, 2013, 12:45:47 PM
I see a number of problems when I display the page HTML:
<div class="post_wrapper">
<div class="poster" style="background: url("" alt="*">
<h4>

1. You've got nothing showing up for the URL
2. You can't use " quotation marks inside a style attribute which itself uses " (change the url() to use ')
3. Your url( property is missing the closing );
4. Your style attribute is missing the closing "
5. You can't use alt= with a background image (remove it)

That ought to keep you busy for a while.

I did that stuff just now, and this is how the code looks

<div class="poster" style="background: url("', $message['member']['postbitbg_image'], '");">

But it still does not display the image.

MrPhil

url(\'', and '\'); is what you want. You have to end up with url('name of image file');. Since the echo statement in PHP is presumably already using ' to enclose the string, to output a ' it has to be escaped: \'. Then you can tackle why you're not seeing anything in the url(). Print out the $message['member']['postbitbg_image'] string and see if it contains anything.

ballin

Quote from: MrPhil on August 13, 2013, 12:57:28 PM
url(\'', and '\'); is what you want. You have to end up with url('name of image file');. Since the echo statement in PHP is presumably already using ' to enclose the string, to output a ' it has to be escaped: \'. Then you can tackle why you're not seeing anything in the url(). Print out the $message['member']['postbitbg_image'] string and see if it contains anything.

Still isn't displaying the image I have set to be output. The view source is correct now, the formatting for the div is correct; however, the link for the image that should be displayed inside the url() tag doesn't display. Is there a problem with string code?

MrPhil

You are STILL not listening. You can NOT have url("name") because the style= attribute already uses " to wrap. You MUST change to url('name'). Then you can investigate why there is nothing in there. Have you tried printing out the name to see if it's there? If it's an empty string, you'll have to work your way back to where it should have been set, and see what happened.

emanuele

Quote from: ballin on August 13, 2013, 12:37:40 PM
@emanuele i don't know what you mean exactly by debug it.
<div class="poster" style="background: url('');">
this is what you are getting at the moment.
This means the value of $message['member']['postbitbg_image'] is not set or set empty "at some point".
You have to find why it is not set. To find it you have to "debug" your code. The simplest way if to put things like:
echo $message['member']['postbitbg_image'];
or
print_r($message['member']['postbitbg_image']);
and alike in your code in order to find where the variable is not properly set.

Guessing:
<operation>
<search position="before"><![CDATA[ LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)]]></search>
<add><![CDATA[ LEFT JOIN {db_prefix}membergroups AS memg ON (memg.id_group = mem.id_post_group)]]></add>
</operation>

You are LEFT JOIN'ing the table on the post group, but changing the main group (e.g. administrator).

But again, seeing only with pieces of code is difficult to figure out, that may or may not work:
<operation>
<search position="before"><![CDATA[ LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)]]></search>
<add><![CDATA[ LEFT JOIN {db_prefix}membergroups AS memg ON (memg.id_group = mem.id_group)]]></add>
</operation>

*And* you are adding this LEFT JOIN, but apparently you are not adding anything to the SELECT, so it becomes effectively useless.


That said: IMHO you are overly-complicating this.
You could very well use the group ID to name the image and use that instead of adding yet another table, with yet another LEFT JOIN, etc.


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

ballin

Thanks guys for the help; yes I had over-complicated things, but with the help of a good friend I was able to get it fixed :)

I really appreciate the effort by everyone who tried to help. Marking this as solved.

Advertisement: