1
0

BxMessengerConfig.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Messenger Messenger
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolPrivacy');
  12. class BxMessengerConfig extends BxBaseModGeneralConfig
  13. {
  14. function __construct($aModule)
  15. {
  16. parent::__construct($aModule);
  17. $this->CNF = array(
  18. // module icon
  19. 'ICON' => 'comments-o col-green3',
  20. // database tables
  21. 'TABLE_ENTRIES' => $aModule['db_prefix'] . 'lots',
  22. 'TABLE_NEW_MESSAGES' => $aModule['db_prefix'] . 'unread_jots',
  23. 'TABLE_MESSAGES' => $aModule['db_prefix'] . 'jots',
  24. 'TABLE_TYPES' => $aModule['db_prefix'] . 'lots_types',
  25. 'TABLE_USERS_INFO' => $aModule['db_prefix'] . 'users_info',
  26. 'TABLE_LIVE_COMMENTS' => $aModule['db_prefix'] . 'lcomments',
  27. 'TABLE_JOT_REACTIONS' => $aModule['db_prefix'] . 'jot_reactions',
  28. 'TABLE_JVC' => $aModule['db_prefix'] . 'jvc',
  29. 'TABLE_PUBLIC_JVC' => $aModule['db_prefix'] . 'public_jvc',
  30. 'TABLE_JVCT' => $aModule['db_prefix'] . 'jvc_track',
  31. 'TABLE_LOT_SETTINGS' => $aModule['db_prefix'] . 'lots_settings',
  32. 'TABLE_GROUPS' => $aModule['db_prefix'] . 'groups',
  33. 'TABLE_GROUPS_LOTS' => $aModule['db_prefix'] . 'groups_lots',
  34. 'TABLE_SAVED_JOTS' => $aModule['db_prefix'] . 'saved_jots',
  35. 'TABLE_LOT_ATTACHMENTS' => $aModule['db_prefix'] . 'attachments',
  36. 'TABLE_JOTS_MEDIA_TRACKER' => $aModule['db_prefix'] . 'jots_media_tracker',
  37. 'TABLE_MASS_TRACKER' => $aModule['db_prefix'] . 'mass_convo_tracker',
  38. 'TABLE_CMTS_OBJECTS' => 'sys_objects_cmts',
  39. 'TABLE_ENTRIES_FULLTEXT' => 'search_title',
  40. 'TABLE_ENTRIES_COMMENTS_FULLTEXT' => 'search_fields',
  41. // database fields
  42. // fields of system table sys_objects_cmts
  43. 'FIELD_COBJ_ID' => 'ID',
  44. 'FIELD_COBJ_MODULE' => 'Module',
  45. // live comments table fields
  46. 'FIELD_LCMTS_ID' => 'lcmt_id',
  47. 'FIELD_LCMTS_PARENT_ID' => 'lcmt_parent_id',
  48. 'FIELD_LCMTS_SYS_ID' => 'lcmt_system_id',
  49. 'FIELD_LCMTS_VPARENT_ID' => 'lcmt_vparent_id',
  50. 'FIELD_LCMTS_OBJECT_ID' => 'lcmt_object_id',
  51. 'FIELD_LCMTS_AUTHOR' => 'lcmt_author_id',
  52. 'FIELD_LCMTS_LEVEL' => 'lcmt_level',
  53. 'FIELD_LCMTS_TEXT' => 'lcmt_text',
  54. 'FIELD_LCMTS_DATE' => 'lcmt_time',
  55. 'FIELD_LCMTS_REPLIES' => 'lcmt_replies',
  56. // main lot table fields
  57. 'FIELD_ID' => 'id',
  58. 'FIELD_AUTHOR' => 'author',
  59. 'FIELD_ADDED' => 'created',
  60. 'FIELD_UPDATED' => 'updated',
  61. 'FIELD_PARTICIPANTS' => 'participants',
  62. 'FIELD_TITLE' => 'title',
  63. 'FIELD_URL' => 'url',
  64. 'FIELD_TYPE' => 'type',
  65. 'FIELD_CLASS' => 'class',
  66. 'FIELD_PARENT_JOT' => 'parent_jot',
  67. 'FIELD_VISIBILITY' => 'visibility',
  68. 'FIELD_HASH' => 'hash',
  69. // storage tale
  70. 'FIELD_ST_ID' => 'id',
  71. 'FIELD_ST_AUTHOR' => 'profile_id',
  72. 'FIELD_ST_REMOTE' => 'remote_id',
  73. 'FIELD_ST_NAME' => 'file_name',
  74. 'FIELD_ST_ADDED' => 'added',
  75. 'FIELD_ST_JOT' => 'jot_id',
  76. 'FIELD_ST_TYPE' => 'mime_type',
  77. 'FIELD_ST_EXT' => 'ext',
  78. // messages/jots table fields
  79. 'FIELD_MESSAGE_ID' => 'id',
  80. 'FIELD_MESSAGE' => 'message',
  81. 'FIELD_MESSAGE_FK' => 'lot_id',
  82. 'FIELD_MESSAGE_AUTHOR' => 'user_id',
  83. 'FIELD_MESSAGE_ADDED' => 'created',
  84. 'FIELD_MESSAGE_AT_TYPE' => 'attachment_type',
  85. 'FIELD_MESSAGE_AT' => 'attachment',
  86. 'FIELD_MESSAGE_LAST_EDIT' => 'last_edit',
  87. 'FIELD_MESSAGE_EDIT_BY' => 'edit_by',
  88. 'FIELD_MESSAGE_TRASH' => 'trash',
  89. 'FIELD_MESSAGE_VIDEOC' => 'vc',
  90. 'FIELD_MESSAGE_REPLY' => 'reply',
  91. // lots types table fields
  92. 'FIELD_TYPE_ID' => 'id',
  93. 'FIELD_TYPE_NAME' => 'name',
  94. 'FIELD_TYPE_LINKED' => 'show_link', // means use link in title
  95. // new messages table
  96. 'FIELD_NEW_ID' => 'id',
  97. 'FIELD_NEW_LOT' => 'lot_id',
  98. 'FIELD_NEW_JOT' => 'first_jot_id',
  99. 'FIELD_NEW_UNREAD' => 'unread_count',
  100. 'FIELD_NEW_PROFILE' => 'user_id',
  101. // users info fields
  102. 'FIELD_INFO_LOT_ID' => 'lot_id',
  103. 'FIELD_INFO_USER_ID' => 'user_id',
  104. 'FIELD_INFO_STAR' => 'star',
  105. 'FIELD_INFO_PARAMS' => 'params', // means use link in title
  106. // jots media tracker
  107. 'FJMT_FILE_ID' => 'file_id',
  108. 'FJMT_USER_ID' => 'user_id',
  109. 'FJMT_COLLAPSED' => 'collapsed',
  110. // talks mass talks tracker
  111. 'FIELD_MASS_CONVO_ID' => 'convo_id',
  112. 'FIELD_MASS_USER_ID' => 'user_id',
  113. 'FIELD_MASS_ADDED' => 'added',
  114. // jot reactions fields
  115. 'FIELD_REACT_JOT_ID' => 'jot_id',
  116. 'FIELD_REACT_NATIVE' => 'native',
  117. 'FIELD_REACT_EMOJI_ID' => 'emoji_id',
  118. 'FIELD_REACT_PROFILE_ID' => 'user_id',
  119. 'FIELD_REACT_ADDED' => 'added',
  120. // jitsi video conference fields
  121. 'FJVC_ID' => 'id',
  122. 'FJVC_LOT_ID' => 'lot_id',
  123. 'FJVC_ROOM' => 'room',
  124. 'FJVC_NUMBER' => 'number',
  125. 'FJVC_ACTIVE' => 'active',
  126. // jitsi video conference tracking fields
  127. 'FJVCT_ID' => 'id',
  128. 'FJVCT_FK' => 'jvc_id',
  129. 'FJVCT_AUTHOR_ID' => 'author_id',
  130. 'FJVCT_START' => 'start',
  131. 'FJVCT_END' => 'end',
  132. 'FJVCT_PART' => 'participants',
  133. 'FJVCT_JOINED' => 'joined',
  134. // jitsi public video conference fields
  135. 'FPJVC_ID' => 'id',
  136. 'FPJVC_ROOM' => 'room',
  137. 'FPJVC_PARTS' => 'participants',
  138. 'FPJVC_STATUS' => 'active',
  139. 'FPJVC_CREATED' => 'created',
  140. // messenger lot settings
  141. 'FLS_ID' => 'lot_id',
  142. 'FLS_ACTIONS' => 'actions',
  143. 'FLS_SETTINGS' => 'settings',
  144. 'FLS_ICON' => 'icon',
  145. // messenger lot settings
  146. 'FSJ_ID' => 'jot_id',
  147. 'FSJ_PROFILE_ID' => 'profile_id',
  148. // messenger lots attachments
  149. 'FLAT_NAME' => 'name',
  150. 'FLAT_SERVICE' => 'service',
  151. // messenger groups
  152. 'FMG_ID' => 'id',
  153. 'FMG_NAME' => 'name',
  154. 'FMG_AUTHOR' => 'author',
  155. 'FMG_ADDED' => 'added',
  156. 'FMG_PRIVACY' => 'allow_view_to',
  157. 'FMG_DESC' => 'desc',
  158. 'FMG_MODULE' => 'module',
  159. 'FMG_URL' => 'url',
  160. 'FMG_PROFILE_ID' => 'profile_id',
  161. // messenger lot settings
  162. 'FMGL_LOT_ID' => 'lot_id',
  163. 'FMGL_GROUP_ID' => 'group_id',
  164. // page URIs
  165. 'URL_HOME' => BX_DOL_URL_ROOT . 'page.php?i=messenger',
  166. 'URL_REPOST' => 'archive/',
  167. 'URL_INBOX' => 'inbox/',
  168. 'URL_TEMPLATE' => BX_DOL_URL_ROOT . 'page.php?{link}',
  169. // some params
  170. 'STAR_BACKGROUND_COLOR' => '#f5a623',
  171. 'FILES_UPLOADER' => 'messenger_uploader_',
  172. 'BELL_ICON_ON' => 'bell',
  173. 'STAR_ICON' => 'star',
  174. 'BELL_ICON_OFF' => 'bell-slash',
  175. 'PARAM_FRIENDS_NUM_BY_DEFAULT' => 10,
  176. 'PARAM_CONTACTS_NUM_BY_DEFAULT' => 5,
  177. 'PARAM_NTFS_INTERVAL' => 1, /* INTERVAL IN HOURS*/
  178. 'PARAM_MESSAGES_INTERVAL' => 1, /* INTERVAL IN MINUTE*/
  179. 'PARAM_SEARCH_DEFAULT_USERS' => (int)getParam($aModule['db_prefix'] . 'max_drop_down_select'),
  180. 'PARAM_MAX_HISTORY_MESSAGES' => 50,
  181. 'PARAM_DEFAULT_TALK_FILES_NUM' => 20,
  182. 'PARAM_MAX_JOT_NTFS_MESSAGE_LENGTH' => 50,
  183. 'PARAM_PUSH_NOTIFICATIONS_DEFAULT_SYMBOLS_NUM' => 190,
  184. 'JOT-PREVIEW-TEXT-LENGTH' => 500,
  185. 'PARAM_PRIVATE' => TRUE,
  186. 'PARAM_PUBLIC' => FALSE,
  187. 'PARAM_ICONS_NUMBER' => 3,
  188. 'PARAM_MODULE_TYPES' => array(
  189. 'bx_groups' => BX_IM_TYPE_GROUPS,
  190. 'bx_events' => BX_IM_TYPE_EVENTS,
  191. 'bx_spaces' => BX_IM_TYPE_GROUPS
  192. ),
  193. 'ADD-TO-PAGES-AREA' => array(
  194. BX_MSG_TALK_TYPE_PAGES => array('system', 'custom', '')
  195. ),
  196. 'JOT-MENU-TO-SHOW' => ['reaction', 'reply'],
  197. 'IMPLODE_GROUPS' => array(
  198. BX_ATT_GROUPS_ATTACH => array(
  199. BX_ATT_TYPE_FILES, BX_ATT_TYPE_FILES_UPLOADING, BX_ATT_TYPE_GIPHY, BX_ATT_TYPE_REPOST, BX_ATT_TYPE_CUSTOM
  200. ),
  201. ),
  202. 'URL_IDENT_PARAMS' => array('i','id','profile_id'),
  203. 'EMOJI_APPS' => ['+1' => 'like'],
  204. 'TITLE_CONSTANTS' => array('opponent'),
  205. 'GROUPS_ITEMS_FIELD' => 'items',
  206. // GIPHY
  207. 'GIPHY' => array(
  208. 'api_key' => getParam($aModule['db_prefix'] . 'giphy_key'),
  209. 'type' => getParam($aModule['db_prefix'] . 'giphy_type'),
  210. 'rating' => getParam($aModule['db_prefix'] . 'giphy_content_rating'),
  211. 'limit' => (int)getParam($aModule['db_prefix'] . 'giphy_limit'),
  212. 'gifs' => 'https://api.giphy.com/v1/gifs/',
  213. 'stickers' => 'https://api.giphy.com/v1/stickers/',
  214. 'search' => 'search',
  215. 'trending' => 'trending'
  216. ),
  217. // Jitsi
  218. 'JITSI' => array(
  219. 'LIB-LINK' => 'external_api.js'
  220. ),
  221. // objects
  222. 'OBJECT_STORAGE' => 'bx_messenger_files',
  223. 'OBJECT_API_FORM_NAME' => 'bx_messenger_send',
  224. 'OBJECT_PRIVACY_GROUPS' => 'bx_messenger_allow_view_groups_to',
  225. 'OBJECT_IMAGES_TRANSCODER_GALLERY' => 'bx_messenger_photos_resized',
  226. 'OBJECT_IMAGES_TRANSCODER_PREVIEW' => 'bx_messenger_preview',
  227. 'OBJECT_IMAGES_TRANSCODER_ICON' => 'bx_messenger_icon',
  228. 'OBJECT_MP3_TRANSCODER' => 'bx_messenger_mp3',
  229. 'OBJECT_VIDEOS_TRANSCODERS' => array(
  230. 'poster' => 'bx_messenger_videos_poster',
  231. 'mp4' => 'bx_messenger_videos_mp4',
  232. 'mp4_hd' => 'bx_messenger_videos_mp4_hd',
  233. 'webm' => 'bx_messenger_videos_webm',
  234. ),
  235. 'OBJECT_MENU_SNIPPET_META' => 'bx_messenger_profile_snippet_meta',
  236. 'OBJECT_VIEWS' => 'bx_messenger_lots',
  237. 'OBJECT_JOTS_RVOTES' => 'bx_messenger_jots_rvotes',
  238. 'OBJECT_FORM_ENTRY' => 'bx_messenger_lots',
  239. 'OBJECT_FORM_FILTER' => 'bx_messenger_filter_criteria',
  240. 'OBJECT_FORM_FILTER_DISPLAY' => 'bx_messenger_filter_criteria',
  241. 'OBJECT_FORM_ENTRY_DISPLAY_VIEW' => 'bx_messenger_lots',
  242. 'OBJECT_MENU_ACTIONS_VIEW_ENTRY' => 'bx_messenger_view', // actions menu on view entry page
  243. 'OBJECT_MENU_ACTIONS_MY_ENTRIES' => 'bx_messenger_my', // actions menu on my entries page
  244. 'OBJECT_MENU_ACTIONS_TALK_MENU' => 'bx_messenger_lot_menu',
  245. 'OBJECT_MENU_TALK_INFO_MENU' => 'bx_messenger_lot_info_menu',
  246. 'OBJECT_MENU_JOT_MENU' => 'bx_messenger_jot_menu',
  247. 'OBJECT_MENU_CREATE_CONVO_MENU' => 'bx_messenger_create_convo_menu',
  248. 'OBJECT_MENU_NAV_LEFT_MENU' => 'bx_messenger_nav_menu',
  249. 'OBJECT_MENU_GROUPS_MENU' => 'bx_messenger_groups_menu',
  250. 'OBJECT_MENU_SUBMENU' => '', // main module submenu
  251. 'OBJECT_MENU_MANAGE_TOOLS' => 'bx_messenger_menu_manage_tools', //manage menu in content administration tools
  252. 'OBJECT_GRID' => 'bx_messenger',
  253. 'OBJECT_UPLOADERS' => array('sys_html5'),
  254. // available lot options
  255. 'LOT_OPTIONS' => array(
  256. 'msg',
  257. 'giphy',
  258. 'files',
  259. 'video_rec',
  260. 'smiles'
  261. ),
  262. 'SEARCH-CRITERIA' => array('titles', 'participants', 'content'),
  263. 'VIEW-IN-TALKS' => array(BX_MSG_TALK_TYPE_MR, BX_MSG_TALK_TYPE_REPLIES, BX_MSG_TALK_TYPE_SAVED),
  264. //options
  265. 'DATE-SEPARATOR-FORMAT-Y' => 'MMM D, Y, H:mm',
  266. 'DATE-SEPARATOR-FORMAT' => 'MMM D, H:mm',
  267. 'DATE-SHIFT' => 300, // time period to show date separator
  268. 'MAX_SEND_SYMBOLS' => (int)getParam($aModule['db_prefix'] . 'max_symbols_number'),
  269. 'MAX_PREV_JOTS_SYMBOLS' => (int)getParam($aModule['db_prefix'] . 'max_symbols_brief_jot'),
  270. 'MAX_JOTS_BY_DEFAULT' => (int)getParam($aModule['db_prefix'] . 'max_jot_number_default'),
  271. 'MAX_JOTS_LOAD_HISTORY' => (int)getParam($aModule['db_prefix'] . 'max_jot_number_in_history'),
  272. 'MAX_LOTS_NUMBER' => (int)getParam($aModule['db_prefix'] . 'max_lots_number'),
  273. 'SERVER_URL' => getParam($aModule['db_prefix'] . 'server_url'),
  274. 'MAX_FILES_TO_UPLOAD' => (int)getParam($aModule['db_prefix'] . 'max_files_send'),
  275. 'MAX_VIDEO_LENGTH' => (int)getParam($aModule['db_prefix'] . 'max_video_length_minutes'),
  276. 'MAX_NTFS_NUMBER' => (int)getParam($aModule['db_prefix'] . 'max_ntfs_number'),
  277. 'MAX_VIEWS_PARTS_NUMBER' => (int)getParam($aModule['db_prefix'] . 'max_parts_views'),
  278. 'ALLOW_TO_REMOVE_MESSAGE' => getParam($aModule['db_prefix'] . 'allow_to_remove_messages') == 'on',
  279. 'ALLOW_TO_MODERATE_MESSAGE_FOR_AUTHORS' => getParam($aModule['db_prefix'] . 'allow_to_moderate_messages') == 'on',
  280. 'REMOVE_MESSAGE_IMMEDIATELY' => getParam($aModule['db_prefix'] . 'remove_messages_immediately') == 'on',
  281. 'USE_EMBEDLY' => getParam($aModule['db_prefix'] . 'use_embedly') == 'on',
  282. 'USE_MENTIONS' => getParam($aModule['db_prefix'] . 'enable_mentions') == 'on',
  283. 'EMOJI_SET' => getParam($aModule['db_prefix'] . 'emoji_set'),
  284. 'REACTIONS_SIZE' => (int)getParam($aModule['db_prefix'] . 'reactions_size'),
  285. 'EMOJI_PREVIEW' => getParam($aModule['db_prefix'] . 'show_emoji_preview') == 'on',
  286. 'ENABLE-JITSI' => getParam($aModule['db_prefix'] . 'jitsi_enable') == 'on',
  287. 'JITSI-SERVER' => getParam($aModule['db_prefix'] . 'jitsi_server'),
  288. 'JITSI-CHAT' => getParam($aModule['db_prefix'] . 'jitsi_chat') == 'on',
  289. 'JITSI-CHAT-SYNC' => getParam($aModule['db_prefix'] . 'jitsi_sync') == 'on',
  290. 'JITSI-HIDDEN-INFO' => getParam($aModule['db_prefix'] . 'jitsi_hide_info') == 'on',
  291. 'JITSI-ONLY-FOR-PRIVATE' => getParam($aModule['db_prefix'] . 'jitsi_only_for_private') == 'on',
  292. 'JITSI-ENABLE-WATERMARK' => getParam($aModule['db_prefix'] . 'jitsi_enable_watermark') == 'on',
  293. 'JITSI-WATERMARK-URL' => getParam($aModule['db_prefix'] . 'jitsi_watermark_link'),
  294. 'JITSI-SUPPORT-LINK' => getParam($aModule['db_prefix'] . 'jitsi_support_url'),
  295. 'DISABLE-PROFILE-PRIVACY' => getParam($aModule['db_prefix'] . 'disable_contact_privacy') == 'on',
  296. 'CONTACT-JOIN-ORGANIZATION' => getParam($aModule['db_prefix'] . 'enable_joined_organizations') == 'on',
  297. 'SHOW-FRIENDS' => getParam($aModule['db_prefix'] . 'show_friends') == 'on',
  298. 'CHECK-CONTENT-FOR-TOXIC' => getParam($aModule['db_prefix'] . 'check_toxic') == 'on',
  299. 'TIME-FROM-NOW' => getParam($aModule['db_prefix'] . 'time_in_history') == 'on',
  300. 'DONT-SHOW-DESC' => getParam($aModule['db_prefix'] . 'dont_show_search_desc') == 'on',
  301. 'USE-UNIQUE-MODE' => getParam($aModule['db_prefix'] . 'use_unique_mode') == 'on',
  302. 'USE-FRIENDS-ONLY-MODE' => getParam($aModule['db_prefix'] . 'connect_friends_only') == 'on',
  303. 'UPDATE-PAGE-TITLE' => getParam($aModule['db_prefix'] . 'dont_update_title') == 'on',
  304. 'HIDE-PARTS' => getParam($aModule['db_prefix'] . 'hide_parts') == 'on',
  305. 'SHOW-SEARCH-BOX' => getParam($aModule['db_prefix'] . 'show_search_box') == 'on',
  306. 'GIPHY-POWERED-BY' => getParam($aModule['db_prefix'] . 'giphy_powered_by') == 'on',
  307. 'SEARCH-CRITERIA-SELECTED' => getParam($aModule['db_prefix'] . 'search_criteria'),
  308. 'BROADCAST-FIELDS' => getParam($aModule['db_prefix'] . 'broadcast_fields'),
  309. 'BROADCAST-ALLOWED-FILTER-FIELDS' => ['gender', 'location', 'birthday', 'membership'],
  310. 'JWT' => [
  311. 'app_id' => getParam($aModule['db_prefix'] . 'jwt_app_id'),
  312. 'secret' => getParam($aModule['db_prefix'] . 'jwt_app_secret'),
  313. ],
  314. 'JOT-JWT' => trim(getParam($aModule['db_prefix'] . 'jot_server_jwt')),
  315. 'QUILL_TOOLBAR' => getParam($aModule['db_prefix'] . 'quill_toolbar'),
  316. 'JSMain' => 'oMessenger',
  317. 'JSCreateConvoMenu' => 'oMessengerCreateConvo',
  318. 'JSMessengerLib' => 'oMUtils',
  319. );
  320. $this->_aObjects = array(
  321. 'alert' => $this->_sName
  322. );
  323. }
  324. function getBroadcastAllowedFields(){
  325. $aFields = $this->CNF['BROADCAST-ALLOWED-FILTER-FIELDS'];
  326. bx_alert($this->_sName, 'broadcast_filtered_fields', 0, 0, [
  327. 'fields' => &$aFields
  328. ]);
  329. return !empty($aFields) && is_array($aFields) ? $aFields : [];
  330. }
  331. /**
  332. * Returns type of the talk
  333. *@param string $sModule module uri, if messenger block was added to a special page of any module
  334. *@return int type
  335. */
  336. public function getTalkType($sModule = ''){
  337. return $sModule && isset($this->CNF['PARAM_MODULE_TYPES'][$sModule]) ? $this->CNF['PARAM_MODULE_TYPES'][$sModule] : BX_IM_TYPE_PUBLIC;
  338. }
  339. /**
  340. * Checks if the posted link is repost link
  341. *@param string $sUrl internal post url
  342. *@return array, string url and int post id
  343. */
  344. public function isJotLink($sUrl){
  345. $aResult = [];
  346. $sJotPattern = '/^'. preg_replace(array('/\./', '/\//', '/\?/'), array('\.', '\/', '\?'), $this->getRepostUrl()) . '(\d+)/i';
  347. if (preg_match($sJotPattern, $sUrl, $aMatches) && intval($aMatches[1]))
  348. $aResult = array('url' => $aMatches[0], 'id' => $aMatches[1]);
  349. return $aResult;
  350. }
  351. public function getBaseUri()
  352. {
  353. $sLink = parent::getBaseUri();
  354. if(strncmp($sLink, BX_DOL_URL_ROOT, strlen(BX_DOL_URL_ROOT)) !== 0)
  355. $sLink = BX_DOL_URL_ROOT . $sLink;
  356. return $sLink;
  357. }
  358. public function getRepostUrl($iJotId = 0)
  359. {
  360. return $this->getBaseUri() . $this->CNF['URL_REPOST'] . ( $iJotId ? $iJotId : '');
  361. }
  362. public function getRepostUrlApi($sLotHash, $iJotId = 0)
  363. {
  364. $sUrl = $this->getUri() . '/' . $this->CNF['URL_INBOX'] . $sLotHash;
  365. if($iJotId)
  366. $sUrl = bx_append_url_params($sUrl, ['id' => $iJotId]);
  367. return $sUrl;
  368. }
  369. /**
  370. * Converts text link to url (wraps text url to <a>)
  371. *@param string $sText url
  372. *@param string $sAttrs special attributes for the link
  373. *@param boolean $bHtmlSpecialChars convert link to special html chars
  374. *@return string url
  375. */
  376. public function bx_linkify($sText, $sAttrs = '', $bHtmlSpecialChars = false){
  377. if ($bHtmlSpecialChars)
  378. $sText = htmlspecialchars($sText, ENT_NOQUOTES, 'UTF-8');
  379. $sRe = "@(((https?://)|(www\.))[^\"<\s]+)(?![^<>]*>|[^\"]*?<\/a)@";
  380. preg_match_all($sRe, $sText, $aMatches, PREG_OFFSET_CAPTURE);
  381. $aMatches = $aMatches[0];
  382. if ($i = count($aMatches))
  383. $bAddNofollow = getParam('sys_add_nofollow') == 'on';
  384. while ($i--)
  385. {
  386. $sUrl = $aMatches[$i][0];
  387. if (!preg_match('@^https?://@', $sUrl))
  388. $sUrl = 'http://'.$sUrl;
  389. if (strncmp(BX_DOL_URL_ROOT, $sUrl, strlen(BX_DOL_URL_ROOT)) !== 0) {
  390. $sAttrs .= ' target="_blank" ';
  391. if ($bAddNofollow)
  392. $sAttrs .= ' rel="nofollow" ';
  393. }
  394. if ($this -> isJotLink($sUrl))
  395. $sReplacement = "<a href=\"{$sUrl}\">{$aMatches[$i][0]}</a>";
  396. else
  397. {
  398. $oEmbed = BxDolEmbed::getObjectInstance();
  399. if($oEmbed && $this -> CNF['USE_EMBEDLY'])
  400. $sReplacement = $oEmbed->getLinkHTML($sUrl, $aMatches[$i][0]);
  401. else
  402. $sReplacement = "<a {$sAttrs} href=\"{$sUrl}\">{$aMatches[$i][0]}</a>";
  403. }
  404. $sText = substr_replace($sText, $sReplacement, $aMatches[$i][1], strlen($aMatches[$i][0]));
  405. }
  406. $mail_pattern = "/([\w.]+@[a-zA-Z_-]+?(?:\.[a-zA-Z]{2,6}))(?![^<>]*>|[^\"]*?<\/a)/";
  407. $sText = preg_replace($mail_pattern, '<a href="mailto:$1">$1</a>', $sText);
  408. return $sText;
  409. }
  410. /**
  411. * Remove repost links from the message
  412. *@param string $sMessage message
  413. *@param int iJotId jot Id
  414. *@return string message
  415. */
  416. public function cleanRepostLinks($sMessage, $iJotId)
  417. {
  418. $sArchiveUrl = $this->getRepostUrl($iJotId);
  419. return str_replace($sArchiveUrl, '', $sMessage);
  420. }
  421. /**
  422. * Builds from server environment valid Url handle for the talk
  423. *@return string url
  424. */
  425. public function getPageIdent($sPageLink = '')
  426. {
  427. $sPageUrl = $sPageLink ? $sPageLink : $_SERVER['REQUEST_URI'];
  428. if ($sPageUrl === '/' || $sPageUrl === '/index.php')
  429. return 'index.php';
  430. $sPath = parse_url(BX_DOL_URL_ROOT, PHP_URL_PATH);
  431. $sPageUrl = substr($sPageUrl, get_mb_len($sPath));
  432. // check if the link is jot link, then to return base url
  433. $sLinkToCheck = BX_DOL_URL_ROOT . $sPageUrl;
  434. if ($this->isJotLink($sLinkToCheck))
  435. $sPageUrl = BxDolPermalinks::getInstance()->permalink($this->CNF['URL_HOME']);
  436. $sPageUrl = BxDolPermalinks::getInstance()->unpermalink($sPageUrl);
  437. $sPageUrl = parse_url($sPageUrl, PHP_URL_QUERY);
  438. if (!empty($sPageUrl)) {
  439. parse_str($sPageUrl, $aUrl);
  440. if (!empty($aUrl)) {
  441. $aValidUrl = array();
  442. foreach ($this->CNF['URL_IDENT_PARAMS'] as &$sParam)
  443. if (!empty($aUrl[$sParam]))
  444. $aValidUrl[$sParam] = $aUrl[$sParam];
  445. if (!empty($aValidUrl))
  446. $sPageUrl = http_build_query($aValidUrl);
  447. }
  448. }
  449. return $sPageUrl;
  450. }
  451. function getPageName($sIdent){
  452. if (!$sIdent)
  453. return '';
  454. parse_str($sIdent, $aUrl);
  455. return !empty($aUrl) && isset($aUrl['i']) ? $aUrl['i'] : '';
  456. }
  457. function normalizeLink($sUrl){
  458. $aValidUrl = array();
  459. parse_str($sUrl, $aUrl);
  460. if (!empty($aUrl)) {
  461. foreach ($this->CNF['URL_IDENT_PARAMS'] as &$sParam)
  462. if (!empty($aUrl[$sParam]))
  463. $aValidUrl[$sParam] = $aUrl[$sParam];
  464. }
  465. return !empty($aValidUrl) ? http_build_query($aValidUrl) : $sUrl;
  466. }
  467. public function getPageLink($sUrl){
  468. if ($sUrl === 'index.php' || !$sUrl)
  469. return BX_DOL_URL_ROOT;
  470. if ($sUrl && $sUrl[0] === '/') {
  471. $sUrl = 'i=' . ltrim($sUrl, '/');
  472. }
  473. return BxDolPermalinks::getInstance()->permalink(str_replace('{link}', $sUrl, $this->CNF['URL_TEMPLATE']));
  474. }
  475. public function getGiphyGifs($sAction = 'trending', $sValue = '', $iStart = 0){
  476. $oGiphy = &$this->CNF['GIPHY'];
  477. $aParams = array(
  478. 'api_key' => $oGiphy['api_key'],
  479. 'offset' => $iStart,
  480. 'limit' => (int)$oGiphy['limit'],
  481. 'rating' => $oGiphy['rating']
  482. );
  483. $sUrl = $oGiphy[$oGiphy['type']];
  484. if ($sAction === 'search' && $sValue){
  485. $aParams['q'] = $sValue;
  486. $aParams['lang'] = bx_lang_name();
  487. $aParams['random_id'] = time();
  488. }
  489. $sAction = $sAction ? $sAction : 'trending';
  490. $sAction = isset($oGiphy[$sAction]) ? $oGiphy[$sAction] : $sAction;
  491. return bx_file_get_contents("{$sUrl}{$sAction}", $aParams);
  492. }
  493. public function getRoomId($mixedLotId = '', $mixedAuthor = ''){
  494. return 'UNA' . md5(BX_DOL_URL_ROOT . $mixedLotId . $mixedAuthor . BX_DOL_SECRET);
  495. }
  496. public function isJitsiAllowed($iType){
  497. if (!$this->CNF['ENABLE-JITSI'])
  498. return false;
  499. if ($this->CNF['JITSI-ONLY-FOR-PRIVATE'] && ($iType == BX_IM_TYPE_PUBLIC || $iType == BX_IM_TYPE_SETS))
  500. return false;
  501. return $this->isAllowedAction(BX_MSG_ACTION_CREATE_VC) === true;
  502. }
  503. public function getValidUrl($sUrl, $sType = 'domain'){
  504. if (!$sUrl || !($aUrl = parse_url($sUrl)))
  505. return '';
  506. $sDomain = isset($aUrl['host']) ? $aUrl['host'] : (isset($aUrl['path']) ? $aUrl['path'] : $sUrl);
  507. $sDomain = str_replace(["www."], [''], $sDomain);
  508. return $sType === 'domain' ? $sDomain : "https://{$sDomain}";
  509. }
  510. public function isAllowedAction($sAction = BX_MSG_ACTION_SEND_MESSAGE, $iProfileId = 0){
  511. if (!$iProfileId)
  512. $iProfileId = bx_get_logged_profile_id();
  513. $aProfileMembership = BxDolAcl::getInstance()->getMemberMembershipInfo($iProfileId);
  514. if (isset($aProfileMembership['status']) && $aProfileMembership['status'] !== 'active')
  515. return false;
  516. if ($sAction && ($sMembershipAction = str_replace('_', ' ', $sAction))){
  517. $aCheck = checkActionModule($iProfileId, $sMembershipAction, $this->getName(), true);
  518. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  519. return $aCheck[CHECK_ACTION_MESSAGE];
  520. }
  521. return true;
  522. }
  523. function generateJWTToken($iProfileId, $aUserParams = array(), $aTokenParams = array()){
  524. $oProfileInfo = BxDolProfile::getInstance( $iProfileId );
  525. if (!$iProfileId || (empty($aUserParams) && empty($aTokenParams)))
  526. return false;
  527. // Encode Header to Base64Url String
  528. $sHeader = json_encode(['alg' => 'HS256', 'typ' => 'JWT']);
  529. $sHeader = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($sHeader));
  530. // Create token payload as a JSON string
  531. $sPayload = json_encode( array_merge(array('context' => $aUserParams), $aTokenParams));
  532. $sPayload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($sPayload));
  533. // Create Signature Hash
  534. $sSignature = hash_hmac('sha256', $sHeader . "." . $sPayload, $this->CNF['JOT-JWT'], true);
  535. $sSignature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($sSignature));
  536. return "{$sHeader}.{$sPayload}.{$sSignature}";
  537. }
  538. function getPageIcon(){
  539. if ($sFileUrl = BxDolDesigns::getInstance()->getSiteLogoUrl())
  540. return $sFileUrl;
  541. if (!($iIdIcon = (int)getParam('sys_site_icon')))
  542. return BxDolTemplate::getInstance()->getIconUrl('apple-touch-icon.png');
  543. $oTranscoder = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_ICON_FAVICON);
  544. return $oTranscoder->getFileUrl($iIdIcon);
  545. }
  546. function getSeparatorTime($iUnixTimestamp){
  547. $sDateUTC = bx_time_utc($iUnixTimestamp);
  548. $sFormat = date('Y', $iUnixTimestamp) != date('Y') ? $this->CNF['DATE-SEPARATOR-FORMAT-Y'] : $this->CNF['DATE-SEPARATOR-FORMAT'];
  549. return '<time datetime="' . $sDateUTC . '" data-bx-autoformat="' . ( !$this->CNF['TIME-FROM-NOW'] ? 0 : getParam('sys_format_timeago')) . '" data-bx-format="' . $sFormat . '">' . $sDateUTC . '</time>';
  550. }
  551. public function isValidToUpload($sFileName){
  552. if (!$sFileName)
  553. return false;
  554. $sBaseName = basename($sFileName);
  555. if (strcmp($sBaseName, $sFileName) !== 0)
  556. return false;
  557. $sRequestPath = realpath(BX_DIRECTORY_PATH_TMP . $sFileName);
  558. $sValidRootPath = realpath(BX_DIRECTORY_PATH_TMP);
  559. return $sRequestPath !== false && strcmp(substr($sRequestPath, 0, strlen($sValidRootPath)), $sValidRootPath) === 0;
  560. }
  561. public function isSearchCriteria($sSelected){
  562. $aItems = $this->CNF['SEARCH-CRITERIA-SELECTED'] ? explode(',', $this->CNF['SEARCH-CRITERIA-SELECTED']) : array();
  563. if (empty($aItems))
  564. return false;
  565. return in_array($sSelected, $aItems);
  566. }
  567. public function replaceConstant($sTitle, $aMarkers){
  568. foreach($this->CNF['TITLE_CONSTANTS'] as &$sItem){
  569. if (isset($aMarkers[$sItem]))
  570. $sTitle = str_replace('{' . $sItem . '}', $aMarkers[$sItem], $sTitle);
  571. }
  572. return $sTitle;
  573. }
  574. public function generateHash($sId){
  575. return md5(BX_DOL_SECRET . $sId);
  576. }
  577. public function isAttachmentType(&$aJot, $sType = BX_ATT_TYPE_REPLY) {
  578. if (empty($aJot) || empty($aJot[$this->CNF['FIELD_MESSAGE_AT']]))
  579. return false;
  580. if ($aJot[$this->CNF['FIELD_MESSAGE_AT_TYPE']])
  581. return $aJot[$this->CNF['FIELD_MESSAGE_AT_TYPE']] === $sType;
  582. $mixedResult = @unserialize($aJot[$this->CNF['FIELD_MESSAGE_AT']]);
  583. return isset($mixedResult[$sType]);
  584. }
  585. public function convertEmoji2App($sName){
  586. return isset($this->CNF['EMOJI_APPS'][$sName]) ? $this->CNF['EMOJI_APPS'][$sName] : $sName;
  587. }
  588. public function convertApp2Emoji($sName){
  589. $sKey = array_search($sName, $this->CNF['EMOJI_APPS']);
  590. if ($sKey === false)
  591. return $sName;
  592. return $this->CNF['EMOJI_APPS'][$sKey];
  593. }
  594. public function getConnectionToFunctionCheck(){
  595. return true;
  596. }
  597. public function generateConvoHash($iId){
  598. $sHash = genRndPwd(10, false);
  599. if (!uriCheckUniq($sHash, $this->CNF['TABLE_ENTRIES'], $this->CNF['FIELD_HASH']))
  600. $sHash = md5($iId . BX_DOL_SECRET);
  601. return strtolower($sHash);
  602. }
  603. public function getConnectionByType($sType){
  604. if ($sType === 'followers')
  605. return BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  606. if ($sType === 'friends')
  607. return BxDolConnection::getObjectInstance('sys_profiles_friends');
  608. return false;
  609. }
  610. public function getSelectedNotificationMode($aNotifData){
  611. if (empty($aNotifData) || !($oModule = BxDolModule::getInstance('bx_notifications')))
  612. return false;
  613. $bEmail = in_array('email', $aNotifData);
  614. $bPush = in_array('push', $aNotifData);
  615. $bSite = in_array('site', $aNotifData);
  616. if ($bEmail && $bPush)
  617. return BX_BASE_MOD_NTFS_SLTMODE_DISABLED;
  618. if ($bEmail)
  619. return BX_NTFS_SLTMODE_SITE_EMAIL;
  620. if ($bPush)
  621. return BX_NTFS_SLTMODE_SITE_PUSH;
  622. if ($bSite)
  623. return BX_NTFS_SLTMODE_SITE;
  624. return BX_NTFS_SLTMODE_ABSOLUTE;
  625. }
  626. }
  627. /** @} */