@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $active_page = $this->get_active_page(); |
| 42 | 42 | |
| 43 | 43 | $menu = array(); |
| 44 | - foreach(self::$MENU as $item) |
|
| 44 | + foreach (self::$MENU as $item) |
|
| 45 | 45 | { |
| 46 | 46 | $menu[] = (object) array( |
| 47 | 47 | 'name' => $item['name'], |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | $current_uri = URLDecode::getPiece(1); |
| 58 | 58 | |
| 59 | - if(!isset($current_uri)) |
|
| 59 | + if (!isset($current_uri)) |
|
| 60 | 60 | return 'About'; |
| 61 | 61 | |
| 62 | 62 | $menu = self::$MENU; |
| 63 | - foreach($menu as $link) |
|
| 63 | + foreach ($menu as $link) |
|
| 64 | 64 | { |
| 65 | - if($link['uri'] == $current_uri) |
|
| 65 | + if ($link['uri'] == $current_uri) |
|
| 66 | 66 | return $link['name']; |
| 67 | 67 | } |
| 68 | 68 | |
@@ -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,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('controller', '/PageController'); |
| 4 | 4 | |
| 5 | -abstract class DefaultPageController extends PageController |
|
| 6 | -{ |
|
| 5 | +abstract class DefaultPageController extends PageController |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | 8 | private static $MENU = array( |
| 9 | 9 | array( |
@@ -19,14 +19,14 @@ discard block |
||
| 19 | 19 | 'name' => 'Contact', |
| 20 | 20 | 'uri' => 'contact')); |
| 21 | 21 | |
| 22 | - protected function set_head_data() |
|
| 23 | - { |
|
| 22 | + protected function set_head_data() |
|
| 23 | + {
|
|
| 24 | 24 | $this->add_css('reset'); |
| 25 | 25 | $this->add_css('site'); |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | - protected function set_body_data() |
|
| 29 | - { |
|
| 28 | + protected function set_body_data() |
|
| 29 | + {
|
|
| 30 | 30 | $this->set_body('top_data', array()); |
| 31 | 31 | $this->set_body('body_data', array()); |
| 32 | 32 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | $this->set_body_view('Page'); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - private function get_menu() |
|
| 40 | - { |
|
| 39 | + private function get_menu() |
|
| 40 | + {
|
|
| 41 | 41 | $active_page = $this->get_active_page(); |
| 42 | 42 | |
| 43 | 43 | $menu = array(); |
@@ -52,18 +52,20 @@ discard block |
||
| 52 | 52 | return $menu; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - private function get_active_page() |
|
| 56 | - { |
|
| 55 | + private function get_active_page() |
|
| 56 | + {
|
|
| 57 | 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 | |
| 62 | 63 | $menu = self::$MENU; |
| 63 | 64 | foreach($menu as $link) |
| 64 | 65 | { |
| 65 | - if($link['uri'] == $current_uri) |
|
| 66 | - return $link['name']; |
|
| 66 | + if($link['uri'] == $current_uri) {
|
|
| 67 | + return $link['name']; |
|
| 68 | + } |
|
| 67 | 69 | } |
| 68 | 70 | |
| 69 | 71 | return 'About'; |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | Loader::load('collector', 'data/ChangelogCollector'); |
| 30 | 30 | $changelog_result = ChangelogCollector::getLast20Changes(); |
| 31 | 31 | |
| 32 | - foreach($changelog_result as $change) |
|
| 32 | + foreach ($changelog_result as $change) |
|
| 33 | 33 | { |
| 34 | 34 | $changelog[] = (object) array( |
| 35 | 35 | 'date' => (object) array( |
@@ -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 | } |
@@ -4,11 +4,11 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | Loader::load('controller', 'site/DefaultPageController'); |
| 6 | 6 | |
| 7 | -final class ChangelogController extends DefaultPageController |
|
| 8 | -{ |
|
| 7 | +final class ChangelogController extends DefaultPageController |
|
| 8 | +{
|
|
| 9 | 9 | |
| 10 | - protected function set_head_data() |
|
| 11 | - { |
|
| 10 | + protected function set_head_data() |
|
| 11 | + {
|
|
| 12 | 12 | $this->set_title("Changelog for Jacob Emerick's Sites"); |
| 13 | 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 | 14 | $this->set_keywords(array('changelog', 'version control', 'code', 'comments', 'Jacob Emerick')); |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | parent::set_head_data(); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - protected function set_body_data() |
|
| 20 | - { |
|
| 19 | + protected function set_body_data() |
|
| 20 | + {
|
|
| 21 | 21 | parent::set_body_data(); |
| 22 | 22 | |
| 23 | 23 | $this->set_body('top_data', array('title' => 'Change Log')); |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | $this->set_body('body_view', 'Changelog'); |
| 27 | 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); |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | protected function execute($is_absolute = false, $size = 'medium') |
| 13 | 13 | { |
| 14 | 14 | preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
| 15 | - foreach($matches[1] as $key => $match) |
|
| 15 | + foreach ($matches[1] as $key => $match) |
|
| 16 | 16 | { |
| 17 | 17 | $photo_content = $this->get_photo_content($match, $size, $is_absolute); |
| 18 | 18 | $this->content = str_replace($matches[0][$key], $photo_content, $this->content); |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | Loader::load('collector', 'image/PhotoCollector'); |
| 39 | 39 | $photo_result = PhotoCollector::fetchRow($category, $photo); |
| 40 | - if($photo_result == false) |
|
| 40 | + if ($photo_result == false) |
|
| 41 | 41 | return ''; |
| 42 | 42 | |
| 43 | 43 | $height = $file_size[1]; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $domain = '/'; |
| 52 | - if($is_absolute) |
|
| 52 | + if ($is_absolute) |
|
| 53 | 53 | $domain = Loader::getRootUrl('blog'); |
| 54 | 54 | |
| 55 | 55 | return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
@@ -5,50 +5,50 @@ |
||
| 5 | 5 | final class FixPhotoContent extends Content |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
| 9 | - private static $ERROR_CONTENT = '<div class="photo-holder"><p class="photo-caption">Image (%s) could not be found!</p></div>'; |
|
| 10 | - private static $PHOTO_CONTENT = '<div class="photo-holder"><img src="%sphoto/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" /><p class="photo-caption">%s</p></div>'; |
|
| 8 | + private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
| 9 | + private static $ERROR_CONTENT = '<div class="photo-holder"><p class="photo-caption">Image (%s) could not be found!</p></div>'; |
|
| 10 | + private static $PHOTO_CONTENT = '<div class="photo-holder"><img src="%sphoto/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" /><p class="photo-caption">%s</p></div>'; |
|
| 11 | 11 | |
| 12 | - protected function execute($is_absolute = false, $size = 'medium') |
|
| 13 | - { |
|
| 14 | - preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
|
| 15 | - foreach($matches[1] as $key => $match) |
|
| 16 | - { |
|
| 17 | - $photo_content = $this->get_photo_content($match, $size, $is_absolute); |
|
| 18 | - $this->content = str_replace($matches[0][$key], $photo_content, $this->content); |
|
| 19 | - } |
|
| 20 | - return; |
|
| 21 | - } |
|
| 12 | + protected function execute($is_absolute = false, $size = 'medium') |
|
| 13 | + { |
|
| 14 | + preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
|
| 15 | + foreach($matches[1] as $key => $match) |
|
| 16 | + { |
|
| 17 | + $photo_content = $this->get_photo_content($match, $size, $is_absolute); |
|
| 18 | + $this->content = str_replace($matches[0][$key], $photo_content, $this->content); |
|
| 19 | + } |
|
| 20 | + return; |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - private function get_file_path($category, $photo, $size, $extension) |
|
| 24 | - { |
|
| 25 | - $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
| 26 | - return Loader::getImagePath('photo', $path); |
|
| 27 | - } |
|
| 23 | + private function get_file_path($category, $photo, $size, $extension) |
|
| 24 | + { |
|
| 25 | + $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
| 26 | + return Loader::getImagePath('photo', $path); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - private function get_photo_content($string, $size, $is_absolute) |
|
| 30 | - { |
|
| 31 | - list($category, $file_name) = explode('/', $string); |
|
| 32 | - list($photo, $extension) = explode('.', $file_name); |
|
| 29 | + private function get_photo_content($string, $size, $is_absolute) |
|
| 30 | + { |
|
| 31 | + list($category, $file_name) = explode('/', $string); |
|
| 32 | + list($photo, $extension) = explode('.', $file_name); |
|
| 33 | 33 | |
| 34 | - $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
| 34 | + $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
| 35 | 35 | |
| 36 | - $file_size = getimagesize($file_path); |
|
| 36 | + $file_size = getimagesize($file_path); |
|
| 37 | 37 | |
| 38 | - Loader::load('collector', 'image/PhotoCollector'); |
|
| 39 | - $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
| 40 | - if($photo_result == false) |
|
| 41 | - return ''; |
|
| 38 | + Loader::load('collector', 'image/PhotoCollector'); |
|
| 39 | + $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
| 40 | + if($photo_result == false) |
|
| 41 | + return ''; |
|
| 42 | 42 | |
| 43 | - $height = $file_size[1]; |
|
| 44 | - $width = $file_size[0]; |
|
| 45 | - $description = $photo_result->description; |
|
| 43 | + $height = $file_size[1]; |
|
| 44 | + $width = $file_size[0]; |
|
| 45 | + $description = $photo_result->description; |
|
| 46 | 46 | |
| 47 | - $domain = '/'; |
|
| 48 | - if($is_absolute) |
|
| 49 | - $domain = Loader::getRootUrl('blog'); |
|
| 47 | + $domain = '/'; |
|
| 48 | + if($is_absolute) |
|
| 49 | + $domain = Loader::getRootUrl('blog'); |
|
| 50 | 50 | |
| 51 | - return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
|
| 52 | - } |
|
| 51 | + return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | } |
@@ -2,15 +2,15 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('utility', 'Content'); |
| 4 | 4 | |
| 5 | -final class FixPhotoContent extends Content |
|
| 6 | -{ |
|
| 5 | +final class FixPhotoContent extends Content |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | 8 | private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
| 9 | 9 | private static $ERROR_CONTENT = '<div class="photo-holder"><p class="photo-caption">Image (%s) could not be found!</p></div>'; |
| 10 | 10 | private static $PHOTO_CONTENT = '<div class="photo-holder"><img src="%sphoto/%s/%s-size-%s.jpg" height="%d" width="%d" alt="%s" /><p class="photo-caption">%s</p></div>'; |
| 11 | 11 | |
| 12 | - protected function execute($is_absolute = false, $size = 'medium') |
|
| 13 | - { |
|
| 12 | + protected function execute($is_absolute = false, $size = 'medium') |
|
| 13 | + {
|
|
| 14 | 14 | preg_match_all(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $matches); |
| 15 | 15 | foreach($matches[1] as $key => $match) |
| 16 | 16 | { |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | return; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - private function get_file_path($category, $photo, $size, $extension) |
|
| 24 | - { |
|
| 23 | + private function get_file_path($category, $photo, $size, $extension) |
|
| 24 | + {
|
|
| 25 | 25 | $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
| 26 | 26 | return Loader::getImagePath('photo', $path); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - private function get_photo_content($string, $size, $is_absolute) |
|
| 30 | - { |
|
| 29 | + private function get_photo_content($string, $size, $is_absolute) |
|
| 30 | + {
|
|
| 31 | 31 | list($category, $file_name) = explode('/', $string); |
| 32 | 32 | list($photo, $extension) = explode('.', $file_name); |
| 33 | 33 | |
@@ -37,16 +37,18 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | Loader::load('collector', 'image/PhotoCollector'); |
| 39 | 39 | $photo_result = PhotoCollector::fetchRow($category, $photo); |
| 40 | - if($photo_result == false) |
|
| 41 | - return ''; |
|
| 40 | + if($photo_result == false) {
|
|
| 41 | + return ''; |
|
| 42 | + } |
|
| 42 | 43 | |
| 43 | 44 | $height = $file_size[1]; |
| 44 | 45 | $width = $file_size[0]; |
| 45 | 46 | $description = $photo_result->description; |
| 46 | 47 | |
| 47 | 48 | $domain = '/'; |
| 48 | - if($is_absolute) |
|
| 49 | - $domain = Loader::getRootUrl('blog'); |
|
| 49 | + if($is_absolute) {
|
|
| 50 | + $domain = Loader::getRootUrl('blog');
|
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | return sprintf(self::$PHOTO_CONTENT, $domain, $category, $photo, $size, $height, $width, $description, $description); |
| 52 | 54 | } |
@@ -10,61 +10,61 @@ |
||
| 10 | 10 | $previous_time = strtotime($this->content); |
| 11 | 11 | $current_time = time(); |
| 12 | 12 | |
| 13 | - if($current_time <= $previous_time) |
|
| 13 | + if ($current_time <= $previous_time) |
|
| 14 | 14 | $this->content = 'few seconds ago'; |
| 15 | - else if(($current_time - $previous_time) < 30) |
|
| 15 | + else if (($current_time - $previous_time) < 30) |
|
| 16 | 16 | $this->content = 'few seconds ago'; |
| 17 | - else if(($current_time - $previous_time) < 1.5 * 60) |
|
| 17 | + else if (($current_time - $previous_time) < 1.5 * 60) |
|
| 18 | 18 | $this->content = 'a minute ago'; |
| 19 | - else if(($current_time - $previous_time) < 4 * 60) |
|
| 19 | + else if (($current_time - $previous_time) < 4 * 60) |
|
| 20 | 20 | $this->content = 'few minutes ago'; |
| 21 | - else if(($current_time - $previous_time) < 7 * 60) |
|
| 21 | + else if (($current_time - $previous_time) < 7 * 60) |
|
| 22 | 22 | $this->content = 'five minutes ago'; |
| 23 | - else if(($current_time - $previous_time) < 12 * 60) |
|
| 23 | + else if (($current_time - $previous_time) < 12 * 60) |
|
| 24 | 24 | $this->content = 'ten minutes ago'; |
| 25 | - else if(($current_time - $previous_time) < 17 * 60) |
|
| 25 | + else if (($current_time - $previous_time) < 17 * 60) |
|
| 26 | 26 | $this->content = 'fifteen minutes ago'; |
| 27 | - else if(($current_time - $previous_time) < 22 * 60) |
|
| 27 | + else if (($current_time - $previous_time) < 22 * 60) |
|
| 28 | 28 | $this->content = 'twenty minutes ago'; |
| 29 | - else if(($current_time - $previous_time) < 37 * 60) |
|
| 29 | + else if (($current_time - $previous_time) < 37 * 60) |
|
| 30 | 30 | $this->content = 'half hour ago'; |
| 31 | - else if(($current_time - $previous_time) < 52 * 60) |
|
| 31 | + else if (($current_time - $previous_time) < 52 * 60) |
|
| 32 | 32 | $this->content = 'forty-five minutes ago'; |
| 33 | - else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
| 33 | + else if (($current_time - $previous_time) < 1.5 * 60 * 60) |
|
| 34 | 34 | $this->content = 'an hour ago'; |
| 35 | - else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
| 35 | + else if (($current_time - $previous_time) < 2.5 * 60 * 60) |
|
| 36 | 36 | $this->content = 'two hours ago'; |
| 37 | - else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
| 37 | + else if (($current_time - $previous_time) < 3.5 * 60 * 60) |
|
| 38 | 38 | $this->content = 'three hours ago'; |
| 39 | - else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
| 39 | + else if (($current_time - $previous_time) < 4.5 * 60 * 60) |
|
| 40 | 40 | $this->content = 'few hours ago'; |
| 41 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
| 41 | + else if (($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
| 42 | 42 | $this->content = 'this afternoon'; |
| 43 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
| 43 | + else if (($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
| 44 | 44 | $this->content = 'this morning'; |
| 45 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
| 45 | + else if (($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
| 46 | 46 | $this->content = 'yesterday evening'; |
| 47 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
| 47 | + else if (($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
| 48 | 48 | $this->content = 'yesterday afternoon'; |
| 49 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
| 49 | + else if (($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
| 50 | 50 | $this->content = 'yesterday morning'; |
| 51 | - else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
| 51 | + else if (($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
| 52 | 52 | $this->content = 'two days ago'; |
| 53 | - else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
| 53 | + else if (($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
| 54 | 54 | $this->content = 'three days ago'; |
| 55 | - else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
| 55 | + else if (($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
| 56 | 56 | $this->content = 'earlier this week'; |
| 57 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
| 57 | + else if (($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
| 58 | 58 | $this->content = 'late last week'; |
| 59 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
| 59 | + else if (($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
| 60 | 60 | $this->content = 'early last week'; |
| 61 | - else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
| 61 | + else if (($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
| 62 | 62 | $this->content = 'few weeks ago'; |
| 63 | - else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
| 63 | + else if (($current_time - $previous_time) < 1.25 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
| 64 | 64 | $this->content = 'earlier this month'; |
| 65 | - else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
| 65 | + else if (($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
| 66 | 66 | $this->content = 'last month'; |
| 67 | - else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
| 67 | + else if (($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
| 68 | 68 | $this->content = 'several months ago'; |
| 69 | 69 | else |
| 70 | 70 | $this->content = 'long ago'; |
@@ -5,69 +5,69 @@ |
||
| 5 | 5 | final class ElapsedTimeContent extends Content |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected function execute() |
|
| 9 | - { |
|
| 10 | - $previous_time = strtotime($this->content); |
|
| 11 | - $current_time = time(); |
|
| 8 | + protected function execute() |
|
| 9 | + { |
|
| 10 | + $previous_time = strtotime($this->content); |
|
| 11 | + $current_time = time(); |
|
| 12 | 12 | |
| 13 | - if($current_time <= $previous_time) |
|
| 14 | - $this->content = 'few seconds ago'; |
|
| 15 | - else if(($current_time - $previous_time) < 30) |
|
| 16 | - $this->content = 'few seconds ago'; |
|
| 17 | - else if(($current_time - $previous_time) < 1.5 * 60) |
|
| 18 | - $this->content = 'a minute ago'; |
|
| 19 | - else if(($current_time - $previous_time) < 4 * 60) |
|
| 20 | - $this->content = 'few minutes ago'; |
|
| 21 | - else if(($current_time - $previous_time) < 7 * 60) |
|
| 22 | - $this->content = 'five minutes ago'; |
|
| 23 | - else if(($current_time - $previous_time) < 12 * 60) |
|
| 24 | - $this->content = 'ten minutes ago'; |
|
| 25 | - else if(($current_time - $previous_time) < 17 * 60) |
|
| 26 | - $this->content = 'fifteen minutes ago'; |
|
| 27 | - else if(($current_time - $previous_time) < 22 * 60) |
|
| 28 | - $this->content = 'twenty minutes ago'; |
|
| 29 | - else if(($current_time - $previous_time) < 37 * 60) |
|
| 30 | - $this->content = 'half hour ago'; |
|
| 31 | - else if(($current_time - $previous_time) < 52 * 60) |
|
| 32 | - $this->content = 'forty-five minutes ago'; |
|
| 33 | - else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
| 34 | - $this->content = 'an hour ago'; |
|
| 35 | - else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
| 36 | - $this->content = 'two hours ago'; |
|
| 37 | - else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
| 38 | - $this->content = 'three hours ago'; |
|
| 39 | - else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
| 40 | - $this->content = 'few hours ago'; |
|
| 41 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
| 42 | - $this->content = 'this afternoon'; |
|
| 43 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
| 44 | - $this->content = 'this morning'; |
|
| 45 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
| 46 | - $this->content = 'yesterday evening'; |
|
| 47 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
| 48 | - $this->content = 'yesterday afternoon'; |
|
| 49 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
| 50 | - $this->content = 'yesterday morning'; |
|
| 51 | - else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
| 52 | - $this->content = 'two days ago'; |
|
| 53 | - else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
| 54 | - $this->content = 'three days ago'; |
|
| 55 | - else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
| 56 | - $this->content = 'earlier this week'; |
|
| 57 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
| 58 | - $this->content = 'late last week'; |
|
| 59 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
| 60 | - $this->content = 'early last week'; |
|
| 61 | - else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
| 62 | - $this->content = 'few weeks ago'; |
|
| 63 | - else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
| 64 | - $this->content = 'earlier this month'; |
|
| 65 | - else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
| 66 | - $this->content = 'last month'; |
|
| 67 | - else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
| 68 | - $this->content = 'several months ago'; |
|
| 69 | - else |
|
| 70 | - $this->content = 'long ago'; |
|
| 71 | - } |
|
| 13 | + if($current_time <= $previous_time) |
|
| 14 | + $this->content = 'few seconds ago'; |
|
| 15 | + else if(($current_time - $previous_time) < 30) |
|
| 16 | + $this->content = 'few seconds ago'; |
|
| 17 | + else if(($current_time - $previous_time) < 1.5 * 60) |
|
| 18 | + $this->content = 'a minute ago'; |
|
| 19 | + else if(($current_time - $previous_time) < 4 * 60) |
|
| 20 | + $this->content = 'few minutes ago'; |
|
| 21 | + else if(($current_time - $previous_time) < 7 * 60) |
|
| 22 | + $this->content = 'five minutes ago'; |
|
| 23 | + else if(($current_time - $previous_time) < 12 * 60) |
|
| 24 | + $this->content = 'ten minutes ago'; |
|
| 25 | + else if(($current_time - $previous_time) < 17 * 60) |
|
| 26 | + $this->content = 'fifteen minutes ago'; |
|
| 27 | + else if(($current_time - $previous_time) < 22 * 60) |
|
| 28 | + $this->content = 'twenty minutes ago'; |
|
| 29 | + else if(($current_time - $previous_time) < 37 * 60) |
|
| 30 | + $this->content = 'half hour ago'; |
|
| 31 | + else if(($current_time - $previous_time) < 52 * 60) |
|
| 32 | + $this->content = 'forty-five minutes ago'; |
|
| 33 | + else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
| 34 | + $this->content = 'an hour ago'; |
|
| 35 | + else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
| 36 | + $this->content = 'two hours ago'; |
|
| 37 | + else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
| 38 | + $this->content = 'three hours ago'; |
|
| 39 | + else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
| 40 | + $this->content = 'few hours ago'; |
|
| 41 | + else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
| 42 | + $this->content = 'this afternoon'; |
|
| 43 | + else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
| 44 | + $this->content = 'this morning'; |
|
| 45 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
| 46 | + $this->content = 'yesterday evening'; |
|
| 47 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
| 48 | + $this->content = 'yesterday afternoon'; |
|
| 49 | + else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
| 50 | + $this->content = 'yesterday morning'; |
|
| 51 | + else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
| 52 | + $this->content = 'two days ago'; |
|
| 53 | + else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
| 54 | + $this->content = 'three days ago'; |
|
| 55 | + else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
| 56 | + $this->content = 'earlier this week'; |
|
| 57 | + else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
| 58 | + $this->content = 'late last week'; |
|
| 59 | + else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
| 60 | + $this->content = 'early last week'; |
|
| 61 | + else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
| 62 | + $this->content = 'few weeks ago'; |
|
| 63 | + else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
| 64 | + $this->content = 'earlier this month'; |
|
| 65 | + else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
| 66 | + $this->content = 'last month'; |
|
| 67 | + else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
| 68 | + $this->content = 'several months ago'; |
|
| 69 | + else |
|
| 70 | + $this->content = 'long ago'; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | } |
| 74 | 74 | \ No newline at end of file |
@@ -2,72 +2,73 @@ |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('utility', 'Content'); |
| 4 | 4 | |
| 5 | -final class ElapsedTimeContent extends Content |
|
| 6 | -{ |
|
| 5 | +final class ElapsedTimeContent extends Content |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | - protected function execute() |
|
| 9 | - { |
|
| 8 | + protected function execute() |
|
| 9 | + {
|
|
| 10 | 10 | $previous_time = strtotime($this->content); |
| 11 | 11 | $current_time = time(); |
| 12 | 12 | |
| 13 | - if($current_time <= $previous_time) |
|
| 14 | - $this->content = 'few seconds ago'; |
|
| 15 | - else if(($current_time - $previous_time) < 30) |
|
| 16 | - $this->content = 'few seconds ago'; |
|
| 17 | - else if(($current_time - $previous_time) < 1.5 * 60) |
|
| 18 | - $this->content = 'a minute ago'; |
|
| 19 | - else if(($current_time - $previous_time) < 4 * 60) |
|
| 20 | - $this->content = 'few minutes ago'; |
|
| 21 | - else if(($current_time - $previous_time) < 7 * 60) |
|
| 22 | - $this->content = 'five minutes ago'; |
|
| 23 | - else if(($current_time - $previous_time) < 12 * 60) |
|
| 24 | - $this->content = 'ten minutes ago'; |
|
| 25 | - else if(($current_time - $previous_time) < 17 * 60) |
|
| 26 | - $this->content = 'fifteen minutes ago'; |
|
| 27 | - else if(($current_time - $previous_time) < 22 * 60) |
|
| 28 | - $this->content = 'twenty minutes ago'; |
|
| 29 | - else if(($current_time - $previous_time) < 37 * 60) |
|
| 30 | - $this->content = 'half hour ago'; |
|
| 31 | - else if(($current_time - $previous_time) < 52 * 60) |
|
| 32 | - $this->content = 'forty-five minutes ago'; |
|
| 33 | - else if(($current_time - $previous_time) < 1.5 * 60 * 60) |
|
| 34 | - $this->content = 'an hour ago'; |
|
| 35 | - else if(($current_time - $previous_time) < 2.5 * 60 * 60) |
|
| 36 | - $this->content = 'two hours ago'; |
|
| 37 | - else if(($current_time - $previous_time) < 3.5 * 60 * 60) |
|
| 38 | - $this->content = 'three hours ago'; |
|
| 39 | - else if(($current_time - $previous_time) < 4.5 * 60 * 60) |
|
| 40 | - $this->content = 'few hours ago'; |
|
| 41 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') |
|
| 42 | - $this->content = 'this afternoon'; |
|
| 43 | - else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') |
|
| 44 | - $this->content = 'this morning'; |
|
| 45 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) |
|
| 46 | - $this->content = 'yesterday evening'; |
|
| 47 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') |
|
| 48 | - $this->content = 'yesterday afternoon'; |
|
| 49 | - else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') |
|
| 50 | - $this->content = 'yesterday morning'; |
|
| 51 | - else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) |
|
| 52 | - $this->content = 'two days ago'; |
|
| 53 | - else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) |
|
| 54 | - $this->content = 'three days ago'; |
|
| 55 | - else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) |
|
| 56 | - $this->content = 'earlier this week'; |
|
| 57 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) |
|
| 58 | - $this->content = 'late last week'; |
|
| 59 | - else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) |
|
| 60 | - $this->content = 'early last week'; |
|
| 61 | - else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) |
|
| 62 | - $this->content = 'few weeks ago'; |
|
| 63 | - else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) |
|
| 64 | - $this->content = 'earlier this month'; |
|
| 65 | - else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) |
|
| 66 | - $this->content = 'last month'; |
|
| 67 | - else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) |
|
| 68 | - $this->content = 'several months ago'; |
|
| 69 | - else |
|
| 70 | - $this->content = 'long ago'; |
|
| 13 | + if($current_time <= $previous_time) {
|
|
| 14 | + $this->content = 'few seconds ago'; |
|
| 15 | + } else if(($current_time - $previous_time) < 30) {
|
|
| 16 | + $this->content = 'few seconds ago'; |
|
| 17 | + } else if(($current_time - $previous_time) < 1.5 * 60) {
|
|
| 18 | + $this->content = 'a minute ago'; |
|
| 19 | + } else if(($current_time - $previous_time) < 4 * 60) {
|
|
| 20 | + $this->content = 'few minutes ago'; |
|
| 21 | + } else if(($current_time - $previous_time) < 7 * 60) {
|
|
| 22 | + $this->content = 'five minutes ago'; |
|
| 23 | + } else if(($current_time - $previous_time) < 12 * 60) {
|
|
| 24 | + $this->content = 'ten minutes ago'; |
|
| 25 | + } else if(($current_time - $previous_time) < 17 * 60) {
|
|
| 26 | + $this->content = 'fifteen minutes ago'; |
|
| 27 | + } else if(($current_time - $previous_time) < 22 * 60) {
|
|
| 28 | + $this->content = 'twenty minutes ago'; |
|
| 29 | + } else if(($current_time - $previous_time) < 37 * 60) {
|
|
| 30 | + $this->content = 'half hour ago'; |
|
| 31 | + } else if(($current_time - $previous_time) < 52 * 60) {
|
|
| 32 | + $this->content = 'forty-five minutes ago'; |
|
| 33 | + } else if(($current_time - $previous_time) < 1.5 * 60 * 60) {
|
|
| 34 | + $this->content = 'an hour ago'; |
|
| 35 | + } else if(($current_time - $previous_time) < 2.5 * 60 * 60) {
|
|
| 36 | + $this->content = 'two hours ago'; |
|
| 37 | + } else if(($current_time - $previous_time) < 3.5 * 60 * 60) {
|
|
| 38 | + $this->content = 'three hours ago'; |
|
| 39 | + } else if(($current_time - $previous_time) < 4.5 * 60 * 60) {
|
|
| 40 | + $this->content = 'few hours ago'; |
|
| 41 | + } else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'pm') {
|
|
| 42 | + $this->content = 'this afternoon'; |
|
| 43 | + } else if(($current_time - $previous_time) < 1 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) && date('a', $previous_time) == 'am') {
|
|
| 44 | + $this->content = 'this morning'; |
|
| 45 | + } else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm' && date('G', $previous_time) >= 17) {
|
|
| 46 | + $this->content = 'yesterday evening'; |
|
| 47 | + } else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'pm') {
|
|
| 48 | + $this->content = 'yesterday afternoon'; |
|
| 49 | + } else if(($current_time - $previous_time) < 2 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 1 && date('a', $previous_time) == 'am') {
|
|
| 50 | + $this->content = 'yesterday morning'; |
|
| 51 | + } else if(($current_time - $previous_time) < 3 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 2) {
|
|
| 52 | + $this->content = 'two days ago'; |
|
| 53 | + } else if(($current_time - $previous_time) < 4 * 24 * 60 * 60 && date('j', $current_time) == date('j', $previous_time) + 3) {
|
|
| 54 | + $this->content = 'three days ago'; |
|
| 55 | + } else if(($current_time - $previous_time) < 1 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time)) {
|
|
| 56 | + $this->content = 'earlier this week'; |
|
| 57 | + } else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1 && date('w', $previous_time) >= 3) {
|
|
| 58 | + $this->content = 'late last week'; |
|
| 59 | + } else if(($current_time - $previous_time) < 2 * 7 * 24 * 60 * 60 && date('W', $current_time) == date('W', $previous_time) + 1) {
|
|
| 60 | + $this->content = 'early last week'; |
|
| 61 | + } else if(($current_time - $previous_time) < 3 * 7 * 24 * 60 * 60) {
|
|
| 62 | + $this->content = 'few weeks ago'; |
|
| 63 | + } else if(($current_time - $previous_time) < 1.25* 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time)) {
|
|
| 64 | + $this->content = 'earlier this month'; |
|
| 65 | + } else if(($current_time - $previous_time) < 2 * 4 * 7 * 24 * 60 * 60 && date('n', $current_time) == date('n', $previous_time) + 1) {
|
|
| 66 | + $this->content = 'last month'; |
|
| 67 | + } else if(($current_time - $previous_time) < 4 * 4 * 7 * 24 * 60 * 60) {
|
|
| 68 | + $this->content = 'several months ago'; |
|
| 69 | + } else {
|
|
| 70 | + $this->content = 'long ago'; |
|
| 71 | + } |
|
| 71 | 72 | } |
| 72 | 73 | |
| 73 | 74 | } |
| 74 | 75 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | protected function execute($is_absolute = false, $size = 'thumb') |
| 13 | 13 | { |
| 14 | - if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
| 14 | + if (preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
| 15 | 15 | $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
| 16 | 16 | else |
| 17 | 17 | $this->content = self::$DEFAULT_RETURN; |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | Loader::load('collector', 'image/PhotoCollector'); |
| 36 | 36 | $photo_result = PhotoCollector::fetchRow($category, $photo); |
| 37 | - if($photo_result == false) |
|
| 37 | + if ($photo_result == false) |
|
| 38 | 38 | return ''; |
| 39 | 39 | |
| 40 | 40 | $height = $file_size[1]; |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | $description = $photo_result->description; |
| 43 | 43 | |
| 44 | 44 | $domain = '/'; |
| 45 | - if($is_absolute) |
|
| 45 | + if ($is_absolute) |
|
| 46 | 46 | $domain = Loader::getRootUrl(); |
| 47 | 47 | |
| 48 | 48 | return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
@@ -5,47 +5,47 @@ |
||
| 5 | 5 | final class FetchFirstPhotoContent extends Content |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
| 9 | - private static $IMAGE_NODE = '<img src="%sphoto/%s/%s-size-%s.%s" height="%d" width="%d" alt="%s" />'; |
|
| 10 | - private static $DEFAULT_RETURN = ''; |
|
| 11 | - |
|
| 12 | - protected function execute($is_absolute = false, $size = 'thumb') |
|
| 13 | - { |
|
| 14 | - if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
| 15 | - $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
| 16 | - else |
|
| 17 | - $this->content = self::$DEFAULT_RETURN; |
|
| 18 | - return; |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - private function get_file_path($category, $photo, $size, $extension) |
|
| 22 | - { |
|
| 23 | - $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
| 24 | - return Loader::getImagePath('photo', $path); |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - private function get_thumb($string, $is_absolute, $size) |
|
| 28 | - { |
|
| 29 | - list($category, $file_name) = explode('/', $string); |
|
| 30 | - list($photo, $extension) = explode('.', $file_name); |
|
| 8 | + private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
|
| 9 | + private static $IMAGE_NODE = '<img src="%sphoto/%s/%s-size-%s.%s" height="%d" width="%d" alt="%s" />'; |
|
| 10 | + private static $DEFAULT_RETURN = ''; |
|
| 11 | + |
|
| 12 | + protected function execute($is_absolute = false, $size = 'thumb') |
|
| 13 | + { |
|
| 14 | + if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
| 15 | + $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
| 16 | + else |
|
| 17 | + $this->content = self::$DEFAULT_RETURN; |
|
| 18 | + return; |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + private function get_file_path($category, $photo, $size, $extension) |
|
| 22 | + { |
|
| 23 | + $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
|
| 24 | + return Loader::getImagePath('photo', $path); |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + private function get_thumb($string, $is_absolute, $size) |
|
| 28 | + { |
|
| 29 | + list($category, $file_name) = explode('/', $string); |
|
| 30 | + list($photo, $extension) = explode('.', $file_name); |
|
| 31 | 31 | |
| 32 | - $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
| 33 | - $file_size = getimagesize($file_path); |
|
| 32 | + $file_path = $this->get_file_path($category, $photo, $size, $extension); |
|
| 33 | + $file_size = getimagesize($file_path); |
|
| 34 | 34 | |
| 35 | - Loader::load('collector', 'image/PhotoCollector'); |
|
| 36 | - $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
| 37 | - if($photo_result == false) |
|
| 38 | - return ''; |
|
| 35 | + Loader::load('collector', 'image/PhotoCollector'); |
|
| 36 | + $photo_result = PhotoCollector::fetchRow($category, $photo); |
|
| 37 | + if($photo_result == false) |
|
| 38 | + return ''; |
|
| 39 | 39 | |
| 40 | - $height = $file_size[1]; |
|
| 41 | - $width = $file_size[0]; |
|
| 42 | - $description = $photo_result->description; |
|
| 40 | + $height = $file_size[1]; |
|
| 41 | + $width = $file_size[0]; |
|
| 42 | + $description = $photo_result->description; |
|
| 43 | 43 | |
| 44 | - $domain = '/'; |
|
| 45 | - if($is_absolute) |
|
| 46 | - $domain = Loader::getRootURL(URLDecode::getSite()); |
|
| 44 | + $domain = '/'; |
|
| 45 | + if($is_absolute) |
|
| 46 | + $domain = Loader::getRootURL(URLDecode::getSite()); |
|
| 47 | 47 | |
| 48 | - return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
|
| 49 | - } |
|
| 48 | + return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -2,30 +2,31 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('utility', 'Content'); |
| 4 | 4 | |
| 5 | -final class FetchFirstPhotoContent extends Content |
|
| 6 | -{ |
|
| 5 | +final class FetchFirstPhotoContent extends Content |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | 8 | private static $PHOTO_PLACEHOLDER_MATCH = '@{{photo="(.*)"}}@'; |
| 9 | 9 | private static $IMAGE_NODE = '<img src="%sphoto/%s/%s-size-%s.%s" height="%d" width="%d" alt="%s" />'; |
| 10 | 10 | private static $DEFAULT_RETURN = ''; |
| 11 | 11 | |
| 12 | - protected function execute($is_absolute = false, $size = 'thumb') |
|
| 13 | - { |
|
| 14 | - if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) |
|
| 15 | - $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
| 16 | - else |
|
| 17 | - $this->content = self::$DEFAULT_RETURN; |
|
| 12 | + protected function execute($is_absolute = false, $size = 'thumb') |
|
| 13 | + {
|
|
| 14 | + if(preg_match(self::$PHOTO_PLACEHOLDER_MATCH, $this->content, $match) === 1) {
|
|
| 15 | + $this->content = $this->get_thumb($match[1], $is_absolute, $size); |
|
| 16 | + } else {
|
|
| 17 | + $this->content = self::$DEFAULT_RETURN; |
|
| 18 | + } |
|
| 18 | 19 | return; |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | - private function get_file_path($category, $photo, $size, $extension) |
|
| 22 | - { |
|
| 22 | + private function get_file_path($category, $photo, $size, $extension) |
|
| 23 | + {
|
|
| 23 | 24 | $path = "{$category}/{$photo}-size-{$size}.{$extension}"; |
| 24 | 25 | return Loader::getImagePath('photo', $path); |
| 25 | 26 | } |
| 26 | 27 | |
| 27 | - private function get_thumb($string, $is_absolute, $size) |
|
| 28 | - { |
|
| 28 | + private function get_thumb($string, $is_absolute, $size) |
|
| 29 | + {
|
|
| 29 | 30 | list($category, $file_name) = explode('/', $string); |
| 30 | 31 | list($photo, $extension) = explode('.', $file_name); |
| 31 | 32 | |
@@ -34,16 +35,18 @@ discard block |
||
| 34 | 35 | |
| 35 | 36 | Loader::load('collector', 'image/PhotoCollector'); |
| 36 | 37 | $photo_result = PhotoCollector::fetchRow($category, $photo); |
| 37 | - if($photo_result == false) |
|
| 38 | - return ''; |
|
| 38 | + if($photo_result == false) {
|
|
| 39 | + return ''; |
|
| 40 | + } |
|
| 39 | 41 | |
| 40 | 42 | $height = $file_size[1]; |
| 41 | 43 | $width = $file_size[0]; |
| 42 | 44 | $description = $photo_result->description; |
| 43 | 45 | |
| 44 | 46 | $domain = '/'; |
| 45 | - if($is_absolute) |
|
| 46 | - $domain = Loader::getRootURL(URLDecode::getSite()); |
|
| 47 | + if($is_absolute) {
|
|
| 48 | + $domain = Loader::getRootURL(URLDecode::getSite()); |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | return sprintf(self::$IMAGE_NODE, $domain, $category, $photo, $size, $extension, $height, $width, $description); |
| 49 | 52 | } |
@@ -56,11 +56,11 @@ |
||
| 56 | 56 | final private function get_list_posts() |
| 57 | 57 | { |
| 58 | 58 | $post_array = array(); |
| 59 | - foreach($this->get_list_results() as $post) |
|
| 59 | + foreach ($this->get_list_results() as $post) |
|
| 60 | 60 | { |
| 61 | 61 | $post_array[] = $this->format_post($post, true); |
| 62 | 62 | } |
| 63 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | + if (count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 64 | 64 | $this->eject(); |
| 65 | 65 | return $post_array; |
| 66 | 66 | } |
@@ -5,63 +5,63 @@ |
||
| 5 | 5 | abstract class DefaultListController extends DefaultPageController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - protected static $POSTS_PER_PAGE = 15; |
|
| 8 | + protected static $POSTS_PER_PAGE = 15; |
|
| 9 | 9 | |
| 10 | - protected $page; |
|
| 11 | - protected $offset; |
|
| 10 | + protected $page; |
|
| 11 | + protected $offset; |
|
| 12 | 12 | |
| 13 | - public function __construct() |
|
| 14 | - { |
|
| 15 | - parent::__construct(); |
|
| 13 | + public function __construct() |
|
| 14 | + { |
|
| 15 | + parent::__construct(); |
|
| 16 | 16 | |
| 17 | - $this->page = $this->get_page_number(); |
|
| 18 | - $this->offset = ($this->page - 1) * self::$POSTS_PER_PAGE; |
|
| 19 | - } |
|
| 17 | + $this->page = $this->get_page_number(); |
|
| 18 | + $this->offset = ($this->page - 1) * self::$POSTS_PER_PAGE; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - abstract protected function get_page_number(); |
|
| 22 | - abstract protected function get_list_results(); |
|
| 23 | - abstract protected function get_list_description(); |
|
| 24 | - abstract protected function get_list_next_link(); |
|
| 25 | - abstract protected function get_list_prev_link(); |
|
| 26 | - abstract protected function get_total_post_count(); |
|
| 21 | + abstract protected function get_page_number(); |
|
| 22 | + abstract protected function get_list_results(); |
|
| 23 | + abstract protected function get_list_description(); |
|
| 24 | + abstract protected function get_list_next_link(); |
|
| 25 | + abstract protected function get_list_prev_link(); |
|
| 26 | + abstract protected function get_total_post_count(); |
|
| 27 | 27 | |
| 28 | - protected function set_head_data() |
|
| 29 | - { |
|
| 30 | - parent::set_head_data(); |
|
| 28 | + protected function set_head_data() |
|
| 29 | + { |
|
| 30 | + parent::set_head_data(); |
|
| 31 | 31 | |
| 32 | - $this->set_head('next_link', $this->get_list_next_link()); |
|
| 33 | - $this->set_head('previous_link', $this->get_list_prev_link()); |
|
| 34 | - } |
|
| 32 | + $this->set_head('next_link', $this->get_list_next_link()); |
|
| 33 | + $this->set_head('previous_link', $this->get_list_prev_link()); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function set_body_data() |
|
| 37 | - { |
|
| 38 | - parent::set_body_data(); |
|
| 36 | + protected function set_body_data() |
|
| 37 | + { |
|
| 38 | + parent::set_body_data(); |
|
| 39 | 39 | |
| 40 | - $this->set_body('view', 'Listing'); |
|
| 41 | - $this->set_body('data', $this->get_list_body_data()); |
|
| 42 | - } |
|
| 40 | + $this->set_body('view', 'Listing'); |
|
| 41 | + $this->set_body('data', $this->get_list_body_data()); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - final private function get_list_body_data() |
|
| 45 | - { |
|
| 46 | - return array( |
|
| 47 | - 'posts' => $this->get_list_posts(), |
|
| 48 | - 'type' => 'list', |
|
| 49 | - 'pagination' => array( |
|
| 50 | - 'description' => $this->get_list_description(), |
|
| 51 | - 'next' => $this->get_list_next_link(), |
|
| 52 | - 'prev' => $this->get_list_prev_link())); |
|
| 53 | - } |
|
| 44 | + final private function get_list_body_data() |
|
| 45 | + { |
|
| 46 | + return array( |
|
| 47 | + 'posts' => $this->get_list_posts(), |
|
| 48 | + 'type' => 'list', |
|
| 49 | + 'pagination' => array( |
|
| 50 | + 'description' => $this->get_list_description(), |
|
| 51 | + 'next' => $this->get_list_next_link(), |
|
| 52 | + 'prev' => $this->get_list_prev_link())); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - final private function get_list_posts() |
|
| 56 | - { |
|
| 57 | - $post_array = array(); |
|
| 58 | - foreach($this->get_list_results() as $post) |
|
| 59 | - { |
|
| 60 | - $post_array[] = $this->expand_post($post, 'full'); |
|
| 61 | - } |
|
| 62 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | - $this->eject(); |
|
| 64 | - return $post_array; |
|
| 65 | - } |
|
| 55 | + final private function get_list_posts() |
|
| 56 | + { |
|
| 57 | + $post_array = array(); |
|
| 58 | + foreach($this->get_list_results() as $post) |
|
| 59 | + { |
|
| 60 | + $post_array[] = $this->expand_post($post, 'full'); |
|
| 61 | + } |
|
| 62 | + if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | + $this->eject(); |
|
| 64 | + return $post_array; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | 67 | } |
@@ -2,16 +2,16 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('controller', 'lifestream/DefaultPageController'); |
| 4 | 4 | |
| 5 | -abstract class DefaultListController extends DefaultPageController |
|
| 6 | -{ |
|
| 5 | +abstract class DefaultListController extends DefaultPageController |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | 8 | protected static $POSTS_PER_PAGE = 15; |
| 9 | 9 | |
| 10 | 10 | protected $page; |
| 11 | 11 | protected $offset; |
| 12 | 12 | |
| 13 | - public function __construct() |
|
| 14 | - { |
|
| 13 | + public function __construct() |
|
| 14 | + {
|
|
| 15 | 15 | parent::__construct(); |
| 16 | 16 | |
| 17 | 17 | $this->page = $this->get_page_number(); |
@@ -25,24 +25,24 @@ discard block |
||
| 25 | 25 | abstract protected function get_list_prev_link(); |
| 26 | 26 | abstract protected function get_total_post_count(); |
| 27 | 27 | |
| 28 | - protected function set_head_data() |
|
| 29 | - { |
|
| 28 | + protected function set_head_data() |
|
| 29 | + {
|
|
| 30 | 30 | parent::set_head_data(); |
| 31 | 31 | |
| 32 | 32 | $this->set_head('next_link', $this->get_list_next_link()); |
| 33 | 33 | $this->set_head('previous_link', $this->get_list_prev_link()); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - protected function set_body_data() |
|
| 37 | - { |
|
| 36 | + protected function set_body_data() |
|
| 37 | + {
|
|
| 38 | 38 | parent::set_body_data(); |
| 39 | 39 | |
| 40 | 40 | $this->set_body('view', 'Listing'); |
| 41 | 41 | $this->set_body('data', $this->get_list_body_data()); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - final private function get_list_body_data() |
|
| 45 | - { |
|
| 44 | + final private function get_list_body_data() |
|
| 45 | + {
|
|
| 46 | 46 | return array( |
| 47 | 47 | 'posts' => $this->get_list_posts(), |
| 48 | 48 | 'type' => 'list', |
@@ -52,15 +52,16 @@ discard block |
||
| 52 | 52 | 'prev' => $this->get_list_prev_link())); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - final private function get_list_posts() |
|
| 56 | - { |
|
| 55 | + final private function get_list_posts() |
|
| 56 | + {
|
|
| 57 | 57 | $post_array = array(); |
| 58 | 58 | foreach($this->get_list_results() as $post) |
| 59 | 59 | { |
| 60 | 60 | $post_array[] = $this->expand_post($post, 'full'); |
| 61 | 61 | } |
| 62 | - if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') |
|
| 63 | - $this->eject(); |
|
| 62 | + if(count($post_array) < 1 && URLDecode::getPiece(1) !== 'search') {
|
|
| 63 | + $this->eject(); |
|
| 64 | + } |
|
| 64 | 65 | return $post_array; |
| 65 | 66 | } |
| 66 | 67 | |
@@ -20,14 +20,14 @@ discard block |
||
| 20 | 20 | parent::__construct(); |
| 21 | 21 | |
| 22 | 22 | $id = URLDecode::getPiece(2); |
| 23 | - if(!$id || !is_numeric($id)) |
|
| 23 | + if (!$id || !is_numeric($id)) |
|
| 24 | 24 | $this->eject(); |
| 25 | 25 | |
| 26 | 26 | $post = $this->postRepository->getPostById($id); |
| 27 | - if(!$post) |
|
| 27 | + if (!$post) |
|
| 28 | 28 | $this->eject(); |
| 29 | 29 | |
| 30 | - if(URLDecode::getPiece(1) != $post['type']) |
|
| 30 | + if (URLDecode::getPiece(1) != $post['type']) |
|
| 31 | 31 | $this->eject(); |
| 32 | 32 | |
| 33 | 33 | $this->post = $post; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | private function get_title() |
| 61 | 61 | { |
| 62 | - switch($this->post['type']) |
|
| 62 | + switch ($this->post['type']) |
|
| 63 | 63 | { |
| 64 | 64 | case 'blog' : |
| 65 | 65 | return 'Jacob blogged'; |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | private function get_description() |
| 86 | 86 | { |
| 87 | - switch($this->post['type']) |
|
| 87 | + switch ($this->post['type']) |
|
| 88 | 88 | { |
| 89 | 89 | case 'blog' : |
| 90 | 90 | return 'Another awesome blog post from Jacob. Did I mention it was awesome?'; |
@@ -5,112 +5,112 @@ |
||
| 5 | 5 | final class PostController extends DefaultPageController |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - private static $TITLE = "Post %d | %s Activity | Jacob Emerick's Lifestream"; |
|
| 9 | - private static $DESCRIPTION = "Post %d of %s activity on Jacob Emerick's Lifestream."; |
|
| 8 | + private static $TITLE = "Post %d | %s Activity | Jacob Emerick's Lifestream"; |
|
| 9 | + private static $DESCRIPTION = "Post %d of %s activity on Jacob Emerick's Lifestream."; |
|
| 10 | 10 | |
| 11 | - private static $KEYWORD_ARRAY = array( |
|
| 12 | - 'lifestream', |
|
| 13 | - 'activity stream', |
|
| 14 | - 'Jacob Emerick'); |
|
| 11 | + private static $KEYWORD_ARRAY = array( |
|
| 12 | + 'lifestream', |
|
| 13 | + 'activity stream', |
|
| 14 | + 'Jacob Emerick'); |
|
| 15 | 15 | |
| 16 | - private $post; |
|
| 16 | + private $post; |
|
| 17 | 17 | |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 20 | - parent::__construct(); |
|
| 18 | + public function __construct() |
|
| 19 | + { |
|
| 20 | + parent::__construct(); |
|
| 21 | 21 | |
| 22 | - $id = URLDecode::getPiece(2); |
|
| 23 | - if(!$id || !is_numeric($id)) |
|
| 24 | - $this->eject(); |
|
| 22 | + $id = URLDecode::getPiece(2); |
|
| 23 | + if(!$id || !is_numeric($id)) |
|
| 24 | + $this->eject(); |
|
| 25 | 25 | |
| 26 | - $post = $this->activityRepository->getActivityById($id); |
|
| 27 | - if(!$post) |
|
| 28 | - $this->eject(); |
|
| 26 | + $post = $this->activityRepository->getActivityById($id); |
|
| 27 | + if(!$post) |
|
| 28 | + $this->eject(); |
|
| 29 | 29 | |
| 30 | - if(URLDecode::getPiece(1) != $post['type']) |
|
| 31 | - $this->eject(); |
|
| 30 | + if(URLDecode::getPiece(1) != $post['type']) |
|
| 31 | + $this->eject(); |
|
| 32 | 32 | |
| 33 | - $this->post = $post; |
|
| 34 | - } |
|
| 33 | + $this->post = $post; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - protected function set_head_data() |
|
| 37 | - { |
|
| 38 | - $this->set_title(sprintf(self::$TITLE, $this->post['id'], ucwords($this->post['type']))); |
|
| 39 | - $this->set_description(sprintf(self::$DESCRIPTION, $this->post['id'], ucwords($this->post['type']))); |
|
| 36 | + protected function set_head_data() |
|
| 37 | + { |
|
| 38 | + $this->set_title(sprintf(self::$TITLE, $this->post['id'], ucwords($this->post['type']))); |
|
| 39 | + $this->set_description(sprintf(self::$DESCRIPTION, $this->post['id'], ucwords($this->post['type']))); |
|
| 40 | 40 | |
| 41 | - $keyword_array = self::$KEYWORD_ARRAY; |
|
| 42 | - array_unshift($keyword_array, $this->post['type']); |
|
| 43 | - $this->set_keywords($keyword_array); |
|
| 41 | + $keyword_array = self::$KEYWORD_ARRAY; |
|
| 42 | + array_unshift($keyword_array, $this->post['type']); |
|
| 43 | + $this->set_keywords($keyword_array); |
|
| 44 | 44 | |
| 45 | - parent::set_head_data(); |
|
| 46 | - } |
|
| 45 | + parent::set_head_data(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - protected function set_body_data() |
|
| 49 | - { |
|
| 50 | - $this->set_body('title', $this->get_title()); |
|
| 51 | - $this->set_body('description', $this->get_description()); |
|
| 48 | + protected function set_body_data() |
|
| 49 | + { |
|
| 50 | + $this->set_body('title', $this->get_title()); |
|
| 51 | + $this->set_body('description', $this->get_description()); |
|
| 52 | 52 | |
| 53 | - $this->set_body('post', $this->expand_post($this->post, 'full')); |
|
| 54 | - $this->set_body('type', 'single'); |
|
| 55 | - $this->set_body('view', 'Post'); |
|
| 53 | + $this->set_body('post', $this->expand_post($this->post, 'full')); |
|
| 54 | + $this->set_body('type', 'single'); |
|
| 55 | + $this->set_body('view', 'Post'); |
|
| 56 | 56 | |
| 57 | - parent::set_body_data(); |
|
| 58 | - } |
|
| 57 | + parent::set_body_data(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - private function get_title() |
|
| 61 | - { |
|
| 62 | - switch($this->post['type']) |
|
| 63 | - { |
|
| 64 | - case 'blog' : |
|
| 65 | - return 'Jacob blogged'; |
|
| 66 | - break; |
|
| 67 | - case 'book' : |
|
| 68 | - return 'Jacob read again'; |
|
| 69 | - break; |
|
| 70 | - case 'distance' : |
|
| 71 | - return 'Jacob ran xor hiked'; |
|
| 72 | - break; |
|
| 73 | - case 'github' : |
|
| 60 | + private function get_title() |
|
| 61 | + { |
|
| 62 | + switch($this->post['type']) |
|
| 63 | + { |
|
| 64 | + case 'blog' : |
|
| 65 | + return 'Jacob blogged'; |
|
| 66 | + break; |
|
| 67 | + case 'book' : |
|
| 68 | + return 'Jacob read again'; |
|
| 69 | + break; |
|
| 70 | + case 'distance' : |
|
| 71 | + return 'Jacob ran xor hiked'; |
|
| 72 | + break; |
|
| 73 | + case 'github' : |
|
| 74 | 74 | return 'Jacob did code'; |
| 75 | - break; |
|
| 76 | - case 'hulu' : |
|
| 77 | - return 'What Jacob watched'; |
|
| 78 | - break; |
|
| 79 | - case 'twitter' : |
|
| 80 | - return 'What Jacob tweeted'; |
|
| 81 | - break; |
|
| 82 | - case 'youtube' : |
|
| 83 | - return 'Jacob Liked a Video'; |
|
| 84 | - break; |
|
| 85 | - } |
|
| 86 | - } |
|
| 75 | + break; |
|
| 76 | + case 'hulu' : |
|
| 77 | + return 'What Jacob watched'; |
|
| 78 | + break; |
|
| 79 | + case 'twitter' : |
|
| 80 | + return 'What Jacob tweeted'; |
|
| 81 | + break; |
|
| 82 | + case 'youtube' : |
|
| 83 | + return 'Jacob Liked a Video'; |
|
| 84 | + break; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - private function get_description() |
|
| 89 | - { |
|
| 90 | - switch($this->post['type']) |
|
| 91 | - { |
|
| 92 | - case 'blog' : |
|
| 93 | - return 'Another awesome blog post from Jacob. Did I mention it was awesome?'; |
|
| 94 | - break; |
|
| 95 | - case 'book' : |
|
| 96 | - return "Yup, Jacob read another book. Don't tell his parents."; |
|
| 97 | - break; |
|
| 98 | - case 'distance' : |
|
| 99 | - return 'Well, it might have been both at the same time if there was a bear.'; |
|
| 100 | - break; |
|
| 101 | - case 'github' : |
|
| 88 | + private function get_description() |
|
| 89 | + { |
|
| 90 | + switch($this->post['type']) |
|
| 91 | + { |
|
| 92 | + case 'blog' : |
|
| 93 | + return 'Another awesome blog post from Jacob. Did I mention it was awesome?'; |
|
| 94 | + break; |
|
| 95 | + case 'book' : |
|
| 96 | + return "Yup, Jacob read another book. Don't tell his parents."; |
|
| 97 | + break; |
|
| 98 | + case 'distance' : |
|
| 99 | + return 'Well, it might have been both at the same time if there was a bear.'; |
|
| 100 | + break; |
|
| 101 | + case 'github' : |
|
| 102 | 102 | return 'An epic code change by Jacob on the Githubs.'; |
| 103 | - break; |
|
| 104 | - case 'hulu' : |
|
| 105 | - return 'It was a cold, dark night, so Jacob watched something on Hulu.'; |
|
| 106 | - break; |
|
| 107 | - case 'twitter' : |
|
| 108 | - return 'Just another awesome insight/thought/RT/random from Jacob.'; |
|
| 109 | - break; |
|
| 110 | - case 'youtube' : |
|
| 111 | - return "This is a video that Jacob liked on Youtube. It's probably awesome. You should check it out."; |
|
| 112 | - break; |
|
| 113 | - } |
|
| 114 | - } |
|
| 103 | + break; |
|
| 104 | + case 'hulu' : |
|
| 105 | + return 'It was a cold, dark night, so Jacob watched something on Hulu.'; |
|
| 106 | + break; |
|
| 107 | + case 'twitter' : |
|
| 108 | + return 'Just another awesome insight/thought/RT/random from Jacob.'; |
|
| 109 | + break; |
|
| 110 | + case 'youtube' : |
|
| 111 | + return "This is a video that Jacob liked on Youtube. It's probably awesome. You should check it out."; |
|
| 112 | + break; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | } |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | Loader::load('controller', 'lifestream/DefaultPageController'); |
| 4 | 4 | |
| 5 | -final class PostController extends DefaultPageController |
|
| 6 | -{ |
|
| 5 | +final class PostController extends DefaultPageController |
|
| 6 | +{
|
|
| 7 | 7 | |
| 8 | 8 | private static $TITLE = "Post %d | %s Activity | Jacob Emerick's Lifestream"; |
| 9 | 9 | private static $DESCRIPTION = "Post %d of %s activity on Jacob Emerick's Lifestream."; |
@@ -15,26 +15,29 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | private $post; |
| 17 | 17 | |
| 18 | - public function __construct() |
|
| 19 | - { |
|
| 18 | + public function __construct() |
|
| 19 | + {
|
|
| 20 | 20 | parent::__construct(); |
| 21 | 21 | |
| 22 | 22 | $id = URLDecode::getPiece(2); |
| 23 | - if(!$id || !is_numeric($id)) |
|
| 24 | - $this->eject(); |
|
| 23 | + if(!$id || !is_numeric($id)) {
|
|
| 24 | + $this->eject(); |
|
| 25 | + } |
|
| 25 | 26 | |
| 26 | 27 | $post = $this->activityRepository->getActivityById($id); |
| 27 | - if(!$post) |
|
| 28 | - $this->eject(); |
|
| 28 | + if(!$post) {
|
|
| 29 | + $this->eject(); |
|
| 30 | + } |
|
| 29 | 31 | |
| 30 | - if(URLDecode::getPiece(1) != $post['type']) |
|
| 31 | - $this->eject(); |
|
| 32 | + if(URLDecode::getPiece(1) != $post['type']) {
|
|
| 33 | + $this->eject(); |
|
| 34 | + } |
|
| 32 | 35 | |
| 33 | 36 | $this->post = $post; |
| 34 | 37 | } |
| 35 | 38 | |
| 36 | - protected function set_head_data() |
|
| 37 | - { |
|
| 39 | + protected function set_head_data() |
|
| 40 | + {
|
|
| 38 | 41 | $this->set_title(sprintf(self::$TITLE, $this->post['id'], ucwords($this->post['type']))); |
| 39 | 42 | $this->set_description(sprintf(self::$DESCRIPTION, $this->post['id'], ucwords($this->post['type']))); |
| 40 | 43 | |
@@ -45,8 +48,8 @@ discard block |
||
| 45 | 48 | parent::set_head_data(); |
| 46 | 49 | } |
| 47 | 50 | |
| 48 | - protected function set_body_data() |
|
| 49 | - { |
|
| 51 | + protected function set_body_data() |
|
| 52 | + {
|
|
| 50 | 53 | $this->set_body('title', $this->get_title()); |
| 51 | 54 | $this->set_body('description', $this->get_description()); |
| 52 | 55 | |
@@ -57,8 +60,8 @@ discard block |
||
| 57 | 60 | parent::set_body_data(); |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | - private function get_title() |
|
| 61 | - { |
|
| 63 | + private function get_title() |
|
| 64 | + {
|
|
| 62 | 65 | switch($this->post['type']) |
| 63 | 66 | { |
| 64 | 67 | case 'blog' : |
@@ -85,8 +88,8 @@ discard block |
||
| 85 | 88 | } |
| 86 | 89 | } |
| 87 | 90 | |
| 88 | - private function get_description() |
|
| 89 | - { |
|
| 91 | + private function get_description() |
|
| 92 | + {
|
|
| 90 | 93 | switch($this->post['type']) |
| 91 | 94 | { |
| 92 | 95 | case 'blog' : |
@@ -131,6 +131,9 @@ |
||
| 131 | 131 | self::send($array); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | + /** |
|
| 135 | + * @param string[] $array |
|
| 136 | + */ |
|
| 134 | 137 | private static function send($array, $gzip = true) |
| 135 | 138 | { |
| 136 | 139 | if($gzip) |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | 'Cache-Control: no-cache', |
| 11 | 11 | 'Content-Language: en', |
| 12 | 12 | 'Content-Type: application/json', |
| 13 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 14 | - 'Last-Modified: ' . self::get_date(), |
|
| 13 | + 'Expires: '.self::get_date(time() - 1), |
|
| 14 | + 'Last-Modified: '.self::get_date(), |
|
| 15 | 15 | 'X-Powered-By: jacobemerick.com'); |
| 16 | 16 | self::send($array); |
| 17 | 17 | } |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | 'Cache-Control: no-cache', |
| 24 | 24 | 'Content-Language: en', |
| 25 | 25 | 'Content-Type: text/html', |
| 26 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 27 | - 'Last-Modified: ' . self::get_date(), |
|
| 26 | + 'Expires: '.self::get_date(time() - 1), |
|
| 27 | + 'Last-Modified: '.self::get_date(), |
|
| 28 | 28 | 'X-Powered-By: jacobemerick.com'); |
| 29 | 29 | self::send($array); |
| 30 | 30 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | 'Cache-Control: no-cache', |
| 43 | 43 | 'Content-Language: en', |
| 44 | 44 | 'Content-Type: text/html', |
| 45 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 46 | - 'Last-Modified: ' . self::get_date(), |
|
| 45 | + 'Expires: '.self::get_date(time() - 1), |
|
| 46 | + 'Last-Modified: '.self::get_date(), |
|
| 47 | 47 | 'X-Powered-By: jacobemerick.com'); |
| 48 | 48 | self::send($array); |
| 49 | 49 | } |
@@ -55,18 +55,18 @@ discard block |
||
| 55 | 55 | 'Cache-Control: no-cache', |
| 56 | 56 | 'Content-Language: en', |
| 57 | 57 | 'Content-Type: text/html', |
| 58 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 59 | - 'Last-Modified: ' . self::get_date(), |
|
| 58 | + 'Expires: '.self::get_date(time() - 1), |
|
| 59 | + 'Last-Modified: '.self::get_date(), |
|
| 60 | 60 | 'X-Powered-By: jacobemerick.com'); |
| 61 | 61 | self::send($array); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | private static function send($array, $gzip = true) |
| 65 | 65 | { |
| 66 | - if($gzip) |
|
| 66 | + if ($gzip) |
|
| 67 | 67 | self::start_gzipping(); |
| 68 | 68 | |
| 69 | - foreach($array as $row) |
|
| 69 | + foreach ($array as $row) |
|
| 70 | 70 | { |
| 71 | 71 | header($row, TRUE); |
| 72 | 72 | } |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | private static function get_date($timestamp = false) |
| 76 | 76 | { |
| 77 | - if($timestamp == 0) |
|
| 77 | + if ($timestamp == 0) |
|
| 78 | 78 | $timestamp = time(); |
| 79 | 79 | return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | private static function start_gzipping() |
| 83 | 83 | { |
| 84 | - if(!ob_start('ob_gzhandler')) |
|
| 84 | + if (!ob_start('ob_gzhandler')) |
|
| 85 | 85 | ob_start(); |
| 86 | 86 | } |
| 87 | 87 | |
@@ -3,86 +3,86 @@ |
||
| 3 | 3 | final class Header |
| 4 | 4 | { |
| 5 | 5 | |
| 6 | - public static function sendJSON() |
|
| 7 | - { |
|
| 8 | - $array = array( |
|
| 9 | - 'HTTP/1.1 200 OK', |
|
| 10 | - 'Cache-Control: no-cache', |
|
| 11 | - 'Content-Language: en', |
|
| 12 | - 'Content-Type: application/json', |
|
| 13 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 14 | - 'Last-Modified: ' . self::get_date(), |
|
| 15 | - 'X-Powered-By: jacobemerick.com'); |
|
| 16 | - self::send($array); |
|
| 17 | - } |
|
| 6 | + public static function sendJSON() |
|
| 7 | + { |
|
| 8 | + $array = array( |
|
| 9 | + 'HTTP/1.1 200 OK', |
|
| 10 | + 'Cache-Control: no-cache', |
|
| 11 | + 'Content-Language: en', |
|
| 12 | + 'Content-Type: application/json', |
|
| 13 | + 'Expires: ' . self::get_date(time() - 1), |
|
| 14 | + 'Last-Modified: ' . self::get_date(), |
|
| 15 | + 'X-Powered-By: jacobemerick.com'); |
|
| 16 | + self::send($array); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public static function sendHTML() |
|
| 20 | - { |
|
| 21 | - $array = array( |
|
| 22 | - 'HTTP/1.1 200 OK', |
|
| 23 | - 'Cache-Control: no-cache', |
|
| 24 | - 'Content-Language: en', |
|
| 25 | - 'Content-Type: text/html', |
|
| 26 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 27 | - 'Last-Modified: ' . self::get_date(), |
|
| 28 | - 'X-Powered-By: jacobemerick.com'); |
|
| 29 | - self::send($array); |
|
| 30 | - } |
|
| 19 | + public static function sendHTML() |
|
| 20 | + { |
|
| 21 | + $array = array( |
|
| 22 | + 'HTTP/1.1 200 OK', |
|
| 23 | + 'Cache-Control: no-cache', |
|
| 24 | + 'Content-Language: en', |
|
| 25 | + 'Content-Type: text/html', |
|
| 26 | + 'Expires: ' . self::get_date(time() - 1), |
|
| 27 | + 'Last-Modified: ' . self::get_date(), |
|
| 28 | + 'X-Powered-By: jacobemerick.com'); |
|
| 29 | + self::send($array); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public static function redirect($location, $method = 301) |
|
| 33 | - { |
|
| 34 | - header("Location: {$location}", TRUE, $method); |
|
| 35 | - exit(); |
|
| 36 | - } |
|
| 32 | + public static function redirect($location, $method = 301) |
|
| 33 | + { |
|
| 34 | + header("Location: {$location}", TRUE, $method); |
|
| 35 | + exit(); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - public static function send404() |
|
| 39 | - { |
|
| 40 | - $array = array( |
|
| 41 | - 'HTTP/1.1 404 Not Found', |
|
| 42 | - 'Cache-Control: no-cache', |
|
| 43 | - 'Content-Language: en', |
|
| 44 | - 'Content-Type: text/html', |
|
| 45 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 46 | - 'Last-Modified: ' . self::get_date(), |
|
| 47 | - 'X-Powered-By: jacobemerick.com'); |
|
| 48 | - self::send($array); |
|
| 49 | - } |
|
| 38 | + public static function send404() |
|
| 39 | + { |
|
| 40 | + $array = array( |
|
| 41 | + 'HTTP/1.1 404 Not Found', |
|
| 42 | + 'Cache-Control: no-cache', |
|
| 43 | + 'Content-Language: en', |
|
| 44 | + 'Content-Type: text/html', |
|
| 45 | + 'Expires: ' . self::get_date(time() - 1), |
|
| 46 | + 'Last-Modified: ' . self::get_date(), |
|
| 47 | + 'X-Powered-By: jacobemerick.com'); |
|
| 48 | + self::send($array); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - public static function send503() |
|
| 52 | - { |
|
| 53 | - $array = array( |
|
| 54 | - 'HTTP/1.1 503 Service Unavailable', |
|
| 55 | - 'Cache-Control: no-cache', |
|
| 56 | - 'Content-Language: en', |
|
| 57 | - 'Content-Type: text/html', |
|
| 58 | - 'Expires: ' . self::get_date(time() - 1), |
|
| 59 | - 'Last-Modified: ' . self::get_date(), |
|
| 60 | - 'X-Powered-By: jacobemerick.com'); |
|
| 61 | - self::send($array); |
|
| 62 | - } |
|
| 51 | + public static function send503() |
|
| 52 | + { |
|
| 53 | + $array = array( |
|
| 54 | + 'HTTP/1.1 503 Service Unavailable', |
|
| 55 | + 'Cache-Control: no-cache', |
|
| 56 | + 'Content-Language: en', |
|
| 57 | + 'Content-Type: text/html', |
|
| 58 | + 'Expires: ' . self::get_date(time() - 1), |
|
| 59 | + 'Last-Modified: ' . self::get_date(), |
|
| 60 | + 'X-Powered-By: jacobemerick.com'); |
|
| 61 | + self::send($array); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - private static function send($array, $gzip = true) |
|
| 65 | - { |
|
| 66 | - if($gzip) |
|
| 67 | - self::start_gzipping(); |
|
| 64 | + private static function send($array, $gzip = true) |
|
| 65 | + { |
|
| 66 | + if($gzip) |
|
| 67 | + self::start_gzipping(); |
|
| 68 | 68 | |
| 69 | - foreach($array as $row) |
|
| 70 | - { |
|
| 71 | - header($row, TRUE); |
|
| 72 | - } |
|
| 73 | - } |
|
| 69 | + foreach($array as $row) |
|
| 70 | + { |
|
| 71 | + header($row, TRUE); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - private static function get_date($timestamp = false) |
|
| 76 | - { |
|
| 77 | - if($timestamp == 0) |
|
| 78 | - $timestamp = time(); |
|
| 79 | - return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
|
| 80 | - } |
|
| 75 | + private static function get_date($timestamp = false) |
|
| 76 | + { |
|
| 77 | + if($timestamp == 0) |
|
| 78 | + $timestamp = time(); |
|
| 79 | + return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - private static function start_gzipping() |
|
| 83 | - { |
|
| 84 | - if(!ob_start('ob_gzhandler')) |
|
| 82 | + private static function start_gzipping() |
|
| 83 | + { |
|
| 84 | + if(!ob_start('ob_gzhandler')) |
|
| 85 | 85 | ob_start(); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | } |
@@ -1,10 +1,10 @@ discard block |
||
| 1 | 1 | <? |
| 2 | 2 | |
| 3 | -final class Header |
|
| 4 | -{ |
|
| 3 | +final class Header |
|
| 4 | +{
|
|
| 5 | 5 | |
| 6 | - public static function sendJSON() |
|
| 7 | - { |
|
| 6 | + public static function sendJSON() |
|
| 7 | + {
|
|
| 8 | 8 | $array = array( |
| 9 | 9 | 'HTTP/1.1 200 OK', |
| 10 | 10 | 'Cache-Control: no-cache', |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | self::send($array); |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | - public static function sendHTML() |
|
| 20 | - { |
|
| 19 | + public static function sendHTML() |
|
| 20 | + {
|
|
| 21 | 21 | $array = array( |
| 22 | 22 | 'HTTP/1.1 200 OK', |
| 23 | 23 | 'Cache-Control: no-cache', |
@@ -29,14 +29,14 @@ discard block |
||
| 29 | 29 | self::send($array); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public static function redirect($location, $method = 301) |
|
| 33 | - { |
|
| 32 | + public static function redirect($location, $method = 301) |
|
| 33 | + {
|
|
| 34 | 34 | header("Location: {$location}", TRUE, $method); |
| 35 | 35 | exit(); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - public static function send404() |
|
| 39 | - { |
|
| 38 | + public static function send404() |
|
| 39 | + {
|
|
| 40 | 40 | $array = array( |
| 41 | 41 | 'HTTP/1.1 404 Not Found', |
| 42 | 42 | 'Cache-Control: no-cache', |
@@ -48,8 +48,8 @@ discard block |
||
| 48 | 48 | self::send($array); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public static function send503() |
|
| 52 | - { |
|
| 51 | + public static function send503() |
|
| 52 | + {
|
|
| 53 | 53 | $array = array( |
| 54 | 54 | 'HTTP/1.1 503 Service Unavailable', |
| 55 | 55 | 'Cache-Control: no-cache', |
@@ -61,10 +61,11 @@ discard block |
||
| 61 | 61 | self::send($array); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - private static function send($array, $gzip = true) |
|
| 65 | - { |
|
| 66 | - if($gzip) |
|
| 67 | - self::start_gzipping(); |
|
| 64 | + private static function send($array, $gzip = true) |
|
| 65 | + {
|
|
| 66 | + if($gzip) {
|
|
| 67 | + self::start_gzipping(); |
|
| 68 | + } |
|
| 68 | 69 | |
| 69 | 70 | foreach($array as $row) |
| 70 | 71 | { |
@@ -72,17 +73,19 @@ discard block |
||
| 72 | 73 | } |
| 73 | 74 | } |
| 74 | 75 | |
| 75 | - private static function get_date($timestamp = false) |
|
| 76 | - { |
|
| 77 | - if($timestamp == 0) |
|
| 78 | - $timestamp = time(); |
|
| 76 | + private static function get_date($timestamp = false) |
|
| 77 | + {
|
|
| 78 | + if($timestamp == 0) {
|
|
| 79 | + $timestamp = time(); |
|
| 80 | + } |
|
| 79 | 81 | return gmdate('D, d M Y H:i:s \G\M\T', $timestamp); |
| 80 | 82 | } |
| 81 | 83 | |
| 82 | - private static function start_gzipping() |
|
| 83 | - { |
|
| 84 | - if(!ob_start('ob_gzhandler')) |
|
| 85 | - ob_start(); |
|
| 84 | + private static function start_gzipping() |
|
| 85 | + {
|
|
| 86 | + if(!ob_start('ob_gzhandler')) {
|
|
| 87 | + ob_start(); |
|
| 88 | + } |
|
| 86 | 89 | } |
| 87 | 90 | |
| 88 | 91 | } |
@@ -84,6 +84,9 @@ |
||
| 84 | 84 | return false; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + /** |
|
| 88 | + * @param string $query |
|
| 89 | + */ |
|
| 87 | 90 | public static function execute($query) |
| 88 | 91 | { |
| 89 | 92 | $start = microtime(true); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $mysqli = new mysqli($host, $username, $password); |
| 37 | 37 | |
| 38 | 38 | $has_connection_error = $mysqli->connect_error; |
| 39 | - if(isset($has_connection_error)) |
|
| 39 | + if (isset($has_connection_error)) |
|
| 40 | 40 | $this->has_connection_error = true; |
| 41 | 41 | |
| 42 | 42 | return $mysqli; |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public static function instance() |
| 46 | 46 | { |
| 47 | - if(!isset(self::$instance)) { |
|
| 47 | + if (!isset(self::$instance)) { |
|
| 48 | 48 | global $config; |
| 49 | 49 | self::$instance = new Database( |
| 50 | 50 | $config->database->master, |
@@ -63,23 +63,23 @@ discard block |
||
| 63 | 63 | public static function select($query) |
| 64 | 64 | { |
| 65 | 65 | $start = microtime(true); |
| 66 | - if($result = self::instance()->read_connection->query($query)) |
|
| 66 | + if ($result = self::instance()->read_connection->query($query)) |
|
| 67 | 67 | { |
| 68 | 68 | self::instance()->log_query($query, $start); |
| 69 | 69 | $array = array(); |
| 70 | - while($row = $result->fetch_object()) |
|
| 70 | + while ($row = $result->fetch_object()) |
|
| 71 | 71 | $array[] = $row; |
| 72 | 72 | $result->close(); |
| 73 | 73 | return $array; |
| 74 | 74 | } |
| 75 | - trigger_error('Could not preform query - ' . $query . ' - ' . self::instance()->read_connection->error); |
|
| 75 | + trigger_error('Could not preform query - '.$query.' - '.self::instance()->read_connection->error); |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | public static function selectRow($query) |
| 80 | 80 | { |
| 81 | 81 | $result = self::select($query); |
| 82 | - if(is_array($result)) |
|
| 82 | + if (is_array($result)) |
|
| 83 | 83 | return array_pop($result); |
| 84 | 84 | return false; |
| 85 | 85 | } |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | public static function execute($query) |
| 88 | 88 | { |
| 89 | 89 | $start = microtime(true); |
| 90 | - if(self::instance()->write_connection->query($query)) |
|
| 90 | + if (self::instance()->write_connection->query($query)) |
|
| 91 | 91 | { |
| 92 | 92 | self::instance()->log_query($query, $start); |
| 93 | 93 | return true; |
| 94 | 94 | } |
| 95 | - trigger_error('Could not preform query - ' . $query . '-' . self::instance()->write_connection->error); |
|
| 95 | + trigger_error('Could not preform query - '.$query.'-'.self::instance()->write_connection->error); |
|
| 96 | 96 | return false; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | public static function lastInsertID() |
| 100 | 100 | { |
| 101 | 101 | $id = self::instance()->write_connection->insert_id; |
| 102 | - if($id == 0) |
|
| 102 | + if ($id == 0) |
|
| 103 | 103 | return false; |
| 104 | 104 | return $id; |
| 105 | 105 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | private function gather_query_data() |
| 120 | 120 | { |
| 121 | 121 | $query_data = array(); |
| 122 | - foreach($this->query_log as $query) |
|
| 122 | + foreach ($this->query_log as $query) |
|
| 123 | 123 | { |
| 124 | 124 | $query = self::explain($query); |
| 125 | 125 | $query_data[] = $query; |
@@ -129,9 +129,9 @@ discard block |
||
| 129 | 129 | |
| 130 | 130 | public static function explain($query) |
| 131 | 131 | { |
| 132 | - $sql = 'EXPLAIN ' . $query['sql']; |
|
| 132 | + $sql = 'EXPLAIN '.$query['sql']; |
|
| 133 | 133 | |
| 134 | - if($result = self::instance()->read_connection->query($sql)) |
|
| 134 | + if ($result = self::instance()->read_connection->query($sql)) |
|
| 135 | 135 | { |
| 136 | 136 | $row = $result->fetch_assoc(); |
| 137 | 137 | $query['explain'] = $row; |
@@ -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 | } |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -final class Database |
|
| 4 | -{ |
|
| 3 | +final class Database |
|
| 4 | +{
|
|
| 5 | 5 | |
| 6 | 6 | private $read_connection; |
| 7 | 7 | private $write_connection; |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 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, |
@@ -31,19 +31,20 @@ discard block |
||
| 31 | 31 | return $this; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - private function connect($host, $username, $password) |
|
| 35 | - { |
|
| 34 | + private function connect($host, $username, $password) |
|
| 35 | + {
|
|
| 36 | 36 | $mysqli = new mysqli($host, $username, $password); |
| 37 | 37 | |
| 38 | 38 | $has_connection_error = $mysqli->connect_error; |
| 39 | - if(isset($has_connection_error)) |
|
| 40 | - $this->has_connection_error = true; |
|
| 39 | + if(isset($has_connection_error)) {
|
|
| 40 | + $this->has_connection_error = true; |
|
| 41 | + } |
|
| 41 | 42 | |
| 42 | 43 | return $mysqli; |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | - public static function instance() |
|
| 46 | - { |
|
| 46 | + public static function instance() |
|
| 47 | + {
|
|
| 47 | 48 | if(!isset(self::$instance)) { |
| 48 | 49 | global $config; |
| 49 | 50 | self::$instance = new Database( |
@@ -55,20 +56,21 @@ discard block |
||
| 55 | 56 | return self::$instance; |
| 56 | 57 | } |
| 57 | 58 | |
| 58 | - public static function escape($string) |
|
| 59 | - { |
|
| 59 | + public static function escape($string) |
|
| 60 | + {
|
|
| 60 | 61 | return self::instance()->read_connection->real_escape_string($string); |
| 61 | 62 | } |
| 62 | 63 | |
| 63 | - public static function select($query) |
|
| 64 | - { |
|
| 64 | + public static function select($query) |
|
| 65 | + {
|
|
| 65 | 66 | $start = microtime(true); |
| 66 | 67 | if($result = self::instance()->read_connection->query($query)) |
| 67 | 68 | { |
| 68 | 69 | self::instance()->log_query($query, $start); |
| 69 | 70 | $array = array(); |
| 70 | - while($row = $result->fetch_object()) |
|
| 71 | - $array[] = $row; |
|
| 71 | + while($row = $result->fetch_object()) {
|
|
| 72 | + $array[] = $row; |
|
| 73 | + } |
|
| 72 | 74 | $result->close(); |
| 73 | 75 | return $array; |
| 74 | 76 | } |
@@ -76,16 +78,17 @@ discard block |
||
| 76 | 78 | return false; |
| 77 | 79 | } |
| 78 | 80 | |
| 79 | - public static function selectRow($query) |
|
| 80 | - { |
|
| 81 | + public static function selectRow($query) |
|
| 82 | + {
|
|
| 81 | 83 | $result = self::select($query); |
| 82 | - if(is_array($result)) |
|
| 83 | - return array_pop($result); |
|
| 84 | + if(is_array($result)) {
|
|
| 85 | + return array_pop($result); |
|
| 86 | + } |
|
| 84 | 87 | return false; |
| 85 | 88 | } |
| 86 | 89 | |
| 87 | - public static function execute($query) |
|
| 88 | - { |
|
| 90 | + public static function execute($query) |
|
| 91 | + {
|
|
| 89 | 92 | $start = microtime(true); |
| 90 | 93 | if(self::instance()->write_connection->query($query)) |
| 91 | 94 | { |
@@ -96,16 +99,17 @@ discard block |
||
| 96 | 99 | return false; |
| 97 | 100 | } |
| 98 | 101 | |
| 99 | - public static function lastInsertID() |
|
| 100 | - { |
|
| 102 | + public static function lastInsertID() |
|
| 103 | + {
|
|
| 101 | 104 | $id = self::instance()->write_connection->insert_id; |
| 102 | - if($id == 0) |
|
| 103 | - return false; |
|
| 105 | + if($id == 0) {
|
|
| 106 | + return false; |
|
| 107 | + } |
|
| 104 | 108 | return $id; |
| 105 | 109 | } |
| 106 | 110 | |
| 107 | - private function log_query($query, $start) |
|
| 108 | - { |
|
| 111 | + private function log_query($query, $start) |
|
| 112 | + {
|
|
| 109 | 113 | $time = (microtime(true) - $start) * 1000; |
| 110 | 114 | $query = array( |
| 111 | 115 | 'sql' => $query, |
@@ -116,8 +120,8 @@ discard block |
||
| 116 | 120 | $this->query_total['time'] += $time; |
| 117 | 121 | } |
| 118 | 122 | |
| 119 | - private function gather_query_data() |
|
| 120 | - { |
|
| 123 | + private function gather_query_data() |
|
| 124 | + {
|
|
| 121 | 125 | $query_data = array(); |
| 122 | 126 | foreach($this->query_log as $query) |
| 123 | 127 | { |
@@ -127,8 +131,8 @@ discard block |
||
| 127 | 131 | return $query_data; |
| 128 | 132 | } |
| 129 | 133 | |
| 130 | - public static function explain($query) |
|
| 131 | - { |
|
| 134 | + public static function explain($query) |
|
| 135 | + {
|
|
| 132 | 136 | $sql = 'EXPLAIN ' . $query['sql']; |
| 133 | 137 | |
| 134 | 138 | if($result = self::instance()->read_connection->query($sql)) |
@@ -140,18 +144,18 @@ discard block |
||
| 140 | 144 | return $query; |
| 141 | 145 | } |
| 142 | 146 | |
| 143 | - public static function getQueryLog() |
|
| 144 | - { |
|
| 147 | + public static function getQueryLog() |
|
| 148 | + {
|
|
| 145 | 149 | return self::instance()->gather_query_data(); |
| 146 | 150 | } |
| 147 | 151 | |
| 148 | - public static function getQueryTotals() |
|
| 149 | - { |
|
| 152 | + public static function getQueryTotals() |
|
| 153 | + {
|
|
| 150 | 154 | return self::instance()->query_total; |
| 151 | 155 | } |
| 152 | 156 | |
| 153 | - public static function isConnected() |
|
| 154 | - { |
|
| 157 | + public static function isConnected() |
|
| 158 | + {
|
|
| 155 | 159 | return !self::instance()->has_connection_error; |
| 156 | 160 | } |
| 157 | 161 | |