BxBaseModGeneralModule.php 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. protected $_aSearchableNamesExcept;
  19. protected $_aFormParams;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_aSearchableNamesExcept = array(
  25. 'allow_view_to'
  26. );
  27. $this->_aFormParams = array(
  28. 'display' => false,
  29. 'dynamic_mode' => false,
  30. 'ajax_mode' => false,
  31. 'absolute_action_url' => false,
  32. 'visibility_autoselect' => false,
  33. 'context_id' => 0,
  34. 'custom' => array()
  35. );
  36. }
  37. // ====== ACTIONS METHODS
  38. public function actionRss ()
  39. {
  40. $aArgs = func_get_args();
  41. $this->_rss($aArgs);
  42. }
  43. public function actionGetCreatePostForm()
  44. {
  45. $sName = $this->_oConfig->getName();
  46. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  47. $aParams = array_merge($this->_aFormParams, $aParams);
  48. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  49. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  50. if(empty($mixedResponse))
  51. return echoJson(array());
  52. else if(is_array($mixedResponse)) {
  53. $mixedResponse['module'] = $sName;
  54. return echoJson($mixedResponse);
  55. }
  56. return echoJson(array(
  57. 'module' => $sName,
  58. 'content' => $mixedResponse
  59. ));
  60. }
  61. // ====== SERVICE METHODS
  62. public function serviceGetCreatePostForm($aParams = array())
  63. {
  64. $aParams = array_merge($this->_aFormParams, $aParams);
  65. $oForm = $this->serviceGetObjectForm('add', $aParams);
  66. if(!$oForm)
  67. return '';
  68. return $this->serviceEntityCreate($aParams);
  69. }
  70. public function serviceGetAuthor ($iContentId)
  71. {
  72. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  73. return $mixedResult !== false ? (int)$mixedResult : 0;
  74. }
  75. public function serviceGetPrivacyView ($iContentId)
  76. {
  77. return $this->_getFieldValue('FIELD_ALLOW_VIEW_TO', $iContentId);
  78. }
  79. public function serviceGetDateAdded ($iContentId)
  80. {
  81. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  82. return $mixedResult !== false ? (int)$mixedResult : 0;
  83. }
  84. public function serviceGetDateChanged ($iContentId)
  85. {
  86. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  87. return $mixedResult !== false ? (int)$mixedResult : 0;
  88. }
  89. public function serviceGetLink ($iContentId)
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. if(empty($CNF['URI_VIEW_ENTRY']))
  93. return '';
  94. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  95. if(empty($aContentInfo))
  96. return '';
  97. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  98. }
  99. public function serviceGetTitle ($iContentId)
  100. {
  101. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  102. return $mixedResult !== false ? $mixedResult : '';
  103. }
  104. public function serviceGetText ($iContentId)
  105. {
  106. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  107. if (false === $mixedResult)
  108. return '';
  109. $CNF = &$this->_oConfig->CNF;
  110. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  111. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  112. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  113. }
  114. return $mixedResult;
  115. }
  116. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  117. {
  118. $CNF = &$this->_oConfig->CNF;
  119. $aContentInfo = $this->_getFields($iContentId);
  120. if(empty($aContentInfo))
  121. return array();
  122. if(!$bSearchableFieldsOnly)
  123. return $aContentInfo;
  124. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  125. return array();
  126. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  127. if(empty($aFields))
  128. return array();
  129. $aResult = array();
  130. foreach($aFields as $sField)
  131. if(isset($aContentInfo[$sField]))
  132. $aResult[$sField] = $aContentInfo[$sField];
  133. return $aResult;
  134. }
  135. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  136. {
  137. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  138. if(empty($aContentInfo))
  139. return '';
  140. if(empty($sUnitTemplate))
  141. $sUnitTemplate = 'unit.html';
  142. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  143. }
  144. public function serviceGetAll ($aParams = array())
  145. {
  146. if(empty($aParams) || !is_array($aParams))
  147. $aParams = array('type' => 'all');
  148. return $this->_oDb->getEntriesBy($aParams);
  149. }
  150. public function serviceGetAllByAuthor ($iProfileId)
  151. {
  152. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  153. }
  154. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  155. {
  156. $CNF = &$this->_oConfig->CNF;
  157. if(empty($CNF['OBJECT_FORM_ENTRY']))
  158. return array();
  159. $aResult = array();
  160. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  161. $aResult[$CNF['FIELD_AUTHOR']] = array(
  162. 'type' => 'text_auto',
  163. 'caption' => $CNF['T']['form_field_author'],
  164. 'info' => '',
  165. 'value' => '',
  166. 'values' => '',
  167. 'pass' => ''
  168. );
  169. $aInputs = array();
  170. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  171. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  172. $aInputs = array_merge($aInputs, $oForm->aInputs);
  173. }
  174. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  175. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  176. $aInputs = array_merge($aInputs, $oForm->aInputs);
  177. }
  178. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  179. $aInputs = array_merge($aInputs, $aInputsAdd);
  180. foreach($aInputs as $aInput){
  181. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  182. $aField = array(
  183. 'type' => $aInput['type'],
  184. 'caption_system' => $aInput['caption_system_src'],
  185. 'caption' => $aInput['caption_src'],
  186. 'info' => $aInput['info_src'],
  187. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  188. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  189. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  190. );
  191. if(isset($aInput['search_type']))
  192. $aField['search_type'] = $aInput['search_type'];
  193. $aResult[$aInput['name']] = $aField;
  194. }
  195. }
  196. return $aResult;
  197. }
  198. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  199. {
  200. if(empty($aParams) || !is_array($aParams))
  201. return array();
  202. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  203. }
  204. public function serviceModuleIcon ()
  205. {
  206. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  207. }
  208. public function serviceGetSearchableFields ($aInputsAdd = array())
  209. {
  210. $CNF = $this->_oConfig->CNF;
  211. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  212. return array();
  213. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  214. if(!$oForm)
  215. return array();
  216. $aInputs = $oForm->aInputs;
  217. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  218. $aInputs = array_merge($aInputs, $aInputsAdd);
  219. $aTextTypes = array('text', 'textarea');
  220. $aTextFields = array();
  221. foreach($aInputs as $r)
  222. if(in_array($r['type'], $aTextTypes))
  223. $aTextFields[$r['name']] = $r['caption'];
  224. return $aTextFields;
  225. }
  226. public function serviceManageTools($sType = 'common')
  227. {
  228. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  229. if(!$oGrid)
  230. return '';
  231. $CNF = &$this->_oConfig->CNF;
  232. $sMenu = '';
  233. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  234. $oPermalink = BxDolPermalinks::getInstance();
  235. $aMenuItems = array();
  236. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  237. $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);
  238. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  239. $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);
  240. if(count($aMenuItems) > 1) {
  241. $oMenu = new BxTemplMenu(array(
  242. 'template' => 'menu_vertical.html',
  243. 'menu_items' => $aMenuItems
  244. ), $this->_oTemplate);
  245. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  246. $sMenu = $oMenu->getCode();
  247. }
  248. }
  249. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  250. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  251. }
  252. $this->_oTemplate->addCss(array('manage_tools.css'));
  253. $this->_oTemplate->addJs(array('manage_tools.js'));
  254. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  255. return array(
  256. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  257. 'menu' => $sMenu
  258. );
  259. }
  260. public function serviceGetMenuAddonManageTools()
  261. {
  262. return 0;
  263. }
  264. public function serviceGetMenuAddonManageToolsProfileStats()
  265. {
  266. return 0;
  267. }
  268. /**
  269. * My entries actions block
  270. */
  271. public function serviceMyEntriesActions ($iProfileId = 0)
  272. {
  273. $CNF = &$this->_oConfig->CNF;
  274. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  275. return false;
  276. if (!$iProfileId)
  277. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  278. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  279. return false;
  280. if ($iProfileId != $this->_iProfileId)
  281. return false;
  282. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  283. return $oMenu ? $oMenu->getCode() : false;
  284. }
  285. /**
  286. * Universal browse method
  287. * @param $aParams custom browse params, possible params are the following:
  288. * - mode - browse mode, such as 'recent', 'featured', etc
  289. * - params - custom params to browse method, for example 'unit_view' can be passed here
  290. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  291. * - empty_message - display or not "empty" message when there is no content
  292. * - ajax_paginate - use AJAX paginate or not
  293. * @return HTML string
  294. */
  295. public function serviceBrowse ($aParams = array())
  296. {
  297. $aDefaults = array (
  298. 'mode' => 'recent',
  299. 'params' => false,
  300. 'design_box' => BX_DB_PADDING_DEF,
  301. 'empty_message' => false,
  302. 'ajax_paginate' => true,
  303. );
  304. $aParams = array_merge($aDefaults, $aParams);
  305. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  306. }
  307. /**
  308. * Display featured entries
  309. * @return HTML string
  310. */
  311. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  312. {
  313. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  314. }
  315. /**
  316. * Display entries favored by a member
  317. * @return HTML string
  318. */
  319. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  320. {
  321. $oProfile = null;
  322. if((int)$iProfileId)
  323. $oProfile = BxDolProfile::getInstance($iProfileId);
  324. if(!$oProfile && bx_get('profile_id') !== false)
  325. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  326. if(!$oProfile)
  327. $oProfile = BxDolProfile::getInstance();
  328. if(!$oProfile)
  329. return '';
  330. $bEmptyMessage = false;
  331. if(isset($aParams['empty_message'])) {
  332. $bEmptyMessage = (bool)$aParams['empty_message'];
  333. unset($aParams['empty_message']);
  334. }
  335. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  336. }
  337. public function serviceFormsHelper ()
  338. {
  339. bx_import('FormsEntryHelper', $this->_aModule);
  340. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  341. return new $sClass($this);
  342. }
  343. /**
  344. * Add entry using provided fields' values.
  345. * @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
  346. */
  347. public function serviceEntityAdd ($iProfile, $aValues)
  348. {
  349. bx_import('FormsEntryHelper', $this->_aModule);
  350. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  351. $oFormsHelper = new $sClass($this);
  352. return $oFormsHelper->addData($iProfile, $aValues);
  353. }
  354. /**
  355. * Perform redirect after content creation
  356. * @return nothing, rediret header is sent
  357. */
  358. public function serviceRedirectAfterAdd($aContentInfo)
  359. {
  360. bx_import('FormsEntryHelper', $this->_aModule);
  361. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  362. $oFormsHelper = new $sClass($this);
  363. $oFormsHelper->redirectAfterAdd($aContentInfo);
  364. }
  365. /**
  366. * Get form object for add, edit, view or delete the content
  367. * @param $sType 'add', 'edit', 'view' or 'delete'
  368. * @param $aParams optional array with parameters(display name, etc)
  369. * @return form object or false on error
  370. */
  371. public function serviceGetObjectForm ($sType, $aParams = array())
  372. {
  373. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  374. return false;
  375. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  376. $bContext = $mixedContextId !== false;
  377. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  378. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  379. return false;
  380. $CNF = &$this->_oConfig->CNF;
  381. bx_import('FormsEntryHelper', $this->_aModule);
  382. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  383. $oFormsHelper = new $sClass($this);
  384. $sParamsKey = 'ajax_mode';
  385. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  386. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  387. $sParamsKey = 'absolute_action_url';
  388. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  389. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  390. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  391. $sFunc = 'getObjectForm' . ucfirst($sType);
  392. $oForm = $oFormsHelper->$sFunc($sDisplay);
  393. $sKey = 'FIELD_ALLOW_VIEW_TO';
  394. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  395. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  396. if(!$bContext || $bContextOwner) {
  397. $iGc = 0;
  398. $iKeyGh = false;
  399. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  400. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  401. if($iKeyGh !== false && $iGc == 0) {
  402. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  403. $iKeyGh = false;
  404. if($aValue['type'] == 'group_end')
  405. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  406. }
  407. if($aValue['type'] == 'group_header') {
  408. $iGc = 0;
  409. $iKeyGh = $iKey;
  410. }
  411. continue;
  412. }
  413. //--- Show 'Public' privacy group only in Public post form.
  414. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  415. $iGc += 1;
  416. continue;
  417. }
  418. //--- Show a default privacy groups in Profile (for Owner) post form.
  419. if($bContextOwner && (int)$aValue['key'] >= 0) {
  420. $iGc += 1;
  421. continue;
  422. }
  423. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  424. }
  425. }
  426. else {
  427. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  428. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  429. }
  430. }
  431. bx_alert('system', 'get_object_form', 0, 0, array(
  432. 'module' => $this->_oConfig->getName(),
  433. 'type' => $sType,
  434. 'params' => $aParams,
  435. 'form' => &$oForm
  436. ));
  437. return $oForm;
  438. }
  439. /**
  440. * Create entry form
  441. * @return HTML string
  442. */
  443. public function serviceEntityCreate ($sParams = false)
  444. {
  445. $bParamsArray = is_array($sParams);
  446. $sDisplay = is_string($sParams) ? $sParams : false;
  447. if($bParamsArray && !empty($sParams['display']))
  448. $sDisplay = $sParams['display'];
  449. bx_import('FormsEntryHelper', $this->_aModule);
  450. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  451. $oFormsHelper = new $sClass($this);
  452. if($bParamsArray && isset($sParams['dynamic_mode']))
  453. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  454. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  455. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  456. echoJson($mixedResult);
  457. exit;
  458. }
  459. return $mixedResult;
  460. }
  461. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  462. {
  463. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  464. }
  465. public function serviceEntityDelete ($iContentId = 0)
  466. {
  467. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  468. }
  469. public function serviceEntityTextBlock ($iContentId = 0)
  470. {
  471. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  472. }
  473. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  474. {
  475. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  476. }
  477. public function serviceEntityInfoFull ($iContentId = 0)
  478. {
  479. $CNF = &$this->_oConfig->CNF;
  480. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  481. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  482. }
  483. public function serviceEntityInfoExtended ($iContentId = 0)
  484. {
  485. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  486. }
  487. /**
  488. * Entry location info
  489. */
  490. public function serviceEntityLocation ($iContentId = 0)
  491. {
  492. $iContentId = $this->_getContent($iContentId, false);
  493. if($iContentId === false)
  494. return false;
  495. return $this->_oTemplate->entryLocation ($iContentId);
  496. }
  497. /**
  498. * Entry comments
  499. */
  500. public function serviceEntityComments ($iContentId = 0)
  501. {
  502. $CNF = &$this->_oConfig->CNF;
  503. if(empty($CNF['OBJECT_COMMENTS']))
  504. return '';
  505. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  506. }
  507. /**
  508. * Entry attachments block
  509. */
  510. public function serviceEntityAttachments ($iContentId = 0)
  511. {
  512. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  513. }
  514. /**
  515. * Delete content entry
  516. * @param $iContentId content id
  517. * @return error message or empty string on success
  518. */
  519. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  520. {
  521. bx_import('FormsEntryHelper', $this->_aModule);
  522. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  523. $oFormsHelper = new $sClass($this);
  524. return $oFormsHelper->$sFuncDelete($iContentId);
  525. }
  526. /**
  527. * Entry actions and social sharing block
  528. */
  529. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  530. {
  531. $CNF = &$this->_oConfig->CNF;
  532. if(!empty($mixedContent)) {
  533. if(!is_array($mixedContent))
  534. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  535. }
  536. else {
  537. $mixedContent = $this->_getContent();
  538. if($mixedContent === false)
  539. return false;
  540. }
  541. list($iContentId, $aContentInfo) = $mixedContent;
  542. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  543. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  544. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  545. if(empty($sObjectMenu))
  546. return false;
  547. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  548. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  549. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  550. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  551. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  552. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  553. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  554. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  555. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  556. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  557. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  558. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  559. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  560. $aMarkers = array(
  561. 'id' => $iContentId,
  562. 'module' => $this->_oConfig->getName(),
  563. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  564. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  565. 'img_url' => ''
  566. );
  567. if(!empty($iEntryThumb)) {
  568. if(!empty($sObjectTranscoder))
  569. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  570. else if(!empty($sObjectStorage))
  571. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  572. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  573. if(!empty($sImageUrl))
  574. $aMarkers['img_url'] = $sImageUrl;
  575. }
  576. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  577. if(!$oActions)
  578. return false;
  579. $oActions->setContentId($iContentId);
  580. $oActions->addMarkers($aMarkers);
  581. return $this->_oTemplate->entryAllActions($oActions->getCode());
  582. }
  583. /**
  584. * Entry actions block
  585. */
  586. public function serviceEntityActions ($iContentId = 0)
  587. {
  588. $iContentId = $this->_getContent($iContentId, false);
  589. if($iContentId === false)
  590. return false;
  591. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  592. return $oMenu ? $oMenu->getCode() : false;
  593. }
  594. /**
  595. * Entry social sharing block.
  596. * @param type $mixedContent integer content ID or array with integer content ID and array with content info, or false.
  597. * @param type $aParams array with additional custom params which may overwrite some default values.
  598. * @return boolean|string string with block content or false if something went wrong.
  599. */
  600. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  601. {
  602. if(!empty($mixedContent)) {
  603. if(!is_array($mixedContent))
  604. $mixedContent = array((int)$mixedContent, array());
  605. }
  606. else {
  607. $mixedContent = $this->_getContent();
  608. if($mixedContent === false)
  609. return false;
  610. }
  611. list($iContentId, $aContentInfo) = $mixedContent;
  612. $CNF = &$this->_oConfig->CNF;
  613. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  614. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  615. $sUri = $CNF['URI_VIEW_ENTRY'];
  616. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  617. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  618. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  619. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  620. $aMarkers = array(
  621. 'id' => $iContentId,
  622. 'module' => $this->_aModule['name'],
  623. 'url' => BX_DOL_URL_ROOT . $sUrl,
  624. 'title' => $sTitle,
  625. );
  626. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  627. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  628. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  629. if ($iIdThumb) {
  630. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  631. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  632. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  633. $sStorage = $CNF['OBJECT_STORAGE'];
  634. if(!empty($sTranscoder))
  635. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  636. else if(!empty($sStorage))
  637. $o = BxDolStorage::getObjectInstance($sStorage);
  638. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  639. if($sImgUrl)
  640. $aMarkers['img_url'] = $sImgUrl;
  641. }
  642. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  643. $oMenu->addMarkers($aMarkers);
  644. $sMenu = $oMenu->getCode();
  645. if(empty($sMenu))
  646. return '';
  647. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  648. 'menu' => $sMenu
  649. ));
  650. }
  651. /**
  652. * Data for Notifications module
  653. */
  654. public function serviceGetNotificationsData()
  655. {
  656. $sModule = $this->_aModule['name'];
  657. $sEventPrivacy = $sModule . '_allow_view_event_to';
  658. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  659. $sEventPrivacy = '';
  660. $aResult = array(
  661. 'handlers' => array(
  662. 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),
  663. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  664. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  665. 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),
  666. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  667. 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),
  668. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  669. 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),
  670. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  671. 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),
  672. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  673. 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),
  674. 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),
  675. ),
  676. 'settings' => array(
  677. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  678. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  679. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  680. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  681. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  682. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  683. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  684. ),
  685. 'alerts' => array(
  686. array('unit' => $sModule, 'action' => 'added'),
  687. array('unit' => $sModule, 'action' => 'edited'),
  688. array('unit' => $sModule, 'action' => 'deleted'),
  689. array('unit' => $sModule, 'action' => 'commentPost'),
  690. array('unit' => $sModule, 'action' => 'commentRemoved'),
  691. array('unit' => $sModule, 'action' => 'replyPost'),
  692. array('unit' => $sModule, 'action' => 'replyRemoved'),
  693. array('unit' => $sModule, 'action' => 'doVote'),
  694. array('unit' => $sModule, 'action' => 'undoVote'),
  695. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  696. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  697. array('unit' => $sModule, 'action' => 'doVoteUp'),
  698. array('unit' => $sModule, 'action' => 'doVoteDown'),
  699. )
  700. );
  701. if(!empty($this->_oConfig->CNF['FIELDS_DELAYED_PROCESSING'])) {
  702. $aResult = array_merge($aResult, array(
  703. 'handlers' => array(
  704. 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' => ''),
  705. 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' => ''),
  706. ),
  707. 'settings' => array(
  708. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  709. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  710. ),
  711. 'alerts' => array(
  712. array('unit' => $sModule, 'action' => 'publish_failed'),
  713. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  714. )
  715. ));
  716. }
  717. return $aResult;
  718. }
  719. /**
  720. * Entry post for Notifications module
  721. */
  722. public function serviceGetNotificationsPost($aEvent)
  723. {
  724. $CNF = &$this->_oConfig->CNF;
  725. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  726. if(empty($aContentInfo) || !is_array($aContentInfo))
  727. return array();
  728. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  729. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  730. return array(
  731. 'entry_sample' => $CNF['T']['txt_sample_single'],
  732. 'entry_url' => $sEntryUrl,
  733. 'entry_caption' => $sEntryCaption,
  734. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  735. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  736. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  737. /*
  738. * Custom settings for email and/or push notifications can be provided here.
  739. * Only necessary parts of 'settings' array can be used.
  740. *
  741. 'settings' => array(
  742. 'email' => array(
  743. 'template' => '', //--- custom email template
  744. 'markers' => '', //--- markers to parse email parts (subject, body) with
  745. 'subject' => '' //--- custom email subject
  746. ),
  747. 'push' => array(
  748. 'subject' => '' //--- custom push notification subject
  749. )
  750. )
  751. */
  752. );
  753. }
  754. public function serviceGetNotificationsPostPublishFailed($aEvent)
  755. {
  756. return $this->serviceGetNotificationsPost($aEvent);
  757. }
  758. public function serviceGetNotificationsPostPublishSucceeded($aEvent)
  759. {
  760. return $this->serviceGetNotificationsPost($aEvent);
  761. }
  762. /**
  763. * Entry post comment for Notifications module
  764. */
  765. public function serviceGetNotificationsComment($aEvent)
  766. {
  767. $CNF = &$this->_oConfig->CNF;
  768. $iContentId = (int)$aEvent['object_id'];
  769. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  770. if(empty($aContentInfo) || !is_array($aContentInfo))
  771. return array();
  772. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  773. if(!$oComment || !$oComment->isEnabled())
  774. return array();
  775. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  776. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  777. return array(
  778. 'entry_sample' => $CNF['T']['txt_sample_single'],
  779. 'entry_url' => $sEntryUrl,
  780. 'entry_caption' => $sEntryCaption,
  781. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  782. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  783. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  784. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  785. );
  786. }
  787. /**
  788. * Entry post reply for Notifications module
  789. */
  790. public function serviceGetNotificationsReply($aEvent)
  791. {
  792. $CNF = &$this->_oConfig->CNF;
  793. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  794. if(!$oComment || !$oComment->isEnabled())
  795. return array();
  796. $iParentId = (int)$aEvent['object_id'];
  797. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  798. if(empty($aParentInfo) || !is_array($aParentInfo))
  799. return array();
  800. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  801. $oComment->init($iObjectId);
  802. return array(
  803. 'object_id' => $iObjectId,
  804. 'entry_sample' => '_cmt_txt_sample_comment_single',
  805. 'entry_url' => $oComment->getViewUrl($iParentId),
  806. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  807. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  808. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  809. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  810. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  811. );
  812. }
  813. /**
  814. * Entry post vote for Notifications module
  815. */
  816. public function serviceGetNotificationsVote($aEvent)
  817. {
  818. $CNF = &$this->_oConfig->CNF;
  819. $iContentId = (int)$aEvent['object_id'];
  820. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  821. if(empty($aContentInfo) || !is_array($aContentInfo))
  822. return array();
  823. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  824. if(!$oVote || !$oVote->isEnabled())
  825. return array();
  826. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  827. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  828. return array(
  829. 'entry_sample' => $CNF['T']['txt_sample_single'],
  830. 'entry_url' => $sEntryUrl,
  831. 'entry_caption' => $sEntryCaption,
  832. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  833. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  834. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  835. );
  836. }
  837. /**
  838. * Entry post vote for Notifications module
  839. */
  840. public function serviceGetNotificationsReaction($aEvent)
  841. {
  842. $CNF = &$this->_oConfig->CNF;
  843. $iContentId = (int)$aEvent['object_id'];
  844. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  845. if(empty($aContentInfo) || !is_array($aContentInfo))
  846. return array();
  847. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  848. if(!$oReaction || !$oReaction->isEnabled())
  849. return array();
  850. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  851. if(empty($aSubentry) || !is_array($aSubentry))
  852. return array();
  853. $aSubentrySampleParams = array();
  854. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  855. if(!empty($aReaction['title']))
  856. $aSubentrySampleParams[] = $aReaction['title'];
  857. else
  858. $aSubentrySampleParams[] = '_undefined';
  859. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  860. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  861. return array(
  862. 'entry_sample' => $CNF['T']['txt_sample_single'],
  863. 'entry_url' => $sEntryUrl,
  864. 'entry_caption' => $sEntryCaption,
  865. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  866. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  867. 'subentry_sample_params' => $aSubentrySampleParams,
  868. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  869. );
  870. }
  871. /**
  872. * Entry post score -> vote up for Notifications module
  873. */
  874. public function serviceGetNotificationsScoreUp($aEvent)
  875. {
  876. return $this->_serviceGetNotificationsScore('up', $aEvent);
  877. }
  878. /**
  879. * Entry post score -> vote up for Notifications module
  880. */
  881. public function serviceGetNotificationsScoreDown($aEvent)
  882. {
  883. return $this->_serviceGetNotificationsScore('down', $aEvent);
  884. }
  885. protected function _serviceGetNotificationsScore($sType, $aEvent)
  886. {
  887. $CNF = &$this->_oConfig->CNF;
  888. $iContentId = (int)$aEvent['object_id'];
  889. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  890. if(empty($aContentInfo) || !is_array($aContentInfo))
  891. return array();
  892. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  893. if(!$oScore || !$oScore->isEnabled())
  894. return array();
  895. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  896. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  897. return array(
  898. 'entry_sample' => $CNF['T']['txt_sample_single'],
  899. 'entry_url' => $sEntryUrl,
  900. 'entry_caption' => $sEntryCaption,
  901. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  902. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  903. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  904. );
  905. }
  906. /**
  907. * Data for Timeline module
  908. */
  909. public function serviceGetTimelineData()
  910. {
  911. $sModule = $this->_aModule['name'];
  912. return array(
  913. 'handlers' => array(
  914. 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' => ''),
  915. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  916. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  917. ),
  918. 'alerts' => array(
  919. array('unit' => $sModule, 'action' => 'added'),
  920. array('unit' => $sModule, 'action' => 'edited'),
  921. array('unit' => $sModule, 'action' => 'deleted'),
  922. )
  923. );
  924. }
  925. /**
  926. * Entry post for Timeline module
  927. */
  928. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  929. {
  930. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  931. if(empty($aContentInfo) || !is_array($aContentInfo))
  932. return false;
  933. $CNF = &$this->_oConfig->CNF;
  934. if((!empty($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active') || (!empty($CNF['FIELD_STATUS_ADMIN']) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] != 'active'))
  935. return false;
  936. $iUserId = $this->getUserId();
  937. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  938. $iAuthorIdAbs = abs($iAuthorId);
  939. 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)
  940. return false;
  941. //--- Views
  942. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  943. $aViews = array();
  944. if ($oViews && $oViews->isEnabled())
  945. $aViews = array(
  946. 'system' => $CNF['OBJECT_VIEWS'],
  947. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  948. 'count' => $aContentInfo['views']
  949. );
  950. //--- Votes
  951. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  952. $aVotes = array();
  953. if ($oVotes && $oVotes->isEnabled())
  954. $aVotes = array(
  955. 'system' => $CNF['OBJECT_VOTES'],
  956. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  957. 'count' => $aContentInfo['votes']
  958. );
  959. //--- Reactions
  960. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  961. $aReactions = array();
  962. if ($oReactions && $oReactions->isEnabled())
  963. $aReactions = array(
  964. 'system' => $CNF['OBJECT_REACTIONS'],
  965. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  966. 'count' => $aContentInfo['rvotes']
  967. );
  968. //--- Scores
  969. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  970. $aScores = array();
  971. if ($oScores && $oScores->isEnabled())
  972. $aScores = array(
  973. 'system' => $CNF['OBJECT_SCORES'],
  974. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  975. 'score' => $aContentInfo['score']
  976. );
  977. //--- Reports
  978. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  979. $aReports = array();
  980. if ($oReports && $oReports->isEnabled())
  981. $aReports = array(
  982. 'system' => $CNF['OBJECT_REPORTS'],
  983. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  984. 'count' => $aContentInfo['reports']
  985. );
  986. //--- Comments
  987. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aContentInfo[$CNF['FIELD_ID']]) : null;
  988. $aComments = array();
  989. if($oCmts && $oCmts->isEnabled())
  990. $aComments = array(
  991. 'system' => $CNF['OBJECT_COMMENTS'],
  992. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  993. 'count' => $aContentInfo['comments']
  994. );
  995. //--- Title & Description
  996. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  997. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  998. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  999. $iOwnerId = $iAuthorIdAbs;
  1000. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  1001. $iOwnerId = abs($aEvent['object_privacy_view']);
  1002. $bCache = true;
  1003. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  1004. if(isset($aContent['_cache'])) {
  1005. $bCache = (bool)$aContent['_cache'];
  1006. unset($aContent['_cache']);
  1007. }
  1008. return array(
  1009. '_cache' => $bCache,
  1010. 'owner_id' => $iOwnerId,
  1011. 'object_owner_id' => $iAuthorId,
  1012. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1013. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1014. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1015. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1016. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1017. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  1018. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1019. 'views' => $aViews,
  1020. 'votes' => $aVotes,
  1021. 'reactions' => $aReactions,
  1022. 'scores' => $aScores,
  1023. 'reports' => $aReports,
  1024. 'comments' => $aComments,
  1025. 'title' => $sTitle, //may be empty.
  1026. 'description' => '' //may be empty.
  1027. );
  1028. }
  1029. public function serviceGetTimelinePostAllowedView($aEvent)
  1030. {
  1031. $iContentId = (int)$aEvent['object_id'];
  1032. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1033. if(empty($aContentInfo) || !is_array($aContentInfo))
  1034. return _t('_sys_txt_access_denied');
  1035. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1036. }
  1037. /**
  1038. * Check particular action permission without content
  1039. * @param $sAction action to check, for example: Browse, Add
  1040. * @param $iContentId content ID
  1041. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1042. */
  1043. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1044. {
  1045. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1046. if (!method_exists($this, $sMethod))
  1047. return _t('_sys_request_method_not_found_cpt');
  1048. return $this->$sMethod($isPerformAction);
  1049. }
  1050. /**
  1051. * Check particular action permission with content
  1052. * @param $sAction action to check, for example: View, Edit
  1053. * @param $iContentId content ID
  1054. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1055. */
  1056. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1057. {
  1058. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1059. return _t('_sys_request_page_not_found_cpt');
  1060. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1061. if (!method_exists($this, $sMethod))
  1062. return _t('_sys_request_method_not_found_cpt');
  1063. return $this->$sMethod($aContentInfo, $isPerformAction);
  1064. }
  1065. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1066. {
  1067. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1068. }
  1069. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1070. {
  1071. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1072. }
  1073. public function serviceGetContentOwnerProfileId ($iContentId)
  1074. {
  1075. $CNF = &$this->_oConfig->CNF;
  1076. // file owner must be author of the content or profile itself in case of profile based module
  1077. if ($iContentId) {
  1078. $sModule = $this->getName();
  1079. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1080. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1081. }
  1082. else {
  1083. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1084. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1085. }
  1086. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1087. }
  1088. else {
  1089. $iProfileId = bx_get_logged_profile_id();
  1090. }
  1091. return $iProfileId;
  1092. }
  1093. // ====== PERMISSION METHODS
  1094. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1095. {
  1096. if (!$iProfileId)
  1097. $iProfileId = $this->_iProfileId;
  1098. $CNF = &$this->_oConfig->CNF;
  1099. // moderator and owner always have access
  1100. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  1101. return CHECK_ACTION_RESULT_ALLOWED;
  1102. // check ACL
  1103. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  1104. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1105. return $aCheck[CHECK_ACTION_MESSAGE];
  1106. // check privacy
  1107. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  1108. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1109. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1110. return _t('_sys_access_denied_to_private_content');
  1111. }
  1112. // check alert to allow custom checks
  1113. $mixedResult = null;
  1114. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1115. if($mixedResult !== null)
  1116. return $mixedResult;
  1117. return CHECK_ACTION_RESULT_ALLOWED;
  1118. }
  1119. public function checkAllowedSetThumb ($iContentId = 0)
  1120. {
  1121. return CHECK_ACTION_RESULT_ALLOWED;
  1122. }
  1123. /**
  1124. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1125. */
  1126. public function checkAllowedBrowse ()
  1127. {
  1128. // check alert to allow custom checks
  1129. $mixedResult = null;
  1130. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1131. if($mixedResult !== null)
  1132. return $mixedResult;
  1133. return CHECK_ACTION_RESULT_ALLOWED;
  1134. }
  1135. /**
  1136. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1137. */
  1138. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1139. {
  1140. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1141. }
  1142. /**
  1143. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1144. */
  1145. public function checkAllowedAdd ($isPerformAction = false)
  1146. {
  1147. // check ACL
  1148. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1149. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1150. return $aCheck[CHECK_ACTION_MESSAGE];
  1151. return CHECK_ACTION_RESULT_ALLOWED;
  1152. }
  1153. /**
  1154. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1155. */
  1156. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1157. {
  1158. // moderator and owner always have access
  1159. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1160. return CHECK_ACTION_RESULT_ALLOWED;
  1161. return _t('_sys_txt_access_denied');
  1162. }
  1163. /**
  1164. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1165. */
  1166. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1167. {
  1168. // moderator always has access
  1169. if ($this->_isModerator($isPerformAction))
  1170. return CHECK_ACTION_RESULT_ALLOWED;
  1171. // check ACL
  1172. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1173. 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)
  1174. return CHECK_ACTION_RESULT_ALLOWED;
  1175. return _t('_sys_txt_access_denied');
  1176. }
  1177. /**
  1178. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1179. */
  1180. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  1181. {
  1182. // admin always has access
  1183. if (isAdmin())
  1184. return CHECK_ACTION_RESULT_ALLOWED;
  1185. // check ACL
  1186. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1187. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1188. return $aCheck[CHECK_ACTION_MESSAGE];
  1189. return CHECK_ACTION_RESULT_ALLOWED;
  1190. }
  1191. /**
  1192. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1193. */
  1194. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1195. {
  1196. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1197. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1198. return CHECK_ACTION_RESULT_ALLOWED;
  1199. return _t('_sys_txt_access_denied');
  1200. }
  1201. /**
  1202. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1203. */
  1204. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1205. {
  1206. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1207. }
  1208. /**
  1209. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1210. */
  1211. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1212. {
  1213. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1214. }
  1215. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1216. {
  1217. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1218. return MsgBox($sMsg);
  1219. bx_import($sClassSearchResult, $this->_aModule);
  1220. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1221. $o = new $sClass($sMode, $aParams);
  1222. $o->setDesignBoxTemplateId($iDesignBox);
  1223. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1224. $o->setAjaxPaginate($bAjaxPaginate);
  1225. $o->setUnitParams(array('context' => $sMode));
  1226. if ($o->isError)
  1227. return '';
  1228. if ($s = $o->processing())
  1229. return $s;
  1230. else
  1231. return '';
  1232. }
  1233. // ====== COMMON METHODS
  1234. public function alertAfterAdd($aContentInfo) {}
  1235. public function alertAfterEdit($aContentInfo) {}
  1236. public function onPublished($iContentId) {}
  1237. public function onFailed($iContentId) {}
  1238. public function processMetasAdd($iContentId)
  1239. {
  1240. $CNF = &$this->_oConfig->CNF;
  1241. if(empty($CNF['OBJECT_METATAGS']))
  1242. return;
  1243. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1244. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1245. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1246. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1247. if(!$bContentInfo)
  1248. return;
  1249. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1250. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  1251. $sKey = 'FIELD_LOCATION';
  1252. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1253. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1254. if(!empty($aLocation) && is_array($aLocation))
  1255. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1256. }
  1257. $sKey = 'FIELD_LABELS';
  1258. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1259. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1260. if(!empty($aLabels) && is_array($aLabels))
  1261. foreach ($aLabels as $sLabel)
  1262. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1263. }
  1264. }
  1265. public function processMetasEdit($iContentId, $oForm)
  1266. {
  1267. $CNF = &$this->_oConfig->CNF;
  1268. if(empty($CNF['OBJECT_METATAGS']))
  1269. return;
  1270. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1271. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1272. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1273. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1274. if(!$bContentInfo)
  1275. return;
  1276. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1277. $oMetatags->metaAddAuto($iContentId, $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  1278. $sKey = 'FIELD_LOCATION';
  1279. if($oMetatags->locationsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1280. $aLocation = unserialize($aContentInfo[$CNF[$sKey]]);
  1281. if(!empty($aLocation) && is_array($aLocation))
  1282. call_user_func_array(array($oMetatags, 'locationsAdd'), array_merge(array($iContentId), array_values($aLocation)));
  1283. }
  1284. $sKey = 'FIELD_LABELS';
  1285. if($oMetatags->keywordsIsEnabled() && !empty($CNF[$sKey]) && !empty($aContentInfo[$CNF[$sKey]])) {
  1286. $aLabels = unserialize($aContentInfo[$CNF[$sKey]]);
  1287. if(!empty($aLabels) && is_array($aLabels))
  1288. foreach ($aLabels as $sLabel)
  1289. $oMetatags->keywordsAddOne($iContentId, $sLabel, false);
  1290. }
  1291. }
  1292. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1293. {
  1294. if(empty($aTranscoders))
  1295. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1296. $CNF = &$this->_oConfig->CNF;
  1297. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1298. return false;
  1299. $iId = (int)$aContentInfo[$CNF[$sField]];
  1300. foreach($aTranscoders as $sTranscoder)
  1301. if(!empty($CNF[$sTranscoder]))
  1302. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1303. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1304. }
  1305. public function getProfileId()
  1306. {
  1307. return bx_get_logged_profile_id();
  1308. }
  1309. public function getProfileInfo($iUserId = 0)
  1310. {
  1311. $oProfile = $this->getObjectUser($iUserId);
  1312. $oAccount = null;
  1313. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1314. $oAccount = $oProfile->getAccountObject();
  1315. $bAccount = !empty($oAccount);
  1316. return array(
  1317. 'id' => $oProfile->id(),
  1318. 'name' => $oProfile->getDisplayName(),
  1319. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1320. 'link' => $oProfile->getUrl(),
  1321. 'icon' => $oProfile->getIcon(),
  1322. 'thumb' => $oProfile->getThumb(),
  1323. 'avatar' => $oProfile->getAvatar(),
  1324. 'unit' => $oProfile->getUnit(),
  1325. 'active' => $oProfile->isActive(),
  1326. );
  1327. }
  1328. public function getObjectUser($iUserId = 0)
  1329. {
  1330. bx_import('BxDolProfile');
  1331. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1332. return $oProfile;
  1333. }
  1334. public function getObjectFavorite($sSystem = '', $iId = 0)
  1335. {
  1336. $CNF = &$this->_oConfig->CNF;
  1337. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1338. $sSystem = $CNF['OBJECT_FAVORITES'];
  1339. if(empty($sSystem))
  1340. return false;
  1341. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1342. if(!$oFavorite || !$oFavorite->isEnabled())
  1343. return false;
  1344. return $oFavorite;
  1345. }
  1346. public function getUserId()
  1347. {
  1348. return isLogged() ? bx_get_logged_profile_id() : 0;
  1349. }
  1350. public function getUserIp()
  1351. {
  1352. return getVisitorIP();
  1353. }
  1354. public function getUserInfo($iUserId = 0)
  1355. {
  1356. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1357. return array(
  1358. $oProfile->getDisplayName(),
  1359. $oProfile->getUrl(),
  1360. $oProfile->getThumb(),
  1361. $oProfile->getUnit(),
  1362. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1363. );
  1364. }
  1365. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1366. {
  1367. $CNF = &$this->_oConfig->CNF;
  1368. // default visible settings
  1369. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1370. return false;
  1371. if (!empty($aItem['visibility_custom'])) {
  1372. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1373. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1374. return false;
  1375. }
  1376. // get custom function name to check menu item visibility
  1377. $sFuncCheckAccess = false;
  1378. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1379. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1380. // check custom visibility settings defined in module config class
  1381. if(!isset($aContentInfo))
  1382. $aContentInfo = array();
  1383. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1384. return false;
  1385. return true;
  1386. }
  1387. public function _isModerator ($isPerformAction = false)
  1388. {
  1389. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1390. }
  1391. public function _prepareAuditParams($aContentInfo, $bIsSaveData = true, $aOverrideAuditParams = array())
  1392. {
  1393. $CNF = &$this->_oConfig->CNF;
  1394. $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;
  1395. $AuditParams = array(
  1396. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1397. 'context_profile_id' => $iContextId,
  1398. 'content_info_object' => isset($CNF['OBJECT_CONTENT_INFO']) ? $CNF['OBJECT_CONTENT_INFO'] : '',
  1399. 'data' => ($bIsSaveData ? $aContentInfo : array())
  1400. );
  1401. if ($iContextId > 0)
  1402. $AuditParams['context_profile_title'] = BxDolProfile::getInstance($iContextId)->getDisplayName();
  1403. $AuditParams = array_merge($AuditParams, $aOverrideAuditParams);
  1404. return $AuditParams;
  1405. }
  1406. // ====== PROTECTED METHODS
  1407. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1408. {
  1409. $iContentId = $this->_getContent($iContentId, false);
  1410. if($iContentId === false)
  1411. return false;
  1412. bx_import('FormsEntryHelper', $this->_aModule);
  1413. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1414. $oFormsHelper = new $sClass($this);
  1415. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1416. }
  1417. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1418. {
  1419. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1420. if($mixedContent === false)
  1421. return false;
  1422. list($iContentId, $aContentInfo) = $mixedContent;
  1423. return $this->_oTemplate->$sFunc($aContentInfo);
  1424. }
  1425. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1426. {
  1427. $sMode = array_shift($aArgs);
  1428. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1429. $this->_oTemplate->displayAccessDenied ($sMsg);
  1430. exit;
  1431. }
  1432. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1433. bx_import ($sClass, $this->_aModule);
  1434. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1435. $o = new $sClass($sMode, $aParams);
  1436. if ($o->isError)
  1437. $this->_oTemplate->displayPageNotFound ();
  1438. else
  1439. $o->outputRSS();
  1440. exit;
  1441. }
  1442. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  1443. {
  1444. if(!$iContentId)
  1445. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1446. if(!$iContentId)
  1447. return false;
  1448. if($sFuncGetContent === true)
  1449. $sFuncGetContent = 'getContentInfoById';
  1450. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1451. return $iContentId;
  1452. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1453. if(!$aContentInfo)
  1454. return false;
  1455. return array($iContentId, $aContentInfo);
  1456. }
  1457. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1458. {
  1459. $CNF = &$this->_oConfig->CNF;
  1460. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1461. //--- Image(s)
  1462. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1463. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1464. //--- Video(s)
  1465. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1466. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1467. //--- Files(s)
  1468. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1469. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1470. //--- Title
  1471. $sTitle = '';
  1472. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1473. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1474. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1475. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1476. //--- Text
  1477. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1478. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1479. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1480. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1481. }
  1482. return array(
  1483. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1484. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1485. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1486. 'url' => $sUrl,
  1487. 'title' => $sTitle,
  1488. 'text' => $sText,
  1489. 'images' => $aImages,
  1490. 'images_attach' => $aImagesAttach,
  1491. 'videos' => $aVideos,
  1492. 'videos_attach' => $aVideosAttach,
  1493. 'files' => $aFiles,
  1494. 'files_attach' => $aFilesAttach
  1495. );
  1496. }
  1497. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1498. {
  1499. $CNF = &$this->_oConfig->CNF;
  1500. $sImage = $sImageOrig = '';
  1501. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1502. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1503. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1504. }
  1505. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1506. if($sImage == '' && $bImageThumb)
  1507. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1508. if($sImageOrig == '' && $bImageThumb)
  1509. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1510. if(empty($sImage))
  1511. return array();
  1512. if($sImageOrig == '')
  1513. $sImageOrig = $sImage;
  1514. return array(
  1515. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1516. );
  1517. }
  1518. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1519. {
  1520. return array();
  1521. }
  1522. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1523. {
  1524. return array();
  1525. }
  1526. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1527. {
  1528. return array();
  1529. }
  1530. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1531. {
  1532. return array();
  1533. }
  1534. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1535. {
  1536. return array();
  1537. }
  1538. protected function _entityComments ($sObject, $iId = 0)
  1539. {
  1540. if (!$iId)
  1541. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1542. if (!$iId)
  1543. return false;
  1544. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1545. if (!$oCmts || !$oCmts->isEnabled())
  1546. return false;
  1547. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1548. }
  1549. protected function _getFields($iContentId)
  1550. {
  1551. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1552. if(empty($aContentInfo))
  1553. return array();
  1554. return BxDolContentInfo::formatFields($aContentInfo);
  1555. }
  1556. protected function _getFieldValue($sField, $iContentId)
  1557. {
  1558. $CNF = &$this->_oConfig->CNF;
  1559. if(empty($CNF[$sField]))
  1560. return false;
  1561. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1562. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1563. return false;
  1564. return $aContentInfo[$CNF[$sField]];
  1565. }
  1566. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1567. {
  1568. $CNF = &$this->_oConfig->CNF;
  1569. if(empty($sTranscoder) || empty($CNF[$sField]))
  1570. return false;
  1571. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1572. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1573. return false;
  1574. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1575. if(!$oImagesTranscoder)
  1576. return false;
  1577. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1578. }
  1579. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1580. {
  1581. if(!$bAsJson)
  1582. return $aResponse;
  1583. if(!empty($aAdditional) && is_array($aAdditional))
  1584. $aResponse = array_merge($aResponse, $aAdditional);
  1585. echoJson($aResponse);
  1586. exit;
  1587. }
  1588. }
  1589. /** @} */