/** * @param string $ip * @param callable $cb */ public function query($ip, $cb) { if (is_string($ip)) { $ip = ip2long($ip); } $this->blocks->findOne(function ($blk) use($cb) { if (!$blk) { call_user_func($cb, false); return; } $this->locations->findOne(function ($loc) use($cb) { if ($loc) { $loc['country'] = $this->countries[$loc['cc']]; $loc['text'] = $loc['country']; if (isset($loc['r']) && !ctype_digit($loc['r'])) { $loc['text'] = $loc['r'] . ', ' . $loc['text']; } if (isset($loc['c'])) { $loc['text'] = $loc['c'] . ', ' . $loc['text']; } } call_user_func($cb, $loc); }, ['where' => ['_id' => $blk['l']]]); }, ['where' => ['s' => ['$lte' => $ip]], 'sort' => ['s' => -1]]); }
/** * @param $block * @param bool $update */ public function saveBlock($block, $update = false) { $block['mtime'] = microtime(true); if (!isset($block['locale'])) { $block['locale'] = null; } if (isset($block['_id'])) { $find = array('_id' => $block['_id']); } elseif (isset($block['path'])) { $find = array('locale' => $block['locale'], 'path' => $block['path']); } else { $find = array('name' => (string) $block['name']); } unset($block['_id']); if (isset($block['template'])) { $tpl = $this->appInstance->getQuickyInstance(); $tpl->register_function('getblock', function ($args) { }); $tpl->load_filter('pre', 'optimize'); $block['templatePHP'] = 'return function($tpl) { $var = &$tpl->_tpl_vars; $config = &$tpl->_tpl_config; $capture = &$tpl->_block_props[\'capture\']; $foreach = &$tpl->_block_props[\'foreach\']; $section = &$tpl->_block_props[\'section\']; ?>' . $tpl->_compile_string($block['template'], implode(':', $find)) . '<?php };'; } $block['cachekey'] = md5($block['templatePHP']); $this->blocks->upsertOne($find, $update ? array('$set' => $block) : $block); }
/** * @param $names * @param callable $cb */ public function get($agent, $cb) { $this->browsers->findOne(function ($item) use($cb, $agent) { if ($item) { call_user_func($cb, $item); return; } $browser = \get_browser($agent, true); $browser['name'] = $browser['browser']; unset($browser['browser_name_regex'], $browser['browser']); $this->browsers->insert(['_id' => $agent] + $browser); call_user_func($cb, $browser); }, ['where' => ['_id' => $agent]]); }
/** * @param $names * @param callable $cb */ public function check($token, $text, $invalidate = true, $cb) { $e = static::decodeToken($token); if ($e === false) { call_user_func($cb, 'badToken'); return; } list($id, $rnd) = $e; $this->captcha->findOne(function ($t) use($cb, $id, $text, $invalidate) { if (!$t) { call_user_func($cb, 'expired'); return; } Daemon::log(Debug::dump([$invalidate])); if (!$invalidate) { if (strtolower($t['text']) === strtolower($text)) { call_user_func($cb, 'ok'); return; } } $this->captcha->remove(['_id' => new \MongoId($id)], function ($lastError) use($t, $text, $cb) { if ($lastError['n'] !== 1) { call_user_func($cb, 'expired'); return; } if (strtolower($t['text']) !== strtolower($text)) { call_user_func($cb, 'incorrect'); return; } call_user_func($cb, 'ok'); }); }, ['where' => ['_id' => $id, 'rnd' => $rnd, 'ctime' => ['$gt' => time() - 3600]]]); }
/** * @param $ip * @param callable $cb */ public function getRecentSignupsFromIP($ip, $cb) { $this->accounts->count($cb, array('where' => array('ip' => (string) $ip, 'regdate' => array('$gt' => time() - 3600)))); }
/** * @param array $cond * @param callable $cb */ public function remove(array $cond, $cb = null) { $this->externalAuthTokens->remove($cond, $cb); }
/** * @param array $credentials * @param callable $cb */ public function getRequestByCredentials(array $credentials, $cb = null) { $this->externalSignupRequests->findOne($cb, ['credentials' => ['$elemMatch' => $credentials]]); }