html.php

来自「j2me is based on j2mepolish, client & se」· PHP 代码 · 共 1,235 行 · 第 1/3 页

PHP
1,235
字号
		}		if (!isset($htmlAttributes['type'])) {			$htmlAttributes['type'] = 'text';		}		if (!isset($htmlAttributes['id'])) {			$htmlAttributes['id'] = $this->model . Inflector::camelize($this->field);		}		if ($this->tagIsInvalid($this->model, $this->field)) {			if (isset($htmlAttributes['class']) && trim($htmlAttributes['class']) != "") {				$htmlAttributes['class'] .= ' form_error';			} else {				$htmlAttributes['class'] = 'form_error';			}		}		return $this->output(sprintf($this->tags['input'], $this->model, $this->field, $this->_parseAttributes($htmlAttributes, null, ' ', ' ')), $return);	} /** * Returns a formatted SELECT element. * * @param string $fieldName Name attribute of the SELECT * @param array $optionElements Array of the OPTION elements (as 'value'=>'Text' pairs) to be used in the SELECT element * @param mixed $selected Selected option * @param array $selectAttr Array of HTML options for the opening SELECT element * @param array $optionAttr Array of HTML options for the enclosed OPTION elements * @param boolean $show_empty If true, the empty select option is shown * @param  boolean $return         Whether this method should return a value * @return string Formatted SELECT element * @access public */	function selectTag($fieldName, $optionElements, $selected = null, $selectAttr = array(), $optionAttr = null, $showEmpty = true, $return = false) {		$this->setFormTag($fieldName);		if ($this->tagIsInvalid($this->model, $this->field)) {			if (isset($selectAttr['class']) && trim($selectAttr['class']) != "") {				$selectAttr['class'] .= ' form_error';			} else {				$selectAttr['class'] = 'form_error';			}		}		if (!isset($selectAttr['id'])) {			$selectAttr['id'] = $this->model . Inflector::camelize($this->field);		}		if (!is_array($optionElements)) {			return null;		}		if (!isset($selected)) {			$selected = $this->tagValue($fieldName);		}		if (isset($selectAttr) && array_key_exists("multiple", $selectAttr)) {			$select[] = sprintf($this->tags['selectmultiplestart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));		} else {			$select[] = sprintf($this->tags['selectstart'], $this->model, $this->field, $this->parseHtmlOptions($selectAttr));		}		if ($showEmpty == true) {			$select[] = sprintf($this->tags['selectempty'], $this->parseHtmlOptions($optionAttr));		}		foreach($optionElements as $name => $title) {			$optionsHere = $optionAttr;			if (($selected != null) && ($selected == $name)) {				$optionsHere['selected'] = 'selected';			} else if(is_array($selected) && in_array($name, $selected)) {				$optionsHere['selected'] = 'selected';			}			$select[] = sprintf($this->tags['selectoption'], $name, $this->parseHtmlOptions($optionsHere), h($title));		}		$select[] = sprintf($this->tags['selectend']);		return $this->output(implode("\n", $select), $return);	}/** * Creates a set of radio widgets. * * @param  string  $fieldName Name of a field, like this "Modelname/fieldname" * @param  array	$options			Radio button options array * @param  array	$inbetween		String that separates the radio buttons. * @param  array	$htmlAttributes Array of HTML attributes. * @param  boolean $return	Wheter this method should return a value or output it. This overrides AUTO_OUTPUT. * @return mixed	Either string or echos the value, depends on AUTO_OUTPUT and $return. * @access public */	function radio($fieldName, $options, $inbetween = null, $htmlAttributes = array(), $return = false) {		$this->setFormTag($fieldName);		$value = isset($htmlAttributes['value']) ? $htmlAttributes['value'] : $this->tagValue($fieldName);		$out = array();		foreach($options as $optValue => $optTitle) {			$optionsHere = array('value' => $optValue);			$optValue == $value ? $optionsHere['checked'] = 'checked' : null;			$parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' ');			$individualTagName = "{$this->field}_{$optValue}";			$out[] = sprintf($this->tags['radio'], $this->model, $this->field, $individualTagName, $parsedOptions, $optTitle);		}		$out = join($inbetween, $out);		return $this->output($out ? $out : null, $return);	}/** * Returns a SELECT element for days. * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @param boolean $showEmpty Show/hide the empty select option * @return mixed * @access public */	function dayOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && $this->tagValue($tagName)) {			$selected = date('d', strtotime($this->tagValue($tagName)));		}		$dayValue = empty($selected) ? ($showEmpty == true ? NULL : date('d')) : $selected;		$days = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23', '24' => '24', '25' => '25', '26' => '26', '27' => '27', '28' => '28', '29' => '29', '30' => '30', '31' => '31');		$option = $this->selectTag($tagName . "_day", $days, $dayValue, $selectAttr, $optionAttr, $showEmpty);		return $option;	}/** * Returns a SELECT element for years * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param integer $minYear First year in sequence * @param integer $maxYear Last year in sequence * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @param boolean $showEmpty Show/hide the empty select option * @return mixed * @access public */	function yearOptionTag($tagName, $value = null, $minYear = null, $maxYear = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && ($this->tagValue($tagName))) {			$selected = date('Y', strtotime($this->tagValue($tagName)));		}		$yearValue = empty($selected) ? ($showEmpty ? NULL : date('Y')) : $selected;		$currentYear = date('Y');		$maxYear = is_null($maxYear) ? $currentYear + 11 : $maxYear + 1;		$minYear = is_null($minYear) ? $currentYear - 60 : $minYear;		if ($minYear > $maxYear) {			$tmpYear = $minYear;			$minYear = $maxYear;			$maxYear = $tmpYear;		}		$minYear = $currentYear < $minYear ? $currentYear : $minYear;		$maxYear = $currentYear > $maxYear ? $currentYear : $maxYear;		for($yearCounter = $minYear; $yearCounter < $maxYear; $yearCounter++) {			$years[$yearCounter] = $yearCounter;		}		return $this->selectTag($tagName . "_year", $years, $yearValue, $selectAttr, $optionAttr, $showEmpty);	}/** * Returns a SELECT element for months. * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @param boolean $showEmpty Show/hide the empty select option * @return mixed * @access public */	function monthOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && ($this->tagValue($tagName))) {			$selected = date('m', strtotime($this->tagValue($tagName)));		}		$monthValue = empty($selected) ? ($showEmpty ? NULL : date('m')) : $selected;		$months = array('01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December');		return $this->selectTag($tagName . "_month", $months, $monthValue, $selectAttr, $optionAttr, $showEmpty);	}/** * Returns a SELECT element for hours. * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param boolean $format24Hours True for 24 hours format * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @return mixed * @access public */	function hourOptionTag($tagName, $value = null, $format24Hours = false, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && ($this->tagValue($tagName))) {			if ($format24Hours) {				$selected = date('H', strtotime($this->tagValue($tagName)));			} else {				$selected = date('g', strtotime($this->tagValue($tagName)));			}		}		if ($format24Hours) {			$hourValue = empty($selected) ? ($showEmpty ? NULL : date('H')) : $selected;		} else {			$hourValue = empty($selected) ? ($showEmpty ? NULL : date('g')) : $selected;			if (isset($selected) && intval($hourValue) == 0 && !$showEmpty) {				$hourValue = 12;			}		}		if ($format24Hours) {			$hours = array('00' => '00', '01' => '01', '02' => '02', '03' => '03', '04' => '04', '05' => '05', '06' => '06', '07' => '07', '08' => '08', '09' => '09', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20', '21' => '21', '22' => '22', '23' => '23');		} else {			$hours = array('01' => '1', '02' => '2', '03' => '3', '04' => '4', '05' => '5', '06' => '6', '07' => '7', '08' => '8', '09' => '9', '10' => '10', '11' => '11', '12' => '12');		}		$option = $this->selectTag($tagName . "_hour", $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);		return $option;	}/** * Returns a SELECT element for minutes. * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @return mixed * @access public */	function minuteOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && ($this->tagValue($tagName))) {			$selected = date('i', strtotime($this->tagValue($tagName)));		}		$minValue = empty($selected) ? ($showEmpty ? NULL : date('i')) : $selected;		for($minCount = 0; $minCount < 60; $minCount++) {			$mins[sprintf('%02d', $minCount)] = sprintf('%02d', $minCount);		}		$option = $this->selectTag($tagName . "_min", $mins, $minValue, $selectAttr, $optionAttr, $showEmpty);		return $option;	}/** * Returns a SELECT element for AM or PM. * * @param string $tagName Prefix name for the SELECT element * @deprecated  string $value * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @return mixed * @access public */	function meridianOptionTag($tagName, $value = null, $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		if (empty($selected) && ($this->tagValue($tagName))) {			$selected = date('a', strtotime($this->tagValue($tagName)));		}		$merValue = empty($selected) ? ($showEmpty ? NULL : date('a')) : $selected;		$meridians = array('am' => 'am', 'pm' => 'pm');		$option = $this->selectTag($tagName . "_meridian", $meridians, $merValue, $selectAttr, $optionAttr, $showEmpty);		return $option;	}/** * Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time. * * @param string $tagName Prefix name for the SELECT element * @param string $dateFormat DMY, MDY, YMD or NONE. * @param string $timeFormat 12, 24, NONE * @param string $selected Option which is selected. * @param array $optionAttr Attribute array for the option elements. * @return string The HTML formatted OPTION element * @access public */	function dateTimeOptionTag($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $selectAttr = null, $optionAttr = null, $showEmpty = true) {		$day      = null;		$month    = null;		$year     = null;		$hour     = null;		$min      = null;		$meridian = null;		if (empty($selected)) {			$selected = $this->tagValue($tagName);		}		if (!empty($selected)) {			if (is_int($selected)) {				$selected = strftime('%Y-%m-%d %H:%M:%S', $selected);			}			$meridian = 'am';			$pos = strpos($selected, '-');			if($pos !== false){				$date = explode('-', $selected);				$days = explode(' ', $date[2]);				$day = $days[0];				$month = $date[1];				$year = $date[0];			} else {				$days[1] = $selected;			}			if ($timeFormat != 'NONE' && !empty($timeFormat)) {				$time = explode(':', $days[1]);				if (($time[0] > 12) && $timeFormat == '12') {					$time[0] = $time[0] - 12;					$meridian = 'pm';				} elseif($time[0] > 12) {					$meridian = 'pm';				}				$hour = $time[0];				$min = $time[1];			}		}		$elements = array('Day','Month','Year','Hour','Minute','Meridian');		if (isset($selectAttr['id'])) {			if (is_string($selectAttr['id'])) {				// build out an array version				foreach ($elements as $element) {					$selectAttrName = 'select' . $element . 'Attr';					${$selectAttrName} = $selectAttr;					${$selectAttrName}['id'] = $selectAttr['id'] . $element;				}			} elseif (is_array($selectAttr['id'])) {				// check for missing ones and build selectAttr for each element				foreach ($elements as $element) {					$selectAttrName = 'select' . $element . 'Attr';					${$selectAttrName} = $selectAttr;					${$selectAttrName}['id'] = $selectAttr['id'][strtolower($element)];				}			}		} else {			// build the selectAttrName with empty id's to pass			foreach ($elements as $element) {				$selectAttrName = 'select' . $element . 'Attr';				${$selectAttrName} = $selectAttr;			}		}		switch($dateFormat) {			case 'DMY': // so uses the new selex				$opt = $this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' .				$this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);			break;			case 'MDY':				$opt = $this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .				$this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty) . '-' . $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty);			break;			case 'YMD':				$opt = $this->yearOptionTag($tagName, null, null, null, $year, $selectYearAttr, $optionAttr, $showEmpty) . '-' .				$this->monthOptionTag($tagName, null, $month, $selectMonthAttr, $optionAttr, $showEmpty) . '-' .				$this->dayOptionTag($tagName, null, $day, $selectDayAttr, $optionAttr, $showEmpty);			break;			case 'Y':				$opt = $this->yearOptionTag($tagName, null, null, null, $selected, $selectYearAttr, $optionAttr, $showEmpty);			break;			case 'NONE':			default:				$opt = '';			break;		}		switch($timeFormat) {			case '24':				$opt .= $this->hourOptionTag($tagName, null, true, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .				$this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty);			break;			case '12':				$opt .= $this->hourOptionTag($tagName, null, false, $hour, $selectHourAttr, $optionAttr, $showEmpty) . ':' .				$this->minuteOptionTag($tagName, null, $min, $selectMinuteAttr, $optionAttr, $showEmpty) . ' ' .				$this->meridianOptionTag($tagName, null, $meridian, $selectMeridianAttr, $optionAttr, $showEmpty);			break;			case 'NONE':			default:				$opt .= '';			break;		}		return $opt;	}/** * Returns a row of formatted and named TABLE headers. * * @param array $names		Array of tablenames. * @param array $trOptions	HTML options for TR elements. * @param array $thOptions	HTML options for TH elements. * @param  boolean $return	Wheter this method should return a value * @return string * @access public */	function tableHeaders($names, $trOptions = null, $thOptions = null, $return = false) {		$out = array();		foreach($names as $arg) {			$out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg);		}		$data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out));		return $this->output($data, $return);	}/** * Returns a formatted string of table rows (TR's with TD's in them). * * @param array $data		Array of table data * @param array $oddTrOptionsHTML options for odd TR elements * @param array $evenTrOptionsHTML options for even TR elements * @param  boolean $return	Wheter this method should return a value * @return string	Formatted HTML

⌨️ 快捷键说明

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