$intro = ''; } if (empty($ur_here)) { $ur_here = $_LANG['search_goods']; } /*------------------------------------------------------ */ //-- 属性检索 /*------------------------------------------------------ */ $attr_in = ''; $attr_num = 0; $attr_url = ''; $attr_arg = array(); if (!empty($_REQUEST['attr'])) { $sql = "SELECT goods_id, COUNT(*) AS num FROM " . $ecs->table("goods_attr") . " WHERE 0 "; foreach ($_REQUEST['attr'] as $key => $val) { if (is_not_null($val)) { $attr_num++; $sql .= " OR (1 "; if (is_array($val)) { $sql .= " AND attr_id = '{$key}'"; if (!empty($val['from'])) { $sql .= is_numeric($val['from']) ? " AND attr_value >= " . floatval($val['from']) : " AND attr_value >= '{$val['from']}'"; $attr_arg["attr[{$key}][from]"] = $val['from']; $attr_url .= "&attr[{$key}][from]={$val['from']}"; } if (!empty($val['to'])) { $sql .= is_numeric($val['to']) ? " AND attr_value <= " . floatval($val['to']) : " AND attr_value <= '{$val['to']}'"; $attr_arg["attr[{$key}][to]"] = $val['to']; $attr_url .= "&attr[{$key}][to]={$val['to']}"; } } else {
$intro = ''; } if (empty($ur_here)) { $ur_here = $_LANG['search_goods']; } /*------------------------------------------------------ */ //-- 属性检索 /*------------------------------------------------------ */ $attr_in = ''; $attr_num = 0; $attr_url = ''; $attr_arg = array(); if (!empty($_REQUEST['attr'])) { $sql = "SELECT goods_id, COUNT(*) AS num FROM " . $ecs->table("goods_attr") . " WHERE 0 "; foreach ($_REQUEST['attr'] as $key => $val) { if (is_not_null($val) && is_numeric($key)) { $attr_num++; $sql .= " OR (1 "; if (is_array($val)) { $sql .= " AND attr_id = '{$key}'"; if (!empty($val['from'])) { $sql .= is_numeric($val['from']) ? " AND attr_value >= " . floatval($val['from']) : " AND attr_value >= '{$val['from']}'"; $attr_arg["attr[{$key}][from]"] = $val['from']; $attr_url .= "&attr[{$key}][from]={$val['from']}"; } if (!empty($val['to'])) { $sql .= is_numeric($val['to']) ? " AND attr_value <= " . floatval($val['to']) : " AND attr_value <= '{$val['to']}'"; $attr_arg["attr[{$key}][to]"] = $val['to']; $attr_url .= "&attr[{$key}][to]={$val['to']}"; } } else {
/** * Converts an associative array into a string of well-formed attributes * * @note usually for HTML, but could be useful for XML too... * * @param array $attrs An associative array of attr => val pairs * * @return string HTML attributes to be inserted into a tag (e.g., <tag $attrs>) */ function elgg_format_attributes(array $attrs) { $attrs = elgg_clean_vars($attrs); $attributes = array(); if (isset($attrs['js'])) { //@todo deprecated notice? if (!empty($attrs['js'])) { $attributes[] = $attrs['js']; } unset($attrs['js']); } foreach ($attrs as $attr => $val) { $attr = strtolower($attr); if ($val === TRUE) { $val = $attr; //e.g. checked => TRUE ==> checked="checked" } // ignore $vars['entity'] => ElggEntity stuff if (is_not_null($val) && (is_array($val) || !is_object($var))) { // allow $vars['class'] => array('one', 'two'); // @todo what about $vars['style']? Needs to be semi-colon separated... if (is_array($val)) { $val = implode(' ', $val); } $val = htmlspecialchars($val, ENT_QUOTES, 'UTF-8', false); $attributes[] = "{$attr}=\"{$val}\""; } } return implode(' ', $attributes); }
function ensure($name, $value, $fn, $class = null, $method = null) { if (!is_callable($fn)) { throw new InvalidArgumentException("#ensure: Given callback is not callable: " . sdump($fn)); } if (!is_a_string($name)) { throw new InvalidArgumentException("#ensure: Given argument name is not a string: " . sdump($fn)); } // TODO: Contract for $value if (is_not_null($class) && is_null($method)) { $method = $class; $class = null; } if (!$fn($value)) { throw new InvalidArgumentException("{$class}#{$method}: {$name} does not comply argument contract " . sdump($fn) . ": " . sdump($value) . ')'); } }
function build_message($params = '') { if ($params == '') { $params = array(); } if (count($params) > 0) { reset($params); while (list($key, $value) = each($params)) { $this->build_params[$key] = $value; } } if (is_not_null($this->html_images)) { reset($this->html_images); while (list(, $value) = each($this->html_images)) { $this->html = str_replace($value['name'], 'cid:' . $value['cid'], $this->html); } } $null = NULL; $attachments = is_not_null($this->attachments) ? true : false; $html_images = is_not_null($this->html_images) ? true : false; $html = is_not_null($this->html) ? true : false; $text = is_not_null($this->text) ? true : false; switch (true) { case $text == true && $attachments == false: /* HPDL PHP3 */ // $message =& $this->add_text_part($null, $this->text); $message = $this->add_text_part($null, $this->text); break; case $text == false && $attachments == true && $html == false: /* HPDL PHP3 */ // $message =& $this->add_mixed_part(); $message = $this->add_mixed_part(); for ($i = 0; $i < count($this->attachments); $i++) { $this->add_attachment_part($message, $this->attachments[$i]); } break; case $text == true && $attachments == true: /* HPDL PHP3 */ // $message =& $this->add_mixed_part(); $message = $this->add_mixed_part(); $this->add_text_part($message, $this->text); for ($i = 0; $i < count($this->attachments); $i++) { $this->add_attachment_part($message, $this->attachments[$i]); } break; case $html == true && $attachments == false && $html_images == false: if (is_not_null($this->html_text)) { /* HPDL PHP3 */ // $message =& $this->add_alternative_part($null); $message = $this->add_alternative_part($null); $this->add_text_part($message, $this->html_text); $this->add_html_part($message); } else { /* HPDL PHP3 */ // $message =& $this->add_html_part($null); $message = $this->add_html_part($null); } break; case $html == true && $attachments == false && $html_images == true: if (is_not_null($this->html_text)) { /* HPDL PHP3 */ // $message =& $this->add_alternative_part($null); $message = $this->add_alternative_part($null); $this->add_text_part($message, $this->html_text); /* HPDL PHP3 */ // $related =& $this->add_related_part($message); $related = $this->add_related_part($message); } else { /* HPDL PHP3 */ // $message =& $this->add_related_part($null); // $related =& $message; $message = $this->add_related_part($null); $related = $message; } $this->add_html_part($related); for ($i = 0; $i < count($this->html_images); $i++) { $this->add_html_image_part($related, $this->html_images[$i]); } break; case $html == true && $attachments == true && $html_images == false: /* HPDL PHP3 */ // $message =& $this->add_mixed_part(); $message = $this->add_mixed_part(); if (is_not_null($this->html_text)) { /* HPDL PHP3 */ // $alt =& $this->add_alternative_part($message); $alt = $this->add_alternative_part($message); $this->add_text_part($alt, $this->html_text); $this->add_html_part($alt); } else { $this->add_html_part($message); } for ($i = 0; $i < count($this->attachments); $i++) { $this->add_attachment_part($message, $this->attachments[$i]); } break; case $html == true && $attachments == true && $html_images == true: /* HPDL PHP3 */ // $message =& $this->add_mixed_part(); $message = $this->add_mixed_part(); if (is_not_null($this->html_text)) { /* HPDL PHP3 */ // $alt =& $this->add_alternative_part($message); $alt = $this->add_alternative_part($message); $this->add_text_part($alt, $this->html_text); /* HPDL PHP3 */ // $rel =& $this->add_related_part($alt); $rel = $this->add_related_part($alt); } else { /* HPDL PHP3 */ // $rel =& $this->add_related_part($message); $rel = $this->add_related_part($message); } $this->add_html_part($rel); for ($i = 0; $i < count($this->html_images); $i++) { $this->add_html_image_part($rel, $this->html_images[$i]); } for ($i = 0; $i < count($this->attachments); $i++) { $this->add_attachment_part($message, $this->attachments[$i]); } break; } if (isset($message) && is_object($message)) { $output = $message->encode(); $this->output = $output['body']; reset($output['headers']); while (list($key, $value) = each($output['headers'])) { $headers[] = $key . ': ' . $value; } $this->headers = array_merge($this->headers, $headers); return true; } else { return false; } }
public function trimF($characters = null) { if (is_not_null($characters)) { ensure('Argument', $characters, 'is_a_string', __CLASS__, __METHOD__); } if (null !== $characters) { $this->string = trim($this->string, $characters); } else { $this->string = trim($this->string); } return $this; }