BxBaseModGeneralModule.php 144 KB

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