1
0

BxBaseModGeneralModule.php 57 KB

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