Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Allow Motifs to be configured.
Browse files Browse the repository at this point in the history
  • Loading branch information
paragonie-security committed Aug 27, 2016
1 parent efffb34 commit e6bb9fe
Show file tree
Hide file tree
Showing 16 changed files with 201 additions and 95 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/src/config/keyring/*.skey
/src/config/keyring/*.keypair
/src/config/universal.json
/src/config/motifs/*.json
/src/tmp/cache/*.json
/src/tmp/installing.json
/src/tmp/last_update_check.txt
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Gadgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function loadCargo(string $name, string $source)
if (!\array_key_exists($name, $cargo)) {
$cargo[$name] = [];
}

\array_unshift($cargo[$name], $source);
$cargo[$name] = \array_values($cargo[$name]);

Expand All @@ -79,8 +79,8 @@ public static function unloadNextCargo(string $name)
$iterate = $state->cargoIterator;

if (isset($iterate[$name])) {
$cargo = self::unloadCargo($name, $iterate[$name]);
++$iterate[$name];
$cargo = self::unloadCargo($name, $iterate[$name]);
$state->cargoIterator = $iterate;
return $cargo;
}
Expand Down
55 changes: 53 additions & 2 deletions src/Engine/Lens.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,56 @@ public function listFilters(): array
return \array_keys($filters);
}

/**
* Load the cargo for these motifs
*
* @param string $name
* @return self
*/
public function loadMotifCargo(string $name): self
{
$state = State::instance();
if (
isset($state->motifs[$name])
&&
isset($state->motifs[$name]['config']['cargo'])
) {
foreach ($state->motifs[$name]['config']['cargo'] as $key => $subPath) {
Gadgets::loadCargo(
$key,
'motif/' . $name . '/cargo/' . $subPath
);
}
}
return $this;
}


/**
* Load the config for this motif
*
* @param string $name
* @return self
*/
public function loadMotifConfig(string $name): self
{
$state = State::instance();
if (isset($state->motifs[$name])) {
try {
if (\file_exists(ROOT . '/config/motifs/' . $name . '.json')) {
$state->motif_config = \Airship\loadJSON(
ROOT . '/config/motifs/' . $name . '.json'
);
} else {
$state->motif_config = [];
}
} catch (\Throwable $ex) {
$state->motif_config = [];
}
}
return $this;
}

/**
* Set the active motif
*
Expand Down Expand Up @@ -308,7 +358,7 @@ public function resetBaseTemplate(): self
* Override the base template
*
* @param string $name
* @return Lens
* @return self
*/
public function setBaseTemplate(string $name): self
{
Expand All @@ -320,9 +370,10 @@ public function setBaseTemplate(string $name): self
) {
$state->base_template = 'motif/' .
$name .
'/lens/' .
'/' .
$state->motifs[$name]['config']['base_template'] .
'.twig';
\var_dump($state->base_template);
}
return $this;
}
Expand Down
16 changes: 16 additions & 0 deletions src/Motifs/paragonie/airship-classic/config.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="multiline_checkbox_container">
<div class="multiline_checkbox">
<input
id="motif-config-bridge-gradient"
type="checkbox"
name="motif_config[bridge][gradient]"
value="1"
{% if motif_config['bridge']['gradient'] %}
checked="checked"
{% endif %}
/>
<label for="motif-config-bridge-gradient">
{{ __("Metallic look?") }}
</label>
</div>
</div>
17 changes: 17 additions & 0 deletions src/Motifs/paragonie/airship-classic/config_filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

use Airship\Engine\Security\Filter\{
BoolFilter,
GeneralFilterContainer
};

/**
* @return $motifInputFilter
*/
$motifInputFilter = (new GeneralFilterContainer())
->addFilter(
'bridge.gradient',
(new BoolFilter())->setDefault(true)
)
;
14 changes: 0 additions & 14 deletions src/Motifs/paragonie/airship-classic/lens/base-classic.twig

