BxBaseModGeneralModule.php 55 KB

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