1
0

BxBaseModGeneralModule.php 138 KB

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