1
0

BxBaseModGeneralModule.php 124 KB

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