BxBaseModGeneralModule.php 74 KB

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