BxTimelineModule.php 150 KB

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