1
0

BxBaseModGeneralModule.php 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. /**
  13. * Base module class.
  14. */
  15. class BxBaseModGeneralModule extends BxDolModule
  16. {
  17. protected $_iProfileId;
  18. protected $_aSearchableNamesExcept;
  19. protected $_aFormParams;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iProfileId = bx_get_logged_profile_id();
  24. $this->_aSearchableNamesExcept = array(
  25. 'allow_view_to'
  26. );
  27. $this->_aFormParams = array(
  28. 'display' => false,
  29. 'dynamic_mode' => false,
  30. 'ajax_mode' => false,
  31. 'absolute_action_url' => false,
  32. 'visibility_autoselect' => false,
  33. 'context_id' => 0,
  34. 'custom' => array()
  35. );
  36. }
  37. // ====== ACTIONS METHODS
  38. public function actionRss ()
  39. {
  40. $aArgs = func_get_args();
  41. $this->_rss($aArgs);
  42. }
  43. public function actionGetCreatePostForm()
  44. {
  45. $sName = $this->_oConfig->getName();
  46. $aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
  47. $aParams = array_merge($this->_aFormParams, $aParams);
  48. $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
  49. $mixedResponse = $this->serviceGetCreatePostForm($aParams);
  50. if(empty($mixedResponse))
  51. return echoJson(array());
  52. else if(is_array($mixedResponse)) {
  53. $mixedResponse['module'] = $sName;
  54. return echoJson($mixedResponse);
  55. }
  56. return echoJson(array(
  57. 'module' => $sName,
  58. 'content' => $mixedResponse
  59. ));
  60. }
  61. // ====== SERVICE METHODS
  62. public function serviceGetCreatePostForm($aParams = array())
  63. {
  64. $aParams = array_merge($this->_aFormParams, $aParams);
  65. $oForm = $this->serviceGetObjectForm('add', $aParams);
  66. if(!$oForm)
  67. return '';
  68. return $this->serviceEntityCreate($aParams);
  69. }
  70. public function serviceGetAuthor ($iContentId)
  71. {
  72. $mixedResult = $this->_getFieldValue('FIELD_AUTHOR', $iContentId);
  73. return $mixedResult !== false ? (int)$mixedResult : 0;
  74. }
  75. public function serviceGetDateAdded ($iContentId)
  76. {
  77. $mixedResult = $this->_getFieldValue('FIELD_ADDED', $iContentId);
  78. return $mixedResult !== false ? (int)$mixedResult : 0;
  79. }
  80. public function serviceGetDateChanged ($iContentId)
  81. {
  82. $mixedResult = $this->_getFieldValue('FIELD_CHANGED', $iContentId);
  83. return $mixedResult !== false ? (int)$mixedResult : 0;
  84. }
  85. public function serviceGetLink ($iContentId)
  86. {
  87. $CNF = &$this->_oConfig->CNF;
  88. if(empty($CNF['URI_VIEW_ENTRY']))
  89. return '';
  90. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  91. if(empty($aContentInfo))
  92. return '';
  93. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  94. }
  95. public function serviceGetTitle ($iContentId)
  96. {
  97. $mixedResult = $this->_getFieldValue('FIELD_TITLE', $iContentId);
  98. return $mixedResult !== false ? $mixedResult : '';
  99. }
  100. public function serviceGetText ($iContentId)
  101. {
  102. $mixedResult = $this->_getFieldValue('FIELD_TEXT', $iContentId);
  103. if (false === $mixedResult)
  104. return '';
  105. $CNF = &$this->_oConfig->CNF;
  106. if (!empty($CNF['OBJECT_METATAGS']) && is_string($mixedResult)) {
  107. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  108. $mixedResult = $oMetatags->metaParse($iContentId, $mixedResult);
  109. }
  110. return $mixedResult;
  111. }
  112. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  113. {
  114. $CNF = &$this->_oConfig->CNF;
  115. $aContentInfo = $this->_getFields($iContentId);
  116. if(empty($aContentInfo))
  117. return array();
  118. if(!$bSearchableFieldsOnly)
  119. return $aContentInfo;
  120. if(empty($CNF['PARAM_SEARCHABLE_FIELDS']))
  121. return array();
  122. $aFields = explode(',', getParam($CNF['PARAM_SEARCHABLE_FIELDS']));
  123. if(empty($aFields))
  124. return array();
  125. $aResult = array();
  126. foreach($aFields as $sField)
  127. if(isset($aContentInfo[$sField]))
  128. $aResult[$sField] = $aContentInfo[$sField];
  129. return $aResult;
  130. }
  131. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  132. {
  133. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  134. if(empty($aContentInfo))
  135. return '';
  136. if(empty($sUnitTemplate))
  137. $sUnitTemplate = 'unit.html';
  138. return $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
  139. }
  140. public function serviceGetAll ($aParams = array())
  141. {
  142. if(empty($aParams) || !is_array($aParams))
  143. $aParams = array('type' => 'all');
  144. return $this->_oDb->getEntriesBy($aParams);
  145. }
  146. public function serviceGetAllByAuthor ($iProfileId)
  147. {
  148. return $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  149. }
  150. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  151. {
  152. $CNF = &$this->_oConfig->CNF;
  153. if(empty($CNF['OBJECT_FORM_ENTRY']))
  154. return array();
  155. $aResult = array();
  156. if(!empty($CNF['FIELD_AUTHOR']) && !in_array($CNF['FIELD_AUTHOR'], $this->_aSearchableNamesExcept))
  157. $aResult[$CNF['FIELD_AUTHOR']] = array(
  158. 'type' => 'text_auto',
  159. 'caption' => $CNF['T']['form_field_author'],
  160. 'info' => '',
  161. 'value' => '',
  162. 'values' => '',
  163. 'pass' => ''
  164. );
  165. $aInputs = array();
  166. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'])) {
  167. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  168. $aInputs = array_merge($aInputs, $oForm->aInputs);
  169. }
  170. if(!empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'])) {
  171. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT'], $this->_oTemplate);
  172. $aInputs = array_merge($aInputs, $oForm->aInputs);
  173. }
  174. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  175. $aInputs = array_merge($aInputs, $aInputsAdd);
  176. foreach($aInputs as $aInput){
  177. if(in_array($aInput['type'], BxDolSearchExtended::$SEARCHABLE_TYPES) && !in_array($aInput['name'], $this->_aSearchableNamesExcept)) {
  178. $aField = array(
  179. 'type' => $aInput['type'],
  180. 'caption_system' => $aInput['caption_system_src'],
  181. 'caption' => $aInput['caption_src'],
  182. 'info' => $aInput['info_src'],
  183. 'value' => !empty($aInput['value']) ? $aInput['value'] : '',
  184. 'values' => !empty($aInput['values_src']) ? $aInput['values_src'] : '',
  185. 'pass' => !empty($aInput['db']['pass']) ? $aInput['db']['pass'] : '',
  186. );
  187. if(isset($aInput['search_type']))
  188. $aField['search_type'] = $aInput['search_type'];
  189. $aResult[$aInput['name']] = $aField;
  190. }
  191. }
  192. return $aResult;
  193. }
  194. public function serviceGetSearchResultExtended($aParams, $iStart = 0, $iPerPage = 0)
  195. {
  196. if(empty($aParams) || !is_array($aParams))
  197. return array();
  198. return $this->_oDb->getEntriesBy(array('type' => 'search_ids', 'search_params' => $aParams, 'start' => $iStart, 'per_page' => $iPerPage));
  199. }
  200. public function serviceModuleIcon ()
  201. {
  202. return isset($this->_oConfig->CNF['ICON']) ? $this->_oConfig->CNF['ICON'] : '';
  203. }
  204. public function serviceGetSearchableFields ($aInputsAdd = array())
  205. {
  206. $CNF = $this->_oConfig->CNF;
  207. if(!isset($CNF['PARAM_SEARCHABLE_FIELDS']) || !isset($CNF['OBJECT_FORM_ENTRY']) || !isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']))
  208. return array();
  209. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  210. if(!$oForm)
  211. return array();
  212. $aInputs = $oForm->aInputs;
  213. if(!empty($aInputsAdd) && is_array($aInputsAdd))
  214. $aInputs = array_merge($aInputs, $aInputsAdd);
  215. $aTextTypes = array('text', 'textarea');
  216. $aTextFields = array();
  217. foreach($aInputs as $r)
  218. if(in_array($r['type'], $aTextTypes))
  219. $aTextFields[$r['name']] = $r['caption'];
  220. return $aTextFields;
  221. }
  222. public function serviceManageTools($sType = 'common')
  223. {
  224. $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->getGridObject($sType));
  225. if(!$oGrid)
  226. return '';
  227. $CNF = &$this->_oConfig->CNF;
  228. $sMenu = '';
  229. if(BxDolAcl::getInstance()->isMemberLevelInSet(192)) {
  230. $oPermalink = BxDolPermalinks::getInstance();
  231. $aMenuItems = array();
  232. if(!empty($CNF['OBJECT_GRID_COMMON']) && !empty($CNF['T']['menu_item_manage_my']))
  233. $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);
  234. if(!empty($CNF['OBJECT_GRID_ADMINISTRATION']) && !empty($CNF['T']['menu_item_manage_all']))
  235. $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);
  236. if(count($aMenuItems) > 1) {
  237. $oMenu = new BxTemplMenu(array(
  238. 'template' => 'menu_vertical.html',
  239. 'menu_items' => $aMenuItems
  240. ), $this->_oTemplate);
  241. $oMenu->setSelected($this->_aModule['name'], 'manage-' . $sType);
  242. $sMenu = $oMenu->getCode();
  243. }
  244. }
  245. if(!empty($CNF['OBJECT_MENU_SUBMENU']) && isset($CNF['URI_MANAGE_COMMON'])) {
  246. BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SUBMENU'])->setSelected($this->_aModule['name'], $CNF['URI_MANAGE_COMMON']);
  247. }
  248. $this->_oTemplate->addCss(array('manage_tools.css'));
  249. $this->_oTemplate->addJs(array('manage_tools.js'));
  250. $this->_oTemplate->addJsTranslation(array('_sys_grid_search'));
  251. return array(
  252. 'content' => $this->_oTemplate->getJsCode('manage_tools', array('sObjNameGrid' => $this->_oConfig->getGridObject($sType))) . $oGrid->getCode(),
  253. 'menu' => $sMenu
  254. );
  255. }
  256. public function serviceGetMenuAddonManageTools()
  257. {
  258. return 0;
  259. }
  260. public function serviceGetMenuAddonManageToolsProfileStats()
  261. {
  262. return 0;
  263. }
  264. /**
  265. * My entries actions block
  266. */
  267. public function serviceMyEntriesActions ($iProfileId = 0)
  268. {
  269. $CNF = &$this->_oConfig->CNF;
  270. if(empty($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']))
  271. return false;
  272. if (!$iProfileId)
  273. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  274. if (!$iProfileId || !($oProfile = BxDolProfile::getInstance($iProfileId)))
  275. return false;
  276. if ($iProfileId != $this->_iProfileId)
  277. return false;
  278. $oMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_MY_ENTRIES']);
  279. return $oMenu ? $oMenu->getCode() : false;
  280. }
  281. /**
  282. * Universal browse method
  283. * @param $aParams custom browse params, possible params are the following:
  284. * - mode - browse mode, such as 'recent', 'featured', etc
  285. * - params - custom params to browse method, for example 'unit_view' can be passed here
  286. * - design_box - design box style, @see BxBaseFunctions::DesignBoxContent
  287. * - empty_message - display or not "empty" message when there is no content
  288. * - ajax_paginate - use AJAX paginate or not
  289. * @return HTML string
  290. */
  291. public function serviceBrowse ($aParams = array())
  292. {
  293. $aDefaults = array (
  294. 'mode' => 'recent',
  295. 'params' => false,
  296. 'design_box' => BX_DB_PADDING_DEF,
  297. 'empty_message' => false,
  298. 'ajax_paginate' => true,
  299. );
  300. $aParams = array_merge($aDefaults, $aParams);
  301. return $this->_serviceBrowse ($aParams['mode'], $aParams['params'], $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  302. }
  303. /**
  304. * Display featured entries
  305. * @return HTML string
  306. */
  307. public function serviceBrowseFeatured ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  308. {
  309. return $this->_serviceBrowse ('featured', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  310. }
  311. /**
  312. * Display entries favored by a member
  313. * @return HTML string
  314. */
  315. public function serviceBrowseFavorite ($iProfileId = 0, $aParams = array())
  316. {
  317. $oProfile = null;
  318. if((int)$iProfileId)
  319. $oProfile = BxDolProfile::getInstance($iProfileId);
  320. if(!$oProfile && bx_get('profile_id') !== false)
  321. $oProfile = BxDolProfile:: getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT));
  322. if(!$oProfile)
  323. $oProfile = BxDolProfile::getInstance();
  324. if(!$oProfile)
  325. return '';
  326. $bEmptyMessage = false;
  327. if(isset($aParams['empty_message'])) {
  328. $bEmptyMessage = (bool)$aParams['empty_message'];
  329. unset($aParams['empty_message']);
  330. }
  331. return $this->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage);
  332. }
  333. public function serviceFormsHelper ()
  334. {
  335. bx_import('FormsEntryHelper', $this->_aModule);
  336. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  337. return new $sClass($this);
  338. }
  339. /**
  340. * Add entry using provided fields' values.
  341. * @return array with result: 'code' is 0 on success or non-zero on error, 'message' is error message in case of error, 'content' is content info array in case of success
  342. */
  343. public function serviceEntityAdd ($iProfile, $aValues)
  344. {
  345. bx_import('FormsEntryHelper', $this->_aModule);
  346. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  347. $oFormsHelper = new $sClass($this);
  348. return $oFormsHelper->addData($iProfile, $aValues);
  349. }
  350. /**
  351. * Perform redirect after content creation
  352. * @return nothing, rediret header is sent
  353. */
  354. public function serviceRedirectAfterAdd($aContentInfo)
  355. {
  356. bx_import('FormsEntryHelper', $this->_aModule);
  357. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  358. $oFormsHelper = new $sClass($this);
  359. $oFormsHelper->redirectAfterAdd($aContentInfo);
  360. }
  361. /**
  362. * Get form object for add, edit, view or delete the content
  363. * @param $sType 'add', 'edit', 'view' or 'delete'
  364. * @param $aParams optional array with parameters(display name, etc)
  365. * @return form object or false on error
  366. */
  367. public function serviceGetObjectForm ($sType, $aParams = array())
  368. {
  369. if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
  370. return false;
  371. $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
  372. $bContext = $mixedContextId !== false;
  373. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  374. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  375. return false;
  376. $CNF = &$this->_oConfig->CNF;
  377. bx_import('FormsEntryHelper', $this->_aModule);
  378. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  379. $oFormsHelper = new $sClass($this);
  380. $sParamsKey = 'ajax_mode';
  381. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  382. $oFormsHelper->setAjaxMode((bool)$aParams[$sParamsKey]);
  383. $sParamsKey = 'absolute_action_url';
  384. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  385. $oFormsHelper->setAbsoluteActionUrl((bool)$aParams[$sParamsKey]);
  386. $sDisplay = !empty($aParams['display']) ? $aParams['display'] : false;
  387. $sFunc = 'getObjectForm' . ucfirst($sType);
  388. $oForm = $oFormsHelper->$sFunc($sDisplay);
  389. $sKey = 'FIELD_ALLOW_VIEW_TO';
  390. if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
  391. $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
  392. if(!$bContext || $bContextOwner) {
  393. $iGc = 0;
  394. $iKeyGh = false;
  395. foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
  396. if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
  397. if($iKeyGh !== false && $iGc == 0) {
  398. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
  399. $iKeyGh = false;
  400. if($aValue['type'] == 'group_end')
  401. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  402. }
  403. if($aValue['type'] == 'group_header') {
  404. $iGc = 0;
  405. $iKeyGh = $iKey;
  406. }
  407. continue;
  408. }
  409. //--- Show 'Public' privacy group only in Public post form.
  410. if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
  411. $iGc += 1;
  412. continue;
  413. }
  414. //--- Show a default privacy groups in Profile (for Owner) post form.
  415. if($bContextOwner && (int)$aValue['key'] >= 0) {
  416. $iGc += 1;
  417. continue;
  418. }
  419. unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
  420. }
  421. }
  422. else {
  423. $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
  424. $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
  425. }
  426. }
  427. bx_alert('system', 'get_object_form', 0, 0, array(
  428. 'module' => $this->_oConfig->getName(),
  429. 'type' => $sType,
  430. 'params' => $aParams,
  431. 'form' => &$oForm
  432. ));
  433. return $oForm;
  434. }
  435. /**
  436. * Create entry form
  437. * @return HTML string
  438. */
  439. public function serviceEntityCreate ($sParams = false)
  440. {
  441. $bParamsArray = is_array($sParams);
  442. $sDisplay = is_string($sParams) ? $sParams : false;
  443. if($bParamsArray && !empty($sParams['display']))
  444. $sDisplay = $sParams['display'];
  445. bx_import('FormsEntryHelper', $this->_aModule);
  446. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  447. $oFormsHelper = new $sClass($this);
  448. if($bParamsArray && isset($sParams['dynamic_mode']))
  449. $oFormsHelper->setDynamicMode($sParams['dynamic_mode']);
  450. $mixedResult = $oFormsHelper->addDataForm($sDisplay);
  451. if(isset($mixedResult['_dt']) && $mixedResult['_dt'] == 'json') {
  452. echoJson($mixedResult);
  453. exit;
  454. }
  455. return $mixedResult;
  456. }
  457. public function serviceEntityEdit ($iContentId = 0, $sDisplay = false)
  458. {
  459. return $this->_serviceEntityForm ('editDataForm', $iContentId, $sDisplay);
  460. }
  461. public function serviceEntityDelete ($iContentId = 0)
  462. {
  463. return $this->_serviceEntityForm ('deleteDataForm', $iContentId);
  464. }
  465. public function serviceEntityTextBlock ($iContentId = 0)
  466. {
  467. return $this->_serviceEntityForm ('viewDataEntry', $iContentId);
  468. }
  469. public function serviceEntityInfo ($iContentId = 0, $sDisplay = false)
  470. {
  471. return $this->_serviceEntityForm ('viewDataForm', $iContentId, $sDisplay);
  472. }
  473. public function serviceEntityInfoFull ($iContentId = 0)
  474. {
  475. $CNF = &$this->_oConfig->CNF;
  476. $sDisplayName = 'OBJECT_FORM_ENTRY_DISPLAY_VIEW_FULL';
  477. return $this->_serviceEntityForm ('viewDataForm', $iContentId, !empty($CNF[$sDisplayName]) ? $CNF[$sDisplayName] : false);
  478. }
  479. public function serviceEntityInfoExtended ($iContentId = 0)
  480. {
  481. return $this->_serviceTemplateFunc ('entryInfo', $iContentId);
  482. }
  483. /**
  484. * Entry location info
  485. */
  486. public function serviceEntityLocation ($iContentId = 0)
  487. {
  488. $iContentId = $this->_getContent($iContentId, false);
  489. if($iContentId === false)
  490. return false;
  491. return $this->_oTemplate->entryLocation ($iContentId);
  492. }
  493. /**
  494. * Entry comments
  495. */
  496. public function serviceEntityComments ($iContentId = 0)
  497. {
  498. $CNF = &$this->_oConfig->CNF;
  499. if(empty($CNF['OBJECT_COMMENTS']))
  500. return '';
  501. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
  502. }
  503. /**
  504. * Entry attachments block
  505. */
  506. public function serviceEntityAttachments ($iContentId = 0)
  507. {
  508. return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
  509. }
  510. /**
  511. * Delete content entry
  512. * @param $iContentId content id
  513. * @return error message or empty string on success
  514. */
  515. public function serviceDeleteEntity ($iContentId, $sFuncDelete = 'deleteData')
  516. {
  517. bx_import('FormsEntryHelper', $this->_aModule);
  518. $sClass = $this->_oConfig->getClassPrefix() . 'FormsEntryHelper';
  519. $oFormsHelper = new $sClass($this);
  520. return $oFormsHelper->$sFuncDelete($iContentId);
  521. }
  522. /**
  523. * Entry actions and social sharing block
  524. */
  525. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  526. {
  527. $CNF = &$this->_oConfig->CNF;
  528. if(!empty($mixedContent)) {
  529. if(!is_array($mixedContent))
  530. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  531. }
  532. else {
  533. $mixedContent = $this->_getContent();
  534. if($mixedContent === false)
  535. return false;
  536. }
  537. list($iContentId, $aContentInfo) = $mixedContent;
  538. $sObjectMenu = !empty($aParams['object_menu']) ? $aParams['object_menu'] : '';
  539. if(empty($sObjectMenu) && !empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  540. $sObjectMenu = $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL'];
  541. if(empty($sObjectMenu))
  542. return false;
  543. $sEntryTitle = !empty($aParams['entry_title']) ? $aParams['entry_title'] : '';
  544. if(empty($sEntryTitle) && !empty($CNF['FIELD_TITLE']) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  545. $sEntryTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  546. $sEntryUrl = !empty($aParams['entry_url']) ? $aParams['entry_url'] : '';
  547. if(empty($sEntryUrl) && !empty($CNF['URI_VIEW_ENTRY']))
  548. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId);
  549. $iEntryThumb = !empty($aParams['entry_thumb']) ? (int)$aParams['entry_thumb'] : 0;
  550. if(empty($iEntryThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  551. $iEntryThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  552. $sObjectStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : false;
  553. if(empty($sObjectStorage) && !empty($CNF['OBJECT_STORAGE']))
  554. $sObjectStorage = $CNF['OBJECT_STORAGE'];
  555. $sObjectTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : false;
  556. $aMarkers = array(
  557. 'id' => $iContentId,
  558. 'module' => $this->_oConfig->getName(),
  559. 'title' => !empty($sEntryTitle) ? $sEntryTitle : '',
  560. 'url' => !empty($sEntryUrl) ? $sEntryUrl : '',
  561. 'img_url' => ''
  562. );
  563. if(!empty($iEntryThumb)) {
  564. if(!empty($sObjectTranscoder))
  565. $o = BxDolTranscoder::getObjectInstance($sObjectTranscoder);
  566. else if(!empty($sObjectStorage))
  567. $o = BxDolStorage::getObjectInstance($sObjectStorage);
  568. $sImageUrl = $o ? $o->getFileUrlById($iEntryThumb) : '';
  569. if(!empty($sImageUrl))
  570. $aMarkers['img_url'] = $sImageUrl;
  571. }
  572. $oActions = BxDolMenu::getObjectInstance($sObjectMenu);
  573. if(!$oActions)
  574. return false;
  575. $oActions->setContentId($iContentId);
  576. $oActions->addMarkers($aMarkers);
  577. return $this->_oTemplate->entryAllActions($oActions->getCode());
  578. }
  579. /**
  580. * Entry actions block
  581. */
  582. public function serviceEntityActions ($iContentId = 0)
  583. {
  584. $iContentId = $this->_getContent($iContentId, false);
  585. if($iContentId === false)
  586. return false;
  587. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY']);
  588. return $oMenu ? $oMenu->getCode() : false;
  589. }
  590. /**
  591. * Entry social sharing block.
  592. * @param type $mixedContent integer content ID or array with integer content ID and array with content info, or false.
  593. * @param type $aParams array with additional custom params which may overwrite some default values.
  594. * @return boolean|string string with block content or false if something went wrong.
  595. */
  596. public function serviceEntitySocialSharing($mixedContent = false, $aParams = array())
  597. {
  598. if(!empty($mixedContent)) {
  599. if(!is_array($mixedContent))
  600. $mixedContent = array((int)$mixedContent, array());
  601. }
  602. else {
  603. $mixedContent = $this->_getContent();
  604. if($mixedContent === false)
  605. return false;
  606. }
  607. list($iContentId, $aContentInfo) = $mixedContent;
  608. $CNF = &$this->_oConfig->CNF;
  609. $sUri = !empty($aParams['uri']) ? $aParams['uri'] : '';
  610. if(empty($sUri) && !empty($CNF['URI_VIEW_ENTRY']))
  611. $sUri = $CNF['URI_VIEW_ENTRY'];
  612. $sUrl = !empty($sUri) ? BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sUri . '&id=' . $iContentId) : '';
  613. $sTitle = !empty($aParams['title']) ? $aParams['title'] : '';
  614. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  615. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  616. $aMarkers = array(
  617. 'id' => $iContentId,
  618. 'module' => $this->_aModule['name'],
  619. 'url' => BX_DOL_URL_ROOT . $sUrl,
  620. 'title' => $sTitle,
  621. );
  622. $iIdThumb = !empty($aParams['id_thumb']) ? (int)$aParams['id_thumb'] : 0;
  623. if(empty($iIdThumb) && !empty($CNF['FIELD_THUMB']) && !empty($aContentInfo[$CNF['FIELD_THUMB']]))
  624. $iIdThumb = (int)$aContentInfo[$CNF['FIELD_THUMB']];
  625. if ($iIdThumb) {
  626. $sTranscoder = !empty($aParams['object_transcoder']) ? $aParams['object_transcoder'] : '';
  627. $sStorage = !empty($aParams['object_storage']) ? $aParams['object_storage'] : '';
  628. if(empty($sStorage) && !empty($CNF['OBJECT_STORAGE']))
  629. $sStorage = $CNF['OBJECT_STORAGE'];
  630. if(!empty($sTranscoder))
  631. $o = BxDolTranscoder::getObjectInstance($sTranscoder);
  632. else if(!empty($sStorage))
  633. $o = BxDolStorage::getObjectInstance($sStorage);
  634. $sImgUrl = $o ? $o->getFileUrlById($iIdThumb) : '';
  635. if($sImgUrl)
  636. $aMarkers['img_url'] = $sImgUrl;
  637. }
  638. $oMenu = BxDolMenu::getObjectInstance('sys_social_sharing');
  639. $oMenu->addMarkers($aMarkers);
  640. $sMenu = $oMenu->getCode();
  641. if(empty($sMenu))
  642. return '';
  643. return $this->_oTemplate->parseHtmlByName('entry-share.html', array(
  644. 'menu' => $sMenu
  645. ));
  646. }
  647. /**
  648. * Data for Notifications module
  649. */
  650. public function serviceGetNotificationsData()
  651. {
  652. $sModule = $this->_aModule['name'];
  653. $sEventPrivacy = $sModule . '_allow_view_event_to';
  654. if(BxDolPrivacy::getObjectInstance($sEventPrivacy) === false)
  655. $sEventPrivacy = '';
  656. return array(
  657. 'handlers' => array(
  658. 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),
  659. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  660. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted'),
  661. 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),
  662. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  663. 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),
  664. array('group' => $sModule . '_reply', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'replyRemoved'),
  665. 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),
  666. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  667. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  668. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  669. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  670. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module', 'module_event_privacy' => $sEventPrivacy),
  671. ),
  672. 'settings' => array(
  673. array('group' => 'content', 'unit' => $sModule, 'action' => 'added', 'types' => array('follow_member', 'follow_context')),
  674. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  675. array('group' => 'reply', 'unit' => $sModule, 'action' => 'replyPost', 'types' => array('personal')),
  676. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  677. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  678. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  679. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  680. ),
  681. 'alerts' => array(
  682. array('unit' => $sModule, 'action' => 'added'),
  683. array('unit' => $sModule, 'action' => 'edited'),
  684. array('unit' => $sModule, 'action' => 'deleted'),
  685. array('unit' => $sModule, 'action' => 'commentPost'),
  686. array('unit' => $sModule, 'action' => 'commentRemoved'),
  687. array('unit' => $sModule, 'action' => 'replyPost'),
  688. array('unit' => $sModule, 'action' => 'replyRemoved'),
  689. array('unit' => $sModule, 'action' => 'doVote'),
  690. array('unit' => $sModule, 'action' => 'undoVote'),
  691. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  692. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  693. array('unit' => $sModule, 'action' => 'doVoteUp'),
  694. array('unit' => $sModule, 'action' => 'doVoteDown'),
  695. )
  696. );
  697. }
  698. /**
  699. * Entry post for Notifications module
  700. */
  701. public function serviceGetNotificationsPost($aEvent)
  702. {
  703. $CNF = &$this->_oConfig->CNF;
  704. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  705. if(empty($aContentInfo) || !is_array($aContentInfo))
  706. return array();
  707. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  708. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  709. return array(
  710. 'entry_sample' => $CNF['T']['txt_sample_single'],
  711. 'entry_url' => $sEntryUrl,
  712. 'entry_caption' => $sEntryCaption,
  713. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  714. 'entry_privacy' => '', //may be empty or not specified. In this case Public privacy will be used.
  715. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  716. /*
  717. * Custom settings for email and/or push notifications can be provided here.
  718. * Only necessary parts of 'settings' array can be used.
  719. *
  720. 'settings' => array(
  721. 'email' => array(
  722. 'template' => '', //--- custom email template
  723. 'markers' => '', //--- markers to parse email parts (subject, body) with
  724. 'subject' => '' //--- custom email subject
  725. ),
  726. 'push' => array(
  727. 'subject' => '' //--- custom push notification subject
  728. )
  729. )
  730. */
  731. );
  732. }
  733. /**
  734. * Entry post comment for Notifications module
  735. */
  736. public function serviceGetNotificationsComment($aEvent)
  737. {
  738. $CNF = &$this->_oConfig->CNF;
  739. $iContentId = (int)$aEvent['object_id'];
  740. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  741. if(empty($aContentInfo) || !is_array($aContentInfo))
  742. return array();
  743. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContentId);
  744. if(!$oComment || !$oComment->isEnabled())
  745. return array();
  746. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  747. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  748. return array(
  749. 'entry_sample' => $CNF['T']['txt_sample_single'],
  750. 'entry_url' => $sEntryUrl,
  751. 'entry_caption' => $sEntryCaption,
  752. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  753. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  754. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  755. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  756. );
  757. }
  758. /**
  759. * Entry post reply for Notifications module
  760. */
  761. public function serviceGetNotificationsReply($aEvent)
  762. {
  763. $CNF = &$this->_oConfig->CNF;
  764. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], 0, false);
  765. if(!$oComment || !$oComment->isEnabled())
  766. return array();
  767. $iParentId = (int)$aEvent['object_id'];
  768. $aParentInfo = $oComment->getQueryObject()->getCommentsBy(array('type' => 'id', 'id' => $iParentId));
  769. if(empty($aParentInfo) || !is_array($aParentInfo))
  770. return array();
  771. $iObjectId = (int)$aParentInfo['cmt_object_id'];
  772. $oComment->init($iObjectId);
  773. return array(
  774. 'object_id' => $iObjectId,
  775. 'entry_sample' => '_cmt_txt_sample_comment_single',
  776. 'entry_url' => $oComment->getViewUrl($iParentId),
  777. 'entry_caption' => strmaxtextlen($aParentInfo['cmt_text'], 20, '...'),
  778. 'entry_author' => (int)$aParentInfo['cmt_author_id'],
  779. 'subentry_sample' => '_cmt_txt_sample_reply_to',
  780. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  781. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  782. );
  783. }
  784. /**
  785. * Entry post vote for Notifications module
  786. */
  787. public function serviceGetNotificationsVote($aEvent)
  788. {
  789. $CNF = &$this->_oConfig->CNF;
  790. $iContentId = (int)$aEvent['object_id'];
  791. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  792. if(empty($aContentInfo) || !is_array($aContentInfo))
  793. return array();
  794. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContentId);
  795. if(!$oVote || !$oVote->isEnabled())
  796. return array();
  797. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  798. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  799. return array(
  800. 'entry_sample' => $CNF['T']['txt_sample_single'],
  801. 'entry_url' => $sEntryUrl,
  802. 'entry_caption' => $sEntryCaption,
  803. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  804. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  805. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  806. );
  807. }
  808. /**
  809. * Entry post vote for Notifications module
  810. */
  811. public function serviceGetNotificationsReaction($aEvent)
  812. {
  813. $CNF = &$this->_oConfig->CNF;
  814. $iContentId = (int)$aEvent['object_id'];
  815. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  816. if(empty($aContentInfo) || !is_array($aContentInfo))
  817. return array();
  818. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContentId);
  819. if(!$oReaction || !$oReaction->isEnabled())
  820. return array();
  821. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  822. if(empty($aSubentry) || !is_array($aSubentry))
  823. return array();
  824. $aSubentrySampleParams = array();
  825. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  826. if(!empty($aReaction['title']))
  827. $aSubentrySampleParams[] = $aReaction['title'];
  828. else
  829. $aSubentrySampleParams[] = '_undefined';
  830. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  831. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  832. return array(
  833. 'entry_sample' => $CNF['T']['txt_sample_single'],
  834. 'entry_url' => $sEntryUrl,
  835. 'entry_caption' => $sEntryCaption,
  836. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  837. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  838. 'subentry_sample_params' => $aSubentrySampleParams,
  839. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  840. );
  841. }
  842. /**
  843. * Entry post score -> vote up for Notifications module
  844. */
  845. public function serviceGetNotificationsScoreUp($aEvent)
  846. {
  847. return $this->_serviceGetNotificationsScore('up', $aEvent);
  848. }
  849. /**
  850. * Entry post score -> vote up for Notifications module
  851. */
  852. public function serviceGetNotificationsScoreDown($aEvent)
  853. {
  854. return $this->_serviceGetNotificationsScore('down', $aEvent);
  855. }
  856. protected function _serviceGetNotificationsScore($sType, $aEvent)
  857. {
  858. $CNF = &$this->_oConfig->CNF;
  859. $iContentId = (int)$aEvent['object_id'];
  860. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  861. if(empty($aContentInfo) || !is_array($aContentInfo))
  862. return array();
  863. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContentId);
  864. if(!$oScore || !$oScore->isEnabled())
  865. return array();
  866. $sEntryUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  867. $sEntryCaption = isset($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  868. return array(
  869. 'entry_sample' => $CNF['T']['txt_sample_single'],
  870. 'entry_url' => $sEntryUrl,
  871. 'entry_caption' => $sEntryCaption,
  872. 'entry_author' => $aContentInfo[$CNF['FIELD_AUTHOR']],
  873. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  874. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  875. );
  876. }
  877. /**
  878. * Data for Timeline module
  879. */
  880. public function serviceGetTimelineData()
  881. {
  882. $sModule = $this->_aModule['name'];
  883. return array(
  884. 'handlers' => array(
  885. 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' => ''),
  886. array('group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'edited'),
  887. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'deleted')
  888. ),
  889. 'alerts' => array(
  890. array('unit' => $sModule, 'action' => 'added'),
  891. array('unit' => $sModule, 'action' => 'edited'),
  892. array('unit' => $sModule, 'action' => 'deleted'),
  893. )
  894. );
  895. }
  896. /**
  897. * Entry post for Timeline module
  898. */
  899. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  900. {
  901. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  902. if(empty($aContentInfo) || !is_array($aContentInfo))
  903. return false;
  904. $CNF = &$this->_oConfig->CNF;
  905. $iUserId = $this->getUserId();
  906. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  907. $iAuthorIdAbs = abs($iAuthorId);
  908. if($iAuthorId < 0 && ((is_numeric($aEvent['owner_id']) && $iAuthorIdAbs == (int)$aEvent['owner_id']) || (is_array($aEvent['owner_id']) && in_array($iAuthorIdAbs, $aEvent['owner_id']))) && $iAuthorIdAbs != $iUserId)
  909. return false;
  910. //--- Views
  911. $oViews = isset($CNF['OBJECT_VIEWS']) ? BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $aEvent['object_id']) : null;
  912. $aViews = array();
  913. if ($oViews && $oViews->isEnabled())
  914. $aViews = array(
  915. 'system' => $CNF['OBJECT_VIEWS'],
  916. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  917. 'count' => $aContentInfo['views']
  918. );
  919. //--- Votes
  920. $oVotes = isset($CNF['OBJECT_VOTES']) ? BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aEvent['object_id']) : null;
  921. $aVotes = array();
  922. if ($oVotes && $oVotes->isEnabled())
  923. $aVotes = array(
  924. 'system' => $CNF['OBJECT_VOTES'],
  925. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  926. 'count' => $aContentInfo['votes']
  927. );
  928. //--- Reactions
  929. $oReactions = isset($CNF['OBJECT_REACTIONS']) ? BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aEvent['object_id']) : null;
  930. $aReactions = array();
  931. if ($oReactions && $oReactions->isEnabled())
  932. $aReactions = array(
  933. 'system' => $CNF['OBJECT_REACTIONS'],
  934. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  935. 'count' => $aContentInfo['rvotes']
  936. );
  937. //--- Scores
  938. $oScores = isset($CNF['OBJECT_SCORES']) ? BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $aEvent['object_id']) : null;
  939. $aScores = array();
  940. if ($oScores && $oScores->isEnabled())
  941. $aScores = array(
  942. 'system' => $CNF['OBJECT_SCORES'],
  943. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  944. 'score' => $aContentInfo['score']
  945. );
  946. //--- Reports
  947. $oReports = isset($CNF['OBJECT_REPORTS']) ? BxDolReport::getObjectInstance($CNF['OBJECT_REPORTS'], $aEvent['object_id']) : null;
  948. $aReports = array();
  949. if ($oReports && $oReports->isEnabled())
  950. $aReports = array(
  951. 'system' => $CNF['OBJECT_REPORTS'],
  952. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  953. 'count' => $aContentInfo['reports']
  954. );
  955. //--- Comments
  956. $oCmts = isset($CNF['OBJECT_COMMENTS']) ? BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $aEvent['object_id']) : null;
  957. $aComments = array();
  958. if($oCmts && $oCmts->isEnabled())
  959. $aComments = array(
  960. 'system' => $CNF['OBJECT_COMMENTS'],
  961. 'object_id' => $aContentInfo[$CNF['FIELD_ID']],
  962. 'count' => $aContentInfo['comments']
  963. );
  964. //--- Title & Description
  965. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  966. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  967. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  968. $iOwnerId = $iAuthorIdAbs;
  969. if(isset($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0)
  970. $iOwnerId = abs($aEvent['object_privacy_view']);
  971. $bCache = true;
  972. $aContent = $this->_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
  973. if(isset($aContent['_cache'])) {
  974. $bCache = (bool)$aContent['_cache'];
  975. unset($aContent['_cache']);
  976. }
  977. return array(
  978. '_cache' => $bCache,
  979. 'owner_id' => $iOwnerId,
  980. 'object_owner_id' => $iAuthorId,
  981. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  982. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  983. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  984. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  985. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  986. 'content' => $aContent, //a string to display or array to parse default template before displaying.
  987. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  988. 'views' => $aViews,
  989. 'votes' => $aVotes,
  990. 'reactions' => $aReactions,
  991. 'scores' => $aScores,
  992. 'reports' => $aReports,
  993. 'comments' => $aComments,
  994. 'title' => $sTitle, //may be empty.
  995. 'description' => '' //may be empty.
  996. );
  997. }
  998. public function serviceGetTimelinePostAllowedView($aEvent)
  999. {
  1000. $iContentId = (int)$aEvent['object_id'];
  1001. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1002. if(empty($aContentInfo) || !is_array($aContentInfo))
  1003. return _t('_sys_txt_access_denied');
  1004. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1005. }
  1006. /**
  1007. * Check particular action permission without content
  1008. * @param $sAction action to check, for example: Browse, Add
  1009. * @param $iContentId content ID
  1010. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1011. */
  1012. public function serviceCheckAllowed($sAction, $isPerformAction = false)
  1013. {
  1014. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1015. if (!method_exists($this, $sMethod))
  1016. return _t('_sys_request_method_not_found_cpt');
  1017. return $this->$sMethod($isPerformAction);
  1018. }
  1019. /**
  1020. * Check particular action permission with content
  1021. * @param $sAction action to check, for example: View, Edit
  1022. * @param $iContentId content ID
  1023. * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
  1024. */
  1025. public function serviceCheckAllowedWithContent($sAction, $iContentId, $isPerformAction = false)
  1026. {
  1027. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  1028. return _t('_sys_request_page_not_found_cpt');
  1029. $sMethod = 'checkAllowed' . bx_gen_method_name($sAction);
  1030. if (!method_exists($this, $sMethod))
  1031. return _t('_sys_request_method_not_found_cpt');
  1032. return $this->$sMethod($aContentInfo, $isPerformAction);
  1033. }
  1034. public function serviceCheckAllowedCommentsView($iContentId, $sObjectComments)
  1035. {
  1036. return $this->serviceCheckAllowedWithContent('comments_view', $iContentId);
  1037. }
  1038. public function serviceCheckAllowedCommentsPost($iContentId, $sObjectComments)
  1039. {
  1040. return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
  1041. }
  1042. public function serviceGetContentOwnerProfileId ($iContentId)
  1043. {
  1044. $CNF = &$this->_oConfig->CNF;
  1045. // file owner must be author of the content or profile itself in case of profile based module
  1046. if ($iContentId) {
  1047. $sModule = $this->getName();
  1048. if ($this instanceof iBxDolProfileService && BxDolService::call($sModule, 'act_as_profile')) {
  1049. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1050. }
  1051. else {
  1052. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1053. $oProfile = $aContentInfo ? BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]) : null;
  1054. }
  1055. $iProfileId = $oProfile ? $oProfile->id() : bx_get_logged_profile_id();
  1056. }
  1057. else {
  1058. $iProfileId = bx_get_logged_profile_id();
  1059. }
  1060. return $iProfileId;
  1061. }
  1062. // ====== PERMISSION METHODS
  1063. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1064. {
  1065. if (!$iProfileId)
  1066. $iProfileId = $this->_iProfileId;
  1067. $CNF = &$this->_oConfig->CNF;
  1068. // moderator and owner always have access
  1069. if (!empty($iProfileId) && (abs($aDataEntry[$CNF['FIELD_AUTHOR']]) == (int)$iProfileId || $this->_isModerator($isPerformAction)))
  1070. return CHECK_ACTION_RESULT_ALLOWED;
  1071. // check ACL
  1072. $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
  1073. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1074. return $aCheck[CHECK_ACTION_MESSAGE];
  1075. // check privacy
  1076. if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
  1077. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1078. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1079. return _t('_sys_access_denied_to_private_content');
  1080. }
  1081. // check alert to allow custom checks
  1082. $mixedResult = null;
  1083. bx_alert('system', 'check_allowed_view', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1084. if($mixedResult !== null)
  1085. return $mixedResult;
  1086. return CHECK_ACTION_RESULT_ALLOWED;
  1087. }
  1088. public function checkAllowedSetThumb ($iContentId = 0)
  1089. {
  1090. return CHECK_ACTION_RESULT_ALLOWED;
  1091. }
  1092. /**
  1093. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1094. */
  1095. public function checkAllowedBrowse ()
  1096. {
  1097. // check alert to allow custom checks
  1098. $mixedResult = null;
  1099. bx_alert('system', 'check_allowed_browse', 0, 0, array('module' => $this->getName(), 'profile_id' => $this->_iProfileId, 'override_result' => &$mixedResult));
  1100. if($mixedResult !== null)
  1101. return $mixedResult;
  1102. return CHECK_ACTION_RESULT_ALLOWED;
  1103. }
  1104. /**
  1105. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1106. */
  1107. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1108. {
  1109. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1110. }
  1111. /**
  1112. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1113. */
  1114. public function checkAllowedAdd ($isPerformAction = false)
  1115. {
  1116. // check ACL
  1117. $aCheck = checkActionModule($this->_iProfileId, 'create entry', $this->getName(), $isPerformAction);
  1118. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1119. return $aCheck[CHECK_ACTION_MESSAGE];
  1120. return CHECK_ACTION_RESULT_ALLOWED;
  1121. }
  1122. /**
  1123. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1124. */
  1125. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1126. {
  1127. // moderator and owner always have access
  1128. if ($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || $this->_isModerator($isPerformAction))
  1129. return CHECK_ACTION_RESULT_ALLOWED;
  1130. return _t('_sys_txt_access_denied');
  1131. }
  1132. /**
  1133. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1134. */
  1135. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1136. {
  1137. // moderator always has access
  1138. if ($this->_isModerator($isPerformAction))
  1139. return CHECK_ACTION_RESULT_ALLOWED;
  1140. // check ACL
  1141. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1142. if (($aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId || -$aDataEntry[$this->_oConfig->CNF['FIELD_AUTHOR']] == $this->_iProfileId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1143. return CHECK_ACTION_RESULT_ALLOWED;
  1144. return _t('_sys_txt_access_denied');
  1145. }
  1146. /**
  1147. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1148. */
  1149. public function checkAllowedSetMembership (&$aDataEntry, $isPerformAction = false)
  1150. {
  1151. // admin always has access
  1152. if (isAdmin())
  1153. return CHECK_ACTION_RESULT_ALLOWED;
  1154. // check ACL
  1155. $aCheck = checkActionModule($this->_iProfileId, 'set acl level', 'system', $isPerformAction);
  1156. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1157. return $aCheck[CHECK_ACTION_MESSAGE];
  1158. return CHECK_ACTION_RESULT_ALLOWED;
  1159. }
  1160. /**
  1161. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1162. */
  1163. public function checkAllowedEditAnyEntry ($isPerformAction = false)
  1164. {
  1165. $aCheck = checkActionModule($this->_iProfileId, 'edit any entry', $this->getName(), $isPerformAction);
  1166. if($aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1167. return CHECK_ACTION_RESULT_ALLOWED;
  1168. return _t('_sys_txt_access_denied');
  1169. }
  1170. /**
  1171. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1172. */
  1173. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1174. {
  1175. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1176. }
  1177. /**
  1178. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make "true === " checking.
  1179. */
  1180. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1181. {
  1182. return $this->checkAllowedView ($aContentInfo, $isPerformAction);
  1183. }
  1184. public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
  1185. {
  1186. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
  1187. return MsgBox($sMsg);
  1188. bx_import($sClassSearchResult, $this->_aModule);
  1189. $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
  1190. $o = new $sClass($sMode, $aParams);
  1191. $o->setDesignBoxTemplateId($iDesignBox);
  1192. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1193. $o->setAjaxPaginate($bAjaxPaginate);
  1194. $o->setUnitParams(array('context' => $sMode));
  1195. if ($o->isError)
  1196. return '';
  1197. if ($s = $o->processing())
  1198. return $s;
  1199. else
  1200. return '';
  1201. }
  1202. // ====== COMMON METHODS
  1203. public function onPublished($iContentId) {}
  1204. public function onFailed($iContentId) {}
  1205. public function processMetasAdd($iContentId)
  1206. {
  1207. $CNF = &$this->_oConfig->CNF;
  1208. if(empty($CNF['OBJECT_METATAGS']))
  1209. return;
  1210. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1211. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1212. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1213. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1214. if(!$bContentInfo)
  1215. return;
  1216. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1217. $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD']);
  1218. if($oMetatags->locationsIsEnabled())
  1219. $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], $CNF['FIELD_LOCATION_PREFIX']);
  1220. if(!empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled())
  1221. foreach ($aLabels as $sLabel)
  1222. $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
  1223. }
  1224. public function processMetasEdit($iContentId, $oForm)
  1225. {
  1226. $CNF = &$this->_oConfig->CNF;
  1227. if(empty($CNF['OBJECT_METATAGS']))
  1228. return;
  1229. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1230. $bFldStatus = isset($CNF['FIELD_STATUS']);
  1231. $bFldStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']);
  1232. $bContentInfo = $aContentInfo && (!$bFldStatus || ($bFldStatus && $aContentInfo[$CNF['FIELD_STATUS']] == 'active')) && (!$bFldStatusAdmin || ($bFldStatusAdmin && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == 'active'));
  1233. if(!$bContentInfo)
  1234. return;
  1235. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1236. $oMetatags->metaAddAuto($aContentInfo[$CNF['FIELD_ID']], $aContentInfo, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT']);
  1237. if(isset($CNF['FIELD_LOCATION_PREFIX']) && isset($oForm->aInputs[$CNF['FIELD_LOCATION_PREFIX']]) && $oMetatags->locationsIsEnabled())
  1238. $oMetatags->locationsAddFromForm($aContentInfo[$CNF['FIELD_ID']], empty($CNF['FIELD_LOCATION_PREFIX']) ? '' : $CNF['FIELD_LOCATION_PREFIX']);
  1239. if(!empty($CNF['FIELD_LABELS']) && ($aLabels = bx_get($CNF['FIELD_LABELS'])) && $oMetatags->keywordsIsEnabled())
  1240. foreach ($aLabels as $sLabel)
  1241. $oMetatags->keywordsAddOne($aContentInfo[$CNF['FIELD_ID']], $sLabel, false);
  1242. }
  1243. public function getEntryImageData($aContentInfo, $sField = 'FIELD_THUMB', $aTranscoders = array())
  1244. {
  1245. if(empty($aTranscoders))
  1246. $aTranscoders = array('OBJECT_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY');
  1247. $CNF = &$this->_oConfig->CNF;
  1248. if(empty($CNF[$sField]) || empty($aContentInfo[$CNF[$sField]]) || empty($CNF['OBJECT_STORAGE']))
  1249. return false;
  1250. $iId = (int)$aContentInfo[$CNF[$sField]];
  1251. foreach($aTranscoders as $sTranscoder)
  1252. if(!empty($CNF[$sTranscoder]))
  1253. return array('id' => $iId, 'transcoder' => $CNF[$sTranscoder]);
  1254. return array('id' => $iId, 'object' => $CNF['OBJECT_STORAGE']);
  1255. }
  1256. public function getProfileId()
  1257. {
  1258. return bx_get_logged_profile_id();
  1259. }
  1260. public function getProfileInfo($iUserId = 0)
  1261. {
  1262. $oProfile = $this->getObjectUser($iUserId);
  1263. $oAccount = null;
  1264. if($oProfile && !($oProfile instanceof BxDolProfileUndefined) && !($oProfile instanceof BxDolProfileAnonymous))
  1265. $oAccount = $oProfile->getAccountObject();
  1266. $bAccount = !empty($oAccount);
  1267. return array(
  1268. 'id' => $oProfile->id(),
  1269. 'name' => $oProfile->getDisplayName(),
  1270. 'email' => $bAccount ? $oAccount->getEmail() : '',
  1271. 'link' => $oProfile->getUrl(),
  1272. 'icon' => $oProfile->getIcon(),
  1273. 'thumb' => $oProfile->getThumb(),
  1274. 'avatar' => $oProfile->getAvatar(),
  1275. 'unit' => $oProfile->getUnit(),
  1276. 'active' => $oProfile->isActive(),
  1277. );
  1278. }
  1279. public function getObjectUser($iUserId = 0)
  1280. {
  1281. bx_import('BxDolProfile');
  1282. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1283. return $oProfile;
  1284. }
  1285. public function getObjectFavorite($sSystem = '', $iId = 0)
  1286. {
  1287. $CNF = &$this->_oConfig->CNF;
  1288. if(empty($sSystem) && !empty($CNF['OBJECT_FAVORITES']))
  1289. $sSystem = $CNF['OBJECT_FAVORITES'];
  1290. if(empty($sSystem))
  1291. return false;
  1292. $oFavorite = BxDolFavorite::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1293. if(!$oFavorite || !$oFavorite->isEnabled())
  1294. return false;
  1295. return $oFavorite;
  1296. }
  1297. public function getUserId()
  1298. {
  1299. return isLogged() ? bx_get_logged_profile_id() : 0;
  1300. }
  1301. public function getUserIp()
  1302. {
  1303. return getVisitorIP();
  1304. }
  1305. public function getUserInfo($iUserId = 0)
  1306. {
  1307. $oProfile = BxDolProfile::getInstanceMagic($iUserId);
  1308. return array(
  1309. $oProfile->getDisplayName(),
  1310. $oProfile->getUrl(),
  1311. $oProfile->getThumb(),
  1312. $oProfile->getUnit(),
  1313. $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  1314. );
  1315. }
  1316. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1317. {
  1318. $CNF = &$this->_oConfig->CNF;
  1319. // default visible settings
  1320. if(!BxDolAcl::getInstance()->isMemberLevelInSet($aItem['visible_for_levels']))
  1321. return false;
  1322. if (!empty($aItem['visibility_custom'])) {
  1323. $oMenu = BxDolMenu::getObjectInstance($sObject);
  1324. if ($oMenu && !BxDolService::callSerialized($aItem['visibility_custom'], $oMenu->getMarkers()))
  1325. return false;
  1326. }
  1327. // get custom function name to check menu item visibility
  1328. $sFuncCheckAccess = false;
  1329. if(isset($CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']]))
  1330. $sFuncCheckAccess = $CNF['MENU_ITEM_TO_METHOD'][$sObject][$aItem['name']];
  1331. // check custom visibility settings defined in module config class
  1332. if(!isset($aContentInfo))
  1333. $aContentInfo = array();
  1334. if($sFuncCheckAccess && CHECK_ACTION_RESULT_ALLOWED !== call_user_func_array(array($this, $sFuncCheckAccess), array(&$aContentInfo)))
  1335. return false;
  1336. return true;
  1337. }
  1338. public function _isModerator ($isPerformAction = false)
  1339. {
  1340. return CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry ($isPerformAction);
  1341. }
  1342. // ====== PROTECTED METHODS
  1343. protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false, $bErrorMsg = true)
  1344. {
  1345. $iContentId = $this->_getContent($iContentId, false);
  1346. if($iContentId === false)
  1347. return false;
  1348. bx_import('FormsEntryHelper', $this->_aModule);
  1349. $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
  1350. $oFormsHelper = new $sClass($this);
  1351. return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction, $bErrorMsg);
  1352. }
  1353. protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')
  1354. {
  1355. $mixedContent = $this->_getContent($iContentId, $sFuncGetContent);
  1356. if($mixedContent === false)
  1357. return false;
  1358. list($iContentId, $aContentInfo) = $mixedContent;
  1359. return $this->_oTemplate->$sFunc($aContentInfo);
  1360. }
  1361. protected function _rss ($aArgs, $sClass = 'SearchResult')
  1362. {
  1363. $sMode = array_shift($aArgs);
  1364. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse())) {
  1365. $this->_oTemplate->displayAccessDenied ($sMsg);
  1366. exit;
  1367. }
  1368. $aParams = $this->_buildRssParams($sMode, $aArgs);
  1369. bx_import ($sClass, $this->_aModule);
  1370. $sClass = $this->_aModule['class_prefix'] . $sClass;
  1371. $o = new $sClass($sMode, $aParams);
  1372. if ($o->isError)
  1373. $this->_oTemplate->displayPageNotFound ();
  1374. else
  1375. $o->outputRSS();
  1376. exit;
  1377. }
  1378. protected function _getContent($iContentId = 0, $sFuncGetContent = true)
  1379. {
  1380. if(!$iContentId)
  1381. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1382. if(!$iContentId)
  1383. return false;
  1384. if($sFuncGetContent === true)
  1385. $sFuncGetContent = 'getContentInfoById';
  1386. if(empty($sFuncGetContent) || !method_exists($this->_oDb, $sFuncGetContent))
  1387. return $iContentId;
  1388. $aContentInfo = $this->_oDb->$sFuncGetContent($iContentId);
  1389. if(!$aContentInfo)
  1390. return false;
  1391. return array($iContentId, $aContentInfo);
  1392. }
  1393. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  1394. {
  1395. $CNF = &$this->_oConfig->CNF;
  1396. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1397. //--- Image(s)
  1398. $aImages = $this->_getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1399. $aImagesAttach = $this->_getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1400. //--- Video(s)
  1401. $aVideos = $this->_getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1402. $aVideosAttach = $this->_getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1403. //--- Files(s)
  1404. $aFiles = $this->_getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1405. $aFilesAttach = $this->_getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams);
  1406. //--- Title
  1407. $sTitle = '';
  1408. if(isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']]))
  1409. $sTitle = $aContentInfo[$CNF['FIELD_TITLE']];
  1410. else if(isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]))
  1411. $sTitle = strmaxtextlen($aContentInfo[$CNF['FIELD_TEXT']], 20, '...');
  1412. //--- Text
  1413. $sText = isset($CNF['FIELD_TEXT']) && isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1414. if(!empty($CNF['OBJECT_METATAGS']) && is_string($sText)) {
  1415. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  1416. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  1417. }
  1418. return array(
  1419. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  1420. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  1421. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  1422. 'url' => $sUrl,
  1423. 'title' => $sTitle,
  1424. 'text' => $sText,
  1425. 'images' => $aImages,
  1426. 'images_attach' => $aImagesAttach,
  1427. 'videos' => $aVideos,
  1428. 'videos_attach' => $aVideosAttach,
  1429. 'files' => $aFiles,
  1430. 'files_attach' => $aFilesAttach
  1431. );
  1432. }
  1433. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1434. {
  1435. $CNF = &$this->_oConfig->CNF;
  1436. $sImage = $sImageOrig = '';
  1437. if(isset($CNF['FIELD_COVER']) && isset($aContentInfo[$CNF['FIELD_COVER']]) && $aContentInfo[$CNF['FIELD_COVER']]) {
  1438. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1439. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_COVER']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1440. }
  1441. $bImageThumb = isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) && $aContentInfo[$CNF['FIELD_THUMB']];
  1442. if($sImage == '' && $bImageThumb)
  1443. $sImage = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_THUMB'));
  1444. if($sImageOrig == '' && $bImageThumb)
  1445. $sImageOrig = $this->_oConfig->getImageUrl($aContentInfo[$CNF['FIELD_THUMB']], array('OBJECT_IMAGES_TRANSCODER_COVER'));
  1446. if(empty($sImage))
  1447. return array();
  1448. if($sImageOrig == '')
  1449. $sImageOrig = $sImage;
  1450. return array(
  1451. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  1452. );
  1453. }
  1454. protected function _getImagesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1455. {
  1456. return array();
  1457. }
  1458. protected function _getVideosForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1459. {
  1460. return array();
  1461. }
  1462. protected function _getVideosForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1463. {
  1464. return array();
  1465. }
  1466. protected function _getFilesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1467. {
  1468. return array();
  1469. }
  1470. protected function _getFilesForTimelinePostAttach($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  1471. {
  1472. return array();
  1473. }
  1474. protected function _entityComments ($sObject, $iId = 0)
  1475. {
  1476. if (!$iId)
  1477. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1478. if (!$iId)
  1479. return false;
  1480. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1481. if (!$oCmts || !$oCmts->isEnabled())
  1482. return false;
  1483. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  1484. }
  1485. protected function _getFields($iContentId)
  1486. {
  1487. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1488. if(empty($aContentInfo))
  1489. return array();
  1490. return BxDolContentInfo::formatFields($aContentInfo);
  1491. }
  1492. protected function _getFieldValue($sField, $iContentId)
  1493. {
  1494. $CNF = &$this->_oConfig->CNF;
  1495. if(empty($CNF[$sField]))
  1496. return false;
  1497. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1498. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1499. return false;
  1500. return $aContentInfo[$CNF[$sField]];
  1501. }
  1502. protected function _getFieldValueThumb($sField, $iContentId, $sTranscoder = '')
  1503. {
  1504. $CNF = &$this->_oConfig->CNF;
  1505. if(empty($sTranscoder) || empty($CNF[$sField]))
  1506. return false;
  1507. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1508. if(empty($aContentInfo) || empty($aContentInfo[$CNF[$sField]]))
  1509. return false;
  1510. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  1511. if(!$oImagesTranscoder)
  1512. return false;
  1513. return $oImagesTranscoder->getFileUrl($aContentInfo[$CNF[$sField]]);
  1514. }
  1515. protected function _prepareResponse($aResponse, $bAsJson = false, $aAdditional = array())
  1516. {
  1517. if(!$bAsJson)
  1518. return $aResponse;
  1519. if(!empty($aAdditional) && is_array($aAdditional))
  1520. $aResponse = array_merge($aResponse, $aAdditional);
  1521. echoJson($aResponse);
  1522. exit;
  1523. }
  1524. }
  1525. /** @} */