BxBaseModGeneralModule.php 96 KB

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