1
0

BxBaseModGeneralModule.php 134 KB

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