📄 storage.php
字号:
* @param mixed $contents * @param mixed $attributes Associative array or string of table row attributes * @access public */ function setHeaderContents($row, $col, $contents, $attributes = null) { $this->setCellContents($row, $col, $contents, 'TH'); if (!is_null($attributes)) { $this->updateCellAttributes($row, $col, $attributes); } } /** * Adds a table row and returns the row identifier * @param array $contents (optional) Must be a indexed array of valid cell contents * @param mixed $attributes (optional) Associative array or string of table row attributes * This can also be an array of attributes, in which case the attributes * will be repeated in a loop. * @param string $type (optional) Cell type either 'th' or 'td' * @param bool $inTR false if attributes are to be applied in TD tags * true if attributes are to be applied in TR tag * @return int * @access public */ function addRow($contents = null, $attributes = null, $type = 'td', $inTR = false) { if (isset($contents) && !is_array($contents)) { return PEAR::raiseError('First parameter to HTML_Table::addRow must be an array'); } if (is_null($contents)) { $contents = array(); } $type = strtolower($type); $row = $this->_rows++; foreach ($contents as $col => $content) { if ($type == 'td') { $this->setCellContents($row, $col, $content); } elseif ($type == 'th') { $this->setHeaderContents($row, $col, $content); } } $this->setRowAttributes($row, $attributes, $inTR); return $row; } /** * Sets the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table row attributes * This can also be an array of attributes, in which case the attributes * will be repeated in a loop. * @param bool $inTR false if attributes are to be applied in TD tags * true if attributes are to be applied in TR tag * @access public * @throws PEAR_Error */ function setRowAttributes($row, $attributes, $inTR = false) { if (!$inTR) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_cols; $i++) { if ($multiAttr) { $this->setCellAttributes($row, $i, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->setCellAttributes($row, $i, $attributes); } } } else { $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, 0, 'setRowAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_structure[$row]['attr'] = $attributes; } } /** * Updates the row attributes for an existing row * @param int $row Row index * @param mixed $attributes Associative array or string of table row attributes * @param bool $inTR false if attributes are to be applied in TD tags * true if attributes are to be applied in TR tag * @access public * @throws PEAR_Error */ function updateRowAttributes($row, $attributes = null, $inTR = false) { if (!$inTR) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_cols; $i++) { if ($multiAttr) { $this->updateCellAttributes($row, $i, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->updateCellAttributes($row, $i, $attributes); } } } else { $attributes = $this->_parseAttributes($attributes); $err = $this->_adjustEnds($row, 0, 'updateRowAttributes', $attributes); if (PEAR::isError($err)) { return $err; } $this->_updateAttrArray($this->_structure[$row]['attr'], $attributes); } } /** * Returns the attributes for a given row as contained in the TR tag * @param int $row Row index * @return array * @access public */ function getRowAttributes($row) { if (isset($this->_structure[$row]['attr'])) { return $this->_structure[$row]['attr']; } return; } /** * Alternates the row attributes starting at $start * @param int $start Row index of row in which alternating begins * @param mixed $attributes1 Associative array or string of table row attributes * @param mixed $attributes2 Associative array or string of table row attributes * @param bool $inTR false if attributes are to be applied in TD tags * true if attributes are to be applied in TR tag * @access public */ function altRowAttributes($start, $attributes1, $attributes2, $inTR = false) { for ($row = $start ; $row < $this->_rows ; $row++) { $attributes = ( ($row + $start) % 2 == 0 ) ? $attributes1 : $attributes2; $this->updateRowAttributes($row, $attributes, $inTR); } } /** * Adds a table column and returns the column identifier * @param array $contents (optional) Must be a indexed array of valid cell contents * @param mixed $attributes (optional) Associative array or string of table row attributes * @param string $type (optional) Cell type either 'th' or 'td' * @return int * @access public */ function addCol($contents = null, $attributes = null, $type = 'td') { if (isset($contents) && !is_array($contents)) { return PEAR::raiseError('First parameter to HTML_Table::addCol must be an array'); } if (is_null($contents)) { $contents = array(); } $type = strtolower($type); $col = $this->_cols++; foreach ($contents as $row => $content) { if ($type == 'td') { $this->setCellContents($row, $col, $content); } elseif ($type == 'th') { $this->setHeaderContents($row, $col, $content); } } $this->setColAttributes($col, $attributes); return $col; } /** * Sets the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or string of table row attributes * @access public */ function setColAttributes($col, $attributes = null) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_rows; $i++) { if ($multiAttr) { $this->setCellAttributes($i, $col, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->setCellAttributes($i, $col, $attributes); } } } /** * Updates the column attributes for an existing column * @param int $col Column index * @param mixed $attributes (optional) Associative array or string of table row attributes * @access public */ function updateColAttributes($col, $attributes = null) { $multiAttr = $this->_isAttributesArray($attributes); for ($i = 0; $i < $this->_rows; $i++) { if ($multiAttr) { $this->updateCellAttributes($i, $col, $attributes[$i - ((ceil(($i + 1) / count($attributes))) - 1) * count($attributes)]); } else { $this->updateCellAttributes($i, $col, $attributes); } } } /** * Sets the attributes for all cells * @param mixed $attributes (optional) Associative array or string of table row attributes * @access public */ function setAllAttributes($attributes = null) { for ($i = 0; $i < $this->_rows; $i++) { $this->setRowAttributes($i, $attributes); } } /** * Updates the attributes for all cells * @param mixed $attributes (optional) Associative array or string of table row attributes * @access public */ function updateAllAttributes($attributes = null) { for ($i = 0; $i < $this->_rows; $i++) { $this->updateRowAttributes($i, $attributes); } } /** * Returns the table rows as HTML * @access public * @return string */ function toHtml($tabs = null, $tab = null) { $strHtml = ''; if (is_null($tabs)) { $tabs = $this->_getTabs(); } if (is_null($tab)) { $tab = $this->_getTab(); } $lnEnd = $this->_getLineEnd(); if ($this->_useTGroups) { $extraTab = $tab; } else { $extraTab = ''; } for ($i = 0 ; $i < $this->_rows ; $i++) { $attr = ''; if (isset($this->_structure[$i]['attr'])) { $attr = $this->_getAttrString($this->_structure[$i]['attr']); } $strHtml .= $tabs .$tab . $extraTab . '<tr'.$attr.'>' . $lnEnd; for ($j = 0 ; $j < $this->_cols ; $j++) { $attr = ''; $contents = ''; $type = 'td'; if (isset($this->_structure[$i][$j]) && $this->_structure[$i][$j] == '__SPANNED__') { continue; } if (isset($this->_structure[$i][$j]['type'])) { $type = (strtolower($this->_structure[$i][$j]['type']) == 'th' ? 'th' : 'td'); } if (isset($this->_structure[$i][$j]['attr'])) { $attr = $this->_structure[$i][$j]['attr']; } if (isset($this->_structure[$i][$j]['contents'])) { $contents = $this->_structure[$i][$j]['contents']; } $strHtml .= $tabs . $tab . $tab . $extraTab . "<$type" . $this->_getAttrString($attr) . '>'; if (is_object($contents)) { // changes indent and line end settings on nested tables if (is_subclass_of($contents, 'html_common')) { $contents->setTab($tab . $extraTab); $contents->setTabOffset($this->_tabOffset + 3); $contents->_nestLevel = $this->_nestLevel + 1; $contents->setLineEnd($this->_getLineEnd()); } if (method_exists($contents, 'toHtml')) { $contents = $contents->toHtml(); } elseif (method_exists($contents, 'toString')) { $contents = $contents->toString(); } } if (is_array($contents)) { $contents = implode(', ', $contents); } if (isset($this->_autoFill) && $contents === '') { $contents = $this->_autoFill; } $strHtml .= $contents; $strHtml .= "</$type>" . $lnEnd; } $strHtml .= $tabs . $tab . $extraTab . '</tr>' . $lnEnd; } return $strHtml; } /** * Checks if rows or columns are spanned * @param int $row Row index * @param int $col Column index * @access private */ function _updateSpanGrid($row, $col) { if (isset($this->_structure[$row][$col]['attr']['colspan'])) { $colspan = $this->_structure[$row][$col]['attr']['colspan']; } if (isset($this->_structure[$row][$col]['attr']['rowspan'])) { $rowspan = $this->_structure[$row][$col]['attr']['rowspan']; } if (isset($colspan)) { for ($j = $col + 1; (($j < $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) { $this->_structure[$row][$j] = '__SPANNED__'; } } if (isset($rowspan)) { for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) { $this->_structure[$i][$col] = '__SPANNED__'; } } if (isset($colspan) && isset($rowspan)) { for ($i = $row + 1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) { for ($j = $col + 1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) { $this->_structure[$i][$j] = '__SPANNED__'; } } } } /** * Adjusts ends (total number of rows and columns) * @param int $row Row index * @param int $col Column index * @param string $method Method name of caller * Used to populate PEAR_Error if thrown. * @param array $attributes Assoc array of attributes * Default is an empty array. * @access private * @throws PEAR_Error */ function _adjustEnds($row, $col, $method, $attributes = array()) { $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1; $rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1; if (($row + $rowspan - 1) >= $this->_rows) { if ($this->_autoGrow) { $this->_rows = $row + $rowspan; } else { return PEAR::raiseError('Invalid table row reference[' . $row . '] in HTML_Table::' . $method); } } if (($col + $colspan - 1) >= $this->_cols) { if ($this->_autoGrow) { $this->_cols = $col + $colspan; } else { return PEAR::raiseError('Invalid table column reference[' . $col . '] in HTML_Table::' . $method); } } } /** * Tells if the parameter is an array of attribute arrays/strings * @param mixed $attributes Variable to test * @access private * @return bool */ function _isAttributesArray($attributes) { if (is_array($attributes) && isset($attributes[0])) { if (is_array($attributes[0]) || (is_string($attributes[0]) && count($attributes) > 1)) { return true; } } return false; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -