-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
143 lines (119 loc) · 5.12 KB
/
config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* IMPORTANT: Use this file to set the custom info in the study.
* Any data that will be consistently used across all items are defined here. Think of this like defaults and global info.
* Go through each of these sections when you set-up your study.
*/
define('ROOT_DIRECTORY', dirname(__FILE__));
// Load the config file
$configFile = file_get_contents(ROOT_DIRECTORY.'/config.json');
$config = json_decode($configFile, true);
/**
* 1. What is the name of the directory you'll use when you upload this to thenewsbeat.org?
* If you'll be at thenewsbeat.org/2019-reporter-biographies/, enter '2019-reporter-biographies'
*/
define('NEWSBEAT_DIRECTORY_NAME', $config['newsbeatDirectoryName']);
/**
* 2. What is the prefix for your study? This will be used in the comment logging and creating people's unique user IDs.
* This will get stored to their localStorage and used from there after the first time. So, if you update it, you'll need
* to clear your localStorage to see the effect.
*/
define('STUDY_PREFIX', $config['studyPrefix']);
define('IS_DEV', "$_SERVER[HTTP_HOST]" !== 'thenewsbeat.org');
define('SITE_NAME', $config['siteName']);
define('DIST_URL', IS_DEV ? "https://$_SERVER[HTTP_HOST]/dist" : "https://$_SERVER[HTTP_HOST]/".NEWSBEAT_DIRECTORY_NAME."/dist");
function getConfigVariation($variationKey) {
foreach($config['variations'] as $key => $val) {
if($variationKey === $key) {
return $val;
}
}
return false;
}
/**
* In this config example, we’ll need five versions of each article:
*
* 1. No bio, only a byline /
* 2. Personal photo with personal bio /?author_photo=personal&author_bio=personal
* 3. Personal photo with basic bio /?author_photo=personal&author_bio=basic
* 4. Professional photo with personal bio /?author_photo=professional&author_bio=personal
* 5. Professional photo with basic bio /?author_photo=professional&author_bio=basic
*/
/**
* 3. Set the query parameters that will define the variations of the study.
* This could be something like:
* - using a photo or not: /?photo=true
* - varying a template: /?template=trust
* - multiple things at once: /?tempalate=trust&author_photo=professional
*
* Set the values based on your potential $_GET values. The keys in the arrays below should match
* the valid $_GET values for your parameters. So, if you do /?author_photo=personal, there should
* be a key in your $authorPhotos array for 'personal'
*/
$variations = array();
// Get all the potential values
foreach($config['variations'] as $key => $val) {
if(isset($_GET[$val['GET']['key']])) {
$GETKeyVal = $_GET[$val['GET']['key']];
// check if this value is set as a valid GET Key value in the JSON array
if(!isset($val['GET']['values'][$GETKeyVal])) {
die($GETKeyVal .' is not a valid value for '.$val['GET']['key']);
}
// we have a value, so set it
$variations[$val['id']] = array(
'GETKeyVal' => $GETKeyVal,
'value' => $val['GET']['values'][$GETKeyVal]
);
} else {
// use the default
// $variations[$val['id']] = array(
// 'GETKeyVal' => 'default',
// 'value' => $val['GET']['values']['default']
// );
die('Missing a valid parameter for '.$val['GET']['key']);
}
}
/**
* 4. Set the identifier for each variation of the study.
* This is used to send to the log which variation of the study is being used.
*/
$identifier = '';
if(!empty($variations)) {
foreach($variations as $key => $val) {
// build the identifier. the value for controls will be "default"
$identifier .= (!empty($identifier) ? '_' : '') . $key .'_'. $val['GETKeyVal'];
}
}
// IMPORTANT: This is always necessary for every study.
define('IDENTIFIER', $identifier);
/**
* 5. Set the constants for the articles. These can be based on the $_GET values or just a simple string/bool value.
* These are used to display the articles.
*/
// Set our variation constants
foreach($config['variations'] as $key => $val) {
define($val['constant'], $variations[$val['id']]['value']);
}
// set the rest of the possible constants
$constants = array(
'AUTHOR_NAME' => $config['article']['author']['name'],
'AUTHOR_BIO' => $config['article']['author']['bio'],
'AUTHOR_PHOTO' => DIST_URL."/img/".$config['article']['author']['image']['src'],
'AUTHOR_PHOTO_ALT' => $config['article']['author']['image']['alt'],
'PUBDATE' => $config['article']['pubdate']
);
foreach($constants as $key => $val) {
if(!defined($key)) {
define($key, $val);
}
}
/**
* 6. NEXT STEPS: All done with the config! Now go and set all the constants you defined for the
* study wherever they need to get set. The main files you'll likely touch:
*
* 1. /articles/path-to-article/data.php - the "database" for the article
* 2. /articles/includes/main.php - the article template file
* 3. /article-list.html - the list of possible article links to make it easy for everyone to review
*/
// include the functions file
include ('inc/functions.php');