public function validate() { $allok = true; foreach ($this->keys as $key) { if (empty($this->model->{$key})) { $this->error .= nf_t('$key is required.', array('$key' => $key)) . "\n"; $allok = false; } } return $allok; }
public function validate() { $allok = true; foreach ($this->keys as $key) { $value = $this->model->{$key}; $count = $this->model->countByAttributes(array($key => $value)); if ($count > 0) { $allok = false; $this->error .= nf_t('$key must be unique.', array('$key' => $key)) . "\n"; } } return $allok; }
public function validate() { $allok = true; foreach ($this->keys as $key) { $v = $this->model->{$key}; if (empty($v)) { continue; } $result = preg_match($this->value, $v); if ($result === false) { throw new Exception('Wrong regex pattern for key ' . $key); } elseif ($result === 0) { $allok = false; $this->error .= nf_t('$key does not match pattern.', array('$key' => $key)) . "\n"; } } return $allok; }
public function validate() { $allok = true; foreach ($this->keys as $key) { if (isset($this->arguments['min'])) { $min = intval($this->arguments['min']); if (strlen($this->model->{$key}) < $min) { $this->error .= nf_t('$key is shorter than $min characters.', array('$key' => $key, '$min' => $min)) . "\n"; $allok = false; } } if (isset($this->arguments['max'])) { $max = intval($this->arguments['max']); if (strlen($this->model->{$key}) > $max) { $this->error .= nf_t('$key is longer than $max characters.', array('$key' => $key, '$max' => $max)) . "\n"; $allok = false; } } } return $allok; }
/** * Perform a query on the SQL database. */ function nf_sql_query($query) { global $nf_sql; $ret = $nf_sql->query($query); if ($ret === false) { nf_error(10, nf_t('Error was:') . ' ' . $nf_sql->error . ' - ' . nf_t('Query was:') . ' ' . $query); } return $ret; }
public static function timeAgo($oldTime, $tags = true) { $timeCalc = 0; $strOldTime = $oldTime; if (preg_match("/^[0-9]+\$/", $oldTime)) { $timeCalc = time() - intval($oldTime); $strOldTime = Nin::timeFormat($oldTime); } else { $timeCalc = time() - strtotime($oldTime); } $timeType = 's'; if ($timeCalc >= 60) { $timeType = 'm'; } if ($timeCalc >= 60 * 60) { $timeType = 'h'; } if ($timeCalc >= 60 * 60 * 24) { $timeType = 'd'; } if ($timeType == "s") { $timeCalc = Nin::multiple($timeCalc, nf_t('second'), nf_t('seconds')) . ' ' . nf_t('ago'); } if ($timeType == "m") { $mins = round($timeCalc / 60); $timeCalc = Nin::multiple($mins, nf_t('minute'), nf_t('minutes')) . ' ' . nf_t('ago'); } if ($timeType == "h") { $hrs = round($timeCalc / 60 / 60); $timeCalc = Nin::multiple($hrs, nf_t('hour'), nf_t('hours')) . ' ' . nf_t('ago'); } if ($timeType == "d") { $days = round($timeCalc / 60 / 60 / 24); $timeCalc = Nin::multiple($days, nf_t('day'), nf_t('days')) . ' ' . nf_t('ago'); } if ($tags) { return "<span title=\"" . $strOldTime . "\">" . $timeCalc . "</span>"; } else { return $timeCalc; } }