BxBaseModGeneralModule.php 95 KB

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