1
0

BxBaseModGeneralModule.php 93 KB

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