/** * Creates and returns a new token/api_key combination for the * specified user ID. Returns an array with the two values. Note * that for an existing user ID, this will generate a new pair, * replacing the old values and making them no longer valid for * API access. */ public static function create_token($user_id) { $a = Api::query()->where('user_id', $user_id)->fetch(); if (count($a) > 0) { $a = $a[0]; $a->token = md5(uniqid(mt_rand(), 1)); $a->api_key = md5(uniqid(mt_rand(), 1)); } else { $a = new Api(array('token' => md5(uniqid(mt_rand(), 1)), 'api_key' => md5(uniqid(mt_rand(), 1)), 'user_id' => $user_id)); } while (!$a->put()) { $a->token = md5(uniqid(mt_rand(), 1)); } return array($a->token, $a->api_key); }
/** Выводит блоки с новостями на страницу * @param count {natural} количество новостей * @return {string} @echo */ function writeNews($count = 2, $form = array()) { global $section; if (count($form) == 0) { $form = $section['loginForm']; } $r = array(); if ($count > 0) { for ($i = 0; $i < count($form); ++$i) { $r[] = $form[$i]; } } $r[] = "<div id=\"news\"" . ($count > 0 ? "" : " class=\"noside\"") . ">"; $news = Api::query('*', 'news', $count, array('id' => 'desc')); for ($i = 0; $i < count($news); ++$i) { $temp = newsItem($news[$i]); for ($j = 0; $j < count($temp); ++$j) { $r[] = space(2) . $temp[$j]; } } if ($count > 0) { $r[] = space(2) . "<a href=\"?page=news\" class=\"button lang\">Все новости</a>"; } $r[] = "</div>"; return $r; }
public static function all() { return Api::query('*', 'groups'); }