BxBaseModGeneralModule.php 52 KB

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