Archive for the ‘jME-Week’ Category

Resetting WP-Polls

Wednesday, June 10th, 2009

Please ignore this entry as production test showed big issues

Use it as hints how to modify WP-Polls but don’t expect that code to work properly!

Known issue: The vote count is not decreased and there seems to be a problem with IE.It works but ajax is haning to saying there is a problem…So actually with that all of this is not much worth! I will try to fix that as fast a possible!

At the moment I’m setting up the website for the jME-Week. It is build upon wordpress. I found a quite capable plugin for voting WP_POLLS. Problem is that once a user voted he is not able to change his vote anymore. My setup is that only users are allowed to vote and the poll should only be visible for logged in users. So I added something like a hook to reset the vote for the current vote again. It is a really dirty hack. So if anyone is using it, it is your own risk!

Ok,…here we go. I assume you installed the plugin already. Go to the “Poll_Templates”-Page in the administration-area:

add this at the beginning of the result footer “Displayed when the user HAS voted”:


<form method=”post”><input type=”submit” value=”reset vote”/><input type=”hidden” name=”poll_id” value=”%POLL_ID%”/><input type=”hidden” name=”reset_poll” value=”1″/></form>

Soo…now comes the real dirty one. Actually I just needed a place where I can catch with global $user_ID the current userID. For some reason I didn’t realise that in wp-polls-widget.php so before search too long in put it into wp-settings.php (You can find it in your main wordpress-directory. usally that is WP)

Add at the end of the file right behind

$wp->init(); // Sets up current user.

// Everything is loaded and initialized.
do_action('init');

the action for processing the reset:

$reset = $_POST['reset_poll'];
if ($reset==’1′)
{
global $wpdb;
global $user_ID;
$poll_id = $_POST['poll_id'];
if ($user_ID>0)
{


$connection=mysql_connect("localhost", "<FILL IN USERNAME>", "<FILL IN PASSWORD>") or die("DB ERROR");
mysql_select_db("<FILLIN DATABASENAME",$connection) or die("DB ERROR");
mysql_query("update wp_pollsa SET polla_votes=polla_votes-1 where polla_aid in (select s.pollip_aid from wp_pollsip s where pollip_userid=$user_ID and pollip_qid=$poll_id)");
mysql_close($connection);
$wpdb->query("delete from $wpdb->pollsip where pollip_userid=$user_ID and pollip_qid=$poll_id");
}
}

In order to disable poll in the sidebar edit the wp-polls-widget.php in the wp/wp-content/plugins/wp-polls/ directory and replace the code at the beginning:


function widget_polls_init() {
get_currentuserinfo();
global $userdata;
if (!function_exists('register_sidebar_widget')||!isset($userdata)) {
return;
}

I know it is really a mess,…but it works for me and I really don’t want to put too much time in to it. AND every minute using PHP makes me much too agressive! I HATE PHP! I HATE IT SOO MUCH!
If someone found a better place how to handle all of this I would be glad for a note.

And don’t forget: Use this on your own risk. It is not well tested….Actually it is only tested twice AND please no requests for modifications! I won’t do it! Look at “I hate PHP“. (If my mother would know what PHP is she would hate it for sure as well…! Isn’t it violating the Geneva conventions? We have to stop it :-) )

organizing the jME-Week

Wednesday, June 10th, 2009

Well…I had the idea that there should be something like the great pyweek for the jME-world as well. So I asked in community if someone would be interested. There was positiv feedback and here we are. Ok, I made the mistake not just saying here is the contest with that rules but started to discuss how it should/could be… So some people start thinking to big from the beginning thinking about prize-money in order to be more attractive to outsider and so on. I know this situations. Maybe there are good ideas but to much at the beginning could be contra-productive or even could risk that the whole competition even starts at all. Noone says the first competition have to be such huge…

Nevertheless I adapted the pyweek rules to the jME-Week (still hoping the pyweek-guys let me use it)  and think that could be a good beginning. In my opinion fame, glory and fun are the only suitable motivations for the competition. That should strengthen the community…. and even if there would be only two participants it would be a beginning to build on to.

If you want to participate at the moment there is a voting for finding a suitable date:

http://www3.doodle.com/bmm8h9iruub7gize