2018-09-07 15:08:34 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class for defining common app functions.
|
|
|
|
*/
|
2018-11-12 10:12:57 +01:00
|
|
|
|
2018-09-07 15:08:34 +02:00
|
|
|
namespace App\Misc;
|
|
|
|
|
|
|
|
class Helper
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Default query cache time in seconds for remember() function.
|
|
|
|
*/
|
|
|
|
const QUERY_CACHE_TIME = 1000;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text preview max length.
|
|
|
|
*/
|
|
|
|
const PREVIEW_MAXLENGTH = 255;
|
|
|
|
|
2018-09-11 14:12:35 +02:00
|
|
|
/**
|
|
|
|
* Menu structure used to display active menu item.
|
|
|
|
* Array are mnemonic names, strings - route names.
|
|
|
|
* Menu has 2 levels.
|
|
|
|
*/
|
|
|
|
public static $menu = [
|
|
|
|
'dashboard' => 'dashboard',
|
2018-11-12 10:12:57 +01:00
|
|
|
'mailbox' => [
|
2018-09-11 14:12:35 +02:00
|
|
|
'mailboxes.view',
|
2018-12-03 11:06:29 +01:00
|
|
|
'mailboxes.view.folder',
|
2018-11-12 10:12:57 +01:00
|
|
|
'conversations.view',
|
|
|
|
'conversations.create',
|
|
|
|
'conversations.draft',
|
|
|
|
'conversations.search',
|
2018-09-11 14:12:35 +02:00
|
|
|
],
|
|
|
|
'manage' => [
|
2018-11-12 10:12:57 +01:00
|
|
|
'settings' => 'settings',
|
2018-09-11 14:12:35 +02:00
|
|
|
'mailboxes' => [
|
2018-11-12 10:12:57 +01:00
|
|
|
'mailboxes',
|
|
|
|
'mailboxes.update',
|
|
|
|
'mailboxes.create',
|
|
|
|
'mailboxes.connection',
|
|
|
|
'mailboxes.connection.incoming',
|
|
|
|
'mailboxes.permissions',
|
|
|
|
'mailboxes.auto_reply',
|
2018-09-11 14:12:35 +02:00
|
|
|
],
|
|
|
|
'users' => [
|
2018-11-12 10:12:57 +01:00
|
|
|
'users',
|
|
|
|
'users.create',
|
|
|
|
'users.profile',
|
|
|
|
'users.permissions',
|
|
|
|
'users.notifications',
|
|
|
|
'users.password',
|
2018-09-11 14:12:35 +02:00
|
|
|
],
|
2018-11-08 07:42:38 +01:00
|
|
|
'logs' => [
|
2018-11-12 10:12:57 +01:00
|
|
|
'logs',
|
2018-11-08 07:42:38 +01:00
|
|
|
'logs.app',
|
|
|
|
],
|
|
|
|
'system' => [
|
2018-11-12 10:12:57 +01:00
|
|
|
'system',
|
2018-11-08 07:42:38 +01:00
|
|
|
'system.tools',
|
|
|
|
],
|
2018-09-11 14:12:35 +02:00
|
|
|
],
|
|
|
|
// No menu item selected
|
2018-11-12 10:12:57 +01:00
|
|
|
'customers' => [],
|
2018-09-11 14:12:35 +02:00
|
|
|
];
|
|
|
|
|
2018-11-25 08:16:20 +01:00
|
|
|
/**
|
|
|
|
* Locales data.
|
2018-11-26 13:47:05 +01:00
|
|
|
*
|
2018-11-25 08:16:20 +01:00
|
|
|
* @var [type]
|
|
|
|
*/
|
2018-09-26 09:00:13 +02:00
|
|
|
public static $locales = [
|
2018-11-26 13:47:05 +01:00
|
|
|
'af' => ['name' => 'Afrikaans',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Afrikaans',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sq' => ['name' => 'Shqip',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Albanian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_IQ' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Iraq)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_LY' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Libya)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_MA' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Morocco)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_OM' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Oman)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_SY' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Syria)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_LB' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Lebanon)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_AE' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (U.A.E.)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_QA' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Qatar)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_SA' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Saudi Arabia)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_EG' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Egypt)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_DZ' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Algeria)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_TN' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Tunisia)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_YE' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Yemen)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_JO' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Jordan)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_KW' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Kuwait)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ar_BH' => ['name' => 'العربية',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Arabic (Bahrain)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'eu' => ['name' => 'Euskara',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Basque',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'be' => ['name' => 'Беларуская',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Belarusian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'bn' => ['name' => 'বাংলা',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Bengali',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'bg' => ['name' => 'Български език',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Bulgarian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ca' => ['name' => 'Català',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Catalan',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'zh_CN' => ['name' => '简体中文',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Chinese (Simplified)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'zh_SG' => ['name' => '简体中文',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Chinese (Singapore)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'zh_TW' => ['name' => '简体中文',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Chinese (Traditional)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'zh_HK' => ['name' => '简体中文',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Chinese (Hong Kong SAR)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'hr' => ['name' => 'Hrvatski',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Croatian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'cs' => ['name' => 'Čeština',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Czech',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'da' => ['name' => 'Dansk',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Danish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'nl' => ['name' => 'Nederlands',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Dutch',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'nl_BE' => ['name' => 'Nederlands',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Dutch (Belgium)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_US' => ['name' => 'English',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (United States)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_AU' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Australia)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_NZ' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (New Zealand)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_ZA' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (South Africa)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'en' => ['name' => 'English',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'English',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'en_TT' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Trinidad)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_GB' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (United Kingdom)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_CA' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Canada)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_IE' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Ireland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_JM' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Jamaica)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'en_BZ' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'English (Belize)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'et' => ['name' => 'Eesti',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Estonian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'fo' => ['name' => 'Føroyskt',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Faeroese',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'fa' => ['name' => 'فارسی',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Farsi',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'fi' => ['name' => 'Suomi',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Finnish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'fr' => ['name' => 'Français',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'French',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'fr_CA' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'French (Canada)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'fr_LU' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'French (Luxembourg)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'fr_BE' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'French (Belgium)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'fr_CH' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'French (Switzerland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'gd' => ['name' => 'Gàidhlig',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Gaelic (Scotland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'de' => ['name' => 'Deutsch',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'German',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'de_CH' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'German (Switzerland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'de_LU' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'German (Luxembourg)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'de_AT' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'German (Austria)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'de_LI' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'German (Liechtenstein)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'el' => ['name' => 'Ελληνικά',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Greek',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'he' => ['name' => 'עברית',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Hebrew',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'hi' => ['name' => 'हिन्दी',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Hindi',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'hu' => ['name' => 'Magyar',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Hungarian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'is' => ['name' => 'Íslenska',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Icelandic',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'id' => ['name' => 'Bahasa Indonesia',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Indonesian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ga' => ['name' => 'Gaeilge',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Irish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'it' => ['name' => 'Italiano',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Italian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'it_CH' => ['name' => 'Italiano',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Italian (Switzerland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ja' => ['name' => '日本語',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Japanese',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ko' => ['name' => '한국어 (韓國語)',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Korean (Johab)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'lv' => ['name' => 'Latviešu valoda',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Latvian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'lt' => ['name' => 'Lietuvių kalba',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Lithuanian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'mk' => ['name' => 'Македонски јазик',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Macedonian (FYROM)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ms' => ['name' => 'Bahasa Melayu, بهاس ملايو',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Malay',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'mt' => ['name' => 'Malti',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Maltese',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ne' => ['name' => 'नेपाली',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Nepali',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'no' => ['name' => 'Norsk bokmål',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Norwegian (Bokmal)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'pl' => ['name' => 'Polski',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Polish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'pt' => ['name' => 'Português',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Portuguese (Portugal)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'pt_BR' => ['name' => 'Português do Brasil',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Portuguese (Brazil)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ro' => ['name' => 'Română',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Romanian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'ro_MO' => ['name' => 'Română',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Romanian (Republic of Moldova)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'rm' => ['name' => 'Rumantsch grischun',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Romansh',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ru' => ['name' => 'Русский',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Russian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'ru_MO' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Russian (Republic of Moldova)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sz' => ['name' => 'Davvisámegiella',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Sami (Lappish)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sr' => ['name' => 'Српски језик',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Serbian (Latin)',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sk' => ['name' => 'Slovenčina',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Slovak',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sl' => ['name' => 'Slovenščina',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Slovenian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
/*'sb' => ['name' => 'Serbsce',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Sorbian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],*/
|
2018-11-26 13:47:05 +01:00
|
|
|
'es' => ['name' => 'Español',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Spanish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// 'es_GT' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Guatemala)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_PA' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Panama)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_VE' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Venezuela)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_PE' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Peru)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_EC' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Ecuador)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_UY' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Uruguay)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_BO' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Bolivia)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_HN' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Honduras)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_PR' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Puerto Rico)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_MX' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Mexico)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_CR' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Costa Rica)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_DO' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Dominican Republic)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_CO' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Colombia)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_AR' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Argentina)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_CL' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Chile)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_PY' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Paraguay)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_SV' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (El Salvador)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'es_NI' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Spanish (Nicaragua)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'sv' => ['name' => 'Svenska',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Swedish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
// unknown
|
|
|
|
// 'sx' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Sutu',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
|
|
|
// 'sv_FI' => ['name' => '',
|
2018-11-25 08:16:20 +01:00
|
|
|
// 'name_en' => 'Swedish (Finland)',
|
2018-09-26 09:00:13 +02:00
|
|
|
// ],
|
2018-11-26 13:47:05 +01:00
|
|
|
'th' => ['name' => 'ไทย',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Thai',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ts' => ['name' => 'Xitsonga',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Tsonga',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'tn' => ['name' => 'Setswana',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Tswana',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'tr' => ['name' => 'Türkçe',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Turkish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'uk' => ['name' => 'українська',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Ukrainian',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ur' => ['name' => 'اردو',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Urdu',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
've' => ['name' => 'Tshivenḓa',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Venda',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'vi' => ['name' => 'Tiếng Việt',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Vietnamese',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'xh' => ['name' => 'isiXhosa',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Xhosa',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'ji' => ['name' => 'ייִדיש',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Yiddish',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
2018-11-26 13:47:05 +01:00
|
|
|
'zu' => ['name' => 'isiZulu',
|
2018-11-25 08:16:20 +01:00
|
|
|
'name_en' => 'Zulu',
|
2018-09-26 09:00:13 +02:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
2018-09-07 15:08:34 +02:00
|
|
|
/**
|
|
|
|
* Cache time of the DB query.
|
|
|
|
*/
|
|
|
|
public static function cacheTime($enabled = true)
|
|
|
|
{
|
|
|
|
if ($enabled) {
|
|
|
|
return self::QUERY_CACHE_TIME;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get preview of the text in a plain form.
|
|
|
|
*/
|
|
|
|
public static function textPreview($text, $length = self::PREVIEW_MAXLENGTH)
|
|
|
|
{
|
|
|
|
// Remove all kinds of spaces after tags
|
|
|
|
// https://stackoverflow.com/questions/3230623/filter-all-types-of-whitespace-in-php
|
|
|
|
$text = preg_replace("/^(.*)>[\r\n]*\s+/mu", '$1>', $text);
|
|
|
|
|
|
|
|
$text = strip_tags($text);
|
|
|
|
$text = preg_replace('/\s+/mu', ' ', $text);
|
|
|
|
|
|
|
|
// Trim
|
|
|
|
$text = trim($text);
|
|
|
|
$text = preg_replace('/^\s+/mu', '', $text);
|
|
|
|
|
|
|
|
// Causes "General error: 1366 Incorrect string value"
|
|
|
|
// Remove "undetectable" whitespaces
|
|
|
|
// $whitespaces = ['%81', '%7F', '%C5%8D', '%8D', '%8F', '%C2%90', '%C2', '%90', '%9D', '%C2%A0', '%A0', '%C2%AD', '%AD', '%08', '%09', '%0A', '%0D'];
|
|
|
|
// $text = urlencode($text);
|
|
|
|
// foreach ($whitespaces as $char) {
|
|
|
|
// $text = str_replace($char, ' ', $text);
|
|
|
|
// }
|
|
|
|
// $text = urldecode($text);
|
|
|
|
|
|
|
|
$text = trim(preg_replace('/[ ]+/', ' ', $text));
|
|
|
|
|
|
|
|
$text = mb_substr($text, 0, $length);
|
|
|
|
|
|
|
|
return $text;
|
|
|
|
}
|
2018-09-11 14:12:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if passed route name equals to the current one.
|
|
|
|
*/
|
|
|
|
public static function isCurrentRoute($route_name)
|
|
|
|
{
|
|
|
|
if (\Request::route()->getName() == $route_name) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if menu item is selected.
|
|
|
|
* Each menu item has a mnemonic name.
|
|
|
|
*/
|
|
|
|
public static function isMenuSelected($menu_item_name)
|
|
|
|
{
|
|
|
|
$current_route = \Request::route()->getName();
|
|
|
|
|
2018-11-08 11:34:00 +01:00
|
|
|
$menu = \Eventy::filter('menu.selected', self::$menu);
|
|
|
|
|
|
|
|
foreach ($menu as $primary_name => $primary_items) {
|
2018-09-11 14:12:35 +02:00
|
|
|
if (!is_array($primary_items)) {
|
|
|
|
if ($current_route == $primary_items) {
|
2018-11-12 10:12:57 +01:00
|
|
|
return $primary_name == $menu_item_name;
|
2018-09-11 14:12:35 +02:00
|
|
|
}
|
|
|
|
if ($primary_name == $menu_item_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
foreach ($primary_items as $secondary_name => $secondary_routes) {
|
|
|
|
if (is_array($secondary_routes)) {
|
|
|
|
if (in_array($current_route, $secondary_routes)) {
|
2018-11-12 10:12:57 +01:00
|
|
|
return $secondary_name == $menu_item_name || $primary_name == $menu_item_name;
|
2018-09-11 14:12:35 +02:00
|
|
|
}
|
2018-09-21 08:10:36 +02:00
|
|
|
} elseif (is_string($secondary_name)) {
|
2018-09-11 14:12:35 +02:00
|
|
|
if ($current_route == $secondary_routes) {
|
2018-11-12 10:12:57 +01:00
|
|
|
return $secondary_name == $menu_item_name || $primary_name == $menu_item_name;
|
2018-09-11 14:12:35 +02:00
|
|
|
}
|
2018-09-21 08:10:36 +02:00
|
|
|
} else {
|
|
|
|
if ($current_route == $secondary_routes) {
|
2018-11-12 10:12:57 +01:00
|
|
|
return $primary_name == $menu_item_name;
|
2018-09-21 08:10:36 +02:00
|
|
|
}
|
2018-09-11 14:12:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 10:12:57 +01:00
|
|
|
|
2018-09-11 14:12:35 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function menuSelectedHtml($menu_item_name)
|
|
|
|
{
|
|
|
|
if (self::isMenuSelected($menu_item_name)) {
|
|
|
|
return 'active';
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
2018-09-16 20:48:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Resize image without using Intervention package.
|
|
|
|
*/
|
|
|
|
public static function resizeImage($file, $mime_type, $thumb_width, $thumb_height)
|
|
|
|
{
|
|
|
|
list($width, $height) = getimagesize($file);
|
|
|
|
if (!$width) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('/png/i', $mime_type)) {
|
|
|
|
$src = imagecreatefrompng($file);
|
2018-11-12 10:12:57 +01:00
|
|
|
} elseif (preg_match('/gif/i', $mime_type)) {
|
2018-09-16 20:48:09 +02:00
|
|
|
$src = imagecreatefromgif($file);
|
2018-11-12 10:12:57 +01:00
|
|
|
} elseif (preg_match('/bmp/i', $mime_type)) {
|
2018-09-16 20:48:09 +02:00
|
|
|
$src = imagecreatefrombmp($file);
|
|
|
|
} else {
|
|
|
|
$src = imagecreatefromjpeg($file);
|
|
|
|
}
|
2018-11-12 10:12:57 +01:00
|
|
|
|
2018-09-16 20:48:09 +02:00
|
|
|
$original_aspect = $width / $height;
|
|
|
|
$thumb_aspect = $thumb_width / $thumb_height;
|
2018-11-12 10:12:57 +01:00
|
|
|
if ($original_aspect == $thumb_aspect) {
|
2018-09-16 20:48:09 +02:00
|
|
|
$new_height = $thumb_height;
|
|
|
|
$new_width = $thumb_width;
|
2018-11-12 10:12:57 +01:00
|
|
|
} elseif ($original_aspect > $thumb_aspect) {
|
|
|
|
// If image is wider than thumbnail (in aspect ratio sense)
|
|
|
|
$new_height = $thumb_height;
|
|
|
|
$new_width = $width / ($height / $thumb_height);
|
2018-09-16 20:48:09 +02:00
|
|
|
} else {
|
2018-11-12 10:12:57 +01:00
|
|
|
// If the thumbnail is wider than the image
|
|
|
|
$new_width = $thumb_width;
|
|
|
|
$new_height = $height / ($width / $thumb_width);
|
2018-09-16 20:48:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
|
|
|
|
// Resize and crop
|
|
|
|
imagecopyresampled($thumb,
|
|
|
|
$src,
|
|
|
|
0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
|
|
|
|
0 - ($new_height - $thumb_height) / 2, // Center the image vertically
|
|
|
|
0, 0,
|
|
|
|
$new_width, $new_height,
|
|
|
|
$width, $height);
|
|
|
|
imagedestroy($src);
|
|
|
|
|
|
|
|
return $thumb;
|
|
|
|
}
|
2018-09-20 09:08:02 +02:00
|
|
|
|
|
|
|
public static function jsonToArray($json, $exclude_array = [])
|
|
|
|
{
|
|
|
|
if ($json) {
|
|
|
|
$array = json_decode($json, true);
|
|
|
|
if (json_last_error()) {
|
|
|
|
$array = [$json];
|
|
|
|
}
|
|
|
|
if ($array && $exclude_array) {
|
|
|
|
$array = array_diff($array, $exclude_array);
|
|
|
|
}
|
2018-11-12 10:12:57 +01:00
|
|
|
|
2018-09-20 09:08:02 +02:00
|
|
|
return $array;
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
2018-09-24 15:07:07 +02:00
|
|
|
|
|
|
|
public static function getDomain()
|
|
|
|
{
|
|
|
|
return parse_url(\Config::get('app.url'), PHP_URL_HOST);
|
|
|
|
}
|
2018-09-26 12:14:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create zip archive.
|
|
|
|
* Source example: public/files/*
|
2018-11-12 10:12:57 +01:00
|
|
|
* File name example: test.zip.
|
2018-09-26 12:14:54 +02:00
|
|
|
*/
|
|
|
|
public static function createZipArchive($source, $file_name, $folder = '')
|
|
|
|
{
|
|
|
|
if (!$source || !$file_name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$files = glob($source);
|
|
|
|
|
|
|
|
//$dest_folder = storage_path().DIRECTORY_SEPARATOR.'app/zipper';
|
|
|
|
// if (!file_exists($dest_folder)) {
|
|
|
|
// $mkdir_result = File::makeDirectory($dest_folder, 0755);
|
|
|
|
// if (!$mkdir_result) {
|
|
|
|
// return false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
$storage_path = 'app/zipper'.DIRECTORY_SEPARATOR.$file_name;
|
|
|
|
$dest_path = storage_path().DIRECTORY_SEPARATOR.$storage_path;
|
|
|
|
|
|
|
|
// If file exists it has to be deleted, otherwise Zipper will add file to the existing archive
|
|
|
|
// By some reason \Storage not finding $storage_path file
|
|
|
|
// todo: use \Storage
|
|
|
|
if (\File::exists($dest_path)) {
|
|
|
|
\File::delete($dest_path);
|
|
|
|
}
|
|
|
|
\Chumper\Zipper\Facades\Zipper::make($dest_path)->folder($folder)->add($files)->close();
|
|
|
|
|
|
|
|
return $dest_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function formatException($e)
|
|
|
|
{
|
|
|
|
return 'Error: '.$e->getMessage().'; File: '.$e->getFile().' ('.$e->getLine().')';
|
|
|
|
}
|
2018-10-31 07:14:59 +01:00
|
|
|
|
|
|
|
public static function denyAccess()
|
|
|
|
{
|
|
|
|
abort(403, 'This action is unauthorized.');
|
|
|
|
}
|
2018-11-04 20:12:37 +01:00
|
|
|
|
|
|
|
/**
|
2018-11-12 10:12:57 +01:00
|
|
|
* Check if application version.
|
|
|
|
*
|
|
|
|
* @param [type] $ver [description]
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
2018-11-04 20:12:37 +01:00
|
|
|
*/
|
|
|
|
public static function checkAppVersion($version2, $operator = '>=')
|
|
|
|
{
|
|
|
|
return version_compare(\Config::get('app.version'), $version2, $operator);
|
|
|
|
}
|
2018-11-06 10:27:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Download remote file and save as file.
|
|
|
|
*/
|
|
|
|
public static function downloadRemoteFile($url, $destinationFilePath)
|
|
|
|
{
|
|
|
|
$client = new \GuzzleHttp\Client();
|
|
|
|
$client->request('GET', $url, [
|
|
|
|
'sink' => $destinationFilePath,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract ZIP archive.
|
2018-11-12 10:12:57 +01:00
|
|
|
* to: must be apsolute path, otherwise extracted into /public/$to.
|
2018-11-06 10:27:53 +01:00
|
|
|
*/
|
|
|
|
public static function unzip($archive, $to)
|
|
|
|
{
|
|
|
|
\Chumper\Zipper\Facades\Zipper::make($archive)->extractTo($to);
|
|
|
|
}
|
2018-11-22 15:45:50 +01:00
|
|
|
|
|
|
|
public static function logException($e)
|
|
|
|
{
|
|
|
|
\Log::error(self::formatException($e));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Safely decrypt.
|
2018-11-24 11:11:51 +01:00
|
|
|
*
|
|
|
|
* @param [type] $e [description]
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
2018-11-22 15:45:50 +01:00
|
|
|
*/
|
|
|
|
public static function decrypt($value)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$value = decrypt($value);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
2018-11-24 11:11:51 +01:00
|
|
|
|
2018-11-22 15:45:50 +01:00
|
|
|
return $value;
|
|
|
|
}
|
2018-11-23 10:06:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Log custom data to activity log.
|
2018-11-24 11:11:51 +01:00
|
|
|
*
|
|
|
|
* @param [type] $log_name [description]
|
|
|
|
* @param [type] $data [description]
|
|
|
|
* @param [type] $code [description]
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
2018-11-23 10:06:32 +01:00
|
|
|
*/
|
|
|
|
public static function log($log_name, $description, $properties = [])
|
|
|
|
{
|
|
|
|
activity()
|
|
|
|
->withProperties($properties)
|
|
|
|
->useLog($log_name)
|
|
|
|
->log($description);
|
|
|
|
}
|
2018-11-24 09:43:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if folder is writable.
|
2018-11-24 11:11:51 +01:00
|
|
|
*
|
|
|
|
* @param [type] $path [description]
|
|
|
|
*
|
|
|
|
* @return bool [description]
|
2018-11-24 09:43:28 +01:00
|
|
|
*/
|
|
|
|
public static function isFolderWritable($path)
|
|
|
|
{
|
|
|
|
if (!file_exists($path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$path = rtrim($path, DIRECTORY_SEPARATOR);
|
2018-11-24 11:11:51 +01:00
|
|
|
|
2018-11-24 09:43:28 +01:00
|
|
|
try {
|
|
|
|
$file = $path.DIRECTORY_SEPARATOR.'.writable_test';
|
|
|
|
if ($file && file_put_contents($file, 'test')) {
|
|
|
|
unlink($file);
|
2018-11-24 11:11:51 +01:00
|
|
|
|
2018-11-24 09:43:28 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-11-25 08:16:20 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get locale's data.
|
2018-11-26 13:47:05 +01:00
|
|
|
*
|
|
|
|
* @param [type] $locale [description]
|
|
|
|
* @param string $param [description]
|
|
|
|
*
|
|
|
|
* @return [type] [description]
|
2018-11-25 08:16:20 +01:00
|
|
|
*/
|
|
|
|
public static function getLocaleData($locale, $param = '')
|
|
|
|
{
|
2018-11-26 10:22:05 +01:00
|
|
|
if (is_string($locale) && isset(self::$locales[$locale])) {
|
2018-11-25 08:16:20 +01:00
|
|
|
$data = self::$locales[$locale];
|
|
|
|
} else {
|
2018-11-26 13:47:05 +01:00
|
|
|
return;
|
2018-11-25 08:16:20 +01:00
|
|
|
}
|
2018-11-26 13:47:05 +01:00
|
|
|
|
2018-11-25 08:16:20 +01:00
|
|
|
if ($param) {
|
|
|
|
if (isset(self::$locales[$locale])) {
|
2018-11-25 12:18:53 +01:00
|
|
|
return self::$locales[$locale][$param];
|
2018-11-25 08:16:20 +01:00
|
|
|
} else {
|
2018-11-26 13:47:05 +01:00
|
|
|
return;
|
2018-11-25 08:16:20 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear application cache.
|
2018-11-26 13:47:05 +01:00
|
|
|
*
|
2018-11-25 08:16:20 +01:00
|
|
|
* @return [type] [description]
|
|
|
|
*/
|
|
|
|
public static function clearCache()
|
|
|
|
{
|
|
|
|
\Artisan::call('freescout:clear-cache');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set variable in .evn file.
|
|
|
|
*/
|
|
|
|
public static function setEnvFileVar($key, $value)
|
|
|
|
{
|
|
|
|
$env_path = app()->environmentFilePath();
|
|
|
|
$contents = file_get_contents($env_path);
|
|
|
|
|
|
|
|
// Maybe validate value and add quotes.
|
|
|
|
// str_contains($key, '=')
|
|
|
|
// !preg_match('/^[a-zA-Z_]+$/', $key)
|
|
|
|
|
|
|
|
$old_value = '';
|
|
|
|
// Match the given key at the beginning of a line
|
|
|
|
preg_match("/^{$key}=[^\r\n]*/m", $contents, $matches);
|
|
|
|
if (count($matches)) {
|
|
|
|
$old_value = substr($matches[0], strlen($key) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($old_value) {
|
|
|
|
// Replace.
|
|
|
|
$contents = str_replace("{$key}={$old_value}", "{$key}={$value}", $contents);
|
|
|
|
} else {
|
2018-12-12 15:39:24 +01:00
|
|
|
// Add or empty value
|
|
|
|
preg_match("/^{$key}=[\r\n]/m", $contents, $matches);
|
|
|
|
if (count($matches)) {
|
|
|
|
// Replace empty value
|
|
|
|
$contents = str_replace("{$key}=", "{$key}={$value}", $contents);
|
|
|
|
} else {
|
|
|
|
// Add.
|
|
|
|
$contents = $contents."\n{$key}={$value}\n";
|
|
|
|
}
|
2018-11-25 08:16:20 +01:00
|
|
|
}
|
2018-12-12 15:39:24 +01:00
|
|
|
\File::put($env_path, $contents);
|
2018-11-25 08:16:20 +01:00
|
|
|
}
|
2018-11-26 10:22:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User may add an extra translation to the app on Translate page.
|
2018-11-26 13:47:05 +01:00
|
|
|
*
|
2018-11-26 10:22:05 +01:00
|
|
|
* @return [type] [description]
|
|
|
|
*/
|
|
|
|
public static function getCustomLocales()
|
|
|
|
{
|
|
|
|
return \Barryvdh\TranslationManager\Models\Translation::distinct()->pluck('locale')->toArray();
|
|
|
|
}
|
2018-11-26 13:23:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* app()->setLocale() in Localize middleware also changes config('app.locale'),
|
|
|
|
* so we are keeping real app locale in real_locale parameter.
|
|
|
|
*/
|
|
|
|
public static function getRealAppLocale()
|
|
|
|
{
|
|
|
|
return config('app.real_locale');
|
|
|
|
}
|
2018-12-02 13:47:47 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a backgound job executing specified action.
|
2018-12-05 08:06:54 +01:00
|
|
|
*
|
2018-12-02 13:47:47 +01:00
|
|
|
* @return [type] [description]
|
|
|
|
*/
|
|
|
|
public static function backgroundAction($action, $params, $delay = 0)
|
|
|
|
{
|
|
|
|
$job = \App\Jobs\TriggerAction::dispatch($action, $params);
|
|
|
|
if ($delay) {
|
|
|
|
$job->delay($delay);
|
|
|
|
}
|
|
|
|
$job->onQueue('default');
|
|
|
|
}
|
2018-12-03 10:03:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert HTML into the text with \n.
|
2018-12-05 08:06:54 +01:00
|
|
|
*
|
2018-12-03 10:03:23 +01:00
|
|
|
* @param [type] $text [description]
|
|
|
|
*/
|
|
|
|
public static function htmlToText($text)
|
|
|
|
{
|
|
|
|
return (new \Html2Text\Html2Text($text))->getText();
|
|
|
|
}
|
2018-09-07 15:08:34 +02:00
|
|
|
}
|