TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,966
  • Latest: safir45
Stats
  • Total Posts: 195,991
  • Total Topics: 21,323
  • Online today: 545
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 291
  • Total: 291

Poll images in front page block

Started by lurkalot, July 06, 2010, 11:22:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Freddy

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;

lurkalot

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.   ;)

Freddy


lurkalot

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> ';

This website is proudly hosted on Crocweb Cloud Website Hosting.