function parse_params($text, $params) { if (!empty($params)) { foreach ($params as $k => $v) { if (is_string($v)) { $k = '%' . $k . '%'; $text = strings::str_replace($k, $v, $text); } } } $text = preg_replace('@\\%.*\\%@U', '', $text); return $text; }
function _parse() { $text = $this->_body; if (!is_array($this->_vars)) { $this->_vars = array(); } $this->_vars['time'] = date('d.m.Y H:i'); $return = array(); foreach ($this->_vars as $k => $v) { $return['body'] = strings::str_replace("%{$k}%", $v, $this->_body); $return['subject'] = strings::str_replace("%{$k}%", $v, $this->_subject); } return $return; }
/** translit */ public static function translit($s, $allowed_syms = '') { $translit = array(' ' => '_', ' ' => '_', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'e', 'ж' => 'j', 'з' => 'z', 'и' => 'i', 'й' => 'y', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ъ' => "'", 'ы' => 'i', 'ь' => "'", 'э' => 'е', 'ю' => 'yu', 'я' => 'ya', 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'E', 'Ж' => 'J', 'З' => 'Z', 'И' => 'I', 'Й' => 'Y', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'TS', 'Ч' => 'CH', 'Ш' => 'SH', 'Щ' => 'SCH', 'Ы' => 'I', 'Э' => 'Е', 'Ю' => 'YU', 'Я' => 'YA'); $s = strings::str_replace(array_keys($translit), array_values($translit), $s); $allowed_syms = preg_quote($allowed_syms); $preg_exp = sprintf('~[^a-z\\d_%s]~iU', $allowed_syms); $s = preg_replace($preg_exp, '', $s); return $s; }
/** * Build filters */ protected function collection_filters() { /* 'value' => array (size=2) 'from' => string '18.04.2014 03:06' (length=16) 'to' => string '18.04.2014 03:06' (length=16) 'operator' => string 'BETWEEN' (length=7) 'connector' => string 'AND' (length=3) 'raw' => null */ // // Filters: Conditions // if (!empty($this->filters)) { foreach ($this->filters as $k => $v) { $k = $this->_sql_key($k); $sql = false; if ($k && array_key_exists($v['connector'], static::$connectors) && array_key_exists($v['operator'], static::$operators)) { if ($v['raw']) { // @todo RAW $sql = strings::str_replace(array(':connector', ':key', ':operator', ':value'), array($v['connector'], $k, $v['operator'], $this->_normalize_value($k, $v['value'])), $v['raw']); } else { if (!isset(static::$operators[$v['operator']])) { throw new collection_filter_exception(__METHOD__ . ' no operator ' . $v['operator']); } if (static::$operators[$v['operator']] instanceof Closure) { $v['key'] = $k; $sql = call_user_func(static::$operators[$v['operator']], $v); } else { if (!empty($v['value'])) { $sql = $k . ' ' . $v['operator'] . " " . $this->_normalize_value($k, $v['value']); } } } if ($sql) { $this->collection->append_where($sql, $v['connector']); } } } } // // Sorting // if (!empty($this->orders)) { $orders = array(); foreach ($this->orders as $k => $v) { $v = strtoupper($v); if ('ASC' !== $v && 'DESC' !== $v) { throw new Collection_Filter_Exception('Bad order: ' . $k); } $orders[] = $this->_sql_key($k) . ' ' . $v; } $this->collection->set_order(trim(join(', ', $orders))); } }