Skip to content

Commit e0d9a01

Browse files
author
Blake Bertuccelli
authored
Merge pull request #28 from bbertucc/mvp-1
🐣 MVP 1
2 parents 7dfef2c + 9bc2c6a commit e0d9a01

18 files changed

Lines changed: 867 additions & 918 deletions

actions/add_site.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
require_once '../config.php';
55
require_once '../models/adders.php';
66
require_once '../models/db.php';
7-
$db = connect(
8-
DB_HOST,
9-
DB_USERNAME,
10-
DB_PASSWORD,
11-
DB_NAME
12-
);
137

148
// We don't validate the URLs here because cURL does
159
// a better job of validating/redirecting in the adders.
@@ -37,7 +31,7 @@
3731
$status = 'active';
3832
$site = $curled_site['url'];
3933
$is_parent = 1;
40-
add_page($db, $site_url, $type, $status, $site, $is_parent );
34+
DataAccess::add_page($site_url, $type, $status, $site, $is_parent );
4135

4236
// WordPress and XML deals with adding pages similarly,
4337
// so their functions are wrapped in one condition.
@@ -56,7 +50,7 @@
5650
$site_url = $curled_site['url'];
5751

5852
// We're setting the status and adding pages here so we
59-
// do not have to call the $db inside "models/adders.php",
53+
// do not have to call the db inside "models/adders.php",
6054
// keeping each model focused on distinct functions.
6155
$pages_records = [];
6256
foreach ($pages as &$page):
@@ -98,7 +92,7 @@
9892
}
9993

10094
// Finalllly, we can add pages to the DB.
101-
add_pages($db, $pages_records);
95+
DataAccess::add_pages($pages_records);
10296

10397
// Since we're passing type through a URL, we have a fallback
10498
// in case someone passes an unsupported 'type'.

actions/delete_alert.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// Info on DB must be declared to use db.php models.
33
require_once '../config.php';
44
require_once '../models/db.php';
5-
$db = connect(
6-
DB_HOST,
7-
DB_USERNAME,
8-
DB_PASSWORD,
9-
DB_NAME
10-
);
115

126
// Get URL parameters.
137
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
@@ -24,7 +18,7 @@
2418
'name' => 'id',
2519
'value' => $id
2620
)];
27-
delete_alerts($db, $filters);
21+
DataAccess::delete_alerts($filters);
2822

2923
// When the work is done, we can triumphantly return to
3024
// wherever we came from.

actions/install.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
11
<?php
22
// Info on DB must be declared to use db.php models.
33
require_once 'models/db.php';
4-
$db = connect(
5-
DB_HOST,
6-
DB_USERNAME,
7-
DB_PASSWORD,
8-
DB_NAME
9-
);
104

115
// All the tables are created with this action.
12-
if(table_exists($db, 'alerts') == false)
13-
create_alerts_table($db);
14-
if(table_exists($db, 'pages') == false)
15-
create_pages_table($db);
16-
if(table_exists($db, 'scans') == false)
17-
create_scans_table($db);
18-
if(table_exists($db, 'meta') == false){
19-
create_meta_table($db);
6+
if(DataAccess::table_exists('alerts') == false)
7+
DataAccess::create_alerts_table();
8+
if(DataAccess::table_exists('pages') == false)
9+
DataAccess::create_pages_table();
10+
if(DataAccess::table_exists('scans') == false)
11+
DataAccess::create_scans_table();
12+
if(DataAccess::table_exists('meta') == false){
13+
DataAccess::create_meta_table();
2014

21-
// We need to add some meta to initialize the table
22-
// since we don't use the INSERT statement anywhere.
23-
add_meta($db, 'usage', 0);
15+
// We need to add some meta to initialize the table
16+
// since we don't use the INSERT statement anywhere.
17+
DataAccess::add_meta('usage', 0);
2418

2519
}

actions/scan_all_pages.php

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,18 @@
55
require_once '../models/db.php';
66
require_once '../models/view_components.php';
77
require_once '../models/integrations.php';
8-
$db = connect(
9-
DB_HOST,
10-
DB_USERNAME,
11-
DB_PASSWORD,
12-
DB_NAME
13-
);
8+
149

1510
// Setup queries to minize db calls.
16-
$meta = get_meta($db);
11+
$meta = DataAccess::get_meta();
1712
$page_filters = [
1813
array(
1914
'name' => 'status',
2015
'value' => 'active'
2116
),
2217
];
23-
$active_page_ids = get_page_ids($db, $page_filters);
24-
$active_pages = get_pages($db, $page_filters);
18+
$active_page_ids = DataAccess::get_page_ids($page_filters);
19+
$active_pages = DataAccess::get_pages($page_filters);
2520
$uploaded_integrations = uploaded_integrations('../integrations');
2621

2722
// Make sure there are pages to scan.
@@ -30,8 +25,8 @@
3025

3126
// Adding a scan to display a running task before scans complete.
3227
if( $_GET['action'] == 'add_scan' ){
33-
add_scan($db, 'running', $active_page_ids);
34-
$scans = get_scans($db);
28+
DataAccess::add_scan('running', $active_page_ids);
29+
$scans = DataAccess::get_scans();
3530
the_scan_rows($scans);
3631
}
3732

@@ -66,17 +61,14 @@
6661
try {
6762
$integration_scan_function_name($page, $meta);
6863

69-
// Only successful scans get their timestamp updated.
70-
update_page_scanned_time($db, $page->id);
71-
7264
} catch (Exception $x) {
7365

7466
// We will kill the scan and alert folks of any errors, but
7567
// we will also record the successful scans that occured.
76-
update_usage_meta($db, $pages_count);
77-
add_integration_alert($db, $x->getMessage());
78-
update_scan_status($db, 'running', 'incomplete');
79-
$scans = get_scans($db);
68+
DataAccess::update_usage_meta($pages_count);
69+
DataAccess::add_integration_alert($x->getMessage());
70+
DataAccess::update_scan_status('running', 'incomplete');
71+
$scans = DataAccess::get_scans();
8072
the_scan_rows($scans);
8173
die;
8274

@@ -86,6 +78,9 @@
8678

8779
}
8880
}
81+
82+
// Successful scans get a timestamp.
83+
DataAccess::update_page_scanned_time($page->id);
8984

