BxBaseModGeneralModule.php 136 KB

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