sNews Ajax Polls mod now available

sNews Ajax Polls mod now available

OK folks, here it is, the initial release of my sNews Polls mod for sNews 1.7. Ready to get started? Good, it should only take about 5-10 minutes for the average sNews user to install. Go ahead and download the mod zip file;

VERSION history
[1.0.3] - fixed show_poll function to display when called directly via PHP for people NOT using the cache mod
[1.0.2] - prepared show_poll function to work with caching mod
[1.0.1] - fixed missing DB prefix
[1.0.0] - initial release

Step 1) Now extract the archive and familiarize yourself with the files, you should have a folder titled mod_poll, with all the relevant content inside. You'll need to edit a few items now, open poll_process.php and modify the language file name (if not English) and database settings;


$server = 'localhost';
$dbuser = 'database_username';
$dbpass = 'database_password';
$dbname = 'database_name';
$dbprefix = '';

Now save the poll_process.php file and close it.

Step 2) Now use the poll.sql file and phpMyAdmin (or your preferred DB tool) to add the database tables. You can delete the poll.sql file if you like now, once the tables have been added.

Step 3) Now upload the entire mod_poll folder and contents to the SAME directory as your snews.php, like in this example;

/home/mysite/public_html/mod_poll/jscolor/<jscolor files>

Step 4) Next we need to gather the sNews files needed to pull the whole thing together... unfortunately sNews has no plug-in hooks at all, so we have to get our hands a little dirty, but I have done my best to make this part as easy as possible for folks to do. So create a new folder on your desktop titled SNEWS-POLL, now download the following files into the folder;

lang/EN.php (or your local language file)

Now copy the SNEWS-POLL folder and save that copy as SNEWS-POLL.orig, now you have a back-up, if your site breaks, just upload the contents of the .orig folder and that will recover your site.

Step 5) Let's edit the index.php file now, make sure you're working in the SNEWS-POLL folder, not the back-up ;)... now add the following just BELOW the snews.php include in the document head;

<?php include("mod_poll/poll_functions.php"); ?>

then add the following just below the title() function call in the document head;

<script type="text/javascript" src="mod_poll/poll.js"></script>
<link rel="stylesheet" href="mod_poll/poll_styles.css" type="text/css" />

Save and close index.php

Step 6) Open EN.php (or whatever language file you use) and add the following code;

    # Ajax Polls mod
    $l['polls'] = 'Manage polls';
    $l['snews_polls'] = 'Manage Ajax polls';
    $l['admin_poll'] = 'Edit Ajax poll';
    $l['poll_not_found'] = 'Error, poll does not exist';
    $l['poll_reset_msg'] = 'All votes will be removed, this will NOT remove cookies set for people who may have already voted, are you sure you want to reset total to 0?';
    $l['poll_delete_msg'] = 'The poll and all votes will be removed, are you sure you want to delete?';
    $l['js_poll1'] = 'Enter the poll ID.';
    $l['poll'] = 'Poll';
    $l['poll_value'] = 'Add Poll';
    $l['poll_question'] = 'Add your poll question here.';
    $l['poll_create'] = 'Create a new poll';
    $l['poll_manage'] = 'Manage current polls';
    $l['no_polls'] = 'No polls created yet.';
    $l['poll_overview_question'] = 'Poll question';
    $l['poll_overview_color'] = 'Poll bar color';
    $l['poll_id'] = 'ID';
    $l['poll_edit_id'] = 'Edit poll ID #';
    $l['poll_answers'] = 'Poll answers';
    $l['poll_add_answer'] = 'Add another answer';
    $l['poll_save'] = 'Save';
    $l['poll_delete'] = 'Delete';
    $l['poll_reset'] = 'Reset votes';
    $l['poll_embed'] = 'Embed codes'; 
    $l['poll_embed_snews'] = 'sNews code:';
    $l['poll_embed_php'] = 'PHP code:';
    $l['poll_preview'] = 'Preview poll';
    $l['poll_votes_singular'] = 'vote';
    $l['poll_votes_plural'] = 'votes';
    $l['poll_total_votes'] = 'Total votes: ';
    $l['poll_back_to'] = 'Back to poll';
    $l['poll_vote_button'] = 'Vote';
    $l['poll_view_results'] = 'View current results';

Save and close EN.php

Step 7) Open your admin.js file, add the poll button code between the func and include button code, highlighted below;

// function use end
case 'poll':// adding function insertion url = prompt("<?php echo l('js_poll1'); ?>", ''); start = url !=null ? '[func]show_poll:|:'+url+',0[\/func]' : ''; end = ''; break;
case 'include':

Save and close admin.js

