@@ -5,22 +5,22 @@ |
||
5 | 5 | final class TermsController extends DefaultPageController |
6 | 6 | { |
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
10 | - $this->set_title("Terms of Use for Jacob Emerick's Sites"); |
|
11 | - $this->set_description("Some basic (and boring) legal jargon and perferred usage of the content on Jacob Emerick's sites. Includes re-use terms and advice on retracing hikes."); |
|
12 | - $this->set_keywords(array('terms of use', 'legal', 'accountability', 'trespassing', 'Jacob Emerick')); |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | + $this->set_title("Terms of Use for Jacob Emerick's Sites"); |
|
11 | + $this->set_description("Some basic (and boring) legal jargon and perferred usage of the content on Jacob Emerick's sites. Includes re-use terms and advice on retracing hikes."); |
|
12 | + $this->set_keywords(array('terms of use', 'legal', 'accountability', 'trespassing', 'Jacob Emerick')); |
|
13 | 13 | |
14 | - parent::set_head_data(); |
|
15 | - } |
|
14 | + parent::set_head_data(); |
|
15 | + } |
|
16 | 16 | |
17 | - protected function set_body_data() |
|
18 | - { |
|
19 | - $this->set_body('top_data', array('title' => 'Terms of Use')); |
|
17 | + protected function set_body_data() |
|
18 | + { |
|
19 | + $this->set_body('top_data', array('title' => 'Terms of Use')); |
|
20 | 20 | |
21 | - $this->set_body('body_view', 'Terms'); |
|
21 | + $this->set_body('body_view', 'Terms'); |
|
22 | 22 | |
23 | - parent::set_body_data(); |
|
24 | - } |
|
23 | + parent::set_body_data(); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | } |
@@ -7,42 +7,42 @@ |
||
7 | 7 | final class ChangelogController extends DefaultPageController |
8 | 8 | { |
9 | 9 | |
10 | - protected function set_head_data() |
|
11 | - { |
|
12 | - $this->set_title("Changelog for Jacob Emerick's Sites"); |
|
13 | - $this->set_description("Listing of the last changes done on the framework behind Jacob Emerick's websites. Yeah, he's down with that version control."); |
|
14 | - $this->set_keywords(array('changelog', 'version control', 'code', 'comments', 'Jacob Emerick')); |
|
10 | + protected function set_head_data() |
|
11 | + { |
|
12 | + $this->set_title("Changelog for Jacob Emerick's Sites"); |
|
13 | + $this->set_description("Listing of the last changes done on the framework behind Jacob Emerick's websites. Yeah, he's down with that version control."); |
|
14 | + $this->set_keywords(array('changelog', 'version control', 'code', 'comments', 'Jacob Emerick')); |
|
15 | 15 | |
16 | - parent::set_head_data(); |
|
17 | - } |
|
16 | + parent::set_head_data(); |
|
17 | + } |
|
18 | 18 | |
19 | - protected function set_body_data() |
|
20 | - { |
|
21 | - parent::set_body_data(); |
|
19 | + protected function set_body_data() |
|
20 | + { |
|
21 | + parent::set_body_data(); |
|
22 | 22 | |
23 | - $this->set_body('top_data', array('title' => 'Change Log')); |
|
23 | + $this->set_body('top_data', array('title' => 'Change Log')); |
|
24 | 24 | |
25 | - $this->set_body('body_data', $this->get_changelog()); |
|
26 | - $this->set_body('body_view', 'Changelog'); |
|
27 | - } |
|
25 | + $this->set_body('body_data', $this->get_changelog()); |
|
26 | + $this->set_body('body_view', 'Changelog'); |
|
27 | + } |
|
28 | 28 | |
29 | - private function get_changelog() |
|
30 | - { |
|
29 | + private function get_changelog() |
|
30 | + { |
|
31 | 31 | global $container; |
32 | 32 | $changelogRepository = new MysqlChangelogRepository($container['db_connection_locator']); |
33 | 33 | $changelog_result = $changelogRepository->getChanges(40); |
34 | 34 | |
35 | - foreach($changelog_result as $change) |
|
36 | - { |
|
37 | - $changelog[] = (object) array( |
|
38 | - 'date' => (object) array( |
|
39 | - 'stamp' => date('c', strtotime($change['datetime'])), |
|
40 | - 'short' => date('M j', strtotime($change['datetime'])), |
|
41 | - 'friendly' => date('F j, Y g:i A', strtotime($change['datetime']))), |
|
42 | - 'message' => $change['message_short']); |
|
43 | - } |
|
35 | + foreach($changelog_result as $change) |
|
36 | + { |
|
37 | + $changelog[] = (object) array( |
|
38 | + 'date' => (object) array( |
|
39 | + 'stamp' => date('c', strtotime($change['datetime'])), |
|
40 | + 'short' => date('M j', strtotime($change['datetime'])), |
|
41 | + 'friendly' => date('F j, Y g:i A', strtotime($change['datetime']))), |
|
42 | + 'message' => $change['message_short']); |
|
43 | + } |
|
44 | 44 | |
45 | - return array('changelog' => $changelog); |
|
46 | - } |
|
45 | + return array('changelog' => $changelog); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | } |
@@ -5,68 +5,68 @@ |
||
5 | 5 | abstract class DefaultPageController extends PageController |
6 | 6 | { |
7 | 7 | |
8 | - private static $MENU = array( |
|
9 | - array( |
|
10 | - 'name' => 'About', |
|
11 | - 'uri' => ''), |
|
12 | - array( |
|
13 | - 'name' => 'Terms', |
|
14 | - 'uri' => 'terms'), |
|
15 | - array( |
|
16 | - 'name' => 'Change Log', |
|
17 | - 'uri' => 'change-log'), |
|
18 | - array( |
|
19 | - 'name' => 'Contact', |
|
20 | - 'uri' => 'contact')); |
|
8 | + private static $MENU = array( |
|
9 | + array( |
|
10 | + 'name' => 'About', |
|
11 | + 'uri' => ''), |
|
12 | + array( |
|
13 | + 'name' => 'Terms', |
|
14 | + 'uri' => 'terms'), |
|
15 | + array( |
|
16 | + 'name' => 'Change Log', |
|
17 | + 'uri' => 'change-log'), |
|
18 | + array( |
|
19 | + 'name' => 'Contact', |
|
20 | + 'uri' => 'contact')); |
|
21 | 21 | |
22 | - protected function set_head_data() |
|
23 | - { |
|
24 | - $this->add_css('reset'); |
|
25 | - $this->add_css('site'); |
|
26 | - } |
|
22 | + protected function set_head_data() |
|
23 | + { |
|
24 | + $this->add_css('reset'); |
|
25 | + $this->add_css('site'); |
|
26 | + } |
|
27 | 27 | |
28 | - protected function set_body_data() |
|
29 | - { |
|
30 | - $this->set_body('top_data', array()); |
|
31 | - $this->set_body('body_data', array()); |
|
28 | + protected function set_body_data() |
|
29 | + { |
|
30 | + $this->set_body('top_data', array()); |
|
31 | + $this->set_body('body_data', array()); |
|
32 | 32 | |
33 | - $this->set_body('left_side_data', array('menu' => $this->get_menu())); |
|
33 | + $this->set_body('left_side_data', array('menu' => $this->get_menu())); |
|
34 | 34 | |
35 | - $this->set_body('activity_array', $this->get_recent_activity()); |
|
36 | - $this->set_body_view('Page'); |
|
37 | - } |
|
35 | + $this->set_body('activity_array', $this->get_recent_activity()); |
|
36 | + $this->set_body_view('Page'); |
|
37 | + } |
|
38 | 38 | |
39 | - private function get_menu() |
|
40 | - { |
|
41 | - $active_page = $this->get_active_page(); |
|
39 | + private function get_menu() |
|
40 | + { |
|
41 | + $active_page = $this->get_active_page(); |
|
42 | 42 | |
43 | - $menu = array(); |
|
44 | - foreach(self::$MENU as $item) |
|
45 | - { |
|
46 | - $menu[] = (object) array( |
|
47 | - 'name' => $item['name'], |
|
48 | - 'uri' => (strlen($item['uri']) > 0) ? "/{$item['uri']}/" : '/', |
|
49 | - 'is_active' => ($item['name'] == $active_page)); |
|
50 | - } |
|
43 | + $menu = array(); |
|
44 | + foreach(self::$MENU as $item) |
|
45 | + { |
|
46 | + $menu[] = (object) array( |
|
47 | + 'name' => $item['name'], |
|
48 | + 'uri' => (strlen($item['uri']) > 0) ? "/{$item['uri']}/" : '/', |
|
49 | + 'is_active' => ($item['name'] == $active_page)); |
|
50 | + } |
|
51 | 51 | |
52 | - return $menu; |
|
53 | - } |
|
52 | + return $menu; |
|
53 | + } |
|
54 | 54 | |
55 | - private function get_active_page() |
|
56 | - { |
|
57 | - $current_uri = URLDecode::getPiece(1); |
|
55 | + private function get_active_page() |
|
56 | + { |
|
57 | + $current_uri = URLDecode::getPiece(1); |
|
58 | 58 | |
59 | - if(!isset($current_uri)) |
|
60 | - return 'About'; |
|
59 | + if(!isset($current_uri)) |
|
60 | + return 'About'; |
|
61 | 61 | |
62 | - $menu = self::$MENU; |
|
63 | - foreach($menu as $link) |
|
64 | - { |
|
65 | - if($link['uri'] == $current_uri) |
|
66 | - return $link['name']; |
|
67 | - } |
|
62 | + $menu = self::$MENU; |
|
63 | + foreach($menu as $link) |
|
64 | + { |
|
65 | + if($link['uri'] == $current_uri) |
|
66 | + return $link['name']; |
|
67 | + } |
|
68 | 68 | |
69 | - return 'About'; |
|
70 | - } |
|
69 | + return 'About'; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
@@ -2,62 +2,62 @@ |
||
2 | 2 | |
3 | 3 | Loader::load('controller', 'site/DefaultPageController'); |
4 | 4 | Loader::load('utility', array( |
5 | - 'Validate')); |
|
5 | + 'Validate')); |
|
6 | 6 | |
7 | 7 | final class ContactController extends DefaultPageController |
8 | 8 | { |
9 | 9 | |
10 | - protected function set_head_data() |
|
11 | - { |
|
12 | - $this->set_title("Contact Form for Jacob Emerick's Sites"); |
|
13 | - $this->set_description("Want to reach out to Jacob Emerick with questions or concerns? Well, then here's a handy contact form for you that will connect you with the man himself."); |
|
14 | - $this->set_keywords(array('contact', 'webmaster', 'support', 'help', 'Jacob Emerick')); |
|
10 | + protected function set_head_data() |
|
11 | + { |
|
12 | + $this->set_title("Contact Form for Jacob Emerick's Sites"); |
|
13 | + $this->set_description("Want to reach out to Jacob Emerick with questions or concerns? Well, then here's a handy contact form for you that will connect you with the man himself."); |
|
14 | + $this->set_keywords(array('contact', 'webmaster', 'support', 'help', 'Jacob Emerick')); |
|
15 | 15 | |
16 | - parent::set_head_data(); |
|
17 | - } |
|
16 | + parent::set_head_data(); |
|
17 | + } |
|
18 | 18 | |
19 | - protected function set_body_data() |
|
20 | - { |
|
21 | - parent::set_body_data(); |
|
19 | + protected function set_body_data() |
|
20 | + { |
|
21 | + parent::set_body_data(); |
|
22 | 22 | |
23 | - $this->set_body('top_data', array('title' => 'Contact Me')); |
|
23 | + $this->set_body('top_data', array('title' => 'Contact Me')); |
|
24 | 24 | |
25 | - $this->set_body('body_data', $this->get_form_results()); |
|
26 | - $this->set_body('body_view', 'Contact'); |
|
27 | - } |
|
28 | - |
|
29 | - private function get_form_results() |
|
30 | - { |
|
31 | - if(!Request::hasPost()) |
|
32 | - return array(); |
|
25 | + $this->set_body('body_data', $this->get_form_results()); |
|
26 | + $this->set_body('body_view', 'Contact'); |
|
27 | + } |
|
28 | + |
|
29 | + private function get_form_results() |
|
30 | + { |
|
31 | + if(!Request::hasPost()) |
|
32 | + return array(); |
|
33 | 33 | |
34 | - if(!Validate::checkRequest('post', 'name', 'string')) |
|
35 | - $error_message['name'] = 'Please enter a value for your name.'; |
|
36 | - if(!Validate::checkRequest('post', 'email', 'string')) |
|
37 | - $error_message['email'] = 'Please enter a valid email address.'; |
|
38 | - if(!Validate::checkRequest('post', 'message', 'string')) |
|
39 | - $error_message['message'] = 'Please enter a message.'; |
|
34 | + if(!Validate::checkRequest('post', 'name', 'string')) |
|
35 | + $error_message['name'] = 'Please enter a value for your name.'; |
|
36 | + if(!Validate::checkRequest('post', 'email', 'string')) |
|
37 | + $error_message['email'] = 'Please enter a valid email address.'; |
|
38 | + if(!Validate::checkRequest('post', 'message', 'string')) |
|
39 | + $error_message['message'] = 'Please enter a message.'; |
|
40 | 40 | |
41 | - if(!empty($error_message)) |
|
42 | - { |
|
43 | - return array( |
|
44 | - 'error_message' => $error_message, |
|
45 | - 'value' => Request::getPost()); |
|
46 | - } |
|
41 | + if(!empty($error_message)) |
|
42 | + { |
|
43 | + return array( |
|
44 | + 'error_message' => $error_message, |
|
45 | + 'value' => Request::getPost()); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | global $container; |
49 | 49 | $sent = $container['mail'] |
50 | - ->addTo($container['config']->admin_email) |
|
51 | - ->setSubject('Site Contact') |
|
52 | - ->setPlainMessage( |
|
50 | + ->addTo($container['config']->admin_email) |
|
51 | + ->setSubject('Site Contact') |
|
52 | + ->setPlainMessage( |
|
53 | 53 | 'Name: ' . Request::getPost('name') . "\n" . |
54 | 54 | 'Email: ' . Request::getPost('email') . "\n" . |
55 | 55 | 'Message: ' . Request::getPost('message') |
56 | - ) |
|
57 | - ->send(); |
|
56 | + ) |
|
57 | + ->send(); |
|
58 | 58 | |
59 | - return array( |
|
60 | - 'success_message' => "Thank you for your message, " . Request::getPost('name') . "! I'll get back to you as soon as possible."); |
|
61 | - } |
|
59 | + return array( |
|
60 | + 'success_message' => "Thank you for your message, " . Request::getPost('name') . "! I'll get back to you as soon as possible."); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -5,20 +5,20 @@ |
||
5 | 5 | final class HomeController extends DefaultPageController |
6 | 6 | { |
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
10 | - $this->set_title("Jacob Emerick's Site Information | General and Technical Information"); |
|
11 | - $this->set_description("Meta information about Jacob Emerick's websites and content. Introduces the man behind the code, discusses the reasons behind the sites, and goes into some technical background of the custom framework."); |
|
12 | - $this->set_keywords(array('site', 'technical', 'support', 'help', 'information', 'Jacob Emerick')); |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | + $this->set_title("Jacob Emerick's Site Information | General and Technical Information"); |
|
11 | + $this->set_description("Meta information about Jacob Emerick's websites and content. Introduces the man behind the code, discusses the reasons behind the sites, and goes into some technical background of the custom framework."); |
|
12 | + $this->set_keywords(array('site', 'technical', 'support', 'help', 'information', 'Jacob Emerick')); |
|
13 | 13 | |
14 | - parent::set_head_data(); |
|
15 | - } |
|
14 | + parent::set_head_data(); |
|
15 | + } |
|
16 | 16 | |
17 | - protected function set_body_data() |
|
18 | - { |
|
19 | - $this->set_body('body_view', 'Home'); |
|
17 | + protected function set_body_data() |
|
18 | + { |
|
19 | + $this->set_body('body_view', 'Home'); |
|
20 | 20 | |
21 | - parent::set_body_data(); |
|
22 | - } |
|
21 | + parent::set_body_data(); |
|
22 | + } |
|
23 | 23 | |
24 | 24 | } |
25 | 25 | \ No newline at end of file |
@@ -5,13 +5,13 @@ |
||
5 | 5 | class Error303Controller extends PageController |
6 | 6 | { |
7 | 7 | |
8 | - public function __construct($uri) |
|
9 | - { |
|
10 | - Header::redirect($uri, 303); |
|
11 | - exit; |
|
12 | - } |
|
8 | + public function __construct($uri) |
|
9 | + { |
|
10 | + Header::redirect($uri, 303); |
|
11 | + exit; |
|
12 | + } |
|
13 | 13 | |
14 | - protected function set_head_data() {} |
|
15 | - protected function set_body_data() {} |
|
14 | + protected function set_head_data() {} |
|
15 | + protected function set_body_data() {} |
|
16 | 16 | |
17 | 17 | } |
@@ -5,58 +5,58 @@ |
||
5 | 5 | class Error404Controller extends PageController |
6 | 6 | { |
7 | 7 | |
8 | - protected function set_head_data() |
|
9 | - { |
|
10 | - $this->set_header_method('send404'); |
|
11 | - $this->add_css('normalize'); |
|
12 | - $this->add_css('404'); |
|
8 | + protected function set_head_data() |
|
9 | + { |
|
10 | + $this->set_header_method('send404'); |
|
11 | + $this->add_css('normalize'); |
|
12 | + $this->add_css('404'); |
|
13 | 13 | |
14 | - $this->set_title("Jacob Emerick's 404 Page"); |
|
15 | - $this->set_head('description', 'Global 404 page for sites under jacobemerick.com. Page not found!'); |
|
16 | - $this->set_head('keywords', ''); |
|
17 | - } |
|
14 | + $this->set_title("Jacob Emerick's 404 Page"); |
|
15 | + $this->set_head('description', 'Global 404 page for sites under jacobemerick.com. Page not found!'); |
|
16 | + $this->set_head('keywords', ''); |
|
17 | + } |
|
18 | 18 | |
19 | - protected function set_body_data() |
|
20 | - { |
|
21 | - $this->set_body('site_list', $this->get_sites()); |
|
19 | + protected function set_body_data() |
|
20 | + { |
|
21 | + $this->set_body('site_list', $this->get_sites()); |
|
22 | 22 | |
23 | - $this->set_body_view('/404'); |
|
24 | - } |
|
23 | + $this->set_body_view('/404'); |
|
24 | + } |
|
25 | 25 | |
26 | - private function get_sites() |
|
27 | - { |
|
26 | + private function get_sites() |
|
27 | + { |
|
28 | 28 | return [ |
29 | - [ |
|
29 | + [ |
|
30 | 30 | 'url' => 'https://home.jacobemerick.com/', |
31 | 31 | 'title' => "Jacob Emerick's Home", |
32 | 32 | 'name' => 'Home' |
33 | - ], |
|
34 | - [ |
|
33 | + ], |
|
34 | + [ |
|
35 | 35 | 'url' => 'https://blog.jacobemerick.com/', |
36 | 36 | 'title' => "Jacob Emerick's Blog", |
37 | 37 | 'name' => 'Blog' |
38 | - ], |
|
39 | - [ |
|
38 | + ], |
|
39 | + [ |
|
40 | 40 | 'url' => 'https://lifestream.jacobemerick.com/', |
41 | 41 | 'title' => "Jacob Emerick's Lifestream", |
42 | 42 | 'name' => 'Lifestream' |
43 | - ], |
|
44 | - [ |
|
43 | + ], |
|
44 | + [ |
|
45 | 45 | 'url' => 'https://map.jacobemerick.com/', |
46 | 46 | 'title' => "Jacob Emerick's Hiking Map", |
47 | 47 | 'name' => 'Map' |
48 | - ], |
|
49 | - [ |
|
48 | + ], |
|
49 | + [ |
|
50 | 50 | 'url' => 'https://portfolio.jacobemerick.com/', |
51 | 51 | 'title' => "Jacob Emerick's Portfolio", |
52 | 52 | 'name' => 'Portfolio', |
53 | - ], |
|
54 | - [ |
|
53 | + ], |
|
54 | + [ |
|
55 | 55 | 'url' => 'https://www.waterfallsofthekeweenaw.com/', |
56 | 56 | 'title' => 'Waterfalls of the Keweenaw', |
57 | 57 | 'name' => 'Waterfalls' |
58 | - ] |
|
59 | - ]; |
|
60 | - } |
|
58 | + ] |
|
59 | + ]; |
|
60 | + } |
|
61 | 61 | |
62 | 62 | } |
@@ -3,35 +3,35 @@ discard block |
||
3 | 3 | class URLDecode |
4 | 4 | { |
5 | 5 | |
6 | - private static $array = array(); |
|
6 | + private static $array = array(); |
|
7 | 7 | |
8 | - static function init() |
|
9 | - { |
|
10 | - $host = $_SERVER['HTTP_HOST']; |
|
11 | - $uri = $_SERVER['REQUEST_URI']; |
|
12 | - self::form_url_array($host, $uri); |
|
13 | - } |
|
8 | + static function init() |
|
9 | + { |
|
10 | + $host = $_SERVER['HTTP_HOST']; |
|
11 | + $uri = $_SERVER['REQUEST_URI']; |
|
12 | + self::form_url_array($host, $uri); |
|
13 | + } |
|
14 | 14 | |
15 | - static private function form_url_array($host, $uri) |
|
16 | - { |
|
17 | - $uri = substr($uri, 1); |
|
18 | - if(strpos($uri, '?')) |
|
19 | - $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | - $uri_array = explode('/', $uri); |
|
15 | + static private function form_url_array($host, $uri) |
|
16 | + { |
|
17 | + $uri = substr($uri, 1); |
|
18 | + if(strpos($uri, '?')) |
|
19 | + $uri = substr($uri, 0, strpos($uri, '?')); |
|
20 | + $uri_array = explode('/', $uri); |
|
21 | 21 | |
22 | - if(!Loader::isLive()) |
|
23 | - $host = substr($host, strpos($host, '.') + 1); |
|
22 | + if(!Loader::isLive()) |
|
23 | + $host = substr($host, strpos($host, '.') + 1); |
|
24 | 24 | |
25 | - self::$array['host'] = $host; |
|
25 | + self::$array['host'] = $host; |
|
26 | 26 | |
27 | 27 | if ( |
28 | - $host == 'www.waterfallsofthekeweenaw.com' || |
|
28 | + $host == 'www.waterfallsofthekeweenaw.com' || |
|
29 | 29 | $host == 'waterfallsofthekeweenaw.com' |
30 | 30 | ) { |
31 | - self::$array['site'] = 'waterfalls'; |
|
32 | - } else { |
|
33 | - self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | - } |
|
31 | + self::$array['site'] = 'waterfalls'; |
|
32 | + } else { |
|
33 | + self::$array['site'] = substr($host, 0, strpos($host, '.')); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $base = ''; |
37 | 37 | $base .= (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http'; |
@@ -40,55 +40,55 @@ discard block |
||
40 | 40 | $base .= $host; |
41 | 41 | $base .= '/'; |
42 | 42 | |
43 | - self::$array['base'] = $base; |
|
44 | - self::$array['uri'] = '/' . implode('/', $uri_array); |
|
43 | + self::$array['base'] = $base; |
|
44 | + self::$array['uri'] = '/' . implode('/', $uri_array); |
|
45 | 45 | |
46 | - if(end($uri_array) == '') |
|
47 | - $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | - self::$array['pieces'] = (array) $uri_array; |
|
49 | - } |
|
46 | + if(end($uri_array) == '') |
|
47 | + $uri_array = array_slice($uri_array, 0, count($uri_array) - 1); |
|
48 | + self::$array['pieces'] = (array) $uri_array; |
|
49 | + } |
|
50 | 50 | |
51 | - static function getSite() |
|
52 | - { |
|
53 | - return self::$array['site']; |
|
54 | - } |
|
51 | + static function getSite() |
|
52 | + { |
|
53 | + return self::$array['site']; |
|
54 | + } |
|
55 | 55 | |
56 | - static function getHost() |
|
57 | - { |
|
58 | - return self::$array['host']; |
|
59 | - } |
|
56 | + static function getHost() |
|
57 | + { |
|
58 | + return self::$array['host']; |
|
59 | + } |
|
60 | 60 | |
61 | - static function getBase() |
|
62 | - { |
|
63 | - return self::$array['base']; |
|
64 | - } |
|
61 | + static function getBase() |
|
62 | + { |
|
63 | + return self::$array['base']; |
|
64 | + } |
|
65 | 65 | |
66 | - static function getURI() |
|
67 | - { |
|
68 | - return self::$array['uri']; |
|
69 | - } |
|
66 | + static function getURI() |
|
67 | + { |
|
68 | + return self::$array['uri']; |
|
69 | + } |
|
70 | 70 | |
71 | - static function getExtension() |
|
72 | - { |
|
73 | - $file = self::getPiece(-1); |
|
74 | - if(substr($file, -1) == '/') |
|
75 | - return false; |
|
76 | - return substr($file, strrpos($file, '.') + 1);; |
|
77 | - } |
|
71 | + static function getExtension() |
|
72 | + { |
|
73 | + $file = self::getPiece(-1); |
|
74 | + if(substr($file, -1) == '/') |
|
75 | + return false; |
|
76 | + return substr($file, strrpos($file, '.') + 1);; |
|
77 | + } |
|
78 | 78 | |
79 | - static function getPiece($piece = null) |
|
80 | - { |
|
81 | - if(!$piece) |
|
82 | - return self::$array['pieces']; |
|
79 | + static function getPiece($piece = null) |
|
80 | + { |
|
81 | + if(!$piece) |
|
82 | + return self::$array['pieces']; |
|
83 | 83 | |
84 | - if($piece == -1) |
|
85 | - return end(self::$array['pieces']); |
|
84 | + if($piece == -1) |
|
85 | + return end(self::$array['pieces']); |
|
86 | 86 | |
87 | - $piece = $piece - 1; |
|
88 | - if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | - return self::$array['pieces'][$piece]; |
|
90 | - return; |
|
91 | - } |
|
87 | + $piece = $piece - 1; |
|
88 | + if(array_key_exists($piece, self::$array['pieces'])) |
|
89 | + return self::$array['pieces'][$piece]; |
|
90 | + return; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | } |
94 | 94 |
@@ -3,19 +3,19 @@ discard block |
||
3 | 3 | final class Database |
4 | 4 | { |
5 | 5 | |
6 | - private $read_connection; |
|
7 | - private $write_connection; |
|
8 | - private $query_log = array(); |
|
9 | - private $query_total = array( |
|
10 | - 'count' => 0, |
|
11 | - 'time' => 0); |
|
6 | + private $read_connection; |
|
7 | + private $write_connection; |
|
8 | + private $query_log = array(); |
|
9 | + private $query_total = array( |
|
10 | + 'count' => 0, |
|
11 | + 'time' => 0); |
|
12 | 12 | |
13 | - private $has_connection_error = false; |
|
13 | + private $has_connection_error = false; |
|
14 | 14 | |
15 | - private static $instance; |
|
15 | + private static $instance; |
|
16 | 16 | |
17 | - private function __construct($write_params, $read_params) |
|
18 | - { |
|
17 | + private function __construct($write_params, $read_params) |
|
18 | + { |
|
19 | 19 | $this->write_connection = $this->connect( |
20 | 20 | $write_params->host, |
21 | 21 | $write_params->user, |
@@ -28,23 +28,23 @@ discard block |
||
28 | 28 | $read_params->password |
29 | 29 | ); |
30 | 30 | |
31 | - return $this; |
|
32 | - } |
|
31 | + return $this; |
|
32 | + } |
|
33 | 33 | |
34 | - private function connect($host, $username, $password) |
|
35 | - { |
|
36 | - $mysqli = new mysqli($host, $username, $password); |
|
34 | + private function connect($host, $username, $password) |
|
35 | + { |
|
36 | + $mysqli = new mysqli($host, $username, $password); |
|
37 | 37 | |
38 | - $has_connection_error = $mysqli->connect_error; |
|
39 | - if(isset($has_connection_error)) |
|
40 | - $this->has_connection_error = true; |
|
38 | + $has_connection_error = $mysqli->connect_error; |
|
39 | + if(isset($has_connection_error)) |
|
40 | + $this->has_connection_error = true; |
|
41 | 41 | |
42 | - return $mysqli; |
|
43 | - } |
|
42 | + return $mysqli; |
|
43 | + } |
|
44 | 44 | |
45 | - public static function instance() |
|
46 | - { |
|
47 | - if(!isset(self::$instance)) { |
|
45 | + public static function instance() |
|
46 | + { |
|
47 | + if(!isset(self::$instance)) { |
|
48 | 48 | global $config; |
49 | 49 | self::$instance = new Database( |
50 | 50 | $config->database->master, |
@@ -52,107 +52,107 @@ discard block |
||
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | - return self::$instance; |
|
56 | - } |
|
57 | - |
|
58 | - public static function escape($string) |
|
59 | - { |
|
60 | - return self::instance()->read_connection->real_escape_string($string); |
|
61 | - } |
|
62 | - |
|
63 | - public static function select($query) |
|
64 | - { |
|
65 | - $start = microtime(true); |
|
66 | - if($result = self::instance()->read_connection->query($query)) |
|
67 | - { |
|
68 | - self::instance()->log_query($query, $start); |
|
69 | - $array = array(); |
|
70 | - while($row = $result->fetch_object()) |
|
71 | - $array[] = $row; |
|
72 | - $result->close(); |
|
73 | - return $array; |
|
74 | - } |
|
75 | - trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
76 | - return false; |
|
77 | - } |
|
78 | - |
|
79 | - public static function selectRow($query) |
|
80 | - { |
|
81 | - $result = self::select($query); |
|
82 | - if(is_array($result)) |
|
83 | - return array_pop($result); |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - public static function execute($query) |
|
88 | - { |
|
89 | - $start = microtime(true); |
|
90 | - if(self::instance()->write_connection->query($query)) |
|
91 | - { |
|
92 | - self::instance()->log_query($query, $start); |
|
93 | - return true; |
|
94 | - } |
|
95 | - trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - public static function lastInsertID() |
|
100 | - { |
|
101 | - $id = self::instance()->write_connection->insert_id; |
|
102 | - if($id == 0) |
|
103 | - return false; |
|
104 | - return $id; |
|
105 | - } |
|
106 | - |
|
107 | - private function log_query($query, $start) |
|
108 | - { |
|
109 | - $time = (microtime(true) - $start) * 1000; |
|
110 | - $query = array( |
|
111 | - 'sql' => $query, |
|
112 | - 'time' => $time); |
|
113 | - array_push($this->query_log, $query); |
|
55 | + return self::$instance; |
|
56 | + } |
|
57 | + |
|
58 | + public static function escape($string) |
|
59 | + { |
|
60 | + return self::instance()->read_connection->real_escape_string($string); |
|
61 | + } |
|
62 | + |
|
63 | + public static function select($query) |
|
64 | + { |
|
65 | + $start = microtime(true); |
|
66 | + if($result = self::instance()->read_connection->query($query)) |
|
67 | + { |
|
68 | + self::instance()->log_query($query, $start); |
|
69 | + $array = array(); |
|
70 | + while($row = $result->fetch_object()) |
|
71 | + $array[] = $row; |
|
72 | + $result->close(); |
|
73 | + return $array; |
|
74 | + } |
|
75 | + trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
76 | + return false; |
|
77 | + } |
|
78 | + |
|
79 | + public static function selectRow($query) |
|
80 | + { |
|
81 | + $result = self::select($query); |
|
82 | + if(is_array($result)) |
|
83 | + return array_pop($result); |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + public static function execute($query) |
|
88 | + { |
|
89 | + $start = microtime(true); |
|
90 | + if(self::instance()->write_connection->query($query)) |
|
91 | + { |
|
92 | + self::instance()->log_query($query, $start); |
|
93 | + return true; |
|
94 | + } |
|
95 | + trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + public static function lastInsertID() |
|
100 | + { |
|
101 | + $id = self::instance()->write_connection->insert_id; |
|
102 | + if($id == 0) |
|
103 | + return false; |
|
104 | + return $id; |
|
105 | + } |
|
106 | + |
|
107 | + private function log_query($query, $start) |
|
108 | + { |
|
109 | + $time = (microtime(true) - $start) * 1000; |
|
110 | + $query = array( |
|
111 | + 'sql' => $query, |
|
112 | + 'time' => $time); |
|
113 | + array_push($this->query_log, $query); |
|
114 | 114 | |
115 | - $this->query_total['count']++; |
|
116 | - $this->query_total['time'] += $time; |
|
117 | - } |
|
118 | - |
|
119 | - private function gather_query_data() |
|
120 | - { |
|
121 | - $query_data = array(); |
|
122 | - foreach($this->query_log as $query) |
|
123 | - { |
|
124 | - $query = self::explain($query); |
|
125 | - $query_data[] = $query; |
|
126 | - } |
|
127 | - return $query_data; |
|
128 | - } |
|
129 | - |
|
130 | - public static function explain($query) |
|
131 | - { |
|
132 | - $sql = 'EXPLAIN ' . $query['sql']; |
|
115 | + $this->query_total['count']++; |
|
116 | + $this->query_total['time'] += $time; |
|
117 | + } |
|
118 | + |
|
119 | + private function gather_query_data() |
|
120 | + { |
|
121 | + $query_data = array(); |
|
122 | + foreach($this->query_log as $query) |
|
123 | + { |
|
124 | + $query = self::explain($query); |
|
125 | + $query_data[] = $query; |
|
126 | + } |
|
127 | + return $query_data; |
|
128 | + } |
|
129 | + |
|
130 | + public static function explain($query) |
|
131 | + { |
|
132 | + $sql = 'EXPLAIN ' . $query['sql']; |
|
133 | 133 | |
134 | - if($result = self::instance()->read_connection->query($sql)) |
|
135 | - { |
|
136 | - $row = $result->fetch_assoc(); |
|
137 | - $query['explain'] = $row; |
|
138 | - } |
|
134 | + if($result = self::instance()->read_connection->query($sql)) |
|
135 | + { |
|
136 | + $row = $result->fetch_assoc(); |
|
137 | + $query['explain'] = $row; |
|
138 | + } |
|
139 | 139 | |
140 | - return $query; |
|
141 | - } |
|
142 | - |
|
143 | - public static function getQueryLog() |
|
144 | - { |
|
145 | - return self::instance()->gather_query_data(); |
|
146 | - } |
|
147 | - |
|
148 | - public static function getQueryTotals() |
|
149 | - { |
|
150 | - return self::instance()->query_total; |
|
151 | - } |
|
152 | - |
|
153 | - public static function isConnected() |
|
154 | - { |
|
155 | - return !self::instance()->has_connection_error; |
|
156 | - } |
|
140 | + return $query; |
|
141 | + } |
|
142 | + |
|
143 | + public static function getQueryLog() |
|
144 | + { |
|
145 | + return self::instance()->gather_query_data(); |
|
146 | + } |
|
147 | + |
|
148 | + public static function getQueryTotals() |
|
149 | + { |
|
150 | + return self::instance()->query_total; |
|
151 | + } |
|
152 | + |
|
153 | + public static function isConnected() |
|
154 | + { |
|
155 | + return !self::instance()->has_connection_error; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | } |