⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class_poll.php

📁 具有多種面版可以選擇的"投票程式" 多國語言版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    function get_poll_question($poll_id) {
        if (!isset($this->poll_question[$poll_id]) && file_exists("$this->include_path/polldata/$poll_id")) {           
            $line = file("$this->include_path/polldata/$poll_id");
            if (ereg(".*\\|[0-9]+\\|[0-9]+\\|[0-9]{1}\\|[0-9]{1}\\|[0-9]{1}\\|[0-9]{1}",$line[0])) {
                list($question,$timestamp,$exp_time,$expire,$logging,$status,$comments) = split("\\|",$line[0]);
                $this->poll_question[$poll_id] = $question;
            } else {
                $this->poll_question[$poll_id] = '';
            }            
        } else {
            $this->poll_question[$poll_id] = '';
        }
        return $this->poll_question[$poll_id];
    }

    function display_poll($poll_id) {
        if (!isset($this->poll_view_html[$poll_id]) || !isset($this->poll_view_html[$poll_id][$this->template_set])) {
            if ($this->get_poll_data($poll_id)) {
                $pollvars = $this->pollvars;
                $question = $this->question;
                eval("\$display_html = \"".$this->get_poll_tpl("display_head")."\";");
                $loop_html = $this->get_poll_tpl("display_loop");
                for (reset($this->poll_array); $key=key($this->poll_array); next($this->poll_array)) {
                    $key = $key;
                    eval("\$display_html .= \"$loop_html\";");
                }
                eval("\$display_html .= \"".$this->get_poll_tpl("display_foot")."\";");
                $this->poll_view_html[$poll_id][$this->template_set] = $display_html;
            } else {
                return '';
            }        
        }
        return $this->poll_view_html[$poll_id][$this->template_set];
    }

    function view_poll_result($poll_id,$vote_stat=0) {
        if (!isset($this->poll_result_html[$poll_id]) || !isset($this->poll_result_html[$poll_id][$this->template_set])) {
            if ($this->get_poll_data($poll_id)) {
                $pollvars = $this->pollvars;
                $question = $this->question;
                eval("\$result_html = \"".$this->get_poll_tpl("result_head")."\";");
                $loop_html = $this->get_poll_tpl("result_loop");
                if (count($this->poll_array)) {                
                    if ($this->pollvars['result_order'] == "asc") {
                        uasort($this->poll_array,"sort_poll");
                    } elseif ($this->pollvars['result_order'] == "desc") {
                        uasort($this->poll_array,"rsort_poll");
                    }
                    $top_pos = (int) ($this->maxvote);
                }
                $total = ($this->total_votes<=0) ? 1 : $this->total_votes;
                $top_pos = ($this->total_votes==0) ? 1 : (int) ($this->maxvote);
                for (reset($this->poll_array); $key=key($this->poll_array); next($this->poll_array)) {
                    $vote_val = ($this->pollvars['type']=="percent") ? sprintf("%.1f",($this->poll_array[$key]*100/$total))."%" : $this->poll_array[$key];
                    $vote_percent = sprintf("%.2f",($this->poll_array[$key]*100/$total));
                    $vote_count = $this->poll_array[$key];
                    $img_width = (int) ($this->poll_array[$key]*$this->pollvars['img_length']/$top_pos);
                    $image = $this->color_array[$key];
                    $key_val = htmlspecialchars($key);                
                    eval("\$result_html .= \"$loop_html\";");
                }
                $VOTE = ($vote_stat==1) ? $this->pollvars['voted'] : '';
                $COMMENT = ($this->comments==1) ? "<a href=\"javascript:void(window.open('$pollvars[base_url]/comments.php?action=send&amp;id=$poll_id&amp;template_set=$this->template_set','$poll_id','width=230,height=320,toolbar=no,statusbar=no'))\">".$this->pollvars['send_com']."</a>" : '';
                eval("\$result_html .= \"".$this->get_poll_tpl("result_foot")."\";");
                $this->poll_result_html[$poll_id][$this->template_set] = $result_html;
            } else {
                return '';
            }
        }
        return $this->poll_result_html[$poll_id][$this->template_set];
    }

    function get_random_poll_id() {
        $hnd = opendir("$this->include_path/polldata");
        while ($file = readdir($hnd)) {
            if (eregi("([0-9]+$)", $file)) {
                $poll_list[] = $file;
            }
        }
        closedir($hnd);
        if (isset($poll_list)) {
            usort($poll_list,"sort_poll");
            for ($i=0; $i<sizeof($poll_list); $i++) {
                $line = file("$this->include_path/polldata/$poll_list[$i]");
                list($question,$timestamp,$exp_time,$expire,$logging,$status,$comments) = split("\\|",$line[0]);
                if (($status==1 && $expire==0) || ($status==1 && $exp_time>time())) {
                    if (eregi("([0-9]+$)", $poll_list[$i], $regs)) {
                        $poll_id_arr[] = $regs[1];
                    }
                }
            }
        }
        if (!isset($poll_id_arr)) {
            return 0;
        }
        $available = sizeof($poll_id_arr)-1;
        srand((double) microtime() * 1000000);
        $random_id = ($available>0) ? rand(0,$available) : 0;
        return $poll_id_arr[$random_id];
    }

    function get_latest_poll_id() {
        $poll_ids = $this->get_poll_list();
        if (!$poll_ids) {
            return 0;
        }
        return $poll_ids[0];
    }

    function is_valid_poll_id($poll_id) {
        if ($poll_id>0) {
            if (!file_exists("$this->include_path/polldata/$poll_id")) {
                return false;
            } else {
                $stat_array = $this->get_poll_stat($poll_id);
                return ($stat_array["status"]==2) ? false : true;
            }
        } else {
            return false;
        }
    }

    function has_voted($poll_id) {
        global $HTTP_COOKIE_VARS;
        $pollcookie = "AdvancedPoll".$poll_id;
        if (isset($HTTP_COOKIE_VARS[$pollcookie])) {
            return true;
        }
        if ($this->pollvars['check_ip']==2) {
            $found=false;
            if (file_exists("$this->include_path/polldata/$poll_id.ip")) {
                $ip_array = file("$this->include_path/polldata/$poll_id.ip");
                $this_time = time();
                for ($i=0; $i<sizeof($ip_array); $i++) {
                    list ($ip_addr, $time_stamp) = split("\\|",$ip_array[$i]);
                    if ($this_time < ($time_stamp+3600*$this->pollvars['lock_timeout'])) {
                        if ($this->ip == $ip_addr) {
                            $found=true;
                            break;
                        }
                    }
                }
            }
            return $found;
        } else {
            return false;
        }
    }

    function is_active_poll_id($poll_id) {
        if ($poll_id>0) {
            if (!file_exists("$this->include_path/polldata/$poll_id")) {
                return false;
            } else {
                $stat_array = $this->get_poll_stat($poll_id);
                if ($stat_array["expire"]==0) {
                    return true;
                }
                return ($stat_array['exp_time']<time()) ? false : true;
            }
        } else {
            return false;
        }
    }

    function get_query_strg($self) {
        global $HTTP_SERVER_VARS;
        if (isset($HTTP_SERVER_VARS['QUERY_STRING']) && !empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
            if (ereg("($self=[0-9]+)",$HTTP_SERVER_VARS['QUERY_STRING'],$regs)) {
                $HTTP_SERVER_VARS['QUERY_STRING'] = str_replace($regs[1], "", $HTTP_SERVER_VARS['QUERY_STRING']);                                
            }
            $HTTP_SERVER_VARS['QUERY_STRING'] = str_replace("$self=", "", $HTTP_SERVER_VARS['QUERY_STRING']);
            if (empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
                $append = $HTTP_SERVER_VARS['PHP_SELF']."?";
            } else {
                $query_vars = explode("&",$HTTP_SERVER_VARS['QUERY_STRING']);
                $append = $HTTP_SERVER_VARS['PHP_SELF']."?";
                for ($i=0; $i<sizeof($query_vars); $i++) {
                    if (!empty($query_vars[$i])) {
                        $append .= $query_vars[$i]."&";        
                    }
                }
            }
        } else {
            $append = $HTTP_SERVER_VARS['PHP_SELF']."?";
        }
        return $append;
    }

    function poll_process($poll_id='') {
        global $HTTP_GET_VARS, $HTTP_POST_VARS;        
        
        $poll_ident = (isset($HTTP_POST_VARS['poll_ident'])) ? intval($HTTP_POST_VARS['poll_ident']) : "";
        if ($poll_ident == "") {
        	if (isset($HTTP_GET_VARS['poll_ident'])) {
        		$poll_ident = intval($HTTP_GET_VARS['poll_ident']);
        	}
        }

        $option_id = (isset($HTTP_POST_VARS['option_id'])) ? trim($HTTP_POST_VARS['option_id']) : "";
        if ($option_id == "") {
        	if (isset($HTTP_GET_VARS['option_id'])) {
        		$option_id = trim($HTTP_GET_VARS['option_id']);
        	}
        }

        $action = (isset($HTTP_POST_VARS['action'])) ? trim($HTTP_POST_VARS['action']) : "";
        if ($action == "") {
        	if (isset($HTTP_GET_VARS['action'])) {
        		$action = trim($HTTP_GET_VARS['action']);
        	}
        }
        
        if ($poll_id=="random") {
            $poll_id = (empty($poll_ident)) ? $this->get_random_poll_id() : $poll_ident;
        } elseif ($poll_id=="newest") {
            $poll_id = $this->get_latest_poll_id();
        }
        if ($this->is_valid_poll_id($poll_id)) {
            $voted = $this->has_voted($poll_id);
            $is_active = $this->is_active_poll_id($poll_id);
            if ($action=="results" && $poll_id==$poll_ident) {
                return $this->view_poll_result($poll_id,0);
            } elseif (!$is_active) {
                return $this->view_poll_result($poll_id,0);
            } elseif ($is_active && $voted) {
                return $this->view_poll_result($poll_id,1);
            } elseif (!$voted && isset($option_id) && $action=="vote" && $poll_id==$poll_ident) {
                $this->update_poll($poll_id,$option_id);
                return $this->view_poll_result($poll_id,0);
            } else {
                return $this->display_poll($poll_id);
            }
        } else {
            $error = "<b>Poll ID <font color=red>$poll_id</font> does not exist.</b>";
            return $error;
        }
    }

}

function sort_poll($a,$b) {
    if ($a == $b) return 0;
    return ($a > $b) ? 1 : -1;
}
    
function rsort_poll($a,$b) {
    if ($a == $b) return 0;
    return ($a > $b) ? -1 : 1;
}

?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -