1
0

BxBaseModGeneralModule.php 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  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. protected $_aFormParams;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_aSearchableNamesExcept = array(
  25. 'allow_view_to'
  26. );
  27. $this->_aFormParams = array(
  28. 'display' => false,
  29. 'dynamic_mode' => false,
  30. 'ajax_mode' => false,
  31. 'absolute_action_url' => false,
  32. 'visibility_autoselect' => false,
  33. 'context_id' => 0,
  34. 'custom' => array()
  35. );
  36. }
  37. // ====== ACTIONS METHODS
  38. public function actionRss ()
  39. {
  40. $aArgs = func_get_args();
  41. $this->_rss($aArgs);
  42. }
  43. public function actionGetCreatePostForm()
  44. {
  45. $sName = $this->_oConfig->getName();
  46. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  47. $aParams = array_merge($this->_aFormParams, $aParams);
  48. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  49. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  50. if(empty($mixedResponse))
  51. return echoJson(array());
  52. else if(is_array($mixedResponse)) {
  53. $mixedResponse['module'] = $sName;
  54. return echoJson($mixedResponse);
  55. }
  56. return echoJson(array(
  57. 'module' => $sName,
  58. 'content' => $mixedResponse
  59. ));
  60. }
  61. // ====== SERVICE METHODS
  62. public function serviceGetCreatePostForm($aParams = array())
  63. {
  64. $aParams = array_merge($this->_aFormParams, $aParams);
  65. $oForm = $this->serviceGetObjectForm('add', $aParams);
  66. if(!$oForm)
  67. return '';
  68. return $this->serviceEntityCreate($aParams);
  69. }
  70. public function serviceGetAuthor ($iContentId)
  71. {
  72. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  73. return $mixedResult !== false ? (int)$mixedResult : 0;
  74. }
  75. public function serviceGetPrivacyView ($iContentId)
  76. {
  77. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  78. }
  79. public function serviceGetDateAdded ($iContentId)
  80. {
  81. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  82. return $mixedResult !== false ? (int)$mixedResult : 0;
  83. }
  84. public function serviceGetDateChanged ($iContentId)
  85. {
  86. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  87. return $mixedResult !== false ? (int)$mixedResult : 0;
  88. }
  89. public function serviceGetLink ($iContentId)
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. if(empty($CNF['URI_VIEW_ENTRY']))
  93. return '';
  94. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  95. if(empty($aContentInfo))
  96. return '';
  97. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  98. }
  99. public function serviceGetTitle ($iContentId)
  100. {
  101. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  102. return $mixedResult !== false ? $mixedResult : '';
  103. }
  104. public function serviceGetText ($iContentId)
  105. {
  106. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  107. if (false === $mixedResult)
  108. return '';
  109. $CNF = &$this->_oConfig->CNF;
  110. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  111. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  112. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  113. }
  114. return $mixedResult;
  115. }
  116. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  117. {
  118. $CNF = &$this->_oConfig->CNF;
  119. $aContentInfo = $this->_getFields($iContentId);
  120. if(empty($aContentInfo))
  121. return array();
  122. if(!$bSearchableFieldsOnly)
  123. return $aContentInfo;
  124. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  125. return array();
  126. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  127. if(empty($aFields))
  128. return array();
  129. $aResult = array();
  130. foreach($aFields as $sField)
  131. if(isset($aContentInfo[$sField]))
  132. $aResult[$sField] = $aContentInfo[$sField];
  133. return $aResult;
  134. }
  135. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  136. {
  137. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  138. if(empty($aContentInfo))
  139. return '';
  140. if(empty($sUnitTemplate))
  141. $sUnitTemplate = 'unit.html';
  142. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  143. }
  144. public function serviceGetAll ($aParams = array())
  145. {
  146. if(empty($aParams) || !is_array($aParams))
  147. $aParams = array('type' => 'all');
  148. return $this->_oDb->getEntriesBy($aParams);
  149. }
  150. public function serviceGetAllByAuthor ($iProfileId)
  151. {
  152. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  153. }
  154. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  155. {
  156. $CNF = &$this->_oConfig->CNF;
  157. if(empty($CNF['OBJECT_FORM_ENTRY']))
  158. return array();
  159. $aResult = array();
  160. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  161. $aResult[$CNF['FIELD_AUTHOR']] = array(
  162. 'type' => 'text_auto',
  163. 'caption' => $CNF['T']['form_field_author'],
  164. 'info' => '',
  165. 'value' => '',
  166. 'values' => '',
  167. 'pass' => ''
  168. );
  169. $aInputs = array();
  170. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  171. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  172. $aInputs = array_merge($aInputs, $oForm->aInputs);
  173. }
  174. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  175. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  176. $aInputs = array_merge($aInputs, $oForm->aInputs);
  177. }
  178. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  179. $aInputs = array_merge($aInputs, $aInputsAdd);
  180. foreach($aInputs as $aInput){
  181. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  182. $aField = array(
  183. 'type' => $aInput['type'],
  184. 'caption_system' => $aInput['caption_system_src'],
  185. 'caption' => $aInput['caption_src'],
  186. 'info' => $aInput['info_src'],
  187. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  188. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  189. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  190. );
  191. if(isset($aInput['search_type']))
  192. $aField['search_type'] = $aInput['search_type'];
  193. $aResult[$aInput['name']] = $aField;
  194. }
  195. }
  196. return $aResult;
  197. }
  198. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  199. {
  200. if(empty($aParams) || !is_array($aParams))
  201. return array();
  202. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  203. }
  204. public function serviceModuleIcon ()
  205. {
  206. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  207. }
  208. public function serviceGetSearchableFields ($aInputsAdd = array())
  209. {
  210. $CNF = $this->_oConfig->CNF;
  211. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  212. return array();
  213. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  214. if(!$oForm)
  215. return array();
  216. $aInputs = $oForm->aInputs;
  217. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  218. $aInputs = array_merge($aInputs, $aInputsAdd);
  219. $aTextTypes = array('text', 'textarea');
  220. $aTextFields = array();
  221. foreach($aInputs as $r)
  222. if(in_array($r['type'], $aTextTypes))
  223. $aTextFields[$r['name']] = $r['caption'];
  224. return $aTextFields;
  225. }
  226. public function serviceManageTools($sType = 'common')
  227. {
  228. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  229. if(!$oGrid)
  230. return '';
  231. $CNF = &$this->_oConfig->CNF;
  232. $sMenu = '';
  233. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  234. $oPermalink = BxDolPermalinks::getInstance();
  235. $aMenuItems = array();
  236. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  237. $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);
  238. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  239. $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);
  240. if(count($aMenuItems) > 1) {
  241. $oMenu = new BxTemplMenu(array(
  242. 'template' => 'menu_vertical.html',
  243. 'menu_items' => $aMenuItems
  244. ), $this->_oTemplate);
  245. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  246. $sMenu = $oMenu->getCode();
  247. }
  248. }
  249. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  250. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  251. }
  252. $this->_oTemplate->addCss(array('manage_tools.css'));
  253. $this->_oTemplate->addJs(array('manage_tools.js'));
  254. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  255. return array(
  256. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  257. 'menu' => $sMenu
  258. );
  259. }
  260. public function serviceGetMenuAddonManageTools()
  261. {
  262. return 0;
  263. }
  264. public function serviceGetMenuAddonManageToolsProfileStats()
  265. {
  266. return 0;
  267. }
  268. /**
  269. * My entries actions block
  270. */
  271. public function serviceMyEntriesActions ($iProfileId = 0)
  272. {
  273. $CNF = &$this->_oConfig->CNF;
  274. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  275. return false;
  276. if (!$iProfileId)
  277. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  278. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  279. return false;
  280. if ($iProfileId != $this->_iProfileId)
  281. return false;
  282. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  283. return $oMenu ? $oMenu->getCode() : false;
  284. }
  285. /**
  286. * Universal browse method
  287. * @param $aParams custom browse params, possible params are the following:
  288. * - mode - browse mode, such as 'recent', 'featured', etc
  289. * - params - custom params to browse method, for example 'unit_view' can be passed here
  290. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  291. * - empty_message - display or not "empty" message when there is no content
  292. * - ajax_paginate - use AJAX paginate or not
  293. * @return HTML string
  294. */
  295. public function serviceBrowse ($aParams = array())
  296. {
  297. $aDefaults = array (
  298. 'mode' => 'recent',
  299. 'params' => false,
  300. 'design_box' => BX_DB_PADDING_DEF,
  301. 'empty_message' => false,
  302. 'ajax_paginate' => true,
  303. );
  304. $aParams = array_merge($aDefaults, $aParams);
  305. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  306. }
  307. /**
  308. * Display featured entries
  309. * @return HTML string
  310. */
  311. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  312. {
  313. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  314. }
  315. /**
  316. * Display entries favored by a member
  317. * @return HTML string
  318. */
  319. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  320. {
  321. $oProfile = null;
  322. if((int)$iProfileId)
  323. $oProfile = BxDolProfile::getInstance($iProfileId);
  324. if(!$oProfile && bx_get('profile_id') !== false)
  325. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  326. if(!$oProfile)
  327. $oProfile = BxDolProfile::getInstance();
  328. if(!$oProfile)
  329. return '';
  330. $bEmptyMessage = false;
  331. if(isset($aParams['empty_message'])) {
  332. $bEmptyMessage = (bool)$aParams['empty_message'];
  333. unset($aParams['empty_message']);
  334. }
  335. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  336. }
  337. public function serviceFormsHelper ()
  338. {
  339. bx_import('FormsEntryHelper', $this->_aModule);
  340. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  341. return new $sClass($this);
  342. }
  343. /**
  344. * Add entry using provided fields' values.
  345. * @return array with result: 'code' is 0 on success or non-zero on error, 'message' is error message in case of error, 'content' is content info array in case of success
  346. */
  347. public function serviceEntityAdd ($iProfile, $aValues)
  348. {
  349. bx_import('FormsEntryHelper', $this->_aModule);
  350. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  351. $oFormsHelper = new $sClass($this);
  352. return $oFormsHelper->addData($iProfile, $aValues);
  353. }
  354. /**
  355. * Perform redirect after content creation
  356. * @return nothing, rediret header is sent
  357. */
  358. public function serviceRedirectAfterAdd($aContentInfo)
  359. {
  360. bx_import('FormsEntryHelper', $this->_aModule);
  361. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  362. $oFormsHelper = new $sClass($this);
  363. $oFormsHelper->redirectAfterAdd($aContentInfo);
  364. }
  365. /**
  366. * Get form object for add, edit, view or delete the content
  367. * @param $sType 'add', 'edit', 'view' or 'delete'
  368. * @param $aParams optional array with parameters(display name, etc)
  369. * @return form object or false on error
  370. */
  371. public function serviceGetObjectForm ($sType, $aParams = array())
  372. {
  373. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  374. return false;
  375. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  376. $bContext = $mixedContextId !== false;
  377. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  378. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  379. return false;
  380. $CNF = &$this->_oConfig->CNF;
  381. bx_import('FormsEntryHelper', $this->_aModule);
  382. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  383. $oFormsHelper = new $sClass($this);
  384. $sParamsKey = 'ajax_mode';
  385. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  386. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  387. $sParamsKey = 'absolute_action_url';
  388. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  389. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  390. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  391. $sFunc = 'getObjectForm' . ucfirst($sType);
  392. $oForm = $oFormsHelper->$sFunc($sDisplay);
  393. $sKey = 'FIELD_ALLOW_VIEW_TO';
  394. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  395. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  396. if(!$bContext || $bContextOwner) {
  397. $iGc = 0;
  398. $iKeyGh = false;
  399. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  400. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  401. if($iKeyGh !== false && $iGc == 0) {
  402. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  403. $iKeyGh = false;
  404. if($aValue['type'] == 'group_end')
  405. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  406. }
  407. if($aValue['type'] == 'group_header') {
  408. $iGc = 0;
  409. $iKeyGh = $iKey;
  410. }
  411. continue;
  412. }
  413. //--- Show 'Public' privacy group only in Public post form.
  414. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  415. $iGc += 1;
  416. continue;
  417. }
  418. //--- Show a default privacy groups in Profile (for Owner) post form.
  419. if($bContextOwner && (int)$aValue['key'] >= 0) {
  420. $iGc += 1;
  421. continue;
  422. }
  423. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  424. }
  425. }
  426. else {
  427. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  428. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  429. }
  430. }
  431. bx_alert('system', 'get_object_form', 0, 0, array(
  432. 'module' => $this->_oConfig->getName(),
  433. 'type' => $sType,
  434. 'params' => $aParams,
  435. 'form' => &$oForm
  436. ));
  437. return $oForm;
  438. }
  439. /**
  440. * Create entry form
  441. * @return HTML string
  442. */
  443. public function serviceEntityCreate ($sParams = false)
  444. {
  445. $bParamsArray = is_array($sParams);
  446. $sDisplay = is_string($sParams) ? $sParams : false;
  447. if($bParamsArray && !empty($sParams['display']))
  448. $sDisplay = $sParams['display'];
  449. bx_import('FormsEntryHelper', $this->_aModule);
  450. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  451. $oFormsHelper = new $sClass($this);
  452. if($bParamsArray && isset($sParams['dynamic_mode']))
  453. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  454. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  455. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  456. echoJson($mixedResult);
  457. exit;
  458. }
  459. return $mixedResult;
  460. }
  461. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  462. {
  463. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  464. }
  465. public function serviceEntityDelete ($iContentId = 0)
  466. {
  467. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  468. }
  469. public function serviceEntityTextBlock ($iContentId = 0)
  470. {
  471. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  472. }
  473. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  474. {
  475. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  476. }
  477. public function serviceEntityInfoFull ($iContentId = 0)
  478. {
  479. $CNF = &$this->_oConfig->CNF;
  480. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  481. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  482. }
  483. public function serviceEntityInfoExtended ($iContentId = 0)
  484. {
  485. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  486. }
  487. /**
  488. * Entry location info
  489. */
  490. public function serviceEntityLocation ($iContentId = 0)
  491. {
  492. $iContentId = $this->_getContent($iContentId, false);
  493. if($iContentId === false)
  494. return false;
  495. return $this->_oTemplate->entryLocation ($iContentId);
  496. }
  497. /**
  498. * Entry comments
  499. */
  500. public function serviceEntityComments ($iContentId = 0)
  501. {
  502. $CNF = &$this->_oConfig->CNF;
  503. if(empty($CNF['OBJECT_COMMENTS']))
  504. return '';
  505. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  506. }
  507. /**
  508. * Entry attachments block
  509. */
  510. public function serviceEntityAttachments ($iContentId = 0)
  511. {
  512. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  513. }
  514. /**
  515. * Delete content entry
  516. * @param $iContentId content id
  517. * @return error message or empty string on success
  518. */
  519. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  520. {
  521. bx_import('FormsEntryHelper', $this->_aModule);
  522. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  523. $oFormsHelper = new $sClass($this);
  524. return $oFormsHelper->$sFuncDelete($iContentId);
  525. }
  526. /**
  527. * Entry actions and social sharing block
  528. */
  529. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  530. {
  531. $CNF = &$this->_oConfig->CNF;
  532. if(!empty($mixedContent)) {
  533. if(!is_array($mixedContent))
  534. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  535. }
  536. else {
  537. $mixedContent = $this->_getContent();
  538. if($mixedContent === false)
  539. return false;
  540. }
  541. list($iContentId, $aContentInfo) = $mixedContent;
  542. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  543. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  544. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  545. if(empty($sObjectMenu))
  546. return false;
  547. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  548. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  549. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  550. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  551. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  552. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  553. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  554. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  555. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  556. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  557. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  558. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  559. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  560. $aMarkers = array(
  561. 'id' => $iContentId,
  562. 'module' => $this->_oConfig->getName(),
  563. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  564. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  565. 'img_url' => ''
  566. );
  567. if(!empty($iEntryThumb)) {
  568. if(!empty($sObjectTranscoder))
  569. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  570. else if(!empty($sObjectStorage))
  571. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  572. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  573. if(!empty($sImageUrl))
  574. $aMarkers['img_url'] = $sImageUrl;
  575. }
  576. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  577. if(!$oActions)
  578. return false;
  579. $oActions->setContentId($iContentId);
  580. $oActions->addMarkers($aMarkers);
  581. return $this->_oTemplate->entryAllActions($oActions->getCode());
  582. }
  583. /**
  584. * Entry actions block
  585. */
  586. public function serviceEntityActions ($iContentId = 0)
  587. {
  588. $iContentId = $this->_getContent($iContentId, false);
  589. if($iContentId === false)
  590. return false;
  591. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  592. return $oMenu ? $oMenu->getCode() : false;
  593. }
  594. /**
  595. * Entry social sharing block.
  596. * @param type $mixedContent integer content ID or array with integer content ID and array with content info, or false.
  597. * @param type $aParams array with additional custom params which may overwrite some default values.
  598. * @return boolean|string string with block content or false if something went wrong.
  599. */
  600. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  601. {
  602. if(!empty($mixedContent)) {
  603. if(!is_array($mixedContent))
  604. $mixedContent = array((int)$mixedContent, array());
  605. }
  606. else {
  607. $mixedContent = $this->_getContent();
  608. if($mixedContent === false)
  609. return false;
  610. }
  611. list($iContentId, $aContentInfo) = $mixedContent;
  612. $CNF = &$this->_oConfig->CNF;
  613. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  614. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  615. $sUri = $CNF['URI_VIEW_ENTRY'];
  616. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  617. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  618. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  619. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  620. $aMarkers = array(
  621. 'id' => $iContentId,
  622. 'module' => $this->_aModule['name'],
  623. 'url' => BX_DOL_URL_ROOT . $sUrl,
  624. 'title' => $sTitle,
  625. );
  626. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  627. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  628. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  629. if ($iIdThumb) {
  630. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  631. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  632. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  633. $sStorage = $CNF['OBJECT_STORAGE'];
  634. if(!empty($sTranscoder))
  635. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  636. else if(!empty($sStorage))
  637. $o = BxDolStorage::getObjectInstance($sStorage);
  638. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  639. if($sImgUrl)
  640. $aMarkers['img_url'] = $sImgUrl;
  641. }
  642. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  643. $oMenu->addMarkers($aMarkers);
  644. $sMenu = $oMenu->getCode();
  645. if(empty($sMenu))
  646. return '';
  647. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  648. 'menu' => $sMenu
  649. ));
  650. }
  651. /**
  652. * Data for Notifications module
  653. */
  654. public function serviceGetNotificationsData()
  655. {
  656. $sModule = $this->_aModule['name'];
  657. $sEventPrivacy = $sModule . '_allow_view_event_to';
  658. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  659. $sEventPrivacy = '';
  660. return array(
  661. 'handlers' => array(
  662. 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),
  663. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  664. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  665. 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),
  666. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  667. 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),
  668. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  669. 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),
  670. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  671. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  672. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  673. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  674. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  675. ),
  676. 'settings' => array(
  677. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  678. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  679. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  680. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  681. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  682. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  683. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  684. ),
  685. 'alerts' => array(
  686. array('unit' => $sModule, 'action' => 'added'),
  687. array('unit' => $sModule, 'action' => 'edited'),
  688. array('unit' => $sModule, 'action' => 'deleted'),
  689. array('unit' => $sModule, 'action' => 'commentPost'),
  690. array('unit' => $sModule, 'action' => 'commentRemoved'),
  691. array('unit' => $sModule, 'action' => 'replyPost'),
  692. array('unit' => $sModule, 'action' => 'replyRemoved'),
  693. array('unit' => $sModule, 'action' => 'doVote'),
  694. array('unit' => $sModule, 'action' => 'undoVote'),
  695. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  696. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  697. array('unit' => $sModule, 'action' => 'doVoteUp'),
  698. array('unit' => $sModule, 'action' => 'doVoteDown'),
  699. )
  700. );
  701. }
  702. /**
  703. * Entry post for Notifications module
  704. */
  705. public function serviceGetNotificationsPost($aEvent)
  706. {
  707. $CNF = &$this->_oConfig->CNF;
  708. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  709. if(empty($aContentInfo) || !is_array($aContentInfo))
  710. return array();
  711. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  712. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  713. return array(
  714. 'entry_sample' => $CNF['T']['txt_sample_single'],
  715. 'entry_url' => $sEntryUrl,
  716. 'entry_caption' => $sEntryCaption,
  717. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  718. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  719. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  720. /*
  721. * Custom settings for email and/or push notifications can be provided here.
  722. * Only necessary parts of 'settings' array can be used.
  723. *
  724. 'settings' => array(
  725. 'email' => array(
  726. 'template' => '', //--- custom email template
  727. 'markers' => '', //--- markers to parse email parts (subject, body) with
  728. 'subject' => '' //--- custom email subject
  729. ),
  730. 'push' => array(
  731. 'subject' => '' //--- custom push notification subject
  732. )
  733. )
  734. */
  735. );
  736. }
  737. /**
  738. * Entry post comment for Notifications module
  739. */
  740. public function serviceGetNotificationsComment($aEvent)
  741. {
  742. $CNF = &$this->_oConfig->CNF;
  743. $iContentId = (int)$aEvent['object_id'];
  744. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  745. if(empty($aContentInfo) || !is_array($aContentInfo))
  746. return array();
  747. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  748. if(!$oComment || !$oComment->isEnabled())
  749. return array();
  750. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  751. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  752. return array(
  753. 'entry_sample' => $CNF['T']['txt_sample_single'],
  754. 'entry_url' => $sEntryUrl,
  755. 'entry_caption' => $sEntryCaption,
  756. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  757. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  758. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  759. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  760. );
  761. }
  762. /**
  763. * Entry post reply for Notifications module
  764. */
  765. public function serviceGetNotificationsReply($aEvent)
  766. {
  767. $CNF = &$this->_oConfig->CNF;
  768. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  769. if(!$oComment || !$oComment->isEnabled())
  770. return array();
  771. $iParentId = (int)$aEvent['object_id'];
  772. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  773. if(empty($aParentInfo) || !is_array($aParentInfo))
  774. return array();
  775. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  776. $oComment->init($iObjectId);
  777. return array(
  778. 'object_id' => $iObjectId,
  779. 'entry_sample' => '_cmt_txt_sample_comment_single',
  780. 'entry_url' => $oComment->getViewUrl($iParentId),
  781. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  782. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  783. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  784. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  785. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  786. );
  787. }
  788. /**
  789. * Entry post vote for Notifications module
  790. */
  791. public function serviceGetNotificationsVote($aEvent)
  792. {
  793. $CNF = &$this->_oConfig->CNF;
  794. $iContentId = (int)$aEvent['object_id'];
  795. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  796. if(empty($aContentInfo) || !is_array($aContentInfo))
  797. return array();
  798. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  799. if(!$oVote || !$oVote->isEnabled())
  800. return array();
  801. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  802. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  803. return array(
  804. 'entry_sample' => $CNF['T']['txt_sample_single'],
  805. 'entry_url' => $sEntryUrl,
  806. 'entry_caption' => $sEntryCaption,
  807. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  808. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  809. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  810. );
  811. }
  812. /**
  813. * Entry post vote for Notifications module
  814. */
  815. public function serviceGetNotificationsReaction($aEvent)
  816. {
  817. $CNF = &$this->_oConfig->CNF;
  818. $iContentId = (int)$aEvent['object_id'];
  819. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  820. if(empty($aContentInfo) || !is_array($aContentInfo))
  821. return array();
  822. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  823. if(!$oReaction || !$oReaction->isEnabled())
  824. return array();
  825. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  826. if(empty($aSubentry) || !is_array($aSubentry))
  827. return array();
  828. $aSubentrySampleParams = array();
  829. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  830. if(!empty($aReaction['title']))
  831. $aSubentrySampleParams[] = $aReaction['title'];
  832. else
  833. $aSubentrySampleParams[] = '_undefined';
  834. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  835. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  836. return array(
  837. 'entry_sample' => $CNF['T']['txt_sample_single'],
  838. 'entry_url' => $sEntryUrl,
  839. 'entry_caption' => $sEntryCaption,
  840. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  841. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  842. 'subentry_sample_params' => $aSubentrySampleParams,
  843. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  844. );
  845. }
  846. /**
  847. * Entry post score -> vote up for Notifications module
  848. */
  849. public function serviceGetNotificationsScoreUp($aEvent)
  850. {
  851. return $this->_serviceGetNotificationsScore('up', $aEvent);
  852. }
  853. /**
  854. * Entry post score -> vote up for Notifications module
  855. */
  856. public function serviceGetNotificationsScoreDown($aEvent)
  857. {
  858. return $this->_serviceGetNotificationsScore('down', $aEvent);
  859. }
  860. protected function _serviceGetNotificationsScore($sType, $aEvent)
  861. {
  862. $CNF = &$this->_oConfig->CNF;
  863. $iContentId = (int)$aEvent['object_id'];
  864. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  865. if(empty($aContentInfo) || !is_array($aContentInfo))
  866. return array();
  867. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  868. if(!$oScore || !$oScore->isEnabled())
  869. return array();
  870. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  871. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  872. return array(
  873. 'entry_sample' => $CNF['T']['txt_sample_single'],
  874. 'entry_url' => $sEntryUrl,
  875. 'entry_caption' => $sEntryCaption,
  876. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  877. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  878. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  879. );
  880. }
  881. /**
  882. * Data for Timeline module
  883. */
  884. public function serviceGetTimelineData()
  885. {
  886. $sModule = $this->_aModule['name'];
  887. return array(
  888. 'handlers' => array(
  889. 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' => ''),
  890. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  891. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  892. ),
  893. 'alerts' => array(
  894. array('unit' => $sModule, 'action' => 'added'),
  895. array('unit' => $sModule, 'action' => 'edited'),
  896. array('unit' => $sModule, 'action' => 'deleted'),
  897. )
  898. );
  899. }
  900. /**
  901. * Entry post for Timeline module
  902. */
  903. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  904. {
  905. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  906. if(empty($aContentInfo) || !is_array($aContentInfo))
  907. return false;
  908. $CNF = &$this->_oConfig->CNF;
  909. $iUserId = $this->getUserId();
  910. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  911. $iAuthorIdAbs = abs($iAuthorId);
  912. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id']))) && $iAuthorIdAbs != $iUserId)
  913. return false;
  914. //--- Views
  915. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  916. $aViews = array();
  917. if ($oViews && $oViews->isEnabled())
  918. $aViews = array(
  919. 'system' => $CNF['OBJECT_VIEWS'],
  920. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  921. 'count' => $aContentInfo['views']
  922. );
  923. //--- Votes
  924. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  925. $aVotes = array();
  926. if ($oVotes && $oVotes->isEnabled())
  927. $aVotes = array(
  928. 'system' => $CNF['OBJECT_VOTES'],
  929. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  930. 'count' => $aContentInfo['votes']
  931. );
  932. //--- Reactions
  933. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  934. $aReactions = array();
  935. if ($oReactions && $oReactions->isEnabled())
  936. $aReactions = array(
  937. 'system' => $CNF['OBJECT_REACTIONS'],
  938. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  939. 'count' => $aContentInfo['rvotes']
  940. );
  941. //--- Scores
  942. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  943. $aScores = array();
  944. if ($oScores && $oScores->isEnabled())
  945. $aScores = array(
  946. 'system' => $CNF['OBJECT_SCORES'],
  947. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  948. 'score' => $aContentInfo['score']
  949. );
  950. //--- Reports
  951. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  952. $aReports = array();
  953. if ($oReports && $oReports->isEnabled())
  954. $aReports = array(
  955. 'system' => $CNF['OBJECT_REPORTS'],
  956. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  957. 'count' => $aContentInfo['reports']
  958. );
  959. //--- Comments
  960. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  961. $aComments = array();
  962. if($oCmts && $oCmts->isEnabled())
  963. $aComments = array(
  964. 'system' => $CNF['OBJECT_COMMENTS'],
  965. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  966. 'count' => $aContentInfo['comments']
  967. );
  968. //--- Title & Description
  969. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  970. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  971. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  972. $iOwnerId = $iAuthorIdAbs;
  973. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  974. $iOwnerId = abs($aEvent['object_privacy_view']);
  975. $bCache = true;
  976. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  977. if(isset($aContent['_cache'])) {
  978. $bCache = (bool)$aContent['_cache'];
  979. unset($aContent['_cache']);
  980. }
  981. return array(
  982. '_cache' => $bCache,
  983. 'owner_id' => $iOwnerId,
  984. 'object_owner_id' => $iAuthorId,
  985. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  986. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  987. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  988. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  989. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  990. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  991. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  992. 'views' => $aViews,
  993. 'votes' => $aVotes,
  994. 'reactions' => $aReactions,
  995. 'scores' => $aScores,
  996. 'reports' => $aReports,
  997. 'comments' => $aComments,
  998. 'title' => $sTitle, //may be empty.
  999. 'description' => '' //may be empty.
  1000. );
  1001. }
  1002. public function serviceGetTimelinePostAllowedView($aEvent)
  1003. {
  1004. $iContentId = (int)$aEvent['object_id'];
  1005. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1006. if(empty($aContentInfo) || !is_array($aContentInfo))
  1007. return _t('_sys_txt_access_denied');
  1008. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1009. }
  1010. /**
  1011. * Check particular action permission without content
  1012. * @param $sAction action to check, for example: Browse, Add
  1013. * @param $iContentId content ID
  1014. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1015. */
  1016. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1017. {
  1018. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1019. if (!method_exists($this, $sMethod))
  1020. return _t('_sys_request_method_not_found_cpt');
  1021. return $this->$sMethod($isPerformAction);
  1022. }
  1023. /**
  1024. * Check particular action permission with content
  1025. * @param $sAction action to check, for example: View, Edit
  1026. * @param $iContentId content ID
  1027. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1028. */
  1029. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1030. {
  1031. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1032. return _t('_sys_request_page_not_found_cpt');
  1033. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1034. if (!method_exists($this, $sMethod))
  1035. return _t('_sys_request_method_not_found_cpt');
  1036. return $this->$sMethod($aContentInfo, $isPerformAction);
  1037. }
  1038. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1039. {
  1040. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1041. }
  1042. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1043. {
  1044. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1045. }
  1046. public function serviceGetContentOwnerProfileId ($iContentId)
  1047. {
  1048. $CNF = &$this->_oConfig->CNF;
  1049. // file owner must be author of the content or profile itself in case of profile based module
  1050. if ($iContentId) {
  1051. $sModule = $this->getName();
  1052. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1053. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1054. }
  1055. else {
  1056. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1057. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1058. }
  1059. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1060. }
  1061. else {
  1062. $iProfileId = bx_get_logged_profile_id();
  1063. }
  1064. return $iProfileId;
  1065. }
  1066. // ====== PERMISSION METHODS
  1067. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1068. {
  1069. if (!$iProfileId)
  1070. $iProfileId = $this->_iProfileId;
  1071. $CNF = &$this->_oConfig->CNF;
  1072. // moderator and owner always have access
  1073. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  1074. return CHECK_ACTION_RESULT_ALLOWED;
  1075. // check ACL
  1076. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  1077. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1078. return $aCheck[CHECK_ACTION_MESSAGE];
  1079. // check privacy
  1080. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  1081. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1082. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1083. return _t('_sys_access_denied_to_private_content');
  1084. }
  1085. // check alert to allow custom checks
  1086. $mixedResult = null;
  1087. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1088. if($mixedResult !== null)
  1089. return $mixedResult;
  1090. return CHECK_ACTION_RESULT_ALLOWED;
  1091. }
  1092. public function checkAllowedSetThumb ($iContentId = 0)
  1093. {
  1094. return CHECK_ACTION_RESULT_ALLOWED;
  1095. }
  1096. /**
  1097. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1098. */
  1099. public function checkAllowedBrowse ()
  1100. {
  1101. // check alert to allow custom checks
  1102. $mixedResult = null;
  1103. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1104. if($mixedResult !== null)
  1105. return $mixedResult;
  1106. return CHECK_ACTION_RESULT_ALLOWED;
  1107. }
  1108. /**
  1109. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1110. */
  1111. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1112. {
  1113. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1114. }
  1115. /**
  1116. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1117. */
  1118. public function checkAllowedAdd ($isPerformAction = false)
  1119. {
  1120. // check ACL
  1121. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1122. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1123. return $aCheck[CHECK_ACTION_MESSAGE];
  1124. return CHECK_ACTION_RESULT_ALLOWED;
  1125. }
  1126. /**
  1127. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1128. */
  1129. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1130. {
  1131. // moderator and owner always have access
  1132. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1133. return CHECK_ACTION_RESULT_ALLOWED;
  1134. return _t('_sys_txt_access_denied');
  1135. }
  1136. /**
  1137. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1138. */
  1139. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1140. {
  1141. // moderator always has access
  1142. if ($this->_isModerator($isPerformAction))
  1143. return CHECK_ACTION_RESULT_ALLOWED;
  1144. // check ACL
  1145. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1146. if (($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1147. return CHECK_ACTION_RESULT_ALLOWED;
  1148. return _t('_sys_txt_access_denied');
  1149. }
  1150. /**
  1151. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1152. */
  1153. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  1154. {
  1155. // admin always has access
  1156. if (isAdmin())
  1157. return CHECK_ACTION_RESULT_ALLOWED;
  1158. // check ACL
  1159. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1160. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1161. return $aCheck[CHECK_ACTION_MESSAGE];
  1162. return CHECK_ACTION_RESULT_ALLOWED;
  1163. }
  1164. /**
  1165. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1166. */
  1167. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1168. {
  1169. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1170. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1171. return CHECK_ACTION_RESULT_ALLOWED;
  1172. return _t('_sys_txt_access_denied');
  1173. }
  1174. /**
  1175. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1176. */
  1177. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1178. {
  1179. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1180. }
  1181. /**
  1182. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1183. */
  1184. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1185. {
  1186. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1187. }
  1188. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1189. {
  1190. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1191. return MsgBox($sMsg);
  1192. bx_import($sClassSearchResult, $this->_aModule);
  1193. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1194. $o = new $sClass($sMode, $aParams);
  1195. $o->setDesignBoxTemplateId($iDesignBox);
  1196. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1197. $o->setAjaxPaginate($bAjaxPaginate);
  1198. $o->setUnitParams(array('context' => $sMode));
  1199. if ($o->isError)
  1200. return '';
  1201. if ($s = $o->processing())
  1202. return $s;
  1203. else
  1204. return '';
  1205. }
  1206. // ====== COMMON METHODS
  1207. public function alertAfterAdd($aContentInfo) {}
  1208. public function alertAfterEdit($aContentInfo) {}
  1209. public function onPublished($iContentId) {}
  1210. public function onFailed($iContentId) {}
  1211. public function processMetasAdd($iContentId)
  1212. {
  1213. $CNF = &$this->_oConfig->CNF;
  1214. if(empty($CNF['OBJECT_METATAGS']))
  1215. return;
  1216. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1217. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1218. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1219. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1220. if(!$bContentInfo)
  1221. return;
  1222. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1223. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  1224. $sKey = 'FIELD_LOCATION';
  1225. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1226. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1227. if(!empty($aLocation) && is_array($aLocation))
  1228. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1229. }
  1230. $sKey = 'FIELD_LABELS';
  1231. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1232. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1233. if(!empty($aLabels) && is_array($aLabels))
  1234. foreach ($aLabels as $sLabel)
  1235. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1236. }
  1237. }
  1238. public function processMetasEdit($iContentId, $oForm)
  1239. {
  1240. $CNF = &$this->_oConfig->CNF;
  1241. if(empty($CNF['OBJECT_METATAGS']))
  1242. return;
  1243. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1244. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1245. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1246. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1247. if(!$bContentInfo)
  1248. return;
  1249. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1250. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  1251. $sKey = 'FIELD_LOCATION';
  1252. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1253. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1254. if(!empty($aLocation) && is_array($aLocation))
  1255. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1256. }
  1257. $sKey = 'FIELD_LABELS';
  1258. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1259. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1260. if(!empty($aLabels) && is_array($aLabels))
  1261. foreach ($aLabels as $sLabel)
  1262. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1263. }
  1264. }
  1265. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1266. {
  1267. if(empty($aTranscoders))
  1268. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1269. $CNF = &$this->_oConfig->CNF;
  1270. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1271. return false;
  1272. $iId = (int)$aContentInfo[$CNF[$sField]];
  1273. foreach($aTranscoders as $sTranscoder)
  1274. if(!empty($CNF[$sTranscoder]))
  1275. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1276. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1277. }
  1278. public function getProfileId()
  1279. {
  1280. return bx_get_logged_profile_id();
  1281. }
  1282. public function getProfileInfo($iUserId = 0)
  1283. {
  1284. $oProfile = $this->getObjectUser($iUserId);
  1285. $oAccount = null;
  1286. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1287. $oAccount = $oProfile->getAccountObject();
  1288. $bAccount = !empty($oAccount);
  1289. return array(
  1290. 'id' => $oProfile->id(),
  1291. 'name' => $oProfile->getDisplayName(),
  1292. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1293. 'link' => $oProfile->getUrl(),
  1294. 'icon' => $oProfile->getIcon(),
  1295. 'thumb' => $oProfile->getThumb(),
  1296. 'avatar' => $oProfile->getAvatar(),
  1297. 'unit' => $oProfile->getUnit(),
  1298. 'active' => $oProfile->isActive(),
  1299. );
  1300. }
  1301. public function getObjectUser($iUserId = 0)
  1302. {
  1303. bx_import('BxDolProfile');
  1304. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1305. return $oProfile;
  1306. }
  1307. public function getObjectFavorite($sSystem = '', $iId = 0)
  1308. {
  1309. $CNF = &$this->_oConfig->CNF;
  1310. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1311. $sSystem = $CNF['OBJECT_FAVORITES'];
  1312. if(empty($sSystem))
  1313. return false;
  1314. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1315. if(!$oFavorite || !$oFavorite->isEnabled())
  1316. return false;
  1317. return $oFavorite;
  1318. }
  1319. public function getUserId()
  1320. {
  1321. return isLogged() ? bx_get_logged_profile_id() : 0;
  1322. }
  1323. public function getUserIp()
  1324. {
  1325. return getVisitorIP();
  1326. }
  1327. public function getUserInfo($iUserId = 0)
  1328. {
  1329. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1330. return array(
  1331. $oProfile->getDisplayName(),
  1332. $oProfile->getUrl(),
  1333. $oProfile->getThumb(),
  1334. $oProfile->getUnit(),
  1335. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1336. );
  1337. }
  1338. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1339. {
  1340. $CNF = &$this->_oConfig->CNF;
  1341. // default visible settings
  1342. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1343. return false;
  1344. if (!empty($aItem['visibility_custom'])) {
  1345. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1346. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1347. return false;
  1348. }
  1349. // get custom function name to check menu item visibility
  1350. $sFuncCheckAccess = false;
  1351. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1352. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1353. // check custom visibility settings defined in module config class
  1354. if(!isset($aContentInfo))
  1355. $aContentInfo = array();
  1356. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1357. return false;
  1358. return true;
  1359. }
  1360. public function _isModerator ($isPerformAction = false)
  1361. {
  1362. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1363. }
  1364. // ====== PROTECTED METHODS
  1365. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1366. {
  1367. $iContentId = $this->_getContent($iContentId, false);
  1368. if($iContentId === false)
  1369. return false;
  1370. bx_import('FormsEntryHelper', $this->_aModule);
  1371. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1372. $oFormsHelper = new $sClass($this);
  1373. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1374. }
  1375. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1376. {
  1377. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1378. if($mixedContent === false)
  1379. return false;
  1380. list($iContentId, $aContentInfo) = $mixedContent;
  1381. return $this->_oTemplate->$sFunc($aContentInfo);
  1382. }
  1383. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1384. {
  1385. $sMode = array_shift($aArgs);
  1386. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1387. $this->_oTemplate->displayAccessDenied ($sMsg);
  1388. exit;
  1389. }
  1390. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1391. bx_import ($sClass, $this->_aModule);
  1392. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1393. $o = new $sClass($sMode, $aParams);
  1394. if ($o->isError)
  1395. $this->_oTemplate->displayPageNotFound ();
  1396. else
  1397. $o->outputRSS();
  1398. exit;
  1399. }
  1400. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  1401. {
  1402. if(!$iContentId)
  1403. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1404. if(!$iContentId)
  1405. return false;
  1406. if($sFuncGetContent === true)
  1407. $sFuncGetContent = 'getContentInfoById';
  1408. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1409. return $iContentId;
  1410. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1411. if(!$aContentInfo)
  1412. return false;
  1413. return array($iContentId, $aContentInfo);
  1414. }
  1415. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1416. {
  1417. $CNF = &$this->_oConfig->CNF;
  1418. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1419. //--- Image(s)
  1420. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1421. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1422. //--- Video(s)
  1423. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1424. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1425. //--- Files(s)
  1426. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1427. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1428. //--- Title
  1429. $sTitle = '';
  1430. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1431. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1432. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1433. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1434. //--- Text
  1435. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1436. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1437. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1438. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1439. }
  1440. return array(
  1441. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1442. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1443. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1444. 'url' => $sUrl,
  1445. 'title' => $sTitle,
  1446. 'text' => $sText,
  1447. 'images' => $aImages,
  1448. 'images_attach' => $aImagesAttach,
  1449. 'videos' => $aVideos,
  1450. 'videos_attach' => $aVideosAttach,
  1451. 'files' => $aFiles,
  1452. 'files_attach' => $aFilesAttach
  1453. );
  1454. }
  1455. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1456. {
  1457. $CNF = &$this->_oConfig->CNF;
  1458. $sImage = $sImageOrig = '';
  1459. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1460. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1461. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1462. }
  1463. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1464. if($sImage == '' && $bImageThumb)
  1465. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1466. if($sImageOrig == '' && $bImageThumb)
  1467. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1468. if(empty($sImage))
  1469. return array();
  1470. if($sImageOrig == '')
  1471. $sImageOrig = $sImage;
  1472. return array(
  1473. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1474. );
  1475. }
  1476. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1477. {
  1478. return array();
  1479. }
  1480. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1481. {
  1482. return array();
  1483. }
  1484. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1485. {
  1486. return array();
  1487. }
  1488. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1489. {
  1490. return array();
  1491. }
  1492. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1493. {
  1494. return array();
  1495. }
  1496. protected function _entityComments ($sObject, $iId = 0)
  1497. {
  1498. if (!$iId)
  1499. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1500. if (!$iId)
  1501. return false;
  1502. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1503. if (!$oCmts || !$oCmts->isEnabled())
  1504. return false;
  1505. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1506. }
  1507. protected function _getFields($iContentId)
  1508. {
  1509. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1510. if(empty($aContentInfo))
  1511. return array();
  1512. return BxDolContentInfo::formatFields($aContentInfo);
  1513. }
  1514. protected function _getFieldValue($sField, $iContentId)
  1515. {
  1516. $CNF = &$this->_oConfig->CNF;
  1517. if(empty($CNF[$sField]))
  1518. return false;
  1519. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1520. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1521. return false;
  1522. return $aContentInfo[$CNF[$sField]];
  1523. }
  1524. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1525. {
  1526. $CNF = &$this->_oConfig->CNF;
  1527. if(empty($sTranscoder) || empty($CNF[$sField]))
  1528. return false;
  1529. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1530. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1531. return false;
  1532. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1533. if(!$oImagesTranscoder)
  1534. return false;
  1535. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1536. }
  1537. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1538. {
  1539. if(!$bAsJson)
  1540. return $aResponse;
  1541. if(!empty($aAdditional) && is_array($aAdditional))
  1542. $aResponse = array_merge($aResponse, $aAdditional);
  1543. echoJson($aResponse);
  1544. exit;
  1545. }
  1546. }
  1547. /** @} */