<?php
//
// CF Polls v0.94
// -------------------------------
//
// Author: codefuture.co.uk
// Version: 0.94
// Date: 2-Jan-11
//
//
// 30-Dec-10
// 0.92 - Added a new Option (On by default) the script can use cookies as well as the IP address logging
// to help prevent multiple votes by people with dynamic IP's address.
// You can turn cookies off by using 'setCookieOff()' before 'one_vote()'....
//
// 28-Dec-10
// 0.92 - Added a new Option to set the end date for the poll
// endPollOn(day,month,year)
//
// 06-Jun-10
// 0.91 - fix script was not letting you add new answer to a poll what is running..
//
// download the latest version from - http://codefuture.co.uk/projects/cf_polling/
// Copyright (c) 2010 codefuture.co.uk
//
////////////////////////////////////////////////////////////////////////////////////
define('CFPOLLS_VOTE', 'Vote');
define('CFPOLLS_VOTE_OPEN_TO', 'Poll open to');
define('CFPOLLS_VOTE_END_ON', 'Poll closed on');
define('CFPOLLS_VIEW_RESULTS', 'View Results');
define('CFPOLLS_RESULTS', 'Results');
define('CFPOLLS_VOTE_IN_POLL', 'Vote in this poll');
define('CFPOLLS_TOTAL', 'Total: %s votes.');
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Please make sure that the folder "polls" in folder cfPolling is writable (chmod 777).
define('CFPOLLS_SAVE_DATA', 'polls');
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
//global sitting
$cfp_js = false;
class cf_poll{
private $votes;
private $filr_dir;
private $question_file;
private $ip_file;
private $one_vote_ip = false;
private $one_vote_cookie = false;
private $cookie;
private $cookie_url = null;
private $cookieOff = 0;//false;
private $voted = false;
private $voteSaved = false;
private $pollEnded = false;
private $question;
private $poll_id;
private $poll_start_date;
private $poll_end_date;
private $total;
private $answer_list;
private $results;
private $css_id_name = 'cf_poll';
private $indexdb = array(); //Poll Index db
private $pollIndexFile; //Poll Index Address
public function cf_poll($question,$answers = null){
// set file address
$dir = dirname(__FILE__).'/'.CFPOLLS_SAVE_DATA.'/';
$this->question_file = $dir.md5($question).'.cfp';
$this->ip_file = $dir.md5($question).'ip.cfp';
$this->pollIndexFile = $dir.'poll_index.cfp';
$this->question = $question;
//$this->polls_index();
$this->loadIndex();
if(!file_exists($this->question_file)){
$i = 1;
foreach ($answers as $v){
$new_answers[] = array( 'id' => $i, 'answer'=> $v, 'votes' => 0 );
$i++;
}
$this->save_db($this->question_file,$new_answers);
$this->votes = $new_answers;
}else{//0.91
$this->votes = $this->load_db($this->question_file);
if(!is_null($answers) && count($this->votes) < count($answers)){
foreach ($answers as $v){
if(!$this->in_array_recursive($v,$this->votes)){
$this->votes[] = array( 'id' => $i, 'answer'=> $v, 'votes' => 0 );
$added_new = 1;
}
}
if($added_new){
$this->save_db($this->question_file,$this->votes);
}
}
}
}
public function one_vote(){
$this->one_vote_ip = true;
$this->one_vote_cookie = true;
if(!$this->cookieOff && isset($_COOKIE['Poll_'.ereg_replace("[^0-9]", "", md5($this->question))])){
$this->voted = true;
return;
}
$ips = $this->load_db($this->ip_file); // load ip array
if(in_array($_SERVER['REMOTE_ADDR'],$ips)){ // submit vote
$this->set_cookie();
$this->voted = true;
}
}
public function poll_for($day){
$time_dif = time() - $this->poll_start_date;
$time_dif = round( abs($time_dif / 86400));
if (empty($this->poll_end_date))
$this->poll_end_date = $this->poll_start_date + ($day * 86400);
if($time_dif >= $day){
$this->voted = true;
$this->pollEnded = true;
}
}
public function endPollOn( $d,$m,$y ){
$gd_a = getdate($this->poll_start_date);
$a_new = mktime( 12, 0, 0, $gd_a['mon'], $gd_a['mday'], $gd_a['year'] );
$b_new = mktime( 12, 0, 0, $m, $d, $y );
$this->poll_end_date = $b_new;
if ($b_new < $a_new)
$this->poll_for(0);
else
$this->poll_for(round( abs( $a_new - $b_new ) / 86400 ));
}
public function new_vote($vote = null){
if(is_null($vote)) return;
if(!isset($vote['vote_'.$this->poll_id]))return;
$vote_id = $vote['vote_'.$this->poll_id];
$ips = $this->load_db($this->ip_file); // load ip array
if(isset($vote_id) && (!in_array($_SERVER['REMOTE_ADDR'],$ips) || !$this->one_vote_ip)){ // submit vote
foreach($this->votes as $k => $v){
if ($v['id']==$vote_id) $this->votes[$k]['votes']++; // add vote
}
$this -> save_db( $this -> question_file, $this->votes); // save vote
if($this->one_vote_ip){
$ips[] = $_SERVER['REMOTE_ADDR']; // add new ip
$this->save_db( $this -> ip_file, $ips); // save ip
$this->voted = true;
}
if($this->one_vote_cookie && !isset($_COOKIE['Poll_'.md5($this->question)])){
$this->set_cookie();
$this->voted = true;
}
$this->voteSaved = true;
}
}
public function setCookieURL($var){$this->cookie_url = $var;}
public function setCookieOff(){$this->cookieOff = true;}
private function set_cookie(){
if(!$this->cookieOff ){
if(is_null($this->cookie_url)){
$domain = $_SERVER['HTTP_HOST'];
if ( !strtolower( substr($domain, 0, 4) ) == 'www.' )
$domain = substr($domain, 4); // Fix the domain to accept domains with and without 'www.'.
if ( substr($domain, 0, 1) != '.' )
$domain = '.'.$domain; // Add the dot prefix to ensure compatibility with subdomains
$self = $_SERVER['PHP_SELF'];
$script_url = 'http://www'.$domain.mb_substr($self,0,-mb_strlen(strrchr($self,"/")));
$this->cookie = '<img src="'.$script_url.'/cfPolling/cf.poll.class.php?id='.ereg_replace("[^0-9]", "", md5($this->question)).'" height="1" width="1" />';
}else{
$this->cookie = '<img src="'.$this->cookie_url.'?id='.ereg_replace("[^0-9]", "", md5($this->question)).'" height="1" width="1" />';
}
}
}
public function make_poll_list(){
//total votes
foreach($this->votes as $k => $v){
$this->total += $v['votes'];
}
//lists
foreach($this->votes as $k => $v){
//list possible answers
if (!$this->voted)
$this->answer_list .= '<label><input type="radio" name="vote_'.$this->poll_id.'" value="'.$v['id'].'" id="answer-'.$v['id'].'"/>'.$v['answer'].'</label>';
//list Results
$this->results .= '<label>'.$v['answer'].' ('.$v['votes'].')</label>
<div class="barempty"><div class="barfull" style="width:'.$this->percent($v['votes'],$this->total).'%"><div class="percent">'.$this->percent($v['votes'],$this->total).'%</div></div></div>';
}
}
private function loadIndex(){
//if no index file then make it
if(!file_exists($this->pollIndexFile)){
//make index db
$this->indexdb[] = array(
'id' => 1,
'file' => md5($this->question),
'date' => time(),
'css' => null,
'vote' => 0,
'cookie'=> 0,
);
$this->poll_id = 1; // set poll id
$this->poll_start_date = time(); // set poll start date
// save index
$this->save_db($this->pollIndexFile,$this->indexdb);
}else{
//read index file
// load index to db
$this->indexdb = $this->load_db($this->pollIndexFile);
// see if poll is in db
$temp_id = 1; //for poll if not found in the db
foreach($this->indexdb as $k => $v){
if($v['id'] >= $temp_id) $temp_id = $v['id'] + 1;
if($v['file'] == md5($this->question)){
$this->poll_id = $v['id'];
$this->poll_start_date = $v['date'];
$this->cs
没有合适的资源?快使用搜索试试~ 我知道了~
基于PHP的CFPollingphp投票系统源码.zip
共4个文件
php:3个
css:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 129 浏览量
2023-07-30
21:51:59
上传
评论
收藏 9KB ZIP 举报
温馨提示
基于PHP的CFPollingphp投票系统源码.zip
资源推荐
资源详情
资源评论
收起资源包目录
基于PHP的CFPollingphp投票系统源码.zip (4个子文件)
132678419979933868
cf_polling_v0.94
cfPolling
ajax.php 309B
cf.poll.class.php 17KB
polls
poll.css 7KB
example.php 3KB
共 4 条
- 1
资源评论
易小侠
- 粉丝: 6481
- 资源: 9万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功