9085
}
9186

@@ -94,18 +89,18 @@
9489
// pages.
9590
$pages_count = count($active_page_ids);
9691

97-
update_usage_meta($db, $pages_count);
98-
update_scan_status($db, 'running', 'complete');
92+
DataAccess::update_usage_meta($pages_count);
93+
DataAccess::update_scan_status('running', 'complete');
9994

10095
// Scan info is passed to JSON on the view, so that we can do
10196
// async scans.
102-
$scans = get_scans($db);
97+
$scans = DataAccess::get_scans();
10398
the_scan_rows($scans);
10499

105100
}
106101

107102
// This changes the little red number asyncronistically with JS
108103
// embedded in the view file.
109104
if( $_GET['action'] == 'get_alerts' ){
110-
echo count(get_alerts($db));
105+
echo count(DataAccess::get_alerts());
111106
}

actions/toggle_integration_status.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
require_once '../config.php';
44
require_once '../models/integrations.php';
55
require_once '../models/db.php';
6-
$db = connect(
7-
DB_HOST,
8-
DB_USERNAME,
9-
DB_PASSWORD,
10-
DB_NAME
11-
);
126

137
// Get URL parameters.
148
$uri = $_GET['uri'];
@@ -32,7 +26,7 @@
3226
'value' => $uri
3327
)
3428
];
35-
delete_alerts($db, $alerts_filter);
29+
DataAccess::delete_alerts($alerts_filter);
3630

3731
// Remove fields.
3832
$integration_fields = get_integration_fields($uri);
@@ -42,16 +36,16 @@
4236
// Delete "meta" fields.
4337
if( !empty($integration_db_fields['meta']) ){
4438
foreach($integration_db_fields['meta'] as $integration_meta_field){
45-
if(db_column_exists($db, 'meta', $integration_meta_field['name']))
46-
delete_db_column($db, 'meta', $integration_meta_field['name']);
39+
if(DataAccess::db_column_exists('meta', $integration_meta_field['name']))
40+
DataAccess::delete_db_column('meta', $integration_meta_field['name']);
4741
}
4842
}
4943

5044
// Delete "pages" fields.
5145
if( !empty($integration_db_fields['pages']) ){
5246
foreach($integration_db_fields['pages'] as $integration_pages_field){
53-
if(db_column_exists($db, 'pages', $integration_pages_field['name']))
54-
delete_db_column($db, 'pages', $integration_pages_field['name']);
47+
if(DataAccess::db_column_exists('pages', $integration_pages_field['name']))
48+
DataAccess::delete_db_column('pages', $integration_pages_field['name']);
5549
}
5650
}
5751

@@ -70,16 +64,16 @@
7064
// Setup "meta" fields.
7165
if( !empty($integration_db_fields['meta']) ){
7266
foreach($integration_db_fields['meta'] as $integration_meta_field){
73-
if(!db_column_exists($db, 'meta', $integration_meta_field['name']))
74-
add_db_column($db, 'meta', $integration_meta_field['name'], $integration_meta_field['type']);
67+
if(!DataAccess::db_column_exists('meta', $integration_meta_field['name']))
68+
DataAccess::add_db_column('meta', $integration_meta_field['name'], $integration_meta_field['type']);
7569
}
7670
}
7771

7872
// Setup "pages" fields.
7973
if( !empty($integration_db_fields['pages']) ){
8074
foreach($integration_db_fields['pages'] as $integration_pages_field){
81-
if(!db_column_exists($db, 'pages', $integration_pages_field['name']))
82-
add_db_column($db, 'pages', $integration_pages_field['name'], $integration_pages_field['type']);
75+
if(!DataAccess::db_column_exists('pages', $integration_pages_field['name']))
76+
DataAccess::add_db_column('pages', $integration_pages_field['name'], $integration_pages_field['type']);
8377
}
8478
}
8579

