Avatar billede funkylezzz Praktikant
28. juni 2010 - 20:41 Der er 1 kommentar og
1 løsning

Vote script omkodning.

Hej jeg leger med XML Flash Voting Poll.
Det er et rigtig fin script, men jeg vil gerne have at man kan tilgå resultatet uden at man skal stemme, for at folk ikke skal stemme bare for at se resultatet, da det give utrovædige resultater. Scriptet kan ses på mit website under kategorien girl.

Xml Flash voting poll indeholder følgene filer:

Index.html
Checkip.php
Vote.php
Xml_functions.php
Content.xml Ikke relevant
Settings.xml



Index.html

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
       
        <script type="text/javascript" src="../../../media/swfobject.js"></script>
        <script type="text/javascript" src="../../../media/swfmacmousewheel.js"></script>
        <script type="text/javascript">
       
            // JAVASCRIPT VARS
            // cache buster
            var cacheBuster = "?t=" + Date.parse(new Date());       
           
            // stage dimensions
            var stageW = 250;//"100%";
            var stageH = 180;//"100%";   
           
           
            // ATTRIBUTES
            var attributes = {};
            attributes.id = 'FlabellComponent';
            attributes.name = attributes.id;

            // PARAMS
            var params = {};
            params.bgcolor = "#ffffff";
            params.menu = "false";
            params.scale = 'noScale';
            params.allowfullscreen = "true";
            params.allowScriptAccess = "always";
            //params.wmode = "transparent";//"opaque";

   
            /* FLASH VARS */
            var flashvars = {};
           
            /// if commented / delete these lines, the component will take the stage dimensions defined
            /// above in "JAVASCRIPT SECTIONS" section or those defined in the settings xml                   
            flashvars.componentWidth = stageW;
            flashvars.componentHeight = stageH;
           
            /// path to the content folder(where the xml files, images or video are nested)
            /// if you want to use absolute paths(like "http://domain.com/images/....") then leave it empty("")           
            flashvars.pathToFiles = "rate/passion-cams/poll/";
            //
            flashvars.id = "12345";
            //
            flashvars.xmlPath = "xml/settings.xml";
            flashvars.xmlContentPath = "xml/content.xml";
            //
            flashvars.checkIpScriptPath = "php/checkIP.php";
            flashvars.voteScriptPath = "php/vote.php";
           
            /** EMBED THE SWF**/       
            swfobject.embedSWF('../../../media/preview.swf'+cacheBuster, attributes.id, stageW, stageH, '9.0.45', '../../../media/expressinstall.swf', flashvars, params, attributes);
            if(swfmacmousewheel) swfmacmousewheel.registerObject(attributes.id);
         
        </script>
       
   
        <table width="100%" height="100%" cellpadding="0" cellspacing="0">
            <td align="center">
               
                <!-- this div will be overwritten by SWF object -->       
                <div id="FlabellComponent">
                    <p>In order to view this object you need Flash Player 9+ support!</p>
                    <a href="http://www.adobe.com/go/getflashplayer">
                        <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/>
                    </a>
                </div>
           
            </td>
        </table>
               
   
</html>




Checkip.php

<?php
$votantIp = $_SERVER['REMOTE_ADDR'];   
$pollId = $_POST['poll_id'];

// restrict multiple votes from the same IP                           
$ipList_hdl = @fopen('iplist_'.$pollId.'.txt','r');
while($ipList_hdl!=null and !feof($ipList_hdl)){
    $one_ip = fgets($ipList_hdl);         
    $one_ip = str_replace(array("\r\n", "\n", "\r"),'',$one_ip);
    if($one_ip == $votantIp){
            fclose($ipList_hdl);
            die('0');
        }                         
}

@fclose($ipList_hdl);

die('1');

?>




Vote.php

