private function login() { $uid = phoxy::Load('user/store')->Register(); $my_name =& $this->get_uid(); $my_name = $uid; return $uid; }
protected function make_step($sequence_type, $instruction, $data) { $is_laststep = $this->require_known_instruction($sequence_type, $instruction); $auth = $this->load(); if (!$is_laststep) { return ['design' => 'networks/auth/sequence.step', 'data' => ['commands' => $auth->{$instruction}($data)]]; } $token = $auth->{$instruction}($data); $account = phoxy::Load('accounts')->save_network($this->network_name, $token); return ["design" => "accounts/create/finished", "data" => ["account" => $account]]; }
public function threads($account_id) { $resolver = function ($network, $cb, $uid) { $threads = $network->threads(); if (!$threads) { return false; } return $cb($threads, time() + 60); }; return phoxy::Load('accounts/cache')->account($account_id)->Retrieve('threads', 0, $resolver); }
protected function info($account_id, $uid = null) { $resolver = function ($network, $cb, $uid) { $user = $network->user($uid); if (!$user) { return false; } return $cb($user, time() + 3600 * 24); }; $user = phoxy::Load('accounts/cache')->account($account_id)->Retrieve('user', $uid, $resolver); return ['design' => 'thread/users/one', 'data' => $user]; }
private function ResolveMissingCache($type, $resource_id, $resolver) { $account_id = $this->AccountID(); $network = phoxy::Load('networks/network')->by_account_id($account_id); $resolved = function ($data, $expiration) use(&$return, $type, $resource_id) { $return = $data; $this->Update($type, $resource_id, $data, $expiration); return true; }; $result = $resolver($network, $resolved, $resource_id); phoxy_protected_assert($result, "Resolver returned failure on {$type} cache miss"); return $return; }
public function get_network_object($network) { $storage_functor = phoxy::Load('user')->StorageShortcut(); $accounts =& $storage_functor()['accounts']; if (!is_array($accounts)) { $accounts = []; } phoxy_protected_assert(!isset($accounts[$network]), "In demo mode one account per social network"); $networks = phoxy::Load('networks'); phoxy_protected_assert($networks->supported($network), "Social network unsupported"); $obj = $networks->get_network_object($network); $this->init_network_object($obj, $network); return $obj; }
private function DefaultCacheTiming() { $conf = phoxy::Config(); if (!isset($this->obj['cache'])) { $this->obj['cache'] = []; } $cache = $this->obj['cache']; //var_dump($this->obj); if (isset($cache['no'])) { if (in_array("all", $cache['no'])) { return; } } $dictionary = ["global", "session", "local"]; foreach ($dictionary as $scope) { if (!isset($cache[$scope]) && !is_null($conf["cache_{$scope}"])) { if (!isset($cache['no']) || !in_array($scope, $cache['no'])) { $this->obj['cache'][$scope] = $conf["cache_{$scope}"]; } } } }
public function GetRpcObject($str, $get) { $t = $this->GetOrganizedTokens($str); $args = $this->ExplodeTokensToCallee($t); $try = $this->GetAllCallVariations($args); include_once 'include.php'; if (!count($try)) { die('Error at rpc resolve: All variations were invalid. Unable to resolve'); } foreach ($try as $t) { $target_dir = "."; if ($t['class'] === 'phoxy') { $target_dir = realpath(dirname(__FILE__)); $t["scope"] = str_replace(\phoxy::Config()["api_dir"], "", $t["scope"]); } $file_location = $target_dir . $t["scope"]; $obj = IncludeModule($file_location, $t["class"]); if (!is_null($obj)) { return ["original_str" => $str, "obj" => $obj, "method" => $t["method"]]; } } exit(json_encode(["error" => 'Module not found'])); }
protected function info($account_id) { $account = phoxy::Load('accounts/tokens')->info($account_id); return ["data" => $this->filter_sensitive_token_data($account)]; }
protected function Login($network, $login, $password) { phoxy::Load('user')->ResetSession(); return phoxy::Load('accounts', true)->add($network, $login, $password); }
public static function SetCacheTimeoutTimestamp($scope, $timeout_timestamp) { if (!is_numeric($timeout_timestamp)) { $dt = new DateTime($timeout_timestamp); $unix_time = $dt->format('U'); // in server timezone $timeout_timestamp = $unix_time; } $timeout = $timeout_timestamp - time(); if ($timeout < 0) { $timeout = 0; } phoxy::SetCacheTimeout($scope, $timeout); }
public static function UID() { $uid = phoxy::Load('user/store')->MyUID(); phoxy_protected_assert($uid, "Please log in to continue"); return $uid; }
{ $ret = ["cache" => PRODUCTION ? ['global' => '10m'] : "no", "result" => "canvas"]; return $ret; } ob_start(); function append_warnings_to_object($that) { $buffer = ob_get_contents(); ob_end_clean(); if (!empty($buffer)) { $that->obj["warnings"] = $buffer; } } include 'phoxy/server/phoxy_return_worker.php'; phoxy_return_worker::$add_hook_cb = function ($that) { global $USER_SENSITIVE; if ($USER_SENSITIVE) { $that->obj['cache'] = 'no'; } $that->hooks[] = append_warnings_to_object; }; error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE); include 'phoxy/load.php'; phoxy::Load("user/store/db"); try { \phoxy::Start(); } catch (Exception $e) { $message = ["error" => $e->getMessage(), "warnings" => ob_get_contents()]; ob_end_clean(); die(json_encode($message, true)); }
protected function Send($account_id, $thread_id, $text) { $network = phoxy::Load('networks/network')->by_account_id($account_id); return ['data' => $network->message_send($thread_id, $text)]; }
public function __call($name, $arguments) { assert($this->json !== null, "API constuctor should be called"); $this->addons = $this->default_addons; $ret = $this->Call($name, $arguments); if (!is_array($ret)) { $ret = [$name => $ret]; $ret = array("data" => $ret); } $ret = array_merge_recursive($this->addons, $ret); $conf = phoxy::Config(); return new phoxy_return_worker($ret); }
public function MyUID() { return phoxy::Load("user")->uid(); }