2015-03-20 18:30:45 -06:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-05-25 17:59:08 +01:00
|
|
|
* (c) Cachet HQ <support@cachethq.io>
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-03-20 18:30:45 -06:00
|
|
|
use CachetHQ\Cachet\Facades\Setting;
|
|
|
|
use Illuminate\Database\QueryException;
|
|
|
|
use Illuminate\Support\Facades\Request;
|
2015-05-07 09:09:03 -05:00
|
|
|
use Jenssegers\Date\Date;
|
2015-03-20 18:30:45 -06:00
|
|
|
|
|
|
|
if (!function_exists('set_active')) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set active class if request is in path.
|
|
|
|
*
|
|
|
|
* @param string $path
|
|
|
|
* @param array $classes
|
|
|
|
* @param string $active
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function set_active($path, array $classes = [], $active = 'active')
|
|
|
|
{
|
|
|
|
if (Request::is($path)) {
|
|
|
|
$classes[] = $active;
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = implode(' ', $classes);
|
|
|
|
|
2015-07-02 13:20:51 -05:00
|
|
|
return empty($classes) ? '' : "class={$class}";
|
2015-03-20 18:30:45 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('segment_identify')) {
|
|
|
|
/**
|
|
|
|
* Identifies the user for Segment.com.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function segment_identify()
|
|
|
|
{
|
|
|
|
if (Config::get('segment.write_key')) {
|
|
|
|
try {
|
|
|
|
if (Setting::get('app_track')) {
|
2015-07-05 15:40:48 +01:00
|
|
|
return app('segment')->identify([
|
2015-03-20 18:30:45 -06:00
|
|
|
'anonymousId' => Config::get('app.key'),
|
|
|
|
'context' => [
|
2015-05-23 13:20:05 +01:00
|
|
|
'locale' => Config::get('app.locale'),
|
|
|
|
'timezone' => Setting::get('app_timezone'),
|
|
|
|
'DB_DRIVER' => getenv('DB_DRIVER'),
|
|
|
|
'CACHE_DRIVER' => getenv('CACHE_DRIVER'),
|
|
|
|
'SESSION_DRIVER' => getenv('SESSION_DRIVER'),
|
2015-03-20 18:30:45 -06:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('segment_track')) {
|
|
|
|
/**
|
|
|
|
* Tracks events in Segment.com.
|
|
|
|
*
|
|
|
|
* @param string $event
|
|
|
|
* @param array $properties
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-05-23 13:29:01 +01:00
|
|
|
function segment_track($event, array $properties = [])
|
2015-03-20 18:30:45 -06:00
|
|
|
{
|
|
|
|
if (Config::get('segment.write_key')) {
|
|
|
|
try {
|
|
|
|
if (Setting::get('app_track')) {
|
2015-07-05 15:40:48 +01:00
|
|
|
return app('segment')->track([
|
2015-03-20 18:30:45 -06:00
|
|
|
'anonymousId' => Config::get('app.key'),
|
|
|
|
'event' => $event,
|
|
|
|
'properties' => $properties,
|
|
|
|
'context' => [
|
2015-05-23 13:30:18 +01:00
|
|
|
'locale' => Config::get('app.locale'),
|
|
|
|
'timezone' => Setting::get('app_timezone'),
|
|
|
|
'DB_DRIVER' => getenv('DB_DRIVER'),
|
|
|
|
'CACHE_DRIVER' => getenv('CACHE_DRIVER'),
|
|
|
|
'SESSION_DRIVER' => getenv('SESSION_DRIVER'),
|
2015-03-20 18:30:45 -06:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!function_exists('segment_page')) {
|
|
|
|
/**
|
|
|
|
* Tracks pages in Segment.com.
|
|
|
|
*
|
|
|
|
* @param string $page
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function segment_page($page)
|
|
|
|
{
|
|
|
|
if (Config::get('segment.write_key')) {
|
|
|
|
try {
|
|
|
|
if (Setting::get('app_track')) {
|
2015-07-05 15:40:48 +01:00
|
|
|
return app('segment')->page([
|
2015-03-20 18:30:45 -06:00
|
|
|
'anonymousId' => Config::get('app.key'),
|
2015-05-23 13:13:38 +01:00
|
|
|
'name' => $page,
|
2015-03-20 18:30:45 -06:00
|
|
|
'context' => [
|
2015-05-23 13:30:18 +01:00
|
|
|
'locale' => Config::get('app.locale'),
|
|
|
|
'timezone' => Setting::get('app_timezone'),
|
|
|
|
'DB_DRIVER' => getenv('DB_DRIVER'),
|
|
|
|
'CACHE_DRIVER' => getenv('CACHE_DRIVER'),
|
|
|
|
'SESSION_DRIVER' => getenv('SESSION_DRIVER'),
|
2015-03-20 18:30:45 -06:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (QueryException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-07 09:09:03 -05:00
|
|
|
|
|
|
|
if (!function_exists('formatted_date')) {
|
|
|
|
/**
|
|
|
|
* Formats a date with the user timezone and the selected format.
|
|
|
|
*
|
|
|
|
* @param string $date
|
|
|
|
*
|
|
|
|
* @return \Jenssegers\Date\Date
|
|
|
|
*/
|
|
|
|
function formatted_date($date)
|
|
|
|
{
|
2015-05-20 12:56:59 -05:00
|
|
|
$dateFormat = Setting::get('date_format', 'jS F Y');
|
2015-05-07 09:09:03 -05:00
|
|
|
|
2015-05-07 10:37:32 -05:00
|
|
|
return (new Date($date))->format($dateFormat);
|
2015-05-07 09:09:03 -05:00
|
|
|
}
|
|
|
|
}
|