BxTimelineModule.php 152 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolAcl');
  12. bx_import('BxBaseModNotificationsModule');
  13. define('BX_TIMELINE_TYPE_ITEM', 'view_item');
  14. define('BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS', 'owner_and_connections');
  15. define('BX_TIMELINE_TYPE_NEWS', 'news'); //--- Followed channels only.
  16. define('BX_TIMELINE_TYPE_FEED', 'feed'); //--- Owner and folloved contexts excluding channels.
  17. define('BX_TIMELINE_TYPE_HOT', 'hot'); //--- Aggrigated hot content.
  18. define('BX_TIMELINE_TYPE_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  19. define('BX_TIMELINE_VIEW_ITEM', 'item');
  20. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  21. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  22. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  23. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  24. define('BX_TIMELINE_FILTER_ALL', 'all');
  25. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  26. define('BX_TIMELINE_FILTER_OTHER', 'other');
  27. define('BX_TIMELINE_FILTER_OTHER_VIEWER', 'other_viewer');
  28. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  29. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  30. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  31. define('BX_TIMELINE_STATUS_ACTIVE', 'active');
  32. define('BX_TIMELINE_STATUS_AWAITING', 'awaiting');
  33. define('BX_TIMELINE_STATUS_FAILED', 'failed');
  34. define('BX_TIMELINE_STATUS_HIDDEN', 'hidden');
  35. define('BX_TIMELINE_STATUS_DELETED', 'deleted');
  36. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  37. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  38. //--- Video Auto Play
  39. define('BX_TIMELINE_VAP_OFF', 'off');
  40. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  41. define('BX_TIMELINE_VAP_ON', 'on');
  42. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  43. {
  44. protected $_sJsPostObject;
  45. protected $_sJsViewObject;
  46. protected $_aPostElements;
  47. protected $_sJsOutlineObject;
  48. protected $_sDividerTemplate;
  49. protected $_sBalloonTemplate;
  50. protected $_sCmtPostTemplate;
  51. protected $_sCmtViewTemplate;
  52. protected $_sCmtTemplate;
  53. /**
  54. * Constructor
  55. */
  56. function __construct($aModule)
  57. {
  58. parent::__construct($aModule);
  59. }
  60. /**
  61. * ACTION METHODS
  62. */
  63. public function actionVideo($iEventId, $iVideoId)
  64. {
  65. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  66. if(empty($aEvent) || !is_array($aEvent))
  67. return;
  68. $aData = $this->_oTemplate->getDataCached($aEvent);
  69. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  70. return;
  71. $oTemplate = BxDolTemplate::getInstance();
  72. $oTemplate->addJs(array(
  73. 'embedly-player.min.js'
  74. ));
  75. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  76. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  77. $oTemplate->getPageCode();
  78. }
  79. public function actionPost()
  80. {
  81. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  82. $mixedAllowed = $this->isAllowedPost(true);
  83. if($mixedAllowed !== true)
  84. return echoJson(array('message' => strip_tags($mixedAllowed)));
  85. echoJson($this->getFormPost());
  86. }
  87. public function actionEdit($iId)
  88. {
  89. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  90. $aBrowseParams = array();
  91. if(bx_get('bp') !== false)
  92. $aBrowseParams = $this->_oConfig->getBrowseParams(bx_process_input(bx_get('bp')));
  93. $mixedAllowed = $this->isAllowedPost(true);
  94. if($mixedAllowed !== true)
  95. return echoJson(array('message' => strip_tags($mixedAllowed)));
  96. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aBrowseParams));
  97. }
  98. function actionPin()
  99. {
  100. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  101. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  102. if(empty($aEvent) || !is_array($aEvent))
  103. return echoJson(array('code' => 1));
  104. $aParams = $this->_prepareParamsGet();
  105. $this->_iOwnerId = $aParams['owner_id'];
  106. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  107. if($mixedAllowed !== true)
  108. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  109. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  110. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  111. return echoJson(array('code' => 3));
  112. echoJson(array(
  113. 'code' => 0,
  114. 'id' => $iId,
  115. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onPinPost(oData)'
  116. ));
  117. }
  118. function actionStick()
  119. {
  120. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  121. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  122. if(empty($aEvent) || !is_array($aEvent))
  123. return echoJson(array('code' => 1));
  124. $aParams = $this->_prepareParamsGet();
  125. $this->_iOwnerId = $aParams['owner_id'];
  126. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['sticked'] == 0 ? 'Stick' : 'Unstick')}($aEvent, true);
  127. if($mixedAllowed !== true)
  128. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  129. $aEvent['sticked'] = (int)$aEvent['sticked'] == 0 ? time() : 0;
  130. if(!$this->_oDb->updateEvent(array('sticked' => $aEvent['sticked']), array('id' => $iId)))
  131. return echoJson(array('code' => 3));
  132. echoJson(array(
  133. 'code' => 0,
  134. 'id' => $iId,
  135. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onStickPost(oData)'
  136. ));
  137. }
  138. function actionPromote()
  139. {
  140. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  141. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  142. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  143. $sAction = (int)$aEvent['promoted'] == 0 ? 'promote' : 'unpromote';
  144. $mixedAllowed = $this->{'isAllowed' . ucfirst($sAction)}($aEvent, true);
  145. if($mixedAllowed !== true)
  146. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  147. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  148. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  149. return echoJson(array('code' => 2));
  150. bx_alert($this->_oConfig->getObject('alert'), $sAction . 'd', $iId, (int)$this->getUserId(), array(
  151. 'owner_id' => $aEvent['owner_id'],
  152. 'object_id' => $aEvent['object_id'],
  153. 'object_author_id' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id']
  154. ));
  155. echoJson(array(
  156. 'code' => 0,
  157. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  158. ));
  159. }
  160. function actionDelete()
  161. {
  162. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  163. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  164. if(empty($aEvent) || !is_array($aEvent))
  165. return echoJson(array('code' => 1));
  166. $aParams = $this->_prepareParamsGet();
  167. $this->_iOwnerId = $aParams['owner_id'];
  168. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  169. if($mixedAllowed !== true)
  170. return echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  171. if(!$this->deleteEvent($aEvent))
  172. return echoJson(array('code' => 3));
  173. $this->_oDb->deleteCache(array('event_id' => $iId));
  174. echoJson(array(
  175. 'code' => 0,
  176. 'id' => $aEvent['id'],
  177. 'eval' => $this->_oConfig->getJsObjectView($aParams) . '.onDeletePost(oData)'
  178. ));
  179. }
  180. public function actionRepost()
  181. {
  182. $iAuthorId = $this->getUserId();
  183. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  184. $sType = bx_process_input(bx_get('type'), BX_DATA_TEXT);
  185. $sAction = bx_process_input(bx_get('action'), BX_DATA_TEXT);
  186. $iObjectId = bx_process_input(bx_get('object_id'), BX_DATA_INT);
  187. $aResult = $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId);
  188. if(!empty($aResult) && is_array($aResult))
  189. return echoJson($aResult);
  190. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  191. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  192. echoJson(array(
  193. 'code' => 0,
  194. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  195. 'count' => $aReposted['reposts'],
  196. 'countf' => (int)$aReposted['reposts'] > 0 ? $this->_oTemplate->getRepostCounterLabel($aReposted['reposts']) : '',
  197. 'counter' => $sCounter,
  198. 'disabled' => true
  199. ));
  200. }
  201. function actionGetView()
  202. {
  203. $aParams = $this->_prepareParamsGet();
  204. $sConten = $this->_oTemplate->getViewBlock($aParams);
  205. if(empty($sConten))
  206. return echoJson(array());
  207. echoJson(array(
  208. 'code' => 0,
  209. 'content' => $sConten,
  210. ));
  211. }
  212. function actionGetPost()
  213. {
  214. $aParams = $this->_prepareParamsGet();
  215. $aParams['dynamic_mode'] = true;
  216. $this->_iOwnerId = $aParams['owner_id'];
  217. $sJsObject = '';
  218. if(bx_get('js_object') !== false)
  219. $sJsObject = bx_process_input(bx_get('js_object'));
  220. if(empty($sJsObject))
  221. $sJsObject = $this->_oConfig->getJsObject('post');
  222. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  223. if(empty($aEvent) || !is_array($aEvent))
  224. return echoJson(array());
  225. /**
  226. * Note. Disabled for now, because Own posts on Timelines of Following members
  227. * became visible on posts' author Dashboard Timeline.
  228. */
  229. /*
  230. $bAfpsLoading = (int)bx_get('afps_loading') === 1;
  231. if($bAfpsLoading && $this->_iOwnerId != $aEvent['owner_id'])
  232. return echoJson(array('message' => _t('_bx_timeline_txt_msg_posted')));
  233. */
  234. echoJson(array(
  235. 'id' => $aEvent['id'],
  236. 'name' => $aParams['name'],
  237. 'view' => $aParams['view'],
  238. 'type' => $aParams['type'],
  239. 'item' => $this->_oTemplate->getPost($aEvent, $aParams),
  240. 'eval' => $sJsObject . "._onGetPost(oData)"
  241. ));
  242. }
  243. function actionGetPosts()
  244. {
  245. $aParams = $this->_prepareParamsGet();
  246. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  247. echoJson(array(
  248. 'view' => $aParams['view'],
  249. 'items' => $sItems,
  250. 'load_more' => $sLoadMore,
  251. 'back' => $sBack,
  252. 'empty' => $sEmpty,
  253. 'eval' => $this->_oConfig->getJsObjectView($aParams) . "._onGetPosts(oData)"
  254. ));
  255. }
  256. public function actionGetPostForm()
  257. {
  258. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  259. $sType = bx_process_input(bx_get('type'));
  260. echoJson($this->getFormPost(array(
  261. 'type' => $sType,
  262. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  263. )));
  264. }
  265. public function actionGetEditForm($iId)
  266. {
  267. $aParams = $this->_prepareParamsGet();
  268. $this->_iOwnerId = $aParams['owner_id'];
  269. echoJson($this->getFormEdit($iId, array('dynamic_mode' => true), $aParams));
  270. }
  271. public function actionGetComments()
  272. {
  273. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  274. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  275. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  276. $sComments = $this->_oTemplate->getComments($sSystem, $iId, array('dynamic_mode' => true));
  277. echoJson(array('content' => $sComments));
  278. }
  279. public function actionAddAttachLink()
  280. {
  281. $sUrl = bx_process_input(bx_get('url'));
  282. if(empty($sUrl))
  283. return echoJson(array());
  284. echoJson($this->addAttachLink(array(
  285. 'url' => $sUrl
  286. )));
  287. }
  288. public function actionDeleteAttachLink()
  289. {
  290. $iUserId = $this->getUserId();
  291. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  292. if(empty($iLinkId)) {
  293. echoJson(array());
  294. return;
  295. }
  296. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  297. if(empty($aLink) || !is_array($aLink)) {
  298. echoJson(array());
  299. return;
  300. }
  301. if(!empty($aLink['media_id']))
  302. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  303. $aResult = array();
  304. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  305. $aResult = array('code' => 0);
  306. else
  307. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  308. echoJson($aResult);
  309. }
  310. public function actionGetAttachLinkForm()
  311. {
  312. echo $this->_oTemplate->getAttachLinkForm();
  313. }
  314. public function actionSubmitAttachLinkForm()
  315. {
  316. echoJson($this->getFormAttachLink());
  317. }
  318. public function actionGetRepostedBy()
  319. {
  320. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  321. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  322. }
  323. public function actionGetItemBrief()
  324. {
  325. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCodeDynamic();
  326. }
  327. public function actionGetJumpTo()
  328. {
  329. $aParams = $this->_prepareParamsGet();
  330. $this->_iOwnerId = $aParams['owner_id'];
  331. $sJsObjectView = $this->_oConfig->getJsObjectView($aParams);
  332. echoJson(array(
  333. 'content' => $this->_oTemplate->getJumpTo($aParams),
  334. 'eval' => $sJsObjectView . '.onGetJumpTo(oData)'
  335. ));
  336. }
  337. public function actionResumeLiveUpdate()
  338. {
  339. $aParams = $this->_prepareParamsGet();
  340. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  341. bx_import('BxDolSession');
  342. BxDolSession::getInstance()->unsetValue($sKey);
  343. }
  344. public function actionPauseLiveUpdate()
  345. {
  346. $aParams = $this->_prepareParamsGet();
  347. $sKey = $this->_oConfig->getLiveUpdateKey($aParams);
  348. bx_import('BxDolSession');
  349. BxDolSession::getInstance()->setValue($sKey, 1);
  350. }
  351. function actionRss()
  352. {
  353. $CNF = &$this->_oConfig->CNF;
  354. $aArgs = func_get_args();
  355. $sType = array_shift($aArgs);
  356. $iOwnerId = 0;
  357. switch($sType) {
  358. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  359. $iOwnerId = array_shift($aArgs);
  360. list($sUserName) = $this->getUserInfo($iOwnerId);
  361. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  362. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  363. break;
  364. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  365. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  366. $sRssLink = $this->_oConfig->getHomeViewUrl();
  367. break;
  368. }
  369. $aParams = $this->_prepareParams(array(
  370. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  371. 'type' => $sType,
  372. 'owner_id' => $iOwnerId,
  373. 'start' => 0,
  374. 'per_page' => $this->_oConfig->getRssLength(),
  375. 'timeline' => 0,
  376. 'filter' => '',
  377. 'modules' => array()
  378. ));
  379. $aEvents = $this->_oDb->getEvents($aParams);
  380. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  381. $aRssData = array();
  382. foreach($aEvents as $aEvent) {
  383. if(empty($aEvent['title']))
  384. continue;
  385. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  386. $sEventFieldAuthor = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id';
  387. if($oPrivacy) {
  388. $oPrivacy->setTableFieldAuthor($sEventFieldAuthor);
  389. if(!$oPrivacy->check($iEventId))
  390. continue;
  391. }
  392. $iOwner = $aEvent[$sEventFieldAuthor];
  393. $oOwner = BxDolProfile::getInstanceMagic($iOwner);
  394. $aRssData[$iEventId] = array(
  395. 'UnitID' => $iEventId,
  396. 'UnitTitle' => $aEvent['title'],
  397. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  398. 'UnitDesc' => bx_replace_markers($aEvent['description'], array(
  399. 'profile_name' => $oOwner->getDisplayName()
  400. )),
  401. 'UnitDateTimeUTS' => $aEvent['date'],
  402. );
  403. }
  404. $oRss = new BxDolRssFactory();
  405. header('Content-Type: application/xml; charset=utf-8');
  406. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  407. }
  408. /**
  409. * SERVICE METHODS
  410. */
  411. /**
  412. * @page service Service Calls
  413. * @section bx_timeline Timeline
  414. * @subsection bx_timeline-other Other
  415. * @subsubsection bx_timeline-get_content_owner_profile_id get_content_owner_profile_id
  416. *
  417. * @code bx_srv('bx_timeline', 'get_content_owner_profile_id', [...]); @endcode
  418. *
  419. * Get event's owner profile id.
  420. *
  421. * @param $mixedEvent integer value with event ID or an array with event info.
  422. * @return event's owner profile id.
  423. *
  424. * @see BxTimelineModule::serviceGetContentOwnerProfileId
  425. */
  426. /**
  427. * @ref bx_timeline-get_content_owner_profile_id "get_content_owner_profile_id"
  428. */
  429. public function serviceGetContentOwnerProfileId($mixedEvent)
  430. {
  431. $CNF = &$this->_oConfig->CNF;
  432. $iProfile = (int)bx_get_logged_profile_id();
  433. if(empty($mixedEvent))
  434. return $iProfile;
  435. if(!is_array($mixedEvent))
  436. $mixedEvent = $this->_oDb->getContentInfoById((int)$mixedEvent);
  437. if(empty($mixedEvent) || !is_array($mixedEvent) || !isset($mixedEvent[$CNF['FIELD_SYSTEM']]))
  438. return $iProfile;
  439. if((int)$mixedEvent[$CNF['FIELD_SYSTEM']] == 0)
  440. return (int)$mixedEvent[$CNF['FIELD_OBJECT_ID']];
  441. if(!empty($mixedEvent['object_owner_id']))
  442. return (int)$mixedEvent['object_owner_id'];
  443. if(!empty($mixedEvent['content'])) {
  444. $aContent = unserialize($mixedEvent['content']);
  445. if(!empty($aContent) && is_array($aContent) && !empty($aContent['object_author_id']))
  446. return (int)$aContent['object_author_id'];
  447. }
  448. $aEventData = $this->_oTemplate->getData($mixedEvent);
  449. if(!empty($aEventData) && is_array($aEventData) && !empty($aEventData['object_owner_id']))
  450. return (int)$aEventData['object_owner_id'];
  451. return $iProfile;
  452. }
  453. /**
  454. * @page service Service Calls
  455. * @section bx_timeline Timeline
  456. * @subsection bx_timeline-other Other
  457. * @subsubsection bx_timeline-get_create_post_form get_create_post_form
  458. *
  459. * @code bx_srv('bx_timeline', 'get_create_post_form', [...]); @endcode
  460. *
  461. * Get form code for add content. Is needed for United Post Form.
  462. *
  463. * @param $aParams optional array with parameters(display name, etc)
  464. * @return form code or error
  465. *
  466. * @see BxTimelineModule::serviceGetCreatePostForm
  467. */
  468. /**
  469. * @ref bx_timeline-get_create_post_form "get_create_post_form"
  470. */
  471. public function serviceGetCreatePostForm($aParams = array())
  472. {
  473. $aParams = array_merge($this->_aFormParams, $aParams);
  474. $bContext = $aParams['context_id'] !== false;
  475. $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
  476. $oForm = $this->serviceGetObjectForm('add', $aParams);
  477. if(!$oForm)
  478. return '';
  479. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  480. $aParams['form_display'] = 'form_display_post_add_public';
  481. if($bContext) {
  482. if($aParams['context_id'] < 0) {
  483. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  484. $aParams['form_display'] = 'form_display_post_add_profile';
  485. }
  486. else {
  487. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  488. $aParams['form_display'] = 'form_display_post_add';
  489. }
  490. }
  491. if(!empty($aParams['display']))
  492. $aParams['form_display'] = $aParams['display'];
  493. $aResult = $this->getFormPost($aParams);
  494. if(!empty($aResult['form'])) {
  495. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'];
  496. $sCode = '';
  497. $sCode .= $this->_oTemplate->getCssJs($bDynamicMode);
  498. $sCode .= $this->_oTemplate->getJsCodePost($this->_iOwnerId, $aParams);
  499. $sCode .= $aResult['form'];
  500. return $sCode;
  501. }
  502. if(!empty($aResult['message']))
  503. return $aResult['message'];
  504. return '';
  505. }
  506. /**
  507. * @page service Service Calls
  508. * @section bx_timeline Timeline
  509. * @subsection bx_timeline-other Other
  510. * @subsubsection bx_timeline-get_object_form get_object_form
  511. *
  512. * @code bx_srv('bx_timeline', 'get_object_form', [...]); @endcode
  513. *
  514. * Get form object for add, edit, view or delete the content.
  515. *
  516. * @param $sType 'add' is supported only
  517. * @param $aParams optional array with parameters(display name, etc)
  518. * @return form object or false on error
  519. *
  520. * @see BxTimelineModule::serviceGetObjectForm
  521. */
  522. /**
  523. * @ref bx_timeline-get_object_form "get_object_form"
  524. */
  525. public function serviceGetObjectForm ($sType, $aParams = array())
  526. {
  527. if(!in_array($sType, array('add')))
  528. return false;
  529. $bContext = $aParams['context_id'] !== false;
  530. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
  531. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  532. return false;
  533. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  534. $aParams['form_display'] = 'form_display_post_add_public';
  535. if($bContext) {
  536. if($aParams['context_id'] < 0) {
  537. $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
  538. $aParams['form_display'] = 'form_display_post_add_profile';
  539. }
  540. else {
  541. $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  542. $aParams['form_display'] = 'form_display_post_add';
  543. }
  544. }
  545. if(!empty($aParams['display']))
  546. $aParams['form_display'] = $aParams['display'];
  547. $oForm = $this->getFormPostObject($aParams);
  548. bx_alert('system', 'get_object_form', 0, 0, array(
  549. 'module' => $this->_oConfig->getName(),
  550. 'type' => $sType,
  551. 'params' => $aParams,
  552. 'form' => &$oForm
  553. ));
  554. return $oForm;
  555. }
  556. /**
  557. * @page service Service Calls
  558. * @section bx_timeline Timeline
  559. * @subsection get_timeline_post
  560. * @see BxTimelineModule::serviceGetTimelinePost
  561. *
  562. * Get Timeline post. It's needed for Timeline module.
  563. *
  564. * @param $aEvent timeline event array from Timeline module
  565. * @return array in special format which is needed specifically for Timeline module to display the data.
  566. */
  567. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  568. {
  569. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  570. if(empty($aContentInfo) || !is_array($aContentInfo))
  571. return false;
  572. $aEvent = array_merge($aEvent, array(
  573. 'owner_id' => $aContentInfo['owner_id'],
  574. 'object_privacy_view' => $aContentInfo['object_privacy_view']
  575. ));
  576. /*
  577. * Note. For 'Direct Timeline Posts' FIELD_OBJECT_ID contains post's author profile ID.
  578. */
  579. $this->_oConfig->CNF['FIELD_AUTHOR'] = $this->_oConfig->CNF['FIELD_OBJECT_ID'];
  580. return parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  581. }
  582. /**
  583. * @page service Service Calls
  584. * @section bx_timeline Timeline
  585. * @subsection get_timeline_post
  586. * @see BxTimelineModule::serviceGetTimelinePostAllowedView
  587. *
  588. * Check Timeline post's visibility. It's needed for Timeline module, when its events
  589. * are accessed and checked from outside. For example, when they are referenced
  590. * from Channels module.
  591. *
  592. * @param $aEvent timeline event array from Timeline module
  593. * @return mixed value: CHECK_ACTION_RESULT_ALLOWED or text of some error message.
  594. */
  595. public function serviceGetTimelinePostAllowedView($aEvent)
  596. {
  597. $CNF = &$this->_oConfig->CNF;
  598. $iOwnerId = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  599. if($iOwnerId == 0)
  600. return CHECK_ACTION_RESULT_ALLOWED;
  601. $oOwner = BxDolProfile::getInstance($iOwnerId);
  602. if(!$oOwner)
  603. return CHECK_ACTION_RESULT_ALLOWED;
  604. $sModule = $oOwner->getModule();
  605. $aOwnerInfo = BxDolService::call($sModule, 'get_info', array($oOwner->getContentId(), false));
  606. if(empty($aOwnerInfo) || !is_array($aOwnerInfo))
  607. return CHECK_ACTION_RESULT_ALLOWED;
  608. return BxDolService::call($sModule, 'check_allowed_view_for_profile', array($aOwnerInfo));
  609. }
  610. /**
  611. * @page service Service Calls
  612. * @section bx_timeline Timeline
  613. * @subsection bx_timeline-other Other
  614. * @subsubsection bx_timeline-get_author get_author
  615. *
  616. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  617. *
  618. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  619. *
  620. * @param $iContentId integer value with content ID.
  621. * @return integer value with author ID.
  622. *
  623. * @see BxTimelineModule::serviceGetAuthor
  624. */
  625. /**
  626. * @ref bx_timeline-get_author "get_author"
  627. */
  628. public function serviceGetAuthor ($iContentId)
  629. {
  630. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  631. if(empty($aEvent) || !is_array($aEvent))
  632. return 0;
  633. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  634. }
  635. /**
  636. * @page service Service Calls
  637. * @section bx_timeline Timeline
  638. * @subsection bx_timeline-other Other
  639. * @subsubsection bx_timeline-get_date_changed get_date_changed
  640. *
  641. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  642. *
  643. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  644. * Note. In case of Timeline event 0 is returned everytime.
  645. *
  646. * @param $iContentId integer value with content ID.
  647. * @return integer value with changing date.
  648. *
  649. * @see BxTimelineModule::serviceGetDateChanged
  650. */
  651. /**
  652. * @ref bx_timeline-get_date_changed "get_date_changed"
  653. */
  654. public function serviceGetDateChanged ($iContentId)
  655. {
  656. return 0;
  657. }
  658. /**
  659. * @page service Service Calls
  660. * @section bx_timeline Timeline
  661. * @subsection bx_timeline-other Other
  662. * @subsubsection bx_timeline-get_link get_link
  663. *
  664. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  665. *
  666. * Get content view page link. Is used in "Content Info Objects" system.
  667. *
  668. * @param $iContentId integer value with content ID.
  669. * @return string value with view page link.
  670. *
  671. * @see BxTimelineModule::serviceGetLink
  672. */
  673. /**
  674. * @ref bx_timeline-get_link "get_link"
  675. */
  676. public function serviceGetLink ($iContentId)
  677. {
  678. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  679. if(empty($aEvent) || !is_array($aEvent))
  680. return '';
  681. return $this->_oConfig->getItemViewUrl($aEvent);
  682. }
  683. /**
  684. * @page service Service Calls
  685. * @section bx_timeline Timeline
  686. * @subsection bx_timeline-other Other
  687. * @subsubsection bx_timeline-get_thumb get_thumb
  688. *
  689. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  690. *
  691. * Get content thumbnail link. Is used in "Content Info Objects" system.
  692. * Note. In case of Timeline event an empty string is returned everytime.
  693. *
  694. * @param $iContentId integer value with content ID.
  695. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  696. * @return string value with thumbnail link.
  697. *
  698. * @see BxTimelineModule::serviceGetThumb
  699. */
  700. /**
  701. * @ref bx_timeline-get_thumb "get_thumb"
  702. */
  703. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  704. {
  705. return '';
  706. }
  707. /**
  708. * @page service Service Calls
  709. * @section bx_timeline Timeline
  710. * @subsection bx_timeline-other Other
  711. * @subsubsection bx_timeline-get_info get_info
  712. *
  713. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  714. *
  715. * Get content info by content ID. Is used in "Content Info Objects" system.
  716. *
  717. * @param $iContentId integer value with content ID.
  718. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  719. * @return an array with content info. Empty array is returned if something is wrong.
  720. *
  721. * @see BxTimelineModule::serviceGetInfo
  722. */
  723. /**
  724. * @ref bx_timeline-get_info "get_info"
  725. */
  726. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  727. {
  728. $aContentInfo = $this->_oDb->getEvents(array(
  729. 'browse' => 'id',
  730. 'value' => $iContentId)
  731. );
  732. return BxDolContentInfo::formatFields($aContentInfo);
  733. }
  734. /**
  735. * @page service Service Calls
  736. * @section bx_timeline Timeline
  737. * @subsection bx_timeline-other Other
  738. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  739. *
  740. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  741. *
  742. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  743. *
  744. * @param $iContentId integer value with content ID.
  745. * @param $sUnitTemplate (optional) string value with template name.
  746. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  747. *
  748. * @see BxTimelineModule::serviceGetSearchResultUnit
  749. */
  750. /**
  751. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  752. */
  753. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  754. {
  755. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  756. if(empty($aEvent) || !is_array($aEvent))
  757. return '';
  758. if(empty($sUnitTemplate))
  759. $sUnitTemplate = 'unit.html';
  760. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  761. }
  762. /**
  763. * @page service Service Calls
  764. * @section bx_timeline Timeline
  765. * @subsection bx_timeline-page_blocks Page Blocks
  766. * @subsubsection bx_timeline-get_block_post get_block_post
  767. *
  768. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  769. *
  770. * Get Post block for a separate page.
  771. *
  772. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  773. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  774. *
  775. * @see BxTimelineModule::serviceGetBlockPost
  776. */
  777. /**
  778. * @ref bx_timeline-get_block_post "get_block_post"
  779. */
  780. public function serviceGetBlockPost($iProfileId = 0)
  781. {
  782. if(empty($iProfileId) && bx_get('profile_id') !== false)
  783. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  784. if(empty($iProfileId) && isLogged())
  785. $iProfileId = bx_get_logged_profile_id();
  786. if(!$iProfileId)
  787. return array();
  788. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  789. return $this->_getBlockPost($iProfileId, array(
  790. 'type' => $sType,
  791. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  792. ));
  793. }
  794. /**
  795. * @page service Service Calls
  796. * @section bx_timeline Timeline
  797. * @subsection bx_timeline-page_blocks Page Blocks
  798. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  799. *
  800. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  801. *
  802. * Get Post block for the Profile page.
  803. *
  804. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  805. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  806. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  807. *
  808. * @see BxTimelineModule::serviceGetBlockPostProfile
  809. */
  810. /**
  811. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  812. */
  813. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  814. {
  815. if(empty($sProfileModule))
  816. return array();
  817. if(empty($iProfileContentId) && bx_get('id') !== false)
  818. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  819. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  820. if(empty($oProfile))
  821. return array();
  822. $iProfileId = $oProfile->id();
  823. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  824. return $this->_getBlockPost($iProfileId, array(
  825. 'type' => $sType,
  826. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  827. ));
  828. }
  829. /**
  830. * @page service Service Calls
  831. * @section bx_timeline Timeline
  832. * @subsection bx_timeline-page_blocks Page Blocks
  833. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  834. *
  835. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  836. *
  837. * Get Post block for site's Home page.
  838. *
  839. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  840. *
  841. * @see BxTimelineModule::serviceGetBlockPostHome
  842. */
  843. /**
  844. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  845. */
  846. public function serviceGetBlockPostHome()
  847. {
  848. $iProfileId = 0;
  849. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  850. return $this->_getBlockPost($iProfileId, array(
  851. 'type' => $sType,
  852. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  853. ));
  854. }
  855. /**
  856. * @page service Service Calls
  857. * @section bx_timeline Timeline
  858. * @subsection bx_timeline-page_blocks Page Blocks
  859. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  860. *
  861. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  862. *
  863. * Get Post block for the Dashboard page.
  864. *
  865. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  866. *
  867. * @see BxTimelineModule::serviceGetBlockPostAccount
  868. */
  869. /**
  870. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  871. */
  872. public function serviceGetBlockPostAccount()
  873. {
  874. if(!isLogged())
  875. return '';
  876. $iProfileId = $this->getProfileId();
  877. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  878. return $this->_getBlockPost($iProfileId, array(
  879. 'type' => $sType,
  880. 'form_display' => $this->_oConfig->getPostFormDisplay($sType)
  881. ));
  882. }
  883. /**
  884. * @page service Service Calls
  885. * @section bx_timeline Timeline
  886. * @subsection bx_timeline-page_blocks Page Blocks
  887. * @subsubsection bx_timeline-get_block_view get_block_view
  888. *
  889. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  890. *
  891. * Get Timeline View block for a separate page.
  892. *
  893. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  894. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  895. *
  896. * @see BxTimelineModule::serviceGetBlockView
  897. */
  898. /**
  899. * @ref bx_timeline-get_block_view "get_block_view"
  900. */
  901. public function serviceGetBlockView($iProfileId = 0)
  902. {
  903. return $this->_serviceGetBlockView($iProfileId, array(
  904. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  905. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  906. 'start' => -1,
  907. 'per_page' => -1,
  908. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  909. 'timeline' => -1,
  910. 'filter' => '',
  911. 'modules' => array()
  912. ));
  913. }
  914. /**
  915. * @page service Service Calls
  916. * @section bx_timeline Timeline
  917. * @subsection bx_timeline-page_blocks Page Blocks
  918. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  919. *
  920. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  921. *
  922. * Get Outline View block for a separate page.
  923. *
  924. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  925. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  926. *
  927. * @see BxTimelineModule::serviceGetBlockViewOutline
  928. */
  929. /**
  930. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  931. */
  932. public function serviceGetBlockViewOutline($iProfileId = 0)
  933. {
  934. return $this->_serviceGetBlockView($iProfileId, array(
  935. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  936. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  937. 'start' => -1,
  938. 'per_page' => -1,
  939. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  940. 'timeline' => -1,
  941. 'filter' => '',
  942. 'modules' => array()
  943. ));
  944. }
  945. /**
  946. * @page service Service Calls
  947. * @section bx_timeline Timeline
  948. * @subsection bx_timeline-page_blocks Page Blocks
  949. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  950. *
  951. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  952. *
  953. * Get Timeline View block for the Profile page.
  954. *
  955. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  956. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  957. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  958. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  959. * @param $sFilter (optional) string value with filter name.
  960. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  961. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  962. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  963. *
  964. * @see BxTimelineModule::serviceGetBlockViewProfile
  965. */
  966. /**
  967. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  968. */
  969. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  970. {
  971. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  972. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  973. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  974. 'start' => $iStart,
  975. 'per_page' => $iPerPage,
  976. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  977. 'timeline' => $iTimeline,
  978. 'filter' => $sFilter,
  979. 'modules' => $aModules
  980. ));
  981. }
  982. /**
  983. * @page service Service Calls
  984. * @section bx_timeline Timeline
  985. * @subsection bx_timeline-page_blocks Page Blocks
  986. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  987. *
  988. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  989. *
  990. * Get Outline View block for the Profile page.
  991. *
  992. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  993. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  994. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  995. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  996. * @param $sFilter (optional) string value with filter name.
  997. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  998. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  999. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1000. *
  1001. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  1002. */
  1003. /**
  1004. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  1005. */
  1006. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1007. {
  1008. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, array(
  1009. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1010. 'type' => BX_BASE_MOD_NTFS_TYPE_OWNER,
  1011. 'start' => $iStart,
  1012. 'per_page' => $iPerPage,
  1013. 'per_page_default' => $this->_oConfig->getPerPage('profile'),
  1014. 'timeline' => $iTimeline,
  1015. 'filter' => $sFilter,
  1016. 'modules' => $aModules
  1017. ));
  1018. }
  1019. public function serviceGetBlockViewsTimeline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1020. {
  1021. return $this->_serviceGetBlockViews(array(
  1022. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1023. 'type' => $sType,
  1024. 'owner_id' => $iProfileId,
  1025. 'start' => $iStart,
  1026. 'per_page' => $iPerPage,
  1027. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1028. 'timeline' => $iTimeline,
  1029. 'filter' => $sFilter,
  1030. 'modules' => $aModules
  1031. ));
  1032. }
  1033. public function serviceGetBlockViewsOutline($sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1034. {
  1035. return $this->_serviceGetBlockViews(array(
  1036. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1037. 'type' => $sType,
  1038. 'owner_id' => $iProfileId,
  1039. 'start' => $iStart,
  1040. 'per_page' => $iPerPage,
  1041. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1042. 'timeline' => $iTimeline,
  1043. 'filter' => $sFilter,
  1044. 'modules' => $aModules
  1045. ));
  1046. }
  1047. /**
  1048. * @page service Service Calls
  1049. * @section bx_timeline Timeline
  1050. * @subsection bx_timeline-page_blocks Page Blocks
  1051. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  1052. *
  1053. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  1054. *
  1055. * Get Timeline View block for site's Home page.
  1056. *
  1057. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1058. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1059. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1060. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1061. * @param $sFilter (optional) string value with filter name.
  1062. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1063. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1064. *
  1065. * @see BxTimelineModule::serviceGetBlockViewHome
  1066. */
  1067. /**
  1068. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  1069. */
  1070. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1071. {
  1072. return $this->_serviceGetBlockViewHome(array(
  1073. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1074. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1075. 'owner_id' => $iProfileId,
  1076. 'start' => $iStart,
  1077. 'per_page' => $iPerPage,
  1078. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1079. 'timeline' => $iTimeline,
  1080. 'filter' => $sFilter,
  1081. 'modules' => $aModules
  1082. ));
  1083. }
  1084. /**
  1085. * @page service Service Calls
  1086. * @section bx_timeline Timeline
  1087. * @subsection bx_timeline-page_blocks Page Blocks
  1088. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  1089. *
  1090. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  1091. *
  1092. * Get Outline View block for site's Home page.
  1093. *
  1094. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1095. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1096. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1097. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1098. * @param $sFilter (optional) string value with filter name.
  1099. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1100. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1101. *
  1102. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  1103. */
  1104. /**
  1105. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  1106. */
  1107. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1108. {
  1109. return $this->_serviceGetBlockViewHome(array(
  1110. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1111. 'type' => BX_BASE_MOD_NTFS_TYPE_PUBLIC,
  1112. 'owner_id' => $iProfileId,
  1113. 'start' => $iStart,
  1114. 'per_page' => $iPerPage,
  1115. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1116. 'timeline' => $iTimeline,
  1117. 'filter' => $sFilter,
  1118. 'modules' => $aModules
  1119. ));
  1120. }
  1121. /**
  1122. * @page service Service Calls
  1123. * @section bx_timeline Timeline
  1124. * @subsection bx_timeline-page_blocks Page Blocks
  1125. * @subsubsection bx_timeline-get_block_view_hot get_block_view_hot
  1126. *
  1127. * @code bx_srv('bx_timeline', 'get_block_view_hot', [...]); @endcode
  1128. *
  1129. * Get Timeline View block with Hot public events.
  1130. *
  1131. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1132. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1133. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1134. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1135. * @param $sFilter (optional) string value with filter name.
  1136. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1137. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1138. *
  1139. * @see BxTimelineModule::serviceGetBlockViewHot
  1140. */
  1141. /**
  1142. * @ref bx_timeline-get_block_view_hot "get_block_view_hot"
  1143. */
  1144. public function serviceGetBlockViewHot($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1145. {
  1146. return $this->_serviceGetBlockViewHot(array(
  1147. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1148. 'type' => BX_TIMELINE_TYPE_HOT,
  1149. 'owner_id' => $iProfileId,
  1150. 'start' => $iStart,
  1151. 'per_page' => $iPerPage,
  1152. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1153. 'timeline' => $iTimeline,
  1154. 'filter' => $sFilter,
  1155. 'modules' => $aModules
  1156. ));
  1157. }
  1158. /**
  1159. * @page service Service Calls
  1160. * @section bx_timeline Timeline
  1161. * @subsection bx_timeline-page_blocks Page Blocks
  1162. * @subsubsection bx_timeline-get_block_view_hot_outline get_block_view_hot_outline
  1163. *
  1164. * @code bx_srv('bx_timeline', 'get_block_view_hot_outline', [...]); @endcode
  1165. *
  1166. * Get Outline View block with Hot public events.
  1167. *
  1168. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1169. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1170. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1171. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1172. * @param $sFilter (optional) string value with filter name.
  1173. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1174. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1175. *
  1176. * @see BxTimelineModule::serviceGetBlockViewHotOutline
  1177. */
  1178. /**
  1179. * @ref bx_timeline-get_block_view_hot_outline "get_block_view_hot_outline"
  1180. */
  1181. public function serviceGetBlockViewHotOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1182. {
  1183. return $this->_serviceGetBlockViewHot(array(
  1184. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1185. 'type' => BX_TIMELINE_TYPE_HOT,
  1186. 'owner_id' => $iProfileId,
  1187. 'start' => $iStart,
  1188. 'per_page' => $iPerPage,
  1189. 'per_page_default' => $this->_oConfig->getPerPage('home'),
  1190. 'timeline' => $iTimeline,
  1191. 'filter' => $sFilter,
  1192. 'modules' => $aModules
  1193. ));
  1194. }
  1195. /**
  1196. * @page service Service Calls
  1197. * @section bx_timeline Timeline
  1198. * @subsection bx_timeline-page_blocks Page Blocks
  1199. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  1200. *
  1201. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  1202. *
  1203. * Get Timeline View block for the Dashboard page.
  1204. *
  1205. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1206. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1207. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1208. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1209. * @param $sFilter (optional) string value with filter name.
  1210. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1211. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1212. *
  1213. * @see BxTimelineModule::serviceGetBlockViewAccount
  1214. */
  1215. /**
  1216. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  1217. */
  1218. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1219. {
  1220. if(!isLogged())
  1221. return '';
  1222. return $this->_serviceGetBlockViewByType(array(
  1223. 'view' => BX_TIMELINE_VIEW_TIMELINE,
  1224. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1225. 'owner_id' => $iProfileId,
  1226. 'start' => $iStart,
  1227. 'per_page' => $iPerPage,
  1228. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1229. 'timeline' => $iTimeline,
  1230. 'filter' => $sFilter,
  1231. 'modules' => $aModules
  1232. ));
  1233. }
  1234. /**
  1235. * @page service Service Calls
  1236. * @section bx_timeline Timeline
  1237. * @subsection bx_timeline-page_blocks Page Blocks
  1238. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  1239. *
  1240. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  1241. *
  1242. * Get Outline View block for the Dashboard page.
  1243. *
  1244. * @param $iProfileId (optional) profile ID. 0 should be used here.
  1245. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  1246. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  1247. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  1248. * @param $sFilter (optional) string value with filter name.
  1249. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  1250. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1251. *
  1252. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  1253. */
  1254. /**
  1255. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  1256. */
  1257. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1258. {
  1259. if(!isLogged())
  1260. return '';
  1261. return $this->_serviceGetBlockViewByType(array(
  1262. 'view' => BX_TIMELINE_VIEW_OUTLINE,
  1263. 'type' => BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS,
  1264. 'owner_id' => $iProfileId,
  1265. 'start' => $iStart,
  1266. 'per_page' => $iPerPage,
  1267. 'per_page_default' => $this->_oConfig->getPerPage('account'),
  1268. 'timeline' => $iTimeline,
  1269. 'filter' => $sFilter,
  1270. 'modules' => $aModules
  1271. ));
  1272. }
  1273. /**
  1274. * @page service Service Calls
  1275. * @section bx_timeline Timeline
  1276. * @subsection bx_timeline-page_blocks Page Blocks
  1277. * @subsubsection bx_timeline-get_block_view_custom get_block_view_custom
  1278. *
  1279. * @code bx_srv('bx_timeline', 'get_block_view_custom', [...]); @endcode
  1280. *
  1281. * Get custom Timeline View block.
  1282. *
  1283. * @param $aParams (optional) an array with block parameneters.
  1284. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1285. *
  1286. * @see BxTimelineModule::serviceGetBlockViewCustom
  1287. */
  1288. /**
  1289. * @ref bx_timeline-get_block_view_custom "get_block_view_custom"
  1290. */
  1291. public function serviceGetBlockViewCustom($aParams = array())
  1292. {
  1293. return $this->_serviceGetBlockViewByType($aParams);
  1294. }
  1295. /**
  1296. * @page service Service Calls
  1297. * @section bx_timeline Timeline
  1298. * @subsection bx_timeline-page_blocks Page Blocks
  1299. * @subsubsection bx_timeline-get_block_item get_block_item
  1300. *
  1301. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  1302. *
  1303. * Get View Item block.
  1304. *
  1305. * @return an array describing a block to display on the site. All necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1306. *
  1307. * @see BxTimelineModule::serviceGetBlockItem
  1308. */
  1309. /**
  1310. * @ref bx_timeline-get_block_item "get_block_item"
  1311. */
  1312. public function serviceGetBlockItem()
  1313. {
  1314. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1315. if(!$iItemId)
  1316. return array();
  1317. $aParams = array(
  1318. 'view' => BX_TIMELINE_VIEW_ITEM,
  1319. 'type' => BX_TIMELINE_TYPE_ITEM
  1320. );
  1321. $aParams = $this->_prepareParams($aParams);
  1322. return $this->_oTemplate->getItemBlock($iItemId, $aParams);
  1323. }
  1324. public function serviceGetBlockItemContent()
  1325. {
  1326. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1327. $sMode = bx_process_input(bx_get('mode'));
  1328. if(!$iItemId || !$sMode)
  1329. return '';
  1330. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  1331. }
  1332. public function serviceGetBlockItemInfo()
  1333. {
  1334. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1335. if(!$iItemId)
  1336. return '';
  1337. return $this->_oTemplate->getItemBlockInfo($iItemId);
  1338. }
  1339. public function serviceGetBlockItemComments()
  1340. {
  1341. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1342. if(!$iItemId)
  1343. return '';
  1344. return $this->_oTemplate->getItemBlockComments($iItemId);
  1345. }
  1346. /**
  1347. * @page service Service Calls
  1348. * @section bx_timeline Timeline
  1349. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1350. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  1351. *
  1352. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  1353. *
  1354. * Data for Notifications module.
  1355. *
  1356. * @return an array with special format.
  1357. *
  1358. * @see BxTimelineModule::serviceGetNotificationsData
  1359. */
  1360. /**
  1361. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  1362. */
  1363. public function serviceGetNotificationsData()
  1364. {
  1365. $sModule = $this->_aModule['name'];
  1366. return array(
  1367. 'handlers' => array(
  1368. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  1369. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  1370. array('group' => $sModule . '_object_publish_failed', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_failed', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_failed', 'module_class' => 'Module'),
  1371. array('group' => $sModule . '_object_publish_succeeded', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'publish_succeeded', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_publish_succeeded', 'module_class' => 'Module'),
  1372. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  1373. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  1374. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  1375. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  1376. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  1377. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  1378. array('group' => $sModule . '_reaction', 'type' => 'insert', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_reaction', 'module_class' => 'Module'),
  1379. array('group' => $sModule . '_reaction', 'type' => 'delete', 'alert_unit' => $sModule . '_reactions', 'alert_action' => 'undoVote'),
  1380. array('group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'),
  1381. array('group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'),
  1382. ),
  1383. 'settings' => array(
  1384. array('group' => 'content', 'unit' => $sModule, 'action' => 'post_common', 'types' => array('personal', 'follow_member', 'follow_context')),
  1385. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_failed', 'types' => array('personal')),
  1386. array('group' => 'content', 'unit' => $sModule, 'action' => 'publish_succeeded', 'types' => array('personal')),
  1387. array('group' => 'content', 'unit' => $sModule, 'action' => 'repost', 'types' => array('follow_member', 'follow_context')),
  1388. array('group' => 'comment', 'unit' => $sModule, 'action' => 'commentPost', 'types' => array('personal', 'follow_member', 'follow_context')),
  1389. array('group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1390. array('group' => 'vote', 'unit' => $sModule . '_reactions', 'action' => 'doVote', 'types' => array('personal', 'follow_member', 'follow_context')),
  1391. array('group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => array('personal', 'follow_member', 'follow_context')),
  1392. array('group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => array('personal', 'follow_member', 'follow_context'))
  1393. ),
  1394. 'alerts' => array(
  1395. array('unit' => $sModule, 'action' => 'post_common'),
  1396. array('unit' => $sModule, 'action' => 'publish_failed'),
  1397. array('unit' => $sModule, 'action' => 'publish_succeeded'),
  1398. array('unit' => $sModule, 'action' => 'delete'),
  1399. array('unit' => $sModule, 'action' => 'repost'),
  1400. array('unit' => $sModule, 'action' => 'delete_repost'),
  1401. array('unit' => $sModule, 'action' => 'commentPost'),
  1402. array('unit' => $sModule, 'action' => 'commentRemoved'),
  1403. array('unit' => $sModule, 'action' => 'doVote'),
  1404. array('unit' => $sModule, 'action' => 'undoVote'),
  1405. array('unit' => $sModule . '_reactions', 'action' => 'doVote'),
  1406. array('unit' => $sModule . '_reactions', 'action' => 'undoVote'),
  1407. array('unit' => $sModule, 'action' => 'doVoteUp'),
  1408. array('unit' => $sModule, 'action' => 'doVoteDown'),
  1409. )
  1410. );
  1411. }
  1412. /**
  1413. * @page service Service Calls
  1414. * @section bx_timeline Timeline
  1415. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1416. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  1417. *
  1418. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  1419. *
  1420. * Get data for Repost event to display in Notifications module.
  1421. *
  1422. * @param $aEvent an array with event description.
  1423. * @return an array with special format.
  1424. *
  1425. * @see BxTimelineModule::serviceGetNotificationsRepost
  1426. */
  1427. /**
  1428. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  1429. */
  1430. public function serviceGetNotificationsRepost($aEvent)
  1431. {
  1432. $aResult = $this->serviceGetNotificationsPost($aEvent);
  1433. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  1434. return $aResult;
  1435. }
  1436. /**
  1437. * @page service Service Calls
  1438. * @section bx_timeline Timeline
  1439. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1440. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  1441. *
  1442. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  1443. *
  1444. * Get data for Post event to display in Notifications module.
  1445. *
  1446. * @param $aEvent an array with event description.
  1447. * @return an array with special format.
  1448. *
  1449. * @see BxTimelineModule::serviceGetNotificationsPost
  1450. */
  1451. /**
  1452. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  1453. */
  1454. public function serviceGetNotificationsPost($aEvent)
  1455. {
  1456. $CNF = &$this->_oConfig->CNF;
  1457. $iContent = (int)$aEvent['object_id'];
  1458. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1459. if(empty($aContent) || !is_array($aContent))
  1460. return array();
  1461. if($this->_oConfig->isSystem($aContent['type'], $aContent['action']))
  1462. $iEntryAuthor = (int)$aContent['owner_id'];
  1463. else
  1464. $iEntryAuthor = (int)$aContent['object_id'];
  1465. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1466. return array(
  1467. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  1468. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1469. 'entry_caption' => $sEntryCaption,
  1470. 'entry_author' => $iEntryAuthor,
  1471. 'lang_key' => '' //may be empty or not specified. In this case the default one from Notification module will be used.
  1472. );
  1473. }
  1474. /**
  1475. * @page service Service Calls
  1476. * @section bx_timeline Timeline
  1477. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1478. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  1479. *
  1480. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  1481. *
  1482. * Get data for Post Comment event to display in Notifications module.
  1483. *
  1484. * @param $aEvent an array with event description.
  1485. * @return an array with special format.
  1486. *
  1487. * @see BxTimelineModule::serviceGetNotificationsComment
  1488. */
  1489. /**
  1490. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  1491. */
  1492. public function serviceGetNotificationsComment($aEvent)
  1493. {
  1494. $CNF = &$this->_oConfig->CNF;
  1495. $iContent = (int)$aEvent['object_id'];
  1496. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1497. if(empty($aContent) || !is_array($aContent))
  1498. return array();
  1499. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  1500. if(!$oComment || !$oComment->isEnabled())
  1501. return array();
  1502. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1503. return array(
  1504. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1505. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1506. 'entry_caption' => $sEntryCaption,
  1507. 'entry_author' => $aContent['owner_id'],
  1508. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  1509. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  1510. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1511. );
  1512. }
  1513. /**
  1514. * @page service Service Calls
  1515. * @section bx_timeline Timeline
  1516. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1517. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  1518. *
  1519. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  1520. *
  1521. * Get data for Vote event to display in Notifications module.
  1522. *
  1523. * @param $aEvent an array with event description.
  1524. * @return an array with special format.
  1525. *
  1526. * @see BxTimelineModule::serviceGetNotificationsVote
  1527. */
  1528. /**
  1529. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  1530. */
  1531. public function serviceGetNotificationsVote($aEvent)
  1532. {
  1533. $CNF = &$this->_oConfig->CNF;
  1534. $iContent = (int)$aEvent['object_id'];
  1535. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1536. if(empty($aContent) || !is_array($aContent))
  1537. return array();
  1538. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1539. if(!$oVote || !$oVote->isEnabled())
  1540. return array();
  1541. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1542. return array(
  1543. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1544. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1545. 'entry_caption' => $sEntryCaption,
  1546. 'entry_author' => $aContent['owner_id'],
  1547. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1548. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1549. );
  1550. }
  1551. /**
  1552. * Entry post vote for Notifications module
  1553. */
  1554. public function serviceGetNotificationsReaction($aEvent)
  1555. {
  1556. $CNF = &$this->_oConfig->CNF;
  1557. $iContent = (int)$aEvent['object_id'];
  1558. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1559. if(empty($aContent) || !is_array($aContent))
  1560. return array();
  1561. $oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $iContent);
  1562. if(!$oReaction || !$oReaction->isEnabled())
  1563. return array();
  1564. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  1565. if(empty($aSubentry) || !is_array($aSubentry))
  1566. return array();
  1567. $aSubentrySampleParams = array();
  1568. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  1569. if(!empty($aReaction['title']))
  1570. $aSubentrySampleParams[] = $aReaction['title'];
  1571. else
  1572. $aSubentrySampleParams[] = '_undefined';
  1573. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1574. return array(
  1575. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1576. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1577. 'entry_caption' => $sEntryCaption,
  1578. 'entry_author' => $aContent['owner_id'],
  1579. 'subentry_sample' => $CNF['T']['txt_sample_reaction_single'],
  1580. 'subentry_sample_params' => $aSubentrySampleParams,
  1581. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1582. );
  1583. }
  1584. /**
  1585. * @page service Service Calls
  1586. * @section bx_timeline Timeline
  1587. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1588. * @subsubsection bx_timeline-get_notifications_score_up get_notifications_score_up
  1589. *
  1590. * @code bx_srv('bx_timeline', 'get_notifications_score_up', [...]); @endcode
  1591. *
  1592. * Get data for Score Up Vote event to display in Notifications module.
  1593. *
  1594. * @param $aEvent an array with event description.
  1595. * @return an array with special format.
  1596. *
  1597. * @see BxTimelineModule::serviceGetNotificationsScoreUp
  1598. */
  1599. /**
  1600. * @ref bx_timeline-get_notifications_score_up "get_notifications_score_up"
  1601. */
  1602. public function serviceGetNotificationsScoreUp($aEvent)
  1603. {
  1604. return $this->_serviceGetNotificationsScore('up', $aEvent);
  1605. }
  1606. /**
  1607. * @page service Service Calls
  1608. * @section bx_timeline Timeline
  1609. * @subsection bx_timeline-integration_notifications Integration with Notifications
  1610. * @subsubsection bx_timeline-get_notifications_score_down get_notifications_score_down
  1611. *
  1612. * @code bx_srv('bx_timeline', 'get_notifications_score_down', [...]); @endcode
  1613. *
  1614. * Get data for Score Down Vote event to display in Notifications module.
  1615. *
  1616. * @param $aEvent an array with event description.
  1617. * @return an array with special format.
  1618. *
  1619. * @see BxTimelineModule::serviceGetNotificationsScoreDown
  1620. */
  1621. /**
  1622. * @ref bx_timeline-get_notifications_score_down "get_notifications_score_down"
  1623. */
  1624. public function serviceGetNotificationsScoreDown($aEvent)
  1625. {
  1626. return $this->_serviceGetNotificationsScore('down', $aEvent);
  1627. }
  1628. protected function _serviceGetNotificationsScore($sType, $aEvent)
  1629. {
  1630. $CNF = &$this->_oConfig->CNF;
  1631. $iContent = (int)$aEvent['object_id'];
  1632. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1633. if(empty($aContent) || !is_array($aContent))
  1634. return array();
  1635. $oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], $iContent);
  1636. if(!$oScore || !$oScore->isEnabled())
  1637. return array();
  1638. $sEntryCaption = call_user_func_array(array($this->_oConfig, 'getTitleShort'), !empty($aContent['title']) ? array($aContent['title']) : array($aContent['description'], $aContent['object_id']));
  1639. return array(
  1640. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1641. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1642. 'entry_caption' => $sEntryCaption,
  1643. 'entry_author' => $aContent['owner_id'],
  1644. 'subentry_sample' => $CNF['T']['txt_sample_score_' . $sType . '_single'],
  1645. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1646. );
  1647. }
  1648. /**
  1649. * @page service Service Calls
  1650. * @section bx_timeline Timeline
  1651. * @subsection bx_timeline-repost Repost
  1652. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1653. *
  1654. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1655. *
  1656. * Get repost element for content based modules.
  1657. *
  1658. * @param $iOwnerId integer value with owner profile ID.
  1659. * @param $sType string value with type (module name).
  1660. * @param $sAction string value with action (module action).
  1661. * @param $iObjectId integer value with object ID to be reposted.
  1662. * @param $aParams (optional) an array with additional params.
  1663. * @return HTML string with repost element to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1664. *
  1665. * @see BxTimelineModule::serviceGetRepostElementBlock
  1666. */
  1667. /**
  1668. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1669. */
  1670. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1671. {
  1672. if(!$this->isEnabled())
  1673. return '';
  1674. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1675. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1676. }
  1677. /**
  1678. * @page service Service Calls
  1679. * @section bx_timeline Timeline
  1680. * @subsection bx_timeline-repost Repost
  1681. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1682. *
  1683. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1684. *
  1685. * Get repost counter.
  1686. *
  1687. * @param $sType string value with type (module name).
  1688. * @param $sAction string value with action (module action).
  1689. * @param $iObjectId integer value with object ID to be reposted.
  1690. * @return HTML string with repost counter to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1691. *
  1692. * @see BxTimelineModule::serviceGetRepostCounter
  1693. */
  1694. /**
  1695. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1696. */
  1697. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1698. {
  1699. if(!$this->isEnabled())
  1700. return '';
  1701. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1702. return $this->_oTemplate->getRepostCounter($aReposted);
  1703. }
  1704. /**
  1705. * @page service Service Calls
  1706. * @section bx_timeline Timeline
  1707. * @subsection bx_timeline-repost Repost
  1708. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1709. *
  1710. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1711. *
  1712. * Get repost JavaScript code.
  1713. *
  1714. * @return HTML string with JavaScript code to display on the site, all necessary CSS and JS files are automatically added to the HEAD section of the site HTML.
  1715. *
  1716. * @see BxTimelineModule::serviceGetRepostJsScript
  1717. */
  1718. /**
  1719. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1720. */
  1721. public function serviceGetRepostJsScript()
  1722. {
  1723. if(!$this->isEnabled())
  1724. return '';
  1725. return $this->_oTemplate->getRepostJsScript();
  1726. }
  1727. /**
  1728. * @page service Service Calls
  1729. * @section bx_timeline Timeline
  1730. * @subsection bx_timeline-repost Repost
  1731. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1732. *
  1733. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1734. *
  1735. * Get repost JavaScript code for OnClick event.
  1736. *
  1737. * @param $iOwnerId integer value with owner profile ID.
  1738. * @param $sType string value with type (module name).
  1739. * @param $sAction string value with action (module action).
  1740. * @param $iObjectId integer value with object ID to be reposted.
  1741. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1742. *
  1743. * @see BxTimelineModule::serviceGetRepostJsClick
  1744. */
  1745. /**
  1746. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1747. */
  1748. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1749. {
  1750. if(!$this->isEnabled())
  1751. return '';
  1752. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1753. }
  1754. /**
  1755. * @page service Service Calls
  1756. * @section bx_timeline Timeline
  1757. * @subsection bx_timeline-repost Repost
  1758. * @subsubsection bx_timeline-repost repost
  1759. *
  1760. * @code bx_srv('bx_timeline', 'repost', [...]); @endcode
  1761. *
  1762. * Perform repost action.
  1763. *
  1764. * @param $iAuthorId integer value with performer profile ID.
  1765. * @param $iOwnerId integer value with repost event owner profile ID.
  1766. * @param $sType string value with type (module name).
  1767. * @param $sAction string value with action (module action).
  1768. * @param $iObjectId integer value with object ID to be reposted.
  1769. * @parem $bForce boolean value force reposting without ACL check.
  1770. * @return an array with error (code and message) or integer with newly created repost event ID.
  1771. *
  1772. * @see BxTimelineModule::serviceRepost
  1773. */
  1774. /**
  1775. * @ref bx_timeline-repost "repost"
  1776. */
  1777. public function serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce = false)
  1778. {
  1779. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1780. if(empty($aReposted) || !is_array($aReposted))
  1781. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1782. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  1783. if(!$bForce && $mixedAllowed !== true)
  1784. return array('code' => 2, 'message' => strip_tags($mixedAllowed));
  1785. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  1786. if($bReposted)
  1787. return array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted'));
  1788. $iId = $this->_oDb->insertEvent(array(
  1789. 'owner_id' => $iOwnerId,
  1790. 'system' => 0,
  1791. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  1792. 'action' => '',
  1793. 'object_id' => $iAuthorId,
  1794. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  1795. 'content' => serialize(array(
  1796. 'type' => $sType,
  1797. 'action' => $sAction,
  1798. 'object_id' => $iObjectId,
  1799. )),
  1800. 'title' => '',
  1801. 'description' => ''
  1802. ));
  1803. if(empty($iId))
  1804. return array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1805. $this->onRepost($iId, $aReposted);
  1806. return $iId;
  1807. }
  1808. /**
  1809. * @page service Service Calls
  1810. * @section bx_timeline Timeline
  1811. * @subsection bx_timeline-repost Repost
  1812. * @subsubsection bx_timeline-repost_by_id repost_by_id
  1813. *
  1814. * @code bx_srv('bx_timeline', 'repost_by_id', [...]); @endcode
  1815. *
  1816. * Perform repost action by Timeline event ID.
  1817. *
  1818. * @param $iAuthorId integer value with performer profile ID.
  1819. * @param $iOwnerId integer value with repost event owner profile ID.
  1820. * @param $iEventId integer value with event ID which will be reposted.
  1821. * @parem $bForce boolean value force reposting without ACL check.
  1822. * @return an array with error (code and message) or integer with newly created repost event ID.
  1823. *
  1824. * @see BxTimelineModule::serviceRepostById
  1825. */
  1826. /**
  1827. * @ref bx_timeline-repost_by_id "repost_by_id"
  1828. */
  1829. public function serviceRepostById($iAuthorId, $iOwnerId, $iEventId, $bForce = false)
  1830. {
  1831. $aEvent = $this->_oDb->getEntriesBy(array('type' => 'id', 'id' => $iEventId));
  1832. if(empty($aEvent) || !is_array($aEvent))
  1833. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1834. $sType = $aEvent['type'];
  1835. $sAction = $aEvent['action'];
  1836. $iObjectId = $this->_oConfig->isSystem($sType, $sAction) ? $aEvent['object_id'] : $aEvent['id'];
  1837. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1838. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1839. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1840. if(empty($aReposted) || !is_array($aReposted))
  1841. return array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost'));
  1842. $aRepostedData = unserialize($aEvent['content']);
  1843. $sType = $aRepostedData['type'];
  1844. $sAction = $aRepostedData['action'];
  1845. $iObjectId = $aRepostedData['object_id'];
  1846. }
  1847. return $this->serviceRepost($iAuthorId, $iOwnerId, $sType, $sAction, $iObjectId, $bForce);
  1848. }
  1849. /**
  1850. * @page service Service Calls
  1851. * @section bx_timeline Timeline
  1852. * @subsection bx_timeline-other Other
  1853. * @subsubsection bx_timeline-update update
  1854. *
  1855. * @code bx_srv('bx_timeline', 'update', [...]); @endcode
  1856. *
  1857. * Update timeline event by ID.
  1858. *
  1859. * @param $iEventId integer value with event ID.
  1860. * @param $aSet an array with key=>value pairs for fields which should be updated.
  1861. * @return boolean value with the result of operation.
  1862. *
  1863. * @see BxTimelineModule::serviceUpdate
  1864. */
  1865. /**
  1866. * @ref bx_timeline-update "update"
  1867. */
  1868. public function serviceUpdate($iEventId, $aSet)
  1869. {
  1870. if(empty($iEventId))
  1871. return false;
  1872. return (int)$this->_oDb->updateEvent($aSet, array('id' => $iEventId)) > 0;
  1873. }
  1874. /**
  1875. * @page service Service Calls
  1876. * @section bx_timeline Timeline
  1877. * @subsection bx_timeline-other Other
  1878. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1879. *
  1880. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1881. *
  1882. * Get addon for Comment menu item.
  1883. *
  1884. * @param $sSystem string value with comments engine system.
  1885. * @param $iObjectId integer value with object ID.
  1886. * @return HTML string to display in menu item.
  1887. *
  1888. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1889. */
  1890. /**
  1891. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1892. */
  1893. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId, $aBrowseParams = array())
  1894. {
  1895. if(empty($sSystem) || empty($iObjectId))
  1896. return '';
  1897. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1898. if($oCmts === false)
  1899. return '';
  1900. $iCounter = (int)$oCmts->getCommentsCount();
  1901. if(empty($iCounter))
  1902. return '';
  1903. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter, array(
  1904. 'class' => 'bx-menu-item-addon',
  1905. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1906. 'onclick' => "javascript:" . $this->_oConfig->getJsObjectView($aBrowseParams) . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1907. ));
  1908. }
  1909. /**
  1910. * @page service Service Calls
  1911. * @section bx_timeline Timeline
  1912. * @subsection bx_timeline-other Other
  1913. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1914. *
  1915. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1916. *
  1917. * Get Checker Helper class name for Forms engine.
  1918. *
  1919. * @return string with Checker Helper class name.
  1920. *
  1921. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1922. */
  1923. /**
  1924. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1925. */
  1926. public function serviceGetSettingsCheckerHelper()
  1927. {
  1928. bx_import('FormCheckerHelper', $this->_aModule);
  1929. return 'BxTimelineFormCheckerHelper';
  1930. }
  1931. /**
  1932. * @page service Service Calls
  1933. * @section bx_timeline Timeline
  1934. * @subsection bx_timeline-other Other
  1935. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1936. *
  1937. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1938. *
  1939. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1940. *
  1941. * @return an array with available options represented as key => value pairs.
  1942. *
  1943. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1944. */
  1945. /**
  1946. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1947. */
  1948. public function serviceGetOptionsVideosAutoplay()
  1949. {
  1950. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1951. $aResult = array();
  1952. foreach($aOptions as $sOption)
  1953. $aResult[] = array(
  1954. 'key' => $sOption,
  1955. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1956. );
  1957. return $aResult;
  1958. }
  1959. /**
  1960. * @page service Service Calls
  1961. * @section bx_timeline Timeline
  1962. * @subsection bx_timeline-other Other
  1963. * @subsubsection bx_timeline-get_live_update get_live_update
  1964. *
  1965. * @code bx_srv('bx_timeline', 'get_live_update', [...]); @endcode
  1966. *
  1967. * Get an array with actual Live Update info. Only one live update notification for all new events.
  1968. *
  1969. * @return an array with Live Update info.
  1970. *
  1971. * @see BxTimelineModule::serviceGetLiveUpdate
  1972. */
  1973. /**
  1974. * @ref bx_timeline-get_live_update "get_live_update"
  1975. */
  1976. public function serviceGetLiveUpdate($aBrowseParams, $iProfileId, $iValue = 0, $iInit = 0)
  1977. {
  1978. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  1979. bx_import('BxDolSession');
  1980. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  1981. return false;
  1982. $aParams = $this->_prepareParams($aBrowseParams);
  1983. $aParams = array_merge($aParams, array(
  1984. 'per_page' => 1,
  1985. 'filter' => BX_TIMELINE_FILTER_OTHER_VIEWER
  1986. ));
  1987. $aEvents = $this->_oDb->getEvents($aParams);
  1988. if(empty($aEvents) || !is_array($aEvents) || count($aEvents) != 1)
  1989. return false;
  1990. $iValueNew = $aEvents[0]['id'];
  1991. if($iValueNew == $iValue)
  1992. return false;
  1993. if((int)$iInit != 0)
  1994. return array('count' => $iValueNew);
  1995. return array(
  1996. 'count' => $iValueNew, // required (for initialization and visualization)
  1997. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdate(oData)', // required (for visualization)
  1998. 'data' => array(
  1999. 'code' => $this->_oTemplate->getLiveUpdate($aBrowseParams, $iProfileId, $iValue, $iValueNew)
  2000. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2001. );
  2002. }
  2003. /**
  2004. * @page service Service Calls
  2005. * @section bx_timeline Timeline
  2006. * @subsection bx_timeline-other Other
  2007. * @subsubsection bx_timeline-get_live_updates get_live_updates
  2008. *
  2009. * @code bx_srv('bx_timeline', 'get_live_updates', [...]); @endcode
  2010. *
  2011. * Get an array with actual Live Update info. Separate live update notification for each new Event.
  2012. *
  2013. * Note. This way to display live update notifications isn't used for now.
  2014. * See BxTimelineModule::serviceGetLiveUpdate method instead.
  2015. *
  2016. * @return an array with Live Update info.
  2017. *
  2018. * @see BxTimelineModule::serviceGetLiveUpdates
  2019. */
  2020. /**
  2021. * @ref bx_timeline-get_live_updates "get_live_updates"
  2022. */
  2023. public function serviceGetLiveUpdates($aBrowseParams, $iProfileId, $iCount = 0, $iInit = 0)
  2024. {
  2025. $sKey = $this->_oConfig->getLiveUpdateKey($aBrowseParams);
  2026. bx_import('BxDolSession');
  2027. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  2028. return false;
  2029. $aParams = $this->_prepareParams($aBrowseParams);
  2030. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  2031. $aParams['count'] = true;
  2032. $iCountNew = $this->_oDb->getEvents($aParams);
  2033. if($iCountNew == $iCount)
  2034. return false;
  2035. if((int)$iInit != 0)
  2036. return array('count' => $iCountNew);
  2037. return array(
  2038. 'count' => $iCountNew, // required (for initialization and visualization)
  2039. 'method' => $this->_oConfig->getJsObjectView($aBrowseParams) . '.showLiveUpdates(oData)', // required (for visualization)
  2040. 'data' => array(
  2041. 'code' => $this->_oTemplate->getLiveUpdates($aBrowseParams, $iProfileId, $iCount, $iCountNew)
  2042. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  2043. );
  2044. }
  2045. /**
  2046. * @page service Service Calls
  2047. * @section bx_timeline Accounts
  2048. * @subsection bx_timeline-other Other
  2049. * @subsubsection bx_timeline-get_menu_addon_manage_tools get_menu_addon_manage_tools
  2050. *
  2051. * @code bx_srv('bx_timeline', 'get_menu_addon_manage_tools', [...]); @endcode
  2052. *
  2053. * Get number of 'hidden' events for User End -> Dasboard page -> Manage block.
  2054. *
  2055. * @return integer number of 'hidden' events
  2056. *
  2057. * @see BxTimelineModule::serviceGetMenuAddonManageTools
  2058. */
  2059. /**
  2060. * @ref bx_timeline-get_menu_addon_manage_tools "get_menu_addon_manage_tools"
  2061. */
  2062. public function serviceGetMenuAddonManageTools()
  2063. {
  2064. bx_import('SearchResult', $this->_aModule);
  2065. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  2066. $oSearch = new $sClass();
  2067. $oSearch->fillFilters(array(
  2068. 'status' => BX_TIMELINE_STATUS_HIDDEN
  2069. ));
  2070. $oSearch->unsetPaginate();
  2071. return $oSearch->getNum();
  2072. }
  2073. /*
  2074. * COMMON METHODS
  2075. */
  2076. public function deleteEvent($aEvent)
  2077. {
  2078. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  2079. return false;
  2080. $this->onDelete($aEvent);
  2081. return true;
  2082. }
  2083. public function addAttachLink($aValues, $sDisplay = false)
  2084. {
  2085. $CNF = &$this->_oConfig->CNF;
  2086. if(!$sDisplay)
  2087. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  2088. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  2089. if(!$oForm)
  2090. return array('message' => '_sys_txt_error_occured');
  2091. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  2092. $oForm->aParams['csrf']['disable'] = true;
  2093. if(!empty($oForm->aParams['db']['submit_name'])) {
  2094. $sSubmitName = $oForm->aParams['db']['submit_name'];
  2095. if(!isset($oForm->aInputs[$sSubmitName])) {
  2096. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  2097. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2098. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  2099. continue;
  2100. $aValues[$sSubmitName] = $aInput['value'];
  2101. }
  2102. }
  2103. else
  2104. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  2105. }
  2106. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2107. $oForm->initChecker(array(), $aValues);
  2108. if(!$oForm->isSubmittedAndValid())
  2109. return array('message' => '_sys_txt_error_occured');
  2110. return $this->_addLink($oForm);
  2111. }
  2112. public function getFormAttachLink()
  2113. {
  2114. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  2115. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  2116. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  2117. $oForm->initChecker();
  2118. if($oForm->isSubmittedAndValid())
  2119. return $this->_addLink($oForm);
  2120. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  2121. }
  2122. public function getFormPost($aParams = array())
  2123. {
  2124. $iUserId = $this->getUserId();
  2125. $oForm = $this->getFormPostObject($aParams);
  2126. $oForm->initChecker();
  2127. $bAjaxMode = $oForm->isAjaxMode();
  2128. $bDynamicMode = $bAjaxMode;
  2129. if($oForm->isSubmittedAndValid()) {
  2130. list($sUserName) = $this->getUserInfo($iUserId);
  2131. $sType = $oForm->getCleanValue('type');
  2132. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  2133. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  2134. $aContent = array();
  2135. //--- Process Text ---//
  2136. $sText = $oForm->getCleanValue('text');
  2137. $sText = $this->_prepareTextForSave($sText);
  2138. $bText = !empty($sText);
  2139. if($bText)
  2140. $aContent['text'] = $sText;
  2141. //--- Process Context and Privacy ---//
  2142. $iOwnerId = (int)$oForm->getCleanValue('owner_id');
  2143. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2144. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2145. if(empty($iObjectPrivacyView))
  2146. $iObjectPrivacyView = $iObjectPrivacyViewDefault;
  2147. else if($iObjectPrivacyView < 0)
  2148. $iOwnerId = abs($iObjectPrivacyView);
  2149. //--- Process Link ---//
  2150. $aLinkIds = $oForm->getCleanValue('link');
  2151. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  2152. //--- Process Media ---//
  2153. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  2154. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  2155. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  2156. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  2157. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds) {
  2158. $oForm->aInputs['text']['error'] = _t('_bx_timeline_txt_err_empty_post');
  2159. $oForm->setValid(false);
  2160. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode);
  2161. }
  2162. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oConfig->getTitleDefault($bLinkIds, $bPhotoIds, $bVideoIds);
  2163. $sDescription = _t('_bx_timeline_txt_user_added_sample', '{profile_name}', _t('_bx_timeline_txt_sample_with_article'));
  2164. /**
  2165. * Unset 'text' input because its data was already processed
  2166. * and will be saved via additional values which were passed
  2167. * to BxDolForm::insert method.
  2168. */
  2169. unset($oForm->aInputs['text']);
  2170. $iId = $oForm->insert(array(
  2171. 'owner_id' => $iOwnerId,
  2172. 'object_id' => $iUserId,
  2173. 'object_privacy_view' => $iObjectPrivacyView,
  2174. 'content' => serialize($aContent),
  2175. 'title' => $sTitle,
  2176. 'description' => $sDescription
  2177. ));
  2178. if(!empty($iId)) {
  2179. $aContent = array_merge($aContent, array(
  2180. 'timeline_group' => array(
  2181. 'by' => $this->getName() . '_' . $iUserId . '_' . $iId,
  2182. 'field' => 'owner_id'
  2183. )
  2184. ));
  2185. $this->_oDb->updateEvent(array('content' => serialize($aContent)), array('id' => $iId));
  2186. //--- Process Meta ---//
  2187. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2188. if($bText)
  2189. $oMetatags->metaAdd($iId, $sText);
  2190. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2191. //--- Process Link ---//
  2192. if($bLinkIds)
  2193. foreach($aLinkIds as $iLinkId)
  2194. $this->_oDb->saveLink($iId, $iLinkId);
  2195. //--- Process Media ---//
  2196. if($bPhotoIds)
  2197. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  2198. if($bVideoIds)
  2199. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  2200. $this->onPost($iId);
  2201. return $this->_prepareResponse(array('id' => $iId), $bAjaxMode, array(
  2202. 'redirect' => $this->_oConfig->getItemViewUrl(array('id' => $iId))
  2203. ));
  2204. }
  2205. return $this->_prepareResponse(array('message' => _t('_bx_timeline_txt_err_cannot_perform_action')), $bAjaxMode);
  2206. }
  2207. return $this->_prepareResponse(array('form' => $oForm->getCode($bDynamicMode), 'form_id' => $oForm->id), $bAjaxMode && $oForm->isSubmitted());
  2208. }
  2209. public function getFormEdit($iId, $aParams = array(), $aBrowseParams = array())
  2210. {
  2211. $CNF = &$this->_oConfig->CNF;
  2212. $sJsObjectView = $this->_oConfig->getJsObjectView($aBrowseParams);
  2213. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  2214. if(empty($aEvent) || !is_array($aEvent))
  2215. return array();
  2216. $aContent = unserialize($aEvent['content']);
  2217. if(is_array($aContent) && !empty($aContent['text']))
  2218. $aEvent['text'] = $aContent['text'];
  2219. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  2220. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2221. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  2222. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2223. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  2224. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  2225. if(!empty($aBrowseParams) && is_array($aBrowseParams))
  2226. $oForm->aFormAttrs['action'] = $this->_oConfig->addBrowseParams($oForm->aFormAttrs['action'], $aBrowseParams);
  2227. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  2228. if(!is_numeric($mixedIndex))
  2229. continue;
  2230. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  2231. 'js_object_view' => $sJsObjectView,
  2232. 'content_id' => $iId
  2233. ));
  2234. }
  2235. $oForm->initChecker($aEvent);
  2236. if($oForm->isSubmittedAndValid()) {
  2237. $aContent = array();
  2238. //--- Process Text ---//
  2239. $sText = $oForm->getCleanValue('text');
  2240. $sText = $this->_prepareTextForSave($sText);
  2241. $bText = !empty($sText);
  2242. unset($oForm->aInputs['text']);
  2243. if($bText)
  2244. $aContent['text'] = $sText;
  2245. $aValsToAdd = array(
  2246. 'content' => serialize($aContent)
  2247. );
  2248. //--- Process Privacy ---//
  2249. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  2250. $iObjectPrivacyViewDefault = $this->_oConfig->getPrivacyViewDefault('object');
  2251. if(empty($iObjectPrivacyView))
  2252. $aValsToAdd = array_merge($aValsToAdd, array(
  2253. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2254. ));
  2255. else if($iObjectPrivacyView < 0)
  2256. $aValsToAdd = array_merge($aValsToAdd, array(
  2257. 'owner_id' => abs($iObjectPrivacyView),
  2258. 'object_privacy_view' => $iObjectPrivacyViewDefault
  2259. ));
  2260. if(!$oForm->update($iId, $aValsToAdd))
  2261. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  2262. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2263. if($bText)
  2264. $oMetatags->metaAdd($iId, $sText);
  2265. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  2266. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iId);
  2267. $this->_oDb->deleteCache(array('event_id' => $iId));
  2268. return array(
  2269. 'id' => $iId
  2270. );
  2271. }
  2272. return array(
  2273. 'id' => $iId,
  2274. 'form' => $oForm->getCode($bDynamicMode),
  2275. 'form_id' => $oForm->id,
  2276. 'eval' => $sJsObjectView . '.onEditPost(oData)'
  2277. );
  2278. }
  2279. public function getFormPostObject($aParams)
  2280. {
  2281. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  2282. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  2283. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  2284. /**
  2285. * Note. 'ajax_mode' parameter isn't checked because
  2286. * timeline post form works as Ajax form by default.
  2287. */
  2288. $sParamsKey = 'visibility_autoselect';
  2289. if(isset($aParams[$sParamsKey]) && (bool)$aParams[$sParamsKey] === true)
  2290. $oForm->setVisibilityAutoselect((bool)$aParams[$sParamsKey]);
  2291. $oForm->init();
  2292. return $oForm;
  2293. }
  2294. public function getCmtsObject($sSystem, $iId)
  2295. {
  2296. if(empty($sSystem) || (int)$iId == 0)
  2297. return false;
  2298. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2299. if(!$oCmts || !$oCmts->isEnabled())
  2300. return false;
  2301. return $oCmts;
  2302. }
  2303. public function getViewObject($sSystem, $iId)
  2304. {
  2305. if(empty($sSystem) || (int)$iId == 0)
  2306. return false;
  2307. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2308. if(!$oView || !$oView->isEnabled())
  2309. return false;
  2310. return $oView;
  2311. }
  2312. public function getVoteObject($sSystem, $iId)
  2313. {
  2314. if(empty($sSystem) || (int)$iId == 0)
  2315. return false;
  2316. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2317. if(!$oVote || !$oVote->isEnabled())
  2318. return false;
  2319. return $oVote;
  2320. }
  2321. public function getReactionObject($sSystem, $iId)
  2322. {
  2323. if(empty($sSystem) || (int)$iId == 0)
  2324. return false;
  2325. $oReaction = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2326. if(!$oReaction || !$oReaction->isEnabled())
  2327. return false;
  2328. return $oReaction;
  2329. }
  2330. public function getScoreObject($sSystem, $iId)
  2331. {
  2332. if(empty($sSystem) || (int)$iId == 0)
  2333. return false;
  2334. $oScore = BxDolScore::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2335. if(!$oScore || !$oScore->isEnabled())
  2336. return false;
  2337. return $oScore;
  2338. }
  2339. public function getReportObject($sSystem, $iId)
  2340. {
  2341. if(empty($sSystem) || (int)$iId == 0)
  2342. return false;
  2343. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  2344. if(!$oReport || !$oReport->isEnabled())
  2345. return false;
  2346. return $oReport;
  2347. }
  2348. public function getAttachmentsMenuObject()
  2349. {
  2350. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  2351. $oMenu->addMarkers(array(
  2352. 'js_object' => $this->_oConfig->getJsObject('post'),
  2353. ));
  2354. return $oMenu;
  2355. }
  2356. public function getManageMenuObject()
  2357. {
  2358. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  2359. }
  2360. public function getCacheItemObject()
  2361. {
  2362. $oCacheEngine = bx_instance('BxDolCache' . $this->_oConfig->getCacheItemEngine());
  2363. if(!$oCacheEngine->isAvailable())
  2364. $oCacheEngine = bx_instance('BxDolCacheFile');
  2365. return $oCacheEngine;
  2366. }
  2367. //--- Check permissions methods ---//
  2368. public function isModerator()
  2369. {
  2370. $sModule = $this->getName();
  2371. $iUserId = (int)$this->getUserId();
  2372. $aCheckResult = checkActionModule($iUserId, 'edit', $sModule);
  2373. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2374. return true;
  2375. $aCheckResult = checkActionModule($iUserId, 'delete', $sModule);
  2376. if($aCheckResult[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  2377. return true;
  2378. return false;
  2379. }
  2380. public function isAllowedPost($bPerform = false)
  2381. {
  2382. if(isAdmin())
  2383. return true;
  2384. $iUserId = $this->getUserId();
  2385. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  2386. if($aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  2387. return $aCheckResult[CHECK_ACTION_MESSAGE];
  2388. if(!empty($this->_iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId)) !== false) {
  2389. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2390. return _t('_sys_txt_access_denied');
  2391. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2392. }
  2393. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2394. }
  2395. public function isAllowedView($aEvent, $bPerform = false)
  2396. {
  2397. $CNF = $this->_oConfig->CNF;
  2398. if((int)$aEvent[$CNF['FIELD_OWNER_ID']] == 0)
  2399. return true;
  2400. $oProfileOwner = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']]);
  2401. if($oProfileOwner && $oProfileOwner->checkAllowedProfileView() !== CHECK_ACTION_RESULT_ALLOWED)
  2402. return false;
  2403. return true;
  2404. }
  2405. public function isAllowedEdit($aEvent, $bPerform = false)
  2406. {
  2407. if(!isLogged())
  2408. return false;
  2409. //--- System posts and Reposts cannot be edited at all.
  2410. if(!$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) || $aEvent['type'] == $this->_oConfig->getPrefix('common_post') . 'repost')
  2411. return false;
  2412. if(isAdmin())
  2413. return true;
  2414. $iUserId = (int)$this->getUserId();
  2415. $iOwnerId = (int)$aEvent['owner_id'];
  2416. $iObjectId = abs((int)$aEvent['object_id']);
  2417. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  2418. return true;
  2419. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  2420. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2421. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2422. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2423. }
  2424. public function isAllowedDelete($aEvent, $bPerform = false)
  2425. {
  2426. if(!isLogged())
  2427. return false;
  2428. if(isAdmin())
  2429. return true;
  2430. $iUserId = (int)$this->getUserId();
  2431. $iOwnerId = (int)$aEvent['owner_id'];
  2432. $iObjectId = abs((int)$aEvent['object_id']);
  2433. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  2434. return true;
  2435. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  2436. if(!empty($iOwnerId) && ($oProfileOwner = BxDolProfile::getInstance($iOwnerId)) !== false)
  2437. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2438. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2439. }
  2440. public function isAllowedComment($aEvent, $bPerform = false)
  2441. {
  2442. $mixedComments = $this->getCommentsData($aEvent['comments']);
  2443. if($mixedComments === false)
  2444. return false;
  2445. list($sSystem, $iObjectId) = $mixedComments;
  2446. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  2447. if($oCmts->isViewAllowed() !== CHECK_ACTION_RESULT_ALLOWED)
  2448. return false;
  2449. $oCmts->addCssJs();
  2450. $bResult = true;
  2451. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false) {
  2452. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  2453. return false;
  2454. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2455. }
  2456. return $bResult;
  2457. }
  2458. public function isAllowedViewCounter($aEvent, $bPerform = false)
  2459. {
  2460. $mixedViews = $this->getViewsData($aEvent['views']);
  2461. if($mixedViews === false)
  2462. return false;
  2463. list($sSystem, $iObjectId) = $mixedViews;
  2464. $oView = $this->getViewObject($sSystem, $iObjectId);
  2465. if(!$oView->isAllowedViewView($bPerform))
  2466. return false;
  2467. $bResult = true;
  2468. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2469. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2470. return $bResult;
  2471. }
  2472. public function isAllowedVote($aEvent, $bPerform = false)
  2473. {
  2474. $mixedVotes = $this->getVotesData($aEvent['votes']);
  2475. if($mixedVotes === false)
  2476. return false;
  2477. list($sSystem, $iObjectId) = $mixedVotes;
  2478. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  2479. if(!$oVote->isAllowedVote($bPerform))
  2480. return false;
  2481. $bResult = true;
  2482. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2483. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2484. return $bResult;
  2485. }
  2486. public function isAllowedReaction($aEvent, $bPerform = false)
  2487. {
  2488. $mixedReactions = $this->getReactionsData($aEvent['reactions']);
  2489. if($mixedReactions === false)
  2490. return false;
  2491. list($sSystem, $iObjectId) = $mixedReactions;
  2492. $oReaction = $this->getReactionObject($sSystem, $iObjectId);
  2493. if(!$oReaction->isAllowedVote($bPerform))
  2494. return false;
  2495. $bResult = true;
  2496. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2497. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_reaction', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2498. return $bResult;
  2499. }
  2500. public function isAllowedScore($aEvent, $bPerform = false)
  2501. {
  2502. $mixedScores = $this->getScoresData($aEvent['scores']);
  2503. if($mixedScores === false)
  2504. return false;
  2505. list($sSystem, $iObjectId) = $mixedScores;
  2506. $oScore = $this->getScoreObject($sSystem, $iObjectId);
  2507. if(!$oScore->isAllowedVote($bPerform))
  2508. return false;
  2509. $bResult = true;
  2510. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2511. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_score', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2512. return $bResult;
  2513. }
  2514. public function isAllowedReport($aEvent, $bPerform = false)
  2515. {
  2516. $mixedReports = $this->getReportsData($aEvent['reports']);
  2517. if($mixedReports === false)
  2518. return false;
  2519. list($sSystem, $iObjectId) = $mixedReports;
  2520. $oReport = $this->getReportObject($sSystem, $iObjectId);
  2521. if(!$oReport->isAllowedReport($bPerform))
  2522. return false;
  2523. $bResult = true;
  2524. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2525. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  2526. return $bResult;
  2527. }
  2528. public function isAllowedRepost($aEvent, $bPerform = false)
  2529. {
  2530. $iUserId = (int)$this->getUserId();
  2531. if($iUserId == 0)
  2532. return false;
  2533. $iPrivacy = (int)$aEvent['object_privacy_view'];
  2534. if($iPrivacy >= 0 && !in_array($iPrivacy, array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
  2535. return false;
  2536. if(isAdmin())
  2537. return true;
  2538. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  2539. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2540. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2541. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2542. }
  2543. public function isAllowedSend($aEvent, $bPerform = false)
  2544. {
  2545. if(!$this->_oDb->isEnabledByName('bx_convos'))
  2546. return false;
  2547. if(isAdmin())
  2548. return true;
  2549. $iUserId = (int)$this->getUserId();
  2550. if($iUserId == 0)
  2551. return false;
  2552. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  2553. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2554. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2555. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2556. }
  2557. /**
  2558. * Pin - "Pin here" - pin the post on Profile Timeline for profile owner.
  2559. * Can be done by profile owner for himself or by admin for profile owner to see.
  2560. * @param type $aEvent
  2561. * @param type $bPerform
  2562. * @return boolean
  2563. */
  2564. public function isAllowedPin($aEvent, $bPerform = false)
  2565. {
  2566. if((int)$aEvent['pinned'] != 0)
  2567. return false;
  2568. return $this->_isAllowedPin($aEvent, $bPerform);
  2569. }
  2570. public function isAllowedUnpin($aEvent, $bPerform = false)
  2571. {
  2572. if((int)$aEvent['pinned'] == 0)
  2573. return false;
  2574. return $this->_isAllowedPin($aEvent, $bPerform);
  2575. }
  2576. /**
  2577. * Stick - "Pin for All" - pin the post on Public Timeline for everybody to see.
  2578. * Is available for Administrators/Moderators only.
  2579. * @param type $aEvent
  2580. * @param type $bPerform
  2581. * @return boolean
  2582. */
  2583. public function isAllowedStick($aEvent, $bPerform = false)
  2584. {
  2585. if((int)$aEvent['sticked'] != 0)
  2586. return false;
  2587. return $this->_isAllowedStick($aEvent, $bPerform);
  2588. }
  2589. public function isAllowedUnstick($aEvent, $bPerform = false)
  2590. {
  2591. if((int)$aEvent['sticked'] == 0)
  2592. return false;
  2593. return $this->_isAllowedStick($aEvent, $bPerform);
  2594. }
  2595. public function isAllowedPromote($aEvent, $bPerform = false)
  2596. {
  2597. if((int)$aEvent['promoted'] != 0)
  2598. return false;
  2599. return $this->_isAllowedPromote($aEvent, $bPerform);
  2600. }
  2601. public function isAllowedUnpromote($aEvent, $bPerform = false)
  2602. {
  2603. if((int)$aEvent['promoted'] == 0)
  2604. return false;
  2605. return $this->_isAllowedPromote($aEvent, $bPerform);
  2606. }
  2607. public function isAllowedMore($aEvent, $bPerform = false)
  2608. {
  2609. $oMoreMenu = $this->getManageMenuObject();
  2610. $oMoreMenu->setEvent($aEvent);
  2611. return $oMoreMenu->isVisible();
  2612. }
  2613. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  2614. {
  2615. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  2616. return _t('_sys_txt_access_denied');
  2617. return CHECK_ACTION_RESULT_ALLOWED;
  2618. }
  2619. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  2620. {
  2621. $CNF = $this->_oConfig->CNF;
  2622. $iOwner = (int)$aContentInfo[$CNF['FIELD_OWNER_ID']];
  2623. if($iOwner == 0) //--- in case of Public Timeline.
  2624. return CHECK_ACTION_RESULT_ALLOWED;
  2625. $oOwner = BxDolProfile::getInstance($iOwner);
  2626. if(!$oOwner) //--- in case of non-existed Timeline owner.
  2627. return _t('_sys_txt_access_denied');
  2628. $mixedResult = $oOwner->checkAllowedProfileView();
  2629. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2630. return $mixedResult;
  2631. return CHECK_ACTION_RESULT_ALLOWED;
  2632. }
  2633. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  2634. {
  2635. $sError = '_sys_txt_access_denied';
  2636. $aContentInfo = $this->_oTemplate->getDataCached($aContentInfo);
  2637. if($aContentInfo === false)
  2638. return _t($sError);
  2639. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  2640. return _t($sError);
  2641. return CHECK_ACTION_RESULT_ALLOWED;
  2642. }
  2643. public function onPost($iContentId)
  2644. {
  2645. $CNF = &$this->_oConfig->CNF;
  2646. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2647. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2648. //--- Request event's data from content module and update it in the Timeline DB.
  2649. $this->_oTemplate->getDataCached($aEvent);
  2650. $sPostType = 'system';
  2651. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2652. }
  2653. else {
  2654. $sPostType = 'common';
  2655. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2656. }
  2657. //--- Event -> Post/Defer for Alerts Engine ---//
  2658. $sAction = ($aEvent[$CNF['FIELD_STATUS']] == BX_TIMELINE_STATUS_AWAITING ? 'defer' : 'post') . '_' . $sPostType;
  2659. bx_alert($this->_oConfig->getObject('alert'), $sAction, $iContentId, $iSenderId, array(
  2660. 'owner_id' => $aEvent['owner_id'],
  2661. 'object_author_id' => $iObjectAuthorId,
  2662. 'privacy_view' => $aEvent['object_privacy_view'],
  2663. ));
  2664. //--- Event -> Post for Alerts Engine ---//
  2665. }
  2666. public function onPublished($iContentId)
  2667. {
  2668. $CNF = &$this->_oConfig->CNF;
  2669. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2670. //--- Clear Item cache
  2671. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2672. //--- Clear Feed cache
  2673. $this->_oDb->deleteCache(array('context_id' => $aEvent[$CNF['FIELD_OWNER_ID']]));
  2674. $this->onPost($iContentId);
  2675. }
  2676. public function onFailed($iContentId)
  2677. {
  2678. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2679. //--- Clear Item cache
  2680. $this->getCacheItemObject()->removeAllByPrefix($this->_oConfig->getPrefix('cache_item') . $iContentId);
  2681. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  2682. //--- Request event's data from content module and update it in the Timeline DB.
  2683. $this->_oTemplate->getDataCached($aEvent);
  2684. $sPostType = 'system';
  2685. $iSenderId = $iObjectAuthorId = (int)$aEvent['owner_id'];
  2686. }
  2687. else {
  2688. $sPostType = 'common';
  2689. $iSenderId = $iObjectAuthorId = (int)$aEvent['object_id'];
  2690. }
  2691. //--- Event -> Fail for Alerts Engine ---//
  2692. bx_alert($this->_oConfig->getObject('alert'), 'fail_' . $sPostType, $iContentId, $iSenderId, array(
  2693. 'owner_id' => $aEvent['owner_id'],
  2694. 'object_author_id' => $iObjectAuthorId,
  2695. 'privacy_view' => $aEvent['object_privacy_view'],
  2696. ));
  2697. //--- Event -> Post for Alerts Engine ---//
  2698. }
  2699. public function onRepost($iContentId, $aReposted = array())
  2700. {
  2701. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  2702. if(empty($aReposted)) {
  2703. $aContent = unserialize($aEvent['content']);
  2704. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2705. if(empty($aReposted) || !is_array($aReposted))
  2706. return;
  2707. }
  2708. $iUserId = $this->getUserId();
  2709. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  2710. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  2711. //--- Timeline -> Update for Alerts Engine ---//
  2712. bx_alert($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  2713. 'privacy_view' => $aEvent['object_privacy_view'],
  2714. 'object_author_id' => $aReposted['owner_id'],
  2715. 'repost_id' => $iContentId,
  2716. ));
  2717. //--- Timeline -> Update for Alerts Engine ---//
  2718. }
  2719. public function onDelete($aEvent)
  2720. {
  2721. $CNF = &$this->_oConfig->CNF;
  2722. $iUserId = $this->getUserId();
  2723. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  2724. $sCommonPostComment = $this->_oConfig->getObject('comment');
  2725. //--- Delete comments for Common posts.
  2726. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  2727. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent[$CNF['FIELD_ID']]);
  2728. if($oComments !== false)
  2729. $oComments->onObjectDelete($aEvent[$CNF['FIELD_ID']]);
  2730. }
  2731. //--- Delete attached photos, videos and links when common event was deleted.
  2732. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  2733. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent[$CNF['FIELD_ID']]);
  2734. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent[$CNF['FIELD_ID']]);
  2735. $this->_deleteLinks($aEvent[$CNF['FIELD_ID']]);
  2736. }
  2737. //--- Update parent event when repost event was deleted.
  2738. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  2739. if($bRepost) {
  2740. $this->_oDb->deleteRepostTrack($aEvent[$CNF['FIELD_ID']]);
  2741. $aContent = unserialize($aEvent['content']);
  2742. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  2743. if(!empty($aReposted) && is_array($aReposted))
  2744. $this->_oDb->updateRepostCounter($aReposted[$CNF['FIELD_ID']], $aReposted['reposts'], -1);
  2745. }
  2746. //--- Find and delete repost events when parent event was deleted.
  2747. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  2748. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  2749. foreach($aRepostEvents as $aRepostEvent) {
  2750. $aContent = unserialize($aRepostEvent['content']);
  2751. if(isset($aContent['type']) && $aContent['type'] == $aEvent['type'] && isset($aContent['object_id']) && (($bSystem && (int)$aContent['object_id'] == (int)$aEvent['object_id']) || (!$bSystem && (int)$aContent['object_id'] == (int)$aEvent[$CNF['FIELD_ID']])) && (int)$this->_oDb->deleteEvent(array('id' => (int)$aRepostEvent[$CNF['FIELD_ID']])) > 0) {
  2752. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent[$CNF['FIELD_ID']]);
  2753. if($oComments !== false)
  2754. $oComments->onObjectDelete($aRepostEvent[$CNF['FIELD_ID']]);
  2755. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent[$CNF['FIELD_ID']], $iUserId, array(
  2756. 'repost_id' => $aRepostEvent[$CNF['FIELD_ID']],
  2757. ));
  2758. }
  2759. }
  2760. //--- Delete associated meta.
  2761. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2762. $oMetatags->onDeleteContent($aEvent[$CNF['FIELD_ID']]);
  2763. //--- Delete feed cache.
  2764. $this->_oDb->deleteCache(array('event_id' => $aEvent[$CNF['FIELD_ID']]));
  2765. //--- Delete item cache.
  2766. $sCacheItemKey = $this->_oConfig->getCacheItemKey($aEvent[$CNF['FIELD_ID']]);
  2767. $this->getCacheItemObject()->delData($sCacheItemKey);
  2768. //--- Event -> Delete for Alerts Engine ---//
  2769. if($bRepost)
  2770. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted[$CNF['FIELD_ID']], $iUserId, array(
  2771. 'repost_id' => $aEvent[$CNF['FIELD_ID']],
  2772. ));
  2773. else
  2774. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent[$CNF['FIELD_ID']], $iUserId);
  2775. //--- Event -> Delete for Alerts Engine ---//
  2776. }
  2777. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = BX_TIMELINE_FILTER_ALL, $aModules = array(), $iTimeline = 0)
  2778. {
  2779. return $this->_prepareParams(array(
  2780. 'view' => $sView,
  2781. 'type' => $sType,
  2782. 'owner_id' => $iOwnerId,
  2783. 'start' => $iStart,
  2784. 'per_page' => $iPerPage,
  2785. 'timeline' => $iTimeline,
  2786. 'filter' => $sFilter,
  2787. 'modules' => $aModules
  2788. ));
  2789. }
  2790. public function getParamsExt($aParams = array())
  2791. {
  2792. return $this->_prepareParams($aParams);
  2793. }
  2794. public function getViewsData(&$aViews)
  2795. {
  2796. if(empty($aViews) || !is_array($aViews))
  2797. return false;
  2798. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  2799. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  2800. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  2801. if($sSystem == '' || $iObjectId == 0)
  2802. return false;
  2803. return array($sSystem, $iObjectId, $iCount);
  2804. }
  2805. public function getVotesData(&$aVotes)
  2806. {
  2807. if(empty($aVotes) || !is_array($aVotes))
  2808. return false;
  2809. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  2810. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  2811. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  2812. if($sSystem == '' || $iObjectId == 0)
  2813. return false;
  2814. return array($sSystem, $iObjectId, $iCount);
  2815. }
  2816. public function getReactionsData(&$aReactions)
  2817. {
  2818. if(empty($aReactions) || !is_array($aReactions))
  2819. return false;
  2820. $sSystem = isset($aReactions['system']) ? $aReactions['system'] : '';
  2821. $iObjectId = isset($aReactions['object_id']) ? (int)$aReactions['object_id'] : 0;
  2822. $iCount = isset($aReactions['count']) ? (int)$aReactions['count'] : 0;
  2823. if($sSystem == '' || $iObjectId == 0)
  2824. return false;
  2825. return array($sSystem, $iObjectId, $iCount);
  2826. }
  2827. public function getScoresData(&$aScores)
  2828. {
  2829. if(empty($aScores) || !is_array($aScores))
  2830. return false;
  2831. $sSystem = isset($aScores['system']) ? $aScores['system'] : '';
  2832. $iObjectId = isset($aScores['object_id']) ? (int)$aScores['object_id'] : 0;
  2833. $iScore = isset($aScores['score']) ? (int)$aScores['score'] : 0;
  2834. if($sSystem == '' || $iObjectId == 0)
  2835. return false;
  2836. return array($sSystem, $iObjectId, $iScore);
  2837. }
  2838. public function getReportsData(&$aReports)
  2839. {
  2840. if(empty($aReports) || !is_array($aReports))
  2841. return false;
  2842. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  2843. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  2844. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  2845. if($sSystem == '' || $iObjectId == 0)
  2846. return false;
  2847. return array($sSystem, $iObjectId, $iCount);
  2848. }
  2849. public function getCommentsData(&$aComments)
  2850. {
  2851. if(empty($aComments) || !is_array($aComments))
  2852. return false;
  2853. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  2854. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  2855. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  2856. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  2857. return false;
  2858. return array($sSystem, $iObjectId, $iCount);
  2859. }
  2860. public function getUserInfo($iUserId = 0)
  2861. {
  2862. $iLoggedId = $this->getUserId();
  2863. $iUserId = (int)$iUserId;
  2864. return parent::getUserInfo($iUserId);
  2865. }
  2866. /**
  2867. * Protected Methods
  2868. */
  2869. protected function _serviceGetBlockView($iProfileId = 0, $aBrowseParams = array())
  2870. {
  2871. if(empty($iProfileId) && bx_get('profile_id') !== false)
  2872. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2873. if(empty($iProfileId) && isLogged())
  2874. $iProfileId = bx_get_logged_profile_id();
  2875. $aBrowseParams['owner_id'] = $iProfileId;
  2876. $aBlock = $this->_getBlockView($aBrowseParams);
  2877. if(!empty($aBlock))
  2878. return $aBlock;
  2879. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  2880. }
  2881. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $aBrowseParams = array())
  2882. {
  2883. if(empty($sProfileModule))
  2884. return array();
  2885. if(empty($iProfileContentId) && bx_get('id') !== false)
  2886. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2887. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  2888. if(empty($oProfile))
  2889. return array();
  2890. $aBrowseParams['owner_id'] = $oProfile->id();
  2891. return $this->_getBlockView($aBrowseParams);
  2892. }
  2893. protected function _serviceGetBlockViews($aBrowseParams = array())
  2894. {
  2895. $aParams = $this->_prepareParams($aBrowseParams);
  2896. $this->_iOwnerId = $aParams['owner_id'];
  2897. return array(
  2898. 'content' => $this->_oTemplate->getViewsBlock($aParams)
  2899. );
  2900. }
  2901. protected function _serviceGetBlockViewHome($aBrowseParams = array())
  2902. {
  2903. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2904. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  2905. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2906. }
  2907. protected function _serviceGetBlockViewHot($aBrowseParams = array())
  2908. {
  2909. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $aBrowseParams['type'] . '/';
  2910. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_hot'), $sRssUrl);
  2911. return $this->_serviceGetBlockViewByType($aBrowseParams);
  2912. }
  2913. protected function _serviceGetBlockViewByType($aBrowseParams = array())
  2914. {
  2915. $aParams = $this->_prepareParams($aBrowseParams);
  2916. $this->_iOwnerId = $aParams['owner_id'];
  2917. return array(
  2918. 'content' => $this->_oTemplate->getViewBlock($aParams)
  2919. );
  2920. }
  2921. protected function _getBlockPost($iProfileId, $aParams = array())
  2922. {
  2923. $this->_iOwnerId = $iProfileId;
  2924. if($this->isAllowedPost() !== true)
  2925. return array();
  2926. return array(
  2927. 'content' => $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams)
  2928. );
  2929. }
  2930. protected function _getBlockView($aBrowseParams = array())
  2931. {
  2932. if(empty($aBrowseParams['owner_id']))
  2933. return array();
  2934. $aParams = $this->_prepareParams($aBrowseParams);
  2935. if(empty($aParams['per_page']))
  2936. $aParams['per_page'] = $this->_oConfig->getPerPage('profile');
  2937. $this->_iOwnerId = $aParams['owner_id'];
  2938. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  2939. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  2940. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  2941. return array('content' => MsgBox($mixedResult));
  2942. list($sUserName) = $this->getUserInfo($aParams['owner_id']);
  2943. $sView = $aParams['view'];
  2944. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $this->_iOwnerId . '/';
  2945. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  2946. $aMenu = array(
  2947. array('id' => $sView . '-view-all', 'name' => $sView . '-view-all', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_all'), 'active' => 1),
  2948. array('id' => $sView . '-view-owner', 'name' => $sView . '-view-owner', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_owner', $sUserName)),
  2949. array('id' => $sView . '-view-other', 'name' => $sView . '-view-other', 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFilter(this)', 'target' => '_self', 'title' => _t('_bx_timeline_menu_item_view_other')),
  2950. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'onclick' => '', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  2951. );
  2952. $sContent = '';
  2953. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  2954. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  2955. $oMenu->setSelected('', $sView . '-view-all');
  2956. if (!$sContent)
  2957. $sContent = $this->_oTemplate->getViewBlock($aParams);
  2958. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  2959. return array('content' => $sContent, 'menu' => $oMenu);
  2960. }
  2961. protected function _getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams = array())
  2962. {
  2963. $CNF = &$this->_oConfig->CNF;
  2964. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  2965. $sText = '';
  2966. if(isset($aContentInfo['content'])){
  2967. $aTmp = unserialize($aContentInfo['content']);
  2968. if(isset($aTmp['text']))
  2969. $sText = $aTmp['text'];
  2970. }
  2971. if(empty($sText) && !empty($aContentInfo[$CNF['FIELD_TITLE']]))
  2972. $sText = $aContentInfo[$CNF['FIELD_TITLE']];
  2973. if(!empty($CNF['OBJECT_METATAGS']) && !empty($sText)) {
  2974. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  2975. $sText = $oMetatags->metaParse($aContentInfo[$CNF['FIELD_ID']], $sText);
  2976. }
  2977. return array(
  2978. 'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
  2979. 'sample_wo_article' => $CNF['T']['txt_sample_single'],
  2980. 'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
  2981. 'url' => $sUrl,
  2982. 'title' => '',
  2983. 'text' => $sText,
  2984. 'images' => array(),
  2985. 'videos' => array()
  2986. );
  2987. }
  2988. protected function _isAllowedPin($aEvent, $bPerform = false)
  2989. {
  2990. $iUserId = (int)$this->getUserId();
  2991. if($iUserId == 0)
  2992. return false;
  2993. if(isAdmin() || (int)$aEvent['owner_id'] == $iUserId || ((int)$aEvent['owner_id'] == 0 && $this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && (int)$aEvent['object_id'] == $iUserId))
  2994. return true;
  2995. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  2996. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  2997. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  2998. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  2999. }
  3000. protected function _isAllowedStick($aEvent, $bPerform = false)
  3001. {
  3002. $iUserId = (int)$this->getUserId();
  3003. if($iUserId == 0)
  3004. return false;
  3005. if(isAdmin())
  3006. return true;
  3007. $aCheckResult = checkActionModule($iUserId, 'stick', $this->getName(), $bPerform);
  3008. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3009. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_stick', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3010. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3011. }
  3012. protected function _isAllowedPromote($aEvent, $bPerform = false)
  3013. {
  3014. if(isAdmin())
  3015. return true;
  3016. $iUserId = (int)$this->getUserId();
  3017. if($iUserId == 0)
  3018. return false;
  3019. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  3020. if(!empty($aEvent['owner_id']) && ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id'])) !== false)
  3021. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  3022. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  3023. }
  3024. protected function _addLink(&$oForm)
  3025. {
  3026. $iUserId = $this->getUserId();
  3027. $sLink = $oForm->getCleanValue('url');
  3028. $aMatches = array();
  3029. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  3030. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  3031. $aSiteInfo = bx_get_site_info($sLink, array(
  3032. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  3033. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  3034. ));
  3035. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  3036. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  3037. $sMediaUrl = '';
  3038. if(!empty($aSiteInfo['thumbnailUrl']))
  3039. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  3040. else if(!empty($aSiteInfo['OGImage']))
  3041. $sMediaUrl = $aSiteInfo['OGImage'];
  3042. $iMediaId = 0;
  3043. $oStorage = null;
  3044. if(!empty($sMediaUrl)) {
  3045. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  3046. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  3047. }
  3048. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  3049. if(!empty($iId)) {
  3050. if(!empty($oStorage) && !empty($iMediaId))
  3051. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  3052. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  3053. }
  3054. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  3055. }
  3056. protected function _deleteLinks($iId)
  3057. {
  3058. $aLinks = $this->_oDb->getLinks($iId);
  3059. if(empty($aLinks) || !is_array($aLinks))
  3060. return;
  3061. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  3062. foreach($aLinks as $aLink)
  3063. if(!empty($aLink['media_id']))
  3064. $oStorage->deleteFile($aLink['media_id']);
  3065. $this->_oDb->deleteLinks($iId);
  3066. }
  3067. protected function _saveMedia($sType, $iId, $aItemIds)
  3068. {
  3069. if(empty($aItemIds) || !is_array($aItemIds))
  3070. return;
  3071. $iUserId = $this->getUserId();
  3072. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3073. foreach($aItemIds as $iItemId)
  3074. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  3075. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  3076. }
  3077. protected function _deleteMedia($sType, $iId)
  3078. {
  3079. $aItems = $this->_oDb->getMedia($sType, $iId);
  3080. if(empty($aItems) || !is_array($aItems))
  3081. return;
  3082. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  3083. foreach($aItems as $iItemId)
  3084. $oStorage->deleteFile($iItemId);
  3085. $this->_oDb->deleteMedia($sType, $iId);
  3086. }
  3087. protected function _prepareParams($aParams)
  3088. {
  3089. if(empty($aParams['name']))
  3090. $aParams['name'] = '';
  3091. if(empty($aParams['view']))
  3092. $aParams['view'] = BX_TIMELINE_VIEW_DEFAULT;
  3093. if(empty($aParams['type']))
  3094. $aParams['type'] = BX_TIMELINE_TYPE_DEFAULT;
  3095. if(empty($aParams['owner_id']))
  3096. $aParams['owner_id'] = $this->getUserId();
  3097. if(!isset($aParams['start']) || (int)$aParams['start'] < 0)
  3098. $aParams['start'] = 0;
  3099. if(!isset($aParams['per_page']) || (int)$aParams['per_page'] <= 0)
  3100. $aParams['per_page'] = isset($aParams['per_page_default']) && (int)$aParams['per_page_default'] > 0 ? $aParams['per_page_default'] : $this->_oConfig->getPerPage();
  3101. if(empty($aParams['timeline']) || (int)$aParams['timeline'] < 0)
  3102. $aParams['timeline'] = 0;
  3103. if(empty($aParams['filter']))
  3104. $aParams['filter'] = BX_TIMELINE_FILTER_ALL;
  3105. if(empty($aParams['modules']) || !is_array($aParams['modules']))
  3106. $aParams['modules'] = array();
  3107. if(empty($aParams['blink']) || !is_array($aParams['blink']))
  3108. $aParams['blink'] = array();
  3109. if($this->_oConfig->isHot())
  3110. $aParams['hot'] = $this->_oDb->getHot();
  3111. $aParams = array_merge($aParams, array(
  3112. 'browse' => 'list',
  3113. 'status' => BX_TIMELINE_STATUS_ACTIVE
  3114. ));
  3115. return $aParams;
  3116. }
  3117. protected function _prepareParamsGet()
  3118. {
  3119. $aParams = array();
  3120. $aParams['name'] = bx_get('name');
  3121. $aParams['name'] = $aParams['name'] !== false ? bx_process_input($aParams['name'], BX_DATA_TEXT) : '';
  3122. $aParams['view'] = bx_get('view');
  3123. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  3124. $aParams['type'] = bx_get('type');
  3125. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  3126. $aParams['owner_id'] = bx_get('owner_id');
  3127. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  3128. $aParams['start'] = bx_get('start');
  3129. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  3130. $aParams['per_page'] = bx_get('per_page');
  3131. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  3132. $aParams['timeline'] = bx_get('timeline');
  3133. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline']) : '';
  3134. $aParams['filter'] = bx_get('filter');
  3135. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  3136. $aParams['modules'] = bx_get('modules');
  3137. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  3138. $aParams['blink'] = bx_get('blink');
  3139. $aParams['blink'] = $aParams['blink'] !== false ? explode(',', bx_process_input($aParams['blink'], BX_DATA_TEXT)) : array();
  3140. if($this->_oConfig->isHot())
  3141. $aParams['hot'] = $this->_oDb->getHot();
  3142. $aParams = array_merge($aParams, array(
  3143. 'browse' => 'list',
  3144. 'status' => BX_TIMELINE_STATUS_ACTIVE,
  3145. 'dynamic_mode' => true,
  3146. ));
  3147. return $aParams;
  3148. }
  3149. protected function _prepareTextForSave($s)
  3150. {
  3151. return bx_process_input($s, BX_DATA_HTML);
  3152. }
  3153. protected function _getFieldValue($sField, $iContentId)
  3154. {
  3155. $CNF = &$this->_oConfig->CNF;
  3156. if(empty($CNF[$sField]))
  3157. return false;
  3158. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  3159. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  3160. return false;
  3161. return $aEvent[$CNF[$sField]];
  3162. }
  3163. /**
  3164. * Returns records for React Jot using OAuth2
  3165. * @param int $iProfileId
  3166. * @param string $sPage
  3167. * @param string $sTab
  3168. * @param int $iStart
  3169. * @param int $iPerPage
  3170. * @return array
  3171. */
  3172. public function serviceGetUserPosts($iProfileId = 0, $sPage = 'home', $sTab = 'hot', $iStart = 0, $iPerPage = 0)
  3173. {
  3174. $iProfileId = (int)$iProfileId ? (int)$iProfileId : bx_get_logged_profile_id();
  3175. if(empty($iProfileId))
  3176. return array(
  3177. 'code' => 1,
  3178. 'result' => array(),
  3179. 'message' => _t('_bx_timeline_txt_msg_no_profile_id'),
  3180. 'page' => $sPage,
  3181. 'tab' => $sTab
  3182. );
  3183. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3184. $sView = BX_TIMELINE_VIEW_DEFAULT;
  3185. $sFilter = BX_TIMELINE_FILTER_ALL;
  3186. $aModules = array();
  3187. switch($sPage){
  3188. case 'profile':
  3189. $sType = BX_BASE_MOD_NTFS_TYPE_OWNER;
  3190. $sFilter = BX_TIMELINE_FILTER_OWNER;
  3191. break;
  3192. default:
  3193. if ($this -> _oDb -> isModuleByName($sPage))
  3194. $aModules = array($sPage);
  3195. }
  3196. switch($sTab)
  3197. {
  3198. case 'latest':
  3199. $sType = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
  3200. break;
  3201. case 'popular':
  3202. $sType = BX_TIMELINE_TYPE_HOT;
  3203. break;
  3204. case 'feed':
  3205. $sType = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
  3206. break;
  3207. default:
  3208. if ($this -> _oDb -> isModuleByName($sTab))
  3209. $aModules = array($sTab);
  3210. }
  3211. $aParams = $this->getParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules);
  3212. $aData = $this->_oDb->getEvents($aParams, true);
  3213. list($aEvents, $iCount) = $aData;
  3214. if(empty($aEvents) || !is_array($aEvents))
  3215. return array(
  3216. 'code' => 0,
  3217. 'result' => array(),
  3218. 'message' => _t('_bx_timeline_txt_msg_no_results'),
  3219. 'page' => $sPage,
  3220. 'tab' => $sTab
  3221. );
  3222. $aBrowseParams = array();
  3223. $aItems = array();
  3224. foreach($aEvents as $aEvent) {
  3225. $aResult = $this->_oTemplate->getData($aEvent, $aBrowseParams);
  3226. if($aResult === false)
  3227. continue;
  3228. $oOwnerProfile = BxDolProfile::getInstance($aResult['owner_id']);
  3229. $aFiles = array();
  3230. $aContent = &$aResult['content'];
  3231. if (!empty($aContent['image']))
  3232. $aFiles['images'] = array_values($aContent['images']);
  3233. if (!empty($aContent['images_attach']))
  3234. $aFiles['images'] = array_values($aContent['images_attach']);
  3235. if (!empty($aContent['videos']))
  3236. $aFiles['videos'] = array_values($aContent['videos']);
  3237. else
  3238. if (!empty($aContent['videos_attach']))
  3239. $aFiles['videos'] = array_values($aContent['videos_attach']);
  3240. if (!empty($aContent['files']))
  3241. $aFiles['files'] = array_values($aContent['files']);
  3242. else
  3243. if (!empty($aContent['files_attach']))
  3244. $aFiles['files'] = array_values($aContent['files_attach']);
  3245. $aItems[$aEvent['id']] = array_merge(array(
  3246. 'owner' => array(
  3247. 'icon' => $oOwnerProfile -> getThumb(),
  3248. 'name' => $oOwnerProfile -> getDisplayName(),
  3249. 'url' => $oOwnerProfile -> getUrl()
  3250. ),
  3251. 'sample' => !empty($aResult['sample']) ? _t($aResult['sample']) : _t('_bx_timeline_txt_sample'),
  3252. 'sample_action' => !empty($aResult['sample_action']) ? _t($aResult['sample_action']) : _t('_bx_timeline_txt_added_sample'),
  3253. 'url' => isset($aResult['url']) ? $aResult['url'] : '',
  3254. 'raw' => isset($aContent['raw']) ? strip_tags($aContent['raw']) : '',
  3255. 'text' => isset($aContent['text']) ? strip_tags($aContent['text']) : '',
  3256. 'views' => isset($aResult['views']['count']) ? (int)$aResult['views']['count'] : 0,
  3257. 'votes' => isset($aResult['votes']['count']) ? (int)$aResult['votes']['count'] : 0,
  3258. 'reactions' => isset($aResult['reactions']['count']) ? (int)$aResult['reactions']['count'] : 0,
  3259. 'scores' => isset($aResult['scores']['count']) ? (int)$aResult['scores']['count'] : 0,
  3260. 'reports' => isset($aResult['reports']['count']) ? (int)$aResult['reports']['count'] : 0,
  3261. 'comments' => isset($aResult['comments']['count']) ? (int)$aResult['comments']['count'] : 0,
  3262. 'date' => isset($aResult['date']) ? $aResult['date'] : $aEvent['date'],
  3263. 'type' => stripos($aEvent['type'], 'timeline') !== FALSE ? 'bx_timeline' : $aEvent['type'],
  3264. 'event_type' => $aEvent['type'],
  3265. 'id' => $aEvent['id'],
  3266. 'content' => $aResult['content'],
  3267. 'title' => isset($aResult['title']) ? _t($aResult['title']) : '',
  3268. 'description' => isset($aResult['description']) ? $aResult['description'] : ''
  3269. ), $aFiles);
  3270. }
  3271. return array(
  3272. 'result' => $aItems,
  3273. 'code' => 0,
  3274. 'message' => '',
  3275. 'page' => $sPage,
  3276. 'tab' => $sTab,
  3277. 'total' => $iCount,
  3278. 'start' => (int)$iStart
  3279. );
  3280. }
  3281. }
  3282. /** @} */