BxBaseModGeneralModule.php 98 KB

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