actions/toggle_page_status.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
require_once '../config.php';
44
require_once '../models/db.php';
55

6-
$db = connect(
7-
DB_HOST,
8-
DB_USERNAME,
9-
DB_PASSWORD,
10-
DB_NAME
11-
);
12-
136
// Get URL variables and fallbacks.
147
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
158
if(empty($id))
@@ -19,9 +12,9 @@
1912
throw new Exception('Status is not specfied for page "'.$id.'"');
2013

2114
// Toggle page status.
22-
$site = get_page($db, $id)->site;
15+
$site = DataAccess::get_page($id)->site;
2316
if($old_status == 'active'){
24-
update_site_status($db, $site, 'archived');
17+
DataAccess::update_site_status($site, 'archived');
2518

2619
// Alerts are deleted when a page is archived.
2720
$filters = [
@@ -30,11 +23,11 @@
3023
'value' => $site
3124
)
3225
];
33-
delete_alerts($db, $filters);
26+
DataAccess::delete_alerts($filters);
3427

3528
}
3629
if($old_status == 'archived'){
37-
update_site_status($db, $site, 'active');
30+
DataAccess::update_site_status($site, 'active');
3831
}
3932

4033
// Redirect

actions/update_meta.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
// Add DB Info
33
require_once '../config.php';
44
require_once '../models/db.php';
5-
$db = connect(
6-
DB_HOST,
7-
DB_USERNAME,
8-
DB_PASSWORD,
9-
DB_NAME
10-
);
115

126
// We need the last view, so we can redirect on success.
137
if(!empty($_POST['last_view'])){
@@ -33,5 +27,5 @@
3327
};
3428

3529
// Time to update meta and redirect!
36-
update_meta($db, $account_records);
30+
DataAccess::update_meta($account_records);
3731
header('Location: ../index.php?view='.$last_view.'&status=success');

index.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
require_once 'models/view_components.php';
77
require_once 'models/integrations.php';
88

9-
// Setup DB Connection
10-
$db = connect(
11-
DB_HOST,
12-
DB_USERNAME,
13-
DB_PASSWORD,
14-
DB_NAME
15-
);
169
$records = [];
1710
?>
1811

@@ -56,7 +49,7 @@
5649
<span class="badge bg-danger float-end">
5750
<span id="alert_count">
5851

59-
<?php echo count(get_alerts($db));?>
52+
<?php echo count(DataAccess::get_alerts());?>
6053

6154
</span>
6255
</span>
@@ -84,12 +77,12 @@
8477
<?php
8578
// As soon as you use Equalify, you know the toll
8679
// you will be asked to support the service.
87-
if(!empty(get_meta($db)->usage)):
80+
if(!empty(DataAccess::get_meta()->usage)):
8881
?>
8982

9083
<div class="border-top mt-3 pt-3">
9184
<p>
92-
🎉 <strong><?php echo get_meta($db)->usage;?> pages scanned.</strong>
85+
🎉 <strong><?php echo DataAccess::get_meta()->usage;?> pages scanned.</strong>
9386
</p>
9487
<p>
9588
<script type="text/javascript" defer src="https://donorbox.org/install-popup-button.js"></script>

integrations/little_forrest/functions.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Name: Little Forrest
44
* Description: Counts WCAG 2.1 errors and links to page reports.
5-
* Status: Disabled
5+
* Status: Active
66
*/
77

88
/**
@@ -40,12 +40,6 @@ function little_forrest_scans($page, $meta){
4040
// Add DB info and required functions.
4141
require_once '../config.php';
4242
require_once '../models/db.php';
43-
$db = connect(
44-
DB_HOST,
45-
DB_USERNAME,
46-
DB_PASSWORD,
47-
DB_NAME
48-
);
4943

5044
// Get Little Forrest data.
5145
$override_https = array(
@@ -82,13 +76,13 @@ function little_forrest_scans($page, $meta){
8276
'value' => 'little_forrest'
8377
)
8478
];
85-
delete_alerts($db, $alerts_filter);
79+
DataAccess::delete_alerts($alerts_filter);
8680

8781
// Set optional alerts.
8882
if($little_forrest_errors >= 1)
89-
add_page_alert($db, $page->id, $page->site,'little_forrest', 'WCAG 2.1 page errors found! See <a href="https://inspector.littleforest.co.uk/InspectorWS/Inspector?url='.$page->url.'&lang=auto&cache=false" target="_blank">Little Forrest report</a>.');
83+
DataAccess::add_page_alert($page->id, $page->site,'little_forrest', 'WCAG 2.1 page errors found! See <a href="https://inspector.littleforest.co.uk/InspectorWS/Inspector?url='.$page->url.'&lang=auto&cache=false" target="_blank">Little Forrest report</a>.');
9084

9185
// Update page data.
92-
update_page_data($db, $page->id, 'little_forrest_wcag_2_1_errors', $little_forrest_errors);
86+
DataAccess::update_page_data($page->id, 'little_forrest_wcag_2_1_errors', $little_forrest_errors);
9387

9488
}

0 commit comments

Comments
 (0)