BxBaseModGeneralModule.php 141 KB

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