BxBaseModGeneralModule.php 121 KB

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