Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2008-01-15 04:24:18
- nyckidd
- New Member
- Registered: 2007-12-16
- Posts: 4
Customize pap_xpoll
Need some help customizing this polling script….need to insert some images in the code ….
// xpoll tags ----------------------------------------------------------------
function pap_xpoll($atts) {
global $xpoll_data;
$pollid = (empty($atts['poll']) ? '' : $atts['poll']);
$optionclass = (empty($atts['optionclass'])) ? '' : $atts['optionclass'];
$previewclass = (empty($atts['previewclass'])) ? '' : $atts['previewclass'];
$voteclass = (empty($atts['voteclass'])) ? '' : $atts['voteclass'];
$submitclass = (empty($atts['submitclass'])) ? '' : $atts['submitclass'];
$resultsclass = (empty($atts['resultsclass'])) ? '' : $atts['resultsclass'];
$id = (empty($atts['id'])) ? 'xpolltxtoption' : $atts['id'];
$formid = (empty($atts['formid'])) ? '' : ' id="' . $atts['formid'] . '"';
$label = (empty($atts['label']) ? gTxt('vote') : $atts['label']);
if (!empty($pollid)) {
$rs = mysql_query ('SELECT pollid, title, starts, expires, vote, voting, optdisplay, answertype, results, graph, resultsvotes, ip, cookies
FROM ' . PFX . 'xpolls WHERE status="on" AND pollid=' . $pollid);
} else {
$rs = mysql_query ('SELECT pollid, title, starts, expires, vote, voting, optdisplay, answertype, results, graph, resultsvotes, ip, cookies
FROM ' . PFX . 'xpolls WHERE status="on" ORDER BY pollid DESC LIMIT 1');
}
$totalpolls = mysql_num_rows($rs);
if ($totalpolls > 0) {
populate_xpoll_data($rs);
if ((!isset($_REQUEST['option']) | $_REQUEST['poll'] != $xpoll_data['poll']) && (!isset($_REQUEST['results']) | $_REQUEST['results'] !=
$xpoll_data['poll']) && $xpoll_data['votecookies'] != 'no' && $xpoll_data['voteip'] != 'no' && $xpoll_data['blocked'] != 'yes' && $xpoll_data['started'] == 'yes' &&
$xpoll_data['expired'] == 'no' && $xpoll_data['voting'] == 'yes') {
$form = (empty($atts['form']) ? '' : $atts['form']);
if ($form) {
$form = parse(fetch("Form","txp_form","name",$form));
} else {
$form = pap_xpoll_title();
$form .= '<br />';
$atts['class'] = $optionclass;
$atts['id'] = $id;
$form .= pap_xpoll_options($atts);
$atts['class'] = $submitclass;
$atts['label'] = $label;
$form .= pap_xpoll_submit($atts);
$form .= '<br />';
$atts['class'] = $previewclass;
$form .= pap_xpoll_preview($atts);
}
$out = '<form action="' . $_SERVER['REQUEST_URI'] . '" method="post" name="xpoll" class="xpoll"' . $formid . ' >' . $form .
'<input name="option" type="hidden" id="optionid" /><input name="poll" type="hidden" value="' . $xpoll_data['poll'] . '" /></form>';
} else {
if (($xpoll_data['blocked'] == 'yes' | $xpoll_data['voteip'] == 'no' | $xpoll_data['votecookies'] == 'no' | isset ($_REQUEST['results']) |
$xpoll_data['voting'] == 'no' | isset ($_REQUEST['option'])) && $xpoll_data['graph'] != 'no' && $xpoll_data['started'] == 'yes') {
if (((isset ($_REQUEST['results']) && $xpoll_data['results'] == 'yes' && ($xpoll_data['voteip'] != 'yes' |
$xpoll_data['votecookies'] != 'yes')) | !isset ($_REQUEST['results'])) && $xpoll_data['started'] == 'yes') {
$form = (empty($atts['resultform']) ? '' : $atts['resultform']);
if ($form) {
$form = parse(fetch("Form","txp_form","name",$form));
} else {
$form = pap_xpoll_title()."Title";
$form .= '<br />';
$atts['class'] = $resultsclass;
$form .= pap_xpoll_results($atts);
$atts['class'] = $voteclass;
$form .= pap_xpoll_vote($atts);
}
$out = $form;
}
}
}
} else {
$out = '<div align="center" class="xpollText">' . gTxt('no_polls') . '</div>';
}
if ($totalpolls > 0 && $xpoll_data['voting'] == 'no' && $xpoll_data['graph'] == 'no') {
$out = '<div align="center" class="xpollText">' . gTxt('no_vote_or_view') . '</div>';
}
if ($totalpolls > 0 && $xpoll_data['voting'] == 'yes' && $xpoll_data['graph'] == 'no' && isset ($_REQUEST['option'])){
$out = '<div align="center" class="xpollText">' . gTxt('thanks_for_voting') . '</div>';
}
if ($totalpolls > 0 && $xpoll_data['voting'] == 'yes' && $xpoll_data['graph'] == 'no' && ($voteip == 'no' | $votecookies == 'no') && !isset
($_REQUEST['option'])) {
$out = '<div align="center" class="xpollText">' . gTxt('no_view') . '</div>';
}
if ($totalpolls > 0 && $xpoll_data['results'] == 'no' && isset ($_REQUEST['results'])) {
$out = '<div align="center" class="xpollText">' . gTxt('no_view') . '</div>';
}
unset($xpoll_data);
return $out;
}
function pap_xpoll_title() {
global $xpoll_data;
return $xpoll_data['title'];
}
function pap_xpoll_options($atts) {
global $xpoll_data;
$poll = $xpoll_data['poll'];
$optdisplay = $xpoll_data['optdisplay'];
$answertype = $xpoll_data['answertype'];
$class = (empty($atts['class'])) ? '' : ' class="' . $atts['class'] . '"';
$id = (empty($atts['id'])) ? 'xpolltxtoption' : $atts['id'];
$options = mysql_query ('SELECT optionid, options, order_id, optiontype FROM ' . PFX . 'xpoll_options WHERE pollid=' . $poll . ' ORDER BY order_id
ASC');
$option = '';
if ($optdisplay == 'yes') {
if ($answertype == 'single') {
while ($optionrows = mysql_fetch_array($options)) {
$option .= '<input name="option1" type="hidden" value="' . $optionrows['optionid'] . '"';
$image_name = $optionrows['order_id'];
switch($image_name){
case 1:
$file_name = "http://final.linxyssolutions.com/images/benhappy.jpg";
break;
case 2:
$file_name = "http://final.linxyssolutions.com/images/mixedben.jpg";
break;
case 3:
$file_name = "http://final.linxyssolutions.com/images/sadben.jpg";
break;
}
if ($optionrows['order_id'] == 1) {
$option .= ' checked="checked"';
}
$option .= (empty($class)) ? '' : $class;
$option .= ' />';
if ($optionrows['optiontype'] == 0) {
$value_pass = $optionrows['optionid'];
$option .= "<input type='image' onClick='setValue($value_pass)' name='pap_xpoll_submit' src='$file_name' value='". $optionrows['optionid']."'>".$optionrows['options'] ;
} else {
$option .= '<label for="' . $id . '">' . $optionrows['options'] . '</label><br /><input name="txtoption[' .
$optionrows['optionid'] . ']" type="text" id="' . $id . '" /><br />';
}
}
} else {
while ($optionrows = mysql_fetch_array($options)) {
$option .= '<input name="option[' . $optionrows['optionid'] . ']" type="checkbox" value="' . $optionrows['optionid'] .
'"';
if ($optionrows['order_id'] == 1) {
$option .= ' checked="checked"';
}
$option .= (empty($class)) ? '' : $class;
$option .= ' />';
if ($optionrows['optiontype'] == 0) {
$option .= $optionrows['options'] . '<br />';
} else {
$option .= '<label for="' . $id . '">' . $optionrows['options'] . '</label><br /><input name="txtoption[' .
$optionrows['optionid'] . ']" type="text" id="' . $id . '" /><br />';
}
}
}
} else {
$request_uri = $_SERVER['REQUEST_URI'];
if (!empty($_SERVER['QUERY_STRING'])) {
$regexp = '[&?]results=[0-9]+';
$replace = '';
if (ereg($regexp, $request_uri)) {
$request_uri = ereg_replace($regexp, $replace, $request_uri);
parse_str($_SERVER['QUERY_STRING'], $querystring);
if (count($querystring) > 1) {
$request_uri .= '&';
} else {
$request_uri .= '?';
}
} else {
$request_uri .= '&';
}
} else {
$request_uri .= '?';
}
while ($optionrows = mysql_fetch_array($options)) {
$option .= '<a href="' . $request_uri;
$option .= 'poll=' . $poll . '&';
$option .= 'option=' . $optionrows['optionid'] . '&';
$option .= 'pap_xpoll_submit=1"';
$option .= (empty($class)) ? '' : $class;
$option .= '>' . $optionrows['options'] . '</a><br />';
}
}
return $option;
}
function pap_xpoll_submit($atts) {
global $xpoll_data;
if ($xpoll_data['optdisplay'] == 'yes') {
$label = (empty($atts['label']) ? gTxt('vote') : $atts['label']);
$class = (empty($atts['class'])) ? '' : ' class="' . $atts['class'] . '"';
$btnSubmit = '<input name="pap_xpoll_submit" type="hidden" value="' . $label . '"' . $class . ' />' ;
return $btnSubmit;
}
return;
}
function pap_xpoll_preview($atts) {
global $xpoll_data;
$results = $xpoll_data['results'];
$graph = $xpoll_data['graph'];
$poll = $xpoll_data['poll'];
$class = (empty($atts['class'])) ? '' : ' class="' . $atts['class'] . '"';
if ($results == 'yes' && $graph != 'no') {
$request_uri = $_SERVER['REQUEST_URI'];
if (!empty($_SERVER['QUERY_STRING'])) {
parse_str($_SERVER['QUERY_STRING'], $querystring);
$countstring = count($querystring);
$count = 0;
if (isset($_GET['poll'])) {
$regexp = '[&?]poll=[0-9]+&option=[0-9]+&pap_xpoll_submit=1';
$request_uri = ereg_replace($regexp, '', $request_uri);
$count += 3;
}
if (isset($_GET['results'])) {
$regexp = 'results=[0-9]+';
$replace = 'results=' . $poll;
$request_uri = ereg_replace($regexp, $replace , $request_uri);
} else {
if ($countstring - $count > 0) {
$request_uri .= '&';
} else {
$request_uri .= '?';
}
$request_uri .= 'results=' . $poll;
}
} else {
$request_uri .= '?results=' . $poll;
}
$preview = '<a href="' . $request_uri . '"' . $class . '>' . gTxt('view_results') . '</a>';
}
return $preview;
}
function pap_xpoll_results($atts) {
global $xpoll_data;
$class = (empty($atts['class'])) ? '' : ' class="' . $atts['class'] . '"';
$option = mysql_query ('SELECT options, votes, images, order_id FROM ' . PFX . 'xpoll_options WHERE pollid=' . $xpoll_data['poll'] . ' ORDER BY
order_id ASC');
$sql ='SELECT options, votes, images, order_id FROM ' . PFX . 'xpoll_options WHERE pollid=' . $xpoll_data['poll'] . ' ORDER BY
order_id ASC';
$total = mysql_fetch_assoc (mysql_query ('SELECT SUM(votes) AS total FROM ' . PFX . 'xpoll_options WHERE pollid=' . $xpoll_data['poll']));
$rsettings = mysql_query('SELECT * FROM ' . PFX . 'xpoll_config WHERE pollid=' . $xpoll_data['poll']);
if (mysql_num_rows($rsettings) == 0) {
$rsettings = mysql_query('SELECT * FROM ' . PFX . 'xpoll_config WHERE pollid = 0');
}
$settings = mysql_fetch_array($rsettings);
$result = '';
if ($xpoll_data['graph'] == 'graph') {
if (!empty($settings['height'])) {
$height = ' height:' . $settings['height'] . ';';
}
while ($optionrows = mysql_fetch_array ($option)) {
$image_name = $optionrows['order_id'];
switch($image_name){
case 1:
$file_name = "http://final.linxyssolutions.com/images/benhappy.jpg";
break;
case 2:
$file_name = "http://final.linxyssolutions.com/images/mixedben.jpg";
break;
case 3:
$file_name = "http://final.linxyssolutions.com/images/sadben.jpg";
break;
}
@$percent = round (($optionrows['votes'] / $total['total']) * 100);
$width = $percent;
if ($width == 0) {
$width = 10;
}
switch ($xpoll_data['resultsvotes']) {
case 0:
$str = '<table border="0" width="100%">';
$str .= '<tr><td>';
$str .= "<img src='$file_name' align='absmiddle'>";
$str .= '</td><td nowrap="nowrap">'.$percent.'%'.$optionrows['votes'] . ' ' . gTxt('votes').'</td></tr></table>';
$value = $str;
break;
case 1: $value = '<span class="clsPerc">' . $percent . '%</span>'; break;
case 2: $value = '<span class="clsPerc">' . $optionrows['votes'] . ' ' . gTxt('votes') . '</span>'; break;
case 3: $value = ''; break;
}
$graph = '<div class="clsGraph" style="background-color:' . $settings['bg1'] . ';"><div style="color:' . $settings['text'] . ';
font-size:' . $settings['size'] . '; text-align:' . $settings['textAlign'] . '; background-color:' . $settings['bg2'] . '; width:' . $width . '%;' . $height . '">';
$result .= $optionrows['options'];
if ($settings['textAlign'] == 'outside') {
$result .= $value . $graph;
} else {
$result .= $graph . $value;
}
$result .= '</div></div>';
}
} else {
global $img_dir;
$rs = safe_row("ext, h", "txp_image", "id='$id' limit 1");
extract($rs);
while ($optionrows = mysql_fetch_array ($option)) {
echo $optionrows['order_id '];
$image_name = $optionrows['order_id'];
switch($image_name){
case 1:
$file_name = "http://final.linxyssolutions.com/images/benhappy.jpg";
break;
case 2:
$file_name = "http://final.linxyssolutions.com/images/mixedben.jpg";
break;
case 3:
$file_name = "http://final.linxyssolutions.com/images/sadben.jpg";
break;
}
@$percent = round (($optionrows['votes'] / $total['total']) * 100);
$width = $percent;
if ($width == 0) {
$width = 10;
}
if ($optionrows['images'] == 'random') {
$rs = mysql_query('SELECT id FROM ' . PFX . 'txp_image WHERE category = "xpoll"');
$images = array();
while ($row = mysql_fetch_array($rs)) {
array_push($images, $row['id']);
}
$rand = array_rand($images);
$id = $images[$rand];
} else {
$id = $optionrows['images'];
}
$rs = safe_row("ext, h", "txp_image", "id='$id' limit 1");
if ($rs) {
extract($rs);
$background = 'background:url('.hu.$img_dir.'/'.$id.$ext.')';
}
switch ($xpoll_data['resultsvotes']) {
case 0:
//$file_name = "http://final.linxyssolutions.com/images/benhappy.jpg";
$value = '<span class="clsPerc">' . $percent . '%</span> / '. $optionrows['votes'] . ' ' . gTxt('votes'); break;
case 1:
//$file_name = "http://final.linxyssolutions.com/images/mixedben.jpg";
$value = '<span class="clsPerc">' . $percent . '%</span>'; break;
case 2: $value = '<span class="clsPerc">' . $optionrows['votes'] . ' ' . gTxt('votes') . '</span>'; break;
case 3: $value = ''; break;
}
$graph = '<div class="clsGraph" style="background-color:' . $settings['bg1'] . ';"><div style="color:' . $settings['text'] . ';
font-size:' . $settings['size'] . '; text-align:' . $settings['textAlign'] . '; ' . $background . '; width:' . $width . '%; height:' . $h . 'px;">';
$result .= $optionrows['options'];
if ($settings['textAlign'] == 'outside') {
$result .= "Hello ".$value . $graph;
} else {
$result .= "<img src='$file_name'>". $graph . $value;
}
$result .= '</div></div>';
}
}
if ($xpoll_data['resultsvotes'] != 3) {
$result .= gTxt('total_votes') . ': ' . $total['total'] . '<br />';
}
return $result;
}
function pap_xpoll_vote() {
global $xpoll_data;
$class = (empty($atts['class'])) ? '' : ' class="' . $atts['class'] . '"';
$httpreferer = $_SERVER['REQUEST_URI'];
$regexp = '[?&]results=[0-9]+';
$replace = '';
$httpreferer = ereg_replace($regexp, $replace , $httpreferer);
$vote = '';
if (isset ($_REQUEST['results']) && $_REQUEST['results'] == $xpoll_data['poll']) {
$vote = '<a href="' . $httpreferer . '"' . $class . '>' . gTxt('vote_on_poll') . '</a>';
}
return $vote;
}
// populate xpoll public data ---------------------------------------------------------------
function populate_xpoll_data($rs) {
global $xpoll_data;
$row = mysql_fetch_array($rs);
$poll = $row['pollid'];
$title = $row['title'];
$answertype = $row['answertype'];
// Calculate Poll Expiration
list ($dayx, $monthx, $yearx) = explode ("/", $row['expires']);
$now = mktime (0, 0, 0, date ("m"), date ("d"), date ("Y"));
$expire = mktime (0, 0, 0, $monthx, $dayx, $yearx);
if ($expire <= $now) {
$expired = "yes";
} else {
$expired = "no";
}
// Calculate Poll Start
if ($expired == "no") {
list ($days, $months, $years) = explode ("/", $row['starts']);
$starts = mktime (0, 0, 0, $months, $days, $years);
if ($starts > $now) {
$started = "no";
} else {
$started = "yes";
}
} else {
$started = "no";
}
// Check if IP is blocked from voting
$blockcheck = mysql_num_rows(mysql_query('SELECT pid FROM ' . PFX . 'xpoll_blocks WHERE (pid ="' . $poll . '" OR pid = 0) AND ip="' .
$_SERVER['REMOTE_ADDR'] . '"'));
if ($blockcheck == 0) {
$blocked = "no";
} else {
$blocked = "yes";
}
// Check if user has voted (IP)
if ($row['ip'] == "yes") {
$check = mysql_query ('SELECT vote FROM ' . PFX . 'xpoll_ip WHERE pollid="' . $poll . '" AND ip="' . $_SERVER['REMOTE_ADDR'] . '"');
$checkip = mysql_num_rows ($check);
$ip = mysql_fetch_array ($check);
if ($checkip == 0 | $ip['vote'] < time ()) {
$voteip = "yes";
} else {
$voteip = "no";
}
if ($ip['vote'] <= time ()) {
mysql_query ('DELETE FROM ' . PFX . 'xpoll_ip WHERE pollid="' . $poll . '" AND ip="' . $_SERVER['REMOTE_ADDR'] . '"');
}
} else {
$voteip = "none";
}
// Check if user has voted (Cookie)
if ($row['cookies'] == "yes") {
if (isset ($_COOKIE[$poll])) {
if ($_COOKIE[$poll] == $title) {
$votecookies = "no";
} else {
$votecookies = "yes";
}
} else {
$votecookies = "yes";
}
} else {
$votecookies = "none";
}
if (isset($_REQUEST['pap_xpoll_submit']) && $_REQUEST['poll'] == $poll) {
$nextvote = $row['vote'] + time ();
if ($row['ip'] == 'yes' && $voteip != 'no') {
mysql_query ('INSERT INTO ' . PFX . 'xpoll_ip (pollid, ip, vote) VALUES ("' . $poll . '", "' . $_SERVER['REMOTE_ADDR'] . '", "' .
$nextvote . '")');
}
if ($row['cookies'] == 'yes' && $votecookies != 'no') {
setcookie ($poll, $title, $nextvote);
}
if ($votecookies != 'no' && $voteip != 'no' && $blocked != 'yes' && $started == 'yes' && $expired == 'no') {
if($answertype == 'single') {
mysql_query ('UPDATE ' . PFX . 'xpoll_options SET votes=votes + 1 WHERE optionid=' . $_REQUEST['option']);
$i = $_REQUEST['option'];
if(isset($_REQUEST['txtoption'][$i])) {
$text = $_REQUEST['txtoption'][$i];
$text = strip_tags($text);
if (!get_magic_quotes_gpc()) {
$text = addslashes($text);
}
mysql_query('INSERT INTO ' . PFX . 'xpoll_inputs (optid, text) VALUES ("' . $i . '", "' . $text . '")');
}
} else {
foreach($_REQUEST['option'] as $value) {
mysql_query ('UPDATE ' . PFX . 'xpoll_options SET votes=votes + 1 WHERE optionid=' . $value);
if(isset($_REQUEST['txtoption'][$value])) {
$text = $_REQUEST['txtoption'][$value];
$text = strip_tags($text);
if (!get_magic_quotes_gpc()) {
$text = addslashes($text);
}
mysql_query('INSERT INTO ' . PFX . 'xpoll_inputs (optid, text) VALUES ("' . $value . '", "' . $text .
'")');
}
}
}
}
}
$xpoll_data['poll'] = $poll;
$xpoll_data['title'] = $title;
$xpoll_data['optdisplay'] = $row['optdisplay'];
$xpoll_data['answertype'] = $answertype;
$xpoll_data['results'] = $row['results'];
$xpoll_data['graph'] = $row['graph'];
$xpoll_data['starts'] = $row['starts'];
$xpoll_data['started'] = $started;
$xpoll_data['expires'] = $row['expires'];
$xpoll_data['expired'] = $expired;
$xpoll_data['vote'] = $row['vote'];
$xpoll_data['voting'] = $row['voting'];
$xpoll_data['resultsvotes'] = $row['resultsvotes'];
$xpoll_data['ip'] = $row['ip'];
$xpoll_data['cookies'] = $row['cookies'];
$xpoll_data['blocked'] = $blocked;
$xpoll_data['voteip'] = $voteip;
$xpoll_data['votecookies'] = $votecookies;
return $xpoll_data;
}
// xpoll admin pages -------------------------------------------------------------
if (@txpinterface == 'admin') {
include_once('../pap_xpoll_lib.php');
add_privs('xpoll','1,2,3,4');
register_tab("extensions", "xpoll", gTxt('tab_xpoll'));
register_callback("pap_xpoll_admin", "xpoll");
}
function pap_xpoll_admin($event, $step) {
pagetop("polls"); ?>
<div style="margin-right:5%; margin-left:5%; margin-top:1em; width:90%;"><?php
switch(strtolower($step)) {
case "": list_polls(); break;
case "addpoll": add_poll(); break;
case "emptypolls": empty_polls(); break;
case "editpoll": edit_poll(); break;
case "deletepoll": delete_poll(); break;
case "viewpoll": view_poll(); break;
case "ipblocker": list_blocks(); break;
case "addblock": add_block(); break;
case "emptyblocks": empty_blocks(); break;
case "editblock": edit_block(); break;
case "deleteblock": delete_block(); break;
case 'createsettings': settings(); break;
case 'settings': list_settings(); break;
case 'addsettings': add_settings(); break;
case 'deletesettings': delete_settings(); break;
case 'emptysettings': empty_settings(); break;
case 'editsettings': settings(); break;
} ?>
</div><?php
}
(Edit: updated discussion topic. -Mary)
Last edited by Mary (2008-01-16 11:43:19)
Offline
Offline
#3 2008-01-15 04:27:48
- nyckidd
- New Member
- Registered: 2007-12-16
- Posts: 4
Re: Customize pap_xpoll
what u mean ? was that the wrong code to paste ?
Offline
Re: Customize pap_xpoll
Well, it’s unreadable. Ask how to modify it in the plugin’s thread.
Offline
Pages: 1