BxBaseModGeneralModule.php 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  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. //--- Scores
  585. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aEvent['object_id']) : null;
  586. $aScores = array();
  587. if ($oScores && $oScores->isEnabled())
  588. $aScores = array(
  589. 'system' => $CNF['OBJECT_SCORES'],
  590. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  591. 'score' => $aContentInfo['score']
  592. );
  593. //--- Reports
  594. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  595. $aReports = array();
  596. if ($oReports && $oReports->isEnabled())
  597. $aReports = array(
  598. 'system' => $CNF['OBJECT_REPORTS'],
  599. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  600. 'count' => $aContentInfo['reports']
  601. );
  602. //--- Comments
  603. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  604. $aComments = array();
  605. if($oCmts && $oCmts->isEnabled())
  606. $aComments = array(
  607. 'system' => $CNF['OBJECT_COMMENTS'],
  608. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  609. 'count' => $aContentInfo['comments']
  610. );
  611. //--- Title & Description
  612. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  613. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  614. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  615. return array(
  616. 'owner_id' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  617. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  618. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  619. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  620. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  621. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  622. 'content' => $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams), //a string to display or array to parse default template before displaying.
  623. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  624. 'views' => $aViews,
  625. 'votes' => $aVotes,
  626. 'scores' => $aScores,
  627. 'reports' => $aReports,
  628. 'comments' => $aComments,
  629. 'title' => $sTitle, //may be empty.
  630. 'description' => '' //may be empty.
  631. );
  632. }
  633. /**
  634. * Check particular action permission without content
  635. * @param $sAction action to check, for example: Browse, Add
  636. * @param $iContentId content ID
  637. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  638. */
  639. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  640. {
  641. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  642. if (!method_exists($this, $sMethod))
  643. return _t('_sys_request_method_not_found_cpt');
  644. return $this->$sMethod($isPerformAction);
  645. }
  646. /**
  647. * Check particular action permission with content
  648. * @param $sAction action to check, for example: View, Edit
  649. * @param $iContentId content ID
  650. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  651. */
  652. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  653. {
  654. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  655. return _t('_sys_request_page_not_found_cpt');
  656. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  657. if (!method_exists($this, $sMethod))
  658. return _t('_sys_request_method_not_found_cpt');
  659. return $this->$sMethod($aContentInfo, $isPerformAction);
  660. }
  661. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  662. {
  663. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  664. }
  665. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  666. {
  667. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  668. }
  669. public function serviceGetContentOwnerProfileId ($iContentId)
  670. {
  671. $CNF = &$this->_oConfig->CNF;
  672. // file owner must be author of the content or profile itself in case of profile based module
  673. if ($iContentId) {
  674. if ($this instanceof iBxDolProfileService) {
  675. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  676. }
  677. else {
  678. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  679. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  680. }
  681. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  682. }
  683. else {
  684. $iProfileId = bx_get_logged_profile_id();
  685. }
  686. return $iProfileId;
  687. }
  688. // ====== PERMISSION METHODS
  689. public function checkAllowedSetThumb ($iContentId = 0)
  690. {
  691. return CHECK_ACTION_RESULT_ALLOWED;
  692. }
  693. /**
  694. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  695. */
  696. public function checkAllowedBrowse ()
  697. {
  698. return CHECK_ACTION_RESULT_ALLOWED;
  699. }
  700. /**
  701. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  702. */
  703. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  704. {
  705. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  706. }
  707. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  708. {
  709. if (!$iProfileId)
  710. $iProfileId = $this->_iProfileId;
  711. $CNF = &$this->_oConfig->CNF;
  712. // moderator and owner always have access
  713. if (!empty($iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  714. return CHECK_ACTION_RESULT_ALLOWED;
  715. // check ACL
  716. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  717. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  718. return $aCheck[CHECK_ACTION_MESSAGE];
  719. // check privacy
  720. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  721. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  722. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  723. return _t('_sys_access_denied_to_private_content');
  724. }
  725. return CHECK_ACTION_RESULT_ALLOWED;
  726. }
  727. /**
  728. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  729. */
  730. public function checkAllowedAdd ($isPerformAction = false)
  731. {
  732. // check ACL
  733. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  734. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  735. return $aCheck[CHECK_ACTION_MESSAGE];
  736. return CHECK_ACTION_RESULT_ALLOWED;
  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 checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  742. {
  743. // moderator and owner always have access
  744. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  745. return CHECK_ACTION_RESULT_ALLOWED;
  746. return _t('_sys_txt_access_denied');
  747. }
  748. /**
  749. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  750. */
  751. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  752. {
  753. // moderator always has access
  754. if ($this->_isModerator($isPerformAction))
  755. return CHECK_ACTION_RESULT_ALLOWED;
  756. // check ACL
  757. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  758. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  759. return CHECK_ACTION_RESULT_ALLOWED;
  760. return _t('_sys_txt_access_denied');
  761. }
  762. /**
  763. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  764. */
  765. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  766. {
  767. // admin always has access
  768. if (isAdmin())
  769. return CHECK_ACTION_RESULT_ALLOWED;
  770. // check ACL
  771. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  772. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  773. return $aCheck[CHECK_ACTION_MESSAGE];
  774. return CHECK_ACTION_RESULT_ALLOWED;
  775. }
  776. /**
  777. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  778. */
  779. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  780. {
  781. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  782. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  783. return CHECK_ACTION_RESULT_ALLOWED;
  784. return _t('_sys_txt_access_denied');
  785. }
  786. /**
  787. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  788. */
  789. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  790. {
  791. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  792. }
  793. /**
  794. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  795. */
  796. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  797. {
  798. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  799. }
  800. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  801. {
  802. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  803. return MsgBox($sMsg);
  804. bx_import($sClassSearchResult, $this->_aModule);
  805. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  806. $o = new $sClass($sMode, $aParams);
  807. $o->setDesignBoxTemplateId($iDesignBox);
  808. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  809. $o->setAjaxPaginate($bAjaxPaginate);
  810. $o->setUnitParams(array('context' => $sMode));
  811. if ($o->isError)
  812. return '';
  813. if ($s = $o->processing())
  814. return $s;
  815. else
  816. return '';
  817. }
  818. // ====== COMMON METHODS
  819. public function getProfileId()
  820. {
  821. return bx_get_logged_profile_id();
  822. }
  823. public function getProfileInfo($iUserId = 0)
  824. {
  825. $oProfile = $this->getObjectUser($iUserId);
  826. $oAccount = null;
  827. if($oProfile && !($oProfile instanceof BxDolProfileUndefined))
  828. $oAccount = $oProfile->getAccountObject();
  829. $bAccount = !empty($oAccount);
  830. return array(
  831. 'id' => $oProfile->id(),
  832. 'name' => $oProfile->getDisplayName(),
  833. 'email' => $bAccount ? $oAccount->getEmail() : '',
  834. 'link' => $oProfile->getUrl(),
  835. 'icon' => $oProfile->getIcon(),
  836. 'thumb' => $oProfile->getThumb(),
  837. 'avatar' => $oProfile->getAvatar(),
  838. 'unit' => $oProfile->getUnit(),
  839. 'active' => $oProfile->isActive(),
  840. );
  841. }
  842. public function getObjectUser($iUserId = 0)
  843. {
  844. bx_import('BxDolProfile');
  845. $oProfile = BxDolProfile::getInstance($iUserId);
  846. if (!$oProfile) {
  847. bx_import('BxDolProfileUndefined');
  848. $oProfile = BxDolProfileUndefined::getInstance();
  849. }
  850. return $oProfile;
  851. }
  852. public function getObjectFavorite($sSystem = '', $iId = 0)
  853. {
  854. $CNF = &$this->_oConfig->CNF;
  855. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  856. $sSystem = $CNF['OBJECT_FAVORITES'];
  857. if(empty($sSystem))
  858. return false;
  859. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  860. if(!$oFavorite->isEnabled())
  861. return false;
  862. return $oFavorite;
  863. }
  864. public function getUserId()
  865. {
  866. return isLogged() ? bx_get_logged_profile_id() : 0;
  867. }
  868. public function getUserIp()
  869. {
  870. return getVisitorIP();
  871. }
  872. public function getUserInfo($iUserId = 0)
  873. {
  874. $oProfile = BxDolProfile::getInstance($iUserId);
  875. if (!$oProfile)
  876. $oProfile = BxDolProfileUndefined::getInstance();
  877. return array(
  878. $oProfile->getDisplayName(),
  879. $oProfile->getUrl(),
  880. $oProfile->getThumb(),
  881. $oProfile->getUnit(),
  882. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  883. );
  884. }
  885. public function _isModerator ($isPerformAction = false)
  886. {
  887. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  888. }
  889. // ====== PROTECTED METHODS
  890. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  891. {
  892. $iContentId = $this->_getContent($iContentId, false);
  893. if($iContentId === false)
  894. return false;
  895. bx_import('FormsEntryHelper', $this->_aModule);
  896. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  897. $oFormsHelper = new $sClass($this);
  898. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  899. }
  900. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  901. {
  902. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  903. if($mixedContent === false)
  904. return false;
  905. list($iContentId, $aContentInfo) = $mixedContent;
  906. return $this->_oTemplate->$sFunc($aContentInfo);
  907. }
  908. protected function _rss ($aArgs, $sClass = 'SearchResult')
  909. {
  910. $sMode = array_shift($aArgs);
  911. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  912. $this->_oTemplate->displayAccessDenied ($sMsg);
  913. exit;
  914. }
  915. $aParams = $this->_buildRssParams($sMode, $aArgs);
  916. bx_import ($sClass, $this->_aModule);
  917. $sClass = $this->_aModule['class_prefix'] . $sClass;
  918. $o = new $sClass($sMode, $aParams);
  919. if ($o->isError)
  920. $this->_oTemplate->displayPageNotFound ();
  921. else
  922. $o->outputRSS();
  923. exit;
  924. }
  925. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  926. {
  927. if(!$iContentId)
  928. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  929. if(!$iContentId)
  930. return false;
  931. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  932. return $iContentId;
  933. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  934. if(!$aContentInfo)
  935. return false;
  936. return array($iContentId, $aContentInfo);
  937. }
  938. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  939. {
  940. $CNF = &$this->_oConfig->CNF;
  941. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  942. //--- Image(s)
  943. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  944. //--- Video(s)
  945. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  946. return array(
  947. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  948. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  949. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  950. 'url' => $sUrl,
  951. 'title' => isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] :
  952. (isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...') : ''),
  953. 'text' => isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '',
  954. 'images' => $aImages,
  955. 'videos' => $aVideos
  956. );
  957. }
  958. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  959. {
  960. $CNF = &$this->_oConfig->CNF;
  961. $sImage = $sImageOrig = '';
  962. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  963. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  964. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  965. }
  966. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  967. if($sImage == '' && $bImageThumb)
  968. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  969. if($sImageOrig == '' && $bImageThumb)
  970. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  971. if(empty($sImage))
  972. return array();
  973. if($sImageOrig == '')
  974. $sImageOrig = $sImage;
  975. return array(
  976. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  977. );
  978. }
  979. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  980. {
  981. return array();
  982. }
  983. protected function _entityComments ($sObject, $iId = 0)
  984. {
  985. if (!$iId)
  986. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  987. if (!$iId)
  988. return false;
  989. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  990. if (!$oCmts || !$oCmts->isEnabled())
  991. return false;
  992. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  993. }
  994. protected function _entitySocialSharing ($iId, $aParams = array())
  995. {
  996. $bShowAsButton = !isset($aParams['show_as_button']) || $aParams['show_as_button'] === true;
  997. $sUrl = !empty($aParams['uri_view_entry']) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $aParams['uri_view_entry'] . '&id=' . $iId) : '';
  998. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  999. //--- Comments
  1000. $sComments = '';
  1001. $oComments = !empty($aParams['object_comments']) ? BxTemplCmts::getObjectInstance($aParams['object_comments'], $iId) : false;
  1002. if ($oComments) {
  1003. $iNum = $oComments->getCommentsCountAll();
  1004. $sComments = $this->_oTemplate->parseHtmlByName('comments-item.html', array (
  1005. 'class' => 'bx-base-general-comments-' . ($bShowAsButton ? 'button' : 'link'),
  1006. 'class_do' => $bShowAsButton ? ' bx-btn' : '',
  1007. 'class_counter' => $bShowAsButton ? ' bx-btn-height' : '',
  1008. 'url' => $sUrl . $oComments->getListAnchor(true),
  1009. 'bx_if:comments' => array (
  1010. 'condition' => $iNum,
  1011. 'content' => array (
  1012. 'num' => $iNum,
  1013. ),
  1014. ),
  1015. ));
  1016. }
  1017. $aCustomParams = array();
  1018. $iIdThumb = isset($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1019. $bSocialSharing = isset($aParams['social_sharing']) ? (bool)$aParams['social_sharing'] : true;
  1020. if ($iIdThumb && $bSocialSharing) {
  1021. if(!empty($aParams['object_transcoder']))
  1022. $o = BxDolTranscoder::getObjectInstance($aParams['object_transcoder']);
  1023. else if(!empty($aParams['object_storage']))
  1024. $o = BxDolStorage::getObjectInstance($aParams['object_storage']);
  1025. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1026. if($sImgUrl)
  1027. $aCustomParams = array (
  1028. 'img_url' => $sImgUrl,
  1029. 'img_url_encoded' => rawurlencode($sImgUrl),
  1030. );
  1031. }
  1032. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Share, etc.
  1033. //--- Views
  1034. $sViews = '';
  1035. $oViews = !empty($aParams['object_view']) ? BxDolView::getObjectInstance($aParams['object_view'], $iId) : false;
  1036. if ($oViews && $oViews->isEnabled())
  1037. $sViews = $oViews->getElementBlock(array('show_do_view_as_button' => $bShowAsButton));
  1038. //--- Votes
  1039. $sVotes = '';
  1040. $oVotes = !empty($aParams['object_vote']) ? BxDolVote::getObjectInstance($aParams['object_vote'], $iId) : false;
  1041. if ($oVotes && $oVotes->isEnabled())
  1042. $sVotes = $oVotes->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
  1043. //--- Scores
  1044. $sScores = '';
  1045. $oScores = !empty($aParams['object_score']) ? BxDolScore::getObjectInstance($aParams['object_score'], $iId) : false;
  1046. if ($oScores && $oScores->isEnabled())
  1047. $sScores = $oScores->getElementBlock(array('show_do_vote_as_button' => $bShowAsButton));
  1048. //--- Favorite
  1049. $sFavorites = '';
  1050. $oFavorites = !empty($aParams['object_favorite']) ? BxDolFavorite::getObjectInstance($aParams['object_favorite'], $iId) : false;
  1051. if ($oFavorites && $oFavorites->isEnabled())
  1052. $sFavorites = $oFavorites->getElementBlock(array('show_do_favorite_as_button' => $bShowAsButton));
  1053. //--- Featured
  1054. $sFeatured = '';
  1055. $oFeatured = !empty($aParams['object_feature']) ? BxDolFeature::getObjectInstance($aParams['object_feature'], $iId) : false;
  1056. if ($oFeatured && $oFeatured->isEnabled())
  1057. $sFeatured = $oFeatured->getElementBlock(array('show_do_feature_as_button' => $bShowAsButton));
  1058. //--- Timeline Repost
  1059. $sRepost = '';
  1060. $iIdTimeline = isset($aParams['id_timeline']) ? (int)$aParams['id_timeline'] : $iId;
  1061. if ($iIdTimeline && BxDolRequest::serviceExists('bx_timeline', 'get_repost_element_block'))
  1062. $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)));
  1063. //--- Report
  1064. $sReport = '';
  1065. $oReport = !empty($aParams['object_report']) ? BxDolReport::getObjectInstance($aParams['object_report'], $iId) : false;
  1066. if ($oReport)
  1067. $sReport = $oReport->getElementBlock(array('show_do_report_as_button' => $bShowAsButton));
  1068. $sSocial = '';
  1069. if($bSocialSharing) {
  1070. $oSocial = BxDolMenu::getObjectInstance('sys_social_sharing');
  1071. $oSocial->addMarkers(array_merge(array(
  1072. 'id' => $iId,
  1073. 'module' => $this->_aModule['name'],
  1074. 'url' => BX_DOL_URL_ROOT . $sUrl,
  1075. 'title' => $sTitle,
  1076. ), $aCustomParams));
  1077. $sSocial = $oSocial->getCode();
  1078. }
  1079. if(empty($sComments) && empty($sViews) && empty($sVotes) && empty($sScores) && empty($sFavorites) && empty($sFeatured) && empty($sRepost) && empty($sReport) && empty($sSocial))
  1080. return '';
  1081. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1082. 'comments' => $sComments,
  1083. 'view' => $sViews,
  1084. 'vote' => $sVotes,
  1085. 'score' => $sScores,
  1086. 'favorite' => $sFavorites,
  1087. 'feature' => $sFeatured,
  1088. 'repost' => $sRepost,
  1089. 'report' => $sReport,
  1090. 'social' => $sSocial,
  1091. ));
  1092. //TODO: Rebuild using menus engine when it will be ready for such elements like Vote, Repost, etc.
  1093. }
  1094. protected function _getFields($iContentId)
  1095. {
  1096. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1097. if(empty($aContentInfo))
  1098. return array();
  1099. return BxDolContentInfo::formatFields($aContentInfo);
  1100. }
  1101. protected function _getFieldValue($sField, $iContentId)
  1102. {
  1103. $CNF = &$this->_oConfig->CNF;
  1104. if(empty($CNF[$sField]))
  1105. return false;
  1106. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1107. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1108. return false;
  1109. return $aContentInfo[$CNF[$sField]];
  1110. }
  1111. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1112. {
  1113. $CNF = &$this->_oConfig->CNF;
  1114. if(empty($sTranscoder) || empty($CNF[$sField]))
  1115. return false;
  1116. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1117. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1118. return false;
  1119. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1120. if(!$oImagesTranscoder)
  1121. return false;
  1122. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1123. }
  1124. }
  1125. /** @} */