1
0

BxBaseModGeneralModule.php 53 KB

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