BxBaseModGeneralModule.php 69 KB

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