BxBaseModGeneralModule.php 140 KB

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