Step 8) Open snews.php and add the two hard-coded pages to the $l['cat_listSEF'], like highlighted below (scroll over if necessary, it's there);

if (_ADMIN) {$l['cat_listSEF'] .= ',administration,admin_category,admin_article,admin_poll,snews_polls,article_new,extra_new,page_new,snews_categories,

now find the function center and add the following highlighted code;

case 'snews_files':
    files(); return; break;
case 'admin_poll': polls('edit'); return; break; case 'snews_polls': polls('home'); return; break;
case 'process':
    processing(); return; break;

now find the function administration and add the following highlighted code;

echo '<p><a href="snews_settings/">'.l('settings').'</a></p>
    <p><a href="snews_files/">'.l('files').'</a></p>
    <p><a href="snews_polls/">'.l('polls').'</a></p>

now find the function button, and insert the highlighted code to make the article poll button;

$insert = array('img', 'link', 'include', 'func','intro','poll');

and lastly, add the following function to the bottom of your snews.php file, just above the closing php tag;

// Ajax POLLS
function polls($option) {
    if (file_exists('mod_poll/poll_admin.php')) {
    } else {
        echo "<h2>Oops!</h2><p>I couldn't find the mod file!</p>";

Step 9) Now upload your index.php, snews.php, admin.js, and EN.php files and you should be all set. Log-in to your admin interface and you should have the option to manage polls now. Enjoy!

A couple of things to note, if you're deleting a poll answer that has already been voted on, those votes remain, unless you reset all votes. Your best bet is to make sure the poll is the way you want it before making it publicly available, or edit the answers, you can always add new answers too. To add a poll to an article, simply click the embed sNews code box and copy the code into your article.

As usual, this stuff is provided without warranty, use at your own risk, etc. If I missed a step or something doesn't appear correct, please let me know as soon as possible and I'll do what I can to fixes any issues.



You might like


Let me be the first to say, WELL DONE (caps was needed) can't wait to try it out.

Great MOD Matt!! I wish i use snews 1.7 but i m for now stuck with 1.6..I know people going to use this MOD a lot .. Great :)

Thanks guys. Sasha, that's too bad, I remember looking at sNews several years ago, it was like 1.3 then or something, but I didn't start using it until 1.7, so I'm kinda of clueless about the differences with 1.6, though I know there were quite a few changes... enough to break most of the existing mods anyways.

Thanks for this great mod!

I installed it on my 1.6 MU version and realized midway the process that it was for 1.7 so I changed the necessary parts and now it works like a charm but it took some more time than the 5-10 minutes you predicted :D

Gnilp, that is cool, was it very difficult to change it to work with sNews 1.6?

I've never used 1.6, but if it's not too much work, I will consider installing it on my test machine and back-porting the mod.

Also, I'll update the article to note it's intended for sNews 1.7 :)

I'm a newbie, but really enjoying the ride. I seem to have problems following the language sometimes in the instructions, so I know I've made the mistake.

Anyway, when I click, Create a Poll, I get, "Error Error, poll does not exist."

I got a feeling it's something that I didn't see or clearly understand in the early phpMyAdmin phase.

Am I correct, and if so, how can I solve this?


Hi Homer, welcome to the fold. If you're getting that error when creating a poll, then it's definitely a problem with inserting into the database tables.

Do you have a default first poll listed on the manage polls page? If not, then the database tables definitely weren't loaded properly.

Let me know, if you have trouble installing the database tables with the .sql file and phpMyAdmin, then drop me a help request on my contact form and I'll do my best to walk you through it over email or yahoo messenger.

Everything went well.
Except one thing.
The total vote is empty(Total votes:).
(I made only 1 vote which is correctly registered).
A bug?

Hi Sven,

Yep, as usual, it's the table prefix, lol :)

Find line 65 of poll_functions.php and and this prefix bit;

$query = mysql_query("SELECT COUNT(id) AS total_votes FROM "._PRE."poll_answers WHERE pid='".$pid."'");

Damn, I thought I had all the prefixes this time too! :)

I will update the package as well.

Those bloody snoozers and their table prefixes!!!
Now it works!
Thanks Matt.

lol, I'll learn to add the prefixes from the start one day!

What I usually do is create these mods for my own site here, and then I'll clean them up and install them on my test site before a public release, I'm going to add prefixes on my test site's tables before the next mod.

The mod_poll package has been updated to 1.0.1, no need to update if you changed line 65 in poll_functions.php, there were no other changes.

Lol too.
But no lol there:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Is it the server or me?

I think it's me... waitee... waitee...

Hmmm, Sven, did you set the database settings & prefix in poll_process.php?

Hum... I made an error with the syntax.
It's now corrected.

... and, tada! it works!
Really a great Mod Matt!
Once again bravo and thanks!

Cool, looks good to me, now I just have to choose between Raquel Welch or Ursula Andress, in their primes, not easy! I think the years have been much kinder to Raquel however, she still looks good :)

Thanks for your vote. I made the same.
Ursula was just a starlette but Raquel was an actress.
It makes a lotta difference.

Hmmm, I see what you're saying, though I'm not able to duplicate the problem.

I just created the same poll on my site and it seems to be working fine.

Have a look here;

Is it working for you?
Try adding this just above the other header calls in poll_process.php
header("Content-Type: text/html; charset=utf-8");

Hi Matt...
it's workin for you and not for me. Weid.

Sven, did you change any encodings with the DB when you set-up sNews?

As it's only when outputting from the ajax called PHP function, it's gotta be something simple.

Did you try adding the extra header yet in poll_process.php?

Comments are closed. No new comments allowed.

Copyleft 2002 - 2017 Matt Jones
Hand crafted with HTML5 & CSS3
↑ Back to top