BxBaseModGeneralModule.php 82 KB

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