BxBaseModGeneralModule.php 56 KB

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