Running SMF 1.1.11 TP 0.9.8 and using images in the polls.
We currently put the image code into the poll option texboxes, so this displays the image next to the selection box. Like this,
http://cameracraniums.com/forum/index.php?topic=1436.0
I've installed the SMF poll mod and can now pull this poll complete with images to my front page. using a php block with this code in it,
ssi_showPoll(X); - For a single fixed poll where X is a topic number.
My question. By adding some code to the block is there a way to resize and add some sort of layout to these images? like a 4x4 image square.
Any help would be appreciated.
try using photoshop to resize the pcitures to 4x4 :D
Matt to be honest I would do that if the content was kind of permanent.
The images linked to the forum polls are the intermediate images from my coppermine gallery. The weekly comp polls are set up by my members so they need to just link to the images for the current weeks entries.
TP 0.9.8
I think a updated version of TP has a fix for that. Not sure.
Quote from: mattb on July 07, 2010, 12:51:54 AM
TP 0.9.8
I think a updated version of TP has a fix for that. Not sure.
Matt, it's not a fix that's needed it all works as designed.
I just wondered if the block could be modded slightly for our needs. We run a weekly comp, and rather than have to go to the forums to vote we would like to do this directly from our home page. Obviously the images are just too big and in one vertical line to have on the front page as is.
Anyone have any ideas please. :'(
When you call the ssi_showPoll function, all the processing has already been done - so it's like the horse has already bolted...
I would look at the function in detail and see if it will return an array of information rather than directly formating the output itself.
If you can return an array with that function then you should be able to make you own layout.
I don't know this mod, perhaps the mod author could help.
Quote from: Freddy on July 07, 2010, 08:27:56 PM
I don't know this mod, perhaps the mod author could help.
Thanks Freddy, but the mod author hasn't been about since February this year. This is the mod though if anyone's interested, http://custom.simplemachines.org/mods/index.php?mod=765
I also posted on the support thread for the mod, but haven't had any replies. :'(
So what you're saying is it's the code in the mod I installed that needs altering, rather than the block code? Methinks this will be beyond my scope without help. :-[
Have you posted on the smf site? showing the layout of your code. And what you would like to alter etc..
Quote from: lurkalot on July 07, 2010, 08:51:22 PM
I also posted on the support thread for the mod, but haven't had any replies. :'(
As said above Matt. ;)
did you show your code? Because there's tons of people that help out with code there as i had help before.
They wrote the code, it's a mod. :D
What version of this poll mod are you using ?
That ssi_showPoll(X); function already exists in SSI.php and it is possible to return the results as an array I think, so then you could process that how you like.
I am still not sure what you actually want, can you do a mock up in Photoshop or something ?
Thanks for the reply Freddy.
I'm using version 1.2 of this mod http://custom.simplemachines.org/mods/index.php?mod=765
What I'm after is something like my latest images block that's on my home page. http://cameracraniums.com/ Only with the poll in it. So the images would have shrink to fit the layout. Only sometimes the amount of images will vary depending on entries, so I guess there will have be a limit.
Or maybe some kind of slider.
Remember I'm running SMF 1.1.11 and TP 0.9.8 on my live site at the moment. ;) Wonder why there's a mod if as you say "That ssi_showPoll(X); function already exists" ???
I just registered at your site so I can get a feel for it - username 'Freddy'
Some of the graphics (images worked fine) didn't show up on that example link you gave in your first post btw...might be only for guests...not sure yet...I think it's the poll graphics.
QuoteWonder why there's a mod if as you say "That ssi_showPoll(X); function already exists"
It's possible they customise the function, I couldn't really tell, I am not that clued up on the way the mods change things.
Quote from: Freddy on July 08, 2010, 05:09:39 PM
I just registered at your site so I can get a feel for it - username 'Freddy'
Some of the graphics (images worked fine) didn't show up on that example link you gave in your first post btw...might be only for guests...not sure yet...I think it's the poll graphics.
Freddy I do apologise, one of my mods deleted your account before you even got on there. I'll have words :knuppel2: I know we've been getting a lot of spammers lately but that's a bit OTT.
You mean the latest gallery images? ???
lol and I am always blocking spammers too - that's just my luck ;)
I will register again...using Freddy or if it doesn't accept that Freddy888
For missing graphics I mean here :
http://cameracraniums.com/forum/index.php?topic=1436.0
Just found there is also a ssi_recentPoll() function too.
Do you normally change the poll manually ?
Quote from: Freddy on July 08, 2010, 06:49:27 PM
lol and I am always blocking spammers too - that's just my luck ;)
I will register again...using Freddy or if it doesn't accept that Freddy888
For missing graphics I mean here :
http://cameracraniums.com/forum/index.php?topic=1436.0
ahah, I haven't copied them into all the themes yet. :-[ I've switched you to a theme with them in. ;)
Quote from: Freddy on July 08, 2010, 07:19:55 PM
Just found there is also a ssi_recentPoll() function too.
Do you normally change the poll manually ?
Yes I will be, so only the current comp poll will be on the front page. ;)
Ah yes good point re comp polls only..
Hmm, well what kind of size do you want the images to be ? Like the gallery you mentioned...how big do you have those ?
Do you want them to be able to vote from the front page - considering they will not be seeing them full size ? It's also easier for me if you only show the smaller images as an enticer and a bar showing votes so far, without the option to vote.
Each image could also be a simple link to the topic.
What I can do is have the browser resize the images on the fly. Which means it will still load the main image but simply render it to a smaller size. That's really the only way to do it as the polls don't generate thumbnails.
Thumbs on in the recent images block are set at max 100 pixels. ;)
Quote from: Freddy on July 08, 2010, 08:06:32 PM
Do you want them to be able to vote from the front page - considering they will not be seeing them full size ? It's also easier for me if you only show the smaller images as an enticer and a bar showing votes so far, without the option to vote.
Each image could also be a simple link to the topic.
I think the mod does give the function of voting from front page, but if you don't think it's possible, then don't worry. O0
It's possible, but I figure people are not going to make a choice without seeing the full size image. So it would save me having to mess around with forms and submits. ;)
At least Freddy's behaving himself, not once have I seen him in the arcade, lol... :D
Freddy, if you want to see exactly what the poll does now on the front page, I'll grant you admin rights, then you will be able to see it. O0
It's okay I have it set up on my test forum at the moment, so I can see what it's doing. Thanks anyway :)
Quote from: Freddy on July 08, 2010, 08:26:56 PM
It's okay I have it set up on my test forum at the moment, so I can see what it's doing. Thanks anyway :)
Cool. O0
Can you try this out and see if it works alright :
// Set up the topic.
$pollResults = ssi_showPoll(11,'array');
// Images per row.
$imagesPerRow = 4;
// Just a counter..
$imageCount = 0;
$patternImg = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
echo '
<table style="width: 100%">
<tr>';
foreach ($pollResults['options'] as $pollItem)
{
preg_match($patternImg, $pollItem['option'], $image);
$imageCount++;
if ($imageCount > $imagesPerRow)
{
echo '
</tr>
<tr>';
$imageCount = 0;
}
echo '
<td style="width: 25%; text-align: center; padding: 1px">
<img ' , $image[0] , ' width="100" />
<br />
Member : ' , strip_tags($pollItem['option']) , '
<br />
Votes : ' , $pollItem['votes'] , ' (' , $pollItem['percent'] , '%)
<br />
' , $pollItem['bar'] , '
</td>';
}
do
{
echo '
<td style="width: 25%">
</td>';
$imageCount++;
} while ($imageCount +1 < $imagesPerRow);
echo '
</tr>
</table>';
This is what it looks like here...
Freddy thanks,
I couldn't get it to work to start with, then I realised that IE8 was messing up the code when I use it to paste the code in. Switched to firefox and it works fine. Been having this problem for a few weeks. Tried it with a couple of old polls, and it displays nicely. O0
Looks like you can only view the poll, but none of the images are clickable to the poll post for voting. I'm assuming this was by design? Or is this purely because the voting is closed?
No they are not click-able because it was late last night and I forgot ! Sorry about that ::)
I'll will make it so when you click on any of the images it will take you to the poll page so they can vote.
I've heard a few people mention now that IE8 messes up the code, strange...
Here you go. I made the poll topic a variable now so it gets used for the links, so you just need to set $pollTopic instead.
I also added some padding to the bottom of each cell too so they space out a bit more.
Edit: Code removed - Hang on a bit, there's a bug with the table. Back later...
Sorted...
/////////////////////
// Set up the topic where the poll is.
$pollTopic = 11;
// Images per row.
$imagesPerRow = 4;
/////////////////////
$pollResults = ssi_showPoll($pollTopic,'array');
// Just a counter..
$imageCount = 0;
global $scripturl;
$patternImg = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
echo '
<table style="width: 100%">
<tr>';
foreach ($pollResults['options'] as $pollItem)
{
preg_match($patternImg, $pollItem['option'], $image);
$imageCount++;
if ($imageCount > $imagesPerRow)
{
echo '
</tr>
<tr>';
$imageCount = 1;
}
echo '
<td style="width: 25%; text-align: center; padding: 1px 1px 10px 1px;">
<a href="' , $scripturl , '?topic=' , $pollTopic , '">
<img ' , $image[0] , ' alt="Go Vote !" title="Go Vote !" border="0" width="100" />
</a>
<br />
Member : ' , strip_tags($pollItem['option']) , '
<br />
Votes : ' , $pollItem['votes'] , ' (' , $pollItem['percent'] , '%)
<br />
' , $pollItem['bar'] , '
</td>';
}
while ($imageCount < $imagesPerRow)
{
echo '
<td style="width: 25%">
</td>';
$imageCount++;
}
echo '
</tr>
</table>';
Quote from: Freddy on July 09, 2010, 12:43:40 PM
Here you go. I made the poll topic a variable now so it gets used for the links, so you just need to set $pollTopic instead.
I also added some padding to the bottom of each cell too so they space out a bit more.
Freddy, sorry for the delay getting back to you, been at work. :(
Hey that's great and the new code works nicely. 8) O0 http://cameracraniums.com/
Will I be able to see the votes before I vote, or only after?
I'm not sure to be honest, try it out... lemme know...
Quote from: Freddy on July 09, 2010, 06:38:58 PM
I'm not sure to be honest, try it out... lemme know...
Thanks Freddy. I'll set up a test poll and see. O0
Edit: OK set up a test poll. it looks like the front page block is bypassing the following settings for the poll,
Show the poll's results to anyone.
Only show the results after someone has voted.
Only show the results after the poll has expired.
I'll wait until someone has voted to be sure. ;)
Quote from: Freddy on July 09, 2010, 06:38:58 PM
I'm not sure to be honest, try it out... lemme know...
OK the guys have a poll running now. You can see the votes before voting yourself. :'(
Is there any way around this Freddy?
Well I can mimic what SSI normally does... try this :
/////////////////////
// Set up the topic where the poll is.
$pollTopic = 11;
// Images per row.
$imagesPerRow = 4;
/////////////////////
$pollResults = ssi_showPoll($pollTopic,'array');
// Just a counter..
$imageCount = 0;
global $scripturl;
$patternImg = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
echo '
<table style="width: 100%">
<tr>';
foreach ($pollResults['options'] as $pollItem)
{
preg_match($patternImg, $pollItem['option'], $image);
$imageCount++;
if ($imageCount > $imagesPerRow)
{
echo '
</tr>
<tr>';
$imageCount = 1;
}
echo '
<td style="width: 25%; text-align: center; padding: 1px 1px 10px 1px;">
<a href="' , $scripturl , '?topic=' , $pollTopic , '">
<img ' , $image[0] , ' alt="Go Vote !" title="Go Vote !" border="0" width="100" />
</a>
<br />
Member : ' , strip_tags($pollItem['option']);
if (!$pollResults['allow_vote'])
{
echo '
<br />
Votes : ' , $pollItem['votes'] , ' (' , $pollItem['percent'] , '%)
<br />
' , $pollItem['bar'];
}
echo '
</td>';
}
while ($imageCount < $imagesPerRow)
{
echo '
<td style="width: 25%">
</td>';
$imageCount++;
}
echo '
</tr>
</table>';
Quote from: Freddy on July 13, 2010, 07:00:57 PM
Well I can mimic what SSI normally does... try this :
Woohoo, it works. :D
Thank you Freddy, you're a star. O0 I'm sure the guys will love this.
Welcome :)
:-[ I spoke too soon. All works well but now if you sign out you can see the votes. ???
Yeah it's the same with SSI. I guess they figured that if they aren't a member then it might not matter if guests could see the results. OR they never finished doing it properly...
We could hide the results from guests...would that do ?
Quote from: Freddy on July 14, 2010, 01:11:39 PM
We could hide the results from guests...would that do ?
That would be great, and would cure the problem O0 I'm assuming the poll images etc will still be visible etc, but just not the votes.
If worst comes to worst and as a last resort, I could always hide the block from guests.
Thanks again
Mick aka lurk
Yes it will still show the images to the guests, but it will omit the votes cast.
Find :
if (!$pollResults['allow_vote'])
Replace with :
if (!$pollResults['allow_vote'] && !$context['user']['is_guest'])
Also, just to be sure, add $context to the global line near the top so it's like this :
global $scripturl, $context;
Freddy.
That seems to have done the trick. I think the block is working just as we wanted now. O0
Cheers and many thanks again for all your help. ;)
You are welcome Mick :)
Resurrecting this thread, as I have another question for Freddy.
This is the final code I've been using for some time now. But just realised that if a image added to my poll is from a attachment, the image doesn't show in the poll block, and it throw a undefined error in the log every time the home page is displayed.
So Freddy, is there any way to make it work with attached images, or it it not possible.?
Here's the code,
/////////////////////
// Set up the topic where the poll is.
$pollTopic = 2245;
// Set poll topic subject
$polltext = "<center><b><h3>Subject = 'Great outdoors' : Voting closes: 03 September 2011, 13:24:42</h3></b></center>" ;
/////////////////////
// Images per row.
$imagesPerRow = 4;
$pollResults = ssi_showPoll($pollTopic,'array');
// Just a counter..
$imageCount = 0;
global $scripturl, $context;
$patternImg = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i";
echo ' <center><b><h2>Poll for the weekly competition</h2></b></center> ';
echo $polltext ;
echo ' <hr> ';
echo '
<table style="width: 100%">
<tr>';
foreach ($pollResults['options'] as $pollItem)
{
preg_match($patternImg, $pollItem['option'], $image);
$imageCount++;
if ($imageCount > $imagesPerRow)
{
echo '
</tr>
<tr>';
$imageCount = 1;
}
echo '
<td style="width: 25%; text-align: center; padding: 1px 1px 10px 1px;">
<a href="' , $scripturl , '?topic=' , $pollTopic , '">
<img ' , $image[0] , ' alt="Go Vote !" title="Go Vote !" border="0" width="100" />
</a>
<br />
Member : ' , strip_tags($pollItem['option']);
if (!$pollResults['allow_vote'] && !$context['user']['is_guest'])
{
echo '
<br />
Votes : ' , $pollItem['votes'] , ' (' , $pollItem['percent'] , '%)
<br />
' , $pollItem['bar'];
}
echo '
</td>';
}
while ($imageCount < $imagesPerRow)
{
echo '
<td style="width: 25%">
</td>';
$imageCount++;
}
echo '
</tr>
</table>';
echo ' <center><b>Please click on any image to take you to the poll</b></center> ';