BxBaseModGeneralModule.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 = false, $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. $bEmptyMessage = false;
  219. if(isset($aParams['empty_message'])) {
  220. $bEmptyMessage = (bool)$aParams['empty_message'];
  221. unset($aParams['empty_message']);
  222. }
  223. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  224. }
  225. public function serviceFormsHelper ()
  226. {
  227. bx_import('FormsEntryHelper', $this->_aModule);
  228. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  229. return new $sClass($this);
  230. }
  231. /**
  232. * Add entry using provided fields' values.
  233. * @return HTML string
  234. */
  235. public function serviceEntityAdd ($iAccount, $aValues)
  236. {
  237. bx_import('FormsEntryHelper', $this->_aModule);
  238. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  239. $oFormsHelper = new $sClass($this);
  240. return $oFormsHelper->addData($iAccount, $aValues);
  241. }
  242. /**
  243. * Create entry form
  244. * @return HTML string
  245. */
  246. public function serviceEntityCreate ()
  247. {
  248. bx_import('FormsEntryHelper', $this->_aModule);
  249. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  250. $oFormsHelper = new $sClass($this);
  251. return $oFormsHelper->addDataForm();
  252. }
  253. public function serviceEntityEdit ($iContentId = 0)
  254. {
  255. return $this->_serviceEntityForm ('editDataForm', $iContentId);
  256. }
  257. public function serviceEntityDelete ($iContentId = 0)
  258. {
  259. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  260. }
  261. public function serviceEntityTextBlock ($iContentId = 0)
  262. {
  263. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  264. }
  265. public function serviceEntityInfo ($iContentId = 0)
  266. {
  267. return $this->_serviceEntityForm ('viewDataForm', $iContentId);
  268. }
  269. public function serviceEntityInfoFull ($iContentId = 0)
  270. {
  271. $CNF = &$this->_oConfig->CNF;
  272. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  273. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  274. }
  275. public function serviceEntityInfoExtended ($iContentId = 0)
  276. {
  277. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  278. }
  279. /**
  280. * Entry location info
  281. */
  282. public function serviceEntityLocation ($iContentId = 0)
  283. {
  284. $iContentId = $this->_getContent($iContentId, false);
  285. if($iContentId === false)
  286. return false;
  287. return $this->_oTemplate->entryLocation ($iContentId);
  288. }
  289. /**
  290. * Entry comments
  291. */
  292. public function serviceEntityComments ($iContentId = 0)
  293. {
  294. $CNF = &$this->_oConfig->CNF;
  295. if(empty($CNF['OBJECT_COMMENTS']))
  296. return '';
  297. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  298. }
  299. /**
  300. * Entry attachments block
  301. */
  302. public function serviceEntityAttachments ($iContentId = 0)
  303. {
  304. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  305. }
  306. /**
  307. * Delete content entry
  308. * @param $iContentId content id
  309. * @return error message or empty string on success
  310. */
  311. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  312. {
  313. bx_import('FormsEntryHelper', $this->_aModule);
  314. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  315. $oFormsHelper = new $sClass($this);
  316. return $oFormsHelper->$sFuncDelete($iContentId);
  317. }
  318. /**
  319. * Entry actions and social sharing block
  320. */
  321. public function serviceEntityAllActions ($iContentId = 0)
  322. {
  323. return $this->_oTemplate->entryAllActions('', $this->serviceEntitySocialSharing($iContentId));
  324. }
  325. /**
  326. * Entry actions block
  327. */
  328. public function serviceEntityActions ($iContentId = 0)
  329. {
  330. $iContentId = $this->_getContent($iContentId, false);
  331. if($iContentId === false)
  332. return false;
  333. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  334. return $oMenu ? $oMenu->getCode() : false;
  335. }
  336. /**
  337. * Entry social sharing block
  338. */
  339. public function serviceEntitySocialSharing ($iContentId = 0)
  340. {
  341. $mixedContent = $this->_getContent($iContentId);
  342. if($mixedContent === false)
  343. return false;
  344. list($iContentId, $aContentInfo) = $mixedContent;
  345. $CNF = &$this->_oConfig->CNF;
  346. return $this->_entitySocialSharing ($iContentId, array(
  347. 'id_timeline' => $iContentId,
  348. 'id_thumb' => !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : '',
  349. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  350. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  351. 'object_transcoder' => false,
  352. 'object_view' => !empty($CNF['OBJECT_VIEWS']) ? $CNF['OBJECT_VIEWS'] : '',
  353. 'object_vote' => !empty($CNF['OBJECT_VOTES']) ? $CNF['OBJECT_VOTES'] : '',
  354. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  355. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  356. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  357. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  358. ));
  359. }
  360. /**
  361. * Data for Notifications module
  362. */
  363. public function serviceGetNotificationsData()
  364. {
  365. $sModule = $this->_aModule['name'];
  366. $sEventPrivacy = $sModule . '_allow_view_event_to';
  367. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  368. $sEventPrivacy = '';
  369. return array(
  370. 'handlers' => array(
  371. 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),
  372. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  373. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  374. 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),
  375. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  376. 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),
  377. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  378. 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),
  379. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  380. ),
  381. 'alerts' => array(
  382. array('unit' => $sModule, 'action' => 'added'),
  383. array('unit' => $sModule, 'action' => 'edited'),
  384. array('unit' => $sModule, 'action' => 'deleted'),
  385. array('unit' => $sModule, 'action' => 'commentPost'),
  386. array('unit' => $sModule, 'action' => 'commentRemoved'),
  387. array('unit' => $sModule, 'action' => 'replyPost'),
  388. array('unit' => $sModule, 'action' => 'replyRemoved'),
  389. array('unit' => $sModule, 'action' => 'doVote'),
  390. array('unit' => $sModule, 'action' => 'undoVote'),
  391. )
  392. );
  393. }
  394. /**
  395. * Entry post for Notifications module
  396. */
  397. public function serviceGetNotificationsPost($aEvent)
  398. {
  399. $CNF = &$this->_oConfig->CNF;
  400. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  401. if(empty($aContentInfo) || !is_array($aContentInfo))
  402. return array();
  403. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  404. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  405. return array(
  406. 'entry_sample' => $CNF['T']['txt_sample_single'],
  407. 'entry_url' => $sEntryUrl,
  408. 'entry_caption' => $sEntryCaption,
  409. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  410. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  411. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  412. );
  413. }
  414. /**
  415. * Entry post comment for Notifications module
  416. */
  417. public function serviceGetNotificationsComment($aEvent)
  418. {
  419. $CNF = &$this->_oConfig->CNF;
  420. $iContentId = (int)$aEvent['object_id'];
  421. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  422. if(empty($aContentInfo) || !is_array($aContentInfo))
  423. return array();
  424. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  425. if(!$oComment || !$oComment->isEnabled())
  426. return array();
  427. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  428. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  429. return array(
  430. 'entry_sample' => $CNF['T']['txt_sample_single'],
  431. 'entry_url' => $sEntryUrl,
  432. 'entry_caption' => $sEntryCaption,
  433. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  434. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  435. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  436. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  437. );
  438. }
  439. /**
  440. * Entry post reply for Notifications module
  441. */
  442. public function serviceGetNotificationsReply($aEvent)
  443. {
  444. $CNF = &$this->_oConfig->CNF;
  445. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  446. if(!$oComment || !$oComment->isEnabled())
  447. return array();
  448. $iParentId = (int)$aEvent['object_id'];
  449. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  450. if(empty($aParentInfo) || !is_array($aParentInfo))
  451. return array();
  452. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  453. $oComment->init($iObjectId);
  454. return array(
  455. 'object_id' => $iObjectId,
  456. 'entry_sample' => '_cmt_txt_sample_comment_single',
  457. 'entry_url' => $oComment->getViewUrl($iParentId),
  458. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  459. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  460. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  461. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  462. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  463. );
  464. }
  465. /**
  466. * Entry post vote for Notifications module
  467. */
  468. public function serviceGetNotificationsVote($aEvent)
  469. {
  470. $CNF = &$this->_oConfig->CNF;
  471. $iContentId = (int)$aEvent['object_id'];
  472. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  473. if(empty($aContentInfo) || !is_array($aContentInfo))
  474. return array();
  475. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  476. if(!$oVote || !$oVote->isEnabled())
  477. return array();
  478. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  479. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  480. return array(
  481. 'entry_sample' => $CNF['T']['txt_sample_single'],
  482. 'entry_url' => $sEntryUrl,
  483. 'entry_caption' => $sEntryCaption,
  484. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  485. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  486. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  487. );
  488. }
  489. /**
  490. * Data for Timeline module
  491. */
  492. public function serviceGetTimelineData()
  493. {
  494. $sModule = $this->_aModule['name'];
  495. return array(
  496. 'handlers' => array(
  497. 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' => ''),
  498. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  499. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  500. ),
  501. 'alerts' => array(
  502. array('unit' => $sModule, 'action' => 'added'),
  503. array('unit' => $sModule, 'action' => 'edited'),
  504. array('unit' => $sModule, 'action' => 'deleted'),
  505. )
  506. );
  507. }
  508. /**
  509. * Entry post for Timeline module
  510. */
  511. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  512. {
  513. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  514. if(empty($aContentInfo) || !is_array($aContentInfo))
  515. return '';
  516. $CNF = &$this->_oConfig->CNF;
  517. //--- Views
  518. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  519. $aViews = array();
  520. if ($oViews && $oViews->isEnabled())
  521. $aViews = array(
  522. 'system' => $CNF['OBJECT_VIEWS'],
  523. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  524. 'count' => $aContentInfo['views']
  525. );
  526. //--- Votes
  527. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  528. $aVotes = array();
  529. if ($oVotes && $oVotes->isEnabled())
  530. $aVotes = array(
  531. 'system' => $CNF['OBJECT_VOTES'],
  532. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  533. 'count' => $aContentInfo['votes']
  534. );
  535. //--- Reports
  536. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  537. $aReports = array();
  538. if ($oReports && $oReports->isEnabled())
  539. $aReports = array(
  540. 'system' => $CNF['OBJECT_REPORTS'],
  541. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  542. 'count' => $aContentInfo['reports']
  543. );
  544. //--- Comments
  545. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  546. $aComments = array();
  547. if($oCmts && $oCmts->isEnabled())
  548. $aComments = array(
  549. 'system' => $CNF['OBJECT_COMMENTS'],
  550. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  551. 'count' => $aContentInfo['comments']
  552. );
  553. //--- Title & Description
  554. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  555. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  556. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  557. return array(
  558. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  559. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  560. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  561. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  562. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  563. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  564. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  565. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  566. 'views' => $aViews,
  567. 'votes' => $aVotes,
  568. 'reports' => $aReports,
  569. 'comments' => $aComments,
  570. 'title' => $sTitle, //may be empty.
  571. 'description' => '' //may be empty.
  572. );
  573. }
  574. /**
  575. * Check particular action permission without content
  576. * @param $sAction action to check, for example: Browse, Add
  577. * @param $iContentId content ID
  578. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  579. */
  580. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  581. {
  582. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  583. if (!method_exists($this, $sMethod))
  584. return _t('_sys_request_method_not_found_cpt');
  585. return $this->$sMethod($isPerformAction);
  586. }
  587. /**
  588. * Check particular action permission with content
  589. * @param $sAction action to check, for example: View, Edit
  590. * @param $iContentId content ID
  591. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  592. */
  593. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  594. {
  595. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  596. return _t('_sys_request_page_not_found_cpt');
  597. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  598. if (!method_exists($this, $sMethod))
  599. return _t('_sys_request_method_not_found_cpt');
  600. return $this->$sMethod($aContentInfo, $isPerformAction);
  601. }
  602. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  603. {
  604. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  605. }
  606. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  607. {
  608. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  609. }
  610. public function serviceGetContentOwnerProfileId ($iContentId)
  611. {
  612. $CNF = &$this->_oConfig->CNF;
  613. // file owner must be author of the content or profile itself in case of profile based module
  614. if ($iContentId) {
  615. if ($this instanceof iBxDolProfileService) {
  616. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  617. }
  618. else {
  619. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  620. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  621. }
  622. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  623. }
  624. else {
  625. $iProfileId = bx_get_logged_profile_id();
  626. }
  627. return $iProfileId;
  628. }
  629. // ====== PERMISSION METHODS
  630. public function checkAllowedSetThumb ($iContentId = 0)
  631. {
  632. return CHECK_ACTION_RESULT_ALLOWED;
  633. }
  634. /**
  635. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  636. */
  637. public function checkAllowedBrowse ()
  638. {
  639. return CHECK_ACTION_RESULT_ALLOWED;
  640. }
  641. /**
  642. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  643. */
  644. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  645. {
  646. $CNF = &$this->_oConfig->CNF;
  647. // moderator and owner always have access
  648. if (!empty($this->_iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$this->_iProfileId || $this->_isModerator($isPerformAction)))
  649. return CHECK_ACTION_RESULT_ALLOWED;
  650. // check ACL
  651. $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
  652. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  653. return $aCheck[CHECK_ACTION_MESSAGE];
  654. // check privacy
  655. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  656. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  657. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
  658. return _t('_sys_access_denied_to_private_content');
  659. }
  660. return CHECK_ACTION_RESULT_ALLOWED;
  661. }
  662. /**
  663. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  664. */
  665. public function checkAllowedAdd ($isPerformAction = false)
  666. {
  667. // check ACL
  668. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  669. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  670. return $aCheck[CHECK_ACTION_MESSAGE];
  671. return CHECK_ACTION_RESULT_ALLOWED;
  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 checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  677. {
  678. // moderator and owner always have access
  679. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  680. return CHECK_ACTION_RESULT_ALLOWED;
  681. return _t('_sys_txt_access_denied');
  682. }
  683. /**
  684. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  685. */
  686. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  687. {
  688. // moderator always has access
  689. if ($this->_isModerator($isPerformAction))
  690. return CHECK_ACTION_RESULT_ALLOWED;
  691. // check ACL
  692. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  693. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $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 strict(===) checking.
  699. */
  700. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  701. {
  702. // admin always has access
  703. if (isAdmin())
  704. return CHECK_ACTION_RESULT_ALLOWED;
  705. // check ACL
  706. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  707. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  708. return $aCheck[CHECK_ACTION_MESSAGE];
  709. return CHECK_ACTION_RESULT_ALLOWED;
  710. }
  711. /**
  712. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  713. */
  714. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  715. {
  716. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  717. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  718. return CHECK_ACTION_RESULT_ALLOWED;
  719. return _t('_sys_txt_access_denied');
  720. }
  721. /**
  722. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  723. */
  724. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  725. {
  726. return CHECK_ACTION_RESULT_ALLOWED;
  727. }
  728. /**
  729. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  730. */
  731. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  732. {
  733. return CHECK_ACTION_RESULT_ALLOWED;
  734. }
  735. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  736. {
  737. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  738. return MsgBox($sMsg);
  739. bx_import($sClassSearchResult, $this->_aModule);
  740. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  741. $o = new $sClass($sMode, $aParams);
  742. $o->setDesignBoxTemplateId($iDesignBox);
  743. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  744. $o->setAjaxPaginate($bAjaxPaginate);
  745. $o->setUnitParams(array('context' => $sMode));
  746. if ($o->isError)
  747. return '';
  748. if ($s = $o->processing())
  749. return $s;
  750. else
  751. return '';
  752. }
  753. // ====== COMMON METHODS
  754. public function getProfileId()
  755. {
  756. return bx_get_logged_profile_id();
  757. }
  758. public function getProfileInfo($iUserId = 0)
  759. {
  760. $oProfile = $this->getObjectUser($iUserId);
  761. $oAccount = null;
  762. if($oProfile && !($oProfile instanceof BxDolProfileUndefined))
  763. $oAccount = $oProfile->getAccountObject();
  764. $bAccount = !empty($oAccount);
  765. return array(
  766. 'id' => $oProfile->id(),
  767. 'name' => $oProfile->getDisplayName(),
  768. 'email' => $bAccount ? $oAccount->getEmail() : '',
  769. 'link' => $oProfile->getUrl(),
  770. 'icon' => $oProfile->getIcon(),
  771. 'thumb' => $oProfile->getThumb(),
  772. 'avatar' => $oProfile->getAvatar(),
  773. 'unit' => $oProfile->getUnit(),
  774. 'active' => $oProfile->isActive(),
  775. );
  776. }
  777. public function getObjectUser($iUserId = 0)
  778. {
  779. bx_import('BxDolProfile');
  780. $oProfile = BxDolProfile::getInstance($iUserId);
  781. if (!$oProfile) {
  782. bx_import('BxDolProfileUndefined');
  783. $oProfile = BxDolProfileUndefined::getInstance();
  784. }
  785. return $oProfile;
  786. }
  787. public function getObjectFavorite($sSystem = '', $iId = 0)
  788. {
  789. $CNF = &$this->_oConfig->CNF;
  790. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  791. $sSystem = $CNF['OBJECT_FAVORITES'];
  792. if(empty($sSystem))
  793. return false;
  794. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  795. if(!$oFavorite->isEnabled())
  796. return false;
  797. return $oFavorite;
  798. }
  799. public function getUserId()
  800. {
  801. return isLogged() ? bx_get_logged_profile_id() : 0;
  802. }
  803. public function getUserIp()
  804. {
  805. return getVisitorIP();
  806. }
  807. public function getUserInfo($iUserId = 0)
  808. {
  809. $oProfile = BxDolProfile::getInstance($iUserId);
  810. if (!$oProfile)
  811. $oProfile = BxDolProfileUndefined::getInstance();
  812. return array(
  813. $oProfile->getDisplayName(),
  814. $oProfile->getUrl(),
  815. $oProfile->getThumb(),
  816. $oProfile->getUnit(),
  817. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  818. );
  819. }
  820. public function _isModerator ($isPerformAction = false)
  821. {
  822. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  823. }
  824. // ====== PROTECTED METHODS
  825. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false)
  826. {
  827. $iContentId = $this->_getContent($iContentId, false);
  828. if($iContentId === false)
  829. return false;
  830. bx_import('FormsEntryHelper', $this->_aModule);
  831. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  832. $oFormsHelper = new $sClass($this);
  833. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction);
  834. }
  835. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  836. {
  837. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  838. if($mixedContent === false)
  839. return false;
  840. list($iContentId, $aContentInfo) = $mixedContent;
  841. return $this->_oTemplate->$sFunc($aContentInfo);
  842. }
  843. protected function _rss ($aArgs, $sClass = 'SearchResult')
  844. {
  845. $sMode = array_shift($aArgs);
  846. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  847. $this->_oTemplate->displayAccessDenied ($sMsg);
  848. exit;
  849. }
  850. $aParams = $this->_buildRssParams($sMode, $aArgs);
  851. bx_import ($sClass, $this->_aModule);
  852. $sClass = $this->_aModule['class_prefix'] . $sClass;
  853. $o = new $sClass($sMode, $aParams);
  854. if ($o->isError)
  855. $this->_oTemplate->displayPageNotFound ();
  856. else
  857. $o->outputRSS();
  858. exit;
  859. }
  860. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  861. {
  862. if(!$iContentId)
  863. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  864. if(!$iContentId)
  865. return false;
  866. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  867. return $iContentId;
  868. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  869. if(!$aContentInfo)
  870. return false;
  871. return array($iContentId, $aContentInfo);
  872. }
  873. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  874. {
  875. $CNF = &$this->_oConfig->CNF;
  876. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  877. //--- Image(s)
  878. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  879. return array(
  880. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  881. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  882. 'sample_action' => isset($CNF['T']['txt_sample_single_action']) ? $CNF['T']['txt_sample_single_action'] : '',
  883. 'url' => $sUrl,
  884. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  885. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  886. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  887. 'images' => $aImages,
  888. );
  889. }
  890. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  891. {
  892. $CNF = &$this->_oConfig->CNF;
  893. $sImage = '';
  894. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']])
  895. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  896. if($sImage == '' && isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']])
  897. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  898. if(empty($sImage))
  899. return array();
  900. return array(
  901. array('url' => $sUrl, 'src' => $sImage),
  902. );
  903. }
  904. protected function _entityComments ($sObject, $iId = 0)
  905. {
  906. if (!$iId)
  907. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  908. if (!$iId)
  909. return false;
  910. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  911. if (!$oCmts || !$oCmts->isEnabled())
  912. return false;
  913. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  914. }
  915. protected function _entitySocialSharing ($iId, $aParams = array())
  916. {
  917. $bShowAsButton = !isset($aParams['show_as_button']) || $aParams['show_as_button'] === true;
  918. $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
  919. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  920. //--- Comments
  921. $sComments = '';
  922. $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
  923. if ($oComments) {
  924. $iNum = $oComments->getCommentsCountAll();
  925. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  926. 'class' => 'bx-base-general-comments-' . ($bShowAsButton ? 'button' : 'link'),
  927. 'class_do' => $bShowAsButton ? ' bx-btn' : '',
  928. 'class_counter' => $bShowAsButton ? ' bx-btn-height' : '',
  929. 'url' => $sUrl . $oComments->getListAnchor(true),
  930. 'bx_if:comments' => array (
  931. 'condition' => $iNum,
  932. 'content' => array (
  933. 'num' => $iNum,
  934. ),
  935. ),
  936. ));
  937. }
  938. $aCustomParams = array();
  939. $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  940. $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
  941. if ($iIdThumb && $bSocialSharing) {
  942. if(!empty($aParams['object_transcoder']))
  943. $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
  944. else if(!empty($aParams['object_storage']))
  945. $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
  946. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  947. if($sImgUrl)
  948. $aCustomParams = array (
  949. 'img_url' => $sImgUrl,
  950. 'img_url_encoded' => rawurlencode($sImgUrl),
  951. );
  952. }
  953. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  954. //--- Views
  955. $sViews = '';
  956. $oViews = !empty($aParams['object_view']) ? BxDolView::getObjectInstance($aParams['object_view'], $iId) : false;
  957. if ($oViews)
  958. $sViews = $oViews->getElementBlock(array('show_do_view_as_button' => $bShowAsButton));
  959. //--- Votes
  960. $sVotes = '';
  961. $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
  962. if ($oVotes)
  963. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
  964. //--- Favorite
  965. $sFavorites = '';
  966. $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
  967. if ($oFavorites)
  968. $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => $bShowAsButton));
  969. //--- Featured
  970. $sFeatured = '';
  971. $oFeatured = !empty($aParams['object_feature']) ? BxDolFeature::getObjectInstance($aParams['object_feature'], $iId) : false;
  972. if ($oFeatured)
  973. $sFeatured = $oFeatured->getElementBlock(array('show_do_feature_as_button' => $bShowAsButton));
  974. //--- Timeline Repost
  975. $sRepost = '';
  976. $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
  977. if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  978. $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)));
  979. //--- Report
  980. $sReport = '';
  981. $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
  982. if ($oReport)
  983. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => $bShowAsButton));
  984. $sSocial = '';
  985. if($bSocialSharing) {
  986. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  987. $oSocial->addMarkers(array_merge(array(
  988. 'id' => $iId,
  989. 'module' => $this->_aModule['name'],
  990. 'url' => BX_DOL_URL_ROOT . $sUrl,
  991. 'title' => $sTitle,
  992. ), $aCustomParams));
  993. $sSocial = $oSocial->getCode();
  994. }
  995. if(empty($sComments) && empty($sViews) && empty($sVotes) && empty($sFavorites) && empty($sFeatured) && empty($sRepost) && empty($sReport) && empty($sSocial))
  996. return '';
  997. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  998. 'comments' => $sComments,
  999. 'view' => $sViews,
  1000. 'vote' => $sVotes,
  1001. 'favorite' => $sFavorites,
  1002. 'feature' => $sFeatured,
  1003. 'repost' => $sRepost,
  1004. 'report' => $sReport,
  1005. 'social' => $sSocial,
  1006. ));
  1007. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
  1008. }
  1009. protected function _getFields($iContentId)
  1010. {
  1011. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1012. if(empty($aContentInfo))
  1013. return array();
  1014. return BxDolContentInfo::formatFields($aContentInfo);
  1015. }
  1016. protected function _getFieldValue($sField, $iContentId)
  1017. {
  1018. $CNF = &$this->_oConfig->CNF;
  1019. if(empty($CNF[$sField]))
  1020. return false;
  1021. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1022. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1023. return false;
  1024. return $aContentInfo[$CNF[$sField]];
  1025. }
  1026. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1027. {
  1028. $CNF = &$this->_oConfig->CNF;
  1029. if(empty($sTranscoder) || empty($CNF[$sField]))
  1030. return false;
  1031. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1032. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1033. return false;
  1034. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1035. if(!$oImagesTranscoder)
  1036. return false;
  1037. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1038. }
  1039. }
  1040. /** @} */