BxBaseModGeneralModule.php 122 KB

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