BxBaseModGeneralModule.php 120 KB

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