/** * Constructs valid statements. * @param [\stdClass] $statements * @param StoreOptions $opts * @return [String => \stdClass] Array of statements mapped to their UUIDs. */ private function constructValidStatements(array $statements, StoreOptions $opts) { $generated_ids = []; $constructed = []; $this->hashes = []; foreach ($statements as $statement) { $statement->authority = $opts->getOpt('authority'); $statement->stored = Helpers::getCurrentDate(); if (!isset($statement->timestamp)) { $statement->timestamp = $statement->stored; } if (!isset($statement->id)) { $statement->id = $this->getUUID($generated_ids); $generated_ids[] = $statement->id; } // Validates statement. $constructed_statement = new XAPIStatement($statement); Helpers::validateAtom($constructed_statement, 'statement'); $statement = $constructed_statement->getValue(); // Gets attachment hashes. $attachments = !isset($statement->attachments) ? [] : $statement->attachments; foreach ($attachments as $attachment) { $this->hashes[] = $attachment->sha2; } // Adds $statement to $constructed. if (isset($constructed[$statement->id])) { $this->inserter->compareForConflict($statement, $constructed[$statement->id]); } else { $constructed[$statement->id] = $statement; } } return $constructed; }
/** * Aggregates the statements in the LRS (with the $lrsId) with the $pipeline. * @param string $lrsId * @param [mixed] $pipeline * @return [Aggregate] http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples */ public function aggregate($lrsId, array $pipeline) { if (strpos(json_encode($pipeline), '$out') !== false) { return; } $pipeline[0]['$match'] = ['$and' => [(object) $pipeline[0]['$match'], [self::LRS_ID_KEY => $lrsId, 'active' => true]]]; return Helpers::replaceHtmlEntity($this->db->statements->aggregate($pipeline), true); }
/** * Makes a statements result. * @param [\stdClass] $statements * @param Int $count * @param [String => Mixed] $opts * @return \stdClass */ private function makeStatementsResult(array $statements, $count, array $opts) { // Defaults to empty array of statements. $statements = $statements ?: []; // Replaces '&46;' in keys with '.' in statements. // http://docs.learninglocker.net/docs/installation#quirks $statements = Helpers::replaceHtmlEntity($statements); // Creates the statement result. $statement_result = (object) ['more' => $this->getMoreLink($count, $opts['limit'], $opts['offset']), 'statements' => $statements]; return json_encode($statement_result); }
private static function migrateQuery(array $query) { $output = []; foreach ($query as $key => $value) { if (is_array($value)) { $value = array_map('urldecode', $value); } $new = \Locker\Helpers\Helpers::replaceFullStopInKeys($key); $output[$new] = $value; } return $output; }
public function up() { $db = \DB::getMongoDB(); Lrs::get()->each(function (Lrs $lrs) use($db) { if (isset($lrs->users)) { $lrs->users = Helpers::convertIds($lrs->users); } $lrs->owner_id = new \MongoId($lrs->owner_id); $lrs->save(); echo 'IDs for lrs collection "' . $lrs->title . '" converted to MongoIds.' . PHP_EOL; }); }
public static function createRepo($repo) { $repos = ['Local' => 'LocalFlyRepository', 'Rackspace' => 'RackspaceFlyRepository', 'Copy' => 'CopyFlyRepository', 'Dropbox' => 'DropboxFlyRepository', 'Azure' => 'AzureFlyRepository', 'S3V3' => 'S3V3FlyRepository']; $repo = ucfirst(strtolower($repo)); $conf = function ($var) { return Helpers::getEnvVar($var); }; if (isset($repos[$repo])) { $selected_repo = 'Locker\\Repository\\File\\' . $repos[$repo]; return new $selected_repo($conf); } else { throw new \Exception('Valid `FS_REPO` not specified in ".env.' . \App::environment() . '.php". Valid values include: "' . implode('", "', array_keys($repos)) . '". You provided "' . $repo . '".'); } }
/** * Removes properties other than `objectType` and identifier from objects inside a statement. * @param \stdClass $statement Statement to be formatted. * @return \stdClass Formatted statement. */ public function identityStatement(\stdClass $statement) { $actor = $statement->actor; // Processes an anonymous group or actor. $is_anonymous_group = $actor->objectType === 'Group' && Helpers::getAgentIdentifier($actor) === null; if ($is_anonymous_group) { $actor->members = array_map(function (\stdClass $member) { return $this->identityObject($member, Helpers::getAgentIdentifier($member)); }, $actor->members); } else { $actor = $this->identityObject($actor, Helpers::getAgentIdentifier($actor)); } // Replace parts of the statements. $statement->actor = $actor; $statement->object = $this->identityObject($statement->object, Helpers::getAgentIdentifier($statement->object) ?: 'id'); return $statement; }
public function up() { $uploads = Helpers::getEnvVar('FS_LOCAL_ENDPOINT'); $LRSs = $this->getDirectores($uploads); // Gets the attachments. $attachments = []; foreach ($LRSs as $lrs) { $attachments = array_merge($attachments, array_map(function ($dir) use($uploads, $lrs) { return $uploads . '/' . $lrs . '/attachments/' . $dir; }, $this->getDirectores($uploads . '/' . $lrs . '/attachments'))); } // Migrates the attachments. foreach ($attachments as $attachment) { $file = $attachment . '/' . scandir($attachment)[2]; $ext = pathinfo($file, PATHINFO_EXTENSION); file_put_contents($attachment . '.' . $ext, file_get_contents($file)); } echo 'Migrated ' . count($attachments) . " attachments." . PHP_EOL; }
/** * Validates the given options as index options. * @param [String => Mixed] $opts * @return [String => Mixed] */ protected function validate($opts) { foreach ($opts as $key => $value) { if ($value !== null && isset($this->types[$key]) && $this->types[$key] !== null) { if (is_array($this->types[$key])) { $class = '\\Locker\\XApi\\' . $this->types[$key][0]; if (!is_array($value)) { throw new Exceptions\Exception("{$key} must be an array."); } foreach ($value as $item) { Helpers::validateAtom(new $class($item)); } } else { $class = '\\Locker\\XApi\\' . $this->types[$key]; Helpers::validateAtom(new $class($value)); } } } return $opts; }
public function toArray() { return (array) \Locker\Helpers\Helpers::replaceHtmlEntity(parent::toArray()); }
<?php use Locker\Helpers\Helpers; return array('driver' => 'file', 'lifetime' => 120, 'expire_on_close' => false, 'files' => Helpers::getEnvVar('SESSION_FILESTORE'), 'connection' => null, 'table' => 'sessions', 'lottery' => array(2, 100), 'cookie' => 'laravel_session', 'path' => '/', 'domain' => null, 'secure' => false);
?> <div class="row"> <div class="col-xs-12 col-sm-12 col-lg-12"> <div class="statement-row clearfix"> <span onclick="$('.state-{{ $statement['id'] }}').toggle();"><i class="icon icon-cog lightgrey pull-left"></i></span> <span class="pull-left statement-avatar"> <img src="{{ $avatar }}" alt='avatar' class="img-circle avatar" /> </span> {{ $name }} <i>{{ $verb }}</i> <a href="{{ $object_id }}">{{{ $object }}}</a> <small>| {{ $stored->diffForHumans() }} ({{ $stored->toDayDateTimeString() }})</small> <div class="full-statement state-{{ $statement['id'] }}" style="display:none;"> <?php $statement = \Locker\Helpers\Helpers::replaceHtmlEntity($json); ?> <pre>{{{ json_encode($statement,JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}}</pre> </div> </div> </div> </div>
public function tearDown() { parent::tearDown(); $dir = Helpers::getEnvVar('FS_LOCAL_ENDPOINT') . '/' . $this->lrs->_id; $this->deleteDirectory($dir); (new \Statement())->where('lrs_id', new \MongoId($this->lrs->_id))->delete(); }
/** * Updates the refs for the given statement. * @param \stdClass $statement * @param [\stdClass] $refs Statements that are referenced by the given statement. * @param StoreOptions $opts */ private function setRefs(\stdClass $statement, array $refs, StoreOptions $opts) { $this->where($opts)->where('statement.id', $statement->id)->update(['refs' => array_map(function ($ref) { $statement = Helpers::replaceFullStop(json_decode(json_encode($ref->statement), true)); $stored = new Carbon($statement['stored']); $timestamp = new Carbon($statement['timestamp']); $statement['stored'] = new MongoDate($stored->timestamp, $stored->micro); $statement['timestamp'] = new MongoDate($timestamp->timestamp, $timestamp->micro); return $statement; }, $refs)]); }
<?php //grab gravatar if available $grav_url = \Locker\Helpers\Helpers::getGravatar($user['email'], '50'); ?> <div class='user-list'> @if ( $lrs->owner['_id'] != $user['_id'] ) <div class="meta pull-right"> @include('partials.lrs.forms.removeUser', array('lrs' => $lrs, 'user' => $user)) </div> @endif <div class="user-avatar"> <img src="{{ $grav_url }}" alt="Avatar" class="pull-left avatar img-circle" /> </div> <div class="user-details"> <div class="user-details-item"> {{ $user['email'] }} </div> <div class="user-details-item"> @if ( $lrs->owner['_id'] != $user['_id'] ) <select class="form-control lrs-user-role" data-user="******"> <option value="admin" @if($user['role'] == 'admin') selected @endif>Admin</option> <option value="observer" @if($user['role'] != 'admin') selected @endif>Observer</option> </select> @else <b>Owner</b> @endif </div> </div> </div>
| Detect The Application Environment |-------------------------------------------------------------------------- | | Laravel takes a dead simple approach to your application environments | so you can just specify a machine name for the host that matches a | given environment, then we will automatically detect it for you. | */ $env = $app->detectEnvironment(function () use($app) { // Attempts to set the environment using the hostname (env => hostname). $env = Helpers::getEnvironment(['local' => [gethostname()]], gethostname()); if ($env) { return $env; } // Attempts to set the environment using the domain (env => domain). $env = Helpers::getEnvironment(['local' => ['127.0.0.1', 'localhost']], $app['request']->getHost()); if ($env) { return $env; } // Sets environment using LARAVEL_ENV server variable if it's set. if (array_key_exists('LARAVEL_ENV', $_SERVER)) { return $_SERVER['LARAVEL_ENV']; } // Otherwise sets the environment to production or the test environment if unit testing. return 'production'; }); /* |-------------------------------------------------------------------------- | Bind Paths |-------------------------------------------------------------------------- |
/** * Updates the refs for the given statement. * @param \stdClass $statement * @param [\stdClass] $refs Statements that are referenced by the given statement. * @param StoreOptions $opts */ private function setRefs(\stdClass $statement, array $refs, StoreOptions $opts) { $this->where($opts)->where('statement.id', $statement->id)->update(['refs' => array_map(function ($ref) { return Helpers::replaceFullStop(json_decode(json_encode($ref->statement), true)); }, $refs)]); }
/** * Constructs a builder using the given agent and options. * @param \stdClass $agent Agent to be matched. * @param Builder $builder * @param IndexOptions $opts Index options. * @return Builder */ private function matchAgent(\stdClass $agent, Builder $builder, IndexOptions $opts) { $id_key = Helpers::getAgentIdentifier($agent); if ($id_key === 'account') { $builder = $this->matchAgentProp('account.homePage', $agent->account->homePage, $builder, $opts); $builder = $this->matchAgentProp('account.name', $agent->account->name, $builder, $opts); } else { $builder = $this->matchAgentProp($id_key, $agent->{$id_key}, $builder, $opts); } return $builder; }
/** * Constructs a model from the given statement and options. * @param \stdClass $statement * @param StoreOptions $opts * @return [String => Mixed] $model */ private function constructModel(\stdClass $statement, StoreOptions $opts) { $timestamp = new \Carbon\Carbon($statement->timestamp); $stored = new \Carbon\Carbon($statement->stored); return ['lrs' => ['_id' => $opts->getOpt('lrs_id')], 'lrs_id' => $opts->getOpt('lrs_id'), 'client_id' => $opts->getOpt('client')->_id, 'statement' => Helpers::replaceFullStop(json_decode(json_encode($statement), true)), 'active' => false, 'voided' => false, 'timestamp' => new \MongoDate($timestamp->timestamp, $timestamp->micro), 'stored' => new \MongoDate($stored->timestamp, $stored->micro)]; }
/** * Aggregates the statements in the LRS (with the $lrsId) with the $pipeline. * @param [string => mixed] $opts * @param [mixed] $pipeline * @return [Aggregate] http://php.net/manual/en/mongocollection.aggregate.php#refsect1-mongocollection.aggregate-examples */ public function aggregate(array $opts, array $pipeline) { if (strpos(json_encode($pipeline), '$out') !== false) { return; } $match = [self::LRS_ID_KEY => $opts['lrs_id'], 'active' => true]; $scopes = $opts['scopes']; if (in_array('all', $scopes) || in_array('all/read', $scopes) || in_array('statements/read', $scopes)) { // Get all statements. } else { if (in_array('statements/read/mine', $scopes)) { $match['client_id'] = $opts['client']->_id; } else { throw new Exceptions\Exception('Unauthorized request.', 401); } } $pipeline[0]['$match'] = ['$and' => [(object) $pipeline[0]['$match'], $match]]; $cache_key = sha1(json_encode($pipeline)); $create_cache = function () use($pipeline, $cache_key) { $expiration = Carbon::now()->addMinutes(10); $result = Helpers::replaceHtmlEntity($this->db->statements->aggregate($pipeline), true); IlluminateCache::put($cache_key, $result, $expiration); return $result; }; //$result = IlluminateCache::get($cache_key, $create_cache); $result = $create_cache(); return $result; }
/** * Gets the statement from the model as an Object. * @param Model $model * @return \stdClass */ protected function formatModel(Model $model) { return Helpers::replaceHtmlEntity($model->statement); }
/** * Gets the CORS headers. * @return [String => Mixed] CORS headers. */ private function getCORSHeaders() { return ['Access-Control-Allow-Origin' => \Request::root(), 'Access-Control-Allow-Methods' => 'GET, PUT, POST, DELETE, OPTIONS', 'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Requested-With, X-Experience-API-Version, X-Experience-API-Consistent-Through, Updated', 'Access-Control-Allow-Credentials' => 'true', 'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate(), 'X-Experience-API-Version' => '1.0.1']; }
/** * Gets the current LRS from the Authorization header. * @return \Lrs */ static function getLrsFromAuth() { list($username, $password) = Helpers::getUserPassFromAuth(); return Helpers::getLrsFromUserPass($username, $password); }
protected function generateStatement($statement = []) { $timestamp = Helpers::getCurrentDate(); return array_merge(['id' => $this->statement_id, 'actor' => ['mbox' => 'mailto:test@example.com', 'objectType' => 'Agent'], 'verb' => ['id' => 'http://www.example.com/verbs/test'], 'object' => ['id' => 'http://www.example.com/objects/test', 'objectType' => 'Activity'], 'timestamp' => $timestamp, 'stored' => $timestamp, 'authority' => ['mbox' => 'mailto:test@example.com', 'objectType' => 'Agent'], 'version' => '1.0.1'], $statement); }
/** * Gets the statements selected by the report with the given ID and options. * @param String $id ID to match. * @param [String => Mixed] $opts * @return [[String => Mixed]] Statements selected by the report. */ public function statements($id, array $opts) { $report = $this->show($id, $opts); return (new QueryRepository())->where($report->lrs_id, Helpers::replaceHtmlEntity($report->where))->orderBy('statement.stored', 'DESC'); }
<?php //grab gravatar if available $grav_url = \Locker\Helpers\Helpers::getGravatar($user->email, '50'); ?> <div class='user-list clearfix'> @if($user->verified == 'yes') <span class="label label-success pull-right"> {{ Lang::get('users.verified') }} <i class="icon icon-check"></i> </span> @else <span class="label label-default pull-right"> {{ Lang::get('users.unverified') }} </span> @endif <div class="user-avatar"> <img src="{{ $grav_url }}" alt="Avatar" class="pull-left avatar img-circle" /> @if ( Auth::user()->_id != $user['_id'] ) @include('partials.users.forms.delete', array('user' => $user)) @endif @if( $user->verified != 'yes') @include('partials.site.forms.verifyUser', array('user' => $user)) @endif </div> <div class="user-details"> <div class="user-details-item"> {{ $user->name }} </div> <div class="user-details-item"> {{ $user->email }} </div>
/** * Constructs a new base controller. */ public function __construct() { $this->lrs = Helpers::getLrsFromAuth(); list($username, $password) = Helpers::getUserPassFromAuth(); $this->client = Helpers::getClient($username, $password); }
public function tearDown() { parent::tearDown(); $dir = Helpers::getEnvVar('LOCAL_FILESTORE') . '/' . $this->lrs->_id; $this->deleteDirectory($dir); (new \Statement())->where('lrs._id', $this->lrs->_id)->delete(); }
/** * Validates data. * @param [String => Mixed] $data Properties to be changed on the model. * @throws \Exception */ protected function validateData(array $data) { if (isset($data['authority'])) { Helpers::validateAtom(XApiAuthority::createFromJson(json_encode($data['authority'])), 'client.authority'); } }
/** * Constructs a model from the given statement and options. * @param \stdClass $statement * @param StoreOptions $opts * @return [String => Mixed] $model */ private function constructModel(\stdClass $statement, StoreOptions $opts) { return ['lrs' => ['_id' => $opts->getOpt('lrs_id')], 'client_id' => $opts->getOpt('client')->_id, 'statement' => Helpers::replaceFullStop(json_decode(json_encode($statement), true)), 'active' => false, 'voided' => false, 'timestamp' => new \MongoDate(strtotime($statement->timestamp))]; }