BxBaseModGeneralModule.php 113 KB

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