parser

Написать ответ на текущее сообщение

 

 
   команды управления поиском

Пустой

dRmx 16.10.2003 21:07 / 16.10.2003 21:14

Но проблемы на этом не кончаются :(

При выполнении этого кода:
@wear[skin;method][skin;fd;method]
^try{
	^if(-f $skin){
		$fd[^file::load[text;$skin]]
		^process{^taint[as-is][$fd.text]}
	}{
		^throw[parser.runtime;poll;Polls $method skin not found]
	}
}{
	^throw[parser.compile;poll;Skin compiling error. Check your $method skin code]
}
мне вылетает Skin compiling error. Check your $method skin code

ПОЖАЛУЙСТА, найдите здесь ошибки. За помощь буду ОЧЕНЬ благодарен.

Есть класс опросника
@CLASS
poll

@auto[] 
$connect_string[mysql://root@localhost/poll]

## main constructor
@create[pi_table_in;pa_table_in;extra][extra]
## shit class path
$cl_path[/poll]
## defining poll_info table
$pi_table[$pi_table_in]
## defining poll_answers table
$pa_table[$pa_table_in]
## defining date used in methods
$date_now[^date::now[]]
## adding extra methods
^if(def $extra){
	^try{
		^if(-f $extra){
			$extra[^file::load[text;$extra]]
			^process{^taint[as-is][$extra.text]}
		}{
			^throw[parser.runtime;poll;Extra methods file not found]
		}
	}{
		^throw[parser.compile;poll;Extra methods compiling error. Check your extra methods code]
	}
}
######## end of @create[] constructor ########

##############################################
## creates and runs-in new poll
@run[params][params;poll_id;answer_keys;id]
## parameters checking and errors detecting
^check_params[$params;run]
## question checking
^if(!def $params.question){
	^throw[parser.runtime;poll;Poll question not defined]
}
## answers checking
^if(!def $params.answers || !($params.answers is hash)){
	^throw[parser.runtime;poll;Answers parameter contains illegal value]
}
## inserting poll into $pi_table
^connect[$connect_string]{ 
^void:sql{
	INSERT INTO 
		$pi_table (
			question,
			type,
			default_value,
			button_text,
			status,
			dt_started
		)
	VALUES
		(
		'$params.question',
		'^if($params.type eq "checkbox"){$params.type}{radio}',
		'^params.default.int(1)',
		'^if(def $params.button_text){$params.button_text}{Ответить}',
		'^if($params.status eq "active"){$params.status}{closed}',
		'^date_now.sql-string[]'
		)
}
}
## extracting last_insert_id()
$poll_id[^last_insert_id[0]]
## sorting income answers
$answer_keys[^params.answers._keys[]]
^answer_keys.sort($answer_keys.key)
## inserting answers into $pa_table
^answer_keys.menu{
	$id[$answer_keys.key]
	^if(!($params.answers.$id is hash)){
		^throw[parser.runtime;poll;Answers must be defined as a hash]
	}
	^if(def $params.answers.$id.answer){
		^connect[$connect_string]{ 
		^void:sql{
			INSERT INTO
				$pa_table (
					poll_id,
					answer,
					vote_count
				)
			VALUES
				(
				'$poll_id',
				'$params.answers.$id.answer',
				'^params.answers.$id.vote_count.int(0)'
				)
		}
	}
}
}
## returns created poll's id and it's status
$result[$poll_id[$poll_id]]
$status[^connect[$connect_string]{^string:sql{SELECT status FROM $pi_table WHERE poll_id = $poll_id}[$.default{closed}]]}]
######## end of @run[] method ########

######################################
## draws the poll body on your page
@show[params][params;poll_id;path_param;cookie;expires;poll;action;answers]
## parameters checking
^check_params[$params;show]
## defining poll_id
^if(def $params.poll_id && $params.poll_id eq "last_active"){
	$poll_id[^last_insert_id[0]]
}{
	$poll_id[^params.poll_id.int(0)]
}
## extracting poll from database
$poll_info[^extract[$poll_id;info]]
## path parameter defining
$path_param[^if(def $params.path_param){^taint[xml][$params.path_param]}{vote_for}]
## detecting vote
^if((def $params.request && $params.request is hash && def $params.request.$path_param) || $poll_info.status eq "closed"){
## detecting restriction
	^if(def $params.restrict && $params.restrict is hash){
## cookie name defining
		^if(def $params.restrict.cookie){
			$cookie[${poll_id}_$params.restrict.cookie]
		}{
			$cookie[${poll_id}_poll]
		}
## expire date defining
		^if(def $params.restrict.expires){
			$expires[^params.restrict.expires.int(1)]
		}{
			$expires[session]
		}
## setting cookie
		^if(!def $cookie:$cookie){
			^if($expires eq "session"){
				$cookie:$cookie[$expires]
			}{
				$cookie:$cookie($expires)
			}
		}{
## voting restricted
			$restricted(1)
		}
	}
## updating vote counts
	^if(!$restricted && def $params.request.$path_param && $params.request.$path_param is table && $poll_info.status ne "closed"){
		^params.request.$path_param.menu{
			^connect[$connect_string]{^void:sql{
				UPDATE	$pa_table
				SET	vote_count = vote_count+1
				WHERE	answer_id = '^params.request.$path_param.field.int(0)'
				AND	poll_id = '$poll_id'
			}
		}
	}
## user voted or poll closed
	$action[result]
}{
## active poll, no vote submitted
	$action[answer]
}
}
## hashing poll
$poll[^poll_info.hash[poll_id]]
## extracting answers
$answers[^extract[$poll_id;answers]]
## hashing answers
$answers[^answers.hash[answer_id]]
## inserting answers into $poll hash
$poll.$poll_id.answers[$answers]
## adding path parameter
$poll.$poll_id.path_param[$path_param]
## extracting total votes for this poll
$poll.$poll_id.total[^connect[$connect_string]{^string:sql{SELECT SUM(vote_count) FROM $pa_table WHERE poll_id = '$poll_id' GROUP BY poll_id}[$.default{0}]}]
	^if($poll.$poll_id.total eq "0"){$poll.$poll_id.total[100]}
## rectriction defining
$poll.$poll_id.restricted[^if($restricted){yes}{no}]
## getting poll view
^if(def $params.skin){
## processing poll skin
	^transform[$params.skin;^printPoll[$poll;$action]]
}{
## printing poll
	^printPoll[$poll;$action]
}
######## end of @show[] method ########

#######################################
## updates existing poll
@update[params][params;poll_id]
## parameters checking
^check_params[$params;update]
## poll_id detecting
^if(!def $params.poll_id){
	^throw[parser.runtime;poll;Nothing to update, check your ^$.poll_id[]]
}{
	$poll_id(^params.poll_id.int(0))
	^if($poll_id <= 0){
		^throw[parser.runtime;poll;Invalid ^$.poll_id[]]
	}
}
## updating poll info
^if(def $params.question || def $params.type || def $params.status || def $params.default){
	^connect[$connect_string]{^void:sql{
		UPDATE	$pi_table
		SET	question = ^if(def $params.question){'$params.question'}{question},
			type = ^if(def $params.type){'^if($params.type eq "checkbox"){checkbox}{radio}'}{type},
			default_value = ^if(def $params.default){'^params.default.int(1)'}{default_value},
			button_text = ^if(def $params.button_text){'$params.button_text'}{button_text},
			status = ^if(def $params.status){^if($params.status eq "active"){'active', dt_ended = ''}{'closed', dt_ended = '^date_now.sql-string[]'}}{status}
		WHERE	poll_id = '$poll_id'
	}
}}
## updating answers
^if(def $params.answers && $params.answers is hash){
	^params.answers.foreach[key;value]{
		^if($value is hash){
			^if(^key.mid(0;3) eq "new"){
				^connect[$connect_string]{ 
				^void:sql{
					INSERT INTO
						$pa_table
							(
							poll_id,
							answer,
							vote_count
							)
					VALUES
						(
						'$poll_id',
						'$value.answer',
						'^value.vote_count.int(0)'
						)
				}
			}{
## deleting answers
				^if(^key.mid(0;6) eq "delete"){
					^void:sql{
						UPDATE	$pa_table
						SET	poll_id = 0
						WHERE	answer_id = ^value.answer.int(0)
						AND	poll_id = '$poll_id'
					}
				
				}{
## updating exist answer
					^void:sql{
						UPDATE	$pa_table
						SET	answer = ^if(def $value.answer){'$value.answer'}{answer},
							vote_count = ^if(def $value.vote_count){'^value.vote_count.int(0)'}{vote_count}
						WHERE	answer_id = ^key.int(0)
						AND	poll_id = '$poll_id'
					}
				}
			}
		}
	}
}}
######## end of @update[] method ########

##############################################
## poll_info and poll_answers extractor
@extract[poll_id;type][poll_id;type]
^if(def $poll_id){
	^switch[$type]{
		^case[info]{$result[^connect[$connect_string]{^table::sql{
						SELECT
							poll_id,
							question,
							type,
							default_value,
							button_text,
							status,
							dt_started,
							dt_ended
						FROM	$pi_table
					^if($poll_id ne "all"){
						WHERE	poll_id = '^poll_id.int(0)'
					}
				}}]
		}
		^case[answers]{$result[^connect[$connect_string]{^table::sql{
						SELECT
							answer_id,
							poll_id,
							answer,
							vote_count
						FROM	$pa_table
					^if($poll_id ne "all"){
						WHERE	poll_id = '^poll_id.int(0)'
					}
				}}]
		}
		^case[DEFAULT]{$result[]}
	}
}{
	$result[]
}
######## end of @extract[] method ############

@last_insert_id[default][default]
$result[^connect[$connect_string]{^string:sql{SELECT MAX(poll_id) FROM $pi_table}[$.default{$default}]}] 
######## end of @last_insert_id[] method ########

##############################################
## parameters hash checker
@check_params[params;method][params;method]
^if(!def $params || !($params is hash)){
	^throw[parser.runtime;poll;Defined none of parameters while calling <b>^#40$method[]</b> method]
}
######## end of @check_params[] method #######

#######################################
## poll xml code generator
@printPoll[params;action][params;action]
^try{
## code generating
	^params.foreach[p_id;poll]{
	     <poll id="$p_id" status="$poll.status" type="$poll.type" default="$poll.default_value" restricted="$poll.restricted">
		<question>$poll.question</question>
		<${action}s total="$poll.total">
		^poll.answers.foreach[a_id;answer]{
			<${action}id="$a_id" vote_count="$answer.vote_count">
				$answer.answer
			</$action>
		}
		</${action}s>
		<date started="$poll.dt_started" closed="$poll.dt_ended" />
		<form path="$poll.path_param" action="$request:uri" button="$poll.button_text" />
	     </poll>
	}
}{
	^throw[parser.compile;poll;printPoll method compiling error.Check your parameters]
}
######## end of @printPoll[] method ###

#######################################
## poll xml xslt transformator
@transform[xslt_file;xml_code][xslt_file;xml_code;document;transformedDoc]
$document[^xdoc::create{<?xml version="1.0" encoding="$response:charset"?> 
<document>
	^untaint{$xml_code}
</document>}] 
$transformedDoc[^document.transform[$xslt_file]]
^transformedDoc.string[
		$.method[html]
		]
######## end of @transform[] method ###
Есть show_poll.xslt
<?xml version="1.0" encoding="windows-1254"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="document">
        	<xsl:apply-templates select="poll" />
    </xsl:template>
    
    <xsl:template match="poll">
        <table border="0" cellpadding="3" cellspacing="0">
	<tr><td><b><xsl:value-of select="question" /></b></td></tr>
	<tr><td align="center">
		<xsl:if test="@restricted = 'yes'">
			<font color="red">Daha цnce oy verdiрiniz iзin oyunuz kabul edilmedi</font>
        	</xsl:if>
		<xsl:apply-templates select="answers" />
		<xsl:apply-templates select="results" />
	</td></tr></table>
    </xsl:template>
    
    <xsl:template match="answers">
    	<form name="poll_{//form/@id}" method="post" action="{//form/@action}">
	<table border="0" width="90%">
	<xsl:for-each select="answer">
	    	<tr><td>
	    	<xsl:element name="input">
    			<xsl:attribute name="id">answer_<xsl:value-of select="@id" /></xsl:attribute>
    			<xsl:attribute name="type"><xsl:value-of select="//poll/@type" /></xsl:attribute>
    			<xsl:attribute name="class"><xsl:value-of select="//poll/@type" /></xsl:attribute>
    			<xsl:attribute name="name"><xsl:value-of select="//form/@path" /></xsl:attribute>
    			<xsl:attribute name="value"><xsl:value-of select="@id" /></xsl:attribute>
			<xsl:if test="position()=//poll/@default"> 
				<xsl:attribute name="checked">checked</xsl:attribute>
        		</xsl:if>
       		</xsl:element>
		<label for="answer_{@id}"><xsl:value-of select="." /></label>
		</td></tr>
	</xsl:for-each>
	</table>
	<br />
	<input type="submit" name="request" value="{//form/@button}" />
	</form>
    </xsl:template>
    
    <xsl:template match="results">
    	<table border="0" width="95%">
		<tr><td>
		<xsl:for-each select="result">
			<xsl:value-of select="." />
			<xsl:variable name="total">
				<xsl:value-of select="//results/@total" />
			</xsl:variable>
			<xsl:variable name="vote">
				<xsl:value-of select="@vote_count" />
			</xsl:variable>
			<br />
			<img src="/i/bar.gif" align="absmiddle" width="{format-number($vote*70 div $total,'#.')}" height="8" />
			<xsl:text> </xsl:text>
			<xsl:value-of select="@vote_count" />
			<xsl:text> </xsl:text>(<xsl:value-of select="format-number($vote*100 div $total,'#.#')" />%)
			<hr size="1" />
		</xsl:for-each>
		</td></tr>
	</table>
	<font size="-2">anket <xsl:value-of select="//date/@started" /> tarihinde baюladэ</font>
    </xsl:template>
    
    
</xsl:stylesheet>
Есть show_skin.xslt
<?xml version="1.0" encoding="windows-1251"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="document">
    	<style type="text/css">
		input {height:20; font:8pt Tahoma;}
	</style>
    	<div style="border:1 #CCCCCC solid; padding:5; width:200">
        	<xsl:apply-templates select="poll" />
    	</div>
    </xsl:template>
    
    <xsl:template match="poll">
        <table border="0" width="200" cellpadding="3" cellspacing="0">
	<tr><td><b><xsl:value-of select="question" /></b></td></tr>
	<tr><td align="center">
		<xsl:if test="@restricted = 'yes'">
			<font color="red">Ваш голос не был принят, т. к. вы уже голосовали</font>
        	</xsl:if>
		<xsl:apply-templates select="answers" />
		<xsl:apply-templates select="results" />
	</td></tr></table>
    </xsl:template>
    
    <xsl:template match="answers">
    	<form name="poll_{//form/@id}" method="post" action="{//form/@action}">
	<table border="0" width="90%">
	<xsl:for-each select="answer">
	    	<tr><td>
	    	<xsl:element name="input">
    			<xsl:attribute name="id">answer_<xsl:value-of select="@id" /></xsl:attribute>
    			<xsl:attribute name="type"><xsl:value-of select="//poll/@type" /></xsl:attribute>
    			<xsl:attribute name="name"><xsl:value-of select="//form/@path" /></xsl:attribute>
    			<xsl:attribute name="value"><xsl:value-of select="@id" /></xsl:attribute>
			<xsl:if test="position()=//poll/@default"> 
				<xsl:attribute name="checked">checked</xsl:attribute>
        		</xsl:if>
       		</xsl:element>
		<label for="answer_{@id}"><xsl:value-of select="." /></label>
		</td></tr>
	</xsl:for-each>
	</table>
	<br />
	<input type="submit" name="request" value="{//form/@button}" />
	</form>
    </xsl:template>
    
    <xsl:template match="results">
    	<table border="0" width="90%">
		<tr><td>
		<xsl:for-each select="result">
			<xsl:value-of select="." />
			<xsl:variable name="total">
				<xsl:value-of select="//results/@total" />
			</xsl:variable>
			<xsl:variable name="vote">
				<xsl:value-of select="@vote_count" />
			</xsl:variable>
			<br />
			<img src="bar.gif" align="absmiddle" width="{format-number($vote*100 div $total,'#.')}" height="8" />
			<xsl:text> </xsl:text>
			<xsl:value-of select="@vote_count" />
			<xsl:text> </xsl:text>(<xsl:value-of select="format-number($vote*100 div $total,'#.##')" /> %)
			<hr size="1" />
		</xsl:for-each>
		</td></tr>
	</table>
	<font size="-2">опрос ведется с <xsl:value-of select="//date/@started" /></font>
    </xsl:template>
    
    
</xsl:stylesheet>
Есть poll_extra.p
## poll adder form
@add[params][params;new_poll]
## parameters checking
^check_params[$params;add]
## request checking
^if(def $params.request && $params.request is hash && def $params.request.answer){
## poll hash creating
	$new_poll[^hash::create[]]
## extracting new poll info
	$new_poll.question[$params.request.question.field]
	$new_poll.type[$params.request.type.field]
	$new_poll.status[$params.request.status.field]
	$new_poll.button_text[$params.request.button_text.field]
## extracting answers
	^if(def $params.request.answer && $params.request.answer is table){
		$new_poll.answers[^hash::create[]]
		^params.request.answer.menu{
			$id[^params.request.answer.line[]]
			^params.request.vote_count.offset[set](^params.request.answer.offset[])
			$new_poll.answers.$id[
					$.answer[$params.request.answer.field]
					$.vote_count[$params.request.vote_count.field]
					]
		}
	}
## calling poll creator
	^run[$new_poll]
}{
## processing poll skin
	^wear[$params.skin;adding]
}
######## end of @add[] method ################

#######################################
## edit form
@edit[params][params;poll_id;id;update_hash]
## parameters checking
^check_params[$params;edit]
## request checking
^if(def $params.request && $params.request is hash && def $params.request.exist_answer && $params.request.exist_answer is table){
## creating update hash
	$update_hash[^hash::create[]]
## extracting poll info from form	
	$update_hash.poll_id[$params.request.poll_id.field]
	$update_hash.question[$params.request.question.field]
	$update_hash.type[$params.request.type.field]
	$update_hash.status[$params.request.status.field]
	$update_hash.answers[^hash::create[]]
	$update_hash.button_text[$params.request.button_text.field]
## extracting answers
	^if($params.request.answer is table && $params.request.exist_answer is table){
		^if($params.request.answer > $params.request.exist_answer){
## detecting answers to update or add
			^params.request.answer.menu{
				^if(^params.request.answer.line[] > $params.request.exist_answer){
					$id[new_^params.request.answer.line[]]
				}{
					^params.request.exist_answer.offset[set](^params.request.answer.offset[])
					$id[$params.request.exist_answer.field]
				}
				^params.request.vote_count.offset[set](^params.request.answer.offset[])
				$update_hash.answers.$id[
							$.answer[$params.request.answer.field]
							$.vote_count[$params.request.vote_count.field]
							]
			}
		}{
## detecting answers to update or delete
			^params.request.exist_answer.menu{
				^if(^params.request.exist_answer.line[] > $params.request.answer){
					$id[delete_^params.request.exist_answer.line[]]
					$answer[$params.request.exist_answer.field]
				}{
					^params.request.answer.offset[set](^params.request.exist_answer.offset[])
					$id[$params.request.exist_answer.field]
					$answer[$params.request.answer.field]
				}
				^params.request.vote_count.offset[set](^params.request.exist_answer.offset[])
				$update_hash.answers.$id[
							$.answer[$answer]
							$.vote_count[$params.request.vote_count.field]
							]
			}
		}
	}
## calling poll updater
	^update[$update_hash]
}{
## detecting poll_id
	$poll_id(^params.poll_id.int(0))
	$poll_info[^extract[$poll_id;info]]
	$poll_answers[^extract[$poll_id;answers]]
## processing poll skin
	^wear[$params.skin;editing]
}
######## end of @edit[] method ########

##############################################
## skin viewer
@wear[skin;method][skin;fd;method]
^try{
	^if(-f $skin){
		$fd[^file::load[text;$skin]]
		^process{^taint[as-is][$fd.text]}
	}{
		^throw[parser.runtime;poll;Polls $method skin not found]
	}
}{
	^throw[parser.compile;poll;Skin compiling error. Check your $method skin code]
}
######## end of @wear[] method ###############