BxBaseModGeneralModule.php 141 KB

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