BxBaseModGeneralModule.php 115 KB

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