1
0

BxBaseModGeneralModule.php 49 KB

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