コード例 #1
0
	/**
	 * Add string part to value of current last option
	 * @param  $token  string current value of token between pipe separators
	 * Also, _optionally_ parses xml-like attributes (when these are found in category definition)
	 */
	function addToLastOption( $token ) {
		$matches = array();
		if ( $this->type === 'text' ) {
			# first entry of "category type text" might contain current category
			# xml-like attributes
			if ( count( $this->input_options ) === 1 &&
				preg_match( '`^::\s*(.+)$`', $token, $matches ) ) {
				# note that hasAttributes is always true regardless the attributes are used or not,
				# because it is checked in $this->addEmptyOption()
				$this->hasAttributes = true;
				# parse attributes string
				$option_attributes = qp_Setup::getXmlLikeAttributes( $matches[1], array( 'width', 'height', 'sorting', 'multiple' ) );
				# apply attributes to current option
				foreach ( $option_attributes as $attr_name => $attr_val ) {
					$this->attributes[$attr_name] = $attr_val;
				}
				return;
			}
		} elseif ( $this->type === 'checkbox' ) {
			if ( $token !== '' ) {
				# checkbox type of categories do not contain text values,
				# only xml-like attributes
				$option_attributes = qp_Setup::getXmlLikeAttributes( $token, array( 'checked' ) );
				# apply attributes to current option
				foreach ( $option_attributes as $attr_name => $attr_val ) {
					$this->attributes[$attr_name] = $attr_val;
				}
			}
		}
		# add new input option
		$this->iopt_last .= $token;
	}
コード例 #2
0
	/**
	 * Get proposal attributes from raw proposal text (source page text or DB field)
	 *
	 * @param  $proposal_text  string  raw proposal text
	 */
	public function getFromSource( $proposal_text ) {
		# set default values of properties
		$this->error = 0;
		$this->name = '';
		$this->dbText =
		$this->catreq = null;
		$this->emptytext = null;
		$this->cpdef = $proposal_text;
		$matches = array();
		# try to match the raw proposal name (without specific attributes)
		preg_match( '/^:\|\s*(.+?)\s*\|\s*(.+?)\s*$/su', $this->cpdef, $matches );
		if ( count( $matches ) < 3 ||
				( $this->name = $matches[1] ) === '' ) {
			# raw proposal name is not defined or empty
			return;
		}
		# check, whether raw proposal name will fit into the corresponding DB field
		if ( strlen( $this->getAttrDef() ) >= qp_Setup::$field_max_len['proposal_text'] ) {
			$this->setError( 'qp_error_too_long_proposal_name' );
			return;
		}
		# try to get xml-like attributes;
		$paramkeys = qp_Setup::getXmlLikeAttributes( $this->name, array( 'name', 'catreq', 'emptytext' ) );
		if ( $paramkeys['name'] !== null ) {
			# name attribute found
			$this->name = trim( $paramkeys['name'] );
		}
		if ( $paramkeys['catreq'] !== null ) {
			$this->catreq = self::getSaneCatReq( $paramkeys['catreq'] );
		}
		if ( $paramkeys['emptytext'] !== null ) {
			$this->emptytext = self::getSaneEmptyText( $paramkeys['emptytext'] );
		}
		if ( is_numeric( $this->name ) ) {
			$this->setError( 'qp_error_numeric_proposal_name' );
			return;
		} elseif ( preg_match( '/$.^/msu', $this->name ) ) {
			$this->setError( 'qp_error_multiline_proposal_name' );
			return;
		}
		# remove raw proposal name from proposal definition
		$this->cpdef = $matches[2];
	}
コード例 #3
0
	/**
	 * Parses attribute line of the question
	 * @param    $attr_str  attribute string from questions header
	 * @modifies $paramkeys  array  key is attribute regexp, value is the value of attribute
	 * @return   string  the value of question's type attribute
	 */
	function getQuestionAttributes( $attr_str, array &$paramkeys ) {
		$paramkeys = qp_Setup::getXmlLikeAttributes( $attr_str, $this->questionAttributeKeys );
		# apply default questions attributes from poll definition, if there is any
		foreach ( $this->defaultQuestionAttributes as $attr => $val ) {
			if ( $paramkeys[$attr] === null ) {
				$paramkeys[$attr] = $val;
			}
		}
		return isset( $paramkeys[ 't[yi]p[eo]' ] ) ? trim( $paramkeys[ 't[yi]p[eo]' ] ) : '';
	}