BxBaseModGeneralModule.php 60 KB

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