BxBaseModGeneralModule.php 136 KB

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