1
0

BxBaseModGeneralModule.php 134 KB

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