BxBaseModGeneralModule.php 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118
  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-page_blocks Page Blocks
  1156. * @subsubsection bx_base_general-reports_count_by_status reports_count_by_status
  1157. *
  1158. * @code bx_srv('bx_posts', 'reports_count_by_status', [...]); @endcode
  1159. *
  1160. * Get number of reports with specified status
  1161. * @param $iStatus status ID
  1162. *
  1163. * @see BxBaseModGeneralModule::serviceReportsCountByStatus
  1164. */
  1165. /**
  1166. * @ref bx_base_general-entity_reports "entity_reports"
  1167. */
  1168. public function serviceReportsCountByStatus ($iStatus)
  1169. {
  1170. $CNF = &$this->_oConfig->CNF;
  1171. if (!isset($CNF['OBJECT_REPORTS']) || !isset($CNF['OBJECT_NOTES']))
  1172. return false;
  1173. $oReport = BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], 0, false);
  1174. return $oReport->getCountByStatus($iStatus);
  1175. }
  1176. /**
  1177. * @page service Service Calls
  1178. * @section bx_base_general Base General
  1179. * @subsection bx_base_general-menu Menu
  1180. * @subsubsection bx_base_general-entity_social_sharing entity_social_sharing
  1181. *
  1182. * @code bx_srv('bx_posts', 'entity_social_sharing', [...]); @endcode
  1183. *
  1184. * Entry social sharing actions
  1185. * @param $mixedContent content ID or array with integer content ID and
  1186. * array with content info, or false
  1187. * @param $aParams array with additional custom params
  1188. * which may overwrite some default values
  1189. *
  1190. * @see BxBaseModGeneralModule::serviceEntitySocialSharing
  1191. */
  1192. /**
  1193. * @ref bx_base_general-entity_social_sharing "entity_social_sharing"
  1194. */
  1195. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  1196. {
  1197. if(!empty($mixedContent)) {
  1198. if(!is_array($mixedContent))
  1199. $mixedContent = array((int)$mixedContent, array());
  1200. }
  1201. else {
  1202. $mixedContent = $this->_getContent();
  1203. if($mixedContent === false)
  1204. return false;
  1205. }
  1206. list($iContentId, $aContentInfo) = $mixedContent;
  1207. $CNF = &$this->_oConfig->CNF;
  1208. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  1209. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  1210. $sUri = $CNF['URI_VIEW_ENTRY'];
  1211. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  1212. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  1213. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  1214. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1215. $aMarkers = array(
  1216. 'id' => $iContentId,
  1217. 'module' => $this->_aModule['name'],
  1218. 'url' => BX_DOL_URL_ROOT . $sUrl,
  1219. 'title' => $sTitle,
  1220. );
  1221. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  1222. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  1223. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  1224. if ($iIdThumb) {
  1225. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  1226. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  1227. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  1228. $sStorage = $CNF['OBJECT_STORAGE'];
  1229. if(!empty($sTranscoder))
  1230. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  1231. else if(!empty($sStorage))
  1232. $o = BxDolStorage::getObjectInstance($sStorage);
  1233. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  1234. if($sImgUrl)
  1235. $aMarkers['img_url'] = $sImgUrl;
  1236. }
  1237. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  1238. $oMenu->addMarkers($aMarkers);
  1239. $sMenu = $oMenu->getCode();
  1240. if(empty($sMenu))
  1241. return '';
  1242. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  1243. 'menu' => $sMenu
  1244. ));
  1245. }
  1246. /**
  1247. * Entry context block
  1248. */
  1249. public function serviceEntityContext ($iContentId = 0)
  1250. {
  1251. return $this->_serviceTemplateFunc ('entryContext', $iContentId);
  1252. }
  1253. /**
  1254. * Blocks for lables tree browsing
  1255. */
  1256. public function serviceGetLablesTree()
  1257. {
  1258. $aBreadcrumbs = array();
  1259. $this->_getLablesBreadcrumbsArray(bx_get('label'), $aBreadcrumbs);
  1260. return $this->_getLablesTreeLevel($aBreadcrumbs);
  1261. }
  1262. public function serviceGetLablesBreadcrumbs()
  1263. {
  1264. if (bx_get('label')){
  1265. $aBreadcrumbs = array();
  1266. $this->_getLablesBreadcrumbsArray(bx_process_input(bx_get('label'), BX_DATA_INT), $aBreadcrumbs);
  1267. $aLabels = array();
  1268. foreach (array_reverse($aBreadcrumbs) as $aLabel){
  1269. $aLabels[] = array(
  1270. 'value' => $aLabel['value'],
  1271. 'url' => $this->_getLablesBrowseUrl($aLabel['id'])
  1272. );
  1273. }
  1274. return $this->_oTemplate->parseHtmlByName('labels_breadcrumbs.html', array('bx_repeat:items' => $aLabels));
  1275. }
  1276. return '';
  1277. }
  1278. public function serviceBrowseByLabel()
  1279. {
  1280. $CNF = &$this->_oConfig->CNF;
  1281. if (empty($CNF['OBJECT_METATAGS']))
  1282. return '';
  1283. $sMode = 'recent';
  1284. $sClassSearchResult ='SearchResult';
  1285. bx_import($sClassSearchResult, $this->_aModule['name']);
  1286. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1287. $o = new $sClass($sMode, false);
  1288. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1289. $o->setDisplayEmptyMsg(true);
  1290. $o->setAjaxPaginate(false);
  1291. $o->setUnitParams(array('context' => $sMode));
  1292. if (bx_get('label')){
  1293. $iLabelId = (int)bx_get('label');
  1294. $oLabel = BxDolLabel::getInstance();
  1295. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  1296. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1297. $sTmp =$oMetatags->keywordsSetSearchCondition($o, $aLabel['value']);
  1298. }
  1299. if ($o->isError)
  1300. return '';
  1301. if ($s = $o->processing())
  1302. return $s;
  1303. else
  1304. return '';
  1305. }
  1306. public function serviceBrowseByCategories($sUnitView, $bEmptyMessage, $bAjaxPaginate, $sMode, $iPerPage)
  1307. {
  1308. $CNF = &$this->_oConfig->CNF;
  1309. $sClassSearchResult ='SearchResult';
  1310. bx_import($sClassSearchResult, $this->_aModule['name']);
  1311. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1312. $o = new $sClass($sMode, array('unit_view' => $sUnitView, 'paginate' => array('perPage' => 10, 'start' => 0, 'num' => 11)));
  1313. $o->setDesignBoxTemplateId(BX_DB_PADDING_DEF);
  1314. $o->setAjaxPaginate($bAjaxPaginate);
  1315. $o->setCategoryObject('multi');
  1316. $aCategoriesOutput = array();
  1317. $aCategories = BxDolCategories::getInstance()->getData(array('type' => 'by_module_with_num', 'module' => $this->_aModule['name']));
  1318. foreach($aCategories as $aCategory){
  1319. if ($aCategory['num'] > 0){
  1320. $o->setCustomSearchCondition(array('keyword' => $aCategory['value']));
  1321. $o->setPaginatePerPage(2);
  1322. if (!$o->isError){
  1323. $aResult = $o->processing();
  1324. if ($aResult && $aResult['content'] != '')
  1325. $aCategoriesOutput[] = array('name' => _t($aCategory['value']), 'url' => '', 'content' => $aResult['content']);
  1326. }
  1327. }
  1328. }
  1329. return $this->_oTemplate->parseHtmlByName('browse_by_categories.html', array(
  1330. 'bx_repeat:categories' => $aCategoriesOutput,
  1331. ));
  1332. }
  1333. /**
  1334. * Data for Notifications module
  1335. */
  1336. public function serviceGetNotificationsData()
  1337. {
  1338. $sModule = $this->_aModule['name'];
  1339. $sEventPrivacy = $sModule . '_allow_view_event_to';
  1340. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  1341. $sEventPrivacy = '';
  1342. $aResult = array(
  1343. 'handlers' => array(
  1344. 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),
  1345. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1346. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  1347. 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),
  1348. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1349. 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),
  1350. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  1351. 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),
  1352. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1353. 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),
  1354. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1355. 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),
  1356. 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),
  1357. ),
  1358. 'settings' => array(
  1359. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  1360. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1361. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  1362. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1363. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1364. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1365. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1366. ),
  1367. 'alerts' => array(
  1368. array('unit' => $sModule, 'action' => 'added'),
  1369. array('unit' => $sModule, 'action' => 'edited'),
  1370. array('unit' => $sModule, 'action' => 'deleted'),
  1371. array('unit' => $sModule, 'action' => 'commentPost'),
  1372. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1373. array('unit' => $sModule, 'action' => 'replyPost'),
  1374. array('unit' => $sModule, 'action' => 'replyRemoved'),
  1375. array('unit' => $sModule, 'action' => 'doVote'),
  1376. array('unit' => $sModule, 'action' => 'undoVote'),
  1377. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1378. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1379. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1380. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1381. )
  1382. );
  1383. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  1384. $aResult['handlers'] = array_merge($aResult['handlers'], array(
  1385. 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' => ''),
  1386. 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' => ''),
  1387. ));
  1388. $aResult['settings'] = array_merge($aResult['settings'], array(
  1389. array('group' => 'content_publish_failed', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1390. array('group' => 'content_publish_succeeded', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1391. ));
  1392. $aResult['alerts'] = array_merge($aResult['alerts'], array(
  1393. array('unit' => $sModule, 'action' => 'publish_failed'),
  1394. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1395. ));
  1396. }
  1397. return $aResult;
  1398. }
  1399. /**
  1400. * Entry post for Notifications module
  1401. */
  1402. public function serviceGetNotificationsPost($aEvent)
  1403. {
  1404. $CNF = &$this->_oConfig->CNF;
  1405. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1406. if(empty($aContentInfo) || !is_array($aContentInfo))
  1407. return array();
  1408. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1409. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1410. return array(
  1411. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1412. 'entry_url' => $sEntryUrl,
  1413. 'entry_caption' => $sEntryCaption,
  1414. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1415. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  1416. '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.
  1417. /*
  1418. * Custom settings for email and/or push notifications can be provided here.
  1419. * Only necessary parts of 'settings' array can be used.
  1420. *
  1421. 'settings' => array(
  1422. 'email' => array(
  1423. 'template' => '', //--- custom email template
  1424. 'markers' => '', //--- markers to parse email parts (subject, body) with
  1425. 'subject' => '' //--- custom email subject
  1426. ),
  1427. 'push' => array(
  1428. 'subject' => '' //--- custom push notification subject
  1429. )
  1430. )
  1431. */
  1432. );
  1433. }
  1434. public function serviceGetNotificationsPostPublishFailed($aEvent)
  1435. {
  1436. return $this->serviceGetNotificationsPost($aEvent);
  1437. }
  1438. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  1439. {
  1440. return $this->serviceGetNotificationsPost($aEvent);
  1441. }
  1442. /**
  1443. * Entry post comment for Notifications module
  1444. */
  1445. public function serviceGetNotificationsComment($aEvent)
  1446. {
  1447. $CNF = &$this->_oConfig->CNF;
  1448. $iContentId = (int)$aEvent['object_id'];
  1449. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1450. if(empty($aContentInfo) || !is_array($aContentInfo))
  1451. return array();
  1452. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  1453. if(!$oComment || !$oComment->isEnabled())
  1454. return array();
  1455. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1456. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1457. return array(
  1458. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1459. 'entry_url' => $sEntryUrl,
  1460. 'entry_caption' => $sEntryCaption,
  1461. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1462. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1463. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1464. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1465. );
  1466. }
  1467. /**
  1468. * Entry post reply for Notifications module
  1469. */
  1470. public function serviceGetNotificationsReply($aEvent)
  1471. {
  1472. $CNF = &$this->_oConfig->CNF;
  1473. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  1474. if(!$oComment || !$oComment->isEnabled())
  1475. return array();
  1476. $iParentId = (int)$aEvent['object_id'];
  1477. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  1478. if(empty($aParentInfo) || !is_array($aParentInfo))
  1479. return array();
  1480. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  1481. $oComment->init($iObjectId);
  1482. return array(
  1483. 'object_id' => $iObjectId,
  1484. 'entry_sample' => '_cmt_txt_sample_comment_single',
  1485. 'entry_url' => $oComment->getViewUrl($iParentId),
  1486. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  1487. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  1488. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  1489. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  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 serviceGetNotificationsVote($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. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  1504. if(!$oVote || !$oVote->isEnabled())
  1505. return array();
  1506. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1507. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1508. return array(
  1509. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1510. 'entry_url' => $sEntryUrl,
  1511. 'entry_caption' => $sEntryCaption,
  1512. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1513. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1514. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1515. );
  1516. }
  1517. /**
  1518. * Entry post vote for Notifications module
  1519. */
  1520. public function serviceGetNotificationsReaction($aEvent)
  1521. {
  1522. $CNF = &$this->_oConfig->CNF;
  1523. $iContentId = (int)$aEvent['object_id'];
  1524. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1525. if(empty($aContentInfo) || !is_array($aContentInfo))
  1526. return array();
  1527. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  1528. if(!$oReaction || !$oReaction->isEnabled())
  1529. return array();
  1530. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1531. if(empty($aSubentry) || !is_array($aSubentry))
  1532. return array();
  1533. $aSubentrySampleParams = array();
  1534. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1535. if(!empty($aReaction['title']))
  1536. $aSubentrySampleParams[] = $aReaction['title'];
  1537. else
  1538. $aSubentrySampleParams[] = '_undefined';
  1539. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1540. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1541. return array(
  1542. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1543. 'entry_url' => $sEntryUrl,
  1544. 'entry_caption' => $sEntryCaption,
  1545. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1546. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1547. 'subentry_sample_params' => $aSubentrySampleParams,
  1548. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1549. );
  1550. }
  1551. /**
  1552. * Entry post score -> vote up for Notifications module
  1553. */
  1554. public function serviceGetNotificationsScoreUp($aEvent)
  1555. {
  1556. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1557. }
  1558. /**
  1559. * Entry post score -> vote up for Notifications module
  1560. */
  1561. public function serviceGetNotificationsScoreDown($aEvent)
  1562. {
  1563. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1564. }
  1565. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1566. {
  1567. $CNF = &$this->_oConfig->CNF;
  1568. $iContentId = (int)$aEvent['object_id'];
  1569. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1570. if(empty($aContentInfo) || !is_array($aContentInfo))
  1571. return array();
  1572. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  1573. if(!$oScore || !$oScore->isEnabled())
  1574. return array();
  1575. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1576. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1577. return array(
  1578. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1579. 'entry_url' => $sEntryUrl,
  1580. 'entry_caption' => $sEntryCaption,
  1581. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  1582. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1583. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1584. );
  1585. }
  1586. /**
  1587. * Data for Timeline module
  1588. */
  1589. public function serviceGetTimelineData()
  1590. {
  1591. $sModule = $this->_aModule['name'];
  1592. return array(
  1593. 'handlers' => array(
  1594. 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' => ''),
  1595. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  1596. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  1597. ),
  1598. 'alerts' => array(
  1599. array('unit' => $sModule, 'action' => 'added'),
  1600. array('unit' => $sModule, 'action' => 'edited'),
  1601. array('unit' => $sModule, 'action' => 'deleted'),
  1602. )
  1603. );
  1604. }
  1605. /**
  1606. * Entry post for Timeline module
  1607. */
  1608. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1609. {
  1610. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1611. if(empty($aContentInfo) || !is_array($aContentInfo))
  1612. return false;
  1613. $CNF = &$this->_oConfig->CNF;
  1614. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  1615. return false;
  1616. $iUserId = $this->getUserId();
  1617. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1618. $iAuthorIdAbs = abs($iAuthorId);
  1619. 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)
  1620. return false;
  1621. //--- Views
  1622. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1623. $aViews = array();
  1624. if ($oViews && $oViews->isEnabled())
  1625. $aViews = array(
  1626. 'system' => $CNF['OBJECT_VIEWS'],
  1627. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1628. 'count' => $aContentInfo['views']
  1629. );
  1630. //--- Votes
  1631. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1632. $aVotes = array();
  1633. if ($oVotes && $oVotes->isEnabled())
  1634. $aVotes = array(
  1635. 'system' => $CNF['OBJECT_VOTES'],
  1636. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1637. 'count' => $aContentInfo['votes']
  1638. );
  1639. //--- Reactions
  1640. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1641. $aReactions = array();
  1642. if ($oReactions && $oReactions->isEnabled())
  1643. $aReactions = array(
  1644. 'system' => $CNF['OBJECT_REACTIONS'],
  1645. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1646. 'count' => $aContentInfo['rvotes']
  1647. );
  1648. //--- Scores
  1649. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1650. $aScores = array();
  1651. if ($oScores && $oScores->isEnabled())
  1652. $aScores = array(
  1653. 'system' => $CNF['OBJECT_SCORES'],
  1654. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1655. 'score' => $aContentInfo['score']
  1656. );
  1657. //--- Reports
  1658. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1659. $aReports = array();
  1660. if ($oReports && $oReports->isEnabled())
  1661. $aReports = array(
  1662. 'system' => $CNF['OBJECT_REPORTS'],
  1663. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1664. 'count' => $aContentInfo['reports']
  1665. );
  1666. //--- Comments
  1667. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  1668. $aComments = array();
  1669. if($oCmts && $oCmts->isEnabled())
  1670. $aComments = array(
  1671. 'system' => $CNF['OBJECT_COMMENTS'],
  1672. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  1673. 'count' => $aContentInfo['comments']
  1674. );
  1675. //--- Title & Description
  1676. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1677. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1678. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1679. $iOwnerId = $iAuthorIdAbs;
  1680. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1681. $iOwnerId = abs($aEvent['object_privacy_view']);
  1682. $bCache = true;
  1683. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1684. if(isset($aContent['_cache'])) {
  1685. $bCache = (bool)$aContent['_cache'];
  1686. unset($aContent['_cache']);
  1687. }
  1688. return array(
  1689. '_cache' => $bCache,
  1690. 'owner_id' => $iOwnerId,
  1691. 'object_owner_id' => $iAuthorId,
  1692. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1693. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1694. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1695. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1696. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1697. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1698. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1699. 'views' => $aViews,
  1700. 'votes' => $aVotes,
  1701. 'reactions' => $aReactions,
  1702. 'scores' => $aScores,
  1703. 'reports' => $aReports,
  1704. 'comments' => $aComments,
  1705. 'title' => $sTitle, //may be empty.
  1706. 'description' => '' //may be empty.
  1707. );
  1708. }
  1709. public function serviceGetTimelinePostAllowedView($aEvent)
  1710. {
  1711. $iContentId = (int)$aEvent['object_id'];
  1712. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1713. if(empty($aContentInfo) || !is_array($aContentInfo))
  1714. return _t('_sys_txt_access_denied');
  1715. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1716. }
  1717. /**
  1718. * Check particular action permission without content
  1719. * @param $sAction action to check, for example: Browse, Add
  1720. * @param $iContentId content ID
  1721. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1722. */
  1723. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1724. {
  1725. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1726. if (!method_exists($this, $sMethod))
  1727. return _t('_sys_request_method_not_found_cpt');
  1728. return $this->$sMethod($isPerformAction);
  1729. }
  1730. /**
  1731. * Check particular action permission with content
  1732. * @param $sAction action to check, for example: View, Edit
  1733. * @param $iContentId content ID
  1734. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1735. */
  1736. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1737. {
  1738. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1739. return _t('_sys_request_page_not_found_cpt');
  1740. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1741. if (!method_exists($this, $sMethod))
  1742. return _t('_sys_request_method_not_found_cpt');
  1743. return $this->$sMethod($aContentInfo, $isPerformAction);
  1744. }
  1745. /**
  1746. * Check particular action permission with content for specified profile
  1747. * @param $sAction action to check, for example: View, Edit
  1748. * @param $iContentId content ID
  1749. * @param $iProfileId profile ID which the permissions to be cheked for
  1750. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1751. */
  1752. public function serviceCheckAllowedWithContentForProfile($sAction, $iContentId, $iProfileId, $isPerformAction = false)
  1753. {
  1754. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1755. return _t('_sys_request_page_not_found_cpt');
  1756. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction) . 'ForProfile';
  1757. if (!method_exists($this, $sMethod))
  1758. return _t('_sys_request_method_not_found_cpt');
  1759. return $this->$sMethod($aContentInfo, $iProfileId, $isPerformAction);
  1760. }
  1761. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1762. {
  1763. //negative id used in comments for reports
  1764. if ($iContentId < 0)
  1765. return CHECK_ACTION_RESULT_ALLOWED;
  1766. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1767. }
  1768. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1769. {
  1770. //negative id used in comments for reports
  1771. if ($iContentId < 0)
  1772. return CHECK_ACTION_RESULT_ALLOWED;
  1773. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1774. }
  1775. public function serviceGetContentOwnerProfileId ($iContentId)
  1776. {
  1777. $CNF = &$this->_oConfig->CNF;
  1778. // file owner must be author of the content or profile itself in case of profile based module
  1779. if ($iContentId) {
  1780. $sModule = $this->getName();
  1781. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1782. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1783. }
  1784. else {
  1785. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1786. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1787. }
  1788. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1789. }
  1790. else {
  1791. $iProfileId = bx_get_logged_profile_id();
  1792. }
  1793. return $iProfileId;
  1794. }
  1795. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  1796. {
  1797. $sModule = $this->getName();
  1798. $oBadges = BxDolBadges::getInstance();
  1799. $aBadges = $oBadges->getData(array(
  1800. 'type' => ($bIsSingle ? 'by_module&object2_single' : 'by_module&object2'),
  1801. 'module' => $sModule,
  1802. 'object_id' => $iContentId
  1803. ));
  1804. $sResult = false;
  1805. bx_alert('system', 'get_badges', 0, 0, array(
  1806. 'module' => $sModule,
  1807. 'content_id' => $iContentId,
  1808. 'is_single' => $bIsSingle,
  1809. 'is_compact' => $bIsCompact,
  1810. 'badges' => $aBadges,
  1811. 'override_result' => &$sResult
  1812. ));
  1813. if($sResult !== false)
  1814. return $sResult;
  1815. if($bIsSingle && count($aBadges) > 0)
  1816. return BxDolService::call('system', 'get_badge', array($aBadges[0], $bIsCompact), 'TemplServices');
  1817. $aBadgesOutput = array();
  1818. foreach($aBadges as $aBadge)
  1819. $aBadgesOutput[] = array('badge' => BxDolService::call('system', 'get_badge', array($aBadge, $bIsCompact), 'TemplServices'));
  1820. return $this->_oTemplate->parseHtmlByName('badges.html', array(
  1821. 'bx_repeat:items' => $aBadgesOutput,
  1822. ));
  1823. }
  1824. /**
  1825. * @page service Service Calls
  1826. * @section bx_base_general Base Text
  1827. * @subsection bx_base_general-page_blocks Page Blocks
  1828. * @subsubsection bx_base_general-categories_multi_list categories_multi_list
  1829. *
  1830. * @code bx_srv('bx_posts', 'categories_multi_list', [...]); @endcode
  1831. *
  1832. * Display multi-categorories block with number of posts in each category
  1833. * @param $bDisplayEmptyCats display empty categories
  1834. *
  1835. * @see BxBaseModGeneralModule::serviceCategoriesMultiList
  1836. */
  1837. /**
  1838. * @ref bx_base_general-categories_multi_list "categories_multi_list"
  1839. */
  1840. public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
  1841. {
  1842. $oCategories = BxDolCategories::getInstance();
  1843. $aCats = $oCategories->getData(array('type' => 'by_module_with_num', 'module' => $this->getName()));
  1844. $aVars = array('bx_repeat:cats' => array());
  1845. foreach ($aCats as $oCat) {
  1846. $sValue = $oCat['value'];
  1847. $iNum = $oCat['num'];
  1848. $aVars['bx_repeat:cats'][] = array(
  1849. 'url' => $oCategories->getUrl($this->getName(), $sValue),
  1850. 'name' => _t($sValue),
  1851. 'value' => $sValue,
  1852. 'num' => $iNum,
  1853. );
  1854. }
  1855. if (!$aVars['bx_repeat:cats'])
  1856. return '';
  1857. return $this->_oTemplate->parseHtmlByName('category_list.html', $aVars);
  1858. }
  1859. /**
  1860. * ======
  1861. * PERMISSION METHODS
  1862. * ======
  1863. */
  1864. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1865. {
  1866. $mixedResult = $this->_serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1867. // check alert to allow custom checks
  1868. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1869. return $mixedResult;
  1870. }
  1871. public function checkAllowedSetThumb ($iContentId = 0)
  1872. {
  1873. return CHECK_ACTION_RESULT_ALLOWED;
  1874. }
  1875. /**
  1876. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1877. */
  1878. public function checkAllowedBrowse ()
  1879. {
  1880. // check alert to allow custom checks
  1881. $mixedResult = null;
  1882. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1883. if($mixedResult !== null)
  1884. return $mixedResult;
  1885. return CHECK_ACTION_RESULT_ALLOWED;
  1886. }
  1887. /**
  1888. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1889. */
  1890. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1891. {
  1892. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1893. }
  1894. /**
  1895. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1896. */
  1897. public function checkAllowedViewForProfile ($aDataEntry, $iProfileId, $isPerformAction = false)
  1898. {
  1899. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1900. }
  1901. /**
  1902. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1903. */
  1904. public function checkAllowedAdd ($isPerformAction = false)
  1905. {
  1906. // check ACL
  1907. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1908. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1909. return $aCheck[CHECK_ACTION_MESSAGE];
  1910. return CHECK_ACTION_RESULT_ALLOWED;
  1911. }
  1912. /**
  1913. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1914. */
  1915. public function checkAllowedApprove ($aDataEntry, $isPerformAction = false)
  1916. {
  1917. // moderator always have access
  1918. if ($this->_isModerator($isPerformAction))
  1919. return CHECK_ACTION_RESULT_ALLOWED;
  1920. // check for context's admins
  1921. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  1922. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1923. if ($oProfile){
  1924. $sModule = $oProfile->getModule();
  1925. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1926. $oModule = BxDolModule::getInstance($sModule);
  1927. // check for context's extra roles with rights
  1928. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1929. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  1930. if ($bResult !== NULL) return $bResult;
  1931. }
  1932. // if allowed edit a group then allowed to edit anything inside its context
  1933. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1934. return CHECK_ACTION_RESULT_ALLOWED;
  1935. }
  1936. }
  1937. }
  1938. return _t('_sys_txt_access_denied');
  1939. }
  1940. /**
  1941. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1942. */
  1943. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1944. {
  1945. // moderator and owner always have access
  1946. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1947. return CHECK_ACTION_RESULT_ALLOWED;
  1948. // check for context's admins
  1949. if (!empty($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  1950. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1951. if ($oProfile){
  1952. $sModule = $oProfile->getModule();
  1953. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1954. $oModule = BxDolModule::getInstance($sModule);
  1955. // check for context's extra roles with rights
  1956. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1957. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'edit_any');
  1958. if ($bResult !== NULL) return $bResult;
  1959. }
  1960. // if allowed edit a group then allowed to edit anything inside its context
  1961. if(isset($aEntity) && $oModule->checkAllowedEdit($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1962. return CHECK_ACTION_RESULT_ALLOWED;
  1963. }
  1964. }
  1965. }
  1966. return _t('_sys_txt_access_denied');
  1967. }
  1968. /**
  1969. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1970. */
  1971. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1972. {
  1973. // moderator always has access
  1974. if ($this->_isAdministrator($isPerformAction))
  1975. return CHECK_ACTION_RESULT_ALLOWED;
  1976. // check ACL
  1977. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1978. 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)
  1979. return CHECK_ACTION_RESULT_ALLOWED;
  1980. // check for context's admins
  1981. if (isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0){
  1982. $oProfile = BxDolProfile::getInstance(-(int)$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]);
  1983. if ($oProfile){
  1984. $sModule = $oProfile->getModule();
  1985. $aEntity = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $oProfile->getContentId()))) : array();
  1986. $oModule = BxDolModule::getInstance($sModule);
  1987. // check for context's extra roles with rights
  1988. if (method_exists($oModule, 'isAllowedModuleActionByProfile')) {
  1989. $bResult = $oModule->isAllowedModuleActionByProfile($oProfile->getContentId(), $this->getName(), 'delete_any');
  1990. if ($bResult !== NULL) return $bResult;
  1991. }
  1992. // if allowed delete a group then allowed to delete anything inside its context
  1993. if(isset($aEntity) && $oModule->checkAllowedDelete($aEntity) === CHECK_ACTION_RESULT_ALLOWED){
  1994. return CHECK_ACTION_RESULT_ALLOWED;
  1995. }
  1996. }
  1997. }
  1998. return _t('_sys_txt_access_denied');
  1999. }
  2000. /**
  2001. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2002. */
  2003. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  2004. {
  2005. // admin always has access
  2006. if (isAdmin())
  2007. return CHECK_ACTION_RESULT_ALLOWED;
  2008. // check ACL
  2009. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  2010. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2011. return $aCheck[CHECK_ACTION_MESSAGE];
  2012. return CHECK_ACTION_RESULT_ALLOWED;
  2013. }
  2014. /**
  2015. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2016. */
  2017. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  2018. {
  2019. return $this->checkAllowedEditAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2020. }
  2021. /**
  2022. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2023. */
  2024. public function checkAllowedDeleteAnyEntry ($isPerformAction = false)
  2025. {
  2026. return $this->checkAllowedDeleteAnyEntryForProfile($isPerformAction, $this->_iProfileId);
  2027. }
  2028. /**
  2029. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2030. */
  2031. public function checkAllowedEditAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2032. {
  2033. if(!$iProfileId)
  2034. $iProfileId = $this->_iProfileId;
  2035. $aCheck = checkActionModule($iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  2036. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2037. return CHECK_ACTION_RESULT_ALLOWED;
  2038. return _t('_sys_txt_access_denied');
  2039. }
  2040. /**
  2041. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  2042. */
  2043. public function checkAllowedDeleteAnyEntryForProfile ($isPerformAction = false, $iProfileId = false)
  2044. {
  2045. if(!$iProfileId)
  2046. $iProfileId = $this->_iProfileId;
  2047. $aCheck = checkActionModule($iProfileId, 'delete any entry', $this->getName(), $isPerformAction);
  2048. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2049. return CHECK_ACTION_RESULT_ALLOWED;
  2050. return _t('_sys_txt_access_denied');
  2051. }
  2052. /**
  2053. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2054. */
  2055. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2056. {
  2057. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2058. }
  2059. /**
  2060. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  2061. */
  2062. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2063. {
  2064. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  2065. }
  2066. protected function _serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)
  2067. {
  2068. $CNF = &$this->_oConfig->CNF;
  2069. if(!$iProfileId)
  2070. $iProfileId = $this->_iProfileId;
  2071. if(empty($aDataEntry) || !is_array($aDataEntry))
  2072. return _t('_sys_txt_not_found');
  2073. // moderator and owner always have access
  2074. if(!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModeratorForProfile($isPerformAction, $iProfileId)))
  2075. return CHECK_ACTION_RESULT_ALLOWED;
  2076. // check ACL
  2077. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  2078. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2079. return $aCheck[CHECK_ACTION_MESSAGE];
  2080. // check privacy
  2081. if(!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  2082. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2083. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  2084. return _t('_sys_access_denied_to_private_content');
  2085. }
  2086. return CHECK_ACTION_RESULT_ALLOWED;
  2087. }
  2088. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  2089. {
  2090. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  2091. return MsgBox($sMsg);
  2092. bx_import($sClassSearchResult, $this->_aModule);
  2093. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  2094. $o = new $sClass($sMode, $aParams);
  2095. $o->setDesignBoxTemplateId($iDesignBox);
  2096. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  2097. $o->setAjaxPaginate($bAjaxPaginate);
  2098. $o->setUnitParams(array('context' => $sMode));
  2099. if (isset($aParams['condition']) && is_array($aParams['condition']))
  2100. $o->setCustomCurrentCondition($aParams['condition']);
  2101. if ($o->isError)
  2102. return '';
  2103. if ($s = $o->processing())
  2104. return $s;
  2105. else
  2106. return '';
  2107. }
  2108. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  2109. {
  2110. // get paginate object
  2111. $oPaginate = new BxTemplPaginate(array(
  2112. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  2113. 'num' => count($aProfiles),
  2114. 'per_page' => $iLimit,
  2115. 'start' => $iStart,
  2116. ));
  2117. // remove last item from connection array, because we've got one more item for pagination calculations only
  2118. if (count($aProfiles) > $iLimit)
  2119. array_pop($aProfiles);
  2120. // get profiles HTML
  2121. $s = '';
  2122. foreach ($aProfiles as $mixedProfile) {
  2123. $bProfile = is_array($mixedProfile);
  2124. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  2125. if(!$oProfile)
  2126. continue;
  2127. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  2128. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  2129. $aUnitParams['template']['name'] = 'unit_wo_cover';
  2130. if($bProfile && is_array($mixedProfile['info']))
  2131. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  2132. $s .= $oProfile->getUnit(0, $aUnitParams);
  2133. }
  2134. // return profiles + paginate
  2135. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  2136. }
  2137. // ====== COMMON METHODS
  2138. public function onPublished($iContentId)
  2139. {
  2140. $CNF = &$this->_oConfig->CNF;
  2141. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2142. if(!$aContentInfo)
  2143. return;
  2144. $aParams = $this->_alertParams($aContentInfo);
  2145. bx_alert($this->getName(), 'added', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2146. }
  2147. public function onFailed($iContentId)
  2148. {
  2149. $CNF = &$this->_oConfig->CNF;
  2150. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2151. if(!$aContentInfo)
  2152. return;
  2153. $aParams = array('object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]);
  2154. bx_alert($this->getName(), 'failed', $iContentId, $aContentInfo[$CNF['FIELD_AUTHOR']], $aParams);
  2155. }
  2156. public function alertAfterAdd($aContentInfo) {}
  2157. public function alertAfterEdit($aContentInfo) {}
  2158. /**
  2159. * Get array of params to be passed in Add/Edit Alert.
  2160. */
  2161. protected function _alertParams($aContentInfo)
  2162. {
  2163. $CNF = &$this->_oConfig->CNF;
  2164. return array(
  2165. 'object_author_id' => (int)$aContentInfo[$CNF['FIELD_AUTHOR']]
  2166. );
  2167. }
  2168. public function processMetasAdd($iContentId)
  2169. {
  2170. $CNF = &$this->_oConfig->CNF;
  2171. if(empty($CNF['OBJECT_METATAGS']))
  2172. return false;
  2173. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2174. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2175. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2176. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2177. if(!$bContentInfo)
  2178. return false;
  2179. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2180. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  2181. $sKey = 'FIELD_LOCATION';
  2182. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2183. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2184. if(!empty($aLocation) && is_array($aLocation))
  2185. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2186. }
  2187. $sKey = 'FIELD_LABELS';
  2188. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2189. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2190. if(!empty($aLabels) && is_array($aLabels))
  2191. foreach ($aLabels as $sLabel)
  2192. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2193. }
  2194. return true;
  2195. }
  2196. public function processMetasEdit($iContentId, $oForm)
  2197. {
  2198. $CNF = &$this->_oConfig->CNF;
  2199. if(empty($CNF['OBJECT_METATAGS']))
  2200. return false;
  2201. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2202. $bFldStatus = isset($CNF['FIELD_STATUS']);
  2203. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  2204. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  2205. if(!$bContentInfo)
  2206. return false;
  2207. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2208. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  2209. $sKey = 'FIELD_LOCATION';
  2210. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2211. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  2212. if(!empty($aLocation) && is_array($aLocation))
  2213. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  2214. }
  2215. $sKey = 'FIELD_LABELS';
  2216. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  2217. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  2218. if(!empty($aLabels) && is_array($aLabels))
  2219. foreach ($aLabels as $sLabel)
  2220. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  2221. }
  2222. return true;
  2223. }
  2224. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  2225. {
  2226. if(empty($aTranscoders))
  2227. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  2228. $CNF = &$this->_oConfig->CNF;
  2229. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  2230. return false;
  2231. $iId = (int)$aContentInfo[$CNF[$sField]];
  2232. foreach($aTranscoders as $sTranscoder)
  2233. if(!empty($CNF[$sTranscoder]))
  2234. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  2235. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  2236. }
  2237. public function getProfileId()
  2238. {
  2239. return bx_get_logged_profile_id();
  2240. }
  2241. public function getProfileInfo($iUserId = false)
  2242. {
  2243. $oProfile = $this->getObjectUser($iUserId);
  2244. $oAccount = null;
  2245. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  2246. $oAccount = $oProfile->getAccountObject();
  2247. $bAccount = !empty($oAccount);
  2248. if(!$bAccount)
  2249. $oProfile = BxDolProfileUndefined::getInstance();
  2250. return array(
  2251. 'id' => $oProfile->id(),
  2252. 'name' => $oProfile->getDisplayName(),
  2253. 'email' => $bAccount ? $oAccount->getEmail() : '',
  2254. 'link' => $oProfile->getUrl(),
  2255. 'icon' => $oProfile->getIcon(),
  2256. 'thumb' => $oProfile->getThumb(),
  2257. 'avatar' => $oProfile->getAvatar(),
  2258. 'unit' => $oProfile->getUnit(),
  2259. 'active' => $oProfile->isActive(),
  2260. );
  2261. }
  2262. public function getObjectUser($iUserId = false)
  2263. {
  2264. bx_import('BxDolProfile');
  2265. return BxDolProfile::getInstanceMagic($iUserId);
  2266. }
  2267. public function getObjectFavorite($sSystem = '', $iId = 0)
  2268. {
  2269. $CNF = &$this->_oConfig->CNF;
  2270. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  2271. $sSystem = $CNF['OBJECT_FAVORITES'];
  2272. if(empty($sSystem))
  2273. return false;
  2274. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2275. if(!$oFavorite || !$oFavorite->isEnabled())
  2276. return false;
  2277. return $oFavorite;
  2278. }
  2279. public function getUserId()
  2280. {
  2281. return isLogged() ? bx_get_logged_profile_id() : 0;
  2282. }
  2283. public function getUserIp()
  2284. {
  2285. return getVisitorIP();
  2286. }
  2287. public function getUserInfo($iUserId = 0)
  2288. {
  2289. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2290. return array(
  2291. $oProfile->getDisplayName(),
  2292. $oProfile->getUrl(),
  2293. $oProfile->getThumb(),
  2294. $oProfile->getUnit(),
  2295. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  2296. );
  2297. }
  2298. public function getUserInfoWithBadges($iUserId = 0)
  2299. {
  2300. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  2301. return array(
  2302. $oProfile->getDisplayName(),
  2303. $oProfile->getUrl(),
  2304. $oProfile->getThumb(),
  2305. $oProfile->getUnit(),
  2306. $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  2307. $oProfile->getBadges()
  2308. );
  2309. }
  2310. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  2311. {
  2312. $CNF = &$this->_oConfig->CNF;
  2313. // default visible settings
  2314. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  2315. return false;
  2316. if (!empty($aItem['visibility_custom'])) {
  2317. $oMenu = BxDolMenu::getObjectInstance($sObject);
  2318. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  2319. return false;
  2320. }
  2321. // get custom function name to check menu item visibility
  2322. $sFuncCheckAccess = false;
  2323. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  2324. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  2325. // check custom visibility settings defined in module config class
  2326. if(!isset($aContentInfo))
  2327. $aContentInfo = array();
  2328. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  2329. return false;
  2330. return true;
  2331. }
  2332. public function _isModerator ($isPerformAction = false)
  2333. {
  2334. return $this->_isModeratorForProfile($isPerformAction, $this->_iProfileId);
  2335. }
  2336. public function _isModeratorForProfile($isPerformAction = false, $iProfileId = false)
  2337. {
  2338. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntryForProfile ($isPerformAction, $iProfileId);
  2339. }
  2340. public function _isAdministrator ($isPerformAction = false)
  2341. {
  2342. return $this->_isAdministratorForProfile($isPerformAction, $this->_iProfileId);
  2343. }
  2344. public function _isAdministratorForProfile($isPerformAction = false, $iProfileId = false)
  2345. {
  2346. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedDeleteAnyEntryForProfile ($isPerformAction, $iProfileId);
  2347. }
  2348. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  2349. {
  2350. $CNF = &$this->_oConfig->CNF;
  2351. $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;
  2352. $AuditParams = array(
  2353. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  2354. 'context_profile_id' => $iContextId,
  2355. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  2356. 'data' => ($bIsSaveData ? $aContentInfo : array())
  2357. );
  2358. if ($iContextId > 0)
  2359. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  2360. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  2361. return $AuditParams;
  2362. }
  2363. public function _getFavoriteListUrl ($iListId, $iProfileId)
  2364. {
  2365. $CNF = &$this->_oConfig->CNF;
  2366. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_FAVORITES_LIST'] . '&profile_id=' . $iProfileId . '&list_id=' . $iListId);
  2367. }
  2368. // ====== PROTECTED METHODS
  2369. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  2370. {
  2371. $iContentId = $this->_getContent($iContentId, false);
  2372. if($iContentId === false)
  2373. return false;
  2374. bx_import('FormsEntryHelper', $this->_aModule);
  2375. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  2376. $oFormsHelper = new $sClass($this);
  2377. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  2378. }
  2379. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  2380. {
  2381. return $this->_serviceTemplateFuncEx($sFunc, $iContentId, array('function_get_content' => 'getContentInfoById'));
  2382. }
  2383. protected function _serviceTemplateFuncEx ($sFunc, $iContentId, $aParams = array())
  2384. {
  2385. if (!isset($aParams['function_get_content']))
  2386. $aParams['function_get_content'] = 'getContentInfoById';
  2387. $mixedContent = $this->_getContent($iContentId, $aParams['function_get_content']);
  2388. if($mixedContent === false)
  2389. return false;
  2390. list($iContentId, $aContentInfo) = $mixedContent;
  2391. if (isset($aParams['template_name']) && !empty($aParams['template_name']))
  2392. return $this->_oTemplate->$sFunc($aContentInfo, array('template_name' => $aParams['template_name']));
  2393. else
  2394. return $this->_oTemplate->$sFunc($aContentInfo);
  2395. }
  2396. protected function _rss ($aArgs, $sClass = 'SearchResult')
  2397. {
  2398. $sMode = array_shift($aArgs);
  2399. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  2400. $this->_oTemplate->displayAccessDenied ($sMsg);
  2401. exit;
  2402. }
  2403. $aParams = $this->_buildRssParams($sMode, $aArgs);
  2404. bx_import ($sClass, $this->_aModule);
  2405. $sClass = $this->_aModule['class_prefix'] . $sClass;
  2406. $o = new $sClass($sMode, $aParams);
  2407. if ($o->isError)
  2408. $this->_oTemplate->displayPageNotFound ();
  2409. else
  2410. $o->outputRSS();
  2411. exit;
  2412. }
  2413. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  2414. {
  2415. if(!$iContentId)
  2416. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2417. if(!$iContentId)
  2418. return false;
  2419. if($sFuncGetContent === true)
  2420. $sFuncGetContent = 'getContentInfoById';
  2421. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  2422. return $iContentId;
  2423. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  2424. if(!$aContentInfo)
  2425. return false;
  2426. return array($iContentId, $aContentInfo);
  2427. }
  2428. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2429. {
  2430. $CNF = &$this->_oConfig->CNF;
  2431. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2432. //--- Image(s)
  2433. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2434. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2435. //--- Video(s)
  2436. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2437. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2438. //--- Files(s)
  2439. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2440. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  2441. //--- Title
  2442. $sTitle = '';
  2443. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  2444. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  2445. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  2446. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  2447. //--- Text
  2448. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  2449. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  2450. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2451. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2452. }
  2453. return array(
  2454. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2455. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2456. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2457. 'url' => $sUrl,
  2458. 'title' => $sTitle,
  2459. 'text' => $sText,
  2460. 'images' => $aImages,
  2461. 'images_attach' => $aImagesAttach,
  2462. 'videos' => $aVideos,
  2463. 'videos_attach' => $aVideosAttach,
  2464. 'files' => $aFiles,
  2465. 'files_attach' => $aFilesAttach
  2466. );
  2467. }
  2468. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2469. {
  2470. $CNF = &$this->_oConfig->CNF;
  2471. $sImage = $sImageOrig = '';
  2472. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  2473. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2474. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2475. }
  2476. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  2477. if($sImage == '' && $bImageThumb)
  2478. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  2479. if($sImageOrig == '' && $bImageThumb)
  2480. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  2481. if(empty($sImage))
  2482. return array();
  2483. if($sImageOrig == '')
  2484. $sImageOrig = $sImage;
  2485. return array(
  2486. array('id' => $aContentInfo[$CNF['FIELD_THUMB']], 'url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  2487. );
  2488. }
  2489. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2490. {
  2491. return array();
  2492. }
  2493. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2494. {
  2495. return array();
  2496. }
  2497. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2498. {
  2499. return array();
  2500. }
  2501. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2502. {
  2503. return array();
  2504. }
  2505. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2506. {
  2507. return array();
  2508. }
  2509. protected function _entityComments ($sObject, $iId = 0)
  2510. {
  2511. if (!$iId)
  2512. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2513. if (!$iId)
  2514. return false;
  2515. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2516. if (!$oCmts || !$oCmts->isEnabled())
  2517. return false;
  2518. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  2519. }
  2520. protected function _getFields($iContentId)
  2521. {
  2522. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2523. if(empty($aContentInfo))
  2524. return array();
  2525. return BxDolContentInfo::formatFields($aContentInfo);
  2526. }
  2527. protected function _getFieldValue($sField, $iContentId)
  2528. {
  2529. $CNF = &$this->_oConfig->CNF;
  2530. if(empty($CNF[$sField]))
  2531. return false;
  2532. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2533. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2534. return false;
  2535. return $aContentInfo[$CNF[$sField]];
  2536. }
  2537. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  2538. {
  2539. $CNF = &$this->_oConfig->CNF;
  2540. if(empty($sTranscoder) || empty($CNF[$sField]))
  2541. return false;
  2542. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  2543. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  2544. return false;
  2545. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  2546. if(!$oImagesTranscoder)
  2547. return false;
  2548. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  2549. }
  2550. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  2551. {
  2552. if(!$bAsJson)
  2553. return $aResponse;
  2554. if(!empty($aAdditional) && is_array($aAdditional))
  2555. $aResponse = array_merge($aResponse, $aAdditional);
  2556. echoJson($aResponse);
  2557. exit;
  2558. }
  2559. /**
  2560. * Blocks for lables tree browsing private functions
  2561. */
  2562. private function _getLablesBreadcrumbsArray($iLabelId, &$aBreadcrumbs)
  2563. {
  2564. $oLabel = BxDolLabel::getInstance();
  2565. $aLabel = $oLabel->getLabels(array('type' => 'id', 'id' => $iLabelId));
  2566. if ($aLabel){
  2567. $aBreadcrumbs[$aLabel['id']] = array('id' => $aLabel['id'], 'value' => $aLabel['value']);
  2568. $this->_getLablesBreadcrumbsArray($aLabel['parent'], $aBreadcrumbs);
  2569. }
  2570. }
  2571. private function _getLablesBrowseUrl($iLabelId)
  2572. {
  2573. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  2574. return BxDolPermalinks::getInstance()->permalink(bx_append_url_params($sPageLink, array_merge($aPageParams, array('label' => $iLabelId))));
  2575. }
  2576. private function _getLablesTreeLevel($aBreadcrumbs, $iParent = 0)
  2577. {
  2578. $oLabel = BxDolLabel::getInstance();
  2579. $aLabelsOutput = array();
  2580. $aLabels = $oLabel->getLabels(array('type' => 'parent', 'parent' => $iParent));
  2581. if (count($aLabels) > 0){
  2582. foreach($aLabels as $aLabel) {
  2583. $sChild = $this->_getLablesTreeLevel($aBreadcrumbs, $aLabel['id']);
  2584. $bChildPresent = $sChild != '' ? true : false;
  2585. $bIsOpen = array_key_exists($aLabel['id'], $aBreadcrumbs) ? true : false;
  2586. if (!$bIsOpen){
  2587. $sChild = '';
  2588. }
  2589. $aLabelsOutput[] = array(
  2590. 'value' => $aLabel['value'],
  2591. 'url' => $this->_getLablesBrowseUrl($aLabel['id']),
  2592. 'child' => $sChild,
  2593. 'selected' => bx_process_input(bx_get('label'), BX_DATA_INT) == $aLabel['id'] ? 'selected' : ''.$aLabel['id'],
  2594. 'bx_if:open' => array(
  2595. 'condition' => $bChildPresent && $bIsOpen,
  2596. 'content' => array()
  2597. ),
  2598. 'bx_if:can_open' => array(
  2599. 'condition' => $bChildPresent && !$bIsOpen,
  2600. 'content' => array()
  2601. )
  2602. );
  2603. }
  2604. return $this->_oTemplate->parseHtmlByName('labels_tree.html',
  2605. array(
  2606. 'bx_repeat:items' => $aLabelsOutput,
  2607. 'parent' => $iParent,
  2608. )
  2609. );
  2610. }
  2611. return '';
  2612. }
  2613. }
  2614. /** @} */