1
0

BxBaseModGeneralModule.php 146 KB

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