Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freescout-helpdesk/freescout into…
Browse files Browse the repository at this point in the history
… dist
  • Loading branch information
freescout-help-desk committed Oct 6, 2020
2 parents ac3255e + cfa2280 commit fbf88be
Show file tree
Hide file tree
Showing 18 changed files with 192 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Thumbs.db
/Modules
/Modules/**/.git
/public/modules
/public/docs
/storage/.ignore_locales
/storage/.installed
/tools
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ Need anything else? Suggest features [here](https://freescout.net/request-featur

## Mobile Apps

<a href="https://freescout.net/android-app/" target="_blank"><img alt="Android App" src="https://freescout-helpdesk.github.io/img/apps/android.png" width="200px" /></a>
<a href="https://freescout.net/android-app/" target="_blank" rel="nofollow"><img alt="Android App" src="https://freescout-helpdesk.github.io/img/apps/android.png" width="200px" /></a>

<a href="https://freescout.net/ios-app/" target="_blank" rel="nofollow"><img alt="iOS App" src="https://freescout-helpdesk.github.io/img/apps/ios.png?v=1" width="200px" /></a>

## Modules

Expand Down
140 changes: 130 additions & 10 deletions app/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ public function setPhones(array $phones_array)
public static function formatPhones(array $phones_array)
{
$phones = [];

foreach ($phones_array as $phone) {
if (is_array($phone)) {
if (!empty($phone['value']) && !empty($phone['type']) && in_array($phone['type'], array_keys(self::$phone_types))) {
Expand All @@ -669,10 +670,17 @@ public static function formatPhones(array $phones_array)
*/
public function addPhone($phone, $type = self::PHONE_TYPE_WORK)
{
$this->setPhones(array_merge(
$this->getPhones(),
[['value' => $phone, 'type' => $type]]
));
if (is_string($phone)) {
$this->setPhones(array_merge(
$this->getPhones(),
[['value' => $phone, 'type' => $type]]
));
} else {
$this->setPhones(array_merge(
$this->getPhones(),
[$phone]
));
}
}

/**
Expand Down Expand Up @@ -725,6 +733,9 @@ public function setWebsites(array $websites_array)
foreach ($websites_array as $key => $value) {
// FILTER_SANITIZE_URL cuts some symbols.
//$value = filter_var((string) $value, FILTER_SANITIZE_URL);
if (isset($value['value'])) {
$value = $value['value'];
}
if (!preg_match("/http(s)?:\/\//i", $value)) {
$value = 'http://'.$value;
}
Expand All @@ -739,10 +750,66 @@ public function setWebsites(array $websites_array)
public function addWebsite($website)
{
$websites = $this->getWebsites();
if (isset($website['value'])) {
$website = $website['value'];
}
array_push($websites, $website);
$this->setWebsites($websites);
}

/**
* Sanitize social profiles.
*
* @param array $list [description]
*
* @return array [description]
*/
public static function formatSocialProfiles(array $list)
{
$social_profiles = [];
foreach ($list as $social_profile) {
if (is_array($social_profile)) {
if (!empty($social_profile['value']) && !empty($social_profile['type'])
&& in_array($social_profile['type'], array_keys(self::$social_types))
) {
$social_profiles[] = [
'value' => (string) $social_profile['value'],
'type' => (int) $social_profile['type'],
];
}
} else {
$social_profiles[] = [
'value' => (string) $social_profile,
'type' => self::SOCIAL_TYPE_OTHER,
];
}
}

return $social_profiles;
}

/**
* Set social profiles as JSON.
*
* @param array $websites_array
*/
public function setSocialProfiles(array $sp_array)
{
$sp_array = self::formatSocialProfiles($sp_array);

// Remove dubplicates.
$list = [];
foreach ($sp_array as $i => $data) {
if (in_array($data['value'], $list)) {
unset($sp_array[$i]);
} else {
$list[] = $data['value'];
}
}

$this->social_profiles = \Helper::jsonEncodeUtf8($sp_array);
}

/**
* Create customer or get existing and fill empty fields.
*
Expand Down Expand Up @@ -789,6 +856,8 @@ public static function create($email, $data = [])
$email_obj->save();
}

// Todo: check phone uniqueness.

if ($new) {
\Eventy::action('customer.created', $customer);
}
Expand All @@ -803,6 +872,11 @@ public function setData($data, $replace_data = true, $save = false)
{
$result = false;

// todo: photoUrl.
if (isset($data['photo_url'])) {
unset($data['photo_url']);
}

if ($replace_data) {
// Replace data.
$this->fill($data);
Expand All @@ -818,23 +892,57 @@ public function setData($data, $replace_data = true, $save = false)
}

// Set JSON values.
if (!empty($data['phone'])) {
$this->addPhone($data['phone']);
}
foreach ($data as $key => $value) {
if (!in_array($key, $this->json_fields)) {
if (!in_array($key, $this->json_fields) && $key != 'emails') {
continue;
}
// todo: setChats, setSocialProfiles
// todo: setChats
if ($key == 'emails') {
foreach ($value as $email_data) {
if (!empty($email_data['value'])) {
if (!$this->id) {
$this->save();
}
$email_created = Email::create($email_data['value'], $this->id, $email_data['type']);

if ($email_created) {
$result = true;
}
}
}
}
if ($key == 'phones') {
foreach ($value as $phone_value) {
$this->addPhone($phone_value);
if (isset($value['value'])) {
$this->addPhone($value);
} else {
foreach ($value as $phone_value) {
$this->addPhone($phone_value);
}
}
$result = true;
}
if ($key == 'websites') {
$this->addWebsite($value);
if (is_array($value)) {
foreach ($value as $website) {
$this->addWebsite($website);
}
} else {
$this->addWebsite($value);
}
$result = true;
}
if ($key == 'social_profiles') {
$this->setSocialProfiles($value);
$result = true;
}
}

// Maybe Todo: check phone uniqueness.
// Same phone can be written in many ways, so it's almost useless to chek uniqueness.

if ($save) {
$this->save();
}
Expand All @@ -843,12 +951,14 @@ public function setData($data, $replace_data = true, $save = false)
}

/**
* Create a customer, email is not required.
* For phone conversations.
*/
public static function createWithoutEmail($data = [])
{
$customer = new self();
$customer->fill($data);
$customer->setData($data);

$customer->save();

\Eventy::action('customer.created', $customer);
Expand All @@ -866,6 +976,16 @@ public function url()
return route('customers.update', ['id'=>$this->id]);
}

/**
* Get view customer URL.
*
* @return string
*/
public function urlView()
{
return route('customers.conversations', ['id'=>$this->id]);
}

/**
* Format date according to customer's timezone.
*
Expand Down
15 changes: 15 additions & 0 deletions app/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ public function getNameFromEmail()
{
return explode('@', $this->email)[0];
}

public static function create($email, $customer_id, $type = self::TYPE_WORK)
{
try {
$email_obj = new Email();
$email_obj->email = $email;
$email_obj->type = array_key_exists($type, self::$types) ? $type : self::TYPE_WORK;
$email_obj->customer_id = $customer_id;
$email_obj->save();

return $email_obj;
} catch (\Exception $e) {
return null;
}
}
}
7 changes: 6 additions & 1 deletion app/Http/Controllers/ModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function ajax(Request $request)
$type = 'success';
$msg = __('":name" module successfully activated!', ['name' => $name]);
} else {
// Deactivate module
// Deactivate the module.
\App\Module::setActive($alias, false);
\Artisan::call('freescout:clear-cache');
}
Expand All @@ -327,6 +327,11 @@ public function ajax(Request $request)
}
}

if ($type == 'success') {
// Migrate again, in case migration did not work in the moment the module was activated.
\Artisan::call('migrate');
}

// \Session::flash does not work after BufferedOutput
$flash = [
'text' => '<strong>'.$msg.'</strong><pre class="margin-top">'.$output.'</pre>',
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function status(Request $request)
// Functions.
$functions = [
'shell_exec (PHP)' => function_exists('shell_exec'),
'proc_open (PHP)' => function_exists('proc_open'),
'ps (shell)' => function_exists('shell_exec') ? shell_exec('ps') : false,
];

Expand Down
9 changes: 4 additions & 5 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Kernel extends HttpKernel
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\TrustProxies::class,
// todo: These two may need to be moved into 'web' not to be called in 'api'.
\App\Http\Middleware\ResponseHeaders::class,
\App\Http\Middleware\TerminateHandler::class,
];
Expand All @@ -45,10 +44,10 @@ class Kernel extends HttpKernel
\App\Http\Middleware\CustomHandle::class,
],

'api' => [
'throttle:60,1',
'bindings',
],
// 'api' => [
// 'throttle:60,1',
// 'bindings',
// ],
];

/**
Expand Down
5 changes: 5 additions & 0 deletions app/Misc/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1363,4 +1363,9 @@ public static function isPrint()
{
return (bool)app('request')->input('print');
}

public static function isDev()
{
return config('app.env') != 'production';
}
}
2 changes: 1 addition & 1 deletion app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Mail
'regex:/<div style="border:none;border\-top:solid \#[A-Z0-9]{6} 1\.0pt;padding:3\.0pt 0in 0in 0in">[^<]*<p class="MsoNormal"><b>/', // MS Outlook

// General separators.
'<blockquote', // General sepator
'regex:/<blockquote((?!quote)[^>])*>/', // General sepator. Should skip Gmail's <blockquote class="gmail_quote">.
'<!-- originalMessage -->',
'‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐',
'--------------- Original Message ---------------',
Expand Down
4 changes: 2 additions & 2 deletions app/Providers/PolycastServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public function boot()
$payload = $collection->map(function ($item, $key) use ($request) {
$created = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $item->created_at);
$requested = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $request->get('time'));
$item->channels = json_decode($item->channels);
$item->payload = json_decode($item->payload);
$item->channels = json_decode($item->channels, false);
$item->payload = json_decode($item->payload, false);
// Add extra data to the payload
// This works only if payload has medius and thread_id
$item->data = BroadcastNotification::fetchPayloadData($item->payload);
Expand Down
16 changes: 8 additions & 8 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function boot()
*/
public function map()
{
$this->mapApiRoutes();
//$this->mapApiRoutes();

$this->mapWebRoutes();

Expand Down Expand Up @@ -71,11 +71,11 @@ protected function mapWebRoutes()
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
// protected function mapApiRoutes()
// {
// Route::prefix('api')
// ->middleware('api')
// ->namespace($this->namespace)
// ->group(base_path('routes/api.php'));
// }
}
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '1.6.1',
'version' => '1.6.2',

/*
|--------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
'provider' => 'users',
],

'api' => [
'driver' => 'token',
'provider' => 'users',
],
// 'api' => [
// 'driver' => 'token',
// 'provider' => 'users',
// ],
],

/*
Expand Down
Loading

0 comments on commit fbf88be

Please sign in to comment.