BxBaseModGeneralModule.php 125 KB

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