BxBaseModGeneralModule.php 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400
  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 = array(
  1476. 'handlers' => array(
  1477. array('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. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1479. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  1480. array('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),
  1481. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1482. array('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),
  1483. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1484. array('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),
  1485. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1486. array('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),
  1487. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1488. array('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),
  1489. array('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),
  1490. ),
  1491. 'settings' => array(
  1492. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  1493. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1494. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1495. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1496. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1497. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1498. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1499. ),
  1500. 'alerts' => array(
  1501. array('unit' => $sModule, 'action' => 'added'),
  1502. array('unit' => $sModule, 'action' => 'edited'),
  1503. array('unit' => $sModule, 'action' => 'deleted'),
  1504. array('unit' => $sModule, 'action' => 'commentPost'),
  1505. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1506. array('unit' => $sModule, 'action' => 'replyPost'),
  1507. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1508. array('unit' => $sModule, 'action' => 'doVote'),
  1509. array('unit' => $sModule, 'action' => 'undoVote'),
  1510. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1511. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1512. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1513. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1514. )
  1515. );
  1516. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1517. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  1518. array('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' => ''),
  1519. array('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' => ''),
  1520. ));
  1521. $aResult['settings'] = array_merge($aResult['settings'], array(
  1522. array('group' => 'content_publish_failed', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1523. array('group' => 'content_publish_succeeded', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1524. ));
  1525. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  1526. array('unit' => $sModule, 'action' => 'publish_failed'),
  1527. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1528. ));
  1529. }
  1530. return $aResult;
  1531. }
  1532. /**
  1533. * Entry post for Notifications module
  1534. */
  1535. public function serviceGetNotificationsPost($aEvent)
  1536. {
  1537. $CNF = &$this->_oConfig->CNF;
  1538. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1539. if(empty($aContentInfo) || !is_array($aContentInfo))
  1540. return array();
  1541. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1542. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1543. return array(
  1544. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1545. 'entry_url' => $sEntryUrl,
  1546. 'entry_caption' => $sEntryCaption,
  1547. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1548. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1549. '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.
  1550. /*
  1551. * Custom settings for email and/or push notifications can be provided here.
  1552. * Only necessary parts of 'settings' array can be used.
  1553. *
  1554. 'settings' => array(
  1555. 'email' => array(
  1556. 'template' => '', //--- custom email template
  1557. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1558. 'subject' => '' //--- custom email subject
  1559. ),
  1560. 'push' => array(
  1561. 'subject' => '' //--- custom push notification subject
  1562. )
  1563. )
  1564. */
  1565. );
  1566. }
  1567. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1568. {
  1569. return $this->serviceGetNotificationsPost($aEvent);
  1570. }
  1571. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1572. {
  1573. return $this->serviceGetNotificationsPost($aEvent);
  1574. }
  1575. /**
  1576. * Entry post comment for Notifications module
  1577. */
  1578. public function serviceGetNotificationsComment($aEvent)
  1579. {
  1580. $CNF = &$this->_oConfig->CNF;
  1581. $iContentId = (int)$aEvent['object_id'];
  1582. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1583. if(empty($aContentInfo) || !is_array($aContentInfo))
  1584. return array();
  1585. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1586. if(!$oComment || !$oComment->isEnabled())
  1587. return array();
  1588. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1589. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1590. return array(
  1591. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1592. 'entry_url' => $sEntryUrl,
  1593. 'entry_caption' => $sEntryCaption,
  1594. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1595. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1596. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1597. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1598. );
  1599. }
  1600. /**
  1601. * Entry post reply for Notifications module
  1602. */
  1603. public function serviceGetNotificationsReply($aEvent)
  1604. {
  1605. $CNF = &$this->_oConfig->CNF;
  1606. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1607. if(!$oComment || !$oComment->isEnabled())
  1608. return array();
  1609. $iParentId = (int)$aEvent['object_id'];
  1610. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1611. if(empty($aParentInfo) || !is_array($aParentInfo))
  1612. return array();
  1613. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1614. $oComment->init($iObjectId);
  1615. return array(
  1616. 'object_id' => $iObjectId,
  1617. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1618. 'entry_url' => $oComment->getViewUrl($iParentId),
  1619. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1620. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1621. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1622. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1623. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1624. );
  1625. }
  1626. /**
  1627. * Entry post vote for Notifications module
  1628. */
  1629. public function serviceGetNotificationsVote($aEvent)
  1630. {
  1631. $CNF = &$this->_oConfig->CNF;
  1632. $iContentId = (int)$aEvent['object_id'];
  1633. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1634. if(empty($aContentInfo) || !is_array($aContentInfo))
  1635. return array();
  1636. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1637. if(!$oVote || !$oVote->isEnabled())
  1638. return array();
  1639. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1640. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1641. return array(
  1642. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1643. 'entry_url' => $sEntryUrl,
  1644. 'entry_caption' => $sEntryCaption,
  1645. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1646. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1647. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1648. );
  1649. }
  1650. /**
  1651. * Entry post vote for Notifications module
  1652. */
  1653. public function serviceGetNotificationsReaction($aEvent)
  1654. {
  1655. $CNF = &$this->_oConfig->CNF;
  1656. $iContentId = (int)$aEvent['object_id'];
  1657. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1658. if(empty($aContentInfo) || !is_array($aContentInfo))
  1659. return array();
  1660. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1661. if(!$oReaction || !$oReaction->isEnabled())
  1662. return array();
  1663. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1664. if(empty($aSubentry) || !is_array($aSubentry))
  1665. return array();
  1666. $aSubentrySampleParams = array();
  1667. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1668. if(!empty($aReaction['title']))
  1669. $aSubentrySampleParams[] = $aReaction['title'];
  1670. else
  1671. $aSubentrySampleParams[] = '_undefined';
  1672. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1673. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1674. return array(
  1675. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1676. 'entry_url' => $sEntryUrl,
  1677. 'entry_caption' => $sEntryCaption,
  1678. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1679. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1680. 'subentry_sample_params' => $aSubentrySampleParams,
  1681. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1682. );
  1683. }
  1684. /**
  1685. * Entry post score -> vote up for Notifications module
  1686. */
  1687. public function serviceGetNotificationsScoreUp($aEvent)
  1688. {
  1689. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1690. }
  1691. /**
  1692. * Entry post score -> vote up for Notifications module
  1693. */
  1694. public function serviceGetNotificationsScoreDown($aEvent)
  1695. {
  1696. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1697. }
  1698. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1699. {
  1700. $CNF = &$this->_oConfig->CNF;
  1701. $iContentId = (int)$aEvent['object_id'];
  1702. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1703. if(empty($aContentInfo) || !is_array($aContentInfo))
  1704. return array();
  1705. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1706. if(!$oScore || !$oScore->isEnabled())
  1707. return array();
  1708. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1709. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1710. return array(
  1711. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1712. 'entry_url' => $sEntryUrl,
  1713. 'entry_caption' => $sEntryCaption,
  1714. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1715. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1716. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1717. );
  1718. }
  1719. /**
  1720. * Data for Timeline module
  1721. */
  1722. public function serviceGetTimelineData()
  1723. {
  1724. $sModule = $this->_aModule['name'];
  1725. return array(
  1726. 'handlers' => array(
  1727. 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' => ''),
  1728. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1729. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1730. ),
  1731. 'alerts' => array(
  1732. array('unit' => $sModule, 'action' => 'added'),
  1733. array('unit' => $sModule, 'action' => 'edited'),
  1734. array('unit' => $sModule, 'action' => 'deleted'),
  1735. )
  1736. );
  1737. }
  1738. /**
  1739. * Entry post for Timeline module
  1740. */
  1741. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1742. {
  1743. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1744. if(empty($aContentInfo) || !is_array($aContentInfo))
  1745. return false;
  1746. $CNF = &$this->_oConfig->CNF;
  1747. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1748. return false;
  1749. $iUserId = $this->getUserId();
  1750. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1751. $iAuthorIdAbs = abs($iAuthorId);
  1752. 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)
  1753. return false;
  1754. //--- Views
  1755. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1756. $aViews = array();
  1757. if ($oViews && $oViews->isEnabled())
  1758. $aViews = array(
  1759. 'system' => $CNF['OBJECT_VIEWS'],
  1760. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1761. 'count' => $aContentInfo['views']
  1762. );
  1763. //--- Votes
  1764. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1765. $aVotes = array();
  1766. if ($oVotes && $oVotes->isEnabled())
  1767. $aVotes = array(
  1768. 'system' => $CNF['OBJECT_VOTES'],
  1769. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1770. 'count' => $aContentInfo['votes']
  1771. );
  1772. //--- Reactions
  1773. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1774. $aReactions = array();
  1775. if ($oReactions && $oReactions->isEnabled())
  1776. $aReactions = array(
  1777. 'system' => $CNF['OBJECT_REACTIONS'],
  1778. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1779. 'count' => $aContentInfo['rvotes']
  1780. );
  1781. //--- Scores
  1782. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1783. $aScores = array();
  1784. if ($oScores && $oScores->isEnabled())
  1785. $aScores = array(
  1786. 'system' => $CNF['OBJECT_SCORES'],
  1787. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1788. 'score' => $aContentInfo['score']
  1789. );
  1790. //--- Reports
  1791. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1792. $aReports = array();
  1793. if ($oReports && $oReports->isEnabled())
  1794. $aReports = array(
  1795. 'system' => $CNF['OBJECT_REPORTS'],
  1796. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1797. 'count' => $aContentInfo['reports']
  1798. );
  1799. //--- Comments
  1800. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1801. $aComments = array();
  1802. if($oCmts && $oCmts->isEnabled())
  1803. $aComments = array(
  1804. 'system' => $CNF['OBJECT_COMMENTS'],
  1805. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1806. 'count' => $aContentInfo['comments']
  1807. );
  1808. //--- Title & Description
  1809. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1810. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1811. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1812. $iOwnerId = $iAuthorIdAbs;
  1813. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1814. $iOwnerId = abs($aEvent['object_privacy_view']);
  1815. $bCache = true;
  1816. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1817. if(isset($aContent['_cache'])) {
  1818. $bCache = (bool)$aContent['_cache'];
  1819. unset($aContent['_cache']);
  1820. }
  1821. return array(
  1822. '_cache' => $bCache,
  1823. 'owner_id' => $iOwnerId,
  1824. 'object_owner_id' => $iAuthorId,
  1825. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1826. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1827. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1828. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1829. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1830. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1831. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1832. 'views' => $aViews,
  1833. 'votes' => $aVotes,
  1834. 'reactions' => $aReactions,
  1835. 'scores' => $aScores,
  1836. 'reports' => $aReports,
  1837. 'comments' => $aComments,
  1838. 'title' => $sTitle, //may be empty.
  1839. 'description' => '' //may be empty.
  1840. );
  1841. }
  1842. public function serviceGetTimelinePostAllowedView($aEvent)
  1843. {
  1844. $iContentId = (int)$aEvent['object_id'];
  1845. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1846. if(empty($aContentInfo) || !is_array($aContentInfo))
  1847. return _t('_sys_txt_access_denied');
  1848. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1849. }
  1850. /**
  1851. * Check particular action permission without content
  1852. * @param $sAction action to check, for example: Browse, Add
  1853. * @param $iContentId content ID
  1854. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1855. */
  1856. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1857. {
  1858. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1859. if (!method_exists($this, $sMethod))
  1860. return _t('_sys_request_method_not_found_cpt');
  1861. return $this->$sMethod($isPerformAction);
  1862. }
  1863. /**
  1864. * Check particular action permission with content
  1865. * @param $sAction action to check, for example: View, Edit
  1866. * @param $iContentId content ID
  1867. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1868. */
  1869. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1870. {
  1871. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1872. return _t('_sys_request_page_not_found_cpt');
  1873. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1874. if (!method_exists($this, $sMethod))
  1875. return _t('_sys_request_method_not_found_cpt');
  1876. return $this->$sMethod($aContentInfo, $isPerformAction);
  1877. }
  1878. /**
  1879. * Check particular action permission with content for specified profile
  1880. * @param $sAction action to check, for example: View, Edit
  1881. * @param $iContentId content ID
  1882. * @param $iProfileId profile ID which the permissions to be cheked for
  1883. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1884. */
  1885. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1886. {
  1887. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1888. return _t('_sys_request_page_not_found_cpt');
  1889. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1890. if (!method_exists($this, $sMethod))
  1891. return _t('_sys_request_method_not_found_cpt');
  1892. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1893. }
  1894. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1895. {
  1896. //negative id used in comments for reports
  1897. if ($iContentId < 0)
  1898. return CHECK_ACTION_RESULT_ALLOWED;
  1899. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1900. }
  1901. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1902. {
  1903. //negative id used in comments for reports
  1904. if ($iContentId < 0)
  1905. return CHECK_ACTION_RESULT_ALLOWED;
  1906. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1907. }
  1908. public function serviceGetContentOwnerProfileId ($iContentId)
  1909. {
  1910. $CNF = &$this->_oConfig->CNF;
  1911. // file owner must be author of the content or profile itself in case of profile based module
  1912. if ($iContentId) {
  1913. $sModule = $this->getName();
  1914. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1915. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1916. }
  1917. else {
  1918. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1919. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1920. }
  1921. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1922. }
  1923. else {
  1924. $iProfileId = bx_get_logged_profile_id();
  1925. }
  1926. return $iProfileId;
  1927. }
  1928. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1929. {
  1930. $sModule = $this->getName();
  1931. $oBadges = BxDolBadges::getInstance();
  1932. $aBadges = $oBadges->getData(array(
  1933. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1934. 'module' => $sModule,
  1935. 'object_id' => $iContentId
  1936. ));
  1937. $sResult = false;
  1938. bx_alert('system', 'get_badges', 0, 0, array(
  1939. 'module' => $sModule,
  1940. 'content_id' => $iContentId,
  1941. 'is_single' => $bIsSingle,
  1942. 'is_compact' => $bIsCompact,
  1943. 'badges' => $aBadges,
  1944. 'override_result' => &$sResult
  1945. ));
  1946. if($sResult !== false)
  1947. return $sResult;
  1948. if(empty($aBadges) || !is_array($aBadges))
  1949. return '';
  1950. if($bIsSingle)
  1951. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  1952. $aBadgesOutput = array();
  1953. foreach($aBadges as $aBadge)
  1954. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  1955. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  1956. 'bx_repeat:items' => $aBadgesOutput,
  1957. ));
  1958. }
  1959. /**
  1960. * @page service Service Calls
  1961. * @section bx_base_general Base General
  1962. * @subsection bx_base_general-page_blocks Page Blocks
  1963. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  1964. *
  1965. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  1966. *
  1967. * Display multi-categorories block with number of posts in each category
  1968. * @param $bDisplayEmptyCats display empty categories
  1969. *
  1970. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  1971. */
  1972. /**
  1973. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  1974. */
  1975. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  1976. {
  1977. $aContextInfo = bx_get_page_info();
  1978. $mProfileContextId = false;
  1979. if (isset($aContextInfo['context_module']) && isset($aContextInfo['profile_context_id'])){
  1980. $mProfileContextId = $aContextInfo['profile_context_id'];
  1981. }
  1982. $oCategories = BxDolCategories::getInstance();
  1983. if ($mProfileContextId)
  1984. $aCats = $oCategories->getData([
  1985. 'type' => 'by_module&context_with_num',
  1986. 'module' => $this->getName(),
  1987. 'context_id' => $mProfileContextId
  1988. ]);
  1989. else{
  1990. $aCats = $oCategories->getData([
  1991. 'type' => 'by_module_with_num',
  1992. 'module' => $this->getName()
  1993. ]);
  1994. }
  1995. $aVars = array('bx_repeat:cats' => array());
  1996. foreach ($aCats as $oCat) {
  1997. $sValue = $oCat['value'];
  1998. $iNum = $oCat['num'];
  1999. $aVars['bx_repeat:cats'][] = array(
  2000. 'url' => $oCategories->getUrl($this->getName(), $sValue, $mProfileContextId ? '&context_id=' . $mProfileContextId : ''),
  2001. 'name' => _t($sValue),
  2002. 'value' => $sValue,
  2003. 'num' => $iNum,
  2004. );
  2005. }
  2006. if (!$aVars['bx_repeat:cats'])
  2007. return '';
  2008. return $this->_oTemplate->parseHtmlByName('category_list_multi.html', $aVars);
  2009. }
  2010. /**
  2011. * ======
  2012. * PERMISSION METHODS
  2013. * ======
  2014. */
  2015. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  2016. {
  2017. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2018. // check alert to allow custom checks
  2019. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  2020. return $mixedResult;
  2021. }
  2022. public function checkAllowedSetThumb ($iContentId = 0)
  2023. {
  2024. return CHECK_ACTION_RESULT_ALLOWED;
  2025. }
  2026. /**
  2027. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2028. */
  2029. public function checkAllowedBrowse ()
  2030. {
  2031. // check alert to allow custom checks
  2032. $mixedResult = null;
  2033. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  2034. if($mixedResult !== null)
  2035. return $mixedResult;
  2036. return CHECK_ACTION_RESULT_ALLOWED;
  2037. }
  2038. /**
  2039. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2040. */
  2041. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  2042. {
  2043. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  2044. }
  2045. /**
  2046. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2047. */
  2048. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  2049. {
  2050. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  2051. }
  2052. /**
  2053. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2054. */
  2055. public function checkAllowedAdd ($isPerformAction = false)
  2056. {
  2057. // check ACL
  2058. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  2059. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2060. return $aCheck[CHECK_ACTION_MESSAGE];
  2061. return CHECK_ACTION_RESULT_ALLOWED;
  2062. }
  2063. /**
  2064. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2065. */
  2066. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  2067. {
  2068. // moderator always have access
  2069. if ($this->_isModerator($isPerformAction))
  2070. return CHECK_ACTION_RESULT_ALLOWED;
  2071. // check for context's admins
  2072. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2073. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2074. if ($oProfile){
  2075. $sModule = $oProfile->getModule();
  2076. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2077. $oModule = BxDolModule::getInstance($sModule);
  2078. // check for context's extra roles with rights
  2079. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2080. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2081. if ($bResult !== NULL) return $bResult;
  2082. }
  2083. // if allowed edit a group then allowed to edit anything inside its context
  2084. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2085. return CHECK_ACTION_RESULT_ALLOWED;
  2086. }
  2087. }
  2088. }
  2089. return _t('_sys_txt_access_denied');
  2090. }
  2091. /**
  2092. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2093. */
  2094. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  2095. {
  2096. // moderator and owner always have access
  2097. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  2098. return CHECK_ACTION_RESULT_ALLOWED;
  2099. // check for context's admins
  2100. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  2101. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2102. if ($oProfile){
  2103. $sModule = $oProfile->getModule();
  2104. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2105. $oModule = BxDolModule::getInstance($sModule);
  2106. // check for context's extra roles with rights
  2107. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2108. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  2109. if ($bResult !== NULL) return $bResult;
  2110. }
  2111. // if allowed edit a group then allowed to edit anything inside its context
  2112. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2113. return CHECK_ACTION_RESULT_ALLOWED;
  2114. }
  2115. }
  2116. }
  2117. return _t('_sys_txt_access_denied');
  2118. }
  2119. /**
  2120. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2121. */
  2122. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  2123. {
  2124. // moderator always has access
  2125. if ($this->_isAdministrator($isPerformAction))
  2126. return CHECK_ACTION_RESULT_ALLOWED;
  2127. // check ACL
  2128. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  2129. 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)
  2130. return CHECK_ACTION_RESULT_ALLOWED;
  2131. // check for context's admins
  2132. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  2133. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  2134. if ($oProfile){
  2135. $sModule = $oProfile->getModule();
  2136. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  2137. $oModule = BxDolModule::getInstance($sModule);
  2138. // check for context's extra roles with rights
  2139. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  2140. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  2141. if ($bResult !== NULL) return $bResult;
  2142. }
  2143. // if allowed delete a group then allowed to delete anything inside its context
  2144. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  2145. return CHECK_ACTION_RESULT_ALLOWED;
  2146. }
  2147. }
  2148. }
  2149. return _t('_sys_txt_access_denied');
  2150. }
  2151. /**
  2152. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2153. */
  2154. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2155. {
  2156. // admin always has access
  2157. if (isAdmin())
  2158. return CHECK_ACTION_RESULT_ALLOWED;
  2159. // check ACL
  2160. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2161. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2162. return $aCheck[CHECK_ACTION_MESSAGE];
  2163. return CHECK_ACTION_RESULT_ALLOWED;
  2164. }
  2165. /**
  2166. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2167. */
  2168. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2169. {
  2170. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2171. }
  2172. /**
  2173. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2174. */
  2175. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2176. {
  2177. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2178. }
  2179. /**
  2180. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2181. */
  2182. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2183. {
  2184. if(!$iProfileId)
  2185. $iProfileId = $this->_iProfileId;
  2186. $aCheck = checkActionModule($iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  2187. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2188. return CHECK_ACTION_RESULT_ALLOWED;
  2189. return _t('_sys_txt_access_denied');
  2190. }
  2191. /**
  2192. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2193. */
  2194. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2195. {
  2196. if(!$iProfileId)
  2197. $iProfileId = $this->_iProfileId;
  2198. $aCheck = checkActionModule($iProfileId, 'delete any entry', $this->getName(), $isPerformAction);
  2199. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2200. return CHECK_ACTION_RESULT_ALLOWED;
  2201. return _t('_sys_txt_access_denied');
  2202. }
  2203. /**
  2204. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2205. */
  2206. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2207. {
  2208. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2209. }
  2210. /**
  2211. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2212. */
  2213. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2214. {
  2215. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2216. }
  2217. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2218. {
  2219. $CNF = &$this->_oConfig->CNF;
  2220. if(!$iProfileId)
  2221. $iProfileId = $this->_iProfileId;
  2222. if(empty($aDataEntry) || !is_array($aDataEntry))
  2223. return _t('_sys_txt_not_found');
  2224. // moderator and owner always have access
  2225. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2226. return CHECK_ACTION_RESULT_ALLOWED;
  2227. // check ACL
  2228. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2229. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2230. return $aCheck[CHECK_ACTION_MESSAGE];
  2231. // check privacy
  2232. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2233. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2234. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2235. return _t('_sys_access_denied_to_private_content');
  2236. }
  2237. return CHECK_ACTION_RESULT_ALLOWED;
  2238. }
  2239. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2240. {
  2241. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2242. return MsgBox($sMsg);
  2243. bx_import($sClassSearchResult, $this->_aModule);
  2244. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2245. $o = new $sClass($sMode, $aParams);
  2246. $o->setDesignBoxTemplateId($iDesignBox);
  2247. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2248. $o->setAjaxPaginate($bAjaxPaginate);
  2249. $o->setUnitParams(array('context' => $sMode));
  2250. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2251. $o->setCustomCurrentCondition($aParams['condition']);
  2252. if ($o->isError)
  2253. return '';
  2254. if ($s = $o->processing())
  2255. return $s;
  2256. else
  2257. return '';
  2258. }
  2259. /**
  2260. * Shows a list of profiles.
  2261. */
  2262. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2263. {
  2264. // get paginate object
  2265. $oPaginate = new BxTemplPaginate(array(
  2266. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2267. 'num' => count($aProfiles),
  2268. 'per_page' => $iLimit,
  2269. 'start' => $iStart,
  2270. ));
  2271. // remove last item from connection array, because we've got one more item for pagination calculations only
  2272. if (count($aProfiles) > $iLimit)
  2273. array_pop($aProfiles);
  2274. // get profiles HTML
  2275. $s = '';
  2276. foreach ($aProfiles as $mixedProfile) {
  2277. $bProfile = is_array($mixedProfile);
  2278. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2279. if(!$oProfile)
  2280. continue;
  2281. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2282. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2283. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2284. if($bProfile && is_array($mixedProfile['info']))
  2285. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2286. $s .= $oProfile->getUnit(0, $aUnitParams);
  2287. }
  2288. $aTmplVarsPaginate = [];
  2289. if($iStart || $oPaginate->getNum() > $iLimit)
  2290. $aTmplVarsPaginate = ['paginate' => $oPaginate->getSimplePaginate()];
  2291. return $this->_oTemplate->parseHtmlByName('browse_quick.html', array(
  2292. 'code' => $s,
  2293. 'bx_if:show_paginate' => [
  2294. 'condition' => !empty($aTmplVarsPaginate),
  2295. 'content' => $aTmplVarsPaginate
  2296. ]
  2297. ));
  2298. }
  2299. // ====== COMMON METHODS
  2300. public function onPublished($iContentId)
  2301. {
  2302. $CNF = &$this->_oConfig->CNF;
  2303. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2304. if(!$aContentInfo)
  2305. return;
  2306. $aParams = $this->_alertParams($aContentInfo);
  2307. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2308. }
  2309. public function onFailed($iContentId)
  2310. {
  2311. $CNF = &$this->_oConfig->CNF;
  2312. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2313. if(!$aContentInfo)
  2314. return;
  2315. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  2316. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2317. }
  2318. public function onApprove($mixedContent)
  2319. {
  2320. $CNF = &$this->_oConfig->CNF;
  2321. if(!is_array($mixedContent))
  2322. $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
  2323. $this->alertAfterApprove($mixedContent);
  2324. $this->onPublished($mixedContent[$CNF['FIELD_ID']]);
  2325. }
  2326. public function alertAfterAdd($aContentInfo) {}
  2327. public function alertAfterEdit($aContentInfo) {}
  2328. public function alertAfterApprove($aContentInfo)
  2329. {
  2330. $CNF = &$this->_oConfig->CNF;
  2331. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  2332. $aParams = $this->_alertParams($aContentInfo);
  2333. bx_alert($this->getName(), 'approved', $iId, false, $aParams);
  2334. }
  2335. /**
  2336. * Get array of params to be passed in Add/Edit Alert.
  2337. */
  2338. protected function _alertParams($aContentInfo)
  2339. {
  2340. $CNF = &$this->_oConfig->CNF;
  2341. return array(
  2342. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2343. );
  2344. }
  2345. public function processMetasAdd($iContentId)
  2346. {
  2347. $CNF = &$this->_oConfig->CNF;
  2348. if(empty($CNF['OBJECT_METATAGS']))
  2349. return false;
  2350. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2351. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2352. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2353. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2354. if(!$bContentInfo)
  2355. return false;
  2356. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2357. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2358. $sKey = 'FIELD_LOCATION';
  2359. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2360. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2361. if(!empty($aLocation) && is_array($aLocation))
  2362. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2363. }
  2364. $sKey = 'FIELD_LABELS';
  2365. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2366. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2367. if(!empty($aLabels) && is_array($aLabels))
  2368. foreach ($aLabels as $sLabel)
  2369. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2370. }
  2371. return true;
  2372. }
  2373. public function processMetasEdit($iContentId, $oForm)
  2374. {
  2375. $CNF = &$this->_oConfig->CNF;
  2376. if(empty($CNF['OBJECT_METATAGS']))
  2377. return false;
  2378. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2379. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2380. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2381. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2382. if(!$bContentInfo)
  2383. return false;
  2384. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2385. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2386. $sKey = 'FIELD_LOCATION';
  2387. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2388. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2389. if(!empty($aLocation) && is_array($aLocation))
  2390. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2391. }
  2392. $sKey = 'FIELD_LABELS';
  2393. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2394. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2395. if(!empty($aLabels) && is_array($aLabels))
  2396. foreach ($aLabels as $sLabel)
  2397. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2398. }
  2399. return true;
  2400. }
  2401. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  2402. {
  2403. if(empty($aTranscoders))
  2404. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  2405. $CNF = &$this->_oConfig->CNF;
  2406. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  2407. return false;
  2408. $iId = (int)$aContentInfo[$CNF[$sField]];
  2409. foreach($aTranscoders as $sTranscoder)
  2410. if(!empty($CNF[$sTranscoder]))
  2411. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  2412. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2413. }
  2414. public function getProfileId()
  2415. {
  2416. return bx_get_logged_profile_id();
  2417. }
  2418. public function getProfileInfo($iUserId = false)
  2419. {
  2420. $oProfile = $this->getObjectUser($iUserId);
  2421. $oAccount = null;
  2422. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  2423. $oAccount = $oProfile->getAccountObject();
  2424. $bAccount = !empty($oAccount);
  2425. if(!$bAccount)
  2426. $oProfile = BxDolProfileUndefined::getInstance();
  2427. return array(
  2428. 'id' => $oProfile->id(),
  2429. 'name' => $oProfile->getDisplayName(),
  2430. 'email' => $bAccount ? $oAccount->getEmail() : '',
  2431. 'link' => $oProfile->getUrl(),
  2432. 'icon' => $oProfile->getIcon(),
  2433. 'thumb' => $oProfile->getThumb(),
  2434. 'avatar' => $oProfile->getAvatar(),
  2435. 'unit' => $oProfile->getUnit(),
  2436. 'active' => $oProfile->isActive(),
  2437. );
  2438. }
  2439. public function getObjectUser($iUserId = false)
  2440. {
  2441. bx_import('BxDolProfile');
  2442. return BxDolProfile::getInstanceMagic($iUserId);
  2443. }
  2444. public function getObjectFavorite($sSystem = '', $iId = 0)
  2445. {
  2446. $CNF = &$this->_oConfig->CNF;
  2447. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  2448. $sSystem = $CNF['OBJECT_FAVORITES'];
  2449. if(empty($sSystem))
  2450. return false;
  2451. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2452. if(!$oFavorite || !$oFavorite->isEnabled())
  2453. return false;
  2454. return $oFavorite;
  2455. }
  2456. public function getUserId()
  2457. {
  2458. return isLogged() ? bx_get_logged_profile_id() : 0;
  2459. }
  2460. public function getUserIp()
  2461. {
  2462. return getVisitorIP();
  2463. }
  2464. public function getUserInfo($iUserId = 0)
  2465. {
  2466. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2467. return array(
  2468. $oProfile->getDisplayName(),
  2469. $oProfile->getUrl(),
  2470. $oProfile->getThumb(),
  2471. $oProfile->getUnit(),
  2472. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  2473. );
  2474. }
  2475. public function getUserInfoWithBadges($iUserId = 0)
  2476. {
  2477. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2478. return array(
  2479. $oProfile->getDisplayName(),
  2480. $oProfile->getUrl(),
  2481. $oProfile->getThumb(),
  2482. $oProfile->getUnit(),
  2483. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  2484. $oProfile->getBadges()
  2485. );
  2486. }
  2487. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  2488. {
  2489. $CNF = &$this->_oConfig->CNF;
  2490. // default visible settings
  2491. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  2492. return false;
  2493. if (!empty($aItem['visibility_custom'])) {
  2494. $oMenu = BxDolMenu::getObjectInstance($sObject);
  2495. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  2496. return false;
  2497. }
  2498. // get custom function name to check menu item visibility
  2499. $sFuncCheckAccess = false;
  2500. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  2501. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  2502. // check custom visibility settings defined in module config class
  2503. if(!isset($aContentInfo))
  2504. $aContentInfo = array();
  2505. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  2506. return false;
  2507. return true;
  2508. }
  2509. public function _isModerator ($isPerformAction = false)
  2510. {
  2511. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  2512. }
  2513. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  2514. {
  2515. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  2516. }
  2517. public function _isAdministrator ($isPerformAction = false)
  2518. {
  2519. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  2520. }
  2521. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  2522. {
  2523. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  2524. }
  2525. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  2526. {
  2527. $CNF = &$this->_oConfig->CNF;
  2528. $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;
  2529. $AuditParams = array(
  2530. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2531. 'context_profile_id' => $iContextId,
  2532. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  2533. 'data' => ($bIsSaveData ? $aContentInfo : array())
  2534. );
  2535. if ($iContextId > 0)
  2536. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  2537. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  2538. return $AuditParams;
  2539. }
  2540. public function _getFavoriteListUrl ($iListId, $iProfileId)
  2541. {
  2542. $CNF = &$this->_oConfig->CNF;
  2543. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId);
  2544. }
  2545. // ====== PROTECTED METHODS
  2546. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  2547. {
  2548. $iContentId = $this->_getContent($iContentId, false);
  2549. if($iContentId === false)
  2550. return false;
  2551. bx_import('FormsEntryHelper', $this->_aModule);
  2552. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  2553. $oFormsHelper = new $sClass($this);
  2554. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  2555. }
  2556. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  2557. {
  2558. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => $sFuncGetContent));
  2559. }
  2560. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  2561. {
  2562. if (!isset($aParams['function_get_content']))
  2563. $aParams['function_get_content'] = 'getContentInfoById';
  2564. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  2565. if($mixedContent === false)
  2566. return false;
  2567. list($iContentId, $aContentInfo) = $mixedContent;
  2568. unset($aParams['function_get_content']);
  2569. if (!empty($aParams))
  2570. return $this->_oTemplate->$sFunc($aContentInfo, $aParams);
  2571. else
  2572. return $this->_oTemplate->$sFunc($aContentInfo);
  2573. }
  2574. protected function _getApproveForm($iContentId, $aContentInfo)
  2575. {
  2576. $CNF = &$this->_oConfig->CNF;
  2577. $sForm = 'sys_manage';
  2578. if(!empty($CNF['OBJECT_FORM_MANAGE']))
  2579. $sForm = $CNF['OBJECT_FORM_MANAGE'];
  2580. $sFormDisplay = 'sys_manage_approve';
  2581. if(!empty($CNF['OBJECT_FORM_MANAGE_APPROVE']))
  2582. $sFormDisplay = $CNF['OBJECT_FORM_MANAGE_APPROVE'];
  2583. $oForm = BxTemplFormView::getObjectInstance($sForm, $sFormDisplay);
  2584. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'approve';
  2585. $oForm->aInputs['content_id']['value'] = $iContentId;
  2586. foreach($oForm->aInputs['controls'] as $iKey => $mixedValue)
  2587. if(is_numeric($iKey) && isset($mixedValue['name']) && $mixedValue['name'] == 'do_submit')
  2588. $oForm->aInputs['controls'][$iKey]['value'] = _t('_sys_form_manage_input_do_submit_approve');
  2589. bx_alert($this->_oConfig->getName(), 'get_approve_form', 0, 0, array(
  2590. 'content_id' => $iContentId,
  2591. 'content_info' => $aContentInfo,
  2592. 'override_result' => &$oForm
  2593. ));
  2594. return $oForm;
  2595. }
  2596. protected function _sendApproveMessage($iContentId, $aContentInfo, &$oForm)
  2597. {
  2598. $CNF = &$this->_oConfig->CNF;
  2599. $sETemplate = 't_ManageApprove';
  2600. if(!empty($CNF['ETEMPLATE_MANAGE_APPROVE']))
  2601. $sETemplate = $CNF['ETEMPLATE_MANAGE_APPROVE'];
  2602. $aEParams = array(
  2603. 'content_title' => !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2604. 'notes' => $oForm->getCleanValue('notes'),
  2605. );
  2606. bx_alert($this->_oConfig->getName(), 'get_approve_message', 0, 0, array(
  2607. 'content_id' => $iContentId,
  2608. 'content_info' => $aContentInfo,
  2609. 'form' => $oForm,
  2610. 'email_template' => &$sETemplate,
  2611. 'email_params' => &$aEParams
  2612. ));
  2613. return sendMailTemplate($sETemplate, 0, $aContentInfo[$CNF['FIELD_AUTHOR']], $aEParams);
  2614. }
  2615. protected function _rss ($aArgs, $sClass = 'SearchResult')
  2616. {
  2617. $sMode = array_shift($aArgs);
  2618. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  2619. $this->_oTemplate->displayAccessDenied ($sMsg);
  2620. exit;
  2621. }
  2622. $aParams = $this->_buildRssParams($sMode, $aArgs);
  2623. bx_import ($sClass, $this->_aModule);
  2624. $sClass = $this->_aModule['class_prefix'] . $sClass;
  2625. $o = new $sClass($sMode, $aParams);
  2626. if ($o->isError)
  2627. $this->_oTemplate->displayPageNotFound ();
  2628. else
  2629. $o->outputRSS();
  2630. exit;
  2631. }
  2632. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  2633. {
  2634. if(!$iContentId)
  2635. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2636. if(!$iContentId)
  2637. return false;
  2638. if($sFuncGetContent === true)
  2639. $sFuncGetContent = 'getContentInfoById';
  2640. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  2641. return $iContentId;
  2642. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  2643. if(!$aContentInfo)
  2644. return false;
  2645. return array($iContentId, $aContentInfo);
  2646. }
  2647. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2648. {
  2649. $CNF = &$this->_oConfig->CNF;
  2650. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2651. //--- Image(s)
  2652. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2653. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2654. //--- Video(s)
  2655. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2656. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2657. //--- Files(s)
  2658. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2659. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2660. //--- Title
  2661. $sTitle = '';
  2662. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  2663. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2664. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  2665. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2666. //--- Text
  2667. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2668. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  2669. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2670. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2671. }
  2672. return array(
  2673. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2674. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2675. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2676. 'url' => $sUrl,
  2677. 'title' => $sTitle,
  2678. 'text' => $sText,
  2679. 'images' => $aImages,
  2680. 'images_attach' => $aImagesAttach,
  2681. 'videos' => $aVideos,
  2682. 'videos_attach' => $aVideosAttach,
  2683. 'files' => $aFiles,
  2684. 'files_attach' => $aFilesAttach
  2685. );
  2686. }
  2687. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2688. {
  2689. $CNF = &$this->_oConfig->CNF;
  2690. $sImage = $sImageOrig = '';
  2691. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  2692. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2693. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2694. }
  2695. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  2696. if($sImage == '' && $bImageThumb)
  2697. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2698. if($sImageOrig == '' && $bImageThumb)
  2699. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2700. if(empty($sImage))
  2701. return array();
  2702. if($sImageOrig == '')
  2703. $sImageOrig = $sImage;
  2704. return array(
  2705. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  2706. );
  2707. }
  2708. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2709. {
  2710. return array();
  2711. }
  2712. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2713. {
  2714. return array();
  2715. }
  2716. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2717. {
  2718. return array();
  2719. }
  2720. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2721. {
  2722. return array();
  2723. }
  2724. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2725. {
  2726. return array();
  2727. }
  2728. protected function _entityComments ($sObject, $iId = 0)
  2729. {
  2730. if (!$iId)
  2731. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2732. if (!$iId)
  2733. return false;
  2734. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2735. if (!$oCmts || !$oCmts->isEnabled())
  2736. return false;
  2737. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
  2738. }
  2739. protected function _getFields($iContentId)
  2740. {
  2741. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2742. if(empty($aContentInfo))
  2743. return array();
  2744. return BxDolContentInfo::formatFields($aContentInfo);
  2745. }
  2746. protected function _getFieldValue($sField, $iContentId)
  2747. {
  2748. $CNF = &$this->_oConfig->CNF;
  2749. if(empty($CNF[$sField]))
  2750. return false;
  2751. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2752. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2753. return false;
  2754. return $aContentInfo[$CNF[$sField]];
  2755. }
  2756. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2757. {
  2758. $CNF = &$this->_oConfig->CNF;
  2759. if(empty($sTranscoder) || empty($CNF[$sField]))
  2760. return false;
  2761. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2762. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2763. return false;
  2764. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2765. if(!$oImagesTranscoder)
  2766. return false;
  2767. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2768. }
  2769. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2770. {
  2771. if(!$bAsJson)
  2772. return $aResponse;
  2773. if(!empty($aAdditional) && is_array($aAdditional))
  2774. $aResponse = array_merge($aResponse, $aAdditional);
  2775. echoJson($aResponse);
  2776. exit;
  2777. }
  2778. /**
  2779. * Blocks for lables tree browsing private functions
  2780. */
  2781. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2782. {
  2783. $oLabel = BxDolLabel::getInstance();
  2784. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2785. if ($aLabel){
  2786. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2787. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2788. }
  2789. }
  2790. private function _getLablesBrowseUrl($iLabelId)
  2791. {
  2792. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2793. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2794. }
  2795. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2796. {
  2797. $oLabel = BxDolLabel::getInstance();
  2798. $aLabelsOutput = array();
  2799. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2800. if (count($aLabels) > 0){
  2801. foreach($aLabels as $aLabel) {
  2802. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2803. $bChildPresent = $sChild != '' ? true : false;
  2804. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2805. if (!$bIsOpen){
  2806. $sChild = '';
  2807. }
  2808. $aLabelsOutput[] = array(
  2809. 'value' => $aLabel['value'],
  2810. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2811. 'child' => $sChild,
  2812. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2813. 'bx_if:open' => array(
  2814. 'condition' => $bChildPresent && $bIsOpen,
  2815. 'content' => array()
  2816. ),
  2817. 'bx_if:can_open' => array(
  2818. 'condition' => $bChildPresent && !$bIsOpen,
  2819. 'content' => array()
  2820. )
  2821. );
  2822. }
  2823. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2824. array(
  2825. 'bx_repeat:items' => $aLabelsOutput,
  2826. 'parent' => $iParent,
  2827. )
  2828. );
  2829. }
  2830. return '';
  2831. }
  2832. }
  2833. /** @} */