BxBaseModGeneralModule.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. protected $_aSearchableNamesExcept;
  19. function __construct(&$aModule)
  20. {
  21. parent::__construct($aModule);
  22. $this->_iProfileId = bx_get_logged_profile_id();
  23. $this->_aSearchableNamesExcept = array(
  24. 'allow_view_to'
  25. );
  26. }
  27. // ====== ACTIONS METHODS
  28. public function actionRss ()
  29. {
  30. $aArgs = func_get_args();
  31. $this->_rss($aArgs);
  32. }
  33. // ====== SERVICE METHODS
  34. public function serviceGetAuthor ($iContentId)
  35. {
  36. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  37. return $mixedResult !== false ? (int)$mixedResult : 0;
  38. }
  39. public function serviceGetDateAdded ($iContentId)
  40. {
  41. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  42. return $mixedResult !== false ? (int)$mixedResult : 0;
  43. }
  44. public function serviceGetDateChanged ($iContentId)
  45. {
  46. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  47. return $mixedResult !== false ? (int)$mixedResult : 0;
  48. }
  49. public function serviceGetLink ($iContentId)
  50. {
  51. $CNF = &$this->_oConfig->CNF;
  52. if(empty($CNF['URI_VIEW_ENTRY']))
  53. return '';
  54. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  55. if(empty($aContentInfo))
  56. return '';
  57. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  58. }
  59. public function serviceGetTitle ($iContentId)
  60. {
  61. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  62. return $mixedResult !== false ? $mixedResult : '';
  63. }
  64. public function serviceGetText ($iContentId)
  65. {
  66. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  67. return $mixedResult !== false ? $mixedResult : '';
  68. }
  69. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  70. {
  71. $CNF = &$this->_oConfig->CNF;
  72. $aContentInfo = $this->_getFields($iContentId);
  73. if(empty($aContentInfo))
  74. return array();
  75. if(!$bSearchableFieldsOnly)
  76. return $aContentInfo;
  77. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  78. return array();
  79. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  80. if(empty($aFields))
  81. return array();
  82. $aResult = array();
  83. foreach($aFields as $sField)
  84. if(isset($aContentInfo[$sField]))
  85. $aResult[$sField] = $aContentInfo[$sField];
  86. return $aResult;
  87. }
  88. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  89. {
  90. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  91. if(empty($aContentInfo))
  92. return '';
  93. if(empty($sUnitTemplate))
  94. $sUnitTemplate = 'unit.html';
  95. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  96. }
  97. public function serviceGetAll ($aParams = array())
  98. {
  99. if(empty($aParams) || !is_array($aParams))
  100. $aParams = array('type' => 'all');
  101. return $this->_oDb->getEntriesBy($aParams);
  102. }
  103. public function serviceGetSearchableFieldsExtended()
  104. {
  105. $CNF = &$this->_oConfig->CNF;
  106. if(empty($CNF['OBJECT_FORM_ENTRY']) || empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  107. return array();
  108. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  109. if(!$oForm)
  110. return array();
  111. $aResult = array();
  112. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  113. $aResult[$CNF['FIELD_AUTHOR']] = array(
  114. 'type' => 'text_auto',
  115. 'caption' => $CNF['T']['form_field_author'],
  116. 'values' => '',
  117. 'pass' => ''
  118. );
  119. foreach ($oForm->aInputs as $aInput)
  120. if (in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept))
  121. $aResult[$aInput['name']] = array(
  122. 'type' => $aInput['type'],
  123. 'caption' => $aInput['caption_src'],
  124. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  125. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  126. );
  127. return $aResult;
  128. }
  129. public function serviceGetSearchResultExtended($aParams)
  130. {
  131. if(empty($aParams) || !is_array($aParams))
  132. return array();
  133. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams));
  134. }
  135. public function serviceModuleIcon ()
  136. {
  137. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  138. }
  139. public function serviceGetSearchableFields ()
  140. {
  141. $CNF = $this->_oConfig->CNF;
  142. if (!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  143. return array();
  144. $aTextTypes = array('text', 'textarea');
  145. $aTextFields = array();
  146. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  147. foreach ($oForm->aInputs as $r) {
  148. if (in_array($r['type'], $aTextTypes))
  149. $aTextFields[$r['name']] = $r['caption'];
  150. }
  151. return $aTextFields;
  152. }
  153. public function serviceManageTools($sType = 'common')
  154. {
  155. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  156. if(!$oGrid)
  157. return '';
  158. $CNF = &$this->_oConfig->CNF;
  159. $sMenu = '';
  160. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  161. $oPermalink = BxDolPermalinks::getInstance();
  162. $aMenuItems = array();
  163. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  164. $aMenuItems[] = array('id' => 'manage-common', 'name' => 'manage-common', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_COMMON']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_my']), 'active' => 1);
  165. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  166. $aMenuItems[] = array('id' => 'manage-administration', 'name' => 'manage-administration', 'class' => '', 'link' => $oPermalink->permalink($CNF['URL_MANAGE_ADMINISTRATION']), 'target' => '_self', 'title' => _t($CNF['T']['menu_item_manage_all']), 'active' => 1);
  167. if(count($aMenuItems) > 1) {
  168. $oMenu = new BxTemplMenu(array(
  169. 'template' => 'menu_vertical.html',
  170. 'menu_items' => $aMenuItems
  171. ), $this->_oTemplate);
  172. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  173. $sMenu = $oMenu->getCode();
  174. }
  175. }
  176. if(!empty($CNF['OBJECT_MENU_SUBMENU'])) {
  177. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  178. }
  179. $this->_oTemplate->addCss(array('manage_tools.css'));
  180. $this->_oTemplate->addJs(array('manage_tools.js'));
  181. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  182. return array(
  183. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  184. 'menu' => $sMenu
  185. );
  186. }
  187. public function serviceGetMenuAddonManageTools()
  188. {
  189. return 0;
  190. }
  191. public function serviceGetMenuAddonManageToolsProfileStats()
  192. {
  193. return 0;
  194. }
  195. /**
  196. * Display featured entries
  197. * @return HTML string
  198. */
  199. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = true, $bAjaxPaginate = true)
  200. {
  201. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  202. }
  203. /**
  204. * Display entries favored by a member
  205. * @return HTML string
  206. */
  207. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  208. {
  209. $oProfile = null;
  210. if((int)$iProfileId)
  211. $oProfile = BxDolProfile::getInstance($iProfileId);
  212. if(!$oProfile && bx_get('profile_id') !== false)
  213. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  214. if(!$oProfile)
  215. $oProfile = BxDolProfile::getInstance();
  216. if(!$oProfile)
  217. return '';
  218. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, true);
  219. }
  220. public function serviceFormsHelper ()
  221. {
  222. bx_import('FormsEntryHelper', $this->_aModule);
  223. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  224. return new $sClass($this);
  225. }
  226. /**
  227. * Add entry using provided fields' values.
  228. * @return HTML string
  229. */
  230. public function serviceEntityAdd ($iAccount, $aValues)
  231. {
  232. bx_import('FormsEntryHelper', $this->_aModule);
  233. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  234. $oFormsHelper = new $sClass($this);
  235. return $oFormsHelper->addData($iAccount, $aValues);
  236. }
  237. /**
  238. * Create entry form
  239. * @return HTML string
  240. */
  241. public function serviceEntityCreate ()
  242. {
  243. bx_import('FormsEntryHelper', $this->_aModule);
  244. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  245. $oFormsHelper = new $sClass($this);
  246. return $oFormsHelper->addDataForm();
  247. }
  248. public function serviceEntityEdit ($iContentId = 0)
  249. {
  250. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  251. }
  252. public function serviceEntityDelete ($iContentId = 0)
  253. {
  254. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  255. }
  256. public function serviceEntityTextBlock ($iContentId = 0)
  257. {
  258. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  259. }
  260. public function serviceEntityInfo ($iContentId = 0)
  261. {
  262. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  263. }
  264. public function serviceEntityInfoFull ($iContentId = 0)
  265. {
  266. $CNF = &$this->_oConfig->CNF;
  267. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  268. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  269. }
  270. public function serviceEntityInfoExtended ($iContentId = 0)
  271. {
  272. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  273. }
  274. /**
  275. * Entry location info
  276. */
  277. public function serviceEntityLocation ($iContentId = 0)
  278. {
  279. $iContentId = $this->_getContent($iContentId, false);
  280. if($iContentId === false)
  281. return false;
  282. return $this->_oTemplate->entryLocation ($iContentId);
  283. }
  284. /**
  285. * Entry comments
  286. */
  287. public function serviceEntityComments ($iContentId = 0)
  288. {
  289. $CNF = &$this->_oConfig->CNF;
  290. if(empty($CNF['OBJECT_COMMENTS']))
  291. return '';
  292. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  293. }
  294. /**
  295. * Entry attachments block
  296. */
  297. public function serviceEntityAttachments ($iContentId = 0)
  298. {
  299. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  300. }
  301. /**
  302. * Delete content entry
  303. * @param $iContentId content id
  304. * @return error message or empty string on success
  305. */
  306. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  307. {
  308. bx_import('FormsEntryHelper', $this->_aModule);
  309. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  310. $oFormsHelper = new $sClass($this);
  311. return $oFormsHelper->$sFuncDelete($iContentId);
  312. }
  313. /**
  314. * Entry actions and social sharing block
  315. */
  316. public function serviceEntityAllActions ($iContentId = 0)
  317. {
  318. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  319. }
  320. /**
  321. * Entry actions block
  322. */
  323. public function serviceEntityActions ($iContentId = 0)
  324. {
  325. $iContentId = $this->_getContent($iContentId, false);
  326. if($iContentId === false)
  327. return false;
  328. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  329. return $oMenu ? $oMenu->getCode() : false;
  330. }
  331. /**
  332. * Entry social sharing block
  333. */
  334. public function serviceEntitySocialSharing ($iContentId = 0)
  335. {
  336. $mixedContent = $this->_getContent($iContentId);
  337. if($mixedContent === false)
  338. return false;
  339. list($iContentId, $aContentInfo) = $mixedContent;
  340. $CNF = &$this->_oConfig->CNF;
  341. return $this->_entitySocialSharing ($iContentId, array(
  342. 'id_timeline' => $iContentId,
  343. 'id_thumb' => !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : '',
  344. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  345. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  346. 'object_transcoder' => false,
  347. 'object_view' => !empty($CNF['OBJECT_VIEWS']) ? $CNF['OBJECT_VIEWS'] : '',
  348. 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
  349. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  350. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  351. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  352. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  353. ));
  354. }
  355. /**
  356. * Data for Notifications module
  357. */
  358. public function serviceGetNotificationsData()
  359. {
  360. $sModule = $this->_aModule['name'];
  361. $sEventPrivacy = $sModule . '_allow_view_event_to';
  362. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  363. $sEventPrivacy = '';
  364. return array(
  365. 'handlers' => array(
  366. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  367. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  368. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  369. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  370. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  371. array('group' => $sModule . '_reply', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'replyPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_reply', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  372. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  373. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  374. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  375. ),
  376. 'alerts' => array(
  377. array('unit' => $sModule, 'action' => 'added'),
  378. array('unit' => $sModule, 'action' => 'edited'),
  379. array('unit' => $sModule, 'action' => 'deleted'),
  380. array('unit' => $sModule, 'action' => 'commentPost'),
  381. array('unit' => $sModule, 'action' => 'commentRemoved'),
  382. array('unit' => $sModule, 'action' => 'replyPost'),
  383. array('unit' => $sModule, 'action' => 'replyRemoved'),
  384. array('unit' => $sModule, 'action' => 'doVote'),
  385. array('unit' => $sModule, 'action' => 'undoVote'),
  386. )
  387. );
  388. }
  389. /**
  390. * Entry post for Notifications module
  391. */
  392. public function serviceGetNotificationsPost($aEvent)
  393. {
  394. $CNF = &$this->_oConfig->CNF;
  395. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  396. if(empty($aContentInfo) || !is_array($aContentInfo))
  397. return array();
  398. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  399. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  400. return array(
  401. 'entry_sample' => $CNF['T']['txt_sample_single'],
  402. 'entry_url' => $sEntryUrl,
  403. 'entry_caption' => $sEntryCaption,
  404. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  405. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  406. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  407. );
  408. }
  409. /**
  410. * Entry post comment for Notifications module
  411. */
  412. public function serviceGetNotificationsComment($aEvent)
  413. {
  414. $CNF = &$this->_oConfig->CNF;
  415. $iContentId = (int)$aEvent['object_id'];
  416. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  417. if(empty($aContentInfo) || !is_array($aContentInfo))
  418. return array();
  419. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  420. if(!$oComment || !$oComment->isEnabled())
  421. return array();
  422. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  423. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  424. return array(
  425. 'entry_sample' => $CNF['T']['txt_sample_single'],
  426. 'entry_url' => $sEntryUrl,
  427. 'entry_caption' => $sEntryCaption,
  428. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  429. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  430. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  431. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  432. );
  433. }
  434. /**
  435. * Entry post reply for Notifications module
  436. */
  437. public function serviceGetNotificationsReply($aEvent)
  438. {
  439. $CNF = &$this->_oConfig->CNF;
  440. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  441. if(!$oComment || !$oComment->isEnabled())
  442. return array();
  443. $iParentId = (int)$aEvent['object_id'];
  444. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  445. if(empty($aParentInfo) || !is_array($aParentInfo))
  446. return array();
  447. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  448. $oComment->init($iObjectId);
  449. return array(
  450. 'object_id' => $iObjectId,
  451. 'entry_sample' => '_cmt_txt_sample_comment_single',
  452. 'entry_url' => $oComment->getViewUrl($iParentId),
  453. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  454. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  455. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  456. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  457. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  458. );
  459. }
  460. /**
  461. * Entry post vote for Notifications module
  462. */
  463. public function serviceGetNotificationsVote($aEvent)
  464. {
  465. $CNF = &$this->_oConfig->CNF;
  466. $iContentId = (int)$aEvent['object_id'];
  467. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  468. if(empty($aContentInfo) || !is_array($aContentInfo))
  469. return array();
  470. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  471. if(!$oVote || !$oVote->isEnabled())
  472. return array();
  473. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  474. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  475. return array(
  476. 'entry_sample' => $CNF['T']['txt_sample_single'],
  477. 'entry_url' => $sEntryUrl,
  478. 'entry_caption' => $sEntryCaption,
  479. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  480. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  481. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  482. );
  483. }
  484. /**
  485. * Data for Timeline module
  486. */
  487. public function serviceGetTimelineData()
  488. {
  489. $sModule = $this->_aModule['name'];
  490. return array(
  491. 'handlers' => array(
  492. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  493. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  494. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  495. ),
  496. 'alerts' => array(
  497. array('unit' => $sModule, 'action' => 'added'),
  498. array('unit' => $sModule, 'action' => 'edited'),
  499. array('unit' => $sModule, 'action' => 'deleted'),
  500. )
  501. );
  502. }
  503. /**
  504. * Entry post for Timeline module
  505. */
  506. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  507. {
  508. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  509. if(empty($aContentInfo) || !is_array($aContentInfo))
  510. return '';
  511. $CNF = &$this->_oConfig->CNF;
  512. //--- Views
  513. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  514. $aViews = array();
  515. if ($oViews && $oViews->isEnabled())
  516. $aViews = array(
  517. 'system' => $CNF['OBJECT_VIEWS'],
  518. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  519. 'count' => $aContentInfo['views']
  520. );
  521. //--- Votes
  522. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  523. $aVotes = array();
  524. if ($oVotes && $oVotes->isEnabled())
  525. $aVotes = array(
  526. 'system' => $CNF['OBJECT_VOTES'],
  527. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  528. 'count' => $aContentInfo['votes']
  529. );
  530. //--- Reports
  531. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  532. $aReports = array();
  533. if ($oReports && $oReports->isEnabled())
  534. $aReports = array(
  535. 'system' => $CNF['OBJECT_REPORTS'],
  536. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  537. 'count' => $aContentInfo['reports']
  538. );
  539. //--- Comments
  540. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  541. $aComments = array();
  542. if($oCmts && $oCmts->isEnabled())
  543. $aComments = array(
  544. 'system' => $CNF['OBJECT_COMMENTS'],
  545. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  546. 'count' => $aContentInfo['comments']
  547. );
  548. //--- Title & Description
  549. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  550. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  551. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  552. return array(
  553. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  554. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  555. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  556. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  557. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  558. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  559. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  560. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  561. 'views' => $aViews,
  562. 'votes' => $aVotes,
  563. 'reports' => $aReports,
  564. 'comments' => $aComments,
  565. 'title' => $sTitle, //may be empty.
  566. 'description' => '' //may be empty.
  567. );
  568. }
  569. /**
  570. * Check particular action permission without content
  571. * @param $sAction action to check, for example: Browse, Add
  572. * @param $iContentId content ID
  573. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  574. */
  575. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  576. {
  577. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  578. if (!method_exists($this, $sMethod))
  579. return _t('_sys_request_method_not_found_cpt');
  580. return $this->$sMethod($isPerformAction);
  581. }
  582. /**
  583. * Check particular action permission with content
  584. * @param $sAction action to check, for example: View, Edit
  585. * @param $iContentId content ID
  586. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  587. */
  588. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  589. {
  590. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  591. return _t('_sys_request_page_not_found_cpt');
  592. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  593. if (!method_exists($this, $sMethod))
  594. return _t('_sys_request_method_not_found_cpt');
  595. return $this->$sMethod($aContentInfo, $isPerformAction);
  596. }
  597. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  598. {
  599. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  600. }
  601. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  602. {
  603. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  604. }
  605. // ====== PERMISSION METHODS
  606. public function checkAllowedSetThumb ()
  607. {
  608. return CHECK_ACTION_RESULT_ALLOWED;
  609. }
  610. /**
  611. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  612. */
  613. public function checkAllowedBrowse ()
  614. {
  615. return CHECK_ACTION_RESULT_ALLOWED;
  616. }
  617. /**
  618. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  619. */
  620. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  621. {
  622. $CNF = &$this->_oConfig->CNF;
  623. // moderator and owner always have access
  624. if (!empty($this->_iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$this->_iProfileId || $this->_isModerator($isPerformAction)))
  625. return CHECK_ACTION_RESULT_ALLOWED;
  626. // check ACL
  627. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  628. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  629. return $aCheck[CHECK_ACTION_MESSAGE];
  630. // check privacy
  631. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  632. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  633. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  634. return _t('_sys_access_denied_to_private_content');
  635. }
  636. return CHECK_ACTION_RESULT_ALLOWED;
  637. }
  638. /**
  639. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  640. */
  641. public function checkAllowedAdd ($isPerformAction = false)
  642. {
  643. // check ACL
  644. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  645. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  646. return $aCheck[CHECK_ACTION_MESSAGE];
  647. return CHECK_ACTION_RESULT_ALLOWED;
  648. }
  649. /**
  650. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  651. */
  652. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  653. {
  654. // moderator and owner always have access
  655. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  656. return CHECK_ACTION_RESULT_ALLOWED;
  657. return _t('_sys_txt_access_denied');
  658. }
  659. /**
  660. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  661. */
  662. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  663. {
  664. // moderator always has access
  665. if ($this->_isModerator($isPerformAction))
  666. return CHECK_ACTION_RESULT_ALLOWED;
  667. // check ACL
  668. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  669. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  670. return CHECK_ACTION_RESULT_ALLOWED;
  671. return _t('_sys_txt_access_denied');
  672. }
  673. /**
  674. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  675. */
  676. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  677. {
  678. // admin always has access
  679. if (isAdmin())
  680. return CHECK_ACTION_RESULT_ALLOWED;
  681. // check ACL
  682. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  683. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  684. return $aCheck[CHECK_ACTION_MESSAGE];
  685. return CHECK_ACTION_RESULT_ALLOWED;
  686. }
  687. /**
  688. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  689. */
  690. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  691. {
  692. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  693. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  694. return CHECK_ACTION_RESULT_ALLOWED;
  695. return _t('_sys_txt_access_denied');
  696. }
  697. /**
  698. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  699. */
  700. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  701. {
  702. return CHECK_ACTION_RESULT_ALLOWED;
  703. }
  704. /**
  705. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  706. */
  707. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  708. {
  709. return CHECK_ACTION_RESULT_ALLOWED;
  710. }
  711. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  712. {
  713. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  714. return MsgBox($sMsg);
  715. bx_import($sClassSearchResult, $this->_aModule);
  716. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  717. $o = new $sClass($sMode, $aParams);
  718. $o->setDesignBoxTemplateId($iDesignBox);
  719. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  720. $o->setAjaxPaginate($bAjaxPaginate);
  721. $o->setUnitParams(array('context' => $sMode));
  722. if ($o->isError)
  723. return '';
  724. if ($s = $o->processing())
  725. return $s;
  726. else
  727. return '';
  728. }
  729. // ====== COMMON METHODS
  730. public function getProfileId()
  731. {
  732. return bx_get_logged_profile_id();
  733. }
  734. public function getProfileInfo($iUserId = 0)
  735. {
  736. $oProfile = $this->getObjectUser($iUserId);
  737. $oAccount = null;
  738. if($oProfile && !($oProfile instanceof BxDolProfileUndefined))
  739. $oAccount = $oProfile->getAccountObject();
  740. $bAccount = !empty($oAccount);
  741. return array(
  742. 'id' => $oProfile->id(),
  743. 'name' => $oProfile->getDisplayName(),
  744. 'email' => $bAccount ? $oAccount->getEmail() : '',
  745. 'link' => $oProfile->getUrl(),
  746. 'icon' => $oProfile->getIcon(),
  747. 'thumb' => $oProfile->getThumb(),
  748. 'avatar' => $oProfile->getAvatar(),
  749. 'unit' => $oProfile->getUnit(),
  750. 'active' => $oProfile->isActive(),
  751. );
  752. }
  753. public function getObjectUser($iUserId = 0)
  754. {
  755. bx_import('BxDolProfile');
  756. $oProfile = BxDolProfile::getInstance($iUserId);
  757. if (!$oProfile) {
  758. bx_import('BxDolProfileUndefined');
  759. $oProfile = BxDolProfileUndefined::getInstance();
  760. }
  761. return $oProfile;
  762. }
  763. public function getObjectFavorite($sSystem = '', $iId = 0)
  764. {
  765. $CNF = &$this->_oConfig->CNF;
  766. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  767. $sSystem = $CNF['OBJECT_FAVORITES'];
  768. if(empty($sSystem))
  769. return false;
  770. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  771. if(!$oFavorite->isEnabled())
  772. return false;
  773. return $oFavorite;
  774. }
  775. public function getUserId()
  776. {
  777. return isLogged() ? bx_get_logged_profile_id() : 0;
  778. }
  779. public function getUserIp()
  780. {
  781. return getVisitorIP();
  782. }
  783. public function getUserInfo($iUserId = 0)
  784. {
  785. $oProfile = BxDolProfile::getInstance($iUserId);
  786. if (!$oProfile)
  787. $oProfile = BxDolProfileUndefined::getInstance();
  788. return array(
  789. $oProfile->getDisplayName(),
  790. $oProfile->getUrl(),
  791. $oProfile->getThumb(),
  792. $oProfile->getUnit(),
  793. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  794. );
  795. }
  796. public function _isModerator ($isPerformAction = false)
  797. {
  798. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  799. }
  800. // ====== PROTECTED METHODS
  801. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false)
  802. {
  803. $iContentId = $this->_getContent($iContentId, false);
  804. if($iContentId === false)
  805. return false;
  806. bx_import('FormsEntryHelper', $this->_aModule);
  807. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  808. $oFormsHelper = new $sClass($this);
  809. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction);
  810. }
  811. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  812. {
  813. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  814. if($mixedContent === false)
  815. return false;
  816. list($iContentId, $aContentInfo) = $mixedContent;
  817. return $this->_oTemplate->$sFunc($aContentInfo);
  818. }
  819. protected function _rss ($aArgs, $sClass = 'SearchResult')
  820. {
  821. $sMode = array_shift($aArgs);
  822. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  823. $this->_oTemplate->displayAccessDenied ($sMsg);
  824. exit;
  825. }
  826. $aParams = $this->_buildRssParams($sMode, $aArgs);
  827. bx_import ($sClass, $this->_aModule);
  828. $sClass = $this->_aModule['class_prefix'] . $sClass;
  829. $o = new $sClass($sMode, $aParams);
  830. if ($o->isError)
  831. $this->_oTemplate->displayPageNotFound ();
  832. else
  833. $o->outputRSS();
  834. exit;
  835. }
  836. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  837. {
  838. if(!$iContentId)
  839. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  840. if(!$iContentId)
  841. return false;
  842. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  843. return $iContentId;
  844. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  845. if(!$aContentInfo)
  846. return false;
  847. return array($iContentId, $aContentInfo);
  848. }
  849. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  850. {
  851. $CNF = &$this->_oConfig->CNF;
  852. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  853. //--- Image(s)
  854. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  855. return array(
  856. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  857. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  858. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  859. 'url' => $sUrl,
  860. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  861. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  862. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  863. 'images' => $aImages,
  864. );
  865. }
  866. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  867. {
  868. $CNF = &$this->_oConfig->CNF;
  869. $sImage = '';
  870. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']])
  871. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  872. if($sImage == '' && isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']])
  873. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  874. if(empty($sImage))
  875. return array();
  876. return array(
  877. array('url' => $sUrl, 'src' => $sImage),
  878. );
  879. }
  880. protected function _entityComments ($sObject, $iId = 0)
  881. {
  882. if (!$iId)
  883. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  884. if (!$iId)
  885. return false;
  886. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  887. if (!$oCmts || !$oCmts->isEnabled())
  888. return false;
  889. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  890. }
  891. protected function _entitySocialSharing ($iId, $aParams = array())
  892. {
  893. $bShowAsButton = !isset($aParams['show_as_button']) || $aParams['show_as_button'] === true;
  894. $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
  895. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  896. //--- Comments
  897. $sComments = '';
  898. $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
  899. if ($oComments) {
  900. $iNum = $oComments->getCommentsCountAll();
  901. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  902. 'class' => 'bx-base-general-comments-' . ($bShowAsButton ? 'button' : 'link'),
  903. 'class_do' => $bShowAsButton ? ' bx-btn' : '',
  904. 'class_counter' => $bShowAsButton ? ' bx-btn-height' : '',
  905. 'url' => $sUrl . $oComments->getListAnchor(true),
  906. 'bx_if:comments' => array (
  907. 'condition' => $iNum,
  908. 'content' => array (
  909. 'num' => $iNum,
  910. ),
  911. ),
  912. ));
  913. }
  914. $aCustomParams = array();
  915. $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  916. $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
  917. if ($iIdThumb && $bSocialSharing) {
  918. if(!empty($aParams['object_transcoder']))
  919. $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
  920. else if(!empty($aParams['object_storage']))
  921. $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
  922. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  923. if($sImgUrl)
  924. $aCustomParams = array (
  925. 'img_url' => $sImgUrl,
  926. 'img_url_encoded' => rawurlencode($sImgUrl),
  927. );
  928. }
  929. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  930. //--- Views
  931. $sViews = '';
  932. $oViews = !empty($aParams['object_view']) ? BxDolView::getObjectInstance($aParams['object_view'], $iId) : false;
  933. if ($oViews)
  934. $sViews = $oViews->getElementBlock(array('show_do_view_as_button' => $bShowAsButton));
  935. //--- Votes
  936. $sVotes = '';
  937. $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
  938. if ($oVotes)
  939. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
  940. //--- Favorite
  941. $sFavorites = '';
  942. $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
  943. if ($oFavorites)
  944. $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => $bShowAsButton));
  945. //--- Featured
  946. $sFeatured = '';
  947. $oFeatured = !empty($aParams['object_feature']) ? BxDolFeature::getObjectInstance($aParams['object_feature'], $iId) : false;
  948. if ($oFeatured)
  949. $sFeatured = $oFeatured->getElementBlock(array('show_do_feature_as_button' => $bShowAsButton));
  950. //--- Timeline Repost
  951. $sRepost = '';
  952. $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
  953. if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  954. $sRepost = BxDolService::call('bx_timeline', 'get_repost_element_block', array(bx_get_logged_profile_id(), $this->_aModule['name'], 'added', $iIdTimeline, array('show_do_repost_as_button' => $bShowAsButton)));
  955. //--- Report
  956. $sReport = '';
  957. $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
  958. if ($oReport)
  959. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => $bShowAsButton));
  960. $sSocial = '';
  961. if($bSocialSharing) {
  962. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  963. $oSocial->addMarkers(array_merge(array(
  964. 'id' => $iId,
  965. 'module' => $this->_aModule['name'],
  966. 'url' => BX_DOL_URL_ROOT . $sUrl,
  967. 'title' => $sTitle,
  968. ), $aCustomParams));
  969. $sSocial = $oSocial->getCode();
  970. }
  971. if(empty($sComments) && empty($sViews) && empty($sVotes) && empty($sFavorites) && empty($sFeatured) && empty($sRepost) && empty($sReport) && empty($sSocial))
  972. return '';
  973. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  974. 'comments' => $sComments,
  975. 'view' => $sViews,
  976. 'vote' => $sVotes,
  977. 'favorite' => $sFavorites,
  978. 'feature' => $sFeatured,
  979. 'repost' => $sRepost,
  980. 'report' => $sReport,
  981. 'social' => $sSocial,
  982. ));
  983. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
  984. }
  985. protected function _getFields($iContentId)
  986. {
  987. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  988. if(empty($aContentInfo))
  989. return array();
  990. return BxDolContentInfo::formatFields($aContentInfo);
  991. }
  992. protected function _getFieldValue($sField, $iContentId)
  993. {
  994. $CNF = &$this->_oConfig->CNF;
  995. if(empty($CNF[$sField]))
  996. return false;
  997. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  998. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  999. return false;
  1000. return $aContentInfo[$CNF[$sField]];
  1001. }
  1002. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1003. {
  1004. $CNF = &$this->_oConfig->CNF;
  1005. if(empty($sTranscoder) || empty($CNF[$sField]))
  1006. return false;
  1007. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1008. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1009. return false;
  1010. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1011. if(!$oImagesTranscoder)
  1012. return false;
  1013. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1014. }
  1015. }
  1016. /** @} */