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;
include_once('../lang/EN.php');
$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/snews.php /home/mysite/public_html/mod_poll/jscolor/<jscolor files> /home/mysite/public_html/mod_poll/delete.png /home/mysite/public_html/mod_poll/loading.gif /home/mysite/public_html/mod_poll/poll.gif /home/mysite/public_html/mod_poll/poll.js /home/mysite/public_html/mod_poll/poll_admin.php /home/mysite/public_html/mod_poll/poll_functions.php /home/mysite/public_html/mod_poll/poll_process.php /home/mysite/public_html/mod_poll/poll_styles.css
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;
index.php snews.php lang/EN.php (or your local language file) js/admin.js
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')) {
include_once('mod_poll/poll_admin.php');
do_polls($option);
} 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.
Comments
RSS Comments Feed
slemborg
sasha
Matt
Gnilp
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
Matt
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 :)
Homer Jackson
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?
Peace.
Matt
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.
Sven - Philippe
Except one thing.
The total vote is empty(Total votes:).
(I made only 1 vote which is correctly registered).
A bug?
Matt
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.
Sven - Philippe
Now it works!
Thanks Matt.
Matt
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.
Sven - Philippe
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?
Sven - Philippe
Sven - Philippe
http://carnet.hiseo.fr/blog-en-vrac/raquel-ou-ursula-ursula-ou-raquel-/
On my side it doesn't work still.
Matt
Sven - Philippe
It's now corrected.
Sven - Philippe
Really a great Mod Matt!
Once again bravo and thanks!
Matt
Sven - Philippe
Ursula was just a starlette but Raquel was an actress.
It makes a lotta difference.
Sven - Philippe
a little issue with the accented chars.
If there are some of those **** foreign chars right after the vote there are not displayed:
try it out here: http://carnet.hiseo.fr/qulture/plagiat-ou-simple-coincidence-/
Page has to be refreshed to display it.
Matt
I just created the same poll on my site and it seems to be working fine.
Have a look here; http://mdj.us/polltest/
Is it working for you?
<br/>
Try adding this just above the other header calls in poll_process.php
header("Content-Type: text/html; charset=utf-8");
Sven - Philippe
it's workin for you and not for me. Weid.
Matt
Sven - Philippe
Matt
Did you try adding the extra header yet in poll_process.php?
50 comments, page 1 of 2 [ 1 2 » ]