BxBaseModGeneralModule.php 50 KB

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