This file was deleted.

73 changes: 73 additions & 0 deletions src/Motifs/paragonie/airship-classic/lens/cargo/base_head.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{% include next_cargo("base_head") %}

<style type="text/css" nonce={{ csp_nonce('style-src') }}>
{% if MOTIF['bridge']['gradient'] %}
.bridge-body-site-wrapper {
background-image: -webkit-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -webkit-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -webkit-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -moz-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -moz-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -moz-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -ms-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -ms-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -ms-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -o-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -o-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -o-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
}
{% endif %}
</style>
3 changes: 3 additions & 0 deletions src/Motifs/paragonie/airship-classic/motif.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"name": "airship-classic",
"display_name": "Airship Classic v1.3.0",
"base_template": null,
"cargo": {
"base_head": "base_head.twig"
},
"css": [
"style.css"
],
Expand Down
65 changes: 0 additions & 65 deletions src/Motifs/paragonie/airship-classic/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,71 +16,6 @@ body {
}
.bridge-body-site-wrapper {
background-color: #242424;
background-image: -webkit-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -webkit-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -webkit-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -moz-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -moz-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -moz-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -ms-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -ms-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -ms-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: -o-linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), -o-linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), -o-linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
background-image: linear-gradient(
top,
rgba(0, 0, 0, 0) 0%,
rgba(0, 0, 0, 0.5) 100%
), linear-gradient(
top,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 3rem
), linear-gradient(
left,
rgba(255, 255, 255, 0.1) 0px,
rgba(255, 255, 255, 0) 200px
);
}
#hull-header-icon {
height: 64px;
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ function($matches) {
/**
* Load up all of the keys used by the application:
*/
require_once ROOT.'/keys.php';
require_once ROOT . '/keys.php';

/**
* Set up the logger
*/
require_once ROOT."/config/logger.php";
require_once ROOT . '/config/logger.php';

/**
* Automatic security updates
Expand Down
2 changes: 1 addition & 1 deletion src/config/gadgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
);
} else {
$cabinsGadgets = [];
\file_get_contents(
\file_put_contents(
ROOT . '/Cabin/' . $active['name'] . '/config/gadgets.json',
'[]'
);
Expand Down
3 changes: 2 additions & 1 deletion src/config/lens.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* GLOBAL LENS MODIFICATIONS GO HERE
*
* We can add filters, functions, etc. to the current lens if we want
*
*
* @global Lens $lens
*/

Expand Down Expand Up @@ -110,6 +110,7 @@
$lens->func('global_config');
$lens->func('is_admin');
$lens->func('logout_token');
$lens->func('next_cargo');
$lens->func('userid');
$lens->func('user_authors');
$lens->func('user_author_ids');
Expand Down
Empty file added src/config/motifs/.gitkeep
Empty file.
17 changes: 14 additions & 3 deletions src/lens_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,6 @@ function logout_token(): string
return $_SESSION['logout_token'];
}


/**
* Get information about the motifs
*
Expand All @@ -605,6 +604,15 @@ function motifs()
return $state->motifs;
}

/**
* @param array ...$args
* @return array
*/
function next_cargo(...$args)
{
return Gadgets::unloadNextCargo(...$args);
}

/**
* @param string $string
* @param bool $return
Expand Down Expand Up @@ -901,10 +909,13 @@ function user_motif(int $userId = null, string $cabin = \CABIN_NAME): array
if (isset($userPrefs['motif'][$cabin])) {
$split = \explode('/', $userPrefs['motif'][$cabin]);
foreach ($state->motifs as $k => $motif) {
if (empty($motif['config'])) {
continue;
}
if (
$motif['config']['supplier'] === $split[0]
$motif['supplier'] === $split[0]
&&
$motif['config']['name'] === $split[1]
$motif['name'] === $split[1]
) {
// We've found a match:
$userCache[$userId] = $k;
Expand Down
Loading

0 comments on commit e6bb9fe

Please sign in to comment.