1
0

BxBaseModGeneralModule.php 133 KB

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