BxTimelineModule.php 129 KB

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