diff --git a/app/Console/Commands/SendRecurringInvoices.php b/app/Console/Commands/SendRecurringInvoices.php
index 389950c8291a..31f6f5be8c86 100644
--- a/app/Console/Commands/SendRecurringInvoices.php
+++ b/app/Console/Commands/SendRecurringInvoices.php
@@ -3,7 +3,7 @@
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
-use ninja\mailers\ContactMailer as Mailer;
+use Ninja\Mailers\ContactMailer as Mailer;
class SendRecurringInvoices extends Command
{
diff --git a/app/Handlers/InvoiceEventHandler.php b/app/Handlers/InvoiceEventHandler.php
index 7b6f4e9cc52b..0296e7818518 100644
--- a/app/Handlers/InvoiceEventHandler.php
+++ b/app/Handlers/InvoiceEventHandler.php
@@ -1,7 +1,7 @@
-getRealPath();
- require_once app_path().'/includes/parsecsv.lib.php';
+ require_once app_path().'/Includes/parsecsv.lib.php';
$csv = new parseCSV();
$csv->heading = false;
$csv->auto($name);
diff --git a/app/Http/Controllers/AccountGatewayController.php b/app/Http/Controllers/AccountGatewayController.php
index e6f646e4e70a..eb18642c1959 100644
--- a/app/Http/Controllers/AccountGatewayController.php
+++ b/app/Http/Controllers/AccountGatewayController.php
@@ -1,4 +1,4 @@
- $app, 'database' => $database, 'mail' => $mail] as $key => $config) {
$content = ' 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
+ 'absurd' => 'App\Http\Middleware\StartupCheck',
];
}
diff --git a/app/Http/Middleware/StartupCheck.php b/app/Http/Middleware/StartupCheck.php
new file mode 100644
index 000000000000..1bf247dfa177
--- /dev/null
+++ b/app/Http/Middleware/StartupCheck.php
@@ -0,0 +1,73 @@
+version != NINJA_VERSION) {
+ $params = [
+ 'user_version' => NINJA_VERSION,
+ 'latest_version'=> $data->version,
+ 'releases_link' => link_to(RELEASES_URL, 'Invoice Ninja', ['target' => '_blank'])
+ ];
+ Session::put('news_feed_id', NEW_VERSION_AVAILABLE);
+ Session::put('news_feed_message', trans('texts.new_version_available', $params));
+ } else {
+ Session::put('news_feed_id', $data->id);
+ if ($data->message && $data->id > Auth::user()->news_feed_id) {
+ Session::put('news_feed_message', $data->message);
+ }
+ }
+ } else {
+ Session::put('news_feed_id', true);
+ }
+ }
+ }
+
+ return $next($request);
+ }
+
+}
diff --git a/app/Http/routes.php b/app/Http/routes.php
index 9fbaa5ad9c25..89c0cf916758 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -64,7 +64,7 @@ Route::get('user/reset/{token?}', 'UserController@reset_password');
Route::post('user/reset', 'UserController@do_reset_password');
Route::get('logout', 'UserController@logout');
-if (\App\libraries\Utils::isNinja()) {
+if (\App\Libraries\Utils::isNinja()) {
Route::post('/signup/register', 'AccountController@doRegister');
Route::get('/news_feed/{user_type}/{version}/', 'HomeController@newsFeed');
Route::get('/demo', 'AccountController@demo');
diff --git a/app/includes/parsecsv.lib.php b/app/Includes/parsecsv.lib.php
similarity index 100%
rename from app/includes/parsecsv.lib.php
rename to app/Includes/parsecsv.lib.php
diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php
index 609ae864cd35..0982f18af80c 100644
--- a/app/Libraries/Utils.php
+++ b/app/Libraries/Utils.php
@@ -1,5 +1,7 @@
registered;
- }
-
- public static function isConfirmed()
- {
- return Auth::check() && Auth::user()->confirmed;
- }
-
- public static function isDatabaseSetup()
- {
- try {
- if (Schema::hasTable('accounts')) {
- return true;
- }
- } catch (Exception $e) {
- return false;
- }
- }
-
- public static function isProd()
- {
- return App::environment() == ENV_PRODUCTION;
- }
-
- public static function isNinja()
- {
- return self::isNinjaProd() || self::isNinjaDev();
- }
-
- public static function isNinjaProd()
- {
- return isset($_ENV['NINJA_PROD']) && $_ENV['NINJA_PROD'];
- }
-
- public static function isNinjaDev()
- {
- return isset($_ENV['NINJA_DEV']) && $_ENV['NINJA_DEV'];
- }
-
- public static function isPro()
- {
- return Auth::check() && Auth::user()->isPro();
- }
-
- public static function getUserType()
- {
- if (Utils::isNinja()) {
- return USER_TYPE_CLOUD_HOST;
- } else {
- return USER_TYPE_SELF_HOST;
- }
- }
-
- public static function getDemoAccountId()
- {
- return isset($_ENV[DEMO_ACCOUNT_ID]) ? $_ENV[DEMO_ACCOUNT_ID] : false;
- }
-
- public static function isDemo()
- {
- return Auth::check() && Auth::user()->isDemo();
- }
-
- public static function getNewsFeedResponse($userType = false)
- {
- if (!$userType) {
- $userType = Utils::getUserType();
- }
-
- $response = new stdClass();
- $response->message = isset($_ENV["{$userType}_MESSAGE"]) ? $_ENV["{$userType}_MESSAGE"] : '';
- $response->id = isset($_ENV["{$userType}_ID"]) ? $_ENV["{$userType}_ID"] : '';
- $response->version = NINJA_VERSION;
-
- return $response;
- }
-
- public static function getProLabel($feature)
- {
- if (Auth::check()
- && !Auth::user()->isPro()
- && $feature == ACCOUNT_ADVANCED_SETTINGS) {
- return ' PRO';
- } else {
- return '';
- }
- }
-
- public static function basePath()
- {
- return substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/') + 1);
- }
-
- public static function trans($input)
- {
- $data = [];
-
- foreach ($input as $field) {
- if ($field == "checkbox") {
- $data[] = $field;
- } else {
- $data[] = trans("texts.$field");
- }
- }
-
- return $data;
- }
-
- public static function fatalError($message = false, $exception = false)
- {
- if (!$message) {
- $message = "An error occurred, please try again later.";
- }
-
- static::logError($message.' '.$exception);
-
- $data = [
- 'showBreadcrumbs' => false,
- 'hideHeader' => true,
- ];
-
- return View::make('error', $data)->with('error', $message);
- }
-
- public static function getErrorString($exception)
- {
- return "{$exception->getFile()} [Line {$exception->getLine()}] => {$exception->getMessage()}";
- }
-
- public static function logError($error, $context = 'PHP')
- {
- $count = Session::get('error_count', 0);
- Session::put('error_count', ++$count);
- if ($count > 100) {
- return 'logged';
- }
-
- $data = [
- 'context' => $context,
- 'user_id' => Auth::check() ? Auth::user()->id : 0,
- 'user_name' => Auth::check() ? Auth::user()->getDisplayName() : '',
- 'url' => Input::get('url', Request::url()),
- 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
- 'ip' => Request::getClientIp(),
- 'count' => Session::get('error_count', 0),
- ];
-
- Log::error($error."\n", $data);
-
- /*
- Mail::queue('emails.error', ['message'=>$error.' '.json_encode($data)], function($message)
- {
- $message->to($email)->subject($subject);
- });
- */
- }
-
- public static function parseFloat($value)
- {
- $value = preg_replace('/[^0-9\.\-]/', '', $value);
-
- return floatval($value);
- }
-
- public static function formatPhoneNumber($phoneNumber)
- {
- $phoneNumber = preg_replace('/[^0-9a-zA-Z]/', '', $phoneNumber);
-
- if (!$phoneNumber) {
- return '';
- }
-
- if (strlen($phoneNumber) > 10) {
- $countryCode = substr($phoneNumber, 0, strlen($phoneNumber)-10);
- $areaCode = substr($phoneNumber, -10, 3);
- $nextThree = substr($phoneNumber, -7, 3);
- $lastFour = substr($phoneNumber, -4, 4);
-
- $phoneNumber = '+'.$countryCode.' ('.$areaCode.') '.$nextThree.'-'.$lastFour;
- } elseif (strlen($phoneNumber) == 10 && in_array(substr($phoneNumber, 0, 3), array(653, 656, 658, 659))) {
- /**
- * SG country code are 653, 656, 658, 659
- * US area code consist of 650, 651 and 657
- * @see http://en.wikipedia.org/wiki/Telephone_numbers_in_Singapore#Numbering_plan
- * @see http://www.bennetyee.org/ucsd-pages/area.html
- */
- $countryCode = substr($phoneNumber, 0, 2);
- $nextFour = substr($phoneNumber, 2, 4);
- $lastFour = substr($phoneNumber, 6, 4);
-
- $phoneNumber = '+'.$countryCode.' '.$nextFour.' '.$lastFour;
- } elseif (strlen($phoneNumber) == 10) {
- $areaCode = substr($phoneNumber, 0, 3);
- $nextThree = substr($phoneNumber, 3, 3);
- $lastFour = substr($phoneNumber, 6, 4);
-
- $phoneNumber = '('.$areaCode.') '.$nextThree.'-'.$lastFour;
- } elseif (strlen($phoneNumber) == 7) {
- $nextThree = substr($phoneNumber, 0, 3);
- $lastFour = substr($phoneNumber, 3, 4);
-
- $phoneNumber = $nextThree.'-'.$lastFour;
- }
-
- return $phoneNumber;
- }
-
- public static function formatMoney($value, $currencyId = false)
- {
- if (!$currencyId) {
- $currencyId = Session::get(SESSION_CURRENCY);
- }
-
- $currency = Currency::remember(DEFAULT_QUERY_CACHE)->find($currencyId);
-
- if (!$currency) {
- $currency = Currency::remember(DEFAULT_QUERY_CACHE)->find(1);
- }
-
- return $currency->symbol.number_format($value, $currency->precision, $currency->decimal_separator, $currency->thousand_separator);
- }
-
- public static function pluralize($string, $count)
- {
- $field = $count == 1 ? $string : $string.'s';
- $string = trans("texts.$field", ['count' => $count]);
-
- return $string;
- }
-
- public static function toArray($data)
- {
- return json_decode(json_encode((array) $data), true);
- }
-
- public static function toSpaceCase($camelStr)
- {
- return preg_replace('/([a-z])([A-Z])/s', '$1 $2', $camelStr);
- }
-
- public static function timestampToDateTimeString($timestamp)
- {
- $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
- $format = Session::get(SESSION_DATETIME_FORMAT, DEFAULT_DATETIME_FORMAT);
-
- return Utils::timestampToString($timestamp, $timezone, $format);
- }
-
- public static function timestampToDateString($timestamp)
- {
- $timezone = Session::get(SESSION_TIMEZONE, DEFAULT_TIMEZONE);
- $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
-
- return Utils::timestampToString($timestamp, $timezone, $format);
- }
-
- public static function dateToString($date)
- {
- $dateTime = new DateTime($date);
- $timestamp = $dateTime->getTimestamp();
- $format = Session::get(SESSION_DATE_FORMAT, DEFAULT_DATE_FORMAT);
-
- return Utils::timestampToString($timestamp, false, $format);
- }
-
- public static function timestampToString($timestamp, $timezone = false, $format)
- {
- if (!$timestamp) {
- return '';
- }
- $date = Carbon::createFromTimeStamp($timestamp);
- if ($timezone) {
- $date->tz = $timezone;
- }
- if ($date->year < 1900) {
- return '';
- }
-
- return $date->format($format);
- }
-
- public static function toSqlDate($date, $formatResult = true)
- {
- if (!$date) {
- return;
- }
-
- $timezone = Session::get(SESSION_TIMEZONE);
- $format = Session::get(SESSION_DATE_FORMAT);
-
- $dateTime = DateTime::createFromFormat($format, $date, new DateTimeZone($timezone));
-
- return $formatResult ? $dateTime->format('Y-m-d') : $dateTime;
- }
-
- public static function fromSqlDate($date, $formatResult = true)
- {
- if (!$date || $date == '0000-00-00') {
- return '';
- }
-
- $timezone = Session::get(SESSION_TIMEZONE);
- $format = Session::get(SESSION_DATE_FORMAT);
-
- $dateTime = DateTime::createFromFormat('Y-m-d', $date, new DateTimeZone($timezone));
-
- return $formatResult ? $dateTime->format($format) : $dateTime;
- }
-
- public static function today($formatResult = true)
- {
- $timezone = Session::get(SESSION_TIMEZONE);
- $format = Session::get(SESSION_DATE_FORMAT);
- $date = date_create(null, new DateTimeZone($timezone));
-
- if ($formatResult) {
- return $date->format($format);
- } else {
- return $date;
- }
- }
-
- public static function trackViewed($name, $type, $url = false)
- {
- if (!$url) {
- $url = Request::url();
- }
-
- $viewed = Session::get(RECENTLY_VIEWED);
-
- if (!$viewed) {
- $viewed = [];
- }
-
- $object = new stdClass();
- $object->url = $url;
- $object->name = ucwords($type).': '.$name;
-
- $data = [];
-
- for ($i = 0; $i