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

📄 class_poll.php

📁 具有多種面版可以選擇的"投票程式" 多國語言版
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php
/**
 * ----------------------------------------------
 * Advanced Poll 2.0.3 (PHP)
 * Copyright (c)2001 Chi Kien Uong
 * URL: http://www.proxy2.de
 * ----------------------------------------------
 */

class poll {

    var $pollvars;
    var $poll_view_html;
    var $poll_result_html;
    var $include_path;
    var $form_forward;
    var $template_set;
    var $poll_array;
    var $color_array;
    var $total_votes;
    var $question;
    var $poll_question; 
    var $comments;
    var $ip;

    function poll() {
        global $pollvars, $HTTP_SERVER_VARS;
        
        $this->poll_view_html = array();
    	$this->poll_result_html = array();
    	$this->poll_array = array();
    	$this->color_array = array();
    	$this->total_votes = '';
    	$this->question = '';
    	$this->poll_question = array(); 
    	$this->comments = '';
    
        if (isset($HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR']) && eregi("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$",$HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'])) {
            $this->ip = $HTTP_SERVER_VARS['HTTP_X_FORWARDED_FOR'];
        } else {
            $this->ip = getenv("REMOTE_ADDR");
        }
        $this->pollvars = $pollvars;
        $this->template_set = "default";
        $this->form_forward = basename($HTTP_SERVER_VARS['PHP_SELF']);
        $this->include_path = dirname(dirname(__FILE__));
    }

    function set_template_set($template_set='') {
        if (empty($template_set) || !file_exists("$this->include_path/templates/$template_set/display_foot.html")) {
            $this->template_set = "default";
        } else {
            $this->template_set = $template_set;
        }
        return $this->template_set;
    }
    
    function set_include_path($path) {
        if (!@is_dir($path)) {
            return false;
        }
        $this->include_path = $path;
        return true;
    }

    function set_display_order($order='') {
        switch ($order) {
            case "asc":
                $this->pollvars['result_order'] = "asc";
                break;
            case "desc":
                $this->pollvars['result_order'] = "desc";
                break;
            default:
                $this->pollvars['result_order'] = "";
                return false;
        }
        return true;
    }

    function set_display_result($result='') {
        switch ($result) {
            case "votes":
                $this->pollvars['type'] = "votes";
                break;
            case "percent":
                $this->pollvars['type'] = "percent";
                break;
            default:
                return false;
        }
        return true;
    }

    function set_max_bar_length($max_bar_length='') {
        if ($max_bar_length && $max_bar_length>0) {
            $this->pollvars['img_length'] = $max_bar_length;
            return true;
        } else {
            return false;
        }
    }

    function set_max_bar_height($max_bar_height='') {
        if ($max_bar_height && $max_bar_height>0) {
            $this->pollvars['img_height'] = $max_bar_height;
            return true;
        } else {
            return false;
        }
    }
    
    function get_poll_tpl($tpl) {
        $filename = "$this->include_path/templates/$this->template_set/$tpl.html";
        if (file_exists("$filename")) {
            $fd = fopen ($filename, "r");
            $template = fread ($fd, filesize ($filename));
            fclose ($fd);
            $template = ereg_replace("\"", "\\\"", $template);
            return $template;
        } else {
            return false;
        }
    }

    function lock_poll_ip($poll_id) {
        $this_time = time();
        if (file_exists("$this->include_path/polldata/$poll_id.ip")) {
            $ip_array = file("$this->include_path/polldata/$poll_id.ip");
            $ip_table = fopen("$this->include_path/polldata/$poll_id.ip","wb");
            flock($ip_table, 2);
            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 ($ip_addr == $this->ip) {
                        continue;
                    }
                    fwrite($ip_table,"$ip_addr|$time_stamp");
                }
            }
            fwrite($ip_table,"$this->ip|$this_time\n");
            flock($ip_table, 3);
            fclose($ip_table);
        } else {
            $ip_table = fopen("$this->include_path/polldata/$poll_id.ip","wb");
            fwrite($ip_table,"$this->ip|$this_time\n");
            fclose($ip_table);
        }
    }

    function log_vote($poll_id) {
        $this_time = date("j-M-Y H:i",time());
        $host = @gethostbyaddr($this->ip);
        $agent = @getenv("HTTP_USER_AGENT");
        $log_table = fopen("$this->include_path/polldata/$poll_id.log","a");
        flock($log_table, 2);
        fwrite($log_table,"$this_time|$this->ip|$host|$agent\n");
        flock($log_table, 3);
        fclose($log_table);
    }

    function get_poll_data($poll_id) {
        $this->total_votes=0;
        if (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->question = $question;
                $this->comments = chop($comments);
                $this->poll_array = '';
                $this->color_array = '';
                for ($i=1; $i<sizeof($line); $i++) {
                    list($name,$vote,$gif_color) = split("\\|",$line[$i]);
                    $this->poll_array[$name] = $vote;
                    $this->color_array[$name] = chop($gif_color);
                    $this->total_votes += $vote;
                }
                for (reset($this->poll_array),$this->maxvote=0; $key=key($this->poll_array); next($this->poll_array)) {
                    $this->maxvote = ($this->poll_array[$key]>$this->maxvote) ? $this->poll_array[$key] : $this->maxvote;
                }
                return true;
            }
        } else {
            return false;
        }
    }

    function get_poll_stat($poll_id) {
        $line = file("$this->include_path/polldata/$poll_id");
        list($question,$timestamp,$exp_time,$expire,$logging,$status,$comments) = split("\\|",$line[0]);
        $comments = chop($comments);
        return (sizeof($line)>0) ? array(
            "question"  => "$question",
            "timestamp" => "$timestamp",
            "exp_time"  => "$exp_time",
            "expire"    => "$expire",
            "logging"   => "$logging",
            "status"    => "$status",
            "comments"  => "$comments"
        ) : false;
    }

    function get_poll_list() {
        $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,"rsort_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==0 || $status==1) {
                    if (eregi("([0-9]+$)", $poll_list[$i], $regs)) {
                        $available_polls[] = $regs[1];
                    }
                }
            }
        }
        return (isset($available_polls)) ? $available_polls : false ;
    }

    function update_poll($poll_id,$option_id) {
        if (get_magic_quotes_gpc()) {
            $option_id = stripslashes($option_id);
        }
        if ($this->pollvars['check_ip'] == 2) {
            $this->lock_poll_ip($poll_id);
        }
        $stat_array = $this->get_poll_stat($poll_id);
        if ($stat_array['logging'] == 1) {
            $this->log_vote($poll_id);
        }
        $line = file("$this->include_path/polldata/$poll_id");
        $count_dat = fopen("$this->include_path/polldata/$poll_id","w");
        flock($count_dat, 2);
        $line[0] = chop($line[0]);
        fwrite($count_dat,"$line[0]\n");
        for ($i=1; $i<sizeof($line); $i++) {
            list($name,$vote,$gif_color) = split("\\|",$line[$i]);
            if ($name == $option_id) {
                $vote += 1;
            }
            $gif_color = chop($gif_color);
            fwrite($count_dat,"$name|$vote|$gif_color\n");
        }
        flock($count_dat, 3);
        fclose($count_dat);
    }

⌨️ 快捷键说明

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