/** * validate data againts a set of rules and set errors in the $this->errors * array * @param array $data * @param array $rules * @return boolean */ public function validate(array $data, array $rules) { $valid = true; foreach ($rules as $item => $ruleset) { // required|email|min:8 $ruleset = explode('|', $ruleset); foreach ($ruleset as $rule) { $pos = strpos($rule, ':'); if ($pos !== false) { $parameter = subtr($rule, $pos + 1); $rule = subtr($rule, 0, $pos); } else { $parameter = ''; } //validateEmail($item, $value, $param) $methodName = 'validate' . ucfirst($rule); $value = isset($data[$item]) ? $data[$item] : NULL; if (method_exists($this, $methodName)) { $this->{$methodName}($item, $value, $parameter) or $valid = false; } } } return $valid; }
public static function fetch($dat, $cfg) { $n = ",cached"; $f = $cfg["path"] . $dat["content"]; if (substr($f, -strlen($n)) == $n) { $cached = true; $f = subtr($f, 0, strlen($f) - strlen($n)); } else { $cached = false; } $txt = file($cfg["path"] . $dat["content"], FILE_IGNORE_NEW_LINES); if ($txt === false || count($txt) == 0) { $txt = "Error reading file"; } if ($cached) { $scriptlet = implode("\n", $txt); ob_start(); eval($scriptlet); return "xx" . explode("\n", ob_get_clean()); } else { $txt[0] = "?>" . $txt[0]; } return $txt; }
/** * Returns the operand to be used in filters * This value comes from the user input * but can be override * * @param string $field Field name * @param string $filter Filter to apply to the field * * @return array */ public function getFilterOp($field, $filter) { if (!isset($this->_data['fields'][$field]['searchType'])) { $this->_data['fields'][$field]['searchType'] = 'like'; } $op = strtolower($this->_data['fields'][$field]['searchType']); if ($this->_data['fields'][$field]['searchType'] == 'sqlExp' && isset($this->_data['fields'][$field]['searchSqlExp'])) { $op = 'sqlExp'; $sqlExp = $this->_data['fields'][$field]['searchSqlExp']; if (!isset($this->_data['fields'][$field]['searchSqlQuote'])) { $this->_data['fields'][$field]['searchSqlQuote'] = false; } $sqlQuote = (bool) $this->_data['fields'][$field]['searchSqlQuote']; if ($sqlQuote === false) { $filter = str_replace('{{value}}', $this->getSource()->quoteValue($filter), $sqlExp); } else { $filter = str_replace('{{value}}', trim(subtr($filter, 1, -1)), $sqlExp); } } elseif (substr(strtolower($filter), 0, 6) == ':empty') { $op = 'empty'; $filter = substr($filter, 2); } elseif (substr(strtolower($filter), 0, 10) == ':isnotnull') { $op = 'isnotnull'; $filter = substr($filter, 2); } elseif (substr(strtolower($filter), 0, 7) == ':isnull') { $op = 'isnull'; $filter = substr($filter, 2); } elseif (substr(strtoupper($filter), 0, 2) == 'R:') { $op = 'REGEX'; $filter = substr($filter, 2); } elseif (strpos($filter, '<>') !== false && substr($filter, 0, 2) != '<>') { $op = 'range'; } elseif (substr($filter, 0, 1) == '=') { $op = '='; $filter = substr($filter, 1); } elseif (substr($filter, 0, 2) == '>=') { $op = '>='; $filter = substr($filter, 2); } elseif ($filter[0] == '>') { $op = '>'; $filter = substr($filter, 1); } elseif (substr($filter, 0, 2) == '<=') { $op = '<='; $filter = substr($filter, 2); } elseif (substr($filter, 0, 2) == '<>' || substr($filter, 0, 2) == '!=') { $op = '<>'; $filter = substr($filter, 2); } elseif ($filter[0] == '<') { $op = '<'; $filter = substr($filter, 1); } elseif ($filter[0] == '*' and substr($filter, -1) == '*') { $op = 'like'; $filter = substr($filter, 1, -1); } elseif ($filter[0] == '*' and substr($filter, -1) != '*') { $op = 'llike'; $filter = substr($filter, 1); } elseif ($filter[0] != '*' and substr($filter, -1) == '*') { $op = 'rlike'; $filter = substr($filter, 0, -1); } elseif (stripos($filter, ',') !== false) { $op = 'IN'; } elseif (substr($filter, 0, 2) == '||') { $op = '||'; $filter = substr($filter, 2); } if (isset($this->_data['fields'][$field]['searchTypeFixed']) && $this->_data['fields'][$field]['searchTypeFixed'] == true && $op != $this->_data['fields'][$field]['searchType']) { $op = $this->_data['fields'][$field]['searchType']; } return array('op' => $op, 'filter' => $filter); }
/** * Zhang-Suen thinning adapted from: * * @link http://pages.cpsc.ucalgary.ca/~parker/thin.c * * @param int * @param mixed * @param mixed * * @return TODO * @author Adam Zammit <*****@*****.**> * @since 2010-10-13 */ function thin_b($image) { /* Thinning algorithm: CACM 1984 march (Zhang and Suen) */ $a = array(); $xdim = imagesx($image); $ydim = imagesy($image); $y = imagecreate($xdim, $ydim); $white = imagecolorallocate($y, 255, 255, 255); $black = imagecolorallocate($y, 0, 0, 0); $br = 0; $ccc = 0; $cont = 1; while ($cont) { $cont = 0; /* Sub-iteration 1: */ for ($i = 0; $i < $xdim; $i++) { for ($j = 0; $j < $ydim; $j++) { /* Scan the entire image */ if (imagecolorat($image, $i, $j) == 0) { imagecolorsettrue($y, $i, $j, 0, $white, $black); //$y[$i][$j] = 0; continue; } $ar = t1a($image, $i, $j, $a, $br, $xdim, $ydim); /* Function A */ $p1 = $a[0] * $a[2] * $a[4]; $p2 = $a[2] * $a[4] * $a[6]; if ($ar == 1 && ($br >= 2 && $br <= 6) && $p1 == 0 && $p2 == 0) { //$y[$i][$j] = 1; imagecolorsettrue($y, $i, $j, 1, $white, $black); $cont = 1; } else { imagecolorsettrue($y, $i, $j, 0, $white, $black); } //$y[$i][$j] = 0; } } subtr($y, $image, $xdim, $ydim, $white, $black); /* Sub iteration 2: */ for ($i = 0; $i < $xdim; $i++) { for ($j = 0; $j < $ydim; $j++) { /* Scan the entire image */ if (imagecolorat($image, $i, $j) == 0) { //$y[$i][$j] = 0; imagecolorsettrue($y, $i, $j, 0, $white, $black); continue; } $ar = t1a($image, $i, $j, $a, $br, $xdim, $ydim); /* Function A */ $p1 = $a[0] * $a[2] * $a[6]; $p2 = $a[0] * $a[4] * $a[6]; if ($ar == 1 && ($br >= 2 && $br <= 6) && $p1 == 0 && $p2 == 0) { //$y[$i][$j] = 1; imagecolorsettrue($y, $i, $j, 1, $white, $black); $cont = 1; } else { imagecolorsettrue($y, $i, $j, 0, $white, $black); } //$y[$i][$j] = 0; } } subtr($y, $image, $xdim, $ydim, $white, $black); $ccc++; } return $image; }
private function return_path($path) { $paths = ""; if (preg_match('/\\_/', $path)) { $path = substr($path, strpos($path, '_')); call(subtr($path, 1), $this->module); $paths = new $path(); $paths = $paths->Read("path"); } return $path; }
function index_exists($dbh, $table_name, $index_name) { $db_type = get_database_type($dbh); if (subtr(get_database_type($db_type), 0, 5) == "mysql") { $select = "SHOW INDEX FROM " . $table_name; $sth = $dbh->query($select); if (DB::isError($sth)) { return false; } else { $found = false; while ($row = $sth->fetchRow()) { if ($row[2] == $index_name) { $found = true; } } $sth->free(); return $found; } } else { if ($db_type == "pgsql") { $select = "SELECT i.relname AS indexname " . "FROM pg_class c, pg_class i " . "WHERE ((c.relkind = 'r'::\"char\") " . "AND (i.relkind = 'i'::\"char\") " . "AND (i.relname = ?) " . "AND (c.relname = ?))"; $sth = $dbh->query($select, array($index_name, $table_name)); if (DB::isError($sth)) { return false; } else { $found = false; if ($row = $sth->fetchRow()) { $found = true; } $sth->free(); return $found; } } } }
function mathOperation($arg1, $arg2, $operation) { switch ($operation) { case '+': return add($arg1, $arg2); break; case '-': return subtr($arg1, $arg2); break; case '*': return mult($arg1, $arg2); break; case '/': return divide($arg1, $arg2); break; default: echo 'Операция не определена'; return null; break; } }