BxBaseModGeneralModule.php 135 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517
  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. define('BX_BASE_MOD_GENERAL_STATUS_ACTIVE', 'active');
  12. define('BX_BASE_MOD_GENERAL_STATUS_HIDDEN', 'hidden');
  13. define('BX_BASE_MOD_GENERAL_STATUS_PENDING', 'pending');
  14. bx_import('BxDolAcl');
  15. /**
  16. * Base module class.
  17. */
  18. class BxBaseModGeneralModule extends BxDolModule
  19. {
  20. protected $_iProfileId;
  21. protected $_aSearchableNamesExcept;
  22. protected $_aFormParams;
  23. function __construct(&$aModule)
  24. {
  25. parent::__construct($aModule);
  26. $this->_iProfileId = bx_get_logged_profile_id();
  27. $this->_aSearchableNamesExcept = array(
  28. 'allow_view_to'
  29. );
  30. $this->_aFormParams = array(
  31. 'display' => false,
  32. 'dynamic_mode' => false,
  33. 'ajax_mode' => false,
  34. 'absolute_action_url' => false,
  35. 'visibility_autoselect' => false,
  36. 'context_id' => 0,
  37. 'custom' => array()
  38. );
  39. }
  40. // ====== ACTIONS METHODS
  41. public function isEntryActive($aContentInfo)
  42. {
  43. $CNF = &$this->_oConfig->CNF;
  44. $iProfileId = bx_get_logged_profile_id();
  45. if($aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId || $this->_isModerator())
  46. return true;
  47. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  48. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  49. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  50. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  51. if(in_array($iProfileId, $aAdmins))
  52. return true;
  53. }
  54. if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
  55. return false;
  56. if(isset($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active')
  57. return false;
  58. return true;
  59. }
  60. public function actionApprove()
  61. {
  62. $CNF = &$this->_oConfig->CNF;
  63. if(!isset($CNF['FIELD_STATUS_ADMIN']))
  64. return echoJson([]);
  65. $iContentId = (int)bx_get('content_id');
  66. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  67. if(empty($aContentInfo) || !is_array($aContentInfo) || $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  68. return echoJson([]);
  69. if(($mixedCheckResult = $this->checkAllowedApprove($aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED)
  70. return echoJson(['msg' => $mixedCheckResult]);
  71. $oForm = $this->_getApproveForm($iContentId, $aContentInfo);
  72. $oForm->initChecker();
  73. if(!$oForm->isSubmitted() || !$oForm->isValid()) {
  74. $sPopupId = $this->getName() . '_approve_' . $iContentId;
  75. $sPopupTitle = '_sys_manage_popup_approve_title';
  76. if(!empty($CNF['T']['txt_approve_popup_title']))
  77. $sPopupTitle = $CNF['T']['txt_approve_popup_title'];
  78. return echoJson(['popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $oForm->getCode(true))]);
  79. }
  80. if($oForm->getCleanValue('do_send')) {
  81. $aResult = [];
  82. if($this->_sendApproveMessage($iContentId, $aContentInfo, $oForm))
  83. $aResult = ['msg' => _t('_sys_manage_txt_sent')];
  84. else
  85. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  86. return echoJson($aResult);
  87. }
  88. if($oForm->getCleanValue('do_submit')) {
  89. $aResult = [];
  90. if($this->_oDb->updateEntriesBy([$CNF['FIELD_STATUS_ADMIN'] => BX_BASE_MOD_GENERAL_STATUS_ACTIVE], [$CNF['FIELD_ID'] => $iContentId])) {
  91. $this->checkAllowedApprove($aContentInfo, true);
  92. $this->onApprove($aContentInfo);
  93. /*
  94. * Process metas.
  95. * Note. It's essential to process metas a the very end,
  96. * because all data related to an entry should be already
  97. * processed and are ready to be passed to alert.
  98. */
  99. $this->processMetasAdd($iContentId);
  100. $aResult = ['msg' => _t('_sys_manage_txt_approved'), 'reload' => 1];
  101. }
  102. else
  103. $aResult = ['msg' => _t('_sys_manage_err_cannot_perform_action')];
  104. return echoJson($aResult);
  105. }
  106. }
  107. public function actionRss ()
  108. {
  109. $aArgs = func_get_args();
  110. $this->_rss($aArgs);
  111. }
  112. public function actionGetCreatePostForm()
  113. {
  114. $sName = $this->_oConfig->getName();
  115. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  116. $aParams = array_merge($this->_aFormParams, $aParams);
  117. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  118. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  119. if(empty($mixedResponse))
  120. return echoJson(array());
  121. else if(is_array($mixedResponse)) {
  122. $mixedResponse['module'] = $sName;
  123. return echoJson($mixedResponse);
  124. }
  125. return echoJson(array(
  126. 'module' => $sName,
  127. 'content' => $mixedResponse
  128. ));
  129. }
  130. public function actionGetNotes()
  131. {
  132. $CNF = &$this->_oConfig->CNF;
  133. if(empty($CNF['OBJECT_NOTES']))
  134. return echoJson(array());
  135. $iContentId = (int)bx_get('content_id');
  136. $oCmtsNotes = BxDolCmts::getObjectInstance($CNF['OBJECT_NOTES'], $iContentId, true, $this->_oTemplate);
  137. $aCmtsNotes = $oCmtsNotes->getCommentsBlock(array(), array('in_designbox' => false));
  138. if(empty($aCmtsNotes) || !is_array($aCmtsNotes))
  139. return echoJson(array());
  140. $sPopupId = $this->getName() . '_notes_' . $iContentId;
  141. $sPopupTitle = !empty($CNF['T']['txt_cmts_notes_popup_view_title']) ? $CNF['T']['txt_cmts_notes_popup_view_title'] : '_cmt_nts_popup_view_title';
  142. echoJson(array('popup' => BxTemplFunctions::getInstance()->popupBox($sPopupId, _t($sPopupTitle), $aCmtsNotes['content'])));
  143. }
  144. public function actionNested()
  145. {
  146. $sAction = bx_get('a');
  147. $sMethodName = 'subaction' . ucfirst($sAction);
  148. if (!method_exists($this, $sMethodName)) {
  149. return;
  150. }
  151. $this->$sMethodName();
  152. }
  153. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  154. {
  155. $oTemplate = BxDolTemplate::getInstance();
  156. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  157. if(empty($aContentInfo))
  158. $oTemplate->getEmbed(false);
  159. if(empty($sUnitTemplate))
  160. $sUnitTemplate = 'unit_gallery.html';
  161. $CNF = &$this->_oConfig->CNF;
  162. if(!empty($CNF['OBJECT_VIEWS'])) {
  163. $oView = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $iContentId);
  164. if($oView && $oView->isEnabled())
  165. $oView->doView();
  166. }
  167. $oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate) . $sAddCode);
  168. }
  169. public function subactionDelete()
  170. {
  171. header('Content-type: text/html; charset=utf-8');
  172. $iNestedId = (int)bx_get('id');
  173. $sNestedForm = bx_get('s');
  174. $oForm = BxDolForm::getObjectInstance($sNestedForm, $sNestedForm);
  175. if (!$oForm){
  176. echo _t('_sys_request_page_not_found_cpt');
  177. return;
  178. }
  179. $aNested = $this->_oDb->getNestedBy(array('type' => 'id', 'id' => $iNestedId, 'key_name' => $oForm->aParams['db']['key']), $oForm->aParams['db']['table']);
  180. if (empty($aNested)){
  181. echo _t('_sys_request_page_not_found_cpt');
  182. return;
  183. }
  184. $aContentInfo = $this->_oDb->getContentInfoById ($aNested['content_id']);
  185. if (!$aContentInfo){
  186. echo _t('_sys_request_page_not_found_cpt');
  187. return;
  188. }
  189. elseif (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedEdit ($aContentInfo))) {
  190. echo $sMsg;
  191. }
  192. elseif (!$this->_oDb->deleteNestedById($iNestedId, $oForm->aParams['db']['key'], $oForm->aParams['db']['table'])) {
  193. echo _t('_sys_txt_error_occured');
  194. }
  195. else {
  196. echo 'ok';
  197. }
  198. }
  199. /**
  200. * Get possible recipients for start conversation form
  201. */
  202. public function actionAjaxGetProfiles ()
  203. {
  204. $sTerm = bx_get('term');
  205. $a = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  206. header('Content-Type:text/javascript; charset=utf-8');
  207. echo(json_encode($a));
  208. }
  209. // ====== SERVICE METHODS
  210. public function serviceIsBadgesAvaliable()
  211. {
  212. if(!isAdmin() && !$this->_isAdministrator())
  213. return false;
  214. $aBadges = BxDolBadges::getInstance()->getData([
  215. 'type' => 'by_module&object',
  216. 'object_id' => 0,
  217. 'module' => $this->getName()
  218. ]);
  219. return count($aBadges) > 0 ? true : false;
  220. }
  221. public function serviceGetSafeServices()
  222. {
  223. return array(
  224. // other
  225. 'ModuleIcon' => '',
  226. 'GetLink' => '',
  227. // browse
  228. 'GetSearchResultUnit' => '',
  229. 'Browse' => '',
  230. 'BrowseFeatured' => '',
  231. 'BrowseFavorite' => '',
  232. // forms
  233. 'GetCreatePostForm' => '',
  234. 'EntityEdit' => '',
  235. 'EntityDelete' => '',
  236. // page blocks
  237. 'EntityTextBlock' => '',
  238. 'EntityInfo' => '',
  239. 'EntityInfoFull' => '',
  240. 'EntityInfoExtended' => '',
  241. 'EntityLocation' => '',
  242. 'EntityComments' => '',
  243. 'EntityAttachments' => '',
  244. 'CategoriesMultiList' => '',
  245. // menu
  246. 'EntityAllActions' => '',
  247. 'EntityActions' => '',
  248. 'EntitySocialSharing' => '',
  249. 'MyEntriesActions' => '',
  250. );
  251. }
  252. /**
  253. * @page service Service Calls
  254. * @section bx_base_general Base General
  255. * @subsection bx_base_general-other Other
  256. * @subsubsection bx_base_general-module_icon module_icon
  257. *
  258. * @code bx_srv('bx_posts', 'module_icon', [...]); @endcode
  259. *
  260. * Get module icon as CSS class name with FontAwesome icon name class and color class
  261. *
  262. * @see BxBaseModGeneralModule::serviceModuleIcon
  263. */
  264. /**
  265. * @ref bx_base_general-module_icon "module_icon"
  266. */
  267. public function serviceModuleIcon ()
  268. {
  269. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  270. }
  271. public function serviceGetAuthor ($iContentId)
  272. {
  273. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  274. return $mixedResult !== false ? (int)$mixedResult : 0;
  275. }
  276. public function serviceGetPrivacyView ($iContentId)
  277. {
  278. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  279. }
  280. public function serviceGetDateAdded ($iContentId)
  281. {
  282. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  283. return $mixedResult !== false ? (int)$mixedResult : 0;
  284. }
  285. public function serviceGetDateChanged ($iContentId)
  286. {
  287. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  288. return $mixedResult !== false ? (int)$mixedResult : 0;
  289. }
  290. /**
  291. * @page service Service Calls
  292. * @section bx_base_general Base General
  293. * @subsection bx_base_general-other Other
  294. * @subsubsection bx_base_general-get_link get_link
  295. *
  296. * @code bx_srv('bx_posts', 'get_link', [...]); @endcode
  297. *
  298. * Get URL for the specified content.
  299. * @param $iContentId content id
  300. *
  301. * @see BxBaseModGeneralModule::serviceGetLink
  302. */
  303. /**
  304. * @ref bx_base_general-get_link "get_link"
  305. */
  306. public function serviceGetLink ($iContentId)
  307. {
  308. $CNF = &$this->_oConfig->CNF;
  309. if(empty($CNF['URI_VIEW_ENTRY']))
  310. return '';
  311. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  312. if(empty($aContentInfo))
  313. return '';
  314. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  315. }
  316. public function serviceGetTitle ($iContentId)
  317. {
  318. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  319. return $mixedResult !== false ? $mixedResult : '';
  320. }
  321. public function serviceGetText ($iContentId)
  322. {
  323. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  324. if (false === $mixedResult)
  325. return '';
  326. $CNF = &$this->_oConfig->CNF;
  327. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  328. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  329. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  330. }
  331. return $mixedResult;
  332. }
  333. public function serviceGetEmbed ($iContentId)
  334. {
  335. $sTitle = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  336. return $this->_oTemplate->parseHtmlByName('embed.html', [
  337. 'title' => $sTitle,
  338. 'url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . $iContentId . '/'
  339. ]);
  340. }
  341. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  342. {
  343. $CNF = &$this->_oConfig->CNF;
  344. $aContentInfo = $this->_getFields($iContentId);
  345. if(empty($aContentInfo))
  346. return array();
  347. if(!$bSearchableFieldsOnly)
  348. return $aContentInfo;
  349. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  350. return array();
  351. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  352. if(empty($aFields))
  353. return array();
  354. $aResult = array();
  355. foreach($aFields as $sField)
  356. if(isset($aContentInfo[$sField]))
  357. $aResult[$sField] = $aContentInfo[$sField];
  358. return $aResult;
  359. }
  360. /**
  361. * @page service Service Calls
  362. * @section bx_base_general Base General
  363. * @subsection bx_base_general-browsing Browsing
  364. * @subsubsection bx_base_general-get_search_result_unit get_search_result_unit
  365. *
  366. * @code bx_srv('bx_posts', 'get_search_result_unit', [3,"unit_gallery.html"]); @endcode
  367. *
  368. * Get browsing unit for the specified content
  369. * @param $iContentId content id
  370. * @param $sUnitTemplate unit template, such as: unit_full.html, unit_gallery.html, unit_live_search.html
  371. *
  372. * @see BxBaseModGeneralModule::serviceGetSearchResultUnit
  373. */
  374. /**
  375. * @ref bx_base_general-get_search_result_unit "get_search_result_unit"
  376. */
  377. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  378. {
  379. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  380. if(empty($aContentInfo))
  381. return '';
  382. if(empty($sUnitTemplate))
  383. $sUnitTemplate = 'unit.html';
  384. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  385. }
  386. public function serviceGetAll ($aParams = array())
  387. {
  388. if(empty($aParams) || !is_array($aParams))
  389. $aParams = array('type' => 'all');
  390. return $this->_oDb->getEntriesBy($aParams);
  391. }
  392. public function serviceGetAllByAuthor ($iProfileId)
  393. {
  394. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  395. }
  396. public function serviceGetSortableFieldsExtended($aInputsAdd = array())
  397. {
  398. $CNF = &$this->_oConfig->CNF;
  399. if(empty($CNF['OBJECT_FORM_ENTRY']))
  400. return array();
  401. $aResult = array();
  402. $aSortableFields = [];
  403. $aDisplays = [];
  404. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  405. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'];
  406. }
  407. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  408. $aDisplays[] = $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'];
  409. }
  410. $aInputsAll = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY']);
  411. foreach($aInputsAll as $aInput){
  412. $aInputsAll[$aInput['name']] = $aInput;
  413. }
  414. $aInputs = BxDolFormQuery::getFormInputs($CNF['OBJECT_FORM_ENTRY'], $aDisplays);
  415. foreach($aInputs as $aInput){
  416. $aInputs[$aInput['name']] = $aInput;
  417. if ($aInput['type'] == 'text'){
  418. $aSortableFields[] = $aInput['name'];
  419. }
  420. }
  421. if(!empty($CNF['FIELD_ADDED']) && isset($aInputsAll[$CNF['FIELD_ADDED']])){
  422. $aSortableFields[] = $CNF['FIELD_ADDED'];
  423. }
  424. if(!empty($CNF['FIELD_CHANGED']) && isset($aInputsAll[$CNF['FIELD_CHANGED']])){
  425. $aSortableFields[] = $CNF['FIELD_CHANGED'];
  426. }
  427. foreach($aSortableFields as $sSortableField){
  428. $aResult[$sSortableField . '_asc'] = [
  429. 'name' => $sSortableField,
  430. 'caption' => $aInputsAll[$sSortableField]['caption'],
  431. 'direction' => 'asc'
  432. ];
  433. $aResult[$sSortableField . '_desc'] = [
  434. 'name' => $sSortableField,
  435. 'caption' => $aInputsAll[$sSortableField]['caption'],
  436. 'direction' => 'desc'
  437. ];
  438. }
  439. return $aResult;
  440. }
  441. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  442. {
  443. $CNF = &$this->_oConfig->CNF;
  444. if(empty($CNF['OBJECT_FORM_ENTRY']))
  445. return array();
  446. $aResult = array();
  447. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  448. $aResult[$CNF['FIELD_AUTHOR']] = array(
  449. 'type' => 'text_auto',
  450. 'caption' => $CNF['T']['form_field_author'],
  451. 'info' => '',
  452. 'value' => '',
  453. 'values' => '',
  454. 'pass' => ''
  455. );
  456. $aInputs = array();
  457. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  458. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  459. $aInputs = array_merge($aInputs, $oForm->aInputs);
  460. }
  461. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  462. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  463. $aInputs = array_merge($aInputs, $oForm->aInputs);
  464. }
  465. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  466. $aInputs = array_merge($aInputs, $aInputsAdd);
  467. foreach($aInputs as $aInput){
  468. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  469. $aField = array(
  470. 'type' => $aInput['type'],
  471. 'caption_system' => $aInput['caption_system_src'],
  472. 'caption' => $aInput['caption_src'],
  473. 'info' => $aInput['info_src'],
  474. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  475. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  476. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  477. );
  478. if(isset($aInput['search_type']))
  479. $aField['search_type'] = $aInput['search_type'];
  480. if(isset($aInput['search_operator']))
  481. $aField['search_operator'] = $aInput['search_operator'];
  482. $aResult[$aInput['name']] = $aField;
  483. }
  484. }
  485. return $aResult;
  486. }
  487. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0, $bFilterMode = false)
  488. {
  489. if((empty($aParams) || !is_array($aParams)) && !$bFilterMode)
  490. return array();
  491. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  492. }
  493. public function serviceGetSearchableFields ($aInputsAdd = array())
  494. {
  495. $CNF = $this->_oConfig->CNF;
  496. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  497. return array();
  498. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  499. if(!$oForm)
  500. return array();
  501. $aInputs = $oForm->aInputs;
  502. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  503. $aInputs = array_merge($aInputs, $aInputsAdd);
  504. $aTextTypes = array('text', 'textarea');
  505. $aTextFields = array();
  506. foreach($aInputs as $r)
  507. if(in_array($r['type'], $aTextTypes))
  508. $aTextFields[$r['name']] = $r['caption'];
  509. return $aTextFields;
  510. }
  511. public function serviceManageTools($sType = 'common')
  512. {
  513. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  514. if(!$oGrid)
  515. return '';
  516. $CNF = &$this->_oConfig->CNF;
  517. $mixedMenu = '';
  518. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  519. $oPermalink = BxDolPermalinks::getInstance();
  520. $aMenuItems = array();
  521. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  522. $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);
  523. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  524. $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);
  525. if(count($aMenuItems) > 1) {
  526. $mixedMenu = new BxTemplMenu(array(
  527. 'template' => 'menu_block_submenu_ver.html',
  528. 'menu_items' => $aMenuItems
  529. ), $this->_oTemplate);
  530. $mixedMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  531. }
  532. }
  533. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  534. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  535. }
  536. $this->_oTemplate->addCss(array('manage_tools.css'));
  537. $this->_oTemplate->addJs(array('manage_tools.js'));
  538. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  539. return array(
  540. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  541. 'menu' => $mixedMenu
  542. );
  543. }
  544. public function serviceGetMenuAddonManageTools()
  545. {
  546. return 0;
  547. }
  548. public function serviceGetMenuAddonManageToolsProfileStats()
  549. {
  550. return 0;
  551. }
  552. /**
  553. * @page service Service Calls
  554. * @section bx_base_general Base General
  555. * @subsection bx_base_general-browsing Browsing
  556. * @subsubsection bx_base_general-browse browse
  557. *
  558. * @code bx_srv('bx_posts', 'browse', [...]); @endcode
  559. * @code {{~bx_posts:browse[{"mode":"author", "params":{"author":"10"}}]~}} @endcode
  560. *
  561. * Universal browse method.
  562. * @param $aParams custom browse params, possible params are the following:
  563. * - mode - browse mode, such as 'recent', 'featured', etc
  564. * - params - custom params to browse method, for example 'unit_view' can be passed here
  565. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  566. * - empty_message - display or not "empty" message when there is no content
  567. * - ajax_paginate - use AJAX paginate or not
  568. *
  569. * @see BxBaseModGeneralModule::serviceBrowse
  570. */
  571. /**
  572. * @ref bx_base_general-browse "browse"
  573. */
  574. public function serviceBrowse ($aParams = array())
  575. {
  576. unset($aParams['params']['condition']);
  577. return $this->serviceBrowseWithCondition ($aParams);
  578. }
  579. public function serviceBrowseWithCondition ($aParams = array())
  580. {
  581. $aDefaults = array (
  582. 'mode' => 'recent',
  583. 'params' => false,
  584. 'design_box' => BX_DB_PADDING_DEF,
  585. 'empty_message' => false,
  586. 'ajax_paginate' => true,
  587. 'class_search_result' => 'SearchResult'
  588. );
  589. $aParams = array_merge($aDefaults, $aParams);
  590. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate'], $aParams['class_search_result']);
  591. }
  592. /**
  593. * @page service Service Calls
  594. * @section bx_base_general Base General
  595. * @subsection bx_base_general-browsing Browsing
  596. * @subsubsection bx_base_general-browse_featured browse_featured
  597. *
  598. * @code bx_srv('bx_posts', 'browse_featured', [...]); @endcode
  599. *
  600. * Display featured entries
  601. * @param $sUnitView browsing unity view,
  602. * such as: full, extended, gallery, showcase
  603. * @param $bEmptyMessage display or not "empty" message when there is no content
  604. * @param $bAjaxPaginate use AJAX paginate or not
  605. *
  606. * @see BxBaseModGeneralModule::serviceBrowseFeatured
  607. */
  608. /**
  609. * @ref bx_base_general-browse_featured "browse_featured"
  610. */
  611. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  612. {
  613. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  614. }
  615. /**
  616. * @page service Service Calls
  617. * @section bx_base_general Base General
  618. * @subsection bx_base_general-browsing Browsing
  619. * @subsubsection bx_base_general-browse_favorite browse_favorite
  620. *
  621. * @code bx_srv('bx_posts', 'browse_favorite', [...]); @endcode
  622. *
  623. * Display entries which were added to favorite list by some member
  624. * @param $iProfileId profile ID
  625. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  626. *
  627. * @see BxBaseModGeneralModule::serviceBrowseFavorite BxBaseModGeneralModule::serviceBrowse
  628. */
  629. /**
  630. * @ref bx_base_general-browse_favorite "browse_favorite"
  631. */
  632. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  633. {
  634. $oProfile = null;
  635. if((int)$iProfileId)
  636. $oProfile = BxDolProfile::getInstance($iProfileId);
  637. if(!$oProfile && bx_get('profile_id') !== false)
  638. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  639. if(!$oProfile)
  640. $oProfile = BxDolProfile::getInstance();
  641. if(!$oProfile)
  642. return '';
  643. $bEmptyMessage = true;
  644. if(isset($aParams['empty_message'])) {
  645. $bEmptyMessage = (bool)$aParams['empty_message'];
  646. unset($aParams['empty_message']);
  647. }
  648. if(bx_get('list_id') !== false && !isset($aParams['list_id']))
  649. $aParams['list_id'] = (int) bx_get('list_id');
  650. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  651. }
  652. /**
  653. * @page service Service Calls
  654. * @section bx_base_general Base General
  655. * @subsection bx_base_general-browsing Browsing
  656. * @subsubsection bx_base_general-browse_favorite_lists browse_favorite_lists
  657. *
  658. * @code bx_srv('bx_posts', 'browse_favorite_lists', [...]); @endcode
  659. *
  660. * Display entries which were added to favorite lists grouped by lists by some member
  661. * @param $iProfileId profile ID
  662. * @param $aParams additional browse params, see BxBaseModGeneralModule::serviceBrowse
  663. *
  664. * @see BxBaseModGeneralModule::serviceBrowseFavoriteLists BxBaseModGeneralModule::serviceBrowse
  665. */
  666. /**
  667. * @ref bx_base_general-browse_favorite_lists "browse_favorite_lists"
  668. */
  669. public function serviceBrowseFavoriteLists ($iProfileId = 0, $aParams = array())
  670. {
  671. $CNF = &$this->_oConfig->CNF;
  672. $oProfile = null;
  673. if((int)$iProfileId)
  674. $oProfile = BxDolProfile::getInstance($iProfileId);
  675. if(!$oProfile && bx_get('profile_id') !== false)
  676. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  677. if(!$oProfile)
  678. $oProfile = BxDolProfile::getInstance();
  679. if(!$oProfile)
  680. return '';
  681. $iStart = (bx_get('list_start') !== false ? (int)bx_get('list_start') : 0);
  682. $iPerPage = (int)getParam($CNF['PARAM_PER_PAGE_FOR_FAVORITES_LISTS']);
  683. return $this->_oTemplate->getFavoriteList($oProfile, $iStart, $iPerPage, $aParams);
  684. }
  685. /**
  686. * @page service Service Calls
  687. * @section bx_base_general Base General
  688. * @subsection bx_base_general-browsing Browsing
  689. * @subsubsection bx_base_general-browse_favorite_list_actions browse_favorite_list_actions
  690. *
  691. * @code bx_srv('bx_posts', 'browse_favorite_list_actions', [...]); @endcode
  692. *
  693. * Display menu actions for favorite lists
  694. *
  695. * @see BxBaseModGeneralModule::serviceFavoritesListActions
  696. */
  697. /**
  698. * @ref bx_base_general-browse_favorite_list_actions "browse_favorite_list_actions"
  699. */
  700. public function serviceFavoritesListActions()
  701. {
  702. $iListId = 0;
  703. if(bx_get('list_id') !== false)
  704. $iListId = (int) bx_get('list_id');
  705. $oProfile = null;
  706. if(bx_get('profile_id') !== false)
  707. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  708. if(!$oProfile)
  709. return false;
  710. $CNF = &$this->_oConfig->CNF;
  711. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  712. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  713. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  714. return false;
  715. $sRv = '';
  716. if (!empty($aList) && $oFavorite->isAllowedEditList($aList['author_id'])){
  717. $aMarkers = array(
  718. 'js_object' => $oFavorite->getJsObjectName(),
  719. 'list_id' => $iListId,
  720. );
  721. $oMenu = BxDolMenu::getObjectInstance('sys_favorite_list');
  722. $oMenu->addMarkers($aMarkers);
  723. $sMenu = $oMenu->getCode();
  724. $sRv .= $sMenu . $oFavorite->getJsScript();
  725. }
  726. $aMarkers = array(
  727. 'id' => $iListId,
  728. 'module' => $this->_aModule['name'],
  729. 'url' => $this->_getFavoriteListUrl($iListId, $oProfile->id()),
  730. 'title' => $iListId > 0 ? $aList['title'] : _t('_sys_txt_default_favorite_list')
  731. );
  732. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  733. $oMenu->addMarkers($aMarkers);
  734. $sRv .= $sMenu = $oMenu->getCode();
  735. return $sRv;
  736. }
  737. /**
  738. * @page service Service Calls
  739. * @section bx_base_general Base General
  740. * @subsection bx_base_general-menu Menu
  741. * @subsubsection bx_base_general-favorites_list_info favorites_list_info
  742. *
  743. * @code bx_srv('bx_posts', 'favorites_list_info', [...]); @endcode
  744. *
  745. * Favorites list info
  746. * @param $aParams array with additional custom params
  747. * which may overwrite some default values
  748. *
  749. * @see BxBaseModGeneralModule::serviceFavoritesListInfo
  750. */
  751. /**
  752. * @ref bx_base_general-favorites_list_info "favorites_list_info"
  753. */
  754. public function serviceFavoritesListInfo($aParams = array())
  755. {
  756. $CNF = &$this->_oConfig->CNF;
  757. $iListId = 0;
  758. if(bx_get('list_id') !== false)
  759. $iListId = (int) bx_get('list_id');
  760. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  761. $aList = $oFavorite->getQueryObject()->getList(array('type' => 'id', 'list_id' => $iListId));
  762. if($iListId != 0 && (empty($aList) || !is_array($aList)))
  763. return false;
  764. $oProfile = null;
  765. if(bx_get('profile_id') !== false)
  766. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  767. if(!$oProfile)
  768. return false;
  769. return $this->_oTemplate->getFavoritesListInfo($aList, $oProfile);
  770. }
  771. /**
  772. * Display entries posted into particular context
  773. * @return HTML string
  774. */
  775. public function serviceBrowseContext ($iProfileId = 0, $aParams = array())
  776. {
  777. return $this->_serviceBrowseWithParam ('context', 'profile_id', $iProfileId, $aParams);
  778. }
  779. public function _serviceBrowseWithParam ($sParamName, $sParamGet, $sParamVal, $aParams = array())
  780. {
  781. if(!$sParamVal)
  782. $sParamVal = bx_process_input(bx_get($sParamGet), BX_DATA_INT);
  783. if(!$sParamVal)
  784. return '';
  785. $bEmptyMessage = true;
  786. if(isset($aParams['empty_message'])) {
  787. $bEmptyMessage = (bool)$aParams['empty_message'];
  788. unset($aParams['empty_message']);
  789. }
  790. $bAjaxPaginate = true;
  791. if(isset($aParams['ajax_paginate'])) {
  792. $bAjaxPaginate = (bool)$aParams['ajax_paginate'];
  793. unset($aParams['ajax_paginate']);
  794. }
  795. return $this->_serviceBrowse ($sParamName, array_merge(array($sParamName => $sParamVal), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  796. }
  797. public function serviceFormsHelper ()
  798. {
  799. bx_import('FormsEntryHelper', $this->_aModule);
  800. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  801. return new $sClass($this);
  802. }
  803. /**
  804. * Add entry using provided fields' values.
  805. * @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
  806. */
  807. public function serviceEntityAdd ($iProfile, $aValues, $sDisplay = false)
  808. {
  809. bx_import('FormsEntryHelper', $this->_aModule);
  810. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  811. $oFormsHelper = new $sClass($this);
  812. return $oFormsHelper->addData($iProfile, $aValues, $sDisplay);
  813. }
  814. /**
  815. * Perform redirect after content creation
  816. * @return nothing, rediret header is sent
  817. */
  818. public function serviceRedirectAfterAdd($aContentInfo)
  819. {
  820. bx_import('FormsEntryHelper', $this->_aModule);
  821. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  822. $oFormsHelper = new $sClass($this);
  823. $oFormsHelper->redirectAfterAdd($aContentInfo);
  824. }
  825. /**
  826. * Get form object for add, edit, view or delete the content
  827. * @param $sType 'add', 'edit', 'view' or 'delete'
  828. * @param $aParams optional array with parameters(display name, etc)
  829. * @return form object or false on error
  830. */
  831. public function serviceGetObjectForm ($sType, $aParams = array())
  832. {
  833. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  834. return false;
  835. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  836. $bContext = $mixedContextId !== false;
  837. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  838. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  839. return false;
  840. $CNF = &$this->_oConfig->CNF;
  841. bx_import('FormsEntryHelper', $this->_aModule);
  842. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  843. $oFormsHelper = new $sClass($this);
  844. $sParamsKey = 'ajax_mode';
  845. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  846. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  847. $sParamsKey = 'absolute_action_url';
  848. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  849. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  850. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  851. $sFunc = 'getObjectForm' . ucfirst($sType);
  852. $oForm = $oFormsHelper->$sFunc($sDisplay);
  853. $sKey = 'FIELD_ALLOW_VIEW_TO';
  854. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  855. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  856. if(!$bContext || $bContextOwner) {
  857. $iGc = 0;
  858. $iKeyGh = false;
  859. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  860. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  861. if($iKeyGh !== false && $iGc == 0) {
  862. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  863. $iKeyGh = false;
  864. if($aValue['type'] == 'group_end')
  865. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  866. }
  867. if($aValue['type'] == 'group_header') {
  868. $iGc = 0;
  869. $iKeyGh = $iKey;
  870. }
  871. continue;
  872. }
  873. //--- Show 'Public' privacy group only in Public post form.
  874. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  875. $iGc += 1;
  876. continue;
  877. }
  878. //--- Show a default privacy groups in Profile (for Owner) post form.
  879. if($bContextOwner && ((int)$aValue['key'] >= 0 || $mixedContextId == $aValue['key'])) {
  880. $iGc += 1;
  881. continue;
  882. }
  883. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  884. }
  885. }
  886. else {
  887. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  888. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  889. }
  890. }
  891. bx_alert('system', 'get_object_form', 0, 0, array(
  892. 'module' => $this->_oConfig->getName(),
  893. 'type' => $sType,
  894. 'params' => $aParams,
  895. 'form' => &$oForm
  896. ));
  897. return $oForm;
  898. }
  899. /**
  900. *
  901. *
  902. * Create entry form
  903. * @return HTML string
  904. */
  905. public function serviceEntityCreate ($sParams = false)
  906. {
  907. $bParamsArray = is_array($sParams);
  908. $sDisplay = is_string($sParams) ? $sParams : false;
  909. if($bParamsArray && !empty($sParams['display']))
  910. $sDisplay = $sParams['display'];
  911. bx_import('FormsEntryHelper', $this->_aModule);
  912. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  913. $oFormsHelper = new $sClass($this);
  914. if($bParamsArray && isset($sParams['dynamic_mode']))
  915. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  916. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  917. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  918. echoJson($mixedResult);
  919. exit;
  920. }
  921. return $mixedResult;
  922. }
  923. /**
  924. * @page service Service Calls
  925. * @section bx_base_general Base General
  926. * @subsection bx_base_general-forms Forms
  927. * @subsubsection bx_base_general-get_create_post_form get_create_post_form
  928. *
  929. * @code bx_srv('bx_posts', 'get_create_post_form'); @endcode
  930. *
  931. * Get content creation form
  932. * @param $aParams additional parameters array:
  933. * context_id, ajax_mode, absolute_action_url, displays
  934. *
  935. * @see BxBaseModGeneralModule::serviceGetCreatePostForm
  936. */
  937. /**
  938. * @ref bx_base_general-get_create_post_form "get_create_post_form"
  939. */
  940. public function serviceGetCreatePostForm($aParams = [])
  941. {
  942. $aParams = array_merge($this->_aFormParams, $aParams);
  943. if($aParams['context_id'] !== false && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($aParams['context_id']))))
  944. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $this->getName()]) !== CHECK_ACTION_RESULT_ALLOWED)
  945. return '';
  946. $oForm = $this->serviceGetObjectForm('add', $aParams);
  947. if(!$oForm)
  948. return '';
  949. return $this->serviceEntityCreate($aParams);
  950. }
  951. /**
  952. * @page service Service Calls
  953. * @section bx_base_general Base General
  954. * @subsection bx_base_general-forms Forms
  955. * @subsubsection bx_base_general-entity_edit entity_edit
  956. *
  957. * @code bx_srv('bx_posts', 'entity_edit', [...]); @endcode
  958. *
  959. * Get content edit form
  960. * @param $iContentId content ID
  961. * @param $sDisplay optional form display name
  962. *
  963. * @see BxBaseModGeneralModule::serviceEntityEdit
  964. */
  965. /**
  966. * @ref bx_base_general-entity_edit "entity_edit"
  967. */
  968. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  969. {
  970. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  971. }
  972. /**
  973. * @page service Service Calls
  974. * @section bx_base_general Base General
  975. * @subsection bx_base_general-forms Forms
  976. * @subsubsection bx_base_general-entity_delete entity_delete
  977. *
  978. * @code bx_srv('bx_posts', 'entity_delete', [...]); @endcode
  979. *
  980. * Get content delete form
  981. * @param $iContentId content ID
  982. *
  983. * @see BxBaseModGeneralModule::serviceEntityDelete
  984. */
  985. /**
  986. * @ref bx_base_general-entity_delete "entity_delete"
  987. */
  988. public function serviceEntityDelete ($iContentId = 0)
  989. {
  990. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  991. }
  992. /**
  993. * @page service Service Calls
  994. * @section bx_base_general Base General
  995. * @subsection bx_base_general-page_blocks Page Blocks
  996. * @subsubsection bx_base_general-entity_text_block entity_text_block
  997. *
  998. * @code bx_srv('bx_posts', 'entity_text_block', [...]); @endcode
  999. *
  1000. * Get content text/description
  1001. * @param $iContentId content ID
  1002. *
  1003. * @see BxBaseModGeneralModule::serviceEntityTextBlock
  1004. */
  1005. /**
  1006. * @ref bx_base_general-entity_text_block "entity_text_block"
  1007. */
  1008. public function serviceEntityTextBlock ($iContentId = 0)
  1009. {
  1010. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  1011. }
  1012. /**
  1013. * @page service Service Calls
  1014. * @section bx_base_general Base General
  1015. * @subsection bx_base_general-page_blocks Page Blocks
  1016. * @subsubsection bx_base_general-entity_info entity_info
  1017. *
  1018. * @code bx_srv('bx_posts', 'entity_info', [...]); @endcode
  1019. *
  1020. * Get content info
  1021. * @param $iContentId content ID
  1022. *
  1023. * @see BxBaseModGeneralModule::serviceEntityInfo
  1024. */
  1025. /**
  1026. * @ref bx_base_general-entity_info "entity_info"
  1027. */
  1028. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  1029. {
  1030. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  1031. }
  1032. /**
  1033. * @page service Service Calls
  1034. * @section bx_base_general Base General
  1035. * @subsection bx_base_general-page_blocks Page Blocks
  1036. * @subsubsection bx_base_general-entity_info_full entity_info_full
  1037. *
  1038. * @code bx_srv('bx_posts', 'entity_info_full', [...]); @endcode
  1039. *
  1040. * Get full content info
  1041. * @param $iContentId content ID
  1042. *
  1043. * @see BxBaseModGeneralModule::serviceEntityInfoFull
  1044. */
  1045. /**
  1046. * @ref bx_base_general-entity_info_full "entity_info_full"
  1047. */
  1048. public function serviceEntityInfoFull ($iContentId = 0)
  1049. {
  1050. $CNF = &$this->_oConfig->CNF;
  1051. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  1052. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  1053. }
  1054. /**
  1055. * @page service Service Calls
  1056. * @section bx_base_general Base General
  1057. * @subsection bx_base_general-page_blocks Page Blocks
  1058. * @subsubsection bx_base_general-entity_info_extended entity_info_extended
  1059. *
  1060. * @code bx_srv('bx_posts', 'entity_info_extended', [...]); @endcode
  1061. *
  1062. * Get extended content info
  1063. * @param $iContentId content ID
  1064. *
  1065. * @see BxBaseModGeneralModule::serviceEntityInfoExtended
  1066. */
  1067. /**
  1068. * @ref bx_base_general-entity_info_extended "entity_info_extended"
  1069. */
  1070. public function serviceEntityInfoExtended ($iContentId = 0)
  1071. {
  1072. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  1073. }
  1074. /**
  1075. * @page service Service Calls
  1076. * @section bx_base_general Base General
  1077. * @subsection bx_base_general-page_blocks Page Blocks
  1078. * @subsubsection bx_base_general-entity_location entity_location
  1079. *
  1080. * @code bx_srv('bx_posts', 'entity_location', [...]); @endcode
  1081. *
  1082. * Get content location
  1083. * @param $iContentId content ID
  1084. *
  1085. * @see BxBaseModGeneralModule::serviceEntityLocation
  1086. */
  1087. /**
  1088. * @ref bx_base_general-entity_location "entity_location"
  1089. */
  1090. public function serviceEntityLocation ($iContentId = 0)
  1091. {
  1092. $iContentId = $this->_getContent($iContentId, false);
  1093. if($iContentId === false)
  1094. return false;
  1095. return $this->_oTemplate->entryLocation ($iContentId);
  1096. }
  1097. /**
  1098. * @page service Service Calls
  1099. * @section bx_base_general Base General
  1100. * @subsection bx_base_general-page_blocks Page Blocks
  1101. * @subsubsection bx_base_general-entity_comments entity_comments
  1102. *
  1103. * @code bx_srv('bx_posts', 'entity_comments', [...]); @endcode
  1104. *
  1105. * Get content comments
  1106. * @param $iContentId content ID
  1107. *
  1108. * @see BxBaseModGeneralModule::serviceEntityComments
  1109. */
  1110. /**
  1111. * @ref bx_base_general-entity_comments "entity_comments"
  1112. */
  1113. public function serviceEntityComments ($iContentId = 0)
  1114. {
  1115. $CNF = &$this->_oConfig->CNF;
  1116. if(empty($CNF['OBJECT_COMMENTS']))
  1117. return '';
  1118. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  1119. }
  1120. /**
  1121. * @page service Service Calls
  1122. * @section bx_base_general Base General
  1123. * @subsection bx_base_general-page_blocks Page Blocks
  1124. * @subsubsection bx_base_general-entity_attachments entity_attachments
  1125. *
  1126. * @code bx_srv('bx_posts', 'entity_attachments', [...]); @endcode
  1127. *
  1128. * Get content attachments
  1129. * @param $iContentId content ID
  1130. *
  1131. * @see BxBaseModGeneralModule::serviceEntityAttachments
  1132. */
  1133. /**
  1134. * @ref bx_base_general-entity_attachments "entity_attachments"
  1135. */
  1136. public function serviceEntityAttachments ($iContentId = 0)
  1137. {
  1138. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  1139. }
  1140. /**
  1141. * Delete content entry
  1142. * @param $iContentId content id
  1143. * @return error message or empty string on success
  1144. */
  1145. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  1146. {
  1147. bx_import('FormsEntryHelper', $this->_aModule);
  1148. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  1149. $oFormsHelper = new $sClass($this);
  1150. return $oFormsHelper->$sFuncDelete($iContentId);
  1151. }
  1152. /**
  1153. * @page service Service Calls
  1154. * @section bx_base_general Base General
  1155. * @subsection bx_base_general-menu Menu
  1156. * @subsubsection bx_base_general-my_entries_actions my_entries_actions
  1157. *
  1158. * @code bx_srv('bx_posts', 'my_entries_actions', [...]); @endcode
  1159. *
  1160. * My entries actions menu
  1161. * @param $iProfileId profiles ID,
  1162. * if omitted it try to get it from 'profile_id' GET param
  1163. *
  1164. * @see BxBaseModGeneralModule::serviceMyEntriesActions
  1165. */
  1166. /**
  1167. * @ref bx_base_general-my_entries_actions "my_entries_actions"
  1168. */
  1169. public function serviceMyEntriesActions ($iProfileId = 0)
  1170. {
  1171. $CNF = &$this->_oConfig->CNF;
  1172. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  1173. return false;
  1174. if (!$iProfileId)
  1175. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1176. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  1177. return false;
  1178. if ($iProfileId != $this->_iProfileId)
  1179. return false;
  1180. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  1181. return $oMenu ? $oMenu->getCode() : false;
  1182. }
  1183. /**
  1184. * @page service Service Calls
  1185. * @section bx_base_general Base General
  1186. * @subsection bx_base_general-menu Menu
  1187. * @subsubsection bx_base_general-entity_all_actions entity_all_actions
  1188. *
  1189. * @code bx_srv('bx_posts', 'entity_all_actions', [...]); @endcode
  1190. *
  1191. * Entry actions and social sharing actions
  1192. * @param $mixedContent content ID
  1193. * @param $aParams additional params
  1194. *
  1195. * @see BxBaseModGeneralModule::serviceEntityAllActions
  1196. */
  1197. /**
  1198. * @ref bx_base_general-entity_all_actions "entity_all_actions"
  1199. */
  1200. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  1201. {
  1202. $CNF = &$this->_oConfig->CNF;
  1203. if(!empty($mixedContent)) {
  1204. if(!is_array($mixedContent))
  1205. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  1206. }
  1207. else {
  1208. $mixedContent = $this->_getContent();
  1209. if($mixedContent === false)
  1210. return false;
  1211. }
  1212. list($iContentId, $aContentInfo) = $mixedContent;
  1213. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  1214. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  1215. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  1216. if(empty($sObjectMenu))
  1217. return false;
  1218. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  1219. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1220. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1221. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  1222. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  1223. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  1224. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  1225. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1226. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1227. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  1228. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  1229. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  1230. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  1231. $aMarkers = array(
  1232. 'id' => $iContentId,
  1233. 'module' => $this->_oConfig->getName(),
  1234. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  1235. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  1236. 'img_url' => ''
  1237. );
  1238. if(!empty($iEntryThumb)) {
  1239. if(!empty($sObjectTranscoder))
  1240. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  1241. else if(!empty($sObjectStorage))
  1242. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  1243. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  1244. if(!empty($sImageUrl))
  1245. $aMarkers['img_url'] = $sImageUrl;
  1246. }
  1247. $oActions = BxDolMenu::getObjectInstance($sObjectMenu, $this->_oTemplate);
  1248. if(!$oActions)
  1249. return false;
  1250. $oActions->setContentId($iContentId);
  1251. $oActions->addMarkers($aMarkers);
  1252. return $this->_oTemplate->entryAllActions($oActions->getCode());
  1253. }
  1254. /**
  1255. * @page service Service Calls
  1256. * @section bx_base_general Base General
  1257. * @subsection bx_base_general-menu Menu
  1258. * @subsubsection bx_base_general-entity_actions entity_actions
  1259. *
  1260. * @code bx_srv('bx_posts', 'entity_actions', [...]); @endcode
  1261. *
  1262. * Entry actions, without social sharing actions
  1263. * @param $iContentId content ID
  1264. *
  1265. * @see BxBaseModGeneralModule::serviceEntityActions
  1266. */
  1267. /**
  1268. * @ref bx_base_general-entity_actions "entity_actions"
  1269. */
  1270. public function serviceEntityActions ($iContentId = 0)
  1271. {
  1272. $iContentId = $this->_getContent($iContentId, false);
  1273. if($iContentId === false)
  1274. return false;
  1275. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  1276. return $oMenu ? $oMenu->getCode() : false;
  1277. }
  1278. /**
  1279. * @page service Service Calls
  1280. * @section bx_base_general Base General
  1281. * @subsection bx_base_general-page_blocks Page Blocks
  1282. * @subsubsection bx_base_general-entity_reports entity_reports
  1283. *
  1284. * @code bx_srv('bx_posts', 'entity_reports', [...]); @endcode
  1285. *
  1286. * Get content reports
  1287. * @param $iContentId content ID
  1288. *
  1289. * @see BxBaseModGeneralModule::serviceEntityReports
  1290. */
  1291. /**
  1292. * @ref bx_base_general-entity_reports "entity_reports"
  1293. */
  1294. public function serviceEntityReports ($iContentId = 0)
  1295. {
  1296. $mixedContent = $this->_getContent($iContentId);
  1297. list($iContentId, $aContentInfo) = $mixedContent;
  1298. if($iContentId === false)
  1299. return false;
  1300. $CNF = &$this->_oConfig->CNF;
  1301. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1302. return false;
  1303. if(!(BxDolAcl::getInstance()->isMemberLevelInSet(192) || (isset($CNF['FIELD_AUTHOR']) && bx_get_logged_profile_id() == $aContentInfo[$CNF['FIELD_AUTHOR']])))
  1304. return false;
  1305. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $iContentId, true);
  1306. if(!$oReport)
  1307. return false;
  1308. return $oReport->getReportedByWithComments($CNF['OBJECT_NOTES']);
  1309. }
  1310. /**
  1311. * @page service Service Calls
  1312. * @section bx_base_general Base General
  1313. * @subsection bx_base_general-page_blocks Page Blocks
  1314. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1315. *
  1316. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1317. *
  1318. * Get number of reports with specified status
  1319. * @param $iStatus status ID
  1320. *
  1321. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  1322. */
  1323. /**
  1324. * @ref bx_base_general-entity_reports "entity_reports"
  1325. */
  1326. public function serviceReportsCountByStatus ($iStatus)
  1327. {
  1328. $CNF = &$this->_oConfig->CNF;
  1329. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1330. return false;
  1331. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  1332. return $oReport->getCountByStatus($iStatus);
  1333. }
  1334. /**
  1335. * @page service Service Calls
  1336. * @section bx_base_general Base General
  1337. * @subsection bx_base_general-menu Menu
  1338. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  1339. *
  1340. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  1341. *
  1342. * Entry social sharing actions
  1343. * @param $mixedContent content ID or array with integer content ID and
  1344. * array with content info, or false
  1345. * @param $aParams array with additional custom params
  1346. * which may overwrite some default values
  1347. *
  1348. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  1349. */
  1350. /**
  1351. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  1352. */
  1353. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  1354. {
  1355. if(!empty($mixedContent)) {
  1356. if(!is_array($mixedContent))
  1357. $mixedContent = array((int)$mixedContent, array());
  1358. }
  1359. else {
  1360. $mixedContent = $this->_getContent();
  1361. if($mixedContent === false)
  1362. return false;
  1363. }
  1364. list($iContentId, $aContentInfo) = $mixedContent;
  1365. $CNF = &$this->_oConfig->CNF;
  1366. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  1367. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  1368. $sUri = $CNF['URI_VIEW_ENTRY'];
  1369. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  1370. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  1371. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1372. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1373. $aMarkers = array(
  1374. 'id' => $iContentId,
  1375. 'module' => $this->_aModule['name'],
  1376. 'url' => BX_DOL_URL_ROOT . $sUrl,
  1377. 'title' => $sTitle,
  1378. );
  1379. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1380. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1381. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1382. if ($iIdThumb) {
  1383. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  1384. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  1385. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  1386. $sStorage = $CNF['OBJECT_STORAGE'];
  1387. if(!empty($sTranscoder))
  1388. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  1389. else if(!empty($sStorage))
  1390. $o = BxDolStorage::getObjectInstance($sStorage);
  1391. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1392. if($sImgUrl)
  1393. $aMarkers['img_url'] = $sImgUrl;
  1394. }
  1395. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1396. $oMenu->addMarkers($aMarkers);
  1397. $sMenu = $oMenu->getCode();
  1398. if(empty($sMenu))
  1399. return '';
  1400. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1401. 'menu' => $sMenu
  1402. ));
  1403. }
  1404. /**
  1405. * Entry context block
  1406. */
  1407. public function serviceEntityContext ($iContentId = 0)
  1408. {
  1409. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1410. }
  1411. /**
  1412. * Blocks for lables tree browsing
  1413. */
  1414. public function serviceGetLablesTree()
  1415. {
  1416. $aBreadcrumbs = array();
  1417. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1418. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1419. }
  1420. public function serviceGetLablesBreadcrumbs()
  1421. {
  1422. if (bx_get('label')){
  1423. $aBreadcrumbs = array();
  1424. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1425. $aLabels = array();
  1426. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1427. $aLabels[] = array(
  1428. 'value' => $aLabel['value'],
  1429. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1430. );
  1431. }
  1432. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1433. }
  1434. return '';
  1435. }
  1436. public function serviceBrowseByLabel()
  1437. {
  1438. $CNF = &$this->_oConfig->CNF;
  1439. if (empty($CNF['OBJECT_METATAGS']))
  1440. return '';
  1441. $sMode = 'recent';
  1442. if(bx_srv('system', 'is_module_content', [$this->_aModule['name']]))
  1443. $sMode = 'public';
  1444. $sClassSearchResult ='SearchResult';
  1445. bx_import($sClassSearchResult, $this->_aModule['name']);
  1446. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1447. $o = new $sClass($sMode, false);
  1448. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1449. $o->setDisplayEmptyMsg(true);
  1450. $o->setAjaxPaginate(false);
  1451. $o->setUnitParams(array('context' => $sMode));
  1452. if (bx_get('label')){
  1453. $iLabelId = (int)bx_get('label');
  1454. $oLabel = BxDolLabel::getInstance();
  1455. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1456. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1457. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1458. }
  1459. if ($o->isError)
  1460. return '';
  1461. if ($s = $o->processing())
  1462. return $s;
  1463. else
  1464. return '';
  1465. }
  1466. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  1467. {
  1468. $CNF = &$this->_oConfig->CNF;
  1469. $sClassSearchResult ='SearchResult';
  1470. bx_import($sClassSearchResult, $this->_aModule['name']);
  1471. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1472. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  1473. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1474. $o->setAjaxPaginate($bAjaxPaginate);
  1475. $o->setCategoryObject('multi');
  1476. $aCategoriesOutput = array();
  1477. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  1478. foreach($aCategories as $aCategory){
  1479. if ($aCategory['num'] > 0){
  1480. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  1481. $o->setPaginatePerPage(2);
  1482. if (!$o->isError){
  1483. $aResult = $o->processing();
  1484. if ($aResult && $aResult['content'] != '')
  1485. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  1486. }
  1487. }
  1488. }
  1489. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  1490. 'bx_repeat:categories' => $aCategoriesOutput,
  1491. ));
  1492. }
  1493. /**
  1494. * Data for Notifications module
  1495. */
  1496. public function serviceGetNotificationsData()
  1497. {
  1498. $sModule = $this->_aModule['name'];
  1499. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1500. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1501. $sEventPrivacy = '';
  1502. $aResult = [
  1503. 'handlers' => [
  1504. ['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],
  1505. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'],
  1506. ['group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'],
  1507. ['group' => $sModule . '_object_approved', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'approved', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_approved', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  1508. ['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],
  1509. ['group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'],
  1510. ['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],
  1511. ['group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'],
  1512. ['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],
  1513. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  1514. ['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],
  1515. ['group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'],
  1516. ['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],
  1517. ['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],
  1518. //--- Moderation related: For 'admins'.
  1519. ['group' => $sModule . '_object_pending_approval', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'pending_approval', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_pending_approval', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy],
  1520. ],
  1521. 'settings' => [
  1522. ['group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => ['follow_member', 'follow_context']],
  1523. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'approved', 'types' => ['personal']],
  1524. ['group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => ['personal', 'follow_member', 'follow_context']],
  1525. ['group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => ['personal']],
  1526. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1527. ['group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => ['personal', 'follow_member', 'follow_context']],
  1528. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => ['personal', 'follow_member', 'follow_context']],
  1529. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => ['personal', 'follow_member', 'follow_context']],
  1530. //--- Moderation related: For 'admins'.
  1531. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  1532. ],
  1533. 'alerts' => [
  1534. ['unit' => $sModule, 'action' => 'added'],
  1535. ['unit' => $sModule, 'action' => 'edited'],
  1536. ['unit' => $sModule, 'action' => 'deleted'],
  1537. ['unit' => $sModule, 'action' => 'approved'],
  1538. ['unit' => $sModule, 'action' => 'commentPost'],
  1539. ['unit' => $sModule, 'action' => 'commentRemoved'],
  1540. ['unit' => $sModule, 'action' => 'replyPost'],
  1541. ['unit' => $sModule, 'action' => 'replyRemoved'],
  1542. ['unit' => $sModule, 'action' => 'doVote'],
  1543. ['unit' => $sModule, 'action' => 'undoVote'],
  1544. ['unit' => $sModule . '_reactions', 'action' => 'doVote'],
  1545. ['unit' => $sModule . '_reactions', 'action' => 'undoVote'],
  1546. ['unit' => $sModule, 'action' => 'doVoteUp'],
  1547. ['unit' => $sModule, 'action' => 'doVoteDown'],
  1548. //--- Moderation related: For 'admins'.
  1549. ['unit' => $sModule, 'action' => 'pending_approval'],
  1550. ]
  1551. ];
  1552. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1553. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1554. ['group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module', 'module_event_privacy' => ''],
  1555. ['group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module', 'module_event_privacy' => ''],
  1556. ]);
  1557. $aResult['settings'] = array_merge($aResult['settings'], [
  1558. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => ['personal']],
  1559. ['group' => 'content_updated', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => ['personal']],
  1560. ]);
  1561. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1562. ['unit' => $sModule, 'action' => 'publish_failed'],
  1563. ['unit' => $sModule, 'action' => 'publish_succeeded'],
  1564. ]);
  1565. }
  1566. return $aResult;
  1567. }
  1568. /**
  1569. * Entry post for Notifications module
  1570. */
  1571. public function serviceGetNotificationsPost($aEvent)
  1572. {
  1573. $CNF = &$this->_oConfig->CNF;
  1574. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1575. if(empty($aContentInfo) || !is_array($aContentInfo))
  1576. return array();
  1577. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1578. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1579. return array(
  1580. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1581. 'entry_url' => $sEntryUrl,
  1582. 'entry_caption' => $sEntryCaption,
  1583. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1584. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1585. 'lang_key' => '', //may be empty or not specified, or a string, or an array('site' => '...', 'email' => '...', 'push' => '...'). In this case of empty/not specified the default one from Notification module will be used.
  1586. /*
  1587. * Custom settings for email and/or push notifications can be provided here.
  1588. * Only necessary parts of 'settings' array can be used.
  1589. *
  1590. 'settings' => array(
  1591. 'email' => array(
  1592. 'template' => '', //--- custom email template
  1593. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1594. 'subject' => '' //--- custom email subject
  1595. ),
  1596. 'push' => array(
  1597. 'subject' => '' //--- custom push notification subject
  1598. )
  1599. )
  1600. */
  1601. );
  1602. }
  1603. public function serviceGetNotificationsPostPendingApproval($aEvent)
  1604. {
  1605. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1606. /**
  1607. * Unset Entry Author because the notification is addressed to 'admins'.
  1608. */
  1609. if(isset($aResult['entry_author']))
  1610. unset($aResult['entry_author']);
  1611. return $aResult;
  1612. }
  1613. public function serviceGetNotificationsPostApproved($aEvent)
  1614. {
  1615. return $this->serviceGetNotificationsPost($aEvent);
  1616. }
  1617. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1618. {
  1619. return $this->serviceGetNotificationsPost($aEvent);
  1620. }
  1621. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1622. {
  1623. return $this->serviceGetNotificationsPost($aEvent);
  1624. }
  1625. /**
  1626. * Entry post comment for Notifications module
  1627. */
  1628. public function serviceGetNotificationsComment($aEvent)
  1629. {
  1630. $CNF = &$this->_oConfig->CNF;
  1631. $iContentId = (int)$aEvent['object_id'];
  1632. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1633. if(empty($aContentInfo) || !is_array($aContentInfo))
  1634. return array();
  1635. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1636. if(!$oComment || !$oComment->isEnabled())
  1637. return array();
  1638. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1639. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1640. return array(
  1641. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1642. 'entry_url' => $sEntryUrl,
  1643. 'entry_caption' => $sEntryCaption,
  1644. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1645. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1646. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1647. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1648. );
  1649. }
  1650. /**
  1651. * Entry post reply for Notifications module
  1652. */
  1653. public function serviceGetNotificationsReply($aEvent)
  1654. {
  1655. $CNF = &$this->_oConfig->CNF;
  1656. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1657. if(!$oComment || !$oComment->isEnabled())
  1658. return array();
  1659. $iParentId = (int)$aEvent['object_id'];
  1660. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1661. if(empty($aParentInfo) || !is_array($aParentInfo))
  1662. return array();
  1663. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1664. $oComment->init($iObjectId);
  1665. return array(
  1666. 'object_id' => $iObjectId,
  1667. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1668. 'entry_url' => $oComment->getViewUrl($iParentId),
  1669. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1670. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1671. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1672. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1673. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1674. );
  1675. }
  1676. /**
  1677. * Entry post vote for Notifications module
  1678. */
  1679. public function serviceGetNotificationsVote($aEvent)
  1680. {
  1681. $CNF = &$this->_oConfig->CNF;
  1682. $iContentId = (int)$aEvent['object_id'];
  1683. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1684. if(empty($aContentInfo) || !is_array($aContentInfo))
  1685. return array();
  1686. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1687. if(!$oVote || !$oVote->isEnabled())
  1688. return array();
  1689. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1690. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1691. return array(
  1692. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1693. 'entry_url' => $sEntryUrl,
  1694. 'entry_caption' => $sEntryCaption,
  1695. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1696. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1697. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1698. );
  1699. }
  1700. /**
  1701. * Entry post vote for Notifications module
  1702. */
  1703. public function serviceGetNotificationsReaction($aEvent)
  1704. {
  1705. $CNF = &$this->_oConfig->CNF;
  1706. $iContentId = (int)$aEvent['object_id'];
  1707. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1708. if(empty($aContentInfo) || !is_array($aContentInfo))
  1709. return array();
  1710. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1711. if(!$oReaction || !$oReaction->isEnabled())
  1712. return array();
  1713. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1714. if(empty($aSubentry) || !is_array($aSubentry))
  1715. return array();
  1716. $aSubentrySampleParams = array();
  1717. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1718. if(!empty($aReaction['title']))
  1719. $aSubentrySampleParams[] = $aReaction['title'];
  1720. else
  1721. $aSubentrySampleParams[] = '_undefined';
  1722. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1723. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1724. return array(
  1725. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1726. 'entry_url' => $sEntryUrl,
  1727. 'entry_caption' => $sEntryCaption,
  1728. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1729. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1730. 'subentry_sample_params' => $aSubentrySampleParams,
  1731. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1732. );
  1733. }
  1734. /**
  1735. * Entry post score -> vote up for Notifications module
  1736. */
  1737. public function serviceGetNotificationsScoreUp($aEvent)
  1738. {
  1739. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1740. }
  1741. /**
  1742. * Entry post score -> vote up for Notifications module
  1743. */
  1744. public function serviceGetNotificationsScoreDown($aEvent)
  1745. {
  1746. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1747. }
  1748. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1749. {
  1750. $CNF = &$this->_oConfig->CNF;
  1751. $iContentId = (int)$aEvent['object_id'];
  1752. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1753. if(empty($aContentInfo) || !is_array($aContentInfo))
  1754. return array();
  1755. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1756. if(!$oScore || !$oScore->isEnabled())
  1757. return array();
  1758. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1759. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1760. return array(
  1761. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1762. 'entry_url' => $sEntryUrl,
  1763. 'entry_caption' => $sEntryCaption,
  1764. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1765. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1766. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1767. );
  1768. }
  1769. /**
  1770. * Data for Timeline module
  1771. */
  1772. public function serviceGetTimelineData()
  1773. {
  1774. $sModule = $this->_aModule['name'];
  1775. return array(
  1776. 'handlers' => array(
  1777. 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' => ''),
  1778. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1779. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1780. ),
  1781. 'alerts' => array(
  1782. array('unit' => $sModule, 'action' => 'added'),
  1783. array('unit' => $sModule, 'action' => 'edited'),
  1784. array('unit' => $sModule, 'action' => 'deleted'),
  1785. )
  1786. );
  1787. }
  1788. /**
  1789. * Entry post for Timeline module
  1790. */
  1791. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1792. {
  1793. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1794. if(empty($aContentInfo) || !is_array($aContentInfo))
  1795. return false;
  1796. $CNF = &$this->_oConfig->CNF;
  1797. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1798. return false;
  1799. $iUserId = $this->getUserId();
  1800. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1801. $iAuthorIdAbs = abs($iAuthorId);
  1802. 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)
  1803. return false;
  1804. //--- Views
  1805. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1806. $aViews = array();
  1807. if ($oViews && $oViews->isEnabled())
  1808. $aViews = array(
  1809. 'system' => $CNF['OBJECT_VIEWS'],
  1810. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1811. 'count' => $aContentInfo['views']
  1812. );
  1813. //--- Votes
  1814. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1815. $aVotes = array();
  1816. if ($oVotes && $oVotes->isEnabled())
  1817. $aVotes = array(
  1818. 'system' => $CNF['OBJECT_VOTES'],
  1819. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1820. 'count' => $aContentInfo['votes']
  1821. );
  1822. //--- Reactions
  1823. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1824. $aReactions = array();
  1825. if ($oReactions && $oReactions->isEnabled())
  1826. $aReactions = array(
  1827. 'system' => $CNF['OBJECT_REACTIONS'],
  1828. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1829. 'count' => $aContentInfo['rvotes']
  1830. );
  1831. //--- Scores
  1832. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1833. $aScores = array();
  1834. if ($oScores && $oScores->isEnabled())
  1835. $aScores = array(
  1836. 'system' => $CNF['OBJECT_SCORES'],
  1837. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1838. 'score' => $aContentInfo['score']
  1839. );
  1840. //--- Reports
  1841. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1842. $aReports = array();
  1843. if ($oReports && $oReports->isEnabled())
  1844. $aReports = array(
  1845. 'system' => $CNF['OBJECT_REPORTS'],
  1846. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1847. 'count' => $aContentInfo['reports']
  1848. );
  1849. //--- Comments
  1850. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1851. $aComments = array();
  1852. if($oCmts && $oCmts->isEnabled())
  1853. $aComments = array(
  1854. 'system' => $CNF['OBJECT_COMMENTS'],
  1855. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1856. 'count' => $aContentInfo['comments']
  1857. );
  1858. //--- Title & Description
  1859. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1860. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1861. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1862. $iOwnerId = $iAuthorIdAbs;
  1863. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1864. $iOwnerId = abs($aEvent['object_privacy_view']);
  1865. $bCache = true;
  1866. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1867. if(isset($aContent['_cache'])) {
  1868. $bCache = (bool)$aContent['_cache'];
  1869. unset($aContent['_cache']);
  1870. }
  1871. return array(
  1872. '_cache' => $bCache,
  1873. 'owner_id' => $iOwnerId,
  1874. 'object_owner_id' => $iAuthorId,
  1875. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1876. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1877. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1878. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1879. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1880. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1881. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1882. 'views' => $aViews,
  1883. 'votes' => $aVotes,
  1884. 'reactions' => $aReactions,
  1885. 'scores' => $aScores,
  1886. 'reports' => $aReports,
  1887. 'comments' => $aComments,
  1888. 'title' => $sTitle, //may be empty.
  1889. 'description' => '' //may be empty.
  1890. );
  1891. }
  1892. public function serviceGetTimelinePostAllowedView($aEvent)
  1893. {
  1894. $iContentId = (int)$aEvent['object_id'];
  1895. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1896. if(empty($aContentInfo) || !is_array($aContentInfo))
  1897. return _t('_sys_txt_access_denied');
  1898. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1899. }
  1900. /**
  1901. * Check particular action permission without content
  1902. * @param $sAction action to check, for example: Browse, Add
  1903. * @param $iContentId content ID
  1904. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1905. */
  1906. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1907. {
  1908. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1909. if (!method_exists($this, $sMethod))
  1910. return _t('_sys_request_method_not_found_cpt');
  1911. return $this->$sMethod($isPerformAction);
  1912. }
  1913. /**
  1914. * Check particular action permission with content
  1915. * @param $sAction action to check, for example: View, Edit
  1916. * @param $iContentId content ID
  1917. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1918. */
  1919. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1920. {
  1921. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1922. return _t('_sys_request_page_not_found_cpt');
  1923. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1924. if (!method_exists($this, $sMethod))
  1925. return _t('_sys_request_method_not_found_cpt');
  1926. return $this->$sMethod($aContentInfo, $isPerformAction);
  1927. }
  1928. /**
  1929. * Check particular action permission with content for specified profile
  1930. * @param $sAction action to check, for example: View, Edit
  1931. * @param $iContentId content ID
  1932. * @param $iProfileId profile ID which the permissions to be cheked for
  1933. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1934. */
  1935. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1936. {
  1937. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1938. return _t('_sys_request_page_not_found_cpt');
  1939. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1940. if (!method_exists($this, $sMethod))
  1941. return _t('_sys_request_method_not_found_cpt');
  1942. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1943. }
  1944. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1945. {
  1946. //negative id used in comments for reports
  1947. if ($iContentId < 0)
  1948. return CHECK_ACTION_RESULT_ALLOWED;
  1949. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1950. }
  1951. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1952. {
  1953. //negative id used in comments for reports
  1954. if ($iContentId < 0)
  1955. return CHECK_ACTION_RESULT_ALLOWED;
  1956. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1957. }
  1958. public function serviceGetContentOwnerProfileId ($iContentId)
  1959. {
  1960. $CNF = &$this->_oConfig->CNF;
  1961. // file owner must be author of the content or profile itself in case of profile based module
  1962. if ($iContentId) {
  1963. $sModule = $this->getName();
  1964. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1965. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1966. }
  1967. else {
  1968. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1969. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1970. }
  1971. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1972. }
  1973. else {
  1974. $iProfileId = bx_get_logged_profile_id();
  1975. }
  1976. return $iProfileId;
  1977. }
  1978. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1979. {
  1980. $sModule = $this->getName();
  1981. $oBadges = BxDolBadges::getInstance();
  1982. $aBadges = $oBadges->getData(array(
  1983. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1984. 'module' => $sModule,
  1985. 'object_id' => $iContentId
  1986. ));
  1987. $sResult = false;
  1988. bx_alert('system', 'get_badges', 0, 0, array(
  1989. 'module' => $sModule,
  1990. 'content_id' => $iContentId,
  1991. 'is_single' => $bIsSingle,
  1992. 'is_compact' => $bIsCompact,
  1993. 'badges' => $aBadges,
  1994. 'override_result' => &$sResult
  1995. ));
  1996. if($sResult !== false)
  1997. return $sResult;
  1998. if(empty($aBadges) || !is_array($aBadges))
  1999. return '';
  2000. if($bIsSingle)
  2001. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  2002. $aBadgesOutput = array();
  2003. foreach($aBadges as $aBadge)
  2004. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  2005. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  2006. 'bx_repeat:items' => $aBadgesOutput,
  2007. ));
  2008. }
  2009. /**
  2010. * @page service Service Calls
  2011. * @section bx_base_general Base General
  2012. * @subsection bx_base_general-page_blocks Page Blocks
  2013. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  2014. *
  2015. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  2016. *
  2017. * Display multi-categorories block with number of posts in each category
  2018. * @param $bDisplayEmptyCats display empty categories
  2019. *
  2020. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  2021. */
  2022. /**
  2023. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  2024. */
  2025. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  2026. {
  2027. $aContextInfo = bx_get_page_info();
  2028. $mProfileContextId = false;
  2029. if ($aContextInfo !== false)
  2030. $mProfileContextId = $aContextInfo['context_profile_id'];
  2031. $oCategories = BxDolCategories::getInstance();
  2032. if ($mProfileContextId)
  2033. $aCats = $oCategories->getData([
  2034. 'type' => 'by_module&context_with_num',
  2035. 'module' => $this->getName(),
  2036. 'context_id' => $mProfileContextId
  2037. ]);
  2038. else{
  2039. $aCats = $oCategories->getData([
  2040. 'type' => 'by_module_with_num',
  2041. 'module' => $this->getName()
  2042. ]);
  2043. }
  2044. $aVars = array('bx_repeat:cats' => array());
  2045. foreach ($aCats as $oCat) {
  2046. $sValue = $oCat['value'];
  2047. $iNum = $oCat['num'];
  2048. $aVars['bx_repeat:cats'][] = array(
  2049. 'url' => $oCategories->getUrl($this->getName(), $sValue, $mProfileContextId ? '&context_id=' . $mProfileContextId : ''),
  2050. 'name' => _t($sValue),
  2051. 'value' => $sValue,
  2052. 'num' => $iNum,
  2053. );
  2054. }
  2055. if (!$aVars['bx_repeat:cats'])
  2056. return '';
  2057. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  2058. }
  2059. /**
  2060. * ======
  2061. * PERMISSION METHODS
  2062. * ======
  2063. */
  2064. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2065. {
  2066. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2067. // check alert to allow custom checks
  2068. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2069. return $mixedResult;
  2070. }
  2071. public function checkAllowedSetThumb ($iContentId = 0)
  2072. {
  2073. return CHECK_ACTION_RESULT_ALLOWED;
  2074. }
  2075. /**
  2076. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2077. */
  2078. public function checkAllowedBrowse ()
  2079. {
  2080. // check alert to allow custom checks
  2081. $mixedResult = null;
  2082. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  2083. if($mixedResult !== null)
  2084. return $mixedResult;
  2085. return CHECK_ACTION_RESULT_ALLOWED;
  2086. }
  2087. /**
  2088. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2089. */
  2090. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  2091. {
  2092. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  2093. }
  2094. /**
  2095. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2096. */
  2097. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  2098. {
  2099. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2100. }
  2101. /**
  2102. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2103. */
  2104. public function checkAllowedAdd ($isPerformAction = false)
  2105. {
  2106. // check ACL
  2107. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  2108. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2109. return $aCheck[CHECK_ACTION_MESSAGE];
  2110. return CHECK_ACTION_RESULT_ALLOWED;
  2111. }
  2112. /**
  2113. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2114. */
  2115. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  2116. {
  2117. $CNF = &$this->_oConfig->CNF;
  2118. $sError = '_sys_txt_access_denied';
  2119. if(!$this->_oConfig->isAutoApproveEnabled())
  2120. return _t($sError);
  2121. if($aDataEntry[$CNF['FIELD_STATUS_ADMIN']] != BX_BASE_MOD_GENERAL_STATUS_PENDING)
  2122. return _t($sError);
  2123. // moderator always have access
  2124. if ($this->_isModerator($isPerformAction))
  2125. return CHECK_ACTION_RESULT_ALLOWED;
  2126. // check for context's admins
  2127. if (!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2128. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2129. if ($oProfile){
  2130. $sModule = $oProfile->getModule();
  2131. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2132. $oModule = BxDolModule::getInstance($sModule);
  2133. // check for context's extra roles with rights
  2134. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2135. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2136. if ($bResult !== NULL) return $bResult;
  2137. }
  2138. // if allowed edit a group then allowed to edit anything inside its context
  2139. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2140. return CHECK_ACTION_RESULT_ALLOWED;
  2141. }
  2142. }
  2143. }
  2144. return _t($sError);
  2145. }
  2146. /**
  2147. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2148. */
  2149. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  2150. {
  2151. // moderator and owner always have access
  2152. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  2153. return CHECK_ACTION_RESULT_ALLOWED;
  2154. // check for context's admins
  2155. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2156. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2157. if ($oProfile){
  2158. $sModule = $oProfile->getModule();
  2159. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2160. $oModule = BxDolModule::getInstance($sModule);
  2161. // check for context's extra roles with rights
  2162. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2163. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2164. if ($bResult !== NULL) return $bResult;
  2165. }
  2166. // if allowed edit a group then allowed to edit anything inside its context
  2167. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2168. return CHECK_ACTION_RESULT_ALLOWED;
  2169. }
  2170. }
  2171. }
  2172. return _t('_sys_txt_access_denied');
  2173. }
  2174. /**
  2175. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2176. */
  2177. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  2178. {
  2179. // moderator always has access
  2180. if ($this->_isAdministrator($isPerformAction))
  2181. return CHECK_ACTION_RESULT_ALLOWED;
  2182. // check ACL
  2183. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  2184. 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)
  2185. return CHECK_ACTION_RESULT_ALLOWED;
  2186. // check for context's admins
  2187. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  2188. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2189. if ($oProfile){
  2190. $sModule = $oProfile->getModule();
  2191. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2192. $oModule = BxDolModule::getInstance($sModule);
  2193. // check for context's extra roles with rights
  2194. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2195. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  2196. if ($bResult !== NULL) return $bResult;
  2197. }
  2198. // if allowed delete a group then allowed to delete anything inside its context
  2199. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2200. return CHECK_ACTION_RESULT_ALLOWED;
  2201. }
  2202. }
  2203. }
  2204. return _t('_sys_txt_access_denied');
  2205. }
  2206. /**
  2207. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2208. */
  2209. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2210. {
  2211. // admin always has access
  2212. if (isAdmin())
  2213. return CHECK_ACTION_RESULT_ALLOWED;
  2214. // check ACL
  2215. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2216. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2217. return $aCheck[CHECK_ACTION_MESSAGE];
  2218. return CHECK_ACTION_RESULT_ALLOWED;
  2219. }
  2220. /**
  2221. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2222. */
  2223. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2224. {
  2225. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2226. }
  2227. /**
  2228. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2229. */
  2230. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2231. {
  2232. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2233. }
  2234. /**
  2235. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2236. */
  2237. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2238. {
  2239. if(!$iProfileId)
  2240. $iProfileId = $this->_iProfileId;
  2241. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_EDIT_ANY_ENTRY, $this->getName(), $isPerformAction);
  2242. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2243. return CHECK_ACTION_RESULT_ALLOWED;
  2244. return _t('_sys_txt_access_denied');
  2245. }
  2246. /**
  2247. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2248. */
  2249. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2250. {
  2251. if(!$iProfileId)
  2252. $iProfileId = $this->_iProfileId;
  2253. $aCheck = checkActionModule($iProfileId, MEMBERSHIP_ACTION_DELETE_ANY_ENTRY, $this->getName(), $isPerformAction);
  2254. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2255. return CHECK_ACTION_RESULT_ALLOWED;
  2256. return _t('_sys_txt_access_denied');
  2257. }
  2258. /**
  2259. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2260. */
  2261. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2262. {
  2263. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2264. }
  2265. /**
  2266. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2267. */
  2268. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2269. {
  2270. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2271. }
  2272. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2273. {
  2274. $CNF = &$this->_oConfig->CNF;
  2275. if(!$iProfileId)
  2276. $iProfileId = $this->_iProfileId;
  2277. if(empty($aDataEntry) || !is_array($aDataEntry))
  2278. return _t('_sys_txt_not_found');
  2279. // moderator and owner always have access
  2280. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2281. return CHECK_ACTION_RESULT_ALLOWED;
  2282. // check ACL
  2283. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2284. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2285. return $aCheck[CHECK_ACTION_MESSAGE];
  2286. // check privacy
  2287. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2288. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2289. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2290. return _t('_sys_access_denied_to_private_content');
  2291. }
  2292. return CHECK_ACTION_RESULT_ALLOWED;
  2293. }
  2294. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2295. {
  2296. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2297. return MsgBox($sMsg);
  2298. bx_import($sClassSearchResult, $this->_aModule);
  2299. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2300. $o = new $sClass($sMode, $aParams);
  2301. $o->setDesignBoxTemplateId($iDesignBox);
  2302. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2303. $o->setAjaxPaginate($bAjaxPaginate);
  2304. $o->setUnitParams(array('context' => $sMode));
  2305. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2306. $o->setCustomCurrentCondition($aParams['condition']);
  2307. if ($o->isError)
  2308. return '';
  2309. if ($s = $o->processing())
  2310. return $s;
  2311. else
  2312. return '';
  2313. }
  2314. /**
  2315. * Shows a list of profiles.
  2316. */
  2317. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2318. {
  2319. // get paginate object
  2320. $oPaginate = new BxTemplPaginate(array(
  2321. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2322. 'num' => count($aProfiles),
  2323. 'per_page' => $iLimit,
  2324. 'start' => $iStart,
  2325. ));
  2326. // remove last item from connection array, because we've got one more item for pagination calculations only
  2327. if (count($aProfiles) > $iLimit)
  2328. array_pop($aProfiles);
  2329. // get profiles HTML
  2330. $s = '';
  2331. foreach ($aProfiles as $mixedProfile) {
  2332. $bProfile = is_array($mixedProfile);
  2333. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2334. if(!$oProfile)
  2335. continue;
  2336. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2337. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2338. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2339. if($bProfile && is_array($mixedProfile['info']))
  2340. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2341. $s .= $oProfile->getUnit(0, $aUnitParams);
  2342. }
  2343. $aTmplVarsPaginate = [];
  2344. if($iStart || $oPaginate->getNum() > $iLimit)
  2345. $aTmplVarsPaginate = ['paginate' => $oPaginate->getSimplePaginate()];
  2346. return $this->_oTemplate->parseHtmlByName('browse_quick.html', array(
  2347. 'code' => $s,
  2348. 'bx_if:show_paginate' => [
  2349. 'condition' => !empty($aTmplVarsPaginate),
  2350. 'content' => $aTmplVarsPaginate
  2351. ]
  2352. ));
  2353. }
  2354. // ====== COMMON METHODS
  2355. public function onPublished($iContentId)
  2356. {
  2357. $CNF = &$this->_oConfig->CNF;
  2358. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2359. if(!$aContentInfo)
  2360. return;
  2361. $aParams = $this->_alertParams($aContentInfo);
  2362. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2363. }
  2364. public function onFailed($iContentId)
  2365. {
  2366. $CNF = &$this->_oConfig->CNF;
  2367. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2368. if(!$aContentInfo)
  2369. return;
  2370. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  2371. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2372. }
  2373. public function onApprove($mixedContent)
  2374. {
  2375. $CNF = &$this->_oConfig->CNF;
  2376. if(!is_array($mixedContent))
  2377. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  2378. $this->alertAfterApprove($mixedContent);
  2379. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  2380. }
  2381. public function alertAfterAdd($aContentInfo) {}
  2382. public function alertAfterEdit($aContentInfo) {}
  2383. public function alertAfterApprove($aContentInfo)
  2384. {
  2385. $CNF = &$this->_oConfig->CNF;
  2386. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  2387. $sModule = $this->getName();
  2388. $aParams = $this->_alertParams($aContentInfo);
  2389. bx_alert($sModule, 'approved', $iId, false, $aParams);
  2390. }
  2391. /**
  2392. * Get array of params to be passed in Add/Edit Alert.
  2393. */
  2394. protected function _alertParams($aContentInfo)
  2395. {
  2396. $CNF = &$this->_oConfig->CNF;
  2397. return array(
  2398. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2399. );
  2400. }
  2401. public function processMetasAdd($iContentId)
  2402. {
  2403. $CNF = &$this->_oConfig->CNF;
  2404. if(empty($CNF['OBJECT_METATAGS']))
  2405. return false;
  2406. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2407. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2408. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2409. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2410. if(!$bContentInfo)
  2411. return false;
  2412. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2413. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2414. $sKey = 'FIELD_LOCATION';
  2415. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2416. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2417. if(!empty($aLocation) && is_array($aLocation))
  2418. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2419. }
  2420. $sKey = 'FIELD_LABELS';
  2421. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2422. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2423. if(!empty($aLabels) && is_array($aLabels))
  2424. foreach ($aLabels as $sLabel)
  2425. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2426. }
  2427. return true;
  2428. }
  2429. public function processMetasEdit($iContentId, $oForm)
  2430. {
  2431. $CNF = &$this->_oConfig->CNF;
  2432. if(empty($CNF['OBJECT_METATAGS']))
  2433. return false;
  2434. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2435. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2436. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2437. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2438. if(!$bContentInfo)
  2439. return false;
  2440. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2441. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2442. $sKey = 'FIELD_LOCATION';
  2443. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2444. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2445. if(!empty($aLocation) && is_array($aLocation))
  2446. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2447. }
  2448. $sKey = 'FIELD_LABELS';
  2449. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2450. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2451. if(!empty($aLabels) && is_array($aLabels))
  2452. foreach ($aLabels as $sLabel)
  2453. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2454. }
  2455. return true;
  2456. }
  2457. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  2458. {
  2459. if(empty($aTranscoders))
  2460. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  2461. $CNF = &$this->_oConfig->CNF;
  2462. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  2463. return false;
  2464. $iId = (int)$aContentInfo[$CNF[$sField]];
  2465. $aFile = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE'])->getFile($iId);
  2466. if(strpos($aFile['mime_type'], 'svg') !== false)
  2467. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2468. foreach($aTranscoders as $sTranscoder)
  2469. if(!empty($CNF[$sTranscoder]))
  2470. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  2471. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2472. }
  2473. public function getProfileId()
  2474. {
  2475. return bx_get_logged_profile_id();
  2476. }
  2477. public function getProfileInfo($iUserId = false)
  2478. {
  2479. $oProfile = $this->getObjectUser($iUserId);
  2480. $oAccount = null;
  2481. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  2482. $oAccount = $oProfile->getAccountObject();
  2483. $bAccount = !empty($oAccount);
  2484. if(!$bAccount)
  2485. $oProfile = BxDolProfileUndefined::getInstance();
  2486. return array(
  2487. 'id' => $oProfile->id(),
  2488. 'name' => $oProfile->getDisplayName(),
  2489. 'email' => $bAccount ? $oAccount->getEmail() : '',
  2490. 'link' => $oProfile->getUrl(),
  2491. 'icon' => $oProfile->getIcon(),
  2492. 'thumb' => $oProfile->getThumb(),
  2493. 'avatar' => $oProfile->getAvatar(),
  2494. 'unit' => $oProfile->getUnit(),
  2495. 'active' => $oProfile->isActive(),
  2496. );
  2497. }
  2498. public function getObjectUser($iUserId = false)
  2499. {
  2500. bx_import('BxDolProfile');
  2501. return BxDolProfile::getInstanceMagic($iUserId);
  2502. }
  2503. public function getObjectFavorite($sSystem = '', $iId = 0)
  2504. {
  2505. $CNF = &$this->_oConfig->CNF;
  2506. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  2507. $sSystem = $CNF['OBJECT_FAVORITES'];
  2508. if(empty($sSystem))
  2509. return false;
  2510. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2511. if(!$oFavorite || !$oFavorite->isEnabled())
  2512. return false;
  2513. return $oFavorite;
  2514. }
  2515. public function getUserId()
  2516. {
  2517. return isLogged() ? bx_get_logged_profile_id() : 0;
  2518. }
  2519. public function getUserIp()
  2520. {
  2521. return getVisitorIP();
  2522. }
  2523. public function getUserInfo($iUserId = 0)
  2524. {
  2525. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2526. return array(
  2527. $oProfile->getDisplayName(),
  2528. $oProfile->getUrl(),
  2529. $oProfile->getThumb(),
  2530. $oProfile->getUnit(),
  2531. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  2532. );
  2533. }
  2534. public function getUserInfoWithBadges($iUserId = 0)
  2535. {
  2536. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2537. return array(
  2538. $oProfile->getDisplayName(),
  2539. $oProfile->getUrl(),
  2540. $oProfile->getThumb(),
  2541. $oProfile->getUnit(),
  2542. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  2543. $oProfile->getBadges()
  2544. );
  2545. }
  2546. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  2547. {
  2548. $CNF = &$this->_oConfig->CNF;
  2549. // default visible settings
  2550. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  2551. return false;
  2552. if (!empty($aItem['visibility_custom'])) {
  2553. $oMenu = BxDolMenu::getObjectInstance($sObject);
  2554. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  2555. return false;
  2556. }
  2557. // get custom function name to check menu item visibility
  2558. $sFuncCheckAccess = false;
  2559. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  2560. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  2561. // check custom visibility settings defined in module config class
  2562. if(!isset($aContentInfo))
  2563. $aContentInfo = array();
  2564. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  2565. return false;
  2566. return true;
  2567. }
  2568. public function _isModerator ($isPerformAction = false)
  2569. {
  2570. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  2571. }
  2572. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  2573. {
  2574. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  2575. }
  2576. public function _isAdministrator ($isPerformAction = false)
  2577. {
  2578. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  2579. }
  2580. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  2581. {
  2582. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  2583. }
  2584. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  2585. {
  2586. $CNF = &$this->_oConfig->CNF;
  2587. $iContextId = isset($CNF['FIELD_ALLOW_VIEW_TO']) && (!empty($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) ? - $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
  2588. $AuditParams = array(
  2589. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2590. 'context_profile_id' => $iContextId,
  2591. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  2592. 'data' => ($bIsSaveData ? $aContentInfo : array())
  2593. );
  2594. if ($iContextId > 0)
  2595. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  2596. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  2597. return $AuditParams;
  2598. }
  2599. public function _getFavoriteListUrl ($iListId, $iProfileId)
  2600. {
  2601. $CNF = &$this->_oConfig->CNF;
  2602. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId);
  2603. }
  2604. // ====== PROTECTED METHODS
  2605. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  2606. {
  2607. $iContentId = $this->_getContent($iContentId, false);
  2608. if($iContentId === false)
  2609. return false;
  2610. bx_import('FormsEntryHelper', $this->_aModule);
  2611. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  2612. $oFormsHelper = new $sClass($this);
  2613. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  2614. }
  2615. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  2616. {
  2617. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  2618. }
  2619. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  2620. {
  2621. if (!isset($aParams['function_get_content']))
  2622. $aParams['function_get_content'] = 'getContentInfoById';
  2623. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  2624. if($mixedContent === false)
  2625. return false;
  2626. list($iContentId, $aContentInfo) = $mixedContent;
  2627. unset($aParams['function_get_content']);
  2628. if (!empty($aParams))
  2629. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  2630. else
  2631. return $this->_oTemplate->$sFunc($aContentInfo);
  2632. }
  2633. protected function _getApproveForm($iContentId, $aContentInfo)
  2634. {
  2635. $CNF = &$this->_oConfig->CNF;
  2636. $sForm = 'sys_manage';
  2637. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  2638. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  2639. $sFormDisplay = 'sys_manage_approve';
  2640. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  2641. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  2642. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  2643. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  2644. $oForm->aInputs['content_id']['value'] = $iContentId;
  2645. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  2646. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  2647. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  2648. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
  2649. 'content_id' => $iContentId,
  2650. 'content_info' => $aContentInfo,
  2651. 'override_result' => &$oForm
  2652. ));
  2653. return $oForm;
  2654. }
  2655. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  2656. {
  2657. $CNF = &$this->_oConfig->CNF;
  2658. $sETemplate = 't_ManageApprove';
  2659. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  2660. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  2661. $aEParams = array(
  2662. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2663. 'notes' => $oForm->getCleanValue('notes'),
  2664. );
  2665. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
  2666. 'content_id' => $iContentId,
  2667. 'content_info' => $aContentInfo,
  2668. 'form' => $oForm,
  2669. 'email_template' => &$sETemplate,
  2670. 'email_params' => &$aEParams
  2671. ));
  2672. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  2673. }
  2674. protected function _processModerationNotifications($aContentInfo)
  2675. {
  2676. $CNF = &$this->_oConfig->CNF;
  2677. if(empty($CNF['PARAM_AUTO_APPROVE']) || getParam($CNF['PARAM_AUTO_APPROVE']) == 'on')
  2678. return;
  2679. $aRecipients = [];
  2680. if(getParam('sys_notify_to_approve_by_role') == 'on' && bx_srv('system', 'is_module_content', [$this->_oConfig->getName()]) && !empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2681. $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2682. $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
  2683. $aRecipients = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  2684. }
  2685. $sModule = $this->getName();
  2686. if(empty($aRecipients))
  2687. $aRecipients = BxDolAclQuery::getInstance()->getProfilesByAction([
  2688. MEMBERSHIP_ACTION_EDIT_ANY_ENTRY,
  2689. MEMBERSHIP_ACTION_DELETE_ANY_ENTRY
  2690. ], [
  2691. 'module' => $sModule,
  2692. 'ids_only' => true
  2693. ]);
  2694. if(empty($aRecipients))
  2695. return;
  2696. foreach($aRecipients as $iRecipientId)
  2697. bx_alert($sModule, 'pending_approval', $aContentInfo[$CNF['FIELD_ID']], $aContentInfo[$CNF['FIELD_AUTHOR']], [
  2698. 'object_author_id' => (int)$iRecipientId
  2699. ]);
  2700. }
  2701. protected function _rss ($aArgs, $sClass = 'SearchResult')
  2702. {
  2703. $sMode = array_shift($aArgs);
  2704. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  2705. $this->_oTemplate->displayAccessDenied ($sMsg);
  2706. exit;
  2707. }
  2708. $aParams = $this->_buildRssParams($sMode, $aArgs);
  2709. bx_import ($sClass, $this->_aModule);
  2710. $sClass = $this->_aModule['class_prefix'] . $sClass;
  2711. $o = new $sClass($sMode, $aParams);
  2712. if ($o->isError)
  2713. $this->_oTemplate->displayPageNotFound ();
  2714. else
  2715. $o->outputRSS();
  2716. exit;
  2717. }
  2718. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  2719. {
  2720. if(!$iContentId)
  2721. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2722. if(!$iContentId)
  2723. return false;
  2724. if($sFuncGetContent === true)
  2725. $sFuncGetContent = 'getContentInfoById';
  2726. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  2727. return $iContentId;
  2728. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  2729. if(!$aContentInfo)
  2730. return false;
  2731. return array($iContentId, $aContentInfo);
  2732. }
  2733. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2734. {
  2735. $CNF = &$this->_oConfig->CNF;
  2736. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2737. //--- Image(s)
  2738. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2739. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2740. //--- Video(s)
  2741. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2742. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2743. //--- Files(s)
  2744. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2745. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2746. //--- Title
  2747. $sTitle = '';
  2748. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  2749. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2750. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  2751. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2752. //--- Text
  2753. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2754. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  2755. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2756. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2757. }
  2758. return array(
  2759. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2760. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2761. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2762. 'url' => $sUrl,
  2763. 'title' => $sTitle,
  2764. 'text' => $sText,
  2765. 'images' => $aImages,
  2766. 'images_attach' => $aImagesAttach,
  2767. 'videos' => $aVideos,
  2768. 'videos_attach' => $aVideosAttach,
  2769. 'files' => $aFiles,
  2770. 'files_attach' => $aFilesAttach
  2771. );
  2772. }
  2773. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2774. {
  2775. $CNF = &$this->_oConfig->CNF;
  2776. $sImage = $sImageOrig = '';
  2777. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  2778. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2779. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2780. }
  2781. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  2782. if($sImage == '' && $bImageThumb)
  2783. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2784. if($sImageOrig == '' && $bImageThumb)
  2785. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2786. if(empty($sImage))
  2787. return array();
  2788. if($sImageOrig == '')
  2789. $sImageOrig = $sImage;
  2790. return array(
  2791. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  2792. );
  2793. }
  2794. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2795. {
  2796. return array();
  2797. }
  2798. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2799. {
  2800. return array();
  2801. }
  2802. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2803. {
  2804. return array();
  2805. }
  2806. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2807. {
  2808. return array();
  2809. }
  2810. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2811. {
  2812. return array();
  2813. }
  2814. protected function _entityComments ($sObject, $iId = 0)
  2815. {
  2816. if (!$iId)
  2817. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2818. if (!$iId)
  2819. return false;
  2820. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2821. if (!$oCmts || !$oCmts->isEnabled())
  2822. return false;
  2823. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
  2824. }
  2825. protected function _getFields($iContentId)
  2826. {
  2827. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2828. if(empty($aContentInfo))
  2829. return array();
  2830. return BxDolContentInfo::formatFields($aContentInfo);
  2831. }
  2832. protected function _getFieldValue($sField, $iContentId)
  2833. {
  2834. $CNF = &$this->_oConfig->CNF;
  2835. if(empty($CNF[$sField]))
  2836. return false;
  2837. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2838. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2839. return false;
  2840. return $aContentInfo[$CNF[$sField]];
  2841. }
  2842. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2843. {
  2844. $CNF = &$this->_oConfig->CNF;
  2845. if(empty($sTranscoder) || empty($CNF[$sField]))
  2846. return false;
  2847. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2848. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2849. return false;
  2850. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2851. if(!$oImagesTranscoder)
  2852. return false;
  2853. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2854. }
  2855. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2856. {
  2857. if(!$bAsJson)
  2858. return $aResponse;
  2859. if(!empty($aAdditional) && is_array($aAdditional))
  2860. $aResponse = array_merge($aResponse, $aAdditional);
  2861. echoJson($aResponse);
  2862. exit;
  2863. }
  2864. /**
  2865. * Blocks for lables tree browsing private functions
  2866. */
  2867. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2868. {
  2869. $oLabel = BxDolLabel::getInstance();
  2870. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2871. if ($aLabel){
  2872. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2873. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2874. }
  2875. }
  2876. private function _getLablesBrowseUrl($iLabelId)
  2877. {
  2878. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2879. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2880. }
  2881. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2882. {
  2883. $oLabel = BxDolLabel::getInstance();
  2884. $aLabelsOutput = array();
  2885. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2886. if (count($aLabels) > 0){
  2887. foreach($aLabels as $aLabel) {
  2888. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2889. $bChildPresent = $sChild != '' ? true : false;
  2890. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2891. if (!$bIsOpen){
  2892. $sChild = '';
  2893. }
  2894. $aLabelsOutput[] = array(
  2895. 'value' => $aLabel['value'],
  2896. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2897. 'child' => $sChild,
  2898. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2899. 'bx_if:open' => array(
  2900. 'condition' => $bChildPresent && $bIsOpen,
  2901. 'content' => array()
  2902. ),
  2903. 'bx_if:can_open' => array(
  2904. 'condition' => $bChildPresent && !$bIsOpen,
  2905. 'content' => array()
  2906. )
  2907. );
  2908. }
  2909. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2910. array(
  2911. 'bx_repeat:items' => $aLabelsOutput,
  2912. 'parent' => $iParent,
  2913. )
  2914. );
  2915. }
  2916. return '';
  2917. }
  2918. }
  2919. /** @} */