<?php
   
    require_once('xml_functions.php');
   
   
    define('XML_PATH','../../'.$_POST['relativeXmlContentPath']);
    //define('XML_PATH','poll.xml');
    $pollId = $_POST['poll_id'];
    $votedId = $_POST['vote_id'];   
    $votantIp = $_SERVER['REMOTE_ADDR'];
                       
    //echo $votantIp;
   
    //die();
                       
    // restrict multiple votes from the same IP                           
    $ipList = array();     
    $ipList_hdl = @fopen('iplist_'.$pollId.'.txt','a+');
    if($ipList_hdl != null){
        while(!feof($ipList_hdl)){
            $one_ip = fgets($ipList_hdl);         
            $one_ip = str_replace(array("\r\n", "\n", "\r"),'',$one_ip);
            if(strlen($one_ip)>6){
                if($one_ip != $votantIp){
                    array_push($ipList,$one_ip);   
                }
                else{
                    fclose($ipList_hdl);
                    die('2');   
                }
            } 
        }
    }
   
                       
    if(!file_exists(substr(XML_PATH,1))) {
        die('0');
        fclose($ipList_hdl);
    }
   
    if(!isset($votedId) or $votedId == ''){
        die('0');
        fclose($ipList_hdl);
    }
   
    $xml = xml2ary(@file_get_contents(substr(XML_PATH,1)));
    $ok = false;
   
    if(isset($xml['poll']['_c']['answer']) and sizeof($xml['poll']['_c']['answer'])>0){
        $i = 0;
        foreach($xml['poll']['_c']['answer'] as $answer){
            if($answer['_a']['id'] == $votedId){
                $xml['poll']['_c']['answer'][$i]['_a']['votes'] = $answer['_a']['votes'] + 1;
                $f = @fopen(substr(XML_PATH,1),'w+');
                fwrite($f,'<?xml version="1.0" encoding="UTF-8"?>'.ary2xml($xml));
                fclose($f);
                $ok = true;
            }
            $i++;
        }
    }
    else{
        die('0');
    }
   
    if($ok){
        //log the votant IP
        fwrite($ipList_hdl,$votantIp.'
');
        fclose($ipList_hdl);   
        echo '1';       
    }
    else{
        fclose($ipList_hdl);
        echo '0';
    }
?>




Xml_functions.php

<?php
/*
    Working with XML. Usage:
    $xml=xml2ary(file_get_contents('1.xml'));
    $link=&$xml['ddd']['_c'];
    $link['twomore']=$link['onemore'];
    // ins2ary(); // dot not insert a link, and arrays with links inside!
    echo ary2xml($xml);
*/

// XML to Array
function xml2ary(&$string) {
    $parser = xml_parser_create();
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parse_into_struct($parser, $string, $vals, $index);
    xml_parser_free($parser);

    $mnary=array();
    $ary=&$mnary;
    foreach ($vals as $r) {
        $t=$r['tag'];
        if ($r['type']=='open') {
            if (isset($ary[$t])) {
                if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
                $cv=&$ary[$t][count($ary[$t])-1];
            } else $cv=&$ary[$t];
            if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
            $cv['_c']=array();
            $cv['_c']['_p']=&$ary;
            $ary=&$cv['_c'];

        } elseif ($r['type']=='complete') {
            if (isset($ary[$t])) { // same as open
                if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
                $cv=&$ary[$t][count($ary[$t])-1];
            } else $cv=&$ary[$t];
            if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
            $cv['_v']=(isset($r['value']) ? $r['value'] : '');

        } elseif ($r['type']=='close') {
            $ary=&$ary['_p'];
        }
    }   
   
    _del_p($mnary);
    return $mnary;
}

// _Internal: Remove recursion in result array
function _del_p(&$ary) {
    foreach ($ary as $k=>$v) {
        if ($k==='_p') unset($ary[$k]);
        elseif (is_array($ary[$k])) _del_p($ary[$k]);
    }
}

// Array to XML
function ary2xml($cary, $d=0, $forcetag='') {
    $res=array();
    foreach ($cary as $tag=>$r) {
        if (isset($r[0])) {
            $res[]=ary2xml($r, $d, $tag);
        } else {
            if ($forcetag) $tag=$forcetag;
            $sp=str_repeat("\t", $d);
            $res[]="$sp<$tag";
            if (isset($r['_a'])) {foreach ($r['_a'] as $at=>$av) $res[]=" $at=\"$av\"";}
            $res[]=">".((isset($r['_c'])) ? "\n" : '');
            if (isset($r['_c'])) $res[]=ary2xml($r['_c'], $d+1);
            elseif (isset($r['_v'])) $res[]=$r['_v'];
            $res[]=(isset($r['_c']) ? $sp : '')."</$tag>\n";
        }
       
    }
    return implode('', $res);
}

// Insert element into array
function ins2ary(&$ary, $element, $pos) {
    $ar1=array_slice($ary, 0, $pos); $ar1[]=$element;
    $ary=array_merge($ar1, array_slice($ary, $pos));
}

?>




Settings.xml

<?xml version = "1.0" encoding = "UTF-8"?>

<settings width = "" height = "">
   
    <voting_session openVoting = "true"
                    openVotingMessage = "Please select one option below."
                    closedVotingMessage = "The voting session is closed now."
                    questionResultMessage = "Thank you for your vote!" />
   
    <background strokeColor = "0xC8CACC" fillColor = "0xF3F5F5" contentMargin = "3" />

    <question backgroundHeight = "10" backgroundStrokeColor = "0xFFFFFF"
        backgroundFillGradientBeginColor = "0xF3A342" backgroundFillGradientEndColor = "0xEE8631"
        textColor = "0xFFFFFF" textFontSize = "10"
       
        votesTextColor = "0x666666" votesTextFontSize = "10"
        votesBackgroundHeight = "10" votesBackgroundStrokeColor = "0xEEEFEF" votesBackgroundFillColor = "0xffffff"
        totalVotesString = "Total votes:" />

    <list itemHeight = "10" distanceBetweenItems = "3"
        imageVisible = "true" imageWidth = "75" imageHeight = "15"
       
        radioButtonColor = "0x000000" radioButtonOverColor = "0xEE8631"
       
        itemStrokeColor = "0xEEEFEF" itemStrokeOverColor = "0xEE8631" itemFillColor = "0xffffff"
       
        itemTextColor = "0x666666" itemTextOverColor = "0xEE8631" itemTextFontSize = "10"
       
        voteSingleString = "Vote" votePluralString = "Votes"
        itemVotesTextColor = "0x666666" itemVotesTextFontSize = "10"
        itemVotesBackgroundHeight = "10" itemVotesBackgroundFillColor = "0xF3F5F5" itemVotesBackgroundStrokeColor = "0xEEEFEF"
       
        itemBarHeight = "3" itemBackgroundBarColor = "0xF1F2F2" itemBarColor = "0xF7941E" />

    <scroll backgroundWidth = "16" backgroundColor = "0xF77E0B" scrubWidth = "6" scrubColor = "0xffffff" />

    <vote_button voteText = "VOTE"
        textColor = "0xffffff" overTextColor = "0x333333" inactiveTextColor = "0xD1D3D4" textFontSize = "12"
        iconColor = "0xffffff" iconInactiveColor = "0xD1D3D4"
        backgroundWidth = "60" backgroundHeight = "23"
        backgroundStrokeColor = "0xC8CACC"
        backgroundFillGradientBeginColor = "0xE84B14" backgroundFillGradientEndColor = "0xF77E0B" backgroundFillInactiveColor = "0xF3F5F5"    />

    <error     visibilityTime = "3" textColor = "0xE84B14" textFontSize = "12"
            serverError = "Sorry for inconvenience. Please try again later."
            votingError = "Your vote wasn't registered."
            alreadyVoted = "You already voted!"
            votedMessage = "Thank you for your vote!" />

</settings>


Håber ikke at jeg er til for meget besvær men er der nogen der kan fortælle hvad jeg skal gøre?
Avatar billede intenz Novice
28. juni 2010 - 21:04 #1
'lav det her for mig' spørgsmål kommer der typisk ikke nogle brugbare svar ud af. Det er ikke ligetil og derfor tages der normalt penge for sådan noget.

Desuden er det nok flash koden der skal rettes i, og du skal have kildekoden hertil for at kunne rette det.
Avatar billede funkylezzz Praktikant
10. januar 2011 - 20:46 #2
Lukker
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester