BxBaseModGeneralModule.php 146 KB

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