1
0

BxBaseModGeneralModule.php 172 KB

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