1
0

BxBaseModGeneralModule.php 83 KB

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