BxBaseModGeneralModule.php 111 KB

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