BxBaseModGeneralModule.php 153 KB

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