1
0

BxBaseModGeneralModule.php 60 KB

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